Logo Search packages:      
Sourcecode: qbankmanager version File versions  Download package

payeeview.cpp

/***************************************************************************
 $RCSfile: payeeview.cpp,v $
                             -------------------
    cvs         : $Id: payeeview.cpp,v 1.3 2005/08/31 05:24:20 aquamaniac Exp $
    begin       : Mon Mar 01 2004
    copyright   : (C) 2004 by Martin Preuss
    email       : martin@libchipcard.de

 ***************************************************************************
 *          Please see toplevel file COPYING for license details           *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif


#include "payeeview.h"
#include "editpayee.h"
#include "calcpayee.h"
#include "transactionwindow.h"

#include <kbanking.h>

#include <qevent.h>
#include <qpushbutton.h>
#include <qgroupbox.h>
#include <qmessagebox.h>
#include <qlayout.h>

#include <gwenhywfar/debug.h>

#ifdef WIN32
# define strcasecmp stricmp
#endif

#define BUTTON_WIDTH 110


PayeeView::PayeeView(KBanking *kb,
                     QWidget* parent,
                     const char* name,
                     WFlags fl)
:PayeeViewUi(parent, name, fl), _app(kb) {
  assert(kb);

  // Manually create and add layout here because the .ui-generated
  // QGroupBox doesn't have one.
  payeeBox->setColumnLayout(0, Qt::Vertical );
  QBoxLayout *payeeBoxLayout = new QHBoxLayout(payeeBox->layout() );
  payeeBoxLayout->setAlignment( Qt::AlignTop );

  _payeeList=new PayeeListView((QWidget*)payeeBox, name);
  payeeBoxLayout->addWidget(_payeeList);

  _payeeList->setSelectionMode(QListView::Single);

  QObject::connect((QObject*)kb->flagStaff(),
                   SIGNAL(signalPayeesUpdated()),
                   this, SLOT(slotUpdated()));

  QObject::connect((QObject*)detailsButton, SIGNAL(clicked()),
                   this, SLOT(slotDetails()));
  QObject::connect((QObject*)transactionButton, SIGNAL(clicked()),
                   this, SLOT(slotTransactions()));

  QObject::connect((QObject*)newButton, SIGNAL(clicked()),
                   this, SLOT(slotNew()));
  QObject::connect((QObject*)editButton, SIGNAL(clicked()),
                   this, SLOT(slotEdit()));
  QObject::connect((QObject*)removeButton, SIGNAL(clicked()),
                   this, SLOT(slotRemove()));

  QObject::connect((QObject*)calcButton, SIGNAL(clicked()),
                   this, SLOT(slotCalc()));
  QObject::connect((QObject*)calcAllButton, SIGNAL(clicked()),
                   this, SLOT(slotCalcAll()));

}



PayeeView::~PayeeView(){
}



bool PayeeView::init(){
  GWEN_DB_NODE *db;

  db=_app->getAppData();
  assert(db);
  db=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST,
                      "gui/views/payeeview/dynamic");
  if (db) {
    int i, j;
    const char *p;

    p=GWEN_DB_GetCharValue(db, "sortOrder", 0, "ascending");
    if (p) {
      if (strcasecmp(p, "ascending")==0)
        _payeeList->setSortOrder(Qt::Ascending);
      else
        if (strcasecmp(p, "descending")==0)
          _payeeList->setSortOrder(Qt::Descending);
    }
    i=GWEN_DB_GetIntValue(db, "sortColumn", 0, -1);
    if (i!=-1)
      _payeeList->setSortColumn(i);

    /* found settings */
    for (i=0; i<_payeeList->columns(); i++) {
      _payeeList->setColumnWidthMode(i, QListView::Manual);
      j=GWEN_DB_GetIntValue(db, "columns", i, -1);
      if (j!=-1)
        _payeeList->setColumnWidth(i, j);
    } /* for */
  } /* if settings */

  _payeeList->addPayees(_app->getPayees());
  update();

  return true;
}



bool PayeeView::fini(){
  GWEN_DB_NODE *db;
  int i, j;

  db=_app->getAppData();
  assert(db);
  db=GWEN_DB_GetGroup(db,
                      GWEN_DB_FLAGS_OVERWRITE_GROUPS,
                      "gui/views/payeeview/dynamic");

  switch(_payeeList->sortOrder()) {
  case Qt::Ascending:
    GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_DEFAULT,
                         "sortOrder", "ascending");
    break;
  case Qt::Descending:
    GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_DEFAULT,
                         "sortOrder", "descending");
    break;
  default:
    break;
  }
  GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_DEFAULT,
                      "sortColumn", _payeeList->sortColumn());

  for (i=0; i<_payeeList->columns(); i++) {
    j=_payeeList->columnWidth(i);
    GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_DEFAULT,
                        "columns", j);
  } /* for */

  return true;
}



void PayeeView::slotDetails(){
  Payee *p;

  std::list<Payee*> pl;
  pl=_payeeList->getSelectedPayees();
  if (pl.empty())
    return;
  p=pl.front();

  EditPayee ep(_app, p, true, this);
  ep.exec();
}



void PayeeView::slotNew(){
  Payee *p;

  p=new Payee();
  EditPayee ep(_app, p, false, this);
  if (ep.exec()!=QDialog::Accepted) {
    delete p;
  }
  else {
    if (!_app->addPayee(p)) {
      DBG_ERROR(0, "Could not add payee");
      delete p;
    }
    else {
      update();
    }
  }
}



void PayeeView::slotEdit(){
  Payee *p;

  std::list<Payee*> pl;
  pl=_payeeList->getSelectedPayees();
  if (pl.empty())
    return;
  p=pl.front();

  EditPayee ep(_app, p, false, this);
  if (ep.exec()==QDialog::Accepted)
    update();
}



void PayeeView::slotRemove(){
  Payee *p;

  std::list<Payee*> pl;
  pl=_payeeList->getSelectedPayees();
  if (pl.empty()) {
    QMessageBox::warning(this,
                         tr("Error"),
                         tr("<qt>"
                            "No payee selected."
                            "</qt>"),
                         tr("Dismiss"), 0, 0, 0);
    return;
  }
  p=pl.front();

  if (QMessageBox::warning(this,
                           tr("Delete Payee"),
                           tr("<qt>"
                              "Do you really want to remove "
                              "the selected payee?"
                              "</qt>"),
                           tr("Yes"), tr("No"), 0, 0)!=0)
    return;
  if (_app->removePayee(p)) {
    delete p;
    update();
  }

}



void PayeeView::slotCalc(){
  Payee *p;
  AB_VALUE *inValue;
  AB_VALUE *outValue;

  std::list<Payee*> pl;
  pl=_payeeList->getSelectedPayees();
  if (pl.empty()) {
    QMessageBox::warning(this,
                         tr("Error"),
                         tr("<qt>"
                            "No payee selected."
                            "</qt>"),
                         tr("Dismiss"), 0, 0, 0);
    return;
  }
  p=pl.front();

  inValue=AB_Value_new(0.0, 0);
  outValue=AB_Value_new(0.0, 0);

  CalculatePayee cp(_app, p, inValue, outValue);
  cp.show();
  if (cp.calculate()) {
    p->resetValues();
    p->addInValue(inValue);
    p->addOutValue(outValue);
    _app->flagStaff()->payeesUpdated();
  }
  AB_Value_free(outValue);
  AB_Value_free(inValue);

}



void PayeeView::slotCalcAll(){
  CalculatePayee cp(_app);
  cp.show();
  cp.calculateAll();
}



void PayeeView::slotTransactions() {
  Payee *p;
  std::list<Payee*> pl;

  pl=_payeeList->getSelectedPayees();
  if (pl.empty()) {
    QMessageBox::warning(this,
                         tr("Error"),
                         tr("<qt>"
                            "No payee selected."
                            "</qt>"),
                         tr("Dismiss"), 0, 0, 0);
    return;
  }
  p=pl.front();

  std::list<RefPointer<Transaction> > l;
  CalculatePayee cp(_app, p);
  cp.show();
  if (cp.getTransactions(l)) {
    TransactionWindow *tv;

    tv=new TransactionWindow(_app, l,
                             "PayeeTransactions",
                             0,
                             "TransactionWindow",
                             Qt::WDestructiveClose);
    tv->setCaption(tr("Transactions"));
    if (!tv->init()) {
      QMessageBox::critical(0,
                            tr("Internal Error"),
                            tr("Could not initialize transaction view."),
                            tr("Dismiss"), 0, 0, 0);
      delete tv;
      return;
    }
    tv->show();
  }

}






void PayeeView::update() {
  _payeeList->clear();
  _payeeList->addPayees(_app->getPayees());
}



void PayeeView::slotUpdated() {
  update();
}









Generated by  Doxygen 1.6.0   Back to index