cellular/psuinotes/src/psuinotes.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 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 #include <hbdevicemessagebox.h>
       
    18 #include <hbdevicenotificationdialog.h>
       
    19 #include <HbDeviceProgressDialog>
       
    20 #include <hblistview.h>
       
    21 #include <hbdialog.h>
       
    22 #include <hblabel.h>
       
    23 #include <hbaction.h>
       
    24 #include <hbmessagebox.h>
       
    25 #include <hbnotificationdialog.h>
       
    26 #include <QStandardItemModel>
       
    27 #include <QItemSelectionModel>
       
    28 #include <hbstringutil.h>
       
    29 #include <hbextendedlocale.h>
       
    30 #include <HbInputDialog>
       
    31 #include <HbEditorInterface>
       
    32 #include <hbinputdef.h>
       
    33 #include <hbinputstandardfilters.h>
       
    34 #include <xqserviceutil.h>
       
    35 #include <QApplication>
       
    36 #include <QTranslator>
       
    37 #include <Qt>
       
    38 
       
    39 #include "psuinotes.h"
       
    40 #include "psuiutils.h"
       
    41 #include "psuilogging.h"
       
    42 #include "psuilocalisation.h"
       
    43 
       
    44 /*!
       
    45   PsUiNotes::instance.
       
    46  */
       
    47 PsUiNotes* PsUiNotes::instance()
       
    48 {
       
    49     DPRINT << ": IN";
       
    50   
       
    51     static PsUiNotes theInstance;
       
    52     
       
    53     DPRINT << ", instance address: " << reinterpret_cast<int>(&theInstance);
       
    54     return &theInstance;
       
    55 }
       
    56  
       
    57 /*!
       
    58   PsUiNotes::PsUiNotes.
       
    59  */
       
    60 PsUiNotes::PsUiNotes(): 
       
    61      QObject(NULL), 
       
    62      m_notesQueue(NULL),
       
    63      m_isNoteShowingOngoing(false),
       
    64      m_passwordDialog(NULL),
       
    65      m_passwordValidator(NULL)
       
    66     {
       
    67     DPRINT << ": IN";
       
    68 
       
    69     m_notesQueue = new QQueue<QObject*>();
       
    70     
       
    71     m_psuiSettings = new PsUiSettingsWrapper();
       
    72  
       
    73     // Localization file loading 
       
    74     m_localisation = new PsUiLocalisation(this); 
       
    75        
       
    76     // Install required translations
       
    77     m_localisation->installTranslator(
       
    78            PsUiLocalisation::
       
    79            TranslationFileCommon);
       
    80     m_localisation->installTranslator(
       
    81            PsUiLocalisation::
       
    82            TranslationFileTelephoneCp);
       
    83     DPRINT << ": OUT";
       
    84     }
       
    85 
       
    86 /*!
       
    87   PsUiNotes::~PsUiNotes.
       
    88  */
       
    89 PsUiNotes::~PsUiNotes()
       
    90 {
       
    91     DPRINT << ": IN";
       
    92 
       
    93     delete m_localisation;
       
    94  
       
    95     qDeleteAll(*m_notesQueue);
       
    96     
       
    97     delete m_psuiSettings;
       
    98     
       
    99     delete m_notesQueue;
       
   100         
       
   101     DPRINT << ": OUT";
       
   102 }
       
   103 
       
   104 /*!
       
   105   PsUiNotes::showGlobalProgressNote.
       
   106  */
       
   107 void PsUiNotes::showGlobalProgressNote(
       
   108     int &noteId, const QString& text)
       
   109 {
       
   110     DPRINT << ": IN";
       
   111     
       
   112     HbDeviceProgressDialog *note = 
       
   113         new HbDeviceProgressDialog(HbProgressDialog::WaitDialog, this);
       
   114     note->setText(text);
       
   115     
       
   116     if(hbTrId("txt_common_info_requesting") == text){
       
   117         QAction *action = new QAction(hbTrId("txt_common_button_hide"), note);
       
   118         note->setAction(action, HbDeviceProgressDialog::CancelButtonRole );
       
   119     }
       
   120     
       
   121     noteId = reinterpret_cast<int>(note);
       
   122     DPRINT << ", NOTEID: " << noteId;
       
   123     QObject::connect(
       
   124         note, SIGNAL(aboutToClose()),
       
   125         this, SLOT(activeNoteAboutToClose()));
       
   126     QObject::connect(
       
   127         note, SIGNAL(cancelled()),
       
   128         this, SLOT(handleProgressNoteCanceled()));
       
   129     m_notesQueue->enqueue(note);    
       
   130     launchNextNoteIfReady();
       
   131     
       
   132     DPRINT << ": OUT";
       
   133 }
       
   134     
       
   135 /*!
       
   136   PsUiNotes::showGlobalNote.
       
   137  */
       
   138 void PsUiNotes::showGlobalNote(int &noteId, const QString& text, 
       
   139     HbMessageBox::MessageBoxType messageBoxType)
       
   140 {
       
   141     DPRINT << ": IN";
       
   142 
       
   143     HbDeviceMessageBox *note
       
   144         = new HbDeviceMessageBox(text, messageBoxType, this);
       
   145     if (messageBoxType == HbMessageBox::MessageTypeQuestion ||
       
   146         messageBoxType == HbMessageBox::MessageTypeInformation) {
       
   147         note->setTimeout(HbPopup::ConfirmationNoteTimeout);
       
   148     }
       
   149     else {
       
   150         note->setTimeout(0);
       
   151     }
       
   152     noteId = reinterpret_cast<int>(note);
       
   153     DPRINT << ", NOTEID: " << noteId;
       
   154     
       
   155     QObject::connect(
       
   156         note, SIGNAL(aboutToClose()),
       
   157         this, SLOT(activeNoteAboutToClose()));
       
   158     
       
   159     m_notesQueue->enqueue(note);
       
   160     launchNextNoteIfReady();
       
   161     
       
   162     DPRINT << ": OUT";
       
   163 }
       
   164 
       
   165 
       
   166 /*!
       
   167   PsUiNotes::cancelNote.
       
   168  */
       
   169 void PsUiNotes::cancelNote(int noteId)
       
   170 {
       
   171     DPRINT << ": IN";
       
   172     
       
   173     if (!m_notesQueue->isEmpty()) {
       
   174         QObject *note = m_notesQueue->head();
       
   175         if(note == reinterpret_cast<QObject *>(noteId)) {
       
   176             int index = m_notesQueue->indexOf(reinterpret_cast<QObject *>(noteId));
       
   177             Q_ASSERT(-1 < index);
       
   178             QObject *note = m_notesQueue->at(index);
       
   179             DPRINT << ": NOTEID: " << noteId;
       
   180             if (qobject_cast<HbDeviceProgressDialog *>(note)) {
       
   181                 static_cast<HbDeviceProgressDialog *>(note)->close();
       
   182             } else if (qobject_cast<HbDeviceMessageBox *>(note)) {
       
   183                 static_cast<HbDeviceMessageBox *>(note)->close();
       
   184             } else {
       
   185                 DPRINT << ", UNKNOWN NOTE";
       
   186                 Q_ASSERT(false);
       
   187             }
       
   188         }
       
   189         else {
       
   190             DPRINT << ": remove from queue, noteId: " << noteId;
       
   191             m_notesQueue->removeOne(reinterpret_cast<QObject *>(noteId));
       
   192         }
       
   193     }
       
   194     
       
   195     DPRINT << ": OUT";
       
   196 }
       
   197 
       
   198 /*!
       
   199   PsUiNotes::noteShowing.
       
   200  */
       
   201 bool PsUiNotes::noteShowing()
       
   202 {
       
   203     return !m_notesQueue->isEmpty();
       
   204 }
       
   205 
       
   206 /*!
       
   207   PsUiNotes::showGlobalErrorNote.
       
   208  */
       
   209 void PsUiNotes::showGlobalErrorNote(int &noteId, int errorcode)
       
   210 {
       
   211     DPRINT << ": IN";
       
   212     
       
   213     QString errorText = "";
       
   214     PsUiUtils::errorCodeTextMapping(errorcode, errorText);
       
   215 
       
   216     HbDeviceMessageBox *note 
       
   217         = new HbDeviceMessageBox(errorText, HbMessageBox::MessageTypeWarning, this);
       
   218     note->setTimeout(0);
       
   219     noteId = reinterpret_cast<int>(note);
       
   220     DPRINT << ", NOTEID: " << noteId;
       
   221     QObject::connect(
       
   222         note, SIGNAL(aboutToClose()),
       
   223         this, SLOT(activeNoteAboutToClose()));
       
   224     m_notesQueue->enqueue(note);
       
   225     launchNextNoteIfReady();
       
   226     
       
   227     DPRINT << ": OUT";
       
   228 } 
       
   229 
       
   230 /*!
       
   231   PsUiNotes::showCallDivertDetails.
       
   232  */
       
   233 void PsUiNotes::showCallDivertDetails(
       
   234     const QList<PSCallDivertingStatus*> &divertingStatusList)
       
   235 {
       
   236     DPRINT << ": IN";
       
   237     
       
   238     DPRINT << ": Status " << divertingStatusList.first()->iStatus;
       
   239     DPRINT << ": ServiceGroup " << divertingStatusList.first()->iServiceGroup;
       
   240     
       
   241     QString status;
       
   242     QString content;
       
   243     
       
   244     switch( divertingStatusList.first()->iStatus )
       
   245         {
       
   246         case DivertingStatusActive:   
       
   247             formatActiveDivertsNoteText(divertingStatusList,content);
       
   248             break;
       
   249         case DivertingStatusInactive:
       
   250         case DivertingStatusNotRegistered:
       
   251             status.append(hbTrId("txt_phone_dpopinfo_divert_not_active")); 
       
   252             break;
       
   253         case DivertingStatusNotProvisioned:
       
   254             status.append(hbTrId("txt_phone_info_not_allowed"));
       
   255             break;
       
   256         case DivertingStatusUnknown:
       
   257         default:
       
   258             status.append(hbTrId("txt_phone_info_request_not_completed"));
       
   259             break;
       
   260         } 
       
   261     if (divertingStatusList.first()->iStatus != DivertingStatusActive) {
       
   262         showGlobalNotificationDialog(status);
       
   263     }
       
   264     else {     
       
   265         HbDeviceMessageBox * note = 
       
   266             new HbDeviceMessageBox(content, HbMessageBox::MessageTypeQuestion, this);
       
   267         note->setIconVisible(EFalse);
       
   268         note->setTimeout(0);
       
   269         HbAction *backAction = 
       
   270             new HbAction(hbTrId("txt_common_button_close_singledialog") );
       
   271         note->setAction(backAction, HbDeviceMessageBox::AcceptButtonRole );
       
   272         note->setAction(NULL, HbDeviceMessageBox::RejectButtonRole);
       
   273         
       
   274         QObject::connect(
       
   275             note, SIGNAL(aboutToClose()),
       
   276             this, SLOT(activeNoteAboutToClose()));
       
   277         
       
   278         m_notesQueue->enqueue(note);
       
   279         launchNextNoteIfReady();      
       
   280     }
       
   281  
       
   282     DPRINT << ": OUT";
       
   283 }
       
   284 
       
   285 /*!
       
   286   PsUiNotes::showPasswordQueryDialog.
       
   287  */
       
   288 void PsUiNotes::showPasswordQueryDialog(
       
   289     const QString &title, 
       
   290     const QValidator &validator,
       
   291     int maxPasswordLength)
       
   292 {
       
   293     DPRINT << ": IN";
       
   294     
       
   295     QScopedPointer<HbInputDialog> passwordDialog(new HbInputDialog());
       
   296     
       
   297     // configure editor so that only digits can be inputted
       
   298     passwordDialog->setPromptText(title);
       
   299     passwordDialog->setEchoMode(HbLineEdit::Password);
       
   300     passwordDialog->setInputMethodHints(Qt::ImhDigitsOnly);
       
   301     passwordDialog->actions().at(0)->setEnabled(false);
       
   302     
       
   303     HbLineEdit *hbLineEdit = passwordDialog->lineEdit();
       
   304     hbLineEdit->setMaxLength(maxPasswordLength);
       
   305     
       
   306     HbEditorInterface editorInterface(hbLineEdit);
       
   307     editorInterface.setMode(HbInputModeNumeric);
       
   308     editorInterface.setInputConstraints(HbEditorConstraintFixedInputMode);
       
   309     editorInterface.setFilter(HbDigitsOnlyFilter::instance());
       
   310     
       
   311     m_passwordValidator = &validator;
       
   312     
       
   313     connect(
       
   314         hbLineEdit, SIGNAL(contentsChanged()), 
       
   315         this, SLOT(passwordTextChanged()));
       
   316     
       
   317     passwordDialog->open(this, SLOT(finishedPasswordQueryDialog(HbAction*)));
       
   318     if(m_passwordDialog) {
       
   319         m_passwordDialog->deleteLater();
       
   320         m_passwordDialog = NULL;
       
   321     }
       
   322     m_passwordDialog = passwordDialog.take();
       
   323     m_passwordDialog->setParent(this);
       
   324     DPRINT << ": OUT";
       
   325 }
       
   326 
       
   327 /*!
       
   328   PsUiNotes::finishedPasswordQueryDialog.
       
   329  */
       
   330 void PsUiNotes::finishedPasswordQueryDialog(HbAction* action)
       
   331 {
       
   332     bool ok;
       
   333     QString password;
       
   334     if(m_passwordDialog) {
       
   335         if (action == m_passwordDialog->actions().at(1)) {
       
   336             ok = false;
       
   337         } else {
       
   338             ok = true;
       
   339             password = m_passwordDialog->value().toString();
       
   340         }
       
   341         
       
   342         disconnect(
       
   343             m_passwordDialog->lineEdit(), SIGNAL(contentsChanged()), 
       
   344             this, SLOT(passwordTextChanged()));
       
   345         
       
   346         m_passwordDialog->deleteLater();
       
   347         m_passwordDialog = NULL;
       
   348         m_passwordValidator = NULL;
       
   349         
       
   350         emit passwordQueryCompleted(password, ok);
       
   351     }
       
   352 }
       
   353 
       
   354 /*!
       
   355   PsUiNotes::formatPhoneNumber.
       
   356   Formats phone number according to locale specific rules.
       
   357  */
       
   358 QString PsUiNotes::formatPhoneNumber(QString number) const
       
   359 {
       
   360     DPRINT << ": IN";
       
   361     
       
   362     QString formattedNumber = number;
       
   363     
       
   364     if (m_psuiSettings->numberGroupingSupported() == true) {
       
   365          //TODO: utilize HbNumberGrouping API when available
       
   366     }
       
   367     
       
   368     // TODO: digit conversion e.g. into arabic-indic
       
   369 //    HbExtendedLocale locale = HbExtendedLocale::system();
       
   370 //    HbStringUtil::convertDigitsTo(formattedNumber, ArabicIndicDigit);
       
   371     
       
   372     DPRINT << ": OUT";
       
   373 
       
   374     return formattedNumber;
       
   375 }
       
   376 
       
   377 /*!
       
   378   PsUiNotes::launchNextNoteIfReady.
       
   379  */
       
   380 void PsUiNotes::launchNextNoteIfReady()
       
   381 {
       
   382     DPRINT << ": IN";
       
   383     
       
   384     if (m_notesQueue->isEmpty()) {
       
   385         DPRINT << ", QUEUE EMPTY";
       
   386         return;
       
   387     }
       
   388     if (!m_isNoteShowingOngoing) {
       
   389         m_isNoteShowingOngoing = true;
       
   390         // note is left in the queue so that it can be cancelled at request
       
   391         QObject *note = m_notesQueue->head();
       
   392         DPRINT << ", note: " << reinterpret_cast<int>(note);
       
   393         if (qobject_cast<HbDeviceProgressDialog *>(note)) {
       
   394             DPRINT << ", show HbDeviceProgressDialog";
       
   395             static_cast<HbDeviceProgressDialog *>(note)->show();
       
   396         } else if (qobject_cast<HbDeviceMessageBox *>(note)) {
       
   397             DPRINT << ", show HbDeviceMessageBox";    
       
   398             static_cast<HbDeviceMessageBox *>(note)->show();
       
   399         } else {
       
   400             DPRINT << ", UNKNOWN NOTE";
       
   401             Q_ASSERT(false);
       
   402         }
       
   403     } else {
       
   404         DPRINT << ", BUSY";
       
   405     }
       
   406     
       
   407     DPRINT << ": OUT";
       
   408 }
       
   409 
       
   410 /*!
       
   411   PsUiNotes::handleActiveDiverts   
       
   412  */
       
   413 void PsUiNotes::formatActiveDivertsNoteText(
       
   414     const QList<PSCallDivertingStatus*> &divertingStatusList,
       
   415     QString &text)
       
   416 {
       
   417     text.append(hbTrId("Active for:") + "\n\n"); //txt_phone_title_active_for
       
   418              
       
   419     int entries = divertingStatusList.count(); 
       
   420     DPRINT << ": entries " << entries;
       
   421     bool dataSet = false;
       
   422     bool voiceSet = false;
       
   423     for (int i = 0; entries > i; i++) {
       
   424        PSCallDivertingStatus *entry = divertingStatusList.at(i);
       
   425        
       
   426        if (((entry->iServiceGroup & ServiceGroupVoice) && !voiceSet ) ||
       
   427            ((entry->iServiceGroup & ServiceGroupData)) && !dataSet) {   
       
   428            if ((entry->iServiceGroup & ServiceGroupVoice) && !voiceSet) {
       
   429                voiceSet = true;
       
   430                text.append(hbTrId("Voice calls") + "\n"); //txt_phone_info_voice_calls  
       
   431               
       
   432            }
       
   433            else if ((entry->iServiceGroup & ServiceGroupData) && !dataSet) {
       
   434                dataSet = true;
       
   435                text.append(hbTrId("Video calls") + "\n"); //txt_phone_info_video_calls
       
   436            }
       
   437                 
       
   438            QString phoneNumber = formatPhoneNumber(divertingStatusList.at(i)->iNumber);
       
   439            text.append(hbTrId("To number:\n%L1").arg(phoneNumber) +"\n"); //txt_phone_info_to_numbernl1
       
   440            if (0 < entry->iTimeout) {
       
   441                text.append(hbTrId("Delay time:\n%L1 seconds").
       
   442                    arg(entry->iTimeout) +"\n\n"); // txt_phone_info_delay_timenln_seconds    
       
   443            }
       
   444            else {
       
   445                text.append("\n");
       
   446            }
       
   447           
       
   448        }
       
   449     }
       
   450     // Convert plain text to html 
       
   451     text = Qt::convertFromPlainText(text);
       
   452 }
       
   453 
       
   454 /*!
       
   455   PsUiNotes::activeNoteAboutToClose.
       
   456  */
       
   457 void PsUiNotes::activeNoteAboutToClose()
       
   458 {
       
   459     DPRINT << ": IN";
       
   460     
       
   461     if (m_isNoteShowingOngoing) {
       
   462         m_isNoteShowingOngoing = false;
       
   463         QObject* note(NULL);
       
   464         if (!m_notesQueue->isEmpty()) {
       
   465             note = m_notesQueue->dequeue();
       
   466         }
       
   467         if(note) {
       
   468             launchNextNoteIfReady();
       
   469             note->disconnect(this);
       
   470             DPRINT << ", delete note: " << reinterpret_cast<int>(note);
       
   471             HbDeviceProgressDialog *pNote = 
       
   472                 qobject_cast<HbDeviceProgressDialog *>(note);
       
   473             note->deleteLater();
       
   474         }
       
   475     }
       
   476     
       
   477     DPRINT << ": OUT";
       
   478 }
       
   479 
       
   480 /*!
       
   481   PsUiNotes::handleProgressNoteCanceled().
       
   482  */
       
   483 void PsUiNotes::handleProgressNoteCanceled()
       
   484 {
       
   485     DPRINT << ": IN";
       
   486     
       
   487     emit progressNoteCanceled();
       
   488     
       
   489     DPRINT << ": OUT";
       
   490 }
       
   491 
       
   492 /*!
       
   493   PsUiNotes::passwordTextChanged().
       
   494  */
       
   495 void PsUiNotes::passwordTextChanged()
       
   496 {
       
   497     DPRINT << ": IN";
       
   498     Q_ASSERT(m_passwordDialog && m_passwordValidator);
       
   499     
       
   500     HbLineEdit *hbLineEdit = m_passwordDialog->lineEdit();
       
   501     int position = 0;
       
   502     QString password = hbLineEdit->text();
       
   503     bool isPasswordValid = 
       
   504         (QValidator::Acceptable == m_passwordValidator->validate(
       
   505             password, position));
       
   506     m_passwordDialog->actions().at(0)->setEnabled(isPasswordValid);
       
   507         
       
   508     DPRINT << ": OUT";
       
   509 }
       
   510 
       
   511 
       
   512 /*!
       
   513   PsUiNotes::showNotificationDialog.
       
   514  */
       
   515 void PsUiNotes::showNotificationDialog(const QString& text)
       
   516 {
       
   517     DPRINT << ": IN";
       
   518     
       
   519     HbNotificationDialog *notifDialog = new HbNotificationDialog();
       
   520     
       
   521     notifDialog->setDismissPolicy(HbPopup::TapAnywhere);
       
   522     notifDialog->setAttribute(Qt::WA_DeleteOnClose, true);
       
   523     notifDialog->setText(text);
       
   524     notifDialog->show();
       
   525 
       
   526     DPRINT << ": OUT";
       
   527 }
       
   528 
       
   529 /*!
       
   530   PsUiNotes::showGlobalNotificationDialog   
       
   531  */
       
   532 void PsUiNotes::showGlobalNotificationDialog(const QString& text)
       
   533 {
       
   534     DPRINT << ": IN";
       
   535         
       
   536     HbDeviceNotificationDialog notifDialog;
       
   537       
       
   538     notifDialog.setText(text);
       
   539     notifDialog.show();
       
   540     
       
   541     DPRINT << ": OUT";    
       
   542 }
       
   543 
       
   544 // End of File.