[gnome-disk-utility/udisks2-port] Add a toolbar for the grid



commit 4100ec3bb23d34ecf9eaecac87af45024fa60af8
Author: David Zeuthen <davidz redhat com>
Date:   Mon Mar 28 16:57:27 2011 -0400

    Add a toolbar for the grid
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 data/ui/palimpsest.ui          |  330 ++++++++++++++++++++++++++++-------
 src/palimpsest/gduvolumegrid.c |   24 ++--
 src/palimpsest/gduwindow.c     |  372 +++++++++++++++++++++++++++++++++++++++-
 3 files changed, 644 insertions(+), 82 deletions(-)
---
diff --git a/data/ui/palimpsest.ui b/data/ui/palimpsest.ui
index e139cb3..9ee0441 100644
--- a/data/ui/palimpsest.ui
+++ b/data/ui/palimpsest.ui
@@ -1,6 +1,56 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkActionGroup" id="devtab-actions">
+    <child>
+      <object class="GtkAction" id="devtab-action-format">
+        <property name="tooltip" translatable="yes">Format the device</property>
+        <property name="icon_name">text-x-generic-symbolic</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="devtab-action-partition-create">
+        <property name="tooltip" translatable="yes">Create a new partition in the free space</property>
+        <property name="icon_name">list-add-symbolic</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="devtab-action-partition-delete">
+        <property name="tooltip" translatable="yes">Delete the partition</property>
+        <property name="icon_name">edit-delete-symbolic</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="devtab-action-mount">
+        <property name="tooltip" translatable="yes">Mount the device</property>
+        <property name="icon_name">media-playback-start-symbolic</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="devtab-action-unmount">
+        <property name="tooltip" translatable="yes">Unmount the device</property>
+        <property name="icon_name">media-playback-stop-symbolic</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="devtab-action-eject">
+        <property name="tooltip" translatable="yes">Ejects the media</property>
+        <property name="icon_name">media-eject-symbolic</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="devtab-action-unlock">
+        <property name="tooltip" translatable="yes">Unlock the encrypted device</property>
+        <property name="icon_name">changes-allow-symbolic</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="devtab-action-lock">
+        <property name="tooltip" translatable="yes">Lock the encrypted device</property>
+        <property name="icon_name">changes-prevent-symbolic</property>
+      </object>
+    </child>
+  </object>
   <object class="GtkDialog" id="change-filesystem-label-dialog">
     <property name="can_focus">False</property>
     <property name="border_width">12</property>
@@ -27,44 +77,6 @@
             <property name="position">0</property>
           </packing>
         </child>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area4">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="button3">
-                <property name="label">gtk-cancel</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_action_appearance">False</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="button4">
-                <property name="label" translatable="yes">C_hange</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_action_appearance">False</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-        </child>
         <child>
           <object class="GtkTable" id="table2">
             <property name="visible">True</property>
@@ -102,32 +114,13 @@
             <property name="position">2</property>
           </packing>
         </child>
-      </object>
-    </child>
-    <action-widgets>
-      <action-widget response="-6">button3</action-widget>
-      <action-widget response="-5">button4</action-widget>
-    </action-widgets>
-  </object>
-  <object class="GtkDialog" id="change-partition-type-dialog">
-    <property name="can_focus">False</property>
-    <property name="border_width">12</property>
-    <property name="resizable">False</property>
-    <property name="modal">True</property>
-    <property name="type_hint">dialog</property>
-    <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox1">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">12</property>
         <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area1">
+          <object class="GtkButtonBox" id="dialog-action_area4">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="layout_style">end</property>
             <child>
-              <object class="GtkButton" id="button1">
+              <object class="GtkButton" id="button3">
                 <property name="label">gtk-cancel</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -142,7 +135,7 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="button2">
+              <object class="GtkButton" id="button4">
                 <property name="label" translatable="yes">C_hange</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -159,6 +152,25 @@
             </child>
           </object>
         </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">button3</action-widget>
+      <action-widget response="-5">button4</action-widget>
+    </action-widgets>
+  </object>
+  <object class="GtkDialog" id="change-partition-type-dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">12</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
         <child>
           <object class="GtkLabel" id="label2">
             <property name="visible">True</property>
@@ -208,6 +220,44 @@
             <property name="position">2</property>
           </packing>
         </child>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button1">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button2">
+                <property name="label" translatable="yes">C_hange</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+        </child>
       </object>
     </child>
     <action-widgets>
@@ -260,7 +310,7 @@
                 <property name="can_focus">False</property>
                 <property name="icon_size">1</property>
                 <child>
-                  <object class="GtkToolButton" id="device-tree-add-toolbutton">
+                  <object class="GtkToolButton" id="dtoolbutton1">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="use_action_appearance">False</property>
@@ -272,7 +322,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkToolButton" id="device-tree-remove-toolbutton">
+                  <object class="GtkToolButton" id="dtoolbutton2">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="use_action_appearance">False</property>
@@ -355,14 +405,125 @@
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <child>
-                          <object class="GtkHBox" id="devtab-grid-hbox">
+                          <object class="GtkVBox" id="vbox4">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
                             <child>
-                              <placeholder/>
+                              <object class="GtkHBox" id="devtab-grid-hbox">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">0</property>
+                              </packing>
                             </child>
                             <child>
-                              <placeholder/>
+                              <object class="GtkToolbar" id="devtab-grid-toolbar">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="icon_size">1</property>
+                                <child>
+                                  <object class="GtkToolButton" id="toolbutton1">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="related_action">devtab-action-format</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="homogeneous">True</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkToolButton" id="toolbutton2">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="related_action">devtab-action-partition-create</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="homogeneous">True</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkToolButton" id="toolbutton3">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="related_action">devtab-action-partition-delete</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="homogeneous">True</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkToolButton" id="toolbutton4">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="related_action">devtab-action-mount</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="homogeneous">True</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkToolButton" id="toolbutton5">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="related_action">devtab-action-unmount</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="homogeneous">True</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkToolButton" id="toolbutton6">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="related_action">devtab-action-eject</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="homogeneous">True</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkToolButton" id="toolbutton7">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="related_action">devtab-action-unlock</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="homogeneous">True</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkToolButton" id="toolbutton8">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="related_action">devtab-action-lock</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="homogeneous">True</property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">1</property>
+                              </packing>
                             </child>
                           </object>
                           <packing>
@@ -375,7 +536,7 @@
                           <object class="GtkTable" id="devtab-table">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
-                            <property name="n_rows">15</property>
+                            <property name="n_rows">16</property>
                             <property name="n_columns">2</property>
                             <property name="column_spacing">10</property>
                             <child>
@@ -905,6 +1066,43 @@
                             <child>
                               <placeholder/>
                             </child>
+                            <child>
+                              <object class="GtkLabel" id="devtab-volume-filesystem-mount-point-label">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="xalign">1</property>
+                                <property name="label" translatable="yes">Mount Point</property>
+                                <attributes>
+                                  <attribute name="foreground" value="#555555555555"/>
+                                </attributes>
+                              </object>
+                              <packing>
+                                <property name="top_attach">14</property>
+                                <property name="bottom_attach">15</property>
+                                <property name="x_options">GTK_FILL</property>
+                                <property name="y_options"></property>
+                                <property name="y_padding">4</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="devtab-volume-filesystem-mount-point-value-label">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="hexpand">True</property>
+                                <property name="xalign">0</property>
+                                <property name="selectable">True</property>
+                                <property name="ellipsize">end</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="right_attach">2</property>
+                                <property name="top_attach">14</property>
+                                <property name="bottom_attach">15</property>
+                                <property name="x_options">GTK_FILL</property>
+                                <property name="y_options"></property>
+                                <property name="y_padding">4</property>
+                              </packing>
+                            </child>
                           </object>
                           <packing>
                             <property name="expand">True</property>
diff --git a/src/palimpsest/gduvolumegrid.c b/src/palimpsest/gduvolumegrid.c
index fb62899..ac7209a 100644
--- a/src/palimpsest/gduvolumegrid.c
+++ b/src/palimpsest/gduvolumegrid.c
@@ -759,8 +759,10 @@ recompute_size_for_slice (GList          *elements,
         element->edge_flags |= GRID_EDGE_TOP;
       if (element->x + element->width == total_width)
         element->edge_flags |= GRID_EDGE_RIGHT;
+#if 0
       if (element->y + element->height == total_height)
         element->edge_flags |= GRID_EDGE_BOTTOM;
+#endif
 
       x += element_width;
 
@@ -1000,9 +1002,9 @@ render_element (GduVolumeGrid *grid,
   focus_rect_red     = 0.60;
   focus_rect_green   = 0.70;
   focus_rect_blue    = 0.80;
-  stroke_red   = 0.75;
-  stroke_green = 0.75;
-  stroke_blue  = 0.75;
+  stroke_red   = 0.65;
+  stroke_green = 0.65;
+  stroke_blue  = 0.65;
   stroke_selected_red   = 0.3;
   stroke_selected_green = 0.45;
   stroke_selected_blue  = 0.6;
@@ -1025,10 +1027,10 @@ render_element (GduVolumeGrid *grid,
 
   cairo_save (cr);
   cairo_rectangle (cr,
-                   element->x + 0.5,
-                   element->y + 0.5,
-                   element->width,
-                   element->height);
+                   element->x - 0.5,
+                   element->y - 0.5,
+                   element->width + 1.5,
+                   element->height + 1.5);
   cairo_clip (cr);
 
   round_rect (cr,
@@ -1221,13 +1223,13 @@ render_element (GduVolumeGrid *grid,
   if (element->show_padlock_open)
     g_ptr_array_add (pixbufs_to_render,
                      gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
-                                               "gdu-encrypted-unlock",
-                                               16, 0, NULL));
+                                               "changes-allow-symbolic",
+                                               12, 0, NULL));
   if (element->show_padlock_closed)
     g_ptr_array_add (pixbufs_to_render,
                      gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
-                                               "gdu-encrypted-lock",
-                                               16, 0, NULL));
+                                               "changes-prevent-symbolic",
+                                               12, 0, NULL));
   for (n = 0; n < pixbufs_to_render->len; n++)
     {
       GdkPixbuf *pixbuf = GDK_PIXBUF (pixbufs_to_render->pdata[n]);
diff --git a/src/palimpsest/gduwindow.c b/src/palimpsest/gduwindow.c
index e8668a8..4490d36 100644
--- a/src/palimpsest/gduwindow.c
+++ b/src/palimpsest/gduwindow.c
@@ -77,6 +77,10 @@ static void gdu_window_show_error (GduWindow   *window,
                                    const gchar *message,
                                    GError      *orig_error);
 
+static gboolean on_activate_link (GtkLabel    *label,
+                                  const gchar *uri,
+                                  gpointer     user_data);
+
 static void setup_device_page (GduWindow *window, GDBusObject *object);
 static void update_device_page (GduWindow *window);
 static void teardown_device_page (GduWindow *window);
@@ -88,6 +92,15 @@ static void teardown_iscsi_target_page (GduWindow *window);
 static void on_volume_grid_changed (GduVolumeGrid  *grid,
                                     gpointer        user_data);
 
+static void on_devtab_action_mount_activated (GtkAction *action, gpointer user_data);
+static void on_devtab_action_unmount_activated (GtkAction *action, gpointer user_data);
+static void on_devtab_action_format_activated (GtkAction *action, gpointer user_data);
+static void on_devtab_action_partition_create_activated (GtkAction *action, gpointer user_data);
+static void on_devtab_action_partition_delete_activated (GtkAction *action, gpointer user_data);
+static void on_devtab_action_eject_activated (GtkAction *action, gpointer user_data);
+static void on_devtab_action_unlock_activated (GtkAction *action, gpointer user_data);
+static void on_devtab_action_lock_activated (GtkAction *action, gpointer user_data);
+
 static void iscsi_connection_switch_on_notify_active (GObject     *object,
                                                       GParamSpec  *pspec,
                                                       gpointer     user_data);
@@ -252,6 +265,41 @@ on_tree_selection_changed (GtkTreeSelection *tree_selection,
 gboolean _gdu_application_get_running_from_source_tree (GduApplication *app);
 
 static void
+init_css (GduWindow *window)
+{
+  GtkCssProvider *provider;
+  GError *error;
+  const gchar *css =
+"#devtab-grid-toolbar.toolbar {\n"
+"    border-width: 1;\n"
+"    border-radius: 3;\n"
+"    border-style: solid;\n"
+"    background-color: @theme_base_color;\n"
+"}\n"
+;
+
+  provider = gtk_css_provider_new ();
+  error = NULL;
+  if (!gtk_css_provider_load_from_data (provider,
+                                        css,
+                                        -1,
+                                        &error))
+    {
+      g_warning ("Can't parse custom CSS: %s\n", error->message);
+      g_error_free (error);
+      goto out;
+    }
+
+  gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (GTK_WIDGET (window)),
+                                             GTK_STYLE_PROVIDER (provider),
+                                             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+  g_object_unref (provider);
+
+ out:
+  ;
+}
+
+static void
 gdu_window_constructed (GObject *object)
 {
   GduWindow *window = GDU_WINDOW (object);
@@ -267,6 +315,8 @@ gdu_window_constructed (GObject *object)
   GtkStyleContext *context;
   GDBusObjectManager *object_manager;
 
+  init_css (window);
+
   /* chain up */
   if (G_OBJECT_CLASS (gdu_window_parent_class)->constructed != NULL)
     G_OBJECT_CLASS (gdu_window_parent_class)->constructed (object);
@@ -401,6 +451,10 @@ gdu_window_constructed (GObject *object)
                     G_CALLBACK (on_volume_grid_changed),
                     window);
 
+  context = gtk_widget_get_style_context (gdu_window_get_widget (window, "devtab-grid-toolbar"));
+  gtk_widget_set_name (gdu_window_get_widget (window, "devtab-grid-toolbar"), "devtab-grid-toolbar");
+  gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
+
   /* devtab's Write Cache switch */
   window->write_cache_switch = gtk_switch_new ();
   gtk_box_pack_start (GTK_BOX (gdu_window_get_widget (window, "devtab-write-cache-hbox")),
@@ -420,6 +474,40 @@ gdu_window_constructed (GObject *object)
                       FALSE, TRUE, 0);
   gtk_label_set_mnemonic_widget (GTK_LABEL (gdu_window_get_widget (window, "iscsitab-connection-label")),
                                  window->iscsi_connection_switch);
+
+  /* actions */
+  g_signal_connect (gtk_builder_get_object (window->builder, "devtab-action-format"),
+                    "activate",
+                    G_CALLBACK (on_devtab_action_format_activated),
+                    window);
+  g_signal_connect (gtk_builder_get_object (window->builder, "devtab-action-partition-create"),
+                    "activate",
+                    G_CALLBACK (on_devtab_action_partition_create_activated),
+                    window);
+  g_signal_connect (gtk_builder_get_object (window->builder, "devtab-action-partition-delete"),
+                    "activate",
+                    G_CALLBACK (on_devtab_action_partition_delete_activated),
+                    window);
+  g_signal_connect (gtk_builder_get_object (window->builder, "devtab-action-mount"),
+                    "activate",
+                    G_CALLBACK (on_devtab_action_mount_activated),
+                    window);
+  g_signal_connect (gtk_builder_get_object (window->builder, "devtab-action-unmount"),
+                    "activate",
+                    G_CALLBACK (on_devtab_action_unmount_activated),
+                    window);
+  g_signal_connect (gtk_builder_get_object (window->builder, "devtab-action-eject"),
+                    "activate",
+                    G_CALLBACK (on_devtab_action_eject_activated),
+                    window);
+  g_signal_connect (gtk_builder_get_object (window->builder, "devtab-action-unlock"),
+                    "activate",
+                    G_CALLBACK (on_devtab_action_unlock_activated),
+                    window);
+  g_signal_connect (gtk_builder_get_object (window->builder, "devtab-action-lock"),
+                    "activate",
+                    G_CALLBACK (on_devtab_action_lock_activated),
+                    window);
 }
 
 static void
@@ -577,11 +665,6 @@ typedef enum
   SET_MARKUP_FLAGS_CHANGE_LINK = (1<<1)
 } SetMarkupFlags;
 
-static gboolean
-on_activate_link (GtkLabel    *label,
-                  const gchar *uri,
-                  gpointer     user_data);
-
 static void
 set_markup (GduWindow      *window,
             const gchar    *key_label_id,
@@ -989,6 +1072,51 @@ update_device_page_for_lun (GduWindow    *window,
               media_compat_for_display, SET_MARKUP_FLAGS_NONE);
 
   g_free (media_compat_for_display);
+
+  gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (window->builder,
+                                                              "devtab-action-format")), TRUE);
+
+  if (udisks_lun_get_media_removable (lun))
+    {
+      gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (window->builder,
+                                                                  "devtab-action-eject")), TRUE);
+    }
+}
+
+static GDBusObject *
+lookup_cleartext_device_for_crypto_device (UDisksClient  *client,
+                                           const gchar   *object_path)
+{
+  GDBusObjectManager *object_manager;
+  GDBusObject *ret;
+  GList *objects;
+  GList *l;
+
+  ret = NULL;
+
+  object_manager = udisks_client_get_object_manager (client);
+  objects = g_dbus_object_manager_get_objects (object_manager);
+  for (l = objects; l != NULL; l = l->next)
+    {
+      GDBusObject *object = G_DBUS_OBJECT (l->data);
+      UDisksBlockDevice *block;
+
+      block = UDISKS_PEEK_BLOCK_DEVICE (object);
+      if (block == NULL)
+        continue;
+
+      if (g_strcmp0 (udisks_block_device_get_crypto_backing_device (block),
+                     object_path) == 0)
+        {
+          ret = g_object_ref (object);
+          goto out;
+        }
+    }
+
+ out:
+  g_list_foreach (objects, (GFunc) g_object_unref, NULL);
+  g_list_free (objects);
+  return ret;
 }
 
 static void
@@ -1078,7 +1206,92 @@ update_device_page_for_block (GduWindow         *window,
                   partition_label,
                   SET_MARKUP_FLAGS_CHANGE_LINK);
       g_free (type_for_display);
+
+      gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (window->builder,
+                                                                  "devtab-action-partition-delete")), TRUE);
     }
+  else
+    {
+      GDBusObject *lun_object;
+      lun_object = g_dbus_object_manager_get_object (udisks_client_get_object_manager (window->client),
+                                                     udisks_block_device_get_lun (block));
+      if (lun_object != NULL)
+        {
+          UDisksLun *lun;
+          lun = UDISKS_PEEK_LUN (lun_object);
+          if (udisks_lun_get_media_removable (lun))
+            {
+              gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (window->builder,
+                                                                          "devtab-action-eject")), TRUE);
+            }
+          g_object_unref (lun_object);
+        }
+    }
+
+  if (g_strcmp0 (udisks_block_device_get_id_usage (block), "filesystem") == 0)
+    {
+      UDisksFilesystem *filesystem;
+      filesystem = UDISKS_PEEK_FILESYSTEM (object);
+      if (filesystem != NULL)
+        {
+          const gchar *const *mount_points;
+          mount_points = udisks_filesystem_get_mount_points (filesystem);
+          if (g_strv_length ((gchar **) mount_points) > 0)
+            {
+              gchar *mount_points_for_display;
+              /* TODO: right now we only display the first mount point; could be we need to display
+               * more than just that...
+               */
+
+              if (g_strcmp0 (mount_points[0], "/") == 0)
+                {
+                  /* Translators: This is shown for a device mounted at the filesystem root / - we show
+                   * this text instead of '/', because '/' is too small to hit as a hyperlink
+                   */
+                  mount_points_for_display = g_strdup_printf ("<a href=\"file:///\">%s</a>", _("Root Filesystem (/)"));
+                }
+              else
+                {
+                  mount_points_for_display = g_strdup_printf ("<a href=\"file://%s\">%s</a>",
+                                                              mount_points[0], mount_points[0]);
+                }
+              set_markup (window,
+                          "devtab-volume-filesystem-mount-point-label",
+                          "devtab-volume-filesystem-mount-point-value-label",
+                          mount_points_for_display,
+                          SET_MARKUP_FLAGS_NONE);
+              g_free (mount_points_for_display);
+
+              gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (window->builder,
+                                                                          "devtab-action-unmount")), TRUE);
+            }
+          else
+            {
+              gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (window->builder,
+                                                                          "devtab-action-mount")), TRUE);
+            }
+        }
+    }
+  else if (g_strcmp0 (udisks_block_device_get_id_usage (block), "crypto") == 0)
+    {
+      GDBusObject *cleartext_device;
+
+      cleartext_device = lookup_cleartext_device_for_crypto_device (window->client,
+                                                                    g_dbus_object_get_object_path (object));
+      if (cleartext_device != NULL)
+        {
+          gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (window->builder,
+                                                                      "devtab-action-lock")), TRUE);
+          g_object_unref (cleartext_device);
+        }
+      else
+        {
+          gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (window->builder,
+                                                                      "devtab-action-unlock")), TRUE);
+        }
+    }
+  gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (window->builder,
+                                                              "devtab-action-format")), TRUE);
 }
 
 static void
@@ -1113,6 +1326,8 @@ update_device_page_for_free_space (GduWindow         *window,
               "devtab-volume-type-value-label",
               _("Unallocated Space"),
               SET_MARKUP_FLAGS_NONE);
+  gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (window->builder,
+                                                              "devtab-action-partition-create")), TRUE);
 }
 
 static void
@@ -1134,6 +1349,14 @@ update_device_page (GduWindow *window)
       gtk_widget_hide (child);
     }
   g_list_free (children);
+  children = gtk_action_group_list_actions (GTK_ACTION_GROUP (gtk_builder_get_object (window->builder, "devtab-actions")));
+  for (l = children; l != NULL; l = l->next)
+    {
+      GtkAction *child = GTK_ACTION (l->data);
+      gtk_action_set_visible (child, FALSE);
+    }
+  g_list_free (children);
+
 
   object = window->current_object;
   lun = UDISKS_PEEK_LUN (window->current_object);
@@ -1846,3 +2069,142 @@ on_activate_link (GtkLabel    *label,
   return handled;
 }
 
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+mount_cb (UDisksFilesystem *filesystem,
+          GAsyncResult     *res,
+          gpointer          user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  GError *error;
+
+  error = NULL;
+  if (!udisks_filesystem_call_mount_finish (filesystem,
+                                            NULL, /* out_mount_path */
+                                            res,
+                                            &error))
+    {
+      gdu_window_show_error (window,
+                             _("Error mounting filesystem"),
+                             error);
+      g_error_free (error);
+    }
+  g_object_unref (window);
+}
+
+static void
+on_devtab_action_mount_activated (GtkAction *action,
+                                  gpointer   user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  GDBusObject *object;
+  UDisksFilesystem *filesystem;
+  const gchar *options[] = {NULL};
+
+  object = gdu_volume_grid_get_selected_device (GDU_VOLUME_GRID (window->volume_grid));
+  filesystem = UDISKS_PEEK_FILESYSTEM (object);
+  udisks_filesystem_call_mount (filesystem,
+                                "", /* filesystem type */
+                                options, /* options */
+                                NULL, /* cancellable */
+                                (GAsyncReadyCallback) mount_cb,
+                                g_object_ref (window));
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+unmount_cb (UDisksFilesystem *filesystem,
+            GAsyncResult     *res,
+            gpointer          user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  GError *error;
+
+  error = NULL;
+  if (!udisks_filesystem_call_unmount_finish (filesystem,
+                                              res,
+                                              &error))
+    {
+      gdu_window_show_error (window,
+                             _("Error unmounting filesystem"),
+                             error);
+      g_error_free (error);
+    }
+  g_object_unref (window);
+}
+
+static void
+on_devtab_action_unmount_activated (GtkAction *action,
+                                    gpointer   user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  GDBusObject *object;
+  UDisksFilesystem *filesystem;
+  const gchar *options[] = {NULL};
+
+  object = gdu_volume_grid_get_selected_device (GDU_VOLUME_GRID (window->volume_grid));
+  filesystem = UDISKS_PEEK_FILESYSTEM (object);
+  udisks_filesystem_call_unmount (filesystem,
+                                  options, /* options */
+                                  NULL, /* cancellable */
+                                  (GAsyncReadyCallback) unmount_cb,
+                                  g_object_ref (window));
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+on_devtab_action_format_activated (GtkAction *action,
+                                   gpointer   user_data)
+{
+  g_debug ("%s: TODO", G_STRFUNC);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+on_devtab_action_partition_create_activated (GtkAction *action,
+                                             gpointer   user_data)
+{
+  g_debug ("%s: TODO", G_STRFUNC);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+on_devtab_action_partition_delete_activated (GtkAction *action,
+                                             gpointer   user_data)
+{
+  g_debug ("%s: TODO", G_STRFUNC);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+on_devtab_action_eject_activated (GtkAction *action,
+                                  gpointer   user_data)
+{
+  g_debug ("%s: TODO", G_STRFUNC);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+on_devtab_action_unlock_activated (GtkAction *action,
+                                   gpointer   user_data)
+{
+  g_debug ("%s: TODO", G_STRFUNC);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+on_devtab_action_lock_activated (GtkAction *action,
+                                 gpointer   user_data)
+{
+  g_debug ("%s: TODO", G_STRFUNC);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */



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