[frogr] Show error if bigger than max filesize for the account (#656466).



commit 67e539182f4fed00ce102d3f63161226fc30772a
Author: Mario Sanchez Prada <msanchez igalia com>
Date:   Sun Aug 14 17:43:22 2011 +0200

    Show error if bigger than max filesize for the account (#656466).
    
    Do not keep loading pictures if some of them is bigger than the
    maximum size allowed for a given account, typically a different limit
    for free and PRO accounts (15MB and 20MB at the moment).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=656466

 src/frogr-controller.c     |   37 +++++++++++++++++++++++++++++++++----
 src/frogr-picture-loader.c |   16 +++++++++++++---
 src/frogr-picture-loader.h |    4 ++--
 3 files changed, 48 insertions(+), 9 deletions(-)
---
diff --git a/src/frogr-controller.c b/src/frogr-controller.c
index 7546eff..4c73643 100644
--- a/src/frogr-controller.c
+++ b/src/frogr-controller.c
@@ -190,7 +190,7 @@ static void _notify_adding_to_group (FrogrController *self,
                                      FrogrPicture *picture,
                                      FrogrGroup *group);
 
-static void _on_picture_loaded (FrogrController *self, FrogrPicture *picture);
+static gboolean _on_picture_loaded (FrogrController *self, FrogrPicture *picture);
 
 static void _on_pictures_loaded (FrogrController *self);
 
@@ -1096,20 +1096,49 @@ _notify_adding_to_group (FrogrController *self,
   g_free (debug_msg);
 }
 
-static void
+static gboolean
 _on_picture_loaded (FrogrController *self, FrogrPicture *picture)
 {
   FrogrControllerPrivate *priv = NULL;
   FrogrMainViewModel *mainview_model = NULL;
+  gulong picture_filesize = 0;
+  gulong max_filesize = G_MAXULONG;
 
-  g_return_if_fail (FROGR_IS_CONTROLLER (self));
-  g_return_if_fail (FROGR_IS_PICTURE (picture));
+  g_return_val_if_fail (FROGR_IS_CONTROLLER (self), FALSE);
+  g_return_val_if_fail (FROGR_IS_PICTURE (picture), FALSE);
 
   priv = FROGR_CONTROLLER_GET_PRIVATE (self);
   mainview_model = frogr_main_view_get_model (priv->mainview);
 
+  /* We need this info if account info was already fetched. */
+  if (priv->account && priv->account_extra_info_fetched) {
+    max_filesize = frogr_account_get_max_filesize (priv->account);
+    picture_filesize = frogr_picture_get_filesize (picture);
+  }
+
+  /* Check max filesize limit, and stop the process if needed. */
+  if (picture_filesize > max_filesize) {
+    GtkWindow *window = NULL;
+    gchar *msg = NULL;
+
+    /* First %s is the title of the picture (filename of the file by
+       default). Second %s is the max allowed size for a picture to be
+       uploaded to flickr (different for free and PRO accounts). */
+    msg = g_strdup_printf (_("Can't load picture %s: size of file is bigger "
+                             "than the maximum allowed for this account (%s)"),
+                           frogr_picture_get_title (picture),
+                           frogr_util_get_datasize_string (max_filesize));
+
+    window = frogr_main_view_get_window (priv->mainview);
+    frogr_util_show_error_dialog (window, msg);
+    g_free (msg);
+
+    return FALSE;
+  }
+
   frogr_main_view_model_add_picture (mainview_model, picture);
   g_signal_emit (self, signals[PICTURE_LOADED], 0, picture);
+  return TRUE;
 }
 
 static void
diff --git a/src/frogr-picture-loader.c b/src/frogr-picture-loader.c
index 46b1a6a..c717f08 100644
--- a/src/frogr-picture-loader.c
+++ b/src/frogr-picture-loader.c
@@ -204,6 +204,7 @@ _load_next_picture_cb (GObject *object,
   GError *error = NULL;
   gchar *contents = NULL;
   gsize length = 0;
+  gboolean keep_going = TRUE;
 
   self = FROGR_PICTURE_LOADER (data);;
   priv = FROGR_PICTURE_LOADER_GET_PRIVATE (self);
@@ -346,15 +347,24 @@ _load_next_picture_cb (GObject *object,
 
   /* Execute 'picture-loaded' callback */
   if (priv->picture_loaded_cb && fpicture)
-    priv->picture_loaded_cb (priv->object, fpicture);
+    keep_going = priv->picture_loaded_cb (priv->object, fpicture);
 
   /* Free memory */
   g_free (contents);
   if (fpicture != NULL)
     g_object_unref (fpicture);
 
-  /* Go for the next picture */
-  _load_next_picture (self);
+  /* Go for the next picture, if needed */
+  if (keep_going)
+    _load_next_picture (self);
+  else {
+    /* Execute final callback */
+    if (priv->pictures_loaded_cb)
+      priv->pictures_loaded_cb (priv->object);
+
+    /* Process finished, self-destruct */
+    g_object_unref (self);
+  }
 }
 
 static void
diff --git a/src/frogr-picture-loader.h b/src/frogr-picture-loader.h
index c5996c9..fc68f77 100644
--- a/src/frogr-picture-loader.h
+++ b/src/frogr-picture-loader.h
@@ -39,8 +39,8 @@ typedef struct _FrogrPictureLoader FrogrPictureLoader;
 typedef struct _FrogrPictureLoaderClass FrogrPictureLoaderClass;
 
 /* Callback to be executed after every single load */
-typedef void (*FrogrPictureLoadedCallback) (GObject *source,
-                                            FrogrPicture *picture);
+typedef gboolean (*FrogrPictureLoadedCallback) (GObject *source,
+                                                FrogrPicture *picture);
 
 /* Callback to be executed after all the pictures are loaded */
 typedef void (*FrogrPicturesLoadedCallback) (GObject *source);



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