anastasis_gtk_util.h (7444B)
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 <gladeui/glade.h> 29 #include <gdk/gdkkeysyms.h> 30 31 #ifndef GDK_KEY_Return 32 #define GDK_KEY_Return GDK_Return 33 #endif 34 #ifndef GDK_KEY_Delete 35 #define GDK_KEY_Delete GDK_Delete 36 #endif 37 38 #define _(String) dgettext (PACKAGE, String) 39 40 #define DIR_SEPARATOR_STR "/" 41 42 #define DIR_SEPARATOR '/' 43 44 45 /** 46 * Handle for our main loop. 47 */ 48 struct ANASTASIS_GTK_MainLoop; 49 50 51 /* ****************** Initialization *************** */ 52 53 54 /** 55 * Initialize natural language support. 56 */ 57 void 58 ANASTASIS_GTK_setup_nls (void); 59 60 61 /** 62 * Initialize GTK search path for icons. 63 * 64 * @param pd project data to use 65 */ 66 void 67 ANASTASIS_GTK_set_icon_search_path ( 68 const struct GNUNET_OS_ProjectData *pd); 69 70 71 /** 72 * Get the name of the directory where all of our package 73 * data is stored ($PREFIX/share/) 74 * 75 * @param pd project data to use 76 * @return name of the data directory 77 */ 78 const char * 79 ANASTASIS_GTK_get_data_dir ( 80 const struct GNUNET_OS_ProjectData *pd); 81 82 83 /** 84 * @brief get the path to a specific GNUnet installation directory or, 85 * with #GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation 86 * directory 87 * @author Milan 88 * 89 * @param dirkind which directory should be returned 90 * @return a pointer to the dir path (to be freed by the caller) 91 */ 92 char * 93 ANASTASIS_GTK_installation_get_path ( 94 enum GNUNET_OS_InstallationPathKind dirkind); 95 96 97 /* **************** Glade/Gtk helpers *************** */ 98 99 /** 100 * Create an initialize a new builder based on the 101 * GNUnet-GTK glade file. 102 * 103 * @param pd project data to use 104 * @param filename name of the resource file to load 105 * @param user_data user_data to pass to signal handlers, 106 * use "NULL" to pass the GtkBuilder itself. 107 * @param cb function to call before connecting signals 108 * @return NULL on error 109 */ 110 GtkBuilder * 111 ANASTASIS_GTK_get_new_builder2 ( 112 const struct GNUNET_OS_ProjectData *pd, 113 const char *filename, 114 void *user_data, 115 GtkBuilderConnectFunc cb); 116 117 118 /** 119 * Create an initialize a new builder based on the GNUnet-GTK glade 120 * file. 121 * 122 * @param pd project data to use 123 * @param filename name of the resource file to load 124 * @param user_data user_data to pass to signal handlers, 125 * use "NULL" to pass the GtkBuilder itself. 126 * @return NULL on error 127 */ 128 #define ANASTASIS_GTK_get_new_builder(pd, filename, user_data) \ 129 ANASTASIS_GTK_get_new_builder2 (pd, filename, user_data, NULL) 130 131 132 /** 133 * Convert a string from the current locale to UTF-8. 134 * 135 * @param str_loc string in current locale 136 * @return string in UTF-8, NULL if str_loc was NULL 137 */ 138 char * 139 ANASTASIS_GTK_from_loc_to_utf8 (const char *str_loc); 140 141 142 /** 143 * Returns filename form filechooser, encoded in UTF-8. 144 * 145 * @param fc file chooser to inspect 146 * @return selected filename as UTF-8, NULL on errors 147 */ 148 char * 149 ANASTASIS_GTK_filechooser_get_filename_utf8 (GtkFileChooser *fc); 150 151 152 /* ******************* main loop ***************** */ 153 154 155 /** 156 * Initialize the main loop. 157 * 158 * @param pd project data of the program we are launching 159 * @param binary_name binary name 160 * @param binary_help help text for the binary 161 * @param argc number of command line options 162 * @param argv command line options 163 * @param options allowed command line options 164 * @param main_window_file glade file for the main window 165 * @param main_task first task to run, closure will be set to the `struct 166 * ANASTASIS_GTK_MainLoop` 167 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (i.e. bad command-line 168 * options, etc) 169 */ 170 int 171 ANASTASIS_GTK_main_loop_start ( 172 const struct GNUNET_OS_ProjectData *pd, 173 const char *binary_name, 174 const char *binary_help, 175 int argc, 176 char *const *argv, 177 struct GNUNET_GETOPT_CommandLineOption *options, 178 const char *main_window_file, 179 GNUNET_SCHEDULER_TaskCallback main_task); 180 181 182 /** 183 * Get an object from the main window. 184 * 185 * @param ml handle to the main loop 186 * @param name name of the object 187 * @return NULL on error, otherwise the object 188 */ 189 GObject * 190 ANASTASIS_GTK_main_loop_get_object (struct ANASTASIS_GTK_MainLoop *ml, 191 const char *name); 192 193 194 /** 195 * Get the builder from the main window. 196 * 197 * @param ml handle to the main loop 198 * @return NULL on error, otherwise the builder 199 */ 200 GtkBuilder * 201 ANASTASIS_GTK_main_loop_get_builder (struct ANASTASIS_GTK_MainLoop *ml); 202 203 204 /** 205 * Get remaining command line arguments. 206 * 207 * @param ml handle to the main loop 208 * @param argc set to argument count 209 * @param argv set to argument vector 210 */ 211 void 212 ANASTASIS_GTK_main_loop_get_args (struct ANASTASIS_GTK_MainLoop *ml, 213 int *argc, 214 char *const **argv); 215 216 217 /** 218 * Initialize a GtkBuilder for the main window and exit 219 * the main loop if this fails. 220 * 221 * @param pd project data to use 222 * @param ml main loop contextual data 223 * @param data additional argument to pass to #ANASTASIS_GTK_get_new_builder() 224 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 225 */ 226 int 227 ANASTASIS_GTK_main_loop_build_window ( 228 const struct GNUNET_OS_ProjectData *pd, 229 struct ANASTASIS_GTK_MainLoop *ml, 230 gpointer data); 231 232 233 /** 234 * Obtain the name of the configuration file that is being used 235 * by gnunet-gtk. 236 * 237 * @param ml handle to the main loop 238 * @return name of configuration file 239 */ 240 const char * 241 ANASTASIS_GTK_main_loop_get_gtk_configuration_file ( 242 struct ANASTASIS_GTK_MainLoop *ml); 243 244 /** 245 * Obtain the name of the configuration file that is being used 246 * by GNUnet (core). 247 * 248 * @param ml handle to the main loop 249 * @return name of configuration file 250 */ 251 const char * 252 ANASTASIS_GTK_main_loop_get_gnunet_configuration_file ( 253 struct ANASTASIS_GTK_MainLoop *ml); 254 255 256 /** 257 * Get the configuration. 258 * 259 * @param ml handle to the main loop 260 * @return handle to the configuration, never NULL 261 */ 262 const struct GNUNET_CONFIGURATION_Handle * 263 ANASTASIS_GTK_main_loop_get_gtk_configuration ( 264 struct ANASTASIS_GTK_MainLoop *ml); 265 266 267 /** 268 * Get the configuration. 269 * 270 * @param ml handle to the main loop 271 * @return handle to the configuration, never NULL 272 */ 273 const struct GNUNET_CONFIGURATION_Handle * 274 ANASTASIS_GTK_main_loop_get_gnunet_configuration (struct ANASTASIS_GTK_MainLoop *ml); 275 276 277 /** 278 * Trigger shutdown of the GUI and exit the main loop. 279 * 280 * @param ml handle to the main loop 281 */ 282 void 283 ANASTASIS_GTK_main_loop_quit (struct ANASTASIS_GTK_MainLoop *ml); 284 285 286 /** 287 * Return project data used by Anastasis-Gtk. 288 * 289 * @return project data for anastasis-gtk 290 */ 291 const struct GNUNET_OS_ProjectData * 292 ANASTASIS_GTK_project_data (void); 293 294 295 #endif