Commit 4d7546e7 authored by Dan Winship's avatar Dan Winship Committed by Dan Williams

connection-editor: port to libnm

Based on a patch by Jiří Klimeš.
parent 05bfc5d3
......@@ -2,8 +2,8 @@ bin_PROGRAMS = nm-connection-editor
nm_connection_editor_CPPFLAGS = \
$(GTK_CFLAGS) \
$(NMA_CFLAGS) \
-DLIBNM_GLIB_BUILD \
$(LIBNM_CFLAGS) \
-DLIBNM_BUILD \
-DNM_VERSION_MIN_REQUIRED=NM_VERSION_0_9_10 \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_0_9_10 \
-DICONDIR=\""$(datadir)/icons"\" \
......@@ -16,7 +16,7 @@ nm_connection_editor_CPPFLAGS = \
$(DBUS_GLIB_CFLAGS) \
-I${top_srcdir}/src/utils \
-I${top_srcdir}/src/wireless-security \
-I${top_srcdir}/src/libnm-gtk
-I${top_srcdir}/src/libnma
nm_connection_editor_SOURCES = \
nm-connection-editor.c \
......@@ -87,12 +87,12 @@ nm-connection-editor-service-glue.h: $(top_srcdir)/src/connection-editor/nm-conn
$(AM_V_GEN) dbus-binding-tool --prefix=nm_connection_editor_service --mode=glib-server --output=$@ $<
nm_connection_editor_LDADD = \
${top_builddir}/src/wireless-security/libwireless-security-libnm-glib.la \
${top_builddir}/src/utils/libutils-libnm-glib.la \
${top_builddir}/src/libnm-gtk/libnm-gtk.la \
${top_builddir}/src/wireless-security/libwireless-security-libnm.la \
${top_builddir}/src/utils/libutils-libnm.la \
${top_builddir}/src/libnma/libnma.la \
$(GTK_LIBS) \
$(NMA_LIBS) \
$(DBUS_GLIB_LIBS) \
$(LIBNM_LIBS) \
-lm
uidir = $(datadir)/nm-applet
......
......@@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2008 - 2011 Red Hat, Inc.
* Copyright 2008 - 2014 Red Hat, Inc.
*/
#include <config.h>
......@@ -29,9 +29,6 @@
#include <glib/gi18n.h>
#include <nm-setting-connection.h>
#include <nm-utils.h>
#include "ce-page.h"
G_DEFINE_ABSTRACT_TYPE (CEPage, ce_page, G_TYPE_OBJECT)
......@@ -151,7 +148,7 @@ ce_page_get_mac_list (CEPage *self, GType device_type, const char *mac_property)
macs = g_ptr_array_new ();
devices = nm_client_get_devices (self->client);
for (i = 0; devices && (i < devices->len); i++) {
for (i = 0; i < devices->len; i++) {
NMDevice *dev = g_ptr_array_index (devices, i);
const char *iface;
char *mac, *item;
......@@ -207,31 +204,11 @@ ce_page_setup_mac_combo (CEPage *self, GtkComboBox *combo,
}
}
void
ce_page_mac_to_entry (const GByteArray *mac, int type, GtkEntry *entry)
{
char *str_addr;
g_return_if_fail (entry != NULL);
g_return_if_fail (GTK_IS_ENTRY (entry));
if (!mac || !mac->len)
return;
if (mac->len != nm_utils_hwaddr_len (type))
return;
str_addr = nm_utils_hwaddr_ntoa (mac->data, type);
gtk_entry_set_text (entry, str_addr);
g_free (str_addr);
}
GByteArray *
char *
ce_page_entry_to_mac (GtkEntry *entry, int type, gboolean *invalid)
{
const char *temp, *sp;
char *buf = NULL;
GByteArray *mac;
const char *sp, *temp;
char *mac;
g_return_val_if_fail (entry != NULL, NULL);
g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
......@@ -240,48 +217,41 @@ ce_page_entry_to_mac (GtkEntry *entry, int type, gboolean *invalid)
g_return_val_if_fail (*invalid == FALSE, NULL);
temp = gtk_entry_get_text (entry);
if (!temp || !strlen (temp))
if (!temp || !*temp)
return NULL;
sp = strchr (temp, ' ');
if (sp)
temp = buf = g_strndup (temp, sp - temp);
mac = nm_utils_hwaddr_atoba (temp, type);
g_free (buf);
if (!mac) {
if (invalid)
*invalid = TRUE;
return NULL;
}
mac = g_strndup (temp, sp - temp);
else
mac = g_strdup (temp);
if (type == ARPHRD_ETHER && !utils_ether_addr_valid ((struct ether_addr *)mac->data)) {
g_byte_array_free (mac, TRUE);
if (!nm_utils_hwaddr_valid (mac, nm_utils_hwaddr_len (type))) {
g_free (mac);
if (invalid)
*invalid = TRUE;
return NULL;
}
return mac;
}
char *
ce_page_get_next_available_name (GSList *connections, const char *format)
ce_page_get_next_available_name (const GPtrArray *connections, const char *format)
{
GSList *names = NULL, *iter;
char *cname = NULL;
int i = 0;
for (iter = connections; iter; iter = g_slist_next (iter)) {
for (i = 0; i < connections->len; i++) {
const char *id;
id = nm_connection_get_id (NM_CONNECTION (iter->data));
id = nm_connection_get_id (connections->pdata[i]);
g_assert (id);
names = g_slist_append (names, (gpointer) id);
}
/* Find the next available unique connection name */
while (!cname && (i++ < 10000)) {
for (i = 1; !cname && i < 10000; i++) {
char *temp;
gboolean found = FALSE;
......@@ -312,23 +282,30 @@ emit_initialized (CEPage *self, GError *error)
void
ce_page_complete_init (CEPage *self,
const char *setting_name,
GHashTable *secrets,
GVariant *secrets,
GError *error)
{
GError *update_error = NULL;
GHashTable *setting_hash;
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) {
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");
g_free (dbus_err);
}
/* Ignore missing settings errors */
if ( error
&& !dbus_g_error_has_name (error, "org.freedesktop.NetworkManager.Settings.InvalidSetting")
&& !dbus_g_error_has_name (error, "org.freedesktop.NetworkManager.Settings.Connection.SettingNotFound")
&& !dbus_g_error_has_name (error, "org.freedesktop.NetworkManager.AgentManager.NoSecrets")) {
if (error && !ignore_error) {
emit_initialized (self, error);
return;
} else if (!setting_name || !secrets || !g_hash_table_size (secrets)) {
} else if (!setting_name || !secrets || g_variant_n_children (secrets) == 0) {
/* Success, no secrets */
emit_initialized (self, NULL);
return;
......@@ -337,12 +314,13 @@ ce_page_complete_init (CEPage *self,
g_assert (setting_name);
g_assert (secrets);
setting_hash = g_hash_table_lookup (secrets, setting_name);
if (!setting_hash) {
setting_dict = g_variant_lookup_value (secrets, setting_name, NM_VARIANT_TYPE_SETTING);
if (!setting_dict) {
/* Success, no secrets */
emit_initialized (self, NULL);
return;
}
g_variant_unref (setting_dict);
/* Update the connection with the new secrets */
if (nm_connection_update_secrets (self->connection,
......@@ -376,7 +354,6 @@ dispose (GObject *object)
g_clear_object (&self->page);
g_clear_object (&self->builder);
g_clear_object (&self->proxy);
g_clear_object (&self->connection);
G_OBJECT_CLASS (ce_page_parent_class)->dispose (object);
......@@ -522,24 +499,23 @@ NMConnection *
ce_page_new_connection (const char *format,
const char *ctype,
gboolean autoconnect,
NMRemoteSettings *settings,
NMClient *client,
gpointer user_data)
{
NMConnection *connection;
NMSettingConnection *s_con;
char *uuid, *id;
GSList *connections;
const GPtrArray *connections;
connection = nm_connection_new ();
connection = nm_simple_connection_new ();
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
nm_connection_add_setting (connection, NM_SETTING (s_con));
uuid = nm_utils_uuid_generate ();
connections = nm_remote_settings_list_connections (settings);
connections = nm_client_get_connections (client);
id = ce_page_get_next_available_name (connections, format);
g_slist_free (connections);
g_object_set (s_con,
NM_SETTING_CONNECTION_UUID, uuid,
......@@ -559,7 +535,6 @@ ce_page_new (GType page_type,
NMConnection *connection,
GtkWindow *parent_window,
NMClient *client,
NMRemoteSettings *settings,
const char *ui_file,
const char *widget_name,
const char *title)
......@@ -577,7 +552,6 @@ ce_page_new (GType page_type,
NULL));
self->title = g_strdup (title);
self->client = client;
self->settings = settings;
if (ui_file) {
if (!gtk_builder_add_from_file (self->builder, ui_file, &error)) {
......
......@@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2008 - 2012 Red Hat, Inc.
* Copyright 2008 - 2014 Red Hat, Inc.
*/
#ifndef __CE_PAGE_H__
......@@ -28,10 +28,8 @@
#include <gtk/gtk.h>
#include <dbus/dbus-glib.h>
#include <nm-connection.h>
#include <nm-client.h>
#include <nm-remote-settings.h>
#include <NetworkManager.h>
#include "utils.h"
/* for ARPHRD_ETHER / ARPHRD_INFINIBAND for MAC utilies */
......@@ -46,7 +44,7 @@ typedef GSList * (*PageGetConnectionsFunc) (gpointer user_data);
typedef void (*PageNewConnectionFunc) (GtkWindow *parent,
const char *detail,
NMRemoteSettings *settings,
NMClient *client,
PageNewConnectionResultFunc result_func,
gpointer user_data);
......@@ -69,13 +67,11 @@ typedef struct {
GtkWidget *page;
char *title;
DBusGProxy *proxy;
gulong secrets_done_validate;
NMConnection *connection;
GtkWindow *parent_window;
NMClient *client;
NMRemoteSettings *settings;
} CEPage;
typedef struct {
......@@ -93,7 +89,6 @@ typedef struct {
typedef CEPage* (*CEPageNewFunc)(NMConnection *connection,
GtkWindow *parent,
NMClient *client,
NMRemoteSettings *settings,
const char **out_secrets_setting_name,
GError **error);
......@@ -112,9 +107,7 @@ void ce_page_setup_mac_combo (CEPage *self, GtkComboBox *combo,
void ce_page_changed (CEPage *self);
void ce_page_mac_to_entry (const GByteArray *mac, int type, GtkEntry *entry);
GByteArray *ce_page_entry_to_mac (GtkEntry *entry, int type, gboolean *invalid);
char *ce_page_entry_to_mac (GtkEntry *entry, int type, gboolean *invalid);
gboolean ce_spin_output_with_automatic (GtkSpinButton *spin, gpointer user_data);
......@@ -124,25 +117,24 @@ int ce_get_property_default (NMSetting *setting, const char *property_name);
void ce_page_complete_init (CEPage *self,
const char *setting_name,
GHashTable *secrets,
GVariant *secrets,
GError *error);
gboolean ce_page_get_initialized (CEPage *self);
char *ce_page_get_next_available_name (GSList *connections, const char *format);
char *ce_page_get_next_available_name (const GPtrArray *connections, const char *format);
/* Only for subclasses */
NMConnection *ce_page_new_connection (const char *format,
const char *ctype,
gboolean autoconnect,
NMRemoteSettings *settings,
NMClient *client,
gpointer user_data);
CEPage *ce_page_new (GType page_type,
NMConnection *connection,
GtkWindow *parent_window,
NMClient *client,
NMRemoteSettings *settings,
const char *ui_file,
const char *widget_name,
const char *title);
......
......@@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2009 Red Hat, Inc.
* Copyright 2009 - 2014 Red Hat, Inc.
*/
#include <string.h>
......
......@@ -17,7 +17,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2009 - 2012 Red Hat, Inc.
* Copyright 2009 - 2014444 Red Hat, Inc.
*/
#ifndef __CE_POLKIT_BUTTON_H__
......@@ -25,7 +25,7 @@
#include <gtk/gtk.h>
#include <nm-client.h>
#include <NetworkManager.h>
#define CE_TYPE_POLKIT_BUTTON (ce_polkit_button_get_type ())
#define CE_POLKIT_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CE_TYPE_POLKIT_BUTTON, CEPolkitButton))
......
......@@ -48,13 +48,13 @@ static GSList *vpn_plugins;
static gint
sort_vpn_plugins (gconstpointer a, gconstpointer b)
{
NMVpnPluginUiInterface *aa = NM_VPN_PLUGIN_UI_INTERFACE (a);
NMVpnPluginUiInterface *bb = NM_VPN_PLUGIN_UI_INTERFACE (b);
NMVpnEditorPlugin *aa = NM_VPN_EDITOR_PLUGIN (a);
NMVpnEditorPlugin *bb = NM_VPN_EDITOR_PLUGIN (b);
char *aa_desc = NULL, *bb_desc = NULL;
int ret;
g_object_get (aa, NM_VPN_PLUGIN_UI_INTERFACE_NAME, &aa_desc, NULL);
g_object_get (bb, NM_VPN_PLUGIN_UI_INTERFACE_NAME, &bb_desc, NULL);
g_object_get (aa, NM_VPN_EDITOR_PLUGIN_NAME, &aa_desc, NULL);
g_object_get (bb, NM_VPN_EDITOR_PLUGIN_NAME, &bb_desc, NULL);
ret = g_strcmp0 (aa_desc, bb_desc);
......@@ -180,7 +180,7 @@ combo_changed_cb (GtkComboBox *combo, gpointer user_data)
GtkLabel *label = GTK_LABEL (user_data);
GtkTreeModel *model;
GtkTreeIter iter;
NMVpnPluginUiInterface *plugin = NULL;
NMVpnEditorPlugin *plugin = NULL;
char *description, *markup;
if (!gtk_combo_box_get_active_iter (combo, &iter))
......@@ -194,7 +194,7 @@ combo_changed_cb (GtkComboBox *combo, gpointer user_data)
if (!plugin)
goto error;
g_object_get (G_OBJECT (plugin), NM_VPN_PLUGIN_UI_INTERFACE_DESC, &description, NULL);
g_object_get (G_OBJECT (plugin), NM_VPN_EDITOR_PLUGIN_DESCRIPTION, &description, NULL);
g_object_unref (plugin);
if (!description)
goto error;
......@@ -293,10 +293,10 @@ set_up_connection_type_combo (GtkComboBox *combo,
}
for (p = vpn_plugins; p; p = p->next) {
NMVpnPluginUiInterface *plugin = NM_VPN_PLUGIN_UI_INTERFACE (p->data);
NMVpnEditorPlugin *plugin = NM_VPN_EDITOR_PLUGIN (p->data);
char *desc;
g_object_get (plugin, NM_VPN_PLUGIN_UI_INTERFACE_NAME, &desc, NULL);
g_object_get (plugin, NM_VPN_EDITOR_PLUGIN_NAME, &desc, NULL);
if (show_headers)
markup = g_markup_printf_escaped (" %s", desc);
......@@ -312,7 +312,7 @@ set_up_connection_type_combo (GtkComboBox *combo,
g_free (markup);
g_free (desc);
if (nm_vpn_plugin_ui_interface_get_capabilities (plugin) & NM_VPN_PLUGIN_UI_CAPABILITY_IMPORT)
if (nm_vpn_editor_plugin_get_capabilities (plugin) & NM_VPN_EDITOR_PLUGIN_CAPABILITY_IMPORT)
import_supported = TRUE;
}
......@@ -338,7 +338,7 @@ set_up_connection_type_combo (GtkComboBox *combo,
typedef struct {
GtkWindow *parent_window;
NMRemoteSettings *settings;
NMClient *client;
NewConnectionResultFunc result_func;
gpointer user_data;
} NewConnectionData;
......@@ -372,7 +372,7 @@ new_connection_result (NMConnection *connection,
void
new_connection_of_type (GtkWindow *parent_window,
const char *detail,
NMRemoteSettings *settings,
NMClient *client,
PageNewConnectionFunc new_func,
NewConnectionResultFunc result_func,
gpointer user_data)
......@@ -381,25 +381,25 @@ new_connection_of_type (GtkWindow *parent_window,
ncd = g_slice_new (NewConnectionData);
ncd->parent_window = parent_window;
ncd->settings = settings;
ncd->client = client;
ncd->result_func = result_func;
ncd->user_data = user_data;
new_func (parent_window,
detail,
settings,
client,
new_connection_result,
ncd);
}
void
new_connection_dialog (GtkWindow *parent_window,
NMRemoteSettings *settings,
NMClient *client,
NewConnectionTypeFilterFunc type_filter_func,
NewConnectionResultFunc result_func,
gpointer user_data)
{
new_connection_dialog_full (parent_window, settings,
new_connection_dialog_full (parent_window, client,
NULL, NULL,
type_filter_func,
result_func,
......@@ -408,7 +408,7 @@ new_connection_dialog (GtkWindow *parent_window,
void
new_connection_dialog_full (GtkWindow *parent_window,
NMRemoteSettings *settings,
NMClient *client,
const char *primary_label,
const char *secondary_label,
NewConnectionTypeFilterFunc type_filter_func,
......@@ -423,7 +423,7 @@ new_connection_dialog_full (GtkWindow *parent_window,
GtkTreeIter iter;
int response;
PageNewConnectionFunc new_func = NULL;
NMVpnPluginUiInterface *plugin = NULL;
NMVpnEditorPlugin *plugin = NULL;
char *vpn_type = NULL;
GError *error = NULL;
......@@ -463,7 +463,7 @@ new_connection_dialog_full (GtkWindow *parent_window,
-1);
if (plugin) {
g_object_get (G_OBJECT (plugin), NM_VPN_PLUGIN_UI_INTERFACE_SERVICE, &vpn_type, NULL);
g_object_get (G_OBJECT (plugin), NM_VPN_EDITOR_PLUGIN_SERVICE, &vpn_type, NULL);
g_object_unref (plugin);
}
}
......@@ -472,7 +472,7 @@ new_connection_dialog_full (GtkWindow *parent_window,
g_object_unref (gui);
if (new_func)
new_connection_of_type (parent_window, vpn_type, settings, new_func, result_func, user_data);
new_connection_of_type (parent_window, vpn_type, client, new_func, result_func, user_data);
else
result_func (NULL, user_data);
......@@ -487,13 +487,15 @@ typedef struct {
} DeleteInfo;
static void
delete_cb (NMRemoteConnection *connection,
GError *error,
delete_cb (GObject *connection,
GAsyncResult *result,
gpointer user_data)
{
DeleteInfo *info = user_data;
DeleteConnectionResultFunc result_func;
GError *error = NULL;
nm_remote_connection_delete_finish (NM_REMOTE_CONNECTION (connection), result, &error);
if (error) {
nm_connection_editor_error (info->parent_window,
_("Connection delete failed"),
......@@ -510,9 +512,10 @@ delete_cb (NMRemoteConnection *connection,
result_func = info->result_func;
user_data = info->user_data;
g_free (info);
g_clear_error (&error);
if (result_func)
(*result_func) (connection, error == NULL, user_data);
(*result_func) (NM_REMOTE_CONNECTION (connection), error == NULL, user_data);
}
void
......@@ -565,7 +568,7 @@ delete_connection (GtkWindow *parent_window,
if (editor)
nm_connection_editor_set_busy (editor, TRUE);
nm_remote_connection_delete (connection, delete_cb, info);
nm_remote_connection_delete_async (connection, NULL, delete_cb, info);
}
gboolean
......
......@@ -15,14 +15,15 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2012 Red Hat, Inc.
* Copyright 2012 - 2014 Red Hat, Inc.
*/
#ifndef __CONNECTION_HELPERS_H__
#define __CONNECTION_HELPERS_H__
#include <NetworkManager.h>
#include "ce-page.h"
#include <nm-remote-settings.h>
typedef struct {
const char *name;
......@@ -39,12 +40,12 @@ typedef void (*NewConnectionResultFunc) (NMConnection *connection,
gpointer user_data);
void new_connection_dialog (GtkWindow *parent_window,
NMRemoteSettings *settings,
NMClient *client,
NewConnectionTypeFilterFunc type_filter_func,
NewConnectionResultFunc result_func,
gpointer user_data);
void new_connection_dialog_full (GtkWindow *parent_window,
NMRemoteSettings *settings,
NMClient *client,
const char *primary_label,
const char *secondary_label,
NewConnectionTypeFilterFunc type_filter_func,
......@@ -53,7 +54,7 @@ void new_connection_dialog_full (GtkWindow *parent_window,
void new_connection_of_type (GtkWindow *parent_window,
const char *detail,
NMRemoteSettings *settings,
NMClient *client,
PageNewConnectionFunc new_func,