vmbx/vmbxengine/src/vmbxqtuihandler.cpp
branchRCL_3
changeset 20 987c9837762f
parent 19 7d48bed6ce0c
child 21 0a6dd2dc9970
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
     1 /*
       
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 // qt
       
    20 #include <QString>
       
    21 #include <QRegExp>
       
    22 #include <QCoreApplication>
       
    23 #include <hbinputdialog.h>
       
    24 #include <hblabel.h>
       
    25 #include <hbaction.h>
       
    26 #include <hbmessagebox.h>
       
    27 #include <hblineedit.h>
       
    28 #include <hbinputeditorinterface.h>
       
    29 #include <hbinputstandardfilters.h>
       
    30 #include <hbinputfilter.h> 
       
    31 #include <hblistwidget.h>
       
    32 #include <hbnotificationdialog.h>
       
    33 #include <dialogwaiter.h>
       
    34 
       
    35 #include <cvoicemailboxentry.h>
       
    36 #include <cvoicemailbox.h>
       
    37 
       
    38 #include "vmbxqtuihandler.h"
       
    39 #include "voicemailboxdefsinternal.h"
       
    40 #include "vmbxlogger.h"
       
    41 
       
    42 // ======== MEMBER FUNCTIONS ==================================================
       
    43 
       
    44 // ----------------------------------------------------------------------------
       
    45 // VmbxQtUiHandler::VmbxQtUiHandler
       
    46 // (Constructor).
       
    47 // ----------------------------------------------------------------------------
       
    48 //
       
    49 VmbxQtUiHandler::VmbxQtUiHandler(QObject* parent): QObject(parent),
       
    50         iTranslator(0), iCommonTranslator(0), iQueryDialog(NULL)
       
    51 {
       
    52     VMBLOGSTRING("VmbxQtUiHandler::VmbxQtUiHandler")
       
    53     init();
       
    54     VMBLOGSTRING("VmbxQtUiHandler::VmbxQtUiHandler Exit")
       
    55 }
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 // VmbxQtUiHandler::~VmbxQtUiHandler
       
    59 // (Destructor).
       
    60 // ----------------------------------------------------------------------------
       
    61 //
       
    62 VmbxQtUiHandler::~VmbxQtUiHandler()
       
    63 {
       
    64     VMBLOGSTRING("VmbxQtUiHandler::~VmbxQtUiHandler")
       
    65     if ( iQueryDialog ) {
       
    66         delete iQueryDialog;
       
    67         iQueryDialog = NULL;
       
    68         VMBLOGSTRING("VmbxQtUiHandler::~VmbxQtUiHandler delete iQueryDialog")
       
    69     }
       
    70     VMBLOGSTRING("VmbxQtUiHandler::~VmbxQtUiHandler Exit")
       
    71 }
       
    72 
       
    73 // ----------------------------------------------------------------------------
       
    74 // VmbxQtUiHandler::Init
       
    75 //
       
    76 // ----------------------------------------------------------------------------
       
    77 //
       
    78 void  VmbxQtUiHandler::init()
       
    79 {
       
    80     VMBLOGSTRING("VmbxQtUiHandler::init")
       
    81     QString lang = QLocale::system().name();
       
    82     VMBLOGSTRING2("VmbxQtUiHandler::init lang type %S",
       
    83             lang.utf16())
       
    84     QString path = "Z:/resource/qt/translations/";
       
    85     bool translatorLoaded = iTranslator.load("vmbx_"+lang, path);
       
    86     VMBLOGSTRING2("VmbxQtUiHandler::init load vmbx result %d",
       
    87             translatorLoaded)
       
    88     // Install vmbx localization
       
    89     if (translatorLoaded) {
       
    90         VMBLOGSTRING("VmbxQtUiHandler::init qApp !")
       
    91         qApp->installTranslator(&iTranslator);
       
    92     }
       
    93     // Install common localization, for select type "cancel".
       
    94     bool loaded = iCommonTranslator.load( "common_"+lang, path);
       
    95     VMBLOGSTRING2("VmbxQtUiHandler::init load common result %d",
       
    96         loaded)
       
    97     if (loaded) {
       
    98         VMBLOGSTRING("VmbxQtUiHandler::init qApp !!")
       
    99         qApp->installTranslator(&iCommonTranslator);
       
   100     }
       
   101     VMBLOGSTRING("VmbxQtUiHandler::init Exit")
       
   102 }
       
   103 
       
   104 // ----------------------------------------------------------------------------
       
   105 // VmbxQtUiHandler::ShowVmbxQueryDialog
       
   106 // (show query dialog).
       
   107 // ----------------------------------------------------------------------------
       
   108 //
       
   109 void VmbxQtUiHandler::showVmbxQueryDialog(const TVmbxType& aType,
       
   110                           QString& aNumber, int& aResult)
       
   111 {
       
   112     VMBLOGSTRING("VmbxQtUiHandler::showVmbxQueryDialog")
       
   113     QString header;
       
   114     if (EVmbxVoice == aType) {
       
   115         header = hbTrId("txt_vmbx_title_voice_mailbox_number");
       
   116     } else if (EVmbxVideo == aType) {
       
   117         // type of EVmbxVideo
       
   118         header = hbTrId("txt_vmbx_title_video_mailbox_number");
       
   119     } else {
       
   120         aResult = KErrCancel;
       
   121         VMBLOGSTRING( "VmbxQtUiHandler::showVmbxQueryDialog type error" )
       
   122         return;
       
   123     }
       
   124     if (iQueryDialog) {
       
   125         delete iQueryDialog;
       
   126         iQueryDialog = 0;
       
   127     }
       
   128         
       
   129     
       
   130     iQueryDialog = new HbInputDialog();
       
   131     iQueryDialog->setDismissPolicy(HbDialog::NoDismiss);
       
   132     iQueryDialog->setTimeout(HbDialog::NoTimeout);
       
   133 
       
   134     iQueryDialog->setModal(true);
       
   135     // Set heading content
       
   136     iQueryDialog->setPromptText(header);
       
   137 
       
   138     // Set HbLineEdit  Content 
       
   139     iQueryDialog->lineEdit()->setText(aNumber); // default text
       
   140     iQueryDialog->lineEdit()->setMaxLength(KVmbxPhoneCharMaxLength);
       
   141     HbEditorInterface inputMode(iQueryDialog->lineEdit());
       
   142     inputMode.setFilter(HbPhoneNumberFilter::instance());
       
   143     bool ret = connect(iQueryDialog->lineEdit(), SIGNAL(textChanged(QString)),
       
   144         this, SLOT(updatePrimaryAction(QString)));    
       
   145     VMBLOGSTRING2( "VmbxQtUiHandler::showVmbxQueryDialog connect textChanged %d", ret)
       
   146     
       
   147     DialogWaiter waiter;
       
   148     HbAction *primary = 0;
       
   149     if (iQueryDialog->actions().count()>= 1) {
       
   150         primary = qobject_cast<HbAction*>(iQueryDialog->actions().at(0));
       
   151     }
       
   152     
       
   153     iQueryDialog->open(&waiter, SLOT(done(HbAction *)));
       
   154     iQueryDialog->lineEdit()->setFocus(); // Enable the VKB
       
   155     
       
   156     HbAction *result = waiter.wait();
       
   157     if (result == primary) {
       
   158         VMBLOGSTRING( "VmbxQtUiHandler::showVmbxQueryDialog select OK" )
       
   159         // asign OK KEY value
       
   160         aResult = KErrNone;
       
   161         aNumber = iQueryDialog->lineEdit()->text();
       
   162     } else {
       
   163         aResult = KErrCancel;
       
   164     }
       
   165     
       
   166     disconnect(iQueryDialog->lineEdit(), SIGNAL(textChanged(QString)),
       
   167             this, SLOT(updatePrimaryAction(QString))); 
       
   168     
       
   169 
       
   170     // TODO Delete Operation will case panic on EM
       
   171     
       
   172 #ifdef __WINS__
       
   173     iQueryDialog->close();
       
   174 #else
       
   175     delete iQueryDialog;
       
   176     iQueryDialog = 0;
       
   177 #endif // __WINS__
       
   178 
       
   179     VMBLOGSTRING2("VmbxQtUiHandler::showVmbxQueryDialog aResult = %d", aResult)
       
   180     VMBLOGSTRING("VmbxQtUiHandler::showVmbxQueryDialog Exit")
       
   181 }
       
   182 
       
   183 // ----------------------------------------------------------------------------
       
   184 // VmbxQtUiHandler::showDefineSelectionDialog
       
   185 // (Shoe define list dialog).
       
   186 // ----------------------------------------------------------------------------
       
   187 //
       
   188 void VmbxQtUiHandler::showDefineSelectionDialog(
       
   189     TVmbxType &aType, int &aResult)
       
   190 {
       
   191     VMBLOGSTRING("VmbxQtUiHandler::showDefineSelectionDialog")
       
   192     HbDialog* defineListDialog = new HbDialog();
       
   193     defineListDialog->setDismissPolicy(HbDialog::NoDismiss);
       
   194     defineListDialog->setTimeout(HbDialog::NoTimeout);
       
   195 
       
   196     defineListDialog->setModal(true);
       
   197     // Set heading widget,"Define number:"
       
   198     defineListDialog->setHeadingWidget(new HbLabel(
       
   199             hbTrId("txt_vmbx_title_select_mailbox")));
       
   200     // Create a define list 
       
   201     HbListWidget *list = new HbListWidget();
       
   202     //Voice Mailbox
       
   203     list->addItem(hbTrId("txt_vmbx_list_voice_mailbox"));
       
   204     //Video Mailbox
       
   205     list->addItem(hbTrId("txt_vmbx_list_video_mailbox"));
       
   206     // Set content widget
       
   207     defineListDialog->setContentWidget(list);
       
   208 
       
   209     //  Sets the "Cancel"-action/button
       
   210     HbAction *cancelAction = 
       
   211         new HbAction(hbTrId("txt_common_button_cancel"),defineListDialog);
       
   212     defineListDialog->addAction(cancelAction);
       
   213     
       
   214     connect(list, SIGNAL(activated(HbListWidgetItem *)), 
       
   215         defineListDialog, SLOT(close()));
       
   216     DialogWaiter waiter;
       
   217     defineListDialog->open(&waiter, SLOT(done(HbAction *)));
       
   218     HbAction *result = waiter.wait();
       
   219     if (cancelAction == result){
       
   220         aType = EVmbxNone;
       
   221         aResult = KErrCancel;
       
   222     } else {
       
   223         // Select one item
       
   224         aResult = KErrNone;
       
   225         int currentItem = list->row(list->currentItem());
       
   226         VMBLOGSTRING2("VmbxQtUiHandler::showDefineSelectionDialog:\
       
   227             currentItem %d", currentItem)
       
   228         if (0 == currentItem) {
       
   229             aType = EVmbxVoice;
       
   230         } else {
       
   231             aType = EVmbxVideo;
       
   232         }
       
   233     }
       
   234     VMBLOGSTRING2("VmbxQtUiHandler::showDefineSelectionDialog: aType%d", aType)
       
   235     VMBLOGSTRING2("VmbxQtUiHandler::showDefineSelectionDialog: aResult%d", \
       
   236         aResult)
       
   237         
       
   238 #ifdef __WINS__
       
   239     defineListDialog->close();
       
   240 #else
       
   241     delete defineListDialog;
       
   242     defineListDialog = 0;
       
   243 #endif // __WINS__  
       
   244 
       
   245     VMBLOGSTRING("VmbxQtUiHandler::showDefineSelectionDialog Exit")
       
   246 }
       
   247 
       
   248 // ----------------------------------------------------------------------------
       
   249 // VmbxQtUiHandler::showCallSelectionDialog
       
   250 // (show call selection dialog).
       
   251 // ----------------------------------------------------------------------------
       
   252 //
       
   253 void VmbxQtUiHandler::showCallSelectionDialog(
       
   254     const QList<CVoiceMailboxEntry *> entryList,
       
   255     TVoiceMailboxParams &params, int &result )
       
   256 {
       
   257     VMBLOGSTRING("VmbxQtUiHandler::showCallSelectionDialog")
       
   258     int count = entryList.count();
       
   259     VMBLOGSTRING("VmbxQtUiHandler::showCallSelectionDialog new before")
       
   260     HbDialog* callListDialog = new HbDialog();
       
   261     VMBLOGSTRING("VmbxQtUiHandler::showCallSelectionDialog new after")
       
   262     callListDialog->setDismissPolicy(HbDialog::NoDismiss);
       
   263     callListDialog->setTimeout(HbDialog::NoTimeout);
       
   264     callListDialog->setModal(true);
       
   265     // Set heading widget,"select mailbox"
       
   266     callListDialog->setHeadingWidget(new HbLabel(
       
   267                hbTrId("txt_vmbx_title_select_mailbox")));
       
   268     // Create a call list 
       
   269     HbListWidget *list = new HbListWidget();
       
   270     // Set content widget
       
   271     callListDialog->setContentWidget(list);
       
   272 
       
   273     QList<TVoiceMailboxParams> paramsList;
       
   274     TVoiceMailboxParams entryParams;
       
   275     for (int i = 0; i < count; i++) {
       
   276         TVmbxType vmbxType = entryList[i]->VoiceMailboxType();
       
   277         entryParams.iType = vmbxType;
       
   278         entryParams.iServiceId = entryList[i]->ServiceId();
       
   279         paramsList.append(entryParams);
       
   280         switch (vmbxType) {
       
   281             case EVmbxVoice:
       
   282                 {
       
   283                 list->addItem(hbTrId("txt_vmbx_list_voice_mailbox"));
       
   284                 break;
       
   285                 }
       
   286             case EVmbxVideo:
       
   287                 {
       
   288                 list->addItem(hbTrId("txt_vmbx_list_video_mailbox"));
       
   289                 break;
       
   290                 }
       
   291             case EVmbxVoip:
       
   292                 {
       
   293                 // Get name
       
   294                 TPtrC vmbxName( KNullDesC );
       
   295                 int voipRes = entryList[i]->GetVmbxName(vmbxName);
       
   296                 VMBLOGSTRING2( "VmbxQtUiHandler::showCallSelectionDialogL\
       
   297                     : voipRes=%I", voipRes );
       
   298                 if (KErrNone == voipRes) {
       
   299                     QString voipName;
       
   300                     if (vmbxName.Length() > 0) {
       
   301                         voipName=QString::fromUtf16(
       
   302                             vmbxName.Ptr(), vmbxName.Length());
       
   303                         // add voip item
       
   304                         list->addItem(voipName);
       
   305                     }
       
   306                 }
       
   307                 break;
       
   308                 }
       
   309             default:
       
   310                 break;
       
   311         }
       
   312     }
       
   313     //  Sets the "Cancel"-action/button
       
   314     HbAction *cancelAction = 
       
   315         new HbAction(hbTrId("txt_common_button_cancel"),callListDialog);
       
   316     callListDialog->addAction(cancelAction);
       
   317     
       
   318     connect(list, SIGNAL(activated(HbListWidgetItem *)), 
       
   319             callListDialog, SLOT(close()));
       
   320     DialogWaiter waiter;
       
   321     callListDialog->open(&waiter, SLOT(done(HbAction *)));
       
   322     HbAction *action = waiter.wait();
       
   323     if (cancelAction == action){
       
   324         params.iType = EVmbxNone;
       
   325         params.iServiceId = KVmbxServiceIdNone;
       
   326         result = KErrCancel;
       
   327     } else {
       
   328         // Select one item
       
   329         result = KErrNone;
       
   330         int currentItem = list->row(list->currentItem());
       
   331         VMBLOGSTRING2("VmbxQtUiHandler::showCallSelectionDialog:\
       
   332             currentItem %d", currentItem)
       
   333         params.iType = paramsList[currentItem].iType;
       
   334         params.iServiceId = paramsList[currentItem].iServiceId;
       
   335     }
       
   336     VMBLOGSTRING2("VmbxQtUiHandler::showCallSelectionDialog: params.iType %d",
       
   337         params.iType)
       
   338     VMBLOGSTRING2("VmbxQtUiHandler::showCallSelectionDialog: result%d",
       
   339         result)
       
   340     
       
   341 #ifdef __WINS__
       
   342     callListDialog->close();
       
   343 #else
       
   344     delete callListDialog;
       
   345     callListDialog = 0;
       
   346 #endif // __WINS__  
       
   347     VMBLOGSTRING("VmbxQtUiHandler::showCallSelectionDialog Exit")
       
   348 }
       
   349 
       
   350 // ----------------------------------------------------------------------------
       
   351 // VmbxQtUiHandler::showInformationNote
       
   352 // (show information note).
       
   353 // ----------------------------------------------------------------------------
       
   354 //
       
   355 void VmbxQtUiHandler::showInformationNote(const TVmbxNoteType aType)
       
   356 {
       
   357     VMBLOGSTRING("VmbxQtUiHandler::showInformationNote")
       
   358     QString noteText;
       
   359     VMBLOGSTRING2("VmbxQtUiHandler::showInformationNote type =%d", aType)
       
   360     switch (aType) {
       
   361     case EInvalidNumber:
       
   362         // Need to comfirm with ui designer
       
   363         noteText = hbTrId("Invalid phone number.");
       
   364         break;
       
   365     case ENotAllowUserEditing:
       
   366         //User not allow to edit.
       
   367         noteText = hbTrId("Number not provisioned");
       
   368         break;
       
   369     case ESavedToPhoneMemory:
       
   370     case ESavedToSimMemory:	
       
   371         //Voice mailbox number saved to Phone memory.
       
   372         noteText = hbTrId("txt_vmbx_dpopinfo_voice_mailbox_number_saved");
       
   373         break;
       
   374     case EVideoNumberSaved:
       
   375         //Video call mailbox saved.
       
   376         noteText = hbTrId("txt_vmbx_dpopinfo_video_mailbox_number_saved");
       
   377         break;
       
   378     case EDefineVoiceNumber:
       
   379         //Define voice mailbox.
       
   380         noteText = hbTrId("txt_vmbx_dpopinfo_define_voice_mailbox_number");
       
   381         break;
       
   382     case EDefineVideoNumber:
       
   383         //Define video mailbox.
       
   384         noteText = hbTrId("txt_vmbx_dpopinfo_define_video_mailbox_number");
       
   385         break;
       
   386     default:
       
   387         VMBLOGSTRING("VmbxQtUiHandler::ShowInformationNote default")
       
   388         break;
       
   389     }
       
   390     HbNotificationDialog::launchDialog(noteText);
       
   391     VMBLOGSTRING("VmbxQtUiHandler::showInformationNote Exit")
       
   392 }
       
   393 
       
   394 // ----------------------------------------------------------------------------
       
   395 // VmbxQtUiHandler::updatePrimaryAction
       
   396 // (show information note).
       
   397 // ----------------------------------------------------------------------------
       
   398 //
       
   399 void VmbxQtUiHandler::updatePrimaryAction(const QString &aInput)
       
   400 {
       
   401     if (iQueryDialog) {    
       
   402         QAction *ok = iQueryDialog->actions().at(0);
       
   403         if (ok) {
       
   404             if ( aInput.isEmpty() || aInput.contains(QRegExp("\\d\\d\\d"))){
       
   405                 if (!ok->isEnabled()){
       
   406                     ok->setEnabled(true);
       
   407                     VMBLOGSTRING("VmbxQtUiHandler::updatePrimaryAction enable OK")
       
   408                 }
       
   409             } else {
       
   410                 if (ok->isEnabled()){
       
   411                     ok->setEnabled(false);
       
   412                     VMBLOGSTRING("VmbxQtUiHandler::updatePrimaryAction disable OK")  
       
   413                 }
       
   414             }
       
   415         }
       
   416     }
       
   417 }
       
   418 
       
   419 //End of file