Commit 1bd79fb6 authored by Jenkins's avatar Jenkins

New upstream version 0.0+git20190723

parent 6db73a94
{
"phabricator.uri" : "https://phabricator.kde.org/"
}
cmake_minimum_required(VERSION 3.0)
project(KPeopleVCard)
find_package(ECM 1.0 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
include(ECMSetupVersion)
include(CMakePackageConfigHelpers)
include(FeatureSummary)
include(WriteBasicConfigVersionFile)
include(CheckFunctionExists)
include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(ECMAddTests)
find_package(Qt5 "5.2" REQUIRED COMPONENTS Widgets)
find_package(KF5 "5.8" REQUIRED COMPONENTS CoreAddons People I18n)
find_package(KF5Contacts REQUIRED)
add_subdirectory(src)
add_subdirectory(autotests)
set(CMAKECONFIG_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/KF5PeopleVCard")
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/KF5PeopleVCardConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/KF5PeopleVCardConfig.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5PeopleVCardConfig.cmake"
DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
COMPONENT Devel )
This diff is collapsed.
find_package(Qt5Test)
ecm_add_test(kpeoplevcardtest.cpp ../src/kpeoplevcard.cpp TEST_NAME kpeoplevcardtest LINK_LIBRARIES KF5::PeopleBackend KF5::CoreAddons Qt5::Test KF5::Contacts KF5::I18n)
/*
Copyright (C) 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <QDir>
#include <QObject>
#include <QTest>
#include <QStandardPaths>
#include <QSignalSpy>
#include <KContacts/VCardConverter>
#include <../src/kpeoplevcard.h>
class KPeopleVCardTest : public QObject
{
Q_OBJECT
public:
KPeopleVCardTest()
{}
void writeContact(const KContacts::Addressee& addressee, const QString& path)
{
QFile f(path);
bool b = f.open(QIODevice::WriteOnly);
Q_ASSERT(b);
KContacts::VCardConverter conv;
f.write(conv.exportVCard(addressee, KContacts::VCardConverter::v3_0));
}
private Q_SLOTS:
void initTestCase()
{
QStandardPaths::setTestModeEnabled(true);
m_vcardsDir = QDir(KPeopleVCard::contactsVCardPath());
QDir().temp().mkpath(KPeopleVCard::contactsVCardPath());
QVERIFY(m_vcardsDir.exists());
foreach(const QFileInfo & entry, m_vcardsDir.entryInfoList(QDir::Files)) {
QFile::remove(entry.absoluteFilePath());
}
QDir().temp().mkpath(KPeopleVCard::contactsVCardPath() + "/subdir");
QCOMPARE(m_vcardsDir.count(), uint(3)); //. and .. and subdir/
m_backend = new KPeopleVCard;
m_backend->setParent(this);
}
void emptyTest()
{
QVERIFY(m_backend->contacts().isEmpty());
}
void crudTest()
{
// ENSURE EMPTY
QVERIFY(m_backend->contacts().isEmpty());
const QString name = QStringLiteral("aaa"), name2 = QStringLiteral("bbb");
KContacts::Addressee addr;
addr.setName(name);
const QString path = m_vcardsDir.absoluteFilePath("X");
const QString pathInSubdir = m_vcardsDir.absoluteFilePath("subdir/a");
// CREATE
{
QSignalSpy spy(m_backend, &KPeople::AllContactsMonitor::contactAdded);
writeContact(addr, path);
QVERIFY(spy.wait());
// write the same contact into a subdir
writeContact(addr, pathInSubdir);
QVERIFY(spy.wait());
}
// READ
{
KPeople::AbstractContact::Ptr ptr = m_backend->contacts().first();
QCOMPARE(ptr->customProperty(KPeople::AbstractContact::NameProperty).toString(), name);
// the contact in subdir
ptr = m_backend->contacts().last();
QCOMPARE(ptr->customProperty(KPeople::AbstractContact::NameProperty).toString(), name);
}
// UPDATE
{
addr.setName(name2);
QSignalSpy spy(m_backend, &KPeople::AllContactsMonitor::contactChanged);
writeContact(addr, path);
QVERIFY(spy.wait());
writeContact(addr, pathInSubdir);
QVERIFY(spy.wait());
}
// READ
{
KPeople::AbstractContact::Ptr ptr = m_backend->contacts().first();
QCOMPARE(ptr->customProperty(KPeople::AbstractContact::NameProperty).toString(), name2);
ptr = m_backend->contacts().last();
QCOMPARE(ptr->customProperty(KPeople::AbstractContact::NameProperty).toString(), name2);
}
// REMOVE
{
QSignalSpy spy(m_backend, &KPeople::AllContactsMonitor::contactRemoved);
QFile::remove(path);
QVERIFY(spy.wait());
QFile::remove(pathInSubdir);
QVERIFY(spy.wait());
}
// ENSURE EMPTY
QVERIFY(m_backend->contacts().isEmpty());
}
private:
KPeopleVCard* m_backend;
QDir m_vcardsDir;
};
QTEST_GUILESS_MAIN(KPeopleVCardTest)
#include "kpeoplevcardtest.moc"
include: 'https://gitlab.com/debian-pm/tools/build/raw/master/docker/gitlab-ci-base.yml'
image: jbbgameich/build
kpeoplevcard (0.0+git20190723-1) UNRELEASED; urgency=medium
* New snapshot
-- Jonah Brüchert <jbb@kaidan.im> Tue, 23 Jul 2019 16:57:40 +0200
kpeoplevcard (0.0+git20190622-1) unstable; urgency=medium
* New snapshot
-- Jonah Brüchert <jbb@kaidan.im> Sat, 22 Jun 2019 15:02:45 +0200
kpeoplevcard (0.0+git20150716) vivid; urgency=medium
* Initial package
-- Jonathan Riddell <jriddell@ubuntu.com> Thu, 16 Jul 2015 13:10:38 +0200
Source: kpeoplevcard
Maintainer: Debian/Kubuntu Qt/KDE Maintainers <debian-qt-kde@lists.debian.org>
Section: kde
Priority: optional
Build-Depends: cmake,
debhelper (>= 11),
extra-cmake-modules,
libkf5contacts-dev,
libkf5coreaddons-dev,
libkf5i18n-dev,
libkf5people-dev,
pkg-config,
pkg-kde-tools,
qtbase5-dev
Standards-Version: 4.3.0
Vcs-Browser: https://gitlab.com/debian-pm/libs/kpeoplevcard
Vcs-Git: https://gitlab.com/debian-pm/libs/kpeoplevcard.git
Package: kpeople-vcard
Architecture: any
Depends: ${misc:Depends}, ${shlibs:Depends}
Description: kpeople plugin for vcard
This plugin lets kpeople read the vcard format.
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: kpeoplecard
Source: kde:scratch/apol/kpeoplevcard branch lookupService
Files: *
Copyright: 2015, Aleix Pol Gonzalez <aleixpol@kde.org>
License: LGPL-2.1+
Files: debian/*
Copyright: 2015, Jonathan Riddell <jr@jriddell.org>
2015, Aleix Pol Gonzalez <aleixpol@kde.org>
License: LGPL-2.1+
Files: src/*
Copyright: 2015, Martin Klapetek <mklapetek@kde.org>
2015, Aleix Pol Gonzalez <aleixpol@kde.org>
License: LGPL-2.1+
License: LGPL-2.1+
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
.
On Debian systems the full text of the GNU Lesser General Public License can be found
in the `/usr/share/common-licenses/LGPL' file.
#!/usr/bin/make -f
include /usr/share/pkg-kde-tools/qt-kde-team/3/debian-qt-kde.mk
# Its a list of linters with it's licenses, not a license for this file
kate source: license-problem-json-evil addons/pate/src/plugins/js_utils/js_lint.py
\ No newline at end of file
kcoreaddons_add_plugin(KPeopleVCard SOURCES kpeoplevcard.cpp JSON "kpeoplevcard.json" INSTALL_NAMESPACE "kpeople/datasource")
target_link_libraries(KPeopleVCard KF5::PeopleBackend KF5::CoreAddons KF5::Contacts KF5::I18n)
/*
Copyright (C) 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
Copyright (C) 2015 Martin Klapetek <mklapetek@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "kpeoplevcard.h"
#include <QDebug>
#include <QImage>
#include <QDir>
#include <QStandardPaths>
#include <KContacts/VCardConverter>
#include <KContacts/Picture>
#include <KPeopleBackend/BasePersonsDataSource>
#include <KLocalizedString>
#include <KPluginFactory>
#include <KPluginLoader>
using namespace KPeople;
Q_GLOBAL_STATIC_WITH_ARGS(QString, vcardsLocation, (QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + ("/kpeoplevcard")))
class VCardContact : public AbstractContact
{
public:
VCardContact() {}
VCardContact(const KContacts::Addressee& addr) : m_addressee(addr) {}
void setAddressee(const KContacts::Addressee& addr) { m_addressee = addr; }
QVariant customProperty(const QString & key) const override
{
QVariant ret;
if (key == NameProperty) {
const QString name = m_addressee.realName();
if (!name.isEmpty()) {
return name;
}
// If both first and last name are set combine them to a full name
if (!m_addressee.givenName().isEmpty() && !m_addressee.familyName().isEmpty())
return i18nc("given-name family-name", "%1 %2", m_addressee.givenName(), m_addressee.familyName());
// If only one of them is set just return what we know
if (!m_addressee.givenName().isEmpty())
return m_addressee.givenName();
if (!m_addressee.familyName().isEmpty())
return m_addressee.familyName();
// Fall back to other identifiers
if (!m_addressee.preferredEmail().isEmpty()) {
return m_addressee.preferredEmail();
}
if (!m_addressee.phoneNumbers().isEmpty()) {
return m_addressee.phoneNumbers().at(0).number();
}
return QVariant();
} else if (key == EmailProperty)
return m_addressee.preferredEmail();
else if (key == AllEmailsProperty)
return m_addressee.emails();
else if (key == PictureProperty)
return m_addressee.photo().data();
else if (key == AllPhoneNumbersProperty) {
const auto phoneNumbers = m_addressee.phoneNumbers();
QVariantList numbers;
for (const KContacts::PhoneNumber &phoneNumber : phoneNumbers) {
// convert from KContacts specific format to QString
numbers << phoneNumber.number();
}
return numbers;
} else if (key == PhoneNumberProperty) {
return m_addressee.phoneNumbers().isEmpty() ? QVariant() : m_addressee.phoneNumbers().at(0).number();
}
return ret;
}
static QString createUri(const QString& path) {
return QStringLiteral("vcard:/") + path;
}
private:
KContacts::Addressee m_addressee;
};
class VCardDataSource : public KPeople::BasePersonsDataSource
{
public:
VCardDataSource(QObject *parent, const QVariantList &data);
~VCardDataSource() override;
QString sourcePluginId() const override;
KPeople::AllContactsMonitor* createAllContactsMonitor() override;
};
KPeopleVCard::KPeopleVCard()
: KPeople::AllContactsMonitor()
, m_fs(new KDirWatch(this))
{
QDir().mkpath(*vcardsLocation);
QDir dir(*vcardsLocation);
const QStringList subdirs = dir.entryList(QDir::AllDirs | QDir::NoDotDot); // includes '.', ie. vcards from no subdir
QStringList entries;
for (const QString &subdirName : subdirs) {
QDir subdir(dir.absoluteFilePath(subdirName));
const QFileInfoList subdirVcards = subdir.entryInfoList({"*.vcard", "*.vcf"});
for (const QFileInfo &vcardFile : subdirVcards) {
entries << vcardFile.absoluteFilePath();
}
}
for (const QString& entry : qAsConst(entries)) {
processVCard(entry);
}
m_fs->addDir(dir.absolutePath(), KDirWatch::WatchDirOnly | KDirWatch::WatchSubDirs);
connect(m_fs, &KDirWatch::dirty, this, [this](const QString& path){ if (QFileInfo(path).isFile()) processVCard(path); });
connect(m_fs, &KDirWatch::created, this, &KPeopleVCard::processVCard);
connect(m_fs, &KDirWatch::deleted, this, &KPeopleVCard::deleteVCard);
}
KPeopleVCard::~KPeopleVCard()
{}
QMap<QString, AbstractContact::Ptr> KPeopleVCard::contacts()
{
return m_contactForUri;
}
void KPeopleVCard::processVCard(const QString &path)
{
m_fs->addFile(path);
QFile f(path);
bool b = f.open(QIODevice::ReadOnly);
if (!b) {
qWarning() << "error: couldn't open:" << path;
return;
}
KContacts::VCardConverter conv;
const KContacts::Addressee addressee = conv.parseVCard(f.readAll());
QString uri = VCardContact::createUri(path);
auto it = m_contactForUri.find(uri);
if (it != m_contactForUri.end()) {
static_cast<VCardContact*>(it->data())->setAddressee(addressee);
Q_EMIT contactChanged(uri, *it);
} else {
KPeople::AbstractContact::Ptr contact(new VCardContact(addressee));
m_contactForUri.insert(uri, contact);
Q_EMIT contactAdded(uri, contact);
}
}
void KPeopleVCard::deleteVCard(const QString &path)
{
QString uri = VCardContact::createUri(path);
int r = m_contactForUri.remove(uri);
Q_ASSERT(r);
Q_EMIT contactRemoved(uri);
}
QString KPeopleVCard::contactsVCardPath()
{
return *vcardsLocation;
}
VCardDataSource::VCardDataSource(QObject *parent, const QVariantList &args)
: BasePersonsDataSource(parent)
{
Q_UNUSED(args);
}
VCardDataSource::~VCardDataSource()
{
}
QString VCardDataSource::sourcePluginId() const
{
return QStringLiteral("vcard");
}
AllContactsMonitor* VCardDataSource::createAllContactsMonitor()
{
return new KPeopleVCard();
}
K_PLUGIN_FACTORY_WITH_JSON( VCardDataSourceFactory, "kpeoplevcard.json", registerPlugin<VCardDataSource>(); )
K_EXPORT_PLUGIN( VCardDataSourceFactory("kpeoplevcard") )
#include "kpeoplevcard.moc"
/*
Copyright (C) 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
Copyright (C) 2015 Martin Klapetek <mklapetek@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef KPEOPLEVCARD_H
#define KPEOPLEVCARD_H
#include <KDirWatch>
#include <KPeopleBackend/AllContactsMonitor>
#include <KPeopleBackend/AbstractContact>
class Q_DECL_EXPORT KPeopleVCard : public KPeople::AllContactsMonitor
{
Q_OBJECT
public:
KPeopleVCard();
~KPeopleVCard() override;
QMap<QString, KPeople::AbstractContact::Ptr> contacts() override;
static QString contactsVCardPath();
private:
void processVCard(const QString &path);
void deleteVCard(const QString &path);
QMap<QString, KPeople::AbstractContact::Ptr> m_contactForUri;
KDirWatch* m_fs;
};
#endif
{
"Encoding": "UTF-8",
"KPlugin": {
"EnabledByDefault": true,
"Id": "VCardProvider",
"License": "LGPL",
"ServiceTypes": [
"KPeople/DataSource"
],
"Version": "0.1"
}
}
\ No newline at end of file
[Desktop Entry]
Encoding=UTF-8
Type=Service
ServiceTypes=KPeople/DataSource
X-KDE-Library=KPeopleVCard
X-KDE-PluginInfo-Author=Aleix Pol Gonzalez
X-KDE-PluginInfo-Email=aleixpol@blue-systems.com
X-KDE-PluginInfo-Name=IMProvider
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-License=LGPL
X-KDE-PluginInfo-EnabledByDefault=true
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment