static void adapter_changed (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, GtkNotebook *notebook) { DBusGProxy *proxy; int i, count; gboolean is_default, powered; char *name; count = gtk_notebook_get_n_pages(notebook); gtk_tree_model_get(model, iter, BLUETOOTH_COLUMN_PROXY, &proxy, BLUETOOTH_COLUMN_DEFAULT, &is_default, BLUETOOTH_COLUMN_POWERED, &powered, BLUETOOTH_COLUMN_NAME, &name, -1); for (i = 0; i < count; i++) { GtkWidget *widget; adapter_data *adapter; widget = gtk_notebook_get_nth_page(notebook, i); if (widget == NULL) continue; adapter = g_object_get_data(G_OBJECT(widget), "adapter"); if (adapter == NULL) continue; adapter->is_default = is_default; if (proxy == NULL || adapter->proxy == NULL) continue; if (g_str_equal (dbus_g_proxy_get_path (proxy), dbus_g_proxy_get_path (adapter->proxy)) != FALSE) { if (is_default != FALSE && powered != FALSE) gtk_notebook_set_current_page (notebook, i); /* We usually get an adapter_added before the device * is powered, so we set the name here instead */ if (name) gtk_entry_set_text(GTK_ENTRY(adapter->entry), name); } } g_object_unref (proxy); g_free (name); }
int main() { DBusGConnection* connection; DBusGProxy* proxy; GError* error = NULL; char* path = "/Test/Proxy/Path"; g_type_init(); connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (connection == NULL) { std_log(LOG_FILENAME_LINE, "Failed to open connection to bus: %s\n", error->message); g_error_free (error); create_xml(1); return 1; } proxy = dbus_g_proxy_new_for_name(connection, "Test.Glib.Proxy.Path", path, "Test.Proxy.Interface"); if(strcmp(path, dbus_g_proxy_get_path(proxy))) { std_log(LOG_FILENAME_LINE, "Fail to check interface %s", path); create_xml(1); return 1; } std_log(LOG_FILENAME_LINE, "Test Successful"); create_xml(0); return 0; }
static void method_call(DBusGProxy *proxy, const char *method, const char *path) { if (proxy == NULL) return; g_print("%s ( %s, %s )\n", method, dbus_g_proxy_get_path(proxy), path); if (path == NULL) { if (dbus_g_proxy_begin_call_with_timeout(proxy, method, method_callback, NULL, NULL, 120 * 1000, G_TYPE_INVALID) == FALSE) { g_print("Can't call method %s\n", method); g_object_unref(proxy); return; } } else { if (dbus_g_proxy_begin_call(proxy, method, method_callback, NULL, NULL, DBUS_TYPE_G_OBJECT_PATH, path, G_TYPE_INVALID) == FALSE) { g_print("Can't call method %s (%s)\n", method, path); g_object_unref(proxy); return; } } }
static void set_network_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) { NMSupplicantInfo *info = (NMSupplicantInfo *) user_data; NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (info->interface); GError *err = NULL; guint tmp; if (!dbus_g_proxy_end_call (proxy, call_id, &err, G_TYPE_UINT, &tmp, G_TYPE_INVALID)) { nm_log_warn (LOGD_SUPPLICANT, "Couldn't set network config: %s.", err->message); emit_error_helper (info->interface, err); g_error_free (err); } else { DBusGProxyCall *call; info = nm_supplicant_info_new (info->interface, priv->iface_proxy, priv->assoc_pcalls); call = dbus_g_proxy_begin_call (priv->iface_proxy, "selectNetwork", select_network_cb, info, nm_supplicant_info_destroy, DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (proxy), G_TYPE_INVALID); nm_supplicant_info_set_call (info, call); } }
static void connect_callback(GtkButton *button, gpointer user_data) { GtkTreeModel *model; GtkTreeIter iter; DBusGProxy *proxy; const gchar *path; gboolean enabled; if (gtk_tree_selection_get_selected(selection, &model, &iter) == FALSE) return; gtk_tree_model_get(model, &iter, CONNMAN_COLUMN_PROXY, &proxy, CONNMAN_COLUMN_ENABLED, &enabled, -1); path = dbus_g_proxy_get_path(proxy); if (enabled == FALSE) connman_client_connect(client, path); else connman_client_disconnect(client, path); g_object_unref(proxy); if (enabled == FALSE) g_object_set(button_connect, "label", GTK_STOCK_DISCONNECT, NULL); else g_object_set(button_connect, "label", GTK_STOCK_CONNECT, NULL); }
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 void changed_callback(GtkComboBox *combo, gpointer user_data) { GtkTreeModel *model = gtk_combo_box_get_model(combo); GtkTreeIter iter; DBusGProxy *proxy; gchar *path; gboolean enabled; if (gtk_combo_box_get_active_iter(combo, &iter) == FALSE) return; path = g_object_get_data(G_OBJECT(button_enabled), "device"); g_free(path); gtk_tree_model_get(model, &iter, CONNMAN_COLUMN_PROXY, &proxy, CONNMAN_COLUMN_ENABLED, &enabled, -1); path = g_strdup(dbus_g_proxy_get_path(proxy)); g_object_set_data(G_OBJECT(button_enabled), "device", path); g_object_unref(proxy); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button_enabled), enabled); gtk_widget_set_sensitive(button_refresh, enabled); model = connman_client_get_network_model(client, path); gtk_tree_view_set_model(GTK_TREE_VIEW(tree_networks), model); g_object_unref(model); }
static gboolean network_model_have_service_in_store (GtkListStore *store, GtkTreeIter *iter, const gchar *path) { gboolean cont, found = FALSE; DBusGProxy *service; cont = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), iter); while (cont) { gtk_tree_model_get (GTK_TREE_MODEL (store), iter, CARRICK_COLUMN_PROXY, &service, -1); if (!service) break; found = g_str_equal (path, dbus_g_proxy_get_path (service)); g_object_unref (service); if (found) break; cont = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), iter); } return found; }
static void modem_removed (DBusGProxy *proxy, const char *path, gpointer user_data) { PluginInfo *info = user_data; GSList *iter; DBusGProxy *found = NULL; g_return_if_fail (path != NULL); g_message ("%s: (%s) modem removed", __func__, path); /* Clean up if a modem gets removed */ for (iter = info->modem_proxies; iter; iter = g_slist_next (iter)) { if (!strcmp (path, dbus_g_proxy_get_path (DBUS_G_PROXY (iter->data)))) { found = iter->data; break; } } if (found) { info->modem_proxies = g_slist_remove (info->modem_proxies, found); g_object_unref (found); } }
static gboolean cancel_request(DBusGMethodInvocation *context, gpointer user_data) { DBusGProxy *adapter = user_data; GList *list; GError *result; input_data *input; input = g_new0(input_data, 1); input->path = g_strdup(dbus_g_proxy_get_path(adapter)); list = g_list_find_custom(input_list, input, input_compare); g_free(input->path); g_free(input); if (!list || !list->data) return FALSE; input = list->data; close_notification(); result = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT, "Agent callback cancelled"); dbus_g_method_return_error(input->context, result); input_free(input); return TRUE; }
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); } } }
/* This is the handler for the Changed() signal emitted by UDisks. */ static void udisks_changed_signal_cb(DBusGProxy *sensor_proxy) { const gchar *path = dbus_g_proxy_get_path(sensor_proxy); DevInfo *info; info = g_hash_table_lookup(devices, path); if (info) { info->changed = TRUE; } }
static void _list_contains_child (GtkWidget *item, find_data *data) { CarrickServiceItem *service_item = CARRICK_SERVICE_ITEM (item); DBusGProxy *proxy = carrick_service_item_get_proxy (service_item); const gchar *path; const gchar *data_path = dbus_g_proxy_get_path (data->service); if (proxy) { path = dbus_g_proxy_get_path (proxy); if (g_str_equal (data_path, path)) { data->widget = item; } } }
static int compare_device_path (NMDevice *nm_device, char *device_path) { const char *path; path = dbus_g_proxy_get_path (nm_device->device_proxy); if (G_UNLIKELY (path == NULL)) return -1; return strcmp (path, device_path); }
static void auth_dialog (DBusGProxy *adapter, DBusGProxy *device, const char *name, const char *long_name, const char *uuid, DBusGMethodInvocation *context) { GtkBuilder *xml; GtkWidget *dialog; GtkWidget *button; char *str; input_data *input; input = g_new0 (input_data, 1); input->path = g_strdup (dbus_g_proxy_get_path (adapter)); input->uuid = g_strdup (uuid); input->device = g_object_ref (device); input->context = context; xml = gtk_builder_new (); if (gtk_builder_add_from_file (xml, "authorisation-dialogue.ui", NULL) == 0) gtk_builder_add_from_file (xml, PKGDATADIR "/authorisation-dialogue.ui", NULL); dialog = GTK_WIDGET (gtk_builder_get_object (xml, "dialog")); gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); if (notification_supports_actions () != FALSE) gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE); else gtk_window_set_focus_on_map (GTK_WINDOW (dialog), FALSE); gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE); input->dialog = dialog; /* translators: Whether to grant access to a particular service */ str = g_strdup_printf (_("Grant access to '%s'"), uuid); g_object_set (G_OBJECT (dialog), "text", str, NULL); g_free (str); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("Device %s wants access to the service '%s'."), long_name, uuid); button = GTK_WIDGET (gtk_builder_get_object (xml, "always_button")); input->button = button; input_list = g_list_append (input_list, input); g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (auth_callback), input); enable_blinking (); }
static gboolean network_model_have_service_by_proxy (GtkListStore *store, GtkTreeIter *iter, DBusGProxy *service) { const gchar *path; if (!service) return FALSE; path = dbus_g_proxy_get_path (service); return network_model_have_service_by_path (store, iter, path); }
static void confirm_dialog (DBusGProxy *adapter, DBusGProxy *device, const char *name, const char *long_name, const char *value, DBusGMethodInvocation *context) { GtkWidget *dialog; GtkBuilder *xml; char *str; input_data *input; input = g_new0 (input_data, 1); input->path = g_strdup (dbus_g_proxy_get_path(adapter)); input->device = g_object_ref (device); input->context = context; xml = gtk_builder_new (); if (gtk_builder_add_from_file (xml, "confirm-dialogue.ui", NULL) == 0) gtk_builder_add_from_file (xml, PKGDATADIR "/confirm-dialogue.ui", NULL); dialog = GTK_WIDGET (gtk_builder_get_object (xml, "dialog")); gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); if (notification_supports_actions () != FALSE) gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE); else gtk_window_set_focus_on_map (GTK_WINDOW (dialog), FALSE); gtk_window_set_urgency_hint (GTK_WINDOW (dialog), TRUE); input->dialog = dialog; str = g_strdup_printf (_("Device '%s' wants to pair with this computer"), name); g_object_set (G_OBJECT (dialog), "text", str, NULL); g_free (str); str = g_strdup_printf ("<b>%s</b>", value); gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog), _("Please confirm whether the PIN '%s' matches the one on device %s."), str, long_name); g_free (str); input_list = g_list_append (input_list, input); g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (confirm_callback), input); enable_blinking (); }
void nm_supplicant_interface_disconnect (NMSupplicantInterface * self) { NMSupplicantInterfacePrivate *priv; g_return_if_fail (NM_IS_SUPPLICANT_INTERFACE (self)); priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); /* Clear and cancel all pending calls related to a prior * connection attempt. */ cancel_all_callbacks (priv->assoc_pcalls); /* Don't do anything if there is no connection to the supplicant yet. */ if (!priv->iface_proxy) return; /* Don't try to disconnect if the supplicant interface is already * disconnected. */ if (priv->con_state == NM_SUPPLICANT_INTERFACE_CON_STATE_DISCONNECTED || priv->con_state == NM_SUPPLICANT_INTERFACE_CON_STATE_INACTIVE) { if (priv->net_proxy) { g_object_unref (priv->net_proxy); priv->net_proxy = NULL; } return; } /* Remove any network that was added by NetworkManager */ if (priv->net_proxy) { dbus_g_proxy_begin_call (priv->iface_proxy, "removeNetwork", remove_network_cb, NULL, NULL, DBUS_TYPE_G_OBJECT_PATH, dbus_g_proxy_get_path (priv->net_proxy), G_TYPE_INVALID); g_object_unref (priv->net_proxy); priv->net_proxy = NULL; } dbus_g_proxy_begin_call (priv->iface_proxy, "disconnect", disconnect_cb, NULL, NULL, G_TYPE_INVALID); }
static void drag_data_received(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time, gpointer user_data) { GtkTreeModel *model = user_data; GtkTreePath *path; GtkTreeIter iter; DBusGProxy *source, *proxy = NULL; gboolean success = FALSE; if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), x, y, &path, NULL, NULL, NULL) == FALSE) return; if (gtk_tree_model_get_iter(model, &iter, path) == FALSE) goto done; gtk_tree_model_get(model, &iter, CONNMAN_COLUMN_PROXY, &proxy, -1); if (data == NULL || data->length == 0) goto done; if (info != CONNMAN_SERVICE_MOVE) goto done; if (gtk_tree_model_get_iter_from_string(model, &iter, (gchar *) data->data) == FALSE) goto done; g_print("%s -> %s\n", (gchar *) data->data, gtk_tree_path_to_string(path)); gtk_tree_model_get(model, &iter, CONNMAN_COLUMN_PROXY, &source, -1); method_call(source, "MoveBefore", dbus_g_proxy_get_path(proxy)); g_object_unref(proxy); success = TRUE; done: gtk_tree_path_free(path); gtk_drag_finish(context, success, FALSE, time); }
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_removed (DBusGProxy *proxy, const char *path, gpointer user_data) { NmaBtDevice *self = NMA_BT_DEVICE (user_data); NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); GSList *iter; g_return_if_fail (path != NULL); g_message ("%s: (%s) modem removed", __func__, path); /* Clean up if a modem gets removed */ for (iter = priv->modem_proxies; iter; iter = g_slist_next (iter)) { if (!strcmp (path, dbus_g_proxy_get_path (DBUS_G_PROXY (iter->data)))) { priv->modem_proxies = g_slist_remove (priv->modem_proxies, iter->data); g_object_unref (iter->data); break; } } }
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); }
static void udisks_device_umount_cb(DBusGProxy *proxy, GError *error, gpointer userdata) { wmvm_volume_set_error(dbus_g_proxy_get_path(proxy), error != NULL); return; }
static void modem_get_all_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) { NmaBtDevice *self = NMA_BT_DEVICE (user_data); NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); const char *path; GHashTable *properties = NULL; GError *error = NULL; GValue *value; NMDeviceType devtype = NM_DEVICE_TYPE_UNKNOWN; path = dbus_g_proxy_get_path (proxy); g_message ("%s: (%s) processing GetAll reply", __func__, path); if (!dbus_g_proxy_end_call (proxy, call, &error, DBUS_TYPE_G_MAP_OF_VARIANT, &properties, G_TYPE_INVALID)) { g_warning ("%s: (%s) Error getting modem properties: (%d) %s", __func__, path, error ? error->code : -1, (error && error->message) ? error->message : "(unknown)"); g_error_free (error); goto out; } /* check whether this is the device we care about */ value = g_hash_table_lookup (properties, "Device"); if (value && G_VALUE_HOLDS_STRING (value) && g_value_get_string (value)) { char *iface_basename = g_path_get_basename (priv->rfcomm_iface); const char *modem_iface = g_value_get_string (value); if (strcmp (iface_basename, modem_iface) == 0) { /* yay, found it! */ value = g_hash_table_lookup (properties, "Type"); if (value && G_VALUE_HOLDS_UINT (value)) { switch (g_value_get_uint (value)) { case 1: devtype = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS; break; case 2: devtype = NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO; break; default: g_message ("%s: (%s) unknown modem type", __func__, path); break; } } } else { g_message ("%s: (%s) (%s) not the modem we're looking for (%s)", __func__, path, modem_iface, iface_basename); } g_free (iface_basename); } else g_message ("%s: (%s) modem had no 'Device' property", __func__, path); g_hash_table_unref (properties); /* Launch wizard! */ start_wizard (self, path, devtype); out: g_message ("%s: finished", __func__); }
static void carrick_list_drag_end (GtkWidget *widget, GdkDragContext *context, CarrickList *list) { CarrickListPrivate *priv = list->priv; GList *children; children = gtk_container_get_children (GTK_CONTAINER (priv->box)); /* destroy the popup window */ g_object_ref (widget); gtk_container_remove (GTK_CONTAINER (priv->drag_window), widget); gtk_widget_destroy (priv->drag_window); priv->drag_window = NULL; /* insert the widget into the list */ gtk_box_pack_start (GTK_BOX (priv->box), widget, FALSE, FALSE, 2); gtk_box_reorder_child (GTK_BOX (priv->box), widget, priv->drop_position); g_object_unref (widget); if (priv->drop_position != priv->drag_position) { GtkWidget *other_widget; DBusGProxy *service, * other_service; const gchar *path; move_data *data = NULL; service = carrick_service_item_get_proxy (CARRICK_SERVICE_ITEM (widget)); data = g_slice_new0 (move_data); data->list = GTK_WIDGET (list->priv->box); data->item = widget; data->pos = priv->drag_position; if (priv->drop_position == 0) { other_widget = g_list_nth_data (children, 0); other_service = carrick_service_item_get_proxy (CARRICK_SERVICE_ITEM (other_widget)); path = dbus_g_proxy_get_path (other_service); net_connman_Service_move_before_async (service, path, move_notify_cb, data); } else { other_widget = g_list_nth_data (children, priv->drop_position - 1); other_service = carrick_service_item_get_proxy (CARRICK_SERVICE_ITEM (other_widget)); path = dbus_g_proxy_get_path (other_service); net_connman_Service_move_after_async (service, path, move_notify_cb, data); } } g_list_free (children); }
static void create_adapter(adapter_data *adapter) { GHashTable *hash = NULL; GValue *value; DBusGProxy *default_proxy; const gchar *name; gboolean powered, discoverable; guint timeout; GtkWidget *mainbox; GtkWidget *vbox; GtkWidget *alignment; GtkWidget *table; GtkWidget *label; GtkWidget *image; GtkWidget *button; GtkWidget *entry; GtkWidget *buttonbox; int page_num; dbus_g_proxy_call(adapter->proxy, "GetProperties", NULL, G_TYPE_INVALID, dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &hash, G_TYPE_INVALID); if (hash != NULL) { value = g_hash_table_lookup(hash, "Name"); name = value ? g_value_get_string(value) : NULL; value = g_hash_table_lookup(hash, "Powered"); powered = value ? g_value_get_boolean(value) : FALSE; value = g_hash_table_lookup(hash, "Discoverable"); discoverable = value ? g_value_get_boolean(value) : FALSE; value = g_hash_table_lookup(hash, "DiscoverableTimeout"); timeout = value ? g_value_get_uint(value) : 0; } else { name = NULL; powered = FALSE; discoverable = FALSE; timeout = 0; } adapter->powered = powered; adapter->discoverable = discoverable; adapter->timeout_value = timeout; default_proxy = bluetooth_client_get_default_adapter (client); if (default_proxy != NULL) { adapter->is_default = g_str_equal (dbus_g_proxy_get_path (default_proxy), dbus_g_proxy_get_path (adapter->proxy)); g_object_unref (default_proxy); } mainbox = gtk_vbox_new(FALSE, 6); gtk_container_set_border_width(GTK_CONTAINER(mainbox), 12); page_num = gtk_notebook_prepend_page(GTK_NOTEBOOK(adapter->notebook), mainbox, NULL); adapter->child = mainbox; vbox = gtk_vbox_new(FALSE, 6); gtk_box_pack_start(GTK_BOX(mainbox), vbox, FALSE, TRUE, 0); /* The discoverable checkbox */ button = gtk_check_button_new_with_mnemonic (_("Make computer _visible")); if (powered == FALSE) discoverable = FALSE; if (discoverable != FALSE && timeout == 0) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); else if (discoverable == FALSE) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE); else { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button), TRUE); } gtk_widget_set_sensitive (button, adapter->powered); adapter->button_discoverable = button; adapter->signal_discoverable = g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(discoverable_changed_cb), adapter); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); /* The friendly name */ vbox = gtk_vbox_new(FALSE, 6); gtk_box_pack_start(GTK_BOX(mainbox), vbox, FALSE, FALSE, 0); label = create_label(_("Friendly name")); gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); alignment = gtk_alignment_new (0.5, 0.5, 1, 1); gtk_widget_show (alignment); gtk_box_pack_start (GTK_BOX (vbox), alignment, TRUE, TRUE, 0); gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0); entry = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(entry), 248); gtk_widget_set_size_request(entry, 240, -1); gtk_container_add (GTK_CONTAINER (alignment), entry); if (name != NULL) gtk_entry_set_text(GTK_ENTRY(entry), name); adapter->entry = entry; adapter->name_vbox = vbox; g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(name_callback), adapter); g_signal_connect(G_OBJECT(entry), "focus-out-event", G_CALLBACK(focus_callback), adapter); gtk_widget_set_sensitive (adapter->name_vbox, adapter->powered); /* The known devices */ table = gtk_table_new(2, 2, FALSE); gtk_box_pack_start(GTK_BOX(mainbox), table, TRUE, TRUE, 0); label = create_label(_("Devices")); gtk_table_attach(GTK_TABLE(table), label, 0, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 6); /* Note that this will only ever show the devices on the default * adapter, this is on purpose */ adapter->chooser = bluetooth_chooser_new (NULL); g_object_set (adapter->chooser, "show-searching", FALSE, "show-device-type", FALSE, "show-device-category", FALSE, "show-pairing", TRUE, "show-connected", TRUE, "device-category-filter", BLUETOOTH_CATEGORY_PAIRED_OR_TRUSTED, NULL); g_signal_connect (adapter->chooser, "notify::device-selected", G_CALLBACK(device_selected_cb), adapter); gtk_table_attach(GTK_TABLE(table), adapter->chooser, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); adapter->devices_table = table; buttonbox = gtk_vbutton_box_new(); gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonbox), GTK_BUTTONBOX_START); gtk_box_set_spacing(GTK_BOX(buttonbox), 6); gtk_box_set_homogeneous(GTK_BOX(buttonbox), FALSE); gtk_table_attach(GTK_TABLE(table), buttonbox, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 6, 6); button = gtk_button_new_with_mnemonic(_("Set up _new device...")); image = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON); gtk_button_set_image(GTK_BUTTON(button), image); gtk_box_pack_start(GTK_BOX(buttonbox), button, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(wizard_callback), adapter); button = gtk_button_new_with_label(_("Disconnect")); image = gtk_image_new_from_stock(GTK_STOCK_DISCONNECT, GTK_ICON_SIZE_BUTTON); gtk_button_set_image(GTK_BUTTON(button), image); gtk_box_pack_end(GTK_BOX(buttonbox), button, FALSE, FALSE, 0); gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(buttonbox), button, TRUE); gtk_widget_set_sensitive(button, FALSE); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(disconnect_callback), adapter); adapter->button_disconnect = button; button = gtk_button_new_with_mnemonic(_("_Remove")); image = gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_BUTTON); gtk_button_set_image(GTK_BUTTON(button), image); gtk_box_pack_end(GTK_BOX(buttonbox), button, FALSE, FALSE, 0); gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(buttonbox), button, TRUE); gtk_widget_set_sensitive(button, FALSE); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(remove_callback), adapter); adapter->button_delete = button; gtk_widget_set_sensitive (adapter->devices_table, adapter->powered); g_object_set_data(G_OBJECT(mainbox), "adapter", adapter); gtk_widget_show_all(mainbox); if (adapter->is_default != FALSE) gtk_notebook_set_current_page (GTK_NOTEBOOK (adapter->notebook), page_num); }
/** * Callback for org.bluez.Adapter.DeviceCreated signal */ static void device_created(DBusGProxy *proxy, const char *path, gpointer user_data) { connect_device_signals(path, dbus_g_proxy_get_path(proxy)); DEBUG("device created: %s", path); }
/** * Callback for org.bluez.HealthDevice.ChannelConnected signal * Reused by CreateChannel callback (channel initiation) */ static void channel_connected(DBusGProxy *proxy, const char *path, gpointer user_data) { int fd; guint64 handle; device_object *dev; const char *device_path; channel_object *c = get_channel(path); if (c) { if (c->initiated_by_us && c->fd >= 0) { DEBUG("initiated channel already connected: %s", path); return; } } DEBUG("channel connected: %s", path); // Need to use non-GLib code here because GLib still does not have // the UNIX FD type. DBusMessage *msg, *reply; DBusError err; msg = dbus_message_new_method_call("org.bluez", path, "org.bluez.HealthChannel", "Acquire"); if (!msg) { ERROR(" network:dbus Can't allocate new method call"); return; } dbus_error_init(&err); reply = dbus_connection_send_with_reply_and_block( dbus_g_connection_get_connection(conn), msg, -1, &err); dbus_message_unref(msg); if (!reply) { DEBUG(" network:dbus Can't acquire FD"); if (dbus_error_is_set(&err)) { ERROR("%s", err.message); dbus_error_free(&err); return; } } if (!dbus_message_get_args(reply, &err, DBUS_TYPE_UNIX_FD, &fd, DBUS_TYPE_INVALID)) { DEBUG(" network:dbus Can't get reply arguments"); if (dbus_error_is_set(&err)) { ERROR("%s", err.message); dbus_error_free(&err); dbus_message_unref(reply); return; } } dbus_message_unref(reply); // dbus_connection_flush(dbus_g_connection_get_connection(conn)); DEBUG("File descriptor: %d", fd); device_path = dbus_g_proxy_get_path(proxy); handle = add_channel(path, device_path, fd, user_data != NULL); if (!handle) { // channel already known, reconnected // or channel is secondary return; } dev = get_device_object(device_path); if (dev) { device_connected(handle, dev->addr); } else { ERROR("Channel from unknown device: %s", device_path); device_connected(handle, device_path); } }
static void update_device_list (GtkTreeIter *parent) { GtkUIManager *uimanager; GtkTreeIter iter; gboolean cont; guint num_devices; GList *actions, *l; num_devices = 0; uimanager = GTK_UI_MANAGER (gtk_builder_get_object (xml, "bluetooth-applet-ui-manager")); if (parent == NULL) { /* No default adapter? Remove everything */ actions = gtk_action_group_list_actions (devices_action_group); g_list_foreach (actions, (GFunc) remove_action_item, uimanager); g_list_free (actions); goto done; } /* Get a list of actions, and we'll remove the ones with a * device in the list. We remove the submenu items first */ actions = gtk_action_group_list_actions (devices_action_group); for (l = actions; l != NULL; l = l->next) { if (bluetooth_verify_address (gtk_action_get_name (l->data)) == FALSE) l->data = NULL; } actions = g_list_remove_all (actions, NULL); cont = gtk_tree_model_iter_children (devices_model, &iter, parent); while (cont) { GHashTable *services; DBusGProxy *proxy; char *alias, *address, **uuids, *name; gboolean is_connected; BluetoothType type; GtkAction *action, *status, *oper; gtk_tree_model_get (devices_model, &iter, BLUETOOTH_COLUMN_PROXY, &proxy, BLUETOOTH_COLUMN_ADDRESS, &address, BLUETOOTH_COLUMN_SERVICES, &services, BLUETOOTH_COLUMN_ALIAS, &alias, BLUETOOTH_COLUMN_UUIDS, &uuids, BLUETOOTH_COLUMN_TYPE, &type, -1); if (device_has_submenu ((const char **) uuids, services, type) == FALSE || address == NULL || proxy == NULL || alias == NULL) { if (proxy != NULL) g_object_unref (proxy); if (services != NULL) g_hash_table_unref (services); g_strfreev (uuids); g_free (alias); g_free (address); cont = gtk_tree_model_iter_next (devices_model, &iter); continue; } action = gtk_action_group_get_action (devices_action_group, address); oper = NULL; status = NULL; if (action) { char *action_name; actions = g_list_remove (actions, action); action_name = g_strdup_printf ("%s-status", address); status = gtk_action_group_get_action (devices_action_group, action_name); g_free (action_name); action_name = g_strdup_printf ("%s-action", address); oper = gtk_action_group_get_action (devices_action_group, action_name); g_free (action_name); } /* If one service is connected, then we're connected */ is_connected = FALSE; if (services != NULL) { GList *list, *l; list = g_hash_table_get_values (services); for (l = list; l != NULL; l = l->next) { BluetoothStatus val = GPOINTER_TO_INT (l->data); if (val == BLUETOOTH_STATUS_CONNECTED || val == BLUETOOTH_STATUS_PLAYING) { is_connected = TRUE; break; } } g_list_free (list); } name = escape_label_for_action (alias); if (action == NULL) { guint menu_merge_id; char *action_path; /* The menu item with descendants */ action = gtk_action_new (address, name, NULL, NULL); gtk_action_group_add_action (devices_action_group, action); g_object_unref (action); menu_merge_id = gtk_ui_manager_new_merge_id (uimanager); gtk_ui_manager_add_ui (uimanager, menu_merge_id, "/bluetooth-applet-popup/devices-placeholder", address, address, GTK_UI_MANAGER_MENU, FALSE); g_object_set_data_full (G_OBJECT (action), "merge-id", GUINT_TO_POINTER (menu_merge_id), NULL); /* The status menu item */ status = add_menu_item (address, "status", is_connected ? _("Connected") : _("Disconnected"), uimanager, menu_merge_id, NULL); gtk_action_set_sensitive (status, FALSE); if (services != NULL) { action_path = g_strdup_printf ("/bluetooth-applet-popup/devices-placeholder/%s/%s-status", address, address); action_set_bold (uimanager, status, action_path); g_free (action_path); } else { gtk_action_set_visible (status, FALSE); } /* The connect button */ oper = add_menu_item (address, "action", is_connected ? _("Disconnect") : _("Connect"), uimanager, menu_merge_id, G_CALLBACK (on_connect_activate)); if (services == NULL) gtk_action_set_visible (oper, FALSE); add_separator_item (address, "connect-sep", uimanager, menu_merge_id); /* The Send to... button */ if (device_has_uuid ((const char **) uuids, "OBEXObjectPush") != FALSE) { add_menu_item (address, "sendto", _("Send files..."), uimanager, menu_merge_id, G_CALLBACK (sendto_callback)); g_object_set_data_full (G_OBJECT (action), "alias", g_strdup (alias), g_free); } if (device_has_uuid ((const char **) uuids, "OBEXFileTransfer") != FALSE) { add_menu_item (address, "browse", _("Browse files..."), uimanager, menu_merge_id, G_CALLBACK (browse_callback)); } add_separator_item (address, "files-sep", uimanager, menu_merge_id); if (type == BLUETOOTH_TYPE_KEYBOARD && program_available (KEYBOARD_PREFS)) { add_menu_item (address, "keyboard", _("Open Keyboard Preferences..."), uimanager, menu_merge_id, G_CALLBACK (keyboard_callback)); } if (type == BLUETOOTH_TYPE_MOUSE && program_available (MOUSE_PREFS)) { add_menu_item (address, "mouse", _("Open Mouse Preferences..."), uimanager, menu_merge_id, G_CALLBACK (mouse_callback)); } if ((type == BLUETOOTH_TYPE_HEADSET || type == BLUETOOTH_TYPE_HEADPHONES || type == BLUETOOTH_TYPE_OTHER_AUDIO) && program_available (SOUND_PREFS)) { add_menu_item (address, "sound", _("Open Sound Preferences..."), uimanager, menu_merge_id, G_CALLBACK (sound_callback)); } } else { gtk_action_set_label (action, name); gtk_action_set_visible (status, services != NULL); gtk_action_set_visible (oper, services != NULL); if (services != NULL) { set_device_status_label (address, is_connected ? CONNECTED : DISCONNECTED); gtk_action_set_label (oper, is_connected ? _("Disconnect") : _("Connect")); } } g_free (name); if (oper != NULL) { g_object_set_data_full (G_OBJECT (oper), "connected", GINT_TO_POINTER (is_connected ? CONNECTED : DISCONNECTED), NULL); g_object_set_data_full (G_OBJECT (oper), "device-path", g_strdup (dbus_g_proxy_get_path (proxy)), g_free); } /* And now for the trick of the day */ if (is_connected != FALSE) { char *path; path = g_strdup_printf ("/bluetooth-applet-popup/devices-placeholder/%s", address); action_set_bold (uimanager, action, path); g_free (path); } num_devices++; if (proxy != NULL) g_object_unref (proxy); if (services != NULL) g_hash_table_unref (services); g_strfreev (uuids); g_free (alias); g_free (address); cont = gtk_tree_model_iter_next (devices_model, &iter); } /* Remove the left-over devices */ g_list_foreach (actions, (GFunc) remove_action_item, uimanager); g_list_free (actions); done: gtk_ui_manager_ensure_update (uimanager); gtk_action_set_visible (GTK_ACTION (gtk_builder_get_object (xml, "devices-label")), num_devices > 0); }
static void modem_get_all_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) { PluginInfo *info = user_data; const char *path; GHashTable *properties = NULL; GError *error = NULL; GValue *value; BMDeviceType devtype = BM_DEVICE_TYPE_UNKNOWN; path = dbus_g_proxy_get_path (proxy); g_message ("%s: (%s) processing GetAll reply", __func__, path); if (!dbus_g_proxy_end_call (proxy, call, &error, DBUS_TYPE_G_MAP_OF_VARIANT, &properties, G_TYPE_INVALID)) { g_warning ("%s: (%s) Error getting modem properties: (%d) %s", __func__, path, error ? error->code : -1, (error && error->message) ? error->message : "(unknown)"); g_error_free (error); goto out; } /* check whether this is the device we care about */ value = g_hash_table_lookup (properties, "Device"); if (value && G_VALUE_HOLDS_STRING (value) && g_value_get_string (value)) { char *iface_basename = g_path_get_basename (info->rfcomm_iface); const char *modem_iface = g_value_get_string (value); if (!strcmp (iface_basename, modem_iface)) { /* yay, found it! */ value = g_hash_table_lookup (properties, "Type"); if (value && G_VALUE_HOLDS_UINT (value)) { switch (g_value_get_uint (value)) { case 1: devtype = BM_DEVICE_TYPE_GSM; break; case 2: devtype = BM_DEVICE_TYPE_CDMA; break; default: g_message ("%s: (%s) unknown modem type", __func__, path); break; } } } else { g_message ("%s: (%s) (%s) not the modem we're looking for (%s)", __func__, path, modem_iface, iface_basename); } g_free (iface_basename); } else g_message ("%s: (%s) modem had no 'Device' property", __func__, path); g_hash_table_unref (properties); if (devtype != BM_DEVICE_TYPE_UNKNOWN) { GtkWidget *parent; if (info->wizard) { g_message ("%s: (%s) oops! not starting Wizard as one is already in progress", __func__, path); goto out; } g_message ("%s: (%s) starting the mobile wizard", __func__, path); g_source_remove (info->dun_timeout_id); info->dun_timeout_id = 0; parent = gtk_widget_get_toplevel (info->hbox); #if GTK_CHECK_VERSION(2,18,0) if (gtk_widget_is_toplevel (parent)) { #else if (GTK_WIDGET_TOPLEVEL (parent)) { #endif info->window_group = gtk_window_group_new (); gtk_window_group_add_window (info->window_group, GTK_WINDOW (parent)); } else { parent = NULL; info->window_group = NULL; } /* Start the mobile wizard */ info->wizard = mobile_wizard_new (parent ? GTK_WINDOW (parent) : NULL, info->window_group, devtype, FALSE, wizard_done_cb, info); mobile_wizard_present (info->wizard); } out: g_message ("%s: finished", __func__); } static void modem_added (DBusGProxy *proxy, const char *path, gpointer user_data) { PluginInfo *info = user_data; DBusGProxy *props_proxy; g_return_if_fail (path != NULL); g_message ("%s: (%s) modem found", __func__, path); /* Create a proxy for the modem and get its properties */ props_proxy = dbus_g_proxy_new_for_name (info->bus, MM_SERVICE, path, "org.freedesktop.DBus.Properties"); g_assert (proxy); info->modem_proxies = g_slist_append (info->modem_proxies, props_proxy); g_message ("%s: (%s) calling GetAll...", __func__, path); dbus_g_proxy_begin_call (props_proxy, "GetAll", modem_get_all_cb, info, NULL, G_TYPE_STRING, MM_MODEM_INTERFACE, G_TYPE_INVALID); }