anastasis-gtk_helper.h (9207B)
1 /* 2 This file is part of anastasis-gtk. 3 Copyright (C) 2020-2021 Anastasis SARL 4 5 Anastasis is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3, or (at your 8 option) any later version. 9 10 Anastasis is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with Anastasis; see the file COPYING. If not, write to the 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19 */ 20 21 /** 22 * @file src/include/anastasis-gtk_helper.h 23 * @brief Definition of helpers. 24 * @author Christian Grothoff 25 * @author Dennis Neufeld 26 */ 27 #ifndef ANASTASIS_GTK_HELPER_H 28 #define ANASTASIS_GTK_HELPER_H 29 #include <gtk/gtk.h> 30 #include <anastasis/anastasis_service.h> 31 #include <anastasis/anastasis_redux.h> 32 #include "anastasis-gtk.h" 33 #include <gdk-pixbuf/gdk-pixbuf.h> 34 35 36 /** 37 * true if we are currently showing an error message. 38 */ 39 extern bool AG_have_error; 40 41 42 /** 43 * Columns of the continent_liststore. 44 */ 45 enum AG_ContinentsModelColumns 46 { 47 /** 48 * A gchararray. 49 */ 50 AG_CMC_CONTINENT_NAME = 0, 51 52 /** 53 * A gchararray. 54 */ 55 AG_CMC_CONTINENT_NAME_I18N = 1 56 }; 57 58 59 /** 60 * Columns of the secret_selection_liststore. 61 */ 62 enum AG_SecretSelectionModelColumns 63 { 64 /** 65 * A gchararray. 66 */ 67 AG_SSMC_PROVIDER_URL = 0, 68 69 /** 70 * A gint. 71 */ 72 AG_SSMC_POLICY_VERSION = 1, 73 74 /** 75 * A gint. 76 */ 77 AG_SSMC_ATTRIBUTE_MASK = 2, 78 79 /** 80 * A gchararray. 81 */ 82 AG_SSMC_SECRET_NAME = 3, 83 84 /** 85 * A gchararray. 86 */ 87 AG_SSMC_POLICY_DATE_STRING = 4, 88 89 /** 90 * A guint64. 91 */ 92 AG_SSMC_POLICY_DATE_NUMERIC = 5, 93 94 /** 95 * A gpointer. 96 */ 97 AG_SSMC_POLICY_PROVIDER_JSON = 6 98 }; 99 100 101 /** 102 * Columns of the currency_liststore. 103 */ 104 enum AG_CurrencyModelColumns 105 { 106 /** 107 * A gchararray. 108 */ 109 AG_CMC_CURRENCY_NAME = 0 110 }; 111 112 113 /** 114 * Columns of the challenge_status_liststore. 115 */ 116 enum AG_ChallengeStatusModelColumns 117 { 118 /** 119 * A guint. 120 */ 121 AG_CSM_CHALLENGE_OFFSET = 0, 122 123 /** 124 * A gchararray. 125 */ 126 AG_CSM_CHALLENGE_UUID = 1, 127 128 /** 129 * A gboolean 130 */ 131 AG_CSM_SOLVED = 2, 132 133 /** 134 * A gchararray. 135 */ 136 AG_CSM_STATUS = 3, 137 138 /** 139 * A GdkPixBuf. 140 */ 141 AG_CSM_PAYMENT_QR_CODE = 4, 142 143 /** 144 * A gchararray. 145 */ 146 AG_CSM_ERROR_MESSAGE = 5, 147 148 /** 149 * A gchararray. 150 */ 151 AG_CSM_PAYTO_URI = 6, 152 153 /** 154 * A gboolean. 155 */ 156 AG_CSM_PAYING = 7, 157 158 /** 159 * A gboolean. 160 */ 161 AG_CSM_HAS_ERROR = 8, 162 163 /** 164 * A gchararray. 165 */ 166 AG_CSM_COST = 9, 167 168 /** 169 * A gchararray. 170 */ 171 AG_CSM_REDIRECT_URL = 10, 172 173 /** 174 * A gboolean. 175 */ 176 AG_CSM_HAVE_REDIRECT = 11, 177 178 /** 179 * A gboolean 180 */ 181 AG_CSM_NOT_SOLVED = 12, 182 183 /** 184 * A gchararray 185 */ 186 AG_CSM_TYPE = 13, 187 188 /** 189 * A gchararray 190 */ 191 AG_CSM_INSTRUCTIONS = 14, 192 193 /** 194 * A gchararray 195 */ 196 AG_CSM_PROVIDER_URL = 15 197 198 }; 199 200 201 /** 202 * Columns of the provider_liststore. 203 */ 204 enum AG_ProviderModelColumns 205 { 206 /** 207 * A gchararray. Contains the provider's base URL. 208 */ 209 AG_PMC_PROVIDER_URL = 0, 210 211 /** 212 * A gchararray. Status of the provider in text. 213 */ 214 AG_PMC_PROVIDER_STATUS = 1, 215 216 /** 217 * A gchararray. Color to use when rendering the status. 218 */ 219 AG_PMC_PROVIDER_STATUS_COLOR = 2, 220 221 /** 222 * A gchararray. Amount as human-readable string with the provider's liability limit, 223 */ 224 AG_PMC_PROVIDER_LIABILITY_LIMIT = 3, 225 226 /** 227 * A gboolean. true if this provider is enabled. 228 */ 229 AG_PMC_PROVIDER_ENABLED = 4, 230 231 /** 232 * A gboolean. true if this provider can be enabled. 233 */ 234 AG_PMC_PROVIDER_SENSITIVE = 5, 235 236 /** 237 * A gboolean. false if this provider can be enabled. 238 */ 239 AG_PMC_PROVIDER_NOT_SENSITIVE = 6, 240 241 /** 242 * A gchararray. Contains the provider's business name, if known, 243 * otherwise the provider's base URL. 244 */ 245 AG_PMC_PROVIDER_NAME = 7, 246 247 }; 248 249 250 /** 251 * Columns of the backup_provider_liststore. 252 */ 253 enum AG_BackupProviderColumns 254 { 255 /** 256 * A gchararray. 257 */ 258 AG_BPC_PROVIDER_URL = 0, 259 260 /** 261 * A guint64 262 */ 263 AG_BPC_BACKUP_VERSION = 1, 264 265 /** 266 * A gchararray. // FIXME: #6823 267 */ 268 AG_BPC_EXPIRATION_TIME_STR = 2, 269 270 /** 271 * A gboolean. 272 */ 273 AG_BPC_SUCCESS_FLAG = 3, 274 275 /** 276 * A gchararray. 277 */ 278 AG_BPC_PROVIDER_NAME = 4 279 280 }; 281 282 /** 283 * Columns of the country_liststore. 284 */ 285 enum AG_CountryCodeModelColumns 286 { 287 /** 288 * A gchararray. 289 */ 290 AG_CCMC_COUNTRY_NAME = 0, 291 292 /** 293 * A gchararray. 294 */ 295 AG_CCMC_COUNTRY_CODE = 1 296 297 }; 298 299 /** 300 * Columns of the authentication_methods_liststore. 301 */ 302 enum AG_AuthenticationMethodsModelColumns 303 { 304 /** 305 * A gchararray. 306 */ 307 AG_AMMC_TYPE = 0, 308 309 /** 310 * A gchararray. 311 */ 312 AG_AMMC_VISUALIZATION = 1, 313 314 /** 315 * A guint. 316 */ 317 AG_AMMC_INDEX = 2 318 }; 319 320 321 /** 322 * Columns of the unpaid_qrcodes_liststore. 323 */ 324 enum AG_UnpaidQrcodesModelColumns 325 { 326 /** 327 * A GdkPixbuf. 328 */ 329 AG_UQRMC_QR_IMAGE = 0, 330 331 /** 332 * A gchararray. 333 */ 334 AG_UQRMC_URL = 1, 335 336 /** 337 * A gchararray. 338 */ 339 AG_UQRMC_PROVIDER = 2 340 }; 341 342 343 /** 344 * Columns of the policy_review_treestore. 345 */ 346 enum AG_PolicyReviewModelColumns 347 { 348 /** 349 * A gchararray. 350 */ 351 AG_PRMC_POLICY_NAME = 0, 352 353 /** 354 * A gchararray. 355 */ 356 AG_PRMC_METHOD_TYPE = 1, 357 358 /** 359 * A gchararray. 360 */ 361 AG_PRMC_COST = 2, 362 363 /** 364 * A gchararray. 365 */ 366 AG_PRMC_PROVIDER_URL = 3, 367 368 /** 369 * A gchararray. 370 */ 371 AG_PRMC_EXPIRATION_TIME_STR = 4, 372 373 /** 374 * A guint. 375 */ 376 AG_PRMC_POLICY_INDEX = 5, 377 378 /** 379 * A gboolean. True on lines representing challenges. 380 */ 381 AG_PRMC_IS_CHALLENGE = 6, 382 383 /** 384 * A guint. 385 */ 386 AG_PRMC_METHOD_INDEX = 7, 387 388 /** 389 * A gboolean. True on lines representing solved challenges. 390 */ 391 AG_PRMC_WAS_SOLVED = 8, 392 393 /** 394 * Name of the provider (if known, otherwise the provider's URL). 395 */ 396 AG_PRMC_PROVIDER_NAME = 9 397 398 }; 399 400 401 /** 402 * Columns in the progress model liststores. 403 */ 404 enum AG_ProgressModelColumns 405 { 406 /** 407 * A gchararray. 408 */ 409 AG_PRGMC_DESCRIPTION = 0, 410 411 /** 412 * A gchararray. 413 */ 414 AG_PRGMC_REGEX = 1, 415 416 /** 417 * A gchararray. 418 */ 419 AG_PRGMC_TOOLTIP = 2 420 }; 421 422 423 /** 424 * Hide widget of the given @a name of the main window 425 * 426 * @param name widget to hide 427 */ 428 void 429 AG_hide (const char *name); 430 431 432 /** 433 * Show widget of the given @a name of the main window 434 * 435 * @param name widget to show 436 */ 437 void 438 AG_show (const char *name); 439 440 441 /** 442 * Make widget of the given @a name of the main window insensitive. 443 * 444 * @param name widget to make insensitive 445 */ 446 void 447 AG_insensitive (const char *name); 448 449 450 /** 451 * Make widget of the given @a name of the main window sensitive. 452 * 453 * @param name widget to make sensitive 454 */ 455 void 456 AG_sensitive (const char *name); 457 458 459 /** 460 * Make the 'next' button sensitive (and trigger it via 'Return'). 461 */ 462 void 463 AG_enable_next (void); 464 465 466 /** 467 * Make widget of the given @a name the focus. 468 * 469 * @param name widget to focus 470 */ 471 void 472 AG_focus (const char *name); 473 474 475 /** 476 * Thaw the user interface. 477 */ 478 void 479 AG_thaw (void); 480 481 482 /** 483 * Freeze the user interface while the action completes. 484 */ 485 void 486 AG_freeze (void); 487 488 489 /** 490 * Hide all of the children of the container widget @a name in the main window. 491 * 492 * @param name name of the object 493 */ 494 void 495 AG_hide_children (const char *name); 496 497 498 /** 499 * Make all of the children of the container widget @a name in the main window 500 * insensitive. 501 * 502 * @param name name of the object 503 */ 504 void 505 AG_insensitive_children (const char *name); 506 507 508 /** 509 * Show all of the children of the container widget @a name in the main window. 510 * 511 * @param name name of the object 512 */ 513 void 514 AG_show_children (const char *name); 515 516 517 /** 518 * Get an object from the main window. 519 * 520 * @param name name of the object 521 * @return NULL on error 522 */ 523 GObject * 524 GCG_get_main_window_object (const char *name); 525 526 527 /** 528 * Checks the actual state. True, if state is correct, else false. 529 * 530 * @param state the state to check 531 * @param expected_state the expected state as string 532 * @return bool 533 */ 534 bool 535 AG_check_state (json_t *state, 536 const char *expected_state); 537 538 539 /** 540 * Hides all frames; 541 */ 542 void 543 AG_hide_all_frames (void); 544 545 546 /** 547 * Show error message. 548 * 549 * @param format format string 550 * @param ... arguments for format string 551 */ 552 void 553 AG_error (const char *format, 554 ...) 555 __attribute__ ((format (printf, 1, 2))); 556 557 558 /** 559 * Stop showing error message. 560 */ 561 void 562 AG_error_clear (void); 563 564 565 /** 566 * Setup QR code image for a widget @a w. 567 * 568 * @param w widget to use to determine screen resolution 569 * @param text text to encode 570 * @param text_size number of bytes in @a text 571 * @return NULL on failure 572 */ 573 GdkPixbuf * 574 AG_setup_qrcode (GtkWidget *w, 575 const char *text, 576 size_t text_size); 577 578 579 /** 580 * Expand base @a name of a widget based on the @a type to 581 * create the name of the widget with the data. 582 * 583 * @param name base name of the widget 584 * @param type type of the widget 585 * @return NULL on error 586 */ 587 char * 588 AG_expand_name (const char *name, 589 const char *type); 590 591 592 #endif