Logo Search packages:      
Sourcecode: libhildonmime version File versions  Download package

HildonURIAction* hildon_uri_get_default_action_by_uri ( const gchar *  uri_str,
GError **  error 

hildon_uri_get_default_action_by_uri : A string which represents a uri : The address of a pointer to a structure. This is optional and can be NULL.

: Use () instead.

This returns the which is the default for a . This function works similarly to () with the difference being that the mime type of the uri is used to look up the action. The reason for this being that default actions now are effective with scheme and mime type instead of JUST the scheme as before.

If NULL is returned and is NULL then there is no default for . If NULL is returned and is non-NULL, it will hold the error that occurred while trying to obtain the default .

Return: The default for .

Definition at line 1961 of file hildon-uri.c.

Referenced by hildon_uri_is_default_action_by_uri().

      GKeyFile         *key_file;
      GnomeVFSURI      *uri;
      GnomeVFSFileInfo *info;
      GnomeVFSResult    result;
      HildonURIAction  *action = NULL;
      gchar            *scheme = NULL;
      gchar            *mime_type = NULL;
      gchar            *desktop_file = NULL;
      gchar            *filename;
      gchar            *full_path = NULL;
      gboolean          ok;

      g_return_val_if_fail (uri_str != NULL && uri_str[0] != '\0', NULL);

      uri = gnome_vfs_uri_new (uri_str);
      if (!uri) {
            g_set_error (error,
                       "Could not create GnomeVFSURI from uri");
            return NULL;

      /* Get scheme */
      scheme = g_strdup (gnome_vfs_uri_get_scheme (uri));
      if (!scheme || scheme[0] == '\0') {
            gnome_vfs_uri_unref (uri);
            g_set_error (error,
                       "The scheme could not be obtained from the uri.");
            return NULL;

      /* Get mime type */
      info = gnome_vfs_file_info_new ();

      result = gnome_vfs_get_file_info (uri_str, info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE);
      if (result == GNOME_VFS_OK && 
          info->mime_type && 
          info->mime_type != '\0') {
            mime_type = g_strdup (info->mime_type);

      DEBUG_MSG (("URI: Getting default action by uri:'%s', with scheme:'%s' and mime type'%s'", 
                uri_str, scheme, mime_type));

      gnome_vfs_file_info_unref (info);
      gnome_vfs_uri_unref (uri);

      /* Open file and get the mime type and action name */
      key_file = g_key_file_new ();

      filename = g_build_filename ("applications", 

      ok = g_key_file_load_from_data_dirs (key_file, 

      DEBUG_MSG (("URI: Getting default actions from file:'%s'", full_path));

      if (ok) {
            gchar *str;

            if (mime_type) {
                  gchar *group;

                  str = strchr (mime_type, '/');
                  if (str) {
                        str[0] = '-';

                  group = g_strdup_printf (HILDON_URI_DEFAULTS_GROUP_FORMAT, scheme);
                  str = g_key_file_get_string (key_file, group, mime_type, NULL);
                  DEBUG_MSG (("URI: Found string:'%s' in group:'%s'", str, group));
                  g_free (group);

                  if (str) {
                        action = uri_get_desktop_file_action (scheme, str);
                        g_free (str);

            if (!action) {
                  /* We fallback to the old function here because it is
                   * used for neutral and fallback actions.
                  DEBUG_MSG (("URI: Getting default action by falling back to old "
                            "function just using scheme:'%s'", 

                  str = g_key_file_get_string (key_file, HILDON_URI_DEFAULTS_GROUP, scheme, NULL);
                  if (str) {
                        action = uri_get_desktop_file_action (scheme, str);
                        g_free (str);

      g_key_file_free (key_file);

      g_free (desktop_file);
      g_free (filename);
      g_free (mime_type);
      g_free (scheme);

      return action;

Generated by  Doxygen 1.6.0   Back to index