| 1 | /* |
| 2 | * File: DeviceMenuProcessor.cpp |
| 3 | * |
| 4 | * Author: Jacob Dekel |
| 5 | * Created on: Oct, 14 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 "DeviceMenuProcessor.h" |
| 27 | #include "GenericDeviceProperties.h" |
| 28 | #include "NewReaderFile.h" |
| 29 | |
| 30 | #include <QMouseEvent> |
| 31 | |
| 32 | DeviceMenuProcessor::DeviceMenuProcessor(QWidget *parent) : |
| 33 | QWidget(parent), mClickRow(-1) |
| 34 | { |
| 35 | |
| 36 | } |
| 37 | |
| 38 | DeviceMenuProcessor::~DeviceMenuProcessor() |
| 39 | { |
| 40 | |
| 41 | } |
| 42 | |
| 43 | void DeviceMenuProcessor::devicesClick(QMouseEvent * event) |
| 44 | { |
| 45 | hOutDebug(5, "devicesClick(" << mClickRow << "): " << |
| 46 | (event->button() == Qt::RightButton ? "Right " : " ?" ) |
| 47 | << " at" << event->x()); |
| 48 | mLastClick = mClickRow; |
| 49 | |
| 50 | if ( event->button() == Qt::RightButton ) |
| 51 | { |
| 52 | mMenu.clear(); |
| 53 | |
| 54 | QMenu * mMenuAdd; |
| 55 | mMenuAdd = mMenu.addMenu("Add..."); |
| 56 | mMenuAdd->clear(); |
| 57 | mMenuAdd->addAction("Terminal", this, SLOT(menuAddTerminal())); |
| 58 | if (canAddSYSG()) |
| 59 | mMenuAdd->addAction("SYSG", this, SLOT(menuAddSYSG())); |
| 60 | mMenuAdd->addAction("Console", this, SLOT(menuAddConsole())); |
| 61 | mMenuAdd->addAction("Printer", this, SLOT(menuAddPrinter())); |
| 62 | mMenuAdd->addAction("Card Reader", this, SLOT(menuAddCardReader())); |
| 63 | mMenuAdd->addAction("Card Punch", this, SLOT(menuAddCardPunch())); |
| 64 | mMenuAdd->addAction("Tape Drives", this, SLOT(menuAddTape())); |
| 65 | mMenuAdd->addAction("CTC", this, SLOT(menuAddCTC())); |
| 66 | mMenuAdd->addAction("Dasd", this, SLOT(menuAddDasd())); |
| 67 | |
| 68 | if (realDevice()) |
| 69 | { |
| 70 | mMenu.addAction("Delete", this, SLOT(menuDelete())); |
| 71 | if (!isConfig()) |
| 72 | { |
| 73 | mMenu.addAction("Rename", this, SLOT(menuRename())); |
| 74 | if (hasConfig()) |
| 75 | mMenu.addAction("Re-Initialize...", this, SLOT(menuProperties())); |
| 76 | mMenu.addAction("Attention Interrupt", this, SLOT(menuInterrupt())); |
| 77 | mMenu.addAction("Subchannel Status", this, SLOT(menuStatus())); |
| 78 | if (traced()) |
| 79 | mMenu.addAction(*new QIcon(":/icons/16x16/check.png"),"Trace CCW", this, SLOT(menuTraceCCW())); |
| 80 | else |
| 81 | mMenu.addAction("Trace CCW", this, SLOT(menuTraceCCW())); |
| 82 | if (this->getType(mClickRow) == DeviceTypes::Tape) |
| 83 | { |
| 84 | hOutDebug(3, "TAPE"); |
| 85 | mMenu.addSeparator(); |
| 86 | mMenu.addAction("Load Tape", this, SLOT(menuLoad())); |
| 87 | mMenu.addAction("Unload Tape", this, SLOT(menuUnload())); |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | hOutDebug(3, "not tape"); |
| 92 | } |
| 93 | } |
| 94 | else |
| 95 | { |
| 96 | mMenu.addSeparator(); |
| 97 | mMenu.addAction("Properties...", this, SLOT(menuProperties())); |
| 98 | mMenu.move(event->globalX(), event->globalY()); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | mMenu.move(event->globalX(), event->globalY()); |
| 103 | mMenu.setVisible(true); |
| 104 | mClickRow = -1; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | void DeviceMenuProcessor::menuAddTerminal() |
| 109 | { |
| 110 | menuAddItem(DeviceTypes::Terminal); |
| 111 | } |
| 112 | |
| 113 | void DeviceMenuProcessor::menuAddConsole() |
| 114 | { |
| 115 | menuAddItem(DeviceTypes::Console); |
| 116 | } |
| 117 | |
| 118 | void DeviceMenuProcessor::menuAddPrinter() |
| 119 | { |
| 120 | menuAddItem(DeviceTypes::Printer); |
| 121 | } |
| 122 | |
| 123 | void DeviceMenuProcessor::menuAddCardReader() |
| 124 | { |
| 125 | menuAddItem(DeviceTypes::CardReader); |
| 126 | } |
| 127 | |
| 128 | void DeviceMenuProcessor::menuAddCardPunch() |
| 129 | { |
| 130 | menuAddItem(DeviceTypes::CardPunch); |
| 131 | } |
| 132 | |
| 133 | void DeviceMenuProcessor::menuAddTape() |
| 134 | { |
| 135 | menuAddItem(DeviceTypes::Tape); |
| 136 | } |
| 137 | |
| 138 | void DeviceMenuProcessor::menuAddCTC() |
| 139 | { |
| 140 | menuAddItem(DeviceTypes::CTC); |
| 141 | } |
| 142 | |
| 143 | void DeviceMenuProcessor::menuAddDasd() |
| 144 | { |
| 145 | menuAddItem(DeviceTypes::DASD); |
| 146 | } |
| 147 | |
| 148 | void DeviceMenuProcessor::menuAddSYSG() |
| 149 | { |
| 150 | menuAddItem(DeviceTypes::Sysg); |
| 151 | } |
| 152 | |
| 153 | void DeviceMenuProcessor::menuAddItem(int iType) |
| 154 | { |
| 155 | hOutDebug(5, "add Item" << mClickRow); |
| 156 | if (iType < 0 || iType > DeviceTypes::Comm) return; |
| 157 | DeviceTypes::Type type = static_cast<DeviceTypes::Type> (iType); |
| 158 | mCandidateLine = new DeviceConfigLine("\n"); |
| 159 | mCandidateLine->setNew(true); |
| 160 | |
| 161 | GenericDeviceProperties * mProp = NULL; |
| 162 | |
| 163 | try |
| 164 | { |
| 165 | mProp = GenericDeviceProperties::classFactory(*mCandidateLine,this,type); |
| 166 | } |
| 167 | catch (...) |
| 168 | { |
| 169 | hOutDebug(2,"exception caught in class factory (add)"); |
| 170 | } |
| 171 | |
| 172 | connect(mProp, SIGNAL(updateLine(bool)), this, SLOT(doAddDevice(bool))); |
| 173 | mProp->setVisible(true); |
| 174 | |
| 175 | mClickRow=-1; |
| 176 | } |
| 177 | |
| 178 | void DeviceMenuProcessor::menuLoad() |
| 179 | { |
| 180 | NewReaderFile * newTapeFile = new NewReaderFile(this); |
| 181 | connect(newTapeFile, SIGNAL(okPressed(QString&)), this, SLOT(newTapeFileOK(QString&))); |
| 182 | newTapeFile->exec(); |
| 183 | } |
| 184 | |
| 185 | void DeviceMenuProcessor::menuUnload() |
| 186 | { |
| 187 | QString s("*"); |
| 188 | if (!isConfig()) doLoadTape(s); |
| 189 | } |
| 190 | |
| 191 | |
| 192 | void DeviceMenuProcessor::newTapeFileOK(QString& tapeFileName) |
| 193 | { |
| 194 | if (!isConfig()) doLoadTape(tapeFileName); |
| 195 | } |
| 196 |