Beispiel #1
0
gboolean fm_launch_desktop_entry(GAppLaunchContext* ctx, const char* file_or_id, GList* uris, GError** err)
{
    GKeyFile* kf = g_key_file_new();
    gboolean loaded;
    gboolean ret = FALSE;

    if(g_path_is_absolute(file_or_id))
        loaded = g_key_file_load_from_file(kf, file_or_id, 0, err);
    else
    {
        char* tmp = g_strconcat("applications/", file_or_id, NULL);
        loaded = g_key_file_load_from_data_dirs(kf, tmp, NULL, 0, err);
        g_free(tmp);
    }

    if(loaded)
    {
        GList* _uris = NULL;
        GAppInfo* app = NULL;
        char* type = g_key_file_get_string(kf, G_KEY_FILE_DESKTOP_GROUP, "Type", NULL);
        if(type)
        {
            if(strcmp(type, "Application") == 0)
                app = g_desktop_app_info_new_from_keyfile(kf);
            else if(strcmp(type, "Link") == 0)
            {
                char* url = g_key_file_get_string(kf, G_KEY_FILE_DESKTOP_GROUP, "URL", NULL);
                if(url)
                {
                    char* scheme = g_uri_parse_scheme(url);
                    if(scheme)
                    {
                        /* Damn! this actually relies on gconf to work. */
                        /* FIXME: use our own way to get a usable browser later. */
                        app = g_app_info_get_default_for_uri_scheme(scheme);
                        uris = _uris = g_list_prepend(NULL, url);
                        g_free(scheme);
                    }
                }
            }
            else if(strcmp(type, "Directory") == 0)
            {
                /* FIXME: how should this work? It's not defined in the spec. */
            }
            if(app)
                ret = g_app_info_launch_uris(app, uris, ctx, err);
        }
    }
    g_key_file_free(kf);

    return ret;
}
Beispiel #2
0
static gboolean
init_mailer (NautilusSendto *nst)
{
	GAppInfo *app_info;
	char *needle;

	nst->type = MAILER_UNKNOWN;

	app_info = g_app_info_get_default_for_uri_scheme ("mailto");
	if (app_info) {
		nst->mail_cmd = g_strdup (g_app_info_get_commandline (app_info));
		g_object_unref (app_info);
	} else {
		nst->mail_cmd = NULL;
	}

	if (nst->mail_cmd == NULL || *nst->mail_cmd == '\0') {
		g_free (nst->mail_cmd);
		nst->mail_cmd = get_evo_cmd ();
		nst->type = MAILER_EVO;
	} else {
		/* Find what the default mailer is */
		if (strstr (nst->mail_cmd, "balsa"))
			nst->type = MAILER_BALSA;
		else if (strstr (nst->mail_cmd, "thunder") || strstr (nst->mail_cmd, "seamonkey") || strstr (nst->mail_cmd, "icedove")) {
			char **strv;

			nst->type = MAILER_THUNDERBIRD;

			/* Thunderbird sucks, see
			 * https://bugzilla.gnome.org/show_bug.cgi?id=614222 */
			strv = g_strsplit (nst->mail_cmd, " ", -1);
			g_free (nst->mail_cmd);
			nst->mail_cmd = g_strdup_printf ("%s %%s", strv[0]);
			g_strfreev (strv);
		} else if (strstr (nst->mail_cmd, "sylpheed") || strstr (nst->mail_cmd, "claws"))
			nst->type = MAILER_SYLPHEED;
		else if (strstr (nst->mail_cmd, "anjal"))
			nst->type = MAILER_EVO;
	}

	if (nst->mail_cmd == NULL)
		return FALSE;

	/* Replace %U by %s */
	while ((needle = g_strrstr (nst->mail_cmd, "%U")) != NULL)
		needle[1] = 's';
	while ((needle = g_strrstr (nst->mail_cmd, "%u")) != NULL)
		needle[1] = 's';

	return TRUE;
}
Beispiel #3
0
static gboolean
check_available_mailer ()
{
	GAppInfo *app_info;

	app_info = g_app_info_get_default_for_uri_scheme ("mailto");
	if (app_info) {
		g_clear_object (&app_info);
		return TRUE;
	}
	else
		return FALSE;
}
Beispiel #4
0
static gboolean
eab_contact_formatter_scheme_supported (const gchar *scheme)
{
	GAppInfo *app_info;
	gboolean supported;

	app_info = g_app_info_get_default_for_uri_scheme (scheme);
	supported = app_info != NULL;

	if (app_info && g_app_info_can_delete (app_info))
		g_app_info_delete (app_info);

	return supported;
}
// used in nsGNOMERegistry
// -----------------------------------------------------------------------------
NS_IMETHODIMP
nsGIOService::GetAppForURIScheme(const nsACString& aURIScheme,
                                 nsIGIOMimeApp** aApp)
{
  *aApp = nsnull;

  GAppInfo *app_info = g_app_info_get_default_for_uri_scheme(
                          PromiseFlatCString(aURIScheme).get());
  if (app_info) {
    nsGIOMimeApp *mozApp = new nsGIOMimeApp(app_info);
    NS_ADDREF(*aApp = mozApp);
  } else {
    return NS_ERROR_FAILURE;
  }
  return NS_OK;
}
static void
help_contents_action (GtkAction *action,
                      gpointer   user_data)
{
	GPInstructServerWindow *window = GPINSTRUCT_SERVER_WINDOW (user_data);

	GAppInfo *app_info;
	gchar *uri;

	app_info = g_app_info_get_default_for_uri_scheme ("help");

#ifdef G_OS_WIN32
        gchar *prefix = g_win32_get_package_installation_directory_of_module (NULL);
	gchar *index_filename = g_build_filename (prefix, "share", "help", "C", PACKAGE, "index.html", NULL);
#else
	gchar *index_filename = g_build_filename (PACKAGE_PREFIX, "share", "help", "C", PACKAGE, "index.html", NULL);
#endif

	if (app_info)
	{
		uri = g_strdup ("help:" PACKAGE);
	}
	else if (g_file_test (index_filename, G_FILE_TEST_IS_REGULAR))
	{
		uri = g_filename_to_uri (index_filename, NULL, NULL);
	}
	else
	{
		uri = g_strdup (PACKAGE_URL);
	}

	gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (window)),
	              uri,
	              GDK_CURRENT_TIME,
	              NULL);

	g_free (uri);
	g_free (index_filename);

	if (app_info)
		g_object_unref (app_info);

#ifdef G_OS_WIN32
	g_free (prefix);
#endif
}
Beispiel #7
0
/**
 * g_app_info_launch_default_for_uri:
 * @uri: the uri to show
 * @launch_context: (allow-none): an optional #GAppLaunchContext.
 * @error: a #GError.
 *
 * Utility function that launches the default application
 * registered to handle the specified uri. Synchronous I/O
 * is done on the uri to detect the type of the file if
 * required.
 * 
 * Returns: %TRUE on success, %FALSE on error.
 **/
gboolean
g_app_info_launch_default_for_uri (const char         *uri,
				   GAppLaunchContext  *launch_context,
				   GError            **error)
{
  char *uri_scheme;
  GAppInfo *app_info = NULL;
  GList l;
  gboolean res;

  /* g_file_query_default_handler() calls
   * g_app_info_get_default_for_uri_scheme() too, but we have to do it
   * here anyway in case GFile can't parse @uri correctly.
   */
  uri_scheme = g_uri_parse_scheme (uri);
  if (uri_scheme && uri_scheme[0] != '\0')
    app_info = g_app_info_get_default_for_uri_scheme (uri_scheme);
  g_free (uri_scheme);

  if (!app_info)
    {
      GFile *file;

      file = g_file_new_for_uri (uri);
      app_info = g_file_query_default_handler (file, NULL, error);
      g_object_unref (file);
      if (app_info == NULL)
	return FALSE;

      /* We still use the original @uri rather than calling
       * g_file_get_uri(), because GFile might have modified the URI
       * in ways we don't want (eg, removing the fragment identifier
       * from a file: URI).
       */
    }

  l.data = (char *)uri;
  l.next = l.prev = NULL;
  res = g_app_info_launch_uris (app_info, &l,
				launch_context, error);

  g_object_unref (app_info);
  
  return res;
}
static struct default_db_t *
get_default_helper (const gchar * desktop_path)
{
    g_return_val_if_fail(desktop_path != NULL, NULL);
    gchar * basename = g_path_get_basename(desktop_path);
    g_return_val_if_fail(basename != NULL, NULL);

    gboolean found = FALSE;
    gint i;
    gint length = G_N_ELEMENTS(default_db);
    for (i = 0; i < length && !found; i++) {
        if (default_db[i].desktop_file) {
            if (g_strcmp0(default_db[i].desktop_file, basename) == 0) {
                found = TRUE;
            }
        } else if (default_db[i].uri_scheme) {
            GAppInfo *info = g_app_info_get_default_for_uri_scheme(default_db[i].uri_scheme);
            if (!info) {
                continue;
            }

            const gchar * filename = g_desktop_app_info_get_filename(G_DESKTOP_APP_INFO(info));
            if (!filename) {
                g_object_unref(info);
                continue;
            }

            gchar * default_basename = g_path_get_basename(filename);
            g_object_unref(info);
            if (g_strcmp0(default_basename, basename) == 0) {
                found = TRUE;
            }

            g_free(default_basename);
        }
    }

    g_free(basename);

    if (found) {
        return &default_db[i - 1];
    }

    return NULL;
}
Beispiel #9
0
GAppInfo*
sokoke_default_for_uri (const gchar* uri,
                        gchar**      scheme_ptr)
{
    gchar* scheme;
    GAppInfo* info;

    scheme = g_uri_parse_scheme (uri);
    if (!scheme)
        return NULL;

    info = g_app_info_get_default_for_uri_scheme (scheme);
    if (scheme_ptr != NULL)
        *scheme_ptr = scheme;
    else
        g_free (scheme);
    return info;

}
Beispiel #10
0
static VALUE
appinfo_get_default_for_uri_scheme(G_GNUC_UNUSED VALUE self, VALUE uri_scheme)
{
        return GOBJ2RVAL_UNREF(g_app_info_get_default_for_uri_scheme(RVAL2CSTR(uri_scheme)));
}
Beispiel #11
0
/**
 * fm_launch_files
 * @ctx: (allow-none): a launch context
 * @file_infos: (element-type FmFileInfo): files to launch
 * @launcher: #FmFileLauncher with callbacks
 * @user_data: data supplied for callbacks
 *
 * Launches files using callbacks in @launcher.
 *
 * Returns: %TRUE in case of success.
 *
 * Since: 0.1.0
 */
gboolean fm_launch_files(GAppLaunchContext* ctx, GList* file_infos, FmFileLauncher* launcher, gpointer user_data)
{
    GList* l;
    GHashTable* hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
    GList *folders = NULL;
    FmFileInfo* fi;
    GList *targets = NULL;
    GError* err = NULL;
    GAppInfo* app;
    const char* type;

    for(l = file_infos; l; l=l->next)
    {
        GList* fis;
        char *filename, *scheme;
        const char *target = NULL;

        fi = (FmFileInfo*)l->data;
        /* special handling for shortcuts */
        if (!fm_file_info_is_symlink(fi))
            /* symlinks also has fi->target, but we only handle shortcuts here. */
            target = fm_file_info_get_target(fi);
        if (launcher->open_folder && fm_file_info_is_dir(fi))
        {
            /* special handling for shortcuts */
            if(target)
            {
                fi = _fetch_file_info_for_shortcut(fm_file_info_get_target(fi),
                                                   ctx, launcher, user_data);
                if (fi == NULL)
                    /* error was shown by job already */
                    continue;
                targets = g_list_prepend(targets, fi);
            }
            folders = g_list_prepend(folders, fi);
        }
        else if (fm_file_info_is_desktop_entry(fi))
        {
_launch_desktop_entry:
            if (!target)
                filename = fm_path_to_str(fm_file_info_get_path(fi));
            fm_launch_desktop_entry(ctx, target ? target : filename, NULL,
                                    launcher, user_data);
            if (!target)
                g_free(filename);
            continue;
        }
        else
        {
            FmPath* path = fm_file_info_get_path(fi);
            FmMimeType* mime_type = NULL;
            if(fm_path_is_native(path))
            {
                /* special handling for shortcuts */
                if (target)
                {
                    if (fm_file_info_get_mime_type(fi) == _fm_mime_type_get_inode_x_shortcut())
                    /* if we already know MIME type then use it instead */
                    {
                      scheme = g_uri_parse_scheme(target);
                      if (scheme)
                      {
                        /* FIXME: this is rough! */
                        if (strcmp(scheme, "file") != 0 &&
                            strcmp(scheme, "trash") != 0 &&
                            strcmp(scheme, "network") != 0 &&
                            strcmp(scheme, "computer") != 0 &&
                            strcmp(scheme, "menu") != 0)
                        {
                            /* we don't support this URI internally, try GIO */
                            app = g_app_info_get_default_for_uri_scheme(scheme);
                            if (app)
                            {
                                fis = g_list_prepend(NULL, (char *)target);
                                fm_app_info_launch_uris(app, fis, ctx, &err);
                                g_list_free(fis);
                                g_object_unref(app);
                            }
                            else if (launcher->error)
                                g_set_error(&err, G_IO_ERROR, G_IO_ERROR_FAILED,
                                            _("No default application is set to launch URIs %s://"),
                                            scheme);
                            if (err)
                            {
                                launcher->error(ctx, err, NULL, user_data);
                                g_clear_error(&err);
                            }
                            g_free(scheme);
                            continue;
                        }
                        g_free(scheme);
                      }
                    }
                    else
                        mime_type = fm_file_info_get_mime_type(fi);
                    /* retrieve file info for target otherwise and handle it */
                    fi = _fetch_file_info_for_shortcut(target, ctx, launcher, user_data);
                    if (fi == NULL)
                        /* error was shown by job already */
                        continue;
                    targets = g_list_prepend(targets, fi);
                    path = fm_file_info_get_path(fi);
                    /* special handling for desktop entries */
                    if (fm_file_info_is_desktop_entry(fi))
                        goto _launch_desktop_entry;
                }
                if(fm_file_info_is_executable_type(fi))
                {
                    /* if it's an executable file, directly execute it. */
                    filename = fm_path_to_str(path);

                    /* FIXME: we need to use eaccess/euidaccess here. */
                    if(g_file_test(filename, G_FILE_TEST_IS_EXECUTABLE))
                    {
                        if(launcher->exec_file)
                        {
                            FmFileLauncherExecAction act = launcher->exec_file(fi, user_data);
                            GAppInfoCreateFlags flags = 0;
                            switch(act)
                            {
                            case FM_FILE_LAUNCHER_EXEC_IN_TERMINAL:
                                flags |= G_APP_INFO_CREATE_NEEDS_TERMINAL;
                                /* NOTE: no break here */
                            case FM_FILE_LAUNCHER_EXEC:
                            {
                                /* filename may contain spaces. Fix #3143296 */
                                char* quoted = g_shell_quote(filename);
                                app = fm_app_info_create_from_commandline(quoted, NULL, flags, NULL);
                                g_free(quoted);
                                if(app)
                                {
                                    char* run_path = g_path_get_dirname(filename);
                                    char* cwd = NULL;
                                    /* bug #3589641: scripts are ran from $HOME.
                                       since GIO launcher is kinda ugly - it has
                                       no means to set running directory so we
                                       do workaround - change directory to it */
                                    if(run_path && strcmp(run_path, "."))
                                    {
                                        cwd = g_get_current_dir();
                                        if(chdir(run_path) != 0)
                                        {
                                            g_free(cwd);
                                            cwd = NULL;
                                            if (launcher->error)
                                            {
                                                g_set_error(&err, G_IO_ERROR,
                                                            g_io_error_from_errno(errno),
                                                            _("Cannot set working directory to '%s': %s"),
                                                            run_path, g_strerror(errno));
                                                launcher->error(ctx, err, NULL, user_data);
                                                g_clear_error(&err);
                                            }
                                        }
                                    }
                                    g_free(run_path);
                                    if(!fm_app_info_launch(app, NULL, ctx, &err))
                                    {
                                        if(launcher->error)
                                            launcher->error(ctx, err, NULL, user_data);
                                        g_error_free(err);
                                        err = NULL;
                                    }
                                    if(cwd) /* return back */
                                    {
                                        if(chdir(cwd) != 0)
                                            g_warning("fm_launch_files(): chdir() failed");
                                        g_free(cwd);
                                    }
                                    g_object_unref(app);
                                    continue;
                                }
                                break;
                            }
                            case FM_FILE_LAUNCHER_EXEC_OPEN:
                                break;
                            case FM_FILE_LAUNCHER_EXEC_CANCEL:
                                continue;
                            }
                        }
                    }
                    g_free(filename);
                }
            }
            if (mime_type == NULL)
                mime_type = fm_file_info_get_mime_type(fi);
            if(mime_type && (type = fm_mime_type_get_type(mime_type)))
            {
                fis = g_hash_table_lookup(hash, type);
                fis = g_list_prepend(fis, fi);
                g_hash_table_insert(hash, (gpointer)type, fis);
            }
            else if (launcher->error)
            {
                g_set_error(&err, G_IO_ERROR, G_IO_ERROR_FAILED,
                            _("Could not determine content type of file '%s' to launch it"),
                            fm_file_info_get_disp_name(fi));
                launcher->error(ctx, err, NULL, user_data);
                g_clear_error(&err);
            }
        }
    }

    if(g_hash_table_size(hash) > 0)
    {
        GHashTableIter it;
        GList* fis;
        g_hash_table_iter_init(&it, hash);
        while(g_hash_table_iter_next(&it, (void**)&type, (void**)&fis))
        {
            GAppInfo* app = g_app_info_get_default_for_type(type, FALSE);
            if(!app)
            {
                if(launcher->get_app)
                {
                    FmMimeType* mime_type = fm_file_info_get_mime_type((FmFileInfo*)fis->data);
                    app = launcher->get_app(fis, mime_type, user_data, NULL);
                }
            }
            if(app)
            {
                for(l=fis; l; l=l->next)
                {
                    char* uri;
                    fi = (FmFileInfo*)l->data;
                    /* special handling for shortcuts */
                    if (fm_file_info_is_shortcut(fi))
                        uri = g_strdup(fm_file_info_get_target(fi));
                    else
                        uri = fm_path_to_uri(fm_file_info_get_path(fi));
                    l->data = uri;
                }
                fis = g_list_reverse(fis);
                fm_app_info_launch_uris(app, fis, ctx, &err);
                /* free URI strings */
                g_list_foreach(fis, (GFunc)g_free, NULL);
                g_object_unref(app);
            }
            else if (launcher->error)
                g_set_error(&err, G_IO_ERROR, G_IO_ERROR_FAILED,
                            _("No default application is set for MIME type %s"),
                            type);
            if (err)
            {
                launcher->error(ctx, err, NULL, user_data);
                g_clear_error(&err);
            }
            g_list_free(fis);
        }
    }
    g_hash_table_destroy(hash);

    if(folders)
    {
        folders = g_list_reverse(folders);
        if(launcher->open_folder)
        {
            launcher->open_folder(ctx, folders, user_data, &err);
            if(err)
            {
                if(launcher->error)
                    launcher->error(ctx, err, NULL, user_data);
                g_error_free(err);
                err = NULL;
            }
        }
        g_list_free(folders);
    }
    g_list_free_full(targets, (GDestroyNotify)fm_file_info_unref);
    return TRUE;
}