phonesettings/cpphonesettingsplugins/cptelephonyutils/src/cpphonenotes.cpp
changeset 27 2f8f8080a020
parent 21 92ab7f8d0eab
child 30 ebdbd102c78a
equal deleted inserted replaced
22:6bb1b21d2484 27:2f8f8080a020
    26 #include <hbmessagebox.h>
    26 #include <hbmessagebox.h>
    27 #include <QStandardItemModel>
    27 #include <QStandardItemModel>
    28 #include <QItemSelectionModel>
    28 #include <QItemSelectionModel>
    29 #include <hbstringutil.h>
    29 #include <hbstringutil.h>
    30 #include <hbextendedlocale.h>
    30 #include <hbextendedlocale.h>
       
    31 #include <HbInputDialog>
       
    32 #include <HbEditorInterface>
       
    33 #include <hbinputdef.h>
       
    34 #include <hbinputstandardfilters.h>
    31 
    35 
    32 /*!
    36 /*!
    33   CpPhoneNotes::instance.
    37   CpPhoneNotes::instance.
    34  */
    38  */
    35 CpPhoneNotes* CpPhoneNotes::instance()
    39 CpPhoneNotes* CpPhoneNotes::instance()
    46   CpPhoneNotes::CpPhoneNotes.
    50   CpPhoneNotes::CpPhoneNotes.
    47  */
    51  */
    48 CpPhoneNotes::CpPhoneNotes(): 
    52 CpPhoneNotes::CpPhoneNotes(): 
    49      QObject(NULL), 
    53      QObject(NULL), 
    50      m_notesQueue(NULL),
    54      m_notesQueue(NULL),
    51      m_isNoteShowingOngoing(false)
    55      m_isNoteShowingOngoing(false),
       
    56      m_passwordDialog(NULL),
       
    57      m_passwordValidator(NULL)
    52     {
    58     {
    53     DPRINT << ": IN";
    59     DPRINT << ": IN";
    54 
    60     
    55     m_notesQueue = new QQueue<QObject*>();
    61     m_notesQueue = new QQueue<QObject*>();
    56     m_cpSettingsWrapper = new CpSettingsWrapper;
    62     m_cpSettingsWrapper = new CpSettingsWrapper;
    57     
    63     
    58     DPRINT << ": OUT";
    64     DPRINT << ": OUT";
    59     }
    65     }
   165     serviceList->setModel(serviceListModel.take());
   171     serviceList->setModel(serviceListModel.take());
   166     serviceList->setSelectionMode(HbAbstractItemView::NoSelection);
   172     serviceList->setSelectionMode(HbAbstractItemView::NoSelection);
   167     serviceListPopup->setContentWidget(serviceList.take());
   173     serviceListPopup->setContentWidget(serviceList.take());
   168     
   174     
   169     HbAction *backAction = 
   175     HbAction *backAction = 
   170         new HbAction(hbTrId("Back"), serviceListPopup.data());
   176         new HbAction(hbTrId("txt_common_button_back"), serviceListPopup.data());
   171     serviceListPopup->setPrimaryAction(backAction);
   177     serviceListPopup->setPrimaryAction(backAction);
   172     serviceListPopup->exec();
   178     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     
   179     
   253     DPRINT << ": OUT";
   180     DPRINT << ": OUT";
   254 }
   181 }
   255 
   182 
   256 /*!
   183 /*!
   295 {
   222 {
   296     return !m_notesQueue->isEmpty();
   223     return !m_notesQueue->isEmpty();
   297 }
   224 }
   298 
   225 
   299 /*!
   226 /*!
   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.
   227   CpPhoneNotes::basicServiceGroupName.
   325   Resolves basic service group name by group identifier.
   228   Resolves basic service group name by group identifier.
   326  */
   229  */
   327 QString CpPhoneNotes::basicServiceGroupName(BasicServiceGroups basicServiceGroupId) const
   230 QString CpPhoneNotes::basicServiceGroupName(BasicServiceGroups basicServiceGroupId) const
   328 {
   231 {
   387             break;
   290             break;
   388     }
   291     }
   389     
   292     
   390     DPRINT << ": OUT";
   293     DPRINT << ": OUT";
   391     return string;
   294     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 }
   295 }
   402 
   296 
   403 /*!
   297 /*!
   404   CpPhoneNotes::showGlobalErrorNote.
   298   CpPhoneNotes::showGlobalErrorNote.
   405  */
   299  */
   437     divertInfo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
   331     divertInfo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
   438     
   332     
   439     // TODO: Orbit layout support is insufficient currently and all text
   333     // TODO: Orbit layout support is insufficient currently and all text
   440     // is not shown.
   334     // is not shown.
   441     QString content = "";
   335     QString content = "";
   442     content.append(hbTrId("To number: "));
   336     content.append(hbTrId("txt_phone_info_number"));
   443     content.append(formatPhoneNumber(divertStatus.iNumber));
   337     content.append(formatPhoneNumber(divertStatus.iNumber));
   444     if (0 < divertStatus.iTimeout) {
   338     if (0 < divertStatus.iTimeout) {
   445         content.append(hbTrId(" Delay time: "));
   339         content.append(hbTrId("txt_phone_setlabel_delay"));
   446         content.append(QString::number(divertStatus.iTimeout));
   340         content.append(QString::number(divertStatus.iTimeout));
   447         content.append(hbTrId(" seconds"));
   341         content.append(hbTrId(" seconds"));
   448     }
   342     }
   449     divertInfo->setText(content);
   343     divertInfo->setText(content);
   450     HbAction *backAction = new HbAction(hbTrId("Back"), divertInfo);
   344     HbAction *backAction = new HbAction(hbTrId("txt_common_button_back"), divertInfo);
   451     divertInfo->setPrimaryAction(backAction);
   345     divertInfo->setPrimaryAction(backAction);
   452     divertInfo->exec();
   346     divertInfo->exec();
   453     delete divertInfo;
   347     delete divertInfo;
       
   348     
       
   349     DPRINT << ": OUT";
       
   350 }
       
   351 
       
   352 /*!
       
   353   CpPhoneNotes::showPasswordQueryDialog.
       
   354  */
       
   355 void CpPhoneNotes::showPasswordQueryDialog(
       
   356     const QString &title, 
       
   357     const QValidator &validator,
       
   358     int maxPasswordLength,
       
   359     QString &password, 
       
   360     bool &ok)
       
   361 {
       
   362     DPRINT << ": IN";
       
   363     
       
   364     QScopedPointer<HbInputDialog> passwordDialog(new HbInputDialog());
       
   365     
       
   366     // configure editor so that only digits can be inputted
       
   367     passwordDialog->setPromptText(title);
       
   368     passwordDialog->setEchoMode(HbLineEdit::Password);
       
   369     passwordDialog->setInputMethodHints(Qt::ImhDigitsOnly);
       
   370     HbLineEdit *hbLineEdit = passwordDialog->lineEdit();
       
   371     hbLineEdit->setMaxLength(maxPasswordLength);
       
   372     HbEditorInterface editorInterface(hbLineEdit);
       
   373     editorInterface.setInputMode(HbInputModeNumeric);
       
   374     editorInterface.setConstraints(HbEditorConstraintFixedInputMode);
       
   375     editorInterface.setFilter(HbDigitsOnlyFilter::instance());
       
   376     
       
   377     m_passwordDialog = passwordDialog.data();
       
   378     m_passwordValidator = &validator;
       
   379     passwordDialog->primaryAction()->setEnabled(false);
       
   380     connect(
       
   381         hbLineEdit, SIGNAL(contentsChanged()), 
       
   382         this, SLOT(passwordTextChanged()));
       
   383     
       
   384     HbAction* action = passwordDialog->exec();
       
   385     if (action == passwordDialog->secondaryAction()) {
       
   386         ok = false;
       
   387     } else {
       
   388         ok = true;
       
   389         password = passwordDialog->value().toString();
       
   390     }
       
   391     
       
   392     m_passwordDialog = NULL;
       
   393     m_passwordValidator = NULL;
       
   394     disconnect(
       
   395         hbLineEdit, SIGNAL(contentsChanged()), 
       
   396         this, SLOT(passwordTextChanged()));
   454     
   397     
   455     DPRINT << ": OUT";
   398     DPRINT << ": OUT";
   456 }
   399 }
   457 
   400 
   458 /*!
   401 /*!
   509     }
   452     }
   510     
   453     
   511     DPRINT << ": OUT";
   454     DPRINT << ": OUT";
   512 }
   455 }
   513 
   456 
       
   457 /*!
       
   458   CpPhoneNotes::activeNoteAboutToClose.
       
   459  */
       
   460 void CpPhoneNotes::activeNoteAboutToClose()
       
   461 {
       
   462     DPRINT << ": IN";
       
   463     
       
   464     if (m_isNoteShowingOngoing) {
       
   465         m_isNoteShowingOngoing = false;
       
   466         QObject* note(NULL);
       
   467         if (!m_notesQueue->isEmpty()) {
       
   468             note = m_notesQueue->dequeue();
       
   469         }
       
   470         if(note) {
       
   471             launchNextNoteIfReady();
       
   472             note->disconnect(this);
       
   473             DPRINT << ", delete note: " << reinterpret_cast<int>(note);
       
   474             note->deleteLater();
       
   475         }
       
   476     }
       
   477     
       
   478     DPRINT << ": OUT";
       
   479 }
   514 
   480 
   515 /*!
   481 /*!
   516   CpPhoneNotes::handleProgressNoteCanceled().
   482   CpPhoneNotes::handleProgressNoteCanceled().
   517  */
   483  */
   518 void CpPhoneNotes::handleProgressNoteCanceled()
   484 void CpPhoneNotes::handleProgressNoteCanceled()
   522     emit progressNoteCanceled();
   488     emit progressNoteCanceled();
   523     
   489     
   524     DPRINT << ": OUT";
   490     DPRINT << ": OUT";
   525 }
   491 }
   526 
   492 
       
   493 /*!
       
   494   CpPhoneNotes::passwordTextChanged().
       
   495  */
       
   496 void CpPhoneNotes::passwordTextChanged()
       
   497 {
       
   498     DPRINT << ": IN";
       
   499     Q_ASSERT(m_passwordDialog && m_passwordValidator);
       
   500     
       
   501     HbLineEdit *hbLineEdit = m_passwordDialog->lineEdit();
       
   502     int position = 0;
       
   503     QString password = hbLineEdit->text();
       
   504     bool isPasswordValid = 
       
   505         (QValidator::Acceptable == m_passwordValidator->validate(
       
   506             password, position));
       
   507     m_passwordDialog->primaryAction()->setEnabled(isPasswordValid);
       
   508     
       
   509     DPRINT << ": OUT";
       
   510 }
       
   511 
   527 // End of File.
   512 // End of File.