~ubuntu-branches/ubuntu/quantal/libfm/quantal

« back to all changes in this revision

Viewing changes to src/gio/fm-app-lookup.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2011-02-21 21:55:43 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20110221215543-m7gn2snkhpk1kk9u
Tags: 0.1.15+git-3625952cea-0ubuntu1
* New upstream snapshot (2011-02-15)
 - Use x-schemas-handler (LP: #683922)
* debian/patches/
 - 90_add_gobject_link.patch: Remove, merged upstream.
 - 02-libfm-0.1.14-API-changes.patch: Refresh.
 - 03_disable_deprecated_gio_module.patch: Refresh.
 - 04_fix_docs_linker.patch: Fix DSO linking in docs/.
* debian/libfm0.install:
 - Remove usr/lib/libfm/gnome-terminal, dropped upstream.
 - Remove gio module, dropped upstream.
* debian/rules:
 - Add --enable-gtk-doc to configure.
* debian/libfm-gtk0.symbols:
 - Update with new symbols.
* debian/apport/source_libfm.py
 - Fix location of pcmanfm config files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
static void app_lookup_iface_init(GDesktopAppInfoLookupIface *iface);
39
39
static GObject* fm_app_lookup_constructor(GType type, guint n_props, GObjectConstructParam *props);
40
 
static void fm_app_lookup_finalize                      (GObject *object);
 
40
static void fm_app_lookup_finalize              (GObject *object);
41
41
static GAppInfo *get_default_for_uri_scheme(GDesktopAppInfoLookup *lookup, const char *scheme);
42
42
 
43
43
G_DEFINE_DYNAMIC_TYPE_EXTENDED(FmAppLookup, fm_app_lookup, G_TYPE_OBJECT, 0,
46
46
 
47
47
static void fm_app_lookup_class_init(FmAppLookupClass *klass)
48
48
{
49
 
        GObjectClass *g_object_class;
50
 
        g_object_class = G_OBJECT_CLASS(klass);
 
49
    GObjectClass *g_object_class;
 
50
    g_object_class = G_OBJECT_CLASS(klass);
51
51
    g_object_class->constructor = fm_app_lookup_constructor;
52
 
        g_object_class->finalize = fm_app_lookup_finalize;
 
52
    g_object_class->finalize = fm_app_lookup_finalize;
53
53
}
54
54
 
55
55
static void fm_app_lookup_class_finalize(FmAppLookupClass *klass)
66
66
 
67
67
static void fm_app_lookup_finalize(GObject *object)
68
68
{
69
 
        FmAppLookup *self;
70
 
 
71
 
        g_return_if_fail(object != NULL);
72
 
        g_return_if_fail(FM_IS_APP_LOOKUP(object));
73
 
 
74
 
        self = FM_APP_LOOKUP(object);
75
 
        G_OBJECT_CLASS(fm_app_lookup_parent_class)->finalize(object);
 
69
    FmAppLookup *self;
 
70
 
 
71
    g_return_if_fail(object != NULL);
 
72
    g_return_if_fail(FM_IS_APP_LOOKUP(object));
 
73
 
 
74
    self = FM_APP_LOOKUP(object);
 
75
    G_OBJECT_CLASS(fm_app_lookup_parent_class)->finalize(object);
76
76
}
77
77
 
78
78
 
108
108
GAppInfo *get_default_for_uri_scheme(GDesktopAppInfoLookup *lookup, const char *scheme)
109
109
{
110
110
    GAppInfo* app;
111
 
    GKeyFile* kf;
112
 
    const char* key;
113
 
    char* fname;
114
 
    char* desktop_id = NULL;
115
 
 
116
 
    /* web browser */
117
 
    if(g_ascii_strcasecmp(scheme, "http")==0 || g_ascii_strcasecmp(scheme, "https")==0)
118
 
        key = "WebBrowser";
119
 
    else if(g_ascii_strcasecmp(scheme, "mailto")==0)
120
 
        key = "MailClient";
121
 
    else /* we don't know this */
122
 
        return NULL;
123
 
 
124
 
    kf = g_key_file_new();
125
 
 
126
 
    /* try user config first */
127
 
    fname = g_build_filename(g_get_user_config_dir(), "libfm/pref-apps.conf", NULL);
128
 
    if(g_key_file_load_from_file(kf, fname, 0, NULL))
129
 
    {
130
 
        desktop_id = g_key_file_get_string(kf, "Preferred Applications", key, NULL);
131
 
        if(desktop_id && !*desktop_id)
132
 
        {
133
 
            g_free(desktop_id);
134
 
            desktop_id = NULL;
135
 
        }
136
 
    }
137
 
    g_free(fname);
138
 
 
139
 
    if(!desktop_id) /* system-wide */
140
 
    {
141
 
        const gchar* const *dirs = g_get_system_config_dirs();
142
 
        int i, n;
143
 
        if(g_key_file_load_from_file(kf, fname, 0, NULL))
144
 
            desktop_id = g_key_file_get_string(kf, "Preferred Applications", key, NULL);
145
 
        n = g_strv_length(dirs);
146
 
        for( i = n - 1; i > 0; --i )
147
 
        {
148
 
            fname = g_build_filename(dirs[i], "libfm/pref-apps.conf", NULL);
149
 
            if( g_key_file_load_from_file(kf, fname, 0, NULL) )
150
 
                desktop_id = g_key_file_get_string(kf, "Preferred Applications", key, NULL);
151
 
            g_free(fname);
152
 
            if(desktop_id)
153
 
            {
154
 
                if(*desktop_id)
155
 
                    break;
156
 
                else
157
 
                {
158
 
                    g_free(desktop_id);
159
 
                    desktop_id = NULL;
160
 
                }
161
 
            }
162
 
        }
163
 
    }
164
 
 
165
 
    g_key_file_free(kf);
166
 
 
167
 
    if(!desktop_id)
168
 
        return NULL;
169
 
 
170
 
    app = g_desktop_app_info_new(desktop_id);
171
 
 
172
 
    g_free(desktop_id);
173
 
 
 
111
    /* use a way compatible with glib >= 2.27 */
 
112
    char* mime_type = g_strconcat("x-scheme-handler/", scheme, NULL);
 
113
    app = g_app_info_get_default_for_type(mime_type, FALSE);
 
114
    g_free(mime_type);
174
115
    return app;
175
116
}