cmmanager/cpdestinationplugin/src/cpdestinationentryitem.cpp
changeset 46 95d45f234cf3
parent 27 489cf6208544
child 47 cb7afde124a3
--- a/cmmanager/cpdestinationplugin/src/cpdestinationentryitem.cpp	Thu May 27 13:17:01 2010 +0300
+++ b/cmmanager/cpdestinationplugin/src/cpdestinationentryitem.cpp	Wed Jun 23 18:39:24 2010 +0300
@@ -93,7 +93,6 @@
     OstTraceFunctionEntry0(DUP1_CPDESTINATIONENTRYITEMDATA_CPDESTINATIONENTRYITEMDATA_ENTRY);
     delete mCmm;
     delete mAps;
-    delete mOkAction;
     OstTraceFunctionExit0(DUP1_CPDESTINATIONENTRYITEMDATA_CPDESTINATIONENTRYITEMDATA_EXIT);
 }
 
@@ -150,13 +149,9 @@
     // Toolbar. Allow arrange if more than one AP is shown
     if (mDestinationId != 0 && mAps->count() > 1) {
         HbToolBar *tb = view->toolBar();
-        HbAction *arrangeAction = tb->addAction(hbTrId("txt_occ_button_arrange"));
-        bool connected = connect(
-            arrangeAction, 
-            SIGNAL(triggered()), 
-            this, 
-            SLOT(activateArrangeMode()));
-        Q_ASSERT(connected);
+        HbIcon arrangeIcon("qtg_mono_sort");
+        HbAction *arrangeAction 
+            = tb->addAction(arrangeIcon, "", this, SLOT(activateArrangeMode()));
     }
     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_CREATESETTINGVIEW_EXIT);
     return view;        
@@ -212,12 +207,18 @@
         iapDataItem->setContentWidgetData(
             QString("text"), 
             apList[i]->getStringAttribute(CMManagerShim::CmName));
+        
+        // Add Icon if found
+        HbIcon iapIcon(resolveApIcon(apList[i]));
+        iapDataItem->setEntryItemIcon(iapIcon);
        
         // Add priority to item if not Uncategorised "Destination"
         if (mDestinationId  != 0) {
             // Access Points are listed in priority order.
-            QString priority = hbTrId("txt_occ_dblist_val_priority_l1", i);
+            QString priority = hbTrId("txt_occ_dblist_val_priority_l1").arg(i + 1);
             iapDataItem->setContentWidgetData(QString("additionalText"), priority);
+        } else {
+            iapDataItem->setContentWidgetData(QString("stretched"), true);
         }
         
         // Set item disabled if it is protected
@@ -294,6 +295,14 @@
 }
 
 /*!
+   Opens selected destination.
+ */
+void CpDestinationEntryItemData::openDestination()
+{    
+    onLaunchView();
+}
+
+/*!
     Prompts user for new destination name and makes 
     the change in commsdat if new name is valid.
     
@@ -304,17 +313,22 @@
     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_RENAMEDESTINATION_ENTRY);
     mDialog = new HbInputDialog();
     mDialog->setAttribute(Qt::WA_DeleteOnClose);
-    mDialog->lineEdit()->setMaxLength(DestinationNameMaxLength);
+    mDialog->lineEdit()->setMaxLength(CMManagerShim::CmNameLength);
     mDialog->clearActions();
     mDialog->setPromptText(hbTrId("txt_occ_dialog_destination_name"));
     mDialog->setInputMode(HbInputDialog::TextInput);
-    mOkAction = new HbAction(hbTrId("txt_common_button_ok"));
+    mDialog->setValue(mDestinationName);
+    mOkAction = new HbAction(
+        hbTrId("txt_common_button_ok"),
+        mDialog);
     bool connected = connect(mOkAction, 
                              SIGNAL(triggered()), 
                              this, 
                              SLOT(saveNewDestinationName()));
     Q_ASSERT(connected);
-    HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
+    HbAction *cancelAction = new HbAction(
+        hbTrId("txt_common_button_cancel"),
+        mDialog);
     mDialog->addAction(mOkAction);
     mDialog->addAction(cancelAction);
     mDialog->show();
@@ -332,7 +346,9 @@
     note->setAttribute(Qt::WA_DeleteOnClose);
     note->setText(hbTrId("txt_occ_info_delete_snap").arg(mDestinationName));
     note->clearActions();
-    HbAction *okAction = new HbAction(hbTrId("txt_common_button_yes"));
+    HbAction *okAction = new HbAction(
+        hbTrId("txt_common_button_yes"),
+        note);
     note->addAction(okAction);
     bool connected = connect(
         okAction, 
@@ -340,7 +356,9 @@
         this, 
         SLOT(deleteDestination()));
     Q_ASSERT(connected);
-    HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_no"));
+    HbAction *cancelAction = new HbAction(
+        hbTrId("txt_common_button_no"),
+        note);
     note->addAction(cancelAction);
     note->setTimeout(HbPopup::NoTimeout);
     note->show();
@@ -397,13 +415,7 @@
     HbMainWindow *mainWnd = mainWindows.front();
     HbView *view = new HbView();
     createArrangeModeView(view);
-    
-    bool connectionSuccessful = connect(
-            mList,
-            SIGNAL(released(HbListWidgetItem*)),
-            this,
-            SLOT(updateIndex(HbListWidgetItem*)));
-    Q_ASSERT(connectionSuccessful);
+    mList->installEventFilter(this);
     
     if (mainWnd && view) {
         mPreView = mainWnd->currentView();
@@ -454,6 +466,7 @@
     
     if (mainWnd && view)  {
         //restore previous status
+        mList->removeEventFilter(this);
         mainWnd->removeView(view);
         mainWnd->setCurrentView(mPreView);
         mPreView = NULL;
@@ -474,6 +487,7 @@
     
     if (mainWnd && view) {
         //restore previous status
+        mList->removeEventFilter(this);
         mainWnd->removeView(view);
         view->deleteLater();
         mainWnd->setCurrentView(mPreView);
@@ -486,17 +500,14 @@
     This function updates access points priorities shown in UI
     when user is in arrange mode.
     
-    @param[in] widgetItem Unused.
-    
     \sa activateArrangeMode()
  */
-void CpDestinationEntryItemData::updateIndex(HbListWidgetItem *widgetItem)
+void CpDestinationEntryItemData::updateIndex()
 {
     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_UPDATEINDEX_ENTRY);
-    Q_UNUSED(widgetItem);
     for (int i = 0; i < mList->count(); i++) {
         HbListWidgetItem *item = mList->item(i);
-        QString priority = hbTrId("txt_occ_dblist_val_priority_l1", i);
+        QString priority = hbTrId("txt_occ_dblist_val_priority_l1").arg(i + 1);
         item->setSecondaryText(priority);
     }
     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_UPDATEINDEX_EXIT);
@@ -609,8 +620,11 @@
             item->setData(apList[i]->getIntAttribute(CMManagerShim::CmId), Hb::IndexFeedbackRole);
 
             uint pri = destination->priority(apList[i].data());
-            QString priority = hbTrId("txt_occ_dblist_val_priority_l1", pri);
+            QString priority = hbTrId("txt_occ_dblist_val_priority_l1").arg(pri);
             item->setSecondaryText(priority);
+            
+            HbIcon iapIcon(resolveApIcon(apList[i]));
+            item->setIcon(iapIcon);
         
             mList->addItem(item);
         }
@@ -630,13 +644,9 @@
     }
     // Toolbar
     HbToolBar *tb = view->toolBar();
-    HbAction *doneAction = tb->addAction(hbTrId("txt_common_button_ok"));
-    bool connected = connect(
-        doneAction, 
-        SIGNAL(triggered()), 
-        this, 
-        SLOT(viewDone()));
-    Q_ASSERT(connected);
+    HbIcon okIcon("qtg_mono_tick");
+    HbAction *doneAction 
+        = tb->addAction(okIcon, "", this, SLOT(viewDone()));
     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_CREATEARRANGEMODEVIEW_EXIT);
 }
 
@@ -653,8 +663,12 @@
     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_CREATEITEMMENU_ENTRY);
     HbMenu *menu = new HbMenu();
     menu->setAttribute(Qt::WA_DeleteOnClose);
+    HbAction *openDestAction = menu->addAction(hbTrId("txt_common_menu_open"));
+    bool connected = 
+        connect(openDestAction, SIGNAL(triggered()), this, SLOT(openDestination()));
+    Q_ASSERT(connected);
     HbAction *renameDestAction = menu->addAction(hbTrId("txt_common_menu_rename_item"));
-    bool connected = 
+    connected = 
         connect(renameDestAction, SIGNAL(triggered()), this, SLOT(renameDestination()));
     Q_ASSERT(connected);
     HbAction *deleteDestAction = menu->addAction(hbTrId("txt_common_menu_delete"));
@@ -678,41 +692,44 @@
 
 /*!
     This function is called when user selects OK from destination
-    name query popup. The given name is valited and if the name is
-    valid, new destination is created in commsdat with given name.
-    If validation fails user is promted again for destination name.
+    name query popup. The given name is validated and if the name is
+    valid, new destination name is saved to commsdat. If validation fails
+    user is prompted again for destination name.
  */
 void CpDestinationEntryItemData::saveNewDestinationName()
 {
     OstTraceFunctionEntry0(CPDESTINATIONENTRYITEMDATA_SAVENEWDESTINATIONNAME_ENTRY);
     QString destinationName = mDialog->value().toString();
-    bool destinationNameInvalid = true;
-    CmManagerShim *cmm = NULL;
-    CmDestinationShim *destination = NULL;
-    
-    try {
-        cmm = new CmManagerShim();
-        if (isDestinationNameValid(destinationName, cmm)) {
-            destination = cmm->destination(mDestinationId);
-            destination->setName(destinationName);
-            destination->update();
-            mDestinationName = destinationName;
-            destinationNameInvalid = false;
+    if (destinationName != mDestinationName) {
+        // Destination name was changed
+        bool destinationNameInvalid = true;
+        CmManagerShim *cmm = NULL;
+        CmDestinationShim *destination = NULL;
+        
+        try {
+            cmm = new CmManagerShim();
+            if (isDestinationNameValid(destinationName, cmm)) {
+                destination = cmm->destination(mDestinationId);
+                destination->setName(destinationName);
+                destination->update();
+                mDestinationName = destinationName;
+                destinationNameInvalid = false;
+            }
+        } catch (const std::exception&) {
+            OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_SAVENEWDESTINATIONNAME_EXIT);
+            return;
         }
-    } catch (const std::exception&) {
-        OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_SAVENEWDESTINATIONNAME_EXIT);
-        return;
-    }
-    delete destination;
-    delete cmm;
-    
-    if (destinationNameInvalid) {   
-        // Validation function has modified destination name 
-        // to be error string
-        showRenameError(destinationName);
-    } else {
-        OstTrace0(TRACE_NORMAL, CPDESTINATIONENTRYITEMDATA_SAVENEWDESTINATIONNAME, "CpDestinationEntryItemData::saveNewDestinationName: emit destination changed");
-        emit destChanged();
+        delete destination;
+        delete cmm;
+        
+        if (destinationNameInvalid) {   
+            // Validation function has modified destination name 
+            // to be error string
+            showRenameError(destinationName);
+        } else {
+            OstTrace0(TRACE_NORMAL, CPDESTINATIONENTRYITEMDATA_SAVENEWDESTINATIONNAME, "CpDestinationEntryItemData::saveNewDestinationName: emit destination changed");
+            emit destChanged();
+        }
     }
     OstTraceFunctionExit0(DUP1_CPDESTINATIONENTRYITEMDATA_SAVENEWDESTINATIONNAME_EXIT);
 }
@@ -730,7 +747,9 @@
     note->setAttribute(Qt::WA_DeleteOnClose);
     note->setText(info);
     note->setTimeout(HbPopup::NoTimeout);
-    HbAction *errorOk = new HbAction(hbTrId("txt_common_button_ok"));
+    HbAction *errorOk = new HbAction(
+        hbTrId("txt_common_button_ok"),
+        note);
     bool connected = connect(
         errorOk,
         SIGNAL(triggered()),
@@ -755,8 +774,51 @@
     note->setAttribute(Qt::WA_DeleteOnClose);
     note->setText(info);
     note->setTimeout(HbPopup::NoTimeout);
-    HbAction *errorOk = new HbAction(hbTrId("txt_common_button_ok"));                       
+    HbAction *errorOk = new HbAction(
+        hbTrId("txt_common_button_ok"),
+        note);
     note->addAction(errorOk);
     note->show();    
     OstTraceFunctionExit0(CPDESTINATIONENTRYITEMDATA_SHOWERRORNOTE_EXIT);
 }
+
+/*!
+    Helper function for showing icons.
+    
+    \return Returns string representing given destination's icon
+ */
+QString CpDestinationEntryItemData::resolveApIcon(QSharedPointer<CmConnectionMethodShim> cm) const
+{
+    QString result(cm->getIcon());
+    
+    if (result.isEmpty()) {
+        uint bearerType = cm->getIntAttribute(CMManagerShim::CmBearerType);
+        switch (bearerType) {
+            case CMManagerShim::BearerTypeWlan:
+                result = "qtg_small_wlan";
+                break;
+            case CMManagerShim::BearerTypePacketData:
+                result = "qtg_small_gprs";
+                break;
+            default:
+                // Unknown bearer type
+                break;
+        }
+    }
+    return result;
+}
+
+/*!
+    Event filter for updating priorities when arrange mode is active.
+    
+    \return Returns false so that event gets forwarded
+ */
+bool CpDestinationEntryItemData::eventFilter(QObject *object, QEvent *event)
+{
+    Q_UNUSED(object);
+    if (event->type() == QEvent::GraphicsSceneMouseRelease) {
+        updateIndex();
+    }
+    return false;
+}
+