summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-12-29 18:27:00 (UTC)
committer llornkcor <llornkcor>2004-12-29 18:27:00 (UTC)
commite3fa443e845e76707171c6fae79125892a369b75 (patch) (unidiff)
treef2214ae1c6e1297109b4dcef4759b2c0aca27595
parente2d6f156eacc312f270a1b5c3830e58be8941460 (diff)
downloadopie-e3fa443e845e76707171c6fae79125892a369b75.zip
opie-e3fa443e845e76707171c6fae79125892a369b75.tar.gz
opie-e3fa443e845e76707171c6fae79125892a369b75.tar.bz2
patch to remove stl, from hrw
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-bartender/drinkdata.cpp9
-rw-r--r--noncore/apps/opie-bartender/drinkdata.h1
2 files changed, 0 insertions, 10 deletions
diff --git a/noncore/apps/opie-bartender/drinkdata.cpp b/noncore/apps/opie-bartender/drinkdata.cpp
index 8856e46..53e7b8d 100644
--- a/noncore/apps/opie-bartender/drinkdata.cpp
+++ b/noncore/apps/opie-bartender/drinkdata.cpp
@@ -1,124 +1,115 @@
1/**************************************************************************** 1/****************************************************************************
2** Created: Sun Dec 26 22:00:00 2004 2** Created: Sun Dec 26 22:00:00 2004
3** by: Paul Eggleton <bluelightning@bluelightning.org> 3** by: Paul Eggleton <bluelightning@bluelightning.org>
4** copyright : (C) 2004 by Paul Eggleton 4** copyright : (C) 2004 by Paul Eggleton
5 email : bluelightning@bluelightning.org 5 email : bluelightning@bluelightning.org
6 * This program is free software; you can redistribute it and/or modify * 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 * 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 * 8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. * 9 * (at your option) any later version. *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/* QT */ 12/* QT */
13#include <qfile.h> 13#include <qfile.h>
14#include <qtextstream.h> 14#include <qtextstream.h>
15#include <qvaluelist.h> 15#include <qvaluelist.h>
16 16
17/* STD */ 17/* STD */
18#include <fcntl.h> 18#include <fcntl.h>
19#include <unistd.h> 19#include <unistd.h>
20#include <stdlib.h> 20#include <stdlib.h>
21#include <iostream>
22#include <errno.h> 21#include <errno.h>
23 22
24#include "drinkdata.h" 23#include "drinkdata.h"
25 24
26// ----- DrinkData ----- 25// ----- DrinkData -----
27 26
28DrinkData::DrinkData() { 27DrinkData::DrinkData() {
29} 28}
30 29
31void DrinkData::setFile(const QString &filename) { 30void DrinkData::setFile(const QString &filename) {
32 this->filename = filename; 31 this->filename = filename;
33} 32}
34 33
35bool DrinkData::read(void) { 34bool DrinkData::read(void) {
36 QFile dbFile; 35 QFile dbFile;
37 36
38 dbFile.setName(filename); 37 dbFile.setName(filename);
39 if ( !dbFile.open( IO_ReadOnly)) { 38 if ( !dbFile.open( IO_ReadOnly)) {
40 return false; 39 return false;
41 } 40 }
42 41
43 items.clear(); 42 items.clear();
44 43
45 QTextStream t( &dbFile); 44 QTextStream t( &dbFile);
46 QString s, name = "", ingredients = ""; 45 QString s, name = "", ingredients = "";
47 46
48 while ( !t.eof()) { 47 while ( !t.eof()) {
49 s = t.readLine(); 48 s = t.readLine();
50 if(s.find( "#", 0, TRUE) != -1 || dbFile.atEnd()) { 49 if(s.find( "#", 0, TRUE) != -1 || dbFile.atEnd()) {
51 if(name != "") 50 if(name != "")
52 addDrink(name, ingredients); 51 addDrink(name, ingredients);
53 // Start new entry 52 // Start new entry
54 name = s.right(s.length()-2); 53 name = s.right(s.length()-2);
55 ingredients = ""; 54 ingredients = "";
56 } 55 }
57 else { 56 else {
58 if(ingredients != "") 57 if(ingredients != "")
59 ingredients += '\n'; 58 ingredients += '\n';
60 ingredients += s; 59 ingredients += s;
61 } 60 }
62 } 61 }
63 62
64 dbFile.close(); 63 dbFile.close();
65 64
66 return true; 65 return true;
67} 66}
68 67
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) { 68void DrinkData::addDrink(const QString &name, const QString &ingredients) {
78 DrinkItem item(name, ingredients); 69 DrinkItem item(name, ingredients);
79 items.append(item); 70 items.append(item);
80} 71}
81 72
82DrinkList::Iterator DrinkData::findDrink(const QString &name) { 73DrinkList::Iterator DrinkData::findDrink(const QString &name) {
83 DrinkList::Iterator it = items.begin(); 74 DrinkList::Iterator it = items.begin();
84 while ( it != items.end() ) { 75 while ( it != items.end() ) {
85 if((*it).getName() == name) 76 if((*it).getName() == name)
86 return it; 77 return it;
87 ++it; 78 ++it;
88 } 79 }
89 return items.end(); 80 return items.end();
90} 81}
91 82
92DrinkList::Iterator DrinkData::getBegin(void) { 83DrinkList::Iterator DrinkData::getBegin(void) {
93 return items.begin(); 84 return items.begin();
94} 85}
95 86
96DrinkList::Iterator DrinkData::getEnd(void) { 87DrinkList::Iterator DrinkData::getEnd(void) {
97 return items.end(); 88 return items.end();
98} 89}
99 90
100bool DrinkData::writeChanges(void) { 91bool DrinkData::writeChanges(void) {
101 QFile dbFile; 92 QFile dbFile;
102 93
103 dbFile.setName(filename); 94 dbFile.setName(filename);
104 if ( !dbFile.open( IO_WriteOnly | IO_Truncate )) { 95 if ( !dbFile.open( IO_WriteOnly | IO_Truncate )) {
105 return false; 96 return false;
106 } 97 }
107 98
108 QTextStream t( &dbFile); 99 QTextStream t( &dbFile);
109 100
110 DrinkList::Iterator it = items.begin(); 101 DrinkList::Iterator it = items.begin();
111 while ( it != items.end() ) { 102 while ( it != items.end() ) {
112 t << "# " << (*it).getName() << '\n'; 103 t << "# " << (*it).getName() << '\n';
113 t << (*it).getIngredients() << '\n'; 104 t << (*it).getIngredients() << '\n';
114 ++it; 105 ++it;
115 } 106 }
116 107
117 dbFile.close(); 108 dbFile.close();
118 109
119 return true; 110 return true;
120} 111}
121 112
122 113
123// ----- DrinkItem ----- 114// ----- DrinkItem -----
124 115
diff --git a/noncore/apps/opie-bartender/drinkdata.h b/noncore/apps/opie-bartender/drinkdata.h
index bcc3022..2b96d1d 100644
--- a/noncore/apps/opie-bartender/drinkdata.h
+++ b/noncore/apps/opie-bartender/drinkdata.h
@@ -1,48 +1,47 @@
1/**************************************************************************** 1/****************************************************************************
2** Created: Sun Dec 26 22:00:00 2004 2** Created: Sun Dec 26 22:00:00 2004
3** by: Paul Eggleton <bluelightning@bluelightning.org> 3** by: Paul Eggleton <bluelightning@bluelightning.org>
4** copyright : (C) 2004 by Paul Eggleton 4** copyright : (C) 2004 by Paul Eggleton
5 email : bluelightning@bluelightning.org 5 email : bluelightning@bluelightning.org
6 * This program is free software; you can redistribute it and/or modify * 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 * 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 * 8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. * 9 * (at your option) any later version. *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12#ifndef DRINKDATA_H 12#ifndef DRINKDATA_H
13#define DRINKDATA_H 13#define DRINKDATA_H
14 14
15class DrinkItem; 15class DrinkItem;
16 16
17typedef QValueList<DrinkItem> DrinkList; 17typedef QValueList<DrinkItem> DrinkList;
18 18
19class DrinkData { 19class DrinkData {
20private: 20private:
21 DrinkList items; 21 DrinkList items;
22 QString filename; 22 QString filename;
23public: 23public:
24 DrinkData(void); 24 DrinkData(void);
25 void setFile(const QString &filename); 25 void setFile(const QString &filename);
26 bool writeChanges(void); 26 bool writeChanges(void);
27 bool read(void); 27 bool read(void);
28 void print(void);
29 void addDrink(const QString &name, const QString &ingredients); 28 void addDrink(const QString &name, const QString &ingredients);
30 DrinkList::Iterator getBegin(void); 29 DrinkList::Iterator getBegin(void);
31 DrinkList::Iterator getEnd(void); 30 DrinkList::Iterator getEnd(void);
32 DrinkList::Iterator findDrink(const QString &name); 31 DrinkList::Iterator findDrink(const QString &name);
33}; 32};
34 33
35class DrinkItem { 34class DrinkItem {
36private: 35private:
37 QString name; 36 QString name;
38 QString ingredients; 37 QString ingredients;
39public: 38public:
40 DrinkItem(void); 39 DrinkItem(void);
41 DrinkItem(const QString &name, const QString &ingredients); 40 DrinkItem(const QString &name, const QString &ingredients);
42 const QString &getName(void); 41 const QString &getName(void);
43 const QString &getIngredients(void); 42 const QString &getIngredients(void);
44 void setName(const QString &name); 43 void setName(const QString &name);
45 void setIngredients(const QString &ingredients); 44 void setIngredients(const QString &ingredients);
46}; 45};
47 46
48#endif // DRINKDATA_H 47#endif // DRINKDATA_H