Move third-party sources to separate sub-directory
[geeqie.git] / src / ui-fileops.h
1 /*
2  * Copyright (C) 2004 John Ellis
3  * Copyright (C) 2008 - 2016 The Geeqie Team
4  *
5  * Author: John Ellis
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef UI_FILEOPS_H
23 #define UI_FILEOPS_H
24
25 #include <sys/types.h>
26
27 #include <ctime>
28
29 #include <gio/gio.h>
30 #include <glib.h>
31
32 #include <config.h>
33
34 #ifdef DEBUG
35 #define GQ_DEBUG_PATH_UTF8 1
36 #endif
37
38 void print_term(gboolean err, const gchar *text_utf8);
39
40 #define printf_term(err, ...) \
41         do { \
42                 gchar *msg = g_strdup_printf(__VA_ARGS__); \
43                 print_term(err, msg); \
44                 g_free(msg); \
45         } while (0)
46
47 #if GQ_DEBUG_PATH_UTF8
48 #define path_to_utf8(path) path_to_utf8_debug(path, __FILE__, __LINE__)
49 #define path_from_utf8(utf8) path_from_utf8_debug(utf8, __FILE__, __LINE__)
50 gchar *path_to_utf8_debug(const gchar *path, const gchar *file, gint line);
51 gchar *path_from_utf8_debug(const gchar *utf8, const gchar *file, gint line);
52 #else
53 gchar *path_to_utf8(const gchar *path);
54 gchar *path_from_utf8(const gchar *utf8);
55 #endif
56
57 const gchar *xdg_data_home_get();
58 const gchar *xdg_config_home_get();
59 const gchar *xdg_cache_home_get();
60 const gchar *homedir();
61 const gchar *get_rc_dir();
62 const gchar *get_collections_dir();
63 const gchar *get_trash_dir();
64 const gchar *get_window_layouts_dir();
65
66 gboolean stat_utf8(const gchar *s, struct stat *st);
67 gboolean lstat_utf8(const gchar *s, struct stat *st);
68
69 gboolean isname(const gchar *s);
70 gboolean isfile(const gchar *s);
71 gboolean isdir(const gchar *s);
72 gboolean islink(const gchar *s);
73 gint64 filesize(const gchar *s);
74 time_t filetime(const gchar *s);
75 gboolean filetime_set(const gchar *s, time_t tval);
76 gboolean is_readable_file(const gchar *s);
77 gboolean access_file(const gchar *s, gint mode);
78 gboolean unlink_file(const gchar *s);
79 gboolean mkdir_utf8(const gchar *s, gint mode);
80 gboolean rmdir_utf8(const gchar *s);
81 gboolean copy_file_attributes(const gchar *s, const gchar *t, gint perms, gint mtime);
82 gboolean copy_file(const gchar *s, const gchar *t);
83 gboolean move_file(const gchar *s, const gchar *t);
84 gboolean rename_file(const gchar *s, const gchar *t);
85 gchar *get_current_dir();
86
87 /**
88  * @headerfile string_list_free
89  * return True on success, it is up to you to free
90  * the lists with string_list_free()
91  */
92 void string_list_free(GList *list);
93 GList *string_list_copy(const GList *list);
94
95 gchar *unique_filename(const gchar *path, const gchar *ext, const gchar *divider, gboolean pad);
96
97 const gchar *filename_from_path(const gchar *path);
98 gchar *remove_level_from_path(const gchar *path);
99
100 gchar *remove_extension_from_path(const gchar *path);
101
102 gboolean file_extension_match(const gchar *path, const gchar *ext);
103
104 /**
105  * @headerfile parse_out_relatives
106  * warning note: this modifies path string!
107  */
108 void parse_out_relatives(gchar *path);
109
110 gboolean file_in_path(const gchar *name);
111
112 gboolean recursive_mkdir_if_not_exists(const gchar *path, mode_t mode);
113
114
115 /**
116  * @headerfile md5_text_from_file_utf8
117  * generate md5 string from file,
118  * on failure returns newly allocated copy of error_text, error_text may be NULL
119  */
120 gchar *md5_text_from_file_utf8(const gchar *path, const gchar *error_text);
121 gboolean md5_get_digest_from_file_utf8(const gchar *path, guchar digest[16]);
122
123 gboolean download_web_file(const gchar *text, gboolean minimized, gpointer data);
124 gboolean rmdir_recursive(GFile *file, GCancellable *cancellable, GError **error);
125 gint scale_factor();
126
127 #endif
128 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */