comparison src/main.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 2bd19478ba29
children 1646720364cf
comparison
equal deleted inserted replaced
1021:988995f6b1cf 1022:9962b24b6b43
42 static RemoteConnection *remote_connection = NULL; 42 static RemoteConnection *remote_connection = NULL;
43 43
44 44
45 /* 45 /*
46 *----------------------------------------------------------------------------- 46 *-----------------------------------------------------------------------------
47 * misc (public)
48 *-----------------------------------------------------------------------------
49 */
50
51
52 gdouble get_zoom_increment(void)
53 {
54 return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 10.0 : 1.0);
55 }
56
57 gchar *utf8_validate_or_convert(const gchar *text)
58 {
59 gint len;
60
61 if (!text) return NULL;
62
63 len = strlen(text);
64 if (!g_utf8_validate(text, len, NULL))
65 return g_convert(text, len, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
66
67 return g_strdup(text);
68 }
69
70 gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive)
71 {
72 gchar *s1_key, *s2_key;
73 gchar *s1_t, *s2_t;
74 gint ret;
75
76 g_assert(g_utf8_validate(s1, -1, NULL));
77 g_assert(g_utf8_validate(s2, -1, NULL));
78
79 if (!case_sensitive)
80 {
81 s1_t = g_utf8_casefold(s1, -1);
82 s2_t = g_utf8_casefold(s2, -1);
83 }
84
85 s1_key = g_utf8_collate_key(s1_t, -1);
86 s2_key = g_utf8_collate_key(s2_t, -1);
87
88 ret = strcmp(s1_key, s2_key);
89
90 g_free(s1_key);
91 g_free(s2_key);
92
93 if (!case_sensitive)
94 {
95 g_free(s1_t);
96 g_free(s2_t);
97 }
98
99 return ret;
100 }
101
102 /* Borrowed from gtkfilesystemunix.c */
103 gchar *expand_tilde(const gchar *filename)
104 {
105 #ifndef G_OS_UNIX
106 return g_strdup(filename);
107 #else
108 const gchar *notilde;
109 const gchar *slash;
110 const gchar *home;
111
112 if (filename[0] != '~')
113 return g_strdup(filename);
114
115 notilde = filename + 1;
116 slash = strchr(notilde, G_DIR_SEPARATOR);
117 if (slash == notilde || !*notilde)
118 {
119 home = g_get_home_dir();
120 if (!home)
121 return g_strdup(filename);
122 }
123 else
124 {
125 gchar *username;
126 struct passwd *passwd;
127
128 if (slash)
129 username = g_strndup(notilde, slash - notilde);
130 else
131 username = g_strdup(notilde);
132
133 passwd = getpwnam(username);
134 g_free(username);
135
136 if (!passwd)
137 return g_strdup(filename);
138
139 home = passwd->pw_dir;
140 }
141
142 if (slash)
143 return g_build_filename(home, G_DIR_SEPARATOR_S, slash + 1, NULL);
144 else
145 return g_build_filename(home, G_DIR_SEPARATOR_S, NULL);
146 #endif
147 }
148
149
150 /*
151 *-----------------------------------------------------------------------------
152 * keyboard functions 47 * keyboard functions
153 *----------------------------------------------------------------------------- 48 *-----------------------------------------------------------------------------
154 */ 49 */
155 50
156 void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event) 51 void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event)