[Xfce4-commits] <ristretto:master> Added save-as function

Stephan Arts stephan at xfce.org
Wed Aug 12 12:18:46 CEST 2009


Updating branch refs/heads/master
         to b53ef99302afe9424dc1f8424e0c896034f3069c (commit)
       from 4b1c367e21a57eaf0f1785838268f379f22bde89 (commit)

commit b53ef99302afe9424dc1f8424e0c896034f3069c
Author: Stephan Arts <stephan at xfce.org>
Date:   Sat May 2 01:27:36 2009 +0200

    Added save-as function
    
        * src/main_window.c
          src/main_window_ui.xml: Implement save-as function (Bug #4647)
        * src/navigator.c: Fix iter_find_image function
        * src/image_cache.h
          src/image_cache.c: Return TRUE when the cache had to drop images to
          fit the new one.
        * src/main.c: Fix error when trying to open nonexistent file from the
          CLI

 ChangeLog              |   13 ++++++++++++-
 src/image_cache.c      |   14 ++++++++++++--
 src/image_cache.h      |    2 +-
 src/main.c             |   16 +++++++++++-----
 src/main_window.c      |   39 +++++++++++++++++++++++++++++++++++++++
 src/main_window_ui.xml |    2 ++
 src/navigator.c        |    1 +
 7 files changed, 78 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index dcfc193..b913bf5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,19 @@
 2009-05-02  Stephan Arts <stephan at xfce.org>
 
+	* src/main_window.c
+	  src/main_window_ui.xml: Implement save-as function (Bug #4647)
+	* src/navigator.c: Fix iter_find_image function
+	* src/image_cache.h
+	  src/image_cache.c: Return TRUE when the cache had to drop images to
+	  fit the new one.
+	* src/main.c: Fix error when trying to open nonexistent file from the
+	  CLI
+
+2009-05-02  Stephan Arts <stephan at xfce.org>
+
 	* src/image,c
 	  src/image.h
-	  src/image_cache.c: Implement image-cache size calculation
+	  src/image_cache.c: Implement image-cache size calculation (Bug #4064)
 
 2009-05-02  Stephan Arts <stephan at xfce.org>
 
diff --git a/src/image_cache.c b/src/image_cache.c
index 55f2de3..46d7220 100644
--- a/src/image_cache.c
+++ b/src/image_cache.c
@@ -86,9 +86,10 @@ rstto_image_cache_class_init (GObjectClass *object_class)
 
 }
 
-void
+gboolean
 rstto_image_cache_push_image (RsttoImageCache *cache, RsttoImage *image, gboolean last)
 {
+    gboolean retval = FALSE;
     RsttoSettings *settings = rstto_settings_new();
     GValue val = {0, }, val_cache_size = {0, };
     guint64 size = 0;
@@ -119,17 +120,24 @@ rstto_image_cache_push_image (RsttoImageCache *cache, RsttoImage *image, gboolea
         cache->cache_list = g_list_prepend (cache->cache_list, image);
     }
 
+    /**
+     * Check if we are keeping a cache
+     */
     if (g_value_get_boolean (&val) == FALSE)
     {
-        if (g_list_length (cache->cache_list) > 1)
+        while (g_list_length (cache->cache_list) > 1)
         {
             c_image = g_list_last (cache->cache_list)->data;
             rstto_image_unload (c_image);
             cache->cache_list = g_list_remove (cache->cache_list, c_image);
+            retval = TRUE;
         }
     }
     else
     {
+        /* Calculate the cache-size, if it exceeds the defined maximum,
+         * unload the the images that exceed that.
+         */
         for (iter = cache->cache_list->next; iter != NULL; iter = g_list_next (iter))
         {
             c_image = iter->data;
@@ -139,10 +147,12 @@ rstto_image_cache_push_image (RsttoImageCache *cache, RsttoImage *image, gboolea
                 rstto_image_unload (c_image);
                 cache->cache_list = g_list_remove (cache->cache_list, c_image);
                 iter = g_list_previous(iter);
+                retval = TRUE;
             } 
         }
     }
     g_value_unset (&val);
+    return retval;
 }
 
 /**
diff --git a/src/image_cache.h b/src/image_cache.h
index ac1a4fe..16501a3 100644
--- a/src/image_cache.h
+++ b/src/image_cache.h
@@ -47,7 +47,7 @@ typedef struct _RsttoImageCacheClass RsttoImageCacheClass;
 
 RsttoImageCache *rstto_image_cache_new ();
 
-void rstto_image_cache_push_image (RsttoImageCache *cache, RsttoImage *image, gboolean last);
+gboolean rstto_image_cache_push_image (RsttoImageCache *cache, RsttoImage *image, gboolean last);
 
 G_END_DECLS
 
diff --git a/src/main.c b/src/main.c
index f914872..ef25bca 100644
--- a/src/main.c
+++ b/src/main.c
@@ -138,12 +138,18 @@ cb_rstto_open_files (RsttoOpenFiles *rof)
     if (rof->iter < rof->argc)
     {
         file = g_file_new_for_commandline_arg (rof->argv[rof->iter]);
-        file_info = g_file_query_info (file, "standard::content-type", 0, NULL, NULL);
-        content_type = g_file_info_get_attribute_string (file_info, "standard::content-type");
-
-        if (strncmp (content_type, "image/", 6) == 0)
+        if (file)
         {
-            rstto_navigator_add_file (rof->navigator, file, NULL);
+            file_info = g_file_query_info (file, "standard::content-type", 0, NULL, NULL);
+            if (file_info)
+            {
+                content_type = g_file_info_get_attribute_string (file_info, "standard::content-type");
+
+                if (strncmp (content_type, "image/", 6) == 0)
+                {
+                    rstto_navigator_add_file (rof->navigator, file, NULL);
+                }
+            }
         }
         rof->iter++;
         return TRUE;
diff --git a/src/main_window.c b/src/main_window.c
index 6ae02d3..7504afe 100644
--- a/src/main_window.c
+++ b/src/main_window.c
@@ -163,6 +163,8 @@ static void
 cb_rstto_main_window_close (GtkWidget *widget, RsttoMainWindow *window);
 static void
 cb_rstto_main_window_close_all (GtkWidget *widget, RsttoMainWindow *window);
+static void
+cb_rstto_main_window_save_as (GtkWidget *widget, RsttoMainWindow *window);
 
 static void
 cb_rstto_main_window_play (GtkWidget *widget, RsttoMainWindow *window);
@@ -204,6 +206,7 @@ static GtkActionEntry action_entries[] =
   { "file-menu", NULL, N_ ("_File"), NULL, },
   { "open", GTK_STOCK_OPEN, N_ ("_Open"), "<control>O", N_ ("Open an image"), G_CALLBACK (cb_rstto_main_window_open_image), },
   { "open-folder", NULL, N_ ("Open _Folder"), NULL, N_ ("Open a folder"), G_CALLBACK (cb_rstto_main_window_open_folder), },
+  { "save-as", GTK_STOCK_SAVE_AS, N_ ("_Save as"), "<control>s", N_ ("Save the image"), G_CALLBACK (cb_rstto_main_window_save_as), },
   { "close", GTK_STOCK_CLOSE, N_ ("_Close"), "<control>W", N_ ("Close this image"), G_CALLBACK (cb_rstto_main_window_close), },
   { "close-all", NULL, N_ ("_Close All"), NULL, N_ ("Close all images"), G_CALLBACK (cb_rstto_main_window_close_all), },
   { "quit", GTK_STOCK_QUIT, N_ ("_Quit"), "<control>Q", N_ ("Quit Ristretto"), G_CALLBACK (cb_rstto_main_window_quit), },
@@ -585,6 +588,11 @@ rstto_main_window_set_sensitive (RsttoMainWindow *window, gboolean sensitive)
     gtk_widget_set_sensitive (
             gtk_ui_manager_get_widget (
                     window->priv->ui_manager,
+                    "/main-menu/file-menu/save-as"),
+            sensitive);
+    gtk_widget_set_sensitive (
+            gtk_ui_manager_get_widget (
+                    window->priv->ui_manager,
                     "/main-menu/file-menu/close"),
             sensitive);
     gtk_widget_set_sensitive (
@@ -1092,6 +1100,37 @@ cb_rstto_main_window_open_recent(GtkRecentChooser *chooser, RsttoMainWindow *win
     g_free (uri);
 }
 
+static void
+cb_rstto_main_window_save_as (GtkWidget *widget, RsttoMainWindow *window)
+{
+    GtkWidget *dialog;
+    gint response;
+    GFile *file, *s_file;
+
+    dialog = gtk_file_chooser_dialog_new(_("Save as"),
+                                         GTK_WINDOW(window),
+                                         GTK_FILE_CHOOSER_ACTION_SAVE,
+                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                         GTK_STOCK_SAVE, GTK_RESPONSE_OK,
+                                         NULL);
+    gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
+
+    response = gtk_dialog_run(GTK_DIALOG(dialog));
+    if(response == GTK_RESPONSE_OK)
+    {
+        file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+        s_file = rstto_image_get_file (rstto_navigator_iter_get_image (window->priv->iter));
+        if (g_file_copy (s_file, file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL))
+        {
+            rstto_navigator_remove_image (window->priv->props.navigator, rstto_navigator_iter_get_image (window->priv->iter));
+            rstto_navigator_add_file (window->priv->props.navigator, file, NULL);
+        }
+    }
+
+    gtk_widget_destroy(dialog);
+
+}
+
 /**
  * cb_rstto_main_window_play:
  * @widget:
diff --git a/src/main_window_ui.xml b/src/main_window_ui.xml
index c3ab245..c2aaf0b 100644
--- a/src/main_window_ui.xml
+++ b/src/main_window_ui.xml
@@ -9,6 +9,8 @@
             <menuitem action="open-folder"/>
             <placeholder name="placeholder-open-recent"/>
             <separator/>
+            <menuitem action="save-as"/>
+            <separator/>
             <menuitem action="close"/>
             <menuitem action="close-all"/>
             <menuitem action="quit"/>
diff --git a/src/navigator.c b/src/navigator.c
index 29292a1..9a654fc 100644
--- a/src/navigator.c
+++ b/src/navigator.c
@@ -273,6 +273,7 @@ gboolean
 rstto_navigator_iter_find_image (RsttoNavigatorIter *iter, RsttoImage *image)
 {
     GList *list = g_list_find (iter->list, image);
+    iter->iter = list;
 
     if (list)
         return TRUE;



More information about the Xfce4-commits mailing list