Commit 75590abc authored by Lubomir Rintel's avatar Lubomir Rintel
Browse files

merge: branch 'lr/app-windows'

!5
parents f950868f 4cf6e615
Pipeline #16384 passed with stages
in 21 minutes and 34 seconds
......@@ -34,7 +34,6 @@ G_DEFINE_ABSTRACT_TYPE (CEPage, ce_page, G_TYPE_OBJECT)
enum {
PROP_0,
PROP_CONNECTION,
PROP_INITIALIZED,
PROP_PARENT_WINDOW,
LAST_PROP
......@@ -43,6 +42,7 @@ enum {
enum {
CHANGED,
INITIALIZED,
NEW_EDITOR,
LAST_SIGNAL
};
......@@ -660,13 +660,6 @@ ce_page_get_next_available_name (const GPtrArray *connections, const char *forma
return cname;
}
static void
emit_initialized (CEPage *self, GError *error)
{
self->initialized = TRUE;
g_signal_emit (self, signals[INITIALIZED], 0, error);
}
void
ce_page_complete_init (CEPage *self,
const char *setting_name,
......@@ -676,27 +669,29 @@ ce_page_complete_init (CEPage *self,
GError *update_error = NULL;
GVariant *setting_dict;
char *dbus_err;
gboolean ignore_error = FALSE;
g_return_if_fail (self != NULL);
g_return_if_fail (CE_IS_PAGE (self));
if (error) {
/* Ignore missing settings errors */
dbus_err = g_dbus_error_get_remote_error (error);
ignore_error = !g_strcmp0 (dbus_err, "org.freedesktop.NetworkManager.Settings.InvalidSetting")
|| !g_strcmp0 (dbus_err, "org.freedesktop.NetworkManager.Settings.Connection.SettingNotFound")
|| !g_strcmp0 (dbus_err, "org.freedesktop.NetworkManager.AgentManager.NoSecrets");
if ( g_strcmp0 (dbus_err, "org.freedesktop.NetworkManager.Settings.InvalidSetting") == 0
|| g_strcmp0 (dbus_err, "org.freedesktop.NetworkManager.Settings.Connection.SettingNotFound") == 0
|| g_strcmp0 (dbus_err, "org.freedesktop.NetworkManager.AgentManager.NoSecrets") == 0)
g_clear_error (&error);
g_free (dbus_err);
}
/* Ignore missing settings errors */
if (error && !ignore_error) {
emit_initialized (self, error);
return;
} else if (!setting_name || !secrets || g_variant_n_children (secrets) == 0) {
if (error) {
g_warning ("Couldn't fetch secrets: %s", error->message);
g_error_free (error);
goto out;
}
if (!setting_name || !secrets || g_variant_n_children (secrets) == 0) {
/* Success, no secrets */
emit_initialized (self, NULL);
return;
goto out;
}
g_assert (setting_name);
......@@ -705,28 +700,22 @@ ce_page_complete_init (CEPage *self,
setting_dict = g_variant_lookup_value (secrets, setting_name, NM_VARIANT_TYPE_SETTING);
if (!setting_dict) {
/* Success, no secrets */
emit_initialized (self, NULL);
return;
goto out;
}
g_variant_unref (setting_dict);
/* Update the connection with the new secrets */
if (nm_connection_update_secrets (self->connection,
if (!nm_connection_update_secrets (self->connection,
setting_name,
secrets,
&update_error)) {
/* Success */
emit_initialized (self, NULL);
return;
g_warning ("Couldn't update the secrets: %s", update_error->message);
g_error_free (update_error);
goto out;
}
if (!update_error) {
g_set_error_literal (&update_error, NMA_ERROR, NMA_ERROR_GENERIC,
_("Failed to update connection secrets due to an unknown error."));
}
emit_initialized (self, update_error);
g_clear_error (&update_error);
out:
g_signal_emit (self, signals[INITIALIZED], 0, NULL);
}
static void
......@@ -773,14 +762,6 @@ ce_page_get_title (CEPage *self)
return self->title;
}
gboolean
ce_page_get_initialized (CEPage *self)
{
g_return_val_if_fail (CE_IS_PAGE (self), FALSE);
return self->initialized;
}
void
ce_page_changed (CEPage *self)
{
......@@ -789,6 +770,25 @@ ce_page_changed (CEPage *self)
g_signal_emit (self, signals[CHANGED], 0);
}
NMConnectionEditor *
ce_page_new_editor (CEPage *self,
GtkWindow *parent_window,
NMConnection *connection)
{
NMConnectionEditor *editor;
g_return_val_if_fail (CE_IS_PAGE (self), NULL);
editor = nm_connection_editor_new (parent_window,
connection,
self->client);
if (!editor)
return NULL;
g_signal_emit (self, signals[NEW_EDITOR], 0, editor);
return editor;
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
......@@ -799,9 +799,6 @@ get_property (GObject *object, guint prop_id,
case PROP_CONNECTION:
g_value_set_object (value, self->connection);
break;
case PROP_INITIALIZED:
g_value_set_boolean (value, self->initialized);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -849,14 +846,6 @@ ce_page_class_init (CEPageClass *page_class)
NM_TYPE_CONNECTION,
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_INITIALIZED,
g_param_spec_boolean (CE_PAGE_INITIALIZED,
"Initialized",
"Initialized",
FALSE,
G_PARAM_READABLE));
g_object_class_install_property
(object_class, PROP_PARENT_WINDOW,
g_param_spec_pointer (CE_PAGE_PARENT_WINDOW,
......@@ -869,16 +858,21 @@ ce_page_class_init (CEPageClass *page_class)
g_signal_new ("changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (CEPageClass, changed),
NULL, NULL, NULL,
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
signals[INITIALIZED] =
g_signal_new ("initialized",
g_signal_new (CE_PAGE_INITIALIZED,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_POINTER);
signals[NEW_EDITOR] =
g_signal_new (CE_PAGE_NEW_EDITOR,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (CEPageClass, initialized),
NULL, NULL, NULL,
0, NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_POINTER);
}
......
......@@ -67,13 +67,15 @@ typedef void (*PageNewConnectionFunc) (FUNC_TAG_PAGE_NEW_CONNECTION_IMPL,
#define CE_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CE_TYPE_PAGE, CEPageClass))
#define CE_PAGE_CONNECTION "connection"
#define CE_PAGE_INITIALIZED "initialized"
#define CE_PAGE_PARENT_WINDOW "parent-window"
#define CE_PAGE_CHANGED "changed"
#define CE_PAGE_INITIALIZED "initialized"
#define CE_PAGE_NEW_EDITOR "new-editor"
typedef struct {
GObject parent;
gboolean initialized;
gboolean inter_page_change_running;
GtkBuilder *builder;
GtkWidget *page;
......@@ -94,10 +96,6 @@ typedef struct {
gboolean (*ce_page_validate_v) (CEPage *self, NMConnection *connection, GError **error);
gboolean (*last_update) (CEPage *self, NMConnection *connection, GError **error);
gboolean (*inter_page_change) (CEPage *self);
/* Signals */
void (*changed) (CEPage *self);
void (*initialized) (CEPage *self, GError *error);
} CEPageClass;
......@@ -155,6 +153,10 @@ gboolean ce_page_cloned_mac_combo_valid (GtkComboBoxText *combo, int type, const
void ce_page_changed (CEPage *self);
NMConnectionEditor *ce_page_new_editor (CEPage *self,
GtkWindow *parent_window,
NMConnection *connection);
void ce_spin_automatic_val (GtkSpinButton *spin, int defvalue);
void ce_spin_default_val (GtkSpinButton *spin, int defvalue);
......@@ -165,8 +167,6 @@ void ce_page_complete_init (CEPage *self,
GVariant *secrets,
GError *error);
gboolean ce_page_get_initialized (CEPage *self);
char *ce_page_get_next_available_name (const GPtrArray *connections, const char *format);
/* Only for subclasses */
......
......@@ -33,21 +33,12 @@
#include "connection-helpers.h"
#include "vpn-helpers.h"
#define CONNECTION_LIST_TAG "nm-connection-list"
gboolean nm_ce_keep_above;
/*************************************************/
static NMConnectionList *
_get_connection_list (GApplication *application)
{
GtkApplication *app = GTK_APPLICATION (application);
GList *windows = gtk_application_get_windows (app);
/* For now, assume we always have a single application window
* that is the connection list. */
return NM_CONNECTION_LIST (windows->data);
}
typedef struct {
gboolean create;
NMConnectionList *list;
......@@ -87,10 +78,9 @@ handle_arguments (GApplication *application,
gboolean create,
gboolean show,
const char *edit_uuid,
const char *import,
gboolean quit_after)
const char *import)
{
NMConnectionList *list = _get_connection_list (application);
NMConnectionList *list = g_object_get_data (G_OBJECT (application), CONNECTION_LIST_TAG);
gboolean show_list = TRUE;
GType ctype = 0;
gs_free char *type_tmp = NULL;
......@@ -145,13 +135,6 @@ handle_arguments (GApplication *application,
show_list = FALSE;
}
/* If only editing a single connection, exit when done with that connection */
if (show_list == FALSE && quit_after == TRUE) {
g_signal_connect_swapped (list, "editing-done",
G_CALLBACK (g_application_quit),
application);
}
return show_list;
}
......@@ -171,7 +154,7 @@ create_activated (GSimpleAction *action, GVariant *parameter, gpointer user_data
{
GApplication *application = G_APPLICATION (user_data);
handle_arguments (application, NULL, TRUE, FALSE, NULL, NULL, FALSE);
handle_arguments (application, NULL, TRUE, FALSE, NULL, NULL);
}
static void
......@@ -188,6 +171,25 @@ static GActionEntry app_entries[] =
{ "quit", quit_activated, NULL, NULL, NULL },
};
static void
new_editor_cb (NMConnectionList *list, NMConnectionEditor *new_editor, gpointer user_data)
{
GtkApplication *app = GTK_APPLICATION (user_data);
gtk_application_add_window (app, nm_connection_editor_get_window (new_editor));
}
static void
list_visible_cb (NMConnectionList *list, GParamSpec *pspec, gpointer user_data)
{
GtkApplication *app = GTK_APPLICATION (user_data);
if (gtk_widget_get_visible (GTK_WIDGET (list)))
gtk_application_add_window (app, GTK_WINDOW (list));
else
gtk_application_remove_window (app, GTK_WINDOW (list));
}
static void
editor_startup (GApplication *application, gpointer user_data)
{
......@@ -203,13 +205,17 @@ editor_startup (GApplication *application, gpointer user_data)
g_application_quit (application);
return;
}
gtk_application_add_window (app, GTK_WINDOW (list));
g_object_set_data_full (G_OBJECT (application), CONNECTION_LIST_TAG, g_object_ref (list), g_object_unref);
g_signal_connect_object (list, NM_CONNECTION_LIST_NEW_EDITOR, G_CALLBACK (new_editor_cb), application, 0);
g_signal_connect_object (list, "notify::visible", G_CALLBACK (list_visible_cb), application, 0);
g_signal_connect (list, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), NULL);
}
static void
editor_activate (GApplication *application, gpointer user_data)
{
NMConnectionList *list = _get_connection_list (application);
NMConnectionList *list = g_object_get_data (G_OBJECT (application), CONNECTION_LIST_TAG);
nm_connection_list_present (list);
}
......@@ -224,7 +230,7 @@ editor_command_line (GApplication *application,
GOptionContext *opt_ctx = NULL;
GError *error = NULL;
gs_free char *type = NULL, *uuid = NULL, *import = NULL;
gboolean create = FALSE, show = FALSE, keepabove = FALSE;
gboolean create = FALSE, show = FALSE;
int ret = 1;
GOptionEntry entries[] = {
{ "type", 't', 0, G_OPTION_ARG_STRING, &type, "Type of connection to show or create", NM_SETTING_WIRED_SETTING_NAME },
......@@ -232,10 +238,6 @@ editor_command_line (GApplication *application,
{ "show", 's', 0, G_OPTION_ARG_NONE, &show, "Show a given connection type page", NULL },
{ "edit", 'e', 0, G_OPTION_ARG_STRING, &uuid, "Edit an existing connection with a given UUID", "UUID" },
{ "import", 'i', 0, G_OPTION_ARG_STRING, &import, "Import a VPN connection from given file", NULL },
/* handled in main but may be passed through here, so we need
* to parse and ignore it
*/
{ "keep-above", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &keepabove, NULL, NULL },
{ NULL }
};
......@@ -256,7 +258,7 @@ editor_command_line (GApplication *application,
type = g_strdup (NM_SETTING_GSM_SETTING_NAME);
}
if (handle_arguments (application, type, create, show, uuid, import, FALSE))
if (handle_arguments (application, type, create, show, uuid, import))
g_application_activate (application);
ret = 0;
......@@ -286,6 +288,7 @@ main (int argc, char *argv[])
opt_ctx = g_option_context_new (NULL);
g_option_context_add_main_entries (opt_ctx, entries, NULL);
g_option_context_set_ignore_unknown_options (opt_ctx, TRUE);
g_option_context_parse (opt_ctx, &argc, &argv, NULL);
g_option_context_free (opt_ctx);
......
......@@ -72,6 +72,7 @@ G_DEFINE_TYPE (NMConnectionEditor, nm_connection_editor, G_TYPE_OBJECT)
enum {
EDITOR_DONE,
NEW_EDITOR,
EDITOR_LAST_SIGNAL
};
......@@ -538,12 +539,18 @@ nm_connection_editor_class_init (NMConnectionEditorClass *klass)
/* Signals */
editor_signals[EDITOR_DONE] =
g_signal_new ("done",
g_signal_new (NM_CONNECTION_EDITOR_DONE,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMConnectionEditorClass, done),
NULL, NULL, NULL,
0, NULL, NULL, NULL,
G_TYPE_NONE, 1, GTK_TYPE_RESPONSE_TYPE);
editor_signals[NEW_EDITOR] =
g_signal_new (NM_CONNECTION_EDITOR_NEW_EDITOR,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_POINTER);
}
NMConnectionEditor *
......@@ -789,6 +796,14 @@ page_initialized (CEPage *page, GError *error, gpointer user_data)
recheck_initialization (editor);
}
static void
page_new_editor (CEPage *page, NMConnectionEditor *new_editor, gpointer user_data)
{
NMConnectionEditor *self = NM_CONNECTION_EDITOR (user_data);
g_signal_emit (self, editor_signals[NEW_EDITOR], 0, new_editor);
}
static void request_secrets (GetSecretsInfo *info);
static void
......@@ -897,8 +912,9 @@ add_page (NMConnectionEditor *editor,
GINT_TO_POINTER (g_slist_length (editor->initializing_pages)));
editor->initializing_pages = g_slist_append (editor->initializing_pages, page);
g_signal_connect (page, "changed", G_CALLBACK (page_changed), editor);
g_signal_connect (page, "initialized", G_CALLBACK (page_initialized), editor);
g_signal_connect (page, CE_PAGE_CHANGED, G_CALLBACK (page_changed), editor);
g_signal_connect (page, CE_PAGE_INITIALIZED, G_CALLBACK (page_initialized), editor);
g_signal_connect (page, CE_PAGE_NEW_EDITOR, G_CALLBACK (page_new_editor), editor);
}
return !!page;
}
......
......@@ -32,6 +32,9 @@
#define NM_IS_CONNECTION_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CONNECTION_EDITOR))
#define NM_CONNECTION_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONNECTION_EDITOR, NMConnectionEditor))
#define NM_CONNECTION_EDITOR_DONE "done"
#define NM_CONNECTION_EDITOR_NEW_EDITOR "new-editor"
typedef struct GetSecretsInfo GetSecretsInfo;
typedef struct {
......@@ -77,9 +80,6 @@ typedef struct {
typedef struct {
GObjectClass parent_class;
/* Signals */
void (*done) (NMConnectionEditor *editor, gint result, GError *error);
} NMConnectionEditorClass;
typedef enum {
......
......@@ -38,8 +38,7 @@
extern gboolean nm_ce_keep_above;
enum {
LIST_DONE,
EDITING_DONE,
NEW_EDITOR,
LIST_LAST_SIGNAL
};
......@@ -286,7 +285,14 @@ add_response_cb (NMConnectionEditor *editor, GtkResponseType response, gpointer
delete_slaves_of_connection (list, nm_connection_editor_get_connection (editor));
g_object_unref (editor);
g_signal_emit (list, list_signals[EDITING_DONE], 0, 0);
}
static void
new_editor_cb (NMConnectionEditor *editor, NMConnectionEditor *new_editor, gpointer user_data)
{
NMConnectionList *list = user_data;
g_signal_emit (list, list_signals[NEW_EDITOR], 0, new_editor);
}
static void
......@@ -298,10 +304,8 @@ really_add_connection (FUNC_TAG_NEW_CONNECTION_RESULT_IMPL,
NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
NMConnectionEditor *editor;
if (!connection) {
g_signal_emit (list, list_signals[EDITING_DONE], 0, 0);
if (!connection)
return;
}
if (connection_supports_proxy (connection) && !nm_connection_get_setting_proxy (connection))
nm_connection_add_setting (connection, nm_setting_proxy_new ());
......@@ -311,12 +315,13 @@ really_add_connection (FUNC_TAG_NEW_CONNECTION_RESULT_IMPL,
nm_connection_add_setting (connection, nm_setting_ip6_config_new ());
editor = nm_connection_editor_new (GTK_WINDOW (list), connection, priv->client);
if (!editor) {
g_signal_emit (list, list_signals[EDITING_DONE], 0, 0);
if (!editor)
return;
}
g_signal_connect (editor, "done", G_CALLBACK (add_response_cb), list);
g_signal_connect (editor, NM_CONNECTION_EDITOR_DONE, G_CALLBACK (add_response_cb), list);
g_signal_connect (editor, NM_CONNECTION_EDITOR_NEW_EDITOR, G_CALLBACK (new_editor_cb), list);
g_signal_emit (list, list_signals[NEW_EDITOR], 0, editor);
nm_connection_editor_run (editor);
}
......@@ -355,7 +360,6 @@ edit_done_cb (NMConnectionEditor *editor, GtkResponseType response, gpointer use
}
g_object_unref (editor);
g_signal_emit (list, list_signals[EDITING_DONE], 0, 0);
}
static void
......@@ -376,10 +380,14 @@ edit_connection (NMConnectionList *list, NMConnection *connection)
editor = nm_connection_editor_new (GTK_WINDOW (list),
NM_CONNECTION (connection),
priv->client);
if (editor) {
g_signal_connect (editor, "done", G_CALLBACK (edit_done_cb), list);
nm_connection_editor_run (editor);
}
if (!editor)
return;
g_signal_connect (editor, NM_CONNECTION_EDITOR_DONE, G_CALLBACK (edit_done_cb), list);
g_signal_connect (editor, NM_CONNECTION_EDITOR_NEW_EDITOR, G_CALLBACK (new_editor_cb), list);
g_signal_emit (list, list_signals[NEW_EDITOR], 0, editor);
nm_connection_editor_run (editor);
}
static void
......@@ -449,15 +457,6 @@ selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
}
}
static void
list_close_cb (GtkDialog *dialog, gpointer user_data)
{
g_signal_emit (NM_CONNECTION_LIST (user_data),
list_signals[LIST_DONE],
0,
GTK_RESPONSE_CLOSE);
}
static gboolean
key_press_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
......@@ -527,21 +526,12 @@ nm_connection_list_class_init (NMConnectionListClass *klass)
object_class->dispose = dispose;
/* Signals */
list_signals[LIST_DONE] =
g_signal_new ("done",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMConnectionListClass, done),
NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_INT);
list_signals[EDITING_DONE] =
g_signal_new ("editing-done",
list_signals[NEW_EDITOR] =
g_signal_new (NM_CONNECTION_LIST_NEW_EDITOR,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMConnectionListClass, done),
NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_INT);
0, NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_POINTER);
/* Initialize the widget template */
gtk_widget_class_set_template_from_resource (widget_class,
......@@ -557,7 +547,6 @@ nm_connection_list_class_init (NMConnectionListClass *klass)
gtk_widget_class_bind_template_callback (widget_class, add_clicked);
gtk_widget_class_bind_template_callback (widget_class, do_edit);
gtk_widget_class_bind_template_callback (widget_class, delete_clicked);
gtk_widget_class_bind_template_callback (widget_class, list_close_cb);
gtk_widget_class_bind_template_callback (widget_class, selection_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, key_press_cb);
gtk_widget_class_bind_template_callback (widget_class, start_search);
......
......@@ -30,10 +30,14 @@
#include <NetworkManager.h>
#include "nm-connection-editor.h"
#define NM_TYPE_CONNECTION_LIST (nm_connection_list_get_type ())
#define NM_IS_CONNECTION_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CONNECTION_LIST))
#define NM_CONNECTION_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONNECTION_LIST, NMConnectionList))
#define NM_CONNECTION_LIST_NEW_EDITOR "new-editor"
typedef struct _NMConnectionListPrivate NMConnectionListPrivate;
typedef struct {
......@@ -42,10 +46,6 @@ typedef struct {
typedef struct {
GtkApplicationWindowClass parent_class;
/* Signals */