| 1 | /* |
| 2 | * File: mainwindow.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 "MainWindow.h" |
| 26 | #include "MainPanelClassic.h" |
| 27 | #include "MainPanelModern.h" |
| 28 | #include "PreferencesWin.h" |
| 29 | #include "Watchdog.h" |
| 30 | #include "Recovery.h" |
| 31 | #include "HelpAbout.h" |
| 32 | #include "DasdInit.h" |
| 33 | #include "DasdLoad.h" |
| 34 | #include "DasdIsup.h" |
| 35 | #include "Dasdls.h" |
| 36 | #include "Dasdcat.h" |
| 37 | #include "Dasdconv.h" |
| 38 | #include "Dasdcopy.h" |
| 39 | #include "TapeMap.h" |
| 40 | #include "TapeSplt.h" |
| 41 | #include "TapeCopy.h" |
| 42 | #include "HetInit.h" |
| 43 | #include "HetGet.h" |
| 44 | #include "HetUpd.h" |
| 45 | #include "HetMap.h" |
| 46 | #include "PrinterDialog.h" |
| 47 | #include "StationeryDialog.h" |
| 48 | #include "StationeryDialog.h" |
| 49 | #include "DecolationDialog.h" |
| 50 | #include "NamedPipe.h" |
| 51 | #include "Environment.h" |
| 52 | #include "Arguments.h" |
| 53 | #include "IplConfig.h" |
| 54 | #include "SystemConfigLine.h" |
| 55 | #include "LogWidget.h" |
| 56 | |
| 57 | #include <QFileDialog> |
| 58 | #include <QDockWidget> |
| 59 | #include <QMessageBox> |
| 60 | #include <QFile> |
| 61 | #include <QTimer> |
| 62 | |
| 63 | #include <iostream> |
| 64 | #include "cerrno" |
| 65 | #ifndef hFramework |
| 66 | #include <err.h> |
| 67 | #endif |
| 68 | #include <typeinfo> |
| 69 | #ifdef UNISTD_INC |
| 70 | #include <unistd.h> |
| 71 | #endif |
| 72 | |
| 73 | |
| 74 | MainWindow::MainWindow(QWidget *parent) |
| 75 | : QMainWindow(parent), |
| 76 | mTopDock(NULL), |
| 77 | mDevicesDock(NULL), |
| 78 | mConfigFile(NULL), |
| 79 | mCommandLine(NULL), |
| 80 | mHerculesExecutor(NULL), |
| 81 | mPrinterDialog(NULL), |
| 82 | mHerculesActive(false) |
| 83 | { |
| 84 | ui.setupUi(this); |
| 85 | setDarkBackground(Preferences::getInstance().darkBackground()); |
| 86 | QString iconPath(Environment::getIconsPath().c_str()); |
| 87 | this->setWindowIcon(QIcon(iconPath+"/tray.xpm")); |
| 88 | |
| 89 | if (Arguments::getInstance().configFileName().length() > 0) |
| 90 | { |
| 91 | mConfigFile = new ConfigFile(Arguments::getInstance().configFileName()); |
| 92 | } |
| 93 | |
| 94 | QDir d(""); |
| 95 | mCurrentPath = d.absolutePath(); |
| 96 | |
| 97 | // left dock (Devices) |
| 98 | mDevicesDock = new QDockWidget("Devices",this); |
| 99 | mDevicesDock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
| 100 | mDevicesPane = new DevicesPane(this); |
| 101 | mDevicesDock->setWidget(mDevicesPane); |
| 102 | addDockWidget(Qt::LeftDockWidgetArea, mDevicesDock ); |
| 103 | |
| 104 | // top dock (MainPanel) |
| 105 | mTopDock = new QDockWidget("Controls",this); |
| 106 | mTopDock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
| 107 | if (Preferences::getInstance().theme() == Preferences::Modern) |
| 108 | mMainPanel = new MainPanelModern(this); |
| 109 | else |
| 110 | mMainPanel = new MainPanelClassic(this); |
| 111 | mTopDock->setWidget(mMainPanel); |
| 112 | addDockWidget(Qt::TopDockWidgetArea,mTopDock ); |
| 113 | |
| 114 | // gregs32 dock |
| 115 | mGRegisters32Dock = new QDockWidget("32-bit General Regs",this); |
| 116 | mGRegisters32Dock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
| 117 | mGRegisters32 = new Regs32(this,Regs32::gCommand); |
| 118 | mGRegisters32Dock->setWidget(mGRegisters32); |
| 119 | addDockWidget(Qt::TopDockWidgetArea,mGRegisters32Dock ); |
| 120 | this->tabifyDockWidget(mTopDock,mGRegisters32Dock); |
| 121 | mGRegisters32Dock->setVisible(false); |
| 122 | |
| 123 | // cregs32 dock |
| 124 | mCRegisters32Dock = new QDockWidget("32-bit Control Regs",this); |
| 125 | mCRegisters32Dock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
| 126 | mCRegisters32 = new Regs32(this,Regs32::cCommand); |
| 127 | mCRegisters32Dock->setWidget(mCRegisters32); |
| 128 | addDockWidget(Qt::TopDockWidgetArea,mCRegisters32Dock ); |
| 129 | this->tabifyDockWidget(mTopDock,mCRegisters32Dock); |
| 130 | mCRegisters32Dock->setVisible(false); |
| 131 | |
| 132 | // fregs32 dock |
| 133 | mFRegisters32Dock = new QDockWidget("32-bit Floating-Point Regs",this); |
| 134 | mFRegisters32Dock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
| 135 | mFRegisters32 = new Regs32(this,Regs32::fCommand); |
| 136 | mFRegisters32Dock->setWidget(mFRegisters32); |
| 137 | addDockWidget(Qt::TopDockWidgetArea,mFRegisters32Dock ); |
| 138 | this->tabifyDockWidget(mTopDock,mFRegisters32Dock); |
| 139 | mFRegisters32Dock->setVisible(false); |
| 140 | |
| 141 | // aregs32 dock |
| 142 | mARegisters32Dock = new QDockWidget("Access Registers",this); |
| 143 | mARegisters32Dock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
| 144 | mARegisters32 = new Regs32(this,Regs32::aCommand); |
| 145 | mARegisters32Dock->setWidget(mARegisters32); |
| 146 | addDockWidget(Qt::TopDockWidgetArea,mARegisters32Dock ); |
| 147 | this->tabifyDockWidget(mTopDock,mARegisters32Dock); |
| 148 | mARegisters32Dock->setVisible(false); |
| 149 | |
| 150 | // gregs64 dock |
| 151 | mGRegisters64Dock = new QDockWidget("64-bit General Regs",this); |
| 152 | mGRegisters64Dock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
| 153 | mGRegisters64 = new Regs64(this,Regs64::gCommand); |
| 154 | mGRegisters64Dock->setWidget(mGRegisters64); |
| 155 | addDockWidget(Qt::TopDockWidgetArea,mGRegisters64Dock ); |
| 156 | this->tabifyDockWidget(mTopDock,mGRegisters64Dock); |
| 157 | mGRegisters64Dock->setVisible(false); |
| 158 | |
| 159 | // cregs64 dock |
| 160 | mCRegisters64Dock = new QDockWidget("64-bit Control Regs",this); |
| 161 | mCRegisters64Dock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
| 162 | mCRegisters64 = new Regs64(this, Regs64::cCommand); |
| 163 | mCRegisters64Dock->setWidget(mCRegisters64); |
| 164 | addDockWidget(Qt::TopDockWidgetArea,mCRegisters64Dock ); |
| 165 | this->tabifyDockWidget(mTopDock,mCRegisters64Dock); |
| 166 | mCRegisters64Dock->setVisible(false); |
| 167 | |
| 168 | // fregs64 dock |
| 169 | mFRegisters64Dock = new QDockWidget("64-bit Floating Point Regs",this); |
| 170 | mFRegisters64Dock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
| 171 | mFRegisters64 = new Regs64(this, Regs64::fCommand); |
| 172 | mFRegisters64Dock->setWidget(mFRegisters64); |
| 173 | addDockWidget(Qt::TopDockWidgetArea,mFRegisters64Dock ); |
| 174 | this->tabifyDockWidget(mTopDock,mFRegisters64Dock); |
| 175 | mFRegisters64Dock->setVisible(false); |
| 176 | |
| 177 | tabifyDockWidget(mGRegisters32Dock, mTopDock); |
| 178 | |
| 179 | // CommandLine |
| 180 | mBottomDock = new QDockWidget("Command",this); |
| 181 | mBottomDock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
| 182 | mCommandLine = new CommandLine(mBottomDock); |
| 183 | mCommandLine->setReadOnly(true); |
| 184 | mBottomDock->setWidget(mCommandLine); |
| 185 | addDockWidget(Qt::BottomDockWidgetArea,mBottomDock ); |
| 186 | |
| 187 | // psw |
| 188 | mPswDock = new QDockWidget("PSW", this); |
| 189 | mPswDock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
| 190 | mPsw = new Psw(this->statusBar()); |
| 191 | mPswDock->setWidget(mPsw); |
| 192 | addDockWidget(Qt::BottomDockWidgetArea,mPswDock ); |
| 193 | this->tabifyDockWidget(mPswDock,mBottomDock); |
| 194 | if (Preferences::getInstance().pswMode() == Psw::Docked) |
| 195 | mPswDock->setVisible(true); |
| 196 | else |
| 197 | mPswDock->setVisible(false); |
| 198 | mPsw->setMode(Preferences::getInstance().pswMode()); |
| 199 | mPsw->setDormant(); |
| 200 | |
| 201 | if( (Preferences::getInstance().regs(Preferences::ViewGR32)) ) editView32BitGr(); |
| 202 | if( (Preferences::getInstance().regs(Preferences::ViewCR32)) ) editView32BitCr(); |
| 203 | if( (Preferences::getInstance().regs(Preferences::ViewFR32)) ) editView32BitFr(); |
| 204 | if( (Preferences::getInstance().regs(Preferences::ViewAR32)) ) editView32BitAr(); |
| 205 | if( (Preferences::getInstance().regs(Preferences::ViewGR64)) ) editView64BitGr(); |
| 206 | if( (Preferences::getInstance().regs(Preferences::ViewCR64)) ) editView64BitCr(); |
| 207 | if( (Preferences::getInstance().regs(Preferences::ViewFR64)) ) editView64BitFr(); |
| 208 | ui.actionView_PSW->setChecked(Preferences::getInstance().regs(Preferences::ViewPsw)); |
| 209 | editViewPSW(); |
| 210 | |
| 211 | QString path = Environment::getIconsPath().c_str(); |
| 212 | QIcon trayIcon(path + "/tray.xpm"); |
| 213 | mSystemTrayIcon = new QSystemTrayIcon(trayIcon); |
| 214 | |
| 215 | QMenu *trayIconMenu = new QMenu(this); |
| 216 | QAction *restoreAction = new QAction(tr("&Hide"), this); |
| 217 | connect(restoreAction, SIGNAL(triggered()), this, SLOT(hideRestore())); |
| 218 | trayIconMenu->addAction(restoreAction); |
| 219 | mSystemTrayIcon->setContextMenu(trayIconMenu); |
| 220 | |
| 221 | connect(ui.actionNew, SIGNAL(triggered()), this , SLOT(newConfig())); |
| 222 | connect(ui.actionOpen_configuration, SIGNAL(triggered()), this , SLOT(openConfig())); |
| 223 | connect(ui.actionEditConfig, SIGNAL(triggered()), this , SLOT(config())); |
| 224 | connect(ui.actionSave, SIGNAL(triggered()), this , SLOT(saveConfig())); |
| 225 | connect(ui.actionSave_As, SIGNAL(triggered()), this , SLOT(saveConfigAs())); |
| 226 | connect(ui.actionExit, SIGNAL(triggered()), this , SLOT(exitNow())); |
| 227 | connect(ui.actionViewControls, SIGNAL(triggered()), this, SLOT(editViewControls())); |
| 228 | connect(ui.actionViewDevices, SIGNAL(triggered()), this, SLOT(editViewDevices())); |
| 229 | connect(ui.actionViewCommand, SIGNAL(triggered()), this, SLOT(editViewCommand())); |
| 230 | connect(ui.actionView_32_bit_General_Registers, SIGNAL(triggered()), this, SLOT(editView32BitGr())); |
| 231 | connect(ui.actionView_32_bit_Control_Registers, SIGNAL(triggered()), this, SLOT(editView32BitCr())); |
| 232 | connect(ui.actionView_32_bit_Floating_Point_Registers, SIGNAL(triggered()), this, SLOT(editView32BitFr())); |
| 233 | connect(ui.actionView_32_bit_Access_Registers, SIGNAL(triggered()), this, SLOT(editView32BitAr())); |
| 234 | connect(ui.actionView_64_bit_General_Registers, SIGNAL(triggered()), this, SLOT(editView64BitGr())); |
| 235 | connect(ui.actionView_64_bit_Control_Registers, SIGNAL(triggered()), this, SLOT(editView64BitCr())); |
| 236 | connect(ui.actionView_64_bit_Floating_Point_Registers, SIGNAL(triggered()), this, SLOT(editView64BitFr())); |
| 237 | connect(ui.actionView_PSW, SIGNAL(triggered()), this, SLOT(editViewPSW())); |
| 238 | connect(ui.actionCopy, SIGNAL(triggered()), this, SLOT(editCopy())); |
| 239 | connect(ui.actionDelete_messages, SIGNAL(triggered()), this, SLOT(deleteMessages())); |
| 240 | connect(ui.actionSave_messages, SIGNAL(triggered()), this, SLOT(saveMessages())); |
| 241 | connect(ui.actionPreferences, SIGNAL(triggered()), this, SLOT(preferences())); |
| 242 | connect(ui.actionPower_on, SIGNAL(triggered()), this, SLOT(powerOn())); |
| 243 | connect(ui.actionPower_off, SIGNAL(triggered()), this, SLOT(powerOff())); |
| 244 | connect(ui.actionIPL_Load, SIGNAL(triggered()), this, SLOT(loadCommand())); |
| 245 | connect(ui.actionStart, SIGNAL(triggered()), this, SLOT(start())); |
| 246 | connect(ui.actionStop, SIGNAL(triggered()), this, SLOT(stop())); |
| 247 | connect(ui.actionExtInterrupt, SIGNAL(triggered()), this, SLOT(extInterrupt())); |
| 248 | connect(ui.actionStore_status, SIGNAL(triggered()), this, SLOT(store())); |
| 249 | connect(ui.actionPSW_Restart, SIGNAL(triggered()), this, SLOT(restart())); |
| 250 | connect(ui.actionDevice_Interrupt, SIGNAL(triggered()), this, SLOT(devInterrupt())); |
| 251 | connect(ui.actionDasdinit, SIGNAL(triggered()), this, SLOT(dasdinit())); |
| 252 | connect(ui.actionDasdload, SIGNAL(triggered()), this, SLOT(dasdload())); |
| 253 | connect(ui.actionDasdisup, SIGNAL(triggered()), this, SLOT(dasdisup())); |
| 254 | connect(ui.actionDasdls, SIGNAL(triggered()), this, SLOT(dasdls())); |
| 255 | connect(ui.actionDasdcat, SIGNAL(triggered()), this, SLOT(dasdcat())); |
| 256 | connect(ui.actionDasdconv, SIGNAL(triggered()), this, SLOT(dasdconv())); |
| 257 | connect(ui.actionDasdcopy, SIGNAL(triggered()), this, SLOT(dasdcopy())); |
| 258 | connect(ui.actionTapemap, SIGNAL(triggered()), this, SLOT(tapemap())); |
| 259 | connect(ui.actionTapecopy, SIGNAL(triggered()), this, SLOT(tapecopy())); |
| 260 | connect(ui.actionTapesplit, SIGNAL(triggered()), this, SLOT(tapesplit())); |
| 261 | connect(ui.actionHetinit, SIGNAL(triggered()), this, SLOT(hetinit())); |
| 262 | connect(ui.actionHetget, SIGNAL(triggered()), this, SLOT(hetget())); |
| 263 | connect(ui.actionHetupd, SIGNAL(triggered()), this, SLOT(hetupd())); |
| 264 | connect(ui.actionHetmap, SIGNAL(triggered()), this, SLOT(hetmap())); |
| 265 | connect(ui.actionStartPrinter, SIGNAL(triggered()), this, SLOT(printer())); |
| 266 | connect(ui.actionStationery, SIGNAL(triggered()), this, SLOT(stationery())); |
| 267 | connect(ui.actionDecolation, SIGNAL(triggered()), this, SLOT(decolation())); |
| 268 | connect(ui.actionAbout, SIGNAL(triggered()), this, SLOT(helpAbout())); |
| 269 | connect(mDevicesPane, SIGNAL(restartDevices()), this , SLOT(restartDevices())); |
| 270 | connect(mCommandLine, SIGNAL(returnPressed()), this , SLOT(newCommand())); |
| 271 | connect(mCommandLine, SIGNAL(ctrl_c()), this , SLOT(editCopy())); |
| 272 | connect(mSystemTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systrayClick(QSystemTrayIcon::ActivationReason))); |
| 273 | connectMainPanel(); |
| 274 | |
| 275 | if (Preferences::getInstance().splitLog()) |
| 276 | { |
| 277 | mLogWindow = new LogWidget(this); |
| 278 | fontChanged(); |
| 279 | setCentralWidget(static_cast<LogWidget *>(mLogWindow)->tabWidget()); |
| 280 | } |
| 281 | else |
| 282 | { |
| 283 | mLogWindow = new PlainLogWidget(this); |
| 284 | mLogWindow->setReadOnly(true); |
| 285 | fontChanged(); |
| 286 | setCentralWidget(mLogWindow); |
| 287 | } |
| 288 | |
| 289 | int recoverRc = NamedPipe::getInstance().recover(); |
| 290 | mRecovery = (recoverRc == 1) ; |
| 291 | if (mRecovery) |
| 292 | { |
| 293 | Recovery * r = new Recovery(this); |
| 294 | r->exec(); |
| 295 | mRecoveryConfig = r->getHerculesConf().c_str(); |
| 296 | if (mRecoveryConfig == "!") |
| 297 | { |
| 298 | exit(0); |
| 299 | } |
| 300 | if (mRecoveryConfig == "") |
| 301 | mRecovery = false; |
| 302 | else |
| 303 | { |
| 304 | powerOn(); |
| 305 | mLogWindow->append("--- successfully attached to Hercules ---"); |
| 306 | } |
| 307 | } |
| 308 | mCommandLine->restore(); |
| 309 | setVisible(true); |
| 310 | if (Preferences::getInstance().animate()) |
| 311 | QTimer::singleShot(100, this, SLOT(preferencesChanged())); |
| 312 | if (Arguments::getInstance().configFileName().length() > 0) |
| 313 | powerOn(); |
| 314 | } |
| 315 | |
| 316 | MainWindow::~MainWindow() |
| 317 | { |
| 318 | DeviceConfigLine::clear(); // free acquired static data |
| 319 | if (mConfigFile != NULL) |
| 320 | delete mConfigFile; |
| 321 | } |
| 322 | |
| 323 | void MainWindow::connectMainPanel() |
| 324 | { |
| 325 | connect(mMainPanel, SIGNAL(powerOnClicked()), this , SLOT(powerOn())); |
| 326 | connect(mMainPanel, SIGNAL(powerOffClicked()), this , SLOT(powerOff())); |
| 327 | connect(mMainPanel, SIGNAL(interruptClicked()), this , SLOT(extInterrupt())); |
| 328 | connect(mMainPanel, SIGNAL(loadClicked()), this , SLOT(load())); |
| 329 | connect(mMainPanel, SIGNAL(restartClicked()), this , SLOT(restart())); |
| 330 | connect(mMainPanel, SIGNAL(storeClicked()), this , SLOT(store())); |
| 331 | connect(mMainPanel, SIGNAL(startClicked()), this , SLOT(start())); |
| 332 | connect(mMainPanel, SIGNAL(stopClicked()), this , SLOT(stop())); |
| 333 | } |
| 334 | |
| 335 | void MainWindow::writeToLog(QByteArray line) |
| 336 | { |
| 337 | mLogWindow->append(line); |
| 338 | } |
| 339 | |
| 340 | void MainWindow::preferencesChanged() |
| 341 | { |
| 342 | fontChanged(); |
| 343 | mipsChanged(); |
| 344 | pswChanged(); |
| 345 | styleChanged(); |
| 346 | themeChanged(); |
| 347 | mLogWindow->preferencesChanged(); |
| 348 | } |
| 349 | |
| 350 | void MainWindow::fontChanged() |
| 351 | { |
| 352 | std::string fontName = Preferences::getInstance().fontName(Preferences::LogFontObject); |
| 353 | if (fontName.size() == 0 || fontName[0] == '(') |
| 354 | { |
| 355 | mLogWindow ->setFont(QFont()); |
| 356 | } |
| 357 | else |
| 358 | { |
| 359 | QFont font(fontName.c_str()); |
| 360 | font.setPointSize(Preferences::getInstance().fontSize(Preferences::LogFontObject)); |
| 361 | font.setBold(Preferences::getInstance().fontIsBold(Preferences::LogFontObject)); |
| 362 | font.setItalic(Preferences::getInstance().fontIsItalic(Preferences::LogFontObject)); |
| 363 | mLogWindow->setFont(font); |
| 364 | } |
| 365 | mCRegisters32->setFont(); |
| 366 | mGRegisters32->setFont(); |
| 367 | mFRegisters32->setFont(); |
| 368 | mARegisters32->setFont(); |
| 369 | mCRegisters64->setFont(); |
| 370 | mGRegisters64->setFont(); |
| 371 | mFRegisters64->setFont(); |
| 372 | |
| 373 | mPsw->setFont(); |
| 374 | mCommandLine->setFont(); |
| 375 | } |
| 376 | |
| 377 | void MainWindow::mipsChanged() |
| 378 | { |
| 379 | mMainPanel->switchMips(); |
| 380 | } |
| 381 | |
| 382 | void MainWindow::pswChanged() |
| 383 | { |
| 384 | mPsw->setMode(Preferences::getInstance().pswMode()); |
| 385 | mPswDock->setVisible(Preferences::getInstance().pswMode() == Psw::Docked); |
| 386 | } |
| 387 | |
| 388 | void MainWindow::styleChanged() |
| 389 | { |
| 390 | QByteArray loadAddress = |
| 391 | QByteArray::number(mMainPanel->getLoadAddress(),16); // preserve |
| 392 | mMainPanel->close(); |
| 393 | delete mMainPanel; |
| 394 | if (Preferences::getInstance().theme() == Preferences::Classic) |
| 395 | mMainPanel = new MainPanelClassic(this); |
| 396 | else |
| 397 | mMainPanel = new MainPanelModern(this); |
| 398 | mMainPanel->setLoadAddress(loadAddress); // restore ipl address |
| 399 | if (mHerculesActive) mMainPanel->standby(); |
| 400 | mTopDock->setWidget(mMainPanel); |
| 401 | connectMainPanel(); |
| 402 | } |
| 403 | |
| 404 | void MainWindow::themeChanged() |
| 405 | { |
| 406 | setDarkBackground (Preferences::getInstance().darkBackground()); |
| 407 | if (Preferences::getInstance().animate()) |
| 408 | mMainPanel->animate(); |
| 409 | } |
| 410 | |
| 411 | void MainWindow::writeToLogFromQueue() |
| 412 | { |
| 413 | if (!mLogQueue.empty()) |
| 414 | { |
| 415 | QByteArray& s = mLogQueue.front(); |
| 416 | if (!s.isEmpty()) |
| 417 | { |
| 418 | mLogWindow->append(s); |
| 419 | } |
| 420 | mLogQueue.pop_front(); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | void MainWindow::dispatchStatus() |
| 425 | { |
| 426 | while (!mStatusQueue.empty()) |
| 427 | { |
| 428 | QByteArray& statusLine = mStatusQueue.front(); |
| 429 | hOutDebug(1, "writeToDevice:" << statusLine.data() << std::endl); |
| 430 | if (!statusLine.isEmpty()) |
| 431 | { |
| 432 | if (statusLine[0] == 'D') |
| 433 | { |
| 434 | if (mDevicesRecovery) recoverDevices(statusLine); |
| 435 | mDevicesPane->notify(statusLine); |
| 436 | } |
| 437 | else if (statusLine[0] == 'G') |
| 438 | mGRegisters32->notify(statusLine); |
| 439 | else if (statusLine[0] == 'C') |
| 440 | mCRegisters32->notify(statusLine); |
| 441 | else if (statusLine[0] == 'F') |
| 442 | mFRegisters32->notify(statusLine); |
| 443 | else if (statusLine[0] == 'A') |
| 444 | mARegisters32->notify(statusLine); |
| 445 | else if (statusLine[0] == '6') |
| 446 | { |
| 447 | if (statusLine[3] == 'G') |
| 448 | mGRegisters64->notify(statusLine); |
| 449 | else if (statusLine[3] == 'C') |
| 450 | mCRegisters64->notify(statusLine); |
| 451 | else if (statusLine[3] == 'F') |
| 452 | mFRegisters64->notify(statusLine); |
| 453 | } |
| 454 | else |
| 455 | { |
| 456 | if (mMainPanel->notify(statusLine)) |
| 457 | mStatusReceived = true; |
| 458 | mPsw->notify(statusLine); |
| 459 | } |
| 460 | } |
| 461 | mStatusQueue.pop_front(); |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | void MainWindow::recoverDevices(QByteArray& statusLine) |
| 466 | { |
| 467 | hOutDebug(3,"recorver:" <<statusLine.data()); |
| 468 | if (statusLine.startsWith("DEVX=")) return; |
| 469 | if (statusLine[4] == 'X') |
| 470 | { |
| 471 | if ( mDevicesRecoveryCommenced ) |
| 472 | { |
| 473 | mDevicesRecoveryCommenced = false; |
| 474 | mDevicesRecovery = false; |
| 475 | } |
| 476 | else |
| 477 | { |
| 478 | mDevicesRecoveryCommenced = true; |
| 479 | } |
| 480 | return; |
| 481 | } |
| 482 | else if (statusLine.startsWith("DEV=")) |
| 483 | statusLine = "DEVA=" + statusLine.mid(4); |
| 484 | else if (statusLine.startsWith("DEV") && statusLine[4] == '=') |
| 485 | statusLine = "DEVA=" + statusLine.mid(5); |
| 486 | |
| 487 | } |
| 488 | |
| 489 | void MainWindow::newCommand() |
| 490 | { |
| 491 | if (mHerculesExecutor == NULL) return; |
| 492 | CommandLine *cl = static_cast<CommandLine *>(QObject::sender()); |
| 493 | if (cl == NULL) return; |
| 494 | hOutDebug(2, cl->text().toStdString()); |
| 495 | if (!mLogWindow->isOSLog() || cl->text().left(1).compare(".") == 0) |
| 496 | mHerculesExecutor->issueFormattedCommand("%s\n",cl->text().toUtf8().data()); |
| 497 | else |
| 498 | mHerculesExecutor->issueFormattedCommand(".%s\n",cl->text().toUtf8().data()); |
| 499 | setIpled(cl->text()); |
| 500 | } |
| 501 | |
| 502 | |
| 503 | void MainWindow::newConfig() |
| 504 | { |
| 505 | mConfigFile = new ConfigFile("/usr/share/herculesstudio/template.conf"); |
| 506 | mConfigFile->setNew(true); |
| 507 | mConfiguration = new Configuration(mConfigFile, true, this); |
| 508 | mConfiguration->show(); |
| 509 | this->setWindowTitle("(new file) - Hercules Studio"); |
| 510 | } |
| 511 | |
| 512 | void MainWindow::config() |
| 513 | { |
| 514 | if (mConfigFile == NULL) |
| 515 | openConfig(); |
| 516 | if (mConfigFile == NULL) |
| 517 | return; |
| 518 | mConfiguration = new Configuration(mConfigFile, false, this); |
| 519 | mConfiguration->show(); |
| 520 | } |
| 521 | |
| 522 | void MainWindow::openConfig() |
| 523 | { |
| 524 | hOutDebug(5,"config at:" << Preferences::getInstance().configDir() << "."); |
| 525 | std::string s = QFileDialog::getOpenFileName(this, |
| 526 | tr("Open configuration"), |
| 527 | Preferences::getInstance().configDir().c_str(), |
| 528 | tr("Hercules configuration files (*.conf *.cnf);;All files(*)")).toUtf8().data(); |
| 529 | if (s.length() == 0) |
| 530 | return; |
| 531 | |
| 532 | mConfigFile = new ConfigFile(s); |
| 533 | QFileInfo f(s.c_str()); |
| 534 | Preferences::getInstance().setVolatileConfigDir(f.dir().absolutePath().toStdString().c_str()); |
| 535 | this->setWindowTitle((mConfigFile->getFileName() + " - Hercules Studio").c_str()); |
| 536 | } |
| 537 | |
| 538 | void MainWindow::saveConfig() |
| 539 | { |
| 540 | if (mConfigFile == NULL) return; |
| 541 | if (mConfigFile->isNew()) |
| 542 | { |
| 543 | saveConfigAs(); |
| 544 | } |
| 545 | else |
| 546 | { |
| 547 | mConfigFile->appendNewLines(); |
| 548 | mConfigFile->write(); |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | void MainWindow::saveConfigAs() |
| 553 | { |
| 554 | if (mConfigFile == NULL) return; |
| 555 | |
| 556 | if (mConfigFile->isNew()) |
| 557 | { |
| 558 | if (mConfigFile->numberOfDevices() == 0) |
| 559 | { |
| 560 | int reply = QMessageBox::warning(this, "New Configuration", |
| 561 | "The new configuration does not contain any devices.\n" |
| 562 | "In most cases Hercules will not be able to process it\n\n" |
| 563 | "Are you sure you want to save this configuration?", |
| 564 | QMessageBox::Ok, |
| 565 | QMessageBox::Cancel); |
| 566 | if (reply != QMessageBox::Ok) |
| 567 | { |
| 568 | mConfiguration = new Configuration(mConfigFile,false,this); |
| 569 | mConfiguration->setVisible(true); |
| 570 | return ; |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | std::string s = QFileDialog::getSaveFileName(this, |
| 576 | "Save configuration", |
| 577 | Preferences::getInstance().configDir().c_str(), |
| 578 | tr("Hercules configuration files (*.conf *.cnf);;All files(*)")).toUtf8().data(); |
| 579 | if (s.length() == 0) |
| 580 | return; |
| 581 | int pos = s.length()-5; |
| 582 | if ( (s.substr(pos,5) != ".conf") && (s.substr(pos+1,4) != ".cnf") ) |
| 583 | s += ".conf"; |
| 584 | mConfigFile->appendNewLines(); |
| 585 | mConfigFile->write(s); |
| 586 | this->setWindowTitle((mConfigFile->getFileName() + " - Hercules Studio").c_str()); |
| 587 | } |
| 588 | |
| 589 | void MainWindow::exitNow() |
| 590 | { |
| 591 | powerOff(); |
| 592 | close(); |
| 593 | } |
| 594 | |
| 595 | void MainWindow::editViewControls() |
| 596 | { |
| 597 | mTopDock->setVisible(!mTopDock->isVisible()); |
| 598 | ui.actionViewControls->setChecked(mTopDock->isVisible()); |
| 599 | } |
| 600 | |
| 601 | void MainWindow::editViewDevices() |
| 602 | { |
| 603 | mDevicesDock->setVisible(!mDevicesDock->isVisible()); |
| 604 | ui.actionViewDevices->setChecked(mDevicesDock->isVisible()); |
| 605 | } |
| 606 | |
| 607 | void MainWindow::editViewCommand() |
| 608 | { |
| 609 | mBottomDock->setVisible(!mBottomDock->isVisible()); |
| 610 | ui.actionViewCommand->setChecked(mBottomDock->isVisible()); |
| 611 | } |
| 612 | |
| 613 | void MainWindow::editView32BitGr() |
| 614 | { |
| 615 | bool newVal = !mGRegisters32Dock->isVisible(); |
| 616 | mGRegisters32Dock->setVisible(newVal); |
| 617 | mGRegisters32->setActive(newVal); |
| 618 | ui.actionView_32_bit_General_Registers->setChecked(newVal); |
| 619 | Preferences::getInstance().setRegs(Preferences::ViewGR32, newVal); |
| 620 | } |
| 621 | |
| 622 | void MainWindow::editView32BitCr() |
| 623 | { |
| 624 | bool newVal = !mCRegisters32Dock->isVisible(); |
| 625 | mCRegisters32Dock->setVisible(newVal); |
| 626 | mCRegisters32->setActive(newVal); |
| 627 | ui.actionView_32_bit_Control_Registers->setChecked(newVal); |
| 628 | Preferences::getInstance().setRegs(Preferences::ViewCR32, newVal); |
| 629 | } |
| 630 | |
| 631 | void MainWindow::editView32BitFr() |
| 632 | { |
| 633 | bool newVal = !mFRegisters32Dock->isVisible(); |
| 634 | mFRegisters32Dock->setVisible(newVal); |
| 635 | mFRegisters32->setActive(newVal); |
| 636 | ui.actionView_32_bit_Floating_Point_Registers->setChecked(newVal); |
| 637 | Preferences::getInstance().setRegs(Preferences::ViewFR32, newVal); |
| 638 | } |
| 639 | |
| 640 | void MainWindow::editView32BitAr() |
| 641 | { |
| 642 | bool newVal = !mARegisters32Dock->isVisible(); |
| 643 | mARegisters32Dock->setVisible(newVal); |
| 644 | mARegisters32->setActive(newVal); |
| 645 | ui.actionView_32_bit_Access_Registers->setChecked(newVal); |
| 646 | Preferences::getInstance().setRegs(Preferences::ViewAR32, newVal); |
| 647 | } |
| 648 | |
| 649 | void MainWindow::editView64BitGr() |
| 650 | { |
| 651 | bool newVal = !mGRegisters64Dock->isVisible(); |
| 652 | mGRegisters64Dock->setVisible(newVal); |
| 653 | mGRegisters64->setActive(newVal); |
| 654 | ui.actionView_64_bit_General_Registers->setChecked(newVal); |
| 655 | Preferences::getInstance().setRegs(Preferences::ViewGR64, newVal); |
| 656 | } |
| 657 | |
| 658 | void MainWindow::editView64BitCr() |
| 659 | { |
| 660 | bool newVal = !mCRegisters64Dock->isVisible(); |
| 661 | mCRegisters64Dock->setVisible(newVal); |
| 662 | mCRegisters64->setActive(newVal); |
| 663 | ui.actionView_64_bit_Control_Registers->setChecked(newVal); |
| 664 | Preferences::getInstance().setRegs(Preferences::ViewCR64, newVal); |
| 665 | } |
| 666 | |
| 667 | void MainWindow::editView64BitFr() |
| 668 | { |
| 669 | bool newVal = !mFRegisters64Dock->isVisible(); |
| 670 | mFRegisters64Dock->setVisible(newVal); |
| 671 | mFRegisters64->setActive(newVal); |
| 672 | ui.actionView_64_bit_Floating_Point_Registers->setChecked(newVal); |
| 673 | Preferences::getInstance().setRegs(Preferences::ViewFR64, newVal); |
| 674 | } |
| 675 | |
| 676 | void MainWindow::editViewPSW() |
| 677 | { |
| 678 | bool newVal = ui.actionView_PSW->isChecked(); |
| 679 | Preferences::getInstance().setRegs(Preferences::ViewPsw, newVal); |
| 680 | mPsw->setVisible(newVal, Preferences::getInstance().theme() == Preferences::Modern); |
| 681 | if (Preferences::getInstance().pswMode() == Psw::Docked) |
| 682 | { |
| 683 | mPswDock->setVisible(newVal); |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | void MainWindow::editCopy() |
| 688 | { |
| 689 | hOutDebug(4, "COPY"); |
| 690 | |
| 691 | if (mLogWindow->textIsSelected()) |
| 692 | { |
| 693 | mLogWindow->copySelectedText(); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | void MainWindow::deleteMessages() |
| 698 | { |
| 699 | if (mHerculesActive) |
| 700 | { |
| 701 | QMessageBox msgBox; |
| 702 | msgBox.setText("Messages belong to to a running Hercules."); |
| 703 | msgBox.setInformativeText("Are you sure you want to delete history messages?"); |
| 704 | msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); |
| 705 | msgBox.setDefaultButton(QMessageBox::Yes); |
| 706 | msgBox.setIcon(QMessageBox::Warning); |
| 707 | int ret = msgBox.exec(); |
| 708 | if (ret != QMessageBox::Yes) |
| 709 | return ; |
| 710 | } |
| 711 | mLogWindow->clear(); |
| 712 | } |
| 713 | |
| 714 | |
| 715 | void MainWindow::saveMessages() |
| 716 | { |
| 717 | mLogWindow->writeToFile(PlainLogWidget::MenuCommand); |
| 718 | return; |
| 719 | } |
| 720 | |
| 721 | void MainWindow::preferences() |
| 722 | { |
| 723 | PreferencesWin * pw = new PreferencesWin(mCurrentPath.toStdString(), this); |
| 724 | connect(pw, SIGNAL(preferencesChanged()), this, SLOT(preferencesChanged())); |
| 725 | pw->exec(); |
| 726 | } |
| 727 | |
| 728 | ConfigFile * MainWindow::getConfigurationFile() |
| 729 | { |
| 730 | return mConfigFile; |
| 731 | } |
| 732 | |
| 733 | |
| 734 | void MainWindow::powerOn() |
| 735 | { |
| 736 | std::string configName; |
| 737 | mStatusReceived=false; |
| 738 | if (!mRecovery) |
| 739 | { |
| 740 | if (mConfigFile == NULL) openConfig(); |
| 741 | if (mConfigFile == NULL) return; |
| 742 | configName = mConfigFile->getFileName(); |
| 743 | } |
| 744 | else |
| 745 | { |
| 746 | configName = mRecoveryConfig.toStdString(); |
| 747 | mConfigFile = new ConfigFile(configName); |
| 748 | } |
| 749 | |
| 750 | if (configName.empty()) return; |
| 751 | if (mConfigFile->changed()) |
| 752 | { |
| 753 | int ret = QMessageBox::warning(this, "Configuration", |
| 754 | "Configuration file was updated since last save action\n" |
| 755 | "Do you want to save it now?", |
| 756 | QMessageBox::Save | QMessageBox::Cancel, |
| 757 | QMessageBox::NoButton); |
| 758 | if (ret == QMessageBox::Save) |
| 759 | { |
| 760 | saveConfig(); |
| 761 | if (mConfigFile->changed()) // was save done? if not - bail out |
| 762 | return; |
| 763 | } |
| 764 | else return; |
| 765 | } |
| 766 | |
| 767 | if (mHerculesExecutor != NULL) return; |
| 768 | ui.menuFile->setEnabled(false); |
| 769 | int herculesPid = 0; |
| 770 | if (!mRecovery) |
| 771 | { |
| 772 | hOutDebug(5,"not recovery"); |
| 773 | mHerculesExecutor = new HerculesExecutor(*this); |
| 774 | herculesPid = mHerculesExecutor->run(configName, Preferences::getInstance().hercDir()); |
| 775 | mDevicesRecovery = false; |
| 776 | } |
| 777 | else |
| 778 | { |
| 779 | hOutDebug(2,"recovery"); |
| 780 | herculesPid = NamedPipe::getInstance().getHerculesPid(); |
| 781 | mHerculesExecutor = new HerculesExecutor(*this, herculesPid); |
| 782 | mDevicesRecovery = true; |
| 783 | } |
| 784 | |
| 785 | if (herculesPid < 0) |
| 786 | { |
| 787 | QMessageBox::critical(this,"Hercules not started", |
| 788 | "The Hercules program could not be started or not found.\n" |
| 789 | "Please set the correct path to the hercules program\n" |
| 790 | "using the Preferences window", |
| 791 | QMessageBox::Ok); |
| 792 | delete mHerculesExecutor; |
| 793 | mHerculesExecutor = NULL; |
| 794 | return; |
| 795 | } |
| 796 | |
| 797 | #ifndef hFramework |
| 798 | NamedPipe::getInstance().generatePid(getpid(), herculesPid); |
| 799 | #endif |
| 800 | |
| 801 | mLogRunner = new LogRunner(mLogQueue, mHerculesExecutor, Preferences::getInstance().logFileLines()); |
| 802 | connect(mLogRunner, SIGNAL(newData()), this , SLOT(writeToLogFromQueue())); |
| 803 | mLogRunner->start(); |
| 804 | |
| 805 | mStatusRunner = new StatusRunner(mStatusQueue, mHerculesExecutor); |
| 806 | connect(mStatusRunner, SIGNAL(newData()), this , SLOT(dispatchStatus())); |
| 807 | mStatusRunner->start(); |
| 808 | |
| 809 | #ifndef hFramework |
| 810 | mWatchdog = new Watchdog(herculesPid, !mRecovery); |
| 811 | #else |
| 812 | mWatchdog = new Watchdog(mHerculesExecutor->getQProcess()); |
| 813 | #endif |
| 814 | connect(mWatchdog, SIGNAL(HerculesEnded()), this, SLOT(herculesEndedSlot())); |
| 815 | mWatchdog->start(); |
| 816 | |
| 817 | mHerculesActive = true; |
| 818 | mMinimizeOnClose=true; |
| 819 | mCommandLine->setReadOnly(false); |
| 820 | |
| 821 | mMainPanel->standby(); |
| 822 | mPsw->standby(); |
| 823 | this->setWindowTitle((mConfigFile->getFileName() + " - Hercules Studio").c_str()); |
| 824 | #ifndef hFramework |
| 825 | if (mRecovery) |
| 826 | { |
| 827 | // refresh devices list |
| 828 | issueCommand("]DEVLIST=1"); |
| 829 | usleep(500000); |
| 830 | issueCommand("]NEWDEVLIST=1"); |
| 831 | |
| 832 | } |
| 833 | #endif |
| 834 | mRecovery = false; |
| 835 | mSystemTrayIcon->show(); |
| 836 | |
| 837 | if (ui.actionView_32_bit_General_Registers->isChecked()) |
| 838 | this->mGRegisters32->setActive(true); |
| 839 | if (ui.actionView_32_bit_Control_Registers->isChecked()) |
| 840 | this->mCRegisters32->setActive(true); |
| 841 | if (ui.actionView_32_bit_Floating_Point_Registers->isChecked()) |
| 842 | this->mFRegisters32->setActive(true); |
| 843 | if (ui.actionView_32_bit_Access_Registers->isChecked()) |
| 844 | this->mARegisters32->setActive(true); |
| 845 | if (ui.actionView_64_bit_General_Registers->isChecked()) |
| 846 | this->mGRegisters64->setActive(true); |
| 847 | if (ui.actionView_64_bit_Control_Registers->isChecked()) |
| 848 | this->mCRegisters64->setActive(true); |
| 849 | if (ui.actionView_64_bit_Floating_Point_Registers->isChecked()) |
| 850 | this->mFRegisters64->setActive(true); |
| 851 | } |
| 852 | |
| 853 | void MainWindow::powerOff() |
| 854 | { |
| 855 | if (!mHerculesActive) return ; |
| 856 | mMinimizeOnClose=false; |
| 857 | printf("Goodbye!\n"); |
| 858 | mHerculesExecutor->issueCommand("quit\n"); |
| 859 | #ifndef hFramework |
| 860 | usleep(100000); // TODO32 |
| 861 | #endif |
| 862 | mDevicesPane->clear(); |
| 863 | // mMainPanel->setDormant(); |
| 864 | mPsw->setDormant(); |
| 865 | mCommandLine->save(); |
| 866 | } |
| 867 | |
| 868 | void MainWindow::load() |
| 869 | { |
| 870 | if (!mHerculesActive) return; |
| 871 | if (Preferences::getInstance().theme()==Preferences::Modern) // modern theme does not have dials |
| 872 | { |
| 873 | loadCommand(); // present menu etc. |
| 874 | return; |
| 875 | } |
| 876 | int addr = mMainPanel->getLoadAddress(); |
| 877 | hOutDebug(1, "going to load " << addr); |
| 878 | mHerculesExecutor->issueFormattedCommand("IPL %X\n",addr); |
| 879 | mIplDevno.setNum(addr,16); |
| 880 | mLogWindow->setIpled(true); |
| 881 | } |
| 882 | |
| 883 | void MainWindow::loadCommand() |
| 884 | { |
| 885 | if (!mHerculesActive) return; |
| 886 | int lpIndex = -1; |
| 887 | if (mAdHocLoadParm == "") |
| 888 | { |
| 889 | hOutDebug(5, "lastSYS=" << mConfigFile->getLastSys()) |
| 890 | for (int i=0; i<= mConfigFile->getLastSys(); i++) |
| 891 | { |
| 892 | if ((*mConfigFile)[i]->getLowercaseToken(0) == "loadparm") |
| 893 | { |
| 894 | lpIndex = i; |
| 895 | mAdHocLoadParm = (*mConfigFile)[i]->getToken(1).c_str(); |
| 896 | break; |
| 897 | } |
| 898 | else hOutDebug(5,"skipping " << i << ": " << (*mConfigFile)[i]->getLowercaseToken(0)); |
| 899 | } |
| 900 | if (lpIndex == -1) mAdHocLoadParm = "......"; |
| 901 | } |
| 902 | if (mIplDevno.isEmpty()) |
| 903 | mIplDevno = "0000"; |
| 904 | if (Preferences::getInstance().theme() == Preferences::Classic) |
| 905 | mIplDevno = QString::number(mMainPanel->getLoadAddress(),16); |
| 906 | |
| 907 | IplConfig * iplConfig = new IplConfig(mIplDevno,mAdHocLoadParm, this); |
| 908 | |
| 909 | int i = iplConfig->exec() ; |
| 910 | if (i == QDialog::Accepted) |
| 911 | { |
| 912 | QString loadCommand = "LOADPARM " + mAdHocLoadParm; |
| 913 | issueCommand(loadCommand.toStdString()); |
| 914 | mMainPanel->setLoadAddress(mIplDevno.toStdString().c_str()); |
| 915 | std::string iplCommand = "IPL " + mIplDevno.toStdString(); |
| 916 | issueCommand(iplCommand); |
| 917 | mLogWindow->setIpled(true); |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | void MainWindow::extInterrupt() |
| 922 | { |
| 923 | if (!mHerculesActive) return; |
| 924 | hOutDebug(1, "going to externally interrupt "); |
| 925 | mHerculesExecutor->issueCommand("ext\n"); |
| 926 | return; |
| 927 | } |
| 928 | |
| 929 | void MainWindow::devInterrupt() |
| 930 | { |
| 931 | if (!mHerculesActive) return; |
| 932 | int addr = mMainPanel->getLoadAddress(); |
| 933 | hOutDebug(1, "going to interrupt " << addr); |
| 934 | mHerculesExecutor->issueFormattedCommand("I %X\n", addr); |
| 935 | } |
| 936 | |
| 937 | void MainWindow::restart() |
| 938 | { |
| 939 | if (mHerculesActive) |
| 940 | mHerculesExecutor->issueCommand("restart\n"); |
| 941 | } |
| 942 | |
| 943 | void MainWindow::store() |
| 944 | { |
| 945 | if (mHerculesActive) |
| 946 | mHerculesExecutor->issueCommand("store\n"); |
| 947 | } |
| 948 | |
| 949 | void MainWindow::start() |
| 950 | { |
| 951 | if (mHerculesActive) |
| 952 | mHerculesExecutor->issueCommand("startall\n"); |
| 953 | } |
| 954 | |
| 955 | void MainWindow::stop() |
| 956 | { |
| 957 | if (mHerculesActive) |
| 958 | { |
| 959 | if (mMainPanel->isStopped()) // this is already done |
| 960 | mHerculesExecutor->issueCommand("stopall\n"); |
| 961 | else |
| 962 | mHerculesExecutor->issueCommand("startall\n"); |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | void MainWindow::dasdinit() |
| 967 | { |
| 968 | DasdInit * dasdinit = new DasdInit(this); |
| 969 | connect(dasdinit, SIGNAL(output(QByteArray)), this , SLOT(writeToLog(QByteArray))); |
| 970 | dasdinit->exec(); |
| 971 | } |
| 972 | |
| 973 | void MainWindow::dasdload() |
| 974 | { |
| 975 | DasdLoad * dasdload = new DasdLoad(this); |
| 976 | connect(dasdload, SIGNAL(output(QByteArray)), this , SLOT(writeToLog(QByteArray))); |
| 977 | dasdload->exec(); |
| 978 | } |
| 979 | |
| 980 | void MainWindow::dasdisup() |
| 981 | { |
| 982 | DasdIsup * dasdisup = new DasdIsup(this); |
| 983 | connect(dasdisup, SIGNAL(output(QByteArray)), this , SLOT(writeToLog(QByteArray))); |
| 984 | dasdisup->exec(); |
| 985 | } |
| 986 | |
| 987 | void MainWindow::dasdls() |
| 988 | { |
| 989 | Dasdls * dasdls = new Dasdls(this); |
| 990 | connect(dasdls, SIGNAL(output(QByteArray)), this , SLOT(writeToLog(QByteArray))); |
| 991 | dasdls->exec(); |
| 992 | } |
| 993 | |
| 994 | void MainWindow::dasdcat() |
| 995 | { |
| 996 | Dasdcat * dasdcat = new Dasdcat(this); |
| 997 | connect(dasdcat, SIGNAL(output(QByteArray)), this , SLOT(writeToLog(QByteArray))); |
| 998 | dasdcat->exec(); |
| 999 | } |
| 1000 | |
| 1001 | void MainWindow::dasdconv() |
| 1002 | { |
| 1003 | Dasdconv * dasdconv = new Dasdconv(this); |
| 1004 | connect(dasdconv, SIGNAL(output(QByteArray)), this , SLOT(writeToLog(QByteArray))); |
| 1005 | dasdconv->exec(); |
| 1006 | } |
| 1007 | |
| 1008 | void MainWindow::dasdcopy() |
| 1009 | { |
| 1010 | Dasdcopy * dasdcopy = new Dasdcopy(this); |
| 1011 | connect(dasdcopy, SIGNAL(output(QByteArray)), this , SLOT(writeToLog(QByteArray))); |
| 1012 | dasdcopy->exec(); |
| 1013 | } |
| 1014 | |
| 1015 | void MainWindow::tapemap() |
| 1016 | { |
| 1017 | TapeMap * tapemap = new TapeMap(this); |
| 1018 | connect(tapemap, SIGNAL(output(QByteArray)), this , SLOT(writeToLog(QByteArray))); |
| 1019 | tapemap->exec(); |
| 1020 | } |
| 1021 | |
| 1022 | void MainWindow::tapecopy() |
| 1023 | { |
| 1024 | TapeCopy * tapecopy = new TapeCopy(this); |
| 1025 | connect(tapecopy, SIGNAL(output(QByteArray)), this , SLOT(writeToLog(QByteArray))); |
| 1026 | tapecopy->exec(); |
| 1027 | } |
| 1028 | |
| 1029 | void MainWindow::tapesplit() |
| 1030 | { |
| 1031 | TapeSplt * tapesplit = new TapeSplt(this); |
| 1032 | connect(tapesplit, SIGNAL(output(QByteArray)), this , SLOT(writeToLog(QByteArray))); |
| 1033 | tapesplit->exec(); |
| 1034 | } |
| 1035 | |
| 1036 | void MainWindow::hetinit() |
| 1037 | { |
| 1038 | HetInit * hetinit = new HetInit(this); |
| 1039 | connect(hetinit, SIGNAL(output(QByteArray)), this , SLOT(writeToLog(QByteArray))); |
| 1040 | hetinit->exec(); |
| 1041 | } |
| 1042 | |
| 1043 | void MainWindow::hetget() |
| 1044 | { |
| 1045 | HetGet * hetget = new HetGet(this); |
| 1046 | connect(hetget, SIGNAL(output(QByteArray)), this , SLOT(writeToLog(QByteArray))); |
| 1047 | hetget->exec(); |
| 1048 | } |
| 1049 | |
| 1050 | void MainWindow::hetupd() |
| 1051 | { |
| 1052 | HetUpd * hetupd = new HetUpd(this); |
| 1053 | connect(hetupd, SIGNAL(output(QByteArray)), this , SLOT(writeToLog(QByteArray))); |
| 1054 | hetupd->exec(); |
| 1055 | } |
| 1056 | |
| 1057 | void MainWindow::hetmap() |
| 1058 | { |
| 1059 | HetMap * hetmap = new HetMap(this); |
| 1060 | connect(hetmap, SIGNAL(output(QByteArray)), this , SLOT(writeToLog(QByteArray))); |
| 1061 | hetmap->exec(); |
| 1062 | } |
| 1063 | |
| 1064 | void MainWindow::printer() |
| 1065 | { |
| 1066 | if (mPrinterDialog == NULL) |
| 1067 | mPrinterDialog = new PrinterDialog(0); |
| 1068 | mPrinterDialog->show(); |
| 1069 | connect(mPrinterDialog, SIGNAL(destroyed()), this, SLOT(printerFinished())); |
| 1070 | } |
| 1071 | |
| 1072 | void MainWindow::printerFinished() |
| 1073 | { |
| 1074 | mPrinterDialog = NULL; |
| 1075 | } |
| 1076 | |
| 1077 | void MainWindow::stationery() |
| 1078 | { |
| 1079 | StationeryDialog* stationeryDialog = new StationeryDialog(this); |
| 1080 | stationeryDialog->exec(); |
| 1081 | } |
| 1082 | |
| 1083 | void MainWindow::decolation() |
| 1084 | { |
| 1085 | DecolationDialog* dialog = new DecolationDialog(this); |
| 1086 | dialog->exec(); |
| 1087 | } |
| 1088 | |
| 1089 | void MainWindow::herculesEndedSlot() |
| 1090 | { |
| 1091 | std::cerr << "############ ended ##############" << std::endl; |
| 1092 | mLogWindow->setIpled(false); |
| 1093 | mLogWindow->writeToFile(PlainLogWidget::Shutdown); |
| 1094 | mLogRunner->terminate(); |
| 1095 | mStatusRunner->terminate(); |
| 1096 | mWatchdog->terminate(); |
| 1097 | if (mWatchdog != NULL) delete mWatchdog; |
| 1098 | mWatchdog = NULL; |
| 1099 | mHerculesActive = false; |
| 1100 | mCommandLine->setReadOnly(true); |
| 1101 | mHerculesExecutor = NULL; |
| 1102 | mMainPanel->setDormant(); |
| 1103 | mPsw->setDormant(); |
| 1104 | ui.menuFile->setEnabled(true); |
| 1105 | mSystemTrayIcon->setVisible(false); |
| 1106 | setVisible(true); |
| 1107 | mMinimizeOnClose=false; |
| 1108 | testGui(); |
| 1109 | } |
| 1110 | |
| 1111 | void MainWindow::helpAbout() |
| 1112 | { |
| 1113 | HelpAbout *ha = new HelpAbout(this); |
| 1114 | ha->exec(); |
| 1115 | } |
| 1116 | |
| 1117 | void MainWindow::systrayHint() |
| 1118 | { |
| 1119 | if (!mSystrayHintEjected) |
| 1120 | { |
| 1121 | mSystemTrayIcon->showMessage("Hercules is still active","Click the Hercules icon to restore the main window",QSystemTrayIcon::Information,5000); |
| 1122 | mSystemTrayIcon->setToolTip("Click on this icon to restore the main window"); |
| 1123 | mSystrayHintEjected = true; |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | void MainWindow::closeEvent(QCloseEvent *event) |
| 1128 | { |
| 1129 | if (mHerculesActive && mMinimizeOnClose) |
| 1130 | { |
| 1131 | hOutDebug(5,"systray"); |
| 1132 | mSystemTrayIcon->setVisible(true); |
| 1133 | systrayHint(); |
| 1134 | setVisible(false); |
| 1135 | mSystemTrayIcon->contextMenu()->actions().at(0)->setText("&Restore"); |
| 1136 | |
| 1137 | event->ignore(); |
| 1138 | } |
| 1139 | else |
| 1140 | { |
| 1141 | hOutDebug(5,"Close"); |
| 1142 | |
| 1143 | if (mHerculesActive) |
| 1144 | { |
| 1145 | if( QMessageBox::warning(this,"Hercules Is Still Running", |
| 1146 | "\nPress OK - To Wait Until Hercules Finishes Running\n" |
| 1147 | "Or\n" |
| 1148 | "Press Abort - To Force Exit", |
| 1149 | QMessageBox::Ok, QMessageBox::Abort) != QMessageBox::Abort) |
| 1150 | { |
| 1151 | event->ignore(); |
| 1152 | QTimer::singleShot(5000, this, SLOT(tryAbort())); |
| 1153 | } |
| 1154 | else hOutDebug(5,"abort"); |
| 1155 | } |
| 1156 | |
| 1157 | if (mPrinterDialog != NULL) |
| 1158 | { |
| 1159 | if (mPrinterDialog->isConnected()) |
| 1160 | { |
| 1161 | if( QMessageBox::warning(this,"Printer Is Still Connected", |
| 1162 | "Press Close - To Close The Printer\n" |
| 1163 | "Or\n" |
| 1164 | "Press Cancel - To Return", |
| 1165 | QMessageBox::Cancel, QMessageBox::Close) == QMessageBox::Cancel) |
| 1166 | { |
| 1167 | event->ignore(); |
| 1168 | } |
| 1169 | else |
| 1170 | { |
| 1171 | mPrinterDialog->close(); |
| 1172 | delete mPrinterDialog; |
| 1173 | } |
| 1174 | } |
| 1175 | else |
| 1176 | { |
| 1177 | mPrinterDialog->close(); |
| 1178 | delete mPrinterDialog; |
| 1179 | } |
| 1180 | } |
| 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | void MainWindow::tryAbort() |
| 1185 | { |
| 1186 | hOutDebug(5,"tryAbort"); |
| 1187 | setVisible(true); |
| 1188 | close(); |
| 1189 | } |
| 1190 | |
| 1191 | void MainWindow::systrayClick(QSystemTrayIcon::ActivationReason) |
| 1192 | { |
| 1193 | hideRestore(); |
| 1194 | } |
| 1195 | |
| 1196 | void MainWindow::hideRestore() |
| 1197 | { |
| 1198 | if (isVisible()) |
| 1199 | { |
| 1200 | setVisible(false); |
| 1201 | systrayHint(); |
| 1202 | mSystemTrayIcon->contextMenu()->actions().at(0)->setText("Restore"); |
| 1203 | |
| 1204 | } |
| 1205 | else |
| 1206 | { |
| 1207 | setVisible(true); |
| 1208 | mSystemTrayIcon->contextMenu()->actions().at(0)->setText("Hide"); |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | void MainWindow::keyPressEvent(QKeyEvent * event) |
| 1213 | { |
| 1214 | hOutDebug(4,"key:" << event->key() << " " << (event->key() == Qt::Key_Up)); |
| 1215 | QMainWindow::keyPressEvent(event); |
| 1216 | if (!mCommandLine->hasFocus()) |
| 1217 | mCommandLine->setFocus(); |
| 1218 | } |
| 1219 | |
| 1220 | void MainWindow::restartDevices() |
| 1221 | { |
| 1222 | hOutDebug(3,"MainWindow::restartRecovery"); |
| 1223 | mDevicesRecovery = true; |
| 1224 | issueCommand("]DEVLIST=1"); |
| 1225 | #ifndef hFramework |
| 1226 | usleep(500000); // TODO32 |
| 1227 | #endif |
| 1228 | issueCommand("]NEWDEVLIST=1"); |
| 1229 | } |
| 1230 | |
| 1231 | bool MainWindow::issueCommand(const std::string& command) |
| 1232 | { |
| 1233 | QString qCommand = command.c_str(); |
| 1234 | if (mHerculesActive) |
| 1235 | { |
| 1236 | mHerculesExecutor->issueFormattedCommand("%s\n", command.c_str()); |
| 1237 | setIpled(qCommand); |
| 1238 | } |
| 1239 | |
| 1240 | hOutDebug(2,"issue command:" << command); |
| 1241 | return true; |
| 1242 | } |
| 1243 | |
| 1244 | void MainWindow::testGui() |
| 1245 | { |
| 1246 | if ( !mStatusReceived && |
| 1247 | (mLogWindow->toPlainText().indexOf("No External GUI support") > 0) ) |
| 1248 | { |
| 1249 | QMessageBox::critical(this,"No GUI Support", |
| 1250 | "The Hercules program that you are running does not support external GUI\n" |
| 1251 | "Please obtain a module that was built with GUI support", |
| 1252 | QMessageBox::Ok); |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | void MainWindow::setIpled(QString command) |
| 1257 | { |
| 1258 | if (mHerculesActive) |
| 1259 | { |
| 1260 | if (command.toLower().leftJustified(4).startsWith("ipl ")) |
| 1261 | { |
| 1262 | mLogWindow->setIpled(true); |
| 1263 | } |
| 1264 | else if (command.toLower().leftJustified(5).startsWith("quit ")) |
| 1265 | { |
| 1266 | mLogWindow->setIpled(false); |
| 1267 | } |
| 1268 | |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | void MainWindow::setDarkBackground(bool dark) |
| 1273 | { |
| 1274 | if (dark) |
| 1275 | { |
| 1276 | QFile file(":/icons/darkorange.css"); |
| 1277 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) |
| 1278 | return; |
| 1279 | QByteArray ss = file.readAll(); |
| 1280 | setStyleSheet(ss); |
| 1281 | } |
| 1282 | else |
| 1283 | setStyleSheet(""); |
| 1284 | } |