[gnome-control-center] Network: Add warning dialogs



commit fea89403bf8324c8f4a6a56709cf9f3615ceec69
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu May 26 17:19:58 2011 -0400

    Network: Add warning dialogs
    
    We warn if there is no connection to the internet (questionable
    to create a hotspot in that case) or if creating the hotspot
    would drop the default connection to the internet (ditto).

 panels/network/cc-network-panel.c |   69 +++++++++++++++++++++++++++++++++++++
 1 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 1e9af11..dab4530 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -2783,8 +2783,77 @@ create_shared_connection (CcNetworkPanel *panel)
 }
 
 static void
+hotspot_response_cb (GtkWidget *dialog, gint response, CcNetworkPanel *panel)
+{
+        if (response == GTK_RESPONSE_OK) {
+                create_shared_connection (panel);
+        }
+        gtk_widget_destroy (dialog);
+}
+
+static void
+show_hotspot_confirmation_dialog (CcNetworkPanel *panel,
+                                  const gchar    *text)
+{
+        GtkWidget *dialog;
+        GtkWidget *window;
+
+        window = gtk_widget_get_toplevel (GTK_WIDGET (panel));
+        dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+                                         GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                         GTK_MESSAGE_WARNING,
+                                         GTK_BUTTONS_NONE,
+                                         text);
+        gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                _("_Start Hotspot"), GTK_RESPONSE_OK,
+                                NULL);
+        g_signal_connect (dialog, "response",
+                          G_CALLBACK (hotspot_response_cb), panel);
+        gtk_window_present (GTK_WINDOW (dialog));
+}
+
+static void
 start_hotspot (GtkButton *button, CcNetworkPanel *panel)
 {
+        NetObject *object;
+        NMDevice *device;
+        gboolean is_default;
+        const GPtrArray *connections;
+        const GPtrArray *devices;
+        NMActiveConnection *c;
+        gint i;
+
+        object = get_selected_object (panel);
+        device = net_device_get_nm_device (NET_DEVICE (object));
+        connections = nm_client_get_active_connections (panel->priv->client);
+        if (connections == NULL || connections->len == 0) {
+                show_hotspot_confirmation_dialog (panel,
+                     _("You have no connection to the internet, so the hotspot will only allow others to reach your system.\n"
+                       "Start the hotspot anyway ?"));
+                return;
+        }
+
+        is_default = FALSE;
+        for (i = 0; i < connections->len; i++) {
+                c = (NMActiveConnection *)connections->pdata[i];
+                devices = nm_active_connection_get_devices (c);
+                if (nm_active_connection_get_default (c)) {
+                        if (devices->pdata[0] == device) {
+                                is_default = TRUE;
+                        }
+                        break;
+                }
+        }
+
+        if (is_default) {
+                show_hotspot_confirmation_dialog (panel,
+                     _("Turning this device into a hotspot will drop your default connection to the internet.\n"
+                       "Start the hotspot anyway ?"));
+                return;
+        }
+
+        /* if we get here, things look good to go ahead */
         create_shared_connection (panel);
 }
 



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