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() ) );
88 connect( iSettingsView, SIGNAL( cancelClicked() ), this, SLOT( settingsCancelClicked() ) );
91 void UIManager::createRoomStatusIndicator()
93 iRoomStatusIndicator = new RoomStatusIndicatorWidget( iEngine->defaultRoom(), Room::FreeStatus, QTime::currentTime(), iEngine->iConfiguration->displaySettings()->dateFormat() );
96 void UIManager::createPasswordDialog()
98 iPasswordDialog = new PasswordDialog( iEngine->iConfiguration->adminPassword(), "", tr("Enter password") );
99 connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) );
102 void UIManager::createProgressBar()
104 iProgressBar = new ProgressBar( tr("CHANGE THIS"), true );
105 // Connect to UIManager
106 connect( iProgressBar, SIGNAL( cancel() ), this, SLOT( progressBarCancelled() ) );
108 connect( iProgressBar, SIGNAL( cancel() ), iEngine, SLOT( cancelFetchMeetingDetails() ) );
111 void UIManager::createMeetingInfoDialog()
113 iMeetingInfo = new MeetingInfoDialog();
116 void UIManager::connectDeviceManager( DeviceManager *aDeviceManager )
118 connect( aDeviceManager, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ),
119 this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) );
121 connect( aDeviceManager, SIGNAL( changingMode( const QString & ) ), this, SLOT( updateProgressBarText( const QString & ) ) );
122 connect( aDeviceManager, SIGNAL( changeModeFailed() ), this, SLOT( hideProgressBar() ) );
125 void UIManager::connectCommunicationManager( CommunicationManager *aCommunicationManager )
127 connect( aCommunicationManager, SIGNAL( meetingDetailsFetched( Meeting & ) ), this, SLOT( meetingDetailsFetched( Meeting & ) ) );
128 connect( aCommunicationManager, SIGNAL( meetingsFetched( const QList<Meeting *> & ) ), this, SLOT( meetingsFetched( const QList<Meeting *> & ) ) );
131 // ============================================
133 void UIManager::settingsViewRequest()
135 // Show the settings view and stop the idle timer
136 if ( iSettingsView != 0 )
138 iWindowManager->showView( static_cast<ViewBase *>( iSettingsView ) );
139 iEngine->stopIdleTimeCounter();
143 void UIManager::settingsOkClicked()
145 // Show the weekly view and restart the idle timer
146 if ( iWeeklyView != 0 )
148 iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
149 iEngine->startIdleTimeCounter();
153 void UIManager::meetingsFetched( const QList<Meeting*> &aMeetings )
155 qDebug() << "[UIManager::meetingsFetched] <Change the weekly views method to slot so we don't need this>";
156 if ( iWeeklyView != 0 )
158 iWeeklyView->refreshMeetings( aMeetings );
162 void UIManager::showMeetingProgressBar( Meeting *aMeeting )
164 if ( iProgressBar != 0 )
166 iProgressBar->update( tr( "Fetching meeting info..." ), tr( "Please wait" ) );
167 iProgressBar->toggleCancellable( true );
168 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
172 void UIManager::meetingDetailsFetched(Meeting &aDetailedMeeting)
174 qDebug() << "[UIManager::meetingDetailsFetched] <Invoked>";
175 if ( iMeetingInfo != 0 )
177 if ( iProgressBar != 0 && iProgressBar->isVisible() )
179 iProgressBar->close(); // Close it in case it's visible
181 MeetingInfoDialog *tmp = new MeetingInfoDialog( &aDetailedMeeting );
182 iWindowManager->showDialog( static_cast<QDialog *>( tmp ) );
183 // TODO : We should use the member variable and implement correctly the setMeeting() method !!!
184 // iMeetingInfo->setMeeting( &aDetailedMeeting );
185 // iWindowManager->showDialog( static_cast<QDialog *>( iMeetingInfo ) );
189 void UIManager::roomStatusIndicatorRequested()
191 if ( iRoomStatusIndicator != 0 )
193 iWindowManager->showView( static_cast<ViewBase *>( iRoomStatusIndicator ) );
194 iEngine->stopIdleTimeCounter();
198 void UIManager::previousViewRestored()
200 iEngine->startIdleTimeCounter();
203 void UIManager::progressBarCancelled()
205 if ( iProgressBar != 0 )
207 iProgressBar->close();
211 void UIManager::changeModeOrdered( DeviceManager::OperationMode aMode )
213 qDebug() << "[UIManager::changeModeOrdered] <Invoked>";
215 if ( iPasswordDialog != 0 )
217 QString text = tr( "You are about to change operation mode to %1." )
218 .arg( iEngine->iDevice->operationModeToString( aMode ) );
219 iPasswordDialog->update( text );
220 iWindowManager->showDialog( static_cast<QDialog *>( iPasswordDialog ) );
224 void UIManager::currentRoomChanged(Room *aRoom)
226 qDebug() << "[UIManager::currentRoomChanged] <Invoked>";
227 if ( iWeeklyView != 0 )
229 QDateTime from = QDateTime( iWeeklyView->beginnigOfShownWeek() );
230 QDateTime to = QDateTime( from.addDays( 8 ) );
231 iEngine->fetchMeetings( from, to, aRoom );
235 void UIManager::updateTime(QDateTime aDateTime)
237 if ( iWeeklyView != 0 )
239 iWeeklyView->setCurrentDateTime( aDateTime );
243 void UIManager::passwordEntered( PasswordDialog::PasswordStatus aStatus )
247 case PasswordDialog::Correct:
248 // Show the progress bar..
249 if ( iProgressBar != 0 )
251 iProgressBar->update( tr( "" ), tr( "Changing operation mode" ) );
252 iProgressBar->toggleCancellable( false );
253 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
255 // ... and initiate the mode changing
256 iEngine->changeDeviceMode();
258 case PasswordDialog::Incorrect:
259 iWindowManager->error( tr("Incorrect Password") );
261 case PasswordDialog::Canceled:
265 // Close the dialog after we have handled the status
266 if ( iPasswordDialog != 0 )
268 iPasswordDialog->close();
272 void UIManager::updateProgressBarText(const QString &aText)
274 if ( iProgressBar != 0 )
276 iProgressBar->update( aText );
280 void UIManager::hideProgressBar()
282 qDebug() << "[UIManager::hideProgressBar] <Invoked>";
283 if ( iProgressBar != 0 && iProgressBar->isVisible() )
285 iProgressBar->close();
289 void UIManager::settingsCancelClicked()
291 // Show the weekly view and restart the idle timer
292 if ( iWeeklyView != 0 )
294 iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
295 iEngine->startIdleTimeCounter();