⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lxuserlistdialog.cc

📁 LxBank是一个基于Qt/X的家庭储蓄应用程序
💻 CC
字号:
// ****************************************************************************// // LxBank - home-banking for Linux using the HBCI standard// // Author: Franz Zimmermann                                   83043 Bad Aibling// // Copyright (C) 2002-2003 Franz Zimmermann - farafang@users.sourceforge.net// // This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.// // This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.// // You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.// // ***************************************************************************//// ***************************************************************************// //// $Name:  $//// $State: Exp $//// $Log: LxUserListDialog.cc,v $// Revision 1.6  2003/04/07 22:44:42  arafang// Put all calls of executeQueue into try/catch clause. Check status of jobs in get accounts.//// Revision 1.5  2003/02/20 02:38:03  arafang// Default args in some constructor implementions removed.//// Revision 1.4  2003/02/08 15:25:21  franz// Mail address changed.//// Revision 1.3  2003/01/26 23:09:41  franz// LxAccountSelectDialog: New method to delete accounts (remove).// Class LxAccountStmtPrint adapted to new account statement view layout.// Account update implemented.//// Revision 1.2  2003/01/11 18:35:22  franz// Complete methods of class LxInteractor.// Worked on class LxPinDialog.// Improve class LxUserAddWizard.// Implement methods removeUser and getAccounts in class LxUserListDialog.// Button enable/dissable bug fixed in class LxRemittanceView.//// Revision 1.1  2003/01/07 22:09:32  franz// Added user list dialog.////#ifdef HAVE_CONFIG_H#include <config.h>#endif#include "LxUserListDialog.h"#include "LxUserAddWizard.h"#include <qlistview.h> #include <qpushbutton.h> #include <qlayout.h>#include <qmessagebox.h>LxUserListDialog::LxUserListDialog(LxHbci *hbciapi, AccountList *acclist,				    QWidget *parent, const char *name, 				    bool modal, WFlags f)  : QDialog( parent, name, modal, f ), hbciApi(hbciapi), accList(acclist),     newButton(0), detailButton(0), getAccButton(0), modifyButton(0), removeButton(0), dismButton(0){  setCaption(tr("User List"));   vBox = new QVBoxLayout( this, 3, 5);  lView = new QListView( this, "UsersList" );  vBox->addWidget( lView, 10 );  lView->setAllColumnsShowFocus ( TRUE );   lView->setSelectionMode ( QListView::Single );  int c1, c2, c3, c4;  c1 = lView->addColumn ( tr("No.") );  c2 = lView->addColumn ( tr("User Name") );	        c3 = lView->addColumn ( tr("User Id") );      c4 = lView->addColumn ( tr("Institute") );     lView->setItemMargin ( 2 );  hBox = new QHBoxLayout(vBox, 3);  hBox->addStretch ( 10 );  createButtons ( );  setupUserList ();  connect( lView, SIGNAL( selectionChanged(QListViewItem *) ), this, SLOT( selectionChanged(QListViewItem *) ) );  connect( lView, SIGNAL( pressed(QListViewItem *) ), this, SLOT( pressedInList(QListViewItem *) ) );}void LxUserListDialog::setupUserList (){  int count;  list<HBCI::Pointer<HBCI::User> >::iterator uit;  userList.clear();  lView->clear();  userList = hbciApi->getUsers ( );  for ( uit = userList.begin(), count = 1; uit != userList.end(); ++uit, ++count ) {    addUserToList (count, uit);  }  QListViewItem *item;  item = lView->firstChild ();  if (item){    lView->setSelected ( item, TRUE );  }  setButtonState ( item );}void LxUserListDialog::addUserToList (int count, list<HBCI::Pointer<HBCI::User> >::iterator uit){  QListViewItem *item;  HBCI::Pointer<HBCI::Bank> bank = (**uit).bank();  item = new QListViewItem( lView,			    QString::number(count),			    (**uit).userName().c_str(),			    (**uit).userId().c_str(),			    (*bank).name().c_str() );}void LxUserListDialog::createButtons( ){    newButton = new QPushButton(tr("New"), this);    addButton( newButton );    connect( newButton, SIGNAL( clicked() ), this, SLOT( createUser() ) );    detailButton = new QPushButton(tr("Details"), this);    addButton( detailButton );    connect( detailButton, SIGNAL( clicked() ), this, SLOT( showDetails() ) );    getAccButton = new QPushButton(tr("Get Accounts"), this);    addButton( getAccButton );    connect( getAccButton, SIGNAL( clicked() ), this, SLOT( getAccounts() ) );    modifyButton = new QPushButton(tr("Modify"), this);    addButton( modifyButton );    connect( modifyButton, SIGNAL( clicked() ), this, SLOT( modifyUser() ) );    removeButton = new QPushButton(tr("Delete"), this);    addButton( removeButton );    connect( removeButton, SIGNAL( clicked() ), this, SLOT( remove() ) );    dismButton = new QPushButton(tr("Dismiss"), this);    addButton( dismButton );    connect( dismButton, SIGNAL( clicked() ), this, SLOT( reject() ) );}void LxUserListDialog::addButton( QPushButton *button ){  hBox->addWidget ( button, 0 );  hBox->addStretch ( 10 );}HBCI::Pointer<HBCI::User> LxUserListDialog::getSelectedUser ( ){  int itemNo;  QListViewItem *item;  HBCI::Pointer<HBCI::User> selectedUser;  item = lView->selectedItem();  if ( item ){    itemNo = item->text(0).toInt();    list<HBCI::Pointer<HBCI::User> >::const_iterator uit;    int count = 0;    for ( count = 1, uit = userList.begin(); count < itemNo; ++uit, ++count ){    }    selectedUser = *uit;  }  return selectedUser;  }void LxUserListDialog::selectionChanged ( QListViewItem *lvItem ){  setButtonState ( lvItem ); }void LxUserListDialog::pressedInList ( QListViewItem *lvItem ){  setButtonState ( lvItem ); }void LxUserListDialog::setButtonState ( QListViewItem *lvItem ){  if ( lvItem && lView->selectedItem() ){    if (removeButton)      removeButton->setEnabled(TRUE);    if (detailButton)      detailButton->setEnabled(TRUE);    if (getAccButton)      getAccButton->setEnabled(TRUE);    if (modifyButton)      modifyButton->setEnabled(TRUE);  }else{    if (removeButton)      removeButton->setEnabled(FALSE);    if (detailButton)      detailButton->setEnabled(FALSE);    if (getAccButton)      getAccButton->setEnabled(FALSE);    if (modifyButton)      modifyButton->setEnabled(FALSE);  }}void LxUserListDialog::createUser(){  int res;  LxUserAddWizard *newUser = new LxUserAddWizard(hbciApi);  res = newUser->exec();  if ( res == QDialog::Accepted ){    setupUserList ();    hbciApi->save ();  }}void LxUserListDialog::showDetails(){  QMessageBox::information ( this, tr("Show Details"),			     tr("Not yet implemented!\n"),			     QMessageBox::Ok,			     0);}void LxUserListDialog::getAccounts(){  HBCI::Pointer<HBCI::User> selectedUser = getSelectedUser ();  if ( !selectedUser.isValid () ){    return;  }  HBCI::Error err;  HBCI::Pointer<HBCI::OutboxJob> job;  int jobCount = 0;  int oldVersion = (*selectedUser).version ();  // set user's version to zero; some banks expect this!!! example: Kreissparkasse Bad Aibling  (*selectedUser).setVersion ( 0 );  const list<HBCI::Pointer<HBCI::Customer> > customersOfUser = (*selectedUser).customers();  list<HBCI::Pointer<HBCI::Customer> >::const_iterator cit;  for ( cit = customersOfUser.begin(); cit != customersOfUser.end(); ++cit ){    job = new HBCI::OutboxJobGetAccounts ( *cit );    hbciApi->addJob (job);    ++jobCount;  }  // execute the job(s)  try {    err = hbciApi->executeQueue();    if ( !err.isOk() ){      LxHbci::reportError (err, "LxUserListDialog::getAccounts: Error at executeQueue!");    }  }  catch (HBCI::Error excErr) {    LxHbci::reportError (excErr, "LxUserListDialog::getAccounts: Exeption at executeQueue!");  }  // reset user's version  int curVersion = (*selectedUser).version ();  (*selectedUser).setVersion ( oldVersion + curVersion );  // check the interactor  HBCI::Pointer<HBCI::Interactor> intActor = hbciApi->interactor();  if ( (*intActor).aborted() ){    (*intActor).abort(false);//     cerr << "\nStatus of Interactor after executeQueue: aborted!" << endl;  }//   else{//     cerr << "\nStatus of Interactor after executeQueue: not aborted!" << endl;//   }  list<HBCI::Pointer<HBCI::OutboxJob> > qjobs = hbciApi->queuedJobs ();  list<HBCI::Pointer<HBCI::OutboxJob> >::iterator jb;  int accountsAdded = 0;  LxAccount *oldAccount;  int accNo, maxAccNo;  // found the maximum account number; new accounts gets greater sequence numbers  for ( oldAccount = accList->first(), maxAccNo = 0; oldAccount != 0; oldAccount = accList->next() ){    accNo = oldAccount->getId();    if ( accNo > maxAccNo  ){      maxAccNo = accNo;    }  }  // get user's bank and bank code  HBCI::Pointer<HBCI::Bank> usersBank = (*selectedUser).bank ();  const string &bankCode = (*usersBank).bankCode ();  // get all accounts of user's bank  list<HBCI::Pointer<HBCI::Account> >::iterator accIt;  list<HBCI::Pointer<HBCI::Account> > accountsOfUsersBank = hbciApi->getAccounts (0, bankCode, "*");//   cerr << "\ngetAccounts: user has " << accountsOfUsersBank.size() << " accounts at bank " << bankCode << "!" << endl;  for ( jb = qjobs.begin(); jb != qjobs.end(); ++jb){//     switch ( (**jb).result() ){//     case HBCI_JOB_RESULT_NONE://       cerr << "\ngetAccounts: job was not executed" << endl;//       break;//     case HBCI_JOB_RESULT_SUCCESS://       cerr << "\ngetAccounts: job was successfully performed" << endl;//       break;//     case HBCI_JOB_RESULT_FAILED://       cerr << "\ngetAccounts: job was executed and failed" << endl;//     }    if ( (**jb).result() == HBCI_JOB_RESULT_SUCCESS ){      cerr << "\nGet Account job has been performed successfully! Setup account!" << endl;      LxAccount *newAccount;      bool isNewAccount;      for (accIt = accountsOfUsersBank.begin(); accIt != accountsOfUsersBank.end(); ++accIt){	const string &accId = (**accIt).accountId ();	// see, if we have this account already in our list	for ( oldAccount = accList->first(), isNewAccount = true; oldAccount != 0; oldAccount = accList->next() ){	  string idOfAcc ( oldAccount->getAccountNo().latin1() );	  if ( idOfAcc == accId ){	    isNewAccount = false;	    break;	  }	}	// take it, if this account is new	if ( isNewAccount ){	  ++maxAccNo;	  newAccount = new LxAccount( maxAccNo, hbciApi, *accIt );	  accList->append (newAccount);	  ++accountsAdded;// 	  cerr << "\ngetAccounts: account " << (**accIt).accountId() << " added!" << endl;	}      }    }else{      cerr << "\nGet Account job has not been performed successfully!" << endl;    }  }  if ( accountsAdded ){    hbciApi->save ();    setupUserList ();  }  // clear queue//   cerr << "\nClear queue!\n\nNumber of queued jobs = " << qjobs.size() << endl;  for ( jb = qjobs.begin(); jb != qjobs.end(); ++jb){    hbciApi->removeQueuedJob ( *jb );  }//   qjobs = hbciApi->queuedJobs ();//   cerr << "\nNumber of queued jobs = " << qjobs.size() << endl;}void LxUserListDialog::modifyUser(){  QMessageBox::information ( this, tr("Modify User"),			     tr("Not yet implemented!\n"),			     QMessageBox::Ok,			     0);}void LxUserListDialog::remove(){  HBCI::Pointer<HBCI::User> user = getSelectedUser ();  if ( user.isValid () ){    switch( QMessageBox::warning ( this, tr("Confirm Delete"), 				   tr("Do you really want to delete this user?"),				   tr("Ok"), tr("Cancel"), QString::null, 1, 1 ) ){    case 0: // The user clicked the Ok button      removeUser ( user );      break;    case 1: // The user clicked the Cancel button, or pressed Enter or Escape      return;      break;    }  }}void LxUserListDialog::removeUser( HBCI::Pointer<HBCI::User> user ){  bool userHasAnAccount = false;  HBCI::Pointer<HBCI::Bank> bank = (*user).bank ();  HBCI::Pointer<HBCI::Medium> medium = (*user).medium ();  int secMode = (*medium).securityMode ();  const list<HBCI::Pointer<HBCI::Customer> > customersOfUser = (*user).customers ();  const list<HBCI::Pointer<HBCI::Account> > allAccountsAtUsersBank = (*bank).accounts ();  list<HBCI::Pointer<HBCI::Account> >::const_iterator ait;  list<HBCI::Pointer<HBCI::Account> > allAccountsOfUser;  for ( ait = allAccountsAtUsersBank.begin(); ait != allAccountsAtUsersBank.end(); ++ait ){     const list<HBCI::Pointer<HBCI::Customer> > customersOfAccount = (**ait).authorizedCustomers();    list<HBCI::Pointer<HBCI::Customer> >::const_iterator cait;    for ( cait = customersOfAccount.begin(); cait != customersOfAccount.end(); ++cait ){      list<HBCI::Pointer<HBCI::Customer> >::const_iterator cuit;	      for ( cuit = customersOfUser.begin(); cuit != customersOfUser.end(); ++cuit ){	if ( (**cait).custId() == (**cuit).custId() ){	  allAccountsOfUser.push_back(*ait);	}      }    }  }  if ( !allAccountsOfUser.empty() ){    userHasAnAccount = true;  }  if ( userHasAnAccount ){    QString msg;    list<HBCI::Pointer<HBCI::Account> >::iterator ac;    if ( allAccountsOfUser.size() == 1 ){      msg  = tr("Cannot remove this user!\n\nThis user owns still one account!\nAccount Number: ");      ac = allAccountsOfUser.begin();      msg += (**ac).accountId().c_str();    }else{      msg  = tr("Cannot remove this user!\n\nThis user owns still ");      msg += QString::number( allAccountsOfUser.size() );      msg += tr(" accounts!\nAccount Numbers: ");      ac = allAccountsOfUser.begin();      msg += (**ac).accountId().c_str();      for (++ac; ac != allAccountsOfUser.end(); ++ac){	msg += ", ";	msg += (**ac).accountId().c_str();      }    }    QMessageBox::critical ( this, tr("Delete User"),			    msg,			    QMessageBox::Ok,			    0);  }else{    switch (secMode){    case HBCI_SECURITY_DDV:      if ( (*medium).isMounted () ){	(*medium).unmountMedium();      }      break;    case HBCI_SECURITY_RDH:      // destroy medium      break;    }    (*bank).removeUser ( user );     // delete bank if no users remaining    const list<HBCI::Pointer<HBCI::User> > bankUsers = (*bank).users();    if ( bankUsers.empty() ){      hbciApi->removeBank(bank);    }    setupUserList ();    hbciApi->save ();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -