void MainWindow::initMenu() { KStandardAction::preferences(this, SLOT(onPreferences()), actionCollection()); m_menu.m_newAction = new QAction(QIcon::fromTheme("file_new"), i18n("&New game"), this); actionCollection()->setDefaultShortcut(m_menu.m_newAction, Qt::CTRL + Qt::Key_N); connect(m_menu.m_newAction, SIGNAL(triggered(bool)), this, SLOT(onNewGame())); actionCollection()->addAction("NewGame", m_menu.m_newAction); m_menu.m_endAction = actionCollection()->addAction("EndGame", this, SLOT(endGame())); m_menu.m_endAction->setIcon(QIcon::fromTheme("window-close")); m_menu.m_endAction->setText(i18n("&End game")); actionCollection()->setDefaultShortcut(m_menu.m_endAction, Qt::CTRL + Qt::Key_E); m_menu.m_endAction->setEnabled(false); m_menu.m_quitAction = actionCollection()->addAction("Quit", this, SLOT(close())); m_menu.m_quitAction->setIcon(QIcon::fromTheme("exit")); m_menu.m_quitAction->setText(i18n("&Quit")); actionCollection()->setDefaultShortcut(m_menu.m_quitAction, Qt::CTRL + Qt::Key_Q); m_menu.m_undoAction = actionCollection()->addAction("UndoGame", this); m_menu.m_undoAction->setIcon(QIcon::fromTheme("undo")); m_menu.m_undoAction->setText(i18n("&Undo")); m_menu.m_undoAction->setEnabled(false); actionCollection()->setDefaultShortcut(m_menu.m_undoAction, Qt::CTRL + Qt::Key_Z); }
void MainWindow::onFormats() { if ( hosts.isEmpty() || ccliveVersion.isEmpty() ) { critCcliveNotSpecified(this); onPreferences(); return; } format->exec(); format->saveCurrent(); format->writeSettings(); }
void SystemMenu::rebuildMenu(bool dockHiding) { if (menu()) { menu()->clear(); } QMenu *menu = new QMenu(this); about = new QAction("About this computer", this); menu->addAction(about); connect(about, SIGNAL(triggered()), this, SLOT(onAbout())); /* TODO: Removed for now until I found clear way for managing software on different distros QAction *software = new QAction("Software management ...", this); menu->addAction(software); */ menu->addSeparator(); QAction *pref = new QAction("System preferences ...", this); menu->addAction(pref); connect(pref, SIGNAL(triggered()), this, SLOT(onPreferences())); menu->addSeparator(); if (dockHiding) { adock_on = new QAction("Turn Hiding Off", this); } else { int s = app->dock->dockState; if (s == Dockbar::Normal || s == Dockbar::Showing || s == Dockbar::AboutToShow) { adock_on = new QAction("Turn Hiding On", this); } else if (s == Dockbar::Hidden || s == Dockbar::Hiding) { adock_on = new QAction("Turn Hiding Off", this); } } //QAction *adock_magn = new QAction("Turn Magnification On", this); adock_pref = new QAction("Dock Preferences ...", this); QMenu *dock_menu = menu->addMenu("Dock"); dock_menu->addAction(adock_on); connect(adock_on, SIGNAL(triggered()), this, SLOT(onShowHideDock())); connect(adock_pref, SIGNAL(triggered()), this, SLOT(onDockPref())); //dock_menu->addAction(adock_magn); dock_menu->addSeparator(); dock_menu->addAction(adock_pref); menu->addSeparator(); /* TODO: Removed for now until I implement the features QAction *force_quit = new QAction("Force Quit ...", this); menu->addAction(force_quit); menu->addSeparator(); */ sleep = new QAction("Sleep", this); menu->addAction(sleep); connect(sleep, SIGNAL(triggered()), this, SLOT(onSleep())); restart = new QAction("Restart ...", this); menu->addAction(restart); connect(restart, SIGNAL(triggered()), this, SLOT(onRestart())); shutdown = new QAction("Shutdown ...", this); menu->addAction(shutdown); connect(shutdown, SIGNAL(triggered()), this, SLOT(onShutdown())); menu->addSeparator(); logout = new QAction("Logout ...", this); menu->addAction(logout); connect(logout, SIGNAL(triggered()), this, SLOT(onLogout())); setMenu(menu); connect(this, SIGNAL(clicked()), this, SLOT(showMenu())); }
MainWindow::MainWindow(MainController& ctrl, QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) , mController(ctrl) , mCurrentBodyWidget(0) , mIsTerminated(false) { irr::IrrlichtDevice* device = 0; ui->setupUi(this); /* Configure Irrlicht */ mIrrlichtWidget = new IrrlichtWidget(mController.getConfiguration().getGraphicsConfiguration(), ui->irrlichtContainer); ui->irrlichtLayout->addWidget(mIrrlichtWidget); device = mIrrlichtWidget->getIrrlichtDevice(); Engine::PlanetariumEngine* engine = mController.createEngine(device); mIrrlichtWidget->setEngine(engine); onNewCamera(); /* Add label to the status bar */ mStatusLabel = new QLabel(ui->statusBar); ui->statusBar->addWidget(mStatusLabel); /* Set status bar message */ mStatusLabel->setText(tr("Uninitialized")); /* Set initial values */ ui->speedSpin->setValue(ctrl.getSpeed()); ui->stepSpin->setValue(ctrl.getStep()); ui->scaleSpinBox->setValue(ctrl.getEngine()->getScale()); /* Connect GUI to controller */ // menu actions connect(ui->quitAction, SIGNAL(triggered()), this, SLOT(close())); connect(ui->actionPreferences, SIGNAL(triggered()), this, SLOT(onPreferences())); connect(ui->openAction, SIGNAL(triggered()), this, SLOT(onOpen())); connect(ui->actionStart, SIGNAL(triggered()), this, SLOT(onPlayTriggered())); connect(ui->actionStop, SIGNAL(triggered()), this, SLOT(onStopTriggered())); // spin buttons connect(ui->speedSpin, SIGNAL(valueChanged(double)), &ctrl, SLOT(setSpeed(double))); connect(ui->stepSpin, SIGNAL(valueChanged(double)), &ctrl, SLOT(setStep(double))); connect(ui->scaleSpinBox, SIGNAL(valueChanged(double)), ctrl.getEngine(), SLOT(setScale(double))); connect(ui->xCamPos, SIGNAL(valueChanged(double)), this, SLOT(onCameraPositionChanged(double))); connect(ui->yCamPos, SIGNAL(valueChanged(double)), this, SLOT(onCameraPositionChanged(double))); connect(ui->zCamPos, SIGNAL(valueChanged(double)), this, SLOT(onCameraPositionChanged(double))); // control buttons connect(ui->playButton, SIGNAL(clicked()), this, SLOT(onPlayTriggered())); connect(ui->stopButton, SIGNAL(clicked()), this, SLOT(onStopTriggered())); // List connect(ui->objectList, SIGNAL(currentRowChanged(int)), this, SLOT(onListSelectionChanged(int))); /* Connect controller event */ connect(&ctrl, SIGNAL(simulationStateChanged()), this, SLOT(simulationStateChanged())); connect(&ctrl, SIGNAL(model_updated()), this, SLOT(onSimulationUpdate())); connect(engine, SIGNAL(newCamera()), this, SLOT(onNewCamera())); }
void MainWindow::onStart() { if ( ccliveVersion.isEmpty() ) { critCcliveNotSpecified(this); onPreferences(); return; } if (linksList->count() == 0) { onAdd(); if (linksList->count() == 0) return; } QString path = prefs->ccliveEdit->text(); // Check video save directory // cclive has no option for this but we can work around it by // changing the current working directory. QString savedir = prefs->savedirEdit->text(); if (savedir.isEmpty()) { QMessageBox::information(this, QCoreApplication::applicationName(), tr("Please define a directory for downloaded videos.")); onPreferences(); return; } process.setWorkingDirectory(savedir); // Construct cclive/clive args QStringList args; args << "--print-fname" << "--continue"; QString s = prefs->streamEdit->text(); if (!s.isEmpty() && streamBox->isChecked()) { args << QString("--stream-exec=%1").arg(s); args << QString("--stream=%1").arg(streamSpin->value()); } s = prefs->commandEdit->text(); if (!s.isEmpty() && commandBox->isChecked()) { if (!s.endsWith(";")) s += ";"; args << QString("--exec=%1").arg(s); args << QString("--exec-run"); } if (prefs->proxyCombo->currentIndex() == 0) args << "--no-proxy"; else { s = prefs->proxyEdit->text(); if (!s.isEmpty()) args << QString("--proxy=%1").arg(s); } if (prefs->limitBox->checkState()) { int n = prefs->limitSpin->value(); args << QString("--limit-rate=%1").arg(n); } if (prefs->timeoutBox->checkState()) { int n = prefs->timeoutSpin->value(); if (!prefs->socksBox->checkState()) args << QString("--connect-timeout=%1").arg(n); else args << QString("--connect-timeout-socks=%1").arg(n); } QStringList env; if (isCcliveFlag) { s = regexpEdit->text(); if (!s.isEmpty()) args << QString("--regexp=%1").arg(s); s = substEdit->text(); if (!s.isEmpty()) args << QString("--substitute=%1").arg(s); } else { args << "--stderr"; // Set environment variables for clive env << "COLUMNS=80" << "LINES=24" // Term::ReadKey << QString("HOME=%1").arg(QDir::homePath()) // $env{HOME} << "CCLIVE_NO_CONFIG=1"; // cclive 0.5.0+ s = cclassEdit->text(); if (!s.isEmpty()) args << QString("--cclass=%1").arg(s); } s = fnamefmtEdit->text(); if (!s.isEmpty()) args << QString("--filename-format=%1").arg(s); // Check if all video page links are of the same host. QUrl first(linksList->item(0)->text()); bool allSame = true; const register _uint count = linksList->count(); for (register _uint i=0; i<count; ++i) { QUrl url(linksList->item(i)->text()); if (url.host() != first.host()) { allSame = false; break; } } s = "flv"; // Use format dialog setting for the host. if (allSame) s = format->getFormatSetting(first.host()); args << QString("--format=%1").arg(s); for (register _uint i=0; i<count; ++i) args << QString("%1").arg(linksList->item(i)->text()); totalProgressbar->setMaximum(linksList->count()); // Prepare log logEdit->clear(); Util::appendLog(logEdit, "% " +path+ " " +args.join(" ")); // And finally start the process cancelledFlag = false; process.setEnvironment(env); process.setProcessChannelMode(QProcess::MergedChannels); process.start(path,args); }
bool MainWindow::parseCcliveHostsOutput() { hosts.clear(); QString path = prefs->ccliveEdit->text(); if (path.isEmpty()) { QMessageBox::information( this, QCoreApplication::applicationName(), tr("abby requires `clive' or `cclive'. " "Please define path to either executable.") ); onPreferences(); return false; } QProcess proc; proc.setEnvironment(QStringList() << "CCLIVE_NO_CONFIG=1"); proc.setProcessChannelMode(QProcess::MergedChannels); proc.start(path, QStringList() << "--hosts"); format->resetHosts(); if (!proc.waitForFinished()) { critCcliveProcessFailed(this, proc.errorString() ); return false; } else { const QString output = QString::fromLocal8Bit( proc.readAll() ); const int exitCode = proc.exitCode(); if (exitCode == 0) { QStringList lst = output.split("\n", QString::SkipEmptyParts); lst.removeLast(); // The note line. const register _uint size = lst.size(); for (register _uint i=0; i<size; ++i) { QString ln = lst[i].remove("\r"); QStringList tmp = ln.split("\t"); if (!tmp[0].isEmpty() && !tmp[1].isEmpty()) hosts[tmp[0]] = tmp[1]; } format->parseHosts(hosts); } else { critCcliveExitedWithError(this, exitCode, output); return false; } } return true; }