/* * GDBusMenuGroup can be in three states: * * OFFLINE: not subscribed to this group * PENDING: we made the call to subscribe to this group, but the result * has not come back yet * ONLINE: we are fully subscribed * * We can get into some nasty situations where we make a call due to an * activation request but receive a deactivation request before the call * returns. If another activation request occurs then we could risk * sending a Start request even though one is already in progress. For * this reason, we have to carefully consider what to do in each of the * three states for each of the following situations: * * - activation requested * - deactivation requested * - Start call finishes * * To simplify things a bit, we do not have a callback for the Stop * call. We just send it and assume that it takes effect immediately. * * Activation requested: * OFFLINE: make the Start call and transition to PENDING * PENDING: do nothing -- call is already in progress. * ONLINE: this should not be possible * * Deactivation requested: * OFFLINE: this should not be possible * PENDING: do nothing -- handle it when the Start call finishes * ONLINE: send the Stop call and move to OFFLINE immediately * * Start call finishes: * OFFLINE: this should not be possible * PENDING: * If we should be active (ie: active count > 0): move to ONLINE * If not: send Stop call and move to OFFLINE immediately * ONLINE: this should not be possible * * We have to take care with regards to signal subscriptions (ie: * activation of the GDBusMenuPath). The signal subscription is always * established when transitioning from OFFLINE to PENDING and taken down * when transitioning to OFFLINE (from either PENDING or ONLINE). * * Since there are two places where we transition to OFFLINE, we split * that code out into a separate function. */ static void g_dbus_menu_group_go_offline (GDBusMenuGroup *group) { g_dbus_menu_path_deactivate (group->path); g_dbus_connection_call (group->path->id->connection, group->path->id->bus_name, group->path->id->object_path, "org.gtk.Menus", "End", g_variant_new_parsed ("([ %u ],)", group->id), NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); group->state = GROUP_OFFLINE; }
static void tls_dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user_data) { TpTLSCertificate *certificate = NULL; TpTLSCertificateRejectReason reason = 0; GHashTable *details = NULL; EmpathyTLSDialog *tls_dialog = EMPATHY_TLS_DIALOG (dialog); gboolean remember = FALSE; EmpathyTLSVerifier *verifier = EMPATHY_TLS_VERIFIER (user_data); g_object_get (tls_dialog, "certificate", &certificate, "reason", &reason, "remember", &remember, "details", &details, NULL); DEBUG ("Response %d (remember: %d)", response_id, remember); gtk_widget_destroy (GTK_WIDGET (dialog)); if (response_id == GTK_RESPONSE_YES) { tp_tls_certificate_accept_async (certificate, NULL, NULL); } else { tp_asv_set_boolean (details, "user-requested", TRUE); tp_tls_certificate_add_rejection (certificate, reason, NULL, g_variant_new_parsed ("{ 'user-requested': <%b> }", TRUE)); tp_tls_certificate_reject_async (certificate, NULL, NULL); } if (remember) empathy_tls_verifier_store_exception (verifier); g_object_unref (certificate); g_hash_table_unref (details); /* restart the timeout */ num_windows--; if (num_windows > 0) return; start_timer (); }
static void on_airplane_mode_off_clicked (GtkButton *button, CcBluetoothPanel *self) { g_debug ("Airplane Mode Off clicked, disabling airplane mode"); g_dbus_proxy_call (self->priv->rfkill, "org.freedesktop.DBus.Properties.Set", g_variant_new_parsed ("('org.gnome.SettingsDaemon.Rfkill'," "'AirplaneMode', %v)", g_variant_new_boolean (FALSE)), G_DBUS_CALL_FLAGS_NONE, -1, self->priv->cancellable, NULL, NULL); }
/** * gtlm_nfc_write_username_password: * @tlm_nfc: an instance of GTlmNfc object * @nfc_tag_path: an identificator of the nfc tag (returned by #GTlmNfc::tag-found) * @username: username to write * @password: password to write * @error: if non-NULL, set to an error, if one occurs * * This function is used to write a username and password to a tag. The tag path * can be obtained by listening to #GTlmNfc::tag-found signals). @error is set to * @GTLM_NFC_ERROR_NO_TAG if no such tag exists. */ void gtlm_nfc_write_username_password(GTlmNfc* tlm_nfc, const gchar* nfc_tag_path, const gchar* username, const gchar* password, GError** error) { if (nfc_tag_path == NULL) { *error = g_error_new(GTLM_NFC_ERROR, GTLM_NFC_ERROR_NO_TAG, "No tag is present"); return; } GDBusProxy* tag = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, /* GDBusInterfaceInfo */ "org.neard", nfc_tag_path, "org.neard.Tag", NULL, /* GCancellable */ error); if (tag == NULL) { g_debug ("Error creating tag proxy: %s", (*error)->message); return; } //gchar binary_data[] = {0x41, 0x42, 0x43, 0x44}; gchar* binary_data = _encode_username_password(username, password); GVariant* payload = g_variant_new_bytestring(binary_data); g_free(binary_data); GVariant* arguments = g_variant_new_parsed ("({'Type': <'MIME'>, 'MIME': <'application/gtlm-nfc'>, 'Payload' : %v },)", payload); GVariant *result = g_dbus_proxy_call_sync (tag, "Write", arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, error); if (result == NULL) { g_debug ("Error writing to tag: %s", (*error)->message); g_object_unref(tag); return; } g_variant_unref(result); g_object_unref(tag); }
/* * Populate user_id with the user ID of the user associated with the given * logind session object at session_path. user_id must already be allocated * and non-NULL. Return TRUE if user_id was successfully populated and * FALSE otherwise, in which case its contents should be ignored. */ static gboolean get_user_id (const gchar *session_path, guint32 *user_id) { GError *error = NULL; GDBusProxy *dbus_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL /* GDBusInterfaceInfo */, "org.freedesktop.login1", session_path, "org.freedesktop.DBus.Properties", NULL /* GCancellable */, &error); if (dbus_proxy == NULL) { g_warning ("Error creating GDBusProxy: %s.", error->message); g_error_free (error); return FALSE; } GVariant *get_user_args = g_variant_new_parsed ("('org.freedesktop.login1.Session', 'User')"); GVariant *user_result = g_dbus_proxy_call_sync (dbus_proxy, "Get", get_user_args, G_DBUS_CALL_FLAGS_NONE, -1 /* timeout */, NULL /* GCancellable */, &error); g_object_unref (dbus_proxy); if (user_result == NULL) { g_warning ("Error getting user ID: %s.", error->message); g_error_free (error); return FALSE; } GVariant *user_variant = g_variant_get_child_value (user_result, 0); g_variant_unref (user_result); GVariant *user_tuple = g_variant_get_child_value (user_variant, 0); g_variant_unref (user_variant); g_variant_get_child (user_tuple, 0, "u", user_id); g_variant_unref (user_tuple); return TRUE; }
static gboolean on_handle_request_signal_emission (TestFrobber *object, GDBusMethodInvocation *invocation, gint which_one, gpointer user_data) { if (which_one == 0) { const gchar *a_strv[] = {"foo", "frobber", NULL}; const gchar *a_objpath_array[] = {"/foo", "/foo/bar", NULL}; GVariant *a_variant = g_variant_new_parsed ("{'first': (42, 42), 'second': (43, 43)}"); test_frobber_emit_test_signal (object, 43, a_strv, a_objpath_array, a_variant); /* consumes a_variant */ test_frobber_complete_request_signal_emission (object, invocation); } return TRUE; }
static void power_callback (GObject *object, GParamSpec *spec, CcBluetoothPanel *self) { gboolean state; state = gtk_switch_get_active (GTK_SWITCH (WID ("switch_bluetooth"))); g_debug ("Power switched to %s", state ? "on" : "off"); g_dbus_proxy_call (self->priv->properties, "Set", g_variant_new_parsed ("('org.gnome.SettingsDaemon.Rfkill', 'BluetoothAirplaneMode', %v)", g_variant_new_boolean (!state)), G_DBUS_CALL_FLAGS_NONE, -1, self->priv->cancellable, NULL, NULL); }
void PasteboardHelper::fillDataObjectFromDropData(GtkSelectionData* data, guint info, DataObjectGtk* dataObject) { if (!gtk_selection_data_get_data(data)) return; GdkAtom target = gtk_selection_data_get_target(data); if (target == textPlainAtom) dataObject->setText(selectionDataToUTF8String(data)); else if (target == markupAtom) { String markup(selectionDataToUTF8String(data)); removeMarkupPrefix(markup); dataObject->setMarkup(markup); } else if (target == uriListAtom) { dataObject->setURIList(selectionDataToUTF8String(data)); } else if (target == netscapeURLAtom) { String urlWithLabel(selectionDataToUTF8String(data)); Vector<String> pieces; urlWithLabel.split("\n", pieces); // Give preference to text/uri-list here, as it can hold more // than one URI but still take the label if there is one. if (!dataObject->hasURIList()) dataObject->setURIList(pieces[0]); if (pieces.size() > 1) dataObject->setText(pieces[1]); } else if (target == unknownAtom) { GRefPtr<GVariant> variant = g_variant_new_parsed(reinterpret_cast<const char*>(gtk_selection_data_get_data(data))); GOwnPtr<gchar> key; GOwnPtr<gchar> value; GVariantIter iter; g_variant_iter_init(&iter, variant.get()); while (g_variant_iter_next(&iter, "{ss}", &key.outPtr(), &value.outPtr())) { dataObject->setUnknownTypeData(key.get(), value.get()); // FIXME: should GOwnPtr be smarter about this and replace the existing ptr when outPtr() is used? key.clear(); value.clear(); } } }
static void g_dbus_menu_group_activate (GDBusMenuGroup *group) { if (group->active++ == 0) { g_assert (group->state != GROUP_ONLINE); if (group->state == GROUP_OFFLINE) { g_dbus_menu_path_activate (group->path); g_dbus_connection_call (group->path->id->connection, group->path->id->bus_name, group->path->id->object_path, "org.gtk.Menus", "Start", g_variant_new_parsed ("([ %u ],)", group->id), G_VARIANT_TYPE ("(a(uuaa{sv}))"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, g_dbus_menu_group_start_ready, g_dbus_menu_group_ref (group)); group->state = GROUP_PENDING; } } }