Merge branch 'master' into dev_local
authorZoltan Papp <zoltan.papp@ixonos.com>
Mon, 1 Jun 2009 06:16:11 +0000 (09:16 +0300)
committerZoltan Papp <zoltan.papp@ixonos.com>
Mon, 1 Jun 2009 06:16:11 +0000 (09:16 +0300)
1  2 
src/BusinessLogic/Engine.cpp
src/BusinessLogic/Engine.h
src/BusinessLogic/UIManager.cpp
src/BusinessLogic/UIManager.h
src/UserInterface/Views/RoomStatusIndicatorWidget.cpp
src/UserInterface/Views/RoomStatusIndicatorWidget.h

@@@ -32,8 -32,6 +32,8 @@@ Engine::Engine() 
                iWindowManager( 0 ), iUIManager( 0 )
  {
        qDebug() << "Engine::Engine()";
 +      iCommunicationFailed = false;
 +      iCurrentWeekFetched = false;
        
        initConfiguration();
        initDevice();
@@@ -197,16 -195,8 +197,16 @@@ void Engine::fetchMeetingDetails( Meeti
  void Engine::meetingsFetched( const QList<Meeting*> &aMeetings )
  {
        qDebug() << "Engine::meetingsFetched( const QList<Meeting*> & )";
 -      
 -      for ( int i = 0; i < iMeetings.count(); ++i ) {
 +      // TODO: should check if this week's meetings were fetched
 +      if( iCommunicationFailed || !iCurrentWeekFetched )
 +      {
 +              iCurrentWeekFetched = true;
 +              iCommunicationFailed = false;
 +              iUIManager->connectionEstablished();
 +      }
 +
 +      for ( int i = 0; i < iMeetings.count(); ++i ) 
 +      {
                Meeting* m = iMeetings.takeAt( i );
                delete m;
        }
  
  void Engine::errorHandler( int aCode, const QString &aAddInfo )
  {     
 +      if( aCode >= 100 && aCode < 150 )
 +      {
 +              iCommunicationFailed = true;
 +              if ( iUIManager != 0 ) iUIManager->connectionLost();
 +      }
        if ( iWindowManager != 0 )
        {
                iWindowManager->error( ErrorMapper::codeToString( aCode, aAddInfo ) );
@@@ -255,20 -240,16 +255,16 @@@ void Engine::shownWeekChanged( QDate aF
  //    fetchMeetings( from, to, iWindowManager->weeklyView()->currentRoom() );
  }
  
- void Engine::changeDeviceMode( bool aChange )
+ void Engine::changeDeviceMode()
  {
-       if ( aChange )
-       {
-               connect( iDevice, SIGNAL( changingModeFailed() ), this, SLOT( changeModeFailed() ) );
-               iAutoRefresh->stop(); // Stop the meeting update
-       }
-       iDevice->changeMode( aChange );
+       connect( iDevice, SIGNAL( changeModeFailed() ), this, SLOT( changeModeFailed() ) );
+       iAutoRefresh->stop(); // Stop the meeting update
+       iDevice->changeMode();
  }
  
  void Engine::changeModeFailed()
  {
        qDebug() << "Engine::progressBarCancelled()";
-       iDevice->changeMode( false );
        iAutoRefresh->start(); //we start the metting updating
  }
  
@@@ -283,8 -264,8 +279,8 @@@ void Engine::initUserInterface(
        
        connect( iWindowManager, SIGNAL( eventDetected() ), this, SLOT( handleViewEvent() ) );
        connect( iWindowManager, SIGNAL( previousViewRestored() ), iUIManager, SLOT( previousViewRestored() ) );
- //    connect( iWindowManager, SIGNAL( dialogActivated() ), this, SLOT( dialogActivated() ) );
- //    connect( iWindowManager, SIGNAL( dialogDeactivated() ), this, SLOT( dialogDeactivated() ) );
+       connect( iWindowManager, SIGNAL( dialogActivated() ), this, SLOT( dialogActivated() ) );
+       connect( iWindowManager, SIGNAL( dialogDeactivated() ), this, SLOT( dialogDeactivated() ) );
        
        // Show the UI
        iWindowManager->setWindowState( Qt::WindowMaximized );
  
  void Engine::handleViewEvent()
  {
-       if ( iIdleTimeCounter != 0 )
+       if ( iIdleTimeCounter != 0 && iIdleTimeCounter->isActive())
        {
                // Restart the idle time counter when view event is received
                iIdleTimeCounter->stop();
@@@ -120,7 -120,7 +120,7 @@@ private slots
        void stopIdleTimeCounter();
        void startIdleTimeCounter();
  
-       void changeDeviceMode( bool aChange );
+       void changeDeviceMode();
        
        void currentRoomChanged( Room *aRoom );
        
@@@ -206,8 -206,6 +206,8 @@@ private
        QList<Meeting*> iMeetings;
        
        Room *iCurrentRoom;
 +      bool iCommunicationFailed;
 +      bool iCurrentWeekFetched;
  };
  
  #endif /*ENGINE_H_*/
@@@ -63,15 -63,6 +63,6 @@@ void UIManager::showMainView(
        iWindowManager->showView( iWeeklyView );
  }
  
- void UIManager::showProgressBar( QString aText )
- {
-       if ( iProgressBar != 0 )
-       {
-               iProgressBar->update( aText );
-               iWindowManager->showDialog( iProgressBar );
-       }
- }
  // ===============================================
  //            INITIALIZE THE UIMANAGER
  void UIManager::createWeeklyView()
@@@ -103,15 -94,13 +94,13 @@@ void UIManager::createRoomStatusIndicat
  
  void UIManager::createPasswordDialog()
  {
-       iPasswordDialog = new PasswordDialog( iEngine->iConfiguration->adminPassword(), tr("UIManager::createPasswordDialog"), tr("UIManager::createPasswordDialog") );
-       
+       iPasswordDialog = new PasswordDialog( iEngine->iConfiguration->adminPassword(), "", tr("Enter password") );
        connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) );
  }
  
  void UIManager::createProgressBar()
  {
        iProgressBar = new ProgressBar( tr("CHANGE THIS"), true );
-       
        // Connect to UIManager
        connect( iProgressBar, SIGNAL( cancel() ), this, SLOT( progressBarCancelled() ) );
        // Connect to Engine
@@@ -173,9 -162,9 +162,9 @@@ void UIManager::showMeetingProgressBar
  {
        if ( iProgressBar != 0 )
        {
-               iProgressBar->update( tr("Fetching meeting info...") );
+               iProgressBar->update( tr( "Fetching meeting info..." ), tr( "Please wait" ) );
+               iProgressBar->toggleCancellable( true );
                iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
-               iEngine->stopIdleTimeCounter();
        }
  }
  
@@@ -215,40 -204,22 +204,38 @@@ void UIManager::progressBarCancelled(
        if ( iProgressBar != 0 )
        {
                iProgressBar->close();
-               iEngine->startIdleTimeCounter();
        }
  }
  
  void UIManager::changeModeOrdered( DeviceManager::OperationMode aMode )
  {
        qDebug() << "[UIManager::changeModeOrdered] <Invoked>";
  
        if ( iPasswordDialog != 0 )
        {
-               // TODO : Set the new text for password dialog
+               QString text = tr( "You are about to change operation mode to %1." )
+                                               .arg( iEngine->iDevice->operationModeToString( aMode ) );
+               iPasswordDialog->update( text );
                iWindowManager->showDialog( static_cast<QDialog *>( iPasswordDialog ) );
        }
  }
  
 +void UIManager::connectionLost()
 +{
 +      qDebug() << "UIManager::connectionLost()";
 +      iWeeklyView->connectionLost();
 +      iSettingsView->connectionLost();
 +      iRoomStatusIndicator->connectionLost();
 +}
 +
 +void UIManager::connectionEstablished()
 +{
 +      qDebug() << "UIManager::connectionEstablished()";
 +      iWeeklyView->connectionEstablished();
 +      iSettingsView->connectionEstablished();
 +      iRoomStatusIndicator->connectionEstablished();
 +}
 +
  void UIManager::currentRoomChanged(Room *aRoom)
  {
        qDebug() << "[UIManager::currentRoomChanged] <Invoked>";
@@@ -276,15 -247,17 +263,17 @@@ void UIManager::passwordEntered( Passwo
                        // Show the progress bar..
                        if ( iProgressBar != 0 )
                        {
-                               iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false );
+                               iProgressBar->update( tr( "" ), tr( "Changing operation mode" ) );
+                               iProgressBar->toggleCancellable( false );
+                               iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
                        }
                        // ... and initiate the mode changing
-                       iEngine->changeDeviceMode( true );
+                       iEngine->changeDeviceMode();
                        break;
                case PasswordDialog::Incorrect:
                        iWindowManager->error( tr("Incorrect Password") );
+                       break;
                case PasswordDialog::Canceled:
-                       iEngine->changeDeviceMode( false );
                        break;
        }
        
@@@ -52,11 -52,6 +52,6 @@@ public
         * Makes the main view visible trough WindowManager.
         */
        void showMainView();
-       //! Shows the progress bar.
-       /*!
-        * Shows the progress bar with given text.
-        */
-       void showProgressBar( QString aText );
  
  signals:
        
@@@ -102,13 -97,6 +97,13 @@@ public slots
         * to start fetching new meetings for currently shown week.
         */
        void currentRoomChanged( Room *aRoom );
 +
 +      //! Shows any view specific indicators for connection error
 +      void connectionLost();
 +      
 +      //! Removes any view specific indicators for connection error
 +      void connectionEstablished();
 +      
        
  private slots:
  
@@@ -6,6 -6,8 +6,8 @@@
  #include "DigitalTimeDisplayWidget.h"\r
  #include "ToolBox.h"\r
  \r
+ #include <QEvent>\r
\r
  #include <QtDebug>\r
  \r
  QTime RoomStatusIndicatorWidget::endOfTheDay = QTime( 23, 59, 0, 0 );\r
@@@ -31,48 -33,28 +33,48 @@@ RoomStatusIndicatorWidget::RoomStatusIn
        iDefaultRoomLabel = ToolBox::createLabel( aDefaultRoom->name(), importantTextFont );\r
        iDefaultRoomLabel->setAlignment( Qt::AlignHCenter );\r
        iDefaultRoomLabel->setStyleSheet( "background-color: transparent" );\r
 +      iDefaultRoomLabel->setHidden( true );\r
 +      \r
        // is busy\r
        iStatusLabel = ToolBox::createLabel( tr( "is %1" ).arg( statusToText( aStatus ) ), importantTextFont );\r
        iStatusLabel->setAlignment( Qt::AlignHCenter );\r
        iStatusLabel->setStyleSheet( "background-color: transparent" );\r
 +      iStatusLabel->setHidden( true );\r
  \r
        // until 13:22\r
        iUntilTextLabel = ToolBox::createLabel( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ), importantTextFont );\r
        iUntilTextLabel->setAlignment( Qt::AlignHCenter );\r
        iUntilTextLabel->setStyleSheet( "background-color: transparent" );\r
 +      iUntilTextLabel->setHidden( true );\r
 +      \r
 +      // No connection to server note\r
 +      qDebug() << "RoomStatusIndicatorWidget::RoomStatusIndicatorWidget() creating connection label";\r
 +      QFrame* connectionLabelFrame = new QFrame( this );\r
 +      iConnectionLabel = new QLabel( tr( "No connection to server" ), connectionLabelFrame );\r
 +      iConnectionLabel->setFont( importantTextFont ); \r
 +      iConnectionLabel->setAlignment( Qt::AlignHCenter );\r
 +      iConnectionLabel->setWordWrap( true );\r
 +      iConnectionLabel->setStyleSheet( "background-color: transparent; color: red; text-decoration:blink; max-width: 250px" );\r
 +      connectionLabelFrame->setFixedSize( iConnectionLabel->sizeHint() );\r
 +      if( connectedOnce && !connectionError ) iConnectionLabel->setHidden( true );\r
 +              \r
  \r
        QVBoxLayout *topLayout = new QVBoxLayout;\r
        topLayout->addStretch();\r
        topLayout->addWidget( iTimeDisplay );\r
 +      topLayout->addSpacing( 28 );\r
        topLayout->addWidget( iDefaultRoomLabel );\r
        topLayout->addWidget( iStatusLabel );\r
        topLayout->addWidget( iUntilTextLabel );\r
 +      topLayout->addSpacing( 28 );\r
 +      topLayout->addWidget( connectionLabelFrame );\r
        topLayout->addStretch();\r
  \r
        QHBoxLayout *mainLayout = new QHBoxLayout;\r
        mainLayout->addLayout( topLayout );\r
        mainLayout->addStretch();\r
 -      mainLayout->setMargin( 65 );\r
 +      //mainLayout->setMargin( 65 );\r
 +      mainLayout->setContentsMargins( 65, 65, 65, 0 );\r
        setLayout( mainLayout );\r
  \r
        statusChanged( aStatus, aUntil );\r
@@@ -94,25 -76,28 +96,28 @@@ QString RoomStatusIndicatorWidget::stat
  \r
  QPalette RoomStatusIndicatorWidget::createPalette( Room::Status aStatus )\r
  {\r
-       QPixmap pixmap( aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free" );\r
+       // QPixmap pixmap( aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free" );\r
+       QString image = aStatus == Room::BusyStatus ? ":roomstatus_busy" : ":roomstatus_free";\r
  \r
        // The image needs to be moved in normal mode so the traffic light not partly outside the screen\r
        const int xoffset( 60 );\r
        const int yoffset( 19 );\r
-       int cropwidth( pixmap.width() - xoffset );\r
-       int cropheight( pixmap.height() - yoffset );\r
+ //    int cropwidth( pixmap.width() - xoffset );\r
+ //    int cropheight( pixmap.height() - yoffset );\r
        \r
        QBrush brush;\r
        if ( windowState() == Qt::WindowFullScreen )\r
        {\r
                // Use the full image in full screen mode\r
-               brush.setTexture( pixmap );\r
+ //            brush.setTexture( pixmap );\r
+               brush.setTexture( QPixmap(image) );\r
        }\r
        else\r
        {\r
                // Take part of the image so the traffic lights are moved xoffset poxels to left \r
                // and yoffset pixels to up\r
-               brush.setTexture( pixmap.copy( xoffset, yoffset, cropwidth, cropheight ) );\r
+ //            brush.setTexture( pixmap.copy( xoffset, yoffset, cropwidth, cropheight ) );\r
+               brush.setTexture( QPixmap(image) );\r
        }\r
  \r
        QPalette palette;\r
@@@ -137,27 -122,26 +142,49 @@@ void RoomStatusIndicatorWidget::statusC
                iUntilTextLabel->setText( tr( "until %1" ).arg( aUntil.toString( iTimeFormat ) ) );\r
        }\r
        setPalette( createPalette( aStatus ) );\r
+ }
\r
+ void RoomStatusIndicatorWidget::currentRoomChanged( Room *aRoom )\r
+ {\r
+       iDefaultRoomLabel->setText( aRoom->name() );\r
+ }\r
\r
+ bool RoomStatusIndicatorWidget::event(QEvent *event)\r
+ {\r
+       switch(event->type())\r
+       {\r
+               case QEvent::Paint:\r
+                       qDebug() << "[RoomStatusIndicatorWidget::event] <Paint event>";\r
+                       break;\r
+               case QEvent::PaletteChange:\r
+                       qDebug() << "[RoomStatusIndicatorWidget::event] <Palette change event>";\r
+                       break;\r
+               default:\r
+                       break;\r
+       }\r
+       \r
+       return ViewBase::event( event );\r
  }\r
 +\r
 +void RoomStatusIndicatorWidget::connectionEstablished()\r
 +{\r
 +      \r
 +      if( !connectedOnce )\r
 +      {\r
 +              // Just got the required meetings for the first time\r
 +              qDebug() << "RoomStatusIndicatorWidget::connectionEstablished() first call";\r
 +              iDefaultRoomLabel->setHidden( false );\r
 +              iUntilTextLabel->setHidden( false );\r
 +              iStatusLabel->setHidden( false );\r
 +      }\r
 +      else qDebug() << "RoomStatusIndicatorWidget::connectionEstablished()";\r
 +      ViewBase::connectionEstablished();\r
 +      iConnectionLabel->setHidden( true );\r
 +}\r
 +\r
 +void RoomStatusIndicatorWidget::connectionLost()\r
 +{\r
 +      ViewBase::connectionLost();\r
 +      iConnectionLabel->setHidden( false );\r
 +}\r
 +\r
@@@ -12,6 -12,8 +12,8 @@@ class QLabel
  class QVBoxLayout;\r
  class TimeDisplayWidget;\r
  \r
+ class QEvent;\r
\r
  //! UserInterface class. Indicates if the default meeting room is busy or not.\r
  /*!\r
   * UserInterface class. Indicates if the default meeting room is busy or not. This widget\r
@@@ -37,6 -39,8 +39,8 @@@ public
        RoomStatusIndicatorWidget( Room *aDefaultRoom, Room::Status aStatus, QTime aUntil, QString aTimeFormat, QWidget *aParent = 0 );\r
        //! Destructor.\r
        virtual ~RoomStatusIndicatorWidget();\r
+       \r
+       bool event(QEvent *event);\r
  \r
  public slots:\r
        //! Slot. Sets current time.\r
        \r
        void viewResized(const QSize &newSize, const QSize &oldSize) { }\r
  \r
 +      void connectionEstablished();\r
 +      \r
 +      void connectionLost();\r
 +      \r
  private:\r
        //! Translates the status into human readable text.\r
        /*!\r
@@@ -82,7 -82,6 +86,7 @@@ private
        QLabel *iDefaultRoomLabel;\r
        QLabel *iStatusLabel;\r
        QLabel *iUntilTextLabel;\r
 +      QLabel *iConnectionLabel;\r
        TimeDisplayWidget *iTimeDisplay;\r
        QString iTimeFormat;\r
  \r