gnome-bluetooth r353 - in trunk: . applet browse common sendto



Author: hadess
Date: Wed Feb 25 14:43:16 2009
New Revision: 353
URL: http://svn.gnome.org/viewvc/gnome-bluetooth?rev=353&view=rev

Log:
More browse killing

Don't use helpers in the applet and sendto, the functions are
only small. Remove more of browse.

Removed:
   trunk/browse/Makefile.am
   trunk/browse/bluetooth-browse.1
   trunk/browse/main.c
Modified:
   trunk/Makefile.am
   trunk/applet/Makefile.am
   trunk/applet/main.c
   trunk/common/helper.c
   trunk/common/helper.h
   trunk/sendto/Makefile.am
   trunk/sendto/main.c

Modified: trunk/Makefile.am
==============================================================================
--- trunk/Makefile.am	(original)
+++ trunk/Makefile.am	Wed Feb 25 14:43:16 2009
@@ -1,5 +1,5 @@
 
-SUBDIRS = po icons common applet properties wizard sendto browse
+SUBDIRS = po icons common applet properties wizard sendto
 
 EXTRA_DIST = intltool-extract.in intltool-update.in intltool-merge.in ChangeLog.pre-2.27
 

Modified: trunk/applet/Makefile.am
==============================================================================
--- trunk/applet/Makefile.am	(original)
+++ trunk/applet/Makefile.am	Wed Feb 25 14:43:16 2009
@@ -3,7 +3,7 @@
 
 bluetooth_applet_SOURCES = main.c notify.h notify.c agent.h agent.c
 
-bluetooth_applet_LDADD = $(top_builddir)/common/libcommon.la $(APPLET_LIBS)
+bluetooth_applet_LDADD = $(top_builddir)/common/libcommon.la $(top_builddir)/common/libgnome-bluetooth.la $(APPLET_LIBS)
 
 noinst_PROGRAMS = test-agentdialog
 

Modified: trunk/applet/main.c
==============================================================================
--- trunk/applet/main.c	(original)
+++ trunk/applet/main.c	Wed Feb 25 14:43:16 2009
@@ -33,6 +33,7 @@
 
 #include <bluetooth-instance.h>
 #include <bluetooth-client.h>
+#include <bluetooth-chooser.h>
 
 #include "notify.h"
 #include "agent.h"
@@ -135,12 +136,65 @@
 		g_printerr("Couldn't execute command: %s\n", command);
 }
 
+static void
+select_device_changed(BluetoothChooser *sel,
+		      char *address,
+		      gpointer user_data)
+{
+	GtkDialog *dialog = user_data;
+
+	gtk_dialog_set_response_sensitive(dialog,
+				GTK_RESPONSE_ACCEPT, address != NULL);
+}
+
 static void browse_callback(GObject *widget, gpointer user_data)
 {
-	const char *command = "bluetooth-browse";
+	GtkWidget *dialog, *selector;
+	char *bdaddr, *cmd;
+	int response_id;
+
+	dialog = gtk_dialog_new_with_buttons(_("Select Device to Browse"), NULL,
+					     GTK_DIALOG_NO_SEPARATOR,
+					     GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+					     GTK_STOCK_CONNECT, GTK_RESPONSE_ACCEPT, NULL);
+	gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog),
+					  GTK_RESPONSE_ACCEPT, FALSE);
+	gtk_window_set_default_size(GTK_WINDOW(dialog), 480, 400);
+
+	gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
+	gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
+
+	selector = bluetooth_chooser_new(_("Select device to browse"));
+	gtk_container_set_border_width(GTK_CONTAINER(selector), 5);
+	gtk_widget_show(selector);
+	g_object_set(selector,
+		     "show-search", TRUE,
+		     "show-device-category", TRUE,
+		     "show-device-type", TRUE,
+		     NULL);
+	g_signal_connect(selector, "selected-device-changed",
+			 G_CALLBACK(select_device_changed), dialog);
+	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), selector);
+	bluetooth_chooser_start_discovery (BLUETOOTH_CHOOSER (selector));
+
+	bdaddr = NULL;
+	response_id = gtk_dialog_run (GTK_DIALOG (dialog));
+	if (response_id == GTK_RESPONSE_ACCEPT)
+		g_object_get (G_OBJECT (selector), "device-selected", &bdaddr, NULL);
 
-	if (!g_spawn_command_line_async(command, NULL))
-		g_printerr("Couldn't execute command: %s\n", command);
+	gtk_widget_destroy (dialog);
+
+	if (response_id != GTK_RESPONSE_ACCEPT)
+		return;
+
+	cmd = g_strdup_printf("%s --no-default-window \"obex://[%s]\"",
+			      "nautilus", bdaddr);
+	g_free (bdaddr);
+
+	if (!g_spawn_command_line_async(cmd, NULL))
+		g_printerr("Couldn't execute command: %s\n", cmd);
+
+	g_free (cmd);
 }
 
 static void sendto_callback(GObject *widget, gpointer user_data)

Modified: trunk/common/helper.c
==============================================================================
--- trunk/common/helper.c	(original)
+++ trunk/common/helper.c	Wed Feb 25 14:43:16 2009
@@ -124,132 +124,3 @@
 	return tree;
 }
 
-static void select_callback(GtkTreeSelection *selection, gpointer user_data)
-{
-	GtkWidget *dialog = user_data;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	gboolean selected;
-
-	selected = gtk_tree_selection_get_selected(selection, &model, &iter);
-
-	if (selected == TRUE) {
-		gchar *address;
-
-		address = g_object_get_data(G_OBJECT(dialog), "address");
-		g_free(address);
-
-		gtk_tree_model_get(model, &iter,
-				BLUETOOTH_COLUMN_ADDRESS, &address, -1);
-
-		g_object_set_data(G_OBJECT(dialog), "address", address);
-	}
-
-	gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog),
-						GTK_RESPONSE_ACCEPT, selected);
-}
-
-gchar *show_browse_dialog(void)
-{
-	BluetoothClient *client;
-	GtkWidget *dialog;
-	GtkWidget *scrolled;
-	GtkWidget *tree;
-	GtkTreeModel *model;
-	GtkTreeModel *sorted;
-	GtkTreeSelection *selection;
-	gchar *address = NULL;
-
-	dialog = gtk_dialog_new_with_buttons(_("Select Device"),
-				NULL, GTK_DIALOG_NO_SEPARATOR,
-				GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
-				GTK_STOCK_CONNECT, GTK_RESPONSE_ACCEPT, NULL);
-
-	gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog),
-						GTK_RESPONSE_ACCEPT, FALSE);
-
-	gtk_window_set_default_size(GTK_WINDOW(dialog), 450, 400);
-
-	gtk_container_set_border_width(GTK_CONTAINER(dialog), 5);
-	gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 2);
-
-	scrolled = gtk_scrolled_window_new(NULL, NULL);
-	gtk_container_set_border_width(GTK_CONTAINER(scrolled), 5);
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
-				GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
-							GTK_SHADOW_OUT);
-	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), scrolled);
-
-	client = bluetooth_client_new();
-
-	model = bluetooth_client_get_device_model(client, NULL);
-	if (model != NULL) {
-		sorted = gtk_tree_model_sort_new_with_model(model);
-		gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sorted),
-				BLUETOOTH_COLUMN_RSSI, GTK_SORT_DESCENDING);
-	} else
-		sorted = NULL;
-
-	tree = create_tree(sorted, TRUE);
-
-	if (sorted != NULL)
-		g_object_unref(sorted);
-	if (model != NULL)
-		g_object_unref(model);
-
-	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
-	gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
-
-	g_signal_connect(G_OBJECT(selection), "changed",
-				G_CALLBACK(select_callback), dialog);
-
-	gtk_container_add(GTK_CONTAINER(scrolled), tree);
-
-	gtk_widget_show_all(scrolled);
-
-	bluetooth_client_start_discovery(client);
-
-	if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
-		address = g_object_get_data(G_OBJECT(dialog), "address");
-
-	bluetooth_client_stop_discovery(client);
-
-	g_object_unref(client);
-
-	gtk_widget_destroy(dialog);
-
-	return address;
-}
-
-gchar **show_select_dialog(void)
-{
-	GtkWidget *dialog;
-	gchar **files = NULL;
-
-	dialog = gtk_file_chooser_dialog_new(_("Choose files to send"), NULL,
-				GTK_FILE_CHOOSER_ACTION_OPEN,
-				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-				GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
-
-	gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
-
-	if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
-		GSList *list, *filenames;
-		int i;
-
-		filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
-
-		files = g_new(gchar *, g_slist_length(filenames) + 1);
-
-		for (list = filenames, i = 0; list; list = list->next, i++)
-			files[i] = list->data;
-		files[i] = NULL;
-
-		g_slist_free(filenames);
-	}
-
-	gtk_widget_destroy(dialog);
-
-	return files;
-}

Modified: trunk/common/helper.h
==============================================================================
--- trunk/common/helper.h	(original)
+++ trunk/common/helper.h	Wed Feb 25 14:43:16 2009
@@ -23,5 +23,3 @@
 
 GtkWidget *create_tree(GtkTreeModel *model, gboolean icons);
 
-gchar *show_browse_dialog(void);
-gchar **show_select_dialog(void);

Modified: trunk/sendto/Makefile.am
==============================================================================
--- trunk/sendto/Makefile.am	(original)
+++ trunk/sendto/Makefile.am	Wed Feb 25 14:43:16 2009
@@ -3,7 +3,7 @@
 
 bluetooth_sendto_SOURCES = main.c
 
-bluetooth_sendto_LDADD = $(top_builddir)/common/libcommon.la $(SENDTO_LIBS)
+bluetooth_sendto_LDADD = $(top_builddir)/common/libcommon.la $(top_builddir)/common/libgnome-bluetooth.la $(SENDTO_LIBS)
 
 AM_CFLAGS = $(SENDTO_CFLAGS) $(WARN_CFLAGS) $(DISABLE_DEPRECATED)
 

Modified: trunk/sendto/main.c
==============================================================================
--- trunk/sendto/main.c	(original)
+++ trunk/sendto/main.c	Wed Feb 25 14:43:16 2009
@@ -36,8 +36,7 @@
 #include <dbus/dbus-glib-lowlevel.h>
 
 #include <obex-agent.h>
-
-#include "helper.h"
+#include <bluetooth-chooser.h>
 #include "marshal.h"
 
 #define AGENT_PATH "/org/bluez/agent/sendto"
@@ -673,6 +672,94 @@
 		gtk_main_quit();
 }
 
+static void
+select_device_changed(BluetoothChooser *sel,
+		      char *address,
+		      gpointer user_data)
+{
+	GtkDialog *dialog = user_data;
+
+	gtk_dialog_set_response_sensitive(dialog,
+				GTK_RESPONSE_ACCEPT, address != NULL);
+}
+
+static char *
+show_browse_dialog (void)
+{
+	GtkWidget *dialog, *selector, *button, *image;
+	char *bdaddr;
+	int response_id;
+
+	dialog = gtk_dialog_new_with_buttons(_("Select Device to Send To"), NULL,
+					     GTK_DIALOG_NO_SEPARATOR,
+					     GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+					     NULL);
+	button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Send _To"), GTK_RESPONSE_ACCEPT);
+	image = gtk_image_new_from_icon_name ("document-send", GTK_ICON_SIZE_BUTTON);
+	gtk_button_set_image (GTK_BUTTON (button), image);
+	gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog),
+					  GTK_RESPONSE_ACCEPT, FALSE);
+	gtk_window_set_default_size(GTK_WINDOW(dialog), 480, 400);
+
+	gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
+	gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
+
+	selector = bluetooth_chooser_new("Select device to send files to");
+	gtk_container_set_border_width(GTK_CONTAINER(selector), 5);
+	gtk_widget_show(selector);
+	g_object_set(selector,
+		     "show-search", TRUE,
+		     "show-device-category", TRUE,
+		     "show-device-type", TRUE,
+		     NULL);
+	g_signal_connect(selector, "selected-device-changed",
+			 G_CALLBACK(select_device_changed), dialog);
+	gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), selector);
+	bluetooth_chooser_start_discovery (BLUETOOTH_CHOOSER (selector));
+
+	bdaddr = NULL;
+	response_id = gtk_dialog_run (GTK_DIALOG (dialog));
+	if (response_id == GTK_RESPONSE_ACCEPT)
+		g_object_get (G_OBJECT (selector), "device-selected", &bdaddr, NULL);
+
+	gtk_widget_destroy (dialog);
+
+	return bdaddr;
+}
+
+static char **
+show_select_dialog(void)
+{
+	GtkWidget *dialog;
+	gchar **files = NULL;
+
+	dialog = gtk_file_chooser_dialog_new(_("Choose files to send"), NULL,
+				GTK_FILE_CHOOSER_ACTION_OPEN,
+				GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+				GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
+
+	gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
+
+	if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
+		GSList *list, *filenames;
+		int i;
+
+		filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
+
+		files = g_new(gchar *, g_slist_length(filenames) + 1);
+
+		for (list = filenames, i = 0; list; list = list->next, i++)
+			files[i] = list->data;
+		files[i] = NULL;
+
+		g_slist_free(filenames);
+	}
+
+	gtk_widget_destroy(dialog);
+
+	return files;
+}
+
 static GOptionEntry options[] = {
 	{ "device", 0, 0, G_OPTION_ARG_STRING, &option_device,
 				N_("Remote device to use"), "ADDRESS" },



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]