[gnome-photos] main-toolbar: Use the CollectionManager



commit 1c0b488da1f893064b55453bbda6745d8cce505d
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue May 1 00:37:58 2012 +0200

    main-toolbar: Use the CollectionManager

 src/photos-main-toolbar.c |   84 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 60 insertions(+), 24 deletions(-)
---
diff --git a/src/photos-main-toolbar.c b/src/photos-main-toolbar.c
index 8ec031d..a8ad1cf 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -25,6 +25,7 @@
 #include <gtk/gtk.h>
 
 #include "gd-main-toolbar.h"
+#include "photos-collection-manager.h"
 #include "photos-main-toolbar.h"
 #include "photos-mode-controller.h"
 #include "photos-selection-controller.h"
@@ -34,8 +35,10 @@ struct _PhotosMainToolbarPrivate
 {
   ClutterActor *actor;
   GtkWidget *widget;
+  PhotosBaseManager *col_mngr;
   PhotosModeController *mode_cntrlr;
   PhotosSelectionController *sel_cntrlr;
+  gulong collection_id;
   gulong selection_changed_id;
   gulong selection_mode_id;
   gulong window_mode_id;
@@ -46,11 +49,46 @@ G_DEFINE_TYPE (PhotosMainToolbar, photos_main_toolbar, G_TYPE_OBJECT);
 
 
 static void
+photos_main_toolbar_set_toolbar_title (PhotosMainToolbar *self)
+{
+  PhotosMainToolbarPrivate *priv = self->priv;
+  GdMainToolbarMode mode;
+
+  mode = gd_main_toolbar_get_mode (GD_MAIN_TOOLBAR (priv->widget));
+  if (mode == GD_MAIN_TOOLBAR_MODE_OVERVIEW)
+    {
+    }
+  else if (mode == GD_MAIN_TOOLBAR_MODE_PREVIEW)
+    {
+    }
+  else if (mode == GD_MAIN_TOOLBAR_MODE_SELECTION)
+    {
+    }
+}
+
+
+static void
+photos_main_toolbar_active_changed (PhotosBaseManager *manager, PhotosBaseItem *item, gpointer user_data)
+{
+  PhotosMainToolbar *self = PHOTOS_MAIN_TOOLBAR (user_data);
+
+  gd_main_toolbar_set_back_visible (GD_MAIN_TOOLBAR (self->priv->widget), item != NULL);
+  photos_main_toolbar_set_toolbar_title (self);
+}
+
+
+static void
 photos_main_toolbar_clear_request (GdMainToolbar *toolbar, gpointer user_data)
 {
   PhotosMainToolbar *self = PHOTOS_MAIN_TOOLBAR (user_data);
   PhotosMainToolbarPrivate *priv = self->priv;
 
+  if (priv->collection_id != 0)
+    {
+      g_signal_handler_disconnect (priv->col_mngr, priv->collection_id);
+      priv->collection_id = 0;
+    }
+
   if (priv->selection_changed_id != 0)
     {
       g_signal_handler_disconnect (priv->sel_cntrlr, priv->selection_changed_id);
@@ -91,38 +129,33 @@ photos_main_toolbar_go_back_request (GdMainToolbar *toolbar, gpointer user_data)
   mode = photos_mode_controller_get_window_mode (priv->mode_cntrlr);
   if (mode == PHOTOS_WINDOW_MODE_PREVIEW)
     photos_mode_controller_set_window_mode (priv->mode_cntrlr, PHOTOS_WINDOW_MODE_OVERVIEW);
+  else
+    photos_base_manager_set_active_item (priv->col_mngr, NULL);
 }
 
 
 static void
 photos_main_toolbar_populate_for_overview (PhotosMainToolbar *self)
 {
-}
+  PhotosMainToolbarPrivate *priv = self->priv;
+  PhotosBaseItem *item;
 
+  gd_main_toolbar_set_mode (GD_MAIN_TOOLBAR (priv->widget), GD_MAIN_TOOLBAR_MODE_OVERVIEW);
+  priv->collection_id = g_signal_connect (priv->col_mngr,
+                                          "active-changed",
+                                          G_CALLBACK (photos_main_toolbar_active_changed),
+                                          self);
 
-static void
-photos_main_toolbar_populate_for_preview (PhotosMainToolbar *self)
-{
+  item = photos_base_manager_get_active_item (priv->col_mngr);
+  photos_main_toolbar_active_changed (priv->col_mngr, item, self);
+
+  gtk_widget_show_all (priv->widget);
 }
 
 
 static void
-photos_main_toolbar_set_toolbar_title (PhotosSelectionController *sel_cntrlr, gpointer user_data)
+photos_main_toolbar_populate_for_preview (PhotosMainToolbar *self)
 {
-  PhotosMainToolbar *self = PHOTOS_MAIN_TOOLBAR (user_data);
-  PhotosMainToolbarPrivate *priv = self->priv;
-  GdMainToolbarMode mode;
-
-  mode = gd_main_toolbar_get_mode (GD_MAIN_TOOLBAR (priv->widget));
-  if (mode == GD_MAIN_TOOLBAR_MODE_OVERVIEW)
-    {
-    }
-  else if (mode == GD_MAIN_TOOLBAR_MODE_PREVIEW)
-    {
-    }
-  else if (mode == GD_MAIN_TOOLBAR_MODE_SELECTION)
-    {
-    }
 }
 
 
@@ -132,12 +165,12 @@ photos_main_toolbar_populate_for_selection_mode (PhotosMainToolbar *self)
   PhotosMainToolbarPrivate *priv = self->priv;
 
   gd_main_toolbar_set_mode (GD_MAIN_TOOLBAR (priv->widget), GD_MAIN_TOOLBAR_MODE_SELECTION);
-  priv->selection_changed_id = g_signal_connect (priv->sel_cntrlr,
-                                                 "selection-changed",
-                                                 G_CALLBACK (photos_main_toolbar_set_toolbar_title),
-                                                 self);
+  priv->selection_changed_id = g_signal_connect_swapped (priv->sel_cntrlr,
+                                                         "selection-changed",
+                                                         G_CALLBACK (photos_main_toolbar_set_toolbar_title),
+                                                         self);
 
-  photos_main_toolbar_set_toolbar_title (priv->sel_cntrlr, self);
+  photos_main_toolbar_set_toolbar_title (self);
   gtk_widget_show_all (priv->widget);
 }
 
@@ -191,6 +224,8 @@ photos_main_toolbar_dispose (GObject *object)
   PhotosMainToolbar *self = PHOTOS_MAIN_TOOLBAR (object);
   PhotosMainToolbarPrivate *priv = self->priv;
 
+  g_clear_object (&priv->col_mngr);
+
   if (priv->mode_cntrlr != NULL)
     {
       g_object_unref (priv->mode_cntrlr);
@@ -223,6 +258,7 @@ photos_main_toolbar_init (PhotosMainToolbar *self)
   gtk_widget_show (priv->widget);
 
   priv->actor = gtk_clutter_actor_new_with_contents (priv->widget);
+  priv->col_mngr = photos_collection_manager_new ();
 
   priv->mode_cntrlr = photos_mode_controller_new ();
   priv->window_mode_id = g_signal_connect (priv->mode_cntrlr,



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