--- gnome-bluetooth-0.8.0/obex/gnome-obex-server.c 2006-06-06 09:54:48.000000000 +0100 +++ gnome-bluetooth-0.8.0.hack/obex/gnome-obex-server.c 2006-12-09 22:10:17.974801000 +0000 @@ -103,16 +103,95 @@ return (result == GTK_RESPONSE_OK); } +#define FILE_TYPE_MUSIC 1 +#define FILE_TYPE_IMAGE 2 +#define FILE_TYPE_VIDEO 3 + +static gint +get_filetype (char* fname) +{ + gint filetype = 0; + gchar *lc_fname = g_ascii_strdown (fname, -1); + + if (g_str_has_suffix(lc_fname, "mp3")) { + filetype = FILE_TYPE_MUSIC; + } else if (g_str_has_suffix(lc_fname, "ogg")) { + filetype = FILE_TYPE_MUSIC; + } else if (g_str_has_suffix(lc_fname, "jpg")) { + filetype = FILE_TYPE_IMAGE; + } else if (g_str_has_suffix(lc_fname, "mp4")) { + filetype = FILE_TYPE_VIDEO; + } + g_message ("Filetype %d\n", filetype); + return filetype; +} + +void +do_default_action (int filetype, char* fname) +{ + GConfClient *client = gconf_client_get_default(); + gchar *action = NULL; + + if (filetype && client) { + switch (filetype) { + case FILE_TYPE_MUSIC: + action = gconf_client_get_string (client, + "/apps/gnome-obex-server/music_action", NULL); + break; + case FILE_TYPE_IMAGE: + action = gconf_client_get_string (client, + "/apps/gnome-obex-server/image_action", NULL); + break; + case FILE_TYPE_VIDEO: + action = gconf_client_get_string (client, + "/apps/gnome-obex-server/video_action", NULL); + break; + } + } + + if (action && strlen(action) > 0) { + gchar *escaped_filename = g_shell_quote (fname); + gchar *command = g_strdup_printf("%s %s", action, + escaped_filename); + + g_message ("Executing %s\n",command); + g_spawn_command_line_async (command, NULL); + + g_free (command); + g_free (escaped_filename); + } + + g_free (action); + if (client) + g_object_unref (client); +} + static char * -get_save_dir (void) +get_save_dir (int filetype) { char *dir = NULL; GConfClient *client = gconf_client_get_default(); - if (client) { + if (filetype && client) { + switch (filetype) { + case FILE_TYPE_MUSIC: + dir = gconf_client_get_string (client, + "/apps/gnome-obex-server/music_savedir", NULL); + break; + case FILE_TYPE_IMAGE: + dir = gconf_client_get_string (client, + "/apps/gnome-obex-server/image_savedir", NULL); + break; + case FILE_TYPE_VIDEO: + dir = gconf_client_get_string (client, + "/apps/gnome-obex-server/video_savedir", NULL); + break; + } + } + + if ((dir == NULL || strlen (dir) == 0 || g_file_test (dir, G_FILE_TEST_IS_DIR) == FALSE) && client) { dir = gconf_client_get_string (client, "/apps/gnome-obex-server/savedir", NULL); - g_object_unref (client); /* Starts with ~/ ? */ if (dir != NULL && dir[0] == '~' && dir[1] == '/') { @@ -149,6 +228,10 @@ g_free (dir); dir = g_strdup (g_get_home_dir ()); } + + if (client) + g_object_unref (client); + return dir; } @@ -249,6 +332,7 @@ char *targetname = NULL, *dir; struct utimbuf utim; GnomebtFileActionDialog *dlg; + int filetype; if (! app->decision) { btctl_obex_set_response (bo, FALSE); @@ -258,7 +342,8 @@ g_message ("File arrived from %s", bdaddr); g_message ("Filename '%s' Length %d", fname, data->body_len); - dir = get_save_dir (); + filetype = get_filetype (fname); + dir = get_save_dir (filetype); targetname = get_safe_unique_filename (fname, dir); g_free (dir); @@ -291,6 +376,9 @@ g_warning ("Couldn't save file."); btctl_obex_set_response (bo, FALSE); } + + do_default_action (filetype, targetname); + g_free (targetname); }