示例#1
0
static void delete_fingerprints(DBusGProxy *dev, const char *username)
{
	GError *error = NULL;
	GHashTable *props;
	DBusGProxy *p;

	p = dbus_g_proxy_new_from_proxy(dev, "org.freedesktop.DBus.Properties", NULL);
	if (!dbus_g_proxy_call (p, "GetAll", &error, G_TYPE_STRING, "net.reactivated.Fprint.Device", G_TYPE_INVALID,
			   dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &props, G_TYPE_INVALID)) {
		g_print("GetAll on the Properties interface failed: %s\n", error->message);
		exit (1);
	}

	if (!net_reactivated_Fprint_Device_delete_enrolled_fingers(dev, username, &error)) {
		if (dbus_g_error_has_name (error, "net.reactivated.Fprint.Error.NoEnrolledPrints") == FALSE) {
			g_print("ListEnrolledFingers failed: %s\n", error->message);
			exit (1);
		} else {
			g_print ("No fingerprints to delete on %s\n", g_value_get_string (g_hash_table_lookup (props, "name")));
		}
	} else {
			g_print ("Fingerprints deleted on %s\n", g_value_get_string (g_hash_table_lookup (props, "name")));
	}
	g_hash_table_destroy (props);
	g_object_unref (p);
}
示例#2
0
gboolean
_nm_dbus_get_property (DBusGProxy *proxy,
					  const char *interface,
					  const char *prop_name,
					  GValue *value)
{
	DBusGProxy *properties_proxy;
	GError *err = NULL;
	gboolean ret = TRUE;

	g_return_val_if_fail (proxy != NULL, FALSE);
	g_return_val_if_fail (interface != NULL, FALSE);
	g_return_val_if_fail (prop_name != NULL, FALSE);

	properties_proxy = dbus_g_proxy_new_from_proxy (proxy,
													"org.freedesktop.DBus.Properties",
													dbus_g_proxy_get_path (proxy));

	if (!dbus_g_proxy_call (properties_proxy, "Get", &err,
							G_TYPE_STRING, interface,
							G_TYPE_STRING, prop_name,
							G_TYPE_INVALID,
							G_TYPE_VALUE, value,
							G_TYPE_INVALID)) {
		g_warning ("Error in device_get_property: %s\n", err->message);
		g_error_free (err);
		ret = FALSE;
	}

	g_object_unref (properties_proxy);

	return ret;
}
static gboolean
create_rb_shell_proxies (DBusGConnection *bus, DBusGProxy **shell_proxy, DBusGProxy **player_proxy, GError **error)
{
	DBusGProxy *sp;

	rb_debug ("creating shell proxy");
	sp = dbus_g_proxy_new_for_name_owner (bus,
					      "org.gnome.Rhythmbox",
					      "/org/gnome/Rhythmbox/Shell",
					      "org.gnome.Rhythmbox.Shell",
					      error);
	if (*error) {
		*shell_proxy = NULL;
		return ((*error)->code == DBUS_GERROR_NAME_HAS_NO_OWNER);
	}

	rb_debug ("creating player proxy");
	*player_proxy = dbus_g_proxy_new_from_proxy (sp,
						     "org.gnome.Rhythmbox.Player",
						     "/org/gnome/Rhythmbox/Player");
	if (*player_proxy == NULL) {
		g_object_unref (G_OBJECT (sp));
		*shell_proxy = NULL;
		*player_proxy = NULL;
		return FALSE;
	}

	*shell_proxy = sp;
	return TRUE;
}
示例#4
0
int main(int argc, char *argv[])
{
	GtkStatusIcon *statusicon;
	DBusGConnection *conn;
	DBusGProxy *adapter, *device;
	GError *error = NULL;

	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
	textdomain(GETTEXT_PACKAGE);

	gtk_init(&argc, &argv);

	gtk_window_set_default_icon_name("bluetooth");

	conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
	if (error != NULL) {
		g_printerr("Connecting to system bus failed: %s\n",
							error->message);
		g_error_free(error);
		return 1;
	}

	set_icon (TRUE);
	statusicon = init_notification();

	g_signal_connect(statusicon, "activate",
				G_CALLBACK(activate_callback), NULL);

	setup_agents();

	adapter = dbus_g_proxy_new_for_name(conn, "org.bluez",
						"/hci0", "org.bluez.Adapter");

	device = dbus_g_proxy_new_from_proxy(adapter,
			"/hci0/dev_11_22_33_44_55_66", "org.bluez.Device");

	//display_dialog(adapter, device, "Test (00:11:22:33:44:55)", "123456", 0, NULL);
	pin_dialog(adapter, device, "Test", "'Test' (00:11:22:33:44:55)", FALSE, NULL);
	confirm_dialog(adapter, device, "Test", "'Test' (00:11:22:33:44:55)", "123456", NULL);
	auth_dialog(adapter, device, "Test", "'Test' (00:11:22:33:44:55)", "UUID", NULL);

	gtk_main();

	g_object_unref(device);
	g_object_unref(adapter);

	cleanup_notification();

	cleanup_agents();

	dbus_g_connection_unref(conn);

	return 0;
}
static void
geoclue_gsmloc_ofono_set_modems (GeoclueGsmlocOfono *ofono, GPtrArray *modems)
{
	GeoclueGsmlocOfonoPrivate *priv = GET_PRIVATE (ofono);
	int i;
	GList *mlist;

	/* empty current modem list */
	for (mlist = priv->modems; mlist; mlist = mlist->next) {
		modem_free ((Modem*)mlist->data);
	}
	g_list_free (priv->modems);
	priv->modems = NULL;

	if (!modems || modems->len == 0) {
		return;
	}

	for (i = 0; i < modems->len; i++) {
		const char* str;
		Modem *modem;

		str = (const char*)g_ptr_array_index (modems, i);

		modem = g_slice_new0 (Modem);
		modem->ofono = ofono;
		modem->lac = NULL;
		modem->cid = NULL;
		modem->proxy = dbus_g_proxy_new_from_proxy (priv->ofono_manager,
		                                            "org.ofono.Modem",
		                                            str);
		if (!modem->proxy) {
			g_warning ("failed to find the oFono Modem '%s'", str);
		} else {
			priv->modems = g_list_prepend (priv->modems, modem);
			org_ofono_Modem_get_properties_async (modem->proxy,
			                                      (org_ofono_Manager_get_properties_reply)modem_get_properties_cb,
			                                      modem);
			dbus_g_proxy_add_signal (modem->proxy,"PropertyChanged",
			                         G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
			dbus_g_proxy_connect_signal (modem->proxy, "PropertyChanged",
			                             G_CALLBACK (modem_property_changed_cb),
			                             modem, NULL);
		}
	}
}
示例#6
0
static void update_service(DBusGProxy *proxy, const char *path)
{
    if (path == NULL) {
        status_offline();
        return;
    }

    if (service != NULL) {
        if (g_strcmp0(dbus_g_proxy_get_path(service), path) == 0)
            return;

        properties_destroy(service);
    }

    service = dbus_g_proxy_new_from_proxy(proxy,
                                          "net.connman.Service", path);

    properties_create(service, service_property_changed, NULL);
}
static void
modem_set_net_reg (Modem *modem, gboolean net_reg)
{
	GList *netops;

	g_free (modem->cid);
	modem->cid = NULL;
	g_free (modem->lac);
	modem->lac = NULL;

	if (modem->netreg_proxy) {
		dbus_g_proxy_disconnect_signal (modem->netreg_proxy, "PropertyChanged",
		                                G_CALLBACK (netreg_property_changed_cb),
		                                modem);
		g_object_unref (modem->netreg_proxy);
		modem->netreg_proxy = NULL;
	}

	for (netops = modem->netops; netops; netops = netops->next) {
		net_op_free ((NetOp*)netops->data);
	}
	g_list_free (modem->netops);
	modem->netops = NULL;

	if (net_reg) {
		modem->netreg_proxy = dbus_g_proxy_new_from_proxy (modem->proxy,
		                                                   "org.ofono.NetworkRegistration",
		                                                   dbus_g_proxy_get_path (modem->proxy));
		if (!modem->netreg_proxy) {
			g_warning ("failed to find the oFono NetworkRegistration '%s'",
			           dbus_g_proxy_get_path (modem->proxy));
		} else {
			org_ofono_NetworkRegistration_get_properties_async (modem->netreg_proxy,
																(org_ofono_NetworkRegistration_get_properties_reply)net_reg_get_properties_cb,
																modem);
			dbus_g_proxy_add_signal (modem->netreg_proxy,"PropertyChanged",
									 G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
			dbus_g_proxy_connect_signal (modem->netreg_proxy, "PropertyChanged",
										 G_CALLBACK (netreg_property_changed_cb),
										 modem, NULL);
		}
	}
}
static void
modem_set_net_ops (Modem *modem, GPtrArray *ops)
{
	int i;
	GList *list;

	for (list = modem->netops; list; list = list->next) {
		net_op_free ((NetOp*)list->data);
	}
	g_list_free (modem->netops);
	modem->netops = NULL;

	if (ops->len == 0) {
		return;
	}

	for (i = 0; i < ops->len; i++) {
		const char* op_path;
		NetOp *op;

		op_path = g_ptr_array_index (ops, i);
		op = g_slice_new0 (NetOp);
		op->ofono = modem->ofono;
		op->proxy = dbus_g_proxy_new_from_proxy (modem->proxy,
												 "org.ofono.NetworkOperator",
												 op_path);
		if (!op->proxy) {
			g_warning ("failed to find the oFono NetworkOperator '%s'", op_path);
		} else {
			modem->netops = g_list_prepend (modem->netops, op);
			org_ofono_NetworkOperator_get_properties_async (op->proxy,
															(org_ofono_NetworkOperator_get_properties_reply)get_netop_properties_cb,
															op);
			dbus_g_proxy_add_signal (op->proxy,"PropertyChanged",
									 G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
			dbus_g_proxy_connect_signal (op->proxy, "PropertyChanged",
										 G_CALLBACK (net_op_property_changed_cb),
										 op, NULL);
		}
	}
}
示例#9
0
void
_nm_dbus_set_property (DBusGProxy *proxy,
					  const char *interface,
					  const char *prop_name,
					  GValue *value)
{
	DBusGProxy *properties_proxy;

	g_return_if_fail (proxy != NULL);
	g_return_if_fail (interface != NULL);
	g_return_if_fail (prop_name != NULL);

	properties_proxy = dbus_g_proxy_new_from_proxy (proxy,
													"org.freedesktop.DBus.Properties",
													dbus_g_proxy_get_path (proxy));

	dbus_g_proxy_call_no_reply (properties_proxy, "Set",
								G_TYPE_STRING, interface,
								G_TYPE_STRING, prop_name,
								G_TYPE_VALUE, value,
								G_TYPE_INVALID);

	g_object_unref (properties_proxy);
}
int
main (int argc, char **argv)
{
	GOptionContext *context;
	gboolean ok;
	GError *error = NULL;
	DBusGConnection *bus;
	DBusGProxy *shell_proxy = NULL;
	DBusGProxy *player_proxy = NULL;
	gboolean is_playing;

#ifdef ENABLE_NLS
	/* initialize i18n */
	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
#endif
	/* setup */
	setlocale (LC_ALL, "");
	g_type_init ();
	g_set_prgname ("rhythmbox-client");

	/* parse arguments */
	context = g_option_context_new (NULL);
	g_option_context_add_main_entries (context, args, NULL);
	ok = g_option_context_parse (context, &argc, &argv, &error);
	if (annoy (&error))
		exit (1);

	rb_debug_init (debug);

	/* get dbus connection and proxy for rhythmbox shell */
	bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
	if (annoy (&error))
		exit (1);

	if (!create_rb_shell_proxies (bus, &shell_proxy, &player_proxy, &error)) {
		annoy (&error);
		exit (1);
	}
	g_clear_error (&error);

	/* 1. activate or quit */
	if (quit) {
		if (shell_proxy) {
			rb_debug ("quitting existing instance");
			dbus_g_proxy_call_no_reply (shell_proxy, "quit", G_TYPE_INVALID);
		} else {
			rb_debug ("no existing instance to quit");
		}

		exit (0);
	}
	if (shell_proxy == NULL) {
		DBusGProxy *bus_proxy;
		guint start_service_reply;

		if (no_start) {
			rb_debug ("no existing instance, and can't start one");
			exit (0);
		}

		rb_debug ("starting new instance");
		bus_proxy = dbus_g_proxy_new_for_name (bus,
						       "org.freedesktop.DBus",
						       "/org/freedesktop/DBus",
						       "org.freedesktop.DBus");

		if (!dbus_g_proxy_call (bus_proxy, "StartServiceByName", &error,
					G_TYPE_STRING, "org.gnome.Rhythmbox",
					G_TYPE_UINT, 0,
					G_TYPE_INVALID,
					G_TYPE_UINT, &start_service_reply,
					G_TYPE_INVALID)) {
			g_warning ("%s", error->message);
			exit (1);
		}

		/* hopefully we can get a proxy for the rb shell now.. */
		if (!create_rb_shell_proxies (bus, &shell_proxy, &player_proxy, &error)) {
			annoy (&error);
			exit (1);
		}
		g_clear_error (&error);
	}

	/* don't present if we're doing something else */
	if (next || previous ||
	    clear_queue ||
	    play_uri || other_stuff ||
	    play || pause || play_pause || stop ||
	    print_playing || print_playing_format || notify ||
	    (set_volume > -0.01) || volume_up || volume_down || print_volume || mute || unmute)
		no_present = TRUE;

	/* 2. present or hide */
	if (hide || !no_present) {
		DBusGProxy *properties_proxy;
		GValue value = {0,};

		rb_debug ("setting visibility property");
		g_value_init (&value, G_TYPE_BOOLEAN);
		g_value_set_boolean (&value, !hide);
		properties_proxy = dbus_g_proxy_new_from_proxy (shell_proxy,
								"org.freedesktop.DBus.Properties",
							        "/org/gnome/Rhythmbox/Shell");
		dbus_g_proxy_call_no_reply (properties_proxy, "Set",
					    G_TYPE_STRING, "org.gnome.Rhythmbox.Shell",
					    G_TYPE_STRING, "visibility",
					    G_TYPE_VALUE, &value,
					    G_TYPE_INVALID);
		g_object_unref (G_OBJECT (properties_proxy));
	}

	/* 3. skip to next or previous track */
	if (next) {
		rb_debug ("next track");
		org_gnome_Rhythmbox_Player_next (player_proxy, &error);
		annoy (&error);
	} else if (previous) {
		rb_debug ("previous track");
		org_gnome_Rhythmbox_Player_previous (player_proxy, &error);
		annoy (&error);
	}

	/* 4. add/enqueue */
	if (clear_queue) {
		org_gnome_Rhythmbox_Shell_clear_queue (shell_proxy, &error);
		annoy (&error);
	}
	if (other_stuff) {
		int i;
		for (i = 0; other_stuff[i] != NULL; i++) {
			GFile *file;
			char *fileuri;

			file = g_file_new_for_commandline_arg (other_stuff[i]);
			fileuri = g_file_get_uri (file);
			if (fileuri == NULL) {
				g_warning ("couldn't convert \"%s\" to a URI", other_stuff[i]);
				continue;
			}

			if (enqueue) {
				rb_debug ("enqueueing %s", fileuri);
				org_gnome_Rhythmbox_Shell_add_to_queue (shell_proxy, fileuri, &error);
			} else {
				rb_debug ("importing %s", fileuri);
				org_gnome_Rhythmbox_Shell_load_ur_i (shell_proxy, fileuri, FALSE, &error);
			}
			annoy (&error);
			g_free (fileuri);
			g_object_unref (file);
		}
	}

	/* play uri */
	if (play_uri) {
		GFile *file;
		char *fileuri;

		file = g_file_new_for_commandline_arg (play_uri);
		fileuri = g_file_get_uri (file);
		if (fileuri == NULL) {
			g_warning ("couldn't convert \"%s\" to a URI", play_uri);
		} else {
			rb_debug ("loading and playing %s", fileuri);
			org_gnome_Rhythmbox_Shell_load_ur_i (shell_proxy, fileuri, TRUE, &error);
			annoy (&error);
		}
		g_free (fileuri);
		g_object_unref (file);
	}

	/* 5. play/pause/stop */
	org_gnome_Rhythmbox_Player_get_playing (player_proxy, &is_playing, &error);
	if (!annoy (&error)) {
		rb_debug ("playback state: %d", is_playing);
		if (play || pause || play_pause) {
			if (is_playing != play || play_pause) {
				rb_debug ("calling playPause to change playback state");
				org_gnome_Rhythmbox_Player_play_pause (player_proxy, FALSE, &error);
				annoy (&error);
			} else {
				rb_debug ("no need to change playback state");
			}
		} else if (stop) {
			g_warning ("not implemented yet");
		}
	}

	/* 6. get/set volume, mute/unmute */
	if (set_volume > -0.01) {
		org_gnome_Rhythmbox_Player_set_volume (player_proxy, set_volume, &error);
		annoy (&error);
	} else if (volume_up || volume_down) {
		org_gnome_Rhythmbox_Player_set_volume_relative (player_proxy, volume_up ? 0.1 : -0.1, &error);
		annoy (&error);
	} else if (unmute || mute) {
		org_gnome_Rhythmbox_Player_set_mute (player_proxy, unmute ? FALSE : TRUE, &error);
		annoy (&error);
	}

	if (print_volume) {
		gboolean mute = FALSE;
		gdouble volume = 1.0;

		org_gnome_Rhythmbox_Player_get_mute (player_proxy, &mute, &error);
		annoy (&error);
		org_gnome_Rhythmbox_Player_get_volume (player_proxy, &volume, &error);
		annoy (&error);

		if (mute)
			g_print (_("Playback is muted.\n"));
		g_print (_("Playback volume is %f.\n"), volume);
	}

	/* 7. print playing song */
	if (print_playing_format) {
		print_playing_song (shell_proxy, player_proxy, print_playing_format);
	} else if (print_playing) {
		print_playing_song_default (shell_proxy, player_proxy);
	}

	/* 8. display notification about playing song */
	if (notify) {
		rb_debug ("show notification");
		org_gnome_Rhythmbox_Shell_notify (shell_proxy, TRUE, &error);
		annoy (&error);
	}

	g_object_unref (shell_proxy);
	g_object_unref (player_proxy);
	g_option_context_free (context);

	return 0;
}
示例#11
0
CmService *
internal_service_new (DBusGProxy *proxy, const gchar *path, int order,
                      CmManager *manager, GError **error)
{
  CmService *service;
  CmServicePrivate *priv;
  DBusGProxyCall *call;

  service = g_object_new (CM_TYPE_SERVICE, NULL);
  if (!service)
  {
    g_set_error (error, SERVICE_ERROR, SERVICE_ERROR_NO_MEMORY,
                 "Unable to allocate CmService.");
    return NULL;
  }

  priv = service->priv;
  priv->manager = manager;

  priv->path = g_strdup (path);
  if (!priv->path)
  {
    g_set_error (error, SERVICE_ERROR, SERVICE_ERROR_NO_MEMORY,
                 "Unable to allocate service path.");
    g_object_unref (service);
    return NULL;
  }

  priv->proxy = dbus_g_proxy_new_from_proxy (
    proxy, CONNMAN_SERVICE_INTERFACE, path);
  if (!priv->proxy)
  {
    g_set_error (error, SERVICE_ERROR, SERVICE_ERROR_CONNMAN_INTERFACE,
                 "No interface for %s/%s from Connman.",
                 CONNMAN_SERVICE_INTERFACE, path);
    g_object_unref (service);
    return NULL;
  }

  dbus_g_proxy_add_signal (
    priv->proxy, "PropertyChanged",
    G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);

  dbus_g_proxy_connect_signal (
    priv->proxy, "PropertyChanged",
    G_CALLBACK (service_property_change_handler_proxy),
    service, NULL);

  call = dbus_g_proxy_begin_call (priv->proxy, "GetProperties",
                                  service_get_properties_call_notify, service,
                                  NULL, G_TYPE_INVALID);
  if (!call)
  {
    g_set_error (error, SERVICE_ERROR, SERVICE_ERROR_CONNMAN_GET_PROPERTIES,
                 "Invocation of GetProperties failed.");
    g_object_unref (service);
    return NULL;
  }

  priv->order = order;

  return service;
}
static void
enroll_fingerprints (GtkWindow *parent, GtkWidget *enable, GtkWidget *disable)
{
	DBusGProxy *device, *p;
	GHashTable *props;
	GtkBuilder *dialog;
	EnrollData *data;
	GtkWidget *ass;
	char *msg;

	device = NULL;

	if (manager == NULL) {
		create_manager ();
		if (manager != NULL)
			device = get_first_device ();
	} else {
		device = get_first_device ();
	}

	if (manager == NULL || device == NULL) {
		GtkWidget *d;

		d = get_error_dialog (_("Could not access any fingerprint readers"),
				      _("Please contact your system administrator for help."),
				      parent);
		gtk_dialog_run (GTK_DIALOG (d));
		gtk_widget_destroy (d);
		return;
	}

	data = g_new0 (EnrollData, 1);
	data->device = device;
	data->enable = enable;
	data->disable = disable;

	/* Get some details about the device */
	p = dbus_g_proxy_new_from_proxy (device, "org.freedesktop.DBus.Properties", NULL);
	if (dbus_g_proxy_call (p, "GetAll", NULL, G_TYPE_STRING, "net.reactivated.Fprint.Device", G_TYPE_INVALID,
			       dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &props, G_TYPE_INVALID)) {
		const char *scan_type;
		data->name = g_value_dup_string (g_hash_table_lookup (props, "name"));
		scan_type = g_value_dup_string (g_hash_table_lookup (props, "scan-type"));
		if (g_str_equal (scan_type, "swipe"))
			data->is_swipe = TRUE;
		g_hash_table_destroy (props);
	}
	g_object_unref (p);

	dialog = gtk_builder_new ();
	gtk_builder_add_from_file (dialog, MATECC_UI_DIR "/mate-about-me-fingerprint.ui", NULL);
	data->dialog = dialog;

	ass = WID ("assistant");
	gtk_window_set_title (GTK_WINDOW (ass), _("Enable Fingerprint Login"));
	gtk_window_set_transient_for (GTK_WINDOW (ass), parent);
	gtk_window_set_position (GTK_WINDOW (ass), GTK_WIN_POS_CENTER_ON_PARENT);
	g_signal_connect (G_OBJECT (ass), "cancel",
			  G_CALLBACK (assistant_cancelled), data);
	g_signal_connect (G_OBJECT (ass), "close",
			  G_CALLBACK (assistant_cancelled), data);
	g_signal_connect (G_OBJECT (ass), "prepare",
			  G_CALLBACK (assistant_prepare), data);

	/* Page 1 */
	gtk_combo_box_set_active (GTK_COMBO_BOX (WID ("finger_combobox")), 0);

	g_signal_connect (G_OBJECT (WID ("radiobutton1")), "toggled",
			  G_CALLBACK (finger_radio_button_toggled), data);
	g_signal_connect (G_OBJECT (WID ("radiobutton2")), "toggled",
			  G_CALLBACK (finger_radio_button_toggled), data);
	g_signal_connect (G_OBJECT (WID ("radiobutton3")), "toggled",
			  G_CALLBACK (finger_radio_button_toggled), data);
	g_signal_connect (G_OBJECT (WID ("finger_combobox")), "changed",
			  G_CALLBACK (finger_combobox_changed), data);

	data->finger = selected_finger (dialog);

	g_object_set_data (G_OBJECT (WID("page1")), "name", "intro");

	/* translators:
	 * The variable is the name of the device, for example:
	 * "To enable fingerprint login, you need to save one of your fingerprints, using the
	 * 'Digital Persona U.are.U 4000/4000B' device." */
	msg = g_strdup_printf (_("To enable fingerprint login, you need to save one of your fingerprints, using the '%s' device."),
			       data->name);
	gtk_label_set_text (GTK_LABEL (WID("intro-label")), msg);
	g_free (msg);

	gtk_assistant_set_page_complete (GTK_ASSISTANT (ass), WID("page1"), TRUE);

	/* Page 2 */
	if (data->is_swipe != FALSE)
		gtk_assistant_set_page_title (GTK_ASSISTANT (ass), WID("page2"), _("Swipe finger on reader"));
	else
		gtk_assistant_set_page_title (GTK_ASSISTANT (ass), WID("page2"), _("Place finger on reader"));

	g_object_set_data (G_OBJECT (WID("page2")), "name", "enroll");

	msg = g_strdup_printf (TR(finger_str_to_msg (data->finger, data->is_swipe)), data->name);
	gtk_label_set_text (GTK_LABEL (WID("enroll-label")), msg);
	g_free (msg);

	/* Page 3 */
	g_object_set_data (G_OBJECT (WID("page3")), "name", "summary");

	data->ass = ass;
	gtk_widget_show_all (ass);
}
static void
assistant_prepare (GtkAssistant *ass, GtkWidget *page, EnrollData *data)
{
	const char *name;

	name = g_object_get_data (G_OBJECT (page), "name");
	if (name == NULL)
		return;

	if (g_str_equal (name, "enroll")) {
		DBusGProxy *p;
		GError *error = NULL;
		GtkBuilder *dialog = data->dialog;
		char *path;
		guint i;
		GValue value = { 0, };

		if (!dbus_g_proxy_call (data->device, "Claim", &error, G_TYPE_STRING, "", G_TYPE_INVALID, G_TYPE_INVALID)) {
			GtkWidget *d;
			char *msg;

			/* translators:
			 * The variable is the name of the device, for example:
			 * "Could you not access "Digital Persona U.are.U 4000/4000B" device */
			msg = g_strdup_printf (_("Could not access '%s' device"), data->name);
			d = get_error_dialog (msg, dbus_g_error_get_name (error), GTK_WINDOW (data->ass));
			g_error_free (error);
			gtk_dialog_run (GTK_DIALOG (d));
			gtk_widget_destroy (d);
			g_free (msg);

			enroll_data_destroy (data);

			return;
		}
		data->state = STATE_CLAIMED;

		p = dbus_g_proxy_new_from_proxy (data->device, "org.freedesktop.DBus.Properties", NULL);
		if (!dbus_g_proxy_call (p, "Get", NULL, G_TYPE_STRING, "net.reactivated.Fprint.Device", G_TYPE_STRING, "num-enroll-stages", G_TYPE_INVALID,
				       G_TYPE_VALUE, &value, G_TYPE_INVALID) || g_value_get_int (&value) < 1) {
			GtkWidget *d;
			char *msg;

			/* translators:
			 * The variable is the name of the device, for example:
			 * "Could you not access "Digital Persona U.are.U 4000/4000B" device */
			msg = g_strdup_printf (_("Could not access '%s' device"), data->name);
			d = get_error_dialog (msg, "net.reactivated.Fprint.Error.Internal", GTK_WINDOW (data->ass));
			gtk_dialog_run (GTK_DIALOG (d));
			gtk_widget_destroy (d);
			g_free (msg);

			enroll_data_destroy (data);

			g_object_unref (p);
			return;
		}
		g_object_unref (p);

		data->num_enroll_stages = g_value_get_int (&value);

		/* Hide the extra "bulbs" if not needed */
		for (i = MAX_ENROLL_STAGES; i > data->num_enroll_stages; i--) {
			char *name;

			name = g_strdup_printf ("image%d", i);
			gtk_widget_hide (WID (name));
			g_free (name);
		}
		/* And set the right image */
		{
			char *filename;

			filename = g_strdup_printf ("%s.png", data->finger);
			path = g_build_filename (MATECC_PIXMAP_DIR, filename, NULL);
			g_free (filename);
		}
		for (i = 1; i <= data->num_enroll_stages; i++) {
			char *name;
			name = g_strdup_printf ("image%d", i);
			gtk_image_set_from_file (GTK_IMAGE (WID (name)), path);
			g_free (name);
		}
		g_free (path);

		dbus_g_proxy_add_signal(data->device, "EnrollStatus", G_TYPE_STRING, G_TYPE_BOOLEAN, NULL);
		dbus_g_proxy_connect_signal(data->device, "EnrollStatus", G_CALLBACK(enroll_result), data, NULL);

		if (!dbus_g_proxy_call(data->device, "EnrollStart", &error, G_TYPE_STRING, data->finger, G_TYPE_INVALID, G_TYPE_INVALID)) {
			GtkWidget *d;
			char *msg;

			/* translators:
			 * The variable is the name of the device, for example:
			 * "Could you not access "Digital Persona U.are.U 4000/4000B" device */
			msg = g_strdup_printf (_("Could not start finger capture on '%s' device"), data->name);
			d = get_error_dialog (msg, dbus_g_error_get_name (error), GTK_WINDOW (data->ass));
			g_error_free (error);
			gtk_dialog_run (GTK_DIALOG (d));
			gtk_widget_destroy (d);
			g_free (msg);

			enroll_data_destroy (data);

			return;
		}
		data->state = STATE_ENROLLING;;
	} else {
		if (data->state == STATE_ENROLLING) {
			dbus_g_proxy_call(data->device, "EnrollStop", NULL, G_TYPE_INVALID, G_TYPE_INVALID);
			data->state = STATE_CLAIMED;
		}
		if (data->state == STATE_CLAIMED) {
			dbus_g_proxy_call(data->device, "Release", NULL, G_TYPE_INVALID, G_TYPE_INVALID);
			data->state = STATE_NONE;
		}
	}
}
示例#14
0
void*
widget_main (struct widget *widget) {
	struct widget_config config = widget_config_defaults;
	widget_init_config_string(widget->config, "dbus_path", config.dbus_path);
	widget_init_config_integer(widget->config, "refresh_interval", config.refresh_interval);
	widget_epoll_init(widget);

	DBusGConnection *conn = NULL;
	DBusGProxy *proxy = NULL;
	DBusGProxy *properties_proxy = NULL;
	GError *error = NULL;

	conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);

	if (conn == NULL) {
		LOG_ERR("dbus: failed to open connection to bus: %s\n", error->message);
		goto cleanup;
	}

	proxy = dbus_g_proxy_new_for_name(conn, "org.freedesktop.UPower", (char*)config.dbus_path,
	                                  "org.freedesktop.UPower.Device.Properties");
	if (proxy == NULL) {
		LOG_ERR("dbus: failed to create proxy object");
		goto cleanup;
	}
	properties_proxy = dbus_g_proxy_new_from_proxy(proxy, "org.freedesktop.DBus.Properties",
	                                               dbus_g_proxy_get_path(proxy));
	if (properties_proxy == NULL) {
		LOG_ERR("dbus: failed to create proxy object");
		goto cleanup;
	}

	unsigned int state;
	if (!proxy_uint_value(&state, properties_proxy, (char*)config.dbus_path, "State")) {
		LOG_ERR("dbus: invalid battery");
		if (proxy != NULL) {
			g_object_unref(proxy);
		}
		if (properties_proxy != NULL) {
			g_object_unref(properties_proxy);
		}
		goto cleanup;
	}

	while (true) {
		widget_update(widget, properties_proxy, (char*)config.dbus_path);
		widget_epoll_wait_goto(widget, config.refresh_interval, cleanup);
	}

cleanup:
	if (error != NULL) {
		g_error_free(error);
	}
	if (proxy != NULL) {
		g_object_unref(proxy);
	}
	if (properties_proxy != NULL) {
		g_object_unref(properties_proxy);
	}

	widget_epoll_cleanup(widget);
	widget_clean_exit(widget);
}
static void
auth_session_get_object_path_reply (DBusGProxy *proxy, char *object_path,
                                    GError *error, gpointer userdata)
{
    g_return_if_fail (SIGNON_IS_AUTH_SESSION (userdata));
    SignonAuthSession *self = SIGNON_AUTH_SESSION (userdata);
    SignonAuthSessionPrivate *priv = self->priv;
    g_return_if_fail (priv != NULL);

    priv->pending_call_get_path = NULL;
    if (!g_strcmp0(object_path, "") || error)
    {
        if (error)
            DEBUG ("Error message is %s", error->message);
        else {
            error = g_error_new (auth_session_errors_quark(), 1, SSO_AUTH_SESSION_CONNECTION_PROBLEM_G);
            g_free (object_path);
        }
    }
    else
    {
        priv->proxy = dbus_g_proxy_new_from_proxy (DBUS_G_PROXY (priv->signon_proxy),
                                                   SIGNOND_AUTH_SESSION_INTERFACE,
                                                   object_path);

        dbus_g_object_register_marshaller (_signon_marshal_VOID__INT_STRING,
                                           G_TYPE_NONE,
                                           G_TYPE_INT,
                                           G_TYPE_STRING,
                                           G_TYPE_INVALID);

        dbus_g_proxy_add_signal (priv->proxy,
                                 "stateChanged",
                                 G_TYPE_INT,
                                 G_TYPE_STRING,
                                 G_TYPE_INVALID);

        dbus_g_proxy_connect_signal (priv->proxy,
                                     "stateChanged",
                                     G_CALLBACK (auth_session_state_changed_cb),
                                     self,
                                     NULL);

        dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__VOID,
                                           G_TYPE_NONE,
                                           G_TYPE_INVALID);

        dbus_g_proxy_add_signal (priv->proxy,
                                 "unregistered",
                                 G_TYPE_INVALID);

        dbus_g_proxy_connect_signal (priv->proxy,
                                     "unregistered",
                                     G_CALLBACK (auth_session_remote_object_destroyed_cb),
                                     self,
                                     NULL);
        g_free (object_path);
    }

    DEBUG ("Object path received: %s", object_path);
    _signon_object_ready (self, auth_session_object_quark (), error);

    g_clear_error (&error);
}
static void
connect_presence_watcher (GSWatcher *watcher)
{
    DBusGConnection *bus;
    GError          *error;
    DBusGProxy      *proxy;
    guint            status;
    GValue           value = { 0, };

    error = NULL;
    bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
    if (bus == NULL) {
        g_warning ("Unable to get session bus: %s", error->message);
        g_error_free (error);
        return;
    }

    watcher->priv->presence_proxy = dbus_g_proxy_new_for_name (bus,
                                    GSM_SERVICE,
                                    GSM_PRESENCE_PATH,
                                    GSM_PRESENCE_INTERFACE);

    dbus_g_proxy_add_signal (watcher->priv->presence_proxy,
                             "StatusChanged",
                             G_TYPE_UINT,
                             G_TYPE_INVALID);
    dbus_g_proxy_connect_signal (watcher->priv->presence_proxy,
                                 "StatusChanged",
                                 G_CALLBACK (on_presence_status_changed),
                                 watcher,
                                 NULL);

    proxy = dbus_g_proxy_new_from_proxy (watcher->priv->presence_proxy,
                                         "org.freedesktop.DBus.Properties",
                                         GSM_PRESENCE_PATH);

    status = 0;

    error = NULL;
    dbus_g_proxy_call (proxy,
                       "Get",
                       &error,
                       G_TYPE_STRING, GSM_PRESENCE_INTERFACE,
                       G_TYPE_STRING, "status",
                       G_TYPE_INVALID,
                       G_TYPE_VALUE, &value,
                       G_TYPE_INVALID);

    if (error != NULL) {
        g_warning ("Couldn't get presence status: %s", error->message);
        g_error_free (error);
        return;
    } else {
        status = g_value_get_uint (&value);
    }

    g_value_unset (&value);

    error = NULL;

    set_status (watcher, status);
}