Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit adc49ff5 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Port Archive mail agent to new config API

Summary:
The new API allows us to open agent configuration dialogs inside of the
application process that wants to show the dialog instead of having the
configuration dialogs running inside of the Akonadi agent process.

This is necessary for single-process Akonadi (running the Server and
Agent within a single process in multiple threads) and for Wayland as
well as we can no longer control placment of the configuration window
on top of other process' window.

Reviewers: mlaurent

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D14902
parent 654c55c6
......@@ -54,7 +54,7 @@ set(KMAILTRANSPORT_LIB_VERSION "5.9.40")
set(KONTACTINTERFACE_LIB_VERSION "5.9.40")
set(KMIME_LIB_VERSION "5.9.40")
set(KPIMTEXTEDIT_LIB_VERSION "5.9.41")
set(AKONADI_VERSION "5.9.40")
set(AKONADI_VERSION "5.9.41")
set(KTNEF_LIB_VERSION "5.9.40")
set(KDEPIM_LIB_VERSION "${KDEPIM_VERSION_NUMBER}")
......
add_definitions(-DTRANSLATION_DOMAIN=\"akonadi_archivemail_agent\")
set(archivemailagent_SRCS
set(libarchivemailagent_SRCS
archivemailkernel.cpp
archivemailagent.cpp
archivemailmanager.cpp
archivemaildialog.cpp
archivemailinfo.cpp
addarchivemaildialog.cpp
archivemailwidget.cpp
job/archivejob.cpp
archivemailagentutil.cpp
widgets/formatcombobox.cpp
widgets/unitcombobox.cpp
)
kconfig_add_kcfg_files(archivemailagent_SRCS
kconfig_add_kcfg_files(libarchivemailagent_SRCS
settings/archivemailagentsettings.kcfgc
)
qt5_add_dbus_adaptor(archivemailagent_SRCS org.freedesktop.Akonadi.ArchiveMailAgent.xml archivemailagent.h ArchiveMailAgent)
qt5_add_dbus_adaptor(libarchivemailagent_SRCS org.freedesktop.Akonadi.ArchiveMailAgent.xml archivemailagent.h ArchiveMailAgent)
ecm_qt_declare_logging_category(libarchivemailagent_SRCS HEADER archivemailagent_debug.h IDENTIFIER ARCHIVEMAILAGENT_LOG CATEGORY_NAME org.kde.pim.archivemailagent)
ecm_qt_declare_logging_category(archivemailagent_SRCS HEADER archivemailagent_debug.h IDENTIFIER ARCHIVEMAILAGENT_LOG CATEGORY_NAME org.kde.pim.archivemailagent)
ki18n_wrap_ui(libarchivemailagent_SRCS ui/archivemailwidget.ui )
add_library(archivemailagent STATIC ${libarchivemailagent_SRCS})
target_link_libraries(archivemailagent
KF5::MailCommon
KF5::I18n
KF5::Notifications
KF5::IconThemes
KF5::KIOWidgets
)
ki18n_wrap_ui(archivemailagent_SRCS ui/archivemailwidget.ui )
########################### Agent executable ################################
add_executable(akonadi_archivemail_agent ${archivemailagent_SRCS})
add_executable(akonadi_archivemail_agent archivemailagent.cpp)
target_link_libraries(akonadi_archivemail_agent
archivemailagent
KF5::AkonadiCore
KF5::IdentityManagement
KF5::AkonadiMime
......@@ -55,8 +60,31 @@ install(TARGETS akonadi_archivemail_agent ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} )
install(FILES archivemailagent.desktop DESTINATION "${KDE_INSTALL_DATAROOTDIR}/akonadi/agents")
install(FILES akonadi_archivemail_agent.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFY5RCDIR} )
install(FILES settings/archivemailagentsettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
if (BUILD_TESTING)
add_subdirectory(autotests)
endif()
########## Configuration ##############
set(archivemailagentconfig_SRCS
addarchivemaildialog.cpp
archivemailwidget.cpp
widgets/formatcombobox.cpp
widgets/unitcombobox.cpp
)
kcoreaddons_add_plugin(archivemailagentconfig
JSON archivemailagentconfig.json
SOURCES ${archivemailagentconfig_SRCS}
INSTALL_NAMESPACE akonadi/config
)
target_link_libraries(archivemailagentconfig
archivemailagent
KF5::AkonadiCore
KF5::WindowSystem
KF5::XmlGui
KF5::I18n
)
install(FILES settings/archivemailagentsettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
......@@ -19,7 +19,6 @@
#include "archivemailagent.h"
#include "archivemailagentadaptor.h"
#include "archivemaildialog.h"
#include "archivemailmanager.h"
#include "archivemailagentsettings.h"
#include <AkonadiCore/ServerManager>
......@@ -45,6 +44,8 @@ ArchiveMailAgent::ArchiveMailAgent(const QString &id)
migrate.setConfigFiles(QStringList() << QStringLiteral("akonadi_archivemail_agentrc") << QStringLiteral("akonadi_archivemail_agent.notifyrc"));
migrate.migrate();
connect(this, &Akonadi::AgentBase::reloadConfiguration, this, &ArchiveMailAgent::reload);
mArchiveManager = new ArchiveMailManager(this);
connect(mArchiveManager, &ArchiveMailManager::needUpdateConfigDialogBox, this, &ArchiveMailAgent::needUpdateConfigDialogBox);
......@@ -58,7 +59,7 @@ ArchiveMailAgent::ArchiveMailAgent(const QString &id)
new ArchiveMailAgentAdaptor(this);
KDBusConnectionPool::threadConnection().registerObject(QStringLiteral("/ArchiveMailAgent"), this, QDBusConnection::ExportAdaptors);
const QString service = Akonadi::ServerManager::self()->agentServiceName(Akonadi::ServerManager::Agent, QStringLiteral("akonadi_archivemail_agent"));
const QString service = Akonadi::ServerManager::self()->agentServiceName(Akonadi::ServerManager::Agent, identifier());
KDBusConnectionPool::threadConnection().registerService(service);
connect(collectionMonitor, &Akonadi::Monitor::collectionRemoved, this, &ArchiveMailAgent::mailCollectionRemoved);
......@@ -120,7 +121,7 @@ void ArchiveMailAgent::reload()
mTimer->start();
}
}
#if 0
void ArchiveMailAgent::configure(WId windowId)
{
QPointer<ArchiveMailDialog> dialog = new ArchiveMailDialog();
......@@ -134,7 +135,7 @@ void ArchiveMailAgent::configure(WId windowId)
}
delete dialog;
}
#endif
void ArchiveMailAgent::pause()
{
if (isOnline() && enabledAgent()) {
......
......@@ -48,7 +48,6 @@ Q_SIGNALS:
void needUpdateConfigDialogBox();
public Q_SLOTS:
void configure(WId windowId) override;
void reload();
void pause();
void resume();
......
{
"X-Akonadi-PluginType": "AgentConfig",
"X-Akonadi-Library": "archivemailagentconfig",
"X-Akonadi-AgentConfig-Type": "akonadi_archivemail_agent"
}
/*
Copyright (C) 2012-2018 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "archivemaildialog.h"
#include "archivemailwidget.h"
#include "kmail-version.h"
#include <MailCommon/MailUtil>
#include <QMenu>
#include <KHelpMenu>
#include <kaboutdata.h>
#include <QIcon>
#include <QHBoxLayout>
#include <KSharedConfig>
#include <QDialogButtonBox>
#include <KConfigGroup>
#include <QPushButton>
ArchiveMailDialog::ArchiveMailDialog(QWidget *parent)
: QDialog(parent)
{
setWindowTitle(i18n("Configure Archive Mail Agent"));
setWindowIcon(QIcon::fromTheme(QStringLiteral("kmail")));
setModal(true);
QVBoxLayout *vlay = new QVBoxLayout(this);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->setMargin(0);
vlay->addLayout(mainLayout);
mWidget = new ArchiveMailWidget(this);
connect(mWidget, &ArchiveMailWidget::archiveNow, this, &ArchiveMailDialog::archiveNow);
mWidget->setObjectName(QStringLiteral("archivemailwidget"));
mainLayout->addWidget(mWidget);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help, this);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::rejected, this, &ArchiveMailDialog::reject);
connect(buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &ArchiveMailDialog::slotSave);
vlay->addWidget(buttonBox);
readConfig();
KAboutData aboutData = KAboutData(
QStringLiteral("archivemailagent"),
i18n("Archive Mail Agent"),
QStringLiteral(KDEPIM_VERSION),
i18n("Archive emails automatically."),
KAboutLicense::GPL_V2,
i18n("Copyright (C) 2012-2018 Laurent Montel"));
aboutData.addAuthor(i18n("Laurent Montel"),
i18n("Maintainer"), QStringLiteral("montel@kde.org"));
QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("kmail")));
aboutData.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"),
i18nc("EMAIL OF TRANSLATORS", "Your emails"));
KHelpMenu *helpMenu = new KHelpMenu(this, aboutData, true);
//Initialize menu
QMenu *menu = helpMenu->menu();
helpMenu->action(KHelpMenu::menuAboutApp)->setIcon(QIcon::fromTheme(QStringLiteral("kmail")));
buttonBox->button(QDialogButtonBox::Help)->setMenu(menu);
}
ArchiveMailDialog::~ArchiveMailDialog()
{
writeConfig();
}
void ArchiveMailDialog::slotNeedReloadConfig()
{
mWidget->needReloadConfig();
}
static const char myConfigGroupName[] = "ArchiveMailDialog";
void ArchiveMailDialog::readConfig()
{
KConfigGroup group(KSharedConfig::openConfig(), myConfigGroupName);
const QSize size = group.readEntry("Size", QSize(500, 300));
if (size.isValid()) {
resize(size);
}
mWidget->restoreTreeWidgetHeader(group.readEntry("HeaderState", QByteArray()));
}
void ArchiveMailDialog::writeConfig()
{
KConfigGroup group(KSharedConfig::openConfig(), myConfigGroupName);
group.writeEntry("Size", size());
mWidget->saveTreeWidgetHeader(group);
group.sync();
}
void ArchiveMailDialog::slotSave()
{
mWidget->save();
accept();
}
/*
Copyright (C) 2012-2018 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef ARCHIVEMAILDIALOG_H
#define ARCHIVEMAILDIALOG_H
#include "archivemailinfo.h"
#include <QDialog>
class ArchiveMailWidget;
class ArchiveMailDialog : public QDialog
{
Q_OBJECT
public:
explicit ArchiveMailDialog(QWidget *parent = nullptr);
~ArchiveMailDialog();
Q_SIGNALS:
void archiveNow(ArchiveMailInfo *info);
public Q_SLOTS:
void slotNeedReloadConfig();
protected Q_SLOTS:
void slotSave();
private:
void writeConfig();
void readConfig();
ArchiveMailWidget *mWidget = nullptr;
};
#endif /* ARCHIVEMAILWIDGET_H */
......@@ -24,6 +24,8 @@
#include "archivemailinfo.h"
#include <QTreeWidgetItem>
#include <AkonadiCore/AgentConfigurationBase>
class ArchiveMailItem : public QTreeWidgetItem
{
public:
......@@ -37,11 +39,11 @@ private:
ArchiveMailInfo *mInfo = nullptr;
};
class ArchiveMailWidget : public QWidget
class ArchiveMailWidget : public Akonadi::AgentConfigurationBase
{
Q_OBJECT
public:
explicit ArchiveMailWidget(QWidget *parent = nullptr);
explicit ArchiveMailWidget(KSharedConfigPtr config, QWidget *parentWidget, const QVariantList &args);
~ArchiveMailWidget();
enum ArchiveMailColumn {
......@@ -51,16 +53,15 @@ public:
StorageDirectory
};
void save();
void saveTreeWidgetHeader(KConfigGroup &group);
void restoreTreeWidgetHeader(const QByteArray &group);
bool save() const override;
void load() override;
void needReloadConfig();
Q_SIGNALS:
void archiveNow(ArchiveMailInfo *info);
private:
void load();
void createOrUpdateItem(ArchiveMailInfo *info, ArchiveMailItem *item = nullptr);
bool verifyExistingArchive(ArchiveMailInfo *info) const;
void updateDiffDate(ArchiveMailItem *item, ArchiveMailInfo *info);
......@@ -73,8 +74,11 @@ private:
void slotCustomContextMenuRequested(const QPoint &);
void slotArchiveNow();
void slotItemChanged(QTreeWidgetItem *item, int);
bool mChanged = false;
Ui::ArchiveMailWidget *mWidget = nullptr;
Ui::ArchiveMailWidget mWidget;
};
AKONADI_AGENTCONFIG_FACTORY(ArchiveMailAgentConfigFactory, "archivemailagentconfig.json", ArchiveMailWidget)
#endif // ARCHIVEMAILWIDGET_H
......@@ -2,17 +2,17 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/
# Convenience macro to add unit tests.
macro( archivemail_agent _source)
set( _test ${_source} ../archivemailinfo.cpp ../archivemaildialog.cpp ../archivemailagentutil.cpp ../addarchivemaildialog.cpp ../widgets/formatcombobox.cpp ../widgets/unitcombobox.cpp ../archivemailwidget.cpp)
set( _test ${_source} ../archivemailwidget.cpp ../addarchivemaildialog.cpp ../widgets/formatcombobox.cpp ../widgets/unitcombobox.cpp)
ki18n_wrap_ui(_test ../ui/archivemailwidget.ui )
ecm_qt_declare_logging_category(_test HEADER archivemailagent_debug.h IDENTIFIER ARCHIVEMAILAGENT_LOG CATEGORY_NAME org.kde.pim.archivemailagent)
get_filename_component( _name ${_source} NAME_WE )
add_executable( ${_name} ${_test} )
add_test(NAME ${_name} COMMAND ${_name} )
ecm_mark_as_test(archivemailagent-${_name})
target_link_libraries( ${_name} Qt5::Test Qt5::Core KF5::MailCommon KF5::AkonadiCore KF5::XmlGui KF5::KIOWidgets KF5::Libkdepim KF5::I18n)
target_link_libraries( ${_name} archivemailagent Qt5::Test Qt5::Core KF5::MailCommon KF5::AkonadiCore KF5::XmlGui KF5::KIOWidgets KF5::Libkdepim KF5::I18n)
endmacro()
archivemail_agent(archivemailinfotest.cpp )
archivemail_agent(archivemaildialogtest.cpp)
archivemail_agent(archivemailwidgettest.cpp)
archivemail_agent(formatcomboboxtest.cpp)
archivemail_agent(unitcomboboxtest.cpp)
......@@ -17,33 +17,32 @@
Boston, MA 02110-1301, USA.
*/
#include "archivemaildialogtest.h"
#include "../archivemaildialog.h"
#include "archivemailwidgettest.h"
#include "../archivemailwidget.h"
#include <qtest.h>
#include <QTreeWidget>
#include "../archivemailwidget.h"
#include <QStandardPaths>
ArchiveMailDialogTest::ArchiveMailDialogTest(QObject *parent)
ArchiveMailWidgetTest::ArchiveMailWidgetTest(QObject *parent)
: QObject(parent)
{
QStandardPaths::setTestModeEnabled(true);
}
ArchiveMailDialogTest::~ArchiveMailDialogTest()
ArchiveMailWidgetTest::~ArchiveMailWidgetTest()
{
}
void ArchiveMailDialogTest::shouldHaveDefaultValue()
void ArchiveMailWidgetTest::shouldHaveDefaultValue()
{
ArchiveMailDialog dlg;
ArchiveMailWidget *mailwidget = dlg.findChild<ArchiveMailWidget *>(QStringLiteral("archivemailwidget"));
QVERIFY(mailwidget);
QTreeWidget *treeWidget = mailwidget->findChild<QTreeWidget *>(QStringLiteral("treewidget"));
QWidget parent;
ArchiveMailWidget mailwidget({}, &parent, {QStringLiteral("akonadi_archivemail_agent")});
QTreeWidget *treeWidget = parent.findChild<QTreeWidget *>(QStringLiteral("treewidget"));
QVERIFY(treeWidget);
QCOMPARE(treeWidget->topLevelItemCount(), 0);
}
QTEST_MAIN(ArchiveMailDialogTest)
QTEST_MAIN(ArchiveMailWidgetTest)
......@@ -17,20 +17,20 @@
Boston, MA 02110-1301, USA.
*/
#ifndef ARCHIVEMAILDIALOGTEST_H
#define ARCHIVEMAILDIALOGTEST_H
#ifndef ARCHIVEMAILWIDGETTEST_H
#define ARCHIVEMAILWIDGETTEST_H
#include <QObject>
class ArchiveMailDialogTest : public QObject
class ArchiveMailWidgetTest : public QObject
{
Q_OBJECT
public:
explicit ArchiveMailDialogTest(QObject *parent = nullptr);
~ArchiveMailDialogTest();
explicit ArchiveMailWidgetTest(QObject *parent = nullptr);
~ArchiveMailWidgetTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
};
#endif // ARCHIVEMAILDIALOGTEST_H
#endif // ARCHIVEMAILWIDGETTEST_H
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