phoneapp/phoneuiqtviewadapter/src/phonenotecontroller.cpp
changeset 72 c76a0b1755b9
parent 56 5bcb308bd24d
child 76 cfea66083b62
--- a/phoneapp/phoneuiqtviewadapter/src/phonenotecontroller.cpp	Thu Sep 02 20:26:16 2010 +0300
+++ b/phoneapp/phoneuiqtviewadapter/src/phonenotecontroller.cpp	Fri Sep 17 08:29:19 2010 +0300
@@ -15,15 +15,13 @@
 */
 
 #include "phonenotecontroller.h"
+#include "phoneglobalnotes.h"
 #include "tphonecmdparamglobalnote.h"
 #include "tphonecmdparamquery.h"
 #include "phoneresourceadapter.h"
 #include "qtphonelog.h"
 #include <QSignalMapper>
 #include <QTimer>
-#include <hbdevicemessagebox.h>
-#include <hbdevicenotificationdialog.h>
-#include <hbdeviceprogressdialog.h>
 #include <hbmessagebox.h>
 #include <hbprogressdialog.h>
 #include <hbaction.h>
@@ -31,42 +29,40 @@
 #include <hbstringutil.h>
 
 PhoneNoteController::PhoneNoteController(QObject *parent) : 
-    QObject(parent), m_timer(0), m_progressDialog(0), m_dtmfNote(0), 
-    m_queryNote(0), m_queryCanceledCommand(-1), m_timeoutCommand(-1)
+    QObject(parent), 
+    m_dtmfNote(0),
+    m_queryNote(0)
 {
-    PHONE_DEBUG("PhoneNoteController::PhoneNoteController");
+    PHONE_TRACE
     m_signalMapper = new QSignalMapper(this);
     connect(m_signalMapper, SIGNAL(mapped(int)), this, SIGNAL(command (int)));
+    m_globalNotes = new PhoneGlobalNotes(this);
+    connect(m_globalNotes, SIGNAL(command(int)), this, SIGNAL(command(int)));
 }
 
 PhoneNoteController::~PhoneNoteController()
 {
-    PHONE_DEBUG("PhoneNoteController::~PhoneNoteController");
-    if (m_timer) {
-        delete m_timer;
-    }
+    PHONE_TRACE
 }
 
 void PhoneNoteController::showGlobalNote(TPhoneCommandParam *commandParam)
 {
-    PHONE_DEBUG("PhoneNoteController::showGlobalNote");
     Q_ASSERT (commandParam->ParamId () == TPhoneCommandParam::EPhoneParamIdGlobalNote);
 
     TPhoneCmdParamGlobalNote* globalNoteParam = 
         static_cast<TPhoneCmdParamGlobalNote*>( commandParam );
     
     if (globalNoteParam->NotificationDialog()) {
-        showDeviceNotificationDialog(globalNoteParam);
+        m_globalNotes->showDeviceNotificationDialog(globalNoteParam);
     } else {
-        showDeviceMessageBox(globalNoteParam);
+        m_globalNotes->showDeviceMessageBox(globalNoteParam);
     }
     
 }
 
 void PhoneNoteController::showNote(TPhoneCommandParam *commandParam)
 {
-    PHONE_DEBUG("PhoneNoteController::showNote");
-
+    PHONE_TRACE
     TPhoneCmdParamNote* noteParam = static_cast<TPhoneCmdParamNote*>(
             commandParam );
     
@@ -78,7 +74,7 @@
 
 void PhoneNoteController::showQuery(TPhoneCommandParam *commandParam)
 {
-    PHONE_DEBUG("PhoneNoteController::showQuery");
+    PHONE_TRACE
     TPhoneCmdParamQuery& params = *static_cast<TPhoneCmdParamQuery*>( commandParam );
 
     if ( EPhoneQueryDialog == params.QueryType() && 
@@ -86,14 +82,13 @@
         showDefaultQuery(&params);
        
     } else if ( EPhoneGlobalWaitNote == params.QueryType() ) {
-        showGlobalWaitNote(&params);
-        
+        m_globalNotes->showGlobalWaitNote(&params);
     }
 }
 
 void PhoneNoteController::removeDtmfNote()
 {
-    PHONE_DEBUG("PhoneNoteController::removeDtmfNote"); 
+    PHONE_TRACE
     if (m_dtmfNote) {
         m_dtmfNote->close();
     }
@@ -101,13 +96,13 @@
 
 void PhoneNoteController::removeNote()
 {
-    PHONE_DEBUG("PhoneNoteController::removeNote"); 
+    PHONE_TRACE
     removeDtmfNote();
 }
 
 void PhoneNoteController::removeQuery()
 {
-    PHONE_DEBUG("PhoneNoteController::removeQuery"); 
+    PHONE_TRACE
     if (m_queryNote) {
         m_queryNote->close();
     }
@@ -115,52 +110,13 @@
 
 void PhoneNoteController::removeGlobalWaitNote()
 {
-    PHONE_DEBUG("PhoneNoteController::removeGlobalWaitNote"); 
-    if (m_timer) {
-        m_timeoutCommand = -1;
-        m_timer->stop();
-    }
-    
-    if (m_progressDialog) {
-        m_queryCanceledCommand = -1;
-        m_progressDialog->close();
-    }
-}
-
-void PhoneNoteController::destroyDialog()
-{
-    PHONE_DEBUG("PhoneNoteController::destroyDialog"); 
-    HbDeviceMessageBox *messageBox = m_messageBoxList.takeFirst();
-    messageBox->deleteLater();
-    messageBox = 0;
-    
-    if ( 0 < m_messageBoxList.size() ) {
-        PHONE_DEBUG("PhoneNoteController::show pending note");
-        HbDeviceMessageBox *messageBoxTemp = m_messageBoxList[0];
-        QObject::connect(messageBoxTemp, SIGNAL(aboutToClose()), 
-                         this, SLOT(destroyDialog()));
-        messageBoxTemp->show();
-    }
-}
-
-void PhoneNoteController::destroyNotification()
-{
-    PHONE_DEBUG("PhoneNoteController::destroyDialog"); 
-    HbDeviceNotificationDialog *notification = m_notificationList.takeFirst();
-    notification->deleteLater();
-    notification = 0;
-    
-    if ( 0 < m_notificationList.size() ) {
-        PHONE_DEBUG("PhoneNoteController::show pending note");
-        HbDeviceNotificationDialog *notificationTemp = m_notificationList[0];
-        QObject::connect(notificationTemp, SIGNAL(aboutToClose()), 
-                         this, SLOT(destroyNotification()));
-        notificationTemp->show();
-    }
+    PHONE_TRACE
+    m_globalNotes->removeGlobalWaitNote();
 }
 
 void PhoneNoteController::removeMappings()
 {
+    PHONE_TRACE
     foreach (HbAction *action, m_actions ) {
         m_signalMapper->removeMappings(action);
     }
@@ -174,74 +130,11 @@
         m_queryNote->deleteLater();
         m_queryNote = 0;
     }
-    if (m_progressDialog) {
-        m_progressDialog->deleteLater();
-        m_progressDialog = 0;
-    }
-}
-
-void PhoneNoteController::queryCancelled()
-{
-    if (m_timer) {
-        m_timer->stop();
-    }
-    
-    if (m_queryCanceledCommand != -1) {
-        emit command(m_queryCanceledCommand);
-    }
-    m_queryCanceledCommand = -1;
-    m_timeoutCommand = -1;
-}
-
-void PhoneNoteController::queryTimeout()
-{
-    int sendCommand = m_timeoutCommand;
-    if (m_progressDialog) {
-        m_queryCanceledCommand = -1;
-        m_progressDialog->close();
-    }
-    if (sendCommand != -1) {        
-        emit command(sendCommand);
-    }
-}
-
-QString PhoneNoteController::globalNoteText(
-        TPhoneCommandParam *commandParam)
-{
-    TPhoneCmdParamGlobalNote* globalNoteParam = 
-        static_cast<TPhoneCmdParamGlobalNote*>( commandParam );
-    
-    QString ret;    
-    
-    if ( globalNoteParam->TextResourceId() && 
-         KErrNone != globalNoteParam->Text().Compare( KNullDesC() ) ) {
-         // resource and text exists
-         ret = PhoneResourceAdapter::Instance()->convertToStringWithParam(
-                     globalNoteParam->TextResourceId(),
-                     QString::fromUtf16(globalNoteParam->Text().Ptr(), 
-                                     globalNoteParam->Text().Length()) );         
-    } else if ( globalNoteParam->TextResourceId() ) {
-        // resource exists
-        QString causeCode;
-        if (-1 != globalNoteParam->CauseCode()) {
-            causeCode.setNum(globalNoteParam->CauseCode());
-            causeCode = HbStringUtil::convertDigits(causeCode);
-        }
-        
-        ret = PhoneResourceAdapter::Instance()->convertToString(
-                    globalNoteParam->TextResourceId(), causeCode);
-
-    } else if ( KErrNone != globalNoteParam->Text().Compare( KNullDesC() ) ) {
-        // text exists
-        ret = QString::fromUtf16(globalNoteParam->Text().Ptr(), 
-                globalNoteParam->Text().Length());
-    }
-    
-    return ret;
 }
 
 void PhoneNoteController::showDtmfNote(TPhoneCmdParamNote* noteParam)
-{    
+{
+    PHONE_TRACE
     if (m_dtmfNote) {
         m_dtmfNote->setText( QString::fromUtf16(noteParam->Text().Ptr(), 
                 noteParam->Text().Length()) );
@@ -252,25 +145,14 @@
 
         if (hbactions.count() > 0) {
             m_dtmfNote = new HbProgressDialog(HbProgressDialog::ProgressDialog);
+            m_dtmfNote->setParent(this);
             m_dtmfNote->setText( QString::fromUtf16(noteParam->Text().Ptr(), 
                     noteParam->Text().Length()) ); 
-                  
-            connect(hbactions.at(0), SIGNAL(triggered()), m_signalMapper, SLOT(map()));
-
-            int count = m_dtmfNote->actions().count();
-            for (int i=count;0<i;i--) {
-                QAction *action = m_dtmfNote->actions().at(i-1);
-                m_dtmfNote->removeAction(action);
-                //TODO
-                //delete action;
-            }
-            m_dtmfNote->addAction(hbactions.at(0));
-            m_signalMapper->setMapping(hbactions.at(0), hbactions.at(0)->data().toInt());
             
             QObject::connect(m_dtmfNote, SIGNAL(aboutToClose()), 
                              this, SLOT(removeMappings())); 
             
-            m_actions.append(hbactions.at(0));
+            replaceDialogActions(m_dtmfNote, hbactions);
       
             m_dtmfNote->show();
         }
@@ -278,13 +160,15 @@
 }
 
 void PhoneNoteController::showDefaultQuery(TPhoneCmdParamQuery* params)
-{    
+{
+    PHONE_TRACE
     if (!m_queryNote) {
         QList<HbAction*> hbactions = PhoneResourceAdapter::Instance()->
             convertToHbActions(params->QueryResourceId());
         
         if (hbactions.count() > 0) {
             m_queryNote = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
+            m_queryNote->setParent(this);
             m_queryNote->setTimeout(HbPopup::NoTimeout);
             m_queryNote->setDismissPolicy(HbPopup::NoDismiss);
             m_queryNote->setText(QString::fromUtf16(params->QueryPrompt().Ptr(), 
@@ -292,169 +176,31 @@
             
             QObject::connect(m_queryNote, SIGNAL(aboutToClose()), 
                              this, SLOT(removeMappings())); 
-                            
-            for (int i = 0; i < hbactions.count(); ++i) {
-                connect(hbactions.at(i), SIGNAL(triggered()), m_signalMapper, SLOT(map()));
-                m_signalMapper->setMapping(hbactions.at(i), hbactions.at(i)->data().toInt());
-                m_actions.append(hbactions.at(i));
-            }
             
-            int count = m_queryNote->actions().count();
-            for (int i=count;0<i;i--) {
-                QAction *action = m_queryNote->actions().at(i-1);
-                m_queryNote->removeAction(action);
-                //TODO
-                //delete action;
-            }
-            
-            for (int i=0;i<hbactions.count();i++) {
-                m_queryNote->addAction(hbactions.at(i));
-            }
+            replaceDialogActions(m_queryNote, hbactions);
             
             m_queryNote->show();
         }
     }
 }
 
-void PhoneNoteController::showGlobalWaitNote(TPhoneCmdParamQuery* params)
-{    
-    if (!m_progressDialog) {        
-        m_queryCanceledCommand = params->CbaCommandMapping(EAknSoftkeyCancel);
-
-        m_progressDialog = new HbDeviceProgressDialog(HbProgressDialog::WaitDialog);
-        
-        if (params->QueryPrompt().Length()) {
-            m_progressDialog->setText(QString::fromUtf16(params->QueryPrompt().Ptr(), 
-                    params->QueryPrompt().Length()));
-        } else if (0 != params->DataText()) {
-            m_progressDialog->setText(QString::fromUtf16(params->DataText()->Ptr(), 
-                    params->DataText()->Length()));
-        }
-        
-        QObject::connect(m_progressDialog, SIGNAL(aboutToClose()), 
-                         this, SLOT(removeMappings())); 
-        
-        QObject::connect(m_progressDialog, SIGNAL(cancelled()), 
-                         this, SLOT(queryCancelled())); 
-        
-        if (params->TimeOut() != 0) {
-            if (!m_timer) {
-                m_timer = new QTimer();
-                m_timer->setSingleShot(true);
-                connect(m_timer, SIGNAL(timeout()), SLOT(queryTimeout()));
-            }           
-            
-            m_timeoutCommand = -1;
-            int customCommand;
-            if (-1 != params->GetCustomCommandForTimeOut(customCommand)) {
-                m_timeoutCommand = customCommand;
-            }
-            
-            m_timer->start(params->TimeOut());
-        }
-        
-        m_progressDialog->show();
+void PhoneNoteController::replaceDialogActions(
+        HbDialog *dialog, QList<HbAction *> &actions)
+{
+    PHONE_TRACE
+    // Remove default actions
+    foreach (QAction *action, dialog->actions()) {
+        dialog->removeAction(action);
+        delete action;
+    }
+    
+    // Add new actions
+    foreach (HbAction *newAction, actions) {
+        newAction->setParent(m_queryNote);
+        connect(newAction, SIGNAL(triggered()), m_signalMapper, SLOT(map()));
+        m_signalMapper->setMapping(newAction, newAction->data().toInt());
+        m_actions.append(newAction);
+        dialog->addAction(newAction);
     }
 }
 
-void PhoneNoteController::showDeviceMessageBox(
-        TPhoneCmdParamGlobalNote* params)
-{
-    PHONE_DEBUG("PhoneNoteController::showDeviceMessageBox");
-
-    HbMessageBox::MessageBoxType type;
-        
-    switch( params->Type() ) {
-    case EPhoneMessageBoxInformation:
-        type = HbMessageBox::MessageTypeInformation;
-        break;
-    case EPhoneMessageBoxWarning:
-    default:
-        type = HbMessageBox::MessageTypeWarning;
-        break;
-    }
-    
-    QString noteString = globalNoteText(params);
-    
-    if (false == noteString.isNull()) {
-        bool showNote(true);
-        for (int i = 0; i < m_messageBoxList.count(); ++i) {
-            // Do not show same note/text several times, e.g when user hits
-            // the end button several times we should show only one "not allowed"
-            // note.
-            if (noteString == m_messageBoxList.at(i)->text()) {
-                showNote = false;
-                break;
-            }
-        }
-        
-        if (showNote) {
-            QScopedPointer<HbDeviceMessageBox> messageBox( 
-                new HbDeviceMessageBox(noteString, type));
-            
-            int timeout = params->Timeout();
-            if (timeout <= 0) {
-                messageBox->setTimeout(HbDialog::StandardTimeout);
-            } else {
-                messageBox->setTimeout(timeout);
-            }
-            
-            HbDeviceMessageBox *messageBoxPtr = messageBox.data();
-            m_messageBoxList.append(messageBoxPtr);
-            messageBox.take();
-            
-            if (1 == m_messageBoxList.size()) {
-                QObject::connect(messageBoxPtr, SIGNAL(aboutToClose()), 
-                                 this, SLOT(destroyDialog()));
-                messageBoxPtr->show();
-            }
-        }
-    }    
-}
-
-void PhoneNoteController::showDeviceNotificationDialog(
-        TPhoneCmdParamGlobalNote* params)
-{
-    PHONE_DEBUG("PhoneNoteController::showDeviceNotificationDialog");
-    
-    QString noteString = globalNoteText(params);
-    
-    if (false == noteString.isNull()) {
-        bool showNote(true);
-        for (int i = 0; i < m_notificationList.count(); ++i) {
-            // Do not show same note/text several times, e.g when user hits
-            // the end button several times we should show only one "not allowed"
-            // note.
-            if (noteString == m_notificationList.at(i)->title()) {
-                showNote = false;
-                break;
-            }
-        }
-        
-        if (showNote) {
-            QScopedPointer<HbDeviceNotificationDialog> notification( 
-                new HbDeviceNotificationDialog());
-            
-            notification->setTitle(noteString);
-            
-            int timeout = params->Timeout();
-            if (timeout > 0) {
-                // If timeout not set we use default timeout. 
-                // Default value is HbPopup::StandardTimeout (3000 ms)
-                notification->setTimeout(timeout);
-            }
-            
-            HbDeviceNotificationDialog *notificationPtr = notification.data();
-            m_notificationList.append(notificationPtr);
-            notification.take();
-            
-            if (1 == m_notificationList.size()) {
-                QObject::connect(notificationPtr, SIGNAL(aboutToClose()), 
-                                 this, SLOT(destroyNotification()));
-                notificationPtr->show();
-            }
-        }
-    }        
-}
-
-