[gnome-control-center] Network: Add a + button and make it do something



commit d4e155a2774f0c2a70a4de3486f8a33c56660e99
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Mar 15 22:05:31 2011 -0400

    Network: Add a + button and make it do something
    
    In the short term, cheat by bringing up nm-connection-editor.
    In the future, we will do something better here.
    The newly created connections do net get picked up in the list
    of devices/connections yet.

 panels/network/cc-network-panel.c |   58 +++++++++++--
 panels/network/network.ui         |  170 +++++++++++++++++++++++++++++++++++++
 2 files changed, 222 insertions(+), 6 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 05fe2fd..e705626 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -1670,16 +1670,61 @@ edit_connection (GtkButton *button, CcNetworkPanel *panel)
         }
 
         uuid = nm_connection_get_uuid (c);
+
         cmdline = g_strdup_printf ("nm-connection-editor --edit %s", uuid);
+        g_debug ("Launching '%s'\n", cmdline);
+
         error = NULL;
         if (!g_spawn_command_line_async (cmdline, &error)) {
                 g_warning ("Failed to launch nm-connection-editor: %s", error->message);
                 g_error_free (error);
         }
+
         g_free (cmdline);
 }
 
 static void
+add_connection (GtkToolButton *button, CcNetworkPanel *panel)
+{
+        GtkWidget *dialog;
+        gint response;
+
+        dialog = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
+                                                     "connection_type_dialog"));
+        gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (panel))));
+
+        response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+        gtk_widget_hide (dialog);
+
+        if (response == GTK_RESPONSE_OK) {
+                GtkComboBox *combo;
+                GtkTreeModel *model;
+                GtkTreeIter iter;
+                gchar *type;
+                gchar *cmdline;
+                GError *error;
+
+                combo = GTK_COMBO_BOX (gtk_builder_get_object (panel->priv->builder,
+                                                               "connection_type_combo"));
+                model = gtk_combo_box_get_model (combo);
+                gtk_combo_box_get_active_iter (combo, &iter);
+                gtk_tree_model_get (model, &iter, 1, &type, -1);
+
+                cmdline = g_strdup_printf ("nm-connection-editor --create --type %s", type);
+                g_debug ("Launching '%s'\n", cmdline);
+
+                error = NULL;
+                if (!g_spawn_command_line_async (cmdline, &error)) {
+                        g_warning ("Failed to launch nm-connection-editor: %s", error->message);
+                        g_error_free (error);
+                }
+                g_free (cmdline);
+                g_free (type);
+        }
+}
+
+static void
 cc_network_panel_init (CcNetworkPanel *panel)
 {
         DBusGConnection *bus = NULL;
@@ -1870,17 +1915,21 @@ cc_network_panel_init (CcNetworkPanel *panel)
         g_signal_connect (widget, "clicked",
                           G_CALLBACK (edit_connection), panel);
 
-        /* disable for now, until we can remove connections without
-         * segfaulting NM... */
         widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
                                                      "add_toolbutton"));
-        gtk_widget_set_sensitive (widget, FALSE);
+        g_signal_connect (widget, "clicked",
+                          G_CALLBACK (add_connection), panel);
+
+        /* disable for now, until we actually show removable connections */
         widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
                                                      "remove_toolbutton"));
         gtk_widget_set_sensitive (widget, FALSE);
+
+        /* nothing to unlock yet */
         widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
                                                      "button_unlock"));
         gtk_widget_set_sensitive (widget, FALSE);
+
         widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
                                                      "switch_flight_mode"));
         ret = nm_client_wireless_get_enabled (panel->priv->client);
@@ -1917,9 +1966,6 @@ cc_network_panel_init (CcNetworkPanel *panel)
 
         /* hide stuff that doesn't work yet */
         widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
-                                                     "devices_toolbar"));
-        gtk_widget_hide (widget);
-        widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder,
                                                      "button_unlock"));
         gtk_widget_hide (widget);
 
diff --git a/panels/network/network.ui b/panels/network/network.ui
index 0ed86ce..7394d3f 100644
--- a/panels/network/network.ui
+++ b/panels/network/network.ui
@@ -2208,4 +2208,174 @@
       <widget name="label47"/>
     </widgets>
   </object>
+  <object class="GtkListStore" id="liststore1">
+    <columns>
+      <!-- column-name type -->
+      <column type="gchararray"/>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Wired</col>
+        <col id="1">802-3-ethernet</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Wireless</col>
+        <col id="1">802-11-wireless</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Mobile Broadband</col>
+        <col id="1">gsm</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">VPN</col>
+        <col id="1">vpn</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">DSL</col>
+        <col id="1">pppoe</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkDialog" id="connection_type_dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="vbox_1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_left">12</property>
+        <property name="margin_right">12</property>
+        <property name="margin_top">12</property>
+        <property name="margin_bottom">12</property>
+        <property name="spacing">10</property>
+        <child>
+          <object class="GtkHBox" id="hbox_1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkLabel" id="label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Select the interface to use for the new service</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox" id="box_1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">center</property>
+            <property name="spacing">10</property>
+            <child>
+              <object class="GtkLabel" id="label_1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Interface:</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBox" id="connection_type_combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="valign">start</property>
+                <property name="margin_top">12</property>
+                <property name="margin_bottom">12</property>
+                <property name="model">liststore1</property>
+                <property name="active">0</property>
+                <child>
+                  <object class="GtkCellRendererText" id="renderer_1"/>
+                  <attributes>
+                    <attribute name="text">0</attribute>
+                  </attributes>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="hbuttonbox_1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="spacing">10</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="cancel_button">
+                <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="create_button">
+                <property name="label" translatable="yes">Create...</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>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">cancel_button</action-widget>
+      <action-widget response="-5">create_button</action-widget>
+    </action-widgets>
+  </object>
 </interface>



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