annotate src/filelist.c @ 25:0c3b353b666e

Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net> * image.c: Connect to 'zoom' signal of pixbuf-renderer and notify listener to update. Fix delay flip by listening for 'render_complete'. * pixbuf-renderer.[ch]: Add complete property and and emit a 'render-complete' signal when changing complete back to TRUE. * view_dir_tree.c (vdtree_row_expanded): Populate a folder node whenever it is expanded. ##### Note: GQview CVS on sourceforge is not always up to date, please use ##### ##### an offical release when making enhancements and translation updates. #####
author gqview
date Sat, 26 Mar 2005 03:50:35 +0000
parents 3263965d5f9e
children ee03f36e9e4b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1 /*
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
2 * GQview
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
3 * (C) 2004 John Ellis
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
4 *
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
5 * Author: John Ellis
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
6 *
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
7 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
8 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
9 * This software comes with no warranty of any kind, use at your own risk!
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
10 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
11
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
12
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
13 #include "gqview.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
14 #include "filelist.h"
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
15
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
16 #include "cache.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
17 #include "rcfile.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
18 #include "ui_fileops.h"
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
19
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
20
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
21 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
22 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
23 * file filtering
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
24 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
25 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
26
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
27 static GList *filter_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
28 static GList *extension_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
29
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
30 gint ishidden(const gchar *name)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
31 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
32 if (name[0] != '.') return FALSE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
33 if (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')) return FALSE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
34 return TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
35 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
36
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
37 static FilterEntry *filter_entry_new(const gchar *key, const gchar *description,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
38 const gchar *extensions, gint enabled)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
39 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
40 FilterEntry *fe;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
41
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
42 fe = g_new0(FilterEntry, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
43 fe->key = g_strdup(key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
44 fe->description = g_strdup(description);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
45 fe->extensions = g_strdup(extensions);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
46 fe->enabled = enabled;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
47
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
48 return fe;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
49 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
50
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
51 static void filter_entry_free(FilterEntry *fe)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
52 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
53 if (!fe) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
54
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
55 g_free(fe->key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
56 g_free(fe->description);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
57 g_free(fe->extensions);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
58 g_free(fe);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
59 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
60
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
61 GList *filter_get_list(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
62 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
63 return filter_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
64 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
65
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
66 void filter_remove_entry(FilterEntry *fe)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
67 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
68 if (!g_list_find(filter_list, fe)) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
69
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
70 filter_list = g_list_remove(filter_list, fe);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
71 filter_entry_free(fe);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
72 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
73
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
74 static gint filter_key_exists(const gchar *key)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
75 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
76 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
77
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
78 if (!key) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
79
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
80 work = filter_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
81 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
82 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
83 FilterEntry *fe = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
84 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
85
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
86 if (strcmp(fe->key, key) == 0) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
87 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
88
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
89 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
90 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
91
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
92 void filter_add(const gchar *key, const gchar *description, const gchar *extensions, gint enabled)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
93 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
94 filter_list = g_list_append(filter_list, filter_entry_new(key, description, extensions, enabled));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
95 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
96
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
97 void filter_add_unique(const gchar *description, const gchar *extensions, gint enabled)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
98 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
99 gchar *key;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
100 gint n;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
101
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
102 key = g_strdup("user0");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
103 n = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
104 while (filter_key_exists(key))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
105 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
106 g_free(key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
107 if (n > 999) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
108 key = g_strdup_printf("user%d", n);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
109 n++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
110 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
111
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
112 filter_add(key, description, extensions, enabled);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
113 g_free(key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
114 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
115
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
116 static void filter_add_if_missing(const gchar *key, const gchar *description, const gchar *extensions, gint enabled)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
117 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
118 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
119
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
120 if (!key) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
121
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
122 work = filter_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
123 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
124 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
125 FilterEntry *fe = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
126 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
127 if (fe->key && strcmp(fe->key, key) == 0) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
128 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
129
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
130 filter_add(key, description, extensions, enabled);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
131 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
132
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
133 void filter_reset(void)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
134 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
135 GList *work;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
136
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
137 work = filter_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
138 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
139 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
140 FilterEntry *fe = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
141 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
142 filter_entry_free(fe);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
143 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
144
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
145 g_list_free(filter_list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
146 filter_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
147 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
148
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
149 void filter_add_defaults(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
150 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
151 GSList *list, *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
152
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
153 list = gdk_pixbuf_get_formats();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
154 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
155 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
156 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
157 GdkPixbufFormat *format;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
158 gchar *name;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
159 gchar *desc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
160 gchar **extensions;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
161 GString *filter = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
162 gint i;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
163
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
164 format = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
165 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
166
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
167 name = gdk_pixbuf_format_get_name(format);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
168 desc = gdk_pixbuf_format_get_description(format);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
169 extensions = gdk_pixbuf_format_get_extensions(format);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
170
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
171 i = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
172 while (extensions[i])
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
173 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
174 if (!filter)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
175 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
176 filter = g_string_new(".");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
177 filter = g_string_append(filter, extensions[i]);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
178 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
179 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
180 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
181 filter = g_string_append(filter, ";.");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
182 filter = g_string_append(filter, extensions[i]);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
183 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
184 i++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
185 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
186
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
187 if (debug) printf("loader reported [%s] [%s] [%s]\n", name, desc, filter->str);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
188
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
189 filter_add_if_missing(name, desc, filter->str, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
190
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
191 g_free(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
192 g_free(desc);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
193 g_strfreev(extensions);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
194 g_string_free(filter, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
195 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
196 g_slist_free(list);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
197
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
198 /* add defaults even if gdk-pixbuf does not have them, but disabled */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
199 filter_add_if_missing("jpeg", "JPEG group", ".jpg;.jpeg;.jpe", FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
200 filter_add_if_missing("png", "Portable Network Graphic", ".png", FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
201 filter_add_if_missing("tiff", "Tiff", ".tif;.tiff", FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
202 filter_add_if_missing("pnm", "Packed Pixel formats", ".pbm;.pgm;.pnm;.ppm", FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
203 filter_add_if_missing("gif", "Graphics Interchange Format", ".gif", FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
204 filter_add_if_missing("xbm", "X bitmap", ".xbm", FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
205 filter_add_if_missing("xpm", "X pixmap", ".xpm", FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
206 filter_add_if_missing("bmp", "Bitmap", ".bmp", FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
207 filter_add_if_missing("ico", "Icon file", ".ico;.cur", FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
208 filter_add_if_missing("ras", "Raster", ".ras", FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
209 filter_add_if_missing("svg", "Scalable Vector Graphics", ".svg", FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
210 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
211
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
212 static GList *filter_to_list(const gchar *extensions)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
213 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
214 GList *list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
215 const gchar *p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
216
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
217 if (!extensions) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
218
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
219 p = extensions;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
220 while (*p != '\0')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
221 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
222 const gchar *b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
223 gint l = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
224
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
225 b = p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
226 while (*p != '\0' && *p != ';')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
227 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
228 p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
229 l++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
230 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
231 list = g_list_append(list, g_strndup(b, l));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
232 if (*p == ';') p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
233 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
234
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
235 return list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
236 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
237
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
238 void filter_rebuild(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
239 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
240 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
241
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
242 path_list_free(extension_list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
243 extension_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
244
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
245 work = filter_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
246 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
247 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
248 FilterEntry *fe;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
249
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
250 fe = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
251 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
252
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
253 if (fe->enabled)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
254 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
255 GList *ext;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
256
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
257 ext = filter_to_list(fe->extensions);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
258 if (ext) extension_list = g_list_concat(extension_list, ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
259 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
260 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
261 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
262
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
263 gint filter_name_exists(const gchar *name)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
264 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
265 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
266 if (!extension_list || file_filter_disable) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
267
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
268 work = extension_list;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
269 while (work)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
270 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
271 gchar *filter = work->data;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
272 gint lf = strlen(filter);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
273 gint ln = strlen(name);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
274 if (ln >= lf)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
275 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
276 if (strncasecmp(name + ln - lf, filter, lf) == 0) return TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
277 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
278 work = work->next;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
279 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
280
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
281 return FALSE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
282 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
283
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
284 void filter_write_list(FILE *f)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
285 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
286 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
287
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
288 work = filter_list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
289 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
290 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
291 FilterEntry *fe = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
292 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
293
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
294 fprintf(f, "filter_ext: \"%s%s\" \"%s\" \"%s\"\n", (fe->enabled) ? "" : "#",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
295 fe->key, fe->extensions,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
296 (fe->description) ? fe->description : "");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
297 }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
298 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
299
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
300 void filter_parse(const gchar *text)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
301 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
302 const gchar *p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
303 gchar *key;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
304 gchar *ext;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
305 gchar *desc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
306 gint enabled = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
307
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
308 if (!text || text[0] != '"') return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
309
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
310 key = quoted_value(text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
311 if (!key) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
312
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
313 p = text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
314 p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
315 while (*p != '"' && *p != '\0') p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
316 if (*p != '"')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
317 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
318 g_free(key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
319 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
320 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
321 p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
322 while (*p != '"' && *p != '\0') p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
323 if (*p != '"')
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
324 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
325 g_free(key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
326 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
327 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
328
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
329 ext = quoted_value(p);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
330
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
331 p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
332 while (*p != '"' && *p != '\0') p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
333 if (*p == '"') p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
334 while (*p != '"' && *p != '\0') p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
335
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
336 if (*p == '"')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
337 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
338 desc = quoted_value(p);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
339 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
340 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
341 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
342 desc = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
343 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
344
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
345 if (key && key[0] == '#')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
346 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
347 gchar *tmp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
348 tmp = g_strdup(key + 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
349 g_free(key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
350 key = tmp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
351
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
352 enabled = FALSE;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
353 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
354
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
355 if (key && strlen(key) > 0 && ext) filter_add(key, desc, ext, enabled);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
356
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
357 g_free(key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
358 g_free(ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
359 g_free(desc);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
360 }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
361
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
362 GList *path_list_filter(GList *list, gint is_dir_list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
363 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
364 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
365
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
366 if (!is_dir_list && file_filter_disable && show_dot_files) return list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
367
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
368 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
369 while (work)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
370 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
371 gchar *name = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
372 const gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
373
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
374 base = filename_from_path(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
375
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
376 if ((!show_dot_files && ishidden(base)) ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
377 (!is_dir_list && !filter_name_exists(base)) ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
378 (is_dir_list && base[0] == '.' && (strcmp(base, GQVIEW_CACHE_LOCAL_THUMB) == 0 ||
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
379 strcmp(base, GQVIEW_CACHE_LOCAL_METADATA) == 0)) )
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
380 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
381 GList *link = work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
382 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
383 list = g_list_remove_link(list, link);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
384 g_free(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
385 g_list_free(link);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
386 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
387 else
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
388 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
389 work = work->next;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
390 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
391 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
392
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
393 return list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
394 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
395
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
396 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
397 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
398 * path list recursive
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
399 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
400 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
401
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
402 static gint path_list_sort_cb(gconstpointer a, gconstpointer b)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
403 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
404 return CASE_SORT((gchar *)a, (gchar *)b);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
405 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
406
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
407 GList *path_list_sort(GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
408 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
409 return g_list_sort(list, path_list_sort_cb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
410 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
411
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
412 static void path_list_recursive_append(GList **list, GList *dirs)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
413 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
414 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
415
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
416 work = dirs;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
417 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
418 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
419 const gchar *path = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
420 GList *f = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
421 GList *d = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
422
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
423 if (path_list(path, &f, &d))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
424 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
425 f = path_list_filter(f, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
426 f = path_list_sort(f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
427 *list = g_list_concat(*list, f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
428
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
429 d = path_list_filter(d, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
430 d = path_list_sort(d);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
431 path_list_recursive_append(list, d);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
432 g_list_free(d);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
433 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
434
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
435 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
436 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
437 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
438
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
439 GList *path_list_recursive(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
440 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
441 GList *list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
442 GList *d = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
443
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
444 if (!path_list(path, &list, &d)) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
445 list = path_list_filter(list, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
446 list = path_list_sort(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
447
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
448 d = path_list_filter(d, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
449 d = path_list_sort(d);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
450 path_list_recursive_append(&list, d);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
451 path_list_free(d);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
452
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
453 return list;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
454 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
455
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
456 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
457 *-----------------------------------------------------------------------------
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
458 * text conversion utils
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
459 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
460 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
461
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
462 gchar *text_from_size(gint64 size)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
463 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
464 gchar *a, *b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
465 gchar *s, *d;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
466 gint l, n, i;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
467
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
468 /* what I would like to use is printf("%'d", size)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
469 * BUT: not supported on every libc :(
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
470 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
471 if (size > G_MAXUINT)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
472 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
473 /* the %lld conversion is not valid in all libcs, so use a simple work-around */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
474 a = g_strdup_printf("%d%09d", (guint)(size / 1000000000), (guint)(size % 1000000000));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
475 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
476 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
477 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
478 a = g_strdup_printf("%d", (guint)size);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
479 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
480 l = strlen(a);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
481 n = (l - 1)/ 3;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
482 if (n < 1) return a;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
483
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
484 b = g_new(gchar, l + n + 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
485
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
486 s = a;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
487 d = b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
488 i = l - n * 3;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
489 while (*s != '\0')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
490 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
491 if (i < 1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
492 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
493 i = 3;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
494 *d = ',';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
495 d++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
496 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
497
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
498 *d = *s;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
499 s++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
500 d++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
501 i--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
502 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
503 *d = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
504
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
505 g_free(a);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
506 return b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
507 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
508
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
509 gchar *text_from_size_abrev(gint64 size)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
510 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
511 if (size < (gint64)1024)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
512 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
513 return g_strdup_printf(_("%d bytes"), (gint)size);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
514 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
515 if (size < (gint64)1048576)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
516 {
15
3263965d5f9e ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
517 return g_strdup_printf(_("%.1f K"), (double)size / 1024.0);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
518 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
519 if (size < (gint64)1073741824)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
520 {
15
3263965d5f9e ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
521 return g_strdup_printf(_("%.1f MB"), (double)size / 1048576.0);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
522 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
523
15
3263965d5f9e ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
524 /* to avoid overflowing the double, do division in two steps */
3263965d5f9e ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
525 size /= 1048576;
3263965d5f9e ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
526 return g_strdup_printf(_("%.1f GB"), (double)size / 1024.0);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
527 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
528
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
529 /* note: returned string is valid until next call to text_from_time() */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
530 const gchar *text_from_time(time_t t)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
531 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
532 static gchar *ret = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
533 gchar buf[128];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
534 gint buflen;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
535 struct tm *btime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
536 GError *error = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
537
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
538 btime = localtime(&t);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
539
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
540 /* the %x warning about 2 digit years is not an error */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
541 buflen = strftime(buf, sizeof(buf), "%x %H:%M", btime);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
542 if (buflen < 1) return "";
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
543
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
544 g_free(ret);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
545 ret = g_locale_to_utf8(buf, buflen, NULL, NULL, &error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
546 if (error)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
547 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
548 printf("Error converting locale strftime to UTF-8: %s\n", error->message);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
549 g_error_free(error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
550 return "";
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
551 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
552
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
553 return ret;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
554 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
555
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
556 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
557 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
558 * file info struct
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
559 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
560 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
561
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
562 FileData *file_data_new(const gchar *path, struct stat *st)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
563 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
564 FileData *fd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
565
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
566 fd = g_new0(FileData, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
567 fd->path = path_to_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
568 fd->name = filename_from_path(fd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
569 fd->size = st->st_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
570 fd->date = st->st_mtime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
571 fd->pixbuf = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
572
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
573 return fd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
574 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
575
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
576 FileData *file_data_new_simple(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
577 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
578 FileData *fd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
579 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
580
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
581 fd = g_new0(FileData, 1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
582 fd->path = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
583 fd->name = filename_from_path(fd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
584
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
585 if (stat_utf8(fd->path, &st))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
586 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
587 fd->size = st.st_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
588 fd->date = st.st_mtime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
589 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
590
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
591 fd->pixbuf = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
592
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
593 return fd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
594 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
595
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
596 void file_data_free(FileData *fd)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
597 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
598 g_free(fd->path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
599 if (fd->pixbuf) g_object_unref(fd->pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
600 g_free(fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
601 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
602
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
603 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
604 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
605 * load file list
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
606 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
607 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
608
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
609 static SortType filelist_sort_method = SORT_NONE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
610 static gint filelist_sort_ascend = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
611
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
612 static gint sort_file_cb(void *a, void *b)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
613 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
614 FileData *fa = a;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
615 FileData *fb = b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
616
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
617 if (!filelist_sort_ascend)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
618 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
619 fa = b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
620 fb = a;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
621 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
622
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
623 switch (filelist_sort_method)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
624 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
625 case SORT_SIZE:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
626 if (fa->size < fb->size) return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
627 if (fa->size > fb->size) return 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
628 return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
629 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
630 case SORT_TIME:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
631 if (fa->date < fb->date) return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
632 if (fa->date > fb->date) return 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
633 return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
634 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
635 #ifdef HAVE_STRVERSCMP
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
636 case SORT_NUMBER:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
637 return strverscmp(fa->name, fb->name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
638 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
639 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
640 case SORT_NAME:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
641 default:
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
642 return CASE_SORT(fa->name, fb->name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
643 break;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
644 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
645 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
646
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
647 GList *filelist_sort(GList *list, SortType method, gint ascend)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
648 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
649 filelist_sort_method = method;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
650 filelist_sort_ascend = ascend;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
651 return g_list_sort(list, (GCompareFunc) sort_file_cb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
652 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
653
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
654 GList *filelist_insert_sort(GList *list, FileData *fd, SortType method, gint ascend)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
655 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
656 filelist_sort_method = method;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
657 filelist_sort_ascend = ascend;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
658 return g_list_insert_sorted(list, fd, (GCompareFunc) sort_file_cb);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
659 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
660
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
661 gint filelist_read(const gchar *path, GList **files, GList **dirs)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
662 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
663 DIR *dp;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
664 struct dirent *dir;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
665 struct stat ent_sbuf;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
666 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
667 GList *dlist;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
668 GList *flist;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
669
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
670 dlist = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
671 flist = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
672
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
673 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
674 if (!pathl || (dp = opendir(pathl)) == NULL)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
675 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
676 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
677 if (files) *files = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
678 if (dirs) *dirs = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
679 return FALSE;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
680 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
681
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
682 /* root dir fix */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
683 if (pathl[0] == '/' && pathl[1] == '\0')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
684 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
685 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
686 pathl = g_strdup("");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
687 }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
688
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
689 while ((dir = readdir(dp)) != NULL)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
690 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
691 gchar *name = dir->d_name;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
692 if (show_dot_files || !ishidden(name))
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
693 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
694 gchar *filepath = g_strconcat(pathl, "/", name, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
695 if (stat(filepath, &ent_sbuf) >= 0)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
696 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
697 if (S_ISDIR(ent_sbuf.st_mode))
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
698 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
699 /* we ignore the .thumbnails dir for cleanliness */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
700 if ((dirs) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
701 !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
702 strcmp(name, GQVIEW_CACHE_LOCAL_THUMB) != 0 &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
703 strcmp(name, GQVIEW_CACHE_LOCAL_METADATA) != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
704 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
705 dlist = g_list_prepend(dlist, file_data_new(filepath, &ent_sbuf));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
706 }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
707 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
708 else
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
709 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
710 if ((files) && filter_name_exists(name))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
711 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
712 flist = g_list_prepend(flist, file_data_new(filepath, &ent_sbuf));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
713 }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
714 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
715 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
716 g_free(filepath);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
717 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
718 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
719
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
720 closedir(dp);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
721
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
722 g_free(pathl);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
723
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
724 if (dirs) *dirs = dlist;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
725 if (files) *files = flist;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
726
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
727 return TRUE;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
728 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
729
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
730 void filelist_free(GList *list)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
731 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
732 GList *work;
3
gqview
parents: 1
diff changeset
733
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
734 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
735 while (work)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
736 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
737 file_data_free((FileData *)work->data);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
738 work = work->next;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
739 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
740
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 3
diff changeset
741 g_list_free(list);
3
gqview
parents: 1
diff changeset
742 }
gqview
parents: 1
diff changeset
743
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
744