Warning, file /frameworks/kcontacts/tests/testwrite.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of the KContacts framework. 0003 SPDX-FileCopyrightText: 2007 KDE-PIM team <kde-pim@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include <QFile> 0009 0010 #include <KLocalizedString> 0011 0012 #include <QCommandLineParser> 0013 #include <QCoreApplication> 0014 0015 #include "converter/kcontacts/vcardconverter.h" 0016 #include "kcontacts/address.h" 0017 #include "kcontacts/addressee.h" 0018 #include "kcontacts/key.h" 0019 #include "kcontacts/phonenumber.h" 0020 #include "kcontacts/picture.h" 0021 #include "kcontacts/secrecy.h" 0022 #include "kcontacts/sound.h" 0023 0024 int main(int argc, char **argv) 0025 { 0026 QCoreApplication app(argc, argv); 0027 QCommandLineParser parser; 0028 parser.addVersionOption(); 0029 parser.addHelpOption(); 0030 parser.process(app); 0031 0032 KContacts::Addressee addressee; 0033 0034 addressee.setNameFromString(QLatin1String("Mr. Tobias Koenig Jr.")); 0035 addressee.setNickName(QLatin1String("tokoe")); 0036 addressee.setBirthday(QDateTime(QDate(1982, 7, 19).startOfDay())); 0037 addressee.setMailer(QLatin1String("mutt1.2")); 0038 addressee.setTimeZone(KContacts::TimeZone(+2)); 0039 0040 KContacts::Geo geo; 0041 geo.setLatitude(30); 0042 geo.setLongitude(51); 0043 addressee.setGeo(geo); 0044 0045 addressee.setTitle(QLatin1String("nerd")); 0046 addressee.setRole(QLatin1String("Maintainer")); 0047 addressee.setOrganization(QLatin1String("KDE")); 0048 addressee.setNote(QLatin1String("never\ntouch a running system")); 0049 addressee.setProductId(QLatin1String("testId")); 0050 addressee.setRevision(QDateTime::currentDateTime()); 0051 addressee.setSortString(QLatin1String("koenig")); 0052 KContacts::ResourceLocatorUrl url; 0053 url.setUrl(QUrl(QLatin1String("http://wgess16.dyndns.org"))); 0054 addressee.setUrl(url); 0055 addressee.setSecrecy(KContacts::Secrecy(KContacts::Secrecy::Confidential)); 0056 0057 KContacts::Email kdemail(QLatin1String("tokoe@kde.org")); 0058 kdemail.setPreferred(true); 0059 addressee.addEmail(kdemail); 0060 0061 KContacts::Email yahoomail(QLatin1String("tokoe82@yahoo.de")); 0062 yahoomail.setPreferred(true); 0063 addressee.addEmail(yahoomail); 0064 0065 KContacts::PhoneNumber phone1(QLatin1String("3541523475"), KContacts::PhoneNumber::Pref | KContacts::PhoneNumber::Home); 0066 KContacts::PhoneNumber phone2(QLatin1String("+46745673475"), KContacts::PhoneNumber::Work); 0067 addressee.insertPhoneNumber(phone1); 0068 addressee.insertPhoneNumber(phone2); 0069 0070 KContacts::Key key(QLatin1String("secret key"), KContacts::Key::X509); 0071 addressee.insertKey(key); 0072 0073 QStringList categories; 0074 categories << QLatin1String("Friends") << QLatin1String("School") << QLatin1String("KDE"); 0075 addressee.setCategories(categories); 0076 0077 KContacts::Address a(KContacts::Address::Work | KContacts::Address::Postal | KContacts::Address::Parcel); 0078 a.setStreet(QLatin1String("6544 Battleford Drive")); 0079 a.setLocality(QLatin1String("Raleigh")); 0080 a.setRegion(QLatin1String("NC")); 0081 a.setPostalCode(QLatin1String("27613-3502")); 0082 a.setCountry(QLatin1String("U.S.A.")); 0083 addressee.insertAddress(a); 0084 0085 addressee.insertCustom(QLatin1String("1hsdf"), QLatin1String("ertuer"), QLatin1String("iurt")); 0086 addressee.insertCustom(QLatin1String("2hsdf"), QLatin1String("ertuer"), QLatin1String("iurt")); 0087 addressee.insertCustom(QLatin1String("3hsdf"), QLatin1String("ertuer"), QLatin1String("iurt")); 0088 0089 KContacts::Addressee::List list; 0090 for (int i = 0; i < 1000; ++i) { 0091 KContacts::Addressee addr = addressee; 0092 addr.setUid(QString::number(i)); 0093 list.append(addr); 0094 } 0095 0096 KContacts::VCardConverter converter; 0097 QByteArray txt = converter.createVCards(list); 0098 0099 QFile file(QLatin1String("out.vcf")); 0100 if (!file.open(QIODevice::WriteOnly)) { 0101 qDebug("Can't open file '%s' for writing", qPrintable(file.fileName())); 0102 return 1; 0103 } 0104 0105 file.write(txt); 0106 file.close(); 0107 0108 return 0; 0109 }