mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-20 04:40:04 +01:00
all: reformat all with new clang-format style
Run:
./contrib/scripts/nm-code-format.sh -i
./contrib/scripts/nm-code-format.sh -i
Yes, it needs to run twice because the first run doesn't yet produce the
final result.
Signed-off-by: Antonio Cardace <acardace@redhat.com>
This commit is contained in:
parent
b4d8e69cd4
commit
328fb90f3e
859 changed files with 325292 additions and 312497 deletions
|
|
@ -17,220 +17,214 @@
|
|||
#include "nm-polkit-listener.h"
|
||||
|
||||
static void
|
||||
usage (void)
|
||||
usage(void)
|
||||
{
|
||||
g_printerr (_("Usage: nmcli agent { COMMAND | help }\n\n"
|
||||
"COMMAND := { secret | polkit | all }\n\n"
|
||||
));
|
||||
g_printerr(_("Usage: nmcli agent { COMMAND | help }\n\n"
|
||||
"COMMAND := { secret | polkit | all }\n\n"));
|
||||
}
|
||||
|
||||
static void
|
||||
usage_agent_secret (void)
|
||||
usage_agent_secret(void)
|
||||
{
|
||||
g_printerr (_("Usage: nmcli agent secret { help }\n"
|
||||
"\n"
|
||||
"Runs nmcli as NetworkManager secret agent. When NetworkManager requires\n"
|
||||
"a password it asks registered agents for it. This command keeps nmcli running\n"
|
||||
"and if a password is required asks the user for it.\n\n"));
|
||||
g_printerr(_("Usage: nmcli agent secret { help }\n"
|
||||
"\n"
|
||||
"Runs nmcli as NetworkManager secret agent. When NetworkManager requires\n"
|
||||
"a password it asks registered agents for it. This command keeps nmcli running\n"
|
||||
"and if a password is required asks the user for it.\n\n"));
|
||||
}
|
||||
|
||||
static void
|
||||
usage_agent_polkit (void)
|
||||
usage_agent_polkit(void)
|
||||
{
|
||||
g_printerr (_("Usage: nmcli agent polkit { help }\n"
|
||||
"\n"
|
||||
"Registers nmcli as a polkit action for the user session.\n"
|
||||
"When a polkit daemon requires an authorization, nmcli asks the user and gives\n"
|
||||
"the response back to polkit.\n\n"));
|
||||
g_printerr(_("Usage: nmcli agent polkit { help }\n"
|
||||
"\n"
|
||||
"Registers nmcli as a polkit action for the user session.\n"
|
||||
"When a polkit daemon requires an authorization, nmcli asks the user and gives\n"
|
||||
"the response back to polkit.\n\n"));
|
||||
}
|
||||
|
||||
static void
|
||||
usage_agent_all (void)
|
||||
usage_agent_all(void)
|
||||
{
|
||||
g_printerr (_("Usage: nmcli agent all { help }\n"
|
||||
"\n"
|
||||
"Runs nmcli as both NetworkManager secret and a polkit agent.\n\n"));
|
||||
g_printerr(_("Usage: nmcli agent all { help }\n"
|
||||
"\n"
|
||||
"Runs nmcli as both NetworkManager secret and a polkit agent.\n\n"));
|
||||
}
|
||||
|
||||
/* for pre-filling a string to readline prompt */
|
||||
static char *pre_input_deftext;
|
||||
static int
|
||||
set_deftext (void)
|
||||
set_deftext(void)
|
||||
{
|
||||
if (pre_input_deftext && rl_startup_hook) {
|
||||
rl_insert_text (pre_input_deftext);
|
||||
g_free (pre_input_deftext);
|
||||
pre_input_deftext = NULL;
|
||||
rl_startup_hook = NULL;
|
||||
}
|
||||
return 0;
|
||||
if (pre_input_deftext && rl_startup_hook) {
|
||||
rl_insert_text(pre_input_deftext);
|
||||
g_free(pre_input_deftext);
|
||||
pre_input_deftext = NULL;
|
||||
rl_startup_hook = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_secrets_from_user (const NmcConfig *nmc_config,
|
||||
const char *request_id,
|
||||
const char *title,
|
||||
const char *msg,
|
||||
GPtrArray *secrets)
|
||||
get_secrets_from_user(const NmcConfig *nmc_config,
|
||||
const char * request_id,
|
||||
const char * title,
|
||||
const char * msg,
|
||||
GPtrArray * secrets)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < secrets->len; i++) {
|
||||
NMSecretAgentSimpleSecret *secret = secrets->pdata[i];
|
||||
char *pwd = NULL;
|
||||
for (i = 0; i < secrets->len; i++) {
|
||||
NMSecretAgentSimpleSecret *secret = secrets->pdata[i];
|
||||
char * pwd = NULL;
|
||||
|
||||
/* Ask user for the password */
|
||||
if (msg)
|
||||
g_print ("%s\n", msg);
|
||||
if (secret->value) {
|
||||
/* Prefill the password if we have it. */
|
||||
rl_startup_hook = set_deftext;
|
||||
pre_input_deftext = g_strdup (secret->value);
|
||||
}
|
||||
if (secret->no_prompt_entry_id)
|
||||
pwd = nmc_readline (nmc_config, "%s: ", secret->pretty_name);
|
||||
else
|
||||
pwd = nmc_readline (nmc_config, "%s (%s): ", secret->pretty_name, secret->entry_id);
|
||||
/* Ask user for the password */
|
||||
if (msg)
|
||||
g_print("%s\n", msg);
|
||||
if (secret->value) {
|
||||
/* Prefill the password if we have it. */
|
||||
rl_startup_hook = set_deftext;
|
||||
pre_input_deftext = g_strdup(secret->value);
|
||||
}
|
||||
if (secret->no_prompt_entry_id)
|
||||
pwd = nmc_readline(nmc_config, "%s: ", secret->pretty_name);
|
||||
else
|
||||
pwd = nmc_readline(nmc_config, "%s (%s): ", secret->pretty_name, secret->entry_id);
|
||||
|
||||
/* No password provided, cancel the secrets. */
|
||||
if (!pwd)
|
||||
return FALSE;
|
||||
g_free (secret->value);
|
||||
secret->value = pwd;
|
||||
}
|
||||
return TRUE;
|
||||
/* No password provided, cancel the secrets. */
|
||||
if (!pwd)
|
||||
return FALSE;
|
||||
g_free(secret->value);
|
||||
secret->value = pwd;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
secrets_requested (NMSecretAgentSimple *agent,
|
||||
const char *request_id,
|
||||
const char *title,
|
||||
const char *msg,
|
||||
GPtrArray *secrets,
|
||||
gpointer user_data)
|
||||
secrets_requested(NMSecretAgentSimple *agent,
|
||||
const char * request_id,
|
||||
const char * title,
|
||||
const char * msg,
|
||||
GPtrArray * secrets,
|
||||
gpointer user_data)
|
||||
{
|
||||
NmCli *nmc = user_data;
|
||||
gboolean success;
|
||||
NmCli * nmc = user_data;
|
||||
gboolean success;
|
||||
|
||||
if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY)
|
||||
nmc_terminal_erase_line ();
|
||||
if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY)
|
||||
nmc_terminal_erase_line();
|
||||
|
||||
success = get_secrets_from_user (&nmc->nmc_config, request_id, title, msg, secrets);
|
||||
nm_secret_agent_simple_response (agent,
|
||||
request_id,
|
||||
success ? secrets : NULL);
|
||||
success = get_secrets_from_user(&nmc->nmc_config, request_id, title, msg, secrets);
|
||||
nm_secret_agent_simple_response(agent, request_id, success ? secrets : NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
do_agent_secret (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv)
|
||||
do_agent_secret(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv)
|
||||
{
|
||||
next_arg (nmc, &argc, &argv, NULL);
|
||||
if (nmc->complete)
|
||||
return;
|
||||
next_arg(nmc, &argc, &argv, NULL);
|
||||
if (nmc->complete)
|
||||
return;
|
||||
|
||||
/* Create secret agent */
|
||||
nmc->secret_agent = nm_secret_agent_simple_new ("nmcli-agent");
|
||||
if (nmc->secret_agent) {
|
||||
/* We keep running */
|
||||
nmc->should_wait++;
|
||||
/* Create secret agent */
|
||||
nmc->secret_agent = nm_secret_agent_simple_new("nmcli-agent");
|
||||
if (nmc->secret_agent) {
|
||||
/* We keep running */
|
||||
nmc->should_wait++;
|
||||
|
||||
nm_secret_agent_simple_enable (nmc->secret_agent, NULL);
|
||||
g_signal_connect (nmc->secret_agent,
|
||||
NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS,
|
||||
G_CALLBACK (secrets_requested),
|
||||
nmc);
|
||||
g_print (_("nmcli successfully registered as a NetworkManager's secret agent.\n"));
|
||||
} else {
|
||||
g_string_printf (nmc->return_text, _("Error: secret agent initialization failed"));
|
||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
nm_secret_agent_simple_enable(nmc->secret_agent, NULL);
|
||||
g_signal_connect(nmc->secret_agent,
|
||||
NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS,
|
||||
G_CALLBACK(secrets_requested),
|
||||
nmc);
|
||||
g_print(_("nmcli successfully registered as a NetworkManager's secret agent.\n"));
|
||||
} else {
|
||||
g_string_printf(nmc->return_text, _("Error: secret agent initialization failed"));
|
||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
polkit_registered (gpointer instance,
|
||||
gpointer user_data)
|
||||
polkit_registered(gpointer instance, gpointer user_data)
|
||||
{
|
||||
g_print (_("nmcli successfully registered as a polkit agent.\n"));
|
||||
g_print(_("nmcli successfully registered as a polkit agent.\n"));
|
||||
}
|
||||
|
||||
static void
|
||||
polkit_error (gpointer instance,
|
||||
const char *error,
|
||||
gpointer user_data)
|
||||
polkit_error(gpointer instance, const char *error, gpointer user_data)
|
||||
{
|
||||
g_main_loop_quit (loop);
|
||||
g_main_loop_quit(loop);
|
||||
}
|
||||
|
||||
static void
|
||||
do_agent_polkit (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv)
|
||||
do_agent_polkit(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv)
|
||||
{
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
next_arg (nmc, &argc, &argv, NULL);
|
||||
if (nmc->complete)
|
||||
return;
|
||||
next_arg(nmc, &argc, &argv, NULL);
|
||||
if (nmc->complete)
|
||||
return;
|
||||
|
||||
if (!nmc_polkit_agent_init (nmc, TRUE, &error)) {
|
||||
g_dbus_error_strip_remote_error (error);
|
||||
g_string_printf (nmc->return_text,
|
||||
_("Error: polkit agent initialization failed: %s"),
|
||||
error->message);
|
||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||
} else {
|
||||
/* We keep running */
|
||||
nmc->should_wait++;
|
||||
g_signal_connect (nmc->pk_listener,
|
||||
NM_POLKIT_LISTENER_SIGNAL_ERROR,
|
||||
G_CALLBACK (polkit_error),
|
||||
NULL);
|
||||
g_signal_connect (nmc->pk_listener,
|
||||
NM_POLKIT_LISTENER_SIGNAL_REGISTERED,
|
||||
G_CALLBACK (polkit_registered),
|
||||
NULL);
|
||||
if (!nmc_polkit_agent_init(nmc, TRUE, &error)) {
|
||||
g_dbus_error_strip_remote_error(error);
|
||||
g_string_printf(nmc->return_text,
|
||||
_("Error: polkit agent initialization failed: %s"),
|
||||
error->message);
|
||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||
} else {
|
||||
/* We keep running */
|
||||
nmc->should_wait++;
|
||||
g_signal_connect(nmc->pk_listener,
|
||||
NM_POLKIT_LISTENER_SIGNAL_ERROR,
|
||||
G_CALLBACK(polkit_error),
|
||||
NULL);
|
||||
g_signal_connect(nmc->pk_listener,
|
||||
NM_POLKIT_LISTENER_SIGNAL_REGISTERED,
|
||||
G_CALLBACK(polkit_registered),
|
||||
NULL);
|
||||
|
||||
/* keep running */
|
||||
nmc->should_wait++;
|
||||
}
|
||||
/* keep running */
|
||||
nmc->should_wait++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_agent_all (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv)
|
||||
do_agent_all(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv)
|
||||
{
|
||||
NMCResultCode r;
|
||||
NMCResultCode r;
|
||||
|
||||
next_arg (nmc, &argc, &argv, NULL);
|
||||
if (nmc->complete)
|
||||
return;
|
||||
next_arg(nmc, &argc, &argv, NULL);
|
||||
if (nmc->complete)
|
||||
return;
|
||||
|
||||
/* Run both secret and polkit agent */
|
||||
do_agent_secret (cmd, nmc, argc, argv);
|
||||
r = nmc->return_value;
|
||||
if (r != NMC_RESULT_SUCCESS) {
|
||||
g_printerr ("%s\n", nmc->return_text->str);
|
||||
g_string_truncate (nmc->return_text, 0);
|
||||
nmc->return_value = NMC_RESULT_SUCCESS;
|
||||
}
|
||||
/* Run both secret and polkit agent */
|
||||
do_agent_secret(cmd, nmc, argc, argv);
|
||||
r = nmc->return_value;
|
||||
if (r != NMC_RESULT_SUCCESS) {
|
||||
g_printerr("%s\n", nmc->return_text->str);
|
||||
g_string_truncate(nmc->return_text, 0);
|
||||
nmc->return_value = NMC_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
do_agent_polkit (cmd, nmc, argc, argv);
|
||||
if (nmc->return_value != NMC_RESULT_SUCCESS) {
|
||||
g_printerr ("%s\n", nmc->return_text->str);
|
||||
g_string_truncate (nmc->return_text, 0);
|
||||
}
|
||||
do_agent_polkit(cmd, nmc, argc, argv);
|
||||
if (nmc->return_value != NMC_RESULT_SUCCESS) {
|
||||
g_printerr("%s\n", nmc->return_text->str);
|
||||
g_string_truncate(nmc->return_text, 0);
|
||||
}
|
||||
|
||||
if (r != NMC_RESULT_SUCCESS)
|
||||
nmc->return_value = r;
|
||||
if (r != NMC_RESULT_SUCCESS)
|
||||
nmc->return_value = r;
|
||||
}
|
||||
|
||||
void
|
||||
nmc_command_func_agent (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv)
|
||||
nmc_command_func_agent(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv)
|
||||
{
|
||||
static const NMCCommand cmds[] = {
|
||||
{ "secret", do_agent_secret, usage_agent_secret, TRUE, TRUE },
|
||||
{ "polkit", do_agent_polkit, usage_agent_polkit, TRUE, TRUE },
|
||||
{ "all", do_agent_all, usage_agent_all, TRUE, TRUE },
|
||||
{ NULL, do_agent_all, usage, TRUE, TRUE },
|
||||
};
|
||||
static const NMCCommand cmds[] = {
|
||||
{"secret", do_agent_secret, usage_agent_secret, TRUE, TRUE},
|
||||
{"polkit", do_agent_polkit, usage_agent_polkit, TRUE, TRUE},
|
||||
{"all", do_agent_all, usage_agent_all, TRUE, TRUE},
|
||||
{NULL, do_agent_all, usage, TRUE, TRUE},
|
||||
};
|
||||
|
||||
next_arg (nmc, &argc, &argv, NULL);
|
||||
nmc_do_cmd (nmc, cmds, *argv, argc, argv);
|
||||
next_arg(nmc, &argc, &argv, NULL);
|
||||
nmc_do_cmd(nmc, cmds, *argv, argc, argv);
|
||||
}
|
||||
|
|
|
|||
2023
clients/cli/common.c
2023
clients/cli/common.c
File diff suppressed because it is too large
Load diff
|
|
@ -9,81 +9,77 @@
|
|||
#include "nmcli.h"
|
||||
#include "nm-secret-agent-simple.h"
|
||||
|
||||
gboolean print_ip_config(NMIPConfig * cfg,
|
||||
int addr_family,
|
||||
const NmcConfig *nmc_config,
|
||||
const char * one_field);
|
||||
|
||||
gboolean print_ip_config (NMIPConfig *cfg,
|
||||
int addr_family,
|
||||
const NmcConfig *nmc_config,
|
||||
const char *one_field);
|
||||
gboolean print_dhcp_config(NMDhcpConfig * dhcp,
|
||||
int addr_family,
|
||||
const NmcConfig *nmc_config,
|
||||
const char * one_field);
|
||||
|
||||
gboolean print_dhcp_config (NMDhcpConfig *dhcp,
|
||||
int addr_family,
|
||||
const NmcConfig *nmc_config,
|
||||
const char *one_field);
|
||||
NMConnection *nmc_find_connection(const GPtrArray *connections,
|
||||
const char * filter_type,
|
||||
const char * filter_val,
|
||||
GPtrArray ** out_result,
|
||||
gboolean complete);
|
||||
|
||||
NMConnection *nmc_find_connection (const GPtrArray *connections,
|
||||
const char *filter_type,
|
||||
const char *filter_val,
|
||||
GPtrArray **out_result,
|
||||
gboolean complete);
|
||||
NMActiveConnection *nmc_find_active_connection(const GPtrArray *active_cons,
|
||||
const char * filter_type,
|
||||
const char * filter_val,
|
||||
GPtrArray ** out_result,
|
||||
gboolean complete);
|
||||
|
||||
NMActiveConnection *nmc_find_active_connection (const GPtrArray *active_cons,
|
||||
const char *filter_type,
|
||||
const char *filter_val,
|
||||
GPtrArray **out_result,
|
||||
gboolean complete);
|
||||
void nmc_secrets_requested(NMSecretAgentSimple *agent,
|
||||
const char * request_id,
|
||||
const char * title,
|
||||
const char * msg,
|
||||
GPtrArray * secrets,
|
||||
gpointer user_data);
|
||||
|
||||
void nmc_secrets_requested (NMSecretAgentSimple *agent,
|
||||
const char *request_id,
|
||||
const char *title,
|
||||
const char *msg,
|
||||
GPtrArray *secrets,
|
||||
gpointer user_data);
|
||||
char *nmc_unique_connection_name(const GPtrArray *connections, const char *try_name);
|
||||
|
||||
char *nmc_unique_connection_name (const GPtrArray *connections,
|
||||
const char *try_name);
|
||||
|
||||
void nmc_cleanup_readline (void);
|
||||
char *nmc_readline (const NmcConfig *nmc_config,
|
||||
const char *prompt_fmt,
|
||||
...) G_GNUC_PRINTF (2, 3);
|
||||
char *nmc_readline_echo (const NmcConfig *nmc_config,
|
||||
gboolean echo_on,
|
||||
const char *prompt_fmt,
|
||||
...) G_GNUC_PRINTF (3, 4);
|
||||
NmcCompEntryFunc nmc_rl_compentry_func_wrap (const char *const*values);
|
||||
char *nmc_rl_gen_func_basic (const char *text, int state, const char *const*words);
|
||||
char *nmc_rl_gen_func_ifnames (const char *text, int state);
|
||||
gboolean nmc_get_in_readline (void);
|
||||
void nmc_set_in_readline (gboolean in_readline);
|
||||
void nmc_cleanup_readline(void);
|
||||
char *nmc_readline(const NmcConfig *nmc_config, const char *prompt_fmt, ...) G_GNUC_PRINTF(2, 3);
|
||||
char *nmc_readline_echo(const NmcConfig *nmc_config, gboolean echo_on, const char *prompt_fmt, ...)
|
||||
G_GNUC_PRINTF(3, 4);
|
||||
NmcCompEntryFunc nmc_rl_compentry_func_wrap(const char *const *values);
|
||||
char * nmc_rl_gen_func_basic(const char *text, int state, const char *const *words);
|
||||
char * nmc_rl_gen_func_ifnames(const char *text, int state);
|
||||
gboolean nmc_get_in_readline(void);
|
||||
void nmc_set_in_readline(gboolean in_readline);
|
||||
|
||||
/* for pre-filling a string to readline prompt */
|
||||
extern char *nmc_rl_pre_input_deftext;
|
||||
int nmc_rl_set_deftext (void);
|
||||
int nmc_rl_set_deftext(void);
|
||||
|
||||
char *nmc_parse_lldp_capabilities (guint value);
|
||||
char *nmc_parse_lldp_capabilities(guint value);
|
||||
|
||||
void nmc_do_cmd (NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, const char *const*argv);
|
||||
void
|
||||
nmc_do_cmd(NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, const char *const *argv);
|
||||
|
||||
void nmc_complete_strv (const char *prefix, gssize nargs, const char *const*args);
|
||||
void nmc_complete_strv(const char *prefix, gssize nargs, const char *const *args);
|
||||
|
||||
#define nmc_complete_strings(prefix, ...) nmc_complete_strv ((prefix), NM_NARG (__VA_ARGS__), (const char *const[]) { __VA_ARGS__ })
|
||||
#define nmc_complete_strings(prefix, ...) \
|
||||
nmc_complete_strv((prefix), NM_NARG(__VA_ARGS__), (const char *const[]){__VA_ARGS__})
|
||||
|
||||
void nmc_complete_bool (const char *prefix);
|
||||
void nmc_complete_bool(const char *prefix);
|
||||
|
||||
const char *nmc_error_get_simple_message (GError *error);
|
||||
const char *nmc_error_get_simple_message(GError *error);
|
||||
|
||||
extern const NmcMetaGenericInfo *const metagen_ip4_config[];
|
||||
extern const NmcMetaGenericInfo *const metagen_ip6_config[];
|
||||
extern const NmcMetaGenericInfo *const metagen_dhcp_config[];
|
||||
|
||||
const char *nm_connectivity_to_string (NMConnectivityState connectivity);
|
||||
const char *nm_connectivity_to_string(NMConnectivityState connectivity);
|
||||
|
||||
GVariant *nmc_dbus_call_sync (NmCli *nmc,
|
||||
const char *object_path,
|
||||
const char *interface_name,
|
||||
const char *method_name,
|
||||
GVariant *parameters,
|
||||
const GVariantType *reply_type,
|
||||
GError **error);
|
||||
GVariant *nmc_dbus_call_sync(NmCli * nmc,
|
||||
const char * object_path,
|
||||
const char * interface_name,
|
||||
const char * method_name,
|
||||
GVariant * parameters,
|
||||
const GVariantType *reply_type,
|
||||
GError ** error);
|
||||
|
||||
#endif /* NMC_COMMON_H */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -8,19 +8,18 @@
|
|||
|
||||
#include "nmcli.h"
|
||||
|
||||
void monitor_connections (NmCli *nmc);
|
||||
void monitor_connections(NmCli *nmc);
|
||||
|
||||
gboolean
|
||||
nmc_process_connection_properties (NmCli *nmc,
|
||||
NMConnection *connection,
|
||||
int *argc,
|
||||
const char *const**argv,
|
||||
gboolean allow_remove_setting,
|
||||
GError **error);
|
||||
gboolean nmc_process_connection_properties(NmCli * nmc,
|
||||
NMConnection * connection,
|
||||
int * argc,
|
||||
const char *const **argv,
|
||||
gboolean allow_remove_setting,
|
||||
GError ** error);
|
||||
|
||||
NMMetaColor nmc_active_connection_state_to_color (NMActiveConnection *ac);
|
||||
NMMetaColor nmc_active_connection_state_to_color(NMActiveConnection *ac);
|
||||
|
||||
int nmc_active_connection_cmp (NMActiveConnection *ac_a, NMActiveConnection *ac_b);
|
||||
int nmc_active_connection_cmp(NMActiveConnection *ac_a, NMActiveConnection *ac_b);
|
||||
|
||||
extern const NmcMetaGenericInfo *const metagen_con_show[];
|
||||
extern const NmcMetaGenericInfo *const metagen_con_active_general[];
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -8,15 +8,15 @@
|
|||
|
||||
#include "nmcli.h"
|
||||
|
||||
void nmc_complete_device (NMClient *client, const char *prefix, gboolean wifi_only);
|
||||
void nmc_complete_device(NMClient *client, const char *prefix, gboolean wifi_only);
|
||||
|
||||
void nmc_complete_bssid (NMClient *client, const char *ifname, const char *bssid_prefix);
|
||||
void nmc_complete_bssid(NMClient *client, const char *ifname, const char *bssid_prefix);
|
||||
|
||||
void monitor_devices (NmCli *nmc);
|
||||
void monitor_devices(NmCli *nmc);
|
||||
|
||||
NMDevice ** nmc_get_devices_sorted (NMClient *client);
|
||||
NMDevice **nmc_get_devices_sorted(NMClient *client);
|
||||
|
||||
NMMetaColor nmc_device_state_to_color (NMDevice *device);
|
||||
NMMetaColor nmc_device_state_to_color(NMDevice *device);
|
||||
|
||||
extern const NmcMetaGenericInfo *const metagen_device_status[];
|
||||
extern const NmcMetaGenericInfo *const metagen_device_detail_general[];
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -7,58 +7,65 @@
|
|||
#define INDENT 4
|
||||
|
||||
static char *
|
||||
_xml_escape_attribute (const char *value)
|
||||
_xml_escape_attribute(const char *value)
|
||||
{
|
||||
gs_free char *s = NULL;
|
||||
gs_free char *s = NULL;
|
||||
|
||||
s = g_markup_escape_text (value, -1);
|
||||
return g_strdup_printf ("\"%s\"", s);
|
||||
s = g_markup_escape_text(value, -1);
|
||||
return g_strdup_printf("\"%s\"", s);
|
||||
}
|
||||
|
||||
static const char *
|
||||
_indent_level (guint num_spaces)
|
||||
_indent_level(guint num_spaces)
|
||||
{
|
||||
static const char spaces[] = " ";
|
||||
static const char spaces[] = " ";
|
||||
|
||||
nm_assert (num_spaces < G_N_ELEMENTS (spaces));
|
||||
return &spaces[G_N_ELEMENTS (spaces) - num_spaces - 1];
|
||||
nm_assert(num_spaces < G_N_ELEMENTS(spaces));
|
||||
return &spaces[G_N_ELEMENTS(spaces) - num_spaces - 1];
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i_sett_infos;
|
||||
int i_property;
|
||||
int i_sett_infos;
|
||||
int i_property;
|
||||
|
||||
g_print ("<nm-setting-docs>\n");
|
||||
for (i_sett_infos = 0; i_sett_infos < G_N_ELEMENTS (nm_meta_setting_infos_editor); i_sett_infos++) {
|
||||
const NMMetaSettingInfoEditor *sett_info = &nm_meta_setting_infos_editor[i_sett_infos];
|
||||
gs_free char *tmp_s1 = NULL;
|
||||
gs_free char *tmp_s2 = NULL;
|
||||
g_print("<nm-setting-docs>\n");
|
||||
for (i_sett_infos = 0; i_sett_infos < G_N_ELEMENTS(nm_meta_setting_infos_editor);
|
||||
i_sett_infos++) {
|
||||
const NMMetaSettingInfoEditor *sett_info = &nm_meta_setting_infos_editor[i_sett_infos];
|
||||
gs_free char * tmp_s1 = NULL;
|
||||
gs_free char * tmp_s2 = NULL;
|
||||
|
||||
g_print ("%s<setting", _indent_level (INDENT));
|
||||
g_print (" name=%s", tmp_s1 = _xml_escape_attribute (sett_info->general->setting_name));
|
||||
if (sett_info->alias)
|
||||
g_print ("\n%salias=%s", _indent_level (INDENT + 9), tmp_s2 = _xml_escape_attribute (sett_info->alias));
|
||||
g_print (" >\n");
|
||||
g_print("%s<setting", _indent_level(INDENT));
|
||||
g_print(" name=%s", tmp_s1 = _xml_escape_attribute(sett_info->general->setting_name));
|
||||
if (sett_info->alias)
|
||||
g_print("\n%salias=%s",
|
||||
_indent_level(INDENT + 9),
|
||||
tmp_s2 = _xml_escape_attribute(sett_info->alias));
|
||||
g_print(" >\n");
|
||||
|
||||
for (i_property = 0; i_property < sett_info->properties_num; i_property++) {
|
||||
const NMMetaPropertyInfo *prop_info = sett_info->properties[i_property];
|
||||
gs_free char *tmp2 = NULL;
|
||||
gs_free char *tmp3 = NULL;
|
||||
gs_free char *tmp4 = NULL;
|
||||
for (i_property = 0; i_property < sett_info->properties_num; i_property++) {
|
||||
const NMMetaPropertyInfo *prop_info = sett_info->properties[i_property];
|
||||
gs_free char * tmp2 = NULL;
|
||||
gs_free char * tmp3 = NULL;
|
||||
gs_free char * tmp4 = NULL;
|
||||
|
||||
g_print ("%s<property", _indent_level (2*INDENT));
|
||||
g_print (" name=%s", tmp2 = _xml_escape_attribute (prop_info->property_name));
|
||||
if (prop_info->property_alias)
|
||||
g_print ("\n%salias=%s", _indent_level (2*INDENT + 10), tmp3 = _xml_escape_attribute (prop_info->property_alias));
|
||||
if (prop_info->describe_doc)
|
||||
g_print ("\n%sdescription=%s", _indent_level (2*INDENT + 10), tmp4 = _xml_escape_attribute (prop_info->describe_doc));
|
||||
g_print (" />\n");
|
||||
}
|
||||
g_print("%s<property", _indent_level(2 * INDENT));
|
||||
g_print(" name=%s", tmp2 = _xml_escape_attribute(prop_info->property_name));
|
||||
if (prop_info->property_alias)
|
||||
g_print("\n%salias=%s",
|
||||
_indent_level(2 * INDENT + 10),
|
||||
tmp3 = _xml_escape_attribute(prop_info->property_alias));
|
||||
if (prop_info->describe_doc)
|
||||
g_print("\n%sdescription=%s",
|
||||
_indent_level(2 * INDENT + 10),
|
||||
tmp4 = _xml_escape_attribute(prop_info->describe_doc));
|
||||
g_print(" />\n");
|
||||
}
|
||||
|
||||
g_print ("%s</setting>\n", _indent_level (INDENT));
|
||||
}
|
||||
g_print ("</nm-setting-docs>\n");
|
||||
return 0;
|
||||
g_print("%s</setting>\n", _indent_level(INDENT));
|
||||
}
|
||||
g_print("</nm-setting-docs>\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
1502
clients/cli/nmcli.c
1502
clients/cli/nmcli.c
File diff suppressed because it is too large
Load diff
|
|
@ -11,179 +11,182 @@
|
|||
|
||||
struct _NMPolkitListener;
|
||||
|
||||
typedef char *(*NmcCompEntryFunc) (const char *, int);
|
||||
typedef char *(*NmcCompEntryFunc)(const char *, int);
|
||||
|
||||
/* nmcli exit codes */
|
||||
typedef enum {
|
||||
/* Indicates successful execution */
|
||||
NMC_RESULT_SUCCESS = 0,
|
||||
/* Indicates successful execution */
|
||||
NMC_RESULT_SUCCESS = 0,
|
||||
|
||||
/* Unknown / unspecified error */
|
||||
NMC_RESULT_ERROR_UNKNOWN = 1,
|
||||
/* Unknown / unspecified error */
|
||||
NMC_RESULT_ERROR_UNKNOWN = 1,
|
||||
|
||||
/* Wrong invocation of nmcli */
|
||||
NMC_RESULT_ERROR_USER_INPUT = 2,
|
||||
/* Wrong invocation of nmcli */
|
||||
NMC_RESULT_ERROR_USER_INPUT = 2,
|
||||
|
||||
/* A timeout expired */
|
||||
NMC_RESULT_ERROR_TIMEOUT_EXPIRED = 3,
|
||||
/* A timeout expired */
|
||||
NMC_RESULT_ERROR_TIMEOUT_EXPIRED = 3,
|
||||
|
||||
/* Error in connection activation */
|
||||
NMC_RESULT_ERROR_CON_ACTIVATION = 4,
|
||||
/* Error in connection activation */
|
||||
NMC_RESULT_ERROR_CON_ACTIVATION = 4,
|
||||
|
||||
/* Error in connection deactivation */
|
||||
NMC_RESULT_ERROR_CON_DEACTIVATION = 5,
|
||||
/* Error in connection deactivation */
|
||||
NMC_RESULT_ERROR_CON_DEACTIVATION = 5,
|
||||
|
||||
/* Error in device disconnect */
|
||||
NMC_RESULT_ERROR_DEV_DISCONNECT = 6,
|
||||
/* Error in device disconnect */
|
||||
NMC_RESULT_ERROR_DEV_DISCONNECT = 6,
|
||||
|
||||
/* Error in connection deletion */
|
||||
NMC_RESULT_ERROR_CON_DEL = 7,
|
||||
/* Error in connection deletion */
|
||||
NMC_RESULT_ERROR_CON_DEL = 7,
|
||||
|
||||
/* NetworkManager is not running */
|
||||
NMC_RESULT_ERROR_NM_NOT_RUNNING = 8,
|
||||
/* NetworkManager is not running */
|
||||
NMC_RESULT_ERROR_NM_NOT_RUNNING = 8,
|
||||
|
||||
/* No more used, keep to preserve API */
|
||||
NMC_RESULT_ERROR_VERSIONS_MISMATCH = 9,
|
||||
/* No more used, keep to preserve API */
|
||||
NMC_RESULT_ERROR_VERSIONS_MISMATCH = 9,
|
||||
|
||||
/* Connection/Device/AP not found */
|
||||
NMC_RESULT_ERROR_NOT_FOUND = 10,
|
||||
/* Connection/Device/AP not found */
|
||||
NMC_RESULT_ERROR_NOT_FOUND = 10,
|
||||
|
||||
/* --complete-args signals a file name may follow */
|
||||
NMC_RESULT_COMPLETE_FILE = 65,
|
||||
/* --complete-args signals a file name may follow */
|
||||
NMC_RESULT_COMPLETE_FILE = 65,
|
||||
} NMCResultCode;
|
||||
|
||||
typedef enum {
|
||||
NMC_PRINT_TERSE = 0,
|
||||
NMC_PRINT_NORMAL = 1,
|
||||
NMC_PRINT_PRETTY = 2
|
||||
} NMCPrintOutput;
|
||||
typedef enum { NMC_PRINT_TERSE = 0, NMC_PRINT_NORMAL = 1, NMC_PRINT_PRETTY = 2 } NMCPrintOutput;
|
||||
|
||||
static inline NMMetaAccessorGetType
|
||||
nmc_print_output_to_accessor_get_type (NMCPrintOutput print_output)
|
||||
nmc_print_output_to_accessor_get_type(NMCPrintOutput print_output)
|
||||
{
|
||||
return NM_IN_SET (print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY)
|
||||
? NM_META_ACCESSOR_GET_TYPE_PRETTY
|
||||
: NM_META_ACCESSOR_GET_TYPE_PARSABLE;
|
||||
return NM_IN_SET(print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY)
|
||||
? NM_META_ACCESSOR_GET_TYPE_PRETTY
|
||||
: NM_META_ACCESSOR_GET_TYPE_PARSABLE;
|
||||
}
|
||||
|
||||
/* === Output fields === */
|
||||
|
||||
typedef enum {
|
||||
NMC_OF_FLAG_FIELD_NAMES = 0x00000001, /* Print field names instead of values */
|
||||
NMC_OF_FLAG_SECTION_PREFIX = 0x00000002, /* Use the first value as section prefix for the other field names - just in multiline */
|
||||
NMC_OF_FLAG_MAIN_HEADER_ADD = 0x00000004, /* Print main header in addition to values/field names */
|
||||
NMC_OF_FLAG_MAIN_HEADER_ONLY = 0x00000008, /* Print main header only */
|
||||
NMC_OF_FLAG_FIELD_NAMES = 0x00000001, /* Print field names instead of values */
|
||||
NMC_OF_FLAG_SECTION_PREFIX =
|
||||
0x00000002, /* Use the first value as section prefix for the other field names - just in multiline */
|
||||
NMC_OF_FLAG_MAIN_HEADER_ADD =
|
||||
0x00000004, /* Print main header in addition to values/field names */
|
||||
NMC_OF_FLAG_MAIN_HEADER_ONLY = 0x00000008, /* Print main header only */
|
||||
} NmcOfFlags;
|
||||
|
||||
extern const NMMetaType nmc_meta_type_generic_info;
|
||||
|
||||
typedef struct _NmcOutputField NmcOutputField;
|
||||
typedef struct _NmcOutputField NmcOutputField;
|
||||
typedef struct _NmcMetaGenericInfo NmcMetaGenericInfo;
|
||||
|
||||
struct _NmcOutputField {
|
||||
const NMMetaAbstractInfo *info;
|
||||
int width; /* Width in screen columns */
|
||||
void *value; /* Value of current field - char* or char** (NULL-terminated array) */
|
||||
gboolean value_is_array; /* Whether value is char** instead of char* */
|
||||
gboolean free_value; /* Whether to free the value */
|
||||
NmcOfFlags flags; /* Flags - whether and how to print values/field names/headers */
|
||||
NMMetaColor color; /* Use this color to print value */
|
||||
const NMMetaAbstractInfo *info;
|
||||
int width; /* Width in screen columns */
|
||||
void * value; /* Value of current field - char* or char** (NULL-terminated array) */
|
||||
gboolean value_is_array; /* Whether value is char** instead of char* */
|
||||
gboolean free_value; /* Whether to free the value */
|
||||
NmcOfFlags flags; /* Flags - whether and how to print values/field names/headers */
|
||||
NMMetaColor color; /* Use this color to print value */
|
||||
};
|
||||
|
||||
typedef struct _NmcConfig {
|
||||
NMCPrintOutput print_output; /* Output mode */
|
||||
bool use_colors; /* Whether to use colors for output: option '--color' */
|
||||
bool multiline_output; /* Multiline output instead of default tabular */
|
||||
bool escape_values; /* Whether to escape ':' and '\' in terse tabular mode */
|
||||
bool in_editor; /* Whether running the editor - nmcli con edit' */
|
||||
bool show_secrets; /* Whether to display secrets (both input and output): option '--show-secrets' */
|
||||
bool overview; /* Overview mode (hide default values) */
|
||||
const char *palette[_NM_META_COLOR_NUM]; /* Color palette */
|
||||
NMCPrintOutput print_output; /* Output mode */
|
||||
bool use_colors; /* Whether to use colors for output: option '--color' */
|
||||
bool multiline_output; /* Multiline output instead of default tabular */
|
||||
bool escape_values; /* Whether to escape ':' and '\' in terse tabular mode */
|
||||
bool in_editor; /* Whether running the editor - nmcli con edit' */
|
||||
bool
|
||||
show_secrets; /* Whether to display secrets (both input and output): option '--show-secrets' */
|
||||
bool overview; /* Overview mode (hide default values) */
|
||||
const char *palette[_NM_META_COLOR_NUM]; /* Color palette */
|
||||
} NmcConfig;
|
||||
|
||||
typedef struct {
|
||||
pid_t pid;
|
||||
pid_t pid;
|
||||
} NmcPagerData;
|
||||
|
||||
typedef struct _NmcOutputData {
|
||||
GPtrArray *output_data; /* GPtrArray of arrays of NmcOutputField structs - accumulates data for output */
|
||||
GPtrArray *
|
||||
output_data; /* GPtrArray of arrays of NmcOutputField structs - accumulates data for output */
|
||||
} NmcOutputData;
|
||||
|
||||
/* NmCli - main structure */
|
||||
typedef struct _NmCli {
|
||||
NMClient *client; /* Pointer to NMClient of libnm */
|
||||
NMClient *client; /* Pointer to NMClient of libnm */
|
||||
|
||||
NMCResultCode return_value; /* Return code of nmcli */
|
||||
GString *return_text; /* Reason text */
|
||||
NMCResultCode return_value; /* Return code of nmcli */
|
||||
GString * return_text; /* Reason text */
|
||||
|
||||
NmcPagerData pager_data;
|
||||
NmcPagerData pager_data;
|
||||
|
||||
int timeout; /* Operation timeout */
|
||||
int timeout; /* Operation timeout */
|
||||
|
||||
NMSecretAgentSimple *secret_agent; /* Secret agent */
|
||||
GHashTable *pwds_hash; /* Hash table with passwords in passwd-file */
|
||||
struct _NMPolkitListener *pk_listener; /* polkit agent listener */
|
||||
NMSecretAgentSimple * secret_agent; /* Secret agent */
|
||||
GHashTable * pwds_hash; /* Hash table with passwords in passwd-file */
|
||||
struct _NMPolkitListener *pk_listener; /* polkit agent listener */
|
||||
|
||||
int should_wait; /* Semaphore indicating whether nmcli should not end or not yet */
|
||||
gboolean nowait_flag; /* '--nowait' option; used for passing to callbacks */
|
||||
gboolean mode_specified; /* Whether tabular/multiline mode was specified via '--mode' option */
|
||||
union {
|
||||
const NmcConfig nmc_config;
|
||||
NmcConfig nmc_config_mutable;
|
||||
};
|
||||
char *required_fields; /* Required fields in output: '--fields' option */
|
||||
gboolean ask; /* Ask for missing parameters: option '--ask' */
|
||||
gboolean complete; /* Autocomplete the command line */
|
||||
gboolean editor_status_line; /* Whether to display status line in connection editor */
|
||||
gboolean editor_save_confirmation; /* Whether to ask for confirmation on saving connections with 'autoconnect=yes' */
|
||||
int should_wait; /* Semaphore indicating whether nmcli should not end or not yet */
|
||||
gboolean nowait_flag; /* '--nowait' option; used for passing to callbacks */
|
||||
gboolean mode_specified; /* Whether tabular/multiline mode was specified via '--mode' option */
|
||||
union {
|
||||
const NmcConfig nmc_config;
|
||||
NmcConfig nmc_config_mutable;
|
||||
};
|
||||
char * required_fields; /* Required fields in output: '--fields' option */
|
||||
gboolean ask; /* Ask for missing parameters: option '--ask' */
|
||||
gboolean complete; /* Autocomplete the command line */
|
||||
gboolean editor_status_line; /* Whether to display status line in connection editor */
|
||||
gboolean
|
||||
editor_save_confirmation; /* Whether to ask for confirmation on saving connections with 'autoconnect=yes' */
|
||||
|
||||
char *palette_buffer; /* Buffer with sequences for terminal-colors.d(5)-based coloring. */
|
||||
char *palette_buffer; /* Buffer with sequences for terminal-colors.d(5)-based coloring. */
|
||||
} NmCli;
|
||||
|
||||
extern const NmCli *const nm_cli_global_readline;
|
||||
|
||||
/* Error quark for GError domain */
|
||||
#define NMCLI_ERROR (nmcli_error_quark ())
|
||||
GQuark nmcli_error_quark (void);
|
||||
#define NMCLI_ERROR (nmcli_error_quark())
|
||||
GQuark nmcli_error_quark(void);
|
||||
|
||||
extern GMainLoop *loop;
|
||||
|
||||
gboolean nmc_seen_sigint (void);
|
||||
void nmc_clear_sigint (void);
|
||||
void nmc_set_sigquit_internal (void);
|
||||
void nmc_exit (void);
|
||||
gboolean nmc_seen_sigint(void);
|
||||
void nmc_clear_sigint(void);
|
||||
void nmc_set_sigquit_internal(void);
|
||||
void nmc_exit(void);
|
||||
|
||||
void nm_cli_spawn_pager (const NmcConfig *nmc_config,
|
||||
NmcPagerData *pager_data);
|
||||
void nm_cli_spawn_pager(const NmcConfig *nmc_config, NmcPagerData *pager_data);
|
||||
|
||||
void nmc_empty_output_fields (NmcOutputData *output_data);
|
||||
void nmc_empty_output_fields(NmcOutputData *output_data);
|
||||
|
||||
#define NMC_OUTPUT_DATA_DEFINE_SCOPED(out) \
|
||||
gs_unref_array GArray *out##_indices = NULL; \
|
||||
nm_auto (nmc_empty_output_fields) NmcOutputData out = { \
|
||||
.output_data = g_ptr_array_new_full (20, g_free), \
|
||||
}
|
||||
#define NMC_OUTPUT_DATA_DEFINE_SCOPED(out) \
|
||||
gs_unref_array GArray * out##_indices = NULL; \
|
||||
nm_auto(nmc_empty_output_fields) NmcOutputData out = { \
|
||||
.output_data = g_ptr_array_new_full(20, g_free), \
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
struct _NMCCommand;
|
||||
|
||||
typedef struct _NMCCommand {
|
||||
const char *cmd;
|
||||
void (*func) (const struct _NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv);
|
||||
void (*usage) (void);
|
||||
bool needs_client;
|
||||
bool needs_nm_running;
|
||||
const char *cmd;
|
||||
void (*func)(const struct _NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
|
||||
void (*usage)(void);
|
||||
bool needs_client;
|
||||
bool needs_nm_running;
|
||||
} NMCCommand;
|
||||
|
||||
void nmc_command_func_agent (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv);
|
||||
void nmc_command_func_general (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv);
|
||||
void nmc_command_func_networking (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv);
|
||||
void nmc_command_func_radio (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv);
|
||||
void nmc_command_func_monitor (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv);
|
||||
void nmc_command_func_overview (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv);
|
||||
void nmc_command_func_connection (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv);
|
||||
void nmc_command_func_device (const NMCCommand *cmd, NmCli *nmc, int argc, const char *const*argv);
|
||||
void nmc_command_func_agent(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
|
||||
void nmc_command_func_general(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
|
||||
void
|
||||
nmc_command_func_networking(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
|
||||
void nmc_command_func_radio(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
|
||||
void nmc_command_func_monitor(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
|
||||
void
|
||||
nmc_command_func_overview(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
|
||||
void
|
||||
nmc_command_func_connection(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
|
||||
void nmc_command_func_device(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -15,90 +15,82 @@
|
|||
#include "common.h"
|
||||
|
||||
static char *
|
||||
polkit_read_passwd (gpointer instance,
|
||||
const char *action_id,
|
||||
const char *message,
|
||||
const char *user,
|
||||
gpointer user_data)
|
||||
polkit_read_passwd(gpointer instance,
|
||||
const char *action_id,
|
||||
const char *message,
|
||||
const char *user,
|
||||
gpointer user_data)
|
||||
{
|
||||
NmCli *nmc = user_data;
|
||||
NmCli *nmc = user_data;
|
||||
|
||||
g_print ("%s\n", message);
|
||||
g_print ("(action_id: %s)\n", action_id);
|
||||
g_print("%s\n", message);
|
||||
g_print("(action_id: %s)\n", action_id);
|
||||
|
||||
/* Ask user for polkit authorization password */
|
||||
if (user) {
|
||||
return nmc_readline_echo (&nmc->nmc_config, FALSE, "password (%s): ", user);
|
||||
}
|
||||
return nmc_readline_echo (&nmc->nmc_config, FALSE, "password: ");
|
||||
/* Ask user for polkit authorization password */
|
||||
if (user) {
|
||||
return nmc_readline_echo(&nmc->nmc_config, FALSE, "password (%s): ", user);
|
||||
}
|
||||
return nmc_readline_echo(&nmc->nmc_config, FALSE, "password: ");
|
||||
}
|
||||
|
||||
static void
|
||||
polkit_error (gpointer instance,
|
||||
const char *error,
|
||||
gpointer user_data)
|
||||
polkit_error(gpointer instance, const char *error, gpointer user_data)
|
||||
{
|
||||
g_printerr (_("Error: polkit agent failed: %s\n"), error);
|
||||
g_printerr(_("Error: polkit agent failed: %s\n"), error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nmc_polkit_agent_init (NmCli* nmc, gboolean for_session, GError **error)
|
||||
nmc_polkit_agent_init(NmCli *nmc, gboolean for_session, GError **error)
|
||||
{
|
||||
NMPolkitListener *listener;
|
||||
GDBusConnection *dbus_connection = NULL;
|
||||
NMPolkitListener *listener;
|
||||
GDBusConnection * dbus_connection = NULL;
|
||||
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
|
||||
|
||||
if (nmc->client && nm_client_get_dbus_connection (nmc->client)) {
|
||||
dbus_connection = nm_client_get_dbus_connection (nmc->client);
|
||||
listener = nm_polkit_listener_new (dbus_connection, for_session);
|
||||
} else {
|
||||
dbus_connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM,
|
||||
NULL,
|
||||
error);
|
||||
if (nmc->client && nm_client_get_dbus_connection(nmc->client)) {
|
||||
dbus_connection = nm_client_get_dbus_connection(nmc->client);
|
||||
listener = nm_polkit_listener_new(dbus_connection, for_session);
|
||||
} else {
|
||||
dbus_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error);
|
||||
|
||||
if (!dbus_connection) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!dbus_connection) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
listener = nm_polkit_listener_new (dbus_connection, for_session);
|
||||
g_object_unref (dbus_connection);
|
||||
}
|
||||
listener = nm_polkit_listener_new(dbus_connection, for_session);
|
||||
g_object_unref(dbus_connection);
|
||||
}
|
||||
|
||||
g_signal_connect (listener,
|
||||
NM_POLKIT_LISTENER_SIGNAL_REQUEST_SYNC,
|
||||
G_CALLBACK (polkit_read_passwd),
|
||||
nmc);
|
||||
g_signal_connect (listener,
|
||||
NM_POLKIT_LISTENER_SIGNAL_ERROR,
|
||||
G_CALLBACK (polkit_error),
|
||||
NULL);
|
||||
g_signal_connect(listener,
|
||||
NM_POLKIT_LISTENER_SIGNAL_REQUEST_SYNC,
|
||||
G_CALLBACK(polkit_read_passwd),
|
||||
nmc);
|
||||
g_signal_connect(listener, NM_POLKIT_LISTENER_SIGNAL_ERROR, G_CALLBACK(polkit_error), NULL);
|
||||
|
||||
nmc->pk_listener = listener;
|
||||
return TRUE;
|
||||
nmc->pk_listener = listener;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nmc_polkit_agent_fini (NmCli* nmc)
|
||||
nmc_polkit_agent_fini(NmCli *nmc)
|
||||
{
|
||||
if (nmc->pk_listener) {
|
||||
g_clear_object (&nmc->pk_listener);
|
||||
}
|
||||
if (nmc->pk_listener) {
|
||||
g_clear_object(&nmc->pk_listener);
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
nmc_start_polkit_agent_start_try (NmCli *nmc)
|
||||
nmc_start_polkit_agent_start_try(NmCli *nmc)
|
||||
{
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
/* We don't register polkit agent at all when running non-interactively */
|
||||
if (!nmc->ask)
|
||||
return TRUE;
|
||||
/* We don't register polkit agent at all when running non-interactively */
|
||||
if (!nmc->ask)
|
||||
return TRUE;
|
||||
|
||||
if (!nmc_polkit_agent_init (nmc, FALSE, &error)) {
|
||||
g_printerr (_("Warning: polkit agent initialization failed: %s\n"),
|
||||
error->message);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
if (!nmc_polkit_agent_init(nmc, FALSE, &error)) {
|
||||
g_printerr(_("Warning: polkit agent initialization failed: %s\n"), error->message);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@
|
|||
|
||||
#include "nmcli.h"
|
||||
|
||||
gboolean nmc_polkit_agent_init (NmCli *nmc, gboolean for_session, GError **error);
|
||||
void nmc_polkit_agent_fini (NmCli* nmc);
|
||||
gboolean nmc_polkit_agent_init(NmCli *nmc, gboolean for_session, GError **error);
|
||||
void nmc_polkit_agent_fini(NmCli *nmc);
|
||||
|
||||
gboolean nmc_start_polkit_agent_start_try (NmCli *nmc);
|
||||
gboolean nmc_start_polkit_agent_start_try(NmCli *nmc);
|
||||
|
||||
#endif /* __NMC_POLKIT_AGENT_H__ */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -13,28 +13,26 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
void nmc_setting_ip4_connect_handlers (NMSettingIPConfig *setting);
|
||||
void nmc_setting_ip6_connect_handlers (NMSettingIPConfig *setting);
|
||||
void nmc_setting_proxy_connect_handlers (NMSettingProxy *setting);
|
||||
void nmc_setting_wireless_connect_handlers (NMSettingWireless *setting);
|
||||
void nmc_setting_connection_connect_handlers (NMSettingConnection *setting, NMConnection *connection);
|
||||
void nmc_setting_ip4_connect_handlers(NMSettingIPConfig *setting);
|
||||
void nmc_setting_ip6_connect_handlers(NMSettingIPConfig *setting);
|
||||
void nmc_setting_proxy_connect_handlers(NMSettingProxy *setting);
|
||||
void nmc_setting_wireless_connect_handlers(NMSettingWireless *setting);
|
||||
void nmc_setting_connection_connect_handlers(NMSettingConnection *setting,
|
||||
NMConnection * connection);
|
||||
|
||||
char **nmc_setting_get_valid_properties (NMSetting *setting);
|
||||
char *nmc_setting_get_property_desc (NMSetting *setting, const char *prop);
|
||||
const char *const*nmc_setting_get_property_allowed_values (NMSetting *setting, const char *prop, char ***out_to_free);
|
||||
char *nmc_setting_get_property (NMSetting *setting,
|
||||
const char *prop,
|
||||
GError **error);
|
||||
char *nmc_setting_get_property_parsable (NMSetting *setting,
|
||||
const char *prop,
|
||||
GError **error);
|
||||
gboolean nmc_setting_set_property (NMClient *client,
|
||||
NMSetting *setting,
|
||||
const char *prop,
|
||||
NMMetaAccessorModifier modifier,
|
||||
const char *val,
|
||||
GError **error);
|
||||
char **nmc_setting_get_valid_properties(NMSetting *setting);
|
||||
char * nmc_setting_get_property_desc(NMSetting *setting, const char *prop);
|
||||
const char *const *
|
||||
nmc_setting_get_property_allowed_values(NMSetting *setting, const char *prop, char ***out_to_free);
|
||||
char * nmc_setting_get_property(NMSetting *setting, const char *prop, GError **error);
|
||||
char * nmc_setting_get_property_parsable(NMSetting *setting, const char *prop, GError **error);
|
||||
gboolean nmc_setting_set_property(NMClient * client,
|
||||
NMSetting * setting,
|
||||
const char * prop,
|
||||
NMMetaAccessorModifier modifier,
|
||||
const char * val,
|
||||
GError ** error);
|
||||
|
||||
gboolean setting_details (const NmcConfig *nmc_config, NMSetting *setting, const char *one_prop);
|
||||
gboolean setting_details(const NmcConfig *nmc_config, NMSetting *setting, const char *one_prop);
|
||||
|
||||
#endif /* NMC_SETTINGS_H */
|
||||
|
|
|
|||
2459
clients/cli/utils.c
2459
clients/cli/utils.c
File diff suppressed because it is too large
Load diff
|
|
@ -11,358 +11,359 @@
|
|||
/* === Types === */
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
gboolean has_value;
|
||||
const char **value;
|
||||
gboolean mandatory;
|
||||
gboolean found;
|
||||
const char * name;
|
||||
gboolean has_value;
|
||||
const char **value;
|
||||
gboolean mandatory;
|
||||
gboolean found;
|
||||
} nmc_arg_t;
|
||||
|
||||
/* === Functions === */
|
||||
int next_arg (NmCli *nmc, int *argc, const char *const**argv, ...);
|
||||
gboolean nmc_arg_is_help (const char *arg);
|
||||
gboolean nmc_arg_is_option (const char *arg, const char *opt_name);
|
||||
gboolean nmc_parse_args (nmc_arg_t *arg_arr, gboolean last, int *argc, const char *const**argv, GError **error);
|
||||
char *ssid_to_hex (const char *str, gsize len);
|
||||
void nmc_terminal_erase_line (void);
|
||||
void nmc_terminal_show_progress (const char *str);
|
||||
pid_t nmc_terminal_spawn_pager (const NmcConfig *nmc_config);
|
||||
char *nmc_colorize (const NmcConfig *nmc_config, NMMetaColor color, const char * fmt, ...) _nm_printf (3, 4);
|
||||
void nmc_filter_out_colors_inplace (char *str);
|
||||
char *nmc_filter_out_colors (const char *str);
|
||||
char *nmc_get_user_input (const char *ask_str);
|
||||
int nmc_string_to_arg_array (const char *line, const char *delim, gboolean unquote,
|
||||
char ***argv, int *argc);
|
||||
const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error);
|
||||
char * nmc_util_strv_for_display (const char *const*strv, gboolean brackets);
|
||||
int nmc_string_screen_width (const char *start, const char *end);
|
||||
void set_val_str (NmcOutputField fields_array[], guint32 index, char *value);
|
||||
void set_val_strc (NmcOutputField fields_array[], guint32 index, const char *value);
|
||||
void set_val_arr (NmcOutputField fields_array[], guint32 index, char **value);
|
||||
void set_val_arrc (NmcOutputField fields_array[], guint32 index, const char **value);
|
||||
void set_val_color_all (NmcOutputField fields_array[], NMMetaColor color);
|
||||
void nmc_free_output_field_values (NmcOutputField fields_array[]);
|
||||
int next_arg(NmCli *nmc, int *argc, const char *const **argv, ...);
|
||||
gboolean nmc_arg_is_help(const char *arg);
|
||||
gboolean nmc_arg_is_option(const char *arg, const char *opt_name);
|
||||
gboolean nmc_parse_args(nmc_arg_t * arg_arr,
|
||||
gboolean last,
|
||||
int * argc,
|
||||
const char *const **argv,
|
||||
GError ** error);
|
||||
char * ssid_to_hex(const char *str, gsize len);
|
||||
void nmc_terminal_erase_line(void);
|
||||
void nmc_terminal_show_progress(const char *str);
|
||||
pid_t nmc_terminal_spawn_pager(const NmcConfig *nmc_config);
|
||||
char * nmc_colorize(const NmcConfig *nmc_config, NMMetaColor color, const char *fmt, ...)
|
||||
_nm_printf(3, 4);
|
||||
void nmc_filter_out_colors_inplace(char *str);
|
||||
char * nmc_filter_out_colors(const char *str);
|
||||
char * nmc_get_user_input(const char *ask_str);
|
||||
int nmc_string_to_arg_array(const char *line,
|
||||
const char *delim,
|
||||
gboolean unquote,
|
||||
char *** argv,
|
||||
int * argc);
|
||||
const char *nmc_string_is_valid(const char *input, const char **allowed, GError **error);
|
||||
char * nmc_util_strv_for_display(const char *const *strv, gboolean brackets);
|
||||
int nmc_string_screen_width(const char *start, const char *end);
|
||||
void set_val_str(NmcOutputField fields_array[], guint32 index, char *value);
|
||||
void set_val_strc(NmcOutputField fields_array[], guint32 index, const char *value);
|
||||
void set_val_arr(NmcOutputField fields_array[], guint32 index, char **value);
|
||||
void set_val_arrc(NmcOutputField fields_array[], guint32 index, const char **value);
|
||||
void set_val_color_all(NmcOutputField fields_array[], NMMetaColor color);
|
||||
void nmc_free_output_field_values(NmcOutputField fields_array[]);
|
||||
|
||||
GArray *parse_output_fields (const char *fields_str,
|
||||
const NMMetaAbstractInfo *const* fields_array,
|
||||
gboolean parse_groups,
|
||||
GPtrArray **group_fields,
|
||||
GError **error);
|
||||
NmcOutputField *nmc_dup_fields_array (const NMMetaAbstractInfo *const*fields, NmcOfFlags flags);
|
||||
void nmc_empty_output_fields (NmcOutputData *output_data);
|
||||
void print_required_fields (const NmcConfig *nmc_config,
|
||||
NmcPagerData *pager_data,
|
||||
NmcOfFlags of_flags,
|
||||
const GArray *indices,
|
||||
const char *header_name,
|
||||
int indent,
|
||||
const NmcOutputField *field_values);
|
||||
void print_data_prepare_width (GPtrArray *output_data);
|
||||
void print_data (const NmcConfig *nmc_config,
|
||||
NmcPagerData *pager_data,
|
||||
const GArray *indices,
|
||||
const char *header_name,
|
||||
int indent,
|
||||
const NmcOutputData *out);
|
||||
GArray * parse_output_fields(const char * fields_str,
|
||||
const NMMetaAbstractInfo *const *fields_array,
|
||||
gboolean parse_groups,
|
||||
GPtrArray ** group_fields,
|
||||
GError ** error);
|
||||
NmcOutputField *nmc_dup_fields_array(const NMMetaAbstractInfo *const *fields, NmcOfFlags flags);
|
||||
void nmc_empty_output_fields(NmcOutputData *output_data);
|
||||
void print_required_fields(const NmcConfig * nmc_config,
|
||||
NmcPagerData * pager_data,
|
||||
NmcOfFlags of_flags,
|
||||
const GArray * indices,
|
||||
const char * header_name,
|
||||
int indent,
|
||||
const NmcOutputField *field_values);
|
||||
void print_data_prepare_width(GPtrArray *output_data);
|
||||
void print_data(const NmcConfig * nmc_config,
|
||||
NmcPagerData * pager_data,
|
||||
const GArray * indices,
|
||||
const char * header_name,
|
||||
int indent,
|
||||
const NmcOutputData *out);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
extern const NMMetaEnvironment *const nmc_meta_environment;
|
||||
extern const NmCli *const nmc_meta_environment_arg;
|
||||
extern const NmCli *const nmc_meta_environment_arg;
|
||||
|
||||
typedef enum {
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_RUNNING = 0,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_VERSION,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STATE,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STARTUP,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_CONNECTIVITY,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NETWORKING,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIFI_HW,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIFI,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WWAN_HW,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WWAN,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIMAX_HW,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIMAX,
|
||||
_NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_RUNNING = 0,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_VERSION,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STATE,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_STARTUP,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_CONNECTIVITY,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NETWORKING,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIFI_HW,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIFI,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WWAN_HW,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WWAN,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIMAX_HW,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_WIMAX,
|
||||
_NMC_GENERIC_INFO_TYPE_GENERAL_STATUS_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_PERMISSION = 0,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_VALUE,
|
||||
_NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_PERMISSION = 0,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_VALUE,
|
||||
_NMC_GENERIC_INFO_TYPE_GENERAL_PERMISSIONS_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_LEVEL = 0,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_DOMAINS,
|
||||
_NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_LEVEL = 0,
|
||||
NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_DOMAINS,
|
||||
_NMC_GENERIC_INFO_TYPE_GENERAL_LOGGING_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS = 0,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DNS,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DOMAIN,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS,
|
||||
_NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ADDRESS = 0,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_GATEWAY,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_ROUTE,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DNS,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_DOMAIN,
|
||||
NMC_GENERIC_INFO_TYPE_IP4_CONFIG_WINS,
|
||||
_NMC_GENERIC_INFO_TYPE_IP4_CONFIG_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ADDRESS = 0,
|
||||
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_GATEWAY,
|
||||
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ROUTE,
|
||||
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DNS,
|
||||
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DOMAIN,
|
||||
_NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ADDRESS = 0,
|
||||
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_GATEWAY,
|
||||
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_ROUTE,
|
||||
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DNS,
|
||||
NMC_GENERIC_INFO_TYPE_IP6_CONFIG_DOMAIN,
|
||||
_NMC_GENERIC_INFO_TYPE_IP6_CONFIG_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_OPTION = 0,
|
||||
_NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_OPTION = 0,
|
||||
_NMC_GENERIC_INFO_TYPE_DHCP_CONFIG_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_NAME = 0,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_UUID,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_TYPE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP_REAL,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT_PRIORITY,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_READONLY,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_DBUS_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_DEVICE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_STATE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_SLAVE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_FILENAME,
|
||||
_NMC_GENERIC_INFO_TYPE_CON_SHOW_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_NAME = 0,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_UUID,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_TYPE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP_REAL,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_AUTOCONNECT_PRIORITY,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_READONLY,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_DBUS_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_DEVICE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_STATE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_ACTIVE_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_SLAVE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_SHOW_FILENAME,
|
||||
_NMC_GENERIC_INFO_TYPE_CON_SHOW_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NAME = 0,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_UUID,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEVICES,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_IP_IFACE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_STATE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT6,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_SPEC_OBJECT,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_VPN,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DBUS_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_CON_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_ZONE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_MASTER_PATH,
|
||||
_NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NAME = 0,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_UUID,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEVICES,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_IP_IFACE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_STATE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DEFAULT6,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_SPEC_OBJECT,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_VPN,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_DBUS_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_CON_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_ZONE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_MASTER_PATH,
|
||||
_NMC_GENERIC_INFO_TYPE_CON_ACTIVE_GENERAL_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_CON_VPN_TYPE = 0,
|
||||
NMC_GENERIC_INFO_TYPE_CON_VPN_USERNAME,
|
||||
NMC_GENERIC_INFO_TYPE_CON_VPN_GATEWAY,
|
||||
NMC_GENERIC_INFO_TYPE_CON_VPN_BANNER,
|
||||
NMC_GENERIC_INFO_TYPE_CON_VPN_VPN_STATE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_VPN_CFG,
|
||||
_NMC_GENERIC_INFO_TYPE_CON_ACTIVE_VPN_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_CON_VPN_TYPE = 0,
|
||||
NMC_GENERIC_INFO_TYPE_CON_VPN_USERNAME,
|
||||
NMC_GENERIC_INFO_TYPE_CON_VPN_GATEWAY,
|
||||
NMC_GENERIC_INFO_TYPE_CON_VPN_BANNER,
|
||||
NMC_GENERIC_INFO_TYPE_CON_VPN_VPN_STATE,
|
||||
NMC_GENERIC_INFO_TYPE_CON_VPN_CFG,
|
||||
_NMC_GENERIC_INFO_TYPE_CON_ACTIVE_VPN_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_DEVICE = 0,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_TYPE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_STATE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_IP4_CONNECTIVITY,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_IP6_CONNECTIVITY,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_DBUS_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_CONNECTION,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_CON_UUID,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_CON_PATH,
|
||||
_NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_DEVICE = 0,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_TYPE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_STATE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_IP4_CONNECTIVITY,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_IP6_CONNECTIVITY,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_DBUS_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_CONNECTION,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_CON_UUID,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_CON_PATH,
|
||||
_NMC_GENERIC_INFO_TYPE_DEVICE_STATUS_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DEVICE = 0,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_TYPE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NM_TYPE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DBUS_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_VENDOR,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PRODUCT,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DRIVER,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DRIVER_VERSION,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_FIRMWARE_VERSION,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_HWADDR,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_MTU,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_STATE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_REASON,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP4_CONNECTIVITY,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP6_CONNECTIVITY,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_UDI,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP_IFACE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IS_SOFTWARE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NM_MANAGED,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_AUTOCONNECT,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_FIRMWARE_MISSING,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NM_PLUGIN_MISSING,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PHYS_PORT_ID,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_CONNECTION,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_CON_UUID,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_CON_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_METERED,
|
||||
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DEVICE = 0,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_TYPE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NM_TYPE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DBUS_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_VENDOR,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PRODUCT,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DRIVER,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_DRIVER_VERSION,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_FIRMWARE_VERSION,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_HWADDR,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_MTU,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_STATE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_REASON,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP4_CONNECTIVITY,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP6_CONNECTIVITY,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_UDI,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IP_IFACE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_IS_SOFTWARE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NM_MANAGED,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_AUTOCONNECT,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_FIRMWARE_MISSING,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NM_PLUGIN_MISSING,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_PHYS_PORT_ID,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_CONNECTION,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_CON_UUID,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_CON_PATH,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_METERED,
|
||||
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_GENERAL_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CONNECTIONS_AVAILABLE_CONNECTION_PATHS = 0,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CONNECTIONS_AVAILABLE_CONNECTIONS,
|
||||
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CONNECTIONS_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CONNECTIONS_AVAILABLE_CONNECTION_PATHS = 0,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CONNECTIONS_AVAILABLE_CONNECTIONS,
|
||||
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CONNECTIONS_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_CARRIER_DETECT = 0,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_SPEED,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_IS_SOFTWARE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_SRIOV,
|
||||
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_CARRIER_DETECT = 0,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_SPEED,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_IS_SOFTWARE,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_SRIOV,
|
||||
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_CAPABILITIES_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIRED_PROPERTIES_CARRIER = 0,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIRED_PROPERTIES_S390_SUBCHANNELS,
|
||||
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIRED_PROPERTIES_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIRED_PROPERTIES_CARRIER = 0,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIRED_PROPERTIES_S390_SUBCHANNELS,
|
||||
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIRED_PROPERTIES_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_WEP = 0,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_WPA,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_WPA2,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_TKIP,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_CCMP,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_AP,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_ADHOC,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_2GHZ,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_5GHZ,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_MESH,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_IBSS_RSN,
|
||||
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_WEP = 0,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_WPA,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_WPA2,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_TKIP,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_CCMP,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_AP,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_ADHOC,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_2GHZ,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_5GHZ,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_MESH,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_IBSS_RSN,
|
||||
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_WIFI_PROPERTIES_NUM,
|
||||
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_UP = 0,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_LOWER_UP,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_CARRIER,
|
||||
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_NUM,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_UP = 0,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_LOWER_UP,
|
||||
NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_CARRIER,
|
||||
_NMC_GENERIC_INFO_TYPE_DEVICE_DETAIL_INTERFACE_FLAGS_NUM,
|
||||
|
||||
} NmcGenericInfoType;
|
||||
|
||||
#define NMC_HANDLE_COLOR(color) \
|
||||
G_STMT_START { \
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_COLOR) \
|
||||
return GINT_TO_POINTER (color); \
|
||||
} G_STMT_END
|
||||
#define NMC_HANDLE_COLOR(color) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_COLOR) \
|
||||
return GINT_TO_POINTER(color); \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
struct _NmcMetaGenericInfo {
|
||||
union {
|
||||
NMObjBaseInst parent;
|
||||
const NMMetaType *meta_type;
|
||||
};
|
||||
NmcGenericInfoType info_type;
|
||||
const char *name;
|
||||
const char *name_header;
|
||||
const NmcMetaGenericInfo *const*nested;
|
||||
union {
|
||||
NMObjBaseInst parent;
|
||||
const NMMetaType *meta_type;
|
||||
};
|
||||
NmcGenericInfoType info_type;
|
||||
const char * name;
|
||||
const char * name_header;
|
||||
const NmcMetaGenericInfo *const *nested;
|
||||
|
||||
#define NMC_META_GENERIC_INFO_GET_FCN_ARGS \
|
||||
const NMMetaEnvironment *environment, \
|
||||
gpointer environment_user_data, \
|
||||
const NmcMetaGenericInfo *info, \
|
||||
gpointer target, \
|
||||
gpointer target_data, \
|
||||
NMMetaAccessorGetType get_type, \
|
||||
NMMetaAccessorGetFlags get_flags, \
|
||||
NMMetaAccessorGetOutFlags *out_flags, \
|
||||
gboolean *out_is_default, \
|
||||
gpointer *out_to_free
|
||||
#define NMC_META_GENERIC_INFO_GET_FCN_ARGS \
|
||||
const NMMetaEnvironment *environment, gpointer environment_user_data, \
|
||||
const NmcMetaGenericInfo *info, gpointer target, gpointer target_data, \
|
||||
NMMetaAccessorGetType get_type, NMMetaAccessorGetFlags get_flags, \
|
||||
NMMetaAccessorGetOutFlags *out_flags, gboolean *out_is_default, gpointer *out_to_free
|
||||
|
||||
gconstpointer (*get_fcn) (NMC_META_GENERIC_INFO_GET_FCN_ARGS);
|
||||
gconstpointer (*get_fcn)(NMC_META_GENERIC_INFO_GET_FCN_ARGS);
|
||||
};
|
||||
|
||||
#define NMC_META_GENERIC(n, ...) \
|
||||
(&((NmcMetaGenericInfo) { \
|
||||
.meta_type = &nmc_meta_type_generic_info, \
|
||||
.name = n, \
|
||||
__VA_ARGS__ \
|
||||
}))
|
||||
(&((NmcMetaGenericInfo){.meta_type = &nmc_meta_type_generic_info, .name = n, __VA_ARGS__}))
|
||||
|
||||
#define NMC_META_GENERIC_WITH_NESTED(n, nest, ...) \
|
||||
NMC_META_GENERIC (n, .nested = (nest), __VA_ARGS__)
|
||||
NMC_META_GENERIC(n, .nested = (nest), __VA_ARGS__)
|
||||
|
||||
#define NMC_META_GENERIC_GROUP(_group_name, _nested, _name_header) \
|
||||
((const NMMetaAbstractInfo *const*) ((const NmcMetaGenericInfo *const[]) { \
|
||||
NMC_META_GENERIC_WITH_NESTED (_group_name,_nested, .name_header = _name_header), \
|
||||
NULL, \
|
||||
}))
|
||||
#define NMC_META_GENERIC_GROUP(_group_name, _nested, _name_header) \
|
||||
((const NMMetaAbstractInfo *const *) ((const NmcMetaGenericInfo *const[]){ \
|
||||
NMC_META_GENERIC_WITH_NESTED(_group_name, _nested, .name_header = _name_header), \
|
||||
NULL, \
|
||||
}))
|
||||
|
||||
static inline const char *
|
||||
nmc_meta_generic_get_str_i18n (const char *s, NMMetaAccessorGetType get_type)
|
||||
nmc_meta_generic_get_str_i18n(const char *s, NMMetaAccessorGetType get_type)
|
||||
{
|
||||
if (!NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY,
|
||||
NM_META_ACCESSOR_GET_TYPE_PARSABLE))
|
||||
g_return_val_if_reached (NULL);
|
||||
if (!NM_IN_SET(get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE))
|
||||
g_return_val_if_reached(NULL);
|
||||
|
||||
if (!s)
|
||||
return NULL;
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
||||
return gettext (s);
|
||||
return s;
|
||||
if (!s)
|
||||
return NULL;
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
||||
return gettext(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
static inline const char *
|
||||
nmc_meta_generic_get_str_i18n_null (const char *s, NMMetaAccessorGetType get_type)
|
||||
nmc_meta_generic_get_str_i18n_null(const char *s, NMMetaAccessorGetType get_type)
|
||||
{
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) {
|
||||
/* in parsable mode, return NULL. That is useful if @s is a pretty string
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PARSABLE) {
|
||||
/* in parsable mode, return NULL. That is useful if @s is a pretty string
|
||||
* to describe a missing value (like "(unknown)"). We don't want to print
|
||||
* that for parsable mode. */
|
||||
return NULL;
|
||||
}
|
||||
return nmc_meta_generic_get_str_i18n (s, get_type);
|
||||
return NULL;
|
||||
}
|
||||
return nmc_meta_generic_get_str_i18n(s, get_type);
|
||||
}
|
||||
|
||||
static inline const char *
|
||||
nmc_meta_generic_get_unknown (NMMetaAccessorGetType get_type)
|
||||
nmc_meta_generic_get_unknown(NMMetaAccessorGetType get_type)
|
||||
{
|
||||
return nmc_meta_generic_get_str_i18n_null (N_("(unknown)"), get_type);
|
||||
return nmc_meta_generic_get_str_i18n_null(N_("(unknown)"), get_type);
|
||||
}
|
||||
|
||||
static inline const char *
|
||||
nmc_meta_generic_get_bool (gboolean val, NMMetaAccessorGetType get_type)
|
||||
nmc_meta_generic_get_bool(gboolean val, NMMetaAccessorGetType get_type)
|
||||
{
|
||||
return nmc_meta_generic_get_str_i18n (val ? N_("yes") : N_("no"), get_type);
|
||||
return nmc_meta_generic_get_str_i18n(val ? N_("yes") : N_("no"), get_type);
|
||||
}
|
||||
|
||||
static inline const char *
|
||||
nmc_meta_generic_get_bool_onoff (gboolean val, NMMetaAccessorGetType get_type)
|
||||
nmc_meta_generic_get_bool_onoff(gboolean val, NMMetaAccessorGetType get_type)
|
||||
{
|
||||
return nmc_meta_generic_get_str_i18n (val ? N_("on") : N_("off"), get_type);
|
||||
return nmc_meta_generic_get_str_i18n(val ? N_("on") : N_("off"), get_type);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
NMC_META_GENERIC_GET_ENUM_TYPE_PARENTHESES,
|
||||
NMC_META_GENERIC_GET_ENUM_TYPE_DASH,
|
||||
NMC_META_GENERIC_GET_ENUM_TYPE_PARENTHESES,
|
||||
NMC_META_GENERIC_GET_ENUM_TYPE_DASH,
|
||||
} NmcMetaGenericGetEnumType;
|
||||
|
||||
static inline char *
|
||||
nmc_meta_generic_get_enum_with_detail (NmcMetaGenericGetEnumType get_enum_type, gint64 enum_val, const char *str_val, NMMetaAccessorGetType get_type)
|
||||
nmc_meta_generic_get_enum_with_detail(NmcMetaGenericGetEnumType get_enum_type,
|
||||
gint64 enum_val,
|
||||
const char * str_val,
|
||||
NMMetaAccessorGetType get_type)
|
||||
{
|
||||
if (!NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY,
|
||||
NM_META_ACCESSOR_GET_TYPE_PARSABLE))
|
||||
g_return_val_if_reached (NULL);
|
||||
if (!NM_IN_SET(get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY, NM_META_ACCESSOR_GET_TYPE_PARSABLE))
|
||||
g_return_val_if_reached(NULL);
|
||||
|
||||
if (!str_val) {
|
||||
/* Pass %NULL for only printing the numeric value. */
|
||||
return g_strdup_printf ("%lld", (long long) enum_val);
|
||||
}
|
||||
if (!str_val) {
|
||||
/* Pass %NULL for only printing the numeric value. */
|
||||
return g_strdup_printf("%lld", (long long) enum_val);
|
||||
}
|
||||
|
||||
switch (get_enum_type) {
|
||||
case NMC_META_GENERIC_GET_ENUM_TYPE_PARENTHESES:
|
||||
/* note that this function will always print "$NUM ($NICK)", also in PARSABLE
|
||||
switch (get_enum_type) {
|
||||
case NMC_META_GENERIC_GET_ENUM_TYPE_PARENTHESES:
|
||||
/* note that this function will always print "$NUM ($NICK)", also in PARSABLE
|
||||
* mode. That might not be desired, but it's done for certain properties to preserve
|
||||
* previous behavior. */
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
||||
return g_strdup_printf (_("%lld (%s)"), (long long) enum_val, gettext (str_val));
|
||||
return g_strdup_printf ("%lld (%s)", (long long) enum_val, str_val);
|
||||
case NMC_META_GENERIC_GET_ENUM_TYPE_DASH:
|
||||
/* note that this function will always print "$NUM ($NICK)", also in PARSABLE
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
||||
return g_strdup_printf(_("%lld (%s)"), (long long) enum_val, gettext(str_val));
|
||||
return g_strdup_printf("%lld (%s)", (long long) enum_val, str_val);
|
||||
case NMC_META_GENERIC_GET_ENUM_TYPE_DASH:
|
||||
/* note that this function will always print "$NUM ($NICK)", also in PARSABLE
|
||||
* mode. That might not be desired, but it's done for certain properties to preserve
|
||||
* previous behavior. */
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
||||
return g_strdup_printf (_("%lld - %s"), (long long) enum_val, gettext (str_val));
|
||||
return g_strdup_printf ("%lld - %s", (long long) enum_val, str_val);
|
||||
}
|
||||
g_return_val_if_reached (NULL);
|
||||
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
|
||||
return g_strdup_printf(_("%lld - %s"), (long long) enum_val, gettext(str_val));
|
||||
return g_strdup_printf("%lld - %s", (long long) enum_val, str_val);
|
||||
}
|
||||
g_return_val_if_reached(NULL);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
gboolean nmc_print (const NmcConfig *nmc_config,
|
||||
gpointer const *targets,
|
||||
gpointer targets_data,
|
||||
const char *header_name_no_l10n,
|
||||
const NMMetaAbstractInfo *const*fields,
|
||||
const char *fields_str,
|
||||
GError **error);
|
||||
gboolean nmc_print(const NmcConfig * nmc_config,
|
||||
gpointer const * targets,
|
||||
gpointer targets_data,
|
||||
const char * header_name_no_l10n,
|
||||
const NMMetaAbstractInfo *const *fields,
|
||||
const char * fields_str,
|
||||
GError ** error);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -9,119 +9,114 @@
|
|||
|
||||
/* mark names for variables that can be used as configuration. Search
|
||||
* for NMCS_ENV_VARIABLE() to find all honored environment variables. */
|
||||
#define NMCS_ENV_VARIABLE(var) ""var""
|
||||
#define NMCS_ENV_VARIABLE(var) "" var ""
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
extern volatile NMLogLevel _nm_logging_configured_level;
|
||||
|
||||
static inline gboolean
|
||||
nm_logging_enabled (NMLogLevel level)
|
||||
nm_logging_enabled(NMLogLevel level)
|
||||
{
|
||||
return level >= _nm_logging_configured_level;
|
||||
return level >= _nm_logging_configured_level;
|
||||
}
|
||||
|
||||
void _nm_logging_enabled_init (const char *level_str);
|
||||
void _nm_logging_enabled_init(const char *level_str);
|
||||
|
||||
void _nm_log_impl_cs (NMLogLevel level,
|
||||
const char *fmt,
|
||||
...) _nm_printf (2, 3);
|
||||
void _nm_log_impl_cs(NMLogLevel level, const char *fmt, ...) _nm_printf(2, 3);
|
||||
|
||||
#define _nm_log(level, ...) \
|
||||
_nm_log_impl_cs ((level), __VA_ARGS__);
|
||||
#define _nm_log(level, ...) _nm_log_impl_cs((level), __VA_ARGS__);
|
||||
|
||||
#define _NMLOG(level, ...) \
|
||||
G_STMT_START { \
|
||||
const NMLogLevel _level = (level); \
|
||||
\
|
||||
if (nm_logging_enabled (_level)) { \
|
||||
_nm_log (_level, __VA_ARGS__); \
|
||||
} \
|
||||
} G_STMT_END
|
||||
#define _NMLOG(level, ...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
const NMLogLevel _level = (level); \
|
||||
\
|
||||
if (nm_logging_enabled(_level)) { \
|
||||
_nm_log(_level, __VA_ARGS__); \
|
||||
} \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef NM_DIST_VERSION
|
||||
#define NM_DIST_VERSION VERSION
|
||||
#define NM_DIST_VERSION VERSION
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
gpointer nmcs_wait_for_objects_register (gpointer target);
|
||||
gpointer nmcs_wait_for_objects_register(gpointer target);
|
||||
|
||||
gboolean nmcs_wait_for_objects_iterate_until_done (GMainContext *context,
|
||||
int timeout_msec);
|
||||
gboolean nmcs_wait_for_objects_iterate_until_done(GMainContext *context, int timeout_msec);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef void (*NMCSUtilsPollProbeStartFcn) (GCancellable *cancellable,
|
||||
gpointer probe_user_data,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
typedef void (*NMCSUtilsPollProbeStartFcn)(GCancellable * cancellable,
|
||||
gpointer probe_user_data,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
typedef gboolean (*NMCSUtilsPollProbeFinishFcn) (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer probe_user_data,
|
||||
GError **error);
|
||||
typedef gboolean (*NMCSUtilsPollProbeFinishFcn)(GObject * source,
|
||||
GAsyncResult *result,
|
||||
gpointer probe_user_data,
|
||||
GError ** error);
|
||||
|
||||
void nmcs_utils_poll (int poll_timeout_ms,
|
||||
int ratelimit_timeout_ms,
|
||||
int sleep_timeout_ms,
|
||||
NMCSUtilsPollProbeStartFcn probe_start_fcn,
|
||||
NMCSUtilsPollProbeFinishFcn probe_finish_fcn,
|
||||
gpointer probe_user_data,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
void nmcs_utils_poll(int poll_timeout_ms,
|
||||
int ratelimit_timeout_ms,
|
||||
int sleep_timeout_ms,
|
||||
NMCSUtilsPollProbeStartFcn probe_start_fcn,
|
||||
NMCSUtilsPollProbeFinishFcn probe_finish_fcn,
|
||||
gpointer probe_user_data,
|
||||
GCancellable * cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
gboolean nmcs_utils_poll_finish (GAsyncResult *result,
|
||||
gpointer *probe_user_data,
|
||||
GError **error);
|
||||
gboolean nmcs_utils_poll_finish(GAsyncResult *result, gpointer *probe_user_data, GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
char *nmcs_utils_hwaddr_normalize (const char *hwaddr, gssize len);
|
||||
char *nmcs_utils_hwaddr_normalize(const char *hwaddr, gssize len);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
const char *nmcs_utils_parse_memmem (GBytes *mem, const char *needle);
|
||||
const char *nmcs_utils_parse_memmem(GBytes *mem, const char *needle);
|
||||
|
||||
const char *nmcs_utils_parse_get_full_line (GBytes *mem, const char *needle);
|
||||
const char *nmcs_utils_parse_get_full_line(GBytes *mem, const char *needle);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
char *nmcs_utils_uri_build_concat_v (const char *base,
|
||||
const char **components,
|
||||
gsize n_components);
|
||||
char *nmcs_utils_uri_build_concat_v(const char *base, const char **components, gsize n_components);
|
||||
|
||||
#define nmcs_utils_uri_build_concat(base, ...) nmcs_utils_uri_build_concat_v (base, ((const char *[]) { __VA_ARGS__ }), NM_NARG (__VA_ARGS__))
|
||||
#define nmcs_utils_uri_build_concat(base, ...) \
|
||||
nmcs_utils_uri_build_concat_v(base, ((const char *[]){__VA_ARGS__}), NM_NARG(__VA_ARGS__))
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
gboolean nmcs_setting_ip_replace_ipv4_addresses (NMSettingIPConfig *s_ip,
|
||||
NMIPAddress **entries_arr,
|
||||
guint entries_len);
|
||||
gboolean nmcs_setting_ip_replace_ipv4_addresses(NMSettingIPConfig *s_ip,
|
||||
NMIPAddress ** entries_arr,
|
||||
guint entries_len);
|
||||
|
||||
gboolean nmcs_setting_ip_replace_ipv4_routes (NMSettingIPConfig *s_ip,
|
||||
NMIPRoute **entries_arr,
|
||||
guint entries_len);
|
||||
gboolean nmcs_setting_ip_replace_ipv4_routes(NMSettingIPConfig *s_ip,
|
||||
NMIPRoute ** entries_arr,
|
||||
guint entries_len);
|
||||
|
||||
gboolean nmcs_setting_ip_replace_ipv4_rules (NMSettingIPConfig *s_ip,
|
||||
NMIPRoutingRule **entries_arr,
|
||||
guint entries_len);
|
||||
gboolean nmcs_setting_ip_replace_ipv4_rules(NMSettingIPConfig *s_ip,
|
||||
NMIPRoutingRule ** entries_arr,
|
||||
guint entries_len);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMConnection *nmcs_device_get_applied_connection (NMDevice *device,
|
||||
GCancellable *cancellable,
|
||||
guint64 *version_id,
|
||||
GError **error);
|
||||
NMConnection *nmcs_device_get_applied_connection(NMDevice * device,
|
||||
GCancellable *cancellable,
|
||||
guint64 * version_id,
|
||||
GError ** error);
|
||||
|
||||
gboolean nmcs_device_reapply (NMDevice *device,
|
||||
GCancellable *sigterm_cancellable,
|
||||
NMConnection *connection,
|
||||
guint64 version_id,
|
||||
gboolean *out_version_id_changed,
|
||||
GError **error);
|
||||
gboolean nmcs_device_reapply(NMDevice * device,
|
||||
GCancellable *sigterm_cancellable,
|
||||
NMConnection *connection,
|
||||
guint64 version_id,
|
||||
gboolean * out_version_id_changed,
|
||||
GError ** error);
|
||||
|
||||
#endif /* __NM_CLOUD_SETUP_UTILS_H__ */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -8,61 +8,63 @@
|
|||
typedef struct _NMHttpClient NMHttpClient;
|
||||
typedef struct _NMHttpClientClass NMHttpClientClass;
|
||||
|
||||
#define NM_TYPE_HTTP_CLIENT (nm_http_client_get_type ())
|
||||
#define NM_HTTP_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_HTTP_CLIENT, NMHttpClient))
|
||||
#define NM_HTTP_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_HTTP_CLIENT, NMHttpClientClass))
|
||||
#define NM_IS_HTTP_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_HTTP_CLIENT))
|
||||
#define NM_IS_HTTP_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_HTTP_CLIENT))
|
||||
#define NM_HTTP_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_HTTP_CLIENT, NMHttpClientClass))
|
||||
#define NM_TYPE_HTTP_CLIENT (nm_http_client_get_type())
|
||||
#define NM_HTTP_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_HTTP_CLIENT, NMHttpClient))
|
||||
#define NM_HTTP_CLIENT_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_HTTP_CLIENT, NMHttpClientClass))
|
||||
#define NM_IS_HTTP_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_HTTP_CLIENT))
|
||||
#define NM_IS_HTTP_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_HTTP_CLIENT))
|
||||
#define NM_HTTP_CLIENT_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_HTTP_CLIENT, NMHttpClientClass))
|
||||
|
||||
GType nm_http_client_get_type (void);
|
||||
GType nm_http_client_get_type(void);
|
||||
|
||||
NMHttpClient *nm_http_client_new (void);
|
||||
NMHttpClient *nm_http_client_new(void);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
GMainContext *nm_http_client_get_main_context (NMHttpClient *self);
|
||||
GMainContext *nm_http_client_get_main_context(NMHttpClient *self);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void nm_http_client_get (NMHttpClient *self,
|
||||
const char *uri,
|
||||
int timeout_msec,
|
||||
gssize max_data,
|
||||
const char *const *http_headers,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
void nm_http_client_get(NMHttpClient * self,
|
||||
const char * uri,
|
||||
int timeout_msec,
|
||||
gssize max_data,
|
||||
const char *const * http_headers,
|
||||
GCancellable * cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
gboolean nm_http_client_get_finish (NMHttpClient *self,
|
||||
GAsyncResult *result,
|
||||
long *out_response_code,
|
||||
GBytes **out_response_data,
|
||||
GError **error);
|
||||
gboolean nm_http_client_get_finish(NMHttpClient *self,
|
||||
GAsyncResult *result,
|
||||
long * out_response_code,
|
||||
GBytes ** out_response_data,
|
||||
GError ** error);
|
||||
|
||||
typedef gboolean (*NMHttpClientPollGetCheckFcn) (long response_code,
|
||||
GBytes *response_data,
|
||||
gpointer check_user_data,
|
||||
GError **error);
|
||||
typedef gboolean (*NMHttpClientPollGetCheckFcn)(long response_code,
|
||||
GBytes * response_data,
|
||||
gpointer check_user_data,
|
||||
GError **error);
|
||||
|
||||
void nm_http_client_poll_get (NMHttpClient *self,
|
||||
const char *uri,
|
||||
int request_timeout_ms,
|
||||
gssize request_max_data,
|
||||
int poll_timeout_ms,
|
||||
int ratelimit_timeout_ms,
|
||||
const char *const *http_headers,
|
||||
GCancellable *cancellable,
|
||||
NMHttpClientPollGetCheckFcn check_fcn,
|
||||
gpointer check_user_data,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
void nm_http_client_poll_get(NMHttpClient * self,
|
||||
const char * uri,
|
||||
int request_timeout_ms,
|
||||
gssize request_max_data,
|
||||
int poll_timeout_ms,
|
||||
int ratelimit_timeout_ms,
|
||||
const char *const * http_headers,
|
||||
GCancellable * cancellable,
|
||||
NMHttpClientPollGetCheckFcn check_fcn,
|
||||
gpointer check_user_data,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
gboolean nm_http_client_poll_get_finish (NMHttpClient *self,
|
||||
GAsyncResult *result,
|
||||
long *out_response_code,
|
||||
GBytes **out_response_data,
|
||||
GError **error);
|
||||
gboolean nm_http_client_poll_get_finish(NMHttpClient *self,
|
||||
GAsyncResult *result,
|
||||
long * out_response_code,
|
||||
GBytes ** out_response_data,
|
||||
GError ** error);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -10,561 +10,521 @@
|
|||
|
||||
#define HTTP_TIMEOUT_MS 3000
|
||||
|
||||
#define NM_AZURE_METADATA_HEADER "Metadata:true"
|
||||
#define NM_AZURE_HOST "169.254.169.254"
|
||||
#define NM_AZURE_BASE "http://" NM_AZURE_HOST
|
||||
#define NM_AZURE_API_VERSION "?format=text&api-version=2017-04-02"
|
||||
#define NM_AZURE_METADATA_URL_BASE /* $NM_AZURE_BASE/$NM_AZURE_API_VERSION */ "/metadata/instance/network/interface/"
|
||||
#define NM_AZURE_METADATA_HEADER "Metadata:true"
|
||||
#define NM_AZURE_HOST "169.254.169.254"
|
||||
#define NM_AZURE_BASE "http://" NM_AZURE_HOST
|
||||
#define NM_AZURE_API_VERSION "?format=text&api-version=2017-04-02"
|
||||
#define NM_AZURE_METADATA_URL_BASE /* $NM_AZURE_BASE/$NM_AZURE_API_VERSION */ \
|
||||
"/metadata/instance/network/interface/"
|
||||
|
||||
#define _azure_uri_concat(...) nmcs_utils_uri_build_concat (NM_AZURE_BASE, __VA_ARGS__, NM_AZURE_API_VERSION)
|
||||
#define _azure_uri_interfaces(...) _azure_uri_concat (NM_AZURE_METADATA_URL_BASE, ##__VA_ARGS__)
|
||||
#define _azure_uri_concat(...) \
|
||||
nmcs_utils_uri_build_concat(NM_AZURE_BASE, __VA_ARGS__, NM_AZURE_API_VERSION)
|
||||
#define _azure_uri_interfaces(...) _azure_uri_concat(NM_AZURE_METADATA_URL_BASE, ##__VA_ARGS__)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
struct _NMCSProviderAzure {
|
||||
NMCSProvider parent;
|
||||
NMCSProvider parent;
|
||||
};
|
||||
|
||||
struct _NMCSProviderAzureClass {
|
||||
NMCSProviderClass parent;
|
||||
NMCSProviderClass parent;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (NMCSProviderAzure, nmcs_provider_azure, NMCS_TYPE_PROVIDER);
|
||||
G_DEFINE_TYPE(NMCSProviderAzure, nmcs_provider_azure, NMCS_TYPE_PROVIDER);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
_detect_get_meta_data_done_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_detect_get_meta_data_done_cb(GObject *source, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
gs_unref_object GTask *task = user_data;
|
||||
gs_free_error GError *get_error = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
gboolean success;
|
||||
gs_unref_object GTask *task = user_data;
|
||||
gs_free_error GError *get_error = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
gboolean success;
|
||||
|
||||
success = nm_http_client_poll_get_finish (NM_HTTP_CLIENT (source),
|
||||
result,
|
||||
NULL,
|
||||
NULL,
|
||||
&get_error);
|
||||
success =
|
||||
nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, NULL, &get_error);
|
||||
|
||||
if (nm_utils_error_is_cancelled (get_error)) {
|
||||
g_task_return_error (task, g_steal_pointer (&get_error));
|
||||
return;
|
||||
}
|
||||
if (nm_utils_error_is_cancelled(get_error)) {
|
||||
g_task_return_error(task, g_steal_pointer(&get_error));
|
||||
return;
|
||||
}
|
||||
|
||||
if (get_error) {
|
||||
nm_utils_error_set (&error,
|
||||
NM_UTILS_ERROR_UNKNOWN,
|
||||
"failure to get Azure metadata: %s",
|
||||
get_error->message);
|
||||
g_task_return_error (task, g_steal_pointer (&error));
|
||||
return;
|
||||
}
|
||||
if (get_error) {
|
||||
nm_utils_error_set(&error,
|
||||
NM_UTILS_ERROR_UNKNOWN,
|
||||
"failure to get Azure metadata: %s",
|
||||
get_error->message);
|
||||
g_task_return_error(task, g_steal_pointer(&error));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
nm_utils_error_set (&error,
|
||||
NM_UTILS_ERROR_UNKNOWN,
|
||||
"failure to detect azure metadata");
|
||||
g_task_return_error (task, g_steal_pointer (&error));
|
||||
return;
|
||||
}
|
||||
if (!success) {
|
||||
nm_utils_error_set(&error, NM_UTILS_ERROR_UNKNOWN, "failure to detect azure metadata");
|
||||
g_task_return_error(task, g_steal_pointer(&error));
|
||||
return;
|
||||
}
|
||||
|
||||
g_task_return_boolean (task, TRUE);
|
||||
g_task_return_boolean(task, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
detect (NMCSProvider *provider,
|
||||
GTask *task)
|
||||
detect(NMCSProvider *provider, GTask *task)
|
||||
{
|
||||
NMHttpClient *http_client;
|
||||
gs_free char *uri = NULL;
|
||||
NMHttpClient *http_client;
|
||||
gs_free char *uri = NULL;
|
||||
|
||||
http_client = nmcs_provider_get_http_client (provider);
|
||||
http_client = nmcs_provider_get_http_client(provider);
|
||||
|
||||
nm_http_client_poll_get (http_client,
|
||||
(uri = _azure_uri_concat ("/metadata/instance")),
|
||||
HTTP_TIMEOUT_MS,
|
||||
256*1024,
|
||||
7000,
|
||||
1000,
|
||||
NM_MAKE_STRV (NM_AZURE_METADATA_HEADER),
|
||||
g_task_get_cancellable (task),
|
||||
NULL,
|
||||
NULL,
|
||||
_detect_get_meta_data_done_cb,
|
||||
task);
|
||||
nm_http_client_poll_get(http_client,
|
||||
(uri = _azure_uri_concat("/metadata/instance")),
|
||||
HTTP_TIMEOUT_MS,
|
||||
256 * 1024,
|
||||
7000,
|
||||
1000,
|
||||
NM_MAKE_STRV(NM_AZURE_METADATA_HEADER),
|
||||
g_task_get_cancellable(task),
|
||||
NULL,
|
||||
NULL,
|
||||
_detect_get_meta_data_done_cb,
|
||||
task);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
NMCSProviderGetConfigTaskData *config_data;
|
||||
guint n_ifaces_pending;
|
||||
GError *error;
|
||||
NMCSProviderGetConfigTaskData *config_data;
|
||||
guint n_ifaces_pending;
|
||||
GError * error;
|
||||
} AzureData;
|
||||
|
||||
typedef struct {
|
||||
NMCSProviderGetConfigIfaceData *iface_get_config;
|
||||
AzureData *azure_data;
|
||||
gssize iface_idx;
|
||||
guint n_ips_prefix_pending;
|
||||
char *hwaddr;
|
||||
NMCSProviderGetConfigIfaceData *iface_get_config;
|
||||
AzureData * azure_data;
|
||||
gssize iface_idx;
|
||||
guint n_ips_prefix_pending;
|
||||
char * hwaddr;
|
||||
} AzureIfaceData;
|
||||
|
||||
static void
|
||||
_azure_iface_data_free (AzureIfaceData *iface_data)
|
||||
_azure_iface_data_free(AzureIfaceData *iface_data)
|
||||
{
|
||||
g_free(iface_data->hwaddr);
|
||||
nm_g_slice_free (iface_data);
|
||||
g_free(iface_data->hwaddr);
|
||||
nm_g_slice_free(iface_data);
|
||||
}
|
||||
|
||||
static void
|
||||
_get_config_maybe_task_return (AzureData *azure_data,
|
||||
GError *error_take)
|
||||
_get_config_maybe_task_return(AzureData *azure_data, GError *error_take)
|
||||
{
|
||||
NMCSProviderGetConfigTaskData *config_data = azure_data->config_data;
|
||||
NMCSProviderGetConfigTaskData *config_data = azure_data->config_data;
|
||||
|
||||
if (error_take) {
|
||||
if (!azure_data->error)
|
||||
azure_data->error = error_take;
|
||||
else if ( !nm_utils_error_is_cancelled (azure_data->error)
|
||||
&& nm_utils_error_is_cancelled (error_take)) {
|
||||
nm_clear_error (&azure_data->error);
|
||||
azure_data->error = error_take;
|
||||
} else
|
||||
g_error_free (error_take);
|
||||
}
|
||||
if (error_take) {
|
||||
if (!azure_data->error)
|
||||
azure_data->error = error_take;
|
||||
else if (!nm_utils_error_is_cancelled(azure_data->error)
|
||||
&& nm_utils_error_is_cancelled(error_take)) {
|
||||
nm_clear_error(&azure_data->error);
|
||||
azure_data->error = error_take;
|
||||
} else
|
||||
g_error_free(error_take);
|
||||
}
|
||||
|
||||
if (azure_data->n_ifaces_pending > 0)
|
||||
return;
|
||||
if (azure_data->n_ifaces_pending > 0)
|
||||
return;
|
||||
|
||||
if (azure_data->error) {
|
||||
if (nm_utils_error_is_cancelled (azure_data->error))
|
||||
_LOGD ("get-config: cancelled");
|
||||
else
|
||||
_LOGD ("get-config: failed: %s", azure_data->error->message);
|
||||
g_task_return_error (config_data->task, g_steal_pointer (&azure_data->error));
|
||||
} else {
|
||||
_LOGD ("get-config: success");
|
||||
g_task_return_pointer (config_data->task,
|
||||
g_hash_table_ref (config_data->result_dict),
|
||||
(GDestroyNotify) g_hash_table_unref);
|
||||
}
|
||||
if (azure_data->error) {
|
||||
if (nm_utils_error_is_cancelled(azure_data->error))
|
||||
_LOGD("get-config: cancelled");
|
||||
else
|
||||
_LOGD("get-config: failed: %s", azure_data->error->message);
|
||||
g_task_return_error(config_data->task, g_steal_pointer(&azure_data->error));
|
||||
} else {
|
||||
_LOGD("get-config: success");
|
||||
g_task_return_pointer(config_data->task,
|
||||
g_hash_table_ref(config_data->result_dict),
|
||||
(GDestroyNotify) g_hash_table_unref);
|
||||
}
|
||||
|
||||
nm_g_slice_free (azure_data);
|
||||
g_object_unref (config_data->task);
|
||||
nm_g_slice_free(azure_data);
|
||||
g_object_unref(config_data->task);
|
||||
}
|
||||
|
||||
static void
|
||||
_get_config_fetch_done_cb (NMHttpClient *http_client,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data,
|
||||
gboolean is_ipv4)
|
||||
_get_config_fetch_done_cb(NMHttpClient *http_client,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data,
|
||||
gboolean is_ipv4)
|
||||
{
|
||||
NMCSProviderGetConfigIfaceData *iface_get_config;
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
AzureIfaceData *iface_data = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
const char *fip_str = NULL;
|
||||
AzureData *azure_data;
|
||||
NMCSProviderGetConfigIfaceData *iface_get_config;
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
AzureIfaceData * iface_data = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
const char * fip_str = NULL;
|
||||
AzureData * azure_data;
|
||||
|
||||
azure_data = iface_data->azure_data;
|
||||
azure_data = iface_data->azure_data;
|
||||
|
||||
nm_http_client_poll_get_finish (http_client,
|
||||
result,
|
||||
NULL,
|
||||
&response,
|
||||
&error);
|
||||
nm_http_client_poll_get_finish(http_client, result, NULL, &response, &error);
|
||||
|
||||
if (error)
|
||||
goto done;
|
||||
if (error)
|
||||
goto done;
|
||||
|
||||
if(!error){
|
||||
in_addr_t tmp_addr;
|
||||
int tmp_prefix;
|
||||
if (!error) {
|
||||
in_addr_t tmp_addr;
|
||||
int tmp_prefix;
|
||||
|
||||
fip_str = g_bytes_get_data (response, NULL);
|
||||
iface_data->iface_get_config = g_hash_table_lookup (azure_data->config_data->result_dict,
|
||||
iface_data->hwaddr);
|
||||
iface_get_config = iface_data->iface_get_config;
|
||||
iface_get_config->iface_idx = iface_data->iface_idx;
|
||||
fip_str = g_bytes_get_data(response, NULL);
|
||||
iface_data->iface_get_config =
|
||||
g_hash_table_lookup(azure_data->config_data->result_dict, iface_data->hwaddr);
|
||||
iface_get_config = iface_data->iface_get_config;
|
||||
iface_get_config->iface_idx = iface_data->iface_idx;
|
||||
|
||||
if (is_ipv4) {
|
||||
if (!nm_utils_parse_inaddr_bin (AF_INET,
|
||||
fip_str,
|
||||
NULL,
|
||||
&tmp_addr)) {
|
||||
error = nm_utils_error_new (NM_UTILS_ERROR_UNKNOWN,
|
||||
"ip is not a valid private ip address");
|
||||
goto done;
|
||||
}
|
||||
_LOGD ("interface[%"G_GSSIZE_FORMAT"]: adding private ip %s",
|
||||
iface_data->iface_idx,
|
||||
fip_str);
|
||||
iface_get_config->ipv4s_arr[iface_get_config->ipv4s_len] = tmp_addr;
|
||||
iface_get_config->has_ipv4s = TRUE;
|
||||
iface_get_config->ipv4s_len++;
|
||||
} else {
|
||||
tmp_prefix = (_nm_utils_ascii_str_to_int64 (fip_str, 10, 0, 32, -1));
|
||||
if (is_ipv4) {
|
||||
if (!nm_utils_parse_inaddr_bin(AF_INET, fip_str, NULL, &tmp_addr)) {
|
||||
error = nm_utils_error_new(NM_UTILS_ERROR_UNKNOWN,
|
||||
"ip is not a valid private ip address");
|
||||
goto done;
|
||||
}
|
||||
_LOGD("interface[%" G_GSSIZE_FORMAT "]: adding private ip %s",
|
||||
iface_data->iface_idx,
|
||||
fip_str);
|
||||
iface_get_config->ipv4s_arr[iface_get_config->ipv4s_len] = tmp_addr;
|
||||
iface_get_config->has_ipv4s = TRUE;
|
||||
iface_get_config->ipv4s_len++;
|
||||
} else {
|
||||
tmp_prefix = (_nm_utils_ascii_str_to_int64(fip_str, 10, 0, 32, -1));
|
||||
|
||||
if (tmp_prefix == -1) {
|
||||
_LOGD ("interface[%"G_GSSIZE_FORMAT"]: invalid prefix %d",
|
||||
iface_data->iface_idx,
|
||||
tmp_prefix);
|
||||
goto done;
|
||||
}
|
||||
_LOGD ("interface[%"G_GSSIZE_FORMAT"]: adding prefix %d",
|
||||
iface_data->iface_idx,
|
||||
tmp_prefix);
|
||||
iface_get_config->cidr_prefix = tmp_prefix;
|
||||
iface_get_config->has_cidr = TRUE;
|
||||
}
|
||||
}
|
||||
if (tmp_prefix == -1) {
|
||||
_LOGD("interface[%" G_GSSIZE_FORMAT "]: invalid prefix %d",
|
||||
iface_data->iface_idx,
|
||||
tmp_prefix);
|
||||
goto done;
|
||||
}
|
||||
_LOGD("interface[%" G_GSSIZE_FORMAT "]: adding prefix %d",
|
||||
iface_data->iface_idx,
|
||||
tmp_prefix);
|
||||
iface_get_config->cidr_prefix = tmp_prefix;
|
||||
iface_get_config->has_cidr = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
--iface_data->n_ips_prefix_pending;
|
||||
if (iface_data->n_ips_prefix_pending == 0) {
|
||||
_azure_iface_data_free (iface_data);
|
||||
--azure_data->n_ifaces_pending;
|
||||
_get_config_maybe_task_return (azure_data, g_steal_pointer (&error));
|
||||
}
|
||||
--iface_data->n_ips_prefix_pending;
|
||||
if (iface_data->n_ips_prefix_pending == 0) {
|
||||
_azure_iface_data_free(iface_data);
|
||||
--azure_data->n_ifaces_pending;
|
||||
_get_config_maybe_task_return(azure_data, g_steal_pointer(&error));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_get_config_fetch_done_cb_private_ipv4s (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_get_config_fetch_done_cb_private_ipv4s(GObject *source, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
_get_config_fetch_done_cb (NM_HTTP_CLIENT (source), result, user_data, TRUE);
|
||||
_get_config_fetch_done_cb(NM_HTTP_CLIENT(source), result, user_data, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
_get_config_fetch_done_cb_subnet_cidr_prefix (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_get_config_fetch_done_cb_subnet_cidr_prefix(GObject * source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
_get_config_fetch_done_cb (NM_HTTP_CLIENT (source), result, user_data, FALSE);
|
||||
_get_config_fetch_done_cb(NM_HTTP_CLIENT(source), result, user_data, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
_get_config_ips_prefix_list_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_get_config_ips_prefix_list_cb(GObject *source, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
AzureIfaceData *iface_data = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
const char *response_str = NULL;
|
||||
gsize response_len;
|
||||
AzureData *azure_data;
|
||||
const char *line;
|
||||
gsize line_len;
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
AzureIfaceData * iface_data = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
const char * response_str = NULL;
|
||||
gsize response_len;
|
||||
AzureData * azure_data;
|
||||
const char * line;
|
||||
gsize line_len;
|
||||
|
||||
azure_data = iface_data->azure_data;
|
||||
azure_data = iface_data->azure_data;
|
||||
|
||||
nm_http_client_poll_get_finish (NM_HTTP_CLIENT (source),
|
||||
result,
|
||||
NULL,
|
||||
&response,
|
||||
&error);
|
||||
if (error)
|
||||
goto done;
|
||||
nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, &response, &error);
|
||||
if (error)
|
||||
goto done;
|
||||
|
||||
response_str = g_bytes_get_data (response, &response_len);
|
||||
/* NMHttpClient guarantees that there is a trailing NUL after the data. */
|
||||
nm_assert (response_str[response_len] == 0);
|
||||
response_str = g_bytes_get_data(response, &response_len);
|
||||
/* NMHttpClient guarantees that there is a trailing NUL after the data. */
|
||||
nm_assert(response_str[response_len] == 0);
|
||||
|
||||
nm_assert (!iface_data->iface_get_config->has_ipv4s);
|
||||
nm_assert (!iface_data->iface_get_config->ipv4s_arr);
|
||||
nm_assert (!iface_data->iface_get_config->has_cidr);
|
||||
nm_assert(!iface_data->iface_get_config->has_ipv4s);
|
||||
nm_assert(!iface_data->iface_get_config->ipv4s_arr);
|
||||
nm_assert(!iface_data->iface_get_config->has_cidr);
|
||||
|
||||
while (nm_utils_parse_next_line (&response_str,
|
||||
&response_len,
|
||||
&line,
|
||||
&line_len)) {
|
||||
gint64 ips_prefix_idx;
|
||||
while (nm_utils_parse_next_line(&response_str, &response_len, &line, &line_len)) {
|
||||
gint64 ips_prefix_idx;
|
||||
|
||||
if (line_len == 0)
|
||||
continue;
|
||||
/* Truncate the string. It's safe to do, because we own @response_data an it has an
|
||||
if (line_len == 0)
|
||||
continue;
|
||||
/* Truncate the string. It's safe to do, because we own @response_data an it has an
|
||||
* extra NULL character after the buffer. */
|
||||
((char *) line)[line_len] = '\0';
|
||||
((char *) line)[line_len] = '\0';
|
||||
|
||||
if (line[line_len - 1] == '/')
|
||||
((char *) line)[--line_len] = '\0';
|
||||
if (line[line_len - 1] == '/')
|
||||
((char *) line)[--line_len] = '\0';
|
||||
|
||||
ips_prefix_idx = _nm_utils_ascii_str_to_int64 (line, 10, 0, G_MAXINT64, -1);
|
||||
ips_prefix_idx = _nm_utils_ascii_str_to_int64(line, 10, 0, G_MAXINT64, -1);
|
||||
|
||||
if (ips_prefix_idx < 0)
|
||||
continue;
|
||||
if (ips_prefix_idx < 0)
|
||||
continue;
|
||||
|
||||
{
|
||||
gs_free const char *uri = NULL;
|
||||
char buf[100];
|
||||
{
|
||||
gs_free const char *uri = NULL;
|
||||
char buf[100];
|
||||
|
||||
iface_data->n_ips_prefix_pending++;
|
||||
iface_data->n_ips_prefix_pending++;
|
||||
|
||||
nm_http_client_poll_get (NM_HTTP_CLIENT (source),
|
||||
(uri = _azure_uri_interfaces (nm_sprintf_buf (buf,"%"G_GSSIZE_FORMAT"/ipv4/ipAddress/%"G_GINT64_FORMAT"/privateIpAddress",
|
||||
iface_data->iface_idx,
|
||||
ips_prefix_idx))),
|
||||
HTTP_TIMEOUT_MS,
|
||||
512*1024,
|
||||
10000,
|
||||
1000,
|
||||
NM_MAKE_STRV (NM_AZURE_METADATA_HEADER),
|
||||
g_task_get_cancellable (azure_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_fetch_done_cb_private_ipv4s,
|
||||
iface_data);
|
||||
}
|
||||
}
|
||||
nm_http_client_poll_get(
|
||||
NM_HTTP_CLIENT(source),
|
||||
(uri = _azure_uri_interfaces(nm_sprintf_buf(
|
||||
buf,
|
||||
"%" G_GSSIZE_FORMAT "/ipv4/ipAddress/%" G_GINT64_FORMAT "/privateIpAddress",
|
||||
iface_data->iface_idx,
|
||||
ips_prefix_idx))),
|
||||
HTTP_TIMEOUT_MS,
|
||||
512 * 1024,
|
||||
10000,
|
||||
1000,
|
||||
NM_MAKE_STRV(NM_AZURE_METADATA_HEADER),
|
||||
g_task_get_cancellable(azure_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_fetch_done_cb_private_ipv4s,
|
||||
iface_data);
|
||||
}
|
||||
}
|
||||
|
||||
iface_data->iface_get_config->ipv4s_len = 0;
|
||||
iface_data->iface_get_config->ipv4s_arr =
|
||||
g_new (in_addr_t , iface_data->n_ips_prefix_pending);
|
||||
iface_data->iface_get_config->ipv4s_len = 0;
|
||||
iface_data->iface_get_config->ipv4s_arr = g_new(in_addr_t, iface_data->n_ips_prefix_pending);
|
||||
|
||||
{
|
||||
gs_free const char *uri = NULL;
|
||||
char buf[30];
|
||||
{
|
||||
gs_free const char *uri = NULL;
|
||||
char buf[30];
|
||||
|
||||
iface_data->n_ips_prefix_pending++;
|
||||
nm_http_client_poll_get (NM_HTTP_CLIENT (source),
|
||||
(uri = _azure_uri_interfaces (nm_sprintf_buf (buf, "%"G_GSSIZE_FORMAT, iface_data->iface_idx),
|
||||
"/ipv4/subnet/0/prefix/")),
|
||||
HTTP_TIMEOUT_MS,
|
||||
512*1024,
|
||||
10000,
|
||||
1000,
|
||||
NM_MAKE_STRV (NM_AZURE_METADATA_HEADER),
|
||||
g_task_get_cancellable (azure_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_fetch_done_cb_subnet_cidr_prefix,
|
||||
iface_data);
|
||||
}
|
||||
return;
|
||||
iface_data->n_ips_prefix_pending++;
|
||||
nm_http_client_poll_get(
|
||||
NM_HTTP_CLIENT(source),
|
||||
(uri = _azure_uri_interfaces(
|
||||
nm_sprintf_buf(buf, "%" G_GSSIZE_FORMAT, iface_data->iface_idx),
|
||||
"/ipv4/subnet/0/prefix/")),
|
||||
HTTP_TIMEOUT_MS,
|
||||
512 * 1024,
|
||||
10000,
|
||||
1000,
|
||||
NM_MAKE_STRV(NM_AZURE_METADATA_HEADER),
|
||||
g_task_get_cancellable(azure_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_fetch_done_cb_subnet_cidr_prefix,
|
||||
iface_data);
|
||||
}
|
||||
return;
|
||||
|
||||
done:
|
||||
_azure_iface_data_free (iface_data);
|
||||
--azure_data->n_ifaces_pending;
|
||||
_get_config_maybe_task_return (azure_data, g_steal_pointer (&error));
|
||||
_azure_iface_data_free(iface_data);
|
||||
--azure_data->n_ifaces_pending;
|
||||
_get_config_maybe_task_return(azure_data, g_steal_pointer(&error));
|
||||
}
|
||||
|
||||
static void
|
||||
_get_config_iface_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_get_config_iface_cb(GObject *source, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
AzureIfaceData *iface_data = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_free const char *uri = NULL;
|
||||
char buf[100];
|
||||
AzureData *azure_data;
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
AzureIfaceData * iface_data = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_free const char * uri = NULL;
|
||||
char buf[100];
|
||||
AzureData * azure_data;
|
||||
|
||||
azure_data = iface_data->azure_data;
|
||||
azure_data = iface_data->azure_data;
|
||||
|
||||
nm_http_client_poll_get_finish (NM_HTTP_CLIENT (source),
|
||||
result,
|
||||
NULL,
|
||||
&response,
|
||||
&error);
|
||||
nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, &response, &error);
|
||||
|
||||
if (error)
|
||||
goto done;
|
||||
if (error)
|
||||
goto done;
|
||||
|
||||
iface_data->hwaddr = nmcs_utils_hwaddr_normalize (g_bytes_get_data (response, NULL), -1);
|
||||
iface_data->hwaddr = nmcs_utils_hwaddr_normalize(g_bytes_get_data(response, NULL), -1);
|
||||
|
||||
if (!iface_data->hwaddr) {
|
||||
goto done;
|
||||
}
|
||||
if (!iface_data->hwaddr) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
iface_data->iface_get_config = g_hash_table_lookup (azure_data->config_data->result_dict,
|
||||
iface_data->hwaddr);
|
||||
iface_data->iface_get_config =
|
||||
g_hash_table_lookup(azure_data->config_data->result_dict, iface_data->hwaddr);
|
||||
|
||||
if (!iface_data->iface_get_config) {
|
||||
if (!iface_data->azure_data->config_data->any) {
|
||||
_LOGD ("interface[%"G_GSSIZE_FORMAT"]: ignore hwaddr %s",
|
||||
iface_data->iface_idx,
|
||||
iface_data->hwaddr);
|
||||
goto done;
|
||||
}
|
||||
iface_data->iface_get_config = nmcs_provider_get_config_iface_data_new (FALSE);
|
||||
g_hash_table_insert (azure_data->config_data->result_dict,
|
||||
g_strdup (iface_data->hwaddr),
|
||||
iface_data->iface_get_config);
|
||||
}
|
||||
if (!iface_data->iface_get_config) {
|
||||
if (!iface_data->azure_data->config_data->any) {
|
||||
_LOGD("interface[%" G_GSSIZE_FORMAT "]: ignore hwaddr %s",
|
||||
iface_data->iface_idx,
|
||||
iface_data->hwaddr);
|
||||
goto done;
|
||||
}
|
||||
iface_data->iface_get_config = nmcs_provider_get_config_iface_data_new(FALSE);
|
||||
g_hash_table_insert(azure_data->config_data->result_dict,
|
||||
g_strdup(iface_data->hwaddr),
|
||||
iface_data->iface_get_config);
|
||||
}
|
||||
|
||||
_LOGD ("interface[%"G_GSSIZE_FORMAT"]: found a matching device with hwaddr %s",
|
||||
iface_data->iface_idx,
|
||||
iface_data->hwaddr);
|
||||
_LOGD("interface[%" G_GSSIZE_FORMAT "]: found a matching device with hwaddr %s",
|
||||
iface_data->iface_idx,
|
||||
iface_data->hwaddr);
|
||||
|
||||
nm_sprintf_buf (buf, "%"G_GSSIZE_FORMAT"/ipv4/ipAddress/", iface_data->iface_idx);
|
||||
nm_sprintf_buf(buf, "%" G_GSSIZE_FORMAT "/ipv4/ipAddress/", iface_data->iface_idx);
|
||||
|
||||
nm_http_client_poll_get (NM_HTTP_CLIENT (source),
|
||||
(uri = _azure_uri_interfaces (buf)),
|
||||
HTTP_TIMEOUT_MS,
|
||||
512*1024,
|
||||
10000,
|
||||
1000,
|
||||
NM_MAKE_STRV (NM_AZURE_METADATA_HEADER),
|
||||
g_task_get_cancellable (azure_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_ips_prefix_list_cb,
|
||||
iface_data);
|
||||
return;
|
||||
nm_http_client_poll_get(NM_HTTP_CLIENT(source),
|
||||
(uri = _azure_uri_interfaces(buf)),
|
||||
HTTP_TIMEOUT_MS,
|
||||
512 * 1024,
|
||||
10000,
|
||||
1000,
|
||||
NM_MAKE_STRV(NM_AZURE_METADATA_HEADER),
|
||||
g_task_get_cancellable(azure_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_ips_prefix_list_cb,
|
||||
iface_data);
|
||||
return;
|
||||
|
||||
done:
|
||||
nm_g_slice_free (iface_data);
|
||||
--azure_data->n_ifaces_pending;
|
||||
_get_config_maybe_task_return (azure_data, g_steal_pointer (&error));
|
||||
nm_g_slice_free(iface_data);
|
||||
--azure_data->n_ifaces_pending;
|
||||
_get_config_maybe_task_return(azure_data, g_steal_pointer(&error));
|
||||
}
|
||||
|
||||
static void
|
||||
_get_net_ifaces_list_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_get_net_ifaces_list_cb(GObject *source, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
gs_unref_ptrarray GPtrArray *ifaces_arr = NULL;
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
AzureData *azure_data = user_data;
|
||||
const char *response_str;
|
||||
gsize response_len;
|
||||
const char *line;
|
||||
gsize line_len;
|
||||
guint i;
|
||||
gs_unref_ptrarray GPtrArray *ifaces_arr = NULL;
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
AzureData * azure_data = user_data;
|
||||
const char * response_str;
|
||||
gsize response_len;
|
||||
const char * line;
|
||||
gsize line_len;
|
||||
guint i;
|
||||
|
||||
nm_http_client_poll_get_finish (NM_HTTP_CLIENT (source),
|
||||
result,
|
||||
NULL,
|
||||
&response,
|
||||
&error);
|
||||
nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, &response, &error);
|
||||
|
||||
if (error) {
|
||||
_get_config_maybe_task_return (azure_data, g_steal_pointer (&error));
|
||||
return;
|
||||
}
|
||||
if (error) {
|
||||
_get_config_maybe_task_return(azure_data, g_steal_pointer(&error));
|
||||
return;
|
||||
}
|
||||
|
||||
response_str = g_bytes_get_data (response, &response_len);
|
||||
/* NMHttpClient guarantees that there is a trailing NUL after the data. */
|
||||
nm_assert (response_str[response_len] == 0);
|
||||
response_str = g_bytes_get_data(response, &response_len);
|
||||
/* NMHttpClient guarantees that there is a trailing NUL after the data. */
|
||||
nm_assert(response_str[response_len] == 0);
|
||||
|
||||
ifaces_arr = g_ptr_array_new ();
|
||||
ifaces_arr = g_ptr_array_new();
|
||||
|
||||
while (nm_utils_parse_next_line (&response_str,
|
||||
&response_len,
|
||||
&line,
|
||||
&line_len)) {
|
||||
AzureIfaceData *iface_data;
|
||||
gssize iface_idx;
|
||||
while (nm_utils_parse_next_line(&response_str, &response_len, &line, &line_len)) {
|
||||
AzureIfaceData *iface_data;
|
||||
gssize iface_idx;
|
||||
|
||||
if (line_len == 0)
|
||||
continue;
|
||||
if (line_len == 0)
|
||||
continue;
|
||||
|
||||
/* Truncate the string. It's safe to do, because we own @response_data an it has an
|
||||
/* Truncate the string. It's safe to do, because we own @response_data an it has an
|
||||
* extra NULL character after the buffer. */
|
||||
((char *) line)[line_len] = '\0';
|
||||
((char *) line)[line_len] = '\0';
|
||||
|
||||
if (line[line_len - 1] == '/' && line_len != 0)
|
||||
((char *) line)[--line_len] = '\0';
|
||||
if (line[line_len - 1] == '/' && line_len != 0)
|
||||
((char *) line)[--line_len] = '\0';
|
||||
|
||||
iface_idx = _nm_utils_ascii_str_to_int64 (line, 10, 0, G_MAXSSIZE, -1);
|
||||
if (iface_idx < 0)
|
||||
continue;
|
||||
iface_idx = _nm_utils_ascii_str_to_int64(line, 10, 0, G_MAXSSIZE, -1);
|
||||
if (iface_idx < 0)
|
||||
continue;
|
||||
|
||||
iface_data = g_slice_new (AzureIfaceData);
|
||||
*iface_data = (AzureIfaceData) {
|
||||
.iface_get_config = NULL,
|
||||
.azure_data = azure_data,
|
||||
.iface_idx = iface_idx,
|
||||
.n_ips_prefix_pending = 0,
|
||||
.hwaddr = NULL,
|
||||
};
|
||||
g_ptr_array_add (ifaces_arr, iface_data);
|
||||
}
|
||||
iface_data = g_slice_new(AzureIfaceData);
|
||||
*iface_data = (AzureIfaceData){
|
||||
.iface_get_config = NULL,
|
||||
.azure_data = azure_data,
|
||||
.iface_idx = iface_idx,
|
||||
.n_ips_prefix_pending = 0,
|
||||
.hwaddr = NULL,
|
||||
};
|
||||
g_ptr_array_add(ifaces_arr, iface_data);
|
||||
}
|
||||
|
||||
_LOGD ("found azure interfaces: %u", ifaces_arr->len);
|
||||
_LOGD("found azure interfaces: %u", ifaces_arr->len);
|
||||
|
||||
if (ifaces_arr->len == 0) {
|
||||
error = nm_utils_error_new (NM_UTILS_ERROR_UNKNOWN,
|
||||
"no Azure interfaces found");
|
||||
_get_config_maybe_task_return (azure_data, g_steal_pointer (&error));
|
||||
return;
|
||||
}
|
||||
if (ifaces_arr->len == 0) {
|
||||
error = nm_utils_error_new(NM_UTILS_ERROR_UNKNOWN, "no Azure interfaces found");
|
||||
_get_config_maybe_task_return(azure_data, g_steal_pointer(&error));
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < ifaces_arr->len; ++i) {
|
||||
AzureIfaceData *data = ifaces_arr->pdata[i];
|
||||
gs_free const char *uri = NULL;
|
||||
char buf[100];
|
||||
for (i = 0; i < ifaces_arr->len; ++i) {
|
||||
AzureIfaceData * data = ifaces_arr->pdata[i];
|
||||
gs_free const char *uri = NULL;
|
||||
char buf[100];
|
||||
|
||||
_LOGD ("azure interface[%"G_GSSIZE_FORMAT"]: retrieving configuration",
|
||||
data->iface_idx);
|
||||
_LOGD("azure interface[%" G_GSSIZE_FORMAT "]: retrieving configuration", data->iface_idx);
|
||||
|
||||
nm_sprintf_buf (buf, "%"G_GSSIZE_FORMAT"/macAddress", data->iface_idx);
|
||||
nm_sprintf_buf(buf, "%" G_GSSIZE_FORMAT "/macAddress", data->iface_idx);
|
||||
|
||||
azure_data->n_ifaces_pending++;
|
||||
nm_http_client_poll_get (NM_HTTP_CLIENT (source),
|
||||
(uri = _azure_uri_interfaces (buf)),
|
||||
HTTP_TIMEOUT_MS,
|
||||
512*1024,
|
||||
10000,
|
||||
1000,
|
||||
NM_MAKE_STRV (NM_AZURE_METADATA_HEADER),
|
||||
g_task_get_cancellable (azure_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_iface_cb,
|
||||
data);
|
||||
}
|
||||
azure_data->n_ifaces_pending++;
|
||||
nm_http_client_poll_get(NM_HTTP_CLIENT(source),
|
||||
(uri = _azure_uri_interfaces(buf)),
|
||||
HTTP_TIMEOUT_MS,
|
||||
512 * 1024,
|
||||
10000,
|
||||
1000,
|
||||
NM_MAKE_STRV(NM_AZURE_METADATA_HEADER),
|
||||
g_task_get_cancellable(azure_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_iface_cb,
|
||||
data);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
get_config (NMCSProvider *provider,
|
||||
NMCSProviderGetConfigTaskData *get_config_data)
|
||||
get_config(NMCSProvider *provider, NMCSProviderGetConfigTaskData *get_config_data)
|
||||
{
|
||||
gs_free const char *uri = NULL;
|
||||
AzureData *azure_data;
|
||||
gs_free const char *uri = NULL;
|
||||
AzureData * azure_data;
|
||||
|
||||
azure_data = g_slice_new (AzureData);
|
||||
*azure_data = (AzureData) {
|
||||
.config_data = get_config_data,
|
||||
.n_ifaces_pending = 0,
|
||||
};
|
||||
azure_data = g_slice_new(AzureData);
|
||||
*azure_data = (AzureData){
|
||||
.config_data = get_config_data,
|
||||
.n_ifaces_pending = 0,
|
||||
};
|
||||
|
||||
nm_http_client_poll_get (nmcs_provider_get_http_client (provider),
|
||||
(uri = _azure_uri_interfaces ()),
|
||||
HTTP_TIMEOUT_MS,
|
||||
256 * 1024,
|
||||
15000,
|
||||
1000,
|
||||
NM_MAKE_STRV (NM_AZURE_METADATA_HEADER),
|
||||
g_task_get_cancellable (get_config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_net_ifaces_list_cb,
|
||||
azure_data);
|
||||
nm_http_client_poll_get(nmcs_provider_get_http_client(provider),
|
||||
(uri = _azure_uri_interfaces()),
|
||||
HTTP_TIMEOUT_MS,
|
||||
256 * 1024,
|
||||
15000,
|
||||
1000,
|
||||
NM_MAKE_STRV(NM_AZURE_METADATA_HEADER),
|
||||
g_task_get_cancellable(get_config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_net_ifaces_list_cb,
|
||||
azure_data);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
nmcs_provider_azure_init (NMCSProviderAzure *self)
|
||||
{
|
||||
}
|
||||
nmcs_provider_azure_init(NMCSProviderAzure *self)
|
||||
{}
|
||||
|
||||
static void
|
||||
nmcs_provider_azure_class_init (NMCSProviderAzureClass *klass)
|
||||
nmcs_provider_azure_class_init(NMCSProviderAzureClass *klass)
|
||||
{
|
||||
NMCSProviderClass *provider_class = NMCS_PROVIDER_CLASS (klass);
|
||||
NMCSProviderClass *provider_class = NMCS_PROVIDER_CLASS(klass);
|
||||
|
||||
provider_class->_name = "azure";
|
||||
provider_class->_env_provider_enabled = NMCS_ENV_VARIABLE ("NM_CLOUD_SETUP_AZURE");
|
||||
provider_class->detect = detect;
|
||||
provider_class->get_config = get_config;
|
||||
provider_class->_name = "azure";
|
||||
provider_class->_env_provider_enabled = NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_AZURE");
|
||||
provider_class->detect = detect;
|
||||
provider_class->get_config = get_config;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,16 +10,19 @@
|
|||
typedef struct _NMCSProviderAzure NMCSProviderAzure;
|
||||
typedef struct _NMCSProviderAzureClass NMCSProviderAzureClass;
|
||||
|
||||
#define NMCS_TYPE_PROVIDER_AZURE (nmcs_provider_azure_get_type ())
|
||||
#define NMCS_PROVIDER_AZURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMCS_TYPE_PROVIDER_AZURE, NMCSProviderAzure))
|
||||
#define NMCS_PROVIDER_AZURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMCS_TYPE_PROVIDER_AZURE, NMCSProviderAzureClass))
|
||||
#define NMCS_IS_PROVIDER_AZURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMCS_TYPE_PROVIDER_AZURE))
|
||||
#define NMCS_IS_PROVIDER_AZURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMCS_TYPE_PROVIDER_AZURE))
|
||||
#define NMCS_PROVIDER_AZURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMCS_TYPE_PROVIDER_AZURE, NMCSProviderAzureClass))
|
||||
#define NMCS_TYPE_PROVIDER_AZURE (nmcs_provider_azure_get_type())
|
||||
#define NMCS_PROVIDER_AZURE(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMCS_TYPE_PROVIDER_AZURE, NMCSProviderAzure))
|
||||
#define NMCS_PROVIDER_AZURE_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMCS_TYPE_PROVIDER_AZURE, NMCSProviderAzureClass))
|
||||
#define NMCS_IS_PROVIDER_AZURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMCS_TYPE_PROVIDER_AZURE))
|
||||
#define NMCS_IS_PROVIDER_AZURE_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass), NMCS_TYPE_PROVIDER_AZURE))
|
||||
#define NMCS_PROVIDER_AZURE_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMCS_TYPE_PROVIDER_AZURE, NMCSProviderAzureClass))
|
||||
|
||||
GType nmcs_provider_azure_get_type (void);
|
||||
GType nmcs_provider_azure_get_type(void);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif /* __NMCS_PROVIDER_AZURE_H__ */
|
||||
|
||||
|
|
|
|||
|
|
@ -10,533 +10,509 @@
|
|||
|
||||
#define HTTP_TIMEOUT_MS 3000
|
||||
|
||||
#define NM_EC2_HOST "169.254.169.254"
|
||||
#define NM_EC2_BASE "http://" NM_EC2_HOST
|
||||
#define NM_EC2_API_VERSION "2018-09-24"
|
||||
#define NM_EC2_METADATA_URL_BASE /* $NM_EC2_BASE/$NM_EC2_API_VERSION */ "/meta-data/network/interfaces/macs/"
|
||||
#define NM_EC2_HOST "169.254.169.254"
|
||||
#define NM_EC2_BASE "http://" NM_EC2_HOST
|
||||
#define NM_EC2_API_VERSION "2018-09-24"
|
||||
#define NM_EC2_METADATA_URL_BASE /* $NM_EC2_BASE/$NM_EC2_API_VERSION */ \
|
||||
"/meta-data/network/interfaces/macs/"
|
||||
|
||||
static const char *
|
||||
_ec2_base (void)
|
||||
_ec2_base(void)
|
||||
{
|
||||
static const char *base_cached = NULL;
|
||||
const char *base;
|
||||
static const char *base_cached = NULL;
|
||||
const char * base;
|
||||
|
||||
again:
|
||||
base = g_atomic_pointer_get (&base_cached);
|
||||
if (G_UNLIKELY (!base)) {
|
||||
|
||||
/* The base URI can be set via environment variable.
|
||||
base = g_atomic_pointer_get(&base_cached);
|
||||
if (G_UNLIKELY(!base)) {
|
||||
/* The base URI can be set via environment variable.
|
||||
* This is mainly for testing, it's not usually supposed to be configured.
|
||||
* Consider this private API! */
|
||||
base = g_getenv (NMCS_ENV_VARIABLE ("NM_CLOUD_SETUP_EC2_HOST"));
|
||||
base = g_getenv(NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_EC2_HOST"));
|
||||
|
||||
if ( base
|
||||
&& base[0]
|
||||
&& !strchr (base, '/')) {
|
||||
if ( NM_STR_HAS_PREFIX (base, "http://")
|
||||
|| NM_STR_HAS_PREFIX (base, "https://"))
|
||||
base = g_intern_string (base);
|
||||
else {
|
||||
gs_free char *s = NULL;
|
||||
if (base && base[0] && !strchr(base, '/')) {
|
||||
if (NM_STR_HAS_PREFIX(base, "http://") || NM_STR_HAS_PREFIX(base, "https://"))
|
||||
base = g_intern_string(base);
|
||||
else {
|
||||
gs_free char *s = NULL;
|
||||
|
||||
s = g_strconcat ("http://", base, NULL);
|
||||
base = g_intern_string (s);
|
||||
}
|
||||
}
|
||||
if (!base)
|
||||
base = NM_EC2_BASE;
|
||||
s = g_strconcat("http://", base, NULL);
|
||||
base = g_intern_string(s);
|
||||
}
|
||||
}
|
||||
if (!base)
|
||||
base = NM_EC2_BASE;
|
||||
|
||||
nm_assert (!NM_STR_HAS_SUFFIX (base, "/"));
|
||||
nm_assert(!NM_STR_HAS_SUFFIX(base, "/"));
|
||||
|
||||
if (!g_atomic_pointer_compare_and_exchange (&base_cached, NULL, base))
|
||||
goto again;
|
||||
}
|
||||
if (!g_atomic_pointer_compare_and_exchange(&base_cached, NULL, base))
|
||||
goto again;
|
||||
}
|
||||
|
||||
return base;
|
||||
return base;
|
||||
}
|
||||
|
||||
#define _ec2_uri_concat(...) nmcs_utils_uri_build_concat (_ec2_base (), __VA_ARGS__)
|
||||
#define _ec2_uri_interfaces(...) _ec2_uri_concat (NM_EC2_API_VERSION, NM_EC2_METADATA_URL_BASE, ##__VA_ARGS__)
|
||||
#define _ec2_uri_concat(...) nmcs_utils_uri_build_concat(_ec2_base(), __VA_ARGS__)
|
||||
#define _ec2_uri_interfaces(...) \
|
||||
_ec2_uri_concat(NM_EC2_API_VERSION, NM_EC2_METADATA_URL_BASE, ##__VA_ARGS__)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
struct _NMCSProviderEC2 {
|
||||
NMCSProvider parent;
|
||||
NMCSProvider parent;
|
||||
};
|
||||
|
||||
struct _NMCSProviderEC2Class {
|
||||
NMCSProviderClass parent;
|
||||
NMCSProviderClass parent;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (NMCSProviderEC2, nmcs_provider_ec2, NMCS_TYPE_PROVIDER);
|
||||
G_DEFINE_TYPE(NMCSProviderEC2, nmcs_provider_ec2, NMCS_TYPE_PROVIDER);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
_detect_get_meta_data_check_cb (long response_code,
|
||||
GBytes *response_data,
|
||||
gpointer check_user_data,
|
||||
GError **error)
|
||||
_detect_get_meta_data_check_cb(long response_code,
|
||||
GBytes * response_data,
|
||||
gpointer check_user_data,
|
||||
GError **error)
|
||||
{
|
||||
return response_code == 200
|
||||
&& nmcs_utils_parse_get_full_line (response_data, "ami-id");
|
||||
return response_code == 200 && nmcs_utils_parse_get_full_line(response_data, "ami-id");
|
||||
}
|
||||
|
||||
static void
|
||||
_detect_get_meta_data_done_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_detect_get_meta_data_done_cb(GObject *source, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
gs_unref_object GTask *task = user_data;
|
||||
gs_free_error GError *get_error = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_unref_object GTask *task = user_data;
|
||||
gs_free_error GError *get_error = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
nm_http_client_poll_get_finish (NM_HTTP_CLIENT (source),
|
||||
result,
|
||||
NULL,
|
||||
NULL,
|
||||
&get_error);
|
||||
nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, NULL, &get_error);
|
||||
|
||||
if (nm_utils_error_is_cancelled (get_error)) {
|
||||
g_task_return_error (task, g_steal_pointer (&get_error));
|
||||
return;
|
||||
}
|
||||
if (nm_utils_error_is_cancelled(get_error)) {
|
||||
g_task_return_error(task, g_steal_pointer(&get_error));
|
||||
return;
|
||||
}
|
||||
|
||||
if (get_error) {
|
||||
nm_utils_error_set (&error,
|
||||
NM_UTILS_ERROR_UNKNOWN,
|
||||
"failure to get EC2 metadata: %s",
|
||||
get_error->message);
|
||||
g_task_return_error (task, g_steal_pointer (&error));
|
||||
return;
|
||||
}
|
||||
if (get_error) {
|
||||
nm_utils_error_set(&error,
|
||||
NM_UTILS_ERROR_UNKNOWN,
|
||||
"failure to get EC2 metadata: %s",
|
||||
get_error->message);
|
||||
g_task_return_error(task, g_steal_pointer(&error));
|
||||
return;
|
||||
}
|
||||
|
||||
g_task_return_boolean (task, TRUE);
|
||||
g_task_return_boolean(task, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
detect (NMCSProvider *provider,
|
||||
GTask *task)
|
||||
detect(NMCSProvider *provider, GTask *task)
|
||||
{
|
||||
NMHttpClient *http_client;
|
||||
gs_free char *uri = NULL;
|
||||
NMHttpClient *http_client;
|
||||
gs_free char *uri = NULL;
|
||||
|
||||
http_client = nmcs_provider_get_http_client (provider);
|
||||
http_client = nmcs_provider_get_http_client(provider);
|
||||
|
||||
nm_http_client_poll_get (http_client,
|
||||
(uri = _ec2_uri_concat ("latest/meta-data/")),
|
||||
HTTP_TIMEOUT_MS,
|
||||
256*1024,
|
||||
7000,
|
||||
1000,
|
||||
NULL,
|
||||
g_task_get_cancellable (task),
|
||||
_detect_get_meta_data_check_cb,
|
||||
NULL,
|
||||
_detect_get_meta_data_done_cb,
|
||||
task);
|
||||
nm_http_client_poll_get(http_client,
|
||||
(uri = _ec2_uri_concat("latest/meta-data/")),
|
||||
HTTP_TIMEOUT_MS,
|
||||
256 * 1024,
|
||||
7000,
|
||||
1000,
|
||||
NULL,
|
||||
g_task_get_cancellable(task),
|
||||
_detect_get_meta_data_check_cb,
|
||||
NULL,
|
||||
_detect_get_meta_data_done_cb,
|
||||
task);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
NMCSProviderGetConfigTaskData *get_config_data;
|
||||
GError *error;
|
||||
GCancellable *cancellable;
|
||||
gulong cancelled_id;
|
||||
guint n_pending;
|
||||
NMCSProviderGetConfigTaskData *get_config_data;
|
||||
GError * error;
|
||||
GCancellable * cancellable;
|
||||
gulong cancelled_id;
|
||||
guint n_pending;
|
||||
} GetConfigIfaceData;
|
||||
|
||||
static void
|
||||
_get_config_task_maybe_return (GetConfigIfaceData *iface_data,
|
||||
GError *error_take)
|
||||
_get_config_task_maybe_return(GetConfigIfaceData *iface_data, GError *error_take)
|
||||
{
|
||||
NMCSProviderGetConfigTaskData *get_config_data = iface_data->get_config_data;
|
||||
NMCSProviderGetConfigTaskData *get_config_data = iface_data->get_config_data;
|
||||
|
||||
if (error_take) {
|
||||
if (!iface_data->error)
|
||||
iface_data->error = error_take;
|
||||
else if ( !nm_utils_error_is_cancelled (iface_data->error)
|
||||
&& nm_utils_error_is_cancelled (error_take)) {
|
||||
nm_clear_error (&iface_data->error);
|
||||
iface_data->error = error_take;
|
||||
} else
|
||||
g_error_free (error_take);
|
||||
}
|
||||
if (error_take) {
|
||||
if (!iface_data->error)
|
||||
iface_data->error = error_take;
|
||||
else if (!nm_utils_error_is_cancelled(iface_data->error)
|
||||
&& nm_utils_error_is_cancelled(error_take)) {
|
||||
nm_clear_error(&iface_data->error);
|
||||
iface_data->error = error_take;
|
||||
} else
|
||||
g_error_free(error_take);
|
||||
}
|
||||
|
||||
if (iface_data->n_pending > 0)
|
||||
return;
|
||||
if (iface_data->n_pending > 0)
|
||||
return;
|
||||
|
||||
nm_clear_g_cancellable_disconnect (g_task_get_cancellable (get_config_data->task),
|
||||
&iface_data->cancelled_id);
|
||||
nm_clear_g_cancellable_disconnect(g_task_get_cancellable(get_config_data->task),
|
||||
&iface_data->cancelled_id);
|
||||
|
||||
nm_clear_g_cancellable (&iface_data->cancellable);
|
||||
nm_clear_g_cancellable(&iface_data->cancellable);
|
||||
|
||||
if (iface_data->error) {
|
||||
if (nm_utils_error_is_cancelled (iface_data->error))
|
||||
_LOGD ("get-config: cancelled");
|
||||
else
|
||||
_LOGD ("get-config: failed: %s", iface_data->error->message);
|
||||
g_task_return_error (get_config_data->task, g_steal_pointer (&iface_data->error));
|
||||
} else {
|
||||
_LOGD ("get-config: success");
|
||||
g_task_return_pointer (get_config_data->task,
|
||||
g_hash_table_ref (get_config_data->result_dict),
|
||||
(GDestroyNotify) g_hash_table_unref);
|
||||
}
|
||||
if (iface_data->error) {
|
||||
if (nm_utils_error_is_cancelled(iface_data->error))
|
||||
_LOGD("get-config: cancelled");
|
||||
else
|
||||
_LOGD("get-config: failed: %s", iface_data->error->message);
|
||||
g_task_return_error(get_config_data->task, g_steal_pointer(&iface_data->error));
|
||||
} else {
|
||||
_LOGD("get-config: success");
|
||||
g_task_return_pointer(get_config_data->task,
|
||||
g_hash_table_ref(get_config_data->result_dict),
|
||||
(GDestroyNotify) g_hash_table_unref);
|
||||
}
|
||||
|
||||
nm_g_slice_free (iface_data);
|
||||
g_object_unref (get_config_data->task);
|
||||
nm_g_slice_free(iface_data);
|
||||
g_object_unref(get_config_data->task);
|
||||
}
|
||||
|
||||
static void
|
||||
_get_config_fetch_done_cb (NMHttpClient *http_client,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data,
|
||||
gboolean is_local_ipv4)
|
||||
_get_config_fetch_done_cb(NMHttpClient *http_client,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data,
|
||||
gboolean is_local_ipv4)
|
||||
{
|
||||
GetConfigIfaceData *iface_data;
|
||||
const char *hwaddr = NULL;
|
||||
gs_unref_bytes GBytes *response_data = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
GetConfigIfaceData *iface_data;
|
||||
const char * hwaddr = NULL;
|
||||
gs_unref_bytes GBytes *response_data = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
nm_utils_user_data_unpack (user_data, &iface_data, &hwaddr);
|
||||
nm_utils_user_data_unpack(user_data, &iface_data, &hwaddr);
|
||||
|
||||
nm_http_client_poll_get_finish (http_client,
|
||||
result,
|
||||
NULL,
|
||||
&response_data,
|
||||
&error);
|
||||
nm_http_client_poll_get_finish(http_client, result, NULL, &response_data, &error);
|
||||
|
||||
if (!error) {
|
||||
NMCSProviderGetConfigIfaceData *config_iface_data;
|
||||
in_addr_t tmp_addr;
|
||||
int tmp_prefix;
|
||||
if (!error) {
|
||||
NMCSProviderGetConfigIfaceData *config_iface_data;
|
||||
in_addr_t tmp_addr;
|
||||
int tmp_prefix;
|
||||
|
||||
config_iface_data = g_hash_table_lookup (iface_data->get_config_data->result_dict, hwaddr);
|
||||
config_iface_data = g_hash_table_lookup(iface_data->get_config_data->result_dict, hwaddr);
|
||||
|
||||
if (is_local_ipv4) {
|
||||
gs_free const char **s_addrs = NULL;
|
||||
gsize i, len;
|
||||
if (is_local_ipv4) {
|
||||
gs_free const char **s_addrs = NULL;
|
||||
gsize i, len;
|
||||
|
||||
s_addrs = nm_utils_strsplit_set_full (g_bytes_get_data (response_data, NULL), "\n", NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP);
|
||||
len = NM_PTRARRAY_LEN (s_addrs);
|
||||
s_addrs = nm_utils_strsplit_set_full(g_bytes_get_data(response_data, NULL),
|
||||
"\n",
|
||||
NM_UTILS_STRSPLIT_SET_FLAGS_STRSTRIP);
|
||||
len = NM_PTRARRAY_LEN(s_addrs);
|
||||
|
||||
nm_assert (!config_iface_data->has_ipv4s);
|
||||
nm_assert (!config_iface_data->ipv4s_arr);
|
||||
config_iface_data->has_ipv4s = TRUE;
|
||||
config_iface_data->ipv4s_len = 0;
|
||||
if (len > 0) {
|
||||
config_iface_data->ipv4s_arr = g_new (in_addr_t, len);
|
||||
nm_assert(!config_iface_data->has_ipv4s);
|
||||
nm_assert(!config_iface_data->ipv4s_arr);
|
||||
config_iface_data->has_ipv4s = TRUE;
|
||||
config_iface_data->ipv4s_len = 0;
|
||||
if (len > 0) {
|
||||
config_iface_data->ipv4s_arr = g_new(in_addr_t, len);
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (nm_utils_parse_inaddr_bin (AF_INET,
|
||||
s_addrs[i],
|
||||
NULL,
|
||||
&tmp_addr))
|
||||
config_iface_data->ipv4s_arr[config_iface_data->ipv4s_len++] = tmp_addr;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (nm_utils_parse_inaddr_prefix_bin (AF_INET,
|
||||
g_bytes_get_data (response_data, NULL),
|
||||
NULL,
|
||||
&tmp_addr,
|
||||
&tmp_prefix)) {
|
||||
nm_assert (!config_iface_data->has_cidr);
|
||||
config_iface_data->has_cidr = TRUE;
|
||||
config_iface_data->cidr_prefix = tmp_prefix;
|
||||
config_iface_data->cidr_addr = tmp_addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
if (nm_utils_parse_inaddr_bin(AF_INET, s_addrs[i], NULL, &tmp_addr))
|
||||
config_iface_data->ipv4s_arr[config_iface_data->ipv4s_len++] = tmp_addr;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (nm_utils_parse_inaddr_prefix_bin(AF_INET,
|
||||
g_bytes_get_data(response_data, NULL),
|
||||
NULL,
|
||||
&tmp_addr,
|
||||
&tmp_prefix)) {
|
||||
nm_assert(!config_iface_data->has_cidr);
|
||||
config_iface_data->has_cidr = TRUE;
|
||||
config_iface_data->cidr_prefix = tmp_prefix;
|
||||
config_iface_data->cidr_addr = tmp_addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iface_data->n_pending--;
|
||||
_get_config_task_maybe_return (iface_data, g_steal_pointer (&error));
|
||||
iface_data->n_pending--;
|
||||
_get_config_task_maybe_return(iface_data, g_steal_pointer(&error));
|
||||
}
|
||||
|
||||
static void
|
||||
_get_config_fetch_done_cb_subnet_ipv4_cidr_block (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_get_config_fetch_done_cb_subnet_ipv4_cidr_block(GObject * source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
_get_config_fetch_done_cb (NM_HTTP_CLIENT (source), result, user_data, FALSE);
|
||||
_get_config_fetch_done_cb(NM_HTTP_CLIENT(source), result, user_data, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
_get_config_fetch_done_cb_local_ipv4s (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_get_config_fetch_done_cb_local_ipv4s(GObject *source, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
_get_config_fetch_done_cb (NM_HTTP_CLIENT (source), result, user_data, TRUE);
|
||||
_get_config_fetch_done_cb(NM_HTTP_CLIENT(source), result, user_data, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
_get_config_fetch_cancelled_cb (GObject *object, gpointer user_data)
|
||||
_get_config_fetch_cancelled_cb(GObject *object, gpointer user_data)
|
||||
{
|
||||
GetConfigIfaceData *iface_data = user_data;
|
||||
GetConfigIfaceData *iface_data = user_data;
|
||||
|
||||
if (iface_data->cancelled_id == 0)
|
||||
return;
|
||||
if (iface_data->cancelled_id == 0)
|
||||
return;
|
||||
|
||||
nm_clear_g_signal_handler (g_task_get_cancellable (iface_data->get_config_data->task),
|
||||
&iface_data->cancelled_id);
|
||||
_get_config_task_maybe_return (iface_data,
|
||||
nm_utils_error_new_cancelled (FALSE, NULL));
|
||||
nm_clear_g_signal_handler(g_task_get_cancellable(iface_data->get_config_data->task),
|
||||
&iface_data->cancelled_id);
|
||||
_get_config_task_maybe_return(iface_data, nm_utils_error_new_cancelled(FALSE, NULL));
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
NMCSProviderGetConfigTaskData *get_config_data;
|
||||
GHashTable *response_parsed;
|
||||
NMCSProviderGetConfigTaskData *get_config_data;
|
||||
GHashTable * response_parsed;
|
||||
} GetConfigMetadataData;
|
||||
|
||||
typedef struct {
|
||||
gssize iface_idx;
|
||||
char path[0];
|
||||
gssize iface_idx;
|
||||
char path[0];
|
||||
} GetConfigMetadataMac;
|
||||
|
||||
static void
|
||||
_get_config_metadata_ready_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_get_config_metadata_ready_cb(GObject *source, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
GetConfigMetadataData *metadata_data = user_data;
|
||||
GetConfigIfaceData *iface_data;
|
||||
NMCSProviderGetConfigTaskData *get_config_data = metadata_data->get_config_data;
|
||||
gs_unref_hashtable GHashTable *response_parsed = g_steal_pointer (&metadata_data->response_parsed);
|
||||
gs_free_error GError *error = NULL;
|
||||
GCancellable *cancellable;
|
||||
GetConfigMetadataMac *v_mac_data;
|
||||
const char *v_hwaddr;
|
||||
GHashTableIter h_iter;
|
||||
NMHttpClient *http_client;
|
||||
GetConfigMetadataData * metadata_data = user_data;
|
||||
GetConfigIfaceData * iface_data;
|
||||
NMCSProviderGetConfigTaskData *get_config_data = metadata_data->get_config_data;
|
||||
gs_unref_hashtable GHashTable *response_parsed =
|
||||
g_steal_pointer(&metadata_data->response_parsed);
|
||||
gs_free_error GError *error = NULL;
|
||||
GCancellable * cancellable;
|
||||
GetConfigMetadataMac *v_mac_data;
|
||||
const char * v_hwaddr;
|
||||
GHashTableIter h_iter;
|
||||
NMHttpClient * http_client;
|
||||
|
||||
nm_g_slice_free (metadata_data);
|
||||
nm_g_slice_free(metadata_data);
|
||||
|
||||
nm_http_client_poll_get_finish (NM_HTTP_CLIENT (source),
|
||||
result,
|
||||
NULL,
|
||||
NULL,
|
||||
&error);
|
||||
nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, NULL, &error);
|
||||
|
||||
iface_data = g_slice_new (GetConfigIfaceData);
|
||||
*iface_data = (GetConfigIfaceData) {
|
||||
.get_config_data = get_config_data,
|
||||
.n_pending = 0,
|
||||
};
|
||||
iface_data = g_slice_new(GetConfigIfaceData);
|
||||
*iface_data = (GetConfigIfaceData){
|
||||
.get_config_data = get_config_data,
|
||||
.n_pending = 0,
|
||||
};
|
||||
|
||||
if (nm_utils_error_is_cancelled (error)) {
|
||||
_get_config_task_maybe_return (iface_data, g_steal_pointer (&error));
|
||||
return;
|
||||
}
|
||||
if (nm_utils_error_is_cancelled(error)) {
|
||||
_get_config_task_maybe_return(iface_data, g_steal_pointer(&error));
|
||||
return;
|
||||
}
|
||||
|
||||
/* We ignore errors. Only if we got no response at all, it's a problem.
|
||||
/* We ignore errors. Only if we got no response at all, it's a problem.
|
||||
* Otherwise, we proceed with whatever we could fetch. */
|
||||
if (!response_parsed) {
|
||||
_get_config_task_maybe_return (iface_data,
|
||||
nm_utils_error_new (NM_UTILS_ERROR_UNKNOWN,
|
||||
"meta data for interfaces not found"));
|
||||
return;
|
||||
}
|
||||
if (!response_parsed) {
|
||||
_get_config_task_maybe_return(
|
||||
iface_data,
|
||||
nm_utils_error_new(NM_UTILS_ERROR_UNKNOWN, "meta data for interfaces not found"));
|
||||
return;
|
||||
}
|
||||
|
||||
cancellable = g_task_get_cancellable (get_config_data->task);
|
||||
if (cancellable) {
|
||||
gulong cancelled_id;
|
||||
cancellable = g_task_get_cancellable(get_config_data->task);
|
||||
if (cancellable) {
|
||||
gulong cancelled_id;
|
||||
|
||||
cancelled_id = g_cancellable_connect (cancellable,
|
||||
G_CALLBACK (_get_config_fetch_cancelled_cb),
|
||||
iface_data,
|
||||
NULL);
|
||||
if (cancelled_id == 0) {
|
||||
_get_config_task_maybe_return (iface_data,
|
||||
nm_utils_error_new_cancelled (FALSE, NULL));
|
||||
return;
|
||||
}
|
||||
cancelled_id = g_cancellable_connect(cancellable,
|
||||
G_CALLBACK(_get_config_fetch_cancelled_cb),
|
||||
iface_data,
|
||||
NULL);
|
||||
if (cancelled_id == 0) {
|
||||
_get_config_task_maybe_return(iface_data, nm_utils_error_new_cancelled(FALSE, NULL));
|
||||
return;
|
||||
}
|
||||
|
||||
iface_data->cancelled_id = cancelled_id;
|
||||
}
|
||||
iface_data->cancelled_id = cancelled_id;
|
||||
}
|
||||
|
||||
iface_data->cancellable = g_cancellable_new ();
|
||||
iface_data->cancellable = g_cancellable_new();
|
||||
|
||||
http_client = nmcs_provider_get_http_client (g_task_get_source_object (get_config_data->task));
|
||||
http_client = nmcs_provider_get_http_client(g_task_get_source_object(get_config_data->task));
|
||||
|
||||
g_hash_table_iter_init (&h_iter, response_parsed);
|
||||
while (g_hash_table_iter_next (&h_iter, (gpointer *) &v_hwaddr, (gpointer *) &v_mac_data)) {
|
||||
NMCSProviderGetConfigIfaceData *config_iface_data;
|
||||
gs_free char *uri1 = NULL;
|
||||
gs_free char *uri2 = NULL;
|
||||
const char *hwaddr;
|
||||
g_hash_table_iter_init(&h_iter, response_parsed);
|
||||
while (g_hash_table_iter_next(&h_iter, (gpointer *) &v_hwaddr, (gpointer *) &v_mac_data)) {
|
||||
NMCSProviderGetConfigIfaceData *config_iface_data;
|
||||
gs_free char * uri1 = NULL;
|
||||
gs_free char * uri2 = NULL;
|
||||
const char * hwaddr;
|
||||
|
||||
if (!g_hash_table_lookup_extended (get_config_data->result_dict, v_hwaddr, (gpointer *) &hwaddr, (gpointer *) &config_iface_data)) {
|
||||
if (!get_config_data->any) {
|
||||
_LOGD ("get-config: skip fetching meta data for %s (%s)", v_hwaddr, v_mac_data->path);
|
||||
continue;
|
||||
}
|
||||
config_iface_data = nmcs_provider_get_config_iface_data_new (FALSE);
|
||||
g_hash_table_insert (get_config_data->result_dict,
|
||||
(char *) (hwaddr = g_strdup (v_hwaddr)),
|
||||
config_iface_data);
|
||||
}
|
||||
if (!g_hash_table_lookup_extended(get_config_data->result_dict,
|
||||
v_hwaddr,
|
||||
(gpointer *) &hwaddr,
|
||||
(gpointer *) &config_iface_data)) {
|
||||
if (!get_config_data->any) {
|
||||
_LOGD("get-config: skip fetching meta data for %s (%s)",
|
||||
v_hwaddr,
|
||||
v_mac_data->path);
|
||||
continue;
|
||||
}
|
||||
config_iface_data = nmcs_provider_get_config_iface_data_new(FALSE);
|
||||
g_hash_table_insert(get_config_data->result_dict,
|
||||
(char *) (hwaddr = g_strdup(v_hwaddr)),
|
||||
config_iface_data);
|
||||
}
|
||||
|
||||
nm_assert (config_iface_data->iface_idx == -1);
|
||||
config_iface_data->iface_idx = v_mac_data->iface_idx;
|
||||
nm_assert(config_iface_data->iface_idx == -1);
|
||||
config_iface_data->iface_idx = v_mac_data->iface_idx;
|
||||
|
||||
_LOGD ("get-config: start fetching meta data for #%"G_GSSIZE_FORMAT", %s (%s)", config_iface_data->iface_idx, hwaddr, v_mac_data->path);
|
||||
_LOGD("get-config: start fetching meta data for #%" G_GSSIZE_FORMAT ", %s (%s)",
|
||||
config_iface_data->iface_idx,
|
||||
hwaddr,
|
||||
v_mac_data->path);
|
||||
|
||||
iface_data->n_pending++;
|
||||
nm_http_client_poll_get (http_client,
|
||||
(uri1 = _ec2_uri_interfaces (v_mac_data->path,
|
||||
NM_STR_HAS_SUFFIX (v_mac_data->path, "/")
|
||||
? ""
|
||||
: "/",
|
||||
"subnet-ipv4-cidr-block")),
|
||||
HTTP_TIMEOUT_MS,
|
||||
512*1024,
|
||||
10000,
|
||||
1000,
|
||||
NULL,
|
||||
iface_data->cancellable,
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_fetch_done_cb_subnet_ipv4_cidr_block,
|
||||
nm_utils_user_data_pack (iface_data, hwaddr));
|
||||
iface_data->n_pending++;
|
||||
nm_http_client_poll_get(
|
||||
http_client,
|
||||
(uri1 = _ec2_uri_interfaces(v_mac_data->path,
|
||||
NM_STR_HAS_SUFFIX(v_mac_data->path, "/") ? "" : "/",
|
||||
"subnet-ipv4-cidr-block")),
|
||||
HTTP_TIMEOUT_MS,
|
||||
512 * 1024,
|
||||
10000,
|
||||
1000,
|
||||
NULL,
|
||||
iface_data->cancellable,
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_fetch_done_cb_subnet_ipv4_cidr_block,
|
||||
nm_utils_user_data_pack(iface_data, hwaddr));
|
||||
|
||||
iface_data->n_pending++;
|
||||
nm_http_client_poll_get (http_client,
|
||||
(uri2 = _ec2_uri_interfaces (v_mac_data->path,
|
||||
NM_STR_HAS_SUFFIX (v_mac_data->path, "/")
|
||||
? ""
|
||||
: "/",
|
||||
"local-ipv4s")),
|
||||
HTTP_TIMEOUT_MS,
|
||||
512*1024,
|
||||
10000,
|
||||
1000,
|
||||
NULL,
|
||||
iface_data->cancellable,
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_fetch_done_cb_local_ipv4s,
|
||||
nm_utils_user_data_pack (iface_data, hwaddr));
|
||||
}
|
||||
iface_data->n_pending++;
|
||||
nm_http_client_poll_get(
|
||||
http_client,
|
||||
(uri2 = _ec2_uri_interfaces(v_mac_data->path,
|
||||
NM_STR_HAS_SUFFIX(v_mac_data->path, "/") ? "" : "/",
|
||||
"local-ipv4s")),
|
||||
HTTP_TIMEOUT_MS,
|
||||
512 * 1024,
|
||||
10000,
|
||||
1000,
|
||||
NULL,
|
||||
iface_data->cancellable,
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_fetch_done_cb_local_ipv4s,
|
||||
nm_utils_user_data_pack(iface_data, hwaddr));
|
||||
}
|
||||
|
||||
_get_config_task_maybe_return (iface_data, NULL);
|
||||
_get_config_task_maybe_return(iface_data, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_get_config_metadata_ready_check (long response_code,
|
||||
GBytes *response_data,
|
||||
gpointer check_user_data,
|
||||
GError **error)
|
||||
_get_config_metadata_ready_check(long response_code,
|
||||
GBytes * response_data,
|
||||
gpointer check_user_data,
|
||||
GError **error)
|
||||
{
|
||||
GetConfigMetadataData *metadata_data = check_user_data;
|
||||
gs_unref_hashtable GHashTable *response_parsed = NULL;
|
||||
const guint8 *r_data;
|
||||
const char *cur_line;
|
||||
gsize r_len;
|
||||
gsize cur_line_len;
|
||||
GHashTableIter h_iter;
|
||||
gboolean has_all;
|
||||
const char *c_hwaddr;
|
||||
gssize iface_idx_counter = 0;
|
||||
GetConfigMetadataData *metadata_data = check_user_data;
|
||||
gs_unref_hashtable GHashTable *response_parsed = NULL;
|
||||
const guint8 * r_data;
|
||||
const char * cur_line;
|
||||
gsize r_len;
|
||||
gsize cur_line_len;
|
||||
GHashTableIter h_iter;
|
||||
gboolean has_all;
|
||||
const char * c_hwaddr;
|
||||
gssize iface_idx_counter = 0;
|
||||
|
||||
if ( response_code != 200
|
||||
|| !response_data) {
|
||||
/* we wait longer. */
|
||||
return FALSE;
|
||||
}
|
||||
if (response_code != 200 || !response_data) {
|
||||
/* we wait longer. */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
r_data = g_bytes_get_data (response_data, &r_len);
|
||||
/* NMHttpClient guarantees that there is a trailing NUL after the data. */
|
||||
nm_assert (r_data[r_len] == 0);
|
||||
r_data = g_bytes_get_data(response_data, &r_len);
|
||||
/* NMHttpClient guarantees that there is a trailing NUL after the data. */
|
||||
nm_assert(r_data[r_len] == 0);
|
||||
|
||||
while (nm_utils_parse_next_line ((const char **) &r_data, &r_len, &cur_line, &cur_line_len)) {
|
||||
GetConfigMetadataMac *mac_data;
|
||||
char *hwaddr;
|
||||
while (nm_utils_parse_next_line((const char **) &r_data, &r_len, &cur_line, &cur_line_len)) {
|
||||
GetConfigMetadataMac *mac_data;
|
||||
char * hwaddr;
|
||||
|
||||
if (cur_line_len == 0)
|
||||
continue;
|
||||
if (cur_line_len == 0)
|
||||
continue;
|
||||
|
||||
/* Truncate the string. It's safe to do, because we own @response_data an it has an
|
||||
/* Truncate the string. It's safe to do, because we own @response_data an it has an
|
||||
* extra NUL character after the buffer. */
|
||||
((char *) cur_line)[cur_line_len] = '\0';
|
||||
((char *) cur_line)[cur_line_len] = '\0';
|
||||
|
||||
hwaddr = nmcs_utils_hwaddr_normalize (cur_line,
|
||||
cur_line[cur_line_len - 1u] == '/'
|
||||
? (gssize) (cur_line_len - 1u)
|
||||
: -1);
|
||||
if (!hwaddr)
|
||||
continue;
|
||||
hwaddr = nmcs_utils_hwaddr_normalize(
|
||||
cur_line,
|
||||
cur_line[cur_line_len - 1u] == '/' ? (gssize)(cur_line_len - 1u) : -1);
|
||||
if (!hwaddr)
|
||||
continue;
|
||||
|
||||
if (!response_parsed)
|
||||
response_parsed = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free);
|
||||
if (!response_parsed)
|
||||
response_parsed = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, g_free);
|
||||
|
||||
mac_data = g_malloc (sizeof (GetConfigMetadataMac) + 1u + cur_line_len);
|
||||
mac_data->iface_idx = iface_idx_counter++;
|
||||
memcpy (mac_data->path, cur_line, cur_line_len + 1u);
|
||||
mac_data = g_malloc(sizeof(GetConfigMetadataMac) + 1u + cur_line_len);
|
||||
mac_data->iface_idx = iface_idx_counter++;
|
||||
memcpy(mac_data->path, cur_line, cur_line_len + 1u);
|
||||
|
||||
g_hash_table_insert (response_parsed, hwaddr, mac_data);
|
||||
}
|
||||
g_hash_table_insert(response_parsed, hwaddr, mac_data);
|
||||
}
|
||||
|
||||
has_all = TRUE;
|
||||
g_hash_table_iter_init (&h_iter, metadata_data->get_config_data->result_dict);
|
||||
while (g_hash_table_iter_next (&h_iter, (gpointer *) &c_hwaddr, NULL)) {
|
||||
if ( !response_parsed
|
||||
|| !g_hash_table_contains (response_parsed, c_hwaddr)) {
|
||||
has_all = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
has_all = TRUE;
|
||||
g_hash_table_iter_init(&h_iter, metadata_data->get_config_data->result_dict);
|
||||
while (g_hash_table_iter_next(&h_iter, (gpointer *) &c_hwaddr, NULL)) {
|
||||
if (!response_parsed || !g_hash_table_contains(response_parsed, c_hwaddr)) {
|
||||
has_all = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nm_clear_pointer (&metadata_data->response_parsed, g_hash_table_unref);
|
||||
metadata_data->response_parsed = g_steal_pointer (&response_parsed);
|
||||
return has_all;
|
||||
nm_clear_pointer(&metadata_data->response_parsed, g_hash_table_unref);
|
||||
metadata_data->response_parsed = g_steal_pointer(&response_parsed);
|
||||
return has_all;
|
||||
}
|
||||
|
||||
static void
|
||||
get_config (NMCSProvider *provider,
|
||||
NMCSProviderGetConfigTaskData *get_config_data)
|
||||
get_config(NMCSProvider *provider, NMCSProviderGetConfigTaskData *get_config_data)
|
||||
{
|
||||
gs_free char *uri = NULL;
|
||||
GetConfigMetadataData *metadata_data;
|
||||
gs_free char * uri = NULL;
|
||||
GetConfigMetadataData *metadata_data;
|
||||
|
||||
metadata_data = g_slice_new (GetConfigMetadataData);
|
||||
*metadata_data = (GetConfigMetadataData) {
|
||||
.get_config_data = get_config_data,
|
||||
};
|
||||
metadata_data = g_slice_new(GetConfigMetadataData);
|
||||
*metadata_data = (GetConfigMetadataData){
|
||||
.get_config_data = get_config_data,
|
||||
};
|
||||
|
||||
/* First we fetch the "macs/". If the caller requested some particular
|
||||
/* First we fetch the "macs/". If the caller requested some particular
|
||||
* MAC addresses, then we poll until we see them. They might not yet be
|
||||
* around from the start...
|
||||
*/
|
||||
nm_http_client_poll_get (nmcs_provider_get_http_client (provider),
|
||||
(uri = _ec2_uri_interfaces ()),
|
||||
HTTP_TIMEOUT_MS,
|
||||
256 * 1024,
|
||||
15000,
|
||||
1000,
|
||||
NULL,
|
||||
g_task_get_cancellable (get_config_data->task),
|
||||
_get_config_metadata_ready_check,
|
||||
metadata_data,
|
||||
_get_config_metadata_ready_cb,
|
||||
metadata_data);
|
||||
nm_http_client_poll_get(nmcs_provider_get_http_client(provider),
|
||||
(uri = _ec2_uri_interfaces()),
|
||||
HTTP_TIMEOUT_MS,
|
||||
256 * 1024,
|
||||
15000,
|
||||
1000,
|
||||
NULL,
|
||||
g_task_get_cancellable(get_config_data->task),
|
||||
_get_config_metadata_ready_check,
|
||||
metadata_data,
|
||||
_get_config_metadata_ready_cb,
|
||||
metadata_data);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
nmcs_provider_ec2_init (NMCSProviderEC2 *self)
|
||||
{
|
||||
}
|
||||
nmcs_provider_ec2_init(NMCSProviderEC2 *self)
|
||||
{}
|
||||
|
||||
static void
|
||||
nmcs_provider_ec2_class_init (NMCSProviderEC2Class *klass)
|
||||
nmcs_provider_ec2_class_init(NMCSProviderEC2Class *klass)
|
||||
{
|
||||
NMCSProviderClass *provider_class = NMCS_PROVIDER_CLASS (klass);
|
||||
NMCSProviderClass *provider_class = NMCS_PROVIDER_CLASS(klass);
|
||||
|
||||
provider_class->_name = "ec2";
|
||||
provider_class->_env_provider_enabled = NMCS_ENV_VARIABLE ("NM_CLOUD_SETUP_EC2");
|
||||
provider_class->detect = detect;
|
||||
provider_class->get_config = get_config;
|
||||
provider_class->_name = "ec2";
|
||||
provider_class->_env_provider_enabled = NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_EC2");
|
||||
provider_class->detect = detect;
|
||||
provider_class->get_config = get_config;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,14 +10,17 @@
|
|||
typedef struct _NMCSProviderEC2 NMCSProviderEC2;
|
||||
typedef struct _NMCSProviderEC2Class NMCSProviderEC2Class;
|
||||
|
||||
#define NMCS_TYPE_PROVIDER_EC2 (nmcs_provider_ec2_get_type ())
|
||||
#define NMCS_PROVIDER_EC2(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMCS_TYPE_PROVIDER_EC2, NMCSProviderEC2))
|
||||
#define NMCS_PROVIDER_EC2_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMCS_TYPE_PROVIDER_EC2, NMCSProviderEC2Class))
|
||||
#define NMCS_IS_PROVIDER_EC2(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMCS_TYPE_PROVIDER_EC2))
|
||||
#define NMCS_IS_PROVIDER_EC2_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMCS_TYPE_PROVIDER_EC2))
|
||||
#define NMCS_PROVIDER_EC2_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMCS_TYPE_PROVIDER_EC2, NMCSProviderEC2Class))
|
||||
#define NMCS_TYPE_PROVIDER_EC2 (nmcs_provider_ec2_get_type())
|
||||
#define NMCS_PROVIDER_EC2(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMCS_TYPE_PROVIDER_EC2, NMCSProviderEC2))
|
||||
#define NMCS_PROVIDER_EC2_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMCS_TYPE_PROVIDER_EC2, NMCSProviderEC2Class))
|
||||
#define NMCS_IS_PROVIDER_EC2(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMCS_TYPE_PROVIDER_EC2))
|
||||
#define NMCS_IS_PROVIDER_EC2_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMCS_TYPE_PROVIDER_EC2))
|
||||
#define NMCS_PROVIDER_EC2_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMCS_TYPE_PROVIDER_EC2, NMCSProviderEC2Class))
|
||||
|
||||
GType nmcs_provider_ec2_get_type (void);
|
||||
GType nmcs_provider_ec2_get_type(void);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
/*****************************************************************************/
|
||||
|
||||
#define HTTP_TIMEOUT_MS 3000
|
||||
#define HTTP_REQ_MAX_DATA 512*1024
|
||||
#define HTTP_REQ_MAX_DATA 512 * 1024
|
||||
#define HTTP_POLL_TIMEOUT_MS 10000
|
||||
#define HTTP_RATE_LIMIT_MS 1000
|
||||
|
||||
|
|
@ -19,489 +19,436 @@
|
|||
#define NM_GCP_METADATA_URL_BASE NM_GCP_BASE "/computeMetadata" NM_GCP_API_VERSION "/instance"
|
||||
#define NM_GCP_METADATA_URL_NET "/network-interfaces/"
|
||||
|
||||
#define NM_GCP_METADATA_HEADER "Metadata-Flavor: Google"
|
||||
#define NM_GCP_METADATA_HEADER "Metadata-Flavor: Google"
|
||||
|
||||
#define _gcp_uri_concat(...) nmcs_utils_uri_build_concat (NM_GCP_METADATA_URL_BASE, __VA_ARGS__)
|
||||
#define _gcp_uri_interfaces(...) _gcp_uri_concat (NM_GCP_METADATA_URL_NET, ##__VA_ARGS__)
|
||||
#define _gcp_uri_concat(...) nmcs_utils_uri_build_concat(NM_GCP_METADATA_URL_BASE, __VA_ARGS__)
|
||||
#define _gcp_uri_interfaces(...) _gcp_uri_concat(NM_GCP_METADATA_URL_NET, ##__VA_ARGS__)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
struct _NMCSProviderGCP {
|
||||
NMCSProvider parent;
|
||||
NMCSProvider parent;
|
||||
};
|
||||
|
||||
struct _NMCSProviderGCPClass {
|
||||
NMCSProviderClass parent;
|
||||
NMCSProviderClass parent;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (NMCSProviderGCP, nmcs_provider_gcp, NMCS_TYPE_PROVIDER);
|
||||
G_DEFINE_TYPE(NMCSProviderGCP, nmcs_provider_gcp, NMCS_TYPE_PROVIDER);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
_detect_get_meta_data_done_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_detect_get_meta_data_done_cb(GObject *source, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
gs_unref_object GTask *task = user_data;
|
||||
gs_free_error GError *get_error = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_unref_object GTask *task = user_data;
|
||||
gs_free_error GError *get_error = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
nm_http_client_poll_get_finish (NM_HTTP_CLIENT (source),
|
||||
result,
|
||||
NULL,
|
||||
NULL,
|
||||
&get_error);
|
||||
nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, NULL, &get_error);
|
||||
|
||||
if (nm_utils_error_is_cancelled (get_error)) {
|
||||
g_task_return_error (task, g_steal_pointer (&get_error));
|
||||
return;
|
||||
}
|
||||
if (nm_utils_error_is_cancelled(get_error)) {
|
||||
g_task_return_error(task, g_steal_pointer(&get_error));
|
||||
return;
|
||||
}
|
||||
|
||||
if (get_error) {
|
||||
nm_utils_error_set (&error,
|
||||
NM_UTILS_ERROR_UNKNOWN,
|
||||
"failure to get GCP metadata: %s",
|
||||
get_error->message);
|
||||
g_task_return_error (task, g_steal_pointer (&error));
|
||||
return;
|
||||
}
|
||||
if (get_error) {
|
||||
nm_utils_error_set(&error,
|
||||
NM_UTILS_ERROR_UNKNOWN,
|
||||
"failure to get GCP metadata: %s",
|
||||
get_error->message);
|
||||
g_task_return_error(task, g_steal_pointer(&error));
|
||||
return;
|
||||
}
|
||||
|
||||
g_task_return_boolean (task, TRUE);
|
||||
g_task_return_boolean(task, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
detect (NMCSProvider *provider,
|
||||
GTask *task)
|
||||
detect(NMCSProvider *provider, GTask *task)
|
||||
{
|
||||
NMHttpClient *http_client;
|
||||
gs_free char *uri = NULL;
|
||||
NMHttpClient *http_client;
|
||||
gs_free char *uri = NULL;
|
||||
|
||||
http_client = nmcs_provider_get_http_client (provider);
|
||||
http_client = nmcs_provider_get_http_client(provider);
|
||||
|
||||
nm_http_client_poll_get (http_client,
|
||||
(uri = _gcp_uri_concat ("id")),
|
||||
HTTP_TIMEOUT_MS,
|
||||
256*1024,
|
||||
7000,
|
||||
1000,
|
||||
NM_MAKE_STRV (NM_GCP_METADATA_HEADER),
|
||||
g_task_get_cancellable (task),
|
||||
NULL,
|
||||
NULL,
|
||||
_detect_get_meta_data_done_cb,
|
||||
task);
|
||||
nm_http_client_poll_get(http_client,
|
||||
(uri = _gcp_uri_concat("id")),
|
||||
HTTP_TIMEOUT_MS,
|
||||
256 * 1024,
|
||||
7000,
|
||||
1000,
|
||||
NM_MAKE_STRV(NM_GCP_METADATA_HEADER),
|
||||
g_task_get_cancellable(task),
|
||||
NULL,
|
||||
NULL,
|
||||
_detect_get_meta_data_done_cb,
|
||||
task);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
NMCSProviderGetConfigTaskData *config_data;
|
||||
guint n_ifaces_pending;
|
||||
GError *error;
|
||||
NMCSProviderGetConfigTaskData *config_data;
|
||||
guint n_ifaces_pending;
|
||||
GError * error;
|
||||
} GCPData;
|
||||
|
||||
typedef struct {
|
||||
NMCSProviderGetConfigIfaceData *iface_get_config;
|
||||
GCPData *gcp_data;
|
||||
gssize iface_idx;
|
||||
guint n_fips_pending;
|
||||
NMCSProviderGetConfigIfaceData *iface_get_config;
|
||||
GCPData * gcp_data;
|
||||
gssize iface_idx;
|
||||
guint n_fips_pending;
|
||||
} GCPIfaceData;
|
||||
|
||||
static void
|
||||
_get_config_maybe_task_return (GCPData *gcp_data,
|
||||
GError *error_take)
|
||||
_get_config_maybe_task_return(GCPData *gcp_data, GError *error_take)
|
||||
{
|
||||
NMCSProviderGetConfigTaskData *config_data = gcp_data->config_data;
|
||||
NMCSProviderGetConfigTaskData *config_data = gcp_data->config_data;
|
||||
|
||||
if (error_take) {
|
||||
if (!gcp_data->error)
|
||||
gcp_data->error = error_take;
|
||||
else if ( !nm_utils_error_is_cancelled (gcp_data->error)
|
||||
&& nm_utils_error_is_cancelled (error_take)) {
|
||||
nm_clear_error (&gcp_data->error);
|
||||
gcp_data->error = error_take;
|
||||
} else
|
||||
g_error_free (error_take);
|
||||
}
|
||||
if (error_take) {
|
||||
if (!gcp_data->error)
|
||||
gcp_data->error = error_take;
|
||||
else if (!nm_utils_error_is_cancelled(gcp_data->error)
|
||||
&& nm_utils_error_is_cancelled(error_take)) {
|
||||
nm_clear_error(&gcp_data->error);
|
||||
gcp_data->error = error_take;
|
||||
} else
|
||||
g_error_free(error_take);
|
||||
}
|
||||
|
||||
if (gcp_data->n_ifaces_pending > 0)
|
||||
return;
|
||||
if (gcp_data->n_ifaces_pending > 0)
|
||||
return;
|
||||
|
||||
if (gcp_data->error) {
|
||||
if (nm_utils_error_is_cancelled (gcp_data->error))
|
||||
_LOGD ("get-config: cancelled");
|
||||
else
|
||||
_LOGD ("get-config: failed: %s", gcp_data->error->message);
|
||||
g_task_return_error (config_data->task, g_steal_pointer (&gcp_data->error));
|
||||
} else {
|
||||
_LOGD ("get-config: success");
|
||||
g_task_return_pointer (config_data->task,
|
||||
g_hash_table_ref (config_data->result_dict),
|
||||
(GDestroyNotify) g_hash_table_unref);
|
||||
}
|
||||
if (gcp_data->error) {
|
||||
if (nm_utils_error_is_cancelled(gcp_data->error))
|
||||
_LOGD("get-config: cancelled");
|
||||
else
|
||||
_LOGD("get-config: failed: %s", gcp_data->error->message);
|
||||
g_task_return_error(config_data->task, g_steal_pointer(&gcp_data->error));
|
||||
} else {
|
||||
_LOGD("get-config: success");
|
||||
g_task_return_pointer(config_data->task,
|
||||
g_hash_table_ref(config_data->result_dict),
|
||||
(GDestroyNotify) g_hash_table_unref);
|
||||
}
|
||||
|
||||
nm_g_slice_free (gcp_data);
|
||||
g_object_unref (config_data->task);
|
||||
nm_g_slice_free(gcp_data);
|
||||
g_object_unref(config_data->task);
|
||||
}
|
||||
|
||||
static void
|
||||
_get_config_fip_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_get_config_fip_cb(GObject *source, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
NMCSProviderGetConfigIfaceData *iface_get_config;
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
GCPIfaceData *iface_data = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
const char *fip_str = NULL;
|
||||
NMIPRoute **routes_arr;
|
||||
NMIPRoute *route_new;
|
||||
GCPData *gcp_data;
|
||||
NMCSProviderGetConfigIfaceData *iface_get_config;
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
GCPIfaceData * iface_data = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
const char * fip_str = NULL;
|
||||
NMIPRoute ** routes_arr;
|
||||
NMIPRoute * route_new;
|
||||
GCPData * gcp_data;
|
||||
|
||||
gcp_data = iface_data->gcp_data;
|
||||
gcp_data = iface_data->gcp_data;
|
||||
|
||||
nm_http_client_poll_get_finish (NM_HTTP_CLIENT (source),
|
||||
result,
|
||||
NULL,
|
||||
&response,
|
||||
&error);
|
||||
nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, &response, &error);
|
||||
|
||||
if (error)
|
||||
goto iface_done;
|
||||
if (error)
|
||||
goto iface_done;
|
||||
|
||||
fip_str = g_bytes_get_data (response, NULL);
|
||||
if (!nm_utils_ipaddr_valid (AF_INET, fip_str)) {
|
||||
error = nm_utils_error_new (NM_UTILS_ERROR_UNKNOWN,
|
||||
"forwarded-ip is not a valid ip address");
|
||||
goto iface_done;
|
||||
}
|
||||
fip_str = g_bytes_get_data(response, NULL);
|
||||
if (!nm_utils_ipaddr_valid(AF_INET, fip_str)) {
|
||||
error =
|
||||
nm_utils_error_new(NM_UTILS_ERROR_UNKNOWN, "forwarded-ip is not a valid ip address");
|
||||
goto iface_done;
|
||||
}
|
||||
|
||||
_LOGI ("GCP interface[%"G_GSSIZE_FORMAT"]: adding forwarded-ip %s",
|
||||
iface_data->iface_idx,
|
||||
fip_str);
|
||||
_LOGI("GCP interface[%" G_GSSIZE_FORMAT "]: adding forwarded-ip %s",
|
||||
iface_data->iface_idx,
|
||||
fip_str);
|
||||
|
||||
iface_get_config = iface_data->iface_get_config;
|
||||
iface_get_config->iface_idx = iface_data->iface_idx;
|
||||
routes_arr = iface_get_config->iproutes_arr;
|
||||
iface_get_config = iface_data->iface_get_config;
|
||||
iface_get_config->iface_idx = iface_data->iface_idx;
|
||||
routes_arr = iface_get_config->iproutes_arr;
|
||||
|
||||
route_new = nm_ip_route_new (AF_INET,
|
||||
fip_str,
|
||||
32,
|
||||
NULL,
|
||||
100,
|
||||
&error);
|
||||
if (error)
|
||||
goto iface_done;
|
||||
route_new = nm_ip_route_new(AF_INET, fip_str, 32, NULL, 100, &error);
|
||||
if (error)
|
||||
goto iface_done;
|
||||
|
||||
nm_ip_route_set_attribute (route_new,
|
||||
NM_IP_ROUTE_ATTRIBUTE_TYPE,
|
||||
g_variant_new_string ("local"));
|
||||
routes_arr[iface_get_config->iproutes_len] = route_new;
|
||||
++iface_get_config->iproutes_len;
|
||||
nm_ip_route_set_attribute(route_new, NM_IP_ROUTE_ATTRIBUTE_TYPE, g_variant_new_string("local"));
|
||||
routes_arr[iface_get_config->iproutes_len] = route_new;
|
||||
++iface_get_config->iproutes_len;
|
||||
|
||||
iface_done:
|
||||
--iface_data->n_fips_pending;
|
||||
if (iface_data->n_fips_pending == 0) {
|
||||
nm_g_slice_free (iface_data);
|
||||
--gcp_data->n_ifaces_pending;
|
||||
}
|
||||
--iface_data->n_fips_pending;
|
||||
if (iface_data->n_fips_pending == 0) {
|
||||
nm_g_slice_free(iface_data);
|
||||
--gcp_data->n_ifaces_pending;
|
||||
}
|
||||
|
||||
_get_config_maybe_task_return (gcp_data, g_steal_pointer (&error));
|
||||
_get_config_maybe_task_return(gcp_data, g_steal_pointer(&error));
|
||||
}
|
||||
|
||||
static void
|
||||
_get_config_ips_list_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_get_config_ips_list_cb(GObject *source, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
gs_unref_ptrarray GPtrArray *uri_arr = NULL;
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
GCPIfaceData *iface_data = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
const char *response_str = NULL;
|
||||
gsize response_len;
|
||||
GCPData *gcp_data;
|
||||
const char *line;
|
||||
gsize line_len;
|
||||
guint i;
|
||||
gs_unref_ptrarray GPtrArray *uri_arr = NULL;
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
GCPIfaceData * iface_data = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
const char * response_str = NULL;
|
||||
gsize response_len;
|
||||
GCPData * gcp_data;
|
||||
const char * line;
|
||||
gsize line_len;
|
||||
guint i;
|
||||
|
||||
gcp_data = iface_data->gcp_data;
|
||||
gcp_data = iface_data->gcp_data;
|
||||
|
||||
nm_http_client_poll_get_finish (NM_HTTP_CLIENT (source),
|
||||
result,
|
||||
NULL,
|
||||
&response,
|
||||
&error);
|
||||
nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, &response, &error);
|
||||
|
||||
if (error)
|
||||
goto fips_error;
|
||||
if (error)
|
||||
goto fips_error;
|
||||
|
||||
response_str = g_bytes_get_data (response, &response_len);
|
||||
/* NMHttpClient guarantees that there is a trailing NUL after the data. */
|
||||
nm_assert (response_str[response_len] == 0);
|
||||
response_str = g_bytes_get_data(response, &response_len);
|
||||
/* NMHttpClient guarantees that there is a trailing NUL after the data. */
|
||||
nm_assert(response_str[response_len] == 0);
|
||||
|
||||
uri_arr = g_ptr_array_new_with_free_func (g_free);
|
||||
while (nm_utils_parse_next_line (&response_str,
|
||||
&response_len,
|
||||
&line,
|
||||
&line_len)) {
|
||||
gint64 fip_index;
|
||||
uri_arr = g_ptr_array_new_with_free_func(g_free);
|
||||
while (nm_utils_parse_next_line(&response_str, &response_len, &line, &line_len)) {
|
||||
gint64 fip_index;
|
||||
|
||||
/* Truncate the string. It's safe to do, because we own @response_data an it has an
|
||||
/* Truncate the string. It's safe to do, because we own @response_data an it has an
|
||||
* extra NUL character after the buffer. */
|
||||
((char *) line)[line_len] = '\0';
|
||||
((char *) line)[line_len] = '\0';
|
||||
|
||||
fip_index = _nm_utils_ascii_str_to_int64 (line, 10, 0, G_MAXINT64, -1);
|
||||
if (fip_index < 0)
|
||||
continue;
|
||||
fip_index = _nm_utils_ascii_str_to_int64(line, 10, 0, G_MAXINT64, -1);
|
||||
if (fip_index < 0)
|
||||
continue;
|
||||
|
||||
g_ptr_array_add (uri_arr,
|
||||
g_strdup_printf ("%"G_GSSIZE_FORMAT"/forwarded-ips/%"G_GINT64_FORMAT,
|
||||
iface_data->iface_idx,
|
||||
fip_index));
|
||||
}
|
||||
g_ptr_array_add(uri_arr,
|
||||
g_strdup_printf("%" G_GSSIZE_FORMAT "/forwarded-ips/%" G_GINT64_FORMAT,
|
||||
iface_data->iface_idx,
|
||||
fip_index));
|
||||
}
|
||||
|
||||
iface_data->n_fips_pending = uri_arr->len;
|
||||
iface_data->n_fips_pending = uri_arr->len;
|
||||
|
||||
_LOGI ("GCP interface[%"G_GSSIZE_FORMAT"]: found %u forwarded ips",
|
||||
iface_data->iface_idx,
|
||||
iface_data->n_fips_pending);
|
||||
_LOGI("GCP interface[%" G_GSSIZE_FORMAT "]: found %u forwarded ips",
|
||||
iface_data->iface_idx,
|
||||
iface_data->n_fips_pending);
|
||||
|
||||
if (iface_data->n_fips_pending == 0) {
|
||||
error = nm_utils_error_new (NM_UTILS_ERROR_UNKNOWN,
|
||||
"found no forwarded ip");
|
||||
goto fips_error;
|
||||
}
|
||||
if (iface_data->n_fips_pending == 0) {
|
||||
error = nm_utils_error_new(NM_UTILS_ERROR_UNKNOWN, "found no forwarded ip");
|
||||
goto fips_error;
|
||||
}
|
||||
|
||||
iface_data->iface_get_config->iproutes_arr =
|
||||
g_new (NMIPRoute *, iface_data->n_fips_pending);
|
||||
iface_data->iface_get_config->iproutes_arr = g_new(NMIPRoute *, iface_data->n_fips_pending);
|
||||
|
||||
for (i = 0; i < uri_arr->len; ++i) {
|
||||
const char *str = uri_arr->pdata[i];
|
||||
gs_free const char *uri = NULL;
|
||||
for (i = 0; i < uri_arr->len; ++i) {
|
||||
const char * str = uri_arr->pdata[i];
|
||||
gs_free const char *uri = NULL;
|
||||
|
||||
nm_http_client_poll_get (NM_HTTP_CLIENT (source),
|
||||
(uri = _gcp_uri_interfaces (str)),
|
||||
HTTP_TIMEOUT_MS,
|
||||
HTTP_REQ_MAX_DATA,
|
||||
HTTP_POLL_TIMEOUT_MS,
|
||||
HTTP_RATE_LIMIT_MS,
|
||||
NM_MAKE_STRV (NM_GCP_METADATA_HEADER),
|
||||
g_task_get_cancellable (gcp_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_fip_cb,
|
||||
iface_data);
|
||||
}
|
||||
return;
|
||||
nm_http_client_poll_get(NM_HTTP_CLIENT(source),
|
||||
(uri = _gcp_uri_interfaces(str)),
|
||||
HTTP_TIMEOUT_MS,
|
||||
HTTP_REQ_MAX_DATA,
|
||||
HTTP_POLL_TIMEOUT_MS,
|
||||
HTTP_RATE_LIMIT_MS,
|
||||
NM_MAKE_STRV(NM_GCP_METADATA_HEADER),
|
||||
g_task_get_cancellable(gcp_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_fip_cb,
|
||||
iface_data);
|
||||
}
|
||||
return;
|
||||
|
||||
fips_error:
|
||||
nm_g_slice_free (iface_data);
|
||||
--gcp_data->n_ifaces_pending;
|
||||
_get_config_maybe_task_return (gcp_data, g_steal_pointer (&error));
|
||||
nm_g_slice_free(iface_data);
|
||||
--gcp_data->n_ifaces_pending;
|
||||
_get_config_maybe_task_return(gcp_data, g_steal_pointer(&error));
|
||||
}
|
||||
|
||||
static void
|
||||
_get_config_iface_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_get_config_iface_cb(GObject *source, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
GCPIfaceData *iface_data = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_free const char *hwaddr = NULL;
|
||||
gs_free const char *uri = NULL;
|
||||
char sbuf[100];
|
||||
GCPData *gcp_data;
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
GCPIfaceData * iface_data = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_free const char * hwaddr = NULL;
|
||||
gs_free const char * uri = NULL;
|
||||
char sbuf[100];
|
||||
GCPData * gcp_data;
|
||||
|
||||
gcp_data = iface_data->gcp_data;
|
||||
gcp_data = iface_data->gcp_data;
|
||||
|
||||
nm_http_client_poll_get_finish (NM_HTTP_CLIENT (source),
|
||||
result,
|
||||
NULL,
|
||||
&response,
|
||||
&error);
|
||||
nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, &response, &error);
|
||||
|
||||
if (error)
|
||||
goto iface_error;
|
||||
if (error)
|
||||
goto iface_error;
|
||||
|
||||
hwaddr = nmcs_utils_hwaddr_normalize (g_bytes_get_data (response, NULL), -1);
|
||||
iface_data->iface_get_config = g_hash_table_lookup (gcp_data->config_data->result_dict,
|
||||
hwaddr);
|
||||
if (!iface_data->iface_get_config) {
|
||||
_LOGI ("GCP interface[%"G_GSSIZE_FORMAT"]: did not find a matching device",
|
||||
iface_data->iface_idx);
|
||||
error = nm_utils_error_new (NM_UTILS_ERROR_UNKNOWN,
|
||||
"no matching hwaddr found for GCP interface");
|
||||
goto iface_error;
|
||||
}
|
||||
hwaddr = nmcs_utils_hwaddr_normalize(g_bytes_get_data(response, NULL), -1);
|
||||
iface_data->iface_get_config = g_hash_table_lookup(gcp_data->config_data->result_dict, hwaddr);
|
||||
if (!iface_data->iface_get_config) {
|
||||
_LOGI("GCP interface[%" G_GSSIZE_FORMAT "]: did not find a matching device",
|
||||
iface_data->iface_idx);
|
||||
error = nm_utils_error_new(NM_UTILS_ERROR_UNKNOWN,
|
||||
"no matching hwaddr found for GCP interface");
|
||||
goto iface_error;
|
||||
}
|
||||
|
||||
_LOGI ("GCP interface[%"G_GSSIZE_FORMAT"]: found a matching device with hwaddr %s",
|
||||
iface_data->iface_idx,
|
||||
hwaddr);
|
||||
_LOGI("GCP interface[%" G_GSSIZE_FORMAT "]: found a matching device with hwaddr %s",
|
||||
iface_data->iface_idx,
|
||||
hwaddr);
|
||||
|
||||
nm_sprintf_buf (sbuf, "%"G_GSSIZE_FORMAT"/forwarded-ips/", iface_data->iface_idx);
|
||||
nm_sprintf_buf(sbuf, "%" G_GSSIZE_FORMAT "/forwarded-ips/", iface_data->iface_idx);
|
||||
|
||||
nm_http_client_poll_get (NM_HTTP_CLIENT (source),
|
||||
(uri = _gcp_uri_interfaces (sbuf)),
|
||||
HTTP_TIMEOUT_MS,
|
||||
HTTP_REQ_MAX_DATA,
|
||||
HTTP_POLL_TIMEOUT_MS,
|
||||
HTTP_RATE_LIMIT_MS,
|
||||
NM_MAKE_STRV (NM_GCP_METADATA_HEADER),
|
||||
g_task_get_cancellable (gcp_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_ips_list_cb,
|
||||
iface_data);
|
||||
return;
|
||||
nm_http_client_poll_get(NM_HTTP_CLIENT(source),
|
||||
(uri = _gcp_uri_interfaces(sbuf)),
|
||||
HTTP_TIMEOUT_MS,
|
||||
HTTP_REQ_MAX_DATA,
|
||||
HTTP_POLL_TIMEOUT_MS,
|
||||
HTTP_RATE_LIMIT_MS,
|
||||
NM_MAKE_STRV(NM_GCP_METADATA_HEADER),
|
||||
g_task_get_cancellable(gcp_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_ips_list_cb,
|
||||
iface_data);
|
||||
return;
|
||||
|
||||
iface_error:
|
||||
nm_g_slice_free (iface_data);
|
||||
--gcp_data->n_ifaces_pending;
|
||||
_get_config_maybe_task_return (gcp_data, g_steal_pointer (&error));
|
||||
nm_g_slice_free(iface_data);
|
||||
--gcp_data->n_ifaces_pending;
|
||||
_get_config_maybe_task_return(gcp_data, g_steal_pointer(&error));
|
||||
}
|
||||
|
||||
static void
|
||||
_get_net_ifaces_list_cb (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
_get_net_ifaces_list_cb(GObject *source, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
gs_unref_ptrarray GPtrArray *ifaces_arr = NULL;
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
GCPData *gcp_data = user_data;
|
||||
const char *response_str;
|
||||
gsize response_len;
|
||||
const char *line;
|
||||
gsize line_len;
|
||||
guint i;
|
||||
gs_unref_ptrarray GPtrArray *ifaces_arr = NULL;
|
||||
gs_unref_bytes GBytes *response = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
GCPData * gcp_data = user_data;
|
||||
const char * response_str;
|
||||
gsize response_len;
|
||||
const char * line;
|
||||
gsize line_len;
|
||||
guint i;
|
||||
|
||||
nm_http_client_poll_get_finish (NM_HTTP_CLIENT (source),
|
||||
result,
|
||||
NULL,
|
||||
&response,
|
||||
&error);
|
||||
nm_http_client_poll_get_finish(NM_HTTP_CLIENT(source), result, NULL, &response, &error);
|
||||
|
||||
if (error) {
|
||||
_get_config_maybe_task_return (gcp_data, g_steal_pointer (&error));
|
||||
return;
|
||||
}
|
||||
if (error) {
|
||||
_get_config_maybe_task_return(gcp_data, g_steal_pointer(&error));
|
||||
return;
|
||||
}
|
||||
|
||||
response_str = g_bytes_get_data (response, &response_len);
|
||||
/* NMHttpClient guarantees that there is a trailing NUL after the data. */
|
||||
nm_assert (response_str[response_len] == 0);
|
||||
response_str = g_bytes_get_data(response, &response_len);
|
||||
/* NMHttpClient guarantees that there is a trailing NUL after the data. */
|
||||
nm_assert(response_str[response_len] == 0);
|
||||
|
||||
ifaces_arr = g_ptr_array_new ();
|
||||
ifaces_arr = g_ptr_array_new();
|
||||
|
||||
while (nm_utils_parse_next_line (&response_str,
|
||||
&response_len,
|
||||
&line,
|
||||
&line_len)) {
|
||||
GCPIfaceData *iface_data;
|
||||
gssize iface_idx;
|
||||
while (nm_utils_parse_next_line(&response_str, &response_len, &line, &line_len)) {
|
||||
GCPIfaceData *iface_data;
|
||||
gssize iface_idx;
|
||||
|
||||
if (line_len == 0)
|
||||
continue;
|
||||
if (line_len == 0)
|
||||
continue;
|
||||
|
||||
/* Truncate the string. It's safe to do, because we own @response_data an it has an
|
||||
/* Truncate the string. It's safe to do, because we own @response_data an it has an
|
||||
* extra NUL character after the buffer. */
|
||||
((char *) line)[line_len] = '\0';
|
||||
if (line[line_len - 1] == '/')
|
||||
((char *) line)[--line_len] = '\0';
|
||||
((char *) line)[line_len] = '\0';
|
||||
if (line[line_len - 1] == '/')
|
||||
((char *) line)[--line_len] = '\0';
|
||||
|
||||
iface_idx = _nm_utils_ascii_str_to_int64 (line, 10, 0, G_MAXSSIZE, -1);
|
||||
if (iface_idx < 0)
|
||||
continue;
|
||||
iface_idx = _nm_utils_ascii_str_to_int64(line, 10, 0, G_MAXSSIZE, -1);
|
||||
if (iface_idx < 0)
|
||||
continue;
|
||||
|
||||
iface_data = g_slice_new (GCPIfaceData);
|
||||
*iface_data = (GCPIfaceData) {
|
||||
.iface_get_config = NULL,
|
||||
.gcp_data = gcp_data,
|
||||
.iface_idx = iface_idx,
|
||||
.n_fips_pending = 0,
|
||||
};
|
||||
g_ptr_array_add (ifaces_arr, iface_data);
|
||||
}
|
||||
iface_data = g_slice_new(GCPIfaceData);
|
||||
*iface_data = (GCPIfaceData){
|
||||
.iface_get_config = NULL,
|
||||
.gcp_data = gcp_data,
|
||||
.iface_idx = iface_idx,
|
||||
.n_fips_pending = 0,
|
||||
};
|
||||
g_ptr_array_add(ifaces_arr, iface_data);
|
||||
}
|
||||
|
||||
gcp_data->n_ifaces_pending = ifaces_arr->len;
|
||||
_LOGI ("found GCP interfaces: %u", ifaces_arr->len);
|
||||
gcp_data->n_ifaces_pending = ifaces_arr->len;
|
||||
_LOGI("found GCP interfaces: %u", ifaces_arr->len);
|
||||
|
||||
for (i = 0; i < ifaces_arr->len; ++i) {
|
||||
GCPIfaceData *data = ifaces_arr->pdata[i];
|
||||
gs_free const char *uri = NULL;
|
||||
char sbuf[100];
|
||||
for (i = 0; i < ifaces_arr->len; ++i) {
|
||||
GCPIfaceData * data = ifaces_arr->pdata[i];
|
||||
gs_free const char *uri = NULL;
|
||||
char sbuf[100];
|
||||
|
||||
_LOGD ("GCP interface[%"G_GSSIZE_FORMAT"]: retrieving configuration",
|
||||
data->iface_idx);
|
||||
_LOGD("GCP interface[%" G_GSSIZE_FORMAT "]: retrieving configuration", data->iface_idx);
|
||||
|
||||
nm_sprintf_buf (sbuf, "%"G_GSSIZE_FORMAT"/mac", data->iface_idx);
|
||||
nm_sprintf_buf(sbuf, "%" G_GSSIZE_FORMAT "/mac", data->iface_idx);
|
||||
|
||||
nm_http_client_poll_get (NM_HTTP_CLIENT (source),
|
||||
(uri = _gcp_uri_interfaces (sbuf)),
|
||||
HTTP_TIMEOUT_MS,
|
||||
HTTP_REQ_MAX_DATA,
|
||||
HTTP_POLL_TIMEOUT_MS,
|
||||
HTTP_RATE_LIMIT_MS,
|
||||
NM_MAKE_STRV (NM_GCP_METADATA_HEADER),
|
||||
g_task_get_cancellable (gcp_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_iface_cb,
|
||||
data);
|
||||
}
|
||||
nm_http_client_poll_get(NM_HTTP_CLIENT(source),
|
||||
(uri = _gcp_uri_interfaces(sbuf)),
|
||||
HTTP_TIMEOUT_MS,
|
||||
HTTP_REQ_MAX_DATA,
|
||||
HTTP_POLL_TIMEOUT_MS,
|
||||
HTTP_RATE_LIMIT_MS,
|
||||
NM_MAKE_STRV(NM_GCP_METADATA_HEADER),
|
||||
g_task_get_cancellable(gcp_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_config_iface_cb,
|
||||
data);
|
||||
}
|
||||
|
||||
if (ifaces_arr->len == 0) {
|
||||
error = nm_utils_error_new (NM_UTILS_ERROR_UNKNOWN,
|
||||
"no GCP interfaces found");
|
||||
_get_config_maybe_task_return (gcp_data, g_steal_pointer (&error));
|
||||
}
|
||||
if (ifaces_arr->len == 0) {
|
||||
error = nm_utils_error_new(NM_UTILS_ERROR_UNKNOWN, "no GCP interfaces found");
|
||||
_get_config_maybe_task_return(gcp_data, g_steal_pointer(&error));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
get_config (NMCSProvider *provider,
|
||||
NMCSProviderGetConfigTaskData *get_config_data)
|
||||
get_config(NMCSProvider *provider, NMCSProviderGetConfigTaskData *get_config_data)
|
||||
{
|
||||
gs_free const char *uri = NULL;
|
||||
GCPData *gcp_data;
|
||||
gs_free const char *uri = NULL;
|
||||
GCPData * gcp_data;
|
||||
|
||||
gcp_data = g_slice_new (GCPData);
|
||||
*gcp_data = (GCPData) {
|
||||
.config_data = get_config_data,
|
||||
.n_ifaces_pending = 0,
|
||||
.error = NULL,
|
||||
};
|
||||
gcp_data = g_slice_new(GCPData);
|
||||
*gcp_data = (GCPData){
|
||||
.config_data = get_config_data,
|
||||
.n_ifaces_pending = 0,
|
||||
.error = NULL,
|
||||
};
|
||||
|
||||
nm_http_client_poll_get (nmcs_provider_get_http_client (provider),
|
||||
(uri = _gcp_uri_interfaces ()),
|
||||
HTTP_TIMEOUT_MS,
|
||||
HTTP_REQ_MAX_DATA,
|
||||
HTTP_POLL_TIMEOUT_MS,
|
||||
HTTP_RATE_LIMIT_MS,
|
||||
NM_MAKE_STRV (NM_GCP_METADATA_HEADER),
|
||||
g_task_get_cancellable (gcp_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_net_ifaces_list_cb,
|
||||
gcp_data);
|
||||
nm_http_client_poll_get(nmcs_provider_get_http_client(provider),
|
||||
(uri = _gcp_uri_interfaces()),
|
||||
HTTP_TIMEOUT_MS,
|
||||
HTTP_REQ_MAX_DATA,
|
||||
HTTP_POLL_TIMEOUT_MS,
|
||||
HTTP_RATE_LIMIT_MS,
|
||||
NM_MAKE_STRV(NM_GCP_METADATA_HEADER),
|
||||
g_task_get_cancellable(gcp_data->config_data->task),
|
||||
NULL,
|
||||
NULL,
|
||||
_get_net_ifaces_list_cb,
|
||||
gcp_data);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
nmcs_provider_gcp_init (NMCSProviderGCP *self)
|
||||
{
|
||||
}
|
||||
nmcs_provider_gcp_init(NMCSProviderGCP *self)
|
||||
{}
|
||||
|
||||
static void
|
||||
nmcs_provider_gcp_class_init (NMCSProviderGCPClass *klass)
|
||||
nmcs_provider_gcp_class_init(NMCSProviderGCPClass *klass)
|
||||
{
|
||||
NMCSProviderClass *provider_class = NMCS_PROVIDER_CLASS (klass);
|
||||
NMCSProviderClass *provider_class = NMCS_PROVIDER_CLASS(klass);
|
||||
|
||||
provider_class->_name = "GCP";
|
||||
provider_class->_env_provider_enabled = NMCS_ENV_VARIABLE ("NM_CLOUD_SETUP_GCP");
|
||||
provider_class->detect = detect;
|
||||
provider_class->get_config = get_config;
|
||||
provider_class->_name = "GCP";
|
||||
provider_class->_env_provider_enabled = NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_GCP");
|
||||
provider_class->detect = detect;
|
||||
provider_class->get_config = get_config;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,14 +10,17 @@
|
|||
typedef struct _NMCSProviderGCP NMCSProviderGCP;
|
||||
typedef struct _NMCSProviderGCPClass NMCSProviderGCPClass;
|
||||
|
||||
#define NMCS_TYPE_PROVIDER_GCP (nmcs_provider_gcp_get_type ())
|
||||
#define NMCS_PROVIDER_GCP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMCS_TYPE_PROVIDER_GCP, NMCSProviderGCP))
|
||||
#define NMCS_PROVIDER_GCP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMCS_TYPE_PROVIDER_GCP, NMCSProviderGCPClass))
|
||||
#define NMCS_IS_PROVIDER_GCP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMCS_TYPE_PROVIDER_GCP))
|
||||
#define NMCS_IS_PROVIDER_GCP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMCS_TYPE_PROVIDER_GCP))
|
||||
#define NMCS_PROVIDER_GCP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMCS_TYPE_PROVIDER_GCP, NMCSProviderGCPClass))
|
||||
#define NMCS_TYPE_PROVIDER_GCP (nmcs_provider_gcp_get_type())
|
||||
#define NMCS_PROVIDER_GCP(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMCS_TYPE_PROVIDER_GCP, NMCSProviderGCP))
|
||||
#define NMCS_PROVIDER_GCP_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMCS_TYPE_PROVIDER_GCP, NMCSProviderGCPClass))
|
||||
#define NMCS_IS_PROVIDER_GCP(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMCS_TYPE_PROVIDER_GCP))
|
||||
#define NMCS_IS_PROVIDER_GCP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMCS_TYPE_PROVIDER_GCP))
|
||||
#define NMCS_PROVIDER_GCP_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMCS_TYPE_PROVIDER_GCP, NMCSProviderGCPClass))
|
||||
|
||||
GType nmcs_provider_gcp_get_type (void);
|
||||
GType nmcs_provider_gcp_get_type(void);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -8,239 +8,225 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
|
||||
PROP_HTTP_CLIENT,
|
||||
);
|
||||
NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_HTTP_CLIENT, );
|
||||
|
||||
typedef struct _NMCSProviderPrivate {
|
||||
NMHttpClient *http_client;
|
||||
NMHttpClient *http_client;
|
||||
} NMCSProviderPrivate;
|
||||
|
||||
G_DEFINE_TYPE (NMCSProvider, nmcs_provider, G_TYPE_OBJECT);
|
||||
G_DEFINE_TYPE(NMCSProvider, nmcs_provider, G_TYPE_OBJECT);
|
||||
|
||||
#define NMCS_PROVIDER_GET_PRIVATE(self) _NM_GET_PRIVATE_PTR(self, NMCSProvider, NMCS_IS_PROVIDER)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
const char *
|
||||
nmcs_provider_get_name (NMCSProvider *self)
|
||||
nmcs_provider_get_name(NMCSProvider *self)
|
||||
{
|
||||
NMCSProviderClass *klass;
|
||||
NMCSProviderClass *klass;
|
||||
|
||||
g_return_val_if_fail (NMCS_IS_PROVIDER (self), NULL);
|
||||
g_return_val_if_fail(NMCS_IS_PROVIDER(self), NULL);
|
||||
|
||||
klass = NMCS_PROVIDER_GET_CLASS (self);
|
||||
nm_assert (klass->_name);
|
||||
return klass->_name;
|
||||
klass = NMCS_PROVIDER_GET_CLASS(self);
|
||||
nm_assert(klass->_name);
|
||||
return klass->_name;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMHttpClient *
|
||||
nmcs_provider_get_http_client (NMCSProvider *self)
|
||||
nmcs_provider_get_http_client(NMCSProvider *self)
|
||||
{
|
||||
g_return_val_if_fail (NMCS_IS_PROVIDER (self), NULL);
|
||||
g_return_val_if_fail(NMCS_IS_PROVIDER(self), NULL);
|
||||
|
||||
return NMCS_PROVIDER_GET_PRIVATE (self)->http_client;
|
||||
return NMCS_PROVIDER_GET_PRIVATE(self)->http_client;
|
||||
}
|
||||
|
||||
GMainContext *
|
||||
nmcs_provider_get_main_context (NMCSProvider *self)
|
||||
nmcs_provider_get_main_context(NMCSProvider *self)
|
||||
{
|
||||
g_return_val_if_fail (NMCS_IS_PROVIDER (self), NULL);
|
||||
g_return_val_if_fail(NMCS_IS_PROVIDER(self), NULL);
|
||||
|
||||
return nm_http_client_get_main_context (NMCS_PROVIDER_GET_PRIVATE (self)->http_client);
|
||||
return nm_http_client_get_main_context(NMCS_PROVIDER_GET_PRIVATE(self)->http_client);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
nmcs_provider_detect (NMCSProvider *self,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
nmcs_provider_detect(NMCSProvider * self,
|
||||
GCancellable * cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
gs_unref_object GTask *task = NULL;
|
||||
const char *env;
|
||||
gs_unref_object GTask *task = NULL;
|
||||
const char * env;
|
||||
|
||||
g_return_if_fail (NMCS_IS_PROVIDER (self));
|
||||
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
|
||||
g_return_if_fail(NMCS_IS_PROVIDER(self));
|
||||
g_return_if_fail(!cancellable || G_IS_CANCELLABLE(cancellable));
|
||||
|
||||
task = nm_g_task_new (self, cancellable, nmcs_provider_detect, callback, user_data);
|
||||
task = nm_g_task_new(self, cancellable, nmcs_provider_detect, callback, user_data);
|
||||
|
||||
nmcs_wait_for_objects_register (task);
|
||||
nmcs_wait_for_objects_register(task);
|
||||
|
||||
env = g_getenv (NMCS_PROVIDER_GET_CLASS (self)->_env_provider_enabled);
|
||||
if (!_nm_utils_ascii_str_to_bool (env, FALSE)) {
|
||||
g_task_return_error (task,
|
||||
nm_utils_error_new (NM_UTILS_ERROR_UNKNOWN,
|
||||
"provider is disabled"));
|
||||
return;
|
||||
}
|
||||
env = g_getenv(NMCS_PROVIDER_GET_CLASS(self)->_env_provider_enabled);
|
||||
if (!_nm_utils_ascii_str_to_bool(env, FALSE)) {
|
||||
g_task_return_error(task,
|
||||
nm_utils_error_new(NM_UTILS_ERROR_UNKNOWN, "provider is disabled"));
|
||||
return;
|
||||
}
|
||||
|
||||
NMCS_PROVIDER_GET_CLASS (self)->detect (self,
|
||||
g_steal_pointer (&task));
|
||||
NMCS_PROVIDER_GET_CLASS(self)->detect(self, g_steal_pointer(&task));
|
||||
}
|
||||
|
||||
gboolean
|
||||
nmcs_provider_detect_finish (NMCSProvider *self,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
nmcs_provider_detect_finish(NMCSProvider *self, GAsyncResult *result, GError **error)
|
||||
{
|
||||
g_return_val_if_fail (NMCS_IS_PROVIDER (self), FALSE);
|
||||
g_return_val_if_fail (nm_g_task_is_valid (result, self, nmcs_provider_detect), FALSE);
|
||||
g_return_val_if_fail(NMCS_IS_PROVIDER(self), FALSE);
|
||||
g_return_val_if_fail(nm_g_task_is_valid(result, self, nmcs_provider_detect), FALSE);
|
||||
|
||||
return g_task_propagate_boolean (G_TASK (result), error);
|
||||
return g_task_propagate_boolean(G_TASK(result), error);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMCSProviderGetConfigIfaceData *
|
||||
nmcs_provider_get_config_iface_data_new (gboolean was_requested)
|
||||
nmcs_provider_get_config_iface_data_new(gboolean was_requested)
|
||||
{
|
||||
NMCSProviderGetConfigIfaceData *iface_data;
|
||||
NMCSProviderGetConfigIfaceData *iface_data;
|
||||
|
||||
iface_data = g_slice_new (NMCSProviderGetConfigIfaceData);
|
||||
*iface_data = (NMCSProviderGetConfigIfaceData) {
|
||||
.iface_idx = -1,
|
||||
.was_requested = was_requested,
|
||||
};
|
||||
return iface_data;
|
||||
iface_data = g_slice_new(NMCSProviderGetConfigIfaceData);
|
||||
*iface_data = (NMCSProviderGetConfigIfaceData){
|
||||
.iface_idx = -1,
|
||||
.was_requested = was_requested,
|
||||
};
|
||||
return iface_data;
|
||||
}
|
||||
|
||||
static void
|
||||
_iface_data_free (gpointer data)
|
||||
_iface_data_free(gpointer data)
|
||||
{
|
||||
NMCSProviderGetConfigIfaceData *iface_data = data;
|
||||
NMCSProviderGetConfigIfaceData *iface_data = data;
|
||||
|
||||
g_free (iface_data->ipv4s_arr);
|
||||
g_free (iface_data->iproutes_arr);
|
||||
g_free(iface_data->ipv4s_arr);
|
||||
g_free(iface_data->iproutes_arr);
|
||||
|
||||
nm_g_slice_free (iface_data);
|
||||
nm_g_slice_free(iface_data);
|
||||
}
|
||||
|
||||
static void
|
||||
_get_config_data_free (gpointer data)
|
||||
_get_config_data_free(gpointer data)
|
||||
{
|
||||
NMCSProviderGetConfigTaskData *get_config_data = data;
|
||||
NMCSProviderGetConfigTaskData *get_config_data = data;
|
||||
|
||||
if (get_config_data->extra_destroy)
|
||||
get_config_data->extra_destroy (get_config_data->extra_data);
|
||||
if (get_config_data->extra_destroy)
|
||||
get_config_data->extra_destroy(get_config_data->extra_data);
|
||||
|
||||
nm_clear_pointer (&get_config_data->result_dict, g_hash_table_unref);
|
||||
nm_clear_pointer(&get_config_data->result_dict, g_hash_table_unref);
|
||||
|
||||
nm_g_slice_free (get_config_data);
|
||||
nm_g_slice_free(get_config_data);
|
||||
}
|
||||
|
||||
void
|
||||
nmcs_provider_get_config (NMCSProvider *self,
|
||||
gboolean any,
|
||||
const char *const*hwaddrs,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
nmcs_provider_get_config(NMCSProvider * self,
|
||||
gboolean any,
|
||||
const char *const * hwaddrs,
|
||||
GCancellable * cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
NMCSProviderGetConfigTaskData *get_config_data;
|
||||
NMCSProviderGetConfigTaskData *get_config_data;
|
||||
|
||||
g_return_if_fail (NMCS_IS_PROVIDER (self));
|
||||
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
|
||||
g_return_if_fail(NMCS_IS_PROVIDER(self));
|
||||
g_return_if_fail(!cancellable || G_IS_CANCELLABLE(cancellable));
|
||||
|
||||
get_config_data = g_slice_new (NMCSProviderGetConfigTaskData);
|
||||
*get_config_data = (NMCSProviderGetConfigTaskData) {
|
||||
.task = nm_g_task_new (self, cancellable, nmcs_provider_get_config, callback, user_data),
|
||||
.any = any,
|
||||
.result_dict = g_hash_table_new_full (nm_str_hash,
|
||||
g_str_equal,
|
||||
g_free,
|
||||
_iface_data_free),
|
||||
};
|
||||
get_config_data = g_slice_new(NMCSProviderGetConfigTaskData);
|
||||
*get_config_data = (NMCSProviderGetConfigTaskData){
|
||||
.task = nm_g_task_new(self, cancellable, nmcs_provider_get_config, callback, user_data),
|
||||
.any = any,
|
||||
.result_dict = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, _iface_data_free),
|
||||
};
|
||||
|
||||
g_task_set_task_data (get_config_data->task, get_config_data, _get_config_data_free);
|
||||
g_task_set_task_data(get_config_data->task, get_config_data, _get_config_data_free);
|
||||
|
||||
nmcs_wait_for_objects_register (get_config_data->task);
|
||||
nmcs_wait_for_objects_register(get_config_data->task);
|
||||
|
||||
for (; hwaddrs && hwaddrs[0]; hwaddrs++) {
|
||||
g_hash_table_insert (get_config_data->result_dict,
|
||||
g_strdup (hwaddrs[0]),
|
||||
nmcs_provider_get_config_iface_data_new (TRUE));
|
||||
}
|
||||
for (; hwaddrs && hwaddrs[0]; hwaddrs++) {
|
||||
g_hash_table_insert(get_config_data->result_dict,
|
||||
g_strdup(hwaddrs[0]),
|
||||
nmcs_provider_get_config_iface_data_new(TRUE));
|
||||
}
|
||||
|
||||
_LOGD ("get-config: starting");
|
||||
_LOGD("get-config: starting");
|
||||
|
||||
NMCS_PROVIDER_GET_CLASS (self)->get_config (self, get_config_data);
|
||||
NMCS_PROVIDER_GET_CLASS(self)->get_config(self, get_config_data);
|
||||
}
|
||||
|
||||
GHashTable *
|
||||
nmcs_provider_get_config_finish (NMCSProvider *self,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
nmcs_provider_get_config_finish(NMCSProvider *self, GAsyncResult *result, GError **error)
|
||||
{
|
||||
g_return_val_if_fail (NMCS_IS_PROVIDER (self), FALSE);
|
||||
g_return_val_if_fail (nm_g_task_is_valid (result, self, nmcs_provider_get_config), FALSE);
|
||||
g_return_val_if_fail(NMCS_IS_PROVIDER(self), FALSE);
|
||||
g_return_val_if_fail(nm_g_task_is_valid(result, self, nmcs_provider_get_config), FALSE);
|
||||
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
return g_task_propagate_pointer(G_TASK(result), error);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMCSProviderPrivate *priv = NMCS_PROVIDER_GET_PRIVATE (object);
|
||||
NMCSProviderPrivate *priv = NMCS_PROVIDER_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_HTTP_CLIENT:
|
||||
priv->http_client = g_value_dup_object (value);
|
||||
g_return_if_fail (NM_IS_HTTP_CLIENT (priv->http_client));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_HTTP_CLIENT:
|
||||
priv->http_client = g_value_dup_object(value);
|
||||
g_return_if_fail(NM_IS_HTTP_CLIENT(priv->http_client));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
nmcs_provider_init (NMCSProvider *self)
|
||||
nmcs_provider_init(NMCSProvider *self)
|
||||
{
|
||||
NMCSProviderPrivate *priv;
|
||||
NMCSProviderPrivate *priv;
|
||||
|
||||
priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NMCS_TYPE_PROVIDER, NMCSProviderPrivate);
|
||||
priv = G_TYPE_INSTANCE_GET_PRIVATE(self, NMCS_TYPE_PROVIDER, NMCSProviderPrivate);
|
||||
|
||||
self->_priv = priv;
|
||||
self->_priv = priv;
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
dispose(GObject *object)
|
||||
{
|
||||
NMCSProvider *self = NMCS_PROVIDER (object);
|
||||
NMCSProviderPrivate *priv = NMCS_PROVIDER_GET_PRIVATE (self);
|
||||
NMCSProvider * self = NMCS_PROVIDER(object);
|
||||
NMCSProviderPrivate *priv = NMCS_PROVIDER_GET_PRIVATE(self);
|
||||
|
||||
g_clear_object (&priv->http_client);
|
||||
g_clear_object(&priv->http_client);
|
||||
|
||||
G_OBJECT_CLASS (nmcs_provider_parent_class)->dispose (object);
|
||||
G_OBJECT_CLASS(nmcs_provider_parent_class)->dispose(object);
|
||||
}
|
||||
|
||||
static void
|
||||
nmcs_provider_class_init (NMCSProviderClass *klass)
|
||||
nmcs_provider_class_init(NMCSProviderClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS(klass);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (NMCSProviderPrivate));
|
||||
g_type_class_add_private(object_class, sizeof(NMCSProviderPrivate));
|
||||
|
||||
object_class->set_property = set_property;
|
||||
object_class->dispose = dispose;
|
||||
object_class->set_property = set_property;
|
||||
object_class->dispose = dispose;
|
||||
|
||||
obj_properties[PROP_HTTP_CLIENT] =
|
||||
g_param_spec_object (NMCS_PROVIDER_HTTP_CLIENT, "", "",
|
||||
NM_TYPE_HTTP_CLIENT,
|
||||
G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
obj_properties[PROP_HTTP_CLIENT] =
|
||||
g_param_spec_object(NMCS_PROVIDER_HTTP_CLIENT,
|
||||
"",
|
||||
"",
|
||||
NM_TYPE_HTTP_CLIENT,
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
||||
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,103 +10,97 @@
|
|||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
in_addr_t *ipv4s_arr;
|
||||
gsize ipv4s_len;
|
||||
gssize iface_idx;
|
||||
in_addr_t cidr_addr;
|
||||
guint8 cidr_prefix;
|
||||
bool has_ipv4s:1;
|
||||
bool has_cidr:1;
|
||||
in_addr_t *ipv4s_arr;
|
||||
gsize ipv4s_len;
|
||||
gssize iface_idx;
|
||||
in_addr_t cidr_addr;
|
||||
guint8 cidr_prefix;
|
||||
bool has_ipv4s : 1;
|
||||
bool has_cidr : 1;
|
||||
|
||||
NMIPRoute **iproutes_arr;
|
||||
gsize iproutes_len;
|
||||
NMIPRoute **iproutes_arr;
|
||||
gsize iproutes_len;
|
||||
|
||||
/* TRUE, if the configuration was requested via hwaddrs argument to
|
||||
/* TRUE, if the configuration was requested via hwaddrs argument to
|
||||
* nmcs_provider_get_config(). */
|
||||
bool was_requested:1;
|
||||
bool was_requested : 1;
|
||||
|
||||
} NMCSProviderGetConfigIfaceData;
|
||||
|
||||
static inline gboolean
|
||||
nmcs_provider_get_config_iface_data_is_valid (const NMCSProviderGetConfigIfaceData *config_data)
|
||||
nmcs_provider_get_config_iface_data_is_valid(const NMCSProviderGetConfigIfaceData *config_data)
|
||||
{
|
||||
return config_data
|
||||
&& config_data->iface_idx >= 0
|
||||
&& ( ( config_data->has_ipv4s
|
||||
&& config_data->has_cidr)
|
||||
|| config_data->iproutes_len);
|
||||
return config_data && config_data->iface_idx >= 0
|
||||
&& ((config_data->has_ipv4s && config_data->has_cidr) || config_data->iproutes_len);
|
||||
}
|
||||
|
||||
NMCSProviderGetConfigIfaceData *nmcs_provider_get_config_iface_data_new (gboolean was_requested);
|
||||
NMCSProviderGetConfigIfaceData *nmcs_provider_get_config_iface_data_new(gboolean was_requested);
|
||||
|
||||
typedef struct {
|
||||
GTask *task;
|
||||
GHashTable *result_dict;
|
||||
gpointer extra_data;
|
||||
GDestroyNotify extra_destroy;
|
||||
bool any:1;
|
||||
GTask * task;
|
||||
GHashTable * result_dict;
|
||||
gpointer extra_data;
|
||||
GDestroyNotify extra_destroy;
|
||||
bool any : 1;
|
||||
} NMCSProviderGetConfigTaskData;
|
||||
|
||||
#define NMCS_TYPE_PROVIDER (nmcs_provider_get_type ())
|
||||
#define NMCS_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMCS_TYPE_PROVIDER, NMCSProvider))
|
||||
#define NMCS_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMCS_TYPE_PROVIDER, NMCSProviderClass))
|
||||
#define NMCS_IS_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMCS_TYPE_PROVIDER))
|
||||
#define NMCS_IS_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMCS_TYPE_PROVIDER))
|
||||
#define NMCS_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMCS_TYPE_PROVIDER, NMCSProviderClass))
|
||||
#define NMCS_TYPE_PROVIDER (nmcs_provider_get_type())
|
||||
#define NMCS_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NMCS_TYPE_PROVIDER, NMCSProvider))
|
||||
#define NMCS_PROVIDER_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMCS_TYPE_PROVIDER, NMCSProviderClass))
|
||||
#define NMCS_IS_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMCS_TYPE_PROVIDER))
|
||||
#define NMCS_IS_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMCS_TYPE_PROVIDER))
|
||||
#define NMCS_PROVIDER_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMCS_TYPE_PROVIDER, NMCSProviderClass))
|
||||
|
||||
#define NMCS_PROVIDER_HTTP_CLIENT "http-client"
|
||||
|
||||
struct _NMCSProviderPrivate;
|
||||
|
||||
typedef struct {
|
||||
GObject parent;
|
||||
struct _NMCSProviderPrivate *_priv;
|
||||
GObject parent;
|
||||
struct _NMCSProviderPrivate *_priv;
|
||||
} NMCSProvider;
|
||||
|
||||
typedef struct {
|
||||
GObjectClass parent;
|
||||
const char *_name;
|
||||
const char *_env_provider_enabled;
|
||||
GObjectClass parent;
|
||||
const char * _name;
|
||||
const char * _env_provider_enabled;
|
||||
|
||||
void (*detect) (NMCSProvider *self,
|
||||
GTask *task);
|
||||
void (*detect)(NMCSProvider *self, GTask *task);
|
||||
|
||||
void (*get_config) (NMCSProvider *self,
|
||||
NMCSProviderGetConfigTaskData *get_config_data);
|
||||
void (*get_config)(NMCSProvider *self, NMCSProviderGetConfigTaskData *get_config_data);
|
||||
|
||||
} NMCSProviderClass;
|
||||
|
||||
GType nmcs_provider_get_type (void);
|
||||
GType nmcs_provider_get_type(void);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
const char *nmcs_provider_get_name (NMCSProvider *provider);
|
||||
const char *nmcs_provider_get_name(NMCSProvider *provider);
|
||||
|
||||
NMHttpClient *nmcs_provider_get_http_client (NMCSProvider *provider);
|
||||
GMainContext *nmcs_provider_get_main_context (NMCSProvider *provider);
|
||||
NMHttpClient *nmcs_provider_get_http_client(NMCSProvider *provider);
|
||||
GMainContext *nmcs_provider_get_main_context(NMCSProvider *provider);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void nmcs_provider_detect (NMCSProvider *provider,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
void nmcs_provider_detect(NMCSProvider * provider,
|
||||
GCancellable * cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
gboolean nmcs_provider_detect_finish (NMCSProvider *provider,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
gboolean nmcs_provider_detect_finish(NMCSProvider *provider, GAsyncResult *result, GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void nmcs_provider_get_config (NMCSProvider *provider,
|
||||
gboolean any,
|
||||
const char *const*hwaddrs,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
void nmcs_provider_get_config(NMCSProvider * provider,
|
||||
gboolean any,
|
||||
const char *const * hwaddrs,
|
||||
GCancellable * cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
GHashTable *nmcs_provider_get_config_finish (NMCSProvider *provider,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
GHashTable *
|
||||
nmcs_provider_get_config_finish(NMCSProvider *provider, GAsyncResult *result, GError **error);
|
||||
|
||||
#endif /* __NMCS_PROVIDER_H__ */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -11,46 +11,43 @@
|
|||
#include "nm-device.h"
|
||||
#include "nm-libnm-core-intern/nm-libnm-core-utils.h"
|
||||
|
||||
const NMObject **nmc_objects_sort_by_path (const NMObject *const*objs, gssize len);
|
||||
const NMObject **nmc_objects_sort_by_path(const NMObject *const *objs, gssize len);
|
||||
|
||||
const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error);
|
||||
const char *nmc_string_is_valid(const char *input, const char **allowed, GError **error);
|
||||
|
||||
gboolean nmc_string_to_uint (const char *str,
|
||||
gboolean range_check,
|
||||
unsigned long int min,
|
||||
unsigned long int max,
|
||||
unsigned long int *value);
|
||||
gboolean nmc_string_to_bool (const char *str, gboolean *val_bool, GError **error);
|
||||
gboolean nmc_string_to_ternary (const char *str, NMTernary *val, GError **error);
|
||||
gboolean nmc_string_to_uint(const char * str,
|
||||
gboolean range_check,
|
||||
unsigned long int min,
|
||||
unsigned long int max,
|
||||
unsigned long int *value);
|
||||
gboolean nmc_string_to_bool(const char *str, gboolean *val_bool, GError **error);
|
||||
gboolean nmc_string_to_ternary(const char *str, NMTernary *val, GError **error);
|
||||
|
||||
gboolean matches (const char *cmd, const char *pattern);
|
||||
gboolean matches(const char *cmd, const char *pattern);
|
||||
|
||||
/* FIXME: don't expose this function on its own, at least not from this file. */
|
||||
const char *nmc_bond_validate_mode (const char *mode, GError **error);
|
||||
const char *nmc_bond_validate_mode(const char *mode, GError **error);
|
||||
|
||||
const char *nmc_device_state_to_string_with_external (NMDevice *device);
|
||||
const char *nmc_device_state_to_string_with_external(NMDevice *device);
|
||||
|
||||
const char *nm_active_connection_state_reason_to_string (NMActiveConnectionStateReason reason);
|
||||
const char *nmc_device_state_to_string (NMDeviceState state);
|
||||
const char *nmc_device_reason_to_string (NMDeviceStateReason reason);
|
||||
const char *nmc_device_metered_to_string (NMMetered value);
|
||||
const char *nm_active_connection_state_reason_to_string(NMActiveConnectionStateReason reason);
|
||||
const char *nmc_device_state_to_string(NMDeviceState state);
|
||||
const char *nmc_device_reason_to_string(NMDeviceStateReason reason);
|
||||
const char *nmc_device_metered_to_string(NMMetered value);
|
||||
|
||||
NMActiveConnectionState nmc_activation_get_effective_state (NMActiveConnection *active,
|
||||
NMDevice *device,
|
||||
const char **reason);
|
||||
NMActiveConnectionState nmc_activation_get_effective_state(NMActiveConnection *active,
|
||||
NMDevice * device,
|
||||
const char ** reason);
|
||||
|
||||
const char *nmc_wifi_strength_bars (guint8 strength);
|
||||
const char *nmc_wifi_strength_bars(guint8 strength);
|
||||
|
||||
const char *nmc_password_subst_char (void);
|
||||
const char *nmc_password_subst_char(void);
|
||||
|
||||
void nmc_print_qrcode (const char *str);
|
||||
void nmc_print_qrcode(const char *str);
|
||||
|
||||
GHashTable *nmc_utils_parse_passwd_file (char *contents,
|
||||
gssize *out_error_line,
|
||||
GError **error);
|
||||
GHashTable *nmc_utils_parse_passwd_file(char *contents, gssize *out_error_line, GError **error);
|
||||
|
||||
GHashTable *nmc_utils_read_passwd_file (const char *passwd_file,
|
||||
gssize *out_error_line,
|
||||
GError **error);
|
||||
GHashTable *
|
||||
nmc_utils_read_passwd_file(const char *passwd_file, gssize *out_error_line, GError **error);
|
||||
|
||||
#endif /* __NM_CLIENT_UTILS_H__ */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -11,81 +11,90 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMSetting *nm_meta_setting_info_editor_new_setting (const NMMetaSettingInfoEditor *setting_info,
|
||||
NMMetaAccessorSettingInitType init_type);
|
||||
NMSetting *nm_meta_setting_info_editor_new_setting(const NMMetaSettingInfoEditor *setting_info,
|
||||
NMMetaAccessorSettingInitType init_type);
|
||||
|
||||
const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_name (const char *setting_name, gboolean use_alias);
|
||||
const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_gtype (GType gtype);
|
||||
const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_setting (NMSetting *setting);
|
||||
const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_name(const char *setting_name,
|
||||
gboolean use_alias);
|
||||
const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_gtype(GType gtype);
|
||||
const NMMetaSettingInfoEditor *nm_meta_setting_info_editor_find_by_setting(NMSetting *setting);
|
||||
|
||||
const NMMetaPropertyInfo *nm_meta_setting_info_editor_get_property_info (const NMMetaSettingInfoEditor *setting_info,
|
||||
const char *property_name);
|
||||
const NMMetaPropertyInfo *nm_meta_property_info_find_by_name (const char *setting_name,
|
||||
const char *property_name);
|
||||
const NMMetaPropertyInfo *nm_meta_property_info_find_by_setting (NMSetting *setting,
|
||||
const char *property_name);
|
||||
const NMMetaPropertyInfo *
|
||||
nm_meta_setting_info_editor_get_property_info(const NMMetaSettingInfoEditor *setting_info,
|
||||
const char * property_name);
|
||||
const NMMetaPropertyInfo *nm_meta_property_info_find_by_name(const char *setting_name,
|
||||
const char *property_name);
|
||||
const NMMetaPropertyInfo *nm_meta_property_info_find_by_setting(NMSetting * setting,
|
||||
const char *property_name);
|
||||
|
||||
gboolean nm_meta_setting_info_editor_has_secrets (const NMMetaSettingInfoEditor *setting_info);
|
||||
gboolean nm_meta_setting_info_editor_has_secrets(const NMMetaSettingInfoEditor *setting_info);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
const NMMetaSettingInfoEditor *const*nm_meta_setting_infos_editor_p (void);
|
||||
const NMMetaSettingInfoEditor *const *nm_meta_setting_infos_editor_p(void);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
const char *nm_meta_abstract_info_get_name (const NMMetaAbstractInfo *abstract_info, gboolean for_header);
|
||||
const char *nm_meta_abstract_info_get_name(const NMMetaAbstractInfo *abstract_info,
|
||||
gboolean for_header);
|
||||
|
||||
const NMMetaAbstractInfo *const*nm_meta_abstract_info_get_nested (const NMMetaAbstractInfo *abstract_info,
|
||||
guint *out_len,
|
||||
gpointer *nested_to_free);
|
||||
const NMMetaAbstractInfo *const *
|
||||
nm_meta_abstract_info_get_nested(const NMMetaAbstractInfo *abstract_info,
|
||||
guint * out_len,
|
||||
gpointer * nested_to_free);
|
||||
|
||||
gconstpointer nm_meta_abstract_info_get (const NMMetaAbstractInfo *abstract_info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
gpointer target,
|
||||
gpointer target_data,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gboolean *out_is_default,
|
||||
gpointer *out_to_free);
|
||||
gconstpointer nm_meta_abstract_info_get(const NMMetaAbstractInfo * abstract_info,
|
||||
const NMMetaEnvironment * environment,
|
||||
gpointer environment_user_data,
|
||||
gpointer target,
|
||||
gpointer target_data,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gboolean * out_is_default,
|
||||
gpointer * out_to_free);
|
||||
|
||||
const char *const*nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const char *const *nm_meta_abstract_info_complete(const NMMetaAbstractInfo *abstract_info,
|
||||
const NMMetaEnvironment * environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaOperationContext *operation_context,
|
||||
const char *text,
|
||||
const char * text,
|
||||
gboolean *out_complete_filename,
|
||||
char ***out_to_free);
|
||||
char *** out_to_free);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
char *nm_meta_abstract_info_get_nested_names_str (const NMMetaAbstractInfo *abstract_info, const char *name_prefix);
|
||||
char *nm_meta_abstract_infos_get_names_str (const NMMetaAbstractInfo *const*fields_array, const char *name_prefix);
|
||||
char *nm_meta_abstract_info_get_nested_names_str(const NMMetaAbstractInfo *abstract_info,
|
||||
const char * name_prefix);
|
||||
char *nm_meta_abstract_infos_get_names_str(const NMMetaAbstractInfo *const *fields_array,
|
||||
const char * name_prefix);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
const NMMetaAbstractInfo *info;
|
||||
const char *self_selection;
|
||||
const char *sub_selection;
|
||||
guint idx;
|
||||
const NMMetaAbstractInfo *info;
|
||||
const char * self_selection;
|
||||
const char * sub_selection;
|
||||
guint idx;
|
||||
} NMMetaSelectionItem;
|
||||
|
||||
typedef struct {
|
||||
const guint num;
|
||||
const NMMetaSelectionItem items[];
|
||||
const guint num;
|
||||
const NMMetaSelectionItem items[];
|
||||
} NMMetaSelectionResultList;
|
||||
|
||||
NMMetaSelectionResultList *nm_meta_selection_create_all (const NMMetaAbstractInfo *const* fields_array);
|
||||
NMMetaSelectionResultList *nm_meta_selection_create_parse_one (const NMMetaAbstractInfo *const* fields_array,
|
||||
const char *fields_prefix,
|
||||
const char *fields_str,
|
||||
gboolean validate_nested,
|
||||
GError **error);
|
||||
NMMetaSelectionResultList *nm_meta_selection_create_parse_list (const NMMetaAbstractInfo *const* fields_array,
|
||||
const char *fields_str,
|
||||
gboolean validate_nested,
|
||||
GError **error);
|
||||
NMMetaSelectionResultList *
|
||||
nm_meta_selection_create_all(const NMMetaAbstractInfo *const *fields_array);
|
||||
NMMetaSelectionResultList *
|
||||
nm_meta_selection_create_parse_one(const NMMetaAbstractInfo *const *fields_array,
|
||||
const char * fields_prefix,
|
||||
const char * fields_str,
|
||||
gboolean validate_nested,
|
||||
GError ** error);
|
||||
NMMetaSelectionResultList *
|
||||
nm_meta_selection_create_parse_list(const NMMetaAbstractInfo *const *fields_array,
|
||||
const char * fields_str,
|
||||
gboolean validate_nested,
|
||||
GError ** error);
|
||||
|
||||
#endif /* _NM_META_SETTING_ACCESS_H__ */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -15,157 +15,170 @@ struct _NMDevice;
|
|||
#define NM_META_TEXT_HIDDEN N_("<hidden>")
|
||||
|
||||
#define NM_META_TEXT_PROMPT_ADSL_PROTO N_("Protocol")
|
||||
#define NM_META_TEXT_PROMPT_ADSL_PROTO_CHOICES "(" NM_SETTING_ADSL_PROTOCOL_PPPOA "/" NM_SETTING_ADSL_PROTOCOL_PPPOE "/" NM_SETTING_ADSL_PROTOCOL_IPOATM ")"
|
||||
#define NM_META_TEXT_PROMPT_ADSL_PROTO_CHOICES \
|
||||
"(" NM_SETTING_ADSL_PROTOCOL_PPPOA "/" NM_SETTING_ADSL_PROTOCOL_PPPOE \
|
||||
"/" NM_SETTING_ADSL_PROTOCOL_IPOATM ")"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_ADSL_ENCAP N_("ADSL encapsulation")
|
||||
#define NM_META_TEXT_PROMPT_ADSL_ENCAP_CHOICES "(" NM_SETTING_ADSL_ENCAPSULATION_VCMUX "/" NM_SETTING_ADSL_ENCAPSULATION_LLC ") [none]"
|
||||
#define NM_META_TEXT_PROMPT_ADSL_ENCAP_CHOICES \
|
||||
"(" NM_SETTING_ADSL_ENCAPSULATION_VCMUX "/" NM_SETTING_ADSL_ENCAPSULATION_LLC ") [none]"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_CON_TYPE N_("Connection type")
|
||||
#define NM_META_TEXT_PROMPT_IFNAME N_("Interface name [*]")
|
||||
#define NM_META_TEXT_PROMPT_VPN_TYPE N_("VPN type")
|
||||
#define NM_META_TEXT_PROMPT_MASTER N_("Master")
|
||||
#define NM_META_TEXT_PROMPT_CON_TYPE N_("Connection type")
|
||||
#define NM_META_TEXT_PROMPT_IFNAME N_("Interface name [*]")
|
||||
#define NM_META_TEXT_PROMPT_VPN_TYPE N_("VPN type")
|
||||
#define NM_META_TEXT_PROMPT_MASTER N_("Master")
|
||||
|
||||
#define NM_META_TEXT_PROMPT_IB_MODE N_("Transport mode")
|
||||
#define NM_META_TEXT_PROMPT_IB_MODE N_("Transport mode")
|
||||
#define NM_META_TEXT_WORD_DATAGRAM "datagram"
|
||||
#define NM_META_TEXT_WORD_CONNECTED "connected"
|
||||
#define NM_META_TEXT_PROMPT_IB_MODE_CHOICES "(" NM_META_TEXT_WORD_DATAGRAM "/" NM_META_TEXT_WORD_CONNECTED ") [" NM_META_TEXT_WORD_DATAGRAM "]"
|
||||
#define NM_META_TEXT_PROMPT_IB_MODE_CHOICES \
|
||||
"(" NM_META_TEXT_WORD_DATAGRAM "/" NM_META_TEXT_WORD_CONNECTED \
|
||||
") [" NM_META_TEXT_WORD_DATAGRAM "]"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_BT_TYPE N_("Bluetooth type")
|
||||
#define NM_META_TEXT_WORD_PANU "panu"
|
||||
#define NM_META_TEXT_WORD_NAP "nap"
|
||||
#define NM_META_TEXT_WORD_DUN_GSM "dun-gsm"
|
||||
#define NM_META_TEXT_WORD_DUN_CDMA "dun-cdma"
|
||||
#define NM_META_TEXT_PROMPT_BT_TYPE_CHOICES "(" NM_META_TEXT_WORD_PANU "/" NM_META_TEXT_WORD_NAP "/" NM_META_TEXT_WORD_DUN_GSM "/" NM_META_TEXT_WORD_DUN_CDMA ") [" NM_META_TEXT_WORD_PANU "]"
|
||||
#define NM_META_TEXT_PROMPT_BT_TYPE_CHOICES \
|
||||
"(" NM_META_TEXT_WORD_PANU "/" NM_META_TEXT_WORD_NAP "/" NM_META_TEXT_WORD_DUN_GSM \
|
||||
"/" NM_META_TEXT_WORD_DUN_CDMA ") [" NM_META_TEXT_WORD_PANU "]"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_BOND_MODE N_("Bonding mode")
|
||||
|
||||
#define NM_META_TEXT_PROMPT_BOND_MON_MODE N_("Bonding monitoring mode")
|
||||
#define NM_META_TEXT_WORD_MIIMON "miimon"
|
||||
#define NM_META_TEXT_WORD_ARP "arp"
|
||||
#define NM_META_TEXT_PROMPT_BOND_MON_MODE_CHOICES "(" NM_META_TEXT_WORD_MIIMON "/" NM_META_TEXT_WORD_ARP ") [" NM_META_TEXT_WORD_MIIMON "]"
|
||||
#define NM_META_TEXT_WORD_MIIMON "miimon"
|
||||
#define NM_META_TEXT_WORD_ARP "arp"
|
||||
#define NM_META_TEXT_PROMPT_BOND_MON_MODE_CHOICES \
|
||||
"(" NM_META_TEXT_WORD_MIIMON "/" NM_META_TEXT_WORD_ARP ") [" NM_META_TEXT_WORD_MIIMON "]"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_WIFI_MODE N_("Wi-Fi mode")
|
||||
#define NM_META_TEXT_WORD_INFRA "infrastructure"
|
||||
#define NM_META_TEXT_WORD_AP "ap"
|
||||
#define NM_META_TEXT_WORD_ADHOC "adhoc"
|
||||
#define NM_META_TEXT_WORD_MESH "mesh"
|
||||
#define NM_META_TEXT_PROMPT_WIFI_MODE_CHOICES "(" NM_META_TEXT_WORD_INFRA "/" NM_META_TEXT_WORD_AP "/" NM_META_TEXT_WORD_ADHOC "/" NM_META_TEXT_WORD_MESH ") [" NM_META_TEXT_WORD_INFRA "]"
|
||||
#define NM_META_TEXT_WORD_INFRA "infrastructure"
|
||||
#define NM_META_TEXT_WORD_AP "ap"
|
||||
#define NM_META_TEXT_WORD_ADHOC "adhoc"
|
||||
#define NM_META_TEXT_WORD_MESH "mesh"
|
||||
#define NM_META_TEXT_PROMPT_WIFI_MODE_CHOICES \
|
||||
"(" NM_META_TEXT_WORD_INFRA "/" NM_META_TEXT_WORD_AP "/" NM_META_TEXT_WORD_ADHOC \
|
||||
"/" NM_META_TEXT_WORD_MESH ") [" NM_META_TEXT_WORD_INFRA "]"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_TUN_MODE N_("Tun mode")
|
||||
#define NM_META_TEXT_WORD_TUN "tun"
|
||||
#define NM_META_TEXT_WORD_TAP "tap"
|
||||
#define NM_META_TEXT_PROMPT_TUN_MODE_CHOICES "(" NM_META_TEXT_WORD_TUN "/" NM_META_TEXT_WORD_TAP ") [" NM_META_TEXT_WORD_TUN "]"
|
||||
#define NM_META_TEXT_WORD_TUN "tun"
|
||||
#define NM_META_TEXT_WORD_TAP "tap"
|
||||
#define NM_META_TEXT_PROMPT_TUN_MODE_CHOICES \
|
||||
"(" NM_META_TEXT_WORD_TUN "/" NM_META_TEXT_WORD_TAP ") [" NM_META_TEXT_WORD_TUN "]"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_IP_TUNNEL_MODE N_("IP Tunnel mode")
|
||||
|
||||
#define NM_META_TEXT_PROMPT_MACVLAN_MODE N_("MACVLAN mode")
|
||||
|
||||
#define NM_META_TEXT_PROMPT_MACSEC_MODE N_("MACsec mode")
|
||||
#define NM_META_TEXT_WORD_PSK "psk"
|
||||
#define NM_META_TEXT_WORD_EAP "eap"
|
||||
#define NM_META_TEXT_PROMPT_MACSEC_MODE_CHOICES "(" NM_META_TEXT_WORD_PSK "/" NM_META_TEXT_WORD_EAP ")"
|
||||
#define NM_META_TEXT_WORD_PSK "psk"
|
||||
#define NM_META_TEXT_WORD_EAP "eap"
|
||||
#define NM_META_TEXT_PROMPT_MACSEC_MODE_CHOICES \
|
||||
"(" NM_META_TEXT_WORD_PSK "/" NM_META_TEXT_WORD_EAP ")"
|
||||
|
||||
#define NM_META_TEXT_PROMPT_PROXY_METHOD N_("Proxy method")
|
||||
#define NM_META_TEXT_WORD_NONE "none"
|
||||
#define NM_META_TEXT_WORD_AUTO "auto"
|
||||
#define NM_META_TEXT_PROMPT_PROXY_METHOD_CHOICES "(" NM_META_TEXT_WORD_NONE "/" NM_META_TEXT_WORD_AUTO ") [" NM_META_TEXT_WORD_NONE "]"
|
||||
#define NM_META_TEXT_WORD_NONE "none"
|
||||
#define NM_META_TEXT_WORD_AUTO "auto"
|
||||
#define NM_META_TEXT_PROMPT_PROXY_METHOD_CHOICES \
|
||||
"(" NM_META_TEXT_WORD_NONE "/" NM_META_TEXT_WORD_AUTO ") [" NM_META_TEXT_WORD_NONE "]"
|
||||
|
||||
typedef enum {
|
||||
NM_META_COLOR_NONE = 0,
|
||||
NM_META_COLOR_CONNECTION_ACTIVATED,
|
||||
NM_META_COLOR_CONNECTION_ACTIVATING,
|
||||
NM_META_COLOR_CONNECTION_DISCONNECTING,
|
||||
NM_META_COLOR_CONNECTION_INVISIBLE,
|
||||
NM_META_COLOR_CONNECTION_EXTERNAL,
|
||||
NM_META_COLOR_CONNECTION_UNKNOWN,
|
||||
NM_META_COLOR_CONNECTIVITY_FULL,
|
||||
NM_META_COLOR_CONNECTIVITY_LIMITED,
|
||||
NM_META_COLOR_CONNECTIVITY_NONE,
|
||||
NM_META_COLOR_CONNECTIVITY_PORTAL,
|
||||
NM_META_COLOR_CONNECTIVITY_UNKNOWN,
|
||||
NM_META_COLOR_DEVICE_ACTIVATED,
|
||||
NM_META_COLOR_DEVICE_ACTIVATING,
|
||||
NM_META_COLOR_DEVICE_DISCONNECTED,
|
||||
NM_META_COLOR_DEVICE_FIRMWARE_MISSING,
|
||||
NM_META_COLOR_DEVICE_PLUGIN_MISSING,
|
||||
NM_META_COLOR_DEVICE_UNAVAILABLE,
|
||||
NM_META_COLOR_DEVICE_DISABLED,
|
||||
NM_META_COLOR_DEVICE_EXTERNAL,
|
||||
NM_META_COLOR_DEVICE_UNKNOWN,
|
||||
NM_META_COLOR_MANAGER_RUNNING,
|
||||
NM_META_COLOR_MANAGER_STARTING,
|
||||
NM_META_COLOR_MANAGER_STOPPED,
|
||||
NM_META_COLOR_PERMISSION_AUTH,
|
||||
NM_META_COLOR_PERMISSION_NO,
|
||||
NM_META_COLOR_PERMISSION_UNKNOWN,
|
||||
NM_META_COLOR_PERMISSION_YES,
|
||||
NM_META_COLOR_PROMPT,
|
||||
NM_META_COLOR_STATE_ASLEEP,
|
||||
NM_META_COLOR_STATE_CONNECTED_GLOBAL,
|
||||
NM_META_COLOR_STATE_CONNECTED_LOCAL,
|
||||
NM_META_COLOR_STATE_CONNECTED_SITE,
|
||||
NM_META_COLOR_STATE_CONNECTING,
|
||||
NM_META_COLOR_STATE_DISCONNECTED,
|
||||
NM_META_COLOR_STATE_DISCONNECTING,
|
||||
NM_META_COLOR_STATE_UNKNOWN,
|
||||
NM_META_COLOR_WIFI_SIGNAL_EXCELLENT,
|
||||
NM_META_COLOR_WIFI_SIGNAL_FAIR,
|
||||
NM_META_COLOR_WIFI_SIGNAL_GOOD,
|
||||
NM_META_COLOR_WIFI_SIGNAL_POOR,
|
||||
NM_META_COLOR_WIFI_SIGNAL_UNKNOWN,
|
||||
NM_META_COLOR_DISABLED,
|
||||
NM_META_COLOR_ENABLED,
|
||||
_NM_META_COLOR_NUM
|
||||
NM_META_COLOR_NONE = 0,
|
||||
NM_META_COLOR_CONNECTION_ACTIVATED,
|
||||
NM_META_COLOR_CONNECTION_ACTIVATING,
|
||||
NM_META_COLOR_CONNECTION_DISCONNECTING,
|
||||
NM_META_COLOR_CONNECTION_INVISIBLE,
|
||||
NM_META_COLOR_CONNECTION_EXTERNAL,
|
||||
NM_META_COLOR_CONNECTION_UNKNOWN,
|
||||
NM_META_COLOR_CONNECTIVITY_FULL,
|
||||
NM_META_COLOR_CONNECTIVITY_LIMITED,
|
||||
NM_META_COLOR_CONNECTIVITY_NONE,
|
||||
NM_META_COLOR_CONNECTIVITY_PORTAL,
|
||||
NM_META_COLOR_CONNECTIVITY_UNKNOWN,
|
||||
NM_META_COLOR_DEVICE_ACTIVATED,
|
||||
NM_META_COLOR_DEVICE_ACTIVATING,
|
||||
NM_META_COLOR_DEVICE_DISCONNECTED,
|
||||
NM_META_COLOR_DEVICE_FIRMWARE_MISSING,
|
||||
NM_META_COLOR_DEVICE_PLUGIN_MISSING,
|
||||
NM_META_COLOR_DEVICE_UNAVAILABLE,
|
||||
NM_META_COLOR_DEVICE_DISABLED,
|
||||
NM_META_COLOR_DEVICE_EXTERNAL,
|
||||
NM_META_COLOR_DEVICE_UNKNOWN,
|
||||
NM_META_COLOR_MANAGER_RUNNING,
|
||||
NM_META_COLOR_MANAGER_STARTING,
|
||||
NM_META_COLOR_MANAGER_STOPPED,
|
||||
NM_META_COLOR_PERMISSION_AUTH,
|
||||
NM_META_COLOR_PERMISSION_NO,
|
||||
NM_META_COLOR_PERMISSION_UNKNOWN,
|
||||
NM_META_COLOR_PERMISSION_YES,
|
||||
NM_META_COLOR_PROMPT,
|
||||
NM_META_COLOR_STATE_ASLEEP,
|
||||
NM_META_COLOR_STATE_CONNECTED_GLOBAL,
|
||||
NM_META_COLOR_STATE_CONNECTED_LOCAL,
|
||||
NM_META_COLOR_STATE_CONNECTED_SITE,
|
||||
NM_META_COLOR_STATE_CONNECTING,
|
||||
NM_META_COLOR_STATE_DISCONNECTED,
|
||||
NM_META_COLOR_STATE_DISCONNECTING,
|
||||
NM_META_COLOR_STATE_UNKNOWN,
|
||||
NM_META_COLOR_WIFI_SIGNAL_EXCELLENT,
|
||||
NM_META_COLOR_WIFI_SIGNAL_FAIR,
|
||||
NM_META_COLOR_WIFI_SIGNAL_GOOD,
|
||||
NM_META_COLOR_WIFI_SIGNAL_POOR,
|
||||
NM_META_COLOR_WIFI_SIGNAL_UNKNOWN,
|
||||
NM_META_COLOR_DISABLED,
|
||||
NM_META_COLOR_ENABLED,
|
||||
_NM_META_COLOR_NUM
|
||||
} NMMetaColor;
|
||||
|
||||
typedef enum {
|
||||
NM_META_ACCESSOR_MODIFIER_SET,
|
||||
NM_META_ACCESSOR_MODIFIER_ADD,
|
||||
NM_META_ACCESSOR_MODIFIER_DEL,
|
||||
NM_META_ACCESSOR_MODIFIER_SET,
|
||||
NM_META_ACCESSOR_MODIFIER_ADD,
|
||||
NM_META_ACCESSOR_MODIFIER_DEL,
|
||||
} NMMetaAccessorModifier;
|
||||
|
||||
typedef enum {
|
||||
NM_META_ACCESSOR_GET_TYPE_PRETTY,
|
||||
NM_META_ACCESSOR_GET_TYPE_PARSABLE,
|
||||
NM_META_ACCESSOR_GET_TYPE_COLOR,
|
||||
NM_META_ACCESSOR_GET_TYPE_PRETTY,
|
||||
NM_META_ACCESSOR_GET_TYPE_PARSABLE,
|
||||
NM_META_ACCESSOR_GET_TYPE_COLOR,
|
||||
} NMMetaAccessorGetType;
|
||||
|
||||
typedef enum {
|
||||
NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT,
|
||||
NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI,
|
||||
NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT,
|
||||
NM_META_ACCESSOR_SETTING_INIT_TYPE_CLI,
|
||||
} NMMetaAccessorSettingInitType;
|
||||
|
||||
typedef enum {
|
||||
NM_META_ACCESSOR_GET_FLAGS_NONE = 0,
|
||||
NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV = (1LL << 0),
|
||||
NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS = (1LL << 1),
|
||||
NM_META_ACCESSOR_GET_FLAGS_NONE = 0,
|
||||
NM_META_ACCESSOR_GET_FLAGS_ACCEPT_STRV = (1LL << 0),
|
||||
NM_META_ACCESSOR_GET_FLAGS_SHOW_SECRETS = (1LL << 1),
|
||||
} NMMetaAccessorGetFlags;
|
||||
|
||||
typedef enum {
|
||||
NM_META_ACCESSOR_GET_OUT_FLAGS_NONE = 0,
|
||||
NM_META_ACCESSOR_GET_OUT_FLAGS_STRV = (1LL << 0),
|
||||
NM_META_ACCESSOR_GET_OUT_FLAGS_NONE = 0,
|
||||
NM_META_ACCESSOR_GET_OUT_FLAGS_STRV = (1LL << 0),
|
||||
|
||||
/* the property allows to be hidden, if and only if, it's value is set to the
|
||||
/* the property allows to be hidden, if and only if, it's value is set to the
|
||||
* default. This should only be set by new properties, to preserve behavior
|
||||
* of old properties, which were always printed. */
|
||||
NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE = (1LL << 1),
|
||||
NM_META_ACCESSOR_GET_OUT_FLAGS_HIDE = (1LL << 1),
|
||||
} NMMetaAccessorGetOutFlags;
|
||||
|
||||
typedef enum {
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC = (1LL << 0),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC_HEX = (1LL << 1),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT = (1LL << 2),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT_L10N = (1LL << 3),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC = (1LL << 4),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC_HEX = (1LL << 5),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT = (1LL << 6),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC = (1LL << 0),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_NUMERIC_HEX = (1LL << 1),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT = (1LL << 2),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PRETTY_TEXT_L10N = (1LL << 3),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC = (1LL << 4),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_NUMERIC_HEX = (1LL << 5),
|
||||
NM_META_PROPERTY_TYP_FLAG_ENUM_GET_PARSABLE_TEXT = (1LL << 6),
|
||||
} NMMetaPropertyTypFlags;
|
||||
|
||||
typedef enum {
|
||||
NM_META_PROPERTY_TYPE_MAC_MODE_DEFAULT,
|
||||
NM_META_PROPERTY_TYPE_MAC_MODE_CLONED,
|
||||
NM_META_PROPERTY_TYPE_MAC_MODE_INFINIBAND,
|
||||
NM_META_PROPERTY_TYPE_MAC_MODE_WPAN,
|
||||
NM_META_PROPERTY_TYPE_MAC_MODE_DEFAULT,
|
||||
NM_META_PROPERTY_TYPE_MAC_MODE_CLONED,
|
||||
NM_META_PROPERTY_TYPE_MAC_MODE_INFINIBAND,
|
||||
NM_META_PROPERTY_TYPE_MAC_MODE_WPAN,
|
||||
} NMMetaPropertyTypeMacMode;
|
||||
|
||||
typedef struct _NMMetaEnvironment NMMetaEnvironment;
|
||||
|
|
@ -183,234 +196,227 @@ typedef struct _NMMetaPropertyTypDataNested NMMetaPropertyTypDataNested;
|
|||
* This command actually violates layering, and should be considered
|
||||
* a hack. In the future, try to replace its use. */
|
||||
struct _NMMetaOperationContext {
|
||||
NMConnection *connection;
|
||||
NMConnection *connection;
|
||||
};
|
||||
|
||||
struct _NMMetaPropertyType {
|
||||
/* should return a translated string */
|
||||
const char *(*describe_fcn)(const NMMetaPropertyInfo *property_info, char **out_to_free);
|
||||
|
||||
/* should return a translated string */
|
||||
const char *(*describe_fcn) (const NMMetaPropertyInfo *property_info,
|
||||
char **out_to_free);
|
||||
gconstpointer (*get_fcn)(const NMMetaPropertyInfo * property_info,
|
||||
const NMMetaEnvironment * environment,
|
||||
gpointer environment_user_data,
|
||||
NMSetting * setting,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gboolean * out_is_default,
|
||||
gpointer * out_to_free);
|
||||
gboolean (*set_fcn)(const NMMetaPropertyInfo *property_info,
|
||||
const NMMetaEnvironment * environment,
|
||||
gpointer environment_user_data,
|
||||
NMSetting * setting,
|
||||
NMMetaAccessorModifier modifier,
|
||||
const char * value,
|
||||
GError ** error);
|
||||
|
||||
gconstpointer (*get_fcn) (const NMMetaPropertyInfo *property_info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
NMSetting *setting,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gboolean *out_is_default,
|
||||
gpointer *out_to_free);
|
||||
gboolean (*set_fcn) (const NMMetaPropertyInfo *property_info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
NMSetting *setting,
|
||||
NMMetaAccessorModifier modifier,
|
||||
const char *value,
|
||||
GError **error);
|
||||
const char *const *(*values_fcn)(const NMMetaPropertyInfo *property_info, char ***out_to_free);
|
||||
|
||||
const char *const*(*values_fcn) (const NMMetaPropertyInfo *property_info,
|
||||
char ***out_to_free);
|
||||
const char *const *(*complete_fcn)(const NMMetaPropertyInfo * property_info,
|
||||
const NMMetaEnvironment * environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaOperationContext *operation_context,
|
||||
const char * text,
|
||||
gboolean * out_complete_filename,
|
||||
char *** out_to_free);
|
||||
|
||||
const char *const*(*complete_fcn) (const NMMetaPropertyInfo *property_info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaOperationContext *operation_context,
|
||||
const char *text,
|
||||
gboolean *out_complete_filename,
|
||||
char ***out_to_free);
|
||||
|
||||
/* Whether set_fcn() supports the '-' modifier. That is, whether the property
|
||||
/* Whether set_fcn() supports the '-' modifier. That is, whether the property
|
||||
* is a list type. */
|
||||
bool set_supports_remove:1;
|
||||
bool set_supports_remove : 1;
|
||||
};
|
||||
|
||||
struct _NMUtilsEnumValueInfo;
|
||||
|
||||
typedef union {
|
||||
gint64 i64;
|
||||
guint64 u64;
|
||||
gint64 i64;
|
||||
guint64 u64;
|
||||
} NMMetaSignUnsignInt64;
|
||||
|
||||
typedef struct {
|
||||
const char *nick;
|
||||
NMMetaSignUnsignInt64 value;
|
||||
const char * nick;
|
||||
NMMetaSignUnsignInt64 value;
|
||||
} NMMetaUtilsIntValueInfo;
|
||||
|
||||
struct _NMMetaPropertyTypData {
|
||||
union {
|
||||
struct {
|
||||
GType (*get_gtype) (void);
|
||||
int min;
|
||||
int max;
|
||||
const struct _NMUtilsEnumValueInfo *value_infos_get; /* nicks for get function */
|
||||
const struct _NMUtilsEnumValueInfo *value_infos; /* nicks for set function */
|
||||
void (*pre_set_notify) (const NMMetaPropertyInfo *property_info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
NMSetting *setting,
|
||||
int value);
|
||||
} gobject_enum;
|
||||
struct {
|
||||
NMMetaSignUnsignInt64 min;
|
||||
NMMetaSignUnsignInt64 max;
|
||||
guint base;
|
||||
const NMMetaUtilsIntValueInfo *value_infos;
|
||||
} gobject_int;
|
||||
struct {
|
||||
const char *(*validate_fcn) (const char *value, char **out_to_free, GError **error);
|
||||
bool handle_emptyunset:1;
|
||||
} gobject_string;
|
||||
struct {
|
||||
bool legacy_format:1;
|
||||
} gobject_bytes;
|
||||
struct {
|
||||
guint32 (*get_num_fcn_u32) (NMSetting *setting);
|
||||
guint (*get_num_fcn_u) (NMSetting *setting);
|
||||
void (*clear_all_fcn) (NMSetting *setting);
|
||||
union {
|
||||
struct {
|
||||
GType (*get_gtype)(void);
|
||||
int min;
|
||||
int max;
|
||||
const struct _NMUtilsEnumValueInfo *value_infos_get; /* nicks for get function */
|
||||
const struct _NMUtilsEnumValueInfo *value_infos; /* nicks for set function */
|
||||
void (*pre_set_notify)(const NMMetaPropertyInfo *property_info,
|
||||
const NMMetaEnvironment * environment,
|
||||
gpointer environment_user_data,
|
||||
NMSetting * setting,
|
||||
int value);
|
||||
} gobject_enum;
|
||||
struct {
|
||||
NMMetaSignUnsignInt64 min;
|
||||
NMMetaSignUnsignInt64 max;
|
||||
guint base;
|
||||
const NMMetaUtilsIntValueInfo *value_infos;
|
||||
} gobject_int;
|
||||
struct {
|
||||
const char *(*validate_fcn)(const char *value, char **out_to_free, GError **error);
|
||||
bool handle_emptyunset : 1;
|
||||
} gobject_string;
|
||||
struct {
|
||||
bool legacy_format : 1;
|
||||
} gobject_bytes;
|
||||
struct {
|
||||
guint32 (*get_num_fcn_u32)(NMSetting *setting);
|
||||
guint (*get_num_fcn_u)(NMSetting *setting);
|
||||
void (*clear_all_fcn)(NMSetting *setting);
|
||||
|
||||
/* some multilist properties distinguish between an empty list and
|
||||
/* some multilist properties distinguish between an empty list and
|
||||
* and unset. If this function pointer is set, certain behaviors come
|
||||
* into action to handle that. */
|
||||
void (*clear_emptyunset_fcn) (NMSetting *setting,
|
||||
gboolean is_set /* or else set default */);
|
||||
void (*clear_emptyunset_fcn)(NMSetting *setting,
|
||||
gboolean is_set /* or else set default */);
|
||||
|
||||
gboolean (*add_fcn) (NMSetting *setting,
|
||||
const char *item);
|
||||
void (*add2_fcn) (NMSetting *setting,
|
||||
const char *item);
|
||||
const char *(*validate_fcn) (const char *item, GError **error);
|
||||
const char *(*validate2_fcn) (NMSetting *setting, const char *item, GError **error);
|
||||
void (*remove_by_idx_fcn_u32) (NMSetting *setting, guint32 idx);
|
||||
void (*remove_by_idx_fcn_u) (NMSetting *setting, guint idx);
|
||||
void (*remove_by_idx_fcn_s) (NMSetting *setting, int idx);
|
||||
gboolean (*remove_by_value_fcn) (NMSetting *setting, const char *item);
|
||||
bool strsplit_plain:1;
|
||||
bool strsplit_with_spaces:1;
|
||||
} multilist;
|
||||
struct {
|
||||
guint (*get_num_fcn) (NMSetting *setting);
|
||||
void (*obj_to_str_fcn) (NMMetaAccessorGetType get_type,
|
||||
NMSetting *setting,
|
||||
guint idx,
|
||||
GString *str);
|
||||
gboolean (*set_fcn) (NMSetting *setting,
|
||||
gboolean do_add /* or else remove. */,
|
||||
const char *value,
|
||||
GError **error);
|
||||
void (*clear_all_fcn) (NMSetting *setting);
|
||||
void (*remove_by_idx_fcn_u) (NMSetting *setting, guint idx);
|
||||
void (*remove_by_idx_fcn_s) (NMSetting *setting, int idx);
|
||||
bool delimit_pretty_with_semicolon:1;
|
||||
bool strsplit_plain:1;
|
||||
} objlist;
|
||||
struct {
|
||||
gboolean (*set_fcn) (NMSetting *setting,
|
||||
const char *option,
|
||||
const char *value,
|
||||
GError **error);
|
||||
bool no_empty_value:1;
|
||||
} optionlist;
|
||||
struct {
|
||||
guint32 (*get_fcn) (NMSetting *setting);
|
||||
} mtu;
|
||||
struct {
|
||||
NMSetting8021xSchemeType scheme_type;
|
||||
} cert_8021x;
|
||||
struct {
|
||||
NMMetaPropertyTypeMacMode mode;
|
||||
} mac;
|
||||
struct {
|
||||
guint (*get_fcn) (NMSettingDcb *setting,
|
||||
guint user_priority);
|
||||
void (*set_fcn) (NMSettingDcb *setting,
|
||||
guint id,
|
||||
guint value);
|
||||
guint max;
|
||||
guint other;
|
||||
bool is_percent:1;
|
||||
} dcb;
|
||||
struct {
|
||||
gboolean (*get_fcn) (NMSettingDcb *s_dcb,
|
||||
guint priority);
|
||||
void (*set_fcn) (NMSettingDcb *setting,
|
||||
guint user_priority,
|
||||
gboolean enabled);
|
||||
bool with_flow_control_flags:1;
|
||||
} dcb_bool;
|
||||
struct {
|
||||
NMEthtoolID ethtool_id;
|
||||
} ethtool;
|
||||
} subtype;
|
||||
gboolean (*is_default_fcn) (NMSetting *setting);
|
||||
const char *const*values_static;
|
||||
const NMMetaPropertyTypDataNested *nested;
|
||||
NMMetaPropertyTypFlags typ_flags;
|
||||
gboolean (*add_fcn)(NMSetting *setting, const char *item);
|
||||
void (*add2_fcn)(NMSetting *setting, const char *item);
|
||||
const char *(*validate_fcn)(const char *item, GError **error);
|
||||
const char *(*validate2_fcn)(NMSetting *setting, const char *item, GError **error);
|
||||
void (*remove_by_idx_fcn_u32)(NMSetting *setting, guint32 idx);
|
||||
void (*remove_by_idx_fcn_u)(NMSetting *setting, guint idx);
|
||||
void (*remove_by_idx_fcn_s)(NMSetting *setting, int idx);
|
||||
gboolean (*remove_by_value_fcn)(NMSetting *setting, const char *item);
|
||||
bool strsplit_plain : 1;
|
||||
bool strsplit_with_spaces : 1;
|
||||
} multilist;
|
||||
struct {
|
||||
guint (*get_num_fcn)(NMSetting *setting);
|
||||
void (*obj_to_str_fcn)(NMMetaAccessorGetType get_type,
|
||||
NMSetting * setting,
|
||||
guint idx,
|
||||
GString * str);
|
||||
gboolean (*set_fcn)(NMSetting * setting,
|
||||
gboolean do_add /* or else remove. */,
|
||||
const char *value,
|
||||
GError ** error);
|
||||
void (*clear_all_fcn)(NMSetting *setting);
|
||||
void (*remove_by_idx_fcn_u)(NMSetting *setting, guint idx);
|
||||
void (*remove_by_idx_fcn_s)(NMSetting *setting, int idx);
|
||||
bool delimit_pretty_with_semicolon : 1;
|
||||
bool strsplit_plain : 1;
|
||||
} objlist;
|
||||
struct {
|
||||
gboolean (*set_fcn)(NMSetting * setting,
|
||||
const char *option,
|
||||
const char *value,
|
||||
GError ** error);
|
||||
bool no_empty_value : 1;
|
||||
} optionlist;
|
||||
struct {
|
||||
guint32 (*get_fcn)(NMSetting *setting);
|
||||
} mtu;
|
||||
struct {
|
||||
NMSetting8021xSchemeType scheme_type;
|
||||
} cert_8021x;
|
||||
struct {
|
||||
NMMetaPropertyTypeMacMode mode;
|
||||
} mac;
|
||||
struct {
|
||||
guint (*get_fcn)(NMSettingDcb *setting, guint user_priority);
|
||||
void (*set_fcn)(NMSettingDcb *setting, guint id, guint value);
|
||||
guint max;
|
||||
guint other;
|
||||
bool is_percent : 1;
|
||||
} dcb;
|
||||
struct {
|
||||
gboolean (*get_fcn)(NMSettingDcb *s_dcb, guint priority);
|
||||
void (*set_fcn)(NMSettingDcb *setting, guint user_priority, gboolean enabled);
|
||||
bool with_flow_control_flags : 1;
|
||||
} dcb_bool;
|
||||
struct {
|
||||
NMEthtoolID ethtool_id;
|
||||
} ethtool;
|
||||
} subtype;
|
||||
gboolean (*is_default_fcn)(NMSetting *setting);
|
||||
const char *const * values_static;
|
||||
const NMMetaPropertyTypDataNested *nested;
|
||||
NMMetaPropertyTypFlags typ_flags;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
NM_META_PROPERTY_INF_FLAG_NONE = 0x00,
|
||||
NM_META_PROPERTY_INF_FLAG_REQD = 0x01, /* Don't ask to ask. */
|
||||
NM_META_PROPERTY_INF_FLAG_DONT_ASK = 0x02, /* Don't ask interactively by default */
|
||||
NM_META_PROPERTY_INF_FLAG_MULTI = 0x04, /* Ask multiple times, do an append instead of set. */
|
||||
NM_META_PROPERTY_INF_FLAG_NONE = 0x00,
|
||||
NM_META_PROPERTY_INF_FLAG_REQD = 0x01, /* Don't ask to ask. */
|
||||
NM_META_PROPERTY_INF_FLAG_DONT_ASK = 0x02, /* Don't ask interactively by default */
|
||||
NM_META_PROPERTY_INF_FLAG_MULTI = 0x04, /* Ask multiple times, do an append instead of set. */
|
||||
} NMMetaPropertyInfFlags;
|
||||
|
||||
enum {
|
||||
_NM_META_PROPERTY_TYPE_VPN_SERVICE_TYPE = 0,
|
||||
_NM_META_PROPERTY_TYPE_CONNECTION_TYPE = 3,
|
||||
_NM_META_PROPERTY_TYPE_VPN_SERVICE_TYPE = 0,
|
||||
_NM_META_PROPERTY_TYPE_CONNECTION_TYPE = 3,
|
||||
};
|
||||
|
||||
#define nm_meta_property_info_connection_type (nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_CONNECTION].properties[_NM_META_PROPERTY_TYPE_CONNECTION_TYPE])
|
||||
#define nm_meta_property_info_vpn_service_type (nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_VPN].properties[_NM_META_PROPERTY_TYPE_VPN_SERVICE_TYPE])
|
||||
#define nm_meta_property_info_connection_type \
|
||||
(nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_CONNECTION] \
|
||||
.properties[_NM_META_PROPERTY_TYPE_CONNECTION_TYPE])
|
||||
#define nm_meta_property_info_vpn_service_type \
|
||||
(nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_VPN] \
|
||||
.properties[_NM_META_PROPERTY_TYPE_VPN_SERVICE_TYPE])
|
||||
|
||||
struct _NMMetaPropertyInfo {
|
||||
union {
|
||||
NMObjBaseInst parent;
|
||||
const NMMetaType *meta_type;
|
||||
};
|
||||
union {
|
||||
NMObjBaseInst parent;
|
||||
const NMMetaType *meta_type;
|
||||
};
|
||||
|
||||
const NMMetaSettingInfoEditor *setting_info;
|
||||
const NMMetaSettingInfoEditor *setting_info;
|
||||
|
||||
const char *property_name;
|
||||
const char *property_name;
|
||||
|
||||
const char *property_alias;
|
||||
const char *property_alias;
|
||||
|
||||
NMMetaPropertyInfFlags inf_flags;
|
||||
bool is_secret:1;
|
||||
NMMetaPropertyInfFlags inf_flags;
|
||||
bool is_secret : 1;
|
||||
|
||||
bool is_cli_option:1;
|
||||
bool hide_if_default:1;
|
||||
bool is_cli_option : 1;
|
||||
bool hide_if_default : 1;
|
||||
|
||||
const char *prompt;
|
||||
const char *prompt;
|
||||
|
||||
const char *def_hint;
|
||||
const char *def_hint;
|
||||
|
||||
const char *describe_doc;
|
||||
const char *describe_doc;
|
||||
|
||||
/* a non-translated but translatable static description (marked with N_()). */
|
||||
const char *describe_message;
|
||||
/* a non-translated but translatable static description (marked with N_()). */
|
||||
const char *describe_message;
|
||||
|
||||
const NMMetaPropertyType *property_type;
|
||||
const NMMetaPropertyTypData *property_typ_data;
|
||||
const NMMetaPropertyType * property_type;
|
||||
const NMMetaPropertyTypData *property_typ_data;
|
||||
};
|
||||
|
||||
typedef struct _NMMetaSettingValidPartItem {
|
||||
const NMMetaSettingInfoEditor *setting_info;
|
||||
bool mandatory;
|
||||
const NMMetaSettingInfoEditor *setting_info;
|
||||
bool mandatory;
|
||||
} NMMetaSettingValidPartItem;
|
||||
|
||||
struct _NMMetaSettingInfoEditor {
|
||||
union {
|
||||
NMObjBaseInst parent;
|
||||
const NMMetaType *meta_type;
|
||||
};
|
||||
const NMMetaSettingInfo *general;
|
||||
const char *alias;
|
||||
const char *pretty_name;
|
||||
const NMMetaPropertyInfo *const*properties;
|
||||
guint properties_num;
|
||||
union {
|
||||
NMObjBaseInst parent;
|
||||
const NMMetaType *meta_type;
|
||||
};
|
||||
const NMMetaSettingInfo * general;
|
||||
const char * alias;
|
||||
const char * pretty_name;
|
||||
const NMMetaPropertyInfo *const *properties;
|
||||
guint properties_num;
|
||||
|
||||
/* a NMConnection has a main type (connection.type), which is a
|
||||
/* a NMConnection has a main type (connection.type), which is a
|
||||
* main NMSetting instance. Depending on the type, a connection
|
||||
* may have a list of other allowed settings.
|
||||
*
|
||||
|
|
@ -420,45 +426,44 @@ struct _NMMetaSettingInfoEditor {
|
|||
* Some setting types a not a main type (NMSettingProxy). They
|
||||
* don't have valid_settings but are usually referenced by other
|
||||
* settings to be valid for them. */
|
||||
const NMMetaSettingValidPartItem *const*valid_parts;
|
||||
const NMMetaSettingValidPartItem *const *valid_parts;
|
||||
|
||||
void (*setting_init_fcn) (const NMMetaSettingInfoEditor *setting_info,
|
||||
NMSetting *setting,
|
||||
NMMetaAccessorSettingInitType init_type);
|
||||
void (*setting_init_fcn)(const NMMetaSettingInfoEditor *setting_info,
|
||||
NMSetting * setting,
|
||||
NMMetaAccessorSettingInitType init_type);
|
||||
};
|
||||
|
||||
struct _NMMetaType {
|
||||
NMObjBaseClass parent;
|
||||
const char *type_name;
|
||||
const char *(*get_name) (const NMMetaAbstractInfo *abstract_info,
|
||||
gboolean for_header);
|
||||
const NMMetaAbstractInfo *const*(*get_nested) (const NMMetaAbstractInfo *abstract_info,
|
||||
guint *out_len,
|
||||
gpointer *out_to_free);
|
||||
gconstpointer (*get_fcn) (const NMMetaAbstractInfo *info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
gpointer target,
|
||||
gpointer target_data,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gboolean *out_is_default,
|
||||
gpointer *out_to_free);
|
||||
const char *const*(*complete_fcn) (const NMMetaAbstractInfo *info,
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaOperationContext *operation_context,
|
||||
const char *text,
|
||||
gboolean *out_complete_filename,
|
||||
char ***out_to_free);
|
||||
NMObjBaseClass parent;
|
||||
const char * type_name;
|
||||
const char *(*get_name)(const NMMetaAbstractInfo *abstract_info, gboolean for_header);
|
||||
const NMMetaAbstractInfo *const *(*get_nested)(const NMMetaAbstractInfo *abstract_info,
|
||||
guint * out_len,
|
||||
gpointer * out_to_free);
|
||||
gconstpointer (*get_fcn)(const NMMetaAbstractInfo * info,
|
||||
const NMMetaEnvironment * environment,
|
||||
gpointer environment_user_data,
|
||||
gpointer target,
|
||||
gpointer target_data,
|
||||
NMMetaAccessorGetType get_type,
|
||||
NMMetaAccessorGetFlags get_flags,
|
||||
NMMetaAccessorGetOutFlags *out_flags,
|
||||
gboolean * out_is_default,
|
||||
gpointer * out_to_free);
|
||||
const char *const *(*complete_fcn)(const NMMetaAbstractInfo * info,
|
||||
const NMMetaEnvironment * environment,
|
||||
gpointer environment_user_data,
|
||||
const NMMetaOperationContext *operation_context,
|
||||
const char * text,
|
||||
gboolean * out_complete_filename,
|
||||
char *** out_to_free);
|
||||
};
|
||||
|
||||
struct _NMMetaAbstractInfo {
|
||||
union {
|
||||
NMObjBaseInst parent;
|
||||
const NMMetaType *meta_type;
|
||||
};
|
||||
union {
|
||||
NMObjBaseInst parent;
|
||||
const NMMetaType *meta_type;
|
||||
};
|
||||
};
|
||||
|
||||
extern const NMMetaType nm_meta_type_setting_info_editor;
|
||||
|
|
@ -468,13 +473,15 @@ extern const NMMetaSettingInfoEditor nm_meta_setting_infos_editor[_NM_META_SETTI
|
|||
|
||||
extern const NMMetaSettingValidPartItem *const nm_meta_setting_info_valid_parts_default[];
|
||||
|
||||
const NMMetaSettingValidPartItem *const*nm_meta_setting_info_valid_parts_for_slave_type (const char *slave_type, const char **out_slave_name);
|
||||
const NMMetaSettingValidPartItem *const *
|
||||
nm_meta_setting_info_valid_parts_for_slave_type(const char * slave_type,
|
||||
const char **out_slave_name);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef enum {
|
||||
NM_META_ENV_WARN_LEVEL_INFO,
|
||||
NM_META_ENV_WARN_LEVEL_WARN,
|
||||
NM_META_ENV_WARN_LEVEL_INFO,
|
||||
NM_META_ENV_WARN_LEVEL_WARN,
|
||||
} NMMetaEnvWarnLevel;
|
||||
|
||||
/* the settings-meta data is supposed to be independent of an actual client
|
||||
|
|
@ -482,21 +489,21 @@ typedef enum {
|
|||
* The meta-data handlers may call back to the environment with certain
|
||||
* actions. */
|
||||
struct _NMMetaEnvironment {
|
||||
void (*warn_fcn)(
|
||||
const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
NMMetaEnvWarnLevel warn_level,
|
||||
const char *
|
||||
fmt_l10n, /* the untranslated format string, but it is marked for translation using N_(). */
|
||||
va_list ap);
|
||||
|
||||
void (*warn_fcn) (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
NMMetaEnvWarnLevel warn_level,
|
||||
const char *fmt_l10n, /* the untranslated format string, but it is marked for translation using N_(). */
|
||||
va_list ap);
|
||||
|
||||
struct _NMDevice *const*(*get_nm_devices) (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
guint *out_len);
|
||||
|
||||
struct _NMRemoteConnection *const*(*get_nm_connections) (const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
guint *out_len);
|
||||
struct _NMDevice *const *(*get_nm_devices)(const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
guint * out_len);
|
||||
|
||||
struct _NMRemoteConnection *const *(*get_nm_connections)(const NMMetaEnvironment *environment,
|
||||
gpointer environment_user_data,
|
||||
guint * out_len);
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
@ -507,27 +514,27 @@ struct _NMMetaEnvironment {
|
|||
|
||||
extern const NMMetaType nm_meta_type_nested_property_info;
|
||||
|
||||
struct _NMMetaNestedPropertyInfo {
|
||||
union {
|
||||
const NMMetaType *meta_type;
|
||||
NMMetaPropertyInfo base;
|
||||
};
|
||||
const NMMetaPropertyInfo *parent_info;
|
||||
struct _NMMetaNestedPropertyInfo {
|
||||
union {
|
||||
const NMMetaType * meta_type;
|
||||
NMMetaPropertyInfo base;
|
||||
};
|
||||
const NMMetaPropertyInfo *parent_info;
|
||||
};
|
||||
|
||||
struct _NMMetaPropertyTypDataNested {
|
||||
const NMMetaNestedPropertyInfo *nested;
|
||||
guint nested_len;
|
||||
struct _NMMetaPropertyTypDataNested {
|
||||
const NMMetaNestedPropertyInfo *nested;
|
||||
guint nested_len;
|
||||
};
|
||||
|
||||
extern const NMMetaPropertyTypDataNested nm_meta_property_typ_data_bond;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
gboolean _nm_meta_setting_bond_add_option (NMSetting *setting,
|
||||
const char *name,
|
||||
const char *value,
|
||||
GError **error);
|
||||
gboolean _nm_meta_setting_bond_add_option(NMSetting * setting,
|
||||
const char *name,
|
||||
const char *value,
|
||||
GError ** error);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -6,24 +6,28 @@
|
|||
#ifndef __NM_POLKIT_LISTENER_H__
|
||||
#define __NM_POLKIT_LISTENER_H__
|
||||
|
||||
#define NM_POLKIT_LISTENER_SIGNAL_REGISTERED "registered"
|
||||
#define NM_POLKIT_LISTENER_SIGNAL_REQUEST_SYNC "request-sync"
|
||||
#define NM_POLKIT_LISTENER_SIGNAL_AUTH_SUCCESS "auth-success"
|
||||
#define NM_POLKIT_LISTENER_SIGNAL_AUTH_FAILURE "auth-failure"
|
||||
#define NM_POLKIT_LISTENER_SIGNAL_ERROR "error"
|
||||
#define NM_POLKIT_LISTENER_SIGNAL_REGISTERED "registered"
|
||||
#define NM_POLKIT_LISTENER_SIGNAL_REQUEST_SYNC "request-sync"
|
||||
#define NM_POLKIT_LISTENER_SIGNAL_AUTH_SUCCESS "auth-success"
|
||||
#define NM_POLKIT_LISTENER_SIGNAL_AUTH_FAILURE "auth-failure"
|
||||
#define NM_POLKIT_LISTENER_SIGNAL_ERROR "error"
|
||||
|
||||
typedef struct _NMPolkitListener NMPolkitListener;
|
||||
typedef struct _NMPolkitListener NMPolkitListener;
|
||||
typedef struct _NMPolkitListenerClass NMPolkitListenerClass;
|
||||
|
||||
#define NM_TYPE_POLKIT_LISTENER (nm_polkit_listener_get_type ())
|
||||
#define NM_POLKIT_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_POLKIT_LISTENER, NMPolkitListener))
|
||||
#define NM_POLKIT_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerClass))
|
||||
#define NM_IS_POLKIT_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_POLKIT_LISTENER))
|
||||
#define NM_IS_POLKIT_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_POLKIT_LISTENER))
|
||||
#define NM_POLKIT_LISTENER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerClass))
|
||||
#define NM_TYPE_POLKIT_LISTENER (nm_polkit_listener_get_type())
|
||||
#define NM_POLKIT_LISTENER(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_POLKIT_LISTENER, NMPolkitListener))
|
||||
#define NM_POLKIT_LISTENER_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerClass))
|
||||
#define NM_IS_POLKIT_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_POLKIT_LISTENER))
|
||||
#define NM_IS_POLKIT_LISTENER_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_POLKIT_LISTENER))
|
||||
#define NM_POLKIT_LISTENER_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerClass))
|
||||
|
||||
GType nm_polkit_listener_get_type (void);
|
||||
GType nm_polkit_listener_get_type(void);
|
||||
|
||||
NMPolkitListener *nm_polkit_listener_new (GDBusConnection *dbus_connection, gboolean session_agent);
|
||||
NMPolkitListener *nm_polkit_listener_new(GDBusConnection *dbus_connection, gboolean session_agent);
|
||||
|
||||
#endif /* __NM_POLKIT_LISTENER_H__ */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -9,49 +9,53 @@
|
|||
#include "nm-secret-agent-old.h"
|
||||
|
||||
typedef enum {
|
||||
NM_SECRET_AGENT_SECRET_TYPE_PROPERTY,
|
||||
NM_SECRET_AGENT_SECRET_TYPE_SECRET,
|
||||
NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET,
|
||||
NM_SECRET_AGENT_SECRET_TYPE_WIREGUARD_PEER_PSK,
|
||||
NM_SECRET_AGENT_SECRET_TYPE_PROPERTY,
|
||||
NM_SECRET_AGENT_SECRET_TYPE_SECRET,
|
||||
NM_SECRET_AGENT_SECRET_TYPE_VPN_SECRET,
|
||||
NM_SECRET_AGENT_SECRET_TYPE_WIREGUARD_PEER_PSK,
|
||||
} NMSecretAgentSecretType;
|
||||
|
||||
typedef struct {
|
||||
NMSecretAgentSecretType secret_type;
|
||||
const char *pretty_name;
|
||||
const char *entry_id;
|
||||
char *value;
|
||||
const char *vpn_type;
|
||||
bool is_secret:1;
|
||||
bool no_prompt_entry_id:1;
|
||||
NMSecretAgentSecretType secret_type;
|
||||
const char * pretty_name;
|
||||
const char * entry_id;
|
||||
char * value;
|
||||
const char * vpn_type;
|
||||
bool is_secret : 1;
|
||||
bool no_prompt_entry_id : 1;
|
||||
} NMSecretAgentSimpleSecret;
|
||||
|
||||
#define NM_SECRET_AGENT_ENTRY_ID_PREFX_VPN_SECRETS "vpn.secrets."
|
||||
|
||||
#define NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT NM_DBUS_INTERFACE".openconnect"
|
||||
#define NM_SECRET_AGENT_VPN_TYPE_OPENCONNECT NM_DBUS_INTERFACE ".openconnect"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define NM_TYPE_SECRET_AGENT_SIMPLE (nm_secret_agent_simple_get_type ())
|
||||
#define NM_SECRET_AGENT_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimple))
|
||||
#define NM_SECRET_AGENT_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass))
|
||||
#define NM_IS_SECRET_AGENT_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SECRET_AGENT_SIMPLE))
|
||||
#define NM_IS_SECRET_AGENT_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SECRET_AGENT_SIMPLE))
|
||||
#define NM_SECRET_AGENT_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass))
|
||||
#define NM_TYPE_SECRET_AGENT_SIMPLE (nm_secret_agent_simple_get_type())
|
||||
#define NM_SECRET_AGENT_SIMPLE(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimple))
|
||||
#define NM_SECRET_AGENT_SIMPLE_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass))
|
||||
#define NM_IS_SECRET_AGENT_SIMPLE(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_SECRET_AGENT_SIMPLE))
|
||||
#define NM_IS_SECRET_AGENT_SIMPLE_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_SECRET_AGENT_SIMPLE))
|
||||
#define NM_SECRET_AGENT_SIMPLE_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass))
|
||||
|
||||
#define NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS "request-secrets"
|
||||
#define NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS "request-secrets"
|
||||
|
||||
typedef struct _NMSecretAgentSimple NMSecretAgentSimple;
|
||||
typedef struct _NMSecretAgentSimpleClass NMSecretAgentSimpleClass;
|
||||
|
||||
GType nm_secret_agent_simple_get_type (void);
|
||||
GType nm_secret_agent_simple_get_type(void);
|
||||
|
||||
NMSecretAgentSimple *nm_secret_agent_simple_new (const char *name);
|
||||
NMSecretAgentSimple *nm_secret_agent_simple_new(const char *name);
|
||||
|
||||
void nm_secret_agent_simple_response (NMSecretAgentSimple *self,
|
||||
const char *request_id,
|
||||
GPtrArray *secrets);
|
||||
void nm_secret_agent_simple_response(NMSecretAgentSimple *self,
|
||||
const char * request_id,
|
||||
GPtrArray * secrets);
|
||||
|
||||
void nm_secret_agent_simple_enable (NMSecretAgentSimple *self,
|
||||
const char *path);
|
||||
void nm_secret_agent_simple_enable(NMSecretAgentSimple *self, const char *path);
|
||||
|
||||
#endif /* __NM_SECRET_AGENT_SIMPLE_H__ */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -7,26 +7,25 @@
|
|||
#define __NM_VPN_HELPERS_H__
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
const char *ui_name;
|
||||
const char *name;
|
||||
const char *ui_name;
|
||||
} NmcVpnPasswordName;
|
||||
|
||||
GSList *nm_vpn_get_plugin_infos (void);
|
||||
GSList *nm_vpn_get_plugin_infos(void);
|
||||
|
||||
NMVpnEditorPlugin *nm_vpn_get_editor_plugin (const char *service_type, GError **error);
|
||||
NMVpnEditorPlugin *nm_vpn_get_editor_plugin(const char *service_type, GError **error);
|
||||
|
||||
gboolean nm_vpn_supports_ipv6 (NMConnection *connection);
|
||||
gboolean nm_vpn_supports_ipv6(NMConnection *connection);
|
||||
|
||||
const NmcVpnPasswordName *nm_vpn_get_secret_names (const char *service_type);
|
||||
const NmcVpnPasswordName *nm_vpn_get_secret_names(const char *service_type);
|
||||
|
||||
gboolean nm_vpn_openconnect_authenticate_helper (const char *host,
|
||||
char **cookie,
|
||||
char **gateway,
|
||||
char **gwcert,
|
||||
int *status,
|
||||
GError **error);
|
||||
gboolean nm_vpn_openconnect_authenticate_helper(const char *host,
|
||||
char ** cookie,
|
||||
char ** gateway,
|
||||
char ** gwcert,
|
||||
int * status,
|
||||
GError ** error);
|
||||
|
||||
NMConnection *nm_vpn_wireguard_import (const char *filename,
|
||||
GError **error);
|
||||
NMConnection *nm_vpn_wireguard_import(const char *filename, GError **error);
|
||||
|
||||
#endif /* __NM_VPN_HELPERS_H__ */
|
||||
#endif /* __NM_VPN_HELPERS_H__ */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -27,12 +27,10 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* This library creates QR Code symbols, which is a type of two-dimension barcode.
|
||||
* Invented by Denso Wave and described in the ISO/IEC 18004 standard.
|
||||
|
|
@ -48,53 +46,49 @@ extern "C" {
|
|||
* (Note that all ways require supplying the desired error correction level and various byte buffers.)
|
||||
*/
|
||||
|
||||
|
||||
/*---- Enum and struct types----*/
|
||||
|
||||
/*
|
||||
* The error correction level in a QR Code symbol.
|
||||
*/
|
||||
enum qrcodegen_Ecc {
|
||||
// Must be declared in ascending order of error protection
|
||||
// so that an internal qrcodegen function works properly
|
||||
qrcodegen_Ecc_LOW = 0 , // The QR Code can tolerate about 7% erroneous codewords
|
||||
qrcodegen_Ecc_MEDIUM , // The QR Code can tolerate about 15% erroneous codewords
|
||||
qrcodegen_Ecc_QUARTILE, // The QR Code can tolerate about 25% erroneous codewords
|
||||
qrcodegen_Ecc_HIGH , // The QR Code can tolerate about 30% erroneous codewords
|
||||
// Must be declared in ascending order of error protection
|
||||
// so that an internal qrcodegen function works properly
|
||||
qrcodegen_Ecc_LOW = 0, // The QR Code can tolerate about 7% erroneous codewords
|
||||
qrcodegen_Ecc_MEDIUM, // The QR Code can tolerate about 15% erroneous codewords
|
||||
qrcodegen_Ecc_QUARTILE, // The QR Code can tolerate about 25% erroneous codewords
|
||||
qrcodegen_Ecc_HIGH, // The QR Code can tolerate about 30% erroneous codewords
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* The mask pattern used in a QR Code symbol.
|
||||
*/
|
||||
enum qrcodegen_Mask {
|
||||
// A special value to tell the QR Code encoder to
|
||||
// automatically select an appropriate mask pattern
|
||||
qrcodegen_Mask_AUTO = -1,
|
||||
// The eight actual mask patterns
|
||||
qrcodegen_Mask_0 = 0,
|
||||
qrcodegen_Mask_1,
|
||||
qrcodegen_Mask_2,
|
||||
qrcodegen_Mask_3,
|
||||
qrcodegen_Mask_4,
|
||||
qrcodegen_Mask_5,
|
||||
qrcodegen_Mask_6,
|
||||
qrcodegen_Mask_7,
|
||||
// A special value to tell the QR Code encoder to
|
||||
// automatically select an appropriate mask pattern
|
||||
qrcodegen_Mask_AUTO = -1,
|
||||
// The eight actual mask patterns
|
||||
qrcodegen_Mask_0 = 0,
|
||||
qrcodegen_Mask_1,
|
||||
qrcodegen_Mask_2,
|
||||
qrcodegen_Mask_3,
|
||||
qrcodegen_Mask_4,
|
||||
qrcodegen_Mask_5,
|
||||
qrcodegen_Mask_6,
|
||||
qrcodegen_Mask_7,
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Describes how a segment's data bits are interpreted.
|
||||
*/
|
||||
enum qrcodegen_Mode {
|
||||
qrcodegen_Mode_NUMERIC = 0x1,
|
||||
qrcodegen_Mode_ALPHANUMERIC = 0x2,
|
||||
qrcodegen_Mode_BYTE = 0x4,
|
||||
qrcodegen_Mode_KANJI = 0x8,
|
||||
qrcodegen_Mode_ECI = 0x7,
|
||||
qrcodegen_Mode_NUMERIC = 0x1,
|
||||
qrcodegen_Mode_ALPHANUMERIC = 0x2,
|
||||
qrcodegen_Mode_BYTE = 0x4,
|
||||
qrcodegen_Mode_KANJI = 0x8,
|
||||
qrcodegen_Mode_ECI = 0x7,
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* A segment of character/binary/control data in a QR Code symbol.
|
||||
* The mid-level way to create a segment is to take the payload data
|
||||
|
|
@ -107,43 +101,41 @@ enum qrcodegen_Mode {
|
|||
* the largest QR Code (version 40) has 31329 modules.
|
||||
*/
|
||||
struct qrcodegen_Segment {
|
||||
// The mode indicator of this segment.
|
||||
enum qrcodegen_Mode mode;
|
||||
// The mode indicator of this segment.
|
||||
enum qrcodegen_Mode mode;
|
||||
|
||||
// The length of this segment's unencoded data. Measured in characters for
|
||||
// numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode.
|
||||
// Always zero or positive. Not the same as the data's bit length.
|
||||
int numChars;
|
||||
// The length of this segment's unencoded data. Measured in characters for
|
||||
// numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode.
|
||||
// Always zero or positive. Not the same as the data's bit length.
|
||||
int numChars;
|
||||
|
||||
// The data bits of this segment, packed in bitwise big endian.
|
||||
// Can be null if the bit length is zero.
|
||||
uint8_t *data;
|
||||
// The data bits of this segment, packed in bitwise big endian.
|
||||
// Can be null if the bit length is zero.
|
||||
uint8_t *data;
|
||||
|
||||
// The number of valid data bits used in the buffer. Requires
|
||||
// 0 <= bitLength <= 32767, and bitLength <= (capacity of data array) * 8.
|
||||
// The character count (numChars) must agree with the mode and the bit buffer length.
|
||||
int bitLength;
|
||||
// The number of valid data bits used in the buffer. Requires
|
||||
// 0 <= bitLength <= 32767, and bitLength <= (capacity of data array) * 8.
|
||||
// The character count (numChars) must agree with the mode and the bit buffer length.
|
||||
int bitLength;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*---- Macro constants and functions ----*/
|
||||
|
||||
#define qrcodegen_VERSION_MIN 1 // The minimum version number supported in the QR Code Model 2 standard
|
||||
#define qrcodegen_VERSION_MAX 40 // The maximum version number supported in the QR Code Model 2 standard
|
||||
#define qrcodegen_VERSION_MIN \
|
||||
1 // The minimum version number supported in the QR Code Model 2 standard
|
||||
#define qrcodegen_VERSION_MAX \
|
||||
40 // The maximum version number supported in the QR Code Model 2 standard
|
||||
|
||||
// Calculates the number of bytes needed to store any QR Code up to and including the given version number,
|
||||
// as a compile-time constant. For example, 'uint8_t buffer[qrcodegen_BUFFER_LEN_FOR_VERSION(25)];'
|
||||
// can store any single QR Code from version 1 to 25 (inclusive). The result fits in an int (or int16).
|
||||
// Requires qrcodegen_VERSION_MIN <= n <= qrcodegen_VERSION_MAX.
|
||||
#define qrcodegen_BUFFER_LEN_FOR_VERSION(n) ((((n) * 4 + 17) * ((n) * 4 + 17) + 7) / 8 + 1)
|
||||
#define qrcodegen_BUFFER_LEN_FOR_VERSION(n) ((((n) *4 + 17) * ((n) *4 + 17) + 7) / 8 + 1)
|
||||
|
||||
// The worst-case number of bytes needed to store one QR Code, up to and including
|
||||
// version 40. This value equals 3918, which is just under 4 kilobytes.
|
||||
// Use this more convenient value to avoid calculating tighter memory bounds for buffers.
|
||||
#define qrcodegen_BUFFER_LEN_MAX qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX)
|
||||
|
||||
|
||||
#define qrcodegen_BUFFER_LEN_MAX qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX)
|
||||
|
||||
/*---- Functions (high level) to generate QR Codes ----*/
|
||||
|
||||
|
|
@ -166,9 +158,14 @@ struct qrcodegen_Segment {
|
|||
* - Please consult the QR Code specification for information on
|
||||
* data capacities per version, ECC level, and text encoding mode.
|
||||
*/
|
||||
bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[],
|
||||
enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl);
|
||||
|
||||
bool qrcodegen_encodeText(const char * text,
|
||||
uint8_t tempBuffer[],
|
||||
uint8_t qrcode[],
|
||||
enum qrcodegen_Ecc ecl,
|
||||
int minVersion,
|
||||
int maxVersion,
|
||||
enum qrcodegen_Mask mask,
|
||||
bool boostEcl);
|
||||
|
||||
/*
|
||||
* Encodes the given binary data to a QR Code, returning true if encoding succeeded.
|
||||
|
|
@ -188,9 +185,14 @@ bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode
|
|||
* - Please consult the QR Code specification for information on
|
||||
* data capacities per version, ECC level, and text encoding mode.
|
||||
*/
|
||||
bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcode[],
|
||||
enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl);
|
||||
|
||||
bool qrcodegen_encodeBinary(uint8_t dataAndTemp[],
|
||||
size_t dataLen,
|
||||
uint8_t qrcode[],
|
||||
enum qrcodegen_Ecc ecl,
|
||||
int minVersion,
|
||||
int maxVersion,
|
||||
enum qrcodegen_Mask mask,
|
||||
bool boostEcl);
|
||||
|
||||
/*---- Functions (low level) to generate QR Codes ----*/
|
||||
|
||||
|
|
@ -206,9 +208,11 @@ bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcod
|
|||
* result in them being clobbered, but the QR Code output will still be correct.
|
||||
* But the qrcode array must not overlap tempBuffer or any segment's data buffer.
|
||||
*/
|
||||
bool qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[], size_t len,
|
||||
enum qrcodegen_Ecc ecl, uint8_t tempBuffer[], uint8_t qrcode[]);
|
||||
|
||||
bool qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[],
|
||||
size_t len,
|
||||
enum qrcodegen_Ecc ecl,
|
||||
uint8_t tempBuffer[],
|
||||
uint8_t qrcode[]);
|
||||
|
||||
/*
|
||||
* Renders a QR Code representing the given segments with the given encoding parameters.
|
||||
|
|
@ -225,9 +229,15 @@ bool qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[], size_t len,
|
|||
* result in them being clobbered, but the QR Code output will still be correct.
|
||||
* But the qrcode array must not overlap tempBuffer or any segment's data buffer.
|
||||
*/
|
||||
bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], size_t len, enum qrcodegen_Ecc ecl,
|
||||
int minVersion, int maxVersion, int mask, bool boostEcl, uint8_t tempBuffer[], uint8_t qrcode[]);
|
||||
|
||||
bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[],
|
||||
size_t len,
|
||||
enum qrcodegen_Ecc ecl,
|
||||
int minVersion,
|
||||
int maxVersion,
|
||||
int mask,
|
||||
bool boostEcl,
|
||||
uint8_t tempBuffer[],
|
||||
uint8_t qrcode[]);
|
||||
|
||||
/*
|
||||
* Tests whether the given string can be encoded as a segment in alphanumeric mode.
|
||||
|
|
@ -236,14 +246,12 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz
|
|||
*/
|
||||
bool qrcodegen_isAlphanumeric(const char *text);
|
||||
|
||||
|
||||
/*
|
||||
* Tests whether the given string can be encoded as a segment in numeric mode.
|
||||
* A string is encodable iff each character is in the range 0 to 9.
|
||||
*/
|
||||
bool qrcodegen_isNumeric(const char *text);
|
||||
|
||||
|
||||
/*
|
||||
* Returns the number of bytes (uint8_t) needed for the data buffer of a segment
|
||||
* containing the given number of characters using the given mode. Notes:
|
||||
|
|
@ -257,7 +265,6 @@ bool qrcodegen_isNumeric(const char *text);
|
|||
*/
|
||||
size_t qrcodegen_calcSegmentBufferSize(enum qrcodegen_Mode mode, size_t numChars);
|
||||
|
||||
|
||||
/*
|
||||
* Returns a segment representing the given binary data encoded in
|
||||
* byte mode. All input byte arrays are acceptable. Any text string
|
||||
|
|
@ -265,13 +272,11 @@ size_t qrcodegen_calcSegmentBufferSize(enum qrcodegen_Mode mode, size_t numChars
|
|||
*/
|
||||
struct qrcodegen_Segment qrcodegen_makeBytes(const uint8_t data[], size_t len, uint8_t buf[]);
|
||||
|
||||
|
||||
/*
|
||||
* Returns a segment representing the given string of decimal digits encoded in numeric mode.
|
||||
*/
|
||||
struct qrcodegen_Segment qrcodegen_makeNumeric(const char *digits, uint8_t buf[]);
|
||||
|
||||
|
||||
/*
|
||||
* Returns a segment representing the given text string encoded in alphanumeric mode.
|
||||
* The characters allowed are: 0 to 9, A to Z (uppercase only), space,
|
||||
|
|
@ -279,14 +284,12 @@ struct qrcodegen_Segment qrcodegen_makeNumeric(const char *digits, uint8_t buf[]
|
|||
*/
|
||||
struct qrcodegen_Segment qrcodegen_makeAlphanumeric(const char *text, uint8_t buf[]);
|
||||
|
||||
|
||||
/*
|
||||
* Returns a segment representing an Extended Channel Interpretation
|
||||
* (ECI) designator with the given assignment value.
|
||||
*/
|
||||
struct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]);
|
||||
|
||||
|
||||
/*---- Functions to extract raw data from QR Codes ----*/
|
||||
|
||||
/*
|
||||
|
|
@ -297,7 +300,6 @@ struct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]);
|
|||
*/
|
||||
int qrcodegen_getSize(const uint8_t qrcode[]);
|
||||
|
||||
|
||||
/*
|
||||
* Returns the color of the module (pixel) at the given coordinates, which is false
|
||||
* for white or true for black. The top left corner has the coordinates (x=0, y=0).
|
||||
|
|
@ -305,7 +307,6 @@ int qrcodegen_getSize(const uint8_t qrcode[]);
|
|||
*/
|
||||
bool qrcodegen_getModule(const uint8_t qrcode[], int x, int y);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -14,313 +14,345 @@
|
|||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
test_client_meta_check (void)
|
||||
test_client_meta_check(void)
|
||||
{
|
||||
const NMMetaSettingInfoEditor *const*infos_p;
|
||||
NMMetaSettingType m;
|
||||
guint p;
|
||||
const NMMetaSettingInfoEditor *const *infos_p;
|
||||
NMMetaSettingType m;
|
||||
guint p;
|
||||
|
||||
G_STATIC_ASSERT (G_STRUCT_OFFSET (NMMetaAbstractInfo, meta_type) == G_STRUCT_OFFSET (NMMetaSettingInfoEditor, meta_type));
|
||||
G_STATIC_ASSERT (G_STRUCT_OFFSET (NMMetaAbstractInfo, meta_type) == G_STRUCT_OFFSET (NMMetaPropertyInfo, meta_type));
|
||||
G_STATIC_ASSERT(G_STRUCT_OFFSET(NMMetaAbstractInfo, meta_type)
|
||||
== G_STRUCT_OFFSET(NMMetaSettingInfoEditor, meta_type));
|
||||
G_STATIC_ASSERT(G_STRUCT_OFFSET(NMMetaAbstractInfo, meta_type)
|
||||
== G_STRUCT_OFFSET(NMMetaPropertyInfo, meta_type));
|
||||
|
||||
for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) {
|
||||
const NMMetaSettingInfo *info = &nm_meta_setting_infos[m];
|
||||
GType gtype;
|
||||
for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) {
|
||||
const NMMetaSettingInfo *info = &nm_meta_setting_infos[m];
|
||||
GType gtype;
|
||||
|
||||
g_assert (info);
|
||||
g_assert (info->meta_type == m);
|
||||
g_assert (info->setting_name);
|
||||
g_assert (info->get_setting_gtype);
|
||||
g_assert(info);
|
||||
g_assert(info->meta_type == m);
|
||||
g_assert(info->setting_name);
|
||||
g_assert(info->get_setting_gtype);
|
||||
|
||||
gtype = info->get_setting_gtype ();
|
||||
g_assert (gtype != NM_TYPE_SETTING);
|
||||
gtype = info->get_setting_gtype();
|
||||
g_assert(gtype != NM_TYPE_SETTING);
|
||||
|
||||
{
|
||||
nm_auto_unref_gtypeclass GTypeClass *gclass = g_type_class_ref (gtype);
|
||||
{
|
||||
nm_auto_unref_gtypeclass GTypeClass *gclass = g_type_class_ref(gtype);
|
||||
|
||||
g_assert (G_TYPE_CHECK_CLASS_TYPE (gclass, gtype));
|
||||
}
|
||||
{
|
||||
gs_unref_object NMSetting *setting = g_object_new (gtype, NULL);
|
||||
g_assert(G_TYPE_CHECK_CLASS_TYPE(gclass, gtype));
|
||||
}
|
||||
{
|
||||
gs_unref_object NMSetting *setting = g_object_new(gtype, NULL);
|
||||
|
||||
g_assert (NM_IS_SETTING (setting));
|
||||
g_assert (G_TYPE_CHECK_INSTANCE_TYPE (setting, gtype));
|
||||
g_assert_cmpstr (nm_setting_get_name (setting), ==, info->setting_name);
|
||||
}
|
||||
}
|
||||
g_assert(NM_IS_SETTING(setting));
|
||||
g_assert(G_TYPE_CHECK_INSTANCE_TYPE(setting, gtype));
|
||||
g_assert_cmpstr(nm_setting_get_name(setting), ==, info->setting_name);
|
||||
}
|
||||
}
|
||||
|
||||
for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) {
|
||||
const NMMetaSettingInfoEditor *info = &nm_meta_setting_infos_editor[m];
|
||||
for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) {
|
||||
const NMMetaSettingInfoEditor *info = &nm_meta_setting_infos_editor[m];
|
||||
|
||||
g_assert (info);
|
||||
g_assert (info->meta_type == &nm_meta_type_setting_info_editor);
|
||||
g_assert (info->general);
|
||||
g_assert (info->general == &nm_meta_setting_infos[m]);
|
||||
g_assert(info);
|
||||
g_assert(info->meta_type == &nm_meta_type_setting_info_editor);
|
||||
g_assert(info->general);
|
||||
g_assert(info->general == &nm_meta_setting_infos[m]);
|
||||
|
||||
g_assert_cmpstr (info->general->setting_name, ==, info->meta_type->get_name ((const NMMetaAbstractInfo *) info, FALSE));
|
||||
g_assert_cmpstr ("name", ==, info->meta_type->get_name ((const NMMetaAbstractInfo *) info, TRUE));
|
||||
g_assert_cmpstr(info->general->setting_name,
|
||||
==,
|
||||
info->meta_type->get_name((const NMMetaAbstractInfo *) info, FALSE));
|
||||
g_assert_cmpstr("name",
|
||||
==,
|
||||
info->meta_type->get_name((const NMMetaAbstractInfo *) info, TRUE));
|
||||
|
||||
g_assert (info->properties_num == NM_PTRARRAY_LEN (info->properties));
|
||||
g_assert(info->properties_num == NM_PTRARRAY_LEN(info->properties));
|
||||
|
||||
if (info->properties_num) {
|
||||
gs_unref_hashtable GHashTable *property_names = g_hash_table_new (nm_str_hash, g_str_equal);
|
||||
if (info->properties_num) {
|
||||
gs_unref_hashtable GHashTable *property_names =
|
||||
g_hash_table_new(nm_str_hash, g_str_equal);
|
||||
|
||||
g_assert (info->properties);
|
||||
for (p = 0; p < info->properties_num; p++) {
|
||||
const NMMetaPropertyInfo *pi = info->properties[p];
|
||||
g_assert(info->properties);
|
||||
for (p = 0; p < info->properties_num; p++) {
|
||||
const NMMetaPropertyInfo *pi = info->properties[p];
|
||||
|
||||
g_assert (pi);
|
||||
g_assert (pi->meta_type == &nm_meta_type_property_info);
|
||||
g_assert (pi->setting_info == info);
|
||||
g_assert (pi->property_name);
|
||||
g_assert(pi);
|
||||
g_assert(pi->meta_type == &nm_meta_type_property_info);
|
||||
g_assert(pi->setting_info == info);
|
||||
g_assert(pi->property_name);
|
||||
|
||||
g_assert (g_hash_table_add (property_names, (gpointer) pi->property_name));
|
||||
g_assert(g_hash_table_add(property_names, (gpointer) pi->property_name));
|
||||
|
||||
g_assert_cmpstr (pi->property_name, ==, pi->meta_type->get_name ((const NMMetaAbstractInfo *) pi, FALSE));
|
||||
g_assert_cmpstr (pi->property_name, ==, pi->meta_type->get_name ((const NMMetaAbstractInfo *) pi, TRUE));
|
||||
g_assert_cmpstr(pi->property_name,
|
||||
==,
|
||||
pi->meta_type->get_name((const NMMetaAbstractInfo *) pi, FALSE));
|
||||
g_assert_cmpstr(pi->property_name,
|
||||
==,
|
||||
pi->meta_type->get_name((const NMMetaAbstractInfo *) pi, TRUE));
|
||||
|
||||
g_assert (pi->property_type);
|
||||
g_assert (pi->property_type->get_fcn);
|
||||
}
|
||||
g_assert (!info->properties[info->properties_num]);
|
||||
} else
|
||||
g_assert (!info->properties);
|
||||
g_assert(pi->property_type);
|
||||
g_assert(pi->property_type->get_fcn);
|
||||
}
|
||||
g_assert(!info->properties[info->properties_num]);
|
||||
} else
|
||||
g_assert(!info->properties);
|
||||
|
||||
if (info->valid_parts) {
|
||||
gsize i, l;
|
||||
gs_unref_hashtable GHashTable *dup = g_hash_table_new (nm_direct_hash, NULL);
|
||||
if (info->valid_parts) {
|
||||
gsize i, l;
|
||||
gs_unref_hashtable GHashTable *dup = g_hash_table_new(nm_direct_hash, NULL);
|
||||
|
||||
l = NM_PTRARRAY_LEN (info->valid_parts);
|
||||
g_assert (l >= 2);
|
||||
l = NM_PTRARRAY_LEN(info->valid_parts);
|
||||
g_assert(l >= 2);
|
||||
|
||||
for (i = 0; info->valid_parts[i]; i++) {
|
||||
g_assert (info->valid_parts[i]->setting_info);
|
||||
g_assert (g_hash_table_add (dup, (gpointer) info->valid_parts[i]->setting_info));
|
||||
for (i = 0; info->valid_parts[i]; i++) {
|
||||
g_assert(info->valid_parts[i]->setting_info);
|
||||
g_assert(g_hash_table_add(dup, (gpointer) info->valid_parts[i]->setting_info));
|
||||
|
||||
if (i == 0) {
|
||||
g_assert (info->valid_parts[i]->setting_info == &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_CONNECTION]);
|
||||
g_assert (info->valid_parts[i]->mandatory);
|
||||
}
|
||||
if (i == 1) {
|
||||
g_assert (info->valid_parts[i]->setting_info == &nm_meta_setting_infos_editor[m]);
|
||||
g_assert (info->valid_parts[i]->mandatory);
|
||||
}
|
||||
}
|
||||
g_assert (i == l);
|
||||
}
|
||||
}
|
||||
if (i == 0) {
|
||||
g_assert(info->valid_parts[i]->setting_info
|
||||
== &nm_meta_setting_infos_editor[NM_META_SETTING_TYPE_CONNECTION]);
|
||||
g_assert(info->valid_parts[i]->mandatory);
|
||||
}
|
||||
if (i == 1) {
|
||||
g_assert(info->valid_parts[i]->setting_info
|
||||
== &nm_meta_setting_infos_editor[m]);
|
||||
g_assert(info->valid_parts[i]->mandatory);
|
||||
}
|
||||
}
|
||||
g_assert(i == l);
|
||||
}
|
||||
}
|
||||
|
||||
for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) {
|
||||
const NMMetaSettingInfoEditor *info = &nm_meta_setting_infos_editor[m];
|
||||
for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++) {
|
||||
const NMMetaSettingInfoEditor *info = &nm_meta_setting_infos_editor[m];
|
||||
|
||||
g_assert (nm_meta_setting_info_editor_find_by_name (info->general->setting_name, FALSE) == info);
|
||||
g_assert (nm_meta_setting_info_editor_find_by_gtype (info->general->get_setting_gtype ()) == info);
|
||||
g_assert(nm_meta_setting_info_editor_find_by_name(info->general->setting_name, FALSE)
|
||||
== info);
|
||||
g_assert(nm_meta_setting_info_editor_find_by_gtype(info->general->get_setting_gtype())
|
||||
== info);
|
||||
|
||||
for (p = 0; p < info->properties_num; p++) {
|
||||
const NMMetaPropertyInfo *pi = info->properties[p];
|
||||
for (p = 0; p < info->properties_num; p++) {
|
||||
const NMMetaPropertyInfo *pi = info->properties[p];
|
||||
|
||||
g_assert (nm_meta_setting_info_editor_get_property_info (info, pi->property_name) == pi);
|
||||
g_assert (nm_meta_property_info_find_by_name (info->general->setting_name, pi->property_name) == pi);
|
||||
}
|
||||
}
|
||||
g_assert(nm_meta_setting_info_editor_get_property_info(info, pi->property_name) == pi);
|
||||
g_assert(
|
||||
nm_meta_property_info_find_by_name(info->general->setting_name, pi->property_name)
|
||||
== pi);
|
||||
}
|
||||
}
|
||||
|
||||
infos_p = nm_meta_setting_infos_editor_p ();
|
||||
g_assert (infos_p);
|
||||
for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++)
|
||||
g_assert (infos_p[m] == &nm_meta_setting_infos_editor[m]);
|
||||
g_assert (!infos_p[m]);
|
||||
infos_p = nm_meta_setting_infos_editor_p();
|
||||
g_assert(infos_p);
|
||||
for (m = 0; m < _NM_META_SETTING_TYPE_NUM; m++)
|
||||
g_assert(infos_p[m] == &nm_meta_setting_infos_editor[m]);
|
||||
g_assert(!infos_p[m]);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
test_client_import_wireguard_test0 (void)
|
||||
test_client_import_wireguard_test0(void)
|
||||
{
|
||||
gs_unref_object NMConnection *connection;
|
||||
NMSettingWireGuard *s_wg;
|
||||
NMSettingIPConfig *s_ip4;
|
||||
NMSettingIPConfig *s_ip6;
|
||||
NMWireGuardPeer *peer;
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_unref_object NMConnection *connection;
|
||||
NMSettingWireGuard * s_wg;
|
||||
NMSettingIPConfig * s_ip4;
|
||||
NMSettingIPConfig * s_ip6;
|
||||
NMWireGuardPeer * peer;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
connection = nm_vpn_wireguard_import (NM_BUILD_SRCDIR"/clients/common/tests/wg-test0.conf",
|
||||
&error);
|
||||
connection =
|
||||
nm_vpn_wireguard_import(NM_BUILD_SRCDIR "/clients/common/tests/wg-test0.conf", &error);
|
||||
|
||||
g_assert_no_error (error);
|
||||
g_assert_no_error(error);
|
||||
|
||||
g_assert_cmpstr (nm_connection_get_id (connection), ==, "wg-test0");
|
||||
g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "wg-test0");
|
||||
g_assert_cmpstr (nm_connection_get_connection_type (connection), ==, NM_SETTING_WIREGUARD_SETTING_NAME);
|
||||
g_assert_cmpstr(nm_connection_get_id(connection), ==, "wg-test0");
|
||||
g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "wg-test0");
|
||||
g_assert_cmpstr(nm_connection_get_connection_type(connection),
|
||||
==,
|
||||
NM_SETTING_WIREGUARD_SETTING_NAME);
|
||||
|
||||
s_wg = NM_SETTING_WIREGUARD (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIREGUARD));
|
||||
s_wg = NM_SETTING_WIREGUARD(nm_connection_get_setting(connection, NM_TYPE_SETTING_WIREGUARD));
|
||||
|
||||
g_assert_cmpint (nm_setting_wireguard_get_listen_port (s_wg), ==, 51820);
|
||||
g_assert_cmpstr (nm_setting_wireguard_get_private_key (s_wg), ==, "yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=");
|
||||
g_assert_cmpint(nm_setting_wireguard_get_listen_port(s_wg), ==, 51820);
|
||||
g_assert_cmpstr(nm_setting_wireguard_get_private_key(s_wg),
|
||||
==,
|
||||
"yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=");
|
||||
|
||||
g_assert_cmpint (nm_setting_wireguard_get_peers_len (s_wg), ==, 3);
|
||||
g_assert_cmpint(nm_setting_wireguard_get_peers_len(s_wg), ==, 3);
|
||||
|
||||
peer = nm_setting_wireguard_get_peer (s_wg, 0);
|
||||
g_assert_cmpstr (nm_wireguard_peer_get_public_key (peer), ==, "xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=");
|
||||
g_assert_cmpstr (nm_wireguard_peer_get_endpoint (peer), ==, "192.95.5.67:1234");
|
||||
g_assert_cmpint (nm_wireguard_peer_get_allowed_ips_len (peer), ==, 2);
|
||||
g_assert_cmpstr (nm_wireguard_peer_get_allowed_ip (peer, 0, NULL), ==, "10.192.122.3/32");
|
||||
g_assert_cmpstr (nm_wireguard_peer_get_allowed_ip (peer, 1, NULL), ==, "10.192.124.1/24");
|
||||
peer = nm_setting_wireguard_get_peer(s_wg, 0);
|
||||
g_assert_cmpstr(nm_wireguard_peer_get_public_key(peer),
|
||||
==,
|
||||
"xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=");
|
||||
g_assert_cmpstr(nm_wireguard_peer_get_endpoint(peer), ==, "192.95.5.67:1234");
|
||||
g_assert_cmpint(nm_wireguard_peer_get_allowed_ips_len(peer), ==, 2);
|
||||
g_assert_cmpstr(nm_wireguard_peer_get_allowed_ip(peer, 0, NULL), ==, "10.192.122.3/32");
|
||||
g_assert_cmpstr(nm_wireguard_peer_get_allowed_ip(peer, 1, NULL), ==, "10.192.124.1/24");
|
||||
|
||||
peer = nm_setting_wireguard_get_peer (s_wg, 1);
|
||||
g_assert_cmpstr (nm_wireguard_peer_get_public_key (peer), ==, "TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0=");
|
||||
g_assert_cmpstr (nm_wireguard_peer_get_endpoint (peer), ==, "[2607:5300:60:6b0::c05f:543]:2468");
|
||||
g_assert_cmpint (nm_wireguard_peer_get_allowed_ips_len (peer), ==, 2);
|
||||
g_assert_cmpstr (nm_wireguard_peer_get_allowed_ip (peer, 0, NULL), ==, "10.192.122.4/32");
|
||||
g_assert_cmpstr (nm_wireguard_peer_get_allowed_ip (peer, 1, NULL), ==, "192.168.0.0/16");
|
||||
peer = nm_setting_wireguard_get_peer(s_wg, 1);
|
||||
g_assert_cmpstr(nm_wireguard_peer_get_public_key(peer),
|
||||
==,
|
||||
"TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0=");
|
||||
g_assert_cmpstr(nm_wireguard_peer_get_endpoint(peer), ==, "[2607:5300:60:6b0::c05f:543]:2468");
|
||||
g_assert_cmpint(nm_wireguard_peer_get_allowed_ips_len(peer), ==, 2);
|
||||
g_assert_cmpstr(nm_wireguard_peer_get_allowed_ip(peer, 0, NULL), ==, "10.192.122.4/32");
|
||||
g_assert_cmpstr(nm_wireguard_peer_get_allowed_ip(peer, 1, NULL), ==, "192.168.0.0/16");
|
||||
|
||||
peer = nm_setting_wireguard_get_peer (s_wg, 2);
|
||||
g_assert_cmpstr (nm_wireguard_peer_get_public_key (peer), ==, "gN65BkIKy1eCE9pP1wdc8ROUtkHLF2PfAqYdyYBz6EA=");
|
||||
g_assert_cmpstr (nm_wireguard_peer_get_endpoint (peer), ==, "test.wireguard.com:18981");
|
||||
g_assert_cmpint (nm_wireguard_peer_get_allowed_ips_len (peer), ==, 1);
|
||||
g_assert_cmpstr (nm_wireguard_peer_get_allowed_ip (peer, 0, NULL), ==, "10.10.10.230/32");
|
||||
peer = nm_setting_wireguard_get_peer(s_wg, 2);
|
||||
g_assert_cmpstr(nm_wireguard_peer_get_public_key(peer),
|
||||
==,
|
||||
"gN65BkIKy1eCE9pP1wdc8ROUtkHLF2PfAqYdyYBz6EA=");
|
||||
g_assert_cmpstr(nm_wireguard_peer_get_endpoint(peer), ==, "test.wireguard.com:18981");
|
||||
g_assert_cmpint(nm_wireguard_peer_get_allowed_ips_len(peer), ==, 1);
|
||||
g_assert_cmpstr(nm_wireguard_peer_get_allowed_ip(peer, 0, NULL), ==, "10.10.10.230/32");
|
||||
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
s_ip6 = nm_connection_get_setting_ip6_config (connection);
|
||||
s_ip4 = nm_connection_get_setting_ip4_config(connection);
|
||||
s_ip6 = nm_connection_get_setting_ip6_config(connection);
|
||||
|
||||
g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1);
|
||||
g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip6), ==, 0);
|
||||
g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip4), ==, 1);
|
||||
g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip6), ==, 0);
|
||||
|
||||
g_assert_cmpint (nm_setting_ip_config_get_num_dns_searches (s_ip4), ==, 1);
|
||||
g_assert_cmpint (nm_setting_ip_config_get_num_dns_searches (s_ip6), ==, 0);
|
||||
g_assert_cmpint(nm_setting_ip_config_get_num_dns_searches(s_ip4), ==, 1);
|
||||
g_assert_cmpint(nm_setting_ip_config_get_num_dns_searches(s_ip6), ==, 0);
|
||||
|
||||
g_assert_cmpstr (nm_setting_ip_config_get_dns_search (s_ip4, 0), ==, "~");
|
||||
g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip4, 0), ==, "~");
|
||||
}
|
||||
|
||||
static void
|
||||
test_client_import_wireguard_test1 (void)
|
||||
test_client_import_wireguard_test1(void)
|
||||
{
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
nm_vpn_wireguard_import (NM_BUILD_SRCDIR"/clients/common/tests/wg-test1.conf", &error);
|
||||
g_assert_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT);
|
||||
g_assert (g_str_has_prefix (error->message, "invalid secret 'PrivateKey'"));
|
||||
g_assert (g_str_has_suffix (error->message, "wg-test1.conf:2"));
|
||||
nm_vpn_wireguard_import(NM_BUILD_SRCDIR "/clients/common/tests/wg-test1.conf", &error);
|
||||
g_assert_error(error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT);
|
||||
g_assert(g_str_has_prefix(error->message, "invalid secret 'PrivateKey'"));
|
||||
g_assert(g_str_has_suffix(error->message, "wg-test1.conf:2"));
|
||||
}
|
||||
|
||||
static void
|
||||
test_client_import_wireguard_test2 (void)
|
||||
test_client_import_wireguard_test2(void)
|
||||
{
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
nm_vpn_wireguard_import (NM_BUILD_SRCDIR"/clients/common/tests/wg-test2.conf", &error);
|
||||
nm_vpn_wireguard_import(NM_BUILD_SRCDIR "/clients/common/tests/wg-test2.conf", &error);
|
||||
|
||||
g_assert_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT);
|
||||
g_assert (g_str_has_prefix (error->message, "unrecognized line at"));
|
||||
g_assert (g_str_has_suffix (error->message, "wg-test2.conf:5"));
|
||||
g_assert_error(error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT);
|
||||
g_assert(g_str_has_prefix(error->message, "unrecognized line at"));
|
||||
g_assert(g_str_has_suffix(error->message, "wg-test2.conf:5"));
|
||||
}
|
||||
|
||||
static void
|
||||
test_client_import_wireguard_test3 (void)
|
||||
test_client_import_wireguard_test3(void)
|
||||
{
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
nm_vpn_wireguard_import (NM_BUILD_SRCDIR"/clients/common/tests/wg-test3.conf", &error);
|
||||
g_assert_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT);
|
||||
g_assert (g_str_has_prefix (error->message, "invalid value for 'ListenPort'"));
|
||||
g_assert (g_str_has_suffix (error->message, "wg-test3.conf:3"));
|
||||
nm_vpn_wireguard_import(NM_BUILD_SRCDIR "/clients/common/tests/wg-test3.conf", &error);
|
||||
g_assert_error(error, NM_UTILS_ERROR, NM_UTILS_ERROR_INVALID_ARGUMENT);
|
||||
g_assert(g_str_has_prefix(error->message, "invalid value for 'ListenPort'"));
|
||||
g_assert(g_str_has_suffix(error->message, "wg-test3.conf:3"));
|
||||
}
|
||||
|
||||
static void
|
||||
test_client_import_wireguard_missing (void)
|
||||
test_client_import_wireguard_missing(void)
|
||||
{
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
nm_vpn_wireguard_import (NM_BUILD_SRCDIR"/clients/common/tests/wg-missing.conf", &error);
|
||||
g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
|
||||
nm_vpn_wireguard_import(NM_BUILD_SRCDIR "/clients/common/tests/wg-missing.conf", &error);
|
||||
g_assert_error(error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define _do_test_parse_passwd_file(contents, success, exp_error_line, ...) \
|
||||
G_STMT_START { \
|
||||
static const NMUtilsNamedValue _values[] = { \
|
||||
__VA_ARGS__ \
|
||||
}; \
|
||||
gs_free char *_contents = g_strndup (contents, NM_STRLEN (contents)); \
|
||||
gs_unref_hashtable GHashTable *_secrets = NULL; \
|
||||
gs_free_error GError *_local = NULL; \
|
||||
gssize _error_line; \
|
||||
GError **_p_local = nmtst_get_rand_bool () ? &_local : NULL; \
|
||||
gssize *_p_error_line = nmtst_get_rand_bool () ? &_error_line : NULL; \
|
||||
gboolean _success = !!(success); \
|
||||
gssize _exp_error_line = (exp_error_line); \
|
||||
int _i; \
|
||||
\
|
||||
g_assert (_success || (G_N_ELEMENTS (_values) == 0)); \
|
||||
\
|
||||
_secrets = nmc_utils_parse_passwd_file (_contents, _p_error_line, _p_local); \
|
||||
\
|
||||
g_assert (_success == (!!_secrets)); \
|
||||
if (!_success) { \
|
||||
if (_p_error_line) \
|
||||
g_assert_cmpint (_exp_error_line, ==, *_p_error_line); \
|
||||
if (_p_local) \
|
||||
g_assert (_local); \
|
||||
} else { \
|
||||
if (_p_error_line) \
|
||||
g_assert_cmpint (-1, ==, *_p_error_line); \
|
||||
g_assert (!_local); \
|
||||
\
|
||||
for (_i = 0; _i < G_N_ELEMENTS (_values); _i++) { \
|
||||
const NMUtilsNamedValue *_n = &_values[_i]; \
|
||||
const char *_v; \
|
||||
\
|
||||
_v = g_hash_table_lookup (_secrets, _n->name); \
|
||||
if (!_v) \
|
||||
g_error ("cannot find key \"%s\"", _n->name); \
|
||||
g_assert_cmpstr (_v, ==, _n->value_str); \
|
||||
} \
|
||||
\
|
||||
g_assert_cmpint (g_hash_table_size (_secrets), ==, G_N_ELEMENTS (_values)); \
|
||||
} \
|
||||
} G_STMT_END
|
||||
#define _do_test_parse_passwd_file(contents, success, exp_error_line, ...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
static const NMUtilsNamedValue _values[] = {__VA_ARGS__}; \
|
||||
gs_free char * _contents = g_strndup(contents, NM_STRLEN(contents)); \
|
||||
gs_unref_hashtable GHashTable *_secrets = NULL; \
|
||||
gs_free_error GError *_local = NULL; \
|
||||
gssize _error_line; \
|
||||
GError ** _p_local = nmtst_get_rand_bool() ? &_local : NULL; \
|
||||
gssize * _p_error_line = nmtst_get_rand_bool() ? &_error_line : NULL; \
|
||||
gboolean _success = !!(success); \
|
||||
gssize _exp_error_line = (exp_error_line); \
|
||||
int _i; \
|
||||
\
|
||||
g_assert(_success || (G_N_ELEMENTS(_values) == 0)); \
|
||||
\
|
||||
_secrets = nmc_utils_parse_passwd_file(_contents, _p_error_line, _p_local); \
|
||||
\
|
||||
g_assert(_success == (!!_secrets)); \
|
||||
if (!_success) { \
|
||||
if (_p_error_line) \
|
||||
g_assert_cmpint(_exp_error_line, ==, *_p_error_line); \
|
||||
if (_p_local) \
|
||||
g_assert(_local); \
|
||||
} else { \
|
||||
if (_p_error_line) \
|
||||
g_assert_cmpint(-1, ==, *_p_error_line); \
|
||||
g_assert(!_local); \
|
||||
\
|
||||
for (_i = 0; _i < G_N_ELEMENTS(_values); _i++) { \
|
||||
const NMUtilsNamedValue *_n = &_values[_i]; \
|
||||
const char * _v; \
|
||||
\
|
||||
_v = g_hash_table_lookup(_secrets, _n->name); \
|
||||
if (!_v) \
|
||||
g_error("cannot find key \"%s\"", _n->name); \
|
||||
g_assert_cmpstr(_v, ==, _n->value_str); \
|
||||
} \
|
||||
\
|
||||
g_assert_cmpint(g_hash_table_size(_secrets), ==, G_N_ELEMENTS(_values)); \
|
||||
} \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
#define _do_test_parse_passwd_file_bad( contents, exp_error_line) _do_test_parse_passwd_file (contents, FALSE, exp_error_line)
|
||||
#define _do_test_parse_passwd_file_good(contents, ...) _do_test_parse_passwd_file (contents, TRUE, -1, __VA_ARGS__)
|
||||
#define _do_test_parse_passwd_file_bad(contents, exp_error_line) \
|
||||
_do_test_parse_passwd_file(contents, FALSE, exp_error_line)
|
||||
#define _do_test_parse_passwd_file_good(contents, ...) \
|
||||
_do_test_parse_passwd_file(contents, TRUE, -1, __VA_ARGS__)
|
||||
|
||||
static void
|
||||
test_nmc_utils_parse_passwd_file (void)
|
||||
test_nmc_utils_parse_passwd_file(void)
|
||||
{
|
||||
_do_test_parse_passwd_file_good ("");
|
||||
_do_test_parse_passwd_file_bad ("x", 1);
|
||||
_do_test_parse_passwd_file_bad ("\r\rx", 3);
|
||||
_do_test_parse_passwd_file_good ("wifi.psk=abc",
|
||||
NM_UTILS_NAMED_VALUE_INIT ("802-11-wireless-security.psk", "abc") );
|
||||
_do_test_parse_passwd_file_good ("wifi.psk:ABC\r"
|
||||
"wifi-sec.psk = abc ",
|
||||
NM_UTILS_NAMED_VALUE_INIT ("802-11-wireless-security.psk", "abc") );
|
||||
_do_test_parse_passwd_file_good ("wifi.psk: abc\r"
|
||||
"wifi-sec.psk2 = d\\145f\r\n"
|
||||
" wifi.psk3 = e\\ \n"
|
||||
" #wifi-sec.psk2 = \r\n"
|
||||
" wifi-sec.psk4:",
|
||||
NM_UTILS_NAMED_VALUE_INIT ("802-11-wireless-security.psk", "abc"),
|
||||
NM_UTILS_NAMED_VALUE_INIT ("802-11-wireless-security.psk2", "def"),
|
||||
NM_UTILS_NAMED_VALUE_INIT ("802-11-wireless-security.psk3", "e "),
|
||||
NM_UTILS_NAMED_VALUE_INIT ("802-11-wireless-security.psk4", "") );
|
||||
_do_test_parse_passwd_file_good("");
|
||||
_do_test_parse_passwd_file_bad("x", 1);
|
||||
_do_test_parse_passwd_file_bad("\r\rx", 3);
|
||||
_do_test_parse_passwd_file_good(
|
||||
"wifi.psk=abc",
|
||||
NM_UTILS_NAMED_VALUE_INIT("802-11-wireless-security.psk", "abc"));
|
||||
_do_test_parse_passwd_file_good(
|
||||
"wifi.psk:ABC\r"
|
||||
"wifi-sec.psk = abc ",
|
||||
NM_UTILS_NAMED_VALUE_INIT("802-11-wireless-security.psk", "abc"));
|
||||
_do_test_parse_passwd_file_good(
|
||||
"wifi.psk: abc\r"
|
||||
"wifi-sec.psk2 = d\\145f\r\n"
|
||||
" wifi.psk3 = e\\ \n"
|
||||
" #wifi-sec.psk2 = \r\n"
|
||||
" wifi-sec.psk4:",
|
||||
NM_UTILS_NAMED_VALUE_INIT("802-11-wireless-security.psk", "abc"),
|
||||
NM_UTILS_NAMED_VALUE_INIT("802-11-wireless-security.psk2", "def"),
|
||||
NM_UTILS_NAMED_VALUE_INIT("802-11-wireless-security.psk3", "e "),
|
||||
NM_UTILS_NAMED_VALUE_INIT("802-11-wireless-security.psk4", ""));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMTST_DEFINE ();
|
||||
NMTST_DEFINE();
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
nmtst_init (&argc, &argv, TRUE);
|
||||
nmtst_init(&argc, &argv, TRUE);
|
||||
|
||||
g_test_add_func ("/client/meta/check", test_client_meta_check);
|
||||
g_test_add_func ("/client/import/wireguard/test0", test_client_import_wireguard_test0);
|
||||
g_test_add_func ("/client/import/wireguard/test1", test_client_import_wireguard_test1);
|
||||
g_test_add_func ("/client/import/wireguard/test2", test_client_import_wireguard_test2);
|
||||
g_test_add_func ("/client/import/wireguard/test3", test_client_import_wireguard_test3);
|
||||
g_test_add_func ("/client/import/wireguard/missing", test_client_import_wireguard_missing);
|
||||
g_test_add_func ("/client/test_nmc_utils_parse_passwd_file", test_nmc_utils_parse_passwd_file);
|
||||
g_test_add_func("/client/meta/check", test_client_meta_check);
|
||||
g_test_add_func("/client/import/wireguard/test0", test_client_import_wireguard_test0);
|
||||
g_test_add_func("/client/import/wireguard/test1", test_client_import_wireguard_test1);
|
||||
g_test_add_func("/client/import/wireguard/test2", test_client_import_wireguard_test2);
|
||||
g_test_add_func("/client/import/wireguard/test3", test_client_import_wireguard_test3);
|
||||
g_test_add_func("/client/import/wireguard/missing", test_client_import_wireguard_missing);
|
||||
g_test_add_func("/client/test_nmc_utils_parse_passwd_file", test_nmc_utils_parse_passwd_file);
|
||||
|
||||
return g_test_run ();
|
||||
return g_test_run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,224 +13,238 @@
|
|||
/*****************************************************************************/
|
||||
|
||||
static NMTeamLinkWatcher *
|
||||
_team_link_watcher_from_string_impl (const char *str, gsize nextra, const char *const*vextra)
|
||||
_team_link_watcher_from_string_impl(const char *str, gsize nextra, const char *const *vextra)
|
||||
{
|
||||
NMTeamLinkWatcher *watcher;
|
||||
gs_free char *str1_free = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
gsize i;
|
||||
NMTeamLinkWatcher *watcher;
|
||||
gs_free char * str1_free = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
gsize i;
|
||||
|
||||
g_assert (str);
|
||||
g_assert(str);
|
||||
|
||||
watcher = nm_utils_team_link_watcher_from_string (str, &error);
|
||||
nmtst_assert_success (watcher, error);
|
||||
watcher = nm_utils_team_link_watcher_from_string(str, &error);
|
||||
nmtst_assert_success(watcher, error);
|
||||
|
||||
for (i = 0; i < 1 + nextra; i++) {
|
||||
nm_auto_unref_team_link_watcher NMTeamLinkWatcher *watcher1 = NULL;
|
||||
const char *str1;
|
||||
for (i = 0; i < 1 + nextra; i++) {
|
||||
nm_auto_unref_team_link_watcher NMTeamLinkWatcher *watcher1 = NULL;
|
||||
const char * str1;
|
||||
|
||||
if (i == 0) {
|
||||
str1_free = nm_utils_team_link_watcher_to_string (watcher);
|
||||
g_assert (str1_free);
|
||||
str1 = str1_free;
|
||||
g_assert_cmpstr (str, ==, str1);
|
||||
} else
|
||||
str1 = vextra[i - 1];
|
||||
if (i == 0) {
|
||||
str1_free = nm_utils_team_link_watcher_to_string(watcher);
|
||||
g_assert(str1_free);
|
||||
str1 = str1_free;
|
||||
g_assert_cmpstr(str, ==, str1);
|
||||
} else
|
||||
str1 = vextra[i - 1];
|
||||
|
||||
watcher1 = nm_utils_team_link_watcher_from_string (str1, &error);
|
||||
nmtst_assert_success (watcher1, error);
|
||||
if (!nm_team_link_watcher_equal (watcher, watcher1)) {
|
||||
gs_free char *ss1 = NULL;
|
||||
gs_free char *ss2 = NULL;
|
||||
watcher1 = nm_utils_team_link_watcher_from_string(str1, &error);
|
||||
nmtst_assert_success(watcher1, error);
|
||||
if (!nm_team_link_watcher_equal(watcher, watcher1)) {
|
||||
gs_free char *ss1 = NULL;
|
||||
gs_free char *ss2 = NULL;
|
||||
|
||||
g_print (">>> watcher differs: \"%s\" vs. \"%s\"",
|
||||
(ss1 = nm_utils_team_link_watcher_to_string (watcher)),
|
||||
(ss2 = nm_utils_team_link_watcher_to_string (watcher1)));
|
||||
g_print (">>> ORIG: \"%s\" vs. \"%s\"", str, str1);
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
g_assert (nm_team_link_watcher_equal (watcher1, watcher));
|
||||
}
|
||||
g_print(">>> watcher differs: \"%s\" vs. \"%s\"",
|
||||
(ss1 = nm_utils_team_link_watcher_to_string(watcher)),
|
||||
(ss2 = nm_utils_team_link_watcher_to_string(watcher1)));
|
||||
g_print(">>> ORIG: \"%s\" vs. \"%s\"", str, str1);
|
||||
g_assert_not_reached();
|
||||
}
|
||||
g_assert(nm_team_link_watcher_equal(watcher1, watcher));
|
||||
}
|
||||
|
||||
return watcher;
|
||||
return watcher;
|
||||
}
|
||||
#define _team_link_watcher_from_string(str, ...) \
|
||||
_team_link_watcher_from_string_impl ((str), NM_NARG (__VA_ARGS__), NM_MAKE_STRV (__VA_ARGS__))
|
||||
_team_link_watcher_from_string_impl((str), NM_NARG(__VA_ARGS__), NM_MAKE_STRV(__VA_ARGS__))
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
test_team_link_watcher_tofro_string (void)
|
||||
test_team_link_watcher_tofro_string(void)
|
||||
{
|
||||
nm_auto_unref_team_link_watcher NMTeamLinkWatcher *w = NULL;
|
||||
nm_auto_unref_team_link_watcher NMTeamLinkWatcher *w = NULL;
|
||||
|
||||
#define _team_link_watcher_cmp(watcher, \
|
||||
name, \
|
||||
delay_down, \
|
||||
delay_up, \
|
||||
init_wait, \
|
||||
interval, \
|
||||
missed_max, \
|
||||
target_host, \
|
||||
source_host, \
|
||||
vlanid, \
|
||||
arping_flags) \
|
||||
G_STMT_START { \
|
||||
nm_auto_unref_team_link_watcher NMTeamLinkWatcher *_w = g_steal_pointer (watcher); \
|
||||
\
|
||||
g_assert_cmpstr ((name), ==, nm_team_link_watcher_get_name (_w)); \
|
||||
g_assert_cmpint ((delay_down), ==, nm_team_link_watcher_get_delay_down (_w)); \
|
||||
g_assert_cmpint ((delay_up), ==, nm_team_link_watcher_get_delay_up (_w)); \
|
||||
g_assert_cmpint ((init_wait), ==, nm_team_link_watcher_get_init_wait (_w)); \
|
||||
g_assert_cmpint ((interval), ==, nm_team_link_watcher_get_interval (_w)); \
|
||||
g_assert_cmpint ((missed_max), ==, nm_team_link_watcher_get_missed_max (_w)); \
|
||||
g_assert_cmpstr ((target_host), ==, nm_team_link_watcher_get_target_host (_w)); \
|
||||
g_assert_cmpstr ((source_host), ==, nm_team_link_watcher_get_source_host (_w)); \
|
||||
g_assert_cmpint ((vlanid), ==, nm_team_link_watcher_get_vlanid (_w)); \
|
||||
g_assert_cmpint ((arping_flags), ==, nm_team_link_watcher_get_flags (_w)); \
|
||||
} G_STMT_END
|
||||
#define _team_link_watcher_cmp(watcher, \
|
||||
name, \
|
||||
delay_down, \
|
||||
delay_up, \
|
||||
init_wait, \
|
||||
interval, \
|
||||
missed_max, \
|
||||
target_host, \
|
||||
source_host, \
|
||||
vlanid, \
|
||||
arping_flags) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
nm_auto_unref_team_link_watcher NMTeamLinkWatcher *_w = g_steal_pointer(watcher); \
|
||||
\
|
||||
g_assert_cmpstr((name), ==, nm_team_link_watcher_get_name(_w)); \
|
||||
g_assert_cmpint((delay_down), ==, nm_team_link_watcher_get_delay_down(_w)); \
|
||||
g_assert_cmpint((delay_up), ==, nm_team_link_watcher_get_delay_up(_w)); \
|
||||
g_assert_cmpint((init_wait), ==, nm_team_link_watcher_get_init_wait(_w)); \
|
||||
g_assert_cmpint((interval), ==, nm_team_link_watcher_get_interval(_w)); \
|
||||
g_assert_cmpint((missed_max), ==, nm_team_link_watcher_get_missed_max(_w)); \
|
||||
g_assert_cmpstr((target_host), ==, nm_team_link_watcher_get_target_host(_w)); \
|
||||
g_assert_cmpstr((source_host), ==, nm_team_link_watcher_get_source_host(_w)); \
|
||||
g_assert_cmpint((vlanid), ==, nm_team_link_watcher_get_vlanid(_w)); \
|
||||
g_assert_cmpint((arping_flags), ==, nm_team_link_watcher_get_flags(_w)); \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
w = _team_link_watcher_from_string ("name=ethtool",
|
||||
"delay-up=0 name=ethtool",
|
||||
" delay-down=0 name=ethtool ");
|
||||
_team_link_watcher_cmp (&w,
|
||||
"ethtool",
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
NULL,
|
||||
-1,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
||||
w = _team_link_watcher_from_string("name=ethtool",
|
||||
"delay-up=0 name=ethtool",
|
||||
" delay-down=0 name=ethtool ");
|
||||
_team_link_watcher_cmp(&w,
|
||||
"ethtool",
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
NULL,
|
||||
-1,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
||||
|
||||
w = _team_link_watcher_from_string ("name=ethtool delay-up=10",
|
||||
" delay-down=0 delay-up=10 name=ethtool");
|
||||
_team_link_watcher_cmp (&w,
|
||||
"ethtool",
|
||||
0,
|
||||
10,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
NULL,
|
||||
-1,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
||||
w = _team_link_watcher_from_string("name=ethtool delay-up=10",
|
||||
" delay-down=0 delay-up=10 name=ethtool");
|
||||
_team_link_watcher_cmp(&w,
|
||||
"ethtool",
|
||||
0,
|
||||
10,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
NULL,
|
||||
-1,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
||||
|
||||
w = _team_link_watcher_from_string ("name=ethtool delay-up=10 delay-down=11",
|
||||
" delay-down=11 delay-up=10 name=ethtool");
|
||||
_team_link_watcher_cmp (&w,
|
||||
"ethtool",
|
||||
11,
|
||||
10,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
NULL,
|
||||
-1,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
||||
w = _team_link_watcher_from_string("name=ethtool delay-up=10 delay-down=11",
|
||||
" delay-down=11 delay-up=10 name=ethtool");
|
||||
_team_link_watcher_cmp(&w,
|
||||
"ethtool",
|
||||
11,
|
||||
10,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
NULL,
|
||||
NULL,
|
||||
-1,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
||||
|
||||
w = _team_link_watcher_from_string ("name=nsna_ping target-host=xxx",
|
||||
"name=nsna_ping target-host=xxx",
|
||||
" missed-max=3 target-host=xxx name=nsna_ping ");
|
||||
_team_link_watcher_cmp (&w,
|
||||
"nsna_ping",
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
"xxx",
|
||||
NULL,
|
||||
-1,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
||||
w = _team_link_watcher_from_string(
|
||||
"name=nsna_ping target-host=xxx",
|
||||
"name=nsna_ping target-host=xxx",
|
||||
" missed-max=3 target-host=xxx name=nsna_ping ");
|
||||
_team_link_watcher_cmp(&w,
|
||||
"nsna_ping",
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
"xxx",
|
||||
NULL,
|
||||
-1,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
||||
|
||||
w = _team_link_watcher_from_string ("name=arp_ping target-host=xxx source-host=yzd",
|
||||
" source-host=yzd target-host=xxx name=arp_ping ");
|
||||
_team_link_watcher_cmp (&w,
|
||||
"arp_ping",
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
"xxx",
|
||||
"yzd",
|
||||
-1,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
||||
w = _team_link_watcher_from_string("name=arp_ping target-host=xxx source-host=yzd",
|
||||
" source-host=yzd target-host=xxx name=arp_ping ");
|
||||
_team_link_watcher_cmp(&w,
|
||||
"arp_ping",
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
"xxx",
|
||||
"yzd",
|
||||
-1,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
||||
|
||||
w = _team_link_watcher_from_string ("name=arp_ping missed-max=0 target-host=xxx vlanid=0 source-host=yzd");
|
||||
_team_link_watcher_cmp (&w,
|
||||
"arp_ping",
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"xxx",
|
||||
"yzd",
|
||||
0,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
||||
w = _team_link_watcher_from_string(
|
||||
"name=arp_ping missed-max=0 target-host=xxx vlanid=0 source-host=yzd");
|
||||
_team_link_watcher_cmp(&w,
|
||||
"arp_ping",
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"xxx",
|
||||
"yzd",
|
||||
0,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
||||
|
||||
w = _team_link_watcher_from_string ("name=arp_ping target-host=xxx source-host=yzd validate-active=true",
|
||||
"source-host=yzd send-always=false name=arp_ping validate-active=true validate-inactive=false target-host=xxx",
|
||||
" source-host=yzd target-host=xxx validate-active=true name=arp_ping ");
|
||||
_team_link_watcher_cmp (&w,
|
||||
"arp_ping",
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
"xxx",
|
||||
"yzd",
|
||||
-1,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_ACTIVE);
|
||||
w = _team_link_watcher_from_string(
|
||||
"name=arp_ping target-host=xxx source-host=yzd validate-active=true",
|
||||
"source-host=yzd send-always=false name=arp_ping validate-active=true "
|
||||
"validate-inactive=false target-host=xxx",
|
||||
" source-host=yzd target-host=xxx validate-active=true name=arp_ping ");
|
||||
_team_link_watcher_cmp(&w,
|
||||
"arp_ping",
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
"xxx",
|
||||
"yzd",
|
||||
-1,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_ACTIVE);
|
||||
|
||||
w = _team_link_watcher_from_string ("name=arp_ping target-host=xxx source-host=yzd validate-active=true validate-inactive=true send-always=true",
|
||||
"source-host=yzd send-always=true name=arp_ping validate-active=true validate-inactive=true target-host=xxx",
|
||||
"source-host=yzd send-always=true name=arp_ping validate-active=1 validate-inactive=yes target-host=xxx",
|
||||
" source-host=yzd target-host=xxx validate-inactive=true send-always=true validate-active=true name=arp_ping ");
|
||||
_team_link_watcher_cmp (&w,
|
||||
"arp_ping",
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
"xxx",
|
||||
"yzd",
|
||||
-1,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_ACTIVE
|
||||
| NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_INACTIVE
|
||||
| NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_SEND_ALWAYS);
|
||||
w = _team_link_watcher_from_string(
|
||||
"name=arp_ping target-host=xxx source-host=yzd validate-active=true validate-inactive=true "
|
||||
"send-always=true",
|
||||
"source-host=yzd send-always=true name=arp_ping validate-active=true "
|
||||
"validate-inactive=true target-host=xxx",
|
||||
"source-host=yzd send-always=true name=arp_ping validate-active=1 validate-inactive=yes "
|
||||
"target-host=xxx",
|
||||
" source-host=yzd target-host=xxx validate-inactive=true send-always=true "
|
||||
"validate-active=true name=arp_ping ");
|
||||
_team_link_watcher_cmp(&w,
|
||||
"arp_ping",
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
3,
|
||||
"xxx",
|
||||
"yzd",
|
||||
-1,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_ACTIVE
|
||||
| NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_VALIDATE_INACTIVE
|
||||
| NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_SEND_ALWAYS);
|
||||
|
||||
w = _team_link_watcher_from_string ("name=arp_ping missed-max=0 target-host=xxx vlanid=0 source-host=yzd");
|
||||
_team_link_watcher_cmp (&w,
|
||||
"arp_ping",
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"xxx",
|
||||
"yzd",
|
||||
0,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
||||
w = _team_link_watcher_from_string(
|
||||
"name=arp_ping missed-max=0 target-host=xxx vlanid=0 source-host=yzd");
|
||||
_team_link_watcher_cmp(&w,
|
||||
"arp_ping",
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"xxx",
|
||||
"yzd",
|
||||
0,
|
||||
NM_TEAM_LINK_WATCHER_ARP_PING_FLAG_NONE);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMTST_DEFINE ();
|
||||
NMTST_DEFINE();
|
||||
|
||||
int main (int argc, char **argv)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
nmtst_init (&argc, &argv, TRUE);
|
||||
nmtst_init(&argc, &argv, TRUE);
|
||||
|
||||
g_test_add_func ("/libnm-core-aux/test_team_link_watcher_tofro_string", test_team_link_watcher_tofro_string);
|
||||
g_test_add_func("/libnm-core-aux/test_team_link_watcher_tofro_string",
|
||||
test_team_link_watcher_tofro_string);
|
||||
|
||||
return g_test_run ();
|
||||
return g_test_run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,288 +27,311 @@
|
|||
|
||||
#define PROGRESS_STEPS 15
|
||||
|
||||
#define EXIT_NONE -1
|
||||
#define EXIT_NONE -1
|
||||
#define EXIT_FAILURE_OFFLINE 1
|
||||
#define EXIT_FAILURE_ERROR 2
|
||||
#define EXIT_FAILURE_LIBNM_BUG 42
|
||||
#define EXIT_FAILURE_UNSPECIFIED 43
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GMainLoop *loop;
|
||||
NMClient *client;
|
||||
GCancellable *client_new_cancellable;
|
||||
guint client_new_timeout_id;
|
||||
guint handle_timeout_id;
|
||||
gulong client_notify_id;
|
||||
gboolean exit_no_nm;
|
||||
gboolean wait_startup;
|
||||
gboolean quiet;
|
||||
gint64 start_timestamp_ms;
|
||||
gint64 end_timestamp_ms;
|
||||
gint64 progress_step_duration;
|
||||
int retval;
|
||||
typedef struct {
|
||||
GMainLoop * loop;
|
||||
NMClient * client;
|
||||
GCancellable *client_new_cancellable;
|
||||
guint client_new_timeout_id;
|
||||
guint handle_timeout_id;
|
||||
gulong client_notify_id;
|
||||
gboolean exit_no_nm;
|
||||
gboolean wait_startup;
|
||||
gboolean quiet;
|
||||
gint64 start_timestamp_ms;
|
||||
gint64 end_timestamp_ms;
|
||||
gint64 progress_step_duration;
|
||||
int retval;
|
||||
} OnlineData;
|
||||
|
||||
static gint64
|
||||
_now_ms (void)
|
||||
_now_ms(void)
|
||||
{
|
||||
return g_get_monotonic_time () / (G_USEC_PER_SEC / 1000);
|
||||
return g_get_monotonic_time() / (G_USEC_PER_SEC / 1000);
|
||||
}
|
||||
|
||||
static void
|
||||
_return (OnlineData *data, int retval)
|
||||
_return(OnlineData *data, int retval)
|
||||
{
|
||||
nm_assert (data);
|
||||
nm_assert (data->retval == EXIT_FAILURE_UNSPECIFIED);
|
||||
nm_assert(data);
|
||||
nm_assert(data->retval == EXIT_FAILURE_UNSPECIFIED);
|
||||
|
||||
data->retval = retval;
|
||||
nm_clear_g_signal_handler (data->client, &data->client_notify_id);
|
||||
g_main_loop_quit (data->loop);
|
||||
data->retval = retval;
|
||||
nm_clear_g_signal_handler(data->client, &data->client_notify_id);
|
||||
g_main_loop_quit(data->loop);
|
||||
}
|
||||
|
||||
static void
|
||||
_print_progress (gboolean wait_startup, int progress_next_step_i, gint64 remaining_ms, int retval)
|
||||
_print_progress(gboolean wait_startup, int progress_next_step_i, gint64 remaining_ms, int retval)
|
||||
{
|
||||
int i, j;
|
||||
int i, j;
|
||||
|
||||
j = progress_next_step_i < 0 ? PROGRESS_STEPS : progress_next_step_i;
|
||||
j = progress_next_step_i < 0 ? PROGRESS_STEPS : progress_next_step_i;
|
||||
|
||||
g_print ("\r%s", _("Connecting"));
|
||||
for (i = 0; i < PROGRESS_STEPS; i++)
|
||||
putchar (i < j ? '.' : ' ');
|
||||
g_print (" %4lds", (long) (MAX (0, remaining_ms + 999) / 1000));
|
||||
if (retval != EXIT_NONE) {
|
||||
const char *result;
|
||||
g_print("\r%s", _("Connecting"));
|
||||
for (i = 0; i < PROGRESS_STEPS; i++)
|
||||
putchar(i < j ? '.' : ' ');
|
||||
g_print(" %4lds", (long) (MAX(0, remaining_ms + 999) / 1000));
|
||||
if (retval != EXIT_NONE) {
|
||||
const char *result;
|
||||
|
||||
if (wait_startup) {
|
||||
if (retval == EXIT_SUCCESS)
|
||||
result = "started";
|
||||
else if (retval == EXIT_FAILURE_OFFLINE)
|
||||
result = "startup-pending";
|
||||
else
|
||||
result = "failure";
|
||||
}
|
||||
else {
|
||||
if (retval == EXIT_SUCCESS)
|
||||
result = "online";
|
||||
else
|
||||
result = "offline";
|
||||
}
|
||||
if (wait_startup) {
|
||||
if (retval == EXIT_SUCCESS)
|
||||
result = "started";
|
||||
else if (retval == EXIT_FAILURE_OFFLINE)
|
||||
result = "startup-pending";
|
||||
else
|
||||
result = "failure";
|
||||
} else {
|
||||
if (retval == EXIT_SUCCESS)
|
||||
result = "online";
|
||||
else
|
||||
result = "offline";
|
||||
}
|
||||
|
||||
g_print (" [%s]\n", result);
|
||||
}
|
||||
fflush (stdout);
|
||||
g_print(" [%s]\n", result);
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
quit_if_connected (OnlineData *data)
|
||||
quit_if_connected(OnlineData *data)
|
||||
{
|
||||
NMState state;
|
||||
NMState state;
|
||||
|
||||
state = nm_client_get_state (data->client);
|
||||
if (!nm_client_get_nm_running (data->client)) {
|
||||
if (data->exit_no_nm) {
|
||||
_return (data, EXIT_FAILURE_OFFLINE);
|
||||
return TRUE;
|
||||
}
|
||||
} else if (data->wait_startup) {
|
||||
if (!nm_client_get_startup (data->client)) {
|
||||
_return (data, EXIT_SUCCESS);
|
||||
return TRUE;
|
||||
}
|
||||
} else {
|
||||
if ( state == NM_STATE_CONNECTED_LOCAL
|
||||
|| state == NM_STATE_CONNECTED_SITE
|
||||
|| state == NM_STATE_CONNECTED_GLOBAL) {
|
||||
_return (data, EXIT_SUCCESS);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if (data->exit_no_nm && (state != NM_STATE_CONNECTING)) {
|
||||
_return (data, EXIT_FAILURE_OFFLINE);
|
||||
return TRUE;
|
||||
}
|
||||
state = nm_client_get_state(data->client);
|
||||
if (!nm_client_get_nm_running(data->client)) {
|
||||
if (data->exit_no_nm) {
|
||||
_return(data, EXIT_FAILURE_OFFLINE);
|
||||
return TRUE;
|
||||
}
|
||||
} else if (data->wait_startup) {
|
||||
if (!nm_client_get_startup(data->client)) {
|
||||
_return(data, EXIT_SUCCESS);
|
||||
return TRUE;
|
||||
}
|
||||
} else {
|
||||
if (state == NM_STATE_CONNECTED_LOCAL || state == NM_STATE_CONNECTED_SITE
|
||||
|| state == NM_STATE_CONNECTED_GLOBAL) {
|
||||
_return(data, EXIT_SUCCESS);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if (data->exit_no_nm && (state != NM_STATE_CONNECTING)) {
|
||||
_return(data, EXIT_FAILURE_OFFLINE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
client_properties_changed (GObject *object,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
client_properties_changed(GObject *object, GParamSpec *pspec, gpointer user_data)
|
||||
{
|
||||
quit_if_connected (user_data);
|
||||
quit_if_connected(user_data);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_timeout (gpointer user_data)
|
||||
handle_timeout(gpointer user_data)
|
||||
{
|
||||
OnlineData *data = user_data;
|
||||
const gint64 now = _now_ms ();
|
||||
gint64 remaining_ms = data->end_timestamp_ms - now;
|
||||
const gint64 elapsed_ms = now - data->start_timestamp_ms;
|
||||
int progress_next_step_i = 0;
|
||||
OnlineData * data = user_data;
|
||||
const gint64 now = _now_ms();
|
||||
gint64 remaining_ms = data->end_timestamp_ms - now;
|
||||
const gint64 elapsed_ms = now - data->start_timestamp_ms;
|
||||
int progress_next_step_i = 0;
|
||||
|
||||
data->handle_timeout_id = 0;
|
||||
data->handle_timeout_id = 0;
|
||||
|
||||
if (remaining_ms <= 3) {
|
||||
_return (data, EXIT_FAILURE_OFFLINE);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
if (remaining_ms <= 3) {
|
||||
_return(data, EXIT_FAILURE_OFFLINE);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
if (!data->quiet) {
|
||||
gint64 rem;
|
||||
if (!data->quiet) {
|
||||
gint64 rem;
|
||||
|
||||
/* calculate the next step (not the current): floor()+1 */
|
||||
progress_next_step_i = NM_MIN ((elapsed_ms / data->progress_step_duration) + 1, PROGRESS_STEPS);
|
||||
_print_progress (data->wait_startup, progress_next_step_i, remaining_ms, EXIT_NONE);
|
||||
/* calculate the next step (not the current): floor()+1 */
|
||||
progress_next_step_i =
|
||||
NM_MIN((elapsed_ms / data->progress_step_duration) + 1, PROGRESS_STEPS);
|
||||
_print_progress(data->wait_startup, progress_next_step_i, remaining_ms, EXIT_NONE);
|
||||
|
||||
/* synchronize the timeout with the ticking of the seconds. */
|
||||
rem = remaining_ms % 1000;
|
||||
if (rem <= 3)
|
||||
rem = rem + G_USEC_PER_SEC;
|
||||
/* add small offset to awake a bit after the second ticks */
|
||||
remaining_ms = NM_MIN (remaining_ms, rem + 10);
|
||||
/* synchronize the timeout with the ticking of the seconds. */
|
||||
rem = remaining_ms % 1000;
|
||||
if (rem <= 3)
|
||||
rem = rem + G_USEC_PER_SEC;
|
||||
/* add small offset to awake a bit after the second ticks */
|
||||
remaining_ms = NM_MIN(remaining_ms, rem + 10);
|
||||
|
||||
/* synchronize the timeout with the steps of the progress bar. */
|
||||
rem = (progress_next_step_i * data->progress_step_duration) - elapsed_ms;
|
||||
if (rem <= 3)
|
||||
rem = rem + data->progress_step_duration;
|
||||
/* add small offset to awake a bit after the second ticks */
|
||||
remaining_ms = NM_MIN (remaining_ms, rem + 10);
|
||||
}
|
||||
/* synchronize the timeout with the steps of the progress bar. */
|
||||
rem = (progress_next_step_i * data->progress_step_duration) - elapsed_ms;
|
||||
if (rem <= 3)
|
||||
rem = rem + data->progress_step_duration;
|
||||
/* add small offset to awake a bit after the second ticks */
|
||||
remaining_ms = NM_MIN(remaining_ms, rem + 10);
|
||||
}
|
||||
|
||||
data->handle_timeout_id = g_timeout_add (remaining_ms, handle_timeout, data);
|
||||
return G_SOURCE_REMOVE;
|
||||
data->handle_timeout_id = g_timeout_add(remaining_ms, handle_timeout, data);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
got_client_timeout (gpointer user_data)
|
||||
got_client_timeout(gpointer user_data)
|
||||
{
|
||||
OnlineData *data = user_data;
|
||||
OnlineData *data = user_data;
|
||||
|
||||
data->client_new_timeout_id = 0;
|
||||
data->quiet = TRUE;
|
||||
g_printerr (_("Error: timeout creating NMClient object\n"));
|
||||
_return (data, EXIT_FAILURE_LIBNM_BUG);
|
||||
return G_SOURCE_REMOVE;
|
||||
data->client_new_timeout_id = 0;
|
||||
data->quiet = TRUE;
|
||||
g_printerr(_("Error: timeout creating NMClient object\n"));
|
||||
_return(data, EXIT_FAILURE_LIBNM_BUG);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
got_client (GObject *source_object, GAsyncResult *res, gpointer user_data)
|
||||
got_client(GObject *source_object, GAsyncResult *res, gpointer user_data)
|
||||
{
|
||||
OnlineData *data = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
OnlineData * data = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
nm_assert (NM_IS_CLIENT (source_object));
|
||||
nm_assert (NM_CLIENT (source_object) == data->client);
|
||||
nm_assert(NM_IS_CLIENT(source_object));
|
||||
nm_assert(NM_CLIENT(source_object) == data->client);
|
||||
|
||||
nm_clear_g_source (&data->client_new_timeout_id);
|
||||
g_clear_object (&data->client_new_cancellable);
|
||||
nm_clear_g_source(&data->client_new_timeout_id);
|
||||
g_clear_object(&data->client_new_cancellable);
|
||||
|
||||
if (!g_async_initable_init_finish (G_ASYNC_INITABLE (source_object),
|
||||
res,
|
||||
&error)) {
|
||||
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
return;
|
||||
data->quiet = TRUE;
|
||||
g_printerr (_("Error: Could not create NMClient object: %s\n"),
|
||||
error->message);
|
||||
_return (data, EXIT_FAILURE_ERROR);
|
||||
return;
|
||||
}
|
||||
if (!g_async_initable_init_finish(G_ASYNC_INITABLE(source_object), res, &error)) {
|
||||
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
return;
|
||||
data->quiet = TRUE;
|
||||
g_printerr(_("Error: Could not create NMClient object: %s\n"), error->message);
|
||||
_return(data, EXIT_FAILURE_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (quit_if_connected (data))
|
||||
return;
|
||||
if (quit_if_connected(data))
|
||||
return;
|
||||
|
||||
data->client_notify_id = g_signal_connect (data->client, "notify",
|
||||
G_CALLBACK (client_properties_changed), data);
|
||||
data->handle_timeout_id = g_timeout_add (data->quiet ? NM_MAX (0, data->end_timestamp_ms - _now_ms ()) : 0, handle_timeout, data);
|
||||
data->client_notify_id =
|
||||
g_signal_connect(data->client, "notify", G_CALLBACK(client_properties_changed), data);
|
||||
data->handle_timeout_id =
|
||||
g_timeout_add(data->quiet ? NM_MAX(0, data->end_timestamp_ms - _now_ms()) : 0,
|
||||
handle_timeout,
|
||||
data);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
OnlineData data = {
|
||||
.retval = EXIT_FAILURE_UNSPECIFIED,
|
||||
};
|
||||
int t_secs;
|
||||
GOptionContext *opt_ctx = NULL;
|
||||
gboolean success;
|
||||
GOptionEntry options[] = {
|
||||
{"quiet", 'q', 0, G_OPTION_ARG_NONE, &data.quiet, N_("Don't print anything"), NULL},
|
||||
{"wait-for-startup", 's', 0, G_OPTION_ARG_NONE, &data.wait_startup, N_("Wait for NetworkManager startup instead of a connection"), NULL},
|
||||
{"timeout", 't', 0, G_OPTION_ARG_INT, &t_secs, N_("Time to wait for a connection, in seconds (without the option, default value is 30)"), "<timeout>"},
|
||||
{"exit", 'x', 0, G_OPTION_ARG_NONE, &data.exit_no_nm, N_("Exit immediately if NetworkManager is not running or connecting"), NULL},
|
||||
{ NULL },
|
||||
};
|
||||
OnlineData data = {
|
||||
.retval = EXIT_FAILURE_UNSPECIFIED,
|
||||
};
|
||||
int t_secs;
|
||||
GOptionContext *opt_ctx = NULL;
|
||||
gboolean success;
|
||||
GOptionEntry options[] = {
|
||||
{"quiet", 'q', 0, G_OPTION_ARG_NONE, &data.quiet, N_("Don't print anything"), NULL},
|
||||
{"wait-for-startup",
|
||||
's',
|
||||
0,
|
||||
G_OPTION_ARG_NONE,
|
||||
&data.wait_startup,
|
||||
N_("Wait for NetworkManager startup instead of a connection"),
|
||||
NULL},
|
||||
{"timeout",
|
||||
't',
|
||||
0,
|
||||
G_OPTION_ARG_INT,
|
||||
&t_secs,
|
||||
N_("Time to wait for a connection, in seconds (without the option, default value is 30)"),
|
||||
"<timeout>"},
|
||||
{"exit",
|
||||
'x',
|
||||
0,
|
||||
G_OPTION_ARG_NONE,
|
||||
&data.exit_no_nm,
|
||||
N_("Exit immediately if NetworkManager is not running or connecting"),
|
||||
NULL},
|
||||
{NULL},
|
||||
};
|
||||
|
||||
/* Set locale to be able to use environment variables */
|
||||
setlocale (LC_ALL, "");
|
||||
/* Set locale to be able to use environment variables */
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
bindtextdomain (GETTEXT_PACKAGE, NMLOCALEDIR);
|
||||
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
||||
textdomain (GETTEXT_PACKAGE);
|
||||
bindtextdomain(GETTEXT_PACKAGE, NMLOCALEDIR);
|
||||
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
|
||||
textdomain(GETTEXT_PACKAGE);
|
||||
|
||||
t_secs = _nm_utils_ascii_str_to_int64 (g_getenv ("NM_ONLINE_TIMEOUT"), 10, 0, G_MAXINT, 30);
|
||||
t_secs = _nm_utils_ascii_str_to_int64(g_getenv("NM_ONLINE_TIMEOUT"), 10, 0, G_MAXINT, 30);
|
||||
|
||||
data.start_timestamp_ms = _now_ms ();
|
||||
data.start_timestamp_ms = _now_ms();
|
||||
|
||||
opt_ctx = g_option_context_new (NULL);
|
||||
g_option_context_set_translation_domain (opt_ctx, GETTEXT_PACKAGE);
|
||||
g_option_context_set_ignore_unknown_options (opt_ctx, FALSE);
|
||||
g_option_context_set_help_enabled (opt_ctx, TRUE);
|
||||
g_option_context_add_main_entries (opt_ctx, options, NULL);
|
||||
opt_ctx = g_option_context_new(NULL);
|
||||
g_option_context_set_translation_domain(opt_ctx, GETTEXT_PACKAGE);
|
||||
g_option_context_set_ignore_unknown_options(opt_ctx, FALSE);
|
||||
g_option_context_set_help_enabled(opt_ctx, TRUE);
|
||||
g_option_context_add_main_entries(opt_ctx, options, NULL);
|
||||
|
||||
g_option_context_set_summary (opt_ctx,
|
||||
_("Waits for NetworkManager to finish activating startup network connections."));
|
||||
g_option_context_set_summary(
|
||||
opt_ctx,
|
||||
_("Waits for NetworkManager to finish activating startup network connections."));
|
||||
|
||||
success = g_option_context_parse (opt_ctx, &argc, &argv, NULL);
|
||||
g_option_context_free (opt_ctx);
|
||||
success = g_option_context_parse(opt_ctx, &argc, &argv, NULL);
|
||||
g_option_context_free(opt_ctx);
|
||||
|
||||
if (!success) {
|
||||
g_printerr ("%s: %s\n", argv[0],
|
||||
_("Invalid option. Please use --help to see a list of valid options."));
|
||||
return EXIT_FAILURE_ERROR;
|
||||
}
|
||||
if (!success) {
|
||||
g_printerr("%s: %s\n",
|
||||
argv[0],
|
||||
_("Invalid option. Please use --help to see a list of valid options."));
|
||||
return EXIT_FAILURE_ERROR;
|
||||
}
|
||||
|
||||
if (t_secs < 0 || t_secs > 3600) {
|
||||
g_printerr ("%s: %s\n", argv[0],
|
||||
_("Invalid option. Please use --help to see a list of valid options."));
|
||||
return EXIT_FAILURE_ERROR;
|
||||
}
|
||||
if (t_secs < 0 || t_secs > 3600) {
|
||||
g_printerr("%s: %s\n",
|
||||
argv[0],
|
||||
_("Invalid option. Please use --help to see a list of valid options."));
|
||||
return EXIT_FAILURE_ERROR;
|
||||
}
|
||||
|
||||
if (t_secs == 0)
|
||||
data.quiet = TRUE;
|
||||
if (t_secs == 0)
|
||||
data.quiet = TRUE;
|
||||
|
||||
data.loop = g_main_loop_new (NULL, FALSE);
|
||||
data.loop = g_main_loop_new(NULL, FALSE);
|
||||
|
||||
data.end_timestamp_ms = data.start_timestamp_ms + (t_secs * 1000);
|
||||
data.progress_step_duration = NM_MAX (1, (data.end_timestamp_ms - data.start_timestamp_ms + PROGRESS_STEPS/2) / PROGRESS_STEPS);
|
||||
data.end_timestamp_ms = data.start_timestamp_ms + (t_secs * 1000);
|
||||
data.progress_step_duration = NM_MAX(
|
||||
1,
|
||||
(data.end_timestamp_ms - data.start_timestamp_ms + PROGRESS_STEPS / 2) / PROGRESS_STEPS);
|
||||
|
||||
data.client_new_cancellable = g_cancellable_new ();
|
||||
data.client_new_cancellable = g_cancellable_new();
|
||||
|
||||
data.client_new_timeout_id = g_timeout_add_seconds (30, got_client_timeout, &data);
|
||||
data.client_new_timeout_id = g_timeout_add_seconds(30, got_client_timeout, &data);
|
||||
|
||||
data.client = nmc_client_new_async (data.client_new_cancellable,
|
||||
got_client,
|
||||
&data,
|
||||
NM_CLIENT_INSTANCE_FLAGS, (guint) NM_CLIENT_INSTANCE_FLAGS_NO_AUTO_FETCH_PERMISSIONS,
|
||||
NULL);
|
||||
data.client = nmc_client_new_async(data.client_new_cancellable,
|
||||
got_client,
|
||||
&data,
|
||||
NM_CLIENT_INSTANCE_FLAGS,
|
||||
(guint) NM_CLIENT_INSTANCE_FLAGS_NO_AUTO_FETCH_PERMISSIONS,
|
||||
NULL);
|
||||
|
||||
g_main_loop_run (data.loop);
|
||||
g_main_loop_run(data.loop);
|
||||
|
||||
nm_clear_g_cancellable (&data.client_new_cancellable);
|
||||
nm_clear_g_source (&data.client_new_timeout_id);
|
||||
nm_clear_g_source (&data.handle_timeout_id);
|
||||
nm_clear_g_signal_handler (data.client, &data.client_notify_id);
|
||||
g_clear_object (&data.client);
|
||||
nm_clear_g_cancellable(&data.client_new_cancellable);
|
||||
nm_clear_g_source(&data.client_new_timeout_id);
|
||||
nm_clear_g_source(&data.handle_timeout_id);
|
||||
nm_clear_g_signal_handler(data.client, &data.client_notify_id);
|
||||
g_clear_object(&data.client);
|
||||
|
||||
nm_clear_pointer (&data.loop, g_main_loop_unref);
|
||||
nm_clear_pointer(&data.loop, g_main_loop_unref);
|
||||
|
||||
if (!data.quiet)
|
||||
_print_progress (data.wait_startup, -1, NM_MAX (0, data.end_timestamp_ms - _now_ms ()), data.retval);
|
||||
if (!data.quiet)
|
||||
_print_progress(data.wait_startup,
|
||||
-1,
|
||||
NM_MAX(0, data.end_timestamp_ms - _now_ms()),
|
||||
data.retval);
|
||||
|
||||
return data.retval;
|
||||
return data.retval;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,21 +22,22 @@
|
|||
|
||||
#include "nmt-newt-button.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtNewtButtonBox, nmt_newt_button_box, NMT_TYPE_NEWT_CONTAINER)
|
||||
G_DEFINE_TYPE(NmtNewtButtonBox, nmt_newt_button_box, NMT_TYPE_NEWT_CONTAINER)
|
||||
|
||||
#define NMT_NEWT_BUTTON_BOX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_BUTTON_BOX, NmtNewtButtonBoxPrivate))
|
||||
#define NMT_NEWT_BUTTON_BOX_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_BUTTON_BOX, NmtNewtButtonBoxPrivate))
|
||||
|
||||
typedef struct {
|
||||
NmtNewtButtonBoxOrientation orientation;
|
||||
GPtrArray *start_buttons, *end_buttons;
|
||||
NmtNewtButtonBoxOrientation orientation;
|
||||
GPtrArray * start_buttons, *end_buttons;
|
||||
} NmtNewtButtonBoxPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_0,
|
||||
|
||||
PROP_ORIENTATION,
|
||||
PROP_ORIENTATION,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -56,20 +57,18 @@ enum {
|
|||
* Returns: a new #NmtNewtButtonBox
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_button_box_new (NmtNewtButtonBoxOrientation orientation)
|
||||
nmt_newt_button_box_new(NmtNewtButtonBoxOrientation orientation)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_NEWT_BUTTON_BOX,
|
||||
"orientation", orientation,
|
||||
NULL);
|
||||
return g_object_new(NMT_TYPE_NEWT_BUTTON_BOX, "orientation", orientation, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_button_box_init (NmtNewtButtonBox *bbox)
|
||||
nmt_newt_button_box_init(NmtNewtButtonBox *bbox)
|
||||
{
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (bbox);
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE(bbox);
|
||||
|
||||
priv->start_buttons = g_ptr_array_new ();
|
||||
priv->end_buttons = g_ptr_array_new ();
|
||||
priv->start_buttons = g_ptr_array_new();
|
||||
priv->end_buttons = g_ptr_array_new();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -84,14 +83,13 @@ nmt_newt_button_box_init (NmtNewtButtonBox *bbox)
|
|||
* Returns: the newly-created button, already added to @bbox
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_button_box_add_start (NmtNewtButtonBox *bbox,
|
||||
const char *label)
|
||||
nmt_newt_button_box_add_start(NmtNewtButtonBox *bbox, const char *label)
|
||||
{
|
||||
NmtNewtWidget *button;
|
||||
NmtNewtWidget *button;
|
||||
|
||||
button = nmt_newt_button_new (label);
|
||||
nmt_newt_button_box_add_widget_start (bbox, button);
|
||||
return button;
|
||||
button = nmt_newt_button_new(label);
|
||||
nmt_newt_button_box_add_widget_start(bbox, button);
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -102,14 +100,13 @@ nmt_newt_button_box_add_start (NmtNewtButtonBox *bbox,
|
|||
* Adds the given widget to the "start" section of @bbox.
|
||||
*/
|
||||
void
|
||||
nmt_newt_button_box_add_widget_start (NmtNewtButtonBox *bbox,
|
||||
NmtNewtWidget *widget)
|
||||
nmt_newt_button_box_add_widget_start(NmtNewtButtonBox *bbox, NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (bbox);
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE(bbox);
|
||||
|
||||
NMT_NEWT_CONTAINER_CLASS (nmt_newt_button_box_parent_class)->
|
||||
add (NMT_NEWT_CONTAINER (bbox), widget);
|
||||
g_ptr_array_add (priv->start_buttons, widget);
|
||||
NMT_NEWT_CONTAINER_CLASS(nmt_newt_button_box_parent_class)
|
||||
->add(NMT_NEWT_CONTAINER(bbox), widget);
|
||||
g_ptr_array_add(priv->start_buttons, widget);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -124,14 +121,13 @@ nmt_newt_button_box_add_widget_start (NmtNewtButtonBox *bbox,
|
|||
* Returns: the newly-created button, already added to @bbox
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_button_box_add_end (NmtNewtButtonBox *bbox,
|
||||
const char *label)
|
||||
nmt_newt_button_box_add_end(NmtNewtButtonBox *bbox, const char *label)
|
||||
{
|
||||
NmtNewtWidget *button;
|
||||
NmtNewtWidget *button;
|
||||
|
||||
button = nmt_newt_button_new (label);
|
||||
nmt_newt_button_box_add_widget_end (bbox, button);
|
||||
return button;
|
||||
button = nmt_newt_button_new(label);
|
||||
nmt_newt_button_box_add_widget_end(bbox, button);
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -142,229 +138,221 @@ nmt_newt_button_box_add_end (NmtNewtButtonBox *bbox,
|
|||
* Adds the given widget to the "end" section of @bbox.
|
||||
*/
|
||||
void
|
||||
nmt_newt_button_box_add_widget_end (NmtNewtButtonBox *bbox,
|
||||
NmtNewtWidget *widget)
|
||||
nmt_newt_button_box_add_widget_end(NmtNewtButtonBox *bbox, NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (bbox);
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE(bbox);
|
||||
|
||||
NMT_NEWT_CONTAINER_CLASS (nmt_newt_button_box_parent_class)->
|
||||
add (NMT_NEWT_CONTAINER (bbox), widget);
|
||||
g_ptr_array_add (priv->end_buttons, widget);
|
||||
NMT_NEWT_CONTAINER_CLASS(nmt_newt_button_box_parent_class)
|
||||
->add(NMT_NEWT_CONTAINER(bbox), widget);
|
||||
g_ptr_array_add(priv->end_buttons, widget);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_button_box_remove (NmtNewtContainer *container,
|
||||
NmtNewtWidget *child)
|
||||
nmt_newt_button_box_remove(NmtNewtContainer *container, NmtNewtWidget *child)
|
||||
{
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (container);
|
||||
int i;
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE(container);
|
||||
int i;
|
||||
|
||||
NMT_NEWT_CONTAINER_CLASS (nmt_newt_button_box_parent_class)->
|
||||
remove (container, child);
|
||||
NMT_NEWT_CONTAINER_CLASS(nmt_newt_button_box_parent_class)->remove(container, child);
|
||||
|
||||
for (i = 0; i < priv->start_buttons->len; i++) {
|
||||
if (priv->start_buttons->pdata[i] == (gpointer) child) {
|
||||
g_ptr_array_remove_index (priv->start_buttons, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < priv->end_buttons->len; i++) {
|
||||
if (priv->end_buttons->pdata[i] == (gpointer) child) {
|
||||
g_ptr_array_remove_index (priv->end_buttons, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < priv->start_buttons->len; i++) {
|
||||
if (priv->start_buttons->pdata[i] == (gpointer) child) {
|
||||
g_ptr_array_remove_index(priv->start_buttons, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < priv->end_buttons->len; i++) {
|
||||
if (priv->end_buttons->pdata[i] == (gpointer) child) {
|
||||
g_ptr_array_remove_index(priv->end_buttons, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
add_buttons (GPtrArray *buttons, GPtrArray *cos)
|
||||
add_buttons(GPtrArray *buttons, GPtrArray *cos)
|
||||
{
|
||||
NmtNewtWidget *child;
|
||||
newtComponent *child_cos;
|
||||
int i, c;
|
||||
NmtNewtWidget *child;
|
||||
newtComponent *child_cos;
|
||||
int i, c;
|
||||
|
||||
for (i = 0; i < buttons->len; i++) {
|
||||
child = buttons->pdata[i];
|
||||
for (i = 0; i < buttons->len; i++) {
|
||||
child = buttons->pdata[i];
|
||||
|
||||
if (!nmt_newt_widget_get_visible (child))
|
||||
continue;
|
||||
if (!nmt_newt_widget_get_visible(child))
|
||||
continue;
|
||||
|
||||
child_cos = nmt_newt_widget_get_components (child);
|
||||
for (c = 0; child_cos[c]; c++)
|
||||
g_ptr_array_add (cos, child_cos[c]);
|
||||
g_free (child_cos);
|
||||
}
|
||||
child_cos = nmt_newt_widget_get_components(child);
|
||||
for (c = 0; child_cos[c]; c++)
|
||||
g_ptr_array_add(cos, child_cos[c]);
|
||||
g_free(child_cos);
|
||||
}
|
||||
}
|
||||
|
||||
static newtComponent *
|
||||
nmt_newt_button_box_get_components (NmtNewtWidget *widget)
|
||||
nmt_newt_button_box_get_components(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (widget);
|
||||
GPtrArray *cos;
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE(widget);
|
||||
GPtrArray * cos;
|
||||
|
||||
cos = g_ptr_array_new ();
|
||||
add_buttons (priv->start_buttons, cos);
|
||||
add_buttons (priv->end_buttons, cos);
|
||||
g_ptr_array_add (cos, NULL);
|
||||
cos = g_ptr_array_new();
|
||||
add_buttons(priv->start_buttons, cos);
|
||||
add_buttons(priv->end_buttons, cos);
|
||||
g_ptr_array_add(cos, NULL);
|
||||
|
||||
return (newtComponent *) g_ptr_array_free (cos, FALSE);
|
||||
return (newtComponent *) g_ptr_array_free(cos, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
size_request_buttons (NmtNewtButtonBox *bbox,
|
||||
GPtrArray *buttons,
|
||||
int *width,
|
||||
int *height)
|
||||
size_request_buttons(NmtNewtButtonBox *bbox, GPtrArray *buttons, int *width, int *height)
|
||||
{
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (bbox);
|
||||
int child_width, child_height;
|
||||
int i;
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE(bbox);
|
||||
int child_width, child_height;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < buttons->len; i++) {
|
||||
NmtNewtWidget *child = buttons->pdata[i];
|
||||
for (i = 0; i < buttons->len; i++) {
|
||||
NmtNewtWidget *child = buttons->pdata[i];
|
||||
|
||||
nmt_newt_widget_size_request (child, &child_width, &child_height);
|
||||
if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL) {
|
||||
*width += child_width;
|
||||
if (i > 0)
|
||||
*width += 1;
|
||||
*height = MAX (*height, child_height);
|
||||
} else {
|
||||
*height += child_height;
|
||||
if (i > 0)
|
||||
*height += 1;
|
||||
*width = MAX (*width, child_width);
|
||||
}
|
||||
}
|
||||
nmt_newt_widget_size_request(child, &child_width, &child_height);
|
||||
if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL) {
|
||||
*width += child_width;
|
||||
if (i > 0)
|
||||
*width += 1;
|
||||
*height = MAX(*height, child_height);
|
||||
} else {
|
||||
*height += child_height;
|
||||
if (i > 0)
|
||||
*height += 1;
|
||||
*width = MAX(*width, child_width);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_button_box_size_request (NmtNewtWidget *widget,
|
||||
int *width,
|
||||
int *height)
|
||||
nmt_newt_button_box_size_request(NmtNewtWidget *widget, int *width, int *height)
|
||||
{
|
||||
NmtNewtButtonBox *bbox = NMT_NEWT_BUTTON_BOX (widget);
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (widget);
|
||||
NmtNewtButtonBox * bbox = NMT_NEWT_BUTTON_BOX(widget);
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE(widget);
|
||||
|
||||
*width = *height = 0;
|
||||
size_request_buttons (bbox, priv->start_buttons, width, height);
|
||||
size_request_buttons (bbox, priv->end_buttons, width, height);
|
||||
*width = *height = 0;
|
||||
size_request_buttons(bbox, priv->start_buttons, width, height);
|
||||
size_request_buttons(bbox, priv->end_buttons, width, height);
|
||||
|
||||
if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL)
|
||||
*width += 1;
|
||||
else
|
||||
*height += 1;
|
||||
if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL)
|
||||
*width += 1;
|
||||
else
|
||||
*height += 1;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_button_box_size_allocate (NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height)
|
||||
nmt_newt_button_box_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height)
|
||||
{
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (widget);
|
||||
NmtNewtWidget *child;
|
||||
int child_x, child_y, child_width, child_height;
|
||||
int i;
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE(widget);
|
||||
NmtNewtWidget * child;
|
||||
int child_x, child_y, child_width, child_height;
|
||||
int i;
|
||||
|
||||
child_x = x;
|
||||
child_y = y;
|
||||
for (i = 0; i < priv->start_buttons->len; i++) {
|
||||
child = priv->start_buttons->pdata[i];
|
||||
nmt_newt_widget_size_request (child, &child_width, &child_height);
|
||||
child_x = x;
|
||||
child_y = y;
|
||||
for (i = 0; i < priv->start_buttons->len; i++) {
|
||||
child = priv->start_buttons->pdata[i];
|
||||
nmt_newt_widget_size_request(child, &child_width, &child_height);
|
||||
|
||||
if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL) {
|
||||
nmt_newt_widget_size_allocate (child, child_x, child_y, child_width, child_height);
|
||||
child_x += child_width + 1;
|
||||
} else {
|
||||
nmt_newt_widget_size_allocate (child, child_x, child_y, child_width, child_height);
|
||||
child_y += child_height + 1;
|
||||
}
|
||||
}
|
||||
if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL) {
|
||||
nmt_newt_widget_size_allocate(child, child_x, child_y, child_width, child_height);
|
||||
child_x += child_width + 1;
|
||||
} else {
|
||||
nmt_newt_widget_size_allocate(child, child_x, child_y, child_width, child_height);
|
||||
child_y += child_height + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL)
|
||||
child_x = x + width;
|
||||
else
|
||||
child_y = y + height;
|
||||
if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL)
|
||||
child_x = x + width;
|
||||
else
|
||||
child_y = y + height;
|
||||
|
||||
for (i = priv->end_buttons->len - 1; i >= 0; i--) {
|
||||
child = priv->end_buttons->pdata[i];
|
||||
nmt_newt_widget_size_request (child, &child_width, &child_height);
|
||||
for (i = priv->end_buttons->len - 1; i >= 0; i--) {
|
||||
child = priv->end_buttons->pdata[i];
|
||||
nmt_newt_widget_size_request(child, &child_width, &child_height);
|
||||
|
||||
if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL) {
|
||||
nmt_newt_widget_size_allocate (child,
|
||||
child_x - child_width, child_y,
|
||||
child_width, child_height);
|
||||
child_x -= child_width + 1;
|
||||
} else {
|
||||
nmt_newt_widget_size_allocate (child,
|
||||
child_x, child_y - child_height,
|
||||
child_width, child_height);
|
||||
child_y -= child_height + 1;
|
||||
}
|
||||
}
|
||||
if (priv->orientation == NMT_NEWT_BUTTON_BOX_HORIZONTAL) {
|
||||
nmt_newt_widget_size_allocate(child,
|
||||
child_x - child_width,
|
||||
child_y,
|
||||
child_width,
|
||||
child_height);
|
||||
child_x -= child_width + 1;
|
||||
} else {
|
||||
nmt_newt_widget_size_allocate(child,
|
||||
child_x,
|
||||
child_y - child_height,
|
||||
child_width,
|
||||
child_height);
|
||||
child_y -= child_height + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_button_box_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_button_box_set_property(GObject * object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (object);
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_ORIENTATION:
|
||||
priv->orientation = g_value_get_int (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_ORIENTATION:
|
||||
priv->orientation = g_value_get_int(value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_button_box_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_button_box_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (object);
|
||||
NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_ORIENTATION:
|
||||
g_value_set_int (value, priv->orientation);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_ORIENTATION:
|
||||
g_value_set_int(value, priv->orientation);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_button_box_class_init (NmtNewtButtonBoxClass *bbox_class)
|
||||
nmt_newt_button_box_class_init(NmtNewtButtonBoxClass *bbox_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (bbox_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (bbox_class);
|
||||
NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS (bbox_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(bbox_class);
|
||||
NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(bbox_class);
|
||||
NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS(bbox_class);
|
||||
|
||||
g_type_class_add_private (bbox_class, sizeof (NmtNewtButtonBoxPrivate));
|
||||
g_type_class_add_private(bbox_class, sizeof(NmtNewtButtonBoxPrivate));
|
||||
|
||||
object_class->get_property = nmt_newt_button_box_get_property;
|
||||
object_class->set_property = nmt_newt_button_box_set_property;
|
||||
object_class->get_property = nmt_newt_button_box_get_property;
|
||||
object_class->set_property = nmt_newt_button_box_set_property;
|
||||
|
||||
widget_class->get_components = nmt_newt_button_box_get_components;
|
||||
widget_class->size_request = nmt_newt_button_box_size_request;
|
||||
widget_class->size_allocate = nmt_newt_button_box_size_allocate;
|
||||
widget_class->get_components = nmt_newt_button_box_get_components;
|
||||
widget_class->size_request = nmt_newt_button_box_size_request;
|
||||
widget_class->size_allocate = nmt_newt_button_box_size_allocate;
|
||||
|
||||
container_class->remove = nmt_newt_button_box_remove;
|
||||
container_class->remove = nmt_newt_button_box_remove;
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ORIENTATION,
|
||||
g_param_spec_int ("orientation", "", "",
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_ORIENTATION,
|
||||
g_param_spec_int("orientation",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
G_MAXINT,
|
||||
0,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,40 +8,39 @@
|
|||
|
||||
#include "nmt-newt-grid.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_BUTTON_BOX (nmt_newt_button_box_get_type ())
|
||||
#define NMT_NEWT_BUTTON_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_BUTTON_BOX, NmtNewtButtonBox))
|
||||
#define NMT_NEWT_BUTTON_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_BUTTON_BOX, NmtNewtButtonBoxClass))
|
||||
#define NMT_IS_NEWT_BUTTON_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_BUTTON_BOX))
|
||||
#define NMT_IS_NEWT_BUTTON_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_BUTTON_BOX))
|
||||
#define NMT_NEWT_BUTTON_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_BUTTON_BOX, NmtNewtButtonBoxClass))
|
||||
#define NMT_TYPE_NEWT_BUTTON_BOX (nmt_newt_button_box_get_type())
|
||||
#define NMT_NEWT_BUTTON_BOX(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_BUTTON_BOX, NmtNewtButtonBox))
|
||||
#define NMT_NEWT_BUTTON_BOX_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_BUTTON_BOX, NmtNewtButtonBoxClass))
|
||||
#define NMT_IS_NEWT_BUTTON_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_BUTTON_BOX))
|
||||
#define NMT_IS_NEWT_BUTTON_BOX_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_BUTTON_BOX))
|
||||
#define NMT_NEWT_BUTTON_BOX_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_BUTTON_BOX, NmtNewtButtonBoxClass))
|
||||
|
||||
struct _NmtNewtButtonBox {
|
||||
NmtNewtContainer parent;
|
||||
|
||||
NmtNewtContainer parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtContainerClass parent;
|
||||
NmtNewtContainerClass parent;
|
||||
|
||||
} NmtNewtButtonBoxClass;
|
||||
|
||||
GType nmt_newt_button_box_get_type (void);
|
||||
GType nmt_newt_button_box_get_type(void);
|
||||
|
||||
typedef enum {
|
||||
NMT_NEWT_BUTTON_BOX_HORIZONTAL,
|
||||
NMT_NEWT_BUTTON_BOX_VERTICAL
|
||||
NMT_NEWT_BUTTON_BOX_HORIZONTAL,
|
||||
NMT_NEWT_BUTTON_BOX_VERTICAL
|
||||
} NmtNewtButtonBoxOrientation;
|
||||
|
||||
NmtNewtWidget *nmt_newt_button_box_new (NmtNewtButtonBoxOrientation orientation);
|
||||
NmtNewtWidget *nmt_newt_button_box_new(NmtNewtButtonBoxOrientation orientation);
|
||||
|
||||
NmtNewtWidget *nmt_newt_button_box_add_start (NmtNewtButtonBox *bbox,
|
||||
const char *label);
|
||||
NmtNewtWidget *nmt_newt_button_box_add_end (NmtNewtButtonBox *bbox,
|
||||
const char *label);
|
||||
NmtNewtWidget *nmt_newt_button_box_add_start(NmtNewtButtonBox *bbox, const char *label);
|
||||
NmtNewtWidget *nmt_newt_button_box_add_end(NmtNewtButtonBox *bbox, const char *label);
|
||||
|
||||
void nmt_newt_button_box_add_widget_start (NmtNewtButtonBox *bbox,
|
||||
NmtNewtWidget *widget);
|
||||
void nmt_newt_button_box_add_widget_end (NmtNewtButtonBox *bbox,
|
||||
NmtNewtWidget *widget);
|
||||
void nmt_newt_button_box_add_widget_start(NmtNewtButtonBox *bbox, NmtNewtWidget *widget);
|
||||
void nmt_newt_button_box_add_widget_end(NmtNewtButtonBox *bbox, NmtNewtWidget *widget);
|
||||
|
||||
#endif /* NMT_NEWT_BUTTON_BOX_H */
|
||||
|
|
|
|||
|
|
@ -15,28 +15,29 @@
|
|||
#include "nmt-newt-button.h"
|
||||
#include "nmt-newt-utils.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtNewtButton, nmt_newt_button, NMT_TYPE_NEWT_COMPONENT)
|
||||
G_DEFINE_TYPE(NmtNewtButton, nmt_newt_button, NMT_TYPE_NEWT_COMPONENT)
|
||||
|
||||
#define NMT_NEWT_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_BUTTON, NmtNewtButtonPrivate))
|
||||
#define NMT_NEWT_BUTTON_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_BUTTON, NmtNewtButtonPrivate))
|
||||
|
||||
typedef struct {
|
||||
char *label;
|
||||
char *label;
|
||||
} NmtNewtButtonPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_LABEL,
|
||||
PROP_0,
|
||||
PROP_LABEL,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
enum {
|
||||
CLICKED,
|
||||
CLICKED,
|
||||
|
||||
LAST_SIGNAL
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
static guint signals[LAST_SIGNAL] = {0};
|
||||
|
||||
/**
|
||||
* nmt_newt_button_new:
|
||||
|
|
@ -47,11 +48,9 @@ static guint signals[LAST_SIGNAL] = { 0 };
|
|||
* Returns: a new #NmtNewtButton
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_button_new (const char *label)
|
||||
nmt_newt_button_new(const char *label)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_NEWT_BUTTON,
|
||||
"label", label,
|
||||
NULL);
|
||||
return g_object_new(NMT_TYPE_NEWT_BUTTON, "label", label, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -62,17 +61,16 @@ nmt_newt_button_new (const char *label)
|
|||
* Updates @button's label.
|
||||
*/
|
||||
void
|
||||
nmt_newt_button_set_label (NmtNewtButton *button,
|
||||
const char *label)
|
||||
nmt_newt_button_set_label(NmtNewtButton *button, const char *label)
|
||||
{
|
||||
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE (button);
|
||||
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE(button);
|
||||
|
||||
if (!g_strcmp0 (priv->label, label))
|
||||
return;
|
||||
if (!g_strcmp0(priv->label, label))
|
||||
return;
|
||||
|
||||
g_free (priv->label);
|
||||
priv->label = g_strdup (label);
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (button));
|
||||
g_free(priv->label);
|
||||
priv->label = g_strdup(label);
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(button));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -84,165 +82,151 @@ nmt_newt_button_set_label (NmtNewtButton *button,
|
|||
* Returns: @button's label.
|
||||
*/
|
||||
const char *
|
||||
nmt_newt_button_get_label (NmtNewtButton *button)
|
||||
nmt_newt_button_get_label(NmtNewtButton *button)
|
||||
{
|
||||
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE (button);
|
||||
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE(button);
|
||||
|
||||
return priv->label;
|
||||
return priv->label;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_button_init (NmtNewtButton *button)
|
||||
{
|
||||
}
|
||||
nmt_newt_button_init(NmtNewtButton *button)
|
||||
{}
|
||||
|
||||
static void
|
||||
nmt_newt_button_finalize (GObject *object)
|
||||
nmt_newt_button_finalize(GObject *object)
|
||||
{
|
||||
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE (object);
|
||||
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE(object);
|
||||
|
||||
g_free (priv->label);
|
||||
g_free(priv->label);
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_button_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS(nmt_newt_button_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static newtComponent
|
||||
nmt_newt_button_build_component (NmtNewtComponent *component,
|
||||
gboolean sensitive)
|
||||
nmt_newt_button_build_component(NmtNewtComponent *component, gboolean sensitive)
|
||||
{
|
||||
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE (component);
|
||||
newtComponent co;
|
||||
char *label = NULL, *label_lc;
|
||||
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE(component);
|
||||
newtComponent co;
|
||||
char * label = NULL, *label_lc;
|
||||
|
||||
if (sensitive) {
|
||||
label_lc = nmt_newt_locale_from_utf8 (priv->label);
|
||||
co = newtCompactButton (-1, -1, label_lc);
|
||||
g_free (label_lc);
|
||||
} else {
|
||||
label = g_strdup_printf (" <%s>", priv->label);
|
||||
label_lc = nmt_newt_locale_from_utf8 (label);
|
||||
co = newtLabel (-1, -1, label_lc);
|
||||
g_free (label_lc);
|
||||
newtLabelSetColors (co, NMT_NEWT_COLORSET_DISABLED_BUTTON);
|
||||
}
|
||||
if (sensitive) {
|
||||
label_lc = nmt_newt_locale_from_utf8(priv->label);
|
||||
co = newtCompactButton(-1, -1, label_lc);
|
||||
g_free(label_lc);
|
||||
} else {
|
||||
label = g_strdup_printf(" <%s>", priv->label);
|
||||
label_lc = nmt_newt_locale_from_utf8(label);
|
||||
co = newtLabel(-1, -1, label_lc);
|
||||
g_free(label_lc);
|
||||
newtLabelSetColors(co, NMT_NEWT_COLORSET_DISABLED_BUTTON);
|
||||
}
|
||||
|
||||
return co;
|
||||
return co;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_button_size_request (NmtNewtWidget *widget,
|
||||
int *width,
|
||||
int *height)
|
||||
nmt_newt_button_size_request(NmtNewtWidget *widget, int *width, int *height)
|
||||
{
|
||||
NMT_NEWT_WIDGET_CLASS (nmt_newt_button_parent_class)->size_request (widget, width, height);
|
||||
NMT_NEWT_WIDGET_CLASS(nmt_newt_button_parent_class)->size_request(widget, width, height);
|
||||
|
||||
/* remove the automatically-added left padding */
|
||||
(*width)--;
|
||||
/* remove the automatically-added left padding */
|
||||
(*width)--;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_button_size_allocate (NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height)
|
||||
nmt_newt_button_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height)
|
||||
{
|
||||
/* account for the automatically-added left padding */
|
||||
x--;
|
||||
width++;
|
||||
/* account for the automatically-added left padding */
|
||||
x--;
|
||||
width++;
|
||||
|
||||
NMT_NEWT_WIDGET_CLASS (nmt_newt_button_parent_class)->size_allocate (widget, x, y, width, height);
|
||||
NMT_NEWT_WIDGET_CLASS(nmt_newt_button_parent_class)->size_allocate(widget, x, y, width, height);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_button_activated (NmtNewtWidget *widget)
|
||||
nmt_newt_button_activated(NmtNewtWidget *widget)
|
||||
{
|
||||
g_signal_emit (widget, signals[CLICKED], 0);
|
||||
g_signal_emit(widget, signals[CLICKED], 0);
|
||||
|
||||
NMT_NEWT_WIDGET_CLASS (nmt_newt_button_parent_class)->activated (widget);
|
||||
NMT_NEWT_WIDGET_CLASS(nmt_newt_button_parent_class)->activated(widget);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_button_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_button_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id) {
|
||||
case PROP_LABEL:
|
||||
nmt_newt_button_set_label (NMT_NEWT_BUTTON (object),
|
||||
g_value_get_string (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_LABEL:
|
||||
nmt_newt_button_set_label(NMT_NEWT_BUTTON(object), g_value_get_string(value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_button_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_button_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE (object);
|
||||
NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_LABEL:
|
||||
g_value_set_string (value, priv->label);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_LABEL:
|
||||
g_value_set_string(value, priv->label);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_button_class_init (NmtNewtButtonClass *button_class)
|
||||
nmt_newt_button_class_init(NmtNewtButtonClass *button_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (button_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS (button_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (button_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(button_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(button_class);
|
||||
NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(button_class);
|
||||
|
||||
g_type_class_add_private (button_class, sizeof (NmtNewtButtonPrivate));
|
||||
g_type_class_add_private(button_class, sizeof(NmtNewtButtonPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_button_set_property;
|
||||
object_class->get_property = nmt_newt_button_get_property;
|
||||
object_class->finalize = nmt_newt_button_finalize;
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_button_set_property;
|
||||
object_class->get_property = nmt_newt_button_get_property;
|
||||
object_class->finalize = nmt_newt_button_finalize;
|
||||
|
||||
widget_class->size_request = nmt_newt_button_size_request;
|
||||
widget_class->size_allocate = nmt_newt_button_size_allocate;
|
||||
widget_class->activated = nmt_newt_button_activated;
|
||||
widget_class->size_request = nmt_newt_button_size_request;
|
||||
widget_class->size_allocate = nmt_newt_button_size_allocate;
|
||||
widget_class->activated = nmt_newt_button_activated;
|
||||
|
||||
component_class->build_component = nmt_newt_button_build_component;
|
||||
component_class->build_component = nmt_newt_button_build_component;
|
||||
|
||||
/* signals */
|
||||
/* signals */
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtButton::clicked:
|
||||
* @button: the #NmtNewtButton
|
||||
*
|
||||
* Emitted when the button is clicked.
|
||||
*/
|
||||
signals[CLICKED] =
|
||||
g_signal_new ("clicked",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
0, NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
signals[CLICKED] = g_signal_new("clicked",
|
||||
G_OBJECT_CLASS_TYPE(object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE,
|
||||
0);
|
||||
|
||||
/* properties */
|
||||
/* properties */
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtButton:label:
|
||||
*
|
||||
* The button's label
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_LABEL,
|
||||
g_param_spec_string ("label", "", "",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_LABEL,
|
||||
g_param_spec_string("label", "", "", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,29 +8,30 @@
|
|||
|
||||
#include "nmt-newt-component.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_BUTTON (nmt_newt_button_get_type ())
|
||||
#define NMT_NEWT_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_BUTTON, NmtNewtButton))
|
||||
#define NMT_NEWT_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_BUTTON, NmtNewtButtonClass))
|
||||
#define NMT_IS_NEWT_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_BUTTON))
|
||||
#define NMT_IS_NEWT_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_BUTTON))
|
||||
#define NMT_NEWT_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_BUTTON, NmtNewtButtonClass))
|
||||
#define NMT_TYPE_NEWT_BUTTON (nmt_newt_button_get_type())
|
||||
#define NMT_NEWT_BUTTON(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_BUTTON, NmtNewtButton))
|
||||
#define NMT_NEWT_BUTTON_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_BUTTON, NmtNewtButtonClass))
|
||||
#define NMT_IS_NEWT_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_BUTTON))
|
||||
#define NMT_IS_NEWT_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_BUTTON))
|
||||
#define NMT_NEWT_BUTTON_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_BUTTON, NmtNewtButtonClass))
|
||||
|
||||
struct _NmtNewtButton {
|
||||
NmtNewtComponent parent;
|
||||
|
||||
NmtNewtComponent parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtComponentClass parent;
|
||||
NmtNewtComponentClass parent;
|
||||
|
||||
} NmtNewtButtonClass;
|
||||
|
||||
GType nmt_newt_button_get_type (void);
|
||||
GType nmt_newt_button_get_type(void);
|
||||
|
||||
NmtNewtWidget *nmt_newt_button_new (const char *label);
|
||||
NmtNewtWidget *nmt_newt_button_new(const char *label);
|
||||
|
||||
void nmt_newt_button_set_label (NmtNewtButton *button,
|
||||
const char *label);
|
||||
const char *nmt_newt_button_get_label (NmtNewtButton *button);
|
||||
void nmt_newt_button_set_label(NmtNewtButton *button, const char *label);
|
||||
const char *nmt_newt_button_get_label(NmtNewtButton *button);
|
||||
|
||||
#endif /* NMT_NEWT_BUTTON_H */
|
||||
|
|
|
|||
|
|
@ -15,21 +15,22 @@
|
|||
#include "nmt-newt-checkbox.h"
|
||||
#include "nmt-newt-utils.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtNewtCheckbox, nmt_newt_checkbox, NMT_TYPE_NEWT_COMPONENT)
|
||||
G_DEFINE_TYPE(NmtNewtCheckbox, nmt_newt_checkbox, NMT_TYPE_NEWT_COMPONENT)
|
||||
|
||||
#define NMT_NEWT_CHECKBOX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_CHECKBOX, NmtNewtCheckboxPrivate))
|
||||
#define NMT_NEWT_CHECKBOX_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_CHECKBOX, NmtNewtCheckboxPrivate))
|
||||
|
||||
typedef struct {
|
||||
char *label_lc;
|
||||
gboolean active;
|
||||
char * label_lc;
|
||||
gboolean active;
|
||||
} NmtNewtCheckboxPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_LABEL,
|
||||
PROP_ACTIVE,
|
||||
PROP_0,
|
||||
PROP_LABEL,
|
||||
PROP_ACTIVE,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
#define CHECKBOX_INACTIVE ' '
|
||||
|
|
@ -45,11 +46,9 @@ enum {
|
|||
* Returns: a new #NmtNewtCheckbox
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_checkbox_new (const char *label)
|
||||
nmt_newt_checkbox_new(const char *label)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_NEWT_CHECKBOX,
|
||||
"label", label,
|
||||
NULL);
|
||||
return g_object_new(NMT_TYPE_NEWT_CHECKBOX, "label", label, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -60,23 +59,22 @@ nmt_newt_checkbox_new (const char *label)
|
|||
* Updates @checkbox's checked state
|
||||
*/
|
||||
void
|
||||
nmt_newt_checkbox_set_active (NmtNewtCheckbox *checkbox,
|
||||
gboolean active)
|
||||
nmt_newt_checkbox_set_active(NmtNewtCheckbox *checkbox, gboolean active)
|
||||
{
|
||||
NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE (checkbox);
|
||||
newtComponent co;
|
||||
NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE(checkbox);
|
||||
newtComponent co;
|
||||
|
||||
active = !!active;
|
||||
if (active == priv->active)
|
||||
return;
|
||||
active = !!active;
|
||||
if (active == priv->active)
|
||||
return;
|
||||
|
||||
priv->active = active;
|
||||
priv->active = active;
|
||||
|
||||
co = nmt_newt_component_get_component (NMT_NEWT_COMPONENT (checkbox));
|
||||
if (co)
|
||||
newtCheckboxSetValue (co, priv->active ? CHECKBOX_ACTIVE : CHECKBOX_INACTIVE);
|
||||
co = nmt_newt_component_get_component(NMT_NEWT_COMPONENT(checkbox));
|
||||
if (co)
|
||||
newtCheckboxSetValue(co, priv->active ? CHECKBOX_ACTIVE : CHECKBOX_INACTIVE);
|
||||
|
||||
g_object_notify (G_OBJECT (checkbox), "active");
|
||||
g_object_notify(G_OBJECT(checkbox), "active");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -88,137 +86,130 @@ nmt_newt_checkbox_set_active (NmtNewtCheckbox *checkbox,
|
|||
* Returns: @checkbox's checked state
|
||||
*/
|
||||
gboolean
|
||||
nmt_newt_checkbox_get_active (NmtNewtCheckbox *checkbox)
|
||||
nmt_newt_checkbox_get_active(NmtNewtCheckbox *checkbox)
|
||||
{
|
||||
NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE (checkbox);
|
||||
NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE(checkbox);
|
||||
|
||||
return priv->active;
|
||||
return priv->active;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_checkbox_init (NmtNewtCheckbox *checkbox)
|
||||
nmt_newt_checkbox_init(NmtNewtCheckbox *checkbox)
|
||||
{}
|
||||
|
||||
static void
|
||||
nmt_newt_checkbox_finalize(GObject *object)
|
||||
{
|
||||
NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE(object);
|
||||
|
||||
g_free(priv->label_lc);
|
||||
|
||||
G_OBJECT_CLASS(nmt_newt_checkbox_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_checkbox_finalize (GObject *object)
|
||||
checkbox_toggled_callback(newtComponent co, void *checkbox)
|
||||
{
|
||||
NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE (object);
|
||||
NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE(checkbox);
|
||||
gboolean active;
|
||||
|
||||
g_free (priv->label_lc);
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_checkbox_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
checkbox_toggled_callback (newtComponent co,
|
||||
void *checkbox)
|
||||
{
|
||||
NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE (checkbox);
|
||||
gboolean active;
|
||||
|
||||
active = (newtCheckboxGetValue (co) == CHECKBOX_ACTIVE);
|
||||
if (active != priv->active) {
|
||||
priv->active = active;
|
||||
g_object_notify (checkbox, "active");
|
||||
}
|
||||
active = (newtCheckboxGetValue(co) == CHECKBOX_ACTIVE);
|
||||
if (active != priv->active) {
|
||||
priv->active = active;
|
||||
g_object_notify(checkbox, "active");
|
||||
}
|
||||
}
|
||||
|
||||
static newtComponent
|
||||
nmt_newt_checkbox_build_component (NmtNewtComponent *component,
|
||||
gboolean sensitive)
|
||||
nmt_newt_checkbox_build_component(NmtNewtComponent *component, gboolean sensitive)
|
||||
{
|
||||
NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE (component);
|
||||
newtComponent co;
|
||||
NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE(component);
|
||||
newtComponent co;
|
||||
|
||||
co = newtCheckbox (-1, -1, priv->label_lc,
|
||||
priv->active ? CHECKBOX_ACTIVE : CHECKBOX_INACTIVE,
|
||||
CHECKBOX_STATES, NULL);
|
||||
if (!sensitive)
|
||||
newtCheckboxSetFlags (co, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
|
||||
newtComponentAddCallback (co, checkbox_toggled_callback, component);
|
||||
return co;
|
||||
co = newtCheckbox(-1,
|
||||
-1,
|
||||
priv->label_lc,
|
||||
priv->active ? CHECKBOX_ACTIVE : CHECKBOX_INACTIVE,
|
||||
CHECKBOX_STATES,
|
||||
NULL);
|
||||
if (!sensitive)
|
||||
newtCheckboxSetFlags(co, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
|
||||
newtComponentAddCallback(co, checkbox_toggled_callback, component);
|
||||
return co;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_checkbox_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_checkbox_set_property(GObject * object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
NmtNewtCheckbox *checkbox = NMT_NEWT_CHECKBOX (object);
|
||||
NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE (object);
|
||||
NmtNewtCheckbox * checkbox = NMT_NEWT_CHECKBOX(object);
|
||||
NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_LABEL:
|
||||
g_free (priv->label_lc);
|
||||
priv->label_lc = nmt_newt_locale_from_utf8 (g_value_get_string (value));
|
||||
break;
|
||||
case PROP_ACTIVE:
|
||||
nmt_newt_checkbox_set_active (checkbox, g_value_get_boolean (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_LABEL:
|
||||
g_free(priv->label_lc);
|
||||
priv->label_lc = nmt_newt_locale_from_utf8(g_value_get_string(value));
|
||||
break;
|
||||
case PROP_ACTIVE:
|
||||
nmt_newt_checkbox_set_active(checkbox, g_value_get_boolean(value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_checkbox_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_checkbox_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE (object);
|
||||
NmtNewtCheckboxPrivate *priv = NMT_NEWT_CHECKBOX_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_LABEL:
|
||||
g_value_take_string (value, nmt_newt_locale_to_utf8 (priv->label_lc));
|
||||
break;
|
||||
case PROP_ACTIVE:
|
||||
g_value_set_boolean (value, priv->active);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_LABEL:
|
||||
g_value_take_string(value, nmt_newt_locale_to_utf8(priv->label_lc));
|
||||
break;
|
||||
case PROP_ACTIVE:
|
||||
g_value_set_boolean(value, priv->active);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_checkbox_class_init (NmtNewtCheckboxClass *checkbox_class)
|
||||
nmt_newt_checkbox_class_init(NmtNewtCheckboxClass *checkbox_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (checkbox_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS (checkbox_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(checkbox_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(checkbox_class);
|
||||
|
||||
g_type_class_add_private (checkbox_class, sizeof (NmtNewtCheckboxPrivate));
|
||||
g_type_class_add_private(checkbox_class, sizeof(NmtNewtCheckboxPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_checkbox_set_property;
|
||||
object_class->get_property = nmt_newt_checkbox_get_property;
|
||||
object_class->finalize = nmt_newt_checkbox_finalize;
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_checkbox_set_property;
|
||||
object_class->get_property = nmt_newt_checkbox_get_property;
|
||||
object_class->finalize = nmt_newt_checkbox_finalize;
|
||||
|
||||
component_class->build_component = nmt_newt_checkbox_build_component;
|
||||
component_class->build_component = nmt_newt_checkbox_build_component;
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtCheckbox:label:
|
||||
*
|
||||
* The checkbox's label
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_LABEL,
|
||||
g_param_spec_string ("label", "", "",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_LABEL,
|
||||
g_param_spec_string("label", "", "", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtCheckbox:active:
|
||||
*
|
||||
* The checkbox's checked state
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ACTIVE,
|
||||
g_param_spec_boolean ("active", "", "",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_ACTIVE,
|
||||
g_param_spec_boolean("active", "", "", FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,29 +8,30 @@
|
|||
|
||||
#include "nmt-newt-component.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_CHECKBOX (nmt_newt_checkbox_get_type ())
|
||||
#define NMT_NEWT_CHECKBOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_CHECKBOX, NmtNewtCheckbox))
|
||||
#define NMT_NEWT_CHECKBOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_CHECKBOX, NmtNewtCheckboxClass))
|
||||
#define NMT_IS_NEWT_CHECKBOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_CHECKBOX))
|
||||
#define NMT_IS_NEWT_CHECKBOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_CHECKBOX))
|
||||
#define NMT_NEWT_CHECKBOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_CHECKBOX, NmtNewtCheckboxClass))
|
||||
#define NMT_TYPE_NEWT_CHECKBOX (nmt_newt_checkbox_get_type())
|
||||
#define NMT_NEWT_CHECKBOX(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_CHECKBOX, NmtNewtCheckbox))
|
||||
#define NMT_NEWT_CHECKBOX_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_CHECKBOX, NmtNewtCheckboxClass))
|
||||
#define NMT_IS_NEWT_CHECKBOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_CHECKBOX))
|
||||
#define NMT_IS_NEWT_CHECKBOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_CHECKBOX))
|
||||
#define NMT_NEWT_CHECKBOX_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_CHECKBOX, NmtNewtCheckboxClass))
|
||||
|
||||
struct _NmtNewtCheckbox {
|
||||
NmtNewtComponent parent;
|
||||
|
||||
NmtNewtComponent parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtComponentClass parent;
|
||||
NmtNewtComponentClass parent;
|
||||
|
||||
} NmtNewtCheckboxClass;
|
||||
|
||||
GType nmt_newt_checkbox_get_type (void);
|
||||
GType nmt_newt_checkbox_get_type(void);
|
||||
|
||||
NmtNewtWidget *nmt_newt_checkbox_new (const char *label);
|
||||
NmtNewtWidget *nmt_newt_checkbox_new(const char *label);
|
||||
|
||||
void nmt_newt_checkbox_set_active (NmtNewtCheckbox *checkbox,
|
||||
gboolean active);
|
||||
gboolean nmt_newt_checkbox_get_active (NmtNewtCheckbox *checkbox);
|
||||
void nmt_newt_checkbox_set_active(NmtNewtCheckbox *checkbox, gboolean active);
|
||||
gboolean nmt_newt_checkbox_get_active(NmtNewtCheckbox *checkbox);
|
||||
|
||||
#endif /* NMT_NEWT_CHECKBOX_H */
|
||||
|
|
|
|||
|
|
@ -17,136 +17,136 @@
|
|||
#include "nmt-newt-form.h"
|
||||
#include "nmt-newt-hacks.h"
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (NmtNewtComponent, nmt_newt_component, NMT_TYPE_NEWT_WIDGET)
|
||||
G_DEFINE_ABSTRACT_TYPE(NmtNewtComponent, nmt_newt_component, NMT_TYPE_NEWT_WIDGET)
|
||||
|
||||
#define NMT_NEWT_COMPONENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_COMPONENT, NmtNewtComponentPrivate))
|
||||
#define NMT_NEWT_COMPONENT_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_COMPONENT, NmtNewtComponentPrivate))
|
||||
|
||||
typedef struct {
|
||||
newtComponent co;
|
||||
gboolean own_component;
|
||||
gboolean sensitive;
|
||||
newtComponent co;
|
||||
gboolean own_component;
|
||||
gboolean sensitive;
|
||||
} NmtNewtComponentPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_0,
|
||||
|
||||
PROP_COMPONENT,
|
||||
PROP_SENSITIVE,
|
||||
PROP_COMPONENT,
|
||||
PROP_SENSITIVE,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
static void
|
||||
nmt_newt_component_init (NmtNewtComponent *component)
|
||||
nmt_newt_component_init(NmtNewtComponent *component)
|
||||
{
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE (component);
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE(component);
|
||||
|
||||
priv->sensitive = TRUE;
|
||||
priv->sensitive = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_component_unrealize (NmtNewtWidget *widget)
|
||||
nmt_newt_component_unrealize(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE (widget);
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE(widget);
|
||||
|
||||
if (!priv->co)
|
||||
return;
|
||||
if (!priv->co)
|
||||
return;
|
||||
|
||||
newtComponentAddCallback (priv->co, NULL, NULL);
|
||||
newtComponentAddDestroyCallback (priv->co, NULL, NULL);
|
||||
newtComponentAddCallback(priv->co, NULL, NULL);
|
||||
newtComponentAddDestroyCallback(priv->co, NULL, NULL);
|
||||
|
||||
if (priv->own_component)
|
||||
newtComponentDestroy (priv->co);
|
||||
priv->co = NULL;
|
||||
if (priv->own_component)
|
||||
newtComponentDestroy(priv->co);
|
||||
priv->co = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
component_destroy_callback (newtComponent co,
|
||||
void *component)
|
||||
component_destroy_callback(newtComponent co, void *component)
|
||||
{
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE (component);
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE(component);
|
||||
|
||||
priv->own_component = FALSE;
|
||||
nmt_newt_widget_unrealize (component);
|
||||
nmt_newt_widget_needs_rebuild (component);
|
||||
priv->own_component = FALSE;
|
||||
nmt_newt_widget_unrealize(component);
|
||||
nmt_newt_widget_needs_rebuild(component);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_component_realize (NmtNewtWidget *widget)
|
||||
nmt_newt_component_realize(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE (widget);
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE(widget);
|
||||
|
||||
nmt_newt_component_unrealize (widget);
|
||||
priv->co = NMT_NEWT_COMPONENT_GET_CLASS (widget)->
|
||||
build_component (NMT_NEWT_COMPONENT (widget), priv->sensitive);
|
||||
priv->own_component = TRUE;
|
||||
if (!priv->sensitive)
|
||||
newtComponentTakesFocus (priv->co, FALSE);
|
||||
newtComponentAddDestroyCallback (priv->co, component_destroy_callback, widget);
|
||||
nmt_newt_component_unrealize(widget);
|
||||
priv->co = NMT_NEWT_COMPONENT_GET_CLASS(widget)->build_component(NMT_NEWT_COMPONENT(widget),
|
||||
priv->sensitive);
|
||||
priv->own_component = TRUE;
|
||||
if (!priv->sensitive)
|
||||
newtComponentTakesFocus(priv->co, FALSE);
|
||||
newtComponentAddDestroyCallback(priv->co, component_destroy_callback, widget);
|
||||
}
|
||||
|
||||
static newtComponent *
|
||||
nmt_newt_component_get_components (NmtNewtWidget *widget)
|
||||
nmt_newt_component_get_components(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE (widget);
|
||||
newtComponent *cos;
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE(widget);
|
||||
newtComponent * cos;
|
||||
|
||||
priv->own_component = FALSE;
|
||||
cos = g_new0 (newtComponent, 2);
|
||||
cos[0] = priv->co;
|
||||
return cos;
|
||||
priv->own_component = FALSE;
|
||||
cos = g_new0(newtComponent, 2);
|
||||
cos[0] = priv->co;
|
||||
return cos;
|
||||
}
|
||||
|
||||
static NmtNewtWidget *
|
||||
nmt_newt_component_find_component (NmtNewtWidget *widget,
|
||||
newtComponent co)
|
||||
nmt_newt_component_find_component(NmtNewtWidget *widget, newtComponent co)
|
||||
{
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE (widget);
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE(widget);
|
||||
|
||||
if (co == priv->co)
|
||||
return widget;
|
||||
else
|
||||
return NULL;
|
||||
if (co == priv->co)
|
||||
return widget;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_component_size_request (NmtNewtWidget *widget,
|
||||
int *width,
|
||||
int *height)
|
||||
nmt_newt_component_size_request(NmtNewtWidget *widget, int *width, int *height)
|
||||
{
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE (widget);
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE(widget);
|
||||
|
||||
newtComponentGetSize (priv->co, width, height);
|
||||
newtComponentGetSize(priv->co, width, height);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_component_size_allocate (NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height)
|
||||
nmt_newt_component_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height)
|
||||
{
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE (widget);
|
||||
newtGrid grid;
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE(widget);
|
||||
newtGrid grid;
|
||||
|
||||
/* You can't directly place a newtComponent, so we create a newtGrid,
|
||||
/* You can't directly place a newtComponent, so we create a newtGrid,
|
||||
* position the component within that, and then place the grid.
|
||||
*/
|
||||
grid = newtCreateGrid (1, 1);
|
||||
newtGridSetField (grid, 0, 0,
|
||||
NEWT_GRID_COMPONENT, priv->co,
|
||||
x, y, 0, 0,
|
||||
NEWT_ANCHOR_LEFT | NEWT_ANCHOR_TOP, 0);
|
||||
newtGridPlace (grid, 0, 0);
|
||||
newtGridFree (grid, FALSE);
|
||||
grid = newtCreateGrid(1, 1);
|
||||
newtGridSetField(grid,
|
||||
0,
|
||||
0,
|
||||
NEWT_GRID_COMPONENT,
|
||||
priv->co,
|
||||
x,
|
||||
y,
|
||||
0,
|
||||
0,
|
||||
NEWT_ANCHOR_LEFT | NEWT_ANCHOR_TOP,
|
||||
0);
|
||||
newtGridPlace(grid, 0, 0);
|
||||
newtGridFree(grid, FALSE);
|
||||
}
|
||||
|
||||
static newtComponent
|
||||
nmt_newt_component_get_focus_component (NmtNewtWidget *widget)
|
||||
nmt_newt_component_get_focus_component(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE (widget);
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE(widget);
|
||||
|
||||
return priv->co;
|
||||
return priv->co;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -161,11 +161,11 @@ nmt_newt_component_get_focus_component (NmtNewtWidget *widget)
|
|||
* Returns: @component's #newtComponent
|
||||
*/
|
||||
newtComponent
|
||||
nmt_newt_component_get_component (NmtNewtComponent *component)
|
||||
nmt_newt_component_get_component(NmtNewtComponent *component)
|
||||
{
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE (component);
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE(component);
|
||||
|
||||
return priv->co;
|
||||
return priv->co;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -180,11 +180,11 @@ nmt_newt_component_get_component (NmtNewtComponent *component)
|
|||
* Returns: @component's #NmtNewtComponent:sensitive property
|
||||
*/
|
||||
gboolean
|
||||
nmt_newt_component_get_sensitive (NmtNewtComponent *component)
|
||||
nmt_newt_component_get_sensitive(NmtNewtComponent *component)
|
||||
{
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE (component);
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE(component);
|
||||
|
||||
return priv->sensitive;
|
||||
return priv->sensitive;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -195,102 +195,99 @@ nmt_newt_component_get_sensitive (NmtNewtComponent *component)
|
|||
* Sets @component's #NmtNewtComponent:sensitive property.
|
||||
*/
|
||||
void
|
||||
nmt_newt_component_set_sensitive (NmtNewtComponent *component,
|
||||
gboolean sensitive)
|
||||
nmt_newt_component_set_sensitive(NmtNewtComponent *component, gboolean sensitive)
|
||||
{
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE (component);
|
||||
NmtNewtComponentPrivate *priv = NMT_NEWT_COMPONENT_GET_PRIVATE(component);
|
||||
|
||||
sensitive = !!sensitive;
|
||||
if (priv->sensitive == sensitive)
|
||||
return;
|
||||
sensitive = !!sensitive;
|
||||
if (priv->sensitive == sensitive)
|
||||
return;
|
||||
|
||||
priv->sensitive = sensitive;
|
||||
g_object_notify (G_OBJECT (component), "sensitive");
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (component));
|
||||
priv->sensitive = sensitive;
|
||||
g_object_notify(G_OBJECT(component), "sensitive");
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(component));
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_component_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_component_set_property(GObject * object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
NmtNewtComponent *component = NMT_NEWT_COMPONENT (object);
|
||||
NmtNewtComponent *component = NMT_NEWT_COMPONENT(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_SENSITIVE:
|
||||
nmt_newt_component_set_sensitive (component, g_value_get_boolean (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_SENSITIVE:
|
||||
nmt_newt_component_set_sensitive(component, g_value_get_boolean(value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_component_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_component_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtComponent *component = NMT_NEWT_COMPONENT (object);
|
||||
NmtNewtComponent *component = NMT_NEWT_COMPONENT(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_COMPONENT:
|
||||
g_value_set_pointer (value, nmt_newt_component_get_component (component));
|
||||
break;
|
||||
case PROP_SENSITIVE:
|
||||
g_value_set_boolean (value, nmt_newt_component_get_sensitive (component));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_COMPONENT:
|
||||
g_value_set_pointer(value, nmt_newt_component_get_component(component));
|
||||
break;
|
||||
case PROP_SENSITIVE:
|
||||
g_value_set_boolean(value, nmt_newt_component_get_sensitive(component));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_component_class_init (NmtNewtComponentClass *component_class)
|
||||
nmt_newt_component_class_init(NmtNewtComponentClass *component_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (component_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (component_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(component_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(component_class);
|
||||
|
||||
g_type_class_add_private (component_class, sizeof (NmtNewtComponentPrivate));
|
||||
g_type_class_add_private(component_class, sizeof(NmtNewtComponentPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_component_set_property;
|
||||
object_class->get_property = nmt_newt_component_get_property;
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_component_set_property;
|
||||
object_class->get_property = nmt_newt_component_get_property;
|
||||
|
||||
widget_class->realize = nmt_newt_component_realize;
|
||||
widget_class->unrealize = nmt_newt_component_unrealize;
|
||||
widget_class->get_components = nmt_newt_component_get_components;
|
||||
widget_class->find_component = nmt_newt_component_find_component;
|
||||
widget_class->size_request = nmt_newt_component_size_request;
|
||||
widget_class->size_allocate = nmt_newt_component_size_allocate;
|
||||
widget_class->get_focus_component = nmt_newt_component_get_focus_component;
|
||||
widget_class->realize = nmt_newt_component_realize;
|
||||
widget_class->unrealize = nmt_newt_component_unrealize;
|
||||
widget_class->get_components = nmt_newt_component_get_components;
|
||||
widget_class->find_component = nmt_newt_component_find_component;
|
||||
widget_class->size_request = nmt_newt_component_size_request;
|
||||
widget_class->size_allocate = nmt_newt_component_size_allocate;
|
||||
widget_class->get_focus_component = nmt_newt_component_get_focus_component;
|
||||
|
||||
/* properties */
|
||||
/* properties */
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtComponent:component:
|
||||
*
|
||||
* The component's #newtComponent
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_COMPONENT,
|
||||
g_param_spec_pointer ("component", "", "",
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_COMPONENT,
|
||||
g_param_spec_pointer("component", "", "", G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtComponent:sensitive:
|
||||
*
|
||||
* Whether the component is sensitive. Insensitive components will
|
||||
* be skipped over in the keyboard tab chain, and may be displayed
|
||||
* differently.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_SENSITIVE,
|
||||
g_param_spec_boolean ("sensitive", "", "",
|
||||
TRUE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_SENSITIVE,
|
||||
g_param_spec_boolean("sensitive",
|
||||
"",
|
||||
"",
|
||||
TRUE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,33 +8,34 @@
|
|||
|
||||
#include "nmt-newt-widget.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_COMPONENT (nmt_newt_component_get_type ())
|
||||
#define NMT_NEWT_COMPONENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_COMPONENT, NmtNewtComponent))
|
||||
#define NMT_NEWT_COMPONENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_COMPONENT, NmtNewtComponentClass))
|
||||
#define NMT_IS_NEWT_COMPONENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_COMPONENT))
|
||||
#define NMT_IS_NEWT_COMPONENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_COMPONENT))
|
||||
#define NMT_NEWT_COMPONENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_COMPONENT, NmtNewtComponentClass))
|
||||
#define NMT_TYPE_NEWT_COMPONENT (nmt_newt_component_get_type())
|
||||
#define NMT_NEWT_COMPONENT(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_COMPONENT, NmtNewtComponent))
|
||||
#define NMT_NEWT_COMPONENT_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_COMPONENT, NmtNewtComponentClass))
|
||||
#define NMT_IS_NEWT_COMPONENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_COMPONENT))
|
||||
#define NMT_IS_NEWT_COMPONENT_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_COMPONENT))
|
||||
#define NMT_NEWT_COMPONENT_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_COMPONENT, NmtNewtComponentClass))
|
||||
|
||||
struct _NmtNewtComponent {
|
||||
NmtNewtWidget parent;
|
||||
|
||||
NmtNewtWidget parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtWidgetClass parent;
|
||||
NmtNewtWidgetClass parent;
|
||||
|
||||
/* methods */
|
||||
newtComponent (*build_component) (NmtNewtComponent *component,
|
||||
gboolean sensitive);
|
||||
/* methods */
|
||||
newtComponent (*build_component)(NmtNewtComponent *component, gboolean sensitive);
|
||||
|
||||
} NmtNewtComponentClass;
|
||||
|
||||
GType nmt_newt_component_get_type (void);
|
||||
GType nmt_newt_component_get_type(void);
|
||||
|
||||
newtComponent nmt_newt_component_get_component (NmtNewtComponent *component);
|
||||
newtComponent nmt_newt_component_get_component(NmtNewtComponent *component);
|
||||
|
||||
gboolean nmt_newt_component_get_sensitive (NmtNewtComponent *component);
|
||||
void nmt_newt_component_set_sensitive (NmtNewtComponent *component,
|
||||
gboolean sensitive);
|
||||
gboolean nmt_newt_component_get_sensitive(NmtNewtComponent *component);
|
||||
void nmt_newt_component_set_sensitive(NmtNewtComponent *component, gboolean sensitive);
|
||||
|
||||
#endif /* NMT_NEWT_COMPONENT_H */
|
||||
|
|
|
|||
|
|
@ -19,145 +19,142 @@
|
|||
|
||||
#include "nmt-newt-component.h"
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (NmtNewtContainer, nmt_newt_container, NMT_TYPE_NEWT_WIDGET)
|
||||
G_DEFINE_ABSTRACT_TYPE(NmtNewtContainer, nmt_newt_container, NMT_TYPE_NEWT_WIDGET)
|
||||
|
||||
#define NMT_NEWT_CONTAINER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_CONTAINER, NmtNewtContainerPrivate))
|
||||
#define NMT_NEWT_CONTAINER_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_CONTAINER, NmtNewtContainerPrivate))
|
||||
|
||||
typedef struct {
|
||||
GPtrArray *children;
|
||||
GPtrArray *children;
|
||||
|
||||
} NmtNewtContainerPrivate;
|
||||
|
||||
static void child_needs_rebuild (NmtNewtWidget *widget, gpointer user_data);
|
||||
static void child_needs_rebuild(NmtNewtWidget *widget, gpointer user_data);
|
||||
|
||||
static void
|
||||
nmt_newt_container_init (NmtNewtContainer *container)
|
||||
nmt_newt_container_init(NmtNewtContainer *container)
|
||||
{
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE (container);
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE(container);
|
||||
|
||||
priv->children = g_ptr_array_new ();
|
||||
priv->children = g_ptr_array_new();
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_container_finalize (GObject *object)
|
||||
nmt_newt_container_finalize(GObject *object)
|
||||
{
|
||||
NmtNewtContainer *container = NMT_NEWT_CONTAINER (object);
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE (object);
|
||||
NmtNewtContainer * container = NMT_NEWT_CONTAINER(object);
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE(object);
|
||||
|
||||
while (priv->children->len)
|
||||
nmt_newt_container_remove (container, priv->children->pdata[0]);
|
||||
while (priv->children->len)
|
||||
nmt_newt_container_remove(container, priv->children->pdata[0]);
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_container_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS(nmt_newt_container_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_container_realize (NmtNewtWidget *widget)
|
||||
nmt_newt_container_realize(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE (widget);
|
||||
int i;
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE(widget);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < priv->children->len; i++)
|
||||
nmt_newt_widget_realize (priv->children->pdata[i]);
|
||||
for (i = 0; i < priv->children->len; i++)
|
||||
nmt_newt_widget_realize(priv->children->pdata[i]);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_container_unrealize (NmtNewtWidget *widget)
|
||||
nmt_newt_container_unrealize(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE (widget);
|
||||
int i;
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE(widget);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < priv->children->len; i++)
|
||||
nmt_newt_widget_unrealize (priv->children->pdata[i]);
|
||||
for (i = 0; i < priv->children->len; i++)
|
||||
nmt_newt_widget_unrealize(priv->children->pdata[i]);
|
||||
}
|
||||
|
||||
static void
|
||||
child_needs_rebuild (NmtNewtWidget *widget,
|
||||
gpointer user_data)
|
||||
child_needs_rebuild(NmtNewtWidget *widget, gpointer user_data)
|
||||
{
|
||||
NmtNewtWidget *container = user_data;
|
||||
NmtNewtWidget *container = user_data;
|
||||
|
||||
nmt_newt_widget_needs_rebuild (container);
|
||||
nmt_newt_widget_needs_rebuild(container);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_container_real_child_validity_changed (NmtNewtContainer *container,
|
||||
NmtNewtWidget *widget)
|
||||
nmt_newt_container_real_child_validity_changed(NmtNewtContainer *container, NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtContainerPrivate *priv;
|
||||
int i;
|
||||
NmtNewtContainerPrivate *priv;
|
||||
int i;
|
||||
|
||||
if (widget) {
|
||||
if (!nmt_newt_widget_get_visible (widget))
|
||||
return;
|
||||
if (!nmt_newt_widget_get_valid (widget)) {
|
||||
nmt_newt_widget_set_valid (NMT_NEWT_WIDGET (container), FALSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (widget) {
|
||||
if (!nmt_newt_widget_get_visible(widget))
|
||||
return;
|
||||
if (!nmt_newt_widget_get_valid(widget)) {
|
||||
nmt_newt_widget_set_valid(NMT_NEWT_WIDGET(container), FALSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
priv = NMT_NEWT_CONTAINER_GET_PRIVATE (container);
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
widget = priv->children->pdata[i];
|
||||
if ( nmt_newt_widget_get_visible (widget)
|
||||
&& !nmt_newt_widget_get_valid (widget)) {
|
||||
nmt_newt_widget_set_valid (NMT_NEWT_WIDGET (container), FALSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
priv = NMT_NEWT_CONTAINER_GET_PRIVATE(container);
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
widget = priv->children->pdata[i];
|
||||
if (nmt_newt_widget_get_visible(widget) && !nmt_newt_widget_get_valid(widget)) {
|
||||
nmt_newt_widget_set_valid(NMT_NEWT_WIDGET(container), FALSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nmt_newt_widget_set_valid (NMT_NEWT_WIDGET (container), TRUE);
|
||||
nmt_newt_widget_set_valid(NMT_NEWT_WIDGET(container), TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_container_child_validity_changed (NmtNewtContainer *container,
|
||||
NmtNewtWidget *widget)
|
||||
nmt_newt_container_child_validity_changed(NmtNewtContainer *container, NmtNewtWidget *widget)
|
||||
{
|
||||
NMT_NEWT_CONTAINER_GET_CLASS (container)->child_validity_changed (container, widget);
|
||||
NMT_NEWT_CONTAINER_GET_CLASS(container)->child_validity_changed(container, widget);
|
||||
}
|
||||
|
||||
static void
|
||||
child_validity_notify (GObject *object,
|
||||
GParamSpec *pspec,
|
||||
gpointer container)
|
||||
child_validity_notify(GObject *object, GParamSpec *pspec, gpointer container)
|
||||
{
|
||||
nmt_newt_container_child_validity_changed (container, NMT_NEWT_WIDGET (object));
|
||||
nmt_newt_container_child_validity_changed(container, NMT_NEWT_WIDGET(object));
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_container_real_add (NmtNewtContainer *container,
|
||||
NmtNewtWidget *widget)
|
||||
nmt_newt_container_real_add(NmtNewtContainer *container, NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE (container);
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE(container);
|
||||
|
||||
g_signal_connect (widget, "needs-rebuild", G_CALLBACK (child_needs_rebuild), container);
|
||||
g_signal_connect (widget, "notify::valid", G_CALLBACK (child_validity_notify), container);
|
||||
g_ptr_array_add (priv->children, g_object_ref_sink (widget));
|
||||
nmt_newt_widget_set_parent (widget, NMT_NEWT_WIDGET (container));
|
||||
g_signal_connect(widget, "needs-rebuild", G_CALLBACK(child_needs_rebuild), container);
|
||||
g_signal_connect(widget, "notify::valid", G_CALLBACK(child_validity_notify), container);
|
||||
g_ptr_array_add(priv->children, g_object_ref_sink(widget));
|
||||
nmt_newt_widget_set_parent(widget, NMT_NEWT_WIDGET(container));
|
||||
|
||||
nmt_newt_container_child_validity_changed (container, widget);
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (container));
|
||||
nmt_newt_container_child_validity_changed(container, widget);
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(container));
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_container_real_remove (NmtNewtContainer *container,
|
||||
NmtNewtWidget *widget)
|
||||
nmt_newt_container_real_remove(NmtNewtContainer *container, NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE (container);
|
||||
int i;
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE(container);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
if (widget == priv->children->pdata[i]) {
|
||||
g_ptr_array_remove_index (priv->children, i);
|
||||
g_signal_handlers_disconnect_by_func (widget, G_CALLBACK (child_needs_rebuild), container);
|
||||
g_signal_handlers_disconnect_by_func (widget, G_CALLBACK (child_validity_notify), container);
|
||||
nmt_newt_widget_set_parent (widget, NULL);
|
||||
g_object_unref (widget);
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
if (widget == priv->children->pdata[i]) {
|
||||
g_ptr_array_remove_index(priv->children, i);
|
||||
g_signal_handlers_disconnect_by_func(widget,
|
||||
G_CALLBACK(child_needs_rebuild),
|
||||
container);
|
||||
g_signal_handlers_disconnect_by_func(widget,
|
||||
G_CALLBACK(child_validity_notify),
|
||||
container);
|
||||
nmt_newt_widget_set_parent(widget, NULL);
|
||||
g_object_unref(widget);
|
||||
|
||||
nmt_newt_container_child_validity_changed (container, NULL);
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (container));
|
||||
return;
|
||||
}
|
||||
}
|
||||
nmt_newt_container_child_validity_changed(container, NULL);
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(container));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -172,29 +169,27 @@ nmt_newt_container_real_remove (NmtNewtContainer *container,
|
|||
* container-type-specific methods to add widgets to containers.
|
||||
*/
|
||||
void
|
||||
nmt_newt_container_remove (NmtNewtContainer *container,
|
||||
NmtNewtWidget *widget)
|
||||
nmt_newt_container_remove(NmtNewtContainer *container, NmtNewtWidget *widget)
|
||||
{
|
||||
NMT_NEWT_CONTAINER_GET_CLASS (container)->remove (container, widget);
|
||||
NMT_NEWT_CONTAINER_GET_CLASS(container)->remove(container, widget);
|
||||
}
|
||||
|
||||
static NmtNewtWidget *
|
||||
nmt_newt_container_find_component (NmtNewtWidget *widget,
|
||||
newtComponent co)
|
||||
nmt_newt_container_find_component(NmtNewtWidget *widget, newtComponent co)
|
||||
{
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE (widget);
|
||||
NmtNewtWidget *found, *child;
|
||||
int i;
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE(widget);
|
||||
NmtNewtWidget * found, *child;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
child = priv->children->pdata[i];
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
child = priv->children->pdata[i];
|
||||
|
||||
found = nmt_newt_widget_find_component (child, co);
|
||||
if (found)
|
||||
return found;
|
||||
}
|
||||
found = nmt_newt_widget_find_component(child, co);
|
||||
if (found)
|
||||
return found;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -206,33 +201,33 @@ nmt_newt_container_find_component (NmtNewtWidget *widget,
|
|||
* Returns: (transfer full): a list of @container's children.
|
||||
*/
|
||||
GSList *
|
||||
nmt_newt_container_get_children (NmtNewtContainer *container)
|
||||
nmt_newt_container_get_children(NmtNewtContainer *container)
|
||||
{
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE (container);
|
||||
GSList *ret;
|
||||
int i;
|
||||
NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE(container);
|
||||
GSList * ret;
|
||||
int i;
|
||||
|
||||
for (i = 0, ret = NULL; i < priv->children->len; i++)
|
||||
ret = g_slist_prepend (ret, g_object_ref (priv->children->pdata[i]));
|
||||
return g_slist_reverse (ret);
|
||||
for (i = 0, ret = NULL; i < priv->children->len; i++)
|
||||
ret = g_slist_prepend(ret, g_object_ref(priv->children->pdata[i]));
|
||||
return g_slist_reverse(ret);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_container_class_init (NmtNewtContainerClass *container_class)
|
||||
nmt_newt_container_class_init(NmtNewtContainerClass *container_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (container_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (container_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(container_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(container_class);
|
||||
|
||||
g_type_class_add_private (container_class, sizeof (NmtNewtContainerPrivate));
|
||||
g_type_class_add_private(container_class, sizeof(NmtNewtContainerPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->finalize = nmt_newt_container_finalize;
|
||||
/* virtual methods */
|
||||
object_class->finalize = nmt_newt_container_finalize;
|
||||
|
||||
widget_class->realize = nmt_newt_container_realize;
|
||||
widget_class->unrealize = nmt_newt_container_unrealize;
|
||||
widget_class->find_component = nmt_newt_container_find_component;
|
||||
widget_class->realize = nmt_newt_container_realize;
|
||||
widget_class->unrealize = nmt_newt_container_unrealize;
|
||||
widget_class->find_component = nmt_newt_container_find_component;
|
||||
|
||||
container_class->add = nmt_newt_container_real_add;
|
||||
container_class->remove = nmt_newt_container_real_remove;
|
||||
container_class->child_validity_changed = nmt_newt_container_real_child_validity_changed;
|
||||
container_class->add = nmt_newt_container_real_add;
|
||||
container_class->remove = nmt_newt_container_real_remove;
|
||||
container_class->child_validity_changed = nmt_newt_container_real_child_validity_changed;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,37 +8,36 @@
|
|||
|
||||
#include "nmt-newt-widget.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_CONTAINER (nmt_newt_container_get_type ())
|
||||
#define NMT_NEWT_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_CONTAINER, NmtNewtContainer))
|
||||
#define NMT_NEWT_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_CONTAINER, NmtNewtContainerClass))
|
||||
#define NMT_IS_NEWT_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_CONTAINER))
|
||||
#define NMT_IS_NEWT_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_CONTAINER))
|
||||
#define NMT_NEWT_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_CONTAINER, NmtNewtContainerClass))
|
||||
#define NMT_TYPE_NEWT_CONTAINER (nmt_newt_container_get_type())
|
||||
#define NMT_NEWT_CONTAINER(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_CONTAINER, NmtNewtContainer))
|
||||
#define NMT_NEWT_CONTAINER_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_CONTAINER, NmtNewtContainerClass))
|
||||
#define NMT_IS_NEWT_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_CONTAINER))
|
||||
#define NMT_IS_NEWT_CONTAINER_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_CONTAINER))
|
||||
#define NMT_NEWT_CONTAINER_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_CONTAINER, NmtNewtContainerClass))
|
||||
|
||||
struct _NmtNewtContainer {
|
||||
NmtNewtWidget parent;
|
||||
|
||||
NmtNewtWidget parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtWidgetClass parent;
|
||||
NmtNewtWidgetClass parent;
|
||||
|
||||
/* methods */
|
||||
void (*add) (NmtNewtContainer *container,
|
||||
NmtNewtWidget *child);
|
||||
void (*remove) (NmtNewtContainer *container,
|
||||
NmtNewtWidget *child);
|
||||
/* methods */
|
||||
void (*add)(NmtNewtContainer *container, NmtNewtWidget *child);
|
||||
void (*remove)(NmtNewtContainer *container, NmtNewtWidget *child);
|
||||
|
||||
void (*child_validity_changed) (NmtNewtContainer *container,
|
||||
NmtNewtWidget *child);
|
||||
void (*child_validity_changed)(NmtNewtContainer *container, NmtNewtWidget *child);
|
||||
|
||||
} NmtNewtContainerClass;
|
||||
|
||||
GType nmt_newt_container_get_type (void);
|
||||
GType nmt_newt_container_get_type(void);
|
||||
|
||||
void nmt_newt_container_remove (NmtNewtContainer *container,
|
||||
NmtNewtWidget *widget);
|
||||
void nmt_newt_container_remove(NmtNewtContainer *container, NmtNewtWidget *widget);
|
||||
|
||||
GSList *nmt_newt_container_get_children (NmtNewtContainer *container);
|
||||
GSList *nmt_newt_container_get_children(NmtNewtContainer *container);
|
||||
|
||||
#endif /* NMT_NEWT_CONTAINER_H */
|
||||
|
|
|
|||
|
|
@ -19,22 +19,23 @@
|
|||
|
||||
#include "nmt-newt-entry-numeric.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtNewtEntryNumeric, nmt_newt_entry_numeric, NMT_TYPE_NEWT_ENTRY)
|
||||
G_DEFINE_TYPE(NmtNewtEntryNumeric, nmt_newt_entry_numeric, NMT_TYPE_NEWT_ENTRY)
|
||||
|
||||
#define NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_ENTRY_NUMERIC, NmtNewtEntryNumericPrivate))
|
||||
#define NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_ENTRY_NUMERIC, NmtNewtEntryNumericPrivate))
|
||||
|
||||
typedef struct {
|
||||
gint64 min, max;
|
||||
bool optional;
|
||||
gint64 min, max;
|
||||
bool optional;
|
||||
} NmtNewtEntryNumericPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_MINIMUM,
|
||||
PROP_MAXIMUM,
|
||||
PROP_OPTIONAL,
|
||||
PROP_0,
|
||||
PROP_MINIMUM,
|
||||
PROP_MAXIMUM,
|
||||
PROP_OPTIONAL,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -49,14 +50,9 @@ enum {
|
|||
* Returns: a new #NmtNewtEntryNumeric
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_entry_numeric_new (int width,
|
||||
gint64 min,
|
||||
gint64 max)
|
||||
nmt_newt_entry_numeric_new(int width, gint64 min, gint64 max)
|
||||
{
|
||||
return nmt_newt_entry_numeric_new_full (width,
|
||||
min,
|
||||
max,
|
||||
FALSE);
|
||||
return nmt_newt_entry_numeric_new_full(width, min, max, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -72,171 +68,177 @@ nmt_newt_entry_numeric_new (int width,
|
|||
* Returns: a new #NmtNewtEntryNumeric
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_entry_numeric_new_full (int width,
|
||||
gint64 min,
|
||||
gint64 max,
|
||||
gboolean optional)
|
||||
nmt_newt_entry_numeric_new_full(int width, gint64 min, gint64 max, gboolean optional)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_NEWT_ENTRY_NUMERIC,
|
||||
"width", width,
|
||||
"minimum", min,
|
||||
"maximum", max,
|
||||
"optional", optional,
|
||||
NULL);
|
||||
return g_object_new(NMT_TYPE_NEWT_ENTRY_NUMERIC,
|
||||
"width",
|
||||
width,
|
||||
"minimum",
|
||||
min,
|
||||
"maximum",
|
||||
max,
|
||||
"optional",
|
||||
optional,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
newt_entry_numeric_filter (NmtNewtEntry *entry,
|
||||
const char *text,
|
||||
int ch,
|
||||
int position,
|
||||
gpointer user_data)
|
||||
newt_entry_numeric_filter(NmtNewtEntry *entry,
|
||||
const char * text,
|
||||
int ch,
|
||||
int position,
|
||||
gpointer user_data)
|
||||
{
|
||||
NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE (entry);
|
||||
NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE(entry);
|
||||
|
||||
if (g_ascii_isdigit (ch))
|
||||
return TRUE;
|
||||
if (g_ascii_isdigit(ch))
|
||||
return TRUE;
|
||||
|
||||
if (ch == '-' && position == 0 && priv->min < 0)
|
||||
return TRUE;
|
||||
if (ch == '-' && position == 0 && priv->min < 0)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
newt_entry_numeric_validate (NmtNewtEntry *entry,
|
||||
const char *text,
|
||||
gpointer user_data)
|
||||
newt_entry_numeric_validate(NmtNewtEntry *entry, const char *text, gpointer user_data)
|
||||
{
|
||||
NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE (entry);
|
||||
gint64 val;
|
||||
NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE(entry);
|
||||
gint64 val;
|
||||
|
||||
if (!*text)
|
||||
return priv->optional ? TRUE : FALSE;
|
||||
if (!*text)
|
||||
return priv->optional ? TRUE : FALSE;
|
||||
|
||||
val = _nm_utils_ascii_str_to_int64 (text, 10, priv->min, priv->max, G_MAXINT64);
|
||||
return val != G_MAXINT64 || errno == 0;
|
||||
val = _nm_utils_ascii_str_to_int64(text, 10, priv->min, priv->max, G_MAXINT64);
|
||||
return val != G_MAXINT64 || errno == 0;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_entry_numeric_init (NmtNewtEntryNumeric *entry)
|
||||
nmt_newt_entry_numeric_init(NmtNewtEntryNumeric *entry)
|
||||
{
|
||||
nmt_newt_entry_set_filter (NMT_NEWT_ENTRY (entry), newt_entry_numeric_filter, NULL);
|
||||
nmt_newt_entry_set_validator (NMT_NEWT_ENTRY (entry), newt_entry_numeric_validate, NULL);
|
||||
nmt_newt_entry_set_filter(NMT_NEWT_ENTRY(entry), newt_entry_numeric_filter, NULL);
|
||||
nmt_newt_entry_set_validator(NMT_NEWT_ENTRY(entry), newt_entry_numeric_validate, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_entry_numeric_constructed (GObject *object)
|
||||
nmt_newt_entry_numeric_constructed(GObject *object)
|
||||
{
|
||||
NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE (object);
|
||||
NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE(object);
|
||||
|
||||
if (!*nmt_newt_entry_get_text (NMT_NEWT_ENTRY (object))) {
|
||||
char buf[32];
|
||||
if (!*nmt_newt_entry_get_text(NMT_NEWT_ENTRY(object))) {
|
||||
char buf[32];
|
||||
|
||||
g_snprintf (buf, sizeof (buf), "%lld", (long long) priv->min);
|
||||
nmt_newt_entry_set_text (NMT_NEWT_ENTRY (object), buf);
|
||||
}
|
||||
g_snprintf(buf, sizeof(buf), "%lld", (long long) priv->min);
|
||||
nmt_newt_entry_set_text(NMT_NEWT_ENTRY(object), buf);
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_entry_numeric_parent_class)->constructed (object);
|
||||
G_OBJECT_CLASS(nmt_newt_entry_numeric_parent_class)->constructed(object);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_entry_numeric_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_entry_numeric_set_property(GObject * object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE (object);
|
||||
NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_MINIMUM:
|
||||
priv->min = g_value_get_int64 (value);
|
||||
break;
|
||||
case PROP_MAXIMUM:
|
||||
priv->max = g_value_get_int64 (value);
|
||||
break;
|
||||
case PROP_OPTIONAL:
|
||||
priv->optional = g_value_get_boolean (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_MINIMUM:
|
||||
priv->min = g_value_get_int64(value);
|
||||
break;
|
||||
case PROP_MAXIMUM:
|
||||
priv->max = g_value_get_int64(value);
|
||||
break;
|
||||
case PROP_OPTIONAL:
|
||||
priv->optional = g_value_get_boolean(value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_entry_numeric_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_entry_numeric_get_property(GObject * object,
|
||||
guint prop_id,
|
||||
GValue * value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE (object);
|
||||
NmtNewtEntryNumericPrivate *priv = NMT_NEWT_ENTRY_NUMERIC_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_MINIMUM:
|
||||
g_value_set_int64 (value, priv->min);
|
||||
break;
|
||||
case PROP_MAXIMUM:
|
||||
g_value_set_int64 (value, priv->max);
|
||||
break;
|
||||
case PROP_OPTIONAL:
|
||||
g_value_set_boolean (value, priv->optional);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_MINIMUM:
|
||||
g_value_set_int64(value, priv->min);
|
||||
break;
|
||||
case PROP_MAXIMUM:
|
||||
g_value_set_int64(value, priv->max);
|
||||
break;
|
||||
case PROP_OPTIONAL:
|
||||
g_value_set_boolean(value, priv->optional);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_entry_numeric_class_init (NmtNewtEntryNumericClass *entry_class)
|
||||
nmt_newt_entry_numeric_class_init(NmtNewtEntryNumericClass *entry_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (entry_class);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS(entry_class);
|
||||
|
||||
g_type_class_add_private (entry_class, sizeof (NmtNewtEntryNumericPrivate));
|
||||
g_type_class_add_private(entry_class, sizeof(NmtNewtEntryNumericPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->constructed = nmt_newt_entry_numeric_constructed;
|
||||
object_class->set_property = nmt_newt_entry_numeric_set_property;
|
||||
object_class->get_property = nmt_newt_entry_numeric_get_property;
|
||||
/* virtual methods */
|
||||
object_class->constructed = nmt_newt_entry_numeric_constructed;
|
||||
object_class->set_property = nmt_newt_entry_numeric_set_property;
|
||||
object_class->get_property = nmt_newt_entry_numeric_get_property;
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtEntryNumeric:minimum:
|
||||
*
|
||||
* The minimum #NmtNewtWidget:valid value for the entry. If this
|
||||
* is non-negative, then the entry will not allow negative numbers
|
||||
* to be entered.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_MINIMUM,
|
||||
g_param_spec_int64 ("minimum", "", "",
|
||||
G_MININT64, G_MAXINT64, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_MINIMUM,
|
||||
g_param_spec_int64("minimum",
|
||||
"",
|
||||
"",
|
||||
G_MININT64,
|
||||
G_MAXINT64,
|
||||
0,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtEntryNumeric:maximum:
|
||||
*
|
||||
* The maximum #NmtNewtWidget:valid value for the entry.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_MAXIMUM,
|
||||
g_param_spec_int64 ("maximum", "", "",
|
||||
G_MININT64, G_MAXINT64, G_MAXINT64,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_MAXIMUM,
|
||||
g_param_spec_int64("maximum",
|
||||
"",
|
||||
"",
|
||||
G_MININT64,
|
||||
G_MAXINT64,
|
||||
G_MAXINT64,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtEntryNumeric:optional:
|
||||
*
|
||||
* If %TRUE, allow empty string to indicate some default value.
|
||||
* It means the property is optional and can be left at the default
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_OPTIONAL,
|
||||
g_param_spec_boolean ("optional", "", "",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_OPTIONAL,
|
||||
g_param_spec_boolean("optional",
|
||||
"",
|
||||
"",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,32 +8,32 @@
|
|||
|
||||
#include "nmt-newt-entry.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_ENTRY_NUMERIC (nmt_newt_entry_numeric_get_type ())
|
||||
#define NMT_NEWT_ENTRY_NUMERIC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_ENTRY_NUMERIC, NmtNewtEntryNumeric))
|
||||
#define NMT_NEWT_ENTRY_NUMERIC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_ENTRY_NUMERIC, NmtNewtEntryNumericClass))
|
||||
#define NMT_IS_NEWT_ENTRY_NUMERIC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_ENTRY_NUMERIC))
|
||||
#define NMT_IS_NEWT_ENTRY_NUMERIC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_ENTRY_NUMERIC))
|
||||
#define NMT_NEWT_ENTRY_NUMERIC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_ENTRY_NUMERIC, NmtNewtEntryNumericClass))
|
||||
#define NMT_TYPE_NEWT_ENTRY_NUMERIC (nmt_newt_entry_numeric_get_type())
|
||||
#define NMT_NEWT_ENTRY_NUMERIC(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_ENTRY_NUMERIC, NmtNewtEntryNumeric))
|
||||
#define NMT_NEWT_ENTRY_NUMERIC_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_ENTRY_NUMERIC, NmtNewtEntryNumericClass))
|
||||
#define NMT_IS_NEWT_ENTRY_NUMERIC(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_ENTRY_NUMERIC))
|
||||
#define NMT_IS_NEWT_ENTRY_NUMERIC_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_ENTRY_NUMERIC))
|
||||
#define NMT_NEWT_ENTRY_NUMERIC_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_ENTRY_NUMERIC, NmtNewtEntryNumericClass))
|
||||
|
||||
struct _NmtNewtEntryNumeric {
|
||||
NmtNewtEntry parent;
|
||||
|
||||
NmtNewtEntry parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtEntryClass parent;
|
||||
NmtNewtEntryClass parent;
|
||||
|
||||
} NmtNewtEntryNumericClass;
|
||||
|
||||
GType nmt_newt_entry_numeric_get_type (void);
|
||||
GType nmt_newt_entry_numeric_get_type(void);
|
||||
|
||||
NmtNewtWidget *nmt_newt_entry_numeric_new (int width,
|
||||
gint64 min,
|
||||
gint64 max);
|
||||
NmtNewtWidget *nmt_newt_entry_numeric_new(int width, gint64 min, gint64 max);
|
||||
|
||||
NmtNewtWidget *nmt_newt_entry_numeric_new_full (int width,
|
||||
gint64 min,
|
||||
gint64 max,
|
||||
gboolean optional);
|
||||
NmtNewtWidget *
|
||||
nmt_newt_entry_numeric_new_full(int width, gint64 min, gint64 max, gboolean optional);
|
||||
|
||||
#endif /* NMT_NEWT_ENTRY_NUMERIC_H */
|
||||
|
|
|
|||
|
|
@ -20,32 +20,33 @@
|
|||
#include "nmt-newt-hacks.h"
|
||||
#include "nmt-newt-utils.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtNewtEntry, nmt_newt_entry, NMT_TYPE_NEWT_COMPONENT)
|
||||
G_DEFINE_TYPE(NmtNewtEntry, nmt_newt_entry, NMT_TYPE_NEWT_COMPONENT)
|
||||
|
||||
#define NMT_NEWT_ENTRY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_ENTRY, NmtNewtEntryPrivate))
|
||||
#define NMT_NEWT_ENTRY_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_ENTRY, NmtNewtEntryPrivate))
|
||||
|
||||
typedef struct {
|
||||
int width;
|
||||
NmtNewtEntryFlags flags;
|
||||
char *text;
|
||||
int last_cursor_pos;
|
||||
guint idle_update;
|
||||
int width;
|
||||
NmtNewtEntryFlags flags;
|
||||
char * text;
|
||||
int last_cursor_pos;
|
||||
guint idle_update;
|
||||
|
||||
NmtNewtEntryFilter filter;
|
||||
gpointer filter_data;
|
||||
NmtNewtEntryFilter filter;
|
||||
gpointer filter_data;
|
||||
|
||||
NmtNewtEntryValidator validator;
|
||||
gpointer validator_data;
|
||||
NmtNewtEntryValidator validator;
|
||||
gpointer validator_data;
|
||||
} NmtNewtEntryPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_TEXT,
|
||||
PROP_WIDTH,
|
||||
PROP_FLAGS,
|
||||
PROP_PASSWORD,
|
||||
PROP_0,
|
||||
PROP_TEXT,
|
||||
PROP_WIDTH,
|
||||
PROP_FLAGS,
|
||||
PROP_PASSWORD,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -70,13 +71,9 @@ enum {
|
|||
* Returns: a new #NmtNewtEntry
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_entry_new (int width,
|
||||
NmtNewtEntryFlags flags)
|
||||
nmt_newt_entry_new(int width, NmtNewtEntryFlags flags)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_NEWT_ENTRY,
|
||||
"width", width,
|
||||
"flags", flags,
|
||||
NULL);
|
||||
return g_object_new(NMT_TYPE_NEWT_ENTRY, "width", width, "flags", flags, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -107,31 +104,28 @@ nmt_newt_entry_new (int width,
|
|||
* nmt_newt_entry_set_text().
|
||||
*/
|
||||
void
|
||||
nmt_newt_entry_set_filter (NmtNewtEntry *entry,
|
||||
NmtNewtEntryFilter filter,
|
||||
gpointer user_data)
|
||||
nmt_newt_entry_set_filter(NmtNewtEntry *entry, NmtNewtEntryFilter filter, gpointer user_data)
|
||||
{
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(entry);
|
||||
|
||||
priv->filter = filter;
|
||||
priv->filter_data = user_data;
|
||||
priv->filter = filter;
|
||||
priv->filter_data = user_data;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_entry_check_valid (NmtNewtEntry *entry)
|
||||
nmt_newt_entry_check_valid(NmtNewtEntry *entry)
|
||||
{
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
|
||||
gboolean valid;
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(entry);
|
||||
gboolean valid;
|
||||
|
||||
if ( (priv->flags & NMT_NEWT_ENTRY_NONEMPTY)
|
||||
&& *priv->text == '\0')
|
||||
valid = FALSE;
|
||||
else if (priv->validator)
|
||||
valid = !!priv->validator (entry, priv->text, priv->validator_data);
|
||||
else
|
||||
valid = TRUE;
|
||||
if ((priv->flags & NMT_NEWT_ENTRY_NONEMPTY) && *priv->text == '\0')
|
||||
valid = FALSE;
|
||||
else if (priv->validator)
|
||||
valid = !!priv->validator(entry, priv->text, priv->validator_data);
|
||||
else
|
||||
valid = TRUE;
|
||||
|
||||
nmt_newt_widget_set_valid (NMT_NEWT_WIDGET (entry), valid);
|
||||
nmt_newt_widget_set_valid(NMT_NEWT_WIDGET(entry), valid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -156,47 +150,45 @@ nmt_newt_entry_check_valid (NmtNewtEntry *entry)
|
|||
* will not be considered #NmtNewtWidget:valid.
|
||||
*/
|
||||
void
|
||||
nmt_newt_entry_set_validator (NmtNewtEntry *entry,
|
||||
NmtNewtEntryValidator validator,
|
||||
gpointer user_data)
|
||||
nmt_newt_entry_set_validator(NmtNewtEntry * entry,
|
||||
NmtNewtEntryValidator validator,
|
||||
gpointer user_data)
|
||||
{
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(entry);
|
||||
|
||||
priv->validator = validator;
|
||||
priv->validator_data = user_data;
|
||||
priv->validator = validator;
|
||||
priv->validator_data = user_data;
|
||||
|
||||
nmt_newt_entry_check_valid (entry);
|
||||
nmt_newt_entry_check_valid(entry);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_entry_set_text_internal (NmtNewtEntry *entry,
|
||||
const char *text,
|
||||
newtComponent co)
|
||||
nmt_newt_entry_set_text_internal(NmtNewtEntry *entry, const char *text, newtComponent co)
|
||||
{
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(entry);
|
||||
|
||||
if (!text)
|
||||
text = "";
|
||||
if (!text)
|
||||
text = "";
|
||||
|
||||
if (!strcmp (priv->text, text))
|
||||
return;
|
||||
if (!strcmp(priv->text, text))
|
||||
return;
|
||||
|
||||
g_free (priv->text);
|
||||
priv->text = g_strdup (text);
|
||||
g_free(priv->text);
|
||||
priv->text = g_strdup(text);
|
||||
|
||||
if (co) {
|
||||
char *text_lc;
|
||||
if (co) {
|
||||
char *text_lc;
|
||||
|
||||
text_lc = priv->text ? nmt_newt_locale_from_utf8 (priv->text) : NULL;
|
||||
newtEntrySet (co, text_lc, TRUE);
|
||||
g_free (text_lc);
|
||||
priv->last_cursor_pos = -1;
|
||||
}
|
||||
text_lc = priv->text ? nmt_newt_locale_from_utf8(priv->text) : NULL;
|
||||
newtEntrySet(co, text_lc, TRUE);
|
||||
g_free(text_lc);
|
||||
priv->last_cursor_pos = -1;
|
||||
}
|
||||
|
||||
g_object_freeze_notify (G_OBJECT (entry));
|
||||
nmt_newt_entry_check_valid (entry);
|
||||
g_object_notify (G_OBJECT (entry), "text");
|
||||
g_object_thaw_notify (G_OBJECT (entry));
|
||||
g_object_freeze_notify(G_OBJECT(entry));
|
||||
nmt_newt_entry_check_valid(entry);
|
||||
g_object_notify(G_OBJECT(entry), "text");
|
||||
g_object_thaw_notify(G_OBJECT(entry));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -209,13 +201,12 @@ nmt_newt_entry_set_text_internal (NmtNewtEntry *entry,
|
|||
* be re-run.
|
||||
*/
|
||||
void
|
||||
nmt_newt_entry_set_text (NmtNewtEntry *entry,
|
||||
const char *text)
|
||||
nmt_newt_entry_set_text(NmtNewtEntry *entry, const char *text)
|
||||
{
|
||||
newtComponent co;
|
||||
newtComponent co;
|
||||
|
||||
co = nmt_newt_component_get_component (NMT_NEWT_COMPONENT (entry));
|
||||
nmt_newt_entry_set_text_internal (entry, text, co);
|
||||
co = nmt_newt_component_get_component(NMT_NEWT_COMPONENT(entry));
|
||||
nmt_newt_entry_set_text_internal(entry, text, co);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -227,11 +218,11 @@ nmt_newt_entry_set_text (NmtNewtEntry *entry,
|
|||
* Returns: @entry's text
|
||||
*/
|
||||
const char *
|
||||
nmt_newt_entry_get_text (NmtNewtEntry *entry)
|
||||
nmt_newt_entry_get_text(NmtNewtEntry *entry)
|
||||
{
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(entry);
|
||||
|
||||
return priv->text;
|
||||
return priv->text;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -242,18 +233,17 @@ nmt_newt_entry_get_text (NmtNewtEntry *entry)
|
|||
* Updates @entry's width
|
||||
*/
|
||||
void
|
||||
nmt_newt_entry_set_width (NmtNewtEntry *entry,
|
||||
int width)
|
||||
nmt_newt_entry_set_width(NmtNewtEntry *entry, int width)
|
||||
{
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(entry);
|
||||
|
||||
if (priv->width == width)
|
||||
return;
|
||||
if (priv->width == width)
|
||||
return;
|
||||
|
||||
priv->width = width;
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (entry));
|
||||
priv->width = width;
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(entry));
|
||||
|
||||
g_object_notify (G_OBJECT (entry), "width");
|
||||
g_object_notify(G_OBJECT(entry), "width");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -265,261 +255,252 @@ nmt_newt_entry_set_width (NmtNewtEntry *entry,
|
|||
* Returns: @entry's width
|
||||
*/
|
||||
int
|
||||
nmt_newt_entry_get_width (NmtNewtEntry *entry)
|
||||
nmt_newt_entry_get_width(NmtNewtEntry *entry)
|
||||
{
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(entry);
|
||||
|
||||
return priv->width;
|
||||
return priv->width;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_entry_init (NmtNewtEntry *entry)
|
||||
nmt_newt_entry_init(NmtNewtEntry *entry)
|
||||
{
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(entry);
|
||||
|
||||
priv->text = g_strdup ("");
|
||||
priv->last_cursor_pos = -1;
|
||||
priv->text = g_strdup("");
|
||||
priv->last_cursor_pos = -1;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_entry_constructed (GObject *object)
|
||||
nmt_newt_entry_constructed(GObject *object)
|
||||
{
|
||||
nmt_newt_entry_check_valid (NMT_NEWT_ENTRY (object));
|
||||
nmt_newt_entry_check_valid(NMT_NEWT_ENTRY(object));
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_entry_parent_class)->constructed (object);
|
||||
G_OBJECT_CLASS(nmt_newt_entry_parent_class)->constructed(object);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_entry_finalize (GObject *object)
|
||||
nmt_newt_entry_finalize(GObject *object)
|
||||
{
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (object);
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(object);
|
||||
|
||||
g_free (priv->text);
|
||||
if (priv->idle_update)
|
||||
g_source_remove (priv->idle_update);
|
||||
g_free(priv->text);
|
||||
if (priv->idle_update)
|
||||
g_source_remove(priv->idle_update);
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_entry_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS(nmt_newt_entry_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
idle_update_entry (gpointer entry)
|
||||
idle_update_entry(gpointer entry)
|
||||
{
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
|
||||
newtComponent co = nmt_newt_component_get_component (entry);
|
||||
char *text;
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(entry);
|
||||
newtComponent co = nmt_newt_component_get_component(entry);
|
||||
char * text;
|
||||
|
||||
priv->idle_update = 0;
|
||||
if (!co)
|
||||
return FALSE;
|
||||
priv->idle_update = 0;
|
||||
if (!co)
|
||||
return FALSE;
|
||||
|
||||
priv->last_cursor_pos = newtEntryGetCursorPosition (co);
|
||||
priv->last_cursor_pos = newtEntryGetCursorPosition(co);
|
||||
|
||||
text = nmt_newt_locale_to_utf8 (newtEntryGetValue (co));
|
||||
nmt_newt_entry_set_text_internal (entry, text, NULL);
|
||||
g_free (text);
|
||||
text = nmt_newt_locale_to_utf8(newtEntryGetValue(co));
|
||||
nmt_newt_entry_set_text_internal(entry, text, NULL);
|
||||
g_free(text);
|
||||
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
entry_filter (newtComponent entry,
|
||||
void *self,
|
||||
int ch,
|
||||
int cursor)
|
||||
entry_filter(newtComponent entry, void *self, int ch, int cursor)
|
||||
{
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (self);
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(self);
|
||||
|
||||
if (g_ascii_isprint (ch)) {
|
||||
if (priv->filter) {
|
||||
char *text = nmt_newt_locale_to_utf8 (newtEntryGetValue (entry));
|
||||
if (g_ascii_isprint(ch)) {
|
||||
if (priv->filter) {
|
||||
char *text = nmt_newt_locale_to_utf8(newtEntryGetValue(entry));
|
||||
|
||||
if (!priv->filter (self, text, ch, cursor, priv->filter_data)) {
|
||||
g_free (text);
|
||||
return 0;
|
||||
}
|
||||
g_free (text);
|
||||
}
|
||||
}
|
||||
if (!priv->filter(self, text, ch, cursor, priv->filter_data)) {
|
||||
g_free(text);
|
||||
return 0;
|
||||
}
|
||||
g_free(text);
|
||||
}
|
||||
}
|
||||
|
||||
if (!priv->idle_update)
|
||||
priv->idle_update = g_idle_add (idle_update_entry, self);
|
||||
return ch;
|
||||
if (!priv->idle_update)
|
||||
priv->idle_update = g_idle_add(idle_update_entry, self);
|
||||
return ch;
|
||||
}
|
||||
|
||||
static guint
|
||||
convert_flags (NmtNewtEntryFlags flags)
|
||||
convert_flags(NmtNewtEntryFlags flags)
|
||||
{
|
||||
guint newt_flags = NEWT_FLAG_RETURNEXIT;
|
||||
guint newt_flags = NEWT_FLAG_RETURNEXIT;
|
||||
|
||||
if (!(flags & NMT_NEWT_ENTRY_NOSCROLL))
|
||||
newt_flags |= NEWT_FLAG_SCROLL;
|
||||
if (flags & NMT_NEWT_ENTRY_PASSWORD)
|
||||
newt_flags |= NEWT_FLAG_PASSWORD;
|
||||
if (!(flags & NMT_NEWT_ENTRY_NOSCROLL))
|
||||
newt_flags |= NEWT_FLAG_SCROLL;
|
||||
if (flags & NMT_NEWT_ENTRY_PASSWORD)
|
||||
newt_flags |= NEWT_FLAG_PASSWORD;
|
||||
|
||||
return newt_flags;
|
||||
return newt_flags;
|
||||
}
|
||||
|
||||
static newtComponent
|
||||
nmt_newt_entry_build_component (NmtNewtComponent *component,
|
||||
gboolean sensitive)
|
||||
nmt_newt_entry_build_component(NmtNewtComponent *component, gboolean sensitive)
|
||||
{
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (component);
|
||||
newtComponent co;
|
||||
char *text_lc;
|
||||
int flags;
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(component);
|
||||
newtComponent co;
|
||||
char * text_lc;
|
||||
int flags;
|
||||
|
||||
flags = convert_flags (priv->flags);
|
||||
if (!sensitive)
|
||||
flags |= NEWT_FLAG_DISABLED;
|
||||
flags = convert_flags(priv->flags);
|
||||
if (!sensitive)
|
||||
flags |= NEWT_FLAG_DISABLED;
|
||||
|
||||
text_lc = priv->text ? nmt_newt_locale_from_utf8 (priv->text) : NULL;
|
||||
co = newtEntry (-1, -1, text_lc, priv->width, NULL, flags);
|
||||
g_free (text_lc);
|
||||
text_lc = priv->text ? nmt_newt_locale_from_utf8(priv->text) : NULL;
|
||||
co = newtEntry(-1, -1, text_lc, priv->width, NULL, flags);
|
||||
g_free(text_lc);
|
||||
|
||||
if (priv->last_cursor_pos != -1)
|
||||
newtEntrySetCursorPosition (co, priv->last_cursor_pos);
|
||||
if (priv->last_cursor_pos != -1)
|
||||
newtEntrySetCursorPosition(co, priv->last_cursor_pos);
|
||||
|
||||
newtEntrySetFilter (co, entry_filter, component);
|
||||
return co;
|
||||
newtEntrySetFilter(co, entry_filter, component);
|
||||
return co;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_entry_activated (NmtNewtWidget *widget)
|
||||
nmt_newt_entry_activated(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (widget);
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(widget);
|
||||
|
||||
if (priv->idle_update) {
|
||||
g_source_remove (priv->idle_update);
|
||||
idle_update_entry (widget);
|
||||
}
|
||||
if (priv->idle_update) {
|
||||
g_source_remove(priv->idle_update);
|
||||
idle_update_entry(widget);
|
||||
}
|
||||
|
||||
NMT_NEWT_WIDGET_CLASS (nmt_newt_entry_parent_class)->activated (widget);
|
||||
NMT_NEWT_WIDGET_CLASS(nmt_newt_entry_parent_class)->activated(widget);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_entry_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_entry_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtEntry *entry = NMT_NEWT_ENTRY (object);
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
|
||||
NmtNewtEntry * entry = NMT_NEWT_ENTRY(object);
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(entry);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_TEXT:
|
||||
nmt_newt_entry_set_text (entry, g_value_get_string (value));
|
||||
break;
|
||||
case PROP_WIDTH:
|
||||
nmt_newt_entry_set_width (entry, g_value_get_int (value));
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
priv->flags = g_value_get_uint (value);
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (entry));
|
||||
break;
|
||||
case PROP_PASSWORD:
|
||||
if (g_value_get_boolean (value))
|
||||
priv->flags |= NMT_NEWT_ENTRY_PASSWORD;
|
||||
else
|
||||
priv->flags &= ~NMT_NEWT_ENTRY_PASSWORD;
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (entry));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_TEXT:
|
||||
nmt_newt_entry_set_text(entry, g_value_get_string(value));
|
||||
break;
|
||||
case PROP_WIDTH:
|
||||
nmt_newt_entry_set_width(entry, g_value_get_int(value));
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
priv->flags = g_value_get_uint(value);
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(entry));
|
||||
break;
|
||||
case PROP_PASSWORD:
|
||||
if (g_value_get_boolean(value))
|
||||
priv->flags |= NMT_NEWT_ENTRY_PASSWORD;
|
||||
else
|
||||
priv->flags &= ~NMT_NEWT_ENTRY_PASSWORD;
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(entry));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_entry_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_entry_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtEntry *entry = NMT_NEWT_ENTRY (object);
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
|
||||
NmtNewtEntry * entry = NMT_NEWT_ENTRY(object);
|
||||
NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE(entry);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_TEXT:
|
||||
g_value_set_string (value, nmt_newt_entry_get_text (entry));
|
||||
break;
|
||||
case PROP_WIDTH:
|
||||
g_value_set_int (value, priv->width);
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
g_value_set_uint (value, priv->flags);
|
||||
break;
|
||||
case PROP_PASSWORD:
|
||||
g_value_set_boolean (value, (priv->flags & NMT_NEWT_ENTRY_PASSWORD) != 0);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_TEXT:
|
||||
g_value_set_string(value, nmt_newt_entry_get_text(entry));
|
||||
break;
|
||||
case PROP_WIDTH:
|
||||
g_value_set_int(value, priv->width);
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
g_value_set_uint(value, priv->flags);
|
||||
break;
|
||||
case PROP_PASSWORD:
|
||||
g_value_set_boolean(value, (priv->flags & NMT_NEWT_ENTRY_PASSWORD) != 0);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_entry_class_init (NmtNewtEntryClass *entry_class)
|
||||
nmt_newt_entry_class_init(NmtNewtEntryClass *entry_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (entry_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (entry_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS (entry_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(entry_class);
|
||||
NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(entry_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(entry_class);
|
||||
|
||||
g_type_class_add_private (entry_class, sizeof (NmtNewtEntryPrivate));
|
||||
g_type_class_add_private(entry_class, sizeof(NmtNewtEntryPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->constructed = nmt_newt_entry_constructed;
|
||||
object_class->set_property = nmt_newt_entry_set_property;
|
||||
object_class->get_property = nmt_newt_entry_get_property;
|
||||
object_class->finalize = nmt_newt_entry_finalize;
|
||||
/* virtual methods */
|
||||
object_class->constructed = nmt_newt_entry_constructed;
|
||||
object_class->set_property = nmt_newt_entry_set_property;
|
||||
object_class->get_property = nmt_newt_entry_get_property;
|
||||
object_class->finalize = nmt_newt_entry_finalize;
|
||||
|
||||
widget_class->activated = nmt_newt_entry_activated;
|
||||
widget_class->activated = nmt_newt_entry_activated;
|
||||
|
||||
component_class->build_component = nmt_newt_entry_build_component;
|
||||
component_class->build_component = nmt_newt_entry_build_component;
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtEntry:text
|
||||
*
|
||||
* The entry's text
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_TEXT,
|
||||
g_param_spec_string ("text", "", "",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_TEXT,
|
||||
g_param_spec_string("text", "", "", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtEntry:width
|
||||
*
|
||||
* The entry's width in characters
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_WIDTH,
|
||||
g_param_spec_int ("width", "", "",
|
||||
-1, 80, -1,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_WIDTH,
|
||||
g_param_spec_int("width", "", "", -1, 80, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtEntry:flags
|
||||
*
|
||||
* The entry's #NmtNewtEntryFlags
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_FLAGS,
|
||||
g_param_spec_uint ("flags", "", "",
|
||||
0, 0xFFFF, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_FLAGS,
|
||||
g_param_spec_uint("flags",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
0xFFFF,
|
||||
0,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtEntry:password
|
||||
*
|
||||
* %TRUE if #NmtNewtEntry:flags contains %NMT_NEWT_ENTRY_PASSWORD,
|
||||
* %FALSE if not.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_PASSWORD,
|
||||
g_param_spec_boolean ("password", "", "",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_PASSWORD,
|
||||
g_param_spec_boolean("password",
|
||||
"",
|
||||
"",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,50 +8,47 @@
|
|||
|
||||
#include "nmt-newt-component.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_ENTRY (nmt_newt_entry_get_type ())
|
||||
#define NMT_NEWT_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_ENTRY, NmtNewtEntry))
|
||||
#define NMT_NEWT_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_ENTRY, NmtNewtEntryClass))
|
||||
#define NMT_IS_NEWT_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_ENTRY))
|
||||
#define NMT_IS_NEWT_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_ENTRY))
|
||||
#define NMT_NEWT_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_ENTRY, NmtNewtEntryClass))
|
||||
#define NMT_TYPE_NEWT_ENTRY (nmt_newt_entry_get_type())
|
||||
#define NMT_NEWT_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_ENTRY, NmtNewtEntry))
|
||||
#define NMT_NEWT_ENTRY_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_ENTRY, NmtNewtEntryClass))
|
||||
#define NMT_IS_NEWT_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_ENTRY))
|
||||
#define NMT_IS_NEWT_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_ENTRY))
|
||||
#define NMT_NEWT_ENTRY_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_ENTRY, NmtNewtEntryClass))
|
||||
|
||||
struct _NmtNewtEntry {
|
||||
NmtNewtComponent parent;
|
||||
|
||||
NmtNewtComponent parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtComponentClass parent;
|
||||
NmtNewtComponentClass parent;
|
||||
|
||||
} NmtNewtEntryClass;
|
||||
|
||||
GType nmt_newt_entry_get_type (void);
|
||||
GType nmt_newt_entry_get_type(void);
|
||||
|
||||
typedef gboolean (*NmtNewtEntryFilter) (NmtNewtEntry *, const char *text, int ch, int position, gpointer);
|
||||
typedef gboolean (*NmtNewtEntryValidator) (NmtNewtEntry *, const char *text, gpointer);
|
||||
typedef gboolean (
|
||||
*NmtNewtEntryFilter)(NmtNewtEntry *, const char *text, int ch, int position, gpointer);
|
||||
typedef gboolean (*NmtNewtEntryValidator)(NmtNewtEntry *, const char *text, gpointer);
|
||||
|
||||
typedef enum {
|
||||
NMT_NEWT_ENTRY_NOSCROLL = (1 << 0),
|
||||
NMT_NEWT_ENTRY_PASSWORD = (1 << 1),
|
||||
NMT_NEWT_ENTRY_NONEMPTY = (1 << 2)
|
||||
NMT_NEWT_ENTRY_NOSCROLL = (1 << 0),
|
||||
NMT_NEWT_ENTRY_PASSWORD = (1 << 1),
|
||||
NMT_NEWT_ENTRY_NONEMPTY = (1 << 2)
|
||||
} NmtNewtEntryFlags;
|
||||
|
||||
NmtNewtWidget *nmt_newt_entry_new (int width,
|
||||
NmtNewtEntryFlags flags);
|
||||
NmtNewtWidget *nmt_newt_entry_new(int width, NmtNewtEntryFlags flags);
|
||||
|
||||
void nmt_newt_entry_set_filter (NmtNewtEntry *entry,
|
||||
NmtNewtEntryFilter filter,
|
||||
gpointer user_data);
|
||||
void nmt_newt_entry_set_validator (NmtNewtEntry *entry,
|
||||
NmtNewtEntryValidator validator,
|
||||
gpointer user_data);
|
||||
void nmt_newt_entry_set_filter(NmtNewtEntry *entry, NmtNewtEntryFilter filter, gpointer user_data);
|
||||
void nmt_newt_entry_set_validator(NmtNewtEntry * entry,
|
||||
NmtNewtEntryValidator validator,
|
||||
gpointer user_data);
|
||||
|
||||
void nmt_newt_entry_set_text (NmtNewtEntry *entry,
|
||||
const char *text);
|
||||
const char *nmt_newt_entry_get_text (NmtNewtEntry *entry);
|
||||
void nmt_newt_entry_set_text(NmtNewtEntry *entry, const char *text);
|
||||
const char *nmt_newt_entry_get_text(NmtNewtEntry *entry);
|
||||
|
||||
void nmt_newt_entry_set_width (NmtNewtEntry *entry,
|
||||
int width);
|
||||
int nmt_newt_entry_get_width (NmtNewtEntry *entry);
|
||||
void nmt_newt_entry_set_width(NmtNewtEntry *entry, int width);
|
||||
int nmt_newt_entry_get_width(NmtNewtEntry *entry);
|
||||
|
||||
#endif /* NMT_NEWT_ENTRY_H */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -8,42 +8,41 @@
|
|||
|
||||
#include "nmt-newt-container.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_FORM (nmt_newt_form_get_type ())
|
||||
#define NMT_NEWT_FORM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_FORM, NmtNewtForm))
|
||||
#define NMT_NEWT_FORM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_FORM, NmtNewtFormClass))
|
||||
#define NMT_IS_NEWT_FORM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_FORM))
|
||||
#define NMT_IS_NEWT_FORM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_FORM))
|
||||
#define NMT_NEWT_FORM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_FORM, NmtNewtFormClass))
|
||||
#define NMT_TYPE_NEWT_FORM (nmt_newt_form_get_type())
|
||||
#define NMT_NEWT_FORM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_FORM, NmtNewtForm))
|
||||
#define NMT_NEWT_FORM_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_FORM, NmtNewtFormClass))
|
||||
#define NMT_IS_NEWT_FORM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_FORM))
|
||||
#define NMT_IS_NEWT_FORM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_FORM))
|
||||
#define NMT_NEWT_FORM_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_FORM, NmtNewtFormClass))
|
||||
|
||||
struct _NmtNewtForm {
|
||||
NmtNewtContainer parent;
|
||||
|
||||
NmtNewtContainer parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtContainerClass parent;
|
||||
NmtNewtContainerClass parent;
|
||||
|
||||
/* signals */
|
||||
void (*quit) (NmtNewtForm *form);
|
||||
/* signals */
|
||||
void (*quit)(NmtNewtForm *form);
|
||||
|
||||
/* methods */
|
||||
void (*show) (NmtNewtForm *form);
|
||||
/* methods */
|
||||
void (*show)(NmtNewtForm *form);
|
||||
|
||||
} NmtNewtFormClass;
|
||||
|
||||
GType nmt_newt_form_get_type (void);
|
||||
GType nmt_newt_form_get_type(void);
|
||||
|
||||
NmtNewtForm *nmt_newt_form_new (const char *title);
|
||||
NmtNewtForm *nmt_newt_form_new_fullscreen (const char *title);
|
||||
NmtNewtForm *nmt_newt_form_new(const char *title);
|
||||
NmtNewtForm *nmt_newt_form_new_fullscreen(const char *title);
|
||||
|
||||
void nmt_newt_form_set_content (NmtNewtForm *form,
|
||||
NmtNewtWidget *content);
|
||||
void nmt_newt_form_set_content(NmtNewtForm *form, NmtNewtWidget *content);
|
||||
|
||||
void nmt_newt_form_show (NmtNewtForm *form);
|
||||
NmtNewtWidget *nmt_newt_form_run_sync (NmtNewtForm *form);
|
||||
void nmt_newt_form_quit (NmtNewtForm *form);
|
||||
void nmt_newt_form_show(NmtNewtForm *form);
|
||||
NmtNewtWidget *nmt_newt_form_run_sync(NmtNewtForm *form);
|
||||
void nmt_newt_form_quit(NmtNewtForm *form);
|
||||
|
||||
void nmt_newt_form_set_focus (NmtNewtForm *form,
|
||||
NmtNewtWidget *widget);
|
||||
void nmt_newt_form_set_focus(NmtNewtForm *form, NmtNewtWidget *widget);
|
||||
|
||||
#endif /* NMT_NEWT_FORM_H */
|
||||
|
|
|
|||
|
|
@ -31,24 +31,25 @@
|
|||
|
||||
#include "nmt-newt-grid.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtNewtGrid, nmt_newt_grid, NMT_TYPE_NEWT_CONTAINER)
|
||||
G_DEFINE_TYPE(NmtNewtGrid, nmt_newt_grid, NMT_TYPE_NEWT_CONTAINER)
|
||||
|
||||
#define NMT_NEWT_GRID_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_GRID, NmtNewtGridPrivate))
|
||||
#define NMT_NEWT_GRID_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_GRID, NmtNewtGridPrivate))
|
||||
|
||||
typedef struct {
|
||||
NmtNewtWidget *widget;
|
||||
int x, y;
|
||||
NmtNewtGridFlags flags;
|
||||
int req_height, req_width;
|
||||
NmtNewtWidget * widget;
|
||||
int x, y;
|
||||
NmtNewtGridFlags flags;
|
||||
int req_height, req_width;
|
||||
} NmtNewtGridChild;
|
||||
|
||||
typedef struct {
|
||||
GArray *children;
|
||||
int max_x, max_y;
|
||||
int *row_heights, *col_widths;
|
||||
gboolean *expand_rows, *expand_cols;
|
||||
int n_expand_rows, n_expand_cols;
|
||||
int req_height, req_width;
|
||||
GArray * children;
|
||||
int max_x, max_y;
|
||||
int * row_heights, *col_widths;
|
||||
gboolean *expand_rows, *expand_cols;
|
||||
int n_expand_rows, n_expand_cols;
|
||||
int req_height, req_width;
|
||||
} NmtNewtGridPrivate;
|
||||
|
||||
/**
|
||||
|
|
@ -59,233 +60,224 @@ typedef struct {
|
|||
* Returns: a new #NmtNewtGrid
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_grid_new (void)
|
||||
nmt_newt_grid_new(void)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_NEWT_GRID, NULL);
|
||||
return g_object_new(NMT_TYPE_NEWT_GRID, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_grid_init (NmtNewtGrid *grid)
|
||||
nmt_newt_grid_init(NmtNewtGrid *grid)
|
||||
{
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE (grid);
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid);
|
||||
|
||||
priv->children = g_array_new (FALSE, FALSE, sizeof (NmtNewtGridChild));
|
||||
priv->children = g_array_new(FALSE, FALSE, sizeof(NmtNewtGridChild));
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_grid_finalize (GObject *object)
|
||||
nmt_newt_grid_finalize(GObject *object)
|
||||
{
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE (object);
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(object);
|
||||
|
||||
g_array_unref (priv->children);
|
||||
nm_clear_g_free (&priv->row_heights);
|
||||
nm_clear_g_free (&priv->col_widths);
|
||||
nm_clear_g_free (&priv->expand_rows);
|
||||
nm_clear_g_free (&priv->expand_cols);
|
||||
g_array_unref(priv->children);
|
||||
nm_clear_g_free(&priv->row_heights);
|
||||
nm_clear_g_free(&priv->col_widths);
|
||||
nm_clear_g_free(&priv->expand_rows);
|
||||
nm_clear_g_free(&priv->expand_cols);
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_grid_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS(nmt_newt_grid_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static int
|
||||
child_sort_func (gconstpointer a,
|
||||
gconstpointer b)
|
||||
child_sort_func(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
NmtNewtGridChild *child_a = (NmtNewtGridChild *)a;
|
||||
NmtNewtGridChild *child_b = (NmtNewtGridChild *)b;
|
||||
NmtNewtGridChild *child_a = (NmtNewtGridChild *) a;
|
||||
NmtNewtGridChild *child_b = (NmtNewtGridChild *) b;
|
||||
|
||||
if (child_a->y != child_b->y)
|
||||
return child_a->y - child_b->y;
|
||||
else
|
||||
return child_a->x - child_b->x;
|
||||
if (child_a->y != child_b->y)
|
||||
return child_a->y - child_b->y;
|
||||
else
|
||||
return child_a->x - child_b->x;
|
||||
}
|
||||
|
||||
static newtComponent *
|
||||
nmt_newt_grid_get_components (NmtNewtWidget *widget)
|
||||
nmt_newt_grid_get_components(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE (widget);
|
||||
NmtNewtGridChild *children;
|
||||
GPtrArray *cos;
|
||||
newtComponent *child_cos;
|
||||
int i, c;
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(widget);
|
||||
NmtNewtGridChild * children;
|
||||
GPtrArray * cos;
|
||||
newtComponent * child_cos;
|
||||
int i, c;
|
||||
|
||||
g_array_sort (priv->children, child_sort_func);
|
||||
children = (NmtNewtGridChild *)priv->children->data;
|
||||
g_array_sort(priv->children, child_sort_func);
|
||||
children = (NmtNewtGridChild *) priv->children->data;
|
||||
|
||||
cos = g_ptr_array_new ();
|
||||
cos = g_ptr_array_new();
|
||||
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
if (!nmt_newt_widget_get_visible (children[i].widget))
|
||||
continue;
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
if (!nmt_newt_widget_get_visible(children[i].widget))
|
||||
continue;
|
||||
|
||||
child_cos = nmt_newt_widget_get_components (children[i].widget);
|
||||
for (c = 0; child_cos[c]; c++)
|
||||
g_ptr_array_add (cos, child_cos[c]);
|
||||
g_free (child_cos);
|
||||
}
|
||||
g_ptr_array_add (cos, NULL);
|
||||
child_cos = nmt_newt_widget_get_components(children[i].widget);
|
||||
for (c = 0; child_cos[c]; c++)
|
||||
g_ptr_array_add(cos, child_cos[c]);
|
||||
g_free(child_cos);
|
||||
}
|
||||
g_ptr_array_add(cos, NULL);
|
||||
|
||||
return (newtComponent *) g_ptr_array_free (cos, FALSE);
|
||||
return (newtComponent *) g_ptr_array_free(cos, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_grid_size_request (NmtNewtWidget *widget,
|
||||
int *width,
|
||||
int *height)
|
||||
nmt_newt_grid_size_request(NmtNewtWidget *widget, int *width, int *height)
|
||||
{
|
||||
NmtNewtGrid *grid = NMT_NEWT_GRID (widget);
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE (grid);
|
||||
NmtNewtGridChild *children = (NmtNewtGridChild *)priv->children->data;
|
||||
int row, col, i;
|
||||
NmtNewtGrid * grid = NMT_NEWT_GRID(widget);
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid);
|
||||
NmtNewtGridChild * children = (NmtNewtGridChild *) priv->children->data;
|
||||
int row, col, i;
|
||||
|
||||
g_free (priv->row_heights);
|
||||
g_free (priv->col_widths);
|
||||
g_free (priv->expand_rows);
|
||||
g_free (priv->expand_cols);
|
||||
g_free(priv->row_heights);
|
||||
g_free(priv->col_widths);
|
||||
g_free(priv->expand_rows);
|
||||
g_free(priv->expand_cols);
|
||||
|
||||
priv->row_heights = g_new0 (int, priv->max_y + 1);
|
||||
priv->col_widths = g_new0 (int, priv->max_x + 1);
|
||||
priv->expand_rows = g_new0 (gboolean, priv->max_y + 1);
|
||||
priv->expand_cols = g_new0 (gboolean, priv->max_x + 1);
|
||||
priv->n_expand_rows = priv->n_expand_cols = 0;
|
||||
priv->row_heights = g_new0(int, priv->max_y + 1);
|
||||
priv->col_widths = g_new0(int, priv->max_x + 1);
|
||||
priv->expand_rows = g_new0(gboolean, priv->max_y + 1);
|
||||
priv->expand_cols = g_new0(gboolean, priv->max_x + 1);
|
||||
priv->n_expand_rows = priv->n_expand_cols = 0;
|
||||
|
||||
for (row = 0; row < priv->max_y + 1; row++) {
|
||||
for (col = 0; col < priv->max_x + 1; col++) {
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
if (children[i].x != col || children[i].y != row)
|
||||
continue;
|
||||
if (!nmt_newt_widget_get_visible (children[i].widget))
|
||||
continue;
|
||||
for (row = 0; row < priv->max_y + 1; row++) {
|
||||
for (col = 0; col < priv->max_x + 1; col++) {
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
if (children[i].x != col || children[i].y != row)
|
||||
continue;
|
||||
if (!nmt_newt_widget_get_visible(children[i].widget))
|
||||
continue;
|
||||
|
||||
nmt_newt_widget_size_request (children[i].widget,
|
||||
&children[i].req_width,
|
||||
&children[i].req_height);
|
||||
if (children[i].req_height > priv->row_heights[row])
|
||||
priv->row_heights[row] = children[i].req_height;
|
||||
if (children[i].req_width > priv->col_widths[col])
|
||||
priv->col_widths[col] = children[i].req_width;
|
||||
nmt_newt_widget_size_request(children[i].widget,
|
||||
&children[i].req_width,
|
||||
&children[i].req_height);
|
||||
if (children[i].req_height > priv->row_heights[row])
|
||||
priv->row_heights[row] = children[i].req_height;
|
||||
if (children[i].req_width > priv->col_widths[col])
|
||||
priv->col_widths[col] = children[i].req_width;
|
||||
|
||||
if ( (children[i].flags & NMT_NEWT_GRID_EXPAND_X)
|
||||
&& !priv->expand_cols[children[i].x]) {
|
||||
priv->expand_cols[children[i].x] = TRUE;
|
||||
priv->n_expand_cols++;
|
||||
}
|
||||
if ( (children[i].flags & NMT_NEWT_GRID_EXPAND_Y)
|
||||
&& !priv->expand_rows[children[i].y]) {
|
||||
priv->expand_rows[children[i].y] = TRUE;
|
||||
priv->n_expand_rows++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((children[i].flags & NMT_NEWT_GRID_EXPAND_X)
|
||||
&& !priv->expand_cols[children[i].x]) {
|
||||
priv->expand_cols[children[i].x] = TRUE;
|
||||
priv->n_expand_cols++;
|
||||
}
|
||||
if ((children[i].flags & NMT_NEWT_GRID_EXPAND_Y)
|
||||
&& !priv->expand_rows[children[i].y]) {
|
||||
priv->expand_rows[children[i].y] = TRUE;
|
||||
priv->n_expand_rows++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
priv->req_height = priv->req_width = 0;
|
||||
for (row = 0; row < priv->max_y + 1; row++)
|
||||
priv->req_height += priv->row_heights[row];
|
||||
for (col = 0; col < priv->max_x + 1; col++)
|
||||
priv->req_width += priv->col_widths[col];
|
||||
priv->req_height = priv->req_width = 0;
|
||||
for (row = 0; row < priv->max_y + 1; row++)
|
||||
priv->req_height += priv->row_heights[row];
|
||||
for (col = 0; col < priv->max_x + 1; col++)
|
||||
priv->req_width += priv->col_widths[col];
|
||||
|
||||
*height = priv->req_height;
|
||||
*width = priv->req_width;
|
||||
*height = priv->req_height;
|
||||
*width = priv->req_width;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_grid_size_allocate (NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height)
|
||||
nmt_newt_grid_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height)
|
||||
{
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE (widget);
|
||||
NmtNewtGridChild *children = (NmtNewtGridChild *)priv->children->data, *child;
|
||||
int i, row, col;
|
||||
int child_x, child_y, child_width, child_height;
|
||||
int extra, extra_all, extra_some;
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(widget);
|
||||
NmtNewtGridChild * children = (NmtNewtGridChild *) priv->children->data, *child;
|
||||
int i, row, col;
|
||||
int child_x, child_y, child_width, child_height;
|
||||
int extra, extra_all, extra_some;
|
||||
|
||||
extra = width - priv->req_width;
|
||||
if (extra > 0 && priv->n_expand_cols) {
|
||||
extra_all = extra / priv->n_expand_cols;
|
||||
extra_some = extra % priv->n_expand_cols;
|
||||
extra = width - priv->req_width;
|
||||
if (extra > 0 && priv->n_expand_cols) {
|
||||
extra_all = extra / priv->n_expand_cols;
|
||||
extra_some = extra % priv->n_expand_cols;
|
||||
|
||||
for (col = 0; col < priv->max_x + 1; col++) {
|
||||
if (!priv->expand_cols[col])
|
||||
continue;
|
||||
priv->col_widths[col] += extra_all;
|
||||
if (extra_some) {
|
||||
priv->col_widths[col]++;
|
||||
extra_some--;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (col = 0; col < priv->max_x + 1; col++) {
|
||||
if (!priv->expand_cols[col])
|
||||
continue;
|
||||
priv->col_widths[col] += extra_all;
|
||||
if (extra_some) {
|
||||
priv->col_widths[col]++;
|
||||
extra_some--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extra = height - priv->req_height;
|
||||
if (extra > 0 && priv->n_expand_rows) {
|
||||
extra_all = extra / priv->n_expand_rows;
|
||||
extra_some = extra % priv->n_expand_rows;
|
||||
extra = height - priv->req_height;
|
||||
if (extra > 0 && priv->n_expand_rows) {
|
||||
extra_all = extra / priv->n_expand_rows;
|
||||
extra_some = extra % priv->n_expand_rows;
|
||||
|
||||
for (row = 0; row < priv->max_y + 1; row++) {
|
||||
if (!priv->expand_rows[row])
|
||||
continue;
|
||||
priv->row_heights[row] += extra_all;
|
||||
if (extra_some) {
|
||||
priv->row_heights[row]++;
|
||||
extra_some--;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (row = 0; row < priv->max_y + 1; row++) {
|
||||
if (!priv->expand_rows[row])
|
||||
continue;
|
||||
priv->row_heights[row] += extra_all;
|
||||
if (extra_some) {
|
||||
priv->row_heights[row]++;
|
||||
extra_some--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
child = &children[i];
|
||||
if (!nmt_newt_widget_get_visible (child->widget))
|
||||
continue;
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
child = &children[i];
|
||||
if (!nmt_newt_widget_get_visible(child->widget))
|
||||
continue;
|
||||
|
||||
child_x = x;
|
||||
for (col = 0; col < child->x; col++)
|
||||
child_x += priv->col_widths[col];
|
||||
child_x = x;
|
||||
for (col = 0; col < child->x; col++)
|
||||
child_x += priv->col_widths[col];
|
||||
|
||||
if ((child->flags & NMT_NEWT_GRID_FILL_X) == NMT_NEWT_GRID_FILL_X) {
|
||||
child_width = priv->col_widths[child->x];
|
||||
} else {
|
||||
child_width = child->req_width;
|
||||
if (child->flags & NMT_NEWT_GRID_ANCHOR_RIGHT)
|
||||
child_x += priv->col_widths[child->x] - child->req_width;
|
||||
else if (!(child->flags & NMT_NEWT_GRID_ANCHOR_LEFT))
|
||||
child_x += (priv->col_widths[child->x] - child->req_width) / 2;
|
||||
}
|
||||
if ((child->flags & NMT_NEWT_GRID_FILL_X) == NMT_NEWT_GRID_FILL_X) {
|
||||
child_width = priv->col_widths[child->x];
|
||||
} else {
|
||||
child_width = child->req_width;
|
||||
if (child->flags & NMT_NEWT_GRID_ANCHOR_RIGHT)
|
||||
child_x += priv->col_widths[child->x] - child->req_width;
|
||||
else if (!(child->flags & NMT_NEWT_GRID_ANCHOR_LEFT))
|
||||
child_x += (priv->col_widths[child->x] - child->req_width) / 2;
|
||||
}
|
||||
|
||||
child_y = y;
|
||||
for (row = 0; row < child->y; row++)
|
||||
child_y += priv->row_heights[row];
|
||||
child_y = y;
|
||||
for (row = 0; row < child->y; row++)
|
||||
child_y += priv->row_heights[row];
|
||||
|
||||
if ((child->flags & NMT_NEWT_GRID_FILL_Y) == NMT_NEWT_GRID_FILL_Y) {
|
||||
child_height = priv->row_heights[child->y];
|
||||
} else {
|
||||
child_height = child->req_height;
|
||||
if (child->flags & NMT_NEWT_GRID_ANCHOR_BOTTOM)
|
||||
child_y += priv->row_heights[child->y] - child->req_height;
|
||||
else if (!(child->flags & NMT_NEWT_GRID_ANCHOR_TOP))
|
||||
child_y += (priv->row_heights[child->y] - child->req_height) / 2;
|
||||
}
|
||||
if ((child->flags & NMT_NEWT_GRID_FILL_Y) == NMT_NEWT_GRID_FILL_Y) {
|
||||
child_height = priv->row_heights[child->y];
|
||||
} else {
|
||||
child_height = child->req_height;
|
||||
if (child->flags & NMT_NEWT_GRID_ANCHOR_BOTTOM)
|
||||
child_y += priv->row_heights[child->y] - child->req_height;
|
||||
else if (!(child->flags & NMT_NEWT_GRID_ANCHOR_TOP))
|
||||
child_y += (priv->row_heights[child->y] - child->req_height) / 2;
|
||||
}
|
||||
|
||||
nmt_newt_widget_size_allocate (child->widget,
|
||||
child_x, child_y,
|
||||
child_width, child_height);
|
||||
}
|
||||
nmt_newt_widget_size_allocate(child->widget, child_x, child_y, child_width, child_height);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_grid_find_size (NmtNewtGrid *grid)
|
||||
nmt_newt_grid_find_size(NmtNewtGrid *grid)
|
||||
{
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE (grid);
|
||||
NmtNewtGridChild *children = (NmtNewtGridChild *)priv->children->data;
|
||||
int i;
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid);
|
||||
NmtNewtGridChild * children = (NmtNewtGridChild *) priv->children->data;
|
||||
int i;
|
||||
|
||||
priv->max_x = priv->max_y = 0;
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
if (children[i].x > priv->max_x)
|
||||
priv->max_x = children[i].x;
|
||||
if (children[i].y > priv->max_y)
|
||||
priv->max_y = children[i].y;
|
||||
}
|
||||
priv->max_x = priv->max_y = 0;
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
if (children[i].x > priv->max_x)
|
||||
priv->max_x = children[i].x;
|
||||
if (children[i].y > priv->max_y)
|
||||
priv->max_y = children[i].y;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -299,60 +291,55 @@ nmt_newt_grid_find_size (NmtNewtGrid *grid)
|
|||
* details of exactly how this works.
|
||||
*/
|
||||
void
|
||||
nmt_newt_grid_add (NmtNewtGrid *grid,
|
||||
NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y)
|
||||
nmt_newt_grid_add(NmtNewtGrid *grid, NmtNewtWidget *widget, int x, int y)
|
||||
{
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE (grid);
|
||||
NmtNewtGridChild child;
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid);
|
||||
NmtNewtGridChild child;
|
||||
|
||||
NMT_NEWT_CONTAINER_CLASS (nmt_newt_grid_parent_class)->add (NMT_NEWT_CONTAINER (grid), widget);
|
||||
NMT_NEWT_CONTAINER_CLASS(nmt_newt_grid_parent_class)->add(NMT_NEWT_CONTAINER(grid), widget);
|
||||
|
||||
memset (&child, 0, sizeof (child));
|
||||
child.widget = widget;
|
||||
child.x = x;
|
||||
child.y = y;
|
||||
child.flags = NMT_NEWT_GRID_FILL_X | NMT_NEWT_GRID_FILL_Y;
|
||||
g_array_append_val (priv->children, child);
|
||||
memset(&child, 0, sizeof(child));
|
||||
child.widget = widget;
|
||||
child.x = x;
|
||||
child.y = y;
|
||||
child.flags = NMT_NEWT_GRID_FILL_X | NMT_NEWT_GRID_FILL_Y;
|
||||
g_array_append_val(priv->children, child);
|
||||
|
||||
if (x > priv->max_x)
|
||||
priv->max_x = x;
|
||||
if (y > priv->max_y)
|
||||
priv->max_y = y;
|
||||
if (x > priv->max_x)
|
||||
priv->max_x = x;
|
||||
if (y > priv->max_y)
|
||||
priv->max_y = y;
|
||||
}
|
||||
|
||||
static int
|
||||
find_child (NmtNewtGrid *grid,
|
||||
NmtNewtWidget *widget)
|
||||
find_child(NmtNewtGrid *grid, NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE (grid);
|
||||
NmtNewtGridChild *children = (NmtNewtGridChild *)priv->children->data;
|
||||
int i;
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid);
|
||||
NmtNewtGridChild * children = (NmtNewtGridChild *) priv->children->data;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
if (children[i].widget == widget)
|
||||
return i;
|
||||
}
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
if (children[i].widget == widget)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_grid_remove (NmtNewtContainer *container,
|
||||
NmtNewtWidget *widget)
|
||||
nmt_newt_grid_remove(NmtNewtContainer *container, NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtGrid *grid = NMT_NEWT_GRID (container);
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE (grid);
|
||||
int i;
|
||||
NmtNewtGrid * grid = NMT_NEWT_GRID(container);
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid);
|
||||
int i;
|
||||
|
||||
i = find_child (grid, widget);
|
||||
if (i != -1) {
|
||||
g_array_remove_index (priv->children, i);
|
||||
nmt_newt_grid_find_size (grid);
|
||||
}
|
||||
i = find_child(grid, widget);
|
||||
if (i != -1) {
|
||||
g_array_remove_index(priv->children, i);
|
||||
nmt_newt_grid_find_size(grid);
|
||||
}
|
||||
|
||||
NMT_NEWT_CONTAINER_CLASS (nmt_newt_grid_parent_class)->remove (container, widget);
|
||||
NMT_NEWT_CONTAINER_CLASS(nmt_newt_grid_parent_class)->remove(container, widget);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -365,22 +352,19 @@ nmt_newt_grid_remove (NmtNewtContainer *container,
|
|||
* Moves @widget to the given new coordinates.
|
||||
*/
|
||||
void
|
||||
nmt_newt_grid_move (NmtNewtGrid *grid,
|
||||
NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y)
|
||||
nmt_newt_grid_move(NmtNewtGrid *grid, NmtNewtWidget *widget, int x, int y)
|
||||
{
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE (grid);
|
||||
NmtNewtGridChild *children = (NmtNewtGridChild *)priv->children->data;
|
||||
int i;
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid);
|
||||
NmtNewtGridChild * children = (NmtNewtGridChild *) priv->children->data;
|
||||
int i;
|
||||
|
||||
i = find_child (grid, widget);
|
||||
if (i != -1 && (children[i].x != x || children[i].y != y)) {
|
||||
children[i].x = x;
|
||||
children[i].y = y;
|
||||
nmt_newt_grid_find_size (grid);
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (grid));
|
||||
}
|
||||
i = find_child(grid, widget);
|
||||
if (i != -1 && (children[i].x != x || children[i].y != y)) {
|
||||
children[i].x = x;
|
||||
children[i].y = y;
|
||||
nmt_newt_grid_find_size(grid);
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(grid));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -424,34 +408,32 @@ nmt_newt_grid_move (NmtNewtGrid *grid,
|
|||
* Sets the #NmtNewtGridFlags on @widget
|
||||
*/
|
||||
void
|
||||
nmt_newt_grid_set_flags (NmtNewtGrid *grid,
|
||||
NmtNewtWidget *widget,
|
||||
NmtNewtGridFlags flags)
|
||||
nmt_newt_grid_set_flags(NmtNewtGrid *grid, NmtNewtWidget *widget, NmtNewtGridFlags flags)
|
||||
{
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE (grid);
|
||||
NmtNewtGridChild *children = (NmtNewtGridChild *)priv->children->data;
|
||||
int i;
|
||||
NmtNewtGridPrivate *priv = NMT_NEWT_GRID_GET_PRIVATE(grid);
|
||||
NmtNewtGridChild * children = (NmtNewtGridChild *) priv->children->data;
|
||||
int i;
|
||||
|
||||
i = find_child (grid, widget);
|
||||
if (i != -1)
|
||||
children[i].flags = flags;
|
||||
i = find_child(grid, widget);
|
||||
if (i != -1)
|
||||
children[i].flags = flags;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_grid_class_init (NmtNewtGridClass *grid_class)
|
||||
nmt_newt_grid_class_init(NmtNewtGridClass *grid_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (grid_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (grid_class);
|
||||
NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS (grid_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(grid_class);
|
||||
NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(grid_class);
|
||||
NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS(grid_class);
|
||||
|
||||
g_type_class_add_private (grid_class, sizeof (NmtNewtGridPrivate));
|
||||
g_type_class_add_private(grid_class, sizeof(NmtNewtGridPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->finalize = nmt_newt_grid_finalize;
|
||||
/* virtual methods */
|
||||
object_class->finalize = nmt_newt_grid_finalize;
|
||||
|
||||
widget_class->get_components = nmt_newt_grid_get_components;
|
||||
widget_class->size_request = nmt_newt_grid_size_request;
|
||||
widget_class->size_allocate = nmt_newt_grid_size_allocate;
|
||||
widget_class->get_components = nmt_newt_grid_get_components;
|
||||
widget_class->size_request = nmt_newt_grid_size_request;
|
||||
widget_class->size_allocate = nmt_newt_grid_size_allocate;
|
||||
|
||||
container_class->remove = nmt_newt_grid_remove;
|
||||
container_class->remove = nmt_newt_grid_remove;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,48 +8,41 @@
|
|||
|
||||
#include "nmt-newt-container.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_GRID (nmt_newt_grid_get_type ())
|
||||
#define NMT_NEWT_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_GRID, NmtNewtGrid))
|
||||
#define NMT_NEWT_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_GRID, NmtNewtGridClass))
|
||||
#define NMT_IS_NEWT_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_GRID))
|
||||
#define NMT_IS_NEWT_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_GRID))
|
||||
#define NMT_NEWT_GRID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_GRID, NmtNewtGridClass))
|
||||
#define NMT_TYPE_NEWT_GRID (nmt_newt_grid_get_type())
|
||||
#define NMT_NEWT_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_GRID, NmtNewtGrid))
|
||||
#define NMT_NEWT_GRID_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_GRID, NmtNewtGridClass))
|
||||
#define NMT_IS_NEWT_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_GRID))
|
||||
#define NMT_IS_NEWT_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_GRID))
|
||||
#define NMT_NEWT_GRID_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_GRID, NmtNewtGridClass))
|
||||
|
||||
struct _NmtNewtGrid {
|
||||
NmtNewtContainer parent;
|
||||
|
||||
NmtNewtContainer parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtContainerClass parent;
|
||||
NmtNewtContainerClass parent;
|
||||
|
||||
} NmtNewtGridClass;
|
||||
|
||||
GType nmt_newt_grid_get_type (void);
|
||||
GType nmt_newt_grid_get_type(void);
|
||||
|
||||
typedef enum {
|
||||
NMT_NEWT_GRID_EXPAND_X = (1 << 0),
|
||||
NMT_NEWT_GRID_EXPAND_Y = (1 << 1),
|
||||
NMT_NEWT_GRID_ANCHOR_LEFT = (1 << 2),
|
||||
NMT_NEWT_GRID_ANCHOR_RIGHT = (1 << 3),
|
||||
NMT_NEWT_GRID_FILL_X = NMT_NEWT_GRID_ANCHOR_LEFT | NMT_NEWT_GRID_ANCHOR_RIGHT,
|
||||
NMT_NEWT_GRID_ANCHOR_TOP = (1 << 4),
|
||||
NMT_NEWT_GRID_ANCHOR_BOTTOM = (1 << 5),
|
||||
NMT_NEWT_GRID_FILL_Y = NMT_NEWT_GRID_ANCHOR_TOP | NMT_NEWT_GRID_ANCHOR_BOTTOM,
|
||||
NMT_NEWT_GRID_EXPAND_X = (1 << 0),
|
||||
NMT_NEWT_GRID_EXPAND_Y = (1 << 1),
|
||||
NMT_NEWT_GRID_ANCHOR_LEFT = (1 << 2),
|
||||
NMT_NEWT_GRID_ANCHOR_RIGHT = (1 << 3),
|
||||
NMT_NEWT_GRID_FILL_X = NMT_NEWT_GRID_ANCHOR_LEFT | NMT_NEWT_GRID_ANCHOR_RIGHT,
|
||||
NMT_NEWT_GRID_ANCHOR_TOP = (1 << 4),
|
||||
NMT_NEWT_GRID_ANCHOR_BOTTOM = (1 << 5),
|
||||
NMT_NEWT_GRID_FILL_Y = NMT_NEWT_GRID_ANCHOR_TOP | NMT_NEWT_GRID_ANCHOR_BOTTOM,
|
||||
} NmtNewtGridFlags;
|
||||
|
||||
NmtNewtWidget *nmt_newt_grid_new (void);
|
||||
NmtNewtWidget *nmt_newt_grid_new(void);
|
||||
|
||||
void nmt_newt_grid_add (NmtNewtGrid *grid,
|
||||
NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y);
|
||||
void nmt_newt_grid_move (NmtNewtGrid *grid,
|
||||
NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y);
|
||||
void nmt_newt_grid_set_flags (NmtNewtGrid *grid,
|
||||
NmtNewtWidget *widget,
|
||||
NmtNewtGridFlags flags);
|
||||
void nmt_newt_grid_add(NmtNewtGrid *grid, NmtNewtWidget *widget, int x, int y);
|
||||
void nmt_newt_grid_move(NmtNewtGrid *grid, NmtNewtWidget *widget, int x, int y);
|
||||
void nmt_newt_grid_set_flags(NmtNewtGrid *grid, NmtNewtWidget *widget, NmtNewtGridFlags flags);
|
||||
|
||||
#endif /* NMT_NEWT_GRID_H */
|
||||
|
|
|
|||
|
|
@ -15,76 +15,71 @@
|
|||
|
||||
#include "nmt-newt-hacks.h"
|
||||
|
||||
#if !defined (HAVE_NEWTCOMPONENTGETSIZE) || !defined (HAVE_NEWTENTRYGETCURSORPOSITION)
|
||||
#if !defined(HAVE_NEWTCOMPONENTGETSIZE) || !defined(HAVE_NEWTENTRYGETCURSORPOSITION)
|
||||
struct newtComponent_0_52_15_struct_hack {
|
||||
int height, width;
|
||||
int top, left;
|
||||
int takesFocus;
|
||||
int isMapped;
|
||||
int height, width;
|
||||
int top, left;
|
||||
int takesFocus;
|
||||
int isMapped;
|
||||
|
||||
struct componentOps *ops;
|
||||
struct componentOps *ops;
|
||||
|
||||
newtCallback callback;
|
||||
void *callbackData;
|
||||
newtCallback callback;
|
||||
void * callbackData;
|
||||
|
||||
newtCallback destroyCallback;
|
||||
void *destroyCallbackData;
|
||||
newtCallback destroyCallback;
|
||||
void * destroyCallbackData;
|
||||
|
||||
void *data;
|
||||
void *data;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_NEWTCOMPONENTGETSIZE
|
||||
void
|
||||
newtComponentGetSize (newtComponent component,
|
||||
int *width,
|
||||
int *height)
|
||||
newtComponentGetSize(newtComponent component, int *width, int *height)
|
||||
{
|
||||
struct newtComponent_0_52_15_struct_hack *hack = (void *) component;
|
||||
struct newtComponent_0_52_15_struct_hack *hack = (void *) component;
|
||||
|
||||
*width = hack->width;
|
||||
*height = hack->height;
|
||||
*width = hack->width;
|
||||
*height = hack->height;
|
||||
}
|
||||
|
||||
void
|
||||
newtComponentGetPosition (newtComponent component,
|
||||
int *left,
|
||||
int *top)
|
||||
newtComponentGetPosition(newtComponent component, int *left, int *top)
|
||||
{
|
||||
struct newtComponent_0_52_15_struct_hack *hack = (void *) component;
|
||||
struct newtComponent_0_52_15_struct_hack *hack = (void *) component;
|
||||
|
||||
*left = hack->left;
|
||||
*top = hack->top;
|
||||
*left = hack->left;
|
||||
*top = hack->top;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_NEWTENTRYGETCURSORPOSITION
|
||||
struct newtEntry_0_52_15_struct_hack {
|
||||
int flags;
|
||||
char *buf;
|
||||
const char **resultPtr;
|
||||
int bufAlloced;
|
||||
int bufUsed;
|
||||
int cursorPosition;
|
||||
/* ... */
|
||||
int flags;
|
||||
char * buf;
|
||||
const char **resultPtr;
|
||||
int bufAlloced;
|
||||
int bufUsed;
|
||||
int cursorPosition;
|
||||
/* ... */
|
||||
};
|
||||
|
||||
int
|
||||
newtEntryGetCursorPosition (newtComponent component)
|
||||
newtEntryGetCursorPosition(newtComponent component)
|
||||
{
|
||||
struct newtComponent_0_52_15_struct_hack *co_hack = (void *) component;
|
||||
struct newtEntry_0_52_15_struct_hack *entry_hack = co_hack->data;
|
||||
struct newtComponent_0_52_15_struct_hack *co_hack = (void *) component;
|
||||
struct newtEntry_0_52_15_struct_hack * entry_hack = co_hack->data;
|
||||
|
||||
return entry_hack->cursorPosition;
|
||||
return entry_hack->cursorPosition;
|
||||
}
|
||||
|
||||
void
|
||||
newtEntrySetCursorPosition (newtComponent component,
|
||||
int position)
|
||||
newtEntrySetCursorPosition(newtComponent component, int position)
|
||||
{
|
||||
struct newtComponent_0_52_15_struct_hack *co_hack = (void *) component;
|
||||
struct newtEntry_0_52_15_struct_hack *entry_hack = co_hack->data;
|
||||
struct newtComponent_0_52_15_struct_hack *co_hack = (void *) component;
|
||||
struct newtEntry_0_52_15_struct_hack * entry_hack = co_hack->data;
|
||||
|
||||
entry_hack->cursorPosition = position;
|
||||
entry_hack->cursorPosition = position;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,19 +9,14 @@
|
|||
#include <newt.h>
|
||||
|
||||
#ifndef HAVE_NEWTCOMPONENTGETSIZE
|
||||
void newtComponentGetSize (newtComponent component,
|
||||
int *width,
|
||||
int *height);
|
||||
void newtComponentGetSize(newtComponent component, int *width, int *height);
|
||||
|
||||
void newtComponentGetPosition (newtComponent component,
|
||||
int *left,
|
||||
int *top);
|
||||
void newtComponentGetPosition(newtComponent component, int *left, int *top);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_NEWTENTRYGETCURSORPOSITION
|
||||
int newtEntryGetCursorPosition (newtComponent component);
|
||||
void newtEntrySetCursorPosition (newtComponent component,
|
||||
int position);
|
||||
int newtEntryGetCursorPosition(newtComponent component);
|
||||
void newtEntrySetCursorPosition(newtComponent component, int position);
|
||||
#endif
|
||||
|
||||
#endif /* NMT_NEWT_HACKS_H */
|
||||
|
|
|
|||
|
|
@ -18,23 +18,24 @@
|
|||
|
||||
#include "nmt-newt-utils.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtNewtLabel, nmt_newt_label, NMT_TYPE_NEWT_COMPONENT)
|
||||
G_DEFINE_TYPE(NmtNewtLabel, nmt_newt_label, NMT_TYPE_NEWT_COMPONENT)
|
||||
|
||||
#define NMT_NEWT_LABEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_LABEL, NmtNewtLabelPrivate))
|
||||
#define NMT_NEWT_LABEL_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_LABEL, NmtNewtLabelPrivate))
|
||||
|
||||
typedef struct {
|
||||
char *text;
|
||||
NmtNewtLabelStyle style;
|
||||
gboolean highlight;
|
||||
char * text;
|
||||
NmtNewtLabelStyle style;
|
||||
gboolean highlight;
|
||||
} NmtNewtLabelPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_TEXT,
|
||||
PROP_STYLE,
|
||||
PROP_HIGHLIGHT,
|
||||
PROP_0,
|
||||
PROP_TEXT,
|
||||
PROP_STYLE,
|
||||
PROP_HIGHLIGHT,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -46,11 +47,9 @@ enum {
|
|||
* Returns: a new #NmtNewtLabel
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_label_new (const char *text)
|
||||
nmt_newt_label_new(const char *text)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_NEWT_LABEL,
|
||||
"text", text,
|
||||
NULL);
|
||||
return g_object_new(NMT_TYPE_NEWT_LABEL, "text", text, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -61,19 +60,18 @@ nmt_newt_label_new (const char *text)
|
|||
* Updates @label's text.
|
||||
*/
|
||||
void
|
||||
nmt_newt_label_set_text (NmtNewtLabel *label,
|
||||
const char *text)
|
||||
nmt_newt_label_set_text(NmtNewtLabel *label, const char *text)
|
||||
{
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE (label);
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE(label);
|
||||
|
||||
if (!g_strcmp0 (priv->text, text))
|
||||
return;
|
||||
if (!g_strcmp0(priv->text, text))
|
||||
return;
|
||||
|
||||
g_free (priv->text);
|
||||
priv->text = g_strdup (text);
|
||||
g_free(priv->text);
|
||||
priv->text = g_strdup(text);
|
||||
|
||||
g_object_notify (G_OBJECT (label), "text");
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (label));
|
||||
g_object_notify(G_OBJECT(label), "text");
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(label));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -85,11 +83,11 @@ nmt_newt_label_set_text (NmtNewtLabel *label,
|
|||
* Returns: @label's text
|
||||
*/
|
||||
const char *
|
||||
nmt_newt_label_get_text (NmtNewtLabel *label)
|
||||
nmt_newt_label_get_text(NmtNewtLabel *label)
|
||||
{
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE (label);
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE(label);
|
||||
|
||||
return priv->text;
|
||||
return priv->text;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -110,17 +108,16 @@ nmt_newt_label_get_text (NmtNewtLabel *label)
|
|||
* Sets the style of @label
|
||||
*/
|
||||
void
|
||||
nmt_newt_label_set_style (NmtNewtLabel *label,
|
||||
NmtNewtLabelStyle style)
|
||||
nmt_newt_label_set_style(NmtNewtLabel *label, NmtNewtLabelStyle style)
|
||||
{
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE (label);
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE(label);
|
||||
|
||||
if (priv->style == style)
|
||||
return;
|
||||
if (priv->style == style)
|
||||
return;
|
||||
|
||||
priv->style = style;
|
||||
g_object_notify (G_OBJECT (label), "style");
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (label));
|
||||
priv->style = style;
|
||||
g_object_notify(G_OBJECT(label), "style");
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(label));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -132,11 +129,11 @@ nmt_newt_label_set_style (NmtNewtLabel *label,
|
|||
* Returns: the style of @label
|
||||
*/
|
||||
NmtNewtLabelStyle
|
||||
nmt_newt_label_get_style (NmtNewtLabel *label)
|
||||
nmt_newt_label_get_style(NmtNewtLabel *label)
|
||||
{
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE (label);
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE(label);
|
||||
|
||||
return priv->style;
|
||||
return priv->style;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -148,18 +145,17 @@ nmt_newt_label_get_style (NmtNewtLabel *label)
|
|||
* this is generally used to highlight invalid widgets.
|
||||
*/
|
||||
void
|
||||
nmt_newt_label_set_highlight (NmtNewtLabel *label,
|
||||
gboolean highlight)
|
||||
nmt_newt_label_set_highlight(NmtNewtLabel *label, gboolean highlight)
|
||||
{
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE (label);
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE(label);
|
||||
|
||||
highlight = !!highlight;
|
||||
if (priv->highlight == highlight)
|
||||
return;
|
||||
highlight = !!highlight;
|
||||
if (priv->highlight == highlight)
|
||||
return;
|
||||
|
||||
priv->highlight = highlight;
|
||||
g_object_notify (G_OBJECT (label), "highlight");
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (label));
|
||||
priv->highlight = highlight;
|
||||
g_object_notify(G_OBJECT(label), "highlight");
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(label));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -171,142 +167,137 @@ nmt_newt_label_set_highlight (NmtNewtLabel *label,
|
|||
* Returns: whether @label is highlighted.
|
||||
*/
|
||||
gboolean
|
||||
nmt_newt_label_get_highlight (NmtNewtLabel *label)
|
||||
nmt_newt_label_get_highlight(NmtNewtLabel *label)
|
||||
{
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE (label);
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE(label);
|
||||
|
||||
return priv->highlight;
|
||||
return priv->highlight;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_label_init (NmtNewtLabel *label)
|
||||
{
|
||||
}
|
||||
nmt_newt_label_init(NmtNewtLabel *label)
|
||||
{}
|
||||
|
||||
static void
|
||||
nmt_newt_label_finalize (GObject *object)
|
||||
nmt_newt_label_finalize(GObject *object)
|
||||
{
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE (object);
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE(object);
|
||||
|
||||
g_free (priv->text);
|
||||
g_free(priv->text);
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_label_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS(nmt_newt_label_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static newtComponent
|
||||
nmt_newt_label_build_component (NmtNewtComponent *component,
|
||||
gboolean sensitive)
|
||||
nmt_newt_label_build_component(NmtNewtComponent *component, gboolean sensitive)
|
||||
{
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE (component);
|
||||
newtComponent co;
|
||||
char *text_lc;
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE(component);
|
||||
newtComponent co;
|
||||
char * text_lc;
|
||||
|
||||
text_lc = nmt_newt_locale_from_utf8 (priv->text);
|
||||
co = newtLabel (-1, -1, text_lc);
|
||||
g_free (text_lc);
|
||||
text_lc = nmt_newt_locale_from_utf8(priv->text);
|
||||
co = newtLabel(-1, -1, text_lc);
|
||||
g_free(text_lc);
|
||||
|
||||
if (priv->highlight)
|
||||
newtLabelSetColors (co, NMT_NEWT_COLORSET_BAD_LABEL);
|
||||
else if (priv->style == NMT_NEWT_LABEL_PLAIN)
|
||||
newtLabelSetColors (co, NMT_NEWT_COLORSET_PLAIN_LABEL);
|
||||
if (priv->highlight)
|
||||
newtLabelSetColors(co, NMT_NEWT_COLORSET_BAD_LABEL);
|
||||
else if (priv->style == NMT_NEWT_LABEL_PLAIN)
|
||||
newtLabelSetColors(co, NMT_NEWT_COLORSET_PLAIN_LABEL);
|
||||
|
||||
return co;
|
||||
return co;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_label_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_label_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtLabel *label = NMT_NEWT_LABEL (object);
|
||||
NmtNewtLabel *label = NMT_NEWT_LABEL(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_TEXT:
|
||||
nmt_newt_label_set_text (label, g_value_get_string (value));
|
||||
break;
|
||||
case PROP_STYLE:
|
||||
nmt_newt_label_set_style (label, g_value_get_int (value));
|
||||
break;
|
||||
case PROP_HIGHLIGHT:
|
||||
nmt_newt_label_set_highlight (label, g_value_get_boolean (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_TEXT:
|
||||
nmt_newt_label_set_text(label, g_value_get_string(value));
|
||||
break;
|
||||
case PROP_STYLE:
|
||||
nmt_newt_label_set_style(label, g_value_get_int(value));
|
||||
break;
|
||||
case PROP_HIGHLIGHT:
|
||||
nmt_newt_label_set_highlight(label, g_value_get_boolean(value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_label_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_label_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE (object);
|
||||
NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_TEXT:
|
||||
g_value_set_string (value, priv->text);
|
||||
break;
|
||||
case PROP_STYLE:
|
||||
g_value_set_int (value, priv->style);
|
||||
break;
|
||||
case PROP_HIGHLIGHT:
|
||||
g_value_set_boolean (value, priv->highlight);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_TEXT:
|
||||
g_value_set_string(value, priv->text);
|
||||
break;
|
||||
case PROP_STYLE:
|
||||
g_value_set_int(value, priv->style);
|
||||
break;
|
||||
case PROP_HIGHLIGHT:
|
||||
g_value_set_boolean(value, priv->highlight);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_label_class_init (NmtNewtLabelClass *label_class)
|
||||
nmt_newt_label_class_init(NmtNewtLabelClass *label_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (label_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS (label_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(label_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(label_class);
|
||||
|
||||
g_type_class_add_private (label_class, sizeof (NmtNewtLabelPrivate));
|
||||
g_type_class_add_private(label_class, sizeof(NmtNewtLabelPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_label_set_property;
|
||||
object_class->get_property = nmt_newt_label_get_property;
|
||||
object_class->finalize = nmt_newt_label_finalize;
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_label_set_property;
|
||||
object_class->get_property = nmt_newt_label_get_property;
|
||||
object_class->finalize = nmt_newt_label_finalize;
|
||||
|
||||
component_class->build_component = nmt_newt_label_build_component;
|
||||
component_class->build_component = nmt_newt_label_build_component;
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtLabel:text:
|
||||
*
|
||||
* The label's text
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_TEXT,
|
||||
g_param_spec_string ("text", "", "",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_TEXT,
|
||||
g_param_spec_string("text", "", "", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtLabel:style:
|
||||
*
|
||||
* The label's #NmtNewtLabelStyle
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_STYLE,
|
||||
g_param_spec_int ("style", "", "",
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(object_class,
|
||||
PROP_STYLE,
|
||||
g_param_spec_int("style",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
G_MAXINT,
|
||||
0,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtLabel:highlight:
|
||||
*
|
||||
* Whether the label is highlighted.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_HIGHLIGHT,
|
||||
g_param_spec_boolean ("highlight", "", "",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_HIGHLIGHT,
|
||||
g_param_spec_boolean("highlight",
|
||||
"",
|
||||
"",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,42 +8,37 @@
|
|||
|
||||
#include "nmt-newt-component.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_LABEL (nmt_newt_label_get_type ())
|
||||
#define NMT_NEWT_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_LABEL, NmtNewtLabel))
|
||||
#define NMT_NEWT_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_LABEL, NmtNewtLabelClass))
|
||||
#define NMT_IS_NEWT_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_LABEL))
|
||||
#define NMT_IS_NEWT_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_LABEL))
|
||||
#define NMT_NEWT_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_LABEL, NmtNewtLabelClass))
|
||||
#define NMT_TYPE_NEWT_LABEL (nmt_newt_label_get_type())
|
||||
#define NMT_NEWT_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_LABEL, NmtNewtLabel))
|
||||
#define NMT_NEWT_LABEL_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_LABEL, NmtNewtLabelClass))
|
||||
#define NMT_IS_NEWT_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_LABEL))
|
||||
#define NMT_IS_NEWT_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_LABEL))
|
||||
#define NMT_NEWT_LABEL_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_LABEL, NmtNewtLabelClass))
|
||||
|
||||
struct _NmtNewtLabel {
|
||||
NmtNewtComponent parent;
|
||||
|
||||
NmtNewtComponent parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtComponentClass parent;
|
||||
NmtNewtComponentClass parent;
|
||||
|
||||
} NmtNewtLabelClass;
|
||||
|
||||
GType nmt_newt_label_get_type (void);
|
||||
GType nmt_newt_label_get_type(void);
|
||||
|
||||
typedef enum {
|
||||
NMT_NEWT_LABEL_NORMAL,
|
||||
NMT_NEWT_LABEL_PLAIN
|
||||
} NmtNewtLabelStyle;
|
||||
typedef enum { NMT_NEWT_LABEL_NORMAL, NMT_NEWT_LABEL_PLAIN } NmtNewtLabelStyle;
|
||||
|
||||
NmtNewtWidget *nmt_newt_label_new (const char *text);
|
||||
NmtNewtWidget *nmt_newt_label_new(const char *text);
|
||||
|
||||
void nmt_newt_label_set_text (NmtNewtLabel *label,
|
||||
const char *text);
|
||||
const char *nmt_newt_label_get_text (NmtNewtLabel *label);
|
||||
void nmt_newt_label_set_text(NmtNewtLabel *label, const char *text);
|
||||
const char *nmt_newt_label_get_text(NmtNewtLabel *label);
|
||||
|
||||
void nmt_newt_label_set_style (NmtNewtLabel *label,
|
||||
NmtNewtLabelStyle style);
|
||||
NmtNewtLabelStyle nmt_newt_label_get_style (NmtNewtLabel *label);
|
||||
void nmt_newt_label_set_style(NmtNewtLabel *label, NmtNewtLabelStyle style);
|
||||
NmtNewtLabelStyle nmt_newt_label_get_style(NmtNewtLabel *label);
|
||||
|
||||
void nmt_newt_label_set_highlight (NmtNewtLabel *label,
|
||||
gboolean highlight);
|
||||
gboolean nmt_newt_label_get_highlight (NmtNewtLabel *label);
|
||||
void nmt_newt_label_set_highlight(NmtNewtLabel *label, gboolean highlight);
|
||||
gboolean nmt_newt_label_get_highlight(NmtNewtLabel *label);
|
||||
|
||||
#endif /* NMT_NEWT_LABEL_H */
|
||||
|
|
|
|||
|
|
@ -24,33 +24,34 @@
|
|||
#include "nmt-newt-form.h"
|
||||
#include "nmt-newt-utils.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtNewtListbox, nmt_newt_listbox, NMT_TYPE_NEWT_COMPONENT)
|
||||
G_DEFINE_TYPE(NmtNewtListbox, nmt_newt_listbox, NMT_TYPE_NEWT_COMPONENT)
|
||||
|
||||
#define NMT_NEWT_LISTBOX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_LISTBOX, NmtNewtListboxPrivate))
|
||||
#define NMT_NEWT_LISTBOX_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_LISTBOX, NmtNewtListboxPrivate))
|
||||
|
||||
typedef struct {
|
||||
int height, alloc_height, width;
|
||||
gboolean fixed_height;
|
||||
NmtNewtListboxFlags flags;
|
||||
int height, alloc_height, width;
|
||||
gboolean fixed_height;
|
||||
NmtNewtListboxFlags flags;
|
||||
|
||||
GPtrArray *entries;
|
||||
GPtrArray *keys;
|
||||
GPtrArray *entries;
|
||||
GPtrArray *keys;
|
||||
|
||||
int active;
|
||||
gpointer active_key;
|
||||
gboolean skip_null_keys;
|
||||
int active;
|
||||
gpointer active_key;
|
||||
gboolean skip_null_keys;
|
||||
|
||||
} NmtNewtListboxPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_HEIGHT,
|
||||
PROP_FLAGS,
|
||||
PROP_ACTIVE,
|
||||
PROP_ACTIVE_KEY,
|
||||
PROP_SKIP_NULL_KEYS,
|
||||
PROP_0,
|
||||
PROP_HEIGHT,
|
||||
PROP_FLAGS,
|
||||
PROP_ACTIVE,
|
||||
PROP_ACTIVE_KEY,
|
||||
PROP_SKIP_NULL_KEYS,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -71,13 +72,9 @@ enum {
|
|||
* Returns: a new #NmtNewtListbox
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_listbox_new (int height,
|
||||
NmtNewtListboxFlags flags)
|
||||
nmt_newt_listbox_new(int height, NmtNewtListboxFlags flags)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_NEWT_LISTBOX,
|
||||
"height", height,
|
||||
"flags", flags,
|
||||
NULL);
|
||||
return g_object_new(NMT_TYPE_NEWT_LISTBOX, "height", height, "flags", flags, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -89,15 +86,13 @@ nmt_newt_listbox_new (int height,
|
|||
* Adds a row to @listbox.
|
||||
*/
|
||||
void
|
||||
nmt_newt_listbox_append (NmtNewtListbox *listbox,
|
||||
const char *entry,
|
||||
gpointer key)
|
||||
nmt_newt_listbox_append(NmtNewtListbox *listbox, const char *entry, gpointer key)
|
||||
{
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (listbox);
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(listbox);
|
||||
|
||||
g_ptr_array_add (priv->entries, nmt_newt_locale_from_utf8 (entry));
|
||||
g_ptr_array_add (priv->keys, key);
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (listbox));
|
||||
g_ptr_array_add(priv->entries, nmt_newt_locale_from_utf8(entry));
|
||||
g_ptr_array_add(priv->keys, key);
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(listbox));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -107,17 +102,17 @@ nmt_newt_listbox_append (NmtNewtListbox *listbox,
|
|||
* Clears the contents of @listbox.
|
||||
*/
|
||||
void
|
||||
nmt_newt_listbox_clear (NmtNewtListbox *listbox)
|
||||
nmt_newt_listbox_clear(NmtNewtListbox *listbox)
|
||||
{
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (listbox);
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(listbox);
|
||||
|
||||
g_ptr_array_set_size (priv->entries, 0);
|
||||
g_ptr_array_set_size (priv->keys, 0);
|
||||
g_ptr_array_set_size(priv->entries, 0);
|
||||
g_ptr_array_set_size(priv->keys, 0);
|
||||
|
||||
priv->active = -1;
|
||||
priv->active_key = NULL;
|
||||
priv->active = -1;
|
||||
priv->active_key = NULL;
|
||||
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (listbox));
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(listbox));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -129,22 +124,21 @@ nmt_newt_listbox_clear (NmtNewtListbox *listbox)
|
|||
* scrolling it into view if needed.
|
||||
*/
|
||||
void
|
||||
nmt_newt_listbox_set_active (NmtNewtListbox *listbox,
|
||||
int active)
|
||||
nmt_newt_listbox_set_active(NmtNewtListbox *listbox, int active)
|
||||
{
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (listbox);
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(listbox);
|
||||
|
||||
if (active == priv->active)
|
||||
return;
|
||||
if (active == priv->active)
|
||||
return;
|
||||
|
||||
g_return_if_fail (active >= 0 && active < priv->entries->len);
|
||||
g_return_if_fail (!priv->skip_null_keys || priv->keys->pdata[active]);
|
||||
g_return_if_fail(active >= 0 && active < priv->entries->len);
|
||||
g_return_if_fail(!priv->skip_null_keys || priv->keys->pdata[active]);
|
||||
|
||||
priv->active = active;
|
||||
priv->active_key = priv->keys->pdata[active];
|
||||
priv->active = active;
|
||||
priv->active_key = priv->keys->pdata[active];
|
||||
|
||||
g_object_notify (G_OBJECT (listbox), "active");
|
||||
g_object_notify (G_OBJECT (listbox), "active-key");
|
||||
g_object_notify(G_OBJECT(listbox), "active");
|
||||
g_object_notify(G_OBJECT(listbox), "active-key");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -156,27 +150,26 @@ nmt_newt_listbox_set_active (NmtNewtListbox *listbox,
|
|||
* scrolling it into view if needed.
|
||||
*/
|
||||
void
|
||||
nmt_newt_listbox_set_active_key (NmtNewtListbox *listbox,
|
||||
gpointer active_key)
|
||||
nmt_newt_listbox_set_active_key(NmtNewtListbox *listbox, gpointer active_key)
|
||||
{
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (listbox);
|
||||
int i;
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(listbox);
|
||||
int i;
|
||||
|
||||
if (active_key == priv->active_key)
|
||||
return;
|
||||
if (active_key == priv->active_key)
|
||||
return;
|
||||
|
||||
g_return_if_fail (!priv->skip_null_keys || active_key);
|
||||
g_return_if_fail(!priv->skip_null_keys || active_key);
|
||||
|
||||
for (i = 0; i < priv->keys->len; i++) {
|
||||
if (priv->keys->pdata[i] == active_key) {
|
||||
priv->active = i;
|
||||
priv->active_key = active_key;
|
||||
for (i = 0; i < priv->keys->len; i++) {
|
||||
if (priv->keys->pdata[i] == active_key) {
|
||||
priv->active = i;
|
||||
priv->active_key = active_key;
|
||||
|
||||
g_object_notify (G_OBJECT (listbox), "active");
|
||||
g_object_notify (G_OBJECT (listbox), "active-key");
|
||||
return;
|
||||
}
|
||||
}
|
||||
g_object_notify(G_OBJECT(listbox), "active");
|
||||
g_object_notify(G_OBJECT(listbox), "active-key");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -188,11 +181,11 @@ nmt_newt_listbox_set_active_key (NmtNewtListbox *listbox,
|
|||
* Returns: the currently-selected row in @listbox.
|
||||
*/
|
||||
int
|
||||
nmt_newt_listbox_get_active (NmtNewtListbox *listbox)
|
||||
nmt_newt_listbox_get_active(NmtNewtListbox *listbox)
|
||||
{
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (listbox);
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(listbox);
|
||||
|
||||
return priv->active;
|
||||
return priv->active;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -204,11 +197,11 @@ nmt_newt_listbox_get_active (NmtNewtListbox *listbox)
|
|||
* Returns: the key of the currently-selected row in @listbox.
|
||||
*/
|
||||
gpointer
|
||||
nmt_newt_listbox_get_active_key (NmtNewtListbox *listbox)
|
||||
nmt_newt_listbox_get_active_key(NmtNewtListbox *listbox)
|
||||
{
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (listbox);
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(listbox);
|
||||
|
||||
return priv->active_key;
|
||||
return priv->active_key;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -219,317 +212,307 @@ nmt_newt_listbox_get_active_key (NmtNewtListbox *listbox)
|
|||
* Updates @listbox's height.
|
||||
*/
|
||||
void
|
||||
nmt_newt_listbox_set_height (NmtNewtListbox *listbox,
|
||||
int height)
|
||||
nmt_newt_listbox_set_height(NmtNewtListbox *listbox, int height)
|
||||
{
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (listbox);
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(listbox);
|
||||
|
||||
priv->height = height;
|
||||
priv->fixed_height = priv->height != 0;
|
||||
g_object_notify (G_OBJECT (listbox), "height");
|
||||
priv->height = height;
|
||||
priv->fixed_height = priv->height != 0;
|
||||
g_object_notify(G_OBJECT(listbox), "height");
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_listbox_init (NmtNewtListbox *listbox)
|
||||
nmt_newt_listbox_init(NmtNewtListbox *listbox)
|
||||
{
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (listbox);
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(listbox);
|
||||
|
||||
priv->entries = g_ptr_array_new_with_free_func (g_free);
|
||||
priv->keys = g_ptr_array_new ();
|
||||
priv->entries = g_ptr_array_new_with_free_func(g_free);
|
||||
priv->keys = g_ptr_array_new();
|
||||
|
||||
priv->active = -1;
|
||||
priv->active = -1;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_listbox_finalize (GObject *object)
|
||||
nmt_newt_listbox_finalize(GObject *object)
|
||||
{
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (object);
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(object);
|
||||
|
||||
g_ptr_array_unref (priv->entries);
|
||||
g_ptr_array_unref (priv->keys);
|
||||
g_ptr_array_unref(priv->entries);
|
||||
g_ptr_array_unref(priv->keys);
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_listbox_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS(nmt_newt_listbox_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_listbox_size_request (NmtNewtWidget *widget,
|
||||
int *width,
|
||||
int *height)
|
||||
nmt_newt_listbox_size_request(NmtNewtWidget *widget, int *width, int *height)
|
||||
{
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (widget);
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(widget);
|
||||
|
||||
NMT_NEWT_WIDGET_CLASS (nmt_newt_listbox_parent_class)->
|
||||
size_request (widget, width, height);
|
||||
NMT_NEWT_WIDGET_CLASS(nmt_newt_listbox_parent_class)->size_request(widget, width, height);
|
||||
|
||||
priv->alloc_height = -1;
|
||||
if (!priv->fixed_height)
|
||||
*height = 1;
|
||||
priv->width = *width;
|
||||
priv->alloc_height = -1;
|
||||
if (!priv->fixed_height)
|
||||
*height = 1;
|
||||
priv->width = *width;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_listbox_size_allocate (NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height)
|
||||
nmt_newt_listbox_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height)
|
||||
{
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (widget);
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(widget);
|
||||
|
||||
if (width > priv->width) {
|
||||
newtListboxSetWidth (nmt_newt_component_get_component (NMT_NEWT_COMPONENT (widget)),
|
||||
width);
|
||||
}
|
||||
if (width > priv->width) {
|
||||
newtListboxSetWidth(nmt_newt_component_get_component(NMT_NEWT_COMPONENT(widget)), width);
|
||||
}
|
||||
|
||||
NMT_NEWT_WIDGET_CLASS (nmt_newt_listbox_parent_class)->
|
||||
size_allocate (widget, x, y, width, height);
|
||||
NMT_NEWT_WIDGET_CLASS(nmt_newt_listbox_parent_class)
|
||||
->size_allocate(widget, x, y, width, height);
|
||||
|
||||
priv->alloc_height = height;
|
||||
priv->alloc_height = height;
|
||||
|
||||
if (!priv->fixed_height && height != priv->height) {
|
||||
priv->height = height;
|
||||
nmt_newt_widget_needs_rebuild (widget);
|
||||
}
|
||||
if (!priv->fixed_height && height != priv->height) {
|
||||
priv->height = height;
|
||||
nmt_newt_widget_needs_rebuild(widget);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
update_active_internal (NmtNewtListbox *listbox,
|
||||
int new_active)
|
||||
update_active_internal(NmtNewtListbox *listbox, int new_active)
|
||||
{
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (listbox);
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(listbox);
|
||||
|
||||
if (priv->active == new_active)
|
||||
return;
|
||||
if (new_active >= priv->keys->len)
|
||||
return;
|
||||
if (priv->active == new_active)
|
||||
return;
|
||||
if (new_active >= priv->keys->len)
|
||||
return;
|
||||
|
||||
if (priv->skip_null_keys && !priv->keys->pdata[new_active]) {
|
||||
if (new_active > priv->active) {
|
||||
while ( new_active < priv->entries->len
|
||||
&& !priv->keys->pdata[new_active])
|
||||
new_active++;
|
||||
} else {
|
||||
while ( new_active >= 0
|
||||
&& !priv->keys->pdata[new_active])
|
||||
new_active--;
|
||||
}
|
||||
if (priv->skip_null_keys && !priv->keys->pdata[new_active]) {
|
||||
if (new_active > priv->active) {
|
||||
while (new_active < priv->entries->len && !priv->keys->pdata[new_active])
|
||||
new_active++;
|
||||
} else {
|
||||
while (new_active >= 0 && !priv->keys->pdata[new_active])
|
||||
new_active--;
|
||||
}
|
||||
|
||||
if ( new_active < 0
|
||||
|| new_active >= priv->entries->len
|
||||
|| !priv->keys->pdata[new_active]) {
|
||||
g_assert (priv->active >= 0 && priv->active < priv->entries->len);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (new_active < 0 || new_active >= priv->entries->len || !priv->keys->pdata[new_active]) {
|
||||
g_assert(priv->active >= 0 && priv->active < priv->entries->len);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nmt_newt_listbox_set_active (listbox, new_active);
|
||||
nmt_newt_listbox_set_active(listbox, new_active);
|
||||
}
|
||||
|
||||
static void
|
||||
selection_changed_callback (newtComponent co,
|
||||
void *user_data)
|
||||
selection_changed_callback(newtComponent co, void *user_data)
|
||||
{
|
||||
NmtNewtListbox *listbox = user_data;
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (listbox);
|
||||
int new_active;
|
||||
NmtNewtListbox * listbox = user_data;
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(listbox);
|
||||
int new_active;
|
||||
|
||||
new_active = GPOINTER_TO_UINT (newtListboxGetCurrent (co));
|
||||
update_active_internal (listbox, new_active);
|
||||
new_active = GPOINTER_TO_UINT(newtListboxGetCurrent(co));
|
||||
update_active_internal(listbox, new_active);
|
||||
|
||||
if (priv->active != new_active)
|
||||
newtListboxSetCurrent (co, priv->active);
|
||||
if (priv->active != new_active)
|
||||
newtListboxSetCurrent(co, priv->active);
|
||||
}
|
||||
|
||||
static guint
|
||||
convert_flags (NmtNewtListboxFlags flags)
|
||||
convert_flags(NmtNewtListboxFlags flags)
|
||||
{
|
||||
guint newt_flags = NEWT_FLAG_RETURNEXIT;
|
||||
guint newt_flags = NEWT_FLAG_RETURNEXIT;
|
||||
|
||||
if (flags & NMT_NEWT_LISTBOX_SCROLL)
|
||||
newt_flags |= NEWT_FLAG_SCROLL;
|
||||
if (flags & NMT_NEWT_LISTBOX_BORDER)
|
||||
newt_flags |= NEWT_FLAG_BORDER;
|
||||
if (flags & NMT_NEWT_LISTBOX_SCROLL)
|
||||
newt_flags |= NEWT_FLAG_SCROLL;
|
||||
if (flags & NMT_NEWT_LISTBOX_BORDER)
|
||||
newt_flags |= NEWT_FLAG_BORDER;
|
||||
|
||||
return newt_flags;
|
||||
return newt_flags;
|
||||
}
|
||||
|
||||
static newtComponent
|
||||
nmt_newt_listbox_build_component (NmtNewtComponent *component,
|
||||
gboolean sensitive)
|
||||
nmt_newt_listbox_build_component(NmtNewtComponent *component, gboolean sensitive)
|
||||
{
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (component);
|
||||
newtComponent co;
|
||||
int i, active;
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(component);
|
||||
newtComponent co;
|
||||
int i, active;
|
||||
|
||||
if (priv->active == -1)
|
||||
update_active_internal (NMT_NEWT_LISTBOX (component), 0);
|
||||
active = priv->active;
|
||||
if (priv->active == -1)
|
||||
update_active_internal(NMT_NEWT_LISTBOX(component), 0);
|
||||
active = priv->active;
|
||||
|
||||
co = newtListbox (-1, -1, priv->height, convert_flags (priv->flags));
|
||||
newtComponentAddCallback (co, selection_changed_callback, component);
|
||||
co = newtListbox(-1, -1, priv->height, convert_flags(priv->flags));
|
||||
newtComponentAddCallback(co, selection_changed_callback, component);
|
||||
|
||||
for (i = 0; i < priv->entries->len; i++) {
|
||||
newtListboxAppendEntry (co, priv->entries->pdata[i], GUINT_TO_POINTER (i));
|
||||
if (active == -1 && priv->keys->pdata[i] == priv->active_key)
|
||||
active = i;
|
||||
}
|
||||
for (i = 0; i < priv->entries->len; i++) {
|
||||
newtListboxAppendEntry(co, priv->entries->pdata[i], GUINT_TO_POINTER(i));
|
||||
if (active == -1 && priv->keys->pdata[i] == priv->active_key)
|
||||
active = i;
|
||||
}
|
||||
|
||||
if (active != -1)
|
||||
newtListboxSetCurrent (co, active);
|
||||
if (active != -1)
|
||||
newtListboxSetCurrent(co, active);
|
||||
|
||||
return co;
|
||||
return co;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_listbox_activated (NmtNewtWidget *widget)
|
||||
nmt_newt_listbox_activated(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtListbox *listbox = NMT_NEWT_LISTBOX (widget);
|
||||
newtComponent co = nmt_newt_component_get_component (NMT_NEWT_COMPONENT (widget));
|
||||
NmtNewtListbox *listbox = NMT_NEWT_LISTBOX(widget);
|
||||
newtComponent co = nmt_newt_component_get_component(NMT_NEWT_COMPONENT(widget));
|
||||
|
||||
nmt_newt_listbox_set_active (listbox, GPOINTER_TO_UINT (newtListboxGetCurrent (co)));
|
||||
nmt_newt_listbox_set_active(listbox, GPOINTER_TO_UINT(newtListboxGetCurrent(co)));
|
||||
|
||||
NMT_NEWT_WIDGET_CLASS (nmt_newt_listbox_parent_class)->activated (widget);
|
||||
NMT_NEWT_WIDGET_CLASS(nmt_newt_listbox_parent_class)->activated(widget);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_listbox_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_listbox_set_property(GObject * object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
NmtNewtListbox *listbox = NMT_NEWT_LISTBOX (object);
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (object);
|
||||
NmtNewtListbox * listbox = NMT_NEWT_LISTBOX(object);
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_HEIGHT:
|
||||
priv->height = g_value_get_int (value);
|
||||
priv->fixed_height = (priv->height != 0);
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
priv->flags = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_ACTIVE:
|
||||
nmt_newt_listbox_set_active (listbox, g_value_get_int (value));
|
||||
break;
|
||||
case PROP_ACTIVE_KEY:
|
||||
nmt_newt_listbox_set_active_key (listbox, g_value_get_pointer (value));
|
||||
break;
|
||||
case PROP_SKIP_NULL_KEYS:
|
||||
priv->skip_null_keys = g_value_get_boolean (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_HEIGHT:
|
||||
priv->height = g_value_get_int(value);
|
||||
priv->fixed_height = (priv->height != 0);
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
priv->flags = g_value_get_uint(value);
|
||||
break;
|
||||
case PROP_ACTIVE:
|
||||
nmt_newt_listbox_set_active(listbox, g_value_get_int(value));
|
||||
break;
|
||||
case PROP_ACTIVE_KEY:
|
||||
nmt_newt_listbox_set_active_key(listbox, g_value_get_pointer(value));
|
||||
break;
|
||||
case PROP_SKIP_NULL_KEYS:
|
||||
priv->skip_null_keys = g_value_get_boolean(value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_listbox_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_listbox_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (object);
|
||||
NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_HEIGHT:
|
||||
g_value_set_int (value, priv->height);
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
g_value_set_uint (value, priv->flags);
|
||||
break;
|
||||
case PROP_ACTIVE:
|
||||
g_value_set_int (value, priv->active);
|
||||
break;
|
||||
case PROP_ACTIVE_KEY:
|
||||
g_value_set_pointer (value, priv->active_key);
|
||||
break;
|
||||
case PROP_SKIP_NULL_KEYS:
|
||||
g_value_set_boolean (value, priv->skip_null_keys);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_HEIGHT:
|
||||
g_value_set_int(value, priv->height);
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
g_value_set_uint(value, priv->flags);
|
||||
break;
|
||||
case PROP_ACTIVE:
|
||||
g_value_set_int(value, priv->active);
|
||||
break;
|
||||
case PROP_ACTIVE_KEY:
|
||||
g_value_set_pointer(value, priv->active_key);
|
||||
break;
|
||||
case PROP_SKIP_NULL_KEYS:
|
||||
g_value_set_boolean(value, priv->skip_null_keys);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_listbox_class_init (NmtNewtListboxClass *listbox_class)
|
||||
nmt_newt_listbox_class_init(NmtNewtListboxClass *listbox_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (listbox_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (listbox_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS (listbox_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(listbox_class);
|
||||
NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(listbox_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(listbox_class);
|
||||
|
||||
g_type_class_add_private (listbox_class, sizeof (NmtNewtListboxPrivate));
|
||||
g_type_class_add_private(listbox_class, sizeof(NmtNewtListboxPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_listbox_set_property;
|
||||
object_class->get_property = nmt_newt_listbox_get_property;
|
||||
object_class->finalize = nmt_newt_listbox_finalize;
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_listbox_set_property;
|
||||
object_class->get_property = nmt_newt_listbox_get_property;
|
||||
object_class->finalize = nmt_newt_listbox_finalize;
|
||||
|
||||
widget_class->size_request = nmt_newt_listbox_size_request;
|
||||
widget_class->size_allocate = nmt_newt_listbox_size_allocate;
|
||||
widget_class->activated = nmt_newt_listbox_activated;
|
||||
widget_class->size_request = nmt_newt_listbox_size_request;
|
||||
widget_class->size_allocate = nmt_newt_listbox_size_allocate;
|
||||
widget_class->activated = nmt_newt_listbox_activated;
|
||||
|
||||
component_class->build_component = nmt_newt_listbox_build_component;
|
||||
component_class->build_component = nmt_newt_listbox_build_component;
|
||||
|
||||
/* properties */
|
||||
/* properties */
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtListbox:height:
|
||||
*
|
||||
* The listbox's height, or -1 if it has no fixed height.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_HEIGHT,
|
||||
g_param_spec_int ("height", "", "",
|
||||
-1, 255, -1,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(object_class,
|
||||
PROP_HEIGHT,
|
||||
g_param_spec_int("height",
|
||||
"",
|
||||
"",
|
||||
-1,
|
||||
255,
|
||||
-1,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtListbox:flags:
|
||||
*
|
||||
* The listbox's #NmtNewtListboxFlags.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_FLAGS,
|
||||
g_param_spec_uint ("flags", "", "",
|
||||
0, 0xFFFF, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_FLAGS,
|
||||
g_param_spec_uint("flags",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
0xFFFF,
|
||||
0,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtListbox:active:
|
||||
*
|
||||
* The currently-selected row.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ACTIVE,
|
||||
g_param_spec_int ("active", "", "",
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(object_class,
|
||||
PROP_ACTIVE,
|
||||
g_param_spec_int("active",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
G_MAXINT,
|
||||
0,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtListbox:active-key:
|
||||
*
|
||||
* The key of the currently-selected row.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ACTIVE_KEY,
|
||||
g_param_spec_pointer ("active-key", "", "",
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_ACTIVE_KEY,
|
||||
g_param_spec_pointer("active-key", "", "", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtListbox:skip-null-keys:
|
||||
*
|
||||
* If %TRUE, rows with %NULL key values will be skipped over when
|
||||
* navigating the list with the arrow keys.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_SKIP_NULL_KEYS,
|
||||
g_param_spec_boolean ("skip-null-keys", "", "",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_SKIP_NULL_KEYS,
|
||||
g_param_spec_boolean("skip-null-keys",
|
||||
"",
|
||||
"",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,47 +8,43 @@
|
|||
|
||||
#include "nmt-newt-component.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_LISTBOX (nmt_newt_listbox_get_type ())
|
||||
#define NMT_NEWT_LISTBOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_LISTBOX, NmtNewtListbox))
|
||||
#define NMT_NEWT_LISTBOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_LISTBOX, NmtNewtListboxClass))
|
||||
#define NMT_IS_NEWT_LISTBOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_LISTBOX))
|
||||
#define NMT_IS_NEWT_LISTBOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_LISTBOX))
|
||||
#define NMT_NEWT_LISTBOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_LISTBOX, NmtNewtListboxClass))
|
||||
#define NMT_TYPE_NEWT_LISTBOX (nmt_newt_listbox_get_type())
|
||||
#define NMT_NEWT_LISTBOX(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_LISTBOX, NmtNewtListbox))
|
||||
#define NMT_NEWT_LISTBOX_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_LISTBOX, NmtNewtListboxClass))
|
||||
#define NMT_IS_NEWT_LISTBOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_LISTBOX))
|
||||
#define NMT_IS_NEWT_LISTBOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_LISTBOX))
|
||||
#define NMT_NEWT_LISTBOX_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_LISTBOX, NmtNewtListboxClass))
|
||||
|
||||
struct _NmtNewtListbox {
|
||||
NmtNewtComponent parent;
|
||||
|
||||
NmtNewtComponent parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtComponentClass parent;
|
||||
NmtNewtComponentClass parent;
|
||||
|
||||
} NmtNewtListboxClass;
|
||||
|
||||
GType nmt_newt_listbox_get_type (void);
|
||||
GType nmt_newt_listbox_get_type(void);
|
||||
|
||||
typedef enum {
|
||||
NMT_NEWT_LISTBOX_SCROLL = (1 << 0),
|
||||
NMT_NEWT_LISTBOX_BORDER = (1 << 1)
|
||||
NMT_NEWT_LISTBOX_SCROLL = (1 << 0),
|
||||
NMT_NEWT_LISTBOX_BORDER = (1 << 1)
|
||||
} NmtNewtListboxFlags;
|
||||
|
||||
NmtNewtWidget *nmt_newt_listbox_new (int height,
|
||||
NmtNewtListboxFlags flags);
|
||||
NmtNewtWidget *nmt_newt_listbox_new(int height, NmtNewtListboxFlags flags);
|
||||
|
||||
void nmt_newt_listbox_set_height (NmtNewtListbox *listbox,
|
||||
int height);
|
||||
void nmt_newt_listbox_set_height(NmtNewtListbox *listbox, int height);
|
||||
|
||||
void nmt_newt_listbox_append (NmtNewtListbox *listbox,
|
||||
const char *entry,
|
||||
gpointer key);
|
||||
void nmt_newt_listbox_clear (NmtNewtListbox *listbox);
|
||||
void nmt_newt_listbox_append(NmtNewtListbox *listbox, const char *entry, gpointer key);
|
||||
void nmt_newt_listbox_clear(NmtNewtListbox *listbox);
|
||||
|
||||
void nmt_newt_listbox_set_active (NmtNewtListbox *listbox,
|
||||
int active);
|
||||
void nmt_newt_listbox_set_active_key (NmtNewtListbox *listbox,
|
||||
gpointer active_key);
|
||||
void nmt_newt_listbox_set_active(NmtNewtListbox *listbox, int active);
|
||||
void nmt_newt_listbox_set_active_key(NmtNewtListbox *listbox, gpointer active_key);
|
||||
|
||||
int nmt_newt_listbox_get_active (NmtNewtListbox *listbox);
|
||||
gpointer nmt_newt_listbox_get_active_key (NmtNewtListbox *listbox);
|
||||
int nmt_newt_listbox_get_active(NmtNewtListbox *listbox);
|
||||
gpointer nmt_newt_listbox_get_active_key(NmtNewtListbox *listbox);
|
||||
|
||||
#endif /* NMT_NEWT_LISTBOX_H */
|
||||
|
|
|
|||
|
|
@ -21,21 +21,22 @@
|
|||
#include "nmt-newt-listbox.h"
|
||||
#include "nmt-newt-utils.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtNewtPopup, nmt_newt_popup, NMT_TYPE_NEWT_BUTTON)
|
||||
G_DEFINE_TYPE(NmtNewtPopup, nmt_newt_popup, NMT_TYPE_NEWT_BUTTON)
|
||||
|
||||
#define NMT_NEWT_POPUP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_POPUP, NmtNewtPopupPrivate))
|
||||
#define NMT_NEWT_POPUP_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_POPUP, NmtNewtPopupPrivate))
|
||||
|
||||
typedef struct {
|
||||
GArray *entries;
|
||||
int active;
|
||||
GArray *entries;
|
||||
int active;
|
||||
} NmtNewtPopupPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_ACTIVE,
|
||||
PROP_ACTIVE_ID,
|
||||
PROP_0,
|
||||
PROP_ACTIVE,
|
||||
PROP_ACTIVE_ID,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -56,93 +57,89 @@ enum {
|
|||
* Returns: a new #NmtNewtPopup
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_popup_new (NmtNewtPopupEntry *entries)
|
||||
nmt_newt_popup_new(NmtNewtPopupEntry *entries)
|
||||
{
|
||||
NmtNewtWidget *widget;
|
||||
NmtNewtPopupPrivate *priv;
|
||||
int i;
|
||||
NmtNewtWidget * widget;
|
||||
NmtNewtPopupPrivate *priv;
|
||||
int i;
|
||||
|
||||
widget = g_object_new (NMT_TYPE_NEWT_POPUP, NULL);
|
||||
priv = NMT_NEWT_POPUP_GET_PRIVATE (widget);
|
||||
widget = g_object_new(NMT_TYPE_NEWT_POPUP, NULL);
|
||||
priv = NMT_NEWT_POPUP_GET_PRIVATE(widget);
|
||||
|
||||
for (i = 0; entries[i].label; i++) {
|
||||
NmtNewtPopupEntry entry;
|
||||
for (i = 0; entries[i].label; i++) {
|
||||
NmtNewtPopupEntry entry;
|
||||
|
||||
entry.label = nmt_newt_locale_from_utf8 (_(entries[i].label));
|
||||
entry.id = g_strdup (entries[i].id);
|
||||
g_array_append_val (priv->entries, entry);
|
||||
}
|
||||
entry.label = nmt_newt_locale_from_utf8(_(entries[i].label));
|
||||
entry.id = g_strdup(entries[i].id);
|
||||
g_array_append_val(priv->entries, entry);
|
||||
}
|
||||
|
||||
return widget;
|
||||
return widget;
|
||||
}
|
||||
|
||||
static void
|
||||
popup_entry_clear_func (NmtNewtPopupEntry *entry)
|
||||
popup_entry_clear_func(NmtNewtPopupEntry *entry)
|
||||
{
|
||||
g_free (entry->label);
|
||||
g_free (entry->id);
|
||||
g_free(entry->label);
|
||||
g_free(entry->id);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_popup_init (NmtNewtPopup *popup)
|
||||
nmt_newt_popup_init(NmtNewtPopup *popup)
|
||||
{
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE (popup);
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE(popup);
|
||||
|
||||
priv->entries = g_array_sized_new (FALSE, FALSE, sizeof (NmtNewtPopupEntry), 10);
|
||||
g_array_set_clear_func (priv->entries, (GDestroyNotify) popup_entry_clear_func);
|
||||
priv->entries = g_array_sized_new(FALSE, FALSE, sizeof(NmtNewtPopupEntry), 10);
|
||||
g_array_set_clear_func(priv->entries, (GDestroyNotify) popup_entry_clear_func);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_popup_finalize (GObject *object)
|
||||
nmt_newt_popup_finalize(GObject *object)
|
||||
{
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE (object);
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE(object);
|
||||
|
||||
g_array_unref (priv->entries);
|
||||
g_array_unref(priv->entries);
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_popup_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS(nmt_newt_popup_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static newtComponent
|
||||
nmt_newt_popup_build_component (NmtNewtComponent *component,
|
||||
gboolean sensitive)
|
||||
nmt_newt_popup_build_component(NmtNewtComponent *component, gboolean sensitive)
|
||||
{
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE (component);
|
||||
NmtNewtPopupEntry *entries = (NmtNewtPopupEntry *)priv->entries->data;
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE(component);
|
||||
NmtNewtPopupEntry * entries = (NmtNewtPopupEntry *) priv->entries->data;
|
||||
|
||||
nmt_newt_button_set_label (NMT_NEWT_BUTTON (component),
|
||||
entries[priv->active].label);
|
||||
return NMT_NEWT_COMPONENT_CLASS (nmt_newt_popup_parent_class)->
|
||||
build_component (component, sensitive);
|
||||
nmt_newt_button_set_label(NMT_NEWT_BUTTON(component), entries[priv->active].label);
|
||||
return NMT_NEWT_COMPONENT_CLASS(nmt_newt_popup_parent_class)
|
||||
->build_component(component, sensitive);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_popup_activated (NmtNewtWidget *widget)
|
||||
nmt_newt_popup_activated(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE (widget);
|
||||
NmtNewtPopupEntry *entries = (NmtNewtPopupEntry *)priv->entries->data;
|
||||
NmtNewtForm *form;
|
||||
NmtNewtWidget *listbox, *ret;
|
||||
int button_x, button_y;
|
||||
int window_x, window_y;
|
||||
int list_w, list_h;
|
||||
int i, active;
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE(widget);
|
||||
NmtNewtPopupEntry * entries = (NmtNewtPopupEntry *) priv->entries->data;
|
||||
NmtNewtForm * form;
|
||||
NmtNewtWidget * listbox, *ret;
|
||||
int button_x, button_y;
|
||||
int window_x, window_y;
|
||||
int list_w, list_h;
|
||||
int i, active;
|
||||
|
||||
listbox = nmt_newt_listbox_new (priv->entries->len, 0);
|
||||
nmt_newt_widget_set_exit_on_activate (listbox, TRUE);
|
||||
for (i = 0; i < priv->entries->len; i++)
|
||||
nmt_newt_listbox_append (NMT_NEWT_LISTBOX (listbox), entries[i].label, NULL);
|
||||
nmt_newt_listbox_set_active (NMT_NEWT_LISTBOX (listbox), priv->active);
|
||||
nmt_newt_widget_set_padding (listbox, 1, 0, 1, 0);
|
||||
listbox = nmt_newt_listbox_new(priv->entries->len, 0);
|
||||
nmt_newt_widget_set_exit_on_activate(listbox, TRUE);
|
||||
for (i = 0; i < priv->entries->len; i++)
|
||||
nmt_newt_listbox_append(NMT_NEWT_LISTBOX(listbox), entries[i].label, NULL);
|
||||
nmt_newt_listbox_set_active(NMT_NEWT_LISTBOX(listbox), priv->active);
|
||||
nmt_newt_widget_set_padding(listbox, 1, 0, 1, 0);
|
||||
|
||||
nmt_newt_widget_size_request (listbox, &list_w, &list_h);
|
||||
nmt_newt_widget_size_request(listbox, &list_w, &list_h);
|
||||
|
||||
g_object_get (nmt_newt_widget_get_form (widget),
|
||||
"x", &window_x,
|
||||
"y", &window_y,
|
||||
NULL);
|
||||
newtComponentGetPosition (nmt_newt_component_get_component (NMT_NEWT_COMPONENT (widget)),
|
||||
&button_x, &button_y);
|
||||
/* (window_x + button_x) is the screen X coordinate of the newtComponent. A
|
||||
g_object_get(nmt_newt_widget_get_form(widget), "x", &window_x, "y", &window_y, NULL);
|
||||
newtComponentGetPosition(nmt_newt_component_get_component(NMT_NEWT_COMPONENT(widget)),
|
||||
&button_x,
|
||||
&button_y);
|
||||
/* (window_x + button_x) is the screen X coordinate of the newtComponent. A
|
||||
* newtButton labelled "Foo" is rendered as " <Foo>" (with a preceding
|
||||
* space), so the "F" is at (window_x + button_x + 2). We've added 1 column
|
||||
* of padding to the left of the listbox, so we need to position the popup
|
||||
|
|
@ -151,35 +148,41 @@ nmt_newt_popup_activated (NmtNewtWidget *widget)
|
|||
* coordinates of the top left of the window content, ignoring the border
|
||||
* graphics.)
|
||||
*/
|
||||
window_x += button_x + 1;
|
||||
window_y += button_y - priv->active;
|
||||
window_x += button_x + 1;
|
||||
window_y += button_y - priv->active;
|
||||
|
||||
form = g_object_new (NMT_TYPE_NEWT_FORM,
|
||||
"x", window_x,
|
||||
"y", window_y,
|
||||
"width", list_w,
|
||||
"height", list_h,
|
||||
"padding", 0,
|
||||
"escape-exits", TRUE,
|
||||
NULL);
|
||||
nmt_newt_form_set_content (form, listbox);
|
||||
form = g_object_new(NMT_TYPE_NEWT_FORM,
|
||||
"x",
|
||||
window_x,
|
||||
"y",
|
||||
window_y,
|
||||
"width",
|
||||
list_w,
|
||||
"height",
|
||||
list_h,
|
||||
"padding",
|
||||
0,
|
||||
"escape-exits",
|
||||
TRUE,
|
||||
NULL);
|
||||
nmt_newt_form_set_content(form, listbox);
|
||||
|
||||
ret = nmt_newt_form_run_sync (form);
|
||||
if (ret == listbox)
|
||||
active = nmt_newt_listbox_get_active (NMT_NEWT_LISTBOX (listbox));
|
||||
else
|
||||
active = priv->active;
|
||||
ret = nmt_newt_form_run_sync(form);
|
||||
if (ret == listbox)
|
||||
active = nmt_newt_listbox_get_active(NMT_NEWT_LISTBOX(listbox));
|
||||
else
|
||||
active = priv->active;
|
||||
|
||||
g_object_unref (form);
|
||||
g_object_unref(form);
|
||||
|
||||
if (active != priv->active) {
|
||||
priv->active = active;
|
||||
g_object_notify (G_OBJECT (widget), "active");
|
||||
g_object_notify (G_OBJECT (widget), "active-id");
|
||||
nmt_newt_widget_needs_rebuild (widget);
|
||||
}
|
||||
if (active != priv->active) {
|
||||
priv->active = active;
|
||||
g_object_notify(G_OBJECT(widget), "active");
|
||||
g_object_notify(G_OBJECT(widget), "active-id");
|
||||
nmt_newt_widget_needs_rebuild(widget);
|
||||
}
|
||||
|
||||
NMT_NEWT_WIDGET_CLASS (nmt_newt_popup_parent_class)->activated (widget);
|
||||
NMT_NEWT_WIDGET_CLASS(nmt_newt_popup_parent_class)->activated(widget);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -191,11 +194,11 @@ nmt_newt_popup_activated (NmtNewtWidget *widget)
|
|||
* Returns: the index of the active entry in @popup.
|
||||
*/
|
||||
int
|
||||
nmt_newt_popup_get_active (NmtNewtPopup *popup)
|
||||
nmt_newt_popup_get_active(NmtNewtPopup *popup)
|
||||
{
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE (popup);
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE(popup);
|
||||
|
||||
return priv->active;
|
||||
return priv->active;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -206,18 +209,17 @@ nmt_newt_popup_get_active (NmtNewtPopup *popup)
|
|||
* Sets the active entry in @popup.
|
||||
*/
|
||||
void
|
||||
nmt_newt_popup_set_active (NmtNewtPopup *popup,
|
||||
int active)
|
||||
nmt_newt_popup_set_active(NmtNewtPopup *popup, int active)
|
||||
{
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE (popup);
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE(popup);
|
||||
|
||||
active = CLAMP (active, 0, priv->entries->len - 1);
|
||||
active = CLAMP(active, 0, priv->entries->len - 1);
|
||||
|
||||
if (active != priv->active) {
|
||||
priv->active = active;
|
||||
g_object_notify (G_OBJECT (popup), "active");
|
||||
g_object_notify (G_OBJECT (popup), "active-id");
|
||||
}
|
||||
if (active != priv->active) {
|
||||
priv->active = active;
|
||||
g_object_notify(G_OBJECT(popup), "active");
|
||||
g_object_notify(G_OBJECT(popup), "active-id");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -229,12 +231,12 @@ nmt_newt_popup_set_active (NmtNewtPopup *popup,
|
|||
* Returns: the ID of the active entry in @popup.
|
||||
*/
|
||||
const char *
|
||||
nmt_newt_popup_get_active_id (NmtNewtPopup *popup)
|
||||
nmt_newt_popup_get_active_id(NmtNewtPopup *popup)
|
||||
{
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE (popup);
|
||||
NmtNewtPopupEntry *entries = (NmtNewtPopupEntry *)priv->entries->data;
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE(popup);
|
||||
NmtNewtPopupEntry * entries = (NmtNewtPopupEntry *) priv->entries->data;
|
||||
|
||||
return entries[priv->active].id;
|
||||
return entries[priv->active].id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -245,101 +247,95 @@ nmt_newt_popup_get_active_id (NmtNewtPopup *popup)
|
|||
* Sets the active entry in @popup.
|
||||
*/
|
||||
void
|
||||
nmt_newt_popup_set_active_id (NmtNewtPopup *popup,
|
||||
const char *active_id)
|
||||
nmt_newt_popup_set_active_id(NmtNewtPopup *popup, const char *active_id)
|
||||
{
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE (popup);
|
||||
NmtNewtPopupEntry *entries = (NmtNewtPopupEntry *)priv->entries->data;
|
||||
int i;
|
||||
NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE(popup);
|
||||
NmtNewtPopupEntry * entries = (NmtNewtPopupEntry *) priv->entries->data;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < priv->entries->len; i++) {
|
||||
if (!g_strcmp0 (active_id, entries[i].id)) {
|
||||
nmt_newt_popup_set_active (popup, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < priv->entries->len; i++) {
|
||||
if (!g_strcmp0(active_id, entries[i].id)) {
|
||||
nmt_newt_popup_set_active(popup, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_popup_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_popup_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtPopup *popup = NMT_NEWT_POPUP (object);
|
||||
NmtNewtPopup *popup = NMT_NEWT_POPUP(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_ACTIVE:
|
||||
nmt_newt_popup_set_active (popup, g_value_get_uint (value));
|
||||
break;
|
||||
case PROP_ACTIVE_ID:
|
||||
nmt_newt_popup_set_active_id (popup, g_value_get_string (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_ACTIVE:
|
||||
nmt_newt_popup_set_active(popup, g_value_get_uint(value));
|
||||
break;
|
||||
case PROP_ACTIVE_ID:
|
||||
nmt_newt_popup_set_active_id(popup, g_value_get_string(value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_popup_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_popup_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtPopup *popup = NMT_NEWT_POPUP (object);
|
||||
NmtNewtPopup *popup = NMT_NEWT_POPUP(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_ACTIVE:
|
||||
g_value_set_uint (value, nmt_newt_popup_get_active (popup));
|
||||
break;
|
||||
case PROP_ACTIVE_ID:
|
||||
g_value_set_string (value, nmt_newt_popup_get_active_id (popup));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_ACTIVE:
|
||||
g_value_set_uint(value, nmt_newt_popup_get_active(popup));
|
||||
break;
|
||||
case PROP_ACTIVE_ID:
|
||||
g_value_set_string(value, nmt_newt_popup_get_active_id(popup));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_popup_class_init (NmtNewtPopupClass *popup_class)
|
||||
nmt_newt_popup_class_init(NmtNewtPopupClass *popup_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (popup_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (popup_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS (popup_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(popup_class);
|
||||
NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(popup_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(popup_class);
|
||||
|
||||
g_type_class_add_private (popup_class, sizeof (NmtNewtPopupPrivate));
|
||||
g_type_class_add_private(popup_class, sizeof(NmtNewtPopupPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_popup_set_property;
|
||||
object_class->get_property = nmt_newt_popup_get_property;
|
||||
object_class->finalize = nmt_newt_popup_finalize;
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_popup_set_property;
|
||||
object_class->get_property = nmt_newt_popup_get_property;
|
||||
object_class->finalize = nmt_newt_popup_finalize;
|
||||
|
||||
widget_class->activated = nmt_newt_popup_activated;
|
||||
widget_class->activated = nmt_newt_popup_activated;
|
||||
|
||||
component_class->build_component = nmt_newt_popup_build_component;
|
||||
component_class->build_component = nmt_newt_popup_build_component;
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtPopup:active:
|
||||
*
|
||||
* The index of the currently-active entry.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ACTIVE,
|
||||
g_param_spec_uint ("active", "", "",
|
||||
0, G_MAXUINT, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(object_class,
|
||||
PROP_ACTIVE,
|
||||
g_param_spec_uint("active",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
G_MAXUINT,
|
||||
0,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtPopup:active-id:
|
||||
*
|
||||
* The textual ID of the currently-active entry.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ACTIVE_ID,
|
||||
g_param_spec_string ("active-id", "", "",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_ACTIVE_ID,
|
||||
g_param_spec_string("active-id", "", "", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,38 +8,37 @@
|
|||
|
||||
#include "nmt-newt-button.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_POPUP (nmt_newt_popup_get_type ())
|
||||
#define NMT_NEWT_POPUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_POPUP, NmtNewtPopup))
|
||||
#define NMT_NEWT_POPUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_POPUP, NmtNewtPopupClass))
|
||||
#define NMT_IS_NEWT_POPUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_POPUP))
|
||||
#define NMT_IS_NEWT_POPUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_POPUP))
|
||||
#define NMT_NEWT_POPUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_POPUP, NmtNewtPopupClass))
|
||||
#define NMT_TYPE_NEWT_POPUP (nmt_newt_popup_get_type())
|
||||
#define NMT_NEWT_POPUP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_POPUP, NmtNewtPopup))
|
||||
#define NMT_NEWT_POPUP_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_POPUP, NmtNewtPopupClass))
|
||||
#define NMT_IS_NEWT_POPUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_POPUP))
|
||||
#define NMT_IS_NEWT_POPUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_POPUP))
|
||||
#define NMT_NEWT_POPUP_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_POPUP, NmtNewtPopupClass))
|
||||
|
||||
struct _NmtNewtPopup {
|
||||
NmtNewtButton parent;
|
||||
|
||||
NmtNewtButton parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtButtonClass parent;
|
||||
NmtNewtButtonClass parent;
|
||||
|
||||
} NmtNewtPopupClass;
|
||||
|
||||
GType nmt_newt_popup_get_type (void);
|
||||
GType nmt_newt_popup_get_type(void);
|
||||
|
||||
typedef struct {
|
||||
char *label;
|
||||
char *id;
|
||||
char *label;
|
||||
char *id;
|
||||
} NmtNewtPopupEntry;
|
||||
|
||||
NmtNewtWidget *nmt_newt_popup_new (NmtNewtPopupEntry *entries);
|
||||
NmtNewtWidget *nmt_newt_popup_new(NmtNewtPopupEntry *entries);
|
||||
|
||||
int nmt_newt_popup_get_active (NmtNewtPopup *popup);
|
||||
void nmt_newt_popup_set_active (NmtNewtPopup *popup,
|
||||
int active);
|
||||
int nmt_newt_popup_get_active(NmtNewtPopup *popup);
|
||||
void nmt_newt_popup_set_active(NmtNewtPopup *popup, int active);
|
||||
|
||||
const char *nmt_newt_popup_get_active_id (NmtNewtPopup *popup);
|
||||
void nmt_newt_popup_set_active_id (NmtNewtPopup *popup,
|
||||
const char *active_id);
|
||||
const char *nmt_newt_popup_get_active_id(NmtNewtPopup *popup);
|
||||
void nmt_newt_popup_set_active_id(NmtNewtPopup *popup, const char *active_id);
|
||||
|
||||
#endif /* NMT_NEWT_POPUP_H */
|
||||
|
|
|
|||
|
|
@ -30,36 +30,37 @@
|
|||
#include "nmt-newt-label.h"
|
||||
#include "nmt-newt-utils.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtNewtSection, nmt_newt_section, NMT_TYPE_NEWT_CONTAINER)
|
||||
G_DEFINE_TYPE(NmtNewtSection, nmt_newt_section, NMT_TYPE_NEWT_CONTAINER)
|
||||
|
||||
#define NMT_NEWT_SECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_SECTION, NmtNewtSectionPrivate))
|
||||
#define NMT_NEWT_SECTION_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_SECTION, NmtNewtSectionPrivate))
|
||||
|
||||
typedef struct {
|
||||
NmtNewtWidget *header;
|
||||
int hheight_req, hwidth_req;
|
||||
NmtNewtWidget *header;
|
||||
int hheight_req, hwidth_req;
|
||||
|
||||
NmtNewtWidget *body;
|
||||
int bheight_req, bwidth_req;
|
||||
NmtNewtWidget *body;
|
||||
int bheight_req, bwidth_req;
|
||||
|
||||
gboolean show_border;
|
||||
NmtNewtWidget *border_grid;
|
||||
NmtNewtWidget *border_open_label;
|
||||
NmtNewtWidget *border_closed_label;
|
||||
NmtNewtWidget *border_end_label;
|
||||
GPtrArray *border_line_labels;
|
||||
gboolean show_border;
|
||||
NmtNewtWidget *border_grid;
|
||||
NmtNewtWidget *border_open_label;
|
||||
NmtNewtWidget *border_closed_label;
|
||||
NmtNewtWidget *border_end_label;
|
||||
GPtrArray * border_line_labels;
|
||||
|
||||
gboolean open;
|
||||
gboolean open;
|
||||
} NmtNewtSectionPrivate;
|
||||
|
||||
static char *closed_glyph, *open_glyph, *line_glyph, *end_glyph;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_0,
|
||||
|
||||
PROP_SHOW_BORDER,
|
||||
PROP_OPEN,
|
||||
PROP_SHOW_BORDER,
|
||||
PROP_OPEN,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -71,46 +72,44 @@ enum {
|
|||
* Returns: a new #NmtNewtSection
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_section_new (gboolean show_border)
|
||||
nmt_newt_section_new(gboolean show_border)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_NEWT_SECTION,
|
||||
"show-border", show_border,
|
||||
NULL);
|
||||
return g_object_new(NMT_TYPE_NEWT_SECTION, "show-border", show_border, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_section_init (NmtNewtSection *section)
|
||||
nmt_newt_section_init(NmtNewtSection *section)
|
||||
{
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (section);
|
||||
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_newt_section_parent_class);
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(section);
|
||||
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS(nmt_newt_section_parent_class);
|
||||
|
||||
priv->show_border = TRUE;
|
||||
priv->show_border = TRUE;
|
||||
|
||||
priv->border_grid = nmt_newt_grid_new ();
|
||||
parent_class->add (NMT_NEWT_CONTAINER (section), priv->border_grid);
|
||||
priv->border_grid = nmt_newt_grid_new();
|
||||
parent_class->add(NMT_NEWT_CONTAINER(section), priv->border_grid);
|
||||
|
||||
priv->border_open_label = nmt_newt_label_new (open_glyph);
|
||||
nmt_newt_widget_set_visible (priv->border_open_label, FALSE);
|
||||
nmt_newt_grid_add (NMT_NEWT_GRID (priv->border_grid), priv->border_open_label, 0, 0);
|
||||
priv->border_open_label = nmt_newt_label_new(open_glyph);
|
||||
nmt_newt_widget_set_visible(priv->border_open_label, FALSE);
|
||||
nmt_newt_grid_add(NMT_NEWT_GRID(priv->border_grid), priv->border_open_label, 0, 0);
|
||||
|
||||
priv->border_closed_label = nmt_newt_label_new (closed_glyph);
|
||||
nmt_newt_grid_add (NMT_NEWT_GRID (priv->border_grid), priv->border_closed_label, 0, 0);
|
||||
priv->border_closed_label = nmt_newt_label_new(closed_glyph);
|
||||
nmt_newt_grid_add(NMT_NEWT_GRID(priv->border_grid), priv->border_closed_label, 0, 0);
|
||||
|
||||
priv->border_end_label = nmt_newt_label_new (end_glyph);
|
||||
nmt_newt_widget_set_visible (priv->border_open_label, FALSE);
|
||||
nmt_newt_grid_add (NMT_NEWT_GRID (priv->border_grid), priv->border_end_label, 0, 1);
|
||||
priv->border_end_label = nmt_newt_label_new(end_glyph);
|
||||
nmt_newt_widget_set_visible(priv->border_open_label, FALSE);
|
||||
nmt_newt_grid_add(NMT_NEWT_GRID(priv->border_grid), priv->border_end_label, 0, 1);
|
||||
|
||||
priv->border_line_labels = g_ptr_array_new ();
|
||||
priv->border_line_labels = g_ptr_array_new();
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_section_finalize (GObject *object)
|
||||
nmt_newt_section_finalize(GObject *object)
|
||||
{
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (object);
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(object);
|
||||
|
||||
g_ptr_array_unref (priv->border_line_labels);
|
||||
g_ptr_array_unref(priv->border_line_labels);
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_section_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS(nmt_newt_section_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -121,17 +120,16 @@ nmt_newt_section_finalize (GObject *object)
|
|||
* Sets @section's header widget.
|
||||
*/
|
||||
void
|
||||
nmt_newt_section_set_header (NmtNewtSection *section,
|
||||
NmtNewtWidget *header)
|
||||
nmt_newt_section_set_header(NmtNewtSection *section, NmtNewtWidget *header)
|
||||
{
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (section);
|
||||
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_newt_section_parent_class);
|
||||
NmtNewtContainer *container = NMT_NEWT_CONTAINER (section);
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(section);
|
||||
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS(nmt_newt_section_parent_class);
|
||||
NmtNewtContainer * container = NMT_NEWT_CONTAINER(section);
|
||||
|
||||
if (priv->header)
|
||||
parent_class->remove (container, priv->header);
|
||||
priv->header = header;
|
||||
parent_class->add (container, header);
|
||||
if (priv->header)
|
||||
parent_class->remove(container, priv->header);
|
||||
priv->header = header;
|
||||
parent_class->add(container, header);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -143,11 +141,11 @@ nmt_newt_section_set_header (NmtNewtSection *section,
|
|||
* Returns: @section's header widget.
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_section_get_header (NmtNewtSection *section)
|
||||
nmt_newt_section_get_header(NmtNewtSection *section)
|
||||
{
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (section);
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(section);
|
||||
|
||||
return priv->header;
|
||||
return priv->header;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -158,17 +156,16 @@ nmt_newt_section_get_header (NmtNewtSection *section)
|
|||
* Sets @section's body widget.
|
||||
*/
|
||||
void
|
||||
nmt_newt_section_set_body (NmtNewtSection *section,
|
||||
NmtNewtWidget *body)
|
||||
nmt_newt_section_set_body(NmtNewtSection *section, NmtNewtWidget *body)
|
||||
{
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (section);
|
||||
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_newt_section_parent_class);
|
||||
NmtNewtContainer *container = NMT_NEWT_CONTAINER (section);
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(section);
|
||||
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS(nmt_newt_section_parent_class);
|
||||
NmtNewtContainer * container = NMT_NEWT_CONTAINER(section);
|
||||
|
||||
if (priv->body)
|
||||
parent_class->remove (container, priv->body);
|
||||
priv->body = body;
|
||||
parent_class->add (container, body);
|
||||
if (priv->body)
|
||||
parent_class->remove(container, priv->body);
|
||||
priv->body = body;
|
||||
parent_class->add(container, body);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -180,254 +177,246 @@ nmt_newt_section_set_body (NmtNewtSection *section,
|
|||
* Returns: @section's body widget.
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_section_get_body (NmtNewtSection *section)
|
||||
nmt_newt_section_get_body(NmtNewtSection *section)
|
||||
{
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (section);
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(section);
|
||||
|
||||
return priv->body;
|
||||
return priv->body;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_section_remove (NmtNewtContainer *container,
|
||||
NmtNewtWidget *widget)
|
||||
nmt_newt_section_remove(NmtNewtContainer *container, NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtSection *section = NMT_NEWT_SECTION (container);
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (section);
|
||||
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_newt_section_parent_class);
|
||||
NmtNewtSection * section = NMT_NEWT_SECTION(container);
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(section);
|
||||
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS(nmt_newt_section_parent_class);
|
||||
|
||||
if (widget == priv->header)
|
||||
priv->header = NULL;
|
||||
else if (widget == priv->body)
|
||||
priv->body = NULL;
|
||||
else if (widget == priv->border_grid)
|
||||
priv->border_grid = NULL;
|
||||
if (widget == priv->header)
|
||||
priv->header = NULL;
|
||||
else if (widget == priv->body)
|
||||
priv->body = NULL;
|
||||
else if (widget == priv->border_grid)
|
||||
priv->border_grid = NULL;
|
||||
|
||||
parent_class->remove (container, widget);
|
||||
parent_class->remove(container, widget);
|
||||
}
|
||||
|
||||
static newtComponent *
|
||||
nmt_newt_section_get_components (NmtNewtWidget *widget)
|
||||
nmt_newt_section_get_components(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (widget);
|
||||
newtComponent *child_cos;
|
||||
GPtrArray *cos;
|
||||
int i;
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(widget);
|
||||
newtComponent * child_cos;
|
||||
GPtrArray * cos;
|
||||
int i;
|
||||
|
||||
g_return_val_if_fail (priv->header != NULL && priv->body != NULL, NULL);
|
||||
g_return_val_if_fail(priv->header != NULL && priv->body != NULL, NULL);
|
||||
|
||||
cos = g_ptr_array_new ();
|
||||
cos = g_ptr_array_new();
|
||||
|
||||
if (priv->show_border) {
|
||||
child_cos = nmt_newt_widget_get_components (priv->border_grid);
|
||||
for (i = 0; child_cos[i]; i++)
|
||||
g_ptr_array_add (cos, child_cos[i]);
|
||||
g_free (child_cos);
|
||||
}
|
||||
if (priv->show_border) {
|
||||
child_cos = nmt_newt_widget_get_components(priv->border_grid);
|
||||
for (i = 0; child_cos[i]; i++)
|
||||
g_ptr_array_add(cos, child_cos[i]);
|
||||
g_free(child_cos);
|
||||
}
|
||||
|
||||
child_cos = nmt_newt_widget_get_components (priv->header);
|
||||
for (i = 0; child_cos[i]; i++)
|
||||
g_ptr_array_add (cos, child_cos[i]);
|
||||
g_free (child_cos);
|
||||
child_cos = nmt_newt_widget_get_components(priv->header);
|
||||
for (i = 0; child_cos[i]; i++)
|
||||
g_ptr_array_add(cos, child_cos[i]);
|
||||
g_free(child_cos);
|
||||
|
||||
if (priv->open) {
|
||||
child_cos = nmt_newt_widget_get_components (priv->body);
|
||||
for (i = 0; child_cos[i]; i++)
|
||||
g_ptr_array_add (cos, child_cos[i]);
|
||||
g_free (child_cos);
|
||||
}
|
||||
if (priv->open) {
|
||||
child_cos = nmt_newt_widget_get_components(priv->body);
|
||||
for (i = 0; child_cos[i]; i++)
|
||||
g_ptr_array_add(cos, child_cos[i]);
|
||||
g_free(child_cos);
|
||||
}
|
||||
|
||||
g_ptr_array_add (cos, NULL);
|
||||
return (newtComponent *) g_ptr_array_free (cos, FALSE);
|
||||
g_ptr_array_add(cos, NULL);
|
||||
return (newtComponent *) g_ptr_array_free(cos, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_section_size_request (NmtNewtWidget *widget,
|
||||
int *width,
|
||||
int *height)
|
||||
nmt_newt_section_size_request(NmtNewtWidget *widget, int *width, int *height)
|
||||
{
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (widget);
|
||||
int w_ignore, h_ignore;
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(widget);
|
||||
int w_ignore, h_ignore;
|
||||
|
||||
g_return_if_fail (priv->header != NULL && priv->body != NULL);
|
||||
g_return_if_fail(priv->header != NULL && priv->body != NULL);
|
||||
|
||||
if (priv->show_border)
|
||||
nmt_newt_widget_size_request (priv->border_grid, &w_ignore, &h_ignore);
|
||||
nmt_newt_widget_size_request (priv->header, &priv->hwidth_req, &priv->hheight_req);
|
||||
nmt_newt_widget_size_request (priv->body, &priv->bwidth_req, &priv->bheight_req);
|
||||
if (priv->show_border)
|
||||
nmt_newt_widget_size_request(priv->border_grid, &w_ignore, &h_ignore);
|
||||
nmt_newt_widget_size_request(priv->header, &priv->hwidth_req, &priv->hheight_req);
|
||||
nmt_newt_widget_size_request(priv->body, &priv->bwidth_req, &priv->bheight_req);
|
||||
|
||||
*width = MAX (priv->hwidth_req, priv->bwidth_req) + 2;
|
||||
if (priv->open)
|
||||
*height = priv->hheight_req + priv->bheight_req + (priv->show_border ? 1 : 0);
|
||||
else
|
||||
*height = priv->hheight_req;
|
||||
*width = MAX(priv->hwidth_req, priv->bwidth_req) + 2;
|
||||
if (priv->open)
|
||||
*height = priv->hheight_req + priv->bheight_req + (priv->show_border ? 1 : 0);
|
||||
else
|
||||
*height = priv->hheight_req;
|
||||
}
|
||||
|
||||
static void
|
||||
adjust_border_for_allocation (NmtNewtSectionPrivate *priv,
|
||||
int height)
|
||||
adjust_border_for_allocation(NmtNewtSectionPrivate *priv, int height)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
/* We have to use a series of one-line labels rather than a multi-line
|
||||
/* We have to use a series of one-line labels rather than a multi-line
|
||||
* textbox, because newt will hide any component that's partially offscreen,
|
||||
* but we want the on-screen portion of the border to show even if part of
|
||||
* it is offscreen.
|
||||
*/
|
||||
|
||||
if (height == 1) {
|
||||
nmt_newt_widget_set_visible (priv->border_closed_label, TRUE);
|
||||
nmt_newt_widget_set_visible (priv->border_open_label, FALSE);
|
||||
for (i = 0; i < priv->border_line_labels->len; i++)
|
||||
nmt_newt_widget_set_visible (priv->border_line_labels->pdata[i], FALSE);
|
||||
nmt_newt_widget_set_visible (priv->border_end_label, FALSE);
|
||||
} else {
|
||||
nmt_newt_widget_set_visible (priv->border_closed_label, FALSE);
|
||||
nmt_newt_widget_set_visible (priv->border_open_label, TRUE);
|
||||
for (i = 0; i < height - 2; i++) {
|
||||
if (i >= priv->border_line_labels->len) {
|
||||
NmtNewtWidget *label;
|
||||
if (height == 1) {
|
||||
nmt_newt_widget_set_visible(priv->border_closed_label, TRUE);
|
||||
nmt_newt_widget_set_visible(priv->border_open_label, FALSE);
|
||||
for (i = 0; i < priv->border_line_labels->len; i++)
|
||||
nmt_newt_widget_set_visible(priv->border_line_labels->pdata[i], FALSE);
|
||||
nmt_newt_widget_set_visible(priv->border_end_label, FALSE);
|
||||
} else {
|
||||
nmt_newt_widget_set_visible(priv->border_closed_label, FALSE);
|
||||
nmt_newt_widget_set_visible(priv->border_open_label, TRUE);
|
||||
for (i = 0; i < height - 2; i++) {
|
||||
if (i >= priv->border_line_labels->len) {
|
||||
NmtNewtWidget *label;
|
||||
|
||||
label = nmt_newt_label_new (line_glyph);
|
||||
g_ptr_array_add (priv->border_line_labels, label);
|
||||
nmt_newt_grid_add (NMT_NEWT_GRID (priv->border_grid), label, 0, i + 1);
|
||||
} else
|
||||
nmt_newt_widget_set_visible (priv->border_line_labels->pdata[i], TRUE);
|
||||
}
|
||||
nmt_newt_widget_set_visible (priv->border_end_label, TRUE);
|
||||
nmt_newt_grid_move (NMT_NEWT_GRID (priv->border_grid), priv->border_end_label, 0, height - 1);
|
||||
}
|
||||
label = nmt_newt_label_new(line_glyph);
|
||||
g_ptr_array_add(priv->border_line_labels, label);
|
||||
nmt_newt_grid_add(NMT_NEWT_GRID(priv->border_grid), label, 0, i + 1);
|
||||
} else
|
||||
nmt_newt_widget_set_visible(priv->border_line_labels->pdata[i], TRUE);
|
||||
}
|
||||
nmt_newt_widget_set_visible(priv->border_end_label, TRUE);
|
||||
nmt_newt_grid_move(NMT_NEWT_GRID(priv->border_grid), priv->border_end_label, 0, height - 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_section_size_allocate (NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height)
|
||||
nmt_newt_section_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height)
|
||||
{
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (widget);
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(widget);
|
||||
|
||||
if (priv->show_border) {
|
||||
int w_ignore, h_ignore;
|
||||
if (priv->show_border) {
|
||||
int w_ignore, h_ignore;
|
||||
|
||||
adjust_border_for_allocation (priv, height);
|
||||
nmt_newt_widget_size_request (priv->border_grid, &w_ignore, &h_ignore);
|
||||
nmt_newt_widget_size_allocate (priv->border_grid, x, y, 1, height);
|
||||
nmt_newt_widget_size_allocate (priv->header, x + 2, y, width, priv->hheight_req);
|
||||
} else
|
||||
nmt_newt_widget_size_allocate (priv->header, x, y, width, priv->hheight_req);
|
||||
adjust_border_for_allocation(priv, height);
|
||||
nmt_newt_widget_size_request(priv->border_grid, &w_ignore, &h_ignore);
|
||||
nmt_newt_widget_size_allocate(priv->border_grid, x, y, 1, height);
|
||||
nmt_newt_widget_size_allocate(priv->header, x + 2, y, width, priv->hheight_req);
|
||||
} else
|
||||
nmt_newt_widget_size_allocate(priv->header, x, y, width, priv->hheight_req);
|
||||
|
||||
if (priv->open) {
|
||||
nmt_newt_widget_size_allocate (priv->body, x + 2, y + priv->hheight_req,
|
||||
width, height - priv->hheight_req);
|
||||
}
|
||||
if (priv->open) {
|
||||
nmt_newt_widget_size_allocate(priv->body,
|
||||
x + 2,
|
||||
y + priv->hheight_req,
|
||||
width,
|
||||
height - priv->hheight_req);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_section_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_section_set_property(GObject * object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (object);
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_SHOW_BORDER:
|
||||
priv->show_border = g_value_get_boolean (value);
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (object));
|
||||
break;
|
||||
case PROP_OPEN:
|
||||
priv->open = g_value_get_boolean (value);
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (object));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_SHOW_BORDER:
|
||||
priv->show_border = g_value_get_boolean(value);
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(object));
|
||||
break;
|
||||
case PROP_OPEN:
|
||||
priv->open = g_value_get_boolean(value);
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(object));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_section_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_section_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (object);
|
||||
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_SHOW_BORDER:
|
||||
g_value_set_boolean (value, priv->show_border);
|
||||
break;
|
||||
case PROP_OPEN:
|
||||
g_value_set_boolean (value, priv->open);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_SHOW_BORDER:
|
||||
g_value_set_boolean(value, priv->show_border);
|
||||
break;
|
||||
case PROP_OPEN:
|
||||
g_value_set_boolean(value, priv->open);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_section_class_init (NmtNewtSectionClass *section_class)
|
||||
nmt_newt_section_class_init(NmtNewtSectionClass *section_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (section_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (section_class);
|
||||
NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS (section_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(section_class);
|
||||
NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(section_class);
|
||||
NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS(section_class);
|
||||
|
||||
g_type_class_add_private (section_class, sizeof (NmtNewtSectionPrivate));
|
||||
g_type_class_add_private(section_class, sizeof(NmtNewtSectionPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_section_set_property;
|
||||
object_class->get_property = nmt_newt_section_get_property;
|
||||
object_class->finalize = nmt_newt_section_finalize;
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_section_set_property;
|
||||
object_class->get_property = nmt_newt_section_get_property;
|
||||
object_class->finalize = nmt_newt_section_finalize;
|
||||
|
||||
widget_class->get_components = nmt_newt_section_get_components;
|
||||
widget_class->size_request = nmt_newt_section_size_request;
|
||||
widget_class->size_allocate = nmt_newt_section_size_allocate;
|
||||
widget_class->get_components = nmt_newt_section_get_components;
|
||||
widget_class->size_request = nmt_newt_section_size_request;
|
||||
widget_class->size_allocate = nmt_newt_section_size_allocate;
|
||||
|
||||
container_class->remove = nmt_newt_section_remove;
|
||||
container_class->remove = nmt_newt_section_remove;
|
||||
|
||||
/* properties */
|
||||
/* properties */
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtSection:show-border:
|
||||
*
|
||||
* %TRUE if the section should show a border along the left side.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_SHOW_BORDER,
|
||||
g_param_spec_boolean ("show-border", "", "",
|
||||
TRUE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_SHOW_BORDER,
|
||||
g_param_spec_boolean("show-border",
|
||||
"",
|
||||
"",
|
||||
TRUE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtSection:open:
|
||||
*
|
||||
* %TRUE if the section is open (ie, its body is visible), %FALSE
|
||||
* if not.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_OPEN,
|
||||
g_param_spec_boolean ("open", "", "",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_OPEN,
|
||||
g_param_spec_boolean("open", "", "", FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/* globals */
|
||||
closed_glyph = nmt_newt_locale_from_utf8 ("\342\225\220"); /* ═ */
|
||||
open_glyph = nmt_newt_locale_from_utf8 ("\342\225\244"); /* ╤ */
|
||||
line_glyph = nmt_newt_locale_from_utf8 ("\342\224\202"); /* │ */
|
||||
end_glyph = nmt_newt_locale_from_utf8 ("\342\224\224"); /* └ */
|
||||
if (!*closed_glyph || !*open_glyph || !*line_glyph || !*end_glyph) {
|
||||
g_free (closed_glyph);
|
||||
g_free (open_glyph);
|
||||
g_free (line_glyph);
|
||||
g_free (end_glyph);
|
||||
/* globals */
|
||||
closed_glyph = nmt_newt_locale_from_utf8("\342\225\220"); /* ═ */
|
||||
open_glyph = nmt_newt_locale_from_utf8("\342\225\244"); /* ╤ */
|
||||
line_glyph = nmt_newt_locale_from_utf8("\342\224\202"); /* │ */
|
||||
end_glyph = nmt_newt_locale_from_utf8("\342\224\224"); /* └ */
|
||||
if (!*closed_glyph || !*open_glyph || !*line_glyph || !*end_glyph) {
|
||||
g_free(closed_glyph);
|
||||
g_free(open_glyph);
|
||||
g_free(line_glyph);
|
||||
g_free(end_glyph);
|
||||
|
||||
closed_glyph = g_strdup ("-");
|
||||
open_glyph = g_strdup ("+");
|
||||
line_glyph = g_strdup ("|");
|
||||
end_glyph = g_strdup ("\\");
|
||||
}
|
||||
closed_glyph = g_strdup("-");
|
||||
open_glyph = g_strdup("+");
|
||||
line_glyph = g_strdup("|");
|
||||
end_glyph = g_strdup("\\");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,33 +8,33 @@
|
|||
|
||||
#include "nmt-newt-container.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_SECTION (nmt_newt_section_get_type ())
|
||||
#define NMT_NEWT_SECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_SECTION, NmtNewtSection))
|
||||
#define NMT_NEWT_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_SECTION, NmtNewtSectionClass))
|
||||
#define NMT_IS_NEWT_SECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_SECTION))
|
||||
#define NMT_IS_NEWT_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_SECTION))
|
||||
#define NMT_NEWT_SECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_SECTION, NmtNewtSectionClass))
|
||||
#define NMT_TYPE_NEWT_SECTION (nmt_newt_section_get_type())
|
||||
#define NMT_NEWT_SECTION(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_SECTION, NmtNewtSection))
|
||||
#define NMT_NEWT_SECTION_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_SECTION, NmtNewtSectionClass))
|
||||
#define NMT_IS_NEWT_SECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_SECTION))
|
||||
#define NMT_IS_NEWT_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_SECTION))
|
||||
#define NMT_NEWT_SECTION_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_SECTION, NmtNewtSectionClass))
|
||||
|
||||
struct _NmtNewtSection {
|
||||
NmtNewtContainer parent;
|
||||
|
||||
NmtNewtContainer parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtContainerClass parent;
|
||||
NmtNewtContainerClass parent;
|
||||
|
||||
} NmtNewtSectionClass;
|
||||
|
||||
GType nmt_newt_section_get_type (void);
|
||||
GType nmt_newt_section_get_type(void);
|
||||
|
||||
NmtNewtWidget *nmt_newt_section_new (gboolean show_border);
|
||||
NmtNewtWidget *nmt_newt_section_new(gboolean show_border);
|
||||
|
||||
void nmt_newt_section_set_header (NmtNewtSection *section,
|
||||
NmtNewtWidget *header);
|
||||
NmtNewtWidget *nmt_newt_section_get_header (NmtNewtSection *section);
|
||||
void nmt_newt_section_set_header(NmtNewtSection *section, NmtNewtWidget *header);
|
||||
NmtNewtWidget *nmt_newt_section_get_header(NmtNewtSection *section);
|
||||
|
||||
void nmt_newt_section_set_body (NmtNewtSection *section,
|
||||
NmtNewtWidget *body);
|
||||
NmtNewtWidget *nmt_newt_section_get_body (NmtNewtSection *section);
|
||||
void nmt_newt_section_set_body(NmtNewtSection *section, NmtNewtWidget *body);
|
||||
NmtNewtWidget *nmt_newt_section_get_body(NmtNewtSection *section);
|
||||
|
||||
#endif /* NMT_NEWT_SECTION_H */
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "nmt-newt-separator.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtNewtSeparator, nmt_newt_separator, NMT_TYPE_NEWT_COMPONENT)
|
||||
G_DEFINE_TYPE(NmtNewtSeparator, nmt_newt_separator, NMT_TYPE_NEWT_COMPONENT)
|
||||
|
||||
/**
|
||||
* nmt_newt_separator_new:
|
||||
|
|
@ -26,28 +26,26 @@ G_DEFINE_TYPE (NmtNewtSeparator, nmt_newt_separator, NMT_TYPE_NEWT_COMPONENT)
|
|||
* Returns: a new #NmtNewtSeparator
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_separator_new (void)
|
||||
nmt_newt_separator_new(void)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_NEWT_SEPARATOR, NULL);
|
||||
return g_object_new(NMT_TYPE_NEWT_SEPARATOR, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_separator_init (NmtNewtSeparator *separator)
|
||||
{
|
||||
}
|
||||
nmt_newt_separator_init(NmtNewtSeparator *separator)
|
||||
{}
|
||||
|
||||
static newtComponent
|
||||
nmt_newt_separator_build_component (NmtNewtComponent *component,
|
||||
gboolean sensitive)
|
||||
nmt_newt_separator_build_component(NmtNewtComponent *component, gboolean sensitive)
|
||||
{
|
||||
return newtLabel (-1, -1, " ");
|
||||
return newtLabel(-1, -1, " ");
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_separator_class_init (NmtNewtSeparatorClass *separator_class)
|
||||
nmt_newt_separator_class_init(NmtNewtSeparatorClass *separator_class)
|
||||
{
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS (separator_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(separator_class);
|
||||
|
||||
/* virtual methods */
|
||||
component_class->build_component = nmt_newt_separator_build_component;
|
||||
/* virtual methods */
|
||||
component_class->build_component = nmt_newt_separator_build_component;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,25 +8,28 @@
|
|||
|
||||
#include "nmt-newt-component.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_SEPARATOR (nmt_newt_separator_get_type ())
|
||||
#define NMT_NEWT_SEPARATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_SEPARATOR, NmtNewtSeparator))
|
||||
#define NMT_NEWT_SEPARATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_SEPARATOR, NmtNewtSeparatorClass))
|
||||
#define NMT_IS_NEWT_SEPARATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_SEPARATOR))
|
||||
#define NMT_IS_NEWT_SEPARATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_SEPARATOR))
|
||||
#define NMT_NEWT_SEPARATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_SEPARATOR, NmtNewtSeparatorClass))
|
||||
#define NMT_TYPE_NEWT_SEPARATOR (nmt_newt_separator_get_type())
|
||||
#define NMT_NEWT_SEPARATOR(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_SEPARATOR, NmtNewtSeparator))
|
||||
#define NMT_NEWT_SEPARATOR_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_SEPARATOR, NmtNewtSeparatorClass))
|
||||
#define NMT_IS_NEWT_SEPARATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_SEPARATOR))
|
||||
#define NMT_IS_NEWT_SEPARATOR_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_SEPARATOR))
|
||||
#define NMT_NEWT_SEPARATOR_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_SEPARATOR, NmtNewtSeparatorClass))
|
||||
|
||||
struct _NmtNewtSeparator {
|
||||
NmtNewtComponent parent;
|
||||
|
||||
NmtNewtComponent parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtComponentClass parent;
|
||||
NmtNewtComponentClass parent;
|
||||
|
||||
} NmtNewtSeparatorClass;
|
||||
|
||||
GType nmt_newt_separator_get_type (void);
|
||||
GType nmt_newt_separator_get_type(void);
|
||||
|
||||
NmtNewtWidget *nmt_newt_separator_new (void);
|
||||
NmtNewtWidget *nmt_newt_separator_new(void);
|
||||
|
||||
#endif /* NMT_NEWT_SEPARATOR_H */
|
||||
|
|
|
|||
|
|
@ -20,23 +20,24 @@
|
|||
|
||||
#include "nmt-newt-stack.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtNewtStack, nmt_newt_stack, NMT_TYPE_NEWT_CONTAINER)
|
||||
G_DEFINE_TYPE(NmtNewtStack, nmt_newt_stack, NMT_TYPE_NEWT_CONTAINER)
|
||||
|
||||
#define NMT_NEWT_STACK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_STACK, NmtNewtStackPrivate))
|
||||
#define NMT_NEWT_STACK_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_STACK, NmtNewtStackPrivate))
|
||||
|
||||
typedef struct {
|
||||
GPtrArray *children;
|
||||
GPtrArray *ids;
|
||||
GPtrArray *children;
|
||||
GPtrArray *ids;
|
||||
|
||||
guint active;
|
||||
guint active;
|
||||
} NmtNewtStackPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_ACTIVE,
|
||||
PROP_ACTIVE_ID,
|
||||
PROP_0,
|
||||
PROP_ACTIVE,
|
||||
PROP_ACTIVE_ID,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -47,82 +48,76 @@ enum {
|
|||
* Returns: a new #NmtNewtStack
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_stack_new (void)
|
||||
nmt_newt_stack_new(void)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_NEWT_STACK, NULL);
|
||||
return g_object_new(NMT_TYPE_NEWT_STACK, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_stack_init (NmtNewtStack *stack)
|
||||
nmt_newt_stack_init(NmtNewtStack *stack)
|
||||
{
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE (stack);
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE(stack);
|
||||
|
||||
priv->children = g_ptr_array_new ();
|
||||
priv->ids = g_ptr_array_new_with_free_func (g_free);
|
||||
priv->children = g_ptr_array_new();
|
||||
priv->ids = g_ptr_array_new_with_free_func(g_free);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_stack_finalize (GObject *object)
|
||||
nmt_newt_stack_finalize(GObject *object)
|
||||
{
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE (object);
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE(object);
|
||||
|
||||
g_ptr_array_unref (priv->children);
|
||||
g_ptr_array_unref (priv->ids);
|
||||
g_ptr_array_unref(priv->children);
|
||||
g_ptr_array_unref(priv->ids);
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_stack_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS(nmt_newt_stack_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static newtComponent *
|
||||
nmt_newt_stack_get_components (NmtNewtWidget *widget)
|
||||
nmt_newt_stack_get_components(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE (widget);
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE(widget);
|
||||
|
||||
if (priv->active > priv->children->len)
|
||||
return NULL;
|
||||
if (priv->active > priv->children->len)
|
||||
return NULL;
|
||||
|
||||
return nmt_newt_widget_get_components (priv->children->pdata[priv->active]);
|
||||
return nmt_newt_widget_get_components(priv->children->pdata[priv->active]);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_stack_size_request (NmtNewtWidget *widget,
|
||||
int *width,
|
||||
int *height)
|
||||
nmt_newt_stack_size_request(NmtNewtWidget *widget, int *width, int *height)
|
||||
{
|
||||
NmtNewtStack *stack = NMT_NEWT_STACK (widget);
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE (stack);
|
||||
int i, child_width, child_height;
|
||||
NmtNewtStack * stack = NMT_NEWT_STACK(widget);
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE(stack);
|
||||
int i, child_width, child_height;
|
||||
|
||||
if (priv->active > priv->children->len) {
|
||||
*width = *height = 0;
|
||||
return;
|
||||
}
|
||||
if (priv->active > priv->children->len) {
|
||||
*width = *height = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* We size-request all pages so that embedded NmtPageGrids will
|
||||
/* We size-request all pages so that embedded NmtPageGrids will
|
||||
* participate in their size-grouping (so that switching pages
|
||||
* won't result in the column widths changing).
|
||||
*/
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
nmt_newt_widget_size_request (priv->children->pdata[i], &child_width, &child_height);
|
||||
if (i == priv->active) {
|
||||
*width = child_width;
|
||||
*height = child_height;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
nmt_newt_widget_size_request(priv->children->pdata[i], &child_width, &child_height);
|
||||
if (i == priv->active) {
|
||||
*width = child_width;
|
||||
*height = child_height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_stack_size_allocate (NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height)
|
||||
nmt_newt_stack_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height)
|
||||
{
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE (widget);
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE(widget);
|
||||
|
||||
if (priv->active > priv->children->len)
|
||||
return;
|
||||
if (priv->active > priv->children->len)
|
||||
return;
|
||||
|
||||
nmt_newt_widget_size_allocate (priv->children->pdata[priv->active], x, y, width, height);
|
||||
nmt_newt_widget_size_allocate(priv->children->pdata[priv->active], x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -134,50 +129,46 @@ nmt_newt_stack_size_allocate (NmtNewtWidget *widget,
|
|||
* Adds @widget to @stack with the given @id.
|
||||
*/
|
||||
void
|
||||
nmt_newt_stack_add (NmtNewtStack *stack,
|
||||
const char *id,
|
||||
NmtNewtWidget *widget)
|
||||
nmt_newt_stack_add(NmtNewtStack *stack, const char *id, NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE (stack);
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE(stack);
|
||||
|
||||
g_ptr_array_add (priv->children, widget);
|
||||
g_ptr_array_add (priv->ids, g_strdup (id));
|
||||
g_ptr_array_add(priv->children, widget);
|
||||
g_ptr_array_add(priv->ids, g_strdup(id));
|
||||
|
||||
NMT_NEWT_CONTAINER_CLASS (nmt_newt_stack_parent_class)->add (NMT_NEWT_CONTAINER (stack), widget);
|
||||
NMT_NEWT_CONTAINER_CLASS(nmt_newt_stack_parent_class)->add(NMT_NEWT_CONTAINER(stack), widget);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_stack_remove (NmtNewtContainer *container,
|
||||
NmtNewtWidget *widget)
|
||||
nmt_newt_stack_remove(NmtNewtContainer *container, NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtStack *stack = NMT_NEWT_STACK (container);
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE (stack);
|
||||
int i;
|
||||
NmtNewtStack * stack = NMT_NEWT_STACK(container);
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE(stack);
|
||||
int i;
|
||||
|
||||
NMT_NEWT_CONTAINER_CLASS (nmt_newt_stack_parent_class)->remove (container, widget);
|
||||
NMT_NEWT_CONTAINER_CLASS(nmt_newt_stack_parent_class)->remove(container, widget);
|
||||
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
if (priv->children->pdata[i] == widget) {
|
||||
g_ptr_array_remove_index (priv->children, i);
|
||||
g_ptr_array_remove_index (priv->ids, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < priv->children->len; i++) {
|
||||
if (priv->children->pdata[i] == widget) {
|
||||
g_ptr_array_remove_index(priv->children, i);
|
||||
g_ptr_array_remove_index(priv->ids, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_stack_child_validity_changed (NmtNewtContainer *container,
|
||||
NmtNewtWidget *widget)
|
||||
nmt_newt_stack_child_validity_changed(NmtNewtContainer *container, NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE (container);
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE(container);
|
||||
|
||||
if (priv->active > priv->children->len)
|
||||
return;
|
||||
if (priv->active > priv->children->len)
|
||||
return;
|
||||
|
||||
if (priv->children->pdata[priv->active] == (gpointer) widget) {
|
||||
NMT_NEWT_CONTAINER_CLASS (nmt_newt_stack_parent_class)->
|
||||
child_validity_changed (container, widget);
|
||||
}
|
||||
if (priv->children->pdata[priv->active] == (gpointer) widget) {
|
||||
NMT_NEWT_CONTAINER_CLASS(nmt_newt_stack_parent_class)
|
||||
->child_validity_changed(container, widget);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -188,18 +179,17 @@ nmt_newt_stack_child_validity_changed (NmtNewtContainer *container,
|
|||
* Sets the active page on @stack to @active.
|
||||
*/
|
||||
void
|
||||
nmt_newt_stack_set_active (NmtNewtStack *stack,
|
||||
guint active)
|
||||
nmt_newt_stack_set_active(NmtNewtStack *stack, guint active)
|
||||
{
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE (stack);
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE(stack);
|
||||
|
||||
if (priv->active == active)
|
||||
return;
|
||||
if (priv->active == active)
|
||||
return;
|
||||
|
||||
priv->active = active;
|
||||
g_object_notify (G_OBJECT (stack), "active");
|
||||
g_object_notify (G_OBJECT (stack), "active-id");
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (stack));
|
||||
priv->active = active;
|
||||
g_object_notify(G_OBJECT(stack), "active");
|
||||
g_object_notify(G_OBJECT(stack), "active-id");
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(stack));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -211,11 +201,11 @@ nmt_newt_stack_set_active (NmtNewtStack *stack,
|
|||
* Returns: the index of the active page on @stack
|
||||
*/
|
||||
guint
|
||||
nmt_newt_stack_get_active (NmtNewtStack *stack)
|
||||
nmt_newt_stack_get_active(NmtNewtStack *stack)
|
||||
{
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE (stack);
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE(stack);
|
||||
|
||||
return priv->active;
|
||||
return priv->active;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -226,24 +216,23 @@ nmt_newt_stack_get_active (NmtNewtStack *stack)
|
|||
* Sets the active page on @stack to @active_id.
|
||||
*/
|
||||
void
|
||||
nmt_newt_stack_set_active_id (NmtNewtStack *stack,
|
||||
const char *id)
|
||||
nmt_newt_stack_set_active_id(NmtNewtStack *stack, const char *id)
|
||||
{
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE (stack);
|
||||
int i;
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE(stack);
|
||||
int i;
|
||||
|
||||
if (!g_strcmp0 (priv->ids->pdata[priv->active], id))
|
||||
return;
|
||||
if (!g_strcmp0(priv->ids->pdata[priv->active], id))
|
||||
return;
|
||||
|
||||
for (i = 0; i < priv->ids->len; i++) {
|
||||
if (!g_strcmp0 (priv->ids->pdata[i], id)) {
|
||||
priv->active = i;
|
||||
g_object_notify (G_OBJECT (stack), "active");
|
||||
g_object_notify (G_OBJECT (stack), "active-id");
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (stack));
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < priv->ids->len; i++) {
|
||||
if (!g_strcmp0(priv->ids->pdata[i], id)) {
|
||||
priv->active = i;
|
||||
g_object_notify(G_OBJECT(stack), "active");
|
||||
g_object_notify(G_OBJECT(stack), "active-id");
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(stack));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -255,99 +244,94 @@ nmt_newt_stack_set_active_id (NmtNewtStack *stack,
|
|||
* Returns: the ID of the active page on @stack
|
||||
*/
|
||||
const char *
|
||||
nmt_newt_stack_get_active_id (NmtNewtStack *stack)
|
||||
nmt_newt_stack_get_active_id(NmtNewtStack *stack)
|
||||
{
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE (stack);
|
||||
NmtNewtStackPrivate *priv = NMT_NEWT_STACK_GET_PRIVATE(stack);
|
||||
|
||||
if (priv->active > priv->children->len)
|
||||
return NULL;
|
||||
if (priv->active > priv->children->len)
|
||||
return NULL;
|
||||
|
||||
return priv->ids->pdata[priv->active];
|
||||
return priv->ids->pdata[priv->active];
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_stack_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_stack_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtStack *stack = NMT_NEWT_STACK (object);
|
||||
NmtNewtStack *stack = NMT_NEWT_STACK(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_ACTIVE:
|
||||
nmt_newt_stack_set_active (stack, g_value_get_uint (value));
|
||||
break;
|
||||
case PROP_ACTIVE_ID:
|
||||
nmt_newt_stack_set_active_id (stack, g_value_get_string (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_ACTIVE:
|
||||
nmt_newt_stack_set_active(stack, g_value_get_uint(value));
|
||||
break;
|
||||
case PROP_ACTIVE_ID:
|
||||
nmt_newt_stack_set_active_id(stack, g_value_get_string(value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_stack_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_stack_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtStack *stack = NMT_NEWT_STACK (object);
|
||||
NmtNewtStack *stack = NMT_NEWT_STACK(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_ACTIVE:
|
||||
g_value_set_uint (value, nmt_newt_stack_get_active (stack));
|
||||
break;
|
||||
case PROP_ACTIVE_ID:
|
||||
g_value_set_string (value, nmt_newt_stack_get_active_id (stack));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_ACTIVE:
|
||||
g_value_set_uint(value, nmt_newt_stack_get_active(stack));
|
||||
break;
|
||||
case PROP_ACTIVE_ID:
|
||||
g_value_set_string(value, nmt_newt_stack_get_active_id(stack));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_stack_class_init (NmtNewtStackClass *stack_class)
|
||||
nmt_newt_stack_class_init(NmtNewtStackClass *stack_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (stack_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (stack_class);
|
||||
NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS (stack_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(stack_class);
|
||||
NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(stack_class);
|
||||
NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS(stack_class);
|
||||
|
||||
g_type_class_add_private (stack_class, sizeof (NmtNewtStackPrivate));
|
||||
g_type_class_add_private(stack_class, sizeof(NmtNewtStackPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_stack_set_property;
|
||||
object_class->get_property = nmt_newt_stack_get_property;
|
||||
object_class->finalize = nmt_newt_stack_finalize;
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_stack_set_property;
|
||||
object_class->get_property = nmt_newt_stack_get_property;
|
||||
object_class->finalize = nmt_newt_stack_finalize;
|
||||
|
||||
widget_class->get_components = nmt_newt_stack_get_components;
|
||||
widget_class->size_request = nmt_newt_stack_size_request;
|
||||
widget_class->size_allocate = nmt_newt_stack_size_allocate;
|
||||
widget_class->get_components = nmt_newt_stack_get_components;
|
||||
widget_class->size_request = nmt_newt_stack_size_request;
|
||||
widget_class->size_allocate = nmt_newt_stack_size_allocate;
|
||||
|
||||
container_class->remove = nmt_newt_stack_remove;
|
||||
container_class->child_validity_changed = nmt_newt_stack_child_validity_changed;
|
||||
container_class->remove = nmt_newt_stack_remove;
|
||||
container_class->child_validity_changed = nmt_newt_stack_child_validity_changed;
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtStack:active:
|
||||
*
|
||||
* The index of the active page
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ACTIVE,
|
||||
g_param_spec_uint ("active", "", "",
|
||||
0, G_MAXUINT, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(object_class,
|
||||
PROP_ACTIVE,
|
||||
g_param_spec_uint("active",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
G_MAXUINT,
|
||||
0,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtStack:active-id:
|
||||
*
|
||||
* The ID of the active page
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ACTIVE_ID,
|
||||
g_param_spec_string ("active-id", "", "",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_ACTIVE_ID,
|
||||
g_param_spec_string("active-id", "", "", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,37 +8,34 @@
|
|||
|
||||
#include "nmt-newt-container.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_STACK (nmt_newt_stack_get_type ())
|
||||
#define NMT_NEWT_STACK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_STACK, NmtNewtStack))
|
||||
#define NMT_NEWT_STACK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_STACK, NmtNewtStackClass))
|
||||
#define NMT_IS_NEWT_STACK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_STACK))
|
||||
#define NMT_IS_NEWT_STACK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_STACK))
|
||||
#define NMT_NEWT_STACK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_STACK, NmtNewtStackClass))
|
||||
#define NMT_TYPE_NEWT_STACK (nmt_newt_stack_get_type())
|
||||
#define NMT_NEWT_STACK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_STACK, NmtNewtStack))
|
||||
#define NMT_NEWT_STACK_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_STACK, NmtNewtStackClass))
|
||||
#define NMT_IS_NEWT_STACK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_STACK))
|
||||
#define NMT_IS_NEWT_STACK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_STACK))
|
||||
#define NMT_NEWT_STACK_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_STACK, NmtNewtStackClass))
|
||||
|
||||
struct _NmtNewtStack {
|
||||
NmtNewtContainer parent;
|
||||
|
||||
NmtNewtContainer parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtContainerClass parent;
|
||||
NmtNewtContainerClass parent;
|
||||
|
||||
} NmtNewtStackClass;
|
||||
|
||||
GType nmt_newt_stack_get_type (void);
|
||||
GType nmt_newt_stack_get_type(void);
|
||||
|
||||
NmtNewtWidget *nmt_newt_stack_new (void);
|
||||
NmtNewtWidget *nmt_newt_stack_new(void);
|
||||
|
||||
void nmt_newt_stack_add (NmtNewtStack *stack,
|
||||
const char *id,
|
||||
NmtNewtWidget *widget);
|
||||
void nmt_newt_stack_add(NmtNewtStack *stack, const char *id, NmtNewtWidget *widget);
|
||||
|
||||
void nmt_newt_stack_set_active (NmtNewtStack *stack,
|
||||
guint active);
|
||||
guint nmt_newt_stack_get_active (NmtNewtStack *stack);
|
||||
void nmt_newt_stack_set_active(NmtNewtStack *stack, guint active);
|
||||
guint nmt_newt_stack_get_active(NmtNewtStack *stack);
|
||||
|
||||
void nmt_newt_stack_set_active_id (NmtNewtStack *stack,
|
||||
const char *id);
|
||||
const char * nmt_newt_stack_get_active_id (NmtNewtStack *stack);
|
||||
void nmt_newt_stack_set_active_id(NmtNewtStack *stack, const char *id);
|
||||
const char *nmt_newt_stack_get_active_id(NmtNewtStack *stack);
|
||||
|
||||
#endif /* NMT_NEWT_STACK_H */
|
||||
|
|
|
|||
|
|
@ -17,25 +17,26 @@
|
|||
|
||||
#include "nmt-newt-utils.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtNewtTextbox, nmt_newt_textbox, NMT_TYPE_NEWT_COMPONENT)
|
||||
G_DEFINE_TYPE(NmtNewtTextbox, nmt_newt_textbox, NMT_TYPE_NEWT_COMPONENT)
|
||||
|
||||
#define NMT_NEWT_TEXTBOX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_TEXTBOX, NmtNewtTextboxPrivate))
|
||||
#define NMT_NEWT_TEXTBOX_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_TEXTBOX, NmtNewtTextboxPrivate))
|
||||
|
||||
typedef struct {
|
||||
int wrap_width;
|
||||
NmtNewtTextboxFlags flags;
|
||||
int wrap_width;
|
||||
NmtNewtTextboxFlags flags;
|
||||
|
||||
char *text;
|
||||
int width, height;
|
||||
char *text;
|
||||
int width, height;
|
||||
} NmtNewtTextboxPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_TEXT,
|
||||
PROP_FLAGS,
|
||||
PROP_WRAP_WIDTH,
|
||||
PROP_0,
|
||||
PROP_TEXT,
|
||||
PROP_FLAGS,
|
||||
PROP_WRAP_WIDTH,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -58,13 +59,9 @@ enum {
|
|||
* Returns: a new #NmtNewtTextbox
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_textbox_new (NmtNewtTextboxFlags flags,
|
||||
int wrap_width)
|
||||
nmt_newt_textbox_new(NmtNewtTextboxFlags flags, int wrap_width)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_NEWT_TEXTBOX,
|
||||
"flags", flags,
|
||||
"wrap-width", wrap_width,
|
||||
NULL);
|
||||
return g_object_new(NMT_TYPE_NEWT_TEXTBOX, "flags", flags, "wrap-width", wrap_width, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -76,33 +73,32 @@ nmt_newt_textbox_new (NmtNewtTextboxFlags flags,
|
|||
* Returns: @textbox's text
|
||||
*/
|
||||
void
|
||||
nmt_newt_textbox_set_text (NmtNewtTextbox *textbox,
|
||||
const char *text)
|
||||
nmt_newt_textbox_set_text(NmtNewtTextbox *textbox, const char *text)
|
||||
{
|
||||
NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE (textbox);
|
||||
char **lines;
|
||||
int i, width;
|
||||
NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE(textbox);
|
||||
char ** lines;
|
||||
int i, width;
|
||||
|
||||
if (!text)
|
||||
text = "";
|
||||
if (!strcmp (priv->text, text))
|
||||
return;
|
||||
if (!text)
|
||||
text = "";
|
||||
if (!strcmp(priv->text, text))
|
||||
return;
|
||||
|
||||
g_free (priv->text);
|
||||
priv->text = g_strdup (text);
|
||||
g_free(priv->text);
|
||||
priv->text = g_strdup(text);
|
||||
|
||||
priv->width = priv->height = 0;
|
||||
lines = g_strsplit (priv->text, "\n", -1);
|
||||
for (i = 0; lines[i]; i++) {
|
||||
width = nmt_newt_text_width (lines[i]);
|
||||
if (width > priv->width)
|
||||
priv->width = width;
|
||||
}
|
||||
g_free (lines);
|
||||
priv->height = MIN (i, 1);
|
||||
priv->width = priv->height = 0;
|
||||
lines = g_strsplit(priv->text, "\n", -1);
|
||||
for (i = 0; lines[i]; i++) {
|
||||
width = nmt_newt_text_width(lines[i]);
|
||||
if (width > priv->width)
|
||||
priv->width = width;
|
||||
}
|
||||
g_free(lines);
|
||||
priv->height = MIN(i, 1);
|
||||
|
||||
g_object_notify (G_OBJECT (textbox), "text");
|
||||
nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (textbox));
|
||||
g_object_notify(G_OBJECT(textbox), "text");
|
||||
nmt_newt_widget_needs_rebuild(NMT_NEWT_WIDGET(textbox));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -114,168 +110,170 @@ nmt_newt_textbox_set_text (NmtNewtTextbox *textbox,
|
|||
* Returns: @textbox's text
|
||||
*/
|
||||
const char *
|
||||
nmt_newt_textbox_get_text (NmtNewtTextbox *textbox)
|
||||
nmt_newt_textbox_get_text(NmtNewtTextbox *textbox)
|
||||
{
|
||||
NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE (textbox);
|
||||
NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE(textbox);
|
||||
|
||||
return priv->text;
|
||||
return priv->text;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_textbox_init (NmtNewtTextbox *textbox)
|
||||
nmt_newt_textbox_init(NmtNewtTextbox *textbox)
|
||||
{
|
||||
NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE (textbox);
|
||||
NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE(textbox);
|
||||
|
||||
priv->text = g_strdup ("");
|
||||
priv->text = g_strdup("");
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_textbox_finalize (GObject *object)
|
||||
nmt_newt_textbox_finalize(GObject *object)
|
||||
{
|
||||
NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE (object);
|
||||
NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE(object);
|
||||
|
||||
g_free (priv->text);
|
||||
g_free(priv->text);
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_textbox_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS(nmt_newt_textbox_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static guint
|
||||
convert_flags (NmtNewtTextboxFlags flags)
|
||||
convert_flags(NmtNewtTextboxFlags flags)
|
||||
{
|
||||
guint newt_flags = 0;
|
||||
guint newt_flags = 0;
|
||||
|
||||
if (flags & NMT_NEWT_TEXTBOX_SCROLLABLE)
|
||||
newt_flags |= NEWT_FLAG_SCROLL;
|
||||
if (flags & NMT_NEWT_TEXTBOX_SCROLLABLE)
|
||||
newt_flags |= NEWT_FLAG_SCROLL;
|
||||
|
||||
return newt_flags;
|
||||
return newt_flags;
|
||||
}
|
||||
|
||||
static newtComponent
|
||||
nmt_newt_textbox_build_component (NmtNewtComponent *component,
|
||||
gboolean sensitive)
|
||||
nmt_newt_textbox_build_component(NmtNewtComponent *component, gboolean sensitive)
|
||||
{
|
||||
NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE (component);
|
||||
newtComponent co;
|
||||
const char *text;
|
||||
char *text_lc;
|
||||
NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE(component);
|
||||
newtComponent co;
|
||||
const char * text;
|
||||
char * text_lc;
|
||||
|
||||
text = priv->text;
|
||||
if (!*text)
|
||||
text = "\n";
|
||||
text = priv->text;
|
||||
if (!*text)
|
||||
text = "\n";
|
||||
|
||||
text_lc = nmt_newt_locale_from_utf8 (text);
|
||||
if (priv->wrap_width > 0) {
|
||||
co = newtTextboxReflowed (-1, -1, text_lc, priv->wrap_width, 0, 0, 0);
|
||||
} else {
|
||||
co = newtTextbox (-1, -1, priv->width, priv->height, convert_flags (priv->flags));
|
||||
newtTextboxSetText (co, text_lc);
|
||||
}
|
||||
g_free (text_lc);
|
||||
text_lc = nmt_newt_locale_from_utf8(text);
|
||||
if (priv->wrap_width > 0) {
|
||||
co = newtTextboxReflowed(-1, -1, text_lc, priv->wrap_width, 0, 0, 0);
|
||||
} else {
|
||||
co = newtTextbox(-1, -1, priv->width, priv->height, convert_flags(priv->flags));
|
||||
newtTextboxSetText(co, text_lc);
|
||||
}
|
||||
g_free(text_lc);
|
||||
|
||||
if (priv->flags & NMT_NEWT_TEXTBOX_SET_BACKGROUND)
|
||||
newtTextboxSetColors (co, NMT_NEWT_COLORSET_TEXTBOX_WITH_BACKGROUND, NEWT_COLORSET_ACTTEXTBOX);
|
||||
if (priv->flags & NMT_NEWT_TEXTBOX_SET_BACKGROUND)
|
||||
newtTextboxSetColors(co,
|
||||
NMT_NEWT_COLORSET_TEXTBOX_WITH_BACKGROUND,
|
||||
NEWT_COLORSET_ACTTEXTBOX);
|
||||
|
||||
return co;
|
||||
return co;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_textbox_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_textbox_set_property(GObject * object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
NmtNewtTextbox *textbox = NMT_NEWT_TEXTBOX (object);
|
||||
NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE (textbox);
|
||||
NmtNewtTextbox * textbox = NMT_NEWT_TEXTBOX(object);
|
||||
NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE(textbox);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_TEXT:
|
||||
nmt_newt_textbox_set_text (textbox, g_value_get_string (value));
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
priv->flags = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_WRAP_WIDTH:
|
||||
priv->wrap_width = g_value_get_int (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_TEXT:
|
||||
nmt_newt_textbox_set_text(textbox, g_value_get_string(value));
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
priv->flags = g_value_get_uint(value);
|
||||
break;
|
||||
case PROP_WRAP_WIDTH:
|
||||
priv->wrap_width = g_value_get_int(value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_textbox_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_textbox_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE (object);
|
||||
NmtNewtTextboxPrivate *priv = NMT_NEWT_TEXTBOX_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_TEXT:
|
||||
g_value_set_string (value, priv->text);
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
g_value_set_uint (value, priv->flags);
|
||||
break;
|
||||
case PROP_WRAP_WIDTH:
|
||||
g_value_set_int (value, priv->wrap_width);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_TEXT:
|
||||
g_value_set_string(value, priv->text);
|
||||
break;
|
||||
case PROP_FLAGS:
|
||||
g_value_set_uint(value, priv->flags);
|
||||
break;
|
||||
case PROP_WRAP_WIDTH:
|
||||
g_value_set_int(value, priv->wrap_width);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_textbox_class_init (NmtNewtTextboxClass *textbox_class)
|
||||
nmt_newt_textbox_class_init(NmtNewtTextboxClass *textbox_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (textbox_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS (textbox_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(textbox_class);
|
||||
NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS(textbox_class);
|
||||
|
||||
g_type_class_add_private (textbox_class, sizeof (NmtNewtTextboxPrivate));
|
||||
g_type_class_add_private(textbox_class, sizeof(NmtNewtTextboxPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_textbox_set_property;
|
||||
object_class->get_property = nmt_newt_textbox_get_property;
|
||||
object_class->finalize = nmt_newt_textbox_finalize;
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_textbox_set_property;
|
||||
object_class->get_property = nmt_newt_textbox_get_property;
|
||||
object_class->finalize = nmt_newt_textbox_finalize;
|
||||
|
||||
component_class->build_component = nmt_newt_textbox_build_component;
|
||||
component_class->build_component = nmt_newt_textbox_build_component;
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtTextbox:text:
|
||||
*
|
||||
* The textbox's text
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_TEXT,
|
||||
g_param_spec_string ("text", "", "",
|
||||
"",
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_TEXT,
|
||||
g_param_spec_string("text", "", "", "", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtTextbox:flags:
|
||||
*
|
||||
* The textbox's flags
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_FLAGS,
|
||||
g_param_spec_uint ("flags", "", "",
|
||||
0, G_MAXUINT, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_FLAGS,
|
||||
g_param_spec_uint("flags",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
G_MAXUINT,
|
||||
0,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtTextbox:wrap-width:
|
||||
*
|
||||
* The width in characters at which the textbox's text
|
||||
* will wrap, or 0 if it does not wrap.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_WRAP_WIDTH,
|
||||
g_param_spec_int ("wrap-width", "", "",
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_WRAP_WIDTH,
|
||||
g_param_spec_int("wrap-width",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
G_MAXINT,
|
||||
0,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,35 +8,35 @@
|
|||
|
||||
#include "nmt-newt-component.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_TEXTBOX (nmt_newt_textbox_get_type ())
|
||||
#define NMT_NEWT_TEXTBOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_TEXTBOX, NmtNewtTextbox))
|
||||
#define NMT_NEWT_TEXTBOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_TEXTBOX, NmtNewtTextboxClass))
|
||||
#define NMT_IS_NEWT_TEXTBOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_TEXTBOX))
|
||||
#define NMT_IS_NEWT_TEXTBOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_TEXTBOX))
|
||||
#define NMT_NEWT_TEXTBOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_TEXTBOX, NmtNewtTextboxClass))
|
||||
#define NMT_TYPE_NEWT_TEXTBOX (nmt_newt_textbox_get_type())
|
||||
#define NMT_NEWT_TEXTBOX(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_TEXTBOX, NmtNewtTextbox))
|
||||
#define NMT_NEWT_TEXTBOX_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_TEXTBOX, NmtNewtTextboxClass))
|
||||
#define NMT_IS_NEWT_TEXTBOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_TEXTBOX))
|
||||
#define NMT_IS_NEWT_TEXTBOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_TEXTBOX))
|
||||
#define NMT_NEWT_TEXTBOX_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_TEXTBOX, NmtNewtTextboxClass))
|
||||
|
||||
struct _NmtNewtTextbox {
|
||||
NmtNewtComponent parent;
|
||||
|
||||
NmtNewtComponent parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtComponentClass parent;
|
||||
NmtNewtComponentClass parent;
|
||||
|
||||
} NmtNewtTextboxClass;
|
||||
|
||||
GType nmt_newt_textbox_get_type (void);
|
||||
GType nmt_newt_textbox_get_type(void);
|
||||
|
||||
typedef enum {
|
||||
NMT_NEWT_TEXTBOX_SCROLLABLE = (1 << 0),
|
||||
NMT_NEWT_TEXTBOX_SET_BACKGROUND = (1 << 1)
|
||||
NMT_NEWT_TEXTBOX_SCROLLABLE = (1 << 0),
|
||||
NMT_NEWT_TEXTBOX_SET_BACKGROUND = (1 << 1)
|
||||
} NmtNewtTextboxFlags;
|
||||
|
||||
NmtNewtWidget *nmt_newt_textbox_new (NmtNewtTextboxFlags flags,
|
||||
int wrap_width);
|
||||
NmtNewtWidget *nmt_newt_textbox_new(NmtNewtTextboxFlags flags, int wrap_width);
|
||||
|
||||
void nmt_newt_textbox_set_text (NmtNewtTextbox *textbox,
|
||||
const char *text);
|
||||
const char *nmt_newt_textbox_get_text (NmtNewtTextbox *textbox);
|
||||
void nmt_newt_textbox_set_text(NmtNewtTextbox *textbox, const char *text);
|
||||
const char *nmt_newt_textbox_get_text(NmtNewtTextbox *textbox);
|
||||
|
||||
#endif /* NMT_NEWT_TEXTBOX_H */
|
||||
|
|
|
|||
|
|
@ -14,22 +14,23 @@
|
|||
|
||||
#include "nmt-newt-toggle-button.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtNewtToggleButton, nmt_newt_toggle_button, NMT_TYPE_NEWT_BUTTON)
|
||||
G_DEFINE_TYPE(NmtNewtToggleButton, nmt_newt_toggle_button, NMT_TYPE_NEWT_BUTTON)
|
||||
|
||||
#define NMT_NEWT_TOGGLE_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_TOGGLE_BUTTON, NmtNewtToggleButtonPrivate))
|
||||
#define NMT_NEWT_TOGGLE_BUTTON_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_TOGGLE_BUTTON, NmtNewtToggleButtonPrivate))
|
||||
|
||||
typedef struct {
|
||||
char *on_label, *off_label;
|
||||
gboolean active;
|
||||
char * on_label, *off_label;
|
||||
gboolean active;
|
||||
} NmtNewtToggleButtonPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_ON_LABEL,
|
||||
PROP_OFF_LABEL,
|
||||
PROP_ACTIVE,
|
||||
PROP_0,
|
||||
PROP_ON_LABEL,
|
||||
PROP_OFF_LABEL,
|
||||
PROP_ACTIVE,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -42,13 +43,14 @@ enum {
|
|||
* Returns: a new #NmtNewtToggleButton
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_toggle_button_new (const char *on_label,
|
||||
const char *off_label)
|
||||
nmt_newt_toggle_button_new(const char *on_label, const char *off_label)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_NEWT_TOGGLE_BUTTON,
|
||||
"on-label", on_label,
|
||||
"off-label", off_label,
|
||||
NULL);
|
||||
return g_object_new(NMT_TYPE_NEWT_TOGGLE_BUTTON,
|
||||
"on-label",
|
||||
on_label,
|
||||
"off-label",
|
||||
off_label,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -60,11 +62,11 @@ nmt_newt_toggle_button_new (const char *on_label,
|
|||
* Returns: whether @button is currently "on" (%TRUE) or "off" (%FALSE)
|
||||
*/
|
||||
gboolean
|
||||
nmt_newt_toggle_button_get_active (NmtNewtToggleButton *button)
|
||||
nmt_newt_toggle_button_get_active(NmtNewtToggleButton *button)
|
||||
{
|
||||
NmtNewtToggleButtonPrivate *priv = NMT_NEWT_TOGGLE_BUTTON_GET_PRIVATE (button);
|
||||
NmtNewtToggleButtonPrivate *priv = NMT_NEWT_TOGGLE_BUTTON_GET_PRIVATE(button);
|
||||
|
||||
return priv->active;
|
||||
return priv->active;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -75,150 +77,138 @@ nmt_newt_toggle_button_get_active (NmtNewtToggleButton *button)
|
|||
* Sets whether @button is currently "on" or "off"
|
||||
*/
|
||||
void
|
||||
nmt_newt_toggle_button_set_active (NmtNewtToggleButton *button,
|
||||
gboolean active)
|
||||
nmt_newt_toggle_button_set_active(NmtNewtToggleButton *button, gboolean active)
|
||||
{
|
||||
NmtNewtToggleButtonPrivate *priv = NMT_NEWT_TOGGLE_BUTTON_GET_PRIVATE (button);
|
||||
NmtNewtToggleButtonPrivate *priv = NMT_NEWT_TOGGLE_BUTTON_GET_PRIVATE(button);
|
||||
|
||||
if (priv->active == active)
|
||||
return;
|
||||
if (priv->active == active)
|
||||
return;
|
||||
|
||||
priv->active = active;
|
||||
g_object_set (G_OBJECT (button),
|
||||
"label", active ? priv->on_label : priv->off_label,
|
||||
NULL);
|
||||
g_object_notify (G_OBJECT (button), "active");
|
||||
priv->active = active;
|
||||
g_object_set(G_OBJECT(button), "label", active ? priv->on_label : priv->off_label, NULL);
|
||||
g_object_notify(G_OBJECT(button), "active");
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_toggle_button_init (NmtNewtToggleButton *button)
|
||||
nmt_newt_toggle_button_init(NmtNewtToggleButton *button)
|
||||
{}
|
||||
|
||||
static void
|
||||
nmt_newt_toggle_button_finalize(GObject *object)
|
||||
{
|
||||
NmtNewtToggleButtonPrivate *priv = NMT_NEWT_TOGGLE_BUTTON_GET_PRIVATE(object);
|
||||
|
||||
g_free(priv->on_label);
|
||||
g_free(priv->off_label);
|
||||
|
||||
G_OBJECT_CLASS(nmt_newt_toggle_button_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_toggle_button_finalize (GObject *object)
|
||||
nmt_newt_toggle_button_activated(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtToggleButtonPrivate *priv = NMT_NEWT_TOGGLE_BUTTON_GET_PRIVATE (object);
|
||||
NmtNewtToggleButton *button = NMT_NEWT_TOGGLE_BUTTON(widget);
|
||||
|
||||
g_free (priv->on_label);
|
||||
g_free (priv->off_label);
|
||||
nmt_newt_toggle_button_set_active(button, !nmt_newt_toggle_button_get_active(button));
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_toggle_button_parent_class)->finalize (object);
|
||||
NMT_NEWT_WIDGET_CLASS(nmt_newt_toggle_button_parent_class)->activated(widget);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_toggle_button_activated (NmtNewtWidget *widget)
|
||||
nmt_newt_toggle_button_set_property(GObject * object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
NmtNewtToggleButton *button = NMT_NEWT_TOGGLE_BUTTON (widget);
|
||||
NmtNewtToggleButtonPrivate *priv = NMT_NEWT_TOGGLE_BUTTON_GET_PRIVATE(object);
|
||||
|
||||
nmt_newt_toggle_button_set_active (button, !nmt_newt_toggle_button_get_active (button));
|
||||
|
||||
NMT_NEWT_WIDGET_CLASS (nmt_newt_toggle_button_parent_class)->activated (widget);
|
||||
switch (prop_id) {
|
||||
case PROP_ON_LABEL:
|
||||
g_free(priv->on_label);
|
||||
priv->on_label = g_value_dup_string(value);
|
||||
if (priv->active)
|
||||
g_object_set(object, "label", priv->on_label, NULL);
|
||||
break;
|
||||
case PROP_OFF_LABEL:
|
||||
g_free(priv->off_label);
|
||||
priv->off_label = g_value_dup_string(value);
|
||||
if (!priv->active)
|
||||
g_object_set(object, "label", priv->off_label, NULL);
|
||||
break;
|
||||
case PROP_ACTIVE:
|
||||
priv->active = g_value_get_boolean(value);
|
||||
g_object_set(object, "label", priv->active ? priv->on_label : priv->off_label, NULL);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_toggle_button_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_toggle_button_get_property(GObject * object,
|
||||
guint prop_id,
|
||||
GValue * value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtToggleButtonPrivate *priv = NMT_NEWT_TOGGLE_BUTTON_GET_PRIVATE (object);
|
||||
NmtNewtToggleButtonPrivate *priv = NMT_NEWT_TOGGLE_BUTTON_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_ON_LABEL:
|
||||
g_free (priv->on_label);
|
||||
priv->on_label = g_value_dup_string (value);
|
||||
if (priv->active)
|
||||
g_object_set (object, "label", priv->on_label, NULL);
|
||||
break;
|
||||
case PROP_OFF_LABEL:
|
||||
g_free (priv->off_label);
|
||||
priv->off_label = g_value_dup_string (value);
|
||||
if (!priv->active)
|
||||
g_object_set (object, "label", priv->off_label, NULL);
|
||||
break;
|
||||
case PROP_ACTIVE:
|
||||
priv->active = g_value_get_boolean (value);
|
||||
g_object_set (object,
|
||||
"label", priv->active ? priv->on_label : priv->off_label,
|
||||
NULL);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_ON_LABEL:
|
||||
g_value_set_string(value, priv->on_label);
|
||||
break;
|
||||
case PROP_OFF_LABEL:
|
||||
g_value_set_string(value, priv->off_label);
|
||||
break;
|
||||
case PROP_ACTIVE:
|
||||
g_value_set_boolean(value, priv->active);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_toggle_button_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_toggle_button_class_init(NmtNewtToggleButtonClass *button_class)
|
||||
{
|
||||
NmtNewtToggleButtonPrivate *priv = NMT_NEWT_TOGGLE_BUTTON_GET_PRIVATE (object);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(button_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS(button_class);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_ON_LABEL:
|
||||
g_value_set_string (value, priv->on_label);
|
||||
break;
|
||||
case PROP_OFF_LABEL:
|
||||
g_value_set_string (value, priv->off_label);
|
||||
break;
|
||||
case PROP_ACTIVE:
|
||||
g_value_set_boolean (value, priv->active);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_type_class_add_private(button_class, sizeof(NmtNewtToggleButtonPrivate));
|
||||
|
||||
static void
|
||||
nmt_newt_toggle_button_class_init (NmtNewtToggleButtonClass *button_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (button_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (button_class);
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_toggle_button_set_property;
|
||||
object_class->get_property = nmt_newt_toggle_button_get_property;
|
||||
object_class->finalize = nmt_newt_toggle_button_finalize;
|
||||
|
||||
g_type_class_add_private (button_class, sizeof (NmtNewtToggleButtonPrivate));
|
||||
widget_class->activated = nmt_newt_toggle_button_activated;
|
||||
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_toggle_button_set_property;
|
||||
object_class->get_property = nmt_newt_toggle_button_get_property;
|
||||
object_class->finalize = nmt_newt_toggle_button_finalize;
|
||||
|
||||
widget_class->activated = nmt_newt_toggle_button_activated;
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtToggleButton:on-label:
|
||||
*
|
||||
* The label the button displays when it is "on".
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ON_LABEL,
|
||||
g_param_spec_string ("on-label", "", "",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_ON_LABEL,
|
||||
g_param_spec_string("on-label", "", "", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtToggleButton:off-label:
|
||||
*
|
||||
* The label the button displays when it is "off".
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_OFF_LABEL,
|
||||
g_param_spec_string ("off-label", "", "",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_OFF_LABEL,
|
||||
g_param_spec_string("off-label", "", "", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtToggleButton:active:
|
||||
*
|
||||
* Whether the button is currently "on" (%TRUE) or "off" (%FALSE)
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_ACTIVE,
|
||||
g_param_spec_boolean ("active", "", "",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_ACTIVE,
|
||||
g_param_spec_boolean("active", "", "", FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,30 +8,32 @@
|
|||
|
||||
#include "nmt-newt-button.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_TOGGLE_BUTTON (nmt_newt_toggle_button_get_type ())
|
||||
#define NMT_NEWT_TOGGLE_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_TOGGLE_BUTTON, NmtNewtToggleButton))
|
||||
#define NMT_NEWT_TOGGLE_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_TOGGLE_BUTTON, NmtNewtToggleButtonClass))
|
||||
#define NMT_IS_NEWT_TOGGLE_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_TOGGLE_BUTTON))
|
||||
#define NMT_IS_NEWT_TOGGLE_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_TOGGLE_BUTTON))
|
||||
#define NMT_NEWT_TOGGLE_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_TOGGLE_BUTTON, NmtNewtToggleButtonClass))
|
||||
#define NMT_TYPE_NEWT_TOGGLE_BUTTON (nmt_newt_toggle_button_get_type())
|
||||
#define NMT_NEWT_TOGGLE_BUTTON(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_TOGGLE_BUTTON, NmtNewtToggleButton))
|
||||
#define NMT_NEWT_TOGGLE_BUTTON_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_TOGGLE_BUTTON, NmtNewtToggleButtonClass))
|
||||
#define NMT_IS_NEWT_TOGGLE_BUTTON(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_TOGGLE_BUTTON))
|
||||
#define NMT_IS_NEWT_TOGGLE_BUTTON_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_TOGGLE_BUTTON))
|
||||
#define NMT_NEWT_TOGGLE_BUTTON_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_TOGGLE_BUTTON, NmtNewtToggleButtonClass))
|
||||
|
||||
struct _NmtNewtToggleButton {
|
||||
NmtNewtButton parent;
|
||||
|
||||
NmtNewtButton parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NmtNewtButtonClass parent;
|
||||
NmtNewtButtonClass parent;
|
||||
|
||||
} NmtNewtToggleButtonClass;
|
||||
|
||||
GType nmt_newt_toggle_button_get_type (void);
|
||||
GType nmt_newt_toggle_button_get_type(void);
|
||||
|
||||
NmtNewtWidget *nmt_newt_toggle_button_new (const char *on_label,
|
||||
const char *off_label);
|
||||
NmtNewtWidget *nmt_newt_toggle_button_new(const char *on_label, const char *off_label);
|
||||
|
||||
gboolean nmt_newt_toggle_button_get_active (NmtNewtToggleButton *button);
|
||||
void nmt_newt_toggle_button_set_active (NmtNewtToggleButton *button,
|
||||
gboolean active);
|
||||
gboolean nmt_newt_toggle_button_get_active(NmtNewtToggleButton *button);
|
||||
void nmt_newt_toggle_button_set_active(NmtNewtToggleButton *button, gboolean active);
|
||||
|
||||
#endif /* NMT_NEWT_TOGGLE_BUTTON_H */
|
||||
|
|
|
|||
|
|
@ -17,89 +17,88 @@
|
|||
#include "nmt-newt-utils.h"
|
||||
|
||||
static void
|
||||
nmt_newt_dialog_g_log_handler (const char *log_domain,
|
||||
GLogLevelFlags log_level,
|
||||
const char *message,
|
||||
gpointer user_data)
|
||||
nmt_newt_dialog_g_log_handler(const char * log_domain,
|
||||
GLogLevelFlags log_level,
|
||||
const char * message,
|
||||
gpointer user_data)
|
||||
{
|
||||
const char *level_name;
|
||||
char *full_message;
|
||||
int screen_width, screen_height;
|
||||
newtComponent text, ok, form;
|
||||
newtGrid grid;
|
||||
const char * level_name;
|
||||
char * full_message;
|
||||
int screen_width, screen_height;
|
||||
newtComponent text, ok, form;
|
||||
newtGrid grid;
|
||||
|
||||
g_assert (!(log_level & G_LOG_FLAG_RECURSION));
|
||||
g_assert(!(log_level & G_LOG_FLAG_RECURSION));
|
||||
|
||||
if (log_level & G_LOG_LEVEL_DEBUG)
|
||||
return;
|
||||
if (log_level & G_LOG_LEVEL_DEBUG)
|
||||
return;
|
||||
|
||||
switch (log_level & G_LOG_LEVEL_MASK) {
|
||||
case G_LOG_LEVEL_ERROR:
|
||||
level_name = "ERROR";
|
||||
break;
|
||||
case G_LOG_LEVEL_CRITICAL:
|
||||
level_name = "CRITICAL";
|
||||
break;
|
||||
case G_LOG_LEVEL_WARNING:
|
||||
level_name = "WARNING";
|
||||
break;
|
||||
case G_LOG_LEVEL_MESSAGE:
|
||||
level_name = "Message";
|
||||
break;
|
||||
default:
|
||||
level_name = NULL;
|
||||
}
|
||||
switch (log_level & G_LOG_LEVEL_MASK) {
|
||||
case G_LOG_LEVEL_ERROR:
|
||||
level_name = "ERROR";
|
||||
break;
|
||||
case G_LOG_LEVEL_CRITICAL:
|
||||
level_name = "CRITICAL";
|
||||
break;
|
||||
case G_LOG_LEVEL_WARNING:
|
||||
level_name = "WARNING";
|
||||
break;
|
||||
case G_LOG_LEVEL_MESSAGE:
|
||||
level_name = "Message";
|
||||
break;
|
||||
default:
|
||||
level_name = NULL;
|
||||
}
|
||||
|
||||
full_message = g_strdup_printf ("%s%s%s%s%s",
|
||||
log_domain ?: "",
|
||||
log_domain && level_name ? " " : "",
|
||||
level_name ?: "",
|
||||
log_domain || level_name ? ": " : "",
|
||||
message);
|
||||
full_message = g_strdup_printf("%s%s%s%s%s",
|
||||
log_domain ?: "",
|
||||
log_domain && level_name ? " " : "",
|
||||
level_name ?: "",
|
||||
log_domain || level_name ? ": " : "",
|
||||
message);
|
||||
|
||||
/* newtWinMessage() wraps the window too narrowly by default, so
|
||||
/* newtWinMessage() wraps the window too narrowly by default, so
|
||||
* we don't want to use that. But we intentionally avoid using any
|
||||
* NmtNewt classes, to avoid possible error recursion.
|
||||
*/
|
||||
|
||||
newtGetScreenSize (&screen_width, &screen_height);
|
||||
text = newtTextboxReflowed (-1, -1, full_message, MAX (70, screen_width - 10), 0, 0, 0);
|
||||
g_free (full_message);
|
||||
newtGetScreenSize(&screen_width, &screen_height);
|
||||
text = newtTextboxReflowed(-1, -1, full_message, MAX(70, screen_width - 10), 0, 0, 0);
|
||||
g_free(full_message);
|
||||
|
||||
ok = newtButton (-1, -1, "OK");
|
||||
ok = newtButton(-1, -1, "OK");
|
||||
|
||||
grid = newtCreateGrid (1, 2);
|
||||
newtGridSetField (grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 0, 0, 0);
|
||||
newtGridSetField (grid, 0, 1, NEWT_GRID_COMPONENT, ok, 0, 1, 0, 0,
|
||||
NEWT_ANCHOR_RIGHT, 0);
|
||||
grid = newtCreateGrid(1, 2);
|
||||
newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 0, 0, 0);
|
||||
newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, ok, 0, 1, 0, 0, NEWT_ANCHOR_RIGHT, 0);
|
||||
|
||||
newtGridWrappedWindow (grid, (char *) (level_name ?: ""));
|
||||
newtGridFree (grid, TRUE);
|
||||
newtGridWrappedWindow(grid, (char *) (level_name ?: ""));
|
||||
newtGridFree(grid, TRUE);
|
||||
|
||||
form = newtForm (NULL, NULL, 0);
|
||||
newtFormAddComponents (form, text, ok, NULL);
|
||||
newtRunForm (form);
|
||||
newtFormDestroy (form);
|
||||
newtPopWindow ();
|
||||
form = newtForm(NULL, NULL, 0);
|
||||
newtFormAddComponents(form, text, ok, NULL);
|
||||
newtRunForm(form);
|
||||
newtFormDestroy(form);
|
||||
newtPopWindow();
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_basic_g_log_handler (const char *log_domain,
|
||||
GLogLevelFlags log_level,
|
||||
const char *message,
|
||||
gpointer user_data)
|
||||
nmt_newt_basic_g_log_handler(const char * log_domain,
|
||||
GLogLevelFlags log_level,
|
||||
const char * message,
|
||||
gpointer user_data)
|
||||
{
|
||||
newtSuspend ();
|
||||
g_log_default_handler (log_domain, log_level, message, NULL);
|
||||
newtResume ();
|
||||
newtSuspend();
|
||||
g_log_default_handler(log_domain, log_level, message, NULL);
|
||||
newtResume();
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_suspend_callback (gpointer user_data)
|
||||
nmt_newt_suspend_callback(gpointer user_data)
|
||||
{
|
||||
newtSuspend ();
|
||||
kill (getpid (), SIGTSTP);
|
||||
newtResume ();
|
||||
newtSuspend();
|
||||
kill(getpid(), SIGTSTP);
|
||||
newtResume();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -109,23 +108,23 @@ nmt_newt_suspend_callback (gpointer user_data)
|
|||
* This should be called once, before any other nmt-newt functions.
|
||||
*/
|
||||
void
|
||||
nmt_newt_init (void)
|
||||
nmt_newt_init(void)
|
||||
{
|
||||
newtInit ();
|
||||
newtCls ();
|
||||
newtInit();
|
||||
newtCls();
|
||||
|
||||
newtSetColor (NEWT_COLORSET_CHECKBOX, "black", "lightgray");
|
||||
newtSetColor (NMT_NEWT_COLORSET_BAD_LABEL, "red", "lightgray");
|
||||
newtSetColor (NMT_NEWT_COLORSET_PLAIN_LABEL, "black", "lightgray");
|
||||
newtSetColor (NMT_NEWT_COLORSET_DISABLED_BUTTON, "blue", "lightgray");
|
||||
newtSetColor (NMT_NEWT_COLORSET_TEXTBOX_WITH_BACKGROUND, "black", "white");
|
||||
newtSetColor(NEWT_COLORSET_CHECKBOX, "black", "lightgray");
|
||||
newtSetColor(NMT_NEWT_COLORSET_BAD_LABEL, "red", "lightgray");
|
||||
newtSetColor(NMT_NEWT_COLORSET_PLAIN_LABEL, "black", "lightgray");
|
||||
newtSetColor(NMT_NEWT_COLORSET_DISABLED_BUTTON, "blue", "lightgray");
|
||||
newtSetColor(NMT_NEWT_COLORSET_TEXTBOX_WITH_BACKGROUND, "black", "white");
|
||||
|
||||
if (g_getenv ("NMTUI_DEBUG"))
|
||||
g_log_set_default_handler (nmt_newt_dialog_g_log_handler, NULL);
|
||||
else
|
||||
g_log_set_default_handler (nmt_newt_basic_g_log_handler, NULL);
|
||||
if (g_getenv("NMTUI_DEBUG"))
|
||||
g_log_set_default_handler(nmt_newt_dialog_g_log_handler, NULL);
|
||||
else
|
||||
g_log_set_default_handler(nmt_newt_basic_g_log_handler, NULL);
|
||||
|
||||
newtSetSuspendCallback (nmt_newt_suspend_callback, NULL);
|
||||
newtSetSuspendCallback(nmt_newt_suspend_callback, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -134,10 +133,10 @@ nmt_newt_init (void)
|
|||
* Wrapper for newtFinished(). Should be called at the end of the program.
|
||||
*/
|
||||
void
|
||||
nmt_newt_finished (void)
|
||||
nmt_newt_finished(void)
|
||||
{
|
||||
newtFinished ();
|
||||
g_log_set_default_handler (g_log_default_handler, NULL);
|
||||
newtFinished();
|
||||
g_log_set_default_handler(g_log_default_handler, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -149,23 +148,22 @@ nmt_newt_finished (void)
|
|||
* button, and returns after the user clicks "OK".
|
||||
*/
|
||||
void
|
||||
nmt_newt_message_dialog (const char *message,
|
||||
...)
|
||||
nmt_newt_message_dialog(const char *message, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *msg, *msg_lc, *ok_lc;
|
||||
va_list ap;
|
||||
char * msg, *msg_lc, *ok_lc;
|
||||
|
||||
va_start (ap, message);
|
||||
msg = g_strdup_vprintf (message, ap);
|
||||
va_end (ap);
|
||||
va_start(ap, message);
|
||||
msg = g_strdup_vprintf(message, ap);
|
||||
va_end(ap);
|
||||
|
||||
msg_lc = nmt_newt_locale_from_utf8 (msg);
|
||||
ok_lc = nmt_newt_locale_from_utf8 (_("OK"));
|
||||
newtWinMessage (NULL, ok_lc, "%s", msg_lc);
|
||||
msg_lc = nmt_newt_locale_from_utf8(msg);
|
||||
ok_lc = nmt_newt_locale_from_utf8(_("OK"));
|
||||
newtWinMessage(NULL, ok_lc, "%s", msg_lc);
|
||||
|
||||
g_free (ok_lc);
|
||||
g_free (msg_lc);
|
||||
g_free (msg);
|
||||
g_free(ok_lc);
|
||||
g_free(msg_lc);
|
||||
g_free(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -181,30 +179,27 @@ nmt_newt_message_dialog (const char *message,
|
|||
* Returns: which button was clicked: 0 for @button1 or 1 for @button2
|
||||
*/
|
||||
int
|
||||
nmt_newt_choice_dialog (const char *button1,
|
||||
const char *button2,
|
||||
const char *message,
|
||||
...)
|
||||
nmt_newt_choice_dialog(const char *button1, const char *button2, const char *message, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *msg, *msg_lc, *button1_lc, *button2_lc;
|
||||
int choice;
|
||||
va_list ap;
|
||||
char * msg, *msg_lc, *button1_lc, *button2_lc;
|
||||
int choice;
|
||||
|
||||
va_start (ap, message);
|
||||
msg = g_strdup_vprintf (message, ap);
|
||||
va_end (ap);
|
||||
va_start(ap, message);
|
||||
msg = g_strdup_vprintf(message, ap);
|
||||
va_end(ap);
|
||||
|
||||
msg_lc = nmt_newt_locale_from_utf8 (msg);
|
||||
button1_lc = nmt_newt_locale_from_utf8 (button1);
|
||||
button2_lc = nmt_newt_locale_from_utf8 (button2);
|
||||
choice = newtWinChoice (NULL, button1_lc, button2_lc, "%s", msg_lc);
|
||||
msg_lc = nmt_newt_locale_from_utf8(msg);
|
||||
button1_lc = nmt_newt_locale_from_utf8(button1);
|
||||
button2_lc = nmt_newt_locale_from_utf8(button2);
|
||||
choice = newtWinChoice(NULL, button1_lc, button2_lc, "%s", msg_lc);
|
||||
|
||||
g_free (button1_lc);
|
||||
g_free (button2_lc);
|
||||
g_free (msg_lc);
|
||||
g_free (msg);
|
||||
g_free(button1_lc);
|
||||
g_free(button2_lc);
|
||||
g_free(msg_lc);
|
||||
g_free(msg);
|
||||
|
||||
return choice;
|
||||
return choice;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -221,14 +216,14 @@ nmt_newt_choice_dialog (const char *button1,
|
|||
* Returns: @str_lc, converted to UTF-8.
|
||||
*/
|
||||
char *
|
||||
nmt_newt_locale_to_utf8 (const char *str_lc)
|
||||
nmt_newt_locale_to_utf8(const char *str_lc)
|
||||
{
|
||||
char *str_utf8;
|
||||
char *str_utf8;
|
||||
|
||||
str_utf8 = g_locale_to_utf8 (str_lc, -1, NULL, NULL, NULL);
|
||||
if (!str_utf8)
|
||||
str_utf8 = g_strdup ("");
|
||||
return str_utf8;
|
||||
str_utf8 = g_locale_to_utf8(str_lc, -1, NULL, NULL, NULL);
|
||||
if (!str_utf8)
|
||||
str_utf8 = g_strdup("");
|
||||
return str_utf8;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -244,14 +239,14 @@ nmt_newt_locale_to_utf8 (const char *str_lc)
|
|||
* Returns: @str_utf8, converted to the user's locale encoding.
|
||||
*/
|
||||
char *
|
||||
nmt_newt_locale_from_utf8 (const char *str_utf8)
|
||||
nmt_newt_locale_from_utf8(const char *str_utf8)
|
||||
{
|
||||
char *str_lc;
|
||||
char *str_lc;
|
||||
|
||||
str_lc = g_locale_from_utf8 (str_utf8, -1, NULL, NULL, NULL);
|
||||
if (!str_lc)
|
||||
str_lc = g_strdup ("");
|
||||
return str_lc;
|
||||
str_lc = g_locale_from_utf8(str_utf8, -1, NULL, NULL, NULL);
|
||||
if (!str_lc)
|
||||
str_lc = g_strdup("");
|
||||
return str_lc;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -263,26 +258,26 @@ nmt_newt_locale_from_utf8 (const char *str_utf8)
|
|||
* Returns: the width of @str
|
||||
*/
|
||||
int
|
||||
nmt_newt_text_width (const char *str)
|
||||
nmt_newt_text_width(const char *str)
|
||||
{
|
||||
int width;
|
||||
gunichar ch;
|
||||
int width;
|
||||
gunichar ch;
|
||||
|
||||
for (width = 0; *str; str = g_utf8_next_char (str)) {
|
||||
ch = g_utf8_get_char (str);
|
||||
for (width = 0; *str; str = g_utf8_next_char(str)) {
|
||||
ch = g_utf8_get_char(str);
|
||||
|
||||
/* Based on _vte_iso2022_unichar_width */
|
||||
if (G_LIKELY (ch < 0x80))
|
||||
width += 1;
|
||||
else if (G_UNLIKELY (g_unichar_iszerowidth (ch)))
|
||||
width += 0;
|
||||
else if (G_UNLIKELY (g_unichar_iswide (ch)))
|
||||
width += 2;
|
||||
else
|
||||
width += 1;
|
||||
}
|
||||
/* Based on _vte_iso2022_unichar_width */
|
||||
if (G_LIKELY(ch < 0x80))
|
||||
width += 1;
|
||||
else if (G_UNLIKELY(g_unichar_iszerowidth(ch)))
|
||||
width += 0;
|
||||
else if (G_UNLIKELY(g_unichar_iswide(ch)))
|
||||
width += 2;
|
||||
else
|
||||
width += 1;
|
||||
}
|
||||
|
||||
return width;
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -298,69 +293,74 @@ nmt_newt_text_width (const char *str)
|
|||
* Returns: the edited data, or %NULL if an error occurred.
|
||||
*/
|
||||
char *
|
||||
nmt_newt_edit_string (const char *data)
|
||||
nmt_newt_edit_string(const char *data)
|
||||
{
|
||||
gssize len, nwrote;
|
||||
char *filename, *argv[3];
|
||||
GError *error = NULL;
|
||||
int fd, status;
|
||||
char *new_data = NULL;
|
||||
gssize len, nwrote;
|
||||
char * filename, *argv[3];
|
||||
GError *error = NULL;
|
||||
int fd, status;
|
||||
char * new_data = NULL;
|
||||
|
||||
fd = g_file_open_tmp ("XXXXXX.json", &filename, &error);
|
||||
if (fd == -1) {
|
||||
nmt_newt_message_dialog (_("Could not create temporary file: %s"), error->message);
|
||||
g_error_free (error);
|
||||
return NULL;
|
||||
}
|
||||
fd = g_file_open_tmp("XXXXXX.json", &filename, &error);
|
||||
if (fd == -1) {
|
||||
nmt_newt_message_dialog(_("Could not create temporary file: %s"), error->message);
|
||||
g_error_free(error);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = data ? strlen (data) : 0;
|
||||
while (len) {
|
||||
do
|
||||
nwrote = write (fd, data, len);
|
||||
while (nwrote == -1 && errno == EINTR);
|
||||
len = data ? strlen(data) : 0;
|
||||
while (len) {
|
||||
do
|
||||
nwrote = write(fd, data, len);
|
||||
while (nwrote == -1 && errno == EINTR);
|
||||
|
||||
len -= nwrote;
|
||||
data += nwrote;
|
||||
}
|
||||
nm_close (fd);
|
||||
len -= nwrote;
|
||||
data += nwrote;
|
||||
}
|
||||
nm_close(fd);
|
||||
|
||||
argv[0] = (char *) g_getenv ("VISUAL");
|
||||
if (!argv[0])
|
||||
argv[0] = (char *) g_getenv ("EDITOR");
|
||||
if (!argv[0])
|
||||
argv[0] = (char *) "vi";
|
||||
argv[1] = filename;
|
||||
argv[2] = NULL;
|
||||
argv[0] = (char *) g_getenv("VISUAL");
|
||||
if (!argv[0])
|
||||
argv[0] = (char *) g_getenv("EDITOR");
|
||||
if (!argv[0])
|
||||
argv[0] = (char *) "vi";
|
||||
argv[1] = filename;
|
||||
argv[2] = NULL;
|
||||
|
||||
newtSuspend ();
|
||||
g_spawn_sync (NULL, argv, NULL,
|
||||
G_SPAWN_SEARCH_PATH | G_SPAWN_CHILD_INHERITS_STDIN,
|
||||
NULL, NULL, NULL, NULL,
|
||||
&status, &error);
|
||||
newtResume ();
|
||||
newtSuspend();
|
||||
g_spawn_sync(NULL,
|
||||
argv,
|
||||
NULL,
|
||||
G_SPAWN_SEARCH_PATH | G_SPAWN_CHILD_INHERITS_STDIN,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
&status,
|
||||
&error);
|
||||
newtResume();
|
||||
|
||||
if (error) {
|
||||
nmt_newt_message_dialog (_("Could not create temporary file: %s"), error->message);
|
||||
g_error_free (error);
|
||||
goto done;
|
||||
}
|
||||
if (error) {
|
||||
nmt_newt_message_dialog(_("Could not create temporary file: %s"), error->message);
|
||||
g_error_free(error);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!g_spawn_check_exit_status (status, &error)) {
|
||||
nmt_newt_message_dialog (_("Editor failed: %s"), error->message);
|
||||
g_error_free (error);
|
||||
goto done;
|
||||
}
|
||||
if (!g_spawn_check_exit_status(status, &error)) {
|
||||
nmt_newt_message_dialog(_("Editor failed: %s"), error->message);
|
||||
g_error_free(error);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!g_file_get_contents (filename, &new_data, NULL, &error)) {
|
||||
nmt_newt_message_dialog (_("Could not re-read file: %s"), error->message);
|
||||
g_error_free (error);
|
||||
goto done;
|
||||
}
|
||||
if (!g_file_get_contents(filename, &new_data, NULL, &error)) {
|
||||
nmt_newt_message_dialog(_("Could not re-read file: %s"), error->message);
|
||||
g_error_free(error);
|
||||
goto done;
|
||||
}
|
||||
|
||||
done:
|
||||
unlink (filename);
|
||||
g_free (filename);
|
||||
done:
|
||||
unlink(filename);
|
||||
g_free(filename);
|
||||
|
||||
return new_data;
|
||||
return new_data;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,28 +8,25 @@
|
|||
|
||||
#include <newt.h>
|
||||
|
||||
void nmt_newt_init (void);
|
||||
void nmt_newt_finished (void);
|
||||
void nmt_newt_init(void);
|
||||
void nmt_newt_finished(void);
|
||||
|
||||
typedef enum {
|
||||
NMT_NEWT_COLORSET_BAD_LABEL = NEWT_COLORSET_CUSTOM (0),
|
||||
NMT_NEWT_COLORSET_PLAIN_LABEL,
|
||||
NMT_NEWT_COLORSET_DISABLED_BUTTON,
|
||||
NMT_NEWT_COLORSET_TEXTBOX_WITH_BACKGROUND
|
||||
NMT_NEWT_COLORSET_BAD_LABEL = NEWT_COLORSET_CUSTOM(0),
|
||||
NMT_NEWT_COLORSET_PLAIN_LABEL,
|
||||
NMT_NEWT_COLORSET_DISABLED_BUTTON,
|
||||
NMT_NEWT_COLORSET_TEXTBOX_WITH_BACKGROUND
|
||||
} NmtNewtColorsets;
|
||||
|
||||
char *nmt_newt_locale_to_utf8 (const char *str_lc);
|
||||
char *nmt_newt_locale_from_utf8 (const char *str_utf8);
|
||||
char *nmt_newt_locale_to_utf8(const char *str_lc);
|
||||
char *nmt_newt_locale_from_utf8(const char *str_utf8);
|
||||
|
||||
int nmt_newt_text_width (const char *str);
|
||||
int nmt_newt_text_width(const char *str);
|
||||
|
||||
void nmt_newt_message_dialog (const char *message,
|
||||
...) _nm_printf (1, 2);
|
||||
int nmt_newt_choice_dialog (const char *button1,
|
||||
const char *button2,
|
||||
const char *message,
|
||||
...) _nm_printf (3, 4);
|
||||
void nmt_newt_message_dialog(const char *message, ...) _nm_printf(1, 2);
|
||||
int nmt_newt_choice_dialog(const char *button1, const char *button2, const char *message, ...)
|
||||
_nm_printf(3, 4);
|
||||
|
||||
char *nmt_newt_edit_string (const char *data);
|
||||
char *nmt_newt_edit_string(const char *data);
|
||||
|
||||
#endif /* NMT_NEWT_UTILS_H */
|
||||
|
|
|
|||
|
|
@ -26,56 +26,57 @@
|
|||
#include "nmt-newt-widget.h"
|
||||
#include "nmt-newt-form.h"
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (NmtNewtWidget, nmt_newt_widget, G_TYPE_INITIALLY_UNOWNED)
|
||||
G_DEFINE_ABSTRACT_TYPE(NmtNewtWidget, nmt_newt_widget, G_TYPE_INITIALLY_UNOWNED)
|
||||
|
||||
#define NMT_NEWT_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_NEWT_WIDGET, NmtNewtWidgetPrivate))
|
||||
#define NMT_NEWT_WIDGET_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_WIDGET, NmtNewtWidgetPrivate))
|
||||
|
||||
typedef struct {
|
||||
NmtNewtWidget *parent;
|
||||
gboolean visible, realized, valid;
|
||||
gboolean exit_on_activate;
|
||||
NmtNewtWidget *parent;
|
||||
gboolean visible, realized, valid;
|
||||
gboolean exit_on_activate;
|
||||
|
||||
int pad_left, pad_top, pad_right, pad_bottom;
|
||||
int pad_left, pad_top, pad_right, pad_bottom;
|
||||
} NmtNewtWidgetPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_0,
|
||||
|
||||
PROP_PARENT,
|
||||
PROP_VISIBLE,
|
||||
PROP_VALID,
|
||||
PROP_EXIT_ON_ACTIVATE,
|
||||
PROP_PARENT,
|
||||
PROP_VISIBLE,
|
||||
PROP_VALID,
|
||||
PROP_EXIT_ON_ACTIVATE,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
enum {
|
||||
NEEDS_REBUILD,
|
||||
ACTIVATED,
|
||||
NEEDS_REBUILD,
|
||||
ACTIVATED,
|
||||
|
||||
LAST_SIGNAL
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
static guint signals[LAST_SIGNAL] = {0};
|
||||
|
||||
static void
|
||||
nmt_newt_widget_init (NmtNewtWidget *widget)
|
||||
nmt_newt_widget_init(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
priv->visible = TRUE;
|
||||
priv->valid = TRUE;
|
||||
priv->visible = TRUE;
|
||||
priv->valid = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_widget_finalize (GObject *object)
|
||||
nmt_newt_widget_finalize(GObject *object)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (object);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(object);
|
||||
|
||||
nmt_newt_widget_unrealize (NMT_NEWT_WIDGET (object));
|
||||
g_clear_object (&priv->parent);
|
||||
nmt_newt_widget_unrealize(NMT_NEWT_WIDGET(object));
|
||||
g_clear_object(&priv->parent);
|
||||
|
||||
G_OBJECT_CLASS (nmt_newt_widget_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS(nmt_newt_widget_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -89,14 +90,14 @@ nmt_newt_widget_finalize (GObject *object)
|
|||
* cause its children to be realized and unrealized as needed.
|
||||
*/
|
||||
void
|
||||
nmt_newt_widget_realize (NmtNewtWidget *widget)
|
||||
nmt_newt_widget_realize(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
if (!priv->realized) {
|
||||
NMT_NEWT_WIDGET_GET_CLASS (widget)->realize (widget);
|
||||
priv->realized = TRUE;
|
||||
}
|
||||
if (!priv->realized) {
|
||||
NMT_NEWT_WIDGET_GET_CLASS(widget)->realize(widget);
|
||||
priv->realized = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -109,14 +110,14 @@ nmt_newt_widget_realize (NmtNewtWidget *widget)
|
|||
* cause its children to be realized and unrealized as needed.
|
||||
*/
|
||||
void
|
||||
nmt_newt_widget_unrealize (NmtNewtWidget *widget)
|
||||
nmt_newt_widget_unrealize(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
if (priv->realized) {
|
||||
NMT_NEWT_WIDGET_GET_CLASS (widget)->unrealize (widget);
|
||||
priv->realized = FALSE;
|
||||
}
|
||||
if (priv->realized) {
|
||||
NMT_NEWT_WIDGET_GET_CLASS(widget)->unrealize(widget);
|
||||
priv->realized = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -128,11 +129,11 @@ nmt_newt_widget_unrealize (NmtNewtWidget *widget)
|
|||
* Returns: whether @widget is realized.
|
||||
*/
|
||||
gboolean
|
||||
nmt_newt_widget_get_realized (NmtNewtWidget *widget)
|
||||
nmt_newt_widget_get_realized(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
return priv->realized;
|
||||
return priv->realized;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -154,13 +155,13 @@ nmt_newt_widget_get_realized (NmtNewtWidget *widget)
|
|||
* with it.
|
||||
*/
|
||||
newtComponent *
|
||||
nmt_newt_widget_get_components (NmtNewtWidget *widget)
|
||||
nmt_newt_widget_get_components(NmtNewtWidget *widget)
|
||||
{
|
||||
if (nmt_newt_widget_get_visible (widget)) {
|
||||
nmt_newt_widget_realize (widget);
|
||||
return NMT_NEWT_WIDGET_GET_CLASS (widget)->get_components (widget);
|
||||
} else
|
||||
return NULL;
|
||||
if (nmt_newt_widget_get_visible(widget)) {
|
||||
nmt_newt_widget_realize(widget);
|
||||
return NMT_NEWT_WIDGET_GET_CLASS(widget)->get_components(widget);
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -173,10 +174,9 @@ nmt_newt_widget_get_components (NmtNewtWidget *widget)
|
|||
* Return value: @co's owner, or %NULL if it was not found.
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_widget_find_component (NmtNewtWidget *widget,
|
||||
newtComponent co)
|
||||
nmt_newt_widget_find_component(NmtNewtWidget *widget, newtComponent co)
|
||||
{
|
||||
return NMT_NEWT_WIDGET_GET_CLASS (widget)->find_component (widget, co);
|
||||
return NMT_NEWT_WIDGET_GET_CLASS(widget)->find_component(widget, co);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -190,18 +190,18 @@ nmt_newt_widget_find_component (NmtNewtWidget *widget,
|
|||
* Sets the padding on @widget.
|
||||
*/
|
||||
void
|
||||
nmt_newt_widget_set_padding (NmtNewtWidget *widget,
|
||||
int pad_left,
|
||||
int pad_top,
|
||||
int pad_right,
|
||||
int pad_bottom)
|
||||
nmt_newt_widget_set_padding(NmtNewtWidget *widget,
|
||||
int pad_left,
|
||||
int pad_top,
|
||||
int pad_right,
|
||||
int pad_bottom)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
priv->pad_left = pad_left;
|
||||
priv->pad_top = pad_top;
|
||||
priv->pad_right = pad_right;
|
||||
priv->pad_bottom = pad_bottom;
|
||||
priv->pad_left = pad_left;
|
||||
priv->pad_top = pad_top;
|
||||
priv->pad_right = pad_right;
|
||||
priv->pad_bottom = pad_bottom;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -215,20 +215,18 @@ nmt_newt_widget_set_padding (NmtNewtWidget *widget,
|
|||
* will be realized first.
|
||||
*/
|
||||
void
|
||||
nmt_newt_widget_size_request (NmtNewtWidget *widget,
|
||||
int *width,
|
||||
int *height)
|
||||
nmt_newt_widget_size_request(NmtNewtWidget *widget, int *width, int *height)
|
||||
{
|
||||
if (nmt_newt_widget_get_visible (widget)) {
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
if (nmt_newt_widget_get_visible(widget)) {
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
nmt_newt_widget_realize (widget);
|
||||
NMT_NEWT_WIDGET_GET_CLASS (widget)->size_request (widget, width, height);
|
||||
nmt_newt_widget_realize(widget);
|
||||
NMT_NEWT_WIDGET_GET_CLASS(widget)->size_request(widget, width, height);
|
||||
|
||||
*width += priv->pad_left + priv->pad_right;
|
||||
*height += priv->pad_top + priv->pad_bottom;
|
||||
} else
|
||||
*width = *height = 0;
|
||||
*width += priv->pad_left + priv->pad_right;
|
||||
*height += priv->pad_top + priv->pad_bottom;
|
||||
} else
|
||||
*width = *height = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -253,23 +251,19 @@ nmt_newt_widget_size_request (NmtNewtWidget *widget,
|
|||
* fit.
|
||||
*/
|
||||
void
|
||||
nmt_newt_widget_size_allocate (NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height)
|
||||
nmt_newt_widget_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height)
|
||||
{
|
||||
if (nmt_newt_widget_get_visible (widget)) {
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
if (nmt_newt_widget_get_visible(widget)) {
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
nmt_newt_widget_realize (widget);
|
||||
x += priv->pad_left;
|
||||
y += priv->pad_top;
|
||||
width -= priv->pad_left + priv->pad_right;
|
||||
height -= priv->pad_top + priv->pad_bottom;
|
||||
nmt_newt_widget_realize(widget);
|
||||
x += priv->pad_left;
|
||||
y += priv->pad_top;
|
||||
width -= priv->pad_left + priv->pad_right;
|
||||
height -= priv->pad_top + priv->pad_bottom;
|
||||
|
||||
NMT_NEWT_WIDGET_GET_CLASS (widget)->size_allocate (widget, x, y, width, height);
|
||||
}
|
||||
NMT_NEWT_WIDGET_GET_CLASS(widget)->size_allocate(widget, x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -283,21 +277,21 @@ nmt_newt_widget_size_allocate (NmtNewtWidget *widget,
|
|||
* take the focus.
|
||||
*/
|
||||
newtComponent
|
||||
nmt_newt_widget_get_focus_component (NmtNewtWidget *widget)
|
||||
nmt_newt_widget_get_focus_component(NmtNewtWidget *widget)
|
||||
{
|
||||
if (!NMT_NEWT_WIDGET_GET_CLASS (widget)->get_focus_component)
|
||||
return NULL;
|
||||
if (!NMT_NEWT_WIDGET_GET_CLASS(widget)->get_focus_component)
|
||||
return NULL;
|
||||
|
||||
return NMT_NEWT_WIDGET_GET_CLASS (widget)->get_focus_component (widget);
|
||||
return NMT_NEWT_WIDGET_GET_CLASS(widget)->get_focus_component(widget);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_widget_real_activated (NmtNewtWidget *widget)
|
||||
nmt_newt_widget_real_activated(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
if (priv->exit_on_activate)
|
||||
nmt_newt_form_quit (nmt_newt_widget_get_form (widget));
|
||||
if (priv->exit_on_activate)
|
||||
nmt_newt_form_quit(nmt_newt_widget_get_form(widget));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -311,9 +305,9 @@ nmt_newt_widget_real_activated (NmtNewtWidget *widget)
|
|||
* will call nmt_newt_form_quit() on the widget's form.
|
||||
*/
|
||||
void
|
||||
nmt_newt_widget_activated (NmtNewtWidget *widget)
|
||||
nmt_newt_widget_activated(NmtNewtWidget *widget)
|
||||
{
|
||||
g_signal_emit (widget, signals[ACTIVATED], 0);
|
||||
g_signal_emit(widget, signals[ACTIVATED], 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -325,11 +319,11 @@ nmt_newt_widget_activated (NmtNewtWidget *widget)
|
|||
* Returns: @widget's #NmtNewtWidget:exit-on-activate flag
|
||||
*/
|
||||
gboolean
|
||||
nmt_newt_widget_get_exit_on_activate (NmtNewtWidget *widget)
|
||||
nmt_newt_widget_get_exit_on_activate(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
return priv->exit_on_activate;
|
||||
return priv->exit_on_activate;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -340,16 +334,15 @@ nmt_newt_widget_get_exit_on_activate (NmtNewtWidget *widget)
|
|||
* Sets @widget's #NmtNewtWidget:exit-on-activate flag, qv.
|
||||
*/
|
||||
void
|
||||
nmt_newt_widget_set_exit_on_activate (NmtNewtWidget *widget,
|
||||
gboolean exit_on_activate)
|
||||
nmt_newt_widget_set_exit_on_activate(NmtNewtWidget *widget, gboolean exit_on_activate)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
exit_on_activate = !!exit_on_activate;
|
||||
if (priv->exit_on_activate != exit_on_activate) {
|
||||
priv->exit_on_activate = exit_on_activate;
|
||||
g_object_notify (G_OBJECT (widget), "exit-on-activate");
|
||||
}
|
||||
exit_on_activate = !!exit_on_activate;
|
||||
if (priv->exit_on_activate != exit_on_activate) {
|
||||
priv->exit_on_activate = exit_on_activate;
|
||||
g_object_notify(G_OBJECT(widget), "exit-on-activate");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -361,11 +354,11 @@ nmt_newt_widget_set_exit_on_activate (NmtNewtWidget *widget,
|
|||
* Returns: @widget's #NmtNewtWidget:visible flag
|
||||
*/
|
||||
gboolean
|
||||
nmt_newt_widget_get_visible (NmtNewtWidget *widget)
|
||||
nmt_newt_widget_get_visible(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
return priv->visible;
|
||||
return priv->visible;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -376,17 +369,16 @@ nmt_newt_widget_get_visible (NmtNewtWidget *widget)
|
|||
* Sets @widget's #NmtNewtWidget:visible flag, qv.
|
||||
*/
|
||||
void
|
||||
nmt_newt_widget_set_visible (NmtNewtWidget *widget,
|
||||
gboolean visible)
|
||||
nmt_newt_widget_set_visible(NmtNewtWidget *widget, gboolean visible)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
visible = !!visible;
|
||||
if (priv->visible != visible) {
|
||||
priv->visible = visible;
|
||||
g_object_notify (G_OBJECT (widget), "visible");
|
||||
nmt_newt_widget_needs_rebuild (widget);
|
||||
}
|
||||
visible = !!visible;
|
||||
if (priv->visible != visible) {
|
||||
priv->visible = visible;
|
||||
g_object_notify(G_OBJECT(widget), "visible");
|
||||
nmt_newt_widget_needs_rebuild(widget);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -399,14 +391,13 @@ nmt_newt_widget_set_visible (NmtNewtWidget *widget,
|
|||
* container-specific method to actually add a widget to a container.
|
||||
*/
|
||||
void
|
||||
nmt_newt_widget_set_parent (NmtNewtWidget *widget,
|
||||
NmtNewtWidget *parent)
|
||||
nmt_newt_widget_set_parent(NmtNewtWidget *widget, NmtNewtWidget *parent)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
g_clear_object (&priv->parent);
|
||||
priv->parent = parent ? g_object_ref (parent) : NULL;
|
||||
g_object_notify (G_OBJECT (widget), "parent");
|
||||
g_clear_object(&priv->parent);
|
||||
priv->parent = parent ? g_object_ref(parent) : NULL;
|
||||
g_object_notify(G_OBJECT(widget), "parent");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -418,11 +409,11 @@ nmt_newt_widget_set_parent (NmtNewtWidget *widget,
|
|||
* Returns: @widget's parent
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_newt_widget_get_parent (NmtNewtWidget *widget)
|
||||
nmt_newt_widget_get_parent(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
return priv->parent;
|
||||
return priv->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -434,15 +425,15 @@ nmt_newt_widget_get_parent (NmtNewtWidget *widget)
|
|||
* Returns: @widget's #NmtNewtForm
|
||||
*/
|
||||
NmtNewtForm *
|
||||
nmt_newt_widget_get_form (NmtNewtWidget *widget)
|
||||
nmt_newt_widget_get_form(NmtNewtWidget *widget)
|
||||
{
|
||||
while (widget) {
|
||||
if (NMT_IS_NEWT_FORM (widget))
|
||||
return NMT_NEWT_FORM (widget);
|
||||
widget = nmt_newt_widget_get_parent (widget);
|
||||
}
|
||||
while (widget) {
|
||||
if (NMT_IS_NEWT_FORM(widget))
|
||||
return NMT_NEWT_FORM(widget);
|
||||
widget = nmt_newt_widget_get_parent(widget);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -455,11 +446,11 @@ nmt_newt_widget_get_form (NmtNewtWidget *widget)
|
|||
* Returns: @widget's #NmtNewtWidget:valid flag
|
||||
*/
|
||||
gboolean
|
||||
nmt_newt_widget_get_valid (NmtNewtWidget *widget)
|
||||
nmt_newt_widget_get_valid(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
return priv->valid;
|
||||
return priv->valid;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -475,17 +466,16 @@ nmt_newt_widget_get_valid (NmtNewtWidget *widget)
|
|||
* point.
|
||||
*/
|
||||
void
|
||||
nmt_newt_widget_set_valid (NmtNewtWidget *widget,
|
||||
gboolean valid)
|
||||
nmt_newt_widget_set_valid(NmtNewtWidget *widget, gboolean valid)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
|
||||
|
||||
valid = !!valid;
|
||||
if (priv->valid == valid)
|
||||
return;
|
||||
valid = !!valid;
|
||||
if (priv->valid == valid)
|
||||
return;
|
||||
|
||||
priv->valid = valid;
|
||||
g_object_notify (G_OBJECT (widget), "valid");
|
||||
priv->valid = valid;
|
||||
g_object_notify(G_OBJECT(widget), "valid");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -500,79 +490,73 @@ nmt_newt_widget_set_valid (NmtNewtWidget *widget,
|
|||
* creating a new one.
|
||||
*/
|
||||
void
|
||||
nmt_newt_widget_needs_rebuild (NmtNewtWidget *widget)
|
||||
nmt_newt_widget_needs_rebuild(NmtNewtWidget *widget)
|
||||
{
|
||||
g_signal_emit (widget, signals[NEEDS_REBUILD], 0);
|
||||
g_signal_emit(widget, signals[NEEDS_REBUILD], 0);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_widget_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_widget_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtWidget *widget = NMT_NEWT_WIDGET (object);
|
||||
NmtNewtWidget *widget = NMT_NEWT_WIDGET(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_PARENT:
|
||||
nmt_newt_widget_set_parent (widget, g_value_get_object (value));
|
||||
break;
|
||||
case PROP_VISIBLE:
|
||||
nmt_newt_widget_set_visible (widget, g_value_get_boolean (value));
|
||||
break;
|
||||
case PROP_EXIT_ON_ACTIVATE:
|
||||
nmt_newt_widget_set_exit_on_activate (widget, g_value_get_boolean (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_PARENT:
|
||||
nmt_newt_widget_set_parent(widget, g_value_get_object(value));
|
||||
break;
|
||||
case PROP_VISIBLE:
|
||||
nmt_newt_widget_set_visible(widget, g_value_get_boolean(value));
|
||||
break;
|
||||
case PROP_EXIT_ON_ACTIVATE:
|
||||
nmt_newt_widget_set_exit_on_activate(widget, g_value_get_boolean(value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_widget_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_newt_widget_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (object);
|
||||
NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_PARENT:
|
||||
g_value_set_object (value, priv->parent);
|
||||
break;
|
||||
case PROP_VISIBLE:
|
||||
g_value_set_boolean (value, priv->visible);
|
||||
break;
|
||||
case PROP_VALID:
|
||||
g_value_set_boolean (value, priv->valid);
|
||||
break;
|
||||
case PROP_EXIT_ON_ACTIVATE:
|
||||
g_value_set_boolean (value, priv->exit_on_activate);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_PARENT:
|
||||
g_value_set_object(value, priv->parent);
|
||||
break;
|
||||
case PROP_VISIBLE:
|
||||
g_value_set_boolean(value, priv->visible);
|
||||
break;
|
||||
case PROP_VALID:
|
||||
g_value_set_boolean(value, priv->valid);
|
||||
break;
|
||||
case PROP_EXIT_ON_ACTIVATE:
|
||||
g_value_set_boolean(value, priv->exit_on_activate);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_newt_widget_class_init (NmtNewtWidgetClass *widget_class)
|
||||
nmt_newt_widget_class_init(NmtNewtWidgetClass *widget_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (widget_class);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS(widget_class);
|
||||
|
||||
g_type_class_add_private (widget_class, sizeof (NmtNewtWidgetPrivate));
|
||||
g_type_class_add_private(widget_class, sizeof(NmtNewtWidgetPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_widget_set_property;
|
||||
object_class->get_property = nmt_newt_widget_get_property;
|
||||
object_class->finalize = nmt_newt_widget_finalize;
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_newt_widget_set_property;
|
||||
object_class->get_property = nmt_newt_widget_get_property;
|
||||
object_class->finalize = nmt_newt_widget_finalize;
|
||||
|
||||
widget_class->activated = nmt_newt_widget_real_activated;
|
||||
widget_class->activated = nmt_newt_widget_real_activated;
|
||||
|
||||
/* signals */
|
||||
/* signals */
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtWidget::needs-rebuild:
|
||||
* @widget: the #NmtNewtWidget
|
||||
*
|
||||
|
|
@ -580,76 +564,79 @@ nmt_newt_widget_class_init (NmtNewtWidgetClass *widget_class)
|
|||
* or any of its children. This signal propagates up the container
|
||||
* hierarchy, eventually reaching the top-level #NmtNewtForm.
|
||||
*/
|
||||
signals[NEEDS_REBUILD] =
|
||||
g_signal_new ("needs-rebuild",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NmtNewtWidgetClass, needs_rebuild),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
signals[NEEDS_REBUILD] = g_signal_new("needs-rebuild",
|
||||
G_OBJECT_CLASS_TYPE(object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET(NmtNewtWidgetClass, needs_rebuild),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE,
|
||||
0);
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtWidget::activated:
|
||||
* @widget: the #NmtNewtWidget
|
||||
*
|
||||
* Emitted when the widget's #newtComponent is activated.
|
||||
*/
|
||||
signals[ACTIVATED] =
|
||||
g_signal_new ("activated",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NmtNewtWidgetClass, activated),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
signals[ACTIVATED] = g_signal_new("activated",
|
||||
G_OBJECT_CLASS_TYPE(object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET(NmtNewtWidgetClass, activated),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE,
|
||||
0);
|
||||
|
||||
/* properties */
|
||||
/* properties */
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtNewtWidget:parent:
|
||||
*
|
||||
* The widget's parent widget, or %NULL if it has no parent.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_PARENT,
|
||||
g_param_spec_object ("parent", "", "",
|
||||
NMT_TYPE_NEWT_WIDGET,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(object_class,
|
||||
PROP_PARENT,
|
||||
g_param_spec_object("parent",
|
||||
"",
|
||||
"",
|
||||
NMT_TYPE_NEWT_WIDGET,
|
||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtWidget:visible:
|
||||
*
|
||||
* Whether the widget is visible. Invisible widgets do not get
|
||||
* realized or sized.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_VISIBLE,
|
||||
g_param_spec_boolean ("visible", "", "",
|
||||
TRUE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_VISIBLE,
|
||||
g_param_spec_boolean("visible", "", "", TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtWidget:valid:
|
||||
*
|
||||
* Whether the widget's content is considered valid. Components
|
||||
* determine their own validity. A container, by default, is
|
||||
* considered valid if all of its children are valid.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_VALID,
|
||||
g_param_spec_boolean ("valid", "", "",
|
||||
TRUE,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_VALID,
|
||||
g_param_spec_boolean("valid", "", "", TRUE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtNewtWidget:exit-on-activate:
|
||||
*
|
||||
* If %TRUE, the widget will call nmt_newt_form_quit() on its form
|
||||
* when it is activated.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_EXIT_ON_ACTIVATE,
|
||||
g_param_spec_boolean ("exit-on-activate", "", "",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_EXIT_ON_ACTIVATE,
|
||||
g_param_spec_boolean("exit-on-activate",
|
||||
"",
|
||||
"",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,94 +8,78 @@
|
|||
|
||||
#include "nmt-newt-types.h"
|
||||
|
||||
#define NMT_TYPE_NEWT_WIDGET (nmt_newt_widget_get_type ())
|
||||
#define NMT_NEWT_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_NEWT_WIDGET, NmtNewtWidget))
|
||||
#define NMT_NEWT_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_NEWT_WIDGET, NmtNewtWidgetClass))
|
||||
#define NMT_IS_NEWT_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_NEWT_WIDGET))
|
||||
#define NMT_IS_NEWT_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_NEWT_WIDGET))
|
||||
#define NMT_NEWT_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_NEWT_WIDGET, NmtNewtWidgetClass))
|
||||
#define NMT_TYPE_NEWT_WIDGET (nmt_newt_widget_get_type())
|
||||
#define NMT_NEWT_WIDGET(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_NEWT_WIDGET, NmtNewtWidget))
|
||||
#define NMT_NEWT_WIDGET_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_NEWT_WIDGET, NmtNewtWidgetClass))
|
||||
#define NMT_IS_NEWT_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_NEWT_WIDGET))
|
||||
#define NMT_IS_NEWT_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_NEWT_WIDGET))
|
||||
#define NMT_NEWT_WIDGET_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_NEWT_WIDGET, NmtNewtWidgetClass))
|
||||
|
||||
struct _NmtNewtWidget {
|
||||
GInitiallyUnowned parent;
|
||||
|
||||
GInitiallyUnowned parent;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
GInitiallyUnownedClass parent;
|
||||
GInitiallyUnownedClass parent;
|
||||
|
||||
/* signals */
|
||||
void (*needs_rebuild) (NmtNewtWidget *widget);
|
||||
void (*activated) (NmtNewtWidget *widget);
|
||||
/* signals */
|
||||
void (*needs_rebuild)(NmtNewtWidget *widget);
|
||||
void (*activated)(NmtNewtWidget *widget);
|
||||
|
||||
/* methods */
|
||||
void (*realize) (NmtNewtWidget *widget);
|
||||
void (*unrealize) (NmtNewtWidget *widget);
|
||||
/* methods */
|
||||
void (*realize)(NmtNewtWidget *widget);
|
||||
void (*unrealize)(NmtNewtWidget *widget);
|
||||
|
||||
newtComponent * (*get_components) (NmtNewtWidget *widget);
|
||||
NmtNewtWidget * (*find_component) (NmtNewtWidget *widget,
|
||||
newtComponent co);
|
||||
newtComponent *(*get_components)(NmtNewtWidget *widget);
|
||||
NmtNewtWidget *(*find_component)(NmtNewtWidget *widget, newtComponent co);
|
||||
|
||||
void (*size_request) (NmtNewtWidget *widget,
|
||||
int *width,
|
||||
int *height);
|
||||
void (*size_allocate) (NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height);
|
||||
void (*size_request)(NmtNewtWidget *widget, int *width, int *height);
|
||||
void (*size_allocate)(NmtNewtWidget *widget, int x, int y, int width, int height);
|
||||
|
||||
newtComponent (*get_focus_component) (NmtNewtWidget *widget);
|
||||
newtComponent (*get_focus_component)(NmtNewtWidget *widget);
|
||||
|
||||
} NmtNewtWidgetClass;
|
||||
|
||||
GType nmt_newt_widget_get_type (void);
|
||||
GType nmt_newt_widget_get_type(void);
|
||||
|
||||
void nmt_newt_widget_realize (NmtNewtWidget *widget);
|
||||
void nmt_newt_widget_unrealize (NmtNewtWidget *widget);
|
||||
gboolean nmt_newt_widget_get_realized (NmtNewtWidget *widget);
|
||||
void nmt_newt_widget_realize(NmtNewtWidget *widget);
|
||||
void nmt_newt_widget_unrealize(NmtNewtWidget *widget);
|
||||
gboolean nmt_newt_widget_get_realized(NmtNewtWidget *widget);
|
||||
|
||||
newtComponent *nmt_newt_widget_get_components (NmtNewtWidget *widget);
|
||||
newtComponent *nmt_newt_widget_get_components(NmtNewtWidget *widget);
|
||||
|
||||
void nmt_newt_widget_set_padding (NmtNewtWidget *widget,
|
||||
int pad_left,
|
||||
int pad_top,
|
||||
int pad_right,
|
||||
int pad_bottom);
|
||||
void nmt_newt_widget_set_padding(NmtNewtWidget *widget,
|
||||
int pad_left,
|
||||
int pad_top,
|
||||
int pad_right,
|
||||
int pad_bottom);
|
||||
|
||||
void nmt_newt_widget_size_request (NmtNewtWidget *widget,
|
||||
int *width,
|
||||
int *height);
|
||||
void nmt_newt_widget_size_allocate (NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height);
|
||||
void nmt_newt_widget_size_request(NmtNewtWidget *widget, int *width, int *height);
|
||||
void nmt_newt_widget_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height);
|
||||
|
||||
void nmt_newt_widget_set_parent (NmtNewtWidget *widget,
|
||||
NmtNewtWidget *parent);
|
||||
NmtNewtWidget *nmt_newt_widget_get_parent (NmtNewtWidget *widget);
|
||||
void nmt_newt_widget_set_parent(NmtNewtWidget *widget, NmtNewtWidget *parent);
|
||||
NmtNewtWidget *nmt_newt_widget_get_parent(NmtNewtWidget *widget);
|
||||
|
||||
NmtNewtForm *nmt_newt_widget_get_form (NmtNewtWidget *widget);
|
||||
NmtNewtForm *nmt_newt_widget_get_form(NmtNewtWidget *widget);
|
||||
|
||||
gboolean nmt_newt_widget_get_visible (NmtNewtWidget *widget);
|
||||
void nmt_newt_widget_set_visible (NmtNewtWidget *widget,
|
||||
gboolean visible);
|
||||
gboolean nmt_newt_widget_get_visible(NmtNewtWidget *widget);
|
||||
void nmt_newt_widget_set_visible(NmtNewtWidget *widget, gboolean visible);
|
||||
|
||||
newtComponent nmt_newt_widget_get_focus_component (NmtNewtWidget *widget);
|
||||
newtComponent nmt_newt_widget_get_focus_component(NmtNewtWidget *widget);
|
||||
|
||||
void nmt_newt_widget_activated (NmtNewtWidget *widget);
|
||||
gboolean nmt_newt_widget_get_exit_on_activate (NmtNewtWidget *widget);
|
||||
void nmt_newt_widget_set_exit_on_activate (NmtNewtWidget *widget,
|
||||
gboolean exit_on_activate);
|
||||
void nmt_newt_widget_activated(NmtNewtWidget *widget);
|
||||
gboolean nmt_newt_widget_get_exit_on_activate(NmtNewtWidget *widget);
|
||||
void nmt_newt_widget_set_exit_on_activate(NmtNewtWidget *widget, gboolean exit_on_activate);
|
||||
|
||||
gboolean nmt_newt_widget_get_valid (NmtNewtWidget *widget);
|
||||
gboolean nmt_newt_widget_get_valid(NmtNewtWidget *widget);
|
||||
|
||||
NmtNewtWidget *nmt_newt_widget_find_component (NmtNewtWidget *widget,
|
||||
newtComponent co);
|
||||
NmtNewtWidget *nmt_newt_widget_find_component(NmtNewtWidget *widget, newtComponent co);
|
||||
|
||||
/* protected */
|
||||
void nmt_newt_widget_needs_rebuild (NmtNewtWidget *widget);
|
||||
void nmt_newt_widget_set_valid (NmtNewtWidget *widget,
|
||||
gboolean valid);
|
||||
void nmt_newt_widget_needs_rebuild(NmtNewtWidget *widget);
|
||||
void nmt_newt_widget_set_valid(NmtNewtWidget *widget, gboolean valid);
|
||||
|
||||
#endif /* NMT_NEWT_WIDGET_H */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -6,52 +6,51 @@
|
|||
#ifndef NM_EDITOR_BINDINGS_H
|
||||
#define NM_EDITOR_BINDINGS_H
|
||||
|
||||
void nm_editor_bindings_init (void);
|
||||
void nm_editor_bindings_init(void);
|
||||
|
||||
void nm_editor_bind_ip_addresses_with_prefix_to_strv (int family,
|
||||
gpointer source,
|
||||
const char *source_property,
|
||||
gpointer target,
|
||||
const char *target_property,
|
||||
GBindingFlags flags);
|
||||
void nm_editor_bind_ip_addresses_to_strv (int family,
|
||||
gpointer source,
|
||||
const char *source_property,
|
||||
gpointer target,
|
||||
const char *target_property,
|
||||
GBindingFlags flags);
|
||||
void nm_editor_bind_ip_addresses_with_prefix_to_strv(int family,
|
||||
gpointer source,
|
||||
const char * source_property,
|
||||
gpointer target,
|
||||
const char * target_property,
|
||||
GBindingFlags flags);
|
||||
void nm_editor_bind_ip_addresses_to_strv(int family,
|
||||
gpointer source,
|
||||
const char * source_property,
|
||||
gpointer target,
|
||||
const char * target_property,
|
||||
GBindingFlags flags);
|
||||
|
||||
void nm_editor_bind_ip_gateway_to_string (int family,
|
||||
NMSettingIPConfig *source,
|
||||
gpointer target,
|
||||
const char *target_property,
|
||||
const char *target_sensitive_property,
|
||||
GBindingFlags flags);
|
||||
void nm_editor_bind_ip_gateway_to_string(int family,
|
||||
NMSettingIPConfig *source,
|
||||
gpointer target,
|
||||
const char * target_property,
|
||||
const char * target_sensitive_property,
|
||||
GBindingFlags flags);
|
||||
|
||||
void nm_editor_bind_ip_route_to_strings (int family,
|
||||
gpointer source,
|
||||
const char *source_property,
|
||||
gpointer dest_target,
|
||||
const char *dest_target_property,
|
||||
gpointer next_hop_target,
|
||||
const char *next_hop_target_property,
|
||||
gpointer metric_target,
|
||||
const char *metric_target_property,
|
||||
GBindingFlags flags);
|
||||
void nm_editor_bind_ip_route_to_strings(int family,
|
||||
gpointer source,
|
||||
const char * source_property,
|
||||
gpointer dest_target,
|
||||
const char * dest_target_property,
|
||||
gpointer next_hop_target,
|
||||
const char * next_hop_target_property,
|
||||
gpointer metric_target,
|
||||
const char * metric_target_property,
|
||||
GBindingFlags flags);
|
||||
|
||||
void nm_editor_bind_wireless_security_method (NMConnection *connection,
|
||||
NMSettingWirelessSecurity *s_wsec,
|
||||
gpointer target,
|
||||
const char *target_property,
|
||||
GBindingFlags flags);
|
||||
void nm_editor_bind_wireless_security_wep_key (NMSettingWirelessSecurity *s_wsec,
|
||||
gpointer entry,
|
||||
const char *entry_property,
|
||||
gpointer key_selector,
|
||||
const char *key_selector_property,
|
||||
GBindingFlags flags);
|
||||
void nm_editor_bind_wireless_security_method(NMConnection * connection,
|
||||
NMSettingWirelessSecurity *s_wsec,
|
||||
gpointer target,
|
||||
const char * target_property,
|
||||
GBindingFlags flags);
|
||||
void nm_editor_bind_wireless_security_wep_key(NMSettingWirelessSecurity *s_wsec,
|
||||
gpointer entry,
|
||||
const char * entry_property,
|
||||
gpointer key_selector,
|
||||
const char * key_selector_property,
|
||||
GBindingFlags flags);
|
||||
|
||||
void nm_editor_bind_vlan_name (NMSettingVlan *s_vlan,
|
||||
NMSettingConnection *s_con);
|
||||
void nm_editor_bind_vlan_name(NMSettingVlan *s_vlan, NMSettingConnection *s_con);
|
||||
|
||||
#endif /* NM_EDITOR_BINDINGS_H */
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "nm-editor-utils.h"
|
||||
#if 0
|
||||
#include "nm-vpn-helpers.h"
|
||||
#include "nm-vpn-helpers.h"
|
||||
|
||||
static GSList *vpn_plugins;
|
||||
|
||||
|
|
@ -41,68 +41,61 @@ sort_vpn_plugins (gconstpointer a, gconstpointer b)
|
|||
#endif
|
||||
|
||||
static void
|
||||
wifi_connection_setup_func (NMConnection *connection,
|
||||
NMSettingConnection *s_con,
|
||||
NMSetting *s_hw)
|
||||
wifi_connection_setup_func(NMConnection *connection, NMSettingConnection *s_con, NMSetting *s_hw)
|
||||
{
|
||||
g_object_set (G_OBJECT (s_hw),
|
||||
NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_INFRA,
|
||||
NULL);
|
||||
g_object_set(G_OBJECT(s_hw), NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_INFRA, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
bond_connection_setup_func (NMConnection *connection,
|
||||
NMSettingConnection *s_con,
|
||||
NMSetting *s_hw)
|
||||
bond_connection_setup_func(NMConnection *connection, NMSettingConnection *s_con, NMSetting *s_hw)
|
||||
{
|
||||
NMSettingBond *s_bond = NM_SETTING_BOND (s_hw);
|
||||
guint i;
|
||||
const char *value;
|
||||
static const char *const options[] = {
|
||||
NM_SETTING_BOND_OPTION_MODE,
|
||||
NM_SETTING_BOND_OPTION_MIIMON,
|
||||
NM_SETTING_BOND_OPTION_DOWNDELAY,
|
||||
NM_SETTING_BOND_OPTION_UPDELAY,
|
||||
};
|
||||
NMSettingBond * s_bond = NM_SETTING_BOND(s_hw);
|
||||
guint i;
|
||||
const char * value;
|
||||
static const char *const options[] = {
|
||||
NM_SETTING_BOND_OPTION_MODE,
|
||||
NM_SETTING_BOND_OPTION_MIIMON,
|
||||
NM_SETTING_BOND_OPTION_DOWNDELAY,
|
||||
NM_SETTING_BOND_OPTION_UPDELAY,
|
||||
};
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (options); i++) {
|
||||
value = nm_setting_bond_get_option_default (s_bond, options[i]);
|
||||
if (value)
|
||||
nm_setting_bond_add_option (s_bond, options[i], value);
|
||||
}
|
||||
for (i = 0; i < G_N_ELEMENTS(options); i++) {
|
||||
value = nm_setting_bond_get_option_default(s_bond, options[i]);
|
||||
if (value)
|
||||
nm_setting_bond_add_option(s_bond, options[i], value);
|
||||
}
|
||||
}
|
||||
|
||||
typedef void (*NMEditorNewConnectionSetupFunc) (NMConnection *connection,
|
||||
NMSettingConnection *s_con,
|
||||
NMSetting *s_hw);
|
||||
typedef void (*NMEditorNewConnectionSetupFunc)(NMConnection * connection,
|
||||
NMSettingConnection *s_con,
|
||||
NMSetting * s_hw);
|
||||
|
||||
typedef struct {
|
||||
NMEditorConnectionTypeData data;
|
||||
NMEditorConnectionTypeData data;
|
||||
|
||||
const char *id_format;
|
||||
NMEditorNewConnectionSetupFunc connection_setup_func;
|
||||
gboolean no_autoconnect;
|
||||
const char * id_format;
|
||||
NMEditorNewConnectionSetupFunc connection_setup_func;
|
||||
gboolean no_autoconnect;
|
||||
} NMEditorConnectionTypeDataReal;
|
||||
|
||||
static int
|
||||
sort_types (gconstpointer a, gconstpointer b)
|
||||
sort_types(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
NMEditorConnectionTypeData *typea = *(NMEditorConnectionTypeData **)a;
|
||||
NMEditorConnectionTypeData *typeb = *(NMEditorConnectionTypeData **)b;
|
||||
NMEditorConnectionTypeData *typea = *(NMEditorConnectionTypeData **) a;
|
||||
NMEditorConnectionTypeData *typeb = *(NMEditorConnectionTypeData **) b;
|
||||
|
||||
if (typea->virtual && !typeb->virtual)
|
||||
return 1;
|
||||
else if (typeb->virtual && !typea->virtual)
|
||||
return -1;
|
||||
if (typea->virtual && !typeb->virtual)
|
||||
return 1;
|
||||
else if (typeb->virtual && !typea->virtual)
|
||||
return -1;
|
||||
|
||||
if (typea->setting_type == NM_TYPE_SETTING_VPN &&
|
||||
typeb->setting_type != NM_TYPE_SETTING_VPN)
|
||||
return 1;
|
||||
else if (typeb->setting_type == NM_TYPE_SETTING_VPN &&
|
||||
typea->setting_type != NM_TYPE_SETTING_VPN)
|
||||
return -1;
|
||||
if (typea->setting_type == NM_TYPE_SETTING_VPN && typeb->setting_type != NM_TYPE_SETTING_VPN)
|
||||
return 1;
|
||||
else if (typeb->setting_type == NM_TYPE_SETTING_VPN
|
||||
&& typea->setting_type != NM_TYPE_SETTING_VPN)
|
||||
return -1;
|
||||
|
||||
return g_utf8_collate (typea->name, typeb->name);
|
||||
return g_utf8_collate(typea->name, typeb->name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -116,45 +109,45 @@ sort_types (gconstpointer a, gconstpointer b)
|
|||
* Returns: the array of connection type information
|
||||
*/
|
||||
NMEditorConnectionTypeData **
|
||||
nm_editor_utils_get_connection_type_list (void)
|
||||
nm_editor_utils_get_connection_type_list(void)
|
||||
{
|
||||
GPtrArray *array;
|
||||
NMEditorConnectionTypeDataReal *item;
|
||||
static NMEditorConnectionTypeData **list;
|
||||
GPtrArray * array;
|
||||
NMEditorConnectionTypeDataReal * item;
|
||||
static NMEditorConnectionTypeData **list;
|
||||
#if 0
|
||||
GHashTable *vpn_plugins_hash;
|
||||
gboolean have_vpn_plugins;
|
||||
#endif
|
||||
|
||||
if (list)
|
||||
return list;
|
||||
if (list)
|
||||
return list;
|
||||
|
||||
array = g_ptr_array_new ();
|
||||
array = g_ptr_array_new();
|
||||
|
||||
item = g_new0 (NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("Ethernet");
|
||||
item->data.setting_type = NM_TYPE_SETTING_WIRED;
|
||||
item->data.device_type = NM_TYPE_DEVICE_ETHERNET;
|
||||
item->data.virtual = FALSE;
|
||||
item->id_format = _("Ethernet connection %d");
|
||||
g_ptr_array_add (array, item);
|
||||
item = g_new0(NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("Ethernet");
|
||||
item->data.setting_type = NM_TYPE_SETTING_WIRED;
|
||||
item->data.device_type = NM_TYPE_DEVICE_ETHERNET;
|
||||
item->data.virtual = FALSE;
|
||||
item->id_format = _("Ethernet connection %d");
|
||||
g_ptr_array_add(array, item);
|
||||
|
||||
item = g_new0 (NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("Wi-Fi");
|
||||
item->data.setting_type = NM_TYPE_SETTING_WIRELESS;
|
||||
item->data.device_type = NM_TYPE_DEVICE_WIFI;
|
||||
item->data.virtual = FALSE;
|
||||
item->id_format = _("Wi-Fi connection %d");
|
||||
item->connection_setup_func = wifi_connection_setup_func;
|
||||
g_ptr_array_add (array, item);
|
||||
item = g_new0(NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("Wi-Fi");
|
||||
item->data.setting_type = NM_TYPE_SETTING_WIRELESS;
|
||||
item->data.device_type = NM_TYPE_DEVICE_WIFI;
|
||||
item->data.virtual = FALSE;
|
||||
item->id_format = _("Wi-Fi connection %d");
|
||||
item->connection_setup_func = wifi_connection_setup_func;
|
||||
g_ptr_array_add(array, item);
|
||||
|
||||
item = g_new0 (NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("InfiniBand");
|
||||
item->data.setting_type = NM_TYPE_SETTING_INFINIBAND;
|
||||
item->data.device_type = NM_TYPE_DEVICE_INFINIBAND;
|
||||
item->data.virtual = FALSE;
|
||||
item->id_format = _("InfiniBand connection %d");
|
||||
g_ptr_array_add (array, item);
|
||||
item = g_new0(NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("InfiniBand");
|
||||
item->data.setting_type = NM_TYPE_SETTING_INFINIBAND;
|
||||
item->data.device_type = NM_TYPE_DEVICE_INFINIBAND;
|
||||
item->data.virtual = FALSE;
|
||||
item->id_format = _("InfiniBand connection %d");
|
||||
g_ptr_array_add(array, item);
|
||||
|
||||
#if 0
|
||||
item = g_new0 (NMEditorConnectionTypeDataReal, 1);
|
||||
|
|
@ -166,57 +159,57 @@ nm_editor_utils_get_connection_type_list (void)
|
|||
g_ptr_array_add (array, item);
|
||||
#endif
|
||||
|
||||
item = g_new0 (NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("DSL");
|
||||
item->data.setting_type = NM_TYPE_SETTING_PPPOE;
|
||||
item->data.device_type = NM_TYPE_DEVICE_ETHERNET;
|
||||
item->data.virtual = FALSE;
|
||||
item->id_format = _("DSL connection %d");
|
||||
item->no_autoconnect = TRUE;
|
||||
g_ptr_array_add (array, item);
|
||||
item = g_new0(NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("DSL");
|
||||
item->data.setting_type = NM_TYPE_SETTING_PPPOE;
|
||||
item->data.device_type = NM_TYPE_DEVICE_ETHERNET;
|
||||
item->data.virtual = FALSE;
|
||||
item->id_format = _("DSL connection %d");
|
||||
item->no_autoconnect = TRUE;
|
||||
g_ptr_array_add(array, item);
|
||||
|
||||
item = g_new0 (NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("Bond");
|
||||
item->data.setting_type = NM_TYPE_SETTING_BOND;
|
||||
item->data.device_type = NM_TYPE_DEVICE_BOND;
|
||||
item->data.virtual = TRUE;
|
||||
item->id_format = _("Bond connection %d");
|
||||
item->connection_setup_func = bond_connection_setup_func;
|
||||
g_ptr_array_add (array, item);
|
||||
item = g_new0(NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("Bond");
|
||||
item->data.setting_type = NM_TYPE_SETTING_BOND;
|
||||
item->data.device_type = NM_TYPE_DEVICE_BOND;
|
||||
item->data.virtual = TRUE;
|
||||
item->id_format = _("Bond connection %d");
|
||||
item->connection_setup_func = bond_connection_setup_func;
|
||||
g_ptr_array_add(array, item);
|
||||
|
||||
item = g_new0 (NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("Bridge");
|
||||
item->data.setting_type = NM_TYPE_SETTING_BRIDGE;
|
||||
item->data.slave_setting_type = NM_TYPE_SETTING_BRIDGE_PORT;
|
||||
item->data.device_type = NM_TYPE_DEVICE_BRIDGE;
|
||||
item->data.virtual = TRUE;
|
||||
item->id_format = _("Bridge connection %d");
|
||||
g_ptr_array_add (array, item);
|
||||
item = g_new0(NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("Bridge");
|
||||
item->data.setting_type = NM_TYPE_SETTING_BRIDGE;
|
||||
item->data.slave_setting_type = NM_TYPE_SETTING_BRIDGE_PORT;
|
||||
item->data.device_type = NM_TYPE_DEVICE_BRIDGE;
|
||||
item->data.virtual = TRUE;
|
||||
item->id_format = _("Bridge connection %d");
|
||||
g_ptr_array_add(array, item);
|
||||
|
||||
item = g_new0 (NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("Team");
|
||||
item->data.setting_type = NM_TYPE_SETTING_TEAM;
|
||||
item->data.slave_setting_type = NM_TYPE_SETTING_TEAM_PORT;
|
||||
item->data.device_type = NM_TYPE_DEVICE_TEAM;
|
||||
item->data.virtual = TRUE;
|
||||
item->id_format = _("Team connection %d");
|
||||
g_ptr_array_add (array, item);
|
||||
item = g_new0(NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("Team");
|
||||
item->data.setting_type = NM_TYPE_SETTING_TEAM;
|
||||
item->data.slave_setting_type = NM_TYPE_SETTING_TEAM_PORT;
|
||||
item->data.device_type = NM_TYPE_DEVICE_TEAM;
|
||||
item->data.virtual = TRUE;
|
||||
item->id_format = _("Team connection %d");
|
||||
g_ptr_array_add(array, item);
|
||||
|
||||
item = g_new0 (NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("VLAN");
|
||||
item->data.setting_type = NM_TYPE_SETTING_VLAN;
|
||||
item->data.device_type = NM_TYPE_DEVICE_VLAN;
|
||||
item->data.virtual = TRUE;
|
||||
item->id_format = _("VLAN connection %d");
|
||||
g_ptr_array_add (array, item);
|
||||
item = g_new0(NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("VLAN");
|
||||
item->data.setting_type = NM_TYPE_SETTING_VLAN;
|
||||
item->data.device_type = NM_TYPE_DEVICE_VLAN;
|
||||
item->data.virtual = TRUE;
|
||||
item->id_format = _("VLAN connection %d");
|
||||
g_ptr_array_add(array, item);
|
||||
|
||||
item = g_new0 (NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("IP tunnel");
|
||||
item->data.setting_type = NM_TYPE_SETTING_IP_TUNNEL;
|
||||
item->data.device_type = NM_TYPE_DEVICE_IP_TUNNEL;
|
||||
item->data.virtual = TRUE;
|
||||
item->id_format = _("IP tunnel connection %d");
|
||||
g_ptr_array_add (array, item);
|
||||
item = g_new0(NMEditorConnectionTypeDataReal, 1);
|
||||
item->data.name = _("IP tunnel");
|
||||
item->data.setting_type = NM_TYPE_SETTING_IP_TUNNEL;
|
||||
item->data.device_type = NM_TYPE_DEVICE_IP_TUNNEL;
|
||||
item->data.virtual = TRUE;
|
||||
item->id_format = _("IP tunnel connection %d");
|
||||
g_ptr_array_add(array, item);
|
||||
|
||||
#if 0
|
||||
/* Add "VPN" only if there are plugins */
|
||||
|
|
@ -242,94 +235,92 @@ nm_editor_utils_get_connection_type_list (void)
|
|||
}
|
||||
#endif
|
||||
|
||||
g_ptr_array_sort (array, sort_types);
|
||||
g_ptr_array_add (array, NULL);
|
||||
g_ptr_array_sort(array, sort_types);
|
||||
g_ptr_array_add(array, NULL);
|
||||
|
||||
list = (NMEditorConnectionTypeData **)g_ptr_array_free (array, FALSE);
|
||||
return list;
|
||||
list = (NMEditorConnectionTypeData **) g_ptr_array_free(array, FALSE);
|
||||
return list;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_assert_format_int (const char *format)
|
||||
_assert_format_int(const char *format)
|
||||
{
|
||||
g_assert (format);
|
||||
format = strchr (format, '%');
|
||||
g_assert (format);
|
||||
format++;
|
||||
g_assert (!strchr (format, '%'));
|
||||
g_assert (format[0] == 'd');
|
||||
return TRUE;
|
||||
g_assert(format);
|
||||
format = strchr(format, '%');
|
||||
g_assert(format);
|
||||
format++;
|
||||
g_assert(!strchr(format, '%'));
|
||||
g_assert(format[0] == 'd');
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static char *
|
||||
get_available_connection_name (const char *format,
|
||||
NMClient *client)
|
||||
get_available_connection_name(const char *format, NMClient *client)
|
||||
{
|
||||
const GPtrArray *conns;
|
||||
GSList *names = NULL, *iter;
|
||||
char *cname = NULL;
|
||||
int i = 0;
|
||||
const GPtrArray *conns;
|
||||
GSList * names = NULL, *iter;
|
||||
char * cname = NULL;
|
||||
int i = 0;
|
||||
|
||||
nm_assert (_assert_format_int (format));
|
||||
nm_assert(_assert_format_int(format));
|
||||
|
||||
conns = nm_client_get_connections (client);
|
||||
for (i = 0; i < conns->len; i++) {
|
||||
const char *id;
|
||||
conns = nm_client_get_connections(client);
|
||||
for (i = 0; i < conns->len; i++) {
|
||||
const char *id;
|
||||
|
||||
id = nm_connection_get_id (NM_CONNECTION (conns->pdata[i]));
|
||||
g_assert (id);
|
||||
names = g_slist_append (names, (gpointer) id);
|
||||
}
|
||||
id = nm_connection_get_id(NM_CONNECTION(conns->pdata[i]));
|
||||
g_assert(id);
|
||||
names = g_slist_append(names, (gpointer) id);
|
||||
}
|
||||
|
||||
/* Find the next available unique connection name */
|
||||
for (i = 1; !cname && i < 10000; i++) {
|
||||
char *temp;
|
||||
gboolean found = FALSE;
|
||||
/* Find the next available unique connection name */
|
||||
for (i = 1; !cname && i < 10000; i++) {
|
||||
char * temp;
|
||||
gboolean found = FALSE;
|
||||
|
||||
NM_PRAGMA_WARNING_DISABLE("-Wformat-nonliteral")
|
||||
temp = g_strdup_printf (format, i);
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
for (iter = names; iter; iter = g_slist_next (iter)) {
|
||||
if (!strcmp (iter->data, temp)) {
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
cname = temp;
|
||||
else
|
||||
g_free (temp);
|
||||
}
|
||||
NM_PRAGMA_WARNING_DISABLE("-Wformat-nonliteral")
|
||||
temp = g_strdup_printf(format, i);
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
for (iter = names; iter; iter = g_slist_next(iter)) {
|
||||
if (!strcmp(iter->data, temp)) {
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
cname = temp;
|
||||
else
|
||||
g_free(temp);
|
||||
}
|
||||
|
||||
g_slist_free (names);
|
||||
return cname;
|
||||
g_slist_free(names);
|
||||
return cname;
|
||||
}
|
||||
|
||||
static char *
|
||||
get_available_iface_name (const char *try_name,
|
||||
NMClient *client)
|
||||
get_available_iface_name(const char *try_name, NMClient *client)
|
||||
{
|
||||
const GPtrArray *connections;
|
||||
NMConnection *connection;
|
||||
char *new_name;
|
||||
unsigned num = 1;
|
||||
int i = 0;
|
||||
const char *ifname = NULL;
|
||||
const GPtrArray *connections;
|
||||
NMConnection * connection;
|
||||
char * new_name;
|
||||
unsigned num = 1;
|
||||
int i = 0;
|
||||
const char * ifname = NULL;
|
||||
|
||||
connections = nm_client_get_connections (client);
|
||||
connections = nm_client_get_connections(client);
|
||||
|
||||
new_name = g_strdup (try_name);
|
||||
while (i < connections->len) {
|
||||
connection = NM_CONNECTION (connections->pdata[i]);
|
||||
ifname = nm_connection_get_interface_name (connection);
|
||||
if (g_strcmp0 (new_name, ifname) == 0) {
|
||||
g_free (new_name);
|
||||
new_name = g_strdup_printf ("%s%d", try_name, num++);
|
||||
i = 0;
|
||||
} else
|
||||
i++;
|
||||
}
|
||||
return new_name;
|
||||
new_name = g_strdup(try_name);
|
||||
while (i < connections->len) {
|
||||
connection = NM_CONNECTION(connections->pdata[i]);
|
||||
ifname = nm_connection_get_interface_name(connection);
|
||||
if (g_strcmp0(new_name, ifname) == 0) {
|
||||
g_free(new_name);
|
||||
new_name = g_strdup_printf("%s%d", try_name, num++);
|
||||
i = 0;
|
||||
} else
|
||||
i++;
|
||||
}
|
||||
return new_name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -348,85 +339,89 @@ get_available_iface_name (const char *try_name,
|
|||
* Returns: a new #NMConnection
|
||||
*/
|
||||
NMConnection *
|
||||
nm_editor_utils_create_connection (GType type,
|
||||
NMConnection *master,
|
||||
NMClient *client)
|
||||
nm_editor_utils_create_connection(GType type, NMConnection *master, NMClient *client)
|
||||
{
|
||||
NMEditorConnectionTypeData **types;
|
||||
NMEditorConnectionTypeDataReal *type_data = NULL;
|
||||
const char *master_setting_type = NULL, *master_uuid = NULL;
|
||||
GType master_type = G_TYPE_INVALID, slave_setting_type = G_TYPE_INVALID;
|
||||
NMConnection *connection;
|
||||
NMSettingConnection *s_con;
|
||||
NMSetting *s_hw, *s_slave;
|
||||
char *uuid, *id, *ifname;
|
||||
int i;
|
||||
NMEditorConnectionTypeData ** types;
|
||||
NMEditorConnectionTypeDataReal *type_data = NULL;
|
||||
const char * master_setting_type = NULL, *master_uuid = NULL;
|
||||
GType master_type = G_TYPE_INVALID, slave_setting_type = G_TYPE_INVALID;
|
||||
NMConnection * connection;
|
||||
NMSettingConnection *s_con;
|
||||
NMSetting * s_hw, *s_slave;
|
||||
char * uuid, *id, *ifname;
|
||||
int i;
|
||||
|
||||
if (master) {
|
||||
NMSettingConnection *master_s_con;
|
||||
if (master) {
|
||||
NMSettingConnection *master_s_con;
|
||||
|
||||
master_s_con = nm_connection_get_setting_connection (master);
|
||||
master_setting_type = nm_setting_connection_get_connection_type (master_s_con);
|
||||
master_uuid = nm_setting_connection_get_uuid (master_s_con);
|
||||
master_type = nm_setting_lookup_type (master_setting_type);
|
||||
}
|
||||
master_s_con = nm_connection_get_setting_connection(master);
|
||||
master_setting_type = nm_setting_connection_get_connection_type(master_s_con);
|
||||
master_uuid = nm_setting_connection_get_uuid(master_s_con);
|
||||
master_type = nm_setting_lookup_type(master_setting_type);
|
||||
}
|
||||
|
||||
types = nm_editor_utils_get_connection_type_list ();
|
||||
for (i = 0; types[i]; i++) {
|
||||
if (types[i]->setting_type == type)
|
||||
type_data = (NMEditorConnectionTypeDataReal *)types[i];
|
||||
if (types[i]->setting_type == master_type)
|
||||
slave_setting_type = types[i]->slave_setting_type;
|
||||
types = nm_editor_utils_get_connection_type_list();
|
||||
for (i = 0; types[i]; i++) {
|
||||
if (types[i]->setting_type == type)
|
||||
type_data = (NMEditorConnectionTypeDataReal *) types[i];
|
||||
if (types[i]->setting_type == master_type)
|
||||
slave_setting_type = types[i]->slave_setting_type;
|
||||
}
|
||||
if (!type_data) {
|
||||
g_return_val_if_reached(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
if (!type_data) {
|
||||
g_return_val_if_reached (NULL);
|
||||
return NULL;
|
||||
}
|
||||
connection = nm_simple_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));
|
||||
|
||||
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_con));
|
||||
s_hw = g_object_new(type, NULL);
|
||||
nm_connection_add_setting(connection, s_hw);
|
||||
|
||||
s_hw = g_object_new (type, NULL);
|
||||
nm_connection_add_setting (connection, s_hw);
|
||||
if (type == NM_TYPE_SETTING_BOND)
|
||||
ifname = get_available_iface_name("nm-bond", client);
|
||||
else if (type == NM_TYPE_SETTING_TEAM)
|
||||
ifname = get_available_iface_name("nm-team", client);
|
||||
else if (type == NM_TYPE_SETTING_BRIDGE)
|
||||
ifname = get_available_iface_name("nm-bridge", client);
|
||||
else
|
||||
ifname = NULL;
|
||||
|
||||
if (type == NM_TYPE_SETTING_BOND)
|
||||
ifname = get_available_iface_name ("nm-bond", client);
|
||||
else if (type == NM_TYPE_SETTING_TEAM)
|
||||
ifname = get_available_iface_name ("nm-team", client);
|
||||
else if (type == NM_TYPE_SETTING_BRIDGE)
|
||||
ifname = get_available_iface_name ("nm-bridge", client);
|
||||
else
|
||||
ifname = NULL;
|
||||
if (slave_setting_type != G_TYPE_INVALID) {
|
||||
s_slave = g_object_new(slave_setting_type, NULL);
|
||||
nm_connection_add_setting(connection, s_slave);
|
||||
}
|
||||
|
||||
if (slave_setting_type != G_TYPE_INVALID) {
|
||||
s_slave = g_object_new (slave_setting_type, NULL);
|
||||
nm_connection_add_setting (connection, s_slave);
|
||||
}
|
||||
uuid = nm_utils_uuid_generate();
|
||||
id = get_available_connection_name(type_data->id_format, client);
|
||||
|
||||
uuid = nm_utils_uuid_generate ();
|
||||
id = get_available_connection_name (type_data->id_format, client);
|
||||
g_object_set(s_con,
|
||||
NM_SETTING_CONNECTION_UUID,
|
||||
uuid,
|
||||
NM_SETTING_CONNECTION_ID,
|
||||
id,
|
||||
NM_SETTING_CONNECTION_TYPE,
|
||||
nm_setting_get_name(s_hw),
|
||||
NM_SETTING_CONNECTION_AUTOCONNECT,
|
||||
!type_data->no_autoconnect,
|
||||
NM_SETTING_CONNECTION_MASTER,
|
||||
master_uuid,
|
||||
NM_SETTING_CONNECTION_SLAVE_TYPE,
|
||||
master_setting_type,
|
||||
NM_SETTING_CONNECTION_INTERFACE_NAME,
|
||||
ifname,
|
||||
NULL);
|
||||
|
||||
g_object_set (s_con,
|
||||
NM_SETTING_CONNECTION_UUID, uuid,
|
||||
NM_SETTING_CONNECTION_ID, id,
|
||||
NM_SETTING_CONNECTION_TYPE, nm_setting_get_name (s_hw),
|
||||
NM_SETTING_CONNECTION_AUTOCONNECT, !type_data->no_autoconnect,
|
||||
NM_SETTING_CONNECTION_MASTER, master_uuid,
|
||||
NM_SETTING_CONNECTION_SLAVE_TYPE, master_setting_type,
|
||||
NM_SETTING_CONNECTION_INTERFACE_NAME, ifname,
|
||||
NULL);
|
||||
g_free(uuid);
|
||||
g_free(id);
|
||||
g_free(ifname);
|
||||
|
||||
g_free (uuid);
|
||||
g_free (id);
|
||||
g_free (ifname);
|
||||
if (type_data->connection_setup_func)
|
||||
type_data->connection_setup_func(connection, s_con, s_hw);
|
||||
|
||||
if (type_data->connection_setup_func)
|
||||
type_data->connection_setup_func (connection, s_con, s_hw);
|
||||
|
||||
return connection;
|
||||
return connection;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -439,26 +434,26 @@ nm_editor_utils_create_connection (GType type,
|
|||
* Returns: the #NMEditorConnectionTypeData
|
||||
*/
|
||||
NMEditorConnectionTypeData *
|
||||
nm_editor_utils_get_connection_type_data (NMConnection *conn)
|
||||
nm_editor_utils_get_connection_type_data(NMConnection *conn)
|
||||
{
|
||||
NMSettingConnection *s_con;
|
||||
const char *conn_type;
|
||||
GType conn_gtype;
|
||||
NMEditorConnectionTypeData **types;
|
||||
int i;
|
||||
NMSettingConnection * s_con;
|
||||
const char * conn_type;
|
||||
GType conn_gtype;
|
||||
NMEditorConnectionTypeData **types;
|
||||
int i;
|
||||
|
||||
s_con = nm_connection_get_setting_connection (conn);
|
||||
g_return_val_if_fail (s_con != NULL, NULL);
|
||||
s_con = nm_connection_get_setting_connection(conn);
|
||||
g_return_val_if_fail(s_con != NULL, NULL);
|
||||
|
||||
conn_type = nm_setting_connection_get_connection_type (s_con);
|
||||
conn_gtype = nm_setting_lookup_type (conn_type);
|
||||
g_return_val_if_fail (conn_gtype != G_TYPE_INVALID, NULL);
|
||||
conn_type = nm_setting_connection_get_connection_type(s_con);
|
||||
conn_gtype = nm_setting_lookup_type(conn_type);
|
||||
g_return_val_if_fail(conn_gtype != G_TYPE_INVALID, NULL);
|
||||
|
||||
types = nm_editor_utils_get_connection_type_list ();
|
||||
for (i = 0; types[i]; i++) {
|
||||
if (types[i]->setting_type == conn_gtype)
|
||||
return types[i];
|
||||
}
|
||||
types = nm_editor_utils_get_connection_type_list();
|
||||
for (i = 0; types[i]; i++) {
|
||||
if (types[i]->setting_type == conn_gtype)
|
||||
return types[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,18 +7,16 @@
|
|||
#define NM_EDITOR_UTILS_H
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
GType setting_type;
|
||||
GType slave_setting_type;
|
||||
GType device_type;
|
||||
gboolean virtual;
|
||||
const char *name;
|
||||
GType setting_type;
|
||||
GType slave_setting_type;
|
||||
GType device_type;
|
||||
gboolean virtual;
|
||||
} NMEditorConnectionTypeData;
|
||||
|
||||
NMEditorConnectionTypeData **nm_editor_utils_get_connection_type_list (void);
|
||||
NMEditorConnectionTypeData *nm_editor_utils_get_connection_type_data (NMConnection *conn);
|
||||
NMEditorConnectionTypeData **nm_editor_utils_get_connection_type_list(void);
|
||||
NMEditorConnectionTypeData * nm_editor_utils_get_connection_type_data(NMConnection *conn);
|
||||
|
||||
NMConnection *nm_editor_utils_create_connection (GType type,
|
||||
NMConnection *master,
|
||||
NMClient *client);
|
||||
NMConnection *nm_editor_utils_create_connection(GType type, NMConnection *master, NMClient *client);
|
||||
|
||||
#endif /* NM_EDITOR_UTILS_H */
|
||||
|
|
|
|||
|
|
@ -25,21 +25,22 @@
|
|||
|
||||
#include "nmt-ip-entry.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtAddressList, nmt_address_list, NMT_TYPE_WIDGET_LIST)
|
||||
G_DEFINE_TYPE(NmtAddressList, nmt_address_list, NMT_TYPE_WIDGET_LIST)
|
||||
|
||||
#define NMT_ADDRESS_LIST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_ADDRESS_LIST, NmtAddressListPrivate))
|
||||
#define NMT_ADDRESS_LIST_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_ADDRESS_LIST, NmtAddressListPrivate))
|
||||
|
||||
typedef struct {
|
||||
NmtAddressListType list_type;
|
||||
char **strings;
|
||||
NmtAddressListType list_type;
|
||||
char ** strings;
|
||||
} NmtAddressListPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_LIST_TYPE,
|
||||
PROP_STRINGS,
|
||||
PROP_0,
|
||||
PROP_LIST_TYPE,
|
||||
PROP_STRINGS,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -62,209 +63,204 @@ enum {
|
|||
* Returns: a new #NmtAddressList
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_address_list_new (NmtAddressListType list_type)
|
||||
nmt_address_list_new(NmtAddressListType list_type)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_ADDRESS_LIST,
|
||||
"list-type", list_type,
|
||||
NULL);
|
||||
return g_object_new(NMT_TYPE_ADDRESS_LIST, "list-type", list_type, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_address_list_init (NmtAddressList *list)
|
||||
nmt_address_list_init(NmtAddressList *list)
|
||||
{}
|
||||
|
||||
static gboolean
|
||||
strings_transform_to_entry(GBinding * binding,
|
||||
const GValue *source_value,
|
||||
GValue * target_value,
|
||||
gpointer user_data)
|
||||
{
|
||||
int n = GPOINTER_TO_INT(user_data);
|
||||
char **strings;
|
||||
|
||||
strings = g_value_get_boxed(source_value);
|
||||
if (n >= g_strv_length(strings))
|
||||
return FALSE;
|
||||
|
||||
g_value_set_string(target_value, strings[n]);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
strings_transform_to_entry (GBinding *binding,
|
||||
const GValue *source_value,
|
||||
GValue *target_value,
|
||||
gpointer user_data)
|
||||
strings_transform_from_entry(GBinding * binding,
|
||||
const GValue *source_value,
|
||||
GValue * target_value,
|
||||
gpointer user_data)
|
||||
{
|
||||
int n = GPOINTER_TO_INT (user_data);
|
||||
char **strings;
|
||||
NmtAddressList * list = NMT_ADDRESS_LIST(g_binding_get_source(binding));
|
||||
NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE(list);
|
||||
int n = GPOINTER_TO_INT(user_data);
|
||||
|
||||
strings = g_value_get_boxed (source_value);
|
||||
if (n >= g_strv_length (strings))
|
||||
return FALSE;
|
||||
if (n >= g_strv_length(priv->strings))
|
||||
return FALSE;
|
||||
|
||||
g_value_set_string (target_value, strings[n]);
|
||||
return TRUE;
|
||||
g_free(priv->strings[n]);
|
||||
priv->strings[n] = g_value_dup_string(source_value);
|
||||
|
||||
g_value_set_boxed(target_value, priv->strings);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
strings_transform_from_entry (GBinding *binding,
|
||||
const GValue *source_value,
|
||||
GValue *target_value,
|
||||
gpointer user_data)
|
||||
hostname_filter(NmtNewtEntry *entry, const char *text, int ch, int position, gpointer user_data)
|
||||
{
|
||||
NmtAddressList *list = NMT_ADDRESS_LIST (g_binding_get_source (binding));
|
||||
NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE (list);
|
||||
int n = GPOINTER_TO_INT (user_data);
|
||||
|
||||
if (n >= g_strv_length (priv->strings))
|
||||
return FALSE;
|
||||
|
||||
g_free (priv->strings[n]);
|
||||
priv->strings[n] = g_value_dup_string (source_value);
|
||||
|
||||
g_value_set_boxed (target_value, priv->strings);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
hostname_filter (NmtNewtEntry *entry,
|
||||
const char *text,
|
||||
int ch,
|
||||
int position,
|
||||
gpointer user_data)
|
||||
{
|
||||
return g_ascii_isalnum (ch) || ch == '.' || ch == '-';
|
||||
return g_ascii_isalnum(ch) || ch == '.' || ch == '-';
|
||||
}
|
||||
|
||||
static NmtNewtWidget *
|
||||
nmt_address_list_create_widget (NmtWidgetList *list,
|
||||
int num)
|
||||
nmt_address_list_create_widget(NmtWidgetList *list, int num)
|
||||
{
|
||||
NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE (list);
|
||||
NmtNewtWidget *entry;
|
||||
NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE(list);
|
||||
NmtNewtWidget * entry;
|
||||
|
||||
if (priv->list_type == NMT_ADDRESS_LIST_IP4_WITH_PREFIX)
|
||||
entry = nmt_ip_entry_new (25, AF_INET, TRUE, FALSE);
|
||||
else if (priv->list_type == NMT_ADDRESS_LIST_IP4)
|
||||
entry = nmt_ip_entry_new (25, AF_INET, FALSE, FALSE);
|
||||
else if (priv->list_type == NMT_ADDRESS_LIST_IP6_WITH_PREFIX)
|
||||
entry = nmt_ip_entry_new (25, AF_INET6, TRUE, FALSE);
|
||||
else if (priv->list_type == NMT_ADDRESS_LIST_IP6)
|
||||
entry = nmt_ip_entry_new (25, AF_INET6, FALSE, FALSE);
|
||||
else if (priv->list_type == NMT_ADDRESS_LIST_HOSTNAME) {
|
||||
entry = nmt_newt_entry_new (25, NMT_NEWT_ENTRY_NONEMPTY);
|
||||
nmt_newt_entry_set_filter (NMT_NEWT_ENTRY (entry), hostname_filter, list);
|
||||
} else
|
||||
g_assert_not_reached ();
|
||||
if (priv->list_type == NMT_ADDRESS_LIST_IP4_WITH_PREFIX)
|
||||
entry = nmt_ip_entry_new(25, AF_INET, TRUE, FALSE);
|
||||
else if (priv->list_type == NMT_ADDRESS_LIST_IP4)
|
||||
entry = nmt_ip_entry_new(25, AF_INET, FALSE, FALSE);
|
||||
else if (priv->list_type == NMT_ADDRESS_LIST_IP6_WITH_PREFIX)
|
||||
entry = nmt_ip_entry_new(25, AF_INET6, TRUE, FALSE);
|
||||
else if (priv->list_type == NMT_ADDRESS_LIST_IP6)
|
||||
entry = nmt_ip_entry_new(25, AF_INET6, FALSE, FALSE);
|
||||
else if (priv->list_type == NMT_ADDRESS_LIST_HOSTNAME) {
|
||||
entry = nmt_newt_entry_new(25, NMT_NEWT_ENTRY_NONEMPTY);
|
||||
nmt_newt_entry_set_filter(NMT_NEWT_ENTRY(entry), hostname_filter, list);
|
||||
} else
|
||||
g_assert_not_reached();
|
||||
|
||||
g_object_bind_property_full (list, "strings", entry, "text",
|
||||
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
|
||||
strings_transform_to_entry,
|
||||
strings_transform_from_entry,
|
||||
GINT_TO_POINTER (num), NULL);
|
||||
g_object_bind_property_full(list,
|
||||
"strings",
|
||||
entry,
|
||||
"text",
|
||||
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
|
||||
strings_transform_to_entry,
|
||||
strings_transform_from_entry,
|
||||
GINT_TO_POINTER(num),
|
||||
NULL);
|
||||
|
||||
return entry;
|
||||
return entry;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_address_list_add_clicked (NmtWidgetList *list)
|
||||
nmt_address_list_add_clicked(NmtWidgetList *list)
|
||||
{
|
||||
NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE (list);
|
||||
int len;
|
||||
NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE(list);
|
||||
int len;
|
||||
|
||||
len = priv->strings ? g_strv_length (priv->strings) : 0;
|
||||
priv->strings = g_renew (char *, priv->strings, len + 2);
|
||||
priv->strings[len] = g_strdup ("");
|
||||
priv->strings[len + 1] = NULL;
|
||||
len = priv->strings ? g_strv_length(priv->strings) : 0;
|
||||
priv->strings = g_renew(char *, priv->strings, len + 2);
|
||||
priv->strings[len] = g_strdup("");
|
||||
priv->strings[len + 1] = NULL;
|
||||
|
||||
nmt_widget_list_set_length (list, len + 1);
|
||||
g_object_notify (G_OBJECT (list), "strings");
|
||||
nmt_widget_list_set_length(list, len + 1);
|
||||
g_object_notify(G_OBJECT(list), "strings");
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_address_list_remove_clicked (NmtWidgetList *list,
|
||||
int num)
|
||||
nmt_address_list_remove_clicked(NmtWidgetList *list, int num)
|
||||
{
|
||||
NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE (list);
|
||||
int len;
|
||||
NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE(list);
|
||||
int len;
|
||||
|
||||
len = g_strv_length (priv->strings);
|
||||
g_free (priv->strings[num]);
|
||||
memmove (priv->strings + num, priv->strings + num + 1, (len - num) * sizeof (char *));
|
||||
len = g_strv_length(priv->strings);
|
||||
g_free(priv->strings[num]);
|
||||
memmove(priv->strings + num, priv->strings + num + 1, (len - num) * sizeof(char *));
|
||||
|
||||
nmt_widget_list_set_length (list, len - 1);
|
||||
g_object_notify (G_OBJECT (list), "strings");
|
||||
nmt_widget_list_set_length(list, len - 1);
|
||||
g_object_notify(G_OBJECT(list), "strings");
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_address_list_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_address_list_set_property(GObject * object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE (object);
|
||||
NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_LIST_TYPE:
|
||||
priv->list_type = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_STRINGS:
|
||||
g_strfreev (priv->strings);
|
||||
priv->strings = g_value_dup_boxed (value);
|
||||
if (!priv->strings)
|
||||
priv->strings = g_new0 (char *, 1);
|
||||
nmt_widget_list_set_length (NMT_WIDGET_LIST (object),
|
||||
g_strv_length (priv->strings));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_LIST_TYPE:
|
||||
priv->list_type = g_value_get_uint(value);
|
||||
break;
|
||||
case PROP_STRINGS:
|
||||
g_strfreev(priv->strings);
|
||||
priv->strings = g_value_dup_boxed(value);
|
||||
if (!priv->strings)
|
||||
priv->strings = g_new0(char *, 1);
|
||||
nmt_widget_list_set_length(NMT_WIDGET_LIST(object), g_strv_length(priv->strings));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_address_list_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_address_list_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE (object);
|
||||
NmtAddressListPrivate *priv = NMT_ADDRESS_LIST_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_LIST_TYPE:
|
||||
g_value_set_uint (value, priv->list_type);
|
||||
break;
|
||||
case PROP_STRINGS:
|
||||
g_value_set_boxed (value, priv->strings);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_LIST_TYPE:
|
||||
g_value_set_uint(value, priv->list_type);
|
||||
break;
|
||||
case PROP_STRINGS:
|
||||
g_value_set_boxed(value, priv->strings);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_address_list_class_init (NmtAddressListClass *list_class)
|
||||
nmt_address_list_class_init(NmtAddressListClass *list_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (list_class);
|
||||
NmtWidgetListClass *widget_list_class = NMT_WIDGET_LIST_CLASS (list_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(list_class);
|
||||
NmtWidgetListClass *widget_list_class = NMT_WIDGET_LIST_CLASS(list_class);
|
||||
|
||||
g_type_class_add_private (list_class, sizeof (NmtAddressListPrivate));
|
||||
g_type_class_add_private(list_class, sizeof(NmtAddressListPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_address_list_set_property;
|
||||
object_class->get_property = nmt_address_list_get_property;
|
||||
/* virtual methods */
|
||||
object_class->set_property = nmt_address_list_set_property;
|
||||
object_class->get_property = nmt_address_list_get_property;
|
||||
|
||||
widget_list_class->create_widget = nmt_address_list_create_widget;
|
||||
widget_list_class->add_clicked = nmt_address_list_add_clicked;
|
||||
widget_list_class->remove_clicked = nmt_address_list_remove_clicked;
|
||||
widget_list_class->create_widget = nmt_address_list_create_widget;
|
||||
widget_list_class->add_clicked = nmt_address_list_add_clicked;
|
||||
widget_list_class->remove_clicked = nmt_address_list_remove_clicked;
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtAddressList:list-type:
|
||||
*
|
||||
* The type of address the list holds.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_LIST_TYPE,
|
||||
g_param_spec_uint ("list-type", "", "",
|
||||
0, G_MAXUINT, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_LIST_TYPE,
|
||||
g_param_spec_uint("list-type",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
G_MAXUINT,
|
||||
0,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtAddressList:strings:
|
||||
*
|
||||
* The strings in the list's entries.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_STRINGS,
|
||||
g_param_spec_boxed ("strings", "", "",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(object_class,
|
||||
PROP_STRINGS,
|
||||
g_param_spec_boxed("strings",
|
||||
"",
|
||||
"",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,33 +8,36 @@
|
|||
|
||||
#include "nmt-widget-list.h"
|
||||
|
||||
#define NMT_TYPE_ADDRESS_LIST (nmt_address_list_get_type ())
|
||||
#define NMT_ADDRESS_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_ADDRESS_LIST, NmtAddressList))
|
||||
#define NMT_ADDRESS_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_ADDRESS_LIST, NmtAddressListClass))
|
||||
#define NMT_IS_ADDRESS_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_ADDRESS_LIST))
|
||||
#define NMT_IS_ADDRESS_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_ADDRESS_LIST))
|
||||
#define NMT_ADDRESS_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_ADDRESS_LIST, NmtAddressListClass))
|
||||
#define NMT_TYPE_ADDRESS_LIST (nmt_address_list_get_type())
|
||||
#define NMT_ADDRESS_LIST(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_ADDRESS_LIST, NmtAddressList))
|
||||
#define NMT_ADDRESS_LIST_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_ADDRESS_LIST, NmtAddressListClass))
|
||||
#define NMT_IS_ADDRESS_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_ADDRESS_LIST))
|
||||
#define NMT_IS_ADDRESS_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_ADDRESS_LIST))
|
||||
#define NMT_ADDRESS_LIST_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_ADDRESS_LIST, NmtAddressListClass))
|
||||
|
||||
typedef struct {
|
||||
NmtWidgetList parent;
|
||||
NmtWidgetList parent;
|
||||
|
||||
} NmtAddressList;
|
||||
|
||||
typedef struct {
|
||||
NmtWidgetListClass parent;
|
||||
NmtWidgetListClass parent;
|
||||
|
||||
} NmtAddressListClass;
|
||||
|
||||
GType nmt_address_list_get_type (void);
|
||||
GType nmt_address_list_get_type(void);
|
||||
|
||||
typedef enum {
|
||||
NMT_ADDRESS_LIST_IP4_WITH_PREFIX,
|
||||
NMT_ADDRESS_LIST_IP4,
|
||||
NMT_ADDRESS_LIST_IP6_WITH_PREFIX,
|
||||
NMT_ADDRESS_LIST_IP6,
|
||||
NMT_ADDRESS_LIST_HOSTNAME
|
||||
NMT_ADDRESS_LIST_IP4_WITH_PREFIX,
|
||||
NMT_ADDRESS_LIST_IP4,
|
||||
NMT_ADDRESS_LIST_IP6_WITH_PREFIX,
|
||||
NMT_ADDRESS_LIST_IP6,
|
||||
NMT_ADDRESS_LIST_HOSTNAME
|
||||
} NmtAddressListType;
|
||||
|
||||
NmtNewtWidget *nmt_address_list_new (NmtAddressListType list_type);
|
||||
NmtNewtWidget *nmt_address_list_new(NmtAddressListType list_type);
|
||||
|
||||
#endif /* NMT_ADDRESS_LIST_H */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -8,37 +8,46 @@
|
|||
|
||||
#include "nmt-newt.h"
|
||||
|
||||
#define NMT_TYPE_CONNECT_CONNECTION_LIST (nmt_connect_connection_list_get_type ())
|
||||
#define NMT_CONNECT_CONNECTION_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_CONNECT_CONNECTION_LIST, NmtConnectConnectionList))
|
||||
#define NMT_CONNECT_CONNECTION_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_CONNECT_CONNECTION_LIST, NmtConnectConnectionListClass))
|
||||
#define NMT_IS_CONNECT_CONNECTION_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_CONNECT_CONNECTION_LIST))
|
||||
#define NMT_IS_CONNECT_CONNECTION_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_CONNECT_CONNECTION_LIST))
|
||||
#define NMT_CONNECT_CONNECTION_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_CONNECT_CONNECTION_LIST, NmtConnectConnectionListClass))
|
||||
#define NMT_TYPE_CONNECT_CONNECTION_LIST (nmt_connect_connection_list_get_type())
|
||||
#define NMT_CONNECT_CONNECTION_LIST(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_CONNECT_CONNECTION_LIST, NmtConnectConnectionList))
|
||||
#define NMT_CONNECT_CONNECTION_LIST_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), \
|
||||
NMT_TYPE_CONNECT_CONNECTION_LIST, \
|
||||
NmtConnectConnectionListClass))
|
||||
#define NMT_IS_CONNECT_CONNECTION_LIST(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_CONNECT_CONNECTION_LIST))
|
||||
#define NMT_IS_CONNECT_CONNECTION_LIST_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_CONNECT_CONNECTION_LIST))
|
||||
#define NMT_CONNECT_CONNECTION_LIST_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), \
|
||||
NMT_TYPE_CONNECT_CONNECTION_LIST, \
|
||||
NmtConnectConnectionListClass))
|
||||
|
||||
typedef struct {
|
||||
NmtNewtListbox parent;
|
||||
NmtNewtListbox parent;
|
||||
|
||||
} NmtConnectConnectionList;
|
||||
|
||||
typedef struct {
|
||||
NmtNewtListboxClass parent;
|
||||
NmtNewtListboxClass parent;
|
||||
|
||||
} NmtConnectConnectionListClass;
|
||||
|
||||
GType nmt_connect_connection_list_get_type (void);
|
||||
GType nmt_connect_connection_list_get_type(void);
|
||||
|
||||
NmtNewtWidget *nmt_connect_connection_list_new (void);
|
||||
NmtNewtWidget *nmt_connect_connection_list_new(void);
|
||||
|
||||
gboolean nmt_connect_connection_list_get_connection (NmtConnectConnectionList *list,
|
||||
const char *identifier,
|
||||
NMConnection **connection,
|
||||
NMDevice **device,
|
||||
NMObject **specific_object,
|
||||
NMActiveConnection **active);
|
||||
gboolean nmt_connect_connection_list_get_selection (NmtConnectConnectionList *list,
|
||||
NMConnection **connection,
|
||||
NMDevice **device,
|
||||
NMObject **specific_object,
|
||||
NMActiveConnection **active);
|
||||
gboolean nmt_connect_connection_list_get_connection(NmtConnectConnectionList *list,
|
||||
const char * identifier,
|
||||
NMConnection ** connection,
|
||||
NMDevice ** device,
|
||||
NMObject ** specific_object,
|
||||
NMActiveConnection ** active);
|
||||
gboolean nmt_connect_connection_list_get_selection(NmtConnectConnectionList *list,
|
||||
NMConnection ** connection,
|
||||
NMDevice ** device,
|
||||
NMObject ** specific_object,
|
||||
NMActiveConnection ** active);
|
||||
|
||||
#endif /* NMT_CONNECT_CONNECTION_LIST_H */
|
||||
|
|
|
|||
|
|
@ -30,35 +30,36 @@
|
|||
|
||||
#include "nmtui.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtDeviceEntry, nmt_device_entry, NMT_TYPE_EDITOR_GRID)
|
||||
G_DEFINE_TYPE(NmtDeviceEntry, nmt_device_entry, NMT_TYPE_EDITOR_GRID)
|
||||
|
||||
#define NMT_DEVICE_ENTRY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_DEVICE_ENTRY, NmtDeviceEntryPrivate))
|
||||
#define NMT_DEVICE_ENTRY_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_DEVICE_ENTRY, NmtDeviceEntryPrivate))
|
||||
|
||||
typedef struct {
|
||||
GType hardware_type;
|
||||
NmtDeviceEntryDeviceFilter device_filter;
|
||||
gpointer device_filter_data;
|
||||
int arptype;
|
||||
GType hardware_type;
|
||||
NmtDeviceEntryDeviceFilter device_filter;
|
||||
gpointer device_filter_data;
|
||||
int arptype;
|
||||
|
||||
char *interface_name;
|
||||
char *mac_address;
|
||||
char *interface_name;
|
||||
char *mac_address;
|
||||
|
||||
char *label;
|
||||
NmtNewtEntry *entry;
|
||||
NmtNewtWidget *button;
|
||||
char * label;
|
||||
NmtNewtEntry * entry;
|
||||
NmtNewtWidget *button;
|
||||
|
||||
gboolean updating;
|
||||
gboolean updating;
|
||||
} NmtDeviceEntryPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_LABEL,
|
||||
PROP_WIDTH,
|
||||
PROP_HARDWARE_TYPE,
|
||||
PROP_INTERFACE_NAME,
|
||||
PROP_MAC_ADDRESS,
|
||||
PROP_0,
|
||||
PROP_LABEL,
|
||||
PROP_WIDTH,
|
||||
PROP_HARDWARE_TYPE,
|
||||
PROP_INTERFACE_NAME,
|
||||
PROP_MAC_ADDRESS,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -76,280 +77,272 @@ enum {
|
|||
* Returns: a new #NmtDeviceEntry.
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_device_entry_new (const char *label,
|
||||
int width,
|
||||
GType hardware_type)
|
||||
nmt_device_entry_new(const char *label, int width, GType hardware_type)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_DEVICE_ENTRY,
|
||||
"label", label,
|
||||
"width", width,
|
||||
"hardware-type", hardware_type,
|
||||
NULL);
|
||||
return g_object_new(NMT_TYPE_DEVICE_ENTRY,
|
||||
"label",
|
||||
label,
|
||||
"width",
|
||||
width,
|
||||
"hardware-type",
|
||||
hardware_type,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
device_entry_parse (NmtDeviceEntry *deventry,
|
||||
const char *text,
|
||||
char **interface_name,
|
||||
char **mac_address)
|
||||
device_entry_parse(NmtDeviceEntry *deventry,
|
||||
const char * text,
|
||||
char ** interface_name,
|
||||
char ** mac_address)
|
||||
{
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (deventry);
|
||||
guint8 buf[NM_UTILS_HWADDR_LEN_MAX];
|
||||
char **words;
|
||||
int len;
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry);
|
||||
guint8 buf[NM_UTILS_HWADDR_LEN_MAX];
|
||||
char ** words;
|
||||
int len;
|
||||
|
||||
*interface_name = *mac_address = NULL;
|
||||
if (!*text)
|
||||
return TRUE;
|
||||
*interface_name = *mac_address = NULL;
|
||||
if (!*text)
|
||||
return TRUE;
|
||||
|
||||
if (priv->hardware_type == G_TYPE_NONE && !priv->device_filter) {
|
||||
if (nm_utils_ifname_valid_kernel (text, NULL)) {
|
||||
*interface_name = g_strdup (text);
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
if (priv->hardware_type == G_TYPE_NONE && !priv->device_filter) {
|
||||
if (nm_utils_ifname_valid_kernel(text, NULL)) {
|
||||
*interface_name = g_strdup(text);
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
words = g_strsplit (text, " ", -1);
|
||||
if (g_strv_length (words) > 2) {
|
||||
g_strfreev (words);
|
||||
return FALSE;
|
||||
}
|
||||
words = g_strsplit(text, " ", -1);
|
||||
if (g_strv_length(words) > 2) {
|
||||
g_strfreev(words);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (words[1]) {
|
||||
len = strlen (words[1]);
|
||||
if (len < 3 || words[1][0] != '(' || words[1][len - 1] != ')')
|
||||
goto fail;
|
||||
if (words[1]) {
|
||||
len = strlen(words[1]);
|
||||
if (len < 3 || words[1][0] != '(' || words[1][len - 1] != ')')
|
||||
goto fail;
|
||||
|
||||
memmove (words[1], words[1] + 1, len - 2);
|
||||
words[1][len - 2] = '\0';
|
||||
}
|
||||
memmove(words[1], words[1] + 1, len - 2);
|
||||
words[1][len - 2] = '\0';
|
||||
}
|
||||
|
||||
len = nm_utils_hwaddr_len (priv->arptype);
|
||||
if ( nm_utils_hwaddr_aton (words[0], buf, len)
|
||||
&& (!words[1] || nm_utils_ifname_valid_kernel (words[1], NULL))) {
|
||||
*mac_address = words[0];
|
||||
*interface_name = NULL;
|
||||
g_free (words);
|
||||
return TRUE;
|
||||
} else if ( nm_utils_ifname_valid_kernel (words[0], NULL)
|
||||
&& (!words[1] || nm_utils_hwaddr_aton (words[1], buf, len))) {
|
||||
*interface_name = words[0];
|
||||
*mac_address = NULL;
|
||||
g_free (words);
|
||||
return TRUE;
|
||||
}
|
||||
len = nm_utils_hwaddr_len(priv->arptype);
|
||||
if (nm_utils_hwaddr_aton(words[0], buf, len)
|
||||
&& (!words[1] || nm_utils_ifname_valid_kernel(words[1], NULL))) {
|
||||
*mac_address = words[0];
|
||||
*interface_name = NULL;
|
||||
g_free(words);
|
||||
return TRUE;
|
||||
} else if (nm_utils_ifname_valid_kernel(words[0], NULL)
|
||||
&& (!words[1] || nm_utils_hwaddr_aton(words[1], buf, len))) {
|
||||
*interface_name = words[0];
|
||||
*mac_address = NULL;
|
||||
g_free(words);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
fail:
|
||||
g_strfreev (words);
|
||||
return FALSE;
|
||||
fail:
|
||||
g_strfreev(words);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
device_entry_validate (NmtNewtEntry *entry,
|
||||
const char *text,
|
||||
gpointer user_data)
|
||||
device_entry_validate(NmtNewtEntry *entry, const char *text, gpointer user_data)
|
||||
{
|
||||
NmtDeviceEntry *deventry = user_data;
|
||||
char *ifname, *mac;
|
||||
NmtDeviceEntry *deventry = user_data;
|
||||
char * ifname, *mac;
|
||||
|
||||
if (!device_entry_parse (deventry, text, &ifname, &mac))
|
||||
return FALSE;
|
||||
if (!device_entry_parse(deventry, text, &ifname, &mac))
|
||||
return FALSE;
|
||||
|
||||
g_free (ifname);
|
||||
g_free (mac);
|
||||
return TRUE;
|
||||
g_free(ifname);
|
||||
g_free(mac);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static NMDevice *
|
||||
find_device_by_interface_name (NmtDeviceEntry *deventry,
|
||||
const char *interface_name)
|
||||
find_device_by_interface_name(NmtDeviceEntry *deventry, const char *interface_name)
|
||||
{
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (deventry);
|
||||
const GPtrArray *devices;
|
||||
NMDevice *device = NULL;
|
||||
int i;
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry);
|
||||
const GPtrArray * devices;
|
||||
NMDevice * device = NULL;
|
||||
int i;
|
||||
|
||||
devices = nm_client_get_devices (nm_client);
|
||||
for (i = 0; i < devices->len && !device; i++) {
|
||||
NMDevice *candidate = devices->pdata[i];
|
||||
devices = nm_client_get_devices(nm_client);
|
||||
for (i = 0; i < devices->len && !device; i++) {
|
||||
NMDevice *candidate = devices->pdata[i];
|
||||
|
||||
if ( priv->hardware_type != G_TYPE_NONE
|
||||
&& !G_TYPE_CHECK_INSTANCE_TYPE (candidate, priv->hardware_type))
|
||||
continue;
|
||||
if (priv->hardware_type != G_TYPE_NONE
|
||||
&& !G_TYPE_CHECK_INSTANCE_TYPE(candidate, priv->hardware_type))
|
||||
continue;
|
||||
|
||||
if ( priv->device_filter
|
||||
&& !priv->device_filter (deventry, candidate, priv->device_filter_data))
|
||||
continue;
|
||||
if (priv->device_filter
|
||||
&& !priv->device_filter(deventry, candidate, priv->device_filter_data))
|
||||
continue;
|
||||
|
||||
if (!g_strcmp0 (interface_name, nm_device_get_iface (candidate)))
|
||||
device = candidate;
|
||||
}
|
||||
if (!g_strcmp0(interface_name, nm_device_get_iface(candidate)))
|
||||
device = candidate;
|
||||
}
|
||||
|
||||
return device;
|
||||
return device;
|
||||
}
|
||||
|
||||
static NMDevice *
|
||||
find_device_by_mac_address (NmtDeviceEntry *deventry,
|
||||
const char *mac_address)
|
||||
find_device_by_mac_address(NmtDeviceEntry *deventry, const char *mac_address)
|
||||
{
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (deventry);
|
||||
const GPtrArray *devices;
|
||||
NMDevice *device = NULL;
|
||||
int i;
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry);
|
||||
const GPtrArray * devices;
|
||||
NMDevice * device = NULL;
|
||||
int i;
|
||||
|
||||
devices = nm_client_get_devices (nm_client);
|
||||
for (i = 0; i < devices->len && !device; i++) {
|
||||
NMDevice *candidate = devices->pdata[i];
|
||||
char *hwaddr;
|
||||
devices = nm_client_get_devices(nm_client);
|
||||
for (i = 0; i < devices->len && !device; i++) {
|
||||
NMDevice *candidate = devices->pdata[i];
|
||||
char * hwaddr;
|
||||
|
||||
if ( priv->hardware_type != G_TYPE_NONE
|
||||
&& !G_TYPE_CHECK_INSTANCE_TYPE (candidate, priv->hardware_type))
|
||||
continue;
|
||||
if (priv->hardware_type != G_TYPE_NONE
|
||||
&& !G_TYPE_CHECK_INSTANCE_TYPE(candidate, priv->hardware_type))
|
||||
continue;
|
||||
|
||||
if ( priv->device_filter
|
||||
&& !priv->device_filter (deventry, candidate, priv->device_filter_data))
|
||||
continue;
|
||||
if (priv->device_filter
|
||||
&& !priv->device_filter(deventry, candidate, priv->device_filter_data))
|
||||
continue;
|
||||
|
||||
g_object_get (G_OBJECT (candidate), "hw-address", &hwaddr, NULL);
|
||||
if (hwaddr && !g_ascii_strcasecmp (mac_address, hwaddr))
|
||||
device = candidate;
|
||||
g_free (hwaddr);
|
||||
}
|
||||
g_object_get(G_OBJECT(candidate), "hw-address", &hwaddr, NULL);
|
||||
if (hwaddr && !g_ascii_strcasecmp(mac_address, hwaddr))
|
||||
device = candidate;
|
||||
g_free(hwaddr);
|
||||
}
|
||||
|
||||
return device;
|
||||
return device;
|
||||
}
|
||||
|
||||
static void
|
||||
update_entry (NmtDeviceEntry *deventry)
|
||||
update_entry(NmtDeviceEntry *deventry)
|
||||
{
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (deventry);
|
||||
const char *ifname;
|
||||
char *mac, *text;
|
||||
NMDevice *ifname_device, *mac_device;
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry);
|
||||
const char * ifname;
|
||||
char * mac, *text;
|
||||
NMDevice * ifname_device, *mac_device;
|
||||
|
||||
if (priv->interface_name) {
|
||||
ifname = priv->interface_name;
|
||||
ifname_device = find_device_by_interface_name (deventry, priv->interface_name);
|
||||
} else {
|
||||
ifname = NULL;
|
||||
ifname_device = NULL;
|
||||
}
|
||||
if (priv->interface_name) {
|
||||
ifname = priv->interface_name;
|
||||
ifname_device = find_device_by_interface_name(deventry, priv->interface_name);
|
||||
} else {
|
||||
ifname = NULL;
|
||||
ifname_device = NULL;
|
||||
}
|
||||
|
||||
if (priv->mac_address) {
|
||||
mac = g_strdup (priv->mac_address);
|
||||
mac_device = find_device_by_mac_address (deventry, priv->mac_address);
|
||||
} else {
|
||||
mac = NULL;
|
||||
mac_device = NULL;
|
||||
}
|
||||
if (priv->mac_address) {
|
||||
mac = g_strdup(priv->mac_address);
|
||||
mac_device = find_device_by_mac_address(deventry, priv->mac_address);
|
||||
} else {
|
||||
mac = NULL;
|
||||
mac_device = NULL;
|
||||
}
|
||||
|
||||
if (!ifname && mac_device)
|
||||
ifname = nm_device_get_iface (mac_device);
|
||||
if (!mac && ifname_device && (priv->hardware_type != G_TYPE_NONE))
|
||||
g_object_get (G_OBJECT (ifname_device), "hw-address", &mac, NULL);
|
||||
if (!ifname && mac_device)
|
||||
ifname = nm_device_get_iface(mac_device);
|
||||
if (!mac && ifname_device && (priv->hardware_type != G_TYPE_NONE))
|
||||
g_object_get(G_OBJECT(ifname_device), "hw-address", &mac, NULL);
|
||||
|
||||
if (ifname_device && mac_device && ifname_device != mac_device) {
|
||||
/* Mismatch! */
|
||||
text = g_strdup_printf ("%s != %s", priv->interface_name, mac);
|
||||
} else if (ifname && mac) {
|
||||
if (ifname_device)
|
||||
text = g_strdup_printf ("%s (%s)", ifname, mac);
|
||||
else
|
||||
text = g_strdup_printf ("%s (%s)", mac, ifname);
|
||||
} else if (ifname)
|
||||
text = g_strdup (ifname);
|
||||
else if (mac)
|
||||
text = g_strdup (mac);
|
||||
else
|
||||
text = g_strdup ("");
|
||||
if (ifname_device && mac_device && ifname_device != mac_device) {
|
||||
/* Mismatch! */
|
||||
text = g_strdup_printf("%s != %s", priv->interface_name, mac);
|
||||
} else if (ifname && mac) {
|
||||
if (ifname_device)
|
||||
text = g_strdup_printf("%s (%s)", ifname, mac);
|
||||
else
|
||||
text = g_strdup_printf("%s (%s)", mac, ifname);
|
||||
} else if (ifname)
|
||||
text = g_strdup(ifname);
|
||||
else if (mac)
|
||||
text = g_strdup(mac);
|
||||
else
|
||||
text = g_strdup("");
|
||||
|
||||
priv->updating = TRUE;
|
||||
g_object_set (G_OBJECT (priv->entry), "text", text, NULL);
|
||||
priv->updating = FALSE;
|
||||
g_free (text);
|
||||
priv->updating = TRUE;
|
||||
g_object_set(G_OBJECT(priv->entry), "text", text, NULL);
|
||||
priv->updating = FALSE;
|
||||
g_free(text);
|
||||
|
||||
g_free (mac);
|
||||
g_free(mac);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
nmt_device_entry_set_interface_name (NmtDeviceEntry *deventry,
|
||||
const char *interface_name)
|
||||
nmt_device_entry_set_interface_name(NmtDeviceEntry *deventry, const char *interface_name)
|
||||
{
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (deventry);
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry);
|
||||
|
||||
if (g_strcmp0 (interface_name, priv->interface_name) != 0) {
|
||||
g_free (priv->interface_name);
|
||||
priv->interface_name = g_strdup (interface_name);
|
||||
if (g_strcmp0(interface_name, priv->interface_name) != 0) {
|
||||
g_free(priv->interface_name);
|
||||
priv->interface_name = g_strdup(interface_name);
|
||||
|
||||
g_object_notify (G_OBJECT (deventry), "interface-name");
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
g_object_notify(G_OBJECT(deventry), "interface-name");
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
nmt_device_entry_set_mac_address (NmtDeviceEntry *deventry,
|
||||
const char *mac_address)
|
||||
nmt_device_entry_set_mac_address(NmtDeviceEntry *deventry, const char *mac_address)
|
||||
{
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (deventry);
|
||||
gboolean changed;
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry);
|
||||
gboolean changed;
|
||||
|
||||
if (mac_address && !priv->mac_address) {
|
||||
priv->mac_address = g_strdup (mac_address);
|
||||
changed = TRUE;
|
||||
} else if (!mac_address && priv->mac_address) {
|
||||
nm_clear_g_free (&priv->mac_address);
|
||||
changed = TRUE;
|
||||
} else if ( mac_address && priv->mac_address
|
||||
&& !nm_utils_hwaddr_matches (mac_address, -1, priv->mac_address, -1)) {
|
||||
g_free (priv->mac_address);
|
||||
priv->mac_address = g_strdup (mac_address);
|
||||
changed = TRUE;
|
||||
} else
|
||||
changed = FALSE;
|
||||
if (mac_address && !priv->mac_address) {
|
||||
priv->mac_address = g_strdup(mac_address);
|
||||
changed = TRUE;
|
||||
} else if (!mac_address && priv->mac_address) {
|
||||
nm_clear_g_free(&priv->mac_address);
|
||||
changed = TRUE;
|
||||
} else if (mac_address && priv->mac_address
|
||||
&& !nm_utils_hwaddr_matches(mac_address, -1, priv->mac_address, -1)) {
|
||||
g_free(priv->mac_address);
|
||||
priv->mac_address = g_strdup(mac_address);
|
||||
changed = TRUE;
|
||||
} else
|
||||
changed = FALSE;
|
||||
|
||||
if (changed)
|
||||
g_object_notify (G_OBJECT (deventry), "mac-address");
|
||||
return changed;
|
||||
if (changed)
|
||||
g_object_notify(G_OBJECT(deventry), "mac-address");
|
||||
return changed;
|
||||
}
|
||||
|
||||
static void
|
||||
entry_text_changed (GObject *object,
|
||||
GParamSpec *pspec,
|
||||
gpointer deventry)
|
||||
entry_text_changed(GObject *object, GParamSpec *pspec, gpointer deventry)
|
||||
{
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (deventry);
|
||||
const char *text;
|
||||
char *ifname, *mac;
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry);
|
||||
const char * text;
|
||||
char * ifname, *mac;
|
||||
|
||||
if (priv->updating)
|
||||
return;
|
||||
if (priv->updating)
|
||||
return;
|
||||
|
||||
text = nmt_newt_entry_get_text (priv->entry);
|
||||
if (!device_entry_parse (deventry, text, &ifname, &mac))
|
||||
return;
|
||||
text = nmt_newt_entry_get_text(priv->entry);
|
||||
if (!device_entry_parse(deventry, text, &ifname, &mac))
|
||||
return;
|
||||
|
||||
nmt_device_entry_set_interface_name (deventry, ifname);
|
||||
g_free (ifname);
|
||||
nmt_device_entry_set_interface_name(deventry, ifname);
|
||||
g_free(ifname);
|
||||
|
||||
nmt_device_entry_set_mac_address (deventry, mac);
|
||||
g_free (mac);
|
||||
nmt_device_entry_set_mac_address(deventry, mac);
|
||||
g_free(mac);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_device_entry_init (NmtDeviceEntry *deventry)
|
||||
nmt_device_entry_init(NmtDeviceEntry *deventry)
|
||||
{
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (deventry);
|
||||
NmtNewtWidget *entry;
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry);
|
||||
NmtNewtWidget * entry;
|
||||
|
||||
priv->hardware_type = G_TYPE_NONE;
|
||||
priv->hardware_type = G_TYPE_NONE;
|
||||
|
||||
entry = nmt_newt_entry_new (-1, 0);
|
||||
priv->entry = NMT_NEWT_ENTRY (entry);
|
||||
nmt_newt_entry_set_validator (priv->entry, device_entry_validate, deventry);
|
||||
g_signal_connect (priv->entry, "notify::text",
|
||||
G_CALLBACK (entry_text_changed), deventry);
|
||||
entry = nmt_newt_entry_new(-1, 0);
|
||||
priv->entry = NMT_NEWT_ENTRY(entry);
|
||||
nmt_newt_entry_set_validator(priv->entry, device_entry_validate, deventry);
|
||||
g_signal_connect(priv->entry, "notify::text", G_CALLBACK(entry_text_changed), deventry);
|
||||
|
||||
#if 0
|
||||
priv->button = nmt_newt_button_new (_("Select..."));
|
||||
|
|
@ -359,24 +352,27 @@ nmt_device_entry_init (NmtDeviceEntry *deventry)
|
|||
}
|
||||
|
||||
static void
|
||||
nmt_device_entry_constructed (GObject *object)
|
||||
nmt_device_entry_constructed(GObject *object)
|
||||
{
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (object);
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(object);
|
||||
|
||||
nmt_editor_grid_append (NMT_EDITOR_GRID (object), priv->label, NMT_NEWT_WIDGET (priv->entry), NULL);
|
||||
nmt_editor_grid_append(NMT_EDITOR_GRID(object),
|
||||
priv->label,
|
||||
NMT_NEWT_WIDGET(priv->entry),
|
||||
NULL);
|
||||
|
||||
G_OBJECT_CLASS (nmt_device_entry_parent_class)->constructed (object);
|
||||
G_OBJECT_CLASS(nmt_device_entry_parent_class)->constructed(object);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_device_entry_finalize (GObject *object)
|
||||
nmt_device_entry_finalize(GObject *object)
|
||||
{
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (object);
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(object);
|
||||
|
||||
g_free (priv->interface_name);
|
||||
g_free (priv->mac_address);
|
||||
g_free(priv->interface_name);
|
||||
g_free(priv->mac_address);
|
||||
|
||||
G_OBJECT_CLASS (nmt_device_entry_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS(nmt_device_entry_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -405,153 +401,155 @@ nmt_device_entry_finalize (GObject *object)
|
|||
* accepted by the filter will be allowed.
|
||||
*/
|
||||
void
|
||||
nmt_device_entry_set_device_filter (NmtDeviceEntry *deventry,
|
||||
NmtDeviceEntryDeviceFilter filter,
|
||||
gpointer user_data)
|
||||
nmt_device_entry_set_device_filter(NmtDeviceEntry * deventry,
|
||||
NmtDeviceEntryDeviceFilter filter,
|
||||
gpointer user_data)
|
||||
{
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (deventry);
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry);
|
||||
|
||||
priv->device_filter = filter;
|
||||
priv->device_filter_data = user_data;
|
||||
priv->device_filter = filter;
|
||||
priv->device_filter_data = user_data;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_device_entry_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_device_entry_set_property(GObject * object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
NmtDeviceEntry *deventry = NMT_DEVICE_ENTRY (object);
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (deventry);
|
||||
const char *interface_name;
|
||||
const char *mac_address;
|
||||
NmtDeviceEntry * deventry = NMT_DEVICE_ENTRY(object);
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(deventry);
|
||||
const char * interface_name;
|
||||
const char * mac_address;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_LABEL:
|
||||
priv->label = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_WIDTH:
|
||||
nmt_newt_entry_set_width (priv->entry, g_value_get_int (value));
|
||||
break;
|
||||
case PROP_HARDWARE_TYPE:
|
||||
priv->hardware_type = g_value_get_gtype (value);
|
||||
priv->arptype = (priv->hardware_type == NM_TYPE_DEVICE_INFINIBAND) ? ARPHRD_INFINIBAND : ARPHRD_ETHER;
|
||||
break;
|
||||
case PROP_INTERFACE_NAME:
|
||||
interface_name = g_value_get_string (value);
|
||||
if (nmt_device_entry_set_interface_name (deventry, interface_name))
|
||||
update_entry (deventry);
|
||||
break;
|
||||
case PROP_MAC_ADDRESS:
|
||||
mac_address = g_value_get_string (value);
|
||||
if (nmt_device_entry_set_mac_address (deventry, mac_address))
|
||||
update_entry (deventry);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_LABEL:
|
||||
priv->label = g_value_dup_string(value);
|
||||
break;
|
||||
case PROP_WIDTH:
|
||||
nmt_newt_entry_set_width(priv->entry, g_value_get_int(value));
|
||||
break;
|
||||
case PROP_HARDWARE_TYPE:
|
||||
priv->hardware_type = g_value_get_gtype(value);
|
||||
priv->arptype =
|
||||
(priv->hardware_type == NM_TYPE_DEVICE_INFINIBAND) ? ARPHRD_INFINIBAND : ARPHRD_ETHER;
|
||||
break;
|
||||
case PROP_INTERFACE_NAME:
|
||||
interface_name = g_value_get_string(value);
|
||||
if (nmt_device_entry_set_interface_name(deventry, interface_name))
|
||||
update_entry(deventry);
|
||||
break;
|
||||
case PROP_MAC_ADDRESS:
|
||||
mac_address = g_value_get_string(value);
|
||||
if (nmt_device_entry_set_mac_address(deventry, mac_address))
|
||||
update_entry(deventry);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_device_entry_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_device_entry_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (object);
|
||||
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_LABEL:
|
||||
g_value_set_string (value, priv->label);
|
||||
break;
|
||||
case PROP_WIDTH:
|
||||
g_value_set_int (value, nmt_newt_entry_get_width (priv->entry));
|
||||
break;
|
||||
case PROP_HARDWARE_TYPE:
|
||||
g_value_set_gtype (value, priv->hardware_type);
|
||||
break;
|
||||
case PROP_INTERFACE_NAME:
|
||||
g_value_set_string (value, priv->interface_name);
|
||||
break;
|
||||
case PROP_MAC_ADDRESS:
|
||||
g_value_set_string (value, priv->mac_address);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_LABEL:
|
||||
g_value_set_string(value, priv->label);
|
||||
break;
|
||||
case PROP_WIDTH:
|
||||
g_value_set_int(value, nmt_newt_entry_get_width(priv->entry));
|
||||
break;
|
||||
case PROP_HARDWARE_TYPE:
|
||||
g_value_set_gtype(value, priv->hardware_type);
|
||||
break;
|
||||
case PROP_INTERFACE_NAME:
|
||||
g_value_set_string(value, priv->interface_name);
|
||||
break;
|
||||
case PROP_MAC_ADDRESS:
|
||||
g_value_set_string(value, priv->mac_address);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_device_entry_class_init (NmtDeviceEntryClass *deventry_class)
|
||||
nmt_device_entry_class_init(NmtDeviceEntryClass *deventry_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (deventry_class);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS(deventry_class);
|
||||
|
||||
g_type_class_add_private (deventry_class, sizeof (NmtDeviceEntryPrivate));
|
||||
g_type_class_add_private(deventry_class, sizeof(NmtDeviceEntryPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->constructed = nmt_device_entry_constructed;
|
||||
object_class->set_property = nmt_device_entry_set_property;
|
||||
object_class->get_property = nmt_device_entry_get_property;
|
||||
object_class->finalize = nmt_device_entry_finalize;
|
||||
/* virtual methods */
|
||||
object_class->constructed = nmt_device_entry_constructed;
|
||||
object_class->set_property = nmt_device_entry_set_property;
|
||||
object_class->get_property = nmt_device_entry_get_property;
|
||||
object_class->finalize = nmt_device_entry_finalize;
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtDeviceEntry:label:
|
||||
*
|
||||
* The entry's label
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_LABEL,
|
||||
g_param_spec_string ("label", "", "",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_LABEL,
|
||||
g_param_spec_string("label",
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtDeviceEntry:width:
|
||||
*
|
||||
* The entry's width in characters
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_WIDTH,
|
||||
g_param_spec_int ("width", "", "",
|
||||
-1, 80, -1,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_WIDTH,
|
||||
g_param_spec_int("width", "", "", -1, 80, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtDeviceEntry:hardware-type:
|
||||
*
|
||||
* The type of #NMDevice to limit the entry to, or %G_TYPE_NONE
|
||||
* if the entry is for a virtual device and should not accept
|
||||
* hardware addresses.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_HARDWARE_TYPE,
|
||||
g_param_spec_gtype ("hardware-type", "", "",
|
||||
G_TYPE_NONE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(object_class,
|
||||
PROP_HARDWARE_TYPE,
|
||||
g_param_spec_gtype("hardware-type",
|
||||
"",
|
||||
"",
|
||||
G_TYPE_NONE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtDeviceEntry:interface-name:
|
||||
*
|
||||
* The interface name of the device identified by the entry.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_INTERFACE_NAME,
|
||||
g_param_spec_string ("interface-name", "", "",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_INTERFACE_NAME,
|
||||
g_param_spec_string("interface-name",
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtDeviceEntry:mac-address:
|
||||
*
|
||||
* The hardware address of the device identified by the entry.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_MAC_ADDRESS,
|
||||
g_param_spec_string ("mac-address", "", "",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_MAC_ADDRESS,
|
||||
g_param_spec_string("mac-address",
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,34 +8,35 @@
|
|||
|
||||
#include "nmt-editor-grid.h"
|
||||
|
||||
#define NMT_TYPE_DEVICE_ENTRY (nmt_device_entry_get_type ())
|
||||
#define NMT_DEVICE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_DEVICE_ENTRY, NmtDeviceEntry))
|
||||
#define NMT_DEVICE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_DEVICE_ENTRY, NmtDeviceEntryClass))
|
||||
#define NMT_IS_DEVICE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_DEVICE_ENTRY))
|
||||
#define NMT_IS_DEVICE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_DEVICE_ENTRY))
|
||||
#define NMT_DEVICE_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_DEVICE_ENTRY, NmtDeviceEntryClass))
|
||||
#define NMT_TYPE_DEVICE_ENTRY (nmt_device_entry_get_type())
|
||||
#define NMT_DEVICE_ENTRY(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_DEVICE_ENTRY, NmtDeviceEntry))
|
||||
#define NMT_DEVICE_ENTRY_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_DEVICE_ENTRY, NmtDeviceEntryClass))
|
||||
#define NMT_IS_DEVICE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_DEVICE_ENTRY))
|
||||
#define NMT_IS_DEVICE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_DEVICE_ENTRY))
|
||||
#define NMT_DEVICE_ENTRY_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_DEVICE_ENTRY, NmtDeviceEntryClass))
|
||||
|
||||
typedef struct {
|
||||
NmtEditorGrid parent;
|
||||
NmtEditorGrid parent;
|
||||
|
||||
} NmtDeviceEntry;
|
||||
|
||||
typedef struct {
|
||||
NmtEditorGridClass parent;
|
||||
NmtEditorGridClass parent;
|
||||
|
||||
} NmtDeviceEntryClass;
|
||||
|
||||
GType nmt_device_entry_get_type (void);
|
||||
GType nmt_device_entry_get_type(void);
|
||||
|
||||
NmtNewtWidget *nmt_device_entry_new (const char *label,
|
||||
int width,
|
||||
GType hardware_type);
|
||||
NmtNewtWidget *nmt_device_entry_new(const char *label, int width, GType hardware_type);
|
||||
|
||||
typedef gboolean (*NmtDeviceEntryDeviceFilter) (NmtDeviceEntry *deventry,
|
||||
NMDevice *device,
|
||||
gpointer user_data);
|
||||
void nmt_device_entry_set_device_filter (NmtDeviceEntry *deventry,
|
||||
NmtDeviceEntryDeviceFilter filter,
|
||||
gpointer user_data);
|
||||
typedef gboolean (*NmtDeviceEntryDeviceFilter)(NmtDeviceEntry *deventry,
|
||||
NMDevice * device,
|
||||
gpointer user_data);
|
||||
void nmt_device_entry_set_device_filter(NmtDeviceEntry * deventry,
|
||||
NmtDeviceEntryDeviceFilter filter,
|
||||
gpointer user_data);
|
||||
|
||||
#endif /* NMT_DEVICE_ENTRY_H */
|
||||
|
|
|
|||
|
|
@ -20,426 +20,431 @@
|
|||
|
||||
#include "nm-editor-utils.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtEditConnectionList, nmt_edit_connection_list, NMT_TYPE_NEWT_GRID)
|
||||
G_DEFINE_TYPE(NmtEditConnectionList, nmt_edit_connection_list, NMT_TYPE_NEWT_GRID)
|
||||
|
||||
#define NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_EDIT_CONNECTION_LIST, NmtEditConnectionListPrivate))
|
||||
#define NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_EDIT_CONNECTION_LIST, NmtEditConnectionListPrivate))
|
||||
|
||||
typedef struct {
|
||||
GSList *connections;
|
||||
GSList *connections;
|
||||
|
||||
gboolean grouped;
|
||||
NmtEditConnectionListFilter connection_filter;
|
||||
gpointer connection_filter_data;
|
||||
gboolean grouped;
|
||||
NmtEditConnectionListFilter connection_filter;
|
||||
gpointer connection_filter_data;
|
||||
|
||||
NmtNewtListbox *listbox;
|
||||
NmtNewtButtonBox *buttons;
|
||||
NmtNewtListbox * listbox;
|
||||
NmtNewtButtonBox *buttons;
|
||||
|
||||
NmtNewtWidget *add;
|
||||
NmtNewtWidget *edit;
|
||||
NmtNewtWidget *delete;
|
||||
NmtNewtWidget *extra;
|
||||
NmtNewtWidget *add;
|
||||
NmtNewtWidget *edit;
|
||||
NmtNewtWidget *delete;
|
||||
NmtNewtWidget *extra;
|
||||
} NmtEditConnectionListPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_0,
|
||||
|
||||
PROP_GROUPED,
|
||||
PROP_CONNECTION_FILTER,
|
||||
PROP_CONNECTION_FILTER_DATA,
|
||||
PROP_EXTRA_WIDGET,
|
||||
PROP_CONNECTIONS,
|
||||
PROP_NUM_CONNECTIONS,
|
||||
PROP_GROUPED,
|
||||
PROP_CONNECTION_FILTER,
|
||||
PROP_CONNECTION_FILTER_DATA,
|
||||
PROP_EXTRA_WIDGET,
|
||||
PROP_CONNECTIONS,
|
||||
PROP_NUM_CONNECTIONS,
|
||||
|
||||
LAST_PROP
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
enum {
|
||||
ADD_CONNECTION,
|
||||
EDIT_CONNECTION,
|
||||
REMOVE_CONNECTION,
|
||||
ADD_CONNECTION,
|
||||
EDIT_CONNECTION,
|
||||
REMOVE_CONNECTION,
|
||||
|
||||
LAST_SIGNAL
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
static guint signals[LAST_SIGNAL] = {0};
|
||||
|
||||
static void add_clicked (NmtNewtButton *button, gpointer list);
|
||||
static void edit_clicked (NmtNewtButton *button, gpointer list);
|
||||
static void delete_clicked (NmtNewtButton *button, gpointer list);
|
||||
static void listbox_activated (NmtNewtWidget *listbox, gpointer list);
|
||||
static void add_clicked(NmtNewtButton *button, gpointer list);
|
||||
static void edit_clicked(NmtNewtButton *button, gpointer list);
|
||||
static void delete_clicked(NmtNewtButton *button, gpointer list);
|
||||
static void listbox_activated(NmtNewtWidget *listbox, gpointer list);
|
||||
|
||||
static void
|
||||
nmt_edit_connection_list_init (NmtEditConnectionList *list)
|
||||
nmt_edit_connection_list_init(NmtEditConnectionList *list)
|
||||
{
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE (list);
|
||||
NmtNewtWidget *listbox, *buttons;
|
||||
NmtNewtGrid *grid = NMT_NEWT_GRID (list);
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
||||
NmtNewtWidget * listbox, *buttons;
|
||||
NmtNewtGrid * grid = NMT_NEWT_GRID(list);
|
||||
|
||||
listbox = g_object_new (NMT_TYPE_NEWT_LISTBOX,
|
||||
"flags", NMT_NEWT_LISTBOX_SCROLL | NMT_NEWT_LISTBOX_BORDER,
|
||||
"skip-null-keys", TRUE,
|
||||
NULL);
|
||||
priv->listbox = NMT_NEWT_LISTBOX (listbox);
|
||||
nmt_newt_grid_add (grid, listbox, 0, 0);
|
||||
nmt_newt_grid_set_flags (grid, listbox,
|
||||
NMT_NEWT_GRID_FILL_X | NMT_NEWT_GRID_FILL_Y |
|
||||
NMT_NEWT_GRID_EXPAND_X | NMT_NEWT_GRID_EXPAND_Y);
|
||||
g_signal_connect (priv->listbox, "activated", G_CALLBACK (listbox_activated), list);
|
||||
listbox = g_object_new(NMT_TYPE_NEWT_LISTBOX,
|
||||
"flags",
|
||||
NMT_NEWT_LISTBOX_SCROLL | NMT_NEWT_LISTBOX_BORDER,
|
||||
"skip-null-keys",
|
||||
TRUE,
|
||||
NULL);
|
||||
priv->listbox = NMT_NEWT_LISTBOX(listbox);
|
||||
nmt_newt_grid_add(grid, listbox, 0, 0);
|
||||
nmt_newt_grid_set_flags(grid,
|
||||
listbox,
|
||||
NMT_NEWT_GRID_FILL_X | NMT_NEWT_GRID_FILL_Y | NMT_NEWT_GRID_EXPAND_X
|
||||
| NMT_NEWT_GRID_EXPAND_Y);
|
||||
g_signal_connect(priv->listbox, "activated", G_CALLBACK(listbox_activated), list);
|
||||
|
||||
buttons = nmt_newt_button_box_new (NMT_NEWT_BUTTON_BOX_VERTICAL);
|
||||
priv->buttons = NMT_NEWT_BUTTON_BOX (buttons);
|
||||
nmt_newt_grid_add (grid, buttons, 1, 0);
|
||||
nmt_newt_widget_set_padding (buttons, 1, 1, 0, 1);
|
||||
nmt_newt_grid_set_flags (grid, buttons,
|
||||
NMT_NEWT_GRID_FILL_X | NMT_NEWT_GRID_FILL_Y |
|
||||
NMT_NEWT_GRID_EXPAND_Y);
|
||||
buttons = nmt_newt_button_box_new(NMT_NEWT_BUTTON_BOX_VERTICAL);
|
||||
priv->buttons = NMT_NEWT_BUTTON_BOX(buttons);
|
||||
nmt_newt_grid_add(grid, buttons, 1, 0);
|
||||
nmt_newt_widget_set_padding(buttons, 1, 1, 0, 1);
|
||||
nmt_newt_grid_set_flags(grid,
|
||||
buttons,
|
||||
NMT_NEWT_GRID_FILL_X | NMT_NEWT_GRID_FILL_Y | NMT_NEWT_GRID_EXPAND_Y);
|
||||
|
||||
priv->add = nmt_newt_button_box_add_start (priv->buttons, _("Add"));
|
||||
g_signal_connect (priv->add, "clicked", G_CALLBACK (add_clicked), list);
|
||||
priv->add = nmt_newt_button_box_add_start(priv->buttons, _("Add"));
|
||||
g_signal_connect(priv->add, "clicked", G_CALLBACK(add_clicked), list);
|
||||
|
||||
priv->edit = nmt_newt_button_box_add_start (priv->buttons, _("Edit..."));
|
||||
g_signal_connect (priv->edit, "clicked", G_CALLBACK (edit_clicked), list);
|
||||
priv->edit = nmt_newt_button_box_add_start(priv->buttons, _("Edit..."));
|
||||
g_signal_connect(priv->edit, "clicked", G_CALLBACK(edit_clicked), list);
|
||||
|
||||
priv->delete = nmt_newt_button_box_add_start (priv->buttons, _("Delete"));
|
||||
g_signal_connect (priv->delete, "clicked", G_CALLBACK (delete_clicked), list);
|
||||
priv->delete = nmt_newt_button_box_add_start(priv->buttons, _("Delete"));
|
||||
g_signal_connect(priv->delete, "clicked", G_CALLBACK(delete_clicked), list);
|
||||
}
|
||||
|
||||
static int
|
||||
sort_by_timestamp (gconstpointer a,
|
||||
gconstpointer b)
|
||||
sort_by_timestamp(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
NMSettingConnection *s_con_a, *s_con_b;
|
||||
guint64 time_a, time_b;
|
||||
NMSettingConnection *s_con_a, *s_con_b;
|
||||
guint64 time_a, time_b;
|
||||
|
||||
s_con_a = nm_connection_get_setting_connection ((NMConnection *) a);
|
||||
s_con_b = nm_connection_get_setting_connection ((NMConnection *) b);
|
||||
s_con_a = nm_connection_get_setting_connection((NMConnection *) a);
|
||||
s_con_b = nm_connection_get_setting_connection((NMConnection *) b);
|
||||
|
||||
time_a = nm_setting_connection_get_timestamp (s_con_a);
|
||||
time_b = nm_setting_connection_get_timestamp (s_con_b);
|
||||
time_a = nm_setting_connection_get_timestamp(s_con_a);
|
||||
time_b = nm_setting_connection_get_timestamp(s_con_b);
|
||||
|
||||
return (int) (time_b - time_a);
|
||||
return (int) (time_b - time_a);
|
||||
}
|
||||
|
||||
static void nmt_edit_connection_list_rebuild (NmtEditConnectionList *list);
|
||||
static void nmt_edit_connection_list_rebuild(NmtEditConnectionList *list);
|
||||
|
||||
static void
|
||||
rebuild_on_connection_changed (NMRemoteConnection *connection,
|
||||
gpointer list)
|
||||
rebuild_on_connection_changed(NMRemoteConnection *connection, gpointer list)
|
||||
{
|
||||
nmt_edit_connection_list_rebuild (list);
|
||||
nmt_edit_connection_list_rebuild(list);
|
||||
}
|
||||
|
||||
static void
|
||||
free_connections (NmtEditConnectionList *list)
|
||||
free_connections(NmtEditConnectionList *list)
|
||||
{
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE (list);
|
||||
NMConnection *conn;
|
||||
GSList *iter;
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
||||
NMConnection * conn;
|
||||
GSList * iter;
|
||||
|
||||
for (iter = priv->connections; iter; iter = iter->next) {
|
||||
conn = iter->data;
|
||||
for (iter = priv->connections; iter; iter = iter->next) {
|
||||
conn = iter->data;
|
||||
|
||||
g_signal_handlers_disconnect_by_func (conn, G_CALLBACK (rebuild_on_connection_changed), list);
|
||||
g_object_unref (conn);
|
||||
}
|
||||
g_slist_free (priv->connections);
|
||||
priv->connections = NULL;
|
||||
g_signal_handlers_disconnect_by_func(conn, G_CALLBACK(rebuild_on_connection_changed), list);
|
||||
g_object_unref(conn);
|
||||
}
|
||||
g_slist_free(priv->connections);
|
||||
priv->connections = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_edit_connection_list_rebuild (NmtEditConnectionList *list)
|
||||
nmt_edit_connection_list_rebuild(NmtEditConnectionList *list)
|
||||
{
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE (list);
|
||||
const GPtrArray *connections;
|
||||
GSList *iter;
|
||||
gboolean did_header = FALSE, did_vpn = FALSE;
|
||||
NMEditorConnectionTypeData **types;
|
||||
NMConnection *conn, *selected_conn;
|
||||
int i, row, selected_row;
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
||||
const GPtrArray * connections;
|
||||
GSList * iter;
|
||||
gboolean did_header = FALSE, did_vpn = FALSE;
|
||||
NMEditorConnectionTypeData ** types;
|
||||
NMConnection * conn, *selected_conn;
|
||||
int i, row, selected_row;
|
||||
|
||||
selected_row = nmt_newt_listbox_get_active (priv->listbox);
|
||||
selected_conn = nmt_newt_listbox_get_active_key (priv->listbox);
|
||||
selected_row = nmt_newt_listbox_get_active(priv->listbox);
|
||||
selected_conn = nmt_newt_listbox_get_active_key(priv->listbox);
|
||||
|
||||
free_connections (list);
|
||||
connections = nm_client_get_connections (nm_client);
|
||||
for (i = 0; i < connections->len; i++) {
|
||||
conn = connections->pdata[i];
|
||||
free_connections(list);
|
||||
connections = nm_client_get_connections(nm_client);
|
||||
for (i = 0; i < connections->len; i++) {
|
||||
conn = connections->pdata[i];
|
||||
|
||||
if ( priv->connection_filter
|
||||
&& !priv->connection_filter (list, conn, priv->connection_filter_data))
|
||||
continue;
|
||||
if (priv->connection_filter
|
||||
&& !priv->connection_filter(list, conn, priv->connection_filter_data))
|
||||
continue;
|
||||
|
||||
g_signal_connect (conn, NM_CONNECTION_CHANGED,
|
||||
G_CALLBACK (rebuild_on_connection_changed), list);
|
||||
priv->connections = g_slist_prepend (priv->connections, g_object_ref (conn));
|
||||
}
|
||||
priv->connections = g_slist_sort (priv->connections, sort_by_timestamp);
|
||||
g_object_notify (G_OBJECT (list), "connections");
|
||||
g_object_notify (G_OBJECT (list), "num-connections");
|
||||
g_signal_connect(conn,
|
||||
NM_CONNECTION_CHANGED,
|
||||
G_CALLBACK(rebuild_on_connection_changed),
|
||||
list);
|
||||
priv->connections = g_slist_prepend(priv->connections, g_object_ref(conn));
|
||||
}
|
||||
priv->connections = g_slist_sort(priv->connections, sort_by_timestamp);
|
||||
g_object_notify(G_OBJECT(list), "connections");
|
||||
g_object_notify(G_OBJECT(list), "num-connections");
|
||||
|
||||
nmt_newt_component_set_sensitive (NMT_NEWT_COMPONENT (priv->edit),
|
||||
priv->connections != NULL);
|
||||
nmt_newt_component_set_sensitive (NMT_NEWT_COMPONENT (priv->delete),
|
||||
priv->connections != NULL);
|
||||
nmt_newt_component_set_sensitive(NMT_NEWT_COMPONENT(priv->edit), priv->connections != NULL);
|
||||
nmt_newt_component_set_sensitive(NMT_NEWT_COMPONENT(priv->delete), priv->connections != NULL);
|
||||
|
||||
nmt_newt_listbox_clear (priv->listbox);
|
||||
nmt_newt_listbox_clear(priv->listbox);
|
||||
|
||||
if (!priv->grouped) {
|
||||
/* Just add the connections in order */
|
||||
for (iter = priv->connections, row = 0; iter; iter = iter->next, row++) {
|
||||
conn = iter->data;
|
||||
nmt_newt_listbox_append (priv->listbox, nm_connection_get_id (conn), conn);
|
||||
if (conn == selected_conn)
|
||||
selected_row = row;
|
||||
}
|
||||
if (selected_row >= row)
|
||||
selected_row = row - 1;
|
||||
nmt_newt_listbox_set_active (priv->listbox, selected_row);
|
||||
if (!priv->grouped) {
|
||||
/* Just add the connections in order */
|
||||
for (iter = priv->connections, row = 0; iter; iter = iter->next, row++) {
|
||||
conn = iter->data;
|
||||
nmt_newt_listbox_append(priv->listbox, nm_connection_get_id(conn), conn);
|
||||
if (conn == selected_conn)
|
||||
selected_row = row;
|
||||
}
|
||||
if (selected_row >= row)
|
||||
selected_row = row - 1;
|
||||
nmt_newt_listbox_set_active(priv->listbox, selected_row);
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
types = nm_editor_utils_get_connection_type_list ();
|
||||
for (i = row = 0; types[i]; i++) {
|
||||
if (types[i]->setting_type == NM_TYPE_SETTING_VPN) {
|
||||
if (did_vpn)
|
||||
continue;
|
||||
did_vpn = TRUE;
|
||||
}
|
||||
types = nm_editor_utils_get_connection_type_list();
|
||||
for (i = row = 0; types[i]; i++) {
|
||||
if (types[i]->setting_type == NM_TYPE_SETTING_VPN) {
|
||||
if (did_vpn)
|
||||
continue;
|
||||
did_vpn = TRUE;
|
||||
}
|
||||
|
||||
did_header = FALSE;
|
||||
did_header = FALSE;
|
||||
|
||||
for (iter = priv->connections; iter; iter = iter->next) {
|
||||
NMSetting *setting;
|
||||
char *indented;
|
||||
for (iter = priv->connections; iter; iter = iter->next) {
|
||||
NMSetting *setting;
|
||||
char * indented;
|
||||
|
||||
conn = iter->data;
|
||||
setting = nm_connection_get_setting (conn, types[i]->setting_type);
|
||||
if (!setting)
|
||||
continue;
|
||||
if (!nm_connection_is_type (conn, nm_setting_get_name (setting)))
|
||||
continue;
|
||||
conn = iter->data;
|
||||
setting = nm_connection_get_setting(conn, types[i]->setting_type);
|
||||
if (!setting)
|
||||
continue;
|
||||
if (!nm_connection_is_type(conn, nm_setting_get_name(setting)))
|
||||
continue;
|
||||
|
||||
if (!did_header) {
|
||||
nmt_newt_listbox_append (priv->listbox, types[i]->name, NULL);
|
||||
if (row == selected_row)
|
||||
selected_row++;
|
||||
row++;
|
||||
did_header = TRUE;
|
||||
}
|
||||
if (!did_header) {
|
||||
nmt_newt_listbox_append(priv->listbox, types[i]->name, NULL);
|
||||
if (row == selected_row)
|
||||
selected_row++;
|
||||
row++;
|
||||
did_header = TRUE;
|
||||
}
|
||||
|
||||
indented = g_strdup_printf (" %s", nm_connection_get_id (conn));
|
||||
nmt_newt_listbox_append (priv->listbox, indented, conn);
|
||||
g_free (indented);
|
||||
indented = g_strdup_printf(" %s", nm_connection_get_id(conn));
|
||||
nmt_newt_listbox_append(priv->listbox, indented, conn);
|
||||
g_free(indented);
|
||||
|
||||
if (conn == selected_conn)
|
||||
selected_row = row;
|
||||
row++;
|
||||
}
|
||||
}
|
||||
if (conn == selected_conn)
|
||||
selected_row = row;
|
||||
row++;
|
||||
}
|
||||
}
|
||||
|
||||
if (selected_row >= row)
|
||||
selected_row = row - 1;
|
||||
nmt_newt_listbox_set_active (priv->listbox, selected_row);
|
||||
if (selected_row >= row)
|
||||
selected_row = row - 1;
|
||||
nmt_newt_listbox_set_active(priv->listbox, selected_row);
|
||||
}
|
||||
|
||||
static void
|
||||
rebuild_on_connections_changed (GObject *object,
|
||||
GParamSpec *pspec,
|
||||
gpointer list)
|
||||
rebuild_on_connections_changed(GObject *object, GParamSpec *pspec, gpointer list)
|
||||
{
|
||||
nmt_edit_connection_list_rebuild (list);
|
||||
nmt_edit_connection_list_rebuild(list);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_edit_connection_list_constructed (GObject *object)
|
||||
nmt_edit_connection_list_constructed(GObject *object)
|
||||
{
|
||||
NmtEditConnectionList *list = NMT_EDIT_CONNECTION_LIST (object);
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE (list);
|
||||
NmtEditConnectionList * list = NMT_EDIT_CONNECTION_LIST(object);
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
||||
|
||||
if (priv->extra)
|
||||
nmt_newt_button_box_add_widget_end (priv->buttons, priv->extra);
|
||||
if (priv->extra)
|
||||
nmt_newt_button_box_add_widget_end(priv->buttons, priv->extra);
|
||||
|
||||
g_signal_connect (nm_client, "notify::" NM_CLIENT_CONNECTIONS,
|
||||
G_CALLBACK (rebuild_on_connections_changed), list);
|
||||
g_signal_connect(nm_client,
|
||||
"notify::" NM_CLIENT_CONNECTIONS,
|
||||
G_CALLBACK(rebuild_on_connections_changed),
|
||||
list);
|
||||
|
||||
nmt_edit_connection_list_rebuild (list);
|
||||
nmt_edit_connection_list_rebuild(list);
|
||||
|
||||
G_OBJECT_CLASS (nmt_edit_connection_list_parent_class)->constructed (object);
|
||||
G_OBJECT_CLASS(nmt_edit_connection_list_parent_class)->constructed(object);
|
||||
}
|
||||
|
||||
static void
|
||||
add_clicked (NmtNewtButton *button, gpointer list)
|
||||
add_clicked(NmtNewtButton *button, gpointer list)
|
||||
{
|
||||
g_signal_emit (list, signals[ADD_CONNECTION], 0);
|
||||
g_signal_emit(list, signals[ADD_CONNECTION], 0);
|
||||
}
|
||||
|
||||
static void
|
||||
edit_clicked (NmtNewtButton *button, gpointer list)
|
||||
edit_clicked(NmtNewtButton *button, gpointer list)
|
||||
{
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE (list);
|
||||
NMConnection *connection;
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
||||
NMConnection * connection;
|
||||
|
||||
connection = nmt_newt_listbox_get_active_key (priv->listbox);
|
||||
g_return_if_fail (connection != NULL);
|
||||
connection = nmt_newt_listbox_get_active_key(priv->listbox);
|
||||
g_return_if_fail(connection != NULL);
|
||||
|
||||
g_signal_emit (list, signals[EDIT_CONNECTION], 0, connection);
|
||||
g_signal_emit(list, signals[EDIT_CONNECTION], 0, connection);
|
||||
}
|
||||
|
||||
static void
|
||||
delete_clicked (NmtNewtButton *button, gpointer list)
|
||||
delete_clicked(NmtNewtButton *button, gpointer list)
|
||||
{
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE (list);
|
||||
NMRemoteConnection *connection;
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
||||
NMRemoteConnection * connection;
|
||||
|
||||
connection = nmt_newt_listbox_get_active_key (priv->listbox);
|
||||
g_return_if_fail (connection != NULL);
|
||||
connection = nmt_newt_listbox_get_active_key(priv->listbox);
|
||||
g_return_if_fail(connection != NULL);
|
||||
|
||||
g_signal_emit (list, signals[REMOVE_CONNECTION], 0, connection);
|
||||
g_signal_emit(list, signals[REMOVE_CONNECTION], 0, connection);
|
||||
}
|
||||
|
||||
static void
|
||||
listbox_activated (NmtNewtWidget *listbox, gpointer list)
|
||||
listbox_activated(NmtNewtWidget *listbox, gpointer list)
|
||||
{
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE (list);
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
||||
|
||||
edit_clicked (NMT_NEWT_BUTTON (priv->edit), list);
|
||||
edit_clicked(NMT_NEWT_BUTTON(priv->edit), list);
|
||||
}
|
||||
|
||||
static void
|
||||
connection_saved (GObject *conn,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
connection_saved(GObject *conn, GAsyncResult *result, gpointer user_data)
|
||||
{
|
||||
nm_remote_connection_save_finish (NM_REMOTE_CONNECTION (conn), result, NULL);
|
||||
nm_remote_connection_save_finish(NM_REMOTE_CONNECTION(conn), result, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
nmt_edit_connection_list_recommit (NmtEditConnectionList *list)
|
||||
nmt_edit_connection_list_recommit(NmtEditConnectionList *list)
|
||||
{
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE (list);
|
||||
NMConnection *conn;
|
||||
GSList *iter;
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(list);
|
||||
NMConnection * conn;
|
||||
GSList * iter;
|
||||
|
||||
for (iter = priv->connections; iter; iter = iter->next) {
|
||||
conn = iter->data;
|
||||
for (iter = priv->connections; iter; iter = iter->next) {
|
||||
conn = iter->data;
|
||||
|
||||
if ( NM_IS_REMOTE_CONNECTION (conn)
|
||||
&& (nm_remote_connection_get_unsaved (NM_REMOTE_CONNECTION (conn)) == FALSE)) {
|
||||
nm_remote_connection_save_async (NM_REMOTE_CONNECTION (conn),
|
||||
NULL, connection_saved, NULL);
|
||||
}
|
||||
}
|
||||
if (NM_IS_REMOTE_CONNECTION(conn)
|
||||
&& (nm_remote_connection_get_unsaved(NM_REMOTE_CONNECTION(conn)) == FALSE)) {
|
||||
nm_remote_connection_save_async(NM_REMOTE_CONNECTION(conn),
|
||||
NULL,
|
||||
connection_saved,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_edit_connection_list_finalize (GObject *object)
|
||||
nmt_edit_connection_list_finalize(GObject *object)
|
||||
{
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE (object);
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(object);
|
||||
|
||||
free_connections (NMT_EDIT_CONNECTION_LIST (object));
|
||||
g_clear_object (&priv->extra);
|
||||
free_connections(NMT_EDIT_CONNECTION_LIST(object));
|
||||
g_clear_object(&priv->extra);
|
||||
|
||||
G_OBJECT_CLASS (nmt_edit_connection_list_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS(nmt_edit_connection_list_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_edit_connection_list_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_edit_connection_list_set_property(GObject * object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec * pspec)
|
||||
{
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE (object);
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_GROUPED:
|
||||
priv->grouped = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_CONNECTION_FILTER:
|
||||
priv->connection_filter = g_value_get_pointer (value);
|
||||
break;
|
||||
case PROP_CONNECTION_FILTER_DATA:
|
||||
priv->connection_filter_data = g_value_get_pointer (value);
|
||||
break;
|
||||
case PROP_EXTRA_WIDGET:
|
||||
priv->extra = g_value_get_object (value);
|
||||
if (priv->extra)
|
||||
g_object_ref_sink (priv->extra);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_GROUPED:
|
||||
priv->grouped = g_value_get_boolean(value);
|
||||
break;
|
||||
case PROP_CONNECTION_FILTER:
|
||||
priv->connection_filter = g_value_get_pointer(value);
|
||||
break;
|
||||
case PROP_CONNECTION_FILTER_DATA:
|
||||
priv->connection_filter_data = g_value_get_pointer(value);
|
||||
break;
|
||||
case PROP_EXTRA_WIDGET:
|
||||
priv->extra = g_value_get_object(value);
|
||||
if (priv->extra)
|
||||
g_object_ref_sink(priv->extra);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_edit_connection_list_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
nmt_edit_connection_list_get_property(GObject * object,
|
||||
guint prop_id,
|
||||
GValue * value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE (object);
|
||||
GPtrArray *connections;
|
||||
GSList *iter;
|
||||
NmtEditConnectionListPrivate *priv = NMT_EDIT_CONNECTION_LIST_GET_PRIVATE(object);
|
||||
GPtrArray * connections;
|
||||
GSList * iter;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_GROUPED:
|
||||
g_value_set_boolean (value, priv->grouped);
|
||||
break;
|
||||
case PROP_CONNECTION_FILTER:
|
||||
g_value_set_pointer (value, priv->connection_filter);
|
||||
break;
|
||||
case PROP_CONNECTION_FILTER_DATA:
|
||||
g_value_set_pointer (value, priv->connection_filter_data);
|
||||
break;
|
||||
case PROP_EXTRA_WIDGET:
|
||||
g_value_set_object (value, priv->extra);
|
||||
break;
|
||||
case PROP_CONNECTIONS:
|
||||
connections = g_ptr_array_new_with_free_func (g_object_unref);
|
||||
for (iter = priv->connections; iter; iter = iter->next)
|
||||
g_ptr_array_add (connections, g_object_ref (iter->data));
|
||||
g_value_take_boxed (value, connections);
|
||||
break;
|
||||
case PROP_NUM_CONNECTIONS:
|
||||
g_value_set_int (value, g_slist_length (priv->connections));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id) {
|
||||
case PROP_GROUPED:
|
||||
g_value_set_boolean(value, priv->grouped);
|
||||
break;
|
||||
case PROP_CONNECTION_FILTER:
|
||||
g_value_set_pointer(value, priv->connection_filter);
|
||||
break;
|
||||
case PROP_CONNECTION_FILTER_DATA:
|
||||
g_value_set_pointer(value, priv->connection_filter_data);
|
||||
break;
|
||||
case PROP_EXTRA_WIDGET:
|
||||
g_value_set_object(value, priv->extra);
|
||||
break;
|
||||
case PROP_CONNECTIONS:
|
||||
connections = g_ptr_array_new_with_free_func(g_object_unref);
|
||||
for (iter = priv->connections; iter; iter = iter->next)
|
||||
g_ptr_array_add(connections, g_object_ref(iter->data));
|
||||
g_value_take_boxed(value, connections);
|
||||
break;
|
||||
case PROP_NUM_CONNECTIONS:
|
||||
g_value_set_int(value, g_slist_length(priv->connections));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_edit_connection_list_class_init (NmtEditConnectionListClass *list_class)
|
||||
nmt_edit_connection_list_class_init(NmtEditConnectionListClass *list_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (list_class);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS(list_class);
|
||||
|
||||
g_type_class_add_private (list_class, sizeof (NmtEditConnectionListPrivate));
|
||||
g_type_class_add_private(list_class, sizeof(NmtEditConnectionListPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->constructed = nmt_edit_connection_list_constructed;
|
||||
object_class->set_property = nmt_edit_connection_list_set_property;
|
||||
object_class->get_property = nmt_edit_connection_list_get_property;
|
||||
object_class->finalize = nmt_edit_connection_list_finalize;
|
||||
/* virtual methods */
|
||||
object_class->constructed = nmt_edit_connection_list_constructed;
|
||||
object_class->set_property = nmt_edit_connection_list_set_property;
|
||||
object_class->get_property = nmt_edit_connection_list_get_property;
|
||||
object_class->finalize = nmt_edit_connection_list_finalize;
|
||||
|
||||
/* signals */
|
||||
/* signals */
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtEditConnectionList::add-connection:
|
||||
* @list: the #NmtEditConnectionList
|
||||
*
|
||||
* Emitted when the user clicks the list's "Add" button.
|
||||
*/
|
||||
signals[ADD_CONNECTION] =
|
||||
g_signal_new ("add-connection",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NmtEditConnectionListClass, add_connection),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
signals[ADD_CONNECTION] =
|
||||
g_signal_new("add-connection",
|
||||
G_OBJECT_CLASS_TYPE(object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET(NmtEditConnectionListClass, add_connection),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE,
|
||||
0);
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtEditConnectionList::edit-connection:
|
||||
* @list: the #NmtEditConnectionList
|
||||
* @connection: the connection to edit
|
||||
|
|
@ -447,49 +452,56 @@ nmt_edit_connection_list_class_init (NmtEditConnectionListClass *list_class)
|
|||
* Emitted when the user clicks the list's "Edit" button, or
|
||||
* hits "Return" on the listbox.
|
||||
*/
|
||||
signals[EDIT_CONNECTION] =
|
||||
g_signal_new ("edit-connection",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NmtEditConnectionListClass, edit_connection),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
NM_TYPE_CONNECTION);
|
||||
signals[EDIT_CONNECTION] =
|
||||
g_signal_new("edit-connection",
|
||||
G_OBJECT_CLASS_TYPE(object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET(NmtEditConnectionListClass, edit_connection),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
NM_TYPE_CONNECTION);
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtEditConnectionList::remove-connection:
|
||||
* @list: the #NmtEditConnectionList
|
||||
* @connection: the connection to remove
|
||||
*
|
||||
* Emitted when the user clicks the list's "Delete" button.
|
||||
*/
|
||||
signals[REMOVE_CONNECTION] =
|
||||
g_signal_new ("remove-connection",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (NmtEditConnectionListClass, remove_connection),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
NM_TYPE_CONNECTION);
|
||||
signals[REMOVE_CONNECTION] =
|
||||
g_signal_new("remove-connection",
|
||||
G_OBJECT_CLASS_TYPE(object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET(NmtEditConnectionListClass, remove_connection),
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE,
|
||||
1,
|
||||
NM_TYPE_CONNECTION);
|
||||
|
||||
/* properties */
|
||||
/* properties */
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtEditConnectionList:grouped:
|
||||
*
|
||||
* If %TRUE, connections should be grouped by type, with headers
|
||||
* indicating the types (as in the main connection list). If %FALSE,
|
||||
* they will not be grouped (as in slave connection lists).
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_GROUPED,
|
||||
g_param_spec_boolean ("grouped", "", "",
|
||||
TRUE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_GROUPED,
|
||||
g_param_spec_boolean("grouped",
|
||||
"",
|
||||
"",
|
||||
TRUE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtEditConnectionListFilter:
|
||||
* @list: the #NmtEditConnectionList
|
||||
* @connection: an #NMConnection
|
||||
|
|
@ -499,67 +511,74 @@ nmt_edit_connection_list_class_init (NmtEditConnectionListClass *list_class)
|
|||
*
|
||||
* Returns: %TRUE or %FALSE
|
||||
*/
|
||||
/**
|
||||
/**
|
||||
* NmtEditConnectionList:connection-filter:
|
||||
*
|
||||
* A callback function for filtering which connections appear in
|
||||
* the list.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_CONNECTION_FILTER,
|
||||
g_param_spec_pointer ("connection-filter", "", "",
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_CONNECTION_FILTER,
|
||||
g_param_spec_pointer("connection-filter",
|
||||
"",
|
||||
"",
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
/**
|
||||
* NmtEditConnectionList:connection-filter-data:
|
||||
*
|
||||
* Data for the #NmtEditConnectionList:connection-filter.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_CONNECTION_FILTER_DATA,
|
||||
g_param_spec_pointer ("connection-filter-data", "", "",
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_CONNECTION_FILTER_DATA,
|
||||
g_param_spec_pointer("connection-filter-data",
|
||||
"",
|
||||
"",
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtEditConnectionList:extra-widget:
|
||||
*
|
||||
* An extra button widget to display at the bottom of the button
|
||||
* box.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_EXTRA_WIDGET,
|
||||
g_param_spec_object ("extra-widget", "", "",
|
||||
NMT_TYPE_NEWT_WIDGET,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
PROP_EXTRA_WIDGET,
|
||||
g_param_spec_object("extra-widget",
|
||||
"",
|
||||
"",
|
||||
NMT_TYPE_NEWT_WIDGET,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtEditConnectionList:connections:
|
||||
*
|
||||
* The list of connections in the widget.
|
||||
*
|
||||
* Element-Type: #NMConnection
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_CONNECTIONS,
|
||||
g_param_spec_boxed ("connections", "", "",
|
||||
G_TYPE_PTR_ARRAY,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(object_class,
|
||||
PROP_CONNECTIONS,
|
||||
g_param_spec_boxed("connections",
|
||||
"",
|
||||
"",
|
||||
G_TYPE_PTR_ARRAY,
|
||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/**
|
||||
/**
|
||||
* NmtEditConnectionList:num-connections:
|
||||
*
|
||||
* The number of connections in the widget.
|
||||
*/
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_NUM_CONNECTIONS,
|
||||
g_param_spec_int ("num-connections", "", "",
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property(object_class,
|
||||
PROP_NUM_CONNECTIONS,
|
||||
g_param_spec_int("num-connections",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
G_MAXINT,
|
||||
0,
|
||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,35 +8,38 @@
|
|||
|
||||
#include "nmt-newt.h"
|
||||
|
||||
#define NMT_TYPE_EDIT_CONNECTION_LIST (nmt_edit_connection_list_get_type ())
|
||||
#define NMT_EDIT_CONNECTION_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_EDIT_CONNECTION_LIST, NmtEditConnectionList))
|
||||
#define NMT_EDIT_CONNECTION_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_EDIT_CONNECTION_LIST, NmtEditConnectionListClass))
|
||||
#define NMT_IS_EDIT_CONNECTION_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_EDIT_CONNECTION_LIST))
|
||||
#define NMT_IS_EDIT_CONNECTION_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_EDIT_CONNECTION_LIST))
|
||||
#define NMT_EDIT_CONNECTION_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_EDIT_CONNECTION_LIST, NmtEditConnectionListClass))
|
||||
#define NMT_TYPE_EDIT_CONNECTION_LIST (nmt_edit_connection_list_get_type())
|
||||
#define NMT_EDIT_CONNECTION_LIST(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_EDIT_CONNECTION_LIST, NmtEditConnectionList))
|
||||
#define NMT_EDIT_CONNECTION_LIST_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_EDIT_CONNECTION_LIST, NmtEditConnectionListClass))
|
||||
#define NMT_IS_EDIT_CONNECTION_LIST(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_EDIT_CONNECTION_LIST))
|
||||
#define NMT_IS_EDIT_CONNECTION_LIST_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_EDIT_CONNECTION_LIST))
|
||||
#define NMT_EDIT_CONNECTION_LIST_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_EDIT_CONNECTION_LIST, NmtEditConnectionListClass))
|
||||
|
||||
typedef struct {
|
||||
NmtNewtGrid parent;
|
||||
NmtNewtGrid parent;
|
||||
|
||||
} NmtEditConnectionList;
|
||||
|
||||
typedef struct {
|
||||
NmtNewtGridClass parent;
|
||||
NmtNewtGridClass parent;
|
||||
|
||||
/* signals */
|
||||
void (*add_connection) (NmtEditConnectionList *list);
|
||||
void (*edit_connection) (NmtEditConnectionList *list,
|
||||
NMConnection *connection);
|
||||
void (*remove_connection) (NmtEditConnectionList *list,
|
||||
NMRemoteConnection *connection);
|
||||
/* signals */
|
||||
void (*add_connection)(NmtEditConnectionList *list);
|
||||
void (*edit_connection)(NmtEditConnectionList *list, NMConnection *connection);
|
||||
void (*remove_connection)(NmtEditConnectionList *list, NMRemoteConnection *connection);
|
||||
} NmtEditConnectionListClass;
|
||||
|
||||
GType nmt_edit_connection_list_get_type (void);
|
||||
GType nmt_edit_connection_list_get_type(void);
|
||||
|
||||
typedef gboolean (*NmtEditConnectionListFilter) (NmtEditConnectionList *list,
|
||||
NMConnection *connection,
|
||||
gpointer user_data);
|
||||
typedef gboolean (*NmtEditConnectionListFilter)(NmtEditConnectionList *list,
|
||||
NMConnection * connection,
|
||||
gpointer user_data);
|
||||
|
||||
void nmt_edit_connection_list_recommit (NmtEditConnectionList *list);
|
||||
void nmt_edit_connection_list_recommit(NmtEditConnectionList *list);
|
||||
|
||||
#endif /* NMT_EDIT_CONNECTION_LIST_H */
|
||||
|
|
|
|||
|
|
@ -28,25 +28,26 @@
|
|||
|
||||
#include "nmt-editor-grid.h"
|
||||
|
||||
G_DEFINE_TYPE (NmtEditorGrid, nmt_editor_grid, NMT_TYPE_NEWT_CONTAINER)
|
||||
G_DEFINE_TYPE(NmtEditorGrid, nmt_editor_grid, NMT_TYPE_NEWT_CONTAINER)
|
||||
|
||||
#define NMT_EDITOR_GRID_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_EDITOR_GRID, NmtEditorGridPrivate))
|
||||
#define NMT_EDITOR_GRID_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_EDITOR_GRID, NmtEditorGridPrivate))
|
||||
|
||||
typedef struct {
|
||||
GArray *rows;
|
||||
int *row_heights;
|
||||
int indent;
|
||||
GArray *rows;
|
||||
int * row_heights;
|
||||
int indent;
|
||||
} NmtEditorGridPrivate;
|
||||
|
||||
typedef struct {
|
||||
NmtNewtWidget *label;
|
||||
NmtNewtWidget *widget;
|
||||
NmtNewtWidget *extra;
|
||||
NmtEditorGridRowFlags flags;
|
||||
NmtNewtWidget * label;
|
||||
NmtNewtWidget * widget;
|
||||
NmtNewtWidget * extra;
|
||||
NmtEditorGridRowFlags flags;
|
||||
} NmtEditorGridRow;
|
||||
|
||||
typedef struct {
|
||||
int col_widths[3];
|
||||
int col_widths[3];
|
||||
} NmtEditorGridFormState;
|
||||
|
||||
/**
|
||||
|
|
@ -57,29 +58,28 @@ typedef struct {
|
|||
* Returns: a new #NmtEditorGrid
|
||||
*/
|
||||
NmtNewtWidget *
|
||||
nmt_editor_grid_new (void)
|
||||
nmt_editor_grid_new(void)
|
||||
{
|
||||
return g_object_new (NMT_TYPE_EDITOR_GRID,
|
||||
NULL);
|
||||
return g_object_new(NMT_TYPE_EDITOR_GRID, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_editor_grid_init (NmtEditorGrid *grid)
|
||||
nmt_editor_grid_init(NmtEditorGrid *grid)
|
||||
{
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (grid);
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE(grid);
|
||||
|
||||
priv->rows = g_array_new (FALSE, TRUE, sizeof (NmtEditorGridRow));
|
||||
priv->rows = g_array_new(FALSE, TRUE, sizeof(NmtEditorGridRow));
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_editor_grid_finalize (GObject *object)
|
||||
nmt_editor_grid_finalize(GObject *object)
|
||||
{
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (object);
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE(object);
|
||||
|
||||
g_array_unref (priv->rows);
|
||||
nm_clear_g_free (&priv->row_heights);
|
||||
g_array_unref(priv->rows);
|
||||
nm_clear_g_free(&priv->row_heights);
|
||||
|
||||
G_OBJECT_CLASS (nmt_editor_grid_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS(nmt_editor_grid_parent_class)->finalize(object);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -101,60 +101,61 @@ nmt_editor_grid_finalize (GObject *object)
|
|||
* See also nmt_editor_grid_set_row_flags().
|
||||
*/
|
||||
void
|
||||
nmt_editor_grid_append (NmtEditorGrid *grid,
|
||||
const char *label,
|
||||
NmtNewtWidget *widget,
|
||||
NmtNewtWidget *extra)
|
||||
nmt_editor_grid_append(NmtEditorGrid *grid,
|
||||
const char * label,
|
||||
NmtNewtWidget *widget,
|
||||
NmtNewtWidget *extra)
|
||||
{
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (grid);
|
||||
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_editor_grid_parent_class);
|
||||
NmtNewtContainer *container = NMT_NEWT_CONTAINER (grid);
|
||||
NmtEditorGridRow row;
|
||||
NmtEditorGridPrivate * priv = NMT_EDITOR_GRID_GET_PRIVATE(grid);
|
||||
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS(nmt_editor_grid_parent_class);
|
||||
NmtNewtContainer * container = NMT_NEWT_CONTAINER(grid);
|
||||
NmtEditorGridRow row;
|
||||
|
||||
g_return_if_fail (label != NULL || widget != NULL);
|
||||
g_return_if_fail(label != NULL || widget != NULL);
|
||||
|
||||
memset (&row, 0, sizeof (row));
|
||||
memset(&row, 0, sizeof(row));
|
||||
|
||||
if (label && !widget) {
|
||||
widget = nmt_newt_label_new (label);
|
||||
label = NULL;
|
||||
}
|
||||
if (label && !widget) {
|
||||
widget = nmt_newt_label_new(label);
|
||||
label = NULL;
|
||||
}
|
||||
|
||||
if (label) {
|
||||
row.label = nmt_newt_label_new (label);
|
||||
parent_class->add (container, row.label);
|
||||
}
|
||||
if (label) {
|
||||
row.label = nmt_newt_label_new(label);
|
||||
parent_class->add(container, row.label);
|
||||
}
|
||||
|
||||
row.widget = widget;
|
||||
parent_class->add (container, widget);
|
||||
if (row.label) {
|
||||
g_object_bind_property (row.widget, "valid",
|
||||
row.label, "highlight",
|
||||
G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
|
||||
}
|
||||
row.widget = widget;
|
||||
parent_class->add(container, widget);
|
||||
if (row.label) {
|
||||
g_object_bind_property(row.widget,
|
||||
"valid",
|
||||
row.label,
|
||||
"highlight",
|
||||
G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
|
||||
}
|
||||
|
||||
if (extra) {
|
||||
row.extra = extra;
|
||||
parent_class->add (container, extra);
|
||||
}
|
||||
if (extra) {
|
||||
row.extra = extra;
|
||||
parent_class->add(container, extra);
|
||||
}
|
||||
|
||||
g_array_append_val (priv->rows, row);
|
||||
g_array_append_val(priv->rows, row);
|
||||
}
|
||||
|
||||
static int
|
||||
nmt_editor_grid_find_widget (NmtEditorGrid *grid,
|
||||
NmtNewtWidget *widget)
|
||||
nmt_editor_grid_find_widget(NmtEditorGrid *grid, NmtNewtWidget *widget)
|
||||
{
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (grid);
|
||||
NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data;
|
||||
int i;
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE(grid);
|
||||
NmtEditorGridRow * rows = (NmtEditorGridRow *) priv->rows->data;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < priv->rows->len; i++) {
|
||||
if (rows[i].label == widget || rows[i].widget == widget || rows[i].extra == widget)
|
||||
return i;
|
||||
}
|
||||
for (i = 0; i < priv->rows->len; i++) {
|
||||
if (rows[i].label == widget || rows[i].widget == widget || rows[i].extra == widget)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -176,272 +177,265 @@ nmt_editor_grid_find_widget (NmtEditorGrid *grid,
|
|||
* Sets flags to adjust the layout of @widget's row in @grid.
|
||||
*/
|
||||
void
|
||||
nmt_editor_grid_set_row_flags (NmtEditorGrid *grid,
|
||||
NmtNewtWidget *widget,
|
||||
NmtEditorGridRowFlags flags)
|
||||
nmt_editor_grid_set_row_flags(NmtEditorGrid * grid,
|
||||
NmtNewtWidget * widget,
|
||||
NmtEditorGridRowFlags flags)
|
||||
{
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (grid);
|
||||
NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data;
|
||||
int i;
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE(grid);
|
||||
NmtEditorGridRow * rows = (NmtEditorGridRow *) priv->rows->data;
|
||||
int i;
|
||||
|
||||
i = nmt_editor_grid_find_widget (grid, widget);
|
||||
if (i != -1)
|
||||
rows[i].flags = flags;
|
||||
i = nmt_editor_grid_find_widget(grid, widget);
|
||||
if (i != -1)
|
||||
rows[i].flags = flags;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_editor_grid_remove (NmtNewtContainer *container,
|
||||
NmtNewtWidget *widget)
|
||||
nmt_editor_grid_remove(NmtNewtContainer *container, NmtNewtWidget *widget)
|
||||
{
|
||||
NmtEditorGrid *grid = NMT_EDITOR_GRID (container);
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (grid);
|
||||
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_editor_grid_parent_class);
|
||||
NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data;
|
||||
int i;
|
||||
NmtEditorGrid * grid = NMT_EDITOR_GRID(container);
|
||||
NmtEditorGridPrivate * priv = NMT_EDITOR_GRID_GET_PRIVATE(grid);
|
||||
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS(nmt_editor_grid_parent_class);
|
||||
NmtEditorGridRow * rows = (NmtEditorGridRow *) priv->rows->data;
|
||||
int i;
|
||||
|
||||
i = nmt_editor_grid_find_widget (grid, widget);
|
||||
if (i != -1) {
|
||||
if (rows[i].label)
|
||||
parent_class->remove (container, rows[i].label);
|
||||
parent_class->remove (container, rows[i].widget);
|
||||
if (rows[i].extra)
|
||||
parent_class->remove (container, rows[i].extra);
|
||||
i = nmt_editor_grid_find_widget(grid, widget);
|
||||
if (i != -1) {
|
||||
if (rows[i].label)
|
||||
parent_class->remove(container, rows[i].label);
|
||||
parent_class->remove(container, rows[i].widget);
|
||||
if (rows[i].extra)
|
||||
parent_class->remove(container, rows[i].extra);
|
||||
|
||||
g_array_remove_index (priv->rows, i);
|
||||
return;
|
||||
}
|
||||
g_array_remove_index(priv->rows, i);
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: shouldn't happen
|
||||
parent_class->remove (container, widget);
|
||||
// FIXME: shouldn't happen
|
||||
parent_class->remove(container, widget);
|
||||
}
|
||||
|
||||
static newtComponent *
|
||||
nmt_editor_grid_get_components (NmtNewtWidget *widget)
|
||||
nmt_editor_grid_get_components(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (widget);
|
||||
NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data;
|
||||
newtComponent *child_cos;
|
||||
GPtrArray *cos;
|
||||
int i, c;
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE(widget);
|
||||
NmtEditorGridRow * rows = (NmtEditorGridRow *) priv->rows->data;
|
||||
newtComponent * child_cos;
|
||||
GPtrArray * cos;
|
||||
int i, c;
|
||||
|
||||
cos = g_ptr_array_new ();
|
||||
cos = g_ptr_array_new();
|
||||
|
||||
for (i = 0; i < priv->rows->len; i++) {
|
||||
if (!nmt_newt_widget_get_visible (rows[i].widget))
|
||||
continue;
|
||||
for (i = 0; i < priv->rows->len; i++) {
|
||||
if (!nmt_newt_widget_get_visible(rows[i].widget))
|
||||
continue;
|
||||
|
||||
if (rows[i].label) {
|
||||
child_cos = nmt_newt_widget_get_components (rows[i].label);
|
||||
g_assert (child_cos[0] && !child_cos[1]);
|
||||
g_ptr_array_add (cos, child_cos[0]);
|
||||
g_free (child_cos);
|
||||
}
|
||||
if (rows[i].label) {
|
||||
child_cos = nmt_newt_widget_get_components(rows[i].label);
|
||||
g_assert(child_cos[0] && !child_cos[1]);
|
||||
g_ptr_array_add(cos, child_cos[0]);
|
||||
g_free(child_cos);
|
||||
}
|
||||
|
||||
child_cos = nmt_newt_widget_get_components (rows[i].widget);
|
||||
for (c = 0; child_cos[c]; c++)
|
||||
g_ptr_array_add (cos, child_cos[c]);
|
||||
g_free (child_cos);
|
||||
child_cos = nmt_newt_widget_get_components(rows[i].widget);
|
||||
for (c = 0; child_cos[c]; c++)
|
||||
g_ptr_array_add(cos, child_cos[c]);
|
||||
g_free(child_cos);
|
||||
|
||||
if (rows[i].extra) {
|
||||
child_cos = nmt_newt_widget_get_components (rows[i].extra);
|
||||
for (c = 0; child_cos[c]; c++)
|
||||
g_ptr_array_add (cos, child_cos[c]);
|
||||
g_free (child_cos);
|
||||
}
|
||||
}
|
||||
if (rows[i].extra) {
|
||||
child_cos = nmt_newt_widget_get_components(rows[i].extra);
|
||||
for (c = 0; child_cos[c]; c++)
|
||||
g_ptr_array_add(cos, child_cos[c]);
|
||||
g_free(child_cos);
|
||||
}
|
||||
}
|
||||
|
||||
g_ptr_array_add (cos, NULL);
|
||||
return (newtComponent *) g_ptr_array_free (cos, FALSE);
|
||||
g_ptr_array_add(cos, NULL);
|
||||
return (newtComponent *) g_ptr_array_free(cos, FALSE);
|
||||
}
|
||||
|
||||
static NmtEditorGridFormState *
|
||||
get_form_state (NmtNewtWidget *widget)
|
||||
get_form_state(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtNewtForm *form = nmt_newt_widget_get_form (widget);
|
||||
NmtEditorGridFormState *state;
|
||||
NmtNewtForm * form = nmt_newt_widget_get_form(widget);
|
||||
NmtEditorGridFormState *state;
|
||||
|
||||
if (!form)
|
||||
return NULL;
|
||||
if (!form)
|
||||
return NULL;
|
||||
|
||||
state = g_object_get_data (G_OBJECT (form), "NmtEditorGridFormState");
|
||||
if (state)
|
||||
return state;
|
||||
state = g_object_get_data(G_OBJECT(form), "NmtEditorGridFormState");
|
||||
if (state)
|
||||
return state;
|
||||
|
||||
state = g_new0 (NmtEditorGridFormState, 1);
|
||||
g_object_set_data_full (G_OBJECT (form), "NmtEditorGridFormState", state, g_free);
|
||||
return state;
|
||||
state = g_new0(NmtEditorGridFormState, 1);
|
||||
g_object_set_data_full(G_OBJECT(form), "NmtEditorGridFormState", state, g_free);
|
||||
return state;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_editor_grid_realize (NmtNewtWidget *widget)
|
||||
nmt_editor_grid_realize(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (widget);
|
||||
NmtNewtWidget *parent;
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE(widget);
|
||||
NmtNewtWidget * parent;
|
||||
|
||||
NMT_NEWT_WIDGET_CLASS (nmt_editor_grid_parent_class)->realize (widget);
|
||||
NMT_NEWT_WIDGET_CLASS(nmt_editor_grid_parent_class)->realize(widget);
|
||||
|
||||
/* This is a hack, but it's the simplest way to make it work... */
|
||||
priv->indent = 0;
|
||||
/* This is a hack, but it's the simplest way to make it work... */
|
||||
priv->indent = 0;
|
||||
|
||||
parent = nmt_newt_widget_get_parent (widget);
|
||||
while (parent) {
|
||||
if (NMT_IS_NEWT_SECTION (parent)) {
|
||||
priv->indent = 2;
|
||||
break;
|
||||
}
|
||||
parent = nmt_newt_widget_get_parent (parent);
|
||||
}
|
||||
parent = nmt_newt_widget_get_parent(widget);
|
||||
while (parent) {
|
||||
if (NMT_IS_NEWT_SECTION(parent)) {
|
||||
priv->indent = 2;
|
||||
break;
|
||||
}
|
||||
parent = nmt_newt_widget_get_parent(parent);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_editor_grid_unrealize (NmtNewtWidget *widget)
|
||||
nmt_editor_grid_unrealize(NmtNewtWidget *widget)
|
||||
{
|
||||
NmtEditorGridFormState *state = get_form_state (widget);
|
||||
NmtEditorGridFormState *state = get_form_state(widget);
|
||||
|
||||
if (state)
|
||||
memset (state->col_widths, 0, sizeof (state->col_widths));
|
||||
if (state)
|
||||
memset(state->col_widths, 0, sizeof(state->col_widths));
|
||||
|
||||
NMT_NEWT_WIDGET_CLASS (nmt_editor_grid_parent_class)->unrealize (widget);
|
||||
NMT_NEWT_WIDGET_CLASS(nmt_editor_grid_parent_class)->unrealize(widget);
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_editor_grid_size_request (NmtNewtWidget *widget,
|
||||
int *width,
|
||||
int *height)
|
||||
nmt_editor_grid_size_request(NmtNewtWidget *widget, int *width, int *height)
|
||||
{
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (widget);
|
||||
NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data;
|
||||
NmtEditorGridFormState *state = get_form_state (widget);
|
||||
gboolean add_padding = FALSE;
|
||||
int i;
|
||||
NmtEditorGridPrivate * priv = NMT_EDITOR_GRID_GET_PRIVATE(widget);
|
||||
NmtEditorGridRow * rows = (NmtEditorGridRow *) priv->rows->data;
|
||||
NmtEditorGridFormState *state = get_form_state(widget);
|
||||
gboolean add_padding = FALSE;
|
||||
int i;
|
||||
|
||||
g_free (priv->row_heights);
|
||||
priv->row_heights = g_new0 (int, priv->rows->len);
|
||||
g_free(priv->row_heights);
|
||||
priv->row_heights = g_new0(int, priv->rows->len);
|
||||
|
||||
*height = 0;
|
||||
for (i = 0; i < priv->rows->len; i++) {
|
||||
int lwidth, lheight, wwidth, wheight, ewidth, eheight;
|
||||
*height = 0;
|
||||
for (i = 0; i < priv->rows->len; i++) {
|
||||
int lwidth, lheight, wwidth, wheight, ewidth, eheight;
|
||||
|
||||
if (!nmt_newt_widget_get_visible (rows[i].widget))
|
||||
continue;
|
||||
if (!nmt_newt_widget_get_visible(rows[i].widget))
|
||||
continue;
|
||||
|
||||
if (rows[i].label) {
|
||||
nmt_newt_widget_size_request (rows[i].label, &lwidth, &lheight);
|
||||
lwidth += priv->indent;
|
||||
state->col_widths[0] = MAX (state->col_widths[0], lwidth);
|
||||
if (rows[i].label) {
|
||||
nmt_newt_widget_size_request(rows[i].label, &lwidth, &lheight);
|
||||
lwidth += priv->indent;
|
||||
state->col_widths[0] = MAX(state->col_widths[0], lwidth);
|
||||
|
||||
nmt_newt_widget_size_request (rows[i].widget, &wwidth, &wheight);
|
||||
state->col_widths[1] = MAX (state->col_widths[1], wwidth);
|
||||
priv->row_heights[i] = wheight;
|
||||
nmt_newt_widget_size_request(rows[i].widget, &wwidth, &wheight);
|
||||
state->col_widths[1] = MAX(state->col_widths[1], wwidth);
|
||||
priv->row_heights[i] = wheight;
|
||||
|
||||
add_padding = TRUE;
|
||||
} else {
|
||||
nmt_newt_widget_size_request (rows[i].widget, &wwidth, &wheight);
|
||||
priv->row_heights[i] = wheight;
|
||||
}
|
||||
add_padding = TRUE;
|
||||
} else {
|
||||
nmt_newt_widget_size_request(rows[i].widget, &wwidth, &wheight);
|
||||
priv->row_heights[i] = wheight;
|
||||
}
|
||||
|
||||
if (rows[i].extra) {
|
||||
nmt_newt_widget_size_request (rows[i].extra, &ewidth, &eheight);
|
||||
state->col_widths[2] = MAX (state->col_widths[2], ewidth);
|
||||
priv->row_heights[i] = MAX (priv->row_heights[i], eheight);
|
||||
}
|
||||
if (rows[i].extra) {
|
||||
nmt_newt_widget_size_request(rows[i].extra, &ewidth, &eheight);
|
||||
state->col_widths[2] = MAX(state->col_widths[2], ewidth);
|
||||
priv->row_heights[i] = MAX(priv->row_heights[i], eheight);
|
||||
}
|
||||
|
||||
*height += priv->row_heights[i];
|
||||
}
|
||||
*height += priv->row_heights[i];
|
||||
}
|
||||
|
||||
*width = state->col_widths[0] + state->col_widths[1] + state->col_widths[2];
|
||||
if (add_padding)
|
||||
*width += 2;
|
||||
*width = state->col_widths[0] + state->col_widths[1] + state->col_widths[2];
|
||||
if (add_padding)
|
||||
*width += 2;
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_editor_grid_size_allocate (NmtNewtWidget *widget,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height)
|
||||
nmt_editor_grid_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height)
|
||||
{
|
||||
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (widget);
|
||||
NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data;
|
||||
NmtEditorGridFormState *state = get_form_state (widget);
|
||||
int col0_width, col1_width, col2_width;
|
||||
int i, row;
|
||||
NmtEditorGridPrivate * priv = NMT_EDITOR_GRID_GET_PRIVATE(widget);
|
||||
NmtEditorGridRow * rows = (NmtEditorGridRow *) priv->rows->data;
|
||||
NmtEditorGridFormState *state = get_form_state(widget);
|
||||
int col0_width, col1_width, col2_width;
|
||||
int i, row;
|
||||
|
||||
col0_width = state->col_widths[0] - priv->indent;
|
||||
col1_width = state->col_widths[1];
|
||||
col2_width = state->col_widths[2];
|
||||
col0_width = state->col_widths[0] - priv->indent;
|
||||
col1_width = state->col_widths[1];
|
||||
col2_width = state->col_widths[2];
|
||||
|
||||
for (i = row = 0; i < priv->rows->len; i++) {
|
||||
if (!nmt_newt_widget_get_visible (rows[i].widget))
|
||||
continue;
|
||||
for (i = row = 0; i < priv->rows->len; i++) {
|
||||
if (!nmt_newt_widget_get_visible(rows[i].widget))
|
||||
continue;
|
||||
|
||||
if (rows[i].label) {
|
||||
int lwidth, lheight, lx;
|
||||
if (rows[i].label) {
|
||||
int lwidth, lheight, lx;
|
||||
|
||||
if (rows[i].flags & NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT)
|
||||
lx = x;
|
||||
else {
|
||||
nmt_newt_widget_size_request (rows[i].label, &lwidth, &lheight);
|
||||
lx = x + col0_width - lwidth;
|
||||
}
|
||||
if (rows[i].flags & NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT)
|
||||
lx = x;
|
||||
else {
|
||||
nmt_newt_widget_size_request(rows[i].label, &lwidth, &lheight);
|
||||
lx = x + col0_width - lwidth;
|
||||
}
|
||||
|
||||
nmt_newt_widget_size_allocate (rows[i].label,
|
||||
lx,
|
||||
y + row,
|
||||
col0_width,
|
||||
priv->row_heights[i]);
|
||||
nmt_newt_widget_size_allocate(rows[i].label,
|
||||
lx,
|
||||
y + row,
|
||||
col0_width,
|
||||
priv->row_heights[i]);
|
||||
|
||||
nmt_newt_widget_size_allocate (rows[i].widget,
|
||||
x + col0_width + 1,
|
||||
y + row,
|
||||
col1_width,
|
||||
priv->row_heights[i]);
|
||||
} else {
|
||||
nmt_newt_widget_size_allocate (rows[i].widget,
|
||||
x,
|
||||
y + row,
|
||||
col0_width + col1_width + 1,
|
||||
priv->row_heights[i]);
|
||||
}
|
||||
nmt_newt_widget_size_allocate(rows[i].widget,
|
||||
x + col0_width + 1,
|
||||
y + row,
|
||||
col1_width,
|
||||
priv->row_heights[i]);
|
||||
} else {
|
||||
nmt_newt_widget_size_allocate(rows[i].widget,
|
||||
x,
|
||||
y + row,
|
||||
col0_width + col1_width + 1,
|
||||
priv->row_heights[i]);
|
||||
}
|
||||
|
||||
if (rows[i].extra) {
|
||||
int wwidth, wheight, ex;
|
||||
if (rows[i].extra) {
|
||||
int wwidth, wheight, ex;
|
||||
|
||||
if (rows[i].flags & NMT_EDITOR_GRID_ROW_EXTRA_ALIGN_RIGHT)
|
||||
ex = x + col0_width + col1_width + 2;
|
||||
else {
|
||||
nmt_newt_widget_size_request (rows[i].widget, &wwidth, &wheight);
|
||||
ex = x + col0_width + wwidth + 2;
|
||||
}
|
||||
if (rows[i].flags & NMT_EDITOR_GRID_ROW_EXTRA_ALIGN_RIGHT)
|
||||
ex = x + col0_width + col1_width + 2;
|
||||
else {
|
||||
nmt_newt_widget_size_request(rows[i].widget, &wwidth, &wheight);
|
||||
ex = x + col0_width + wwidth + 2;
|
||||
}
|
||||
|
||||
nmt_newt_widget_size_allocate (rows[i].extra,
|
||||
ex,
|
||||
y + row,
|
||||
col2_width,
|
||||
priv->row_heights[i]);
|
||||
}
|
||||
nmt_newt_widget_size_allocate(rows[i].extra,
|
||||
ex,
|
||||
y + row,
|
||||
col2_width,
|
||||
priv->row_heights[i]);
|
||||
}
|
||||
|
||||
row += priv->row_heights[i];
|
||||
}
|
||||
row += priv->row_heights[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nmt_editor_grid_class_init (NmtEditorGridClass *grid_class)
|
||||
nmt_editor_grid_class_init(NmtEditorGridClass *grid_class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (grid_class);
|
||||
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (grid_class);
|
||||
NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS (grid_class);
|
||||
GObjectClass * object_class = G_OBJECT_CLASS(grid_class);
|
||||
NmtNewtWidgetClass * widget_class = NMT_NEWT_WIDGET_CLASS(grid_class);
|
||||
NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS(grid_class);
|
||||
|
||||
g_type_class_add_private (grid_class, sizeof (NmtEditorGridPrivate));
|
||||
g_type_class_add_private(grid_class, sizeof(NmtEditorGridPrivate));
|
||||
|
||||
/* virtual methods */
|
||||
object_class->finalize = nmt_editor_grid_finalize;
|
||||
/* virtual methods */
|
||||
object_class->finalize = nmt_editor_grid_finalize;
|
||||
|
||||
widget_class->realize = nmt_editor_grid_realize;
|
||||
widget_class->unrealize = nmt_editor_grid_unrealize;
|
||||
widget_class->get_components = nmt_editor_grid_get_components;
|
||||
widget_class->size_request = nmt_editor_grid_size_request;
|
||||
widget_class->size_allocate = nmt_editor_grid_size_allocate;
|
||||
widget_class->realize = nmt_editor_grid_realize;
|
||||
widget_class->unrealize = nmt_editor_grid_unrealize;
|
||||
widget_class->get_components = nmt_editor_grid_get_components;
|
||||
widget_class->size_request = nmt_editor_grid_size_request;
|
||||
widget_class->size_allocate = nmt_editor_grid_size_allocate;
|
||||
|
||||
container_class->remove = nmt_editor_grid_remove;
|
||||
container_class->remove = nmt_editor_grid_remove;
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue