Initial Commit
[HECS.git] / Sedbuk.cpp
blob8925a37b1525974a19562fd0de7c7b04a2cc3e98
1 /***************************************************************************
2 * *
3 * Sedbuk.h Copyright (C) 2008 by Jon Rumble *
4 * j.w.rumble@reading.ac.uk *
5 * *
6 * This file is part of HECS, *
7 * *
8 * HECS is free software: you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation, either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * HECS is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * You should have received a copy of the GNU General Public License *
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
21 ***************************************************************************/
24 #include "Sedbuk.h"
26 SedbukList::SedbukList(const QString fileNameIn) {
27 fileName = fileNameIn;
28 initVars();
29 openFile(fileName);
32 SedbukList::~SedbukList() {
35 void SedbukList::openFile(QString fileName)
37 QFile file(fileName);
39 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
40 std::cerr << "Cannot open file for reading: "
41 << qPrintable(file.errorString())
42 << std::endl;
43 m_sedbukAvail = 0;
44 return;
47 QTextStream in (&file);
48 while (!in.atEnd()) {
49 QString out = in.readLine();
50 if (out.startsWith("$001"))
51 parseVersion(out);
52 //Process Table 103
53 else if (out.startsWith("$103"))
55 do{
56 out = in.readLine();
58 if (out.startsWith("#"))
59 continue;
60 if (out.startsWith("$"))
61 continue;
62 else
63 parseBoilerTable(out);
65 }while (!out.startsWith("$121"));
67 //Skip Comment Line
68 else if (out.startsWith("#"))
69 continue;
70 //End Of File
71 else if (out.startsWith("$999"))
72 break;
74 else
75 continue;
79 m_sedbukAvail = 1;
80 file.close();
81 return;
85 bool SedbukList::get_sedbukAvail ()
87 return m_sedbukAvail;
90 Boiler SedbukList::findBoiler (const QString& modelStr)
92 QString Junk = modelStr;
93 Boiler currBoiler;
94 if (!boilerHash.contains(modelStr))
95 return currBoiler;
97 currBoiler = boilerHash[modelStr];
98 return currBoiler;
104 QStringList SedbukList::getBrandList(int fuel_type)
107 QStringList entries;
110 switch (fuel_type){
111 case 1:
112 //entries = buildBoilerList(gasBoilers);
113 break;
114 case 2:
115 //entries = buildBoilerList(lpgBoilers);
116 break;
117 case 4:
118 //entries = buildBoilerList(oilBoilers);
119 break;
122 return entries;
127 QStringList SedbukList::getModelList(QString brandNameIn)
129 QStringList listIn;
130 QHashIterator <QString, Boiler> i (boilerHash);
132 Boiler entry;
133 while (i.hasNext())
135 i.next();
136 entry = i.value();
137 if ((entry.get_brandName() == brandNameIn) && (entry.get_fuelType() == m_fuelType))
138 listIn << entry.get_modelName() + entry.get_modelQualifier();
139 else
140 continue;
143 listIn.sort();
144 return listIn;
147 QString SedbukList::get_revisionDate()
149 return m_revisionDate;
152 QStringList SedbukList::getBoilerBrands (int fuel_type)
155 m_fuelType = fuel_type;
156 QStringList listIn;
157 QHashIterator <QString, Boiler> i (boilerHash);
159 Boiler entry;
160 while (i.hasNext())
162 i.next();
163 entry = i.value();
164 if (entry.get_fuelType() == m_fuelType)
165 listIn << entry.get_brandName();
166 else
167 continue;
170 listIn.sort();
171 return pruneDuplicates(listIn);
175 void SedbukList::initVars()
177 m_revisionNum = 0;
178 m_day = 0;
179 m_month = 0;
180 m_year = 0;
183 void SedbukList::parseVersion(QString versionString) {
184 QStringList versionInfo;
186 m_revisionNum = versionString.section(",",1,1).toInt();
187 m_day = versionString.section(",",4,4).toInt();
188 m_month = versionString.section(",",3,3).toInt();
189 m_year = versionString.section(",",2,2).toInt();
190 m_revisionDate = versionString.section(",",4,4) + "/" +
191 versionString.section(",",3,3)+ "/" +
192 versionString.section(",",2,2);
196 void SedbukList::parseBoilerTable(QString parseStr)
198 int str = 0, f5 =0, f4 =0;
199 QString f1, f2, f3, id;
201 QStringList record = parseStr.split(",");
202 QVector<QString> line = record.toVector();
204 str = line[0].toInt();
205 f1 = line[3];
206 f2 = line[4];
207 f3 = line[5];
208 f4 = line[20].toDouble();
209 f5 = line[9].toInt();
210 Boiler tmp(str,f1,f2,f3,f4,f5);
211 id = tmp.get_modelName() + tmp.get_modelQualifier();
212 boilerHash.insert(id,tmp);
215 //qDebug("" + id.toLatin1());
218 void SedbukList::updateSedbukDatabase()
220 if (m_updateFlag)
222 //TODO`