summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-bartender/bartender.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-bartender/bartender.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-bartender/bartender.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/noncore/apps/opie-bartender/bartender.cpp b/noncore/apps/opie-bartender/bartender.cpp
index 3c010e9..b6401ed 100644
--- a/noncore/apps/opie-bartender/bartender.cpp
+++ b/noncore/apps/opie-bartender/bartender.cpp
@@ -1,299 +1,299 @@
1/**************************************************************************** 1/****************************************************************************
2** 2**
3** Created: Sat Jul 20 08:10:53 2002 3** Created: Sat Jul 20 08:10:53 2002
4** by: L.J. Potter <ljp@llornkcor.com> 4** by: L.J. Potter <ljp@llornkcor.com>
5** copyright : (C) 2002 by ljp 5** copyright : (C) 2002 by ljp
6 email : ljp@llornkcor.com 6 email : ljp@llornkcor.com
7 * This program is free software; you can redistribute it and/or modify * 7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or * 9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. * 10 * (at your option) any later version. *
11 ***************************************************************************/ 11 ***************************************************************************/
12 12
13#include "bartender.h" 13#include "bartender.h"
14#include "showdrinks.h" 14#include "showdrinks.h"
15#include "inputDialog.h" 15#include "inputDialog.h"
16#include "searchresults.h" 16#include "searchresults.h"
17#include "bac.h" 17#include "bac.h"
18 18
19#include <qpe/qpetoolbar.h> 19#include <qpe/qpetoolbar.h>
20#include <qmenubar.h> 20#include <qmenubar.h>
21//#include <opie2/colorpopupmenu.h> 21//#include <opie2/colorpopupmenu.h>
22#include <qpe/qpeapplication.h> 22#include <qpe/qpeapplication.h>
23#include <qpe/resource.h> 23#include <qpe/resource.h>
24 24
25#include <qlineedit.h> 25#include <qlineedit.h>
26#include <qdir.h> 26#include <qdir.h>
27#include <qpushbutton.h> 27#include <qpushbutton.h>
28#include <qlistbox.h> 28#include <qlistbox.h>
29#include <qmultilineedit.h> 29#include <qmultilineedit.h>
30#include <qmessagebox.h> 30#include <qmessagebox.h>
31#include <qtextstream.h> 31#include <qtextstream.h>
32#include <qaction.h> 32#include <qaction.h>
33#include <qheader.h> 33#include <qheader.h>
34#include <qlistview.h> 34#include <qlistview.h>
35#include <qlayout.h> 35#include <qlayout.h>
36 36
37#include <fcntl.h> 37#include <fcntl.h>
38#include <unistd.h> 38#include <unistd.h>
39#include <stdlib.h> 39#include <stdlib.h>
40#include <stdio.h> 40#include <stdio.h>
41#include <errno.h> 41#include <errno.h>
42 42
43 43
44Bartender::Bartender( QWidget* parent, const char* name, WFlags fl ) 44Bartender::Bartender( QWidget* parent, const char* name, WFlags fl )
45 : QMainWindow( parent, name, fl ) { 45 : QMainWindow( parent, name, fl ) {
46 if ( !name ) 46 if ( !name )
47 setName( "Bartender" ); 47 setName( "Bartender" );
48 QGridLayout *layout = new QGridLayout( this ); 48 QGridLayout *layout = new QGridLayout( this );
49 layout->setSpacing( 2); 49 layout->setSpacing( 2);
50 layout->setMargin( 2); 50 layout->setMargin( 2);
51 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); 51 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
52 52
53 setCaption( tr( "Bartender" ) ); 53 setCaption( tr( "Bartender" ) );
54 54
55 ToolBar1 = new QToolBar( this, "ToolBar1" ); 55 ToolBar1 = new QToolBar( this, "ToolBar1" );
56 ToolBar1->setFixedHeight(22); 56 ToolBar1->setFixedHeight(22);
57 layout->addMultiCellWidget( ToolBar1, 0, 0, 0, 4 ); 57 layout->addMultiCellWidget( ToolBar1, 0, 0, 0, 4 );
58 58
59 QMenuBar *menuBar = new QMenuBar( ToolBar1 ); 59 QMenuBar *menuBar = new QMenuBar( ToolBar1 );
60 QPopupMenu *fileMenu; 60 QPopupMenu *fileMenu;
61 fileMenu = new QPopupMenu( this); 61 fileMenu = new QPopupMenu( this);
62 menuBar->insertItem( tr("File"), fileMenu ); 62 menuBar->insertItem( tr("File"), fileMenu );
63 63
64 fileMenu->insertItem(tr("New Drink")); 64 fileMenu->insertItem(tr("New Drink"));
65 fileMenu->insertItem(tr("Open Drink")); 65 fileMenu->insertItem(tr("Open Drink"));
66 fileMenu->insertItem(tr("Find by Drink Name")); 66 fileMenu->insertItem(tr("Find by Drink Name"));
67 fileMenu->insertItem(tr("Find by Alcohol")); 67 fileMenu->insertItem(tr("Find by Alcohol"));
68 68
69 QPopupMenu *editMenu; 69 QPopupMenu *editMenu;
70 editMenu = new QPopupMenu( this); 70 editMenu = new QPopupMenu( this);
71 menuBar->insertItem( tr("Edit"), editMenu ); 71 menuBar->insertItem( tr("Edit"), editMenu );
72 editMenu->insertItem(tr("edit")); 72 editMenu->insertItem(tr("edit"));
73 73
74 connect( fileMenu, SIGNAL( activated(int) ), this, SLOT( fileMenuActivated(int) )); 74 connect( fileMenu, SIGNAL( activated(int) ), this, SLOT( fileMenuActivated(int) ));
75 connect( editMenu, SIGNAL( activated(int) ), this, SLOT( editMenuActivated(int) )); 75 connect( editMenu, SIGNAL( activated(int) ), this, SLOT( editMenuActivated(int) ));
76 76
77 77
78 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), "New", 0, this, 0 ); 78 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), "New", 0, this, 0 );
79 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 79 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
80 a->addTo( ToolBar1 ); 80 a->addTo( ToolBar1 );
81 81
82 a = new QAction( tr( "Open" ), Resource::loadPixmap( "bartender/bartender_sm" ), "open", 0, this, 0 ); 82 a = new QAction( tr( "Open" ), Resource::loadPixmap( "bartender/bartender_sm" ), "open", 0, this, 0 );
83 connect( a, SIGNAL( activated() ), this, SLOT( openCurrentDrink() ) ); 83 connect( a, SIGNAL( activated() ), this, SLOT( openCurrentDrink() ) );
84 a->addTo( ToolBar1 ); 84 a->addTo( ToolBar1 );
85 85
86 a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), "Find", 0, this, 0 ); 86 a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), "Find", 0, this, 0 );
87 connect( a, SIGNAL( activated() ), this, SLOT( askSearch() ) ); 87 connect( a, SIGNAL( activated() ), this, SLOT( askSearch() ) );
88 a->addTo( ToolBar1 ); 88 a->addTo( ToolBar1 );
89 89
90 a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ),"Edit", 0, this, 0 ); 90 a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ),"Edit", 0, this, 0 );
91 connect( a, SIGNAL( activated() ), this, SLOT( doEdit() ) ); 91 connect( a, SIGNAL( activated() ), this, SLOT( doEdit() ) );
92 a->addTo( ToolBar1 ); 92 a->addTo( ToolBar1 );
93 93
94 QPushButton *t; 94 QPushButton *t;
95 t= new QPushButton( "BAC", ToolBar1, "bacButtin"); 95 t= new QPushButton( "BAC", ToolBar1, "bacButtin");
96 connect( t, SIGNAL( clicked() ), this, SLOT( doBac() ) ); 96 connect( t, SIGNAL( clicked() ), this, SLOT( doBac() ) );
97 97
98 DrinkView = new QListView( this, "DrinkView" ); 98 DrinkView = new QListView( this, "DrinkView" );
99 DrinkView->addColumn( tr( "Name of Drink" ) ); 99 DrinkView->addColumn( tr( "Name of Drink" ) );
100// DrinkView->setRootIsDecorated( TRUE ); 100// DrinkView->setRootIsDecorated( TRUE );
101 DrinkView->header()->hide(); 101 DrinkView->header()->hide();
102 102
103 QPEApplication::setStylusOperation( DrinkView->viewport(),QPEApplication::RightOnHold); 103 QPEApplication::setStylusOperation( DrinkView->viewport(),QPEApplication::RightOnHold);
104 104
105 connect(DrinkView, SIGNAL( doubleClicked(QListViewItem*)),this,SLOT(showDrink( QListViewItem*))); 105 connect(DrinkView, SIGNAL( doubleClicked(QListViewItem*)),this,SLOT(showDrink(QListViewItem*)));
106 connect(DrinkView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), 106 connect(DrinkView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)),
107 this,SLOT( showDrink(int, QListViewItem *, const QPoint&, int))); 107 this,SLOT( showDrink(int,QListViewItem*,const QPoint&,int)));
108 108
109 layout->addMultiCellWidget( DrinkView, 1, 2, 0, 4 ); 109 layout->addMultiCellWidget( DrinkView, 1, 2, 0, 4 );
110 if(QDir("db").exists()) { 110 if(QDir("db").exists()) {
111 dbFile.setName( "db/drinkdb.txt"); 111 dbFile.setName( "db/drinkdb.txt");
112 } else 112 } else
113 dbFile.setName( QPEApplication::qpeDir()+"/etc/bartender/drinkdb.txt"); 113 dbFile.setName( QPEApplication::qpeDir()+"/etc/bartender/drinkdb.txt");
114 initDrinkDb(); 114 initDrinkDb();
115} 115}
116 116
117Bartender::~Bartender() { 117Bartender::~Bartender() {
118} 118}
119 119
120/* 120/*
121this happens right before exit */ 121this happens right before exit */
122void Bartender::cleanUp() { 122void Bartender::cleanUp() {
123 dbFile.close(); 123 dbFile.close();
124 124
125} 125}
126 126
127void Bartender::initDrinkDb() { 127void Bartender::initDrinkDb() {
128 128
129 if(!dbFile.isOpen()) 129 if(!dbFile.isOpen())
130 if ( !dbFile.open( IO_ReadOnly)) { 130 if ( !dbFile.open( IO_ReadOnly)) {
131 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); 131 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) );
132 return; 132 return;
133 } 133 }
134 fillList(); 134 fillList();
135} 135}
136 136
137void Bartender::fillList() { 137void Bartender::fillList() {
138 dbFile.at(1); 138 dbFile.at(1);
139 DrinkView->clear(); 139 DrinkView->clear();
140 int i=0; 140 int i=0;
141 QListViewItem * item ; 141 QListViewItem * item ;
142 QTextStream t( &dbFile); 142 QTextStream t( &dbFile);
143 QString s; 143 QString s;
144 while ( !t.eof()) { 144 while ( !t.eof()) {
145 s = t.readLine(); 145 s = t.readLine();
146 if(s.find("#",0,TRUE) != -1) { 146 if(s.find("#",0,TRUE) != -1) {
147// qDebug(s.right(s.length()-2)); 147// qDebug(s.right(s.length()-2));
148 item= new QListViewItem( DrinkView, 0 ); 148 item= new QListViewItem( DrinkView, 0 );
149 item->setText( 0, s.right(s.length()-2)); 149 item->setText( 0, s.right(s.length()-2));
150 i++; 150 i++;
151 } 151 }
152 } 152 }
153 qDebug("there are currently %d of drinks", i); 153 qDebug("there are currently %d of drinks", i);
154} 154}
155 155
156void Bartender::fileNew() { 156void Bartender::fileNew() {
157 157
158 New_Drink *newDrinks; 158 New_Drink *newDrinks;
159 newDrinks = new New_Drink(this,"New Drink....", TRUE); 159 newDrinks = new New_Drink(this,"New Drink....", TRUE);
160 QString newName, newIng; 160 QString newName, newIng;
161 QPEApplication::execDialog( newDrinks ); 161 QPEApplication::execDialog( newDrinks );
162 newName = newDrinks->LineEdit1->text(); 162 newName = newDrinks->LineEdit1->text();
163 newIng= newDrinks->MultiLineEdit1->text(); 163 newIng= newDrinks->MultiLineEdit1->text();
164 164
165 if(dbFile.isOpen()) 165 if(dbFile.isOpen())
166 dbFile.close(); 166 dbFile.close();
167 if ( !dbFile.open( IO_WriteOnly| IO_Append)) { 167 if ( !dbFile.open( IO_WriteOnly| IO_Append)) {
168 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); 168 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) );
169 return; 169 return;
170 } 170 }
171 if(newDrinks ->result() == 1 ) { 171 if(newDrinks ->result() == 1 ) {
172 QString newDrink="\n# "+newName+"\n"; 172 QString newDrink="\n# "+newName+"\n";
173 newDrink.append(newIng+"\n"); 173 newDrink.append(newIng+"\n");
174 qDebug("writing "+newDrink); 174 qDebug("writing "+newDrink);
175 dbFile.writeBlock( newDrink.latin1(), newDrink.length()); 175 dbFile.writeBlock( newDrink.latin1(), newDrink.length());
176 clearList(); 176 clearList();
177 dbFile.close(); 177 dbFile.close();
178 178
179 initDrinkDb(); 179 initDrinkDb();
180 } 180 }
181 delete newDrinks; 181 delete newDrinks;
182} 182}
183 183
184void Bartender::showDrink(int mouse, QListViewItem * item, const QPoint&, int) { 184void Bartender::showDrink(int mouse, QListViewItem * item, const QPoint&, int) {
185 switch (mouse) { 185 switch (mouse) {
186 case 1: 186 case 1:
187// showDrink(item); 187// showDrink(item);
188 break; 188 break;
189 case 2: 189 case 2:
190 showDrink(item); 190 showDrink(item);
191 break; 191 break;
192 } 192 }
193} 193}
194 194
195void Bartender::showDrink( QListViewItem *item) { 195void Bartender::showDrink( QListViewItem *item) {
196 if(item==NULL) return; 196 if(item==NULL) return;
197 dbFile.at(0); 197 dbFile.at(0);
198 Show_Drink *showDrinks; 198 Show_Drink *showDrinks;
199 QString myDrink=item->text(0); 199 QString myDrink=item->text(0);
200 showDrinks = new Show_Drink(this, myDrink, TRUE); 200 showDrinks = new Show_Drink(this, myDrink, TRUE);
201 QTextStream t( &dbFile); 201 QTextStream t( &dbFile);
202 202
203 QString s, s2; 203 QString s, s2;
204 while ( !t.eof()) { 204 while ( !t.eof()) {
205 s = t.readLine(); 205 s = t.readLine();
206 if(s.find( myDrink, 0, TRUE) != -1) { 206 if(s.find( myDrink, 0, TRUE) != -1) {
207 for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) { 207 for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) {
208 s2 = t.readLine(); 208 s2 = t.readLine();
209 if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) { 209 if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) {
210// qDebug(s2); 210// qDebug(s2);
211 showDrinks->MultiLineEdit1->append(s2); 211 showDrinks->MultiLineEdit1->append(s2);
212 } 212 }
213 if( dbFile.atEnd() ) break; 213 if( dbFile.atEnd() ) break;
214 } 214 }
215 } 215 }
216 } 216 }
217 QPEApplication::execDialog( showDrinks ); 217 QPEApplication::execDialog( showDrinks );
218 218
219 if(showDrinks ->result() ==0) { 219 if(showDrinks ->result() ==0) {
220 doEdit(); 220 doEdit();
221 } 221 }
222 delete showDrinks; 222 delete showDrinks;
223} 223}
224 224
225void Bartender::askSearch() { 225void Bartender::askSearch() {
226 switch ( QMessageBox::warning(this,tr("Find"),tr("Search by drink name\n")+ 226 switch ( QMessageBox::warning(this,tr("Find"),tr("Search by drink name\n")+
227 "\nor alcohol ?" 227 "\nor alcohol ?"
228 ,tr("Drink Name"),tr("Alcohol"),0,0,1) ) { 228 ,tr("Drink Name"),tr("Alcohol"),0,0,1) ) {
229 case 0: 229 case 0:
230 doSearchByName(); 230 doSearchByName();
231 break; 231 break;
232 case 1: 232 case 1:
233 doSearchByDrink(); 233 doSearchByDrink();
234 break; 234 break;
235 }; 235 };
236} 236}
237 237
238/* search by name */ 238/* search by name */
239void Bartender::doSearchByName() { 239void Bartender::doSearchByName() {
240// if( DrinkView->currentItem() == NULL) return; 240// if( DrinkView->currentItem() == NULL) return;
241 QStringList searchList; 241 QStringList searchList;
242 QString searchForDrinkName; 242 QString searchForDrinkName;
243 InputDialog *fileDlg; 243 InputDialog *fileDlg;
244 fileDlg = new InputDialog(this,tr("Find by Drink Name"),TRUE, 0); 244 fileDlg = new InputDialog(this,tr("Find by Drink Name"),TRUE, 0);
245 fileDlg->exec(); 245 fileDlg->exec();
246 if( fileDlg->result() == 1 ) { 246 if( fileDlg->result() == 1 ) {
247 searchForDrinkName = fileDlg->LineEdit1->text(); 247 searchForDrinkName = fileDlg->LineEdit1->text();
248 QListViewItemIterator it( DrinkView ); 248 QListViewItemIterator it( DrinkView );
249 for ( ; it.current(); ++it ) { 249 for ( ; it.current(); ++it ) {
250 if ( it.current()->text(0).find( searchForDrinkName, 0, TRUE) != -1 ) { 250 if ( it.current()->text(0).find( searchForDrinkName, 0, TRUE) != -1 ) {
251// qDebug( it.current()->text(0)); 251// qDebug( it.current()->text(0));
252 searchList.append(it.current()->text(0)); 252 searchList.append(it.current()->text(0));
253 } 253 }
254 } 254 }
255 if(searchList.count() >0) 255 if(searchList.count() >0)
256 showSearchResult(searchList); 256 showSearchResult(searchList);
257 else 257 else
258 QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+searchForDrinkName); 258 QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+searchForDrinkName);
259 }//end Inputdialog 259 }//end Inputdialog
260 delete fileDlg; 260 delete fileDlg;
261} 261}
262 262
263void Bartender::doSearchByDrink() { 263void Bartender::doSearchByDrink() {
264// if( DrinkView->currentItem() == NULL) return; 264// if( DrinkView->currentItem() == NULL) return;
265 QStringList searchList; 265 QStringList searchList;
266 QString searchForDrinkName, lastDrinkName, tempName; 266 QString searchForDrinkName, lastDrinkName, tempName;
267 267
268 InputDialog *fileDlg; 268 InputDialog *fileDlg;
269 fileDlg = new InputDialog(this,tr("Find by Alcohol"),TRUE, 0); 269 fileDlg = new InputDialog(this,tr("Find by Alcohol"),TRUE, 0);
270 fileDlg->exec(); 270 fileDlg->exec();
271 if( fileDlg->result() == 1 ) { 271 if( fileDlg->result() == 1 ) {
272 searchForDrinkName = fileDlg->LineEdit1->text(); 272 searchForDrinkName = fileDlg->LineEdit1->text();
273 273
274 dbFile.at(0); 274 dbFile.at(0);
275 QTextStream t( &dbFile); 275 QTextStream t( &dbFile);
276 276
277 QString s, s2; 277 QString s, s2;
278 while ( !t.eof()) { 278 while ( !t.eof()) {
279 s = t.readLine(); 279 s = t.readLine();
280 if(s.find("#",0,TRUE) != -1) { 280 if(s.find("#",0,TRUE) != -1) {
281 lastDrinkName=s.right(s.length()-2); 281 lastDrinkName=s.right(s.length()-2);
282// qDebug("last drink name "+lastDrinkName); 282// qDebug("last drink name "+lastDrinkName);
283 } 283 }
284 else if( s.find( searchForDrinkName ,0, FALSE) != -1 && lastDrinkName != tempName ) { 284 else if( s.find( searchForDrinkName ,0, FALSE) != -1 && lastDrinkName != tempName ) {
285// qDebug("appending "+lastDrinkName); 285// qDebug("appending "+lastDrinkName);
286 searchList.append( lastDrinkName); 286 searchList.append( lastDrinkName);
287 tempName=lastDrinkName; 287 tempName=lastDrinkName;
288 } 288 }
289// if( dbFile.atEnd() ) break; 289// if( dbFile.atEnd() ) break;
290 290
291 } //oef 291 } //oef
292 if(searchList.count() >0) 292 if(searchList.count() >0)
293 showSearchResult(searchList); 293 showSearchResult(searchList);
294 else 294 else
295 QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+ searchForDrinkName); 295 QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+ searchForDrinkName);
296 } 296 }
297 delete fileDlg; 297 delete fileDlg;
298} 298}
299 299