phonebookui/pbkcommonui/src/cnteditview_p.cpp
changeset 37 fd64c38c277d
parent 31 2a11b5b00470
child 40 b46a585f6909
equal deleted inserted replaced
31:2a11b5b00470 37:fd64c38c277d
    32 #include <hblistview.h>
    32 #include <hblistview.h>
    33 #include <hbaction.h>
    33 #include <hbaction.h>
    34 #include <hbmenu.h>
    34 #include <hbmenu.h>
    35 #include <hbframebackground.h>
    35 #include <hbframebackground.h>
    36 #include <hbparameterlengthlimiter.h>
    36 #include <hbparameterlengthlimiter.h>
       
    37 #include <hbnotificationdialog.h>
    37 
    38 
    38 const char *CNT_EDIT_XML = ":/xml/contacts_ev.docml";
    39 const char *CNT_EDIT_XML = ":/xml/contacts_ev.docml";
    39 
    40 
    40 CntEditViewPrivate::CntEditViewPrivate() :
    41 CntEditViewPrivate::CntEditViewPrivate() :
    41 mModel( NULL ),
    42 mModel( NULL ),
   120     {
   121     {
   121         connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
   122         connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
   122         setOrientation(window->orientation());
   123         setOrientation(window->orientation());
   123     }
   124     }
   124         
   125         
   125     QVariant selectedAction = mArgs.value( EMyCard );
   126     QString myCard = mArgs.value( EMyCard ).toString();
   126     QString myCard = selectedAction.toString();
   127     QString selectedAction = mArgs.value( ESelectedAction ).toString();
   127     
   128     
   128     QVariant contact = aArgs.value( ESelectedContact );
   129     QVariant contact = aArgs.value( ESelectedContact );
   129     mContact = new QContact( contact.value<QContact>() );
   130     mContact = new QContact( contact.value<QContact>() );
   130     QContactLocalId localId = mContact->localId();
   131     QContactLocalId localId = mContact->localId();
   131     
   132     
   180 }
   181 }
   181 
   182 
   182 void CntEditViewPrivate::deactivate()
   183 void CntEditViewPrivate::deactivate()
   183 {   
   184 {   
   184 }
   185 }
       
   186 
       
   187 void CntEditViewPrivate::openView(CntViewParameters& viewParams)
       
   188 {
       
   189     QList<int> keys = viewParams.keys();
       
   190     for(int i = 0;i < keys.count();i++)
       
   191     {
       
   192         mArgs.insert(keys.at(i), viewParams.value(keys.at(i)));
       
   193     }
       
   194     mMgr->changeView( mArgs );
       
   195 }
       
   196 
       
   197 void CntEditViewPrivate::requestRefresh()
       
   198 {
       
   199     mModel->refreshExtensionItems();
       
   200 }
   185     
   201     
   186 void CntEditViewPrivate::activated( const QModelIndex& aIndex )
   202 void CntEditViewPrivate::activated( const QModelIndex& aIndex )
   187 {
   203 {
   188     CntEditViewItem* item = mModel->itemAt( aIndex );
   204     CntEditViewItem* item = mModel->itemAt( aIndex );
   189     QVariant type = item->data( ERoleItemType );
   205     QVariant type = item->data( ERoleItemType );
   190     if ( type == QVariant(ETypeUiExtension) )
   206     if ( type == QVariant(ETypeUiExtension) )
   191     {
   207     {
   192         item->activated();
   208         item->activated(this);
   193         mModel->refreshExtensionItems( aIndex );
       
   194     }
   209     }
   195     else
   210     else
   196     {
   211     {
   197         // open editor view
   212         // open editor view
   198         QVariant id = item->data( ERoleEditorViewId );
   213         QVariant id = item->data( ERoleEditorViewId );
   212     QVariant type = item->data( ERoleItemType );
   227     QVariant type = item->data( ERoleItemType );
   213     
   228     
   214     // Ui extensions handle the long press by themselves.
   229     // Ui extensions handle the long press by themselves.
   215     if ( type == QVariant(ETypeUiExtension) )
   230     if ( type == QVariant(ETypeUiExtension) )
   216     {
   231     {
   217         item->longPressed( aCoords );
   232         item->longPressed( aCoords, this );
   218         mModel->refreshExtensionItems( aItem->modelIndex() );
       
   219     }
   233     }
   220     // only detail items are able to show context specific menu
   234     // only detail items are able to show context specific menu
   221     else
   235     else
   222     {
   236     {
   223         HbMenu* menu = createPopup( aItem->modelIndex(), item );
   237         HbMenu* menu = createPopup( aItem->modelIndex(), item );
   233     int row = aAction->data().toInt();
   247     int row = aAction->data().toInt();
   234     QModelIndex index = mModel->index(row, 0);
   248     QModelIndex index = mModel->index(row, 0);
   235     CntEditViewItem* item = mModel->itemAt( index );
   249     CntEditViewItem* item = mModel->itemAt( index );
   236     if ( aAction )
   250     if ( aAction )
   237     {
   251     {
   238         switch ( aAction->commandRole() )  
   252         switch ( aAction->property("menu").toInt() )  
   239         {
   253         {
   240         case HbAction::EditRole:
   254         case HbAction::EditRole:
   241         {
   255         {
   242             editDetail( item );
   256             editDetail( item );
   243         }
   257         }
   380                 bool success = mgr->saveContact( mContact );
   394                 bool success = mgr->saveContact( mContact );
   381                 if ( success && mIsMyCard )
   395                 if ( success && mIsMyCard )
   382                 {
   396                 {
   383                     mgr->setSelfContactId( mContact->localId() );
   397                     mgr->setSelfContactId( mContact->localId() );
   384                 }
   398                 }
       
   399                 
       
   400                 emit contactUpdated(success);
       
   401                 
       
   402                 QString name = mgr->synthesizedDisplayLabel( *mContact );
       
   403                 
       
   404                 if ( success )
       
   405                 {
       
   406                     HbNotificationDialog::launchDialog(HbParameterLengthLimiter("txt_phob_dpophead_contact_1_saved").arg(name));
       
   407                 }
       
   408                 else
       
   409                 {
       
   410                     //TODO: localization is missing
       
   411                     HbNotificationDialog::launchDialog(qtTrId("SAVING FAILED!"));
       
   412                 }
       
   413                 
   385                 QVariant var;
   414                 QVariant var;
   386                 var.setValue(*mContact);
   415                 var.setValue(*mContact);
   387                 mArgs.insert(ESelectedContact, var);
   416                 mArgs.insert(ESelectedContact, var);
   388                 mArgs.insert( ESelectedAction, success ? "save" : "failed" );
   417             }        
   389                 emit contactUpdated(success);
       
   390             }
       
   391         }
   418         }
   392         else
   419         else
   393         {
   420         {
   394             // contact details has been cleared out.
   421             // contact details has been cleared out.
   395             if ( detailCount <= 4 )
   422             if ( detailCount <= 4 )
   398                 // and show the delete notification to user
   425                 // and show the delete notification to user
   399                 QContact c = mgr->contact( mContact->localId() );
   426                 QContact c = mgr->contact( mContact->localId() );
   400                 
   427                 
   401                 bool success = mgr->removeContact( mContact->localId() );
   428                 bool success = mgr->removeContact( mContact->localId() );
   402                 emit contactRemoved(success);
   429                 emit contactRemoved(success);
   403                 if ( success )
       
   404                 {
       
   405                     mArgs.insert( ESelectedAction, "delete" );
       
   406                     QVariant contact;
       
   407                     contact.setValue( c );
       
   408                     mArgs.insert( ESelectedContact, contact );
       
   409                 }
       
   410             }
   430             }
   411             else
   431             else
   412             {
   432             {
   413                 bool success = mgr->saveContact(mContact);
   433                 bool success = mgr->saveContact(mContact);
   414                 mArgs.insert( ESelectedAction, success ? "save" : "failed");
   434                 
       
   435                 emit contactUpdated( success );
       
   436                 
       
   437                 QString name = mgr->synthesizedDisplayLabel( *mContact );
       
   438                 
       
   439                 if ( success )
       
   440                 {
       
   441                     HbNotificationDialog::launchDialog(HbParameterLengthLimiter("txt_phob_dpophead_contacts_1_updated").arg(name));
       
   442                 }
       
   443                 else
       
   444                 {
       
   445                     //TODO: localization is missing
       
   446                     HbNotificationDialog::launchDialog(qtTrId("SAVING FAILED!"));
       
   447                 }
   415                 
   448                 
   416                 QVariant var;
   449                 QVariant var;
   417                 var.setValue(*mContact);
   450                 var.setValue(*mContact);
   418                 mArgs.insert(ESelectedContact, var);
   451                 mArgs.insert(ESelectedContact, var);           
   419                     
       
   420                 emit contactUpdated( success );
       
   421             }
   452             }
   422         }
   453         }
   423     }
   454     }
   424     else
   455     else
   425     {
   456     {
   500              def == QContactOnlineAccount::DefinitionName ||
   531              def == QContactOnlineAccount::DefinitionName ||
   501              def == QContactEmailAddress::DefinitionName  ||
   532              def == QContactEmailAddress::DefinitionName  ||
   502              def == QContactUrl::DefinitionName || 
   533              def == QContactUrl::DefinitionName || 
   503              def == QContactNote::DefinitionName )
   534              def == QContactNote::DefinitionName )
   504         {
   535         {
   505             HbAction* add = menu->addAction(HbParameterLengthLimiter(
   536             HbAction* add = menu->addAction(map->getContactEditorAddLocString(detail.definitionName(), ""));
   506                     map->getContactEditorAddLocString(detail.definitionName(), "")));
   537             add->setProperty( "menu", HbAction::NewRole );
   507             add->setCommandRole( HbAction::NewRole );
       
   508             add->setData( data );
   538             add->setData( data );
   509         }
   539         }
   510         
   540         
   511         QString context;
   541         QString context;
   512         QString subtype;
   542         QString subtype;
   530         else
   560         else
   531         {
   561         {
   532             context = QString();
   562             context = QString();
   533             subtype = detail.definitionName();
   563             subtype = detail.definitionName();
   534         }
   564         }
   535             HbAction* edit = menu->addAction(HbParameterLengthLimiter(map->getContactEditorEditLocString(subtype, context)));
   565         
   536             HbAction* del = menu->addAction(HbParameterLengthLimiter(map->getContactEditorDelLocString(subtype, context)));
   566         HbAction* edit = menu->addAction(hbTrId("txt_common_menu_edit"));
   537             edit->setCommandRole( HbAction::EditRole );
   567         HbAction* del = menu->addAction(map->getContactEditorDelLocString(subtype, context));
   538             del->setCommandRole( HbAction::DeleteRole );
   568         edit->setProperty( "menu", HbAction::EditRole );
   539             edit->setData( data );
   569         del->setProperty( "menu" , HbAction::DeleteRole );
   540             del->setData( data );
   570         edit->setData( data );
       
   571         del->setData( data );
   541     }
   572     }
   542     else
   573     else
   543     {
   574     {
   544         HbAction* edit = menu->addAction(HbParameterLengthLimiter(map->getContactEditorEditLocString(detail.definitionName(), "")));
   575         HbAction* add = menu->addAction(map->getContactEditorAddLocString(detail.definitionName(), ""));
   545         edit->setCommandRole( HbAction::EditRole );
   576         add->setProperty( "menu", HbAction::NewRole );
   546         edit->setData( data );
   577         add->setData( data );
   547     }
   578     }
   548     
   579     
   549     return menu;
   580     return menu;
   550 }
   581 }
   551 
   582