cmmanager/cpdestinationplugin/src/cpiapitem.cpp
changeset 23 7ec726f93df1
parent 20 9c97ad6591ae
child 27 489cf6208544
equal deleted inserted replaced
20:9c97ad6591ae 23:7ec726f93df1
    74     int iapId, 
    74     int iapId, 
    75     const QString &iapName, 
    75     const QString &iapName, 
    76     int destId,
    76     int destId,
    77     bool apProtected,
    77     bool apProtected,
    78     CpBearerApPluginInterface *bearerPlugin) :
    78     CpBearerApPluginInterface *bearerPlugin) :
    79     CpSettingFormEntryItemData(itemDataHelper), 
    79     CpSettingFormEntryItemData(CpSettingFormEntryItemData::ButtonEntryItem, itemDataHelper), 
       
    80     mItemDataHelper(&itemDataHelper),
    80     mIapId(iapId), 
    81     mIapId(iapId), 
    81     mIapName(iapName),
    82     mIapName(iapName),
    82     mDestId(destId),
    83     mDestId(destId),
    83     mProtected(apProtected),
       
    84     mBearerPlugin(bearerPlugin),
    84     mBearerPlugin(bearerPlugin),
    85     mMoveOngoing(false),
    85     mMoveOngoing(false),
    86     mDialog(0),
    86     mDialog(0),
    87     mList(0)
    87     mList(0)
    88 {
    88 {
    94         mCmm = NULL;
    94         mCmm = NULL;
    95     }
    95     }
    96     
    96     
    97     // Fix connections
    97     // Fix connections
    98     itemDataHelper.removeConnection(this,SIGNAL(pressed()),this,SLOT(onLaunchView()));
    98     itemDataHelper.removeConnection(this,SIGNAL(pressed()),this,SLOT(onLaunchView()));
    99     itemDataHelper.addConnection(
       
   100         this,
       
   101         SIGNAL(longPress(QPointF)),
       
   102         this,
       
   103         SLOT(showItemMenu(QPointF)));
       
   104     if (!apProtected) {
    99     if (!apProtected) {
       
   100         itemDataHelper.addConnection(
       
   101             this,
       
   102             SIGNAL(longPress(QPointF)),
       
   103             this,
       
   104             SLOT(showItemMenu(QPointF)));
   105         itemDataHelper.addConnection(this,SIGNAL(clicked()),this,SLOT(onLaunchView()));
   105         itemDataHelper.addConnection(this,SIGNAL(clicked()),this,SLOT(onLaunchView()));
   106     }
   106     }
   107     OstTraceFunctionExit0(CPIAPITEM_CPIAPITEM_EXIT);
   107     OstTraceFunctionExit0(CPIAPITEM_CPIAPITEM_EXIT);
   108 }
   108 }
   109 
   109 
   116     delete mCmm;
   116     delete mCmm;
   117     OstTraceFunctionExit0(DUP1_CPIAPITEM_CPIAPITEM_EXIT);
   117     OstTraceFunctionExit0(DUP1_CPIAPITEM_CPIAPITEM_EXIT);
   118 }
   118 }
   119 
   119 
   120 /*!
   120 /*!
   121     \return Returns ID of this access point
       
   122  */
       
   123 int CpIapItem::getIapId() const
       
   124 {
       
   125     OstTraceFunctionEntry0(CPIAPITEM_GETIAPID_ENTRY);
       
   126     OstTraceFunctionExit0(CPIAPITEM_GETIAPID_EXIT);
       
   127     return mIapId;
       
   128 }
       
   129 
       
   130 /*!
       
   131     Shows user the item specific menu. The menu is triggered by long pressing
   121     Shows user the item specific menu. The menu is triggered by long pressing
   132     the access point item.
   122     the access point item.
   133     
   123     
   134     @param[in] position Preferred position for the item specific menu.
   124     @param[in] position Preferred position for the item specific menu.
   135  */
   125  */
   136 void CpIapItem::showItemMenu(QPointF position)
   126 void CpIapItem::showItemMenu(QPointF position)
   137 {
   127 {
   138     OstTraceFunctionEntry0(CPIAPITEM_SHOWITEMMENU_ENTRY);
   128     OstTraceFunctionEntry0(CPIAPITEM_SHOWITEMMENU_ENTRY);
   139     if (isCmManagerAvailable()) {
   129     if (isCmManagerAvailable()) {
   140         bool settingsReadSuccessful = true;
   130         bool settingsReadSuccessful = true;
   141         CMManagerShim::CmmProtectionLevel protLvl;
   131         bool cmConnected = false;
   142         try {      
   132         try {
   143             if (mDestId == 0) {
   133             CmConnectionMethodShim *cm = mCmm->connectionMethod(mIapId);
   144                 protLvl = CMManagerShim::ProtLevel0;
   134             cmConnected = cm->getBoolAttribute(CMManagerShim::CmConnected);
   145             } else {
   135             delete cm;
   146                 CmDestinationShim *destination = mCmm->destination(mDestId);
       
   147                 protLvl = destination->protectionLevel();
       
   148                 delete destination;
       
   149             }              
       
   150         } 
   136         } 
   151         catch (const std::exception&)  {
   137         catch (const std::exception&)  {
   152             OstTrace0(TRACE_NORMAL, CPIAPITEM_SHOWITEMMENU, "CpIapItem::showItemMenu: Exception caught");
   138             OstTrace0(TRACE_NORMAL, CPIAPITEM_SHOWITEMMENU, "CpIapItem::showItemMenu: Exception caught");
   153             settingsReadSuccessful = false;
   139             settingsReadSuccessful = false;
   154         }
   140         }
   155         if (settingsReadSuccessful) {
   141         if (settingsReadSuccessful) {
   156             // Settings could be read from commsdat: show menu.
   142             // Settings could be read from commsdat: show menu.
   157             createItemMenu(protLvl, position)->show();
   143             createItemMenu(cmConnected, position)->show();
   158         }    
   144         }    
   159     }
   145     }
   160     OstTraceFunctionExit0(CPIAPITEM_SHOWITEMMENU_EXIT);
   146     OstTraceFunctionExit0(CPIAPITEM_SHOWITEMMENU_EXIT);
   161 }
   147 }
   162 
   148 
   246     } catch (const std::exception&) {
   232     } catch (const std::exception&) {
   247         OstTrace0(TRACE_NORMAL, DUP1_CPIAPITEM_DELETECONFIRMED, "CpIapItem::deleteConfirmed: Exception caught");
   233         OstTrace0(TRACE_NORMAL, DUP1_CPIAPITEM_DELETECONFIRMED, "CpIapItem::deleteConfirmed: Exception caught");
   248         deleteSuccessful = false;
   234         deleteSuccessful = false;
   249     }
   235     }
   250     if (deleteSuccessful) {
   236     if (deleteSuccessful) {
   251         HbDataForm *form = static_cast<HbDataForm*>(model()->parent());
   237         this->deleteLater();
   252         QModelIndex index = static_cast<HbDataFormModel*>(this->model())->indexFromItem(this);
       
   253         HbDataFormViewItem *viewItem = form->dataFormViewItem(index);
       
   254         viewItem->deleteLater();
       
   255         OstTrace0(TRACE_NORMAL, CPIAPITEM_DELETECONFIRMED, "CpIapItem::deleteConfirmed: Emit access point changed signal");
   238         OstTrace0(TRACE_NORMAL, CPIAPITEM_DELETECONFIRMED, "CpIapItem::deleteConfirmed: Emit access point changed signal");
   256         emit iapChanged();
   239         emit iapChanged();
   257     } else {
   240     } else {
   258         showErrorNote(hbTrId("txt_occ_info_unable_to_save_setting"));
   241         showErrorNote(hbTrId("txt_occ_info_unable_to_save_setting"));
   259     }
   242     }
   274     } catch (const std::exception&) {
   257     } catch (const std::exception&) {
   275         OstTrace0( TRACE_NORMAL, CPIAPITEM_UPDATEIAP, "CpIapItem::updateIap: exception caught, CM name reading failed" );
   258         OstTrace0( TRACE_NORMAL, CPIAPITEM_UPDATEIAP, "CpIapItem::updateIap: exception caught, CM name reading failed" );
   276     }
   259     }
   277     // Disconnect because we need to do this only after returning
   260     // Disconnect because we need to do this only after returning
   278     // from accees point settings view
   261     // from accees point settings view
   279     HbDataForm *form = static_cast<HbDataForm*>(model()->parent());
   262     CpItemDataHelper *itemDataHelper = new CpItemDataHelper();
   280     disconnect(
   263     itemDataHelper->disconnectFromForm( 
   281         form, 
       
   282         SIGNAL(itemShown(const QModelIndex)),
   264         SIGNAL(itemShown(const QModelIndex)),
   283         this, 
   265         this, 
   284         SLOT(updateIap(const QModelIndex)));
   266         SLOT(updateIap(const QModelIndex)));
       
   267     delete itemDataHelper;
   285     OstTrace0( TRACE_FLOW, DUP1_CPIAPITEM_UPDATEIAP_EXIT, "CpIapItem::updateIap exit" );
   268     OstTrace0( TRACE_FLOW, DUP1_CPIAPITEM_UPDATEIAP_EXIT, "CpIapItem::updateIap exit" );
   286 }
   269 }
   287 
   270 
   288 /*!
   271 /*!
   289     Gets access point specific view from bearer plugin.
   272     Gets access point specific view from bearer plugin.
   292  */
   275  */
   293 CpBaseSettingView *CpIapItem::createSettingView() const
   276 CpBaseSettingView *CpIapItem::createSettingView() const
   294 {
   277 {
   295     OstTraceFunctionEntry0(CPIAPITEM_CREATESETTINGVIEW_ENTRY);
   278     OstTraceFunctionEntry0(CPIAPITEM_CREATESETTINGVIEW_ENTRY);
   296     CpBaseSettingView *view = NULL;
   279     CpBaseSettingView *view = NULL;
       
   280     CpItemDataHelper *itemDataHelper = new CpItemDataHelper();
   297     if (mBearerPlugin != NULL) {
   281     if (mBearerPlugin != NULL) {
   298         HbDataForm *form = static_cast<HbDataForm*>(model()->parent()); 
   282         CpIapItem *iap = const_cast<CpIapItem*>(this);
   299         bool connected = connect(
   283         itemDataHelper->connectToForm( 
   300             form, 
       
   301             SIGNAL(itemShown(const QModelIndex)),
   284             SIGNAL(itemShown(const QModelIndex)),
   302             this, 
   285             iap, 
   303             SLOT(updateIap(const QModelIndex)));
   286             SLOT(updateIap(const QModelIndex)));
   304         Q_ASSERT(connected);
       
   305         view = mBearerPlugin->createSettingView(mIapId);
   287         view = mBearerPlugin->createSettingView(mIapId);
   306     }
   288     }
       
   289     delete itemDataHelper;
   307     OstTraceFunctionExit0(CPIAPITEM_CREATESETTINGVIEW_EXIT);
   290     OstTraceFunctionExit0(CPIAPITEM_CREATESETTINGVIEW_EXIT);
   308     return view;
   291     return view;
   309 }
   292 }
   310 
   293 
   311 /*!
   294 /*!
   372 void CpIapItem::saveShare(int id)
   355 void CpIapItem::saveShare(int id)
   373 {
   356 {
   374     OstTraceFunctionEntry0(CPIAPITEM_SAVESHARE_ENTRY);
   357     OstTraceFunctionEntry0(CPIAPITEM_SAVESHARE_ENTRY);
   375     try {
   358     try {
   376         CmConnectionMethodShim *cm;
   359         CmConnectionMethodShim *cm;
   377         if (mDestId != 0) {
   360         CmDestinationShim *source = mCmm->destination(mDestId);
   378             CmDestinationShim *source = mCmm->destination(mDestId);
   361         cm = source->connectionMethodByID(mIapId);
   379             cm = source->connectionMethodByID(mIapId);
   362         delete source;
   380             delete source;
       
   381         } else {
       
   382             cm = mCmm->connectionMethod(mIapId);
       
   383         }
       
   384         CmDestinationShim *target = mCmm->destination(id);
   363         CmDestinationShim *target = mCmm->destination(id);
   385         target->addConnectionMethod(cm);
   364         target->addConnectionMethod(cm);
   386         target->update();
   365         target->update();
   387         delete cm;
   366         delete cm;
   388         delete target;
   367         delete target;
   459     
   438     
   460     @param[in] protLvl Effective protection level for this
   439     @param[in] protLvl Effective protection level for this
   461                        access point.
   440                        access point.
   462  */
   441  */
   463 HbMenu *CpIapItem::createItemMenu(
   442 HbMenu *CpIapItem::createItemMenu(
   464     CMManagerShim::CmmProtectionLevel protLvl,
   443     bool cmConnected,
   465     const QPointF &position)
   444     const QPointF &position)
   466 {
   445 {
   467     OstTraceFunctionEntry0(CPIAPITEM_CREATEITEMMENU_ENTRY);
   446     OstTraceFunctionEntry0(CPIAPITEM_CREATEITEMMENU_ENTRY);
   468     HbMenu* menu = new HbMenu();
   447     HbMenu* menu = new HbMenu();
   469     menu->setAttribute(Qt::WA_DeleteOnClose);
   448     menu->setAttribute(Qt::WA_DeleteOnClose);
   482     HbAction* shareIapAction 
   461     HbAction* shareIapAction 
   483         = menu->addAction(hbTrId("txt_occ_menu_share_to_other_destination"));
   462         = menu->addAction(hbTrId("txt_occ_menu_share_to_other_destination"));
   484     connected = connect(shareIapAction, SIGNAL(triggered()), this, SLOT(shareIap()));
   463     connected = connect(shareIapAction, SIGNAL(triggered()), this, SLOT(shareIap()));
   485     Q_ASSERT(connected);
   464     Q_ASSERT(connected);
   486        
   465        
   487     if (protLvl == CMManagerShim::ProtLevel1) {
   466     if (cmConnected) {
   488         // Disable operations for protected destinations
   467         // Disable operations for connected APs
   489         moveIapAction->setDisabled(true);
   468         moveIapAction->setDisabled(true);
   490         deleteIapAction->setDisabled(true);
   469         deleteIapAction->setDisabled(true);
   491         shareIapAction->setDisabled(true);
   470         shareIapAction->setDisabled(true);
   492     } else if (protLvl == CMManagerShim::ProtLevel3) {
       
   493         // Disable operations for protected access points.
       
   494         moveIapAction->setDisabled(mProtected);
       
   495         deleteIapAction->setDisabled(mProtected);
       
   496         shareIapAction->setDisabled(mProtected);
       
   497     }
   471     }
   498     
   472     
   499     // Can't share uncategorised APs
   473     // Can't share uncategorised APs
   500     if (mDestId == 0)
   474     if (mDestId == 0)
   501     {
   475     {