author | llornkcor <llornkcor> | 2004-12-27 23:41:09 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-12-27 23:41:09 (UTC) |
commit | 02395040e422485ceb2fa435a3fb30879d5f3df2 (patch) (side-by-side diff) | |
tree | 0052da61e1a209bddf2da6f130210d569610de9f | |
parent | b2b6055b9180214150cdbbff72b79b35db379fb2 (diff) | |
download | opie-02395040e422485ceb2fa435a3fb30879d5f3df2.zip opie-02395040e422485ceb2fa435a3fb30879d5f3df2.tar.gz opie-02395040e422485ceb2fa435a3fb30879d5f3df2.tar.bz2 |
new code from Paul Eggleton
-rw-r--r-- | noncore/apps/opie-bartender/bartender.cpp | 235 | ||||
-rw-r--r-- | noncore/apps/opie-bartender/bartender.h | 5 | ||||
-rw-r--r-- | noncore/apps/opie-bartender/bartender.pro | 10 | ||||
-rw-r--r-- | noncore/apps/opie-bartender/drinkdata.cpp | 147 | ||||
-rw-r--r-- | noncore/apps/opie-bartender/drinkdata.h | 48 | ||||
-rw-r--r-- | noncore/apps/opie-bartender/newDrinks.ui | 4 | ||||
-rw-r--r-- | noncore/apps/opie-bartender/newdrinks.cpp | 1 | ||||
-rw-r--r-- | noncore/apps/opie-bartender/showdrinks.cpp | 1 | ||||
-rw-r--r-- | noncore/apps/opie-bartender/showdrinks.h | 2 |
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 @@ -2,32 +2,33 @@ ** ** Created: Sat Jul 20 08:10:53 2002 ** by: L.J. Potter <ljp@llornkcor.com> ** copyright : (C) 2002 by ljp email : ljp@llornkcor.com * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #include "bartender.h" #include "showdrinks.h" #include "inputDialog.h" #include "searchresults.h" #include "bac.h" +#include "drinkdata.h" /* OPIE */ #include <opie2/odebug.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> using namespace Opie::Core; /* QT */ #include <qlineedit.h> #include <qdir.h> #include <qpushbutton.h> #include <qlistbox.h> #include <qmultilineedit.h> #include <qmessagebox.h> #include <qtextstream.h> #include <qaction.h> @@ -42,50 +43,52 @@ using namespace Opie::Core; #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <errno.h> Bartender::Bartender( QWidget* parent, const char* name, WFlags fl ) : QMainWindow( parent, name, fl ) { if ( !name ) setName( "Bartender" ); QGridLayout *layout = new QGridLayout( this ); layout->setSpacing( 2); layout->setMargin( 2); connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); setCaption( tr( "Bartender" ) ); + setToolBarsMovable( FALSE ); + ToolBar1 = new QToolBar( this, "ToolBar1" ); ToolBar1->setFixedHeight(22); layout->addMultiCellWidget( ToolBar1, 0, 0, 0, 4 ); QMenuBar *menuBar = new QMenuBar( ToolBar1 ); QPopupMenu *fileMenu; fileMenu = new QPopupMenu( this); menuBar->insertItem( tr("File"), fileMenu ); fileMenu->insertItem(tr("New Drink")); fileMenu->insertItem(tr("Open Drink")); fileMenu->insertItem(tr("Find by Drink Name")); - fileMenu->insertItem(tr("Find by Alcohol")); + fileMenu->insertItem(tr("Find by Ingredient")); QPopupMenu *editMenu; editMenu = new QPopupMenu( this); menuBar->insertItem( tr("Edit"), editMenu ); - editMenu->insertItem(tr("edit")); + editMenu->insertItem(tr("Edit Drink")); connect( fileMenu, SIGNAL( activated(int) ), this, SLOT( fileMenuActivated(int) )); connect( editMenu, SIGNAL( activated(int) ), this, SLOT( editMenuActivated(int) )); QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), "New", 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); a->addTo( ToolBar1 ); a = new QAction( tr( "Open" ), Resource::loadPixmap( "bartender/bartender_sm" ), "open", 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( openCurrentDrink() ) ); a->addTo( ToolBar1 ); a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), "Find", 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( askSearch() ) ); a->addTo( ToolBar1 ); @@ -97,336 +100,298 @@ Bartender::Bartender( QWidget* parent, const char* name, WFlags fl ) QPushButton *t; t= new QPushButton( "BAC", ToolBar1, "bacButtin"); connect( t, SIGNAL( clicked() ), this, SLOT( doBac() ) ); DrinkView = new QListView( this, "DrinkView" ); DrinkView->addColumn( tr( "Name of Drink" ) ); // DrinkView->setRootIsDecorated( TRUE ); DrinkView->header()->hide(); QPEApplication::setStylusOperation( DrinkView->viewport(),QPEApplication::RightOnHold); connect(DrinkView, SIGNAL( doubleClicked(QListViewItem*)),this,SLOT(showDrink(QListViewItem*))); connect(DrinkView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)), this,SLOT( showDrink(int,QListViewItem*,const QPoint&,int))); layout->addMultiCellWidget( DrinkView, 1, 2, 0, 4 ); - if(QDir("db").exists()) { - dbFile.setName( "db/drinkdb.txt"); - } else - dbFile.setName( QPEApplication::qpeDir()+"etc/bartender/drinkdb.txt"); + if(QDir("db").exists()) + drinkDB.setFile("db/drinkdb.txt"); + else + drinkDB.setFile(QPEApplication::qpeDir()+"etc/bartender/drinkdb.txt"); + initDrinkDb(); + + DrinkView->setFocus(); } Bartender::~Bartender() { } /* this happens right before exit */ void Bartender::cleanUp() { - dbFile.close(); } void Bartender::initDrinkDb() { - - if(!dbFile.isOpen()) - if ( !dbFile.open( IO_ReadOnly)) { + if(drinkDB.read()) + fillList(); + else QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); - return; - } - fillList(); } void Bartender::fillList() { - dbFile.at(1); + QString lastName; + if( DrinkView->currentItem() != NULL ) + lastName = DrinkView->currentItem()->text(0); + else + lastName = ""; + DrinkView->clear(); int i=0; QListViewItem * item ; - QTextStream t( &dbFile); QString s; - while ( !t.eof()) { - s = t.readLine(); - if(s.find("#",0,TRUE) != -1) { -// odebug << s.right(s.length()-2) << oendl; - item= new QListViewItem( DrinkView, 0 ); - item->setText( 0, s.right(s.length()-2)); - i++; + + DrinkList::Iterator it = drinkDB.getBegin(); + while ( it != drinkDB.getEnd() ) { + item= new QListViewItem( DrinkView, 0 ); + item->setText( 0, (*it).getName()); + i++; + ++it; + } + + if( lastName != "" ) { + QListViewItemIterator it( DrinkView ); + for ( ; it.current(); ++it ) { + if ( it.current()->text(0) == lastName ) { + DrinkView->setCurrentItem(it.current()); + break; + } } } + else if( DrinkView->childCount() > 0) + DrinkView->setCurrentItem(DrinkView->firstChild()); + odebug << "there are currently " << i << " of drinks" << oendl; } void Bartender::fileNew() { New_Drink *newDrinks; - newDrinks = new New_Drink(this,"New Drink....", TRUE); + newDrinks = new New_Drink(this,"New Drink", TRUE); QString newName, newIng; QPEApplication::execDialog( newDrinks ); newName = newDrinks->LineEdit1->text(); newIng= newDrinks->MultiLineEdit1->text(); - if(dbFile.isOpen()) - dbFile.close(); - if ( !dbFile.open( IO_WriteOnly| IO_Append)) { - QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); - return; - } if(newDrinks ->result() == 1 ) { - QString newDrink="\n# "+newName+"\n"; - newDrink.append(newIng+"\n"); - odebug << "writing "+newDrink << oendl; - dbFile.writeBlock( newDrink.latin1(), newDrink.length()); - clearList(); - dbFile.close(); - - initDrinkDb(); + drinkDB.addDrink(newName, newIng); + if(!drinkDB.writeChanges()) { + QMessageBox::message( (tr("Note")), (tr("Failed to write to drink database!\n")) ); + } + fillList(); } delete newDrinks; } void Bartender::showDrink(int mouse, QListViewItem * item, const QPoint&, int) { switch (mouse) { case 1: // showDrink(item); break; case 2: showDrink(item); break; } } void Bartender::showDrink( QListViewItem *item) { if(item==NULL) return; - dbFile.at(0); Show_Drink *showDrinks; QString myDrink=item->text(0); showDrinks = new Show_Drink(this, myDrink, TRUE); - QTextStream t( &dbFile); - - QString s, s2; - while ( !t.eof()) { - s = t.readLine(); - if(s.find( myDrink, 0, TRUE) != -1) { - for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) { - s2 = t.readLine(); - if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) { -// odebug << s2 << oendl; - showDrinks->MultiLineEdit1->append(s2); - } - if( dbFile.atEnd() ) break; - } - } - } - QPEApplication::execDialog( showDrinks ); - if(showDrinks ->result() ==0) { - doEdit(); + DrinkList::Iterator it = drinkDB.findDrink(myDrink); + if(it != drinkDB.getEnd()) { + showDrinks->MultiLineEdit1->setText((*it).getIngredients()); + + connect(showDrinks->editDrinkButton, SIGNAL(clicked()), this, SLOT(doEdit())); + QPEApplication::execDialog( showDrinks ); } + delete showDrinks; } void Bartender::askSearch() { switch ( QMessageBox::warning(this,tr("Find"),tr("Search by drink name\n")+ - "\nor alcohol ?" - ,tr("Drink Name"),tr("Alcohol"),0,0,1) ) { + "\nor ingredient ?" + ,tr("Drink Name"),tr("Ingredient"),0,0,1) ) { case 0: doSearchByName(); break; case 1: - doSearchByDrink(); + doSearchByIngredient(); break; }; } /* search by name */ void Bartender::doSearchByName() { // if( DrinkView->currentItem() == NULL) return; QStringList searchList; QString searchForDrinkName; InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Find by Drink Name"),TRUE, 0); fileDlg->exec(); if( fileDlg->result() == 1 ) { searchForDrinkName = fileDlg->LineEdit1->text(); QListViewItemIterator it( DrinkView ); for ( ; it.current(); ++it ) { - if ( it.current()->text(0).find( searchForDrinkName, 0, TRUE) != -1 ) { + if ( it.current()->text(0).find( searchForDrinkName, 0, FALSE) != -1 ) { // odebug << it.current()->text(0) << oendl; searchList.append(it.current()->text(0)); } } if(searchList.count() >0) showSearchResult(searchList); else QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+searchForDrinkName); }//end Inputdialog delete fileDlg; } -void Bartender::doSearchByDrink() { +void Bartender::doSearchByIngredient() { // if( DrinkView->currentItem() == NULL) return; QStringList searchList; - QString searchForDrinkName, lastDrinkName, tempName; + QString searchForIngredient, lastDrinkName, lastDrinkIngredients; InputDialog *fileDlg; - fileDlg = new InputDialog(this,tr("Find by Alcohol"),TRUE, 0); + fileDlg = new InputDialog(this,tr("Find by Ingredient"),TRUE, 0); fileDlg->exec(); if( fileDlg->result() == 1 ) { - searchForDrinkName = fileDlg->LineEdit1->text(); - - dbFile.at(0); - QTextStream t( &dbFile); - - QString s, s2; - while ( !t.eof()) { - s = t.readLine(); - if(s.find("#",0,TRUE) != -1) { - lastDrinkName=s.right(s.length()-2); -// odebug << "last drink name "+lastDrinkName << oendl; - } - else if( s.find( searchForDrinkName ,0, FALSE) != -1 && lastDrinkName != tempName ) { -// odebug << "appending "+lastDrinkName << oendl; - searchList.append( lastDrinkName); - tempName=lastDrinkName; - } -// if( dbFile.atEnd() ) break; - - } //oef + searchForIngredient = fileDlg->LineEdit1->text(); + + DrinkList::Iterator it = drinkDB.getBegin(); + while ( it != drinkDB.getEnd() ) { + lastDrinkName = (*it).getName(); + lastDrinkIngredients = (*it).getIngredients(); + + if( lastDrinkIngredients.find( searchForIngredient ,0, FALSE) != -1 ) + searchList.append( lastDrinkName ); + + ++it; + } + if(searchList.count() >0) showSearchResult(searchList); else - QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+ searchForDrinkName); + QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+ searchForIngredient); } delete fileDlg; } void Bartender::showSearchResult(QStringList &searchList) { QString result; Search_Results *searchDlg; searchList.sort(); searchDlg = new Search_Results(this, "Search Results", TRUE); searchDlg->ListBox1->insertStringList( searchList,-1); QPEApplication::execDialog( searchDlg ); if( searchDlg->result() == 1 ) { result= searchDlg->ListBox1->currentText(); } QListViewItemIterator it2( DrinkView ); for ( ; it2.current(); ++it2 ) { if ( it2.current()->text(0)== result ) { // odebug << it2.current()->text(0) << oendl; showDrink(it2.current()); } } delete searchDlg; } void Bartender::doEdit() { - if(DrinkView->currentItem() == NULL) { - fileNew(); - } + if(DrinkView->currentItem() == NULL) { + fileNew(); + return; + } - QString myDrink; + QString myDrink; myDrink= DrinkView->currentItem()->text(0); - dbFile.at(0); - int foundAt=0; + New_Drink *newDrinks; - newDrinks = new New_Drink(this,"Edit Drink....", TRUE); + newDrinks = new New_Drink(this,"Edit Drink", TRUE); QString newName, newIng; QPEApplication::showDialog( newDrinks ); - QTextStream t( &dbFile); - - QString s, s2; - while ( !t.eof()) { - s = t.readLine(); - if(s.find( myDrink, 0, TRUE) != -1) { - foundAt = dbFile.at() - (s.length()+1); - for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) { - s2 = t.readLine(); - if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) { -// odebug << s2 << oendl; - newDrinks->MultiLineEdit1->append(s2); - newDrinks->LineEdit1->setText(myDrink); - } - if( dbFile.atEnd() ) break; - } - } - } - newDrinks->exec(); - newName = newDrinks->LineEdit1->text(); - newIng= newDrinks->MultiLineEdit1->text(); - if( newDrinks ->result() == 1 ) { - if(dbFile.isOpen()) - dbFile.close(); - if ( !dbFile.open( IO_ReadWrite )) { - QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); - return; + DrinkList::Iterator drinkItem = drinkDB.findDrink(myDrink); + if(drinkItem != drinkDB.getEnd()) { + newDrinks->LineEdit1->setText((*drinkItem).getName()); + newDrinks->MultiLineEdit1->setText((*drinkItem).getIngredients()); + + newDrinks->exec(); + newName = newDrinks->LineEdit1->text(); + newIng= newDrinks->MultiLineEdit1->text(); + + if( newDrinks ->result() == 1 ) { + (*drinkItem).setName(newName); + (*drinkItem).setIngredients(newIng); + if(!drinkDB.writeChanges()) { + QMessageBox::message( (tr("Note")), (tr("Failed to write to drink database!\n")) ); + } + fillList(); } - int fd = dbFile.handle(); - lseek( fd, foundAt, SEEK_SET); - -// dbFile.at( foundAt); -#warning FIXME problems with editing drinks db - ////////// FIXME write to user file - QString newDrink="# "+newName+"\n"; - newDrink.append(newIng+"\n"); - odebug << "writing "+newDrink << oendl; - dbFile.writeBlock( newDrink.latin1(), newDrink.length()); - clearList(); - - dbFile.flush(); - - initDrinkDb(); } + + delete newDrinks; } void Bartender::clearList() { DrinkView->clear(); } void Bartender::doBac() { BacDialog *bacDlg; bacDlg = new BacDialog(this,"BAC",TRUE); QPEApplication::execDialog( bacDlg ); delete bacDlg; } void Bartender::openCurrentDrink() { if(DrinkView->currentItem() == NULL) return; showDrink(DrinkView->currentItem()); } void Bartender::fileMenuActivated( int item) { odebug << "Item " << item << "" << oendl; switch(item) { case -3: // new -3 fileNew(); break; case -4:// open -4 openCurrentDrink(); break; case -5:// drink -5 doSearchByName(); break; case -6:// alcohol -6 - doSearchByDrink(); + doSearchByIngredient(); break; } } void Bartender::editMenuActivated(int item) { odebug << "Item " << item << "" << oendl; /* edit -8 */ switch(item) { case -8: doEdit() ; break; 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 @@ -1,65 +1,66 @@ /**************************************************************************** ** Created: Sat Jul 20 08:10:31 2002 ** by: L.J. Potter <ljp@llornkcor.com> ** copyright : (C) 2002 by ljp email : ljp@llornkcor.com * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #ifndef BARTENDER_H #define BARTENDER_H #include "newdrinks.h" +#include "drinkdata.h" #include <qvariant.h> #include <qwidget.h> #include <qmainwindow.h> #include <qfile.h> class QVBoxLayout; class QHBoxLayout; class QGridLayout; class QListView; class QListViewItem; class QToolBar; class Bartender : public QMainWindow { Q_OBJECT public: Bartender( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~Bartender(); static QString appName() { return QString::fromLatin1("bartender"); } QToolBar* ToolBar1; QListView* DrinkView; - QFile dbFile; + DrinkData drinkDB; public slots: void doEdit(); protected: protected slots: void fileMenuActivated(int); void editMenuActivated(int); void cleanUp(); void fileNew(); void showDrink( QListViewItem *); void showDrink(int, QListViewItem *, const QPoint&, int); void initDrinkDb(); void doSearchByName(); - void doSearchByDrink(); + void doSearchByIngredient(); void showSearchResult(QStringList &); void doBac(); void openCurrentDrink(); void askSearch(); private: void clearList(); void fillList(); }; #endif // BARTENDER_H 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 @@ -CONFIG = qt quick-app -HEADERS = bartender.h newdrinks.h showdrinks.h inputDialog.h searchresults.h bac.h -SOURCES = main.cpp bartender.cpp newdrinks.cpp showdrinks.cpp inputDialog.cpp searchresults.cpp bac.cpp +TEMPLATE = app +CONFIG = qt warn_on +HEADERS = bartender.h newdrinks.h showdrinks.h inputDialog.h searchresults.h bac.h drinkdata.h +SOURCES = main.cpp bartender.cpp newdrinks.cpp showdrinks.cpp inputDialog.cpp searchresults.cpp bac.cpp drinkdata.cpp INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include -LIBS += -lqpe -lopiecore2 +LIBS += -lqpe -lopiecore2 -lopieui2 +DESTDIR = $(OPIEDIR)/bin TARGET = bartender include( $(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 @@ +/**************************************************************************** +** Created: Sun Dec 26 22:00:00 2004 +** by: Paul Eggleton <bluelightning@bluelightning.org> +** copyright : (C) 2004 by Paul Eggleton + email : bluelightning@bluelightning.org + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +/* QT */ +#include <qfile.h> +#include <qtextstream.h> +#include <qvaluelist.h> + +/* STD */ +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> +#include <iostream> +#include <errno.h> + +#include "drinkdata.h" + +// ----- DrinkData ----- + +DrinkData::DrinkData() { +} + +void DrinkData::setFile(const QString &filename) { + this->filename = filename; +} + +bool DrinkData::read(void) { + QFile dbFile; + + dbFile.setName(filename); + if ( !dbFile.open( IO_ReadOnly)) { + return false; + } + + items.clear(); + + QTextStream t( &dbFile); + QString s, name = "", ingredients = ""; + + while ( !t.eof()) { + s = t.readLine(); + if(s.find( "#", 0, TRUE) != -1 || dbFile.atEnd()) { + if(name != "") + addDrink(name, ingredients); + // Start new entry + name = s.right(s.length()-2); + ingredients = ""; + } + else { + if(ingredients != "") + ingredients += '\n'; + ingredients += s; + } + } + + dbFile.close(); + + return true; +} + +void DrinkData::print(void) { + DrinkList::Iterator it = items.begin(); + while ( it != items.end() ) { + std::cout << (*it).getName() << '\n'; + ++it; + } +} + +void DrinkData::addDrink(const QString &name, const QString &ingredients) { + DrinkItem item(name, ingredients); + items.append(item); +} + +DrinkList::Iterator DrinkData::findDrink(const QString &name) { + DrinkList::Iterator it = items.begin(); + while ( it != items.end() ) { + if((*it).getName() == name) + return it; + ++it; + } + return items.end(); +} + +DrinkList::Iterator DrinkData::getBegin(void) { + return items.begin(); +} + +DrinkList::Iterator DrinkData::getEnd(void) { + return items.end(); +} + +bool DrinkData::writeChanges(void) { + QFile dbFile; + + dbFile.setName(filename); + if ( !dbFile.open( IO_WriteOnly | IO_Truncate )) { + return false; + } + + QTextStream t( &dbFile); + + DrinkList::Iterator it = items.begin(); + while ( it != items.end() ) { + t << "# " << (*it).getName() << '\n'; + t << (*it).getIngredients() << '\n'; + ++it; + } + + dbFile.close(); + + return true; +} + + +// ----- DrinkItem ----- + +DrinkItem::DrinkItem(void) { +} + +DrinkItem::DrinkItem(const QString &name, const QString &ingredients) { + this->name = name; + this->ingredients = ingredients; +} + +const QString &DrinkItem::getName(void) { + return name; +} + +const QString &DrinkItem::getIngredients(void) { + return ingredients; +} + +void DrinkItem::setName(const QString &name) { + this->name = name; +} + +void DrinkItem::setIngredients(const QString &ingredients) { + this->ingredients = ingredients; +} 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 @@ +/**************************************************************************** +** Created: Sun Dec 26 22:00:00 2004 +** by: Paul Eggleton <bluelightning@bluelightning.org> +** copyright : (C) 2004 by Paul Eggleton + email : bluelightning@bluelightning.org + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef DRINKDATA_H +#define DRINKDATA_H + +class DrinkItem; + +typedef QValueList<DrinkItem> DrinkList; + +class DrinkData { +private: + DrinkList items; + QString filename; +public: + DrinkData(void); + void setFile(const QString &filename); + bool writeChanges(void); + bool read(void); + void print(void); + void addDrink(const QString &name, const QString &ingredients); + DrinkList::Iterator getBegin(void); + DrinkList::Iterator getEnd(void); + DrinkList::Iterator findDrink(const QString &name); +}; + +class DrinkItem { +private: + QString name; + QString ingredients; +public: + DrinkItem(void); + DrinkItem(const QString &name, const QString &ingredients); + const QString &getName(void); + const QString &getIngredients(void); + void setName(const QString &name); + void setIngredients(const QString &ingredients); +}; + +#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 @@ -1,30 +1,30 @@ <!DOCTYPE UI><UI> <class>New_Drink</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>New_Drink</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>245</width> + <width>241</width> <height>320</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>New Drink</string> </property> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout5</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> @@ -73,33 +73,33 @@ <class>QLineEdit</class> <property stdset="1"> <name>name</name> <cstring>LineEdit1</cstring> </property> </widget> </hbox> </widget> <widget row="1" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel2</cstring> </property> <property stdset="1"> <name>text</name> - <string>Ingrediants</string> + <string>Ingredients</string> </property> </widget> <widget row="2" column="0" > <class>QMultiLineEdit</class> <property stdset="1"> <name>name</name> <cstring>MultiLineEdit1</cstring> </property> </widget> </grid> </widget> </widget> <customwidgets> <customwidget> <class>QWidget</class> <header location="global">qwidget.h</header> 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 @@ -33,28 +33,29 @@ New_Drink::New_Drink( QWidget* parent, const char* name, bool modal, WFlags fl // Layout4->setMargin( 4 ); TextLabel1 = new QLabel( this, "TextLabel1" ); TextLabel1->setText( tr( "Name" ) ); Layout5->addMultiCellWidget( TextLabel1, 0, 0, 0, 0); LineEdit1 = new QLineEdit( this, "LineEdit1" ); Layout5->addMultiCellWidget( LineEdit1, 0, 0, 1, 2); TextLabel2 = new QLabel( this, "TextLabel2" ); TextLabel2->setText( tr( "Ingredients" ) ); Layout5->addMultiCellWidget( TextLabel2, 1, 1, 0, 0); MultiLineEdit1 = new QMultiLineEdit( this, "MultiLineEdit1" ); + MultiLineEdit1->setWordWrap(QMultiLineEdit::WidgetWidth); Layout5->addMultiCellWidget( MultiLineEdit1, 2, 2, 0, 2); } /* * Destroys the object and frees any allocated resources */ New_Drink::~New_Drink() { // no need to delete child widgets, Qt does it all for us } 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 @@ -23,25 +23,26 @@ Show_Drink::Show_Drink( QWidget* parent, const char* name, bool modal, WFlags f setName( drinkName); drinkName = name; setCaption( drinkName ); Layout5 = new QGridLayout( this); Layout5->setSpacing( 6 ); Layout5->setMargin( 4 ); editDrinkButton = new QPushButton( tr("Edit"), this,"editBtn"); Layout5->addMultiCellWidget( editDrinkButton, 0, 0, 0, 0 ); connect(editDrinkButton, SIGNAL(clicked()), this, SLOT(slotEditDrink())); MultiLineEdit1 = new QMultiLineEdit( this, "MultiLineEdit1" ); MultiLineEdit1->setWordWrap(QMultiLineEdit::WidgetWidth); + MultiLineEdit1->setReadOnly(true); Layout5->addMultiCellWidget( MultiLineEdit1, 1, 3, 0, 3 ); } Show_Drink::~Show_Drink() { } void Show_Drink::slotEditDrink() { reject(); } 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 @@ -20,25 +20,25 @@ class QHBoxLayout; class QGridLayout; class QLabel; class QLineEdit; class QMultiLineEdit; class QString; class QPushButton; class Show_Drink : public QDialog { Q_OBJECT public: Show_Drink( QWidget* parent = 0, const char* name = 0, bool modal=TRUE, WFlags fl = 0 ); ~Show_Drink(); QMultiLineEdit* MultiLineEdit1; + QPushButton *editDrinkButton; public slots: void slotEditDrink(); protected: QGridLayout* Layout5; QString drinkName; - QPushButton *editDrinkButton; }; #endif // SHOW_DRINK_H |