Commit 74fdca97 authored by Carl Schwan's avatar Carl Schwan 🚴
Browse files

Move contacts integration inside a qml plugin



This helps with code seperation in modules and would allows in the
future to build Plasma applets using the same plugin

Signed-off-by: Carl Schwan's avatarCarl Schwan <carl@carlschwan.eu>
parent 525ebb2e
......@@ -6,7 +6,10 @@ Files: logo.png org.kde.kalendar.svg
Copyright: 2021 Áron Kovács <aronkvh@gmail.com>
License: LGPL-2.0-or-later
Files: src/contents/resources/fallbackBackground.png
Files: src/contacts/resources/fallbackBackground.png
Copyright: Jonah Brüchert <jbb.prv@gmx.de>
License: GPL-3.0-or-later
Files: src/contacts/qml/qmldir
Copyright: Carl Schwan <carl@carlschwan.eu>
License: CC0-1.0
......@@ -39,6 +39,9 @@ include(ECMPoQmTools)
include(KDEGitCommitHooks)
include(KDEClangFormat)
include(ECMDeprecationSettings)
include(ECMGenerateQmlTypes)
include(ECMQmlModule)
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h *.c)
kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
......
......@@ -2,6 +2,9 @@
#
# SPDX-License-Identifier: BSD-2-Clause
add_subdirectory(lib)
add_subdirectory(contacts)
add_executable(kalendar)
set(kalendar_SRCS
......@@ -46,20 +49,6 @@ set(kalendar_SRCS
models/timezonelistmodel.h
models/todosortfilterproxymodel.cpp
models/todosortfilterproxymodel.h
models/colorproxymodel.h
models/colorproxymodel.cpp
contacts/addresseewrapper.cpp
contacts/addresseewrapper.h
contacts/addressmodel.cpp
contacts/addressmodel.h
contacts/emailmodel.h
contacts/emailmodel.cpp
contacts/globalcontactmodel.cpp
contacts/globalcontactmodel.h
contacts/contactmanager.h
contacts/contactmanager.cpp
contacts/contactcollectionmodel.cpp
contacts/contactcollectionmodel.h
resources.qrc
)
qt_add_dbus_adaptor(kalendar_SRCS org.kde.calendar.Calendar.xml kalendarapplication.h KalendarApplication)
......@@ -71,15 +60,7 @@ target_sources(kalendar PRIVATE
ecm_qt_declare_logging_category(kalendar HEADER kalendar_debug.h IDENTIFIER KALENDAR_LOG CATEGORY_NAME org.kde.kalendar DESCRIPTION "kalendar" EXPORT KALENDAR)
set(kalendar_LIBS
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
Qt::QuickControls2
Qt::Svg
Qt::DBus
KF5::I18n
KF5::CoreAddons
kalendar_lib
KF5::DBusAddons
KF5::CalendarCore
KF5::AkonadiCore
......
......@@ -35,11 +35,11 @@
#include <Akonadi/Monitor>
#include <akonadi_version.h>
#if AKONADICALENDAR_VERSION > QT_VERSION_CHECK(5, 19, 41)
#include <Akonadi/IncidenceChanger>
#include <Akonadi/History>
#include <Akonadi/IncidenceChanger>
#else
#include <Akonadi/Calendar/IncidenceChanger>
#include <Akonadi/Calendar/History>
#include <Akonadi/Calendar/IncidenceChanger>
#endif
#include <CalendarSupport/KCalPrefs>
#include <CalendarSupport/Utils>
......@@ -58,7 +58,7 @@
#else
#include <etmcalendar.h>
#endif
#include "models/colorproxymodel.h"
#include <colorproxymodel.h>
using namespace Akonadi;
......
# SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
# SPDX-License-Identifier: BSD-2-Clause
ecm_add_qml_module(kalendar_contact_plugin URI "org.kde.kalendar.contact" VERSION 1.0)
target_sources(kalendar_contact_plugin PRIVATE
contactplugin.cpp
contactplugin.h
addresseewrapper.cpp
addresseewrapper.h
addressmodel.cpp
addressmodel.h
emailmodel.h
emailmodel.cpp
globalcontactmodel.cpp
globalcontactmodel.h
contactmanager.h
contactmanager.cpp
contactcollectionmodel.cpp
contactcollectionmodel.h
resources.qrc
)
ecm_target_qml_sources(kalendar_contact_plugin SOURCES
qml/ContactChooserPage.qml
qml/ContactView.qml
)
ecm_target_qml_sources(kalendar_contact_plugin
PRIVATE PATH private SOURCES
qml/private/ContactListItem.qml
qml/private/ContactPage.qml
qml/private/ContactsPage.qml
qml/private/Header.qml
qml/private/PhoneNumberDialog.qml
)
ecm_qt_declare_logging_category(kalendar_contact_plugin
HEADER kalendar_contact_debug.h
IDENTIFIER KALENDAR_LOG
CATEGORY_NAME org.kde.kalendar.contact
DESCRIPTION "kalendar contact"
EXPORT KALENDAR
)
target_link_libraries(kalendar_contact_plugin PRIVATE kalendar_lib)
ecm_qt_install_logging_categories(
EXPORT KALENDAR
FILE kalendar.contact.categories
DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}
)
if (BUILD_TESTING)
add_subdirectory(autotests)
endif()
ecm_finalize_qml_module(kalendar_contact_plugin
DESTINATION ${KDE_INSTALL_QMLDIR}
BUILD_SHARED_LIBS OFF)
\ No newline at end of file
......@@ -2,12 +2,12 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "addresseewrapper.h"
#include "kalendar_debug.h"
#include "kalendar_contact_debug.h"
#include <Akonadi/ItemMonitor>
#include <KContacts/Addressee>
#include <KLocalizedString>
#include <QBitArray>
#include <QJSValue>
#include <Akonadi/ItemMonitor>
#include <KContacts/Addressee>
AddresseeWrapper::AddresseeWrapper(QObject *parent)
: QObject(parent)
......
......@@ -12,8 +12,8 @@
#include <KContacts/Addressee>
#include <QObject>
#include "emailmodel.h"
#include "addressmodel.h"
#include "emailmodel.h"
/// This class is a QObject wrapper for a KContact::Adressee
class AddresseeWrapper : public QObject, public Akonadi::ItemMonitor
......
// SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "contacts/addressmodel.h"
#include "addressmodel.h"
#include <QDebug>
#include <qabstractitemmodel.h>
......
# SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
# SPDX-License-Identifier: BSD-2-Clause
add_library(kalendar_contact STATIC
../addresseewrapper.cpp
../addresseewrapper.h
../addressmodel.cpp
../addressmodel.h
../emailmodel.h
../emailmodel.cpp
../globalcontactmodel.cpp
../globalcontactmodel.h
../contactmanager.h
../contactmanager.cpp
../contactcollectionmodel.cpp
../contactcollectionmodel.h
)
target_include_directories(kalendar_contact INTERFACE "$<INSTALL_INTERFACE:${KALENDAR_CONTACT_INCLUDE_INSTALL_DIR}>")
target_link_libraries(kalendar_contact PRIVATE kalendar_lib)
ecm_qt_declare_logging_category(kalendar_contact
HEADER kalendar_contact_debug.h
IDENTIFIER KALENDAR_LOG
CATEGORY_NAME org.kde.kalendar.contact
DESCRIPTION "kalendar contact"
EXPORT KALENDAR
)
ecm_add_test(emailmodeltest.cpp
TEST_NAME emailmodeltest
LINK_LIBRARIES kalendar_contact kalendar_lib Qt::Test
NAME_PREFIX "kalendar-contact-"
)
// SPDX-FileCopyrightText: (C) 2020 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: BSD-2-Clause
#include "../emailmodel.h"
#include <KContacts/Email>
#include <KLocalizedString>
#include <QObject>
#include <QtTest/QtTest>
class EmailModelTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase()
{
}
void testReading()
{
KContacts::Email::List emails;
emails.append(KContacts::Email(QStringLiteral("carl@carlschwan.eu")));
emails.append(KContacts::Email(QStringLiteral("carl1@carlschwan.eu")));
KContacts::Email email(QStringLiteral("carl2@carlschwan.eu"));
email.setPreferred(true);
email.setType(KContacts::Email::Home);
emails.append(email);
EmailModel emailModel;
emailModel.setEmails(emails);
QCOMPARE(emailModel.rowCount(), 3);
QCOMPARE(emailModel.data(emailModel.index(2, 0), Qt::DisplayRole).toString(), QStringLiteral("carl2@carlschwan.eu"));
QCOMPARE(emailModel.data(emailModel.index(2, 0), EmailModel::DefaultRole).toBool(), true);
QCOMPARE(emailModel.data(emailModel.index(2, 0), EmailModel::TypeRole).toString(), i18n("Home:"));
}
};
QTEST_MAIN(EmailModelTest)
#include "emailmodeltest.moc"
......@@ -33,7 +33,6 @@
#endif
#include "contactcollectionmodel.h"
#include "globalcontactmodel.h"
#include "models/colorproxymodel.h"
#include <Akonadi/CollectionFilterProxyModel>
#include <Akonadi/EntityMimeTypeFilterModel>
#include <Akonadi/EntityRightsFilterModel>
......@@ -47,8 +46,10 @@
#include <QBuffer>
#include <QItemSelectionModel>
#include <QSortFilterProxyModel>
#include <colorproxymodel.h>
namespace {
namespace
{
class ContactsModel : public QSortFilterProxyModel
{
public:
......
......@@ -4,9 +4,8 @@
#pragma once
#include <Akonadi/Item>
#include <KDescendantsProxyModel>
#include <QObject>
#include <kdescendantsproxymodel.h>
#include <qobjectdefs.h>
namespace Akonadi
{
......
// SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "contactplugin.h"
#include "addresseewrapper.h"
#include "addressmodel.h"
#include "contactcollectionmodel.h"
#include "contactmanager.h"
#include "emailmodel.h"
#include "globalcontactmodel.h"
#include <QAbstractListModel>
#include <QQmlEngine>
#include <QtQml>
void CalendarPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QByteArray("org.kde.kalendar.contact"));
qmlRegisterSingletonType<ContactManager>("org.kde.kalendar.contact", 1, 0, "ContactManager", [](QQmlEngine *engine, QJSEngine *scriptEngine) {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new ContactManager;
});
qmlRegisterType<AddresseeWrapper>("org.kde.kalendar.contact", 1, 0, "AddresseeWrapper");
qRegisterMetaType<KContacts::Picture>("KContacts::Picture");
qRegisterMetaType<KContacts::PhoneNumber::List>("KContacts::PhoneNumber::List");
qRegisterMetaType<KContacts::PhoneNumber>("KContacts::PhoneNumber");
}
// SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: LGPL-2.0-or-later
#pragma once
#include <QQmlExtensionPlugin>
class QQmlEngine;
class CalendarPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void registerTypes(const char *uri) override;
};
\ No newline at end of file
......@@ -4,10 +4,10 @@
#include "emailmodel.h"
#include <KLocalizedString>
EmailModel::EmailModel(QObject *parent)
: QAbstractListModel(parent)
{}
{
}
int EmailModel::rowCount(const QModelIndex &parent) const
{
......
......@@ -3,8 +3,8 @@
#pragma once
#include <QAbstractListModel>
#include <KContacts/Email>
#include <QAbstractListModel>
class EmailModel : public QAbstractListModel
{
......
......@@ -8,8 +8,8 @@
#include "globalcontactmodel.h"
#include <akonadi-calendar_version.h>
#include <Akonadi/ChangeRecorder>
#include <akonadi-calendar_version.h>
#if AKONADICALENDAR_VERSION > QT_VERSION_CHECK(5, 19, 41)
#include <Akonadi/ContactsTreeModel>
#else
......
......@@ -7,6 +7,8 @@ import QtQuick.Layouts 1.15
import org.kde.kirigami 2.12 as Kirigami
import org.kde.kalendar 1.0
import org.kde.kalendar.contact 1.0
import './private'
ContactsPage {
signal addAttendee(var itemId, string email)
......
......@@ -5,7 +5,9 @@ import QtQuick 2.15
import QtQuick.Controls 2.15 as Controls
import QtQuick.Layouts 1.15
import org.kde.kirigami 2.12 as Kirigami
import org.kde.kalendar.contact 1.0
import org.kde.kalendar 1.0
import './private'
Kirigami.ScrollablePage {
objectName: "contactView"
......@@ -25,7 +27,7 @@ Kirigami.ScrollablePage {
name: model && model.display
avatarIcon: model && model.decoration
onClicked: applicationWindow().pageStack.push('qrc:/ContactPage.qml', {
onClicked: applicationWindow().pageStack.push(Qt.resolvedUrl('./private/ContactPage.qml'), {
contact: model,
itemId: model.itemId,
})
......
......@@ -12,7 +12,7 @@ import QtQuick.Controls 2.0 as Controls
import QtGraphicalEffects 1.0
import org.kde.kirigami 2.14 as Kirigami
import org.kde.kalendar 1.0
import org.kde.kalendar.contact 1.0
Kirigami.AbstractListItem {
id: listItem
......
Supports Markdown
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