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(), iEngine->iConfiguration->displaySettings()->timeFormat() );
93 connect( iEngine, SIGNAL( roomStatusChanged( Room::Status, QTime ) ), iRoomStatusIndicator, SLOT( statusChanged( Room::Status, QTime ) ) );
94 connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), iRoomStatusIndicator, SLOT( currentRoomChanged( Room * ) ) );
97 void UIManager::createPasswordDialog()
99 iPasswordDialog = new PasswordDialog( iEngine->iConfiguration->adminPassword(), "", tr("Enter password") );
100 connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) );
103 void UIManager::createProgressBar()
105 iProgressBar = new ProgressBar( tr("CHANGE THIS"), true );
106 // Connect to UIManager
107 connect( iProgressBar, SIGNAL( cancel() ), this, SLOT( progressBarCancelled() ) );
109 connect( iProgressBar, SIGNAL( cancel() ), iEngine, SLOT( cancelFetchMeetingDetails() ) );
112 void UIManager::createMeetingInfoDialog()
114 iMeetingInfo = new MeetingInfoDialog();
117 void UIManager::connectDeviceManager( DeviceManager *aDeviceManager )
119 connect( aDeviceManager, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ),
120 this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) );
122 connect( aDeviceManager, SIGNAL( changingMode( const QString & ) ), this, SLOT( updateProgressBarText( const QString & ) ) );
123 connect( aDeviceManager, SIGNAL( changeModeFailed() ), this, SLOT( hideProgressBar() ) );
126 void UIManager::connectCommunicationManager( CommunicationManager *aCommunicationManager )
128 connect( aCommunicationManager, SIGNAL( meetingDetailsFetched( Meeting & ) ), this, SLOT( meetingDetailsFetched( Meeting & ) ) );
129 connect( aCommunicationManager, SIGNAL( meetingsFetched( const QList<Meeting *> & ) ), this, SLOT( meetingsFetched( const QList<Meeting *> & ) ) );
132 // ============================================
134 void UIManager::settingsViewRequest()
136 // Show the settings view and stop the idle timer
137 if ( iSettingsView != 0 )
139 iWindowManager->showView( static_cast<ViewBase *>( iSettingsView ) );
140 iEngine->stopIdleTimeCounter();
144 void UIManager::settingsOkClicked()
146 // Show the weekly view and restart the idle timer
147 if ( iWeeklyView != 0 )
149 iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
150 iEngine->startIdleTimeCounter();
154 void UIManager::meetingsFetched( const QList<Meeting*> &aMeetings )
156 qDebug() << "[UIManager::meetingsFetched] <Change the weekly views method to slot so we don't need this>";
157 if ( iWeeklyView != 0 )
159 iWeeklyView->refreshMeetings( aMeetings );
163 void UIManager::showMeetingProgressBar( Meeting *aMeeting )
165 if ( iProgressBar != 0 )
167 iProgressBar->update( tr( "Fetching meeting info..." ), tr( "Please wait" ) );
168 iProgressBar->toggleCancellable( true );
169 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
173 void UIManager::meetingDetailsFetched(Meeting &aDetailedMeeting)
175 qDebug() << "[UIManager::meetingDetailsFetched] <Invoked>";
176 if ( iMeetingInfo != 0 )
178 if ( iProgressBar != 0 && iProgressBar->isVisible() )
180 iProgressBar->close(); // Close it in case it's visible
182 MeetingInfoDialog *tmp = new MeetingInfoDialog( &aDetailedMeeting );
183 iWindowManager->showDialog( static_cast<QDialog *>( tmp ) );
184 // TODO : We should use the member variable and implement correctly the setMeeting() method !!!
185 // iMeetingInfo->setMeeting( &aDetailedMeeting );
186 // iWindowManager->showDialog( static_cast<QDialog *>( iMeetingInfo ) );
190 void UIManager::roomStatusIndicatorRequested()
192 if ( iRoomStatusIndicator != 0 )
194 iWindowManager->showView( static_cast<ViewBase *>( iRoomStatusIndicator ) );
195 iEngine->stopIdleTimeCounter();
199 void UIManager::previousViewRestored()
201 iEngine->startIdleTimeCounter();
204 void UIManager::progressBarCancelled()
206 if ( iProgressBar != 0 )
208 iProgressBar->close();
212 void UIManager::changeModeOrdered( DeviceManager::OperationMode aMode )
214 qDebug() << "[UIManager::changeModeOrdered] <Invoked>";
216 if ( iPasswordDialog != 0 )
218 QString text = tr( "You are about to change operation mode to %1." )
219 .arg( iEngine->iDevice->operationModeToString( aMode ) );
220 iPasswordDialog->update( text );
221 iWindowManager->showDialog( static_cast<QDialog *>( iPasswordDialog ) );
225 void UIManager::connectionLost()
227 qDebug() << "UIManager::connectionLost()";
228 iWeeklyView->connectionLost();
229 iSettingsView->connectionLost();
230 iRoomStatusIndicator->connectionLost();
233 void UIManager::connectionEstablished()
235 qDebug() << "UIManager::connectionEstablished()";
236 iWeeklyView->connectionEstablished();
237 iSettingsView->connectionEstablished();
238 iRoomStatusIndicator->connectionEstablished();
241 void UIManager::currentRoomChanged(Room *aRoom)
243 qDebug() << "[UIManager::currentRoomChanged] <Invoked>";
244 if ( iWeeklyView != 0 )
246 QDateTime from = QDateTime( iWeeklyView->beginnigOfShownWeek() );
247 QDateTime to = QDateTime( from.addDays( 8 ) );
248 iEngine->fetchMeetings( from, to, aRoom );
252 void UIManager::updateTime(QDateTime aDateTime)
254 if ( iWeeklyView != 0 )
256 iWeeklyView->setCurrentDateTime( aDateTime );
258 if ( iRoomStatusIndicator != 0 )
260 iRoomStatusIndicator->setCurrentTime( aDateTime.time() );
264 void UIManager::passwordEntered( PasswordDialog::PasswordStatus aStatus )
268 case PasswordDialog::Correct:
269 // Show the progress bar..
270 if ( iProgressBar != 0 )
272 iProgressBar->update( tr( "" ), tr( "Changing operation mode" ) );
273 iProgressBar->toggleCancellable( false );
274 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
276 // ... and initiate the mode changing
277 iEngine->changeDeviceMode();
279 case PasswordDialog::Incorrect:
280 iWindowManager->error( tr("Incorrect Password") );
282 case PasswordDialog::Canceled:
286 // Close the dialog after we have handled the status
287 if ( iPasswordDialog != 0 )
289 iPasswordDialog->close();
293 void UIManager::updateProgressBarText(const QString &aText)
295 if ( iProgressBar != 0 )
297 iProgressBar->update( aText );
301 void UIManager::hideProgressBar()
303 qDebug() << "[UIManager::hideProgressBar] <Invoked>";
304 if ( iProgressBar != 0 && iProgressBar->isVisible() )
306 iProgressBar->close();