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.

1771 lines
58KB

  1. /*
  2. * pamac-vala
  3. *
  4. * Copyright (C) 2014-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 2 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. const string VERSION = "3.2.1";
  20. namespace Pamac {
  21. struct SortInfo {
  22. public int column_number;
  23. public Gtk.SortType sort_type;
  24. }
  25. [GtkTemplate (ui = "/org/manjaro/pamac/manager/manager_window.ui")]
  26. class ManagerWindow : Gtk.ApplicationWindow {
  27. // icons
  28. public Gdk.Pixbuf? installed_icon;
  29. public Gdk.Pixbuf? uninstalled_icon;
  30. public Gdk.Pixbuf? to_install_icon;
  31. public Gdk.Pixbuf? to_reinstall_icon;
  32. public Gdk.Pixbuf? to_remove_icon;
  33. public Gdk.Pixbuf? locked_icon;
  34. // manager objects
  35. [GtkChild]
  36. Gtk.TreeView packages_treeview;
  37. [GtkChild]
  38. public Gtk.TreeViewColumn packages_state_column;
  39. [GtkChild]
  40. public Gtk.TreeViewColumn packages_name_column;
  41. [GtkChild]
  42. public Gtk.TreeViewColumn packages_version_column;
  43. [GtkChild]
  44. public Gtk.TreeViewColumn packages_repo_column;
  45. [GtkChild]
  46. public Gtk.TreeViewColumn packages_size_column;
  47. [GtkChild]
  48. Gtk.TreeView aur_treeview;
  49. [GtkChild]
  50. Gtk.ScrolledWindow aur_scrolledwindow;
  51. [GtkChild]
  52. public Gtk.TreeViewColumn aur_state_column;
  53. [GtkChild]
  54. public Gtk.TreeViewColumn aur_name_column;
  55. [GtkChild]
  56. public Gtk.TreeViewColumn aur_version_column;
  57. [GtkChild]
  58. public Gtk.TreeViewColumn aur_votes_column;
  59. [GtkChild]
  60. Gtk.Notebook filters_notebook;
  61. [GtkChild]
  62. Gtk.SearchEntry search_entry;
  63. [GtkChild]
  64. Gtk.TreeView search_treeview;
  65. [GtkChild]
  66. Gtk.TreeView groups_treeview;
  67. [GtkChild]
  68. Gtk.TreeView states_treeview;
  69. [GtkChild]
  70. Gtk.TreeView repos_treeview;
  71. [GtkChild]
  72. Gtk.Notebook packages_notebook;
  73. [GtkChild]
  74. Gtk.Notebook properties_notebook;
  75. [GtkChild]
  76. Gtk.TreeView deps_treeview;
  77. [GtkChild]
  78. Gtk.TreeView details_treeview;
  79. [GtkChild]
  80. Gtk.ScrolledWindow files_scrolledwindow;
  81. [GtkChild]
  82. Gtk.Label name_label;
  83. [GtkChild]
  84. Gtk.Label desc_label;
  85. [GtkChild]
  86. Gtk.Label link_label;
  87. [GtkChild]
  88. Gtk.Label licenses_label;
  89. [GtkChild]
  90. Gtk.TextView files_textview;
  91. [GtkChild]
  92. Gtk.Box search_aur_box;
  93. [GtkChild]
  94. Gtk.Switch search_aur_button;
  95. [GtkChild]
  96. Gtk.Button valid_button;
  97. [GtkChild]
  98. Gtk.Button cancel_button;
  99. // menu
  100. Gtk.Menu right_click_menu;
  101. Gtk.MenuItem deselect_item;
  102. Gtk.MenuItem install_item;
  103. Gtk.MenuItem remove_item;
  104. Gtk.MenuItem reinstall_item;
  105. Gtk.MenuItem install_optional_deps_item;
  106. Gtk.MenuItem explicitly_installed_item;
  107. Alpm.List<unowned Alpm.Package?> selected_pkgs;
  108. GLib.List<unowned Json.Object> selected_aur;
  109. // liststore
  110. Gtk.ListStore search_list;
  111. Gtk.ListStore groups_list;
  112. Gtk.ListStore states_list;
  113. Gtk.ListStore repos_list;
  114. Gtk.ListStore deps_list;
  115. Gtk.ListStore details_list;
  116. PackagesModel packages_list;
  117. AURModel aur_list;
  118. HashTable<string,Json.Array> aur_search_results;
  119. string current_package_path;
  120. string current_aur_path;
  121. public Transaction transaction;
  122. public SortInfo sortinfo;
  123. bool refreshing;
  124. uint search_entry_timeout_id;
  125. public ManagerWindow (Gtk.Application application) {
  126. Object (application: application);
  127. support_aur (false, false);
  128. refreshing = false;
  129. Timeout.add (100, populate_window);
  130. }
  131. bool populate_window () {
  132. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  133. right_click_menu = new Gtk.Menu ();
  134. deselect_item = new Gtk.MenuItem.with_label (dgettext (null, "Deselect"));
  135. deselect_item.activate.connect (on_deselect_item_activate);
  136. right_click_menu.append (deselect_item);
  137. install_item = new Gtk.MenuItem.with_label (dgettext (null, "Install"));
  138. install_item.activate.connect (on_install_item_activate);
  139. right_click_menu.append (install_item);
  140. remove_item = new Gtk.MenuItem.with_label (dgettext (null, "Remove"));
  141. remove_item.activate.connect (on_remove_item_activate);
  142. right_click_menu.append (remove_item);
  143. var separator_item = new Gtk.SeparatorMenuItem ();
  144. right_click_menu.append (separator_item);
  145. reinstall_item = new Gtk.MenuItem.with_label (dgettext (null, "Reinstall"));
  146. reinstall_item.activate.connect (on_reinstall_item_activate);
  147. right_click_menu.append (reinstall_item);
  148. install_optional_deps_item = new Gtk.MenuItem.with_label (dgettext (null, "Install optional dependencies"));
  149. install_optional_deps_item.activate.connect (on_install_optional_deps_item_activate);
  150. right_click_menu.append (install_optional_deps_item);
  151. explicitly_installed_item = new Gtk.MenuItem.with_label (dgettext (null, "Mark as explicitly installed"));
  152. explicitly_installed_item.activate.connect (on_explicitly_installed_item_activate);
  153. right_click_menu.append (explicitly_installed_item);
  154. right_click_menu.show_all ();
  155. search_list = new Gtk.ListStore (1, typeof (string));
  156. search_treeview.set_model (search_list);
  157. groups_list = new Gtk.ListStore (1, typeof (string));
  158. groups_treeview.set_model (groups_list);
  159. states_list = new Gtk.ListStore (1, typeof (string));
  160. states_treeview.set_model (states_list);
  161. repos_list = new Gtk.ListStore (1, typeof (string));
  162. repos_treeview.set_model (repos_list);
  163. deps_list = new Gtk.ListStore (2, typeof (string), typeof (string));
  164. deps_treeview.set_model (deps_list);
  165. details_list = new Gtk.ListStore (2, typeof (string), typeof (string));
  166. details_treeview.set_model (details_list);
  167. try {
  168. installed_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-installed-updated.png");
  169. uninstalled_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-available.png");
  170. to_install_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-install.png");
  171. to_reinstall_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-reinstall.png");
  172. to_remove_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-remove.png");
  173. locked_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-installed-locked.png");
  174. } catch (GLib.Error e) {
  175. stderr.printf (e.message);
  176. }
  177. transaction = new Transaction (this as Gtk.ApplicationWindow);
  178. transaction.mode = Mode.MANAGER;
  179. transaction.finished.connect (on_transaction_finished);
  180. transaction.write_pamac_config_finished.connect (on_write_pamac_config_finished);
  181. transaction.set_pkgreason_finished.connect (on_set_pkgreason_finished);
  182. unowned Alpm.Package? pkg = Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), "yaourt");
  183. if (pkg != null) {
  184. support_aur (transaction.pamac_config.enable_aur, transaction.pamac_config.search_aur);
  185. }
  186. set_buttons_sensitive (false);
  187. // sort by name by default
  188. sortinfo = {0, Gtk.SortType.ASCENDING};
  189. aur_search_results = new HashTable<string,Json.Array> (str_hash, str_equal);
  190. update_lists ();
  191. show_default_pkgs ();
  192. return false;
  193. }
  194. void on_write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
  195. bool enable_aur, bool search_aur) {
  196. if (recurse) {
  197. transaction.flags |= Alpm.TransFlag.RECURSE;
  198. }
  199. unowned Alpm.Package? pkg = Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), "yaourt");
  200. if (pkg != null) {
  201. support_aur (enable_aur, search_aur);
  202. }
  203. }
  204. void on_set_pkgreason_finished () {
  205. refresh_packages_list ();
  206. }
  207. void support_aur (bool enable_aur, bool search_aur) {
  208. if (enable_aur) {
  209. search_aur_button.set_active (search_aur);
  210. search_aur_box.set_visible (true);
  211. aur_scrolledwindow.set_visible (true);
  212. } else {
  213. search_aur_button.set_active (false);
  214. search_aur_box.set_visible (false);
  215. aur_scrolledwindow.set_visible (false);
  216. }
  217. }
  218. void set_buttons_sensitive (bool sensitive) {
  219. valid_button.set_sensitive (sensitive);
  220. cancel_button.set_sensitive (sensitive);
  221. }
  222. void show_default_pkgs () {
  223. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  224. get_installed_pkgs.begin ((obj, res) => {
  225. var pkgs = get_installed_pkgs.end (res);
  226. populate_packages_list ((owned) pkgs);
  227. });
  228. }
  229. void update_lists () {
  230. Gtk.TreeIter iter;
  231. Gtk.TreeSelection selection;
  232. selection = repos_treeview.get_selection ();
  233. selection.changed.disconnect (on_repos_treeview_selection_changed);
  234. var groups_names = new GLib.List<string> ();
  235. foreach (var db in transaction.alpm_utils.get_syncdbs ()) {
  236. repos_list.insert_with_values (out iter, -1, 0, db.name);
  237. foreach (var group in db.groupcache) {
  238. if (groups_names.find_custom (group.name, strcmp) == null) {
  239. groups_names.append (group.name);
  240. }
  241. }
  242. }
  243. repos_list.insert_with_values (out iter, -1, 0, dgettext (null, "local"));
  244. repos_list.get_iter_first (out iter);
  245. selection.select_iter (iter);
  246. selection.changed.connect_after (on_repos_treeview_selection_changed);
  247. selection = groups_treeview.get_selection ();
  248. selection.changed.disconnect (on_groups_treeview_selection_changed);
  249. foreach (var group in transaction.alpm_utils.get_localdb ().groupcache) {
  250. if (groups_names.find_custom (group.name, strcmp) == null) {
  251. groups_names.append (group.name);
  252. }
  253. }
  254. foreach (unowned string group_name in groups_names) {
  255. groups_list.insert_with_values (out iter, -1, 0, group_name);
  256. }
  257. groups_list.set_sort_column_id (0, Gtk.SortType.ASCENDING);
  258. groups_list.get_iter_first (out iter);
  259. selection.select_iter (iter);
  260. selection.changed.connect_after (on_groups_treeview_selection_changed);
  261. selection = states_treeview.get_selection ();
  262. selection.changed.disconnect (on_states_treeview_selection_changed);
  263. states_list.insert_with_values (out iter, -1, 0, dgettext (null, "Installed"));
  264. //states_list.insert_with_values (out iter, -1, 0, dgettext (null, "Uninstalled"));
  265. states_list.insert_with_values (out iter, -1, 0, dgettext (null, "Orphans"));
  266. states_list.insert_with_values (out iter, -1, 0, dgettext (null, "To install"));
  267. states_list.insert_with_values (out iter, -1, 0, dgettext (null, "To remove"));
  268. states_list.get_iter_first (out iter);
  269. selection.select_iter (iter);
  270. selection.changed.connect_after (on_states_treeview_selection_changed);
  271. }
  272. void set_package_infos_list (Alpm.Package pkg) {
  273. name_label.set_markup ("<big><b>%s %s</b></big>".printf (pkg.name, pkg.version));
  274. desc_label.set_markup (Markup.escape_text (pkg.desc));
  275. string url = Markup.escape_text (pkg.url);
  276. link_label.set_markup ("<a href=\"%s\">%s</a>".printf (url, url));
  277. StringBuilder licenses = new StringBuilder ();
  278. licenses.append (dgettext (null, "Licenses"));
  279. licenses.append (":");
  280. foreach (unowned string license in pkg.licenses) {
  281. licenses.append (" ");
  282. licenses.append (license);
  283. }
  284. licenses_label.set_markup (licenses.str);
  285. }
  286. async void set_aur_infos_list (Json.Object pkg_info) {
  287. unowned Json.Node? node;
  288. node = pkg_info.get_member ("Name");
  289. unowned string name = node.get_string ();
  290. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  291. Json.Object all_infos = yield transaction.get_aur_infos (name);
  292. this.get_window ().set_cursor (null);
  293. node = all_infos.get_member ("Version");
  294. name_label.set_markup ("<big><b>%s %s</b></big>".printf (name, node.get_string ()));
  295. node = all_infos.get_member ("Description");
  296. desc_label.set_markup (Markup.escape_text (node.get_string ()));
  297. string url = "";
  298. node = all_infos.get_member ("URL");
  299. if (!node.is_null ()) {
  300. url = Markup.escape_text (node.get_string ());
  301. }
  302. string aur_url = "http://aur.archlinux.org/packages/" + name;
  303. link_label.set_markup ("<a href=\"%s\">%s</a>\n\n<a href=\"%s\">%s</a>".printf (url, url, aur_url, aur_url));
  304. StringBuilder licenses = new StringBuilder ();
  305. licenses.append (dgettext (null, "Licenses"));
  306. licenses.append (":");
  307. node = all_infos.get_member ("License");
  308. if (node != null) {
  309. unowned Json.Array array = node.get_array ();
  310. uint i = 0;
  311. uint length = array.get_length ();
  312. while (i < length) {
  313. licenses.append (" ");
  314. licenses.append (array.get_string_element (i));
  315. i++;
  316. }
  317. } else {
  318. licenses.append (dgettext (null, "Unknown"));
  319. }
  320. licenses_label.set_markup (licenses.str);
  321. }
  322. void set_package_deps_list (Alpm.Package pkg) {
  323. deps_list.clear ();
  324. Gtk.TreeIter iter;
  325. unowned Alpm.List<unowned Alpm.Depend> deps = pkg.depends;
  326. unowned Alpm.List<unowned Alpm.Depend>? list;
  327. if (deps.length != 0) {
  328. list = deps;
  329. deps_list.insert_with_values (out iter, -1,
  330. 0, dgettext (null, "Depends On") + ":",
  331. 1, list.data.compute_string ());
  332. for (list = list.next (); list != null; list = list.next ()) {
  333. deps_list.insert_with_values (out iter, -1,
  334. 1, list.data.compute_string ());
  335. }
  336. }
  337. deps = pkg.optdepends;
  338. if (deps.length != 0) {
  339. list = deps;
  340. string optdep_str = list.data.compute_string ();
  341. var optdep = new StringBuilder (optdep_str);
  342. if (Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), optdep_str) != null) {
  343. optdep.append (" [");
  344. optdep.append (dgettext (null, "Installed"));
  345. optdep.append ("]");
  346. }
  347. deps_list.insert_with_values (out iter, -1,
  348. 0, dgettext (null, "Optional Dependencies") + ":",
  349. 1, optdep.str);
  350. for (list = list.next (); list != null; list = list.next ()) {
  351. optdep_str = list.data.compute_string ();
  352. optdep = new StringBuilder (optdep_str);
  353. if (Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), optdep_str) != null) {
  354. optdep.append (" [");
  355. optdep.append (dgettext (null, "Installed"));
  356. optdep.append ("]");
  357. }
  358. deps_list.insert_with_values (out iter, -1, 1, optdep.str);
  359. }
  360. }
  361. if (pkg.origin == Alpm.Package.From.LOCALDB) {
  362. Alpm.List<string> requiredby = pkg.compute_requiredby ();
  363. unowned Alpm.List<string>? list2;
  364. if (requiredby.length != 0) {
  365. list2 = requiredby;
  366. deps_list.insert_with_values (out iter, -1,
  367. 0, dgettext (null, "Required By") + ":",
  368. 1, list2.data);
  369. for (list2 = list2.next (); list2 != null; list2 = list2.next ()) {
  370. deps_list.insert_with_values (out iter, -1,
  371. 1, list2.data);
  372. }
  373. }
  374. requiredby.free_data ();
  375. Alpm.List<string> optionalfor = pkg.compute_optionalfor ();
  376. if (optionalfor.length != 0) {
  377. list2 = optionalfor;
  378. deps_list.insert_with_values (out iter, -1,
  379. 0, dgettext (null, "Optional For") + ":",
  380. 1, list2.data);
  381. for (list2 = list2.next (); list2 != null; list2 = list2.next ()) {
  382. deps_list.insert_with_values (out iter, -1,
  383. 1, list2.data);
  384. }
  385. }
  386. optionalfor.free_data ();
  387. }
  388. deps = pkg.provides;
  389. if (deps.length != 0) {
  390. list = deps;
  391. deps_list.insert_with_values (out iter, -1,
  392. 0, dgettext (null, "Provides") + ":",
  393. 1, list.data.compute_string ());
  394. for (list = list.next (); list != null; list = list.next ()) {
  395. deps_list.insert_with_values (out iter, -1,
  396. 1, list.data.compute_string ());
  397. }
  398. }
  399. deps = pkg.replaces;
  400. if (deps.length != 0) {
  401. list = deps;
  402. deps_list.insert_with_values (out iter, -1,
  403. 0, dgettext (null, "Replaces") + ":",
  404. 1, list.data.compute_string ());
  405. for (list = list.next (); list != null; list = list.next ()) {
  406. deps_list.insert_with_values (out iter, -1,
  407. 1, list.data.compute_string ());
  408. }
  409. }
  410. deps = pkg.conflicts;
  411. if (deps.length != 0) {
  412. list = deps;
  413. deps_list.insert_with_values (out iter, -1,
  414. 0, dgettext (null, "Conflicts With") + ":",
  415. 1, list.data.compute_string ());
  416. for (list = list.next (); list != null; list = list.next ()) {
  417. deps_list.insert_with_values (out iter, -1,
  418. 1, list.data.compute_string ());
  419. }
  420. }
  421. }
  422. async void set_aur_deps_list (Json.Object pkg_info) {
  423. deps_list.clear ();
  424. Gtk.TreeIter iter;
  425. unowned Json.Node? node;
  426. node = pkg_info.get_member ("Name");
  427. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  428. Json.Object all_infos = yield transaction.get_aur_infos (node.get_string ());
  429. this.get_window ().set_cursor (null);
  430. unowned Json.Array deps;
  431. uint i;
  432. uint length;
  433. node = all_infos.get_member ("Depends");
  434. if (node != null) {
  435. deps = node.get_array ();
  436. deps_list.insert_with_values (out iter, -1,
  437. 0, dgettext (null, "Depends On") + ":",
  438. 1, deps.get_string_element (0));
  439. i = 1;
  440. length = deps.get_length ();
  441. while (i < length) {
  442. deps_list.insert_with_values (out iter, -1,
  443. 1, deps.get_string_element (i));
  444. i++;
  445. }
  446. }
  447. node = all_infos.get_member ("MakeDepends");
  448. if (node != null) {
  449. deps = node.get_array ();
  450. deps_list.insert_with_values (out iter, -1,
  451. 0, dgettext (null, "Make Dependencies") + ":",
  452. 1, deps.get_string_element (0));
  453. i = 1;
  454. length = deps.get_length ();
  455. while (i < length) {
  456. deps_list.insert_with_values (out iter, -1,
  457. 1, deps.get_string_element (i));
  458. i++;
  459. }
  460. }
  461. node = all_infos.get_member ("CheckDepends");
  462. if (node != null) {
  463. deps = node.get_array ();
  464. deps_list.insert_with_values (out iter, -1,
  465. 0, dgettext (null, "Check Dependencies") + ":",
  466. 1, deps.get_string_element (0));
  467. i = 1;
  468. length = deps.get_length ();
  469. while (i < length) {
  470. deps_list.insert_with_values (out iter, -1,
  471. 1, deps.get_string_element (i));
  472. i++;
  473. }
  474. }
  475. node = all_infos.get_member ("OptDepends");
  476. if (node != null) {
  477. deps = node.get_array ();
  478. string optdep_str = deps.get_string_element (0);
  479. var optdep = new StringBuilder (optdep_str);
  480. if (Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), optdep_str) != null) {
  481. optdep.append (" [");
  482. optdep.append (dgettext (null, "Installed"));
  483. optdep.append ("]");
  484. }
  485. deps_list.insert_with_values (out iter, -1,
  486. 0, dgettext (null, "Optional Dependencies") + ":",
  487. 1, optdep.str);
  488. i = 1;
  489. length = deps.get_length ();
  490. while (i < length) {
  491. optdep_str = deps.get_string_element (i);
  492. optdep = new StringBuilder (optdep_str);
  493. if (Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), optdep_str.split (": ", 2)[0]) != null) {
  494. optdep.append (" [");
  495. optdep.append (dgettext (null, "Installed"));
  496. optdep.append ("]");
  497. }
  498. deps_list.insert_with_values (out iter, -1, 1, optdep.str);
  499. i++;
  500. }
  501. }
  502. node = all_infos.get_member ("Provides");
  503. if (node != null) {
  504. deps = node.get_array ();
  505. deps_list.insert_with_values (out iter, -1,
  506. 0, dgettext (null, "Provides") + ":",
  507. 1, deps.get_string_element (0));
  508. i = 1;
  509. length = deps.get_length ();
  510. while (i < length) {
  511. deps_list.insert_with_values (out iter, -1,
  512. 1, deps.get_string_element (i));
  513. i++;
  514. }
  515. }
  516. node = all_infos.get_member ("Replaces");
  517. if (node != null) {
  518. deps = node.get_array ();
  519. deps_list.insert_with_values (out iter, -1,
  520. 0, dgettext (null, "Replaces") + ":",
  521. 1, deps.get_string_element (0));
  522. i = 1;
  523. length = deps.get_length ();
  524. while (i < length) {
  525. deps_list.insert_with_values (out iter, -1,
  526. 1, deps.get_string_element (i));
  527. i++;
  528. }
  529. }
  530. node = all_infos.get_member ("Conflicts");
  531. if (node != null) {
  532. deps = node.get_array ();
  533. deps_list.insert_with_values (out iter, -1,
  534. 0, dgettext (null, "Conflicts With") + ":",
  535. 1, deps.get_string_element (0));
  536. i = 1;
  537. length = deps.get_length ();
  538. while (i < length) {
  539. deps_list.insert_with_values (out iter, -1,
  540. 1, deps.get_string_element (1));
  541. i++;
  542. }
  543. }
  544. }
  545. void set_package_details_list (Alpm.Package pkg) {
  546. details_list.clear ();
  547. Gtk.TreeIter iter;
  548. if (pkg.origin == Alpm.Package.From.SYNCDB) {
  549. details_list.insert_with_values (out iter, -1,
  550. 0, dgettext (null, "Repository") + ":",
  551. 1, pkg.db.name);
  552. }
  553. unowned Alpm.List<unowned string> groups = pkg.groups;
  554. if (groups.length != 0) {
  555. unowned Alpm.List<unowned string>? list = groups;
  556. details_list.insert_with_values (out iter, -1,
  557. 0, dgettext (null, "Groups") + ":",
  558. 1, list.data);
  559. for (list = list.next (); list != null; list = list.next ()) {
  560. details_list.insert_with_values (out iter, -1,
  561. 1, list.data);
  562. }
  563. }
  564. details_list.insert_with_values (out iter, -1,
  565. 0, dgettext (null, "Packager") + ":",
  566. 1, pkg.packager);
  567. GLib.Time time = GLib.Time.local ((time_t) pkg.builddate);
  568. string build_date = time.format ("%a %d %b %Y %X %Z");
  569. details_list.insert_with_values (out iter, -1,
  570. 0, dgettext (null, "Build Date") + ":",
  571. 1, build_date);
  572. if (pkg.origin == Alpm.Package.From.LOCALDB) {
  573. time = GLib.Time.local ((time_t) pkg.installdate);
  574. string install_date = time.format ("%a %d %b %Y %X %Z");
  575. details_list.insert_with_values (out iter, -1,
  576. 0, dgettext (null, "Install Date") + ":",
  577. 1, install_date);
  578. string reason;
  579. if (pkg.reason == Alpm.Package.Reason.EXPLICIT) {
  580. reason = dgettext (null, "Explicitly installed");
  581. } else if (pkg.reason == Alpm.Package.Reason.DEPEND) {
  582. reason = dgettext (null, "Installed as a dependency for another package");
  583. } else {
  584. reason = dgettext (null, "Unknown");
  585. }
  586. details_list.insert_with_values (out iter, -1,
  587. 0, dgettext (null, "Install Reason") + ":",
  588. 1, reason);
  589. }
  590. if (pkg.origin == Alpm.Package.From.SYNCDB) {
  591. string has_signature = pkg.base64_sig != null ? dgettext (null, "Yes") : dgettext (null, "No");
  592. details_list.insert_with_values (out iter, -1,
  593. 0, dgettext (null, "Signatures") + ":",
  594. 1, has_signature);
  595. }
  596. if (pkg.origin == Alpm.Package.From.LOCALDB) {
  597. unowned Alpm.List<unowned Alpm.Backup> backups = pkg.backups;
  598. if (backups.length != 0) {
  599. unowned Alpm.List<unowned Alpm.Backup>? list = backups;
  600. details_list.insert_with_values (out iter, -1,
  601. 0, dgettext (null, "Backup files") + ":",
  602. 1, "/" + list.data.name);
  603. for (list = list.next (); list != null; list = list.next ()) {
  604. details_list.insert_with_values (out iter, -1,
  605. 1, "/" + list.data.name);
  606. }
  607. }
  608. }
  609. }
  610. void set_aur_details_list (Json.Object pkg_info) {
  611. details_list.clear ();
  612. Gtk.TreeIter iter;
  613. unowned Json.Node? node;
  614. node = pkg_info.get_member ("PackageBase");
  615. unowned string package_base = node.get_string ();
  616. node = pkg_info.get_member ("Name");
  617. if (package_base != node.get_string ()) {
  618. details_list.insert_with_values (out iter, -1,
  619. 0, dgettext (null, "Package Base") + ":",
  620. 1, package_base);
  621. }
  622. node = pkg_info.get_member ("Maintainer");
  623. details_list.insert_with_values (out iter, -1,
  624. 0, dgettext (null, "Maintainer") + ":",
  625. 1, node.get_string());
  626. node = pkg_info.get_member ("FirstSubmitted");
  627. GLib.Time time = GLib.Time.local ((time_t) node.get_int ());
  628. details_list.insert_with_values (out iter, -1,
  629. 0, dgettext (null, "First Submitted") + ":",
  630. 1, time.format ("%a %d %b %Y %X %Z"));
  631. node = pkg_info.get_member ("LastModified");
  632. time = GLib.Time.local ((time_t) node.get_int ());
  633. details_list.insert_with_values (out iter, -1,
  634. 0, dgettext (null, "Last Modified") + ":",
  635. 1, time.format ("%a %d %b %Y %X %Z"));
  636. node = pkg_info.get_member ("NumVotes");
  637. details_list.insert_with_values (out iter, -1,
  638. 0, dgettext (null, "Votes") + ":",
  639. 1, node.get_int ().to_string ());
  640. node = pkg_info.get_member ("OutOfDate");
  641. if (!node.is_null ()) {
  642. time = GLib.Time.local ((time_t) node.get_int ());
  643. details_list.insert_with_values (out iter, -1,
  644. 0, dgettext (null, "Out of Date") + ":",
  645. 1, time.format ("%a %d %b %Y %X %Z"));
  646. }
  647. }
  648. void set_package_files_list (Alpm.Package pkg) {
  649. StringBuilder text = new StringBuilder ();
  650. foreach (var file in pkg.files) {
  651. if (text.len != 0) {
  652. text.append ("\n");
  653. }
  654. text.append ("/");
  655. text.append (file.name);
  656. }
  657. files_textview.buffer.set_text (text.str, (int) text.len);
  658. }
  659. void populate_packages_list (owned Alpm.List<unowned Alpm.Package?>? pkgs) {
  660. Gtk.TreeSelection selection = packages_treeview.get_selection ();
  661. selection.changed.disconnect (on_packages_treeview_selection_changed);
  662. // populate liststore
  663. packages_list = new PackagesModel ((owned) pkgs, this);
  664. // sort liststore
  665. int column = sortinfo.column_number;
  666. switch (column) {
  667. case 0:
  668. packages_list.sort_by_name (sortinfo.sort_type);
  669. break;
  670. case 1:
  671. packages_list.sort_by_state (sortinfo.sort_type);
  672. break;
  673. case 2:
  674. packages_list.sort_by_version (sortinfo.sort_type);
  675. break;
  676. case 3:
  677. packages_list.sort_by_repo (sortinfo.sort_type);
  678. break;
  679. case 4:
  680. packages_list.sort_by_size (sortinfo.sort_type);
  681. break;
  682. default:
  683. break;
  684. }
  685. packages_treeview.set_model (packages_list);
  686. selection.changed.connect (on_packages_treeview_selection_changed);
  687. display_package_properties ();
  688. this.get_window ().set_cursor (null);
  689. }
  690. void populate_aur_list (Json.Array? pkgs_infos) {
  691. Gtk.TreeSelection selection = aur_treeview.get_selection ();
  692. selection.changed.disconnect (on_aur_treeview_selection_changed);
  693. // populate liststore
  694. aur_list = new AURModel (pkgs_infos, this);
  695. // sort liststore
  696. int column = sortinfo.column_number;
  697. switch (column) {
  698. case 0:
  699. aur_list.sort_by_name (sortinfo.sort_type);
  700. break;
  701. case 1:
  702. aur_list.sort_by_state (sortinfo.sort_type);
  703. break;
  704. case 2:
  705. aur_list.sort_by_version (sortinfo.sort_type);
  706. break;
  707. case 3:
  708. aur_list.sort_by_votes (sortinfo.sort_type);
  709. break;
  710. default:
  711. break;
  712. }
  713. aur_treeview.set_model (aur_list);
  714. selection.changed.connect (on_aur_treeview_selection_changed);
  715. display_package_properties();
  716. this.get_window ().set_cursor (null);
  717. }
  718. void refresh_packages_list () {
  719. switch (filters_notebook.get_current_page ()) {
  720. case 0:
  721. if (search_aur_button.get_active ()) {
  722. aur_scrolledwindow.set_visible (true);
  723. }
  724. Gtk.TreeSelection selection = search_treeview.get_selection ();
  725. if (selection.get_selected (null, null)) {
  726. on_search_treeview_selection_changed ();
  727. } else {
  728. show_default_pkgs ();
  729. }
  730. break;
  731. case 1:
  732. aur_scrolledwindow.set_visible (false);
  733. on_groups_treeview_selection_changed ();
  734. break;
  735. case 2:
  736. aur_scrolledwindow.set_visible (false);
  737. on_states_treeview_selection_changed ();
  738. break;
  739. case 3:
  740. aur_scrolledwindow.set_visible (false);
  741. on_repos_treeview_selection_changed ();
  742. break;
  743. default:
  744. break;
  745. }
  746. }
  747. void display_package_properties () {
  748. switch (packages_notebook.get_current_page ()) {
  749. case 0:
  750. Gtk.TreeSelection selection = packages_treeview.get_selection ();
  751. GLib.List<Gtk.TreePath> selected = selection.get_selected_rows (null);
  752. unowned GLib.List<Gtk.TreePath>? first_element = selected.nth (0);
  753. if (first_element == null) {
  754. Gtk.TreeIter? iter;
  755. if (current_package_path == null) {
  756. packages_list.get_iter_first (out iter);
  757. selection.select_iter (iter);
  758. current_package_path = packages_list.get_path (iter).to_string ();
  759. } else {
  760. // check if current_package_path is valid else select first iter
  761. if (packages_list.get_iter_from_string (out iter, current_package_path)) {
  762. selection.select_iter (iter);
  763. } else {
  764. packages_list.get_iter_first (out iter);
  765. selection.select_iter (iter);
  766. current_package_path = packages_list.get_path (iter).to_string ();
  767. }
  768. }
  769. } else {
  770. // display info for the first package of the selection
  771. current_package_path = first_element.data.to_string ();
  772. }
  773. unowned Alpm.Package? pkg = packages_list.get_pkg_at_path (new Gtk.TreePath.from_string (current_package_path));
  774. if (pkg == null) {
  775. return;
  776. }
  777. if (pkg.origin == Alpm.Package.From.LOCALDB) {
  778. files_scrolledwindow.visible = true;
  779. } else {
  780. files_scrolledwindow.visible = false;
  781. }
  782. switch (properties_notebook.get_current_page ()) {
  783. case 0:
  784. set_package_infos_list (pkg);
  785. break;
  786. case 1:
  787. set_package_deps_list (pkg);
  788. break;
  789. case 2:
  790. set_package_details_list (pkg);
  791. break;
  792. case 3:
  793. if (pkg.origin == Alpm.Package.From.LOCALDB) {
  794. set_package_files_list (pkg);
  795. }
  796. break;
  797. default:
  798. break;
  799. }
  800. break;
  801. case 1:
  802. Gtk.TreeSelection selection = aur_treeview.get_selection ();
  803. GLib.List<Gtk.TreePath> selected = selection.get_selected_rows (null);
  804. unowned GLib.List<Gtk.TreePath>? first_element = selected.nth (0);
  805. if (first_element == null) {
  806. Gtk.TreeIter? iter;
  807. if (current_aur_path == null) {
  808. aur_list.get_iter_first (out iter);
  809. selection.select_iter (iter);
  810. current_aur_path = aur_list.get_path (iter).to_string ();
  811. } else {
  812. // check if current_package_path is valid else select first iter
  813. if (aur_list.get_iter_from_string (out iter, current_aur_path)) {
  814. selection.select_iter (iter);
  815. } else {
  816. aur_list.get_iter_first (out iter);
  817. selection.select_iter (iter);
  818. current_aur_path = aur_list.get_path (iter).to_string ();
  819. }
  820. }
  821. } else {
  822. // display info for the first package of the selection
  823. current_aur_path = first_element.data.to_string ();
  824. }
  825. unowned Json.Object? pkg_info = aur_list.get_pkg_at_path (new Gtk.TreePath.from_string (current_aur_path));
  826. if (pkg_info == null) {
  827. return;
  828. }
  829. unowned Alpm.Package? pkg = transaction.alpm_utils.get_installed_pkg (pkg_info.get_string_member ("Name"));
  830. if (pkg == null) {
  831. files_scrolledwindow.visible = false;
  832. switch (properties_notebook.get_current_page ()) {
  833. case 0:
  834. set_aur_infos_list.begin (pkg_info);
  835. break;
  836. case 1:
  837. set_aur_deps_list.begin (pkg_info);
  838. break;
  839. case 2:
  840. set_aur_details_list (pkg_info);
  841. break;
  842. case 3:
  843. break;
  844. default:
  845. break;
  846. }
  847. } else {
  848. files_scrolledwindow.visible = true;
  849. switch (properties_notebook.get_current_page ()) {
  850. case 0:
  851. set_package_infos_list (pkg);
  852. break;
  853. case 1:
  854. set_package_deps_list (pkg);
  855. break;
  856. case 2:
  857. set_package_details_list (pkg);
  858. break;
  859. case 3:
  860. set_package_files_list (pkg);
  861. break;
  862. default:
  863. break;
  864. }
  865. }
  866. break;
  867. default:
  868. break;
  869. }
  870. }
  871. [GtkCallback]
  872. void on_packages_treeview_selection_changed () {
  873. display_package_properties ();
  874. }
  875. [GtkCallback]
  876. void on_aur_treeview_selection_changed () {
  877. display_package_properties ();
  878. }
  879. [GtkCallback]
  880. void on_properties_notebook_switch_page (Gtk.Widget page, uint page_num) {
  881. display_package_properties ();
  882. }
  883. [GtkCallback]
  884. void on_packages_treeview_row_activated (Gtk.TreeView treeview, Gtk.TreePath path, Gtk.TreeViewColumn column) {
  885. unowned Alpm.Package? pkg = packages_list.get_pkg_at_path (path);
  886. if (pkg != null) {
  887. if (transaction.to_add.remove (pkg.name)) {
  888. } else if (transaction.to_remove.remove (pkg.name)) {
  889. } else {
  890. if (pkg.origin == Alpm.Package.From.LOCALDB) {
  891. if (transaction.alpm_utils.get_holdpkgs ().find_custom (pkg.name, strcmp) == null) {
  892. transaction.to_remove.add (pkg.name);
  893. }
  894. } else {
  895. transaction.to_add.add (pkg.name);
  896. }
  897. }
  898. }
  899. if ((transaction.to_add.length == 0) && (transaction.to_remove.length == 0)) {
  900. set_buttons_sensitive (false);
  901. } else {
  902. set_buttons_sensitive (true);
  903. }
  904. // force a display refresh
  905. packages_treeview.queue_draw ();
  906. }
  907. [GtkCallback]
  908. void on_aur_treeview_row_activated (Gtk.TreeView treeview, Gtk.TreePath path, Gtk.TreeViewColumn column) {
  909. unowned Json.Object? pkg_info = aur_list.get_pkg_at_path (path);
  910. if (pkg_info != null) {
  911. unowned Alpm.Package? pkg = transaction.alpm_utils.get_installed_pkg (pkg_info.get_string_member ("Name"));
  912. if (pkg != null) {
  913. if (pkg.origin == Alpm.Package.From.LOCALDB) {
  914. if (transaction.alpm_utils.get_holdpkgs ().find_custom (pkg.name, strcmp) == null) {
  915. transaction.to_remove.add (pkg.name);
  916. }
  917. }
  918. } else if (transaction.to_build.remove (pkg_info.get_string_member ("Name"))) {
  919. } else {
  920. transaction.to_build.add (pkg_info.get_string_member ("Name"));
  921. }
  922. }
  923. if ((transaction.to_build.length == 0) && (transaction.to_remove.length == 0)) {
  924. set_buttons_sensitive (false);
  925. } else {
  926. set_buttons_sensitive (true);
  927. }
  928. // force a display refresh
  929. aur_treeview.queue_draw ();
  930. }
  931. void on_install_item_activate () {
  932. foreach (var pkg in selected_pkgs) {
  933. if (pkg.origin == Alpm.Package.From.SYNCDB) {
  934. transaction.to_add.add (pkg.name);
  935. }
  936. }
  937. foreach (var pkg_info in selected_aur) {
  938. transaction.to_build.add (pkg_info.get_string_member ("Name"));
  939. }
  940. if (transaction.to_add.length != 0 || transaction.to_build.length != 0) {
  941. set_buttons_sensitive (true);
  942. }
  943. }
  944. void on_reinstall_item_activate () {
  945. foreach (var pkg in selected_pkgs) {
  946. transaction.to_remove.remove (pkg.name);
  947. if (pkg.origin == Alpm.Package.From.LOCALDB) {
  948. transaction.to_add.add (pkg.name);
  949. }
  950. }
  951. if (transaction.to_add.length != 0) {
  952. set_buttons_sensitive (true);
  953. }
  954. }
  955. void on_remove_item_activate () {
  956. foreach (var pkg in selected_pkgs) {
  957. transaction.to_add.remove (pkg.name);
  958. if (transaction.alpm_utils.get_holdpkgs ().find_custom (pkg.name, strcmp) == null) {
  959. if (pkg.origin == Alpm.Package.From.LOCALDB) {
  960. transaction.to_remove.add (pkg.name);
  961. }
  962. }
  963. }
  964. if (transaction.to_remove.length != 0) {
  965. set_buttons_sensitive (true);
  966. }
  967. }
  968. void on_deselect_item_activate () {
  969. foreach (var pkg in selected_pkgs) {
  970. if (transaction.to_add.remove (pkg.name)) {
  971. } else {
  972. transaction.to_remove.remove (pkg.name);
  973. }
  974. }
  975. foreach (var pkg_info in selected_aur) {
  976. transaction.to_build.remove (pkg_info.get_string_member ("Name"));
  977. }
  978. if ((transaction.to_add.length == 0)
  979. && (transaction.to_remove.length == 0)
  980. && (transaction.to_load.length == 0)
  981. && (transaction.to_build.length == 0)) {
  982. set_buttons_sensitive (false);
  983. }
  984. }
  985. void choose_opt_dep (Alpm.List<unowned Alpm.Package?> pkgs) {
  986. foreach (var pkg in pkgs) {
  987. var choose_dep_dialog = new ChooseDependenciesDialog (this);
  988. Gtk.TreeIter iter;
  989. int length = 0;
  990. foreach (var optdep in pkg.optdepends) {
  991. if (Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), optdep.name) == null) {
  992. length++;
  993. choose_dep_dialog.deps_list.insert_with_values (out iter, -1,
  994. 0, false,
  995. 1, optdep.name,
  996. 2, optdep.desc);
  997. }
  998. }
  999. choose_dep_dialog.label.set_markup ("<b>%s</b>".printf (
  1000. ngettext ("%s has %u uninstalled optional dependency.\nChoose if you would like to install it",
  1001. "%s has %u uninstalled optional dependencies.\nChoose those you would like to install", length).printf (pkg.name, length)));
  1002. if (choose_dep_dialog.run () == Gtk.ResponseType.OK) {
  1003. choose_dep_dialog.deps_list.foreach ((model, path, iter) => {
  1004. GLib.Value val;
  1005. // get value at column 0 to know if it is selected
  1006. choose_dep_dialog.deps_list.get_value (iter, 0, out val);
  1007. if ((bool) val) {
  1008. // get value at column 1 to get the pkg name
  1009. choose_dep_dialog.deps_list.get_value (iter, 1, out val);
  1010. unowned Alpm.Package? sync_pkg = transaction.alpm_utils.get_sync_pkg ((string) val);
  1011. if (sync_pkg != null) {
  1012. transaction.to_add.add (sync_pkg.name);
  1013. }
  1014. }
  1015. return false;
  1016. });
  1017. }
  1018. choose_dep_dialog.destroy ();
  1019. while (Gtk.events_pending ()) {
  1020. Gtk.main_iteration ();
  1021. }
  1022. }
  1023. }
  1024. void on_install_optional_deps_item_activate () {
  1025. choose_opt_dep (selected_pkgs);
  1026. if (transaction.to_add.length != 0) {
  1027. set_buttons_sensitive (true);
  1028. }
  1029. }
  1030. void on_explicitly_installed_item_activate () {
  1031. foreach (var pkg in selected_pkgs) {
  1032. transaction.start_set_pkgreason (pkg.name, Alpm.Package.Reason.EXPLICIT);
  1033. }
  1034. }
  1035. async void search_in_aur (string search_string) {
  1036. if (!aur_search_results.contains (search_string)) {
  1037. Json.Array results = AUR.search (search_string.split (" "));
  1038. aur_search_results.insert (search_string, results);
  1039. }
  1040. }
  1041. [GtkCallback]
  1042. void on_packages_notebook_switch_page (Gtk.Widget page, uint page_num) {
  1043. Gtk.TreeModel model;
  1044. Gtk.TreeIter? iter;
  1045. Gtk.TreeSelection selection = search_treeview.get_selection ();
  1046. if (selection.get_selected (out model, out iter)) {
  1047. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  1048. GLib.Value val;
  1049. model.get_value (iter, 0, out val);
  1050. string search_string = val.get_string ();
  1051. switch (packages_notebook.get_current_page ()) {
  1052. case 0:
  1053. search_all_dbs.begin (search_string, (obj, res) => {
  1054. var pkgs = search_all_dbs.end (res);
  1055. populate_packages_list ((owned) pkgs);
  1056. });
  1057. break;
  1058. case 1:
  1059. search_in_aur.begin (search_string, (obj, res) => {
  1060. populate_aur_list (aur_search_results.lookup (search_string));
  1061. });
  1062. break;
  1063. default:
  1064. break;
  1065. }
  1066. }
  1067. }
  1068. [GtkCallback]
  1069. bool on_packages_treeview_button_press_event (Gdk.EventButton event) {
  1070. packages_treeview.grab_focus ();
  1071. // Check if right mouse button was clicked
  1072. if (event.type == Gdk.EventType.BUTTON_PRESS && event.button == 3) {
  1073. Gtk.TreePath? treepath;
  1074. unowned Alpm.Package? clicked_pkg;
  1075. Gtk.TreeSelection selection = packages_treeview.get_selection ();
  1076. packages_treeview.get_path_at_pos ((int) event.x, (int) event.y, out treepath, null, null, null);
  1077. clicked_pkg = packages_list.get_pkg_at_path (treepath);
  1078. if (clicked_pkg == null) {
  1079. return true;
  1080. }
  1081. if (!selection.path_is_selected (treepath)) {
  1082. selection.unselect_all ();
  1083. selection.select_path (treepath);
  1084. }
  1085. GLib.List<Gtk.TreePath> selected_paths = selection.get_selected_rows (null);
  1086. deselect_item.set_sensitive (false);
  1087. install_item.set_sensitive (false);
  1088. remove_item.set_sensitive (false);
  1089. reinstall_item.set_sensitive (false);
  1090. install_optional_deps_item.set_sensitive (false);
  1091. explicitly_installed_item.set_sensitive (false);
  1092. selected_pkgs = new Alpm.List<unowned Alpm.Package?> ();
  1093. foreach (unowned Gtk.TreePath path in selected_paths) {
  1094. selected_pkgs.add (packages_list.get_pkg_at_path (path));
  1095. }
  1096. foreach (var pkg in selected_pkgs) {
  1097. if (transaction.to_add.contains (pkg.name)
  1098. || transaction.to_remove.contains (pkg.name)) {
  1099. deselect_item.set_sensitive (true);
  1100. break;
  1101. }
  1102. }
  1103. foreach (var pkg in selected_pkgs) {
  1104. if (pkg.origin == Alpm.Package.From.SYNCDB) {
  1105. install_item.set_sensitive (true);
  1106. break;
  1107. }
  1108. }
  1109. foreach (var pkg in selected_pkgs) {
  1110. if (pkg.origin == Alpm.Package.From.LOCALDB) {
  1111. remove_item.set_sensitive (true);
  1112. break;
  1113. }
  1114. }
  1115. if (selected_pkgs.length == 1) {
  1116. clicked_pkg = selected_pkgs.data;
  1117. if (clicked_pkg.origin == Alpm.Package.From.LOCALDB) {
  1118. foreach (var optdep in clicked_pkg.optdepends) {
  1119. if (Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), optdep.name) == null) {
  1120. install_optional_deps_item.set_sensitive (true);
  1121. break;
  1122. }
  1123. }
  1124. if (clicked_pkg.reason == Alpm.Package.Reason.DEPEND) {
  1125. explicitly_installed_item.set_sensitive (true);
  1126. }
  1127. unowned Alpm.Package? find_pkg = transaction.alpm_utils.get_sync_pkg (clicked_pkg.name);
  1128. if (find_pkg != null) {
  1129. if (Alpm.pkg_vercmp (find_pkg.version, clicked_pkg.version) == 0) {
  1130. reinstall_item.set_sensitive (true);
  1131. }
  1132. }
  1133. }
  1134. }
  1135. right_click_menu.popup (null, null, null, event.button, event.time);
  1136. return true;
  1137. } else {
  1138. return false;
  1139. }
  1140. }
  1141. [GtkCallback]
  1142. bool on_aur_treeview_button_press_event (Gdk.EventButton event) {
  1143. aur_treeview.grab_focus ();
  1144. // Check if right mouse button was clicked
  1145. if (event.type == Gdk.EventType.BUTTON_PRESS && event.button == 3) {
  1146. Gtk.TreePath? treepath;
  1147. unowned Json.Object? clicked_pkg_info;
  1148. Gtk.TreeSelection selection = aur_treeview.get_selection ();
  1149. aur_treeview.get_path_at_pos ((int) event.x, (int) event.y, out treepath, null, null, null);
  1150. clicked_pkg_info = aur_list.get_pkg_at_path (treepath);
  1151. if (clicked_pkg_info == null) {
  1152. return true;
  1153. }
  1154. if (!selection.path_is_selected (treepath)) {
  1155. selection.unselect_all ();
  1156. selection.select_path (treepath);
  1157. }
  1158. GLib.List<Gtk.TreePath> selected_paths = selection.get_selected_rows (null);
  1159. deselect_item.set_sensitive (false);
  1160. install_item.set_sensitive (false);
  1161. remove_item.set_sensitive (false);
  1162. reinstall_item.set_sensitive (false);
  1163. install_optional_deps_item.set_sensitive (false);
  1164. explicitly_installed_item.set_sensitive (false);
  1165. selected_pkgs = new Alpm.List<unowned Alpm.Package?> ();
  1166. selected_aur = new GLib.List<unowned Json.Object> ();
  1167. foreach (unowned Gtk.TreePath path in selected_paths) {
  1168. unowned Alpm.Package? pkg = transaction.alpm_utils.get_installed_pkg (clicked_pkg_info.get_string_member ("Name"));
  1169. if (pkg != null) {
  1170. selected_pkgs.add (pkg);
  1171. // there is for sure a pkg to remove
  1172. remove_item.set_sensitive (true);
  1173. } else {
  1174. selected_aur.append (aur_list.get_pkg_at_path (path));
  1175. }
  1176. }
  1177. foreach (var pkg_info in selected_aur) {
  1178. if (transaction.to_build.contains (pkg_info.get_string_member ("Name"))) {
  1179. deselect_item.set_sensitive (true);
  1180. break;
  1181. }
  1182. }
  1183. foreach (var pkg_info in selected_aur) {
  1184. if (!transaction.to_build.contains (pkg_info.get_string_member ("Name"))) {
  1185. install_item.set_sensitive (true);
  1186. break;
  1187. }
  1188. }
  1189. foreach (var pkg in selected_pkgs) {
  1190. if (transaction.to_remove.contains (pkg.name)) {
  1191. deselect_item.set_sensitive (true);
  1192. break;
  1193. }
  1194. }
  1195. right_click_menu.popup (null, null, null, event.button, event.time);
  1196. return true;
  1197. } else {
  1198. return false;
  1199. }
  1200. }
  1201. [GtkCallback]
  1202. void on_packages_name_column_clicked () {
  1203. Gtk.SortType new_order;
  1204. if (!packages_name_column.sort_indicator) {
  1205. new_order = Gtk.SortType.ASCENDING;
  1206. } else {
  1207. if (sortinfo.sort_type == Gtk.SortType.ASCENDING) {
  1208. new_order = Gtk.SortType.DESCENDING;
  1209. } else {
  1210. new_order = Gtk.SortType.ASCENDING;
  1211. }
  1212. }
  1213. packages_list.sort_by_name (new_order);
  1214. // force a display refresh
  1215. packages_treeview.queue_draw ();
  1216. }
  1217. [GtkCallback]
  1218. void on_aur_name_column_clicked () {
  1219. Gtk.SortType new_order;
  1220. if (!aur_name_column.sort_indicator) {
  1221. new_order = Gtk.SortType.ASCENDING;
  1222. } else {
  1223. if (sortinfo.sort_type == Gtk.SortType.ASCENDING) {
  1224. new_order = Gtk.SortType.DESCENDING;
  1225. } else {
  1226. new_order = Gtk.SortType.ASCENDING;
  1227. }
  1228. }
  1229. aur_list.sort_by_name (new_order);
  1230. // force a display refresh
  1231. aur_treeview.queue_draw ();
  1232. }
  1233. [GtkCallback]
  1234. void on_packages_state_column_clicked () {
  1235. Gtk.SortType new_order;
  1236. if (!packages_state_column.sort_indicator) {
  1237. new_order = Gtk.SortType.ASCENDING;
  1238. } else {
  1239. if (sortinfo.sort_type == Gtk.SortType.ASCENDING) {
  1240. new_order = Gtk.SortType.DESCENDING;
  1241. } else {
  1242. new_order = Gtk.SortType.ASCENDING;
  1243. }
  1244. }
  1245. packages_list.sort_by_state (new_order);
  1246. // force a display refresh
  1247. packages_treeview.queue_draw ();
  1248. }
  1249. [GtkCallback]
  1250. void on_aur_state_column_clicked () {
  1251. Gtk.SortType new_order;
  1252. if (!aur_state_column.sort_indicator) {
  1253. new_order = Gtk.SortType.ASCENDING;
  1254. } else {
  1255. if (sortinfo.sort_type == Gtk.SortType.ASCENDING) {
  1256. new_order = Gtk.SortType.DESCENDING;
  1257. } else {
  1258. new_order = Gtk.SortType.ASCENDING;
  1259. }
  1260. }
  1261. aur_list.sort_by_state (new_order);
  1262. // force a display refresh
  1263. aur_treeview.queue_draw ();
  1264. }
  1265. [GtkCallback]
  1266. void on_packages_version_column_clicked () {
  1267. Gtk.SortType new_order;
  1268. if (!packages_version_column.sort_indicator) {
  1269. new_order = Gtk.SortType.ASCENDING;
  1270. } else {
  1271. if (sortinfo.sort_type == Gtk.SortType.ASCENDING) {
  1272. new_order = Gtk.SortType.DESCENDING;
  1273. } else {
  1274. new_order = Gtk.SortType.ASCENDING;
  1275. }
  1276. }
  1277. packages_list.sort_by_version (new_order);
  1278. // force a display refresh
  1279. packages_treeview.queue_draw ();
  1280. }
  1281. [GtkCallback]
  1282. void on_aur_version_column_clicked () {
  1283. Gtk.SortType new_order;
  1284. if (!aur_version_column.sort_indicator) {
  1285. new_order = Gtk.SortType.ASCENDING;
  1286. } else {
  1287. if (sortinfo.sort_type == Gtk.SortType.ASCENDING) {
  1288. new_order = Gtk.SortType.DESCENDING;
  1289. } else {
  1290. new_order = Gtk.SortType.ASCENDING;
  1291. }
  1292. }
  1293. aur_list.sort_by_version (new_order);
  1294. // force a display refresh
  1295. aur_treeview.queue_draw ();
  1296. }
  1297. [GtkCallback]
  1298. void on_packages_repo_column_clicked () {
  1299. Gtk.SortType new_order;
  1300. if (!packages_repo_column.sort_indicator) {
  1301. new_order = Gtk.SortType.ASCENDING;
  1302. } else {
  1303. if (sortinfo.sort_type == Gtk.SortType.ASCENDING) {
  1304. new_order = Gtk.SortType.DESCENDING;
  1305. } else {
  1306. new_order = Gtk.SortType.ASCENDING;
  1307. }
  1308. }
  1309. packages_list.sort_by_repo (new_order);
  1310. // force a display refresh
  1311. packages_treeview.queue_draw ();
  1312. }
  1313. [GtkCallback]
  1314. void on_packages_size_column_clicked () {
  1315. Gtk.SortType new_order;
  1316. if (!packages_size_column.sort_indicator) {
  1317. new_order = Gtk.SortType.ASCENDING;
  1318. } else {
  1319. if (sortinfo.sort_type == Gtk.SortType.ASCENDING) {
  1320. new_order = Gtk.SortType.DESCENDING;
  1321. } else {
  1322. new_order = Gtk.SortType.ASCENDING;
  1323. }
  1324. }
  1325. packages_list.sort_by_size (new_order);
  1326. // force a display refresh
  1327. packages_treeview.queue_draw ();
  1328. }
  1329. [GtkCallback]
  1330. void on_aur_votes_column_clicked () {
  1331. Gtk.SortType new_order;
  1332. if (!aur_votes_column.sort_indicator) {
  1333. new_order = Gtk.SortType.ASCENDING;
  1334. } else {
  1335. if (sortinfo.sort_type == Gtk.SortType.ASCENDING) {
  1336. new_order = Gtk.SortType.DESCENDING;
  1337. } else {
  1338. new_order = Gtk.SortType.ASCENDING;
  1339. }
  1340. }
  1341. aur_list.sort_by_votes (new_order);
  1342. // force a display refresh
  1343. aur_treeview.queue_draw ();
  1344. }
  1345. [GtkCallback]
  1346. void on_search_entry_activate () {
  1347. unowned string search_string = search_entry.get_text ();
  1348. if (search_string != "") {
  1349. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  1350. Gtk.TreeModel model;
  1351. Gtk.TreeIter? iter;
  1352. Gtk.TreeSelection selection = search_treeview.get_selection ();
  1353. // add search string in search_list if needed
  1354. bool found = false;
  1355. // check if search string is already selected in search list
  1356. if (selection.get_selected (out model, out iter)) {
  1357. GLib.Value selected_string;
  1358. model.get_value (iter, 0, out selected_string);
  1359. if ((string) selected_string == search_string) {
  1360. on_search_treeview_selection_changed ();
  1361. found = true;
  1362. }
  1363. }
  1364. // check if search string exists in search list
  1365. if (!found) {
  1366. search_list.foreach ((_model, _path, _iter) => {
  1367. GLib.Value line;
  1368. _model.get_value (_iter, 0, out line);
  1369. if ((string) line == search_string) {
  1370. found = true;
  1371. // we select the iter in search_list
  1372. // it will populate the list with the selection changed signal
  1373. selection.select_iter (_iter);
  1374. }
  1375. return found;
  1376. });
  1377. }
  1378. if (!found) {
  1379. search_list.insert_with_values (out iter, -1, 0, search_string);
  1380. // we select the iter in search_list
  1381. // it will populate the list with the selection changed signal
  1382. selection.select_iter (iter);
  1383. }
  1384. }
  1385. }
  1386. bool search_entry_timeout_callback () {
  1387. on_search_entry_activate ();
  1388. search_entry_timeout_id = 0;
  1389. return false;
  1390. }
  1391. [GtkCallback]
  1392. void on_search_entry_changed () {
  1393. if (search_entry.get_text () != "") {
  1394. if (search_entry_timeout_id != 0) {
  1395. Source.remove (search_entry_timeout_id);
  1396. }
  1397. search_entry_timeout_id = Timeout.add (750, search_entry_timeout_callback);
  1398. }
  1399. }
  1400. async Alpm.List<unowned Alpm.Package?> search_all_dbs (string search_string) {
  1401. return transaction.alpm_utils.search_all_dbs (search_string);
  1402. }
  1403. async Alpm.List<unowned Alpm.Package?> get_group_pkgs (string group_name) {
  1404. return transaction.alpm_utils.get_group_pkgs (group_name);
  1405. }
  1406. async Alpm.List<unowned Alpm.Package?> get_installed_pkgs () {
  1407. return transaction.alpm_utils.get_installed_pkgs ();
  1408. }
  1409. async Alpm.List<unowned Alpm.Package?> get_orphans () {
  1410. return transaction.alpm_utils.get_orphans ();
  1411. }
  1412. async Alpm.List<unowned Alpm.Package?> get_local_pkgs () {
  1413. return transaction.alpm_utils.get_local_pkgs ();
  1414. }
  1415. async Alpm.List<unowned Alpm.Package?> get_repo_pkgs (string repo_name) {
  1416. return transaction.alpm_utils.get_repo_pkgs (repo_name);
  1417. }
  1418. [GtkCallback]
  1419. void on_search_treeview_selection_changed () {
  1420. Gtk.TreeModel model;
  1421. Gtk.TreeIter? iter;
  1422. Gtk.TreeSelection selection = search_treeview.get_selection ();
  1423. if (selection.get_selected (out model, out iter)) {
  1424. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  1425. GLib.Value val;
  1426. model.get_value (iter, 0, out val);
  1427. string search_string = val.get_string ();
  1428. switch (packages_notebook.get_current_page ()) {
  1429. case 0:
  1430. search_all_dbs.begin (search_string, (obj, res) => {
  1431. var pkgs = search_all_dbs.end (res);
  1432. if (search_aur_button.get_active ()) {
  1433. search_in_aur.begin (search_string, (obj, res) => {
  1434. if (pkgs.length == 0) {
  1435. if (aur_search_results.lookup (search_string) != null) {
  1436. packages_notebook.set_current_page (1);
  1437. }
  1438. } else {
  1439. if (aur_search_results.lookup (search_string) != null) {
  1440. }
  1441. }
  1442. populate_packages_list ((owned) pkgs);
  1443. });
  1444. } else {
  1445. populate_packages_list ((owned) pkgs);
  1446. }
  1447. });
  1448. break;
  1449. case 1:
  1450. search_in_aur.begin (search_string, (obj, res) => {
  1451. populate_aur_list (aur_search_results.lookup (search_string));
  1452. });
  1453. break;
  1454. default:
  1455. break;
  1456. }
  1457. }
  1458. }
  1459. [GtkCallback]
  1460. void on_groups_treeview_selection_changed () {
  1461. Gtk.TreeModel model;
  1462. Gtk.TreeIter? iter;
  1463. Gtk.TreeSelection selection = groups_treeview.get_selection ();
  1464. if (selection.get_selected (out model, out iter)) {
  1465. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  1466. GLib.Value grp_name;
  1467. model.get_value (iter, 0, out grp_name);
  1468. get_group_pkgs.begin ((string) grp_name, (obj, res) => {
  1469. var pkgs = get_group_pkgs.end (res);
  1470. populate_packages_list ((owned) pkgs);
  1471. });
  1472. }
  1473. }
  1474. [GtkCallback]
  1475. void on_states_treeview_selection_changed () {
  1476. Gtk.TreeModel model;
  1477. Gtk.TreeIter? treeiter;
  1478. Gtk.TreeSelection selection = states_treeview.get_selection ();
  1479. if (selection.get_selected (out model, out treeiter)) {
  1480. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  1481. GLib.Value val;
  1482. model.get_value (treeiter, 0, out val);
  1483. unowned string state = val.get_string ();
  1484. if (state == dgettext (null, "To install")) {
  1485. var pkgs = new Alpm.List<unowned Alpm.Package?> ();
  1486. foreach (unowned string pkgname in transaction.to_add) {
  1487. unowned Alpm.Package? pkg = transaction.alpm_utils.get_installed_pkg (pkgname);
  1488. if (pkg == null) {
  1489. pkg = transaction.alpm_utils.get_sync_pkg (pkgname);
  1490. }
  1491. if (pkg != null) {
  1492. pkgs.add (pkg);
  1493. }
  1494. }
  1495. populate_packages_list ((owned) pkgs);
  1496. } else if (state == dgettext (null, "To remove")) {
  1497. var pkgs = new Alpm.List<unowned Alpm.Package?> ();
  1498. foreach (unowned string pkgname in transaction.to_remove) {
  1499. unowned Alpm.Package? pkg = transaction.alpm_utils.get_installed_pkg (pkgname);
  1500. if (pkg != null) {
  1501. pkgs.add (pkg);
  1502. }
  1503. }
  1504. populate_packages_list ((owned) pkgs);
  1505. } else if (state == dgettext (null, "Installed")) {
  1506. get_installed_pkgs.begin ((obj, res) => {
  1507. var pkgs = get_installed_pkgs.end (res);
  1508. populate_packages_list ((owned) pkgs);
  1509. });
  1510. } else if (state == dgettext (null, "Uninstalled")) {
  1511. //get_sync_pkgs.begin ((obj, res) => {
  1512. //var pkgs = get_sync_pkgs.end (res);
  1513. //populate_packages_list ((owned) pkgs);
  1514. //});
  1515. } else if (state == dgettext (null, "Orphans")) {
  1516. get_orphans.begin ((obj, res) => {
  1517. var pkgs = get_orphans.end (res);
  1518. populate_packages_list ((owned) pkgs);
  1519. });
  1520. }
  1521. }
  1522. }
  1523. [GtkCallback]
  1524. void on_repos_treeview_selection_changed () {
  1525. Gtk.TreeModel model;
  1526. Gtk.TreeIter? iter;
  1527. Gtk.TreeSelection selection = repos_treeview.get_selection ();
  1528. if (selection.get_selected (out model, out iter)) {
  1529. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  1530. GLib.Value val;
  1531. model.get_value (iter, 0, out val);
  1532. unowned string repo = val.get_string ();
  1533. if (repo == dgettext (null, "local")) {
  1534. get_local_pkgs.begin ((obj, res) => {
  1535. var pkgs = get_local_pkgs.end (res);
  1536. populate_packages_list ((owned) pkgs);
  1537. });
  1538. } else {
  1539. get_repo_pkgs.begin (repo, (obj, res) => {
  1540. var pkgs = get_repo_pkgs.end (res);
  1541. populate_packages_list ((owned) pkgs);
  1542. });
  1543. }
  1544. }
  1545. }
  1546. [GtkCallback]
  1547. void on_filters_notebook_switch_page (Gtk.Widget page, uint page_num) {
  1548. refresh_packages_list ();
  1549. }
  1550. [GtkCallback]
  1551. void on_history_item_activate () {
  1552. var file = GLib.File.new_for_path ("/var/log/pamac.log");
  1553. if (!file.query_exists ()) {
  1554. GLib.stderr.printf ("File '%s' doesn't exist.\n", file.get_path ());
  1555. } else {
  1556. StringBuilder text = new StringBuilder ();
  1557. try {
  1558. // Open file for reading and wrap returned FileInputStream into a
  1559. // DataInputStream, so we can read line by line
  1560. var dis = new DataInputStream (file.read ());
  1561. string line;
  1562. // Read lines until end of file (null) is reached
  1563. while ((line = dis.read_line ()) != null) {
  1564. // construct text in reverse order
  1565. text.prepend (line + "\n");
  1566. }
  1567. } catch (GLib.Error e) {
  1568. GLib.stderr.printf ("%s\n", e.message);
  1569. }
  1570. var history_dialog = new HistoryDialog (this);
  1571. history_dialog.textview.buffer.set_text (text.str, (int) text.len);
  1572. history_dialog.show ();
  1573. history_dialog.response.connect (() => {
  1574. history_dialog.destroy ();
  1575. });
  1576. while (Gtk.events_pending ()) {
  1577. Gtk.main_iteration ();
  1578. }
  1579. }
  1580. }
  1581. [GtkCallback]
  1582. void on_local_item_activate () {
  1583. Gtk.FileChooserDialog chooser = new Gtk.FileChooserDialog (
  1584. dgettext (null, "Install Local Packages"), this, Gtk.FileChooserAction.OPEN,
  1585. dgettext (null, "_Cancel"), Gtk.ResponseType.CANCEL,
  1586. dgettext (null, "_Open"),Gtk.ResponseType.ACCEPT);
  1587. chooser.window_position = Gtk.WindowPosition.CENTER_ON_PARENT;
  1588. chooser.icon_name = "system-software-install";
  1589. chooser.default_width = 900;
  1590. chooser.select_multiple = true;
  1591. chooser.local_only = false;
  1592. chooser.create_folders = false;
  1593. Gtk.FileFilter package_filter = new Gtk.FileFilter ();
  1594. package_filter.set_filter_name (dgettext (null, "Alpm Package"));
  1595. package_filter.add_pattern ("*.pkg.tar.xz");
  1596. chooser.add_filter (package_filter);
  1597. if (chooser.run () == Gtk.ResponseType.ACCEPT) {
  1598. SList<string> packages_paths = chooser.get_filenames ();
  1599. if (packages_paths.length () != 0) {
  1600. foreach (unowned string path in packages_paths) {
  1601. transaction.to_load.add (path);
  1602. }
  1603. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  1604. chooser.destroy ();
  1605. while (Gtk.events_pending ()) {
  1606. Gtk.main_iteration ();
  1607. }
  1608. transaction.run ();
  1609. }
  1610. } else {
  1611. chooser.destroy ();
  1612. while (Gtk.events_pending ()) {
  1613. Gtk.main_iteration ();
  1614. }
  1615. }
  1616. }
  1617. [GtkCallback]
  1618. void on_preferences_item_activate () {
  1619. transaction.run_preferences_dialog.begin ();
  1620. }
  1621. [GtkCallback]
  1622. void on_about_item_activate () {
  1623. Gtk.show_about_dialog (
  1624. this,
  1625. "program_name", "Pamac",
  1626. "logo_icon_name", "system-software-install",
  1627. "comments", dgettext (null, "A Gtk3 frontend for libalpm"),
  1628. "copyright", "Copyright © 2016 Guillaume Benoit",
  1629. "version", VERSION,
  1630. "license_type", Gtk.License.GPL_3_0,
  1631. "website", "http://manjaro.org");
  1632. }
  1633. [GtkCallback]
  1634. void on_valid_button_clicked () {
  1635. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  1636. transaction.run ();
  1637. }
  1638. [GtkCallback]
  1639. void on_cancel_button_clicked () {
  1640. transaction.clear_lists ();
  1641. set_buttons_sensitive (false);
  1642. // force a display refresh
  1643. packages_treeview.queue_draw ();
  1644. aur_treeview.queue_draw ();
  1645. }
  1646. [GtkCallback]
  1647. void on_refresh_button_clicked () {
  1648. this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
  1649. refreshing = true;
  1650. transaction.start_refresh (false);
  1651. }
  1652. void on_transaction_finished (bool success) {
  1653. if (transaction.to_add.length == 0
  1654. && transaction.to_remove.length == 0
  1655. && transaction.to_load.length == 0
  1656. && transaction.to_build.length == 0) {
  1657. set_buttons_sensitive (false);
  1658. }
  1659. refresh_packages_list ();
  1660. transaction.to_load.remove_all ();
  1661. if (refreshing) {
  1662. if (success) {
  1663. transaction.sysupgrade (false);
  1664. }
  1665. refreshing = false;
  1666. }
  1667. }
  1668. }
  1669. }