3
* BlueZ - Bluetooth protocol stack for Linux
5
* Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org>
6
* Copyright (C) 2006-2007 Bastien Nocera <hadess@hadess.net>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29
#include <glib/gi18n.h>
30
#include <gdk/gdkkeysyms.h>
33
#include <unique/uniqueapp.h>
35
#include "bluetooth-plugin-manager.h"
36
#include "bluetooth-client.h"
37
#include "bluetooth-client-private.h"
38
#include "gconf-bridge.h"
42
#define PREF_DIR "/apps/bluetooth-manager"
43
#define PREF_SHOW_ICON PREF_DIR "/show_icon"
45
static gboolean delete_callback(GtkWidget *window, GdkEvent *event,
48
gtk_widget_destroy(GTK_WIDGET(window));
56
keypress_callback (GtkWidget *window,
60
if (key->keyval == GDK_Escape) {
61
gtk_widget_destroy(GTK_WIDGET(window));
69
static void close_callback(GtkWidget *button, gpointer user_data)
71
GtkWidget *window = user_data;
73
gtk_widget_destroy(GTK_WIDGET(window));
79
receive_callback (GtkWidget *item, GtkWindow *window)
81
GtkWidget *dialog, *hbox, *image, *label;
82
const char *command = "gnome-file-share-properties";
84
if (!g_spawn_command_line_async(command, NULL)) {
86
* This is the name of the preferences dialogue for gnome-user-share */
87
dialog = gtk_dialog_new_with_buttons(_("Cannot start \"Personal File Sharing\" Preferences"), window,
88
GTK_DIALOG_NO_SEPARATOR,
89
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL);
91
hbox = gtk_hbox_new (FALSE, 4);
93
image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_MENU);
94
gtk_box_pack_start(GTK_BOX (hbox), image, FALSE, FALSE, 4);
97
* This is the name of the preferences dialogue for gnome-user-share */
98
label = gtk_label_new (_("Please verify that the \"Personal File Sharing\" program is correctly installed."));
99
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
100
gtk_box_pack_start(GTK_BOX (hbox), label, TRUE, TRUE, 4);
102
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 2);
104
gtk_widget_show_all(hbox);
105
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
106
gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), hbox);
108
gtk_dialog_run (GTK_DIALOG (dialog));
109
gtk_widget_destroy (dialog);
113
static void help_callback(GtkWidget *item)
115
GError *error = NULL;
117
if(!gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET(item)),
118
"ghelp:gnome-bluetooth", gtk_get_current_event_time (), &error)) {
120
g_printerr("Unable to launch help: %s", error->message);
125
static GtkWidget *create_window(GtkWidget *notebook)
129
GtkWidget *buttonbox;
134
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
135
gtk_window_set_title(GTK_WINDOW(window), _("Bluetooth Preferences"));
136
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
137
gtk_window_set_default_size(GTK_WINDOW(window), 600, 420);
138
g_signal_connect(G_OBJECT(window), "delete-event",
139
G_CALLBACK(delete_callback), NULL);
141
g_signal_connect(G_OBJECT(window), "key-press-event",
142
G_CALLBACK(keypress_callback), NULL);
144
vbox = gtk_vbox_new(FALSE, 6);
145
gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
146
gtk_container_add(GTK_CONTAINER(window), vbox);
148
gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
150
button = gtk_check_button_new_with_mnemonic (_("_Show Bluetooth icon"));
151
bridge = gconf_bridge_get ();
152
gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
153
gconf_bridge_bind_property_full (bridge, PREF_SHOW_ICON, G_OBJECT (button),
156
buttonbox = gtk_hbutton_box_new();
157
gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonbox), GTK_BUTTONBOX_END);
158
gtk_box_pack_start(GTK_BOX(vbox), buttonbox, FALSE, FALSE, 0);
160
button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
161
gtk_container_add(GTK_CONTAINER(buttonbox), button);
162
g_signal_connect(G_OBJECT(button), "clicked",
163
G_CALLBACK(close_callback), window);
165
button = gtk_button_new_from_stock(GTK_STOCK_HELP);
166
gtk_container_add(GTK_CONTAINER(buttonbox), button);
167
gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(buttonbox),
169
g_signal_connect(G_OBJECT(button), "clicked",
170
G_CALLBACK(help_callback), window);
172
image = gtk_image_new_from_stock (GTK_STOCK_JUMP_TO,
173
GTK_ICON_SIZE_BUTTON);
174
button = gtk_button_new_with_label (_("Receive Files"));
175
gtk_button_set_image (GTK_BUTTON (button), image);
176
gtk_container_add(GTK_CONTAINER(buttonbox), button);
177
gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(buttonbox),
179
g_signal_connect(G_OBJECT(button), "clicked",
180
G_CALLBACK(receive_callback), window);
182
gtk_widget_show_all(window);
187
static UniqueResponse
188
message_received_cb (UniqueApp *app,
190
UniqueMessageData *message_data,
194
gtk_window_present (GTK_WINDOW (user_data));
196
return UNIQUE_RESPONSE_OK;
202
BluetoothClient *client;
206
client = bluetooth_client_new ();
207
model = bluetooth_client_get_model (client);
209
if (gtk_tree_model_get_iter_first (model, &iter) == FALSE) {
210
g_print ("No known devices\n");
211
g_print ("Is bluetoothd running, and a Bluetooth adapter enabled?\n");
214
bluetooth_client_dump_device (model, &iter, TRUE);
215
while (gtk_tree_model_iter_next (model, &iter))
216
bluetooth_client_dump_device (model, &iter, TRUE);
219
static gboolean option_dump = FALSE;
221
static GOptionEntry options[] = {
222
{ "dump-devices", 'd', 0, G_OPTION_ARG_NONE, &option_dump, N_("Output a list of currently known devices"), NULL },
226
int main(int argc, char *argv[])
231
GError *error = NULL;
233
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
234
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
235
textdomain(GETTEXT_PACKAGE);
237
if (gtk_init_with_args(&argc, &argv, NULL,
238
options, GETTEXT_PACKAGE, &error) == FALSE) {
240
g_print("%s\n", error->message);
243
g_print("An unknown error occurred\n");
248
if (option_dump != FALSE) {
253
app = unique_app_new ("org.gnome.Bluetooth.properties", NULL);
254
if (unique_app_is_running (app)) {
255
gdk_notify_startup_complete ();
256
unique_app_send_message (app, UNIQUE_ACTIVATE, NULL);
260
g_set_application_name(_("Bluetooth Properties"));
262
gtk_window_set_default_icon_name("bluetooth");
264
bluetooth_plugin_manager_init ();
266
notebook = gtk_notebook_new();
267
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
269
setup_adapter(GTK_NOTEBOOK(notebook));
271
window = create_window(notebook);
273
g_signal_connect (app, "message-received",
274
G_CALLBACK (message_received_cb), window);
278
bluetooth_plugin_manager_cleanup ();