phoneapp/phoneuiqtviewadapter/src/phonenotecontroller.cpp
branchGCC_SURGE
changeset 51 f39ed5e045e0
parent 30 ebdbd102c78a
parent 46 bc5a64e5bc3c
equal deleted inserted replaced
40:bab96b7ed1a4 51:f39ed5e045e0
    20 #include "phoneresourceadapter.h"
    20 #include "phoneresourceadapter.h"
    21 #include "qtphonelog.h"
    21 #include "qtphonelog.h"
    22 #include <QSignalMapper>
    22 #include <QSignalMapper>
    23 #include <QTimer>
    23 #include <QTimer>
    24 #include <hbdevicemessagebox.h>
    24 #include <hbdevicemessagebox.h>
       
    25 #include <hbdevicenotificationdialog.h>
    25 #include <hbdeviceprogressdialog.h>
    26 #include <hbdeviceprogressdialog.h>
    26 #include <hbmessagebox.h>
    27 #include <hbmessagebox.h>
    27 #include <hbprogressdialog.h>
    28 #include <hbprogressdialog.h>
    28 #include <hbaction.h>
    29 #include <hbaction.h>
    29 #include <phoneappcommands.hrh>
    30 #include <phoneappcommands.hrh>
    30   
    31 #include <hbstringutil.h>
       
    32 
    31 PhoneNoteController::PhoneNoteController(QObject *parent) : 
    33 PhoneNoteController::PhoneNoteController(QObject *parent) : 
    32     QObject(parent), m_timer(0), m_progressDialog(0), m_dtmfNote(0), 
    34     QObject(parent), m_timer(0), m_progressDialog(0), m_dtmfNote(0), 
    33     m_queryNote(0), m_queryCanceledCommand(-1), m_timeoutCommand(-1)
    35     m_queryNote(0), m_queryCanceledCommand(-1), m_timeoutCommand(-1)
    34 {
    36 {
    35     PHONE_DEBUG("PhoneNoteController::PhoneNoteController");
    37     PHONE_DEBUG("PhoneNoteController::PhoneNoteController");
    51     Q_ASSERT (commandParam->ParamId () == TPhoneCommandParam::EPhoneParamIdGlobalNote);
    53     Q_ASSERT (commandParam->ParamId () == TPhoneCommandParam::EPhoneParamIdGlobalNote);
    52 
    54 
    53     TPhoneCmdParamGlobalNote* globalNoteParam = 
    55     TPhoneCmdParamGlobalNote* globalNoteParam = 
    54         static_cast<TPhoneCmdParamGlobalNote*>( commandParam );
    56         static_cast<TPhoneCmdParamGlobalNote*>( commandParam );
    55     
    57     
    56         
    58     if (globalNoteParam->NotificationDialog()) {
       
    59         showDeviceNotificationDialog(globalNoteParam);
       
    60     } else {
       
    61         showDeviceMessageBox(globalNoteParam);
       
    62     }
       
    63     
       
    64 }
       
    65 
       
    66 void PhoneNoteController::showNote(TPhoneCommandParam *commandParam)
       
    67 {
       
    68     PHONE_DEBUG("PhoneNoteController::showNote");
       
    69 
       
    70     TPhoneCmdParamNote* noteParam = static_cast<TPhoneCmdParamNote*>(
       
    71             commandParam );
       
    72     
       
    73     if ( noteParam->Type() == EPhoneNoteDtmfSending ) {
       
    74         showDtmfNote(noteParam);
       
    75     }
       
    76         
       
    77 }
       
    78 
       
    79 void PhoneNoteController::showQuery(TPhoneCommandParam *commandParam)
       
    80 {
       
    81     PHONE_DEBUG("PhoneNoteController::showQuery");
       
    82     TPhoneCmdParamQuery& params = *static_cast<TPhoneCmdParamQuery*>( commandParam );
       
    83 
       
    84     if ( EPhoneQueryDialog == params.QueryType() && 
       
    85          params.QueryPrompt().Length() ) {
       
    86         showDefaultQuery(&params);
       
    87        
       
    88     } else if ( EPhoneGlobalWaitNote == params.QueryType() ) {
       
    89         showGlobalWaitNote(&params);
       
    90         
       
    91     }
       
    92 
       
    93         
       
    94 }
       
    95 
       
    96 void PhoneNoteController::removeDtmfNote()
       
    97 {
       
    98     PHONE_DEBUG("PhoneNoteController::removeDtmfNote"); 
       
    99     if (m_dtmfNote) {
       
   100         m_dtmfNote->close();
       
   101     }
       
   102 }
       
   103 
       
   104 void PhoneNoteController::removeNote()
       
   105 {
       
   106     PHONE_DEBUG("PhoneNoteController::removeNote"); 
       
   107     removeDtmfNote();
       
   108 }
       
   109 
       
   110 void PhoneNoteController::removeQuery()
       
   111 {
       
   112     PHONE_DEBUG("PhoneNoteController::removeQuery"); 
       
   113     if (m_queryNote) {
       
   114         m_queryNote->close();
       
   115     }
       
   116 }
       
   117 
       
   118 void PhoneNoteController::removeGlobalWaitNote()
       
   119 {
       
   120     PHONE_DEBUG("PhoneNoteController::removeGlobalWaitNote"); 
       
   121     if (m_timer) {
       
   122         m_timeoutCommand = -1;
       
   123         m_timer->stop();
       
   124     }
       
   125     
       
   126     if (m_progressDialog) {
       
   127         m_queryCanceledCommand = -1;
       
   128         m_progressDialog->close();
       
   129     }
       
   130 }
       
   131 
       
   132 void PhoneNoteController::destroyDialog()
       
   133 {
       
   134     PHONE_DEBUG("PhoneNoteController::destroyDialog"); 
       
   135     HbDeviceMessageBox *messageBox = m_messageBoxList.takeFirst();
       
   136     messageBox->deleteLater();
       
   137     messageBox = 0;
       
   138     
       
   139     if ( 0 < m_messageBoxList.size() ) {
       
   140         PHONE_DEBUG("PhoneNoteController::show pending note");
       
   141         HbDeviceMessageBox *messageBoxTemp = m_messageBoxList[0];
       
   142         QObject::connect(messageBoxTemp, SIGNAL(aboutToClose()), 
       
   143                          this, SLOT(destroyDialog()));
       
   144         messageBoxTemp->show();
       
   145     }
       
   146 }
       
   147 
       
   148 void PhoneNoteController::destroyNotification()
       
   149 {
       
   150     PHONE_DEBUG("PhoneNoteController::destroyDialog"); 
       
   151     HbDeviceNotificationDialog *notification = m_notificationList.takeFirst();
       
   152     notification->deleteLater();
       
   153     notification = 0;
       
   154     
       
   155     if ( 0 < m_notificationList.size() ) {
       
   156         PHONE_DEBUG("PhoneNoteController::show pending note");
       
   157         HbDeviceNotificationDialog *notificationTemp = m_notificationList[0];
       
   158         QObject::connect(notificationTemp, SIGNAL(aboutToClose()), 
       
   159                          this, SLOT(destroyNotification()));
       
   160         notificationTemp->show();
       
   161     }
       
   162 }
       
   163 
       
   164 void PhoneNoteController::removeMappings()
       
   165 {
       
   166     foreach (HbAction *action, m_actions ) {
       
   167         m_signalMapper->removeMappings(action);
       
   168     }
       
   169     m_actions.clear();
       
   170     
       
   171     if (m_dtmfNote) {
       
   172         m_dtmfNote->deleteLater();
       
   173         m_dtmfNote = 0;
       
   174     }
       
   175     if (m_queryNote) {
       
   176         m_queryNote->deleteLater();
       
   177         m_queryNote = 0;
       
   178     }
       
   179     if (m_progressDialog) {
       
   180         m_progressDialog->deleteLater();
       
   181         m_progressDialog = 0;
       
   182     }
       
   183 }
       
   184 
       
   185 void PhoneNoteController::queryCancelled()
       
   186 {
       
   187     if (m_timer) {
       
   188         m_timer->stop();
       
   189     }
       
   190     
       
   191     if (m_queryCanceledCommand != -1) {
       
   192         emit command(m_queryCanceledCommand);
       
   193     }
       
   194     m_queryCanceledCommand = -1;
       
   195     m_timeoutCommand = -1;
       
   196 }
       
   197 
       
   198 void PhoneNoteController::queryTimeout()
       
   199 {
       
   200     int sendCommand = m_timeoutCommand;
       
   201     if (m_progressDialog) {
       
   202         m_queryCanceledCommand = -1;
       
   203         m_progressDialog->close();
       
   204     }
       
   205     if (sendCommand != -1) {        
       
   206         emit command(sendCommand);
       
   207     }
       
   208 }
       
   209 
       
   210 QString PhoneNoteController::globalNoteText(
       
   211         TPhoneCommandParam *commandParam)
       
   212 {
       
   213     TPhoneCmdParamGlobalNote* globalNoteParam = 
       
   214         static_cast<TPhoneCmdParamGlobalNote*>( commandParam );
       
   215     
       
   216     QString ret;    
       
   217     
       
   218     if ( globalNoteParam->TextResourceId() && 
       
   219          KErrNone != globalNoteParam->Text().Compare( KNullDesC() ) ) {
       
   220          // resource and text exists
       
   221          ret = PhoneResourceAdapter::Instance()->convertToStringWithParam(
       
   222                      globalNoteParam->TextResourceId(),
       
   223                      QString::fromUtf16(globalNoteParam->Text().Ptr(), 
       
   224                                      globalNoteParam->Text().Length()) );         
       
   225     } else if ( globalNoteParam->TextResourceId() ) {
       
   226         // resource exists
       
   227         QString causeCode;
       
   228         if (-1 != globalNoteParam->CauseCode()) {
       
   229             causeCode.setNum(globalNoteParam->CauseCode());
       
   230             causeCode = HbStringUtil::convertDigits(causeCode);
       
   231         }
       
   232         
       
   233         ret = PhoneResourceAdapter::Instance()->convertToString(
       
   234                     globalNoteParam->TextResourceId(), causeCode);
       
   235 
       
   236     } else if ( KErrNone != globalNoteParam->Text().Compare( KNullDesC() ) ) {
       
   237         // text exists
       
   238         ret = QString::fromUtf16(globalNoteParam->Text().Ptr(), 
       
   239                 globalNoteParam->Text().Length());
       
   240     }
       
   241     
       
   242     return ret;
       
   243 }
       
   244 
       
   245 void PhoneNoteController::showDtmfNote(TPhoneCmdParamNote* noteParam)
       
   246 {    
       
   247     if (m_dtmfNote) {
       
   248         m_dtmfNote->setText( QString::fromUtf16(noteParam->Text().Ptr(), 
       
   249                 noteParam->Text().Length()) );
       
   250         m_dtmfNote->update();
       
   251     } else {
       
   252         QList<HbAction*> hbactions = PhoneResourceAdapter::Instance()->
       
   253             convertToHbActions(noteParam->ResourceId());
       
   254 
       
   255         if (hbactions.count() > 0) {
       
   256             m_dtmfNote = new HbProgressDialog(HbProgressDialog::ProgressDialog);
       
   257             m_dtmfNote->setText( QString::fromUtf16(noteParam->Text().Ptr(), 
       
   258                     noteParam->Text().Length()) ); 
       
   259                   
       
   260             connect(hbactions.at(0), SIGNAL(triggered()), m_signalMapper, SLOT(map()));
       
   261 
       
   262             int count = m_dtmfNote->actions().count();
       
   263             for (int i=count;0<i;i--) {
       
   264                 QAction *action = m_dtmfNote->actions().at(i-1);
       
   265                 m_dtmfNote->removeAction(action);
       
   266                 //TODO
       
   267                 //delete action;
       
   268             }
       
   269             m_dtmfNote->addAction(hbactions.at(0));
       
   270             m_signalMapper->setMapping(hbactions.at(0), hbactions.at(0)->data().toInt());
       
   271             
       
   272             QObject::connect(m_dtmfNote, SIGNAL(aboutToClose()), 
       
   273                              this, SLOT(removeMappings())); 
       
   274             
       
   275             m_actions.append(hbactions.at(0));
       
   276       
       
   277             m_dtmfNote->show();
       
   278         }
       
   279     }
       
   280 }
       
   281 
       
   282 void PhoneNoteController::showDefaultQuery(TPhoneCmdParamQuery* params)
       
   283 {    
       
   284     if (!m_queryNote) {
       
   285         QList<HbAction*> hbactions = PhoneResourceAdapter::Instance()->
       
   286             convertToHbActions(params->QueryResourceId());
       
   287         
       
   288         if (hbactions.count() > 0) {
       
   289             m_queryNote = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
       
   290             m_queryNote->setTimeout(HbPopup::NoTimeout);
       
   291             m_queryNote->setDismissPolicy(HbPopup::NoDismiss);
       
   292             m_queryNote->setText(QString::fromUtf16(params->QueryPrompt().Ptr(), 
       
   293                     params->QueryPrompt().Length()));
       
   294             
       
   295             QObject::connect(m_queryNote, SIGNAL(aboutToClose()), 
       
   296                              this, SLOT(removeMappings())); 
       
   297                             
       
   298             for (int i = 0; i < hbactions.count(); ++i) {
       
   299                 connect(hbactions.at(i), SIGNAL(triggered()), m_signalMapper, SLOT(map()));
       
   300                 m_signalMapper->setMapping(hbactions.at(i), hbactions.at(i)->data().toInt());
       
   301                 m_actions.append(hbactions.at(i));
       
   302             }
       
   303             
       
   304             int count = m_queryNote->actions().count();
       
   305             for (int i=count;0<i;i--) {
       
   306                 QAction *action = m_queryNote->actions().at(i-1);
       
   307                 m_queryNote->removeAction(action);
       
   308                 //TODO
       
   309                 //delete action;
       
   310             }
       
   311             
       
   312             for (int i=0;i<hbactions.count();i++) {
       
   313                 m_queryNote->addAction(hbactions.at(i));
       
   314             }
       
   315             
       
   316             m_queryNote->show();
       
   317         }
       
   318     }
       
   319 }
       
   320 
       
   321 void PhoneNoteController::showGlobalWaitNote(TPhoneCmdParamQuery* params)
       
   322 {    
       
   323     if (!m_progressDialog) {        
       
   324         m_queryCanceledCommand = params->CbaCommandMapping(EAknSoftkeyCancel);
       
   325 
       
   326         m_progressDialog = new HbDeviceProgressDialog(HbProgressDialog::WaitDialog);
       
   327         
       
   328         if (params->QueryPrompt().Length()) {
       
   329             m_progressDialog->setText(QString::fromUtf16(params->QueryPrompt().Ptr(), 
       
   330                     params->QueryPrompt().Length()));
       
   331         } else if (0 != params->DataText()) {
       
   332             m_progressDialog->setText(QString::fromUtf16(params->DataText()->Ptr(), 
       
   333                     params->DataText()->Length()));
       
   334         }
       
   335         
       
   336         QObject::connect(m_progressDialog, SIGNAL(aboutToClose()), 
       
   337                          this, SLOT(removeMappings())); 
       
   338         
       
   339         QObject::connect(m_progressDialog, SIGNAL(cancelled()), 
       
   340                          this, SLOT(queryCancelled())); 
       
   341         
       
   342         if (params->TimeOut() != 0) {
       
   343             if (!m_timer) {
       
   344                 m_timer = new QTimer();
       
   345                 m_timer->setSingleShot(true);
       
   346                 connect(m_timer, SIGNAL(timeout()), SLOT(queryTimeout()));
       
   347             }           
       
   348             
       
   349             m_timeoutCommand = -1;
       
   350             int customCommand;
       
   351             if (-1 != params->GetCustomCommandForTimeOut(customCommand)) {
       
   352                 m_timeoutCommand = customCommand;
       
   353             }
       
   354             
       
   355             m_timer->start(params->TimeOut());
       
   356         }
       
   357         
       
   358         m_progressDialog->show();
       
   359     }
       
   360 }
       
   361 
       
   362 void PhoneNoteController::showDeviceMessageBox(
       
   363         TPhoneCmdParamGlobalNote* params)
       
   364 {
       
   365     PHONE_DEBUG("PhoneNoteController::showDeviceMessageBox");
       
   366 
    57     HbMessageBox::MessageBoxType type;
   367     HbMessageBox::MessageBoxType type;
    58     
   368         
    59     switch( globalNoteParam->Type() ) {
   369     switch( params->Type() ) {
    60     case EAknGlobalInformationNote:
   370     case EAknGlobalInformationNote:
    61         type = HbMessageBox::MessageTypeInformation;
   371         type = HbMessageBox::MessageTypeInformation;
    62         break;
   372         break;
    63     case EAknGlobalWarningNote:
   373     case EAknGlobalWarningNote:
    64     default:
   374     default:
    65         type = HbMessageBox::MessageTypeWarning;
   375         type = HbMessageBox::MessageTypeWarning;
    66         break;
   376         break;
    67     }
   377     }
    68     
   378     
    69     QString noteString = globalNoteText(globalNoteParam);
   379     QString noteString = globalNoteText(params);
    70     
   380     
    71     if (false == noteString.isNull()) {
   381     if (false == noteString.isNull()) {
    72         bool showNote(true);
   382         bool showNote(true);
    73         for (int i = 0; i < m_messageBoxList.count(); ++i) {
   383         for (int i = 0; i < m_messageBoxList.count(); ++i) {
    74             // Do not show same note/text several times, e.g when user hits
   384             // Do not show same note/text several times, e.g when user hits
    82         
   392         
    83         if (showNote) {
   393         if (showNote) {
    84             QScopedPointer<HbDeviceMessageBox> messageBox( 
   394             QScopedPointer<HbDeviceMessageBox> messageBox( 
    85                 new HbDeviceMessageBox(noteString, type));
   395                 new HbDeviceMessageBox(noteString, type));
    86             
   396             
    87             int timeout = globalNoteParam->Timeout();
   397             int timeout = params->Timeout();
    88             if (timeout == 0) {
   398             if (timeout <= 0) {
    89                 messageBox->setTimeout(HbDialog::StandardTimeout);
   399                 messageBox->setTimeout(HbDialog::StandardTimeout);
    90             } else {
   400             } else {
    91                 messageBox->setTimeout(timeout);
   401                 messageBox->setTimeout(timeout);
    92             }
   402             }
    93             
   403             
    99                 QObject::connect(messageBoxPtr, SIGNAL(aboutToClose()), 
   409                 QObject::connect(messageBoxPtr, SIGNAL(aboutToClose()), 
   100                                  this, SLOT(destroyDialog()));
   410                                  this, SLOT(destroyDialog()));
   101                 messageBoxPtr->show();
   411                 messageBoxPtr->show();
   102             }
   412             }
   103         }
   413         }
   104     }
   414     }    
   105 }
   415 }
   106 
   416 
   107 void PhoneNoteController::showNote(TPhoneCommandParam *commandParam)
   417 void PhoneNoteController::showDeviceNotificationDialog(
   108 {
   418         TPhoneCmdParamGlobalNote* params)
   109     PHONE_DEBUG("PhoneNoteController::showNote");
   419 {
   110 
   420     PHONE_DEBUG("PhoneNoteController::showDeviceNotificationDialog");
   111     TPhoneCmdParamNote* noteParam = static_cast<TPhoneCmdParamNote*>(
   421     
   112             commandParam );
   422     QString noteString = globalNoteText(params);
   113     
   423     
   114     if ( noteParam->Type() == EPhoneNoteDtmfSending ) {
   424     if (false == noteString.isNull()) {
   115         showDtmfNote(noteParam);
   425         bool showNote(true);
   116     }
   426         for (int i = 0; i < m_notificationList.count(); ++i) {
   117         
   427             // Do not show same note/text several times, e.g when user hits
   118 }
   428             // the end button several times we should show only one "not allowed"
   119 
   429             // note.
   120 void PhoneNoteController::showQuery(TPhoneCommandParam *commandParam)
   430             if (noteString == m_notificationList.at(i)->title()) {
   121 {
   431                 showNote = false;
   122     PHONE_DEBUG("PhoneNoteController::showQuery");
   432                 break;
   123     TPhoneCmdParamQuery& params = *static_cast<TPhoneCmdParamQuery*>( commandParam );
   433             }
   124 
   434         }
   125     if ( EPhoneQueryDialog == params.QueryType() && 
   435         
   126          params.QueryPrompt().Length() ) {
   436         if (showNote) {
   127         showDefaultQuery(&params);
   437             QScopedPointer<HbDeviceNotificationDialog> notification( 
   128        
   438                 new HbDeviceNotificationDialog());
   129     } else if ( EPhoneGlobalWaitNote == params.QueryType() ) {
   439             
   130         showGlobalWaitNote(&params);
   440             notification->setTitle(noteString);
   131         
   441             
   132     }
   442             int timeout = params->Timeout();
   133 
   443             if (timeout > 0) {
   134         
   444                 // If timeout not set we use default timeout. 
   135 }
   445                 // Default value is HbPopup::StandardTimeout (3000 ms)
   136 
   446                 notification->setTimeout(timeout);
   137 void PhoneNoteController::removeDtmfNote()
   447             }
   138 {
   448             
   139     PHONE_DEBUG("PhoneNoteController::removeDtmfNote"); 
   449             HbDeviceNotificationDialog *notificationPtr = notification.data();
   140     if (m_dtmfNote) {
   450             m_notificationList.append(notificationPtr);
   141         m_dtmfNote->close();
   451             notification.take();
   142     }
   452             
   143 }
   453             if (1 == m_notificationList.size()) {
   144 
   454                 QObject::connect(notificationPtr, SIGNAL(aboutToClose()), 
   145 void PhoneNoteController::removeNote()
   455                                  this, SLOT(destroyNotification()));
   146 {
   456                 notificationPtr->show();
   147     PHONE_DEBUG("PhoneNoteController::removeNote"); 
   457             }
   148     removeDtmfNote();
   458         }
   149 }
   459     }        
   150 
   460 }
   151 void PhoneNoteController::removeQuery()
   461 
   152 {
   462 
   153     PHONE_DEBUG("PhoneNoteController::removeQuery"); 
       
   154     if (m_queryNote) {
       
   155         m_queryNote->close();
       
   156     }
       
   157 }
       
   158 
       
   159 void PhoneNoteController::removeGlobalWaitNote()
       
   160 {
       
   161     PHONE_DEBUG("PhoneNoteController::removeGlobalWaitNote"); 
       
   162     if (m_timer) {
       
   163         m_timeoutCommand = -1;
       
   164         m_timer->stop();
       
   165     }
       
   166     
       
   167     if (m_progressDialog) {
       
   168         m_queryCanceledCommand = -1;
       
   169         m_progressDialog->close();
       
   170     }
       
   171 }
       
   172 
       
   173 void PhoneNoteController::destroyDialog()
       
   174 {
       
   175     PHONE_DEBUG("PhoneNoteController::destroyDialog"); 
       
   176     HbDeviceMessageBox *messageBox = m_messageBoxList.takeFirst();
       
   177     messageBox->deleteLater();
       
   178     messageBox = 0;
       
   179     
       
   180     if ( 0 < m_messageBoxList.size() ) {
       
   181         PHONE_DEBUG("PhoneNoteController::show pending note");
       
   182         HbDeviceMessageBox *messageBoxTemp = m_messageBoxList[0];
       
   183         QObject::connect(messageBoxTemp, SIGNAL(aboutToClose()), 
       
   184                          this, SLOT(destroyDialog()));
       
   185         messageBoxTemp->show();
       
   186     }
       
   187 }
       
   188 
       
   189 void PhoneNoteController::removeMappings()
       
   190 {
       
   191     foreach (HbAction *action, m_actions ) {
       
   192         m_signalMapper->removeMappings(action);
       
   193     }
       
   194     m_actions.clear();
       
   195     
       
   196     if (m_dtmfNote) {
       
   197         m_dtmfNote->deleteLater();
       
   198         m_dtmfNote = 0;
       
   199     }
       
   200     if (m_queryNote) {
       
   201         m_queryNote->deleteLater();
       
   202         m_queryNote = 0;
       
   203     }
       
   204     if (m_progressDialog) {
       
   205         m_progressDialog->deleteLater();
       
   206         m_progressDialog = 0;
       
   207     }
       
   208 }
       
   209 
       
   210 void PhoneNoteController::queryCancelled()
       
   211 {
       
   212     if (m_timer) {
       
   213         m_timer->stop();
       
   214     }
       
   215     
       
   216     if (m_queryCanceledCommand != -1) {
       
   217         emit command(m_queryCanceledCommand);
       
   218     }
       
   219     m_queryCanceledCommand = -1;
       
   220     m_timeoutCommand = -1;
       
   221 }
       
   222 
       
   223 void PhoneNoteController::queryTimeout()
       
   224 {
       
   225     int sendCommand = m_timeoutCommand;
       
   226     if (m_progressDialog) {
       
   227         m_queryCanceledCommand = -1;
       
   228         m_progressDialog->close();
       
   229     }
       
   230     if (sendCommand != -1) {        
       
   231         emit command(sendCommand);
       
   232     }
       
   233 }
       
   234 
       
   235 QString PhoneNoteController::globalNoteText(
       
   236         TPhoneCommandParam *commandParam)
       
   237 {
       
   238     TPhoneCmdParamGlobalNote* globalNoteParam = 
       
   239         static_cast<TPhoneCmdParamGlobalNote*>( commandParam );
       
   240     
       
   241     QString ret;    
       
   242     
       
   243     if ( globalNoteParam->TextResourceId() && 
       
   244          KErrNone != globalNoteParam->Text().Compare( KNullDesC() ) ) {
       
   245          // resource and text exists
       
   246          ret = PhoneResourceAdapter::Instance()->convertToString(
       
   247                      globalNoteParam->TextResourceId(),
       
   248                      QString::fromUtf16(globalNoteParam->Text().Ptr(), 
       
   249                                      globalNoteParam->Text().Length()) );         
       
   250     } else if ( globalNoteParam->TextResourceId() ) {
       
   251         // resource exists
       
   252         ret = PhoneResourceAdapter::Instance()->convertToString(
       
   253                     globalNoteParam->TextResourceId());
       
   254 
       
   255     } else if ( KErrNone != globalNoteParam->Text().Compare( KNullDesC() ) ) {
       
   256         // text exists
       
   257         ret = QString::fromUtf16(globalNoteParam->Text().Ptr(), 
       
   258                 globalNoteParam->Text().Length());
       
   259     }
       
   260     
       
   261     return ret;
       
   262 }
       
   263 
       
   264 void PhoneNoteController::showDtmfNote(TPhoneCmdParamNote* noteParam)
       
   265 {    
       
   266     if (m_dtmfNote) {
       
   267         m_dtmfNote->setText( QString::fromUtf16(noteParam->Text().Ptr(), 
       
   268                 noteParam->Text().Length()) );
       
   269         m_dtmfNote->update();
       
   270     } else {
       
   271         QList<HbAction*> hbactions = PhoneResourceAdapter::Instance()->
       
   272             convertToHbActions(noteParam->ResourceId());
       
   273 
       
   274         if (hbactions.count() > 0) {
       
   275             m_dtmfNote = new HbProgressDialog(HbProgressDialog::ProgressDialog);
       
   276             m_dtmfNote->setText( QString::fromUtf16(noteParam->Text().Ptr(), 
       
   277                     noteParam->Text().Length()) ); 
       
   278                   
       
   279             connect(hbactions.at(0), SIGNAL(triggered()), m_signalMapper, SLOT(map()));
       
   280 
       
   281             int count = m_dtmfNote->actions().count();
       
   282             for (int i=count;0<i;i--) {
       
   283                 QAction *action = m_dtmfNote->actions().at(i-1);
       
   284                 m_dtmfNote->removeAction(action);
       
   285                 //TODO
       
   286                 //delete action;
       
   287             }
       
   288             m_dtmfNote->addAction(hbactions.at(0));
       
   289             m_signalMapper->setMapping(hbactions.at(0), hbactions.at(0)->data().toInt());
       
   290             
       
   291             QObject::connect(m_dtmfNote, SIGNAL(aboutToClose()), 
       
   292                              this, SLOT(removeMappings())); 
       
   293             
       
   294             m_actions.append(hbactions.at(0));
       
   295       
       
   296             m_dtmfNote->show();
       
   297         }
       
   298     }
       
   299 }
       
   300 
       
   301 void PhoneNoteController::showDefaultQuery(TPhoneCmdParamQuery* params)
       
   302 {    
       
   303     if (!m_queryNote) {
       
   304         QList<HbAction*> hbactions = PhoneResourceAdapter::Instance()->
       
   305             convertToHbActions(params->QueryResourceId());
       
   306         
       
   307         if (hbactions.count() > 0) {
       
   308             m_queryNote = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
       
   309             m_queryNote->setTimeout(HbPopup::NoTimeout);
       
   310             m_queryNote->setDismissPolicy(HbPopup::NoDismiss);
       
   311             m_queryNote->setText(QString::fromUtf16(params->QueryPrompt().Ptr(), 
       
   312                     params->QueryPrompt().Length()));
       
   313             
       
   314             QObject::connect(m_queryNote, SIGNAL(aboutToClose()), 
       
   315                              this, SLOT(removeMappings())); 
       
   316                             
       
   317             for (int i = 0; i < hbactions.count(); ++i) {
       
   318                 connect(hbactions.at(i), SIGNAL(triggered()), m_signalMapper, SLOT(map()));
       
   319                 m_signalMapper->setMapping(hbactions.at(i), hbactions.at(i)->data().toInt());
       
   320                 m_actions.append(hbactions.at(i));
       
   321             }
       
   322             
       
   323             int count = m_queryNote->actions().count();
       
   324             for (int i=count;0<i;i--) {
       
   325                 QAction *action = m_queryNote->actions().at(i-1);
       
   326                 m_queryNote->removeAction(action);
       
   327                 //TODO
       
   328                 //delete action;
       
   329             }
       
   330             
       
   331             for (int i=0;i<hbactions.count();i++) {
       
   332                 m_queryNote->addAction(hbactions.at(i));
       
   333             }
       
   334             
       
   335             m_queryNote->show();
       
   336         }
       
   337     }
       
   338 }
       
   339 
       
   340 void PhoneNoteController::showGlobalWaitNote(TPhoneCmdParamQuery* params)
       
   341 {    
       
   342     if (!m_progressDialog) {        
       
   343         m_queryCanceledCommand = params->CbaCommandMapping(EAknSoftkeyCancel);
       
   344 
       
   345         m_progressDialog = new HbDeviceProgressDialog(HbProgressDialog::WaitDialog);
       
   346         
       
   347         if (params->QueryPrompt().Length()) {
       
   348             m_progressDialog->setText(QString::fromUtf16(params->QueryPrompt().Ptr(), 
       
   349                     params->QueryPrompt().Length()));
       
   350         } else if (0 != params->DataText()) {
       
   351             m_progressDialog->setText(QString::fromUtf16(params->DataText()->Ptr(), 
       
   352                     params->DataText()->Length()));
       
   353         }
       
   354         
       
   355         QObject::connect(m_progressDialog, SIGNAL(aboutToClose()), 
       
   356                          this, SLOT(removeMappings())); 
       
   357         
       
   358         QObject::connect(m_progressDialog, SIGNAL(cancelled()), 
       
   359                          this, SLOT(queryCancelled())); 
       
   360         
       
   361         if (params->TimeOut() != 0) {
       
   362             if (!m_timer) {
       
   363                 m_timer = new QTimer();
       
   364                 m_timer->setSingleShot(true);
       
   365                 connect(m_timer, SIGNAL(timeout()), SLOT(queryTimeout()));
       
   366             }           
       
   367             
       
   368             m_timeoutCommand = -1;
       
   369             int customCommand;
       
   370             if (-1 != params->GetCustomCommandForTimeOut(customCommand)) {
       
   371                 m_timeoutCommand = customCommand;
       
   372             }
       
   373             
       
   374             m_timer->start(params->TimeOut());
       
   375         }
       
   376         
       
   377         m_progressDialog->show();
       
   378     }
       
   379 }
       
   380 
       
   381