Commit a4d7a0d1 authored by Laurent Montel's avatar Laurent Montel 😁

Move progressmanagerakonadi from libkdepim

parent 8e32c6b5
Pipeline #23644 passed with stage
in 27 minutes and 37 seconds
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.14.44")
set(PIM_VERSION "5.14.45")
project(pimcommon VERSION ${PIM_VERSION})
......
......@@ -71,6 +71,10 @@ set(libpimcommonakonadi_util_SRCS
util/mailutil.cpp
)
set(libpimcommonakonadi_progresswidget_SRCS
progresswidget/agentprogressmonitor.cpp
progresswidget/progressmanagerakonadi.cpp)
set(libpimcommonakonadi_collection_SRCS
collectionpage/collectiontypeutil.cpp
collectionpage/attributeregistrar.cpp
......@@ -90,6 +94,7 @@ set(libpimcommonakonadi_SRCS
${libpimcommonakonadi_manageserversidesubscription_SRCS}
${libpimcommonakonadi_widgets_SRCS}
${libpimcommonakonadi_util_SRCS}
${libpimcommonakonadi_progresswidget_SRCS}
)
......@@ -178,6 +183,13 @@ ecm_generate_headers(PimCommonAkonadiUtil_CamelCase_HEADERS
RELATIVE util
)
ecm_generate_headers(libkdepimakonadi_Camelcaseprogresswidget_HEADERS
HEADER_NAMES
ProgressManagerAkonadi
REQUIRED_HEADERS libkdepimakonadi_progresswidget_HEADERS
PREFIX PimCommonAkonadi
RELATIVE progresswidget
)
ecm_generate_headers(PimCommonAkonadi_Camelcasewidgets_HEADERS
HEADER_NAMES
......@@ -246,6 +258,7 @@ install(FILES
${PimCommon_Camelcasemanagerserversidesubscription_HEADERS}
${PimCommonAkonadi_Camelcasewidgets_HEADERS}
${PimCommonAkonadiUtil_CamelCase_HEADERS}
${libkdepimakonadi_Camelcaseprogresswidget_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/PimCommonAkonadi
COMPONENT Devel
)
......@@ -263,6 +276,7 @@ install(FILES
${PimCommonAkonadi_widgets_HEADERS}
${PimCommon_managerserversidesubscription_HEADERS}
${PimCommonAkonadiUtil_HEADERS}
${libkdepimakonadi_progresswidget_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/pimcommonakonadi
COMPONENT Devel
......
/*
Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "agentprogressmonitor.h"
#include <AgentManager>
using namespace Akonadi;
using namespace PimCommon;
AgentProgressMonitor::AgentProgressMonitor(const AgentInstance &agent, KPIM::ProgressItem *item)
: QObject(item)
, mAgent(agent)
, mItem(item)
{
connect(AgentManager::self(), &AgentManager::instanceProgressChanged,
this, &AgentProgressMonitor::instanceProgressChanged);
connect(AgentManager::self(), &AgentManager::instanceStatusChanged,
this, &AgentProgressMonitor::instanceStatusChanged);
connect(Akonadi::AgentManager::self(), &AgentManager::instanceRemoved,
this, &AgentProgressMonitor::instanceRemoved);
connect(Akonadi::AgentManager::self(), &AgentManager::instanceNameChanged,
this, &AgentProgressMonitor::instanceNameChanged);
// TODO connect to instanceError, instanceWarning, instanceOnline ?
// and do what?
connect(item, &KPIM::ProgressItem::progressItemCanceled,
this, &AgentProgressMonitor::abort);
// TODO handle offline case
}
AgentProgressMonitor::~AgentProgressMonitor()
{
}
void AgentProgressMonitor::abort()
{
mAgent.abortCurrentTask();
}
void AgentProgressMonitor::instanceRemoved(const Akonadi::AgentInstance &instance)
{
Q_UNUSED(instance);
if (!mItem.data()) {
return;
}
mItem.data()->disconnect(this); // avoid abort call
mItem.data()->cancel();
if (mItem.data()) {
mItem.data()->setComplete();
}
}
void AgentProgressMonitor::instanceProgressChanged(const AgentInstance &instance)
{
if (!mItem.data()) {
return;
}
if (mAgent == instance) { // compares identifiers
mAgent = instance; // keeps copy of current status
const int progress = mAgent.progress();
if (progress >= 0) {
mItem.data()->setProgress(progress);
}
}
}
void AgentProgressMonitor::instanceStatusChanged(const AgentInstance &instance)
{
if (!mItem.data()) {
return;
}
if (mAgent == instance) { // compares identifiers
mAgent = instance; // keeps copy of current status
mItem.data()->setStatus(mAgent.statusMessage());
switch (mAgent.status()) {
case AgentInstance::Idle:
if (mItem.data()) {
mItem.data()->setComplete();
}
break;
case AgentInstance::Running:
break;
case AgentInstance::Broken:
mItem.data()->disconnect(this); // avoid abort call
mItem.data()->cancel();
if (mItem.data()) {
mItem.data()->setComplete();
}
break;
default:
Q_ASSERT(false);
}
}
}
void AgentProgressMonitor::instanceNameChanged(const Akonadi::AgentInstance &instance)
{
if (!mItem.data()) {
return;
}
mItem.data()->setLabel(instance.name());
}
/*
Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef PIMCOMMON_AGENTPROGRESSMONITOR_H
#define PIMCOMMON_AGENTPROGRESSMONITOR_H
#include <Libkdepim/ProgressManager> // ProgressItem
#include <AgentInstance>
namespace PimCommon {
/**
* @internal
*
* This class automatically updates a ProgressItem based on
* Akonadi::AgentManager's signals, and places the abort() call if the
* ProgressItem has been cancelled.
*/
class AgentProgressMonitor : public QObject
{
Q_OBJECT
public:
// used by our friend ProgressManager
AgentProgressMonitor(const Akonadi::AgentInstance &mAgent, KPIM::ProgressItem *mItem);
~AgentProgressMonitor();
private:
void abort();
void instanceProgressChanged(const Akonadi::AgentInstance &);
void instanceStatusChanged(const Akonadi::AgentInstance &);
void instanceRemoved(const Akonadi::AgentInstance &);
void instanceNameChanged(const Akonadi::AgentInstance &);
Akonadi::AgentInstance mAgent;
QPointer<KPIM::ProgressItem> const mItem;
};
}
#endif
/*
progressmanager.cpp
Copyright (c) 2004 Till Adam <adam@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "progressmanagerakonadi.h"
#include "agentprogressmonitor.h"
KPIM::ProgressItem *PimCommon::ProgressManagerAkonadi::createProgressItem(KPIM::ProgressItem *parent, const Akonadi::AgentInstance &agent, const QString &id, const QString &label, const QString &status, bool canBeCanceled, KPIM::ProgressItem::CryptoStatus cryptoStatus)
{
const bool itemAlreadyExists = (KPIM::ProgressManager::instance()->progressItem(id) != nullptr);
KPIM::ProgressItem *t = KPIM::ProgressManager::instance()->createProgressItem(parent, id, label,
status, canBeCanceled, cryptoStatus);
t->setTypeProgressItem(0);
if (!itemAlreadyExists) {
// qCDebug(LIBKDEPIM_LOG) << "Created ProgressItem for agent" << instance.name();
new AgentProgressMonitor(agent, t);
}
return t;
}
/*
progressmanager.cpp
Copyright (c) 2004 Till Adam <adam@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef PROGRESSMANAGERAKONADI_H
#define PROGRESSMANAGERAKONADI_H
#include "pimcommonakonadi_export.h"
#include <Libkdepim/ProgressManager>
#include <AkonadiCore/AgentInstance>
namespace PimCommon {
namespace ProgressManagerAkonadi {
PIMCOMMONAKONADI_EXPORT KPIM::ProgressItem *createProgressItem(KPIM::ProgressItem *parent, const Akonadi::AgentInstance &agent, const QString &id, const QString &label, const QString &status, bool canBeCanceled, KPIM::ProgressItem::CryptoStatus cryptoStatus);
}
}
#endif // PROGRESSMANAGERAKONADI_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