1 #include "qmlcontact.h" |
|
2 #include <qcontactname.h> |
|
3 #include <QtDebug> |
|
4 |
|
5 |
|
6 QT_USE_NAMESPACE |
|
7 QTM_USE_NAMESPACE |
|
8 |
|
9 QTM_BEGIN_NAMESPACE |
|
10 |
|
11 QmlContact::QmlContact(QContact& contact, QObject *parent) |
|
12 : QObject(parent), m_contact(contact) |
|
13 { |
|
14 } |
|
15 |
|
16 QmlContact::QmlContact() |
|
17 { |
|
18 |
|
19 } |
|
20 |
|
21 QmlContact::~QmlContact() |
|
22 { |
|
23 |
|
24 } |
|
25 |
|
26 QContact &QmlContact::contact() |
|
27 { |
|
28 return m_contact; |
|
29 } |
|
30 |
|
31 void QmlContact::setContact(QContact& contact) |
|
32 { |
|
33 m_contact = contact; |
|
34 emit contactChanged(this); |
|
35 } |
|
36 |
|
37 QString QmlContact::name() |
|
38 { |
|
39 QList<QContactDetail> allNames = m_contact.details(QContactName::DefinitionName); |
|
40 |
|
41 const QLatin1String space(" "); |
|
42 |
|
43 // synthesise the display label from the name. |
|
44 for (int i=0; i < allNames.size(); i++) { |
|
45 const QContactName& name = allNames.at(i); |
|
46 |
|
47 QString result; |
|
48 if (!name.value(QContactName::FieldPrefix).trimmed().isEmpty()) { |
|
49 result += name.value(QContactName::FieldPrefix); |
|
50 } |
|
51 |
|
52 if (!name.value(QContactName::FieldFirst).trimmed().isEmpty()) { |
|
53 if (!result.isEmpty()) |
|
54 result += space; |
|
55 result += name.value(QContactName::FieldFirst); |
|
56 } |
|
57 |
|
58 if (!name.value(QContactName::FieldMiddle).trimmed().isEmpty()) { |
|
59 if (!result.isEmpty()) |
|
60 result += space; |
|
61 result += name.value(QContactName::FieldMiddle); |
|
62 } |
|
63 |
|
64 if (!name.value(QContactName::FieldLast).trimmed().isEmpty()) { |
|
65 if (!result.isEmpty()) |
|
66 result += space; |
|
67 result += name.value(QContactName::FieldLast); |
|
68 } |
|
69 |
|
70 if (!name.value(QContactName::FieldSuffix).trimmed().isEmpty()) { |
|
71 if (!result.isEmpty()) |
|
72 result += space; |
|
73 result += name.value(QContactName::FieldSuffix); |
|
74 } |
|
75 |
|
76 if (!result.isEmpty()) { |
|
77 return result; |
|
78 } |
|
79 } |
|
80 |
|
81 |
|
82 return QString("noName"); |
|
83 } |
|
84 |
|
85 void QmlContact::setName(QString name) |
|
86 { |
|
87 Q_UNUSED(name); |
|
88 qWarning() << "Not implemented yet"; |
|
89 emit nameChanged(this); |
|
90 } |
|
91 |
|
92 QStringList QmlContact::availableActions() |
|
93 { |
|
94 QList<QContactActionDescriptor> actions = m_contact.availableActions(); |
|
95 QStringList names; |
|
96 |
|
97 foreach (const QContactActionDescriptor& action, actions) { |
|
98 names << action.actionName(); |
|
99 } |
|
100 return names; |
|
101 } |
|
102 QStringList QmlContact::details() |
|
103 { |
|
104 QStringList dets; |
|
105 QList<QContactDetail> ld = m_contact.details(); |
|
106 QContactDetail d; |
|
107 foreach(d, ld){ |
|
108 dets += d.definitionName(); |
|
109 } |
|
110 return dets; |
|
111 } |
|
112 |
|
113 QStringList QmlContact::contexts() |
|
114 { |
|
115 QStringList dets; |
|
116 QList<QContactDetail> ld = m_contact.details(); |
|
117 QContactDetail d; |
|
118 foreach(d, ld){ |
|
119 dets += d.contexts(); |
|
120 } |
|
121 return dets; |
|
122 } |
|
123 |
|
124 //QStringList QmlContact::values(QString definitionId) |
|
125 QVariantMap QmlContact::values(QString definitionId) |
|
126 { |
|
127 QStringList strlist; |
|
128 QContactDetail detail = m_contact.detail(definitionId); |
|
129 |
|
130 QVariantMap map = detail.values(); |
|
131 //qWarning() << "Number of e: " << map.count(); |
|
132 return map; |
|
133 |
|
134 // QMap<QString, QVariant>::const_iterator i = map.constBegin(); |
|
135 // while (i != map.constEnd()) { |
|
136 // qWarning() << "Key: " << i.key() << " Value: " << i.value(); |
|
137 // strlist += i.key() + ": " + i.value().toString(); |
|
138 // ++i; |
|
139 // } |
|
140 // |
|
141 // return strlist; |
|
142 } |
|
143 |
|
144 #include "moc_qmlcontact.cpp" |
|
145 QTM_END_NAMESPACE |
|
146 QML_DEFINE_TYPE(QmlContact, 1, 0, QmlContact, QmlContact) |
|