コード例 #1
0
static void
listbox_active_changed (GObject    *object,
                        GParamSpec *pspec,
                        gpointer    button)
{
	NmtConnectConnectionList *list = NMT_CONNECT_CONNECTION_LIST (object);
	static const char *activate, *deactivate;
	static int deactivate_padding, activate_padding;
	NMActiveConnection *ac;
	gboolean has_selection;

	if (G_UNLIKELY (activate == NULL)) {
		int activate_width, deactivate_width;

		activate = _("Activate");
		activate_width = nmt_newt_text_width (activate);
		deactivate = _("Deactivate");
		deactivate_width = nmt_newt_text_width (deactivate);

		activate_padding = MAX (0, deactivate_width - activate_width);
		deactivate_padding = MAX (0, activate_width - deactivate_width);
	}

	has_selection = nmt_connect_connection_list_get_selection (list, NULL, NULL, NULL, &ac);

	nmt_newt_component_set_sensitive (button, has_selection);
	if (has_selection && ac) {
		nmt_newt_button_set_label (button, deactivate);
		nmt_newt_widget_set_padding (button, 0, 0, deactivate_padding, 0);
	} else {
		nmt_newt_button_set_label (button, activate);
		nmt_newt_widget_set_padding (button, 0, 0, activate_padding, 0);
	}
}
コード例 #2
0
static void
nmt_route_table_init (NmtRouteTable *table)
{
	NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
	NmtNewtWidget *header, *empty;
	NmtNewtWidget *dest_prefix_label, *next_hop_label, *metric_label;
	int dest_prefix_width, next_hop_width, metric_width;
	char *text;

	priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);

	header = nmt_newt_grid_new ();

	text = g_strdup_printf ("%s/%s", _("Destination"), _("Prefix"));
	dest_prefix_width = nmt_newt_text_width (text);
	dest_prefix_label = g_object_new (NMT_TYPE_NEWT_LABEL,
	                                  "text", text,
	                                  "style", NMT_NEWT_LABEL_PLAIN,
	                                  NULL);
	g_free (text);
	nmt_newt_grid_add (NMT_NEWT_GRID (header), dest_prefix_label, 0, 0);

	text = _("Next Hop");
	next_hop_label = g_object_new (NMT_TYPE_NEWT_LABEL,
	                               "text", text,
	                               "style", NMT_NEWT_LABEL_PLAIN,
	                               NULL);
	next_hop_width = nmt_newt_text_width (text);
	nmt_newt_grid_add (NMT_NEWT_GRID (header), next_hop_label, 1, 0);

	text = _("Metric");
	metric_label = g_object_new (NMT_TYPE_NEWT_LABEL,
	                             "text", text,
	                             "style", NMT_NEWT_LABEL_PLAIN,
	                             NULL);
	metric_width = nmt_newt_text_width (text);
	nmt_newt_grid_add (NMT_NEWT_GRID (header), metric_label, 2, 0);

	priv->ip_entry_width = MAX (20, MAX (dest_prefix_width, next_hop_width));
	priv->metric_entry_width = MAX (7, metric_width);

	nmt_newt_widget_set_padding (dest_prefix_label,
	                           0, 0, priv->ip_entry_width - dest_prefix_width, 0);
	nmt_newt_widget_set_padding (next_hop_label,
	                           2, 0, priv->ip_entry_width - next_hop_width, 0);
	nmt_newt_widget_set_padding (metric_label,
	                           2, 0, priv->metric_entry_width - metric_width, 0);

	nmt_newt_grid_add (NMT_NEWT_GRID (table), header, 0, 0);

	empty = nmt_newt_label_new (_("No custom routes are defined."));
	priv->list = nmt_widget_list_new (create_route_entry, table, NULL, empty);
	g_signal_connect (priv->list, "add-clicked", G_CALLBACK (add_route), table);
	g_signal_connect (priv->list, "remove-clicked", G_CALLBACK (remove_route), table);
	nmt_newt_grid_add (NMT_NEWT_GRID (table), priv->list, 0, 1);
}
コード例 #3
0
ファイル: nmtui.c プロジェクト: heftig/NetworkManager
static void
usage (void)
{
	const char *argv0 = g_get_prgname ();
	const char *usage_str = _("Usage");
	int i;

	for (i = 0; i < num_subprograms; i++) {
		if (!strcmp (argv0, subprograms[i].shortcut)) {
			g_printerr ("%s: %s [%s]\n", usage_str, argv0, _(subprograms[i].arg));
			exit (1);
		}
	}

	g_printerr ("%s: nmtui\n", usage_str);
	for (i = 0; i < num_subprograms; i++) {
		g_printerr ("%*s  nmtui %s [%s]\n",
		            nmt_newt_text_width (usage_str), " ",
		            subprograms[i].name,
		            _(subprograms[i].arg));
	}
	exit (1);
}
コード例 #4
0
static void
nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list)
{
	NmtConnectConnectionListPrivate *priv = NMT_CONNECT_CONNECTION_LIST_GET_PRIVATE (list);
	NmtNewtListbox *listbox = NMT_NEWT_LISTBOX (list);
	const GPtrArray *devices, *acs, *connections;
	int max_width;
	char **names, *row, active_col;
	const char *strength_col;
	GSList *nmt_devices, *diter, *citer;
	NmtConnectDevice *nmtdev;
	NmtConnectConnection *nmtconn;

	g_slist_free_full (priv->nmt_devices, (GDestroyNotify) nmt_connect_device_free);
	priv->nmt_devices = NULL;
	nmt_newt_listbox_clear (listbox);

	devices = nm_client_get_devices (nm_client);
	acs = nm_client_get_active_connections (nm_client);
	connections = nm_client_get_connections (nm_client);

	nmt_devices = NULL;

	names = nm_device_disambiguate_names ((NMDevice **) devices->pdata, devices->len);
	nmt_devices = append_nmt_devices_for_devices (nmt_devices, devices, names, connections);
	g_strfreev (names);

	nmt_devices = append_nmt_devices_for_virtual_devices (nmt_devices, connections);
	nmt_devices = append_nmt_devices_for_vpns (nmt_devices, connections);

	nmt_devices = g_slist_sort (nmt_devices, sort_nmt_devices);

	max_width = 0;
	for (diter = nmt_devices; diter; diter = diter->next) {
		nmtdev = diter->data;
		for (citer = nmtdev->conns; citer; citer = citer->next) {
			nmtconn = citer->data;

			max_width = MAX (max_width, nmt_newt_text_width (nmtconn->name));
		}
	}

	for (diter = nmt_devices; diter; diter = diter->next) {
		nmtdev = diter->data;

		if (diter != nmt_devices)
			nmt_newt_listbox_append (listbox, "", NULL);
		nmt_newt_listbox_append (listbox, nmtdev->name, NULL);

		for (citer = nmtdev->conns; citer; citer = citer->next) {
			nmtconn = citer->data;

			if (nmtconn->conn)
				nmtconn->active = connection_find_ac (nmtconn->conn, acs);
			if (nmtconn->active) {
				g_object_ref (nmtconn->active);
				active_col = '*';
			} else
				active_col = ' ';

			if (nmtconn->ap) {
				guint8 strength = nm_access_point_get_strength (nmtconn->ap);

				strength_col = nm_utils_wifi_strength_bars (strength);
			} else
				strength_col = NULL;

			row = g_strdup_printf ("%c %s%-*s%s%s",
			                       active_col,
			                       nmtconn->name,
			                       (int)(max_width - nmt_newt_text_width (nmtconn->name)), "",
			                       strength_col ? " " : "",
			                       strength_col ? strength_col : "");

			nmt_newt_listbox_append (listbox, row, nmtconn);
			g_free (row);
		}
	}

	priv->nmt_devices = nmt_devices;

	g_object_notify (G_OBJECT (listbox), "active");
	g_object_notify (G_OBJECT (listbox), "active-key");
}