-rw-r--r-- | noncore/apps/opie-bartender/bartender.cpp | 36 | ||||
-rw-r--r-- | noncore/apps/opie-bartender/opie-bartender.control | 4 |
2 files changed, 20 insertions, 20 deletions
diff --git a/noncore/apps/opie-bartender/bartender.cpp b/noncore/apps/opie-bartender/bartender.cpp index cd0a364..740478f 100644 --- a/noncore/apps/opie-bartender/bartender.cpp +++ b/noncore/apps/opie-bartender/bartender.cpp | |||
@@ -1,443 +1,443 @@ | |||
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 "newdrinks.h" | 14 | #include "newdrinks.h" |
15 | #include "showdrinks.h" | 15 | #include "showdrinks.h" |
16 | #include "inputDialog.h" | 16 | #include "inputDialog.h" |
17 | #include "searchresults.h" | 17 | #include "searchresults.h" |
18 | #include "bac.h" | 18 | #include "bac.h" |
19 | 19 | ||
20 | #include <qpe/qpetoolbar.h> | 20 | #include <qpe/qpetoolbar.h> |
21 | #include <qmenubar.h> | 21 | #include <qmenubar.h> |
22 | #include <opie/colorpopupmenu.h> | 22 | //#include <opie2/colorpopupmenu.h> |
23 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | 25 | ||
26 | #include <qcstring.h> | 26 | #include <qcstring.h> |
27 | #include <qlineedit.h> | 27 | #include <qlineedit.h> |
28 | #include <qdir.h> | 28 | #include <qdir.h> |
29 | #include <qpushbutton.h> | 29 | #include <qpushbutton.h> |
30 | #include <qlistbox.h> | 30 | #include <qlistbox.h> |
31 | #include <qstringlist.h> | 31 | #include <qstringlist.h> |
32 | #include <qmultilineedit.h> | 32 | #include <qmultilineedit.h> |
33 | #include <qmessagebox.h> | 33 | #include <qmessagebox.h> |
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
36 | #include <qfile.h> | 36 | #include <qfile.h> |
37 | #include <qaction.h> | 37 | #include <qaction.h> |
38 | #include <qheader.h> | 38 | #include <qheader.h> |
39 | #include <qlistview.h> | 39 | #include <qlistview.h> |
40 | #include <qwidget.h> | 40 | #include <qwidget.h> |
41 | #include <qlayout.h> | 41 | #include <qlayout.h> |
42 | #include <qvariant.h> | 42 | #include <qvariant.h> |
43 | #include <qtooltip.h> | 43 | #include <qtooltip.h> |
44 | #include <qwhatsthis.h> | 44 | #include <qwhatsthis.h> |
45 | #include <qimage.h> | 45 | #include <qimage.h> |
46 | #include <qpixmap.h> | 46 | #include <qpixmap.h> |
47 | 47 | ||
48 | #include <fcntl.h> | 48 | #include <fcntl.h> |
49 | #include <unistd.h> | 49 | #include <unistd.h> |
50 | #include <stdlib.h> | 50 | #include <stdlib.h> |
51 | #include <stdio.h> | 51 | #include <stdio.h> |
52 | #include <errno.h> | 52 | #include <errno.h> |
53 | 53 | ||
54 | 54 | ||
55 | Bartender::Bartender( QWidget* parent, const char* name, WFlags fl ) | 55 | Bartender::Bartender( QWidget* parent, const char* name, WFlags fl ) |
56 | : QMainWindow( parent, name, fl ) { | 56 | : QMainWindow( parent, name, fl ) { |
57 | if ( !name ) | 57 | if ( !name ) |
58 | setName( "Bartender" ); | 58 | setName( "Bartender" ); |
59 | QGridLayout *layout = new QGridLayout( this ); | 59 | QGridLayout *layout = new QGridLayout( this ); |
60 | layout->setSpacing( 2); | 60 | layout->setSpacing( 2); |
61 | layout->setMargin( 2); | 61 | layout->setMargin( 2); |
62 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 62 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
63 | 63 | ||
64 | setCaption( tr( "Bartender" ) ); | 64 | setCaption( tr( "Bartender" ) ); |
65 | 65 | ||
66 | ToolBar1 = new QToolBar( this, "ToolBar1" ); | 66 | ToolBar1 = new QToolBar( this, "ToolBar1" ); |
67 | ToolBar1->setFixedHeight(22); | 67 | ToolBar1->setFixedHeight(22); |
68 | layout->addMultiCellWidget( ToolBar1, 0, 0, 0, 4 ); | 68 | layout->addMultiCellWidget( ToolBar1, 0, 0, 0, 4 ); |
69 | 69 | ||
70 | QMenuBar *menuBar = new QMenuBar( ToolBar1 ); | 70 | QMenuBar *menuBar = new QMenuBar( ToolBar1 ); |
71 | QPopupMenu *fileMenu; | 71 | QPopupMenu *fileMenu; |
72 | fileMenu = new QPopupMenu( this); | 72 | fileMenu = new QPopupMenu( this); |
73 | menuBar->insertItem( tr("File"), fileMenu ); | 73 | menuBar->insertItem( tr("File"), fileMenu ); |
74 | 74 | ||
75 | fileMenu->insertItem(tr("New Drink")); | 75 | fileMenu->insertItem(tr("New Drink")); |
76 | fileMenu->insertItem(tr("Open Drink")); | 76 | fileMenu->insertItem(tr("Open Drink")); |
77 | fileMenu->insertItem(tr("Find by Drink Name")); | 77 | fileMenu->insertItem(tr("Find by Drink Name")); |
78 | fileMenu->insertItem(tr("Find by Alcohol")); | 78 | fileMenu->insertItem(tr("Find by Alcohol")); |
79 | 79 | ||
80 | QPopupMenu *editMenu; | 80 | QPopupMenu *editMenu; |
81 | editMenu = new QPopupMenu( this); | 81 | editMenu = new QPopupMenu( this); |
82 | menuBar->insertItem( tr("Edit"), editMenu ); | 82 | menuBar->insertItem( tr("Edit"), editMenu ); |
83 | editMenu->insertItem(tr("edit")); | 83 | editMenu->insertItem(tr("edit")); |
84 | 84 | ||
85 | connect( fileMenu, SIGNAL( activated(int) ), this, SLOT( fileMenuActivated(int) )); | 85 | connect( fileMenu, SIGNAL( activated(int) ), this, SLOT( fileMenuActivated(int) )); |
86 | connect( editMenu, SIGNAL( activated(int) ), this, SLOT( editMenuActivated(int) )); | 86 | connect( editMenu, SIGNAL( activated(int) ), this, SLOT( editMenuActivated(int) )); |
87 | 87 | ||
88 | 88 | ||
89 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), "New", 0, this, 0 ); | 89 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), "New", 0, this, 0 ); |
90 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 90 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
91 | a->addTo( ToolBar1 ); | 91 | a->addTo( ToolBar1 ); |
92 | 92 | ||
93 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "bartender/bartender_sm" ), "open", 0, this, 0 ); | 93 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "bartender/bartender_sm" ), "open", 0, this, 0 ); |
94 | connect( a, SIGNAL( activated() ), this, SLOT( openCurrentDrink() ) ); | 94 | connect( a, SIGNAL( activated() ), this, SLOT( openCurrentDrink() ) ); |
95 | a->addTo( ToolBar1 ); | 95 | a->addTo( ToolBar1 ); |
96 | 96 | ||
97 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), "Find", 0, this, 0 ); | 97 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), "Find", 0, this, 0 ); |
98 | connect( a, SIGNAL( activated() ), this, SLOT( askSearch() ) ); | 98 | connect( a, SIGNAL( activated() ), this, SLOT( askSearch() ) ); |
99 | a->addTo( ToolBar1 ); | 99 | a->addTo( ToolBar1 ); |
100 | 100 | ||
101 | a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ),"Edit", 0, this, 0 ); | 101 | a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ),"Edit", 0, this, 0 ); |
102 | connect( a, SIGNAL( activated() ), this, SLOT( doEdit() ) ); | 102 | connect( a, SIGNAL( activated() ), this, SLOT( doEdit() ) ); |
103 | a->addTo( ToolBar1 ); | 103 | a->addTo( ToolBar1 ); |
104 | 104 | ||
105 | QPushButton *t; | 105 | QPushButton *t; |
106 | t= new QPushButton( "BAC", ToolBar1, "bacButtin"); | 106 | t= new QPushButton( "BAC", ToolBar1, "bacButtin"); |
107 | connect( t, SIGNAL( clicked() ), this, SLOT( doBac() ) ); | 107 | connect( t, SIGNAL( clicked() ), this, SLOT( doBac() ) ); |
108 | 108 | ||
109 | DrinkView = new QListView( this, "DrinkView" ); | 109 | DrinkView = new QListView( this, "DrinkView" ); |
110 | DrinkView->addColumn( tr( "Name of Drink" ) ); | 110 | DrinkView->addColumn( tr( "Name of Drink" ) ); |
111 | // DrinkView->setRootIsDecorated( TRUE ); | 111 | // DrinkView->setRootIsDecorated( TRUE ); |
112 | DrinkView->header()->hide(); | 112 | DrinkView->header()->hide(); |
113 | 113 | ||
114 | QPEApplication::setStylusOperation( DrinkView->viewport(),QPEApplication::RightOnHold); | 114 | QPEApplication::setStylusOperation( DrinkView->viewport(),QPEApplication::RightOnHold); |
115 | 115 | ||
116 | connect(DrinkView, SIGNAL( doubleClicked(QListViewItem*)),this,SLOT(showDrink( QListViewItem*))); | 116 | connect(DrinkView, SIGNAL( doubleClicked(QListViewItem*)),this,SLOT(showDrink( QListViewItem*))); |
117 | connect(DrinkView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 117 | connect(DrinkView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
118 | this,SLOT( showDrink(int, QListViewItem *, const QPoint&, int))); | 118 | this,SLOT( showDrink(int, QListViewItem *, const QPoint&, int))); |
119 | 119 | ||
120 | layout->addMultiCellWidget( DrinkView, 1, 2, 0, 4 ); | 120 | layout->addMultiCellWidget( DrinkView, 1, 2, 0, 4 ); |
121 | if(QDir("db").exists()) { | 121 | if(QDir("db").exists()) { |
122 | dbFile.setName( "db/drinkdb.txt"); | 122 | dbFile.setName( "db/drinkdb.txt"); |
123 | } else | 123 | } else |
124 | dbFile.setName( QPEApplication::qpeDir()+"/etc/bartender/drinkdb.txt"); | 124 | dbFile.setName( QPEApplication::qpeDir()+"/etc/bartender/drinkdb.txt"); |
125 | initDrinkDb(); | 125 | initDrinkDb(); |
126 | } | 126 | } |
127 | 127 | ||
128 | Bartender::~Bartender() { | 128 | Bartender::~Bartender() { |
129 | } | 129 | } |
130 | 130 | ||
131 | /* | 131 | /* |
132 | this happens right before exit */ | 132 | this happens right before exit */ |
133 | void Bartender::cleanUp() { | 133 | void Bartender::cleanUp() { |
134 | dbFile.close(); | 134 | dbFile.close(); |
135 | 135 | ||
136 | } | 136 | } |
137 | 137 | ||
138 | void Bartender::initDrinkDb() { | 138 | void Bartender::initDrinkDb() { |
139 | 139 | ||
140 | if(!dbFile.isOpen()) | 140 | if(!dbFile.isOpen()) |
141 | if ( !dbFile.open( IO_ReadOnly)) { | 141 | if ( !dbFile.open( IO_ReadOnly)) { |
142 | QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); | 142 | QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); |
143 | return; | 143 | return; |
144 | } | 144 | } |
145 | fillList(); | 145 | fillList(); |
146 | } | 146 | } |
147 | 147 | ||
148 | void Bartender::fillList() { | 148 | void Bartender::fillList() { |
149 | dbFile.at(1); | 149 | dbFile.at(1); |
150 | DrinkView->clear(); | 150 | DrinkView->clear(); |
151 | int i=0; | 151 | int i=0; |
152 | QListViewItem * item ; | 152 | QListViewItem * item ; |
153 | QTextStream t( &dbFile); | 153 | QTextStream t( &dbFile); |
154 | QString s; | 154 | QString s; |
155 | while ( !t.eof()) { | 155 | while ( !t.eof()) { |
156 | s = t.readLine(); | 156 | s = t.readLine(); |
157 | if(s.find("#",0,TRUE) != -1) { | 157 | if(s.find("#",0,TRUE) != -1) { |
158 | // qDebug(s.right(s.length()-2)); | 158 | // qDebug(s.right(s.length()-2)); |
159 | item= new QListViewItem( DrinkView, 0 ); | 159 | item= new QListViewItem( DrinkView, 0 ); |
160 | item->setText( 0, s.right(s.length()-2)); | 160 | item->setText( 0, s.right(s.length()-2)); |
161 | i++; | 161 | i++; |
162 | } | 162 | } |
163 | } | 163 | } |
164 | qDebug("there are currently %d of drinks", i); | 164 | qDebug("there are currently %d of drinks", i); |
165 | } | 165 | } |
166 | 166 | ||
167 | void Bartender::fileNew() { | 167 | void Bartender::fileNew() { |
168 | 168 | ||
169 | New_Drink *newDrinks; | 169 | New_Drink *newDrinks; |
170 | newDrinks = new New_Drink(this,"New Drink....", TRUE); | 170 | newDrinks = new New_Drink(this,"New Drink....", TRUE); |
171 | QString newName, newIng; | 171 | QString newName, newIng; |
172 | QPEApplication::execDialog( newDrinks ); | 172 | QPEApplication::execDialog( newDrinks ); |
173 | newName = newDrinks->LineEdit1->text(); | 173 | newName = newDrinks->LineEdit1->text(); |
174 | newIng= newDrinks->MultiLineEdit1->text(); | 174 | newIng= newDrinks->MultiLineEdit1->text(); |
175 | 175 | ||
176 | if(dbFile.isOpen()) | 176 | if(dbFile.isOpen()) |
177 | dbFile.close(); | 177 | dbFile.close(); |
178 | if ( !dbFile.open( IO_WriteOnly| IO_Append)) { | 178 | if ( !dbFile.open( IO_WriteOnly| IO_Append)) { |
179 | QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); | 179 | QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); |
180 | return; | 180 | return; |
181 | } | 181 | } |
182 | if(newDrinks ->result() == 1 ) { | 182 | if(newDrinks ->result() == 1 ) { |
183 | QString newDrink="\n# "+newName+"\n"; | 183 | QString newDrink="\n# "+newName+"\n"; |
184 | newDrink.append(newIng+"\n"); | 184 | newDrink.append(newIng+"\n"); |
185 | qDebug("writing "+newDrink); | 185 | qDebug("writing "+newDrink); |
186 | dbFile.writeBlock( newDrink.latin1(), newDrink.length()); | 186 | dbFile.writeBlock( newDrink.latin1(), newDrink.length()); |
187 | clearList(); | 187 | clearList(); |
188 | dbFile.close(); | 188 | dbFile.close(); |
189 | 189 | ||
190 | initDrinkDb(); | 190 | initDrinkDb(); |
191 | } | 191 | } |
192 | delete newDrinks; | 192 | delete newDrinks; |
193 | } | 193 | } |
194 | 194 | ||
195 | void Bartender::showDrink(int mouse, QListViewItem * item, const QPoint&, int) { | 195 | void Bartender::showDrink(int mouse, QListViewItem * item, const QPoint&, int) { |
196 | switch (mouse) { | 196 | switch (mouse) { |
197 | case 1: | 197 | case 1: |
198 | // showDrink(item); | 198 | // showDrink(item); |
199 | break; | 199 | break; |
200 | case 2: | 200 | case 2: |
201 | showDrink(item); | 201 | showDrink(item); |
202 | break; | 202 | break; |
203 | } | 203 | } |
204 | } | 204 | } |
205 | 205 | ||
206 | void Bartender::showDrink( QListViewItem *item) { | 206 | void Bartender::showDrink( QListViewItem *item) { |
207 | if(item==NULL) return; | 207 | if(item==NULL) return; |
208 | dbFile.at(0); | 208 | dbFile.at(0); |
209 | Show_Drink *showDrinks; | 209 | Show_Drink *showDrinks; |
210 | QString myDrink=item->text(0); | 210 | QString myDrink=item->text(0); |
211 | showDrinks = new Show_Drink(this, myDrink, TRUE); | 211 | showDrinks = new Show_Drink(this, myDrink, TRUE); |
212 | QTextStream t( &dbFile); | 212 | QTextStream t( &dbFile); |
213 | 213 | ||
214 | QString s, s2; | 214 | QString s, s2; |
215 | while ( !t.eof()) { | 215 | while ( !t.eof()) { |
216 | s = t.readLine(); | 216 | s = t.readLine(); |
217 | if(s.find( myDrink, 0, TRUE) != -1) { | 217 | if(s.find( myDrink, 0, TRUE) != -1) { |
218 | for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) { | 218 | for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) { |
219 | s2 = t.readLine(); | 219 | s2 = t.readLine(); |
220 | if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) { | 220 | if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) { |
221 | // qDebug(s2); | 221 | // qDebug(s2); |
222 | showDrinks->MultiLineEdit1->append(s2); | 222 | showDrinks->MultiLineEdit1->append(s2); |
223 | } | 223 | } |
224 | if( dbFile.atEnd() ) break; | 224 | if( dbFile.atEnd() ) break; |
225 | } | 225 | } |
226 | } | 226 | } |
227 | } | 227 | } |
228 | QPEApplication::execDialog( showDrinks ); | 228 | QPEApplication::execDialog( showDrinks ); |
229 | 229 | ||
230 | if(showDrinks ->result() ==0) { | 230 | if(showDrinks ->result() ==0) { |
231 | doEdit(); | 231 | doEdit(); |
232 | } | 232 | } |
233 | delete showDrinks; | 233 | delete showDrinks; |
234 | } | 234 | } |
235 | 235 | ||
236 | void Bartender::askSearch() { | 236 | void Bartender::askSearch() { |
237 | switch ( QMessageBox::warning(this,tr("Find"),tr("Search by drink name\n")+ | 237 | switch ( QMessageBox::warning(this,tr("Find"),tr("Search by drink name\n")+ |
238 | "\nor alcohol ?" | 238 | "\nor alcohol ?" |
239 | ,tr("Drink Name"),tr("Alcohol"),0,0,1) ) { | 239 | ,tr("Drink Name"),tr("Alcohol"),0,0,1) ) { |
240 | case 0: | 240 | case 0: |
241 | doSearchByName(); | 241 | doSearchByName(); |
242 | break; | 242 | break; |
243 | case 1: | 243 | case 1: |
244 | doSearchByDrink(); | 244 | doSearchByDrink(); |
245 | break; | 245 | break; |
246 | }; | 246 | }; |
247 | } | 247 | } |
248 | 248 | ||
249 | /* search by name */ | 249 | /* search by name */ |
250 | void Bartender::doSearchByName() { | 250 | void Bartender::doSearchByName() { |
251 | // if( DrinkView->currentItem() == NULL) return; | 251 | // if( DrinkView->currentItem() == NULL) return; |
252 | QStringList searchList; | 252 | QStringList searchList; |
253 | QString searchForDrinkName; | 253 | QString searchForDrinkName; |
254 | InputDialog *fileDlg; | 254 | InputDialog *fileDlg; |
255 | fileDlg = new InputDialog(this,tr("Find by Drink Name"),TRUE, 0); | 255 | fileDlg = new InputDialog(this,tr("Find by Drink Name"),TRUE, 0); |
256 | fileDlg->exec(); | 256 | fileDlg->exec(); |
257 | if( fileDlg->result() == 1 ) { | 257 | if( fileDlg->result() == 1 ) { |
258 | searchForDrinkName = fileDlg->LineEdit1->text(); | 258 | searchForDrinkName = fileDlg->LineEdit1->text(); |
259 | QListViewItemIterator it( DrinkView ); | 259 | QListViewItemIterator it( DrinkView ); |
260 | for ( ; it.current(); ++it ) { | 260 | for ( ; it.current(); ++it ) { |
261 | if ( it.current()->text(0).find( searchForDrinkName, 0, TRUE) != -1 ) { | 261 | if ( it.current()->text(0).find( searchForDrinkName, 0, TRUE) != -1 ) { |
262 | // qDebug( it.current()->text(0)); | 262 | // qDebug( it.current()->text(0)); |
263 | searchList.append(it.current()->text(0)); | 263 | searchList.append(it.current()->text(0)); |
264 | } | 264 | } |
265 | } | 265 | } |
266 | if(searchList.count() >0) | 266 | if(searchList.count() >0) |
267 | showSearchResult(searchList); | 267 | showSearchResult(searchList); |
268 | else | 268 | else |
269 | QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+searchForDrinkName); | 269 | QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+searchForDrinkName); |
270 | }//end Inputdialog | 270 | }//end Inputdialog |
271 | delete fileDlg; | 271 | delete fileDlg; |
272 | } | 272 | } |
273 | 273 | ||
274 | void Bartender::doSearchByDrink() { | 274 | void Bartender::doSearchByDrink() { |
275 | // if( DrinkView->currentItem() == NULL) return; | 275 | // if( DrinkView->currentItem() == NULL) return; |
276 | QStringList searchList; | 276 | QStringList searchList; |
277 | QString searchForDrinkName, lastDrinkName, tempName; | 277 | QString searchForDrinkName, lastDrinkName, tempName; |
278 | 278 | ||
279 | InputDialog *fileDlg; | 279 | InputDialog *fileDlg; |
280 | fileDlg = new InputDialog(this,tr("Find by Alcohol"),TRUE, 0); | 280 | fileDlg = new InputDialog(this,tr("Find by Alcohol"),TRUE, 0); |
281 | fileDlg->exec(); | 281 | fileDlg->exec(); |
282 | if( fileDlg->result() == 1 ) { | 282 | if( fileDlg->result() == 1 ) { |
283 | searchForDrinkName = fileDlg->LineEdit1->text(); | 283 | searchForDrinkName = fileDlg->LineEdit1->text(); |
284 | 284 | ||
285 | dbFile.at(0); | 285 | dbFile.at(0); |
286 | QTextStream t( &dbFile); | 286 | QTextStream t( &dbFile); |
287 | 287 | ||
288 | QString s, s2; | 288 | QString s, s2; |
289 | while ( !t.eof()) { | 289 | while ( !t.eof()) { |
290 | s = t.readLine(); | 290 | s = t.readLine(); |
291 | if(s.find("#",0,TRUE) != -1) { | 291 | if(s.find("#",0,TRUE) != -1) { |
292 | lastDrinkName=s.right(s.length()-2); | 292 | lastDrinkName=s.right(s.length()-2); |
293 | // qDebug("last drink name "+lastDrinkName); | 293 | // qDebug("last drink name "+lastDrinkName); |
294 | } | 294 | } |
295 | else if( s.find( searchForDrinkName ,0, FALSE) != -1 && lastDrinkName != tempName ) { | 295 | else if( s.find( searchForDrinkName ,0, FALSE) != -1 && lastDrinkName != tempName ) { |
296 | // qDebug("appending "+lastDrinkName); | 296 | // qDebug("appending "+lastDrinkName); |
297 | searchList.append( lastDrinkName); | 297 | searchList.append( lastDrinkName); |
298 | tempName=lastDrinkName; | 298 | tempName=lastDrinkName; |
299 | } | 299 | } |
300 | // if( dbFile.atEnd() ) break; | 300 | // if( dbFile.atEnd() ) break; |
301 | 301 | ||
302 | } //oef | 302 | } //oef |
303 | if(searchList.count() >0) | 303 | if(searchList.count() >0) |
304 | showSearchResult(searchList); | 304 | showSearchResult(searchList); |
305 | else | 305 | else |
306 | QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+ searchForDrinkName); | 306 | QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+ searchForDrinkName); |
307 | } | 307 | } |
308 | delete fileDlg; | 308 | delete fileDlg; |
309 | } | 309 | } |
310 | 310 | ||
311 | void Bartender::showSearchResult(QStringList &searchList) { | 311 | void Bartender::showSearchResult(QStringList &searchList) { |
312 | QString result; | 312 | QString result; |
313 | Search_Results *searchDlg; | 313 | Search_Results *searchDlg; |
314 | 314 | ||
315 | searchList.sort(); | 315 | searchList.sort(); |
316 | 316 | ||
317 | searchDlg = new Search_Results(this, "Search Results", TRUE); | 317 | searchDlg = new Search_Results(this, "Search Results", TRUE); |
318 | searchDlg->ListBox1->insertStringList( searchList,-1); | 318 | searchDlg->ListBox1->insertStringList( searchList,-1); |
319 | QPEApplication::execDialog( searchDlg ); | 319 | QPEApplication::execDialog( searchDlg ); |
320 | 320 | ||
321 | if( searchDlg->result() == 1 ) { | 321 | if( searchDlg->result() == 1 ) { |
322 | result= searchDlg->ListBox1->currentText(); | 322 | result= searchDlg->ListBox1->currentText(); |
323 | } | 323 | } |
324 | QListViewItemIterator it2( DrinkView ); | 324 | QListViewItemIterator it2( DrinkView ); |
325 | for ( ; it2.current(); ++it2 ) { | 325 | for ( ; it2.current(); ++it2 ) { |
326 | if ( it2.current()->text(0)== result ) { | 326 | if ( it2.current()->text(0)== result ) { |
327 | // qDebug( it2.current()->text(0)); | 327 | // qDebug( it2.current()->text(0)); |
328 | showDrink(it2.current()); | 328 | showDrink(it2.current()); |
329 | } | 329 | } |
330 | } | 330 | } |
331 | delete searchDlg; | 331 | delete searchDlg; |
332 | } | 332 | } |
333 | 333 | ||
334 | void Bartender::doEdit() { | 334 | void Bartender::doEdit() { |
335 | if(DrinkView->currentItem() == NULL) { | 335 | if(DrinkView->currentItem() == NULL) { |
336 | fileNew(); | 336 | fileNew(); |
337 | } | 337 | } |
338 | 338 | ||
339 | QString myDrink; | 339 | QString myDrink; |
340 | myDrink= DrinkView->currentItem()->text(0); | 340 | myDrink= DrinkView->currentItem()->text(0); |
341 | dbFile.at(0); | 341 | dbFile.at(0); |
342 | int foundAt=0; | 342 | int foundAt=0; |
343 | New_Drink *newDrinks; | 343 | New_Drink *newDrinks; |
344 | newDrinks = new New_Drink(this,"Edit Drink....", TRUE); | 344 | newDrinks = new New_Drink(this,"Edit Drink....", TRUE); |
345 | QString newName, newIng; | 345 | QString newName, newIng; |
346 | QPEApplication::showDialog( newDrinks ); | 346 | QPEApplication::showDialog( newDrinks ); |
347 | QTextStream t( &dbFile); | 347 | QTextStream t( &dbFile); |
348 | 348 | ||
349 | QString s, s2; | 349 | QString s, s2; |
350 | while ( !t.eof()) { | 350 | while ( !t.eof()) { |
351 | s = t.readLine(); | 351 | s = t.readLine(); |
352 | if(s.find( myDrink, 0, TRUE) != -1) { | 352 | if(s.find( myDrink, 0, TRUE) != -1) { |
353 | foundAt = dbFile.at() - (s.length()+1); | 353 | foundAt = dbFile.at() - (s.length()+1); |
354 | for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) { | 354 | for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) { |
355 | s2 = t.readLine(); | 355 | s2 = t.readLine(); |
356 | if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) { | 356 | if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) { |
357 | // qDebug(s2); | 357 | // qDebug(s2); |
358 | newDrinks->MultiLineEdit1->append(s2); | 358 | newDrinks->MultiLineEdit1->append(s2); |
359 | newDrinks->LineEdit1->setText(myDrink); | 359 | newDrinks->LineEdit1->setText(myDrink); |
360 | } | 360 | } |
361 | if( dbFile.atEnd() ) break; | 361 | if( dbFile.atEnd() ) break; |
362 | } | 362 | } |
363 | } | 363 | } |
364 | } | 364 | } |
365 | newDrinks->exec(); | 365 | newDrinks->exec(); |
366 | newName = newDrinks->LineEdit1->text(); | 366 | newName = newDrinks->LineEdit1->text(); |
367 | newIng= newDrinks->MultiLineEdit1->text(); | 367 | newIng= newDrinks->MultiLineEdit1->text(); |
368 | 368 | ||
369 | if( newDrinks ->result() == 1 ) { | 369 | if( newDrinks ->result() == 1 ) { |
370 | if(dbFile.isOpen()) | 370 | if(dbFile.isOpen()) |
371 | dbFile.close(); | 371 | dbFile.close(); |
372 | if ( !dbFile.open( IO_ReadWrite )) { | 372 | if ( !dbFile.open( IO_ReadWrite )) { |
373 | QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); | 373 | QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); |
374 | return; | 374 | return; |
375 | } | 375 | } |
376 | int fd = dbFile.handle(); | 376 | int fd = dbFile.handle(); |
377 | lseek( fd, foundAt, SEEK_SET); | 377 | lseek( fd, foundAt, SEEK_SET); |
378 | 378 | ||
379 | // dbFile.at( foundAt); | 379 | // dbFile.at( foundAt); |
380 | #warning FIXME problems with editing drinks db | 380 | #warning FIXME problems with editing drinks db |
381 | ////////// FIXME write to user file | 381 | ////////// FIXME write to user file |
382 | QString newDrink="# "+newName+"\n"; | 382 | QString newDrink="# "+newName+"\n"; |
383 | newDrink.append(newIng+"\n"); | 383 | newDrink.append(newIng+"\n"); |
384 | qDebug("writing "+newDrink); | 384 | qDebug("writing "+newDrink); |
385 | dbFile.writeBlock( newDrink.latin1(), newDrink.length()); | 385 | dbFile.writeBlock( newDrink.latin1(), newDrink.length()); |
386 | clearList(); | 386 | clearList(); |
387 | 387 | ||
388 | dbFile.flush(); | 388 | dbFile.flush(); |
389 | 389 | ||
390 | initDrinkDb(); | 390 | initDrinkDb(); |
391 | } | 391 | } |
392 | } | 392 | } |
393 | 393 | ||
394 | void Bartender::clearList() { | 394 | void Bartender::clearList() { |
395 | DrinkView->clear(); | 395 | DrinkView->clear(); |
396 | } | 396 | } |
397 | 397 | ||
398 | void Bartender::doBac() { | 398 | void Bartender::doBac() { |
399 | BacDialog *bacDlg; | 399 | BacDialog *bacDlg; |
400 | bacDlg = new BacDialog(this,"BAC",TRUE); | 400 | bacDlg = new BacDialog(this,"BAC",TRUE); |
401 | QPEApplication::execDialog( bacDlg ); | 401 | QPEApplication::execDialog( bacDlg ); |
402 | delete bacDlg; | 402 | delete bacDlg; |
403 | } | 403 | } |
404 | 404 | ||
405 | void Bartender::openCurrentDrink() { | 405 | void Bartender::openCurrentDrink() { |
406 | if(DrinkView->currentItem() == NULL) return; | 406 | if(DrinkView->currentItem() == NULL) return; |
407 | showDrink(DrinkView->currentItem()); | 407 | showDrink(DrinkView->currentItem()); |
408 | } | 408 | } |
409 | 409 | ||
410 | void Bartender::fileMenuActivated( int item) { | 410 | void Bartender::fileMenuActivated( int item) { |
411 | qDebug("Item %d", item); | 411 | qDebug("Item %d", item); |
412 | switch(item) { | 412 | switch(item) { |
413 | case -3: // new -3 | 413 | case -3: // new -3 |
414 | fileNew(); | 414 | fileNew(); |
415 | break; | 415 | break; |
416 | case -4:// open -4 | 416 | case -4:// open -4 |
417 | openCurrentDrink(); | 417 | openCurrentDrink(); |
418 | break; | 418 | break; |
419 | case -5:// drink -5 | 419 | case -5:// drink -5 |
420 | doSearchByName(); | 420 | doSearchByName(); |
421 | 421 | ||
422 | break; | 422 | break; |
423 | case -6:// alcohol -6 | 423 | case -6:// alcohol -6 |
424 | doSearchByDrink(); | 424 | doSearchByDrink(); |
425 | 425 | ||
426 | break; | 426 | break; |
427 | 427 | ||
428 | } | 428 | } |
429 | } | 429 | } |
430 | 430 | ||
431 | void Bartender::editMenuActivated(int item) { | 431 | void Bartender::editMenuActivated(int item) { |
432 | qDebug("Item %d", item); | 432 | qDebug("Item %d", item); |
433 | /* | 433 | /* |
434 | edit -8 | 434 | edit -8 |
435 | */ | 435 | */ |
436 | switch(item) { | 436 | switch(item) { |
437 | case -8: | 437 | case -8: |
438 | doEdit() ; | 438 | doEdit() ; |
439 | break; | 439 | break; |
440 | 440 | ||
441 | } | 441 | } |
442 | } | 442 | } |
443 | 443 | ||
diff --git a/noncore/apps/opie-bartender/opie-bartender.control b/noncore/apps/opie-bartender/opie-bartender.control index acd3304..a8bf860 100644 --- a/noncore/apps/opie-bartender/opie-bartender.control +++ b/noncore/apps/opie-bartender/opie-bartender.control | |||
@@ -1,10 +1,10 @@ | |||
1 | Files: bin/bartender apps/Applications/bartender.desktop | 1 | Files: bin/bartender apps/Applications/bartender.desktop |
2 | Priority: optional | 2 | Priority: optional |
3 | Package: opie-bartender | 3 | Package: opie-bartender |
4 | Section: opie/applications | 4 | Section: opie/applications |
5 | Maintainer: L.J. Potter <lpotter@trolltech.com> | 5 | Maintainer: L.J. Potter <lpotter@trolltech.com> |
6 | Architecture: arm | 6 | Architecture: arm |
7 | Version: $QPE_VERSION-$SUB_VERSION | 7 | Version: $QPE_VERSION-$SUB_VERSION |
8 | Depends: qpe-base ($QPE_VERSION) | 8 | Depends: task-opie-minimal |
9 | Description: Bartender drink receipe database lookup, and | 9 | Description: Bartender drink receipe database lookup, and |
10 | blood alcohol estimator. | 10 | blood alcohol estimator. |