[gnome-photos/gnome-3-24] application, source-manager: Add an option to run without any content



commit 9aee8a4720386e0a36dd98c2a9709111585320d0
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Dec 8 14:45:18 2017 +0100

    application, source-manager: Add an option to run without any content
    
    This will make it easier to develop and test the "empty state" logic.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785376

 src/photos-application.c    |   38 ++++++++++++++++++++++++++++++++++++++
 src/photos-application.h    |    2 ++
 src/photos-source-manager.c |   22 +++++++++++++++++++---
 3 files changed, 59 insertions(+), 3 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 4e5a9d6..621c1f7 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -118,6 +118,7 @@ struct _PhotosApplication
   PhotosSelectionController *sel_cntrlr;
   PhotosThumbnailFactory *factory;
   TrackerExtractPriority *extract_priority;
+  gboolean empty_results;
   gboolean main_window_deleted;
   guint create_miners_count;
   guint init_fishes_id;
@@ -150,6 +151,7 @@ enum
 
 static const GOptionEntry COMMAND_LINE_OPTIONS[] =
 {
+  { "empty-results", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, N_("Show the empty state"), NULL },
   { "version", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, N_("Show the application's version"), NULL},
   { NULL }
 };
@@ -1574,6 +1576,32 @@ photos_application_activate (GApplication *application)
 }
 
 
+static gint
+photos_application_command_line (GApplication *application, GApplicationCommandLine *command_line)
+{
+  PhotosApplication *self = PHOTOS_APPLICATION (application);
+  GVariantDict *options;
+  gint ret_val = -1;
+
+  options = g_application_command_line_get_options_dict (command_line);
+  if (g_variant_dict_contains (options, "empty-results"))
+    {
+      if (g_application_command_line_get_is_remote (command_line))
+        {
+          ret_val = EXIT_FAILURE;
+          goto out;
+        }
+
+      self->empty_results = TRUE;
+    }
+
+  g_application_activate (application);
+
+ out:
+  return ret_val;
+}
+
+
 static gboolean
 photos_application_dbus_register (GApplication *application,
                                   GDBusConnection *connection,
@@ -2036,6 +2064,7 @@ photos_application_init (PhotosApplication *self)
   self->activation_timestamp = GDK_CURRENT_TIME;
 
   g_application_add_main_option_entries (G_APPLICATION (self), COMMAND_LINE_OPTIONS);
+  g_application_set_flags (G_APPLICATION (self), G_APPLICATION_HANDLES_COMMAND_LINE);
 }
 
 
@@ -2048,6 +2077,7 @@ photos_application_class_init (PhotosApplicationClass *class)
   object_class->dispose = photos_application_dispose;
   object_class->finalize = photos_application_finalize;
   application_class->activate = photos_application_activate;
+  application_class->command_line = photos_application_command_line;
   application_class->dbus_register = photos_application_dbus_register;
   application_class->dbus_unregister = photos_application_dbus_unregister;
   application_class->handle_local_options = photos_application_handle_local_options;
@@ -2083,6 +2113,14 @@ photos_application_new (void)
 }
 
 
+gboolean
+photos_application_get_empty_results (PhotosApplication *self)
+{
+  g_return_val_if_fail (PHOTOS_IS_APPLICATION (self), FALSE);
+  return self->empty_results;
+}
+
+
 GomMiner *
 photos_application_get_miner (PhotosApplication *self, const gchar *provider_type)
 {
diff --git a/src/photos-application.h b/src/photos-application.h
index caf3a38..b14f408 100644
--- a/src/photos-application.h
+++ b/src/photos-application.h
@@ -36,6 +36,8 @@ G_DECLARE_FINAL_TYPE (PhotosApplication, photos_application, PHOTOS, APPLICATION
 
 GApplication          *photos_application_new                    (void);
 
+gboolean               photos_application_get_empty_results      (PhotosApplication *self);
+
 GomMiner              *photos_application_get_miner              (PhotosApplication *self,
                                                                   const gchar *provider_type);
 
diff --git a/src/photos-source-manager.c b/src/photos-source-manager.c
index 67b2941..3f8b5e3 100644
--- a/src/photos-source-manager.c
+++ b/src/photos-source-manager.c
@@ -30,6 +30,7 @@
 #include <glib/gi18n.h>
 #include <goa/goa.h>
 
+#include "photos-application.h"
 #include "photos-filterable.h"
 #include "photos-query.h"
 #include "photos-source.h"
@@ -65,10 +66,18 @@ G_DEFINE_TYPE (PhotosSourceManager, photos_source_manager, PHOTOS_TYPE_BASE_MANA
 static gchar *
 photos_source_manager_get_filter (PhotosBaseManager *mngr, gint flags)
 {
+  GApplication *app;
   GObject *source;
   const gchar *id;
   gchar *filter;
 
+  app = g_application_get_default ();
+  if (photos_application_get_empty_results (PHOTOS_APPLICATION (app)))
+    {
+      filter = g_strdup ("(false)");
+      goto out;
+    }
+
   if (flags & PHOTOS_QUERY_FLAGS_SEARCH)
     source = photos_base_manager_get_active_object (mngr);
   else
@@ -80,6 +89,7 @@ photos_source_manager_get_filter (PhotosBaseManager *mngr, gint flags)
   else
     filter = photos_filterable_get_filter (PHOTOS_FILTERABLE (source));
 
+ out:
   return filter;
 }
 
@@ -107,12 +117,17 @@ photos_source_manager_remove_object_by_id (PhotosBaseManager *mngr, const gchar
 static void
 photos_source_manager_refresh_accounts (PhotosSourceManager *self)
 {
-  GHashTable *new_sources;
-  GList *accounts;
+  GApplication *app;
+  GHashTable *new_sources = NULL;
+  GList *accounts = NULL;
   GList *l;
   guint i;
   guint n_items;
 
+  app = g_application_get_default ();
+  if (photos_application_get_empty_results (PHOTOS_APPLICATION (app)))
+    goto out;
+
   accounts = goa_client_get_accounts (self->client);
   new_sources = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
 
@@ -185,7 +200,8 @@ photos_source_manager_refresh_accounts (PhotosSourceManager *self)
       g_clear_object (&source);
     }
 
-  g_hash_table_unref (new_sources);
+ out:
+  g_clear_pointer (&new_sources, (GDestroyNotify) g_hash_table_unref);
   g_list_free_full (accounts, g_object_unref);
 }
 


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