summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/mainwindow.cpp
authordrw <drw>2002-10-21 23:04:11 (UTC)
committer drw <drw>2002-10-21 23:04:11 (UTC)
commit0b0f3dccd3b6dbb01fd268e2c737fd1a6c163379 (patch) (unidiff)
treefc39f1647722bb5bc9a935c32567a3da666ae843 /noncore/apps/checkbook/mainwindow.cpp
parentb466b56f8a17010d651f07149ae5b860296ac710 (diff)
downloadopie-0b0f3dccd3b6dbb01fd268e2c737fd1a6c163379.zip
opie-0b0f3dccd3b6dbb01fd268e2c737fd1a6c163379.tar.gz
opie-0b0f3dccd3b6dbb01fd268e2c737fd1a6c163379.tar.bz2
New version of Checkbook app
Diffstat (limited to 'noncore/apps/checkbook/mainwindow.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/checkbook/mainwindow.cpp164
1 files changed, 164 insertions, 0 deletions
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp
new file mode 100644
index 0000000..9410536
--- a/dev/null
+++ b/noncore/apps/checkbook/mainwindow.cpp
@@ -0,0 +1,164 @@
1/*
2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#include "mainwindow.h"
30#include "checkbook.h"
31
32#include <qpe/global.h>
33#include <qpe/qpeapplication.h>
34#include <qpe/qpemenubar.h>
35#include <qpe/qpemessagebox.h>
36#include <qpe/qpetoolbar.h>
37#include <qpe/resource.h>
38
39#include <qaction.h>
40#include <qdir.h>
41#include <qlistbox.h>
42#include <qpopupmenu.h>
43#include <qstring.h>
44
45MainWindow::MainWindow()
46 : QMainWindow()
47{
48 setCaption( tr( "Checkbook" ) );
49
50 cbDir = Global::applicationFileName( "checkbook", "" );
51
52 // Build menu and tool bars
53 setToolBarsMovable( FALSE );
54
55 QPEToolBar *bar = new QPEToolBar( this );
56 bar->setHorizontalStretchable( TRUE );
57 QPEMenuBar *mb = new QPEMenuBar( bar );
58 mb->setMargin( 0 );
59 QPopupMenu *popup = new QPopupMenu( this );
60
61 bar = new QPEToolBar( this );
62 actionOpen = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null,
63 0, this, 0 );
64 connect( actionOpen, SIGNAL( activated() ), this, SLOT( slotOpen() ) );
65 actionOpen->addTo( popup );
66 actionOpen->addTo( bar );
67
68 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
69 connect( a, SIGNAL( activated() ), this, SLOT( slotNew() ) );
70 a->addTo( popup );
71 a->addTo( bar );
72
73 actionDelete = new QAction( tr( "Delete" ), Resource::loadPixmap( "editdelete" ), QString::null,
74 0, this, 0 );
75 connect( actionDelete, SIGNAL( activated() ), this, SLOT( slotDelete() ) );
76 actionDelete->addTo( popup );
77 actionDelete->addTo( bar );
78
79 popup->insertSeparator();
80
81 a = new QAction( tr( "Exit" ), QString::null, 0, this, 0 );
82 connect( a, SIGNAL( activated() ), this, SLOT( close() ) );
83 a->addTo( popup );
84
85 mb->insertItem( tr( "Checkbook" ), popup );
86
87 // Build Checkbook selection list control
88 cbList = new QListBox( this );
89 QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold );
90 connect( cbList, SIGNAL( rightButtonPressed( QListBoxItem *, const QPoint & ) ),
91 this, SLOT( slotOpen() ) );
92 setCentralWidget( cbList );
93
94 // Load Checkbook selection list
95 QDir checkdir( cbDir );
96 if (checkdir.exists() == true)
97 {
98 QStringList checkbooks = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable,
99 QDir::Time );
100 for ( QStringList::Iterator it = checkbooks.begin(); it != checkbooks.end(); it++ )
101 {
102 (*it) = (*it).remove( (*it).find('.'), (*it).length() );
103 }
104 cbList->insertStringList( checkbooks );
105 }
106 cbList->sort();
107 cbList->setSelected( 0, TRUE );
108
109 currencySymbol = '$';
110}
111
112MainWindow::~MainWindow()
113{
114}
115
116void MainWindow::slotOpen()
117{
118 QString currname = cbList->currentText();
119 Checkbook *currcb = new Checkbook( this, currname, cbDir, currencySymbol );
120 currcb->showMaximized();
121 if ( currcb->exec() == QDialog::Accepted )
122 {
123 QString newname = currcb->getName();
124 if ( currname != newname )
125 {
126 cbList->changeItem( newname, cbList->currentItem() );
127 cbList->sort();
128
129 QFile f( cbDir + currname + ".qcb" );
130 if ( f.exists() )
131 {
132 f.remove();
133 }
134 }
135 delete currcb;
136 }
137}
138
139void MainWindow::slotNew()
140{
141 Checkbook *currcb = new Checkbook( this, "", cbDir, currencySymbol );
142 currcb->showMaximized();
143 if ( currcb->exec() == QDialog::Accepted )
144 {
145 cbList->insertItem( currcb->getName() );
146 cbList->sort();
147 delete currcb;
148 }
149}
150
151void MainWindow::slotDelete()
152{
153 if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), cbList->currentText() ) )
154 {
155 cbList->removeItem( cbList->currentItem() );
156
157 QString name = cbDir + cbList->currentText() + ".qcb";
158 QFile f( name );
159 if ( f.exists() )
160 {
161 f.remove();
162 }
163 }
164}