cmmanager/cpdestinationplugin/src/cpdestinationentryitem.cpp
changeset 20 9c97ad6591ae
child 23 7ec726f93df1
child 28 860702281757
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
       
     1 /*
       
     2 * Copyright (c) 2010 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 *   This items represents one Destination in UI.
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <HbDataForm>
       
    20 #include <HbDataFormModel>
       
    21 #include <HbToolBar>
       
    22 #include <HbAction>
       
    23 #include <HbDataFormViewItem>
       
    24 #include <HbMenu>
       
    25 #include <HbListDialog>
       
    26 #include <HbInputDialog>
       
    27 #include <HbMessageBox>
       
    28 #include <HbPopup>
       
    29 #include <HbListWidget>
       
    30 #include <HbListWidgetItem>
       
    31 #include <HbMainWindow>
       
    32 #include <cppluginutility.h>
       
    33 #include <cpitemdatahelper.h>
       
    34 #include <cpbasesettingview.h>
       
    35 #include <cmdestination_shim.h>
       
    36 #include <cmconnectionmethod_shim.h>
       
    37 #include <cmmanager_shim.h>
       
    38 
       
    39 // User includes
       
    40 #include "cpiapitem.h"
       
    41 #include "cpdestinationentryitem.h"
       
    42 #include "cpdestinationgroup.h"
       
    43 #include "OstTraceDefinitions.h"
       
    44 #ifdef OST_TRACE_COMPILER_IN_USE
       
    45 #include "cpdestinationentryitemTraces.h"
       
    46 #endif
       
    47 /*!
       
    48     \class  CpDestinationEntryItemData
       
    49     \brief  This class represents destination in data model. 
       
    50             It takes care of all destination related operations.
       
    51 */
       
    52 
       
    53 // External function prototypes
       
    54 
       
    55 // Local constants
       
    56 
       
    57 // ======== LOCAL FUNCTIONS ========
       
    58 
       
    59 // ======== MEMBER FUNCTIONS ========
       
    60 
       
    61 /*!         
       
    62     Constructor.
       
    63     
       
    64     @param[in] itemDataHelper Helper for connecting signals and slots.
       
    65  */
       
    66 CpDestinationEntryItemData::CpDestinationEntryItemData(CpItemDataHelper &itemDataHelper)
       
    67     : CpSettingFormEntryItemData(itemDataHelper),
       
    68     mDialog(0),
       
    69     mOkAction(0)
       
    70 {
       
    71     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_CPDESTINATIONENTRYITEMDATA_ENTRY);
       
    72     mAps = new QList<CpIapItem*>();
       
    73     try {
       
    74         mCmm = new CmManagerShim();
       
    75     } catch (const std::exception&) {
       
    76         OstTrace0(TRACE_NORMAL, CPDESTINATIONENTRYITEMDATA_CPDESTINATIONENTRYITEMDATA, "CpDestinationEntryItemData::CpDestinationEntryItemData: Exception caught");
       
    77         mCmm = NULL;
       
    78     }
       
    79     mList = new HbListWidget();
       
    80     bool connectionSuccessful = connect(
       
    81         mList,
       
    82         SIGNAL(released(HbListWidgetItem *)),
       
    83         this,
       
    84         SLOT(updateIndex(HbListWidgetItem*)));
       
    85     Q_ASSERT(connectionSuccessful);
       
    86     
       
    87     // Fix connections
       
    88     itemDataHelper.removeConnection(this,SIGNAL(pressed()),this,SLOT(onLaunchView()));
       
    89     itemDataHelper.addConnection(this,SIGNAL(clicked()),this,SLOT(onLaunchView()));
       
    90     itemDataHelper.addConnection(this,SIGNAL(longPress(QPointF)),this,SLOT(showItemMenu(QPointF)));
       
    91     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_CPDESTINATIONENTRYITEMDATA_EXIT);
       
    92 }
       
    93 
       
    94 /*!
       
    95     Destructor
       
    96  */
       
    97 CpDestinationEntryItemData::~CpDestinationEntryItemData()
       
    98 {
       
    99     OstTraceFunctionEntry0(DUP1_CPDESTINATIONENTRYITEMDATA_CPDESTINATIONENTRYITEMDATA_ENTRY);
       
   100     delete mList;
       
   101     delete mCmm;
       
   102     delete mAps;
       
   103     delete mOkAction;
       
   104     OstTraceFunctionExit0(DUP1_CPDESTINATIONENTRYITEMDATA_CPDESTINATIONENTRYITEMDATA_EXIT);
       
   105 }
       
   106 
       
   107 /*!
       
   108     \return unique destination ID of this item.
       
   109  */
       
   110 int CpDestinationEntryItemData::destinationId()
       
   111 {
       
   112     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_DESTINATIONID_ENTRY);
       
   113     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_DESTINATIONID_EXIT);
       
   114     return mDestinationId;
       
   115 }
       
   116 
       
   117 /*!
       
   118     Sets destination ID to be given integer.
       
   119  */
       
   120 void CpDestinationEntryItemData::setDestinationId(int destId)
       
   121 {
       
   122     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_SETDESTINATIONID_ENTRY);
       
   123     mDestinationId = destId;
       
   124     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_SETDESTINATIONID_EXIT);
       
   125 }
       
   126 
       
   127 /*!
       
   128     \return Returns destination name as QString
       
   129  */
       
   130 QString CpDestinationEntryItemData::destinationName()
       
   131 {
       
   132     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_DESTINATIONNAME_ENTRY);
       
   133     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_DESTINATIONNAME_EXIT);
       
   134     return mDestinationName;
       
   135 }
       
   136 
       
   137 /*!
       
   138     Sets given QString to be destination name.
       
   139  */
       
   140 void CpDestinationEntryItemData::setDestinationName(const QString destinationName)
       
   141 {
       
   142     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_SETDESTINATIONNAME_ENTRY);
       
   143     mDestinationName = destinationName;
       
   144     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_SETDESTINATIONNAME_EXIT);
       
   145 }
       
   146 
       
   147 /*!
       
   148     Inherited member from CpSettingFormEntryItemData. Returns view that contains
       
   149     all access points included in this destination item.
       
   150  */
       
   151 CpBaseSettingView *CpDestinationEntryItemData::createSettingView() const
       
   152 {
       
   153     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_CREATESETTINGVIEW_ENTRY);
       
   154     CpBaseSettingView* view = new CpBaseSettingView();
       
   155     constructSettingView(view);
       
   156     
       
   157     // Toolbar. Allow arrange if more than one AP is shown
       
   158     if (mDestinationId != 0 && mAps->count() > 1) {
       
   159         HbToolBar *tb = view->toolBar();
       
   160         HbAction *arrangeAction = tb->addAction(hbTrId("txt_occ_button_arrange"));
       
   161         bool connected = connect(
       
   162             arrangeAction, 
       
   163             SIGNAL(triggered()), 
       
   164             this, 
       
   165             SLOT(activateArrangeMode()));
       
   166         Q_ASSERT(connected);
       
   167     }
       
   168     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_CREATESETTINGVIEW_EXIT);
       
   169     return view;        
       
   170 }
       
   171 
       
   172 /*!
       
   173     Worker function for createSettingView(). Adds Access points to given view.
       
   174     
       
   175      @param[out] view Target view where settings are constructed.
       
   176  */
       
   177 void CpDestinationEntryItemData::constructSettingView(CpBaseSettingView *view) const
       
   178 {
       
   179     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_CONSTRUCTSETTINGVIEW_ENTRY);
       
   180     mAps->clear();
       
   181     CpItemDataHelper *itemDataHelper = new CpItemDataHelper();
       
   182     HbDataForm *form = new HbDataForm();
       
   183     HbDataFormModel *model = new HbDataFormModel;
       
   184     form->setModel(model);
       
   185     model->setParent(form);
       
   186     view->setWidget(form);
       
   187     CpPluginUtility::addCpItemPrototype(form);
       
   188     QList<QSharedPointer<CmConnectionMethodShim> > apList;
       
   189     // Following won't throw exception
       
   190     fetchReferencedAps(apList, mCmm);
       
   191     form->setHeading(text());
       
   192 
       
   193     for (int i = 0; i < apList.count(); i++) {
       
   194         int apId = apList[i]->getIntAttribute(CMManagerShim::CmId);
       
   195         CpBearerApPluginInterface *bearerPlugin = 
       
   196                 static_cast<CpDestinationGroup*>(HbDataFormModelItem::parent())->findBearerPlugin(apId);
       
   197         bool apProtected = false;
       
   198         if (mDestinationId != 0) {
       
   199             CmDestinationShim *destination = mCmm->destination(mDestinationId);
       
   200             if (destination->protectionLevel() == CMManagerShim::ProtLevel3) {
       
   201                 apProtected = apList[i]->getBoolAttribute(CMManagerShim::CmProtected);
       
   202             }
       
   203             delete destination;
       
   204         }
       
   205         
       
   206         CpIapItem *iapDataItem;
       
   207         iapDataItem = new CpIapItem(
       
   208             *itemDataHelper, 
       
   209             apId, 
       
   210             apList[i]->getStringAttribute(CMManagerShim::CmName), 
       
   211             mDestinationId,
       
   212             apProtected,
       
   213             bearerPlugin);
       
   214        
       
   215         // Add name to item
       
   216         iapDataItem->setContentWidgetData(
       
   217             QString("text"), 
       
   218             apList[i]->getStringAttribute(CMManagerShim::CmName));
       
   219        
       
   220         // Add priority to item if not Uncategorised "Destination"
       
   221         if (mDestinationId  != 0) {
       
   222             // Access Points are listed in priority order.
       
   223             QString priority = hbTrId("txt_occ_dblist_val_priority_l1", i);
       
   224             iapDataItem->setContentWidgetData(QString("additionalText"), priority);
       
   225         }
       
   226         
       
   227         // Set item disabled if it is protected
       
   228         if (apProtected) {
       
   229             iapDataItem->setContentWidgetData(QString("enabled"), false);
       
   230         }
       
   231         
       
   232         // Add to model
       
   233         model->appendDataFormItem(iapDataItem);
       
   234         
       
   235         // Save and make connections
       
   236         mAps->append(iapDataItem);
       
   237         bool connected 
       
   238             = connect(iapDataItem, SIGNAL(iapChanged()), this, SLOT(updateDestinationView()));
       
   239         Q_ASSERT(connected);
       
   240     }
       
   241     
       
   242     itemDataHelper->bindToForm(form);
       
   243     delete itemDataHelper;
       
   244     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_CONSTRUCTSETTINGVIEW_EXIT);
       
   245 }
       
   246 
       
   247 /*!
       
   248     Rebuilds view with access points after access points have changed.
       
   249  */
       
   250 void CpDestinationEntryItemData::updateDestinationView()
       
   251 {
       
   252     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_UPDATEDESTINATIONVIEW_ENTRY);
       
   253     HbDataForm *form = static_cast<HbDataForm*>(model()->parent()); 
       
   254     HbMainWindow *mainWnd = form->mainWindow();
       
   255        
       
   256     if (mainWnd) {
       
   257         HbView *view = mainWnd->currentView();
       
   258         CpBaseSettingView  *cpView = static_cast<CpBaseSettingView  *>(view);
       
   259         constructSettingView(cpView);
       
   260         
       
   261         // Remove Toolbar if necessary
       
   262         if (mDestinationId != 0 && mAps->count() <= 1) {
       
   263             HbToolBar *tb = view->toolBar();
       
   264             tb->clearActions();
       
   265         }
       
   266     }
       
   267     OstTrace0(TRACE_NORMAL, CPDESTINATIONENTRYITEMDATA_UPDATEDESTINATIONVIEW, "CpDestinationEntryItemData::updateDestinationView: Emit destination changed");
       
   268     emit destChanged();
       
   269     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_UPDATEDESTINATIONVIEW_EXIT);
       
   270 }
       
   271 
       
   272 /*!
       
   273     Prompts user for action after long tap. Choices for actions are "Rename" and "Delete".
       
   274     
       
   275     @param[in] position The item specific menu is shown in given position.
       
   276  */
       
   277 void CpDestinationEntryItemData::showItemMenu(QPointF position)
       
   278 {
       
   279     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_SHOWITEMMENU_ENTRY);
       
   280     if (mDestinationId != 0) {
       
   281         CmDestinationShim *destination = NULL;
       
   282         CMManagerShim::CmmProtectionLevel protLvl = CMManagerShim::ProtLevel1;
       
   283         
       
   284         try {
       
   285             destination = mCmm->destination(mDestinationId);
       
   286             protLvl = destination->protectionLevel();
       
   287             delete destination;
       
   288         } catch (const std::exception&) {
       
   289             OstTrace0(TRACE_NORMAL, CPDESTINATIONENTRYITEMDATA_SHOWITEMMENU, "CpDestinationEntryItemData::showItemMenu: Exception caught");
       
   290             if (destination != NULL) {
       
   291                 delete destination;
       
   292             }
       
   293         }
       
   294         
       
   295         HbMenu *menu = createItemMenu(protLvl, position);
       
   296         menu->show();
       
   297     }
       
   298     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_SHOWITEMMENU_EXIT);
       
   299 }
       
   300 
       
   301 /*!
       
   302     Prompts user for new destination name and makes 
       
   303     the change in commsdat if new name is valid.
       
   304     
       
   305     \sa isDestinationNameValid()
       
   306  */
       
   307 void CpDestinationEntryItemData::renameDestination()
       
   308 {    
       
   309     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_RENAMEDESTINATION_ENTRY);
       
   310     mDialog = new HbInputDialog();
       
   311     mDialog->setAttribute(Qt::WA_DeleteOnClose);
       
   312     mDialog->lineEdit()->setMaxLength(DestinationNameMaxLength);
       
   313     mDialog->clearActions();
       
   314     mDialog->setPromptText(hbTrId("txt_occ_dialog_destination_name"));
       
   315     mDialog->setInputMode(HbInputDialog::TextInput);
       
   316     mOkAction = new HbAction(hbTrId("txt_common_button_ok"));
       
   317     bool connected = connect(mOkAction, 
       
   318                              SIGNAL(triggered()), 
       
   319                              this, 
       
   320                              SLOT(saveNewDestinationName()));
       
   321     Q_ASSERT(connected);
       
   322     HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
       
   323     mDialog->addAction(mOkAction);
       
   324     mDialog->addAction(cancelAction);
       
   325     mDialog->show();
       
   326     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_RENAMEDESTINATION_EXIT);
       
   327 }
       
   328 
       
   329 /*!
       
   330     Shows confirmation query for user before deleteting destination.
       
   331     \sa deleteDestination()
       
   332  */
       
   333 void CpDestinationEntryItemData::confirmDestinationDelete()
       
   334 {
       
   335     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_CONFIRMDESTINATIONDELETE_ENTRY);
       
   336     HbMessageBox *note = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
       
   337     note->setAttribute(Qt::WA_DeleteOnClose);
       
   338     note->setText(hbTrId("txt_occ_info_delete_snap").arg(mDestinationName));
       
   339     note->clearActions();
       
   340     HbAction *okAction = new HbAction(hbTrId("txt_common_button_yes"));
       
   341     note->addAction(okAction);
       
   342     bool connected = connect(
       
   343         okAction, 
       
   344         SIGNAL(triggered()), 
       
   345         this, 
       
   346         SLOT(deleteDestination()));
       
   347     Q_ASSERT(connected);
       
   348     HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_no"));
       
   349     note->addAction(cancelAction);
       
   350     note->setTimeout(HbPopup::NoTimeout);
       
   351     note->show();
       
   352     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_CONFIRMDESTINATIONDELETE_EXIT);
       
   353 }
       
   354 
       
   355 /*!
       
   356     Destination is deleted after user chooses "OK" from destination deletion
       
   357     confirmation query.
       
   358     \sa confirmDestinationDelete()
       
   359  */
       
   360 void CpDestinationEntryItemData::deleteDestination()
       
   361 {
       
   362     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_DELETEDESTINATION_ENTRY);
       
   363     CmDestinationShim *destination = NULL;
       
   364     CmConnectionMethodShim *cm = NULL;
       
   365     try {
       
   366         destination = mCmm->destination(mDestinationId);
       
   367         int cmCount = destination->connectionMethodCount();
       
   368         while (cmCount > 0) {
       
   369             cm = destination->connectionMethod(0);
       
   370             destination->removeConnectionMethod(cm);
       
   371             cmCount--;
       
   372             delete cm;
       
   373             cm = NULL;
       
   374         }
       
   375         destination->update();
       
   376         destination->deleteDestination();
       
   377         CpDestinationGroup *parent 
       
   378             = static_cast<CpDestinationGroup *>(HbDataFormModelItem::parent());
       
   379         parent->deleteDestination(mDestinationId);
       
   380         delete destination;
       
   381     } catch (const std::exception&) {
       
   382         OstTrace0(TRACE_NORMAL, CPDESTINATIONENTRYITEMDATA_DELETEDESTINATION, "CpDestinationEntryItemData::deleteDestination: Exception caught");
       
   383         if (destination != NULL) {
       
   384             delete destination;
       
   385         }
       
   386         if (cm != NULL) {
       
   387             delete cm;
       
   388         }
       
   389         showErrorNote(hbTrId("txt_occ_info_unable_to_save_setting"));
       
   390     }
       
   391     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_DELETEDESTINATION_EXIT);
       
   392 }
       
   393 
       
   394 /*!
       
   395     Creates new view where access point priorities can 
       
   396     be changed by dragging and dropping and shows it to user.
       
   397  */
       
   398 void CpDestinationEntryItemData::activateArrangeMode()
       
   399 {
       
   400     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_ACTIVATEARRANGEMODE_ENTRY);
       
   401     mList = new HbListWidget();
       
   402     HbDataForm *form = static_cast<HbDataForm*>(model()->parent());             
       
   403     HbMainWindow *mainWnd = form->mainWindow();
       
   404     HbView *view = new HbView();
       
   405     createArrangeModeView(view);
       
   406     
       
   407     if (mainWnd && view) {
       
   408         mPreView = mainWnd->currentView();
       
   409         mainWnd->addView(view);
       
   410         mainWnd->setCurrentView(view, false);
       
   411         HbAction *arrangeViewBackAction = new HbAction(Hb::BackAction, view);
       
   412         bool connected = connect(
       
   413             arrangeViewBackAction, 
       
   414             SIGNAL(triggered()), 
       
   415             this, 
       
   416             SLOT(viewCancel()));
       
   417         Q_ASSERT(connected);
       
   418         view->setNavigationAction(arrangeViewBackAction);
       
   419     }
       
   420     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_ACTIVATEARRANGEMODE_EXIT);
       
   421 }
       
   422 
       
   423 /*!
       
   424     This function is called when user returns from arrange mode with
       
   425     toolbar command "Done" thus accapting the changes. New priorities
       
   426     are saved to commsdat according to order of the items in the previous view.
       
   427  */
       
   428 void CpDestinationEntryItemData::viewDone()
       
   429 {
       
   430     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_VIEWDONE_ENTRY);
       
   431     try {
       
   432         // Arrange items
       
   433         CmDestinationShim *destination = mCmm->destination(mDestinationId);
       
   434         for (int i = 0; i < mList->count(); i++) {
       
   435             int apId = mList->item(i)->data(Hb::IndexFeedbackRole).toInt();
       
   436             CmConnectionMethodShim *cm = mCmm->connectionMethod(apId);
       
   437             destination->modifyPriority(cm,i);
       
   438             delete cm;
       
   439         }
       
   440         destination->update();
       
   441         delete destination;
       
   442     } catch (const std::exception&) {
       
   443         OstTrace0(TRACE_NORMAL, CPDESTINATIONENTRYITEMDATA_VIEWDONE, "CpDestinationEntryItemData::viewDone: Exception caught");
       
   444         viewCancel();
       
   445         showErrorNote(QString("txt_occ_info_unable_to_save_setting"));
       
   446         OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_VIEWDONE_EXIT);
       
   447         return;
       
   448     }
       
   449     
       
   450     HbDataForm *form = static_cast<HbDataForm*>(model()->parent());
       
   451     HbMainWindow *mainWnd = form->mainWindow();
       
   452     HbView* view = mainWnd->currentView();
       
   453     
       
   454     if (mainWnd && view)  {
       
   455         //restore previous status
       
   456         mainWnd->removeView(view);
       
   457         mainWnd->setCurrentView(mPreView);
       
   458         mPreView = NULL;
       
   459     }
       
   460     updateDestinationView();
       
   461     OstTraceFunctionExit0(DUP1_CPDESTINATIONENTRYITEMDATA_VIEWDONE_EXIT);
       
   462 }
       
   463 
       
   464 /*!
       
   465     User returns from view without accepting the changes to priorities.
       
   466  */
       
   467 void CpDestinationEntryItemData::viewCancel()
       
   468 {
       
   469     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_VIEWCANCEL_ENTRY);
       
   470     HbDataForm *form = static_cast<HbDataForm*>(model()->parent());
       
   471     HbMainWindow *mainWnd = form->mainWindow();
       
   472     HbView* view = mainWnd->currentView();
       
   473     
       
   474     if (mainWnd && view) {
       
   475         //restore previous status
       
   476         mainWnd->removeView(view);
       
   477         view->deleteLater();
       
   478         mainWnd->setCurrentView(mPreView);
       
   479         mPreView = NULL;
       
   480     }
       
   481     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_VIEWCANCEL_EXIT);
       
   482 }
       
   483 
       
   484 /*!
       
   485     This function updates access points priorities shown in UI
       
   486     when user is in arrange mode.
       
   487     
       
   488     @param[in] widgetItem Unused.
       
   489     
       
   490     \sa activateArrangeMode()
       
   491  */
       
   492 void CpDestinationEntryItemData::updateIndex(HbListWidgetItem *widgetItem)
       
   493 {
       
   494     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_UPDATEINDEX_ENTRY);
       
   495     Q_UNUSED(widgetItem);
       
   496     for (int i = 0; i < mList->count(); i++) {
       
   497         HbListWidgetItem *item = mList->item(i);
       
   498         QString priority = hbTrId("txt_occ_dblist_val_priority_l1", i);
       
   499         item->setSecondaryText(priority);
       
   500     }
       
   501     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_UPDATEINDEX_EXIT);
       
   502 }
       
   503 
       
   504 /*!
       
   505     This function searches all connection methods from commsdat that are
       
   506     connected to this destination item. Connection methods are returned in
       
   507     apList reference parameter.
       
   508     
       
   509     @param[out] apList Constains list of this destination's accesspoints.
       
   510     @param[in] cmm Pointer to CmManagerShim instance to avoid multiple session openings.
       
   511  */
       
   512 void CpDestinationEntryItemData::fetchReferencedAps(
       
   513     QList<QSharedPointer<CmConnectionMethodShim> > &apList, 
       
   514     const CmManagerShim *cmm) const
       
   515 {   
       
   516     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_FETCHREFERENCEDAPS_ENTRY);
       
   517     CmDestinationShim *destination = NULL;
       
   518     try {
       
   519         if (mDestinationId == 0) {
       
   520             QList<uint> apIds;
       
   521             cmm->connectionMethod(apIds);
       
   522             for (int i = 0; i < apIds.count(); i++) {
       
   523                 CmConnectionMethodShim *cm;
       
   524                 cm = cmm->connectionMethod(apIds.at(i));
       
   525                 apList.append(QSharedPointer<CmConnectionMethodShim>(cm));
       
   526             }
       
   527         } else {
       
   528             destination = cmm->destination(mDestinationId);
       
   529             int apCount = destination->connectionMethodCount();
       
   530             for (int i = 0; i < apCount; i++) {
       
   531                 CmConnectionMethodShim *cm = NULL;
       
   532                 cm = destination->connectionMethod(i);
       
   533                 apList.append(QSharedPointer<CmConnectionMethodShim>(cm));
       
   534             }
       
   535             delete destination;
       
   536         }
       
   537     } catch (const std::exception&) {
       
   538         OstTrace0(TRACE_NORMAL, CPDESTINATIONENTRYITEMDATA_FETCHREFERENCEDAPS, "CpDestinationEntryItemData::fetchReferencedAps: Exception caught");
       
   539         if (destination != NULL) {
       
   540             delete destination;
       
   541         }
       
   542     }
       
   543     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_FETCHREFERENCEDAPS_EXIT);
       
   544 }
       
   545 
       
   546 /*!
       
   547     Function for checking if the given destination name is valid. Duplicate and
       
   548     and empty names are rejected.
       
   549     
       
   550     @param[out] destination Constains the destination name to be validated. If name 
       
   551                 is valid it remains unchanged. If the given name is invalid, appropriate
       
   552                 error text is set the variable.
       
   553     @param[in] cmm Pointer to CmManagerShim instance to avoid multiple session openings.
       
   554     
       
   555     \return true if name is valid.
       
   556  */
       
   557 bool CpDestinationEntryItemData::isDestinationNameValid(
       
   558     QString &destination, 
       
   559     const CmManagerShim *cmm)
       
   560 {
       
   561     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_ISDESTINATIONNAMEVALID_ENTRY);
       
   562     bool retVal = true;
       
   563     
       
   564     if (destination.length() > 0) {
       
   565         QList<uint> destinationList;
       
   566         cmm->allDestinations(destinationList);
       
   567     
       
   568         for (int i = 0; i < destinationList.count(); i ++) {
       
   569             CmDestinationShim *dest = cmm->destination(destinationList[i]);
       
   570             if (0 == destination.compare(dest->name())) {
       
   571                 destination = hbTrId("txt_occ_info_name_already_in_use");
       
   572                 retVal = false;
       
   573                 break;
       
   574             }
       
   575             delete dest;
       
   576         }
       
   577     } else {
       
   578         destination = hbTrId("txt_occ_info_invalid_name");
       
   579         retVal = false;
       
   580     }
       
   581     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_ISDESTINATIONNAMEVALID_EXIT);
       
   582     return retVal;
       
   583 }
       
   584 
       
   585 /*!
       
   586     Worker function for activateArrangeMode(). Adds list of access points
       
   587     to given view.
       
   588     
       
   589     @param[out] view Target view where the arrange mode is constructed.
       
   590 
       
   591     \sa activateArrangeMode()
       
   592  */
       
   593 void CpDestinationEntryItemData::createArrangeModeView(HbView *view)
       
   594 {
       
   595     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_CREATEARRANGEMODEVIEW_ENTRY);
       
   596     QList<QSharedPointer<CmConnectionMethodShim> >  apList;
       
   597     fetchReferencedAps(apList, mCmm);   
       
   598     CmDestinationShim *destination = NULL;
       
   599     
       
   600     try {
       
   601         destination = mCmm->destination(mDestinationId);
       
   602         for (int i = 0; i < apList.count(); i++) {
       
   603             HbListWidgetItem *item = new HbListWidgetItem();
       
   604             item->setText(apList[i]->getStringAttribute(CMManagerShim::CmName));
       
   605             item->setData(apList[i]->getIntAttribute(CMManagerShim::CmId), Hb::IndexFeedbackRole);
       
   606 
       
   607             uint pri = destination->priority(apList[i].data());
       
   608             QString priority = hbTrId("txt_occ_dblist_val_priority_l1", pri);
       
   609             item->setSecondaryText(priority);
       
   610         
       
   611             mList->addItem(item);
       
   612         }
       
   613         mList->setArrangeMode(true);
       
   614         view->setWidget(mList);
       
   615                 
       
   616         // Toolbar
       
   617         HbToolBar *tb = view->toolBar();
       
   618         HbAction *doneAction = tb->addAction(hbTrId("txt_common_button_ok"));
       
   619         bool connected = connect(
       
   620             doneAction, 
       
   621             SIGNAL(triggered()), 
       
   622             this, 
       
   623             SLOT(viewDone()));
       
   624         Q_ASSERT(connected);
       
   625         delete destination;
       
   626     } catch (const std::exception&) {
       
   627         OstTrace0(TRACE_NORMAL, CPDESTINATIONENTRYITEMDATA_CREATEARRANGEMODEVIEW, "CpDestinationEntryItemData::createArrangeModeView: Exception caught");
       
   628         // return empty view
       
   629         if (destination != NULL) {
       
   630             delete destination;
       
   631         }
       
   632         while (mList->count() > 0) {
       
   633             HbListWidgetItem *item = mList->item(0);
       
   634             delete item;
       
   635         }
       
   636         mList->clear();
       
   637     }
       
   638     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_CREATEARRANGEMODEVIEW_EXIT);
       
   639 }
       
   640 
       
   641 /*!
       
   642     Helper function for creating item specific menu.
       
   643     
       
   644     @param[in] protLvl Effective protection level for this
       
   645                        access point.
       
   646  */
       
   647 HbMenu *CpDestinationEntryItemData::createItemMenu(
       
   648     CMManagerShim::CmmProtectionLevel protLvl,
       
   649     const QPointF position)
       
   650 {
       
   651     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_CREATEITEMMENU_ENTRY);
       
   652     HbMenu *menu = new HbMenu();
       
   653     menu->setAttribute(Qt::WA_DeleteOnClose);
       
   654     HbAction *renameDestAction = menu->addAction(hbTrId("txt_common_menu_rename_item"));
       
   655     bool connected = 
       
   656         connect(renameDestAction, SIGNAL(triggered()), this, SLOT(renameDestination()));
       
   657     Q_ASSERT(connected);
       
   658     HbAction *deleteDestAction = menu->addAction(hbTrId("txt_common_menu_delete"));
       
   659     connected = 
       
   660         connect(deleteDestAction, SIGNAL(triggered()), this, SLOT(confirmDestinationDelete()));
       
   661     Q_ASSERT(connected);
       
   662                      
       
   663     if (protLvl == CMManagerShim::ProtLevel1
       
   664          || protLvl == CMManagerShim::ProtLevel2 ) {
       
   665     
       
   666         // Disable operations for protected destinations
       
   667         renameDestAction->setDisabled(true);
       
   668         deleteDestAction->setDisabled(true);
       
   669     }
       
   670         
       
   671     menu->setModal(true);
       
   672     menu->setPreferredPos(position);
       
   673     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_CREATEITEMMENU_EXIT);
       
   674     return menu;
       
   675 }
       
   676 
       
   677 /*!
       
   678     This function is called when user selects OK from destination
       
   679     name query popup. The given name is valited and if the name is
       
   680     valid, new destination is created in commsdat with given name.
       
   681     If validation fails user is promted again for destination name.
       
   682  */
       
   683 void CpDestinationEntryItemData::saveNewDestinationName()
       
   684 {
       
   685     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_SAVENEWDESTINATIONNAME_ENTRY);
       
   686     QString destinationName = mDialog->value().toString();
       
   687     bool destinationNameInvalid = true;
       
   688     CmManagerShim *cmm = NULL;
       
   689     CmDestinationShim *destination = NULL;
       
   690     
       
   691     try {
       
   692         cmm = new CmManagerShim();
       
   693         if (isDestinationNameValid(destinationName, cmm)) {
       
   694             cmm = new CmManagerShim();
       
   695             cmm->destination(mDestinationId)->setName(destinationName);
       
   696             mDestinationName = destinationName;
       
   697             destinationNameInvalid = false;
       
   698         }
       
   699     } catch (const std::exception&) {
       
   700         OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_SAVENEWDESTINATIONNAME_EXIT);
       
   701         return;
       
   702     }
       
   703     delete destination;
       
   704     delete cmm;
       
   705     
       
   706     if (destinationNameInvalid) {   
       
   707         // Validation function has modified destination name 
       
   708         // to be error string
       
   709         showRenameError(destinationName);
       
   710     } else {
       
   711         OstTrace0(TRACE_NORMAL, CPDESTINATIONENTRYITEMDATA_SAVENEWDESTINATIONNAME, "CpDestinationEntryItemData::saveNewDestinationName: emit destination changed");
       
   712         emit destChanged();
       
   713     }
       
   714     OstTraceFunctionExit0(DUP1_CPDESTINATIONENTRYITEMDATA_SAVENEWDESTINATIONNAME_EXIT);
       
   715 }
       
   716 
       
   717 /*!
       
   718  * Helper function for showing error note when user inputs
       
   719  * invalid destination name.
       
   720  */
       
   721 void CpDestinationEntryItemData::showRenameError(const QString &info)
       
   722 {
       
   723     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_SHOWRENAMEERROR_ENTRY);
       
   724     // Destination name NOK. Inform user and ask again.
       
   725     HbMessageBox *note = new HbMessageBox(HbMessageBox::MessageTypeInformation);
       
   726     note->clearActions();
       
   727     note->setAttribute(Qt::WA_DeleteOnClose);
       
   728     note->setText(info);
       
   729     note->setTimeout(HbPopup::NoTimeout);
       
   730     HbAction *errorOk = new HbAction(hbTrId("txt_common_button_ok"));
       
   731     bool connected = connect(
       
   732         errorOk,
       
   733         SIGNAL(triggered()),
       
   734         this,
       
   735         SLOT(renameDestination()));
       
   736     Q_ASSERT(connected);                        
       
   737     note->addAction(errorOk);
       
   738     note->show();
       
   739     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_SHOWRENAMEERROR_EXIT);
       
   740 }
       
   741 
       
   742 /*!
       
   743     Helper function for showing error notes.
       
   744     
       
   745     @param[in] info Info string to be shown in note.
       
   746  */
       
   747 void CpDestinationEntryItemData::showErrorNote(const QString &info)
       
   748 {
       
   749     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_SHOWERRORNOTE_ENTRY);
       
   750     HbMessageBox *note = new HbMessageBox(HbMessageBox::MessageTypeInformation);
       
   751     note->clearActions();
       
   752     note->setAttribute(Qt::WA_DeleteOnClose);
       
   753     note->setText(info);
       
   754     note->setTimeout(HbPopup::NoTimeout);
       
   755     HbAction *errorOk = new HbAction(hbTrId("txt_common_button_ok"));                       
       
   756     note->addAction(errorOk);
       
   757     note->show();    
       
   758     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_SHOWERRORNOTE_EXIT);
       
   759 }