[gnome-photos] utils: Add photos_utils_get_controller



commit d68287d45b281c74233e3314b2c2eca5cddf84c8
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Jan 10 12:15:42 2017 +0100

    utils: Add photos_utils_get_controller
    
    It is a convenience function for getting the OffsetController and
    TrackerController for a given WindowMode. We can use this to delete
    some code in the subsequent commit.

 src/photos-utils.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/photos-utils.h |    9 +++++++-
 2 files changed, 66 insertions(+), 3 deletions(-)
---
diff --git a/src/photos-utils.c b/src/photos-utils.c
index cd751cd..35382ed 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012 – 2016 Red Hat, Inc.
+ * Copyright © 2012 – 2017 Red Hat, Inc.
  * Copyright © 2009 Yorba Foundation
  *
  * This program is free software; you can redistribute it and/or
@@ -42,6 +42,10 @@
 #include "photos-google-item.h"
 #include "photos-local-item.h"
 #include "photos-media-server-item.h"
+#include "photos-offset-collections-controller.h"
+#include "photos-offset-favorites-controller.h"
+#include "photos-offset-overview-controller.h"
+#include "photos-offset-search-controller.h"
 #include "photos-operation-insta-curve.h"
 #include "photos-operation-insta-filter.h"
 #include "photos-operation-insta-hefe.h"
@@ -62,7 +66,6 @@
 #include "photos-tool-enhance.h"
 #include "photos-tool-filters.h"
 #include "photos-tracker-collections-controller.h"
-#include "photos-tracker-controller.h"
 #include "photos-tracker-favorites-controller.h"
 #include "photos-tracker-overview-controller.h"
 #include "photos-tracker-queue.h"
@@ -935,6 +938,59 @@ photos_utils_eval_radial_line (gdouble crop_center_x,
 }
 
 
+void
+photos_utils_get_controller (PhotosWindowMode mode,
+                             PhotosOffsetController **out_offset_cntrlr,
+                             PhotosTrackerController **out_trk_cntrlr)
+{
+  PhotosOffsetController *offset_cntrlr = NULL;
+  PhotosTrackerController *trk_cntrlr = NULL;
+
+  g_return_if_fail (mode != PHOTOS_WINDOW_MODE_NONE);
+  g_return_if_fail (mode != PHOTOS_WINDOW_MODE_EDIT);
+  g_return_if_fail (mode != PHOTOS_WINDOW_MODE_PREVIEW);
+
+  switch (mode)
+    {
+    case PHOTOS_WINDOW_MODE_COLLECTIONS:
+      offset_cntrlr = photos_offset_collections_controller_dup_singleton ();
+      trk_cntrlr = photos_tracker_collections_controller_dup_singleton ();
+      break;
+
+    case PHOTOS_WINDOW_MODE_FAVORITES:
+      offset_cntrlr = photos_offset_favorites_controller_dup_singleton ();
+      trk_cntrlr = photos_tracker_favorites_controller_dup_singleton ();
+      break;
+
+    case PHOTOS_WINDOW_MODE_OVERVIEW:
+      offset_cntrlr = photos_offset_overview_controller_dup_singleton ();
+      trk_cntrlr = photos_tracker_overview_controller_dup_singleton ();
+      break;
+
+    case PHOTOS_WINDOW_MODE_SEARCH:
+      offset_cntrlr = photos_offset_search_controller_dup_singleton ();
+      trk_cntrlr = photos_tracker_search_controller_dup_singleton ();
+      break;
+
+    case PHOTOS_WINDOW_MODE_NONE:
+    case PHOTOS_WINDOW_MODE_EDIT:
+    case PHOTOS_WINDOW_MODE_PREVIEW:
+    default:
+      g_assert_not_reached ();
+      break;
+    }
+
+  if (out_offset_cntrlr != NULL)
+    g_set_object (out_offset_cntrlr, offset_cntrlr);
+
+  if (out_trk_cntrlr != NULL)
+    g_set_object (out_trk_cntrlr, trk_cntrlr);
+
+  g_clear_object (&offset_cntrlr);
+  g_clear_object (&trk_cntrlr);
+}
+
+
 static gchar *
 photos_utils_filename_get_extension_offset (const gchar *filename)
 {
diff --git a/src/photos-utils.h b/src/photos-utils.h
index f161e17..40bab83 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012 – 2016 Red Hat, Inc.
+ * Copyright © 2012 – 2017 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
@@ -38,6 +38,9 @@
 
 #include "photos-base-item.h"
 #include "photos-base-manager.h"
+#include "photos-item-manager.h"
+#include "photos-offset-controller.h"
+#include "photos-tracker-controller.h"
 
 G_BEGIN_DECLS
 
@@ -146,6 +149,10 @@ GQuark           photos_utils_flash_off_quark             (void);
 
 GQuark           photos_utils_flash_on_quark              (void);
 
+void             photos_utils_get_controller              (PhotosWindowMode mode,
+                                                           PhotosOffsetController **out_offset_cntrlr,
+                                                           PhotosTrackerController **out_trk_cntrlr);
+
 gchar           *photos_utils_get_extension_from_mime_type (const gchar *mime_type);
 
 


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