2 * Copyright (C) 2008 - 2016 The Geeqie Team
4 * Authors: Vladimir Nadvornik, Laurent Monin
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "ui_fileops.h"
27 gdouble get_zoom_increment(void)
29 return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 100.0 : 1.0);
32 gchar *utf8_validate_or_convert(const gchar *text)
36 if (!text) return NULL;
39 if (!g_utf8_validate(text, len, NULL))
40 return g_convert(text, len, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
42 return g_strdup(text);
45 gint utf8_compare(const gchar *s1, const gchar *s2, gboolean case_sensitive)
47 gchar *s1_key, *s2_key;
51 g_assert(g_utf8_validate(s1, -1, NULL));
52 g_assert(g_utf8_validate(s2, -1, NULL));
56 s1_t = g_utf8_casefold(s1, -1);
57 s2_t = g_utf8_casefold(s2, -1);
65 s1_key = g_utf8_collate_key(s1_t, -1);
66 s2_key = g_utf8_collate_key(s2_t, -1);
68 ret = strcmp(s1_key, s2_key);
82 /* Borrowed from gtkfilesystemunix.c */
83 gchar *expand_tilde(const gchar *filename)
86 return g_strdup(filename);
92 if (filename[0] != '~')
93 return g_strdup(filename);
95 notilde = filename + 1;
96 slash = strchr(notilde, G_DIR_SEPARATOR);
97 if (slash == notilde || !*notilde)
99 home = g_get_home_dir();
101 return g_strdup(filename);
106 struct passwd *passwd;
109 username = g_strndup(notilde, slash - notilde);
111 username = g_strdup(notilde);
113 passwd = getpwnam(username);
117 return g_strdup(filename);
119 home = passwd->pw_dir;
123 return g_build_filename(home, G_DIR_SEPARATOR_S, slash + 1, NULL);
125 return g_build_filename(home, G_DIR_SEPARATOR_S, NULL);
129 /* Search for latitude/longitude parameters in a string
132 #define GEOCODE_NAME "geocode-parameters.awk"
135 gchar *decode_geo_script(const gchar *path_dir, const gchar *input_text)
138 gchar *path = g_build_filename(path_dir, GEOCODE_NAME, NULL);
139 gchar *cmd = g_strconcat("echo \'", input_text, "\' | awk -f ", path, NULL);
141 if (g_file_test(path, G_FILE_TEST_EXISTS))
146 if ((fp = popen(cmd, "r")) == NULL)
148 message = g_strconcat("Error: opening pipe\n", input_text, NULL);
152 while (fgets(buf, BUFSIZE, fp))
154 DEBUG_1("Output: %s", buf);
157 message = g_strconcat(buf, NULL);
161 message = g_strconcat("Error: Command not found or exited with error status\n", input_text, NULL);
167 message = g_strconcat(input_text, NULL);
175 gchar *decode_geo_parameters(const gchar *input_text)
180 message = decode_geo_script(GQ_BIN_DIR, input_text);
181 if (strstr(message, "Error"))
184 dir = g_build_filename(get_rc_dir(), "applications", NULL);
185 message = decode_geo_script(dir, input_text);
192 /* Run a command like system() but may output debug messages. */
193 int runcmd(gchar *cmd)
199 /* For debugging purposes */
203 DEBUG_1("Running command: %s", cmd);
205 in = popen(cmd, "r");
212 while (fgets(buf, sizeof(buf), in) != NULL )
214 DEBUG_1("Output: %s", buf);
219 if (WIFEXITED(status))
221 msg = "Command terminated with exit code";
222 retval = WEXITSTATUS(status);
224 else if (WIFSIGNALED(status))
226 msg = "Command was killed by signal";
227 retval = WTERMSIG(status);
231 msg = "pclose() returned";
235 DEBUG_1("%s : %d\n", msg, retval);
243 * @brief Returns integer representing first_day_of_week
244 * @returns Integer in range 1 to 7
246 * Uses current locale to get first day of week
250 gint date_get_first_day_of_week()
252 return nl_langinfo(_NL_TIME_FIRST_WEEKDAY)[0];
256 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */