Hi,
I tried a quick testing program but it does not seems to work... Here it
finds the uri scheme "http" but g_app_info_get_default_for_uri_scheme()
returns NULL.
I attached my test program, could you please tell me what's wrong? If I get
it working I'll make a patch to introduce g_file_get_default_handler().
Thanks,
Xavier Claessens.
2007/11/16, Alexander Larsson <[EMAIL PROTECTED]>:
>
>
> On Thu, 2007-11-15 at 16:25 +0100, Xavier Claessens wrote:
> > Hello,
> >
> > I'm trying to get ride of GnomeVFS dependency in Empathy. I'm looking
> > for a replacement of gnome_vfs_open_url(), is there an API in gio to do
> > the same thing?
>
> There is no simple call for it, but all the ingredients for it is there.
>
> Start by looking at:
>
> GAppInfo *g_app_info_get_default_for_uri_scheme (const char *uri_scheme);
>
> (uri scheme comes from g_file_get_uri_scheme())
>
> If that returns NULL, we must look at the file type, which is done with:
>
> g_file_query_info() or g_file_query_info_async()
>
> (passing G_FILE_ATTRIBUTE_STD_CONTENT_TYPE as attribute)
>
> Then you can get the default from:
>
> GAppInfo *g_app_info_get_default_for_type (const char *content_type,
> gboolean
> must_support_uris);
>
> Clearly these could all go into a helper function:
>
> GAppInfo *g_file_get_default_handler (GFile *file,
> GCancellable, *cancellable,
> GError **error)
>
> Patches accepted.
>
> Then you can launch the GAppInfo using g_app_info_launch().
>
> For certain features (startup notification, starting on right screen)
> you can also pass in a GAppLaunchContext implementation. This is a bit
> tricky atm, but in the future such an implementation will be availible
> in Gtk+ for simple use.
>
>
>
/* compile with: gcc open-url.c `pkg-config gio-2.0 --libs --cflags` */
#include <glib.h>
#include <gio/gappinfo.h>
#include <gio/gfile.h>
int
main (int argc, char *argv[])
{
GAppInfo *app_info = NULL;
GFile *file;
gchar *uri_scheme;
GList *files;
g_type_init ();
file = g_file_new_for_uri ("http://google.be");
uri_scheme = g_file_get_uri_scheme (file);
if (uri_scheme) {
g_print ("Found uri scheme: %s\n", uri_scheme);
app_info = g_app_info_get_default_for_uri_scheme (uri_scheme);
g_free (uri_scheme);
} else {
GFileInfo *info;
const gchar *content_type;
g_print ("Query information...\n");
info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STD_CONTENT_TYPE,
0, NULL, NULL);
if (info) {
content_type = g_file_info_get_content_type (info);
g_print ("Found content type: %s\n", content_type);
app_info = g_app_info_get_default_for_type (content_type, FALSE);
g_object_unref (info);
}
}
if (app_info) {
g_print ("launching...\n");
files = g_list_prepend (NULL, file);
g_app_info_launch (app_info, files, NULL, NULL);
g_list_free (files);
g_object_unref (app_info);
}
g_object_unref (file);
}
_______________________________________________
gnome-vfs-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gnome-vfs-list