[gnome-packagekit] Make the arch filter a single tickbox, not an option group



commit d6058c2b4eb3b1d14d3247a7413a660b5b022f80
Author: Richard Hughes <richard hughsie com>
Date:   Thu Jul 23 17:08:14 2009 +0100

    Make the arch filter a single tickbox, not an option group

 data/gnome-packagekit.schemas.in |   12 +++++
 data/gpk-application.ui          |   46 +++----------------
 src/gpk-application.c            |   88 +++++++++++++++++++-------------------
 src/gpk-common.h                 |    1 +
 4 files changed, 65 insertions(+), 82 deletions(-)
---
diff --git a/data/gnome-packagekit.schemas.in b/data/gnome-packagekit.schemas.in
index 63e7059..ced1a29 100644
--- a/data/gnome-packagekit.schemas.in
+++ b/data/gnome-packagekit.schemas.in
@@ -380,6 +380,18 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/gnome-packagekit/application/filter_arch</key>
+      <applyto>/apps/gnome-packagekit/application/filter_arch</applyto>
+      <owner>gnome-packagekit</owner>
+      <type>bool</type>
+      <default>true</default>
+      <locale name="C">
+        <short>Only show native packages in the file lists</short>
+        <long>Only show native packages maching the machine architecture in the file lists</long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/gnome-packagekit/application/category_groups</key>
       <applyto>/apps/gnome-packagekit/application/category_groups</applyto>
       <owner>gnome-packagekit</owner>
diff --git a/data/gpk-application.ui b/data/gpk-application.ui
index c73a7f6..f6358c6 100644
--- a/data/gpk-application.ui
+++ b/data/gpk-application.ui
@@ -246,44 +246,6 @@
                       </object>
                     </child>
                     <child>
-                      <object class="GtkMenuItem" id="menuitem_arch">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">_Architectures</property>
-                        <property name="use_underline">True</property>
-                        <child type="submenu">
-                          <object class="GtkMenu" id="menu1">
-                            <property name="visible">True</property>
-                            <child>
-                              <object class="GtkRadioMenuItem" id="menuitem_arch_yes">
-                                <property name="visible">True</property>
-                                <property name="label" translatable="yes">_Only native architectures</property>
-                                <property name="use_underline">True</property>
-                                <property name="draw_as_radio">True</property>
-                              </object>
-                            </child>
-                            <child>
-                              <object class="GtkRadioMenuItem" id="menuitem_arch_no">
-                                <property name="visible">True</property>
-                                <property name="label" translatable="yes">_Only non-native architectures</property>
-                                <property name="use_underline">True</property>
-                                <property name="draw_as_radio">True</property>
-                                <property name="group">menuitem_arch_yes</property>
-                              </object>
-                            </child>
-                            <child>
-                              <object class="GtkRadioMenuItem" id="menuitem_arch_both">
-                                <property name="visible">True</property>
-                                <property name="label" translatable="yes">_No filter</property>
-                                <property name="use_underline">True</property>
-                                <property name="draw_as_radio">True</property>
-                                <property name="group">menuitem_arch_yes</property>
-                              </object>
-                            </child>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                    <child>
                       <object class="GtkMenuItem" id="menuitem_source">
                         <property name="visible">True</property>
                         <property name="label" translatable="yes">_Source</property>
@@ -341,6 +303,14 @@
                         <property name="active">True</property>
                       </object>
                     </child>
+                    <child>
+                      <object class="GtkCheckMenuItem" id="menuitem_arch">
+                        <property name="visible">True</property>
+                        <property name="tooltip_text" translatable="yes">Only show packages matching the machine architecture</property>
+                        <property name="label" translatable="yes">Only n_ative packages</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                    </child>
                   </object>
                 </child>
               </object>
diff --git a/src/gpk-application.c b/src/gpk-application.c
index e14b218..c84379e 100644
--- a/src/gpk-application.c
+++ b/src/gpk-application.c
@@ -2711,39 +2711,6 @@ gpk_application_menu_filter_free_cb (GtkWidget *widget, GpkApplication *applicat
 }
 
 /**
- * gpk_application_menu_filter_arch_cb:
- * @widget: The GtkWidget object
- **/
-static void
-gpk_application_menu_filter_arch_cb (GtkWidget *widget, GpkApplication *application)
-{
-	const gchar *name;
-
-	g_return_if_fail (GPK_IS_APPLICATION (application));
-
-	name = gtk_widget_get_name (widget);
-
-	/* only care about new state */
-	if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget)))
-		return;
-
-	/* set new filter */
-	if (g_str_has_suffix (name, "_yes")) {
-		pk_bitfield_add (application->priv->filters_current, PK_FILTER_ENUM_ARCH);
-		pk_bitfield_remove (application->priv->filters_current, PK_FILTER_ENUM_NOT_ARCH);
-	} else if (g_str_has_suffix (name, "_no")) {
-		pk_bitfield_remove (application->priv->filters_current, PK_FILTER_ENUM_ARCH);
-		pk_bitfield_add (application->priv->filters_current, PK_FILTER_ENUM_NOT_ARCH);
-	} else {
-		pk_bitfield_remove (application->priv->filters_current, PK_FILTER_ENUM_ARCH);
-		pk_bitfield_remove (application->priv->filters_current, PK_FILTER_ENUM_NOT_ARCH);
-	}
-
-	/* refresh the search results */
-	gpk_application_perform_search (application);
-}
-
-/**
  * gpk_application_menu_filter_source_cb:
  * @widget: The GtkWidget object
  **/
@@ -2829,6 +2796,32 @@ gpk_application_menu_filter_newest_cb (GtkWidget *widget, GpkApplication *applic
 }
 
 /**
+ * gpk_application_menu_filter_arch_cb:
+ * @widget: The GtkWidget object
+ **/
+static void
+gpk_application_menu_filter_arch_cb (GtkWidget *widget, GpkApplication *application)
+{
+	gboolean enabled;
+
+	g_return_if_fail (GPK_IS_APPLICATION (application));
+
+	/* save users preference to gconf */
+	enabled = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget));
+	gconf_client_set_bool (application->priv->gconf_client,
+			       GPK_CONF_APPLICATION_FILTER_ARCH, enabled, NULL);
+
+	/* change the filter */
+	if (enabled)
+		pk_bitfield_add (application->priv->filters_current, PK_FILTER_ENUM_ARCH);
+	else
+		pk_bitfield_remove (application->priv->filters_current, PK_FILTER_ENUM_ARCH);
+
+	/* refresh the search results */
+	gpk_application_perform_search (application);
+}
+
+/**
  * gpk_application_status_changed_timeout_cb:
  **/
 static gboolean
@@ -3865,17 +3858,6 @@ gpk_application_init (GpkApplication *application)
 	g_signal_connect (widget, "toggled",
 			  G_CALLBACK (gpk_application_menu_filter_free_cb), application);
 
-	/* arch filter */
-	widget = GTK_WIDGET (gtk_builder_get_object (application->priv->builder, "menuitem_arch_yes"));
-	g_signal_connect (widget, "toggled",
-			  G_CALLBACK (gpk_application_menu_filter_arch_cb), application);
-	widget = GTK_WIDGET (gtk_builder_get_object (application->priv->builder, "menuitem_arch_no"));
-	g_signal_connect (widget, "toggled",
-			  G_CALLBACK (gpk_application_menu_filter_arch_cb), application);
-	widget = GTK_WIDGET (gtk_builder_get_object (application->priv->builder, "menuitem_arch_both"));
-	g_signal_connect (widget, "toggled",
-			  G_CALLBACK (gpk_application_menu_filter_arch_cb), application);
-
 	/* source filter */
 	widget = GTK_WIDGET (gtk_builder_get_object (application->priv->builder, "menuitem_source_yes"));
 	g_signal_connect (widget, "toggled",
@@ -3897,6 +3879,11 @@ gpk_application_init (GpkApplication *application)
 	g_signal_connect (widget, "toggled",
 			  G_CALLBACK (gpk_application_menu_filter_newest_cb), application);
 
+	/* newest filter */
+	widget = GTK_WIDGET (gtk_builder_get_object (application->priv->builder, "menuitem_arch"));
+	g_signal_connect (widget, "toggled",
+			  G_CALLBACK (gpk_application_menu_filter_arch_cb), application);
+
 	/* Remove description/file list if needed. */
 	if (pk_bitfield_contain (application->priv->roles, PK_ROLE_ENUM_GET_DETAILS) == FALSE) {
 		widget = GTK_WIDGET (gtk_builder_get_object (application->priv->builder, "scrolledwindow2"));
@@ -4022,6 +4009,19 @@ gpk_application_init (GpkApplication *application)
 		gtk_widget_hide (widget);
 	}
 
+	/* ARCH, use by default, or hide */
+	widget = GTK_WIDGET (gtk_builder_get_object (application->priv->builder, "menuitem_arch"));
+	if (pk_bitfield_contain (application->priv->filters, PK_FILTER_ENUM_ARCH)) {
+		/* set from remembered state */
+		enabled = gconf_client_get_bool (application->priv->gconf_client,
+						 GPK_CONF_APPLICATION_FILTER_ARCH, NULL);
+		gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), enabled);
+		/* work round a gtk2+ bug: toggled should be fired when doing gtk_check_menu_item_set_active */
+		gpk_application_menu_filter_arch_cb (widget, application);
+	} else {
+		gtk_widget_hide (widget);
+	}
+
 	widget = GTK_WIDGET (gtk_builder_get_object (application->priv->builder, "entry_text"));
 	g_signal_connect (widget, "key-press-event",
 			  G_CALLBACK (gpk_application_text_changed_cb), application);
diff --git a/src/gpk-common.h b/src/gpk-common.h
index 64db208..21a9eae 100644
--- a/src/gpk-common.h
+++ b/src/gpk-common.h
@@ -68,6 +68,7 @@ G_BEGIN_DECLS
 #define GPK_CONF_WATCH_ACTIVE_TRANSACTIONS	"/apps/gnome-packagekit/update-icon/watch_active_transactions"
 #define GPK_CONF_APPLICATION_FILTER_BASENAME	"/apps/gnome-packagekit/application/filter_basename"
 #define GPK_CONF_APPLICATION_FILTER_NEWEST	"/apps/gnome-packagekit/application/filter_newest"
+#define GPK_CONF_APPLICATION_FILTER_ARCH	"/apps/gnome-packagekit/application/filter_arch"
 #define GPK_CONF_APPLICATION_CATEGORY_GROUPS	"/apps/gnome-packagekit/application/category_groups"
 #define GPK_CONF_APPLICATION_SEARCH_MODE	"/apps/gnome-packagekit/application/search_mode"
 #define GPK_CONF_UPDATE_VIEWER_MOBILE_BBAND	"/apps/gnome-packagekit/update-viewer/notify_mobile_connection"



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