Debian Codegraph @

HercConfiguration/PunchProperties.cpp

raw symbols SCIP
1 /*
2 * File: PunchProperties.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 "PunchProperties.h"
26
27 #include <sstream>
28 #include <algorithm>
29
30 PunchProperties::PunchProperties(ConfigLine& line, QWidget *parent)
31 : GenericDeviceProperties(line, parent)
32 {
33 ui.setupUi(this);
34
35 ui.fileName->setValidator(new PunchFileNameValidator(this));
36
37 if (!line.isNew())
38 {
39 ui.deviceNumber->setText(mLine.getToken(0).c_str());
40 ui.punchCombo->setCurrentIndex( 0 );
41 if (mLine.size() > 2)
42 {
43 ui.fileName->setText(mLine.getToken(2).c_str());
44 ui.asciiCheckBox->setChecked(false);
45 ui.crlfCheckBox->setChecked(false);
46 ui.noclearCheckBox->setChecked(false);
47 for (int i=3; i< mLine.size(); i++)
48 {
49 std::string token = (mLine.getToken(i));
50 std::transform(token.begin(), token.end(), token.begin(), ::tolower);
51 if (token == "ascii")
52 ui.asciiCheckBox->setChecked(true);
53 if (token == "crlf")
54 ui.crlfCheckBox->setChecked(true);
55 if (token == "noclear")
56 ui.noclearCheckBox->setChecked(true);
57 }
58 }
59 else
60 {
61 ui.asciiCheckBox->setEnabled(false);
62 ui.crlfCheckBox->setEnabled(false);
63 ui.noclearCheckBox->setEnabled(false);
64 }
65 }
66
67 connect(ui.OKButton, SIGNAL(clicked()), this, SLOT(ok()));
68 connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
69
70 }
71
72 PunchProperties::~PunchProperties()
73 {
74
75 }
76
77 void PunchProperties::ok()
78 {
79 if (!deviceNumberValidator(ui.deviceNumber))
80 return;
81 std::stringstream newLineBuff;
82 bool fileGiven = (ui.fileName->text().toStdString().length() > 0);
83
84 newLineBuff << ui.deviceNumber->text().toStdString() << " "
85 << ui.punchCombo->currentText().toStdString() << " "
86 << ui.fileName->text().toStdString()
87 << (fileGiven && ui.asciiCheckBox->isChecked() ? " ascii" : " ")
88 << (fileGiven && ui.crlfCheckBox->isChecked() ? " crlf" : " ")
89 << (fileGiven && ui.noclearCheckBox->isChecked() ? " noclear" : " ")
90 << "\n";
91 hOutDebug(5, "new line:" << newLineBuff.str());
92 mLine.replaceLine(newLineBuff.str());
93 emit updateLine(true);
94 this->deleteLater();
95 }
96
97 void PunchProperties::cancel()
98 {
99 emit updateLine(false);
100 this->deleteLater();
101 }
102
103
104 void PunchProperties::setBoxesEnabled(bool enabled)
105 {
106 ui.asciiCheckBox->setEnabled(enabled);
107 ui.crlfCheckBox->setEnabled(enabled);
108 ui.noclearCheckBox->setEnabled(enabled);
109 }
110
111 PunchFileNameValidator::PunchFileNameValidator(QObject * parent)
112 : QValidator(parent), mParent(dynamic_cast<PunchProperties *>(parent))
113 {
114
115 }
116
117 QValidator::State PunchFileNameValidator::validate(QString & v, int & ) const
118 {
119 mParent->setBoxesEnabled(v.length()>0);
120 return QValidator::Acceptable;
121 }
122