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(), iEngine->iConfiguration->displaySettings()->dateFormat() );
104 void UIManager::createPasswordDialog()
106 iPasswordDialog = new PasswordDialog( iEngine->iConfiguration->adminPassword(), tr("UIManager::createPasswordDialog"), tr("UIManager::createPasswordDialog") );
108 connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) );
111 void UIManager::createProgressBar()
113 iProgressBar = new ProgressBar( tr("CHANGE THIS"), true );
115 // Connect to UIManager
116 connect( iProgressBar, SIGNAL( cancel() ), this, SLOT( progressBarCancelled() ) );
118 connect( iProgressBar, SIGNAL( cancel() ), iEngine, SLOT( cancelFetchMeetingDetails() ) );
121 void UIManager::createMeetingInfoDialog()
123 iMeetingInfo = new MeetingInfoDialog();
126 void UIManager::connectDeviceManager( DeviceManager *aDeviceManager )
128 connect( aDeviceManager, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ),
129 this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) );
131 connect( aDeviceManager, SIGNAL( changingMode( const QString & ) ), this, SLOT( updateProgressBarText( const QString & ) ) );
132 connect( aDeviceManager, SIGNAL( changeModeFailed() ), this, SLOT( hideProgressBar() ) );
135 void UIManager::connectCommunicationManager( CommunicationManager *aCommunicationManager )
137 connect( aCommunicationManager, SIGNAL( meetingDetailsFetched( Meeting & ) ), this, SLOT( meetingDetailsFetched( Meeting & ) ) );
138 connect( aCommunicationManager, SIGNAL( meetingsFetched( const QList<Meeting *> & ) ), this, SLOT( meetingsFetched( const QList<Meeting *> & ) ) );
141 // ============================================
143 void UIManager::settingsViewRequest()
145 // Show the settings view and stop the idle timer
146 if ( iSettingsView != 0 )
148 iWindowManager->showView( static_cast<ViewBase *>( iSettingsView ) );
149 iEngine->stopIdleTimeCounter();
153 void UIManager::settingsOkClicked()
155 // Show the weekly view and restart the idle timer
156 if ( iWeeklyView != 0 )
158 iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
159 iEngine->startIdleTimeCounter();
163 void UIManager::meetingsFetched( const QList<Meeting*> &aMeetings )
165 qDebug() << "[UIManager::meetingsFetched] <Change the weekly views method to slot so we don't need this>";
166 if ( iWeeklyView != 0 )
168 iWeeklyView->refreshMeetings( aMeetings );
172 void UIManager::showMeetingProgressBar( Meeting *aMeeting )
174 if ( iProgressBar != 0 )
176 iProgressBar->update( tr("Fetching meeting info...") );
177 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
178 iEngine->stopIdleTimeCounter();
182 void UIManager::meetingDetailsFetched(Meeting &aDetailedMeeting)
184 qDebug() << "[UIManager::meetingDetailsFetched] <Invoked>";
185 if ( iMeetingInfo != 0 )
187 if ( iProgressBar != 0 && iProgressBar->isVisible() )
189 iProgressBar->close(); // Close it in case it's visible
191 MeetingInfoDialog *tmp = new MeetingInfoDialog( &aDetailedMeeting );
192 iWindowManager->showDialog( static_cast<QDialog *>( tmp ) );
193 // TODO : We should use the member variable and implement correctly the setMeeting() method !!!
194 // iMeetingInfo->setMeeting( &aDetailedMeeting );
195 // iWindowManager->showDialog( static_cast<QDialog *>( iMeetingInfo ) );
199 void UIManager::roomStatusIndicatorRequested()
201 if ( iRoomStatusIndicator != 0 )
203 iWindowManager->showView( static_cast<ViewBase *>( iRoomStatusIndicator ) );
204 iEngine->stopIdleTimeCounter();
208 void UIManager::previousViewRestored()
210 iEngine->startIdleTimeCounter();
213 void UIManager::progressBarCancelled()
215 if ( iProgressBar != 0 )
217 iProgressBar->close();
218 iEngine->startIdleTimeCounter();
222 void UIManager::changeModeOrdered( DeviceManager::OperationMode aMode )
224 qDebug() << "[UIManager::changeModeOrdered] <Invoked>";
226 QString message = tr( "You are about to change operation mode to %1." )
227 .arg( iEngine->iDevice->operationModeToString( aMode ) );
229 if ( iPasswordDialog != 0 )
231 // TODO : Set the new text for password dialog
232 iWindowManager->showDialog( static_cast<QDialog *>( iPasswordDialog ) );
236 void UIManager::currentRoomChanged(Room *aRoom)
238 qDebug() << "[UIManager::currentRoomChanged] <Invoked>";
239 if ( iWeeklyView != 0 )
241 QDateTime from = QDateTime( iWeeklyView->beginnigOfShownWeek() );
242 QDateTime to = QDateTime( from.addDays( 8 ) );
243 iEngine->fetchMeetings( from, to, aRoom );
247 void UIManager::updateTime(QDateTime aDateTime)
249 if ( iWeeklyView != 0 )
251 iWeeklyView->setCurrentDateTime( aDateTime );
255 void UIManager::passwordEntered( PasswordDialog::PasswordStatus aStatus )
259 case PasswordDialog::Correct:
260 // Show the progress bar..
261 if ( iProgressBar != 0 )
263 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false );
265 // ... and initiate the mode changing
266 iEngine->changeDeviceMode( true );
268 case PasswordDialog::Incorrect:
269 iWindowManager->error( tr("Incorrect Password") );
270 case PasswordDialog::Canceled:
271 iEngine->changeDeviceMode( false );
275 // Close the dialog after we have handled the status
276 if ( iPasswordDialog != 0 )
278 iPasswordDialog->close();
282 void UIManager::updateProgressBarText(const QString &aText)
284 if ( iProgressBar != 0 )
286 iProgressBar->update( aText );
290 void UIManager::hideProgressBar()
292 qDebug() << "[UIManager::hideProgressBar] <Invoked>";
293 if ( iProgressBar != 0 && iProgressBar->isVisible() )
295 iProgressBar->close();