#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 <QApplication>
#include <QTimer>
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<Meeting*>& ) ), this, SLOT( meetingsFetched( const QList<Meeting*>& ) ));
- 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->setInterval( 10000 );
+ iIdleTimeCounter->setSingleShot( true);
+ iIdleTimeCounter->setInterval(IDLE_TIME_MULTIPLIER * iConfiguration->displaySettings()->screensaver() );
iIdleTimeCounter->start();
// 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() ) );
++ // 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() ) );
++ // QTimer::singleShot( 0, this, SLOT( fetchMeetings() ) );
// TODO: continue implementation
}
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()
QTimer::singleShot( 1000, QApplication::instance(), SLOT( quit() ));
}
-void Engine::observedEventDetected()
-{
- qDebug() << "Engine::observedEventDetected()";
- if ( !iIdleTimeCounter->isActive() )
- {
- iWindowManager->weeklyView()->showCurrentWeek();
- }
- iWindowManager->showWeeklyView();
- // prepare to restart idle counter
- if (iIdleTimeCounter->isActive() )
- {
- iIdleTimeCounter->stop();
- }
- // (re)start idle counter
- iIdleTimeCounter->start();
-}
-
Room* Engine::defaultRoom()
{
qDebug() << "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++)
{
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)
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++)
void Engine::roomStatusInfoNeeded(Room *aRoom)
{
- qDebug() << "Engine::roomStatusInfoNeeded( Room * )";
- if (aRoom == 0)
+// qDebug() << "Engine::roomStatusInfoNeeded( Room * )";
+ if ( aRoom == 0 )
{
return;
}
int indexOfNextMeeting = indexOfMeetingAfter(aRoom, iClock->datetime() );
// if there is no meeting, then status is Free; otherwise Busy
- Room::Status
- status =
- (indexOfCurrentMeeting == -1 ) ? Room::FreeStatus : Room::BusyStatus;
+ Room::Status status = (indexOfCurrentMeeting == -1 ) ? Room::FreeStatus : Room::BusyStatus;
// if room is Busy, then check end time, otherwise...
QTime until = (status == Room::BusyStatus ) ? iMeetings.at( indexOfCurrentMeeting )->endsAt().time() :
// ...if there is meeting following on the same day then check end time, otherwise end is the of the working day
- ((indexOfNextMeeting != -1 ) ? iMeetings.at( indexOfNextMeeting )->startsAt().time() : Engine::endOfTheDay );
+ ( ( 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()
{
- Room *room = defaultRoom();
- qDebug() << "Engine::fetchMeetings for " << room->name();
- fetchMeetings(iClock->datetime(), iClock->datetime().addDays( 7), room);
- qDebug() << "Engine::fetchMeetings for " << iWindowManager->weeklyView()->currentRoom();
++ qDebug() << "Engine::fetchMeetings for " << iCurrentRoom;
+ QDateTime from( iWindowManager->weeklyView()->beginnigOfShownWeek() );
+ QDateTime to( from.addDays( 7 ) );
- fetchMeetings( from, to, iWindowManager->weeklyView()->currentRoom() );
++ // fetchMeetings( from, to, iWindowManager->weeklyView()->currentRoom() );
++ // Signal is connected to the currentRoomChanged slot which keeps the iCurrentRoom up to date
++ fetchMeetings( from, to, iCurrentRoom );
}
++*/
- void Engine::fetchMeetingDetails(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() ));
+/* iWindowManager->showProgressBar(tr("Please Wait"), true);
+ iWindowManager->updateProgressBar(tr("Fetching Meeting Details...") );
+ connect(iWindowManager,
+ SIGNAL( progressBarCancelled() ), this,
+ SLOT( fetchMeetingDetailsCancelled() ));
+ iCommunication->fetchMeetingDetails( *aMeeting); */
-
iCommunication->fetchMeetingDetails( *aMeeting );
}
}
iMeetings.clear();
for ( int i = 0; i < aMeetings.count(); ++i ) {
- Meeting* m = new Meeting( *(aMeetings.at( i )) );
+ Meeting* m = new Meeting( *( aMeetings.at( i ) ) );
iMeetings.append( m );
}
- iWindowManager->refreshMeetings( iMeetings );
// refresh room status info
- roomStatusInfoNeeded(defaultRoom() );
+ roomStatusInfoNeeded( defaultRoom() );
}
-void Engine::meetingDetailsFetched( Meeting &aDetailedMeeting )
-{
- qDebug() << "Engine::meetingDetailsFetched( Meeting & )";
- iWindowManager->closeProgressBar();
- iWindowManager->showMeetingInfo( &aDetailedMeeting );
-}
-
void Engine::errorHandler( int aCode, const QString &aAddInfo )
-{
- 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();
+{
+ if ( iWindowManager != 0 )
+ {
+ iWindowManager->error( ErrorMapper::codeToString( aCode, aAddInfo ) );
}
- iWindowManager->error( ErrorMapper::codeToString(aCode, aAddInfo ) );
}
-void Engine::currentRoomChanged( Room *aCurrentRoom )
+void Engine::fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn )
{
- qDebug() << "Engine::currentRoomChanged to " << aCurrentRoom->name();
- QDateTime from(iWindowManager->weeklyView()->beginnigOfShownWeek() );
- QDateTime to( from.addDays( 7 ) );
- fetchMeetings( from, to, aCurrentRoom );
+ qDebug()
+ << "Engine::fetchMeetings( const QDateTime &, const QDateTime &, const Room * )";
+ iCommunication->fetchMeetings(aFrom, aUntil, *aIn);
}
-void Engine::fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn )
+void Engine::cancelFetchMeetingDetails()
{
- qDebug() << "Engine::fetchMeetings( const QDateTime &, const QDateTime &, const Room * )";
- iCommunication->fetchMeetings( aFrom, aUntil, *aIn );
+ iCommunication->cancelFetchMeetingDetails();
}
void Engine::shownWeekChanged( QDate aFrom )
{
- qDebug() << "Engine::shownWeekChanged( QDate )";
+ qDebug() << "[Engine::shownWeekChanged] <Invoked>";
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() );
+ qDebug() << "[Engine::shownWeekChanged] <From " << aFrom.toString( "d.m. h:mm" ) << " to " << to.toString( "d.m. h:mm" ) << ">";
+ 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
+ }
+ iDevice->changeMode( aChange );
+}
+
+void Engine::changeModeFailed()
+{
+ qDebug() << "Engine::progressBarCancelled()";
+ iDevice->changeMode( false );
+ iAutoRefresh->start(); //we start the metting updating
}
-void Engine::changeModeOrdered( DeviceManager::OperationMode aMode )
+void Engine::initUserInterface()
{
- qDebug() << "Engine::changeModeOrdered( DeviceManager::OperationMode )";
- QString message = tr( "You are about to change operation mode to %1." ).arg( iDevice->operationModeToString(aMode ) );
+ qDebug() << "[Engine::initUserInterface] <Invoked>";
+
+ // 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] <Finished>";
+}
- iWindowManager->showPasswordDialog( iConfiguration->adminPassword(), message );
+void Engine::handleViewEvent()
+{
+ if ( iIdleTimeCounter != 0 )
+ {
+ // Restart the idle time counter when view event is received
+ iIdleTimeCounter->stop();
+ iIdleTimeCounter->start();
+ }
}
-void Engine::passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus )
+void Engine::initConfiguration()
{
- qDebug() << "Engine::passwordEntered( PasswordDialog::PasswordStatus )";
- iWindowManager->closePasswordDialog();
-
- switch ( aPasswordStatus ) {
- 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 );
+ iConfiguration = Configuration::instance();
+ if ( iConfiguration == 0 )
+ {
+ QTimer::singleShot( 0, this, SLOT( closeApplication() ) );
}
++ iCurrentRoom = iConfiguration->defaultRoom();
}
-void Engine::changeModeFailed()
+void Engine::connectSignals()
{
- qDebug() << "Engine::changeModeFailed()";
- iWindowManager->closeProgressBar();
- iAutoRefresh->start(); //we start the metting updating
+ // 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::fetchMeetingDetailsCancelled()
+void Engine::initCommunication()
{
- iCommunication->cancelFetchMeetingDetails();
- iWindowManager->closeProgressBar();
+ // initialize communication
+ iCommunication = new CommunicationManager( *(iConfiguration->connectionSettings()) );
+ connect( iCommunication, SIGNAL( error( int, CommunicationManager::CommunicationType ) ),
+ this, SLOT( errorHandler( int ) ) );
+ connect( iCommunication, SIGNAL( meetingsFetched( const QList<Meeting*>& ) ),
+ this, SLOT( meetingsFetched( const QList<Meeting*>& ) ) );
}
+void Engine::initDevice()
+{
+ // create device manager
+ iDevice = new DeviceManager( iConfiguration->startupSettings() );
+ connect( iDevice, SIGNAL( error( int, const QString& ) ), this, SLOT( errorHandler( int, const QString& ) ) );
+ iDevice->initDeviceManager();
+}
+
+void Engine::dialogActivated()
+{
+ if ( iIdleTimeCounter != 0 )
+ {
+ iIdleTimeCounter->stop();
+ }
+}
+
+void Engine::dialogDeactivated()
+{
+ if ( iIdleTimeCounter != 0 )
+ {
+ iIdleTimeCounter->start();
+ }
+}
+
+void Engine::previousViewRestored()
+{
+ if ( iIdleTimeCounter != 0 )
+ {
+ iIdleTimeCounter->start();
+ }
+}
+
+void Engine::stopIdleTimeCounter()
+{
+ if ( iIdleTimeCounter != 0 )
+ {
+ iIdleTimeCounter->stop();
+ }
+}
+
+void Engine::startIdleTimeCounter()
+{
+ if ( iIdleTimeCounter != 0 )
+ {
+ iIdleTimeCounter->start();
+ }
+}
+
++void Engine::currentRoomChanged(Room *aRoom)
++{
++ iCurrentRoom = aRoom;
++}
#include <QDateTime>
#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.
/*!
signals:
- void meetingDetailsFetched( Meeting *aDetailedMeeting );
-
private slots:
//! Slot. Closes the application.
/*!
* \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.
* Slot. Fetches meetings from the server. Parameters are hard coded: the meetings of the default
* room from current and +/- 2 weeks are fetched.
*/
-- void fetchMeetings();
++// void fetchMeetings();
//! Slot. Saves fetched meetings to the current instance's local storage.
/*!
* Slot. Saves fetched meetings to the current instance's local storage. Meetings are soted in a
* \param aMeetings The list of freshly fetched meetings.
*/
void meetingsFetched( const QList<Meeting*>& );
-
- 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.
/*!
* 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 );
+
++ void currentRoomChanged( Room *aRoom );
++
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
* \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;
WindowManager *iWindowManager;
+
QTimer *iIdleTimeCounter;
Clock *iClock;
Configuration *iConfiguration;
CommunicationManager *iCommunication;
DeviceManager *iDevice;
+ UIManager *iUIManager;
QTimer *iAutoRefresh;
QList<Meeting*> iMeetings;
++
++ Room *iCurrentRoom;
};
#endif /*ENGINE_H_*/
--- /dev/null
+#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 ) ) );
++ connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), iEngine, SLOT( currentRoomChanged( Room * ) ) );
+}
+
+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<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] <Change the weekly views method to slot so we don't need this>";
+ if ( iWeeklyView != 0 )
+ {
+ iWeeklyView->refreshMeetings( aMeetings );
+ }
+}
+
+void UIManager::showMeetingProgressBar( Meeting *aMeeting )
+{
+ if ( iProgressBar != 0 )
+ {
+ iProgressBar->update( tr("Fetching meeting info...") );
+ iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
+ iEngine->stopIdleTimeCounter();
+ }
+}
+
+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
+ }
+ MeetingInfoDialog *tmp = new MeetingInfoDialog( &aDetailedMeeting );
+ iWindowManager->showDialog( static_cast<QDialog *>( tmp ) );
+// TODO : We should use the member variable and implement correctly the setMeeting() method !!!
+// iMeetingInfo->setMeeting( &aDetailedMeeting );
+// iWindowManager->showDialog( static_cast<QDialog *>( 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();
+ iEngine->startIdleTimeCounter();
+ }
+}
+
+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();
+ }
+}