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 connect(iWindowManager, SIGNAL(showSettingsClicked()), this, SLOT(settingsViewRequest()));
43 createRoomStatusIndicator();
44 createPasswordDialog();
46 createMeetingInfoDialog();
49 UIManager::~UIManager()
54 QT_DELETE( iMeetingInfo );
55 QT_DELETE( iProgressBar );
56 QT_DELETE( iPasswordDialog );
57 QT_DELETE( iRoomStatusIndicator );
58 QT_DELETE( iSettingsView );
59 QT_DELETE( iWeeklyView );
62 void UIManager::showMainView()
64 iWindowManager->showView( iWeeklyView );
67 // ===============================================
68 // INITIALIZE THE UIMANAGER
69 void UIManager::createWeeklyView()
71 iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), iEngine->iConfiguration );
73 // Connect signals to UIManager
74 connect( iWeeklyView, SIGNAL( settingsButtonClicked() ), this, SLOT( settingsViewRequest() ) );
75 connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), this, SLOT( currentRoomChanged( Room * ) ) );
76 connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), this, SLOT( showMeetingProgressBar( Meeting * ) ) );
77 // Connect signals to engine
78 connect( iWeeklyView, SIGNAL( refreshButtonClicked() ), iEngine, SLOT( updateRoomInfo() ) );
79 connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), iEngine, SLOT( fetchMeetingDetails( Meeting * ) ) );
80 connect( iWeeklyView, SIGNAL( shownWeekChanged( QDate ) ), iEngine, SLOT( shownWeekChanged( QDate ) ) );
81 connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), iEngine, SLOT( currentRoomChanged( Room * ) ) );
84 void UIManager::createSettingsView()
86 iSettingsView = new SettingsView;
89 connect( iSettingsView, SIGNAL( okClicked() ), this, SLOT( settingsOkClicked() ) );
90 connect( iSettingsView, SIGNAL( cancelClicked() ), this, SLOT( settingsCancelClicked() ) );
93 void UIManager::createRoomStatusIndicator()
95 iRoomStatusIndicator = new RoomStatusIndicatorWidget( iEngine->defaultRoom(), Room::FreeStatus, QTime::currentTime(), iEngine->iConfiguration->displaySettings()->timeFormat() );
96 connect( iEngine, SIGNAL( roomStatusChanged( Room::Status, QTime ) ), iRoomStatusIndicator, SLOT( statusChanged( Room::Status, QTime ) ) );
97 connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), iRoomStatusIndicator, SLOT( currentRoomChanged( Room * ) ) );
100 void UIManager::createPasswordDialog()
102 iPasswordDialog = new PasswordDialog( iEngine->iConfiguration->adminPassword(), "", tr("Enter password") );
103 connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) );
106 void UIManager::createProgressBar()
108 iProgressBar = new ProgressBar( tr("CHANGE THIS"), true );
109 // Connect to UIManager
110 connect( iProgressBar, SIGNAL( cancel() ), this, SLOT( progressBarCancelled() ) );
112 connect( iProgressBar, SIGNAL( cancel() ), iEngine, SLOT( cancelFetchMeetingDetails() ) );
115 void UIManager::createMeetingInfoDialog()
117 iMeetingInfo = new MeetingInfoDialog();
120 void UIManager::connectDeviceManager( DeviceManager *aDeviceManager )
122 connect( aDeviceManager, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ),
123 this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) );
125 connect( aDeviceManager, SIGNAL( changingMode( const QString & ) ), this, SLOT( updateProgressBarText( const QString & ) ) );
126 connect( aDeviceManager, SIGNAL( changeModeFailed() ), this, SLOT( hideProgressBar() ) );
129 void UIManager::connectCommunicationManager( CommunicationManager *aCommunicationManager )
131 connect( aCommunicationManager, SIGNAL( meetingDetailsFetched( Meeting & ) ), this, SLOT( meetingDetailsFetched( Meeting & ) ) );
132 connect( aCommunicationManager, SIGNAL( meetingsFetched( const QList<Meeting *> & ) ), this, SLOT( meetingsFetched( const QList<Meeting *> & ) ) );
135 // ============================================
137 void UIManager::settingsViewRequest()
139 createSettingsView();
141 // Show the settings view and stop the idle timer
142 iWindowManager->showView( static_cast<ViewBase *>( iSettingsView ) );
143 iEngine->stopIdleTimeCounter();
146 void UIManager::settingsOkClicked()
148 // Show the weekly view and restart the idle timer
149 if ( iWeeklyView != 0 )
151 iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
152 QT_DELETE(iSettingsView);
153 iEngine->startIdleTimeCounter();
154 currentRoomChanged(iWeeklyView->currentRoom());
158 void UIManager::meetingsFetched( const QList<Meeting*> &aMeetings )
160 qDebug() << "[UIManager::meetingsFetched] <Change the weekly views method to slot so we don't need this>";
161 if ( iWeeklyView != 0 )
163 iWeeklyView->refreshMeetings( aMeetings );
167 void UIManager::showMeetingProgressBar( Meeting */*aMeeting*/ )
169 if ( iProgressBar != 0 )
171 iProgressBar->update( tr( "Fetching meeting info..." ), tr( "Please wait" ) );
172 iProgressBar->toggleCancellable( true );
173 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
177 void UIManager::meetingDetailsFetched(Meeting &aDetailedMeeting)
179 qDebug() << "[UIManager::meetingDetailsFetched] <Invoked>";
180 if ( iMeetingInfo != 0 )
182 if ( iProgressBar != 0 && iProgressBar->isVisible() )
184 iProgressBar->close(); // Close it in case it's visible
186 MeetingInfoDialog *tmp = new MeetingInfoDialog( &aDetailedMeeting );
187 iWindowManager->showDialog( static_cast<QDialog *>( tmp ) );
188 // TODO : We should use the member variable and implement correctly the setMeeting() method !!!
189 // iMeetingInfo->setMeeting( &aDetailedMeeting );
190 // iWindowManager->showDialog( static_cast<QDialog *>( iMeetingInfo ) );
194 void UIManager::roomStatusIndicatorRequested()
196 if ( iRoomStatusIndicator != 0 )
198 iWindowManager->showView( static_cast<ViewBase *>( iRoomStatusIndicator ) );
199 iEngine->stopIdleTimeCounter();
203 void UIManager::previousViewRestored()
205 iEngine->startIdleTimeCounter();
208 void UIManager::progressBarCancelled()
210 if ( iProgressBar != 0 )
212 iProgressBar->close();
216 void UIManager::changeModeOrdered( DeviceManager::OperationMode aMode )
218 qDebug() << "[UIManager::changeModeOrdered] <Invoked>";
220 if ( iPasswordDialog != 0 )
222 QString text = tr( "You are about to change operation mode to %1." )
223 .arg( iEngine->iDevice->operationModeToString( aMode ) );
224 iPasswordDialog->update( text );
225 iWindowManager->showDialog( static_cast<QDialog *>( iPasswordDialog ) );
229 void UIManager::connectionLost()
231 qDebug() << "UIManager::connectionLost()";
232 iWeeklyView->connectionLost();
233 iRoomStatusIndicator->connectionLost();
236 void UIManager::connectionEstablished()
238 qDebug() << "UIManager::connectionEstablished()";
239 iWeeklyView->connectionEstablished();
240 iRoomStatusIndicator->connectionEstablished();
243 void UIManager::currentRoomChanged(Room *aRoom)
245 qDebug() << "[UIManager::currentRoomChanged] <Invoked>";
246 if ( iWeeklyView != 0 )
248 QDateTime shown = QDateTime( iWeeklyView->beginnigOfShownWeek() );
249 iEngine->fetchMeetings( shown.date().weekNumber(), shown.date().year(), aRoom );
253 void UIManager::updateTime(QDateTime aDateTime)
255 if ( iWeeklyView != 0 )
257 iWeeklyView->setConnectionStatus( aDateTime, iEngine->connected(), iEngine->lastUpdated(), iEngine->errorMessage() );
259 if ( iRoomStatusIndicator != 0 )
261 iRoomStatusIndicator->setConnectionStatus( aDateTime, iEngine->connected(), iEngine->lastUpdated(), iEngine->errorMessage() );
265 void UIManager::passwordEntered( PasswordDialog::PasswordStatus aStatus )
269 case PasswordDialog::Correct:
270 // Show the progress bar..
271 if ( iProgressBar != 0 )
273 iProgressBar->update( tr( "" ), tr( "Changing operation mode" ) );
274 iProgressBar->toggleCancellable( false );
275 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
277 // ... and initiate the mode changing
278 iEngine->changeDeviceMode();
280 case PasswordDialog::Incorrect:
281 iWindowManager->error( tr("Incorrect Password") );
283 case PasswordDialog::Canceled:
287 // Close the dialog after we have handled the status
288 if ( iPasswordDialog != 0 )
290 iPasswordDialog->close();
294 void UIManager::updateProgressBarText(const QString &aText)
296 if ( iProgressBar != 0 )
298 iProgressBar->update( aText );
302 void UIManager::hideProgressBar()
304 qDebug() << "[UIManager::hideProgressBar] <Invoked>";
305 if ( iProgressBar != 0 && iProgressBar->isVisible() )
307 iProgressBar->close();
311 void UIManager::settingsCancelClicked()
313 // Show the weekly view and restart the idle timer
314 if ( iWeeklyView != 0 )
316 iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
317 QT_DELETE(iSettingsView);
318 iEngine->startIdleTimeCounter();