Debian Codegraph @

HercConfiguration/CardReaderProperties.cpp

raw symbols SCIP
1 /*
2 * File: CardReaderProperties.cpp
3 *
4 * Author: Jacob Dekel
5 * Created on: Aug 7, 2009
6 *
7 * Copyright (c) 2009-2013 Jacob Dekel
8 * $Id$
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25 #include "HerculesStudio.h"
26 #include "CardReaderProperties.h"
27 #include "NewReaderFile.h"
28
29 #include <sstream>
30
31 CardReaderProperties::CardReaderProperties(ConfigLine& line, QWidget *parent)
32 : GenericDeviceProperties(line, parent), mNewReaderFile(NULL)
33 {
34 ui.setupUi(this);
35 ReaderFileListView * listView = static_cast<ReaderFileListView *>(ui.fileNamesListView);
36 listView->setReaderParent(this);
37
38 initialize(line);
39 connect(ui.fileNamesListView, SIGNAL(pressed (const QModelIndex &)), this, SLOT(itemPressed( const QModelIndex &)));
40 connect(ui.sockdev, SIGNAL(textChanged(const QString &)), this, SLOT(sockdevChanged()));
41 connect(ui.addButton, SIGNAL(pressed()), this, SLOT(addPressed()));
42 connect(ui.deleteButton, SIGNAL(pressed()), this, SLOT(deletePressed()));
43 connect(ui.OKButton, SIGNAL(pressed()), this, SLOT(ok()));
44 connect(ui.cancelButton, SIGNAL(pressed()), this, SLOT(cancel()));
45 connect(ui.sockdevCheckBox, SIGNAL(stateChanged(int)), this, SLOT(sockdevChanged()));
46 }
47
48 CardReaderProperties::~CardReaderProperties()
49 {
50
51 }
52
53 void CardReaderProperties::ok()
54 {
55 if (!deviceNumberValidator(ui.deviceNumber))
56 return;
57 std::stringstream newLineBuff;
58
59 newLineBuff << ui.deviceNumber->text().toStdString()
60 << " " << ui.deviceCombo->currentText().toStdString();
61 if (ui.sockdevCheckBox->isChecked())
62 {
63 newLineBuff << " " << ui.sockdev->text().toStdString();
64 }
65 else
66 {
67 if (mModel!=NULL)
68 {
69 for (int i=0; i<mModel->rowCount(); i++)
70 {
71 newLineBuff << " " << mModel->item(i)->text().toStdString();
72 }
73 }
74 }
75 if (ui.sockdevCheckBox->isChecked())
76 {
77 newLineBuff << " sockdev" ;
78 }
79 else
80 {
81 if (ui.eofRadioButton->isChecked())
82 {
83 newLineBuff << " eof";
84 }
85 if (ui.intrqRadioButton->isChecked())
86 {
87 newLineBuff << " intrq";
88 }
89 if (ui.multifileCheckBox->isChecked())
90 {
91 newLineBuff << " multifile";
92 }
93 }
94
95 if (ui.truncCheckBox->isChecked())
96 {
97 newLineBuff << " trunc";
98 }
99 if (ui.autopadCheckBox->isChecked())
100 {
101 newLineBuff << " autopad";
102 }
103 if (ui.ebcdicRadioButton->isChecked())
104 {
105 newLineBuff << " ebcdic";
106 }
107 if (ui.asciiRadioButton->isChecked())
108 {
109 newLineBuff << " ascii";
110 }
111
112 newLineBuff << "\n";
113 mLine.replaceLine(newLineBuff.str());
114 emit updateLine(true);
115 this->deleteLater();
116 }
117
118 void CardReaderProperties::cancel()
119 {
120 emit updateLine(false);
121 this->deleteLater();
122 }
123
124 void CardReaderProperties::itemPressed(const QModelIndex & index)
125 {
126 mDragCandidate = index.row();
127 mDragCount = mModel->rowCount();
128 hOutDebug(5, "index pressed:" << mDragCandidate << std::endl);
129 }
130 void CardReaderProperties::shouldBeDeleted()
131 {
132 hOutDebug(5, "should be deleted:" << mDragCandidate << std::endl);
133 if (mModel->rowCount() > mDragCount)
134 mModel->removeRow(mDragCandidate);
135 mDragCandidate=-1;
136 }
137
138 void CardReaderProperties::addPressed()
139 {
140 if (mNewReaderFile != NULL)
141 mNewReaderFile->close();
142 mNewReaderFile = new NewReaderFile(this);
143 mNewReaderFile->move(this->geometry().x(),this->geometry().y());
144 connect(mNewReaderFile, SIGNAL(okPressed(QString &)), this, SLOT(addFile(QString&)));
145 connect(mNewReaderFile, SIGNAL(destroyed(QObject *)), this, SLOT(newFileFinished(QObject *)));
146 hOutDebug(5, "add pressed:" << mDragCandidate << std::endl);
147 }
148
149 void CardReaderProperties::deletePressed()
150 {
151 hOutDebug(5, "delete pressed:" << std::endl);
152 if (ui.fileNamesListView->currentIndex().row() >= 0)
153 {
154 mModel->removeRow(ui.fileNamesListView->currentIndex().row());
155 }
156 ui.sockdevCheckBox->setEnabled (mModel->rowCount() == 0);
157 }
158
159 void CardReaderProperties::addFile(QString & file)
160 {
161 hOutDebug(5,"pickupFile:" << file.toStdString() << std::endl);
162 QStandardItem *parentItem = mModel->invisibleRootItem();
163 parentItem->appendRow(new QStandardItem(file));
164 ui.sockdevCheckBox->setEnabled (mModel->rowCount() == 0);
165 }
166
167 void CardReaderProperties::newFileFinished(QObject *)
168 {
169 mNewReaderFile = NULL;
170 }
171
172 void CardReaderProperties::sockdevChanged()
173 {
174 setSockdev(ui.sockdevCheckBox->isChecked());
175 ui.sockdevCheckBox->setEnabled (ui.sockdev->text().isEmpty());
176 }
177
178 void CardReaderProperties::setSockdev(bool enabled)
179 {
180 ui.addButton->setVisible(!enabled);
181 ui.deleteButton->setVisible(!enabled);
182 ui.fileNamesListView->setVisible(!enabled);
183 ui.label->setVisible(!enabled);
184 ui.multifileCheckBox->setVisible(!enabled);
185 ui.eofGroupBox->setVisible(!enabled);
186
187 ui.sockdev->setVisible(enabled);
188 ui.sockspecLabel->setVisible(enabled);
189
190 }
191
192 void CardReaderProperties::initialize(const ConfigLine & line)
193 {
194 if (line.size() > 0)
195 ui.deviceNumber->setText(line.getToken(0).c_str());
196 std::string dev = line.getToken(1);
197 if (dev == "2501")
198 ui.deviceCombo->setCurrentIndex(1);
199 else if (dev == "3505")
200 ui.deviceCombo->setCurrentIndex(2);
201 else ui.deviceCombo->setCurrentIndex(0);
202
203 mModel = new QStandardItemModel(0,3);
204 mModel->clear();
205 QStandardItem *parentItem = mModel->invisibleRootItem();
206 ui.autoDetectRadioButton->setChecked(true); // default
207 ui.eofNoneRadioButton->setChecked(true); // default
208
209 int index = line.size()-1;
210 if (index >= 2)
211 {
212 std::string keywords = "sockdev eof intrq multifile ebcdic ascii trunc autopad";
213 ui.sockdevCheckBox->setChecked(false);
214 while (keywords.find(line.getToken(index)) != std::string::npos)
215 {
216 if (line.getToken(index) == "sockdev")
217 {
218 ui.sockdevCheckBox->setChecked(true);
219 }
220 else if (line.getToken(index) == "eof")
221 {
222 ui.eofRadioButton->setChecked(true);
223 }
224 else if (line.getToken(index) == "intrq")
225 {
226 ui.intrqRadioButton->setChecked(true);
227 }
228 else if (line.getToken(index) == "multifile")
229 {
230 ui.multifileCheckBox->setChecked(true);
231 }
232 else if (line.getToken(index) == "ebcdic")
233 {
234 ui.ebcdicRadioButton->setChecked(true);
235 }
236 else if (line.getToken(index) == "ascii")
237 {
238 ui.asciiRadioButton->setChecked(true);
239 }
240 else if (line.getToken(index) == "trunc")
241 {
242 ui.truncCheckBox->setChecked(true);
243 }
244 else if (line.getToken(index) == "autopad")
245 {
246 ui.autopadCheckBox->setChecked(true);
247 }
248 index--;
249 }
250 if (!ui.sockdevCheckBox->isChecked())
251 {
252 for (int i=0; i<=index-2; i++)
253 {
254 parentItem->appendRow(new QStandardItem(line.getToken(i+2).c_str()));
255 }
256 }
257 else
258 {
259 ui.sockdev->setText(line.getToken(2).c_str());
260 }
261 }
262 sockdevChanged();
263 ui.fileNamesListView->setModel(mModel);
264 ui.fileNamesListView->setViewMode(QListView::ListMode);
265 }
266