summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-03-05 12:48:43 -0500
committerDan Winship <danw@gnome.org>2014-03-21 13:32:50 -0400
commit941ce3523893e8083da650a5b1e59c78097d3718 (patch)
tree786b80eb0d1cbe04ecdc07bbde44dc52484c854e
parentbbc6434e96b013740df4d3ef35ccf988f20afe0a (diff)
downloadNetworkManager-941ce3523893e8083da650a5b1e59c78097d3718.tar.gz
tui: fix quitting from "nmtui edit CONN-ID"
If you launched nmtui directly into the editor for a specific connection, it would hang with a blank screen when you quit. Fix this by changing the way startup works a bit, and have the created toplevel NmtNewtForm get returned all the way to nmtui.c, which can then connect to the "quit" signal on it and quit (rather than having the different subprograms trying to guess whether they're supposed to quit-on-exit or not).
-rw-r--r--tui/nmtui-connect.c23
-rw-r--r--tui/nmtui-connect.h2
-rw-r--r--tui/nmtui-edit.c22
-rw-r--r--tui/nmtui-edit.h2
-rw-r--r--tui/nmtui-hostname.c4
-rw-r--r--tui/nmtui-hostname.h2
-rw-r--r--tui/nmtui.c26
7 files changed, 40 insertions, 41 deletions
diff --git a/tui/nmtui-connect.c b/tui/nmtui-connect.c
index b889815978..a6a4e96ba8 100644
--- a/tui/nmtui-connect.c
+++ b/tui/nmtui-connect.c
@@ -236,14 +236,7 @@ listbox_active_changed (GObject *object,
}
}
-static void
-form_quit (NmtNewtForm *form,
- gpointer user_data)
-{
- nmtui_quit ();
-}
-
-static void
+static NmtNewtForm *
nmt_connect_connection_list (void)
{
int screen_width, screen_height;
@@ -257,7 +250,6 @@ nmt_connect_connection_list (void)
"height", screen_height - 4,
"escape-exits", TRUE,
NULL);
- g_signal_connect (form, "quit", G_CALLBACK (form_quit), NULL);
grid = nmt_newt_grid_new ();
@@ -281,11 +273,10 @@ nmt_connect_connection_list (void)
nmt_newt_widget_set_exit_on_activate (quit, TRUE);
nmt_newt_form_set_content (form, grid);
- nmt_newt_form_show (form);
- g_object_unref (form);
+ return form;
}
-static void
+static NmtNewtForm *
nmt_connect_connection (const char *identifier)
{
NmtNewtWidget *list;
@@ -308,14 +299,14 @@ nmt_connect_connection (const char *identifier)
activate_connection (connection, device, specific_object);
g_object_unref (list);
- nmtui_quit ();
+ return NULL;
}
-void
+NmtNewtForm *
nmtui_connect (int argc, char **argv)
{
if (argc == 2)
- nmt_connect_connection (argv[1]);
+ return nmt_connect_connection (argv[1]);
else
- nmt_connect_connection_list ();
+ return nmt_connect_connection_list ();
}
diff --git a/tui/nmtui-connect.h b/tui/nmtui-connect.h
index 818b860ed6..8310ac389a 100644
--- a/tui/nmtui-connect.h
+++ b/tui/nmtui-connect.h
@@ -21,7 +21,7 @@
G_BEGIN_DECLS
-void nmtui_connect (int argc, char **argv);
+NmtNewtForm *nmtui_connect (int argc, char **argv);
G_END_DECLS
diff --git a/tui/nmtui-edit.c b/tui/nmtui-edit.c
index 34e51a684c..2a17b45405 100644
--- a/tui/nmtui-edit.c
+++ b/tui/nmtui-edit.c
@@ -77,14 +77,7 @@ edit_connection_list_filter (NmtEditConnectionList *list,
return (nm_setting_connection_get_slave_type (s_con) == NULL);
}
-static void
-form_quit (NmtNewtForm *form,
- gpointer user_data)
-{
- nmtui_quit ();
-}
-
-static void
+static NmtNewtForm *
nmt_edit_main_connection_list (void)
{
int screen_width, screen_height;
@@ -98,7 +91,6 @@ nmt_edit_main_connection_list (void)
"height", screen_height - 4,
"escape-exits", TRUE,
NULL);
- g_signal_connect (form, "quit", G_CALLBACK (form_quit), NULL);
quit = nmt_newt_button_new (_("Quit"));
nmt_newt_widget_set_exit_on_activate (quit, TRUE);
@@ -116,8 +108,7 @@ nmt_edit_main_connection_list (void)
G_CALLBACK (list_remove_connection), form);
nmt_newt_form_set_content (form, list);
- nmt_newt_form_show (form);
- g_object_unref (form);
+ return form;
}
#define NMT_TYPE_ADD_CONNECTION (nmt_add_connection_get_type ())
@@ -492,7 +483,7 @@ nmt_remove_connection (NMRemoteConnection *connection)
g_object_unref (connection);
}
-void
+NmtNewtForm *
nmtui_edit (int argc, char **argv)
{
NMConnection *conn = NULL;
@@ -505,11 +496,10 @@ nmtui_edit (int argc, char **argv)
if (!conn) {
nmt_newt_message_dialog ("%s: no such connection '%s'\n", argv[0], argv[1]);
- nmtui_quit ();
- return;
+ return NULL;
}
- nmt_edit_connection (conn);
+ return nmt_editor_new (conn);
} else
- nmt_edit_main_connection_list ();
+ return nmt_edit_main_connection_list ();
}
diff --git a/tui/nmtui-edit.h b/tui/nmtui-edit.h
index a28c8a6f4f..dae91cfac7 100644
--- a/tui/nmtui-edit.h
+++ b/tui/nmtui-edit.h
@@ -26,7 +26,7 @@ G_BEGIN_DECLS
typedef gboolean (*NmtAddConnectionTypeFilter) (GType connection_type,
gpointer user_data);
-void nmtui_edit (int argc, char **argv);
+NmtNewtForm *nmtui_edit (int argc, char **argv);
void nmt_add_connection (void);
void nmt_add_connection_full (const char *primary_text,
diff --git a/tui/nmtui-hostname.c b/tui/nmtui-hostname.c
index b600d4e447..7c8aff3a85 100644
--- a/tui/nmtui-hostname.c
+++ b/tui/nmtui-hostname.c
@@ -93,7 +93,7 @@ hostname_set (NMRemoteSettings *settings,
nmt_sync_op_complete_boolean (op, error == NULL, error);
}
-void
+NmtNewtForm *
nmtui_hostname (int argc, char **argv)
{
const char *hostname;
@@ -120,5 +120,5 @@ nmtui_hostname (int argc, char **argv)
g_free (tmp);
}
- nmtui_quit ();
+ return NULL;
}
diff --git a/tui/nmtui-hostname.h b/tui/nmtui-hostname.h
index 921b231b2f..a14bc69937 100644
--- a/tui/nmtui-hostname.h
+++ b/tui/nmtui-hostname.h
@@ -21,7 +21,7 @@
G_BEGIN_DECLS
-void nmtui_hostname (int argc, char **argv);
+NmtNewtForm *nmtui_hostname (int argc, char **argv);
G_END_DECLS
diff --git a/tui/nmtui.c b/tui/nmtui.c
index eff99f7d04..2c1a75df30 100644
--- a/tui/nmtui.c
+++ b/tui/nmtui.c
@@ -49,7 +49,7 @@ NMClient *nm_client;
NMRemoteSettings *nm_settings;
static GMainLoop *loop;
-typedef void (*NmtuiSubprogram) (int argc, char **argv);
+typedef NmtNewtForm * (*NmtuiSubprogram) (int argc, char **argv);
static const struct {
const char *name, *shortcut, *arg;
@@ -74,7 +74,7 @@ quit_func (int argc, char **argv)
nmtui_quit ();
}
-static void
+static NmtNewtForm *
nmtui_main (int argc, char **argv)
{
NmtNewtForm *form;
@@ -124,7 +124,10 @@ nmtui_main (int argc, char **argv)
subprogram = nmt_newt_listbox_get_active_key (listbox);
g_object_unref (form);
- subprogram (argc, argv);
+ if (subprogram)
+ return subprogram (argc, argv);
+ else
+ return NULL;
}
/**
@@ -177,12 +180,27 @@ typedef struct {
char **argv;
} NmtuiStartupData;
+static void
+toplevel_form_quit (NmtNewtForm *form,
+ gpointer user_data)
+{
+ nmtui_quit ();
+}
+
static gboolean
idle_run_subprogram (gpointer user_data)
{
NmtuiStartupData *data = user_data;
+ NmtNewtForm *form;
+
+ form = data->subprogram (data->argc, data->argv);
+ if (form) {
+ g_signal_connect (form, "quit", G_CALLBACK (toplevel_form_quit), NULL);
+ nmt_newt_form_show (form);
+ g_object_unref (form);
+ } else
+ nmtui_quit ();
- data->subprogram (data->argc, data->argv);
return FALSE;
}