annotate src/rcfile.c @ 276:4f526d436873

Implement secure rc file saving. First data is written to a temporary file, then if nothing was wrong, this file is renamed to the final name. This way the risk of corrupted rc file is greatly reduced. The code is borrowed from ELinks (http://elinks.cz).
author zas_
date Tue, 08 Apr 2008 21:55:58 +0000
parents a9adf9e1a746
children 9995c5fb202a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1 /*
196
f6e307c7bad6 rename GQview -> Geeqie over the code
nadvornik
parents: 170
diff changeset
2 * Geeqie
113
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
3 * (C) 2006 John Ellis
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
4 *
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
5 * Author: John Ellis
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
6 *
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
7 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
8 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
9 * This software comes with no warranty of any kind, use at your own risk!
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
10 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
11
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
12 #include <glib/gstdio.h>
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
13 #include <errno.h>
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
14
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
15 #include "gqview.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
16 #include "rcfile.h"
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
17
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
18 #include "filelist.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
19 #include "slideshow.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
20 #include "ui_fileops.h"
222
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 218
diff changeset
21 #include "bar_exif.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
22
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
23 /* ABOUT SECURE SAVE */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
24 /* This code was borrowed from the ELinks project (http://elinks.cz)
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
25 * It was originally written by me (Laurent Monin aka Zas) and heavily
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
26 * modified and improved by all ELinks contributors.
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
27 * This code was released under the GPLv2 licence.
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
28 * It was modified to be included in geeqie on 2008/04/05 */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
29
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
30 /* If ssi->secure_save is TRUE:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
31 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
32 *
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
33 * A call to secure_open("/home/me/.geeqie/filename", mask) will open a file
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
34 * named "filename.tmp_XXXXXX" in /home/me/.geeqie/ and return a pointer to a
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
35 * structure SecureSaveInfo on success or NULL on error.
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
36 *
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
37 * filename.tmp_XXXXXX can't conflict with any file since it's created using
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
38 * mkstemp(). XXXXXX is a random string.
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
39 *
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
40 * Subsequent write operations are done using returned SecureSaveInfo FILE *
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
41 * field named fp.
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
42 *
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
43 * If an error is encountered, SecureSaveInfo int field named err is set
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
44 * (automatically if using secure_fp*() functions or by programmer)
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
45 *
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
46 * When secure_close() is called, "filename.tmp_XXXXXX" is flushed and closed,
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
47 * and if SecureSaveInfo err field has a value of zero, "filename.tmp_XXXXXX"
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
48 * is renamed to "filename". If this succeeded, then secure_close() returns 0.
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
49 *
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
50 * WARNING: since rename() is used, any symlink called "filename" may be
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
51 * replaced by a regular file. If destination file isn't a regular file,
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
52 * then secsave is disabled for that file.
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
53 *
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
54 * If ssi->secure_save is FALSE:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
55 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
56 *
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
57 * No temporary file is created, "filename" is truncated, all operations are
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
58 * done on it, no rename nor flush occur, symlinks are preserved.
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
59 *
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
60 * In both cases:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
61 * ~~~~~~~~~~~~~
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
62 *
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
63 * Access rights are affected by secure_open() mask parameter.
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
64 */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
65
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
66 /* FIXME: locking system on files about to be rewritten ? */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
67 /* FIXME: Low risk race conditions about ssi->file_name. */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
68
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
69 SecureSaveErrno secsave_errno = SS_ERR_NONE;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
70
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
71
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
72 /** Open a file for writing in a secure way. @returns a pointer to a
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
73 * structure secure_save_info on success, or NULL on failure. */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
74 static SecureSaveInfo *
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
75 secure_open_umask(gchar *file_name)
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
76 {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
77 struct stat st;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
78 SecureSaveInfo *ssi;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
79
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
80 secsave_errno = SS_ERR_NONE;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
81
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
82 ssi = g_new0(SecureSaveInfo, 1);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
83 if (!ssi) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
84 secsave_errno = SS_ERR_OUT_OF_MEM;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
85 goto end;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
86 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
87
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
88 ssi->secure_save = TRUE;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
89
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
90 ssi->file_name = g_strdup(file_name);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
91 if (!ssi->file_name) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
92 secsave_errno = SS_ERR_OUT_OF_MEM;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
93 goto free_f;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
94 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
95
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
96 /* Check properties of final file. */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
97 #ifndef NO_UNIX_SOFTLINKS
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
98 if (g_lstat(ssi->file_name, &st)) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
99 #else
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
100 if (g_stat(ssi->file_name, &st)) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
101 #endif
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
102 /* We ignore error caused by file inexistence. */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
103 if (errno != ENOENT) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
104 /* lstat() error. */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
105 ssi->err = errno;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
106 secsave_errno = SS_ERR_STAT;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
107 goto free_file_name;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
108 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
109 } else {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
110 if (!S_ISREG(st.st_mode)) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
111 /* Not a regular file, secure_save is disabled. */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
112 ssi->secure_save = 0;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
113 } else {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
114 #ifdef HAVE_ACCESS
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
115 /* XXX: access() do not work with setuid programs. */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
116 if (g_access(ssi->file_name, R_OK | W_OK) < 0) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
117 ssi->err = errno;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
118 secsave_errno = SS_ERR_ACCESS;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
119 goto free_file_name;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
120 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
121 #else
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
122 FILE *f1;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
123
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
124 /* We still have a race condition here between
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
125 * [l]stat() and fopen() */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
126
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
127 f1 = g_fopen(ssi->file_name, "rb+");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
128 if (f1) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
129 fclose(f1);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
130 } else {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
131 ssi->err = errno;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
132 secsave_errno = SS_ERR_OPEN_READ;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
133 goto free_file_name;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
134 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
135 #endif
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
136 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
137 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
138
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
139 if (ssi->secure_save) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
140 /* We use a random name for temporary file, mkstemp() opens
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
141 * the file and return a file descriptor named fd, which is
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
142 * then converted to FILE * using fdopen().
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
143 */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
144 gint fd;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
145 gchar *randname = g_strconcat(ssi->file_name, ".tmp_XXXXXX", NULL);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
146
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
147 if (!randname) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
148 secsave_errno = SS_ERR_OUT_OF_MEM;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
149 goto free_file_name;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
150 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
151
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
152 /* No need to use safe_mkstemp() here. --Zas */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
153 fd = g_mkstemp(randname);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
154 if (fd == -1) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
155 secsave_errno = SS_ERR_MKSTEMP;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
156 g_free(randname);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
157 goto free_file_name;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
158 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
159
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
160 ssi->fp = fdopen(fd, "wb");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
161 if (!ssi->fp) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
162 secsave_errno = SS_ERR_OPEN_WRITE;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
163 ssi->err = errno;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
164 g_free(randname);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
165 goto free_file_name;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
166 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
167
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
168 ssi->tmp_file_name = randname;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
169 } else {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
170 /* No need to create a temporary file here. */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
171 ssi->fp = g_fopen(ssi->file_name, "wb");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
172 if (!ssi->fp) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
173 secsave_errno = SS_ERR_OPEN_WRITE;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
174 ssi->err = errno;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
175 goto free_file_name;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
176 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
177 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
178
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
179 return ssi;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
180
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
181 free_file_name:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
182 g_free(ssi->file_name);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
183 ssi->file_name = NULL;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
184
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
185 free_f:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
186 g_free(ssi);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
187 ssi = NULL;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
188
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
189 end:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
190 return NULL;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
191 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
192
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
193 SecureSaveInfo *
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
194 secure_open(gchar *file_name)
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
195 {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
196 SecureSaveInfo *ssi;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
197 mode_t saved_mask;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
198 #ifdef CONFIG_OS_WIN32
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
199 /* There is neither S_IRWXG nor S_IRWXO under crossmingw32-gcc */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
200 const mode_t mask = 0177;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
201 #else
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
202 const mode_t mask = S_IXUSR | S_IRWXG | S_IRWXO;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
203 #endif
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
204
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
205 saved_mask = umask(mask);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
206 ssi = secure_open_umask(file_name);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
207 umask(saved_mask);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
208
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
209 return ssi;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
210 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
211
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
212 /** Close a file opened with secure_open(). Rreturns 0 on success,
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
213 * errno or -1 on failure.
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
214 */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
215 gint
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
216 secure_close(SecureSaveInfo *ssi)
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
217 {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
218 gint ret = -1;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
219
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
220 if (!ssi) return ret;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
221 if (!ssi->fp) goto free;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
222
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
223 if (ssi->err) { /* Keep previous errno. */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
224 ret = ssi->err;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
225 fclose(ssi->fp); /* Close file */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
226 goto free;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
227 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
228
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
229 /* Ensure data is effectively written to disk, we first flush libc buffers
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
230 * using fflush(), then fsync() to flush kernel buffers, and finally call
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
231 * fclose() (which call fflush() again, but the first one is needed since
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
232 * it doesn't make much sense to flush kernel buffers and then libc buffers,
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
233 * while closing file releases file descriptor we need to call fsync(). */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
234 #if defined(HAVE_FFLUSH) || defined(HAVE_FSYNC)
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
235 if (ssi->secure_save) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
236 int fail = 0;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
237
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
238 #ifdef HAVE_FFLUSH
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
239 fail = (fflush(ssi->fp) == EOF);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
240 #endif
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
241
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
242 #ifdef HAVE_FSYNC
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
243 if (!fail) fail = fsync(fileno(ssi->fp));
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
244 #endif
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
245
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
246 if (fail) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
247 ret = errno;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
248 secsave_errno = SS_ERR_OTHER;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
249
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
250 fclose(ssi->fp); /* Close file, ignore errors. */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
251 goto free;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
252 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
253 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
254 #endif
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
255
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
256 /* Close file. */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
257 if (fclose(ssi->fp) == EOF) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
258 ret = errno;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
259 secsave_errno = SS_ERR_OTHER;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
260 goto free;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
261 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
262
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
263 if (ssi->secure_save && ssi->file_name && ssi->tmp_file_name) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
264 /* FIXME: Race condition on ssi->file_name. The file
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
265 * named ssi->file_name may have changed since
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
266 * secure_open() call (where we stat() file and
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
267 * more..). */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
268 if (debug > 2) g_printf("rename %s -> %s", ssi->tmp_file_name, ssi->file_name);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
269 if (g_rename(ssi->tmp_file_name, ssi->file_name) == -1) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
270 ret = errno;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
271 secsave_errno = SS_ERR_RENAME;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
272 goto free;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
273 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
274 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
275
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
276 ret = 0; /* Success. */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
277
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
278 free:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
279 if (ssi->tmp_file_name) g_free(ssi->tmp_file_name);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
280 if (ssi->file_name) g_free(ssi->file_name);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
281 if (ssi) g_free(ssi);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
282
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
283 return ret;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
284 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
285
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
286
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
287 /** fputs() wrapper, set ssi->err to errno on error. If ssi->err is set when
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
288 * called, it immediatly returns EOF.
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
289 */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
290 gint
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
291 secure_fputs(SecureSaveInfo *ssi, const gchar *s)
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
292 {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
293 gint ret;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
294
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
295 if (!ssi || !ssi->fp || ssi->err) return EOF;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
296
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
297 ret = fputs(s, ssi->fp);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
298 if (ret == EOF) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
299 secsave_errno = SS_ERR_OTHER;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
300 ssi->err = errno;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
301 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
302
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
303 return ret;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
304 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
305
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
306
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
307 /** fputc() wrapper, set ssi->err to errno on error. If ssi->err is set when
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
308 * called, it immediatly returns EOF.
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
309 */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
310 gint
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
311 secure_fputc(SecureSaveInfo *ssi, gint c)
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
312 {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
313 gint ret;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
314
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
315 if (!ssi || !ssi->fp || ssi->err) return EOF;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
316
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
317 ret = fputc(c, ssi->fp);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
318 if (ret == EOF) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
319 ssi->err = errno;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
320 secsave_errno = SS_ERR_OTHER;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
321 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
322
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
323 return ret;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
324 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
325
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
326 /** fprintf() wrapper, set ssi->err to errno on error and return a negative
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
327 * value. If ssi->err is set when called, it immediatly returns -1.
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
328 */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
329 gint
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
330 secure_fprintf(SecureSaveInfo *ssi, const gchar *format, ...)
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
331 {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
332 va_list ap;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
333 gint ret;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
334
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
335 if (!ssi || !ssi->fp || ssi->err) return -1;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
336
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
337 va_start(ap, format);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
338 ret = vfprintf(ssi->fp, format, ap);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
339 if (ret < 0) ssi->err = errno;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
340 va_end(ap);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
341
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
342 return ret;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
343 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
344
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
345 gchar *
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
346 secsave_strerror(SecureSaveErrno secsave_error)
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
347 {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
348 switch (secsave_error) {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
349 case SS_ERR_OPEN_READ:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
350 return _("Cannot read the file");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
351 case SS_ERR_STAT:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
352 return _("Cannot get file status");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
353 case SS_ERR_ACCESS:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
354 return _("Cannot access the file");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
355 case SS_ERR_MKSTEMP:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
356 return _("Cannot create temp file");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
357 case SS_ERR_RENAME:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
358 return _("Cannot rename the file");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
359 case SS_ERR_DISABLED:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
360 return _("File saving disabled by option");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
361 case SS_ERR_OUT_OF_MEM:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
362 return _("Out of memory");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
363 case SS_ERR_OPEN_WRITE:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
364 return _("Cannot write the file");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
365 case SS_ERR_NONE: /* Impossible. */
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
366 case SS_ERR_OTHER:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
367 default:
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
368 return _("Secure file saving error");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
369 }
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
370 }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
371
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
372 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
373 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
374 * line write/parse routines (private)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
375 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
376 */
217
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
377
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
378 /*
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
379 returns text without quotes or NULL for empty or broken string
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
380 any text up to first '"' is skipped
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
381 tail is set to point at the char after the second '"'
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
382 or at the ending \0
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
383
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
384 */
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
385
217
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
386 gchar *quoted_value(const gchar *text, const gchar **tail)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
387 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
388 const gchar *ptr;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
389 gint c = 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
390 gint l = strlen(text);
210
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
391 gchar *retval = NULL;
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
392
217
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
393 if (tail) *tail = text;
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
394
210
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
395 if (l == 0) return retval;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
396
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
397 while (c < l && text[c] !='"') c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
398 if (text[c] == '"')
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
399 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
400 gint e;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
401 c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
402 ptr = text + c;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
403 e = c;
210
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
404 while (e < l)
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
405 {
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
406 if (text[e-1] != '\\' && text[e] == '"') break;
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
407 e++;
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
408 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
409 if (text[e] == '"')
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
410 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
411 if (e - c > 0)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
412 {
210
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
413 gchar *substring = g_strndup(ptr, e - c);
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
414
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
415 if (substring)
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
416 {
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
417 retval = g_strcompress(substring);
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
418 g_free(substring);
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
419 }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
420 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
421 }
217
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
422 if (tail) *tail = text + e + 1;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
423 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
424 else
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
425 /* for compatibility with older formats (<0.3.7)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
426 * read a line without quotes too */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
427 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
428 c = 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
429 while (c < l && text[c] !=' ' && text[c] !=8 && text[c] != '\n') c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
430 if (c != 0)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
431 {
210
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
432 retval = g_strndup(text, c);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
433 }
217
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
434 if (tail) *tail = text + c;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
435 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
436
210
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
437 return retval;
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
438 }
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
439
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
440 gchar *escquote_value(const gchar *text)
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
441 {
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
442 gchar *e;
250
22ed43d4c849 Drop a bunch of unused variables.
zas_
parents: 226
diff changeset
443
217
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
444 if (!text) return g_strdup("\"\"");
210
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
445
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
446 e = g_strescape(text, "");
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
447 if (e)
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
448 {
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
449 gchar *retval = g_strdup_printf("\"%s\"", e);
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
450 g_free(e);
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
451 return retval;
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
452 }
217
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
453 return g_strdup("\"\"");
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
454 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
455
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
456 static void write_char_option(SecureSaveInfo *ssi, gchar *label, gchar *text)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
457 {
210
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
458 gchar *escval = escquote_value(text);
3fa93ab9b119 Improve escaping and quoting of strings saved in rc files.
zas_
parents: 209
diff changeset
459
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
460 secure_fprintf(ssi, "%s: %s\n", label, escval);
217
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
461 g_free(escval);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
462 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
463
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
464 static gchar *read_char_option(FILE *f, gchar *option, gchar *label, gchar *value, gchar *text)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
465 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
466 if (strcasecmp(option, label) == 0)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
467 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
468 g_free(text);
217
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
469 text = quoted_value(value, NULL);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
470 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
471 return text;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
472 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
473
267
a9adf9e1a746 Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents: 250
diff changeset
474 /* Since gdk_color_to_string() is only available since gtk 2.12
a9adf9e1a746 Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents: 250
diff changeset
475 * here is an equivalent stub function. */
a9adf9e1a746 Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents: 250
diff changeset
476 static gchar *color_to_string(GdkColor *color)
a9adf9e1a746 Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents: 250
diff changeset
477 {
a9adf9e1a746 Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents: 250
diff changeset
478 return g_strdup_printf("#%04X%04X%04X", color->red, color->green, color->blue);
a9adf9e1a746 Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents: 250
diff changeset
479 }
a9adf9e1a746 Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents: 250
diff changeset
480
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
481 static void write_color_option(SecureSaveInfo *ssi, gchar *label, GdkColor *color)
208
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
482 {
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
483 if (color)
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
484 {
267
a9adf9e1a746 Remove dependency on GTK 2.12, reported by John Vodden and Vladimir
zas_
parents: 250
diff changeset
485 gchar *colorstring = color_to_string(color);
208
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
486
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
487 write_char_option(ssi, label, colorstring);
208
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
488 g_free(colorstring);
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
489 }
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
490 else
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
491 secure_fprintf(ssi, "%s: \n", label);
208
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
492 }
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
493
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
494 static GdkColor *read_color_option(FILE *f, gchar *option, gchar *label, gchar *value, GdkColor *color)
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
495 {
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
496 if (strcasecmp(option, label) == 0)
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
497 {
217
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
498 gchar *colorstr = quoted_value(value, NULL);
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
499 if (colorstr) gdk_color_parse(colorstr, color);
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
500 g_free(colorstr);
208
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
501 }
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
502 return color;
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
503 }
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
504
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
505
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
506 static void write_int_option(SecureSaveInfo *ssi, gchar *label, gint n)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
507 {
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
508 secure_fprintf(ssi, "%s: %d\n", label, n);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
509 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
510
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
511 static gint read_int_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
512 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
513 if (strcasecmp(option, label) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
514 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
515 n = strtol(value, NULL, 10);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
516 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
517 return n;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
518 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
519
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
520 static void write_int_unit_option(SecureSaveInfo *ssi, gchar *label, gint n, gint subunits)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
521 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
522 gint l, r;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
523
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
524 if (subunits > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
525 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
526 l = n / subunits;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
527 r = n % subunits;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
528 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
529 else
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
530 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
531 l = n;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
532 r = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
533 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
534
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
535 secure_fprintf(ssi, "%s: %d.%d\n", label, l, r);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
536 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
537
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
538 static gint read_int_unit_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n, gint subunits)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
539 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
540 if (strcasecmp(option, label) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
541 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
542 gint l, r;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
543 gchar *ptr;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
544
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
545 ptr = value;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
546 while (*ptr != '\0' && *ptr != '.') ptr++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
547 if (*ptr == '.')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
548 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
549 *ptr = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
550 l = strtol(value, NULL, 10);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
551 *ptr = '.';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
552 ptr++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
553 r = strtol(ptr, NULL, 10);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
554 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
555 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
556 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
557 l = strtol(value, NULL, 10);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
558 r = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
559 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
560
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
561 n = l * subunits + r;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
562 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
563 return n;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
564 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
565
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
566 static void write_bool_option(SecureSaveInfo *ssi, gchar *label, gint n)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
567 {
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
568 secure_fprintf(ssi, "%s: ", label);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
569 if (n) secure_fprintf(ssi, "true\n"); else secure_fprintf(ssi, "false\n");
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
570 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
571
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
572 static gint read_bool_option(FILE *f, gchar *option, gchar *label, gchar *value, gint n)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
573 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
574 if (strcasecmp(option, label) == 0)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
575 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
576 if (strcasecmp(value, "true") == 0)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
577 n = TRUE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
578 else
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
579 n = FALSE;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
580 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
581 return n;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
582 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
583
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
584 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
585 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
586 * save configuration (public)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
587 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
588 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
589
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
590 void save_options(void)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
591 {
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
592 SecureSaveInfo *ssi;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
593 gchar *rc_path;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
594 gchar *rc_pathl;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
595 gint i;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
596
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
597 rc_path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/", RC_FILE_NAME, NULL);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
598
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
599 rc_pathl = path_from_utf8(rc_path);
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
600 ssi = secure_open(rc_pathl);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
601 g_free(rc_pathl);
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
602 if (!ssi)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
603 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
604 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
605
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
606 buf = g_strdup_printf(_("error saving config file: %s\n"), rc_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
607 print_term(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
608 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
609
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
610 g_free(rc_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
611 return;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
612 }
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
613
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
614 secure_fprintf(ssi, "######################################################################\n");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
615 secure_fprintf(ssi, "# Geeqie config file version %7s #\n", VERSION);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
616 secure_fprintf(ssi, "######################################################################\n");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
617 secure_fputc(ssi, '\n');
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
618
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
619 secure_fprintf(ssi, "# Note: This file is autogenerated. Options can be changed here,\n");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
620 secure_fprintf(ssi, "# but user comments and formatting will be lost.\n");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
621 secure_fputc(ssi, '\n');
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
622
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
623 secure_fprintf(ssi, "##### General Options #####\n\n");
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
624
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
625 write_int_option(ssi, "layout_style", layout_style);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
626 write_char_option(ssi, "layout_order", layout_order);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
627 secure_fputc(ssi, '\n');
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
628
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
629 write_bool_option(ssi, "layout_view_as_icons", layout_view_icons);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
630 write_bool_option(ssi, "layout_view_as_tree", layout_view_tree);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
631 write_bool_option(ssi, "show_icon_names", show_icon_names);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
632 secure_fputc(ssi, '\n');
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
633
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
634 write_bool_option(ssi, "tree_descend_folders", tree_descend_subdirs);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
635 write_bool_option(ssi, "lazy_image_sync", lazy_image_sync);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
636 write_bool_option(ssi, "update_on_time_change", update_on_time_change);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
637 write_bool_option(ssi, "exif_auto_rotate", exif_rotate_enable);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
638 secure_fputc(ssi, '\n');
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
639
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
640 write_bool_option(ssi, "enable_startup_path", startup_path_enable);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
641 write_char_option(ssi, "startup_path", startup_path);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
642 secure_fputc(ssi, '\n');
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
643
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
644 secure_fprintf(ssi, "zoom_mode: ");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
645 if (zoom_mode == ZOOM_RESET_ORIGINAL) secure_fprintf(ssi, "original\n");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
646 if (zoom_mode == ZOOM_RESET_FIT_WINDOW) secure_fprintf(ssi, "fit\n");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
647 if (zoom_mode == ZOOM_RESET_NONE) secure_fprintf(ssi, "dont_change\n");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
648 write_bool_option(ssi, "two_pass_scaling", two_pass_zoom);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
649 write_bool_option(ssi, "zoom_to_fit_allow_expand", zoom_to_fit_expands);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
650 secure_fputc(ssi, '\n');
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
651
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
652 write_bool_option(ssi, "fit_window_to_image", fit_window);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
653 write_bool_option(ssi, "limit_window_size", limit_window_size);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
654 write_int_option(ssi, "max_window_size", max_window_size);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
655 write_bool_option(ssi, "limit_autofit_size", limit_autofit_size);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
656 write_int_option(ssi, "max_autofit_size", max_autofit_size);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
657 secure_fputc(ssi, '\n');
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
658
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
659 write_bool_option(ssi, "progressive_keyboard_scrolling", progressive_key_scrolling);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
660 write_int_option(ssi, "scroll_reset_method", scroll_reset_method);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
661 secure_fputc(ssi, '\n');
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
662
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
663 write_bool_option(ssi, "enable_thumbnails", thumbnails_enabled);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
664 write_int_option(ssi, "thumbnail_width", thumb_max_width);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
665 write_int_option(ssi, "thumbnail_height", thumb_max_height);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
666 write_bool_option(ssi, "cache_thumbnails", enable_thumb_caching);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
667 write_bool_option(ssi, "cache_thumbnails_into_dirs", enable_thumb_dirs);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
668 write_bool_option(ssi, "thumbnail_fast", thumbnail_fast);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
669 write_bool_option(ssi, "use_xvpics_thumbnails", use_xvpics_thumbnails);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
670 write_bool_option(ssi, "thumbnail_spec_standard", thumbnail_spec_standard);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
671 secure_fputc(ssi, '\n');
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
672
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
673 write_bool_option(ssi, "local_metadata", enable_metadata_dirs);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
674 secure_fputc(ssi, '\n');
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
675
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
676 write_int_option(ssi, "sort_method", (gint)file_sort_method);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
677 write_bool_option(ssi, "sort_ascending", file_sort_ascending);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
678 write_bool_option(ssi, "sort_case_sensitive", file_sort_case_sensitive);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
679 secure_fputc(ssi, '\n');
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
680
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
681 write_bool_option(ssi, "confirm_delete", confirm_delete);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
682 write_bool_option(ssi, "enable_delete_key", enable_delete_key);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
683 write_bool_option(ssi, "safe_delete", safe_delete_enable);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
684 write_char_option(ssi, "safe_delete_path", safe_delete_path);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
685 write_int_option(ssi, "safe_delete_size", safe_delete_size);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
686 secure_fputc(ssi, '\n');
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
687
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
688 write_bool_option(ssi, "tools_float", tools_float);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
689 write_bool_option(ssi, "tools_hidden", tools_hidden);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
690 write_bool_option(ssi, "restore_tool_state", restore_tool);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
691 write_bool_option(ssi, "toolbar_hidden", toolbar_hidden);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
692 secure_fputc(ssi, '\n');
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
693
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
694 write_bool_option(ssi, "mouse_wheel_scrolls", mousewheel_scrolls);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
695 write_bool_option(ssi, "in_place_rename", enable_in_place_rename);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
696 write_int_option(ssi, "open_recent_max", recent_list_max);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
697 write_int_option(ssi, "image_cache_size_max", tile_cache_max);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
698 write_int_option(ssi, "thumbnail_quality", thumbnail_quality);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
699 write_int_option(ssi, "zoom_quality", zoom_quality);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
700 write_int_option(ssi, "dither_quality", dither_quality);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
701 write_int_option(ssi, "zoom_increment", zoom_increment);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
702 write_bool_option(ssi, "enable_read_ahead", enable_read_ahead);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
703 write_bool_option(ssi, "display_dialogs_under_mouse", place_dialogs_under_mouse);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
704 secure_fputc(ssi, '\n');
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
705
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
706 write_bool_option(ssi, "user_specified_window_background", user_specified_window_background);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
707 write_color_option(ssi, "window_background_color", &window_background_color);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
708 secure_fputc(ssi, '\n');
4
e149abcda4eb Syncing to 0.8.1
gqview
parents: 3
diff changeset
709
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
710 write_int_option(ssi, "fullscreen_screen", fullscreen_screen);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
711 write_bool_option(ssi, "fullscreen_clean_flip", fullscreen_clean_flip);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
712 write_bool_option(ssi, "fullscreen_disable_saver", fullscreen_disable_saver);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
713 write_bool_option(ssi, "fullscreen_above", fullscreen_above);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
714 write_bool_option(ssi, "show_fullscreen_info", show_fullscreen_info);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
715 write_char_option(ssi, "fullscreen_info", fullscreen_info);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
716 secure_fputc(ssi, '\n');
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
717
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
718 write_int_option(ssi, "custom_similarity_threshold", dupe_custom_threshold);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
719
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
720 secure_fprintf(ssi, "\n##### Slideshow Options #####\n\n");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
721
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
722 write_int_unit_option(ssi, "slideshow_delay", slideshow_delay, SLIDESHOW_SUBSECOND_PRECISION);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
723
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
724 write_bool_option(ssi, "slideshow_random", slideshow_random);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
725 write_bool_option(ssi, "slideshow_repeat", slideshow_repeat);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
726
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
727 secure_fprintf(ssi, "\n##### Filtering Options #####\n\n");
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
728
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
729 write_bool_option(ssi, "show_dotfiles", show_dot_files);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
730 write_bool_option(ssi, "disable_filtering", file_filter_disable);
145
8be2cc687304 fixed grouping sidecar files and made it configurable via config file
nadvornik
parents: 113
diff changeset
731
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
732 filter_write_list(ssi);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
733
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
734 sidecar_ext_write(ssi);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
735
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
736 secure_fprintf(ssi, "\n##### Color Profiles #####\n\n");
113
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
737
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
738 #ifndef HAVE_LCMS
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
739 secure_fprintf(ssi, "# NOTICE: Geeqie was not built with support for color profiles,\n"
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
740 "# color profile options will have no effect.\n\n");
113
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
741 #endif
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
742
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
743 write_bool_option(ssi, "color_profile_enabled", color_profile_enabled);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
744 write_bool_option(ssi, "color_profile_use_image", color_profile_use_image);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
745 write_int_option(ssi, "color_profile_input_type", color_profile_input_type);
113
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
746 for (i = 0; i < COLOR_PROFILE_INPUTS; i++)
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
747 {
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
748 gchar *buf;
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
749
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
750 buf = g_strdup_printf("color_profile_input_file_%d", i + 1);
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
751 write_char_option(ssi, buf, color_profile_input_file[i]);
113
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
752 g_free(buf);
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
753
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
754 buf = g_strdup_printf("color_profile_input_name_%d", i + 1);
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
755 write_char_option(ssi, buf, color_profile_input_name[i]);
113
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
756 g_free(buf);
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
757 }
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
758 secure_fputc(ssi, '\n');
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
759 write_int_option(ssi, "color_profile_screen_type", color_profile_screen_type);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
760 write_char_option(ssi, "color_profile_screen_file_1", color_profile_screen_file);
113
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
761
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
762 secure_fprintf(ssi, "\n##### External Programs #####\n");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
763 secure_fprintf(ssi, "# Maximum of 10 programs (external_1 through external_10)\n");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
764 secure_fprintf(ssi, "# format: external_n: \"menu name\" \"command line\"\n\n");
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
765
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
766 for (i = 0; i < GQVIEW_EDITOR_SLOTS; i++)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
767 {
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
768 gchar *qname = escquote_value(editor_name[i]);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
769 gchar *qcommand = escquote_value(editor_command[i]);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
770 secure_fprintf(ssi, "external_%d: %s %s\n", i+1, qname, qcommand);
217
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
771 g_free(qname);
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
772 g_free(qcommand);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
773 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
774
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
775 secure_fprintf(ssi, "\n##### Collection Options #####\n\n");
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
776
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
777 write_bool_option(ssi, "rectangular_selections", collection_rectangular_selection);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
778
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
779 secure_fprintf(ssi, "\n##### Window Positions #####\n\n");
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
780
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
781 write_bool_option(ssi, "restore_window_positions", save_window_positions);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
782 secure_fputc(ssi, '\n');
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
783 write_int_option(ssi, "main_window_x", main_window_x);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
784 write_int_option(ssi, "main_window_y", main_window_y);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
785 write_int_option(ssi, "main_window_width", main_window_w);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
786 write_int_option(ssi, "main_window_height", main_window_h);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
787 write_bool_option(ssi, "main_window_maximized", main_window_maximized);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
788 write_int_option(ssi, "float_window_x", float_window_x);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
789 write_int_option(ssi, "float_window_y", float_window_y);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
790 write_int_option(ssi, "float_window_width", float_window_w);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
791 write_int_option(ssi, "float_window_height", float_window_h);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
792 write_int_option(ssi, "float_window_divider", float_window_divider);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
793 write_int_option(ssi, "divider_position_h", window_hdivider_pos);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
794 write_int_option(ssi, "divider_position_v", window_vdivider_pos);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
795
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
796 secure_fprintf(ssi, "\n##### Exif #####\n# 0: never\n# 1: if set\n# 2: always\n\n");
222
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 218
diff changeset
797 for (i = 0; ExifUIList[i].key; i++)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 218
diff changeset
798 {
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
799 secure_fprintf(ssi, "exif_");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
800 write_int_option(ssi, (gchar *)ExifUIList[i].key, ExifUIList[i].current);
222
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 218
diff changeset
801 }
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 218
diff changeset
802
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
803 secure_fputc(ssi, '\n');
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
804 secure_fprintf(ssi, "######################################################################\n");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
805 secure_fprintf(ssi, "# end of Geeqie config file #\n");
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
806 secure_fprintf(ssi, "######################################################################\n");
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
807
276
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
808
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
809 if (secure_close(ssi))
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
810 {
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
811 gchar *buf;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
812
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
813 buf = g_strdup_printf(_("error saving config file: %s\nerror: %s\n"), rc_path,
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
814 secsave_strerror(secsave_errno));
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
815 print_term(buf);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
816 g_free(buf);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
817
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
818 g_free(rc_path);
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
819 return;
4f526d436873 Implement secure rc file saving.
zas_
parents: 267
diff changeset
820 }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
821
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
822 g_free(rc_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
823 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
824
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
825 /*
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
826 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
827 * load configuration (public)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
828 *-----------------------------------------------------------------------------
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
829 */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
830
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
831 void load_options(void)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
832 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
833 FILE *f;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
834 gchar *rc_path;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
835 gchar *rc_pathl;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
836 gchar s_buf[1024];
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
837 gchar *s_buf_ptr;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
838 gchar option[1024];
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
839 gchar value[1024];
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
840 gchar value_all[1024];
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
841 gint c,l,i;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
842
222
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 218
diff changeset
843 for (i = 0; ExifUIList[i].key; i++)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 218
diff changeset
844 ExifUIList[i].current = ExifUIList[i].default_value;
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 218
diff changeset
845
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
846 rc_path = g_strconcat(homedir(), "/", GQVIEW_RC_DIR, "/", RC_FILE_NAME, NULL);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
847
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
848 rc_pathl = path_from_utf8(rc_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
849 f = fopen(rc_pathl,"r");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
850 g_free(rc_pathl);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
851 if (!f)
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
852 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
853 g_free(rc_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
854 return;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
855 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
856
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
857 while (fgets(s_buf,1024,f))
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
858 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
859 if (s_buf[0]=='#') continue;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
860 if (s_buf[0]=='\n') continue;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
861 c = 0;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
862 l = strlen(s_buf);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
863 while (s_buf[c] != ':' && c < l) c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
864 if (c >= l) continue;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
865 s_buf[c] = '\0';
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
866 c++;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
867 while ((s_buf[c] == ' ' || s_buf[c] == 8) && c < l) c++;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
868 s_buf_ptr = s_buf + c;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
869 strncpy(value_all, s_buf_ptr, sizeof(value_all));
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
870 while (s_buf[c] != 8 && s_buf[c] != ' ' && s_buf[c] != '\n' && c < l) c++;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
871 s_buf[c] = '\0';
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
872 strncpy(option, s_buf, sizeof(option));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
873 strncpy(value, s_buf_ptr, sizeof(value));
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
874
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
875 /* general options */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
876
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
877 layout_style = read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
878 "layout_style", value, layout_style);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
879 layout_order = read_char_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
880 "layout_order", value, layout_order);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
881 layout_view_icons = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
882 "layout_view_as_icons", value, layout_view_icons);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
883 layout_view_tree = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
884 "layout_view_as_tree", value, layout_view_tree);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
885 show_icon_names = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
886 "show_icon_names", value, show_icon_names);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
887
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
888 tree_descend_subdirs = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
889 "tree_descend_folders", value, tree_descend_subdirs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
890 lazy_image_sync = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
891 "lazy_image_sync", value, lazy_image_sync);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
892 update_on_time_change = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
893 "update_on_time_change", value, update_on_time_change);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
894 exif_rotate_enable = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
895 "exif_auto_rotate", value, exif_rotate_enable);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
896
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
897 startup_path_enable = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
898 "enable_startup_path", value, startup_path_enable);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
899 startup_path = read_char_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
900 "startup_path", value_all, startup_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
901
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
902 if (strcasecmp(option,"zoom_mode") == 0)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
903 {
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
904 if (strcasecmp(value, "original") == 0) zoom_mode = ZOOM_RESET_ORIGINAL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
905 if (strcasecmp(value, "fit") == 0) zoom_mode = ZOOM_RESET_FIT_WINDOW;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
906 if (strcasecmp(value, "dont_change") == 0) zoom_mode = ZOOM_RESET_NONE;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
907 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
908 two_pass_zoom = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
909 "two_pass_scaling", value, two_pass_zoom);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
910 zoom_to_fit_expands = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
911 "zoom_to_fit_allow_expand", value, zoom_to_fit_expands);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
912
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
913 fit_window = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
914 "fit_window_to_image", value, fit_window);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
915 limit_window_size = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
916 "limit_window_size", value, limit_window_size);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
917 max_window_size = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
918 "max_window_size", value, max_window_size);
209
ad78ad18523a configurable frame around image - geeqie_autofit_maxsize.patch by Laurent MONIN
nadvornik
parents: 208
diff changeset
919 limit_autofit_size = read_bool_option(f, option,
ad78ad18523a configurable frame around image - geeqie_autofit_maxsize.patch by Laurent MONIN
nadvornik
parents: 208
diff changeset
920 "limit_autofit_size", value, limit_autofit_size);
ad78ad18523a configurable frame around image - geeqie_autofit_maxsize.patch by Laurent MONIN
nadvornik
parents: 208
diff changeset
921 max_autofit_size = read_int_option(f, option,
ad78ad18523a configurable frame around image - geeqie_autofit_maxsize.patch by Laurent MONIN
nadvornik
parents: 208
diff changeset
922 "max_autofit_size", value, max_autofit_size);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
923 progressive_key_scrolling = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
924 "progressive_keyboard_scrolling", value, progressive_key_scrolling);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
925 scroll_reset_method = read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
926 "scroll_reset_method", value, scroll_reset_method);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
927
3
gqview
parents: 1
diff changeset
928 thumbnails_enabled = read_bool_option(f, option,
gqview
parents: 1
diff changeset
929 "enable_thumbnails", value, thumbnails_enabled);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
930 thumb_max_width = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
931 "thumbnail_width", value, thumb_max_width);
226
3c89da4aef95 Fix and simplify thumbnails size combo box related code.
zas_
parents: 222
diff changeset
932 if (thumb_max_width < 16) thumb_max_width = 16;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
933 thumb_max_height = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
934 "thumbnail_height", value, thumb_max_height);
226
3c89da4aef95 Fix and simplify thumbnails size combo box related code.
zas_
parents: 222
diff changeset
935 if (thumb_max_height < 16) thumb_max_height = 16;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
936 enable_thumb_caching = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
937 "cache_thumbnails", value, enable_thumb_caching);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
938 enable_thumb_dirs = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
939 "cache_thumbnails_into_dirs", value, enable_thumb_dirs);
14
25335c62cd9b ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
940 thumbnail_fast = read_bool_option(f, option,
25335c62cd9b ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
941 "thumbnail_fast", value, thumbnail_fast);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
942 use_xvpics_thumbnails = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
943 "use_xvpics_thumbnails", value, use_xvpics_thumbnails);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
944 thumbnail_spec_standard = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
945 "thumbnail_spec_standard", value, thumbnail_spec_standard);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
946
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
947 enable_metadata_dirs = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
948 "local_metadata", value, enable_metadata_dirs);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
949
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
950 file_sort_method = (SortType)read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
951 "sort_method", value, (gint)file_sort_method);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
952 file_sort_ascending = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
953 "sort_ascending", value, file_sort_ascending);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
954 file_sort_case_sensitive = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
955 "sort_case_sensitive", value, file_sort_case_sensitive);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
956
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
957 confirm_delete = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
958 "confirm_delete", value, confirm_delete);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
959 enable_delete_key = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
960 "enable_delete_key", value, enable_delete_key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
961 safe_delete_enable = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
962 "safe_delete", value, safe_delete_enable);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
963 safe_delete_path = read_char_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
964 "safe_delete_path", value, safe_delete_path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
965 safe_delete_size = read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
966 "safe_delete_size", value, safe_delete_size);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
967
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
968 tools_float = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
969 "tools_float", value, tools_float);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
970 tools_hidden = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
971 "tools_hidden", value, tools_hidden);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
972 restore_tool = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
973 "restore_tool_state", value, restore_tool);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
974
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
975 toolbar_hidden = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
976 "toolbar_hidden", value, toolbar_hidden);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
977
4
e149abcda4eb Syncing to 0.8.1
gqview
parents: 3
diff changeset
978 mousewheel_scrolls = read_bool_option(f, option,
e149abcda4eb Syncing to 0.8.1
gqview
parents: 3
diff changeset
979 "mouse_wheel_scrolls", value, mousewheel_scrolls);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
980 enable_in_place_rename = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
981 "in_place_rename", value, enable_in_place_rename);
4
e149abcda4eb Syncing to 0.8.1
gqview
parents: 3
diff changeset
982
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
983 recent_list_max = read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
984 "open_recent_max", value, recent_list_max);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
985
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
986 tile_cache_max = read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
987 "image_cache_size_max", value, tile_cache_max);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
988
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
989 thumbnail_quality = CLAMP(read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
990 "thumbnail_quality", value, thumbnail_quality), GDK_INTERP_NEAREST, GDK_INTERP_HYPER);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
991 zoom_quality = CLAMP(read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
992 "zoom_quality", value, zoom_quality), GDK_INTERP_NEAREST, GDK_INTERP_HYPER);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
993 dither_quality = CLAMP(read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
994 "dither_quality", value, dither_quality), GDK_RGB_DITHER_NONE, GDK_RGB_DITHER_MAX);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
995
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
996 zoom_increment = read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
997 "zoom_increment", value, zoom_increment);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
998
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
999 enable_read_ahead = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1000 "enable_read_ahead", value, enable_read_ahead);
4
e149abcda4eb Syncing to 0.8.1
gqview
parents: 3
diff changeset
1001
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1002 place_dialogs_under_mouse = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1003 "display_dialogs_under_mouse", value, place_dialogs_under_mouse);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1004
208
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
1005 user_specified_window_background = read_bool_option(f, option,
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
1006 "user_specified_window_background", value, user_specified_window_background);
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
1007 read_color_option(f, option,
fa0e05f985c3 set user-defined color as image background - patch by Laurent MONIN
nadvornik
parents: 196
diff changeset
1008 "window_background_color", value, &window_background_color);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1009
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1010 fullscreen_screen = read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1011 "fullscreen_screen", value, fullscreen_screen);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1012 fullscreen_clean_flip = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1013 "fullscreen_clean_flip", value, fullscreen_clean_flip);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1014 fullscreen_disable_saver = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1015 "fullscreen_disable_saver", value, fullscreen_disable_saver);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1016 fullscreen_above = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1017 "fullscreen_above", value, fullscreen_above);
218
f4a0555794a9 Customizable info overlay in fullscreen, based on the patch posted to gqview-devel list by Timo on 2007-09-10.
zas_
parents: 217
diff changeset
1018 show_fullscreen_info = read_bool_option(f, option,
f4a0555794a9 Customizable info overlay in fullscreen, based on the patch posted to gqview-devel list by Timo on 2007-09-10.
zas_
parents: 217
diff changeset
1019 "show_fullscreen_info", value, show_fullscreen_info);
f4a0555794a9 Customizable info overlay in fullscreen, based on the patch posted to gqview-devel list by Timo on 2007-09-10.
zas_
parents: 217
diff changeset
1020 fullscreen_info = read_char_option(f, option,
f4a0555794a9 Customizable info overlay in fullscreen, based on the patch posted to gqview-devel list by Timo on 2007-09-10.
zas_
parents: 217
diff changeset
1021 "fullscreen_info", value_all, fullscreen_info);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1022
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1023 dupe_custom_threshold = read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1024 "custom_similarity_threshold", value, dupe_custom_threshold);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1025
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1026 /* slideshow options */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1027
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1028 slideshow_delay = read_int_unit_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1029 "slideshow_delay", value, slideshow_delay, SLIDESHOW_SUBSECOND_PRECISION);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1030 slideshow_random = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1031 "slideshow_random", value, slideshow_random);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1032 slideshow_repeat = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1033 "slideshow_repeat", value, slideshow_repeat);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1034
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1035 /* filtering options */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1036
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1037 show_dot_files = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1038 "show_dotfiles", value, show_dot_files);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1039 file_filter_disable = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1040 "disable_filtering", value, file_filter_disable);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1041
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1042 if (strcasecmp(option, "filter_ext") == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1043 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1044 filter_parse(value_all);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1045 }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1046
145
8be2cc687304 fixed grouping sidecar files and made it configurable via config file
nadvornik
parents: 113
diff changeset
1047 if (strcasecmp(option, "sidecar_ext") == 0)
8be2cc687304 fixed grouping sidecar files and made it configurable via config file
nadvornik
parents: 113
diff changeset
1048 {
170
9a56e3d13e67 basic sidecar files configuration via preferences dialog
nadvornik
parents: 145
diff changeset
1049 sidecar_ext_parse(value_all, TRUE);
145
8be2cc687304 fixed grouping sidecar files and made it configurable via config file
nadvornik
parents: 113
diff changeset
1050 }
8be2cc687304 fixed grouping sidecar files and made it configurable via config file
nadvornik
parents: 113
diff changeset
1051
113
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1052 /* Color Profiles */
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1053
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1054 color_profile_enabled = read_bool_option(f, option,
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1055 "color_profile_enabled", value, color_profile_enabled);
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1056 color_profile_use_image = read_bool_option(f, option,
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1057 "color_profile_use_image", value, color_profile_use_image);
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1058 color_profile_input_type = read_int_option(f, option,
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1059 "color_profile_input_type", value, color_profile_input_type);
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1060
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1061 if (strncasecmp(option, "color_profile_input_file_", 25) == 0)
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1062 {
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1063 i = strtol(option + 25, NULL, 0) - 1;
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1064 if (i >= 0 && i < COLOR_PROFILE_INPUTS)
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1065 {
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1066 color_profile_input_file[i] = read_char_option(f, option,
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1067 option, value, color_profile_input_file[i]);
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1068 }
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1069 }
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1070 if (strncasecmp(option, "color_profile_input_name_", 25) == 0)
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1071 {
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1072 i = strtol(option + 25, NULL, 0) - 1;
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1073 if (i >= 0 && i < COLOR_PROFILE_INPUTS)
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1074 {
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1075 color_profile_input_name[i] = read_char_option(f, option,
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1076 option, value, color_profile_input_name[i]);
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1077 }
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1078 }
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1079
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1080 color_profile_screen_type = read_int_option(f, option,
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1081 "color_profile_screen_type", value, color_profile_screen_type);
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1082 color_profile_screen_file = read_char_option(f, option,
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1083 "color_profile_screen_file_1", value, color_profile_screen_file);
55166d93498d Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents: 41
diff changeset
1084
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1085 /* External Programs */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1086
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1087 if (strncasecmp(option, "external_", 9) == 0)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1088 {
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1089 i = strtol(option + 9, NULL, 0);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1090 if (i > 0 && i <= GQVIEW_EDITOR_SLOTS)
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1091 {
217
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
1092 const gchar *ptr;
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1093 i--;
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1094 g_free(editor_name[i]);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1095 g_free(editor_command[i]);
217
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
1096
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
1097 editor_name[i] = quoted_value(value_all, &ptr);
5bdab7ed4bcd use quoted_value everywhere
nadvornik
parents: 210
diff changeset
1098 editor_command[i] = quoted_value(ptr, NULL);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1099 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1100 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1101
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1102 /* colection options */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1103
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1104 collection_rectangular_selection = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1105 "rectangular_selections", value, collection_rectangular_selection);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1106
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1107 /* window positions */
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1108
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1109 save_window_positions = read_bool_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1110 "restore_window_positions", value, save_window_positions);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1111
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1112 main_window_x = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1113 "main_window_x", value, main_window_x);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1114 main_window_y = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1115 "main_window_y", value, main_window_y);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1116 main_window_w = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1117 "main_window_width", value, main_window_w);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1118 main_window_h = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1119 "main_window_height", value, main_window_h);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1120 main_window_maximized = read_bool_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1121 "main_window_maximized", value, main_window_maximized);
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1122 float_window_x = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1123 "float_window_x", value, float_window_x);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1124 float_window_y = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1125 "float_window_y", value, float_window_y);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1126 float_window_w = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1127 "float_window_width", value, float_window_w);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1128 float_window_h = read_int_option(f, option,
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1129 "float_window_height", value, float_window_h);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1130 float_window_divider = read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1131 "float_window_divider", value, float_window_divider);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1132 window_hdivider_pos = read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1133 "divider_position_h", value, window_hdivider_pos);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1134 window_vdivider_pos = read_int_option(f, option,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1135 "divider_position_v", value, window_vdivider_pos);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents: 4
diff changeset
1136
222
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 218
diff changeset
1137 if (0 == strncasecmp(option, "exif_", 5))
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 218
diff changeset
1138 {
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 218
diff changeset
1139 for (i = 0; ExifUIList[i].key; i++)
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 218
diff changeset
1140 if (0 == strcasecmp(option+5, ExifUIList[i].key))
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 218
diff changeset
1141 ExifUIList[i].current = strtol(value, NULL, 10);
77f1bcc6c161 various exif improvements based on patch by Uwe Ohse
nadvornik
parents: 218
diff changeset
1142 }
1
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1143 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1144
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1145 fclose(f);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1146 g_free(rc_path);
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1147 }
b3e0e515fabf Initial revision
gqview
parents:
diff changeset
1148