34 #include <glib/gi18n.h>
35 #include <gwenhywfar/gui_be.h>
36 #include <gwenhywfar/inherit.h>
38 #include "dialog-utils.h"
40 #include "gnc-component-manager.h"
42 #include "gnc-session.h"
48 #if GWENHYWFAR_VERSION_INT >= 39921
51 # define USING_GWENHYWFAR_GTK2_GUI
52 # define GNC_GWENHYWFAR_CB GWENHYWFAR_CB
54 # define GNC_GWENHYWFAR_CB
57 #define GWEN_GUI_CM_CLASS "dialog-hbcilog"
58 #define GNC_PREFS_GROUP_CONNECTION GNC_PREFS_GROUP_AQBANKING ".connection-dialog"
59 #define GNC_PREF_CLOSE_ON_FINISH "close-on-finish"
60 #define GNC_PREF_REMEMBER_PIN "remember-pin"
62 #ifdef USING_GWENHYWFAR_GTK2_GUI
63 # include <gwen-gui-gtk2/gtk2_gui.h>
74 static GWEN_GUI *gwen_gui = NULL;
80 gwen_gui = Gtk2_Gui_new();
81 GWEN_Gui_SetGui(gwen_gui);
88 return (GncGWENGui*) gwen_gui;
97 GWEN_Gui_free(gwen_gui);
99 GWEN_Gui_SetGui(NULL);
106 GNC_PREFS_GROUP_AQBANKING, GNC_PREF_CLOSE_ON_FINISH,
107 close_when_finished);
129 static GncGWENGui *full_gui = NULL;
133 static GWEN_GUI *log_gwen_gui = NULL;
136 static GLogLevelFlags log_levels[] =
140 G_LOG_LEVEL_CRITICAL,
141 G_LOG_LEVEL_CRITICAL,
148 static guint8 n_log_levels = G_N_ELEMENTS(log_levels);
151 GWEN_INHERIT(GWEN_GUI, GncGWENGui)
152 #define SETDATA_GUI(gwen_gui, gui) GWEN_INHERIT_SETDATA(GWEN_GUI, GncGWENGui, \
153 (gwen_gui), (gui), NULL)
154 #define GETDATA_GUI(gwen_gui) GWEN_INHERIT_GETDATA(GWEN_GUI, GncGWENGui, (gwen_gui))
156 #define OTHER_ENTRIES_ROW_OFFSET 3
159 typedef enum _GuiState GuiState;
161 static void register_callbacks(GncGWENGui *gui);
162 static void unregister_callbacks(GncGWENGui *gui);
163 static void setup_dialog(GncGWENGui *gui);
164 static void enable_password_cache(GncGWENGui *gui, gboolean enabled);
165 static void reset_dialog(GncGWENGui *gui);
166 static void set_finished(GncGWENGui *gui);
167 static void set_aborted(GncGWENGui *gui);
168 static void show_dialog(GncGWENGui *gui, gboolean clear_log);
169 static void hide_dialog(GncGWENGui *gui);
170 static gboolean show_progress_cb(gpointer user_data);
171 static void show_progress(GncGWENGui *gui,
Progress *progress);
172 static void hide_progress(GncGWENGui *gui,
Progress *progress);
173 static void free_progress(
Progress *progress, gpointer unused);
174 static gboolean keep_alive(GncGWENGui *gui);
175 static void cm_close_handler(gpointer user_data);
176 static void erase_password(gchar *password);
177 static gchar *strip_html(gchar *text);
178 static void get_input(GncGWENGui *gui, guint32 flags,
const gchar *title,
179 const gchar *text, gchar **input, gint min_len,
181 static gint messagebox_cb(GWEN_GUI *gwen_gui, guint32 flags,
const gchar *title,
182 const gchar *text,
const gchar *b1,
const gchar *b2,
183 const gchar *b3, guint32 guiid);
184 static gint inputbox_cb(GWEN_GUI *gwen_gui, guint32 flags,
const gchar *title,
185 const gchar *text, gchar *buffer, gint min_len,
186 gint max_len, guint32 guiid);
187 static guint32 showbox_cb(GWEN_GUI *gwen_gui, guint32 flags,
const gchar *title,
188 const gchar *text, guint32 guiid);
189 static void hidebox_cb(GWEN_GUI *gwen_gui, guint32
id);
190 static guint32 progress_start_cb(GWEN_GUI *gwen_gui, uint32_t progressFlags,
191 const char *title,
const char *text,
192 uint64_t total, uint32_t guiid);
193 static gint progress_advance_cb(GWEN_GUI *gwen_gui, uint32_t
id,
194 uint64_t new_progress);
195 static gint progress_log_cb(GWEN_GUI *gwen_gui, guint32
id,
196 GWEN_LOGGER_LEVEL level,
const gchar *text);
197 static gint progress_end_cb(GWEN_GUI *gwen_gui, guint32
id);
198 static gint GNC_GWENHYWFAR_CB getpassword_cb(GWEN_GUI *gwen_gui, guint32 flags,
const gchar *token,
199 const gchar *title,
const gchar *text, gchar *buffer,
200 gint min_len, gint max_len, guint32 guiid);
201 static gint GNC_GWENHYWFAR_CB setpasswordstatus_cb(GWEN_GUI *gwen_gui,
const gchar *token,
203 GWEN_GUI_PASSWORD_STATUS status, guint32 guiid);
204 static gint GNC_GWENHYWFAR_CB loghook_cb(GWEN_GUI *gwen_gui,
const gchar *log_domain,
205 GWEN_LOGGER_LEVEL priority,
const gchar *text);
206 #ifdef AQBANKING_VERSION_5_PLUS
207 typedef GWEN_SYNCIO GWEN_IO_LAYER;
209 static gint GNC_GWENHYWFAR_CB checkcert_cb(GWEN_GUI *gwen_gui,
const GWEN_SSLCERTDESCR *cert,
210 GWEN_IO_LAYER *io, guint32 guiid);
212 gboolean ggg_delete_event_cb(GtkWidget *widget, GdkEvent *event,
214 void ggg_abort_clicked_cb(GtkButton *button, gpointer user_data);
215 void ggg_close_clicked_cb(GtkButton *button, gpointer user_data);
216 void ggg_close_toggled_cb(GtkToggleButton *button, gpointer user_data);
234 GtkWidget *entries_table;
235 GtkWidget *top_entry;
236 GtkWidget *top_progress;
237 GtkWidget *second_entry;
238 GtkWidget *other_entries_box;
245 guint64 current_action;
251 GtkWidget *abort_button;
252 GtkWidget *close_button;
253 GtkWidget *close_checkbutton;
260 gboolean cache_passwords;
261 GHashTable *passwords;
264 GHashTable *accepted_certs;
265 GWEN_DB_NODE *permanently_accepted_certs;
266 GWEN_GUI_CHECKCERT_FN builtin_checkcert;
270 GHashTable *showbox_hash;
271 GtkWidget *showbox_last;
274 GWEN_LOGGER_LEVEL min_loglevel;
294 #ifdef USING_GWENHYWFAR_GTK2_GUI
302 GWEN_Gui_SetLogHookFn(log_gwen_gui, loghook_cb);
305 GWEN_Gui_Attach(log_gwen_gui);
307 GWEN_Gui_SetGui(log_gwen_gui);
315 ENTER(
"parent=%p", parent);
319 if (full_gui->state == INIT || full_gui->state == RUNNING)
321 LEAVE(
"full_gui in use, state=%d", full_gui->state);
326 gui->parent = parent;
328 register_callbacks(gui);
330 LEAVE(
"gui=%p", gui);
334 gui = g_new0(GncGWENGui, 1);
335 gui->parent = parent;
337 register_callbacks(gui);
341 LEAVE(
"new gui=%p", gui);
348 g_return_if_fail(gui && gui == full_gui);
351 ENTER(
"gui=%p", gui);
358 GncGWENGui *gui = full_gui;
364 GWEN_Gui_free(log_gwen_gui);
367 GWEN_Gui_SetGui(NULL);
375 g_hash_table_destroy(gui->passwords);
376 if (gui->showbox_hash)
377 g_hash_table_destroy(gui->showbox_hash);
378 if (gui->permanently_accepted_certs)
379 GWEN_DB_Group_free(gui->permanently_accepted_certs);
380 if (gui->accepted_certs)
381 g_hash_table_destroy(gui->accepted_certs);
382 gtk_widget_destroy(gui->dialog);
394 GNC_PREFS_GROUP_AQBANKING, GNC_PREF_CLOSE_ON_FINISH,
395 close_when_finished);
399 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(full_gui->close_checkbutton))
400 != close_when_finished)
402 gtk_toggle_button_set_active(
403 GTK_TOGGLE_BUTTON(full_gui->close_checkbutton),
404 close_when_finished);
418 GncGWENGui *gui = full_gui;
427 if (gui->state == HIDDEN)
429 gui->state = FINISHED;
431 gtk_toggle_button_set_active(
432 GTK_TOGGLE_BUTTON(gui->close_checkbutton),
435 show_dialog(gui, FALSE);
446 GncGWENGui *gui = full_gui;
455 register_callbacks(GncGWENGui *gui)
459 g_return_if_fail(gui && !gui->gwen_gui);
461 ENTER(
"gui=%p", gui);
464 #ifdef USING_GWENHYWFAR_GTK2_GUI
470 gui->gwen_gui = gwen_gui;
472 GWEN_Gui_SetMessageBoxFn(gwen_gui, messagebox_cb);
473 GWEN_Gui_SetInputBoxFn(gwen_gui, inputbox_cb);
474 GWEN_Gui_SetShowBoxFn(gwen_gui, showbox_cb);
475 GWEN_Gui_SetHideBoxFn(gwen_gui, hidebox_cb);
476 GWEN_Gui_SetProgressStartFn(gwen_gui, progress_start_cb);
477 GWEN_Gui_SetProgressAdvanceFn(gwen_gui, progress_advance_cb);
478 GWEN_Gui_SetProgressLogFn(gwen_gui, progress_log_cb);
479 GWEN_Gui_SetProgressEndFn(gwen_gui, progress_end_cb);
480 GWEN_Gui_SetGetPasswordFn(gwen_gui, getpassword_cb);
481 GWEN_Gui_SetSetPasswordStatusFn(gwen_gui, setpasswordstatus_cb);
482 GWEN_Gui_SetLogHookFn(gwen_gui, loghook_cb);
483 gui->builtin_checkcert = GWEN_Gui_SetCheckCertFn(gwen_gui, checkcert_cb);
485 GWEN_Gui_SetGui(gwen_gui);
486 SETDATA_GUI(gwen_gui, gui);
492 unregister_callbacks(GncGWENGui *gui)
494 g_return_if_fail(gui);
496 ENTER(
"gui=%p", gui);
500 LEAVE(
"already unregistered");
507 gui->gwen_gui = NULL;
513 setup_dialog(GncGWENGui *gui)
518 g_return_if_fail(gui);
520 ENTER(
"gui=%p", gui);
522 builder = gtk_builder_new();
523 gnc_builder_add_from_file (builder,
"dialog-ab.glade",
"Connection Dialog");
525 gui->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"Connection Dialog"));
527 gui->entries_table = GTK_WIDGET(gtk_builder_get_object (builder,
"entries_table"));
528 gui->top_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"top_entry"));
529 gui->top_progress = GTK_WIDGET(gtk_builder_get_object (builder,
"top_progress"));
530 gui->second_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"second_entry"));
531 gui->other_entries_box = NULL;
532 gui->progresses = NULL;
533 gui->log_text = GTK_WIDGET(gtk_builder_get_object (builder,
"log_text"));
534 gui->abort_button = GTK_WIDGET(gtk_builder_get_object (builder,
"abort_button"));
535 gui->close_button = GTK_WIDGET(gtk_builder_get_object (builder,
"close_button"));
536 gui->close_checkbutton = GTK_WIDGET(gtk_builder_get_object (builder,
"close_checkbutton"));
537 gui->accepted_certs = NULL;
538 gui->permanently_accepted_certs = NULL;
539 gui->showbox_hash = NULL;
543 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, gui);
545 gtk_toggle_button_set_active(
546 GTK_TOGGLE_BUTTON(gui->close_checkbutton),
549 component_id = gnc_register_gui_component(GWEN_GUI_CM_CLASS, NULL,
550 cm_close_handler, gui);
551 gnc_gui_component_set_session(component_id, gnc_get_current_session());
555 g_object_unref(G_OBJECT(builder));
563 enable_password_cache(GncGWENGui *gui, gboolean enabled)
565 g_return_if_fail(gui);
567 if (enabled && !gui->passwords)
570 gui->passwords = g_hash_table_new_full(
571 g_str_hash, g_str_equal, (GDestroyNotify) g_free,
572 (GDestroyNotify) erase_password);
574 else if (!enabled && gui->passwords)
577 g_hash_table_destroy(gui->passwords);
578 gui->passwords = NULL;
580 gui->cache_passwords = enabled;
584 reset_dialog(GncGWENGui *gui)
586 gboolean cache_passwords;
588 g_return_if_fail(gui);
590 ENTER(
"gui=%p", gui);
592 gtk_entry_set_text(GTK_ENTRY(gui->top_entry),
"");
593 gtk_entry_set_text(GTK_ENTRY(gui->second_entry),
"");
594 g_list_foreach(gui->progresses, (GFunc) free_progress, NULL);
595 g_list_free(gui->progresses);
596 gui->progresses = NULL;
598 if (gui->other_entries_box)
600 gtk_table_resize(GTK_TABLE(gui->entries_table),
601 OTHER_ENTRIES_ROW_OFFSET, 2);
602 gtk_widget_destroy(gui->other_entries_box);
603 gui->other_entries_box = NULL;
605 if (gui->showbox_hash)
606 g_hash_table_destroy(gui->showbox_hash);
607 gui->showbox_last = NULL;
608 gui->showbox_hash = g_hash_table_new_full(
609 NULL, NULL, NULL, (GDestroyNotify) gtk_widget_destroy);
612 gtk_window_set_transient_for(GTK_WINDOW(gui->dialog),
613 GTK_WINDOW(gui->parent));
614 gnc_restore_window_size(GNC_PREFS_GROUP_CONNECTION, GTK_WINDOW(gui->dialog));
616 gui->keep_alive = TRUE;
618 gui->min_loglevel = GWEN_LoggerLevel_Verbous;
621 GNC_PREF_REMEMBER_PIN);
622 enable_password_cache(gui, cache_passwords);
624 if (!gui->accepted_certs)
625 gui->accepted_certs = g_hash_table_new_full(
626 g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL);
627 if (!gui->permanently_accepted_certs)
634 set_running(GncGWENGui *gui)
636 g_return_if_fail(gui);
638 ENTER(
"gui=%p", gui);
640 gui->state = RUNNING;
641 gtk_widget_set_sensitive(gui->abort_button, TRUE);
642 gtk_widget_set_sensitive(gui->close_button, FALSE);
643 gui->keep_alive = TRUE;
649 set_finished(GncGWENGui *gui)
651 g_return_if_fail(gui);
653 ENTER(
"gui=%p", gui);
656 gui->state = FINISHED;
657 unregister_callbacks(gui);
659 gtk_widget_set_sensitive(gui->abort_button, FALSE);
660 gtk_widget_set_sensitive(gui->close_button, TRUE);
661 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui->close_checkbutton)))
668 set_aborted(GncGWENGui *gui)
670 g_return_if_fail(gui);
672 ENTER(
"gui=%p", gui);
675 gui->state = ABORTED;
676 unregister_callbacks(gui);
678 gtk_widget_set_sensitive(gui->abort_button, FALSE);
679 gtk_widget_set_sensitive(gui->close_button, TRUE);
680 gui->keep_alive = FALSE;
686 show_dialog(GncGWENGui *gui, gboolean clear_log)
688 g_return_if_fail(gui);
690 ENTER(
"gui=%p, clear_log=%d", gui, clear_log);
692 gtk_widget_show(gui->dialog);
699 gtk_text_buffer_set_text(
700 gtk_text_view_get_buffer(GTK_TEXT_VIEW(gui->log_text)),
"", 0);
707 hide_dialog(GncGWENGui *gui)
709 g_return_if_fail(gui);
711 ENTER(
"gui=%p", gui);
714 gtk_widget_hide(gui->dialog);
720 GNC_PREFS_GROUP_AQBANKING, GNC_PREF_CLOSE_ON_FINISH,
721 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui->close_checkbutton)));
724 gnc_save_window_size(GNC_PREFS_GROUP_CONNECTION, GTK_WINDOW(gui->dialog));
728 unregister_callbacks(gui);
734 show_progress_cb(gpointer user_data)
738 g_return_val_if_fail(progress, FALSE);
740 ENTER(
"progress=%p", progress);
742 show_progress(progress->gui, progress);
752 show_progress(GncGWENGui *gui,
Progress *progress)
757 g_return_if_fail(gui);
759 ENTER(
"gui=%p, progress=%p", gui, progress);
761 for (item = g_list_last(gui->progresses); item; item = item->prev)
766 && current != progress)
774 show_dialog(gui, TRUE);
775 gtk_entry_set_text(GTK_ENTRY(gui->top_entry), current->title);
777 else if (!item->next->next)
780 gtk_entry_set_text(GTK_ENTRY(gui->second_entry), current->title);
785 GtkWidget *entry = gtk_entry_new();
786 GtkWidget *box = gui->other_entries_box;
787 gboolean new_box = box == NULL;
789 gtk_entry_set_text(GTK_ENTRY(entry), current->title);
791 gui->other_entries_box = box = gtk_vbox_new(TRUE, 6);
792 gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 0);
793 gtk_widget_show(entry);
796 gtk_table_resize(GTK_TABLE(gui->entries_table),
797 OTHER_ENTRIES_ROW_OFFSET + 1, 2);
798 gtk_table_attach_defaults(
799 GTK_TABLE(gui->entries_table), box, 1, 2,
800 OTHER_ENTRIES_ROW_OFFSET, OTHER_ENTRIES_ROW_OFFSET + 1);
801 gtk_widget_show(box);
808 g_source_remove(current->source);
812 if (current == progress)
823 hide_progress(GncGWENGui *gui,
Progress *progress)
828 g_return_if_fail(gui);
830 ENTER(
"gui=%p, progress=%p", gui, progress);
832 for (item = gui->progresses; item; item = item->next)
839 g_source_remove(current->source);
841 if (current == progress)
851 gtk_entry_set_text(GTK_ENTRY(gui->second_entry),
"");
853 else if (!item->next->next)
856 gtk_entry_set_text(GTK_ENTRY(gui->second_entry),
"");
861 GtkWidget *box = gui->other_entries_box;
864 g_return_if_fail(box);
865 entries = gtk_container_get_children(GTK_CONTAINER(box));
866 g_return_if_fail(entries);
870 gtk_widget_destroy(GTK_WIDGET(g_list_last(entries)->data));
875 gtk_table_resize(GTK_TABLE(gui->entries_table),
876 OTHER_ENTRIES_ROW_OFFSET, 2);
877 gtk_widget_destroy(box);
878 gui->other_entries_box = NULL;
880 g_list_free(entries);
883 if (current == progress)
891 free_progress(
Progress *progress, gpointer unused)
893 if (progress->source)
894 g_source_remove(progress->source);
895 g_free(progress->title);
900 keep_alive(GncGWENGui *gui)
902 g_return_val_if_fail(gui, FALSE);
904 ENTER(
"gui=%p", gui);
907 while (g_main_context_iteration(NULL, FALSE));
909 LEAVE(
"alive=%d", gui->keep_alive);
910 return gui->keep_alive;
914 cm_close_handler(gpointer user_data)
916 GncGWENGui *gui = user_data;
918 g_return_if_fail(gui);
920 ENTER(
"gui=%p", gui);
929 erase_password(gchar *password)
931 g_return_if_fail(password);
935 memset(password, 0, strlen(password));
945 strip_html(gchar *text)
953 while (strchr(p,
'<'))
956 if (*q && toupper(*q++) ==
'H'
957 && *q && toupper(*q++) ==
'T'
958 && *q && toupper(*q++) ==
'M'
959 && *q && toupper(*q) ==
'L')
970 get_input(GncGWENGui *gui, guint32 flags,
const gchar *title,
const gchar *text,
971 gchar **input, gint min_len, gint max_len)
975 GtkWidget *heading_label;
976 GtkWidget *input_entry;
977 GtkWidget *confirm_entry;
978 GtkWidget *confirm_label;
979 GtkWidget *remember_pin_checkbutton;
980 const gchar *internal_input, *internal_confirmed;
981 gboolean confirm = (flags & GWEN_GUI_INPUT_FLAGS_CONFIRM) != 0;
982 gboolean is_tan = (flags & GWEN_GUI_INPUT_FLAGS_TAN) != 0;
984 g_return_if_fail(input);
985 g_return_if_fail(max_len >= min_len && max_len > 0);
990 builder = gtk_builder_new();
991 gnc_builder_add_from_file (builder,
"dialog-ab.glade",
"Password Dialog");
992 dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"Password Dialog"));
994 heading_label = GTK_WIDGET(gtk_builder_get_object (builder,
"heading_pw_label"));
995 input_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"input_entry"));
996 confirm_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"confirm_entry"));
997 confirm_label = GTK_WIDGET(gtk_builder_get_object (builder,
"confirm_label"));
998 remember_pin_checkbutton = GTK_WIDGET(gtk_builder_get_object (builder,
"remember_pin"));
1001 gtk_widget_hide(remember_pin_checkbutton);
1005 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(remember_pin_checkbutton),
1006 gui->cache_passwords);
1010 gtk_window_set_transient_for(GTK_WINDOW(dialog),
1011 GTK_WINDOW(gui->parent));
1013 gtk_window_set_title(GTK_WINDOW(dialog), title);
1017 gchar *raw_text = strip_html(g_strdup(text));
1018 gtk_label_set_text(GTK_LABEL(heading_label), raw_text);
1024 gtk_entry_set_text(GTK_ENTRY(input_entry), *input);
1025 erase_password(*input);
1031 gtk_entry_set_activates_default(GTK_ENTRY(input_entry), FALSE);
1032 gtk_entry_set_activates_default(GTK_ENTRY(confirm_entry), TRUE);
1033 gtk_entry_set_max_length(GTK_ENTRY(input_entry), max_len);
1034 gtk_entry_set_max_length(GTK_ENTRY(confirm_entry), max_len);
1038 gtk_entry_set_activates_default(GTK_ENTRY(input_entry), TRUE);
1039 gtk_entry_set_max_length(GTK_ENTRY(input_entry), max_len);
1040 gtk_widget_hide(confirm_entry);
1041 gtk_widget_hide(confirm_label);
1043 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
1048 gboolean remember_pin;
1050 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK)
1056 remember_pin = gtk_toggle_button_get_active(
1057 GTK_TOGGLE_BUTTON(remember_pin_checkbutton));
1058 enable_password_cache(gui, remember_pin);
1063 internal_input = gtk_entry_get_text(GTK_ENTRY(input_entry));
1064 if (strlen(internal_input) < min_len)
1067 gchar *msg = g_strdup_printf(
1068 _(
"The PIN needs to be at least %d characters \n"
1069 "long. Do you want to try again?"), min_len);
1070 retval = gnc_verify_dialog(gui->parent, TRUE,
"%s", msg);
1079 *input = g_strdup(internal_input);
1083 internal_confirmed = gtk_entry_get_text(GTK_ENTRY(confirm_entry));
1084 if (strcmp(internal_input, internal_confirmed) == 0)
1086 *input = g_strdup(internal_input);
1091 g_object_unref(G_OBJECT(builder));
1094 gtk_widget_destroy(dialog);
1096 LEAVE(
"input %s", *input ?
"non-NULL" :
"NULL");
1100 messagebox_cb(GWEN_GUI *gwen_gui, guint32 flags,
const gchar *title,
1101 const gchar *text,
const gchar *b1,
const gchar *b2,
1102 const gchar *b3, guint32 guiid)
1104 GncGWENGui *gui = GETDATA_GUI(gwen_gui);
1111 ENTER(
"gui=%p, flags=%d, title=%s, b1=%s, b2=%s, b3=%s", gui, flags,
1112 title ? title :
"(null)", b1 ? b1 :
"(null)", b2 ? b2 :
"(null)",
1113 b3 ? b3 :
"(null)");
1115 dialog = gtk_dialog_new_with_buttons(
1116 title, gui->parent ? GTK_WINDOW(gui->parent) : NULL,
1117 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1118 b1, 1, b2, 2, b3, 3, (gchar*) NULL);
1120 raw_text = strip_html(g_strdup(text));
1121 label = gtk_label_new(raw_text);
1123 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
1124 vbox = gtk_vbox_new(TRUE, 0);
1125 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
1126 gtk_container_add(GTK_CONTAINER(vbox), label);
1127 gtk_container_set_border_width(GTK_CONTAINER(dialog), 5);
1128 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), vbox);
1129 gtk_widget_show_all(dialog);
1131 result = gtk_dialog_run(GTK_DIALOG(dialog));
1132 gtk_widget_destroy(dialog);
1134 if (result < 1 || result > 3)
1136 g_warning(
"messagebox_cb: Bad result %d", result);
1140 LEAVE(
"result=%d", result);
1145 inputbox_cb(GWEN_GUI *gwen_gui, guint32 flags,
const gchar *title,
1146 const gchar *text, gchar *buffer, gint min_len, gint max_len,
1149 GncGWENGui *gui = GETDATA_GUI(gwen_gui);
1150 gchar *input = NULL;
1152 g_return_val_if_fail(gui, -1);
1154 ENTER(
"gui=%p, flags=%d", gui, flags);
1156 get_input(gui, flags, title, text, &input, min_len, max_len);
1161 strncpy(buffer, input, max_len);
1162 buffer[max_len-1] =
'\0';
1166 return input ? 0 : -1;
1170 showbox_cb(GWEN_GUI *gwen_gui, guint32 flags,
const gchar *title,
1171 const gchar *text, guint32 guiid)
1173 GncGWENGui *gui = GETDATA_GUI(gwen_gui);
1177 g_return_val_if_fail(gui, -1);
1179 ENTER(
"gui=%p, flags=%d, title=%s", gui, flags, title ? title :
"(null)");
1181 dialog = gtk_message_dialog_new(
1182 gui->parent ? GTK_WINDOW(gui->parent) : NULL, 0, GTK_MESSAGE_INFO,
1183 GTK_BUTTONS_OK,
"%s", text);
1186 gtk_window_set_title(GTK_WINDOW(dialog), title);
1188 g_signal_connect(dialog,
"response", G_CALLBACK(gtk_widget_hide), NULL);
1189 gtk_widget_show_all(dialog);
1191 showbox_id = gui->showbox_id++;
1192 g_hash_table_insert(gui->showbox_hash, GUINT_TO_POINTER(showbox_id),
1194 gui->showbox_last = dialog;
1197 if (!keep_alive(gui))
1200 LEAVE(
"id=%" G_GUINT32_FORMAT, showbox_id);
1205 hidebox_cb(GWEN_GUI *gwen_gui, guint32
id)
1207 GncGWENGui *gui = GETDATA_GUI(gwen_gui);
1209 g_return_if_fail(gui && gui->showbox_hash);
1211 ENTER(
"gui=%p, id=%d", gui,
id);
1215 if (gui->showbox_last)
1217 g_hash_table_remove(gui->showbox_hash,
1218 GUINT_TO_POINTER(gui->showbox_id));
1219 gui->showbox_last = NULL;
1223 g_warning(
"hidebox_cb: Last showed message box already destroyed");
1229 p_var = g_hash_table_lookup(gui->showbox_hash, GUINT_TO_POINTER(
id));
1232 g_hash_table_remove(gui->showbox_hash, GUINT_TO_POINTER(
id));
1233 if (p_var == gui->showbox_last)
1234 gui->showbox_last = NULL;
1238 g_warning(
"hidebox_cb: Message box %d could not been found",
id);
1246 progress_start_cb(GWEN_GUI *gwen_gui, uint32_t progressFlags,
const char *title,
1247 const char *text, uint64_t total, uint32_t guiid)
1249 GncGWENGui *gui = GETDATA_GUI(gwen_gui);
1252 g_return_val_if_fail(gui, -1);
1254 ENTER(
"gui=%p, flags=%d, title=%s, total=%" G_GUINT64_FORMAT, gui,
1255 progressFlags, title ? title :
"(null)", (guint64)total);
1257 if (!gui->progresses)
1260 if (progressFlags & GWEN_GUI_PROGRESS_SHOW_PROGRESS)
1262 gtk_widget_set_sensitive(gui->top_progress, TRUE);
1263 gtk_progress_bar_set_fraction(
1264 GTK_PROGRESS_BAR(gui->top_progress), 0.0);
1265 gui->max_actions = total;
1269 gtk_widget_set_sensitive(gui->top_progress, FALSE);
1270 gui->max_actions = -1;
1277 progress->gui = gui;
1278 progress->title = title ? g_strdup(title) :
"";
1279 gui->progresses = g_list_prepend(gui->progresses, progress);
1281 if (progressFlags & GWEN_GUI_PROGRESS_DELAY)
1284 progress->source = g_timeout_add(GWEN_GUI_DELAY_SECS * 1000,
1285 (GSourceFunc) show_progress_cb,
1291 progress->source = 0;
1292 show_progress(gui, progress);
1296 return g_list_length(gui->progresses);
1300 progress_advance_cb(GWEN_GUI *gwen_gui, uint32_t
id, uint64_t progress)
1302 GncGWENGui *gui = GETDATA_GUI(gwen_gui);
1304 g_return_val_if_fail(gui, -1);
1306 ENTER(
"gui=%p, progress=%" G_GUINT64_FORMAT, gui, (guint64)progress);
1309 && gui->max_actions > 0
1310 && progress != GWEN_GUI_PROGRESS_NONE)
1312 if (progress == GWEN_GUI_PROGRESS_ONE)
1313 gui->current_action++;
1315 gui->current_action = progress;
1317 gtk_progress_bar_set_fraction(
1318 GTK_PROGRESS_BAR(gui->top_progress),
1319 ((gdouble) gui->current_action) / ((gdouble) gui->max_actions));
1323 return !keep_alive(gui);
1327 progress_log_cb(GWEN_GUI *gwen_gui, guint32
id, GWEN_LOGGER_LEVEL level,
1330 GncGWENGui *gui = GETDATA_GUI(gwen_gui);
1334 g_return_val_if_fail(gui, -1);
1336 ENTER(
"gui=%p, text=%s", gui, text ? text :
"(null)");
1338 tv = GTK_TEXT_VIEW(gui->log_text);
1339 tb = gtk_text_view_get_buffer(tv);
1340 gtk_text_buffer_insert_at_cursor(tb, text, -1);
1341 gtk_text_buffer_insert_at_cursor(tb,
"\n", -1);
1344 gtk_text_view_scroll_to_mark(tv, gtk_text_buffer_get_insert(tb),
1345 0.0, FALSE, 0.0, 0.0);
1348 if (level < gui->min_loglevel)
1349 gui->min_loglevel = level;
1352 return !keep_alive(gui);
1356 progress_end_cb(GWEN_GUI *gwen_gui, guint32
id)
1358 GncGWENGui *gui = GETDATA_GUI(gwen_gui);
1361 g_return_val_if_fail(gui, -1);
1362 g_return_val_if_fail(
id == g_list_length(gui->progresses), -1);
1364 ENTER(
"gui=%p, id=%d", gui,
id);
1366 if (gui->state != RUNNING)
1369 LEAVE(
"not running anymore");
1374 progress = (
Progress*) gui->progresses->data;
1375 hide_progress(gui, progress);
1378 gui->progresses = g_list_delete_link(gui->progresses, gui->progresses);
1379 free_progress(progress, NULL);
1381 if (!gui->progresses)
1391 static gint GNC_GWENHYWFAR_CB
1392 getpassword_cb(GWEN_GUI *gwen_gui, guint32 flags,
const gchar *token,
1393 const gchar *title,
const gchar *text, gchar *buffer,
1394 gint min_len, gint max_len, guint32 guiid)
1396 GncGWENGui *gui = GETDATA_GUI(gwen_gui);
1397 gchar *password = NULL;
1398 gboolean is_tan = (flags & GWEN_GUI_INPUT_FLAGS_TAN) != 0;
1400 g_return_val_if_fail(gui, -1);
1402 ENTER(
"gui=%p, flags=%d, token=%s", gui, flags, token ? token :
"(null");
1405 if (!is_tan && gui->cache_passwords && gui->passwords && token)
1407 if (flags & GWEN_GUI_INPUT_FLAGS_RETRY)
1410 g_hash_table_remove(gui->passwords, token);
1415 if (g_hash_table_lookup_extended(gui->passwords, token, NULL,
1420 strncpy(buffer, password, max_len);
1421 buffer[max_len-1] =
'\0';
1423 LEAVE(
"chose remembered password");
1429 get_input(gui, flags, title, text, &password, min_len, max_len);
1434 strncpy(buffer, password, max_len);
1435 buffer[max_len-1] =
'\0';
1437 if (!is_tan && token)
1439 if (gui->cache_passwords && gui->passwords)
1442 DEBUG(
"Remember password, token=%s", token);
1443 g_hash_table_insert(gui->passwords, g_strdup(token), password);
1448 DEBUG(
"Forget password, token=%s", token);
1449 erase_password(password);
1455 return password ? 0 : -1;
1458 static gint GNC_GWENHYWFAR_CB
1459 setpasswordstatus_cb(GWEN_GUI *gwen_gui,
const gchar *token,
const gchar *pin,
1460 GWEN_GUI_PASSWORD_STATUS status, guint32 guiid)
1462 GncGWENGui *gui = GETDATA_GUI(gwen_gui);
1464 g_return_val_if_fail(gui, -1);
1466 ENTER(
"gui=%p, token=%s, status=%d", gui, token ? token :
"(null)", status);
1468 if (gui->passwords && status != GWEN_Gui_PasswordStatus_Ok)
1471 g_hash_table_remove(gui->passwords, token);
1478 static gint GNC_GWENHYWFAR_CB
1479 loghook_cb(GWEN_GUI *gwen_gui,
const gchar *log_domain,
1480 GWEN_LOGGER_LEVEL priority,
const gchar *text)
1482 if (G_LIKELY(priority < n_log_levels))
1483 g_log(log_domain, log_levels[priority],
"%s", text);
1488 static gint GNC_GWENHYWFAR_CB
1489 checkcert_cb(GWEN_GUI *gwen_gui,
const GWEN_SSLCERTDESCR *cert,
1490 GWEN_IO_LAYER *io, guint32 guiid)
1492 GncGWENGui *gui = GETDATA_GUI(gwen_gui);
1493 const gchar *hash, *status;
1494 GChecksum *gcheck = g_checksum_new (G_CHECKSUM_MD5);
1495 gchar cert_hash[16];
1499 g_return_val_if_fail(gui && gui->accepted_certs, -1);
1501 ENTER(
"gui=%p, cert=%p", gui, cert);
1503 hash = GWEN_SslCertDescr_GetFingerPrint(cert);
1504 status = GWEN_SslCertDescr_GetStatusText(cert);
1506 g_checksum_update (gcheck, hash, strlen (hash));
1507 g_checksum_update (gcheck, status, strlen (status));
1510 if (gui->permanently_accepted_certs)
1513 retval = GWEN_DB_GetIntValue(gui->permanently_accepted_certs,
1514 g_checksum_get_string (gcheck), 0, -1);
1518 g_checksum_free (gcheck);
1519 LEAVE(
"Certificate accepted by AqBanking's permanent cert store");
1525 g_warning(
"Can't check permanently accepted certs from invalid AqBanking cert store.");
1528 g_checksum_get_digest (gcheck, cert_hash, &hashlen);
1529 g_checksum_free (gcheck);
1530 g_assert (hashlen <=
sizeof (cert_hash));
1532 if (g_hash_table_lookup(gui->accepted_certs, cert_hash))
1535 LEAVE(
"Automatically accepting certificate");
1539 retval = gui->builtin_checkcert(gwen_gui, cert, io, guiid);
1543 g_hash_table_insert(gui->accepted_certs, g_strdup(cert_hash), cert_hash);
1546 LEAVE(
"retval=%d", retval);
1551 ggg_delete_event_cb(GtkWidget *widget, GdkEvent *event, gpointer user_data)
1553 GncGWENGui *gui = user_data;
1555 g_return_val_if_fail(gui, FALSE);
1557 ENTER(
"gui=%p, state=%d", gui, gui->state);
1559 if (gui->state == RUNNING)
1561 const char *still_running_msg =
1562 _(
"The Online Banking job is still running; are you "
1563 "sure you want to cancel?");
1564 if (!gnc_verify_dialog(gui->dialog, FALSE,
"%s", still_running_msg))
1577 ggg_abort_clicked_cb(GtkButton *button, gpointer user_data)
1579 GncGWENGui *gui = user_data;
1581 g_return_if_fail(gui && gui->state == RUNNING);
1583 ENTER(
"gui=%p", gui);
1591 ggg_close_clicked_cb(GtkButton *button, gpointer user_data)
1593 GncGWENGui *gui = user_data;
1595 g_return_if_fail(gui);
1596 g_return_if_fail(gui->state == FINISHED || gui->state == ABORTED);
1598 ENTER(
"gui=%p", gui);
1606 ggg_close_toggled_cb(GtkToggleButton *button, gpointer user_data)
1608 GncGWENGui *gui = user_data;
1610 g_return_if_fail(gui);
1611 g_return_if_fail(gui->parent);
1613 ENTER(
"gui=%p", gui);
1616 GNC_PREFS_GROUP_AQBANKING, GNC_PREF_CLOSE_ON_FINISH,
1617 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)));
gboolean gnc_GWEN_Gui_show_dialog()
void gnc_GWEN_Gui_shutdown(void)
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
gboolean gnc_GWEN_Gui_get_close_flag()
#define DEBUG(format, args...)
#define ENTER(format, args...)
GncGWENGui * gnc_GWEN_Gui_get(GtkWidget *parent)
GWEN_DB_NODE * gnc_ab_get_permanent_certs(void)
void gnc_GWEN_Gui_release(GncGWENGui *gui)
void gnc_plugin_aqbanking_set_logwindow_visible(gboolean logwindow_visible)
gboolean gnc_prefs_set_bool(const gchar *group, const gchar *pref_name, gboolean value)
Generic api to store and retrieve preferences.
Plugin registration of the AqBanking module.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
#define LEAVE(format, args...)
GUI callbacks for AqBanking.
void gnc_GWEN_Gui_log_init(void)
AqBanking utility functions.
void gnc_GWEN_Gui_set_close_flag(gboolean close_when_finished)
void gnc_GWEN_Gui_hide_dialog()
const gchar * QofLogModule