Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

aqbanking / src / libs / plugins / backends / aqhbci / dialogs / dlg_editaccount.c @ 5bc3f3e7

History | View | Annotate | Download (21.3 KB)

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 "i18n_l.h"
19
#include "provider_l.h"
20

    
21
#include <aqhbci/account.h>
22
#include <aqhbci/provider.h>
23
#include <aqbanking/account.h>
24
#include <aqbanking/banking_be.h>
25
#include <aqbanking/dlg_selectbankinfo.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/text.h>
33

    
34

    
35
#define DIALOG_MINWIDTH  400
36
#define DIALOG_MINHEIGHT 300
37

    
38
#define USER_LIST_MINCOLWIDTH 50
39

    
40

    
41

    
42
GWEN_INHERIT(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG)
43

    
44

    
45

    
46

    
47
GWEN_DIALOG *AH_EditAccountDialog_new(AB_PROVIDER *pro, AB_ACCOUNT *a, int doLock) {
48
  GWEN_DIALOG *dlg;
49
  AH_EDIT_ACCOUNT_DIALOG *xdlg;
50
  GWEN_BUFFER *fbuf;
51
  int rv;
52

    
53
  dlg=GWEN_Dialog_new("ah_edit_account");
54
  GWEN_NEW_OBJECT(AH_EDIT_ACCOUNT_DIALOG, xdlg);
55
  GWEN_INHERIT_SETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg, xdlg,
56
                       AH_EditAccountDialog_FreeData);
57
  GWEN_Dialog_SetSignalHandler(dlg, AH_EditAccountDialog_SignalHandler);
58

    
59
  /* get path of dialog description file */
60
  fbuf=GWEN_Buffer_new(0, 256, 0, 1);
61
  rv=GWEN_PathManager_FindFile(AB_PM_LIBNAME, AB_PM_DATADIR,
62
                               "aqbanking/backends/aqhbci//dialogs/dlg_editaccount.dlg",
63
                               fbuf);
64
  if (rv<0) {
65
    DBG_INFO(AQBANKING_LOGDOMAIN, "Dialog description file not found (%d).", rv);
66
    GWEN_Buffer_free(fbuf);
67
    GWEN_Dialog_free(dlg);
68
    return NULL;
69
  }
70

    
71
  /* read dialog from dialog description file */
72
  rv=GWEN_Dialog_ReadXmlFile(dlg, GWEN_Buffer_GetStart(fbuf));
73
  if (rv<0) {
74
    DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d).", rv);
75
    GWEN_Buffer_free(fbuf);
76
    GWEN_Dialog_free(dlg);
77
    return NULL;
78
  }
79
  GWEN_Buffer_free(fbuf);
80

    
81
  xdlg->provider=pro;
82
  xdlg->banking=AB_Provider_GetBanking(pro);
83
  xdlg->account=a;
84
  xdlg->doLock=doLock;
85

    
86
  /* done */
87
  return dlg;
88
}
89

    
90

    
91

    
92
void GWENHYWFAR_CB AH_EditAccountDialog_FreeData(void *bp, void *p) {
93
  AH_EDIT_ACCOUNT_DIALOG *xdlg;
94

    
95
  xdlg=(AH_EDIT_ACCOUNT_DIALOG*) p;
96
  GWEN_FREE_OBJECT(xdlg);
97
}
98

    
99

    
100

    
101
static void createUserString(const AB_USER *u, GWEN_BUFFER *tbuf) {
102
  const char *s;
103
  char numbuf[32];
104
  uint32_t uid;
105
  
106
  /* column 1 */
107
  uid=AB_User_GetUniqueId(u);
108
  snprintf(numbuf, sizeof(numbuf)-1, "%d", uid);
109
  numbuf[sizeof(numbuf)-1]=0;
110

    
111
  s=AB_User_GetUserName(u);
112
  if (s && *s)
113
    GWEN_Buffer_AppendString(tbuf, s);
114
  GWEN_Buffer_AppendString(tbuf, "-");
115

    
116
  s=AB_User_GetBankCode(u);
117
  if (s && *s)
118
    GWEN_Buffer_AppendString(tbuf, s);
119
  GWEN_Buffer_AppendString(tbuf, "-");
120
  
121
  s=AB_User_GetCustomerId(u);
122
  if (!(s && *s))
123
    s=AB_User_GetUserId(u);
124
  if (s && *s)
125
    GWEN_Buffer_AppendString(tbuf, s);
126

    
127
  GWEN_Buffer_AppendString(tbuf, " (");
128
  GWEN_Buffer_AppendString(tbuf, numbuf);
129
  GWEN_Buffer_AppendString(tbuf, ")");
130

    
131
}
132

    
133

    
134

    
135
uint32_t AH_EditAccountDialog_GetCurrentUserId(GWEN_DIALOG *dlg) {
136
  int idx;
137

    
138
  idx=GWEN_Dialog_GetIntProperty(dlg, "userCombo",  GWEN_DialogProperty_Value, 0, -1);
139
  if (idx>=0) {
140
    const char *currentText;
141

    
142
    currentText=GWEN_Dialog_GetCharProperty(dlg, "userCombo", GWEN_DialogProperty_Value, idx, NULL);
143
    if (currentText && *currentText) {
144
      unsigned long int id;
145

    
146
      if (sscanf(currentText, "%lu", &id)==1) {
147
        return (uint32_t) id;
148
      }
149
    }
150
  }
151

    
152
  return 0;
153
}
154

    
155

    
156

    
157
int AH_EditAccountDialog_FindUserEntry(GWEN_DIALOG *dlg, uint32_t userId) {
158
  AH_EDIT_ACCOUNT_DIALOG *xdlg;
159
  int i;
160
  int num;
161

    
162
  assert(dlg);
163
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
164
  assert(xdlg);
165

    
166
  /* user list */
167
  num=GWEN_Dialog_GetIntProperty(dlg, "userCombo", GWEN_DialogProperty_ValueCount, 0, 0);
168
  for (i=0; i<num; i++) {
169
    const char *t;
170

    
171
    t=GWEN_Dialog_GetCharProperty(dlg, "userCombo", GWEN_DialogProperty_Value, i, NULL);
172
    if (t && *t) {
173
      unsigned long int id;
174

    
175
      if (sscanf(t, "%lu", &id)==1) {
176
        return i;
177
      }
178
    }
179
  } /* for i */
180

    
181
  return -1;
182
}
183

    
184

    
185

    
186
void AH_EditAccountDialog_RebuildUserLists(GWEN_DIALOG *dlg) {
187
  AH_EDIT_ACCOUNT_DIALOG *xdlg;
188
  AB_USER_LIST *users;
189
  GWEN_STRINGLIST *sl;
190
  int rv;
191

    
192
  assert(dlg);
193
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
194
  assert(xdlg);
195

    
196
  GWEN_Dialog_SetIntProperty(dlg, "userCombo", GWEN_DialogProperty_ClearValues, 0, 0, 0);
197
  GWEN_Dialog_SetCharProperty(dlg,
198
                              "userCombo",
199
                              GWEN_DialogProperty_AddValue,
200
                              0,
201
                              I18N("-- select --"),
202
                              0);
203

    
204
  /* setup lists of available and selected users */
205
  sl=GWEN_StringList_new();
206
  users=AB_User_List_new();
207
  rv=AB_Provider_ReadUsers(xdlg->provider, users);
208
  if (rv<0) {
209

    
210
  }
211
  else {
212
    GWEN_BUFFER *tbuf;
213
    AB_USER *u;
214

    
215
    tbuf=GWEN_Buffer_new(0, 256, 0, 1);
216

    
217
    u=AB_User_List_First(users);
218
    while(u) {
219
      createUserString(u, tbuf);
220
      GWEN_StringList_AppendString(sl, GWEN_Buffer_GetStart(tbuf), 0, 1);
221
      GWEN_Buffer_Reset(tbuf);
222
      u=AB_User_List_Next(u);
223
    }
224
    GWEN_Buffer_free(tbuf);
225
  }
226
  AB_User_List_free(users);
227

    
228
  if (GWEN_StringList_Count(sl)) {
229
    GWEN_STRINGLISTENTRY *se;
230

    
231
    /* sort user list */
232
    GWEN_StringList_Sort(sl, 1, GWEN_StringList_SortModeNoCase);
233
    se=GWEN_StringList_FirstEntry(sl);
234
    while(se) {
235
      const char *s;
236

    
237
      s=GWEN_StringListEntry_Data(se);
238
      if (s && *s)
239
        GWEN_Dialog_SetCharProperty(dlg,
240
                                    "userCombo",
241
                                    GWEN_DialogProperty_AddValue,
242
                                    0,
243
                                    s,
244
                                    0);
245
      se=GWEN_StringListEntry_Next(se);
246
    }
247
  }
248
  GWEN_StringList_free(sl);
249
}
250

    
251

    
252

    
253
void AH_EditAccountDialog_Init(GWEN_DIALOG *dlg) {
254
  AH_EDIT_ACCOUNT_DIALOG *xdlg;
255
  GWEN_DB_NODE *dbPrefs;
256
  int i;
257
  const char *s;
258
  AB_ACCOUNT_TYPE t;
259
  uint32_t aflags;
260
  uint32_t uid;
261

    
262
  assert(dlg);
263
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
264
  assert(xdlg);
265

    
266
  dbPrefs=GWEN_Dialog_GetPreferences(dlg);
267

    
268
  /* init */
269
  GWEN_Dialog_SetCharProperty(dlg,
270
                              "",
271
                              GWEN_DialogProperty_Title,
272
                              0,
273
                              I18N("Edit Account"),
274
                              0);
275

    
276
  s=AB_Account_GetBankCode(xdlg->account);
277
  GWEN_Dialog_SetCharProperty(dlg, "bankCodeEdit", GWEN_DialogProperty_Value, 0, s, 0);
278

    
279
  s=AB_Account_GetBankName(xdlg->account);
280
  GWEN_Dialog_SetCharProperty(dlg, "bankNameEdit", GWEN_DialogProperty_Value, 0, s, 0);
281

    
282
  s=AB_Account_GetBic(xdlg->account);
283
  GWEN_Dialog_SetCharProperty(dlg, "bicEdit", GWEN_DialogProperty_Value, 0, s, 0);
284

    
285
  s=AB_Account_GetAccountNumber(xdlg->account);
286
  GWEN_Dialog_SetCharProperty(dlg, "accountNumberEdit", GWEN_DialogProperty_Value, 0, s, 0);
287

    
288
  s=AB_Account_GetAccountName(xdlg->account);
289
  GWEN_Dialog_SetCharProperty(dlg, "accountNameEdit", GWEN_DialogProperty_Value, 0, s, 0);
290

    
291
  s=AB_Account_GetIban(xdlg->account);
292
  GWEN_Dialog_SetCharProperty(dlg, "ibanEdit", GWEN_DialogProperty_Value, 0, s, 0);
293

    
294
  s=AB_Account_GetOwnerName(xdlg->account);
295
  GWEN_Dialog_SetCharProperty(dlg, "ownerNameEdit", GWEN_DialogProperty_Value, 0, s, 0);
296

    
297
  s=AB_Account_GetCurrency(xdlg->account);
298
  GWEN_Dialog_SetCharProperty(dlg, "currencyEdit", GWEN_DialogProperty_Value, 0, s, 0);
299

    
300
  s=AB_Account_GetCountry(xdlg->account);
301
  GWEN_Dialog_SetCharProperty(dlg, "countryEdit", GWEN_DialogProperty_Value, 0, s, 0);
302

    
303
  /* setup account type */
304
  GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
305
                              I18N("unknown"),
306
                              0);
307
  GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
308
                              I18N("Bank Account"),
309
                              0);
310
  GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
311
                              I18N("Credit Card Account"),
312
                              0);
313
  GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
314
                              I18N("Checking Account"),
315
                              0);
316
  GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
317
                              I18N("Savings Account"),
318
                              0);
319
  GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
320
                              I18N("Investment Account"),
321
                              0);
322
  GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
323
                              I18N("Cash Account"),
324
                              0);
325
  GWEN_Dialog_SetCharProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_AddValue, 0,
326
                              I18N("Moneymarket Account"),
327
                              0);
328

    
329
  t=AB_Account_GetAccountType(xdlg->account);
330
  if (t<AB_AccountType_MoneyMarket)
331
    GWEN_Dialog_SetIntProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_Value, 0, t, 0);
332

    
333
  AH_EditAccountDialog_RebuildUserLists(dlg);
334
  uid=AB_Account_GetUserId(xdlg->account);
335
  if (uid) {
336
    int idx;
337

    
338
    idx=AH_EditAccountDialog_FindUserEntry(dlg, uid);
339
    if (idx>=0)
340
      GWEN_Dialog_SetIntProperty(dlg, "userCombo", GWEN_DialogProperty_Value, 0, idx, 0);
341
  }
342

    
343
  /* setup flags */
344
  aflags=AH_Account_GetFlags(xdlg->account);
345
  GWEN_Dialog_SetIntProperty(dlg, "preferSingleTransferCheck", GWEN_DialogProperty_Value, 0,
346
                             (aflags & AH_BANK_FLAGS_PREFER_SINGLE_TRANSFER)?1:0,
347
                             0);
348
  GWEN_Dialog_SetIntProperty(dlg, "preferSingleDebitNoteCheck", GWEN_DialogProperty_Value, 0,
349
                             (aflags & AH_BANK_FLAGS_PREFER_SINGLE_DEBITNOTE)?1:0,
350
                             0);
351

    
352
  GWEN_Dialog_SetIntProperty(dlg, "sepaPreferSingleTransferCheck", GWEN_DialogProperty_Value, 0,
353
                             (aflags & AH_BANK_FLAGS_SEPA_PREFER_SINGLE_TRANSFER)?1:0,
354
                             0);
355
  GWEN_Dialog_SetIntProperty(dlg, "sepaPreferSingleDebitNoteCheck", GWEN_DialogProperty_Value, 0,
356
                             (aflags & AH_BANK_FLAGS_SEPA_PREFER_SINGLE_DEBITNOTE)?1:0,
357
                             0);
358

    
359

    
360
  /* read width */
361
  i=GWEN_DB_GetIntValue(dbPrefs, "dialog_width", 0, -1);
362
  if (i>=DIALOG_MINWIDTH)
363
    GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, i, 0);
364

    
365
  /* read height */
366
  i=GWEN_DB_GetIntValue(dbPrefs, "dialog_height", 0, -1);
367
  if (i>=DIALOG_MINHEIGHT)
368
    GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, i, 0);
369
}
370

    
371

    
372

    
373
static void removeAllSpaces(uint8_t *s) {
374
  uint8_t *d;
375

    
376
  d=s;
377
  while(*s) {
378
    if (*s>33)
379
      *(d++)=*s;
380
    s++;
381
  }
382
  *d=0;
383
}
384

    
385

    
386

    
387
int AH_EditAccountDialog_fromGui(GWEN_DIALOG *dlg, AB_ACCOUNT *a, int quiet) {
388
  AH_EDIT_ACCOUNT_DIALOG *xdlg;
389
  int i;
390
  const char *s;
391
  uint32_t aflags=0;
392

    
393
  assert(dlg);
394
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
395
  assert(xdlg);
396

    
397
  /* fromGui */
398
  s=GWEN_Dialog_GetCharProperty(dlg, "accountNumberEdit", GWEN_DialogProperty_Value, 0, NULL);
399
  if (s && *s) {
400
    GWEN_BUFFER *tbuf;
401

    
402
    tbuf=GWEN_Buffer_new(0, 256, 0, 1);
403
    GWEN_Buffer_AppendString(tbuf, s);
404
    GWEN_Text_CondenseBuffer(tbuf);
405
    removeAllSpaces((uint8_t*)GWEN_Buffer_GetStart(tbuf));
406
    if (a)
407
      AB_Account_SetAccountNumber(a, GWEN_Buffer_GetStart(tbuf));
408
    GWEN_Buffer_free(tbuf);
409
  }
410

    
411
  s=GWEN_Dialog_GetCharProperty(dlg, "accountNameEdit", GWEN_DialogProperty_Value, 0, NULL);
412
  if (s && *s) {
413
    GWEN_BUFFER *tbuf;
414

    
415
    tbuf=GWEN_Buffer_new(0, 256, 0, 1);
416
    GWEN_Buffer_AppendString(tbuf, s);
417
    GWEN_Text_CondenseBuffer(tbuf);
418
    if (a)
419
      AB_Account_SetAccountName(a, GWEN_Buffer_GetStart(tbuf));
420
    GWEN_Buffer_free(tbuf);
421
  }
422

    
423
  s=GWEN_Dialog_GetCharProperty(dlg, "ibanEdit", GWEN_DialogProperty_Value, 0, NULL);
424
  if (s && *s) {
425
    GWEN_BUFFER *tbuf;
426

    
427
    tbuf=GWEN_Buffer_new(0, 256, 0, 1);
428
    GWEN_Buffer_AppendString(tbuf, s);
429
    GWEN_Text_CondenseBuffer(tbuf);
430
    removeAllSpaces((uint8_t*)GWEN_Buffer_GetStart(tbuf));
431
    if (a)
432
      AB_Account_SetIban(a, GWEN_Buffer_GetStart(tbuf));
433
    GWEN_Buffer_free(tbuf);
434
  }
435

    
436
  s=GWEN_Dialog_GetCharProperty(dlg, "ownerNameEdit", GWEN_DialogProperty_Value, 0, NULL);
437
  if (s && *s) {
438
    GWEN_BUFFER *tbuf;
439

    
440
    tbuf=GWEN_Buffer_new(0, 256, 0, 1);
441
    GWEN_Buffer_AppendString(tbuf, s);
442
    GWEN_Text_CondenseBuffer(tbuf);
443
    if (a)
444
      AB_Account_SetOwnerName(a, GWEN_Buffer_GetStart(tbuf));
445
    GWEN_Buffer_free(tbuf);
446
  }
447

    
448
  /* get currency */
449
  s=GWEN_Dialog_GetCharProperty(dlg, "currencyEdit", GWEN_DialogProperty_Value, 0, NULL);
450
  if (a && s && *s)
451
    AB_Account_SetCurrency(a, s);
452

    
453
  i=GWEN_Dialog_GetIntProperty(dlg, "accountTypeCombo", GWEN_DialogProperty_Value, 0, 0);
454
  if (a)
455
    AB_Account_SetAccountType(a, i);
456

    
457
  /*  get country */
458
  s=GWEN_Dialog_GetCharProperty(dlg, "countryEdit", GWEN_DialogProperty_Value, 0, NULL);
459
  if (a && s && *s)
460
    AB_Account_SetCountry(a, s);
461

    
462
  s=GWEN_Dialog_GetCharProperty(dlg, "bankCodeEdit", GWEN_DialogProperty_Value, 0, NULL);
463
  if (s && *s) {
464
    GWEN_BUFFER *tbuf;
465

    
466
    tbuf=GWEN_Buffer_new(0, 256, 0, 1);
467
    GWEN_Buffer_AppendString(tbuf, s);
468
    GWEN_Text_CondenseBuffer(tbuf);
469
    removeAllSpaces((uint8_t*)GWEN_Buffer_GetStart(tbuf));
470
    if (a)
471
      AB_Account_SetBankCode(a, GWEN_Buffer_GetStart(tbuf));
472
    GWEN_Buffer_free(tbuf);
473
  }
474

    
475
  s=GWEN_Dialog_GetCharProperty(dlg, "bankNameEdit", GWEN_DialogProperty_Value, 0, NULL);
476
  if (s && *s) {
477
    GWEN_BUFFER *tbuf;
478

    
479
    tbuf=GWEN_Buffer_new(0, 256, 0, 1);
480
    GWEN_Buffer_AppendString(tbuf, s);
481
    GWEN_Text_CondenseBuffer(tbuf);
482
    if (a)
483
      AB_Account_SetBankName(a, GWEN_Buffer_GetStart(tbuf));
484
    GWEN_Buffer_free(tbuf);
485
  }
486

    
487
  s=GWEN_Dialog_GetCharProperty(dlg, "bicEdit", GWEN_DialogProperty_Value, 0, NULL);
488
  if (s && *s) {
489
    GWEN_BUFFER *tbuf;
490

    
491
    tbuf=GWEN_Buffer_new(0, 256, 0, 1);
492
    GWEN_Buffer_AppendString(tbuf, s);
493
    GWEN_Text_CondenseBuffer(tbuf);
494
    removeAllSpaces((uint8_t*)GWEN_Buffer_GetStart(tbuf));
495
    if (a)
496
      AB_Account_SetBic(a, GWEN_Buffer_GetStart(tbuf));
497
    GWEN_Buffer_free(tbuf);
498
  }
499

    
500
  aflags=0;
501
  if (GWEN_Dialog_GetIntProperty(dlg, "preferSingleTransferCheck", GWEN_DialogProperty_Value, 0, 0))
502
    aflags|=AH_BANK_FLAGS_PREFER_SINGLE_TRANSFER;
503
  if (GWEN_Dialog_GetIntProperty(dlg, "preferSingleDebitNoteCheck", GWEN_DialogProperty_Value, 0, 0))
504
    aflags|=AH_BANK_FLAGS_PREFER_SINGLE_DEBITNOTE;
505
  if (GWEN_Dialog_GetIntProperty(dlg, "sepaPreferSingleTransferCheck", GWEN_DialogProperty_Value, 0, 0))
506
    aflags|=AH_BANK_FLAGS_SEPA_PREFER_SINGLE_TRANSFER;
507
  if (GWEN_Dialog_GetIntProperty(dlg, "sepaPreferSingleDebitNoteCheck", GWEN_DialogProperty_Value, 0, 0))
508
    aflags|=AH_BANK_FLAGS_SEPA_PREFER_SINGLE_DEBITNOTE;
509
  if (a)
510
    AH_Account_SetFlags(a, aflags);
511

    
512
  if (a) {
513
    uint32_t uid;
514

    
515
    uid=AH_EditAccountDialog_GetCurrentUserId(dlg);
516
    if (uid)
517
      AB_Account_SetUserId(a, uid);
518
    else {
519
      DBG_ERROR(AQHBCI_LOGDOMAIN, "No user selected.");
520
      return GWEN_ERROR_INVALID;
521
    }
522
  }
523

    
524
  return 0;
525
}
526

    
527

    
528

    
529
void AH_EditAccountDialog_Fini(GWEN_DIALOG *dlg) {
530
  AH_EDIT_ACCOUNT_DIALOG *xdlg;
531
  int i;
532
  GWEN_DB_NODE *dbPrefs;
533

    
534
  assert(dlg);
535
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
536
  assert(xdlg);
537

    
538
  dbPrefs=GWEN_Dialog_GetPreferences(dlg);
539

    
540
  /* store dialog width */
541
  i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, -1);
542
  GWEN_DB_SetIntValue(dbPrefs,
543
                      GWEN_DB_FLAGS_OVERWRITE_VARS,
544
                      "dialog_width",
545
                      i);
546

    
547
  /* store dialog height */
548
  i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, -1);
549
  GWEN_DB_SetIntValue(dbPrefs,
550
                      GWEN_DB_FLAGS_OVERWRITE_VARS,
551
                      "dialog_height",
552
                      i);
553
}
554

    
555

    
556

    
557
int AH_EditAccountDialog_HandleActivatedBankCode(GWEN_DIALOG *dlg) {
558
  AH_EDIT_ACCOUNT_DIALOG *xdlg;
559
  GWEN_DIALOG *dlg2;
560
  int rv;
561

    
562
  assert(dlg);
563
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
564
  assert(xdlg);
565

    
566
  dlg2=AB_SelectBankInfoDialog_new(xdlg->banking, "de", NULL);
567
  if (dlg2==NULL) {
568
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Could not create dialog");
569
    return GWEN_DialogEvent_ResultHandled;
570
  }
571

    
572
  rv=GWEN_Gui_ExecDialog(dlg2, 0);
573
  if (rv==0) {
574
    /* rejected */
575
    GWEN_Dialog_free(dlg2);
576
    return GWEN_DialogEvent_ResultHandled;
577
  }
578
  else {
579
    const AB_BANKINFO *bi;
580

    
581
    bi=AB_SelectBankInfoDialog_GetSelectedBankInfo(dlg2);
582
    if (bi) {
583
      const char *s;
584

    
585
      s=AB_BankInfo_GetBankId(bi);
586
      GWEN_Dialog_SetCharProperty(dlg,
587
                                  "bankCodeEdit",
588
                                  GWEN_DialogProperty_Value,
589
                                  0,
590
                                  (s && *s)?s:"",
591
                                  0);
592

    
593
      s=AB_BankInfo_GetBankName(bi);
594
      GWEN_Dialog_SetCharProperty(dlg,
595
                                  "bankNameEdit",
596
                                  GWEN_DialogProperty_Value,
597
                                  0,
598
                                  (s && *s)?s:"",
599
                                  0);
600

    
601
      s=AB_BankInfo_GetBic(bi);
602
      GWEN_Dialog_SetCharProperty(dlg,
603
                                  "bicEdit",
604
                                  GWEN_DialogProperty_Value,
605
                                  0,
606
                                  (s && *s)?s:"",
607
                                  0);
608
    }
609
  }
610
  GWEN_Dialog_free(dlg2);
611

    
612
  return GWEN_DialogEvent_ResultHandled;
613
}
614

    
615

    
616

    
617
int AH_EditAccountDialog_HandleActivatedOk(GWEN_DIALOG *dlg) {
618
  AH_EDIT_ACCOUNT_DIALOG *xdlg;
619
  int rv;
620

    
621
  assert(dlg);
622
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
623
  assert(xdlg);
624

    
625
  rv=AH_EditAccountDialog_fromGui(dlg, NULL, 0);
626
  if (rv<0) {
627
    return GWEN_DialogEvent_ResultHandled;
628
  }
629

    
630
  if (xdlg->doLock) {
631
    int rv;
632

    
633
    rv=AB_Provider_BeginExclUseAccount(xdlg->provider, xdlg->account);
634
    if (rv<0) {
635
      DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d)", rv);
636
      GWEN_Gui_MessageBox(GWEN_GUI_MSG_FLAGS_SEVERITY_NORMAL |
637
                          GWEN_GUI_MSG_FLAGS_TYPE_ERROR |
638
                          GWEN_GUI_MSG_FLAGS_CONFIRM_B1,
639
                          I18N("Error"),
640
                          I18N("Unable to lock account. Maybe already in use?"),
641
                          I18N("Dismiss"),
642
                          NULL,
643
                          NULL,
644
                          0);
645
      return GWEN_DialogEvent_ResultHandled;
646
    }
647
  }
648

    
649
  AH_EditAccountDialog_fromGui(dlg, xdlg->account, 1);
650

    
651
  if (xdlg->doLock) {
652
    int rv;
653

    
654
    rv=AB_Provider_EndExclUseAccount(xdlg->provider, xdlg->account, 0);
655
    if (rv<0) {
656
      DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d)", rv);
657
      GWEN_Gui_MessageBox(GWEN_GUI_MSG_FLAGS_SEVERITY_NORMAL |
658
                          GWEN_GUI_MSG_FLAGS_TYPE_ERROR |
659
                          GWEN_GUI_MSG_FLAGS_CONFIRM_B1,
660
                          I18N("Error"),
661
                          I18N("Unable to unlock account."),
662
                          I18N("Dismiss"),
663
                          NULL,
664
                          NULL,
665
                          0);
666
      AB_Provider_EndExclUseAccount(xdlg->provider, xdlg->account, 1);
667
      return GWEN_DialogEvent_ResultHandled;
668
    }
669
  }
670

    
671
  return GWEN_DialogEvent_ResultAccept;
672
}
673

    
674

    
675

    
676
int AH_EditAccountDialog_HandleActivatedSepa(GWEN_DIALOG *dlg) {
677
  AH_EDIT_ACCOUNT_DIALOG *xdlg;
678
  int rv;
679
  AB_IMEXPORTER_CONTEXT *ctx;
680

    
681
  assert(dlg);
682
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
683
  assert(xdlg);
684

    
685
  ctx=AB_ImExporterContext_new();
686
  rv=AH_Provider_GetAccountSepaInfo(xdlg->provider,
687
                                    xdlg->account,
688
                                    ctx,
689
                                    1,   /* withProgress */
690
                                    0,   /* nounmount */
691
                                    xdlg->doLock);
692
  AB_ImExporterContext_free(ctx);
693
  if (rv<0) {
694
    DBG_INFO(AQHBCI_LOGDOMAIN, "here (%d)", rv);
695
  }
696
  else {
697
    const char *s;
698

    
699
    /* update dialog */
700
    s=AB_Account_GetBankCode(xdlg->account);
701
    GWEN_Dialog_SetCharProperty(dlg, "bankCodeEdit", GWEN_DialogProperty_Value, 0, s, 0);
702

    
703
    s=AB_Account_GetBankName(xdlg->account);
704
    GWEN_Dialog_SetCharProperty(dlg, "bankNameEdit", GWEN_DialogProperty_Value, 0, s, 0);
705

    
706
    s=AB_Account_GetBic(xdlg->account);
707
    GWEN_Dialog_SetCharProperty(dlg, "bicEdit", GWEN_DialogProperty_Value, 0, s, 0);
708

    
709
    s=AB_Account_GetAccountNumber(xdlg->account);
710
    GWEN_Dialog_SetCharProperty(dlg, "accountNumberEdit", GWEN_DialogProperty_Value, 0, s, 0);
711

    
712
    s=AB_Account_GetAccountName(xdlg->account);
713
    GWEN_Dialog_SetCharProperty(dlg, "accountNameEdit", GWEN_DialogProperty_Value, 0, s, 0);
714

    
715
    s=AB_Account_GetIban(xdlg->account);
716
    GWEN_Dialog_SetCharProperty(dlg, "ibanEdit", GWEN_DialogProperty_Value, 0, s, 0);
717

    
718
    s=AB_Account_GetOwnerName(xdlg->account);
719
    GWEN_Dialog_SetCharProperty(dlg, "ownerNameEdit", GWEN_DialogProperty_Value, 0, s, 0);
720
  }
721

    
722
  return GWEN_DialogEvent_ResultHandled;
723
}
724

    
725

    
726

    
727
int AH_EditAccountDialog_HandleActivated(GWEN_DIALOG *dlg, const char *sender) {
728
  if (strcasecmp(sender, "bankCodeButton")==0)
729
    return AH_EditAccountDialog_HandleActivatedBankCode(dlg);
730
  else if (strcasecmp(sender, "getSepaButton")==0)
731
    return AH_EditAccountDialog_HandleActivatedSepa(dlg);
732
  else if (strcasecmp(sender, "okButton")==0)
733
    return AH_EditAccountDialog_HandleActivatedOk(dlg);
734
  else if (strcasecmp(sender, "abortButton")==0)
735
    return GWEN_DialogEvent_ResultReject;
736
  else if (strcasecmp(sender, "helpButton")==0) {
737
    /* TODO: open a help dialog */
738
  }
739

    
740
  return GWEN_DialogEvent_ResultNotHandled;
741
}
742

    
743

    
744

    
745
int GWENHYWFAR_CB AH_EditAccountDialog_SignalHandler(GWEN_DIALOG *dlg,
746
                                                     GWEN_DIALOG_EVENTTYPE t,
747
                                                     const char *sender) {
748
  AH_EDIT_ACCOUNT_DIALOG *xdlg;
749

    
750
  assert(dlg);
751
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AH_EDIT_ACCOUNT_DIALOG, dlg);
752
  assert(xdlg);
753

    
754
  switch(t) {
755
  case GWEN_DialogEvent_TypeInit:
756
    AH_EditAccountDialog_Init(dlg);
757
    return GWEN_DialogEvent_ResultHandled;;
758

    
759
  case GWEN_DialogEvent_TypeFini:
760
    AH_EditAccountDialog_Fini(dlg);
761
    return GWEN_DialogEvent_ResultHandled;;
762

    
763
  case GWEN_DialogEvent_TypeValueChanged:
764
    DBG_NOTICE(0, "ValueChanged: %s", sender);
765
    return GWEN_DialogEvent_ResultHandled;;
766

    
767
  case GWEN_DialogEvent_TypeActivated:
768
    return AH_EditAccountDialog_HandleActivated(dlg, sender);
769

    
770
  case GWEN_DialogEvent_TypeEnabled:
771
  case GWEN_DialogEvent_TypeDisabled:
772
  case GWEN_DialogEvent_TypeClose:
773

    
774
  case GWEN_DialogEvent_TypeLast:
775
    return GWEN_DialogEvent_ResultNotHandled;
776

    
777
  }
778

    
779
  return GWEN_DialogEvent_ResultNotHandled;
780
}
781

    
782

    
783

    
784

    
785

    
786