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 void UIManager::showProgressBar( QString aText )
68 if ( iProgressBar != 0 )
70 iProgressBar->update( aText );
71 iWindowManager->showDialog( iProgressBar );
75 // ===============================================
76 // INITIALIZE THE UIMANAGER
77 void UIManager::createWeeklyView()
79 iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), iEngine->iConfiguration );
81 // Connect signals to UIManager
82 connect( iWeeklyView, SIGNAL( settingsButtonClicked() ), this, SLOT( settingsViewRequest() ) );
83 connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), this, SLOT( currentRoomChanged( Room * ) ) );
84 connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), this, SLOT( showMeetingProgressBar( Meeting * ) ) );
85 // Connect signals to engine
86 connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), iEngine, SLOT( fetchMeetingDetails( Meeting * ) ) );
87 connect( iWeeklyView, SIGNAL( shownWeekChanged( QDate ) ), iEngine, SLOT( shownWeekChanged( QDate ) ) );
88 connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), iEngine, SLOT( currentRoomChanged( Room * ) ) );
91 void UIManager::createSettingsView()
93 iSettingsView = new SettingsView;
96 connect( iSettingsView, SIGNAL( okClicked() ), this, SLOT( settingsOkClicked() ) );
99 void UIManager::createRoomStatusIndicator()
101 iRoomStatusIndicator = new RoomStatusIndicatorWidget( iEngine->defaultRoom(), Room::FreeStatus, QTime::currentTime().addSecs(100000000), iEngine->iConfiguration->displaySettings()->timeFormat() );
103 // Connect engine signals
104 connect( iEngine, SIGNAL( roomStatusChanged( Room::Status, QTime ) ), iRoomStatusIndicator, SLOT( statusChanged( Room::Status, QTime ) ) );
105 connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), iRoomStatusIndicator, SLOT( currentRoomChanged( Room * ) ) );
108 void UIManager::createPasswordDialog()
110 iPasswordDialog = new PasswordDialog( iEngine->iConfiguration->adminPassword(), tr("UIManager::createPasswordDialog"), tr("UIManager::createPasswordDialog") );
112 connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) );
115 void UIManager::createProgressBar()
117 iProgressBar = new ProgressBar( tr("CHANGE THIS"), true );
119 // Connect to UIManager
120 connect( iProgressBar, SIGNAL( cancel() ), this, SLOT( progressBarCancelled() ) );
122 connect( iProgressBar, SIGNAL( cancel() ), iEngine, SLOT( cancelFetchMeetingDetails() ) );
125 void UIManager::createMeetingInfoDialog()
127 iMeetingInfo = new MeetingInfoDialog();
130 void UIManager::connectDeviceManager( DeviceManager *aDeviceManager )
132 connect( aDeviceManager, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ),
133 this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) );
135 connect( aDeviceManager, SIGNAL( changingMode( const QString & ) ), this, SLOT( updateProgressBarText( const QString & ) ) );
136 connect( aDeviceManager, SIGNAL( changeModeFailed() ), this, SLOT( hideProgressBar() ) );
139 void UIManager::connectCommunicationManager( CommunicationManager *aCommunicationManager )
141 connect( aCommunicationManager, SIGNAL( meetingDetailsFetched( Meeting & ) ), this, SLOT( meetingDetailsFetched( Meeting & ) ) );
142 connect( aCommunicationManager, SIGNAL( meetingsFetched( const QList<Meeting *> & ) ), this, SLOT( meetingsFetched( const QList<Meeting *> & ) ) );
145 // ============================================
147 void UIManager::settingsViewRequest()
149 // Show the settings view and stop the idle timer
150 if ( iSettingsView != 0 )
152 iWindowManager->showView( static_cast<ViewBase *>( iSettingsView ) );
153 iEngine->stopIdleTimeCounter();
157 void UIManager::settingsOkClicked()
159 // Show the weekly view and restart the idle timer
160 if ( iWeeklyView != 0 )
162 iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
163 iEngine->startIdleTimeCounter();
167 void UIManager::meetingsFetched( const QList<Meeting*> &aMeetings )
169 qDebug() << "[UIManager::meetingsFetched] <Change the weekly views method to slot so we don't need this>";
170 if ( iWeeklyView != 0 )
172 iWeeklyView->refreshMeetings( aMeetings );
176 void UIManager::showMeetingProgressBar( Meeting *aMeeting )
178 if ( iProgressBar != 0 )
180 iProgressBar->update( tr("Fetching meeting info...") );
181 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
182 iEngine->stopIdleTimeCounter();
186 void UIManager::meetingDetailsFetched(Meeting &aDetailedMeeting)
188 qDebug() << "[UIManager::meetingDetailsFetched] <Invoked>";
189 if ( iMeetingInfo != 0 )
191 if ( iProgressBar != 0 && iProgressBar->isVisible() )
193 iProgressBar->close(); // Close it in case it's visible
195 iEngine->stopIdleTimeCounter(); // Timer restarted when the dialog is dismissed.
196 MeetingInfoDialog *tmp = new MeetingInfoDialog( &aDetailedMeeting );
197 iWindowManager->showDialog( static_cast<QDialog *>( tmp ) );
199 // TODO : We should use the member variable and implement correctly the setMeeting() method !!!
200 // iMeetingInfo->setMeeting( &aDetailedMeeting );
201 // iWindowManager->showDialog( static_cast<QDialog *>( iMeetingInfo ) );
205 void UIManager::roomStatusIndicatorRequested()
207 if ( iRoomStatusIndicator != 0 )
209 iWindowManager->showView( static_cast<ViewBase *>( iRoomStatusIndicator ) );
210 iEngine->stopIdleTimeCounter();
214 void UIManager::previousViewRestored()
216 iEngine->startIdleTimeCounter();
219 void UIManager::progressBarCancelled()
221 if ( iProgressBar != 0 )
223 iProgressBar->close();
224 iEngine->startIdleTimeCounter();
228 void UIManager::changeModeOrdered( DeviceManager::OperationMode aMode )
230 qDebug() << "[UIManager::changeModeOrdered] <Invoked>";
232 QString message = tr( "You are about to change operation mode to %1." )
233 .arg( iEngine->iDevice->operationModeToString( aMode ) );
235 if ( iPasswordDialog != 0 )
237 // TODO : Set the new text for password dialog
238 iWindowManager->showDialog( static_cast<QDialog *>( iPasswordDialog ) );
242 void UIManager::currentRoomChanged(Room *aRoom)
244 qDebug() << "[UIManager::currentRoomChanged] <Invoked>";
245 if ( iWeeklyView != 0 )
247 QDateTime from = QDateTime( iWeeklyView->beginnigOfShownWeek() );
248 QDateTime to = QDateTime( from.addDays( 8 ) );
249 iEngine->fetchMeetings( from, to, aRoom );
253 void UIManager::updateTime(QDateTime aDateTime)
255 if ( iWeeklyView != 0 )
257 iWeeklyView->setCurrentDateTime( aDateTime );
259 if ( iRoomStatusIndicator != 0 )
261 iRoomStatusIndicator->setCurrentTime( aDateTime.time() );
265 void UIManager::passwordEntered( PasswordDialog::PasswordStatus aStatus )
269 case PasswordDialog::Correct:
270 // Show the progress bar..
271 if ( iProgressBar != 0 )
273 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false );
275 // ... and initiate the mode changing
276 iEngine->changeDeviceMode( true );
278 case PasswordDialog::Incorrect:
279 iWindowManager->error( tr("Incorrect Password") );
280 case PasswordDialog::Canceled:
281 iEngine->changeDeviceMode( false );
285 // Close the dialog after we have handled the status
286 if ( iPasswordDialog != 0 )
288 iPasswordDialog->close();
292 void UIManager::updateProgressBarText(const QString &aText)
294 if ( iProgressBar != 0 )
296 iProgressBar->update( aText );
300 void UIManager::hideProgressBar()
302 qDebug() << "[UIManager::hideProgressBar] <Invoked>";
303 if ( iProgressBar != 0 && iProgressBar->isVisible() )
305 iProgressBar->close();