annotate src/ui_fileops.c @ 1429:985366bccfb8

do not allow to add keywords with the same name as siblings
author nadvornik
date Fri, 13 Mar 2009 23:19:58 +0000
parents 4da6d326919c
children a3d3208b0c50
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
1 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
2 * (SLIK) SimpLIstic sKin functions
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
3 * (C) 2006 John Ellis
1284
8b89e3ff286b Add year 2009 to copyright info everywhere.
zas_
parents: 1249
diff changeset
4 * Copyright (C) 2008 - 2009 The Geeqie Team
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13 #ifdef HAVE_CONFIG_H
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
14 # include "config.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
17 #include <pwd.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
18 #include <stdio.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include <stdlib.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20 #include <string.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21 #include <unistd.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22 #include <sys/param.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23 #include <dirent.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24 #include <utime.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
25
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26 #include <glib.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27 #include <gtk/gtk.h> /* for locale warning dialog */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
28
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 254
diff changeset
29 #include "main.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
30 #include "ui_fileops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32 #include "ui_utildlg.h" /* for locale warning dialog */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
36 * generic file information and manipulation routines (public)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37 *-----------------------------------------------------------------------------
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
38 */
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42 void print_term(const gchar *text_utf8)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44 gchar *text_l;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46 text_l = g_locale_from_utf8(text_utf8, -1, NULL, NULL, NULL);
759
362c9a769bb7 use fputs instead of printf - patch by Uwe Ohse
nadvornik
parents: 704
diff changeset
47 fputs((text_l) ? text_l : text_utf8, stdout);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 g_free(text_l);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51 static void encoding_dialog(const gchar *path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53 static gint encoding_dialog_idle(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
55 gchar *path = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57 encoding_dialog(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 g_free(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
61 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
62
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
63 static gint encoding_dialog_delay(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
64 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
65 g_idle_add(encoding_dialog_idle, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
66
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
67 return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
68 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
69
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
70 static void encoding_dialog(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
71 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
72 static gint warned_user = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73 GenericDialog *gd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
74 GString *string;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
75 const gchar *lc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
76 const gchar *bf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
77
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78 /* check that gtk is initialized (loop is level > 0) */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
79 if (gtk_main_level() == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
81 /* gtk not initialized */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
82 gtk_init_add(encoding_dialog_delay, g_strdup(path));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
85
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
86 if (warned_user) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
87 warned_user = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
88
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
89 lc = getenv("LANG");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
90 bf = getenv("G_BROKEN_FILENAMES");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
91
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92 string = g_string_new("");
989
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
93 g_string_append(string, _("One or more filenames are not encoded with the preferred locale character set.\n"));
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
94 g_string_append_printf(string, _("Operations on, and display of these files with %s may not succeed.\n"), PACKAGE);
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
95 g_string_append(string, "\n");
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
96 g_string_append(string, _("If your filenames are not encoded in utf-8, try setting the environment variable G_BROKEN_FILENAMES=1\n"));
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
97 if (bf)
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
98 g_string_append_printf(string, _("It appears G_BROKEN_FILENAMES is set to %s\n"), bf);
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
99 else
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
100 g_string_append(string, _("It appears G_BROKEN_FILENAMES is not set\n"));
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
101 g_string_append(string, "\n");
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
102 g_string_append_printf(string, _("The locale appears to be set to \"%s\"\n(set by the LANG environment variable)\n"), (lc) ? lc : "undefined");
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 if (lc && (strstr(lc, "UTF-8") || strstr(lc, "utf-8")))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 gchar *name;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106 name = g_convert(path, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
989
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
107 string = g_string_append(string, _("\nPreferred encoding appears to be UTF-8, however the file:\n"));
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
108 g_string_append_printf(string, "\"%s\"\n", (name) ? name : _("[name not displayable]"));
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
109
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
110 if (g_utf8_validate(path, -1, NULL))
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
111 g_string_append_printf(string, _("\"%s\" is encoded in valid UTF-8."), (name) ? name : _("[name not displayable]"));
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
112 else
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
113 g_string_append_printf(string, _("\"%s\" is not encoded in valid UTF-8."), (name) ? name : _("[name not displayable]"));
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
114 g_string_append(string, "\n");
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115 g_free(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117
989
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
118 gd = generic_dialog_new(_("Filename encoding locale mismatch"),
1174
0bea79d87065 Drop useless wmclass stuff. Gtk will take care of it and as said in the documentation using gtk_window_set_wmclass() is sort of pointless.
zas_
parents: 1164
diff changeset
119 "locale warning", NULL, TRUE, NULL, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
120 generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, NULL, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
121
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
122 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_WARNING,
989
50e1f5e54c1a Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents: 983
diff changeset
123 _("Filename encoding locale mismatch"), string->str);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125 gtk_widget_show(gd->dialog);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 g_string_free(string, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
129
1386
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
130 #if GQ_DEBUG_PATH_UTF8
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
131 gchar *path_to_utf8_debug(const gchar *path, const gchar *file, gint line)
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
132 #else
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 gchar *path_to_utf8(const gchar *path)
1386
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
134 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
136 gchar *utf8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
137 GError *error = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
138
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
139 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
140
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 utf8 = g_filename_to_utf8(path, -1, NULL, NULL, &error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142 if (error)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
143 {
1386
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
144 #if GQ_DEBUG_PATH_UTF8
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
145 log_printf("%s:%d: Unable to convert filename to UTF-8:\n%s\n%s\n", file, line, path, error->message);
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
146 #else
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
147 log_printf("Unable to convert filename to UTF-8:\n%s\n%s\n", path, error->message);
1386
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
148 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
149 g_error_free(error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
150 encoding_dialog(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
151 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
152 if (!utf8)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154 /* just let it through, but bad things may happen */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155 utf8 = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
157
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158 return utf8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
159 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
160
1386
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
161 #if GQ_DEBUG_PATH_UTF8
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
162 gchar *path_from_utf8_debug(const gchar *utf8, const gchar *file, gint line)
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
163 #else
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164 gchar *path_from_utf8(const gchar *utf8)
1386
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
165 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168 GError *error = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
169
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170 if (!utf8) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
172 path = g_filename_from_utf8(utf8, -1, NULL, NULL, &error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173 if (error)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174 {
1386
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
175 #if GQ_DEBUG_PATH_UTF8
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
176 log_printf("%s:%d: Unable to convert filename to locale from UTF-8:\n%s\n%s\n", file, line, utf8, error->message);
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
177 #else
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
178 log_printf("Unable to convert filename to locale from UTF-8:\n%s\n%s\n", utf8, error->message);
1386
4da6d326919c Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents: 1360
diff changeset
179 #endif
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180 g_error_free(error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182 if (!path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184 /* if invalid UTF-8, text probaby still in original form, so just copy it */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185 path = g_strdup(utf8);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188 return path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190
998
d2701a5864c5 Fixed segfault when is run inside directory with non valid uft-8 image
bruclik
parents: 990
diff changeset
191 /* first we try the HOME environment var, if that doesn't work, we try g_get_homedir(). */
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192 const gchar *homedir(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
194 static gchar *home = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 if (!home)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 home = path_to_utf8(getenv("HOME"));
998
d2701a5864c5 Fixed segfault when is run inside directory with non valid uft-8 image
bruclik
parents: 990
diff changeset
198
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 if (!home)
998
d2701a5864c5 Fixed segfault when is run inside directory with non valid uft-8 image
bruclik
parents: 990
diff changeset
200 home = path_to_utf8(g_get_home_dir());
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
202 return home;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
203 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204
1149
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
205 static gchar *xdg_dir_get(const gchar *key, const gchar *fallback)
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
206 {
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
207 gchar *dir = getenv(key);
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
208
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
209 if (!dir || dir[0] == '\0')
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
210 {
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
211 return g_build_filename(homedir(), fallback, NULL);
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
212 }
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
213
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
214 return path_to_utf8(dir);
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
215 }
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
216
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
217 const gchar *xdg_data_home_get(void)
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
218 {
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
219 static const gchar *xdg_data_home = NULL;
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
220
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
221 if (xdg_data_home) return xdg_data_home;
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
222
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
223 xdg_data_home = xdg_dir_get("XDG_DATA_HOME", ".local/share");
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
224
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
225 return xdg_data_home;
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
226 }
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
227
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
228 const gchar *xdg_config_home_get(void)
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
229 {
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
230 static const gchar *xdg_config_home = NULL;
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
231
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
232 if (xdg_config_home) return xdg_config_home;
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
233
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
234 xdg_config_home = xdg_dir_get("XDG_CONFIG_HOME", ".config");
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
235
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
236 return xdg_config_home;
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
237 }
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
238
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
239 const gchar *xdg_cache_home_get(void)
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
240 {
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
241 static const gchar *xdg_cache_home = NULL;
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
242
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
243 if (xdg_cache_home) return xdg_cache_home;
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
244
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
245 xdg_cache_home = xdg_dir_get("XDG_CACHE_HOME", ".cache");
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
246
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
247 return xdg_cache_home;
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
248 }
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
249
1145
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
250 const gchar *get_rc_dir(void)
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
251 {
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
252 static gchar *rc_dir = NULL;
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
253
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
254 if (rc_dir) return rc_dir;
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
255
1149
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
256 if (USE_XDG)
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
257 {
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
258 rc_dir = g_build_filename(xdg_config_home_get(), GQ_APPNAME_LC, NULL);
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
259 }
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
260 else
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
261 {
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
262 rc_dir = g_build_filename(homedir(), GQ_RC_DIR, NULL);
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
263 }
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
264
1145
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
265 return rc_dir;
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
266 }
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
267
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
268 const gchar *get_collections_dir(void)
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
269 {
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
270 static gchar *collections_dir = NULL;
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
271
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
272 if (collections_dir) return collections_dir;
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
273
1149
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
274 if (USE_XDG)
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
275 {
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
276 collections_dir = g_build_filename(xdg_data_home_get(), GQ_APPNAME_LC, GQ_COLLECTIONS_DIR, NULL);
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
277 }
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
278 else
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
279 {
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
280 collections_dir = g_build_filename(get_rc_dir(), GQ_COLLECTIONS_DIR, NULL);
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
281 }
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
282
1145
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
283 return collections_dir;
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
284 }
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
285
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
286 const gchar *get_trash_dir(void)
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
287 {
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
288 static gchar *trash_dir = NULL;
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
289
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
290 if (trash_dir) return trash_dir;
1149
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
291
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
292 if (USE_XDG)
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
293 {
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
294 trash_dir = g_build_filename(xdg_data_home_get(), GQ_APPNAME_LC, GQ_TRASH_DIR, NULL);
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
295 }
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
296 else
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
297 {
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
298 trash_dir = g_build_filename(get_rc_dir(), GQ_TRASH_DIR, NULL);
c4fcf8001574 Implement preliminary support for XDG Base Directory Specification.
zas_
parents: 1148
diff changeset
299 }
1145
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
300
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
301 return trash_dir;
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
302 }
3a7af6a8cd5f Use functions to return directories instead of constants.
zas_
parents: 1055
diff changeset
303
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304 gint stat_utf8(const gchar *s, struct stat *st)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
306 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 if (!s) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311 ret = (stat(sl, st) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316
40
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
317 gint lstat_utf8(const gchar *s, struct stat *st)
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
318 {
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
319 gchar *sl;
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
320 gint ret;
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
321
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
322 if (!s) return FALSE;
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
323 sl = path_from_utf8(s);
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
324 ret = (lstat(sl, st) == 0);
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
325 g_free(sl);
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
326
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
327 return ret;
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
328 }
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
329
1229
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
330 /* extension must contain only ASCII characters */
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
331 gint stat_utf8_case_insensitive_ext(GString *base, const gchar *ext, struct stat *st)
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
332 {
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
333 gchar *sl;
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
334 gchar *extl;
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
335 gint ret = 0;
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
336 gint ext_len;
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
337 gint base_len = strlen(base->str);
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
338
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
339 g_string_append(base, ext);
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
340 sl = path_from_utf8(base->str);
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
341
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
342 extl = strrchr(sl, '.');
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
343 if (extl)
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
344 {
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
345 gint i, j;
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
346 extl++; /* the first char after . */
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
347 ext_len = strlen(extl);
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
348
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
349 for (i = 0; i < (1 << ext_len); i++)
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
350 {
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
351 for (j = 0; j < ext_len; j++)
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
352 {
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
353 if (i & (1 << j))
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
354 extl[j] = g_ascii_toupper(extl[j]);
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
355 else
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
356 extl[j] = g_ascii_tolower(extl[j]);
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
357 }
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
358 ret = (stat(sl, st) == 0);
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
359 if (ret) break;
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
360 }
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
361
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
362 if (ret)
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
363 {
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
364 /* append the found extension to base */
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
365 base = g_string_truncate(base, base_len);
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
366 extl--;
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
367 g_string_append(base, extl);
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
368 }
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
369 }
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
370 g_free(sl);
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
371
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
372 return ret;
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
373 }
878718372aca sidecar files grouping was made case-insensitive
nadvornik
parents: 1198
diff changeset
374
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 gint isname(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 return stat_utf8(s, &st);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 gint isfile(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386 return (stat_utf8(s, &st) && S_ISREG(st.st_mode));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
388
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389 gint isdir(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391 struct stat st;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
392
1198
931ff871799f Cosmetic fix.
zas_
parents: 1174
diff changeset
393 return (stat_utf8(s, &st) && S_ISDIR(st.st_mode));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395
40
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
396 gint islink(const gchar *s)
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
397 {
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
398 struct stat st;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
399
1198
931ff871799f Cosmetic fix.
zas_
parents: 1174
diff changeset
400 return (lstat_utf8(s, &st) && S_ISLNK(st.st_mode));
40
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
401 }
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
402
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403 gint64 filesize(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405 struct stat st;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
406
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407 if (!stat_utf8(s, &st)) return 0;
983
5049449ad841 Remove unneeded type casting.
zas_
parents: 919
diff changeset
408 return st.st_size;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411 time_t filetime(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412 {
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
413 struct stat st;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 if (!stat_utf8(s, &st)) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 return st.st_mtime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 gint filetime_set(const gchar *s, time_t tval)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
421 gint ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
422
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 if (tval > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425 struct utimbuf ut;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 ut.actime = ut.modtime = tval;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 ret = (utime(sl, &ut) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437
1360
721ffb823d6e Introduce is_readable_file() which test if file exists, is regular and readable.
zas_
parents: 1356
diff changeset
438 gboolean is_readable_file(const gchar *s)
721ffb823d6e Introduce is_readable_file() which test if file exists, is regular and readable.
zas_
parents: 1356
diff changeset
439 {
721ffb823d6e Introduce is_readable_file() which test if file exists, is regular and readable.
zas_
parents: 1356
diff changeset
440 if (!s || !s[0] || !isfile(s)) return FALSE;
721ffb823d6e Introduce is_readable_file() which test if file exists, is regular and readable.
zas_
parents: 1356
diff changeset
441 return access_file(s, R_OK);
721ffb823d6e Introduce is_readable_file() which test if file exists, is regular and readable.
zas_
parents: 1356
diff changeset
442 }
721ffb823d6e Introduce is_readable_file() which test if file exists, is regular and readable.
zas_
parents: 1356
diff changeset
443
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 998
diff changeset
444 gint access_file(const gchar *s, gint mode)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448
1356
681e79dd0820 Slightly modify access_file() and use it to test profile files existence and read access.
zas_
parents: 1307
diff changeset
449 if (!s || !s[0]) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452 ret = (access(sl, mode) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
455 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458 gint unlink_file(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
460 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
463 if (!s) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
464
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466 ret = (unlink(sl) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
468
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
469 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
470 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
471
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 gint symlink_utf8(const gchar *source, const gchar *target)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475 gchar *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
477
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478 if (!source || !target) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 sl = path_from_utf8(source);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 tl = path_from_utf8(target);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
483 ret = (symlink(sl, tl) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
484
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486 g_free(tl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
488 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
489 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 998
diff changeset
491 gint mkdir_utf8(const gchar *s, gint mode)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
492 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496 if (!s) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499 ret = (mkdir(sl, mode) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
500 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
501 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
502 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
503
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
504 gint rmdir_utf8(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
505 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
507 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
508
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
509 if (!s) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
512 ret = (rmdir(sl) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
513 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
514
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
515 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
516 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
517
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518 gint copy_file_attributes(const gchar *s, const gchar *t, gint perms, gint mtime)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
519 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
521 gchar *sl, *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522 gint ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
523
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
524 if (!s || !t) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
526 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
527 tl = path_from_utf8(t);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
528
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529 if (stat(sl, &st) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
531 struct utimbuf tb;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
532
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
533 ret = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
534
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
535 /* set the dest file attributes to that of source (ignoring errors) */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
536
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
537 if (perms && chown(tl, st.st_uid, st.st_gid) < 0) ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
538 if (perms && chmod(tl, st.st_mode) < 0) ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
539
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
540 tb.actime = st.st_atime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
541 tb.modtime = st.st_mtime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
542 if (mtime && utime(tl, &tb) < 0) ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
545 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546 g_free(tl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
547
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
548 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
549 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
550
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 /* paths are in filesystem encoding */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
552 static gint hard_linked(const gchar *a, const gchar *b)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 struct stat sta;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 struct stat stb;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
556
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
557 if (stat(a, &sta) != 0 || stat(b, &stb) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
559 return (sta.st_dev == stb.st_dev &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
560 sta.st_ino == stb.st_ino);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
561 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
562
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563 gint copy_file(const gchar *s, const gchar *t)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
564 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
565 FILE *fi = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
566 FILE *fo = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
567 gchar *sl, *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
568 gchar buf[4096];
704
839525c4e85f Use size_t instead of gint, it silents a signed vs unsigned warning.
zas_
parents: 703
diff changeset
569 size_t b;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
570
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
571 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
572 tl = path_from_utf8(t);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
573
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574 if (hard_linked(sl, tl))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
575 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
577 g_free(tl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
578 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
579 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
580
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
581 fi = fopen(sl, "rb");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
582 if (fi)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
583 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
584 fo = fopen(tl, "wb");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
585 if (!fo)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
586 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
587 fclose(fi);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
588 fi = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
589 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
590 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
591
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
592 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
593 g_free(tl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
594
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
595 if (!fi || !fo) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
596
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 998
diff changeset
597 while ((b = fread(buf, sizeof(gchar), sizeof(buf), fi)) && b != 0)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
598 {
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 998
diff changeset
599 if (fwrite(buf, sizeof(gchar), b, fo) != b)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
600 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
601 fclose(fi);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
602 fclose(fo);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
603 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
604 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
605 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
606
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
607 fclose(fi);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
608 fclose(fo);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
609
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610 copy_file_attributes(s, t, TRUE, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
611
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
612 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
613 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
614
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
615 gint move_file(const gchar *s, const gchar *t)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
616 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
617 gchar *sl, *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
618 gint ret = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
619
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
620 if (!s || !t) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
622 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
623 tl = path_from_utf8(t);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
624 if (rename(sl, tl) < 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
625 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
626 /* this may have failed because moving a file across filesystems
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
627 was attempted, so try copy and delete instead */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
628 if (copy_file(s, t))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
629 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
630 if (unlink(sl) < 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
631 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
632 /* err, now we can't delete the source file so return FALSE */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
633 ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
634 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
635 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
636 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
637 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
638 ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
639 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
640 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
641 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
642 g_free(tl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
643
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
644 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
645 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
646
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647 gint rename_file(const gchar *s, const gchar *t)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
648 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
649 gchar *sl, *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
651
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
652 if (!s || !t) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
653
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
654 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
655 tl = path_from_utf8(t);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
656 ret = (rename(sl, tl) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
657 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
658 g_free(tl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
659
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
660 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
661 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
662
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
663 gchar *get_current_dir(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
664 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
665 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
666 gchar *path8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
667
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
668 pathl = g_get_current_dir();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
669 path8 = path_to_utf8(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
670 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
671
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
672 return path8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
673 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
674
576
9dc0513837b5 dropped path_list functions, use filelist functions everywhere
nadvornik
parents: 545
diff changeset
675 void string_list_free(GList *list)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
676 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
677 g_list_foreach(list, (GFunc)g_free, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
678 g_list_free(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
679 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
680
1238
947e603a52c6 simplified metadata interface, dropped metadata_read,
nadvornik
parents: 1229
diff changeset
681 GList *string_list_copy(const GList *list)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
682 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
683 GList *new_list = NULL;
1249
a5c78d3cfea0 Silent two compilation warnings.
zas_
parents: 1238
diff changeset
684 GList *work = (GList *) list;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
685
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
686 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
687 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
688 gchar *path;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
689
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
690 path = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
691 work = work->next;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
692
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
693 new_list = g_list_prepend(new_list, g_strdup(path));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
694 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
695
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
696 return g_list_reverse(new_list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
697 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
698
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
699 gchar *unique_filename(const gchar *path, const gchar *ext, const gchar *divider, gint pad)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
700 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
701 gchar *unique;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
702 gint n = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
703
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
704 if (!ext) ext = "";
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
705 if (!divider) divider = "";
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
706
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
707 unique = g_strconcat(path, ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
708 while (isname(unique))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
709 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
710 g_free(unique);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
711 if (pad)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
712 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
713 unique = g_strdup_printf("%s%s%03d%s", path, divider, n, ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
714 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
715 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
716 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
717 unique = g_strdup_printf("%s%s%d%s", path, divider, n, ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
718 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
719 n++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
720 if (n > 999)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
721 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
722 /* well, we tried */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
723 g_free(unique);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
724 return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
725 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
726 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
727
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
728 return unique;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
729 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
730
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
731 gchar *unique_filename_simple(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
732 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
733 gchar *unique;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
734 const gchar *name;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
735 const gchar *ext;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
736
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
737 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
738
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
739 name = filename_from_path(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
740 if (!name) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
741
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
742 ext = extension_from_path(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
743
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
744 if (!ext)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
745 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
746 unique = unique_filename(path, NULL, "_", TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
747 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
748 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
749 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
750 gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
751
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
752 base = remove_extension_from_path(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
753 unique = unique_filename(base, ext, "_", TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
754 g_free(base);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
755 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
756
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
757 return unique;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
758 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
759
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
760 const gchar *filename_from_path(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
761 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
762 const gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
763
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
764 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
765
701
28af4b6dd9ef Use G_DIR_SEPARATOR instead of '/' where applicable.
zas_
parents: 673
diff changeset
766 base = strrchr(path, G_DIR_SEPARATOR);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
767 if (base) return base + 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
768
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
769 return path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
770 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
771
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
772 gchar *remove_level_from_path(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
773 {
543
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
774 gint p = 0, n = -1;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
775
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
776 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
777
543
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
778 while (path[p])
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
779 {
701
28af4b6dd9ef Use G_DIR_SEPARATOR instead of '/' where applicable.
zas_
parents: 673
diff changeset
780 if (path[p] == G_DIR_SEPARATOR) n = p;
543
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
781 p++;
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
782 }
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
783 if (n <= 0) n++;
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
784
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
785 return g_strndup(path, (gsize) n);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
786 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
787
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
788 const gchar *extension_from_path(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
789 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
790 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
791 return strrchr(path, '.');
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
792 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
793
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
794 gint file_extension_match(const gchar *path, const gchar *ext)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
795 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
796 gint p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
797 gint e;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
798
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
799 if (!path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
800 if (!ext) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
801
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
802 p = strlen(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
803 e = strlen(ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
804
605
651ae2be1031 Use g_ascii_strncasecmp() instead of strncasecmp() where applicable.
zas_
parents: 576
diff changeset
805 /* FIXME: utf8 */
1307
e8f21b91885d Glibification again.
zas_
parents: 1284
diff changeset
806 return (p > e && g_ascii_strncasecmp(path + p - e, ext, e) == 0);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
807 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
808
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
809 gchar *remove_extension_from_path(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
810 {
544
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
811 gint p = 0, n = -1;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
812
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
813 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
814
544
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
815 while (path[p])
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
816 {
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
817 if (path[p] == '.') n = p;
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
818 p++;
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
819 }
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
820 if (n < 0) n = p;
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
821
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
822 return g_strndup(path, (gsize) n);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
823 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
824
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
825 void parse_out_relatives(gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
826 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
827 gint s, t;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
828
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
829 if (!path) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
830
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
831 s = t = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
832
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
833 while (path[s] != '\0')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
834 {
919
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
835 if (path[s] == G_DIR_SEPARATOR && path[s+1] == '.')
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
836 {
919
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
837 /* /. occurence, let's see more */
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
838 gint p = s + 2;
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
839
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
840 if (path[p] == G_DIR_SEPARATOR || path[p] == '\0')
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
841 {
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
842 /* /./ or /., just skip this part */
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
843 s = p;
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
844 continue;
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
845 }
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
846 else if (path[p] == '.' && (path[p+1] == G_DIR_SEPARATOR || path[p+1] == '\0'))
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
847 {
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
848 /* /../ or /.., remove previous part, ie. /a/b/../ becomes /a/ */
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
849 s = p + 1;
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
850 if (t > 0) t--;
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
851 while (path[t] != G_DIR_SEPARATOR && t > 0) t--;
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
852 continue;
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
853 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
854 }
919
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
855
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
856 if (s != t) path[t] = path[s];
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
857 t++;
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
858 s++;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
859 }
919
3a939c88305c Simplify parse_out_relatives().
zas_
parents: 759
diff changeset
860
701
28af4b6dd9ef Use G_DIR_SEPARATOR instead of '/' where applicable.
zas_
parents: 673
diff changeset
861 if (t == 0 && path[t] == G_DIR_SEPARATOR) t++;
28af4b6dd9ef Use G_DIR_SEPARATOR instead of '/' where applicable.
zas_
parents: 673
diff changeset
862 if (t > 1 && path[t-1] == G_DIR_SEPARATOR) t--;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
863 path[t] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
864 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
865
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
866 gint file_in_path(const gchar *name)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
867 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
868 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
869 gchar *namel;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
870 gint p, l;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
871 gint ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
872
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
873 if (!name) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
874 path = g_strdup(getenv("PATH"));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
875 if (!path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
876 namel = path_from_utf8(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
877
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
878 p = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
879 l = strlen(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
880 while (p < l && !ret)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
881 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
882 gchar *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
883 gint e = p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
884 while (path[e] != ':' && path[e] != '\0') e++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
885 path[e] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
886 e++;
703
911e3769b60c Use g_build_filename() instead of g_strconcat().
zas_
parents: 702
diff changeset
887 f = g_build_filename(path + p, namel, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
888 if (isfile(f)) ret = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
889 g_free(f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
890 p = e;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
891 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
892 g_free(namel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
893 g_free(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
894
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
895 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
896 }
1148
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
897
1164
3692efcbd325 Fix compilation warnings.
zas_
parents: 1149
diff changeset
898 gboolean recursive_mkdir_if_not_exists(const gchar *path, mode_t mode)
1148
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
899 {
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
900 if (!path) return FALSE;
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
901
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
902 if (!isdir(path))
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
903 {
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
904 gchar *npath = g_strdup(path);
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
905 gchar *p = npath;
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
906
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
907 while (p[0] != '\0')
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
908 {
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
909 p++;
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
910 if (p[0] == G_DIR_SEPARATOR || p[0] == '\0')
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
911 {
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
912 gint end = TRUE;
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
913
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
914 if (p[0] != '\0')
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
915 {
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
916 p[0] = '\0';
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
917 end = FALSE;
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
918 }
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
919
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
920 if (!isdir(npath))
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
921 {
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
922 DEBUG_1("creating sub dir:%s", npath);
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
923 if (!mkdir_utf8(npath, mode))
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
924 {
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
925 log_printf("create dir failed: %s\n", npath);
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
926 g_free(npath);
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
927 return FALSE;
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
928 }
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
929 }
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
930
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
931 if (!end) p[0] = G_DIR_SEPARATOR;
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
932 }
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
933 }
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
934 g_free(npath);
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
935 }
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
936
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
937 return TRUE;
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
938 }
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
939
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
940
95860439070b Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents: 1145
diff changeset
941
1055
1646720364cf Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents: 1000
diff changeset
942 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */