[Xfce4-commits] <thunar:jannis/new-shortcuts-pane> Add a spinner that is shown during mount/eject.

Jannis Pohlmann noreply at xfce.org
Fri Jul 15 21:10:19 CEST 2011


Updating branch refs/heads/jannis/new-shortcuts-pane
         to 5dea55ba646b654e1ab1f7058e957d990362a993 (commit)
       from 62ebb470761ab41c92d16e74275eecdd3f8dc9cb (commit)

commit 5dea55ba646b654e1ab1f7058e957d990362a993
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Tue Jun 7 04:13:04 2011 +0200

    Add a spinner that is shown during mount/eject.
    
    Clicking the button with the spinner does not abort the mount or eject
    process yet but in the future that is going to work.

 thunar/thunar-shortcut-row.c |   73 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/thunar/thunar-shortcut-row.c b/thunar/thunar-shortcut-row.c
index 67636fe..3acab7b 100644
--- a/thunar/thunar-shortcut-row.c
+++ b/thunar/thunar-shortcut-row.c
@@ -118,6 +118,8 @@ static void     thunar_shortcut_row_file_changed         (ThunarShortcutRow *row
 static void     thunar_shortcut_row_eject_icon_changed   (ThunarShortcutRow *row);
 static void     thunar_shortcut_row_volume_changed       (ThunarShortcutRow *row);
 static void     thunar_shortcut_row_icon_size_changed    (ThunarShortcutRow *row);
+static void     thunar_shortcut_row_set_spinning         (ThunarShortcutRow *row,
+                                                          gboolean           spinning);
 
 
 
@@ -144,6 +146,7 @@ struct _ThunarShortcutRow
   GtkWidget         *icon_image;
   GtkWidget         *action_button;
   GtkWidget         *action_image;
+  GtkWidget         *spinner;
                     
   ThunarIconSize     icon_size;
 
@@ -296,11 +299,23 @@ thunar_shortcut_row_init (ThunarShortcutRow *row)
   gtk_button_set_image (GTK_BUTTON (row->action_button), row->action_image);
   gtk_widget_show (row->action_image);
 
+  /* take a reference because we need to be able to remove it from the
+   * button temporarily */
+  g_object_ref (row->action_image);
+
   /* default to "media-eject", we only set this for the button size
   * to be computed so that all rows have equal heights */
   gtk_image_set_from_icon_name (GTK_IMAGE (row->action_image), "media-eject",
                                 GTK_ICON_SIZE_MENU);
 
+  /* create the spinner icon */
+  row->spinner = gtk_spinner_new ();
+  gtk_spinner_stop (GTK_SPINNER (row->spinner));
+  
+  /* take a reference because we need to be able to remove it from the
+   * button temporarily */
+  g_object_ref (row->spinner);
+
   /* update the icon size whenever necessary */
   row->preferences = thunar_preferences_get ();
   exo_binding_new (G_OBJECT (row->preferences), "shortcuts-icon-size",
@@ -331,6 +346,10 @@ thunar_shortcut_row_finalize (GObject *object)
 
   g_free (row->label);
 
+  /* release the spinner and action image */
+  g_object_unref (row->spinner);
+  g_object_unref (row->action_image);
+
   if (row->icon != NULL)
     g_object_unref (row->icon);
 
@@ -721,6 +740,9 @@ thunar_shortcut_row_button_clicked (ThunarShortcutRow *row,
             {
               g_debug ("  trying to unmount the mount");
 
+              /* start spinning */
+              thunar_shortcut_row_set_spinning (row, TRUE);
+
               /* try unmounting the mount */
               g_mount_unmount_with_operation (mount,
                                               G_MOUNT_UNMOUNT_NONE,
@@ -733,6 +755,9 @@ thunar_shortcut_row_button_clicked (ThunarShortcutRow *row,
             {
               g_debug ("  trying to eject the mount");
 
+              /* start spinning */
+              thunar_shortcut_row_set_spinning (row, TRUE);
+
               /* try ejecting the mount */
               g_mount_eject_with_operation (mount,
                                             G_MOUNT_UNMOUNT_NONE,
@@ -782,6 +807,9 @@ thunar_shortcut_row_mount_unmount_finish (GObject      *object,
   _thunar_return_if_fail (G_IS_MOUNT (mount));
   _thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
 
+  /* stop spinning */
+  thunar_shortcut_row_set_spinning (row, FALSE);
+
   if (!g_mount_unmount_with_operation_finish (mount, result, &error))
     {
       thunar_dialogs_show_error (GTK_WIDGET (row), error,
@@ -806,6 +834,9 @@ thunar_shortcut_row_mount_eject_finish (GObject      *object,
   _thunar_return_if_fail (G_IS_MOUNT (mount));
   _thunar_return_if_fail (G_IS_ASYNC_RESULT (result));
 
+  /* stop spinning */
+  thunar_shortcut_row_set_spinning (row, FALSE);
+
   if (!g_mount_eject_with_operation_finish (mount, result, &error))
     {
       thunar_dialogs_show_error (GTK_WIDGET (row), error,
@@ -830,6 +861,9 @@ thunar_shortcut_row_poke_volume_finish (ThunarBrowser *browser,
   _thunar_return_if_fail (G_IS_VOLUME (volume));
   _thunar_return_if_fail (file == NULL || THUNAR_IS_FILE (file));
   
+  /* deactivate the spinner */
+  thunar_shortcut_row_set_spinning (row, FALSE);
+
   if (error == NULL)
     {
       g_signal_emit (row, row_signals[SIGNAL_ACTIVATED], 0, file);
@@ -857,6 +891,9 @@ thunar_shortcut_row_poke_file_finish (ThunarBrowser *browser,
   _thunar_return_if_fail (THUNAR_IS_FILE (file));
   _thunar_return_if_fail (target_file == NULL || THUNAR_IS_FILE (target_file));
   
+  /* deactivate the spinner */
+  thunar_shortcut_row_set_spinning (row, FALSE);
+
   if (error == NULL)
     {
       g_signal_emit (row, row_signals[SIGNAL_ACTIVATED], 0, target_file);
@@ -881,6 +918,9 @@ thunar_shortcut_row_resolve_and_activate (ThunarShortcutRow *row)
 
   if (row->volume != NULL)
     {
+      /* activate the spinner */
+      thunar_shortcut_row_set_spinning (row, TRUE);
+
       thunar_browser_poke_volume (THUNAR_BROWSER (row), row->volume, row,
                                   thunar_shortcut_row_poke_volume_finish,
                                   NULL);
@@ -890,6 +930,9 @@ thunar_shortcut_row_resolve_and_activate (ThunarShortcutRow *row)
       file = thunar_file_get (row->file, NULL);
       if (file != NULL)
         {
+          /* activate the spinner */
+          thunar_shortcut_row_set_spinning (row, TRUE);
+
           thunar_browser_poke_file (THUNAR_BROWSER (row), file, row,
                                     thunar_shortcut_row_poke_file_finish,
                                     NULL);
@@ -1033,6 +1076,36 @@ thunar_shortcut_row_icon_size_changed (ThunarShortcutRow *row)
 
   gtk_image_set_pixel_size (GTK_IMAGE (row->icon_image), row->icon_size);
   gtk_image_set_pixel_size (GTK_IMAGE (row->action_image), row->icon_size);
+
+  gtk_widget_set_size_request (row->spinner, row->icon_size, row->icon_size);
+}
+
+
+
+static void
+thunar_shortcut_row_set_spinning (ThunarShortcutRow *row,
+                                  gboolean           spinning)
+{
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (row));
+
+  if (spinning)
+    {
+      gtk_button_set_image (GTK_BUTTON (row->action_button), row->spinner);
+      gtk_spinner_start (GTK_SPINNER (row->spinner));
+      gtk_widget_show (row->spinner);
+      gtk_widget_show (row->action_button);
+    }
+  else
+    {
+      gtk_button_set_image (GTK_BUTTON (row->action_button), row->action_image);
+      gtk_spinner_stop (GTK_SPINNER (row->spinner));
+      gtk_widget_hide (row->spinner);
+      gtk_widget_hide (row->action_button);
+
+      /* assume the volume has changed which will make the action button
+       * visible again if the volume or file is mounted and can be ejected */
+      thunar_shortcut_row_volume_changed (row);
+    }
 }
 
 



More information about the Xfce4-commits mailing list