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