anastasis_gtk_util.h (7257B)
1 /* 2 This file is part of ANASTASIS-GTK 3 Copyright (C) 2024 Taler Systems SA 4 5 ANASTASIS-GTK is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 ANASTASIS-GTK is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 ANASTASIS-GTK; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file include/anastasis_gtk_util.h 18 * @brief Interface for common utility functions 19 * @author Christian Grothoff 20 */ 21 #ifndef ANASTASIS_GTK_UTIL_H 22 #define ANASTASIS_GTK_UTIL_H 23 24 #include <gnunet/gnunet_util_lib.h> 25 26 27 #include <gtk/gtk.h> 28 #include <gdk/gdkkeysyms.h> 29 30 #define _(String) dgettext (PACKAGE, String) 31 32 /** 33 * Mark a string for translation without translating it right here, for 34 * strings in static tables. Translate them with #_() where they are used. 35 */ 36 #define N_(String) String 37 38 #define DIR_SEPARATOR_STR "/" 39 40 #define DIR_SEPARATOR '/' 41 42 43 /** 44 * Handle for our main loop. 45 */ 46 struct ANASTASIS_GTK_MainLoop; 47 48 49 /* ****************** Initialization *************** */ 50 51 52 /** 53 * Initialize natural language support. 54 */ 55 void 56 ANASTASIS_GTK_setup_nls (void); 57 58 59 /** 60 * Initialize GTK search path for icons. 61 * 62 * @param pd project data to use 63 */ 64 void 65 ANASTASIS_GTK_set_icon_search_path ( 66 const struct GNUNET_OS_ProjectData *pd); 67 68 69 /** 70 * Get the name of the directory where all of our package 71 * data is stored ($PREFIX/share/) 72 * 73 * @param pd project data to use 74 * @return name of the data directory 75 */ 76 const char * 77 ANASTASIS_GTK_get_data_dir ( 78 const struct GNUNET_OS_ProjectData *pd); 79 80 81 /** 82 * @brief get the path to a specific GNUnet installation directory or, 83 * with #GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation 84 * directory 85 * @author Milan 86 * 87 * @param dirkind which directory should be returned 88 * @return a pointer to the dir path (to be freed by the caller) 89 */ 90 char * 91 ANASTASIS_GTK_installation_get_path ( 92 enum GNUNET_OS_InstallationPathKind dirkind); 93 94 95 /* **************** GtkBuilder helpers ************** */ 96 97 /** 98 * Create and initialize a new builder from one of our GtkBuilder UI 99 * files. Signal handlers named in the file are resolved against the 100 * binary's dynamic symbols and connected while the file is parsed. 101 * 102 * @param pd project data to use 103 * @param filename name of the resource file to load 104 * @param user_data object to pass to signal handlers, 105 * use "NULL" to pass the GtkBuilder itself. 106 * @return NULL on error 107 */ 108 GtkBuilder * 109 ANASTASIS_GTK_get_new_builder ( 110 const struct GNUNET_OS_ProjectData *pd, 111 const char *filename, 112 GObject *user_data); 113 114 115 /** 116 * Convert a string from the current locale to UTF-8. 117 * 118 * @param str_loc string in current locale 119 * @return string in UTF-8, NULL if str_loc was NULL 120 */ 121 char * 122 ANASTASIS_GTK_from_loc_to_utf8 (const char *str_loc); 123 124 125 /** 126 * Returns the path of @a file, encoded in UTF-8. 127 * 128 * @param fc the file the user picked, may be NULL 129 * @return path of @a file as UTF-8, NULL on errors 130 */ 131 char * 132 ANASTASIS_GTK_file_get_path_utf8 (GFile *file); 133 134 135 /** 136 * Load the application's style sheet. Called once GTK is up. 137 */ 138 void 139 ANASTASIS_GTK_load_css ( 140 const struct GNUNET_OS_ProjectData *pd); 141 142 143 /* ******************* main loop ***************** */ 144 145 146 /** 147 * Initialize the main loop. 148 * 149 * @param pd project data of the program we are launching 150 * @param binary_name binary name 151 * @param binary_help help text for the binary 152 * @param argc number of command line options 153 * @param argv command line options 154 * @param options allowed command line options 155 * @param main_window_file GtkBuilder UI file for the main window 156 * @param main_task first task to run, closure will be set to the `struct 157 * ANASTASIS_GTK_MainLoop` 158 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (i.e. bad command-line 159 * options, etc) 160 */ 161 int 162 ANASTASIS_GTK_main_loop_start ( 163 const struct GNUNET_OS_ProjectData *pd, 164 const char *binary_name, 165 const char *binary_help, 166 int argc, 167 char *const *argv, 168 struct GNUNET_GETOPT_CommandLineOption *options, 169 const char *main_window_file, 170 GNUNET_SCHEDULER_TaskCallback main_task); 171 172 173 /** 174 * Get an object from the main window. 175 * 176 * @param ml handle to the main loop 177 * @param name name of the object 178 * @return NULL on error, otherwise the object 179 */ 180 GObject * 181 ANASTASIS_GTK_main_loop_get_object (struct ANASTASIS_GTK_MainLoop *ml, 182 const char *name); 183 184 185 /** 186 * Get the builder from the main window. 187 * 188 * @param ml handle to the main loop 189 * @return NULL on error, otherwise the builder 190 */ 191 GtkBuilder * 192 ANASTASIS_GTK_main_loop_get_builder (struct ANASTASIS_GTK_MainLoop *ml); 193 194 195 /** 196 * Get remaining command line arguments. 197 * 198 * @param ml handle to the main loop 199 * @param argc set to argument count 200 * @param argv set to argument vector 201 */ 202 void 203 ANASTASIS_GTK_main_loop_get_args (struct ANASTASIS_GTK_MainLoop *ml, 204 int *argc, 205 char *const **argv); 206 207 208 /** 209 * Initialize a GtkBuilder for the main window and exit 210 * the main loop if this fails. 211 * 212 * @param pd project data to use 213 * @param ml main loop contextual data 214 * @param data additional argument to pass to #ANASTASIS_GTK_get_new_builder() 215 * (may be NULL to pass the builder itself) 216 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 217 */ 218 int 219 ANASTASIS_GTK_main_loop_build_window ( 220 const struct GNUNET_OS_ProjectData *pd, 221 struct ANASTASIS_GTK_MainLoop *ml, 222 GObject *data); 223 224 225 /** 226 * Obtain the name of the configuration file that is being used 227 * by gnunet-gtk. 228 * 229 * @param ml handle to the main loop 230 * @return name of configuration file 231 */ 232 const char * 233 ANASTASIS_GTK_main_loop_get_gtk_configuration_file ( 234 struct ANASTASIS_GTK_MainLoop *ml); 235 236 /** 237 * Obtain the name of the configuration file that is being used 238 * by GNUnet (core). 239 * 240 * @param ml handle to the main loop 241 * @return name of configuration file 242 */ 243 const char * 244 ANASTASIS_GTK_main_loop_get_gnunet_configuration_file ( 245 struct ANASTASIS_GTK_MainLoop *ml); 246 247 248 /** 249 * Get the configuration. 250 * 251 * @param ml handle to the main loop 252 * @return handle to the configuration, never NULL 253 */ 254 const struct GNUNET_CONFIGURATION_Handle * 255 ANASTASIS_GTK_main_loop_get_gtk_configuration ( 256 struct ANASTASIS_GTK_MainLoop *ml); 257 258 259 /** 260 * Get the configuration. 261 * 262 * @param ml handle to the main loop 263 * @return handle to the configuration, never NULL 264 */ 265 const struct GNUNET_CONFIGURATION_Handle * 266 ANASTASIS_GTK_main_loop_get_gnunet_configuration (struct ANASTASIS_GTK_MainLoop *ml); 267 268 269 /** 270 * Trigger shutdown of the GUI and exit the main loop. 271 * 272 * @param ml handle to the main loop 273 */ 274 void 275 ANASTASIS_GTK_main_loop_quit (struct ANASTASIS_GTK_MainLoop *ml); 276 277 278 /** 279 * Return project data used by Anastasis-Gtk. 280 * 281 * @return project data for anastasis-gtk 282 */ 283 const struct GNUNET_OS_ProjectData * 284 ANASTASIS_GTK_project_data (void); 285 286 287 #endif