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 QT_DELETE(iWeeklyView);
152 if ( iWeeklyView != 0 )
154 iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
155 QT_DELETE(iSettingsView);
156 iEngine->startIdleTimeCounter();
157 currentRoomChanged(iWeeklyView->currentRoom());
161 void UIManager::meetingsFetched( const QList<Meeting*> &aMeetings )
163 qDebug() << "[UIManager::meetingsFetched] <Change the weekly views method to slot so we don't need this>";
164 if ( iWeeklyView != 0 )
166 iWeeklyView->refreshMeetings( aMeetings );
170 void UIManager::showMeetingProgressBar( Meeting */*aMeeting*/ )
172 if ( iProgressBar != 0 )
174 iProgressBar->update( tr( "Fetching meeting info..." ), tr( "Please wait" ) );
175 iProgressBar->toggleCancellable( true );
176 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
180 void UIManager::meetingDetailsFetched(Meeting &aDetailedMeeting)
182 qDebug() << "[UIManager::meetingDetailsFetched] <Invoked>";
183 if ( iMeetingInfo != 0 )
185 if ( iProgressBar != 0 && iProgressBar->isVisible() )
187 iProgressBar->close(); // Close it in case it's visible
189 MeetingInfoDialog *tmp = new MeetingInfoDialog( &aDetailedMeeting );
190 iWindowManager->showDialog( static_cast<QDialog *>( tmp ) );
191 // TODO : We should use the member variable and implement correctly the setMeeting() method !!!
192 // iMeetingInfo->setMeeting( &aDetailedMeeting );
193 // iWindowManager->showDialog( static_cast<QDialog *>( iMeetingInfo ) );
197 void UIManager::roomStatusIndicatorRequested()
199 if ( iRoomStatusIndicator != 0 )
201 iWindowManager->showView( static_cast<ViewBase *>( iRoomStatusIndicator ) );
202 iEngine->stopIdleTimeCounter();
206 void UIManager::previousViewRestored()
208 iEngine->startIdleTimeCounter();
211 void UIManager::progressBarCancelled()
213 if ( iProgressBar != 0 )
215 iProgressBar->close();
219 void UIManager::changeModeOrdered( DeviceManager::OperationMode aMode )
221 qDebug() << "[UIManager::changeModeOrdered] <Invoked>";
223 if ( iPasswordDialog != 0 )
225 QString text = tr( "You are about to change operation mode to %1." )
226 .arg( iEngine->iDevice->operationModeToString( aMode ) );
227 iPasswordDialog->update( text );
228 iWindowManager->showDialog( static_cast<QDialog *>( iPasswordDialog ) );
232 void UIManager::connectionLost()
234 qDebug() << "UIManager::connectionLost()";
235 iWeeklyView->connectionLost();
236 iRoomStatusIndicator->connectionLost();
239 void UIManager::connectionEstablished()
241 qDebug() << "UIManager::connectionEstablished()";
242 iWeeklyView->connectionEstablished();
243 iRoomStatusIndicator->connectionEstablished();
246 void UIManager::currentRoomChanged(Room *aRoom)
248 qDebug() << "[UIManager::currentRoomChanged] <Invoked>";
249 if ( iWeeklyView != 0 )
251 QDateTime shown = QDateTime( iWeeklyView->beginnigOfShownWeek() );
252 iEngine->fetchMeetings( shown.date().weekNumber(), shown.date().year(), aRoom );
256 void UIManager::updateTime(QDateTime aDateTime)
258 if ( iWeeklyView != 0 )
260 iWeeklyView->setConnectionStatus( aDateTime, iEngine->connected(), iEngine->lastUpdated(), iEngine->errorMessage() );
262 if ( iRoomStatusIndicator != 0 )
264 iRoomStatusIndicator->setConnectionStatus( aDateTime, iEngine->connected(), iEngine->lastUpdated(), iEngine->errorMessage() );
268 void UIManager::passwordEntered( PasswordDialog::PasswordStatus aStatus )
272 case PasswordDialog::Correct:
273 // Show the progress bar..
274 if ( iProgressBar != 0 )
276 iProgressBar->update( tr( "" ), tr( "Changing operation mode" ) );
277 iProgressBar->toggleCancellable( false );
278 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
280 // ... and initiate the mode changing
281 iEngine->changeDeviceMode();
283 case PasswordDialog::Incorrect:
284 iWindowManager->error( tr("Incorrect Password") );
286 case PasswordDialog::Canceled:
290 // Close the dialog after we have handled the status
291 if ( iPasswordDialog != 0 )
293 iPasswordDialog->close();
297 void UIManager::updateProgressBarText(const QString &aText)
299 if ( iProgressBar != 0 )
301 iProgressBar->update( aText );
305 void UIManager::hideProgressBar()
307 qDebug() << "[UIManager::hideProgressBar] <Invoked>";
308 if ( iProgressBar != 0 && iProgressBar->isVisible() )
310 iProgressBar->close();
314 void UIManager::settingsCancelClicked()
316 // Show the weekly view and restart the idle timer
317 if ( iWeeklyView != 0 )
319 iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
320 QT_DELETE(iSettingsView);
321 iEngine->startIdleTimeCounter();