From 6e3724f67fd80a027aa5d17cc64bd4bd3a3b43f8 Mon Sep 17 00:00:00 2001 From: guinux <nuxgui@gmail.com> Date: Wed, 25 Oct 2017 10:30:21 +0200 Subject: [PATCH] v6.2.0 --- resources/manager_window.ui | 100 ++++++--- src/manager_window.vala | 408 ++++++++++++++++++++++++------------ src/user_daemon.vala | 29 +++ vapi/appstream-glib.vapi | 2 +- 4 files changed, 379 insertions(+), 160 deletions(-) diff --git a/resources/manager_window.ui b/resources/manager_window.ui index 60144b10..3a6d3ec2 100644 --- a/resources/manager_window.ui +++ b/resources/manager_window.ui @@ -125,10 +125,23 @@ <property name="transition_duration">250</property> <property name="transition_type">slide-left-right</property> <child> - <object class="GtkStackSidebar" id="filters_stacksidebar"> + <object class="GtkScrolledWindow" id="filters_scrolledwindow"> <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="stack">filters_stack</property> + <property name="can_focus">True</property> + <child> + <object class="GtkViewport" id="filters_viewport"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkListBox" id="filters_listbox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="selection_mode">none</property> + <signal name="row-activated" handler="on_filters_listbox_row_activated" swapped="no"/> + </object> + </child> + </object> + </child> </object> <packing> <property name="name">filters</property> @@ -138,7 +151,6 @@ <object class="GtkScrolledWindow" id="categories_scrolledwindow"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="shadow_type">in</property> <child> <object class="GtkViewport" id="categories_viewport"> <property name="visible">True</property> @@ -147,6 +159,7 @@ <object class="GtkListBox" id="categories_listbox"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="selection_mode">browse</property> <signal name="row-activated" handler="on_categories_listbox_row_activated" swapped="no"/> </object> </child> @@ -155,7 +168,6 @@ </object> <packing> <property name="name">categories</property> - <property name="title" translatable="yes">Categories</property> <property name="position">1</property> </packing> </child> @@ -163,7 +175,6 @@ <object class="GtkScrolledWindow" id="groups_scrolledwindow"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="shadow_type">in</property> <child> <object class="GtkViewport" id="groups_viewport"> <property name="visible">True</property> @@ -172,6 +183,7 @@ <object class="GtkListBox" id="groups_listbox"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="selection_mode">browse</property> <signal name="row-activated" handler="on_groups_listbox_row_activated" swapped="no"/> </object> </child> @@ -180,7 +192,6 @@ </object> <packing> <property name="name">groups</property> - <property name="title" translatable="yes">Groups</property> <property name="position">2</property> </packing> </child> @@ -188,7 +199,6 @@ <object class="GtkScrolledWindow" id="repos_scrolledwindow"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="shadow_type">in</property> <child> <object class="GtkViewport" id="repos_viewport"> <property name="visible">True</property> @@ -197,6 +207,7 @@ <object class="GtkListBox" id="repos_listbox"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="selection_mode">browse</property> <signal name="row-activated" handler="on_repos_listbox_row_activated" swapped="no"/> </object> </child> @@ -205,7 +216,6 @@ </object> <packing> <property name="name">repos</property> - <property name="title" translatable="yes">Repositories</property> <property name="position">3</property> </packing> </child> @@ -213,7 +223,6 @@ <object class="GtkScrolledWindow" id="installed_scrolledwindow"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="shadow_type">in</property> <child> <object class="GtkViewport" id="installed_viewport"> <property name="visible">True</property> @@ -222,6 +231,7 @@ <object class="GtkListBox" id="installed_listbox"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="selection_mode">browse</property> <signal name="row-activated" handler="on_installed_listbox_row_activated" swapped="no"/> </object> </child> @@ -230,39 +240,39 @@ </object> <packing> <property name="name">installed</property> - <property name="title" translatable="yes">Installed</property> <property name="position">4</property> </packing> </child> <child> - <object class="GtkStackSidebar" id="updates_stacksidebar"> + <object class="GtkListBox" id="updates_listbox"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="stack">origin_stack</property> + <property name="selection_mode">browse</property> + <signal name="row-activated" handler="on_updates_listbox_row_activated" swapped="no"/> </object> <packing> <property name="name">updates</property> - <property name="title" translatable="yes">Updates</property> <property name="position">5</property> </packing> </child> <child> - <object class="GtkStackSidebar" id="pending_stacksidebar"> + <object class="GtkListBox" id="pending_listbox"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="stack">origin_stack</property> + <property name="selection_mode">browse</property> + <signal name="row-activated" handler="on_pending_listbox_row_activated" swapped="no"/> </object> <packing> <property name="name">pending</property> - <property name="title" translatable="yes">Pending</property> <property name="position">6</property> </packing> </child> <child> - <object class="GtkStackSidebar" id="search_stacksidebar"> + <object class="GtkListBox" id="search_listbox"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="stack">origin_stack</property> + <property name="selection_mode">browse</property> + <signal name="row-activated" handler="on_search_listbox_row_activated" swapped="no"/> </object> <packing> <property name="name">search</property> @@ -445,7 +455,6 @@ </object> <packing> <property name="name">repos</property> - <property name="title" translatable="yes">Repositories</property> </packing> </child> <child> @@ -553,7 +562,6 @@ </object> <packing> <property name="name">aur</property> - <property name="title" translatable="yes">AUR</property> <property name="position">1</property> </packing> </child> @@ -562,6 +570,7 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="orientation">vertical</property> + <property name="spacing">6</property> <property name="homogeneous">True</property> <child> <object class="GtkImage" id="updated_icon"> @@ -600,6 +609,7 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="orientation">vertical</property> + <property name="spacing">6</property> <property name="homogeneous">True</property> <child> <object class="GtkImage" id="no_item_icon"> @@ -633,6 +643,44 @@ <property name="position">3</property> </packing> </child> + <child> + <object class="GtkBox" id="checking_box"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="spacing">12</property> + <property name="homogeneous">True</property> + <child> + <object class="GtkSpinner" id="checking_spinner"> + <property name="height_request">40</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="valign">end</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="checking_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="valign">start</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="name">checking</property> + <property name="position">4</property> + </packing> + </child> </object> <packing> <property name="expand">True</property> @@ -658,12 +706,11 @@ <property name="visible">True</property> <property name="can_focus">False</property> <child> - <object class="GtkStackSidebar" id="properties_stacksidebar"> + <object class="GtkListBox" id="properties_listbox"> <property name="width_request">175</property> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="halign">center</property> - <property name="stack">properties_stack</property> + <signal name="row-activated" handler="on_properties_listbox_row_activated" swapped="no"/> </object> <packing> <property name="expand">False</property> @@ -955,7 +1002,6 @@ </object> <packing> <property name="name">details</property> - <property name="title" translatable="yes">Details</property> </packing> </child> <child> @@ -1008,7 +1054,6 @@ </object> <packing> <property name="name">deps</property> - <property name="title" translatable="yes">Dependencies</property> <property name="position">1</property> </packing> </child> @@ -1031,7 +1076,6 @@ </object> <packing> <property name="name">files</property> - <property name="title" translatable="yes">Files</property> <property name="position">2</property> </packing> </child> @@ -1167,7 +1211,7 @@ <object class="GtkBox" id="header_left_buttonbox"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="spacing">18</property> + <property name="spacing">32</property> <child> <object class="GtkButton" id="button_back"> <property name="visible">True</property> diff --git a/src/manager_window.vala b/src/manager_window.vala index 7640d020..f01cae34 100644 --- a/src/manager_window.vala +++ b/src/manager_window.vala @@ -17,7 +17,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -const string VERSION = "6.1.2"; +const string VERSION = "6.2.0"; namespace Pamac { @@ -73,10 +73,6 @@ namespace Pamac { [GtkChild] public Gtk.Stack filters_stack; [GtkChild] - Gtk.StackSidebar updates_stacksidebar; - [GtkChild] - Gtk.StackSidebar pending_stacksidebar; - [GtkChild] public Gtk.ToggleButton search_button; [GtkChild] Gtk.SearchBar searchbar; @@ -85,6 +81,8 @@ namespace Pamac { [GtkChild] Gtk.Entry search_entry; [GtkChild] + Gtk.ListBox filters_listbox; + [GtkChild] Gtk.ListBox categories_listbox; [GtkChild] Gtk.ListBox groups_listbox; @@ -95,6 +93,12 @@ namespace Pamac { [GtkChild] Gtk.Stack origin_stack; [GtkChild] + Gtk.ListBox updates_listbox; + [GtkChild] + Gtk.ListBox pending_listbox; + [GtkChild] + Gtk.ListBox search_listbox; + [GtkChild] Gtk.ScrolledWindow packages_scrolledwindow; [GtkChild] Gtk.ScrolledWindow aur_scrolledwindow; @@ -103,9 +107,13 @@ namespace Pamac { [GtkChild] Gtk.Label no_item_label; [GtkChild] + Gtk.Label checking_label; + [GtkChild] + Gtk.Spinner checking_spinner; + [GtkChild] Gtk.Stack properties_stack; [GtkChild] - Gtk.StackSidebar properties_stacksidebar; + Gtk.ListBox properties_listbox; [GtkChild] Gtk.Grid deps_grid; [GtkChild] @@ -183,13 +191,14 @@ namespace Pamac { uint search_entry_timeout_id; string search_string; + Gtk.Label pending_label; + Gtk.ListBoxRow pending_row; public ManagerWindow (Gtk.Application application) { Object (application: application); button_back.visible = false; select_all_button.visible = false; - pending_stacksidebar.visible = false; searchbar.connect_entry (search_entry); refreshing = false; important_details = false; @@ -197,9 +206,9 @@ namespace Pamac { sysupgrade_running = false; generate_mirrors_list = false; - this.title = dgettext (null, "Package Manager"); - updated_label.set_markup ("<b>%s</b>".printf (dgettext (null, "Your system is up-to-date"))); - no_item_label.set_markup ("<b>%s</b>".printf (dgettext (null, "No package found"))); + updated_label.set_markup ("<big><b>%s</b></big>".printf (dgettext (null, "Your system is up-to-date"))); + no_item_label.set_markup ("<big><b>%s</b></big>".printf (dgettext (null, "No package found"))); + checking_label.set_markup ("<big><b>%s</b></big>".printf (dgettext (null, "Checking for Updates"))); this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); while (Gtk.events_pending ()) { Gtk.main_iteration (); @@ -488,8 +497,7 @@ namespace Pamac { uint total_pending = transaction.to_install.length + transaction.to_remove.length + transaction.to_build.length; if (total_pending == 0) { if (filters_stack.visible_child_name != "pending") { - pending_stacksidebar.visible = false; - updates_stacksidebar.visible = true; + active_pending_row (false); } transaction.progress_box.action_label.label = ""; cancel_button.sensitive = false; @@ -498,13 +506,7 @@ namespace Pamac { show_transaction_infobox (); } } else { - updates_stacksidebar.visible = false; - pending_stacksidebar.visible = true; - var attention_val = GLib.Value (typeof (bool)); - attention_val.set_boolean (true); - filters_stack.child_set_property (filters_stack.get_child_by_name ("pending"), - "needs-attention", - attention_val); + active_pending_row (true); string info = dngettext (null, "%u pending operation", "%u pending operations", total_pending).printf (total_pending); transaction.progress_box.action_label.label = info; cancel_button.sensitive = true; @@ -526,7 +528,7 @@ namespace Pamac { Gtk.Label create_list_label (string str) { var label = new Gtk.Label (str); label.visible = true; - label.margin = 8; + label.margin = 12; label.xalign = 0; return label; } @@ -537,20 +539,41 @@ namespace Pamac { return strcmp (label1.label, label2.label); } + void active_pending_row (bool active) { + pending_row.activatable = active; + pending_label.sensitive = active; + } + public void update_lists () { Gtk.Label label; + label = create_list_label (dgettext (null, "Categories")); + filters_listbox.add (label); + label = create_list_label (dgettext (null, "Groups")); + filters_listbox.add (label); + label = create_list_label (dgettext (null, "Repositories")); + filters_listbox.add (label); + label = create_list_label (dgettext (null, "Installed")); + filters_listbox.add (label); + label = create_list_label (dgettext (null, "Updates")); + filters_listbox.add (label); + pending_label = create_list_label (dgettext (null, "Pending")); + pending_row = new Gtk.ListBoxRow (); + pending_row.visible = true; + pending_row.add (pending_label); + filters_listbox.add (pending_row); + active_pending_row (false); + filters_listbox.get_style_context ().add_class (Gtk.STYLE_CLASS_SIDEBAR); + foreach (unowned string repo in transaction.get_repos_names ()) { label = create_list_label (repo); repos_listbox.add (label); } - repos_listbox.select_row (repos_listbox.get_row_at_index (0)); foreach (unowned string group in transaction.get_groups_names ()) { label = create_list_label (group); groups_listbox.add (label); } groups_listbox.set_sort_func (sort_list_row); - groups_listbox.select_row (groups_listbox.get_row_at_index (0)); label = create_list_label (dgettext (null, "Installed")); installed_listbox.add (label); @@ -560,7 +583,6 @@ namespace Pamac { installed_listbox.add (label); label = create_list_label (dgettext (null, "Foreign")); installed_listbox.add (label); - installed_listbox.select_row (installed_listbox.get_row_at_index (0)); label = create_list_label (dgettext (null, "Accessories")); categories_listbox.add (label); @@ -585,7 +607,26 @@ namespace Pamac { label = create_list_label (dgettext (null, "System Tools")); categories_listbox.add (label); categories_listbox.set_sort_func (sort_list_row); - categories_listbox.select_row (categories_listbox.get_row_at_index (0)); + + label = create_list_label (dgettext (null, "Repositories")); + updates_listbox.add (label); + label = create_list_label (dgettext (null, "AUR")); + updates_listbox.add (label); + label = create_list_label (dgettext (null, "Repositories")); + pending_listbox.add (label); + label = create_list_label (dgettext (null, "AUR")); + pending_listbox.add (label); + label = create_list_label (dgettext (null, "Repositories")); + search_listbox.add (label); + label = create_list_label (dgettext (null, "AUR")); + search_listbox.add (label); + + label = create_list_label (dgettext (null, "Details")); + properties_listbox.add (label); + label = create_list_label (dgettext (null, "Dependencies")); + properties_listbox.add (label); + label = create_list_label (dgettext (null, "Files")); + properties_listbox.add (label); } void on_mark_explicit_button_clicked (Gtk.Button button) { @@ -936,7 +977,7 @@ namespace Pamac { remove_togglebutton.visible = false; reinstall_togglebutton.visible = false; install_togglebutton.visible = false; - properties_stacksidebar.visible = false; + properties_listbox.visible = false; details_grid.foreach (destroy_widget); deps_grid.foreach (destroy_widget); this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); @@ -968,7 +1009,7 @@ namespace Pamac { remove_togglebutton.active = transaction.to_remove.contains (pkg.name); } // details - properties_stacksidebar.visible = true; + properties_listbox.visible = true; details_grid.foreach (destroy_widget); Gtk.Widget? previous_widget = null; if (details.packagebase != details.name) { @@ -1027,6 +1068,24 @@ namespace Pamac { }); } + [GtkCallback] + void on_properties_listbox_row_activated (Gtk.ListBoxRow row) { + int index = row.get_index (); + switch (index) { + case 0: // details + properties_stack.visible_child_name = "details"; + break; + case 1: // deps + properties_stack.visible_child_name = "deps"; + break; + case 2: // files + properties_stack.visible_child_name = "files"; + break; + default: + break; + } + } + [GtkCallback] void on_install_togglebutton_toggled () { if (install_togglebutton.active) { @@ -1220,12 +1279,13 @@ namespace Pamac { if (filters_stack.visible_child_name != "pending") { uint total_pending = transaction.to_install.length + transaction.to_remove.length + transaction.to_build.length; if (total_pending == 0) { - pending_stacksidebar.visible = false; - updates_stacksidebar.visible = true; + active_pending_row (false); } } switch (filters_stack.visible_child_name) { case "filters": + this.title = dgettext (null, "Package Manager"); + filters_listbox.select_row (null); header_filter_label.set_markup (""); search_button.active = false; restore_packages_sort_order (); @@ -1234,7 +1294,7 @@ namespace Pamac { show_default_pkgs (); break; case "categories": - header_filter_label.set_markup ("<b>%s</b>".printf (dgettext (null, "Categories"))); + header_filter_label.label = dgettext (null, "Categories"); search_button.active = false; restore_packages_sort_order (); show_sidebar (); @@ -1242,6 +1302,7 @@ namespace Pamac { on_categories_listbox_row_activated (categories_listbox.get_selected_row ()); break; case "search": + this.title = dgettext (null, "Search"); header_filter_label.set_markup (""); save_packages_sort_order (); set_pendings_operations (); @@ -1265,7 +1326,7 @@ namespace Pamac { } break; case "groups": - header_filter_label.set_markup ("<b>%s</b>".printf (dgettext (null, "Groups"))); + header_filter_label.label = dgettext (null, "Groups"); search_button.active = false; restore_packages_sort_order (); show_sidebar (); @@ -1273,7 +1334,7 @@ namespace Pamac { on_groups_listbox_row_activated (groups_listbox.get_selected_row ()); break; case "installed": - header_filter_label.set_markup ("<b>%s</b>".printf (dgettext (null, "Installed"))); + header_filter_label.label = dgettext (null, "Installed"); search_button.active = false; restore_packages_sort_order (); show_sidebar (); @@ -1281,7 +1342,7 @@ namespace Pamac { on_installed_listbox_row_activated (installed_listbox.get_selected_row ()); break; case "repos": - header_filter_label.set_markup ("<b>%s</b>".printf (dgettext (null, "Repositories"))); + header_filter_label.label = dgettext (null, "Repositories"); search_button.active = false; restore_packages_sort_order (); show_sidebar (); @@ -1289,25 +1350,24 @@ namespace Pamac { on_repos_listbox_row_activated (repos_listbox.get_selected_row ()); break; case "updates": + this.title = dgettext (null, "Updates"); header_filter_label.set_markup (""); search_button.active = false; save_packages_sort_order (); // order updates by name packages_list.set_sort_column_id (2, Gtk.SortType.ASCENDING); hide_sidebar (); + origin_stack.visible_child_name = "checking"; + checking_spinner.active = true; packages_list.clear (); aur_list.clear (); select_all_button.visible = false; - var attention_val = GLib.Value (typeof (bool)); - attention_val.set_boolean (false); - filters_stack.child_set_property (filters_stack.get_child_by_name ("updates"), - "needs-attention", - attention_val); apply_button.sensitive = false; this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); transaction.start_get_updates (); break; case "pending": + this.title = dgettext (null, "Pending"); header_filter_label.set_markup (""); search_button.active = false; save_packages_sort_order (); @@ -1318,11 +1378,6 @@ namespace Pamac { } else { hide_sidebar (); } - var attention_val = GLib.Value (typeof (bool)); - attention_val.set_boolean (false); - filters_stack.child_set_property (filters_stack.get_child_by_name ("pending"), - "needs-attention", - attention_val); AlpmPackage[] pkgs = {}; foreach (unowned string pkgname in transaction.to_install) { AlpmPackage pkg = transaction.get_installed_pkg (pkgname); @@ -1652,54 +1707,119 @@ namespace Pamac { } void on_origin_stack_visible_child_changed () { - switch (origin_stack.visible_child_name) { - case "repos": - if (filters_stack.visible_child_name == "search") { - Timeout.add (200, () => { - search_entry.grab_focus_without_selecting (); - search_entry.set_position (-1); - return false; - }); - if (search_string == null) { - return; - } - this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); - while (Gtk.events_pending ()) { - Gtk.main_iteration (); - } - transaction.search_pkgs.begin (search_string, (obj, res) => { - populate_packages_list (transaction.search_pkgs.end (res)); - }); - } else if (filters_stack.visible_child_name == "updates") { - populate_packages_list (repos_updates); - } else if (filters_stack.visible_child_name == "pending") { - if ((transaction.to_install.length + transaction.to_remove.length) == 0) { - origin_stack.visible_child_name = "no_item"; - } + switch (filters_stack.visible_child_name) { + case "updates": + if (origin_stack.visible_child_name == "repos") { + updates_listbox.get_row_at_index (0).activate (); + } else if (origin_stack.visible_child_name == "aur") { + updates_listbox.get_row_at_index (1).activate (); } break; - case "aur": - if (filters_stack.visible_child_name == "search") { - Timeout.add (200, () => { - search_entry.grab_focus_without_selecting (); - search_entry.set_position (-1); - return false; - }); - if (search_string == null) { - origin_stack.visible_child_name = "no_item"; - return; - } - this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); - while (Gtk.events_pending ()) { - Gtk.main_iteration (); - } - transaction.search_in_aur.begin (search_string, (obj, res) => { - populate_aur_list (transaction.search_in_aur.end (res)); - }); - } else if (filters_stack.visible_child_name == "updates") { - populate_aur_list (aur_updates); + case "pending": + if (origin_stack.visible_child_name == "repos") { + pending_listbox.get_row_at_index (0).activate (); + } else if (origin_stack.visible_child_name == "aur") { + pending_listbox.get_row_at_index (1).activate (); + } + break; + case "search": + if (origin_stack.visible_child_name == "repos") { + search_listbox.get_row_at_index (0).activate (); + } else if (origin_stack.visible_child_name == "aur") { + search_listbox.get_row_at_index (1).activate (); + } + break; + default: + if (origin_stack.visible_child_name == "repos") { + updates_listbox.select_row (updates_listbox.get_row_at_index (0)); + pending_listbox.select_row (pending_listbox.get_row_at_index (0)); + search_listbox.select_row (search_listbox.get_row_at_index (0)); + } else if (origin_stack.visible_child_name == "aur") { + updates_listbox.select_row (updates_listbox.get_row_at_index (1)); + pending_listbox.select_row (pending_listbox.get_row_at_index (1)); + search_listbox.select_row (search_listbox.get_row_at_index (1)); + } + break; + } + } + + [GtkCallback] + void on_updates_listbox_row_activated (Gtk.ListBoxRow row) { + int index = row.get_index (); + switch (index) { + case 0: // repos + origin_stack.visible_child_name = "repos"; + populate_packages_list (repos_updates); + break; + case 1: // aur + origin_stack.visible_child_name = "aur"; + populate_aur_list (aur_updates); + break; + default: + break; + } + } + + [GtkCallback] + void on_pending_listbox_row_activated (Gtk.ListBoxRow row) { + int index = row.get_index (); + switch (index) { + case 0: // repos + if ((transaction.to_install.length + transaction.to_remove.length) > 0) { + origin_stack.visible_child_name = "repos"; + } else { + origin_stack.visible_child_name = "no_item"; } break; + case 1: // aur + origin_stack.visible_child_name = "aur"; + break; + default: + break; + } + } + + [GtkCallback] + void on_search_listbox_row_activated (Gtk.ListBoxRow row) { + int index = row.get_index (); + switch (index) { + case 0: // repos + Timeout.add (200, () => { + search_entry.grab_focus_without_selecting (); + search_entry.set_position (-1); + return false; + }); + if (search_string == null) { + return; + } + origin_stack.visible_child_name = "repos"; + this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); + while (Gtk.events_pending ()) { + Gtk.main_iteration (); + } + transaction.search_pkgs.begin (search_string, (obj, res) => { + populate_packages_list (transaction.search_pkgs.end (res)); + }); + break; + case 1: // aur + Timeout.add (200, () => { + search_entry.grab_focus_without_selecting (); + search_entry.set_position (-1); + return false; + }); + if (search_string == null) { + origin_stack.visible_child_name = "no_item"; + return; + } + origin_stack.visible_child_name = "aur"; + this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); + while (Gtk.events_pending ()) { + Gtk.main_iteration (); + } + transaction.search_in_aur.begin (search_string, (obj, res) => { + populate_aur_list (transaction.search_in_aur.end (res)); + }); + break; default: break; } @@ -1938,12 +2058,16 @@ namespace Pamac { // a history line was choosen this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); search_string = search_comboboxtext.get_active_text (); + if (filters_stack.visible_child_name != "search") { + // this function will be recalled when refresh_packages_list + filters_stack.visible_child_name = "search"; + return; + } Timeout.add (200, () => { search_entry.grab_focus_without_selecting (); search_entry.set_position (-1); return false; }); - filters_stack.visible_child_name = "search"; switch (origin_stack.visible_child_name) { case "repos": transaction.search_pkgs.begin (search_string, (obj, res) => { @@ -1973,10 +2097,12 @@ namespace Pamac { packages_list.clear (); break; case "updated": - origin_stack.visible_child_name = "repos"; + // select repos + on_search_listbox_row_activated (search_listbox.get_row_at_index (0)); break; case "no_item": - origin_stack.visible_child_name = "repos"; + // select repos + on_search_listbox_row_activated (search_listbox.get_row_at_index (0)); break; default: break; @@ -1991,6 +2117,33 @@ namespace Pamac { } } + [GtkCallback] + void on_filters_listbox_row_activated (Gtk.ListBoxRow row) { + int index = row.get_index (); + switch (index) { + case 0: // categories + filters_stack.visible_child_name = "categories"; + break; + case 1: // groups + filters_stack.visible_child_name = "groups"; + break; + case 2: // repos + filters_stack.visible_child_name = "repos"; + break; + case 3: // installed + filters_stack.visible_child_name = "installed"; + break; + case 4: // updates + filters_stack.visible_child_name = "updates"; + break; + case 5: // pending + filters_stack.visible_child_name = "pending"; + break; + default: + break; + } + } + [GtkCallback] void on_categories_listbox_row_activated (Gtk.ListBoxRow row) { this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); @@ -1998,6 +2151,7 @@ namespace Pamac { var label = row.get_child () as Gtk.Label; string matching_cat = ""; string category = label.label; + this.title = category; if (category == dgettext (null, "Accessories")) { matching_cat = "Utility"; } else if (category == dgettext (null, "Audio & Video")) { @@ -2032,6 +2186,7 @@ namespace Pamac { origin_stack.visible_child_name = "repos"; var label = row.get_child () as Gtk.Label; string group_name = label.label; + this.title = group_name; transaction.get_group_pkgs.begin (group_name, (obj, res) => { populate_packages_list (transaction.get_group_pkgs.end (res)); }); @@ -2042,23 +2197,31 @@ namespace Pamac { this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); origin_stack.visible_child_name = "repos"; var label = row.get_child () as Gtk.Label; - string state = label.label; - if (state == dgettext (null, "Installed")) { - transaction.get_installed_pkgs.begin ((obj, res) => { - populate_packages_list (transaction.get_installed_pkgs.end (res)); - }); - } else if (state == dgettext (null, "Explicitly installed")) { - transaction.get_explicitly_installed_pkgs.begin ((obj, res) => { - populate_packages_list (transaction.get_explicitly_installed_pkgs.end (res)); - }); - } else if (state == dgettext (null, "Orphans")) { - transaction.get_orphans.begin ((obj, res) => { - populate_packages_list (transaction.get_orphans.end (res)); - }); - } else if (state == dgettext (null, "Foreign")) { - transaction.get_foreign_pkgs.begin ((obj, res) => { - populate_packages_list (transaction.get_foreign_pkgs.end (res)); - }); + this.title = label.label; + int index = row.get_index (); + switch (index) { + case 0: // Installed + transaction.get_installed_pkgs.begin ((obj, res) => { + populate_packages_list (transaction.get_installed_pkgs.end (res)); + }); + break; + case 1: // Explicitly installed + transaction.get_explicitly_installed_pkgs.begin ((obj, res) => { + populate_packages_list (transaction.get_explicitly_installed_pkgs.end (res)); + }); + break; + case 2: // Orphans + transaction.get_orphans.begin ((obj, res) => { + populate_packages_list (transaction.get_orphans.end (res)); + }); + break; + case 3: // Foreign + transaction.get_foreign_pkgs.begin ((obj, res) => { + populate_packages_list (transaction.get_foreign_pkgs.end (res)); + }); + break; + default: + break; } } @@ -2068,6 +2231,7 @@ namespace Pamac { origin_stack.visible_child_name = "repos"; var label = row.get_child () as Gtk.Label; string repo = label.label; + this.title = repo; transaction.get_repo_pkgs.begin (repo, (obj, res) => { populate_packages_list (transaction.get_repo_pkgs.end (res)); }); @@ -2203,6 +2367,8 @@ namespace Pamac { void on_run_preferences_dialog_finished () { transaction.unlock (); if (filters_stack.visible_child_name == "updates") { + origin_stack.visible_child_name = "checking"; + checking_spinner.active = true; transaction.start_get_updates (); } else { this.get_window ().set_cursor (null); @@ -2234,9 +2400,6 @@ namespace Pamac { uint total_pending = transaction.to_install.length + transaction.to_remove.length + transaction.to_build.length; if (total_pending == 0) { main_stack.visible_child_name = "term"; - } else { - main_stack.visible_child_name = "browse"; - filters_stack.visible_child_name = "pending"; } } } @@ -2340,15 +2503,12 @@ namespace Pamac { void on_get_updates_finished (Updates updates) { repos_updates = updates.repos_updates; aur_updates = updates.aur_updates; + origin_stack.visible_child_name = "repos"; + checking_spinner.active = false; if (filters_stack.visible_child_name == "updates") { populate_updates (); } else if ((repos_updates.length + aur_updates.length) > 0) { this.get_window ().set_cursor (null); - var attention_val = GLib.Value (typeof (bool)); - attention_val.set_boolean (true); - filters_stack.child_set_property (filters_stack.get_child_by_name ("updates"), - "needs-attention", - attention_val); } } @@ -2376,24 +2536,10 @@ namespace Pamac { } show_sidebar (); } - if (origin_stack.visible_child_name == "repos") { - if (repos_updates.length > 0) { - populate_packages_list (repos_updates); - } else { - origin_stack.visible_child_name = "aur"; - } - } else if (origin_stack.visible_child_name == "aur") { - if (repos_updates.length > 0) { - origin_stack.visible_child_name = "repos"; - } else { - populate_aur_list (aur_updates); - } + if (repos_updates.length > 0) { + origin_stack.visible_child_name = "repos"; } else { - if (repos_updates.length > 0) { - origin_stack.visible_child_name = "repos"; - } else { - origin_stack.visible_child_name = "aur"; - } + origin_stack.visible_child_name = "aur"; } if (main_stack.visible_child_name == "browse") { select_all_button.visible = filters_stack.visible_child_name != "filters"; diff --git a/src/user_daemon.vala b/src/user_daemon.vala index 5a8e8423..d69c9f70 100644 --- a/src/user_daemon.vala +++ b/src/user_daemon.vala @@ -105,6 +105,9 @@ namespace Pamac { refresh_handle (); // init appstream app_store = new As.Store (); + app_store.set_add_flags (As.StoreAddFlags.USE_UNIQUE_ID + | As.StoreAddFlags.ONLY_NATIVE_LANGS + | As.StoreAddFlags.USE_MERGE_HEURISTIC); locale = Environ.get_variable (Environ.get (), "LANG"); if (locale != null) { // remove .UTF-8 from locale @@ -114,6 +117,11 @@ namespace Pamac { } try { app_store.load (As.StoreLoadFlags.APP_INFO_SYSTEM); + app_store.set_search_match (As.AppSearchMatch.PKGNAME + | As.AppSearchMatch.DESCRIPTION + | As.AppSearchMatch.COMMENT + | As.AppSearchMatch.NAME + | As.AppSearchMatch.KEYWORD); } catch (Error e) { stderr.printf ("Error: %s\n", e.message); } @@ -530,6 +538,27 @@ namespace Pamac { syncdbs.next (); } result.join (syncpkgs.diff (result, (Alpm.List.CompareFunc) alpm_pkg_compare_name)); + // search in appstream + if (search_string.length >= 3) { + Alpm.List<unowned Alpm.Package> appstream_result = null; + string[] search_terms = As.utils_search_tokenize (search_string); + app_store.get_apps ().foreach ((app) => { + uint match_score = app.search_matches_all (search_terms); + if (match_score > 0) { + unowned string pkgname = app.get_pkgname_default (); + unowned Alpm.Package? alpm_pkg = alpm_handle.localdb.get_pkg (pkgname); + if (alpm_pkg == null) { + alpm_pkg = get_syncpkg (pkgname); + } + if (alpm_pkg != null) { + if (appstream_result.find (alpm_pkg, (Alpm.List.CompareFunc) alpm_pkg_compare_name) == null) { + appstream_result.add (alpm_pkg); + } + } + } + }); + result.join (appstream_result.diff (result, (Alpm.List.CompareFunc) alpm_pkg_compare_name)); + } // use custom sort function global_search_string = search_string; result.sort (result.length, (Alpm.List.CompareFunc) alpm_pkg_sort_search_by_relevance); diff --git a/vapi/appstream-glib.vapi b/vapi/appstream-glib.vapi index 047209cd..82477223 100644 --- a/vapi/appstream-glib.vapi +++ b/vapi/appstream-glib.vapi @@ -375,7 +375,7 @@ namespace As { public uint search_matches (string search); [CCode (cname = "as_app_search_matches_all")] [Version (since = "0.1.3")] - public uint search_matches_all (string search); + public uint search_matches_all ([CCode (array_length = false, array_null_terminated = true)] string[] search); [CCode (cname = "as_app_set_branch")] [Version (since = "0.6.1")] public void set_branch (string branch); -- GitLab