diff --git a/CMakeLists.txt b/CMakeLists.txt index e49ee1a..7066dd4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,79 +1,79 @@ cmake_minimum_required(VERSION 3.5) -set(PIM_VERSION "5.12.40") +set(PIM_VERSION "5.12.41") project(kdepim-apps-lib VERSION ${PIM_VERSION}) set(KF5_MIN_VERSION "5.63.0") find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) set(LIBRARY_NAMELINK) if (POLICY CMP0053) cmake_policy(SET CMP0053 NEW) endif() include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(GenerateExportHeader) include(ECMGenerateHeaders) include(ECMGeneratePriFile) include(ECMSetupVersion) include(FeatureSummary) include(ECMQtDeclareLoggingCategory) include(ECMAddTests) set(KDEPIM_APPS_LIB_VERSION ${PIM_VERSION}) set(QT_REQUIRED_VERSION "5.11.0") set(AKONADI_VERSION "5.12.40") set(GRANTLEETHEME_LIB_VERSION "5.12.40") set(AKONADICONTACT_LIB_VERSION "5.12.40") set(LIBKLEO_LIB_VERSION "5.12.40") set(PIMCOMMON_LIB_VERSION "5.12.40") find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Widgets DBus Gui) find_package(KF5Config ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5ConfigWidgets ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5CoreAddons ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5I18n ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5IconThemes ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5KIO ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Service ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5WidgetsAddons ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Akonadi ${AKONADI_VERSION} CONFIG REQUIRED) find_package(KF5AkonadiContact ${AKONADICONTACT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Contacts ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5ContactEditor ${AKONADICONTACT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5GrantleeTheme ${GRANTLEETHEME_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Libkleo ${LIBKLEO_LIB_VERSION} CONFIG REQUIRED) find_package(KF5PimCommonAkonadi ${PIMCOMMON_LIB_VERSION} CONFIG REQUIRED) find_package(Grantlee5 "5.1" CONFIG REQUIRED) find_package(KF5Prison ${KF5_MIN_VERSION} CONFIG REQUIRED) if(BUILD_TESTING) find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Test) add_definitions(-DBUILD_TESTING) endif() if (EXISTS "${CMAKE_SOURCE_DIR}/.git") add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) endif() add_definitions(-DQT_NO_FOREACH) add_subdirectory(libfollowupreminder) add_subdirectory(libkdepimdbusinterfaces) add_subdirectory(libsendlater) add_subdirectory(kaddressbookgrantlee) add_subdirectory(kaddressbookimportexport) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) install(FILES kdepim-apps-lib.renamecategories kdepim-apps-lib.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}) diff --git a/libsendlater/src/sendlaterutil.cpp b/libsendlater/src/sendlaterutil.cpp index 81c0f7b..c05f444 100644 --- a/libsendlater/src/sendlaterutil.cpp +++ b/libsendlater/src/sendlaterutil.cpp @@ -1,151 +1,164 @@ /* Copyright (C) 2013-2019 Montel Laurent 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 "sendlaterutil.h" #include "sendlaterutil_p.h" #include "sendlaterinfo.h" #include "sendlateragentsettings.h" #include "libsendlater_debug.h" #include #include #include #include namespace { QString serviceName() { return Akonadi::ServerManager::agentServiceName(Akonadi::ServerManager::Agent, QStringLiteral("akonadi_sendlater_agent")); } QString dbusPath() { return QStringLiteral("/SendLaterAgent"); } } bool SendLater::SendLaterUtil::compareSendLaterInfo(SendLater::SendLaterInfo *left, SendLater::SendLaterInfo *right) { if (left->dateTime() == right->dateTime()) { //Set no recursive first. if (left->isRecurrence()) { return false; } } return left->dateTime() < right->dateTime(); } void SendLater::SendLaterUtil::changeRecurrentDate(SendLater::SendLaterInfo *info) { if (info && info->isRecurrence()) { qCDebug(LIBSENDLATER_LOG) << "BEFORE SendLater::SendLaterUtil::changeRecurrentDate " << info->dateTime().toString(); QDateTime newInfoDateTime = info->dateTime(); newInfoDateTime = updateRecurence(info, newInfoDateTime); qCDebug(LIBSENDLATER_LOG) << " QDateTime::currentDateTime()" << QDateTime::currentDateTime().toString(); while (newInfoDateTime <= QDateTime::currentDateTime()) { newInfoDateTime = updateRecurence(info, newInfoDateTime); } info->setDateTime(newInfoDateTime); qCDebug(LIBSENDLATER_LOG) << "AFTER SendLater::SendLaterUtil::changeRecurrentDate " << info->dateTime().toString() << " info" << info << "New date" << newInfoDateTime; writeSendLaterInfo(defaultConfig(), info, true); } } QDateTime SendLater::SendLaterUtil::updateRecurence(SendLater::SendLaterInfo *info, QDateTime dateTime) { switch (info->recurrenceUnit()) { case SendLater::SendLaterInfo::Days: dateTime = dateTime.addDays(info->recurrenceEachValue()); break; case SendLater::SendLaterInfo::Weeks: dateTime = dateTime.addDays(info->recurrenceEachValue() * 7); break; case SendLater::SendLaterInfo::Months: dateTime = dateTime.addMonths(info->recurrenceEachValue()); break; case SendLater::SendLaterInfo::Years: dateTime = dateTime.addYears(info->recurrenceEachValue()); break; } return dateTime; } KSharedConfig::Ptr SendLater::SendLaterUtil::defaultConfig() { return KSharedConfig::openConfig(QStringLiteral("akonadi_sendlater_agentrc"), KConfig::SimpleConfig); } void SendLater::SendLaterUtil::writeSendLaterInfo(KSharedConfig::Ptr config, SendLater::SendLaterInfo *info, bool forceReload) { if (!info || !info->isValid()) { return; } const QString groupName = SendLater::SendLaterUtil::sendLaterPattern().arg(info->itemId()); // first, delete all filter groups: const QStringList filterGroups = config->groupList(); for (const QString &group : filterGroups) { if (group == groupName) { config->deleteGroup(group); } } KConfigGroup group = config->group(groupName); info->writeConfig(group); config->sync(); config->reparseConfiguration(); qCDebug(LIBSENDLATER_LOG) << " reparse config"; if (forceReload) { reload(); } } bool SendLater::SendLaterUtil::sentLaterAgentWasRegistered() { QDBusInterface interface(serviceName(), dbusPath()); return interface.isValid(); } void SendLater::SendLaterUtil::forceReparseConfiguration() { SendLaterAgentSettings::self()->save(); SendLaterAgentSettings::self()->config()->reparseConfiguration(); } bool SendLater::SendLaterUtil::sentLaterAgentEnabled() { return SendLaterAgentSettings::self()->enabled(); } void SendLater::SendLaterUtil::reload() { qCDebug(LIBSENDLATER_LOG) << " void SendLater::SendLaterUtil::reload()"; QDBusInterface interface(serviceName(), dbusPath()); if (interface.isValid()) { interface.call(QStringLiteral("reload")); } else { qCDebug(LIBSENDLATER_LOG) << " Can not reload list"; } } +void SendLater::SendLaterUtil::removeItem(qint64 item) +{ + qCDebug(LIBSENDLATER_LOG) << " void SendLater::SendLaterUtil::removeItem()" << item; + + QDBusInterface interface(serviceName(), dbusPath()); + if (interface.isValid()) { + interface.call(QStringLiteral("reload"), item); + } else { + qCDebug(LIBSENDLATER_LOG) << " Can not remove item"; + } +} + + QString SendLater::SendLaterUtil::sendLaterPattern() { return QStringLiteral("SendLaterItem %1"); } diff --git a/libsendlater/src/sendlaterutil.h b/libsendlater/src/sendlaterutil.h index 0ffca69..4bab82b 100644 --- a/libsendlater/src/sendlaterutil.h +++ b/libsendlater/src/sendlaterutil.h @@ -1,49 +1,50 @@ /* Copyright (C) 2013-2019 Montel Laurent 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 SENDLATERUTIL_H #define SENDLATERUTIL_H #include "sendlater_export.h" #include namespace SendLater { class SendLaterInfo; /** Send later utilities. */ namespace SendLaterUtil { Q_REQUIRED_RESULT SENDLATER_EXPORT bool compareSendLaterInfo(SendLater::SendLaterInfo *left, SendLater::SendLaterInfo *right); SENDLATER_EXPORT KSharedConfig::Ptr defaultConfig(); SENDLATER_EXPORT void writeSendLaterInfo(KSharedConfig::Ptr config, SendLater::SendLaterInfo *info, bool forceReload = true); Q_REQUIRED_RESULT SENDLATER_EXPORT bool sentLaterAgentWasRegistered(); Q_REQUIRED_RESULT SENDLATER_EXPORT bool sentLaterAgentEnabled(); SENDLATER_EXPORT void reload(); SENDLATER_EXPORT void changeRecurrentDate(SendLater::SendLaterInfo *info); SENDLATER_EXPORT void forceReparseConfiguration(); Q_REQUIRED_RESULT SENDLATER_EXPORT QString sendLaterPattern(); +Q_REQUIRED_RESULT SENDLATER_EXPORT void removeItem(qint64 item); } } #endif // SENDLATERUTIL_H