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;
40 qDebug() << "[UIManager::ctor] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
44 createRoomStatusIndicator();
45 createPasswordDialog();
47 createMeetingInfoDialog();
49 qDebug() << "[UIManager::ctor] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
52 UIManager::~UIManager()
57 QT_DELETE( iMeetingInfo );
58 QT_DELETE( iProgressBar );
59 QT_DELETE( iPasswordDialog );
60 QT_DELETE( iRoomStatusIndicator );
61 QT_DELETE( iSettingsView );
62 QT_DELETE( iWeeklyView );
65 void UIManager::showMainView()
67 iWindowManager->showView( iWeeklyView );
70 void UIManager::showProgressBar( QString aText )
72 if ( iProgressBar != 0 )
74 iProgressBar->update( tr("Changing current operation mode.") );
75 iWindowManager->showDialog( iProgressBar );
79 // ===============================================
80 // INITIALIZE THE UIMANAGER
81 void UIManager::createWeeklyView()
83 iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), iEngine->iConfiguration );
85 // Connect signals to UIManager
86 connect( iWeeklyView, SIGNAL( settingsButtonClicked() ), this, SLOT( settingsViewRequest() ) );
87 connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), this, SLOT( currentRoomChanged( Room * ) ) );
88 connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), this, SLOT( showMeetingProgressBar( Meeting * ) ) );
89 // Connect signals to engine
90 connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), iEngine, SLOT( fetchMeetingDetails( Meeting * ) ) );
91 connect( iWeeklyView, SIGNAL( shownWeekChanged( QDate ) ), iEngine, SLOT( shownWeekChanged( QDate ) ) );
94 void UIManager::createSettingsView()
96 iSettingsView = new SettingsView;
99 connect( iSettingsView, SIGNAL( okClicked() ), this, SLOT( settingsOkClicked() ) );
102 void UIManager::createRoomStatusIndicator()
104 iRoomStatusIndicator = new RoomStatusIndicatorWidget( iEngine->defaultRoom(), Room::FreeStatus, QTime::currentTime(), iEngine->iConfiguration->displaySettings()->dateFormat() );
107 void UIManager::createPasswordDialog()
109 iPasswordDialog = new PasswordDialog( iEngine->iConfiguration->adminPassword(), tr("UIManager::createPasswordDialog"), tr("UIManager::createPasswordDialog") );
111 connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) );
114 void UIManager::createProgressBar()
116 iProgressBar = new ProgressBar( tr("CHANGE THIS") );
118 // Connect to UIManager
119 connect( iProgressBar, SIGNAL( cancel() ), this, SLOT( progressBarCancelled() ) );
121 connect( iProgressBar, SIGNAL( cancel() ), iEngine, SLOT( cancelFetchMeetingDetails() ) );
124 void UIManager::createMeetingInfoDialog()
126 iMeetingInfo = new MeetingInfoDialog();
129 void UIManager::connectDeviceManager( DeviceManager *aDeviceManager )
131 connect( aDeviceManager, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ),
132 this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) );
134 connect( aDeviceManager, SIGNAL( changingMode( const QString & ) ), this, SLOT( updateProgressBarText( const QString & ) ) );
137 void UIManager::connectCommunicationManager( CommunicationManager *aCommunicationManager )
139 connect( aCommunicationManager, SIGNAL( meetingDetailsFetched( Meeting & ) ), this, SLOT( meetingDetailsFetched( Meeting & ) ) );
142 // ============================================
144 void UIManager::settingsViewRequest()
146 // Show the settings view and stop the idle timer
147 if ( iSettingsView != 0 )
149 iWindowManager->showView( static_cast<ViewBase *>( iSettingsView ) );
150 iEngine->stopIdleTimeCounter();
154 void UIManager::settingsOkClicked()
156 // Show the weekly view and restart the idle timer
157 if ( iWeeklyView != 0 )
159 iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
160 iEngine->startIdleTimeCounter();
164 void UIManager::meetingsFetched( const QList<Meeting*> &aMeetings )
169 void UIManager::showMeetingProgressBar( Meeting *aMeeting )
171 if ( iProgressBar != 0 )
173 iProgressBar->update( tr("Fetching meeting info...") );
174 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ) );
178 void UIManager::meetingDetailsFetched(Meeting &aDetailedMeeting)
180 if ( iMeetingInfo != 0 )
182 if ( iProgressBar != 0 )
184 iProgressBar->close(); // Close it in case it's visible
186 iMeetingInfo->setMeeting( &aDetailedMeeting );
187 iWindowManager->showDialog( static_cast<QDialog *>( iMeetingInfo ) );
191 void UIManager::roomStatusIndicatorRequested()
193 if ( iRoomStatusIndicator != 0 )
195 iWindowManager->showView( static_cast<ViewBase *>( iRoomStatusIndicator ) );
196 iEngine->stopIdleTimeCounter();
200 void UIManager::previousViewRestored()
202 iEngine->startIdleTimeCounter();
205 void UIManager::progressBarCancelled()
207 if ( iProgressBar != 0 )
209 iProgressBar->close();
213 void UIManager::changeModeOrdered( DeviceManager::OperationMode aMode )
215 qDebug() << "[UIManager::changeModeOrdered] <Invoked>";
217 QString message = tr( "You are about to change operation mode to %1." )
218 .arg( iEngine->iDevice->operationModeToString( aMode ) );
220 if ( iPasswordDialog != 0 )
222 // TODO : Set the new text for password dialog
223 iWindowManager->showDialog( static_cast<QDialog *>( iPasswordDialog ) );
227 void UIManager::currentRoomChanged(Room *aRoom)
229 if ( iWeeklyView != 0 )
231 QDateTime from = QDateTime( iWeeklyView->beginnigOfShownWeek() );
232 QDateTime to = QDateTime( from.addDays( 8 ) );
233 iEngine->fetchMeetings( from, to, aRoom );
237 void UIManager::updateTime(QDateTime aDateTime)
239 if ( iWeeklyView != 0 )
241 iWeeklyView->setCurrentDateTime( aDateTime );
245 void UIManager::passwordEntered( PasswordDialog::PasswordStatus aStatus )
249 case PasswordDialog::Correct:
250 // Show the progress bar..
251 if ( iProgressBar != 0 )
253 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ) );
255 // ... and initiate the mode changing
256 iEngine->changeDeviceMode( true );
258 case PasswordDialog::Incorrect:
259 iWindowManager->error( tr("Incorrect Password") );
260 case PasswordDialog::Canceled:
261 iEngine->changeDeviceMode( false );
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 );