Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

aqbanking / src / libs / plugins / backends / aqpaypal / dlg_edituser.c @ 5bc3f3e7

History | View | Annotate | Download (17.3 KB)

1
/***************************************************************************
2
 begin       : Tue Aug 03 2010
3
 copyright   : (C) 2010 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 "provider_l.h"
18
#include "dlg_edituser_p.h"
19
#include "dlg_editsecret_p.h"
20
#include "i18n_l.h"
21

    
22
#include <aqbanking/user.h>
23
#include <aqbanking/banking_be.h>
24

    
25
#include <aqpaypal/user.h>
26
#include <aqpaypal/provider.h>
27

    
28
#include <gwenhywfar/gwenhywfar.h>
29
#include <gwenhywfar/misc.h>
30
#include <gwenhywfar/pathmanager.h>
31
#include <gwenhywfar/debug.h>
32
#include <gwenhywfar/gui.h>
33
#include <gwenhywfar/text.h>
34

    
35

    
36
#define DIALOG_MINWIDTH  400
37
#define DIALOG_MINHEIGHT 200
38

    
39

    
40

    
41
GWEN_INHERIT(GWEN_DIALOG, APY_EDITUSER_DIALOG)
42

    
43

    
44

    
45

    
46
GWEN_DIALOG *APY_EditUserDialog_new(AB_PROVIDER *pro, AB_USER *u, int doLock) {
47
  GWEN_DIALOG *dlg;
48
  APY_EDITUSER_DIALOG *xdlg;
49
  GWEN_BUFFER *fbuf;
50
  int rv;
51
  const char *s;
52

    
53
  dlg=GWEN_Dialog_new("apy_edituser");
54
  GWEN_NEW_OBJECT(APY_EDITUSER_DIALOG, xdlg);
55
  GWEN_INHERIT_SETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg, xdlg, APY_EditUserDialog_FreeData);
56
  GWEN_Dialog_SetSignalHandler(dlg, APY_EditUserDialog_SignalHandler);
57

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

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

    
80
  xdlg->provider=pro;
81
  xdlg->banking=AB_Provider_GetBanking(pro);
82

    
83
  /* preset */
84
  xdlg->doLock=doLock;
85
  xdlg->user=u;
86

    
87
  s=AB_User_GetUserName(u);
88
  if (s && *s) xdlg->userName=strdup(s);
89
  else xdlg->userName=NULL;
90

    
91
  s=AB_User_GetUserId(u);
92
  if (s && *s) xdlg->userId=strdup(s);
93
  else xdlg->userId=NULL;
94

    
95
  s=AB_User_GetCustomerId(u);
96
  if (s && *s) xdlg->customerId=strdup(s);
97
  else xdlg->customerId=NULL;
98

    
99
  s=APY_User_GetServerUrl(u);
100
  if (!(s && *s)) xdlg->url=strdup("https://api-3t.paypal.com/nvp");
101
  else xdlg->url=strdup(s);
102

    
103

    
104
  /* done */
105
  return dlg;
106
}
107

    
108

    
109

    
110
void GWENHYWFAR_CB APY_EditUserDialog_FreeData(void *bp, void *p) {
111
  APY_EDITUSER_DIALOG *xdlg;
112

    
113
  xdlg=(APY_EDITUSER_DIALOG*) p;
114
  free(xdlg->apiUserId);
115
  free(xdlg->apiPassword);
116
  free(xdlg->apiSignature);
117
  free(xdlg->userName);
118
  free(xdlg->userId);
119
  free(xdlg->url);
120
  GWEN_FREE_OBJECT(xdlg);
121
}
122

    
123

    
124

    
125
AB_USER *APY_EditUserDialog_GetUser(const GWEN_DIALOG *dlg) {
126
  APY_EDITUSER_DIALOG *xdlg;
127

    
128
  assert(dlg);
129
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
130
  assert(xdlg);
131

    
132
  return xdlg->user;
133
}
134

    
135

    
136

    
137
const char *APY_EditUserDialog_GetApiUserId(const GWEN_DIALOG *dlg) {
138
  APY_EDITUSER_DIALOG *xdlg;
139

    
140
  assert(dlg);
141
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
142
  assert(xdlg);
143

    
144
  return xdlg->apiUserId;
145
}
146

    
147

    
148

    
149
void APY_EditUserDialog_SetApiUserId(GWEN_DIALOG *dlg, const char *s) {
150
  APY_EDITUSER_DIALOG *xdlg;
151

    
152
  assert(dlg);
153
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
154
  assert(xdlg);
155

    
156
  free(xdlg->apiUserId);
157
  if (s) xdlg->apiUserId=strdup(s);
158
  else xdlg->apiUserId=NULL;
159
}
160

    
161

    
162

    
163
const char *APY_EditUserDialog_GetApiPassword(const GWEN_DIALOG *dlg) {
164
  APY_EDITUSER_DIALOG *xdlg;
165

    
166
  assert(dlg);
167
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
168
  assert(xdlg);
169

    
170
  return xdlg->apiPassword;
171
}
172

    
173

    
174

    
175
void APY_EditUserDialog_SetApiPassword(GWEN_DIALOG *dlg, const char *s) {
176
  APY_EDITUSER_DIALOG *xdlg;
177

    
178
  assert(dlg);
179
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
180
  assert(xdlg);
181

    
182
  free(xdlg->apiPassword);
183
  if (s) xdlg->apiPassword=strdup(s);
184
  else xdlg->apiPassword=NULL;
185
}
186

    
187

    
188

    
189
const char *APY_EditUserDialog_GetApiSignature(const GWEN_DIALOG *dlg) {
190
  APY_EDITUSER_DIALOG *xdlg;
191

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

    
196
  return xdlg->apiSignature;
197
}
198

    
199

    
200

    
201
void APY_EditUserDialog_SetApiSignature(GWEN_DIALOG *dlg, const char *s) {
202
  APY_EDITUSER_DIALOG *xdlg;
203

    
204
  assert(dlg);
205
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
206
  assert(xdlg);
207

    
208
  free(xdlg->apiSignature);
209
  if (s) xdlg->apiSignature=strdup(s);
210
  else xdlg->apiSignature=NULL;
211
}
212

    
213

    
214

    
215
const char *APY_EditUserDialog_GetUserName(const GWEN_DIALOG *dlg) {
216
  APY_EDITUSER_DIALOG *xdlg;
217

    
218
  assert(dlg);
219
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
220
  assert(xdlg);
221

    
222
  return xdlg->userName;
223
}
224

    
225

    
226

    
227
void APY_EditUserDialog_SetUserName(GWEN_DIALOG *dlg, const char *s) {
228
  APY_EDITUSER_DIALOG *xdlg;
229

    
230
  assert(dlg);
231
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
232
  assert(xdlg);
233

    
234
  free(xdlg->userName);
235
  if (s) xdlg->userName=strdup(s);
236
  else xdlg->userName=NULL;
237
}
238

    
239

    
240

    
241
const char *APY_EditUserDialog_GetUserId(const GWEN_DIALOG *dlg) {
242
  APY_EDITUSER_DIALOG *xdlg;
243

    
244
  assert(dlg);
245
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
246
  assert(xdlg);
247

    
248
  return xdlg->userId;
249
}
250

    
251

    
252

    
253
void APY_EditUserDialog_SetUserId(GWEN_DIALOG *dlg, const char *s) {
254
  APY_EDITUSER_DIALOG *xdlg;
255

    
256
  assert(dlg);
257
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
258
  assert(xdlg);
259

    
260
  free(xdlg->userId);
261
  if (s) xdlg->userId=strdup(s);
262
  else xdlg->userId=NULL;
263
}
264

    
265

    
266

    
267
const char *APY_EditUserDialog_GetUrl(const GWEN_DIALOG *dlg) {
268
  APY_EDITUSER_DIALOG *xdlg;
269

    
270
  assert(dlg);
271
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
272
  assert(xdlg);
273

    
274
  return xdlg->url;
275
}
276

    
277

    
278

    
279
void APY_EditUserDialog_SetUrl(GWEN_DIALOG *dlg, const char *s) {
280
  APY_EDITUSER_DIALOG *xdlg;
281

    
282
  assert(dlg);
283
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
284
  assert(xdlg);
285

    
286
  free(xdlg->url);
287
  if (s) xdlg->url=strdup(s);
288
  else xdlg->url=NULL;
289
}
290

    
291

    
292

    
293
uint32_t APY_EditUserDialog_GetFlags(const GWEN_DIALOG *dlg) {
294
  APY_EDITUSER_DIALOG *xdlg;
295

    
296
  assert(dlg);
297
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
298
  assert(xdlg);
299

    
300
  return xdlg->flags;
301
}
302

    
303

    
304

    
305
void APY_EditUserDialog_SetFlags(GWEN_DIALOG *dlg, uint32_t fl) {
306
  APY_EDITUSER_DIALOG *xdlg;
307

    
308
  assert(dlg);
309
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
310
  assert(xdlg);
311

    
312
  xdlg->flags=fl;
313
}
314

    
315

    
316

    
317
void APY_EditUserDialog_AddFlags(GWEN_DIALOG *dlg, uint32_t fl) {
318
  APY_EDITUSER_DIALOG *xdlg;
319

    
320
  assert(dlg);
321
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
322
  assert(xdlg);
323

    
324
  xdlg->flags&=~fl;
325
}
326

    
327

    
328

    
329
void APY_EditUserDialog_SubFlags(GWEN_DIALOG *dlg, uint32_t fl) {
330
  APY_EDITUSER_DIALOG *xdlg;
331

    
332
  assert(dlg);
333
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
334
  assert(xdlg);
335

    
336
  xdlg->flags&=~fl;
337
}
338

    
339

    
340

    
341

    
342

    
343

    
344
void APY_EditUserDialog_Init(GWEN_DIALOG *dlg) {
345
  APY_EDITUSER_DIALOG *xdlg;
346
  GWEN_DB_NODE *dbPrefs;
347
  int i;
348

    
349
  assert(dlg);
350
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
351
  assert(xdlg);
352

    
353
  dbPrefs=GWEN_Dialog_GetPreferences(dlg);
354

    
355
  GWEN_Dialog_SetCharProperty(dlg,
356
                              "",
357
                              GWEN_DialogProperty_Title,
358
                              0,
359
                              I18N("Edit Paypal User"),
360
                              0);
361

    
362
  if (xdlg->userName)
363
    GWEN_Dialog_SetCharProperty(dlg,
364
                                "wiz_username_edit",
365
                                GWEN_DialogProperty_Value,
366
                                0,
367
                                xdlg->userName,
368
                                0);
369

    
370
  if (xdlg->userId)
371
    GWEN_Dialog_SetCharProperty(dlg,
372
                                "wiz_userid_edit",
373
                                GWEN_DialogProperty_Value,
374
                                0,
375
                                xdlg->userId,
376
                                0);
377

    
378
  if (xdlg->url)
379
    GWEN_Dialog_SetCharProperty(dlg,
380
                                "wiz_url_edit",
381
                                GWEN_DialogProperty_Value,
382
                                0,
383
                                xdlg->url,
384
                                0);
385

    
386
  /* read width */
387
  i=GWEN_DB_GetIntValue(dbPrefs, "dialog_width", 0, -1);
388
  if (i>=DIALOG_MINWIDTH)
389
    GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, i, 0);
390

    
391
  /* read height */
392
  i=GWEN_DB_GetIntValue(dbPrefs, "dialog_height", 0, -1);
393
  if (i>=DIALOG_MINHEIGHT)
394
    GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, i, 0);
395
}
396

    
397

    
398

    
399
void APY_EditUserDialog_Fini(GWEN_DIALOG *dlg) {
400
  APY_EDITUSER_DIALOG *xdlg;
401
  int i;
402
  GWEN_DB_NODE *dbPrefs;
403

    
404
  assert(dlg);
405
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
406
  assert(xdlg);
407

    
408
  dbPrefs=GWEN_Dialog_GetPreferences(dlg);
409

    
410
  /* store dialog width */
411
  i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, -1);
412
  GWEN_DB_SetIntValue(dbPrefs,
413
                      GWEN_DB_FLAGS_OVERWRITE_VARS,
414
                      "dialog_width",
415
                      i);
416

    
417
  /* store dialog height */
418
  i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, -1);
419
  GWEN_DB_SetIntValue(dbPrefs,
420
                      GWEN_DB_FLAGS_OVERWRITE_VARS,
421
                      "dialog_height",
422
                      i);
423
}
424

    
425

    
426

    
427
int APY_EditUserDialog_fromGui(GWEN_DIALOG *dlg, AB_USER *u, int quiet) {
428
  APY_EDITUSER_DIALOG *xdlg;
429
  const char *s;
430

    
431
  assert(dlg);
432
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
433
  assert(xdlg);
434

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

    
439
    tbuf=GWEN_Buffer_new(0, 256, 0, 1);
440
    GWEN_Buffer_AppendString(tbuf, s);
441
    GWEN_Text_CondenseBuffer(tbuf);
442
    if (u)
443
      APY_EditUserDialog_SetUserName(dlg, GWEN_Buffer_GetStart(tbuf));
444
    GWEN_Buffer_free(tbuf);
445
  }
446
  else {
447
    DBG_INFO(AQPAYPAL_LOGDOMAIN, "Missing user name");
448
    return GWEN_ERROR_NO_DATA;
449
  }
450

    
451
  s=GWEN_Dialog_GetCharProperty(dlg, "wiz_userid_edit", GWEN_DialogProperty_Value, 0, NULL);
452
  if (s && *s) {
453
    GWEN_BUFFER *tbuf;
454

    
455
    tbuf=GWEN_Buffer_new(0, 256, 0, 1);
456
    GWEN_Buffer_AppendString(tbuf, s);
457
    GWEN_Text_CondenseBuffer(tbuf);
458
    if (u)
459
      APY_EditUserDialog_SetUserId(dlg, GWEN_Buffer_GetStart(tbuf));
460
    GWEN_Buffer_free(tbuf);
461
  }
462
  else {
463
    DBG_INFO(AQPAYPAL_LOGDOMAIN, "Missing user id");
464
    return GWEN_ERROR_NO_DATA;
465
  }
466

    
467
  s=GWEN_Dialog_GetCharProperty(dlg, "wiz_url_edit", GWEN_DialogProperty_Value, 0, NULL);
468
  if (s && *s) {
469
    GWEN_BUFFER *tbuf;
470

    
471
    tbuf=GWEN_Buffer_new(0, 256, 0, 1);
472
    GWEN_Buffer_AppendString(tbuf, s);
473
    GWEN_Text_CondenseBuffer(tbuf);
474
    if (u)
475
      APY_EditUserDialog_SetUrl(dlg, GWEN_Buffer_GetStart(tbuf));
476
    GWEN_Buffer_free(tbuf);
477
  }
478
  else {
479
    DBG_INFO(AQPAYPAL_LOGDOMAIN, "Missing URL");
480
    return GWEN_ERROR_NO_DATA;
481
  }
482

    
483
  return 0;
484
}
485

    
486

    
487

    
488
int APY_EditUserDialog_HandleActivatedOk(GWEN_DIALOG *dlg) {
489
  APY_EDITUSER_DIALOG *xdlg;
490
  int rv;
491

    
492
  assert(dlg);
493
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
494
  assert(xdlg);
495

    
496
  rv=APY_EditUserDialog_fromGui(dlg, NULL, 0);
497
  if (rv<0) {
498
    return GWEN_DialogEvent_ResultHandled;
499
  }
500

    
501
  if (xdlg->doLock) {
502
    int rv;
503

    
504
    rv=AB_Provider_BeginExclUseUser(xdlg->provider, xdlg->user);
505
    if (rv<0) {
506
      DBG_INFO(AQPAYPAL_LOGDOMAIN, "here (%d)", rv);
507
      GWEN_Gui_MessageBox(GWEN_GUI_MSG_FLAGS_SEVERITY_NORMAL |
508
                          GWEN_GUI_MSG_FLAGS_TYPE_ERROR |
509
                          GWEN_GUI_MSG_FLAGS_CONFIRM_B1,
510
                          I18N("Error"),
511
                          I18N("Unable to lock user. Maybe already in use?"),
512
                          I18N("Dismiss"),
513
                          NULL,
514
                          NULL,
515
                          0);
516
      return GWEN_DialogEvent_ResultHandled;
517
    }
518
  }
519

    
520
  APY_EditUserDialog_fromGui(dlg, xdlg->user, 1);
521
  AB_User_SetUserName(xdlg->user, xdlg->userName);
522
  AB_User_SetUserId(xdlg->user, xdlg->userId);
523
  AB_User_SetCustomerId(xdlg->user, xdlg->userId);
524
  AB_User_SetCountry(xdlg->user, "de");
525
  AB_User_SetBankCode(xdlg->user, "PAYPAL");
526

    
527
  if (xdlg->doLock) {
528
    int rv;
529

    
530
    rv=AB_Provider_EndExclUseUser(xdlg->provider, xdlg->user, 0);
531
    if (rv<0) {
532
      DBG_INFO(AQPAYPAL_LOGDOMAIN, "here (%d)", rv);
533
      GWEN_Gui_MessageBox(GWEN_GUI_MSG_FLAGS_SEVERITY_NORMAL |
534
                          GWEN_GUI_MSG_FLAGS_TYPE_ERROR |
535
                          GWEN_GUI_MSG_FLAGS_CONFIRM_B1,
536
                          I18N("Error"),
537
                          I18N("Unable to unlock user."),
538
                          I18N("Dismiss"),
539
                          NULL,
540
                          NULL,
541
                          0);
542
      return GWEN_DialogEvent_ResultHandled;
543
    }
544
  }
545

    
546
  return GWEN_DialogEvent_ResultAccept;
547
}
548

    
549

    
550
int APY_EditUserDialog_HandleActivatedSecret(GWEN_DIALOG *dlg) {
551
  APY_EDITUSER_DIALOG *xdlg;
552
  GWEN_DIALOG *dlg2;
553
  int rv;
554
  AB_USER *u;
555
  GWEN_BUFFER *xbuf, *tbuf;
556

    
557
  assert(dlg);
558
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
559
  assert(xdlg);
560

    
561
  u=xdlg->user;
562

    
563
  dlg2=APY_EditSecretDialog_new(xdlg->banking);
564
  if (dlg2==NULL) {
565
    DBG_ERROR(AQBANKING_LOGDOMAIN, "Could not create dialog");
566
    return GWEN_DialogEvent_ResultHandled;
567
  }
568

    
569
  xbuf=GWEN_Buffer_new(0, 256, 0, 1);
570
  rv=APY_Provider_ReadUserApiSecrets(AB_User_GetProvider(u), u, xbuf);
571
  if (rv<0) {
572
    DBG_INFO(AQPAYPAL_LOGDOMAIN, "here (%d)", rv);
573
    GWEN_Buffer_free(xbuf);
574
    return rv;
575
  }
576
  else {
577
    char *t;
578
    char *t2=NULL;
579
    GWEN_BUFFER *sbuf1;
580
    GWEN_BUFFER *sbuf2;
581
    GWEN_BUFFER *sbuf3;
582

    
583
    t=strchr(GWEN_Buffer_GetStart(xbuf), ':');
584
    if (t) {
585
      *(t++)=0;
586
      t2=strchr(t, ':');
587
      if (t2) {
588
        *(t2++)=0;
589
      }
590
    }
591

    
592
    sbuf1=GWEN_Buffer_new(0, 256, 0, 1);
593
    sbuf2=GWEN_Buffer_new(0, 256, 0, 1);
594
    sbuf3=GWEN_Buffer_new(0, 256, 0, 1);
595
    GWEN_Text_UnescapeToBufferTolerant(GWEN_Buffer_GetStart(xbuf), sbuf1);
596
    if (t) {
597
      GWEN_Text_UnescapeToBufferTolerant(t, sbuf2);
598
      if (t2) {
599
        GWEN_Text_UnescapeToBufferTolerant(t2, sbuf3);
600
      }
601
    }
602
    APY_EditSecretDialog_SetApiUserId(dlg2,    GWEN_Buffer_GetStart(sbuf3));
603
    APY_EditSecretDialog_SetApiPassword(dlg2,  GWEN_Buffer_GetStart(sbuf1));
604
    APY_EditSecretDialog_SetApiSignature(dlg2, GWEN_Buffer_GetStart(sbuf2));
605

    
606
    GWEN_Buffer_free(xbuf);
607
    GWEN_Buffer_free(sbuf3);
608
    GWEN_Buffer_free(sbuf2);
609
    GWEN_Buffer_free(sbuf1);
610
  }
611

    
612
  rv=GWEN_Gui_ExecDialog(dlg2, 0);
613
  if (rv==0) {
614
    /* rejected */
615
    DBG_INFO(AQPAYPAL_LOGDOMAIN, "Rejected");
616
    GWEN_Dialog_free(dlg2);
617
    return GWEN_DialogEvent_ResultHandled;
618
  }
619
  else {
620
    DBG_INFO(AQPAYPAL_LOGDOMAIN, "Accepted");
621
    
622
    tbuf=GWEN_Buffer_new(0, 256, 0, 1);
623
    GWEN_Text_EscapeToBuffer(APY_EditSecretDialog_GetApiPassword(dlg2), tbuf);
624
    GWEN_Buffer_AppendByte(tbuf, ':');
625
    GWEN_Text_EscapeToBuffer(APY_EditSecretDialog_GetApiSignature(dlg2), tbuf);
626
    GWEN_Buffer_AppendByte(tbuf, ':');
627
    GWEN_Text_EscapeToBuffer(APY_EditSecretDialog_GetApiUserId(dlg2), tbuf);
628
    rv=APY_Provider_WriteUserApiSecrets(AB_User_GetProvider(u), u,
629
                                        GWEN_Buffer_GetStart(tbuf));
630
    GWEN_Buffer_free(tbuf);
631
    if (rv<0) {
632
      DBG_INFO(AQPAYPAL_LOGDOMAIN, "here (%d)", rv);
633
      return rv;
634
    }
635
  }
636

    
637
  GWEN_Dialog_free(dlg2);
638
  return GWEN_DialogEvent_ResultHandled;
639
}
640

    
641

    
642
int APY_EditUserDialog_GetSecretPageData(GWEN_DIALOG *dlg) {
643
  APY_EDITUSER_DIALOG *xdlg;
644
  const char *s;
645

    
646
  assert(dlg);
647
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
648
  assert(xdlg);
649

    
650
  fprintf(stderr, "\n>>>> GetSecretPageData #1\n");
651
  s=GWEN_Dialog_GetCharProperty(dlg, "wiz_apiuserid_edit", GWEN_DialogProperty_Value, 0, NULL);
652
  fprintf(stderr, "\n>>>> GetSecretPageData #2%s\n", s);
653
  if (s && *s)
654
    APY_EditUserDialog_SetApiUserId(dlg, s);
655
  else {
656
    DBG_INFO(AQPAYPAL_LOGDOMAIN, "Missing API User ID");
657
    return GWEN_ERROR_NO_DATA;
658
  }
659
  fprintf(stderr, "\n>>>> GetSecretPageData #3\n");
660

    
661
  s=GWEN_Dialog_GetCharProperty(dlg, "wiz_apipass_edit", GWEN_DialogProperty_Value, 0, NULL);
662
  fprintf(stderr, "\n>>>> GetSecretPageData #4\n");
663
  if (s && *s)
664
    APY_EditUserDialog_SetApiPassword(dlg, s);
665
  else {
666
    DBG_INFO(AQPAYPAL_LOGDOMAIN, "Missing API Password");
667
    return GWEN_ERROR_NO_DATA;
668
  }
669

    
670
  s=GWEN_Dialog_GetCharProperty(dlg, "wiz_apisig_edit", GWEN_DialogProperty_Value, 0, NULL);
671
  if (s && *s)
672
    APY_EditUserDialog_SetApiSignature(dlg, s);
673
  else {
674
    DBG_INFO(AQPAYPAL_LOGDOMAIN, "Missing API Signature");
675
    return GWEN_ERROR_NO_DATA;
676
  }
677

    
678
  return 0;
679
}
680

    
681

    
682

    
683
int APY_EditUserDialog_HandleActivated(GWEN_DIALOG *dlg, const char *sender) {
684
  DBG_ERROR(0, "Activated: %s", sender);
685
  if (strcasecmp(sender, "okButton")==0)
686
    return APY_EditUserDialog_HandleActivatedOk(dlg);
687
  else if (strcasecmp(sender, "abortButton")==0)
688
    return GWEN_DialogEvent_ResultReject;
689
  else if (strcasecmp(sender, "wiz_secret_button")==0) {
690
    APY_EditUserDialog_HandleActivatedSecret(dlg);
691
  }
692
  else if (strcasecmp(sender, "wiz_help_button")==0) {
693
    /* TODO: open a help dialog */
694
  }
695

    
696
  return GWEN_DialogEvent_ResultNotHandled;
697
}
698

    
699

    
700

    
701
int GWENHYWFAR_CB APY_EditUserDialog_SignalHandler(GWEN_DIALOG *dlg,
702
                                                   GWEN_DIALOG_EVENTTYPE t,
703
                                                   const char *sender) {
704
  APY_EDITUSER_DIALOG *xdlg;
705

    
706
  assert(dlg);
707
  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, APY_EDITUSER_DIALOG, dlg);
708
  assert(xdlg);
709

    
710
  switch(t) {
711
  case GWEN_DialogEvent_TypeInit:
712
    APY_EditUserDialog_Init(dlg);
713
    return GWEN_DialogEvent_ResultHandled;
714

    
715
  case GWEN_DialogEvent_TypeFini:
716
    APY_EditUserDialog_Fini(dlg);
717
    return GWEN_DialogEvent_ResultHandled;
718

    
719
  case GWEN_DialogEvent_TypeValueChanged:
720
    return GWEN_DialogEvent_ResultHandled;
721

    
722
  case GWEN_DialogEvent_TypeActivated:
723
    return APY_EditUserDialog_HandleActivated(dlg, sender);
724

    
725
  case GWEN_DialogEvent_TypeEnabled:
726
  case GWEN_DialogEvent_TypeDisabled:
727
  case GWEN_DialogEvent_TypeClose:
728

    
729
  case GWEN_DialogEvent_TypeLast:
730
    return GWEN_DialogEvent_ResultNotHandled;
731

    
732
  }
733

    
734
  return GWEN_DialogEvent_ResultNotHandled;
735
}
736

    
737

    
738

    
739