Merge branch 'master' into dev_local
[qtmeetings] / src / UserInterface / WindowManager.cpp
index 3819076..f4b7aea 100644 (file)
 #include "WindowManager.h"
 
-#include <QTimer>
-#include "Configuration.h"
-#include "DisplaySettings.h"
-#include "Meeting.h"
-#include "Room.h"
-#include "Clock.h"
-#include "WeeklyViewWidget.h"
-#include "RoomStatusIndicatorWidget.h"
-#include "MeetingInfoDialog.h"
+#include <QEvent>
+#include <QDialog>
+#include "ViewBase.h"
 #include "PopUpMessageBox.h"
-#include "DeviceManager.h"
-#include "SettingsView.h"
-#include "ProgressBar.h"
 
 #include <QtDebug>
 
-WindowManager::WindowManager( Configuration *aConfiguration ) :
-               QObject(),
+WindowManager::WindowManager( QWidget *aParent ) :
+               QWidget( aParent ),
                iApplicationName( tr( "Qt Meetings" ) ),
-               iFullScreen( false ),
-               iConfiguration( aConfiguration ),
-               iWeeklyView( 0 ),
-               iRoomStatusView( 0 ),
-               iMeetingInfo( 0 ),
-               iProgressBar( 0 ),
-               iPasswordDialog( 0 )
+               iCurrentView( 0 )
 {
-       iWeeklyView = new WeeklyViewWidget( QDateTime::currentDateTime(), aConfiguration );
-       iWeeklyView->setWindowTitle( iApplicationName );
-       connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );
-       connect( iWeeklyView, SIGNAL( meetingActivated( Meeting * ) ), this, SIGNAL( meetingActivated( Meeting * ) ) );
-       connect( iWeeklyView, SIGNAL( currentRoomChanged( Room * ) ), this, SIGNAL( currentRoomChanged( Room * ) ) );
-       connect( iWeeklyView, SIGNAL( shownWeekChanged( QDate ) ), this, SIGNAL( shownWeekChanged( QDate ) ) );
-       
-       showWeeklyView();
-       
+       this->setWindowTitle( iApplicationName );
 }
 
 WindowManager::~WindowManager()
 {
-       delete iWeeklyView;
-       iWeeklyView = 0;
-       delete iRoomStatusView;
-       iRoomStatusView = 0;
-       delete iMeetingInfo;
-       iMeetingInfo = 0;
-       delete iProgressBar;
-       iProgressBar = 0;
-       delete iPasswordDialog;
-       iPasswordDialog = 0;
+       
 }
 
-void WindowManager::distributeDateTimeInfo( QDateTime aCurrentDateTime )
+void WindowManager::showView( ViewBase *view )
 {
-       if ( iRoomStatusView != 0 && iRoomStatusView->isActiveWindow() )
+       // The views parent must be WindowManager when it is displayed trough this
+       QWidget *parent = static_cast<QWidget *>(view->parent());
+       if ( parent != this )
        {
-               iRoomStatusView->setCurrentTime( aCurrentDateTime.time() );
+               view->setParent( this );
        }
-
-       if ( iWeeklyView != 0 && iWeeklyView->isActiveWindow() )
+       
+       // Store the current view because it is hidden after the new view is shown
+       QWidget *oldView = iCurrentView;
+       
+       // If the new view is observed view we store the current into stack
+       // from which it is restored when the new view receives event we are
+       // listening to.
+       if ( view->viewMode() == ViewBase::ObservedView )
        {
-               iWeeklyView->setCurrentDateTime( aCurrentDateTime );
+               iViewList.push( iCurrentView );
        }
+       
+       // Make the new view visible and handle connections
+       iCurrentView = view;
+       connect( iCurrentView, SIGNAL( eventDetected() ), this, SLOT( viewEventDetected() ) );
+       connect( this, SIGNAL( viewResized(const QSize &, const QSize &) ), iCurrentView, SLOT( viewResized( const QSize &, const QSize & ) ) );
+       view->resize( this->size() );
+       
+       view->show();
+       
+       // Disconnect old connections and hide the view
+       if ( oldView != 0 )
+       {
+               disconnect( oldView, SIGNAL( eventDetected() ), this, SLOT( viewEventDetected() ) );
+               disconnect( this, SIGNAL( viewResized(const QSize &, const QSize &) ), oldView, SLOT( viewResized(const QSize &, const QSize &) ) );
+               oldView->hide();
+       }
+       
 }
 
-void WindowManager::roomStatusChanged( Room *aRoom, Room::Status aStatus, QTime aTime )
+void WindowManager::showDialog(QDialog *aDialog, bool blocking, bool aSendSignal)
 {
-       if ( iRoomStatusView == 0 )
+       // Handle dialog displaying
+       if ( aSendSignal ) emit dialogActivated();
+       if ( blocking )
        {
-               iRoomStatusView = new RoomStatusIndicatorWidget( aRoom, aStatus, aTime, iConfiguration->displaySettings()->timeFormat() );
-               iRoomStatusView->setWindowTitle( iApplicationName );
-               if( iFullScreen )
-                       iRoomStatusView->setWindowState( Qt::WindowFullScreen );
-               connect( iRoomStatusView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );
+               aDialog->exec();
        }
        else
        {
-               iRoomStatusView->statusChanged( aStatus, aTime );
-       }
-       if ( !iWeeklyView->isVisible() && !iRoomStatusView->isVisible() )
-       {
-               showRoomStatus();
+               aDialog->show();
        }
+       if ( aSendSignal ) emit dialogDeactivated();
 }
 
-void WindowManager::showRoomStatus()
+void WindowManager::viewEventDetected()
 {
-       qDebug() << "WindowManager::showRoomStatus";
-       iWeeklyView->setDefaultRoom();
-       if ( iRoomStatusView == 0 )
-       {
-               emit roomStatusInfoNeeded( iWeeklyView->currentRoom() );
-       }
-       else
+       
+       if ( iCurrentView != 0 )
        {
-               iRoomStatusView->show();
-               if ( iWeeklyView->isVisible() )
+               if ( iCurrentView->viewMode() == ViewBase::NormalView )
+               {
+                       emit eventDetected();
+               }
+               else if ( iCurrentView->viewMode() == ViewBase::ObservedView )
                {
-                       iWeeklyView->hide();
+                       if ( !iViewList.isEmpty() )
+                       {
+                               ViewBase *previousView = static_cast<ViewBase *>( iViewList.pop() );
+                               this->showView( previousView );
+                               emit previousViewRestored();
+                       }
                }
        }
 
-       // closing/deleting meeting info dialog
-       if ( iMeetingInfo != 0 )
-       {
-               iMeetingInfo->hide();
-       }
 }
 
-void WindowManager::showWeeklyView()
+bool WindowManager::event(QEvent *event)
 {
-       qDebug() << "WindowManager::showWeeklyView";
-       if ( iRoomStatusView != 0 && iRoomStatusView->isVisible() )
+       if ( event->type() == QEvent::Resize )
        {
-               iRoomStatusView->hide();
+               if ( iCurrentView != 0 )
+               {
+                       QSize currentSize = iCurrentView->size();
+                       iCurrentView->setFixedSize( this->size() );
+                       emit viewResized( this->size(), currentSize );
+               }
        }
-
-       iWeeklyView->show();
-}
-
-void WindowManager::fullScreen()
-{
-       if ( iRoomStatusView != 0 )
-               iRoomStatusView->setWindowState( Qt::WindowFullScreen );
-       if ( iWeeklyView != 0 )
-               iWeeklyView->setWindowState( Qt::WindowFullScreen );
-       iFullScreen = true;
-}
-
-void WindowManager::insertMeeting( Meeting *aMeeting )
-{
-       iWeeklyView->insertMeeting( aMeeting );
-}
-
-void WindowManager::deleteMeeting( Meeting *aMeeting )
-{
-       iWeeklyView->deleteMeeting( aMeeting );
-}
-
-void WindowManager::showMeetingInfo( Meeting *aMeeting )
-{
-       iMeetingInfo = new MeetingInfoDialog( aMeeting );
-       // Display modal dialog
-       iMeetingInfo->exec();
-
-       delete iMeetingInfo;
-       iMeetingInfo = 0;
-}
-
-void WindowManager::showSettingsView()
-{
-       // TODO : give the Torspo for the person who was responsible to write this method
-}
-
-WeeklyViewWidget * WindowManager::weeklyView()
-{
-       return iWeeklyView;
-}
-
-void WindowManager::error( const QString &aErrorMessage )
-{
-       qDebug() << "WindowManager::showErrorPopup";
-
-       PopUpMessageBox::error( 0, aErrorMessage );
-}
-
-void WindowManager::showPasswordDialog( QByteArray aAdminPassword, const QString &aMessage )
-{
-       iPasswordDialog = new PasswordDialog( aAdminPassword, aMessage );
-       connect( iPasswordDialog, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ),
-                       this, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ) );
-       iPasswordDialog->show();
        
-       //TODO connect connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );
+       return QWidget::event( event );
 }
 
-void WindowManager::closePasswordDialog()
-{
-       iPasswordDialog->close();
-       delete iPasswordDialog;
-       iPasswordDialog = 0;
-}
-
-void WindowManager::showProgressBar( const QString &aText, bool aCancellable )
+void WindowManager::error( const QString &aErrorMessage )
 {
-       qDebug() << "WindowManager::showProgressBar( const QString & )";
-       if( iProgressBar == 0 ) {
-               iProgressBar = new ProgressBar( aText, aCancellable );
-               iProgressBar->setFixedSize( 600, 125 );
-               iProgressBar->show();
-               if( aCancellable )
-                       connect( iProgressBar, SIGNAL( cancel() ), this, SIGNAL( progressBarCancelled() ) );
-       }
-       
-       //TODO connect connect( iWeeklyView, SIGNAL( observedEventDetected() ), this, SIGNAL( observedEventDetected() ) );
-}
+       qDebug() << "WindowManager::error       ";
 
-void WindowManager::closeProgressBar()
-{
-       qDebug() << "WindowManager::closeProgressBar()";
-       if( iProgressBar )
+       PopUpMessageBox *popup = PopUpMessageBox::error( 0, aErrorMessage );
+       if ( popup != 0 )
        {
-               iProgressBar->close();
-               delete iProgressBar;
-               iProgressBar = 0;
+               showDialog( static_cast<QDialog *>( popup ), false );
        }
 }
 
-void WindowManager::updateProgressBar( const QString &aMessage )
+void WindowManager::setFullscreen()
 {
-       qDebug() << "WindowManager::updateProgressBar( const QString & )";
-       if( iProgressBar != 0 )
-               iProgressBar->update( aMessage );
+       this->setWindowState( Qt::WindowFullScreen );
+       // Resize event handles the rest.
 }
 
 void WindowManager::connectionLost()