Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
utility.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2010-2020 darktable developers.
4
5 darktable is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 darktable is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with darktable. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#pragma once
20
21#include <gtk/gtk.h>
22#include <string.h>
23#include <librsvg/rsvg.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
35size_t safe_strlen(const char *str);
36
38gchar *dt_util_dstrcat(gchar *str, const gchar *format, ...) __attribute__((format(printf, 2, 3)));
39
41gchar *dt_util_str_replace(const gchar *string, const gchar *pattern, const gchar *substitute);
43guint dt_util_str_occurence(const gchar *haystack, const gchar *needle);
45gchar *dt_util_glist_to_str(const gchar *separator, GList *items);
47GList *dt_util_str_to_glist(const gchar *separator, const gchar *text);
49GList *dt_util_glist_uniq(GList *items);
51gchar *dt_util_fix_path(const gchar *path);
52size_t dt_utf8_strlcpy(char *dest, const char *src, size_t n);
54gboolean dt_util_test_image_file(const char *filename);
56gboolean dt_util_test_writable_dir(const char *path);
58gboolean dt_util_dir_exist(const char *dir);
60gboolean dt_util_is_dir_empty(const char *dirname);
62gchar *dt_util_foo_to_utf8(const char *string);
64guint dt_util_string_count_char(const char *text, const char needle);
65/* helper function to convert en float numbers to local based numbers for scanf */
67
75
78
79cairo_surface_t *dt_util_get_logo(const float size);
80cairo_surface_t *dt_util_get_logo_text(const float size);
81
82gchar *dt_util_latitude_str(float latitude);
83gchar *dt_util_longitude_str(float longitude);
84gchar *dt_util_elevation_str(float elevation);
85double dt_util_gps_string_to_number(const gchar *input);
86gboolean dt_util_gps_rationale_to_number(const double r0_1, const double r0_2, const double r1_1,
87 const double r1_2, const double r2_1, const double r2_2, char sign,
88 double *result);
89gboolean dt_util_gps_elevation_to_number(const double r_1, const double r_2, char sign, double *result);
90
91// make paths absolute and try to normalize on Windows. also deal with character encoding on Windows.
92gchar *dt_util_normalize_path(const gchar *input);
93
94#ifdef WIN32
95// returns TRUE if the path is a Windows UNC (\\server\share\...\file)
96const gboolean dt_util_path_is_UNC(const gchar *filename);
97#endif
98
99// gets the directory components of a file name, like g_path_get_dirname(), but works also with Windows networks paths (\\hostname\share\file)
100gchar *dt_util_path_get_dirname(const gchar *filename);
101
102// format exposure time string
103gchar *dt_util_format_exposure(const float exposuretime);
104
105// read the contents of the given file into a malloc'ed buffer
106// returns NULL if unable to read file or alloc memory; sets filesize to the number of bytes returned
107char *dt_read_file(const char *filename, size_t *filesize);
108
109// copy the contents of the given file to a new file
110void dt_copy_file(const char *src, const char *dst);
111
112// copy the contents of a file in dt's data directory to a new file
113void dt_copy_resource_file(const char *src, const char *dst);
114
115// returns the RsvgDimensionData of a supplied RsvgHandle
116RsvgDimensionData dt_get_svg_dimension(RsvgHandle *svg);
117
118// renders svg data
119void dt_render_svg(RsvgHandle *svg, cairo_t *cr, double width, double height, double offset_x, double offset_y);
120
121// check if the path + basenames are the same (<=> only differ by the extension)
122gboolean dt_has_same_path_basename(const char *filename1, const char *filename2);
123
124// set the filename2 extension to filename1 - return NULL if fails - result should be freed
125char *dt_copy_filename_extension(const char *filename1, const char *filename2);
126
127// replaces all occurences of a substring in a string
128gchar *dt_str_replace(const char *string, const char *search, const char *replace);
129
130// Checks for the opposite separator in a string and replace it by the needed one by the current OS
131gchar *dt_cleanup_separators(gchar *string);
132
133gchar *dt_util_remove_whitespace(const gchar *path);
134
135// Get the datetime of modification for a given file, identified by its full path
136GDateTime *dt_util_get_file_datetime(const char *const path);
137
138#ifdef __cplusplus
139}
140#endif
141
142// clang-format off
143// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
144// vim: shiftwidth=2 expandtab tabstop=2 cindent
145// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
146// clang-format on
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
const dt_collection_sort_t items[]
Definition filter.c:74
size_t size
Definition mipmap_cache.c:3
static int sign(int a)
Definition nlmeans_core.c:84
static float __attribute__((__unused__))
Definition thinplate.c:39
gboolean dt_util_gps_elevation_to_number(const double r_1, const double r_2, char sign, double *result)
Definition utility.c:631
guint dt_util_string_count_char(const char *text, const char needle)
Definition utility.c:773
gchar * dt_util_longitude_str(float longitude)
Definition utility.c:538
gchar * dt_str_replace(const char *string, const char *search, const char *replace)
Definition utility.c:1001
gboolean dt_has_same_path_basename(const char *filename1, const char *filename2)
Definition utility.c:962
void dt_util_str_to_loc_numbers_format(char *data)
Definition utility.c:784
gchar * dt_cleanup_separators(gchar *string)
Definition utility.c:1010
gchar * dt_util_elevation_str(float elevation)
Definition utility.c:556
gboolean dt_util_dir_exist(const char *dir)
Definition utility.c:335
dt_logo_season_t dt_util_get_logo_season(void)
Definition utility.c:402
RsvgDimensionData dt_get_svg_dimension(RsvgHandle *svg)
Definition utility.c:912
cairo_surface_t * dt_util_get_logo_text(const float size)
Definition utility.c:502
GDateTime * dt_util_get_file_datetime(const char *const path)
Definition utility.c:758
GList * dt_util_str_to_glist(const gchar *separator, const gchar *text)
Definition utility.c:792
gboolean dt_util_test_image_file(const char *filename)
Definition utility.c:286
gchar * dt_util_format_exposure(const float exposuretime)
Definition utility.c:827
char * dt_read_file(const char *filename, size_t *filesize)
Definition utility.c:855
void dt_copy_resource_file(const char *src, const char *dst)
Definition utility.c:903
gchar gchar * dt_util_str_replace(const gchar *string, const gchar *pattern, const gchar *substitute)
Definition utility.c:104
guint dt_util_str_occurence(const gchar *haystack, const gchar *needle)
Definition utility.c:87
gchar * dt_util_normalize_path(const gchar *input)
Definition utility.c:649
double dt_util_gps_string_to_number(const gchar *input)
Definition utility.c:575
gchar * dt_util_path_get_dirname(const gchar *filename)
Definition utility.c:743
dt_logo_season_t
Definition utility.h:69
@ DT_LOGO_SEASON_HALLOWEEN
Definition utility.h:71
@ DT_LOGO_SEASON_XMAS
Definition utility.h:72
@ DT_LOGO_SEASON_EASTER
Definition utility.h:73
@ DT_LOGO_SEASON_NONE
Definition utility.h:70
gboolean dt_util_is_dir_empty(const char *dirname)
Definition utility.c:343
size_t dt_utf8_strlcpy(char *dest, const char *src, size_t n)
Definition utility.c:257
size_t safe_strlen(const char *str)
check if the string is empty or NULL before calling strlen()
Definition utility.c:58
gboolean dt_util_test_writable_dir(const char *path)
Definition utility.c:312
gboolean dt_util_gps_rationale_to_number(const double r0_1, const double r0_2, const double r1_1, const double r1_2, const double r2_1, const double r2_2, char sign, double *result)
Definition utility.c:593
gchar * dt_util_fix_path(const gchar *path)
Definition utility.c:190
void dt_copy_file(const char *src, const char *dst)
Definition utility.c:879
gchar * dt_util_foo_to_utf8(const char *string)
Definition utility.c:360
gchar * dt_util_latitude_str(float latitude)
Definition utility.c:520
gchar * dt_util_remove_whitespace(const gchar *path)
Definition utility.c:1021
void dt_render_svg(RsvgHandle *svg, cairo_t *cr, double width, double height, double offset_x, double offset_y)
Definition utility.c:945
gchar * dt_util_dstrcat(gchar *str, const gchar *format,...) __attribute__((format(printf
gchar * dt_util_glist_to_str(const gchar *separator, GList *items)
Definition utility.c:134
char * dt_copy_filename_extension(const char *filename1, const char *filename2)
Definition utility.c:981
GList * dt_util_glist_uniq(GList *items)
Definition utility.c:161
cairo_surface_t * dt_util_get_logo(const float size)
Definition utility.c:490