cmmanager/cpdestinationplugin/src/cpadddestinationentryitemdata.cpp
changeset 56 dd6aaa97e7b1
parent 32 5c4486441ae6
child 72 0c32cf868819
equal deleted inserted replaced
52:bbe4544dfd31 56:dd6aaa97e7b1
     1 /*
     1 /*
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3  * All rights reserved.
     3 * All rights reserved.
     4  * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5  * under the terms of "Eclipse Public License v1.0""
     5 * under the terms of "Eclipse Public License v1.0""
     6  * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8  *
     8 *
     9  * Initial Contributors:
     9 * Initial Contributors:
    10  * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11  *
    11 *
    12  * Contributors:
    12 * Contributors:
    13  *
    13 *
    14  * Description:  
    14 * Description:  
    15  *   Data item for representing "Add Destination" button in UI.
    15 * Data item for representing "Add Destination" button in UI.
    16  */
    16 */
    17 
    17 
    18 // System includes
    18 // System includes
       
    19 
    19 #include <HbInputDialog>
    20 #include <HbInputDialog>
    20 #include <HbAction>
    21 #include <HbAction>
    21 #include <HbMessageBox>
    22 #include <HbMessageBox>
    22 #include <HbPopup>
    23 #include <HbPopup>
       
    24 
    23 #include <cpitemdatahelper.h>
    25 #include <cpitemdatahelper.h>
    24 #include <cmdestination_shim.h>
    26 #include <cmdestination_shim.h>
    25 #include <cmmanager_shim.h>
    27 #include <cmmanager_shim.h>
    26 
    28 
    27 // User includes
    29 // User includes
       
    30 
    28 #include "cpadddestinationentryitemdata.h"
    31 #include "cpadddestinationentryitemdata.h"
    29 #include "cpdestinationgroup.h"
    32 #include "cpdestinationgroup.h"
       
    33 
    30 #include "OstTraceDefinitions.h"
    34 #include "OstTraceDefinitions.h"
    31 #ifdef OST_TRACE_COMPILER_IN_USE
    35 #ifdef OST_TRACE_COMPILER_IN_USE
    32 #include "cpadddestinationentryitemdataTraces.h"
    36 #include "cpadddestinationentryitemdataTraces.h"
    33 #endif
    37 #endif
       
    38 
    34 /*!
    39 /*!
    35     \class  CpAddDestinationEntryItemData
    40     \class  CpAddDestinationEntryItemData
    36     \brief  This class is a dummy destination. It does not contain 
    41     \brief  This class is a dummy destination. It does not contain 
    37             access points but clicking it starts new destination 
    42             access points but clicking it starts new destination 
    38             creation process.
    43             creation process.
    46 
    51 
    47 // ======== MEMBER FUNCTIONS ========
    52 // ======== MEMBER FUNCTIONS ========
    48 
    53 
    49 
    54 
    50 /*!
    55 /*!
    51             
       
    52     Constructor.
    56     Constructor.
    53     
    57     
    54     @param[in] itemDataHelper Helper from Control Panel for making connections.
    58     @param[in] itemDataHelper Helper from Control Panel for making connections.
    55     @param[in] parent Parent object.
    59     @param[in] parent Parent object.
    56  */
    60  */
    57 CpAddDestinationEntryItemData::CpAddDestinationEntryItemData(CpItemDataHelper &itemDataHelper,
    61 CpAddDestinationEntryItemData::CpAddDestinationEntryItemData(
    58                                                              CpDestinationGroup *parent)
    62     CpItemDataHelper &itemDataHelper,
    59     : CpSettingFormEntryItemData(CpSettingFormEntryItemData::ButtonEntryItem, itemDataHelper),
    63     CpDestinationGroup *parent) :
       
    64     CpSettingFormEntryItemData(CpSettingFormEntryItemData::ButtonEntryItem, itemDataHelper),
    60     mParent(parent),
    65     mParent(parent),
    61     mDialog(0)
    66     mDialog(0),
       
    67     mOkAction(NULL)
    62 {
    68 {
    63     OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_CPADDDESTINATIONENTRYITEMDATA_ENTRY);
    69     OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_CPADDDESTINATIONENTRYITEMDATA_ENTRY);
    64     OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_CPADDDESTINATIONENTRYITEMDATA_EXIT);
    70     OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_CPADDDESTINATIONENTRYITEMDATA_EXIT);
    65 }
    71 }
    66 
    72 
    78     new dialog is started for creating new destination.
    84     new dialog is started for creating new destination.
    79  */
    85  */
    80 void CpAddDestinationEntryItemData::onLaunchView()
    86 void CpAddDestinationEntryItemData::onLaunchView()
    81 {
    87 {
    82     OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_ONLAUNCHVIEW_ENTRY);
    88     OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_ONLAUNCHVIEW_ENTRY);
       
    89     
    83     mDialog = new HbInputDialog();
    90     mDialog = new HbInputDialog();
    84     mDialog->setAttribute(Qt::WA_DeleteOnClose);
    91     mDialog->setAttribute(Qt::WA_DeleteOnClose);
    85     mDialog->lineEdit()->setMaxLength(CMManagerShim::CmNameLength);
    92     mDialog->lineEdit()->setMaxLength(CMManagerShim::CmNameLength);
    86     mDialog->clearActions();
    93     mDialog->clearActions();
    87     mDialog->setPromptText(hbTrId("txt_occ_dialog_destination_name"));
    94     mDialog->setPromptText(hbTrId("txt_occ_dialog_destination_name"));
    88     mDialog->setInputMode(HbInputDialog::TextInput);
    95     mDialog->setInputMode(HbInputDialog::TextInput);
    89     mOkAction = new HbAction(
    96     mOkAction = new HbAction(
    90         hbTrId("txt_common_button_ok"),
    97         hbTrId("txt_common_button_ok"),
    91         mDialog);
    98         mDialog);
    92     bool connected = connect(mOkAction, 
    99     bool connected = connect(
    93                              SIGNAL(triggered()), 
   100         mOkAction, 
    94                              this, 
   101         SIGNAL(triggered()), 
    95                              SLOT(setNewDestinationName()));
   102         this, 
       
   103         SLOT(setNewDestinationName()));
    96     Q_ASSERT(connected);
   104     Q_ASSERT(connected);
    97     HbAction *cancelAction = new HbAction(
   105     HbAction *cancelAction = new HbAction(
    98         hbTrId("txt_common_button_cancel"),
   106         hbTrId("txt_common_button_cancel"),
    99         mDialog);
   107         mDialog);
   100     mDialog->addAction(mOkAction);
   108     mDialog->addAction(mOkAction);
   101     mDialog->addAction(cancelAction);
   109     mDialog->addAction(cancelAction);
   102     mDialog->show();
   110     mDialog->show();
       
   111     
   103     OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_ONLAUNCHVIEW_EXIT);
   112     OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_ONLAUNCHVIEW_EXIT);
   104 }
   113 }
   105 
   114 
   106 /*!
   115 /*!
   107     This function is called when user selects OK from destination
   116     This function is called when user selects OK from destination
   110     If validation fails user is promted again for destination name.
   119     If validation fails user is promted again for destination name.
   111  */
   120  */
   112 void CpAddDestinationEntryItemData::setNewDestinationName()
   121 void CpAddDestinationEntryItemData::setNewDestinationName()
   113 {
   122 {
   114     OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_SETNEWDESTINATIONNAME_ENTRY);
   123     OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_SETNEWDESTINATIONNAME_ENTRY);
       
   124     
   115     QString destinationName = mDialog->value().toString();
   125     QString destinationName = mDialog->value().toString();
   116     bool destinationNameInvalid = true;
   126     bool destinationNameValid = false;
   117     CmManagerShim *cmm = NULL;
   127     QSharedPointer<CmManagerShim> cmm;
   118     CmDestinationShim *destination = NULL;
   128     QSharedPointer<CmDestinationShim> destination;
   119     
   129     
   120     try {
   130     try {
   121         cmm = new CmManagerShim();
   131         cmm = QSharedPointer<CmManagerShim>(new CmManagerShim());
   122         if (isDestinationNameValid(destinationName, cmm)) {
   132         if (isDestinationNameValid(destinationName, cmm.data())) {
   123             // Destination name OK. Create new destination.
   133             // Destination name OK. Create new destination.
   124             destination = cmm->createDestination(destinationName);
   134             destination = QSharedPointer<CmDestinationShim>(
   125             destinationNameInvalid = false;
   135                 cmm->createDestination(destinationName));
       
   136             destinationNameValid = true;
   126         }
   137         }
   127     } catch (const std::exception&) {
   138     } catch (const std::exception&) {
   128         OstTrace0( TRACE_NORMAL, DUP2_CPADDDESTINATIONENTRYITEMDATA_SETNEWDESTINATIONNAME, "CpAddDestinationEntryItemData::setNewDestinationName: exception caught" );
   139         OstTrace0(
       
   140             TRACE_NORMAL,
       
   141             DUP2_CPADDDESTINATIONENTRYITEMDATA_SETNEWDESTINATIONNAME,
       
   142             "CpAddDestinationEntryItemData::setNewDestinationName: exception caught");
   129         return;
   143         return;
   130     }
   144     }
   131 
   145 
   132     if (!destinationNameInvalid) {
   146     if (destinationNameValid) {
   133         // Update view
   147         // Update view
   134         if (mParent != 0) {
   148         if (mParent != 0) {
   135             mParent->addDestination(destinationName, destination->id());
   149             mParent->addDestination(destinationName, destination);
   136         }                
   150         }                
   137     } else {
   151     } else {
   138         showErrorNote();
   152         showErrorNote();
   139     }
   153     }
   140     delete destination;
   154     
   141     delete cmm;
       
   142     OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_SETNEWDESTINATIONNAME_EXIT);
   155     OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_SETNEWDESTINATIONNAME_EXIT);
   143 }
   156 }
   144 
   157 
   145 /*!
   158 /*!
   146     Inherited member from CpSettingFormEntryItemData. This item does not
   159     Inherited member from CpSettingFormEntryItemData. This item does not
   161     
   174     
   162     @param[in] dest Name which user has entered to be the name of the new destination.
   175     @param[in] dest Name which user has entered to be the name of the new destination.
   163     @param[in] cmm Pointer to CmManagerShim for accessing data in commsdat.
   176     @param[in] cmm Pointer to CmManagerShim for accessing data in commsdat.
   164     \return true if name is valid.
   177     \return true if name is valid.
   165  */
   178  */
   166 bool CpAddDestinationEntryItemData::isDestinationNameValid(const QString dest, CmManagerShim *cmm) const
   179 bool CpAddDestinationEntryItemData::isDestinationNameValid(
       
   180     const QString dest,
       
   181     CmManagerShim *cmm) const
   167 {
   182 {
   168     OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_ISDESTINATIONNAMEVALID_ENTRY);
   183     OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_ISDESTINATIONNAMEVALID_ENTRY);
       
   184     
   169     bool retVal = true;
   185     bool retVal = true;
   170     
   186     
   171     if (dest.length() > 0) {
   187     if (dest.length() > 0) {
   172         QList<uint> destinationList;
   188         QList<uint> destinationList;
   173         cmm->allDestinations(destinationList);
   189         cmm->allDestinations(destinationList);
   174     
   190     
   175         for (int i = 0; i < destinationList.count(); i ++) {
   191         for (int i = 0; i < destinationList.count(); i ++) {
   176             CmDestinationShim *destination = cmm->destination(destinationList[i]);
   192             QScopedPointer<CmDestinationShim> destination(
       
   193                 cmm->destination(destinationList[i]));
   177             if (0 == dest.compare(destination->name())) {
   194             if (0 == dest.compare(destination->name())) {
   178                 retVal = false;
   195                 retVal = false;
   179                 delete destination;
       
   180                 break;
   196                 break;
   181             }
   197             }
   182             delete destination;
       
   183         }
   198         }
   184     } else {
   199     } else {
   185         retVal = false;
   200         retVal = false;
   186     }
   201     }
       
   202     
   187     OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_ISDESTINATIONNAMEVALID_EXIT);
   203     OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_ISDESTINATIONNAMEVALID_EXIT);
   188     return retVal;
   204     return retVal;
   189 }
   205 }
   190 
   206 
   191 /*!
   207 /*!
   193  * invalid destination name.
   209  * invalid destination name.
   194  */
   210  */
   195 void CpAddDestinationEntryItemData::showErrorNote()
   211 void CpAddDestinationEntryItemData::showErrorNote()
   196 {
   212 {
   197     OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_SHOWERRORNOTE_ENTRY);
   213     OstTraceFunctionEntry0(CPADDDESTINATIONENTRYITEMDATA_SHOWERRORNOTE_ENTRY);
       
   214     
   198     // Destination name NOK. Inform user and ask again.
   215     // Destination name NOK. Inform user and ask again.
   199     HbMessageBox *note = new HbMessageBox(HbMessageBox::MessageTypeInformation);
   216     HbMessageBox *note = new HbMessageBox(HbMessageBox::MessageTypeInformation);
   200     note->clearActions();
   217     note->clearActions();
   201     note->setAttribute(Qt::WA_DeleteOnClose);
   218     note->setAttribute(Qt::WA_DeleteOnClose);
   202     QString info = hbTrId("txt_occ_info_invalid_name");
   219     QString info = hbTrId("txt_occ_info_invalid_name");
   211         this,
   228         this,
   212         SLOT(onLaunchView()));
   229         SLOT(onLaunchView()));
   213     Q_ASSERT(connected);                        
   230     Q_ASSERT(connected);                        
   214     note->addAction(errorOk);
   231     note->addAction(errorOk);
   215     note->show();
   232     note->show();
       
   233     
   216     OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_SHOWERRORNOTE_EXIT);
   234     OstTraceFunctionExit0(CPADDDESTINATIONENTRYITEMDATA_SHOWERRORNOTE_EXIT);
   217 }
   235 }