aboutsummaryrefslogtreecommitdiff
path: root/src/anastasis/anastasis-gtk_helper.h
blob: 48972a2f27f26794f7ab4e37207fecc26bc8284d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
/*
     This file is part of anastasis-gtk.
     Copyright (C) 2020-2021 Anastasis SARL

     Anastasis is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 3, or (at your
     option) any later version.

     Anastasis is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with Anastasis; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     Boston, MA 02110-1301, USA.
*/

/**
 * @file src/include/anastasis-gtk_helper.h
 * @brief Definition of helpers.
 * @author Christian Grothoff
 * @author Dennis Neufeld
 */
#ifndef ANASTASIS_GTK_HELPER_H
#define ANASTASIS_GTK_HELPER_H
#include <gnunet-gtk/gnunet_gtk.h>
#include <gtk/gtk.h>
#include <anastasis/anastasis_service.h>
#include <anastasis/anastasis_redux.h>
#include "anastasis-gtk.h"
#include <gdk-pixbuf/gdk-pixbuf.h>


/**
 * true if we are currently showing an error message.
 */
extern bool AG_have_error;


/**
 * Columns of the continent_liststore.
 */
enum AG_ContinentsModelColumns
{
  /**
   * A gchararray.
   */
  AG_CMC_CONTINENT_NAME = 0,

  /**
   * A gchararray.
   */
  AG_CMC_CONTINENT_NAME_I18N = 1
};


/**
 * Columns of the secret_selection_liststore.
 */
enum AG_SecretSelectionModelColumns
{
  /**
   * A gchararray.
   */
  AG_SSMC_PROVIDER_URL = 0,

  /**
   * A gint.
   */
  AG_SSMC_POLICY_VERSION = 1,

  /**
   * A gint.
   */
  AG_SSMC_ATTRIBUTE_MASK = 2,

  /**
   * A gchararray.
   */
  AG_SSMC_SECRET_NAME = 3,

  /**
   * A gchararray.
   */
  AG_SSMC_POLICY_DATE_STRING = 4,

  /**
   * A guint64.
   */
  AG_SSMC_POLICY_DATE_NUMERIC = 5,

  /**
   * A gpointer.
   */
  AG_SSMC_POLICY_PROVIDER_JSON = 6
};


/**
 * Columns of the currency_liststore.
 */
enum AG_CurrencyModelColumns
{
  /**
   * A gchararray.
   */
  AG_CMC_CURRENCY_NAME = 0
};


/**
 * Columns of the challenge_status_liststore.
 */
enum AG_ChallengeStatusModelColumns
{
  /**
   * A guint.
   */
  AG_CSM_CHALLENGE_OFFSET = 0,

  /**
   * A gchararray.
   */
  AG_CSM_CHALLENGE_UUID = 1,

  /**
   * A gboolean
   */
  AG_CSM_SOLVED = 2,

  /**
   * A gchararray.
   */
  AG_CSM_STATUS = 3,

  /**
   * A GdkPixBuf.
   */
  AG_CSM_PAYMENT_QR_CODE = 4,

  /**
   * A gchararray.
   */
  AG_CSM_ERROR_MESSAGE = 5,

  /**
    * A gchararray.
    */
  AG_CSM_PAYTO_URI = 6,

  /**
   * A gboolean.
   */
  AG_CSM_PAYING = 7,

  /**
   * A gboolean.
   */
  AG_CSM_HAS_ERROR = 8,

  /**
   * A gchararray.
   */
  AG_CSM_COST = 9,

  /**
   * A gchararray.
   */
  AG_CSM_REDIRECT_URL = 10,

  /**
   * A gboolean.
   */
  AG_CSM_HAVE_REDIRECT = 11,

  /**
   * A gboolean
   */
  AG_CSM_NOT_SOLVED = 12,

  /**
   * A gchararray
   */
  AG_CSM_TYPE = 13,

  /**
   * A gchararray
   */
  AG_CSM_INSTRUCTIONS = 14,

  /**
   * A gchararray
   */
  AG_CSM_PROVIDER_URL = 15

};


/**
 * Columns of the provider_liststore.
 */
enum AG_ProviderModelColumns
{
  /**
   * A gchararray. Contains the provider's base URL.
   */
  AG_PMC_PROVIDER_URL = 0,

  /**
   * A gchararray. Status of the provider in text.
   */
  AG_PMC_PROVIDER_STATUS = 1,

  /**
   * A gchararray. Color to use when rendering the status.
   */
  AG_PMC_PROVIDER_STATUS_COLOR = 2,

  /**
   * A gchararray. Amount as human-readable string with the provider's liability limit,
   */
  AG_PMC_PROVIDER_LIABILITY_LIMIT = 3,

  /**
   * A gboolean. true if this provider is enabled.
   */
  AG_PMC_PROVIDER_ENABLED = 4,

  /**
   * A gboolean. true if this provider can be enabled.
   */
  AG_PMC_PROVIDER_SENSITIVE = 5,

  /**
   * A gboolean. false if this provider can be enabled.
   */
  AG_PMC_PROVIDER_NOT_SENSITIVE = 6,

  /**
   * A gchararray. Contains the provider's business name, if known,
   * otherwise the provider's base URL.
   */
  AG_PMC_PROVIDER_NAME = 7,

};


/**
 * Columns of the backup_provider_liststore.
 */
enum AG_BackupProviderColumns
{
  /**
   * A gchararray.
   */
  AG_BPC_PROVIDER_URL = 0,

  /**
   * A guint64
   */
  AG_BPC_BACKUP_VERSION = 1,

  /**
   * A gchararray. // FIXME: #6823
   */
  AG_BPC_EXPIRATION_TIME_STR = 2,

  /**
   * A gboolean.
   */
  AG_BPC_SUCCESS_FLAG = 3,

  /**
   * A gchararray.
   */
  AG_BPC_PROVIDER_NAME = 4

};

/**
 * Columns of the country_liststore.
 */
enum AG_CountryCodeModelColumns
{
  /**
   * A gchararray.
   */
  AG_CCMC_COUNTRY_NAME = 0,

  /**
   * A gchararray.
   */
  AG_CCMC_COUNTRY_CODE = 1

};

/**
 * Columns of the authentication_methods_liststore.
 */
enum AG_AuthenticationMethodsModelColumns
{
  /**
   * A gchararray.
   */
  AG_AMMC_TYPE = 0,

  /**
   * A gchararray.
   */
  AG_AMMC_VISUALIZATION = 1,

  /**
   * A guint.
   */
  AG_AMMC_INDEX = 2
};


/**
 * Columns of the unpaid_qrcodes_liststore.
 */
enum AG_UnpaidQrcodesModelColumns
{
  /**
   * A GdkPixbuf.
   */
  AG_UQRMC_QR_IMAGE = 0,

  /**
   * A gchararray.
   */
  AG_UQRMC_URL = 1,

  /**
   * A gchararray.
   */
  AG_UQRMC_PROVIDER = 2
};


/**
 * Columns of the policy_review_treestore.
 */
enum AG_PolicyReviewModelColumns
{
  /**
   * A gchararray.
   */
  AG_PRMC_POLICY_NAME = 0,

  /**
   * A gchararray.
   */
  AG_PRMC_METHOD_TYPE = 1,

  /**
   * A gchararray.
   */
  AG_PRMC_COST = 2,

  /**
   * A gchararray.
   */
  AG_PRMC_PROVIDER_URL = 3,

  /**
   * A gchararray.
   */
  AG_PRMC_EXPIRATION_TIME_STR = 4,

  /**
   * A guint.
   */
  AG_PRMC_POLICY_INDEX = 5,

  /**
   * A gboolean. True on lines representing challenges.
   */
  AG_PRMC_IS_CHALLENGE = 6,

  /**
   * A guint.
   */
  AG_PRMC_METHOD_INDEX = 7,

  /**
   * A gboolean. True on lines representing solved challenges.
   */
  AG_PRMC_WAS_SOLVED = 8,

  /**
   * Name of the provider (if known, otherwise the provider's URL).
   */
  AG_PRMC_PROVIDER_NAME = 9

};


/**
 * Columns in the progress model liststores.
 */
enum AG_ProgressModelColumns
{
  /**
   * A gchararray.
   */
  AG_PRGMC_DESCRIPTION = 0,

  /**
   * A gchararray.
   */
  AG_PRGMC_REGEX = 1,

  /**
   * A gchararray.
   */
  AG_PRGMC_TOOLTIP = 2
};


/**
 * Hide widget of the given @a name of the main window
 *
 * @param name widget to hide
 */
void
AG_hide (const char *name);


/**
 * Show widget of the given @a name of the main window
 *
 * @param name widget to show
 */
void
AG_show (const char *name);


/**
 * Make widget of the given @a name of the main window insensitive.
 *
 * @param name widget to make insensitive
 */
void
AG_insensitive (const char *name);


/**
 * Make widget of the given @a name of the main window sensitive.
 *
 * @param name widget to make sensitive
 */
void
AG_sensitive (const char *name);


/**
 * Make the 'next' button sensitive (and trigger it via 'Return').
 */
void
AG_enable_next (void);


/**
 * Make widget of the given @a name the focus.
 *
 * @param name widget to focus
 */
void
AG_focus (const char *name);


/**
 * Thaw the user interface.
 */
void
AG_thaw (void);


/**
 * Freeze the user interface while the action completes.
 */
void
AG_freeze (void);


/**
 * Hide all of the children of the container widget @a name in the main window.
 *
 * @param name name of the object
 */
void
AG_hide_children (const char *name);


/**
 * Make all of the children of the container widget @a name in the main window
 * insensitive.
 *
 * @param name name of the object
 */
void
AG_insensitive_children (const char *name);


/**
 * Show all of the children of the container widget @a name in the main window.
 *
 * @param name name of the object
 */
void
AG_show_children (const char *name);


/**
 * Get an object from the main window.
 *
 * @param name name of the object
 * @return NULL on error
 */
GObject *
GCG_get_main_window_object (const char *name);


/**
 * Checks the actual state. True, if state is correct, else false.
 *
 * @param state the state to check
 * @param expected_state the expected state as string
 * @return bool
 */
bool
AG_check_state (json_t *state,
                const char *expected_state);


/**
 * Hides all frames;
 */
void
AG_hide_all_frames (void);


/**
 * Show error message.
 *
 * @param format format string
 * @param ... arguments for format string
 */
void
AG_error (const char *format,
          ...)
__attribute__ ((format (printf, 1, 2)));


/**
 * Stop showing error message.
 */
void
AG_error_clear (void);


/**
 * Setup QR code image for a widget @a w.
 *
 * @param w widget to use to determine screen resolution
 * @param text text to encode
 * @param text_size number of bytes in @a text
 * @return NULL on failure
 */
GdkPixbuf *
AG_setup_qrcode (GtkWidget *w,
                 const char *text,
                 size_t text_size);


/**
 * Expand base @a name of a widget based on the @a type to
 * create the name of the widget with the data.
 *
 * @param name base name of the widget
 * @param type type of the widget
 * @return NULL on error
 */
char *
AG_expand_name (const char *name,
                const char *type);


#endif