Changes to error texts
[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         iWeeklyView->setDefaultRoom();
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::showMeetingInfo( Meeting *aMeeting )
133 {
134         iMeetingInfo = new MeetingInfoDialog( aMeeting );
135         // Display modal dialog
136         iMeetingInfo->exec();
137
138         delete iMeetingInfo;
139         iMeetingInfo = 0;
140 }
141
142 void WindowManager::showSettingsView()
143 {
144         // TODO : give the Torspo for the person who was responsible to write this method
145 }
146
147 WeeklyViewWidget * WindowManager::weeklyView()
148 {
149         return iWeeklyView;
150 }
151
152 void WindowManager::error( const QString &aErrorMessage )
153 {
154         qDebug() << "WindowManager::showErrorPopup";
155
156         PopUpMessageBox::error( 0, aErrorMessage );
157 }
158
159 void WindowManager::showPasswordDialog( QByteArray aAdminPassword, const QString &aMessage )
160 {
161         iPasswordDialog = new PasswordDialog( aAdminPassword, aMessage );
162         connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ),
163                         this, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ) );
164         iPasswordDialog->show();
165         
166         //TODO connect connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );
167 }
168
169 void WindowManager::closePasswordDialog()
170 {
171         iPasswordDialog->close();
172         delete iPasswordDialog;
173         iPasswordDialog = 0;
174 }
175
176 void WindowManager::showProgressBar( const QString &aText, bool aCancellable )
177 {
178         qDebug() << "WindowManager::showProgressBar( const QString & )";
179         if( iProgressBar == 0 ) {
180                 iProgressBar = new ProgressBar( aText, aCancellable );
181                 iProgressBar->setFixedSize( 600, 125 );
182                 iProgressBar->show();
183                 if( aCancellable )
184                         connect( iProgressBar, SIGNAL( cancel() ), this, SIGNAL( progressBarCancelled() ) );
185         }
186         
187         //TODO connect connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );
188 }
189
190 void WindowManager::closeProgressBar()
191 {
192         qDebug() << "WindowManager::closeProgressBar()";
193         if( iProgressBar )
194         {
195                 iProgressBar->close();
196                 delete iProgressBar;
197                 iProgressBar = 0;
198         }
199 }
200
201 void WindowManager::updateProgressBar( const QString &aMessage )
202 {
203         qDebug() << "WindowManager::updateProgressBar( const QString & )";
204         if( iProgressBar != 0 )
205                 iProgressBar->update( aMessage );
206 }
207
208 void WindowManager::refreshMeetings( const QList<Meeting*> &aMeetings )
209 {
210         qDebug() << "WindowManager::refreshMeetings()";
211         iWeeklyView->refreshMeetings( aMeetings );
212 }