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