Moved the logicasl part of the progresbar/password dialog from WindowManager to Engin...
authorZoltan Papp <zoltan.papp@ixonos.com>
Tue, 19 May 2009 13:41:28 +0000 (16:41 +0300)
committerZoltan Papp <zoltan.papp@ixonos.com>
Tue, 19 May 2009 13:41:28 +0000 (16:41 +0300)
src/BusinessLogic/Engine.cpp
src/BusinessLogic/Engine.h
src/IO/DeviceControl/DeviceManager.h
src/UserInterface/Utils/PasswordDialog.cpp
src/UserInterface/Utils/PasswordDialog.h
src/UserInterface/Utils/ProgressBar.cpp [new file with mode: 0755]
src/UserInterface/Utils/ProgressBar.h [new file with mode: 0755]
src/UserInterface/WindowManager.cpp
src/UserInterface/WindowManager.h

index 6e677c4..e529799 100644 (file)
@@ -35,6 +35,9 @@ Engine::Engine() :
        connect( iWindowManager, SIGNAL( meetingActivated( Meeting * ) ), this, SLOT( fetchMeetingDetails( Meeting * ) ) );
        connect( iWindowManager, SIGNAL( currentRoomChanged( Room * ) ), this, SLOT( currentRoomChanged( Room * ) ) );
        connect( iWindowManager, SIGNAL( shownWeekChanged( QDate ) ), this, SLOT( shownWeekChanged( QDate ) ) );
+       connect( iWindowManager, SIGNAL( passwordEntered( PasswordDialog::PasswordStatus ) ),
+                       this, SLOT( passwordEntered( PasswordDialog::PasswordStatus ) ) );
+       connect( iWindowManager, SIGNAL( progressBarCancelled() ), this, SLOT( progressBarCancelled() ) );
        
        // initialize communication
        iCommunication = new CommunicationManager( *(iConfiguration->connectionSettings()) );
@@ -287,3 +290,35 @@ void Engine::changeModeOrdered( DeviceManager::OperationMode aMode )
        
        iWindowManager->showPasswordDialog( iConfiguration->adminPassword(), message );
 }
+
+void Engine::passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus )
+{
+       qDebug() << "Engine::passwordEntered( PasswordDialog::PasswordStatus )";
+       iWindowManager->closePasswordDialog();
+       
+       switch ( aPasswordStatus )
+       {
+               case PasswordDialog::Correct :
+               {
+                       iWindowManager->showProgressBar( "Changing current operation mode." );
+                       break;
+               }
+               case PasswordDialog::Incorrect :
+               {
+                       iWindowManager->error( tr( "Incorrect password." ) );
+                       iDevice->handleKeyPresses( true );
+                       break;
+               }
+               default : //case PasswordDialog::Canceled
+               {
+                       iDevice->handleKeyPresses( true );
+               }
+       }
+}
+
+void Engine::progressBarCancelled()
+{
+       //TODO: cancel the on-going event
+       iWindowManager->closeProgressBar();
+       iDevice->handleKeyPresses( true );
+}
index bec1f3b..457d6ba 100644 (file)
@@ -113,6 +113,19 @@ private slots:
         * \param aMeeting The meeting.
         */
        void fetchMeetingDetails( Meeting *aMeeting );
+       //! Slot for receiving the status of the entered password
+       /*!
+        * Slot. Receives the status of the entered password and makes the DeviceManager to change the
+        * operation mode if the password is correct.
+        * \param aPasswordStatus The status of the password.
+        */
+       void passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus );
+       //! Slot for receiving the cancel event of the progress bar.
+       /*!
+        * Slot. Receives the cancel event of the progress bar.
+        */
+       void progressBarCancelled();
+       
 private:
        //! Provides the index of the Meeting instance which is at the specified time.
        /*!
index f3f89dc..e65f714 100644 (file)
@@ -84,6 +84,19 @@ public:
         * \return QString value of the current operation mode.
         */
        QString operationModeToString( OperationMode aMode );
+       //! Connects/disconnects the HWKeyListener signals to the private HWKeyFullScreenPressed() slot.
+       /*!
+        * Connects/disconnects the HWKeyListener signals to the private HWKeyFullScreenPressed() slot. In case
+        * a signal is caught the connection is disabled until the signal handling is finished.
+        * \param aHandle indicates if the signals should be connected or not.
+        */
+       void handleKeyPresses( bool aHandle );
+       //! Changes the operation mode.
+       /*!
+        * Changes the operation mode.
+        * \param aChange To indicate if the mode should be changed or not
+        */
+       void changeMode( bool aChange );
 
 signals:
        //! Signal. Emitted if user tries to change the operation mode.
@@ -100,14 +113,6 @@ signals:
         */
        void error( int aCode, const QString &aAddInfo );
 
-public slots:
-       //! Slot. Changes the operation mode.
-       /*!
-        * Slot. Changes the operation mode.
-        * \param aChange To indicate if the mode should be changed or not
-        */
-       void changeMode( bool aChange );
-
 private slots:
        //! Slot. Handles "full screen"-hardware key presses.
        /*!
@@ -148,13 +153,6 @@ private:
         * \return True if operation mode storing and deactivation of the init script succeed; otherwise, false.
         */
        bool finalizeStandAloneMode();
-       //! Connects/disconnects the HWKeyListener signals to the private HWKeyFullScreenPressed() slot.
-       /*!
-        * Connects/disconnects the HWKeyListener signals to the private HWKeyFullScreenPressed() slot. In case
-        * a signal is caught the connection is disabled until the signal handling is finished.
-        * \param aHandle indicates if the signals should be connected or not.
-        */
-       void handleKeyPresses( bool aHandle );
 
 private:
        AlarmSender *iAlarmSender;
index 3a8590f..778d32a 100644 (file)
@@ -13,12 +13,6 @@ PasswordDialog::PasswordDialog( const QString &aPassword, const QString &aText,
        setWindowTitle( aTitle.isNull() ? tr( "Enter password" ) : aTitle );
        setModal( true );
 
-       // Store the password hash to iPasswordHash
-       // ( aPassword should be allready encoded )
-//     QCryptographicHash *hash = new QCryptographicHash( QCryptographicHash::Md5 );
-//     hash->addData( aPassword.toUtf8() );
-//     iPasswordHash = hash->result();
-//     delete hash;
        iPasswordHash = aPassword.toUtf8();
 
        /* Create the layout:
@@ -61,13 +55,10 @@ PasswordDialog::PasswordDialog( const QString &aPassword, const QString &aText,
 
        // Enable the layout
        setLayout( layout );
-       
-       show();
 }
 
 PasswordDialog::~PasswordDialog()
 {
-       close();
 }
 
 void PasswordDialog::okButtonPressed()
index 86879c9..686523b 100644 (file)
@@ -27,18 +27,6 @@ public:
                Canceled
        };
 
-       //! Creates a new PasswordDialog instance and shows the dialog on the screen.
-       /*!
-        * Creates a new Password query dialog.
-        * \param aParent The parent object.
-        * \param aPassword The password.
-        * \param aText Optional. Text displayed in the dialog.
-        * \param aTitle Optional. Dialog title, defaults to "Enter password".
-        * \return The instance which was created.
-       static PasswordDialog * query( QWidget *aParent, const QString &aPassword,
-                                                const QString &aText = 0, const QString &aTitle = 0 );
-                                                */
-
 signals:
        //! Signals the authenticity of the password when the uuser dismisses the dialog.
        /*!
diff --git a/src/UserInterface/Utils/ProgressBar.cpp b/src/UserInterface/Utils/ProgressBar.cpp
new file mode 100755 (executable)
index 0000000..a43098d
--- /dev/null
@@ -0,0 +1,34 @@
+#include "ProgressBar.h"
+
+#include <QProgressBar>
+#include <QBoxLayout>
+#include <QPushButton>
+
+ProgressBar::ProgressBar( const QString &aText, QWidget *aParent ) :
+       QDialog( aParent )
+{
+       setWindowTitle( aText );
+       setModal( true );
+
+       iProgress = new QProgressBar();
+       iProgress->setMinimumWidth( 200 );
+       iProgress->setMaximum( 0 );
+       iProgress->setTextVisible( false );
+
+       QBoxLayout* layout = new QBoxLayout( QBoxLayout::LeftToRight, this );
+       layout->setSizeConstraint( QLayout::SetDefaultConstraint );
+       layout->addWidget( iProgress, 0, Qt::AlignHCenter );
+       
+       QPushButton *buttonCancel = new QPushButton( tr( "Cancel" ) );
+       layout->addSpacing( 5 );
+       layout->addWidget( buttonCancel );
+       
+       connect( buttonCancel, SIGNAL( pressed() ), this, SIGNAL( cancel() ) );
+       connect( iProgress, SIGNAL( valueChanged( int ) ), this, SIGNAL( started() ) );
+       
+       setLayout( layout );
+}
+
+ProgressBar::~ProgressBar()
+{
+}
diff --git a/src/UserInterface/Utils/ProgressBar.h b/src/UserInterface/Utils/ProgressBar.h
new file mode 100755 (executable)
index 0000000..a247cf3
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef PROGRESSBAR_H_
+#define PROGRESSBAR_H_
+
+#include <QDialog>
+
+class QProgressBar;
+
+//! UserInterface class.
+/*!
+ * UserInterface class which launches a modal progress bar during application events that might take
+ * some time
+ */
+class ProgressBar : public QDialog
+{
+       Q_OBJECT
+
+public:
+       //! Constructor.
+       /*!
+        * Constructor to initialize the StatusWidget instance.
+        * \param aParent Parent object.
+        * \param aText Title string to be set to the progress bar.
+        */
+       ProgressBar( const QString &aText, QWidget *aParent = 0 );
+       //! Destructor.
+       virtual ~ProgressBar();
+
+signals:
+       //! Signal. Emitted if user presses cancel button.
+       /*!
+        * Signal. Emitted if user presses cancel button.
+        */
+       void cancel();
+       void started();
+
+private:
+       QProgressBar *iProgress;
+
+};
+
+#endif /*PROGRESSBAR_H_*/
index 8107fbb..3a593a9 100644 (file)
@@ -160,53 +160,34 @@ void WindowManager::error( const QString &aErrorMessage )
        PopUpMessageBox::error( 0, aErrorMessage );
 }
 
-void WindowManager::passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus )
-{
-       delete iPasswordDialog;
-       iPasswordDialog = 0;
-       
-       switch ( aPasswordStatus )
-       {
-               case PasswordDialog::Correct :
-               {
-                       progressBar( tr( "Changing operation mode" ), true );
-                       iProgressBar->show();
-                       while(1);
-                       break;
-               }
-               case PasswordDialog::Incorrect :
-               {
-                       error( tr( "Incorrect password." ) );
-                       break;
-               }
-               default : //case PasswordDialog::Canceled
-               {
-               }
-       }
-}
-
 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();
 }
 
+void WindowManager::closePasswordDialog()
+{
+       iPasswordDialog->close();
+       delete iPasswordDialog;
+       iPasswordDialog = 0;
+}
 
-void WindowManager::progressBar( const QString &aText, bool aStart )
+void WindowManager::showProgressBar( const QString &aText )
 {
-       qDebug() << "WindowManager::progressBar( const QString &, bool)";
-       if( aStart ) {
-               if( iProgressBar == 0 ) {
-                       iProgressBar = new ProgressBar( aText );
-                       connect( iProgressBar, SIGNAL( cancel() ), this, SLOT( progressBar() ) );
-                       connect( iProgressBar, SIGNAL( started() ), this, SLOT( changeMode() ) );
-               }
-       }
-       else {
-               if( iProgressBar != 0 ) {
-                       delete iProgressBar;
-                       iProgressBar = 0;
-               }
+       qDebug() << "WindowManager::showProgressBar( const QString & )";
+       if( iProgressBar == 0 ) {
+               iProgressBar = new ProgressBar( aText );
+               iProgressBar->show();
+               connect( iProgressBar, SIGNAL( cancel() ), this, SIGNAL( progressBarCancelled() ) );
        }
 }
 
+void WindowManager::closeProgressBar()
+{
+       iProgressBar->close();
+       delete iProgressBar;
+       iProgressBar = 0;
+}
index 0c85515..6a56e77 100644 (file)
@@ -57,6 +57,11 @@ public:
         * \param aMessage The message to be shown in the password dialog.\r
         */\r
        void showPasswordDialog( QByteArray aAdminPassword, const QString &aMessage );\r
+       //! Closes the password dialog.\r
+       /*!\r
+        * Closes the password dialog.\r
+        */\r
+       void closePasswordDialog();\r
        //! Displays the weekly view.\r
        /*!\r
         * Displays the weekly view.\r
@@ -78,6 +83,17 @@ public:
         * Switches the views to full screen.\r
         */\r
        void fullScreen();\r
+       //! Shows the progress bar.\r
+       /*!\r
+        * Starts showing the progress bar.\r
+        * \param aText The text to be shown in progress bar.\r
+        */\r
+       void showProgressBar( const QString &aText );\r
+       //! Closes the progress bar.\r
+       /*!\r
+        * Closes the progress bar.\r
+        */\r
+       void closeProgressBar();\r
        \r
        void insertMeeting( Meeting *aMeeting );\r
        \r
@@ -113,6 +129,17 @@ signals:
         * \param aRoom Selected meeting room.\r
         */\r
        void currentRoomChanged( Room *aRoom );\r
+       //! Signals when the password dialog buttons are clicked.\r
+       /*!\r
+        * Signal is emitted when the password dialog buttons are clicked.\r
+        * \param aPasswordStatus The status of the password.\r
+        */\r
+       void passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus );\r
+       //! Signals when the cancel button in the progress bar is clicked.\r
+       /*!\r
+        * Signal is emitted when the cancel button in the progress bar is clicked.\r
+        */\r
+       void progressBarCancelled();\r
        \r
 public slots:\r
        //! Slot for displaying the screensaver (room status view).\r
@@ -130,20 +157,6 @@ public slots:
 private slots:\r
        //! Displays the settings view\r
        void showSettingsView();\r
-       //! Slot for receiving the status of the entered password\r
-       /*!\r
-        * Slot. Receives the status of the entered password and makes the DeviceManager to change the\r
-        * operation mode if the password is correct.\r
-        * \param aPasswordStatus The status of the password.\r
-        */\r
-       void passwordEntered( PasswordDialog::PasswordStatus aPasswordStatus );\r
-       //! Slot for showing/hiding the progress bar.\r
-       /*!\r
-        * Slot. Starts showing or hides the progress bar.\r
-        * \param aText The text to be shown in progress bar.\r
-        * \param aStart to indicate whether the progress bar is wanted to shown or hidden\r
-        */\r
-       void progressBar( const QString &aText = "", bool aStart = false );\r
 \r
 private:\r
        //! Name of the application.\r