anastasis-gtk

Demonstrator GUI for Anastasis
Log | Files | Refs | README | LICENSE

anastasis-gtk_helper.h (9242B)


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