1 /***************************************************************************
2  begin       : Fri Jul 30 2010
3  copyright   : (C) 2018 by Martin Preuss
4  email       : martin@aqbanking.de
5 
6  ***************************************************************************
7  * This file is part of the project "AqBanking".                           *
8  * Please see toplevel file COPYING of that project for license details.   *
9  ***************************************************************************/
10 
11 #ifdef HAVE_CONFIG_H
12 # include <config.h>
13 #endif
14 
15 
16 
17 #include "dlg_choose_usertype_p.h"
18 #include "aqbanking/i18n_l.h"
19 
20 #include "aqhbci/banking/provider.h"
21 
22 #include <aqbanking/backendsupport/user.h>
23 #include <aqbanking/banking_be.h>
24 #include <aqbanking/dialogs/dlg_usertype_page_be.h>
25 
26 #include <gwenhywfar/gwenhywfar.h>
27 #include <gwenhywfar/misc.h>
28 #include <gwenhywfar/pathmanager.h>
29 #include <gwenhywfar/debug.h>
30 #include <gwenhywfar/gui.h>
31 #include <gwenhywfar/text.h>
32 
33 
34 
35 
AH_ChooseUserTypeDialog_new(AB_PROVIDER * pro)36 GWEN_DIALOG *AH_ChooseUserTypeDialog_new(AB_PROVIDER *pro)
37 {
38   GWEN_DIALOG *dlg;
39   GWEN_BUFFER *fbuf;
40   int rv;
41 
42   DBG_INFO(AQHBCI_LOGDOMAIN, "AH_ChooseUserTypeDialog_new called");
43 
44   dlg=AB_UserTypePageDialog_new(AB_Provider_GetBanking(pro), "ah_choose_usertype");
45   GWEN_Dialog_SetSignalHandler(dlg, AH_ChooseUserTypeDialog_SignalHandler);
46 
47   /* get path of dialog description file */
48   fbuf=GWEN_Buffer_new(0, 256, 0, 1);
49   rv=GWEN_PathManager_FindFile(AB_PM_LIBNAME, AB_PM_DATADIR,
50                                "aqbanking/backends/aqhbci/dialogs/dlg_choose_usertype.dlg",
51                                fbuf);
52   if (rv<0) {
53     DBG_INFO(AQHBCI_LOGDOMAIN, "Dialog description file not found (%d).", rv);
54     GWEN_Buffer_free(fbuf);
55     GWEN_Dialog_free(dlg);
56     return NULL;
57   }
58 
59   /* read dialog from dialog description file */
60   rv=GWEN_Dialog_ReadXmlFile(dlg, GWEN_Buffer_GetStart(fbuf));
61   if (rv<0) {
62     DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d).", rv);
63     GWEN_Buffer_free(fbuf);
64     GWEN_Dialog_free(dlg);
65     return NULL;
66   }
67   GWEN_Buffer_free(fbuf);
68 
69   /* add media paths for icons */
70   GWEN_Dialog_AddMediaPathsFromPathManager(dlg,
71                                            GWEN_PM_LIBNAME,
72                                            GWEN_PM_SYSDATADIR,
73                                            "aqbanking/backends/aqhbci/dialogs");
74 
75   /* done */
76   return dlg;
77 }
78 
79 
80 
AH_ChooseUserTypeDialog_Init(GWEN_DIALOG * dlg)81 void AH_ChooseUserTypeDialog_Init(GWEN_DIALOG *dlg)
82 {
83   GWEN_Dialog_SetCharProperty(dlg, "hbciIntroLabel", GWEN_DialogProperty_Title, 0,
84                               I18N("<html>"
85                                    "<p>The HBCI module supports a broad range of security "
86                                    "media. Please choose the user setup mode from the following "
87                                    "list.</p>"
88                                    "<p>Click on the <i>run</i> button below to create the user.</p>"
89                                    "</html>"
90                                    "The HBCI module supports a broad range of security\n"
91                                    "media. Please choose the user setup mode from the following\n"
92                                    "list.\n"
93                                    "Click on the RUN button below to create the user."
94                                   ),
95                               0);
96 
97   switch (AB_UserTypePageDialog_GetSelectedType(dlg)) {
98   case AqHBCI_NewUserDialog_CodeGeneric:
99   case AqHBCI_NewUserDialog_CodeExistingPinTan:
100     GWEN_Dialog_SetIntProperty(dlg, "hbciPinTanRadio", GWEN_DialogProperty_Value, 0, 1, 0);
101     break;
102 
103   case AqHBCI_NewUserDialog_CodeCreateKeyFile:
104     GWEN_Dialog_SetIntProperty(dlg, "hbciCreateKeyFileRadio", GWEN_DialogProperty_Value, 0, 1, 0);
105     break;
106   case AqHBCI_NewUserDialog_CodeExistingKeyFile:
107     GWEN_Dialog_SetIntProperty(dlg, "hbciImportKeyFileRadio", GWEN_DialogProperty_Value, 0, 1, 0);
108     break;
109   case AqHBCI_NewUserDialog_CodeCreateChipcard:
110     GWEN_Dialog_SetIntProperty(dlg, "hbciInitChipcardRadio", GWEN_DialogProperty_Value, 0, 1, 0);
111     break;
112   case AqHBCI_NewUserDialog_CodeExistingChipcard:
113     GWEN_Dialog_SetIntProperty(dlg, "hbciUseChipcardRadio", GWEN_DialogProperty_Value, 0, 1, 0);
114     break;
115   }
116 
117   /* temporarily disable not-implemented buttons */
118   GWEN_Dialog_SetIntProperty(dlg, "hbciInitChipcardRadio", GWEN_DialogProperty_Enabled, 0, 0, 0);
119 }
120 
121 
122 
AH_ChooseUserTypeDialog_Fini(GWEN_DIALOG * dlg)123 void AH_ChooseUserTypeDialog_Fini(GWEN_DIALOG *dlg)
124 {
125   int i;
126 
127   if (GWEN_Dialog_GetIntProperty(dlg, "hbciPinTanRadio", GWEN_DialogProperty_Value, 0, 0)!=0)
128     i=AqHBCI_NewUserDialog_CodeExistingPinTan;
129   else if (GWEN_Dialog_GetIntProperty(dlg, "hbciUseChipcardRadio", GWEN_DialogProperty_Value, 0, 0)!=0)
130     i=AqHBCI_NewUserDialog_CodeExistingChipcard;
131   else if (GWEN_Dialog_GetIntProperty(dlg, "hbciCreateKeyFileRadio", GWEN_DialogProperty_Value, 0, 0)!=0)
132     i=AqHBCI_NewUserDialog_CodeCreateKeyFile;
133   else if (GWEN_Dialog_GetIntProperty(dlg, "hbciImportKeyFileRadio", GWEN_DialogProperty_Value, 0, 0)!=0)
134     i=AqHBCI_NewUserDialog_CodeExistingKeyFile;
135   else if (GWEN_Dialog_GetIntProperty(dlg, "hbciInitChipcardRadio", GWEN_DialogProperty_Value, 0, 0)!=0)
136     i=AqHBCI_NewUserDialog_CodeCreateChipcard;
137   else
138     i=AqHBCI_NewUserDialog_CodeGeneric;
139   DBG_NOTICE(0, "Setting selected type to %d", i);
140   AB_UserTypePageDialog_SetSelectedType(dlg, i);
141 }
142 
143 
144 
AH_ChooseUserTypeDialog_HandleActivated(GWEN_DIALOG * dlg,const char * sender)145 int AH_ChooseUserTypeDialog_HandleActivated(GWEN_DIALOG *dlg, const char *sender)
146 {
147   /* nothing for now */
148   return GWEN_DialogEvent_ResultNotHandled;
149 }
150 
151 
152 
AH_ChooseUserTypeDialog_SignalHandler(GWEN_DIALOG * dlg,GWEN_DIALOG_EVENTTYPE t,const char * sender)153 int GWENHYWFAR_CB AH_ChooseUserTypeDialog_SignalHandler(GWEN_DIALOG *dlg,
154                                                         GWEN_DIALOG_EVENTTYPE t,
155                                                         const char *sender)
156 {
157   switch (t) {
158   case GWEN_DialogEvent_TypeInit:
159     AH_ChooseUserTypeDialog_Init(dlg);
160     return GWEN_DialogEvent_ResultHandled;;
161 
162   case GWEN_DialogEvent_TypeFini:
163     AH_ChooseUserTypeDialog_Fini(dlg);
164     return GWEN_DialogEvent_ResultHandled;;
165 
166   case GWEN_DialogEvent_TypeValueChanged:
167     return GWEN_DialogEvent_ResultHandled;;
168 
169   case GWEN_DialogEvent_TypeActivated:
170     return AH_ChooseUserTypeDialog_HandleActivated(dlg, sender);
171 
172   case GWEN_DialogEvent_TypeEnabled:
173   case GWEN_DialogEvent_TypeDisabled:
174   case GWEN_DialogEvent_TypeClose:
175 
176   case GWEN_DialogEvent_TypeLast:
177     return GWEN_DialogEvent_ResultNotHandled;
178 
179   }
180 
181   return GWEN_DialogEvent_ResultNotHandled;
182 }
183 
184 
185 
186 
187 
188 
189