qonsole.cpp

Go to the documentation of this file.
00001 #include    "qonsole.h"
00002 
00003 #include    <QFile>
00004 #include    <QApplication>
00005 #include    <QDateTime>
00006 
00007 
00008 #define     PLUGIN_DIR_UNIX     "/usr/local/BBoB/plugins"
00009 #define     BBOB_HELP_FILE      "help.chm"
00010 #define     BBOB_HELP_HTML      "doc/html/index.html"
00011 
00012 
00013 /*! \file qonsole.cpp
00014     \brief The main BBoB application.
00015 
00016     Graphical interface to BCore.
00017 */
00018 
00019 
00020 /** Customizing of code for MainWindow.ui -
00021  ** Creates BCore class, makes plugin submenu, loads plugins through BCore, and restores dock settings.
00022  **/
00023 Qonsole::Qonsole(QSplashScreen* splash, bool Debug, bool BootUser, QString BootFile, bool BootPluginSettings, QString args,
00024                  QWidget * parent, Qt::WFlags f)
00025     : QMainWindow(parent, f)
00026 {
00027     setupUi(this);
00028 
00029     // Add a clock toolbar
00030     time = new QDateTimeEdit(this);
00031     time->setReadOnly(true);
00032     time->setFrame(false);
00033     time->setButtonSymbols(QAbstractSpinBox::NoButtons);
00034     time->setFocusPolicy(Qt::NoFocus);
00035     time->setEnabled(false);
00036     time->setDisplayFormat("hh:mm a");
00037     time->setLayoutDirection(Qt::LeftToRight);
00038 
00039     QToolBar* clockBar = new QToolBar("Clock", this );
00040     clockBar->setObjectName("ClockBar");
00041     addToolBar(Qt::TopToolBarArea, clockBar);
00042     clockBar->addWidget(time);
00043     clockBar->setLayoutDirection(Qt::RightToLeft);
00044 
00045     startTimer(2000);
00046 
00047     // Setup desk storage
00048     Desks << "" << "" << "" << "" << "" << "" << "" << "" << "" << "" << "" << "" << "";
00049 
00050     // Add buttons to desk toolbar
00051     QActionGroup* actGroup = new QActionGroup(DeskBar);
00052     actGroup->setExclusive(true);
00053 
00054     Desk = 1;
00055     QAction* a;
00056     for(int x = 1; x <= 12; x++)
00057     {
00058         QString name = "Desk " +  QString::number(x);
00059         a = DeskBar->addAction(name, this, SLOT(ChangeDesk(bool)));
00060         a->setCheckable(true);
00061         if (x == 1)
00062             a->setChecked(true);
00063         actGroup->addAction(a);
00064         QString key = "F" + QString::number(x);
00065         QList<QKeySequence> keys;
00066         keys << QKeySequence(key);
00067         a->setShortcuts(keys);
00068         a->setToolTip("Shortcut : " + key);
00069     }
00070 
00071 
00072     // setup debug button on statusbar
00073     if (Debug)
00074     {
00075         debugIcon.addPixmap(style()->standardPixmap(QStyle::SP_MessageBoxInformation), QIcon::Normal, QIcon::On);
00076         QPushButton* debugButton = new QPushButton();
00077         debugButton->setIcon(debugIcon);
00078         debugButton->setToolTip("Open the debug text window");
00079         debugButton->setFlat(true);
00080         debugButton->setIconSize(QSize(15,15));
00081         statusBar()->addPermanentWidget(debugButton);
00082 
00083         DebugWindow = new DebugDialog("", this);
00084         connect(debugButton, SIGNAL(clicked()), this, SLOT(showDebugWindow()));
00085     }
00086     else
00087         statusBar()->hide();
00088 
00089     QFile file;
00090 
00091     // Start core
00092     bcore = new BCore();
00093     bcore->Args = args;
00094 
00095     connect(bcore, SIGNAL(StatusBar(QString, int)), this->statusBar(), SLOT(showMessage(QString, int)));
00096 
00097     // load menus when core loads plugins
00098     connect(bcore, SIGNAL(newPlugin(QObject*)), this, SLOT(populateMenus(QObject*)));
00099 
00100     // Load settings required for functions below
00101     LoadForStartup();
00102 
00103 #ifdef WIN32
00104     assistantClient = new QAssistantClient("hh", this);
00105 #endif
00106 #ifdef unix
00107     assistantClient = new QAssistantClient("", this);
00108 #endif
00109 
00110     // menu option for aboutQt window.
00111     connect(helpAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
00112 
00113     // show dock when plugin sends one
00114     connect(bcore, SIGNAL(newDock(QDockWidget*)), this, SLOT(addDock(QDockWidget*)));
00115 
00116     // add config tab when plugin sends one
00117     connect(bcore, SIGNAL(newConfigTab(QWidget*)), this, SLOT(addConfigTab(QWidget*)));
00118 
00119     // create submenu for plugins
00120     plugSubMenu = new QMenu;
00121     plugSubMenu->setTitle( "Plugin Menus" );
00122     pluginsMenu->addMenu(plugSubMenu);
00123 
00124     // Initialize, load plugin list, and open docks that were saved
00125     bcore->init(splash);
00126     bcore->loadCues(splash);
00127 
00128     // Load module connections, must be after bcore->init()
00129     bcore->loadConnections();
00130 
00131     // Tabs for ConfigTabs
00132     Config_Cues* ConfigCues = new Config_Cues(bcore);
00133     addConfigTab(ConfigCues, true);
00134 
00135     Config_Groups* ConfigGroups = new Config_Groups();
00136     addConfigTab(ConfigGroups, true);
00137 
00138     Config_Portmap* ConfigPortmap = new Config_Portmap(bcore);
00139     addConfigTab(ConfigPortmap, true);
00140 
00141     // Load Desk configurations
00142     loadDesks();
00143 
00144     // Done loading
00145     //restoreState( bcore->settings->getValue("Qonsole", "WindowState", "").toByteArray());
00146     statusBar()->showMessage( QString("Ready."), 20000);
00147 }
00148 
00149 void Qonsole::ChangeDesk(bool checked)
00150 {
00151     QAction *clicked = qobject_cast<QAction*>(sender());
00152     int i = clicked->text().remove("Desk ").toInt();
00153     if (i > 0 & i < 13)
00154     {
00155         qDebug("Change Desk : %i", i);
00156         Desks.replace(Desk, saveState());
00157         Desk = i;
00158         restoreState(Desks.at(Desk));
00159     }
00160 
00161 }
00162 
00163 void Qonsole::timerEvent(QTimerEvent *event)
00164 {
00165     time->setDateTime( QDateTime::currentDateTime() );
00166 }
00167 
00168 
00169 /** Loads settings through BCore -
00170  ** Shows last boot time, sets new boot time, and restores window geometry.
00171  **/
00172 void Qonsole::LoadForStartup()
00173 {
00174     // create configuration dock
00175     ConfigTabs = new QTabWidget();
00176     ConfigDock = new QDockWidget("Configuration");
00177     ConfigDock->setWidget(ConfigTabs);
00178     ConfigDock->setObjectName("Configuration"); // Needed to save state
00179     ConfigDock->setAllowedAreas(Qt::AllDockWidgetAreas);
00180     addDockWidget(Qt::BottomDockWidgetArea, ConfigDock );
00181     ConfigToggle = ConfigDock->toggleViewAction();
00182 
00183     // connect menu to dock
00184     ConfigDock->setVisible(false);
00185     editConfig->setCheckable(true);
00186     editConfig->setChecked(false);
00187     connect(editConfig, SIGNAL(triggered(bool)), ConfigDock, SLOT(setVisible(bool)));
00188     connect(ConfigToggle, SIGNAL(toggled(bool)), editConfig, SLOT(setChecked(bool)));
00189 
00190     // Initialize BCoreSettings for this app
00191     bcore->settings = new BBoB_Settings("Qonsole");
00192     qDebug("Last Boot : " + bcore->settings->getValue("Qonsole", "LastBoot", "Last boot time error.").toByteArray() );
00193     bcore->settings->setValue("Qonsole", "LastBoot", QDateTime::currentDateTime().toString( Qt::TextDate ) );
00194 
00195     // Initialize Cue Settings from app settings
00196     bcore->cueSettings = new BBoB_Settings( bcore->settings->getValue("Qonsole", "CueList", "QonsoleCues").toString() );
00197 
00198     // Initialize Connection Settings from app settings
00199     bcore->connectionSettings = new BBoB_Settings( bcore->settings->getValue("Qonsole", "ConnectionList", "QonsoleConnections").toString() );
00200 
00201     Desk = bcore->settings->getValue("Qonsole", "ActiveDesk", 1).toInt();
00202 
00203     restoreGeometry( bcore->settings->getValue("Qonsole", "WindowGeometry", "").toByteArray());
00204 }
00205 
00206 /** Saves settings through BCore -
00207  ** Saves window geometry and dock states, then calls savePluginSettings.
00208  **/
00209 void Qonsole::SaveSettings()
00210 {
00211     qDebug("Qonsole-> SaveSettings()");
00212 
00213     saveDesks();
00214     bcore->settings->setValue("Qonsole", "ActiveDesk", Desk );
00215     bcore->settings->setValue("Qonsole", "WindowGeometry", saveGeometry() );
00216     bcore->settings->setValue("Qonsole", "CueList", bcore->cueSettings->Program);
00217     bcore->settings->setValue("Qonsole", "ConnectionList", bcore->connectionSettings->Program);
00218     bcore->savePluginSettings();
00219     bcore->saveCues();
00220     bcore->saveConnections();
00221 
00222     qDebug("Qonsole-> Settings Saved");
00223     bcore->settings->Sync();
00224     bcore->cueSettings->Sync();
00225 }
00226 
00227 
00228 void Qonsole::loadDesks()
00229 {
00230     Desks.replace(1, bcore->settings->getValue("Desks", "Desk 1", "" ).toByteArray());
00231     Desks.replace(2, bcore->settings->getValue("Desks", "Desk 2", "" ).toByteArray());
00232     Desks.replace(3, bcore->settings->getValue("Desks", "Desk 3", "" ).toByteArray());
00233     Desks.replace(4, bcore->settings->getValue("Desks", "Desk 4", "" ).toByteArray());
00234     Desks.replace(5, bcore->settings->getValue("Desks", "Desk 5", "" ).toByteArray());
00235     Desks.replace(6, bcore->settings->getValue("Desks", "Desk 6", "" ).toByteArray());
00236     Desks.replace(7, bcore->settings->getValue("Desks", "Desk 7", "" ).toByteArray());
00237     Desks.replace(8, bcore->settings->getValue("Desks", "Desk 8", "" ).toByteArray());
00238     Desks.replace(9, bcore->settings->getValue("Desks", "Desk 9", "" ).toByteArray());
00239     Desks.replace(10, bcore->settings->getValue("Desks", "Desk 10", "" ).toByteArray());
00240     Desks.replace(11, bcore->settings->getValue("Desks", "Desk 11", "" ).toByteArray());
00241     Desks.replace(12, bcore->settings->getValue("Desks", "Desk 12", "" ).toByteArray());
00242 }
00243 
00244 
00245 void Qonsole::saveDesks()
00246 {
00247     bcore->settings->setValue("Desks", "Desk 1", Desks.at(1) );
00248     bcore->settings->setValue("Desks", "Desk 2", Desks.at(2) );
00249     bcore->settings->setValue("Desks", "Desk 3", Desks.at(3) );
00250     bcore->settings->setValue("Desks", "Desk 4", Desks.at(4) );
00251     bcore->settings->setValue("Desks", "Desk 5", Desks.at(5) );
00252     bcore->settings->setValue("Desks", "Desk 6", Desks.at(6) );
00253     bcore->settings->setValue("Desks", "Desk 7", Desks.at(7) );
00254     bcore->settings->setValue("Desks", "Desk 8", Desks.at(8) );
00255     bcore->settings->setValue("Desks", "Desk 9", Desks.at(9) );
00256     bcore->settings->setValue("Desks", "Desk 10", Desks.at(10) );
00257     bcore->settings->setValue("Desks", "Desk 11", Desks.at(11) );
00258     bcore->settings->setValue("Desks", "Desk 12", Desks.at(12) );
00259 
00260 }
00261 
00262 /** Save settings and exit main application
00263  **/
00264 void Qonsole::SaveExit()
00265 {
00266     SaveSettings();
00267     qDebug("Exit OK");
00268     qApp->quit();
00269 }
00270 
00271 /** Given a plugin, this gets commands and creates a menu or submenu for them.
00272  **/
00273 void Qonsole::populateMenus(QObject *plugin)
00274 {
00275     DisplayInterface *iDisplay = qobject_cast<DisplayInterface *>(plugin);
00276     if (iDisplay)
00277         addToMenu(plugin, iDisplay->commands(), plugSubMenu, SLOT(pluginMenuDisplay()) );
00278 }
00279 
00280 
00281 void Qonsole::addToMenu(QObject *plugin, const QStringList &texts,
00282                            QMenu *menu, const char *member,
00283                            QActionGroup *actionGroup)
00284 {
00285     if ( texts.count() == 1 )
00286     {
00287         QAction *action = new QAction( texts.first().toAscii() , plugin);
00288         connect(action, SIGNAL(triggered()), this, member);
00289         menu->addAction(action);
00290     }
00291     else
00292     {
00293         QMenu* plugMenu = new QMenu;
00294         plugMenu->setTitle( texts.first() );
00295 
00296         QStringList::const_iterator Iter;
00297         for (Iter = texts.constBegin(); Iter != texts.constEnd(); ++Iter)
00298         {
00299             if (Iter == texts.constBegin()) Iter++;
00300             QAction *action = new QAction( (*Iter).toLocal8Bit().constData(), plugin);
00301             connect(action, SIGNAL(triggered()), this, member);
00302             plugMenu->addAction(action);
00303             if (actionGroup) {
00304                 action->setCheckable(true);
00305                 actionGroup->addAction(action);
00306             }
00307         }
00308         menu->addMenu(plugMenu);
00309     }
00310 }
00311 
00312 /** Called from the plugins menu -
00313  ** Gets the dock from a plugin, and adds to application.
00314  **/
00315 void Qonsole::pluginMenuDisplay()
00316 {
00317     QAction *action = qobject_cast<QAction *>(sender());
00318     DisplayInterface *iDisplay = qobject_cast<DisplayInterface *>(action->parent());
00319 
00320     QDockWidget* newDock = iDisplay->getDock( action->text() );
00321 
00322     if ( newDock > 0 )
00323         addDockWidget(Qt::LeftDockWidgetArea, newDock );
00324 }
00325 
00326 /** Given a QDockWidget this sets some needed dock options and adds to MainWindow.
00327  **/
00328 void Qonsole::addDock(QDockWidget* dock)
00329 {
00330     if ( dock > 0 )
00331     {
00332         dock->setFeatures(QDockWidget::AllDockWidgetFeatures);
00333         dock->widget()->setParent(dock);
00334         addDockWidget(Qt::LeftDockWidgetArea, dock );
00335         pluginsMenu->addAction(dock->toggleViewAction());
00336     }
00337 }
00338 
00339 /** Given a QDialog this adds it to ConfigTabs
00340  **/
00341 void Qonsole::addConfigTab(QWidget* tab, bool first)
00342 {
00343     if ( tab > 0 )
00344         if (first)
00345             ConfigTabs->insertTab(0, tab, tab->windowTitle());
00346         else
00347             ConfigTabs->addTab(tab, tab->windowTitle());
00348 }
00349 
00350 
00351 void Qonsole::removeDock(bool state)
00352 {
00353     QDockWidget *dock = qobject_cast< QDockWidget* > ( sender() );
00354 
00355     if ( !dock->isVisible() )
00356         removeDockWidget(dock);
00357 }
00358 
00359 
00360 /** Function for File Menu - New
00361  **/
00362 void Qonsole::on_fileNew_triggered()
00363 {
00364     qWarning("Not implemented yet.");
00365 }
00366 
00367 
00368 /** Function for File Menu - Open
00369  **/
00370 void Qonsole::on_fileOpen_triggered()
00371 {
00372     qWarning("You can select a file, but it won't load yet");
00373 
00374     QString fileName = QFileDialog::getOpenFileName(this,
00375                        tr("Open Config File"), "", tr("INI (*.ini)"));
00376 
00377 }
00378 
00379 
00380 /** Function for File Menu - Save
00381  **/
00382 void Qonsole::on_fileSave_triggered()
00383 {
00384     SaveSettings();
00385 }
00386 
00387 
00388 /** Function for File Menu - SaveAs
00389  **/
00390 void Qonsole::on_fileSaveAs_triggered()
00391 {
00392     qWarning("Not implemented yet.");
00393 }
00394 
00395 
00396 /** Function for File Menu - Print
00397  **/
00398 void Qonsole::on_filePrint_triggered()
00399 {
00400     qWarning("Not implemented yet.");
00401 }
00402 
00403 
00404 /** Function for File Menu - Exit
00405  **/
00406 void Qonsole::on_fileExit_triggered()
00407 {
00408      if (assistantClient)
00409          assistantClient->closeAssistant();
00410 
00411      SaveSettings();
00412      close();
00413 }
00414 
00415 
00416 /** Function for Edit Menu - Undo
00417  **/
00418 void Qonsole::on_editUndo_triggered()
00419 {
00420     qWarning("Not implemented yet.");
00421 }
00422 
00423 
00424 /** Function for Edit Menu - Redo
00425  **/
00426 void Qonsole::on_editRedo_triggered()
00427 {
00428     qWarning("Not implemented yet.");
00429 }
00430 
00431 
00432 /** Function for Edit Menu - Cut
00433  **/
00434 void Qonsole::on_editCut_triggered()
00435 {
00436     qWarning("Not implemented yet.");
00437 }
00438 
00439 
00440 /** Function for Edit Menu - Copy
00441  **/
00442 void Qonsole::on_editCopy_triggered()
00443 {
00444     qWarning("Not implemented yet.");
00445 }
00446 
00447 
00448 /** Function for Edit Menu - Paste
00449  **/
00450 void Qonsole::on_editPaste_triggered()
00451 {
00452     qWarning("Not implemented yet.");
00453 }
00454 
00455 
00456 /** Function for Help Menu - Index
00457  **/
00458 void Qonsole::on_helpIndex_triggered()
00459 {
00460     qWarning("Not implemented yet.");
00461 }
00462 
00463 
00464 /** Function for Help Menu - Contents
00465  **/
00466 void Qonsole::on_helpContents_triggered()
00467 {
00468 #ifdef WIN32
00469     assistantClient->showPage(BBOB_HELP_FILE);
00470 #endif
00471 #ifdef unix
00472     assistantClient->showPage(BBOB_HELP_HTML);
00473 #endif
00474 }
00475 
00476 
00477 /** Function for Help Menu - About
00478  **/
00479 void Qonsole::on_helpAbout_triggered()
00480 {
00481     aboutDialog = new BBoB_About( QString("Qonsole - graphical interface to BBoB core."), this);
00482     aboutDialog->show();
00483 }
00484 
00485 
00486 
00487 void Qonsole::showDebugWindow()
00488 {
00489     qDebug("Show Debug Window");
00490     DebugWindow->show();
00491 }
00492 
00493 void Qonsole::LoadDebug(QString text)
00494 {
00495     DebugWindow->addText(text);
00496 }
00497 

Generated on Sun Oct 28 22:51:30 2007 for BBoB by  doxygen 1.5.3