From: Mikko Siren Date: Wed, 27 May 2009 13:05:51 +0000 (+0300) Subject: Merged and got it partly working X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=2cf43eccdaf498030f5155f66385ca7d8b9fc483;hp=47ed106398a5c3ac172e2ea7cc5fb983649d18cf;p=qtmeetings Merged and got it partly working --- diff --git a/QtMeetings.pro b/QtMeetings.pro index c57d210..121575b 100644 --- a/QtMeetings.pro +++ b/QtMeetings.pro @@ -13,7 +13,8 @@ INCLUDEPATH += src/Domain/ \ src/UserInterface/Components/ \ src/UserInterface/Utils/ \ src/UserInterface/Views/ -HEADERS += src/IO/DeviceControl/OperationModeToggler.h \ +HEADERS += src/BusinessLogic/UIManager.h \ + src/IO/DeviceControl/OperationModeToggler.h \ src/UserInterface/Utils/ProgressBar.h \ src/Domain/Room.h \ src/Domain/Meeting.h \ @@ -44,8 +45,10 @@ HEADERS += src/IO/DeviceControl/OperationModeToggler.h \ src/UserInterface/Views/WeeklyViewWidget.h \ src/UserInterface/Views/MeetingInfoDialog.h \ src/UserInterface/Views/SettingsView.h \ - src/UserInterface/WindowManager.h -SOURCES += src/IO/DeviceControl/OperationModeToggler.cpp \ + src/UserInterface/WindowManager.h \ + src/UserInterface/Views/ViewBase.h +SOURCES += src/BusinessLogic/UIManager.cpp \ + src/IO/DeviceControl/OperationModeToggler.cpp \ src/UserInterface/Utils/ProgressBar.cpp \ src/Domain/Room.cpp \ src/Domain/Meeting.cpp \ @@ -77,6 +80,7 @@ SOURCES += src/IO/DeviceControl/OperationModeToggler.cpp \ src/UserInterface/Views/MeetingInfoDialog.cpp \ src/UserInterface/Views/SettingsView.cpp \ src/UserInterface/WindowManager.cpp \ + src/UserInterface/Views/ViewBase.cpp \ src/main.cpp RESOURCES += resources/BusinessLogic.qrc \ resources/UserInterface.qrc diff --git a/src/BusinessLogic/Engine.cpp b/src/BusinessLogic/Engine.cpp index 104bbdf..1a79851 100644 --- a/src/BusinessLogic/Engine.cpp +++ b/src/BusinessLogic/Engine.cpp @@ -5,10 +5,10 @@ #include "Configuration.h" #include "DisplaySettings.h" #include "CommunicationManager.h" -#include "DeviceManager.h" +// #include "DeviceManager.h" #include "Clock.h" #include "ErrorMapper.h" -#include "WeeklyViewWidget.h" +#include "UIManager.h" #include #include @@ -18,61 +18,53 @@ QTime Engine::endOfTheDay = QTime( 23, 59, 0, 0); // end of the day is 11:59pm const int IDLE_TIME_MULTIPLIER = 60000; // Multiplies milliseconds to minutes -Engine::Engine() : - iClock( 0), iConfiguration(Configuration::instance() ), iCommunication( 0) -{ - qDebug() << "Engine::Engine()"; - // if reading of configuration fails, signal that initialization failed - if (iConfiguration == 0) - { - QTimer::singleShot( 0, this, SLOT( closeApplication() )); - return; +// Macro to help deleting objects. This could be global. +#define QT_DELETE(X) \ + if ( X != 0 ) \ + { \ + delete X; \ + X = 0; \ } - //initialize window manager - iWindowManager = new WindowManager( iConfiguration ); - connect(iWindowManager, SIGNAL( roomStatusInfoNeeded( Room * ) ), this, SLOT( roomStatusInfoNeeded( Room * ) )); - connect(iWindowManager, SIGNAL( observedEventDetected() ), this, SLOT( observedEventDetected() )); - connect(iWindowManager, SIGNAL( meetingActivated( Meeting * ) ), this, SLOT( fetchMeetingDetails( Meeting * ) )); - connect(iWindowManager, SIGNAL( currentRoomChanged( Room * ) ), this, SLOT( currentRoomChanged( Room * ) )); - connect(iWindowManager, SIGNAL( shownWeekChanged( QDate ) ), this, SLOT( shownWeekChanged( QDate ) )); - connect(iWindowManager, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) )); - - // initialize communication - iCommunication = new CommunicationManager( *(iConfiguration->connectionSettings()) ); - connect(iCommunication, SIGNAL( error( int, CommunicationManager::CommunicationType ) ), this, SLOT( errorHandler( int ) )); - connect(iCommunication, SIGNAL( meetingsFetched( const QList& ) ), this, SLOT( meetingsFetched( const QList& ) )); - connect(iCommunication, SIGNAL( meetingDetailsFetched( Meeting& ) ), this, SLOT( meetingDetailsFetched( Meeting& ) )); +Engine::Engine() : + iClock( 0 ), iConfiguration( 0 ), iCommunication( 0 ), + iWindowManager( 0 ), iUIManager( 0 ) +{ + qDebug() << "Engine::Engine()"; + + initConfiguration(); + initDevice(); + initCommunication(); + initUserInterface(); + //initialize idle time counter iIdleTimeCounter = new QTimer(); - iIdleTimeCounter->setSingleShot( true); - iIdleTimeCounter->setInterval(IDLE_TIME_MULTIPLIER - * iConfiguration->displaySettings()->screensaver() ); + iIdleTimeCounter->setSingleShot( true ); + // iIdleTimeCounter->setInterval( IDLE_TIME_MULTIPLIER * iConfiguration->displaySettings()->screensaver() ); + iIdleTimeCounter->setInterval( 10000 ); iIdleTimeCounter->start(); - connect(iIdleTimeCounter, SIGNAL( timeout() ), iWindowManager, SLOT( showRoomStatus() )); // create application clock iClock = new Clock; - connect(iClock, SIGNAL( tick( QDateTime ) ), this, SLOT( checkStatusOfAllRooms() )); - connect(iClock, SIGNAL( tick( QDateTime ) ), iWindowManager, SLOT( distributeDateTimeInfo( QDateTime ) )); + connect( iClock, SIGNAL( tick( QDateTime ) ), this, SLOT( checkStatusOfAllRooms() ) ); + // connect( iClock, SIGNAL( tick( QDateTime ) ), iWindowManager, SLOT( distributeDateTimeInfo( QDateTime ) ) ); + // Create auto refresh timer iAutoRefresh = new QTimer; iAutoRefresh->setInterval(iConfiguration->connectionSettings()->refreshInterval() * 1000); iAutoRefresh->start(); - connect(iAutoRefresh, SIGNAL( timeout() ), iAutoRefresh, SLOT( start() )); - connect(iAutoRefresh, SIGNAL( timeout() ), this, SLOT( fetchMeetings() )); - - // create device manager - iDevice = new DeviceManager( iConfiguration->startupSettings() ); - connect(iDevice, SIGNAL( error( int, const QString& ) ), this, SLOT( errorHandler( int, const QString& ) )); - connect(iDevice, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ), this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) )); - iDevice->initDeviceManager(); - - if (iDevice->currentOperationMode() == DeviceManager::KioskMode) - iWindowManager->fullScreen(); + connect( iAutoRefresh, SIGNAL( timeout() ), iAutoRefresh, SLOT( start() ) ); + connect( iAutoRefresh, SIGNAL( timeout() ), this, SLOT( fetchMeetings() ) ); + + if( iDevice->currentOperationMode() == DeviceManager::KioskMode ) + { + iWindowManager->setFullscreen(); + } - QTimer::singleShot( 0, this, SLOT( fetchMeetings() )); + connectSignals(); + + QTimer::singleShot( 0, this, SLOT( fetchMeetings() ) ); // TODO: continue implementation } @@ -82,15 +74,18 @@ Engine::~Engine() qDebug() << "Engine::~Engine()"; while ( !iMeetings.isEmpty() ) delete iMeetings.takeFirst(); - iIdleTimeCounter->stop(); - delete iIdleTimeCounter; - iIdleTimeCounter = 0; - delete iWindowManager; - iWindowManager = 0; - delete iClock; - iClock = 0; - delete iDevice; - iDevice = 0; + + if ( iIdleTimeCounter != 0 ) + { + iIdleTimeCounter->stop(); + delete iIdleTimeCounter; + iIdleTimeCounter = 0; + } + QT_DELETE( iClock ); + QT_DELETE( iDevice ); + + QT_DELETE( iUIManager ); + QT_DELETE( iWindowManager ); } void Engine::closeApplication() @@ -100,27 +95,6 @@ void Engine::closeApplication() QTimer::singleShot( 1000, QApplication::instance(), SLOT( quit() )); } -void Engine::observedEventDetected() -{ - qDebug() << "Engine::observedEventDetected()"; -<<<<<<< HEAD:src/BusinessLogic/Engine.cpp - iWindowManager->refreshMeetings( iMeetings ); -======= - if ( !iIdleTimeCounter->isActive() ) - { - iWindowManager->weeklyView()->showCurrentWeek(); - } - iWindowManager->showWeeklyView(); ->>>>>>> 56f763c68a2ff56d344ef150b7378ca417d08b36:src/BusinessLogic/Engine.cpp - // prepare to restart idle counter - if (iIdleTimeCounter->isActive() ) - { - iIdleTimeCounter->stop(); - } - // (re)start idle counter - iIdleTimeCounter->start(); -} - Room* Engine::defaultRoom() { qDebug() << "Engine::defaultRoom()"; @@ -129,7 +103,7 @@ Room* Engine::defaultRoom() void Engine::checkStatusOfAllRooms() { - qDebug() << "Engine::checkStatusOfAllRooms()"; +// qDebug() << "Engine::checkStatusOfAllRooms()"; // iterate trough on the rooms for (int i = 0; i < iConfiguration->rooms().count(); i++) { @@ -140,8 +114,8 @@ void Engine::checkStatusOfAllRooms() int Engine::indexOfMeetingAt(Room *aRoom, QDateTime aAt) { - qDebug() << "Engine::indexOfMeetingAt( Room *, QDateTime )"; - for (int i = 0; i < iMeetings.count(); i++) +// qDebug() << "Engine::indexOfMeetingAt( Room *, QDateTime )"; + for ( int i = 0; i < iMeetings.count(); i++ ) { // exchange server ensures that there is only one meeting in a room at a specified time if (aRoom->equals(iMeetings.at( i )->room() ) && iMeetings.at( i )->startsAt() <= aAt && iMeetings.at( i )->endsAt() >= aAt) @@ -154,7 +128,7 @@ int Engine::indexOfMeetingAt(Room *aRoom, QDateTime aAt) int Engine::indexOfMeetingAfter(Room *aRoom, QDateTime aAfter) { - qDebug() << "Engine::indexOfMeetingAfter( Room *, QDateTime )"; +// qDebug() << "Engine::indexOfMeetingAfter( Room *, QDateTime )"; // seeks for the next meeting on the SAME DAY int min = -1; for (int i = 0; i < iMeetings.count(); i++) @@ -174,8 +148,8 @@ int Engine::indexOfMeetingAfter(Room *aRoom, QDateTime aAfter) void Engine::roomStatusInfoNeeded(Room *aRoom) { - qDebug() << "Engine::roomStatusInfoNeeded( Room * )"; - if (aRoom == 0) +// qDebug() << "Engine::roomStatusInfoNeeded( Room * )"; + if ( aRoom == 0 ) { return; } @@ -193,8 +167,8 @@ void Engine::roomStatusInfoNeeded(Room *aRoom) ((indexOfNextMeeting != -1 ) ? iMeetings.at( indexOfNextMeeting )->startsAt().time() : Engine::endOfTheDay ); //currently works only for deafult room - if (aRoom->equals( *(defaultRoom() )) ) - iWindowManager->roomStatusChanged(aRoom, status, until); +// if( aRoom->equals( *(defaultRoom() ) ) ) +// iWindowManager->roomStatusChanged( aRoom, status, until ); } void Engine::fetchMeetings() @@ -204,31 +178,6 @@ void Engine::fetchMeetings() fetchMeetings(iClock->datetime(), iClock->datetime().addDays( 7), room); } -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 &aMeetings ) -{ - qDebug() << "Engine::meetingsFetched( const QList & )"; - - 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 &aList, const Meeting *aMeeting) { qDebug() @@ -246,6 +195,7 @@ bool Engine::isMeetingInList(const QList &aList, const Meeting *aMeeti void Engine::meetingsFetched(const QList &aMeetings) { qDebug() << "Engine::meetingsFetched( const QList & )"; + // check if there is any new meeting in the list came from the server -> added for (int i = 0; i < aMeetings.count(); i++) { @@ -255,8 +205,6 @@ void Engine::meetingsFetched(const QList &aMeetings) // add to the local database =) Meeting* m = new Meeting( *(aMeetings.at( i )) ); iMeetings.append(m); - // and signal the changes - iWindowManager->insertMeeting(m); } } @@ -267,112 +215,176 @@ void Engine::meetingsFetched(const QList &aMeetings) 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; } ->>>>>>> 56f763c68a2ff56d344ef150b7378ca417d08b36:src/BusinessLogic/Engine.cpp } - iWindowManager->refreshMeetings( iMeetings ); // refresh room status info roomStatusInfoNeeded(defaultRoom() ); } -void Engine::meetingDetailsFetched(Meeting &aDetailedMeeting) +void Engine::errorHandler( int aCode, const QString &aAddInfo ) +{ + if ( iWindowManager != 0 ) + { + iWindowManager->error( ErrorMapper::codeToString( aCode, aAddInfo ) ); + } +} + +void Engine::fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn ) +{ + qDebug() + << "Engine::fetchMeetings( const QDateTime &, const QDateTime &, const Room * )"; + iCommunication->fetchMeetings(aFrom, aUntil, *aIn); +} + +void Engine::fetchMeetingDetails(Meeting *aMeeting) { - qDebug() << "Engine::meetingDetailsFetched( Meeting & )"; - iWindowManager->closeProgressBar(); - iWindowManager->showMeetingInfo( &aDetailedMeeting); + qDebug() << "[Engine::fetchMeetingDetails] "; + Meeting tempMeeting(aMeeting->primaryId(), aMeeting->room(), aMeeting->startsAt(), aMeeting->endsAt() ); + iCommunication->fetchMeetingDetails( tempMeeting ); +// Meeting tempMeeting = aMeeting; +// iCommunication->fetchMeetingDetails( tempMeeting ); } -void Engine::errorHandler(int aCode, const QString &aAddInfo) +void Engine::cancelFetchMeetingDetails() { - qDebug() << "Engine::ErrorHandler, aCode: " << aCode; - // inform UI about the problem - if( aCode >= 100 && aCode <= 150 ) { //communication errors - //we don't want these to close operation changing - qDebug() << "CommunicationManager signaled an error:" << aCode; - iWindowManager->closeProgressBar(); + iCommunication->cancelFetchMeetingDetails(); +} + +void Engine::shownWeekChanged( QDate aFrom ) +{ + qDebug() << "[Engine::shownWeekChanged] "; + QDateTime from( aFrom ); + QDateTime to( aFrom.addDays( 7 ), QTime( 23, 59 ) ); + qDebug() << "[Engine::shownWeekChanged] "; + iCommunication->fetchMeetings( from, to, *defaultRoom() ); +// fetchMeetings( from, to, iWindowManager->weeklyView()->currentRoom() ); +} + +void Engine::changeDeviceMode( bool aChange ) +{ + if ( aChange ) + { + connect( iDevice, SIGNAL( changingModeFailed() ), this, SLOT( changeModeFailed() ) ); + iAutoRefresh->stop(); // Stop the meeting update } - iWindowManager->error(ErrorMapper::codeToString(aCode, aAddInfo) ); + iDevice->changeMode( aChange ); } -void Engine::currentRoomChanged(Room *aCurrentRoom) +void Engine::changeModeFailed() { - qDebug() << "Engine::currentRoomChanged to " << aCurrentRoom->name(); - QDateTime from(iWindowManager->weeklyView()->beginnigOfShownWeek() ); - QDateTime to(from.addDays( 8) ); - fetchMeetings(from, to, aCurrentRoom); + qDebug() << "Engine::progressBarCancelled()"; + iDevice->changeMode( false ); + iAutoRefresh->start(); //we start the metting updating } -void Engine::fetchMeetings(const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn) +void Engine::initUserInterface() { - qDebug() - << "Engine::fetchMeetings( const QDateTime &, const QDateTime &, const Room * )"; - iCommunication->fetchMeetings(aFrom, aUntil, *aIn); + qDebug() << "[Engine::initUserInterface] "; + + // Initialize the window manager and connect what ever signals can be connected + iWindowManager = new WindowManager; + // Create the UIManager which internally handles most of the UI actions + iUIManager = new UIManager( this, iWindowManager ); + + 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() ) ); + + // Show the UI + iWindowManager->setWindowState( Qt::WindowMaximized ); + iWindowManager->show(); + iUIManager->showMainView(); + + qDebug() << "[Engine::initUserInterface] "; +} + +void Engine::handleViewEvent() +{ + if ( iIdleTimeCounter != 0 ) + { + // Restart the idle time counter when view event is received + iIdleTimeCounter->stop(); + iIdleTimeCounter->start(); + } +} + +void Engine::initConfiguration() +{ + iConfiguration = Configuration::instance(); + if ( iConfiguration == 0 ) + { + QTimer::singleShot( 0, this, SLOT( closeApplication() ) ); + } +} + +void Engine::connectSignals() +{ + // Connect engine objects signals to UIManager + connect( iClock, SIGNAL( tick( QDateTime ) ), iUIManager, SLOT( updateTime( QDateTime ) ) ); + connect( iIdleTimeCounter, SIGNAL( timeout() ) , iUIManager, SLOT( roomStatusIndicatorRequested() ) ); + + iUIManager->connectDeviceManager( iDevice ); + iUIManager->connectCommunicationManager( iCommunication ); } -void Engine::shownWeekChanged(QDate aFrom) +void Engine::initCommunication() { - qDebug() << "Engine::shownWeekChanged( QDate )"; - QDateTime from(aFrom); - QDateTime to(aFrom.addDays( 7), QTime( 23, 59) ); - qDebug() << "Engine::shownWeekChanged " << aFrom.toString("d.m. h:mm") - << " to " << to.toString("d.m. h:mm"); - fetchMeetings(from, to, iWindowManager->weeklyView()->currentRoom() ); + // initialize communication + iCommunication = new CommunicationManager( *(iConfiguration->connectionSettings()) ); + connect( iCommunication, SIGNAL( error( int, CommunicationManager::CommunicationType ) ), + this, SLOT( errorHandler( int ) ) ); + connect( iCommunication, SIGNAL( meetingsFetched( const QList& ) ), + this, SLOT( meetingsFetched( const QList& ) ) ); } -void Engine::changeModeOrdered(DeviceManager::OperationMode aMode) +void Engine::initDevice() { - qDebug() << "Engine::changeModeOrdered( DeviceManager::OperationMode )"; - QString message = tr( "You are about to change operation mode to %1." ) - .arg(iDevice->operationModeToString(aMode) ); + // create device manager + iDevice = new DeviceManager( iConfiguration->startupSettings() ); + connect( iDevice, SIGNAL( error( int, const QString& ) ), this, SLOT( errorHandler( int, const QString& ) ) ); + iDevice->initDeviceManager(); +} - iWindowManager->showPasswordDialog(iConfiguration->adminPassword(), message); +void Engine::dialogActivated() +{ + if ( iIdleTimeCounter != 0 ) + { + iIdleTimeCounter->stop(); + } } -void Engine::passwordEntered(PasswordDialog::PasswordStatus aPasswordStatus) +void Engine::dialogDeactivated() { - qDebug() << "Engine::passwordEntered( PasswordDialog::PasswordStatus )"; - iWindowManager->closePasswordDialog(); + if ( iIdleTimeCounter != 0 ) + { + iIdleTimeCounter->start(); + } +} - switch (aPasswordStatus) +void Engine::previousViewRestored() +{ + if ( iIdleTimeCounter != 0 ) { - case PasswordDialog::Correct: - { - iAutoRefresh->stop(); //we stop the metting updating - iWindowManager->showProgressBar( "Changing current operation mode." ); - connect(iDevice, SIGNAL( changingMode( const QString & ) ), iWindowManager, SLOT( updateProgressBar( const QString & ) )); - connect( iDevice, SIGNAL( changingMode( const QString & ) ), - iWindowManager, SLOT( updateProgressBar( const QString & ) ) ); - connect( iDevice, SIGNAL( changeModeFailed() ), this, SLOT( changeModeFailed() ) ); - iDevice->changeMode( true); - break; - } - case PasswordDialog::Incorrect: - { - iWindowManager->error(tr("Incorrect password.") ); - iDevice->changeMode( false); - break; - } - default: //case PasswordDialog::Canceled - { - iDevice->changeMode( false); - } + iIdleTimeCounter->start(); } } -void Engine::changeModeFailed() +void Engine::stopIdleTimeCounter() { - qDebug() << "Engine::changeModeFailed()"; - iWindowManager->closeProgressBar(); - iAutoRefresh->start(); //we start the metting updating + if ( iIdleTimeCounter != 0 ) + { + iIdleTimeCounter->stop(); + } } -void Engine::fetchMeetingDetailsCancelled() +void Engine::startIdleTimeCounter() { - iCommunication->cancelFetchMeetingDetails(); - iWindowManager->closeProgressBar(); + if ( iIdleTimeCounter != 0 ) + { + iIdleTimeCounter->start(); + } } diff --git a/src/BusinessLogic/Engine.h b/src/BusinessLogic/Engine.h index 14d2740..90f6342 100644 --- a/src/BusinessLogic/Engine.h +++ b/src/BusinessLogic/Engine.h @@ -5,13 +5,15 @@ #include #include "Room.h" #include "WindowManager.h" +#include "DeviceManager.h" +#include "PasswordDialog.h" class QTimer; class Clock; class Configuration; class CommunicationManager; class Meeting; -class DeviceManager; +class UIManager; //! BusinessLogic class. Contains all the business logic of the application. /*! @@ -39,8 +41,6 @@ public: signals: - void meetingDetailsFetched( Meeting *aDetailedMeeting ); - private slots: //! Slot. Closes the application. /*! @@ -53,17 +53,6 @@ private slots: * \param aRoom The room which availability information is needed. */ void roomStatusInfoNeeded( Room *aRoom ); - //! Slot. Indicates that some user event has happened. - /*! - * Slot. Indicates that some user event has happened. - */ - void observedEventDetected(); - //! Slot. Asks the communication to fetch new meeting data. - /*! - * Slot. Asks the communication to fetch new meeting data. - * \param aCurrentRoom The current room. - */ - void currentRoomChanged( Room *aCurrentRoom ); //! Slot. Asks the communication to fetch new meeting data. /*! * Slot. Asks the communication to fetch new meeting data. @@ -92,34 +81,12 @@ private slots: * \param aMeetings The list of freshly fetched meetings. */ void meetingsFetched( const QList& ); - - void meetingDetailsFetched( Meeting &aDetailedMeeting ); - //! Slot. Checks the availability of all the rooms. /*! * Slot. Checks the availability of all the rooms by iterating through the current object's local * room storage and calling the roomStatusInfoNeeded() separately on each of them. */ void checkStatusOfAllRooms(); - //! Slot for popping up the confirmation dialog to change the current operation mode - /*! - * Slot. Asks Window manager to pop up a confirmation dialog. - * \param aMode The operation mode to be changed to - */ - void changeModeOrdered( DeviceManager::OperationMode aMode ); - //! Slot. Fetches meeting details from the server. - /*! - * Slot. Fetches meeting details from the server. - * \param aMeeting The meeting. - */ - void fetchMeetingDetails( Meeting *aMeeting ); - //! Slot for receiving the status of the entered password - /*! - * Slot. Receives the status of the entered password and makes the DeviceManager to change the - * operation mode if the password is correct. - * \param aPasswordStatus The status of the password. - */ - void passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus ); //! Slot for receiving the failure event of operation mode changing. /*! * Slot. Receives the failure event of operation mode changing. @@ -129,9 +96,36 @@ private slots: /*! * Receives the cancel event of the progress bar when meeting details requested. */ - void fetchMeetingDetailsCancelled(); + void fetchMeetingDetails( Meeting *aMeeting ); + void cancelFetchMeetingDetails(); + + void handleViewEvent(); + void previousViewRestored(); + + //! Slot for dialog activation signal. + /*! + * This slot is used to inform that dialog is activated. It stops + * the idle time counter so screensaver is not activated while the + * dialog is displayed. + */ + void dialogActivated(); + //! Slot for dialog deactivation signal. + /*! + * This slot is used to inform that dialog is deactivated. It restarts + * the idle time counter so that the screensaver is being activated again + * as needed. + */ + void dialogDeactivated(); + + void stopIdleTimeCounter(); + void startIdleTimeCounter(); + void changeDeviceMode( bool aChange ); + private: + // Make the UIManager as friendly class so it can connect to private slots. + friend class UIManager; + //! Provides the index of the Meeting instance which is at the specified time. /*! * Provides the index of the Meeting instance which is at the specified time. If there are @@ -158,16 +152,52 @@ 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 &aList, const Meeting *aMeeting); + private: static QTime endOfTheDay; WindowManager *iWindowManager; + QTimer *iIdleTimeCounter; Clock *iClock; Configuration *iConfiguration; CommunicationManager *iCommunication; DeviceManager *iDevice; + UIManager *iUIManager; QTimer *iAutoRefresh; diff --git a/src/BusinessLogic/UIManager.cpp b/src/BusinessLogic/UIManager.cpp new file mode 100644 index 0000000..9455bb0 --- /dev/null +++ b/src/BusinessLogic/UIManager.cpp @@ -0,0 +1,295 @@ +#include "UIManager.h" + +#include +#include + +#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 + +#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( meetingsFetched( const QList & ) ), this, SLOT( meetingsFetched( const QList & ) ) ); +} + +// ============================================ +// UIMANAGER SLOTS +void UIManager::settingsViewRequest() +{ + // Show the settings view and stop the idle timer + if ( iSettingsView != 0 ) + { + iWindowManager->showView( static_cast( iSettingsView ) ); + iEngine->stopIdleTimeCounter(); + } +} + +void UIManager::settingsOkClicked() +{ + // Show the weekly view and restart the idle timer + if ( iWeeklyView != 0 ) + { + iWindowManager->showView( static_cast( iWeeklyView ) ); + iEngine->startIdleTimeCounter(); + } +} + +void UIManager::meetingsFetched( const QList &aMeetings ) +{ + qDebug() << "[UIManager::meetingsFetched] "; + if ( iWeeklyView != 0 ) + { + iWeeklyView->refreshMeetings( aMeetings ); + } +} + +void UIManager::showMeetingProgressBar( Meeting *aMeeting ) +{ + if ( iProgressBar != 0 ) + { + iProgressBar->update( tr("Fetching meeting info...") ); + iWindowManager->showDialog( static_cast( iProgressBar ), false ); + } +} + +void UIManager::meetingDetailsFetched(Meeting &aDetailedMeeting) +{ + qDebug() << "[UIManager::meetingDetailsFetched] "; + 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( tmp/*iMeetingInfo*/ ) ); + } +} + +void UIManager::roomStatusIndicatorRequested() +{ + if ( iRoomStatusIndicator != 0 ) + { + iWindowManager->showView( static_cast( 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] "; + + 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( 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( 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] "; + if ( iProgressBar != 0 && iProgressBar->isVisible() ) + { + iProgressBar->close(); + } +} diff --git a/src/BusinessLogic/UIManager.h b/src/BusinessLogic/UIManager.h new file mode 100644 index 0000000..de123b6 --- /dev/null +++ b/src/BusinessLogic/UIManager.h @@ -0,0 +1,77 @@ +#ifndef UIMANAGER_H_ +#define UIMANAGER_H_ + +#include +#include + +#include "Meeting.h" +#include "DeviceManager.h" +#include "PasswordDialog.h" + +class Engine; +class WindowManager; +class WeeklyViewWidget; +class SettingsView; +class RoomStatusIndicatorWidget; +class ProgressBar; +class MeetingInfoDialog; +class CommunicationManager; +class QDateTime; + +class UIManager : public QObject +{ + Q_OBJECT + +public: + UIManager( Engine *aEngine, WindowManager *aWindowManager ); + virtual ~UIManager(); + + void connectDeviceManager( DeviceManager *aDeviceManager ); + void connectCommunicationManager( CommunicationManager *aCommunicationManager ); + void showMainView(); + void showProgressBar( QString aText ); + +signals: + +public slots: + + void settingsViewRequest(); + void settingsOkClicked(); + void roomStatusIndicatorRequested(); + void previousViewRestored(); + void changeModeOrdered( DeviceManager::OperationMode aMode ); + +private slots: + + void meetingsFetched( const QList &aMeetings ); + void meetingDetailsFetched( Meeting &aDetailedMeeting ); + void currentRoomChanged( Room *aRoom ); + void progressBarCancelled(); + void updateTime( QDateTime aDateTime ); + void passwordEntered( PasswordDialog::PasswordStatus aStatus ); + void showMeetingProgressBar( Meeting *aMeeting ); + void updateProgressBarText( const QString &aText ); + void hideProgressBar(); + +private: + + void createWeeklyView(); + void createSettingsView(); + void createRoomStatusIndicator(); + void createPasswordDialog(); + void createProgressBar(); + void createMeetingInfoDialog(); + +private: + Engine *iEngine; + WindowManager *iWindowManager; + + WeeklyViewWidget *iWeeklyView; + SettingsView *iSettingsView; + RoomStatusIndicatorWidget *iRoomStatusIndicator; + PasswordDialog *iPasswordDialog; + ProgressBar *iProgressBar; + MeetingInfoDialog *iMeetingInfo; +}; + +#endif /*UIMANAGER_H_*/ diff --git a/src/UserInterface/Components/MeetingRoomCombo.cpp b/src/UserInterface/Components/MeetingRoomCombo.cpp index 4b7a128..fad0493 100644 --- a/src/UserInterface/Components/MeetingRoomCombo.cpp +++ b/src/UserInterface/Components/MeetingRoomCombo.cpp @@ -7,7 +7,7 @@ #include MeetingRoomCombo::MeetingRoomCombo( QList aRooms, QWidget *aParent ) : - ObservedWidget( aParent ) + QWidget( aParent ) { iRooms = aRooms; qSort( iRooms.begin(), iRooms.end(), Room::caseInsensitiveLessThan ); diff --git a/src/UserInterface/Components/MeetingRoomCombo.h b/src/UserInterface/Components/MeetingRoomCombo.h index 5c7120a..01a858e 100644 --- a/src/UserInterface/Components/MeetingRoomCombo.h +++ b/src/UserInterface/Components/MeetingRoomCombo.h @@ -1,7 +1,6 @@ #ifndef MEETINGROOMCOMBO_H_ #define MEETINGROOMCOMBO_H_ -#include "ObservedWidget.h" #include #include @@ -13,7 +12,7 @@ class Room; * Userinterface class. Displays a list of selectable meeting rooms. Customized QComboBox which hides * all the not needed functionality of the "base" class. */ -class MeetingRoomCombo : public ObservedWidget +class MeetingRoomCombo : public QWidget { Q_OBJECT diff --git a/src/UserInterface/Components/TimeDisplayWidget.cpp b/src/UserInterface/Components/TimeDisplayWidget.cpp index 8267ca0..9fd2fab 100644 --- a/src/UserInterface/Components/TimeDisplayWidget.cpp +++ b/src/UserInterface/Components/TimeDisplayWidget.cpp @@ -1,7 +1,7 @@ #include "TimeDisplayWidget.h" TimeDisplayWidget::TimeDisplayWidget( QTime aNow, QWidget *aParent ) : - ObservedWidget( aParent ) + QWidget( aParent ) { iCurrentTime = aNow; diff --git a/src/UserInterface/Components/TimeDisplayWidget.h b/src/UserInterface/Components/TimeDisplayWidget.h index a1bcfd4..5f4e3a4 100644 --- a/src/UserInterface/Components/TimeDisplayWidget.h +++ b/src/UserInterface/Components/TimeDisplayWidget.h @@ -1,7 +1,6 @@ #ifndef TIMEDISPLAYWIDGET_H_ #define TIMEDISPLAYWIDGET_H_ -#include "ObservedWidget.h" #include #include #include @@ -11,7 +10,7 @@ * Abstact. UserInterface class. Offers basic functionality to display time. Inherited by * DigitalTimeDisplayWidget. */ -class TimeDisplayWidget : public ObservedWidget +class TimeDisplayWidget : public QWidget { Q_OBJECT diff --git a/src/UserInterface/Views/MeetingInfoDialog.cpp b/src/UserInterface/Views/MeetingInfoDialog.cpp index 95e2cce..3250e82 100644 --- a/src/UserInterface/Views/MeetingInfoDialog.cpp +++ b/src/UserInterface/Views/MeetingInfoDialog.cpp @@ -13,6 +13,26 @@ MeetingInfoDialog::MeetingInfoDialog( Meeting *aMeeting, QWidget *aParent ) : { setWindowTitle( tr( "Details" ) ); + if ( aMeeting != 0 ) + { + createDialogView( aMeeting ); + } + + setMinimumWidth( MeetingInfoDialog::width ); + setMinimumHeight( MeetingInfoDialog::height ); +} + +MeetingInfoDialog::~MeetingInfoDialog() +{ +} + +void MeetingInfoDialog::setMeeting(Meeting *aMeeting) +{ + createDialogView( aMeeting ); +} + +void MeetingInfoDialog::createDialogView(Meeting *aMeeting) +{ QFont normalFont; normalFont.setPointSize( 11 ); @@ -75,11 +95,4 @@ MeetingInfoDialog::MeetingInfoDialog( Meeting *aMeeting, QWidget *aParent ) : layout->addStretch(); layout->addLayout( buttonLayout ); setLayout( layout ); - - setMinimumWidth( MeetingInfoDialog::width ); - setMinimumHeight( MeetingInfoDialog::height ); -} - -MeetingInfoDialog::~MeetingInfoDialog() -{ } diff --git a/src/UserInterface/Views/MeetingInfoDialog.h b/src/UserInterface/Views/MeetingInfoDialog.h index a62cb32..86c33d1 100644 --- a/src/UserInterface/Views/MeetingInfoDialog.h +++ b/src/UserInterface/Views/MeetingInfoDialog.h @@ -19,11 +19,14 @@ public: * \param aMeeting The Meeting instance which is needed to be presented in detail. * \param aParent Pointer to the parent widget. Optional. */ - MeetingInfoDialog( Meeting *aMeeting, QWidget *aParent = 0 ); + MeetingInfoDialog( Meeting *aMeeting = 0, QWidget *aParent = 0 ); //! Destructor. virtual ~MeetingInfoDialog(); + + void setMeeting( Meeting * aMeeting ); private: + void createDialogView(Meeting *aMeeting); static const int width = 200; static const int height = 400; diff --git a/src/UserInterface/Views/RoomStatusIndicatorWidget.cpp b/src/UserInterface/Views/RoomStatusIndicatorWidget.cpp index 7421a47..c903bc0 100644 --- a/src/UserInterface/Views/RoomStatusIndicatorWidget.cpp +++ b/src/UserInterface/Views/RoomStatusIndicatorWidget.cpp @@ -11,7 +11,7 @@ QTime RoomStatusIndicatorWidget::endOfTheDay = QTime( 23, 59, 0, 0 ); RoomStatusIndicatorWidget::RoomStatusIndicatorWidget( Room *aDefaultRoom, Room::Status aStatus, QTime aUntil, QString aTimeFormat, QWidget *aParent ) : - ObservedWidget( aParent ), iTimeFormat( aTimeFormat ) + ViewBase( ViewBase::ObservedView, aParent ), iTimeFormat( aTimeFormat ) { QFont importantTextFont; //importantTextFont.setBold( true ); diff --git a/src/UserInterface/Views/RoomStatusIndicatorWidget.h b/src/UserInterface/Views/RoomStatusIndicatorWidget.h index 615051e..c20ce45 100644 --- a/src/UserInterface/Views/RoomStatusIndicatorWidget.h +++ b/src/UserInterface/Views/RoomStatusIndicatorWidget.h @@ -1,7 +1,7 @@ #ifndef ROOMSTATUSINDICATORWIDGET_H_ #define ROOMSTATUSINDICATORWIDGET_H_ -#include "ObservedWidget.h" +#include "ViewBase.h" #include #include #include @@ -19,7 +19,7 @@ class TimeDisplayWidget; * and disappears if there is any. Its function is to behave like a screen saver on one hand, and * to provide details about the current availability on the other hand. */ -class RoomStatusIndicatorWidget : public ObservedWidget +class RoomStatusIndicatorWidget : public ViewBase { Q_OBJECT @@ -55,6 +55,8 @@ public slots: * \param aUntil The new time until the specified status is valid. */ void statusChanged( const Room::Status aStatus, const QTime aUntil ); + + void viewResized(const QSize &newSize, const QSize &oldSize) { } private: //! Translates the status into human readable text. diff --git a/src/UserInterface/Views/SettingsView.cpp b/src/UserInterface/Views/SettingsView.cpp index caa5cfe..1021d77 100644 --- a/src/UserInterface/Views/SettingsView.cpp +++ b/src/UserInterface/Views/SettingsView.cpp @@ -24,7 +24,7 @@ #include SettingsView::SettingsView( QWidget *aParent ) : - ObservedWidget( aParent ) + ViewBase( ViewBase::NormalView, aParent ) { qDebug() << "SettingsView::ctor invoked"; // Prepare the tabbed view @@ -44,10 +44,7 @@ SettingsView::SettingsView( QWidget *aParent ) : QHBoxLayout *buttonLayout = new QHBoxLayout; iOkButton = new QPushButton; iOkButton->setText( tr( "OK" ) ); - iCancelButton = new QPushButton; - iCancelButton->setText( tr( "Cancel" ) ); buttonLayout->addWidget( iOkButton ); - buttonLayout->addWidget( iCancelButton ); // Handle the main layout QVBoxLayout *mainLayout = new QVBoxLayout; @@ -57,8 +54,7 @@ SettingsView::SettingsView( QWidget *aParent ) : setLayout( mainLayout ); // Handle component connections - connect( iOkButton, SIGNAL( pressed() ), this, SLOT( okClicked() ) ); - connect( iCancelButton, SIGNAL( pressed() ), this, SLOT( cancelClicked() ) ); + connect( iOkButton, SIGNAL( clicked() ), this, SLOT( handleOkClicked() ) ); } SettingsView::~SettingsView() @@ -73,11 +69,6 @@ SettingsView::~SettingsView() delete iOkButton; iOkButton = 0; } - if ( iCancelButton != 0 ) - { - delete iCancelButton; - iCancelButton = 0; - } if ( iSettingsTab != 0 ) { delete iSettingsTab; @@ -389,7 +380,7 @@ QWidget *SettingsView::initKioskModeTab() return widget; } -void SettingsView::okClicked() +void SettingsView::handleOkClicked() { qDebug() << "[SettingsView::okClicked] "; @@ -409,12 +400,17 @@ void SettingsView::okClicked() bool powerSaveEnabled = iPowerSaveEnabled->isChecked(); // TODO : Set the values to configuration and save it - - close(); + + // Emit the signal to notify that ok is pressed and data is saved. + emit okClicked(); } -void SettingsView::cancelClicked() +void SettingsView::viewResized(const QSize &newSize, const QSize &oldSize) { - qDebug() << "[SettingsView::cancelClicked] "; - close(); -} + if ( oldSize.height() > newSize.height() ) + { + // Get the button's height and add that to the new size so that + // the ok button is hidden under the keyboard. + size().rheight() += iOkButton->size().height(); + } +} \ No newline at end of file diff --git a/src/UserInterface/Views/SettingsView.h b/src/UserInterface/Views/SettingsView.h index 8b9bbeb..2845a8d 100644 --- a/src/UserInterface/Views/SettingsView.h +++ b/src/UserInterface/Views/SettingsView.h @@ -1,7 +1,7 @@ #ifndef SETTINGSVIEW_H_ #define SETTINGSVIEW_H_ -#include "ObservedWidget.h" +#include "ViewBase.h" class QTabWidget; class QPushButton; @@ -9,9 +9,10 @@ class QLineEdit; class QTimeEdit; class QRadioButton; class QCheckBox; +class QSize; //! User interface class. Shows the settings view and handles configuration changes. -class SettingsView : public ObservedWidget +class SettingsView : public ViewBase { Q_OBJECT @@ -25,12 +26,16 @@ public: SettingsView( QWidget *aParent = 0 ); //! Destructor. virtual ~SettingsView(); + +signals: + void okClicked(); + +public slots: + void viewResized(const QSize &newSize, const QSize &oldSize); private slots: //! Slot to handle the Ok button pressing. - void okClicked(); - //! Slot to handle the cancel button pressing. - void cancelClicked(); + void handleOkClicked(); private: //! Initialize "Settings" tab. @@ -46,8 +51,6 @@ private: QTabWidget *iTabWidget; //! OK button to dismiss the settings view with saving the settings. QPushButton *iOkButton; - //! Cancel button to dismiss the settings view without saving settings. - QPushButton *iCancelButton; //! Settings tab. QWidget *iSettingsTab; //! Week View tab. diff --git a/src/UserInterface/Views/ViewBase.cpp b/src/UserInterface/Views/ViewBase.cpp new file mode 100644 index 0000000..24d6461 --- /dev/null +++ b/src/UserInterface/Views/ViewBase.cpp @@ -0,0 +1,77 @@ +#include "ViewBase.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +ViewBase::ViewBase( ViewBase::ViewMode aMode, QWidget *aParent ) : QWidget( aParent ), iViewMode( aMode ) +{ + +} + +ViewBase::~ViewBase() +{ + +} + +ViewBase::ViewMode ViewBase::viewMode() +{ + return iViewMode; +} + +bool ViewBase::event(QEvent *event) +{ + switch( event->type() ) + { + // TODO : Add events as needed !!! + case QEvent::KeyPress: + case QEvent::KeyRelease: + case QEvent::TabletMove: + case QEvent::TabletPress: + case QEvent::MouseMove: + case QEvent::MouseButtonPress: + case QEvent::MouseButtonDblClick: + emit eventDetected(); + break; + default: + break; + } + + return QWidget::event( event ); +} + +bool ViewBase::eventFilter( QObject *watched, QEvent *event ) +{ + if ( watched != this ) // We do not filter our own events + { + switch( event->type() ) + { + // TODO : Add events as needed !!!! + case QEvent::KeyPress: + case QEvent::KeyRelease: + case QEvent::TabletMove: + case QEvent::TabletPress: + case QEvent::MouseMove: + case QEvent::MouseButtonPress: + case QEvent::MouseButtonDblClick: + emit eventDetected(); + break; + default: + break; + } + } + + return QWidget::eventFilter( watched, event ); +} + +void ViewBase::observeChild(QWidget *aChild) +{ + aChild->setMouseTracking( true ); + aChild->installEventFilter( this ); +} diff --git a/src/UserInterface/Views/ViewBase.h b/src/UserInterface/Views/ViewBase.h new file mode 100644 index 0000000..631a089 --- /dev/null +++ b/src/UserInterface/Views/ViewBase.h @@ -0,0 +1,69 @@ +#ifndef VIEWBASE_ +#define VIEWBASE_ + +#include + +class QEvent; +class QSize; + +class ViewBase : public QWidget +{ + Q_OBJECT + +public: + enum ViewMode + { + NormalView, /*!< Indicates that the view is normal view that isn't hidden by events. */ + ObservedView /*!< Indicates that the view will be hidden when event occurs. */ + }; + +public: + ViewBase( ViewBase::ViewMode aMode, QWidget *aParent = 0 ); + virtual ~ViewBase(); + + //! Overwritten event handler. + /*! + * Listens for events and emits eventDetected signal when observed + * event is triggered. + */ + virtual bool event(QEvent *event); + + //! Event filter. + /*! + * Event filter method that is used to listen for child widgets + * events. + */ + virtual bool eventFilter(QObject *watched, QEvent *event); + + //! Returns view mode. + /*! + * Returns the views mode which is one of the ViewMode enumerations. + */ + ViewBase::ViewMode viewMode(); + +public slots: + //! This slot is called when the view is resized. + /*! + * This slot will be called after the view is resized by the window manager + * to fit its client area. This method can be used to refine the view size + * after it has been resized, for example when the on screen keyboard is + * displayed. + */ + virtual void viewResized(const QSize &newSize, const QSize &oldSize) = 0; + +signals: + /*! + * This signal indicates that some user initiated event has occured. + * Event filter tracks for mouse, pointer and key events. + */ + void eventDetected(); + +protected: + void observeChild(QWidget *aChild); + +private: + ViewMode iViewMode; + +}; + +#endif /*VIEWBASE_*/ diff --git a/src/UserInterface/Views/WeeklyViewWidget.cpp b/src/UserInterface/Views/WeeklyViewWidget.cpp index 21fdc94..673d91e 100644 --- a/src/UserInterface/Views/WeeklyViewWidget.cpp +++ b/src/UserInterface/Views/WeeklyViewWidget.cpp @@ -20,7 +20,7 @@ #include WeeklyViewWidget::WeeklyViewWidget( QDateTime aCurrentDateTime, Configuration *aConfiguration, QWidget *aParent ) : - ObservedWidget( aParent ), iConfiguration( aConfiguration ) + ViewBase( ViewBase::NormalView, aParent ), iConfiguration( aConfiguration ) { // ***************************************** @@ -36,23 +36,21 @@ WeeklyViewWidget::WeeklyViewWidget( QDateTime aCurrentDateTime, Configuration *a iSettingsButton = new QPushButton; iSettingsButton->setIcon( QPixmap( ":button_settings" ) ); iSettingsButton->setFixedWidth( 36 ); - connect( iSettingsButton, SIGNAL( clicked() ), this, SIGNAL( showSettingsView() ) ); + connect( iSettingsButton, SIGNAL( clicked() ), this, SIGNAL( settingsButtonClicked() ) ); iCurrentDayLabel = ToolBox::createLabel( aCurrentDateTime.toString( iConfiguration->displaySettings()->dateFormat() ), regularTextFont ); iCurrentWeekLabel = ToolBox::createLabel( tr( "Wk %1" ).arg( aCurrentDateTime.date().weekNumber() ), regularTextFont ); iRoomsCombo = new MeetingRoomCombo( iConfiguration->rooms(), this ); iRoomsCombo->setCurrentRoom( iConfiguration->defaultRoom() ); - connect( iRoomsCombo, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) ); + connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( currentRoomChanged( Room * ) ) ); iTimeDisplay = new DigitalTimeDisplayWidget( aCurrentDateTime.time(), iConfiguration->displaySettings()->timeFormat(), this ); iTimeDisplay->setFrameVisible( false ); iTimeDisplay->setFont( regularTextFont ); - connect( iTimeDisplay, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) ); iSchedule = new ScheduleWidget( aCurrentDateTime, iConfiguration->displaySettings(), this ); connect( iSchedule, SIGNAL( shownWeekChanged( QDate ) ), this, SIGNAL( shownWeekChanged( QDate ) ) ); - connect( iSchedule, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) ); connect( iSchedule, SIGNAL( meetingActivated( Meeting* ) ), this, SIGNAL( meetingActivated( Meeting* ) ) ); iPreviousWeekButton = new QPushButton( this ); @@ -91,6 +89,16 @@ WeeklyViewWidget::WeeklyViewWidget( QDateTime aCurrentDateTime, Configuration *a mainLayout->addLayout( tableLayout ); mainLayout->addLayout( bottomLayout ); setLayout( mainLayout ); + + // Set child observing + observeChild( iRoomsCombo ); + observeChild( iTimeDisplay ); + observeChild( iCurrentDayLabel ); + observeChild( iCurrentWeekLabel ); + observeChild( iPreviousWeekButton ); + observeChild( iCurrentWeekButton ); + observeChild( iNextWeekButton ); + observeChild( iSettingsButton ); QPalette palette; palette.setColor( QPalette::Window, Qt::white ); @@ -100,11 +108,11 @@ WeeklyViewWidget::WeeklyViewWidget( QDateTime aCurrentDateTime, Configuration *a // ****************************************** // Handle all the signal connections // TODO : this solution if interaction monitoring is not elegant enough - connect( iPreviousWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) ); - connect( iCurrentWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) ); - connect( iNextWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) ); - connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( observedEventDetected() ) ); - connect( iRoomsCombo, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( observedEventDetected() ) ); +// connect( iPreviousWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) ); +// connect( iCurrentWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) ); +// connect( iNextWeekButton, SIGNAL( clicked() ), this, SIGNAL( observedEventDetected() ) ); +// connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( observedEventDetected() ) ); +// connect( iRoomsCombo, SIGNAL( currentIndexChanged( int ) ), this, SIGNAL( observedEventDetected() ) ); // TODO: connect RoomCombo signals to change meetings data. connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( currentRoomChanged( Room * ) ) ); connect( iRoomsCombo, SIGNAL( currentRoomChanged( Room * ) ), iSchedule, SLOT( refresh() ) ); diff --git a/src/UserInterface/Views/WeeklyViewWidget.h b/src/UserInterface/Views/WeeklyViewWidget.h index f4c4762..055617b 100644 --- a/src/UserInterface/Views/WeeklyViewWidget.h +++ b/src/UserInterface/Views/WeeklyViewWidget.h @@ -1,7 +1,7 @@ #ifndef WEEKLYVIEWWIDGET_H_ #define WEEKLYVIEWWIDGET_H_ -#include "ObservedWidget.h" +#include "ViewBase.h" #include class QLabel; @@ -19,7 +19,7 @@ class Room; * selected meeting room. User can select meeting room, browse weeks back and forth, and can navigate * back to the current week. */ -class WeeklyViewWidget : public ObservedWidget +class WeeklyViewWidget : public ViewBase { Q_OBJECT @@ -101,14 +101,14 @@ signals: /*! * Signal is emited when settings button is clicked. */ - void showSettingsView(); + void settingsButtonClicked(); //! Signal. Emitted if the shown week has been changed. /*! * Signal. Emitted if the shown week has been changed. * \param aDate The first date of the shown week. */ - void shownWeekChanged( QDate aDate ); + void shownWeekChanged( QDate aDate ); public slots: //! Sets the date and time @@ -117,6 +117,12 @@ public slots: * \param aCurrentDateTime Date and time to be displayd. */ void setCurrentDateTime( QDateTime aCurrentDateTime ); + //! Handle resizing + /*! + * Handle possible resize changes after the view is resized + * to match the window managers client area. + */ + void viewResized(const QSize &newSize, const QSize &oldSize) { } private: //! Displays the selectable meeting rooms. diff --git a/src/UserInterface/WindowManager.cpp b/src/UserInterface/WindowManager.cpp index 552bb7c..af006f1 100644 --- a/src/UserInterface/WindowManager.cpp +++ b/src/UserInterface/WindowManager.cpp @@ -1,212 +1,128 @@ #include "WindowManager.h" -#include -#include "Configuration.h" -#include "DisplaySettings.h" -#include "Meeting.h" -#include "Room.h" -#include "Clock.h" -#include "WeeklyViewWidget.h" -#include "RoomStatusIndicatorWidget.h" -#include "MeetingInfoDialog.h" +#include +#include +#include "ViewBase.h" #include "PopUpMessageBox.h" -#include "DeviceManager.h" -#include "SettingsView.h" -#include "ProgressBar.h" #include -WindowManager::WindowManager( Configuration *aConfiguration ) : - QObject(), +WindowManager::WindowManager( QWidget *aParent ) : + QWidget( aParent ), iApplicationName( tr( "Qt Meetings" ) ), - iFullScreen( false ), - iConfiguration( aConfiguration ), - iWeeklyView( 0 ), - iRoomStatusView( 0 ), - iMeetingInfo( 0 ), - iProgressBar( 0 ), - iPasswordDialog( 0 ) + iCurrentView( 0 ) { - iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), aConfiguration ); - iWeeklyView->setWindowTitle( iApplicationName ); - connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) ); - connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), this, SIGNAL( meetingActivated( Meeting * ) ) ); - connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( currentRoomChanged( Room * ) ) ); - connect( iWeeklyView, SIGNAL( shownWeekChanged( QDate ) ), this, SIGNAL( shownWeekChanged( QDate ) ) ); - - showWeeklyView(); - + this->setWindowTitle( iApplicationName ); } WindowManager::~WindowManager() { - delete iWeeklyView; - iWeeklyView = 0; - delete iRoomStatusView; - iRoomStatusView = 0; - delete iMeetingInfo; - iMeetingInfo = 0; - delete iProgressBar; - iProgressBar = 0; - delete iPasswordDialog; - iPasswordDialog = 0; + } -void WindowManager::distributeDateTimeInfo( QDateTime aCurrentDateTime ) +void WindowManager::showView( ViewBase *view ) { - if ( iRoomStatusView != 0 && iRoomStatusView->isActiveWindow() ) + // The views parent must be WindowManager when it is displayed trough this + QWidget *parent = static_cast(view->parent()); + if ( parent != this ) { - iRoomStatusView->setCurrentTime( aCurrentDateTime.time() ); + view->setParent( this ); } - - if ( iWeeklyView != 0 && iWeeklyView->isActiveWindow() ) + + // Store the current view because it is hidden after the new view is shown + QWidget *oldView = iCurrentView; + + // If the new view is observed view we store the current into stack + // from which it is restored when the new view receives event we are + // listening to. + if ( view->viewMode() == ViewBase::ObservedView ) { - iWeeklyView->setCurrentDateTime( aCurrentDateTime ); + iViewList.push( iCurrentView ); } + + // Make the new view visible and handle connections + iCurrentView = view; + connect( iCurrentView, SIGNAL( eventDetected() ), this, SLOT( viewEventDetected() ) ); + connect( this, SIGNAL( viewResized(const QSize &, const QSize &) ), iCurrentView, SLOT( viewResized( const QSize &, const QSize & ) ) ); + view->resize( this->size() ); + + view->show(); + + // Disconnect old connections and hide the view + if ( oldView != 0 ) + { + disconnect( oldView, SIGNAL( eventDetected() ), this, SLOT( viewEventDetected() ) ); + disconnect( this, SIGNAL( viewResized(const QSize &, const QSize &) ), oldView, SLOT( viewResized(const QSize &, const QSize &) ) ); + oldView->hide(); + } + } -void WindowManager::roomStatusChanged( Room *aRoom, Room::Status aStatus, QTime aTime ) +void WindowManager::showDialog(QDialog *aDialog, bool blocking, bool aSendSignal) { - if ( iRoomStatusView == 0 ) + // Handle dialog displaying + if ( aSendSignal ) emit dialogActivated(); + if ( blocking ) { - iRoomStatusView = new RoomStatusIndicatorWidget( aRoom, aStatus, aTime, iConfiguration->displaySettings()->timeFormat() ); - iRoomStatusView->setWindowTitle( iApplicationName ); - if( iFullScreen ) - iRoomStatusView->setWindowState( Qt::WindowFullScreen ); - connect( iRoomStatusView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) ); + aDialog->exec(); } else { - iRoomStatusView->statusChanged( aStatus, aTime ); - } - if ( !iWeeklyView->isVisible() && !iRoomStatusView->isVisible() ) - { - showRoomStatus(); + aDialog->show(); } + if ( aSendSignal ) emit dialogDeactivated(); } -void WindowManager::showRoomStatus() +void WindowManager::viewEventDetected() { - qDebug() << "WindowManager::showRoomStatus"; - iWeeklyView->setDefaultRoom(); - if ( iRoomStatusView == 0 ) - { - emit roomStatusInfoNeeded( iWeeklyView->currentRoom() ); - } - else + + if ( iCurrentView != 0 ) { - iRoomStatusView->show(); - if ( iWeeklyView->isVisible() ) + if ( iCurrentView->viewMode() == ViewBase::NormalView ) { - iWeeklyView->hide(); + emit eventDetected(); + } + else if ( iCurrentView->viewMode() == ViewBase::ObservedView ) + { + if ( !iViewList.isEmpty() ) + { + ViewBase *previousView = static_cast( iViewList.pop() ); + this->showView( previousView ); + emit previousViewRestored(); + } } } - // closing/deleting meeting info dialog - if ( iMeetingInfo != 0 ) - { - iMeetingInfo->hide(); - } } -void WindowManager::showWeeklyView() +bool WindowManager::event(QEvent *event) { - qDebug() << "WindowManager::showWeeklyView"; - if ( iRoomStatusView != 0 && iRoomStatusView->isVisible() ) + if ( event->type() == QEvent::Resize ) { - iRoomStatusView->hide(); + if ( iCurrentView != 0 ) + { + QSize currentSize = iCurrentView->size(); + iCurrentView->setFixedSize( this->size() ); + emit viewResized( this->size(), currentSize ); + } } - - iWeeklyView->show(); -} - -void WindowManager::fullScreen() -{ - if ( iRoomStatusView != 0 ) - iRoomStatusView->setWindowState( Qt::WindowFullScreen ); - if ( iWeeklyView != 0 ) - iWeeklyView->setWindowState( Qt::WindowFullScreen ); - iFullScreen = true; -} - -void WindowManager::showMeetingInfo( Meeting *aMeeting ) -{ - iMeetingInfo = new MeetingInfoDialog( aMeeting ); - // Display modal dialog - iMeetingInfo->exec(); - - delete iMeetingInfo; - iMeetingInfo = 0; -} - -void WindowManager::showSettingsView() -{ - // TODO : give the Torspo for the person who was responsible to write this method -} - -WeeklyViewWidget * WindowManager::weeklyView() -{ - return iWeeklyView; -} - -void WindowManager::error( const QString &aErrorMessage ) -{ - qDebug() << "WindowManager::showErrorPopup"; - - PopUpMessageBox::error( 0, aErrorMessage ); -} - -void WindowManager::showPasswordDialog( QByteArray aAdminPassword, const QString &aMessage ) -{ - iPasswordDialog = new PasswordDialog( aAdminPassword, aMessage ); - connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), - this, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ) ); - iPasswordDialog->show(); - //TODO connect connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) ); + return QWidget::event( event ); } -void WindowManager::closePasswordDialog() -{ - iPasswordDialog->close(); - delete iPasswordDialog; - iPasswordDialog = 0; -} - -void WindowManager::showProgressBar( const QString &aText, bool aCancellable ) +void WindowManager::error( const QString &aErrorMessage ) { - qDebug() << "WindowManager::showProgressBar( const QString & )"; - if( iProgressBar == 0 ) { - iProgressBar = new ProgressBar( aText, aCancellable ); - iProgressBar->setFixedSize( 600, 125 ); - iProgressBar->show(); - if( aCancellable ) - connect( iProgressBar, SIGNAL( cancel() ), this, SIGNAL( progressBarCancelled() ) ); - } - - //TODO connect connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) ); -} + qDebug() << "WindowManager::error "; -void WindowManager::closeProgressBar() -{ - qDebug() << "WindowManager::closeProgressBar()"; - if( iProgressBar ) + PopUpMessageBox *popup = PopUpMessageBox::error( 0, aErrorMessage ); + if ( popup != 0 ) { - iProgressBar->close(); - delete iProgressBar; - iProgressBar = 0; + showDialog( static_cast( popup ), false ); } } -void WindowManager::updateProgressBar( const QString &aMessage ) -{ - qDebug() << "WindowManager::updateProgressBar( const QString & )"; - if( iProgressBar != 0 ) - iProgressBar->update( aMessage ); -} - -void WindowManager::refreshMeetings( const QList &aMeetings ) +void WindowManager::setFullscreen() { - qDebug() << "WindowManager::refreshMeetings()"; - iWeeklyView->refreshMeetings( aMeetings ); + this->setWindowState( Qt::WindowFullScreen ); + // Resize event handles the rest. } diff --git a/src/UserInterface/WindowManager.h b/src/UserInterface/WindowManager.h index 2267525..2f46050 100644 --- a/src/UserInterface/WindowManager.h +++ b/src/UserInterface/WindowManager.h @@ -1,188 +1,107 @@ -#ifndef WINDOWMANAGER_H_ -#define WINDOWMANAGER_H_ - -#include -#include -#include "Room.h" -#include "Meeting.h" -#include "PasswordDialog.h" -#include "DeviceManager.h" - -class QTimer; -class RoomStatusIndicatorWidget; -class WeeklyViewWidget; -class Engine; -class MeetingInfoDialog; -class SettingsView; -class ProgressBar; -class Configuration; - -//! UserInterface class. Behaves as a proxy between the user interface and application's business logic. -/*! - * UserInterface class. Controls the whole user interface, starting with displaying the appropriate - * views. It behaves as a proxy between the user interface and application's business logic, it connects - * the specified components together and forwards the data to the correct place. It also manages the correct - * appearance of current views on the screen. - */ -class WindowManager : public QObject -{ - Q_OBJECT - -public: - //! Constructor. - /*! - * Constructor of WindowManager. - * \param aConfiguration The pointer to configuration. - */ - WindowManager( Configuration *aConfiguration ); - //! Destructor. - virtual ~WindowManager(); - /*! - * Displays an error message - * \param aErrorMessage Message to be displayd - */ - void error( const QString &aErrorMessage ); - //! Updates the rooms status. - /*! - * Forwards the signal of changed status to current view. - * \param aRoom Room which status is changed. - * \param aStatus Current status of room. - * \param aTime Time when status is changed. - */ - void roomStatusChanged( Room *aRoom, Room::Status aStatus, QTime aTime ); - //! Shows the password dialog. - /*! - * Shows the password dialog. - * \param aAdminPassword The correct password. - * \param aMessage The message to be shown in the password dialog. - */ - void showPasswordDialog( QByteArray aAdminPassword, const QString &aMessage ); - //! Closes the password dialog. - /*! - * Closes the password dialog. - */ - void closePasswordDialog(); - //! Displays the weekly view. - /*! - * Displays the weekly view. - */ - void showWeeklyView(); - //! Displays the meeting info dialog. - /*! - * Displays the meeting info dialog. - * \param aMeeting Meeting to be displayd - */ - void showMeetingInfo( Meeting *aMeeting ); - //! Returns the pointer to the weekly view. - /*! - * Returns the pointer to the weekly view. - */ - WeeklyViewWidget * weeklyView(); - //! Switches the views to full screen. - /*! - * Switches the views to full screen. - */ - void fullScreen(); - //! Shows the progress bar. - /*! - * Starts showing the progress bar. - * \param aText The text to be shown in progress bar. - * \param aCancellable Is the Cancel button visible. By default not visible. - */ - void showProgressBar( const QString &aText, bool aCancellable = false ); - //! Closes the progress bar. - /*! - * Closes the progress bar. - */ - void closeProgressBar(); - //! Sends the refresh command to weekly view widget. - /*! - * Sends the refresh command to weekly view widget. - * \param aMeetings The list of meetings. - */ - void refreshMeetings( const QList &aMeetings ); - -signals: - //! Request current status of the room. - /*! - * Signal is emitted when there is need to check current status of room aRoom. - * \param aRoom Meetingroom which status is requested. - */ - void roomStatusInfoNeeded( Room *aRoom ); - //! Indicate that some user event has happened. - /*! - * Signal is emitted if some user event has happened. - */ - void observedEventDetected(); - //! Meeting activated. - /*! - * Signal is emitted when a meeting is clicked by the user. - * \param aMeeting actived meeting. - */ - void meetingActivated( Meeting *aMeeting ); - //! Signals if the shown week has been changed. - /*! - * Signal. Emitted if the shown week has been changed. - * \param aDate The first date of the shown week. - */ - void shownWeekChanged( QDate aDate ); - //! Signals change of the meeting room. - /*! - * Signal is emitted when meeting room is changed. - * \param aRoom Selected meeting room. - */ - void currentRoomChanged( Room *aRoom ); - //! Signals when the password dialog buttons are clicked. - /*! - * Signal is emitted when the password dialog buttons are clicked. - * \param aPasswordStatus The status of the password. - */ - void passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus ); - //! Signals when the cancel button in the progress bar is clicked. - /*! - * Signal is emitted when the cancel button in the progress bar is clicked. - */ - void progressBarCancelled(); - -public slots: - //! Slot for displaying the screensaver (room status view). - /*! - * Slot. Displays the screensaver. - */ - void showRoomStatus(); - //! Slot for updating the time. - /*! - * Slot. Forwards the signal of changed time to current view. - * \param aCurrentDateTime Current date and time. - */ - void distributeDateTimeInfo( QDateTime aCurrentDateTime ); - - void updateProgressBar( const QString &aMessage ); - -private slots: - //! Displays the settings view - void showSettingsView(); - -private: - //! Name of the application. - QString iApplicationName; - //! Defines whether the views should be shown as full screen - bool iFullScreen; - //! Pointer to the configuration. - Configuration *iConfiguration; - //! Pointer to the weekly view. - WeeklyViewWidget *iWeeklyView; - //! Pointer to the screensaver (room status view). - RoomStatusIndicatorWidget *iRoomStatusView; - //! Pointer to the meeting info dialog - MeetingInfoDialog *iMeetingInfo; - //! Pointer to the settings view - SettingsView *iSettingsView; - //! Pointer to the progress bar - ProgressBar *iProgressBar; - //! Pointer to the password dialog. - PasswordDialog *iPasswordDialog; - -}; - -#endif /*WINDOWMANAGER_H_*/ +#ifndef WINDOWMANAGER_H_ +#define WINDOWMANAGER_H_ + +#include +#include + +// Forward declarations +class ViewBase; +class QEvent; +class QSize; +class QDialog; +class QString; + +//! UserInterface class. Manages displayed views. +/*! + * UserInterface class. WindowManager class is responsible for displaying views that inherit the + * ViewBase class. It also handles dialog showing. Depending on the views type the WindowManager + * can track the views events and restore previous view if the current on is ObservedView. This + * is a handy mechanism for screensaver etc. + */ +class WindowManager : public QWidget +{ + Q_OBJECT + +public: + //! Constructor. + /*! + * Constructor of WindowManager. + */ + WindowManager( QWidget *aParent = 0 ); + //! Destructor. + virtual ~WindowManager(); + + virtual bool event(QEvent *event); + +signals: + //! Request current status of the room. + /*! + * Signal is emitted when there is need to check current status of room aRoom. + * \param aRoom Meetingroom which status is requested. + */ + void eventDetected(); + + //! The view size is changed. + /*! + * This signal is emitted when the window managers view changes, + * i.e. it received resized QEvent. + * \param The new view size. + */ + void viewResized(const QSize &newSize, const QSize &oldSize); + + //! Previous view is restored. + /*! + * This signal is emitted when previously stored view is + * restored. This happens when view with type ViewMode::ObservedView + * is shown and it receives an event that initiates the view + * restoring chain. + */ + void previousViewRestored(); + + void dialogActivated(); + void dialogDeactivated(); + +public slots: + //! Shows the view. + /*! + * Show view that inherits ViewBase class. If the views parent is not + * the WindowManager it will changed within this method. Depeding on the + * views type the currently active view might be stored and restored + * when specific event occurs in the view to be displayed. + */ + void showView( ViewBase *view ); + + //! Shows modal dialog. + /*! + * Shows modal dialog. Emits dialogActivated() signal prior calling + * QDialog's exec() method and emits dialogDeactivated signal when + * the exec() method returns. + */ + void showDialog( QDialog *aDialog, bool blocking = true, bool aSendSignal = true ); + + //! View event is detected. + /*! + * WindowManager connects this slot to ViewBase classes eventDetected() + * signal and either emits eventDetected() signal if the current views + * type is ViewMode::NormalView or restores possible previous view + * if the current views type is ViewMode::ObservedView. + */ + void viewEventDetected(); + + void setFullscreen(); + + void error( const QString &aErrorMessage ); + +private: + //! Name of the application. + QString iApplicationName; + + //! Currently active view. + ViewBase *iCurrentView; + + //! Stack of views previously displayed. + QStack iViewList; + +}; + +#endif /*WINDOWMANAGER_H_*/