[maemo-commits] [maemo-commits] r8957 - in projects/haf/trunk/libossomime: . libossomime tests tests/datadir/applications/test

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Thu Jan 4 16:15:07 EET 2007
Author: martyn
Date: 2007-01-04 16:15:04 +0200 (Thu, 04 Jan 2007)
New Revision: 8957

Added:
   projects/haf/trunk/libossomime/tests/datadir/applications/test/osso-addressbook.desktop
Modified:
   projects/haf/trunk/libossomime/ChangeLog
   projects/haf/trunk/libossomime/libossomime/osso-uri.c
   projects/haf/trunk/libossomime/tests/datadir/applications/test/browser.desktop
   projects/haf/trunk/libossomime/tests/test-all.c
Log:
	* osso-uri.c: (uri_get_desktop_file_actions),
	(uri_get_desktop_file_actions_filtered), (osso_uri_get_actions),
	(osso_uri_get_actions_by_uri):

	* tests/datadir/applications/test/browser.desktop:
	* tests/datadir/applications/test/osso-addressbook.desktop: Added
	2 of the new format desktop files for testing with.

	* tests/test-all.c: Added tests for osso_uri_get_actions_by_uri()
	and test the types of actions which we would expect to be returned.


Modified: projects/haf/trunk/libossomime/ChangeLog
===================================================================
--- projects/haf/trunk/libossomime/ChangeLog	2007-01-04 11:36:58 UTC (rev 8956)
+++ projects/haf/trunk/libossomime/ChangeLog	2007-01-04 14:15:04 UTC (rev 8957)
@@ -1,3 +1,28 @@
+2007-01-04  Martyn Russell  <martyn at imendio.com>
+
+	* libossomime/osso-uri.c: Don't error if NULL is given for
+	osso_uri_free_actions(), just silently return. Fixed
+	osso_uri_get_actions_by_uri() which wasn't using the action type
+	parameter to filter the actions returned.
+	
+	* tests/datadir/applications/test/browser.desktop:
+	* tests/datadir/applications/test/osso-addressbook.desktop: Added
+	2 of the new format desktop files for testing with.
+	
+	* tests/test-all.c: Added tests for osso_uri_get_actions_by_uri()
+	and test the types of actions which we would expect to be returned.
+
+2007-01-03  Martyn Russell  <martyn at imendio.com>
+
+	* tests/test-all.c:
+	* tests/datadir/applications/test/osso-addressbook.desktop: 
+	* tests/datadir/applications/test/browser.desktop: Add 2 new tests
+	for the new desktop file format. 
+
+	* libossomime/osso-uri.c (uri_get_desktop_file_actions_filtered):
+	Fix this function so we actually filter on the action type, before
+	we didn't do this which made the type in _get_actions() useless.
+
 2007-01-02  Martyn Russell  <martyn at imendio.com>
 
 	* libossomime/osso-uri.c: Fixed a problem with

Modified: projects/haf/trunk/libossomime/libossomime/osso-uri.c
===================================================================
--- projects/haf/trunk/libossomime/libossomime/osso-uri.c	2007-01-04 11:36:58 UTC (rev 8956)
+++ projects/haf/trunk/libossomime/libossomime/osso-uri.c	2007-01-04 14:15:04 UTC (rev 8957)
@@ -63,8 +63,8 @@
 #define APP_LAUNCH_BANNER_METHOD            "app_launch_banner"
 
 
-#define DEBUG_MSG(x)  
-/*#define DEBUG_MSG(args) g_printerr args ; g_printerr ("\n");*/
+#define DEBUG_MSG(x)
+/* #define DEBUG_MSG(args) g_printerr args ; g_printerr ("\n"); */
 
 /* The ID is the group name in the desktop file for this
  * action, the domain is the translation domain used for the
@@ -111,6 +111,7 @@
 static GSList *          uri_get_desktop_file_actions          (const gchar       *desktop_file,
 								const gchar       *scheme);
 static GSList *          uri_get_desktop_file_actions_filtered (GSList            *actions,
+								OssoURIActionType  filter_action_type,
 								const gchar       *filter_mime_type);
 static GSList *          uri_get_desktop_file_info             (const gchar       *desktop_file,
 								const gchar       *scheme);
@@ -673,8 +674,9 @@
 }
 
 static GSList *
-uri_get_desktop_file_actions_filtered (GSList      *actions,
-				       const gchar *filter_mime_type)
+uri_get_desktop_file_actions_filtered (GSList            *actions,
+				       OssoURIActionType  filter_action_type,
+				       const gchar       *filter_mime_type)
 {
 	GSList *l;
 	GSList *actions_filtered = NULL;
@@ -685,18 +687,27 @@
 	 * and free the old list.
 	 */
 
+	DEBUG_MSG (("URI: Filtering actions..."));
+
 	for (l = actions; l; l = l->next) {
 		OssoURIAction *action;
 		gboolean       add_to_list = FALSE;
 
 		action = l->data;
 	
+		if (filter_action_type != -1 && action->type != filter_action_type) {
+			DEBUG_MSG (("URI: \tIgnoring action:'%s', type:%d, "
+				    "because filter action type = %d", 
+				    action->name, action->type, filter_action_type));
+			continue;
+		}
+
 		if ((action->type == OSSO_URI_ACTION_FALLBACK && 
 		     filter_mime_type == NULL) ||
 		    (action->type == OSSO_URI_ACTION_NEUTRAL)) {
 			add_to_list = TRUE;
 
-			DEBUG_MSG (("Adding action:'%s' to list (neutral||fallback)", 
+			DEBUG_MSG (("URI: \tAdding action:'%s' to list (neutral||fallback)", 
 				    action->name));
 		} 
 		else if (action->type == OSSO_URI_ACTION_NORMAL && 
@@ -711,7 +722,7 @@
 				if (g_ascii_strcasecmp (strv[i], filter_mime_type) == 0) {
 					add_to_list = TRUE;
 
-					DEBUG_MSG (("Adding action:'%s' to list (normal)", 
+					DEBUG_MSG (("URI: \tAdding action:'%s' to list (normal)", 
 						    action->name));
 
 					break;
@@ -721,15 +732,21 @@
 			g_strfreev (strv);
 		}
 
-		if (add_to_list) {
-			actions_filtered = g_slist_append (actions_filtered, 
-							   osso_uri_action_ref (action));
+		if (!add_to_list) {
+			DEBUG_MSG (("URI: \tIgnoring action:'%s', type:%d", 
+				    action->name, action->type));
+			continue;
 		}
+
+		actions_filtered = g_slist_append (actions_filtered, 
+						   osso_uri_action_ref (action));
 	}
 
-	DEBUG_MSG (("Filtering %d actions by mime type:'%s', returning %d actions", 
+	DEBUG_MSG (("URI: Filtering %d actions by mime type:'%s' and "
+		    "action type:'%s', returning %d actions", 
 		    g_slist_length (actions), 
 		    filter_mime_type, 
+		    uri_action_type_to_string (filter_action_type),
 		    g_slist_length (actions_filtered)));
 
 	g_slist_foreach (actions, (GFunc) osso_uri_action_unref, NULL);
@@ -1266,7 +1283,7 @@
 
 GSList *  
 osso_uri_get_actions_by_uri (const gchar        *uri_str,
-			     OssoURIActionType   type,
+			     OssoURIActionType   action_type,
 			     GError            **error)
 {
 	GnomeVFSURI      *uri;
@@ -1321,13 +1338,47 @@
 		filename = l->data;
 
 		actions_found = uri_get_desktop_file_actions (filename, scheme);
-		actions_found = uri_get_desktop_file_actions_filtered (actions_found, 
-								       mime_type);
 		if (actions_found) {
 			actions = g_slist_concat (actions, actions_found);
 		}
 	}
 
+#ifdef EXTRA_DEBUGGING
+	{
+		gint count = 0;
+
+		DEBUG_MSG (("URI: Actions found:"));
+		
+		for (l = actions; l; l = l->next) {
+			OssoURIAction *action;
+			
+			action = l->data;
+			DEBUG_MSG (("URI: \tAction %2.2d:'%s', type:'%s'", 
+				    ++count, action->name, 
+				    uri_action_type_to_string (action->type)));
+		}
+	}
+#endif
+
+	actions = uri_get_desktop_file_actions_filtered (actions, 
+							 action_type, 
+							 mime_type);
+
+#ifdef EXTRA_DEBUGGING
+	{
+		gint count = 0;
+
+		DEBUG_MSG (("URI: Actions returned:"));
+		
+		for (l = actions; l; l = l->next) {
+			OssoURIAction *action;
+			
+			action = l->data;
+			DEBUG_MSG (("URI: \tAction %2.2d:'%s'", ++count, action->name));
+		}
+	}
+#endif
+
 	g_slist_foreach (desktop_files, (GFunc) g_free, NULL);
 	g_slist_free (desktop_files);
 	
@@ -1340,8 +1391,10 @@
 void   
 osso_uri_free_actions (GSList *list)
 {
-	g_return_if_fail (list != NULL);
-	
+	if (list == NULL) {
+		return;
+	}
+
 	g_slist_foreach (list, (GFunc) osso_uri_action_unref, NULL);
 	g_slist_free (list);
 }

Modified: projects/haf/trunk/libossomime/tests/datadir/applications/test/browser.desktop
===================================================================
--- projects/haf/trunk/libossomime/tests/datadir/applications/test/browser.desktop	2007-01-04 11:36:58 UTC (rev 8956)
+++ projects/haf/trunk/libossomime/tests/datadir/applications/test/browser.desktop	2007-01-04 14:15:04 UTC (rev 8957)
@@ -1,13 +1,37 @@
 [Desktop Entry]
 Encoding=UTF-8
-Version=1.0
+Version=0.1
 Type=Application
-Name=browser
-X-Osso-Service=browser
-MimeType=image/png;
-X-Osso-URI-Actions=http;
+Name=weba_ap_web_browser
+Comment=weba_ap_web_browser_thumb
+Exec=/usr/bin/browser
+Icon=qgn_list_browser
+X-Window-Icon=qgn_list_browser
+X-Window-Icon-Dimmed=qgn_list_browser
+X-Osso-Service=osso_browser
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
+MimeType=text/html;text/css;text/sgml;text/x-dtd;application/x-javascript;image/gif;image/jpeg;image/png;image/vnd.wap.wbmp;image/pjpeg;image/bmp;image/x-windows-bmp;image/x-ms-bmp;image/xbm;image/ico;image/x-ico;image/x-xbitmap;text/plain;application/x-shockwave-flash;
 
-[X-Osso-URI-Action Handler http]
-Method=browser_open
-Name=browser_open
-TranslationDomain=foo_bar_domain
+[X-Osso-URI-Actions]
+http=X-Osso-URI-Action-Open;X-Osso-URI-Action-Save;X-Osso-URI-Action-Fallback
+https=X-Osso-URI-Action-Open;X-Osso-URI-Action-Save;X-Osso-URI-Action-Fallback
+ftp=X-Osso-URI-Action-Open;X-Osso-URI-Action-Save;X-Osso-URI-Action-Fallback
+file=X-Osso-URI-Action-Open;X-Osso-URI-Action-Save;X-Osso-URI-Action-Fallback
+
+[X-Osso-URI-Action-Open]
+Method=load_url
+Name=uri_link_open_link
+TranslationDomain=osso-uri
+
+[X-Osso-URI-Action-Save]
+Type=Neutral
+Method=save_url
+Name=uri_link_save_link
+TranslationDomain=osso-uri
+
+[X-Osso-URI-Action-Fallback]
+Type=Fallback
+Method=load_url_fallback
+Name=uri_link_open_link_fallback
+TranslationDomain=osso-uri

Added: projects/haf/trunk/libossomime/tests/datadir/applications/test/osso-addressbook.desktop
===================================================================
--- projects/haf/trunk/libossomime/tests/datadir/applications/test/osso-addressbook.desktop	2007-01-04 11:36:58 UTC (rev 8956)
+++ projects/haf/trunk/libossomime/tests/datadir/applications/test/osso-addressbook.desktop	2007-01-04 14:15:04 UTC (rev 8957)
@@ -0,0 +1,26 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Name=addr_ap_address_book
+Comment=addr_ap_address_book_thumb
+Exec=/usr/bin/osso-addressbook
+X-Osso-Service=osso_addressbook
+Icon=qgn_list_addressbook
+StartupWMClass=osso-addressbook
+MimeType=text/x-vcard
+
+[X-Osso-URI-Actions]
+mailto=X-Osso-URI-Action-Add-Contact;
+xmpp=X-Osso-URI-Action-Add-Account;
+sipto=X-Osso-URI-Action-Add-Account;
+
+[X-Osso-URI-Action-Add-Contact]
+Method=add_account
+Name=addr_me_cs_addtocontacts
+TranslationDomain=osso-addressbook
+
+[X-Osso-URI-Action-Add-Account]
+Method=add_account
+Name=addr_ap_address_book
+TranslationDomain=osso-addressbook

Modified: projects/haf/trunk/libossomime/tests/test-all.c
===================================================================
--- projects/haf/trunk/libossomime/tests/test-all.c	2007-01-04 11:36:58 UTC (rev 8956)
+++ projects/haf/trunk/libossomime/tests/test-all.c	2007-01-04 14:15:04 UTC (rev 8957)
@@ -108,8 +108,8 @@
 
 	/* Test with more than 1 action. */
 	g_print ("For http\n");
-	actions = osso_uri_get_actions ("http", NULL);
-	assert_int (g_slist_length (actions), 2);
+	actions = osso_uri_get_actions_by_uri ("http://www.nokia.com", -1, NULL);
+	assert_int (g_slist_length (actions), 3);
 	action = actions->data;
 	osso_uri_free_actions (actions);
 
@@ -173,20 +173,50 @@
 
 	/* The browser should be the default for http. */
 	g_print ("For http\n");
+	actions = osso_uri_get_actions_by_uri ("http://www.nokia.com", -1, NULL);
+	assert_int (g_slist_length (actions), 3);
 
-	actions = osso_uri_get_actions ("http", NULL);
-	assert_int (g_slist_length (actions), 2);
-
 	/* The default. */
-	assert_bool (is_default_action (actions, "browser_open"));
+	assert_bool (is_default_action (actions, "uri_link_open_link"));
 
 	/* Existing, non-default. */
-	assert_bool (!is_default_action (actions, "image_viewer_open"));
+	assert_bool (!is_default_action (actions, "uri_link_save_link"));
 
 	/* Non-existing. */
 	assert_bool (!is_default_action (actions, "foo_open"));
 	
 	osso_uri_free_actions (actions);
+
+	/* Basic use of the new API to get actions by a URI */
+	actions = osso_uri_get_actions_by_uri ("http://www.nokia.com", OSSO_URI_ACTION_NORMAL, NULL);
+	assert_int (g_slist_length (actions), 1);
+	osso_uri_free_actions (actions);
+
+	/* Getting neutral actions which apply in all conditions where
+	 * there is a known mime type. There are 2 here because we
+	 * also have the older desktop file which defaults as a
+	 * neutral action type. 
+	 */
+	actions = osso_uri_get_actions_by_uri ("http://www.nokia.com", OSSO_URI_ACTION_NEUTRAL, NULL);
+	assert_int (g_slist_length (actions), 2);
+	osso_uri_free_actions (actions);
+
+	/* Fallbacks only get returned if the mime type is unknown, so
+	 * we test with something known first and then with something
+	 * unknown second. 
+	 */
+	actions = osso_uri_get_actions_by_uri ("http://www.nokia.com", OSSO_URI_ACTION_FALLBACK, NULL);
+	assert_int (g_slist_length (actions), 0);
+	osso_uri_free_actions (actions);
+
+	actions = osso_uri_get_actions_by_uri ("http://www.imendio.com/sliff.sloff", OSSO_URI_ACTION_FALLBACK, NULL);
+	assert_int (g_slist_length (actions), 1);
+	osso_uri_free_actions (actions);
+
+	/* FIXME: Finish this and test
+	 * osso_uri_get_default_action_by_uri() &
+	 * osso_uri_set_default_action_by_uri() 
+	 */
 }
 
 static void
@@ -204,12 +234,11 @@
 
 	/* The browser should be the default for http. */
 	g_print ("For http\n");
+	actions = osso_uri_get_actions_by_uri ("http://www.imendio.com", -1, NULL);
+	assert_int (g_slist_length (actions), 3);
 
-	actions = osso_uri_get_actions ("http", NULL);
-	assert_int (g_slist_length (actions), 2);
-
 	/* The default. */
-	assert_bool (is_default_action (actions, "browser_open"));
+	assert_bool (is_default_action (actions, "uri_link_open_link"));
 
 	/* Override the default. */
 	action = NULL;
@@ -241,7 +270,7 @@
 	}
 
 	/* We're back to the system default. */
-	assert_bool (is_default_action (actions, "browser_open"));
+	assert_bool (is_default_action (actions, "uri_link_open_link"));
 	
 	osso_uri_free_actions (actions);
 
@@ -256,39 +285,44 @@
 	GError   *error = NULL;
 	gboolean  ret;
 
+	if (!gnome_vfs_init()) {
+		g_error ("Could not initialise GnomeVFS");
+		return 1;
+	}
+
 	/* Use our custom data here. */
 	g_setenv ("XDG_DATA_DIRS", TEST_DATADIR, TRUE);
 	g_setenv ("XDG_DATA_HOME", TEST_DATADIR "-local", TRUE);
 
-	tmp = g_strdup_printf ("../libossomime/osso-update-category-database %s",
+	tmp = g_strdup_printf ("../libossomime/osso-update-category-database -v %s",
 			       TEST_DATADIR "/mime");
 	ret = g_spawn_command_line_sync (tmp, NULL, NULL, NULL, &error);
 	g_free (tmp);
 	if (!ret) {
-		g_print ("Couldn't launch ../libossomime/osso-update-category-database: %s\n",
-			 error->message);
+		g_printerr ("Couldn't launch ../libossomime/osso-update-category-database: %s\n",
+			    error->message);
 		g_clear_error (&error);
 		return 1;
 	}
 	
-	tmp = g_strdup_printf ("update-mime-database %s",
+	tmp = g_strdup_printf ("update-mime-database -v %s",
 			       TEST_DATADIR "/mime");
 	ret = g_spawn_command_line_sync (tmp, NULL, NULL, NULL, &error);
 	g_free (tmp);
 	if (!ret) {
-		g_print ("Couldn't launch update-mime-database: %s\n",
-			 error->message);
+		g_printerr ("Couldn't launch update-mime-database: %s\n",
+			    error->message);
 		g_clear_error (&error);
 		return 1;
 	}
 	
-	tmp = g_strdup_printf ("update-desktop-database %s",
+	tmp = g_strdup_printf ("update-desktop-database -v %s",
 			       TEST_DATADIR "/applications");
 	ret = g_spawn_command_line_sync (tmp, NULL, NULL, NULL, &error);
 	g_free (tmp);
 	if (!ret) {
-		g_print ("Couldn't launch update-desktop-database: %s\n",
-			 error->message);
+		g_printerr ("Couldn't launch update-desktop-database: %s\n",
+			    error->message);
 		g_clear_error (&error);
 		return 1;
 	}
@@ -298,7 +332,6 @@
 		test_get_actions ();
 	}
 
-	
 	test_system_default_actions ();
 	test_local_default_actions ();
 


More information about the maemo-commits mailing list