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



commit 0118eb6d0d78a5c4d029bddf73d3c53a5c0d4edf
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Apr 24 17:37:28 2012 +0200

    main-toolbar: Use the SelectionController

 src/photos-main-toolbar.c |  122 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 109 insertions(+), 13 deletions(-)
---
diff --git a/src/photos-main-toolbar.c b/src/photos-main-toolbar.c
index f5d2373..0d3bfa9 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -27,13 +27,17 @@
 #include "gd-main-toolbar.h"
 #include "photos-main-toolbar.h"
 #include "photos-mode-controller.h"
+#include "photos-selection-controller.h"
 
 
 struct _PhotosMainToolbarPrivate
 {
   ClutterActor *actor;
   GtkWidget *widget;
-  PhotosModeController *controller;
+  PhotosModeController *mode_cntrlr;
+  PhotosSelectionController *sel_cntrlr;
+  gulong selection_changed_id;
+  gulong selection_mode_id;
   gulong window_mode_id;
 };
 
@@ -42,16 +46,38 @@ G_DEFINE_TYPE (PhotosMainToolbar, photos_main_toolbar, G_TYPE_OBJECT);
 
 
 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->selection_changed_id != 0)
+    {
+      g_signal_handler_disconnect (priv->sel_cntrlr, priv->selection_changed_id);
+      priv->selection_changed_id = 0;
+    }
+}
+
+
+static void
 photos_main_toolbar_destroy (GtkWidget *widget, gpointer user_data)
 {
   PhotosMainToolbar *self = PHOTOS_MAIN_TOOLBAR (user_data);
   PhotosMainToolbarPrivate *priv = self->priv;
 
+  photos_main_toolbar_clear_request (GD_MAIN_TOOLBAR (widget), self);
+
   if (priv->window_mode_id != 0)
     {
-      g_signal_handler_disconnect (priv->controller, priv->window_mode_id);
+      g_signal_handler_disconnect (priv->mode_cntrlr, priv->window_mode_id);
       priv->window_mode_id = 0;
     }
+
+  if (priv->selection_mode_id != 0)
+    {
+      g_signal_handler_disconnect (priv->sel_cntrlr, priv->selection_mode_id);
+      priv->selection_mode_id = 0;
+    }
 }
 
 
@@ -62,9 +88,9 @@ photos_main_toolbar_go_back_request (GdMainToolbar *toolbar, gpointer user_data)
   PhotosMainToolbarPrivate *priv = self->priv;
   PhotosWindowMode mode;
 
-  mode = photos_mode_controller_get_window_mode (priv->controller);
+  mode = photos_mode_controller_get_window_mode (priv->mode_cntrlr);
   if (mode == PHOTOS_WINDOW_MODE_PREVIEW)
-    photos_mode_controller_set_window_mode (priv->controller, PHOTOS_WINDOW_MODE_OVERVIEW);
+    photos_mode_controller_set_window_mode (priv->mode_cntrlr, PHOTOS_WINDOW_MODE_OVERVIEW);
 }
 
 
@@ -81,13 +107,71 @@ photos_main_toolbar_populate_for_preview (PhotosMainToolbar *self)
 
 
 static void
+photos_main_toolbar_set_toolbar_title (PhotosSelectionController *sel_cntrlr, gpointer user_data)
+{
+  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)
+    {
+    }
+}
+
+
+static void
+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);
+
+  photos_main_toolbar_set_toolbar_title (priv->sel_cntrlr, self);
+  gtk_widget_show_all (priv->widget);
+}
+
+
+static void
+photos_main_toolbar_selection_mode_changed (PhotosSelectionController *sel_cntrlr,
+                                            gboolean mode,
+                                            gpointer user_data)
+{
+  PhotosMainToolbar *self = PHOTOS_MAIN_TOOLBAR (user_data);
+  PhotosMainToolbarPrivate *priv = self->priv;
+  PhotosWindowMode window_mode;
+
+  window_mode = photos_mode_controller_get_window_mode (priv->mode_cntrlr);
+  if (window_mode != PHOTOS_WINDOW_MODE_OVERVIEW)
+    return;
+
+  if (mode)
+    photos_main_toolbar_populate_for_selection_mode (self);
+  else
+    photos_main_toolbar_populate_for_overview (self);
+}
+
+
+static void
 photos_main_toolbar_selection_mode_request (GdMainToolbar *toolbar, gboolean request_mode, gpointer user_data)
 {
+  PhotosMainToolbar *self = PHOTOS_MAIN_TOOLBAR (user_data);
+  photos_selection_controller_set_selection_mode (self->priv->sel_cntrlr, request_mode);
 }
 
 
 static void
-photos_main_toolbar_window_mode_changed (PhotosModeController *controller,
+photos_main_toolbar_window_mode_changed (PhotosModeController *mode_cntrlr,
                                          PhotosWindowMode mode,
                                          PhotosWindowMode old_mode,
                                          gpointer user_data)
@@ -107,10 +191,16 @@ photos_main_toolbar_dispose (GObject *object)
   PhotosMainToolbar *self = PHOTOS_MAIN_TOOLBAR (object);
   PhotosMainToolbarPrivate *priv = self->priv;
 
-  if (priv->controller != NULL)
+  if (priv->mode_cntrlr != NULL)
+    {
+      g_object_unref (priv->mode_cntrlr);
+      priv->mode_cntrlr = NULL;
+    }
+
+  if (priv->sel_cntrlr != NULL)
     {
-      g_object_unref (priv->controller);
-      priv->controller = NULL;
+      g_object_unref (priv->sel_cntrlr);
+      priv->sel_cntrlr = NULL;
     }
 
   G_OBJECT_CLASS (photos_main_toolbar_parent_class)->dispose (object);
@@ -134,15 +224,20 @@ photos_main_toolbar_init (PhotosMainToolbar *self)
 
   priv->actor = gtk_clutter_actor_new_with_contents (priv->widget);
 
-  priv->controller = photos_mode_controller_new ();
-
-  priv->window_mode_id = g_signal_connect (priv->controller,
+  priv->mode_cntrlr = photos_mode_controller_new ();
+  priv->window_mode_id = g_signal_connect (priv->mode_cntrlr,
                                            "window-mode-changed",
                                            G_CALLBACK (photos_main_toolbar_window_mode_changed),
                                            self);
 
-  photos_main_toolbar_window_mode_changed (priv->controller,
-                                           photos_mode_controller_get_window_mode (priv->controller),
+  priv->sel_cntrlr = photos_selection_controller_new ();
+  priv->selection_mode_id = g_signal_connect (priv->sel_cntrlr,
+                                              "selection-mode-changed",
+                                              G_CALLBACK (photos_main_toolbar_selection_mode_changed),
+                                              self);
+
+  photos_main_toolbar_window_mode_changed (priv->mode_cntrlr,
+                                           photos_mode_controller_get_window_mode (priv->mode_cntrlr),
                                            PHOTOS_WINDOW_MODE_NONE, /* unused */
                                            self);
 
@@ -152,6 +247,7 @@ photos_main_toolbar_init (PhotosMainToolbar *self)
                     G_CALLBACK (photos_main_toolbar_selection_mode_request),
                     self);
   g_signal_connect (priv->widget, "go-back-request", G_CALLBACK (photos_main_toolbar_go_back_request), self);
+  g_signal_connect (priv->widget, "clear-request", G_CALLBACK (photos_main_toolbar_clear_request), self);
 }
 
 



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