15 * |
15 * |
16 */ |
16 */ |
17 #include "cntphonenumbermodel.h" |
17 #include "cntphonenumbermodel.h" |
18 #include "cntdetailconst.h" |
18 #include "cntdetailconst.h" |
19 #include "cntdetailmodelitem.h" |
19 #include "cntdetailmodelitem.h" |
|
20 #include "cntdetailorderinghelper.h" |
20 #include <hbdataformmodelitem.h> |
21 #include <hbdataformmodelitem.h> |
21 #include <QDebug> |
22 #include <QDebug> |
22 |
23 |
23 CntPhoneNumberModel::CntPhoneNumberModel( QContact* aContact, QObject* aParent ) : |
24 CntPhoneNumberModel::CntPhoneNumberModel( QContact* aContact, QObject* aParent ) : |
24 CntDetailEditorModel( aContact ) |
25 CntDetailEditorModel( aContact ) |
25 { |
26 { |
26 setParent( aParent ); |
27 setParent( aParent ); |
27 |
28 |
28 QList<QContactDetail> all; |
29 QList<QContactDetail> all; |
29 foreach ( QContactDetail detail, mContact->details<QContactPhoneNumber>() ) |
30 foreach ( QContactDetail detail, CntDetailOrderingHelper::getOrderedSupportedPhoneNumbers(*mContact) ) |
|
31 { |
30 all.append( detail ); |
32 all.append( detail ); |
|
33 mNumberList.append( detail ); |
|
34 } |
31 |
35 |
32 foreach ( QContactDetail detail, mContact->details<QContactOnlineAccount>() ) |
36 foreach ( QContactDetail detail, CntDetailOrderingHelper::getOrderedSupportedOnlineAccounts(*mContact) ) |
|
37 { |
33 all.append( detail ); |
38 all.append( detail ); |
|
39 mNumberList.append( detail ); |
|
40 } |
34 |
41 |
35 // if there's no details, add |
42 // if there's no details, add |
36 if ( all.isEmpty() ) |
43 if ( all.isEmpty() ) |
37 { |
44 { |
38 QContactPhoneNumber mobileNumber; |
45 mMobileTemplate.setSubTypes( QContactPhoneNumber::SubTypeMobile ); |
39 mobileNumber.setSubTypes( QContactPhoneNumber::SubTypeMobile ); |
46 all.append( mMobileTemplate ); |
40 all.append( mobileNumber ); |
|
41 |
47 |
42 QContactPhoneNumber landLineNumber; |
48 mLandlineTemplate.setSubTypes( QContactPhoneNumber::SubTypeLandline ); |
43 landLineNumber.setSubTypes( QContactPhoneNumber::SubTypeLandline ); |
49 all.append( mLandlineTemplate ); |
44 all.append( landLineNumber ); |
|
45 } |
50 } |
46 |
51 |
47 HbDataFormModelItem* root = invisibleRootItem(); |
52 HbDataFormModelItem* root = invisibleRootItem(); |
48 // add all phone numbers & online accounts to model |
53 // add all phone numbers & online accounts to model |
49 foreach ( QContactDetail contactDetail, all ) |
54 foreach ( QContactDetail contactDetail, all ) |
66 HbDataFormModelItem* root = invisibleRootItem(); |
71 HbDataFormModelItem* root = invisibleRootItem(); |
67 int count( root->childCount() ); |
72 int count( root->childCount() ); |
68 for ( int i = 0; i < count; i++ ) { |
73 for ( int i = 0; i < count; i++ ) { |
69 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( root->childAt(i) ); |
74 CntDetailModelItem* item = static_cast<CntDetailModelItem*>( root->childAt(i) ); |
70 QContactDetail detail = item->detail(); |
75 QContactDetail detail = item->detail(); |
71 mContact->saveDetail( &detail ); |
|
72 |
76 |
73 if ( detail.definitionName() == QContactPhoneNumber::DefinitionName ) |
77 if ( detail.definitionName() == QContactPhoneNumber::DefinitionName ) |
74 { |
78 { |
|
79 QContactPhoneNumber number = detail; |
|
80 if ( !mNumberList.contains(detail) ) |
|
81 { |
|
82 mContact->saveDetail( &detail ); |
|
83 } |
|
84 |
75 if ( detail.value(QContactPhoneNumber::FieldNumber).isEmpty() ) |
85 if ( detail.value(QContactPhoneNumber::FieldNumber).isEmpty() ) |
|
86 { |
|
87 // this won't change the pointer value if the detail does not exists in contact. |
|
88 // But, this is the situation in wk20... |
76 mContact->removeDetail( &detail ); |
89 mContact->removeDetail( &detail ); |
|
90 } |
77 } |
91 } |
78 |
92 |
79 if ( detail.definitionName() == QContactOnlineAccount::DefinitionName ) |
93 if ( detail.definitionName() == QContactOnlineAccount::DefinitionName ) |
80 { |
94 { |
81 if ( detail.value(QContactOnlineAccount::FieldAccountUri).isEmpty() ) |
95 QContactOnlineAccount account = detail; |
|
96 if ( !mNumberList.contains(detail) && !account.accountUri().isEmpty() ) |
|
97 { |
|
98 mContact->saveDetail( &detail ); |
|
99 } |
|
100 |
|
101 if ( account.accountUri().isEmpty() ) |
82 { |
102 { |
83 mContact->removeDetail( &detail ); |
103 mContact->removeDetail( &detail ); |
84 } |
104 } |
85 } |
105 } |
86 } |
106 } |