Status bar fixed
authorRisto Lintinen <lintiri@lintiri-desktop.(none)>
Mon, 24 Aug 2009 09:04:45 +0000 (12:04 +0300)
committerRisto Lintinen <lintiri@lintiri-desktop.(none)>
Mon, 24 Aug 2009 09:04:45 +0000 (12:04 +0300)
src/BusinessLogic/Engine.cpp
src/BusinessLogic/Engine.h
src/BusinessLogic/UIManager.cpp
src/UserInterface/Views/RoomStatusIndicatorWidget.cpp
src/UserInterface/Views/RoomStatusIndicatorWidget.h
src/UserInterface/Views/WeeklyViewWidget.cpp
src/UserInterface/Views/WeeklyViewWidget.h

index e46ddc9..6207440 100644 (file)
@@ -32,8 +32,7 @@ Engine::Engine() :
                iWindowManager( 0 ), iUIManager( 0 )
 {
        qDebug() << "Engine::Engine()";
-       iCommunicationFailed = false;
-       iCurrentWeekFetched = false;
+       iCommunicationFailed = true;
        
        initConfiguration();
        initDevice();
@@ -184,10 +183,14 @@ void Engine::fetchMeetingDetails( Meeting *aMeeting )
 void Engine::meetingsFetched( const QList<Meeting*> &aMeetings )
 {
        qDebug() << "Engine::meetingsFetched( const QList<Meeting*> & )";
-       // TODO: should check if this week's meetings were fetched
-       if( iCommunicationFailed || !iCurrentWeekFetched )
+       QTime c = QTime::currentTime();
+       iLastCommunication.setHMS( c.hour(), c.minute(), c.second() );
+
+       qDebug() << "Error length: "<< iCommunicationError.length();
+       qDebug() << "Error: "<< iCommunicationError;
+
+       if( iCommunicationError.length() == 0 )
        {
-               iCurrentWeekFetched = true;
                iCommunicationFailed = false;
                iUIManager->connectionEstablished();
        }
@@ -210,10 +213,10 @@ void Engine::meetingsFetched( const QList<Meeting*> &aMeetings )
 
 void Engine::errorHandler( int aCode, const QString &aAddInfo )
 {      
+       iCommunicationFailed = true;
+
        if( aCode >= 100 && aCode < 150 )
        {
-               iCommunicationFailed = true;
-
                if ( iUIManager != 0 )
                        {
                                iUIManager->connectionLost();
@@ -221,14 +224,31 @@ void Engine::errorHandler( int aCode, const QString &aAddInfo )
        }
        if ( iWindowManager != 0 )
        {
-               iWindowManager->error( ErrorMapper::codeToString( aCode, aAddInfo ) );
+               iCommunicationError = ErrorMapper::codeToString( aCode, aAddInfo );
+               //iWindowManager->error( ErrorMapper::codeToString( aCode, aAddInfo ) );
        }
 }
 
+bool Engine::connected()
+{
+       return !iCommunicationFailed;
+}
+
+QTime Engine::lastUpdated()
+{
+       return iLastCommunication;
+}
+
+QString Engine::errorMessage()
+{
+       return iCommunicationError;
+}
+
 void Engine::fetchMeetings( const int aWeek, const int aYear, const Room *aIn )
 {
        qDebug()
                        << "Engine::fetchMeetings( const int aWeek, const int aYear, const Room * )";
+       iCommunicationError = "";
        iCommunication->fetchMeetings(aWeek, aYear, *aIn);
 }
 
@@ -240,6 +260,7 @@ void Engine::cancelFetchMeetingDetails()
 void Engine::shownWeekChanged( QDate aFrom )
 {
        qDebug() << "[Engine::shownWeekChanged] <Invoked>";
+       iCommunicationError = "";
        iCommunication->fetchMeetings( aFrom.weekNumber(), aFrom.year(), *iCurrentRoom/*defaultRoom()*/ );
 }
 
index 39ba221..65690a1 100644 (file)
@@ -39,6 +39,10 @@ public:
         */
        Room* defaultRoom();
 
+       bool connected();
+       QTime lastUpdated();
+       QString errorMessage();
+
 signals:
 
        void roomStatusChanged( Room::Status aStatus, QTime aUntil );
@@ -214,7 +218,8 @@ private:
        
        Room *iCurrentRoom;
        bool iCommunicationFailed;
-       bool iCurrentWeekFetched;
+       QString iCommunicationError;
+       QTime iLastCommunication;
 };
 
 #endif /*ENGINE_H_*/
index 089eb9c..0913697 100644 (file)
@@ -253,11 +253,11 @@ void UIManager::updateTime(QDateTime aDateTime)
 {
        if ( iWeeklyView != 0 )
        {
-               iWeeklyView->setCurrentDateTime( aDateTime );
+               iWeeklyView->setConnectionStatus( aDateTime, iEngine->connected(), iEngine->lastUpdated(), iEngine->errorMessage() );
        }
        if ( iRoomStatusIndicator != 0 )
        {
-               iRoomStatusIndicator->setCurrentTime( aDateTime.time() );
+               iRoomStatusIndicator->setConnectionStatus( aDateTime, iEngine->connected(), iEngine->lastUpdated(), iEngine->errorMessage() );
        }
 }
 
index ca53b9d..d71fcb1 100644 (file)
@@ -132,7 +132,7 @@ QPalette RoomStatusIndicatorWidget::createPalette(Room::Status aStatus)
        int cropheight(pixmap.height() - yoffset);
 
        QBrush brush;
-       if (windowState() == Qt::WindowFullScreen)
+       if ( (pixmap.width() == rect().width()) && (pixmap.height() == rect().height()) )
        {
                // Use the full image in full screen mode
                brush.setTexture(pixmap);
@@ -151,11 +151,38 @@ QPalette RoomStatusIndicatorWidget::createPalette(Room::Status aStatus)
        return palette;
 }
 
-void RoomStatusIndicatorWidget::setCurrentTime(QTime aCurrentTime)
+void RoomStatusIndicatorWidget::setConnectionStatus( QDateTime aCurrentTime, bool aConnected,
+               QTime aLastUpdated, QString aError )
 {
        iTimeDisplay->setText( aCurrentTime.toString( iTimeFormat ) );
+       if ( aLastUpdated.isNull() )
+               iStatusBar->setText( tr("Disconnected") , BorderedBarWidget::LeftAlign );
+       else
+       {
+               iDefaultRoomLabel->setHidden( false );
+               iUntilTextLabel->setHidden( false );
+               iStatusLabel->setHidden( false );
+
+               if (!aConnected)
+               {
+                       iStatusBar->setText( tr("Disconnected").arg(aLastUpdated.toString(iTimeFormat))
+                                       , BorderedBarWidget::LeftAlign );
+               }
+               else
+               {
+                       iStatusBar->setText( tr("Connected - Last update %1").arg(aLastUpdated.toString(iTimeFormat)) ,
+                                       BorderedBarWidget::LeftAlign );
+               }
+       }
+       showError( aError );
+}
+
+void RoomStatusIndicatorWidget::showError( QString aError )
+{
+       iStatusBar->setText( aError );
 }
 
+
 void RoomStatusIndicatorWidget::statusChanged(const Room::Status aStatus, const QTime aUntil)
 {
        iStatusLabel->setText(tr( "is %1" ).arg(statusToText(aStatus) ) );
@@ -195,24 +222,10 @@ bool RoomStatusIndicatorWidget::event(QEvent *event)
 
 void RoomStatusIndicatorWidget::connectionEstablished()
 {
-       if ( !connectedOnce)
-       { 
-               // Just got the required meetings for the first time              
-               qDebug() << "RoomStatusIndicatorWidget::connectionEstablished() first call";
-               iDefaultRoomLabel->setHidden( false);
-               iUntilTextLabel->setHidden( false);
-               iStatusLabel->setHidden( false);
-       }
-       else
-       {
-               qDebug() << "RoomStatusIndicatorWidget::connectionEstablished()";
-       }
        ViewBase::connectionEstablished();
-       iStatusBar->setText( tr("Connected"), BorderedBarWidget::LeftAlign );
 }
 
 void RoomStatusIndicatorWidget::connectionLost()
 {
        ViewBase::connectionLost();
-       iStatusBar->setText( tr("Disconnected"), BorderedBarWidget::LeftAlign );
 }
index bf82485..c9256dc 100644 (file)
@@ -43,13 +43,14 @@ public:
        bool event(QEvent *event);\r
 \r
 public slots:\r
-       //! Slot. Sets current time.\r
+       //! Slot. Sets the connection status\r
        /*!\r
-        * Slots. Sets current time on the widget. It is used to provide up-to-date time for the widget's\r
-        * TimeDisplayWidget.\r
-        * \param aCurrentTime The current time.\r
+        * Sets the current time, and connection status\r
+        * \param aCurrentTime Time to be displayed.\r
+        * \param aConnected connection status to be displayed.\r
+        * \param aLastUpdated Time of last successful connection to be displayed.\r
         */\r
-       void setCurrentTime( QTime aCurrentTime );\r
+       void setConnectionStatus( QDateTime aCurrentTime, bool aConnected, QTime aLastUpdated = QTime(), QString aError = "");\r
        //! Slot. Used to indicate changes in the status of the default room.\r
        /*!\r
         * Slot. Used to indicate changes in the status of the default room. If the specified until time equals\r
@@ -60,6 +61,8 @@ public slots:
         */\r
        void statusChanged( const Room::Status aStatus, const QTime aUntil );\r
        \r
+       void showError( QString aError );\r
+\r
        void currentRoomChanged( Room *aRoom );\r
        \r
        void viewResized(const QSize &/*newSize*/, const QSize &/*oldSize*/) { }\r
index 6c8b75c..0c9b61f 100644 (file)
@@ -76,6 +76,7 @@ WeeklyViewWidget::WeeklyViewWidget( QDateTime aCurrentDateTime, Configuration *a
        iStatusBar->setFixedHeight( 28 );\r
        QPixmap pixmap(":ixonos_logo");\r
        iStatusBar->setPixmap( pixmap );\r
+       iStatusBar->setText( tr("Disconnected"), BorderedBarWidget::LeftAlign );\r
 \r
        iSchedule = new ScheduleWidget( aCurrentDateTime, iConfiguration->displaySettings(), this );\r
        connect( iSchedule, SIGNAL( shownWeekChanged( QDate ) ), this, SIGNAL( shownWeekChanged( QDate ) ) );\r
@@ -227,15 +228,34 @@ Room* WeeklyViewWidget::currentRoom()
        return iRoomsCombo->currentRoom();\r
 }\r
 \r
-void WeeklyViewWidget::setCurrentDateTime( QDateTime aCurrentDateTime )\r
+void WeeklyViewWidget::setConnectionStatus( QDateTime aCurrentTime, bool aConnected,\r
+               QTime aLastUpdated, QString aError )\r
 {\r
-       iCurrentDayLabel->setText( aCurrentDateTime.date().toString( iConfiguration->displaySettings()->dateFormat() ) );\r
+       iCurrentDayLabel->setText( aCurrentTime.date().toString( iConfiguration->displaySettings()->dateFormat() ) );\r
+       iCurrentWeekLabel->setText( tr( "Wk %1" ).arg( aCurrentTime.date().weekNumber() ) );\r
+       iSchedule->setCurrentDateTime( aCurrentTime );\r
        \r
-       iCurrentWeekLabel->setText( tr( "Wk %1" ).arg( aCurrentDateTime.date().weekNumber() ) );\r
-\r
-       iTimeDisplay->setText( aCurrentDateTime.toString( iConfiguration->displaySettings()->timeFormat() ) );\r
+       iTimeDisplay->setText( aCurrentTime.toString( iConfiguration->displaySettings()->timeFormat() ) );\r
+       if ( aLastUpdated.isNull() )\r
+               iStatusBar->setText( tr("Disconnected") , BorderedBarWidget::LeftAlign );\r
+       else if ( !aConnected )\r
+       {\r
+               iStatusBar->setText( tr("Disconnected")\r
+                               .arg(aLastUpdated.toString(iConfiguration->displaySettings()->timeFormat()))\r
+                               , BorderedBarWidget::LeftAlign );\r
+       }\r
+       else\r
+       {\r
+               iStatusBar->setText( tr("Connected - Last update %1")\r
+                               .arg(aLastUpdated.toString(iConfiguration->displaySettings()->timeFormat())) ,\r
+                               BorderedBarWidget::LeftAlign );\r
+       }\r
+       showError( aError );\r
+ }\r
 \r
-       iSchedule->setCurrentDateTime( aCurrentDateTime );\r
+void WeeklyViewWidget::showError( QString aError )\r
+{\r
+       iStatusBar->setText( aError );\r
 }\r
 \r
 QDate WeeklyViewWidget::beginnigOfShownWeek()\r
@@ -262,12 +282,9 @@ void WeeklyViewWidget::setDefaultRoom()
 void WeeklyViewWidget::connectionEstablished()\r
 {\r
        ViewBase::connectionEstablished();\r
-       qDebug() << "WeeklyViewWidget::connectionEstablished";\r
-       iStatusBar->setText( tr("Connected"), BorderedBarWidget::LeftAlign );\r
 }\r
 \r
 void WeeklyViewWidget::connectionLost()\r
 {\r
        ViewBase::connectionLost();\r
-       iStatusBar->setText( tr("Disconnected"), BorderedBarWidget::LeftAlign );\r
 }\r
index 0fcd1cb..a9632a2 100644 (file)
@@ -112,12 +112,14 @@ signals:
        void shownWeekChanged( QDate aDate );
 
 public slots:
-       //! Sets the date and time
+       //! Slot. Sets the connection status
        /*!
-        * Sets the current date and time
-        * \param aCurrentDateTime Date and time to be displayd.
+        * Sets the current time, and connection status
+        * \param aCurrentTime Time to be displayed.
+        * \param aConnected connection status to be displayed.
+        * \param aLastUpdated Time of last successful connection to be displayed.
         */
-       void setCurrentDateTime( QDateTime aCurrentDateTime );
+       void setConnectionStatus( QDateTime aCurrentTime, bool aConnected, QTime aLastUpdated = QTime(), QString aError = "" );
        //! Handle resizing
        /*!
         * Handle possible resize changes after the view is resized
@@ -125,6 +127,8 @@ public slots:
         */
        void viewResized(const QSize &/*newSize*/, const QSize &/*oldSize*/) { }
 
+       void showError( QString aError );
+
        void connectionEstablished();
 
        void connectionLost();