Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

aqfinance / src / fox / lib / modules / bankaccounts / fm_bankaccpage.cpp @ 1a3fe7c5

History | View | Annotate | Download (8.32 KB)

1
/****************************************************************************
2
 * This file is part of the project AqFinance.
3
 * AqFinance (c) by 2009 Martin Preuss, all rights reserved.
4
 *
5
 * The license for this file can be found in the file COPYING which you
6
 * should have received along with this file.
7
 ****************************************************************************/
8

    
9
#ifdef HAVE_CONFIG_H
10
# include <config.h>
11
#endif
12

    
13

    
14
#include "ff_app.hpp"
15
#include "fm_bankaccounts.hpp"
16
#include "fm_bankaccpage.hpp"
17
#include "fm_bankaccaccpage.hpp"
18
#include "fm_bankaccstmpage.hpp"
19

    
20
#include <gwen-gui-fox16/theme.h>
21

    
22
#include <gwenhywfar/debug.h>
23
#include <gwenhywfar/i18n.h>
24

    
25

    
26
#define I18N(msg) GWEN_I18N_Translate(PACKAGE, msg)
27

    
28

    
29

    
30
FXDEFMAP(FM_BankAccountPage) FM_BankAccountPageMap[]= {
31
  FXMAPFUNC(SEL_COMMAND, FM_BankAccountPage::ID_TABBOOK, FM_BankAccountPage::onTabClicked),
32
  FXMAPFUNC(SEL_LEFTBUTTONPRESS, FM_BankAccountPage::ID_TABITEM, FM_BankAccountPage::onTabLeftButtonPressed),
33
};
34

    
35

    
36

    
37
FXIMPLEMENT(FM_BankAccountPage, FF_ModTabBook, FM_BankAccountPageMap, ARRAYNUMBER(FM_BankAccountPageMap))
38

    
39

    
40

    
41

    
42

    
43
FM_BankAccountPage::FM_BankAccountPage(FM_BankAccounts *modBankAccounts,
44
                                       FXComposite *p,
45
                                       FXuint opts,
46
                                       FXint x, FXint y, FXint w, FXint h)
47
:FF_ModTabBook(modBankAccounts, p, opts, x, y, w, h)
48
, m_bankAccountView(NULL)
49
, m_lastEnteredTab(-1)
50
, m_config(NULL)
51
, m_statementMarkId(0)
52
, m_closeTabIcon(NULL)
53
{
54
  FF_App *app;
55

    
56
  app=dynamic_cast<FF_App *>(getApp());
57

    
58
  m_closeTabIcon=app->getIcon("closetab");
59

    
60
  /* create tab 1 */
61
  addTabHeader(I18N("Accounts"), false);
62
  m_bankAccountView=new FM_BankAccountAccPage("accountTreePage", this, LAYOUT_FILL_X | LAYOUT_FILL_Y);
63
  addTabPage(m_bankAccountView, false);
64
}
65

    
66

    
67

    
68
FM_BankAccountPage::FM_BankAccountPage()
69
:FF_ModTabBook()
70
, m_bankAccountView(NULL)
71
, m_lastEnteredTab(-1)
72
, m_config(NULL)
73
, m_statementMarkId(0)
74
, m_closeTabIcon(NULL)
75
{
76
}
77

    
78

    
79

    
80
FM_BankAccountPage::~FM_BankAccountPage()
81
{
82
}
83

    
84

    
85

    
86
void FM_BankAccountPage::create()
87
{
88
  FXHorizontalFrame::create();
89
  if (m_closeTabIcon)
90
    m_closeTabIcon->create();
91
}
92

    
93

    
94

    
95
void FM_BankAccountPage::init(GWEN_DB_NODE *db)
96
{
97
  DBG_INFO(0, "Init");
98
  m_config=GWEN_DB_Group_dup(db);
99
  std::list<FM_BankAccountStmPage *>::iterator it;
100

    
101
  m_bankAccountView->init(m_config);
102
  for (it=m_accountPages.begin(); it!=m_accountPages.end(); it++)
103
    (*it)->init(m_config);
104

    
105
}
106

    
107

    
108

    
109
void FM_BankAccountPage::fini(GWEN_DB_NODE *db)
110
{
111
  std::list<FM_BankAccountStmPage *>::iterator it;
112

    
113
  DBG_INFO(0, "Fini");
114

    
115
  /* list open accounts */
116
  GWEN_DB_DeleteVar(m_config, "openAccounts");
117
  for (it=m_accountPages.begin(); it!=m_accountPages.end(); it++)
118
    GWEN_DB_SetIntValue(m_config, GWEN_DB_FLAGS_DEFAULT, "openAccounts",
119
                        (*it)->getBankAccountId());
120

    
121
  for (it=m_accountPages.begin(); it!=m_accountPages.end(); it++)
122
    (*it)->fini(m_config);
123
  m_bankAccountView->fini(m_config);
124

    
125
  GWEN_DB_ClearGroup(db, NULL);
126
  GWEN_DB_AddGroupChildren(db, m_config);
127

    
128
  GWEN_DB_Group_free(m_config);
129
  m_config=NULL;
130
}
131

    
132

    
133

    
134
void FM_BankAccountPage::dbOpened(AE_BOOK *bk)
135
{
136
  std::list<FM_BankAccountStmPage *>::iterator it;
137

    
138
  m_bankAccountView->dbOpened(bk);
139

    
140
  for (it=m_accountPages.begin(); it!=m_accountPages.end(); it++) {
141
    (*it)->dbOpened(bk);
142
  }
143
}
144

    
145

    
146

    
147
void FM_BankAccountPage::dbClosing()
148
{
149
  std::list<FM_BankAccountStmPage *>::iterator it;
150

    
151
  m_bankAccountView->dbClosing();
152

    
153
  for (it=m_accountPages.begin(); it!=m_accountPages.end(); it++) {
154
    (*it)->dbClosing();
155
  }
156
}
157

    
158

    
159

    
160
void FM_BankAccountPage::dbClosed()
161
{
162
  std::list<FM_BankAccountStmPage *>::iterator it;
163

    
164
  m_bankAccountView->dbClosed();
165

    
166
  for (it=m_accountPages.begin(); it!=m_accountPages.end(); it++) {
167
    (*it)->dbClosed();
168
  }
169
}
170

    
171

    
172

    
173
void FM_BankAccountPage::dbReload(AE_BOOK_TABLE_TYPE tt)
174
{
175
  std::list<FM_BankAccountStmPage *>::iterator it;
176

    
177
  m_bankAccountView->dbReload(tt);
178

    
179
  for (it=m_accountPages.begin(); it!=m_accountPages.end(); it++) {
180
    (*it)->dbReload(tt);
181
  }
182
}
183

    
184

    
185

    
186
void FM_BankAccountPage::aboutToSendJobs()
187
{
188
  FF_App *app;
189
  AE_BOOK *b;
190
  std::list<FM_BankAccountStmPage *>::iterator it;
191

    
192
  app=dynamic_cast<FF_App *>(getApp());
193
  b=app->getBook();
194
  if (b) {
195
    int rv;
196
    AQDB_ID id;
197

    
198
    rv=AE_Book_GetLastId(b, AE_Book_TableType_BankStatement, &id);
199
    if (rv<0) {
200
      DBG_ERROR(0, "here (%d)", rv);
201
    }
202
    else {
203
      m_statementMarkId=id;
204
    }
205
  }
206

    
207
  m_bankAccountView->aboutToSendJobs();
208
  for (it=m_accountPages.begin(); it!=m_accountPages.end(); it++) {
209
    (*it)->aboutToSendJobs();
210
  }
211
}
212

    
213

    
214

    
215
void FM_BankAccountPage::jobListUpdated()
216
{
217
  m_bankAccountView->jobListUpdated();
218
}
219

    
220

    
221

    
222
long FM_BankAccountPage::onTabClicked(FXObject *, FXSelector, void *ptr)
223
{
224
  FXint idx=(FXint)(FXival)ptr;
225
  FM_BankAccountStmPage *ap;
226

    
227
  if (m_lastEnteredTab!=-1) {
228
    if (m_lastEnteredTab==0)
229
      m_bankAccountView->leave();
230
    else {
231
      ap=findPageAt(m_lastEnteredTab-1);
232
      if (ap)
233
        ap->leave();
234
    }
235
  }
236

    
237
  if (idx==0) {
238
    m_bankAccountView->enter();
239
  }
240
  else {
241
    ap=findPageAt(idx-1);
242
    if (ap)
243
      ap->enter();
244
  }
245

    
246
  m_lastEnteredTab=idx;
247

    
248

    
249
  return 1;
250
}
251

    
252

    
253

    
254
long FM_BankAccountPage::onTabLeftButtonPressed(FXObject *obj, FXSelector, void *ptr)
255
{
256
  FXEvent *event=(FXEvent *) ptr;
257
  FXTabItem *item=(FXTabItem *) obj;
258

    
259
  if (item->isEnabled()) {
260
    if (m_closeTabIcon) {
261
      int ix;
262

    
263
      ix=item->getWidth()-m_closeTabIcon->getWidth();
264
      if (event->win_x>ix) {
265
        FM_BankAccountStmPage *page;
266

    
267
        page=(FM_BankAccountStmPage *)(item->getNext());
268
        page->fini(m_config);
269
        m_accountPages.remove(page);
270
        delete item;
271
        delete page;
272
        return 1;
273
      }
274
    }
275
    else {
276
      DBG_ERROR(0, "no icon");
277
    }
278
  }
279
  else {
280
    DBG_ERROR(0, "Not enabled");
281
  }
282

    
283
  return 0;
284
}
285

    
286

    
287

    
288
FM_BankAccountStmPage *FM_BankAccountPage::findPageForAccount(AQDB_ID aid)
289
{
290
  std::list<FM_BankAccountStmPage *>::iterator it;
291

    
292
  for (it=m_accountPages.begin(); it!=m_accountPages.end(); it++) {
293
    if ((*it)->getBankAccountId()==aid)
294
      return *it;
295
  }
296

    
297
  return NULL;
298
}
299

    
300

    
301

    
302
int FM_BankAccountPage::findIndexForAccount(AQDB_ID aid)
303
{
304
  std::list<FM_BankAccountStmPage *>::iterator it;
305
  int idx=0;
306

    
307
  for (it=m_accountPages.begin(); it!=m_accountPages.end(); it++) {
308
    if ((*it)->getBankAccountId()==aid)
309
      return idx;
310
    idx++;
311
  }
312

    
313
  return -1;
314
}
315

    
316

    
317

    
318
FM_BankAccountStmPage *FM_BankAccountPage::findPageAt(int idx)
319
{
320
  std::list<FM_BankAccountStmPage *>::iterator it;
321

    
322
  for (it=m_accountPages.begin(); it!=m_accountPages.end(); it++) {
323
    if (idx==0)
324
      return *it;
325
    idx--;
326
  }
327

    
328
  return NULL;
329
}
330

    
331

    
332

    
333
void FM_BankAccountPage::openAccountPage(const AE_BANKACCOUNT *ba)
334
{
335
  FM_BankAccountStmPage *ap;
336
  AQDB_ID aid;
337

    
338
  aid=AE_BankAccount_GetId(ba);
339
  ap=findPageForAccount(aid);
340
  if (ap) {
341
    int idx=findIndexForAccount(aid);
342
    if (idx!=-1)
343
      m_tabBook->setCurrent(idx+1, true);
344
  }
345
  else {
346
    const char *s;
347
    FXString title;
348
    FXTabItem *tab;
349

    
350
    /* no page open for account, create one */
351
    s=AE_BankAccount_GetAccountName(ba);
352
    if (s==NULL || *s==0)
353
      s=AE_BankAccount_GetAccountNumber(ba);
354
    if (s==NULL || *s==0)
355
      s=AE_BankAccount_GetIban(ba);
356
    if (s==NULL || *s==0)
357
      s=I18N("<unknown>");
358
    title=FXString(s);
359

    
360
    /* create tab entry */
361
    tab=addTabHeader(title, true);
362
    tab->create();
363
    ap=new FM_BankAccountStmPage(title, this, ba, LAYOUT_FILL_X | LAYOUT_FILL_Y);
364
    ap->create();
365
    addTabPage(ap, true);
366
    m_accountPages.push_back(ap);
367
    ap->init(m_config);
368

    
369
    /* we correctly use .size() here, not size()-1, because the first tab is the account tree */
370
    m_tabBook->setCurrent(m_accountPages.size(), true);
371
  }
372
}
373

    
374

    
375

    
376
void FM_BankAccountPage::enter()
377
{
378
  if (m_lastEnteredTab!=-1) {
379
    FM_BankAccountStmPage *ap;
380

    
381
    if (m_lastEnteredTab==0)
382
      m_bankAccountView->enter();
383
    else {
384
      ap=findPageAt(m_lastEnteredTab-1);
385
      if (ap)
386
        ap->enter();
387
    }
388
  }
389
}
390

    
391

    
392

    
393
void FM_BankAccountPage::leave()
394
{
395
  if (m_lastEnteredTab!=-1) {
396
    FM_BankAccountStmPage *ap;
397

    
398
    if (m_lastEnteredTab==0)
399
      m_bankAccountView->leave();
400
    else {
401
      ap=findPageAt(m_lastEnteredTab-1);
402
      if (ap)
403
        ap->leave();
404
    }
405
  }
406
}
407

    
408

    
409
void FM_BankAccountPage::reset()
410
{
411
  std::list<FM_BankAccountStmPage *>::iterator it;
412

    
413
  m_bankAccountView->reset();
414

    
415
  for (it=m_accountPages.begin(); it!=m_accountPages.end(); it++) {
416
    (*it)->reset();
417
  }
418
}
419

    
420

    
421

    
422

    
423