20 using namespace KABMergeContacts;
39 KABC::Addressee newContact;
40 if (mListItem.count() <= 1)
42 bool firstAddress =
true;
43 Q_FOREACH (
const Akonadi::Item &item, mListItem) {
44 if (item.hasPayload<KABC::Addressee>()) {
45 KABC::Addressee address = item.payload<KABC::Addressee>();
50 mergeToContact(newContact, address, excludeConflictPart);
57 void MergeContacts::mergeToContact(KABC::Addressee &newContact,
const KABC::Addressee &fromContact,
bool excludeConflictPart)
60 const QString fromContactNote = fromContact.note();
61 if (!fromContactNote.
isEmpty()) {
62 QString newContactNote = newContact.note();
63 if (!newContactNote.
isEmpty()) {
66 newContactNote += fromContactNote;
67 newContact.setNote(newContactNote);
73 Q_FOREACH(
const QString &email, emails) {
74 if (!newContactsEmail.
contains(email)) {
75 newContactsEmail.
append(email);
78 newContact.setEmails(newContactsEmail);
81 const QStringList categories = fromContact.categories();
83 QStringList newContactsCategories = newContact.categories();
84 Q_FOREACH(
const QString &category, categories) {
85 if (!newContactsCategories.
contains(category)) {
86 newContactsCategories.
append(category);
89 newContact.setCategories(newContactsCategories);
93 const PhoneNumber::List listPhone = fromContact.phoneNumbers();
94 if (!listPhone.isEmpty()) {
95 PhoneNumber::List newContactsPhone = newContact.phoneNumbers();
96 Q_FOREACH(
const PhoneNumber &phone, listPhone) {
97 if (!newContactsPhone.contains(phone)) {
98 newContact.insertPhoneNumber(phone);
104 const Address::List listAddress = fromContact.addresses();
105 if (!listAddress.isEmpty()) {
106 Address::List newContactsAddress = newContact.addresses();
107 Q_FOREACH(
const Address &addr, listAddress) {
108 if (!newContactsAddress.contains(addr)) {
109 newContact.insertAddress(addr);
114 if (!excludeConflictPart) {
116 if (newContact.name().isEmpty() && !fromContact.name().isEmpty()) {
117 newContact.setName(fromContact.name());
120 if (newContact.organization().isEmpty() && !fromContact.organization().isEmpty()) {
121 newContact.setOrganization(fromContact.organization());
124 if (newContact.nickName().isEmpty() && !fromContact.nickName().isEmpty()) {
125 newContact.setNickName(fromContact.nickName());
128 if (newContact.title().isEmpty() && !fromContact.title().isEmpty()) {
129 newContact.setTitle(fromContact.title());
132 if (newContact.department().isEmpty() && !fromContact.department().isEmpty()) {
133 newContact.setDepartment(fromContact.department());
136 if (newContact.familyName().isEmpty() && !fromContact.familyName().isEmpty()) {
137 newContact.setFamilyName(fromContact.familyName());
140 if (newContact.url().isEmpty() && !fromContact.url().isEmpty()) {
141 newContact.setUrl(fromContact.url());
144 if (newContact.geo().isValid() && !fromContact.geo().isValid()) {
145 newContact.setGeo(fromContact.geo());
148 if (newContact.photo().isEmpty() && !fromContact.photo().isEmpty()) {
149 newContact.setPhoto(fromContact.photo());
153 if (newContact.logo().isEmpty() && !fromContact.logo().isEmpty()) {
154 newContact.setLogo(fromContact.logo());
159 mergeCustomValue(fromContact,
QLatin1String(
"BlogFeed" ), newContact);
161 mergeCustomValue(fromContact,
QLatin1String(
"X-Profession" ), newContact);
163 mergeCustomValue(fromContact,
QLatin1String(
"X-Office" ), newContact);
165 mergeCustomValue(fromContact,
QLatin1String(
"X-ManagersName" ), newContact);
167 mergeCustomValue(fromContact,
QLatin1String(
"X-AssistantsName" ), newContact);
169 mergeCustomValue(fromContact,
QLatin1String(
"X-SpousesName" ), newContact);
171 mergeCustomValue(fromContact,
QLatin1String(
"X-Anniversary" ), newContact);
176 void MergeContacts::mergeCustomValue(
const KABC::Addressee &fromContact,
const QString &variable, KABC::Addressee &newContact)
181 newContact.insertCustom(
QLatin1String(
"KADDRESSBOOK" ), variable, value);
188 MergeContacts::ConflictInformations result =
None;
189 if (mListItem.count() < 2)
191 KABC::Addressee newContact;
192 Q_FOREACH (
const Akonadi::Item &item, mListItem) {
193 if (item.hasPayload<KABC::Addressee>()) {
195 const KABC::Addressee address = item.payload<KABC::Addressee>();
196 if (address.birthday().date().isValid()) {
197 if (newContact.birthday().date().isValid()) {
198 if (newContact.birthday().date() != address.birthday().date()) {
202 newContact.setBirthday(address.birthday());
207 const KABC::Geo geo = address.geo();
209 if (newContact.geo().isValid()) {
210 if (newContact.geo() != geo) {
214 newContact.setGeo(address.geo());
218 const KABC::Picture photo = address.photo();
219 if (!photo.isEmpty()) {
220 if (!newContact.photo().isEmpty()) {
221 if (newContact.photo() != photo) {
225 newContact.setPhoto(address.photo());
229 const KABC::Picture logo = address.logo();
230 if (!logo.isEmpty()) {
231 if (!newContact.logo().isEmpty()) {
232 if (newContact.logo() != logo) {
236 newContact.setLogo(address.logo());
240 const QString name = address.name();
242 if (!newContact.name().isEmpty()) {
243 if (newContact.name() != name) {
247 newContact.setName(address.name());
251 const QString nickName = address.nickName();
253 if (!newContact.nickName().isEmpty()) {
254 if (newContact.nickName() != nickName) {
258 newContact.setNickName(address.nickName());
262 const QString organization = address.organization();
264 if (!newContact.organization().isEmpty()) {
265 if (newContact.organization() != organization) {
269 newContact.setOrganization(address.organization());
273 const QString title = address.title();
275 if (!newContact.title().isEmpty()) {
276 if (newContact.title() != title) {
280 newContact.setTitle(address.title());
284 const QString departement = address.department();
286 if (!newContact.department().isEmpty()) {
287 if (newContact.department() != departement) {
291 newContact.setDepartment(address.department());
295 const KUrl url = address.url();
296 if (url.isValid() && !url.isEmpty()) {
297 if (newContact.url().isValid() && !newContact.url().isEmpty()) {
298 if (newContact.url() != url) {
302 newContact.setUrl(address.url());
306 const QString familyName = address.familyName();
308 if (!newContact.familyName().isEmpty()) {
309 if (newContact.familyName() != familyName) {
313 newContact.setFamilyName(address.familyName());
317 checkCustomValue(address,
QLatin1String(
"BlogFeed" ), newContact, result,
Blog);
336 void MergeContacts::checkCustomValue(
const KABC::Addressee &address,
const QString &variable, KABC::Addressee &newContact, MergeContacts::ConflictInformations &result,
MergeContacts::ConflictInformation conflict)
342 if (newValue != value) {
346 newContact.insertCustom(
QLatin1String(
"KADDRESSBOOK" ), variable, value);
bool contains(const QString &str, Qt::CaseSensitivity cs) const
void append(const T &value)