1 /***************************************************************************
2 begin : Thu Aug 19 2010
3 copyright : (C) 2020 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_newuser_p.h"
18 #include "dlg_ofx_special_l.h"
19 #include "aqofxconnect/libofxhome/dlg_getinst.h"
20 #include <aqofxconnect/user.h>
21 #include <aqofxconnect/provider.h>
22
23 #include "aqbanking/i18n_l.h"
24 #include <aqbanking/backendsupport/user.h>
25 #include <aqbanking/banking_be.h>
26
27 #include <gwenhywfar/gwenhywfar.h>
28 #include <gwenhywfar/misc.h>
29 #include <gwenhywfar/pathmanager.h>
30 #include <gwenhywfar/debug.h>
31 #include <gwenhywfar/gui.h>
32 #include <gwenhywfar/directory.h>
33
34
35 #define PAGE_BEGIN 0
36 #define PAGE_BANK 1
37 #define PAGE_USER 2
38 #define PAGE_APP 3
39 #define PAGE_CREATE 4
40 #define PAGE_END 5
41
42
43 #define DIALOG_MINWIDTH 400
44 #define DIALOG_MINHEIGHT 200
45
46
47
GWEN_INHERIT(GWEN_DIALOG,AO_NEWUSER_DIALOG)48 GWEN_INHERIT(GWEN_DIALOG, AO_NEWUSER_DIALOG)
49
50
51
52
53
54 GWEN_DIALOG *AO_NewUserDialog_new(AB_PROVIDER *pro)
55 {
56 GWEN_DIALOG *dlg;
57 AO_NEWUSER_DIALOG *xdlg;
58 GWEN_BUFFER *fbuf;
59 int rv;
60
61 dlg=GWEN_Dialog_new("ao_newuser");
62 GWEN_NEW_OBJECT(AO_NEWUSER_DIALOG, xdlg);
63 GWEN_INHERIT_SETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg, xdlg,
64 AO_NewUserDialog_FreeData);
65 GWEN_Dialog_SetSignalHandler(dlg, AO_NewUserDialog_SignalHandler);
66
67 /* get path of dialog description file */
68 fbuf=GWEN_Buffer_new(0, 256, 0, 1);
69 rv=GWEN_PathManager_FindFile(AB_PM_LIBNAME, AB_PM_DATADIR,
70 "aqbanking/backends/aqofxconnect/dialogs/dlg_newuser.dlg",
71 fbuf);
72 if (rv<0) {
73 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "Dialog description file not found (%d).", rv);
74 GWEN_Buffer_free(fbuf);
75 GWEN_Dialog_free(dlg);
76 return NULL;
77 }
78
79 /* read dialog from dialog description file */
80 rv=GWEN_Dialog_ReadXmlFile(dlg, GWEN_Buffer_GetStart(fbuf));
81 if (rv<0) {
82 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "here (%d)", rv);
83 GWEN_Buffer_free(fbuf);
84 GWEN_Dialog_free(dlg);
85 return NULL;
86 }
87 GWEN_Buffer_free(fbuf);
88
89 xdlg->provider=pro;
90 xdlg->banking=AB_Provider_GetBanking(pro);
91
92 /* preset */
93 xdlg->httpVMajor=1;
94 xdlg->httpVMinor=1;
95
96 /* done */
97 return dlg;
98 }
99
100
101
AO_NewUserDialog_FreeData(void * bp,void * p)102 void GWENHYWFAR_CB AO_NewUserDialog_FreeData(void *bp, void *p)
103 {
104 AO_NEWUSER_DIALOG *xdlg;
105
106 xdlg=(AO_NEWUSER_DIALOG *) p;
107 free(xdlg->userName);
108 free(xdlg->userId);
109 free(xdlg->url);
110 free(xdlg->brokerId);
111 free(xdlg->org);
112 free(xdlg->fid);
113 free(xdlg->appId);
114 free(xdlg->appVer);
115 free(xdlg->headerVer);
116 free(xdlg->clientUid);
117 free(xdlg->securityType);
118
119 GWEN_FREE_OBJECT(xdlg);
120 }
121
122
123
AO_NewUserDialog_GetUser(const GWEN_DIALOG * dlg)124 AB_USER *AO_NewUserDialog_GetUser(const GWEN_DIALOG *dlg)
125 {
126 AO_NEWUSER_DIALOG *xdlg;
127
128 assert(dlg);
129 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
130 assert(xdlg);
131
132 return xdlg->user;
133 }
134
135
136
AO_NewUserDialog_GetBankName(const GWEN_DIALOG * dlg)137 const char *AO_NewUserDialog_GetBankName(const GWEN_DIALOG *dlg)
138 {
139 AO_NEWUSER_DIALOG *xdlg;
140
141 assert(dlg);
142 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
143 assert(xdlg);
144
145 return xdlg->bankName;
146 }
147
148
149
AO_NewUserDialog_SetBankName(GWEN_DIALOG * dlg,const char * s)150 void AO_NewUserDialog_SetBankName(GWEN_DIALOG *dlg, const char *s)
151 {
152 AO_NEWUSER_DIALOG *xdlg;
153
154 assert(dlg);
155 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
156 assert(xdlg);
157
158 free(xdlg->bankName);
159 if (s)
160 xdlg->bankName=strdup(s);
161 else
162 xdlg->bankName=NULL;
163 }
164
165
166
AO_NewUserDialog_GetUserName(const GWEN_DIALOG * dlg)167 const char *AO_NewUserDialog_GetUserName(const GWEN_DIALOG *dlg)
168 {
169 AO_NEWUSER_DIALOG *xdlg;
170
171 assert(dlg);
172 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
173 assert(xdlg);
174
175 return xdlg->userName;
176 }
177
178
179
AO_NewUserDialog_SetUserName(GWEN_DIALOG * dlg,const char * s)180 void AO_NewUserDialog_SetUserName(GWEN_DIALOG *dlg, const char *s)
181 {
182 AO_NEWUSER_DIALOG *xdlg;
183
184 assert(dlg);
185 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
186 assert(xdlg);
187
188 free(xdlg->userName);
189 if (s)
190 xdlg->userName=strdup(s);
191 else
192 xdlg->userName=NULL;
193 }
194
195
196
AO_NewUserDialog_GetUserId(const GWEN_DIALOG * dlg)197 const char *AO_NewUserDialog_GetUserId(const GWEN_DIALOG *dlg)
198 {
199 AO_NEWUSER_DIALOG *xdlg;
200
201 assert(dlg);
202 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
203 assert(xdlg);
204
205 return xdlg->userId;
206 }
207
208
209
AO_NewUserDialog_SetUserId(GWEN_DIALOG * dlg,const char * s)210 void AO_NewUserDialog_SetUserId(GWEN_DIALOG *dlg, const char *s)
211 {
212 AO_NEWUSER_DIALOG *xdlg;
213
214 assert(dlg);
215 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
216 assert(xdlg);
217
218 free(xdlg->userId);
219 if (s)
220 xdlg->userId=strdup(s);
221 else
222 xdlg->userId=NULL;
223 }
224
225
226
AO_NewUserDialog_GetFid(const GWEN_DIALOG * dlg)227 const char *AO_NewUserDialog_GetFid(const GWEN_DIALOG *dlg)
228 {
229 AO_NEWUSER_DIALOG *xdlg;
230
231 assert(dlg);
232 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
233 assert(xdlg);
234
235 return xdlg->fid;
236 }
237
238
239
AO_NewUserDialog_SetFid(GWEN_DIALOG * dlg,const char * s)240 void AO_NewUserDialog_SetFid(GWEN_DIALOG *dlg, const char *s)
241 {
242 AO_NEWUSER_DIALOG *xdlg;
243
244 assert(dlg);
245 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
246 assert(xdlg);
247
248 free(xdlg->fid);
249 if (s)
250 xdlg->fid=strdup(s);
251 else
252 xdlg->fid=NULL;
253 }
254
255
256
AO_NewUserDialog_GetOrg(const GWEN_DIALOG * dlg)257 const char *AO_NewUserDialog_GetOrg(const GWEN_DIALOG *dlg)
258 {
259 AO_NEWUSER_DIALOG *xdlg;
260
261 assert(dlg);
262 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
263 assert(xdlg);
264
265 return xdlg->org;
266 }
267
268
269
AO_NewUserDialog_SetOrg(GWEN_DIALOG * dlg,const char * s)270 void AO_NewUserDialog_SetOrg(GWEN_DIALOG *dlg, const char *s)
271 {
272 AO_NEWUSER_DIALOG *xdlg;
273
274 assert(dlg);
275 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
276 assert(xdlg);
277
278 free(xdlg->org);
279 if (s)
280 xdlg->org=strdup(s);
281 else
282 xdlg->org=NULL;
283 }
284
285
286
AO_NewUserDialog_GetAppId(const GWEN_DIALOG * dlg)287 const char *AO_NewUserDialog_GetAppId(const GWEN_DIALOG *dlg)
288 {
289 AO_NEWUSER_DIALOG *xdlg;
290
291 assert(dlg);
292 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
293 assert(xdlg);
294
295 return xdlg->appId;
296 }
297
298
299
AO_NewUserDialog_SetAppId(GWEN_DIALOG * dlg,const char * s)300 void AO_NewUserDialog_SetAppId(GWEN_DIALOG *dlg, const char *s)
301 {
302 AO_NEWUSER_DIALOG *xdlg;
303
304 assert(dlg);
305 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
306 assert(xdlg);
307
308 free(xdlg->appId);
309 if (s)
310 xdlg->appId=strdup(s);
311 else
312 xdlg->appId=NULL;
313 }
314
315
316
AO_NewUserDialog_GetAppVer(const GWEN_DIALOG * dlg)317 const char *AO_NewUserDialog_GetAppVer(const GWEN_DIALOG *dlg)
318 {
319 AO_NEWUSER_DIALOG *xdlg;
320
321 assert(dlg);
322 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
323 assert(xdlg);
324
325 return xdlg->appVer;
326 }
327
328
329
AO_NewUserDialog_SetAppVer(GWEN_DIALOG * dlg,const char * s)330 void AO_NewUserDialog_SetAppVer(GWEN_DIALOG *dlg, const char *s)
331 {
332 AO_NEWUSER_DIALOG *xdlg;
333
334 assert(dlg);
335 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
336 assert(xdlg);
337
338 free(xdlg->appVer);
339 if (s)
340 xdlg->appVer=strdup(s);
341 else
342 xdlg->appVer=NULL;
343 }
344
345
346
AO_NewUserDialog_GetHeaderVer(const GWEN_DIALOG * dlg)347 const char *AO_NewUserDialog_GetHeaderVer(const GWEN_DIALOG *dlg)
348 {
349 AO_NEWUSER_DIALOG *xdlg;
350
351 assert(dlg);
352 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
353 assert(xdlg);
354
355 return xdlg->headerVer;
356 }
357
358
359
AO_NewUserDialog_SetHeaderVer(GWEN_DIALOG * dlg,const char * s)360 void AO_NewUserDialog_SetHeaderVer(GWEN_DIALOG *dlg, const char *s)
361 {
362 AO_NEWUSER_DIALOG *xdlg;
363
364 assert(dlg);
365 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
366 assert(xdlg);
367
368 free(xdlg->headerVer);
369 if (s)
370 xdlg->headerVer=strdup(s);
371 else
372 xdlg->headerVer=NULL;
373 }
374
375
376
AO_NewUserDialog_GetBrokerId(const GWEN_DIALOG * dlg)377 const char *AO_NewUserDialog_GetBrokerId(const GWEN_DIALOG *dlg)
378 {
379 AO_NEWUSER_DIALOG *xdlg;
380
381 assert(dlg);
382 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
383 assert(xdlg);
384
385 return xdlg->brokerId;
386 }
387
388
389
AO_NewUserDialog_SetBrokerId(GWEN_DIALOG * dlg,const char * s)390 void AO_NewUserDialog_SetBrokerId(GWEN_DIALOG *dlg, const char *s)
391 {
392 AO_NEWUSER_DIALOG *xdlg;
393
394 assert(dlg);
395 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
396 assert(xdlg);
397
398 free(xdlg->brokerId);
399 if (s)
400 xdlg->brokerId=strdup(s);
401 else
402 xdlg->brokerId=NULL;
403 }
404
405
406
AO_NewUserDialog_GetUrl(const GWEN_DIALOG * dlg)407 const char *AO_NewUserDialog_GetUrl(const GWEN_DIALOG *dlg)
408 {
409 AO_NEWUSER_DIALOG *xdlg;
410
411 assert(dlg);
412 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
413 assert(xdlg);
414
415 return xdlg->url;
416 }
417
418
419
AO_NewUserDialog_SetUrl(GWEN_DIALOG * dlg,const char * s)420 void AO_NewUserDialog_SetUrl(GWEN_DIALOG *dlg, const char *s)
421 {
422 AO_NEWUSER_DIALOG *xdlg;
423
424 assert(dlg);
425 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
426 assert(xdlg);
427
428 free(xdlg->url);
429 if (s)
430 xdlg->url=strdup(s);
431 else
432 xdlg->url=NULL;
433 }
434
435
436
AO_NewUserDialog_GetClientUid(const GWEN_DIALOG * dlg)437 const char *AO_NewUserDialog_GetClientUid(const GWEN_DIALOG *dlg)
438 {
439 AO_NEWUSER_DIALOG *xdlg;
440
441 assert(dlg);
442 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
443 assert(xdlg);
444
445 return xdlg->clientUid;
446 }
447
448
449
AO_NewUserDialog_SetClientUid(GWEN_DIALOG * dlg,const char * s)450 void AO_NewUserDialog_SetClientUid(GWEN_DIALOG *dlg, const char *s)
451 {
452 AO_NEWUSER_DIALOG *xdlg;
453
454 assert(dlg);
455 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
456 assert(xdlg);
457
458 free(xdlg->clientUid);
459 if (s)
460 xdlg->clientUid=strdup(s);
461 else
462 xdlg->clientUid=NULL;
463 }
464
465
466
AO_NewUserDialog_GetHttpVMajor(const GWEN_DIALOG * dlg)467 int AO_NewUserDialog_GetHttpVMajor(const GWEN_DIALOG *dlg)
468 {
469 AO_NEWUSER_DIALOG *xdlg;
470
471 assert(dlg);
472 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
473 assert(xdlg);
474
475 return xdlg->httpVMajor;
476 }
477
478
479
AO_NewUserDialog_GetHttpVMinor(const GWEN_DIALOG * dlg)480 int AO_NewUserDialog_GetHttpVMinor(const GWEN_DIALOG *dlg)
481 {
482 AO_NEWUSER_DIALOG *xdlg;
483
484 assert(dlg);
485 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
486 assert(xdlg);
487
488 return xdlg->httpVMinor;
489 }
490
491
492
AO_NewUserDialog_SetHttpVersion(GWEN_DIALOG * dlg,int vmajor,int vminor)493 void AO_NewUserDialog_SetHttpVersion(GWEN_DIALOG *dlg, int vmajor, int vminor)
494 {
495 AO_NEWUSER_DIALOG *xdlg;
496
497 assert(dlg);
498 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
499 assert(xdlg);
500
501 xdlg->httpVMajor=vmajor;
502 xdlg->httpVMinor=vminor;
503 }
504
505
506
AO_NewUserDialog_GetFlags(const GWEN_DIALOG * dlg)507 uint32_t AO_NewUserDialog_GetFlags(const GWEN_DIALOG *dlg)
508 {
509 AO_NEWUSER_DIALOG *xdlg;
510
511 assert(dlg);
512 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
513 assert(xdlg);
514
515 return xdlg->flags;
516 }
517
518
519
AO_NewUserDialog_SetFlags(GWEN_DIALOG * dlg,uint32_t fl)520 void AO_NewUserDialog_SetFlags(GWEN_DIALOG *dlg, uint32_t fl)
521 {
522 AO_NEWUSER_DIALOG *xdlg;
523
524 assert(dlg);
525 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
526 assert(xdlg);
527
528 xdlg->flags=fl;
529 }
530
531
532
AO_NewUserDialog_AddFlags(GWEN_DIALOG * dlg,uint32_t fl)533 void AO_NewUserDialog_AddFlags(GWEN_DIALOG *dlg, uint32_t fl)
534 {
535 AO_NEWUSER_DIALOG *xdlg;
536
537 assert(dlg);
538 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
539 assert(xdlg);
540
541 xdlg->flags&=~fl;
542 }
543
544
545
AO_NewUserDialog_SubFlags(GWEN_DIALOG * dlg,uint32_t fl)546 void AO_NewUserDialog_SubFlags(GWEN_DIALOG *dlg, uint32_t fl)
547 {
548 AO_NEWUSER_DIALOG *xdlg;
549
550 assert(dlg);
551 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
552 assert(xdlg);
553
554 xdlg->flags&=~fl;
555 }
556
557
558
559
560
561
AO_NewUserDialog_Init(GWEN_DIALOG * dlg)562 void AO_NewUserDialog_Init(GWEN_DIALOG *dlg)
563 {
564 AO_NEWUSER_DIALOG *xdlg;
565 GWEN_DB_NODE *dbPrefs;
566 int i;
567 const AO_APPINFO *ai;
568
569 assert(dlg);
570 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
571 assert(xdlg);
572
573 dbPrefs=GWEN_Dialog_GetPreferences(dlg);
574
575 GWEN_Dialog_SetCharProperty(dlg,
576 "",
577 GWEN_DialogProperty_Title,
578 0,
579 I18N("OFX DirectConnect Setup Wizard"),
580 0);
581
582 /* select first page */
583 GWEN_Dialog_SetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, 0, 0);
584
585 /* setup intro page */
586 GWEN_Dialog_SetCharProperty(dlg,
587 "wiz_begin_label",
588 GWEN_DialogProperty_Title,
589 0,
590 I18N("<html>"
591 "<p>This dialog assists you in setting up an OFX DirectConnect User.</p>"
592 "</html>"
593 "This dialog assists you in setting up an OFX DirectConnect User."),
594 0);
595
596 /* setup bank page */
597 GWEN_Dialog_SetCharProperty(dlg,
598 "wiz_bank_label",
599 GWEN_DialogProperty_Title,
600 0,
601 I18N("<html>"
602 "<p>Please enter your bank settings below.</p>"
603 "<p>Click the <b>Select</b> button to choose from a list of "
604 "known banks. That will connect to <i>www.ofxhome.com</i> and "
605 "try to retrieve information about your bank.</p>"
606 "<p>If you had to manually enter this information because your "
607 "bank was unknown to <i>www.ofxhome.com</i> you are kindly "
608 "asked to submit your bank server information there to help "
609 "the next user.</p>"
610 "</html>"
611 "Click the SELECT button to choose from a list of\n"
612 "known banks. That will connect to \"www.ofxhome.com\" and\n"
613 "try to retrieve information about your bank.\n"
614 "If you had to manually enter this information because your\n"
615 "bank was unknown to \"www.ofxhome.com\" you are kindly\n"
616 "asked to submit your bank server information there to help\n"
617 "the next user."),
618 0);
619
620 /* setup user page */
621 GWEN_Dialog_SetCharProperty(dlg,
622 "wiz_user_label",
623 GWEN_DialogProperty_Title,
624 0,
625 I18N("<html>"
626 "<p>Please enter your user settings below.</p>"
627 "<p><i>User Name</i> is your real name, <i>User Id</i> is "
628 "assigned to you by the bank after applying for OFX DirectConnect "
629 "and <i>Client UID</i> is used by some banks only. If you do not have such "
630 "a value in your documents from the bank just leave it blank.</p>"
631 "</html>"
632 "Please enter your user settings below.\n"
633 "\"User Name\" is your real name, \"User Id\" is\n"
634 "assigned to you by the bank after applying for OFX DirectConnect\n"
635 "and \"Client UID\" is used by some banks. If you do not have such\n"
636 "a value in your documents from the bank just leave it blank."),
637 0);
638
639
640 /* setup application page */
641 GWEN_Dialog_SetCharProperty(dlg,
642 "wiz_app_label",
643 GWEN_DialogProperty_Title,
644 0,
645 I18N("<html>"
646 "<p>Please choose the application you want AqBanking to emulate. "
647 "Not all banks support all applications and versions, you might have "
648 "to try multiple settings.</p>"
649 "</html>"
650 "Please choose the application you want AqBanking to emulate.\n"
651 "Not all banks support all applications and versions, you might have\n"
652 "to try multiple settings."),
653 0);
654
655 GWEN_Dialog_SetIntProperty(dlg, "wiz_app_combo", GWEN_DialogProperty_ClearValues, 0, 0, 0);
656 GWEN_Dialog_SetCharProperty(dlg, "wiz_app_combo", GWEN_DialogProperty_AddValue, 0, I18N("-- select --"), 0);
657
658 ai=AO_Provider_GetAppInfos(xdlg->provider);
659 if (ai) {
660 const AO_APPINFO *first;
661
662 first=ai;
663 while (ai->appName) {
664 GWEN_Dialog_SetCharProperty(dlg, "wiz_app_combo", GWEN_DialogProperty_AddValue, 0, I18N(ai->appName), 0);
665 ai++;
666 }
667
668 if (first->appName) {
669 GWEN_Dialog_SetIntProperty(dlg, "wiz_app_combo", GWEN_DialogProperty_Value, 0, 1, 0);
670 if (first->appId)
671 GWEN_Dialog_SetCharProperty(dlg, "wiz_appid_edit", GWEN_DialogProperty_Value, 0, first->appId, 0);
672 if (first->appVer)
673 GWEN_Dialog_SetCharProperty(dlg, "wiz_appver_edit", GWEN_DialogProperty_Value, 0, first->appVer, 0);
674 }
675 }
676
677 GWEN_Dialog_SetCharProperty(dlg, "wiz_headerver_edit", GWEN_DialogProperty_Value, 0, "102", 0);
678
679 /* setup creation page */
680 GWEN_Dialog_SetCharProperty(dlg,
681 "wiz_create_label",
682 GWEN_DialogProperty_Title,
683 0,
684 I18N("<html>"
685 "<p>We are now ready to create the user.</p>"
686 "<p>Click the <i>next</i> button to proceed or <i>abort</i> to abort.</p>"
687 "</html>"
688 "We are now ready to create the user.\n"
689 "Click the NEXT button to proceed or ABORT to abort."),
690 0);
691
692 /* setup extro page */
693 GWEN_Dialog_SetCharProperty(dlg,
694 "wiz_end_label",
695 GWEN_DialogProperty_Title,
696 0,
697 I18N("<html>"
698 "<p>The user has been successfully setup.</p>"
699 "<p>You can now try to retrieve the list of accounts the "
700 "bank allows you to manage via OFX DirectConnect.</p>"
701 "<p>Please note that not every banks supports this. If your "
702 "bank does not support account list download you will have to "
703 "add the account manually.</p>"
704 "</html>"
705 "The user has been successfully setup.\n"
706 "You can now try to retrieve the list of accounts the\n"
707 "bank allows you to manage via OFX DirectConnect.\n"
708 "Please note that not every banks supports this. If your\n"
709 "bank does not support account list download you will have to\n"
710 "add the account manually."
711 ),
712 0);
713
714 /* read width */
715 i=GWEN_DB_GetIntValue(dbPrefs, "dialog_width", 0, -1);
716 if (i>=DIALOG_MINWIDTH)
717 GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, i, 0);
718
719 /* read height */
720 i=GWEN_DB_GetIntValue(dbPrefs, "dialog_height", 0, -1);
721 if (i>=DIALOG_MINHEIGHT)
722 GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, i, 0);
723
724 /* disable next and previous buttons */
725 GWEN_Dialog_SetIntProperty(dlg, "wiz_prev_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
726 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
727 }
728
729
730
AO_NewUserDialog_Fini(GWEN_DIALOG * dlg)731 void AO_NewUserDialog_Fini(GWEN_DIALOG *dlg)
732 {
733 AO_NEWUSER_DIALOG *xdlg;
734 int i;
735 GWEN_DB_NODE *dbPrefs;
736
737 assert(dlg);
738 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
739 assert(xdlg);
740
741 dbPrefs=GWEN_Dialog_GetPreferences(dlg);
742
743 /* store dialog width */
744 i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, -1);
745 GWEN_DB_SetIntValue(dbPrefs,
746 GWEN_DB_FLAGS_OVERWRITE_VARS,
747 "dialog_width",
748 i);
749
750 /* store dialog height */
751 i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, -1);
752 GWEN_DB_SetIntValue(dbPrefs,
753 GWEN_DB_FLAGS_OVERWRITE_VARS,
754 "dialog_height",
755 i);
756 }
757
758
759
AO_NewUserDialog_GetBankPageData(GWEN_DIALOG * dlg)760 int AO_NewUserDialog_GetBankPageData(GWEN_DIALOG *dlg)
761 {
762 AO_NEWUSER_DIALOG *xdlg;
763 const char *s;
764
765 assert(dlg);
766 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
767 assert(xdlg);
768
769 s=GWEN_Dialog_GetCharProperty(dlg, "wiz_bankname_edit", GWEN_DialogProperty_Value, 0, NULL);
770 if (s && *s)
771 AO_NewUserDialog_SetBankName(dlg, s);
772 else {
773 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "Missing bank name");
774 return GWEN_ERROR_NO_DATA;
775 }
776
777 s=GWEN_Dialog_GetCharProperty(dlg, "wiz_brokerid_edit", GWEN_DialogProperty_Value, 0, NULL);
778 if (s && *s)
779 AO_NewUserDialog_SetBrokerId(dlg, s);
780 else
781 AO_NewUserDialog_SetBrokerId(dlg, NULL);
782
783 s=GWEN_Dialog_GetCharProperty(dlg, "wiz_fid_edit", GWEN_DialogProperty_Value, 0, NULL);
784 if (s && *s)
785 AO_NewUserDialog_SetFid(dlg, s);
786 else {
787 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "Missing FID");
788 return GWEN_ERROR_NO_DATA;
789 }
790
791 s=GWEN_Dialog_GetCharProperty(dlg, "wiz_org_edit", GWEN_DialogProperty_Value, 0, NULL);
792 if (s && *s)
793 AO_NewUserDialog_SetOrg(dlg, s);
794 else {
795 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "Missing ORG");
796 return GWEN_ERROR_NO_DATA;
797 }
798
799 s=GWEN_Dialog_GetCharProperty(dlg, "wiz_url_edit", GWEN_DialogProperty_Value, 0, NULL);
800 if (s && *s)
801 AO_NewUserDialog_SetUrl(dlg, s);
802 else {
803 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "Missing URL");
804 return GWEN_ERROR_NO_DATA;
805 }
806
807 return 0;
808 }
809
810
811
AO_NewUserDialog_GetUserPageData(GWEN_DIALOG * dlg)812 int AO_NewUserDialog_GetUserPageData(GWEN_DIALOG *dlg)
813 {
814 AO_NEWUSER_DIALOG *xdlg;
815 const char *s;
816
817 assert(dlg);
818 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
819 assert(xdlg);
820
821 s=GWEN_Dialog_GetCharProperty(dlg, "wiz_username_edit", GWEN_DialogProperty_Value, 0, NULL);
822 if (s && *s)
823 AO_NewUserDialog_SetUserName(dlg, s);
824 else {
825 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "Missing user name");
826 return GWEN_ERROR_NO_DATA;
827 }
828
829 s=GWEN_Dialog_GetCharProperty(dlg, "wiz_userid_edit", GWEN_DialogProperty_Value, 0, NULL);
830 if (s && *s)
831 AO_NewUserDialog_SetUserId(dlg, s);
832 else {
833 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "Missing user id");
834 return GWEN_ERROR_NO_DATA;
835 }
836
837 s=GWEN_Dialog_GetCharProperty(dlg, "wiz_clientuid_edit", GWEN_DialogProperty_Value, 0, NULL);
838 if (s && *s)
839 AO_NewUserDialog_SetClientUid(dlg, s);
840 else
841 AO_NewUserDialog_SetClientUid(dlg, NULL);
842
843 return 0;
844 }
845
846
847
AO_NewUserDialog_GetAppPageData(GWEN_DIALOG * dlg)848 int AO_NewUserDialog_GetAppPageData(GWEN_DIALOG *dlg)
849 {
850 AO_NEWUSER_DIALOG *xdlg;
851 const char *s;
852
853 assert(dlg);
854 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
855 assert(xdlg);
856
857 s=GWEN_Dialog_GetCharProperty(dlg, "wiz_appid_edit", GWEN_DialogProperty_Value, 0, NULL);
858 if (s && *s)
859 AO_NewUserDialog_SetAppId(dlg, s);
860 else {
861 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "Missing application id");
862 return GWEN_ERROR_NO_DATA;
863 }
864
865 s=GWEN_Dialog_GetCharProperty(dlg, "wiz_appver_edit", GWEN_DialogProperty_Value, 0, NULL);
866 if (s && *s)
867 AO_NewUserDialog_SetAppVer(dlg, s);
868 else {
869 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "Missing application version");
870 return GWEN_ERROR_NO_DATA;
871 }
872
873 s=GWEN_Dialog_GetCharProperty(dlg, "wiz_headerver_edit", GWEN_DialogProperty_Value, 0, NULL);
874 if (s && *s)
875 AO_NewUserDialog_SetHeaderVer(dlg, s);
876 else {
877 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "Missing application version");
878 return GWEN_ERROR_NO_DATA;
879 }
880
881 return 0;
882 }
883
884
885
AO_NewUserDialog_EnterPage(GWEN_DIALOG * dlg,int page,int forwards)886 int AO_NewUserDialog_EnterPage(GWEN_DIALOG *dlg, int page, int forwards)
887 {
888 AO_NEWUSER_DIALOG *xdlg;
889 int rv;
890
891 assert(dlg);
892 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
893 assert(xdlg);
894
895 switch (page) {
896 case PAGE_BEGIN:
897 GWEN_Dialog_SetIntProperty(dlg, "wiz_prev_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
898 GWEN_Dialog_SetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, page, 0);
899 return GWEN_DialogEvent_ResultHandled;
900
901 case PAGE_BANK:
902 GWEN_Dialog_SetIntProperty(dlg, "wiz_prev_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
903 rv=AO_NewUserDialog_GetBankPageData(dlg);
904 if (rv<0)
905 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
906 else
907 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
908 GWEN_Dialog_SetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, page, 0);
909 return GWEN_DialogEvent_ResultHandled;
910
911 case PAGE_USER:
912 GWEN_Dialog_SetIntProperty(dlg, "wiz_prev_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
913 rv=AO_NewUserDialog_GetUserPageData(dlg);
914 if (rv<0)
915 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
916 else
917 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
918 GWEN_Dialog_SetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, page, 0);
919 return GWEN_DialogEvent_ResultHandled;
920
921 case PAGE_APP:
922 GWEN_Dialog_SetIntProperty(dlg, "wiz_prev_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
923 rv=AO_NewUserDialog_GetAppPageData(dlg);
924 if (rv<0)
925 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
926 else
927 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
928 GWEN_Dialog_SetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, page, 0);
929 return GWEN_DialogEvent_ResultHandled;
930
931 case PAGE_CREATE:
932 if (!forwards) {
933 AO_NewUserDialog_UndoIt(dlg);
934 GWEN_Dialog_SetCharProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Title, 0, I18N("Next"), 0);
935 }
936 GWEN_Dialog_SetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, page, 0);
937 return GWEN_DialogEvent_ResultHandled;
938
939 case PAGE_END:
940 GWEN_Dialog_SetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, page, 0);
941 GWEN_Dialog_SetCharProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Title, 0, I18N("Finish"), 0);
942 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
943 #if 0
944 GWEN_Dialog_SetIntProperty(dlg, "wiz_prev_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
945 GWEN_Dialog_SetIntProperty(dlg, "wiz_abort_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
946 #endif
947 return GWEN_DialogEvent_ResultHandled;
948
949 default:
950 return GWEN_DialogEvent_ResultHandled;
951 }
952
953 return GWEN_DialogEvent_ResultHandled;
954 }
955
956
957
AO_NewUserDialog_DoIt(GWEN_DIALOG * dlg)958 int AO_NewUserDialog_DoIt(GWEN_DIALOG *dlg)
959 {
960 AO_NEWUSER_DIALOG *xdlg;
961 AB_USER *u;
962 int rv;
963 uint32_t pid;
964
965 DBG_ERROR(0, "Doit");
966 assert(dlg);
967 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
968 assert(xdlg);
969
970 DBG_ERROR(0, "Creating user");
971 u=AB_Provider_CreateUserObject(xdlg->provider);
972 if (u==NULL) {
973 DBG_ERROR(AQOFXCONNECT_LOGDOMAIN, "Could not create user, maybe backend missing?");
974 // TODO: show error message
975 return GWEN_DialogEvent_ResultHandled;
976 }
977
978 /* generic setup */
979 AB_User_SetUserName(u, xdlg->userName);
980 AB_User_SetUserId(u, xdlg->userId);
981 AB_User_SetCustomerId(u, xdlg->userId);
982 AB_User_SetCountry(u, "us");
983 AO_User_SetBankName(u, xdlg->bankName);
984 AB_User_SetBankCode(u, "0000000000");
985
986 AO_User_SetFlags(u, xdlg->flags);
987 AO_User_SetBrokerId(u, xdlg->brokerId);
988 AO_User_SetOrg(u, xdlg->org);
989 AO_User_SetFid(u, xdlg->fid);
990
991 AO_User_SetAppId(u, xdlg->appId);
992 AO_User_SetAppVer(u, xdlg->appVer);
993 AO_User_SetHeaderVer(u, xdlg->headerVer);
994 AO_User_SetClientUid(u, xdlg->clientUid);
995 AO_User_SetSecurityType(u, xdlg->securityType);
996
997 AO_User_SetServerAddr(u, xdlg->url);
998 AO_User_SetHttpVMajor(u, xdlg->httpVMajor);
999 AO_User_SetHttpVMinor(u, xdlg->httpVMinor);
1000
1001 DBG_ERROR(0, "Adding user");
1002 rv=AB_Provider_AddUser(xdlg->provider, u);
1003 if (rv<0) {
1004 DBG_ERROR(AQOFXCONNECT_LOGDOMAIN, "Could not add user (%d)", rv);
1005 AB_User_free(u);
1006 return GWEN_DialogEvent_ResultHandled;
1007 }
1008
1009 pid=GWEN_Gui_ProgressStart(GWEN_GUI_PROGRESS_DELAY |
1010 GWEN_GUI_PROGRESS_ALLOW_EMBED |
1011 GWEN_GUI_PROGRESS_SHOW_PROGRESS |
1012 GWEN_GUI_PROGRESS_SHOW_ABORT,
1013 I18N("Setting Up OFX DirectConnect User"),
1014 I18N("The user will be created and the certificate retrieved."),
1015 1,
1016 0);
1017 /* lock new user */
1018 DBG_ERROR(0, "Locking user");
1019 rv=AB_Provider_BeginExclUseUser(xdlg->provider, u);
1020 if (rv<0) {
1021 DBG_ERROR(AQOFXCONNECT_LOGDOMAIN, "Could not lock user (%d)", rv);
1022 GWEN_Gui_ProgressLog(pid,
1023 GWEN_LoggerLevel_Error,
1024 I18N("Unable to lock users"));
1025 AB_Provider_DeleteUser(xdlg->provider, AB_User_GetUniqueId(u));
1026 GWEN_Gui_ProgressEnd(pid);
1027 return GWEN_DialogEvent_ResultHandled;
1028 }
1029
1030 GWEN_Gui_ProgressLog(pid,
1031 GWEN_LoggerLevel_Notice,
1032 I18N("Retrieving SSL certificate"));
1033 rv=AO_Provider_GetCert(xdlg->provider, u);
1034 if (rv<0) {
1035 AB_Provider_EndExclUseUser(xdlg->provider, u, 1);
1036 DBG_ERROR(AQOFXCONNECT_LOGDOMAIN, "here (%d)", rv);
1037 AB_Provider_DeleteUser(xdlg->provider, AB_User_GetUniqueId(u));
1038 GWEN_Gui_ProgressEnd(pid);
1039 return GWEN_DialogEvent_ResultHandled;
1040 }
1041
1042 rv=GWEN_Gui_ProgressAdvance(pid, GWEN_GUI_PROGRESS_ONE);
1043 if (rv==GWEN_ERROR_USER_ABORTED) {
1044 AB_Provider_EndExclUseUser(xdlg->provider, u, 1);
1045 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "here (%d)", rv);
1046 AB_Provider_DeleteUser(xdlg->provider, AB_User_GetUniqueId(u));
1047 GWEN_Gui_ProgressLog(pid,
1048 GWEN_LoggerLevel_Error,
1049 I18N("Aborted by user."));
1050 GWEN_Gui_ProgressEnd(pid);
1051 return GWEN_DialogEvent_ResultHandled;
1052 }
1053
1054 /* unlock user */
1055 DBG_ERROR(0, "Unlocking user");
1056 rv=AB_Provider_EndExclUseUser(xdlg->provider, u, 0);
1057 if (rv<0) {
1058 DBG_INFO(AQOFXCONNECT_LOGDOMAIN,
1059 "Could not unlock user [%s] (%d)",
1060 AB_User_GetUserId(u), rv);
1061 GWEN_Gui_ProgressLog2(pid,
1062 GWEN_LoggerLevel_Error,
1063 I18N("Could not unlock user %s (%d)"),
1064 AB_User_GetUserId(u), rv);
1065 AB_Provider_EndExclUseUser(xdlg->provider, u, 1);
1066 AB_Provider_DeleteUser(xdlg->provider, AB_User_GetUniqueId(u));
1067 GWEN_Gui_ProgressEnd(pid);
1068 return GWEN_DialogEvent_ResultHandled;
1069 }
1070
1071 GWEN_Gui_ProgressEnd(pid);
1072 AO_NewUserDialog_EnterPage(dlg, PAGE_END, 1);
1073
1074 xdlg->user=u;
1075
1076 return GWEN_DialogEvent_ResultHandled;
1077 }
1078
1079
1080
AO_NewUserDialog_UndoIt(GWEN_DIALOG * dlg)1081 int AO_NewUserDialog_UndoIt(GWEN_DIALOG *dlg)
1082 {
1083 AO_NEWUSER_DIALOG *xdlg;
1084 AB_USER *u;
1085
1086 DBG_ERROR(0, "UndoIt");
1087 assert(dlg);
1088 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
1089 assert(xdlg);
1090
1091 u=xdlg->user;
1092 if (u) {
1093 AB_ACCOUNT_LIST *accountList;
1094 int rv;
1095
1096 /* delete all accounts created for this user */
1097 accountList=AB_Account_List_new();
1098 rv=AB_Provider_ReadAccounts(xdlg->provider, accountList);
1099 if (rv<0) {
1100 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "here (%d)", rv);
1101 }
1102 else {
1103 uint32_t uid;
1104 AB_ACCOUNT *a;
1105
1106 uid=AB_User_GetUniqueId(u);
1107 a=AB_Account_List_First(accountList);
1108 while (a) {
1109 AB_Account_List_Del(a);
1110 if (AB_Account_GetUserId(a)==uid)
1111 AB_Provider_DeleteAccount(xdlg->provider, AB_Account_GetUniqueId(a));
1112 a=AB_Account_List_Next(a);
1113 } /* while a */
1114 }
1115 AB_Account_List_free(accountList);
1116
1117 /* delete the user itself */
1118 AB_Provider_DeleteUser(xdlg->provider, AB_User_GetUniqueId(u));
1119 xdlg->user=NULL;
1120 }
1121 return GWEN_DialogEvent_ResultHandled;
1122 }
1123
1124
1125
AO_NewUserDialog_Next(GWEN_DIALOG * dlg)1126 int AO_NewUserDialog_Next(GWEN_DIALOG *dlg)
1127 {
1128 AO_NEWUSER_DIALOG *xdlg;
1129 int page;
1130
1131 assert(dlg);
1132 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
1133 assert(xdlg);
1134
1135 page=GWEN_Dialog_GetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, -1);
1136 if (page==PAGE_CREATE) {
1137 return AO_NewUserDialog_DoIt(dlg);
1138 }
1139 else if (page<PAGE_END) {
1140 page++;
1141 return AO_NewUserDialog_EnterPage(dlg, page, 1);
1142 }
1143 else if (page==PAGE_END)
1144 return GWEN_DialogEvent_ResultAccept;
1145
1146 return GWEN_DialogEvent_ResultHandled;
1147 }
1148
1149
1150
AO_NewUserDialog_Previous(GWEN_DIALOG * dlg)1151 int AO_NewUserDialog_Previous(GWEN_DIALOG *dlg)
1152 {
1153 AO_NEWUSER_DIALOG *xdlg;
1154 int page;
1155
1156 assert(dlg);
1157 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
1158 assert(xdlg);
1159
1160 page=GWEN_Dialog_GetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, -1);
1161 if (page>PAGE_BEGIN) {
1162 page--;
1163 return AO_NewUserDialog_EnterPage(dlg, page, 0);
1164 }
1165
1166 return GWEN_DialogEvent_ResultHandled;
1167 }
1168
1169
1170
AO_NewUserDialog_HandleActivatedSpecial(GWEN_DIALOG * dlg)1171 int AO_NewUserDialog_HandleActivatedSpecial(GWEN_DIALOG *dlg)
1172 {
1173 AO_NEWUSER_DIALOG *xdlg;
1174 GWEN_DIALOG *dlg2;
1175 int rv;
1176
1177 assert(dlg);
1178 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
1179 assert(xdlg);
1180
1181 dlg2=AO_OfxSpecialDialog_new(xdlg->provider);
1182 if (dlg2==NULL) {
1183 DBG_ERROR(AQBANKING_LOGDOMAIN, "Could not create dialog");
1184 return GWEN_DialogEvent_ResultHandled;
1185 }
1186
1187 AO_OfxSpecialDialog_SetHttpVersion(dlg2, xdlg->httpVMajor, xdlg->httpVMinor);
1188 AO_OfxSpecialDialog_SetFlags(dlg2, xdlg->flags);
1189
1190 AO_OfxSpecialDialog_SetClientUid(dlg2, xdlg->clientUid);
1191 AO_OfxSpecialDialog_SetSecurityType(dlg2, xdlg->securityType);
1192
1193 rv=GWEN_Gui_ExecDialog(dlg2, 0);
1194 if (rv==0) {
1195 /* rejected */
1196 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "Rejected");
1197 GWEN_Dialog_free(dlg2);
1198 return GWEN_DialogEvent_ResultHandled;
1199 }
1200 else {
1201 const char *s;
1202
1203 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "Accepted");
1204 xdlg->httpVMajor=AO_OfxSpecialDialog_GetHttpVMajor(dlg2);
1205 xdlg->httpVMinor=AO_OfxSpecialDialog_GetHttpVMinor(dlg2);
1206 xdlg->flags=AO_OfxSpecialDialog_GetFlags(dlg2);
1207
1208 s=AO_OfxSpecialDialog_GetClientUid(dlg2);
1209 free(xdlg->clientUid);
1210 if (s)
1211 xdlg->clientUid=strdup(s);
1212 else
1213 xdlg->clientUid=NULL;
1214
1215 s=AO_OfxSpecialDialog_GetSecurityType(dlg2);
1216 free(xdlg->securityType);
1217 if (s)
1218 xdlg->securityType=strdup(s);
1219 else
1220 xdlg->securityType=NULL;
1221 }
1222
1223 GWEN_Dialog_free(dlg2);
1224 return GWEN_DialogEvent_ResultHandled;
1225 }
1226
1227
1228
AO_NewUserDialog_HandleActivatedBankSelect(GWEN_DIALOG * dlg)1229 int AO_NewUserDialog_HandleActivatedBankSelect(GWEN_DIALOG *dlg)
1230 {
1231 AO_NEWUSER_DIALOG *xdlg;
1232 int rv;
1233 GWEN_DIALOG *dlg2;
1234 GWEN_BUFFER *tbuf;
1235
1236 assert(dlg);
1237 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
1238 assert(xdlg);
1239
1240 /* get data dir */
1241 tbuf=GWEN_Buffer_new(0, 256, 0, 1);
1242 rv=AB_Banking_GetProviderUserDataDir(xdlg->banking, "aqofxconnect", tbuf);
1243 if (rv<0) {
1244 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "here (%d)", rv);
1245 GWEN_Buffer_free(tbuf);
1246 return GWEN_DialogEvent_ResultHandled;
1247 }
1248 GWEN_Buffer_AppendString(tbuf, GWEN_DIR_SEPARATOR_S "ofxhome");
1249
1250 /* possibly create data folder */
1251 rv=GWEN_Directory_GetPath(GWEN_Buffer_GetStart(tbuf), GWEN_PATH_FLAGS_CHECKROOT);
1252 if (rv<0) {
1253 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "here (%d)", rv);
1254 GWEN_Buffer_free(tbuf);
1255 return GWEN_DialogEvent_ResultHandled;
1256 }
1257
1258 dlg2=OH_GetInstituteDialog_new(GWEN_Buffer_GetStart(tbuf), NULL);
1259 GWEN_Buffer_free(tbuf);
1260 if (dlg2==NULL) {
1261 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "Could not create dialog");
1262 return GWEN_DialogEvent_ResultHandled;
1263 }
1264 rv=GWEN_Gui_ExecDialog(dlg2, 0);
1265 if (rv<=0) {
1266 DBG_DEBUG(AQOFXCONNECT_LOGDOMAIN, "Dialog: rejected (%d)", rv);
1267 return GWEN_DialogEvent_ResultHandled;
1268 }
1269 else {
1270 const OH_INSTITUTE_DATA *od;
1271
1272 DBG_DEBUG(AQOFXCONNECT_LOGDOMAIN, "Dialog: rejected (%d)", rv);
1273 od=OH_GetInstituteDialog_GetSelectedInstitute(dlg2);
1274 if (od) {
1275 const char *s;
1276
1277 s=OH_InstituteData_GetName(od);
1278 if (s && *s)
1279 GWEN_Dialog_SetCharProperty(dlg, "wiz_bankname_edit", GWEN_DialogProperty_Value, 0, s, 0);
1280
1281 s=OH_InstituteData_GetFid(od);
1282 if (s && *s)
1283 GWEN_Dialog_SetCharProperty(dlg, "wiz_fid_edit", GWEN_DialogProperty_Value, 0, s, 0);
1284 s=OH_InstituteData_GetOrg(od);
1285 if (s && *s)
1286 GWEN_Dialog_SetCharProperty(dlg, "wiz_org_edit", GWEN_DialogProperty_Value, 0, s, 0);
1287 s=OH_InstituteData_GetUrl(od);
1288 if (s && *s)
1289 GWEN_Dialog_SetCharProperty(dlg, "wiz_url_edit", GWEN_DialogProperty_Value, 0, s, 0);
1290 rv=AO_NewUserDialog_GetBankPageData(dlg);
1291 if (rv<0)
1292 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
1293 else
1294 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
1295 }
1296 }
1297 GWEN_Dialog_free(dlg2);
1298 return GWEN_DialogEvent_ResultHandled;
1299 }
1300
1301
1302
AO_NewUserDialog_HandleActivatedApp(GWEN_DIALOG * dlg)1303 int AO_NewUserDialog_HandleActivatedApp(GWEN_DIALOG *dlg)
1304 {
1305 AO_NEWUSER_DIALOG *xdlg;
1306 int idx;
1307
1308 assert(dlg);
1309 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
1310 assert(xdlg);
1311
1312
1313 idx=GWEN_Dialog_GetIntProperty(dlg, "wiz_app_combo", GWEN_DialogProperty_Value, 0, -1);
1314 if (idx>0) {
1315 const AO_APPINFO *ai;
1316
1317 ai=AO_Provider_GetAppInfos(xdlg->provider);
1318 if (ai) {
1319 while (ai->appName && --idx) {
1320 ai++;
1321 }
1322 if (ai->appName) {
1323 if (ai->appId)
1324 GWEN_Dialog_SetCharProperty(dlg, "wiz_appid_edit", GWEN_DialogProperty_Value, 0, ai->appId, 0);
1325 if (ai->appVer)
1326 GWEN_Dialog_SetCharProperty(dlg, "wiz_appver_edit", GWEN_DialogProperty_Value, 0, ai->appVer, 0);
1327 }
1328 }
1329 }
1330
1331 return GWEN_DialogEvent_ResultHandled;
1332 }
1333
1334
1335
AO_NewUserDialog_HandleActivatedGetAccounts(GWEN_DIALOG * dlg)1336 int AO_NewUserDialog_HandleActivatedGetAccounts(GWEN_DIALOG *dlg)
1337 {
1338 AO_NEWUSER_DIALOG *xdlg;
1339 int rv;
1340
1341 assert(dlg);
1342 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
1343 assert(xdlg);
1344
1345 rv=AO_Provider_RequestAccounts(xdlg->provider, xdlg->user, 1);
1346 if (rv<0) {
1347 DBG_INFO(AQOFXCONNECT_LOGDOMAIN, "here");
1348 }
1349
1350 return GWEN_DialogEvent_ResultHandled;
1351 }
1352
1353
1354
1355
AO_NewUserDialog_HandleActivated(GWEN_DIALOG * dlg,const char * sender)1356 int AO_NewUserDialog_HandleActivated(GWEN_DIALOG *dlg, const char *sender)
1357 {
1358 DBG_ERROR(0, "Activated: %s", sender);
1359 if (strcasecmp(sender, "wiz_prev_button")==0)
1360 return AO_NewUserDialog_Previous(dlg);
1361 else if (strcasecmp(sender, "wiz_next_button")==0)
1362 return AO_NewUserDialog_Next(dlg);
1363 else if (strcasecmp(sender, "wiz_abort_button")==0) {
1364 AO_NewUserDialog_UndoIt(dlg);
1365 return GWEN_DialogEvent_ResultReject;
1366 }
1367 else if (strcasecmp(sender, "wiz_bank_button")==0)
1368 return AO_NewUserDialog_HandleActivatedBankSelect(dlg);
1369 else if (strcasecmp(sender, "wiz_app_combo")==0)
1370 return AO_NewUserDialog_HandleActivatedApp(dlg);
1371 else if (strcasecmp(sender, "wiz_special_button")==0)
1372 return AO_NewUserDialog_HandleActivatedSpecial(dlg);
1373 else if (strcasecmp(sender, "wiz_getaccounts_button")==0)
1374 return AO_NewUserDialog_HandleActivatedGetAccounts(dlg);
1375 else if (strcasecmp(sender, "wiz_help_button")==0) {
1376 /* TODO: open a help dialog */
1377 }
1378
1379 return GWEN_DialogEvent_ResultNotHandled;
1380 }
1381
1382
1383
AO_NewUserDialog_HandleValueChanged(GWEN_DIALOG * dlg,const char * sender)1384 int AO_NewUserDialog_HandleValueChanged(GWEN_DIALOG *dlg, const char *sender)
1385 {
1386 if (strcasecmp(sender, "wiz_username_edit")==0 ||
1387 strcasecmp(sender, "wiz_userid_edit")==0 ||
1388 strcasecmp(sender, "wiz_url_edit")==0 ||
1389 strcasecmp(sender, "wiz_brokerid_edit")==0 ||
1390 strcasecmp(sender, "wiz_fid_edit")==0 ||
1391 strcasecmp(sender, "wiz_org_edit")==0 ||
1392 strcasecmp(sender, "wiz_appid_edit")==0 ||
1393 strcasecmp(sender, "wiz_appver_edit")==0 ||
1394 strcasecmp(sender, "wiz_headerver_edit")==0) {
1395 int rv;
1396
1397 if (GWEN_Dialog_GetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, -1)==PAGE_BANK) {
1398 rv=AO_NewUserDialog_GetBankPageData(dlg);
1399 if (rv<0)
1400 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
1401 else
1402 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
1403 }
1404 else if (GWEN_Dialog_GetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, -1)==PAGE_USER) {
1405 rv=AO_NewUserDialog_GetUserPageData(dlg);
1406 if (rv<0)
1407 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
1408 else
1409 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
1410 }
1411 else if (GWEN_Dialog_GetIntProperty(dlg, "wiz_stack", GWEN_DialogProperty_Value, 0, -1)==PAGE_APP) {
1412 rv=AO_NewUserDialog_GetAppPageData(dlg);
1413 if (rv<0)
1414 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 0, 0);
1415 else
1416 GWEN_Dialog_SetIntProperty(dlg, "wiz_next_button", GWEN_DialogProperty_Enabled, 0, 1, 0);
1417 }
1418 return GWEN_DialogEvent_ResultHandled;
1419 }
1420 return GWEN_DialogEvent_ResultNotHandled;
1421 }
1422
1423
1424
AO_NewUserDialog_SignalHandler(GWEN_DIALOG * dlg,GWEN_DIALOG_EVENTTYPE t,const char * sender)1425 int GWENHYWFAR_CB AO_NewUserDialog_SignalHandler(GWEN_DIALOG *dlg,
1426 GWEN_DIALOG_EVENTTYPE t,
1427 const char *sender)
1428 {
1429 AO_NEWUSER_DIALOG *xdlg;
1430
1431 assert(dlg);
1432 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AO_NEWUSER_DIALOG, dlg);
1433 assert(xdlg);
1434
1435 switch (t) {
1436 case GWEN_DialogEvent_TypeInit:
1437 AO_NewUserDialog_Init(dlg);
1438 return GWEN_DialogEvent_ResultHandled;;
1439
1440 case GWEN_DialogEvent_TypeFini:
1441 AO_NewUserDialog_Fini(dlg);
1442 return GWEN_DialogEvent_ResultHandled;;
1443
1444 case GWEN_DialogEvent_TypeValueChanged:
1445 return AO_NewUserDialog_HandleValueChanged(dlg, sender);
1446
1447 case GWEN_DialogEvent_TypeActivated:
1448 return AO_NewUserDialog_HandleActivated(dlg, sender);
1449
1450 case GWEN_DialogEvent_TypeEnabled:
1451 case GWEN_DialogEvent_TypeDisabled:
1452 case GWEN_DialogEvent_TypeClose:
1453
1454 case GWEN_DialogEvent_TypeLast:
1455 return GWEN_DialogEvent_ResultNotHandled;
1456
1457 }
1458
1459 return GWEN_DialogEvent_ResultNotHandled;
1460 }
1461
1462
1463
1464
1465