summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-bartender/bartender.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-bartender/bartender.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-bartender/bartender.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/apps/opie-bartender/bartender.cpp b/noncore/apps/opie-bartender/bartender.cpp
index 59fc242..b4958b3 100644
--- a/noncore/apps/opie-bartender/bartender.cpp
+++ b/noncore/apps/opie-bartender/bartender.cpp
@@ -20,193 +20,193 @@
20#include <opie2/odebug.h> 20#include <opie2/odebug.h>
21#include <qpe/qpeapplication.h> 21#include <qpe/qpeapplication.h>
22#include <qpe/resource.h> 22#include <qpe/resource.h>
23using namespace Opie::Core; 23using namespace Opie::Core;
24 24
25/* QT */ 25/* QT */
26#include <qlineedit.h> 26#include <qlineedit.h>
27#include <qdir.h> 27#include <qdir.h>
28#include <qpushbutton.h> 28#include <qpushbutton.h>
29#include <qlistbox.h> 29#include <qlistbox.h>
30#include <qmultilineedit.h> 30#include <qmultilineedit.h>
31#include <qmessagebox.h> 31#include <qmessagebox.h>
32#include <qtextstream.h> 32#include <qtextstream.h>
33#include <qaction.h> 33#include <qaction.h>
34#include <qheader.h> 34#include <qheader.h>
35#include <qlistview.h> 35#include <qlistview.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qtoolbar.h> 37#include <qtoolbar.h>
38#include <qmenubar.h> 38#include <qmenubar.h>
39 39
40/* STD */ 40/* STD */
41#include <fcntl.h> 41#include <fcntl.h>
42#include <unistd.h> 42#include <unistd.h>
43#include <stdlib.h> 43#include <stdlib.h>
44#include <stdio.h> 44#include <stdio.h>
45#include <errno.h> 45#include <errno.h>
46 46
47Bartender::Bartender( QWidget* parent, const char* name, WFlags fl ) 47Bartender::Bartender( QWidget* parent, const char* name, WFlags fl )
48 : QMainWindow( parent, name, fl ) { 48 : QMainWindow( parent, name, fl ) {
49 if ( !name ) 49 if ( !name )
50 setName( "Bartender" ); 50 setName( "Bartender" );
51 QGridLayout *layout = new QGridLayout( this ); 51 QGridLayout *layout = new QGridLayout( this );
52 layout->setSpacing( 2); 52 layout->setSpacing( 2);
53 layout->setMargin( 2); 53 layout->setMargin( 2);
54 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); 54 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
55 55
56 setCaption( tr( "Bartender" ) ); 56 setCaption( tr( "Bartender" ) );
57 57
58 ToolBar1 = new QToolBar( this, "ToolBar1" ); 58 ToolBar1 = new QToolBar( this, "ToolBar1" );
59 ToolBar1->setFixedHeight(22); 59 ToolBar1->setFixedHeight(22);
60 layout->addMultiCellWidget( ToolBar1, 0, 0, 0, 4 ); 60 layout->addMultiCellWidget( ToolBar1, 0, 0, 0, 4 );
61 61
62 QMenuBar *menuBar = new QMenuBar( ToolBar1 ); 62 QMenuBar *menuBar = new QMenuBar( ToolBar1 );
63 QPopupMenu *fileMenu; 63 QPopupMenu *fileMenu;
64 fileMenu = new QPopupMenu( this); 64 fileMenu = new QPopupMenu( this);
65 menuBar->insertItem( tr("File"), fileMenu ); 65 menuBar->insertItem( tr("File"), fileMenu );
66 66
67 fileMenu->insertItem(tr("New Drink")); 67 fileMenu->insertItem(tr("New Drink"));
68 fileMenu->insertItem(tr("Open Drink")); 68 fileMenu->insertItem(tr("Open Drink"));
69 fileMenu->insertItem(tr("Find by Drink Name")); 69 fileMenu->insertItem(tr("Find by Drink Name"));
70 fileMenu->insertItem(tr("Find by Alcohol")); 70 fileMenu->insertItem(tr("Find by Alcohol"));
71 71
72 QPopupMenu *editMenu; 72 QPopupMenu *editMenu;
73 editMenu = new QPopupMenu( this); 73 editMenu = new QPopupMenu( this);
74 menuBar->insertItem( tr("Edit"), editMenu ); 74 menuBar->insertItem( tr("Edit"), editMenu );
75 editMenu->insertItem(tr("edit")); 75 editMenu->insertItem(tr("edit"));
76 76
77 connect( fileMenu, SIGNAL( activated(int) ), this, SLOT( fileMenuActivated(int) )); 77 connect( fileMenu, SIGNAL( activated(int) ), this, SLOT( fileMenuActivated(int) ));
78 connect( editMenu, SIGNAL( activated(int) ), this, SLOT( editMenuActivated(int) )); 78 connect( editMenu, SIGNAL( activated(int) ), this, SLOT( editMenuActivated(int) ));
79 79
80 80
81 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), "New", 0, this, 0 ); 81 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), "New", 0, this, 0 );
82 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 82 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
83 a->addTo( ToolBar1 ); 83 a->addTo( ToolBar1 );
84 84
85 a = new QAction( tr( "Open" ), Resource::loadPixmap( "bartender/bartender_sm" ), "open", 0, this, 0 ); 85 a = new QAction( tr( "Open" ), Resource::loadPixmap( "bartender/bartender_sm" ), "open", 0, this, 0 );
86 connect( a, SIGNAL( activated() ), this, SLOT( openCurrentDrink() ) ); 86 connect( a, SIGNAL( activated() ), this, SLOT( openCurrentDrink() ) );
87 a->addTo( ToolBar1 ); 87 a->addTo( ToolBar1 );
88 88
89 a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), "Find", 0, this, 0 ); 89 a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), "Find", 0, this, 0 );
90 connect( a, SIGNAL( activated() ), this, SLOT( askSearch() ) ); 90 connect( a, SIGNAL( activated() ), this, SLOT( askSearch() ) );
91 a->addTo( ToolBar1 ); 91 a->addTo( ToolBar1 );
92 92
93 a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ),"Edit", 0, this, 0 ); 93 a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ),"Edit", 0, this, 0 );
94 connect( a, SIGNAL( activated() ), this, SLOT( doEdit() ) ); 94 connect( a, SIGNAL( activated() ), this, SLOT( doEdit() ) );
95 a->addTo( ToolBar1 ); 95 a->addTo( ToolBar1 );
96 96
97 QPushButton *t; 97 QPushButton *t;
98 t= new QPushButton( "BAC", ToolBar1, "bacButtin"); 98 t= new QPushButton( "BAC", ToolBar1, "bacButtin");
99 connect( t, SIGNAL( clicked() ), this, SLOT( doBac() ) ); 99 connect( t, SIGNAL( clicked() ), this, SLOT( doBac() ) );
100 100
101 DrinkView = new QListView( this, "DrinkView" ); 101 DrinkView = new QListView( this, "DrinkView" );
102 DrinkView->addColumn( tr( "Name of Drink" ) ); 102 DrinkView->addColumn( tr( "Name of Drink" ) );
103// DrinkView->setRootIsDecorated( TRUE ); 103// DrinkView->setRootIsDecorated( TRUE );
104 DrinkView->header()->hide(); 104 DrinkView->header()->hide();
105 105
106 QPEApplication::setStylusOperation( DrinkView->viewport(),QPEApplication::RightOnHold); 106 QPEApplication::setStylusOperation( DrinkView->viewport(),QPEApplication::RightOnHold);
107 107
108 connect(DrinkView, SIGNAL( doubleClicked(QListViewItem*)),this,SLOT(showDrink(QListViewItem*))); 108 connect(DrinkView, SIGNAL( doubleClicked(QListViewItem*)),this,SLOT(showDrink(QListViewItem*)));
109 connect(DrinkView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)), 109 connect(DrinkView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)),
110 this,SLOT( showDrink(int,QListViewItem*,const QPoint&,int))); 110 this,SLOT( showDrink(int,QListViewItem*,const QPoint&,int)));
111 111
112 layout->addMultiCellWidget( DrinkView, 1, 2, 0, 4 ); 112 layout->addMultiCellWidget( DrinkView, 1, 2, 0, 4 );
113 if(QDir("db").exists()) { 113 if(QDir("db").exists()) {
114 dbFile.setName( "db/drinkdb.txt"); 114 dbFile.setName( "db/drinkdb.txt");
115 } else 115 } else
116 dbFile.setName( QPEApplication::qpeDir()+"/etc/bartender/drinkdb.txt"); 116 dbFile.setName( QPEApplication::qpeDir()+"etc/bartender/drinkdb.txt");
117 initDrinkDb(); 117 initDrinkDb();
118} 118}
119 119
120Bartender::~Bartender() { 120Bartender::~Bartender() {
121} 121}
122 122
123/* 123/*
124this happens right before exit */ 124this happens right before exit */
125void Bartender::cleanUp() { 125void Bartender::cleanUp() {
126 dbFile.close(); 126 dbFile.close();
127 127
128} 128}
129 129
130void Bartender::initDrinkDb() { 130void Bartender::initDrinkDb() {
131 131
132 if(!dbFile.isOpen()) 132 if(!dbFile.isOpen())
133 if ( !dbFile.open( IO_ReadOnly)) { 133 if ( !dbFile.open( IO_ReadOnly)) {
134 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); 134 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) );
135 return; 135 return;
136 } 136 }
137 fillList(); 137 fillList();
138} 138}
139 139
140void Bartender::fillList() { 140void Bartender::fillList() {
141 dbFile.at(1); 141 dbFile.at(1);
142 DrinkView->clear(); 142 DrinkView->clear();
143 int i=0; 143 int i=0;
144 QListViewItem * item ; 144 QListViewItem * item ;
145 QTextStream t( &dbFile); 145 QTextStream t( &dbFile);
146 QString s; 146 QString s;
147 while ( !t.eof()) { 147 while ( !t.eof()) {
148 s = t.readLine(); 148 s = t.readLine();
149 if(s.find("#",0,TRUE) != -1) { 149 if(s.find("#",0,TRUE) != -1) {
150// odebug << s.right(s.length()-2) << oendl; 150// odebug << s.right(s.length()-2) << oendl;
151 item= new QListViewItem( DrinkView, 0 ); 151 item= new QListViewItem( DrinkView, 0 );
152 item->setText( 0, s.right(s.length()-2)); 152 item->setText( 0, s.right(s.length()-2));
153 i++; 153 i++;
154 } 154 }
155 } 155 }
156 odebug << "there are currently " << i << " of drinks" << oendl; 156 odebug << "there are currently " << i << " of drinks" << oendl;
157} 157}
158 158
159void Bartender::fileNew() { 159void Bartender::fileNew() {
160 160
161 New_Drink *newDrinks; 161 New_Drink *newDrinks;
162 newDrinks = new New_Drink(this,"New Drink....", TRUE); 162 newDrinks = new New_Drink(this,"New Drink....", TRUE);
163 QString newName, newIng; 163 QString newName, newIng;
164 QPEApplication::execDialog( newDrinks ); 164 QPEApplication::execDialog( newDrinks );
165 newName = newDrinks->LineEdit1->text(); 165 newName = newDrinks->LineEdit1->text();
166 newIng= newDrinks->MultiLineEdit1->text(); 166 newIng= newDrinks->MultiLineEdit1->text();
167 167
168 if(dbFile.isOpen()) 168 if(dbFile.isOpen())
169 dbFile.close(); 169 dbFile.close();
170 if ( !dbFile.open( IO_WriteOnly| IO_Append)) { 170 if ( !dbFile.open( IO_WriteOnly| IO_Append)) {
171 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); 171 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) );
172 return; 172 return;
173 } 173 }
174 if(newDrinks ->result() == 1 ) { 174 if(newDrinks ->result() == 1 ) {
175 QString newDrink="\n# "+newName+"\n"; 175 QString newDrink="\n# "+newName+"\n";
176 newDrink.append(newIng+"\n"); 176 newDrink.append(newIng+"\n");
177 odebug << "writing "+newDrink << oendl; 177 odebug << "writing "+newDrink << oendl;
178 dbFile.writeBlock( newDrink.latin1(), newDrink.length()); 178 dbFile.writeBlock( newDrink.latin1(), newDrink.length());
179 clearList(); 179 clearList();
180 dbFile.close(); 180 dbFile.close();
181 181
182 initDrinkDb(); 182 initDrinkDb();
183 } 183 }
184 delete newDrinks; 184 delete newDrinks;
185} 185}
186 186
187void Bartender::showDrink(int mouse, QListViewItem * item, const QPoint&, int) { 187void Bartender::showDrink(int mouse, QListViewItem * item, const QPoint&, int) {
188 switch (mouse) { 188 switch (mouse) {
189 case 1: 189 case 1:
190// showDrink(item); 190// showDrink(item);
191 break; 191 break;
192 case 2: 192 case 2:
193 showDrink(item); 193 showDrink(item);
194 break; 194 break;
195 } 195 }
196} 196}
197 197
198void Bartender::showDrink( QListViewItem *item) { 198void Bartender::showDrink( QListViewItem *item) {
199 if(item==NULL) return; 199 if(item==NULL) return;
200 dbFile.at(0); 200 dbFile.at(0);
201 Show_Drink *showDrinks; 201 Show_Drink *showDrinks;
202 QString myDrink=item->text(0); 202 QString myDrink=item->text(0);
203 showDrinks = new Show_Drink(this, myDrink, TRUE); 203 showDrinks = new Show_Drink(this, myDrink, TRUE);
204 QTextStream t( &dbFile); 204 QTextStream t( &dbFile);
205 205
206 QString s, s2; 206 QString s, s2;
207 while ( !t.eof()) { 207 while ( !t.eof()) {
208 s = t.readLine(); 208 s = t.readLine();
209 if(s.find( myDrink, 0, TRUE) != -1) { 209 if(s.find( myDrink, 0, TRUE) != -1) {
210 for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) { 210 for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) {
211 s2 = t.readLine(); 211 s2 = t.readLine();
212 if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) { 212 if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) {