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()->dateFormat() );
95 void UIManager::createPasswordDialog()
97 iPasswordDialog = new PasswordDialog( iEngine->iConfiguration->adminPassword(), "", tr("Enter password") );
98 connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ), this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) );
101 void UIManager::createProgressBar()
103 iProgressBar = new ProgressBar( tr("CHANGE THIS"), true );
104 // Connect to UIManager
105 connect( iProgressBar, SIGNAL( cancel() ), this, SLOT( progressBarCancelled() ) );
107 connect( iProgressBar, SIGNAL( cancel() ), iEngine, SLOT( cancelFetchMeetingDetails() ) );
110 void UIManager::createMeetingInfoDialog()
112 iMeetingInfo = new MeetingInfoDialog();
115 void UIManager::connectDeviceManager( DeviceManager *aDeviceManager )
117 connect( aDeviceManager, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ),
118 this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) );
120 connect( aDeviceManager, SIGNAL( changingMode( const QString & ) ), this, SLOT( updateProgressBarText( const QString & ) ) );
121 connect( aDeviceManager, SIGNAL( changeModeFailed() ), this, SLOT( hideProgressBar() ) );
124 void UIManager::connectCommunicationManager( CommunicationManager *aCommunicationManager )
126 connect( aCommunicationManager, SIGNAL( meetingDetailsFetched( Meeting & ) ), this, SLOT( meetingDetailsFetched( Meeting & ) ) );
127 connect( aCommunicationManager, SIGNAL( meetingsFetched( const QList<Meeting *> & ) ), this, SLOT( meetingsFetched( const QList<Meeting *> & ) ) );
130 // ============================================
132 void UIManager::settingsViewRequest()
134 // Show the settings view and stop the idle timer
135 if ( iSettingsView != 0 )
137 iWindowManager->showView( static_cast<ViewBase *>( iSettingsView ) );
138 iEngine->stopIdleTimeCounter();
142 void UIManager::settingsOkClicked()
144 // Show the weekly view and restart the idle timer
145 if ( iWeeklyView != 0 )
147 iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
148 iEngine->startIdleTimeCounter();
152 void UIManager::meetingsFetched( const QList<Meeting*> &aMeetings )
154 qDebug() << "[UIManager::meetingsFetched] <Change the weekly views method to slot so we don't need this>";
155 if ( iWeeklyView != 0 )
157 iWeeklyView->refreshMeetings( aMeetings );
161 void UIManager::showMeetingProgressBar( Meeting *aMeeting )
163 if ( iProgressBar != 0 )
165 iProgressBar->update( tr( "Fetching meeting info..." ), tr( "Please wait" ) );
166 iProgressBar->toggleCancellable( true );
167 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
171 void UIManager::meetingDetailsFetched(Meeting &aDetailedMeeting)
173 qDebug() << "[UIManager::meetingDetailsFetched] <Invoked>";
174 if ( iMeetingInfo != 0 )
176 if ( iProgressBar != 0 && iProgressBar->isVisible() )
178 iProgressBar->close(); // Close it in case it's visible
180 MeetingInfoDialog *tmp = new MeetingInfoDialog( &aDetailedMeeting );
181 iWindowManager->showDialog( static_cast<QDialog *>( tmp ) );
182 // TODO : We should use the member variable and implement correctly the setMeeting() method !!!
183 // iMeetingInfo->setMeeting( &aDetailedMeeting );
184 // iWindowManager->showDialog( static_cast<QDialog *>( iMeetingInfo ) );
188 void UIManager::roomStatusIndicatorRequested()
190 if ( iRoomStatusIndicator != 0 )
192 iWindowManager->showView( static_cast<ViewBase *>( iRoomStatusIndicator ) );
193 iEngine->stopIdleTimeCounter();
197 void UIManager::previousViewRestored()
199 iEngine->startIdleTimeCounter();
202 void UIManager::progressBarCancelled()
204 if ( iProgressBar != 0 )
206 iProgressBar->close();
210 void UIManager::changeModeOrdered( DeviceManager::OperationMode aMode )
212 qDebug() << "[UIManager::changeModeOrdered] <Invoked>";
214 if ( iPasswordDialog != 0 )
216 QString text = tr( "You are about to change operation mode to %1." )
217 .arg( iEngine->iDevice->operationModeToString( aMode ) );
218 iPasswordDialog->update( text );
219 iWindowManager->showDialog( static_cast<QDialog *>( iPasswordDialog ) );
223 void UIManager::connectionLost()
225 qDebug() << "UIManager::connectionLost()";
226 iWeeklyView->connectionLost();
227 iSettingsView->connectionLost();
228 iRoomStatusIndicator->connectionLost();
231 void UIManager::connectionEstablished()
233 qDebug() << "UIManager::connectionEstablished()";
234 iWeeklyView->connectionEstablished();
235 iSettingsView->connectionEstablished();
236 iRoomStatusIndicator->connectionEstablished();
239 void UIManager::currentRoomChanged(Room *aRoom)
241 qDebug() << "[UIManager::currentRoomChanged] <Invoked>";
242 if ( iWeeklyView != 0 )
244 QDateTime from = QDateTime( iWeeklyView->beginnigOfShownWeek() );
245 QDateTime to = QDateTime( from.addDays( 8 ) );
246 iEngine->fetchMeetings( from, to, aRoom );
250 void UIManager::updateTime(QDateTime aDateTime)
252 if ( iWeeklyView != 0 )
254 iWeeklyView->setCurrentDateTime( aDateTime );
258 void UIManager::passwordEntered( PasswordDialog::PasswordStatus aStatus )
262 case PasswordDialog::Correct:
263 // Show the progress bar..
264 if ( iProgressBar != 0 )
266 iProgressBar->update( tr( "" ), tr( "Changing operation mode" ) );
267 iProgressBar->toggleCancellable( false );
268 iWindowManager->showDialog( static_cast<QDialog *>( iProgressBar ), false, false );
270 // ... and initiate the mode changing
271 iEngine->changeDeviceMode();
273 case PasswordDialog::Incorrect:
274 iWindowManager->error( tr("Incorrect Password") );
276 case PasswordDialog::Canceled:
280 // Close the dialog after we have handled the status
281 if ( iPasswordDialog != 0 )
283 iPasswordDialog->close();
287 void UIManager::updateProgressBarText(const QString &aText)
289 if ( iProgressBar != 0 )
291 iProgressBar->update( aText );
295 void UIManager::hideProgressBar()
297 qDebug() << "[UIManager::hideProgressBar] <Invoked>";
298 if ( iProgressBar != 0 && iProgressBar->isVisible() )
300 iProgressBar->close();