[gnome-packagekit] Put the clear selection button up in the header to match mockups



commit b27c77503ec2faca921c8626a23b49c3132ea0a8
Author: Richard Hughes <richard hughsie com>
Date:   Fri May 11 14:24:14 2012 +0100

    Put the clear selection button up in the header to match mockups

 data/gpk-application.ui |   37 +++++----
 src/gpk-application.c   |  205 +++++++++++++++++++++++++++--------------------
 2 files changed, 139 insertions(+), 103 deletions(-)
---
diff --git a/data/gpk-application.ui b/data/gpk-application.ui
index f08e729..67182f1 100644
--- a/data/gpk-application.ui
+++ b/data/gpk-application.ui
@@ -22,6 +22,7 @@
           <object class="GtkBox" id="box1">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
+            <property name="spacing">6</property>
             <child>
               <object class="GtkEntry" id="entry_text">
                 <property name="visible">True</property>
@@ -52,6 +53,25 @@
                 <property name="position">1</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkButton" id="button_clear">
+                <property name="label">Abandon Changes</property>
+                <property name="use_action_appearance">False</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="has_tooltip">True</property>
+                <property name="tooltip_markup" translatable="yes">Clear current selection</property>
+                <property name="tooltip_text" translatable="yes">Clear current selection</property>
+                <property name="use_action_appearance">False</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="pack_type">end</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -469,23 +489,6 @@
                         <property name="position">1</property>
                       </packing>
                     </child>
-                    <child>
-                      <object class="GtkButton" id="button_clear">
-                        <property name="label">gtk-clear</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">True</property>
-                        <property name="tooltip_text" translatable="yes">Clear current selection</property>
-                        <property name="use_action_appearance">False</property>
-                        <property name="use_stock">True</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="position">2</property>
-                      </packing>
-                    </child>
                   </object>
                   <packing>
                     <property name="expand">False</property>
diff --git a/src/gpk-application.c b/src/gpk-application.c
index e4c127d..ebfea0d 100644
--- a/src/gpk-application.c
+++ b/src/gpk-application.c
@@ -306,10 +306,100 @@ gpk_application_get_checkbox_enable (GpkApplicationPrivate *priv, PkBitfield sta
 }
 
 /**
- * gpk_application_set_buttons_apply_clear:
+ * gpk_application_get_selected_package:
+ **/
+static gboolean
+gpk_application_get_selected_package (GpkApplicationPrivate *priv, gchar **package_id, gchar **summary)
+{
+	GtkTreeView *treeview;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	GtkTreeSelection *selection;
+	gboolean ret;
+
+	/* get the selection and add */
+	treeview = GTK_TREE_VIEW (gtk_builder_get_object (priv->builder, "treeview_packages"));
+	selection = gtk_tree_view_get_selection (treeview);
+	ret = gtk_tree_selection_get_selected (selection, &model, &iter);
+	if (!ret) {
+		g_warning ("no selection");
+		goto out;
+	}
+
+	/* get data */
+	if (summary == NULL) {
+		gtk_tree_model_get (model, &iter,
+				    PACKAGES_COLUMN_ID, package_id,
+				    -1);
+	} else {
+		gtk_tree_model_get (model, &iter,
+				    PACKAGES_COLUMN_ID, package_id,
+				    PACKAGES_COLUMN_SUMMARY, summary,
+				    -1);
+	}
+out:
+	return ret;
+}
+
+/**
+ * gpk_application_group_add_selected:
+ **/
+static void
+gpk_application_group_add_selected (GpkApplicationPrivate *priv)
+{
+	gboolean ret;
+	gchar *id = NULL;
+	GtkTreeIter iter;
+
+	ret = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->groups_store), &iter);
+	if (!ret)
+		goto out;
+	gtk_tree_model_get (GTK_TREE_MODEL (priv->groups_store), &iter,
+			    GROUPS_COLUMN_ID, &id,
+			    -1);
+	if (g_strcmp0 (id, "selected") == 0)
+		goto out;
+	gtk_tree_store_insert (priv->groups_store, &iter, NULL, 0);
+	gtk_tree_store_set (priv->groups_store, &iter,
+			    /* TRANSLATORS: this is a menu group of packages in the queue */
+			    GROUPS_COLUMN_NAME, _("Pending"),
+			    GROUPS_COLUMN_SUMMARY, NULL,
+			    GROUPS_COLUMN_ID, "selected",
+			    GROUPS_COLUMN_ICON, "edit-find",
+			    GROUPS_COLUMN_ACTIVE, TRUE,
+			    -1);
+out:
+	g_free (id);
+}
+
+/**
+ * gpk_application_group_remove_selected:
+ **/
+static void
+gpk_application_group_remove_selected (GpkApplicationPrivate *priv)
+{
+	gboolean ret;
+	gchar *id = NULL;
+	GtkTreeIter iter;
+
+	ret = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->groups_store), &iter);
+	if (!ret)
+		goto out;
+	gtk_tree_model_get (GTK_TREE_MODEL (priv->groups_store), &iter,
+			    GROUPS_COLUMN_ID, &id,
+			    -1);
+	if (g_strcmp0 (id, "selected") != 0)
+		goto out;
+	gtk_tree_store_remove (priv->groups_store, &iter);
+out:
+	g_free (id);
+}
+
+/**
+ * gpk_application_change_queue_status:
  **/
 static void
-gpk_application_set_buttons_apply_clear (GpkApplicationPrivate *priv)
+gpk_application_change_queue_status (GpkApplicationPrivate *priv)
 {
 	GtkWidget *widget;
 	GtkTreeView *treeview;
@@ -319,25 +409,21 @@ gpk_application_set_buttons_apply_clear (GpkApplicationPrivate *priv)
 	PkBitfield state;
 	gboolean enabled;
 	gchar *package_id;
-	gint len;
-	GPtrArray *array;
-
-	/* okay to apply? */
-	array = pk_package_sack_get_array (priv->package_sack);
-	len = array->len;
-	g_ptr_array_unref (array);
 
-	if (len == 0) {
+	/* show and hide the action widgets */
+	if (pk_package_sack_get_size (priv->package_sack) > 0) {
 		widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_apply"));
-		gtk_widget_set_sensitive (widget, FALSE);
+		gtk_widget_show (widget);
 		widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_clear"));
-		gtk_widget_set_sensitive (widget, FALSE);
-		priv->action = GPK_ACTION_NONE;
+		gtk_widget_show (widget);
+		gpk_application_group_add_selected (priv);
 	} else {
+		priv->action = GPK_ACTION_NONE;
 		widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_apply"));
-		gtk_widget_set_sensitive (widget, TRUE);
+		gtk_widget_hide (widget);
 		widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_clear"));
-		gtk_widget_set_sensitive (widget, TRUE);
+		gtk_widget_hide (widget);
+		gpk_application_group_remove_selected (priv);
 	}
 
 	/* correct the enabled state */
@@ -367,42 +453,6 @@ gpk_application_set_buttons_apply_clear (GpkApplicationPrivate *priv)
 }
 
 /**
- * gpk_application_get_selected_package:
- **/
-static gboolean
-gpk_application_get_selected_package (GpkApplicationPrivate *priv, gchar **package_id, gchar **summary)
-{
-	GtkTreeView *treeview;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	GtkTreeSelection *selection;
-	gboolean ret;
-
-	/* get the selection and add */
-	treeview = GTK_TREE_VIEW (gtk_builder_get_object (priv->builder, "treeview_packages"));
-	selection = gtk_tree_view_get_selection (treeview);
-	ret = gtk_tree_selection_get_selected (selection, &model, &iter);
-	if (!ret) {
-		g_warning ("no selection");
-		goto out;
-	}
-
-	/* get data */
-	if (summary == NULL) {
-		gtk_tree_model_get (model, &iter,
-				    PACKAGES_COLUMN_ID, package_id,
-				    -1);
-	} else {
-		gtk_tree_model_get (model, &iter,
-				    PACKAGES_COLUMN_ID, package_id,
-				    PACKAGES_COLUMN_SUMMARY, summary,
-				    -1);
-	}
-out:
-	return ret;
-}
-
-/**
  * gpk_application_install:
  **/
 static gboolean
@@ -430,11 +480,12 @@ gpk_application_install (GpkApplicationPrivate *priv)
 			gpk_application_allow_install (priv, FALSE);
 			gpk_application_allow_remove (priv, TRUE);
 			gpk_application_packages_checkbox_invert (priv);
-			gpk_application_set_buttons_apply_clear (priv);
-			return TRUE;
+			ret = TRUE;
+			goto out;
 		}
 		g_warning ("wrong mode and not in array");
-		return FALSE;
+		ret = FALSE;
+		goto out;
 	}
 
 	/* already added */
@@ -461,8 +512,10 @@ gpk_application_install (GpkApplicationPrivate *priv)
 	gpk_application_allow_install (priv, FALSE);
 	gpk_application_allow_remove (priv, TRUE);
 	gpk_application_packages_checkbox_invert (priv);
-	gpk_application_set_buttons_apply_clear (priv);
 out:
+	/* add the selected group if there are any packages in the queue */
+	gpk_application_change_queue_status (priv);
+
 	g_free (package_id_selected);
 	g_free (summary_selected);
 	return ret;
@@ -744,11 +797,12 @@ gpk_application_remove (GpkApplicationPrivate *priv)
 			gpk_application_allow_install (priv, TRUE);
 			gpk_application_allow_remove (priv, FALSE);
 			gpk_application_packages_checkbox_invert (priv);
-			gpk_application_set_buttons_apply_clear (priv);
-			return TRUE;
+			ret = TRUE;
+			goto out;
 		}
 		g_warning ("wrong mode and not in array");
-		return FALSE;
+		ret = FALSE;
+		goto out;
 	}
 
 	/* already added */
@@ -772,8 +826,9 @@ gpk_application_remove (GpkApplicationPrivate *priv)
 	gpk_application_allow_install (priv, TRUE);
 	gpk_application_allow_remove (priv, FALSE);
 	gpk_application_packages_checkbox_invert (priv);
-	gpk_application_set_buttons_apply_clear (priv);
 out:
+	/* add the selected group if there are any packages in the queue */
+	gpk_application_change_queue_status (priv);
 	g_free (package_id_selected);
 	g_free (summary_selected);
 	return TRUE;
@@ -1550,7 +1605,6 @@ gpk_application_search_cb (PkClient *client, GAsyncResult *res, GpkApplicationPr
 	gtk_widget_set_sensitive (widget, TRUE);
 	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_apply"));
 	gtk_widget_set_sensitive (widget, TRUE);
-	gpk_application_set_buttons_apply_clear (priv);
 out:
 	/* mark find button sensitive */
 	priv->search_in_progress = FALSE;
@@ -1907,7 +1961,8 @@ gpk_application_button_clear_cb (GtkWidget *widget_button, GpkApplicationPrivate
 	selection = gtk_tree_view_get_selection (treeview);
 	gpk_application_packages_treeview_clicked_cb (selection, priv);
 
-	gpk_application_set_buttons_apply_clear (priv);
+	priv->action = GPK_ACTION_NONE;
+	gpk_application_change_queue_status (priv);
 }
 
 /**
@@ -1954,7 +2009,7 @@ gpk_application_install_packages_cb (PkTask *task, GAsyncResult *res, GpkApplica
 	/* clear if success */
 	pk_package_sack_clear (priv->package_sack);
 	priv->action = GPK_ACTION_NONE;
-	gpk_application_set_buttons_apply_clear (priv);
+	gpk_application_change_queue_status (priv);
 out:
 	if (error_code != NULL)
 		g_object_unref (error_code);
@@ -2003,7 +2058,7 @@ gpk_application_remove_packages_cb (PkTask *task, GAsyncResult *res, GpkApplicat
 	/* clear if success */
 	pk_package_sack_clear (priv->package_sack);
 	priv->action = GPK_ACTION_NONE;
-	gpk_application_set_buttons_apply_clear (priv);
+	gpk_application_change_queue_status (priv);
 out:
 	if (error_code != NULL)
 		g_object_unref (error_code);
@@ -2433,25 +2488,6 @@ gpk_application_group_add_data (GpkApplicationPrivate *priv, PkGroupEnum group)
 }
 
 /**
- * gpk_application_group_add_selected:
- **/
-static void
-gpk_application_group_add_selected (GpkApplicationPrivate *priv)
-{
-	GtkTreeIter iter;
-
-	gtk_tree_store_append (priv->groups_store, &iter, NULL);
-	gtk_tree_store_set (priv->groups_store, &iter,
-			    /* TRANSLATORS: this is a menu group of packages in the queue */
-			    GROUPS_COLUMN_NAME, _("Pending"),
-			    GROUPS_COLUMN_SUMMARY, NULL,
-			    GROUPS_COLUMN_ID, "selected",
-			    GROUPS_COLUMN_ICON, "edit-find",
-			    GROUPS_COLUMN_ACTIVE, TRUE,
-			    -1);
-}
-
-/**
  * gpk_application_popup_position_menu:
  **/
 static void
@@ -3202,9 +3238,6 @@ pk_backend_status_get_properties_cb (GObject *object, GAsyncResult *res, GpkAppl
 	if (pk_bitfield_contain (priv->groups, PK_GROUP_ENUM_COLLECTIONS))
 		gpk_application_group_add_data (priv, PK_GROUP_ENUM_COLLECTIONS);
 
-	/* add group item for selected items */
-	gpk_application_group_add_selected (priv);
-
 	/* add a separator */
 	gtk_tree_store_append (priv->groups_store, &iter, NULL);
 	gtk_tree_store_set (priv->groups_store, &iter,
@@ -3569,7 +3602,7 @@ gpk_application_startup_cb (GtkApplication *application, GpkApplicationPrivate *
 
 	/* set current action */
 	priv->action = GPK_ACTION_NONE;
-	gpk_application_set_buttons_apply_clear (priv);
+	gpk_application_change_queue_status (priv);
 
 	/* hide details */
 	gpk_application_clear_details (priv);



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