Network: Improve wording of warnings

Also, add a warning when stopping hotspots, too, and consequently
add the dots back to the stop button as well.
This commit is contained in:
Matthias Clasen 2011-05-26 18:47:27 -04:00
parent 24c320a2c3
commit a7c3024998
2 changed files with 84 additions and 46 deletions

View file

@ -2680,7 +2680,7 @@ is_hotspot_connection (NMConnection *connection)
} }
static void static void
create_shared_connection (CcNetworkPanel *panel) start_shared_connection (CcNetworkPanel *panel)
{ {
NMConnection *c; NMConnection *c;
NMConnection *tmp; NMConnection *tmp;
@ -2788,36 +2788,14 @@ create_shared_connection (CcNetworkPanel *panel)
} }
static void static void
hotspot_response_cb (GtkWidget *dialog, gint response, CcNetworkPanel *panel) start_hotspot_response_cb (GtkWidget *dialog, gint response, CcNetworkPanel *panel)
{ {
if (response == GTK_RESPONSE_OK) { if (response == GTK_RESPONSE_OK) {
create_shared_connection (panel); start_shared_connection (panel);
} }
gtk_widget_destroy (dialog); 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 static void
start_hotspot (GtkButton *button, CcNetworkPanel *panel) start_hotspot (GtkButton *button, CcNetworkPanel *panel)
{ {
@ -2827,43 +2805,73 @@ start_hotspot (GtkButton *button, CcNetworkPanel *panel)
const GPtrArray *connections; const GPtrArray *connections;
const GPtrArray *devices; const GPtrArray *devices;
NMActiveConnection *c; NMActiveConnection *c;
NMAccessPoint *ap;
gchar *active_ssid;
gchar *warning;
gint i; gint i;
warning = NULL;
object = get_selected_object (panel); object = get_selected_object (panel);
device = net_device_get_nm_device (NET_DEVICE (object)); device = net_device_get_nm_device (NET_DEVICE (object));
connections = nm_client_get_active_connections (panel->priv->client); connections = nm_client_get_active_connections (panel->priv->client);
if (connections == NULL || connections->len == 0) { if (connections == NULL || connections->len == 0) {
show_hotspot_confirmation_dialog (panel, warning = g_strdup_printf ("%s\n\n%s",
_("You have no connection to the internet, so the hotspot will only allow others to reach your system.\n" _("Not connected to the internet."),
"Start the hotspot anyway ?")); _("Create the hotspot anyway ?"));
return; } else {
} is_default = FALSE;
active_ssid = NULL;
is_default = FALSE; for (i = 0; i < connections->len; i++) {
for (i = 0; i < connections->len; i++) { c = (NMActiveConnection *)connections->pdata[i];
c = (NMActiveConnection *)connections->pdata[i]; devices = nm_active_connection_get_devices (c);
devices = nm_active_connection_get_devices (c);
if (nm_active_connection_get_default (c)) {
if (devices->pdata[0] == device) { if (devices->pdata[0] == device) {
is_default = TRUE; ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (device));
active_ssid = nm_utils_ssid_to_utf8 (nm_access_point_get_ssid (ap));
is_default = nm_active_connection_get_default (c);
break;
} }
break; }
if (active_ssid != NULL) {
GString *str;
str = g_string_new ("");
g_string_append_printf (str, _("Disconnect from %s and create a new hotspot ?"), active_ssid);
if (is_default) {
g_string_append (str, "\n\n");
g_string_append (str, _("This is your only connection to the internet."));
}
warning = g_string_free (str, FALSE);
} }
} }
if (is_default) { if (warning != NULL) {
show_hotspot_confirmation_dialog (panel, GtkWidget *dialog;
_("Turning this device into a hotspot will drop your default connection to the internet.\n" GtkWidget *window;
"Start the hotspot anyway ?"));
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_OTHER,
GTK_BUTTONS_NONE,
warning);
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
_("Create _Hotspot"), GTK_RESPONSE_OK,
NULL);
g_signal_connect (dialog, "response",
G_CALLBACK (start_hotspot_response_cb), panel);
gtk_window_present (GTK_WINDOW (dialog));
return; return;
} }
/* if we get here, things look good to go ahead */ /* if we get here, things look good to go ahead */
create_shared_connection (panel); start_shared_connection (panel);
} }
static void static void
stop_hotspot (GtkButton *button, CcNetworkPanel *panel) stop_shared_connection (CcNetworkPanel *panel)
{ {
const GPtrArray *connections; const GPtrArray *connections;
const GPtrArray *devices; const GPtrArray *devices;
@ -2889,6 +2897,36 @@ stop_hotspot (GtkButton *button, CcNetworkPanel *panel)
refresh_ui (panel); refresh_ui (panel);
} }
static void
stop_hotspot_response_cb (GtkWidget *dialog, gint response, CcNetworkPanel *panel)
{
if (response == GTK_RESPONSE_OK) {
stop_shared_connection (panel);
}
gtk_widget_destroy (dialog);
}
static void
stop_hotspot (GtkButton *button, CcNetworkPanel *panel)
{
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_OTHER,
GTK_BUTTONS_NONE,
_("Stop hotspot and disconnect any users ?"));
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
_("_Stop Hotspot"), GTK_RESPONSE_OK,
NULL);
g_signal_connect (dialog, "response",
G_CALLBACK (stop_hotspot_response_cb), panel);
gtk_window_present (GTK_WINDOW (dialog));
}
static void static void
cc_network_panel_init (CcNetworkPanel *panel) cc_network_panel_init (CcNetworkPanel *panel)
{ {

View file

@ -1165,7 +1165,7 @@
</child> </child>
<child> <child>
<object class="GtkButton" id="stop_hotspot_button"> <object class="GtkButton" id="stop_hotspot_button">
<property name="label" translatable="yes">_Stop Hotspot</property> <property name="label" translatable="yes">_Stop Hotspot...</property>
<property name="halign">start</property> <property name="halign">start</property>
<property name="valign">end</property> <property name="valign">end</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>