PageRenderTime 58ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/aqbanking-5.0.22/src/libs/aqbanking/dialogs/dlg_editaccount.c

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