~timchen119/ubuntu/trusty/gnome-bluetooth/lp1035431

« back to all changes in this revision

Viewing changes to properties/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2011-02-27 15:45:22 UTC
  • mfrom: (1.3.2 upstream)
  • mto: (2.2.3 experimental) (1.5.1)
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: james.westby@ubuntu.com-20110227154522-dnnoqasv5v3mv42a
Tags: upstream-2.91.5
ImportĀ upstreamĀ versionĀ 2.91.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *
3
 
 *  BlueZ - Bluetooth protocol stack for Linux
4
 
 *
5
 
 *  Copyright (C) 2005-2008  Marcel Holtmann <marcel@holtmann.org>
6
 
 *  Copyright (C) 2006-2007  Bastien Nocera <hadess@hadess.net>
7
 
 *
8
 
 *
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.
13
 
 *
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.
18
 
 *
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
22
 
 *
23
 
 */
24
 
 
25
 
#ifdef HAVE_CONFIG_H
26
 
#include <config.h>
27
 
#endif
28
 
 
29
 
#include <glib/gi18n.h>
30
 
#include <gdk/gdkkeysyms.h>
31
 
#include <gdk/gdk.h>
32
 
#include <gtk/gtk.h>
33
 
#include <unique/uniqueapp.h>
34
 
 
35
 
#include "bluetooth-plugin-manager.h"
36
 
#include "bluetooth-client.h"
37
 
#include "bluetooth-client-private.h"
38
 
#include "gconf-bridge.h"
39
 
#include "general.h"
40
 
#include "adapter.h"
41
 
 
42
 
#define PREF_DIR                "/apps/bluetooth-manager"
43
 
#define PREF_SHOW_ICON          PREF_DIR "/show_icon"
44
 
 
45
 
static gboolean delete_callback(GtkWidget *window, GdkEvent *event,
46
 
                                                        gpointer user_data)
47
 
{
48
 
        gtk_widget_destroy(GTK_WIDGET(window));
49
 
 
50
 
        gtk_main_quit();
51
 
 
52
 
        return FALSE;
53
 
}
54
 
 
55
 
static gboolean
56
 
keypress_callback (GtkWidget *window,
57
 
                   GdkEventKey *key,
58
 
                   gpointer user_data)
59
 
{
60
 
        if (key->keyval == GDK_Escape) {
61
 
                gtk_widget_destroy(GTK_WIDGET(window));
62
 
 
63
 
                gtk_main_quit();
64
 
        }
65
 
 
66
 
        return FALSE;
67
 
}
68
 
 
69
 
static void close_callback(GtkWidget *button, gpointer user_data)
70
 
{
71
 
        GtkWidget *window = user_data;
72
 
 
73
 
        gtk_widget_destroy(GTK_WIDGET(window));
74
 
 
75
 
        gtk_main_quit();
76
 
}
77
 
 
78
 
static void
79
 
receive_callback (GtkWidget *item, GtkWindow *window)
80
 
{
81
 
        GtkWidget *dialog, *hbox, *image, *label;
82
 
        const char *command = "gnome-file-share-properties";
83
 
 
84
 
        if (!g_spawn_command_line_async(command, NULL)) {
85
 
                /* translators:
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);
90
 
 
91
 
                hbox = gtk_hbox_new (FALSE, 4);
92
 
 
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);
95
 
 
96
 
                /* translators:
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);
101
 
 
102
 
                gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 2);
103
 
 
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);
107
 
 
108
 
                gtk_dialog_run (GTK_DIALOG (dialog));
109
 
                gtk_widget_destroy (dialog);
110
 
        }
111
 
}
112
 
 
113
 
static void help_callback(GtkWidget *item)
114
 
{
115
 
        GError *error = NULL;
116
 
 
117
 
        if(!gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET(item)),
118
 
                "ghelp:gnome-bluetooth",  gtk_get_current_event_time (), &error)) {
119
 
 
120
 
                g_printerr("Unable to launch help: %s", error->message);
121
 
                g_error_free(error);
122
 
        }
123
 
}       
124
 
 
125
 
static GtkWidget *create_window(GtkWidget *notebook)
126
 
{
127
 
        GtkWidget *window;
128
 
        GtkWidget *vbox;
129
 
        GtkWidget *buttonbox;
130
 
        GtkWidget *button;
131
 
        GtkWidget *image;
132
 
        GConfBridge *bridge;
133
 
 
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);
140
 
 
141
 
        g_signal_connect(G_OBJECT(window), "key-press-event",
142
 
                         G_CALLBACK(keypress_callback), NULL);
143
 
 
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);
147
 
 
148
 
        gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
149
 
 
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),
154
 
                                         "active", FALSE);
155
 
 
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);
159
 
 
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);
164
 
 
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),
168
 
                                                                button, TRUE);
169
 
        g_signal_connect(G_OBJECT(button), "clicked",
170
 
                                        G_CALLBACK(help_callback), window);
171
 
 
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),
178
 
                                                                button, TRUE);
179
 
        g_signal_connect(G_OBJECT(button), "clicked",
180
 
                                        G_CALLBACK(receive_callback), window);
181
 
 
182
 
        gtk_widget_show_all(window);
183
 
 
184
 
        return window;
185
 
}
186
 
 
187
 
static UniqueResponse
188
 
message_received_cb (UniqueApp         *app,
189
 
                     int                command,
190
 
                     UniqueMessageData *message_data,
191
 
                     guint              time_,
192
 
                     gpointer           user_data)
193
 
{
194
 
        gtk_window_present (GTK_WINDOW (user_data));
195
 
 
196
 
        return UNIQUE_RESPONSE_OK;
197
 
}
198
 
 
199
 
static void
200
 
dump_devices (void)
201
 
{
202
 
        BluetoothClient *client;
203
 
        GtkTreeModel *model;
204
 
        GtkTreeIter iter;
205
 
 
206
 
        client = bluetooth_client_new ();
207
 
        model = bluetooth_client_get_model (client);
208
 
 
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");
212
 
                return;
213
 
        }
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);
217
 
}
218
 
 
219
 
static gboolean option_dump = FALSE;
220
 
 
221
 
static GOptionEntry options[] = {
222
 
        { "dump-devices", 'd', 0, G_OPTION_ARG_NONE, &option_dump, N_("Output a list of currently known devices"), NULL },
223
 
        { NULL },
224
 
};
225
 
 
226
 
int main(int argc, char *argv[])
227
 
{
228
 
        UniqueApp *app;
229
 
        GtkWidget *window;
230
 
        GtkWidget *notebook;
231
 
        GError *error = NULL;
232
 
 
233
 
        bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
234
 
        bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
235
 
        textdomain(GETTEXT_PACKAGE);
236
 
 
237
 
        if (gtk_init_with_args(&argc, &argv, NULL,
238
 
                                options, GETTEXT_PACKAGE, &error) == FALSE) {
239
 
                if (error) {
240
 
                        g_print("%s\n", error->message);
241
 
                        g_error_free(error);
242
 
                } else
243
 
                        g_print("An unknown error occurred\n");
244
 
 
245
 
                return 1;
246
 
        }
247
 
 
248
 
        if (option_dump != FALSE) {
249
 
                dump_devices ();
250
 
                return 0;
251
 
        }
252
 
 
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);
257
 
                return 0;
258
 
        }
259
 
 
260
 
        g_set_application_name(_("Bluetooth Properties"));
261
 
 
262
 
        gtk_window_set_default_icon_name("bluetooth");
263
 
 
264
 
        bluetooth_plugin_manager_init ();
265
 
 
266
 
        notebook = gtk_notebook_new();
267
 
        gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
268
 
 
269
 
        setup_adapter(GTK_NOTEBOOK(notebook));
270
 
 
271
 
        window = create_window(notebook);
272
 
 
273
 
        g_signal_connect (app, "message-received",
274
 
                          G_CALLBACK (message_received_cb), window);
275
 
 
276
 
        gtk_main();
277
 
 
278
 
        bluetooth_plugin_manager_cleanup ();
279
 
 
280
 
        cleanup_adapter();
281
 
 
282
 
        g_object_unref(app);
283
 
 
284
 
        return 0;
285
 
}