~ubuntu-branches/ubuntu/karmic/file-browser-applet/karmic

« back to all changes in this revision

Viewing changes to src/vfs.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2009-04-11 17:15:39 UTC
  • mfrom: (1.1.4 upstream) (2.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090411171539-jk4kgkvm4i39nv3c
Tags: 0.6.2-1
* New upstream release. (Closes: #504525)
 - Added context menu with a few actions (open-with, new folder here, 
   delete file/folder, create/extract archive, create CD/DVD from 
   file/folder, compile a tex file).
 - Added configuration option to make text vertical/horizontal when 
   the panel is vertical.
 - Added tooltips to configuration dialog.
 - Fixes upstream bugs #21, #30, #34, #37, #39, #43, #44, #45, #49, 
   #51, #56, #59, #60, and #62.
 - Added mnemonic keyboard shortcut to menus for 
   faster keyboard navigation.
 - Added recent documents' support.
 - Improved menu browser focus after context menu close.
 - Added preliminary DnD dragging out of applet. MOVE is the default 
   behaviour.
 - Some code cleanups and plugged memory leaks.
 - Slightly improved "New Folder" dialog.
 - Migrated to gtk+ builder from libglade.
* debian/control:
 - Add suggests on file-roller, brasero, and rubber 
   for new features.
 - Add Vcs-Bzr field.
 - Drop depricated libglade2-dev Build-Depend
 - Drop unneeded libpanel-applet2-0 Depend. Already picked up by 
   shlibs:Depends.
 - Add versionized Build-Depend on libgtk2.0-dev (>= 2.14)
 - Bump Standards-Version to 3.8.1
* debian/copyright:
 - Use /usr/share/common-licenses/GPL-2 rather than just GLP.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * File:                                vfs.c
3
 
 * Created:                             August 2008
4
 
 * Created by:                  Axel von Bertoldi
5
 
 * Last Modified:               March 2008
6
 
 * Last Modified by:    Axel von Bertoldi
7
 
 * (C) 2005-2008                Axel von Bertoldi
 
2
 * File:                vfs.c
 
3
 * Created:             August 2008
 
4
 * Created by:          Axel von Bertoldi
 
5
 * Last Modified:       March 2008
 
6
 * Last Modified by:    Axel von Bertoldi
 
7
 * (C) 2005-2008        Axel von Bertoldi
8
8
 *
9
9
 * This program is free software; you can redistribute it and/or modify it
10
10
 * under the terms of the GNU General Public License as published by the Free
36
36
/* sort the structures based on the file's display_name */
37
37
static inline gint
38
38
vfs_sort_array (const VfsFileInfo **i1, const VfsFileInfo **i2) {
39
 
        return g_utf8_collate ((gchar *)(*i1)->display_name, (gchar *)(*i2)->display_name);
 
39
    return g_utf8_collate ((gchar *)(*i1)->display_name, (gchar *)(*i2)->display_name);
40
40
}
41
41
/******************************************************************************/
42
42
gboolean
43
43
vfs_file_exists (const gchar *file_name) {
44
 
        return g_file_test (file_name, G_FILE_TEST_EXISTS);
 
44
    return g_file_test (file_name, G_FILE_TEST_EXISTS);
45
45
}
46
46
/******************************************************************************/
47
47
gboolean
48
48
vfs_file_is_executable (const gchar *file_name) {
49
 
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
50
 
 
51
 
        GFile*     file = g_file_new_for_path (file_name);
52
 
        GFileInfo* file_info =  g_file_query_info (file,
53
 
                                                                                           /*G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE ,*/
54
 
                                                                                           "standard::content-type,"
55
 
                                                                                           "access::can-execute",
56
 
                                                                                           0,
57
 
                                                                                           NULL,
58
 
                                                                                           NULL);
59
 
 
60
 
        gboolean ret = g_file_info_get_attribute_boolean (file_info,
61
 
                                                                                                          G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE) &&
62
 
                                                                                                          g_content_type_can_be_executable (g_file_info_get_content_type (file_info));
63
 
 
64
 
        g_object_unref (file_info);
65
 
        g_object_unref (file);
66
 
        return ret;     
 
49
    if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
 
50
 
 
51
    GFile*     file = g_file_new_for_path (file_name);
 
52
    GFileInfo* file_info =  g_file_query_info (file,
 
53
                                               /*G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE ,*/
 
54
                                               "standard::content-type,"
 
55
                                               "access::can-execute",
 
56
                                               0,
 
57
                                               NULL,
 
58
                                               NULL);
 
59
 
 
60
    gboolean ret = g_file_info_get_attribute_boolean (file_info,
 
61
                                                      G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE) &&
 
62
                                                      g_content_type_can_be_executable (g_file_info_get_content_type (file_info));
 
63
 
 
64
    g_object_unref (file_info);
 
65
    g_object_unref (file);
 
66
    return ret; 
67
67
}
68
68
/******************************************************************************/
69
69
gboolean
70
70
vfs_file_is_directory (const gchar *file_name) {
71
 
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
72
 
 
73
 
        GFile*     file = g_file_new_for_path (file_name);
74
 
        GFileInfo* file_info =  g_file_query_info (file,
75
 
                                                                                           G_FILE_ATTRIBUTE_STANDARD_TYPE,
76
 
                                                                                           0,
77
 
                                                                                           NULL,
78
 
                                                                                           NULL);
79
 
 
80
 
        gboolean ret = (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY);
81
 
        g_object_unref (file_info);
82
 
        g_object_unref (file);
83
 
        return ret;
 
71
    if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
 
72
 
 
73
    GFile*     file = g_file_new_for_path (file_name);
 
74
    GFileInfo* file_info =  g_file_query_info (file,
 
75
                                               G_FILE_ATTRIBUTE_STANDARD_TYPE,
 
76
                                               0,
 
77
                                               NULL,
 
78
                                               NULL);
 
79
 
 
80
    gboolean ret = (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY);
 
81
    g_object_unref (file_info);
 
82
    g_object_unref (file);
 
83
    return ret;
84
84
}
85
85
/******************************************************************************/
86
86
gboolean
87
87
vfs_file_is_desktop (const gchar *file_name) {
88
 
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
 
88
    if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
89
89
 
90
 
        GDesktopAppInfo *app_info = g_desktop_app_info_new_from_filename (file_name);
91
 
        gboolean ret = !(app_info == NULL);
92
 
        app_info ? g_object_unref (app_info) : NULL;
93
 
        return ret;
 
90
    GDesktopAppInfo *app_info = g_desktop_app_info_new_from_filename (file_name);
 
91
    gboolean ret = !(app_info == NULL);
 
92
    app_info ? g_object_unref (app_info) : NULL;
 
93
    return ret;
94
94
}
95
95
/******************************************************************************/
96
96
/* Gets the executable file name of the application associated  with the passed
97
97
 * file. The caller must free the returned value. */
98
98
gchar*
99
99
vfs_get_default_mime_application (const gchar *file_name) {
100
 
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
101
 
 
102
 
        GFile*     file = g_file_new_for_path (file_name);
103
 
        GFileInfo* file_info =  g_file_query_info (file,
104
 
                                                                                           G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
105
 
                                                                                           0,
106
 
                                                                                           NULL,                                                                                           
107
 
                                                                                           NULL);
108
 
 
109
 
        const gchar* content_type = g_file_info_get_content_type (file_info);
110
 
        GAppInfo *app_info = g_app_info_get_default_for_type (content_type, FALSE);
111
 
        gchar* exec = g_strdup (g_app_info_get_executable (app_info));
112
 
 
113
 
        g_object_unref (file_info);
114
 
        g_object_unref (file);
115
 
        g_object_unref (app_info);
116
 
 
117
 
        return exec;
 
100
    if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
 
101
 
 
102
    GFile*     file = g_file_new_for_path (file_name);
 
103
    GFileInfo* file_info =  g_file_query_info (file,
 
104
                                               G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
 
105
                                               0,
 
106
                                               NULL,                                               
 
107
                                               NULL);
 
108
 
 
109
    const gchar* content_type = g_file_info_get_content_type (file_info);
 
110
    GAppInfo *app_info = g_app_info_get_default_for_type (content_type, FALSE);
 
111
    gchar* exec = g_strdup (g_app_info_get_executable (app_info));
 
112
 
 
113
    g_object_unref (file_info);
 
114
    g_object_unref (file);
 
115
    g_object_unref (app_info);
 
116
 
 
117
    return exec;
118
118
}
119
119
/******************************************************************************/
120
120
 /* The caller  must free the return value. */
121
121
static gchar *
122
122
vfs_get_desktop_app_name (const gchar *file_name) {
123
 
        GDesktopAppInfo *info = g_desktop_app_info_new_from_filename (file_name);
124
 
        gchar* ret = g_strdup (g_app_info_get_name (G_APP_INFO (info)));
125
 
        g_object_unref (info);
126
 
        return ret;
 
123
    GDesktopAppInfo *info = g_desktop_app_info_new_from_filename (file_name);
 
124
    gchar* ret = g_strdup (g_app_info_get_name (G_APP_INFO (info)));
 
125
    g_object_unref (info);
 
126
    return ret;
127
127
}
128
128
/******************************************************************************/
129
129
void
130
 
vfs_file_trash (gchar *file_name) {
131
 
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
132
 
 
133
 
        GError *error = NULL;
134
 
        GFile *file = g_file_new_for_path (file_name);
135
 
 
136
 
        /* Try moving it to the trash */
137
 
        g_file_trash (file, NULL, &error);
138
 
 
139
 
        /* Let the user know if we failed. */
140
 
        utils_gerror_ok (&error, TRUE);
141
 
        g_free (file_name);
 
130
vfs_file_trash (const gchar *file_name) {
 
131
    if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
 
132
 
 
133
    GError *error = NULL;
 
134
    GFile *file = g_file_new_for_path (file_name);
 
135
 
 
136
    /* Try moving it to the trash */
 
137
    g_file_trash (file, NULL, &error);
 
138
 
 
139
    /* Let the user know if we failed. */
 
140
    utils_gerror_ok (&error, TRUE);
142
141
}
143
142
/******************************************************************************/
144
143
GtkWidget *
145
144
vfs_get_icon_for_file (const gchar *file_name) {
146
145
 
147
 
        GtkWidget *icon_widget = NULL;
148
 
        GDesktopAppInfo *app_info = g_desktop_app_info_new_from_filename (file_name);
149
 
 
150
 
        if (app_info != NULL) {
151
 
                GIcon *icon = g_app_info_get_icon (G_APP_INFO (app_info));
152
 
                icon_widget = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
153
 
                g_object_unref (app_info);
154
 
        }
155
 
        else {
156
 
                GFile *file = g_file_new_for_path (file_name);
157
 
                GFileInfo *file_info = g_file_query_info (file,
158
 
                                                                                          G_FILE_ATTRIBUTE_STANDARD_ICON,
159
 
                                                                                          0,
160
 
                                                                                          NULL,
161
 
                                                                                          NULL);        
162
 
 
163
 
                GIcon *icon = g_file_info_get_icon (file_info);
164
 
                icon_widget = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
165
 
                g_object_unref (file);
166
 
                g_object_unref (file_info);
167
 
        }
168
 
        return icon_widget;
 
146
    GtkWidget *icon_widget = NULL;
 
147
    GDesktopAppInfo *app_info = g_desktop_app_info_new_from_filename (file_name);
 
148
 
 
149
    if (app_info != NULL) {
 
150
        GIcon *icon = g_app_info_get_icon (G_APP_INFO (app_info));
 
151
        icon_widget = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
 
152
        g_object_unref (app_info);
 
153
    }
 
154
    else {
 
155
        GFile *file = g_file_new_for_path (file_name);
 
156
        GFileInfo *file_info = g_file_query_info (file,
 
157
                                              G_FILE_ATTRIBUTE_STANDARD_ICON,
 
158
                                              0,
 
159
                                              NULL,
 
160
                                              NULL);    
 
161
 
 
162
        GIcon *icon = g_file_info_get_icon (file_info);
 
163
        icon_widget = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
 
164
        g_object_unref (file);
 
165
        g_object_unref (file_info);
 
166
    }
 
167
    return icon_widget;
169
168
}
170
169
/******************************************************************************/
171
170
GList*
172
171
vfs_get_all_mime_applications (const gchar *file_name) {
173
 
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
174
 
 
175
 
        GFile*     file = g_file_new_for_path (file_name);
176
 
        GFileInfo* file_info =  g_file_query_info (file,
177
 
                                                                                           G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
178
 
                                                                                           0,
179
 
                                                                                           NULL,
180
 
                                                                                           NULL);
181
 
 
182
 
        const gchar* content_type = g_file_info_get_content_type (file_info);
183
 
        GList *app_infos = g_app_info_get_all_for_type (content_type);
184
 
        
185
 
        g_object_unref (file_info);
186
 
        g_object_unref (file);
187
 
 
188
 
        return app_infos;
 
172
    if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
 
173
 
 
174
    GFile*     file = g_file_new_for_path (file_name);
 
175
    GFileInfo* file_info =  g_file_query_info (file,
 
176
                                               G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
 
177
                                               0,
 
178
                                               NULL,
 
179
                                               NULL);
 
180
 
 
181
    const gchar* content_type = g_file_info_get_content_type (file_info);
 
182
    GList *app_infos = g_app_info_get_all_for_type (content_type);
 
183
    
 
184
    g_object_unref (file_info);
 
185
    g_object_unref (file);
 
186
 
 
187
    return app_infos;
189
188
}
190
189
/******************************************************************************/
191
190
/* Takes a null-terminated array of strings at least 2 items long. The first
196
195
gboolean
197
196
vfs_launch_application (const gchar *const *args) {
198
197
 
199
 
        /* Can't have both arg[ARG_APP] and args[ARG_FILE} NULL */
200
 
        g_return_val_if_fail ((args[ARG_APP] != NULL || args[ARG_FILE] != NULL), FALSE);
201
 
 
202
 
        guint    i;
203
 
        gboolean ret       = FALSE;
204
 
        GError   *error    = NULL;
205
 
        GList    *files    = NULL;
206
 
        gchar    *command_line = NULL;
207
 
 
208
 
        /* Put the file(s) in a list (only of there is a file) for g_app_info_launch() */
209
 
        for (i = ARG_FILE; args[i]; i++) {
210
 
                files = g_list_append (files, (gpointer)g_file_new_for_path (args[i]));
211
 
        }
 
198
    /* Can't have both arg[ARG_APP] and args[ARG_FILE} NULL */
 
199
    g_return_val_if_fail ((args[ARG_APP] != NULL || args[ARG_FILE] != NULL), FALSE);
 
200
 
 
201
    guint    i;
 
202
    gboolean ret       = FALSE;
 
203
    GError   *error    = NULL;
 
204
    GList    *files    = NULL;
 
205
    gchar    *command_line = NULL;
 
206
 
 
207
    /* Put the file(s) in a list (only of there is a file) for g_app_info_launch() */
 
208
    for (i = ARG_FILE; args[i]; i++) {
 
209
        files = g_list_append (files, (gpointer)g_file_new_for_path (args[i]));
 
210
    }
212
211
 
213
212
    gchar *uri = args[ARG_FILE] ? g_filename_to_uri(args[ARG_FILE], NULL, NULL) : g_filename_to_uri(args[ARG_APP], NULL, NULL);
214
213
    GtkRecentManager *recent = gtk_recent_manager_new ();
216
215
    g_object_unref (G_OBJECT(recent));
217
216
    g_free (uri);
218
217
 
219
 
        /* Set the current working dir. Do we use ARG_APP or ARG_FILE to set
220
 
         * cwd?  If ARG_FILE == NULL, use ARG_APP, otherwise use ARG_FILE */
221
 
        const gchar *cwd_root = args[ARG_FILE] == NULL ? args[ARG_APP] : args[ARG_FILE];
222
 
        gchar *working_dir = vfs_file_is_directory (cwd_root) ? g_strdup (cwd_root) : g_path_get_dirname (cwd_root);
223
 
        g_chdir (working_dir);
224
 
        g_free (working_dir);
225
 
 
226
 
        /* No agrs[ARG_APP] was NULL, open file with default mime handler */
227
 
        if (args[ARG_APP] == NULL) {
228
 
                GFile *file = g_file_new_for_path (args[ARG_FILE]);
229
 
                gchar *uri = g_file_get_uri (file);
230
 
                ret = g_app_info_launch_default_for_uri (uri, NULL, &error);
231
 
                utils_gerror_ok (&error, TRUE);
232
 
                g_free (uri);
233
 
                g_object_unref (file);
234
 
        }
235
 
        else {
236
 
                GAppInfo *app_info = NULL;
237
 
                if (vfs_file_is_desktop (args[ARG_APP])) {
238
 
                        app_info = G_APP_INFO (g_desktop_app_info_new_from_filename (args[ARG_APP]));
239
 
                }
240
 
                else {
241
 
                        command_line = vfs_file_is_executable (args[ARG_APP]) ?
242
 
                                utils_escape_str (args[ARG_APP], " ", "\\ ") : g_strdup (args[ARG_APP]);
243
 
                        app_info = g_app_info_create_from_commandline (command_line, NULL, 0, &error);
244
 
                        utils_gerror_ok (&error, TRUE);
245
 
                }
246
 
 
247
 
                if (app_info) {
248
 
                        ret = g_app_info_launch (app_info, files, NULL, &error);
249
 
                        utils_gerror_ok (&error, TRUE);
250
 
                        g_object_unref (app_info);
251
 
                }
252
 
                else {
253
 
                        gchar *msg = g_strdup_printf (_("Could not open \"%s\".\n"), args[ARG_FILE]);
254
 
                        utils_show_dialog (_("Error"), msg, GTK_MESSAGE_ERROR);
255
 
                        g_free (msg);
256
 
                }
257
 
        }
258
 
        g_list_foreach (files, (GFunc)g_object_unref, NULL);
259
 
        g_list_free (files);
260
 
        g_free (command_line);
261
 
 
262
 
        g_chdir (g_get_home_dir());
263
 
 
264
 
        return ret;
 
218
    /* Set the current working dir. Do we use ARG_APP or ARG_FILE to set
 
219
     * cwd?  If ARG_FILE == NULL, use ARG_APP, otherwise use ARG_FILE */
 
220
    const gchar *cwd_root = args[ARG_FILE] == NULL ? args[ARG_APP] : args[ARG_FILE];
 
221
    gchar *working_dir = vfs_file_is_directory (cwd_root) ? g_strdup (cwd_root) : g_path_get_dirname (cwd_root);
 
222
    g_chdir (working_dir);
 
223
    g_free (working_dir);
 
224
 
 
225
    /* No agrs[ARG_APP] was NULL, open file with default mime handler */
 
226
    if (args[ARG_APP] == NULL) {
 
227
        GFile *file = g_file_new_for_path (args[ARG_FILE]);
 
228
        gchar *uri = g_file_get_uri (file);
 
229
        ret = g_app_info_launch_default_for_uri (uri, NULL, &error);
 
230
        utils_gerror_ok (&error, TRUE);
 
231
        g_free (uri);
 
232
        g_object_unref (file);
 
233
    }
 
234
    else {
 
235
        GAppInfo *app_info = NULL;
 
236
        if (vfs_file_is_desktop (args[ARG_APP])) {
 
237
            app_info = G_APP_INFO (g_desktop_app_info_new_from_filename (args[ARG_APP]));
 
238
        }
 
239
        else {
 
240
            command_line = vfs_file_is_executable (args[ARG_APP]) ?
 
241
                utils_escape_str (args[ARG_APP], " ", "\\ ") : g_strdup (args[ARG_APP]);
 
242
            app_info = g_app_info_create_from_commandline (command_line, NULL, 0, &error);
 
243
            utils_gerror_ok (&error, TRUE);
 
244
        }
 
245
 
 
246
        if (app_info) {
 
247
            ret = g_app_info_launch (app_info, files, NULL, &error);
 
248
            utils_gerror_ok (&error, TRUE);
 
249
            g_object_unref (app_info);
 
250
        }
 
251
        else {
 
252
            gchar *msg = g_strdup_printf (_("Could not open \"%s\".\n"), args[ARG_FILE]);
 
253
            utils_show_dialog (_("Error"), msg, GTK_MESSAGE_ERROR);
 
254
            g_free (msg);
 
255
        }
 
256
    }
 
257
    g_list_foreach (files, (GFunc)g_object_unref, NULL);
 
258
    g_list_free (files);
 
259
    g_free (command_line);
 
260
 
 
261
    g_chdir (g_get_home_dir());
 
262
 
 
263
    return ret;
265
264
}
266
265
/******************************************************************************/
267
266
gboolean
268
267
vfs_file_do_default_action (const gchar *file_name) {
269
 
        gchar **args = g_strv_new (ARGS_SIZE);
270
 
        gchar *_file_name = g_strdup (file_name);
 
268
    gchar **args = g_strv_new (ARGS_SIZE);
 
269
    gchar *_file_name = g_strdup (file_name);
271
270
 
272
 
        if (vfs_file_is_desktop (_file_name) ||
273
 
                vfs_file_is_executable (_file_name)) {
274
 
                args[ARG_APP] = _file_name;
275
 
        }
276
 
        /* open it with the default mime app */
277
 
        else {
278
 
                args[ARG_FILE] = _file_name;
279
 
        }
280
 
        gboolean ret = vfs_launch_application ((const gchar*const*)args);
281
 
        g_strfreev (args);
282
 
        return ret;
 
271
    if (vfs_file_is_desktop (_file_name) ||
 
272
        vfs_file_is_executable (_file_name)) {
 
273
        args[ARG_APP] = _file_name;
 
274
    }
 
275
    /* open it with the default mime app */
 
276
    else {
 
277
        args[ARG_FILE] = _file_name;
 
278
    }
 
279
    gboolean ret = vfs_launch_application ((const gchar*const*)args);
 
280
    g_strfreev (args);
 
281
    return ret;
283
282
}
284
283
/******************************************************************************/
285
284
/* Gets the contents of a directory. Puts the files and directories in separate
286
285
 * arrays, and sorts them both. The caller must free the return value. */
287
286
gchar*
288
287
vfs_get_dir_listings (GPtrArray *files,
289
 
                                          GPtrArray *dirs,
290
 
                                          gboolean show_hidden,
291
 
                                          const gchar *path) {
292
 
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
293
 
 
294
 
        GError *error = NULL;
295
 
 
296
 
        GFile *file = g_file_new_for_path (path);
297
 
        /* get ALL the info about the files */
298
 
        GFileEnumerator *enumerator = g_file_enumerate_children (file,
299
 
                                                                                                                         /*"*",*/
300
 
                                                                                                                         "standard::type,"
301
 
                                                                                                                         "standard::is-hidden,"
302
 
                                                                                                                         "standard::name,"
303
 
                                                                                                                         "standard::display-name,"
304
 
                                                                                                                         "access::can-execute",
305
 
                                                                                                                         0,
306
 
                                                                                                                         NULL,
307
 
                                                                                                                         &error);
308
 
        /* did we read the dir correctly? */
309
 
        if (error) {
310
 
                gchar *error_msg = g_strdup (error->message);
311
 
                utils_gerror_ok (&error, FALSE);
312
 
                return error_msg;
313
 
        }
314
 
 
315
 
        GFileInfo *file_info = NULL;
316
 
        while ((file_info = g_file_enumerator_next_file (enumerator, NULL, &error)) != NULL) {
317
 
                /* skip the file if it's hidden and we aren't showing hidden files */
318
 
                if (g_file_info_get_is_hidden (file_info) && !show_hidden) {
319
 
                        g_object_unref (file_info);
320
 
                        continue;
321
 
                }
322
 
                VfsFileInfo *vfs_file_info = g_new0 (VfsFileInfo ,1);
323
 
 
324
 
                vfs_file_info->file_name = g_strdup_printf ("%s/%s", path, g_file_info_get_name (file_info));
325
 
 
326
 
                /* get the file's human readable name, including if it's a desktop file */
327
 
 
328
 
                
329
 
                vfs_file_info->display_name = (vfs_file_is_desktop (vfs_file_info->file_name)) ?
330
 
                                                                           vfs_get_desktop_app_name (vfs_file_info->file_name) :
331
 
                                                                           g_strdup (g_file_info_get_display_name (file_info));
332
 
 
333
 
                vfs_file_info->is_executable = g_file_info_get_attribute_boolean (file_info,
334
 
                                                                                                                                                  G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE) &&
335
 
                                                                                        (g_file_info_get_file_type (file_info) != G_FILE_TYPE_DIRECTORY);
336
 
                /* get the icon */
337
 
                vfs_file_info->icon = vfs_get_icon_for_file (vfs_file_info->file_name); 
338
 
 
339
 
                /* add it to the array */
340
 
                if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY) {
341
 
                        g_ptr_array_add (dirs, (gpointer)vfs_file_info);
342
 
                }
343
 
                else {
344
 
                        g_ptr_array_add (files, (gpointer)vfs_file_info);
345
 
                }
346
 
                g_object_unref (file_info);
347
 
        }
348
 
        g_object_unref (enumerator);
349
 
        g_object_unref (file);
350
 
 
351
 
        /* always check for errors */
352
 
        if (error) {
353
 
                gchar *error_msg = g_strdup (error->message);
354
 
                utils_gerror_ok (&error, FALSE);
355
 
                return error_msg;
356
 
        }
357
 
 
358
 
        g_ptr_array_sort (dirs, (GCompareFunc)&vfs_sort_array);
359
 
        g_ptr_array_sort (files, (GCompareFunc)&vfs_sort_array);
360
 
 
361
 
        return NULL;
 
288
                      GPtrArray *dirs,
 
289
                      gboolean show_hidden,
 
290
                      const gchar *path) {
 
291
    if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
 
292
 
 
293
    GError *error = NULL;
 
294
 
 
295
    GFile *file = g_file_new_for_path (path);
 
296
    /* get ALL the info about the files */
 
297
    GFileEnumerator *enumerator = g_file_enumerate_children (file,
 
298
                                                             /*"*",*/
 
299
                                                             "standard::type,"
 
300
                                                             "standard::is-hidden,"
 
301
                                                             "standard::name,"
 
302
                                                             "standard::display-name,"
 
303
                                                             "access::can-execute",
 
304
                                                             0,
 
305
                                                             NULL,
 
306
                                                             &error);
 
307
    /* did we read the dir correctly? */
 
308
    if (error) {
 
309
        gchar *error_msg = g_strdup (error->message);
 
310
        utils_gerror_ok (&error, FALSE);
 
311
        return error_msg;
 
312
    }
 
313
 
 
314
    GFileInfo *file_info = NULL;
 
315
    while ((file_info = g_file_enumerator_next_file (enumerator, NULL, &error)) != NULL) {
 
316
        /* skip the file if it's hidden and we aren't showing hidden files */
 
317
        if (g_file_info_get_is_hidden (file_info) && !show_hidden) {
 
318
            g_object_unref (file_info);
 
319
            continue;
 
320
        }
 
321
        VfsFileInfo *vfs_file_info = g_new0 (VfsFileInfo ,1);
 
322
 
 
323
        vfs_file_info->file_name = g_strdup_printf ("%s/%s", path, g_file_info_get_name (file_info));
 
324
 
 
325
        /* get the file's human readable name, including if it's a desktop file */
 
326
 
 
327
        
 
328
        vfs_file_info->display_name = (vfs_file_is_desktop (vfs_file_info->file_name)) ?
 
329
                                       vfs_get_desktop_app_name (vfs_file_info->file_name) :
 
330
                                       g_strdup (g_file_info_get_display_name (file_info));
 
331
 
 
332
        vfs_file_info->is_executable = g_file_info_get_attribute_boolean (file_info,
 
333
                                                                          G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE) &&
 
334
                                            (g_file_info_get_file_type (file_info) != G_FILE_TYPE_DIRECTORY);
 
335
        /* get the icon */
 
336
        vfs_file_info->icon = vfs_get_icon_for_file (vfs_file_info->file_name); 
 
337
 
 
338
        /* add it to the array */
 
339
        if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY) {
 
340
            g_ptr_array_add (dirs, (gpointer)vfs_file_info);
 
341
        }
 
342
        else {
 
343
            g_ptr_array_add (files, (gpointer)vfs_file_info);
 
344
        }
 
345
        g_object_unref (file_info);
 
346
    }
 
347
    g_object_unref (enumerator);
 
348
    g_object_unref (file);
 
349
 
 
350
    /* always check for errors */
 
351
    if (error) {
 
352
        gchar *error_msg = g_strdup (error->message);
 
353
        utils_gerror_ok (&error, FALSE);
 
354
        return error_msg;
 
355
    }
 
356
 
 
357
    g_ptr_array_sort (dirs, (GCompareFunc)&vfs_sort_array);
 
358
    g_ptr_array_sort (files, (GCompareFunc)&vfs_sort_array);
 
359
 
 
360
    return NULL;
362
361
}
363
362
/******************************************************************************/