UIManager and some functionality
[qtmeetings] / src / BusinessLogic / UIManager.cpp
1 #include "UIManager.h"
2
3 #include <QDateTime>
4 #include <QTime>
5
6 #include "Engine.h"
7 #include "WindowManager.h"
8 #include "ViewBase.h"
9 #include "WeeklyViewWidget.h"
10 #include "SettingsView.h"
11 #include "RoomStatusIndicatorWidget.h"
12 #include "PasswordDialog.h"
13 #include "MeetingInfoDialog.h"
14 #include "ProgressBar.h"
15 #include "CommunicationManager.h"
16 #include "Configuration.h"
17 #include "DisplaySettings.h"
18
19 #include <QtDebug>
20
21 #define QT_DELETE(X) \
22         if ( X != 0 ) \
23         { \
24                 delete X; \
25                 X = 0; \
26         }
27
28 UIManager::UIManager( Engine *aEngine, WindowManager *aWindowManager ) :
29         iEngine( aEngine ),
30         iWindowManager( aWindowManager ),
31         iWeeklyView( 0 ),
32         iSettingsView( 0 ),
33         iRoomStatusIndicator( 0 ),
34         iPasswordDialog( 0 ),
35         iProgressBar( 0 ),
36         iMeetingInfo( 0 )
37 {
38         if ( iEngine == 0 ) return;
39         if ( iWindowManager == 0 ) return;
40         
41         createWeeklyView();
42         createSettingsView();
43         createRoomStatusIndicator();
44         createPasswordDialog();
45         createProgressBar();
46         createMeetingInfoDialog();
47 }
48
49 UIManager::~UIManager()
50 {
51         iEngine = 0;
52         iWindowManager = 0;
53         
54         QT_DELETE( iMeetingInfo );
55         QT_DELETE( iProgressBar );
56         QT_DELETE( iPasswordDialog );
57         QT_DELETE( iRoomStatusIndicator );
58         QT_DELETE( iSettingsView );
59         QT_DELETE( iWeeklyView );
60 }
61
62 void UIManager::showMainView()
63 {
64         iWindowManager->showView( iWeeklyView );
65 }
66
67 void UIManager::showProgressBar( QString aText )
68 {
69         if ( iProgressBar != 0 )
70         {
71                 iProgressBar->update( tr("Changing current operation mode.") );
72                 iWindowManager->showDialog( iProgressBar );
73         }
74 }
75
76 // ===============================================
77 //              INITIALIZE THE UIMANAGER
78 void UIManager::createWeeklyView()
79 {
80         iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), iEngine->iConfiguration );
81         
82         // Connect signals
83         connect( iWeeklyView, SIGNAL( settingsButtonClicked() ), this, SLOT( settingsViewRequest() ) );
84         connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), this, SLOT( currentRoomChanged( Room * ) ) );
85 }
86
87 void UIManager::createSettingsView()
88 {
89         iSettingsView = new SettingsView;
90         
91         // Connect signals
92         connect( iSettingsView, SIGNAL( okClicked() ), this, SLOT( settingsOkClicked() ) );
93 }
94
95 void UIManager::createRoomStatusIndicator()
96 {
97         iRoomStatusIndicator = new RoomStatusIndicatorWidget( iEngine->defaultRoom(), Room::FreeStatus, QTime::currentTime(), iEngine->iConfiguration->displaySettings()->dateFormat() );
98 }
99
100 void UIManager::createPasswordDialog()
101 {
102         iPasswordDialog = new PasswordDialog( iEngine->iConfiguration->adminPassword(), tr("UIManager::createPasswordDialog"), tr("UIManager::createPasswordDialog") );
103 }
104
105 void UIManager::createProgressBar()
106 {
107         iProgressBar = new ProgressBar( tr("CHANGE THIS") );
108         
109         connect( iProgressBar, SIGNAL( cancelled() ), this, SLOT( progressBarCancelled() ) );
110         connect( iProgressBar, SIGNAL( cancelled() ), iEngine, SLOT( progressBarCancelled() ) );
111 }
112
113 void UIManager::createMeetingInfoDialog()
114 {
115         
116 }
117
118 void UIManager::connectDeviceManager( DeviceManager *aDeviceManager )
119 {
120         connect( aDeviceManager, SIGNAL( changeModeOrdered( DeviceManager::OperationMode ) ),
121                         this, SLOT( changeModeOrdered( DeviceManager::OperationMode ) ) );
122         
123         connect( aDeviceManager, SIGNAL( changingMode( const QString & ) ), iProgressBar, SLOT( update( const QString & ) ) );
124 }
125
126 void UIManager::connectCommunicationManager( CommunicationManager *aCommunicationManager )
127 {
128         // To communication manager
129         connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), aCommunicationManager, SLOT( fetchMeetingDetails( Meeting * ) ) );
130         
131         // From communication manager
132         connect( aCommunicationManager, SIGNAL( meetingsFetched( const QList<Meeting *> ) ), this, SLOT( meetingsFetched( const QList<Meeting *> ) ) );
133         connect( aCommunicationManager, SIGNAL( meetingDetailsFetched( Meeting & ) ), this, SLOT( meetingDetailsFetched( Meeting & ) ) );
134 }
135
136 // ============================================
137 //              UIMANAGER SLOTS
138 void UIManager::settingsViewRequest()
139 {
140         // Show the settings view and stop the idle timer
141         if ( iSettingsView != 0 )
142         {
143                 iWindowManager->showView( static_cast<ViewBase *>( iSettingsView ) );
144                 iEngine->stopIdleTimeCounter();
145         }
146 }
147
148 void UIManager::settingsOkClicked()
149 {
150         // Show the weekly view and restart the idle timer
151         if ( iWeeklyView != 0 )
152         {
153                 iWindowManager->showView( static_cast<ViewBase *>( iWeeklyView ) );
154                 iEngine->startIdleTimeCounter();
155         }
156 }
157
158 void UIManager::meetingsFetched( const QList<Meeting*> &aMeetings )
159 {
160         
161 }
162
163 void UIManager::meetingDetailsFetched(Meeting &aDetailedMeeting)
164 {
165         if ( iMeetingInfo != 0 )
166         {
167                 iMeetingInfo->setMeeting( &aDetailedMeeting );
168                 iWindowManager->showDialog( static_cast<QDialog *>( iMeetingInfo ) );
169         }
170 }
171
172 void UIManager::roomStatusIndicatorRequested()
173 {
174         if ( iRoomStatusIndicator != 0 )
175         {
176                 iWindowManager->showView( static_cast<ViewBase *>( iRoomStatusIndicator ) );
177                 iEngine->stopIdleTimeCounter();
178         }
179 }
180
181 void UIManager::previousViewRestored()
182 {
183         iEngine->startIdleTimeCounter();
184 }
185
186 void UIManager::progressBarCancelled()
187 {
188         // TODO : Close progress bar
189 }
190
191 void UIManager::changeModeOrdered( DeviceManager::OperationMode aMode )
192 {
193         qDebug() << "[UIManager::changeModeOrdered] <Invoked>";
194         
195         QString message = tr( "You are about to change operation mode to %1." )
196                                 .arg( iEngine->iDevice->operationModeToString( aMode ) );
197
198         if ( iPasswordDialog != 0 )
199         {
200                 // TODO : Set the new text for password dialog
201                 iWindowManager->showDialog( static_cast<QDialog *>( iPasswordDialog ) );
202         }
203 }
204
205 void UIManager::currentRoomChanged(Room *aRoom)
206 {
207         if ( iWeeklyView != 0 )
208         {
209                 QDateTime from = QDateTime( iWeeklyView->beginnigOfShownWeek() );
210                 QDateTime to = QDateTime( from.addDays( 8 ) );
211                 iEngine->fetchMeetings( from, to, aRoom );
212         }
213 }
214
215 void UIManager::updateTime(QDateTime aDateTime)
216 {
217         if ( iWeeklyView != 0 )
218         {
219                 iWeeklyView->setCurrentDateTime( aDateTime );
220         }
221 }