Wosh3DWindow.cpp

Go to the documentation of this file.
00001 /** @file    Wosh3DWindow.cpp
00002  *  @author  Alessandro Polo
00003  *  @version $Id: Wosh3DWindow.cpp 3775 2011-01-01 16:38:17Z alex $
00004  *  @brief
00005  * File containing methods for the wosh::application::Wosh3DWindow class.
00006  * The header for this class can be found in Wosh3DWindow.h, check that file
00007  * for class description.
00008  ****************************************************************************/
00009 /* Copyright (c) 2007-2011, WOSH - Wide Open Smart Home 
00010  * by Alessandro Polo - OpenSmartHome.com
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *     * Redistributions of source code must retain the above copyright
00016  *       notice, this list of conditions and the following disclaimer.
00017  *     * Redistributions in binary form must reproduce the above copyright
00018  *       notice, this list of conditions and the following disclaimer in the
00019  *       documentation and/or other materials provided with the distribution.
00020  *     * Neither the name of the OpenSmartHome.com WOSH nor the
00021  *       names of its contributors may be used to endorse or promote products
00022  *       derived from this software without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
00025  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027  * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
00028  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00033  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  ****************************************************************************/
00035  
00036  #include "Wosh3DWindow.h"
00037  #include "ui_Wosh3DWindow.h"
00038  #include <core/ObjectAllocator.h>
00039  #include <core/DeviceManager.h>
00040  #include <core/FileSystem.h>
00041  #include <core/UserManager.h>
00042  #include <core/BusManager.h>
00043  #include <core/ThreadManager.h>
00044  #include <core/BundleManager.h>
00045  #include <core/NetworkManager.h>
00046  #include <core/WoshKernel.h>
00047  #include <core/MethodsCommon.h>
00048  #include <framework/security/AuthenticationOS.h>
00049  #include <framework/gui/components/FormContainer.h>
00050  #include <framework/gui/GuiUtilities.h>
00051  #include <framework/gui/components/GuiDialogs.h>
00052  #include <framework/gui/components/FormBusViewer.h>
00053  #include <framework/gui/components/FormConsole.h>
00054  #include <framework/gui/components/FormLogViewer.h>
00055  #include <framework/gui/widgets/wCore_PropertiesProvider.h>
00056  #include <bundles/DesktopNotifier/DesktopNotifierBundle.h>
00057  #include <interfaces/communication/CommunicationManager.h>
00058  #include <framework/gui/glc/WidgetBuildingRendererGLC.h>
00059  #include <QtGui>
00060 
00061 
00062 namespace wosh {
00063   namespace application {
00064   
00065 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00066 Wosh3DWindow* Wosh3DWindow::instance = NULL;
00067 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00068 //////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTORS
00069 
00070 Wosh3DWindow::Wosh3DWindow(QWidget *parent)
00071     : QMainWindow(parent) {
00072     this->m_ui = new Ui::Wosh3DWindow();
00073     this->m_ui->setupUi(this);
00074 
00075     this->trayIcon = NULL;
00076     this->desktopNotifierBundle = NULL;
00077     this->renderer = NULL;
00078     this->formLogViewer = NULL;
00079 
00080     Wosh3DWindow::instance = this;
00081  }
00082 
00083 Wosh3DWindow::~Wosh3DWindow() {
00084     writeSettings();
00085 
00086     if ( this->trayIcon != NULL ) {
00087         this->trayIcon->hide();
00088         if ( this->desktopNotifierBundle != NULL )
00089             this->desktopNotifierBundle->setTrayIcon(NULL);
00090         delete this->trayIcon; this->trayIcon = NULL;
00091      }
00092 
00093     if ( this->renderer != NULL )
00094         delete this->renderer; this->renderer = NULL;
00095 
00096     delete this->m_ui; this->m_ui = NULL;
00097 
00098     Wosh3DWindow::instance = NULL;
00099  }
00100 
00101 void Wosh3DWindow::init() {
00102     Log.setContext("Wosh3DWindow");
00103     Log.setLevel( LOG_VERBOSE );
00104     Log.setIndent( 1 );
00105 
00106     this->myUri.setKernelLocal();
00107     this->myUri.clearPathName();
00108     this->myUri.setName("Wosh3DWindow");
00109 
00110     this->renderer = new WidgetBuildingRendererGLC(this);
00111     setCentralWidget(this->renderer);
00112     this->renderer->setFocusPolicy(Qt::StrongFocus);
00113 
00114     BusGui.setMessageHandler(this);
00115     WRESULT bus_gui_connected = BusGui.connect( _Bus_Gui );
00116     (void)bus_gui_connected;
00117 
00118     // so all components will be really connected to busses and reflesh operation will work:
00119     WoshKernel::getInstance()->busses().fixDeferredListenersOf(_Bus_Gui);
00120 
00121     setDockOptions( QMainWindow::AnimatedDocks );
00122 
00123     // setup and connect menus
00124     createMenus();
00125     // setup tray icon stuff
00126     createTrayIcon();
00127     // setup status bar fields
00128     configureStatusBar();
00129 
00130     refreshInfo();
00131     readSettings();
00132 
00133     this->renderer->init(false);
00134  }
00135 
00136 void Wosh3DWindow::quitWosh() {
00137     QApplication::quit();
00138  }
00139 
00140 //////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTORS
00141 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00142 
00143 void Wosh3DWindow::refreshInfo() {
00144     if ( SessionGui::getInstance().getCurrentKernel() == WoshKernel::getKernelName() ) {
00145         setWindowTitle( QString("%1 v%2/%3.%4  - OpenSmartHome.com").arg(_APPLICATION_WOSH_3D_NAME)
00146                             .arg(_APPLICATION_WOSH_3D_VERSION).arg(_WOSH_VER_MAJOR).arg(_WOSH_VER_MINOR) );
00147         Log(LOG_INFO, ":changeCurrentKernelUser() : Switching to Local Kernel [%s] as %s..", SessionGui::getInstance().getCurrentKernel().c_str(), SessionGui::getInstance().getUsernameCurrent().c_str() );
00148      }
00149     else {
00150         setWindowTitle( QString("%1@%2 - %3 v%4/%5.%6")
00151                             .arg(SessionGui::getInstance().getUsernameCurrent().c_str()).arg(SessionGui::getInstance().getCurrentKernel().c_str()).arg(_APPLICATION_WOSH_3D_NAME)
00152                             .arg(_APPLICATION_WOSH_3D_VERSION).arg(_WOSH_VER_MAJOR).arg(_WOSH_VER_MINOR) );
00153         Log(LOG_INFO, ":changeCurrentKernelUser() : Switching to [%s] as %s..", SessionGui::getInstance().getCurrentKernel().c_str(), SessionGui::getInstance().getUsernameCurrent().c_str() );
00154      }
00155     this->statusBar()->showMessage(tr("Hi %1, Welcome to %2 version %3").arg(SessionGui::getInstance().getUsernameCurrent().c_str())
00156                                                                         .arg(_APPLICATION_WOSH_3D_NAME)
00157                                                                         .arg(_APPLICATION_WOSH_3D_VERSION), 5000);
00158     updateDynamicMenus();
00159     updateStatusBar();
00160  }
00161 
00162 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00163 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00164 /////////////////////////////////////////////////////////////////////////////////////////////////// WORKSPACE
00165 
00166 void Wosh3DWindow::create_GUI( const std::string& name, const std::string& type, const URI& uri, const QStringList& interfaces ) {
00167     Log(LOG_VERBOSE, ":create_GUI() : GUI for %s [%s]#%i {%s}", name.c_str(), type.c_str(), interfaces.size(), uri.toString().c_str() );
00168     IWidget* guiWidget = GuiUtilities::create_GUI( name, type, uri, interfaces );
00169     if ( guiWidget == NULL ) {
00170         QMessageBox::information(this, this->windowTitle(), QString("Sorry, Can't allocate GUI for '%1' [%2]").arg(type.c_str()).arg(interfaces.join(";")) );
00171         return;
00172      }
00173     QWidget* qWidget = guiWidget->asQWidget();
00174     if ( qWidget == NULL )
00175         return;
00176     qWidget->show();
00177  }
00178 
00179 /////////////////////////////////////////////////////////////////////////////////////////////////// WORKSPACE
00180 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00181 /////////////////////////////////////////////////////////////////////////////////////////////// MENU HANLDERS
00182 
00183 void Wosh3DWindow::menu_StaticItem_triggered( QAction* action ) {
00184     if ( action == NULL ) return;
00185     // ---------------------------------------------------------------------------
00186     // WOSH
00187     else if ( action == this->m_ui->actionWOSH_ReLogas ) {
00188         std::string username = SessionGui::getInstance().getUsernameLogged();
00189         DialogLogin::waitLogin(username, &SessionGui::getInstance());
00190         refreshInfo();
00191      }
00192 //  else if ( action == this->m_ui->actionWOSH_Import ) {
00193 //      DialogLoadBundle* dLb = new DialogLoadBundle(this);
00194 //      this->m_ui->mdiArea->addSubWindow(dLb);
00195 //      dLb->show();
00196 //   }
00197     else if ( action == this->m_ui->actionWOSH_LogViewer ) {
00198         if ( this->formLogViewer == NULL ) {
00199             this->formLogViewer = new FormLogViewer();
00200             this->formLogViewer->show();
00201          }
00202         this->formLogViewer->show();
00203         ///@todo QMdiSubWindow* subWin = this->m_ui->mdiArea->addSubWindow(this->formLogViewer);
00204         ///@todo subWin->show();
00205      }
00206     else if ( action == this->m_ui->actionWOSH_Terminal ) {
00207         FormConsole* cF = new FormConsole();
00208         cF->show();
00209      }
00210     else if ( action == this->m_ui->actionWOSH_Quit ) {
00211         quitWosh();
00212      }
00213     // ---------------------------------------------------------------------------
00214     // Bundles
00215     else if ( action == this->m_ui->actionBundles_CreateGUI ) {
00216         DialogCreateGui* dCgui = new DialogCreateGui();
00217         dCgui->init(false);
00218         std::vector<std::string> temp;
00219 //      this->guiAllocator->getSupportedObjects(temp);
00220 //      dCgui->setTypes(temp);
00221         if ( dCgui->exec() == QDialog::Accepted ) {
00222             create_GUI(dCgui->getName(), dCgui->getType(), dCgui->getTargetURI(), dCgui->getInterfaces() );
00223          }
00224         dCgui->deleteLater();
00225      }
00226     // ---------------------------------------------------------------------------
00227     // Network
00228     else if ( action == this->m_ui->actionNetwork_Refresh ) {
00229         this->m_ui->menuNetwork_Hosts->refreshAll();
00230         this->m_ui->menuNetwork_Protocols->refreshAll();
00231         this->m_ui->menuNetwork_Channels->refreshAll();
00232      }
00233 //  else if ( action == this->m_ui->actionNetwork_Listen ) {
00234 //      QMessageBox::warning(this, this->windowTitle(), tr("TODO") );
00235 //   }
00236 //  else if ( action == this->m_ui->actionNetwork_Connect ) {
00237 //      QMessageBox::warning(this, this->windowTitle(), tr("TODO") );
00238 //   }
00239     // ---------------------------------------------------------------------------
00240     // Tools
00241     else if ( action == this->m_ui->actionTools_BusViewer ) {
00242         FormBusViewer* bV = new FormBusViewer();
00243         bV->refreshAll();
00244         bV->show();
00245      }
00246     else if ( action == this->m_ui->actionTools_PropertiesEditor ) {
00247      }
00248     else if ( action == this->m_ui->actionTools_Preferences ) {
00249      }
00250     else if ( action == this->m_ui->actionTools_GuiMappings ) {
00251         DialogGuiMapping* dCgui = new DialogGuiMapping();
00252         dCgui->exec();
00253         dCgui->deleteLater();
00254      }
00255     // ---------------------------------------------------------------------------
00256     // HELP menu
00257     else if ( action == this->m_ui->actionHelp_Documentation ) {
00258         QDesktopServices::openUrl( QUrl(_WOSH_WEB_DOCS) );
00259      }
00260     else if ( action == this->m_ui->actionHelp_WOSH_Online ) {
00261         QDesktopServices::openUrl( QUrl(_WOSH_WEB_SITE) );
00262      }
00263     else if ( action == this->m_ui->actionHelp_AlessandroPoloOnline ) {
00264         QDesktopServices::openUrl( QUrl(_WOSH_CREATOR_WEB) );
00265      }
00266     else if ( action == this->m_ui->actionHelp_OpenSmartHome_com ) {
00267         QDesktopServices::openUrl( QUrl(_OPEN_SMART_HOME_WEB) );
00268      }
00269     else if ( action == this->m_ui->actionHelp_CheckforUpdates ) {
00270         ///@todo CheckforUpdates
00271         QMessageBox::warning(this, this->windowTitle(), tr("Feature NOT Implemented yet.") );
00272      }
00273     else if ( action == this->m_ui->actionHelp_DonatePaypal ) {
00274         QDesktopServices::openUrl( QUrl(_WOSH_DONATE_URL) );
00275      }
00276     else if ( action == this->m_ui->actionHelp_AboutWOSHSHOP ) {
00277         QMessageBox::information(this, this->windowTitle(), "<h1>" _APPLICATION_WOSH_3D_NAME "</h1>"
00278                                     "<h3>version " _APPLICATION_WOSH_3D_VERSION " - 2011</h3>"
00279                                     "<h2>3D Frontend for WOSH Network</h2>"
00280                                     "<p>Refer to <a href='http://wosh.sourceforge.net'>http://wosh.sourceforge.net</a>.</p>"
00281                                     "<p>An open source software by <a href='mailto:contact@alessandropolo.name'>Alessandro Polo</a>.</p>" );
00282      }
00283     else if ( action == this->m_ui->actionHelp_AboutWOSH ) {
00284         GuiUtilities::aboutWOSH(this);
00285      }
00286     else if ( action == this->m_ui->actionHelp_AboutQT ) {
00287         QMessageBox::aboutQt(this);
00288      }
00289     else if ( action == this->m_ui->actionHelp_ShowSplash ) {
00290         QDialog dialog;
00291         dialog.setWindowTitle( tr("%1 version %2").arg(_APPLICATION_WOSH_3D_NAME).arg(_APPLICATION_WOSH_3D_VERSION) );
00292         dialog.setWindowIcon( this->windowIcon() );
00293         QPixmap splash(":/wosh.splash.icarus.png");
00294         QLabel* imageLabel = new QLabel(&dialog);
00295         imageLabel->setPixmap(splash);
00296         QVBoxLayout l(&dialog);
00297         l.addWidget(imageLabel);
00298         dialog.exec();
00299      }
00300     // ---------------------------------------------------------------------------
00301     // ---------------------------------------------------------------------------
00302     else if ( action == this->m_ui->actionWindows_DockCurrent ) {
00303         ///@todo todo
00304      }
00305     
00306  }
00307 
00308 void Wosh3DWindow::menu_CreateGUI_triggeredItem( WidgetQMenuItem * actionItem ) { // CHANGE TO REMOTEOBJECT !!
00309     if ( actionItem == NULL ) return;
00310 
00311     create_GUI( actionItem->getRemoteName(), // CHANGE TO REMOTEOBJECT !!
00312                 actionItem->getRemoteType(),
00313                 actionItem->getRemoteURI(),
00314                 actionItem->getInterfaces() ); // CHANGE TO DATALIST in REMOTEOBJECT !!
00315  }
00316 
00317 void Wosh3DWindow::menuWOSH_Kernel_triggeredItem( WidgetQMenuItem * actionItem ) {
00318     if ( actionItem == NULL ) return;
00319     URI loc = SessionGui::getInstance().getCurrentLocation();
00320     loc.setKernelName( actionItem->text().toLatin1().constData() );
00321     SessionGui::getInstance().setCurrentLocation(loc);
00322     refreshInfo();
00323  }
00324 
00325 /////////////////////////////////////////////////////////////////////////////////////////////// MENU HANLDERS
00326 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00327 ////////////////////////////////////////////////////////////////////////////////////////// CREATE/UPDATE MENU
00328 
00329 void Wosh3DWindow::createMenus() {
00330     Log(LOG_VERBOSE, ":createMenus() : Setting up.." );
00331 
00332     // MENU WOSH
00333     connect(this->m_ui->menu_Kernels, SIGNAL( triggeredItem( WidgetQMenuItem* ) ), this, SLOT(menuWOSH_Kernel_triggeredItem( WidgetQMenuItem* )));
00334 
00335     // MENU Modules
00336     connect(this->m_ui->menu_Modules, SIGNAL( triggeredItem( WidgetQMenuItem* ) ), this, SLOT(menu_CreateGUI_triggeredItem( WidgetQMenuItem* )));
00337     connect(this->m_ui->menu_Modules, SIGNAL( updated() ), this, SLOT(menu_Modules_update_ToolBar()));
00338 
00339     // MENU Bundles
00340     connect(this->m_ui->menu_Bundles, SIGNAL( triggeredItem( WidgetQMenuItem* ) ), this, SLOT(menu_CreateGUI_triggeredItem( WidgetQMenuItem* )));
00341 
00342     // Static items from MENUS
00343     connect(this->m_ui->menu_WOSH, SIGNAL( triggered( QAction* ) ), this, SLOT(menu_StaticItem_triggered( QAction* )));
00344     connect(this->m_ui->menu_Bundles, SIGNAL( triggered( QAction* ) ), this, SLOT(menu_StaticItem_triggered( QAction* )));
00345     connect(this->m_ui->menu_Network, SIGNAL( triggered( QAction* ) ), this, SLOT(menu_StaticItem_triggered( QAction* )));
00346     connect(this->m_ui->menu_Tools, SIGNAL( triggered( QAction* ) ), this, SLOT(menu_StaticItem_triggered( QAction* )));
00347     connect(this->m_ui->menu_Help, SIGNAL( triggered( QAction* ) ), this, SLOT(menu_StaticItem_triggered( QAction* )));
00348 
00349  }
00350 
00351 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00352 
00353 void Wosh3DWindow::updateDynamicMenus() {
00354     Log(LOG_VERBOSE, ":updateDynamicMenus() : Updating Menus [%s]..", SessionGui::getInstance().getCurrentKernel().c_str() );
00355 
00356     this->m_ui->menu_Kernels->getTargetURI().setKernelLocal(); // always map to local kernel!
00357     this->m_ui->menu_Kernels->getTargetURI().setName("Network");
00358     this->m_ui->menu_Kernels->setDefaultType(WoshHost::className());
00359     this->m_ui->menu_Kernels->setForceType(true);
00360     this->m_ui->menu_Kernels->setRequestMethod(_NetworkManager_METHOD_Hosts_list);
00361     this->m_ui->menu_Kernels->refreshAll();
00362     std::string kName = SessionGui::getInstance().getCurrentKernel();
00363     for (int i=0; i<this->m_ui->menu_Kernels->getActionsDynamic().size(); i++) {
00364         if ( this->m_ui->menu_Kernels->getActionsDynamic().at(i) == NULL ) continue;
00365         if (this->m_ui->menu_Kernels->getActionsDynamic().at(i)->getRemoteName() == kName )
00366             this->m_ui->menu_Kernels->getActionsDynamic().at(i)->setChecked(true);
00367         else
00368             this->m_ui->menu_Kernels->getActionsDynamic().at(i)->setChecked(false);
00369      }
00370 
00371     this->m_ui->menu_Modules->getTargetURI().setKernelName(SessionGui::getInstance().getCurrentKernel());
00372     this->m_ui->menu_Modules->getTargetURI().setName("");
00373     this->m_ui->menu_Modules->setRequestMethod(_METHOD_List);
00374     this->m_ui->menu_Modules->setDefaultType(WoshModule::className());
00375     this->m_ui->menu_Modules->refreshAll();
00376 
00377     this->m_ui->menu_Bundles->getTargetURI().setKernelName(SessionGui::getInstance().getCurrentKernel());
00378     this->m_ui->menu_Bundles->getTargetURI().setName("Bundles");
00379     this->m_ui->menu_Bundles->refreshAll();
00380 
00381     this->m_ui->menuNetwork_Protocols->getTargetURI().setKernelName(SessionGui::getInstance().getCurrentKernel());
00382     this->m_ui->menuNetwork_Protocols->getTargetURI().setName("Network");
00383     this->m_ui->menuNetwork_Protocols->setRequestMethod(_NetworkManager_METHOD_Protocols_list);
00384     this->m_ui->menuNetwork_Protocols->refreshAll();
00385 
00386     this->m_ui->menuNetwork_Channels->getTargetURI().setKernelName(SessionGui::getInstance().getCurrentKernel());
00387     this->m_ui->menuNetwork_Channels->getTargetURI().setName("Network");
00388     this->m_ui->menuNetwork_Channels->setRequestMethod(_NetworkManager_METHOD_Channels_list);
00389     this->m_ui->menuNetwork_Channels->refreshAll();
00390 
00391     this->m_ui->menuNetwork_Hosts->getTargetURI().setKernelName(SessionGui::getInstance().getCurrentKernel());
00392     this->m_ui->menuNetwork_Hosts->getTargetURI().setName("Network");
00393     this->m_ui->menuNetwork_Hosts->setDefaultType(WoshHost::className());
00394     this->m_ui->menuNetwork_Hosts->setForceType(true);
00395     this->m_ui->menuNetwork_Hosts->setRequestMethod(_NetworkManager_METHOD_Hosts_list);
00396     this->m_ui->menuNetwork_Hosts->refreshAll();
00397  }
00398 
00399 ////////////////////////////////////////////////////////////////////////////////////////// CREATE/UPDATE MENU
00400 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00401 /////////////////////////////////////////////////////////////////////////////////////////// TRAY ICON METHODS
00402 
00403 void Wosh3DWindow::createTrayIcon() {
00404     Log(LOG_VERBOSE, ":createTrayIcon() : Setting up.." );
00405 
00406     this->minimizeAction = new QAction(tr("Mi&nimize"), this);
00407     connect(this->minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
00408 
00409     this->maximizeAction = new QAction(tr("Ma&ximize"), this);
00410     connect(this->maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
00411 
00412     this->restoreAction = new QAction(tr("&Restore"), this);
00413     connect(this->restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
00414 
00415     this->trayIconMenu = new QMenu(this);
00416     this->trayIconMenu->addAction(minimizeAction);
00417     this->trayIconMenu->addAction(maximizeAction);
00418     this->trayIconMenu->addAction(restoreAction);
00419     this->trayIconMenu->addSeparator();
00420     this->trayIconMenu->addAction(this->m_ui->actionWOSH_Quit);
00421 
00422     this->trayIcon = new QSystemTrayIcon(this);
00423     this->trayIcon->setContextMenu(this->trayIconMenu);
00424     this->trayIcon->setIcon(this->windowIcon());
00425     this->trayIcon->setToolTip(_APPLICATION_WOSH_3D_NAME);
00426 //  connect(this->trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));
00427 //  connect(this->trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
00428     this->trayIcon->show();
00429  }
00430 
00431 void Wosh3DWindow::configureStatusBar() {
00432     Log(LOG_VERBOSE, ":configureStatusBar() : Setting up.." );
00433 
00434     this->statusUserAtKernelLbl = new QLabel(this->statusBar());
00435 //  this->statusUserAtKernelLbl->setFrameShape(QFrame::StyledPanel);
00436 
00437     this->statusConnections = new QLabel(this->statusBar());
00438 
00439     QLabel* statusEmpty = new QLabel(this->statusBar());
00440 //  statusEmpty->setFrameShape(QFrame::NoFrame);
00441 //  statusEmpty->setFrameShadow(QFrame::Plain);
00442 //  statusEmpty->setLineWidth(0);
00443 
00444     this->statusBar()->addWidget(statusEmpty, 1);
00445     this->statusBar()->addWidget(this->statusUserAtKernelLbl, 0);
00446 
00447     updateStatusBar();
00448  }
00449 
00450 void Wosh3DWindow::updateStatusBar() {
00451     this->statusUserAtKernelLbl->setText( QString("%1@%2").arg(SessionGui::getInstance().getUsernameCurrent().c_str()).arg(SessionGui::getInstance().getCurrentKernel().c_str()) );
00452  }
00453 
00454 void Wosh3DWindow::showMessage( const QString& title, const QString& message, long timeout, QSystemTrayIcon::MessageIcon icon ) {
00455     this->statusBar()->showMessage(tr("%1: %2").arg(title).arg(message), timeout);
00456 
00457     if ( this->trayIcon == NULL )
00458         return;
00459     this->trayIcon->showMessage(title, message, icon, timeout);
00460  }
00461 
00462 /////////////////////////////////////////////////////////////////////////////////////////// TRAY ICON METHODS
00463 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00464 //////////////////////////////////////////////////////////////////////////////////////////////////// SETTINGS
00465 
00466 void Wosh3DWindow::readSettings() {
00467     Log(LOG_INFO, ":readSettings() : Reading.." );
00468     QSettings settings("OpenSmartHome.com", _APPLICATION_WOSH_3D_NAME);
00469 
00470     int winstate = settings.value("state", (int)Qt::WindowActive).toInt();
00471     QPoint pos = settings.value("pos", QPoint(50, 50)).toPoint();
00472     move(pos);
00473     QSize size = settings.value("size", QSize(800, 600)).toSize();
00474     resize(size);
00475     this->setWindowState( (Qt::WindowState)winstate );
00476 
00477     //QString language = settings.value("language", QLocale::system().name() ).toString();
00478     //loadLanguage(language);
00479 
00480     QString styleName = settings.value("style", "Plastique").toString();
00481     qApp->setStyle(styleName);
00482 
00483     QString styleSheet = settings.value("styleSheet", "Coffee").toString();
00484     loadStyleSheet(styleSheet);
00485 
00486     QByteArray winState = settings.value("winState").toByteArray();
00487     restoreState(winState);
00488  }
00489 
00490 void Wosh3DWindow::writeSettings() {
00491     Log(LOG_INFO, ":writeSettings() : Writing.." );
00492     QSettings settings("OpenSmartHome.com", _APPLICATION_WOSH_3D_NAME);
00493 
00494     settings.setValue("state", (int)this->windowState() );
00495     if ( this->windowState() != Qt::WindowMaximized && this->windowState() != Qt::WindowFullScreen ) {
00496         settings.setValue("pos", pos());
00497         settings.setValue("size", size());
00498      }
00499 
00500     settings.setValue("style", qApp->style()->objectName() );
00501     settings.setValue("styleSheet", qApp->styleSheet() );
00502 
00503     QByteArray winState = saveState(1);
00504     settings.setValue("winState", winState );
00505 
00506 //type|uri
00507 
00508  }
00509 
00510 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00511 
00512 void Wosh3DWindow::loadStyleSheet( const QString& sheetName ){
00513     Log(LOG_INFO, ":loadStyleSheet(%s) : Loading StyleSheet..",sheetName.toLatin1().constData() );
00514 
00515     QFile file(":/qss/" + sheetName.toLower() + ".qss");
00516     file.open(QFile::ReadOnly);
00517     QString styleSheet = QLatin1String(file.readAll());
00518     qApp->setStyleSheet(styleSheet);
00519 }
00520 
00521 void Wosh3DWindow::loadLanguage(const QString& language) {
00522     if ( language.empty() ) return;
00523     Log(LOG_INFO, ":loadLanguage(%s) : Loading Translator..",language.toLatin1().constData() );
00524 
00525     QTranslator* qtTranslator = new QTranslator();
00526     QString trQt = "qt_" + language;
00527     bool loadedQt = qtTranslator->load(trQt, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
00528     if ( loadedQt )
00529         qApp->installTranslator(qtTranslator);
00530 //  else
00531 //      QMessageBox::critical(this, this->windowTitle(), QString("Error occurred while loading Translation file [%1].").arg(trQt) );
00532 
00533     QTranslator* woshWidgetTranslator = new QTranslator();
00534     QString trWw = ":/translations/widgets."+language+".qm";
00535     bool loadedWw = woshWidgetTranslator->load( trWw );
00536     if ( loadedWw )
00537         qApp->installTranslator(woshWidgetTranslator);
00538     else
00539         QMessageBox::critical(this, this->windowTitle(), QString("Error occurred while loading Translation file [%1].").arg(trWw) );
00540 
00541     QTranslator* myappTranslator = new QTranslator();
00542     QString trMy = ":/translations/"+language+".qm";
00543     bool loadedMy = myappTranslator->load( trMy );
00544     if ( loadedMy )
00545         qApp->installTranslator(myappTranslator);
00546     else
00547         QMessageBox::critical(this, this->windowTitle(), QString("Error occurred while loading Translation file [%1].").arg(trMy) );
00548  }
00549 
00550 //////////////////////////////////////////////////////////////////////////////////////////////////// SETTINGS
00551 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00552 
00553 void Wosh3DWindow::changeEvent(QEvent *e) {
00554     QMainWindow::changeEvent(e);
00555     switch (e->type()) {
00556         case QEvent::LanguageChange:
00557             m_ui->retranslateUi(this);
00558             refreshInfo(); // refresh title
00559             break;
00560         default:
00561             break;
00562      }
00563  }
00564 
00565 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00566 
00567 void Wosh3DWindow::busMessage( const Message& message, const Bus* )
00568  {
00569     if ( message.isEmpty() ) return;
00570     if ( message.getContent()->isFact() ) {
00571         const wosh::Fact* fact = message.getContent()->asFact();
00572         if ( message.getSource().isKernelLocal() && message.getSource().getName() == "Network"
00573             && fact->getEvent() == _WoshHost_EVENT_ListChanged ) {
00574                 this->m_ui->menu_Kernels->refreshAll();
00575          }
00576      }
00577     else if ( message.getContent()->isResponse() ) {
00578         const wosh::Response* response = message.getContent()->asResponse();
00579         if ( !response->hasData() )
00580             return;
00581         if ( !message.getSource().isKernelLocal() || message.getSource().getName() != "Network" )
00582             return;
00583         if ( response->getMethod() == _METHOD_GetProperties ) {
00584             if ( !response->getData()->isKindOf<Table>() )
00585                 return;
00586             //const wosh::Table* propTable = response->getData()->as<Table>();
00587          }
00588      }
00589 
00590         //this->statusConnections->setText("X [Y]");
00591         //this->statusConnections->setToolTip("X Connections [Y Neighbours]");
00592  }
00593 
00594 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00595 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00596 
00597 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
00598 
00599   }; // namespace application
00600 }; // namespace wosh

Generated on Tue Feb 8 2011 09:33:13 for WOSH system 0.8.888 [wolf] by Alessandro Polo, using DoxyGen 1.7.2 hosted by WOSH Framework