924392e2d4b327f1973bc08f29b661ec656e124d
[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                 iFullScreen( false ),
23                 iConfiguration( aConfiguration ),
24                 iWeeklyView( 0 ),
25                 iRoomStatusView( 0 ),
26                 iMeetingInfo( 0 ),
27                 iProgressBar( 0 ),
28                 iPasswordDialog( 0 )
29 {
30         iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), aConfiguration );
31         iWeeklyView->setWindowTitle( iApplicationName );
32         connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );
33         connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), this, SIGNAL( meetingActivated( Meeting * ) ) );
34         connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( currentRoomChanged( Room * ) ) );
35         connect( iWeeklyView, SIGNAL( shownWeekChanged( QDate ) ), this, SIGNAL( shownWeekChanged( QDate ) ) );
36         
37         showWeeklyView();
38         
39 }
40
41 WindowManager::~WindowManager()
42 {
43         delete iWeeklyView;
44         iWeeklyView = 0;
45         delete iRoomStatusView;
46         iRoomStatusView = 0;
47         delete iMeetingInfo;
48         iMeetingInfo = 0;
49         delete iProgressBar;
50         iProgressBar = 0;
51         delete iPasswordDialog;
52         iPasswordDialog = 0;
53 }
54
55 void WindowManager::distributeDateTimeInfo( QDateTime aCurrentDateTime )
56 {
57         if ( iRoomStatusView != 0 && iRoomStatusView->isActiveWindow() )
58         {
59                 iRoomStatusView->setCurrentTime( aCurrentDateTime.time() );
60         }
61
62         if ( iWeeklyView != 0 && iWeeklyView->isActiveWindow() )
63         {
64                 iWeeklyView->setCurrentDateTime( aCurrentDateTime );
65         }
66 }
67
68 void WindowManager::roomStatusChanged( Room *aRoom, Room::Status aStatus, QTime aTime )
69 {
70         if ( iRoomStatusView == 0 )
71         {
72                 iRoomStatusView = new RoomStatusIndicatorWidget( aRoom, aStatus, aTime, iConfiguration->displaySettings()->timeFormat() );
73                 iRoomStatusView->setWindowTitle( iApplicationName );
74                 if( iFullScreen )
75                         iRoomStatusView->setWindowState( Qt::WindowFullScreen );
76                 connect( iRoomStatusView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );
77         }
78         else
79         {
80                 iRoomStatusView->statusChanged( aStatus, aTime );
81         }
82         if ( !iWeeklyView->isVisible() && !iRoomStatusView->isVisible() )
83         {
84                 showRoomStatus();
85         }
86 }
87
88 void WindowManager::showRoomStatus()
89 {
90         qDebug() << "WindowManager::showRoomStatus";
91
92         if ( iRoomStatusView == 0 )
93         {
94                 emit roomStatusInfoNeeded( iWeeklyView->currentRoom() );
95         }
96         else
97         {
98                 iRoomStatusView->show();
99                 if ( iWeeklyView->isVisible() )
100                 {
101                         iWeeklyView->hide();
102                 }
103         }
104
105         // closing/deleting meeting info dialog
106         if ( iMeetingInfo != 0 )
107         {
108                 iMeetingInfo->hide();
109         }
110 }
111
112 void WindowManager::showWeeklyView()
113 {
114         qDebug() << "WindowManager::showWeeklyView";
115         if ( iRoomStatusView != 0 && iRoomStatusView->isVisible() )
116         {
117                 iRoomStatusView->hide();
118         }
119
120         iWeeklyView->show();
121 }
122
123 void WindowManager::fullScreen()
124 {
125         if ( iRoomStatusView != 0 )
126                 iRoomStatusView->setWindowState( Qt::WindowFullScreen );
127         if ( iWeeklyView != 0 )
128                 iWeeklyView->setWindowState( Qt::WindowFullScreen );
129         iFullScreen = true;
130 }
131
132 void WindowManager::insertMeeting( Meeting *aMeeting )
133 {
134         iWeeklyView->insertMeeting( aMeeting );
135 }
136
137 void WindowManager::deleteMeeting( Meeting *aMeeting )
138 {
139         iWeeklyView->deleteMeeting( aMeeting );
140 }
141
142 void WindowManager::showMeetingInfo( Meeting *aMeeting )
143 {
144         iMeetingInfo = new MeetingInfoDialog( aMeeting );
145         // Display modal dialog
146         iMeetingInfo->exec();
147
148         delete iMeetingInfo;
149         iMeetingInfo = 0;
150 }
151
152 void WindowManager::showSettingsView()
153 {
154         // TODO : give the Torspo for the person who was responsible to write this method
155 }
156
157 WeeklyViewWidget * WindowManager::weeklyView()
158 {
159         return iWeeklyView;
160 }
161
162 void WindowManager::error( const QString &aErrorMessage )
163 {
164         qDebug() << "WindowManager::showErrorPopup";
165
166         PopUpMessageBox::error( 0, aErrorMessage );
167 }
168
169 void WindowManager::showPasswordDialog( QByteArray aAdminPassword, const QString &aMessage )
170 {
171         iPasswordDialog = new PasswordDialog( aAdminPassword, aMessage );
172         connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ),
173                         this, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ) );
174         iPasswordDialog->show();
175         
176         //TODO connect connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );
177 }
178
179 void WindowManager::closePasswordDialog()
180 {
181         iPasswordDialog->close();
182         delete iPasswordDialog;
183         iPasswordDialog = 0;
184 }
185
186 void WindowManager::showProgressBar( const QString &aText, bool aCancellable )
187 {
188         qDebug() << "WindowManager::showProgressBar( const QString & )";
189         if( iProgressBar == 0 ) {
190                 iProgressBar = new ProgressBar( aText, aCancellable );
191                 iProgressBar->setFixedSize( 600, 125 );
192                 iProgressBar->show();
193                 connect( iProgressBar, SIGNAL( cancel() ), this, SIGNAL( progressBarCancelled() ) );
194         }
195         
196         //TODO connect connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );
197 }
198
199 void WindowManager::closeProgressBar()
200 {
201         qDebug() << "WindowManager::closeProgressBar()";
202         if( iProgressBar )
203         {
204                 iProgressBar->close();
205                 delete iProgressBar;
206                 iProgressBar = 0;
207         }
208 }
209
210 void WindowManager::updateProgressBar( const QString &aMessage )
211 {
212         qDebug() << "WindowManager::updateProgressBar( const QString & )";
213         if( iProgressBar != 0 )
214                 iProgressBar->update( aMessage );
215 }