Commit 8c6a9d20 authored by Carl Schwan's avatar Carl Schwan 🚴
Browse files

Allow adding new address book sources



Signed-off-by: Carl Schwan's avatarCarl Schwan <carl@carlschwan.eu>
parent 6729bbd2
Pipeline #174829 passed with stage
in 4 minutes and 40 seconds
......@@ -2,21 +2,26 @@
// SPDX-License-Identifier: LGPL-2.0-or-later
#include "agentconfiguration.h"
#include "kalendarapplication.h"
#include <Akonadi/AgentConfigurationDialog>
#include <Akonadi/AgentInstanceCreateJob>
#include <Akonadi/AgentInstanceModel>
#include <Akonadi/AgentManager>
#include <Akonadi/AgentTypeModel>
#include <KContacts/Addressee>
#include <KContacts/ContactGroup>
#include <KWindowSystem>
#include <QDebug>
#include <QPointer>
#include <qobjectdefs.h>
using namespace Akonadi;
AgentConfiguration::AgentConfiguration(QObject *parent)
: QObject(parent)
, m_mode(KalendarApplication::Event)
{
connect(Akonadi::AgentManager::self(), &Akonadi::AgentManager::instanceProgressChanged, this, &AgentConfiguration::processInstanceProgressChanged);
connect(Akonadi::AgentManager::self(), &Akonadi::AgentManager::instanceStatusChanged, this, &AgentConfiguration::processInstanceProgressChanged);
......@@ -32,7 +37,12 @@ Akonadi::AgentFilterProxyModel *AgentConfiguration::availableAgents()
auto agentInstanceModel = new AgentTypeModel(this);
m_availableAgents = new AgentFilterProxyModel(this);
m_availableAgents->addMimeTypeFilter(QStringLiteral("text/calendar"));
if (m_mode == KalendarApplication::Contact) {
m_availableAgents->addMimeTypeFilter(KContacts::Addressee::mimeType());
m_availableAgents->addMimeTypeFilter(KContacts::ContactGroup::mimeType());
} else {
m_availableAgents->addMimeTypeFilter(QStringLiteral("text/calendar"));
}
m_availableAgents->setSourceModel(agentInstanceModel);
m_availableAgents->addCapabilityFilter(QStringLiteral("Resource")); // show only resources, no agents
return m_availableAgents;
......@@ -46,7 +56,12 @@ Akonadi::AgentFilterProxyModel *AgentConfiguration::runningAgents()
auto agentInstanceModel = new AgentInstanceModel(this);
m_runningAgents = new AgentFilterProxyModel(this);
m_runningAgents->addMimeTypeFilter(QStringLiteral("text/calendar"));
if (m_mode == KalendarApplication::Contact) {
m_runningAgents->addMimeTypeFilter(KContacts::Addressee::mimeType());
m_runningAgents->addMimeTypeFilter(KContacts::ContactGroup::mimeType());
} else {
m_runningAgents->addMimeTypeFilter(QStringLiteral("text/calendar"));
}
m_runningAgents->setSourceModel(agentInstanceModel);
m_runningAgents->addCapabilityFilter(QStringLiteral("Resource")); // show only resources, no agents
return m_runningAgents;
......@@ -141,3 +156,31 @@ void AgentConfiguration::processInstanceProgressChanged(const Akonadi::AgentInst
Q_EMIT agentProgressChanged(instanceData);
}
KalendarApplication::Mode AgentConfiguration::mode() const
{
return m_mode;
}
void AgentConfiguration::setMode(KalendarApplication::Mode mode)
{
if (mode == m_mode) {
return;
}
m_mode = mode;
Q_EMIT modeChanged();
if (m_runningAgents) {
delete m_runningAgents;
m_runningAgents = nullptr;
Q_EMIT runningAgentsChanged();
}
if (m_availableAgents) {
delete m_availableAgents;
m_availableAgents = nullptr;
Q_EMIT availableAgentsChanged();
}
}
......@@ -7,12 +7,14 @@
#include <Akonadi/AgentInstance>
#include <QObject>
#include <QTimer>
#include "kalendarapplication.h"
class AgentConfiguration : public QObject
{
Q_OBJECT
Q_PROPERTY(Akonadi::AgentFilterProxyModel *availableAgents READ availableAgents CONSTANT)
Q_PROPERTY(Akonadi::AgentFilterProxyModel *runningAgents READ runningAgents CONSTANT)
Q_PROPERTY(Akonadi::AgentFilterProxyModel *availableAgents READ availableAgents NOTIFY availableAgentsChanged)
Q_PROPERTY(Akonadi::AgentFilterProxyModel *runningAgents READ runningAgents NOTIFY runningAgentsChanged)
Q_PROPERTY(KalendarApplication::Mode mode READ mode WRITE setMode NOTIFY modeChanged)
public:
enum AgentStatuses {
Idle = Akonadi::AgentInstance::Idle,
......@@ -27,6 +29,8 @@ public:
Akonadi::AgentFilterProxyModel *availableAgents();
Akonadi::AgentFilterProxyModel *runningAgents();
KalendarApplication::Mode mode() const;
void setMode(KalendarApplication::Mode mode);
Q_INVOKABLE void createNew(int index);
Q_INVOKABLE void edit(int index);
......@@ -41,6 +45,9 @@ public Q_SLOTS:
Q_SIGNALS:
void agentProgressChanged(const QVariantMap agentData);
void modeChanged();
void runningAgentsChanged();
void availableAgentsChanged();
private:
void setupEdit(Akonadi::AgentInstance instance);
......@@ -49,4 +56,5 @@ private:
Akonadi::AgentFilterProxyModel *m_runningAgents = nullptr;
Akonadi::AgentFilterProxyModel *m_availableAgents = nullptr;
KalendarApplication::Mode m_mode;
};
......@@ -9,7 +9,14 @@ import org.kde.kalendar 1.0
Kirigami.Page {
id: sourcesSettingsPage
title: i18n("Calendar Sources")
title: switch (mode) {
case KalendarApplication.Contact:
return i18n("Address Book Sources");
case KalendarApplication.Event:
return i18n("Calendar Sources");
}
property int mode: AgentConfiguration.mode
ColumnLayout {
anchors.fill: parent
......@@ -22,8 +29,8 @@ Kirigami.Page {
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
model: AgentConfiguration.runningAgents // CalendarManager.collections
delegate: Kirigami.BasicListItem { // Originally swipelistitem, caused issues in mobile mode
model: AgentConfiguration.runningAgents
delegate: Kirigami.BasicListItem {
id: listItem
leftPadding: Kirigami.Units.largeSpacing * 2
topPadding: Kirigami.Units.largeSpacing
......@@ -128,7 +135,7 @@ Kirigami.Page {
id: addCalendarPage
Kirigami.ScrollablePage {
id: overlay
title: i18n("Add New Calendar Source")
title: sourcesSettingsPage.mode === KalendarApplication.Contact ? i18n("Add New Address Book Source…") : i18n("Add New Calendar Source")
footer: Controls.DialogButtonBox {
Kirigami.Theme.inherit: false
......@@ -163,7 +170,8 @@ Kirigami.Page {
Layout.fillWidth: true
Controls.Button {
Layout.alignment: Qt.AlignRight
text: i18n("Add New Calendar Source…")
text: mode === KalendarApplication.Contact ? i18n("Add New Address Book Source…") : i18n("Add New Calendar Source")
icon.name: "list-add"
onClicked: pageStack.pushDialogLayer(addCalendarPage)
}
......
......@@ -5,6 +5,7 @@ import QtQuick 2.15
import org.kde.kirigami 2.18 as Kirigami
import QtQuick.Controls 2.15 as Controls
import QtQuick.Layouts 1.15
import org.kde.kalendar 1.0
Kirigami.CategorizedSettings {
objectName: "settingsPage"
......@@ -23,6 +24,13 @@ Kirigami.CategorizedSettings {
text: i18n("Calendar Sources")
icon.name: "preferences-system-users"
page: Qt.resolvedUrl("SourceSettingsPage.qml")
onTriggered: AgentConfiguration.mode = KalendarApplication.Event
},
Kirigami.SettingAction {
text: i18n("Address Book Sources")
icon.name: "preferences-system-users"
page: Qt.resolvedUrl("SourceSettingsPage.qml")
onTriggered: AgentConfiguration.mode = KalendarApplication.Contact
},
Kirigami.SettingAction {
text: i18n("Calendars")
......
......@@ -150,6 +150,7 @@ int main(int argc, char *argv[])
qmlRegisterType<InfiniteCalendarViewModel>("org.kde.kalendar", 1, 0, "InfiniteCalendarViewModel");
qRegisterMetaType<Akonadi::ETMCalendar::Ptr>();
qRegisterMetaType<QAbstractProxyModel *>("QAbstractProxyModel*");
qRegisterMetaType<Akonadi::AgentFilterProxyModel *>();
qRegisterMetaType<KContacts::Picture>("KContacts::Picture");
qRegisterMetaType<KContacts::PhoneNumber::List>("KContacts::PhoneNumber::List");
......
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