1 /***************************************************************************
2  begin       : Thu Apr 15 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_editaccount_p.h"
18 #include "aqbanking/i18n_l.h"
19 #include "aqhbci/banking/provider_l.h"
20 
21 #include "aqhbci/banking/account.h"
22 #include "aqhbci/banking/provider.h"
23 #include "aqhbci/banking/provider_online.h"
24 
25 #include <aqbanking/backendsupport/account.h>
26 #include <aqbanking/banking_be.h>
27 #include <aqbanking/dialogs/dlg_selectbankinfo.h>
28 
29 #include <gwenhywfar/gwenhywfar.h>
30 #include <gwenhywfar/misc.h>
31 #include <gwenhywfar/pathmanager.h>
32 #include <gwenhywfar/debug.h>
33 #include <gwenhywfar/gui.h>
34 #include <gwenhywfar/text.h>
35 
36 
37 #define DIALOG_MINWIDTH  400
38 #define DIALOG_MINHEIGHT 300
39 
40 #define USER_LIST_MINCOLWIDTH 50
41 
42 
43 
GWEN_INHERIT(GWEN_DIALOG,AH_EDIT_ACCOUNT_DIALOG)44 GWEN_INHERIT(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG)
45 
46 
47 
48 
49 GWEN_DIALOG *AH_EditAccountDialog_new(AB_PROVIDER *pro, AB_ACCOUNT *a, int doLock)
50 {
51   GWEN_DIALOG *dlg;
52   AH_EDIT_ACCOUNT_DIALOG *xdlg;
53   GWEN_BUFFER *fbuf;
54   int rv;
55 
56   dlg=GWEN_Dialog_new("ah_edit_account");
57   GWEN_NEW_OBJECT(AH_EDIT_ACCOUNT_DIALOG, xdlg);
58   GWEN_INHERIT_SETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg, xdlg,
59                        AH_EditAccountDialog_FreeData);
60   GWEN_Dialog_SetSignalHandler(dlg, AH_EditAccountDialog_SignalHandler);
61 
62   /* get path of dialog description file */
63   fbuf=GWEN_Buffer_new(0, 256, 0, 1);
64   rv=GWEN_PathManager_FindFile(AB_PM_LIBNAME, AB_PM_DATADIR,
65                                "aqbanking/backends/aqhbci//dialogs/dlg_editaccount.dlg",
66                                fbuf);
67   if (rv<0) {
68     DBG_INFO(AQBANKING_LOGDOMAIN, "Dialog description file not found (%d).", rv);
69     GWEN_Buffer_free(fbuf);
70     GWEN_Dialog_free(dlg);
71     return NULL;
72   }
73 
74   /* read dialog from dialog description file */
75   rv=GWEN_Dialog_ReadXmlFile(dlg, GWEN_Buffer_GetStart(fbuf));
76   if (rv<0) {
77     DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d).", rv);
78     GWEN_Buffer_free(fbuf);
79     GWEN_Dialog_free(dlg);
80     return NULL;
81   }
82   GWEN_Buffer_free(fbuf);
83 
84   xdlg->provider=pro;
85   xdlg->banking=AB_Provider_GetBanking(pro);
86   xdlg->account=a;
87   xdlg->doLock=doLock;
88 
89   /* done */
90   return dlg;
91 }
92 
93 
94 
AH_EditAccountDialog_FreeData(void * bp,void * p)95 void GWENHYWFAR_CB AH_EditAccountDialog_FreeData(void *bp, void *p)
96 {
97   AH_EDIT_ACCOUNT_DIALOG *xdlg;
98 
99   xdlg=(AH_EDIT_ACCOUNT_DIALOG *) p;
100   GWEN_FREE_OBJECT(xdlg);
101 }
102 
103 
104 
createUserString(const AB_USER * u,GWEN_BUFFER * tbuf)105 static void createUserString(const AB_USER *u, GWEN_BUFFER *tbuf)
106 {
107   const char *s;
108   char numbuf[32];
109   uint32_t uid;
110 
111   /* column 1 */
112   uid=AB_User_GetUniqueId(u);
113   snprintf(numbuf, sizeof(numbuf)-1, "%d", uid);
114   numbuf[sizeof(numbuf)-1]=0;
115   GWEN_Buffer_AppendString(tbuf, numbuf);
116   GWEN_Buffer_AppendString(tbuf, "-");
117 
118   /* column 2 */
119   s=AB_User_GetBankCode(u);
120   if (s && *s)
121     GWEN_Buffer_AppendString(tbuf, s);
122   GWEN_Buffer_AppendString(tbuf, "-");
123 
124   /* column 3 */
125   s=AB_User_GetBankCode(u);
126   if (s && *s)
127     GWEN_Buffer_AppendString(tbuf, s);
128   GWEN_Buffer_AppendString(tbuf, "-");
129 
130   /* column 4 */
131   s=AB_User_GetCustomerId(u);
132   if (!(s && *s))
133     s=AB_User_GetUserId(u);
134   if (s && *s)
135     GWEN_Buffer_AppendString(tbuf, s);
136   GWEN_Buffer_AppendString(tbuf, "-");
137 
138   /* column 5 */
139   s=AB_User_GetUserName(u);
140   if (s && *s)
141     GWEN_Buffer_AppendString(tbuf, s);
142 
143 }
144 
145 
146 
AH_EditAccountDialog_GetCurrentUserId(GWEN_DIALOG * dlg)147 uint32_t AH_EditAccountDialog_GetCurrentUserId(GWEN_DIALOG *dlg)
148 {
149   int idx;
150 
151   idx=GWEN_Dialog_GetIntProperty(dlg, "userCombo",  GWEN_DialogProperty_Value, 0, -1);
152   if (idx>=0) {
153     const char *currentText;
154 
155     currentText=GWEN_Dialog_GetCharProperty(dlg, "userCombo", GWEN_DialogProperty_Value, idx, NULL);
156     if (currentText && *currentText) {
157       unsigned long int id;
158 
159       if (sscanf(currentText, "%lu", &id)==1) {
160         return (uint32_t) id;
161       }
162     }
163   }
164 
165   return 0;
166 }
167 
168 
169 
AH_EditAccountDialog_FindUserEntry(GWEN_DIALOG * dlg,uint32_t userId)170 int AH_EditAccountDialog_FindUserEntry(GWEN_DIALOG *dlg, uint32_t userId)
171 {
172   AH_EDIT_ACCOUNT_DIALOG *xdlg;
173   int i;
174   int num;
175 
176   assert(dlg);
177   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
178   assert(xdlg);
179 
180   /* user list */
181   num=GWEN_Dialog_GetIntProperty(dlg, "userCombo", GWEN_DialogProperty_ValueCount, 0, 0);
182   for (i=1; i<num; i++) {
183     const char *t;
184 
185     t=GWEN_Dialog_GetCharProperty(dlg, "userCombo", GWEN_DialogProperty_Value, i, NULL);
186     if (t && *t) {
187       unsigned long int id;
188 
189       if (sscanf(t, "%lu-", &id)==1) {
190         if (id==userId)
191           return i;
192       }
193     }
194   } /* for i */
195 
196   return -1;
197 }
198 
199 
200 
AH_EditAccountDialog_RebuildUserLists(GWEN_DIALOG * dlg)201 void AH_EditAccountDialog_RebuildUserLists(GWEN_DIALOG *dlg)
202 {
203   AH_EDIT_ACCOUNT_DIALOG *xdlg;
204   AB_USER_LIST *users;
205   GWEN_STRINGLIST *sl;
206   int rv;
207 
208   assert(dlg);
209   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
210   assert(xdlg);
211 
212   GWEN_Dialog_SetIntProperty(dlg, "userCombo", GWEN_DialogProperty_ClearValues, 0, 0, 0);
213   GWEN_Dialog_SetCharProperty(dlg,
214                               "userCombo",
215                               GWEN_DialogProperty_AddValue,
216                               0,
217                               I18N("-- select --"),
218                               0);
219 
220   /* setup lists of available and selected users */
221   sl=GWEN_StringList_new();
222   users=AB_User_List_new();
223   rv=AB_Provider_ReadUsers(xdlg->provider, users);
224   if (rv<0) {
225 
226   }
227   else {
228     GWEN_BUFFER *tbuf;
229     AB_USER *u;
230 
231     tbuf=GWEN_Buffer_new(0, 256, 0, 1);
232 
233     u=AB_User_List_First(users);
234     while (u) {
235       createUserString(u, tbuf);
236       GWEN_StringList_AppendString(sl, GWEN_Buffer_GetStart(tbuf), 0, 1);
237       GWEN_Buffer_Reset(tbuf);
238       u=AB_User_List_Next(u);
239     }
240     GWEN_Buffer_free(tbuf);
241   }
242   AB_User_List_free(users);
243 
244   if (GWEN_StringList_Count(sl)) {
245     GWEN_STRINGLISTENTRY *se;
246 
247     /* sort user list */
248     GWEN_StringList_Sort(sl, 1, GWEN_StringList_SortModeNoCase);
249     se=GWEN_StringList_FirstEntry(sl);
250     while (se) {
251       const char *s;
252 
253       s=GWEN_StringListEntry_Data(se);
254       if (s && *s)
255         GWEN_Dialog_SetCharProperty(dlg,
256                                     "userCombo",
257                                     GWEN_DialogProperty_AddValue,
258                                     0,
259                                     s,
260                                     0);
261       se=GWEN_StringListEntry_Next(se);
262     }
263   }
264   GWEN_StringList_free(sl);
265 }
266 
267 
268 
AH_EditAccountDialog_Init(GWEN_DIALOG * dlg)269 void AH_EditAccountDialog_Init(GWEN_DIALOG *dlg)
270 {
271   AH_EDIT_ACCOUNT_DIALOG *xdlg;
272   GWEN_DB_NODE *dbPrefs;
273   int i;
274   const char *s;
275   AB_ACCOUNT_TYPE t;
276   uint32_t aflags;
277   uint32_t uid;
278 
279   assert(dlg);
280   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
281   assert(xdlg);
282 
283   dbPrefs=GWEN_Dialog_GetPreferences(dlg);
284 
285   /* init */
286   GWEN_Dialog_SetCharProperty(dlg,
287                               "",
288                               GWEN_DialogProperty_Title,
289                               0,
290                               I18N("Edit Account"),
291                               0);
292 
293   s=AB_Account_GetBankCode(xdlg->account);
294   GWEN_Dialog_SetCharProperty(dlg, "bankCodeEdit", GWEN_DialogProperty_Value, 0, s, 0);
295 
296   s=AB_Account_GetBankName(xdlg->account);
297   GWEN_Dialog_SetCharProperty(dlg, "bankNameEdit", GWEN_DialogProperty_Value, 0, s, 0);
298 
299   s=AB_Account_GetBic(xdlg->account);
300   GWEN_Dialog_SetCharProperty(dlg, "bicEdit", GWEN_DialogProperty_Value, 0, s, 0);
301 
302   s=AB_Account_GetAccountNumber(xdlg->account);
303   GWEN_Dialog_SetCharProperty(dlg, "accountNumberEdit", GWEN_DialogProperty_Value, 0, s, 0);
304 
305   s=AB_Account_GetAccountName(xdlg->account);
306   GWEN_Dialog_SetCharProperty(dlg, "accountNameEdit", GWEN_DialogProperty_Value, 0, s, 0);
307 
308   s=AB_Account_GetIban(xdlg->account);
309   GWEN_Dialog_SetCharProperty(dlg, "ibanEdit", GWEN_DialogProperty_Value, 0, s, 0);
310 
311   s=AB_Account_GetOwnerName(xdlg->account);
312   GWEN_Dialog_SetCharProperty(dlg, "ownerNameEdit", GWEN_DialogProperty_Value, 0, s, 0);
313 
314   s=AB_Account_GetCurrency(xdlg->account);
315   GWEN_Dialog_SetCharProperty(dlg, "currencyEdit", GWEN_DialogProperty_Value, 0, s, 0);
316 
317   s=AB_Account_GetCountry(xdlg->account);
318   GWEN_Dialog_SetCharProperty(dlg, "countryEdit", GWEN_DialogProperty_Value, 0, s, 0);
319 
320   /* setup account type */
321   GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
322                               I18N("unknown"),
323                               0);
324   GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
325                               I18N("Bank Account"),
326                               0);
327   GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
328                               I18N("Credit Card Account"),
329                               0);
330   GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
331                               I18N("Checking Account"),
332                               0);
333   GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
334                               I18N("Savings Account"),
335                               0);
336   GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
337                               I18N("Investment Account"),
338                               0);
339   GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
340                               I18N("Cash Account"),
341                               0);
342   GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
343                               I18N("Moneymarket Account"),
344                               0);
345 
346   t=AB_Account_GetAccountType(xdlg->account);
347   if (t<AB_AccountType_MoneyMarket)
348     GWEN_Dialog_SetIntProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_Value, 0, t, 0);
349 
350   AH_EditAccountDialog_RebuildUserLists(dlg);
351   uid=AB_Account_GetUserId(xdlg->account);
352   if (uid) {
353     int idx;
354 
355     idx=AH_EditAccountDialog_FindUserEntry(dlg, uid);
356     if (idx>=0)
357       GWEN_Dialog_SetIntProperty(dlg, "userCombo", GWEN_DialogProperty_Value, 0, idx, 0);
358   }
359 
360   /* setup flags */
361   aflags=AH_Account_GetFlags(xdlg->account);
362   GWEN_Dialog_SetIntProperty(dlg, "preferSingleTransferCheck", GWEN_DialogProperty_Value, 0,
363                              (aflags & AH_BANK_FLAGS_PREFER_SINGLE_TRANSFER)?1:0,
364                              0);
365   GWEN_Dialog_SetIntProperty(dlg, "preferSingleDebitNoteCheck", GWEN_DialogProperty_Value, 0,
366                              (aflags & AH_BANK_FLAGS_PREFER_SINGLE_DEBITNOTE)?1:0,
367                              0);
368 
369   GWEN_Dialog_SetIntProperty(dlg, "sepaPreferSingleTransferCheck", GWEN_DialogProperty_Value, 0,
370                              (aflags & AH_BANK_FLAGS_SEPA_PREFER_SINGLE_TRANSFER)?1:0,
371                              0);
372   GWEN_Dialog_SetIntProperty(dlg, "sepaPreferSingleDebitNoteCheck", GWEN_DialogProperty_Value, 0,
373                              (aflags & AH_BANK_FLAGS_SEPA_PREFER_SINGLE_DEBITNOTE)?1:0,
374                              0);
375   GWEN_Dialog_SetIntProperty(dlg, "preferCamtDownloadCheck", GWEN_DialogProperty_Value, 0,
376                              (aflags & AH_BANK_FLAGS_PREFER_CAMT_DOWNLOAD)?1:0,
377                              0);
378 
379 
380   /* read width */
381   i=GWEN_DB_GetIntValue(dbPrefs, "dialog_width", 0, -1);
382   if (i>=DIALOG_MINWIDTH)
383     GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, i, 0);
384 
385   /* read height */
386   i=GWEN_DB_GetIntValue(dbPrefs, "dialog_height", 0, -1);
387   if (i>=DIALOG_MINHEIGHT)
388     GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, i, 0);
389 }
390 
391 
392 
removeAllSpaces(uint8_t * s)393 static void removeAllSpaces(uint8_t *s)
394 {
395   uint8_t *d;
396 
397   d=s;
398   while (*s) {
399     if (*s>33)
400       *(d++)=*s;
401     s++;
402   }
403   *d=0;
404 }
405 
406 
407 
AH_EditAccountDialog_fromGui(GWEN_DIALOG * dlg,AB_ACCOUNT * a,int quiet)408 int AH_EditAccountDialog_fromGui(GWEN_DIALOG *dlg, AB_ACCOUNT *a, int quiet)
409 {
410   AH_EDIT_ACCOUNT_DIALOG *xdlg;
411   int i;
412   const char *s;
413   uint32_t aflags=0;
414 
415   assert(dlg);
416   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
417   assert(xdlg);
418 
419   /* fromGui */
420   s=GWEN_Dialog_GetCharProperty(dlg, "accountNumberEdit", GWEN_DialogProperty_Value, 0, NULL);
421   if (s && *s) {
422     GWEN_BUFFER *tbuf;
423 
424     tbuf=GWEN_Buffer_new(0, 256, 0, 1);
425     GWEN_Buffer_AppendString(tbuf, s);
426     GWEN_Text_CondenseBuffer(tbuf);
427     removeAllSpaces((uint8_t *)GWEN_Buffer_GetStart(tbuf));
428     if (a)
429       AB_Account_SetAccountNumber(a, GWEN_Buffer_GetStart(tbuf));
430     GWEN_Buffer_free(tbuf);
431   }
432 
433   s=GWEN_Dialog_GetCharProperty(dlg, "accountNameEdit", GWEN_DialogProperty_Value, 0, NULL);
434   if (s && *s) {
435     GWEN_BUFFER *tbuf;
436 
437     tbuf=GWEN_Buffer_new(0, 256, 0, 1);
438     GWEN_Buffer_AppendString(tbuf, s);
439     GWEN_Text_CondenseBuffer(tbuf);
440     if (a)
441       AB_Account_SetAccountName(a, GWEN_Buffer_GetStart(tbuf));
442     GWEN_Buffer_free(tbuf);
443   }
444 
445   s=GWEN_Dialog_GetCharProperty(dlg, "ibanEdit", GWEN_DialogProperty_Value, 0, NULL);
446   if (s && *s) {
447     GWEN_BUFFER *tbuf;
448 
449     tbuf=GWEN_Buffer_new(0, 256, 0, 1);
450     GWEN_Buffer_AppendString(tbuf, s);
451     GWEN_Text_CondenseBuffer(tbuf);
452     removeAllSpaces((uint8_t *)GWEN_Buffer_GetStart(tbuf));
453     if (a)
454       AB_Account_SetIban(a, GWEN_Buffer_GetStart(tbuf));
455     GWEN_Buffer_free(tbuf);
456   }
457 
458   s=GWEN_Dialog_GetCharProperty(dlg, "ownerNameEdit", GWEN_DialogProperty_Value, 0, NULL);
459   if (s && *s) {
460     GWEN_BUFFER *tbuf;
461 
462     tbuf=GWEN_Buffer_new(0, 256, 0, 1);
463     GWEN_Buffer_AppendString(tbuf, s);
464     GWEN_Text_CondenseBuffer(tbuf);
465     if (a)
466       AB_Account_SetOwnerName(a, GWEN_Buffer_GetStart(tbuf));
467     GWEN_Buffer_free(tbuf);
468   }
469 
470   /* get currency */
471   s=GWEN_Dialog_GetCharProperty(dlg, "currencyEdit", GWEN_DialogProperty_Value, 0, NULL);
472   if (a && s && *s)
473     AB_Account_SetCurrency(a, s);
474 
475   i=GWEN_Dialog_GetIntProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_Value, 0, 0);
476   if (a)
477     AB_Account_SetAccountType(a, i);
478 
479   /*  get country */
480   s=GWEN_Dialog_GetCharProperty(dlg, "countryEdit", GWEN_DialogProperty_Value, 0, NULL);
481   if (a && s && *s)
482     AB_Account_SetCountry(a, s);
483 
484   s=GWEN_Dialog_GetCharProperty(dlg, "bankCodeEdit", GWEN_DialogProperty_Value, 0, NULL);
485   if (s && *s) {
486     GWEN_BUFFER *tbuf;
487 
488     tbuf=GWEN_Buffer_new(0, 256, 0, 1);
489     GWEN_Buffer_AppendString(tbuf, s);
490     GWEN_Text_CondenseBuffer(tbuf);
491     removeAllSpaces((uint8_t *)GWEN_Buffer_GetStart(tbuf));
492     if (a)
493       AB_Account_SetBankCode(a, GWEN_Buffer_GetStart(tbuf));
494     GWEN_Buffer_free(tbuf);
495   }
496 
497   s=GWEN_Dialog_GetCharProperty(dlg, "bankNameEdit", GWEN_DialogProperty_Value, 0, NULL);
498   if (s && *s) {
499     GWEN_BUFFER *tbuf;
500 
501     tbuf=GWEN_Buffer_new(0, 256, 0, 1);
502     GWEN_Buffer_AppendString(tbuf, s);
503     GWEN_Text_CondenseBuffer(tbuf);
504     if (a)
505       AB_Account_SetBankName(a, GWEN_Buffer_GetStart(tbuf));
506     GWEN_Buffer_free(tbuf);
507   }
508 
509   s=GWEN_Dialog_GetCharProperty(dlg, "bicEdit", GWEN_DialogProperty_Value, 0, NULL);
510   if (s && *s) {
511     GWEN_BUFFER *tbuf;
512 
513     tbuf=GWEN_Buffer_new(0, 256, 0, 1);
514     GWEN_Buffer_AppendString(tbuf, s);
515     GWEN_Text_CondenseBuffer(tbuf);
516     removeAllSpaces((uint8_t *)GWEN_Buffer_GetStart(tbuf));
517     if (a)
518       AB_Account_SetBic(a, GWEN_Buffer_GetStart(tbuf));
519     GWEN_Buffer_free(tbuf);
520   }
521 
522   aflags=0;
523   if (GWEN_Dialog_GetIntProperty(dlg, "preferSingleTransferCheck", GWEN_DialogProperty_Value, 0, 0))
524     aflags|=AH_BANK_FLAGS_PREFER_SINGLE_TRANSFER;
525   if (GWEN_Dialog_GetIntProperty(dlg, "preferSingleDebitNoteCheck", GWEN_DialogProperty_Value, 0, 0))
526     aflags|=AH_BANK_FLAGS_PREFER_SINGLE_DEBITNOTE;
527   if (GWEN_Dialog_GetIntProperty(dlg, "sepaPreferSingleTransferCheck", GWEN_DialogProperty_Value, 0, 0))
528     aflags|=AH_BANK_FLAGS_SEPA_PREFER_SINGLE_TRANSFER;
529   if (GWEN_Dialog_GetIntProperty(dlg, "sepaPreferSingleDebitNoteCheck", GWEN_DialogProperty_Value, 0, 0))
530     aflags|=AH_BANK_FLAGS_SEPA_PREFER_SINGLE_DEBITNOTE;
531   if (GWEN_Dialog_GetIntProperty(dlg, "preferCamtDownloadCheck", GWEN_DialogProperty_Value, 0, 0))
532     aflags|=AH_BANK_FLAGS_PREFER_CAMT_DOWNLOAD;
533   if (a)
534     AH_Account_SetFlags(a, aflags);
535 
536   if (a) {
537     uint32_t uid;
538 
539     uid=AH_EditAccountDialog_GetCurrentUserId(dlg);
540     if (uid)
541       AB_Account_SetUserId(a, uid);
542     else {
543       DBG_ERROR(AQHBCI_LOGDOMAIN, "No user selected.");
544       return GWEN_ERROR_INVALID;
545     }
546   }
547 
548   return 0;
549 }
550 
551 
552 
AH_EditAccountDialog_Fini(GWEN_DIALOG * dlg)553 void AH_EditAccountDialog_Fini(GWEN_DIALOG *dlg)
554 {
555   AH_EDIT_ACCOUNT_DIALOG *xdlg;
556   int i;
557   GWEN_DB_NODE *dbPrefs;
558 
559   assert(dlg);
560   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
561   assert(xdlg);
562 
563   dbPrefs=GWEN_Dialog_GetPreferences(dlg);
564 
565   /* store dialog width */
566   i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, -1);
567   GWEN_DB_SetIntValue(dbPrefs,
568                       GWEN_DB_FLAGS_OVERWRITE_VARS,
569                       "dialog_width",
570                       i);
571 
572   /* store dialog height */
573   i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, -1);
574   GWEN_DB_SetIntValue(dbPrefs,
575                       GWEN_DB_FLAGS_OVERWRITE_VARS,
576                       "dialog_height",
577                       i);
578 }
579 
580 
581 
AH_EditAccountDialog_HandleActivatedBankCode(GWEN_DIALOG * dlg)582 int AH_EditAccountDialog_HandleActivatedBankCode(GWEN_DIALOG *dlg)
583 {
584   AH_EDIT_ACCOUNT_DIALOG *xdlg;
585   GWEN_DIALOG *dlg2;
586   int rv;
587 
588   assert(dlg);
589   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
590   assert(xdlg);
591 
592   dlg2=AB_SelectBankInfoDialog_new(xdlg->banking, "de", NULL);
593   if (dlg2==NULL) {
594     DBG_ERROR(AQBANKING_LOGDOMAIN, "Could not create dialog");
595     return GWEN_DialogEvent_ResultHandled;
596   }
597 
598   rv=GWEN_Gui_ExecDialog(dlg2, 0);
599   if (rv==0) {
600     /* rejected */
601     GWEN_Dialog_free(dlg2);
602     return GWEN_DialogEvent_ResultHandled;
603   }
604   else {
605     const AB_BANKINFO *bi;
606 
607     bi=AB_SelectBankInfoDialog_GetSelectedBankInfo(dlg2);
608     if (bi) {
609       const char *s;
610 
611       s=AB_BankInfo_GetBankId(bi);
612       GWEN_Dialog_SetCharProperty(dlg,
613                                   "bankCodeEdit",
614                                   GWEN_DialogProperty_Value,
615                                   0,
616                                   (s && *s)?s:"",
617                                   0);
618 
619       s=AB_BankInfo_GetBankName(bi);
620       GWEN_Dialog_SetCharProperty(dlg,
621                                   "bankNameEdit",
622                                   GWEN_DialogProperty_Value,
623                                   0,
624                                   (s && *s)?s:"",
625                                   0);
626 
627       s=AB_BankInfo_GetBic(bi);
628       GWEN_Dialog_SetCharProperty(dlg,
629                                   "bicEdit",
630                                   GWEN_DialogProperty_Value,
631                                   0,
632                                   (s && *s)?s:"",
633                                   0);
634     }
635   }
636   GWEN_Dialog_free(dlg2);
637 
638   return GWEN_DialogEvent_ResultHandled;
639 }
640 
641 
642 
AH_EditAccountDialog_HandleActivatedOk(GWEN_DIALOG * dlg)643 int AH_EditAccountDialog_HandleActivatedOk(GWEN_DIALOG *dlg)
644 {
645   AH_EDIT_ACCOUNT_DIALOG *xdlg;
646   int rv;
647 
648   assert(dlg);
649   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
650   assert(xdlg);
651 
652   rv=AH_EditAccountDialog_fromGui(dlg, NULL, 0);
653   if (rv<0) {
654     return GWEN_DialogEvent_ResultHandled;
655   }
656 
657   if (xdlg->doLock) {
658     int rv;
659 
660     rv=AB_Provider_BeginExclUseAccount(xdlg->provider, xdlg->account);
661     if (rv<0) {
662       DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d)", rv);
663       GWEN_Gui_MessageBox(GWEN_GUI_MSG_FLAGS_SEVERITY_NORMAL |
664                           GWEN_GUI_MSG_FLAGS_TYPE_ERROR |
665                           GWEN_GUI_MSG_FLAGS_CONFIRM_B1,
666                           I18N("Error"),
667                           I18N("Unable to lock account. Maybe already in use?"),
668                           I18N("Dismiss"),
669                           NULL,
670                           NULL,
671                           0);
672       return GWEN_DialogEvent_ResultHandled;
673     }
674   }
675 
676   AH_EditAccountDialog_fromGui(dlg, xdlg->account, 1);
677 
678   if (xdlg->doLock) {
679     int rv;
680 
681     rv=AB_Provider_EndExclUseAccount(xdlg->provider, xdlg->account, 0);
682     if (rv<0) {
683       DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d)", rv);
684       GWEN_Gui_MessageBox(GWEN_GUI_MSG_FLAGS_SEVERITY_NORMAL |
685                           GWEN_GUI_MSG_FLAGS_TYPE_ERROR |
686                           GWEN_GUI_MSG_FLAGS_CONFIRM_B1,
687                           I18N("Error"),
688                           I18N("Unable to unlock account."),
689                           I18N("Dismiss"),
690                           NULL,
691                           NULL,
692                           0);
693       AB_Provider_EndExclUseAccount(xdlg->provider, xdlg->account, 1);
694       return GWEN_DialogEvent_ResultHandled;
695     }
696   }
697 
698   rv=AB_Provider_WriteAccountSpecForAccount(xdlg->provider, xdlg->account, 1);
699   if (rv<0) {
700     DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
701     GWEN_Gui_MessageBox(GWEN_GUI_MSG_FLAGS_SEVERITY_NORMAL |
702                         GWEN_GUI_MSG_FLAGS_TYPE_ERROR |
703                         GWEN_GUI_MSG_FLAGS_CONFIRM_B1,
704                         I18N("Error"),
705                         I18N("Unable to update account spec."),
706                         I18N("Dismiss"),
707                         NULL,
708                         NULL,
709                         0);
710   }
711 
712 
713   return GWEN_DialogEvent_ResultAccept;
714 }
715 
716 
717 
AH_EditAccountDialog_HandleActivatedSepa(GWEN_DIALOG * dlg)718 int AH_EditAccountDialog_HandleActivatedSepa(GWEN_DIALOG *dlg)
719 {
720   AH_EDIT_ACCOUNT_DIALOG *xdlg;
721   int rv;
722   AB_IMEXPORTER_CONTEXT *ctx;
723 
724   assert(dlg);
725   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
726   assert(xdlg);
727 
728   ctx=AB_ImExporterContext_new();
729   rv=AH_Provider_GetAccountSepaInfo(xdlg->provider,
730                                     xdlg->account,
731                                     ctx,
732                                     1,   /* withProgress */
733                                     0,   /* nounmount */
734                                     xdlg->doLock);
735   AB_ImExporterContext_free(ctx);
736   if (rv<0) {
737     DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
738   }
739   else {
740     const char *s;
741 
742     /* update dialog */
743     s=AB_Account_GetBankCode(xdlg->account);
744     GWEN_Dialog_SetCharProperty(dlg, "bankCodeEdit", GWEN_DialogProperty_Value, 0, s, 0);
745 
746     s=AB_Account_GetBankName(xdlg->account);
747     GWEN_Dialog_SetCharProperty(dlg, "bankNameEdit", GWEN_DialogProperty_Value, 0, s, 0);
748 
749     s=AB_Account_GetBic(xdlg->account);
750     GWEN_Dialog_SetCharProperty(dlg, "bicEdit", GWEN_DialogProperty_Value, 0, s, 0);
751 
752     s=AB_Account_GetAccountNumber(xdlg->account);
753     GWEN_Dialog_SetCharProperty(dlg, "accountNumberEdit", GWEN_DialogProperty_Value, 0, s, 0);
754 
755     s=AB_Account_GetAccountName(xdlg->account);
756     GWEN_Dialog_SetCharProperty(dlg, "accountNameEdit", GWEN_DialogProperty_Value, 0, s, 0);
757 
758     s=AB_Account_GetIban(xdlg->account);
759     GWEN_Dialog_SetCharProperty(dlg, "ibanEdit", GWEN_DialogProperty_Value, 0, s, 0);
760 
761     s=AB_Account_GetOwnerName(xdlg->account);
762     GWEN_Dialog_SetCharProperty(dlg, "ownerNameEdit", GWEN_DialogProperty_Value, 0, s, 0);
763   }
764 
765   return GWEN_DialogEvent_ResultHandled;
766 }
767 
768 
769 
AH_EditAccountDialog_HandleActivated(GWEN_DIALOG * dlg,const char * sender)770 int AH_EditAccountDialog_HandleActivated(GWEN_DIALOG *dlg, const char *sender)
771 {
772   if (strcasecmp(sender, "bankCodeButton")==0)
773     return AH_EditAccountDialog_HandleActivatedBankCode(dlg);
774   else if (strcasecmp(sender, "getSepaButton")==0)
775     return AH_EditAccountDialog_HandleActivatedSepa(dlg);
776   else if (strcasecmp(sender, "okButton")==0)
777     return AH_EditAccountDialog_HandleActivatedOk(dlg);
778   else if (strcasecmp(sender, "abortButton")==0)
779     return GWEN_DialogEvent_ResultReject;
780   else if (strcasecmp(sender, "helpButton")==0) {
781     /* TODO: open a help dialog */
782   }
783 
784   return GWEN_DialogEvent_ResultNotHandled;
785 }
786 
787 
788 
AH_EditAccountDialog_SignalHandler(GWEN_DIALOG * dlg,GWEN_DIALOG_EVENTTYPE t,const char * sender)789 int GWENHYWFAR_CB AH_EditAccountDialog_SignalHandler(GWEN_DIALOG *dlg,
790                                                      GWEN_DIALOG_EVENTTYPE t,
791                                                      const char *sender)
792 {
793   AH_EDIT_ACCOUNT_DIALOG *xdlg;
794 
795   assert(dlg);
796   xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
797   assert(xdlg);
798 
799   switch (t) {
800   case GWEN_DialogEvent_TypeInit:
801     AH_EditAccountDialog_Init(dlg);
802     return GWEN_DialogEvent_ResultHandled;;
803 
804   case GWEN_DialogEvent_TypeFini:
805     AH_EditAccountDialog_Fini(dlg);
806     return GWEN_DialogEvent_ResultHandled;;
807 
808   case GWEN_DialogEvent_TypeValueChanged:
809     DBG_NOTICE(0, "ValueChanged: %s", sender);
810     return GWEN_DialogEvent_ResultHandled;;
811 
812   case GWEN_DialogEvent_TypeActivated:
813     return AH_EditAccountDialog_HandleActivated(dlg, sender);
814 
815   case GWEN_DialogEvent_TypeEnabled:
816   case GWEN_DialogEvent_TypeDisabled:
817   case GWEN_DialogEvent_TypeClose:
818 
819   case GWEN_DialogEvent_TypeLast:
820     return GWEN_DialogEvent_ResultNotHandled;
821 
822   }
823 
824   return GWEN_DialogEvent_ResultNotHandled;
825 }
826 
827 
828 
829 
830 
831 
832