Merged and got it partly working
authorMikko Siren <mikko.siren@ixonos.com>
Wed, 27 May 2009 13:05:51 +0000 (16:05 +0300)
committerMikko Siren <mikko.siren@ixonos.com>
Wed, 27 May 2009 13:05:51 +0000 (16:05 +0300)
1  2 
src/BusinessLogic/Engine.cpp
src/BusinessLogic/Engine.h
src/BusinessLogic/UIManager.cpp
src/UserInterface/Views/WeeklyViewWidget.cpp
src/UserInterface/Views/WeeklyViewWidget.h

@@@ -178,7 -204,32 +178,7 @@@ void Engine::fetchMeetings(
        fetchMeetings(iClock->datetime(), iClock->datetime().addDays( 7), room);
  }
  
- bool Engine::isMeetingInList( const QList<Meeting*> &aList, const Meeting *aMeeting )
 -void Engine::fetchMeetingDetails(Meeting *aMeeting)
 -{
 -      qDebug() << "Engine::fetchMeetingDetails( Meeting* )";
 -      iWindowManager->showProgressBar(tr("Please Wait"), true);
 -      iWindowManager->updateProgressBar(tr("Fetching Meeting Details...") );
 -      connect(iWindowManager, 
 -      SIGNAL( progressBarCancelled() ), this, 
 -      SLOT( fetchMeetingDetailsCancelled() ));
 -      iCommunication->fetchMeetingDetails( *aMeeting);
 -}
 -
 -<<<<<<< HEAD:src/BusinessLogic/Engine.cpp
 -void Engine::meetingsFetched( const QList<Meeting*> &aMeetings )
 -{
 -      qDebug() << "Engine::meetingsFetched( const QList<Meeting*> & )";
 -      
 -      for ( int i = 0; i < iMeetings.count(); ++i ) {
 -              Meeting* m = iMeetings.takeAt( i );
 -              delete m;
 -      }
 -      iMeetings.clear();
 -      for ( int i = 0; i < aMeetings.count(); ++i ) {
 -              Meeting* m = new Meeting( *(aMeetings.at( i )) );
 -              iMeetings.append( m );
 -=======
+ bool Engine::isMeetingInList(const QList<Meeting*> &aList, const Meeting *aMeeting)
  {
        qDebug()
                        << "Engine::isMeetingInList( const QList<Meeting*> &, const Meeting * )";
  void Engine::meetingsFetched(const QList<Meeting*> &aMeetings)
  {
        qDebug() << "Engine::meetingsFetched( const QList<Meeting*> & )";
++      
        // check if there is any new meeting in the list came from the server -> added
        for (int i = 0; i < aMeetings.count(); i++)
        {
                        // add to the local database =)
                        Meeting* m = new Meeting( *(aMeetings.at( i )) );
                        iMeetings.append(m);
--                      // and signal the changes
 -                      iWindowManager->insertMeeting(m);
                }
        }
  
                if ( !isMeetingInList(aMeetings, iMeetings.at(i) ) )
                {
                        Meeting* m = iMeetings.takeAt(i);
--                      // signal the changes
 -                      iWindowManager->deleteMeeting(m);
                        // delete the meeting from the local list
                        delete m;
                }
@@@ -41,8 -39,8 +41,6 @@@ public
  
  signals:
  
--      void meetingDetailsFetched( Meeting *aDetailedMeeting );        
--
  private slots:
        //! Slot. Closes the application.
        /*!
@@@ -162,39 -158,7 +152,41 @@@ private
         * \param aIn The room which meetings need to be fetched.
         */
        void fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn );
 +      //! Initialize configuration package.
 +      /*!
 +       * This method initializes configuration classes and
 +       * connects signals from and to the engine.
 +       */
 +      void initConfiguration();
 +      //! Initialize device package.
 +      /*!
 +       * This method initializes device manager and
 +       * connects signals from and to the engine.
 +       */
 +      void initDevice();
 +      //! Initialize communication package.
 +      /*!
 +       * This method initializes the communication manager and
 +       * connects signals from and to the engine.
 +       */
 +      void initCommunication();
 +      //! Initialize user interface package.
 +      /*!
 +       * This method initializes the user interface and
 +       * connects signals from and to the engine. This method
 +       * makes the window manager visible and shows weekly
 +       * view as the first view.
 +       */
 +      void initUserInterface();
 +      //! Connects signal between objects.
 +      /*!
 +       * Signals that could not be connected while initializing different
 +       * packages are connected here.
 +       */
 +      void connectSignals();
+       
++      bool isMeetingInList(const QList<Meeting*> &aList, const Meeting *aMeeting);
 +
  private:
        static QTime endOfTheDay;
  
index 7e24d61,0000000..9455bb0
mode 100644,000000..100644
--- /dev/null
@@@ -1,296 -1,0 +1,295 @@@
 +#include "UIManager.h"
 +
 +#include <QDateTime>
 +#include <QTime>
 +
 +#include "Engine.h"
 +#include "WindowManager.h"
 +#include "ViewBase.h"
 +#include "WeeklyViewWidget.h"
 +#include "SettingsView.h"
 +#include "RoomStatusIndicatorWidget.h"
 +#include "MeetingInfoDialog.h"
 +#include "ProgressBar.h"
 +#include "CommunicationManager.h"
 +#include "Configuration.h"
 +#include "DisplaySettings.h"
 +
 +#include <QtDebug>
 +
 +#define QT_DELETE(X) \
 +      if ( X != 0 ) \
 +      { \
 +              delete X; \
 +              X = 0; \
 +      }
 +
 +UIManager::UIManager( Engine *aEngine, WindowManager *aWindowManager ) :
 +      iEngine( aEngine ),
 +      iWindowManager( aWindowManager ),
 +      iWeeklyView( 0 ),
 +      iSettingsView( 0 ),
 +      iRoomStatusIndicator( 0 ),
 +      iPasswordDialog( 0 ),
 +      iProgressBar( 0 ),
 +      iMeetingInfo( 0 )
 +{
 +      if ( iEngine == 0 ) return;
 +      if ( iWindowManager == 0 ) return;
 +      
 +      qDebug() << "[UIManager::ctor] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
 +      
 +      createWeeklyView();
 +      createSettingsView();
 +      createRoomStatusIndicator();
 +      createPasswordDialog();
 +      createProgressBar();
 +      createMeetingInfoDialog();
 +      
 +      qDebug() << "[UIManager::ctor] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
 +}
 +
 +UIManager::~UIManager()
 +{
 +      iEngine = 0;
 +      iWindowManager = 0;
 +      
 +      QT_DELETE( iMeetingInfo );
 +      QT_DELETE( iProgressBar );
 +      QT_DELETE( iPasswordDialog );
 +      QT_DELETE( iRoomStatusIndicator );
 +      QT_DELETE( iSettingsView );
 +      QT_DELETE( iWeeklyView );
 +}
 +
 +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()
 +{
 +      iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), iEngine->iConfiguration );
 +      
 +      // Connect signals to UIManager
 +      connect( iWeeklyView, SIGNAL( settingsButtonClicked() ), this, SLOT( settingsViewRequest() ) );
 +      connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), this, SLOT( currentRoomChanged( Room * ) ) );
 +      connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), this, SLOT( showMeetingProgressBar( Meeting * ) ) );
 +      // Connect signals to engine
 +      connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), iEngine, SLOT( fetchMeetingDetails( Meeting * ) ) );
 +      connect( iWeeklyView, SIGNAL( shownWeekChanged( QDate ) ), iEngine, SLOT( shownWeekChanged( QDate ) ) );
 +}
 +
 +void UIManager::createSettingsView()
 +{
 +      iSettingsView = new SettingsView;
 +      
 +      // Connect signals
 +      connect( iSettingsView, SIGNAL( okClicked() ), this, SLOT( settingsOkClicked() ) );
 +}
 +
 +void UIManager::createRoomStatusIndicator()
 +{
 +      iRoomStatusIndicator = new RoomStatusIndicatorWidget( iEngine->defaultRoom(), Room::FreeStatus, QTime::currentTime(), iEngine->iConfiguration->displaySettings()->dateFormat() );
 +}
 +
 +void UIManager::createPasswordDialog()
 +{
 +      iPasswordDialog = new PasswordDialog( iEngine->iConfiguration->adminPassword(), tr("UIManager::createPasswordDialog"), tr("UIManager::createPasswordDialog") );
 +      
 +      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
 +      connect( iProgressBar, SIGNAL( cancel() ), iEngine, SLOT( cancelFetchMeetingDetails() ) );
 +}
 +
 +void UIManager::createMeetingInfoDialog()
 +{
 +      iMeetingInfo = new MeetingInfoDialog();
 +}
 +
 +void UIManager::connectDeviceManager( DeviceManager *aDeviceManager )
 +{
 +      connect( aDeviceManager, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ),
 +                      this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) );
 +      
 +      connect( aDeviceManager, SIGNAL( changingMode( const QString & ) ), this, SLOT( updateProgressBarText( const QString & ) ) );
 +      connect( aDeviceManager, SIGNAL( changeModeFailed() ), this, SLOT( hideProgressBar() ) );
 +}
 +
 +void UIManager::connectCommunicationManager( CommunicationManager *aCommunicationManager )
 +{
-       connect( aCommunicationManager, SIGNAL( meetingDetailsFetched( Meeting & ) ), this, SLOT( meetingDetailsFetched( Meeting & ) ) );
++//    connect( aCommunicationManager, SIGNAL( meetingDetailsFetched( Meeting & ) ), this, SLOT( meetingDetailsFetched( Meeting & ) ) );
 +      connect( aCommunicationManager, SIGNAL( meetingsFetched( const QList<Meeting *> & ) ), this, SLOT( meetingsFetched( const QList<Meeting *> & ) ) );
 +}
 +
 +// ============================================
 +//            UIMANAGER SLOTS
 +void UIManager::settingsViewRequest()
 +{
 +      // Show the settings view and stop the idle timer
 +      if ( iSettingsView != 0 )
 +      {
 +              iWindowManager->showView( static_cast<ViewBase *>( iSettingsView ) );
 +              iEngine->stopIdleTimeCounter();
 +      }
 +}
 +
 +void UIManager::settingsOkClicked()
 +{
 +      // Show the weekly view and restart the idle timer
 +      if ( iWeeklyView != 0 )
 +      {
 +              iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
 +              iEngine->startIdleTimeCounter();
 +      }
 +}
 +
 +void UIManager::meetingsFetched( const QList<Meeting*> &aMeetings )
 +{
-       qDebug() << "[UIManager::meetingsFetched] <SHOULD NOT SIMPLY INSERT MEETINGS TO WEEKLYVIEW !!!>";
-       for ( int i = 0; i < aMeetings.count(); i++ )
++      qDebug() << "[UIManager::meetingsFetched] <Change the weekly views method to slot so we don't need this>";
++      if ( iWeeklyView != 0 )
 +      {
-               Meeting *m = new Meeting( *( aMeetings.at(i) ) );
-               iWeeklyView->insertMeeting( m );
++              iWeeklyView->refreshMeetings( aMeetings );
 +      }
 +}
 +
 +void UIManager::showMeetingProgressBar( Meeting *aMeeting )
 +{
 +      if ( iProgressBar != 0 )
 +      {
 +              iProgressBar->update( tr("Fetching meeting info...") );
 +              iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false );
 +      }
 +}
 +
 +void UIManager::meetingDetailsFetched(Meeting &aDetailedMeeting)
 +{
 +      qDebug() << "[UIManager::meetingDetailsFetched] <Invoked>";
 +      if ( iMeetingInfo != 0 )
 +      {
 +              if ( iProgressBar != 0 && iProgressBar->isVisible() )
 +              {
 +                      iProgressBar->close(); // Close it in case it's visible
 +              }
 +              // iMeetingInfo->setMeeting( &aDetailedMeeting );
 +              MeetingInfoDialog *tmp = new MeetingInfoDialog( &aDetailedMeeting );
 +              iWindowManager->showDialog( static_cast<QDialog *>( tmp/*iMeetingInfo*/ ) );
 +      }
 +}
 +
 +void UIManager::roomStatusIndicatorRequested()
 +{
 +      if ( iRoomStatusIndicator != 0 )
 +      {
 +              iWindowManager->showView( static_cast<ViewBase *>( iRoomStatusIndicator ) );
 +              iEngine->stopIdleTimeCounter();
 +      }
 +}
 +
 +void UIManager::previousViewRestored()
 +{
 +      iEngine->startIdleTimeCounter();
 +}
 +
 +void UIManager::progressBarCancelled()
 +{
 +      if ( iProgressBar != 0 )
 +      {
 +              iProgressBar->close();
 +      }
 +}
 +
 +void UIManager::changeModeOrdered( DeviceManager::OperationMode aMode )
 +{
 +      qDebug() << "[UIManager::changeModeOrdered] <Invoked>";
 +      
 +      QString message = tr( "You are about to change operation mode to %1." )
 +                              .arg( iEngine->iDevice->operationModeToString( aMode ) );
 +
 +      if ( iPasswordDialog != 0 )
 +      {
 +              // TODO : Set the new text for password dialog
 +              iWindowManager->showDialog( static_cast<QDialog *>( iPasswordDialog ) );
 +      }
 +}
 +
 +void UIManager::currentRoomChanged(Room *aRoom)
 +{
 +      if ( iWeeklyView != 0 )
 +      {
 +              QDateTime from = QDateTime( iWeeklyView->beginnigOfShownWeek() );
 +              QDateTime to = QDateTime( from.addDays( 8 ) );
 +              iEngine->fetchMeetings( from, to, aRoom );
 +      }
 +}
 +
 +void UIManager::updateTime(QDateTime aDateTime)
 +{
 +      if ( iWeeklyView != 0 )
 +      {
 +              iWeeklyView->setCurrentDateTime( aDateTime );
 +      }
 +}
 +
 +void UIManager::passwordEntered( PasswordDialog::PasswordStatus aStatus )
 +{
 +      switch( aStatus )
 +      {
 +              case PasswordDialog::Correct:
 +                      // Show the progress bar..
 +                      if ( iProgressBar != 0 )
 +                      {
 +                              iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false );
 +                      }
 +                      // ... and initiate the mode changing
 +                      iEngine->changeDeviceMode( true );
 +                      break;
 +              case PasswordDialog::Incorrect:
 +                      iWindowManager->error( tr("Incorrect Password") );
 +              case PasswordDialog::Canceled:
 +                      iEngine->changeDeviceMode( false );
 +                      break;
 +      }
 +      
 +      // Close the dialog after we have handled the status
 +      if ( iPasswordDialog != 0 )
 +      {
 +              iPasswordDialog->close();
 +      }
 +}
 +
 +void UIManager::updateProgressBarText(const QString &aText)
 +{
 +      if ( iProgressBar != 0 )
 +      {
 +              iProgressBar->update( aText );
 +      }
 +}
 +
 +void UIManager::hideProgressBar()
 +{
 +      qDebug() << "[UIManager::hideProgressBar] <Invoked>";
 +      if ( iProgressBar != 0 && iProgressBar->isVisible() )
 +      {
 +              iProgressBar->close();
 +      }
 +}
@@@ -108,13 -100,12 +108,12 @@@ WeeklyViewWidget::WeeklyViewWidget( QDa
        // ******************************************\r
        //              Handle all the signal connections\r
        // TODO : this solution if interaction monitoring is not elegant enough\r
 -      connect( iPreviousWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
 -      connect( iCurrentWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
 -      connect( iNextWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
 -      connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( observedEventDetected() ) );\r
 -      connect( iRoomsCombo, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( observedEventDetected() ) );\r
 +//    connect( iPreviousWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
 +//    connect( iCurrentWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
 +//    connect( iNextWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) );\r
 +//    connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( observedEventDetected() ) );\r
 +//    connect( iRoomsCombo, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( observedEventDetected() ) );\r
        // TODO: connect RoomCombo signals to change meetings data.\r
-       connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), iSchedule, SLOT( clear() ) );\r
        connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( currentRoomChanged( Room * ) ) );\r
        connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), iSchedule, SLOT( refresh() ) );\r
  }\r
@@@ -123,31 -117,6 +117,12 @@@ public slots
         * \param aCurrentDateTime Date and time to be displayd.\r
         */\r
        void setCurrentDateTime( QDateTime aCurrentDateTime );\r
-       //! Insert meeting\r
-       /*!\r
-        * Inserts new meeting into the calendar\r
-        * \param aMeeting Meeting to be inserted.\r
-        */\r
-       void insertMeeting( Meeting *aMeeting );\r
-       //! Delete meeting\r
-       /*!\r
-        * Removes meeting from the calendar\r
-        * \param aMeeting Meeting to be deleted.\r
-        */\r
-       void deleteMeeting( Meeting *aMeeting );\r
-       //! Update meeting\r
-       /*!\r
-        * Updates the display of given meeting in calendar.\r
-        * \param aMeeting Meeting to be updated.\r
-        */\r
-       void updateMeeting( Meeting *aMeeting );\r
-       \r
 +      //! Handle resizing\r
 +      /*!\r
 +       * Handle possible resize changes after the view is resized\r
 +       * to match the window managers client area.\r
 +       */\r
 +      void viewResized(const QSize &newSize, const QSize &oldSize) { }\r
  \r
  private:\r
        //! Displays the selectable meeting rooms.\r