Commit 93b5eed9 authored by Richard Hughes's avatar Richard Hughes
Browse files

Allow filtering the search results by free software

parent 2ad2d6aa
......@@ -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>
......@@ -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),
......@@ -196,6 +203,15 @@ gs_shell_search_set_appid_to_show (GsShellSearch *self, const gchar *appid)
self->appid_to_show = g_strdup (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:
**/
......
......@@ -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);
......
......@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment