3a593a9a450ddf4e993dabd25ec05b6513f6d1db
[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::showPasswordDialog( QByteArray aAdminPassword, const QString &aMessage )
164 {
165         iPasswordDialog = new PasswordDialog( aAdminPassword, aMessage );
166         connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ),
167                         this, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ) );
168         iPasswordDialog->show();
169 }
170
171 void WindowManager::closePasswordDialog()
172 {
173         iPasswordDialog->close();
174         delete iPasswordDialog;
175         iPasswordDialog = 0;
176 }
177
178 void WindowManager::showProgressBar( const QString &aText )
179 {
180         qDebug() << "WindowManager::showProgressBar( const QString & )";
181         if( iProgressBar == 0 ) {
182                 iProgressBar = new ProgressBar( aText );
183                 iProgressBar->show();
184                 connect( iProgressBar, SIGNAL( cancel() ), this, SIGNAL( progressBarCancelled() ) );
185         }
186 }
187
188 void WindowManager::closeProgressBar()
189 {
190         iProgressBar->close();
191         delete iProgressBar;
192         iProgressBar = 0;
193 }