~jeremywootten/pantheon-files/fix-hang-on-large-copy

1 by am.monkeyd at gmail
let's roll
1
/*
2
 * Copyright (C) 2010 ammonkey
3
 *
4
 * This library is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License
6
 * version 3.0 as published by the Free Software Foundation.
7
 *
8
 * This library is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU Lesser General Public License version 3.0 for more details.
12
 *
13
 * You should have received a copy of the GNU Lesser General Public
14
 * License along with this library. If not, see
15
 * <http://www.gnu.org/licenses/>.
16
 *
17
 * Author: ammonkey <am.monkeyd@gmail.com>
18
 */
19
20
#include "gof-file.h"
21
#include <stdlib.h>
22
#include <string.h>
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
23
#include <sys/stat.h>
1 by am.monkeyd at gmail
let's roll
24
#include "eel-i18n.h"
25
#include "eel-fcts.h"
122.1.1 by am.monkeyd at gmail
drag&drop
26
#include "eel-string.h"
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
27
#include "eel-gio-extensions.h"
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
28
#include "eel-string.h"
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
29
#include "marlin-exec.h"
131 by am.monkeyd at gmail
xdg directories icons
30
#include "marlin-icons.h"
698 by am.monkeyd at gmail
cleaning some compil warnings
31
#include "fm-list-model.h"
1564 by xapantu
Rename both filescore and fileswidgets to files-core and files-widgets
32
#include "pantheon-files-core.h"
1 by am.monkeyd at gmail
let's roll
33
34
604.1.2 by am.monkeyd at gmail
adding file_cache
35
G_LOCK_DEFINE_STATIC (file_cache_mutex);
36
37
static GHashTable   *file_cache;
1 by am.monkeyd at gmail
let's roll
38
39
//static void gof_file_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
40
//static void gof_file_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
41
42
G_DEFINE_TYPE (GOFFile, gof_file, G_TYPE_OBJECT)
43
44
#define SORT_LAST_CHAR1 '.'
45
#define SORT_LAST_CHAR2 '#'
46
106.1.2 by am.monkeyd at gmail
file_operations mount/unmount copy/move
47
#define ICON_NAME_THUMBNAIL_LOADING   "image-loading"
48
737 by am.monkeyd at gmail
libcore use a static GOFPreferences object, free libcore from gsetting, bind GOFPreferences with gsettings outside of libcore in marlin-application. gof_file_get_formated_time implement date-format pref.
49
enum {
50
    CHANGED,
51
    //UPDATED_DEEP_COUNT_IN_PROGRESS,
52
    INFO_AVAILABLE,
53
    ICON_CHANGED,
54
    DESTROY,
55
    LAST_SIGNAL
56
};
106.1.1 by am.monkeyd at gmail
copy/cut/paste + merge_menus + some file_operations
57
122.1.1 by am.monkeyd at gmail
drag&drop
58
static guint    signals[LAST_SIGNAL];
737 by am.monkeyd at gmail
libcore use a static GOFPreferences object, free libcore from gsetting, bind GOFPreferences with gsettings outside of libcore in marlin-application. gof_file_get_formated_time implement date-format pref.
59
60
61
/*struct _GOFFilePrivate {
62
};*/
63
122.1.1 by am.monkeyd at gmail
drag&drop
64
static guint32  effective_user_id;
106.1.1 by am.monkeyd at gmail
copy/cut/paste + merge_menus + some file_operations
65
604.1.10 by am.monkeyd at gmail
goffile missing object_ref - bug with bookmarked dir
66
static gpointer _g_object_ref0 (gpointer self) {
1811.1.1 by Jeremy Wootten
Code clean: tabs, trailing space, headers, comments
67
    return self ? g_object_ref (self) : NULL;
604.1.10 by am.monkeyd at gmail
goffile missing object_ref - bug with bookmarked dir
68
}
585 by am.monkeyd at gmail
OpenWith (sub)menus refactoring. available from menubar too. more tradtional menus
69
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
70
const gchar     *gof_file_get_thumbnail_path (GOFFile *file);
71
131 by am.monkeyd at gmail
xdg directories icons
72
static GIcon *
73
get_icon_user_special_dirs(char *path)
74
{
75
    GIcon *icon = NULL;
76
77
    if (!path)
78
        return NULL;
604.1.14 by am.monkeyd at gmail
start to monitor
79
    if (g_strcmp0 (path, g_get_home_dir ()) == 0)
131 by am.monkeyd at gmail
xdg directories icons
80
        icon = g_themed_icon_new ("user-home");
604.1.14 by am.monkeyd at gmail
start to monitor
81
    else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP)) == 0)
131 by am.monkeyd at gmail
xdg directories icons
82
        icon = g_themed_icon_new ("user-desktop");
83
    else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS)) == 0)
84
        icon = g_themed_icon_new_with_default_fallbacks ("folder-documents");
85
    else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD)) == 0)
86
        icon = g_themed_icon_new_with_default_fallbacks ("folder-download");
87
    else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_MUSIC)) == 0)
88
        icon = g_themed_icon_new_with_default_fallbacks ("folder-music");
89
    else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_PICTURES)) == 0)
90
        icon = g_themed_icon_new_with_default_fallbacks ("folder-pictures");
91
    else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE)) == 0)
92
        icon = g_themed_icon_new_with_default_fallbacks ("folder-publicshare");
93
    else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES)) == 0)
94
        icon = g_themed_icon_new_with_default_fallbacks ("folder-templates");
95
    else if (g_strcmp0 (path, g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS)) == 0)
96
        icon = g_themed_icon_new_with_default_fallbacks ("folder-videos");
97
98
    return (icon);
99
}
100
763 by am.monkeyd at gmail
memory enhancements, use toggle ref on our caches hashtables from gof-directory-async & marlin-icon-info. check refcounts, unload files and icon pixbuf from memory.
101
GOFFile *
102
gof_file_new (GFile *location, GFile *dir)
1 by am.monkeyd at gmail
let's roll
103
{
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
104
    GOFFile *file;
160 by am.monkeyd at gmail
gof-file gof-directory refont
105
106
    file = (GOFFile*) g_object_new (GOF_TYPE_FILE, NULL);
107
    file->location = g_object_ref (location);
360 by am.monkeyd at gmail
adding -d debug option, goffile got uri checked all g_file_get_uri debug msg
108
    file->uri = g_file_get_uri (location);
479 by am.monkeyd at gmail
fix regression introduced in rev465 const string TRASH_URI we loosed the empty trash menu item due to strcmp mismatch. update LoactionBar with trash:///. gof_file : fix parent root filesystem being null + needed unref
109
    if (dir != NULL)
110
        file->directory = g_object_ref (dir);
111
    else
112
        file->directory = NULL;
1459.1.187 by jeremy at elementaryos
Improve cancelling of timeouts etc before view or path change; suppress errors due to invalid pixbuf size and null cache lookup
113
160 by am.monkeyd at gmail
gof-file gof-directory refont
114
    file->basename = g_file_get_basename (file->location);
115
    //file->parent_dir = g_file_enumerator_get_container (enumerator);
116
1785.2.4 by cmm2
Fix owner:group string memory leak in gof_file_finalize.
117
    //g_debug ("%s: create %p", __func__, file);
160 by am.monkeyd at gmail
gof-file gof-directory refont
118
    return (file);
119
}
120
679 by am.monkeyd at gmail
files operations use file-changes-queue. rename on new folder. rename reuse edited row.
121
#if 0
122
void    gof_file_changed (GOFFile *file)
123
{
124
    GOFDirectoryAsync *dir;
125
126
    /* get the DirectoryAsync associated to the file */
127
    dir = gof_directory_async_cache_lookup (file->directory);
128
    if (dir != NULL) {
129
        if (!file->is_hidden || dir->show_hidden_files)
130
            g_signal_emit_by_name (dir, "file_changed", file);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
131
679 by am.monkeyd at gmail
files operations use file-changes-queue. rename on new folder. rename reuse edited row.
132
        g_object_unref (dir);
133
    }
134
    g_signal_emit_by_name (file, "changed");
135
}
136
#endif
137
763 by am.monkeyd at gmail
memory enhancements, use toggle ref on our caches hashtables from gof-directory-async & marlin-icon-info. check refcounts, unload files and icon pixbuf from memory.
138
void
139
gof_file_icon_changed (GOFFile *file)
604.1.30 by am.monkeyd at gmail
- enable back thumbnails
140
{
1459.1.187 by jeremy at elementaryos
Improve cancelling of timeouts etc before view or path change; suppress errors due to invalid pixbuf size and null cache lookup
141
    GOFDirectoryAsync *dir = NULL;
604.1.30 by am.monkeyd at gmail
- enable back thumbnails
142
143
    /* get the DirectoryAsync associated to the file */
2033.2.6 by jeremy at elementaryos
Fix view reloading
144
    if (file->directory != NULL) {
145
        dir = gof_directory_async_cache_lookup (file->directory);
146
        if (dir != NULL) {
147
            if (!file->is_hidden || gof_preferences_get_default ()->pref_show_hidden_files)
148
                g_signal_emit_by_name (dir, "icon_changed", file);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
149
2033.2.6 by jeremy at elementaryos
Fix view reloading
150
            g_object_unref (dir);
151
        }
604.1.30 by am.monkeyd at gmail
- enable back thumbnails
152
    }
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
153
    g_signal_emit_by_name (file, "icon_changed");
604.1.30 by am.monkeyd at gmail
- enable back thumbnails
154
}
155
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
156
static void
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
157
gof_file_clear_info (GOFFile *file)
158
{
159
    g_return_if_fail (file != NULL);
160
787 by am.monkeyd at gmail
PropertiesWindow show device usage when selection contain a folder, for mounted device or root filesystem
161
    _g_object_unref0 (file->target_location);
162
    _g_object_unref0 (file->mount);
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
163
    _g_free0(file->utf8_collation_key);
164
    _g_free0(file->formated_type);
165
    _g_free0(file->format_size);
166
    _g_free0(file->formated_modified);
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
167
    _g_object_unref0 (file->icon);
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
168
    _g_free0 (file->custom_display_name);
169
    _g_free0 (file->custom_icon_name);
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
170
171
    file->uid = -1;
172
    file->gid = -1;
173
    file->has_permissions = FALSE;
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
174
    file->permissions = 0;
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
175
    _g_free0(file->owner);
176
    _g_free0(file->group);
787 by am.monkeyd at gmail
PropertiesWindow show device usage when selection contain a folder, for mounted device or root filesystem
177
    file->can_unmount = FALSE;
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
178
}
179
1198.1.11 by optimisme at gmail
static method is_location_uri_default
180
/**
181
 * gof_file_is_location_uri_default:
182
 *
1201 by Victor
GOFFile: avoid using UTF-8-encoded string in gof_file_is_location_uri_default to prevent failures, since the string functions are expecting native character encoding.
183
 * example: afp://server.local:123/)
1198.1.11 by optimisme at gmail
static method is_location_uri_default
184
 *
1201 by Victor
GOFFile: avoid using UTF-8-encoded string in gof_file_is_location_uri_default to prevent failures, since the string functions are expecting native character encoding.
185
 * Returns: TRUE if it is an URI at "/"; FALSE otherwise.
1198.1.11 by optimisme at gmail
static method is_location_uri_default
186
**/
187
static gboolean
1198.1.5 by optimisme at gmail
new function to check if an uri is default
188
gof_file_is_location_uri_default (GOFFile *file)
189
{
1643.2.16 by jeremy at elementaryos
Quieten some warnings, show informative content in view for unmountable locations, do not show 'file://' in breadcrumbs
190
    g_return_val_if_fail (file->info != NULL, FALSE);
1643.2.23 by jeremy at elementaryos
Limit context menu options for schemes and servers
191
    gboolean res;
1643.2.16 by jeremy at elementaryos
Quieten some warnings, show informative content in view for unmountable locations, do not show 'file://' in breadcrumbs
192
1201 by Victor
GOFFile: avoid using UTF-8-encoded string in gof_file_is_location_uri_default to prevent failures, since the string functions are expecting native character encoding.
193
    const char *target_uri = g_file_info_get_attribute_string (file->info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
1643.2.14 by jeremy at elementaryos
Remove debugging code, fix formatting
194
1643.2.23 by jeremy at elementaryos
Limit context menu options for schemes and servers
195
    if (target_uri == NULL)
196
        target_uri = file->uri;
197
198
    gchar **split = g_strsplit (target_uri, "/", 4);
199
    res = (split[3] == NULL || !strcmp (split[3], ""));
200
    g_strfreev (split);
201
202
    return res;
1191.1.5 by Albert Palacios
merged with victor suggestions and fixed bug 998555
203
}
204
1643.2.17 by jeremy at elementaryos
Suppress properties, edit, bookmark and open in terminal for root network folders
205
gboolean
206
gof_file_is_mountable (GOFFile *file) {
207
    g_return_val_if_fail (file->info != NULL, FALSE);
208
    return g_file_info_get_file_type(file->info) == G_FILE_TYPE_MOUNTABLE;
209
}
210
1643.2.43 by jeremy at elementaryos
Restrict bookmarking on network locations to folders and shares
211
guint
212
get_number_of_uri_parts (GOFFile *file) {
213
    const char *target_uri = NULL;
214
    if (file->info != NULL)
215
        target_uri = g_file_info_get_attribute_string (file->info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
216
217
    if (target_uri == NULL)
218
        target_uri = file->uri;
219
220
    gchar **split = g_strsplit (target_uri, "/", 6);
221
    guint i, count;
222
    count = 0;
223
    for (i = 0; i < g_strv_length (split); i++) {
224
        if (split [i][0] != NULL) {
225
            count++;
226
        }
227
    }
228
    g_strfreev (split);
229
    return count;
230
}
231
232
gboolean
1643.2.9 by jeremy at elementaryos
Adjust context menu appropriately for network locations
233
gof_file_is_smb_share (GOFFile *file)
234
{
1643.2.17 by jeremy at elementaryos
Suppress properties, edit, bookmark and open in terminal for root network folders
235
    gboolean res;
236
    res = FALSE;
237
1643.2.53 by jeremy at elementaryos
Fix gof_file_is_folder function
238
    if (gof_file_is_smb_uri_scheme (file) || gof_file_is_network_uri_scheme (file)) {
1643.2.43 by jeremy at elementaryos
Restrict bookmarking on network locations to folders and shares
239
        res = get_number_of_uri_parts (file) == 3;
1643.2.53 by jeremy at elementaryos
Fix gof_file_is_folder function
240
    }
1643.2.47 by jeremy at elementaryos
Remove clipboard options from domain/workkgroup context menu
241
1643.2.43 by jeremy at elementaryos
Restrict bookmarking on network locations to folders and shares
242
    return res;
243
}
244
245
gboolean
246
gof_file_is_smb_server (GOFFile *file)
247
{
248
    gboolean res;
249
    res = FALSE;
250
251
    if (gof_file_is_smb_uri_scheme (file) || gof_file_is_network_uri_scheme (file)){
252
        res = get_number_of_uri_parts (file) == 2;
1643.2.9 by jeremy at elementaryos
Adjust context menu appropriately for network locations
253
    }
1643.2.53 by jeremy at elementaryos
Fix gof_file_is_folder function
254
1643.2.17 by jeremy at elementaryos
Suppress properties, edit, bookmark and open in terminal for root network folders
255
    return res;
1643.2.9 by jeremy at elementaryos
Adjust context menu appropriately for network locations
256
}
257
1191.1.5 by Albert Palacios
merged with victor suggestions and fixed bug 998555
258
gboolean
1198.1.11 by optimisme at gmail
static method is_location_uri_default
259
gof_file_is_remote_uri_scheme (GOFFile *file)
260
{
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
261
    if (gof_file_is_root_network_folder (file) || gof_file_is_other_uri_scheme (file))
1198.1.11 by optimisme at gmail
static method is_location_uri_default
262
        return TRUE;
263
}
264
265
gboolean
266
gof_file_is_root_network_folder (GOFFile *file)
267
{
1643.2.51 by jeremy at elementaryos
Fix context menu contents for samba share selection, fix undo/redo move
268
    return (gof_file_is_network_uri_scheme (file) || gof_file_is_smb_server (file));
1198.1.11 by optimisme at gmail
static method is_location_uri_default
269
}
270
271
gboolean
1191.1.5 by Albert Palacios
merged with victor suggestions and fixed bug 998555
272
gof_file_is_network_uri_scheme (GOFFile *file)
273
{
1643.2.41 by jeremy at elementaryos
Synchronise windows showing remote folder when changed by create, delete or rename operations
274
    if (!G_IS_FILE (file->location))
275
        return TRUE;
276
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
277
    return g_file_has_uri_scheme (file->location, "network");
1191.1.5 by Albert Palacios
merged with victor suggestions and fixed bug 998555
278
}
279
280
gboolean
281
gof_file_is_smb_uri_scheme (GOFFile *file)
282
{
1643.2.41 by jeremy at elementaryos
Synchronise windows showing remote folder when changed by create, delete or rename operations
283
    if (!G_IS_FILE (file->location))
284
        return TRUE;
285
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
286
    return g_file_has_uri_scheme (file->location, "smb");
287
}
288
289
gboolean
290
gof_file_is_other_uri_scheme (GOFFile *file)
291
{
292
    GFile *loc = file->location;
1643.2.41 by jeremy at elementaryos
Synchronise windows showing remote folder when changed by create, delete or rename operations
293
    if (!G_IS_FILE (file->location))
294
        return TRUE;
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
295
296
    gboolean res;
297
298
    res = g_file_has_uri_scheme (loc, "ftp") ||
299
          g_file_has_uri_scheme (loc, "sftp") ||
300
          g_file_has_uri_scheme (loc, "afp") ||
301
          g_file_has_uri_scheme (loc, "dav") ||
302
          g_file_has_uri_scheme (loc, "davs");
303
304
    return res;
1191.1.5 by Albert Palacios
merged with victor suggestions and fixed bug 998555
305
}
306
1643.2.60 by jeremy at elementaryos
Fix regression in user special directory icons
307
void
308
gof_file_get_folder_icon_from_uri_or_path (GOFFile *file)
632 by am.monkeyd at gmail
don't put remote folder icon on all not native file, fix folder icon in trash, try to evaluate real remote folder even if gio doesn t help much on this. evalute bookmark folder icon even when not mounted
309
{
1643.2.45 by jeremy at elementaryos
Refactor gof_file_get_folder_icon_from_uri_or_path
310
    if (file->icon != NULL)
311
        return;
312
313
    if (!file->is_hidden && file->uri != NULL) {
632 by am.monkeyd at gmail
don't put remote folder icon on all not native file, fix folder icon in trash, try to evaluate real remote folder even if gio doesn t help much on this. evalute bookmark folder icon even when not mounted
314
        char *path = g_filename_from_uri (file->uri, NULL, NULL);
315
        file->icon = get_icon_user_special_dirs(path);
316
        _g_free0 (path);
317
    }
318
1643.2.61 by jeremy at elementaryos
Fix fix of regression in user special directory icons
319
    if (file->icon == NULL && !g_file_is_native (file->location)
320
        && gof_file_is_remote_uri_scheme (file))
632 by am.monkeyd at gmail
don't put remote folder icon on all not native file, fix folder icon in trash, try to evaluate real remote folder even if gio doesn t help much on this. evalute bookmark folder icon even when not mounted
321
        file->icon = g_themed_icon_new (MARLIN_ICON_FOLDER_REMOTE);
1643.2.61 by jeremy at elementaryos
Fix fix of regression in user special directory icons
322
    if (file->icon == NULL)
1643.2.60 by jeremy at elementaryos
Fix regression in user special directory icons
323
        file->icon = g_themed_icon_new (MARLIN_ICON_FOLDER);
632 by am.monkeyd at gmail
don't put remote folder icon on all not native file, fix folder icon in trash, try to evaluate real remote folder even if gio doesn t help much on this. evalute bookmark folder icon even when not mounted
324
}
325
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
326
static void
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
327
gof_file_target_location_update (GOFFile *file)
328
{
329
    if (file->target_location == NULL)
330
        return;
331
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
332
    /*GOFFile *gof = gof_file_get (file->target_location);
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
333
    gof_file_query_update (gof);
334
    file->is_directory = gof->is_directory;
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
335
    file->ftype = gof->ftype;*/
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
336
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
337
    file->target_gof = gof_file_get (file->target_location);
338
    /* TODO make async */
339
    gof_file_query_update (file->target_gof);
340
}
341
342
static void
343
gof_file_update_size (GOFFile *file)
344
{
345
    g_free (file->format_size);
2300.2.2 by Jeremy Wootten
Use 'Inaccessible' for size and modified if no info
346
347
    if (gof_file_is_folder (file) || gof_file_is_root_network_folder (file)) {
1213.1.1 by Ryan Van Quinlan
Files now shows em dash as folder size
348
        file->format_size = g_strdup ("—");
2300.2.2 by Jeremy Wootten
Use 'Inaccessible' for size and modified if no info
349
    } else if (g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_STANDARD_SIZE)) {
798.2.2 by am.monkeyd at gmail
replace deprecated fcts from gtk & glib
350
        file->format_size = g_format_size (file->size);
2300.2.2 by Jeremy Wootten
Use 'Inaccessible' for size and modified if no info
351
    } else {
352
        file->format_size = g_strdup (_("Inaccessible"));
2300.2.1 by Jeremy Wootten
Emblem on unexecutable folders, fix file size and modified in unexecutable folders
353
    }
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
354
}
355
356
static void
748 by am.monkeyd at gmail
adding ctags core plugin, content-type detection, color ...
357
gof_file_update_formated_type (GOFFile *file)
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
358
{
359
    gchar *formated_type = NULL;
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
360
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
361
    _g_free0 (file->formated_type);
756 by am.monkeyd at gmail
goffile clean up
362
    if (gof_preferences_get_default ()->pref_interpret_desktop_files && file->target_gof && gof_file_get_ftype (file->target_gof)) {
363
        file->formated_type = g_content_type_get_description (gof_file_get_ftype (file->target_gof));
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
364
    } else {
365
        //trash doesn't have a ftype
757 by am.monkeyd at gmail
goffile more clean up
366
        const gchar *ftype = gof_file_get_ftype (file);
367
        if (ftype != NULL) {
368
            formated_type = g_content_type_get_description (ftype);
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
369
            if (G_UNLIKELY (gof_file_is_symlink (file))) {
370
                file->formated_type = g_strdup_printf (_("link to %s"), formated_type);
371
            } else {
372
                file->formated_type = g_strdup (formated_type);
373
            }
374
        } else {
375
            file->formated_type = g_strdup ("");
376
        }
377
    }
378
    g_free (formated_type);
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
379
}
380
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
381
static void
748 by am.monkeyd at gmail
adding ctags core plugin, content-type detection, color ...
382
gof_file_update_icon_internal (GOFFile *file, gint size);
383
384
void
385
gof_file_update_type (GOFFile *file)
386
{
755 by am.monkeyd at gmail
goffile file info const start cleanup
387
    const gchar *ftype = gof_file_get_ftype (file);
748 by am.monkeyd at gmail
adding ctags core plugin, content-type detection, color ...
388
755 by am.monkeyd at gmail
goffile file info const start cleanup
389
    gof_file_update_formated_type (file);
390
    /* update icon */
391
    file->icon = g_content_type_get_icon (ftype);
1459.1.202 by jeremy at elementaryos
Ensure gof_file_icon_update_internal is not called with invalid pix_size
392
    if (file->pix_size > 1)
393
        gof_file_update_icon_internal (file, file->pix_size);
394
755 by am.monkeyd at gmail
goffile file info const start cleanup
395
    gof_file_icon_changed (file);
748 by am.monkeyd at gmail
adding ctags core plugin, content-type detection, color ...
396
}
397
787 by am.monkeyd at gmail
PropertiesWindow show device usage when selection contain a folder, for mounted device or root filesystem
398
void
399
gof_file_update (GOFFile *file)
160 by am.monkeyd at gmail
gof-file gof-directory refont
400
{
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
401
    GKeyFile *key_file;
402
    gchar *p;
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
403
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
404
    g_return_if_fail (file->info != NULL);
405
266 by am.monkeyd at gmail
thumbnailer via tumblermonitor file_changetoolbar-primary-css-style bool dconf key
406
    /* free previously allocated */
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
407
    gof_file_clear_info (file);
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
408
262 by xapantu
Ignore backup files when hidden file are ignored
409
    file->is_hidden = g_file_info_get_is_hidden (file->info) || g_file_info_get_is_backup (file->info);
160 by am.monkeyd at gmail
gof-file gof-directory refont
410
    file->size = (guint64) g_file_info_get_size (file->info);
604.1.2 by am.monkeyd at gmail
adding file_cache
411
    file->file_type = g_file_info_get_file_type (file->info);
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
412
    file->is_directory = (file->file_type == G_FILE_TYPE_DIRECTORY);
160 by am.monkeyd at gmail
gof-file gof-directory refont
413
    file->modified = g_file_info_get_attribute_uint64 (file->info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
414
697 by am.monkeyd at gmail
Bug #896573 Folder file sorting selected by user is not recorded
415
    /* metadata */
416
    if (file->is_directory) {
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
417
        if (g_file_info_has_attribute (file->info, "metadata::marlin-sort-column-id"))
697 by am.monkeyd at gmail
Bug #896573 Folder file sorting selected by user is not recorded
418
            file->sort_column_id = fm_list_model_get_column_id_from_string (g_file_info_get_attribute_string (file->info, "metadata::marlin-sort-column-id"));
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
419
        if (g_file_info_has_attribute (file->info, "metadata::marlin-sort-reversed"))
697 by am.monkeyd at gmail
Bug #896573 Folder file sorting selected by user is not recorded
420
            file->sort_order = !g_strcmp0 (g_file_info_get_attribute_string (file->info, "metadata::marlin-sort-reversed"), "true") ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING;
421
    }
422
1406.2.1 by Niclas Lockner
Fixes a double-free in gof-file
423
    if (g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_STANDARD_ICON)) {
681 by am.monkeyd at gmail
removing some compil warnings
424
        file->icon = (GIcon *) g_file_info_get_attribute_object (file->info, G_FILE_ATTRIBUTE_STANDARD_ICON);
1406.2.1 by Niclas Lockner
Fixes a double-free in gof-file
425
        g_object_ref (file->icon);
426
    }
665 by am.monkeyd at gmail
use gio full attrs for network and computer schemes
427
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
428
    if (file->file_type == G_FILE_TYPE_SHORTCUT || file->file_type == G_FILE_TYPE_MOUNTABLE) {
1198.1.14 by optimisme at gmail
linal fixes
429
        const char *target_uri =  g_file_info_get_attribute_string (file->info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
430
        if (target_uri != NULL) {
431
            file->target_location = g_file_new_for_uri (target_uri);
432
            gof_file_target_location_update (file);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
433
1643.2.34 by jeremy at elementaryos
Allow bookmarking of all mounted network locations by context menu
434
            if (file->file_type == G_FILE_TYPE_MOUNTABLE) {
1643.2.9 by jeremy at elementaryos
Adjust context menu appropriately for network locations
435
                file->mount = gof_file_get_mount_at (file->target_location);
1643.2.34 by jeremy at elementaryos
Allow bookmarking of all mounted network locations by context menu
436
                file->is_mounted = (file->mount != NULL);
437
            }
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
438
        }
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
439
    }
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
440
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
441
    /* TODO the key-files could be loaded async.
604.1.25 by am.monkeyd at gmail
enable back desktop files, ensure pixbuf is always not null
442
    <lazy>The performance gain would not be that great</lazy>*/
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
443
    if ((file->is_desktop = gof_file_is_desktop_file (file)))
444
    {
604.1.26 by am.monkeyd at gmail
add thunar copyright for desktop files code snippet in gof-file.c
445
        /* The following code snippet about desktop files come from Thunar thunar-file.c,
446
         * Copyright (c) 2005-2007 Benedikt Meurer <benny@xfce.org>
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
447
         * Copyright (c) 2009-2011 Jannis Pohlmann <jannis@xfce.org>
604.1.26 by am.monkeyd at gmail
add thunar copyright for desktop files code snippet in gof-file.c
448
         */
449
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
450
        /* determine the custom icon and display name for .desktop files */
451
452
        /* query a key file for the .desktop file */
453
        //TODO make cancellable & error
454
        key_file = eel_g_file_query_key_file (file->location, NULL, NULL);
455
        if (key_file != NULL)
456
        {
457
            /* read the icon name from the .desktop file */
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
458
            file->custom_icon_name = g_key_file_get_string (key_file,
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
459
                                                            G_KEY_FILE_DESKTOP_GROUP,
460
                                                            G_KEY_FILE_DESKTOP_KEY_ICON,
461
                                                            NULL);
462
463
            if (G_UNLIKELY (eel_str_is_empty (file->custom_icon_name)))
464
            {
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
465
                /* make sure we set null if the string is empty else the assertion in
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
466
                 * thunar_icon_factory_lookup_icon() will fail */
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
467
                _g_free0 (file->custom_icon_name);
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
468
                file->custom_icon_name = NULL;
469
            }
470
            else
471
            {
472
                /* drop any suffix (e.g. '.png') from themed icons */
473
                if (!g_path_is_absolute (file->custom_icon_name))
474
                {
475
                    p = strrchr (file->custom_icon_name, '.');
476
                    if (p != NULL)
477
                        *p = '\0';
478
                }
479
            }
480
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
481
            /* read the display name from the .desktop file (will be overwritten later
482
             * if it's undefined here) */
2132.1.1 by jeremy at elementaryos
Show name of desktop files in current locale
483
            gchar *custom_display_name = g_key_file_get_locale_string (key_file,
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
484
                                                                G_KEY_FILE_DESKTOP_GROUP,
485
                                                                G_KEY_FILE_DESKTOP_KEY_NAME,
2132.1.1 by jeremy at elementaryos
Show name of desktop files in current locale
486
                                                                NULL,
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
487
                                                                NULL);
488
489
            /* check if we have a display name now */
490
            if (custom_display_name != NULL)
491
            {
492
                /* drop the name if it's empty or has invalid encoding */
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
493
                if (*custom_display_name == '\0'
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
494
                    || !g_utf8_validate (custom_display_name, -1, NULL))
495
                {
496
                    _g_free0 (custom_display_name);
497
                    custom_display_name = NULL;
498
                } else {
499
                    file->custom_display_name = custom_display_name;
500
                }
501
            }
502
503
            /* check f we have a target location */
504
            gchar *url;
505
            gchar *type;
506
507
            type = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
508
                                          G_KEY_FILE_DESKTOP_KEY_TYPE, NULL);
509
            if (eel_str_is_equal (type, "Link"))
510
            {
511
                url = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
512
                                             G_KEY_FILE_DESKTOP_KEY_URL, NULL);
513
                if (G_LIKELY (url != NULL))
514
                {
515
                    g_debug ("%s .desktop Link %s\n", G_STRFUNC, url);
516
                    file->target_location = g_file_new_for_uri (url);
517
                    gof_file_target_location_update (file);
518
                    g_free (url);
519
                }
520
            }
521
            _g_free0 (type);
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
522
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
523
            /* free the key file */
524
            g_key_file_free (key_file);
525
        }
526
    }
527
2310.2.1 by Jeremy Wootten
Show protocol after servers in network:// view
528
    if (file->custom_display_name == NULL) {
529
        /* Use custom_display_name to store default display name if there is no custom name */
530
        if (file->info && g_file_info_get_display_name (file->info) != NULL) {
2310.2.2 by Jeremy Wootten
Capitalize protocol, no protocol after Windows Network
531
            if (file->directory != NULL &&
532
                strcmp (g_file_get_uri_scheme (file->directory), "network") == 0 &&
533
                !(strcmp (g_file_get_uri (file->target_location), "smb:///") == 0)) {
2310.2.1 by Jeremy Wootten
Show protocol after servers in network:// view
534
                /* Show protocol after server name (lp:1184606) */
535
                file->custom_display_name = g_strdup_printf ("%s (%s)", g_file_info_get_display_name (file->info),
2310.2.2 by Jeremy Wootten
Capitalize protocol, no protocol after Windows Network
536
                                                                        g_utf8_strup (g_file_get_uri_scheme (file->target_location), -1));
2310.2.1 by Jeremy Wootten
Show protocol after servers in network:// view
537
            } else {
538
                file->custom_display_name = g_strdup (g_file_info_get_display_name (file->info));
539
            }
540
        }
541
    }
542
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
543
    /* sizes */
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
544
    gof_file_update_size (file);
737 by am.monkeyd at gmail
libcore use a static GOFPreferences object, free libcore from gsetting, bind GOFPreferences with gsettings outside of libcore in marlin-application. gof_file_get_formated_time implement date-format pref.
545
    /* modified date */
2300.2.1 by Jeremy Wootten
Emblem on unexecutable folders, fix file size and modified in unexecutable folders
546
    if (g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) {
547
        file->formated_modified = gof_file_get_formated_time (file, G_FILE_ATTRIBUTE_TIME_MODIFIED);
548
    } else {
2300.2.2 by Jeremy Wootten
Use 'Inaccessible' for size and modified if no info
549
        file->formated_modified = g_strdup (_("Inaccessible"));
2300.2.1 by Jeremy Wootten
Emblem on unexecutable folders, fix file size and modified in unexecutable folders
550
    }
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
551
    /* icon */
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
552
    if (file->is_directory) {
632 by am.monkeyd at gmail
don't put remote folder icon on all not native file, fix folder icon in trash, try to evaluate real remote folder even if gio doesn t help much on this. evalute bookmark folder icon even when not mounted
553
        gof_file_get_folder_icon_from_uri_or_path (file);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
554
    } else if (g_file_info_get_file_type(file->info) == G_FILE_TYPE_MOUNTABLE) {
1191.1.5 by Albert Palacios
merged with victor suggestions and fixed bug 998555
555
        file->icon = g_themed_icon_new_with_default_fallbacks ("folder-remote");
632 by am.monkeyd at gmail
don't put remote folder icon on all not native file, fix folder icon in trash, try to evaluate real remote folder even if gio doesn t help much on this. evalute bookmark folder icon even when not mounted
556
    } else {
757 by am.monkeyd at gmail
goffile more clean up
557
        const gchar *ftype = gof_file_get_ftype (file);
558
        if (ftype != NULL && file->icon == NULL)
559
            file->icon = g_content_type_get_icon (ftype);
632 by am.monkeyd at gmail
don't put remote folder icon on all not native file, fix folder icon in trash, try to evaluate real remote folder even if gio doesn t help much on this. evalute bookmark folder icon even when not mounted
560
    }
131 by am.monkeyd at gmail
xdg directories icons
561
666 by am.monkeyd at gmail
use display_name in the FILENAME column model and not name
562
    file->utf8_collation_key = g_utf8_collate_key_for_filename  (gof_file_get_display_name (file), -1);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
563
    /* mark the thumb flags as state none, we'll load the thumbs once the directory
772 by am.monkeyd at gmail
threaded thumbnail loading, thumbs generated from a cached raw pixbuf don't read foreach zoom level changed every thumbs files, thumbs size *1.33, fixing toggles ref in marlin-icon-info
564
     * would be loaded on a thread */
2056.1.1 by jeremy at elementaryos
Ensure new thumbnails are displayed, do not try to thumbnail when unnecessary
565
    if (gof_file_get_thumbnail_path (file) != NULL) {
566
        file->flags = GOF_FILE_THUMB_STATE_UNKNOWN;  /* UNKNOWN means thumbnail not known to be unobtainable */
567
    }
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
568
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
569
    /* formated type */
748 by am.monkeyd at gmail
adding ctags core plugin, content-type detection, color ...
570
    gof_file_update_formated_type (file);
164 by am.monkeyd at gmail
gof-file: update trash info
571
597.1.7 by am.monkeyd at gmail
permissions
572
    /* permissions */
597.1.8 by am.monkeyd at gmail
typo
573
    file->has_permissions = g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_UNIX_MODE);
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
574
    file->permissions = g_file_info_get_attribute_uint32 (file->info, G_FILE_ATTRIBUTE_UNIX_MODE);
597.1.17 by am.monkeyd at gmail
user & group owners
575
    const char *owner = g_file_info_get_attribute_string (file->info, G_FILE_ATTRIBUTE_OWNER_USER);
576
    const char *group = g_file_info_get_attribute_string (file->info, G_FILE_ATTRIBUTE_OWNER_GROUP);
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
577
597.1.17 by am.monkeyd at gmail
user & group owners
578
    if (owner != NULL)
579
        file->owner = strdup (owner);
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
580
597.1.17 by am.monkeyd at gmail
user & group owners
581
    if (group != NULL)
582
        file->group = strdup (group);
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
583
597.1.17 by am.monkeyd at gmail
user & group owners
584
    if (g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_UNIX_UID)) {
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
585
        file->uid = g_file_info_get_attribute_uint32 (file->info, G_FILE_ATTRIBUTE_UNIX_UID);
2357.1.1 by Jeremy Wootten
Correctly determine write permissions for ftp files
586
        if (file->owner == NULL) {
597.1.17 by am.monkeyd at gmail
user & group owners
587
            file->owner = g_strdup_printf ("%d", file->uid);
2357.1.1 by Jeremy Wootten
Correctly determine write permissions for ftp files
588
        }
589
    } else if (file->owner != NULL) { /* e.g. ftp info yields owner but not uid */
590
        file->uid = atoi (file->owner);
597.1.17 by am.monkeyd at gmail
user & group owners
591
    }
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
592
597.1.17 by am.monkeyd at gmail
user & group owners
593
    if (g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_UNIX_GID)) {
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
594
        file->gid = g_file_info_get_attribute_uint32 (file->info, G_FILE_ATTRIBUTE_UNIX_GID);
2357.1.1 by Jeremy Wootten
Correctly determine write permissions for ftp files
595
        if (file->group == NULL) {
597.1.17 by am.monkeyd at gmail
user & group owners
596
            file->group = g_strdup_printf ("%d", file->gid);
2357.1.1 by Jeremy Wootten
Correctly determine write permissions for ftp files
597
        }
598
    } else if (file->group != NULL) {  /* e.g. ftp info yields owner but not uid */
599
        file->gid = atoi (file->group);
597.1.17 by am.monkeyd at gmail
user & group owners
600
    }
601
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
602
    if (g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT))
787 by am.monkeyd at gmail
PropertiesWindow show device usage when selection contain a folder, for mounted device or root filesystem
603
        file->can_unmount = g_file_info_get_attribute_boolean (file->info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT);
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
604
164 by am.monkeyd at gmail
gof-file: update trash info
605
    gof_file_update_trash_info (file);
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
606
560.1.8 by am.monkeyd at gmail
clean up
607
    gof_file_update_emblem (file);
608
}
609
641 by am.monkeyd at gmail
cleanup, some renames
610
static MarlinIconInfo *
772 by am.monkeyd at gmail
threaded thumbnail loading, thumbs generated from a cached raw pixbuf don't read foreach zoom level changed every thumbs files, thumbs size *1.33, fixing toggles ref in marlin-icon-info
611
gof_file_get_special_icon (GOFFile *file, int size, GOFFileIconFlags flags)
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
612
{
1459.1.187 by jeremy at elementaryos
Improve cancelling of timeouts etc before view or path change; suppress errors due to invalid pixbuf size and null cache lookup
613
    g_return_val_if_fail (size >= 1, NULL);
614
772 by am.monkeyd at gmail
threaded thumbnail loading, thumbs generated from a cached raw pixbuf don't read foreach zoom level changed every thumbs files, thumbs size *1.33, fixing toggles ref in marlin-icon-info
615
    if (file->custom_icon_name != NULL) {
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
616
        if (g_path_is_absolute (file->custom_icon_name))
772 by am.monkeyd at gmail
threaded thumbnail loading, thumbs generated from a cached raw pixbuf don't read foreach zoom level changed every thumbs files, thumbs size *1.33, fixing toggles ref in marlin-icon-info
617
            return marlin_icon_info_lookup_from_path (file->custom_icon_name, size);
618
        else
619
            return marlin_icon_info_lookup_from_name (file->custom_icon_name, size);
620
    }
621
    if (flags & GOF_FILE_ICON_FLAGS_USE_THUMBNAILS
622
        && file->flags == GOF_FILE_THUMB_STATE_READY) {
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
623
        const gchar *thumb_path = gof_file_get_thumbnail_path (file);
760 by am.monkeyd at gmail
goffile thumbs don't use query file_info again to get the thumb path but use the md5 filename when thumb state is ready. avoid requesting thumbs to tumbler for already known thumbs path, mark files with THUMB_STATE_READY.
624
        /* TODO thumb test : Playing with the thumbs */
625
        //if (file->flags != 0 && thumb_path != NULL) {
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
626
        if (thumb_path != NULL) {
1643.2.14 by jeremy at elementaryos
Remove debugging code, fix formatting
627
            //g_message ("show thumb %s %s %d\n", file->uri, thumb_path, size);
781 by am.monkeyd at gmail
icon-info store the raw pibuf with normal default size at the fake size 0. gof-file don't scale thumbs to 1.33. icon-renderer scallable emblems, change the positions and determined number depending on the zoom level, (we don't want 4 emblems on a 16px icon...). fix bug #914485
628
            //return marlin_icon_info_lookup_from_path (thumb_path, size * 1.33);
629
            return marlin_icon_info_lookup_from_path (thumb_path, size);
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
630
        }
631
    }
632
772 by am.monkeyd at gmail
threaded thumbnail loading, thumbs generated from a cached raw pixbuf don't read foreach zoom level changed every thumbs files, thumbs size *1.33, fixing toggles ref in marlin-icon-info
633
    return NULL;
634
}
635
636
MarlinIconInfo *
637
gof_file_get_icon (GOFFile *file, int size, GOFFileIconFlags flags)
638
{
639
    MarlinIconInfo *icon = NULL;
640
    GIcon *gicon;
641
642
    g_return_val_if_fail (file, NULL);
1459.1.187 by jeremy at elementaryos
Improve cancelling of timeouts etc before view or path change; suppress errors due to invalid pixbuf size and null cache lookup
643
    g_return_val_if_fail (size >= 1, NULL);
644
772 by am.monkeyd at gmail
threaded thumbnail loading, thumbs generated from a cached raw pixbuf don't read foreach zoom level changed every thumbs files, thumbs size *1.33, fixing toggles ref in marlin-icon-info
645
    icon = gof_file_get_special_icon (file, size, flags);
1171.3.3 by Albert Palacios
fixed source style
646
    if (icon != NULL && !marlin_icon_info_is_fallback (icon))
772 by am.monkeyd at gmail
threaded thumbnail loading, thumbs generated from a cached raw pixbuf don't read foreach zoom level changed every thumbs files, thumbs size *1.33, fixing toggles ref in marlin-icon-info
647
        return icon;
648
    _g_object_unref0 (icon);
649
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
650
    if (flags & GOF_FILE_ICON_FLAGS_USE_THUMBNAILS
651
        && file->flags == GOF_FILE_THUMB_STATE_LOADING) {
652
        gicon = g_themed_icon_new (ICON_NAME_THUMBNAIL_LOADING);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
653
    } else {
648 by am.monkeyd at gmail
- gof_file get icon code refactoring, fix mem leaks.
654
        gicon = _g_object_ref0 (file->icon);
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
655
    }
656
648 by am.monkeyd at gmail
- gof_file get icon code refactoring, fix mem leaks.
657
    if (gicon != NULL) {
641 by am.monkeyd at gmail
cleanup, some renames
658
        icon = marlin_icon_info_lookup (gicon, size);
1589.3.5 by jeremy at elementaryos
Handle null icon_info in marlin_icon_info_is_fallback () and gof_file_get_icon ()
659
        if (icon != NULL && marlin_icon_info_is_fallback(icon)) {
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
660
            g_object_unref (icon);
648 by am.monkeyd at gmail
- gof_file get icon code refactoring, fix mem leaks.
661
            icon = marlin_icon_info_get_generic_icon (size);
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
662
        }
663
        g_object_unref (gicon);
664
    } else {
648 by am.monkeyd at gmail
- gof_file get icon code refactoring, fix mem leaks.
665
        icon = marlin_icon_info_get_generic_icon (size);
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
666
    }
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
667
648 by am.monkeyd at gmail
- gof_file get icon code refactoring, fix mem leaks.
668
    return icon;
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
669
}
670
772 by am.monkeyd at gmail
threaded thumbnail loading, thumbs generated from a cached raw pixbuf don't read foreach zoom level changed every thumbs files, thumbs size *1.33, fixing toggles ref in marlin-icon-info
671
#if 0
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
672
static GdkPixbuf
648 by am.monkeyd at gmail
- gof_file get icon code refactoring, fix mem leaks.
673
*ensure_pixbuf_from_nicon (GOFFile *file, gint size, gboolean force_size, MarlinIconInfo *nicon)
604.1.25 by am.monkeyd at gmail
enable back desktop files, ensure pixbuf is always not null
674
{
675
    GdkPixbuf *pix;
641 by am.monkeyd at gmail
cleanup, some renames
676
    MarlinIconInfo *temp_nicon;
1459.1.187 by jeremy at elementaryos
Improve cancelling of timeouts etc before view or path change; suppress errors due to invalid pixbuf size and null cache lookup
677
    g_return_val_if_fail (size >= 1, NULL);
678
648 by am.monkeyd at gmail
- gof_file get icon code refactoring, fix mem leaks.
679
    pix = marlin_icon_info_get_pixbuf_force_size (nicon, size, force_size);
604.1.25 by am.monkeyd at gmail
enable back desktop files, ensure pixbuf is always not null
680
    if (pix == NULL) {
681
        temp_nicon = gof_file_get_icon (file, size, GOF_FILE_ICON_FLAGS_USE_THUMBNAILS);
648 by am.monkeyd at gmail
- gof_file get icon code refactoring, fix mem leaks.
682
        pix = marlin_icon_info_get_pixbuf_force_size (temp_nicon, size, force_size);
770 by am.monkeyd at gmail
_g_object_unref0 insanities, check all & replace
683
        if (temp_nicon)
684
            g_object_unref (temp_nicon);
604.1.25 by am.monkeyd at gmail
enable back desktop files, ensure pixbuf is always not null
685
    }
686
687
    return pix;
688
}
772 by am.monkeyd at gmail
threaded thumbnail loading, thumbs generated from a cached raw pixbuf don't read foreach zoom level changed every thumbs files, thumbs size *1.33, fixing toggles ref in marlin-icon-info
689
#endif
604.1.25 by am.monkeyd at gmail
enable back desktop files, ensure pixbuf is always not null
690
648 by am.monkeyd at gmail
- gof_file get icon code refactoring, fix mem leaks.
691
GdkPixbuf *
692
gof_file_get_icon_pixbuf (GOFFile *file, gint size, gboolean force_size, GOFFileIconFlags flags)
560.1.8 by am.monkeyd at gmail
clean up
693
{
648 by am.monkeyd at gmail
- gof_file get icon code refactoring, fix mem leaks.
694
    MarlinIconInfo *nicon;
695
    GdkPixbuf *pix;
1459.1.187 by jeremy at elementaryos
Improve cancelling of timeouts etc before view or path change; suppress errors due to invalid pixbuf size and null cache lookup
696
    g_return_val_if_fail (size >= 1, NULL);
772 by am.monkeyd at gmail
threaded thumbnail loading, thumbs generated from a cached raw pixbuf don't read foreach zoom level changed every thumbs files, thumbs size *1.33, fixing toggles ref in marlin-icon-info
697
    nicon = gof_file_get_icon (file, size, flags);
1922.1.3 by Jeremy Wootten
Enable force icon size
698
    pix = marlin_icon_info_get_pixbuf_force_size (nicon, size, force_size);
699
    if (nicon) {
770 by am.monkeyd at gmail
_g_object_unref0 insanities, check all & replace
700
        g_object_unref (nicon);
1922.1.3 by Jeremy Wootten
Enable force icon size
701
    }
648 by am.monkeyd at gmail
- gof_file get icon code refactoring, fix mem leaks.
702
    return pix;
703
}
704
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
705
static void
706
gof_file_update_icon_internal (GOFFile *file, gint size)
649 by am.monkeyd at gmail
gof_file_update_icon_internal update icon for thumb state ready
707
{
1459.1.187 by jeremy at elementaryos
Improve cancelling of timeouts etc before view or path change; suppress errors due to invalid pixbuf size and null cache lookup
708
    g_return_if_fail (size >= 1);
649 by am.monkeyd at gmail
gof_file_update_icon_internal update icon for thumb state ready
709
    /* destroy pixbuff if already present */
782 by am.monkeyd at gmail
thumbnails are always generated from a thread, queue thumbnails load foreach zoom-level changed = smooth zoom. still a draft but quite happy with the result so far.
710
    _g_object_unref0 (file->pix);
1922.1.3 by Jeremy Wootten
Enable force icon size
711
    /* make sure we always got a non null pixbuf of the specified size */
1922.1.5 by Jeremy Wootten
Make force-icon-size setting
712
    file->pix = gof_file_get_icon_pixbuf (file, size,
713
                                          gof_preferences_get_default ()->pref_force_icon_size,
714
                                          GOF_FILE_ICON_FLAGS_USE_THUMBNAILS);
649 by am.monkeyd at gmail
gof_file_update_icon_internal update icon for thumb state ready
715
    file->pix_size = size;
716
}
717
1459.1.49 by jeremy at elementaryos
IconView vala using Gtk.IconView - first draft
718
/* This function is used by the icon renderer and fm-list-model.
648 by am.monkeyd at gmail
- gof_file get icon code refactoring, fix mem leaks.
719
 * Store the pixbuf and update it only for size change.
720
 */
721
void gof_file_update_icon (GOFFile *file, gint size)
722
{
1459.1.202 by jeremy at elementaryos
Ensure gof_file_icon_update_internal is not called with invalid pix_size
723
    if (size <= 1)
782 by am.monkeyd at gmail
thumbnails are always generated from a thread, queue thumbnails load foreach zoom-level changed = smooth zoom. still a draft but quite happy with the result so far.
724
        return;
1459.1.56 by jeremy at elementaryos
merged trunk r1581
725
648 by am.monkeyd at gmail
- gof_file get icon code refactoring, fix mem leaks.
726
    if (!(file->pix == NULL || file->pix_size != size))
727
        return;
728
649 by am.monkeyd at gmail
gof_file_update_icon_internal update icon for thumb state ready
729
    gof_file_update_icon_internal (file, size);
560.1.8 by am.monkeyd at gmail
clean up
730
}
731
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
732
void gof_file_update_desktop_file (GOFFile *file)
733
{
734
    g_free (file->utf8_collation_key);
735
    file->utf8_collation_key = g_utf8_collate_key_for_filename  (gof_file_get_display_name (file), -1);
748 by am.monkeyd at gmail
adding ctags core plugin, content-type detection, color ...
736
    gof_file_update_formated_type (file);
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
737
    gof_file_update_size (file);
738
    gof_file_icon_changed (file);
739
}
740
568 by am.monkeyd at gmail
moving gof_file_query_update from directory-view to gof-monitor where it belong. put gof_monitor_file_changed in the correct places to trigger the row changes
741
void gof_file_update_emblem (GOFFile *file)
560.1.8 by am.monkeyd at gmail
clean up
742
{
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
743
    /* Do not try to add emblems to network and remote files (except smb) - can cause blocking io*/
744
    if (gof_file_is_other_uri_scheme (file) || gof_file_is_network_uri_scheme (file))
745
        return;
746
1643.2.42 by jeremy at elementaryos
Suppress emblems on smb shares
747
    /* Do not try to add emblems to smb shares either */
748
    if (gof_file_is_smb_share (file))
749
        return;
750
560.1.7 by am.monkeyd at gmail
reset emblems list
751
    /* erase previous stored emblems */
752
    if (file->emblems_list != NULL) {
753
        g_list_free (file->emblems_list);
754
        file->emblems_list = NULL;
755
    }
1459.1.187 by jeremy at elementaryos
Improve cancelling of timeouts etc before view or path change; suppress errors due to invalid pixbuf size and null cache lookup
756
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
757
    if(plugins != NULL)
604.1.6 by am.monkeyd at gmail
ref fix
758
        marlin_plugin_manager_update_file_info (plugins, file);
1459.1.187 by jeremy at elementaryos
Improve cancelling of timeouts etc before view or path change; suppress errors due to invalid pixbuf size and null cache lookup
759
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
760
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
761
    if(gof_file_is_symlink(file) || (file->is_desktop && file->target_gof))
560.1.6 by am.monkeyd at gmail
moving emblem generation in gof_file_update (a more appropriate section). some emblems position tweaking.
762
    {
763
        gof_file_add_emblem(file, "emblem-symbolic-link");
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
764
560.1.6 by am.monkeyd at gmail
moving emblem generation in gof_file_update (a more appropriate section). some emblems position tweaking.
765
        /* testing up to 4 emblems */
766
        /*gof_file_add_emblem(file, "emblem-generic");
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
767
          gof_file_add_emblem(file, "emblem-important");
768
          gof_file_add_emblem(file, "emblem-favorite");*/
560.1.6 by am.monkeyd at gmail
moving emblem generation in gof_file_update (a more appropriate section). some emblems position tweaking.
769
    }
568 by am.monkeyd at gmail
moving gof_file_query_update from directory-view to gof-monitor where it belong. put gof_monitor_file_changed in the correct places to trigger the row changes
770
1740.1.48 by Fabio Zaramella
typos
771
    /* We hide lock emblems if in Recents, because files here are not real files and emblems would always shown. */
1740.1.46 by Fabio Zaramella
hide lock emblem
772
    if (!gof_file_is_writable (file) && !g_file_has_uri_scheme (file->location, "recent")) {
1615.1.1 by jeremy at elementaryos
Display readonly and unreadable emblems when appropriate
773
        if (gof_file_is_readable (file))
774
            gof_file_add_emblem (file, "emblem-readonly");
775
        else
776
            gof_file_add_emblem (file, "emblem-unreadable");
777
    }
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
778
604.1.30 by am.monkeyd at gmail
- enable back thumbnails
779
    /* TODO update signal on real change */
604.1.9 by am.monkeyd at gmail
fix and more spotted stuff
780
    //g_warning ("update emblem %s", file.uri);
604.1.30 by am.monkeyd at gmail
- enable back thumbnails
781
    if (file->emblems_list != NULL)
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
782
        gof_file_icon_changed (file);
1643.2.20 by jeremy at elementaryos
Do not add emblems to remote network files, fix reload when network connection breaks
783
160 by am.monkeyd at gmail
gof-file gof-directory refont
784
}
785
604.1.30 by am.monkeyd at gmail
- enable back thumbnails
786
void gof_file_add_emblem (GOFFile* file, const gchar* emblem)
498 by xapantu
Emblems for icon view, and add a default emblem for symlink
787
{
788
    GList* emblems = g_list_first(file->emblems_list);
789
    while(emblems != NULL)
790
    {
791
        if(!g_strcmp0(emblems->data, emblem))
792
            return;
793
        emblems = g_list_next(emblems);
794
    }
795
    file->emblems_list = g_list_append(file->emblems_list, (void*)emblem);
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
796
    gof_file_icon_changed (file);
498 by xapantu
Emblems for icon view, and add a default emblem for symlink
797
}
560.1.3 by am.monkeyd at gmail
marlin-icon-renderer fix crash when missing correct emblem, u1 plugins define correct emblems names
798
266 by am.monkeyd at gmail
thumbnailer via tumblermonitor file_changetoolbar-primary-css-style bool dconf key
799
static void
604.1.30 by am.monkeyd at gmail
- enable back thumbnails
800
print_error (GError *error)
266 by am.monkeyd at gmail
thumbnailer via tumblermonitor file_changetoolbar-primary-css-style bool dconf key
801
{
802
    if (error != NULL)
803
    {
1643.2.23 by jeremy at elementaryos
Limit context menu options for schemes and servers
804
        g_debug ("%s [code %d]\n", error->message, error->code);
266 by am.monkeyd at gmail
thumbnailer via tumblermonitor file_changetoolbar-primary-css-style bool dconf key
805
        g_clear_error (&error);
806
    }
807
}
808
1643.2.9 by jeremy at elementaryos
Adjust context menu appropriately for network locations
809
GMount *
810
gof_file_get_mount_at (GFile *target)
787 by am.monkeyd at gmail
PropertiesWindow show device usage when selection contain a folder, for mounted device or root filesystem
811
{
812
    GVolumeMonitor *monitor;
813
    GFile *root;
814
    GList *mounts, *l;
815
    GMount *found;
816
817
    monitor = g_volume_monitor_get ();
818
    mounts = g_volume_monitor_get_mounts (monitor);
819
820
    found = NULL;
821
    for (l = mounts; l != NULL; l = l->next) {
822
        GMount *mount = G_MOUNT (l->data);
823
824
        if (g_mount_is_shadowed (mount))
825
            continue;
826
827
        root = g_mount_get_root (mount);
828
        if (g_file_equal (target, root)) {
829
            found = g_object_ref (mount);
830
            break;
831
        }
1459.1.22 by Jeremy Wootten
Merge changes from trunk and resolve conflict
832
787 by am.monkeyd at gmail
PropertiesWindow show device usage when selection contain a folder, for mounted device or root filesystem
833
        g_object_unref (root);
834
    }
835
836
    g_list_free_full (mounts, g_object_unref);
1811.1.1 by Jeremy Wootten
Code clean: tabs, trailing space, headers, comments
837
    g_object_unref (monitor);
787 by am.monkeyd at gmail
PropertiesWindow show device usage when selection contain a folder, for mounted device or root filesystem
838
1811.1.1 by Jeremy Wootten
Code clean: tabs, trailing space, headers, comments
839
    return found;
787 by am.monkeyd at gmail
PropertiesWindow show device usage when selection contain a folder, for mounted device or root filesystem
840
}
841
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
842
static GFileInfo *
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
843
gof_file_query_info (GOFFile *file)
266 by am.monkeyd at gmail
thumbnailer via tumblermonitor file_changetoolbar-primary-css-style bool dconf key
844
{
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
845
    GFileInfo *info = NULL;
266 by am.monkeyd at gmail
thumbnailer via tumblermonitor file_changetoolbar-primary-css-style bool dconf key
846
    GError *err = NULL;
847
1643.2.41 by jeremy at elementaryos
Synchronise windows showing remote folder when changed by create, delete or rename operations
848
    g_return_val_if_fail (G_IS_FILE (file->location), NULL);
849
2033.1.1 by Jeremy Wootten
Separate creation and loading of directory; simplify
850
    file->is_mounted = TRUE;
851
    file->exists = TRUE;
852
    file->is_connected = TRUE;
853
1643.2.14 by jeremy at elementaryos
Remove debugging code, fix formatting
854
    info = g_file_query_info (file->location, "*", 0, NULL, &err);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
855
266 by am.monkeyd at gmail
thumbnailer via tumblermonitor file_changetoolbar-primary-css-style bool dconf key
856
    if (err != NULL) {
443 by am.monkeyd at gmail
fixing monitoring bugs files should now appear/dissapear correctly thumbnailed or not
857
        if (err->domain == G_IO_ERROR && err->code == G_IO_ERROR_NOT_MOUNTED) {
266 by am.monkeyd at gmail
thumbnailer via tumblermonitor file_changetoolbar-primary-css-style bool dconf key
858
            file->is_mounted = FALSE;
1643.2.5 by jeremy at elementaryos
Fix password dialog
859
        } else if (err->code == G_IO_ERROR_NOT_FOUND
443 by am.monkeyd at gmail
fixing monitoring bugs files should now appear/dissapear correctly thumbnailed or not
860
            || err->code == G_IO_ERROR_NOT_DIRECTORY) {
861
            file->exists = FALSE;
1643.2.19 by jeremy at elementaryos
Fix pathbar regression, clear cached files when reloading so remote directories refresh properly
862
        } else if (err->code == G_IO_ERROR_TIMED_OUT) {
863
            file->is_connected = FALSE;
864
        }
865
866
        print_error (err); /* also frees error */
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
867
    }
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
868
    return info;
570 by am.monkeyd at gmail
restore thumb updates, code cleanup/optimisation
869
}
870
604.1.24 by am.monkeyd at gmail
caches checked. places ensure file_info. update tests
871
/* query info and update. This call is synchronous */
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
872
void
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
873
gof_file_query_update (GOFFile *file)
570 by am.monkeyd at gmail
restore thumb updates, code cleanup/optimisation
874
{
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
875
    GFileInfo *info = NULL;
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
876
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
877
    if ((info = gof_file_query_info (file)) != NULL) {
770 by am.monkeyd at gmail
_g_object_unref0 insanities, check all & replace
878
        g_clear_object (&file->info);
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
879
        file->info = info;
443 by am.monkeyd at gmail
fixing monitoring bugs files should now appear/dissapear correctly thumbnailed or not
880
        gof_file_update (file);
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
881
    }
570 by am.monkeyd at gmail
restore thumb updates, code cleanup/optimisation
882
}
883
604.1.24 by am.monkeyd at gmail
caches checked. places ensure file_info. update tests
884
/* ensure we got the file info */
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
885
gboolean
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
886
gof_file_ensure_query_info (GOFFile *file)
604.1.24 by am.monkeyd at gmail
caches checked. places ensure file_info. update tests
887
{
1424.1.5 by Jeremy Wootten
Sort and group templates in menulist
888
    if (file->info == NULL)
604.1.24 by am.monkeyd at gmail
caches checked. places ensure file_info. update tests
889
        gof_file_query_update (file);
890
891
    return (file->info != NULL);
892
}
893
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
894
/* only the thumbnail has changed (been generated) */
895
void
649 by am.monkeyd at gmail
gof_file_update_icon_internal update icon for thumb state ready
896
gof_file_query_thumbnail_update (GOFFile *file)
570 by am.monkeyd at gmail
restore thumb updates, code cleanup/optimisation
897
{
760 by am.monkeyd at gmail
goffile thumbs don't use query file_info again to get the thumb path but use the md5 filename when thumb state is ready. avoid requesting thumbs to tumbler for already known thumbs path, mark files with THUMB_STATE_READY.
898
    gchar    *base_name;
899
    gchar    *md5_hash;
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
900
1459.1.187 by jeremy at elementaryos
Improve cancelling of timeouts etc before view or path change; suppress errors due to invalid pixbuf size and null cache lookup
901
    /* Silently ignore invalid requests */
1459.1.202 by jeremy at elementaryos
Ensure gof_file_icon_update_internal is not called with invalid pix_size
902
    if (file->pix_size <= 1)
1459.1.187 by jeremy at elementaryos
Improve cancelling of timeouts etc before view or path change; suppress errors due to invalid pixbuf size and null cache lookup
903
        return;
904
760 by am.monkeyd at gmail
goffile thumbs don't use query file_info again to get the thumb path but use the md5 filename when thumb state is ready. avoid requesting thumbs to tumbler for already known thumbs path, mark files with THUMB_STATE_READY.
905
    if (gof_file_get_thumbnail_path (file) == NULL) {
906
        /* get the thumbnail path from md5 filename */
907
        md5_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, file->uri, -1);
908
        base_name = g_strdup_printf ("%s.png", md5_hash);
2056.1.1 by jeremy at elementaryos
Ensure new thumbnails are displayed, do not try to thumbnail when unnecessary
909
910
        /* Use $XDG_CACHE_HOME specified thumbnail directory instead of hard coding */
1922.1.7 by Jeremy Wootten
Change switch point to between 128px and 192px
911
        if (file->pix_size <= 128) {
2056.1.1 by jeremy at elementaryos
Ensure new thumbnails are displayed, do not try to thumbnail when unnecessary
912
            file->thumbnail_path = g_build_filename (g_get_user_cache_dir (), "thumbnails",
1922.1.2 by Jeremy Wootten
Load large thumbnails for icon-size >= 128px
913
                                                     "normal", base_name, NULL);
914
        } else {
2056.1.1 by jeremy at elementaryos
Ensure new thumbnails are displayed, do not try to thumbnail when unnecessary
915
            file->thumbnail_path = g_build_filename (g_get_user_cache_dir (), "thumbnails",
1922.1.2 by Jeremy Wootten
Load large thumbnails for icon-size >= 128px
916
                                                     "large", base_name, NULL);
917
        }
760 by am.monkeyd at gmail
goffile thumbs don't use query file_info again to get the thumb path but use the md5 filename when thumb state is ready. avoid requesting thumbs to tumbler for already known thumbs path, mark files with THUMB_STATE_READY.
918
        g_free (base_name);
919
        g_free (md5_hash);
649 by am.monkeyd at gmail
gof_file_update_icon_internal update icon for thumb state ready
920
    }
1459.1.187 by jeremy at elementaryos
Improve cancelling of timeouts etc before view or path change; suppress errors due to invalid pixbuf size and null cache lookup
921
760 by am.monkeyd at gmail
goffile thumbs don't use query file_info again to get the thumb path but use the md5 filename when thumb state is ready. avoid requesting thumbs to tumbler for already known thumbs path, mark files with THUMB_STATE_READY.
922
    gof_file_update_icon_internal (file, file->pix_size);
160 by am.monkeyd at gmail
gof-file gof-directory refont
923
}
924
925
void gof_file_update_trash_info (GOFFile *file)
926
{
156 by am.monkeyd at gmail
genmarshal + trash / delete / restore actions
927
    GTimeVal g_trash_time;
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
928
    const char * time_string;
156 by am.monkeyd at gmail
genmarshal + trash / delete / restore actions
929
160 by am.monkeyd at gmail
gof-file gof-directory refont
930
    g_return_if_fail (file->info != NULL);
931
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
932
    file->trash_time = 0;
160 by am.monkeyd at gmail
gof-file gof-directory refont
933
    time_string = g_file_info_get_attribute_string (file->info, "trash::deletion-date");
156 by am.monkeyd at gmail
genmarshal + trash / delete / restore actions
934
    if (time_string != NULL) {
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
935
        g_time_val_from_iso8601 (time_string, &g_trash_time);
936
        file->trash_time = g_trash_time.tv_sec;
156 by am.monkeyd at gmail
genmarshal + trash / delete / restore actions
937
    }
1 by am.monkeyd at gmail
let's roll
938
}
939
604.1.16 by am.monkeyd at gmail
more cleanp. add remove from cache(s)
940
void gof_file_remove_from_caches (GOFFile *file)
941
{
942
    /* remove from file_cache */
691 by am.monkeyd at gmail
gof-directory-async file added monitor, add to hash cache earlier, fix potential crash. goffile gof_file_get_display_name fallback on basename.
943
    if (file_cache != NULL && g_hash_table_remove (file_cache, file->location))
604.1.24 by am.monkeyd at gmail
caches checked. places ensure file_info. update tests
944
        g_debug ("remove from file_cache %s", file->uri);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
945
604.1.16 by am.monkeyd at gmail
more cleanp. add remove from cache(s)
946
    /* remove from directory_cache */
771 by am.monkeyd at gmail
marlin-icon-renderer drop all unused
947
    if (file->directory && G_OBJECT (file->directory)->ref_count > 0) {
1504.1.1 by jeremy at elementaryos
Prevent multiple simultaneous thumbnail threads, restrict access to Async directory functions, guard directory cache with mutex, set maximum windows and tabs
948
        gof_directory_async_remove_file_from_cache (file);
604.1.24 by am.monkeyd at gmail
caches checked. places ensure file_info. update tests
949
    }
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
950
694 by am.monkeyd at gmail
gof-directory-async remove hidden_file_hash as it introduce more complexity than what it's really used for. don't add to the model files removed from caches (marked with is_gone), which gonna be destroyed
951
    file->is_gone = TRUE;
604.1.16 by am.monkeyd at gmail
more cleanp. add remove from cache(s)
952
}
953
128 by am.monkeyd at gmail
bookmark use goffile - goffile object exist for unmounted locations (doesn't return null) - small fixs: location entry use utf8 string get_parse_name, don't reload an unchanged path
954
static void gof_file_init (GOFFile *file) {
737 by am.monkeyd at gmail
libcore use a static GOFPreferences object, free libcore from gsetting, bind GOFPreferences with gsettings outside of libcore in marlin-application. gof_file_get_formated_time implement date-format pref.
955
    /*file->priv = G_TYPE_INSTANCE_GET_PRIVATE (file, GOF_TYPE_FILE, GOFFilePrivate);*/
956
128 by am.monkeyd at gmail
bookmark use goffile - goffile object exist for unmounted locations (doesn't return null) - small fixs: location entry use utf8 string get_parse_name, don't reload an unchanged path
957
    file->info = NULL;
958
    file->location = NULL;
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
959
    file->target_location = NULL;
128 by am.monkeyd at gmail
bookmark use goffile - goffile object exist for unmounted locations (doesn't return null) - small fixs: location entry use utf8 string get_parse_name, don't reload an unchanged path
960
    file->icon = NULL;
961
    file->pix = NULL;
748 by am.monkeyd at gmail
adding ctags core plugin, content-type detection, color ...
962
    file->color = 0;
2044.2.1 by Jeremy Wootten
Limit time spent loading resolution in OverlayBar; remember results; skip .JP2
963
    file->width = 0;
964
    file->height = 0;
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
965
966
    file->utf8_collation_key = NULL;
967
    file->formated_type = NULL;
968
    file->format_size = NULL;
969
    file->formated_modified = NULL;
283 by am.monkeyd at gmail
fix bug nullify object after g_free for reuse
970
    file->custom_display_name = NULL;
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
971
    file->custom_icon_name = NULL;
972
    file->owner = NULL;
973
    file->group = NULL;
128 by am.monkeyd at gmail
bookmark use goffile - goffile object exist for unmounted locations (doesn't return null) - small fixs: location entry use utf8 string get_parse_name, don't reload an unchanged path
974
975
    /* assume the file is mounted by default */
976
    file->is_mounted = TRUE;
438 by am.monkeyd at gmail
detach DirectoryNotFound welcome screen from fm-directory-view
977
    file->exists = TRUE;
1643.2.19 by jeremy at elementaryos
Fix pathbar regression, clear cached files when reloading so remote directories refresh properly
978
    file->is_connected = TRUE;
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
979
2056.1.1 by jeremy at elementaryos
Ensure new thumbnails are displayed, do not try to thumbnail when unnecessary
980
    file->flags = GOF_FILE_THUMB_STATE_UNKNOWN;
648 by am.monkeyd at gmail
- gof_file get icon code refactoring, fix mem leaks.
981
    file->pix_size = -1;
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
982
755 by am.monkeyd at gmail
goffile file info const start cleanup
983
    file->target_gof = NULL;
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
984
    file->thumbnail_path = NULL;
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
985
697 by am.monkeyd at gmail
Bug #896573 Folder file sorting selected by user is not recorded
986
    file->sort_column_id = FM_LIST_MODEL_FILENAME;
987
    file->sort_order = GTK_SORT_ASCENDING;
1459.1.124 by jeremy at elementaryos
Show folder-open icon for expanded folders in list view
988
989
    file->is_expanded = FALSE;
1 by am.monkeyd at gmail
let's roll
990
}
991
992
static void gof_file_finalize (GObject* obj) {
1785.2.4 by cmm2
Fix owner:group string memory leak in gof_file_finalize.
993
    //g_debug ("%s: delete %p", __func__, obj);
994
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
995
    GOFFile *file;
996
997
    file = GOF_FILE (obj);
798.3.15 by xapantu
Pressed state for breadcrumbs, BreadcrumbsElement drawing code needs a diagram. Remove some debug code (gof_finalize), which slowed my computer a bit (printing more than 100 lines to a terminal at once is not super fast)
998
#if 0
763 by am.monkeyd at gmail
memory enhancements, use toggle ref on our caches hashtables from gof-directory-async & marlin-icon-info. check refcounts, unload files and icon pixbuf from memory.
999
    if (file->pix)
1000
        g_warning ("%s %s %u\n", G_STRFUNC, file->uri, G_OBJECT (file->pix)->ref_count);
770 by am.monkeyd at gmail
_g_object_unref0 insanities, check all & replace
1001
    else
1002
        g_warning ("%s %s", G_STRFUNC, file->basename);
798.3.15 by xapantu
Pressed state for breadcrumbs, BreadcrumbsElement drawing code needs a diagram. Remove some debug code (gof_finalize), which slowed my computer a bit (printing more than 100 lines to a terminal at once is not super fast)
1003
#endif
2033.3.1 by jeremy at elementaryos
Fix rename; fix reload multiple slots
1004
    if (!(G_IS_FILE (file->location))) {
1005
        g_warning ("Invalid file location on finalize for %s", file->basename);
1006
    } else {
1007
        g_object_unref (file->location);
1008
    }
770 by am.monkeyd at gmail
_g_object_unref0 insanities, check all & replace
1009
    g_clear_object (&file->info);
1643.2.41 by jeremy at elementaryos
Synchronise windows showing remote folder when changed by create, delete or rename operations
1010
    _g_object_unref0 (file->directory);
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
1011
    _g_free0 (file->uri);
1012
    _g_free0(file->basename);
1013
    _g_free0(file->utf8_collation_key);
1014
    _g_free0(file->formated_type);
1015
    _g_free0(file->format_size);
1016
    _g_free0(file->formated_modified);
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1017
    _g_object_unref0 (file->icon);
1643.2.41 by jeremy at elementaryos
Synchronise windows showing remote folder when changed by create, delete or rename operations
1018
    _g_object_unref0 (file->pix);
770 by am.monkeyd at gmail
_g_object_unref0 insanities, check all & replace
1019
    //g_clear_object (&file->pix);
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1020
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
1021
    _g_free0 (file->custom_display_name);
1022
    _g_free0 (file->custom_icon_name);
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
1023
787 by am.monkeyd at gmail
PropertiesWindow show device usage when selection contain a folder, for mounted device or root filesystem
1024
    _g_object_unref0 (file->target_location);
1025
    _g_object_unref0 (file->mount);
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
1026
    /* TODO remove the target_gof */
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
1027
    _g_free0 (file->thumbnail_path);
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
1028
1930.1.1 by Jeremy Wootten
Unref non-null target_gof on finalize
1029
    if (file->target_gof != NULL) {
1030
        _g_object_unref0 (file->target_gof);
1031
    }
1032
1785.2.4 by cmm2
Fix owner:group string memory leak in gof_file_finalize.
1033
#ifndef NDEBUG
1034
    g_warn_if_fail (file->target_gof == NULL);
1035
#endif
1036
1037
    _g_free0 (file->owner);
1038
    _g_free0 (file->group);
1039
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1040
    G_OBJECT_CLASS (gof_file_parent_class)->finalize (obj);
1 by am.monkeyd at gmail
let's roll
1041
}
1042
1043
static void gof_file_class_init (GOFFileClass * klass) {
122.1.1 by am.monkeyd at gmail
drag&drop
1044
1045
    /* determine the effective user id of the process */
1046
    effective_user_id = geteuid ();
1047
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1048
    gof_file_parent_class = g_type_class_peek_parent (klass);
1049
    //g_type_class_add_private (klass, sizeof (GOFFilePrivate));
1050
    /*G_OBJECT_CLASS (klass)->get_property = gof_file_get_property;
1051
      G_OBJECT_CLASS (klass)->set_property = gof_file_set_property;*/
1052
    G_OBJECT_CLASS (klass)->finalize = gof_file_finalize;
106.1.1 by am.monkeyd at gmail
copy/cut/paste + merge_menus + some file_operations
1053
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
1054
    signals[CHANGED] = g_signal_new ("changed",
1811.1.1 by Jeremy Wootten
Code clean: tabs, trailing space, headers, comments
1055
                                     G_TYPE_FROM_CLASS (klass),
1056
                                     G_SIGNAL_RUN_LAST,
1057
                                     G_STRUCT_OFFSET (GOFFileClass, changed),
1058
                                     NULL, NULL,
1059
                                     g_cclosure_marshal_VOID__VOID,
1060
                                     G_TYPE_NONE, 0);
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
1061
1062
    signals[DESTROY] = g_signal_new ("destroy",
1811.1.1 by Jeremy Wootten
Code clean: tabs, trailing space, headers, comments
1063
                                     G_TYPE_FROM_CLASS (klass),
1064
                                     G_SIGNAL_RUN_LAST,
1065
                                     G_STRUCT_OFFSET (GOFFileClass, destroy),
1066
                                     NULL, NULL,
1067
                                     g_cclosure_marshal_VOID__VOID,
1068
                                     G_TYPE_NONE, 0);
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
1069
1070
604.1.18 by am.monkeyd at gmail
reconnect info_available signal move it to goffile lvl
1071
    signals[INFO_AVAILABLE] = g_signal_new ("info_available",
1811.1.1 by Jeremy Wootten
Code clean: tabs, trailing space, headers, comments
1072
                                             G_TYPE_FROM_CLASS (klass),
1073
                                             G_SIGNAL_RUN_LAST,
1074
                                             G_STRUCT_OFFSET (GOFFileClass, info_available),
1075
                                             NULL, NULL,
1076
                                             g_cclosure_marshal_VOID__VOID,
1077
                                             G_TYPE_NONE, 0);
604.1.18 by am.monkeyd at gmail
reconnect info_available signal move it to goffile lvl
1078
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
1079
    signals[ICON_CHANGED] = g_signal_new ("icon_changed",
1811.1.1 by Jeremy Wootten
Code clean: tabs, trailing space, headers, comments
1080
                                          G_TYPE_FROM_CLASS (klass),
1081
                                          G_SIGNAL_RUN_LAST,
1082
                                          G_STRUCT_OFFSET (GOFFileClass, icon_changed),
1083
                                          NULL, NULL,
1084
                                          g_cclosure_marshal_VOID__VOID,
1085
                                          G_TYPE_NONE, 0);
106.1.1 by am.monkeyd at gmail
copy/cut/paste + merge_menus + some file_operations
1086
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1087
    /*g_object_class_install_property (G_OBJECT_CLASS (klass), gof_FILE_NAME, g_param_spec_string ("name", "name", "name", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
1088
      g_object_class_install_property (G_OBJECT_CLASS (klass), gof_FILE_SIZE, g_param_spec_uint64 ("size", "size", "size", 0, G_MAXUINT64, 0U, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
1089
      g_object_class_install_property (G_OBJECT_CLASS (klass), gof_FILE_DIRECTORY, g_param_spec_boolean ("directory", "directory", "directory", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));*/
1 by am.monkeyd at gmail
let's roll
1090
}
1091
1092
1093
#if 0
1094
static void gof_file_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1095
    GOFFile * self;
1096
    self = GOF_FILE (object);
1097
    switch (property_id) {
1098
    case gof_FILE_NAME:
1099
        g_value_set_string (value, gof_file_get_name (self));
1100
        break;
1101
    case gof_FILE_SIZE:
1102
        g_value_set_uint64 (value, gof_file_get_size (self));
1103
        break;
1104
    case gof_FILE_DIRECTORY:
1105
        g_value_set_boolean (value, gof_file_get_directory (self));
1106
        break;
1107
    default:
1108
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1109
        break;
1110
    }
1 by am.monkeyd at gmail
let's roll
1111
}
1112
1113
1114
static void gof_file_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1115
    GOFFile * self;
1116
    self = GOF_FILE (object);
1117
    switch (property_id) {
1118
    default:
1119
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1120
        break;
1121
    }
1 by am.monkeyd at gmail
let's roll
1122
}
1123
#endif
1124
1125
static int
1126
compare_files_by_time (GOFFile *file1, GOFFile *file2)
1127
{
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1128
    if (file1->modified < file2->modified)
1129
        return -1;
1130
    else if (file1->modified > file2->modified)
1131
        return 1;
1 by am.monkeyd at gmail
let's roll
1132
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1133
    return 0;
1 by am.monkeyd at gmail
let's roll
1134
}
1135
1136
static int
1137
compare_by_time (GOFFile *file1, GOFFile *file2)
1138
{
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1139
    if (gof_file_is_folder (file1) && !gof_file_is_folder (file2))
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1140
        return -1;
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1141
    if (gof_file_is_folder (file2) && !gof_file_is_folder (file1))
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1142
        return 1;
1 by am.monkeyd at gmail
let's roll
1143
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1144
    return compare_files_by_time (file1, file2);
1 by am.monkeyd at gmail
let's roll
1145
}
1146
1147
static int
1148
compare_by_type (GOFFile *file1, GOFFile *file2)
1149
{
653 by am.monkeyd at gmail
fix Bug #798468 Marlin sorts numbered folder names incorrectly. fix compare_by_display_name and compare_by_type
1150
    gchar *key1, *key2;
1151
    int compare;
1152
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1153
    /* Directories go first. Then, if mime types are identical,
1154
     * don't bother getting strings (for speed). This assumes
1155
     * that the string is dependent entirely on the mime type,
1156
     * which is true now but might not be later.
1157
     */
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1158
    if (gof_file_is_folder (file1) && gof_file_is_folder (file2))
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1159
        return 0;
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
1160
    if (gof_file_is_folder (file1))
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1161
        return -1;
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
1162
    if (gof_file_is_folder (file2))
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1163
        return +1;
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
1164
653 by am.monkeyd at gmail
fix Bug #798468 Marlin sorts numbered folder names incorrectly. fix compare_by_display_name and compare_by_type
1165
    key1 = g_utf8_collate_key (file1->formated_type, -1);
1166
    key2 = g_utf8_collate_key (file2->formated_type, -1);
1167
    compare = g_strcmp0 (key1, key2);
1168
    g_free (key1);
1169
    g_free (key2);
1170
1171
    return compare;
1 by am.monkeyd at gmail
let's roll
1172
}
1173
1174
static int
1175
compare_by_display_name (GOFFile *file1, GOFFile *file2)
1176
{
798.3.14 by xapantu
Add more checks in gof-file and fm-list-model functions (return if not valid goffile for instace) and fix a bug with the pathbar: need_completion reloads the current directory, so, it caused a problem with backspace because it moved to parent and did need_completion: two directory loaded at the same moment -> weird problems
1177
    g_return_val_if_fail (GOF_IS_FILE (file1), -1);
1178
    g_return_val_if_fail (GOF_IS_FILE (file2), -1);
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1179
    const char *name_1, *name_2;
1180
    gboolean sort_last_1, sort_last_2;
1181
    int compare;
1182
666 by am.monkeyd at gmail
use display_name in the FILENAME column model and not name
1183
    name_1 = gof_file_get_display_name (file1);
1184
    name_2 = gof_file_get_display_name (file2);
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1185
1186
    sort_last_1 = name_1[0] == SORT_LAST_CHAR1 || name_1[0] == SORT_LAST_CHAR2;
1187
    sort_last_2 = name_2[0] == SORT_LAST_CHAR1 || name_2[0] == SORT_LAST_CHAR2;
1188
1189
    if (sort_last_1 && !sort_last_2) {
1190
        compare = +1;
1191
    } else if (!sort_last_1 && sort_last_2) {
1192
        compare = -1;
1193
    } else {
604.1.14 by am.monkeyd at gmail
start to monitor
1194
        compare = g_strcmp0 (file1->utf8_collation_key, file2->utf8_collation_key);
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1195
    }
1196
1197
    return compare;
1 by am.monkeyd at gmail
let's roll
1198
}
1199
1200
static int
1201
compare_files_by_size (GOFFile *file1, GOFFile *file2)
1202
{
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1203
    if (file1->size < file2->size) {
1204
        return -1;
1205
    }
1206
    else if (file1->size > file2->size) {
1207
        return 1;
1208
    }
1 by am.monkeyd at gmail
let's roll
1209
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1210
    return 0;
1 by am.monkeyd at gmail
let's roll
1211
}
1212
1213
static int
1214
compare_by_size (GOFFile *file1, GOFFile *file2)
1215
{
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1216
    if (gof_file_is_folder (file1) && !gof_file_is_folder (file2))
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1217
        return -1;
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1218
    if (gof_file_is_folder (file2) && !gof_file_is_folder (file1))
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1219
        return 1;
1 by am.monkeyd at gmail
let's roll
1220
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1221
    return compare_files_by_size (file1, file2);
1 by am.monkeyd at gmail
let's roll
1222
}
1223
1224
static int
1225
gof_file_compare_for_sort_internal (GOFFile *file1,
1226
                                    GOFFile *file2,
1227
                                    gboolean directories_first,
1228
                                    gboolean reversed)
1229
{
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1230
    if (directories_first) {
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1231
        if (gof_file_is_folder (file1) && !gof_file_is_folder (file2))
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1232
            return -1;
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1233
        if (gof_file_is_folder (file2) && !gof_file_is_folder (file1))
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1234
            return 1;
1235
    }
1236
1237
    /*if (file1->details->sort_order < file2->details->sort_order) {
1238
      return reversed ? 1 : -1;
1239
      } else if (file_1->details->sort_order > file_2->details->sort_order) {
1240
      return reversed ? -1 : 1;
1241
      }*/
1242
1243
    return 0;
1 by am.monkeyd at gmail
let's roll
1244
}
1245
1246
int
1247
gof_file_compare_for_sort (GOFFile *file1,
1248
                           GOFFile *file2,
1249
                           gint sort_type,
1250
                           gboolean directories_first,
1251
                           gboolean reversed)
1252
{
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1253
    int result;
1254
1255
    if (file1 == file2) {
1256
        return 0;
1257
    }
1258
1259
    result = gof_file_compare_for_sort_internal (file1, file2, directories_first, reversed);
1260
1261
    if (result == 0) {
1262
        switch (sort_type) {
1263
        case FM_LIST_MODEL_FILENAME:
1264
            result = compare_by_display_name (file1, file2);
1265
            /*if (result == 0) {
1266
              result = compare_by_directory_name (file_1, file_2);
1267
              }*/
1268
            break;
1269
        case FM_LIST_MODEL_SIZE:
1270
            result = compare_by_size (file1, file2);
1517 by xapantu
Sort files by name once they are sorted by type, modified or size to fix bug #1083102
1271
            if (result == 0) {
1272
                result = compare_by_display_name (file1, file2);
1273
            }
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1274
            break;
1275
        case FM_LIST_MODEL_TYPE:
1276
            result = compare_by_type (file1, file2);
1517 by xapantu
Sort files by name once they are sorted by type, modified or size to fix bug #1083102
1277
            if (result == 0) {
1278
                result = compare_by_display_name (file1, file2);
1279
            }
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1280
            break;
1281
        case FM_LIST_MODEL_MODIFIED:
1282
            result = compare_by_time (file1, file2);
1517 by xapantu
Sort files by name once they are sorted by type, modified or size to fix bug #1083102
1283
            if (result == 0) {
1284
                result = compare_by_display_name (file1, file2);
1285
            }
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1286
            break;
1287
        }
1288
1289
        if (reversed) {
1290
            result = -result;
1291
        }
1292
    }
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1293
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1294
    return result;
1 by am.monkeyd at gmail
let's roll
1295
}
1296
1297
GOFFile *
1298
gof_file_ref (GOFFile *file)
1299
{
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1300
    if (file == NULL) {
1301
        return NULL;
1302
    }
1303
    g_return_val_if_fail (GOF_IS_FILE (file), NULL);
1 by am.monkeyd at gmail
let's roll
1304
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1305
    return g_object_ref (file);
1 by am.monkeyd at gmail
let's roll
1306
}
1307
1308
void
1309
gof_file_unref (GOFFile *file)
1310
{
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
1311
    if (file == NULL) {
1312
        return;
1313
    }
1314
1315
    g_return_if_fail (GOF_IS_FILE (file));
1316
1317
    g_object_unref (file);
1 by am.monkeyd at gmail
let's roll
1318
}
1319
585 by am.monkeyd at gmail
OpenWith (sub)menus refactoring. available from menubar too. more tradtional menus
1320
GList *
1321
gof_files_get_location_list (GList *files)
1322
{
1323
    GList *gfile_list = NULL;
1324
    GList *l;
1325
    GOFFile *file;
1326
1327
    for (l=files; l != NULL; l=l->next) {
1328
        file = (GOFFile *) l->data;
1329
        if (file != NULL && file->location != NULL) {
1330
            gfile_list = g_list_prepend (gfile_list, eel_g_file_ref (file->location));
1331
        }
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1332
    }
585 by am.monkeyd at gmail
OpenWith (sub)menus refactoring. available from menubar too. more tradtional menus
1333
    //gfile_list = g_list_reverse (gfile_list);
1334
1335
    return (gfile_list);
1336
}
1337
106.1.2 by am.monkeyd at gmail
file_operations mount/unmount copy/move
1338
1339
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1340
/**
1341
 * gof_file_is_writable: impoted from thunar
1342
 * @file : a #GOFFile instance.
1343
 *
1344
 * Determines whether the owner of the current process is allowed
1345
 * to write the @file.
1346
 *
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
1347
 * Return value: %TRUE if @file can be written.
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
1348
**/
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1349
gboolean
1350
gof_file_is_writable (GOFFile *file)
1351
{
1352
    g_return_val_if_fail (GOF_IS_FILE (file), FALSE);
2257.4.4 by Jeremy Wootten
Determine writability the same way as readability; correctly test non-null info before info_has_attribute ()
1353
    if (file->target_gof && !g_file_equal (file->location, file->target_gof->location)) {
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
1354
        return gof_file_is_writable (file->target_gof);
2257.4.4 by Jeremy Wootten
Determine writability the same way as readability; correctly test non-null info before info_has_attribute ()
1355
    } else if (file->info != NULL && g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
1356
        return g_file_info_get_attribute_boolean (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
1357
    } else if (file->has_permissions) {
2357.1.1 by Jeremy Wootten
Correctly determine write permissions for ftp files
1358
        return ((file->permissions & S_IWOTH) > 0) ||
2357.1.2 by Jeremy Wootten
Use effective uid to determine writability, correctly determine default drop action on ftp
1359
               ((file->permissions & S_IWUSR) > 0) && (file->uid < 0 || file->uid == geteuid ()) ||
2357.1.1 by Jeremy Wootten
Correctly determine write permissions for ftp files
1360
               ((file->permissions & S_IWGRP) > 0) && eel_user_in_group (file->group);
2257.4.4 by Jeremy Wootten
Determine writability the same way as readability; correctly test non-null info before info_has_attribute ()
1361
    } else {
1362
        return TRUE;  /* We will just have to assume we can write to the file */
1081.1.1 by Julián Unrrein
Force the trash folder to be recognised as writable. Fixes bug #1005270
1363
    }
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1364
2300.2.1 by Jeremy Wootten
Emblem on unexecutable folders, fix file size and modified in unexecutable folders
1365
    gboolean can_write = g_file_info_get_attribute_boolean (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
1366
1367
    if (file->directory && g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE)) {
1368
        return can_write && g_file_info_get_attribute_boolean (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE);
1369
    }
1370
1371
    return can_write;
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1372
}
1373
1374
gboolean
1615.1.1 by jeremy at elementaryos
Display readonly and unreadable emblems when appropriate
1375
gof_file_is_readable (GOFFile *file)
1376
{
1377
    g_return_val_if_fail (GOF_IS_FILE (file), FALSE);
1378
2252.1.1 by Jeremy Wootten
check file permissions in gof_file_is_readable (); return true if cannot determine
1379
    if (file->target_gof && !g_file_equal (file->location, file->target_gof->location)) {
1380
        return gof_file_is_readable (file->target_gof);
2257.4.4 by Jeremy Wootten
Determine writability the same way as readability; correctly test non-null info before info_has_attribute ()
1381
    } else if (file->info != NULL && g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ)) {
2252.1.1 by Jeremy Wootten
check file permissions in gof_file_is_readable (); return true if cannot determine
1382
        return g_file_info_get_attribute_boolean (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ);
1383
    } else if (file->has_permissions) {
2257.4.5 by Jeremy Wootten
Do not show Paste into Folder for files; only paste into trash for cut files; check user and user group against file permissions for readability and writability
1384
        return (file->permissions & S_IROTH) ||
2357.1.2 by Jeremy Wootten
Use effective uid to determine writability, correctly determine default drop action on ftp
1385
               (file->permissions & S_IRUSR) && (file->uid < 0 || file->uid == geteuid ()) ||
2257.4.5 by Jeremy Wootten
Do not show Paste into Folder for files; only paste into trash for cut files; check user and user group against file permissions for readability and writability
1386
               (file->permissions & S_IRGRP) && eel_user_in_group (file->group);
2253 by Jeremy Wootten
Assume file is readable if gof_file_is_readable () cannot determine so (lp:1601841)
1387
    } else {
2252.1.1 by Jeremy Wootten
check file permissions in gof_file_is_readable (); return true if cannot determine
1388
        return TRUE;  /* We will just have to assume we can read the file */
1389
    }
1615.1.1 by jeremy at elementaryos
Display readonly and unreadable emblems when appropriate
1390
}
1391
1392
gboolean
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1393
gof_file_is_trashed (GOFFile *file)
1394
{
126 by am.monkeyd at gmail
using icons & display_name from .desktop files /usr/share/applications looks ok now
1395
    g_return_val_if_fail (GOF_IS_FILE (file), FALSE);
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
1396
    return eel_g_file_is_trashed (gof_file_get_target_location (file));
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1397
}
1398
132 by am.monkeyd at gmail
follow symlink + formated_type
1399
const gchar *
1400
gof_file_get_symlink_target (GOFFile *file)
1401
{
1402
    g_return_val_if_fail (GOF_IS_FILE (file), NULL);
1403
1404
    if (file->info == NULL)
1405
        return NULL;
1406
1407
    return g_file_info_get_symlink_target (file->info);
1408
}
1409
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1410
gboolean
1411
gof_file_is_symlink (GOFFile *file)
132 by am.monkeyd at gmail
follow symlink + formated_type
1412
{
1413
    g_return_val_if_fail (GOF_IS_FILE (file), FALSE);
1414
1415
    if (file->info == NULL)
1416
        return FALSE;
1417
1418
    return g_file_info_get_is_symlink (file->info);
1419
}
1420
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1421
gchar *
597.1.3 by am.monkeyd at gmail
use_wrap_label
1422
gof_file_get_formated_time (GOFFile *file, const char *attr)
1423
{
1424
    g_return_val_if_fail (file != NULL, NULL);
1425
    g_return_val_if_fail (file->info != NULL, NULL);
1426
2052.2.1 by jeremy at elementaryos
Amend formatting of dates; show properties of trashed files
1427
    return pf_file_utils_get_formatted_time_attribute_from_info (file->info,
1428
                                                                 attr,
1429
                                                                 gof_preferences_get_default ()->pref_date_format);
597.1.3 by am.monkeyd at gmail
use_wrap_label
1430
}
1431
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1432
1433
/**
1434
 * gof_file_is_desktop_file: imported from thunar
1435
 * @file : a #GOFFile.
1436
 *
1437
 * Returns %TRUE if @file is a .desktop file, but not a .directory file.
1438
 *
1439
 * Return value: %TRUE if @file is a .desktop file.
1440
**/
1441
gboolean
604.1.4 by am.monkeyd at gmail
gof-directory-async.vala
1442
gof_file_is_desktop_file (GOFFile *file)
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1443
{
1444
    const gchar *content_type;
1445
    gboolean     is_desktop_file = FALSE;
1446
1447
    g_return_val_if_fail (GOF_IS_FILE (file), FALSE);
1448
1449
    if (file->info == NULL)
1450
        return FALSE;
1451
757 by am.monkeyd at gmail
goffile more clean up
1452
    content_type = gof_file_get_ftype (file);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1453
    if (content_type != NULL)
1454
        is_desktop_file = g_content_type_equals (content_type, "application/x-desktop");
1455
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1456
    return is_desktop_file
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1457
        && !g_str_has_suffix (file->basename, ".directory");
1458
}
1459
1460
/**
1461
 * gof_file_is_executable: imported from thunar
1462
 * @file : a #GOFFile instance.
1463
 *
1464
 * Determines whether the owner of the current process is allowed
1465
 * to execute the @file (or enter the directory refered to by
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1466
 * @file). On UNIX it also returns %TRUE if @file refers to a
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1467
 * desktop entry.
1468
 *
1469
 * Return value: %TRUE if @file can be executed.
1470
**/
1471
gboolean
604.1.4 by am.monkeyd at gmail
gof-directory-async.vala
1472
gof_file_is_executable (GOFFile *file)
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1473
{
1474
    gboolean     can_execute = FALSE;
1475
    const gchar *content_type;
1476
1477
    g_return_val_if_fail (GOF_IS_FILE (file), FALSE);
1478
2112.2.1 by jeremy at elementaryos
Check if is desktop file first in gof_file_is_executable ()
1479
    if (gof_file_is_desktop_file (file)) {
1480
        return TRUE;
1481
    }
1482
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
1483
    if (file->target_gof)
1484
        return gof_file_is_executable (file->target_gof);
1459.1.55 by jeremy at elementaryos
commit prior to merging trunk
1485
    if (file->info == NULL) {
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1486
        return FALSE;
1459.1.55 by jeremy at elementaryos
commit prior to merging trunk
1487
    }
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1488
1489
    if (g_file_info_get_attribute_boolean (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE))
1490
    {
1491
        /* get the content type of the file */
757 by am.monkeyd at gmail
goffile more clean up
1492
        content_type = gof_file_get_ftype (file);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1493
        if (G_LIKELY (content_type != NULL))
1494
        {
1495
#ifdef G_OS_WIN32
1496
            /* check for .exe, .bar or .com */
1497
            can_execute = g_content_type_can_be_executable (content_type);
1498
#else
1499
            /* check if the content type is save to execute, we don't use
1500
             * g_content_type_can_be_executable() for unix because it also returns
1501
             * true for "text/plain" and we don't want that */
1502
            if (g_content_type_is_a (content_type, "application/x-executable")
1742.1.1 by jeremy at elementaryos
Do not execute application/octet-stream
1503
                || g_content_type_is_a (content_type, "application/x-shellscript"))
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1504
                can_execute = TRUE;
1505
#endif
106.1.2 by am.monkeyd at gmail
file_operations mount/unmount copy/move
1506
        }
1507
    }
1508
744 by am.monkeyd at gmail
fixing action Open with desktop/executable files
1509
    return can_execute;
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1510
}
1511
266 by am.monkeyd at gmail
thumbnailer via tumblermonitor file_changetoolbar-primary-css-style bool dconf key
1512
/**
1513
 * gof_file_set_thumb_state: imported from thunar
1514
 * @file        : a #GOFFile.
1515
 * @thumb_state : the new #GOFFileThumbState.
1516
 *
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1517
 * Sets the #GOFFileThumbState for @file to @thumb_state.
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
1518
 * This will cause a "icon-changed" signal to be emitted from
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1519
 * #GOFMonitor.
1520
**/
266 by am.monkeyd at gmail
thumbnailer via tumblermonitor file_changetoolbar-primary-css-style bool dconf key
1521
void
1522
gof_file_set_thumb_state (GOFFile *file, GOFFileThumbState state)
130 by am.monkeyd at gmail
make sure to mount dir before enumerating them + sidebar go_to_after_mount_slot + some clean up
1523
{
266 by am.monkeyd at gmail
thumbnailer via tumblermonitor file_changetoolbar-primary-css-style bool dconf key
1524
    g_return_if_fail (GOF_IS_FILE (file));
1525
1526
    /* set the new thumbnail state */
1527
    file->flags = (file->flags & ~GOF_FILE_THUMB_STATE_MASK) | (state);
1459.1.2 by Jeremy Wootten
Refactor FMColumnsView based on FMListView and ExoTreeView - make changes to ViewContainer and other files to enable the new FMColumnsView to function in MarlinWindowColumns without extensive internal changes
1528
    g_debug ("%s %s %u", G_STRFUNC, file->uri, file->flags);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1529
    if (file->flags == GOF_FILE_THUMB_STATE_READY)
570 by am.monkeyd at gmail
restore thumb updates, code cleanup/optimisation
1530
        gof_file_query_thumbnail_update (file);
1531
266 by am.monkeyd at gmail
thumbnailer via tumblermonitor file_changetoolbar-primary-css-style bool dconf key
1532
    /* notify others of this change, so that all components can update
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
1533
     * their file information */
640 by am.monkeyd at gmail
- fix Bug #805339 icon renderer / previews don't update on file change
1534
    gof_file_icon_changed (file);
130 by am.monkeyd at gmail
make sure to mount dir before enumerating them + sidebar go_to_after_mount_slot + some clean up
1535
}
1536
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
1537
GOFFile* gof_file_cache_lookup (GFile *location)
604.1.2 by am.monkeyd at gmail
adding file_cache
1538
{
604.1.24 by am.monkeyd at gmail
caches checked. places ensure file_info. update tests
1539
    GOFFile *cached_file = NULL;
604.1.2 by am.monkeyd at gmail
adding file_cache
1540
1541
    g_return_val_if_fail (G_IS_FILE (location), NULL);
1542
1543
    /* allocate the GOFFile cache on-demand */
1544
    if (G_UNLIKELY (file_cache == NULL))
1545
    {
1546
        G_LOCK (file_cache_mutex);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1547
        file_cache = g_hash_table_new_full (g_file_hash,
1548
                                            (GEqualFunc) g_file_equal,
1549
                                            (GDestroyNotify) g_object_unref,
604.1.24 by am.monkeyd at gmail
caches checked. places ensure file_info. update tests
1550
                                            (GDestroyNotify) g_object_unref);
604.1.2 by am.monkeyd at gmail
adding file_cache
1551
        G_UNLOCK (file_cache_mutex);
1552
    }
604.1.24 by am.monkeyd at gmail
caches checked. places ensure file_info. update tests
1553
    if (file_cache != NULL)
1554
        cached_file = g_hash_table_lookup (file_cache, location);
604.1.2 by am.monkeyd at gmail
adding file_cache
1555
604.1.10 by am.monkeyd at gmail
goffile missing object_ref - bug with bookmarked dir
1556
    return _g_object_ref0 (cached_file);
604.1.2 by am.monkeyd at gmail
adding file_cache
1557
}
106.1.2 by am.monkeyd at gmail
file_operations mount/unmount copy/move
1558
1459.1.124 by jeremy at elementaryos
Show folder-open icon for expanded folders in list view
1559
void
1560
gof_file_set_expanded (GOFFile *file, gboolean expanded) {
1756.1.2 by Geronimo Bareiro
Fix Only goffiles representing a folder can be expanded.
1561
    g_return_if_fail (file != NULL && file->is_directory);
1459.1.124 by jeremy at elementaryos
Show folder-open icon for expanded folders in list view
1562
    file->is_expanded = expanded;
1563
}
1564
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1565
GOFFile*
763 by am.monkeyd at gmail
memory enhancements, use toggle ref on our caches hashtables from gof-directory-async & marlin-icon-info. check refcounts, unload files and icon pixbuf from memory.
1566
gof_file_get (GFile *location)
106.1.2 by am.monkeyd at gmail
file_operations mount/unmount copy/move
1567
{
1568
    GFile *parent;
122.1.6 by am.monkeyd at gmail
new cached files API
1569
    GOFFile *file = NULL;
1570
    GOFDirectoryAsync *dir = NULL;
1571
1459.1.187 by jeremy at elementaryos
Improve cancelling of timeouts etc before view or path change; suppress errors due to invalid pixbuf size and null cache lookup
1572
g_return_val_if_fail (location != NULL && G_IS_FILE (location), NULL);
1811.1.1 by Jeremy Wootten
Code clean: tabs, trailing space, headers, comments
1573
1504.1.1 by jeremy at elementaryos
Prevent multiple simultaneous thumbnail threads, restrict access to Async directory functions, guard directory cache with mutex, set maximum windows and tabs
1574
    if ((parent = g_file_get_parent (location)) != NULL) {
604.1.4 by am.monkeyd at gmail
gof-directory-async.vala
1575
        dir = gof_directory_async_cache_lookup (parent);
1504.1.1 by jeremy at elementaryos
Prevent multiple simultaneous thumbnail threads, restrict access to Async directory functions, guard directory cache with mutex, set maximum windows and tabs
1576
        if (dir != NULL) {
1577
            file = gof_directory_async_file_hash_lookup_location (dir, location);
1578
            g_object_unref (dir);
1579
        }
122.1.6 by am.monkeyd at gmail
new cached files API
1580
    }
1581
1504.1.1 by jeremy at elementaryos
Prevent multiple simultaneous thumbnail threads, restrict access to Async directory functions, guard directory cache with mutex, set maximum windows and tabs
1582
    if (file == NULL)
604.1.2 by am.monkeyd at gmail
adding file_cache
1583
        file = gof_file_cache_lookup (location);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1584
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
1585
    if (file != NULL) {
604.1.24 by am.monkeyd at gmail
caches checked. places ensure file_info. update tests
1586
        g_debug (">>>>reuse file %s", file->uri);
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
1587
    } else {
160 by am.monkeyd at gmail
gof-file gof-directory refont
1588
        file = gof_file_new (location, parent);
604.1.24 by am.monkeyd at gmail
caches checked. places ensure file_info. update tests
1589
        g_debug (">>>>create file %s", file->uri);
604.1.2 by am.monkeyd at gmail
adding file_cache
1590
        G_LOCK (file_cache_mutex);
604.1.16 by am.monkeyd at gmail
more cleanp. add remove from cache(s)
1591
        if (file_cache != NULL)
604.1.24 by am.monkeyd at gmail
caches checked. places ensure file_info. update tests
1592
            g_hash_table_insert (file_cache, g_object_ref (location), g_object_ref (file));
604.1.2 by am.monkeyd at gmail
adding file_cache
1593
        G_UNLOCK (file_cache_mutex);
122.1.6 by am.monkeyd at gmail
new cached files API
1594
    }
438 by am.monkeyd at gmail
detach DirectoryNotFound welcome screen from fm-directory-view
1595
770 by am.monkeyd at gmail
_g_object_unref0 insanities, check all & replace
1596
    if (parent)
1597
        g_object_unref (parent);
604.1.16 by am.monkeyd at gmail
more cleanp. add remove from cache(s)
1598
106.1.2 by am.monkeyd at gmail
file_operations mount/unmount copy/move
1599
    return (file);
1600
}
1601
122.1.1 by am.monkeyd at gmail
drag&drop
1602
GOFFile* gof_file_get_by_uri (const char *uri)
1603
{
1604
    GFile *location;
1605
    GOFFile *file;
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1606
122.1.1 by am.monkeyd at gmail
drag&drop
1607
    location = g_file_new_for_uri (uri);
298 by xapantu
Add unit tests for some gof-file functions, basic GOFFile creation are tested, and symlink functions too
1608
    if(location == NULL)
1609
        return NULL;
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
1610
360 by am.monkeyd at gmail
adding -d debug option, goffile got uri checked all g_file_get_uri debug msg
1611
    file = gof_file_get (location);
298 by xapantu
Add unit tests for some gof-file functions, basic GOFFile creation are tested, and symlink functions too
1612
#ifdef ENABLE_DEBUG
360 by am.monkeyd at gmail
adding -d debug option, goffile got uri checked all g_file_get_uri debug msg
1613
    g_debug ("%s %s", G_STRFUNC, file->uri);
298 by xapantu
Add unit tests for some gof-file functions, basic GOFFile creation are tested, and symlink functions too
1614
#endif
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1615
    g_object_unref (location);
1616
1617
    return file;
1618
}
1619
1620
GOFFile* gof_file_get_by_commandline_arg (const char *arg)
1621
{
1622
    GFile *location;
1623
    GOFFile *file;
1624
1625
    location = g_file_new_for_commandline_arg (arg);
1626
    file = gof_file_get (location);
1627
    g_object_unref (location);
1628
122.1.1 by am.monkeyd at gmail
drag&drop
1629
    return file;
1630
}
1631
506 by xapantu
Some improvements to the plugin system, loading/unloading is not fully live yet, but there is some progress
1632
gchar* gof_file_list_to_string (GList *list, gsize *len)
122.1.1 by am.monkeyd at gmail
drag&drop
1633
{
1634
    GString *string;
1635
    GList   *lp;
1636
1637
    /* allocate initial string */
1638
    string = g_string_new (NULL);
1639
1640
    for (lp = list; lp != NULL; lp = lp->next)
1641
    {
360 by am.monkeyd at gmail
adding -d debug option, goffile got uri checked all g_file_get_uri debug msg
1642
        string = g_string_append (string, GOF_FILE(lp->data)->uri);
122.1.1 by am.monkeyd at gmail
drag&drop
1643
        string = g_string_append (string, "\r\n");
1644
    }
1645
1646
    *len = string->len;
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1647
    return g_string_free (string, FALSE);
122.1.1 by am.monkeyd at gmail
drag&drop
1648
}
1649
506 by xapantu
Some improvements to the plugin system, loading/unloading is not fully live yet, but there is some progress
1650
gboolean gof_file_same_filesystem (GOFFile *file_a, GOFFile *file_b)
122.1.1 by am.monkeyd at gmail
drag&drop
1651
{
1652
    const gchar *filesystem_id_a;
1653
    const gchar *filesystem_id_b;
1654
1655
    g_return_val_if_fail (GOF_IS_FILE (file_a), FALSE);
1656
    g_return_val_if_fail (GOF_IS_FILE (file_b), FALSE);
1657
1658
    /* return false if we have no information about one of the files */
1659
    if (file_a->info == NULL || file_b->info == NULL)
1660
        return FALSE;
1661
1662
    /* determine the filesystem IDs */
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1663
    filesystem_id_a = g_file_info_get_attribute_string (file_a->info,
122.1.1 by am.monkeyd at gmail
drag&drop
1664
                                                        G_FILE_ATTRIBUTE_ID_FILESYSTEM);
1665
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1666
    filesystem_id_b = g_file_info_get_attribute_string (file_b->info,
122.1.1 by am.monkeyd at gmail
drag&drop
1667
                                                        G_FILE_ATTRIBUTE_ID_FILESYSTEM);
1668
1669
    /* compare the filesystem IDs */
1670
    return eel_str_is_equal (filesystem_id_a, filesystem_id_b);
1671
}
1672
1673
/**
1674
 * gof_file_accepts_drop (imported from thunar):
1675
 * @file                    : a #GOFFile instance.
1676
 * @file_list               : the list of #GFile<!---->s that will be droppped.
1677
 * @context                 : the current #GdkDragContext, which is used for the drop.
1678
 * @suggested_action_return : return location for the suggested #GdkDragAction or %NULL.
1679
 *
1680
 * Checks whether @file can accept @path_list for the given @context and
1681
 * returns the #GdkDragAction<!---->s that can be used or 0 if no actions
1682
 * apply.
1683
 *
1684
 * If any #GdkDragAction<!---->s apply and @suggested_action_return is not
1685
 * %NULL, the suggested #GdkDragAction for this drop will be stored to the
1686
 * location pointed to by @suggested_action_return.
1687
 *
1688
 * Return value: the #GdkDragAction<!---->s supported for the drop or
1689
 *               0 if no drop is possible.
1690
**/
1691
1692
GdkDragAction
1693
gof_file_accepts_drop (GOFFile          *file,
1694
                       GList            *file_list,
1695
                       GdkDragContext   *context,
1696
                       GdkDragAction    *suggested_action_return)
1697
{
1698
    GdkDragAction   suggested_action;
1699
    GdkDragAction   actions;
1700
    GOFFile         *ofile;
1701
    GFile           *parent_file;
1702
    GList           *lp;
1703
    guint           n;
1704
1705
    g_return_val_if_fail (GOF_IS_FILE (file), 0);
1706
    g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), 0);
1707
1708
    /* we can never drop an empty list */
1709
    if (G_UNLIKELY (file_list == NULL))
1710
        return 0;
1711
1712
    /* default to whatever GTK+ thinks for the suggested action */
1713
    suggested_action = gdk_drag_context_get_suggested_action (context);
1714
1715
    /* check if we have a writable directory here or an executable file */
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
1716
    if (gof_file_is_folder (file) && gof_file_is_writable (file))
122.1.1 by am.monkeyd at gmail
drag&drop
1717
    {
1718
        /* determine the possible actions */
1719
        actions = gdk_drag_context_get_actions (context) & (GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK);
1720
1721
1722
        /* check up to 100 of the paths (just in case somebody tries to
1723
         * drag around his music collection with 5000 files).
1724
         */
1643.2.50 by jeremy at elementaryos
Stop linking to and from remote files
1725
122.1.1 by am.monkeyd at gmail
drag&drop
1726
        for (lp = file_list, n = 0; lp != NULL && n < 100; lp = lp->next, ++n)
1727
        {
360 by am.monkeyd at gmail
adding -d debug option, goffile got uri checked all g_file_get_uri debug msg
1728
122.1.1 by am.monkeyd at gmail
drag&drop
1729
            /* we cannot drop a file on itself */
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
1730
            if (G_UNLIKELY (g_file_equal (gof_file_get_target_location (file), lp->data)))
122.1.1 by am.monkeyd at gmail
drag&drop
1731
                return 0;
1732
1733
            /* check whether source and destination are the same */
1734
            parent_file = g_file_get_parent (lp->data);
1735
            if (G_LIKELY (parent_file != NULL))
1736
            {
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
1737
                if (g_file_equal (gof_file_get_target_location (file), parent_file))
122.1.1 by am.monkeyd at gmail
drag&drop
1738
                {
1739
                    g_object_unref (parent_file);
1814.2.1 by Jeremy Wootten
Ask to link if file dropped onto its parent folder
1740
                    suggested_action = GDK_ACTION_ASK;
1741
                    actions = GDK_ACTION_ASK|GDK_ACTION_LINK;
122.1.1 by am.monkeyd at gmail
drag&drop
1742
                }
1743
                else
1744
                    g_object_unref (parent_file);
1745
            }
1746
2033.3.6 by Jeremy Wootten
Fix permitted drag-drop actions for remote folders
1747
        /* Make these tests at the end so that any changes are not reversed subsequently */
1748
            char *scheme;
1749
            scheme = g_file_get_uri_scheme (lp->data);
1750
            if (!g_str_has_prefix (scheme, "file")) {
1751
                /* do not allow symbolic links from remote filesystems */
1752
                actions &= ~(GDK_ACTION_LINK);
1753
            }
1754
1755
            g_free (scheme);
1756
122.1.1 by am.monkeyd at gmail
drag&drop
1757
            /* copy/move/link within the trash not possible */
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1758
            if (G_UNLIKELY (eel_g_file_is_trashed (lp->data) && gof_file_is_trashed (file)))
1759
                return 0;
122.1.1 by am.monkeyd at gmail
drag&drop
1760
        }
1761
2357.1.2 by Jeremy Wootten
Use effective uid to determine writability, correctly determine default drop action on ftp
1762
        /* if the source offers both copy and move and the GTK+ suggested action is copy, try to
1763
         * be smart telling whether we should copy or move by default by checking whether the
1764
         * source and target are on the same disk. */
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1765
        if ((actions & (GDK_ACTION_COPY | GDK_ACTION_MOVE)) != 0
122.1.1 by am.monkeyd at gmail
drag&drop
1766
            && (suggested_action == GDK_ACTION_COPY))
1767
        {
1768
            /* default to move as suggested action */
1769
            suggested_action = GDK_ACTION_MOVE;
1770
1771
            /* check for up to 100 files, for the reason state above */
1772
            for (lp = file_list, n = 0; lp != NULL && n < 100; lp = lp->next, ++n)
1773
            {
1774
                /* dropping from the trash always suggests move */
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1775
                if (G_UNLIKELY (eel_g_file_is_trashed (lp->data)))
1776
                    break;
122.1.1 by am.monkeyd at gmail
drag&drop
1777
1778
                /* determine the cached version of the source file */
1779
                ofile = gof_file_get(lp->data);
1780
1781
                /* we have only move if we know the source and both the source and the target
1782
                 * are on the same disk, and the source file is owned by the current user.
1783
                 */
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1784
                if (ofile == NULL
122.1.1 by am.monkeyd at gmail
drag&drop
1785
                    || !gof_file_same_filesystem (file, ofile)
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1786
                    || (ofile->info != NULL
2357.1.2 by Jeremy Wootten
Use effective uid to determine writability, correctly determine default drop action on ftp
1787
                        && ofile->uid > -1
1788
                        && ofile->uid != effective_user_id ))
122.1.1 by am.monkeyd at gmail
drag&drop
1789
                {
1790
                    /* default to copy and get outa here */
1791
                    suggested_action = GDK_ACTION_COPY;
1792
                    break;
1793
                }
1794
            }
1795
        }
1796
    }
1459.1.111 by jeremy at elementaryos
Fix drop highighting, compile warnings, improve renaming - use small font if necessary, blank area to side of icon now not active in icon view
1797
    else if (!gof_file_is_folder (file) && gof_file_is_executable (file))
122.1.1 by am.monkeyd at gmail
drag&drop
1798
    {
1799
        /* determine the possible actions */
1800
        actions = gdk_drag_context_get_actions (context) & (GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_PRIVATE);
2033.3.6 by Jeremy Wootten
Fix permitted drag-drop actions for remote folders
1801
    } else {
1802
        g_debug ("Not a valid drop target");
1803
        return 0;
1804
    }
1805
1806
    /* Make these tests at the end so that any changes are not reversed subsequently */
1807
    char *scheme;
1808
    scheme = g_file_get_uri_scheme (gof_file_get_target_location (file));
1809
    /* do not allow symbolic links to remote filesystems */
1810
    if (!g_str_has_prefix (scheme, "file"))
1811
        actions &= ~(GDK_ACTION_LINK);
1812
1813
    g_free (scheme);
1814
1815
    /* cannot create symbolic links in the trash or copy to the trash */
1816
    if (gof_file_is_trashed (file))
1817
        actions &= ~(GDK_ACTION_COPY | GDK_ACTION_LINK);
1818
1819
    if (actions == GDK_ACTION_ASK) {
1820
        /* No point in asking if there are no allowed actions */
1821
        return 0;
1822
    }
122.1.1 by am.monkeyd at gmail
drag&drop
1823
1824
    /* determine the preferred action based on the context */
1825
    if (G_LIKELY (suggested_action_return != NULL))
1826
    {
1827
        /* determine a working action */
1828
        if (G_LIKELY ((suggested_action & actions) != 0))
1829
            *suggested_action_return = suggested_action;
1830
        else if ((actions & GDK_ACTION_ASK) != 0)
1831
            *suggested_action_return = GDK_ACTION_ASK;
1832
        else if ((actions & GDK_ACTION_COPY) != 0)
1833
            *suggested_action_return = GDK_ACTION_COPY;
1834
        else if ((actions & GDK_ACTION_LINK) != 0)
1835
            *suggested_action_return = GDK_ACTION_LINK;
1836
        else if ((actions & GDK_ACTION_MOVE) != 0)
1837
            *suggested_action_return = GDK_ACTION_MOVE;
1838
        else
1839
            *suggested_action_return = GDK_ACTION_PRIVATE;
1840
    }
1841
1842
    /* yeppa, we can drop here */
1843
    return actions;
1844
}
1845
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1846
static gboolean
1847
gof_spawn_command_line_on_screen (char *cmd, GdkScreen *screen)
1848
{
1849
    GAppInfo *app;
1850
    GdkAppLaunchContext *ctx;
1851
    GError *error = NULL;
1852
    gboolean succeed = FALSE;
1853
1854
    app = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
1855
1856
    if (app != NULL && screen != NULL) {
798.2.2 by am.monkeyd at gmail
replace deprecated fcts from gtk & glib
1857
        ctx = gdk_display_get_app_launch_context (gdk_screen_get_display (screen));
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1858
1859
        succeed = g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), &error);
1860
1861
        g_object_unref (app);
1862
        g_object_unref (ctx);
1863
    }
1864
1865
    if (error != NULL) {
1866
        g_error_free (error);
1867
    }
1868
1869
    return (succeed);
1870
}
1871
1872
1873
/**
1874
 * gof_file_get_default_handler: imported from thunar
1875
 * @file : a #GOFFile instance.
1876
 *
1877
 * Returns the default #GAppInfo for @file or %NULL if there is none.
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1878
 *
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1879
 * The caller is responsible to free the returned #GAppInfo using
1880
 * g_object_unref().
1881
 *
1882
 * Return value: Default #GAppInfo for @file or %NULL if there is none.
1883
**/
1884
GAppInfo *
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1885
gof_file_get_default_handler (GOFFile *file)
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1886
{
1887
    const gchar *content_type;
1888
    gboolean     must_support_uris = FALSE;
1889
    gchar       *path;
1890
1891
    g_return_val_if_fail (GOF_IS_FILE (file), NULL);
1892
757 by am.monkeyd at gmail
goffile more clean up
1893
    content_type = gof_file_get_ftype (file);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1894
    if (content_type != NULL)
1895
    {
1896
        path = g_file_get_path (file->location);
1897
        must_support_uris = (path == NULL);
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
1898
        _g_free0 (path);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1899
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
1900
        return g_app_info_get_default_for_type (content_type, must_support_uris);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1901
    }
1902
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
1903
    //g_app_info_get_default_for_uri_scheme
1904
    if (file->target_location != NULL)
1905
        return g_file_query_default_handler (file->target_location, NULL, NULL);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1906
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
1907
    return g_file_query_default_handler (file->location, NULL, NULL);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1908
}
1909
1910
gboolean
1911
gof_file_execute (GOFFile *file, GdkScreen *screen, GList *file_list, GError **error)
1912
{
597.1.17 by am.monkeyd at gmail
user & group owners
1913
    /*gboolean    snotify = FALSE;
1914
    gboolean    terminal;*/
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1915
    gboolean    result = FALSE;
1916
    GKeyFile    *key_file;
1917
    GError      *err = NULL;
1918
    gchar       *icon = NULL;
1919
    gchar       *name;
1920
    gchar       *type;
1921
    gchar       *url;
1922
    gchar       *location;
1923
    gchar       *exec;
1924
1925
    gchar       *cmd = NULL;
1926
    gchar       *quoted_location;
1927
1928
    g_return_val_if_fail (GOF_IS_FILE (file), FALSE);
1929
    g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
1930
    g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1931
1932
    /* only execute locale executable files */
1933
    if (!g_file_is_native (file->location))
1934
        return FALSE;
1935
    location = g_file_get_path (file->location);
1936
1937
    if (gof_file_is_desktop_file (file))
1938
    {
1939
        key_file = eel_g_file_query_key_file (file->location, NULL, &err);
1940
1941
        if (key_file == NULL)
1942
        {
1943
            g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL,
1944
                         _("Failed to parse the desktop file: %s"), err->message);
1945
            g_error_free (err);
1946
            return FALSE;
1947
        }
1948
1949
        type = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
1950
                                      G_KEY_FILE_DESKTOP_KEY_TYPE, NULL);
1951
1952
        if (G_LIKELY (eel_str_is_equal (type, "Application")))
1953
        {
1954
            exec = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
1955
                                          G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
1956
            if (G_LIKELY (exec != NULL))
1957
            {
1958
                /* parse other fields */
1959
                name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
1960
                                                     G_KEY_FILE_DESKTOP_KEY_NAME, NULL,
1961
                                                     NULL);
1962
                icon = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
1963
                                              G_KEY_FILE_DESKTOP_KEY_ICON, NULL);
1964
                /* TODO use terminal snotify */
597.1.17 by am.monkeyd at gmail
user & group owners
1965
                /*terminal = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1966
                                                   G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL);
1967
                snotify = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1968
                                                  G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY,
597.1.17 by am.monkeyd at gmail
user & group owners
1969
                                                  NULL);*/
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1970
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1971
                cmd = marlin_exec_parse (exec, file_list, icon, name, location);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1972
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
1973
                _g_free0 (name);
1974
                _g_free0 (icon);
1975
                _g_free0 (exec);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1976
            }
1977
            else
1978
            {
2262.1.1 by Jeremy Wootten
Give existing translator comments elementaryos format
1979
                /// TRANSLATORS: `Exec' is a field name in a .desktop file. Don't translate it.
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1980
                g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL,
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1981
                             _("No Exec field specified"));
1982
            }
1983
        }
1984
        else if (eel_str_is_equal (type, "Link"))
1985
        {
1986
            url = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
1987
                                         G_KEY_FILE_DESKTOP_KEY_URL, NULL);
1988
            if (G_LIKELY (url != NULL))
1989
            {
1990
                //printf ("%s Link %s\n", G_STRFUNC, url);
1991
                GOFFile *link = gof_file_get_by_commandline_arg (url);
744 by am.monkeyd at gmail
fixing action Open with desktop/executable files
1992
                result = gof_file_launch (link, screen, NULL);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1993
                g_object_unref (link);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1994
                return (result);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
1995
            }
1996
            else
1997
            {
2262.1.1 by Jeremy Wootten
Give existing translator comments elementaryos format
1998
                /// TRANSLATORS: `Exec' is a field name in a .desktop file. Don't translate it.
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
1999
                g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL,
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
2000
                             _("No URL field specified"));
2001
            }
2002
        }
2003
        else
2004
        {
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2005
            g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL,
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
2006
                         _("Invalid desktop file"));
2007
        }
2008
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
2009
        _g_free0 (type);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
2010
        g_key_file_free (key_file);
2011
    }
2012
    else
2013
    {
2014
        quoted_location = g_shell_quote (location);
2015
        cmd = marlin_exec_auto_parse (quoted_location, file_list);
2016
        //printf ("%s exec: %s\n", G_STRFUNC, cmd);
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
2017
        _g_free0 (quoted_location);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
2018
    }
2019
2020
    if (cmd != NULL) {
2021
        //printf ("%s cmd: %s\n", G_STRFUNC, cmd);
2022
        result = gof_spawn_command_line_on_screen (cmd, screen);
2023
    }
2024
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
2025
    _g_free0 (location);
2026
    _g_free0 (cmd);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
2027
2028
    return result;
2029
}
2030
744 by am.monkeyd at gmail
fixing action Open with desktop/executable files
2031
static gboolean
2032
gof_file_launch_with (GOFFile  *file, GdkScreen *screen, GAppInfo* app_info)
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
2033
{
2034
    GdkAppLaunchContext *context;
2035
    gboolean             succeed;
2036
    GList                path_list;
477 by am.monkeyd at gmail
gof_file_launch don't forget Gerror NULL init
2037
    GError              *error = NULL;
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
2038
2039
    g_return_val_if_fail (GOF_IS_FILE (file), FALSE);
2040
    g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2041
744 by am.monkeyd at gmail
fixing action Open with desktop/executable files
2042
    /* fake a path list */
2043
    path_list.data = file->location;
2044
    path_list.next = path_list.prev = NULL;
2045
798.2.2 by am.monkeyd at gmail
replace deprecated fcts from gtk & glib
2046
    context = gdk_display_get_app_launch_context (gdk_screen_get_display (screen));
744 by am.monkeyd at gmail
fixing action Open with desktop/executable files
2047
    succeed = g_app_info_launch (app_info, &path_list, G_APP_LAUNCH_CONTEXT (context), &error);
2048
2049
    g_object_unref (context);
2050
2051
    return succeed;
2052
}
2053
2054
gboolean
1459.1.41 by jeremy at elementaryos
Convert Columns view to Vala - basic functionality, no menus
2055
gof_file_launch_files (GList *files, GdkScreen *screen, GAppInfo* app_info)
744 by am.monkeyd at gmail
fixing action Open with desktop/executable files
2056
{
2057
    GdkAppLaunchContext *context;
2058
    gboolean             succeed;
2059
    GList               *gfiles;
2060
    GError              *error = NULL;
2061
2062
    g_return_val_if_fail (files != NULL, FALSE);
2063
    g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2064
798.2.2 by am.monkeyd at gmail
replace deprecated fcts from gtk & glib
2065
    context = gdk_display_get_app_launch_context (gdk_screen_get_display (screen));
744 by am.monkeyd at gmail
fixing action Open with desktop/executable files
2066
2067
    gfiles = gof_files_get_location_list (files);
2068
2069
    succeed = g_app_info_launch (app_info, gfiles, G_APP_LAUNCH_CONTEXT (context), &error);
1643.2.19 by jeremy at elementaryos
Fix pathbar regression, clear cached files when reloading so remote directories refresh properly
2070
    print_error (error); /* also frees error */
744 by am.monkeyd at gmail
fixing action Open with desktop/executable files
2071
2072
    g_list_free_full (gfiles, (GDestroyNotify) eel_g_file_unref);
2073
    g_object_unref (context);
2074
2075
    return succeed;
2076
}
2077
2078
gboolean
2079
gof_file_launch (GOFFile  *file, GdkScreen *screen, GAppInfo *app_info)
2080
{
2081
    GAppInfo    *app = NULL;
2082
    gboolean    succeed;
2083
    GError      *error = NULL;
2084
2085
    g_return_val_if_fail (GOF_IS_FILE (file), FALSE);
2086
    g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2087
2088
    if (app_info != NULL)
2089
        app = g_app_info_dup (app_info);
2160.1.1 by jeremy at elementaryos
Do not execute files when launched with an app
2090
2091
    /* Do not run executables if an app to open them with has been supplied */
2092
    if (app == NULL) {
2093
        /* check if we should execute the file */
2094
        if (gof_file_is_executable (file))
2095
            return gof_file_execute (file, screen, NULL, &error);
2096
        else
2097
            app = gof_file_get_default_handler (file);
2098
    }
744 by am.monkeyd at gmail
fixing action Open with desktop/executable files
2099
    if (app == NULL)
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
2100
    {
2192.1.1 by jeremy at elementaryos
Launch app chooser when no default app
2101
        /* AppChooser dialog has already been shown by Marlin.MimeActions*/
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
2102
        return TRUE;
2103
    }
2104
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
2105
    /* check if we're not trying to launch our own file manager */
2106
    /*if (g_strcmp0 (g_app_info_get_id (app_info), "marlin.desktop") == 0
2107
        || g_strcmp0 (g_app_info_get_name (app_info), "marlin") == 0)
2108
    {
2109
        g_object_unref (G_OBJECT (app_info));
2110
        app_info = g_app_info_create_from_commandline ("marlin -t", "marlin", 0, NULL);
2111
    }*/
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
2112
2113
    /* TODO allow launch of multiples same content type files */
2114
744 by am.monkeyd at gmail
fixing action Open with desktop/executable files
2115
    succeed = gof_file_launch_with (file, screen, app);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
2116
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2117
    /* TODO error */
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
2118
744 by am.monkeyd at gmail
fixing action Open with desktop/executable files
2119
    g_object_unref (G_OBJECT (app));
585 by am.monkeyd at gmail
OpenWith (sub)menus refactoring. available from menubar too. more tradtional menus
2120
2121
    return succeed;
2122
}
2123
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
2124
void
744 by am.monkeyd at gmail
fixing action Open with desktop/executable files
2125
gof_file_open_single (GOFFile *file, GdkScreen *screen, GAppInfo *app_info)
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
2126
{
744 by am.monkeyd at gmail
fixing action Open with desktop/executable files
2127
    gof_file_launch (file, screen, app_info);
122.1.12 by am.monkeyd at gmail
drop gdk_spawn
2128
}
2129
1 by am.monkeyd at gmail
let's roll
2130
void
182 by am.monkeyd at gmail
icon_view first draft + zoom lvl
2131
gof_file_list_free (GList *list)
1 by am.monkeyd at gmail
let's roll
2132
{
65 by am.monkeyd at gmail
reinenting all the C code tab=4spaces
2133
    g_list_foreach (list, (GFunc) gof_file_unref, NULL);
2134
    g_list_free (list);
1 by am.monkeyd at gmail
let's roll
2135
}
2136
585 by am.monkeyd at gmail
OpenWith (sub)menus refactoring. available from menubar too. more tradtional menus
2137
GList *
2138
gof_file_list_ref (GList *list)
2139
{
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2140
    g_list_foreach (list, (GFunc) gof_file_ref, NULL);
2141
    return list;
585 by am.monkeyd at gmail
OpenWith (sub)menus refactoring. available from menubar too. more tradtional menus
2142
}
2143
2144
GList *
2145
gof_file_list_copy (GList *list)
2146
{
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2147
    return g_list_copy (gof_file_list_ref (list));
585 by am.monkeyd at gmail
OpenWith (sub)menus refactoring. available from menubar too. more tradtional menus
2148
}
2149
2150
679 by am.monkeyd at gmail
files operations use file-changes-queue. rename on new folder. rename reuse edited row.
2151
static void
2152
gof_file_update_existing (GOFFile *file, GFile *new_location)
2153
{
2033.2.6 by jeremy at elementaryos
Fix view reloading
2154
    GOFDirectoryAsync *dir = NULL;
2155
    if (file->directory != NULL) {
2156
        dir = gof_directory_async_cache_lookup (file->directory);
2157
    }
696 by am.monkeyd at gmail
gof_file_update_existing remove from all the caches mark is_gone false to reuse the goffile. fm-directory-view on row deleted action make sure selection_before_delete don't save an old path
2158
2159
    gof_file_remove_from_caches (file);
2160
    file->is_gone = FALSE;
679 by am.monkeyd at gmail
files operations use file-changes-queue. rename on new folder. rename reuse edited row.
2161
2162
    g_object_unref (file->location);
2163
    file->location = g_object_ref (new_location);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2164
2165
    if (dir != NULL)
1504.1.1 by jeremy at elementaryos
Prevent multiple simultaneous thumbnail threads, restrict access to Async directory functions, guard directory cache with mutex, set maximum windows and tabs
2166
        gof_directory_async_file_hash_add_file (dir, file);
679 by am.monkeyd at gmail
files operations use file-changes-queue. rename on new folder. rename reuse edited row.
2167
2168
    _g_free0 (file->uri);
2169
    file->uri = g_file_get_uri (new_location);
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
2170
    _g_free0 (file->basename);
679 by am.monkeyd at gmail
files operations use file-changes-queue. rename on new folder. rename reuse edited row.
2171
    file->basename = g_file_get_basename (file->location);
2172
    /* TODO update color on rename ? */
748 by am.monkeyd at gmail
adding ctags core plugin, content-type detection, color ...
2173
    //file->color = 0;
679 by am.monkeyd at gmail
files operations use file-changes-queue. rename on new folder. rename reuse edited row.
2174
    file->pix_size = -1;
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
2175
    _g_free0 (file->thumbnail_path);
770 by am.monkeyd at gmail
_g_object_unref0 insanities, check all & replace
2176
    file->flags = 0;
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2177
679 by am.monkeyd at gmail
files operations use file-changes-queue. rename on new folder. rename reuse edited row.
2178
    gof_file_query_update (file);
770 by am.monkeyd at gmail
_g_object_unref0 insanities, check all & replace
2179
2180
    g_object_unref (dir);
679 by am.monkeyd at gmail
files operations use file-changes-queue. rename on new folder. rename reuse edited row.
2181
}
2182
155 by am.monkeyd at gmail
gof_file_rename
2183
/* TODO move this mini job to marlin-file-operations? */
2184
GOFFileOperation *
2185
gof_file_operation_new (GOFFile *file,
2186
                        GOFFileOperationCallback callback,
2187
                        gpointer callback_data)
2188
{
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2189
    GOFFileOperation *op;
155 by am.monkeyd at gmail
gof_file_rename
2190
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2191
    op = g_new0 (GOFFileOperation, 1);
2192
    op->file = gof_file_ref (file);
2193
    op->callback = callback;
2194
    op->callback_data = callback_data;
2195
    op->cancellable = g_cancellable_new ();
155 by am.monkeyd at gmail
gof_file_rename
2196
560.1.7 by am.monkeyd at gmail
reset emblems list
2197
    /* FIXME check this Glist */
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2198
    op->file->operations_in_progress = g_list_prepend
2199
        (op->file->operations_in_progress, op);
155 by am.monkeyd at gmail
gof_file_rename
2200
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2201
    return op;
155 by am.monkeyd at gmail
gof_file_rename
2202
}
2203
2204
static void
2205
gof_file_operation_remove (GOFFileOperation *op)
2206
{
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2207
    op->file->operations_in_progress = g_list_remove
2208
        (op->file->operations_in_progress, op);
155 by am.monkeyd at gmail
gof_file_rename
2209
}
2210
2211
void
2212
gof_file_operation_free (GOFFileOperation *op)
2213
{
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2214
    gof_file_operation_remove (op);
2215
    gof_file_unref (op->file);
2216
    g_object_unref (op->cancellable);
2217
    if (op->free_data) {
2218
        op->free_data (op->data);
2219
    }
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
2220
    _g_free0 (op);
155 by am.monkeyd at gmail
gof_file_rename
2221
}
2222
2223
void
2224
gof_file_operation_complete (GOFFileOperation *op, GFile *result_file, GError *error)
2225
{
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2226
    /* Claim that something changed even if the operation failed.
2227
     * This makes it easier for some clients who see the "reverting"
2228
     * as "changing back".
2229
     */
2230
    gof_file_operation_remove (op);
679 by am.monkeyd at gmail
files operations use file-changes-queue. rename on new folder. rename reuse edited row.
2231
    gof_file_icon_changed (op->file);
2232
    //marlin_file_changes_consume_changes (TRUE);
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2233
    if (op->callback) {
2234
        (* op->callback) (op->file, result_file, error, op->callback_data);
2235
    }
2236
    gof_file_operation_free (op);
155 by am.monkeyd at gmail
gof_file_rename
2237
}
2238
2239
void
2240
gof_file_operation_cancel (GOFFileOperation *op)
2241
{
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2242
    /* Cancel the operation if it's still in progress. */
2243
    g_cancellable_cancel (op->cancellable);
155 by am.monkeyd at gmail
gof_file_rename
2244
}
2245
2246
static void
2247
rename_callback (GObject *source_object,
2248
                 GAsyncResult *res,
2249
                 gpointer callback_data)
2250
{
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2251
    GOFFileOperation *op;
2252
    GFile *new_file;
2253
    GError *error;
155 by am.monkeyd at gmail
gof_file_rename
2254
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2255
    op = callback_data;
2256
    error = NULL;
2257
    new_file = g_file_set_display_name_finish (G_FILE (source_object),
155 by am.monkeyd at gmail
gof_file_rename
2258
                                               res, &error);
679 by am.monkeyd at gmail
files operations use file-changes-queue. rename on new folder. rename reuse edited row.
2259
    //marlin_file_changes_queue_file_changed (new_file);
2260
    //marlin_file_changes_queue_file_removed (op->file->location);
2261
    //marlin_file_changes_queue_file_added (new_file);
2262
    if (error == NULL)
2263
        gof_file_update_existing (op->file, new_file);
1459.1.51 by jeremy at elementaryos
Fix renaming
2264
    else
1459.1.190 by jeremy at elementaryos
Fix rename error dialog and handling
2265
        marlin_dialogs_show_error (NULL,
2266
                                   error,
2267
                                   "Failed to rename %s",
2268
                                   g_file_get_parse_name (op->file->location));
155 by am.monkeyd at gmail
gof_file_rename
2269
770 by am.monkeyd at gmail
_g_object_unref0 insanities, check all & replace
2270
    //g_warning ("%s %u", G_STRFUNC, G_OBJECT (op->file)->ref_count);
1459.1.51 by jeremy at elementaryos
Fix renaming
2271
    gof_file_operation_complete (op, new_file, error);
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2272
    if (new_file != NULL) {
155 by am.monkeyd at gmail
gof_file_rename
2273
        g_object_unref (new_file);
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2274
    } else {
155 by am.monkeyd at gmail
gof_file_rename
2275
        g_error_free (error);
2276
    }
2277
}
2278
2279
void
2280
gof_file_rename (GOFFile *file,
2281
                 const char *new_name,
2282
                 GOFFileOperationCallback callback,
2283
                 gpointer callback_data)
2284
{
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2285
    GOFFileOperation *op;
597.1.17 by am.monkeyd at gmail
user & group owners
2286
    //char *uri;
2287
    //char *old_name;
2288
    //char *new_file_name;
2289
    //gboolean success, name_changed;
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2290
    GError *error;
770 by am.monkeyd at gmail
_g_object_unref0 insanities, check all & replace
2291
    //g_warning ("%s %u", G_STRFUNC, G_OBJECT (file)->ref_count);
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2292
    g_return_if_fail (GOF_IS_FILE (file));
2293
    g_return_if_fail (new_name != NULL);
2294
    g_return_if_fail (callback != NULL);
155 by am.monkeyd at gmail
gof_file_rename
2295
2296
    //TODO rename .desktop files
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2297
    /* Return an error for incoming names containing path separators.
2298
     * But not for .desktop files as '/' are allowed for them */
2299
    if (strstr (new_name, "/") != NULL) {
2300
        error = g_error_new (G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
2301
                             _("Slashes are not allowed in filenames"));
2302
        (* callback) (file, NULL, error, callback_data);
2303
        g_error_free (error);
2304
        return;
2305
    }
2306
155 by am.monkeyd at gmail
gof_file_rename
2307
    //TODO check
2308
2309
    /* Self-owned files can't be renamed. Test the name-not-actually-changing
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2310
     * case before this case.
2311
     */
155 by am.monkeyd at gmail
gof_file_rename
2312
#if 0
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2313
    if (nautilus_file_is_self_owned (file)) {
2314
        /* Claim that something changed even if the rename
2315
         * failed. This makes it easier for some clients who
2316
         * see the "reverting" to the old name as "changing
2317
         * back".
2318
         */
2319
        nautilus_file_changed (file);
2320
        error = g_error_new (G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
155 by am.monkeyd at gmail
gof_file_rename
2321
                             _("Toplevel files cannot be renamed"));
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2322
2323
        (* callback) (file, NULL, error, callback_data);
2324
        g_error_free (error);
2325
        return;
2326
    }
155 by am.monkeyd at gmail
gof_file_rename
2327
#endif
2328
2329
    /* Set up a renaming operation. */
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2330
    op = gof_file_operation_new (file, callback, callback_data);
2331
    op->is_rename = TRUE;
155 by am.monkeyd at gmail
gof_file_rename
2332
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2333
    /* Do the renaming. */
2334
    g_file_set_display_name_async (file->location,
155 by am.monkeyd at gmail
gof_file_rename
2335
                                   new_name,
2336
                                   G_PRIORITY_DEFAULT,
2337
                                   op->cancellable,
2338
                                   rename_callback,
2339
                                   op);
2340
}
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
2341
597.1.17 by am.monkeyd at gmail
user & group owners
2342
2343
gboolean
2344
gof_file_can_set_owner (GOFFile *file)
2345
{
2346
    /* unknown file uid */
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2347
    if (file->uid == -1)
1811.1.1 by Jeremy Wootten
Code clean: tabs, trailing space, headers, comments
2348
        return FALSE;
597.1.17 by am.monkeyd at gmail
user & group owners
2349
1811.1.1 by Jeremy Wootten
Code clean: tabs, trailing space, headers, comments
2350
    /* root */
2351
    return geteuid() == 0;
597.1.17 by am.monkeyd at gmail
user & group owners
2352
}
2353
2354
/* copied from nautilus-file.c */
2355
/**
2356
 * gof_file_can_set_group:
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2357
 *
597.1.17 by am.monkeyd at gmail
user & group owners
2358
 * Check whether the current user is allowed to change
2359
 * the group of a file.
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2360
 *
597.1.17 by am.monkeyd at gmail
user & group owners
2361
 * @file: The file in question.
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2362
 *
597.1.17 by am.monkeyd at gmail
user & group owners
2363
 * Return value: TRUE if the current user can change the
2364
 * group of @file, FALSE otherwise. It's always possible
2365
 * that when you actually try to do it, you will fail.
2366
 */
2367
gboolean
2368
gof_file_can_set_group (GOFFile *file)
2369
{
1811.1.1 by Jeremy Wootten
Code clean: tabs, trailing space, headers, comments
2370
    uid_t user_id;
2371
2372
    if (file->gid == -1)
2373
        return FALSE;
2374
2375
    user_id = geteuid();
2376
2377
    /* Owner is allowed to set group (with restrictions). */
2378
    if (user_id == (uid_t) file->uid)
2379
        return TRUE;
2380
2381
    /* Root is also allowed to set group. */
2382
    if (user_id == 0)
2383
        return TRUE;
2384
2385
    return FALSE;
597.1.17 by am.monkeyd at gmail
user & group owners
2386
}
2387
2388
/* copied from nautilus-file.c */
2389
/**
2390
 * nautilus_file_get_settable_group_names:
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2391
 *
597.1.17 by am.monkeyd at gmail
user & group owners
2392
 * Get a list of all group names that the current user
2393
 * can set the group of a specific file to.
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2394
 *
597.1.17 by am.monkeyd at gmail
user & group owners
2395
 * @file: The NautilusFile in question.
2396
 */
2397
GList *
2398
gof_file_get_settable_group_names (GOFFile *file)
2399
{
1811.1.1 by Jeremy Wootten
Code clean: tabs, trailing space, headers, comments
2400
    uid_t user_id;
2401
    GList *result = NULL;
2402
2403
    if (!gof_file_can_set_group (file))
2404
        return NULL;
2405
2406
    /* Check the user. */
2407
    user_id = geteuid();
2408
2409
    if (user_id == 0) {
2410
        /* Root is allowed to set group to anything. */
2411
        result = eel_get_all_group_names ();
2412
    } else if (user_id == (uid_t) file->uid) {
2413
        /* Owner is allowed to set group to any that owner is member of. */
2414
        result = eel_get_group_names_for_user ();
2415
    } else {
2416
        g_warning ("unhandled case in %s", G_STRFUNC);
2417
    }
2418
2419
    return result;
597.1.17 by am.monkeyd at gmail
user & group owners
2420
}
2421
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2422
/* copied from nautilus-file.c */
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
2423
/**
2424
 * gof_file_can_set_permissions:
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2425
 *
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
2426
 * Check whether the current user is allowed to change
2427
 * the permissions of a file.
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2428
 *
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
2429
 * @file: The file in question.
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2430
 *
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
2431
 * Return value: TRUE if the current user can change the
2432
 * permissions of @file, FALSE otherwise. It's always possible
2433
 * that when you actually try to do it, you will fail.
2434
 */
2435
gboolean
2436
gof_file_can_set_permissions (GOFFile *file)
2437
{
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2438
    uid_t user_id;
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
2439
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2440
    if (file->uid != -1 && g_file_is_native (file->location))
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
2441
    {
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2442
        /* Check the user. */
2443
        user_id = geteuid();
2444
2445
        /* Owner is allowed to set permissions. */
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2446
        if (user_id == (uid_t) file->uid)
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2447
            return TRUE;
2448
2449
        /* Root is also allowed to set permissions. */
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2450
        if (user_id == 0)
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2451
            return TRUE;
2452
2453
        /* Nobody else is allowed. */
2454
        return FALSE;
2455
    }
2456
2457
    /* pretend to have full chmod rights when no info is available, relevant when
2458
     * the FS can't provide ownership info, for instance for FTP */
2459
    return TRUE;
2460
}
2461
2462
/* copied from nautilus-file.c */
2463
/**
2464
 * gof_file_get_permissions_as_string:
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2465
 *
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2466
 * Get a user-displayable string representing a file's permissions. The caller
604.1.3 by am.monkeyd at gmail
_g_free0 _g_object_unref0
2467
 * is responsible for _g_free0-ing this string.
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2468
 * @file: GOFFile representing the file in question.
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2469
 *
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2470
 * Returns: Newly allocated string ready to display to the user.
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2471
 *
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2472
 **/
2473
char *
2474
gof_file_get_permissions_as_string (GOFFile *file)
2475
{
2476
    gboolean is_link;
2477
    gboolean suid, sgid, sticky;
2478
2479
    g_assert (GOF_IS_FILE (file));
2480
2481
    is_link = gof_file_is_symlink (file);
2482
2483
    /* We use ls conventions for displaying these three obscure flags */
2484
    suid = file->permissions & S_ISUID;
2485
    sgid = file->permissions & S_ISGID;
2486
    sticky = file->permissions & S_ISVTX;
2487
2488
    return g_strdup_printf ("%c%c%c%c%c%c%c%c%c%c",
2489
                            is_link ? 'l' : file->is_directory ? 'd' : '-',
2490
                            file->permissions & S_IRUSR ? 'r' : '-',
2491
                            file->permissions & S_IWUSR ? 'w' : '-',
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2492
                            file->permissions & S_IXUSR
2493
                            ? (suid ? 's' : 'x')
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2494
                            : (suid ? 'S' : '-'),
2495
                            file->permissions & S_IRGRP ? 'r' : '-',
2496
                            file->permissions & S_IWGRP ? 'w' : '-',
2497
                            file->permissions & S_IXGRP
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2498
                            ? (sgid ? 's' : 'x')
1459.1.22 by Jeremy Wootten
Merge changes from trunk and resolve conflict
2499
                            : (sgid ? 'S' : '-'),
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2500
                            file->permissions & S_IROTH ? 'r' : '-',
2501
                            file->permissions & S_IWOTH ? 'w' : '-',
2502
                            file->permissions & S_IXOTH
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2503
                            ? (sticky ? 't' : 'x')
597.1.10 by am.monkeyd at gmail
grabbing permissions print -rwx label active toggle buttons...
2504
                            : (sticky ? 'T' : '-'));
2505
}
597.1.9 by am.monkeyd at gmail
set sensitive the permission panel
2506
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2507
gint
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
2508
gof_file_compare_by_display_name (gconstpointer a, gconstpointer b)
651 by am.monkeyd at gmail
LocationBar sorted breadcrumb menus. sorted_dirs cached in gof-directory-async
2509
{
698 by am.monkeyd at gmail
cleaning some compil warnings
2510
    return compare_by_display_name (GOF_FILE (a), GOF_FILE (b));
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
2511
}
2512
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
2513
GFile *
2514
gof_file_get_target_location (GOFFile *file)
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
2515
{
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2516
    /* when desktop files are not interpreted return the original loc,
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
2517
     * this way we can copy/paste simple desktop files intead of their target */
2518
    if (file->is_desktop && !gof_preferences_get_default ()->pref_interpret_desktop_files)
2519
        return file->location;
664 by am.monkeyd at gmail
gof_file using target_location for G_FILE_TYPE_SHORTCUT G_FILE_TYPE_MOUNTABLE .desktop Link
2520
    if (file->target_location != NULL)
2521
        return file->target_location;
2522
2523
    return file->location;
651 by am.monkeyd at gmail
LocationBar sorted breadcrumb menus. sorted_dirs cached in gof-directory-async
2524
}
666 by am.monkeyd at gmail
use display_name in the FILENAME column model and not name
2525
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
2526
const gchar *
2527
gof_file_get_display_name (GOFFile *file)
666 by am.monkeyd at gmail
use display_name in the FILENAME column model and not name
2528
{
2310.2.1 by Jeremy Wootten
Show protocol after servers in network:// view
2529
    return file->custom_display_name ? file->custom_display_name : file->basename;
666 by am.monkeyd at gmail
use display_name in the FILENAME column model and not name
2530
}
677 by am.monkeyd at gmail
fix network browsing: use gio full attrs on smb scheme, use gtk_mount_operation_new instead of g_mount_operation_new (bring auth dialog), open folder on gof_file_is_remote_folder
2531
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2532
gboolean
742 by am.monkeyd at gmail
desktop files... show desktop files fix Bug #897446, .desktop files are not listed by actual file name
2533
gof_file_is_folder (GOFFile *file)
677 by am.monkeyd at gmail
fix network browsing: use gio full attrs on smb scheme, use gtk_mount_operation_new instead of g_mount_operation_new (bring auth dialog), open folder on gof_file_is_remote_folder
2534
{
1928.1.1 by Jeremy Wootten
Check for null file in gof_file_is_folder and OverlayBar.scan_list
2535
    if (file == NULL) {
2536
        g_warning ("gof_file_is_folder () called with null file - ignoring");
2537
        return FALSE;
2538
    }
2539
1643.2.23 by jeremy at elementaryos
Limit context menu options for schemes and servers
2540
    /* TODO check this works for non-local files and other uri schemes*/
1740.1.47 by Fabio Zaramella
change default action to open real file, add open in menu entry
2541
    if ((file->is_directory && !gof_file_is_root_network_folder (file)))
1643.2.1 by jeremy at elementaryos
Open network shared folders correctly
2542
        return TRUE;
2543
1643.2.53 by jeremy at elementaryos
Fix gof_file_is_folder function
2544
    if (gof_file_is_smb_share (file))
1643.2.51 by jeremy at elementaryos
Fix context menu contents for samba share selection, fix undo/redo move
2545
        return TRUE;
2546
1643.2.17 by jeremy at elementaryos
Suppress properties, edit, bookmark and open in terminal for root network folders
2547
    if (file->file_type == G_FILE_TYPE_MOUNTABLE &&
1643.2.23 by jeremy at elementaryos
Limit context menu options for schemes and servers
2548
        file->info != NULL &&
1643.2.17 by jeremy at elementaryos
Suppress properties, edit, bookmark and open in terminal for root network folders
2549
        g_file_info_get_attribute_boolean (file->info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT))
2550
2551
        return TRUE;
2552
1643.2.39 by jeremy at elementaryos
Modified gof_file_is_folder
2553
    if (file->target_gof && file->target_gof->is_directory) {
2554
        /* file->target_gof is directory */
2555
        if (gof_preferences_get_default ()->pref_interpret_desktop_files ||
2556
            gof_file_is_network_uri_scheme (file->target_gof))
2557
2558
            return TRUE;
2559
    }
1643.2.53 by jeremy at elementaryos
Fix gof_file_is_folder function
2560
677 by am.monkeyd at gmail
fix network browsing: use gio full attrs on smb scheme, use gtk_mount_operation_new instead of g_mount_operation_new (bring auth dialog), open folder on gof_file_is_remote_folder
2561
    return FALSE;
2562
}
2563
755 by am.monkeyd at gmail
goffile file info const start cleanup
2564
const gchar *
2565
gof_file_get_ftype (GOFFile *file)
2566
{
1643.2.23 by jeremy at elementaryos
Limit context menu options for schemes and servers
2567
    if (file->info == NULL || gof_file_is_location_uri_default (file))
1643.2.5 by jeremy at elementaryos
Fix password dialog
2568
        return NULL;
755 by am.monkeyd at gmail
goffile file info const start cleanup
2569
2570
    const char *ftype = NULL;
2571
    if (g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE))
2572
        return g_file_info_get_attribute_string (file->info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
1643.2.23 by jeremy at elementaryos
Limit context menu options for schemes and servers
2573
755 by am.monkeyd at gmail
goffile file info const start cleanup
2574
    if (g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE))
2575
        ftype = g_file_info_get_attribute_string (file->info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
1643.2.23 by jeremy at elementaryos
Limit context menu options for schemes and servers
2576
755 by am.monkeyd at gmail
goffile file info const start cleanup
2577
    if (!g_strcmp0 (ftype, "application/octet-stream") && file->tagstype)
2578
        return file->tagstype;
2579
2580
    return ftype;
2581
}
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
2582
798.3.11 by xapantu
Infrastructure for large thumbnails, need UI code
2583
2584
/**
2585
 * transfer: none
2586
 **/
759 by am.monkeyd at gmail
goffile more clean up. 1 memory leak fixed + don't update file info without update.
2587
const gchar *
2588
gof_file_get_thumbnail_path (GOFFile *file)
2589
{
2590
    if (file->thumbnail_path != NULL)
2591
        return file->thumbnail_path;
2592
    if (file->info != NULL && g_file_info_has_attribute (file->info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH))
2593
        return g_file_info_get_attribute_byte_string (file->info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
2594
2595
    return NULL;
2596
}
787 by am.monkeyd at gmail
PropertiesWindow show device usage when selection contain a folder, for mounted device or root filesystem
2597
1201 by Victor
GOFFile: avoid using UTF-8-encoded string in gof_file_is_location_uri_default to prevent failures, since the string functions are expecting native character encoding.
2598
char*
2599
gof_file_get_display_target_uri (GOFFile *file)
1198.1.8 by optimisme at gmail
changed variable by function
2600
{
1198.1.14 by optimisme at gmail
linal fixes
2601
    return g_file_info_get_attribute_as_string (file->info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
1198.1.8 by optimisme at gmail
changed variable by function
2602
}
2603
798.3.11 by xapantu
Infrastructure for large thumbnails, need UI code
2604
const gchar *
2605
gof_file_get_preview_path(GOFFile* file)
2606
{
2607
    gchar* thumbnail_path = gof_file_get_thumbnail_path(file);
2608
    gchar* new_thumbnail_path = NULL;
2609
    gchar** thumbnail_path_split = NULL;
2610
2611
    if (thumbnail_path != NULL)
2612
    {
2056.1.1 by jeremy at elementaryos
Ensure new thumbnails are displayed, do not try to thumbnail when unnecessary
2613
        /* Construct new path to large thumbnail based on $XDG_CACHE_HOME */
2614
        thumbnail_path_split = g_strsplit(thumbnail_path, G_DIR_SEPARATOR_S, -1);
2615
        uint l;
2616
        l = g_strv_length(thumbnail_path_split);
2617
        if(l > 2)
798.3.11 by xapantu
Infrastructure for large thumbnails, need UI code
2618
        {
2056.1.1 by jeremy at elementaryos
Ensure new thumbnails are displayed, do not try to thumbnail when unnecessary
2619
            new_thumbnail_path = g_strjoin(G_DIR_SEPARATOR_S, g_get_user_cache_dir (), "thumbnails/large", thumbnail_path_split[l-1], NULL);
2620
798.3.12 by xapantu
Better file preview support, it could use some cache system
2621
            if(!g_file_test(new_thumbnail_path, G_FILE_TEST_EXISTS))
2622
            {
2056.1.1 by jeremy at elementaryos
Ensure new thumbnails are displayed, do not try to thumbnail when unnecessary
2623
                new_thumbnail_path = g_strdup(thumbnail_path);
798.3.12 by xapantu
Better file preview support, it could use some cache system
2624
            }
798.3.11 by xapantu
Infrastructure for large thumbnails, need UI code
2625
        }
2626
        else
2627
        {
2628
            g_critical("Thumbnailer is not FD.o compliant?");
2629
            new_thumbnail_path = g_strdup(thumbnail_path);
2630
        }
2631
        g_strfreev(thumbnail_path_split);
2632
    }
2633
    return new_thumbnail_path;
2634
}
2635
787 by am.monkeyd at gmail
PropertiesWindow show device usage when selection contain a folder, for mounted device or root filesystem
2636
gboolean
2637
gof_file_can_unmount (GOFFile *file)
2638
{
1811.1.1 by Jeremy Wootten
Code clean: tabs, trailing space, headers, comments
2639
    g_return_val_if_fail (GOF_IS_FILE (file), FALSE);
787 by am.monkeyd at gmail
PropertiesWindow show device usage when selection contain a folder, for mounted device or root filesystem
2640
1811.1.1 by Jeremy Wootten
Code clean: tabs, trailing space, headers, comments
2641
    return file->can_unmount || (file->mount != NULL && g_mount_can_unmount (file->mount));
787 by am.monkeyd at gmail
PropertiesWindow show device usage when selection contain a folder, for mounted device or root filesystem
2642
}
2643
798.2.8 by am.monkeyd at gmail
soft shadows + frame. exceptions being made for path containing keywords icons .icons, we don't want frame or squared shadows for thoses.
2644
gboolean
2645
gof_file_thumb_can_frame (GOFFile *file)
2646
{
2033.2.6 by jeremy at elementaryos
Fix view reloading
2647
    GOFDirectoryAsync *dir = NULL;
798.2.8 by am.monkeyd at gmail
soft shadows + frame. exceptions being made for path containing keywords icons .icons, we don't want frame or squared shadows for thoses.
2648
2649
    /* get the DirectoryAsync associated to the file */
2033.2.6 by jeremy at elementaryos
Fix view reloading
2650
    if (file->directory != NULL) {
2651
        dir = gof_directory_async_cache_lookup (file->directory);
2652
    }
798.2.8 by am.monkeyd at gmail
soft shadows + frame. exceptions being made for path containing keywords icons .icons, we don't want frame or squared shadows for thoses.
2653
    if (dir != NULL) {
1266.3.5 by David Gomes
Stripped more trailing white space and fixed a typo on Animations.vala.
2654
        gboolean can_frame = !dir->uri_contain_keypath_icons;
798.2.12 by am.monkeyd at gmail
gof_file_thumb_can_frame don't forget to unref dir
2655
        g_object_unref (dir);
2656
        return can_frame;
798.2.8 by am.monkeyd at gmail
soft shadows + frame. exceptions being made for path containing keywords icons .icons, we don't want frame or squared shadows for thoses.
2657
    }
2658
2659
    return FALSE;
1615.1.1 by jeremy at elementaryos
Display readonly and unreadable emblems when appropriate
2660
}