phonesettings/cpphonesettingsplugins/cptelephonyutils/src/cpphonenotes.cpp
changeset 37 ba76fc04e6c2
child 45 6b911d05207e
equal deleted inserted replaced
36:2eacb6118286 37:ba76fc04e6c2
       
     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 <QStandardItemModel>
       
    28 #include <QItemSelectionModel>
       
    29 #include <hbstringutil.h>
       
    30 #include <hbextendedlocale.h>
       
    31 #include <HbInputDialog>
       
    32 #include <HbEditorInterface>
       
    33 #include <hbinputdef.h>
       
    34 #include <hbinputstandardfilters.h>
       
    35 
       
    36 /*!
       
    37   CpPhoneNotes::instance.
       
    38  */
       
    39 CpPhoneNotes* CpPhoneNotes::instance()
       
    40 {
       
    41     DPRINT << ": IN";
       
    42   
       
    43     static CpPhoneNotes theInstance;
       
    44     
       
    45     DPRINT << ", instance address: " << reinterpret_cast<int>(&theInstance);
       
    46     return &theInstance;
       
    47 }
       
    48  
       
    49 /*!
       
    50   CpPhoneNotes::CpPhoneNotes.
       
    51  */
       
    52 CpPhoneNotes::CpPhoneNotes(): 
       
    53      QObject(NULL), 
       
    54      m_notesQueue(NULL),
       
    55      m_isNoteShowingOngoing(false),
       
    56      m_passwordDialog(NULL),
       
    57      m_passwordValidator(NULL)
       
    58     {
       
    59     DPRINT << ": IN";
       
    60 
       
    61     m_notesQueue = new QQueue<QObject*>();
       
    62     m_cpSettingsWrapper = new CpSettingsWrapper;
       
    63     
       
    64     DPRINT << ": OUT";
       
    65     }
       
    66 
       
    67 /*!
       
    68   CpPhoneNotes::~CpPhoneNotes.
       
    69  */
       
    70 CpPhoneNotes::~CpPhoneNotes()
       
    71 {
       
    72     DPRINT << ": IN";
       
    73 
       
    74     delete m_cpSettingsWrapper;
       
    75     QObject* note(NULL);
       
    76     foreach (note, *m_notesQueue) {
       
    77         delete note;
       
    78     }
       
    79     delete m_notesQueue;
       
    80     if(m_passwordDialog) {
       
    81         delete m_passwordDialog;
       
    82     }
       
    83         
       
    84     
       
    85     DPRINT << ": OUT";
       
    86 }
       
    87 
       
    88 /*!
       
    89   CpPhoneNotes::showGlobalProgressNote.
       
    90  */
       
    91 void CpPhoneNotes::showGlobalProgressNote(
       
    92     int &noteId, const QString& text)
       
    93 {
       
    94     DPRINT << ": IN";
       
    95     
       
    96     HbDeviceProgressDialog *note = 
       
    97         new HbDeviceProgressDialog(HbProgressDialog::WaitDialog, this);
       
    98     note->setText(text);
       
    99     QAction *action = new QAction(hbTrId("txt_common_button_hide"), this);
       
   100     //Ownership of action is not transferred. Deleted when note closes.
       
   101     note->setAction(action, HbDeviceProgressDialog::CancelButtonRole );
       
   102     noteId = reinterpret_cast<int>(note);
       
   103     DPRINT << ", NOTEID: " << noteId;
       
   104     QObject::connect(
       
   105         note, SIGNAL(aboutToClose()),
       
   106         this, SLOT(activeNoteAboutToClose()));
       
   107     QObject::connect(
       
   108         note, SIGNAL(cancelled()),
       
   109         this, SLOT(handleProgressNoteCanceled()));
       
   110     m_notesQueue->enqueue(note);    
       
   111     launchNextNoteIfReady();
       
   112     
       
   113     DPRINT << ": OUT";
       
   114 }
       
   115     
       
   116 /*!
       
   117   CpPhoneNotes::showGlobalNote.
       
   118  */
       
   119 void CpPhoneNotes::showGlobalNote(int &noteId, const QString& text, 
       
   120     HbMessageBox::MessageBoxType messageBoxType)
       
   121 {
       
   122     DPRINT << ": IN";
       
   123 
       
   124     HbDeviceMessageBox *note
       
   125         = new HbDeviceMessageBox(text, messageBoxType, this);
       
   126     if (messageBoxType == HbMessageBox::MessageTypeQuestion ||
       
   127         messageBoxType == HbMessageBox::MessageTypeInformation) {
       
   128         note->setTimeout(HbPopup::ConfirmationNoteTimeout);
       
   129     }
       
   130     else {
       
   131         note->setTimeout(0);
       
   132     }
       
   133     noteId = reinterpret_cast<int>(note);
       
   134     DPRINT << ", NOTEID: " << noteId;
       
   135     
       
   136     QObject::connect(
       
   137         note, SIGNAL(aboutToClose()),
       
   138         this, SLOT(activeNoteAboutToClose()));
       
   139     
       
   140     m_notesQueue->enqueue(note);
       
   141     launchNextNoteIfReady();
       
   142     
       
   143     DPRINT << ": OUT";
       
   144 }
       
   145 
       
   146 /*!
       
   147   CpPhoneNotes::showBasicServiceList.
       
   148  */
       
   149 void CpPhoneNotes::showBasicServiceList(
       
   150     const QString &title, 
       
   151     const QList<unsigned char> &basicServiceGroupIds)
       
   152 {
       
   153     DPRINT << ": IN";
       
   154     
       
   155     Q_ASSERT(title != "");
       
   156     Q_ASSERT(0 < basicServiceGroupIds.count());
       
   157     
       
   158     QScopedPointer<HbDialog> serviceListPopup(new HbDialog());
       
   159     serviceListPopup->setDismissPolicy(HbDialog::NoDismiss);
       
   160     serviceListPopup->setTimeout(HbPopup::NoTimeout);
       
   161     
       
   162     QScopedPointer<HbLabel> heading(
       
   163         new HbLabel(title, serviceListPopup.data()));
       
   164     heading->setAlignment(Qt::AlignLeft | Qt::AlignTop);
       
   165     serviceListPopup->setHeadingWidget(heading.take());
       
   166     
       
   167     QScopedPointer<HbListView> serviceList(
       
   168         new HbListView(serviceListPopup.data()));
       
   169     QScopedPointer<QStandardItemModel> serviceListModel(
       
   170         new QStandardItemModel(serviceList.data()));
       
   171     for (int i = 0; i < basicServiceGroupIds.count(); i++) {
       
   172         BasicServiceGroups groupId = 
       
   173             static_cast<BasicServiceGroups>(basicServiceGroupIds.at(i));
       
   174         QString groupName = basicServiceGroupName(groupId);
       
   175         QScopedPointer<QStandardItem> listItem(new QStandardItem(groupName));
       
   176         serviceListModel->appendRow(listItem.take());
       
   177     }
       
   178     serviceList->setModel(serviceListModel.take());
       
   179     serviceList->setSelectionMode(HbAbstractItemView::NoSelection);
       
   180     serviceListPopup->setContentWidget(serviceList.take());
       
   181     
       
   182     HbAction *backAction = 
       
   183         new HbAction(hbTrId("txt_common_button_back"), serviceListPopup.data());
       
   184     serviceListPopup->setPrimaryAction(backAction);
       
   185     
       
   186     HbDialog *serviceListPopupDialog = serviceListPopup.take();
       
   187     QObject::connect(
       
   188         serviceListPopupDialog, SIGNAL(finished(HbAction*)), 
       
   189         serviceListPopupDialog, SLOT(deleteLater()));
       
   190     serviceListPopupDialog->show();
       
   191     
       
   192     DPRINT << ": OUT";
       
   193 }
       
   194 
       
   195 /*!
       
   196   CpPhoneNotes::cancelNote.
       
   197  */
       
   198 void CpPhoneNotes::cancelNote(int noteId)
       
   199 {
       
   200     DPRINT << ": IN";
       
   201     
       
   202     if (!m_notesQueue->isEmpty()) {
       
   203         QObject *note = m_notesQueue->head();
       
   204         if(note == reinterpret_cast<QObject *>(noteId)) {
       
   205             int index = m_notesQueue->indexOf(reinterpret_cast<QObject *>(noteId));
       
   206             Q_ASSERT(-1 < index);
       
   207             QObject *note = m_notesQueue->at(index);
       
   208             DPRINT << ": NOTEID: " << noteId;
       
   209             if (qobject_cast<HbDeviceProgressDialog *>(note)) {
       
   210                 static_cast<HbDeviceProgressDialog *>(note)->close();
       
   211             } else if (qobject_cast<HbDeviceMessageBox *>(note)) {
       
   212                 static_cast<HbDeviceMessageBox *>(note)->close();
       
   213             } else {
       
   214                 DPRINT << ", UNKNOWN NOTE";
       
   215                 Q_ASSERT(false);
       
   216             }
       
   217         }
       
   218         else {
       
   219             DPRINT << ": remove from queue, noteId: " << noteId;
       
   220             m_notesQueue->removeOne(reinterpret_cast<QObject *>(noteId));
       
   221         }
       
   222     }
       
   223     
       
   224     DPRINT << ": OUT";
       
   225 }
       
   226 
       
   227 /*!
       
   228   CpPhoneNotes::noteShowing.
       
   229  */
       
   230 bool CpPhoneNotes::noteShowing()
       
   231 {
       
   232     return !m_notesQueue->isEmpty();
       
   233 }
       
   234 
       
   235 /*!
       
   236   CpPhoneNotes::basicServiceGroupName.
       
   237   Resolves basic service group name by group identifier.
       
   238  */
       
   239 QString CpPhoneNotes::basicServiceGroupName(BasicServiceGroups basicServiceGroupId) const
       
   240 {
       
   241     DPRINT << ": IN";
       
   242     
       
   243     QString string = "";
       
   244     switch (basicServiceGroupId) {
       
   245         case AllTeleAndBearer:
       
   246             string = hbTrId("All services");
       
   247             break;
       
   248         case AllTele:
       
   249             string = hbTrId("Voice, fax and messages");
       
   250             break;
       
   251         case Telephony:
       
   252             string = hbTrId("Voice calls");
       
   253             break;
       
   254         case AllDataTele:
       
   255             string = hbTrId("Fax and messages");
       
   256             break;
       
   257         case Fax:
       
   258             string = hbTrId("Fax");
       
   259             break;
       
   260         case Sms:
       
   261             string = hbTrId("Messages");
       
   262             break;
       
   263         case AllTeleExcSms:
       
   264             string = hbTrId("Voice calls and fax");
       
   265             break;
       
   266         case AllBearer:
       
   267             if (Tools::videoSupported()) {
       
   268                 string = hbTrId("Data and video services");
       
   269             } else {
       
   270                 string = hbTrId("Data services");
       
   271             }
       
   272             break;
       
   273         case AllAsync:
       
   274             string = hbTrId("Asynchronous services");
       
   275             break;
       
   276         case AllSync:
       
   277             string = hbTrId("Synchronous services");
       
   278             break;
       
   279         case SyncData:
       
   280             string = hbTrId("Synchronous data services");
       
   281             break;
       
   282         case AsyncData:
       
   283             string = hbTrId("Asynchronous data services");
       
   284             break;
       
   285         case PacketData:
       
   286             string = hbTrId("Packet data");
       
   287             break;
       
   288         case PadAccess:
       
   289             string = hbTrId("PAD access");
       
   290             break;
       
   291         case 30:
       
   292             string = hbTrId("Video calls");
       
   293             break;
       
   294         case AltTele:
       
   295             string = hbTrId("Alternate line services");
       
   296             break;
       
   297         default:
       
   298             DPRINT << ", DEFAULT";
       
   299             break;
       
   300     }
       
   301     
       
   302     DPRINT << ": OUT";
       
   303     return string;
       
   304 }
       
   305 
       
   306 /*!
       
   307   CpPhoneNotes::showGlobalErrorNote.
       
   308  */
       
   309 void CpPhoneNotes::showGlobalErrorNote(int &noteId, int errorcode)
       
   310 {
       
   311     DPRINT << ": IN";
       
   312     
       
   313     QString errorText = "";
       
   314     Tools::errorCodeTextMapping(errorcode, errorText);
       
   315 
       
   316     HbDeviceMessageBox *note 
       
   317         = new HbDeviceMessageBox(errorText, HbMessageBox::MessageTypeWarning, this);
       
   318     note->setTimeout(0);
       
   319     noteId = reinterpret_cast<int>(note);
       
   320     DPRINT << ", NOTEID: " << noteId;
       
   321     QObject::connect(
       
   322         note, SIGNAL(aboutToClose()),
       
   323         this, SLOT(activeNoteAboutToClose()));
       
   324     m_notesQueue->enqueue(note);
       
   325     launchNextNoteIfReady();
       
   326     
       
   327     DPRINT << ": OUT";
       
   328 } 
       
   329 
       
   330 /*!
       
   331   CpPhoneNotes::showCallDivertDetails.
       
   332  */
       
   333 void CpPhoneNotes::showCallDivertDetails(
       
   334     const PSCallDivertingStatus &divertStatus)
       
   335 {
       
   336     DPRINT << ": IN";
       
   337     
       
   338     QScopedPointer<HbMessageBox> divertInfoScopedPointer(
       
   339         new HbMessageBox(HbMessageBox::MessageTypeInformation));
       
   340     divertInfoScopedPointer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
   341     
       
   342     // TODO: Orbit layout support is insufficient currently and all text
       
   343     // is not shown.
       
   344     QString content = "";
       
   345     content.append(hbTrId("txt_phone_info_number"));
       
   346     content.append(formatPhoneNumber(divertStatus.iNumber));
       
   347     if (0 < divertStatus.iTimeout) {
       
   348         content.append(hbTrId("txt_phone_setlabel_delay"));
       
   349         content.append(QString::number(divertStatus.iTimeout));
       
   350         content.append(hbTrId(" seconds"));
       
   351     }
       
   352     divertInfoScopedPointer->setText(content);
       
   353     HbAction *backAction = new HbAction(
       
   354         hbTrId("txt_common_button_back"), 
       
   355         divertInfoScopedPointer.data());
       
   356     divertInfoScopedPointer->setPrimaryAction(backAction);
       
   357     
       
   358     HbMessageBox *divertInfo = divertInfoScopedPointer.take();
       
   359     QObject::connect(
       
   360             divertInfo, SIGNAL(finished(HbAction*)), 
       
   361             divertInfo, SLOT(deleteLater()));
       
   362     divertInfo->show();
       
   363     
       
   364     DPRINT << ": OUT";
       
   365 }
       
   366 
       
   367 /*!
       
   368   CpPhoneNotes::showPasswordQueryDialog.
       
   369  */
       
   370 void CpPhoneNotes::showPasswordQueryDialog(
       
   371     const QString &title, 
       
   372     const QValidator &validator,
       
   373     int maxPasswordLength)
       
   374 {
       
   375     DPRINT << ": IN";
       
   376     
       
   377     QScopedPointer<HbInputDialog> passwordDialog(new HbInputDialog());
       
   378     
       
   379     // configure editor so that only digits can be inputted
       
   380     passwordDialog->setPromptText(title);
       
   381     passwordDialog->setEchoMode(HbLineEdit::Password);
       
   382     passwordDialog->setInputMethodHints(Qt::ImhDigitsOnly);
       
   383     HbLineEdit *hbLineEdit = passwordDialog->lineEdit();
       
   384     hbLineEdit->setMaxLength(maxPasswordLength);
       
   385     HbEditorInterface editorInterface(hbLineEdit);
       
   386     
       
   387     editorInterface.setMode(HbInputModeNumeric);
       
   388     editorInterface.setInputConstraints(HbEditorConstraintFixedInputMode);
       
   389     
       
   390     editorInterface.setFilter(HbDigitsOnlyFilter::instance());
       
   391     
       
   392     m_passwordValidator = &validator;
       
   393     passwordDialog->primaryAction()->setEnabled(false);
       
   394     connect(
       
   395         hbLineEdit, SIGNAL(contentsChanged()), 
       
   396         this, SLOT(passwordTextChanged()));
       
   397     
       
   398     passwordDialog->open(this, SLOT(finishedPasswordQueryDialog(HbAction*)));
       
   399 	if(m_passwordDialog) {
       
   400 		m_passwordDialog->deleteLater();
       
   401 		m_passwordDialog = NULL;
       
   402 	}
       
   403     m_passwordDialog = passwordDialog.take();
       
   404         
       
   405     DPRINT << ": OUT";
       
   406 }
       
   407 
       
   408 /*!
       
   409   CpPhoneNotes::finishedPasswordQueryDialog.
       
   410  */
       
   411 void CpPhoneNotes::finishedPasswordQueryDialog(HbAction* action)
       
   412 {
       
   413     bool ok;
       
   414     QString password;
       
   415     if(m_passwordDialog) {
       
   416         if (action == m_passwordDialog->secondaryAction()) {
       
   417             ok = false;
       
   418         } else {
       
   419             ok = true;
       
   420             password = m_passwordDialog->value().toString();
       
   421         }
       
   422         
       
   423         disconnect(
       
   424             m_passwordDialog->lineEdit(), SIGNAL(contentsChanged()), 
       
   425             this, SLOT(passwordTextChanged()));
       
   426         
       
   427         m_passwordDialog->deleteLater();
       
   428         m_passwordDialog = NULL;
       
   429         m_passwordValidator = NULL;
       
   430         
       
   431         emit passwordQueryCompleted(password, ok);
       
   432     }
       
   433 }
       
   434 
       
   435 /*!
       
   436   CpPhoneNotes::formatPhoneNumber.
       
   437   Formats phone number according to locale specific rules.
       
   438  */
       
   439 QString CpPhoneNotes::formatPhoneNumber(QString number) const
       
   440 {
       
   441     DPRINT << ": IN";
       
   442     
       
   443     QString formattedNumber = number;
       
   444     
       
   445     if (m_cpSettingsWrapper->numberGroupingSupported() == true) {
       
   446         // TODO: utilize HbNumberGrouping API when available
       
   447     }
       
   448     
       
   449     // TODO: digit conversion e.g. into arabic-indic
       
   450 //    HbExtendedLocale locale = HbExtendedLocale::system();
       
   451 //    HbStringUtil::convertDigitsTo(formattedNumber, ArabicIndicDigit);
       
   452     
       
   453     DPRINT << ": OUT";
       
   454 
       
   455     return formattedNumber;
       
   456 }
       
   457 
       
   458 /*!
       
   459   CpPhoneNotes::launchNextNoteIfReady.
       
   460  */
       
   461 void CpPhoneNotes::launchNextNoteIfReady()
       
   462 {
       
   463     DPRINT << ": IN";
       
   464     
       
   465     if (m_notesQueue->isEmpty()) {
       
   466         DPRINT << ", QUEUE EMPTY";
       
   467         return;
       
   468     }
       
   469     if (!m_isNoteShowingOngoing) {
       
   470         m_isNoteShowingOngoing = true;
       
   471         // note is left in the queue so that it can be cancelled at request
       
   472         QObject *note = m_notesQueue->head();
       
   473         DPRINT << ", note: " << reinterpret_cast<int>(note);
       
   474         if (qobject_cast<HbDeviceProgressDialog *>(note)) {
       
   475             DPRINT << ", show HbDeviceProgressDialog";
       
   476             static_cast<HbDeviceProgressDialog *>(note)->show();
       
   477         } else if (qobject_cast<HbDeviceMessageBox *>(note)) {
       
   478             DPRINT << ", show HbDeviceMessageBox";    
       
   479             static_cast<HbDeviceMessageBox *>(note)->show();
       
   480         } else {
       
   481             DPRINT << ", UNKNOWN NOTE";
       
   482             Q_ASSERT(false);
       
   483         }
       
   484     } else {
       
   485         DPRINT << ", BUSY";
       
   486     }
       
   487     
       
   488     DPRINT << ": OUT";
       
   489 }
       
   490 
       
   491 /*!
       
   492   CpPhoneNotes::activeNoteAboutToClose.
       
   493  */
       
   494 void CpPhoneNotes::activeNoteAboutToClose()
       
   495 {
       
   496     DPRINT << ": IN";
       
   497     
       
   498     if (m_isNoteShowingOngoing) {
       
   499         m_isNoteShowingOngoing = false;
       
   500         QObject* note(NULL);
       
   501         if (!m_notesQueue->isEmpty()) {
       
   502             note = m_notesQueue->dequeue();
       
   503         }
       
   504         if(note) {
       
   505             launchNextNoteIfReady();
       
   506             note->disconnect(this);
       
   507             DPRINT << ", delete note: " << reinterpret_cast<int>(note);
       
   508             HbDeviceProgressDialog *pNote = 
       
   509                 qobject_cast<HbDeviceProgressDialog *>(note);
       
   510             if(pNote){
       
   511                 delete pNote->action();
       
   512             }
       
   513             note->deleteLater();
       
   514         }
       
   515     }
       
   516     
       
   517     DPRINT << ": OUT";
       
   518 }
       
   519 
       
   520 /*!
       
   521   CpPhoneNotes::handleProgressNoteCanceled().
       
   522  */
       
   523 void CpPhoneNotes::handleProgressNoteCanceled()
       
   524 {
       
   525     DPRINT << ": IN";
       
   526     
       
   527     emit progressNoteCanceled();
       
   528     
       
   529     DPRINT << ": OUT";
       
   530 }
       
   531 
       
   532 /*!
       
   533   CpPhoneNotes::passwordTextChanged().
       
   534  */
       
   535 void CpPhoneNotes::passwordTextChanged()
       
   536 {
       
   537     DPRINT << ": IN";
       
   538     Q_ASSERT(m_passwordDialog && m_passwordValidator);
       
   539     
       
   540     HbLineEdit *hbLineEdit = m_passwordDialog->lineEdit();
       
   541     int position = 0;
       
   542     QString password = hbLineEdit->text();
       
   543     bool isPasswordValid = 
       
   544         (QValidator::Acceptable == m_passwordValidator->validate(
       
   545             password, position));
       
   546     m_passwordDialog->primaryAction()->setEnabled(isPasswordValid);
       
   547     
       
   548     DPRINT << ": OUT";
       
   549 }
       
   550 
       
   551 // End of File.