Commit aecc5bc7 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Move it directly in pimcommon

parent 48117e07
Pipeline #23646 passed with stage
in 19 minutes and 2 seconds
......@@ -47,15 +47,9 @@ set(kdepim_addressline_plugin_LIB_SRCS
)
############ next target ###############
set(kdepimakonadi_progresswidget_LIB_SRCS
progresswidget/progressmanagerakonadi.cpp
progresswidget/agentprogressmonitor.cpp
)
set(kdepimakonadi_LIB_SRCS
${kdepim_addressline_LIB_SRCS}
${kdepim_addressline_blacklist_baloo_LIB_SRCS}
${kdepimakonadi_progresswidget_LIB_SRCS}
${kdepim_addressline_plugin_LIB_SRCS}
)
......@@ -113,14 +107,6 @@ install(TARGETS
EXPORT KF5LibkdepimAkonadiTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK}
)
ecm_generate_headers(libkdepimakonadi_Camelcaseprogresswidget_HEADERS
HEADER_NAMES
ProgressManagerAkonadi
REQUIRED_HEADERS libkdepimakonadi_progresswidget_HEADERS
PREFIX LibkdepimAkonadi
RELATIVE progresswidget
)
ecm_generate_headers(libkdepim_Camelcaseaddressline_HEADERS
HEADER_NAMES
AddresseeLineEdit
......@@ -153,7 +139,6 @@ ecm_generate_pri_file(BASE_NAME LibkdepimAkonadi
install(FILES
${libkdepim_Camelcasecompletionconfiguredialog_HEADERS}
${libkdepim_Camelcasecompletionorder_HEADERS}
${libkdepimakonadi_Camelcaseprogresswidget_HEADERS}
${libkdepim_Camelcaseaddressline_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/LibkdepimAkonadi
COMPONENT Devel
......@@ -163,7 +148,6 @@ install(FILES
${libkdepim_completionconfiguredialog_HEADERS}
${libkdepim_completionorder_HEADERS}
${CMAKE_CURRENT_BINARY_DIR}/kdepimakonadi_export.h
${libkdepimakonadi_progresswidget_HEADERS}
${libkdepim_addressline_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/libkdepimakonadi
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 KPIM;
AgentProgressMonitor::AgentProgressMonitor(const AgentInstance &agent, 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, &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 KDEPIM_AGENTPROGRESSMONITOR_H
#define KDEPIM_AGENTPROGRESSMONITOR_H
#include <Libkdepim/ProgressManager> // ProgressItem
#include <AgentInstance>
namespace KPIM {
/**
* @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, 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<ProgressItem> const mItem;
};
}
#endif
/*
progressmanager.cpp
This file is part of libkdepim.
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 *KPIM::ProgressManagerAkonadi::createProgressItem(ProgressItem *parent, const Akonadi::AgentInstance &agent, const QString &id, const QString &label, const QString &status, bool canBeCanceled, 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
This file is part of libkdepim.
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 "kdepimakonadi_export.h"
#include <Libkdepim/ProgressManager>
#include <AkonadiCore/AgentInstance>
namespace KPIM {
namespace ProgressManagerAkonadi {
KDEPIMAKONADI_EXPORT ProgressItem *createProgressItem(ProgressItem *parent, const Akonadi::AgentInstance &agent, const QString &id, const QString &label, const QString &status, bool canBeCanceled, 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