[gnome-disk-utility/wip/iscsi] iscsi: Show a switch that can be used to connect/disconnect all connections



commit 2f0e3016274f0c76ed9141ccdab6b5c4bffef1c3
Author: David Zeuthen <davidz redhat com>
Date:   Tue Feb 28 18:03:49 2012 -0500

    iscsi: Show a switch that can be used to connect/disconnect all connections
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 data/ui/palimpsest.ui      |   63 ++++++++++++++++++++++++++++++---
 src/palimpsest/gduwindow.c |   84 ++++++++++++++++++++++++++++++++++++--------
 2 files changed, 126 insertions(+), 21 deletions(-)
---
diff --git a/data/ui/palimpsest.ui b/data/ui/palimpsest.ui
index 555de26..c6574eb 100644
--- a/data/ui/palimpsest.ui
+++ b/data/ui/palimpsest.ui
@@ -1170,7 +1170,7 @@
                   <object class="GtkTable" id="iscsitab-table">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="n_rows">2</property>
+                    <property name="n_rows">3</property>
                     <property name="n_columns">2</property>
                     <property name="column_spacing">12</property>
                     <child>
@@ -1249,10 +1249,61 @@
                         <property name="y_padding">4</property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkLabel" id="iscsitab-connection-label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">_Connection</property>
+                        <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">iscsitab-connection-switch</property>
+                        <style>
+                          <class name="dim-label"/>
+                        </style>
+                      </object>
+                      <packing>
+                        <property name="left_attach">0</property>
+                        <property name="right_attach">1</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                        <property name="y_padding">4</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkBox" id="box1">
+                        <property name="visible">True</property>
+                        <property name="orientation">horizontal</property>
+                        <property name="can_focus">False</property>
+                        <child>
+                          <object class="GtkSwitch" id="iscsitab-connection-switch">
+                            <property name="use_action_appearance">False</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="use_action_appearance">False</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">2</property>
+                        <property name="bottom_attach">3</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">False</property>
-                    <property name="fill">True</property>
+                    <property name="fill">False</property>
                     <property name="position">0</property>
                   </packing>
                 </child>
@@ -1261,10 +1312,10 @@
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                    <property name="label" translatable="yes">&lt;b&gt;_Connections&lt;/b&gt;</property>
+                    <property name="label" translatable="yes">&lt;b&gt;_Portals&lt;/b&gt;</property>
                     <property name="use_markup">True</property>
                     <property name="use_underline">True</property>
-                    <property name="mnemonic_widget">iscsi-connections-treeview</property>
+                    <property name="mnemonic_widget">iscsitab-connections-treeview</property>
                   </object>
                   <packing>
                     <property name="expand">False</property>
@@ -1288,13 +1339,13 @@
                             <property name="hscrollbar_policy">never</property>
                             <property name="shadow_type">in</property>
                             <child>
-                              <object class="GtkTreeView" id="iscsi-connections-treeview">
+                              <object class="GtkTreeView" id="iscsitab-connections-treeview">
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="show_expanders">False</property>
                                 <property name="level_indentation">12</property>
                                 <child internal-child="selection">
-                                  <object class="GtkTreeSelection" id="iscsi-treeview-selection"/>
+                                  <object class="GtkTreeSelection" id="iscsitab-treeview-selection"/>
                                 </child>
                               </object>
                             </child>
diff --git a/src/palimpsest/gduwindow.c b/src/palimpsest/gduwindow.c
index 8e3fc6c..6894459 100644
--- a/src/palimpsest/gduwindow.c
+++ b/src/palimpsest/gduwindow.c
@@ -112,6 +112,7 @@ struct _GduWindow
   GtkWidget *iscsitab_table;
   GtkWidget *iscsitab_toolbar;
   GtkWidget *iscsitab_connections_treeview;
+  GtkWidget *iscsitab_connection_switch;
 
   GtkWidget *generic_drive_menu;
   GtkWidget *generic_drive_menu_item_view_smart;
@@ -171,7 +172,8 @@ static const struct {
   {G_STRUCT_OFFSET (GduWindow, iscsitab_scrolledwindow), "iscsitab-scrolledwindow"},
   {G_STRUCT_OFFSET (GduWindow, iscsitab_table), "iscsitab-table"},
   {G_STRUCT_OFFSET (GduWindow, iscsitab_toolbar), "iscsitab-toolbar"},
-  {G_STRUCT_OFFSET (GduWindow, iscsitab_connections_treeview), "iscsi-connections-treeview"},
+  {G_STRUCT_OFFSET (GduWindow, iscsitab_connections_treeview), "iscsitab-connections-treeview"},
+  {G_STRUCT_OFFSET (GduWindow, iscsitab_connection_switch), "iscsitab-connection-switch"},
 
   {G_STRUCT_OFFSET (GduWindow, generic_drive_menu), "generic-drive-menu"},
   {G_STRUCT_OFFSET (GduWindow, generic_drive_menu_item_create_disk_image), "generic-drive-menu-item-create-disk-image"},
@@ -254,6 +256,10 @@ static void on_volume_grid_changed (GduVolumeGrid  *grid,
 static void on_iscsi_connections_tree_selection_changed (GtkTreeSelection *tree_selection,
                                                          gpointer          user_data);
 
+static void iscsi_target_connection_switch_on_notify_active (GObject     *object,
+                                                             GParamSpec  *pspec,
+                                                             gpointer     user_data);
+
 static void on_devtab_action_generic_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);
@@ -2401,12 +2407,16 @@ init_iscsi_target_page (GduWindow   *window)
   gtk_tree_view_column_set_attributes (column, renderer,
                                        "markup", GDU_ISCSI_PATH_MODEL_COLUMN_STATUS, NULL);
 
+  g_signal_connect (window->iscsitab_connection_switch,
+                    "notify::active",
+                    G_CALLBACK (iscsi_target_connection_switch_on_notify_active),
+                    window);
+
   g_once_init_leave (&init_val, 1);
  out:
   ;
 }
 
-#if 0
 static gboolean
 iscsi_target_has_active_connections (UDisksiSCSITarget *target)
 {
@@ -2418,11 +2428,12 @@ iscsi_target_has_active_connections (UDisksiSCSITarget *target)
   portals_and_interfaces = udisks_iscsi_target_get_connections (target);
   g_variant_iter_init (&portal_iter, portals_and_interfaces);
   while (g_variant_iter_next (&portal_iter,
-                              "(^&siis&sa{sv})",
+                              "(&siisa{ss}&sa{sv})",
                               NULL,   /* &portal_adress */
                               NULL,   /* &port */
                               NULL,   /* &tpgt */
                               NULL,   /* iface_name */
+                              NULL,   /* configuration */
                               &state,
                               NULL))  /* expansion */
     {
@@ -2435,7 +2446,6 @@ iscsi_target_has_active_connections (UDisksiSCSITarget *target)
  out:
   return ret;
 }
-#endif
 
 static void
 update_iscsi_connection_details (GduWindow *window)
@@ -2515,28 +2525,20 @@ out:
 static void
 update_iscsi_target_page (GduWindow *window)
 {
-  GList *children;
-  GList *l;
   UDisksiSCSITarget *target;
   UDisksObject *source_object = NULL;
   UDisksiSCSISource *source = NULL;
   gchar *discovery = NULL;
 
-  /* first hide everything */
-  children = gtk_container_get_children (GTK_CONTAINER (window->iscsitab_table));
-  for (l = children; l != NULL; l = l->next)
-    {
-      GtkWidget *child = GTK_WIDGET (l->data);
-      gtk_widget_hide (child);
-    }
-  g_list_free (children);
-
   target = udisks_object_peek_iscsi_target (window->current_object);
   set_markup (window,
               "iscsitab-name-label",
               "iscsitab-name-value-label",
               udisks_iscsi_target_get_name (target), SET_MARKUP_FLAGS_NONE);
 
+  gtk_switch_set_active (GTK_SWITCH (window->iscsitab_connection_switch),
+                         iscsi_target_has_active_connections (target));
+
   /* TODO: also show Alias for the target */
 
   source_object = udisks_client_peek_object (window->client, udisks_iscsi_target_get_source (target));
@@ -2689,6 +2691,58 @@ teardown_iscsi_target_page (GduWindow *window)
   gtk_tree_view_set_model (tree_view, NULL);
 }
 
+static void
+iscsi_target_connection_switch_on_notify_active (GObject     *object,
+                                                 GParamSpec  *pspec,
+                                                 gpointer     user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  gboolean active;
+  gboolean has_connections;
+  UDisksiSCSITarget *target;
+
+  target = udisks_object_peek_iscsi_target (window->current_object);
+  if (target == NULL)
+    {
+      g_warning ("Expected selected object to be an iSCSI target");
+      goto out;
+    }
+
+  active = !! gtk_switch_get_active (GTK_SWITCH (window->iscsitab_connection_switch));
+  has_connections = !! iscsi_target_has_active_connections (target);
+  if (active != has_connections)
+    {
+      if (!has_connections)
+        {
+          udisks_iscsi_target_call_login (target,
+                                          "", /* portal_address */
+                                          0,  /* portal_port */
+                                          -1, /* tpgt */
+                                          "", /* interface_name */
+                                          g_variant_new ("a{sv}", NULL), /* options */
+                                          NULL,  /* GCancellable* */
+                                          (GAsyncReadyCallback) iscsi_target_login_cb,
+                                          g_object_ref (window));
+        }
+      else
+        {
+          udisks_iscsi_target_call_logout (target,
+                                           "", /* portal_address */
+                                           0, /* portal_port */
+                                           -1, /* tpgt */
+                                           "", /* interface_name */
+                                           g_variant_new ("a{sv}", NULL), /* options */
+                                           NULL,  /* GCancellable* */
+                                           (GAsyncReadyCallback) iscsi_target_logout_cb,
+                                           g_object_ref (window));
+        }
+    }
+  gtk_switch_set_active (GTK_SWITCH (window->iscsitab_connection_switch), has_connections);
+
+ out:
+  ;
+}
+
 /* ---------------------------------------------------------------------------------------------------- */
 
 /* TODO: right now we show a MessageDialog but we could do things like an InfoBar etc */



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