File indexing completed on 2024-12-22 04:52:51
0001 /* 0002 SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "trojitaaddressbook.h" 0008 #include <KContacts/Addressee> 0009 0010 #include <QUrl> 0011 0012 #include <QSettings> 0013 0014 TrojitaAddressBook::TrojitaAddressBook(const QString &filename) 0015 { 0016 settings = new QSettings(filename, QSettings::IniFormat, this); 0017 } 0018 0019 TrojitaAddressBook::~TrojitaAddressBook() 0020 { 0021 delete settings; 0022 } 0023 0024 void TrojitaAddressBook::readAddressBook() 0025 { 0026 const QStringList contacts = settings->childGroups(); 0027 for (const QString &contact : contacts) { 0028 KContacts::Addressee contactABC; 0029 settings->beginGroup(contact); 0030 contactABC.setEmails(QStringList() << settings->value(QStringLiteral("email")).toStringList()); 0031 0032 KContacts::Address homeAddr = KContacts::Address(KContacts::Address::Home); 0033 homeAddr.setLocality(settings->value(QStringLiteral("city")).toString()); 0034 homeAddr.setRegion(settings->value(QStringLiteral("state")).toString()); 0035 homeAddr.setPostalCode(settings->value(QStringLiteral("zip")).toString()); 0036 homeAddr.setCountry(settings->value(QStringLiteral("country")).toString()); 0037 homeAddr.setStreet(settings->value(QStringLiteral("address")).toString()); 0038 if (!homeAddr.isEmpty()) { 0039 contactABC.insertAddress(homeAddr); 0040 } 0041 0042 contactABC.insertPhoneNumber(KContacts::PhoneNumber(settings->value(QStringLiteral("phone")).toString(), KContacts::PhoneNumber::Home)); 0043 contactABC.insertPhoneNumber(KContacts::PhoneNumber(settings->value(QStringLiteral("workphone")).toString(), KContacts::PhoneNumber::Work)); 0044 contactABC.insertPhoneNumber(KContacts::PhoneNumber(settings->value(QStringLiteral("fax")).toString(), KContacts::PhoneNumber::Fax)); 0045 contactABC.insertPhoneNumber(KContacts::PhoneNumber(settings->value(QStringLiteral("mobile")).toString(), KContacts::PhoneNumber::Cell)); 0046 contactABC.setNickName(settings->value(QStringLiteral("nick")).toString()); 0047 KContacts::ResourceLocatorUrl url; 0048 url.setUrl(QUrl(settings->value(QStringLiteral("url")).toString())); 0049 contactABC.setUrl(url); 0050 0051 const QDate birthDate = QDate::fromString(settings->value(QStringLiteral("anniversary")).toString()); 0052 if (birthDate.isValid()) { 0053 contactABC.setBirthday(birthDate); 0054 } 0055 // TODO 0056 // ADD(Photo, "photo"); 0057 addImportContactNote(contactABC, QStringLiteral("Trojita")); 0058 createContact(contactABC); 0059 settings->endGroup(); 0060 } 0061 }