From: Zoltan Papp Date: Tue, 19 May 2009 12:28:55 +0000 (+0300) Subject: Re-factored the basic idea of the application: Engine is the main class that ownsWind... X-Git-Url: https://vcs.maemo.org/git/?p=qtmeetings;a=commitdiff_plain;h=a4efac92adf76a72d0bacc30eb99b79d148588d6 Re-factored the basic idea of the application: Engine is the main class that ownsWindowManager from now on. --- diff --git a/QtMeetings.pro b/QtMeetings.pro index 38adacb..cbe1b6c 100644 --- a/QtMeetings.pro +++ b/QtMeetings.pro @@ -1,10 +1,7 @@ TEMPLATE = app - TARGET = qtmeetings - QT += xml \ network - INCLUDEPATH += src/Domain/ \ src/Domain/Configuration/ \ src/IO/ \ @@ -16,8 +13,8 @@ INCLUDEPATH += src/Domain/ \ src/UserInterface/Components/ \ src/UserInterface/Utils/ \ src/UserInterface/Views/ - -HEADERS += src/Domain/Room.h \ +HEADERS += src/UserInterface/Utils/ProgressBar.h \ + src/Domain/Room.h \ src/Domain/Meeting.h \ src/Domain/Configuration/ConnectionSettings.h \ src/Domain/Configuration/StartupSettings.h \ @@ -47,8 +44,8 @@ HEADERS += src/Domain/Room.h \ src/UserInterface/Views/MeetingInfoDialog.h \ src/UserInterface/Views/SettingsView.h \ src/UserInterface/WindowManager.h - -SOURCES += src/Domain/Room.cpp \ +SOURCES += src/UserInterface/Utils/ProgressBar.cpp \ + src/Domain/Room.cpp \ src/Domain/Meeting.cpp \ src/Domain/Configuration/ConnectionSettings.cpp \ src/Domain/Configuration/StartupSettings.cpp \ @@ -79,50 +76,40 @@ SOURCES += src/Domain/Room.cpp \ src/UserInterface/Views/SettingsView.cpp \ src/UserInterface/WindowManager.cpp \ src/main.cpp - RESOURCES += resources/BusinessLogic.qrc \ resources/UserInterface.qrc - CONFIG += link_pkgconfig PKGCONFIG += libalarm -DEFINES += QT_NO_DEBUG_OUTPUT - +# DEFINES += QT_NO_DEBUG_OUTPUT executable.files = qtmeetings executable.path = /usr/bin/ executable.hint = executable INSTALLS += executable - appconfig.files = QtMeetings.conf appconfig.path = /etc/ appconfig.hint = appconfig INSTALLS += appconfig - desktop.files = QtMeetings.desktop desktop.path = /usr/share/applications/hildon/ desktop.hint = desktop INSTALLS += desktop - devstopperscript.files = scripts/qtmeetings-devstopper devstopperscript.path = /usr/bin/ devstopperscript.hint = devstopperscript INSTALLS += devstopperscript - renamescript.files = scripts/qtmeetings-rename renamescript.path = /usr/bin/ renamescript.hint = renamescript INSTALLS += renamescript - updatercdscript.files = scripts/qtmeetings-updatercd updatercdscript.path = /usr/bin/ updatercdscript.hint = updatercdscript INSTALLS += updatercdscript - launcherscript.files = scripts/qtmeetings-launcher launcherscript.path = /etc/init.d/ launcherscript.hint = launcherscript INSTALLS += launcherscript - unix:exists( $$system(which doxygen) ) { message( "Doxygen is present in your system." ) BUILD_NOW = $$prompt( "Do you want to build Doxygen documentation now? [YES/no]" ) diff --git a/debian/postrm b/debian/postrm index 00ece1c..5ca9600 100644 --- a/debian/postrm +++ b/debian/postrm @@ -25,4 +25,8 @@ if [ -e /usr/var/qtmeetings.txt ]; then rm /usr/var/qtmeetings.txt fi +if [ -e /usr/var/qtmeetings.log ]; then + rm /usr/var/qtmeetings.log +fi + exit 0 diff --git a/src/BusinessLogic/Engine.cpp b/src/BusinessLogic/Engine.cpp index 2f943a7..6e677c4 100644 --- a/src/BusinessLogic/Engine.cpp +++ b/src/BusinessLogic/Engine.cpp @@ -1,49 +1,61 @@ #include "Engine.h" - -#include -#include #include "Room.h" #include "Meeting.h" #include "ConnectionSettings.h" #include "Configuration.h" +#include "DisplaySettings.h" #include "CommunicationManager.h" #include "DeviceManager.h" #include "Clock.h" #include "ErrorMapper.h" +#include "WeeklyViewWidget.h" +#include +#include +#include #include 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 ), iCurrentRoom( 0 ) + iClock( 0 ), iConfiguration( Configuration::instance() ), iCommunication( 0 ) { // if reading of configuration fails, signal that initialization failed if ( iConfiguration == 0 ) { - QTimer::singleShot( 0, this, SIGNAL( initializationFailed() ) ); + QTimer::singleShot( 0, this, SLOT( closeApplication() ) ); return; } + + //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 ) ) ); + // 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& ) ) - ); + 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& ) ) ); + + //initialize idle time counter + iIdleTimeCounter = new QTimer(); + iIdleTimeCounter->setSingleShot( true ); + iIdleTimeCounter->setInterval( IDLE_TIME_MULTIPLIER * iConfiguration->displaySettings()->screensaver() ); + 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 ) ) ); iAutoRefresh = new QTimer; iAutoRefresh->setInterval( iConfiguration->connectionSettings()->refreshInterval() * 1000 ); @@ -51,9 +63,15 @@ Engine::Engine() : 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( 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(); QTimer::singleShot( 0, this, SLOT( fetchMeetings() ) ); @@ -64,26 +82,39 @@ 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; } -Room* Engine::defaultRoom() +void Engine::closeApplication() { - return iConfiguration->defaultRoom(); + qDebug() << "Engine::closeApplication()"; + // closes application after 1 second + QTimer::singleShot( 1000, QApplication::instance(), SLOT( quit() ) ); } -Clock* Engine::clock() +void Engine::observedEventDetected() { - return iClock; -} - -Configuration* Engine::configuration() -{ - return iConfiguration; + iWindowManager->showWeeklyView(); + // prepare to restart idle counter + if ( iIdleTimeCounter->isActive() ) + { + iIdleTimeCounter->stop(); + } + // (re)start idle counter + iIdleTimeCounter->start(); } -DeviceManager* Engine::deviceManager() +Room* Engine::defaultRoom() { - return iDevice; + return iConfiguration->defaultRoom(); } void Engine::checkStatusOfAllRooms() @@ -143,8 +174,6 @@ void Engine::roomStatusInfoNeeded( Room *aRoom ) int indexOfCurrentMeeting = indexOfMeetingAt( aRoom, iClock->datetime() ); int indexOfNextMeeting = indexOfMeetingAfter( aRoom, iClock->datetime() ); -// qDebug() << QString( "Engine::roomStatusInfoNeeded\troom:%1current:%2 next:%3" ).arg( aRoom->toString() ).arg( indexOfCurrentMeeting ).arg( indexOfNextMeeting ); - // if there is no meeting, then status is Free; otherwise Busy Room::Status status = ( indexOfCurrentMeeting == -1 ) ? Room::FreeStatus : Room::BusyStatus; // if room is Busy, then check end time, otherwise... @@ -152,21 +181,16 @@ void Engine::roomStatusInfoNeeded( Room *aRoom ) // ...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 ); - emit roomStatusChanged( aRoom, status, until ); + //currently works only for deafult room + if( aRoom->equals( *(defaultRoom() ) ) ) + iWindowManager->roomStatusChanged( aRoom, status, until ); } void Engine::fetchMeetings() { - // TODO : define interval correctly. at the moment it's +/- 14 days - Room *room = iCurrentRoom; - if ( room == 0 ) room = defaultRoom(); + Room *room = defaultRoom(); qDebug() << "Engine::fetchMeetings for " << room->name(); - fetchMeetings( iClock->datetime().addDays( -14 ), iClock->datetime().addDays( 14 ), room ); -} - -void Engine::fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, Room *aIn ) -{ - iCommunication->fetchMeetings( aFrom, aUntil, *aIn ); + fetchMeetings( iClock->datetime(), iClock->datetime().addDays( 7 ), room ); } void Engine::fetchMeetingDetails( Meeting *aMeeting ) @@ -198,7 +222,7 @@ void Engine::meetingsFetched( const QList &aMeetings ) Meeting* m = new Meeting( *(aMeetings.at( i )) ); iMeetings.append( m ); // and signal the changes - emit meetingAdded( m ); + iWindowManager->insertMeeting( m ); } } @@ -210,7 +234,7 @@ void Engine::meetingsFetched( const QList &aMeetings ) { Meeting* m = iMeetings.takeAt( i ); // signal the changes - emit meetingDeleted( m ); + iWindowManager->deleteMeeting( m ); // delete the meeting from the local list delete m; } @@ -222,7 +246,7 @@ void Engine::meetingsFetched( const QList &aMeetings ) void Engine::meetingDetailsFetched( Meeting &aDetailedMeeting ) { - emit meetingDetailsFetched( &aDetailedMeeting ); + iWindowManager->showMeetingInfo( &aDetailedMeeting ); } void Engine::errorHandler( int aCode, const QString &aAddInfo ) @@ -231,11 +255,35 @@ void Engine::errorHandler( int aCode, const QString &aAddInfo ) // inform UI about the problem if( aCode >= 100 && aCode <= 110 ) qDebug() << "CommunicationManager signaled an error:" << aCode; - emit error( ErrorMapper::codeToString( aCode, aAddInfo ) ); + iWindowManager->error( ErrorMapper::codeToString( aCode, aAddInfo ) ); } void Engine::currentRoomChanged( Room *aCurrentRoom ) { - iCurrentRoom = aCurrentRoom; - qDebug() << "Engine::currentRoomChanged to " << iCurrentRoom->name(); + qDebug() << "Engine::currentRoomChanged to " << aCurrentRoom->name(); + QDateTime from( iWindowManager->weeklyView()->beginnigOfShownWeek() ); + QDateTime to( from.addDays( 8 ) ); + fetchMeetings( from, to, aCurrentRoom ); +} + +void Engine::fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn ) +{ + qDebug() << "Engine::fetchMeetings"; + iCommunication->fetchMeetings( aFrom, aUntil, *aIn ); +} + +void Engine::shownWeekChanged( QDate aFrom ) +{ + 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() ); +} + +void Engine::changeModeOrdered( DeviceManager::OperationMode aMode ) +{ + QString message = tr( "You are about to change operation mode to %1." ) + .arg( iDevice->operationModeToString( aMode ) ); + + iWindowManager->showPasswordDialog( iConfiguration->adminPassword(), message ); } diff --git a/src/BusinessLogic/Engine.h b/src/BusinessLogic/Engine.h index 47b2a4d..bec1f3b 100644 --- a/src/BusinessLogic/Engine.h +++ b/src/BusinessLogic/Engine.h @@ -4,6 +4,7 @@ #include #include #include "Room.h" +#include "WindowManager.h" class QTimer; class Clock; @@ -29,94 +30,46 @@ public: Engine(); //! Destructor. virtual ~Engine(); - - //! Gets the clock instance used by the object to get up-to-date date and time info. - /*! - * Gets the clock instance used by the object to get up-to-date date and time info. - * \return Pointer to the Clock instance. - */ - Clock* clock(); - //! Gets the application's configuration. - /*! - * Gets the application's configuration. - * \return Pointer to the Configuration instance. - */ - Configuration* configuration(); //! Gets default room of the application. /*! * Gets default room of the application. * \return Pointer to the default Room instance. */ Room* defaultRoom(); - //! Gets the deviceManager instance - /*! - * Gets the deviceManager instance. - * \return Pointer to the deviceManager instance. - */ - DeviceManager* deviceManager(); signals: - //! Signal. Emitted if initialization of the current instance failed. - /*! - * Signal. Emitted if initialization of the current instance failed, if reading of the configuration - * was not successful. It's purpose to inform the userinterface that the Engine is not ready for - * controlling the application, application must be shut down. - */ - void initializationFailed(); - //! Signal. Emitted if the availability information of the specified room changed. - /*! - * Signal. Emitted if the availability information of the specified room changed. - * \param aRoom The Room instance which availability changed. - * \param aStatus The status of the room. - * \param aUntil Time until the spacified status is valid. - */ - void roomStatusChanged( Room *aRoom, Room::Status aStatus, QTime aUntil ); - //! Signal. Emitted if new meeting was found on the server. - /*! - * Signal. Emitted if new meeting was found on the server. - * \param aMeeting The new meeting which was added. - */ - void meetingAdded( Meeting *aMeeting ); - //! Signal. Emitted if meeting was deleted on the server. - /*! - * Signal. Emitted if meeting was deleted on the server. - * \param aMeeting The meeting which was deleted. - */ - void meetingDeleted( Meeting *aMeeting ); - //! Signal. Emitted error occured and error message must be shown on UI. - /*! - * Signal. Emitted error occured and error message must be shown on UI. - * \param aErrorMessage The message. - */ - void error( const QString &aErrorMessage ); - void meetingDetailsFetched( Meeting *aDetailedMeeting ); + void meetingDetailsFetched( Meeting *aDetailedMeeting ); -public slots: +private slots: + //! Slot. Closes the application. + /*! + * Slot. Closes the application. + */ + void closeApplication(); //! Slot. Checks actual availability information of the specified room. /*! * Slot. Checks actual availability information of the specified room. * \param aRoom The room which availability information is needed. */ void roomStatusInfoNeeded( Room *aRoom ); - //! Slot. Fetches meetings from the server. + //! Slot. Indicates that some user event has happened. /*! - * Slot. Fetches meetings from the server, exact parameters are specified in the parameter list. - * \param aFrom Time from when the meetings need to be fetched. - * \param aUntil Time until when the meetings need to be fetched. - * \param aIn The room which meetings need to be fetched. + * Slot. Indicates that some user event has happened. */ - void fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, Room *aIn ); - - void fetchMeetingDetails( Meeting * ); - + void observedEventDetected(); + //! Slot. Asks the communication to fetch new meeting data. /*! - * Slot. Sets the current meeting room iCurrentRoom. - * \param aCurrentRoom + * Slot. Asks the communication to fetch new meeting data. + * \param aCurrentRoom The current room. */ void currentRoomChanged( Room *aCurrentRoom ); - -private slots: + //! Slot. Asks the communication to fetch new meeting data. + /*! + * Slot. Asks the communication to fetch new meeting data. + * \param aCurrentRoom The current room. + */ + void shownWeekChanged( QDate aDate ); //! Slot. Handles errors. /*! * Slot. Handles errors and informs the UI by emitting the error() signal with the message in @@ -148,7 +101,18 @@ private slots: * 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 ); private: //! Provides the index of the Meeting instance which is at the specified time. /*! @@ -176,10 +140,20 @@ private: * \return True if contains; otherwise, false. */ static bool isMeetingInList( const QList &aList, const Meeting *aMeeting ); + //! Slot. Fetches meetings from the server. + /*! + * Slot. Fetches meetings from the server, exact parameters are specified in the parameter list. + * \param aFrom Time from when the meetings need to be fetched. + * \param aUntil Time until when the meetings need to be fetched. + * \param aIn The room which meetings need to be fetched. + */ + void fetchMeetings( const QDateTime &aFrom, const QDateTime &aUntil, const Room *aIn ); private: static QTime endOfTheDay; + WindowManager *iWindowManager; + QTimer *iIdleTimeCounter; Clock *iClock; Configuration *iConfiguration; CommunicationManager *iCommunication; @@ -188,8 +162,6 @@ private: QTimer *iAutoRefresh; QList iMeetings; - - Room *iCurrentRoom; /*! Not owned */ }; #endif /*ENGINE_H_*/ diff --git a/src/Domain/Configuration/Configuration.cpp b/src/Domain/Configuration/Configuration.cpp index 9286846..56a4472 100644 --- a/src/Domain/Configuration/Configuration.cpp +++ b/src/Domain/Configuration/Configuration.cpp @@ -479,10 +479,10 @@ StartupSettings * Configuration::readStartupSettings( const QDomNode &aXML ) DisplaySettings * Configuration::readDisplaySettings( const QDomNode &aXML ) { - DisplaySettings::DaysInSchedule daysInSchedule; + DisplaySettings::DaysInSchedule daysInSchedule = DisplaySettings::WeekdaysInSchedule; QTime dayStartsAt, dayEndsAt; - DisplaySettings::DateFormat dateformat; - DisplaySettings::TimeFormat timeformat; + DisplaySettings::DateFormat dateformat = DisplaySettings::ShortDateFormat; + DisplaySettings::TimeFormat timeformat = DisplaySettings::TwentyFourHoursTimeFormat; int screensaver = 1; //! Default value for screensaver wait time for ( QDomNode node = aXML.firstChild(); !node.isNull(); node = node.nextSibling() ) diff --git a/src/UserInterface/Utils/PasswordDialog.cpp b/src/UserInterface/Utils/PasswordDialog.cpp index 332b0b6..3a8590f 100644 --- a/src/UserInterface/Utils/PasswordDialog.cpp +++ b/src/UserInterface/Utils/PasswordDialog.cpp @@ -7,7 +7,7 @@ #include #include -PasswordDialog::PasswordDialog( QWidget *aParent, const QString &aPassword, const QString &aText, const QString &aTitle ) : +PasswordDialog::PasswordDialog( const QString &aPassword, const QString &aText, const QString &aTitle, QWidget *aParent ) : QDialog( aParent ) { setWindowTitle( aTitle.isNull() ? tr( "Enter password" ) : aTitle ); @@ -61,10 +61,13 @@ PasswordDialog::PasswordDialog( QWidget *aParent, const QString &aPassword, cons // Enable the layout setLayout( layout ); + + show(); } PasswordDialog::~PasswordDialog() { + close(); } void PasswordDialog::okButtonPressed() @@ -75,8 +78,10 @@ void PasswordDialog::okButtonPressed() QCryptographicHash *hash = new QCryptographicHash( QCryptographicHash::Md5 ); hash->addData( iPasswordEdit->text().toUtf8() ); QByteArray userpw = hash->result(); - delete hash; + delete hash; + close(); + // Compare the password hashes and emit corresponding signal tellin if the password was correct if ( iPasswordHash == userpw.toHex() ) { @@ -88,25 +93,13 @@ void PasswordDialog::okButtonPressed() emit passwordEntered( PasswordDialog::Incorrect ); qDebug() << "Incorrect password!"; } - - // Close the dialog - close(); } void PasswordDialog::cancelButtonPressed() { qDebug() << "PasswordDialog::cancelButtonPressed()"; - - emit passwordEntered( PasswordDialog::Canceled ); - + close(); -} - -PasswordDialog * PasswordDialog::query( QWidget *aParent, const QString &aPassword, const QString &aText, const QString &aTitle ) -{ - // Create a PasswordDialog instance and show it - PasswordDialog* dlg = new PasswordDialog( aParent, aPassword, aText, aTitle ); - dlg->show(); - return dlg; + emit passwordEntered( PasswordDialog::Canceled ); } diff --git a/src/UserInterface/Utils/PasswordDialog.h b/src/UserInterface/Utils/PasswordDialog.h index 5bf8c62..86879c9 100644 --- a/src/UserInterface/Utils/PasswordDialog.h +++ b/src/UserInterface/Utils/PasswordDialog.h @@ -35,9 +35,9 @@ public: * \param aText Optional. Text displayed in the dialog. * \param aTitle Optional. Dialog title, defaults to "Enter password". * \return The instance which was created. - */ static PasswordDialog * query( QWidget *aParent, const QString &aPassword, const QString &aText = 0, const QString &aTitle = 0 ); + */ signals: //! Signals the authenticity of the password when the uuser dismisses the dialog. @@ -51,14 +51,14 @@ private slots: void okButtonPressed(); void cancelButtonPressed(); -private: +public: //! Constructor. /*! * Constructor to initialize a PasswordDialog instance. * \param aParent The parent object. * \param aPassword The password. */ - PasswordDialog( QWidget *aParent, const QString &aPassword, const QString &aText, const QString &aTitle ); + PasswordDialog( const QString &aPassword, const QString &aText, const QString &aTitle = "", QWidget *aParent = 0 ); //! Destructor. virtual ~PasswordDialog(); diff --git a/src/UserInterface/WindowManager.cpp b/src/UserInterface/WindowManager.cpp index edb7b95..8107fbb 100644 --- a/src/UserInterface/WindowManager.cpp +++ b/src/UserInterface/WindowManager.cpp @@ -1,12 +1,10 @@ #include "WindowManager.h" -#include #include #include "Configuration.h" #include "DisplaySettings.h" #include "Meeting.h" #include "Room.h" -#include "Engine.h" #include "Clock.h" #include "WeeklyViewWidget.h" #include "RoomStatusIndicatorWidget.h" @@ -14,86 +12,43 @@ #include "PopUpMessageBox.h" #include "DeviceManager.h" #include "SettingsView.h" +#include "ProgressBar.h" #include -const int IDLE_TIME_MULTIPLIER = 60000; // Multiplies milliseconds to minutes - -WindowManager::WindowManager() : +WindowManager::WindowManager( Configuration *aConfiguration ) : QObject(), iApplicationName( tr( "Qt Meetings" ) ), + iConfiguration( aConfiguration ), iWeeklyView( 0 ), iRoomStatusView( 0 ), - iMeetingInfo( 0 ) + iMeetingInfo( 0 ), + iProgressBar( 0 ), + iPasswordDialog( 0 ) { - iEngine = new Engine; - connect( iEngine, SIGNAL( initializationFailed() ), this, SLOT( closeApplication() ) ); - connect( this, SIGNAL( roomStatusInfoNeeded( Room * ) ), iEngine, SLOT( roomStatusInfoNeeded( Room * ) ) ); - connect( iEngine, SIGNAL( roomStatusChanged( Room *, Room::Status, QTime ) ), this, SLOT( roomStatusChanged( Room *, Room::Status, QTime ) ) ); - connect( iEngine->clock(), SIGNAL( tick( QDateTime ) ), this, SLOT( distributeDateTimeInfo( QDateTime ) ) ); - connect( iEngine, SIGNAL( error( QString ) ), this, SLOT( error( QString ) ) ); - connect( iEngine->deviceManager(), SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ), this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) ); - - iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), iEngine->configuration() ); + iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), aConfiguration ); iWeeklyView->setWindowTitle( iApplicationName ); - connect( iEngine, SIGNAL( meetingAdded( Meeting * ) ), iWeeklyView, SLOT( insertMeeting( Meeting * ) ) ); - connect( iEngine, SIGNAL( meetingDeleted( Meeting * ) ), iWeeklyView, SLOT( deleteMeeting( Meeting * ) ) ); - connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SLOT( observedEventDetected() ) ); - connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), iEngine, SLOT( fetchMeetingDetails( Meeting* ) ) ); - connect( iEngine, SIGNAL( meetingDetailsFetched( Meeting* ) ), this, SLOT( showMeetingInfo( Meeting * ) ) ); - connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), iEngine, SLOT( currentRoomChanged( Room * ) ) ); - connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), this, SLOT( fetchMeetings( Room * ) ) ); - // TODO: fetch meetings for specific week - connect( iWeeklyView, SIGNAL( shownWeekChanged( QDate ) ), this, SLOT( fetchMeetings( QDate ) ) ); - - iIdleTimeCounter = new QTimer(); - iIdleTimeCounter->setSingleShot( true ); - iIdleTimeCounter->setInterval( IDLE_TIME_MULTIPLIER * iEngine->configuration()->displaySettings()->screensaver() ); - iIdleTimeCounter->start(); - connect( iIdleTimeCounter, SIGNAL( timeout() ), this, SLOT( showRoomStatus() ) ); - - if( iEngine->deviceManager()->currentOperationMode() == DeviceManager::KioskMode ) - iWeeklyView->setWindowState( Qt::WindowFullScreen ); - else - iWeeklyView->setWindowState( Qt::WindowMaximized ); + 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(); - - //QTimer::singleShot( 0, this, SLOT( closeApplication() ) ); + } WindowManager::~WindowManager() { - if ( iWeeklyView != 0 ) - { - delete iWeeklyView; - iWeeklyView = 0; - } - - if ( iRoomStatusView != 0 ) - { - delete iRoomStatusView; - iRoomStatusView = 0; - } - - if ( iMeetingInfo != 0 ) - { - delete iMeetingInfo; - iMeetingInfo = 0; - } - - if ( iIdleTimeCounter ) - { - iIdleTimeCounter->stop(); - delete iIdleTimeCounter; - iIdleTimeCounter = 0; - } -} - -void WindowManager::closeApplication() -{ - qDebug() << "WindowManager::closeApplication\tclose application"; - // closes application after 1 second - QTimer::singleShot( 1000, QApplication::instance(), SLOT( quit() ) ); + 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 ) @@ -111,28 +66,19 @@ void WindowManager::distributeDateTimeInfo( QDateTime aCurrentDateTime ) void WindowManager::roomStatusChanged( Room *aRoom, Room::Status aStatus, QTime aTime ) { - // currently works only for default room - if ( aRoom->equals( *(iEngine->defaultRoom()) ) ) + if ( iRoomStatusView == 0 ) { - if ( iRoomStatusView == 0 ) - { - iRoomStatusView = new RoomStatusIndicatorWidget( aRoom, aStatus, aTime, iEngine->configuration()->displaySettings()->timeFormat() ); - iRoomStatusView->setWindowTitle( iApplicationName ); - connect( iRoomStatusView, SIGNAL( observedEventDetected() ), this, SLOT( observedEventDetected() ) ); - if( iEngine->deviceManager()->currentOperationMode() == DeviceManager::KioskMode ) - iRoomStatusView->setWindowState( Qt::WindowFullScreen ); - else - iRoomStatusView->setWindowState( Qt::WindowMaximized ); - } - else - { - iRoomStatusView->statusChanged( aStatus, aTime ); - } - - if ( !iWeeklyView->isVisible() && !iRoomStatusView->isVisible() ) - { - showRoomStatus(); - } + iRoomStatusView = new RoomStatusIndicatorWidget( aRoom, aStatus, aTime, iConfiguration->displaySettings()->timeFormat() ); + iRoomStatusView->setWindowTitle( iApplicationName ); + connect( iRoomStatusView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) ); + } + else + { + iRoomStatusView->statusChanged( aStatus, aTime ); + } + if ( !iWeeklyView->isVisible() && !iRoomStatusView->isVisible() ) + { + showRoomStatus(); } } @@ -142,7 +88,7 @@ void WindowManager::showRoomStatus() if ( iRoomStatusView == 0 ) { - iEngine->roomStatusInfoNeeded( iWeeklyView->currentRoom() ); + emit roomStatusInfoNeeded( iWeeklyView->currentRoom() ); } else { @@ -151,12 +97,6 @@ void WindowManager::showRoomStatus() { iWeeklyView->hide(); } - /* Causes SEGMENTATION FAULT - if ( iSettingsView->isVisible() ) - { - iSettingsView->hide(); - } - */ } // closing/deleting meeting info dialog @@ -177,6 +117,22 @@ void WindowManager::showWeeklyView() iWeeklyView->show(); } +void WindowManager::fullScreen() +{ + iRoomStatusView->setWindowState( Qt::WindowFullScreen ); + iWeeklyView->setWindowState( Qt::WindowFullScreen ); +} + +void WindowManager::insertMeeting( Meeting *aMeeting ) +{ + iWeeklyView->insertMeeting( aMeeting ); +} + +void WindowManager::deleteMeeting( Meeting *aMeeting ) +{ + iWeeklyView->deleteMeeting( aMeeting ); +} + void WindowManager::showMeetingInfo( Meeting *aMeeting ) { iMeetingInfo = new MeetingInfoDialog( aMeeting ); @@ -192,81 +148,65 @@ void WindowManager::showSettingsView() // TODO : give the Torspo for the person who was responsible to write this method } -void WindowManager::error( const QString &aErrorMessage ) -{ - qDebug() << "WindowManager::showErrorPopup"; - - PopUpMessageBox::error( 0, aErrorMessage ); -} - -void WindowManager::observedEventDetected() -{ - // if event was detected on room status view - if ( iRoomStatusView != 0 && iRoomStatusView->isVisible() ) - { - // show weekly view - showWeeklyView(); - } - // otherwise - else - { - // prepare to restart idle counter - if ( iIdleTimeCounter->isActive() ) - { - iIdleTimeCounter->stop(); - } - } - // (re)start idle counter - iIdleTimeCounter->start(); -} - -void WindowManager::fetchMeetings( Room * aRoom ) +WeeklyViewWidget * WindowManager::weeklyView() { - QDateTime from( iWeeklyView->beginnigOfShownWeek() ); - QDateTime to( from.addDays( 8 ) ); - qDebug() << "WindowManager::fetchMeetings from " << from.toString( "d.m. h:mm" ) - << " to " << to.toString( "d.m. h:mm" ); - iEngine->fetchMeetings( from, to, aRoom ); + return iWeeklyView; } -void WindowManager::fetchMeetings( QDate aFrom ) +void WindowManager::error( const QString &aErrorMessage ) { - QDateTime from( aFrom ); - QDateTime to( aFrom.addDays( 7 ), QTime( 23, 59 ) ); - qDebug() << "WindowManager::fetchMeetings from " << from.toString( "d.m. h:mm" ) - << " to " << to.toString( "d.m. h:mm" ); - iEngine->fetchMeetings( from, to, iWeeklyView->currentRoom() ); -} + qDebug() << "WindowManager::showErrorPopup"; -void WindowManager::changeModeOrdered( DeviceManager::OperationMode aMode ) -{ - QString message = tr( "You are about to change operation mode to %1." ) - .arg( iEngine->deviceManager()->operationModeToString( aMode ) ); - PasswordDialog *dlg = PasswordDialog::query( 0, iEngine->configuration()->adminPassword(), message ); - qDebug() << "WindowManager::changeModeOrdered/tpassword: " << iEngine->configuration()->adminPassword(); - //TODO make this modal!!! - connect( dlg, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), - this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) ); + PopUpMessageBox::error( 0, aErrorMessage ); } void WindowManager::passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus ) { + delete iPasswordDialog; + iPasswordDialog = 0; + switch ( aPasswordStatus ) { case PasswordDialog::Correct : { - iEngine->deviceManager()->changeMode( true ); + progressBar( tr( "Changing operation mode" ), true ); + iProgressBar->show(); + while(1); break; } case PasswordDialog::Incorrect : { error( tr( "Incorrect password." ) ); - iEngine->deviceManager()->changeMode( false ); break; } default : //case PasswordDialog::Canceled { - iEngine->deviceManager()->changeMode( false ); } } } + +void WindowManager::showPasswordDialog( QByteArray aAdminPassword, const QString &aMessage ) +{ + iPasswordDialog = new PasswordDialog( aAdminPassword, aMessage ); + iPasswordDialog->show(); +} + + +void WindowManager::progressBar( const QString &aText, bool aStart ) +{ + qDebug() << "WindowManager::progressBar( const QString &, bool)"; + if( aStart ) { + if( iProgressBar == 0 ) { + iProgressBar = new ProgressBar( aText ); + connect( iProgressBar, SIGNAL( cancel() ), this, SLOT( progressBar() ) ); + connect( iProgressBar, SIGNAL( started() ), this, SLOT( changeMode() ) ); + } + } + else { + if( iProgressBar != 0 ) { + delete iProgressBar; + iProgressBar = 0; + } + } +} + diff --git a/src/UserInterface/WindowManager.h b/src/UserInterface/WindowManager.h index f1f72b5..0c85515 100644 --- a/src/UserInterface/WindowManager.h +++ b/src/UserInterface/WindowManager.h @@ -14,6 +14,8 @@ 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. /*! @@ -30,72 +32,104 @@ public: //! Constructor. /*! * Constructor of WindowManager. + * \param aConfiguration The pointer to configuration. */ - WindowManager(); + WindowManager( Configuration *aConfiguration ); //! Destructor. virtual ~WindowManager(); - -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 ); - -private slots: - //! Closes the application. - void closeApplication(); - //! Updates the time. - /*! - * Forwards the signal of changed time to current view. - * \param aCurrentDateTime Current date and time. + * Displays an error message + * \param aErrorMessage Message to be displayd */ - void distributeDateTimeInfo( QDateTime aCurrentDateTime ); + 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 ); - //! Displays the weekly view + //! 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 ); + //! Displays the weekly view. + /*! + * Displays the weekly view. + */ void showWeeklyView(); - //! Displays the screensaver (room status view) - void showRoomStatus(); - //! Displays the settings view - void showSettingsView(); + //! Displays the meeting info dialog. /*! - * 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. /*! - * Displays an error message - * \param aErrorMessage Message to be displayd + * Returns the pointer to the weekly view. + */ + WeeklyViewWidget * weeklyView(); + //! Switches the views to full screen. + /*! + * Switches the views to full screen. + */ + void fullScreen(); + + void insertMeeting( Meeting *aMeeting ); + + void deleteMeeting( Meeting *aMeeting ); + +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 error( const QString &aErrorMessage ); - //! Restarts the timer to launch the screensaver. void observedEventDetected(); - //! Slot for fetching meetings. + //! Meeting activated. /*! - * Slot. Fetches meetings for room aRoom for currently visible week - * \param aRoom + * Signal is emitted when a meeting is clicked by the user. + * \param aMeeting actived meeting. */ - void fetchMeetings( Room *aRoom ); - //! Slot for fetching meetings. + void meetingActivated( Meeting *aMeeting ); + //! Signals if the shown week has been changed. /*! - * Slot. Fetches meetings for current room from date aFrom to week ahead. - * \param aFrom Date where to begin fetching + * Signal. Emitted if the shown week has been changed. + * \param aDate The first date of the shown week. */ - void fetchMeetings( QDate aFrom ); - //! Slot for popping up the confirmation dialog to change the current operation mode + void shownWeekChanged( QDate aDate ); + //! Signals change of the meeting room. /*! - * Slot. Asks PopUpMessageBox to pop up a confirmation dialog. - * \param aMode The operation mode to be changed to + * Signal is emitted when meeting room is changed. + * \param aRoom Selected meeting room. */ - void changeModeOrdered( DeviceManager::OperationMode aMode ); + void currentRoomChanged( Room *aRoom ); + +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 ); + +private slots: + //! Displays the settings view + void showSettingsView(); //! Slot for receiving the status of the entered password /*! * Slot. Receives the status of the entered password and makes the DeviceManager to change the @@ -103,22 +137,31 @@ private slots: * \param aPasswordStatus The status of the password. */ void passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus ); + //! Slot for showing/hiding the progress bar. + /*! + * Slot. Starts showing or hides the progress bar. + * \param aText The text to be shown in progress bar. + * \param aStart to indicate whether the progress bar is wanted to shown or hidden + */ + void progressBar( const QString &aText = "", bool aStart = false ); private: //! Name of the application. QString iApplicationName; + //! 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 engine. - Engine *iEngine; - //! Timer to launch the screensaver widget - QTimer *iIdleTimeCounter; //! Pointer to the settings view SettingsView *iSettingsView; + //! Pointer to the progress bar + ProgressBar *iProgressBar; + //! Pointer to the password dialog. + PasswordDialog *iPasswordDialog; }; diff --git a/src/main.cpp b/src/main.cpp index 9ed1c36..feaca6e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include "WindowManager.h" +#include "Engine.h" using namespace std; @@ -31,11 +31,11 @@ void DebugOutputHandler( QtMsgType type, const char *msg ) { int main( int argc, char *argv[] ) { #ifndef QT_NO_DEBUG_OUTPUT - logfile.open( "/tmp/qtmeetings.log", ios::app ); + logfile.open( "/usr/var/qtmeetings.log", ios::app ); qInstallMsgHandler( DebugOutputHandler ); #endif QApplication app( argc, argv ); - WindowManager *windowManager = new WindowManager; + Engine *engine = new Engine; return app.exec(); }