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.

485 lines
18KB

  1. /*
  2. * pamac-vala
  3. *
  4. * Copyright (C) 2017-2019 Chris Cromer <cromer@cromnix.org>
  5. * Copyright (C) 2015-2017 Guillaume Benoit <guillaume@manjaro.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a get of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. namespace Pamac {
  21. [GtkTemplate (ui = "/org/pamac/preferences/interface/preferences_dialog.ui")]
  22. class PreferencesDialog : Gtk.Dialog {
  23. [GtkChild]
  24. Gtk.Switch remove_unrequired_deps_button;
  25. [GtkChild]
  26. Gtk.Switch update_files_db_button;
  27. [GtkChild]
  28. Gtk.Switch check_space_button;
  29. [GtkChild]
  30. Gtk.Switch check_updates_button;
  31. [GtkChild]
  32. Gtk.Label refresh_period_label;
  33. [GtkChild]
  34. Gtk.SpinButton refresh_period_spin_button;
  35. [GtkChild]
  36. Gtk.CheckButton no_update_hide_icon_checkbutton;
  37. [GtkChild]
  38. Gtk.Box ignorepkgs_box;
  39. [GtkChild]
  40. Gtk.TreeView ignorepkgs_treeview;
  41. [GtkChild]
  42. Gtk.Box mirrors_config_box;
  43. [GtkChild]
  44. Gtk.ComboBoxText mirrors_country_comboboxtext;
  45. [GtkChild]
  46. Gtk.ComboBoxText mirrors_list_generation_method_comboboxtext;
  47. [GtkChild]
  48. Gtk.Button generate_mirrors_list_button;
  49. #if DISABLE_AUR
  50. [GtkChild]
  51. Gtk.Stack stack;
  52. [GtkChild]
  53. Gtk.Box aur_config_box;
  54. #else
  55. [GtkChild]
  56. Gtk.Switch enable_aur_button;
  57. [GtkChild]
  58. Gtk.CheckButton search_aur_checkbutton;
  59. [GtkChild]
  60. Gtk.Label aur_build_dir_label;
  61. [GtkChild]
  62. Gtk.FileChooserButton aur_build_dir_file_chooser;
  63. [GtkChild]
  64. Gtk.CheckButton check_aur_updates_checkbutton;
  65. #endif
  66. [GtkChild]
  67. Gtk.Label cache_keep_nb_label;
  68. [GtkChild]
  69. Gtk.SpinButton cache_keep_nb_spin_button;
  70. [GtkChild]
  71. Gtk.CheckButton cache_only_uninstalled_checkbutton;
  72. [GtkChild]
  73. Gtk.ColorButton terminal_background;
  74. [GtkChild]
  75. Gtk.ColorButton terminal_foreground;
  76. [GtkChild]
  77. Gtk.FontButton terminal_font;
  78. Gtk.ListStore ignorepkgs_liststore;
  79. Transaction transaction;
  80. uint64 previous_refresh_period;
  81. string[] countries;
  82. public PreferencesDialog (Transaction transaction) {
  83. Object (transient_for: transaction.application_window, use_header_bar: 1);
  84. this.transaction = transaction;
  85. refresh_period_label.set_markup (dgettext (null, "How often to check for updates, value in hours") +":");
  86. cache_keep_nb_label.set_markup (dgettext (null, "Number of versions of each package to keep in the cache") +":");
  87. #if DISABLE_AUR
  88. stack.remove (aur_config_box);
  89. #else
  90. aur_build_dir_label.set_markup (dgettext (null, "Build directory") +":");
  91. #endif
  92. remove_unrequired_deps_button.active = transaction.recurse;
  93. update_files_db_button.active = transaction.update_files_db;
  94. check_space_button.active = transaction.get_checkspace ();
  95. if (transaction.refresh_period == 0) {
  96. check_updates_button.active = false;
  97. refresh_period_label.sensitive = false;
  98. // set default value
  99. refresh_period_spin_button.value = 6;
  100. previous_refresh_period = 6;
  101. refresh_period_spin_button.sensitive = false;
  102. no_update_hide_icon_checkbutton.sensitive = false;
  103. ignorepkgs_box.sensitive = false;
  104. } else {
  105. check_updates_button.active = true;
  106. refresh_period_spin_button.value = transaction.refresh_period;
  107. previous_refresh_period = transaction.refresh_period;
  108. }
  109. no_update_hide_icon_checkbutton.active = transaction.no_update_hide_icon;
  110. cache_keep_nb_spin_button.value = transaction.keep_num_pkgs;
  111. cache_only_uninstalled_checkbutton.active = transaction.rm_only_uninstalled;
  112. // Set up terminal
  113. terminal_background.use_alpha = false;
  114. terminal_foreground.use_alpha = false;
  115. Gdk.RGBA rgba = Gdk.RGBA ();
  116. bool tmp = rgba.parse (transaction.terminal_background);
  117. terminal_background.rgba = rgba;
  118. tmp = rgba.parse (transaction.terminal_foreground);
  119. terminal_foreground.rgba = rgba;
  120. terminal_font.set_font(transaction.terminal_font);
  121. // populate ignorepkgs_liststore
  122. ignorepkgs_liststore = new Gtk.ListStore (1, typeof (string));
  123. ignorepkgs_treeview.set_model (ignorepkgs_liststore);
  124. foreach (unowned string ignorepkg in transaction.get_ignorepkgs ()) {
  125. ignorepkgs_liststore.insert_with_values (null, -1, 0, ignorepkg);
  126. }
  127. remove_unrequired_deps_button.state_set.connect (on_remove_unrequired_deps_button_state_set);
  128. update_files_db_button.state_set.connect (on_update_files_db_button_state_set);
  129. check_space_button.state_set.connect (on_check_space_button_state_set);
  130. transaction.write_alpm_config_finished.connect (on_write_alpm_config_finished);
  131. check_updates_button.state_set.connect (on_check_updates_button_state_set);
  132. refresh_period_spin_button.value_changed.connect (on_refresh_period_spin_button_value_changed);
  133. no_update_hide_icon_checkbutton.toggled.connect (on_no_update_hide_icon_checkbutton_toggled);
  134. cache_keep_nb_spin_button.value_changed.connect (on_cache_keep_nb_spin_button_value_changed);
  135. cache_only_uninstalled_checkbutton.toggled.connect (on_cache_only_uninstalled_checkbutton_toggled);
  136. terminal_background.color_set.connect (on_select_background);
  137. terminal_foreground.color_set.connect (on_select_foreground);
  138. terminal_font.font_set.connect (on_select_font);
  139. AlpmPackage pkg = transaction.find_installed_satisfier ("pacman-mirrors");
  140. if (pkg.name == "") {
  141. mirrors_config_box.visible = false;
  142. } else {
  143. var mirrors_config = new MirrorsConfig ("/etc/pacman-mirrors.conf");
  144. mirrors_country_comboboxtext.append_text (dgettext (null, "Worldwide"));
  145. mirrors_country_comboboxtext.active = 0;
  146. countries = transaction.get_mirrors_countries ();
  147. int index = 1;
  148. foreach (unowned string country in countries) {
  149. mirrors_country_comboboxtext.append_text (country);
  150. if (country == mirrors_config.choosen_country) {
  151. mirrors_country_comboboxtext.active = index;
  152. }
  153. index += 1;
  154. }
  155. mirrors_list_generation_method_comboboxtext.append_text (dgettext (null, "Speed"));
  156. mirrors_list_generation_method_comboboxtext.append_text (dgettext (null, "Random"));
  157. if (mirrors_config.choosen_generation_method == "rank") {
  158. mirrors_list_generation_method_comboboxtext.active = 0;
  159. } else {
  160. mirrors_list_generation_method_comboboxtext.active = 1;
  161. }
  162. mirrors_country_comboboxtext.changed.connect (on_mirrors_country_comboboxtext_changed);
  163. mirrors_list_generation_method_comboboxtext.changed.connect (on_mirrors_list_generation_method_comboboxtext_changed);
  164. transaction.write_mirrors_config_finished.connect (on_write_mirrors_config_finished);
  165. }
  166. #if DISABLE_AUR
  167. #else
  168. enable_aur_button.active = transaction.enable_aur;
  169. search_aur_checkbutton.active = transaction.search_aur;
  170. search_aur_checkbutton.sensitive = transaction.enable_aur;
  171. aur_build_dir_label.sensitive = transaction.enable_aur;
  172. aur_build_dir_file_chooser.sensitive = transaction.enable_aur;
  173. aur_build_dir_file_chooser.set_filename (transaction.aur_build_dir);
  174. // add /tmp choice always visible
  175. try {
  176. aur_build_dir_file_chooser.add_shortcut_folder ("/tmp");
  177. } catch (GLib.Error e) {
  178. stderr.printf ("%s\n", e.message);
  179. }
  180. check_aur_updates_checkbutton.active = transaction.check_aur_updates;
  181. check_aur_updates_checkbutton.sensitive = transaction.enable_aur;
  182. enable_aur_button.state_set.connect (on_enable_aur_button_state_set);
  183. search_aur_checkbutton.toggled.connect (on_search_aur_checkbutton_toggled);
  184. aur_build_dir_file_chooser.file_set.connect (on_aur_build_dir_set);
  185. check_aur_updates_checkbutton.toggled.connect (on_check_aur_updates_checkbutton_toggled);
  186. #endif
  187. }
  188. bool on_remove_unrequired_deps_button_state_set (bool new_state) {
  189. var settings = new Settings ("org.pamac.main");
  190. settings.set_boolean ("remove-unrequired-deps", new_state);
  191. config_changed();
  192. transaction.start_save_pamac_config ();
  193. return true;
  194. }
  195. bool on_update_files_db_button_state_set (bool new_state) {
  196. var settings = new Settings ("org.pamac.main");
  197. settings.set_boolean ("update-files-db", new_state);
  198. config_changed();
  199. transaction.start_save_pamac_config ();
  200. return true;
  201. }
  202. bool on_check_updates_button_state_set (bool new_state) {
  203. var settings = new Settings ("org.pamac.main");
  204. refresh_period_label.sensitive = new_state;
  205. refresh_period_spin_button.sensitive = new_state;
  206. no_update_hide_icon_checkbutton.sensitive = new_state;
  207. ignorepkgs_box.sensitive = new_state;
  208. if (new_state) {
  209. settings.set_uint64 ("refresh-period", previous_refresh_period);
  210. } else {
  211. settings.set_uint64 ("refresh-period", 0);
  212. }
  213. config_changed();
  214. transaction.start_save_pamac_config ();
  215. return true;
  216. }
  217. void on_refresh_period_spin_button_value_changed () {
  218. var settings = new Settings ("org.pamac.main");
  219. settings.set_uint64 ("refresh-period", refresh_period_spin_button.get_value_as_int ());
  220. config_changed();
  221. transaction.start_save_pamac_config ();
  222. }
  223. void on_cache_keep_nb_spin_button_value_changed () {
  224. var settings = new Settings ("org.pamac.main");
  225. settings.set_uint64 ("keep-num-packages", cache_keep_nb_spin_button.get_value_as_int ());
  226. config_changed();
  227. transaction.start_save_pamac_config ();
  228. }
  229. void on_cache_only_uninstalled_checkbutton_toggled () {
  230. var settings = new Settings ("org.pamac.main");
  231. settings.set_boolean ("only-rm-uninstalled", cache_only_uninstalled_checkbutton.active);
  232. config_changed();
  233. transaction.start_save_pamac_config ();
  234. }
  235. void on_no_update_hide_icon_checkbutton_toggled () {
  236. var settings = new Settings ("org.pamac.main");
  237. settings.set_boolean ("no-update-hide-icon", no_update_hide_icon_checkbutton.active);
  238. config_changed();
  239. transaction.start_save_pamac_config ();
  240. }
  241. void on_select_background () {
  242. var settings = new Settings ("org.pamac.main");
  243. settings.set_string ("background-color", terminal_background.rgba.to_string ());
  244. config_changed();
  245. transaction.start_save_pamac_config ();
  246. transaction.update_terminal_background (terminal_background.rgba.to_string ());
  247. }
  248. void on_select_foreground () {
  249. var settings = new Settings ("org.pamac.main");
  250. settings.set_string ("foreground-color", terminal_foreground.rgba.to_string ());
  251. config_changed();
  252. transaction.start_save_pamac_config ();
  253. transaction.update_terminal_foreground (terminal_foreground.rgba.to_string ());
  254. }
  255. void on_select_font () {
  256. var settings = new Settings ("org.pamac.main");
  257. settings.set_string ("terminal-font", terminal_font.get_font ());
  258. config_changed();
  259. transaction.start_save_pamac_config ();
  260. transaction.update_terminal_font (terminal_font.get_font ());
  261. }
  262. #if DISABLE_AUR
  263. #else
  264. bool on_enable_aur_button_state_set (bool new_state) {
  265. var settings = new Settings ("org.pamac.aur");
  266. settings.set_boolean ("enable-aur", new_state);
  267. config_changed();
  268. transaction.start_save_pamac_config ();
  269. return true;
  270. }
  271. void on_search_aur_checkbutton_toggled () {
  272. var settings = new Settings ("org.pamac.aur");
  273. settings.set_boolean ("search-in-aur", search_aur_checkbutton.active);
  274. config_changed();
  275. transaction.start_save_pamac_config ();
  276. }
  277. void on_aur_build_dir_set () {
  278. var settings = new Settings ("org.pamac.aur");
  279. settings.set_string ("build-directory", aur_build_dir_file_chooser.get_filename ());
  280. config_changed();
  281. transaction.start_save_pamac_config ();
  282. }
  283. void on_check_aur_updates_checkbutton_toggled () {
  284. var settings = new Settings ("org.pamac.aur");
  285. settings.set_boolean ("check-aur-updates", check_aur_updates_checkbutton.active);
  286. config_changed();
  287. transaction.start_save_pamac_config ();
  288. }
  289. #endif
  290. void config_changed() {
  291. transaction.config_changed();
  292. remove_unrequired_deps_button.state = transaction.recurse;
  293. update_files_db_button.state = transaction.update_files_db;
  294. if (transaction.refresh_period == 0) {
  295. check_updates_button.state = false;
  296. refresh_period_label.sensitive = false;
  297. refresh_period_spin_button.sensitive = false;
  298. no_update_hide_icon_checkbutton.sensitive = false;
  299. ignorepkgs_box.sensitive = false;
  300. } else {
  301. check_updates_button.state = true;
  302. refresh_period_label.sensitive = true;
  303. refresh_period_spin_button.value = transaction.refresh_period;
  304. previous_refresh_period = transaction.refresh_period;
  305. refresh_period_spin_button.sensitive = true;
  306. no_update_hide_icon_checkbutton.sensitive = true;
  307. ignorepkgs_box.sensitive = true;
  308. }
  309. no_update_hide_icon_checkbutton.active = transaction.no_update_hide_icon;
  310. #if DISABLE_AUR
  311. #else
  312. enable_aur_button.state = transaction.enable_aur;
  313. search_aur_checkbutton.active = transaction.search_aur;
  314. search_aur_checkbutton.sensitive = transaction.enable_aur;
  315. aur_build_dir_label.sensitive = transaction.enable_aur;
  316. aur_build_dir_file_chooser.sensitive = transaction.enable_aur;
  317. check_aur_updates_checkbutton.active = transaction.check_aur_updates;
  318. check_aur_updates_checkbutton.sensitive = transaction.enable_aur;
  319. #endif
  320. }
  321. bool on_check_space_button_state_set (bool new_state) {
  322. var new_alpm_conf = new HashTable<string,Variant> (str_hash, str_equal);
  323. new_alpm_conf.insert ("CheckSpace", new Variant.boolean (new_state));
  324. check_space_button.state = new_state;
  325. transaction.start_write_alpm_config (new_alpm_conf);
  326. return true;
  327. }
  328. [GtkCallback]
  329. void on_add_ignorepkgs_button_clicked () {
  330. var choose_ignorepkgs_dialog = new ChooseIgnorepkgsDialog (this);
  331. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  332. while (Gtk.events_pending ()) {
  333. Gtk.main_iteration ();
  334. }
  335. transaction.get_installed_pkgs.begin ((obj, res) => {
  336. var pkgs = transaction.get_installed_pkgs.end (res);
  337. foreach (unowned AlpmPackage pkg in pkgs) {
  338. if (pkg.name in transaction.get_ignorepkgs ()) {
  339. choose_ignorepkgs_dialog.pkgs_list.insert_with_values (null, -1, 0, true, 1, pkg.name);
  340. } else {
  341. choose_ignorepkgs_dialog.pkgs_list.insert_with_values (null, -1, 0, false, 1, pkg.name);
  342. }
  343. }
  344. this.get_window ().set_cursor (null);
  345. if (choose_ignorepkgs_dialog.run () == Gtk.ResponseType.OK) {
  346. var ignorepkg_string = new StringBuilder ();
  347. choose_ignorepkgs_dialog.pkgs_list.foreach ((model, path, iter) => {
  348. GLib.Value val;
  349. // get value at column 0 to know if it is selected
  350. model.get_value (iter, 0, out val);
  351. if ((bool) val) {
  352. // get value at column 1 to get the pkg name
  353. model.get_value (iter, 1, out val);
  354. if (ignorepkg_string.len != 0) {
  355. ignorepkg_string.append (" ");
  356. }
  357. ignorepkg_string.append ((string) val);
  358. }
  359. return false;
  360. });
  361. var new_alpm_conf = new HashTable<string,Variant> (str_hash, str_equal);
  362. new_alpm_conf.insert ("IgnorePkg", new Variant.string (ignorepkg_string.str));
  363. transaction.start_write_alpm_config (new_alpm_conf);
  364. }
  365. choose_ignorepkgs_dialog.destroy ();
  366. while (Gtk.events_pending ()) {
  367. Gtk.main_iteration ();
  368. }
  369. });
  370. }
  371. [GtkCallback]
  372. void on_remove_ignorepkgs_button_clicked () {
  373. Gtk.TreeIter? iter;
  374. Gtk.TreeSelection selection = ignorepkgs_treeview.get_selection ();
  375. if (selection.get_selected (null, out iter)) {
  376. ignorepkgs_liststore.remove (ref iter);
  377. var ignorepkg_string = new StringBuilder ();
  378. ignorepkgs_liststore.foreach ((model, path, iter) => {
  379. GLib.Value name;
  380. model.get_value (iter, 0, out name);
  381. if (ignorepkg_string.len != 0) {
  382. ignorepkg_string.append (" ");
  383. }
  384. ignorepkg_string.append ((string) name);
  385. return false;
  386. });
  387. var new_alpm_conf = new HashTable<string,Variant> (str_hash, str_equal);
  388. new_alpm_conf.insert ("IgnorePkg", new Variant.string (ignorepkg_string.str));
  389. transaction.start_write_alpm_config (new_alpm_conf);
  390. }
  391. }
  392. void on_write_alpm_config_finished (bool checkspace) {
  393. check_space_button.state = checkspace;
  394. ignorepkgs_liststore.clear ();
  395. foreach (unowned string ignorepkg in transaction.get_ignorepkgs ()) {
  396. ignorepkgs_liststore.insert_with_values (null, -1, 0, ignorepkg);
  397. }
  398. }
  399. void on_mirrors_country_comboboxtext_changed () {
  400. var new_mirrors_conf = new HashTable<string,Variant> (str_hash, str_equal);
  401. var mirror_country = mirrors_country_comboboxtext.get_active_text ();
  402. if (mirror_country == dgettext (null, "Worldwide")) {
  403. mirror_country = "ALL";
  404. }
  405. new_mirrors_conf.insert ("OnlyCountry", new Variant.string (mirror_country) );
  406. transaction.start_write_mirrors_config (new_mirrors_conf);
  407. }
  408. void on_mirrors_list_generation_method_comboboxtext_changed () {
  409. var new_mirrors_conf = new HashTable<string,Variant> (str_hash, str_equal);
  410. if (mirrors_list_generation_method_comboboxtext.get_active_text () == dgettext (null, "Speed")){
  411. new_mirrors_conf.insert ("Method", new Variant.string ("rank"));
  412. } else {
  413. new_mirrors_conf.insert ("Method", new Variant.string ("random"));
  414. }
  415. transaction.start_write_mirrors_config (new_mirrors_conf);
  416. }
  417. void on_write_mirrors_config_finished (string choosen_country, string choosen_generation_method) {
  418. int index = 0;
  419. string choosen_country_ = dgettext (null, "Worldwide");
  420. if (choosen_country != "ALL") {
  421. choosen_country_ = choosen_country;
  422. }
  423. mirrors_country_comboboxtext.model.foreach ((model, path, iter) => {
  424. GLib.Value country;
  425. model.get_value (iter, 0, out country);
  426. if ((string) country == choosen_country_) {
  427. return true;
  428. }
  429. index += 1;
  430. return false;
  431. });
  432. mirrors_country_comboboxtext.active = index;
  433. if (choosen_generation_method == "rank") {
  434. mirrors_list_generation_method_comboboxtext.active = 0;
  435. } else {
  436. mirrors_list_generation_method_comboboxtext.active = 1;
  437. }
  438. generate_mirrors_list_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
  439. }
  440. [GtkCallback]
  441. void on_generate_mirrors_list_button_clicked () {
  442. transaction.start_generate_mirrors_list ();
  443. generate_mirrors_list_button.get_style_context ().remove_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
  444. }
  445. [GtkCallback]
  446. void on_cache_clean_button_clicked () {
  447. transaction.clean_cache (transaction.keep_num_pkgs, transaction.rm_only_uninstalled);
  448. }
  449. }
  450. }