1 #include "WindowManager.h"
3 #include <QApplication>
5 #include "Configuration.h"
6 #include "DisplaySettings.h"
11 #include "WeeklyViewWidget.h"
12 #include "RoomStatusIndicatorWidget.h"
13 #include "MeetingInfoDialog.h"
14 #include "PopUpMessageBox.h"
15 #include "DeviceManager.h"
16 #include "SettingsView.h"
20 const int IDLE_TIME_MULTIPLIER = 60000; // Multiplies milliseconds to minutes
22 WindowManager::WindowManager() :
24 iApplicationName( tr( "Qt Meetings" ) ),
30 connect( iEngine, SIGNAL( initializationFailed() ), this, SLOT( closeApplication() ) );
31 connect( this, SIGNAL( roomStatusInfoNeeded( Room * ) ), iEngine, SLOT( roomStatusInfoNeeded( Room * ) ) );
32 connect( iEngine, SIGNAL( roomStatusChanged( Room *, Room::Status, QTime ) ), this, SLOT( roomStatusChanged( Room *, Room::Status, QTime ) ) );
33 connect( iEngine->clock(), SIGNAL( tick( QDateTime ) ), this, SLOT( distributeDateTimeInfo( QDateTime ) ) );
34 connect( iEngine, SIGNAL( error( QString ) ), this, SLOT( error( QString ) ) );
35 connect( iEngine->deviceManager(), SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ), this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) );
37 iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), iEngine->configuration() );
38 iWeeklyView->setWindowTitle( iApplicationName );
39 connect( iEngine, SIGNAL( meetingAdded( Meeting * ) ), iWeeklyView, SLOT( insertMeeting( Meeting * ) ) );
40 connect( iEngine, SIGNAL( meetingDeleted( Meeting * ) ), iWeeklyView, SLOT( deleteMeeting( Meeting * ) ) );
41 connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SLOT( observedEventDetected() ) );
42 connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), iEngine, SLOT( fetchMeetingDetails( Meeting* ) ) );
43 connect( iEngine, SIGNAL( meetingDetailsFetched( Meeting* ) ), this, SLOT( showMeetingInfo( Meeting * ) ) );
44 connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), iEngine, SLOT( currentRoomChanged( Room * ) ) );
45 connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), this, SLOT( fetchMeetings( Room * ) ) );
46 // TODO: fetch meetings for specific week
47 connect( iWeeklyView, SIGNAL( shownWeekChanged( QDate ) ), this, SLOT( fetchMeetings( QDate ) ) );
49 iIdleTimeCounter = new QTimer();
50 iIdleTimeCounter->setSingleShot( true );
51 iIdleTimeCounter->setInterval( IDLE_TIME_MULTIPLIER * iEngine->configuration()->displaySettings()->screensaver() );
52 iIdleTimeCounter->start();
53 connect( iIdleTimeCounter, SIGNAL( timeout() ), this, SLOT( showRoomStatus() ) );
55 if( iEngine->deviceManager()->currentOperationMode() == DeviceManager::KioskMode )
56 iWeeklyView->setWindowState( Qt::WindowFullScreen );
58 iWeeklyView->setWindowState( Qt::WindowMaximized );
61 //QTimer::singleShot( 0, this, SLOT( closeApplication() ) );
64 WindowManager::~WindowManager()
66 if ( iWeeklyView != 0 )
72 if ( iRoomStatusView != 0 )
74 delete iRoomStatusView;
78 if ( iMeetingInfo != 0 )
84 if ( iIdleTimeCounter )
86 iIdleTimeCounter->stop();
87 delete iIdleTimeCounter;
92 void WindowManager::closeApplication()
94 qDebug() << "WindowManager::closeApplication\tclose application";
95 // closes application after 1 second
96 QTimer::singleShot( 1000, QApplication::instance(), SLOT( quit() ) );
99 void WindowManager::distributeDateTimeInfo( QDateTime aCurrentDateTime )
101 if ( iRoomStatusView != 0 && iRoomStatusView->isActiveWindow() )
103 iRoomStatusView->setCurrentTime( aCurrentDateTime.time() );
106 if ( iWeeklyView != 0 && iWeeklyView->isActiveWindow() )
108 iWeeklyView->setCurrentDateTime( aCurrentDateTime );
112 void WindowManager::roomStatusChanged( Room *aRoom, Room::Status aStatus, QTime aTime )
114 // currently works only for default room
115 if ( aRoom->equals( *(iEngine->defaultRoom()) ) )
117 if ( iRoomStatusView == 0 )
119 iRoomStatusView = new RoomStatusIndicatorWidget( aRoom, aStatus, aTime, iEngine->configuration()->displaySettings()->timeFormat() );
120 iRoomStatusView->setWindowTitle( iApplicationName );
121 connect( iRoomStatusView, SIGNAL( observedEventDetected() ), this, SLOT( observedEventDetected() ) );
122 if( iEngine->deviceManager()->currentOperationMode() == DeviceManager::KioskMode )
123 iRoomStatusView->setWindowState( Qt::WindowFullScreen );
125 iRoomStatusView->setWindowState( Qt::WindowMaximized );
129 iRoomStatusView->statusChanged( aStatus, aTime );
132 if ( !iWeeklyView->isVisible() && !iRoomStatusView->isVisible() )
139 void WindowManager::showRoomStatus()
141 qDebug() << "WindowManager::showRoomStatus";
143 if ( iRoomStatusView == 0 )
145 iEngine->roomStatusInfoNeeded( iWeeklyView->currentRoom() );
149 iRoomStatusView->show();
150 if ( iWeeklyView->isVisible() )
154 /* Causes SEGMENTATION FAULT
155 if ( iSettingsView->isVisible() )
157 iSettingsView->hide();
162 // closing/deleting meeting info dialog
163 if ( iMeetingInfo != 0 )
165 iMeetingInfo->hide();
169 void WindowManager::showWeeklyView()
171 qDebug() << "WindowManager::showWeeklyView";
172 if ( iRoomStatusView != 0 && iRoomStatusView->isVisible() )
174 iRoomStatusView->hide();
180 void WindowManager::showMeetingInfo( Meeting *aMeeting )
182 iMeetingInfo = new MeetingInfoDialog( aMeeting );
183 // Display modal dialog
184 iMeetingInfo->exec();
190 void WindowManager::showSettingsView()
192 // TODO : give the Torspo for the person who was responsible to write this method
195 void WindowManager::error( const QString &aErrorMessage )
197 qDebug() << "WindowManager::showErrorPopup";
199 PopUpMessageBox::error( 0, aErrorMessage );
202 void WindowManager::observedEventDetected()
204 // if event was detected on room status view
205 if ( iRoomStatusView != 0 && iRoomStatusView->isVisible() )
213 // prepare to restart idle counter
214 if ( iIdleTimeCounter->isActive() )
216 iIdleTimeCounter->stop();
219 // (re)start idle counter
220 iIdleTimeCounter->start();
223 void WindowManager::fetchMeetings( Room * aRoom )
225 QDateTime from( iWeeklyView->beginnigOfShownWeek() );
226 QDateTime to( from.addDays( 8 ) );
227 qDebug() << "WindowManager::fetchMeetings from " << from.toString( "d.m. h:mm" )
228 << " to " << to.toString( "d.m. h:mm" );
229 iEngine->fetchMeetings( from, to, aRoom );
232 void WindowManager::fetchMeetings( QDate aFrom )
234 QDateTime from( aFrom );
235 QDateTime to( aFrom.addDays( 7 ), QTime( 23, 59 ) );
236 qDebug() << "WindowManager::fetchMeetings from " << from.toString( "d.m. h:mm" )
237 << " to " << to.toString( "d.m. h:mm" );
238 iEngine->fetchMeetings( from, to, iWeeklyView->currentRoom() );
241 void WindowManager::changeModeOrdered( DeviceManager::OperationMode aMode )
243 QString message = tr( "You are about to change operation mode to %1." )
244 .arg( iEngine->deviceManager()->operationModeToString( aMode ) );
245 PasswordDialog *dlg = PasswordDialog::query( 0, iEngine->configuration()->adminPassword(), message );
246 qDebug() << "WindowManager::changeModeOrdered/tpassword: " << iEngine->configuration()->adminPassword();
247 //TODO make this modal!!!
248 connect( dlg, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ),
249 this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) );
252 void WindowManager::passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus )
254 switch ( aPasswordStatus )
256 case PasswordDialog::Correct :
258 iEngine->deviceManager()->changeMode( true );
261 case PasswordDialog::Incorrect :
263 error( tr( "Incorrect password." ) );
264 iEngine->deviceManager()->changeMode( false );
267 default : //case PasswordDialog::Canceled
269 iEngine->deviceManager()->changeMode( false );