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( aText );
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"), true );
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 & ) ) );
135 connect( aDeviceManager, SIGNAL( changeModeFailed() ), this, SLOT( hideProgressBar() ) );
138 void UIManager::connectCommunicationManager( CommunicationManager *aCommunicationManager )
140 connect( aCommunicationManager, SIGNAL( meetingDetailsFetched( Meeting & ) ), this, SLOT( meetingDetailsFetched( Meeting & ) ) );
141 connect( aCommunicationManager, SIGNAL( meetingsFetched( const QList<Meeting *> & ) ), this, SLOT( meetingsFetched( const QList<Meeting *> & ) ) );
144 // ============================================
146 void UIManager::settingsViewRequest()
148 // Show the settings view and stop the idle timer
149 if ( iSettingsView != 0 )
151 iWindowManager->showView( static_cast<ViewBase *>( iSettingsView ) );
152 iEngine->stopIdleTimeCounter();
156 void UIManager::settingsOkClicked()
158 // Show the weekly view and restart the idle timer
159 if ( iWeeklyView != 0 )
161 iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
162 iEngine->startIdleTimeCounter();
166 void UIManager::meetingsFetched( const QList<Meeting*> &aMeetings )
168 qDebug() << "[UIManager::meetingsFetched] <SHOULD NOT SIMPLY INSERT MEETINGS TO WEEKLYVIEW !!!>";
169 for ( int i = 0; i < aMeetings.count(); i++ )
171 Meeting *m = new Meeting( *( aMeetings.at(i) ) );
172 iWeeklyView->insertMeeting( m );
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 );
185 void UIManager::meetingDetailsFetched(Meeting &aDetailedMeeting)
187 qDebug() << "[UIManager::meetingDetailsFetched] <Invoked>";
188 if ( iMeetingInfo != 0 )
190 if ( iProgressBar != 0 && iProgressBar->isVisible() )
192 iProgressBar->close(); // Close it in case it's visible
194 // iMeetingInfo->setMeeting( &aDetailedMeeting );
195 MeetingInfoDialog *tmp = new MeetingInfoDialog( &aDetailedMeeting );
196 iWindowManager->showDialog( static_cast<QDialog *>( tmp/*iMeetingInfo*/ ) );
200 void UIManager::roomStatusIndicatorRequested()
202 if ( iRoomStatusIndicator != 0 )
204 iWindowManager->showView( static_cast<ViewBase *>( iRoomStatusIndicator ) );
205 iEngine->stopIdleTimeCounter();
209 void UIManager::previousViewRestored()
211 iEngine->startIdleTimeCounter();
214 void UIManager::progressBarCancelled()
216 if ( iProgressBar != 0 )
218 iProgressBar->close();
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 if ( iWeeklyView != 0 )
240 QDateTime from = QDateTime( iWeeklyView->beginnigOfShownWeek() );
241 QDateTime to = QDateTime( from.addDays( 8 ) );
242 iEngine->fetchMeetings( from, to, aRoom );
246 void UIManager::updateTime(QDateTime aDateTime)
248 if ( iWeeklyView != 0 )
250 iWeeklyView->setCurrentDateTime( aDateTime );
254 void UIManager::passwordEntered( PasswordDialog::PasswordStatus aStatus )
258 case PasswordDialog::Correct:
259 // Show the progress bar..
260 if ( iProgressBar != 0 )
262 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false );
264 // ... and initiate the mode changing
265 iEngine->changeDeviceMode( true );
267 case PasswordDialog::Incorrect:
268 iWindowManager->error( tr("Incorrect Password") );
269 case PasswordDialog::Canceled:
270 iEngine->changeDeviceMode( false );
274 // Close the dialog after we have handled the status
275 if ( iPasswordDialog != 0 )
277 iPasswordDialog->close();
281 void UIManager::updateProgressBarText(const QString &aText)
283 if ( iProgressBar != 0 )
285 iProgressBar->update( aText );
289 void UIManager::hideProgressBar()
291 qDebug() << "[UIManager::hideProgressBar] <Invoked>";
292 if ( iProgressBar != 0 && iProgressBar->isVisible() )
294 iProgressBar->close();