Graphical package manager for pacman based on pamac 5.x.x
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

365 lines
15KB

  1. /*
  2. * pamac-vala
  3. *
  4. * Copyright (C) 2015-2016 Guillaume Benoit <guillaume@manjaro.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a get of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. namespace Pamac {
  20. [GtkTemplate (ui = "/org/manjaro/pamac/preferences/preferences_dialog.ui")]
  21. class PreferencesDialog : Gtk.Dialog {
  22. [GtkChild]
  23. Gtk.Switch remove_unrequired_deps_button;
  24. [GtkChild]
  25. Gtk.Switch check_space_button;
  26. [GtkChild]
  27. Gtk.Switch check_updates_button;
  28. [GtkChild]
  29. Gtk.Label refresh_period_label;
  30. [GtkChild]
  31. Gtk.SpinButton refresh_period_spin_button;
  32. [GtkChild]
  33. Gtk.CheckButton no_update_hide_icon_checkbutton;
  34. [GtkChild]
  35. Gtk.Box ignorepkgs_box;
  36. [GtkChild]
  37. Gtk.TreeView ignorepkgs_treeview;
  38. [GtkChild]
  39. Gtk.Box mirrors_config_box;
  40. [GtkChild]
  41. Gtk.ComboBoxText mirrors_country_comboboxtext;
  42. [GtkChild]
  43. Gtk.ComboBoxText mirrors_list_generation_method_comboboxtext;
  44. [GtkChild]
  45. Gtk.Button generate_mirrors_list_button;
  46. [GtkChild]
  47. Gtk.Box aur_config_box;
  48. [GtkChild]
  49. Gtk.Switch enable_aur_button;
  50. [GtkChild]
  51. Gtk.CheckButton search_aur_checkbutton;
  52. [GtkChild]
  53. Gtk.CheckButton check_aur_updates_checkbutton;
  54. [GtkChild]
  55. Gtk.CheckButton no_confirm_build_checkbutton;
  56. Gtk.ListStore ignorepkgs_liststore;
  57. Transaction transaction;
  58. uint64 previous_refresh_period;
  59. public PreferencesDialog (Transaction transaction) {
  60. Object (transient_for: transaction.application_window, use_header_bar: 0);
  61. this.transaction = transaction;
  62. refresh_period_label.set_markup (dgettext (null, "How often to check for updates, value in hours") +":");
  63. remove_unrequired_deps_button.active = transaction.recurse;
  64. check_space_button.active = transaction.get_checkspace ();
  65. if (transaction.refresh_period == 0) {
  66. check_updates_button.active = false;
  67. refresh_period_label.sensitive = false;
  68. // set default value
  69. refresh_period_spin_button.value = 6;
  70. previous_refresh_period = 6;
  71. refresh_period_spin_button.sensitive = false;
  72. no_update_hide_icon_checkbutton.sensitive = false;
  73. ignorepkgs_box.sensitive = false;
  74. } else {
  75. check_updates_button.active = true;
  76. refresh_period_spin_button.value = transaction.refresh_period;
  77. previous_refresh_period = transaction.refresh_period;
  78. }
  79. no_update_hide_icon_checkbutton.active = transaction.no_update_hide_icon;
  80. // populate ignorepkgs_liststore
  81. ignorepkgs_liststore = new Gtk.ListStore (1, typeof (string));
  82. ignorepkgs_treeview.set_model (ignorepkgs_liststore);
  83. foreach (unowned string ignorepkg in transaction.get_ignorepkgs ()) {
  84. ignorepkgs_liststore.insert_with_values (null, -1, 0, ignorepkg);
  85. }
  86. remove_unrequired_deps_button.state_set.connect (on_remove_unrequired_deps_button_state_set);
  87. check_space_button.state_set.connect (on_check_space_button_state_set);
  88. transaction.write_alpm_config_finished.connect (on_write_alpm_config_finished);
  89. check_updates_button.state_set.connect (on_check_updates_button_state_set);
  90. refresh_period_spin_button.value_changed.connect (on_refresh_period_spin_button_value_changed);
  91. no_update_hide_icon_checkbutton.toggled.connect (on_no_update_hide_icon_checkbutton_toggled);
  92. transaction.write_pamac_config_finished.connect (on_write_pamac_config_finished);
  93. AlpmPackage pkg = transaction.find_installed_satisfier ("pacman-mirrorlist");
  94. if (pkg.name == "") {
  95. mirrors_config_box.visible = false;
  96. } else {
  97. var mirrors_config = new MirrorsConfig ("/etc/pacman-mirrors.conf");
  98. mirrors_country_comboboxtext.append_text (dgettext (null, "Worldwide"));
  99. mirrors_country_comboboxtext.active = 0;
  100. int index = 1;
  101. foreach (unowned string country in mirrors_config.countrys) {
  102. mirrors_country_comboboxtext.append_text (country);
  103. if (country == mirrors_config.choosen_country) {
  104. mirrors_country_comboboxtext.active = index;
  105. }
  106. index += 1;
  107. }
  108. mirrors_list_generation_method_comboboxtext.append_text (dgettext (null, "Speed"));
  109. mirrors_list_generation_method_comboboxtext.append_text (dgettext (null, "Random"));
  110. if (mirrors_config.choosen_generation_method == "rank") {
  111. mirrors_list_generation_method_comboboxtext.active = 0;
  112. } else {
  113. mirrors_list_generation_method_comboboxtext.active = 1;
  114. }
  115. mirrors_country_comboboxtext.changed.connect (on_mirrors_country_comboboxtext_changed);
  116. mirrors_list_generation_method_comboboxtext.changed.connect (on_mirrors_list_generation_method_comboboxtext_changed);
  117. transaction.write_mirrors_config_finished.connect (on_write_mirrors_config_finished);
  118. }
  119. pkg = transaction.find_installed_satisfier ("yaourt");
  120. if (pkg.name == "") {
  121. aur_config_box.visible = false;
  122. } else {
  123. enable_aur_button.active = transaction.enable_aur;
  124. search_aur_checkbutton.active = transaction.search_aur;
  125. search_aur_checkbutton.sensitive = transaction.enable_aur;
  126. check_aur_updates_checkbutton.active = transaction.check_aur_updates;
  127. check_aur_updates_checkbutton.sensitive = transaction.enable_aur;
  128. no_confirm_build_checkbutton.active = transaction.no_confirm_build;
  129. no_confirm_build_checkbutton.sensitive = transaction.enable_aur;
  130. enable_aur_button.state_set.connect (on_enable_aur_button_state_set);
  131. search_aur_checkbutton.toggled.connect (on_search_aur_checkbutton_toggled);
  132. check_aur_updates_checkbutton.toggled.connect (on_check_aur_updates_checkbutton_toggled);
  133. no_confirm_build_checkbutton.toggled.connect (on_no_confirm_build_checkbutton_toggled);
  134. }
  135. }
  136. bool on_remove_unrequired_deps_button_state_set (bool new_state) {
  137. var new_pamac_conf = new HashTable<string,Variant> (str_hash, str_equal);
  138. new_pamac_conf.insert ("RemoveUnrequiredDeps", new Variant.boolean (new_state));
  139. transaction.start_write_pamac_config (new_pamac_conf);
  140. return true;
  141. }
  142. bool on_check_updates_button_state_set (bool new_state) {
  143. var new_pamac_conf = new HashTable<string,Variant> (str_hash, str_equal);
  144. refresh_period_label.sensitive = new_state;
  145. refresh_period_spin_button.sensitive = new_state;
  146. no_update_hide_icon_checkbutton.sensitive = new_state;
  147. ignorepkgs_box.sensitive = new_state;
  148. if (new_state) {
  149. new_pamac_conf.insert ("RefreshPeriod", new Variant.uint64 (previous_refresh_period));
  150. } else {
  151. new_pamac_conf.insert ("RefreshPeriod", new Variant.uint64 (0));
  152. }
  153. transaction.start_write_pamac_config (new_pamac_conf);
  154. return true;
  155. }
  156. void on_refresh_period_spin_button_value_changed () {
  157. var new_pamac_conf = new HashTable<string,Variant> (str_hash, str_equal);
  158. new_pamac_conf.insert ("RefreshPeriod", new Variant.uint64 (refresh_period_spin_button.get_value_as_int ()));
  159. transaction.start_write_pamac_config (new_pamac_conf);
  160. }
  161. void on_no_update_hide_icon_checkbutton_toggled () {
  162. var new_pamac_conf = new HashTable<string,Variant> (str_hash, str_equal);
  163. new_pamac_conf.insert ("NoUpdateHideIcon", new Variant.boolean (no_update_hide_icon_checkbutton.active));
  164. transaction.start_write_pamac_config (new_pamac_conf);
  165. }
  166. bool on_enable_aur_button_state_set (bool new_state) {
  167. var new_pamac_conf = new HashTable<string,Variant> (str_hash, str_equal);
  168. new_pamac_conf.insert ("EnableAUR", new Variant.boolean (new_state));
  169. transaction.start_write_pamac_config (new_pamac_conf);
  170. return true;
  171. }
  172. void on_search_aur_checkbutton_toggled () {
  173. var new_pamac_conf = new HashTable<string,Variant> (str_hash, str_equal);
  174. new_pamac_conf.insert ("SearchInAURByDefault", new Variant.boolean (search_aur_checkbutton.active));
  175. transaction.start_write_pamac_config (new_pamac_conf);
  176. }
  177. void on_check_aur_updates_checkbutton_toggled () {
  178. var new_pamac_conf = new HashTable<string,Variant> (str_hash, str_equal);
  179. new_pamac_conf.insert ("CheckAURUpdates", new Variant.boolean (check_aur_updates_checkbutton.active));
  180. transaction.start_write_pamac_config (new_pamac_conf);
  181. }
  182. void on_no_confirm_build_checkbutton_toggled () {
  183. var new_pamac_conf = new HashTable<string,Variant> (str_hash, str_equal);
  184. new_pamac_conf.insert ("NoConfirmBuild", new Variant.boolean (no_confirm_build_checkbutton.active));
  185. transaction.start_write_pamac_config (new_pamac_conf);
  186. }
  187. void on_write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
  188. bool enable_aur, bool search_aur, bool check_aur_updates,
  189. bool no_confirm_build) {
  190. remove_unrequired_deps_button.state = recurse;
  191. if (refresh_period == 0) {
  192. check_updates_button.state = false;
  193. refresh_period_label.sensitive = false;
  194. refresh_period_spin_button.sensitive = false;
  195. no_update_hide_icon_checkbutton.sensitive = false;
  196. ignorepkgs_box.sensitive = false;
  197. } else {
  198. check_updates_button.state = true;
  199. refresh_period_label.sensitive = true;
  200. refresh_period_spin_button.value = refresh_period;
  201. previous_refresh_period = refresh_period;
  202. refresh_period_spin_button.sensitive = true;
  203. no_update_hide_icon_checkbutton.sensitive = true;
  204. ignorepkgs_box.sensitive = true;
  205. // launch pamac-tray if needed
  206. try {
  207. Process.spawn_command_line_async ("pamac-tray");
  208. } catch (SpawnError e) {
  209. stderr.printf ("SpawnError: %s\n", e.message);
  210. }
  211. }
  212. no_update_hide_icon_checkbutton.active = no_update_hide_icon;
  213. enable_aur_button.state = enable_aur;
  214. search_aur_checkbutton.active = search_aur;
  215. search_aur_checkbutton.sensitive = enable_aur;
  216. check_aur_updates_checkbutton.active = check_aur_updates;
  217. check_aur_updates_checkbutton.sensitive = enable_aur;
  218. no_confirm_build_checkbutton.active = no_confirm_build;
  219. no_confirm_build_checkbutton.sensitive = enable_aur;
  220. }
  221. bool on_check_space_button_state_set (bool new_state) {
  222. var new_alpm_conf = new HashTable<string,Variant> (str_hash, str_equal);
  223. new_alpm_conf.insert ("CheckSpace", new Variant.boolean (new_state));
  224. transaction.start_write_alpm_config (new_alpm_conf);
  225. return true;
  226. }
  227. [GtkCallback]
  228. void on_add_ignorepkgs_button_clicked () {
  229. var choose_ignorepkgs_dialog = new ChooseIgnorepkgsDialog (this);
  230. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  231. while (Gtk.events_pending ()) {
  232. Gtk.main_iteration ();
  233. }
  234. transaction.get_installed_pkgs.begin ((obj, res) => {
  235. var pkgs = transaction.get_installed_pkgs.end (res);
  236. foreach (unowned AlpmPackage pkg in pkgs) {
  237. if (pkg.name in transaction.get_ignorepkgs ()) {
  238. choose_ignorepkgs_dialog.pkgs_list.insert_with_values (null, -1, 0, true, 1, pkg.name);
  239. } else {
  240. choose_ignorepkgs_dialog.pkgs_list.insert_with_values (null, -1, 0, false, 1, pkg.name);
  241. }
  242. }
  243. this.get_window ().set_cursor (null);
  244. if (choose_ignorepkgs_dialog.run () == Gtk.ResponseType.OK) {
  245. var ignorepkg_string = new StringBuilder ();
  246. choose_ignorepkgs_dialog.pkgs_list.foreach ((model, path, iter) => {
  247. GLib.Value val;
  248. // get value at column 0 to know if it is selected
  249. model.get_value (iter, 0, out val);
  250. if ((bool) val) {
  251. // get value at column 1 to get the pkg name
  252. model.get_value (iter, 1, out val);
  253. if (ignorepkg_string.len != 0) {
  254. ignorepkg_string.append (" ");
  255. }
  256. ignorepkg_string.append ((string) val);
  257. }
  258. return false;
  259. });
  260. var new_alpm_conf = new HashTable<string,Variant> (str_hash, str_equal);
  261. new_alpm_conf.insert ("IgnorePkg", new Variant.string (ignorepkg_string.str));
  262. transaction.start_write_alpm_config (new_alpm_conf);
  263. }
  264. choose_ignorepkgs_dialog.destroy ();
  265. while (Gtk.events_pending ()) {
  266. Gtk.main_iteration ();
  267. }
  268. });
  269. }
  270. [GtkCallback]
  271. void on_remove_ignorepkgs_button_clicked () {
  272. Gtk.TreeIter? iter;
  273. Gtk.TreeSelection selection = ignorepkgs_treeview.get_selection ();
  274. if (selection.get_selected (null, out iter)) {
  275. ignorepkgs_liststore.remove (iter);
  276. var ignorepkg_string = new StringBuilder ();
  277. ignorepkgs_liststore.foreach ((model, path, iter) => {
  278. GLib.Value name;
  279. model.get_value (iter, 0, out name);
  280. if (ignorepkg_string.len != 0) {
  281. ignorepkg_string.append (" ");
  282. }
  283. ignorepkg_string.append ((string) name);
  284. return false;
  285. });
  286. var new_alpm_conf = new HashTable<string,Variant> (str_hash, str_equal);
  287. new_alpm_conf.insert ("IgnorePkg", new Variant.string (ignorepkg_string.str));
  288. transaction.start_write_alpm_config (new_alpm_conf);
  289. }
  290. }
  291. void on_write_alpm_config_finished (bool checkspace) {
  292. check_space_button.state = checkspace;
  293. ignorepkgs_liststore.clear ();
  294. foreach (unowned string ignorepkg in transaction.get_ignorepkgs ()) {
  295. ignorepkgs_liststore.insert_with_values (null, -1, 0, ignorepkg);
  296. }
  297. }
  298. void on_mirrors_country_comboboxtext_changed () {
  299. var new_mirrors_conf = new HashTable<string,Variant> (str_hash, str_equal);
  300. new_mirrors_conf.insert ("OnlyCountry", new Variant.string (mirrors_country_comboboxtext.get_active_text ()));
  301. transaction.start_write_mirrors_config (new_mirrors_conf);
  302. }
  303. void on_mirrors_list_generation_method_comboboxtext_changed () {
  304. var new_mirrors_conf = new HashTable<string,Variant> (str_hash, str_equal);
  305. if (mirrors_list_generation_method_comboboxtext.get_active_text () == dgettext (null, "Speed")){
  306. new_mirrors_conf.insert ("Method", new Variant.string ("rank"));
  307. } else {
  308. new_mirrors_conf.insert ("Method", new Variant.string ("random"));
  309. }
  310. transaction.start_write_mirrors_config (new_mirrors_conf);
  311. }
  312. void on_write_mirrors_config_finished (string choosen_country, string choosen_generation_method) {
  313. int index = 0;
  314. mirrors_country_comboboxtext.model.foreach ((model, path, iter) => {
  315. GLib.Value country;
  316. model.get_value (iter, 0, out country);
  317. if ((string) country == choosen_country) {
  318. return true;
  319. }
  320. index += 1;
  321. return false;
  322. });
  323. mirrors_country_comboboxtext.active = index;
  324. if (choosen_generation_method == "rank") {
  325. mirrors_list_generation_method_comboboxtext.active = 0;
  326. } else {
  327. mirrors_list_generation_method_comboboxtext.active = 1;
  328. }
  329. generate_mirrors_list_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
  330. }
  331. [GtkCallback]
  332. void on_generate_mirrors_list_button_clicked () {
  333. transaction.start_generate_mirrors_list ();
  334. generate_mirrors_list_button.get_style_context ().remove_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
  335. }
  336. }
  337. }