Debian Codegraph @

HercConfiguration/GenericDeviceProperties.cpp

raw symbols SCIP
1 /*
2 * File: GenericDeviceProperties.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 "GenericDeviceProperties.h"
27 #include "TerminalProperties.h"
28 #include "SysgProperties.h"
29 #include "ConsoleProperties.h"
30 #include "PrinterProperties.h"
31 #include "CardReaderProperties.h"
32 #include "PunchProperties.h"
33 #include "TapeProperties.h"
34 #include "CtcProperties.h"
35 #include "DasdProperties.h"
36 #include "DevicesWidget.h"
37 #include "ConfigurationEditor.h"
38
39 #include <QMessageBox>
40
41 #include <sstream>
42 #include <iomanip>
43
44 GenericDeviceProperties::GenericDeviceProperties(ConfigLine& line, QWidget *parent)
45 : IpValidator(parent) , mLine(line), mParent(parent),
46 mOriginalDeviceNumber(ConfigurationEditor::parseNum(mLine.getToken(0),16))
47 {
48
49
50 }
51
52 GenericDeviceProperties::~GenericDeviceProperties()
53 {
54
55 }
56
57 GenericDeviceProperties * GenericDeviceProperties::classFactory(DeviceConfigLine& line, QWidget *parent, DeviceTypes::Type type)
58 {
59 if (type == 0)
60 type = line.getDeviceType();
61 hOutDebug(1, "GenericDeviceProperties::classFactory " << type);
62 switch(type)
63 {
64 case DeviceTypes::Terminal:
65 return new TerminalProperties(line,parent);
66 case DeviceTypes::Console:
67 return new ConsoleProperties(line,parent);
68 case DeviceTypes::Printer:
69 return new PrinterProperties(line,parent);
70 case DeviceTypes::CardReader:
71 return new CardReaderProperties(line,parent);
72 case DeviceTypes::CardPunch:
73 return new PunchProperties(line,parent);
74 case DeviceTypes::Tape:
75 return new TapeProperties(line,parent);
76 case DeviceTypes::CTC:
77 return new CtcProperties(line,parent);
78 case DeviceTypes::DASD:
79 return new DasdProperties(line,parent);
80 case DeviceTypes::Sysg:
81 return new SysgProperties(line,parent);
82 default:
83 throw hsException("Invalid device, "+ line.getToken(1));
84 }
85 }
86
87 bool GenericDeviceProperties::deviceNumberValidator(QLineEdit * deviceLine)
88 {
89 // check that field is not empty
90 if (deviceLine->text().isEmpty() || !ConfigurationEditor::validateNum(deviceLine->text().toStdString(),16))
91 {
92 QMessageBox * p = new QMessageBox(this);
93 p->setText("Please enter device number in the range 0000-ffff");
94 p->exec();
95 deviceLine->setFocus();
96 return false;
97 }
98
99 //make sure device number is new/unique
100 DevicesWidget * dev = dynamic_cast<DevicesWidget *>(mParent);
101 // if parent is not DevicesWidget, it must be a live update while hercules is running
102 if (dev == NULL)
103 return true;
104
105 std::stringstream buff;
106 int iDevno = ConfigurationEditor::parseNum(deviceLine->text().toStdString(),16);
107 if (iDevno != mOriginalDeviceNumber)
108 {
109 buff << std::hex << std::setw(4) << std::setfill('0') << std::uppercase
110 << iDevno;
111 std::string devno = buff.str();
112 if (!dev->isUnique(devno))
113 {
114 QMessageBox * p = new QMessageBox(this);
115 p->setText("This device number is already used");
116 p->exec();
117 return false;
118 }
119 }
120 return true;
121
122 }
123