[gnome-software/wip/hughsie/non-free-filter] Allow filtering the search results by free software



commit 93b5eed95c8ee73b497dbd3611de498056f8bf4a
Author: Richard Hughes <richard hughsie com>
Date:   Thu Jan 7 11:37:35 2016 +0000

    Allow filtering the search results by free software

 src/gnome-software.ui |  147 +++++++++++++++++++++++++++++++++++++------------
 src/gs-shell-search.c |   16 +++++
 src/gs-shell-search.h |    2 +
 src/gs-shell.c        |   42 ++++++++++++++
 4 files changed, 171 insertions(+), 36 deletions(-)
---
diff --git a/src/gnome-software.ui b/src/gnome-software.ui
index c647f8e..946a6d9 100644
--- a/src/gnome-software.ui
+++ b/src/gnome-software.ui
@@ -325,50 +325,52 @@
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <child>
-                      <object class="GtkBox" id="box_left">
+                      <placeholder/>
+                    </child>
+                    <child type="center">
+                      <object class="GtkBox" id="box2">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="halign">start</property>
-                        <property name="hexpand">True</property>
-                        <property name="orientation">vertical</property>
                         <child>
-                          <placeholder/>
+                          <object class="GtkSearchEntry" id="entry_search">
+                            <property name="width_request">500</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="halign">center</property>
+                            <property name="hexpand">True</property>
+                            <property name="activates_default">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
                         </child>
-                      </object>
-                      <packing>
-                        <property name="expand">True</property>
-                        <property name="fill">True</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkSearchEntry" id="entry_search">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="activates_default">True</property>
-                        <property name="width_request">500</property>
-                        <property name="hexpand">True</property>
-                        <property name="halign">center</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkBox" id="box_right">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="halign">start</property>
-                        <property name="hexpand">True</property>
-                        <property name="orientation">vertical</property>
                         <child>
-                          <placeholder/>
+                          <object class="GtkButton" id="button_filters">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                            <child>
+                              <object class="GtkArrow" id="header_selection_arrow1">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="arrow_type">down</property>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
                         </child>
+                        <style>
+                          <class name="linked"/>
+                        </style>
                       </object>
                       <packing>
-                        <property name="expand">True</property>
+                        <property name="expand">False</property>
                         <property name="fill">True</property>
                         <property name="position">2</property>
                       </packing>
@@ -460,4 +462,77 @@
       </object>
     </child>
   </object>
+  <object class="GtkPopover" id="popover_filter">
+    <property name="can_focus">False</property>
+    <property name="relative_to">button_filters</property>
+    <property name="position">bottom</property>
+    <child>
+      <object class="GtkGrid" id="grid_filter">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="border_width">15</property>
+        <property name="row_spacing">6</property>
+        <child>
+          <object class="GtkBox" id="box_filter_license">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">3</property>
+            <child>
+              <object class="GtkRadioButton" id="radiobutton_filter_everything">
+                <property name="label" translatable="yes" comments="No applications are 
filtered">Everything</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">True</property>
+                <property name="group">radiobutton_filter_free</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkRadioButton" id="radiobutton_filter_free">
+                <property name="label" translatable="yes" comments="Only applications with a free license 
are shown">Only Free Software</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="xalign">0</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">Permitted Licenses</property>
+            <property name="xalign">0</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
 </interface>
diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c
index 9d79e45..ccd2651 100644
--- a/src/gs-shell-search.c
+++ b/src/gs-shell-search.c
@@ -43,6 +43,7 @@ struct _GsShellSearch
        GsShell                 *shell;
        gchar                   *appid_to_show;
        gchar                   *value;
+       gboolean                 only_free;
 
        GtkWidget               *list_box_search;
        GtkWidget               *scrolledwindow_search;
@@ -122,6 +123,12 @@ gs_shell_search_get_search_cb (GObject *source_object,
        gtk_stack_set_visible_child_name (GTK_STACK (self->stack_search), "results");
        for (l = list; l != NULL; l = l->next) {
                app = GS_APP (l->data);
+
+               if (self->only_free && !gs_app_get_licence_is_free (app)) {
+                       g_debug ("not showing %s as nonfree", gs_app_get_id (app));
+                       continue;
+               }
+
                app_row = gs_app_row_new (app);
                g_signal_connect (app_row, "button-clicked",
                                  G_CALLBACK (gs_shell_search_app_row_clicked_cb),
@@ -197,6 +204,15 @@ gs_shell_search_set_appid_to_show (GsShellSearch *self, const gchar *appid)
 }
 
 /**
+ * gs_shell_search_set_only_free:
+ **/
+void
+gs_shell_search_set_only_free (GsShellSearch *self, gboolean only_free)
+{
+       self->only_free = only_free;
+}
+
+/**
  * gs_shell_search_switch_to:
  **/
 void
diff --git a/src/gs-shell-search.h b/src/gs-shell-search.h
index 0260a1d..0140c9f 100644
--- a/src/gs-shell-search.h
+++ b/src/gs-shell-search.h
@@ -38,6 +38,8 @@ G_DECLARE_FINAL_TYPE (GsShellSearch, gs_shell_search, GS, SHELL_SEARCH, GsPage)
 GsShellSearch  *gs_shell_search_new            (void);
 void            gs_shell_search_set_appid_to_show (GsShellSearch       *self,
                                                 const gchar            *appid);
+void            gs_shell_search_set_only_free  (GsShellSearch          *self,
+                                                gboolean                only_free);
 void            gs_shell_search_switch_to      (GsShellSearch          *self,
                                                 const gchar            *text,
                                                 gboolean                scroll_up);
diff --git a/src/gs-shell.c b/src/gs-shell.c
index c1dff9e..f937d36 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -560,6 +560,36 @@ gs_shell_monitor_permission (GsShell *shell)
                           G_CALLBACK (on_permission_changed), shell);
 }
 
+static void
+filter_show_popover_cb (GtkButton *button, GsShell *shell)
+{
+       GsShellPrivate *priv = gs_shell_get_instance_private (shell);
+       GtkWidget *widget;
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "popover_filter"));
+       gtk_widget_show_all (widget);
+}
+
+static void
+filter_changed_cb (GtkRadioButton *button, GsShell *shell)
+{
+       GsShellPrivate *priv = gs_shell_get_instance_private (shell);
+       GtkWidget *widget;
+       const gchar *text;
+       gboolean only_free;
+
+       /* get filters */
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "radiobutton_filter_free"));
+       only_free = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+
+       /* re-search */
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "entry_search"));
+       text = gtk_entry_get_text (GTK_ENTRY (widget));
+       if (text[0] == '\0')
+               return;
+       gs_shell_search_set_only_free (priv->shell_search, only_free);
+       gs_shell_search_switch_to (priv->shell_search, text, TRUE);
+}
+
 /**
  * gs_shell_setup:
  */
@@ -683,6 +713,18 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can
        g_signal_connect (widget, "search-changed",
                          G_CALLBACK (search_changed_handler), shell);
 
+       /* handle non-free searches */
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "radiobutton_filter_everything"));
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+       g_signal_connect (widget, "toggled",
+                         G_CALLBACK (filter_changed_cb), shell);
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "radiobutton_filter_free"));
+       g_signal_connect (widget, "toggled",
+                         G_CALLBACK (filter_changed_cb), shell);
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_filters"));
+       g_signal_connect (widget, "clicked",
+                         G_CALLBACK (filter_show_popover_cb), shell);
+
        /* load content */
        g_signal_connect (priv->shell_overview, "refreshed",
                          G_CALLBACK (initial_overview_load_done), shell);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]