annotate src/pan-util.c @ 130:7ea9fbcff664

connected zoom
author nadvornik
date Wed, 11 Jul 2007 21:10:25 +0000
parents de64a683d5d0
children 71e1ebee420e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
105
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
1 /*
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
2 * GQview
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
3 * (C) 2006 John Ellis
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
4 *
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
5 * Author: John Ellis
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
6 *
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
7 * This software is released under the GNU General Public License (GNU GPL).
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
8 * Please read the included file COPYING for more information.
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
9 * This software comes with no warranty of any kind, use at your own risk!
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
10 */
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
11
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
12 #include "gqview.h"
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
13 #include "pan-types.h"
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
14
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
15 #include "ui_fileops.h"
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
16
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
17
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
18 /*
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
19 *-----------------------------------------------------------------------------
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
20 * date functions
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
21 *-----------------------------------------------------------------------------
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
22 */
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
23
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
24 gint pan_date_compare(time_t a, time_t b, PanDateLengthType length)
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
25 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
26 struct tm ta;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
27 struct tm tb;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
28
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
29 if (length == PAN_DATE_LENGTH_EXACT) return (a == b);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
30
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
31 if (!localtime_r(&a, &ta) ||
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
32 !localtime_r(&b, &tb)) return FALSE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
33
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
34 if (ta.tm_year != tb.tm_year) return FALSE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
35 if (length == PAN_DATE_LENGTH_YEAR) return TRUE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
36
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
37 if (ta.tm_mon != tb.tm_mon) return FALSE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
38 if (length == PAN_DATE_LENGTH_MONTH) return TRUE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
39
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
40 if (length == PAN_DATE_LENGTH_WEEK) return (ta.tm_yday / 7 == tb.tm_yday / 7);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
41
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
42 if (ta.tm_mday != tb.tm_mday) return FALSE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
43 if (length == PAN_DATE_LENGTH_DAY) return TRUE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
44
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
45 return (ta.tm_hour == tb.tm_hour);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
46 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
47
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
48 gint pan_date_value(time_t d, PanDateLengthType length)
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
49 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
50 struct tm td;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
51
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
52 if (!localtime_r(&d, &td)) return -1;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
53
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
54 switch (length)
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
55 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
56 case PAN_DATE_LENGTH_DAY:
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
57 return td.tm_mday;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
58 break;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
59 case PAN_DATE_LENGTH_WEEK:
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
60 return td.tm_wday;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
61 break;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
62 case PAN_DATE_LENGTH_MONTH:
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
63 return td.tm_mon + 1;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
64 break;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
65 case PAN_DATE_LENGTH_YEAR:
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
66 return td.tm_year + 1900;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
67 break;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
68 case PAN_DATE_LENGTH_EXACT:
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
69 default:
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
70 break;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
71 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
72
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
73 return -1;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
74 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
75
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
76 gchar *pan_date_value_string(time_t d, PanDateLengthType length)
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
77 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
78 struct tm td;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
79 gchar buf[128];
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
80 gchar *format = NULL;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
81
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
82 if (!localtime_r(&d, &td)) return g_strdup("");
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
83
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
84 switch (length)
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
85 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
86 case PAN_DATE_LENGTH_DAY:
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
87 return g_strdup_printf("%d", td.tm_mday);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
88 break;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
89 case PAN_DATE_LENGTH_WEEK:
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
90 format = "%A %e";
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
91 break;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
92 case PAN_DATE_LENGTH_MONTH:
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
93 format = "%B %Y";
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
94 break;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
95 case PAN_DATE_LENGTH_YEAR:
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
96 return g_strdup_printf("%d", td.tm_year + 1900);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
97 break;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
98 case PAN_DATE_LENGTH_EXACT:
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
99 default:
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
100 return g_strdup(text_from_time(d));
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
101 break;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
102 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
103
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
104
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
105 if (format && strftime(buf, sizeof(buf), format, &td) > 0)
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
106 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
107 gchar *ret = g_locale_to_utf8(buf, -1, NULL, NULL, NULL);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
108 if (ret) return ret;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
109 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
110
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
111 return g_strdup("");
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
112 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
113
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
114 time_t pan_date_to_time(gint year, gint month, gint day)
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
115 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
116 struct tm lt;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
117
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
118 lt.tm_sec = 0;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
119 lt.tm_min = 0;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
120 lt.tm_hour = 0;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
121 lt.tm_mday = (day >= 1 && day <= 31) ? day : 1;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
122 lt.tm_mon = (month >= 1 && month <= 12) ? month - 1 : 0;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
123 lt.tm_year = year - 1900;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
124 lt.tm_isdst = 0;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
125
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
126 return mktime(&lt);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
127 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
128
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
129
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
130 /*
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
131 *-----------------------------------------------------------------------------
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
132 * folder validation
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
133 *-----------------------------------------------------------------------------
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
134 */
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
135
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
136 gint pan_is_link_loop(const gchar *s)
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
137 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
138 gchar *sl;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
139 struct stat st;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
140 gint ret = FALSE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
141
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
142 sl = path_from_utf8(s);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
143
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
144 if (lstat(sl, &st) == 0 && S_ISLNK(st.st_mode))
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
145 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
146 gchar *buf;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
147 gint l;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
148
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
149 buf = g_malloc(st.st_size + 1);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
150 l = readlink(sl, buf, st.st_size);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
151 if (l == st.st_size)
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
152 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
153 buf[l] = '\0';
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
154
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
155 parse_out_relatives(buf);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
156 l = strlen(buf);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
157
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
158 parse_out_relatives(sl);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
159
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
160 if (buf[0] == '/')
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
161 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
162 if (strncmp(sl, buf, l) == 0 &&
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
163 (sl[l] == '\0' || sl[l] == '/' || l == 1)) ret = TRUE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
164 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
165 else
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
166 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
167 gchar *link_path;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
168
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
169 link_path = concat_dir_and_file(sl, buf);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
170 parse_out_relatives(link_path);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
171
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
172 if (strncmp(sl, link_path, l) == 0 &&
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
173 (sl[l] == '\0' || sl[l] == '/' || l == 1)) ret = TRUE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
174
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
175 g_free(link_path);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
176 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
177 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
178
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
179 g_free(buf);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
180 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
181
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
182 g_free(sl);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
183
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
184 return ret;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
185 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
186
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
187 gint pan_is_ignored(const gchar *s, gint ignore_symlinks)
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
188 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
189 struct stat st;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
190 const gchar *n;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
191
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
192 if (!lstat_utf8(s, &st)) return TRUE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
193
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
194 #if 0
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
195 /* normal filesystems have directories with some size or block allocation,
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
196 * special filesystems (like linux /proc) set both to zero.
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
197 * enable this check if you enable listing the root "/" folder
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
198 */
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
199 if (st.st_size == 0 && st.st_blocks == 0) return TRUE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
200 #endif
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
201
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
202 if (S_ISLNK(st.st_mode) && (ignore_symlinks || pan_is_link_loop(s))) return TRUE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
203
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
204 n = filename_from_path(s);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
205 if (n && strcmp(n, GQVIEW_RC_DIR) == 0) return TRUE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
206
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
207 return FALSE;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
208 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
209
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
210 GList *pan_list_tree(const gchar *path, SortType sort, gint ascend,
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
211 gint ignore_symlinks)
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
212 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
213 GList *flist = NULL;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
214 GList *dlist = NULL;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
215 GList *result;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
216 GList *folders;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
217
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
218 filelist_read(path, &flist, &dlist);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
219 if (sort != SORT_NONE)
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
220 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
221 flist = filelist_sort(flist, sort, ascend);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
222 dlist = filelist_sort(dlist, sort, ascend);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
223 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
224
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
225 result = flist;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
226 folders = dlist;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
227 while (folders)
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
228 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
229 FileData *fd;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
230
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
231 fd = folders->data;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
232 folders = g_list_remove(folders, fd);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
233
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
234 if (!pan_is_ignored(fd->path, ignore_symlinks) &&
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
235 filelist_read(fd->path, &flist, &dlist))
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
236 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
237 if (sort != SORT_NONE)
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
238 {
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
239 flist = filelist_sort(flist, sort, ascend);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
240 dlist = filelist_sort(dlist, sort, ascend);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
241 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
242
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
243 result = g_list_concat(result, flist);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
244 folders = g_list_concat(dlist, folders);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
245 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
246
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
247 file_data_free(fd);
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
248 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
249
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
250 return result;
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
251 }
de64a683d5d0 Thu Nov 9 17:43:06 2006 John Ellis <johne@verizon.net>
gqview
parents:
diff changeset
252