[gtk/gtk-3-24: 1/2] gtkplacessidebar: Show busy spinner in sidebar row during mount ops



commit 0e7228b26740244037f0aa8bf7fa8dc89f9554de
Author: segfault <segfault riseup net>
Date:   Sun Jul 22 13:47:46 2018 +0200

    gtkplacessidebar: Show busy spinner in sidebar row during mount ops

 gtk/gtkplacessidebar.c     | 38 ++++++++++++++++++++++++++++----------
 gtk/gtksidebarrow.c        | 12 ++++++++++++
 gtk/gtksidebarrowprivate.h |  2 ++
 gtk/ui/gtksidebarrow.ui    |  9 +++++++++
 4 files changed, 51 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index 810c085d0f..17fee6d5f5 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -2398,7 +2398,8 @@ volume_mount_cb (GObject      *source_object,
                  GAsyncResult *result,
                  gpointer      user_data)
 {
-  GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
+  GtkSidebarRow *row = GTK_SIDEBAR_ROW (user_data);
+  GtkPlacesSidebar *sidebar;
   GVolume *volume;
   GError *error;
   gchar *primary;
@@ -2406,6 +2407,7 @@ volume_mount_cb (GObject      *source_object,
   GMount *mount;
 
   volume = G_VOLUME (source_object);
+  g_object_get (row, "sidebar", &sidebar, NULL);
 
   error = NULL;
   if (!g_volume_mount_finish (volume, result, &error))
@@ -2423,6 +2425,7 @@ volume_mount_cb (GObject      *source_object,
     }
 
   sidebar->mounting = FALSE;
+  gtk_sidebar_row_set_busy (row, FALSE);
 
   mount = g_volume_get_mount (volume);
   if (mount != NULL)
@@ -2436,32 +2439,42 @@ volume_mount_cb (GObject      *source_object,
       g_object_unref (G_OBJECT (mount));
     }
 
+  g_object_unref (row);
   g_object_unref (sidebar);
 }
 
 static void
-mount_volume (GtkPlacesSidebar *sidebar,
-              GVolume          *volume)
+mount_volume (GtkSidebarRow *row,
+              GVolume       *volume)
 {
+  GtkPlacesSidebar *sidebar;
   GMountOperation *mount_op;
 
+  g_object_get (row, "sidebar", &sidebar, NULL);
+
   mount_op = get_mount_operation (sidebar);
   g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION);
 
+  g_object_ref (row);
   g_object_ref (sidebar);
-  g_volume_mount (volume, 0, mount_op, NULL, volume_mount_cb, sidebar);
+  g_volume_mount (volume, 0, mount_op, NULL, volume_mount_cb, row);
 }
 
 static void
-open_drive (GtkPlacesSidebar   *sidebar,
+open_drive (GtkSidebarRow      *row,
             GDrive             *drive,
             GtkPlacesOpenFlags  open_flags)
 {
+  GtkPlacesSidebar *sidebar;
+
+  g_object_get (row, "sidebar", &sidebar, NULL);
+
   if (drive != NULL &&
       (g_drive_can_start (drive) || g_drive_can_start_degraded (drive)))
     {
       GMountOperation *mount_op;
 
+      gtk_sidebar_row_set_busy (row, TRUE);
       mount_op = get_mount_operation (sidebar);
       g_drive_start (drive, G_DRIVE_START_NONE, mount_op, NULL, drive_start_from_bookmark_cb, NULL);
       g_object_unref (mount_op);
@@ -2469,15 +2482,20 @@ open_drive (GtkPlacesSidebar   *sidebar,
 }
 
 static void
-open_volume (GtkPlacesSidebar   *sidebar,
+open_volume (GtkSidebarRow      *row,
              GVolume            *volume,
              GtkPlacesOpenFlags  open_flags)
 {
+  GtkPlacesSidebar *sidebar;
+
+  g_object_get (row, "sidebar", &sidebar, NULL);
+
   if (volume != NULL && !sidebar->mounting)
     {
       sidebar->mounting = TRUE;
       sidebar->go_to_after_mount_open_flags = open_flags;
-      mount_volume (sidebar, volume);
+      gtk_sidebar_row_set_busy (row, TRUE);
+      mount_volume (row, volume);
     }
 }
 
@@ -2534,11 +2552,11 @@ open_row (GtkSidebarRow      *row,
     }
   else if (volume != NULL)
     {
-      open_volume (sidebar, volume, open_flags);
+      open_volume (row, volume, open_flags);
     }
   else if (drive != NULL)
     {
-      open_drive (sidebar, drive, open_flags);
+      open_drive (row, drive, open_flags);
     }
 
   g_object_unref (sidebar);
@@ -2875,7 +2893,7 @@ mount_shortcut_cb (GSimpleAction *action,
                 NULL);
 
   if (volume != NULL)
-    mount_volume (sidebar, volume);
+    mount_volume (sidebar->context_row, volume);
 
   g_object_unref (volume);
 }
diff --git a/gtk/gtksidebarrow.c b/gtk/gtksidebarrow.c
index effbb1fb3b..4e88a7fed9 100644
--- a/gtk/gtksidebarrow.c
+++ b/gtk/gtksidebarrow.c
@@ -28,6 +28,7 @@
 #include "gtkstylecontext.h"
 #include "gtkrevealer.h"
 #include "gtkselection.h"
+#include "gtkspinner.h"
 
 #ifdef HAVE_CLOUDPROVIDERS
 #include <cloudproviders/cloudprovidersaccount.h>
@@ -57,6 +58,7 @@ struct _GtkSidebarRow
   GtkPlacesSidebar *sidebar;
   GtkWidget *event_box;
   GtkWidget *revealer;
+  GtkWidget *busy_spinner;
 };
 
 G_DEFINE_TYPE (GtkSidebarRow, gtk_sidebar_row, GTK_TYPE_LIST_BOX_ROW)
@@ -621,6 +623,7 @@ gtk_sidebar_row_class_init (GtkSidebarRowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GtkSidebarRow, eject_button);
   gtk_widget_class_bind_template_child (widget_class, GtkSidebarRow, event_box);
   gtk_widget_class_bind_template_child (widget_class, GtkSidebarRow, revealer);
+  gtk_widget_class_bind_template_child (widget_class, GtkSidebarRow, busy_spinner);
 
   gtk_widget_class_bind_template_callback (widget_class, on_child_revealed);
   gtk_widget_class_set_css_name (widget_class, "row");
@@ -658,3 +661,12 @@ gtk_sidebar_row_get_event_box (GtkSidebarRow *self)
 {
   return self->event_box;
 }
+
+void
+gtk_sidebar_row_set_busy (GtkSidebarRow *row,
+                          gboolean       is_busy)
+{
+  g_return_if_fail (GTK_IS_SIDEBAR_ROW (row));
+
+  gtk_widget_set_visible (row->busy_spinner, is_busy);
+}
diff --git a/gtk/gtksidebarrowprivate.h b/gtk/gtksidebarrowprivate.h
index 5b53a4b145..35797e7cb7 100644
--- a/gtk/gtksidebarrowprivate.h
+++ b/gtk/gtksidebarrowprivate.h
@@ -54,6 +54,8 @@ void           gtk_sidebar_row_set_start_icon   (GtkSidebarRow *self,
                                                  GIcon         *icon);
 void           gtk_sidebar_row_set_end_icon     (GtkSidebarRow *self,
                                                  GIcon         *icon);
+void           gtk_sidebar_row_set_busy         (GtkSidebarRow *row,
+                                                 gboolean       is_busy);
 
 G_END_DECLS
 
diff --git a/gtk/ui/gtksidebarrow.ui b/gtk/ui/gtksidebarrow.ui
index 3cb6947857..1fca7e8311 100644
--- a/gtk/ui/gtksidebarrow.ui
+++ b/gtk/ui/gtksidebarrow.ui
@@ -71,6 +71,15 @@
                     </style>
                   </object>
                 </child>
+                <child>
+                  <object class="GtkSpinner" id="busy_spinner">
+                    <property name="active">1</property>
+                    <property name="halign">center</property>
+                    <property name="valign">center</property>
+                    <property name="margin-start">4px</property>
+                    <property name="no-show-all">1</property>
+                  </object>
+                </child>
               </object>
             </child>
           </object>


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