[gnome-photos] Rename View to ViewContainer, and derive from GtkGrid not GdMainView



commit bd528df4d2c926f685d8198580a79324ae6e7d39
Author: Debarshi Ray <debarshir gnome org>
Date:   Sat Aug 11 18:57:36 2012 +0200

    Rename View to ViewContainer, and derive from GtkGrid not GdMainView
    
    Original patch from Cosimo Cecchi for gnome-documents.

 src/Makefile.am             |    4 +-
 src/photos-embed.c          |  106 ++--------------
 src/photos-view-container.c |  291 +++++++++++++++++++++++++++++++++++++++++++
 src/photos-view-container.h |   71 +++++++++++
 src/photos-view.c           |  172 -------------------------
 src/photos-view.h           |   71 -----------
 6 files changed, 373 insertions(+), 342 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index ef50cc4..5c40bdf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -85,8 +85,8 @@ gnome_photos_SOURCES = \
 	photos-tracker-queue.h \
 	photos-utils.c \
 	photos-utils.h \
-	photos-view.c \
-	photos-view.h \
+	photos-view-container.c \
+	photos-view-container.h \
 	photos-main.c \
 	$(NULL)
 
diff --git a/src/photos-embed.c b/src/photos-embed.c
index 86b8333..66d895a 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -32,7 +32,7 @@
 #include "photos-mode-controller.h"
 #include "photos-selection-toolbar.h"
 #include "photos-tracker-controller.h"
-#include "photos-view.h"
+#include "photos-view-container.h"
 
 
 struct _PhotosEmbedPrivate
@@ -40,14 +40,13 @@ struct _PhotosEmbedPrivate
   ClutterActor *background;
   ClutterActor *contents_actor;
   ClutterActor *error_box;
-  ClutterActor *grid_actor;
   ClutterActor *image_actor;
+  ClutterActor *overview_actor;
   ClutterActor *view_actor;
   ClutterLayoutManager *contents_layout;
   ClutterLayoutManager *view_layout;
   GCancellable *loader_cancellable;
-  GtkWidget *grid;
-  GtkWidget *view;
+  GtkWidget *overview;
   PhotosBaseManager *item_mngr;
   PhotosMainToolbar *toolbar;
   PhotosSelectionToolbar *selection_toolbar;
@@ -55,9 +54,6 @@ struct _PhotosEmbedPrivate
   PhotosTrackerController *trk_cntrlr;
   gint preview_page;
   gint view_page;
-  gulong adjustment_changed_id;
-  gulong adjustment_value_id;
-  gulong scrollbar_visible_id;
 };
 
 
@@ -136,41 +132,9 @@ photos_embed_fullscreen_changed (PhotosModeController *mode_cntrlr, gboolean ful
 
 
 static void
-photos_embed_view_change (PhotosEmbed *self)
-{
-}
-
-
-static void
-photos_embed_view_vadjustment_changed (GtkAdjustment *adjustment, gpointer user_data)
-{
-  PhotosEmbed *self = PHOTOS_EMBED (user_data);
-  photos_embed_view_change (self);
-}
-
-
-static void
-photos_embed_view_vadjustment_value_changed (GtkAdjustment *adjustment, gpointer user_data)
-{
-  PhotosEmbed *self = PHOTOS_EMBED (user_data);
-  photos_embed_view_change (self);
-}
-
-
-static void
-photos_embed_view_vscrolbar_notify_visible (GObject *object, GParamSpec *pspec, gpointer user_data)
-{
-  PhotosEmbed *self = PHOTOS_EMBED (user_data);
-  photos_embed_view_change (self);
-}
-
-
-static void
 photos_embed_prepare_for_overview (PhotosEmbed *self)
 {
   PhotosEmbedPrivate *priv = self->priv;
-  GtkAdjustment *vadjustment;
-  GtkWidget *vscrollbar;
 
   photos_base_manager_set_active_object (priv->item_mngr, NULL);
 
@@ -181,33 +145,7 @@ photos_embed_prepare_for_overview (PhotosEmbed *self)
     }
 
   photos_error_box_move_out (PHOTOS_ERROR_BOX (priv->error_box));
-
-  if (priv->view == NULL)
-    {
-      priv->view = photos_view_new ();
-      gtk_container_add (GTK_CONTAINER (priv->grid), priv->view);
-
-      /* TODO: LoadMoreButton */
-    }
-
-  vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->view));
-  priv->adjustment_changed_id = g_signal_connect (vadjustment,
-                                                  "changed",
-                                                  G_CALLBACK (photos_embed_view_vadjustment_changed),
-                                                  self);
-  priv->adjustment_value_id = g_signal_connect (vadjustment,
-                                                "value-changed",
-                                                G_CALLBACK (photos_embed_view_vadjustment_value_changed),
-                                                self);
-
-  vscrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (priv->view));
-  priv->scrollbar_visible_id = g_signal_connect (vscrollbar,
-                                                 "notify::visible",
-                                                 G_CALLBACK (photos_embed_view_vscrolbar_notify_visible),
-                                                 self);
-
-  photos_embed_view_change (self);
-  clutter_actor_set_child_above_sibling (priv->view_actor, priv->grid_actor, NULL);
+  clutter_actor_set_child_above_sibling (priv->view_actor, priv->overview_actor, NULL);
 }
 
 
@@ -215,34 +153,11 @@ static void
 photos_embed_prepare_for_preview (PhotosEmbed *self)
 {
   PhotosEmbedPrivate *priv = self->priv;
-  GtkAdjustment *vadjustment;
-  GtkWidget *vscrollbar;
 
   /* TODO: SearchController,
    *       ErrorHandler
    */
 
-  vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->view));
-  vscrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (priv->view));
-
-  if (priv->adjustment_changed_id != 0)
-    {
-      g_signal_handler_disconnect (vadjustment, priv->adjustment_changed_id);
-      priv->adjustment_changed_id = 0;
-    }
-
-  if (priv->adjustment_value_id != 0)
-    {
-      g_signal_handler_disconnect (vadjustment, priv->adjustment_value_id);
-      priv->adjustment_value_id = 0;
-    }
-
-  if (priv->scrollbar_visible_id != 0)
-    {
-      g_signal_handler_disconnect (vscrollbar, priv->scrollbar_visible_id);
-      priv->scrollbar_visible_id = 0;
-    }
-
   clutter_actor_set_child_above_sibling (priv->view_actor, priv->image_actor, NULL);
 }
 
@@ -376,14 +291,11 @@ photos_embed_init (PhotosEmbed *self)
   clutter_actor_set_y_expand (priv->view_actor, TRUE);
   clutter_actor_add_child (priv->contents_actor, priv->view_actor);
 
-  priv->grid = gtk_grid_new ();
-  gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->grid), GTK_ORIENTATION_VERTICAL);
-  gtk_widget_show_all (priv->grid);
-
-  priv->grid_actor = gtk_clutter_actor_new_with_contents (priv->grid);
-  clutter_actor_set_x_expand (priv->grid_actor, TRUE);
-  clutter_actor_set_y_expand (priv->grid_actor, TRUE);
-  clutter_actor_add_child (priv->view_actor, priv->grid_actor);
+  priv->overview = photos_view_container_new ();
+  priv->overview_actor = gtk_clutter_actor_new_with_contents (priv->overview);
+  clutter_actor_set_x_expand (priv->overview_actor, TRUE);
+  clutter_actor_set_y_expand (priv->overview_actor, TRUE);
+  clutter_actor_add_child (priv->view_actor, priv->overview_actor);
 
   priv->image_actor = clutter_actor_new ();
   clutter_actor_set_background_color (priv->image_actor, CLUTTER_COLOR_Black);
diff --git a/src/photos-view-container.c b/src/photos-view-container.c
new file mode 100644
index 0000000..ad6a741
--- /dev/null
+++ b/src/photos-view-container.c
@@ -0,0 +1,291 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright  2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+
+#include "config.h"
+
+#include "gd-main-view.h"
+#include "photos-item-manager.h"
+#include "photos-mode-controller.h"
+#include "photos-selection-controller.h"
+#include "photos-tracker-controller.h"
+#include "photos-utils.h"
+#include "photos-view-container.h"
+
+
+struct _PhotosViewContainerPrivate
+{
+  GdMainView *view;
+  GtkListStore *model;
+  PhotosBaseManager *item_mngr;
+  PhotosModeController *mode_cntrlr;
+  PhotosSelectionController *sel_cntrlr;
+  PhotosTrackerController *trk_cntrlr;
+  gboolean disposed;
+  gulong adjustment_changed_id;
+  gulong adjustment_value_id;
+  gulong scrollbar_visible_id;
+};
+
+
+G_DEFINE_TYPE (PhotosViewContainer, photos_view_container, GTK_TYPE_GRID);
+
+
+static void
+photos_view_container_view_changed (PhotosViewContainer *self)
+{
+}
+
+
+static void
+photos_view_container_connect_view (PhotosViewContainer *self)
+{
+  PhotosViewContainerPrivate *priv = self->priv;
+  GtkAdjustment *vadjustment;
+  GtkWidget *vscrollbar;
+
+  vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->view));
+  priv->adjustment_changed_id = g_signal_connect_swapped (vadjustment,
+                                                          "changed",
+                                                          G_CALLBACK (photos_view_container_view_changed),
+                                                          self);
+  priv->adjustment_value_id = g_signal_connect_swapped (vadjustment,
+                                                        "value-changed",
+                                                        G_CALLBACK (photos_view_container_view_changed),
+                                                        self);
+
+  vscrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (priv->view));
+  priv->scrollbar_visible_id = g_signal_connect_swapped (vscrollbar,
+                                                         "notify::visible",
+                                                         G_CALLBACK (photos_view_container_view_changed),
+                                                         self);
+
+  photos_view_container_view_changed (self);
+}
+
+
+static void
+photos_view_container_disconnect_view (PhotosViewContainer *self)
+{
+  PhotosViewContainerPrivate *priv = self->priv;
+  GtkAdjustment *vadjustment;
+  GtkWidget *vscrollbar;
+
+  vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->view));
+  vscrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (priv->view));
+
+  if (priv->adjustment_changed_id != 0)
+    {
+      g_signal_handler_disconnect (vadjustment, priv->adjustment_changed_id);
+      priv->adjustment_changed_id = 0;
+    }
+
+  if (priv->adjustment_value_id != 0)
+    {
+      g_signal_handler_disconnect (vadjustment, priv->adjustment_value_id);
+      priv->adjustment_value_id = 0;
+    }
+
+  if (priv->scrollbar_visible_id != 0)
+    {
+      g_signal_handler_disconnect (vscrollbar, priv->scrollbar_visible_id);
+      priv->scrollbar_visible_id = 0;
+    }
+}
+
+
+static void
+photos_view_container_item_activated (GdMainView *main_view,
+                                      const gchar * id,
+                                      const GtkTreePath *path,
+                                      gpointer user_data)
+{
+  PhotosViewContainer *self = PHOTOS_VIEW_CONTAINER (user_data);
+  photos_base_manager_set_active_object_by_id (self->priv->item_mngr, id);
+}
+
+
+static void
+photos_view_container_query_status_changed (PhotosTrackerController *trk_cntrlr,
+                                            gboolean query_status,
+                                            gpointer user_data)
+{
+  PhotosViewContainer *self = PHOTOS_VIEW_CONTAINER (user_data);
+  PhotosViewContainerPrivate *priv = self->priv;
+
+  if (!query_status)
+    {
+      priv->model = photos_item_manager_get_model (PHOTOS_ITEM_MANAGER (priv->item_mngr));
+      gd_main_view_set_model (priv->view, GTK_TREE_MODEL (priv->model));
+      photos_selection_controller_freeze_selection (priv->sel_cntrlr, FALSE);
+      /* TODO: update selection */
+    }
+  else
+    {
+      photos_selection_controller_freeze_selection (priv->sel_cntrlr, TRUE);
+      priv->model = NULL;
+      gd_main_view_set_model (priv->view, NULL);
+    }
+}
+
+
+static void
+photos_view_container_selection_mode_changed (PhotosSelectionController *sel_cntrlr,
+                                              gboolean mode,
+                                              gpointer user_data)
+{
+  PhotosViewContainer *self = PHOTOS_VIEW_CONTAINER (user_data);
+  gd_main_view_set_selection_mode (self->priv->view, mode);
+}
+
+
+static void
+photos_view_container_selection_mode_request (GdMainView *main_view, gpointer user_data)
+{
+  PhotosViewContainer *self = PHOTOS_VIEW_CONTAINER (user_data);
+  photos_selection_controller_set_selection_mode (self->priv->sel_cntrlr, TRUE);
+}
+
+
+static void
+photos_view_container_view_selection_changed (GdMainView *main_view, gpointer user_data)
+{
+  PhotosViewContainer *self = PHOTOS_VIEW_CONTAINER (user_data);
+  PhotosViewContainerPrivate *priv = self->priv;
+  GList *selected_urns;
+  GList *selection;
+
+  selection = gd_main_view_get_selection (main_view);
+  selected_urns = photos_utils_get_urns_from_paths (selection, GTK_TREE_MODEL (priv->model));
+  photos_selection_controller_set_selection (priv->sel_cntrlr, selected_urns);
+
+  if (selection != NULL)
+    g_list_free_full (selection, (GDestroyNotify) gtk_tree_path_free);
+}
+
+
+static void
+photos_view_container_window_mode_changed (PhotosModeController *mode_cntrlr,
+                                           PhotosWindowMode mode,
+                                           PhotosWindowMode old_mode,
+                                           gpointer user_data)
+{
+  PhotosViewContainer *self = PHOTOS_VIEW_CONTAINER (user_data);
+
+  if (mode == PHOTOS_WINDOW_MODE_OVERVIEW)
+    photos_view_container_connect_view (self);
+  else
+    photos_view_container_disconnect_view (self);
+}
+
+
+static void
+photos_view_container_dispose (GObject *object)
+{
+  PhotosViewContainer *self = PHOTOS_VIEW_CONTAINER (object);
+  PhotosViewContainerPrivate *priv = self->priv;
+
+  if (!priv->disposed)
+    {
+      photos_view_container_disconnect_view (self);
+      priv->disposed = TRUE;
+    }
+
+  g_clear_object (&priv->item_mngr);
+  g_clear_object (&priv->sel_cntrlr);
+  g_clear_object (&priv->trk_cntrlr);
+
+  G_OBJECT_CLASS (photos_view_container_parent_class)->dispose (object);
+}
+
+
+static void
+photos_view_container_init (PhotosViewContainer *self)
+{
+  PhotosViewContainerPrivate *priv;
+  gboolean status;
+
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+                                            PHOTOS_TYPE_VIEW_CONTAINER,
+                                            PhotosViewContainerPrivate);
+  priv = self->priv;
+
+  gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
+
+  priv->view = gd_main_view_new (GD_MAIN_VIEW_ICON);
+  gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (priv->view));
+
+  gtk_widget_show_all (GTK_WIDGET (self));
+
+  g_signal_connect (priv->view, "item-activated", G_CALLBACK (photos_view_container_item_activated), self);
+  g_signal_connect (priv->view,
+                    "selection-mode-request",
+                    G_CALLBACK (photos_view_container_selection_mode_request),
+                    self);
+  g_signal_connect (priv->view,
+                    "view-selection-changed",
+                    G_CALLBACK (photos_view_container_view_selection_changed),
+                    self);
+
+  priv->item_mngr = photos_item_manager_new ();
+
+  priv->sel_cntrlr = photos_selection_controller_new ();
+  g_signal_connect (priv->sel_cntrlr,
+                    "selection-mode-changed",
+                    G_CALLBACK (photos_view_container_selection_mode_changed),
+                    self);
+  photos_view_container_selection_mode_changed (priv->sel_cntrlr,
+                                                photos_selection_controller_get_selection_mode (priv->sel_cntrlr),
+                                                self);
+
+  priv->mode_cntrlr = photos_mode_controller_new ();
+  g_signal_connect (priv->mode_cntrlr,
+                    "window-mode-changed",
+                    G_CALLBACK (photos_view_container_window_mode_changed),
+                    self);
+
+  priv->trk_cntrlr = photos_tracker_controller_new ();
+  g_signal_connect (priv->trk_cntrlr,
+                    "query-status-changed",
+                    G_CALLBACK (photos_view_container_query_status_changed),
+                    self);
+  photos_tracker_controller_start (priv->trk_cntrlr);
+
+  status = photos_tracker_controller_get_query_status (priv->trk_cntrlr);
+  photos_view_container_query_status_changed (priv->trk_cntrlr, status, self);
+}
+
+
+static void
+photos_view_container_class_init (PhotosViewContainerClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->dispose = photos_view_container_dispose;
+
+  g_type_class_add_private (class, sizeof (PhotosViewContainerPrivate));
+}
+
+
+GtkWidget *
+photos_view_container_new (void)
+{
+  return g_object_new (PHOTOS_TYPE_VIEW_CONTAINER, NULL);
+}
diff --git a/src/photos-view-container.h b/src/photos-view-container.h
new file mode 100644
index 0000000..b8d002a
--- /dev/null
+++ b/src/photos-view-container.h
@@ -0,0 +1,71 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright  2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef PHOTOS_VIEW_CONTAINER_H
+#define PHOTOS_VIEW_CONTAINER_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_VIEW_CONTAINER (photos_view_container_get_type ())
+
+#define PHOTOS_VIEW_CONTAINER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_VIEW_CONTAINER, PhotosViewContainer))
+
+#define PHOTOS_VIEW_CONTAINER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_VIEW_CONTAINER, PhotosViewContainerClass))
+
+#define PHOTOS_IS_VIEW_CONTAINER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_VIEW_CONTAINER))
+
+#define PHOTOS_IS_VIEW_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_VIEW_CONTAINER))
+
+#define PHOTOS_VIEW_CONTAINER_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_VIEW_CONTAINER, PhotosViewContainerClass))
+
+typedef struct _PhotosViewContainer        PhotosViewContainer;
+typedef struct _PhotosViewContainerClass   PhotosViewContainerClass;
+typedef struct _PhotosViewContainerPrivate PhotosViewContainerPrivate;
+
+struct _PhotosViewContainer
+{
+  GtkGrid parent_instance;
+  PhotosViewContainerPrivate *priv;
+};
+
+struct _PhotosViewContainerClass
+{
+  GtkGridClass parent_class;
+};
+
+GType                  photos_view_container_get_type               (void) G_GNUC_CONST;
+
+GtkWidget             *photos_view_container_new                    (void);
+
+G_END_DECLS
+
+#endif /* PHOTOS_VIEW_CONTAINER_H */



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