author | drw <drw> | 2005-05-16 18:28:46 (UTC) |
---|---|---|
committer | drw <drw> | 2005-05-16 18:28:46 (UTC) |
commit | 1a6137e3182a1b6974b64e22017207c32f9d4f7c (patch) (side-by-side diff) | |
tree | 181be57df97461f2ea05eed85198ff373d4dd2f9 | |
parent | 97a12da2b324be1545b2b6942a14ab813e1a735b (diff) | |
download | opie-1a6137e3182a1b6974b64e22017207c32f9d4f7c.zip opie-1a6137e3182a1b6974b64e22017207c32f9d4f7c.tar.gz opie-1a6137e3182a1b6974b64e22017207c32f9d4f7c.tar.bz2 |
Resource -> OResource
-rw-r--r-- | noncore/apps/checkbook/checkbook.cpp | 62 | ||||
-rw-r--r-- | noncore/apps/checkbook/listedit.cpp | 56 | ||||
-rw-r--r-- | noncore/apps/checkbook/mainwindow.cpp | 67 |
3 files changed, 102 insertions, 83 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp index 44d3764..b325f45 100644 --- a/noncore/apps/checkbook/checkbook.cpp +++ b/noncore/apps/checkbook/checkbook.cpp @@ -1,484 +1,494 @@ /* - This file is part of the OPIE Project + This file is part of the OPIE Project =. - .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> - .>+-= - _;:, .> :=|. This file is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU General Public -.="- .-=="i, .._ License as published by the Free Software - - . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This file 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 file; - -_. . . )=. = see the file COPYING. If not, write to the - -- :-=` Free Software Foundation, Inc., + .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> + .>+-= +_;:, .> :=|. This file is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This file 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 file; + -_. . . )=. = see the file COPYING. If not, write to the + -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "checkbook.h" #include "cbinfo.h" #include "transaction.h" #include "traninfo.h" #include "graph.h" #include "graphinfo.h" #include "password.h" #include "cfg.h" +#include <opie2/oresource.h> + +#include <qpe/applnk.h> #include <qpe/qpeapplication.h> #include <qpe/qpemessagebox.h> -#include <qpe/resource.h> #include <qcheckbox.h> #include <qcombobox.h> #include <qlabel.h> #include <qlayout.h> #include <qlineedit.h> #include <qmultilineedit.h> #include <qpushbutton.h> #include <qwhatsthis.h> #include <qpopupmenu.h> #define COL_ID 0 #define COL_SORTDATE 1 #define COL_NUM 2 #define COL_DATE 3 #define COL_DESC 4 #define COL_AMOUNT 5 #define COL_BAL 6 // --- Checkbook -------------------------------------------------------------- using namespace Opie::Ui; Checkbook::Checkbook( QWidget *parent, CBInfo *i, Cfg *cfg ) : QDialog( parent, 0, TRUE, WStyle_ContextHelp ) { info = i; _pCfg=cfg; // Title bar if ( info->name() != "" ) { QString tempstr = info->name(); tempstr.append( " - " ); tempstr.append( tr( "Checkbook" ) ); setCaption( tempstr ); } else { setCaption( tr( "New checkbook" ) ); } // Setup layout to make everything pretty QVBoxLayout *layout = new QVBoxLayout( this ); layout->setMargin( 2 ); layout->setSpacing( 4 ); // Setup tabs for all info mainWidget = new OTabWidget( this ); layout->addWidget( mainWidget ); mainWidget->addTab( initInfo(), "checkbook/infotab", tr( "Info" ) ); mainWidget->addTab( initTransactions(), "checkbook/trantab", tr( "Transactions" ) ); mainWidget->addTab( initCharts(), "checkbook/charttab", tr( "Charts" ) ); if( _pCfg->isShowLastTab() ) mainWidget->setCurrentTab( info->getLastTab() ); else mainWidget->setCurrentTab( tr( "Info" ) ); connect( mainWidget, SIGNAL( currentChanged(QWidget*) ), this, SLOT( slotTab(QWidget*) ) ); // Load checkbook information loadCheckbook(); } Checkbook::~Checkbook() { } // --- initInfo --------------------------------------------------------------- QWidget *Checkbook::initInfo() { QWidget *control = new QWidget( mainWidget, tr("Info") ); QVBoxLayout *vb = new QVBoxLayout( control ); QScrollView *sv = new QScrollView( control ); vb->addWidget( sv, 0, 0 ); sv->setResizePolicy( QScrollView::AutoOneFit ); sv->setFrameStyle( QFrame::NoFrame ); QWidget *container = new QWidget( sv->viewport() ); sv->addChild( container ); QGridLayout *layout = new QGridLayout( container ); layout->setSpacing( 2 ); layout->setMargin( 4 ); // Password protection passwordCB = new QCheckBox( tr( "Password protect" ), container ); QWhatsThis::add( passwordCB, tr( "Click here to enable/disable password protection of this checkbook." ) ); connect( passwordCB, SIGNAL( clicked() ), this, SLOT( slotPasswordClicked() ) ); layout->addMultiCellWidget( passwordCB, 0, 0, 0, 1 ); // Account name QLabel *label = new QLabel( tr( "Name:" ), container ); QWhatsThis::add( label, tr( "Enter name of checkbook here." ) ); layout->addWidget( label, 1, 0 ); nameEdit = new QLineEdit( container ); QWhatsThis::add( nameEdit, tr( "Enter name of checkbook here." ) ); connect( nameEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotNameChanged(const QString&) ) ); layout->addWidget( nameEdit, 1, 1 ); // Type of account label = new QLabel( tr( "Type:" ), container ); QWhatsThis::add( label, tr( "Select type of checkbook here." ) ); layout->addWidget( label, 2, 0 ); typeList = new QComboBox( container ); QWhatsThis::add( typeList, tr( "Select type of checkbook here." ) ); typeList->insertStringList( _pCfg->getAccountTypes() ); layout->addWidget( typeList, 2, 1 ); // Bank/institution name label = new QLabel( tr( "Bank:" ), container ); QWhatsThis::add( label, tr( "Enter name of the bank for this checkbook here." ) ); layout->addWidget( label, 3, 0 ); bankEdit = new QLineEdit( container ); QWhatsThis::add( bankEdit, tr( "Enter name of the bank for this checkbook here." ) ); layout->addWidget( bankEdit, 3, 1 ); // Account number label = new QLabel( tr( "Account number:" ), container ); QWhatsThis::add( label, tr( "Enter account number for this checkbook here." ) ); layout->addWidget( label, 4, 0 ); acctNumEdit = new QLineEdit( container ); QWhatsThis::add( acctNumEdit, tr( "Enter account number for this checkbook here." ) ); layout->addWidget( acctNumEdit, 4, 1 ); // PIN number label = new QLabel( tr( "PIN number:" ), container ); QWhatsThis::add( label, tr( "Enter PIN number for this checkbook here." ) ); layout->addWidget( label, 5, 0 ); pinNumEdit = new QLineEdit( container ); QWhatsThis::add( pinNumEdit, tr( "Enter PIN number for this checkbook here." ) ); layout->addWidget( pinNumEdit, 5, 1 ); // Starting balance label = new QLabel( tr( "Starting balance:" ), container ); QWhatsThis::add( label, tr( "Enter the initial balance for this checkbook here." ) ); layout->addWidget( label, 6, 0 ); balanceEdit = new QLineEdit( container ); QWhatsThis::add( balanceEdit, tr( "Enter the initial balance for this checkbook here." ) ); connect( balanceEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotStartingBalanceChanged(const QString&) ) ); layout->addWidget( balanceEdit, 6, 1 ); // Notes label = new QLabel( tr( "Notes:" ), container ); QWhatsThis::add( label, tr( "Enter any additional information for this checkbook here." ) ); layout->addWidget( label, 7, 0 ); notesEdit = new QMultiLineEdit( container ); QWhatsThis::add( notesEdit, tr( "Enter any additional information for this checkbook here." ) ); notesEdit->setMinimumHeight( 25 ); notesEdit->setMaximumHeight( 65 ); layout->addMultiCellWidget( notesEdit, 8, 8, 0, 1 ); return control; } // --- initTransactions ------------------------------------------------------- QWidget *Checkbook::initTransactions() { QWidget *control = new QWidget( mainWidget, tr("Transactions") ); QGridLayout *layout = new QGridLayout( control ); layout->setSpacing( 2 ); layout->setMargin( 4 ); // Sort selector QLabel *label = new QLabel( tr( "Sort by:" ), control ); QWhatsThis::add( label, tr( "Select checkbook sorting here." ) ); layout->addMultiCellWidget( label, 0, 0, 0, 1 ); _cbSortType=new QComboBox( control ); _cbSortType->insertItem( tr("Entry Order") ); _cbSortType->insertItem( tr("Date") ); _cbSortType->insertItem( tr("Number") ); layout->addMultiCellWidget( _cbSortType, 0, 0, 1, 2 ); connect( _cbSortType, SIGNAL( activated(const QString&) ), this, SLOT( slotSortChanged(const QString&) ) ); // Table tranTable = new QListView( control ); QFont fnt(QPEApplication::font()); fnt.setPointSize( fnt.pointSize()-1 ); tranTable->setFont( fnt ); QWhatsThis::add( tranTable, tr( "This is a listing of all transactions entered for this checkbook.\n\nTo sort entries by a specific field, click on the column name." ) ); tranTable->addColumn( tr( "Id" ) ); tranTable->setColumnWidthMode( COL_ID, QListView::Manual ); tranTable->setColumnWidth( COL_ID, 0); tranTable->addColumn( tr( "SortDate" ) ); tranTable->setColumnWidthMode( COL_SORTDATE, QListView::Manual ); tranTable->setColumnWidth( COL_SORTDATE, 0); tranTable->addColumn( tr( "Num" ) ); tranTable->addColumn( tr( "Date" ) ); //tranTable->addColumn( tr( "Cleared" ) ); tranTable->addColumn( tr( "Description" ) ); int column = tranTable->addColumn( tr( "Amount" ) ); tranTable->setColumnAlignment( column, Qt::AlignRight ); column=tranTable->addColumn( tr("Balance") ); tranTable->setColumnAlignment( column, Qt::AlignRight ); tranTable->setAllColumnsShowFocus( TRUE ); tranTable->setSorting( -1 ); layout->addMultiCellWidget( tranTable, 1, 1, 0, 2 ); QPEApplication::setStylusOperation( tranTable->viewport(), QPEApplication::RightOnHold ); connect( tranTable, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), this, SLOT( slotMenuTran(QListViewItem*,const QPoint&) ) ); connect( tranTable, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( slotEditTran() ) ); _sortCol=COL_ID; // Buttons - QPushButton *btn = new QPushButton( Resource::loadPixmap( "new" ), tr( "New" ), control ); + QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), + tr( "New" ), control ); + btn->setFixedHeight( AppLnk::smallIconSize()+4 ); QWhatsThis::add( btn, tr( "Click here to add a new transaction." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotNewTran() ) ); layout->addWidget( btn, 2, 0 ); - btn = new QPushButton( Resource::loadPixmap( "edit" ), tr( "Edit" ), control ); + btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), + tr( "Edit" ), control ); + btn->setFixedHeight( AppLnk::smallIconSize()+4 ); QWhatsThis::add( btn, tr( "Select a transaction and then click here to edit it." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotEditTran() ) ); layout->addWidget( btn, 2, 1 ); - btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), control ); + btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), + tr( "Delete" ), control ); + btn->setFixedHeight( AppLnk::smallIconSize()+4 ); QWhatsThis::add( btn, tr( "Select a checkbook and then click here to delete it." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotDeleteTran() ) ); layout->addWidget( btn, 2, 2 ); return( control ); } // --- initCharts ------------------------------------------------------------- QWidget *Checkbook::initCharts() { graphInfo = 0x0; QWidget *control = new QWidget( mainWidget, tr("Charts") ); QGridLayout *layout = new QGridLayout( control ); layout->setSpacing( 2 ); layout->setMargin( 4 ); graphWidget = new Graph( control ); QWhatsThis::add( graphWidget, tr( "Select the desired chart below and then click on the Draw button." ) ); layout->addMultiCellWidget( graphWidget, 0, 0, 0, 2 ); graphList = new QComboBox( control ); QWhatsThis::add( graphList, tr( "Click here to select the desired chart type." ) ); graphList->insertItem( tr( "Account balance" ) ); graphList->insertItem( tr( "Withdrawals by category" ) ); graphList->insertItem( tr( "Deposits by category" ) ); layout->addMultiCellWidget( graphList, 1, 1, 0, 1 ); - QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control ); + QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "checkbook/drawbtn", Opie::Core::OResource::SmallIcon ), + tr( "Draw" ), control ); + btn->setFixedHeight( AppLnk::smallIconSize()+4 ); QWhatsThis::add( btn, tr( "Click here to draw the selected chart." ) ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotDrawGraph() ) ); layout->addWidget( btn, 1, 2 ); return control; } // --- loadCheckbook ---------------------------------------------------------- void Checkbook::loadCheckbook() { if ( !info ) { return; } tranList = info->transactions(); passwordCB->setChecked( !info->password().isNull() ); nameEdit->setText( info->name() ); QString temptext = info->type(); int i = typeList->count(); while ( i > 0 ) { i--; typeList->setCurrentItem( i ); if ( typeList->currentText() == temptext ) { break; } } if( i<=0 ) { typeList->insertItem( temptext, 0 ); typeList->setCurrentItem(0); } bankEdit->setText( info->bank() ); acctNumEdit->setText( info->account() ); pinNumEdit->setText( info->pin() ); temptext.setNum( info->startingBalance(), 'f', 2 ); balanceEdit->setText( temptext ); notesEdit->setText( info->notes() ); // Load transactions float amount; QString stramount; QString symbol = _pCfg->getCurrencySymbol(); for ( TranInfo *tran = tranList->first(); tran; tran = tranList->next() ) { amount = tran->amount(); if ( tran->withdrawal() ) { amount *= -1; } stramount.sprintf( "%.2f", amount ); stramount.prepend( symbol ); ( void ) new CBListItem( tran, tranTable, tran->getIdStr(), tran->datestr(false), tran->number(), tran->datestr(true), tran->desc(), stramount ); } // set sort order bool bOk=false; for(int i=0; i<_cbSortType->count(); i++) { if( _cbSortType->text(i)==info->getSortOrder() ) { _cbSortType->setCurrentItem(i); slotSortChanged( info->getSortOrder() ); bOk=true; break; } } if( !bOk ) { _cbSortType->setCurrentItem(0); slotSortChanged( _cbSortType->currentText() ); } // calc running balance adjustBalance(); } // --- adjustBalance ---------------------------------------------------------- void Checkbook::adjustBalance() { // update running balance in register QString sRunning; QString symbol = _pCfg->getCurrencySymbol(); float bal=info->startingBalance(); for(CBListItem *item=(CBListItem *)tranTable->firstChild(); item; item=(CBListItem *)item->nextSibling() ) { TranInfo *tran=item->getTranInfo(); bal=bal + (tran->withdrawal() ? -1 : 1)*tran->amount() - tran->fee(); sRunning.sprintf( "%.2f", bal ); sRunning.prepend(symbol); item->setText( COL_BAL, sRunning); } } // --- resort ----------------------------------------------------------------- void Checkbook::resort() { tranTable->setSorting(_sortCol); tranTable->sort(); tranTable->setSorting(-1); } // --- accept ----------------------------------------------------------------- void Checkbook::accept() { info->setName( nameEdit->text() ); info->setType( typeList->currentText() ); info->setBank( bankEdit->text() ); info->setAccount( acctNumEdit->text() ); info->setPin( pinNumEdit->text() ); bool ok; info->setStartingBalance( balanceEdit->text().toFloat( &ok ) ); info->setNotes( notesEdit->text() ); QDialog::accept(); } // --- slotPasswordClicked ---------------------------------------------------- void Checkbook::slotPasswordClicked() { if ( info->password().isNull() && passwordCB->isChecked() ) { Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); if ( pw->exec() != QDialog::Accepted ) { passwordCB->setChecked( FALSE ); delete pw; return; } info->setPassword( pw->password ); delete pw; pw = new Password( this, tr( "Confirm password" ), tr( "Please confirm your password:" ) ); if ( pw->exec() != QDialog::Accepted || pw->password != info->password() ) { passwordCB->setChecked( FALSE ); info->setPassword( QString::null ); } delete pw; } else if ( !info->password().isNull() && !passwordCB->isChecked() ) { Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password to confirm removal of password protection:" ) ); if ( pw->exec() == QDialog::Accepted && pw->password == info->password() ) { info->setPassword( QString::null ); delete pw; return; } else { passwordCB->setChecked( TRUE ); } delete pw; } } void Checkbook::slotNameChanged( const QString &newname ) { info->setName( newname ); // TODO - need filedir // QString namestr = filedir; // namestr.append( newname ); // namestr.append( ".qcb" ); // info->setFilename( namestr ); QString namestr = newname; namestr.append( " - " ); namestr.append( tr( "Checkbook" ) ); setCaption( namestr ); } // ---slotStartingBalanceChanged ---------------------------------------------- void Checkbook::slotStartingBalanceChanged( const QString &newbalance ) { bool ok; info->setStartingBalance( newbalance.toFloat( &ok ) ); adjustBalance(); } // --- slotNewTran ------------------------------------------------------------ void Checkbook::slotNewTran() { TranInfo *traninfo = new TranInfo( info->getNextNumber() ); if( !_dLastNew.isNull() ) diff --git a/noncore/apps/checkbook/listedit.cpp b/noncore/apps/checkbook/listedit.cpp index 2612488..e40377b 100644 --- a/noncore/apps/checkbook/listedit.cpp +++ b/noncore/apps/checkbook/listedit.cpp @@ -1,279 +1,285 @@ /* - This file is part of the OPIE Project + This file is part of the OPIE Project =. - .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> - .>+-= - _;:, .> :=|. This file is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU General Public -.="- .-=="i, .._ License as published by the Free Software - - . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This file 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 file; - -_. . . )=. = see the file COPYING. If not, write to the - -- :-=` Free Software Foundation, Inc., + .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> + .>+-= +_;:, .> :=|. This file is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This file 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 file; + -_. . . )=. = see the file COPYING. If not, write to the + -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "listedit.h" /* OPIE */ #include <opie2/odebug.h> -#include <qpe/resource.h> +#include <opie2/oresource.h> + +#include <qpe/applnk.h> + using namespace Opie::Core; /* QT */ #include <qlayout.h> #include <qlineedit.h> #include <qlistview.h> #include <qwidgetstack.h> #include <qcombobox.h> #include <qpushbutton.h> // --- ListEdit --------------------------------------------------------------- ListEdit::ListEdit( QWidget *parent, const char *sName ) : QWidget(parent, sName), TableDef(sName) { // get font height int fh = fontMetrics().height(); // create layout QGridLayout *layout=new QGridLayout(this); layout->setSpacing( 2 ); layout->setMargin( 4 ); // type table _typeTable = new QListView( this ); ColumnDef *def=first(); while( def ) { _typeTable->addColumn( def->getName() ); def=next(); } connect( _typeTable, SIGNAL( clicked(QListViewItem*,const QPoint&,int) ), this, SLOT( slotClick(QListViewItem*,const QPoint&,int) ) ); layout->addMultiCellWidget(_typeTable, 0,4,0,4); _currentItem=NULL; // edit field _stack=new QWidgetStack( this ); _stack->setMaximumHeight(fh+5); layout->addMultiCellWidget(_stack, 5,5,0,2); _typeEdit = new QLineEdit( _stack ); _stack->raiseWidget(_typeEdit ); connect( _typeEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotEditChanged(const QString&) ) ); // combo box _box=new QComboBox( _stack ); connect( _box, SIGNAL( activated(const QString&) ), this, SLOT( slotActivated(const QString&) ) ); // add button - QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/add" ), tr( "Add" ), this ); + QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), + tr( "Add" ), this ); + btn->setFixedHeight( AppLnk::smallIconSize()+4 ); connect( btn, SIGNAL( clicked() ), this, SLOT( slotAdd() ) ); layout->addWidget( btn, 5, 3 ); // delete button - btn = new QPushButton( Resource::loadPixmap( "trash" ), tr( "Delete" ), this ); - connect( btn, SIGNAL( clicked() ), this, SLOT( slotDel() ) ); + btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), this ); + btn->setFixedHeight( AppLnk::smallIconSize()+4 ); + connect( btn, SIGNAL( clicked() ), this, SLOT( slotDel() ) ); layout->addWidget( btn, 5, 4 ); } // --- ~ListEdit -------------------------------------------------------------- ListEdit::~ListEdit() { } // --- slotEditTypeChanged ---------------------------------------------------- void ListEdit::slotEditChanged(const QString &str) { if( !_currentItem || _currentColumn<0 ) return; _currentItem->setText(_currentColumn, str); } // --- slotAddType ------------------------------------------------------------ void ListEdit::slotAdd() { // construct new row QString args[8]; ColumnDef *pCol=this->first(); int i=0; while( pCol && i<8 ) { args[i++]=pCol->getNewValue(); pCol=this->next(); } _currentItem=new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7] ); // fix uniques fixTypes(); // display col 0 of new value QPoint pnt; slotClick(_currentItem, pnt, 0); _typeTable->setSelected( _currentItem, true ); // make it selected _typeEdit->setCursorPosition(0); _typeEdit->setSelection(0, _typeEdit->text().length() ); } // --- slotDel ------------------------------------------------------------- void ListEdit::slotDel() { if( !_currentItem ) return; delete _currentItem; _currentItem=NULL; _typeEdit->setText(""); _stack->raiseWidget(_typeEdit); } // --- fixTypes ---------------------------------------------------------------- // Makes sure all entries have a unique name and empty entries are replaced // by a generic string. The first version performs the operation on a particular // column, whereas the 2nd does it for all unique columns. class ColMap { public: ColMap(QString sValue, QListViewItem *pEntry) { _sValue=sValue; _pEntry=pEntry; } QString &getValue() { return(_sValue); } QListViewItem *getItem() { return(_pEntry); } protected: QString _sValue; QListViewItem *_pEntry; }; class ColList : public QList<QString> { public: ColList() : QList<QString>() { } protected: int compareItems(QCollection::Item, QCollection::Item); }; int ColList::compareItems(QCollection::Item i1, QCollection::Item i2) { return( ((QString *)i1)->compare(*(QString *)i2) ); } void ListEdit::fixTypes(int iColumn) { // get column def ColumnDef *pDef=this->at(iColumn); // create map of entries if( !_typeTable->childCount() ) return; ColMap **colMap=new ColMap *[_typeTable->childCount()]; QListViewItem *cur=_typeTable->firstChild(); ColList lst; for(int i=0; i<_typeTable->childCount(); i++) { colMap[i]=new ColMap(cur->text(iColumn), cur); lst.append( &(colMap[i]->getValue()) ); cur=cur->nextSibling(); } // fix empty entries int i=0; for(QString *ptr=lst.first(); ptr; ptr=lst.next()) { *ptr=ptr->stripWhiteSpace(); if( ptr->isEmpty() ) { i++; if( i==1 ) *ptr=pDef->getNewValue(); else ptr->sprintf("%s %d", (const char *)pDef->getNewValue(), i); } } // fix dups lst.sort(); QString repl; for(uint iCur=0; iCur<lst.count()-1; iCur++) { QString *current=lst.at(iCur); for(uint iNext=iCur+1; iNext<lst.count(); iNext++ ) { if( *current!=*lst.at(iNext) ) continue; for(int i=2; ; i++) { repl.sprintf("%s %d", (const char *)*current, i); bool bDup=false; uint iChk=iNext+1; while( iChk<lst.count() ) { QString *chk=lst.at(iChk); if( !chk->startsWith(*current) ) break; if( *chk==repl ) { bDup=true; break; } iChk++; } if( !bDup ) { *lst.at(iNext)=repl; break; } } } } lst.sort(); // copy back clean up col map for(int i=0; i<_typeTable->childCount(); i++) { colMap[i]->getItem()->setText(iColumn, colMap[i]->getValue()); delete colMap[i]; } delete colMap; } void ListEdit::fixTypes() { int i; ColumnDef *pDef; for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { if( pDef->hasFlag(ColumnDef::typeUnique) ) fixTypes(i); } _typeTable->sort(); } // --- storeInList ------------------------------------------------------------ void ListEdit::storeInList(QStringList &lst) { // delete old content lst.clear(); // add new one fixTypes(); QListViewItem *itm=_typeTable->firstChild(); while( itm ) { int i=0; QString sAdd; ColumnDef *pDef; for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { if( i>=1 ) sAdd+=";"; sAdd += itm->text(i); } lst.append( sAdd ); itm=itm->nextSibling(); } } // --- slotClicked ------------------------------------------------------------ void ListEdit::slotClick(QListViewItem *itm, const QPoint &pnt, int col) { (void)pnt; // get rid of unused warning; // save values _currentItem=itm; _currentColumn=col; if( itm==NULL ) { diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp index c7ffa7c..d9e2047 100644 --- a/noncore/apps/checkbook/mainwindow.cpp +++ b/noncore/apps/checkbook/mainwindow.cpp @@ -1,351 +1,354 @@ /* - This file is part of the OPIE Project + This file is part of the OPIE Project =. - .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> - .>+-= - _;:, .> :=|. This file is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU General Public -.="- .-=="i, .._ License as published by the Free Software - - . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This file 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 file; - -_. . . )=. = see the file COPYING. If not, write to the - -- :-=` Free Software Foundation, Inc., + .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> + .>+-= +_;:, .> :=|. This file is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This file 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 file; + -_. . . )=. = see the file COPYING. If not, write to the + -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "mainwindow.h" #include "cbinfo.h" #include "configuration.h" #include "password.h" #include "checkbook.h" +#include <opie2/oresource.h> + #include <qpe/config.h> #include <qpe/qpeapplication.h> #include <qpe/qpemessagebox.h> -#include <qtoolbar.h> -#include <qpe/resource.h> -#include <qmenubar.h> #include <qaction.h> #include <qdir.h> +#include <qmenubar.h> +#include <qtoolbar.h> #include <qwhatsthis.h> MainWindow::MainWindow( QWidget* parent, const char* name, WFlags /*fl*/ ) : QMainWindow( parent, name, WStyle_ContextHelp ) { setCaption( tr( "Checkbook" ) ); cbDir = Global::applicationFileName( "checkbook", "" ); - lockIcon = Resource::loadPixmap( "locked" ); + lockIcon = Opie::Core::OResource::loadPixmap( "locked", Opie::Core::OResource::SmallIcon ); // Load configuration options Config config( "checkbook" ); _cfg.readConfig( config ); // Build menu and tool bars setToolBarsMovable( FALSE ); QToolBar *bar = new QToolBar( this ); bar->setHorizontalStretchable( TRUE ); QMenuBar *mb = new QMenuBar( bar ); mb->setMargin( 0 ); QPopupMenu *popup = new QPopupMenu( this ); bar = new QToolBar( this ); - QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); + QAction *a = new QAction( tr( "New" ), Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), + QString::null, 0, this, 0 ); a->setWhatsThis( tr( "Click here to create a new checkbook.\n\nYou also can select New from the Checkbook menu." ) ); connect( a, SIGNAL( activated() ), this, SLOT( slotNew() ) ); a->addTo( popup ); a->addTo( bar ); - actionOpen = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, - 0, this, 0 ); + actionOpen = new QAction( tr( "Edit" ), Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), + QString::null, 0, this, 0 ); actionOpen->setWhatsThis( tr( "Select a checkbook and then click here to edit it.\n\nYou also can select Edit from the Checkbook menu, or click and hold on a checkbook name." ) ); connect( actionOpen, SIGNAL( activated() ), this, SLOT( slotEdit() ) ); actionOpen->addTo( popup ); actionOpen->addTo( bar ); - actionDelete = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, - 0, this, 0 ); + actionDelete = new QAction( tr( "Delete" ), Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), + QString::null, 0, this, 0 ); actionDelete->setWhatsThis( tr( "Select a checkbook and then click here delete it.\n\nYou also can select Delete from the Checkbook menu." ) ); connect( actionDelete, SIGNAL( activated() ), this, SLOT( slotDelete() ) ); actionDelete->addTo( popup ); actionDelete->addTo( bar ); popup->insertSeparator(); - a = new QAction( tr( "Configure" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, 0, this, 0 ); + a = new QAction( tr( "Configure" ), Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), + QString::null, 0, this, 0 ); a->setWhatsThis( tr( "Click here to configure this app." ) ); connect( a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) ); a->addTo( popup ); a->addTo( bar ); mb->insertItem( tr( "Checkbook" ), popup ); // Load Checkbook selection list checkbooks = new CBInfoList(); QDir checkdir( cbDir ); if (checkdir.exists() == true) { QStringList cblist = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable, QDir::Time ); CBInfo *cb = 0x0; QString filename; for ( QStringList::Iterator it = cblist.begin(); it != cblist.end(); it++ ) { filename = cbDir; filename.append( (*it) ); cb = new CBInfo( (*it).remove( (*it).find('.'), (*it).length() ), filename ); checkbooks->inSort( cb ); } } // Build Checkbook selection list control cbList = 0x0; buildList(); // open last book? if( _cfg.isOpenLastBook() ) { this->show(); this->showMaximized(); QListViewItem *itm=cbList->firstChild(); while( itm ) { if( itm->text(posName)==_cfg.getLastBook() ) { openBook( itm ); break; } itm=itm->nextSibling(); } } } // --- ~MainWindow ------------------------------------------------------------ MainWindow::~MainWindow() { writeConfig(); } // --- buildList -------------------------------------------------------------- void MainWindow::buildList() { if ( cbList ) delete cbList; cbList = new QListView( this ); QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) ); if ( _cfg.getShowLocks() ) { - cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 ); + cbList->addColumn( lockIcon, "", 24 ); posName = 1; } else { posName = 0; } cbList->addColumn( tr( "Checkbook Name" ) ); if ( _cfg.getShowBalances() ) { int colnum = cbList->addColumn( tr( "Balance" ) ); cbList->setColumnAlignment( colnum, Qt::AlignRight ); } cbList->setAllColumnsShowFocus( TRUE ); cbList->setSorting( posName ); QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold ); connect( cbList, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), this, SLOT( slotEdit() ) ); setCentralWidget( cbList ); for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() ) { addCheckbook( cb ); } } void MainWindow::addCheckbook( CBInfo *cb ) { QListViewItem *lvi = new QListViewItem( cbList ); if ( _cfg.getShowLocks() && !cb->password().isNull() ) { lvi->setPixmap( 0, lockIcon ); } lvi->setText( posName, cb->name() ); if ( _cfg.getShowBalances() ) { QString balance; balance.sprintf( "%.2f", cb->balance() ); balance.prepend( _cfg.getCurrencySymbol() ); lvi->setText( posName + 1, balance ); } } void MainWindow::buildFilename( const QString &name ) { tempFilename = cbDir; tempFilename.append( name ); tempFilename.append( ".qcb" ); } void MainWindow::slotNew() { CBInfo *cb = new CBInfo(); Checkbook *currcb = new Checkbook( this, cb, &_cfg ); if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted ) { // Save new checkbook buildFilename( cb->name() ); _cfg.setLastBook( cb->name() ); cb->setFilename( tempFilename ); cb->write(); // Add to listbox checkbooks->inSort( cb ); addCheckbook( cb ); } delete currcb; } // --- slotEdit --------------------------------------------------------------- void MainWindow::slotEdit() { // get name and open it QListViewItem *curritem = cbList->currentItem(); if ( !curritem ) return; openBook( curritem ); } // --- openBook --------------------------------------------------------------- void MainWindow::openBook(QListViewItem *curritem) { // find book in List QString currname=curritem->text(posName); CBInfo *cb = checkbooks->first(); while ( cb ) { if ( cb->name() == currname ) break; cb = checkbooks->next(); } if ( !cb ) return; // buildFilename( currname ); float currbalance = cb->balance(); bool currlock = !cb->password().isNull(); if ( currlock ) { Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() ) { delete pw; return; } delete pw; } _cfg.setLastBook( currname ); Checkbook *currcb = new Checkbook( this, cb, &_cfg ); if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted ) { QString newname = cb->name(); if ( currname != newname ) { // Update name if changed if( curritem ) { curritem->setText( posName, newname ); cbList->sort(); } _cfg.setLastBook( newname ); // Remove old file QFile f( tempFilename ); if ( f.exists() ) f.remove(); // Get new filename buildFilename( newname ); cb->setFilename( tempFilename ); } cb->write(); // Update lock if changed if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock ) { if ( !cb->password().isNull() ) curritem->setPixmap( 0, lockIcon ); else curritem->setPixmap( 0, nullIcon ); } // Update balance if changed if ( _cfg.getShowBalances() && cb->balance() != currbalance ) { QString tempstr; tempstr.sprintf( "%.2f", cb->balance() ); tempstr.prepend( _cfg.getCurrencySymbol() ); curritem->setText( posName + 1, tempstr ); } // write config, if needed if( _cfg.isDirty() ) { Config config("checkbook"); _cfg.writeConfig( config ); } } delete currcb; } // --- slotDelete ------------------------------------------------------------- void MainWindow::slotDelete() { QString currname = cbList->currentItem()->text( posName ); if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) ) { buildFilename( currname ); QFile f( tempFilename ); if ( f.exists() ) { f.remove(); } delete cbList->currentItem(); } } // --- slotConfigure ---------------------------------------------------------- void MainWindow::slotConfigure() { Configuration *cfgdlg = new Configuration( this, _cfg ); if ( QPEApplication::execDialog( cfgdlg ) == QDialog::Accepted ) { // read data from config dialog & save it cfgdlg->saveConfig( _cfg ); writeConfig(); buildList(); } delete cfgdlg; |