2 * Copyright (c) 2011, Mika Laitio. <lamikr@pilppa.org>, Tom Swindell
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 #include "VCardDirectoryImporter.h"
14 #include <QStringList>
15 #include <QCoreApplication>
17 #include <QContactSaveRequest>
19 #include <QVersitReader>
20 #include <QVersitContactImporter>
22 #include <seasidesyncmodel.h>
26 VCardDirectoryImporter::VCardDirectoryImporter(QObject *parent) : QObject(parent) {
30 VCardDirectoryImporter::~VCardDirectoryImporter()
34 int VCardDirectoryImporter::importVCardsDirectoryContacts(const QString &path)
38 QVersitContactImporter importer;
39 QList<QVersitDocument> documents;
43 if (directory.exists() == true) {
44 qDebug() << "Importing v-card contacts from directory " << path;
45 foreach(QString fileName, directory.entryList((QStringList() << "*.vcf"), QDir::Files)) {
46 QFile file(directory.filePath(fileName));
47 file.open(QFile::ReadOnly);
49 reader.setDevice(&file);
50 reader.startReading();
51 reader.waitForFinished();
53 documents.append(reader.results());
54 qDebug() << "Read " << reader.results().count() << " contacts: " << file.fileName();
56 importer.importDocuments(documents);
57 qDebug() << "Total count of contacts read: " << importer.contacts().count();
59 contactList.append(importer.contacts());
63 qWarning() << "Error, V-Card contact directory" << directory.path() << "not found.";
68 int VCardDirectoryImporter::saveContacts()
71 SeasideSyncModel *syncModel;
73 syncModel = SeasideSyncModel::instance();
74 //syncModel->addContacts(contactList, contactList.count());
75 foreach (const QContact& cnt, contactList) {
76 syncModel->updatePerson(&cnt);