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

gboolean hildon_uri_open ( const gchar *  uri,
HildonURIAction *  action_to_try,
GError **  error 
)

hildon_uri_open: : A string which represents a URI. : A pointer. This is optional and NULL can be specified to use the default action instead. : The address of a pointer to a structure. This is optional and can be NULL.

This will open the with the application associated with . Using the details in , a DBus signal is sent to the application to open .

If is NULL then the default action will be tried. If the default action is NULL, the first available action in the desktop file is used instead.

If FALSE is returned and is non-NULL, it will hold the error that occurred while trying to open .

Return: TRUE if successfull or FALSE.

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

References hildon_uri_action_ref(), hildon_uri_action_unref(), hildon_uri_free_actions(), hildon_uri_get_actions(), hildon_uri_get_default_action(), and hildon_uri_get_scheme_from_uri().

{
      DBusConnection   *connection;
      HildonURIAction  *action;
      gchar            *scheme;
      GSList           *uris = NULL;
      const gchar      *str;
      gboolean          ok;
      gboolean          cleanup_action = FALSE;

      connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
      if (!connection) {
            str = "Could not get DBus connection";
            DEBUG_MSG (("URI: %s", str));
            
            g_set_error (error,
                       HILDON_URI_ERROR,
                       HILDON_URI_DBUS_FAILED,
                       str);

            return FALSE;
      }

      scheme = hildon_uri_get_scheme_from_uri (uri, error);
      if (!scheme || scheme[0] == '\0') {
            /* Error is filled in by _get_scheme_from_uri(). */
            return FALSE;
      }

      action = action_to_try;
      if (!action) {
            DEBUG_MSG (("URI: Attempting to open URI:'%s' using the default "
                      "since no action was given.",
                      uri));
            
            /* TODO: Fix this, what was the idea here */
/*
            if (action->id) {
                  action = hildon_uri_get_default_action_by_uri (uri, error);
            } else {
*/
            action = hildon_uri_get_default_action (scheme, error);

/*          }
 */
            cleanup_action = TRUE;

            if (!action) {
                  GSList *actions;

                  /* The error parameter is NULL here since it
                   * checks the scheme is ok and we have already
                   * done that in this function, plus if we get
                   * an error further down, we want to use it
                   * for that.
                   */
                  actions = hildon_uri_get_actions (scheme, NULL);

                  /* At this stage we choose the first action
                   * available from the long list picked up in
                   * the desktop file. 
                   */
                  if (actions) {
                        action = g_slist_nth_data (actions, 0);
                        if (action) {
                              hildon_uri_action_ref (action);
                        }

                        hildon_uri_free_actions (actions);
                  }

                  g_clear_error (error);

                  if (!action) {
                        gchar *error_str;

                        error_str = g_strdup_printf 
                              ("No actions exist for the scheme '%s'", scheme);
                        
                        DEBUG_MSG (("URI: %s", error_str));

                        g_set_error (error,
                                   HILDON_URI_ERROR,
                                   HILDON_URI_NO_ACTIONS,
                                   error_str);

                        g_free (error_str);

                        return FALSE;
                  }

                  DEBUG_MSG (("URI: Using first action available for scheme:'%s'", scheme));
            }
      }

      g_free (scheme);

      uris = g_slist_append (uris, (gchar*)uri);
      ok = uri_launch (connection, action, uris);
      g_slist_free (uris);

      if (cleanup_action) {
            hildon_uri_action_unref (action);
      }
      
      if (!ok) {
            str = "Failed to open URI using DBus";
            DEBUG_MSG (("URI: %s", str));

            g_set_error (error,
                       HILDON_URI_ERROR,
                       HILDON_URI_DBUS_FAILED,
                       str);
      }

      return ok;
}


Generated by  Doxygen 1.6.0   Back to index