ce-page.h 7.91 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0+
2 3 4 5
/* NetworkManager Connection editor -- Connection editor for NetworkManager
 *
 * Dan Williams <dcbw@redhat.com>
 *
Dan Winship's avatar
Dan Winship committed
6
 * Copyright 2008 - 2014 Red Hat, Inc.
7 8 9 10 11
 */

#ifndef __CE_PAGE_H__
#define __CE_PAGE_H__

12
#include <glib.h>
13 14
#include <glib-object.h>

15
#include <gtk/gtk.h>
16

Dan Winship's avatar
Dan Winship committed
17 18
#include <NetworkManager.h>

19
#include "nm-connection-editor.h"
Dan Winship's avatar
Dan Winship committed
20
#include "utils.h"
21

22 23 24
/* for ARPHRD_ETHER / ARPHRD_INFINIBAND for MAC utilies */
#include <net/if_arp.h>

25 26 27 28
struct _func_tag_page_new_connection_result;
#define FUNC_TAG_PAGE_NEW_CONNECTION_RESULT_IMPL struct _func_tag_page_new_connection_result *_dummy
#define FUNC_TAG_PAGE_NEW_CONNECTION_RESULT_CALL ((struct _func_tag_page_new_connection_result *) NULL)
typedef void (*PageNewConnectionResultFunc) (FUNC_TAG_PAGE_NEW_CONNECTION_RESULT_IMPL,
29
                                             NMConnection *connection, /* allow-none, don't transfer reference, allow-keep */
30 31 32 33 34 35
                                             gboolean canceled,
                                             GError *error,
                                             gpointer user_data);

typedef GSList * (*PageGetConnectionsFunc) (gpointer user_data);

36 37 38 39 40
struct _func_tag_page_new_connection;
#define FUNC_TAG_PAGE_NEW_CONNECTION_IMPL struct _func_tag_page_new_connection *_dummy
#define FUNC_TAG_PAGE_NEW_CONNECTION_CALL ((struct _func_tag_page_new_connection *) NULL)
typedef void (*PageNewConnectionFunc) (FUNC_TAG_PAGE_NEW_CONNECTION_IMPL,
                                       GtkWindow *parent,
41
                                       const char *detail,
42
                                       gpointer detail_data,
43
                                       NMConnection *connection,
Dan Winship's avatar
Dan Winship committed
44
                                       NMClient *client,
45 46 47
                                       PageNewConnectionResultFunc result_func,
                                       gpointer user_data);

48 49 50 51
#define CE_TYPE_PAGE            (ce_page_get_type ())
#define CE_PAGE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), CE_TYPE_PAGE, CEPage))
#define CE_PAGE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), CE_TYPE_PAGE, CEPageClass))
#define CE_IS_PAGE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CE_TYPE_PAGE))
52
#define CE_IS_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CE_TYPE_PAGE))
53 54
#define CE_PAGE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), CE_TYPE_PAGE, CEPageClass))

55
#define CE_PAGE_CONNECTION    "connection"
56 57
#define CE_PAGE_PARENT_WINDOW "parent-window"

58 59
#define CE_PAGE_CHANGED       "changed"
#define CE_PAGE_INITIALIZED   "initialized"
60
#define CE_PAGE_NEW_EDITOR    "new-editor"
61

62 63 64
typedef struct {
	GObject parent;

65
	gboolean inter_page_change_running;
66
	GtkBuilder *builder;
67 68 69
	GtkWidget *page;
	char *title;

70 71
	gulong secrets_done_validate;

72
	NMConnectionEditor *editor;
73 74
	NMConnection *connection;
	GtkWindow *parent_window;
75
	NMClient *client;
76 77 78 79 80 81
} CEPage;

typedef struct {
	GObjectClass parent;

	/* Virtual functions */
82
	gboolean    (*ce_page_validate_v) (CEPage *self, NMConnection *connection, GError **error);
83
	gboolean    (*last_update)  (CEPage *self, NMConnection *connection, GError **error);
84
	gboolean    (*inter_page_change)  (CEPage *self);
85 86
} CEPageClass;

87 88
typedef CEPage* (*CEPageNewFunc)(NMConnectionEditor *editor,
                                 NMConnection *connection,
89
                                 GtkWindow *parent,
90
                                 NMClient *client,
91 92
                                 const char **out_secrets_setting_name,
                                 GError **error);
93

94
#define CE_TOOLTIP_ADDR_AUTO _("IP addresses identify your computer on the network. " \
95
                               "Click the “Add” button to add static IP address to be " \
96
                               "configured in addition to the automatic ones.")
97
#define CE_TOOLTIP_ADDR_MANUAL _("IP addresses identify your computer on the network. " \
98
                                 "Click the “Add” button to add an IP address.")
99
#define CE_TOOLTIP_ADDR_SHARED _("The IP address identify your computer on the network and " \
100 101
                                 "determines the address range distributed to other computers. " \
                                 "Click the “Add” button to add an IP address. "\
102
                                 "If no address is provided, range will be determined automatically.")
103 104 105

#define CE_LABEL_ADDR_AUTO _("Additional static addresses")
#define CE_LABEL_ADDR_MANUAL _("Addresses")
106
#define CE_LABEL_ADDR_SHARED _("Address (optional)")
107

108 109 110 111 112 113
GType ce_page_get_type (void);

GtkWidget *  ce_page_get_page (CEPage *self);

const char * ce_page_get_title (CEPage *self);

114
gboolean ce_page_validate (CEPage *self, NMConnection *connection, GError **error);
115
gboolean ce_page_last_update (CEPage *self, NMConnection *connection, GError **error);
116
gboolean ce_page_inter_page_change (CEPage *self);
117

118
void ce_page_setup_mac_combo (CEPage *self, GtkComboBox *combo,
119 120 121
                              const char *mac, char **mac_list);
void ce_page_setup_data_combo (CEPage *self, GtkComboBox *combo,
                               const char *data, char **list);
122
void ce_page_setup_cloned_mac_combo (GtkComboBoxText *combo, const char *current);
123 124 125 126 127
void ce_page_setup_device_combo (CEPage *self,
                                 GtkComboBox *combo,
                                 GType device_type,
                                 const char *ifname,
                                 const char *mac,
128
                                 const char *mac_property);
129 130
gboolean ce_page_mac_entry_valid (GtkEntry *entry, int type, const char *property_name, GError **error);
gboolean ce_page_interface_name_valid (const char *iface, const char *property_name, GError **error);
131
gboolean ce_page_device_entry_get (GtkEntry *entry, int type,
132
                                   gboolean check_ifname,
133 134 135
                                   char **ifname, char **mac,
                                   const char *device_name,
                                   GError **error);
136
char *ce_page_cloned_mac_get (GtkComboBoxText *combo);
137
gboolean ce_page_cloned_mac_combo_valid (GtkComboBoxText *combo, int type, const char *property_name, GError **error);
138

139 140
void ce_page_changed (CEPage *self);

141 142 143 144
NMConnectionEditor *ce_page_new_editor (CEPage *self,
                                        GtkWindow *parent_window,
                                        NMConnection *connection);

145 146
void ce_spin_automatic_val (GtkSpinButton *spin, int defvalue);
void ce_spin_default_val (GtkSpinButton *spin, int defvalue);
147
void ce_spin_off_val (GtkSpinButton *spin, int defvalue);
148 149
int ce_get_property_default (NMSetting *setting, const char *property_name);

150 151
void ce_page_complete_init (CEPage *self,
                            const char *setting_name,
Dan Winship's avatar
Dan Winship committed
152
                            GVariant *secrets,
153
                            GError *error);
154

Dan Winship's avatar
Dan Winship committed
155
char *ce_page_get_next_available_name (const GPtrArray *connections, const char *format);
156

157
/* Only for subclasses */
158 159 160 161 162
void ce_page_complete_connection (NMConnection *connection,
                                  const char *format,
                                  const char *ctype,
                                  gboolean autoconnect,
                                  NMClient *client);
163

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
static inline NMConnection *
_ensure_connection_own (NMConnection **connection)
{
	return (*connection) ?: (*connection = nm_simple_connection_new ());
}

static inline NMConnection *
_ensure_connection_other (NMConnection *connection, NMConnection **connection_to_free)
{
	if (connection) {
		*connection_to_free = NULL;
		return connection;
	}
	return (*connection_to_free = nm_simple_connection_new ());
}

180
CEPage *ce_page_new (GType page_type,
181
                     NMConnectionEditor *editor,
182 183
                     NMConnection *connection,
                     GtkWindow *parent_window,
184
                     NMClient *client,
Lubomir Rintel's avatar
Lubomir Rintel committed
185
                     const char *ui_resource,
186 187 188
                     const char *widget_name,
                     const char *title);

189 190
#endif  /* __CE_PAGE_H__ */