Mercurial > geeqie.yaz
annotate src/misc.c @ 1022:9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
author | zas_ |
---|---|
date | Sun, 31 Aug 2008 10:51:41 +0000 |
parents | |
children | 650c02c0c8ff |
rev | line source |
---|---|
1022
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
1 /* |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
2 * Geeqie |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
3 * Copyright (C) 2008 The Geeqie Team |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
4 * |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
5 * Authors: Vladimir Nadvornik / Laurent Monin |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
6 * |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
7 * This software is released under the GNU General Public License (GNU GPL). |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
8 * Please read the included file COPYING for more information. |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
9 * This software comes with no warranty of any kind, use at your own risk! |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
10 */ |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
11 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
12 #include "main.h" |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
13 #include "misc.h" |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
14 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
15 gdouble get_zoom_increment(void) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
16 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
17 return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 10.0 : 1.0); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
18 } |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
19 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
20 gchar *utf8_validate_or_convert(const gchar *text) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
21 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
22 gint len; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
23 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
24 if (!text) return NULL; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
25 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
26 len = strlen(text); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
27 if (!g_utf8_validate(text, len, NULL)) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
28 return g_convert(text, len, "UTF-8", "ISO-8859-1", NULL, NULL, NULL); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
29 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
30 return g_strdup(text); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
31 } |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
32 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
33 gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
34 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
35 gchar *s1_key, *s2_key; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
36 gchar *s1_t, *s2_t; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
37 gint ret; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
38 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
39 g_assert(g_utf8_validate(s1, -1, NULL)); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
40 g_assert(g_utf8_validate(s2, -1, NULL)); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
41 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
42 if (!case_sensitive) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
43 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
44 s1_t = g_utf8_casefold(s1, -1); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
45 s2_t = g_utf8_casefold(s2, -1); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
46 } |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
47 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
48 s1_key = g_utf8_collate_key(s1_t, -1); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
49 s2_key = g_utf8_collate_key(s2_t, -1); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
50 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
51 ret = strcmp(s1_key, s2_key); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
52 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
53 g_free(s1_key); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
54 g_free(s2_key); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
55 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
56 if (!case_sensitive) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
57 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
58 g_free(s1_t); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
59 g_free(s2_t); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
60 } |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
61 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
62 return ret; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
63 } |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
64 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
65 /* Borrowed from gtkfilesystemunix.c */ |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
66 gchar *expand_tilde(const gchar *filename) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
67 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
68 #ifndef G_OS_UNIX |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
69 return g_strdup(filename); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
70 #else |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
71 const gchar *notilde; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
72 const gchar *slash; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
73 const gchar *home; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
74 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
75 if (filename[0] != '~') |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
76 return g_strdup(filename); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
77 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
78 notilde = filename + 1; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
79 slash = strchr(notilde, G_DIR_SEPARATOR); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
80 if (slash == notilde || !*notilde) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
81 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
82 home = g_get_home_dir(); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
83 if (!home) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
84 return g_strdup(filename); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
85 } |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
86 else |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
87 { |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
88 gchar *username; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
89 struct passwd *passwd; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
90 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
91 if (slash) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
92 username = g_strndup(notilde, slash - notilde); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
93 else |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
94 username = g_strdup(notilde); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
95 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
96 passwd = getpwnam(username); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
97 g_free(username); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
98 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
99 if (!passwd) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
100 return g_strdup(filename); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
101 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
102 home = passwd->pw_dir; |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
103 } |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
104 |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
105 if (slash) |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
106 return g_build_filename(home, G_DIR_SEPARATOR_S, slash + 1, NULL); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
107 else |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
108 return g_build_filename(home, G_DIR_SEPARATOR_S, NULL); |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
109 #endif |
9962b24b6b43
Move miscellaneous functions to their own files (new misc.[ch]).
zas_
parents:
diff
changeset
|
110 } |