8107fbbe1b164f0ee3ef2fb46f6271322dd0c589
[qtmeetings] / src / UserInterface / WindowManager.cpp
1 #include "WindowManager.h"
2
3 #include <QTimer>
4 #include "Configuration.h"
5 #include "DisplaySettings.h"
6 #include "Meeting.h"
7 #include "Room.h"
8 #include "Clock.h"
9 #include "WeeklyViewWidget.h"
10 #include "RoomStatusIndicatorWidget.h"
11 #include "MeetingInfoDialog.h"
12 #include "PopUpMessageBox.h"
13 #include "DeviceManager.h"
14 #include "SettingsView.h"
15 #include "ProgressBar.h"
16
17 #include <QtDebug>
18
19 WindowManager::WindowManager( Configuration *aConfiguration ) :
20                 QObject(),
21                 iApplicationName( tr( "Qt Meetings" ) ),
22                 iConfiguration( aConfiguration ),
23                 iWeeklyView( 0 ),
24                 iRoomStatusView( 0 ),
25                 iMeetingInfo( 0 ),
26                 iProgressBar( 0 ),
27                 iPasswordDialog( 0 )
28 {
29         iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), aConfiguration );
30         iWeeklyView->setWindowTitle( iApplicationName );
31         connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );
32         connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), this, SIGNAL( meetingActivated( Meeting * ) ) );
33         connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( currentRoomChanged( Room * ) ) );
34         connect( iWeeklyView, SIGNAL( shownWeekChanged( QDate ) ), this, SIGNAL( shownWeekChanged( QDate ) ) );
35         
36         showWeeklyView();
37         
38 }
39
40 WindowManager::~WindowManager()
41 {
42         delete iWeeklyView;
43         iWeeklyView = 0;
44         delete iRoomStatusView;
45         iRoomStatusView = 0;
46         delete iMeetingInfo;
47         iMeetingInfo = 0;
48         delete iProgressBar;
49         iProgressBar = 0;
50         delete iPasswordDialog;
51         iPasswordDialog = 0;
52 }
53
54 void WindowManager::distributeDateTimeInfo( QDateTime aCurrentDateTime )
55 {
56         if ( iRoomStatusView != 0 && iRoomStatusView->isActiveWindow() )
57         {
58                 iRoomStatusView->setCurrentTime( aCurrentDateTime.time() );
59         }
60
61         if ( iWeeklyView != 0 && iWeeklyView->isActiveWindow() )
62         {
63                 iWeeklyView->setCurrentDateTime( aCurrentDateTime );
64         }
65 }
66
67 void WindowManager::roomStatusChanged( Room *aRoom, Room::Status aStatus, QTime aTime )
68 {
69         if ( iRoomStatusView == 0 )
70         {
71                 iRoomStatusView = new RoomStatusIndicatorWidget( aRoom, aStatus, aTime, iConfiguration->displaySettings()->timeFormat() );
72                 iRoomStatusView->setWindowTitle( iApplicationName );
73                 connect( iRoomStatusView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );
74         }
75         else
76         {
77                 iRoomStatusView->statusChanged( aStatus, aTime );
78         }
79         if ( !iWeeklyView->isVisible() && !iRoomStatusView->isVisible() )
80         {
81                 showRoomStatus();
82         }
83 }
84
85 void WindowManager::showRoomStatus()
86 {
87         qDebug() << "WindowManager::showRoomStatus";
88
89         if ( iRoomStatusView == 0 )
90         {
91                 emit roomStatusInfoNeeded( iWeeklyView->currentRoom() );
92         }
93         else
94         {
95                 iRoomStatusView->show();
96                 if ( iWeeklyView->isVisible() )
97                 {
98                         iWeeklyView->hide();
99                 }
100         }
101
102         // closing/deleting meeting info dialog
103         if ( iMeetingInfo != 0 )
104         {
105                 iMeetingInfo->hide();
106         }
107 }
108
109 void WindowManager::showWeeklyView()
110 {
111         qDebug() << "WindowManager::showWeeklyView";
112         if ( iRoomStatusView != 0 && iRoomStatusView->isVisible() )
113         {
114                 iRoomStatusView->hide();
115         }
116
117         iWeeklyView->show();
118 }
119
120 void WindowManager::fullScreen()
121 {
122         iRoomStatusView->setWindowState( Qt::WindowFullScreen );
123         iWeeklyView->setWindowState( Qt::WindowFullScreen );
124 }
125
126 void WindowManager::insertMeeting( Meeting *aMeeting )
127 {
128         iWeeklyView->insertMeeting( aMeeting );
129 }
130
131 void WindowManager::deleteMeeting( Meeting *aMeeting )
132 {
133         iWeeklyView->deleteMeeting( aMeeting );
134 }
135
136 void WindowManager::showMeetingInfo( Meeting *aMeeting )
137 {
138         iMeetingInfo = new MeetingInfoDialog( aMeeting );
139         // Display modal dialog
140         iMeetingInfo->exec();
141
142         delete iMeetingInfo;
143         iMeetingInfo = 0;
144 }
145
146 void WindowManager::showSettingsView()
147 {
148         // TODO : give the Torspo for the person who was responsible to write this method
149 }
150
151 WeeklyViewWidget * WindowManager::weeklyView()
152 {
153         return iWeeklyView;
154 }
155
156 void WindowManager::error( const QString &aErrorMessage )
157 {
158         qDebug() << "WindowManager::showErrorPopup";
159
160         PopUpMessageBox::error( 0, aErrorMessage );
161 }
162
163 void WindowManager::passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus )
164 {
165         delete iPasswordDialog;
166         iPasswordDialog = 0;
167         
168         switch ( aPasswordStatus )
169         {
170                 case PasswordDialog::Correct :
171                 {
172                         progressBar( tr( "Changing operation mode" ), true );
173                         iProgressBar->show();
174                         while(1);
175                         break;
176                 }
177                 case PasswordDialog::Incorrect :
178                 {
179                         error( tr( "Incorrect password." ) );
180                         break;
181                 }
182                 default : //case PasswordDialog::Canceled
183                 {
184                 }
185         }
186 }
187
188 void WindowManager::showPasswordDialog( QByteArray aAdminPassword, const QString &aMessage )
189 {
190         iPasswordDialog = new PasswordDialog( aAdminPassword, aMessage );
191         iPasswordDialog->show();
192 }
193
194
195 void WindowManager::progressBar( const QString &aText, bool aStart )
196 {
197         qDebug() << "WindowManager::progressBar( const QString &, bool)";
198         if( aStart ) {
199                 if( iProgressBar == 0 ) {
200                         iProgressBar = new ProgressBar( aText );
201                         connect( iProgressBar, SIGNAL( cancel() ), this, SLOT( progressBar() ) );
202                         connect( iProgressBar, SIGNAL( started() ), this, SLOT( changeMode() ) );
203                 }
204         }
205         else {
206                 if( iProgressBar != 0 ) {
207                         delete iProgressBar;
208                         iProgressBar = 0;
209                 }
210         }
211 }
212