phonesettings/cpphonesettingsplugins/cptelephonyutils/src/cpphonenotes.cpp
changeset 50 377c906a8701
parent 46 bc5a64e5bc3c
child 52 a49bfe5190e4
equal deleted inserted replaced
46:bc5a64e5bc3c 50:377c906a8701
     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 "cpphonenotes.h"
       
    18 #include "cpplugincommon.h"
       
    19 #include "cppluginlogging.h"
       
    20 #include <hbdevicemessagebox.h>
       
    21 #include <HbDeviceProgressDialog>
       
    22 #include <hblistview.h>
       
    23 #include <hbdialog.h>
       
    24 #include <hblabel.h>
       
    25 #include <hbaction.h>
       
    26 #include <hbmessagebox.h>
       
    27 #include <hbnotificationdialog.h>
       
    28 #include <QStandardItemModel>
       
    29 #include <QItemSelectionModel>
       
    30 #include <hbstringutil.h>
       
    31 #include <hbextendedlocale.h>
       
    32 #include <HbInputDialog>
       
    33 #include <HbEditorInterface>
       
    34 #include <hbinputdef.h>
       
    35 #include <hbinputstandardfilters.h>
       
    36 
       
    37 /*!
       
    38   CpPhoneNotes::instance.
       
    39  */
       
    40 CpPhoneNotes* CpPhoneNotes::instance()
       
    41 {
       
    42     DPRINT << ": IN";
       
    43   
       
    44     static CpPhoneNotes theInstance;
       
    45     
       
    46     DPRINT << ", instance address: " << reinterpret_cast<int>(&theInstance);
       
    47     return &theInstance;
       
    48 }
       
    49  
       
    50 /*!
       
    51   CpPhoneNotes::CpPhoneNotes.
       
    52  */
       
    53 CpPhoneNotes::CpPhoneNotes(): 
       
    54      QObject(NULL), 
       
    55      m_notesQueue(NULL),
       
    56      m_isNoteShowingOngoing(false),
       
    57      m_passwordDialog(NULL),
       
    58      m_passwordValidator(NULL)
       
    59     {
       
    60     DPRINT << ": IN";
       
    61 
       
    62     m_notesQueue = new QQueue<QObject*>();
       
    63     m_cpSettingsWrapper = new CpSettingsWrapper;
       
    64     
       
    65     DPRINT << ": OUT";
       
    66     }
       
    67 
       
    68 /*!
       
    69   CpPhoneNotes::~CpPhoneNotes.
       
    70  */
       
    71 CpPhoneNotes::~CpPhoneNotes()
       
    72 {
       
    73     DPRINT << ": IN";
       
    74 
       
    75     delete m_cpSettingsWrapper;
       
    76     qDeleteAll(*m_notesQueue);
       
    77     delete m_notesQueue;
       
    78         
       
    79     
       
    80     DPRINT << ": OUT";
       
    81 }
       
    82 
       
    83 /*!
       
    84   CpPhoneNotes::showGlobalProgressNote.
       
    85  */
       
    86 void CpPhoneNotes::showGlobalProgressNote(
       
    87     int &noteId, const QString& text)
       
    88 {
       
    89     DPRINT << ": IN";
       
    90     
       
    91     HbDeviceProgressDialog *note = 
       
    92         new HbDeviceProgressDialog(HbProgressDialog::WaitDialog, this);
       
    93     note->setText(text);
       
    94     
       
    95     if(hbTrId("txt_common_info_requesting") == text){
       
    96         QAction *action = new QAction(hbTrId("txt_common_button_hide"), note);
       
    97         note->setAction(action, HbDeviceProgressDialog::CancelButtonRole );
       
    98     }
       
    99     
       
   100     noteId = reinterpret_cast<int>(note);
       
   101     DPRINT << ", NOTEID: " << noteId;
       
   102     QObject::connect(
       
   103         note, SIGNAL(aboutToClose()),
       
   104         this, SLOT(activeNoteAboutToClose()));
       
   105     QObject::connect(
       
   106         note, SIGNAL(cancelled()),
       
   107         this, SLOT(handleProgressNoteCanceled()));
       
   108     m_notesQueue->enqueue(note);    
       
   109     launchNextNoteIfReady();
       
   110     
       
   111     DPRINT << ": OUT";
       
   112 }
       
   113     
       
   114 /*!
       
   115   CpPhoneNotes::showGlobalNote.
       
   116  */
       
   117 void CpPhoneNotes::showGlobalNote(int &noteId, const QString& text, 
       
   118     HbMessageBox::MessageBoxType messageBoxType)
       
   119 {
       
   120     DPRINT << ": IN";
       
   121 
       
   122     HbDeviceMessageBox *note
       
   123         = new HbDeviceMessageBox(text, messageBoxType, this);
       
   124     if (messageBoxType == HbMessageBox::MessageTypeQuestion ||
       
   125         messageBoxType == HbMessageBox::MessageTypeInformation) {
       
   126         note->setTimeout(HbPopup::ConfirmationNoteTimeout);
       
   127     }
       
   128     else {
       
   129         note->setTimeout(0);
       
   130     }
       
   131     noteId = reinterpret_cast<int>(note);
       
   132     DPRINT << ", NOTEID: " << noteId;
       
   133     
       
   134     QObject::connect(
       
   135         note, SIGNAL(aboutToClose()),
       
   136         this, SLOT(activeNoteAboutToClose()));
       
   137     
       
   138     m_notesQueue->enqueue(note);
       
   139     launchNextNoteIfReady();
       
   140     
       
   141     DPRINT << ": OUT";
       
   142 }
       
   143 
       
   144 
       
   145 /*!
       
   146   CpPhoneNotes::cancelNote.
       
   147  */
       
   148 void CpPhoneNotes::cancelNote(int noteId)
       
   149 {
       
   150     DPRINT << ": IN";
       
   151     
       
   152     if (!m_notesQueue->isEmpty()) {
       
   153         QObject *note = m_notesQueue->head();
       
   154         if(note == reinterpret_cast<QObject *>(noteId)) {
       
   155             int index = m_notesQueue->indexOf(reinterpret_cast<QObject *>(noteId));
       
   156             Q_ASSERT(-1 < index);
       
   157             QObject *note = m_notesQueue->at(index);
       
   158             DPRINT << ": NOTEID: " << noteId;
       
   159             if (qobject_cast<HbDeviceProgressDialog *>(note)) {
       
   160                 static_cast<HbDeviceProgressDialog *>(note)->close();
       
   161             } else if (qobject_cast<HbDeviceMessageBox *>(note)) {
       
   162                 static_cast<HbDeviceMessageBox *>(note)->close();
       
   163             } else {
       
   164                 DPRINT << ", UNKNOWN NOTE";
       
   165                 Q_ASSERT(false);
       
   166             }
       
   167         }
       
   168         else {
       
   169             DPRINT << ": remove from queue, noteId: " << noteId;
       
   170             m_notesQueue->removeOne(reinterpret_cast<QObject *>(noteId));
       
   171         }
       
   172     }
       
   173     
       
   174     DPRINT << ": OUT";
       
   175 }
       
   176 
       
   177 /*!
       
   178   CpPhoneNotes::noteShowing.
       
   179  */
       
   180 bool CpPhoneNotes::noteShowing()
       
   181 {
       
   182     return !m_notesQueue->isEmpty();
       
   183 }
       
   184 
       
   185 /*!
       
   186   CpPhoneNotes::showGlobalErrorNote.
       
   187  */
       
   188 void CpPhoneNotes::showGlobalErrorNote(int &noteId, int errorcode)
       
   189 {
       
   190     DPRINT << ": IN";
       
   191     
       
   192     QString errorText = "";
       
   193     Tools::errorCodeTextMapping(errorcode, errorText);
       
   194 
       
   195     HbDeviceMessageBox *note 
       
   196         = new HbDeviceMessageBox(errorText, HbMessageBox::MessageTypeWarning, this);
       
   197     note->setTimeout(0);
       
   198     noteId = reinterpret_cast<int>(note);
       
   199     DPRINT << ", NOTEID: " << noteId;
       
   200     QObject::connect(
       
   201         note, SIGNAL(aboutToClose()),
       
   202         this, SLOT(activeNoteAboutToClose()));
       
   203     m_notesQueue->enqueue(note);
       
   204     launchNextNoteIfReady();
       
   205     
       
   206     DPRINT << ": OUT";
       
   207 } 
       
   208 
       
   209 /*!
       
   210   CpPhoneNotes::showCallDivertDetails.
       
   211  */
       
   212 void CpPhoneNotes::showCallDivertDetails(
       
   213     const PSCallDivertingStatus &divertStatus)
       
   214 {
       
   215     DPRINT << ": IN";
       
   216     
       
   217     QScopedPointer<HbMessageBox> divertInfoScopedPointer(
       
   218         new HbMessageBox(HbMessageBox::MessageTypeInformation));
       
   219     divertInfoScopedPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
   220     
       
   221     // TODO: Orbit layout support is insufficient currently and all text
       
   222     // is not shown.
       
   223     QString content = "";
       
   224     content.append(hbTrId("txt_phone_info_number"));
       
   225     content.append(formatPhoneNumber(divertStatus.iNumber));
       
   226     if (0 < divertStatus.iTimeout) {
       
   227         content.append(hbTrId("txt_phone_setlabel_delay"));
       
   228         content.append(QString::number(divertStatus.iTimeout));
       
   229         content.append(hbTrId(" seconds"));
       
   230     }
       
   231     divertInfoScopedPointer->setText(content);
       
   232     HbAction *backAction = new HbAction(
       
   233         hbTrId("txt_common_button_back"), 
       
   234         divertInfoScopedPointer.data());
       
   235     divertInfoScopedPointer->addAction(backAction);
       
   236     
       
   237     HbMessageBox *divertInfo = divertInfoScopedPointer.take();
       
   238     QObject::connect(
       
   239             divertInfo, SIGNAL(finished(HbAction*)), 
       
   240             divertInfo, SLOT(deleteLater()));
       
   241     divertInfo->show();
       
   242     
       
   243     DPRINT << ": OUT";
       
   244 }
       
   245 
       
   246 /*!
       
   247   CpPhoneNotes::showPasswordQueryDialog.
       
   248  */
       
   249 void CpPhoneNotes::showPasswordQueryDialog(
       
   250     const QString &title, 
       
   251     const QValidator &validator,
       
   252     int maxPasswordLength)
       
   253 {
       
   254     DPRINT << ": IN";
       
   255     
       
   256     QScopedPointer<HbInputDialog> passwordDialog(new HbInputDialog());
       
   257     
       
   258     // configure editor so that only digits can be inputted
       
   259     passwordDialog->setPromptText(title);
       
   260     passwordDialog->setEchoMode(HbLineEdit::Password);
       
   261     passwordDialog->setInputMethodHints(Qt::ImhDigitsOnly);
       
   262     passwordDialog->actions().at(0)->setEnabled(false);
       
   263     
       
   264     HbLineEdit *hbLineEdit = passwordDialog->lineEdit();
       
   265     hbLineEdit->setMaxLength(maxPasswordLength);
       
   266     
       
   267     HbEditorInterface editorInterface(hbLineEdit);
       
   268     editorInterface.setMode(HbInputModeNumeric);
       
   269     editorInterface.setInputConstraints(HbEditorConstraintFixedInputMode);
       
   270     editorInterface.setFilter(HbDigitsOnlyFilter::instance());
       
   271     
       
   272     m_passwordValidator = &validator;
       
   273     
       
   274     connect(
       
   275         hbLineEdit, SIGNAL(contentsChanged()), 
       
   276         this, SLOT(passwordTextChanged()));
       
   277     
       
   278     passwordDialog->open(this, SLOT(finishedPasswordQueryDialog(HbAction*)));
       
   279 	if(m_passwordDialog) {
       
   280 		m_passwordDialog->deleteLater();
       
   281 		m_passwordDialog = NULL;
       
   282 	}
       
   283     m_passwordDialog = passwordDialog.take();
       
   284     m_passwordDialog->setParent(this);
       
   285     DPRINT << ": OUT";
       
   286 }
       
   287 
       
   288 /*!
       
   289   CpPhoneNotes::finishedPasswordQueryDialog.
       
   290  */
       
   291 void CpPhoneNotes::finishedPasswordQueryDialog(HbAction* action)
       
   292 {
       
   293     bool ok;
       
   294     QString password;
       
   295     if(m_passwordDialog) {
       
   296         if (action == m_passwordDialog->actions().at(1)) {
       
   297             ok = false;
       
   298         } else {
       
   299             ok = true;
       
   300             password = m_passwordDialog->value().toString();
       
   301         }
       
   302         
       
   303         disconnect(
       
   304             m_passwordDialog->lineEdit(), SIGNAL(contentsChanged()), 
       
   305             this, SLOT(passwordTextChanged()));
       
   306         
       
   307         m_passwordDialog->deleteLater();
       
   308         m_passwordDialog = NULL;
       
   309         m_passwordValidator = NULL;
       
   310         
       
   311         emit passwordQueryCompleted(password, ok);
       
   312     }
       
   313 }
       
   314 
       
   315 /*!
       
   316   CpPhoneNotes::formatPhoneNumber.
       
   317   Formats phone number according to locale specific rules.
       
   318  */
       
   319 QString CpPhoneNotes::formatPhoneNumber(QString number) const
       
   320 {
       
   321     DPRINT << ": IN";
       
   322     
       
   323     QString formattedNumber = number;
       
   324     
       
   325     if (m_cpSettingsWrapper->numberGroupingSupported() == true) {
       
   326         // TODO: utilize HbNumberGrouping API when available
       
   327     }
       
   328     
       
   329     // TODO: digit conversion e.g. into arabic-indic
       
   330 //    HbExtendedLocale locale = HbExtendedLocale::system();
       
   331 //    HbStringUtil::convertDigitsTo(formattedNumber, ArabicIndicDigit);
       
   332     
       
   333     DPRINT << ": OUT";
       
   334 
       
   335     return formattedNumber;
       
   336 }
       
   337 
       
   338 /*!
       
   339   CpPhoneNotes::launchNextNoteIfReady.
       
   340  */
       
   341 void CpPhoneNotes::launchNextNoteIfReady()
       
   342 {
       
   343     DPRINT << ": IN";
       
   344     
       
   345     if (m_notesQueue->isEmpty()) {
       
   346         DPRINT << ", QUEUE EMPTY";
       
   347         return;
       
   348     }
       
   349     if (!m_isNoteShowingOngoing) {
       
   350         m_isNoteShowingOngoing = true;
       
   351         // note is left in the queue so that it can be cancelled at request
       
   352         QObject *note = m_notesQueue->head();
       
   353         DPRINT << ", note: " << reinterpret_cast<int>(note);
       
   354         if (qobject_cast<HbDeviceProgressDialog *>(note)) {
       
   355             DPRINT << ", show HbDeviceProgressDialog";
       
   356             static_cast<HbDeviceProgressDialog *>(note)->show();
       
   357         } else if (qobject_cast<HbDeviceMessageBox *>(note)) {
       
   358             DPRINT << ", show HbDeviceMessageBox";    
       
   359             static_cast<HbDeviceMessageBox *>(note)->show();
       
   360         } else {
       
   361             DPRINT << ", UNKNOWN NOTE";
       
   362             Q_ASSERT(false);
       
   363         }
       
   364     } else {
       
   365         DPRINT << ", BUSY";
       
   366     }
       
   367     
       
   368     DPRINT << ": OUT";
       
   369 }
       
   370 
       
   371 /*!
       
   372   CpPhoneNotes::activeNoteAboutToClose.
       
   373  */
       
   374 void CpPhoneNotes::activeNoteAboutToClose()
       
   375 {
       
   376     DPRINT << ": IN";
       
   377     
       
   378     if (m_isNoteShowingOngoing) {
       
   379         m_isNoteShowingOngoing = false;
       
   380         QObject* note(NULL);
       
   381         if (!m_notesQueue->isEmpty()) {
       
   382             note = m_notesQueue->dequeue();
       
   383         }
       
   384         if(note) {
       
   385             launchNextNoteIfReady();
       
   386             note->disconnect(this);
       
   387             DPRINT << ", delete note: " << reinterpret_cast<int>(note);
       
   388             HbDeviceProgressDialog *pNote = 
       
   389                 qobject_cast<HbDeviceProgressDialog *>(note);
       
   390             note->deleteLater();
       
   391         }
       
   392     }
       
   393     
       
   394     DPRINT << ": OUT";
       
   395 }
       
   396 
       
   397 /*!
       
   398   CpPhoneNotes::handleProgressNoteCanceled().
       
   399  */
       
   400 void CpPhoneNotes::handleProgressNoteCanceled()
       
   401 {
       
   402     DPRINT << ": IN";
       
   403     
       
   404     emit progressNoteCanceled();
       
   405     
       
   406     DPRINT << ": OUT";
       
   407 }
       
   408 
       
   409 /*!
       
   410   CpPhoneNotes::passwordTextChanged().
       
   411  */
       
   412 void CpPhoneNotes::passwordTextChanged()
       
   413 {
       
   414     DPRINT << ": IN";
       
   415     Q_ASSERT(m_passwordDialog && m_passwordValidator);
       
   416     
       
   417     HbLineEdit *hbLineEdit = m_passwordDialog->lineEdit();
       
   418     int position = 0;
       
   419     QString password = hbLineEdit->text();
       
   420     bool isPasswordValid = 
       
   421         (QValidator::Acceptable == m_passwordValidator->validate(
       
   422             password, position));
       
   423     m_passwordDialog->actions().at(0)->setEnabled(isPasswordValid);
       
   424         
       
   425     DPRINT << ": OUT";
       
   426 }
       
   427 
       
   428 
       
   429 /*!
       
   430   CpPhoneNotes::showNotificationDialog.
       
   431  */
       
   432 void CpPhoneNotes::showNotificationDialog(const QString& text)
       
   433 {
       
   434     DPRINT << ": IN";
       
   435     HbNotificationDialog *notifDialog = new HbNotificationDialog();
       
   436     notifDialog->setDismissPolicy(HbPopup::TapAnywhere);
       
   437     notifDialog->setAttribute(Qt::WA_DeleteOnClose, true);
       
   438     notifDialog->setText(text);
       
   439     notifDialog->show();
       
   440 
       
   441     DPRINT << ": OUT";
       
   442 }
       
   443 
       
   444 // End of File.