[maemo-commits] [maemo-commits] r11108 - in projects/haf/trunk/libhildonmime: . debian libhildonmime tests
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Tue Apr 17 14:07:31 EEST 2007
- Previous message: [maemo-commits] r11107 - in projects/haf/trunk/hildon-desktop: . debian
- Next message: [maemo-commits] r11109 - in projects/haf/trunk/hildon-theme-layout-4: . rc
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: martyn Date: 2007-04-17 14:07:29 +0300 (Tue, 17 Apr 2007) New Revision: 11108 Modified: projects/haf/trunk/libhildonmime/ChangeLog projects/haf/trunk/libhildonmime/debian/changelog projects/haf/trunk/libhildonmime/libhildonmime/hildon-mime-open.c projects/haf/trunk/libhildonmime/libhildonmime/hildon-mime.h projects/haf/trunk/libhildonmime/tests/test-open.c Log: * libhildonmime/hildon-mime-open.c: Actually use the return value from dbus_connection_send() to know if we succeeded locally. * libhildonmime/hildon-mime.h: Updated the documentation to be consistent with hildon-uri.h and also to describe how the _open*() API is asynchronous and requires an event loop in cases where applications have to be launched if not already running. * tests/test-open.c: Fixed the test case to use a main loop so that if the application associated with the mime type is not running and has to be started by D-Bus, we have time to allow dbus to process the events and then send the "mime_open" dbus message. Fixes NB#54056. Modified: projects/haf/trunk/libhildonmime/ChangeLog =================================================================== --- projects/haf/trunk/libhildonmime/ChangeLog 2007-04-17 10:38:37 UTC (rev 11107) +++ projects/haf/trunk/libhildonmime/ChangeLog 2007-04-17 11:07:29 UTC (rev 11108) @@ -1,3 +1,19 @@ +2007-04-17 Martyn Russell <martyn at imendio.com> + + * libhildonmime/hildon-mime-open.c: Actually use the return value + from dbus_connection_send() to know if we succeeded locally. + + * libhildonmime/hildon-mime.h: Updated the documentation to be + consistent with hildon-uri.h and also to describe how the _open*() + API is asynchronous and requires an event loop in cases where + applications have to be launched if not already running. + + * tests/test-open.c: Fixed the test case to use a main loop so + that if the application associated with the mime type is not + running and has to be started by D-Bus, we have time to allow dbus + to process the events and then send the "mime_open" dbus + message. Fixes NB#54056. + 2007-04-04 Richard Hult <richard at imendio.com> * tests/test-mime-category.c: Improve output. Modified: projects/haf/trunk/libhildonmime/debian/changelog =================================================================== --- projects/haf/trunk/libhildonmime/debian/changelog 2007-04-17 10:38:37 UTC (rev 11107) +++ projects/haf/trunk/libhildonmime/debian/changelog 2007-04-17 11:07:29 UTC (rev 11108) @@ -1,3 +1,10 @@ +libhildonmime (1.9.4-1) unstable; urgency=low + + * UNRELEASED! + * Fixes: NB#54056, The files are not getting opened when the application... + + -- Martyn Russell <martyn at imendio.com> Fri, 20 April 2007 17:33:01 +0000 + libhildonmime (1.9.3-2) unstable; urgency=low * Implemented: NR#153624, NR#153625, NR#153171 Modified: projects/haf/trunk/libhildonmime/libhildonmime/hildon-mime-open.c =================================================================== --- projects/haf/trunk/libhildonmime/libhildonmime/hildon-mime-open.c 2007-04-17 10:38:37 UTC (rev 11107) +++ projects/haf/trunk/libhildonmime/libhildonmime/hildon-mime-open.c 2007-04-17 11:07:29 UTC (rev 11108) @@ -92,22 +92,20 @@ #define APP_LAUNCH_BANNER_METHOD_PATH "/com/nokia/tasknav/app_launch_banner" #define APP_LAUNCH_BANNER_METHOD "app_launch_banner" - typedef struct { + gchar *service_name; GSList *files; } AppEntry; +static gboolean mime_launch (DBusConnection *con, + AppEntry *entry); +static void mime_launch_add_arg (const gchar *uri, + DBusMessageIter *iter); -static void mime_launch (const gchar *key, - AppEntry *entry, - DBusConnection *con); -static void mime_launch_add_arg (const gchar *uri, - DBusMessageIter *iter); - - static void app_entry_free (AppEntry *entry) { + g_free (entry->service_name); g_slist_free (entry->files); g_free (entry); } @@ -139,8 +137,8 @@ g_free (group); } + g_key_file_free (key_file); g_free (filename); - g_key_file_free (key_file); return service_name; } @@ -156,8 +154,11 @@ gchar *service_name = NULL; default_id = gnome_vfs_mime_get_default_desktop_entry (mime_type); - if (default_id != NULL && default_id[0] != '\0') { - service_name = desktop_file_get_service_name (default_id); + if (default_id) { + if (default_id[0] != '\0') { + service_name = desktop_file_get_service_name (default_id); + } + g_free (default_id); return service_name; @@ -199,6 +200,7 @@ { AppEntry *entry; gchar *service_name; + gboolean success; if (con == NULL) { DLOG_OPEN("libossomime"); @@ -223,22 +225,33 @@ } entry = g_new0 (AppEntry, 1); + + entry->service_name = service_name; entry->files = g_slist_append (NULL, (gpointer) file); - mime_launch (service_name, entry, con); + success = mime_launch (con, entry); - g_free (service_name); app_entry_free (entry); - return 1; + return success ? 1 : 0; } +static void +mime_open_file_list_foreach (const gchar *key, + AppEntry *entry, + GSList **list) +{ + *list = g_slist_prepend (*list, entry); +} + gint hildon_mime_open_file_list (DBusConnection *con, GSList *files) { GHashTable *apps = NULL; + GSList *list = NULL; GSList *l; gint num_apps; + gboolean success = TRUE; if (con == NULL) { DLOG_OPEN("libossomime"); @@ -254,8 +267,9 @@ return 0; } - apps = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, + apps = g_hash_table_new_full (g_str_hash, + g_str_equal, + NULL, (GDestroyNotify) app_entry_free); gnome_vfs_init (); /* make sure that gnome vfs is initialized */ @@ -275,26 +289,37 @@ entry = g_hash_table_lookup (apps, service_name); if (!entry) { entry = g_new0 (AppEntry, 1); - g_hash_table_insert (apps, service_name, entry); + + entry->service_name = service_name; + g_hash_table_insert (apps, entry->service_name, entry); + } else { + g_free (service_name); } - + entry->files = g_slist_append (entry->files, file); } else { dprint ("No service name for file '%s'", file); } } + num_apps = g_hash_table_size (apps); + g_hash_table_foreach (apps, (GHFunc) mime_open_file_list_foreach, &list); - g_hash_table_foreach (apps, (GHFunc) mime_launch, con); - g_hash_table_destroy (apps); + /* If we didn't find an application to launch, it's an error. */ + success &= list != NULL; - /* If we didn't find an application to launch, it's an error. */ - if (num_apps == 0) { - return 0; - } else { - return 1; + for (l = list; l; l = l->next) { + AppEntry *entry; + + entry = l->data; + success &= mime_launch (con, entry); } + + g_slist_free (list); + g_hash_table_destroy (apps); + + return success ? 1 : 0; } gint @@ -304,6 +329,7 @@ { AppEntry *entry; gchar *service_name; + gboolean success; if (con == NULL) { DLOG_OPEN("libossomime"); @@ -335,26 +361,79 @@ } entry = g_new0 (AppEntry, 1); + + entry->service_name = service_name; entry->files = g_slist_append (NULL, (gpointer) file); - mime_launch (service_name, entry, con); - - g_free (service_name); + success = mime_launch (con, entry); app_entry_free (entry); - return 1; + return success ? 1 : 0; } -static void mime_launch (const gchar *key, - AppEntry *entry, - DBusConnection *con) +static gboolean +mime_launch_notify_task_navigator (DBusConnection *con, + const gchar *service) { + DBusMessage *msg; + gboolean success = TRUE; + + /* From osso-rpc.c */ + /* Inform the task navigator that we are launching the service */ + dprint ("Notifying the task navigator..."); + + dprint ("Creating message for service: '%s'", TASK_NAV_SERVICE); + msg = dbus_message_new_method_call (TASK_NAV_SERVICE, + APP_LAUNCH_BANNER_METHOD_PATH, + APP_LAUNCH_BANNER_METHOD_INTERFACE, + APP_LAUNCH_BANNER_METHOD); + + if (msg) { + if (dbus_message_append_args (msg, + DBUS_TYPE_STRING, &service, + DBUS_TYPE_INVALID)) { + + if (dbus_connection_send (con, msg, NULL) == TRUE) { + dprint ("Sent message to service: '%s'", + TASK_NAV_SERVICE); + dbus_connection_flush (con); + } else { + dprint ("Couldn't send message to service: '%s'", + TASK_NAV_SERVICE); + success = FALSE; + } + + } else { + dprint ("Couldn't append msg with service: '%s'", + TASK_NAV_SERVICE); + success = FALSE; + } + + dbus_message_unref (msg); + } else { + dprint ("Couldn't create msg with method: '%s' to service: '%s'", + APP_LAUNCH_BANNER_METHOD, + TASK_NAV_SERVICE); + success = FALSE; + } + + return success; +} + +static gboolean +mime_launch (DBusConnection *con, + AppEntry *entry) +{ DBusMessage *msg; DBusMessageIter iter; + const gchar *key; gchar *service; gchar *object_path; gchar *interface; + gboolean success = TRUE; + key = entry->service_name; + /* If the service name has a '.', treat it as a full name, otherwise * prepend com.nokia. */ if (strchr (key, '.')) { @@ -368,59 +447,54 @@ object_path = g_strdup_printf ("/com/nokia/%s", key); interface = g_strdup (service); } - - dprint ("Activating service: %s\n", service); - msg = dbus_message_new_method_call (service, object_path, - interface, "mime_open"); + dprint ("Activating: '%s'...", key); + + dprint ("Creating message for service: '%s'", service); + msg = dbus_message_new_method_call (service, object_path, interface, "mime_open"); + if (msg) { dbus_message_set_no_reply (msg, TRUE); - dbus_message_iter_init_append (msg, &iter); + dprint ("Adding arguments:"); g_slist_foreach (entry->files, (GFunc) mime_launch_add_arg, &iter); - dbus_connection_send (con, msg, NULL); - dbus_connection_flush (con); + if (dbus_connection_send (con, msg, NULL) == TRUE) { + dprint ("Sent message to service: '%s'", service); + dbus_connection_flush (con); + + /* Update the task navigator */ + success = mime_launch_notify_task_navigator (con, service); + } else { + dprint ("Couldn't send message to service: '%s'", service); + success = FALSE; + } dbus_message_unref (msg); - - /* From osso-rpc.c */ - /* Inform the task navigator that we are launching the service */ - msg = dbus_message_new_method_call (TASK_NAV_SERVICE, - APP_LAUNCH_BANNER_METHOD_PATH, - APP_LAUNCH_BANNER_METHOD_INTERFACE, - APP_LAUNCH_BANNER_METHOD); - - if (msg) { - if (dbus_message_append_args (msg, - DBUS_TYPE_STRING, &service, - DBUS_TYPE_INVALID)) { - dbus_connection_send (con, msg, NULL); - dbus_connection_flush (con); - } else { - dprint ("Couldn't add service: %s\n", service); - } - dbus_message_unref (msg); - } else { - dprint ("Couldn't create msg to: %s\n", service); - } + } else { + dprint ("Couldn't create msg with method: 'mime-open' to service: '%s'", + service); + success = FALSE; } g_free (service); g_free (object_path); g_free (interface); + + return success; } -static void mime_launch_add_arg (const gchar *uri, - DBusMessageIter *iter) +static void +mime_launch_add_arg (const gchar *uri, + DBusMessageIter *iter) { if (!g_utf8_validate (uri, -1, NULL)) { g_warning ("Invalid UTF-8 passed to hildon_mime_open\n"); return; } - dprint (" %s\n", uri); + dprint ("URI: '%s'", uri); dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &uri); } Modified: projects/haf/trunk/libhildonmime/libhildonmime/hildon-mime.h =================================================================== --- projects/haf/trunk/libhildonmime/libhildonmime/hildon-mime.h 2007-04-17 10:38:37 UTC (rev 11107) +++ projects/haf/trunk/libhildonmime/libhildonmime/hildon-mime.h 2007-04-17 11:07:29 UTC (rev 11108) @@ -43,39 +43,45 @@ /*@{*/ /** + * hildon_mime_open_file: + * @con: The D-BUS connection to use. + * @file: A %const @gchar pointer URI to be opened (UTF-8). + * * This function opens a file in the application that has - * registered as the handler for the mime type of the file. - * @param con The D-BUS connection that we want to use. - * @param file A string representation of the GnomeVFS URI of the file to be - * opened (UTF-8). See hildonmime_open for more details. + * registered as the handler for the mime type of the @file. * + * The @file parameter must be a full URI, that is to say that it must + * be in the form of 'file:///etc/hosts'. + * * The mapping from mime type to D-BUS service is done by looking up the * application for the mime type and in the desktop file for that application * the X-Osso-Service field is used to get the D-BUS service. * - * @return 1 in case of success, < 1 if an error occurred or if some parameter - * is invalid. + * This function operates asynchronously, this means that if D-BUS has + * to open the application that handles this @file type and your + * application quits prematurely, the application may not open the + * @file. An event loop is expected to be used here to ensure D-BUS has + * a chance to send the message if the application isn't already started. + * + * Return: 1 in case of success, < 1 if an error occurred or if some parameter + * is invalid. */ gint hildon_mime_open_file (DBusConnection *con, const gchar *file); /** - * This function opens a list of files in the application that has - * registered as the handler for the mime type of the file. - * @param con The D-BUS connection that we want to use. - * @param files A list of string representations of the GnomeVFS URI of the file - * to be opened (UTF-8). See hildonmime_open for more details. - * - * These will be sent to the application that handles this MIME-type. - * If more then one type of file is specified, many applications may be - * launched. + * hildon_mime_open_file_list: + * @con: The D-BUS connection to use. + * @files: A @GList of %const @gchar pointer URIs to be opened (UTF-8). * - * The mapping from mime type to D-BUS service is done by looking up the - * application for the mime type and in the desktop file for that application - * the X-Osso-Service field is used to get the D-BUS service. + * This function opens a list of @files. The @files will be sent to + * each application that handles their MIME-type. If more then one + * type of file is specified, many applications may be launched. * - * @return 1 in case of success, < 1 if an error occurred or if some parameter + * For more information on opening files, see hildon_mime_open_file(). + * + * Return: 1 in case of success, < 1 if an error occurred or if some parameter * is invalid. */ gint hildon_mime_open_file_list (DBusConnection *con, @@ -83,16 +89,20 @@ /** - * This function opens a file in the application that has - * registered as the handler for the mime type of the file. - * @param con The D-BUS connection that we want to use. - * @param mime_type A string representation of the mime-type. + * hildon_mime_open_file_with_mime_type: + * @con: The D-BUS connection that we want to use. + * @file: A %const @gchar pointer URI to be opened (UTF-8). + * @mime_type: A %const @gchar pointer MIME-type to be used (UTF-8). * - * This operates similarly to hildonmime_open_file() with the exception - * that a file does not need to be given, and the @mime_type supplied - * is used without the need for checking the mime-type of the file itself. + * This function opens @file in the application that has + * registered as the handler for @mime_type. * - * @return 1 in case of success, < 1 if an error occurred or if some parameter + * The @file is optional. If it is omitted, the @mime_type is used + * to know which application to launch. + * + * For more information on opening files, see hildon_mime_open_file(). + * + * Return: 1 in case of success, < 1 if an error occurred or if some parameter * is invalid. */ gint hildon_mime_open_file_with_mime_type (DBusConnection *con, @@ -118,20 +128,25 @@ } HildonMimeCategory; /** - * Return the category the specified mime type is in. See - * hildon_mime_get_mime_types_for_category() for more information. + * hildon_mime_get_category_for_mime_type: + * @mime_type: A %const @gchar pointer MIME-type to be used (UTF-8). * - * @param mime_type The mime type. + * This function returns the @HildonMimeCategory for the specified + * @mime_type. See hildon_mime_get_mime_types_for_category() for more + * information. * -* @return The category that the mime type is in. -*/ + * Return: The category that the @mime_type is in. + */ HildonMimeCategory hildon_mime_get_category_for_mime_type (const gchar *mime_type); /** - * Returns a list of mime types that are in the specified category. The returned - * list should be freed by calling hildon_mime_types_list_free(). + * hildon_mime_get_mime_types_for_category: + * @category: The @HildonMimeCategory. * - * The mapping between category and mime type is handled through the shared mime + * This function returns a @GList of %const @gchar pointer mime types + * that are in the specified category. + * + * The mapping between @category and mime type is handled through the shared mime * info. Add the tag <osso:category name="name"/> to a mime type to specify that * the mime type is in the category "name". Valid category names are: * @@ -139,40 +154,42 @@ * * An example: * - * <mime-type type="text/plain"> - * <osso:category name="documents"/> - * </mime-type> - * - * @param category The category. + * <mime-type type="text/plain"> + * <osso:category name="documents"/> + * </mime-type> * - * @return A list of mime types, represented as strings, or NULL if none were - * found or not valid category. + * Return: A newly allocated @GList which should be freed with + * hildon_mime_types_list_free() OR %NULL if none were found. */ GList * hildon_mime_get_mime_types_for_category (HildonMimeCategory category); /** - * Frees the list of mime types as returned by + * hildon_mime_types_list_free: + * @list: A @GList of mime types. + * + * Frees the list of mime types returned by * hildon_mime_get_mime_types_for_category(). - * - * @param list A list of mime types. */ void hildon_mime_types_list_free (GList *list); /** - * Returns the name of the specified category. - * - * @param category The category. + * hildon_mime_get_category_name: + * @category: The @HildonMimeCategory. * - * @return The name of the category, should not be freed or modified. + * This function returns the name of the specified category. + * + * Return: The %const @gchar pointer name of the category, this should not + * be freed or modified. */ const gchar * hildon_mime_get_category_name (HildonMimeCategory category); /** - * Returns the category corresponding to the given name. - * - * @param category The category name. + * hildon_mime_get_category_from_name: + * @category: The %const @gchar pointer category name. * - * @return The category. + * This function returns the @HildonMimeCategory corresponding to @category. + * + * Return: The @HildonMimeCategory. */ HildonMimeCategory hildon_mime_get_category_from_name (const gchar *category); @@ -184,25 +201,28 @@ /*@{*/ /** + * hildon_mime_application_get_mime_types: + * @application_id: The application id, as returned by GnomeVFS. + * * Returns a list of mime types supported by the application corresponding to - * the specified appliction id. The returned list should be freed by calling - * hildon_mime_application_mime_types_list_free(). + * the specified @appliction_id. * * The list of mime types is specifed in the desktop file for the application * with the MimeType field. - * - * @param application_id The application id, as returned by GnomeVFS. * - * @return A list of mime types, represented as strings, or NULL if none were - * found. + * Return: A newly allocated @GList of %const @gchar pointer mime + * types which should be freed with + * hildon_mime_application_mime_types_list_free() OR %NULL if none were + * found. */ GList * hildon_mime_application_get_mime_types (const gchar *application_id); /** - * Frees the list of mime types as returned by - * hildon_mime_application_get_mime_types(). + * hildon_mime_application_mime_types_list_free: + * @mime_types: A @GList of %const @gchar pointer mime types. * - * @param mime_types A list of mime types. + * Frees the list of mime_types as returned by + * hildon_mime_application_get_mime_types(). */ void hildon_mime_application_mime_types_list_free (GList *mime_types); @@ -214,24 +234,27 @@ /*@{*/ /** - * Returns a NULL terminated array of icon names for the specified mime - * type. The icon names are GtkIconTheme names. A number of names are returned, - * ordered by how specific they are. For example, if the mime type "image/png" - * is passed, the first icon name might correspond to a png file, the second to - * an image file, and the third to a regular file. + * hildon_mime_get_icon_names: + * @mime_type: The %const @gchar pointer mime type + * @file_info: Optional GnomeVFSFileInfo struct, or %NULL + * + * This function returns a %NULL terminated array of icon names for + * the specified @mime_type. The icon names are @GtkIconTheme names. A + * number of names are returned, ordered by how specific they are. For + * example, if the mime type "image/png" is passed, the first icon + * name might correspond to a png file, the second to an image file, + * and the third to a regular file. * - * In order to decide which icon to use, the existance of it in the icon theme - * should be checked with gtk_icon_theme_has_icon(). If the first icon is not - * available, try the next etc. + * In order to decide which icon to use, the existance of it in the + * icon theme should be checked with gtk_icon_theme_has_icon(). If the + * first icon is not available, try the next etc. * - * The optional GnomeVFSFileInfo struct is used to get additional information - * about a file or directory that might help to get the right icon. + * The optional GnomeVFSFileInfo struct is used to get additional + * information about a file or directory that might help to get the + * right icon. * - * @param mime_type The mime type - * @param file_info Optional GnomeVFSFileInfo struct, or NULL - * - * @return A newly allocated array of icon name strings. Should be freed with - * g_strfreev(). + * Return: A newly allocated array of icon name strings which should be freed with + * g_strfreev() OR %NULL if none were found. */ gchar ** hildon_mime_get_icon_names (const gchar *mime_type, GnomeVFSFileInfo *file_info); Modified: projects/haf/trunk/libhildonmime/tests/test-open.c =================================================================== --- projects/haf/trunk/libhildonmime/tests/test-open.c 2007-04-17 10:38:37 UTC (rev 11107) +++ projects/haf/trunk/libhildonmime/tests/test-open.c 2007-04-17 11:07:29 UTC (rev 11108) @@ -2,7 +2,7 @@ /* * This is file is part of libhildonmime * - * Copyright (C) 2004-2006 Nokia Corporation. + * Copyright (C) 2004-2007 Nokia Corporation. * * Contact: Erik Karlsson <erik.b.karlsson at nokia.com> * @@ -23,48 +23,127 @@ */ #include <config.h> +#include <stdlib.h> #include <hildon-mime.h> +static gboolean use_system = FALSE; +static gchar *open_uri = NULL; +static gchar **open_uri_list = NULL; +static gchar *mime_type = NULL; + +static GOptionEntry entries[] = { + { "open-uri", 'o', + 0, G_OPTION_ARG_STRING, + &open_uri, + "Open a URI (for example, \"-l file://...\")", + NULL }, + { "open-uri-list", 'l', + 0, G_OPTION_ARG_STRING_ARRAY, + &open_uri_list, + "Open a list of URIs (for example, \"-l file://... -l file://...\", etc)", + NULL }, + { "mime-type", 'm', + 0, G_OPTION_ARG_STRING, + &mime_type, + "Opens the application associated with the mime-type (used WITH --open-uri)", + NULL}, + { "system", 's', + 0, G_OPTION_ARG_NONE, + &use_system, + "Use SYSTEM bus instead of SESSION bus for the D-Bus connection", + NULL }, + { NULL } +}; + +static gboolean +quit_cb (GMainLoop *main_loop) +{ + g_main_loop_quit (main_loop); + return FALSE; +} + int main (int argc, char** argv) { - DBusConnection *conn; - gint ret; + DBusConnection *con; + GMainLoop *main_loop; + GOptionContext *context; + gboolean success; - if (argc < 2) { - g_printerr ("Usage: %s <URI> [<mime-type>]\n", argv[0]); - return 1; - } - - conn = dbus_bus_get (DBUS_BUS_SESSION, NULL); - g_assert (conn != NULL); + context = g_option_context_new ("- test the hildon-open API."); + g_option_context_add_main_entries (context, entries, NULL); + g_option_context_parse (context, &argc, &argv, NULL); + g_option_context_free (context); - g_print ("\nTesting hildon_mime_open_file() with URI:'%s'\n", argv[1]); - ret = hildon_mime_open_file (conn, argv[1]); - if (ret != 1) { - g_print ("Error\n"); - } else { - g_print ("Success\n"); + if (!open_uri && !mime_type && !open_uri_list) { + g_printerr ("Usage: %s --help\n", argv[0]); + return EXIT_FAILURE; } - g_print ("\nTesting hildon_mime_open_file_list() with URI:'%s'\n", argv[1]); - ret = hildon_mime_open_file_list (conn, g_slist_append (NULL, argv[1])); - if (ret != 1) { - g_print ("Error\n"); + if (!use_system) { + g_print ("---- Using SESSION bus\n"); + con = dbus_bus_get (DBUS_BUS_SESSION, NULL); } else { - g_print ("Success\n"); + g_print ("---- Using SYSTEM bus\n"); + con = dbus_bus_get (DBUS_BUS_SYSTEM, NULL); } - if (argc > 2 && argv[2]) { - g_print ("\nTesting hildon_mime_open_file_with_mime() with URI:'%s' and MIME:'%s'\n", - argv[1], argv[2]); - ret = hildon_mime_open_file_with_mime_type (conn, argv[1], argv[2]); - if (ret != 1) { - g_print ("Error\n"); + if (!con) { + g_printerr ("Could not get D-Bus connection\n"); + return EXIT_FAILURE; + } + + if (open_uri_list) { + GSList *uris = NULL; + const gchar *uri; + gint i = 0; + + while ((uri = open_uri_list[i++]) != NULL) { + uris = g_slist_append (uris, g_strdup (uri)); + } + + g_print ("---> hildon_uri_open_file_list() with %d URIs\n", g_slist_length (uris)); + success = hildon_mime_open_file_list (con, uris) == 1; + g_slist_foreach (uris, (GFunc) g_free, NULL); + g_slist_free (uris); + + if (!success) { + g_print ("<--- Error\n"); + return EXIT_FAILURE; } else { - g_print ("Success\n"); + g_print ("<--- Success\n"); } } + + if (open_uri && !mime_type) { + g_print ("---> Testing hildon_mime_open_file() with URI: '%s'\n", open_uri); + success = hildon_mime_open_file (con, open_uri) == 1; + if (!success) { + g_print ("<--- Error\n"); + return EXIT_FAILURE; + } else { + g_print ("<--- Success\n"); + } + } - return 0; + if (open_uri && mime_type) { + g_print ("---> Testing hildon_mime_open_file_with_mime() with URI: '%s' and MIME: '%s'\n", + open_uri, mime_type); + + success = hildon_mime_open_file_with_mime_type (con, open_uri, mime_type) == 1; + if (!success) { + g_print ("<--- Error\n"); + return EXIT_FAILURE; + } else { + g_print ("<--- Success\n"); + } + } + + /* Quit after 2 seconds, which should be long enough */ + main_loop = g_main_loop_new (NULL, FALSE); + g_timeout_add (2000, (GSourceFunc) quit_cb, main_loop); + g_main_loop_run (main_loop); + g_main_loop_unref (main_loop); + + return EXIT_SUCCESS; }
- Previous message: [maemo-commits] r11107 - in projects/haf/trunk/hildon-desktop: . debian
- Next message: [maemo-commits] r11109 - in projects/haf/trunk/hildon-theme-layout-4: . rc
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]