[gnome-utils] [baobab] Adds suggested filename to chart snapshot file-chooser dialog



commit 4d1f26b4ea6b0f5d2b5403938e9a9fefa9214058
Author: Eduardo Lima Mitev <elima igalia com>
Date:   Mon Jul 27 13:29:55 2009 +0200

    [baobab] Adds suggested filename to chart snapshot file-chooser dialog
    
    Closes bug #546196

 baobab/src/baobab-chart.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/baobab/src/baobab-chart.c b/baobab/src/baobab-chart.c
index 7fa139b..204801b 100644
--- a/baobab/src/baobab-chart.c
+++ b/baobab/src/baobab-chart.c
@@ -41,6 +41,8 @@
                                        BAOBAB_CHART_TYPE, \
                                        BaobabChartPrivate))
 
+#define SNAPSHOT_DEF_FILENAME_FORMAT "%s-disk-usage"
+
 G_DEFINE_ABSTRACT_TYPE (BaobabChart, baobab_chart, GTK_TYPE_WIDGET);
 
 enum
@@ -1649,6 +1651,9 @@ baobab_chart_save_snapshot (GtkWidget *chart)
   GtkWidget *opt_menu;
   gchar *sel_type;
   gchar *filename;
+  gchar *def_filename;
+
+  BaobabChartItem *item;
 
   g_return_if_fail (BAOBAB_IS_CHART (chart));
 
@@ -1671,6 +1676,8 @@ baobab_chart_save_snapshot (GtkWidget *chart)
       return;
     }
 
+  priv = BAOBAB_CHART (chart)->priv;
+
   /* Popup the File chooser dialog */
   fs_dlg = gtk_file_chooser_dialog_new (_("Save Snapshot"),
                                         NULL,
@@ -1680,6 +1687,12 @@ baobab_chart_save_snapshot (GtkWidget *chart)
                                         GTK_STOCK_SAVE,
                                         GTK_RESPONSE_ACCEPT, NULL);
 
+  item = (BaobabChartItem *) priv->first_item->data;
+  def_filename = g_strdup_printf (SNAPSHOT_DEF_FILENAME_FORMAT, item->name);
+
+  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fs_dlg), def_filename);
+  g_free (def_filename);
+
   gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fs_dlg),
                                        g_get_home_dir ());
 
@@ -1714,6 +1727,13 @@ baobab_chart_save_snapshot (GtkWidget *chart)
     {
       filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fs_dlg));
       sel_type = gtk_combo_box_get_active_text (GTK_COMBO_BOX (opt_menu));
+      if (! g_str_has_suffix (filename, sel_type))
+        {
+          gchar *tmp;
+          tmp = filename;
+          filename = g_strjoin (".", filename, sel_type, NULL);
+          g_free (tmp);
+        }
       gdk_pixbuf_save (pixbuf, filename, sel_type, NULL, NULL);
 
       g_free (filename);



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