7 #include "WindowManager.h"
9 #include "WeeklyViewWidget.h"
10 #include "SettingsView.h"
11 #include "RoomStatusIndicatorWidget.h"
12 #include "MeetingInfoDialog.h"
13 #include "ProgressBar.h"
14 #include "CommunicationManager.h"
15 #include "Configuration.h"
16 #include "DisplaySettings.h"
20 #define QT_DELETE(X) \
27 UIManager::UIManager( Engine *aEngine, WindowManager *aWindowManager ) :
29 iWindowManager( aWindowManager ),
32 iRoomStatusIndicator( 0 ),
37 if ( iEngine == 0 ) return;
38 if ( iWindowManager == 0 ) return;
42 createRoomStatusIndicator();
43 createPasswordDialog();
45 createMeetingInfoDialog();
48 UIManager::~UIManager()
53 QT_DELETE( iMeetingInfo );
54 QT_DELETE( iProgressBar );
55 QT_DELETE( iPasswordDialog );
56 QT_DELETE( iRoomStatusIndicator );
57 QT_DELETE( iSettingsView );
58 QT_DELETE( iWeeklyView );
61 void UIManager::showMainView()
63 iWindowManager->showView( iWeeklyView );
66 // ===============================================
67 // INITIALIZE THE UIMANAGER
68 void UIManager::createWeeklyView()
70 iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), iEngine->iConfiguration );
72 // Connect signals to UIManager
73 connect( iWeeklyView, SIGNAL( settingsButtonClicked() ), this, SLOT( settingsViewRequest() ) );
74 connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), this, SLOT( currentRoomChanged( Room * ) ) );
75 connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), this, SLOT( showMeetingProgressBar( Meeting * ) ) );
76 // Connect signals to engine
77 connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), iEngine, SLOT( fetchMeetingDetails( Meeting * ) ) );
78 connect( iWeeklyView, SIGNAL( shownWeekChanged( QDate ) ), iEngine, SLOT( shownWeekChanged( QDate ) ) );
79 connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), iEngine, SLOT( currentRoomChanged( Room * ) ) );
82 void UIManager::createSettingsView()
84 iSettingsView = new SettingsView;
87 connect( iSettingsView, SIGNAL( okClicked() ), this, SLOT( settingsOkClicked() ) );
90 void UIManager::createRoomStatusIndicator()
92 iRoomStatusIndicator = new RoomStatusIndicatorWidget( iEngine->defaultRoom(), Room::FreeStatus, QTime::currentTime().addSecs(100000000), iEngine->iConfiguration->displaySettings()->timeFormat() );
94 // Connect engine signals
95 connect( iEngine, SIGNAL( roomStatusChanged( Room::Status, QTime ) ), iRoomStatusIndicator, SLOT( statusChanged( Room::Status, QTime ) ) );
96 connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), iRoomStatusIndicator, SLOT( currentRoomChanged( Room * ) ) );
99 void UIManager::createPasswordDialog()
101 iPasswordDialog = new PasswordDialog( iEngine->iConfiguration->adminPassword(), "", tr("Enter password") );
102 connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) );
105 void UIManager::createProgressBar()
107 iProgressBar = new ProgressBar( tr("CHANGE THIS"), true );
109 // Connect to UIManager
110 connect( iProgressBar, SIGNAL( cancel() ), this, SLOT( progressBarCancelled() ) );
112 connect( iProgressBar, SIGNAL( cancel() ), iEngine, SLOT( cancelFetchMeetingDetails() ) );
115 void UIManager::createMeetingInfoDialog()
117 iMeetingInfo = new MeetingInfoDialog();
120 void UIManager::connectDeviceManager( DeviceManager *aDeviceManager )
122 connect( aDeviceManager, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ),
123 this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) );
125 connect( aDeviceManager, SIGNAL( changingMode( const QString & ) ), this, SLOT( updateProgressBarText( const QString & ) ) );
126 connect( aDeviceManager, SIGNAL( changeModeFailed() ), this, SLOT( hideProgressBar() ) );
129 void UIManager::connectCommunicationManager( CommunicationManager *aCommunicationManager )
131 connect( aCommunicationManager, SIGNAL( meetingDetailsFetched( Meeting & ) ), this, SLOT( meetingDetailsFetched( Meeting & ) ) );
132 connect( aCommunicationManager, SIGNAL( meetingsFetched( const QList<Meeting *> & ) ), this, SLOT( meetingsFetched( const QList<Meeting *> & ) ) );
135 // ============================================
137 void UIManager::settingsViewRequest()
139 // Show the settings view and stop the idle timer
140 if ( iSettingsView != 0 )
142 iWindowManager->showView( static_cast<ViewBase *>( iSettingsView ) );
143 iEngine->stopIdleTimeCounter();
147 void UIManager::settingsOkClicked()
149 // Show the weekly view and restart the idle timer
150 if ( iWeeklyView != 0 )
152 iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
153 iEngine->startIdleTimeCounter();
157 void UIManager::meetingsFetched( const QList<Meeting*> &aMeetings )
159 qDebug() << "[UIManager::meetingsFetched] <Change the weekly views method to slot so we don't need this>";
160 if ( iWeeklyView != 0 )
162 iWeeklyView->refreshMeetings( aMeetings );
166 void UIManager::showMeetingProgressBar( Meeting *aMeeting )
168 if ( iProgressBar != 0 )
170 iProgressBar->update( tr( "Fetching meeting info..." ), tr( "Please wait" ) );
171 iProgressBar->toggleCancellable( true );
172 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
173 iEngine->stopIdleTimeCounter();
177 void UIManager::meetingDetailsFetched(Meeting &aDetailedMeeting)
179 qDebug() << "[UIManager::meetingDetailsFetched] <Invoked>";
180 if ( iMeetingInfo != 0 )
182 if ( iProgressBar != 0 && iProgressBar->isVisible() )
184 iProgressBar->close(); // Close it in case it's visible
186 iEngine->stopIdleTimeCounter(); // Timer restarted when the dialog is dismissed.
187 MeetingInfoDialog *tmp = new MeetingInfoDialog( &aDetailedMeeting );
188 iWindowManager->showDialog( static_cast<QDialog *>( tmp ) );
190 // TODO : We should use the member variable and implement correctly the setMeeting() method !!!
191 // iMeetingInfo->setMeeting( &aDetailedMeeting );
192 // iWindowManager->showDialog( static_cast<QDialog *>( iMeetingInfo ) );
196 void UIManager::roomStatusIndicatorRequested()
198 if ( iRoomStatusIndicator != 0 )
200 iWindowManager->showView( static_cast<ViewBase *>( iRoomStatusIndicator ) );
201 iEngine->stopIdleTimeCounter();
205 void UIManager::previousViewRestored()
207 iEngine->startIdleTimeCounter();
210 void UIManager::progressBarCancelled()
212 if ( iProgressBar != 0 )
214 iProgressBar->close();
215 iEngine->startIdleTimeCounter();
219 void UIManager::changeModeOrdered( DeviceManager::OperationMode aMode )
221 qDebug() << "[UIManager::changeModeOrdered] <Invoked>";
223 if ( iPasswordDialog != 0 )
225 QString text = tr( "You are about to change operation mode to %1." )
226 .arg( iEngine->iDevice->operationModeToString( aMode ) );
227 iPasswordDialog->update( text );
228 iWindowManager->showDialog( static_cast<QDialog *>( iPasswordDialog ) );
232 void UIManager::currentRoomChanged(Room *aRoom)
234 qDebug() << "[UIManager::currentRoomChanged] <Invoked>";
235 if ( iWeeklyView != 0 )
237 QDateTime from = QDateTime( iWeeklyView->beginnigOfShownWeek() );
238 QDateTime to = QDateTime( from.addDays( 8 ) );
239 iEngine->fetchMeetings( from, to, aRoom );
243 void UIManager::updateTime(QDateTime aDateTime)
245 if ( iWeeklyView != 0 )
247 iWeeklyView->setCurrentDateTime( aDateTime );
249 if ( iRoomStatusIndicator != 0 )
251 iRoomStatusIndicator->setCurrentTime( aDateTime.time() );
255 void UIManager::passwordEntered( PasswordDialog::PasswordStatus aStatus )
259 case PasswordDialog::Correct:
260 // Show the progress bar..
261 if ( iProgressBar != 0 )
263 iProgressBar->update( tr( "" ), tr( "Changing operation mode" ) );
264 iProgressBar->toggleCancellable( false );
265 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false );
267 // ... and initiate the mode changing
268 iEngine->changeDeviceMode( true );
270 case PasswordDialog::Incorrect:
271 iWindowManager->error( tr("Incorrect Password") );
272 case PasswordDialog::Canceled:
273 iEngine->changeDeviceMode( false );
277 // Close the dialog after we have handled the status
278 if ( iPasswordDialog != 0 )
280 iPasswordDialog->close();
284 void UIManager::updateProgressBarText(const QString &aText)
286 if ( iProgressBar != 0 )
288 iProgressBar->update( aText );
292 void UIManager::hideProgressBar()
294 qDebug() << "[UIManager::hideProgressBar] <Invoked>";
295 if ( iProgressBar != 0 && iProgressBar->isVisible() )
297 iProgressBar->close();