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; }
int main(int argc, char *argv[]) { GApplication *app; #ifdef HAVE_APP_INDICATOR AppIndicator *indicator; #else GtkStatusIcon *statusicon; #endif /* HAVE_APP_INDICATOR */ GtkWidget *menu; GOptionContext *context; GError *error = NULL; bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); g_type_init (); /* Parse command-line options */ context = g_option_context_new (N_("- Bluetooth applet")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) { g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"), error->message, argv[0]); g_error_free (error); return 1; } if (option_debug == FALSE) { GError *error = NULL; app = g_application_new ("org.cinnamon.Bluetooth.applet", G_APPLICATION_FLAGS_NONE); if (!g_application_register (app, NULL, &error)) { g_object_unref (app); g_warning ("%s", error->message); g_error_free (error); return 1; } if (g_application_get_is_remote (app)) { g_object_unref (app); g_warning ("Applet is already running, exiting"); return 0; } } else { app = NULL; } g_set_application_name(_("Bluetooth Applet")); gtk_window_set_default_icon_name("bluetooth"); applet = g_object_new (BLUETOOTH_TYPE_APPLET, NULL); g_signal_connect (G_OBJECT (applet), "notify::killswitch-state", G_CALLBACK (killswitch_state_changed), NULL); menu = create_popupmenu(); #ifdef HAVE_APP_INDICATOR indicator = init_notification(); app_indicator_set_menu(indicator, GTK_MENU(menu)); app_indicator_set_title(indicator, _("Bluetooth")); gsettings = g_settings_new (BLUETOOTH_INDICATOR_GSETTINGS_SCHEMA_ID); g_signal_connect (gsettings, "changed::" GSETTINGS_VISIBLE_KEY, G_CALLBACK(update_icon_visibility), NULL); #else statusicon = init_notification(); #endif /* HAVE_APP_INDICATOR */ g_signal_connect (G_OBJECT (applet), "devices-changed", G_CALLBACK (update_device_list), NULL); g_signal_connect (G_OBJECT (applet), "notify::discoverable", G_CALLBACK (update_discoverability), NULL); g_signal_connect (G_OBJECT (applet), "notify::show-full-menu", G_CALLBACK (update_menu_items), NULL); killswitch_state_changed ((GObject*) applet, NULL, NULL); update_menu_items ((GObject*) applet, NULL, NULL); update_discoverability ((GObject*) applet, NULL, NULL); update_device_list (applet, NULL); update_icon_visibility(); #ifndef HAVE_APP_INDICATOR g_signal_connect(statusicon, "activate", G_CALLBACK(activate_callback), menu); g_signal_connect(statusicon, "popup-menu", G_CALLBACK(popup_callback), menu); #endif /* HAVE_APP_INDICATOR */ setup_agents(applet); gtk_main(); gtk_widget_destroy(menu); cleanup_notification(); g_object_unref(applet); if (app != NULL) g_object_unref (app); return 0; }
int main(int argc, char *argv[]) { UniqueApp *app; GtkStatusIcon *statusicon; GtkWidget *menu; GOptionContext *context; GError *error = NULL; bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #if !GLIB_CHECK_VERSION (2, 36, 0) g_type_init (); #endif /* Parse command-line options */ context = g_option_context_new (N_("- Bluetooth applet")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) { g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"), error->message, argv[0]); g_error_free (error); return 1; } if (option_debug == FALSE) { app = unique_app_new ("org.mate.Bluetooth.applet", NULL); if (unique_app_is_running (app)) { gdk_notify_startup_complete (); g_warning ("Applet is already running, exiting"); return 0; } } else { app = NULL; } g_set_application_name(_("Bluetooth Applet")); gtk_window_set_default_icon_name("bluetooth"); killswitch = bluetooth_killswitch_new (); g_signal_connect (G_OBJECT (killswitch), "state-changed", G_CALLBACK (killswitch_state_changed), NULL); menu = create_popupmenu(); client = bluetooth_client_new(); devices_model = bluetooth_client_get_model(client); g_signal_connect(G_OBJECT(devices_model), "row-inserted", G_CALLBACK(device_added), NULL); g_signal_connect(G_OBJECT(devices_model), "row-deleted", G_CALLBACK(device_removed), NULL); g_signal_connect (G_OBJECT (devices_model), "row-changed", G_CALLBACK (device_changed), NULL); /* Set the default adapter */ device_changed (devices_model, NULL, NULL, NULL); if (bluetooth_killswitch_has_killswitches (killswitch) != FALSE) { killswitch_state_changed (killswitch, bluetooth_killswitch_get_state (killswitch)); } /* Make sure all the unblocked adapters are powered, * so as to avoid seeing unpowered, but unblocked * devices */ bluetooth_set_adapter_powered (); settings = g_settings_new (SCHEMA_NAME); show_icon_pref = g_settings_get_boolean (settings, PREF_SHOW_ICON); g_signal_connect (G_OBJECT (settings), "changed::" PREF_SHOW_ICON, G_CALLBACK (show_icon_changed), NULL); statusicon = init_notification(); update_icon_visibility(); g_signal_connect(statusicon, "activate", G_CALLBACK(activate_callback), menu); g_signal_connect(statusicon, "popup-menu", G_CALLBACK(popup_callback), menu); setup_agents(); gtk_main(); gtk_widget_destroy(menu); g_object_unref(settings); cleanup_agents(); cleanup_notification(); g_object_unref(devices_model); g_object_unref(client); if (app != NULL) g_object_unref (app); return 0; }
void notify(DBusMessage * dmsg) { DBusMessage *reply; DBusMessageIter args; DBusMessageIter hints; DBusMessageIter hint; char *hint_name; int i; int id; const char *appname = NULL; const char *summary = NULL; const char *body = NULL; const char *icon = NULL; const char *fgcolor = NULL; const char *bgcolor = NULL; int urgency = 1; int progress = -1; notification *n = malloc(sizeof(notification)); dbus_uint32_t replaces_id = 0; dbus_int32_t expires = -1; dbus_serial++; dbus_message_iter_init(dmsg, &args); _extract_basic(DBUS_TYPE_STRING, &args, &appname); dbus_message_iter_next(&args); _extract_basic(DBUS_TYPE_UINT32, &args, &replaces_id); dbus_message_iter_next(&args); _extract_basic(DBUS_TYPE_STRING, &args, &icon); dbus_message_iter_next(&args); _extract_basic(DBUS_TYPE_STRING, &args, &summary); dbus_message_iter_next(&args); _extract_basic(DBUS_TYPE_STRING, &args, &body); dbus_message_iter_next(&args); dbus_message_iter_next(&args); dbus_message_iter_recurse(&args, &hints); dbus_message_iter_next(&args); _extract_basic(DBUS_TYPE_INT32, &args, &expires); while (dbus_message_iter_get_arg_type(&hints) != DBUS_TYPE_INVALID) { dbus_message_iter_recurse(&hints, &hint); while (dbus_message_iter_get_arg_type(&hint) != DBUS_TYPE_INVALID) { if (dbus_message_iter_get_arg_type(&hint) != DBUS_TYPE_STRING) { dbus_message_iter_next(&hint); continue; } dbus_message_iter_get_basic(&hint, &hint_name); _extract_hint(DBUS_TYPE_BYTE, "urgency", hint_name, &hint, &urgency); _extract_hint(DBUS_TYPE_STRING, "fgcolor", hint_name, &hint, &fgcolor); _extract_hint(DBUS_TYPE_STRING, "bgcolor", hint_name, &hint, &bgcolor); _extract_hint(DBUS_TYPE_INT32, "value", hint_name, &hint, &progress); if (!progress) _extract_hint(DBUS_TYPE_UINT32, "value", hint_name, &hint, &progress); dbus_message_iter_next(&hint); } dbus_message_iter_next(&hints); } if (expires > 0) { /* do some rounding */ expires = (expires + 500) / 1000; if (expires < 1) { expires = 1; } } n->appname = appname != NULL ? strdup(appname) : ""; n->summary = summary != NULL ? strdup(summary) : ""; n->body = body != NULL ? strdup(body) : ""; n->icon = icon != NULL ? strdup(icon) : ""; n->timeout = expires; n->progress = (progress < 0 || progress > 100) ? 0 : progress + 1; n->urgency = urgency; n->dbus_client = strdup(dbus_message_get_sender(dmsg)); for (i = 0; i < ColLast; i++) { n->color_strings[i] = NULL; } n->color_strings[ColFG] = fgcolor == NULL ? NULL : strdup(fgcolor); n->color_strings[ColBG] = bgcolor == NULL ? NULL : strdup(bgcolor); id = init_notification(n, replaces_id); if (id > 0) map_win(); reply = dbus_message_new_method_return(dmsg); dbus_message_iter_init_append(reply, &args); dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT32, &id); dbus_connection_send(dbus_conn, reply, &dbus_serial); dbus_message_unref(reply); }