~ubuntu-branches/ubuntu/saucy/blender/saucy-proposed

« back to all changes in this revision

Viewing changes to source/blender/editors/space_file/fsmenu.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
#include "DNA_space_types.h" /* FILE_MAX */
41
41
 
 
42
#include "BLI_utildefines.h"
42
43
#include "BLI_blenlib.h"
43
44
#include "BLI_linklist.h"
44
45
#include "BLI_dynstr.h"
54
55
#endif
55
56
 
56
57
#ifdef __APPLE__
57
 
   /* XXX BIG WARNING: carbon.h can not be included in blender code, it conflicts with struct ID */
 
58
/* XXX BIG WARNING: carbon.h can not be included in blender code, it conflicts with struct ID */
58
59
#  define ID ID_
59
60
#  include <CoreServices/CoreServices.h>
60
61
#endif /* __APPLE__ */
68
69
 
69
70
/* FSMENU HANDLING */
70
71
 
71
 
        /* FSMenuEntry's without paths indicate seperators */
 
72
/* FSMenuEntry's without paths indicate seperators */
72
73
typedef struct _FSMenuEntry FSMenuEntry;
73
74
struct _FSMenuEntry {
74
75
        FSMenuEntry *next;
77
78
        short save;
78
79
};
79
80
 
80
 
typedef struct FSMenu
81
 
{
 
81
typedef struct FSMenu {
82
82
        FSMenuEntry *fsmenu_system;
 
83
        FSMenuEntry *fsmenu_system_bookmarks;
83
84
        FSMenuEntry *fsmenu_bookmarks;
84
85
        FSMenuEntry *fsmenu_recent;
85
 
 
86
86
} FSMenu;
87
87
 
88
88
static FSMenu *g_fsmenu = NULL;
89
89
 
90
 
struct FSMenu* fsmenu_get(void)
 
90
FSMenu *fsmenu_get(void)
91
91
{
92
92
        if (!g_fsmenu) {
93
 
                g_fsmenu=MEM_callocN(sizeof(struct FSMenu), "fsmenu");
 
93
                g_fsmenu = MEM_callocN(sizeof(struct FSMenu), "fsmenu");
94
94
        }
95
95
        return g_fsmenu;
96
96
}
97
97
 
98
 
static FSMenuEntry *fsmenu_get_category(struct FSMenu* fsmenu, FSMenuCategory category)
99
 
{
100
 
        FSMenuEntry *fsms = NULL;
101
 
 
102
 
        switch(category) {
103
 
                case FS_CATEGORY_SYSTEM:
104
 
                        fsms = fsmenu->fsmenu_system;
105
 
                        break;
106
 
                case FS_CATEGORY_BOOKMARKS:
107
 
                        fsms = fsmenu->fsmenu_bookmarks;
108
 
                        break;
109
 
                case FS_CATEGORY_RECENT:
110
 
                        fsms = fsmenu->fsmenu_recent;
111
 
                        break;
112
 
        }
113
 
        return fsms;
114
 
}
115
 
 
116
 
static void fsmenu_set_category(struct FSMenu* fsmenu, FSMenuCategory category, FSMenuEntry *fsms)
117
 
{
118
 
        switch(category) {
119
 
                case FS_CATEGORY_SYSTEM:
120
 
                        fsmenu->fsmenu_system = fsms;
121
 
                        break;
122
 
                case FS_CATEGORY_BOOKMARKS:
123
 
                        fsmenu->fsmenu_bookmarks = fsms;
124
 
                        break;
125
 
                case FS_CATEGORY_RECENT:
126
 
                        fsmenu->fsmenu_recent = fsms;
127
 
                        break;
128
 
        }
129
 
}
130
 
 
131
 
int fsmenu_get_nentries(struct FSMenu* fsmenu, FSMenuCategory category)
132
 
{
133
 
        FSMenuEntry *fsme;
134
 
        int count= 0;
135
 
 
136
 
        for (fsme= fsmenu_get_category(fsmenu, category); fsme; fsme= fsme->next) 
 
98
static FSMenuEntry *fsmenu_get_category(struct FSMenu *fsmenu, FSMenuCategory category)
 
99
{
 
100
        FSMenuEntry *fsm_head = NULL;
 
101
 
 
102
        switch (category) {
 
103
                case FS_CATEGORY_SYSTEM:
 
104
                        fsm_head = fsmenu->fsmenu_system;
 
105
                        break;
 
106
                case FS_CATEGORY_SYSTEM_BOOKMARKS:
 
107
                        fsm_head = fsmenu->fsmenu_system_bookmarks;
 
108
                        break;
 
109
                case FS_CATEGORY_BOOKMARKS:
 
110
                        fsm_head = fsmenu->fsmenu_bookmarks;
 
111
                        break;
 
112
                case FS_CATEGORY_RECENT:
 
113
                        fsm_head = fsmenu->fsmenu_recent;
 
114
                        break;
 
115
        }
 
116
        return fsm_head;
 
117
}
 
118
 
 
119
static void fsmenu_set_category(struct FSMenu *fsmenu, FSMenuCategory category, FSMenuEntry *fsm_head)
 
120
{
 
121
        switch (category) {
 
122
                case FS_CATEGORY_SYSTEM:
 
123
                        fsmenu->fsmenu_system = fsm_head;
 
124
                        break;
 
125
                case FS_CATEGORY_SYSTEM_BOOKMARKS:
 
126
                        fsmenu->fsmenu_system_bookmarks = fsm_head;
 
127
                        break;
 
128
                case FS_CATEGORY_BOOKMARKS:
 
129
                        fsmenu->fsmenu_bookmarks = fsm_head;
 
130
                        break;
 
131
                case FS_CATEGORY_RECENT:
 
132
                        fsmenu->fsmenu_recent = fsm_head;
 
133
                        break;
 
134
        }
 
135
}
 
136
 
 
137
int fsmenu_get_nentries(struct FSMenu *fsmenu, FSMenuCategory category)
 
138
{
 
139
        FSMenuEntry *fsm_iter;
 
140
        int count = 0;
 
141
 
 
142
        for (fsm_iter = fsmenu_get_category(fsmenu, category); fsm_iter; fsm_iter = fsm_iter->next) {
137
143
                count++;
 
144
        }
138
145
 
139
146
        return count;
140
147
}
141
148
 
142
 
char *fsmenu_get_entry(struct FSMenu* fsmenu, FSMenuCategory category, int idx)
143
 
{
144
 
        FSMenuEntry *fsme;
145
 
 
146
 
        for (fsme= fsmenu_get_category(fsmenu, category); fsme && idx; fsme= fsme->next)
147
 
                idx--;
148
 
 
149
 
        return fsme?fsme->path:NULL;
150
 
}
151
 
 
152
 
short fsmenu_can_save (struct FSMenu* fsmenu, FSMenuCategory category, int idx)
153
 
{
154
 
        FSMenuEntry *fsme;
155
 
 
156
 
        for (fsme= fsmenu_get_category(fsmenu, category); fsme && idx; fsme= fsme->next)
157
 
                idx--;
158
 
 
159
 
        return fsme?fsme->save:0;
160
 
}
161
 
 
162
 
void fsmenu_insert_entry(struct FSMenu* fsmenu, FSMenuCategory category, const char *path, int sorted, short save)
163
 
{
164
 
        FSMenuEntry *prev;
165
 
        FSMenuEntry *fsme;
166
 
        FSMenuEntry *fsms;
167
 
 
168
 
        fsms = fsmenu_get_category(fsmenu, category);
169
 
        prev= fsme= fsms;
170
 
 
171
 
        for (; fsme; prev= fsme, fsme= fsme->next) {
172
 
                if (fsme->path) {
173
 
                        const int cmp_ret= BLI_path_cmp(path, fsme->path);
 
149
char *fsmenu_get_entry(struct FSMenu *fsmenu, FSMenuCategory category, int idx)
 
150
{
 
151
        FSMenuEntry *fsm_iter;
 
152
 
 
153
        for (fsm_iter = fsmenu_get_category(fsmenu, category); fsm_iter && idx; fsm_iter = fsm_iter->next) {
 
154
                idx--;
 
155
        }
 
156
 
 
157
        return fsm_iter ? fsm_iter->path : NULL;
 
158
}
 
159
 
 
160
short fsmenu_can_save(struct FSMenu *fsmenu, FSMenuCategory category, int idx)
 
161
{
 
162
        FSMenuEntry *fsm_iter;
 
163
 
 
164
        for (fsm_iter = fsmenu_get_category(fsmenu, category); fsm_iter && idx; fsm_iter = fsm_iter->next) {
 
165
                idx--;
 
166
        }
 
167
 
 
168
        return fsm_iter ? fsm_iter->save : 0;
 
169
}
 
170
 
 
171
void fsmenu_insert_entry(struct FSMenu *fsmenu, FSMenuCategory category, const char *path, FSMenuInsert flag)
 
172
{
 
173
        FSMenuEntry *fsm_prev;
 
174
        FSMenuEntry *fsm_iter;
 
175
        FSMenuEntry *fsm_head;
 
176
 
 
177
        fsm_head = fsmenu_get_category(fsmenu, category);
 
178
        fsm_prev = fsm_head;  /* this is odd and not really correct? */
 
179
 
 
180
        for (fsm_iter = fsm_head; fsm_iter; fsm_prev = fsm_iter, fsm_iter = fsm_iter->next) {
 
181
                if (fsm_iter->path) {
 
182
                        const int cmp_ret = BLI_path_cmp(path, fsm_iter->path);
174
183
                        if (cmp_ret == 0) {
 
184
                                if (flag & FS_INSERT_FIRST) {
 
185
                                        if (fsm_iter != fsm_head) {
 
186
                                                fsm_prev->next = fsm_iter->next;
 
187
                                                fsm_iter->next = fsm_head;
 
188
                                                fsmenu_set_category(fsmenu, category, fsm_iter);
 
189
                                        }
 
190
                                }
175
191
                                return;
176
192
                        }
177
 
                        else if (sorted && cmp_ret < 0) {
 
193
                        else if ((flag & FS_INSERT_SORTED) && cmp_ret < 0) {
178
194
                                break;
179
195
                        }
180
196
                }
181
197
                else {
182
 
                        // if we're bookmarking this, file should come 
183
 
                        // before the last separator, only automatically added
184
 
                        // current dir go after the last sep.
185
 
                        if (save) {
 
198
                        /* if we're bookmarking this, file should come
 
199
                         * before the last separator, only automatically added
 
200
                         * current dir go after the last sep. */
 
201
                        if (flag & FS_INSERT_SAVE) {
186
202
                                break;
187
203
                        }
188
204
                }
189
205
        }
190
 
        
191
 
        fsme= MEM_mallocN(sizeof(*fsme), "fsme");
192
 
        fsme->path= BLI_strdup(path);
193
 
        fsme->save = save;
194
 
 
195
 
        if (prev) {
196
 
                fsme->next= prev->next;
197
 
                prev->next= fsme;
 
206
 
 
207
        fsm_iter = MEM_mallocN(sizeof(*fsm_iter), "fsme");
 
208
        fsm_iter->path = BLI_strdup(path);
 
209
        fsm_iter->save = (flag & FS_INSERT_SAVE) != 0;
 
210
 
 
211
        if (fsm_prev) {
 
212
                if (flag & FS_INSERT_FIRST) {
 
213
                        fsm_iter->next = fsm_head;
 
214
                        fsmenu_set_category(fsmenu, category, fsm_iter);
 
215
                }
 
216
                else {
 
217
                        fsm_iter->next = fsm_prev->next;
 
218
                        fsm_prev->next = fsm_iter;
 
219
                }
198
220
        }
199
221
        else {
200
 
                fsme->next= fsms;
201
 
                fsmenu_set_category(fsmenu, category, fsme);
 
222
                fsm_iter->next = fsm_head;
 
223
                fsmenu_set_category(fsmenu, category, fsm_iter);
202
224
        }
203
225
}
204
226
 
205
 
void fsmenu_remove_entry(struct FSMenu* fsmenu, FSMenuCategory category, int idx)
 
227
void fsmenu_remove_entry(struct FSMenu *fsmenu, FSMenuCategory category, int idx)
206
228
{
207
 
        FSMenuEntry *prev= NULL, *fsme= NULL;
208
 
        FSMenuEntry *fsms = fsmenu_get_category(fsmenu, category);
209
 
 
210
 
        for (fsme= fsms; fsme && idx; prev= fsme, fsme= fsme->next)             
 
229
        FSMenuEntry *fsm_prev = NULL;
 
230
        FSMenuEntry *fsm_iter;
 
231
        FSMenuEntry *fsm_head;
 
232
 
 
233
        fsm_head = fsmenu_get_category(fsmenu, category);
 
234
 
 
235
        for (fsm_iter = fsm_head; fsm_iter && idx; fsm_prev = fsm_iter, fsm_iter = fsm_iter->next)
211
236
                idx--;
212
237
 
213
 
        if (fsme) {
 
238
        if (fsm_iter) {
214
239
                /* you should only be able to remove entries that were 
215
240
                 * not added by default, like windows drives.
216
241
                 * also separators (where path == NULL) shouldn't be removed */
217
 
                if (fsme->save && fsme->path) {
 
242
                if (fsm_iter->save && fsm_iter->path) {
218
243
 
219
244
                        /* remove fsme from list */
220
 
                        if (prev) {
221
 
                                prev->next= fsme->next;
 
245
                        if (fsm_prev) {
 
246
                                fsm_prev->next = fsm_iter->next;
222
247
                        }
223
248
                        else {
224
 
                                fsms= fsme->next;
225
 
                                fsmenu_set_category(fsmenu, category, fsms);
 
249
                                fsm_head = fsm_iter->next;
 
250
                                fsmenu_set_category(fsmenu, category, fsm_head);
226
251
                        }
227
252
                        /* free entry */
228
 
                        MEM_freeN(fsme->path);
229
 
                        MEM_freeN(fsme);
 
253
                        MEM_freeN(fsm_iter->path);
 
254
                        MEM_freeN(fsm_iter);
230
255
                }
231
256
        }
232
257
}
233
258
 
234
 
void fsmenu_write_file(struct FSMenu* fsmenu, const char *filename)
 
259
void fsmenu_write_file(struct FSMenu *fsmenu, const char *filename)
235
260
{
236
 
        FSMenuEntry *fsme= NULL;
237
 
        int nskip= 0;
 
261
        FSMenuEntry *fsm_iter = NULL;
 
262
        int nwritten = 0;
238
263
 
239
264
        FILE *fp = BLI_fopen(filename, "w");
240
265
        if (!fp) return;
241
266
        
242
267
        fprintf(fp, "[Bookmarks]\n");
243
 
        for (fsme= fsmenu_get_category(fsmenu, FS_CATEGORY_BOOKMARKS); fsme; fsme= fsme->next) {
244
 
                if (fsme->path && fsme->save) {
245
 
                        fprintf(fp, "%s\n", fsme->path);
 
268
        for (fsm_iter = fsmenu_get_category(fsmenu, FS_CATEGORY_BOOKMARKS); fsm_iter; fsm_iter = fsm_iter->next) {
 
269
                if (fsm_iter->path && fsm_iter->save) {
 
270
                        fprintf(fp, "%s\n", fsm_iter->path);
246
271
                }
247
272
        }
248
273
        fprintf(fp, "[Recent]\n");
249
 
        nskip = fsmenu_get_nentries(fsmenu, FS_CATEGORY_RECENT) - FSMENU_RECENT_MAX;
250
 
        // skip first entries if list too long
251
 
        for (fsme= fsmenu_get_category(fsmenu, FS_CATEGORY_RECENT); fsme && (nskip>0); fsme= fsme->next, --nskip) {
252
 
                /* pass */
253
 
        }
254
 
        for (; fsme; fsme= fsme->next) {
255
 
                if (fsme->path && fsme->save) {
256
 
                        fprintf(fp, "%s\n", fsme->path);
 
274
        for (fsm_iter = fsmenu_get_category(fsmenu, FS_CATEGORY_RECENT); fsm_iter && (nwritten < FSMENU_RECENT_MAX); fsm_iter = fsm_iter->next, ++nwritten) {
 
275
                if (fsm_iter->path && fsm_iter->save) {
 
276
                        fprintf(fp, "%s\n", fsm_iter->path);
257
277
                }
258
278
        }
259
279
        fclose(fp);
260
280
}
261
281
 
262
 
void fsmenu_read_bookmarks(struct FSMenu* fsmenu, const char *filename)
 
282
void fsmenu_read_bookmarks(struct FSMenu *fsmenu, const char *filename)
263
283
{
264
284
        char line[256];
265
285
        FSMenuCategory category = FS_CATEGORY_BOOKMARKS;
268
288
        fp = BLI_fopen(filename, "r");
269
289
        if (!fp) return;
270
290
 
271
 
        while ( fgets ( line, 256, fp ) != NULL ) /* read a line */
272
 
        {
273
 
                if (strncmp(line, "[Bookmarks]", 11)==0) {
 
291
        while (fgets(line, 256, fp) != NULL) {       /* read a line */
 
292
                if (strncmp(line, "[Bookmarks]", 11) == 0) {
274
293
                        category = FS_CATEGORY_BOOKMARKS;
275
294
                }
276
 
                else if (strncmp(line, "[Recent]", 8)==0) {
 
295
                else if (strncmp(line, "[Recent]", 8) == 0) {
277
296
                        category = FS_CATEGORY_RECENT;
278
297
                }
279
298
                else {
280
299
                        int len = strlen(line);
281
 
                        if (len>0) {
282
 
                                if (line[len-1] == '\n') {
283
 
                                        line[len-1] = '\0';
 
300
                        if (len > 0) {
 
301
                                if (line[len - 1] == '\n') {
 
302
                                        line[len - 1] = '\0';
284
303
                                }
285
 
                                if (BLI_exists(line)) {
286
 
                                        fsmenu_insert_entry(fsmenu, category, line, 0, 1);
 
304
                                /* don't do this because it can be slow on network drives,
 
305
                                 * having a bookmark from a drive thats ejected or so isn't
 
306
                                 * all _that_ bad */
 
307
#if 0
 
308
                                if (BLI_exists(line))
 
309
#endif
 
310
                                {
 
311
                                        fsmenu_insert_entry(fsmenu, category, line, FS_INSERT_SAVE);
287
312
                                }
288
313
                        }
289
314
                }
291
316
        fclose(fp);
292
317
}
293
318
 
294
 
void fsmenu_read_system(struct FSMenu* fsmenu)
 
319
void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
295
320
{
296
321
        char line[256];
297
322
#ifdef WIN32
301
326
                char tmps[4];
302
327
                int i;
303
328
                        
304
 
                tmp= GetLogicalDrives();
 
329
                tmp = GetLogicalDrives();
305
330
                
306
 
                for (i=0; i < 26; i++) {
307
 
                        if ((tmp>>i) & 1) {
308
 
                                tmps[0]='A'+i;
309
 
                                tmps[1]=':';
310
 
                                tmps[2]='\\';
311
 
                                tmps[3]=0;
 
331
                for (i = 0; i < 26; i++) {
 
332
                        if ((tmp >> i) & 1) {
 
333
                                tmps[0] = 'A' + i;
 
334
                                tmps[1] = ':';
 
335
                                tmps[2] = '\\';
 
336
                                tmps[3] = 0;
312
337
                                
313
 
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, tmps, 1, 0);
 
338
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, tmps, FS_INSERT_SORTED);
314
339
                        }
315
340
                }
316
341
 
317
342
                /* Adding Desktop and My Documents */
318
 
                SHGetSpecialFolderPath(0, line, CSIDL_PERSONAL, 0);
319
 
                fsmenu_insert_entry(fsmenu,FS_CATEGORY_BOOKMARKS, line, 1, 0);
320
 
                SHGetSpecialFolderPath(0, line, CSIDL_DESKTOPDIRECTORY, 0);
321
 
                fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
 
343
                if (read_bookmarks) {
 
344
                        SHGetSpecialFolderPath(0, line, CSIDL_PERSONAL, 0);
 
345
                        fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, FS_INSERT_SORTED);
 
346
                        SHGetSpecialFolderPath(0, line, CSIDL_DESKTOPDIRECTORY, 0);
 
347
                        fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, FS_INSERT_SORTED);
 
348
                }
322
349
        }
323
350
#else
324
351
#ifdef __APPLE__
325
352
        {
326
 
#if (MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4)
327
 
                OSErr err=noErr;
 
353
#if (MAC_OS_X_VERSION_MIN_REQUIRED <= 1040)
 
354
                OSErr err = noErr;
328
355
                int i;
329
356
                const char *home;
330
357
                
331
358
                /* loop through all the OS X Volumes, and add them to the SYSTEM section */
332
 
                for (i=1; err!=nsvErr; i++)
333
 
                {
 
359
                for (i = 1; err != nsvErr; i++) {
334
360
                        FSRef dir;
335
361
                        unsigned char path[FILE_MAX];
336
362
                        
339
365
                                continue;
340
366
                        
341
367
                        FSRefMakePath(&dir, path, FILE_MAX);
342
 
                        if (strcmp((char*)path, "/home") && strcmp((char*)path, "/net")) {
 
368
                        if (strcmp((char *)path, "/home") && strcmp((char *)path, "/net")) {
343
369
                                /* /net and /home are meaningless on OSX, home folders are stored in /Users */
344
 
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, (char *)path, 1, 0);
 
370
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, (char *)path, FS_INSERT_SORTED);
345
371
                        }
346
372
                }
347
373
 
349
375
                 * assume they are the standard ones 
350
376
                 * TODO : replace hardcoded paths with proper BLI_get_folder calls */
351
377
                home = getenv("HOME");
352
 
                if (home) {
 
378
                if (read_bookmarks && home) {
353
379
                        BLI_snprintf(line, 256, "%s/", home);
354
 
                        fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
 
380
                        fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, FS_INSERT_SORTED);
355
381
                        BLI_snprintf(line, 256, "%s/Desktop/", home);
356
382
                        if (BLI_exists(line)) {
357
 
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
 
383
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, FS_INSERT_SORTED);
358
384
                        }
359
385
                        BLI_snprintf(line, 256, "%s/Documents/", home);
360
386
                        if (BLI_exists(line)) {
361
 
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
 
387
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, FS_INSERT_SORTED);
362
388
                        }
363
389
                        BLI_snprintf(line, 256, "%s/Pictures/", home);
364
390
                        if (BLI_exists(line)) {
365
 
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
 
391
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, FS_INSERT_SORTED);
366
392
                        }
367
393
                        BLI_snprintf(line, 256, "%s/Music/", home);
368
394
                        if (BLI_exists(line)) {
369
 
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
 
395
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, FS_INSERT_SORTED);
370
396
                        }
371
397
                        BLI_snprintf(line, 256, "%s/Movies/", home);
372
398
                        if (BLI_exists(line)) {
373
 
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
 
399
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, FS_INSERT_SORTED);
374
400
                        }
375
401
                }
376
402
#else
389
415
                pathesArray = LSSharedFileListCopySnapshot(list, &seed);
390
416
                pathesCount = CFArrayGetCount(pathesArray);
391
417
                
392
 
                for (i=0; i<pathesCount; i++)
393
 
                {
 
418
                for (i = 0; i < pathesCount; i++) {
394
419
                        itemRef = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(pathesArray, i);
395
420
                        
396
421
                        err = LSSharedFileListItemResolve(itemRef, 
397
 
                                                                                          kLSSharedFileListNoUserInteraction
398
 
                                                                                          | kLSSharedFileListDoNotMountVolumes, 
399
 
                                                                                          &cfURL, NULL);
 
422
                                                          kLSSharedFileListNoUserInteraction |
 
423
                                                          kLSSharedFileListDoNotMountVolumes,
 
424
                                                          &cfURL, NULL);
400
425
                        if (err != noErr)
401
426
                                continue;
402
427
                        
403
428
                        pathString = CFURLCopyFileSystemPath(cfURL, kCFURLPOSIXPathStyle);
404
429
                        
405
 
                        if (!CFStringGetCString(pathString,line,256,kCFStringEncodingASCII))
 
430
                        if (!CFStringGetCString(pathString, line, 256, kCFStringEncodingASCII))
406
431
                                continue;
407
 
                        fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, line, 1, 0);
 
432
                        fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, line, FS_INSERT_SORTED);
408
433
                        
409
434
                        CFRelease(pathString);
410
435
                        CFRelease(cfURL);
415
440
                
416
441
                /* Then get network volumes */
417
442
                err = noErr;
418
 
                for (i=1; err!=nsvErr; i++)
419
 
                {
 
443
                for (i = 1; err != nsvErr; i++) {
420
444
                        FSRef dir;
421
445
                        FSVolumeRefNum volRefNum;
422
446
                        struct GetVolParmsInfoBuffer volParmsBuffer;
432
456
                        
433
457
                        
434
458
                        FSRefMakePath(&dir, path, FILE_MAX);
435
 
                        fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, (char *)path, 1, 0);
 
459
                        if (strcmp((char *)path, "/home") && strcmp((char *)path, "/net")) {
 
460
                                /* /net and /home are meaningless on OSX, home folders are stored in /Users */
 
461
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, (char *)path, FS_INSERT_SORTED);
 
462
                        }
436
463
                }
437
464
                
438
465
                /* Finally get user favorite places */
439
 
                list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL);
440
 
                pathesArray = LSSharedFileListCopySnapshot(list, &seed);
441
 
                pathesCount = CFArrayGetCount(pathesArray);
442
 
                
443
 
                for (i=0; i<pathesCount; i++)
444
 
                {
445
 
                        itemRef = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(pathesArray, i);
446
 
                        
447
 
                        err = LSSharedFileListItemResolve(itemRef, 
448
 
                                                                                          kLSSharedFileListNoUserInteraction
449
 
                                                                                          | kLSSharedFileListDoNotMountVolumes, 
450
 
                                                                                          &cfURL, NULL);
451
 
                        if (err != noErr)
452
 
                                continue;
453
 
                        
454
 
                        pathString = CFURLCopyFileSystemPath(cfURL, kCFURLPOSIXPathStyle);
455
 
                        
456
 
                        if (!CFStringGetCString(pathString,line,256,kCFStringEncodingASCII))
457
 
                                continue;
458
 
                        fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
459
 
                        
460
 
                        CFRelease(pathString);
461
 
                        CFRelease(cfURL);
 
466
                if (read_bookmarks) {
 
467
                        list = LSSharedFileListCreate(NULL, kLSSharedFileListFavoriteItems, NULL);
 
468
                        pathesArray = LSSharedFileListCopySnapshot(list, &seed);
 
469
                        pathesCount = CFArrayGetCount(pathesArray);
 
470
                        
 
471
                        for (i = 0; i < pathesCount; i++) {
 
472
                                itemRef = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(pathesArray, i);
 
473
                                
 
474
                                err = LSSharedFileListItemResolve(itemRef, 
 
475
                                                                  kLSSharedFileListNoUserInteraction |
 
476
                                                                  kLSSharedFileListDoNotMountVolumes,
 
477
                                                                  &cfURL, NULL);
 
478
                                if (err != noErr)
 
479
                                        continue;
 
480
                                
 
481
                                pathString = CFURLCopyFileSystemPath(cfURL, kCFURLPOSIXPathStyle);
 
482
                                
 
483
                                if (!CFStringGetCString(pathString, line, 256, kCFStringEncodingASCII))
 
484
                                        continue;
 
485
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, FS_INSERT_SORTED);
 
486
                                
 
487
                                CFRelease(pathString);
 
488
                                CFRelease(cfURL);
 
489
                        }
 
490
                        
 
491
                        CFRelease(pathesArray);
 
492
                        CFRelease(list);
462
493
                }
463
 
                
464
 
                CFRelease(pathesArray);
465
 
                CFRelease(list);
466
494
#endif /* OSX 10.5+ */
467
495
        }
468
496
#else
469
497
        /* unix */
470
498
        {
471
 
                const char *home= getenv("HOME");
 
499
                const char *home = getenv("HOME");
472
500
 
473
 
                if (home) {
 
501
                if (read_bookmarks && home) {
474
502
                        BLI_snprintf(line, FILE_MAXDIR, "%s/", home);
475
 
                        fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
 
503
                        fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, FS_INSERT_SORTED);
476
504
                        BLI_snprintf(line, FILE_MAXDIR, "%s/Desktop/", home);
477
505
                        if (BLI_exists(line)) {
478
 
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, line, 1, 0);
 
506
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, FS_INSERT_SORTED);
479
507
                        }
480
508
                }
481
509
 
482
510
                {
483
 
                        int found= 0;
 
511
                        int found = 0;
484
512
#ifdef __linux__
485
513
                        /* loop over mount points */
486
514
                        struct mntent *mnt;
487
515
                        int len;
488
516
                        FILE *fp;
489
517
 
490
 
                        fp = setmntent (MOUNTED, "r");
 
518
                        fp = setmntent(MOUNTED, "r");
491
519
                        if (fp == NULL) {
492
520
                                fprintf(stderr, "could not get a list of mounted filesystemts\n");
493
521
                        }
494
522
                        else {
495
 
                                while ((mnt = getmntent (fp))) {
 
523
                                while ((mnt = getmntent(fp))) {
496
524
                                        /* not sure if this is right, but seems to give the relevant mnts */
497
525
                                        if (strncmp(mnt->mnt_fsname, "/dev", 4))
498
526
                                                continue;
499
527
 
500
 
                                        len= strlen(mnt->mnt_dir);
501
 
                                        if (len && mnt->mnt_dir[len-1] != '/') {
 
528
                                        len = strlen(mnt->mnt_dir);
 
529
                                        if (len && mnt->mnt_dir[len - 1] != '/') {
502
530
                                                BLI_snprintf(line, FILE_MAXDIR, "%s/", mnt->mnt_dir);
503
 
                                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, line, 1, 0);
504
 
                                        }
505
 
                                        else
506
 
                                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, mnt->mnt_dir, 1, 0);
 
531
                                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, line, FS_INSERT_SORTED);
 
532
                                        }
 
533
                                        else {
 
534
                                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, mnt->mnt_dir, FS_INSERT_SORTED);
 
535
                                        }
507
536
 
508
 
                                        found= 1;
 
537
                                        found = 1;
509
538
                                }
510
 
                                if (endmntent (fp) == 0) {
 
539
                                if (endmntent(fp) == 0) {
511
540
                                        fprintf(stderr, "could not close the list of mounted filesystemts\n");
512
541
                                }
513
542
                        }
515
544
 
516
545
                        /* fallback */
517
546
                        if (!found)
518
 
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, "/", 1, 0);
519
 
                }
520
 
        }
521
 
#endif
522
 
#endif
523
 
}
524
 
 
525
 
 
526
 
static void fsmenu_free_category(struct FSMenu* fsmenu, FSMenuCategory category)
527
 
{
528
 
        FSMenuEntry *fsme= fsmenu_get_category(fsmenu, category);
529
 
 
530
 
        while (fsme) {
531
 
                FSMenuEntry *n= fsme->next;
532
 
 
533
 
                if (fsme->path) MEM_freeN(fsme->path);
534
 
                MEM_freeN(fsme);
535
 
 
536
 
                fsme= n;
537
 
        }
538
 
}
539
 
 
540
 
void fsmenu_free(struct FSMenu* fsmenu)
541
 
{
542
 
        fsmenu_free_category(fsmenu, FS_CATEGORY_SYSTEM);
 
547
                                fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM, "/", FS_INSERT_SORTED);
 
548
                }
 
549
        }
 
550
#endif
 
551
#endif
 
552
}
 
553
 
 
554
 
 
555
static void fsmenu_free_category(struct FSMenu *fsmenu, FSMenuCategory category)
 
556
{
 
557
        FSMenuEntry *fsm_iter = fsmenu_get_category(fsmenu, category);
 
558
 
 
559
        while (fsm_iter) {
 
560
                FSMenuEntry *fsm_next = fsm_iter->next;
 
561
 
 
562
                if (fsm_iter->path) {
 
563
                        MEM_freeN(fsm_iter->path);
 
564
                }
 
565
                MEM_freeN(fsm_iter);
 
566
 
 
567
                fsm_iter = fsm_next;
 
568
        }
 
569
}
 
570
 
 
571
void fsmenu_refresh_system_category(struct FSMenu *fsmenu)
 
572
{
 
573
        fsmenu_free_category(fsmenu, FS_CATEGORY_SYSTEM);
 
574
        fsmenu_set_category(fsmenu, FS_CATEGORY_SYSTEM, NULL);
 
575
 
 
576
        fsmenu_free_category(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS);
 
577
        fsmenu_set_category(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, NULL);
 
578
 
 
579
        /* Add all entries to system category */
 
580
        fsmenu_read_system(fsmenu, TRUE);
 
581
}
 
582
 
 
583
void fsmenu_free(struct FSMenu *fsmenu)
 
584
{
 
585
        fsmenu_free_category(fsmenu, FS_CATEGORY_SYSTEM);
 
586
        fsmenu_free_category(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS);
543
587
        fsmenu_free_category(fsmenu, FS_CATEGORY_BOOKMARKS);
544
588
        fsmenu_free_category(fsmenu, FS_CATEGORY_RECENT);
545
589
        MEM_freeN(fsmenu);
546
590
}
547