[Xfce4-commits] <xfce4-screenshooter:master> Rework the actions dialog to add horodating.

Jérôme Guelfucci jeromeg at xfce.org
Fri Aug 14 00:26:16 CEST 2009


Updating branch refs/heads/master
         to 0e4e465cb968489bc032abf178a274b196a57a35 (commit)
       from de40fecd77cb06fc32a60497e24959bfd0b58c43 (commit)

commit 0e4e465cb968489bc032abf178a274b196a57a35
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date:   Fri Aug 7 20:01:15 2009 +0200

    Rework the actions dialog to add horodating.
    
    Add two new options: the title of the capture is now customizable and
    is used to generate the name of the saved captures. It is now also
    possible to append the date and the time of capturing to the name of
    the saved file (TODO: check if "horodating" exists in English).
    
    Fix a leak in the panel plugin.

 ChangeLog                           |   11 ++
 lib/screenshooter-actions.c         |   10 ++-
 lib/screenshooter-capture.c         |    2 +
 lib/screenshooter-dialogs.c         |  194 ++++++++++++++++++++++++++++-------
 lib/screenshooter-dialogs.h         |    6 +-
 lib/screenshooter-global.h          |    2 +
 lib/screenshooter-utils.c           |   48 +++++++++-
 lib/screenshooter-utils.h           |    3 +
 panel-plugin/screenshooter-plugin.c |    2 +
 src/main.c                          |    1 +
 10 files changed, 236 insertions(+), 43 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5a8a518..8b401ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,17 @@ Fixed the Indonesian documentation sub-directory, the autotools scripts were
 incomplete.
 Updated Italian and Galician documentation translation.
 
+2009-08-07 jeromeg
+
+Rework the actions dialog to add horodating.
+
+Add two new options: the title of the capture is now customizable and
+is used to generate the name of the saved captures. It is now also
+possible to append the date and the time of capturing to the name of
+the saved file (TODO: check if "horodating" exists in English).
+
+Fix a leak in the panel plugin.
+
 2009-08-05 jeromeg
 
 Improve the layout of the actions dialog.
diff --git a/lib/screenshooter-actions.c b/lib/screenshooter-actions.c
index 7cc1fdd..839cf70 100644
--- a/lib/screenshooter-actions.c
+++ b/lib/screenshooter-actions.c
@@ -83,7 +83,10 @@ gboolean screenshooter_action_idle (ScreenshotData *sd)
       if (sd->screenshot_dir == NULL)
         sd->screenshot_dir = screenshooter_get_home_uri ();
 
-      screenshooter_save_screenshot (sd->screenshot, sd->screenshot_dir);
+      screenshooter_save_screenshot (sd->screenshot,
+                                     sd->screenshot_dir,
+                                     sd->title,
+                                     sd->horodate);
     }
   else if (sd->action == CLIPBOARD)
     {
@@ -94,7 +97,10 @@ gboolean screenshooter_action_idle (ScreenshotData *sd)
       GFile *temp_dir = g_file_new_for_path (g_get_tmp_dir ());
       const gchar *temp_dir_uri = g_file_get_uri (temp_dir);
       const gchar *screenshot_path =
-        screenshooter_save_screenshot (sd->screenshot, temp_dir_uri);
+        screenshooter_save_screenshot (sd->screenshot,
+                                       temp_dir_uri,
+                                       sd->title,
+                                       sd->horodate);
 
       if (screenshot_path != NULL)
         {
diff --git a/lib/screenshooter-capture.c b/lib/screenshooter-capture.c
index 131c728..4da3a1f 100644
--- a/lib/screenshooter-capture.c
+++ b/lib/screenshooter-capture.c
@@ -461,6 +461,8 @@ GdkPixbuf *screenshooter_take_screenshot (gint region, gint delay, gboolean show
   display = gdk_display_get_default ();
   gdk_display_sync (display);
 
+  gdk_window_process_all_updates ();
+
   /* wait for n=delay seconds */
   /* Workaround: sleep at least one second to make sure the
    * WM/X server hast time to select the new active window after
diff --git a/lib/screenshooter-dialogs.c b/lib/screenshooter-dialogs.c
index 7858012..7c29ae2 100644
--- a/lib/screenshooter-dialogs.c
+++ b/lib/screenshooter-dialogs.c
@@ -49,6 +49,12 @@ static void
 cb_open_toggled                    (GtkToggleButton    *tb,
                                     ScreenshotData     *sd);
 static void
+cb_title_entry_changed             (GtkEditable        *editable,
+                                    ScreenshotData     *sd);
+static void
+cb_horodate_toggled                (GtkToggleButton    *togglebutton,
+                                    ScreenshotData     *sd);
+static void
 cb_clipboard_toggled               (GtkToggleButton    *tb,
                                     ScreenshotData     *sd);
 static void
@@ -61,7 +67,9 @@ static void
 cb_delay_spinner_changed           (GtkWidget          *spinner,
                                     ScreenshotData     *sd);
 static gchar
-*generate_filename_for_uri         (const gchar        *uri);
+*generate_filename_for_uri         (const gchar        *uri,
+                                    const gchar        *title,
+                                    gboolean            horodate);
 static void
 cb_combo_active_item_changed       (GtkWidget          *box,
                                     ScreenshotData     *sd);
@@ -176,6 +184,23 @@ static void cb_open_toggled (GtkToggleButton *tb, ScreenshotData *sd)
 
 
 
+static void cb_title_entry_changed (GtkEditable *editable,
+                                    ScreenshotData *sd)
+{
+  g_free (sd->title);
+  sd->title = gtk_editable_get_chars (editable, 0, -1);
+}
+
+
+
+static void cb_horodate_toggled (GtkToggleButton *togglebutton,
+                                 ScreenshotData *sd)
+{
+  sd->horodate = gtk_toggle_button_get_active (togglebutton);
+}
+
+
+
 static void cb_clipboard_toggled (GtkToggleButton *tb, ScreenshotData *sd)
 {
   if (gtk_toggle_button_get_active (tb))
@@ -201,6 +226,16 @@ static void cb_default_folder (GtkWidget *chooser, ScreenshotData  *sd)
 
 
 
+static void cb_hide_save_align (GtkToggleButton *togglebutton, GtkWidget *widget)
+{
+  if (gtk_toggle_button_get_active (togglebutton))
+    gtk_widget_show (widget);
+  else
+    gtk_widget_hide (widget);
+}
+
+
+
 /* Set the delay according to the spinner */
 static void cb_delay_spinner_changed (GtkWidget *spinner, ScreenshotData *sd)
 {
@@ -209,18 +244,27 @@ static void cb_delay_spinner_changed (GtkWidget *spinner, ScreenshotData *sd)
 
 
 
-/* Generates filename Screenshot-n.png (where n is the first integer
- * greater than 0) so that Screenshot-n.jpg does not exist in the folder
- * whose URI is *uri.
+/* If @horodate is true, generates a file name @title - date - hour - n.png,
+ * where n is the lowest integer such as this file does not exist in the @uri
+ * folder.
+ * Else, generates a file name @title-n.png, where n is the lowest integer 
+ * such as this file does not exist in the @uri folder.
+ * 
  * @uri: uri of the folder for which the filename should be generated.
+ * @title: the main title of the file name.
+ * @horodate: whether the date and the hour should be appended to the file name.
+ *
  * returns: the filename or NULL if *uri == NULL.
 */
-static gchar *generate_filename_for_uri (const gchar *uri)
+static gchar *generate_filename_for_uri (const gchar *uri,
+                                         const gchar *title,
+                                         gboolean horodate)
 {
   gboolean exists = TRUE;
   GFile *directory;
   GFile *file;
   gchar *base_name;
+  const gchar *date_hour = screenshooter_get_date_hour ();
   gint i;
 
   if (G_UNLIKELY (uri == NULL))
@@ -232,7 +276,10 @@ static gchar *generate_filename_for_uri (const gchar *uri)
 
   TRACE ("Get the folder corresponding to the URI");
   directory = g_file_new_for_uri (uri);
-  base_name = g_strdup (_("Screenshot.png"));
+  if (!horodate)
+    base_name = g_strconcat (title, ".png", NULL);
+  else
+    base_name = g_strconcat (title, " - ", date_hour, ".png", NULL);
 
   file = g_file_get_child (directory, base_name);
 
@@ -249,7 +296,14 @@ static gchar *generate_filename_for_uri (const gchar *uri)
 
   for (i = 1; exists; ++i)
     {
-      base_name = g_strdup_printf (_("Screenshot-%d.png"), i);
+      const gchar *extension =
+        g_strdup_printf ("-%d.png", i);
+
+      if (!horodate)
+         base_name = g_strconcat (title, extension, NULL);
+       else
+         base_name = g_strconcat (title, " - ", date_hour, extension, NULL);
+
       file = g_file_get_child (directory, base_name);
 
       if (!g_file_query_exists (file, NULL))
@@ -864,18 +918,16 @@ GtkWidget *screenshooter_region_dialog_new (ScreenshotData *sd, gboolean plugin)
 
 
 
-/* Build the preferences dialog.
- at sd: a ScreenshotData to set the options.
-*/
 GtkWidget *screenshooter_actions_dialog_new (ScreenshotData *sd)
 {
   GtkWidget *dlg, *main_alignment;
   GtkWidget *vbox;
 
-  GtkWidget *layout_table;
+  GtkWidget *layout_table, *right_table;
 
-  GtkWidget *left_box, *actions_label, *actions_alignment, *actions_box;
-  GtkWidget *save_box, *save_radio_button, *dir_chooser;
+  GtkWidget *left_box;
+  GtkWidget *actions_label, *actions_alignment, *actions_box;
+  GtkWidget *save_box, *save_radio_button, *dir_chooser, *save_alignment;
   GtkWidget *clipboard_radio_button, *open_with_radio_button;
   GtkWidget *zimagez_radio_button;
 
@@ -883,7 +935,9 @@ GtkWidget *screenshooter_actions_dialog_new (ScreenshotData *sd)
   GtkWidget *combobox, *open_box;
   GtkCellRenderer *renderer, *renderer_pixbuf;
 
-  GtkWidget *preview, *preview_frame, *preview_alignment, *preview_label;
+  GtkWidget *capture_info_box;
+  GtkWidget *title_box, *title_label, *title_entry, *horodate_checkbox;
+  GtkWidget *preview, *preview_box, *preview_label;
   GdkPixbuf *thumbnail;
 
   dlg = xfce_titled_dialog_new_with_buttons (_("Screenshot"),
@@ -916,7 +970,7 @@ GtkWidget *screenshooter_actions_dialog_new (ScreenshotData *sd)
   gtk_container_add (GTK_CONTAINER (main_alignment), vbox);
   gtk_widget_show (vbox);
 
-  /* Create the table to align the differents parts of the top of the UI */
+  /* Create the table to align the two columns of the UI */
   layout_table = gtk_table_new (1, 2, FALSE);
   gtk_table_set_col_spacings (GTK_TABLE (layout_table), 30);
   gtk_box_pack_start (GTK_BOX (vbox), layout_table, TRUE, TRUE, 0);
@@ -951,7 +1005,7 @@ GtkWidget *screenshooter_actions_dialog_new (ScreenshotData *sd)
   /* Create the save horizontal box */
   save_box = gtk_hbox_new (FALSE, 6);
   gtk_container_set_border_width (GTK_CONTAINER (save_box), 0);
-  gtk_box_pack_start (GTK_BOX (actions_box), save_box, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (actions_box), save_box, FALSE, FALSE, 0);
   gtk_widget_show (save_box);
 
   /* Save option radio button */
@@ -961,7 +1015,7 @@ GtkWidget *screenshooter_actions_dialog_new (ScreenshotData *sd)
   g_signal_connect (G_OBJECT (save_radio_button), "toggled",
                     G_CALLBACK (cb_save_toggled), sd);
   gtk_widget_set_tooltip_text (save_radio_button, _("Save the screenshot to a PNG file"));
-  gtk_box_pack_start (GTK_BOX (save_box), save_radio_button, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (save_box), save_radio_button, FALSE, FALSE, 0);
   gtk_widget_show (save_radio_button);
 
   /* Directory chooser */
@@ -979,6 +1033,24 @@ GtkWidget *screenshooter_actions_dialog_new (ScreenshotData *sd)
   gtk_box_pack_start (GTK_BOX (save_box), dir_chooser, TRUE, TRUE, 0);
   gtk_widget_show (dir_chooser);
 
+  /* Save alignment */
+  save_alignment = gtk_alignment_new (0, 0, 1, 1);
+  gtk_alignment_set_padding (GTK_ALIGNMENT (save_alignment), 0, 6, 16, 0);
+  gtk_box_pack_start (GTK_BOX (actions_box), save_alignment, TRUE, TRUE, 0);
+  gtk_widget_show (save_alignment);
+  g_signal_connect (G_OBJECT (save_radio_button), "toggled",
+                    G_CALLBACK (cb_hide_save_align), save_alignment);
+
+  /* Create the horodate checkbox */
+  horodate_checkbox =
+    gtk_check_button_new_with_label (_("Horodate the capture"));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (horodate_checkbox),
+                                sd->horodate);
+  g_signal_connect (horodate_checkbox, "toggled",
+                    (GCallback) cb_horodate_toggled, sd);
+  gtk_container_add (GTK_CONTAINER (save_alignment), horodate_checkbox);
+  gtk_widget_show (horodate_checkbox);
+
   /* Copy to clipboard radio button */
   clipboard_radio_button =
     gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (save_radio_button),
@@ -990,13 +1062,13 @@ GtkWidget *screenshooter_actions_dialog_new (ScreenshotData *sd)
                                 (sd->action == CLIPBOARD));
   g_signal_connect (G_OBJECT (clipboard_radio_button), "toggled",
                     G_CALLBACK (cb_clipboard_toggled), sd);
-  gtk_box_pack_start (GTK_BOX (actions_box), clipboard_radio_button, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (actions_box), clipboard_radio_button, FALSE, FALSE, 0);
   gtk_widget_show (clipboard_radio_button);
 
   /* Horizontal box for the open with stuff */
   open_box = gtk_hbox_new (FALSE, 6);
   gtk_container_set_border_width (GTK_CONTAINER (open_box), 0);
-  gtk_box_pack_start (GTK_BOX (actions_box), open_box, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (actions_box), open_box, FALSE, FALSE, 0);
   gtk_widget_show (open_box);
 
   /* Open with radio button */
@@ -1009,7 +1081,7 @@ GtkWidget *screenshooter_actions_dialog_new (ScreenshotData *sd)
                     G_CALLBACK (cb_open_toggled), sd);
   gtk_widget_set_tooltip_text (open_with_radio_button,
                                _("Open the screenshot with the chosen application"));
-  gtk_box_pack_start (GTK_BOX (open_box), open_with_radio_button, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (open_box), open_with_radio_button, FALSE, FALSE, 0);
   gtk_widget_show (open_with_radio_button);
 
   /* Open with combobox */
@@ -1046,44 +1118,88 @@ GtkWidget *screenshooter_actions_dialog_new (ScreenshotData *sd)
                                  "image hosting service"));
   g_signal_connect (G_OBJECT (zimagez_radio_button), "toggled",
                     G_CALLBACK (cb_zimagez_toggled), sd);
-  gtk_box_pack_start (GTK_BOX (actions_box), zimagez_radio_button, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (actions_box), zimagez_radio_button, FALSE, FALSE, 0);
   gtk_widget_show (zimagez_radio_button);
 
-  /* Preview of the screenshot */
-  preview_frame = gtk_frame_new ("");
+  /* Right table for the right of the UI */
+  right_table = gtk_table_new (2, 1, FALSE);
+  gtk_table_set_row_spacings (GTK_TABLE (right_table), 12);
+  gtk_table_attach_defaults (GTK_TABLE (layout_table), right_table, 1, 2, 0, 1);
+  gtk_widget_show (right_table);
+
+  /* Preview box */
+  preview_box = gtk_vbox_new (FALSE, 6);
+  gtk_container_set_border_width (GTK_CONTAINER (preview_box), 0);
+  gtk_table_attach_defaults (GTK_TABLE (right_table), preview_box, 0, 1, 0, 1);
+  gtk_widget_show (preview_box);
+
+  /* Preview label*/
   preview_label = gtk_label_new ("");
   gtk_label_set_markup (GTK_LABEL (preview_label),
-                        _("<span weight=\"bold\" stretch=\"semiexpanded\"> Preview "
-                          "</span>"));
-  gtk_frame_set_label_widget (GTK_FRAME (preview_frame), preview_label);
-  gtk_table_attach_defaults (GTK_TABLE (layout_table), preview_frame, 1, 2, 0, 1);
+                        _("<span weight=\"bold\" stretch=\"semiexpanded\">"
+                          "Preview</span>"));
+  gtk_misc_set_alignment (GTK_MISC (preview_label), 0, 0.5);
+  gtk_box_pack_start (GTK_BOX (preview_box), preview_label, FALSE, FALSE, 0);
   gtk_widget_show (preview_label);
-  gtk_widget_show (preview_frame);
-
-  preview_alignment = gtk_alignment_new (0, 0, 1, 1);
-  gtk_alignment_set_padding (GTK_ALIGNMENT (preview_alignment), 8, 8, 8, 8);
-  gtk_container_add (GTK_CONTAINER (preview_frame), preview_alignment);
-  gtk_widget_show (preview_alignment);
 
+  /* The preview image */
   thumbnail = screenshot_get_thumbnail (sd->screenshot);
   preview = gtk_image_new_from_pixbuf (thumbnail);
-  gtk_container_add (GTK_CONTAINER (preview_alignment), preview);
+  gtk_box_pack_start (GTK_BOX (preview_box), preview, FALSE, FALSE, 0);
   g_object_unref (thumbnail);
   gtk_widget_show (preview);
 
+  /* Create the capture_info box */
+  capture_info_box = gtk_vbox_new (FALSE, 6);
+  gtk_container_set_border_width (GTK_CONTAINER (capture_info_box), 0);
+  gtk_table_attach_defaults (GTK_TABLE (right_table), capture_info_box, 0, 1, 1, 2);
+  gtk_widget_show (capture_info_box);
+
+  /* Create the title horizontal box */
+  title_box = gtk_hbox_new (FALSE, 6);
+  gtk_container_set_border_width (GTK_CONTAINER (title_box), 0);
+  gtk_box_pack_start (GTK_BOX (capture_info_box), title_box, TRUE, TRUE, 0);
+  gtk_widget_show (title_box);
+
+  /* Create the title label */
+  title_label = gtk_label_new ("Title:");
+  gtk_misc_set_alignment (GTK_MISC (title_label), 0, 0.5);
+  gtk_box_pack_start (GTK_BOX (title_box), title_label, FALSE, FALSE, 0);
+  gtk_widget_show (title_label);
+
+  /* Create the title entry */
+  title_entry = gtk_entry_new ();
+  gtk_entry_set_text (GTK_ENTRY (title_entry), sd->title);
+  g_signal_connect (title_entry, "changed",
+                    (GCallback) cb_title_entry_changed, sd);
+  gtk_box_pack_start (GTK_BOX (title_box), title_entry, TRUE, TRUE, 0);
+  gtk_widget_show (title_entry);
+
+
+
   return dlg;
 }
 
 
 
-/* Saves the screenshot in the given directory.
- * @screenshot: a GdkPixbuf containing our screenshot
- * @directory: the default save location.
+/* Saves the @screenshot in the given @directory using
+ * @title and @horodate to generate the file name.
+ *
+ * @screenshot: a GdkPixbuf containing the screenshot.
+ * @directory: the save location.
+ * @title: the title of the screenshot.
+ * @horodate: whether the date and the hour should be added to
+ * the file name.
+ *
+ * Returns: a string containing the path to the saved file.
  */
 gchar
-*screenshooter_save_screenshot (GdkPixbuf *screenshot, const gchar *directory)
+*screenshooter_save_screenshot (GdkPixbuf *screenshot,
+                                const gchar *directory,
+                                const gchar *title,
+                                gboolean horodate)
 {
-  gchar *filename = generate_filename_for_uri (directory);
+  gchar *filename = generate_filename_for_uri (directory, title, horodate);
   gchar *savename = NULL;
   gchar *save_uri = g_build_filename (directory, filename, NULL);
 
diff --git a/lib/screenshooter-dialogs.h b/lib/screenshooter-dialogs.h
index 64a3257..ebbba01 100644
--- a/lib/screenshooter-dialogs.h
+++ b/lib/screenshooter-dialogs.h
@@ -40,7 +40,11 @@ GtkWidget *screenshooter_actions_dialog_new (ScreenshotData *sd);
 GtkWidget *screenshooter_region_dialog_new  (ScreenshotData *sd,
                                              gboolean        plugin);
 gchar     *screenshooter_save_screenshot    (GdkPixbuf      *screenshot,
-                                             const gchar    *directory);
+                                             const gchar    *directory,
+                                             const gchar    *title,
+                                             gboolean        horodate);
+
+
 
 
 #endif
diff --git a/lib/screenshooter-global.h b/lib/screenshooter-global.h
index db96ee5..21bea82 100644
--- a/lib/screenshooter-global.h
+++ b/lib/screenshooter-global.h
@@ -47,7 +47,9 @@ typedef struct
   gint delay;
   gint action;
   gboolean plugin;
+  gboolean horodate;
   gchar *screenshot_dir;
+  gchar *title;
   gchar *app;
   gchar *last_user;
   GdkPixbuf *screenshot;
diff --git a/lib/screenshooter-utils.c b/lib/screenshooter-utils.c
index b88be25..4532cee 100644
--- a/lib/screenshooter-utils.c
+++ b/lib/screenshooter-utils.c
@@ -61,7 +61,9 @@ screenshooter_read_rc_file (const gchar *file, ScreenshotData *sd)
   gint region = FULLSCREEN;
   gint action = SAVE;
   gint show_mouse = 1;
+  gboolean horodate = FALSE;
   gchar *screenshot_dir = g_strdup (home_uri);
+  gchar *title = g_strdup ("Screenshot");
   gchar *app = g_strdup ("none");
   gchar *last_user = g_strdup ("");
 
@@ -79,6 +81,7 @@ screenshooter_read_rc_file (const gchar *file, ScreenshotData *sd)
           region = xfce_rc_read_int_entry (rc, "region", FULLSCREEN);
           action = xfce_rc_read_int_entry (rc, "action", SAVE);
           show_mouse = xfce_rc_read_int_entry (rc, "show_mouse", 1);
+          horodate = xfce_rc_read_bool_entry (rc, "horodate", FALSE);
 
           g_free (app);
           app = g_strdup (xfce_rc_read_entry (rc, "app", "none"));
@@ -89,6 +92,9 @@ screenshooter_read_rc_file (const gchar *file, ScreenshotData *sd)
           g_free (screenshot_dir);
           screenshot_dir =
             g_strdup (xfce_rc_read_entry (rc, "screenshot_dir", home_uri));
+
+          g_free (title);
+          title = g_strdup (xfce_rc_read_entry (rc, "title", "Screenshot"));
         }
 
       TRACE ("Close the rc file");
@@ -103,7 +109,9 @@ screenshooter_read_rc_file (const gchar *file, ScreenshotData *sd)
   sd->region = region;
   sd->action = action;
   sd->show_mouse = show_mouse;
+  sd->horodate = horodate;
   sd->screenshot_dir = screenshot_dir;
+  sd->title = title;
   sd->app = app;
   sd->last_user = last_user;
 }
@@ -133,7 +141,9 @@ screenshooter_write_rc_file (const gchar *file, ScreenshotData *sd)
   xfce_rc_write_int_entry (rc, "region", sd->region);
   xfce_rc_write_int_entry (rc, "action", sd->action);
   xfce_rc_write_int_entry (rc, "show_mouse", sd->show_mouse);
+  xfce_rc_write_bool_entry (rc, "horodate", sd->horodate);
   xfce_rc_write_entry (rc, "screenshot_dir", sd->screenshot_dir);
+  xfce_rc_write_entry (rc, "title", sd->title);
   xfce_rc_write_entry (rc, "app", sd->app);
   xfce_rc_write_entry (rc, "last_user", sd->last_user);
 
@@ -158,7 +168,8 @@ screenshooter_open_screenshot (const gchar *screenshot_path, const gchar *applic
 
   TRACE ("Path was != NULL");
 
-  g_return_if_fail (!g_str_equal (application, "none"));
+  if (!g_str_equal (application, "none"))
+    return;
 
   TRACE ("Application was not none");
 
@@ -255,3 +266,38 @@ void screenshooter_error (const gchar *format, ...)
   g_free (message);
 }
 
+gchar *screenshooter_get_date_hour (void)
+{
+  time_t now = time (0);
+  struct tm *tm;
+  gchar *tmp, *result, *converted;
+  gchar **split;
+  gsize length;
+  gchar buffer[512];
+
+  tm = localtime (&now);
+
+  converted = g_locale_from_utf8 ("%x-%X", -1, NULL, NULL, NULL);
+  if (G_UNLIKELY (converted == NULL))
+    converted = g_strdup ("");
+
+  length = strftime (buffer, sizeof (buffer), converted, tm);
+
+  if (G_UNLIKELY (length == 0))
+    {
+      TRACE ("Buffer is NULL");
+      buffer[0] = '\0';
+    }
+
+  tmp = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
+  split = g_strsplit (tmp, "/", 0);
+  result = g_strjoinv (NULL, split);
+
+  g_strfreev (split);
+  g_free (converted);
+  g_free (tmp);
+
+  return result;
+}
+
+
diff --git a/lib/screenshooter-utils.h b/lib/screenshooter-utils.h
index 31bceb0..2fd368f 100644
--- a/lib/screenshooter-utils.h
+++ b/lib/screenshooter-utils.h
@@ -28,6 +28,7 @@
 
 #include <gtk/gtk.h>
 #include <glib/gstdio.h>
+#include <time.h>
 
 #include <libxfce4util/libxfce4util.h>
 #include <libxfcegui4/libxfcegui4.h>
@@ -46,5 +47,7 @@ gboolean screenshooter_is_remote_uri (const gchar    *uri);
 gchar *rot13                         (gchar          *string);
 void screenshooter_error             (const gchar    *format,
                                       ...);
+gchar *screenshooter_get_date_hour   (void);
+
 
 #endif
diff --git a/panel-plugin/screenshooter-plugin.c b/panel-plugin/screenshooter-plugin.c
index 0f0756f..96f21aa 100644
--- a/panel-plugin/screenshooter-plugin.c
+++ b/panel-plugin/screenshooter-plugin.c
@@ -141,7 +141,9 @@ cb_free_data (XfcePanelPlugin *plugin, PluginData *pd)
 
   pd->style_id = 0;
   g_free (pd->sd->screenshot_dir);
+  g_free (pd->sd->title);
   g_free (pd->sd->app);
+  g_free (pd->sd->last_user);
   g_free (pd->sd);
   g_free (pd);
 }
diff --git a/src/main.c b/src/main.c
index 8a086f7..717c365 100644
--- a/src/main.c
+++ b/src/main.c
@@ -348,6 +348,7 @@ int main (int argc, char **argv)
     }
 
   g_free (sd->screenshot_dir);
+  g_free (sd->title);
   g_free (sd->app);
   g_free (sd->last_user);
   g_free (sd);



More information about the Xfce4-commits mailing list