Commit 941ce352 authored by Dan Winship's avatar Dan Winship

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).
parent bbc6434e
......@@ -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 ();
}
......@@ -21,7 +21,7 @@
G_BEGIN_DECLS
void nmtui_connect (int argc, char **argv);
NmtNewtForm *nmtui_connect (int argc, char **argv);
G_END_DECLS
......
......@@ -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 ();
}
......@@ -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,
......
......@@ -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;
}
......@@ -21,7 +21,7 @@
G_BEGIN_DECLS
void nmtui_hostname (int argc, char **argv);
NmtNewtForm *nmtui_hostname (int argc, char **argv);
G_END_DECLS
......
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment