Updating branch refs/heads/jannis/new-shortcuts-pane
         to 1a525b93f6564443c3170eac256601f7f1e984b3 (commit)
       from 0b1a3bac5d4573cd9dd2701b18615ac478e2779f (commit)

commit 1a525b93f6564443c3170eac256601f7f1e984b3
Author: Jannis Pohlmann <jan...@xfce.org>
Date:   Mon Jun 13 00:07:03 2011 +0200

    Further work on mount/unmonut/disconnect context menu actions.

 thunar/thunar-shortcut-row.c   |  323 +++++++++++++++++++++++-----------------
 thunar/thunar-shortcut-row.h   |    4 +-
 thunar/thunar-shortcuts-view.c |   49 ++++++-
 3 files changed, 233 insertions(+), 143 deletions(-)

diff --git a/thunar/thunar-shortcut-row.c b/thunar/thunar-shortcut-row.c
index 504d861..ae98671 100644
--- a/thunar/thunar-shortcut-row.c
+++ b/thunar/thunar-shortcut-row.c
@@ -873,10 +873,6 @@ static void
 thunar_shortcut_row_button_clicked (ThunarShortcutRow *row,
                                     GtkButton         *button)
 {
-  GMountOperation *mount_operation;
-  GtkWidget       *toplevel;
-  GMount          *mount;
-
   _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (row));
 
   /* check if we are currently mounting/ejecting something */
@@ -889,109 +885,8 @@ thunar_shortcut_row_button_clicked (ThunarShortcutRow 
*row,
       return;
     }
 
-  /* create a mount operation */
-  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (row));
-  mount_operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
-  gtk_mount_operation_set_screen (GTK_MOUNT_OPERATION (mount_operation),
-                                  gtk_widget_get_screen (GTK_WIDGET (row)));
-
-  if (row->shortcut_type == THUNAR_SHORTCUT_STANDALONE_MOUNT)
-    {
-      /* if this fails there is something out of sync with the model */
-      g_assert (row->mount != NULL);
-
-      if (g_mount_can_unmount (row->mount))
-        {
-          /* start spinning */
-          thunar_shortcut_row_set_spinning (row, TRUE, 
THUNAR_SHORTCUT_ROW_EJECTING);
-
-          /* try unmounting the mount */
-          g_mount_unmount_with_operation (row->mount,
-                                          G_MOUNT_UNMOUNT_NONE,
-                                          mount_operation,
-                                          row->cancellable,
-                                          
thunar_shortcut_row_mount_unmount_finish,
-                                          row);
-        }
-      else if (g_mount_can_eject (row->mount))
-        {
-          g_debug ("need to eject the mount");
-
-          /* start spinning */
-          thunar_shortcut_row_set_spinning (row, TRUE, 
THUNAR_SHORTCUT_ROW_EJECTING);
-
-          /* try ejecting the mount */
-          g_mount_eject_with_operation (row->mount,
-                                        G_MOUNT_UNMOUNT_NONE,
-                                        mount_operation,
-                                        row->cancellable,
-                                        thunar_shortcut_row_mount_eject_finish,
-                                        row);
-        }
-      else
-        {
-          /* something is out of sync... */
-        }
-    }
-  else if (row->shortcut_type == THUNAR_SHORTCUT_REGULAR_VOLUME
-           || row->shortcut_type == THUNAR_SHORTCUT_EJECTABLE_VOLUME)
-    {
-      /* if this fails there is something out of sync with the model */
-      g_assert (row->volume != NULL);
-
-      /* check if the volume is mounted */
-      mount = g_volume_get_mount (row->volume);
-      if (mount != NULL)
-        {
-          g_debug ("have mount");
-
-          /* check if we can unmount the mount */
-          if (g_mount_can_unmount (mount))
-            {
-              g_debug ("  trying to unmount the mount");
-
-              /* start spinning */
-              thunar_shortcut_row_set_spinning (row, TRUE, 
THUNAR_SHORTCUT_ROW_EJECTING);
-
-              /* try unmounting the mount */
-              g_mount_unmount_with_operation (mount,
-                                              G_MOUNT_UNMOUNT_NONE,
-                                              mount_operation,
-                                              row->cancellable,
-                                              
thunar_shortcut_row_mount_unmount_finish,
-                                              row);
-            }
-          else if (g_mount_can_eject (mount))
-            {
-              g_debug ("  trying to eject the mount");
-
-              /* start spinning */
-              thunar_shortcut_row_set_spinning (row, TRUE, 
THUNAR_SHORTCUT_ROW_EJECTING);
-
-              /* try ejecting the mount */
-              g_mount_eject_with_operation (mount,
-                                            G_MOUNT_UNMOUNT_NONE,
-                                            mount_operation,
-                                            row->cancellable,
-                                            
thunar_shortcut_row_mount_eject_finish,
-                                            row);
-            }
-
-          g_object_unref (mount);
-        }
-      else if (g_volume_can_eject (row->volume))
-        {
-          /* TODO try ejecting the volume */
-          g_debug ("trying to eject the volume");
-        }
-      else
-        {
-          /* something is out of sync... */
-        }
-    }
-
-  /* release the mount operation */
-  g_object_unref (mount_operation);
+  /* disconnect the shortcut */
+  thunar_shortcut_row_disconnect (row);
 }
 
 
@@ -1122,6 +1017,14 @@ thunar_shortcut_row_resolve_and_activate 
(ThunarShortcutRow *row,
 
   _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (row));
 
+  /* check if we are currently mounting/ejecting something */
+  if (row->state != THUNAR_SHORTCUT_ROW_NORMAL)
+    {
+      /* abort the current mount/eject process */
+      g_cancellable_cancel (row->cancellable);
+      g_cancellable_reset (row->cancellable);
+    }
+
   if (row->volume != NULL)
     {
       /* activate the spinner */
@@ -1666,21 +1569,110 @@ thunar_shortcut_row_set_icon_size (ThunarShortcutRow 
*row,
 
 
 void
-thunar_shortcut_row_disconnect_mount (ThunarShortcutRow *row)
+thunar_shortcut_row_mount (ThunarShortcutRow *row)
+{
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (row));
+
+  thunar_shortcut_row_resolve_and_activate (row, FALSE);
+}
+
+
+
+void
+thunar_shortcut_row_unmount (ThunarShortcutRow *row)
 {
   GMountOperation *mount_operation;
   GtkWidget       *toplevel;
+  GMount          *mount;
 
   _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (row));
-  _thunar_return_if_fail (row->shortcut_type == 
THUNAR_SHORTCUT_STANDALONE_MOUNT);
 
-  if (row->shortcut_type != THUNAR_SHORTCUT_STANDALONE_MOUNT)
-    return;
+  /* check if we are currently mounting/ejecting something */
+  if (row->state != THUNAR_SHORTCUT_ROW_NORMAL)
+    {
+      /* abort the current mount/eject process */
+      g_cancellable_cancel (row->cancellable);
+      g_cancellable_reset (row->cancellable);
+    }
 
-  if (row->mount == NULL)
+  /* create a mount operation */
+  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (row));
+  mount_operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
+  gtk_mount_operation_set_screen (GTK_MOUNT_OPERATION (mount_operation),
+                                  gtk_widget_get_screen (GTK_WIDGET (row)));
+
+  if (row->mount != NULL)
     {
-      /* something is out of sync */
-      return;
+      /* only handle mounts that can be unmounted here */
+      if (g_mount_can_unmount (row->mount))
+        {
+          /* start spinning */
+          thunar_shortcut_row_set_spinning (row, TRUE, 
THUNAR_SHORTCUT_ROW_EJECTING);
+
+          /* try unmounting the mount */
+          g_mount_unmount_with_operation (row->mount,
+                                          G_MOUNT_UNMOUNT_NONE,
+                                          mount_operation,
+                                          row->cancellable,
+                                          
thunar_shortcut_row_mount_unmount_finish,
+                                          row);
+        }
+    }
+  else if (row->volume != NULL)
+    {
+      mount = g_volume_get_mount (row->volume);
+      if (mount != NULL)
+        {
+          g_debug ("have mount");
+          /* only handle mounts that can be unmounted here */
+          if (g_mount_can_unmount(mount))
+            {
+              g_debug ("can unmount");
+              /* start spinning */
+              thunar_shortcut_row_set_spinning (row, TRUE, 
+                                                THUNAR_SHORTCUT_ROW_EJECTING);
+
+              /* try unmounting the mount */
+              g_mount_unmount_with_operation (mount,
+                                              G_MOUNT_UNMOUNT_NONE,
+                                              mount_operation,
+                                              row->cancellable,
+                                              
thunar_shortcut_row_mount_unmount_finish,
+                                              row);
+            }
+
+          /* release the mount */
+          g_object_unref (mount);
+        }
+      
+    }
+  else
+    {
+      /* this method was called despite no mount or volume being available
+       * for this shortcut... that should not happen */
+    }
+
+  /* release the mount operation */
+  g_object_unref (mount_operation);
+}
+
+
+
+void
+thunar_shortcut_row_disconnect (ThunarShortcutRow *row)
+{
+  GMountOperation *mount_operation;
+  GtkWidget       *toplevel;
+  GMount          *mount;
+
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (row));
+
+  /* check if we are currently mounting/ejecting something */
+  if (row->state != THUNAR_SHORTCUT_ROW_NORMAL)
+    {
+      /* abort the current mount/eject process */
+      g_cancellable_cancel (row->cancellable);
+      g_cancellable_reset (row->cancellable);
     }
 
   /* create a mount operation */
@@ -1689,36 +1681,91 @@ thunar_shortcut_row_disconnect_mount (ThunarShortcutRow 
*row)
   gtk_mount_operation_set_screen (GTK_MOUNT_OPERATION (mount_operation),
                                   gtk_widget_get_screen (GTK_WIDGET (row)));
 
-  /* distinguish between mountable and ejectable mounts */
-  if (g_mount_can_unmount (row->mount))
+  if (row->mount != NULL)
     {
-      /* start spinning */
-      thunar_shortcut_row_set_spinning (row, TRUE, 
THUNAR_SHORTCUT_ROW_EJECTING);
-
-      /* try unmounting the mount */
-      g_mount_unmount_with_operation (row->mount,
-                                      G_MOUNT_UNMOUNT_NONE,
-                                      mount_operation,
-                                      row->cancellable,
-                                      thunar_shortcut_row_mount_unmount_finish,
-                                      row);
+      /* distinguish between ejectable and unmountable mounts */
+      if (g_mount_can_eject (row->mount))
+        {
+          /* start spinning */
+          thunar_shortcut_row_set_spinning (row, TRUE, 
THUNAR_SHORTCUT_ROW_EJECTING);
+
+          /* try ejecting the mount */
+          g_mount_eject_with_operation (row->mount,
+                                        G_MOUNT_UNMOUNT_NONE,
+                                        mount_operation,
+                                        row->cancellable,
+                                        thunar_shortcut_row_mount_eject_finish,
+                                        row);
+        }
+      else if (g_mount_can_unmount (row->mount))
+        {
+          /* start spinning */
+          thunar_shortcut_row_set_spinning (row, TRUE, 
THUNAR_SHORTCUT_ROW_EJECTING);
+
+          /* try unmounting the mount */
+          g_mount_unmount_with_operation (row->mount,
+                                          G_MOUNT_UNMOUNT_NONE,
+                                          mount_operation,
+                                          row->cancellable,
+                                          
thunar_shortcut_row_mount_unmount_finish,
+                                          row);
+        }
+      else
+        {
+          /* something is out of sync... */
+        }
     }
-  else if (g_mount_can_eject (row->mount))
+  else if (row->volume != NULL)
     {
-      /* start spinning */
-      thunar_shortcut_row_set_spinning (row, TRUE, 
THUNAR_SHORTCUT_ROW_EJECTING);
-
-      /* try ejecting the mount */
-      g_mount_eject_with_operation (row->mount,
-                                    G_MOUNT_UNMOUNT_NONE,
-                                    mount_operation,
-                                    row->cancellable,
-                                    thunar_shortcut_row_mount_eject_finish,
-                                    row);
+      if (g_volume_can_eject (row->volume))
+        {
+          /* try to eject the volume */
+          g_debug ("trying to eject the volume");
+        }
+      else
+        {
+          mount = g_volume_get_mount (row->volume);
+          if (mount != NULL)
+            {
+              /* distinguish between ejectable and unmountable mounts */
+              if (g_mount_can_eject (mount))
+                {
+                  /* start spinning */
+                  thunar_shortcut_row_set_spinning (row, TRUE, 
+                                                    
THUNAR_SHORTCUT_ROW_EJECTING);
+
+                  /* try unmounting the mount */
+                  g_mount_unmount_with_operation (mount,
+                                                  G_MOUNT_UNMOUNT_NONE,
+                                                  mount_operation,
+                                                  row->cancellable,
+                                                  
thunar_shortcut_row_mount_unmount_finish,
+                                                  row);
+                }
+              else if (g_mount_can_unmount (mount))
+                {
+                  /* start spinning */
+                  thunar_shortcut_row_set_spinning (row, TRUE, 
+                                                    
THUNAR_SHORTCUT_ROW_EJECTING);
+
+                  /* try unmounting the mount */
+                  g_mount_unmount_with_operation (mount,
+                                                  G_MOUNT_UNMOUNT_NONE,
+                                                  mount_operation,
+                                                  row->cancellable,
+                                                  
thunar_shortcut_row_mount_unmount_finish,
+                                                  row);
+                }
+
+              /* release the mount */
+              g_object_unref (mount);
+            }
+        }
     }
   else
     {
-      /* something is out of sync... */
+      /* this method was called despite no mount or volume being available
+       * for this shortcut... that should not happen */
     }
 
   /* release the mount operation */
diff --git a/thunar/thunar-shortcut-row.h b/thunar/thunar-shortcut-row.h
index e114fec..effddfa 100644
--- a/thunar/thunar-shortcut-row.h
+++ b/thunar/thunar-shortcut-row.h
@@ -64,7 +64,9 @@ void               thunar_shortcut_row_set_icon_size        
(ThunarShortcutRow *
                                                              ThunarIconSize    
 icon_size);
 void               thunar_shortcut_row_resolve_and_activate (ThunarShortcutRow 
*row,
                                                              gboolean          
 open_in_new_window);
-void               thunar_shortcut_row_disconnect_mount     (ThunarShortcutRow 
*row);
+void               thunar_shortcut_row_mount                (ThunarShortcutRow 
*row);
+void               thunar_shortcut_row_unmount              (ThunarShortcutRow 
*row);
+void               thunar_shortcut_row_disconnect           (ThunarShortcutRow 
*row);
 
 G_END_DECLS
 
diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c
index bf2b7a9..e34859b 100644
--- a/thunar/thunar-shortcuts-view.c
+++ b/thunar/thunar-shortcuts-view.c
@@ -108,7 +108,9 @@ static gboolean           
thunar_shortcuts_view_row_context_menu         (Thunar
                                                                           
GtkWidget                        *widget);
 static void               thunar_shortcuts_view_row_open                 
(ThunarShortcutsView              *view);
 static void               thunar_shortcuts_view_row_open_new_window      
(ThunarShortcutsView              *view);
-static void               thunar_shortcuts_view_row_disconnect_mount     
(ThunarShortcutsView              *view);
+static void               thunar_shortcuts_view_row_disconnect           
(ThunarShortcutsView              *view);
+static void               thunar_shortcuts_view_row_mount                
(ThunarShortcutsView              *view);
+static void               thunar_shortcuts_view_row_unmount              
(ThunarShortcutsView              *view);
 static void               thunar_shortcuts_view_open                     
(ThunarShortcutsView              *view,
                                                                           
ThunarFile                       *file,
                                                                           
gboolean                          new_window);
@@ -731,7 +733,7 @@ thunar_shortcuts_view_row_context_menu (ThunarShortcutsView 
*view,
       /* append the "Disconnect" item */
       item = gtk_image_menu_item_new_with_mnemonic (_("Disconn_ect"));
       g_signal_connect_swapped (item, "activate",
-                                G_CALLBACK 
(thunar_shortcuts_view_row_disconnect_mount),
+                                G_CALLBACK 
(thunar_shortcuts_view_row_disconnect),
                                 view);
       gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
       gtk_widget_show (item);
@@ -753,6 +755,9 @@ thunar_shortcuts_view_row_context_menu (ThunarShortcutsView 
*view,
       /* append the "Mount" item */
       item = gtk_image_menu_item_new_with_mnemonic (_("_Mount"));
       gtk_widget_set_sensitive (item, !thunar_g_volume_is_mounted (volume));
+      g_signal_connect_swapped (item, "activate",
+                                G_CALLBACK (thunar_shortcuts_view_row_mount),
+                                view);
       gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
       gtk_widget_show (item);
 
@@ -761,6 +766,9 @@ thunar_shortcuts_view_row_context_menu (ThunarShortcutsView 
*view,
           /* append the "Unmount" item */
           item = gtk_image_menu_item_new_with_mnemonic (_("_Unmount"));
           gtk_widget_set_sensitive (item, thunar_g_volume_is_mounted (volume));
+          g_signal_connect_swapped (item, "activate",
+                                    G_CALLBACK 
(thunar_shortcuts_view_row_unmount),
+                                    view);
           gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
           gtk_widget_show (item);
         }
@@ -768,6 +776,9 @@ thunar_shortcuts_view_row_context_menu (ThunarShortcutsView 
*view,
       /* append the "Disconnect" (eject + safely remove drive) item */
       item = gtk_image_menu_item_new_with_mnemonic (_("Disconn_ect"));
       gtk_widget_set_sensitive (item, thunar_g_volume_is_mounted (volume));
+      g_signal_connect_swapped (item, "activate",
+                                G_CALLBACK 
(thunar_shortcuts_view_row_disconnect),
+                                view);
       gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
       gtk_widget_show (item);
     }
@@ -902,7 +913,37 @@ thunar_shortcuts_view_row_open_new_window 
(ThunarShortcutsView *view)
 
 
 static void
-thunar_shortcuts_view_row_disconnect_mount (ThunarShortcutsView *view)
+thunar_shortcuts_view_row_disconnect (ThunarShortcutsView *view)
+{
+  ThunarShortcutRow *row;
+
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
+
+  row = thunar_shortcuts_view_get_selected_row (view);
+
+  if (row != NULL)
+    thunar_shortcut_row_disconnect (row);
+}
+
+
+
+static void
+thunar_shortcuts_view_row_mount (ThunarShortcutsView *view)
+{
+  ThunarShortcutRow *row;
+
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view));
+
+  row = thunar_shortcuts_view_get_selected_row (view);
+
+  if (row != NULL)
+    thunar_shortcut_row_mount (row);
+}
+
+
+
+static void
+thunar_shortcuts_view_row_unmount (ThunarShortcutsView *view)
 {
   ThunarShortcutRow *row;
 
@@ -911,7 +952,7 @@ thunar_shortcuts_view_row_disconnect_mount 
(ThunarShortcutsView *view)
   row = thunar_shortcuts_view_get_selected_row (view);
 
   if (row != NULL)
-    thunar_shortcut_row_disconnect_mount (row);
+    thunar_shortcut_row_unmount (row);
 }
 
 
_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to