static void mode_widget_changed (GObject *object, GParamSpec *pspec, gpointer user_data) { NmtPageBond *bond = NMT_PAGE_BOND (user_data); NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE (bond); const char *mode; if (priv->updating) return; mode = nmt_newt_popup_get_active_id (priv->mode); priv->updating = TRUE; nm_setting_bond_add_option (priv->s_bond, NM_SETTING_BOND_OPTION_MODE, mode); priv->updating = FALSE; if (!strcmp (mode, "balance-tlb") || !strcmp (mode, "balance-alb")) { nmt_newt_popup_set_active (priv->monitoring, NMT_PAGE_BOND_MONITORING_MII); nmt_newt_component_set_sensitive (NMT_NEWT_COMPONENT (priv->monitoring), FALSE); } else nmt_newt_component_set_sensitive (NMT_NEWT_COMPONENT (priv->monitoring), TRUE); if (!strcmp (mode, "active-backup")) { nmt_newt_widget_set_visible (NMT_NEWT_WIDGET (priv->primary), TRUE); nm_setting_bond_add_option (priv->s_bond, NM_SETTING_BOND_OPTION_PRIMARY, nmt_newt_entry_get_text (priv->primary)); } else { nmt_newt_widget_set_visible (NMT_NEWT_WIDGET (priv->primary), FALSE); nm_setting_bond_remove_option (priv->s_bond, NM_SETTING_BOND_OPTION_PRIMARY); } }
static void slaves_changed (GObject *object, GParamSpec *pspec, gpointer user_data) { NmtPageBond *bond = NMT_PAGE_BOND (user_data); NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE (bond); GPtrArray *slaves; g_object_get (object, "connections", &slaves, NULL); if (slaves->len == 0) { if (priv->slave_type == G_TYPE_NONE) return; priv->slave_type = G_TYPE_NONE; } else { NMConnection *slave = slaves->pdata[0]; if (priv->slave_type != G_TYPE_NONE) return; if (nm_connection_is_type (slave, NM_SETTING_INFINIBAND_SETTING_NAME)) priv->slave_type = NM_TYPE_SETTING_INFINIBAND; else priv->slave_type = NM_TYPE_SETTING_WIRED; } if (priv->slave_type == NM_TYPE_SETTING_INFINIBAND) { nmt_newt_popup_set_active_id (priv->mode, "active-backup"); nmt_newt_component_set_sensitive (NMT_NEWT_COMPONENT (priv->mode), FALSE); } else nmt_newt_component_set_sensitive (NMT_NEWT_COMPONENT (priv->mode), TRUE); }
/** * nmt_newt_entry_set_text: * @entry: an #NmtNewtEntry * @text: the new text * * Updates @entry's text. Note that this skips the entry's * #NmtNewtEntryFilter, but will cause its #NmtNewtEntryValidator to * be re-run. */ void nmt_newt_entry_set_text (NmtNewtEntry *entry, const char *text) { newtComponent co; co = nmt_newt_component_get_component (NMT_NEWT_COMPONENT (entry)); nmt_newt_entry_set_text_internal (entry, text, co); }
static void nmt_newt_listbox_activated (NmtNewtWidget *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_WIDGET_CLASS (nmt_newt_listbox_parent_class)->activated (widget); }
static void nmt_newt_listbox_size_allocate (NmtNewtWidget *widget, int x, int y, int width, int height) { NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (widget); 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); priv->alloc_height = height; if (!priv->fixed_height && height != priv->height) { priv->height = height; nmt_newt_widget_needs_rebuild (widget); } }
static void 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; 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); 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 * at (window_x + button_x + 1) in order for its text to be aligned with the * button's text. (The x and y coordinates given to NmtNewtForm are the * coordinates of the top left of the window content, ignoring the border * graphics.) */ 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); 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); 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); }