From: Bastien Nocera <hadess@hadess.net>
To: BlueZ development <bluez-devel@lists.sourceforge.net>
Subject: [Bluez-devel] [PATCH] Allow multiple files to be sent
Date: Thu, 17 Jan 2008 10:43:22 +0000 [thread overview]
Message-ID: <1200566602.26259.89.camel@cookie.hadess.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 248 bytes --]
Heya,
Another for bluetooth-sento feature parity with gnome-obex-send.
This one adds support for sending multiple files, change the
command-line option to match those of gnome-obex-send, as well as add a
TODO list at the top of the file.
Cheers
[-- Attachment #2: bluez-gnome-sendto-multiple-files.patch --]
[-- Type: text/x-patch, Size: 8221 bytes --]
Index: main.c
===================================================================
RCS file: /cvsroot/bluez/gnome/sendto/main.c,v
retrieving revision 1.11
diff -u -p -r1.11 main.c
--- main.c 22 Dec 2007 00:09:17 -0000 1.11
+++ main.c 17 Jan 2008 10:43:01 -0000
@@ -21,6 +21,15 @@
*
*/
+/* TODO
+ * - Fix passing URIs and relative paths as options
+ * - Special nice error for Palm Pilots
+ * - Support cancelling a transfer from the phone
+ * - Show the remote device name if possible
+ * - Truncate long filenames nicely for remote devices
+ * - Close button should be "Cancel" during operations
+ */
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -42,24 +51,40 @@ static GtkWidget *label_filename;
static GtkWidget *label_status;
static GtkWidget *progress;
-static gint filesize = -1;
+static guint64 filesize = -1;
+static guint current_file = 0;
-static gchar *open_file_dialog(void)
+static gchar **open_file_dialog(void)
{
GtkWidget *dialog;
- gchar *filename = NULL;
+ GSList *list, *l;
+ gchar **filenames = NULL;
dialog = gtk_file_chooser_dialog_new(_("Select File"), 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)
- filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
+ GPtrArray *array;
+
+ list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
+ if (list == NULL) {
+ gtk_widget_destroy(dialog);
+ return NULL;
+ }
+ array = g_ptr_array_new();
+ for (l = list; l != NULL; l = l->next)
+ g_ptr_array_add(array, l->data);
+ g_slist_free(list);
+
+ filenames = (char **) array;
+ }
gtk_widget_destroy(dialog);
- return filename;
+ return filenames;
}
static void selected_device_changed(BluetoothDeviceSelection *selector,
@@ -114,11 +139,32 @@ static void response_callback(GtkWidget
gtk_main_quit();
}
+static void set_filename(GtkWidget *label, const gchar *filename)
+{
+ gchar *display, *text;
+
+ if (g_str_has_prefix(filename, "file:///") != FALSE) {
+ gchar *local;
+
+ local = g_filename_from_uri(filename, NULL, NULL);
+ display = g_filename_display_basename(local);
+ g_free (local);
+ } else if (filename[0] == '/') {
+ display = g_filename_display_basename(filename);
+ } else {
+ display = g_filename_display_name(filename);
+ }
+
+ text = g_strdup_printf("<b>%s</b>", display);
+ g_free(display);
+ gtk_label_set_markup(GTK_LABEL(label), text);
+ g_free(text);
+}
+
static void create_window(const gchar *filename)
{
GtkWidget *vbox;
GtkWidget *label;
- gchar *text;
dialog = gtk_dialog_new_with_buttons(_("File Transfer"), NULL,
GTK_DIALOG_NO_SEPARATOR,
@@ -147,9 +193,7 @@ static void create_window(const gchar *f
label_status = label;
- text = g_strdup_printf("<b>%s</b>", filename);
- gtk_label_set_markup(GTK_LABEL(label_filename), text);
- g_free(text);
+ set_filename(label_filename, filename);
gtk_label_set_markup(GTK_LABEL(label_status), _("Connecting..."));
@@ -181,7 +225,7 @@ static void transfer_progress(DBusGProxy
gchar *text;
gdouble fraction;
- text = g_strdup_printf(_("Transfered %d of %d bytes"), bytes, filesize);
+ text = g_strdup_printf(_("Transfered %d of %"G_GUINT64_FORMAT" bytes"), bytes, filesize);
gtk_label_set_markup(GTK_LABEL(label_status), text);
g_free(text);
@@ -191,30 +235,51 @@ static void transfer_progress(DBusGProxy
static void transfer_completed(DBusGProxy *proxy, gpointer user_data)
{
+ gchar **filenames = user_data;
+
gtk_label_set_markup(GTK_LABEL(label_status), _("Completed"));
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress), 1.0);
- dbus_g_proxy_call(proxy, "Disconnect", NULL, G_TYPE_INVALID,
- G_TYPE_INVALID);
+ current_file++;
- gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog),
+ /* Any more files to process? */
+ if (filenames[current_file] != NULL) {
+ GError *error = NULL;
+
+ //FIXME process filename to a proper local path
+ set_filename(label_filename, filenames[current_file]);
+ dbus_g_proxy_call(proxy, "SendFile", &error,
+ G_TYPE_STRING, filenames[current_file], G_TYPE_INVALID,
+ G_TYPE_INVALID);
+
+ if (error != NULL) {
+ g_printerr("Sending of file %s failed: %s\n", filenames[current_file],
+ error->message);
+ g_error_free(error);
+ gtk_main_quit();
+ }
+ } else {
+ dbus_g_proxy_call(proxy, "Disconnect", NULL, G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog),
GTK_RESPONSE_CLOSE, TRUE);
+ }
}
static void session_connected(DBusGProxy *proxy, gpointer user_data)
{
- gchar *filename = user_data;
+ gchar **filenames = user_data;
GError *error = NULL;
gtk_label_set_markup(GTK_LABEL(label_status), _("Connected"));
dbus_g_proxy_call(proxy, "SendFile", &error,
- G_TYPE_STRING, filename, G_TYPE_INVALID,
+ G_TYPE_STRING, filenames[current_file], G_TYPE_INVALID,
G_TYPE_INVALID);
if (error != NULL) {
- g_printerr("Sending of file %s failed: %s\n", filename,
+ g_printerr("Sending of file %s failed: %s\n", filenames[current_file],
error->message);
g_error_free(error);
gtk_main_quit();
@@ -261,7 +326,7 @@ static void create_notify(DBusGProxy *pr
G_TYPE_STRING, G_TYPE_INT, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(proxy, "TransferStarted",
- G_CALLBACK(transfer_started), NULL, NULL);
+ G_CALLBACK(transfer_started), user_data, NULL);
dbus_g_proxy_add_signal(proxy, "TransferProgress",
G_TYPE_UINT, G_TYPE_INVALID);
@@ -272,17 +337,20 @@ static void create_notify(DBusGProxy *pr
dbus_g_proxy_add_signal(proxy, "TransferCompleted", G_TYPE_INVALID);
dbus_g_proxy_connect_signal(proxy, "TransferCompleted",
- G_CALLBACK(transfer_completed), NULL, NULL);
+ G_CALLBACK(transfer_completed), user_data, NULL);
dbus_g_proxy_call(proxy, "Connect", NULL, G_TYPE_INVALID,
G_TYPE_INVALID);
}
static gchar *option_device = NULL;
+static gchar **filenames = NULL;
static GOptionEntry options[] = {
- { "device", 0, 0, G_OPTION_ARG_STRING, &option_device,
- N_("Remote device to use"), "ADDRESS" },
+ { "dest", 'd', 0, G_OPTION_ARG_STRING, &option_device,
+ N_("Remote device to use"), "ADDRESS" },
+ { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames,
+ N_("Files to send"), NULL},
{ NULL },
};
@@ -290,7 +358,7 @@ int main(int argc, char *argv[])
{
DBusGProxy *proxy;
GError *error;
- gchar *filename, *address;
+ gchar *address;
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
@@ -298,7 +366,7 @@ int main(int argc, char *argv[])
error = NULL;
- if (gtk_init_with_args(&argc, &argv, "[FILE...]",
+ if (gtk_init_with_args(&argc, &argv, "[FILENAMES...]",
options, GETTEXT_PACKAGE, &error) == FALSE) {
if (error != NULL) {
g_printerr("%s\n", error->message);
@@ -311,17 +379,15 @@ int main(int argc, char *argv[])
gtk_window_set_default_icon_name("stock_bluetooth");
- if (argc < 2) {
- filename = open_file_dialog();
- if (filename == NULL)
+ if (filenames == NULL) {
+ filenames = open_file_dialog();
+ if (filenames == NULL)
gtk_exit(1);
- } else
- filename = g_strdup(argv[1]);
+ }
if (option_device == NULL) {
address = browse_device_dialog();
if (address == NULL) {
- g_free(filename);
gtk_exit(1);
}
} else
@@ -345,22 +411,22 @@ int main(int argc, char *argv[])
gtk_exit(1);
}
- create_window(filename);
+ create_window(filenames[0]);
proxy = dbus_g_proxy_new_for_name(conn, "org.openobex",
"/org/openobex", "org.openobex.Manager");
dbus_g_proxy_begin_call(proxy, "CreateBluetoothSession",
- create_notify, filename, NULL,
+ create_notify, filenames, NULL,
G_TYPE_STRING, address, G_TYPE_STRING, "opp",
- G_TYPE_BOOLEAN, FALSE, G_TYPE_INVALID);
+ G_TYPE_INVALID);
gtk_main();
dbus_g_connection_unref(conn);
g_free(address);
- g_free(filename);
+ g_strfreev(filenames);
return 0;
}
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #4: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
next reply other threads:[~2008-01-17 10:43 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-17 10:43 Bastien Nocera [this message]
2008-01-18 13:43 ` [Bluez-devel] [PATCH] Allow multiple files to be sent Bastien Nocera
2008-02-01 13:14 ` Bastien Nocera
2008-02-01 16:08 ` Bastien Nocera
2008-02-01 16:20 ` Bastien Nocera
2008-02-06 12:18 ` [Bluez-devel] [PATCH] Updated sendto Bastien Nocera
2008-02-06 13:08 ` Bastien Nocera
2008-02-07 0:59 ` Bastien Nocera
2008-02-23 1:30 ` Bastien Nocera
2008-02-24 18:29 ` Bastien Nocera
2008-02-25 2:21 ` Marcel Holtmann
2008-02-25 10:56 ` Bastien Nocera
2008-02-25 20:36 ` Marcel Holtmann
2008-02-26 1:18 ` Bastien Nocera
2008-02-26 1:21 ` Marcel Holtmann
2008-02-27 1:28 ` Bastien Nocera
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1200566602.26259.89.camel@cookie.hadess.net \
--to=hadess@hadess.net \
--cc=bluez-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox