summaryrefslogtreecommitdiff
path: root/noncore
authorzecke <zecke>2004-10-26 21:28:59 (UTC)
committer zecke <zecke>2004-10-26 21:28:59 (UTC)
commitae5855babec6e46802be89ee408d26a2cbbb1981 (patch) (side-by-side diff)
tree6aab434ceb2831741b997b93f053e1843c3d59ec /noncore
parentc95aeb8fd283fe9d2f220209e696726120857257 (diff)
downloadopie-ae5855babec6e46802be89ee408d26a2cbbb1981.zip
opie-ae5855babec6e46802be89ee408d26a2cbbb1981.tar.gz
opie-ae5855babec6e46802be89ee408d26a2cbbb1981.tar.bz2
-Remove usage of latin1() as a possible fix to #1471
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/checkbook/checkbook.cpp18
-rw-r--r--noncore/apps/checkbook/mainwindow.cpp6
2 files changed, 17 insertions, 7 deletions
diff --git a/noncore/apps/checkbook/checkbook.cpp b/noncore/apps/checkbook/checkbook.cpp
index 706d970..44d3764 100644
--- a/noncore/apps/checkbook/checkbook.cpp
+++ b/noncore/apps/checkbook/checkbook.cpp
@@ -289,137 +289,142 @@ QWidget *Checkbook::initCharts()
layout->addMultiCellWidget( graphList, 1, 1, 0, 1 );
QPushButton *btn = new QPushButton( Resource::loadPixmap( "checkbook/drawbtn" ), tr( "Draw" ), control );
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( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
+ 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( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), bal );
+ 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 );
@@ -437,156 +442,159 @@ void Checkbook::slotPasswordClicked()
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() )
traninfo->setDate(_dLastNew);
Transaction *currtran = new Transaction( this, true, info->name(),
traninfo,
_pCfg );
+ QString symbol = _pCfg->getCurrencySymbol();
if ( QPEApplication::execDialog( currtran ) == QDialog::Accepted )
{
// Add to transaction list
info->addTransaction( traninfo );
// Add to transaction table
float amount;
QString stramount;
- amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount();
- stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
+ amount = (traninfo->withdrawal() ? -1 : 1)*traninfo->amount();
+ stramount.sprintf( "%.2f", amount );
+ stramount.prepend(symbol);
( void ) new CBListItem( traninfo, tranTable, traninfo->getIdStr(), traninfo->datestr(false),
traninfo->number(), traninfo->datestr(true), traninfo->desc(),
stramount );
resort();
adjustBalance();
// save last date
_dLastNew = traninfo->date();
// save description in list of payees, if not in there
QStringList *pLst=&_pCfg->getPayees();
if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) {
pLst->append( traninfo->desc() );
pLst->sort();
_pCfg->setDirty(true);
}
}
else
{
delete traninfo;
}
}
// --- slotEditTran -----------------------------------------------------------
void Checkbook::slotEditTran()
{
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
return;
TranInfo *traninfo=info->findTransaction( curritem->text(COL_ID) );
Transaction *currtran = new Transaction( this, false, info->name(),
traninfo,
_pCfg );
if ( QPEApplication::execDialog( currtran ) == QDialog::Accepted )
{
curritem->setText( COL_NUM, traninfo->number() );
curritem->setText( COL_SORTDATE, traninfo->datestr(false) );
curritem->setText( COL_DATE, traninfo->datestr(true) );
curritem->setText( COL_DESC, traninfo->desc() );
float amount = traninfo->amount();
if ( traninfo->withdrawal() )
{
amount *= -1;
}
QString stramount;
- stramount.sprintf( "%s%.2f", _pCfg->getCurrencySymbol().latin1(), amount );
+ stramount.sprintf( "%.2f", amount );
+ stramount.prepend( _pCfg->getCurrencySymbol() );
curritem->setText( COL_AMOUNT, stramount );
resort();
adjustBalance();
// save description in list of payees, if not in there
QStringList *pLst=&_pCfg->getPayees();
if( _pCfg->getSavePayees() && pLst->contains(traninfo->desc())==0 ) {
pLst->append( traninfo->desc() );
pLst->sort();
_pCfg->setDirty(true);
}
}
delete currtran;
}
// --- slotMenuTran -----------------------------------------------------------
void Checkbook::slotMenuTran(QListViewItem *item, const QPoint &pnt)
{
// active item?
if( !item )
return;
// Display menu
QPopupMenu m;
m.insertItem( QWidget::tr( "Edit" ), 1 );
m.insertItem( QWidget::tr( "New" ), 2 );
m.insertItem( QWidget::tr( "Delete" ), 3 );
int r = m.exec( pnt );
switch(r) {
case 1:
slotEditTran();
break;
case 2:
slotNewTran();
break;
case 3:
slotDeleteTran();
break;
}
}
// --- slotDeleteTran ---------------------------------------------------------
void Checkbook::slotDeleteTran()
{
QListViewItem *curritem = tranTable->currentItem();
if ( !curritem )
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp
index ce15e3e..c7ffa7c 100644
--- a/noncore/apps/checkbook/mainwindow.cpp
+++ b/noncore/apps/checkbook/mainwindow.cpp
@@ -148,97 +148,98 @@ MainWindow::~MainWindow()
// --- 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 );
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( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->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();
@@ -259,97 +260,98 @@ void MainWindow::openBook(QListViewItem *curritem)
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( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() );
+ 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;
}
// --- writeConfig --------------------------------------------------------------
void MainWindow::writeConfig()
{