[frogr] Renamed FrogrPictureLoader to FrogrFileLoader.



commit 4b0b66c36b3b11836c93dbc1b63198b2631c959e
Author: Mario Sanchez Prada <msanchez gnome org>
Date:   Tue Oct 30 10:52:19 2012 +0100

    Renamed FrogrPictureLoader to FrogrFileLoader.
    
    One day frogr will also load / upload other kind of media (e.g. videos).

 src/Makefile.am                                    |    4 +-
 src/frogr-controller.c                             |   25 ++--
 ...{frogr-picture-loader.c => frogr-file-loader.c} |  162 ++++++++++----------
 src/frogr-file-loader.h                            |   70 +++++++++
 src/frogr-picture-loader.h                         |   70 ---------
 5 files changed, 165 insertions(+), 166 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index a12a516..e009941 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -62,6 +62,8 @@ frogr_SOURCES = \
 	frogr-create-new-set-dialog.h \
 	frogr-details-dialog.c \
 	frogr-details-dialog.h \
+	frogr-file-loader.c \
+	frogr-file-loader.h \
 	frogr-global-defs.h \
 	frogr-group.c \
 	frogr-group.h \
@@ -77,8 +79,6 @@ frogr_SOURCES = \
 	frogr-main-view.h \
 	frogr-photoset.c \
 	frogr-photoset.h \
-	frogr-picture-loader.c \
-	frogr-picture-loader.h \
 	frogr-picture.c \
 	frogr-picture.h \
 	frogr-settings-dialog.c \
diff --git a/src/frogr-controller.c b/src/frogr-controller.c
index fa04813..84c3e25 100644
--- a/src/frogr-controller.c
+++ b/src/frogr-controller.c
@@ -23,15 +23,15 @@
 #include "frogr-about-dialog.h"
 #include "frogr-account.h"
 #include "frogr-add-tags-dialog.h"
-#include "frogr-add-to-set-dialog.h"
 #include "frogr-add-to-group-dialog.h"
+#include "frogr-add-to-set-dialog.h"
 #include "frogr-auth-dialog.h"
 #include "frogr-config.h"
 #include "frogr-create-new-set-dialog.h"
 #include "frogr-details-dialog.h"
+#include "frogr-file-loader.h"
 #include "frogr-global-defs.h"
 #include "frogr-main-view.h"
-#include "frogr-picture-loader.h"
 #include "frogr-settings-dialog.h"
 #include "frogr-util.h"
 
@@ -210,9 +210,9 @@ static void _notify_adding_to_group (FrogrController *self,
                                      FrogrPicture *picture,
                                      FrogrGroup *group);
 
-static gboolean _on_picture_loaded (FrogrController *self, FrogrPicture *picture);
+static gboolean _on_file_loaded (FrogrController *self, FrogrPicture *picture);
 
-static void _on_pictures_loaded (FrogrController *self);
+static void _on_files_loaded (FrogrController *self);
 
 static void _fetch_everything (FrogrController *self, gboolean force_fetch);
 
@@ -1345,7 +1345,7 @@ _notify_adding_to_group (FrogrController *self,
 }
 
 static gboolean
-_on_picture_loaded (FrogrController *self, FrogrPicture *picture)
+_on_file_loaded (FrogrController *self, FrogrPicture *picture)
 {
   FrogrControllerPrivate *priv = NULL;
   FrogrMainViewModel *mainview_model = NULL;
@@ -1392,7 +1392,7 @@ _on_picture_loaded (FrogrController *self, FrogrPicture *picture)
 }
 
 static void
-_on_pictures_loaded (FrogrController *self)
+_on_files_loaded (FrogrController *self)
 {
   g_return_if_fail (FROGR_IS_CONTROLLER (self));
 
@@ -2693,15 +2693,14 @@ void
 frogr_controller_load_pictures (FrogrController *self,
                                 GSList *fileuris)
 {
-  FrogrPictureLoader *fploader;
-  fploader = frogr_picture_loader_new (fileuris,
-                                       (FrogrPictureLoadedCallback) _on_picture_loaded,
-                                       (FrogrPicturesLoadedCallback) _on_pictures_loaded,
-                                       self);
+  FrogrFileLoader *loader;
+  loader = frogr_file_loader_new (fileuris,
+                                  (FrogrFileLoadedCallback) _on_file_loaded,
+                                  (FrogrFilesLoadedCallback) _on_files_loaded,
+                                  self);
   /* Load the pictures! */
   _set_state (self, FROGR_STATE_LOADING_PICTURES);
-
-  frogr_picture_loader_load (fploader);
+  frogr_file_loader_load (loader);
 }
 
 void
diff --git a/src/frogr-picture-loader.c b/src/frogr-file-loader.c
similarity index 81%
rename from src/frogr-picture-loader.c
rename to src/frogr-file-loader.c
index a99cf9b..550de70 100644
--- a/src/frogr-picture-loader.c
+++ b/src/frogr-file-loader.c
@@ -1,5 +1,5 @@
 /*
- * frogr-picture-loader.c -- Asynchronous picture loader in frogr
+ * frogr-file-loader.c -- Asynchronous file loader in frogr
  *
  * Copyright (C) 2009-2012 Mario Sanchez Prada
  * Authors: Mario Sanchez Prada <msanchez gnome org>
@@ -22,7 +22,7 @@
  *
  */
 
-#include "frogr-picture-loader.h"
+#include "frogr-file-loader.h"
 
 #include "frogr-config.h"
 #include "frogr-controller.h"
@@ -42,16 +42,16 @@
 #include <glib/gi18n.h>
 #include <gio/gio.h>
 
-#define FROGR_PICTURE_LOADER_GET_PRIVATE(object)                \
+#define FROGR_FILE_LOADER_GET_PRIVATE(object)                   \
   (G_TYPE_INSTANCE_GET_PRIVATE ((object),                       \
-                                FROGR_TYPE_PICTURE_LOADER,      \
-                                FrogrPictureLoaderPrivate))
+                                FROGR_TYPE_FILE_LOADER,         \
+                                FrogrFileLoaderPrivate))
 
-G_DEFINE_TYPE (FrogrPictureLoader, frogr_picture_loader, G_TYPE_OBJECT)
+G_DEFINE_TYPE (FrogrFileLoader, frogr_file_loader, G_TYPE_OBJECT)
 
 /* Private struct */
-typedef struct _FrogrPictureLoaderPrivate FrogrPictureLoaderPrivate;
-struct _FrogrPictureLoaderPrivate
+typedef struct _FrogrFileLoaderPrivate FrogrFileLoaderPrivate;
+struct _FrogrFileLoaderPrivate
 {
   FrogrController *controller;
   FrogrMainView *mainview;
@@ -59,7 +59,7 @@ struct _FrogrPictureLoaderPrivate
   GSList *file_uris;
   GSList *current;
   guint index;
-  guint n_pictures;
+  guint n_files;
 
   gboolean keep_file_extensions;
   gboolean import_tags;
@@ -72,8 +72,8 @@ struct _FrogrPictureLoaderPrivate
   FspSafetyLevel safety_level;
   FspContentType content_type;
 
-  FrogrPictureLoadedCallback picture_loaded_cb;
-  FrogrPicturesLoadedCallback pictures_loaded_cb;
+  FrogrFileLoadedCallback file_loaded_cb;
+  FrogrFilesLoadedCallback files_loaded_cb;
   GObject *object;
 };
 
@@ -91,11 +91,11 @@ static const gchar *valid_mimetypes[] = {
 
 /* Prototypes */
 
-static void _update_status_and_progress (FrogrPictureLoader *self);
-static void _load_next_picture (FrogrPictureLoader *self);
-static void _load_next_picture_cb (GObject *object,
-                                   GAsyncResult *res,
-                                   gpointer data);
+static void _update_status_and_progress (FrogrFileLoader *self);
+static void _load_next_file (FrogrFileLoader *self);
+static void _load_next_file_cb (GObject *object,
+                                GAsyncResult *res,
+                                gpointer data);
 
 static gboolean get_gps_coordinate (ExifData *exif,
                                     ExifTag   tag,
@@ -105,22 +105,22 @@ static FrogrLocation *get_location_from_exif (ExifData *exif_data);
 
 static gchar *remove_spaces_from_keyword (const gchar *keyword);
 static gchar *import_tags_from_xmp_keywords (const char *buffer, size_t len);
-static void _finish_task_and_self_destruct (FrogrPictureLoader *self);
+static void _finish_task_and_self_destruct (FrogrFileLoader *self);
 
 /* Private API */
 
 static void
-_update_status_and_progress (FrogrPictureLoader *self)
+_update_status_and_progress (FrogrFileLoader *self)
 {
-  FrogrPictureLoaderPrivate *priv =
-    FROGR_PICTURE_LOADER_GET_PRIVATE (self);
+  FrogrFileLoaderPrivate *priv =
+    FROGR_FILE_LOADER_GET_PRIVATE (self);
 
   gchar *status_text = NULL;
 
   /* Update progress */
   if (priv->current)
-    status_text = g_strdup_printf (_("Loading pictures %d / %d"),
-                                   priv->index, priv->n_pictures);
+    status_text = g_strdup_printf (_("Loading files %d / %d"),
+                                   priv->index, priv->n_files);
 
   frogr_main_view_set_status_text (priv->mainview, status_text);
 
@@ -129,10 +129,10 @@ _update_status_and_progress (FrogrPictureLoader *self)
 }
 
 static void
-_load_next_picture (FrogrPictureLoader *self)
+_load_next_file (FrogrFileLoader *self)
 {
-  FrogrPictureLoaderPrivate *priv =
-    FROGR_PICTURE_LOADER_GET_PRIVATE (self);
+  FrogrFileLoaderPrivate *priv =
+    FROGR_FILE_LOADER_GET_PRIVATE (self);
 
   if (priv->current)
     {
@@ -176,21 +176,21 @@ _load_next_picture (FrogrPictureLoader *self)
         }
 #endif
 
-      /* Asynchronously load the picture if mime is valid */
+      /* Asynchronously load the file if mime is valid */
       if (file_info && valid_mime)
         {
           g_file_load_contents_async (gfile,
                                       NULL,
-                                      _load_next_picture_cb,
+                                      _load_next_file_cb,
                                       self);
           DEBUG ("Adding file %s", file_uri);
         }
       else
         {
-          /* update internal status and check the next picture */
+          /* update internal status and check the next file */
           priv->current = g_slist_next (priv->current);
           priv->index++;
-          _load_next_picture (self);
+          _load_next_file (self);
         }
     }
   else
@@ -202,12 +202,12 @@ _load_next_picture (FrogrPictureLoader *self)
 }
 
 static void
-_load_next_picture_cb (GObject *object,
-                       GAsyncResult *res,
-                       gpointer data)
+_load_next_file_cb (GObject *object,
+                    GAsyncResult *res,
+                    gpointer data)
 {
-  FrogrPictureLoader *self = NULL;
-  FrogrPictureLoaderPrivate *priv = NULL;
+  FrogrFileLoader *self = NULL;
+  FrogrFileLoaderPrivate *priv = NULL;
   FrogrPicture *fpicture = NULL;
   GFile *file = NULL;
   GError *error = NULL;
@@ -215,8 +215,8 @@ _load_next_picture_cb (GObject *object,
   gsize length = 0;
   gboolean keep_going = TRUE;
 
-  self = FROGR_PICTURE_LOADER (data);;
-  priv = FROGR_PICTURE_LOADER_GET_PRIVATE (self);
+  self = FROGR_FILE_LOADER (data);;
+  priv = FROGR_FILE_LOADER_GET_PRIVATE (self);
 
   file = G_FILE (object);
   if (g_file_load_contents_finish (file, res, &contents, &length, NULL, &error))
@@ -381,16 +381,16 @@ _load_next_picture_cb (GObject *object,
   /* Update status and progress */
   _update_status_and_progress (self);
 
-  /* Execute 'picture-loaded' callback */
-  if (priv->picture_loaded_cb && fpicture)
-    keep_going = priv->picture_loaded_cb (priv->object, fpicture);
+  /* Execute 'file-loaded' callback */
+  if (priv->file_loaded_cb && fpicture)
+    keep_going = priv->file_loaded_cb (priv->object, fpicture);
 
   if (fpicture != NULL)
     g_object_unref (fpicture);
 
-  /* Go for the next picture, if needed */
+  /* Go for the next file, if needed */
   if (keep_going)
-    _load_next_picture (self);
+    _load_next_file (self);
   else
     _finish_task_and_self_destruct (self);
 }
@@ -430,8 +430,8 @@ get_gps_coordinate (ExifData *exif,
         }
 
       f = (double)c1.numerator/c1.denominator+
-          (double)c2.numerator/(c2.denominator*60)+
-          (double)c3.numerator/(c3.denominator*60*60);
+        (double)c2.numerator/(c2.denominator*60)+
+        (double)c3.numerator/(c3.denominator*60*60);
 
       if (ref == 'S' || ref == 'W')
         {
@@ -553,24 +553,24 @@ import_tags_from_xmp_keywords (const char *buffer, size_t len)
 }
 
 static void
-_finish_task_and_self_destruct (FrogrPictureLoader *self)
+_finish_task_and_self_destruct (FrogrFileLoader *self)
 {
-  FrogrPictureLoaderPrivate *priv =
-    FROGR_PICTURE_LOADER_GET_PRIVATE (self);
+  FrogrFileLoaderPrivate *priv =
+    FROGR_FILE_LOADER_GET_PRIVATE (self);
 
   /* Execute final callback */
-  if (priv->pictures_loaded_cb)
-    priv->pictures_loaded_cb (priv->object);
+  if (priv->files_loaded_cb)
+    priv->files_loaded_cb (priv->object);
 
   /* Process finished, self-destruct */
   g_object_unref (self);
 }
 
 static void
-_frogr_picture_loader_dispose (GObject* object)
+_frogr_file_loader_dispose (GObject* object)
 {
-  FrogrPictureLoaderPrivate *priv =
-    FROGR_PICTURE_LOADER_GET_PRIVATE (object);
+  FrogrFileLoaderPrivate *priv =
+    FROGR_FILE_LOADER_GET_PRIVATE (object);
 
   if (priv->mainview)
     {
@@ -584,38 +584,38 @@ _frogr_picture_loader_dispose (GObject* object)
       priv->controller = NULL;
     }
 
-  G_OBJECT_CLASS (frogr_picture_loader_parent_class)->dispose(object);
+  G_OBJECT_CLASS (frogr_file_loader_parent_class)->dispose(object);
 }
 
 static void
-_frogr_picture_loader_finalize (GObject* object)
+_frogr_file_loader_finalize (GObject* object)
 {
-  FrogrPictureLoaderPrivate *priv =
-    FROGR_PICTURE_LOADER_GET_PRIVATE (object);
+  FrogrFileLoaderPrivate *priv =
+    FROGR_FILE_LOADER_GET_PRIVATE (object);
 
   /* Free */
   g_slist_foreach (priv->file_uris, (GFunc)g_free, NULL);
   g_slist_free (priv->file_uris);
 
-  G_OBJECT_CLASS (frogr_picture_loader_parent_class)->finalize(object);
+  G_OBJECT_CLASS (frogr_file_loader_parent_class)->finalize(object);
 }
 
 static void
-frogr_picture_loader_class_init(FrogrPictureLoaderClass *klass)
+frogr_file_loader_class_init(FrogrFileLoaderClass *klass)
 {
   GObjectClass *obj_class = G_OBJECT_CLASS(klass);
 
-  obj_class->dispose = _frogr_picture_loader_dispose;
-  obj_class->finalize = _frogr_picture_loader_finalize;
+  obj_class->dispose = _frogr_file_loader_dispose;
+  obj_class->finalize = _frogr_file_loader_finalize;
 
-  g_type_class_add_private (obj_class, sizeof (FrogrPictureLoaderPrivate));
+  g_type_class_add_private (obj_class, sizeof (FrogrFileLoaderPrivate));
 }
 
 static void
-frogr_picture_loader_init (FrogrPictureLoader *self)
+frogr_file_loader_init (FrogrFileLoader *self)
 {
-  FrogrPictureLoaderPrivate *priv =
-    FROGR_PICTURE_LOADER_GET_PRIVATE (self);
+  FrogrFileLoaderPrivate *priv =
+    FROGR_FILE_LOADER_GET_PRIVATE (self);
 
   FrogrConfig *config = frogr_config_get_instance ();
 
@@ -641,23 +641,23 @@ frogr_picture_loader_init (FrogrPictureLoader *self)
   priv->file_uris = NULL;
   priv->current = NULL;
   priv->index = -1;
-  priv->n_pictures = 0;
+  priv->n_files = 0;
 }
 
 /* Public API */
 
-FrogrPictureLoader *
-frogr_picture_loader_new (GSList *file_uris,
-                          FrogrPictureLoadedCallback picture_loaded_cb,
-                          FrogrPicturesLoadedCallback pictures_loaded_cb,
-                          gpointer object)
+FrogrFileLoader *
+frogr_file_loader_new (GSList *file_uris,
+                       FrogrFileLoadedCallback file_loaded_cb,
+                       FrogrFilesLoadedCallback files_loaded_cb,
+                       gpointer object)
 {
-  FrogrPictureLoader *self = NULL;
-  FrogrPictureLoaderPrivate *priv = NULL;
+  FrogrFileLoader *self = NULL;
+  FrogrFileLoaderPrivate *priv = NULL;
   GSList *uri = NULL;
 
-  self = FROGR_PICTURE_LOADER (g_object_new(FROGR_TYPE_PICTURE_LOADER, NULL));
-  priv = FROGR_PICTURE_LOADER_GET_PRIVATE (self);
+  self = FROGR_FILE_LOADER (g_object_new(FROGR_TYPE_FILE_LOADER, NULL));
+  priv = FROGR_FILE_LOADER_GET_PRIVATE (self);
 
   /* We need to gain ownership of the strings */
   for (uri = file_uris; uri; uri = g_slist_next (uri))
@@ -667,24 +667,24 @@ frogr_picture_loader_new (GSList *file_uris,
   /* Other internal data */
   priv->current = priv->file_uris;
   priv->index = 0;
-  priv->n_pictures = g_slist_length (priv->file_uris);
+  priv->n_files = g_slist_length (priv->file_uris);
 
   /* Callback data */
-  priv->picture_loaded_cb = picture_loaded_cb;
-  priv->pictures_loaded_cb = pictures_loaded_cb;
+  priv->file_loaded_cb = file_loaded_cb;
+  priv->files_loaded_cb = files_loaded_cb;
   priv->object = object;
 
   return self;
 }
 
 void
-frogr_picture_loader_load (FrogrPictureLoader *self)
+frogr_file_loader_load (FrogrFileLoader *self)
 {
-  FrogrPictureLoaderPrivate *priv = NULL;
+  FrogrFileLoaderPrivate *priv = NULL;
 
-  g_return_if_fail (FROGR_IS_PICTURE_LOADER (self));
+  g_return_if_fail (FROGR_IS_FILE_LOADER (self));
 
-  priv = FROGR_PICTURE_LOADER_GET_PRIVATE (self);
+  priv = FROGR_FILE_LOADER_GET_PRIVATE (self);
 
   /* Check first whether there's something to load */
   if (priv->file_uris == NULL)
@@ -694,5 +694,5 @@ frogr_picture_loader_load (FrogrPictureLoader *self)
   _update_status_and_progress (self);
 
   /* Trigger the asynchronous process */
-  _load_next_picture (self);
+  _load_next_file (self);
 }
diff --git a/src/frogr-file-loader.h b/src/frogr-file-loader.h
new file mode 100644
index 0000000..b4699ff
--- /dev/null
+++ b/src/frogr-file-loader.h
@@ -0,0 +1,70 @@
+/*
+ * frogr-file-loader.h -- Asynchronous file loader in frogr
+ *
+ * Copyright (C) 2009-2012 Mario Sanchez Prada
+ * Authors: Mario Sanchez Prada <msanchez gnome org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef _FROGR_FILE_LOADER_H
+#define _FROGR_FILE_LOADER_H
+
+#include "frogr-picture.h"
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define FROGR_TYPE_FILE_LOADER            (frogr_file_loader_get_type())
+#define FROGR_FILE_LOADER(obj)            (G_TYPE_CHECK_INSTANCE_CAST(obj, FROGR_TYPE_FILE_LOADER, FrogrFileLoader))
+#define FROGR_FILE_LOADER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST(klass, FROGR_TYPE_FILE_LOADER, FrogrFileLoaderClass))
+#define FROGR_IS_FILE_LOADER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE(obj, FROGR_TYPE_FILE_LOADER))
+#define FROGR_IS_FILE_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), FROGR_TYPE_FILE_LOADER))
+#define FROGR_FILE_LOADER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), FROGR_TYPE_FILE_LOADER, FrogrFileLoaderClass))
+
+typedef struct _FrogrFileLoader FrogrFileLoader;
+typedef struct _FrogrFileLoaderClass FrogrFileLoaderClass;
+
+/* Callback to be executed after every single load */
+typedef gboolean (*FrogrFileLoadedCallback) (GObject *source,
+                                             FrogrPicture *picture);
+
+/* Callback to be executed after all the files are loaded */
+typedef void (*FrogrFilesLoadedCallback) (GObject *source);
+
+struct _FrogrFileLoader
+{
+  GObject parent_instance;
+};
+
+struct _FrogrFileLoaderClass
+{
+  GObjectClass parent_class;
+};
+
+
+GType frogr_file_loader_get_type(void) G_GNUC_CONST;
+
+FrogrFileLoader *frogr_file_loader_new (GSList *file_uris,
+                                        FrogrFileLoadedCallback file_loaded_cb,
+                                        FrogrFilesLoadedCallback files_loaded_cb,
+                                        gpointer object);
+
+void frogr_file_loader_load (FrogrFileLoader *self);
+
+G_END_DECLS
+
+#endif



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