summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-bartender/bartender.cpp235
-rw-r--r--noncore/apps/opie-bartender/bartender.h5
-rw-r--r--noncore/apps/opie-bartender/bartender.pro10
-rw-r--r--noncore/apps/opie-bartender/drinkdata.cpp147
-rw-r--r--noncore/apps/opie-bartender/drinkdata.h48
-rw-r--r--noncore/apps/opie-bartender/newDrinks.ui4
-rw-r--r--noncore/apps/opie-bartender/newdrinks.cpp1
-rw-r--r--noncore/apps/opie-bartender/showdrinks.cpp1
-rw-r--r--noncore/apps/opie-bartender/showdrinks.h2
9 files changed, 309 insertions, 144 deletions
diff --git a/noncore/apps/opie-bartender/bartender.cpp b/noncore/apps/opie-bartender/bartender.cpp
index b4958b3..bee164c 100644
--- a/noncore/apps/opie-bartender/bartender.cpp
+++ b/noncore/apps/opie-bartender/bartender.cpp
@@ -15,6 +15,7 @@
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#include "drinkdata.h"
18 19
19/* OPIE */ 20/* OPIE */
20#include <opie2/odebug.h> 21#include <opie2/odebug.h>
@@ -55,6 +56,8 @@ Bartender::Bartender( QWidget* parent, const char* name, WFlags fl )
55 56
56 setCaption( tr( "Bartender" ) ); 57 setCaption( tr( "Bartender" ) );
57 58
59 setToolBarsMovable( FALSE );
60
58 ToolBar1 = new QToolBar( this, "ToolBar1" ); 61 ToolBar1 = new QToolBar( this, "ToolBar1" );
59 ToolBar1->setFixedHeight(22); 62 ToolBar1->setFixedHeight(22);
60 layout->addMultiCellWidget( ToolBar1, 0, 0, 0, 4 ); 63 layout->addMultiCellWidget( ToolBar1, 0, 0, 0, 4 );
@@ -67,12 +70,12 @@ Bartender::Bartender( QWidget* parent, const char* name, WFlags fl )
67 fileMenu->insertItem(tr("New Drink")); 70 fileMenu->insertItem(tr("New Drink"));
68 fileMenu->insertItem(tr("Open Drink")); 71 fileMenu->insertItem(tr("Open Drink"));
69 fileMenu->insertItem(tr("Find by Drink Name")); 72 fileMenu->insertItem(tr("Find by Drink Name"));
70 fileMenu->insertItem(tr("Find by Alcohol")); 73 fileMenu->insertItem(tr("Find by Ingredient"));
71 74
72 QPopupMenu *editMenu; 75 QPopupMenu *editMenu;
73 editMenu = new QPopupMenu( this); 76 editMenu = new QPopupMenu( this);
74 menuBar->insertItem( tr("Edit"), editMenu ); 77 menuBar->insertItem( tr("Edit"), editMenu );
75 editMenu->insertItem(tr("edit")); 78 editMenu->insertItem(tr("Edit Drink"));
76 79
77 connect( fileMenu, SIGNAL( activated(int) ), this, SLOT( fileMenuActivated(int) )); 80 connect( fileMenu, SIGNAL( activated(int) ), this, SLOT( fileMenuActivated(int) ));
78 connect( editMenu, SIGNAL( activated(int) ), this, SLOT( editMenuActivated(int) )); 81 connect( editMenu, SIGNAL( activated(int) ), this, SLOT( editMenuActivated(int) ));
@@ -110,11 +113,14 @@ Bartender::Bartender( QWidget* parent, const char* name, WFlags fl )
110 this,SLOT( showDrink(int,QListViewItem*,const QPoint&,int))); 113 this,SLOT( showDrink(int,QListViewItem*,const QPoint&,int)));
111 114
112 layout->addMultiCellWidget( DrinkView, 1, 2, 0, 4 ); 115 layout->addMultiCellWidget( DrinkView, 1, 2, 0, 4 );
113 if(QDir("db").exists()) { 116 if(QDir("db").exists())
114 dbFile.setName( "db/drinkdb.txt"); 117 drinkDB.setFile("db/drinkdb.txt");
115 } else 118 else
116 dbFile.setName( QPEApplication::qpeDir()+"etc/bartender/drinkdb.txt"); 119 drinkDB.setFile(QPEApplication::qpeDir()+"etc/bartender/drinkdb.txt");
120
117 initDrinkDb(); 121 initDrinkDb();
122
123 DrinkView->setFocus();
118} 124}
119 125
120Bartender::~Bartender() { 126Bartender::~Bartender() {
@@ -123,63 +129,66 @@ Bartender::~Bartender() {
123/* 129/*
124this happens right before exit */ 130this happens right before exit */
125void Bartender::cleanUp() { 131void Bartender::cleanUp() {
126 dbFile.close();
127 132
128} 133}
129 134
130void Bartender::initDrinkDb() { 135void Bartender::initDrinkDb() {
131 136 if(drinkDB.read())
132 if(!dbFile.isOpen()) 137 fillList();
133 if ( !dbFile.open( IO_ReadOnly)) { 138 else
134 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); 139 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) );
135 return;
136 }
137 fillList();
138} 140}
139 141
140void Bartender::fillList() { 142void Bartender::fillList() {
141 dbFile.at(1); 143 QString lastName;
144 if( DrinkView->currentItem() != NULL )
145 lastName = DrinkView->currentItem()->text(0);
146 else
147 lastName = "";
148
142 DrinkView->clear(); 149 DrinkView->clear();
143 int i=0; 150 int i=0;
144 QListViewItem * item ; 151 QListViewItem * item ;
145 QTextStream t( &dbFile);
146 QString s; 152 QString s;
147 while ( !t.eof()) { 153
148 s = t.readLine(); 154 DrinkList::Iterator it = drinkDB.getBegin();
149 if(s.find("#",0,TRUE) != -1) { 155 while ( it != drinkDB.getEnd() ) {
150// odebug << s.right(s.length()-2) << oendl; 156 item= new QListViewItem( DrinkView, 0 );
151 item= new QListViewItem( DrinkView, 0 ); 157 item->setText( 0, (*it).getName());
152 item->setText( 0, s.right(s.length()-2)); 158 i++;
153 i++; 159 ++it;
160 }
161
162 if( lastName != "" ) {
163 QListViewItemIterator it( DrinkView );
164 for ( ; it.current(); ++it ) {
165 if ( it.current()->text(0) == lastName ) {
166 DrinkView->setCurrentItem(it.current());
167 break;
168 }
154 } 169 }
155 } 170 }
171 else if( DrinkView->childCount() > 0)
172 DrinkView->setCurrentItem(DrinkView->firstChild());
173
156 odebug << "there are currently " << i << " of drinks" << oendl; 174 odebug << "there are currently " << i << " of drinks" << oendl;
157} 175}
158 176
159void Bartender::fileNew() { 177void Bartender::fileNew() {
160 178
161 New_Drink *newDrinks; 179 New_Drink *newDrinks;
162 newDrinks = new New_Drink(this,"New Drink....", TRUE); 180 newDrinks = new New_Drink(this,"New Drink", TRUE);
163 QString newName, newIng; 181 QString newName, newIng;
164 QPEApplication::execDialog( newDrinks ); 182 QPEApplication::execDialog( newDrinks );
165 newName = newDrinks->LineEdit1->text(); 183 newName = newDrinks->LineEdit1->text();
166 newIng= newDrinks->MultiLineEdit1->text(); 184 newIng= newDrinks->MultiLineEdit1->text();
167 185
168 if(dbFile.isOpen())
169 dbFile.close();
170 if ( !dbFile.open( IO_WriteOnly| IO_Append)) {
171 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) );
172 return;
173 }
174 if(newDrinks ->result() == 1 ) { 186 if(newDrinks ->result() == 1 ) {
175 QString newDrink="\n# "+newName+"\n"; 187 drinkDB.addDrink(newName, newIng);
176 newDrink.append(newIng+"\n"); 188 if(!drinkDB.writeChanges()) {
177 odebug << "writing "+newDrink << oendl; 189 QMessageBox::message( (tr("Note")), (tr("Failed to write to drink database!\n")) );
178 dbFile.writeBlock( newDrink.latin1(), newDrink.length()); 190 }
179 clearList(); 191 fillList();
180 dbFile.close();
181
182 initDrinkDb();
183 } 192 }
184 delete newDrinks; 193 delete newDrinks;
185} 194}
@@ -197,43 +206,30 @@ void Bartender::showDrink(int mouse, QListViewItem * item, const QPoint&, int) {
197 206
198void Bartender::showDrink( QListViewItem *item) { 207void Bartender::showDrink( QListViewItem *item) {
199 if(item==NULL) return; 208 if(item==NULL) return;
200 dbFile.at(0);
201 Show_Drink *showDrinks; 209 Show_Drink *showDrinks;
202 QString myDrink=item->text(0); 210 QString myDrink=item->text(0);
203 showDrinks = new Show_Drink(this, myDrink, TRUE); 211 showDrinks = new Show_Drink(this, myDrink, TRUE);
204 QTextStream t( &dbFile);
205
206 QString s, s2;
207 while ( !t.eof()) {
208 s = t.readLine();
209 if(s.find( myDrink, 0, TRUE) != -1) {
210 for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) {
211 s2 = t.readLine();
212 if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) {
213// odebug << s2 << oendl;
214 showDrinks->MultiLineEdit1->append(s2);
215 }
216 if( dbFile.atEnd() ) break;
217 }
218 }
219 }
220 QPEApplication::execDialog( showDrinks );
221 212
222 if(showDrinks ->result() ==0) { 213 DrinkList::Iterator it = drinkDB.findDrink(myDrink);
223 doEdit(); 214 if(it != drinkDB.getEnd()) {
215 showDrinks->MultiLineEdit1->setText((*it).getIngredients());
216
217 connect(showDrinks->editDrinkButton, SIGNAL(clicked()), this, SLOT(doEdit()));
218 QPEApplication::execDialog( showDrinks );
224 } 219 }
220
225 delete showDrinks; 221 delete showDrinks;
226} 222}
227 223
228void Bartender::askSearch() { 224void Bartender::askSearch() {
229 switch ( QMessageBox::warning(this,tr("Find"),tr("Search by drink name\n")+ 225 switch ( QMessageBox::warning(this,tr("Find"),tr("Search by drink name\n")+
230 "\nor alcohol ?" 226 "\nor ingredient ?"
231 ,tr("Drink Name"),tr("Alcohol"),0,0,1) ) { 227 ,tr("Drink Name"),tr("Ingredient"),0,0,1) ) {
232 case 0: 228 case 0:
233 doSearchByName(); 229 doSearchByName();
234 break; 230 break;
235 case 1: 231 case 1:
236 doSearchByDrink(); 232 doSearchByIngredient();
237 break; 233 break;
238 }; 234 };
239} 235}
@@ -250,7 +246,7 @@ void Bartender::doSearchByName() {
250 searchForDrinkName = fileDlg->LineEdit1->text(); 246 searchForDrinkName = fileDlg->LineEdit1->text();
251 QListViewItemIterator it( DrinkView ); 247 QListViewItemIterator it( DrinkView );
252 for ( ; it.current(); ++it ) { 248 for ( ; it.current(); ++it ) {
253 if ( it.current()->text(0).find( searchForDrinkName, 0, TRUE) != -1 ) { 249 if ( it.current()->text(0).find( searchForDrinkName, 0, FALSE) != -1 ) {
254// odebug << it.current()->text(0) << oendl; 250// odebug << it.current()->text(0) << oendl;
255 searchList.append(it.current()->text(0)); 251 searchList.append(it.current()->text(0));
256 } 252 }
@@ -263,39 +259,32 @@ void Bartender::doSearchByName() {
263 delete fileDlg; 259 delete fileDlg;
264} 260}
265 261
266void Bartender::doSearchByDrink() { 262void Bartender::doSearchByIngredient() {
267// if( DrinkView->currentItem() == NULL) return; 263// if( DrinkView->currentItem() == NULL) return;
268 QStringList searchList; 264 QStringList searchList;
269 QString searchForDrinkName, lastDrinkName, tempName; 265 QString searchForIngredient, lastDrinkName, lastDrinkIngredients;
270 266
271 InputDialog *fileDlg; 267 InputDialog *fileDlg;
272 fileDlg = new InputDialog(this,tr("Find by Alcohol"),TRUE, 0); 268 fileDlg = new InputDialog(this,tr("Find by Ingredient"),TRUE, 0);
273 fileDlg->exec(); 269 fileDlg->exec();
274 if( fileDlg->result() == 1 ) { 270 if( fileDlg->result() == 1 ) {
275 searchForDrinkName = fileDlg->LineEdit1->text(); 271 searchForIngredient = fileDlg->LineEdit1->text();
276 272
277 dbFile.at(0); 273 DrinkList::Iterator it = drinkDB.getBegin();
278 QTextStream t( &dbFile); 274 while ( it != drinkDB.getEnd() ) {
279 275 lastDrinkName = (*it).getName();
280 QString s, s2; 276 lastDrinkIngredients = (*it).getIngredients();
281 while ( !t.eof()) { 277
282 s = t.readLine(); 278 if( lastDrinkIngredients.find( searchForIngredient ,0, FALSE) != -1 )
283 if(s.find("#",0,TRUE) != -1) { 279 searchList.append( lastDrinkName );
284 lastDrinkName=s.right(s.length()-2); 280
285// odebug << "last drink name "+lastDrinkName << oendl; 281 ++it;
286 } 282 }
287 else if( s.find( searchForDrinkName ,0, FALSE) != -1 && lastDrinkName != tempName ) { 283
288// odebug << "appending "+lastDrinkName << oendl;
289 searchList.append( lastDrinkName);
290 tempName=lastDrinkName;
291 }
292// if( dbFile.atEnd() ) break;
293
294 } //oef
295 if(searchList.count() >0) 284 if(searchList.count() >0)
296 showSearchResult(searchList); 285 showSearchResult(searchList);
297 else 286 else
298 QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+ searchForDrinkName); 287 QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+ searchForIngredient);
299 } 288 }
300 delete fileDlg; 289 delete fileDlg;
301} 290}
@@ -324,63 +313,39 @@ delete searchDlg;
324} 313}
325 314
326void Bartender::doEdit() { 315void Bartender::doEdit() {
327 if(DrinkView->currentItem() == NULL) { 316 if(DrinkView->currentItem() == NULL) {
328 fileNew(); 317 fileNew();
329 } 318 return;
319 }
330 320
331 QString myDrink; 321 QString myDrink;
332 myDrink= DrinkView->currentItem()->text(0); 322 myDrink= DrinkView->currentItem()->text(0);
333 dbFile.at(0); 323
334 int foundAt=0;
335 New_Drink *newDrinks; 324 New_Drink *newDrinks;
336 newDrinks = new New_Drink(this,"Edit Drink....", TRUE); 325 newDrinks = new New_Drink(this,"Edit Drink", TRUE);
337 QString newName, newIng; 326 QString newName, newIng;
338 QPEApplication::showDialog( newDrinks ); 327 QPEApplication::showDialog( newDrinks );
339 QTextStream t( &dbFile);
340
341 QString s, s2;
342 while ( !t.eof()) {
343 s = t.readLine();
344 if(s.find( myDrink, 0, TRUE) != -1) {
345 foundAt = dbFile.at() - (s.length()+1);
346 for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) {
347 s2 = t.readLine();
348 if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) {
349// odebug << s2 << oendl;
350 newDrinks->MultiLineEdit1->append(s2);
351 newDrinks->LineEdit1->setText(myDrink);
352 }
353 if( dbFile.atEnd() ) break;
354 }
355 }
356 }
357 newDrinks->exec();
358 newName = newDrinks->LineEdit1->text();
359 newIng= newDrinks->MultiLineEdit1->text();
360 328
361 if( newDrinks ->result() == 1 ) { 329 DrinkList::Iterator drinkItem = drinkDB.findDrink(myDrink);
362 if(dbFile.isOpen()) 330 if(drinkItem != drinkDB.getEnd()) {
363 dbFile.close(); 331 newDrinks->LineEdit1->setText((*drinkItem).getName());
364 if ( !dbFile.open( IO_ReadWrite )) { 332 newDrinks->MultiLineEdit1->setText((*drinkItem).getIngredients());
365 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); 333
366 return; 334 newDrinks->exec();
335 newName = newDrinks->LineEdit1->text();
336 newIng= newDrinks->MultiLineEdit1->text();
337
338 if( newDrinks ->result() == 1 ) {
339 (*drinkItem).setName(newName);
340 (*drinkItem).setIngredients(newIng);
341 if(!drinkDB.writeChanges()) {
342 QMessageBox::message( (tr("Note")), (tr("Failed to write to drink database!\n")) );
343 }
344 fillList();
367 } 345 }
368 int fd = dbFile.handle();
369 lseek( fd, foundAt, SEEK_SET);
370
371// dbFile.at( foundAt);
372#warning FIXME problems with editing drinks db
373 ////////// FIXME write to user file
374 QString newDrink="# "+newName+"\n";
375 newDrink.append(newIng+"\n");
376 odebug << "writing "+newDrink << oendl;
377 dbFile.writeBlock( newDrink.latin1(), newDrink.length());
378 clearList();
379
380 dbFile.flush();
381
382 initDrinkDb();
383 } 346 }
347
348 delete newDrinks;
384} 349}
385 350
386void Bartender::clearList() { 351void Bartender::clearList() {
@@ -413,7 +378,7 @@ void Bartender::fileMenuActivated( int item) {
413 378
414 break; 379 break;
415 case -6:// alcohol -6 380 case -6:// alcohol -6
416 doSearchByDrink(); 381 doSearchByIngredient();
417 382
418 break; 383 break;
419 384
diff --git a/noncore/apps/opie-bartender/bartender.h b/noncore/apps/opie-bartender/bartender.h
index 27362df..9970ef1 100644
--- a/noncore/apps/opie-bartender/bartender.h
+++ b/noncore/apps/opie-bartender/bartender.h
@@ -11,6 +11,7 @@
11#ifndef BARTENDER_H 11#ifndef BARTENDER_H
12#define BARTENDER_H 12#define BARTENDER_H
13#include "newdrinks.h" 13#include "newdrinks.h"
14#include "drinkdata.h"
14 15
15#include <qvariant.h> 16#include <qvariant.h>
16#include <qwidget.h> 17#include <qwidget.h>
@@ -36,7 +37,7 @@ public:
36 37
37 QToolBar* ToolBar1; 38 QToolBar* ToolBar1;
38 QListView* DrinkView; 39 QListView* DrinkView;
39 QFile dbFile; 40 DrinkData drinkDB;
40public slots: 41public slots:
41 void doEdit(); 42 void doEdit();
42 43
@@ -51,7 +52,7 @@ protected slots:
51 void showDrink(int, QListViewItem *, const QPoint&, int); 52 void showDrink(int, QListViewItem *, const QPoint&, int);
52 void initDrinkDb(); 53 void initDrinkDb();
53 void doSearchByName(); 54 void doSearchByName();
54 void doSearchByDrink(); 55 void doSearchByIngredient();
55 void showSearchResult(QStringList &); 56 void showSearchResult(QStringList &);
56 void doBac(); 57 void doBac();
57 void openCurrentDrink(); 58 void openCurrentDrink();
diff --git a/noncore/apps/opie-bartender/bartender.pro b/noncore/apps/opie-bartender/bartender.pro
index cdec93c..b304ae9 100644
--- a/noncore/apps/opie-bartender/bartender.pro
+++ b/noncore/apps/opie-bartender/bartender.pro
@@ -1,9 +1,11 @@
1CONFIG = qt quick-app 1TEMPLATE = app
2HEADERS = bartender.h newdrinks.h showdrinks.h inputDialog.h searchresults.h bac.h 2CONFIG = qt warn_on
3SOURCES = main.cpp bartender.cpp newdrinks.cpp showdrinks.cpp inputDialog.cpp searchresults.cpp bac.cpp 3HEADERS = bartender.h newdrinks.h showdrinks.h inputDialog.h searchresults.h bac.h drinkdata.h
4SOURCES = main.cpp bartender.cpp newdrinks.cpp showdrinks.cpp inputDialog.cpp searchresults.cpp bac.cpp drinkdata.cpp
4INCLUDEPATH += $(OPIEDIR)/include 5INCLUDEPATH += $(OPIEDIR)/include
5DEPENDPATH += $(OPIEDIR)/include 6DEPENDPATH += $(OPIEDIR)/include
6LIBS += -lqpe -lopiecore2 7LIBS += -lqpe -lopiecore2 -lopieui2
8DESTDIR = $(OPIEDIR)/bin
7TARGET = bartender 9TARGET = bartender
8 10
9include( $(OPIEDIR)/include.pro ) 11include( $(OPIEDIR)/include.pro )
diff --git a/noncore/apps/opie-bartender/drinkdata.cpp b/noncore/apps/opie-bartender/drinkdata.cpp
new file mode 100644
index 0000000..8856e46
--- a/dev/null
+++ b/noncore/apps/opie-bartender/drinkdata.cpp
@@ -0,0 +1,147 @@
1/****************************************************************************
2** Created: Sun Dec 26 22:00:00 2004
3** by: Paul Eggleton <bluelightning@bluelightning.org>
4** copyright : (C) 2004 by Paul Eggleton
5 email : bluelightning@bluelightning.org
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
11
12/* QT */
13#include <qfile.h>
14#include <qtextstream.h>
15#include <qvaluelist.h>
16
17/* STD */
18#include <fcntl.h>
19#include <unistd.h>
20#include <stdlib.h>
21#include <iostream>
22#include <errno.h>
23
24#include "drinkdata.h"
25
26// ----- DrinkData -----
27
28DrinkData::DrinkData() {
29}
30
31void DrinkData::setFile(const QString &filename) {
32 this->filename = filename;
33}
34
35bool DrinkData::read(void) {
36 QFile dbFile;
37
38 dbFile.setName(filename);
39 if ( !dbFile.open( IO_ReadOnly)) {
40 return false;
41 }
42
43 items.clear();
44
45 QTextStream t( &dbFile);
46 QString s, name = "", ingredients = "";
47
48 while ( !t.eof()) {
49 s = t.readLine();
50 if(s.find( "#", 0, TRUE) != -1 || dbFile.atEnd()) {
51 if(name != "")
52 addDrink(name, ingredients);
53 // Start new entry
54 name = s.right(s.length()-2);
55 ingredients = "";
56 }
57 else {
58 if(ingredients != "")
59 ingredients += '\n';
60 ingredients += s;
61 }
62 }
63
64 dbFile.close();
65
66 return true;
67}
68
69void DrinkData::print(void) {
70 DrinkList::Iterator it = items.begin();
71 while ( it != items.end() ) {
72 std::cout << (*it).getName() << '\n';
73 ++it;
74 }
75}
76
77void DrinkData::addDrink(const QString &name, const QString &ingredients) {
78 DrinkItem item(name, ingredients);
79 items.append(item);
80}
81
82DrinkList::Iterator DrinkData::findDrink(const QString &name) {
83 DrinkList::Iterator it = items.begin();
84 while ( it != items.end() ) {
85 if((*it).getName() == name)
86 return it;
87 ++it;
88 }
89 return items.end();
90}
91
92DrinkList::Iterator DrinkData::getBegin(void) {
93 return items.begin();
94}
95
96DrinkList::Iterator DrinkData::getEnd(void) {
97 return items.end();
98}
99
100bool DrinkData::writeChanges(void) {
101 QFile dbFile;
102
103 dbFile.setName(filename);
104 if ( !dbFile.open( IO_WriteOnly | IO_Truncate )) {
105 return false;
106 }
107
108 QTextStream t( &dbFile);
109
110 DrinkList::Iterator it = items.begin();
111 while ( it != items.end() ) {
112 t << "# " << (*it).getName() << '\n';
113 t << (*it).getIngredients() << '\n';
114 ++it;
115 }
116
117 dbFile.close();
118
119 return true;
120}
121
122
123// ----- DrinkItem -----
124
125DrinkItem::DrinkItem(void) {
126}
127
128DrinkItem::DrinkItem(const QString &name, const QString &ingredients) {
129 this->name = name;
130 this->ingredients = ingredients;
131}
132
133const QString &DrinkItem::getName(void) {
134 return name;
135}
136
137const QString &DrinkItem::getIngredients(void) {
138 return ingredients;
139}
140
141void DrinkItem::setName(const QString &name) {
142 this->name = name;
143}
144
145void DrinkItem::setIngredients(const QString &ingredients) {
146 this->ingredients = ingredients;
147}
diff --git a/noncore/apps/opie-bartender/drinkdata.h b/noncore/apps/opie-bartender/drinkdata.h
new file mode 100644
index 0000000..bcc3022
--- a/dev/null
+++ b/noncore/apps/opie-bartender/drinkdata.h
@@ -0,0 +1,48 @@
1/****************************************************************************
2** Created: Sun Dec 26 22:00:00 2004
3** by: Paul Eggleton <bluelightning@bluelightning.org>
4** copyright : (C) 2004 by Paul Eggleton
5 email : bluelightning@bluelightning.org
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 ***************************************************************************/
11
12#ifndef DRINKDATA_H
13#define DRINKDATA_H
14
15class DrinkItem;
16
17typedef QValueList<DrinkItem> DrinkList;
18
19class DrinkData {
20private:
21 DrinkList items;
22 QString filename;
23public:
24 DrinkData(void);
25 void setFile(const QString &filename);
26 bool writeChanges(void);
27 bool read(void);
28 void print(void);
29 void addDrink(const QString &name, const QString &ingredients);
30 DrinkList::Iterator getBegin(void);
31 DrinkList::Iterator getEnd(void);
32 DrinkList::Iterator findDrink(const QString &name);
33};
34
35class DrinkItem {
36private:
37 QString name;
38 QString ingredients;
39public:
40 DrinkItem(void);
41 DrinkItem(const QString &name, const QString &ingredients);
42 const QString &getName(void);
43 const QString &getIngredients(void);
44 void setName(const QString &name);
45 void setIngredients(const QString &ingredients);
46};
47
48#endif // DRINKDATA_H
diff --git a/noncore/apps/opie-bartender/newDrinks.ui b/noncore/apps/opie-bartender/newDrinks.ui
index eccb312..bcf21d2 100644
--- a/noncore/apps/opie-bartender/newDrinks.ui
+++ b/noncore/apps/opie-bartender/newDrinks.ui
@@ -11,7 +11,7 @@
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>245</width> 14 <width>241</width>
15 <height>320</height> 15 <height>320</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
@@ -86,7 +86,7 @@
86 </property> 86 </property>
87 <property stdset="1"> 87 <property stdset="1">
88 <name>text</name> 88 <name>text</name>
89 <string>Ingrediants</string> 89 <string>Ingredients</string>
90 </property> 90 </property>
91 </widget> 91 </widget>
92 <widget row="2" column="0" > 92 <widget row="2" column="0" >
diff --git a/noncore/apps/opie-bartender/newdrinks.cpp b/noncore/apps/opie-bartender/newdrinks.cpp
index a7ada3a..2540fb1 100644
--- a/noncore/apps/opie-bartender/newdrinks.cpp
+++ b/noncore/apps/opie-bartender/newdrinks.cpp
@@ -46,6 +46,7 @@ New_Drink::New_Drink( QWidget* parent, const char* name, bool modal, WFlags fl
46 Layout5->addMultiCellWidget( TextLabel2, 1, 1, 0, 0); 46 Layout5->addMultiCellWidget( TextLabel2, 1, 1, 0, 0);
47 47
48 MultiLineEdit1 = new QMultiLineEdit( this, "MultiLineEdit1" ); 48 MultiLineEdit1 = new QMultiLineEdit( this, "MultiLineEdit1" );
49 MultiLineEdit1->setWordWrap(QMultiLineEdit::WidgetWidth);
49 50
50 Layout5->addMultiCellWidget( MultiLineEdit1, 2, 2, 0, 2); 51 Layout5->addMultiCellWidget( MultiLineEdit1, 2, 2, 0, 2);
51} 52}
diff --git a/noncore/apps/opie-bartender/showdrinks.cpp b/noncore/apps/opie-bartender/showdrinks.cpp
index dcfce16..9f679f0 100644
--- a/noncore/apps/opie-bartender/showdrinks.cpp
+++ b/noncore/apps/opie-bartender/showdrinks.cpp
@@ -36,6 +36,7 @@ Show_Drink::Show_Drink( QWidget* parent, const char* name, bool modal, WFlags f
36 36
37 MultiLineEdit1 = new QMultiLineEdit( this, "MultiLineEdit1" ); 37 MultiLineEdit1 = new QMultiLineEdit( this, "MultiLineEdit1" );
38 MultiLineEdit1->setWordWrap(QMultiLineEdit::WidgetWidth); 38 MultiLineEdit1->setWordWrap(QMultiLineEdit::WidgetWidth);
39 MultiLineEdit1->setReadOnly(true);
39 Layout5->addMultiCellWidget( MultiLineEdit1, 1, 3, 0, 3 ); 40 Layout5->addMultiCellWidget( MultiLineEdit1, 1, 3, 0, 3 );
40} 41}
41 42
diff --git a/noncore/apps/opie-bartender/showdrinks.h b/noncore/apps/opie-bartender/showdrinks.h
index 11a0cc1..f892c18 100644
--- a/noncore/apps/opie-bartender/showdrinks.h
+++ b/noncore/apps/opie-bartender/showdrinks.h
@@ -33,12 +33,12 @@ public:
33 ~Show_Drink(); 33 ~Show_Drink();
34 34
35 QMultiLineEdit* MultiLineEdit1; 35 QMultiLineEdit* MultiLineEdit1;
36 QPushButton *editDrinkButton;
36public slots: 37public slots:
37 void slotEditDrink(); 38 void slotEditDrink();
38protected: 39protected:
39 QGridLayout* Layout5; 40 QGridLayout* Layout5;
40 QString drinkName; 41 QString drinkName;
41 QPushButton *editDrinkButton;
42}; 42};
43 43
44#endif // SHOW_DRINK_H 44#endif // SHOW_DRINK_H