diff --git a/CMakeLists.txt b/CMakeLists.txt index 4752821..d4ecc59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,140 +1,139 @@ cmake_minimum_required(VERSION 3.5) set(PIM_VERSION "5.12.43") project(mailcommon VERSION ${PIM_VERSION}) set(KF5_MIN_VERSION "5.61.0") find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${mailcommon_SOURCE_DIR}/cmake/modules/ ${ECM_MODULE_PATH}) if (POLICY CMP0053) cmake_policy(SET CMP0053 NEW) endif() set(LIBRARY_NAMELINK) include(KDEInstallDirs) include(KDECMakeSettings) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(GenerateExportHeader) include(ECMGenerateHeaders) include(ECMGeneratePriFile) include(ECMSetupVersion) include(FeatureSummary) include(ECMQtDeclareLoggingCategory) include(ECMAddTests) set(QT_REQUIRED_VERSION "5.11.0") set(MAILCOMMON_LIB_VERSION ${PIM_VERSION}) set(AKONADIMIME_LIB_VERSION "5.12.40") set(MESSAGELIB_LIB_VERSION "5.12.40") set(KMIME_LIB_VERSION "5.12.40") set(KMAILTRANSPORT_LIB_VERSION "5.12.40") set(MAILIMPORTER_LIB_VERSION "5.12.40") set(LIBKDEPIM_LIB_VERSION "5.12.40") set(PIMCOMMON_LIB_VERSION "5.12.40") set(AKONADI_VERSION "5.12.40") set(AKONADIMIME_LIB_VERSION "5.12.40") set(MESSAGELIB_LIB_VERSION "5.12.40") set(KMIME_LIB_VERSION "5.12.40") set(KMAILTRANSPORT_LIB_VERSION "5.12.40") set(MAILIMPORTER_LIB_VERSION "5.12.40") set(LIBKDEPIM_LIB_VERSION "5.12.40") set(PIMCOMMON_LIB_VERSION "5.12.40") set(PHONON_LIB_VERSION "4.10.60") set(AKONADI_VERSION "5.12.40") find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Widgets DBus Test Xml) find_package(KF5Archive ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Codecs ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Completion ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Config ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5ConfigWidgets ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5I18n ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5IconThemes ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5ItemModels ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5ItemViews ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5KIO ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5TextWidgets ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5WidgetsAddons ${KF5_MIN_VERSION} CONFIG REQUIRED) -find_package(KF5WindowSystem ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5XmlGui ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5DBusAddons ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5SyntaxHighlighting ${KF5_MIN_VERSION} CONFIG REQUIRED) find_package(KF5Akonadi ${AKONADI_VERSION} CONFIG REQUIRED) find_package(KF5AkonadiMime ${AKONADIMIME_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Libkdepim ${LIBKDEPIM_LIB_VERSION} CONFIG REQUIRED) find_package(KF5LibkdepimAkonadi ${LIBKDEPIM_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MailImporter ${MAILIMPORTER_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MailTransport ${KMAILTRANSPORT_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MessageComposer ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MessageCore ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5MessageViewer ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(KF5Mime ${KMIME_LIB_VERSION} CONFIG REQUIRED) find_package(KF5PimCommonAkonadi ${PIMCOMMON_LIB_VERSION} CONFIG REQUIRED) find_package(KF5TemplateParser ${MESSAGELIB_LIB_VERSION} CONFIG REQUIRED) find_package(Phonon4Qt5 ${PHONON_LIB_VERSION} CONFIG REQUIRED) set(USE_NEW_DESIGNERPLUGIN_MACRO false) if (ECM_VERSION VERSION_GREATER "5.61.0") option(BUILD_DESIGNERPLUGIN "Build plugin for Qt Designer" ON) add_feature_info(DESIGNERPLUGIN ${BUILD_DESIGNERPLUGIN} "Build plugin for Qt Designer") set(USE_NEW_DESIGNERPLUGIN_MACRO true) else() find_package(KF5DesignerPlugin ${KF5_MIN_VERSION} CONFIG) set_package_properties(KF5DesignerPlugin PROPERTIES DESCRIPTION "KF5 designer plugin" TYPE OPTIONAL) endif() ecm_setup_version(PROJECT VARIABLE_PREFIX MAILCOMMON VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/mailcommon_version.h" PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5MailCommonConfigVersion.cmake" SOVERSION 5 ) find_package(Xsltproc) set_package_properties(Xsltproc PROPERTIES DESCRIPTION "XSLT processor from libxslt" TYPE REQUIRED PURPOSE "Required to generate D-Bus interfaces for all Akonadi resources.") ########### Targets ########### remove_definitions( -DQT_NO_CAST_FROM_ASCII ) add_definitions(-DQT_NO_FOREACH) option(KDEPIM_RUN_AKONADI_TEST "Enable autotest based on Akonadi." TRUE) if (EXISTS "${CMAKE_SOURCE_DIR}/.git") add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) endif() ########### CMake Config Files ########### set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5MailCommon") configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/KF5MailCommonConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/KF5MailCommonConfig.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/KF5MailCommonConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/KF5MailCommonConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) install(EXPORT KF5MailCommonTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5MailCommonTargets.cmake NAMESPACE KF5::) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mailcommon_version.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel ) add_subdirectory(src) if(BUILD_TESTING) add_subdirectory(autotests) endif() install(FILES mailcommon.renamecategories mailcommon.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c528c09..19ce14f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,497 +1,496 @@ add_definitions(-DTRANSLATION_DOMAIN=\"libmailcommon\") #add_definitions( -DQT_NO_CAST_FROM_ASCII ) #add_definitions( -DQT_NO_CAST_TO_ASCII ) if(BUILD_TESTING) add_definitions(-DBUILD_TESTING) endif() set(libmailcommon_filter_SRCS filter/kmfilteraccountlist.cpp filter/kmfilterlistbox.cpp filter/filterselectiondialog.cpp filter/filterconverter/filterconverttosieve.cpp filter/filterconverter/filterconverttosieveresultdialog.cpp filter/filterconverter/filterconverttosievepurposemenuwidget.cpp filter/filteractions/filteraction.cpp filter/filteractions/filteractionaddheader.cpp filter/filteractions/filteractionaddtag.cpp filter/filteractions/filteractionaddtoaddressbook.cpp filter/filteractions/filteractioncopy.cpp filter/filteractions/filteractiondecrypt.cpp filter/filteractions/filteractiondelete.cpp filter/filteractions/filteractiondict.cpp filter/filteractions/filteractionencrypt.cpp filter/filteractions/filteractionexec.cpp filter/filteractions/filteractionforward.cpp filter/filteractions/filteractionmove.cpp filter/filteractions/filteractionpipethrough.cpp filter/filteractions/filteractionplaysound.cpp filter/filteractions/filteractionredirect.cpp filter/filteractions/filteractionremoveheader.cpp filter/filteractions/filteractionreplyto.cpp filter/filteractions/filteractionrewriteheader.cpp filter/filteractions/filteractionsendfakedisposition.cpp filter/filteractions/filteractionsendreceipt.cpp filter/filteractions/filteractionsetidentity.cpp filter/filteractions/filteractionsetstatus.cpp filter/filteractions/filteractionstatus.cpp filter/filteractions/filteractionunsetstatus.cpp filter/filteractions/filteractionsettransport.cpp filter/filteractions/filteractionwidget.cpp filter/filteractions/filteractionwithaddress.cpp filter/filteractions/filteractionwithcommand.cpp filter/filteractions/filteractionwithcrypto.cpp filter/filteractions/filteractionwithfolder.cpp filter/filteractions/filteractionwithnone.cpp filter/filteractions/filteractionwithstring.cpp filter/filteractions/filteractionwithstringlist.cpp filter/filteractions/filteractionwithtest.cpp filter/filteractions/filteractionwithuoid.cpp filter/filteractions/filteractionwithurl.cpp filter/filterimporterexporter.cpp filter/filterimporter/filterimporterabstract.cpp filter/filterimporter/filterimporterevolution.cpp filter/filterimporter/filterimportersylpheed.cpp filter/filterimporter/filterimporterthunderbird.cpp filter/filterimporter/filterimporterprocmail.cpp filter/filterimporter/filterimporterbalsa.cpp filter/filterimporter/filterimporterclawsmail.cpp filter/filterimporter/filterimportergmail.cpp filter/filterlog.cpp filter/filtermanager.cpp filter/itemcontext.cpp filter/kmfilterdialog.cpp filter/mailfilter.cpp filter/mdnadvicedialog.cpp filter/filterimporterpathcache.cpp ) set(libmailcommon_filter_dialog filter/dialog/selectthunderbirdfilterfilesdialog.cpp filter/dialog/selectthunderbirdfilterfileswidget.cpp filter/dialog/filteractionmissingfolderdialog.cpp filter/dialog/filteractionmissingsoundurldialog.cpp filter/dialog/filteractionmissingtagdialog.cpp filter/dialog/filteractionmissingaccountdialog.cpp filter/dialog/filteractionmissingtemplatedialog.cpp filter/dialog/filteractionmissingtransportdialog.cpp filter/dialog/filteractionmissingidentitydialog.cpp ) set(libmailcommon_invalidfilters filter/invalidfilters/invalidfilterdialog.cpp filter/invalidfilters/invalidfilterlistview.cpp filter/invalidfilters/invalidfilterwidget.cpp filter/invalidfilters/invalidfilterinfo.cpp filter/invalidfilters/invalidfilterlistitemdelegate.cpp filter/invalidfilters/invalidfilterlistmodel.cpp filter/invalidfilters/invalidfilterinfowidget.cpp ) set(libmailcommon_collection_SRCS collectionpage/attributeregistrar.cpp collectionpage/collectiongeneralpage.cpp collectionpage/collectionexpirypage.cpp collectionpage/attributes/expirecollectionattribute.cpp ) set(libmailcommon_folder_SRCS folder/foldersettings.cpp folder/foldercollectionmonitor.cpp folder/folderrequester.cpp folder/folderselectiondialog.cpp folder/foldertreeview.cpp folder/foldertreewidget.cpp folder/foldertreewidgetproxymodel.cpp folder/entitycollectionorderproxymodel.cpp folder/accountconfigorderdialog.cpp folder/favoritecollectionorderproxymodel.cpp ) set(libmailcommon_job_SRCS job/jobscheduler.cpp job/folderjob.cpp job/expirejob.cpp job/backupjob.cpp ) set(libmailcommon_search_SRCS search/widgethandler/rulewidgethandlermanager.cpp search/searchpattern.cpp search/searchpatternedit.cpp search/widgethandler/encryptionwidgethandler.cpp search/widgethandler/textrulerwidgethandler.cpp search/widgethandler/statusrulewidgethandler.cpp search/widgethandler/messagerulewidgethandler.cpp search/widgethandler/tagrulewidgethandler.cpp search/widgethandler/numericrulewidgethandler.cpp search/widgethandler/daterulewidgethandler.cpp search/widgethandler/numericdoublerulewidgethandler.cpp search/widgethandler/headersrulerwidgethandler.cpp search/searchrule/searchrulenumerical.cpp search/searchrule/searchruledate.cpp search/searchrule/searchrulestring.cpp search/searchrule/searchrulestatus.cpp search/searchrule/searchruleencryption.cpp search/searchrule/searchrule.cpp ) set(libmailcommon_snippets_SRCS snippets/snippetdialog.cpp snippets/snippetsmanager.cpp snippets/snippetsmodel.cpp snippets/snippetvariabledialog.cpp ) set(libmailcommon_tag_SRCS tag/tagwidget.cpp tag/tag.cpp tag/addtagdialog.cpp ) set(libmailcommon_widget_SRCS widgets/redirectdialog.cpp widgets/redirectwidget.cpp widgets/favoritecollectionwidget.cpp ) set(libmailcommon_mdn_SRCS mdn/sendmdnhandler.cpp mdn/mdnstateattribute.cpp ) set(libmailcommon_util_SRCS util/cryptoutils.cpp util/mailutil.cpp util/resourcereadconfigfile.cpp ) set(libmailcommon_SRCS kernel/mailkernel.cpp ${libmailcommon_filter_dialog} ${libmailcommon_util_SRCS} ${libmailcommon_mdn_SRCS} ${libmailcommon_invalidfilters} ${libmailcommon_widget_SRCS} ${libmailcommon_tag_SRCS} ${libmailcommon_snippets_SRCS} ${libmailcommon_search_SRCS} ${libmailcommon_job_SRCS} ${libmailcommon_collection_SRCS} ${libmailcommon_folder_SRCS} ${libmailcommon_filter_SRCS} ) kconfig_add_kcfg_files(libmailcommon_SRCS settings/mailcommonsettings_base.kcfgc ) ecm_qt_declare_logging_category(libmailcommon_SRCS HEADER mailcommon_debug.h IDENTIFIER MAILCOMMON_LOG CATEGORY_NAME org.kde.pim.mailcommon) set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/dbusinterfaces/org.freedesktop.Akonadi.MailFilterAgent.xml PROPERTIES INCLUDE "dbusoperators.h") qt5_add_dbus_interfaces(libmailcommon_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/dbusinterfaces/org.freedesktop.Akonadi.MailFilterAgent.xml ) ki18n_wrap_ui(libmailcommon_SRCS filter/ui/filterconfigwidget.ui snippets/ui/snippetdialog.ui filter/ui/selectthunderbirdfilterfileswidget.ui) set(libmailcommon_SRCS ${libmailcommon_SRCS} filter/soundtestwidget.cpp) macro(add_resource_iface _kcfgFile _ifaceName _className) kcfg_generate_dbus_interface(${CMAKE_CURRENT_SOURCE_DIR}/${_kcfgFile} ${_ifaceName}) string(TOLOWER ${_className} _codeFile) qt5_add_dbus_interface(libmailcommon_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${_ifaceName}.xml ${_codeFile} ${_className} ) endmacro() add_resource_iface(settings.kcfg org.kde.Akonadi.POP3.Settings Pop3Settings) qt5_add_dbus_interfaces(libmailcommon_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/dbusinterfaces/org.kde.Korganizer.Calendar.xml ) add_library(KF5MailCommon ${libmailcommon_SRCS}) generate_export_header(KF5MailCommon BASE_NAME mailcommon) add_library(KF5::MailCommon ALIAS KF5MailCommon) target_link_libraries(KF5MailCommon PUBLIC KF5::AkonadiCore KF5::AkonadiMime KF5::Libkdepim KF5::MessageComposer KF5::PimCommonAkonadi KF5::Completion PRIVATE KF5::TextWidgets KF5::I18n KF5::LibkdepimAkonadi KF5::MessageViewer KF5::MailImporter KF5::MessageCore KF5::TemplateParser KF5::Mime KF5::Codecs KF5::MailTransport Phonon::phonon4qt5 KF5::XmlGui KF5::KIOWidgets - KF5::WindowSystem KF5::IconThemes KF5::Archive KF5::ItemViews KF5::SyntaxHighlighting ) target_include_directories(KF5MailCommon INTERFACE "$") target_include_directories(KF5MailCommon PUBLIC "$") set_target_properties(KF5MailCommon PROPERTIES VERSION ${MAILCOMMON_VERSION_STRING} SOVERSION ${MAILCOMMON_SOVERSION} EXPORT_NAME MailCommon ) install(TARGETS KF5MailCommon EXPORT KF5MailCommonTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK} ) if (BUILD_TESTING) add_subdirectory(filter/filterimporter/autotests) add_subdirectory(collectionpage/autotests) add_subdirectory(filter/autotests) add_subdirectory(snippets/autotests) add_subdirectory(filter/tests) add_subdirectory(search/autotests) add_subdirectory(mdn/autotests/) endif() ecm_generate_headers(MailCommon_CamelCase_HEADERS HEADER_NAMES CryptoUtils MailUtil ResourceReadConfigFile REQUIRED_HEADERS MailCommon_HEADERS PREFIX MailCommon RELATIVE util ) ecm_generate_headers(MailCommon_Camelcasetop_HEADERS HEADER_NAMES DBusOperators REQUIRED_HEADERS MailCommon_top_HEADERS PREFIX MailCommon ) ecm_generate_headers(MailCommon_Camelcasetag_HEADERS HEADER_NAMES TagWidget Tag AddTagDialog REQUIRED_HEADERS MailCommon_tag_HEADERS PREFIX MailCommon RELATIVE tag ) ecm_generate_headers(MailCommon_Camelcasefolder_HEADERS HEADER_NAMES FolderSettings FolderRequester FolderCollectionMonitor AccountConfigOrderDialog FolderTreeView FolderTreeWidget FolderSelectionDialog FolderTreeWidgetProxyModel FavoriteCollectionOrderProxyModel REQUIRED_HEADERS MailCommon_folder_HEADERS PREFIX MailCommon RELATIVE folder ) ecm_generate_headers(MailCommon_Camelcasekernel_HEADERS HEADER_NAMES MailKernel REQUIRED_HEADERS MailCommon_kernel_HEADERS PREFIX MailCommon RELATIVE kernel ) ecm_generate_headers(MailCommon_Camelcaseinterfaces_HEADERS HEADER_NAMES MailInterfaces REQUIRED_HEADERS MailCommon_interfaces_HEADERS PREFIX MailCommon RELATIVE interfaces ) ecm_generate_headers(MailCommon_Camelcasefilter_HEADERS HEADER_NAMES FilterLog MailFilter FilterImporterExporter FilterManager KMFilterDialog FilterImporterPathCache ItemContext REQUIRED_HEADERS MailCommon_filter_HEADERS PREFIX MailCommon RELATIVE filter ) ecm_generate_headers(MailCommon_Camelcasejob_HEADERS HEADER_NAMES BackupJob JobScheduler FolderJob REQUIRED_HEADERS MailCommon_job_HEADERS PREFIX MailCommon RELATIVE job ) ecm_generate_headers(MailCommon_Camelcasefilteraction_HEADERS HEADER_NAMES FilterAction FilterActionDict REQUIRED_HEADERS MailCommon_filteraction_HEADERS PREFIX MailCommon RELATIVE filter/filteractions/ ) ecm_generate_headers(MailCommon_Camelcasemdn_HEADERS HEADER_NAMES SendMdnHandler MDNStateAttribute REQUIRED_HEADERS MailCommon_mdn_HEADERS PREFIX MailCommon RELATIVE mdn ) ecm_generate_headers(MailCommon_Camelcasecollectionpage_HEADERS HEADER_NAMES CollectionGeneralPage CollectionExpiryPage REQUIRED_HEADERS MailCommon_collectionpage_HEADERS PREFIX MailCommon RELATIVE collectionpage ) ecm_generate_headers(MailCommon_Camelcasecollectionpageattributes_HEADERS HEADER_NAMES ExpireCollectionAttribute REQUIRED_HEADERS MailCommon_collectionpageattributes_HEADERS PREFIX MailCommon RELATIVE collectionpage/attributes ) ecm_generate_headers(MailCommon_Camelcasefilterimporter_HEADERS HEADER_NAMES FilterImporterBalsa FilterImporterClawsMail FilterImporterAbstract REQUIRED_HEADERS MailCommon_filterimporter_HEADERS PREFIX MailCommon RELATIVE filter/filterimporter/ ) ecm_generate_headers(MailCommon_Camelcasesnippets_HEADERS HEADER_NAMES SnippetsManager REQUIRED_HEADERS MailCommon_snippets_HEADERS PREFIX MailCommon RELATIVE snippets ) ecm_generate_headers(MailCommon_Camelcasekernel_HEADERS HEADER_NAMES SearchPattern SearchPatternEdit REQUIRED_HEADERS MailCommon_kernel_HEADERS PREFIX MailCommon RELATIVE search ) ecm_generate_headers(MailCommon_Camelcasewidgets_HEADERS HEADER_NAMES RedirectDialog FavoriteCollectionWidget REQUIRED_HEADERS MailCommon_widgets_HEADERS PREFIX MailCommon RELATIVE widgets ) ecm_generate_headers(MailCommon_Camelcasesearchrule_HEADERS HEADER_NAMES SearchRule SearchRuleStatus REQUIRED_HEADERS MailCommon_searchrule_HEADERS PREFIX MailCommon RELATIVE search/searchrule ) ecm_generate_pri_file(BASE_NAME MailCommon LIB_NAME KF5MailCommon DEPS "AkonadiCore AkonadiMime MessageComposer PimCommon" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/MailCommon ) install(FILES ${MailCommon_Camelcasesearchrule_HEADERS} ${MailCommon_CamelCase_HEADERS} ${MailCommon_Camelcasetop_HEADERS} ${MailCommon_Camelcasetag_HEADERS} ${MailCommon_Camelcasefolder_HEADERS} ${MailCommon_Camelcasekernel_HEADERS} ${MailCommon_Camelcaseinterfaces_HEADERS} ${MailCommon_Camelcasefilter_HEADERS} ${MailCommon_Camelcasejob_HEADERS} ${MailCommon_Camelcasefilteraction_HEADERS} ${MailCommon_Camelcasemdn_HEADERS} ${MailCommon_Camelcasecollectionpage_HEADERS} ${MailCommon_Camelcasecollectionpageattributes_HEADERS} ${MailCommon_Camelcasefilterimporter_HEADERS} ${MailCommon_Camelcasesnippets_HEADERS} ${MailCommon_Camelcasewidgets_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/MailCommon COMPONENT Devel ) install(FILES ${MailCommon_searchrule_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/mailcommon_export.h ${CMAKE_CURRENT_BINARY_DIR}/pop3settings.h ${CMAKE_CURRENT_BINARY_DIR}/mailcommonsettings_base.h ${MailCommon_HEADERS} ${MailCommon_top_HEADERS} ${MailCommon_tag_HEADERS} ${MailCommon_folder_HEADERS} ${MailCommon_kernel_HEADERS} ${MailCommon_interfaces_HEADERS} ${MailCommon_filter_HEADERS} ${MailCommon_job_HEADERS} ${MailCommon_filteraction_HEADERS} ${MailCommon_mdn_HEADERS} ${MailCommon_collectionpage_HEADERS} ${MailCommon_collectionpageattributes_HEADERS} ${MailCommon_filterimporter_HEADERS} ${MailCommon_snippets_HEADERS} ${MailCommon_widgets_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/mailcommon COMPONENT Devel ) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) add_subdirectory(designer) diff --git a/src/filter/kmfilterdialog.cpp b/src/filter/kmfilterdialog.cpp index 505186b..4eef3da 100644 --- a/src/filter/kmfilterdialog.cpp +++ b/src/filter/kmfilterdialog.cpp @@ -1,814 +1,808 @@ /* Filter Dialog Author: Marc Mutz based upon work by Stefan Taferner Copyright (c) 2011-2019 Laurent Montel 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; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kmfilterdialog.h" #include "mailcommon_debug.h" #include "kmfilterlistbox.h" #include "filterimporterpathcache.h" #include "filteractions/filteractiondict.h" #include "filteractions/filteractionwidget.h" #include "filterimporterexporter.h" #include "filterselectiondialog.h" #include "kmfilteraccountlist.h" using MailCommon::FilterImporterExporter; #include "filtermanager.h" #include "folder/folderrequester.h" #include "kernel/mailkernel.h" #include "util/mailutil.h" #include "search/searchpatternedit.h" #include "filterconverter/filterconverttosieve.h" #include #include #include #include #include #include #include #include #include #include #include -#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include Q_DECLARE_METATYPE(MailCommon::FilterImporterExporter::FilterType) using namespace MailCommon; //============================================================================= // // class KMFilterDialog (the filter dialog) // //============================================================================= KMFilterDialog::KMFilterDialog(const QList &actionCollection, QWidget *parent, bool createDummyFilter) : QDialog(parent) , mFilter(nullptr) , mDoNotClose(false) , mIgnoreFilterUpdates(true) { setWindowTitle(i18n("Filter Rules")); QVBoxLayout *mainLayout = new QVBoxLayout(this); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Apply, this); QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); QPushButton *user1Button = new QPushButton(this); buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole); QPushButton *user2Button = new QPushButton(this); buttonBox->addButton(user2Button, QDialogButtonBox::ActionRole); QPushButton *user3Button = new QPushButton(this); buttonBox->addButton(user3Button, QDialogButtonBox::ActionRole); connect(buttonBox, &QDialogButtonBox::accepted, this, &KMFilterDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); connect(buttonBox->button(QDialogButtonBox::Help), &QAbstractButton::clicked, this, &KMFilterDialog::slotHelp); setModal(false); okButton->setFocus(); - KWindowSystem::setIcons(winId(), - qApp->windowIcon().pixmap(IconSize(KIconLoader::Desktop), - IconSize(KIconLoader::Desktop)), - qApp->windowIcon().pixmap(IconSize(KIconLoader::Small), - IconSize(KIconLoader::Small))); user1Button->setText(i18n("Import...")); user2Button->setText(i18n("Export...")); user3Button->setText(i18n("Convert to...")); QMenu *menu = new QMenu(); QAction *act = new QAction(i18n("KMail filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::KMailFilter)); menu->addAction(act); act = new QAction(i18n("Thunderbird filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::ThunderBirdFilter)); menu->addAction(act); act = new QAction(i18n("Evolution filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::EvolutionFilter)); menu->addAction(act); act = new QAction(i18n("Sylpheed filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::SylpheedFilter)); menu->addAction(act); act = new QAction(i18n("Procmail filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::ProcmailFilter)); menu->addAction(act); act = new QAction(i18n("Balsa filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::BalsaFilter)); menu->addAction(act); act = new QAction(i18n("Claws Mail filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::ClawsMailFilter)); menu->addAction(act); act = new QAction(i18n("Icedove Mail filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::IcedoveFilter)); menu->addAction(act); connect(menu, &QMenu::triggered, this, &KMFilterDialog::slotImportFilter); act = new QAction(i18n("Gmail filters"), this); act->setData(QVariant::fromValue(MailCommon::FilterImporterExporter::GmailFilter)); menu->addAction(act); user1Button->setMenu(menu); menu = new QMenu(); act = new QAction(i18n("Sieve script"), this); connect(act, &QAction::triggered, this, &KMFilterDialog::slotExportAsSieveScript); menu->addAction(act); user3Button->setMenu(menu); connect(user2Button, &QAbstractButton::clicked, this, &KMFilterDialog::slotExportFilters); mApplyButton = buttonBox->button(QDialogButtonBox::Apply); mApplyButton->setEnabled(false); QWidget *w = new QWidget(this); mainLayout->addWidget(w); mainLayout->addWidget(buttonBox); QVBoxLayout *topVLayout = new QVBoxLayout(w); topVLayout->setContentsMargins(0, 0, 0, 0); QHBoxLayout *topLayout = new QHBoxLayout; topVLayout->addLayout(topLayout); topLayout->setContentsMargins(0, 0, 0, 0); QSplitter *splitter = new QSplitter; splitter->setChildrenCollapsible(false); topLayout->addWidget(splitter); mFilterList = new KMFilterListBox(i18n("Available Filters"), this); splitter->addWidget(mFilterList); QTabWidget *tabWidget = new QTabWidget(this); splitter->addWidget(tabWidget); QWidget *page1 = new QWidget(tabWidget); tabWidget->addTab(page1, i18nc("General mail filter settings.", "General")); QHBoxLayout *hbl = new QHBoxLayout(page1); QWidget *page2 = new QWidget(tabWidget); tabWidget->addTab(page2, i18nc("Advanced mail filter settings.", "Advanced")); QVBoxLayout *vbl2 = new QVBoxLayout(page2); QVBoxLayout *vbl = new QVBoxLayout(); hbl->addLayout(vbl); hbl->setStretchFactor(vbl, 2); QGroupBox *patternGroupBox = new QGroupBox(i18n("Filter Criteria"), page1); QHBoxLayout *layout = new QHBoxLayout(patternGroupBox); mPatternEdit = new MailCommon::SearchPatternEdit( patternGroupBox, MailCommon::SearchPatternEdit::MatchAllMessages); layout->addWidget(mPatternEdit); vbl->addWidget(patternGroupBox, 0, Qt::AlignTop); QGroupBox *agb = new QGroupBox(i18n("Filter Actions"), page1); QHBoxLayout *layout2 = new QHBoxLayout; mActionLister = new MailCommon::FilterActionWidgetLister(agb); layout2->addWidget(mActionLister); agb->setLayout(layout2); vbl->addWidget(agb, 0, Qt::AlignTop); mAdvOptsGroup = new QGroupBox(i18n("Advanced Options"), page2); { QGridLayout *gl = new QGridLayout(); QVBoxLayout *vbl3 = new QVBoxLayout(); gl->addLayout(vbl3, 0, 0); vbl3->addStretch(1); mApplyOnIn = new QCheckBox(i18n("Apply this filter to incoming messages:"), mAdvOptsGroup); vbl3->addWidget(mApplyOnIn); QButtonGroup *bg = new QButtonGroup(mAdvOptsGroup); mApplyOnForAll = new QRadioButton(i18n("from all accounts"), mAdvOptsGroup); bg->addButton(mApplyOnForAll); vbl3->addWidget(mApplyOnForAll); mApplyOnForTraditional = new QRadioButton(i18n("from all but online IMAP accounts"), mAdvOptsGroup); bg->addButton(mApplyOnForTraditional); vbl3->addWidget(mApplyOnForTraditional); mApplyOnForChecked = new QRadioButton(i18n("from checked accounts only"), mAdvOptsGroup); bg->addButton(mApplyOnForChecked); vbl3->addWidget(mApplyOnForChecked); vbl3->addStretch(2); mAccountList = new KMFilterAccountList(mAdvOptsGroup); gl->addWidget(mAccountList, 0, 1, 4, 3); mApplyOnOut = new QCheckBox(i18n("Apply this filter to &sent messages"), mAdvOptsGroup); mApplyOnOut->setToolTip( i18n("

The filter will be triggered after the message is sent " "and it will only affect the local copy of the message.

" "

If the recipient's copy also needs to be modified, " "please use \"Apply this filter before sending messages\".

")); gl->addWidget(mApplyOnOut, 4, 0, 1, 4); mApplyBeforeOut = new QCheckBox(i18n("Apply this filter &before sending messages"), mAdvOptsGroup); mApplyBeforeOut->setToolTip( i18n("

The filter will be triggered before the message is sent " "and it will affect both the local copy and the sent copy of the message.

" "

This is required if the recipient's copy also needs to be modified.

")); gl->addWidget(mApplyBeforeOut, 5, 0, 1, 4); mApplyOnCtrlJ = new QCheckBox(i18n("Apply this filter on manual &filtering"), mAdvOptsGroup); gl->addWidget(mApplyOnCtrlJ, 6, 0, 1, 4); mApplyOnAllFolders = new QCheckBox(i18n("Apply this filter on inbound emails in all folders"), mAdvOptsGroup); mApplyOnAllFolders->setToolTip(i18n("

The filter will be applied on inbound emails from all folders " "belonging to all accounts selected above. This is useful when using local filters " "with IMAP accounts where new emails may have already been moved to different folders " "by server-side filters.

")); gl->addWidget(mApplyOnAllFolders, 7, 0, 1, 4); mStopProcessingHere = new QCheckBox(i18n("If this filter &matches, stop processing here"), mAdvOptsGroup); gl->addWidget(mStopProcessingHere, 8, 0, 1, 4); mConfigureShortcut = new QCheckBox(i18n("Add this filter to the Apply Filter menu"), mAdvOptsGroup); gl->addWidget(mConfigureShortcut, 9, 0, 1, 2); QLabel *keyButtonLabel = new QLabel(i18n("Shortcut:"), mAdvOptsGroup); keyButtonLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight); gl->addWidget(keyButtonLabel, 9, 2, 1, 1); mKeySeqWidget = new KKeySequenceWidget(mAdvOptsGroup); mKeySeqWidget->setObjectName(QStringLiteral("FilterShortcutSelector")); gl->addWidget(mKeySeqWidget, 9, 3, 1, 1); mKeySeqWidget->setEnabled(false); mKeySeqWidget->setModifierlessAllowed(true); mKeySeqWidget->setCheckActionCollections(actionCollection); mConfigureToolbar = new QCheckBox(i18n("Additionally add this filter to the toolbar"), mAdvOptsGroup); gl->addWidget(mConfigureToolbar, 10, 0, 1, 4); mConfigureToolbar->setEnabled(false); QWidget *hbox = new QWidget(mAdvOptsGroup); QHBoxLayout *hboxHBoxLayout = new QHBoxLayout(hbox); hboxHBoxLayout->setContentsMargins(0, 0, 0, 0); mFilterActionLabel = new QLabel(i18n("Icon for this filter:"), hbox); hboxHBoxLayout->addWidget(mFilterActionLabel); mFilterActionLabel->setEnabled(false); mFilterActionIconButton = new KIconButton(hbox); hboxHBoxLayout->addWidget(mFilterActionIconButton); mFilterActionLabel->setBuddy(mFilterActionIconButton); mFilterActionIconButton->setIconType(KIconLoader::NoGroup, KIconLoader::Action, false); mFilterActionIconButton->setIconSize(16); mFilterActionIconButton->setIcon(QIcon::fromTheme(QStringLiteral("system-run"))); mFilterActionIconButton->setEnabled(false); gl->addWidget(hbox, 11, 0, 1, 4); mAdvOptsGroup->setLayout(gl); } vbl2->addWidget(mAdvOptsGroup, 0, Qt::AlignTop); QHBoxLayout *applySpecificFiltersLayout = new QHBoxLayout; QLabel *lab = new QLabel(i18n("Run selected filter(s) on: "), this); applySpecificFiltersLayout->addWidget(lab); mFolderRequester = new MailCommon::FolderRequester(this); mFolderRequester->setNotAllowToCreateNewFolder(true); applySpecificFiltersLayout->addWidget(mFolderRequester); connect(mFolderRequester, &FolderRequester::folderChanged, this, &KMFilterDialog::slotFolderChanged); mRunNow = new QPushButton(i18n("Run Now"), this); mRunNow->setEnabled(false); applySpecificFiltersLayout->addWidget(mRunNow); connect(mRunNow, &QPushButton::clicked, this, &KMFilterDialog::slotRunFilters); topVLayout->addLayout(applySpecificFiltersLayout); // spacer: vbl->addStretch(1); // load the filter parts into the edit widgets connect(mFilterList, &KMFilterListBox::filterSelected, this, &KMFilterDialog::slotFilterSelected); // transfer changes from the 'Apply this filter on...' // combo box to the filter connect(mApplyOnIn, &QCheckBox::clicked, this, &KMFilterDialog::slotApplicabilityChanged); connect(mApplyOnForAll, &QRadioButton::clicked, this, &KMFilterDialog::slotApplicabilityChanged); connect(mApplyOnForTraditional, &QAbstractButton::clicked, this, &KMFilterDialog::slotApplicabilityChanged); connect(mApplyOnForChecked, &QAbstractButton::clicked, this, &KMFilterDialog::slotApplicabilityChanged); connect(mApplyBeforeOut, &QAbstractButton::clicked, this, &KMFilterDialog::slotApplicabilityChanged); connect(mApplyOnAllFolders, &QAbstractButton::clicked, this, &KMFilterDialog::slotApplicabilityChanged); connect(mApplyOnOut, &QAbstractButton::clicked, this, &KMFilterDialog::slotApplicabilityChanged); connect(mApplyOnCtrlJ, &QAbstractButton::clicked, this, &KMFilterDialog::slotApplicabilityChanged); connect(mAccountList, &KMFilterAccountList::itemChanged, this, &KMFilterDialog::slotApplicableAccountsChanged); // transfer changes from the 'stop processing here' // check box to the filter connect(mStopProcessingHere, &QCheckBox::toggled, this, &KMFilterDialog::slotStopProcessingButtonToggled); connect(mConfigureShortcut, &QCheckBox::toggled, this, &KMFilterDialog::slotConfigureShortcutButtonToggled); connect(mKeySeqWidget, &KKeySequenceWidget::keySequenceChanged, this, &KMFilterDialog::slotShortcutChanged); connect(mConfigureToolbar, &QCheckBox::toggled, this, &KMFilterDialog::slotConfigureToolbarButtonToggled); connect(mFilterActionIconButton, &KIconButton::iconChanged, this, &KMFilterDialog::slotFilterActionIconChanged); // reset all widgets here connect(mFilterList, &KMFilterListBox::resetWidgets, this, &KMFilterDialog::slotReset); connect(mFilterList, &KMFilterListBox::applyWidgets, this, &KMFilterDialog::slotUpdateFilter); // support auto-naming the filter connect(mPatternEdit, &MailCommon::SearchPatternEdit::maybeNameChanged, mFilterList, &KMFilterListBox::slotUpdateFilterName); // save filters on 'Apply' or 'OK' connect(mApplyButton, &QAbstractButton::clicked, this, &KMFilterDialog::slotApply); // save dialog size on 'OK' connect(okButton, &QAbstractButton::clicked, this, &KMFilterDialog::slotSaveSize); // destruct the dialog on close and Cancel connect(buttonBox->button(QDialogButtonBox::Cancel), &QAbstractButton::clicked, this, &KMFilterDialog::slotFinished); // disable closing when user wants to continue editing connect(mFilterList, &KMFilterListBox::abortClosing, this, &KMFilterDialog::slotDisableAccept); connect(mFilterList, &KMFilterListBox::filterCreated, this, &KMFilterDialog::slotDialogUpdated); connect(mFilterList, &KMFilterListBox::filterRemoved, this, &KMFilterDialog::slotDialogUpdated); connect(mFilterList, &KMFilterListBox::filterUpdated, this, &KMFilterDialog::slotDialogUpdated); connect(mFilterList, &KMFilterListBox::filterOrderAltered, this, &KMFilterDialog::slotDialogUpdated); connect(mPatternEdit, &MailCommon::SearchPatternEdit::patternChanged, this, &KMFilterDialog::slotDialogUpdated); connect(mActionLister, QOverload::of(&FilterActionWidgetLister::widgetAdded), this, &KMFilterDialog::slotDialogUpdated); connect(mActionLister, QOverload::of(&FilterActionWidgetLister::widgetRemoved), this, &KMFilterDialog::slotDialogUpdated); connect(mActionLister, &MailCommon::FilterActionWidgetLister::filterModified, this, &KMFilterDialog::slotDialogUpdated); connect(mActionLister, &MailCommon::FilterActionWidgetLister::clearWidgets, this, &KMFilterDialog::slotDialogUpdated); KConfigGroup myGroup(KernelIf->config(), "Geometry"); const QSize size = myGroup.readEntry("filterDialogSize", QSize()); if (size != QSize()) { resize(size); } else { adjustSize(); } // load the filter list (emits filterSelected()) mFilterList->loadFilterList(createDummyFilter); mIgnoreFilterUpdates = false; } void KMFilterDialog::createFilter(const QByteArray &field, const QString &value) { mFilterList->createFilter(field, value); } void KMFilterDialog::accept() { if (mDoNotClose) { mDoNotClose = false; // only abort current close attempt } else { QDialog::accept(); slotFinished(); } } bool KMFilterDialog::event(QEvent *e) { // Close the bar when pressing Escape. // Not using a QShortcut for this because it could conflict with // window-global actions (e.g. Emil Sedgh binds Esc to "close tab"). // With a shortcut override we can catch this before it gets to kactions. const bool shortCutOverride = (e->type() == QEvent::ShortcutOverride); if (shortCutOverride || e->type() == QEvent::KeyPress) { QKeyEvent *kev = static_cast(e); if (kev->key() == Qt::Key_Escape) { e->ignore(); return true; } } return QDialog::event(e); } void KMFilterDialog::slotApply() { mApplyButton->setEnabled(false); mFilterList->slotApplied(); } void KMFilterDialog::slotFinished() { deleteLater(); } void KMFilterDialog::slotFolderChanged(const Akonadi::Collection &collection) { mRunNow->setEnabled(collection.isValid()); } void KMFilterDialog::slotRunFilters() { if (!mFolderRequester->collection().isValid()) { KMessageBox::information( this, i18nc("@info", "Unable to apply this filter since there are no folders selected."), i18n("No folder selected.")); return; } if (mApplyButton->isEnabled()) { KMessageBox::information( this, i18nc("@info", "Some filters were changed and not saved yet. " "You must save your filters before they can be applied."), i18n("Filters changed.")); return; } SearchRule::RequiredPart requiredPart = SearchRule::Envelope; const QStringList selectedFiltersId = mFilterList->selectedFilterId(requiredPart, mFolderRequester->collection().resource()); if (selectedFiltersId.isEmpty()) { KMessageBox::information( this, i18nc("@info", "Unable to apply a filter since there are no filters currently selected."), i18n("No filters selected.")); return; } Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob(mFolderRequester->collection(), this); job->setProperty("requiredPart", QVariant::fromValue(requiredPart)); job->setProperty("listFilters", QVariant::fromValue(selectedFiltersId)); connect(job, &KJob::result, this, &KMFilterDialog::slotFetchItemsForFolderDone); mRunNow->setEnabled(false); //Disable it } void KMFilterDialog::slotFetchItemsForFolderDone(KJob *job) { Akonadi::ItemFetchJob *fjob = qobject_cast(job); Q_ASSERT(fjob); QStringList filtersId; if (fjob->property("listFilters").isValid()) { filtersId = fjob->property("listFilters").toStringList(); } SearchRule::RequiredPart requiredPart = SearchRule::Envelope; if (fjob->property("requiredPart").isValid()) { requiredPart = fjob->property("requiredPart").value(); } Akonadi::Item::List items = fjob->items(); mRunNow->setEnabled(true); MailCommon::FilterManager::instance()->filter(items, requiredPart, filtersId); } void KMFilterDialog::slotSaveSize() { mFilterList->slotAccepted(); KConfigGroup myGroup(KernelIf->config(), "Geometry"); myGroup.writeEntry("filterDialogSize", size()); myGroup.sync(); } void KMFilterDialog::slotFilterSelected(MailFilter *aFilter) { Q_ASSERT(aFilter); mIgnoreFilterUpdates = true; mActionLister->setActionList(aFilter->actions()); mAdvOptsGroup->setEnabled(true); mPatternEdit->setSearchPattern(aFilter->pattern()); mFilter = aFilter; qCDebug(MAILCOMMON_LOG) << "apply on inbound ==" << aFilter->applyOnInbound(); qCDebug(MAILCOMMON_LOG) << "apply on outbound ==" << aFilter->applyOnOutbound(); qCDebug(MAILCOMMON_LOG) << "apply before outbound == " << aFilter->applyBeforeOutbound(); qCDebug(MAILCOMMON_LOG) << "apply on explicit ==" << aFilter->applyOnExplicit(); qCDebug(MAILCOMMON_LOG) << "apply on all folders inboud == " << aFilter->applyOnAllFoldersInbound(); // NOTE: setting these values activates the slot that sets them in // the filter! So make sure we have the correct values _before_ we // set the first one: const bool applyOnIn = aFilter->applyOnInbound(); const bool applyOnForAll = aFilter->applicability() == MailFilter::All; const bool applyOnTraditional = aFilter->applicability() == MailFilter::ButImap; const bool applyBeforeOut = aFilter->applyBeforeOutbound(); const bool applyOnOut = aFilter->applyOnOutbound(); const bool applyOnAllFolders = aFilter->applyOnAllFoldersInbound(); const bool applyOnExplicit = aFilter->applyOnExplicit(); const bool stopHere = aFilter->stopProcessingHere(); const bool configureShortcut = aFilter->configureShortcut(); const bool configureToolbar = aFilter->configureToolbar(); const QString icon = aFilter->icon(); const QKeySequence shortcut(aFilter->shortcut()); mApplyOnIn->setChecked(applyOnIn); mApplyOnForAll->setEnabled(applyOnIn); mApplyOnForTraditional->setEnabled(applyOnIn); mApplyOnForChecked->setEnabled(applyOnIn); mApplyOnForAll->setChecked(applyOnForAll); mApplyOnAllFolders->setChecked(applyOnAllFolders); mApplyOnForTraditional->setChecked(applyOnTraditional); mApplyOnForChecked->setChecked(!applyOnForAll && !applyOnTraditional); mAccountList->setEnabled(mApplyOnForChecked->isEnabled() && mApplyOnForChecked->isChecked()); slotUpdateAccountList(); mApplyBeforeOut->setChecked(applyBeforeOut); mApplyOnOut->setChecked(applyOnOut); mApplyOnCtrlJ->setChecked(applyOnExplicit); mStopProcessingHere->setChecked(stopHere); mConfigureShortcut->setChecked(configureShortcut); mKeySeqWidget->setKeySequence(shortcut, KKeySequenceWidget::NoValidate); mConfigureToolbar->setChecked(configureToolbar); mFilterActionIconButton->setIcon(icon); mIgnoreFilterUpdates = false; } void KMFilterDialog::slotReset() { mFilter = nullptr; mPatternEdit->reset(); mActionLister->reset(); mAdvOptsGroup->setEnabled(false); slotUpdateAccountList(); } void KMFilterDialog::slotUpdateFilter() { mPatternEdit->updateSearchPattern(); mActionLister->updateActionList(); } void KMFilterDialog::slotApplicabilityChanged() { if (mFilter) { mFilter->setApplyOnInbound(mApplyOnIn->isChecked()); mFilter->setApplyBeforeOutbound(mApplyBeforeOut->isChecked()); mFilter->setApplyOnOutbound(mApplyOnOut->isChecked()); mFilter->setApplyOnExplicit(mApplyOnCtrlJ->isChecked()); mFilter->setApplyOnAllFoldersInbound(mApplyOnAllFolders->isChecked()); if (mApplyOnForAll->isChecked()) { mFilter->setApplicability(MailFilter::All); mFilter->clearApplyOnAccount(); } else if (mApplyOnForTraditional->isChecked()) { mFilter->setApplicability(MailFilter::ButImap); } else if (mApplyOnForChecked->isChecked()) { mFilter->setApplicability(MailFilter::Checked); } mApplyOnForAll->setEnabled(mApplyOnIn->isChecked()); mApplyOnForTraditional->setEnabled(mApplyOnIn->isChecked()); mApplyOnForChecked->setEnabled(mApplyOnIn->isChecked()); mAccountList->setEnabled(mApplyOnForChecked->isEnabled() && mApplyOnForChecked->isChecked()); // Advanced tab functionality - Update list of accounts this filter applies to if (!mApplyOnForAll->isChecked()) { mAccountList->applyOnAccount(mFilter); } // Enable the apply button slotDialogUpdated(); qCDebug(MAILCOMMON_LOG) << "Setting filter to be applied at" << (mFilter->applyOnInbound() ? "incoming " : "") << (mFilter->applyOnOutbound() ? "outgoing " : "") << (mFilter->applyBeforeOutbound() ? "before_outgoing " : "") << (mFilter->applyOnAllFoldersInbound() ? "all folders inboud " : "") << (mFilter->applyOnExplicit() ? "explicit CTRL-J" : ""); } } void KMFilterDialog::slotApplicableAccountsChanged() { // Advanced tab functionality - Update list of accounts this filter applies to if (mFilter && mApplyOnForChecked->isEnabled() && mApplyOnForChecked->isChecked()) { QTreeWidgetItemIterator it(mAccountList); while (QTreeWidgetItem *item = *it) { const QString id = item->text(2); mFilter->setApplyOnAccount(id, item->checkState(0) == Qt::Checked); ++it; } // Enable the apply button slotDialogUpdated(); } } void KMFilterDialog::slotStopProcessingButtonToggled(bool aChecked) { if (mFilter) { mFilter->setStopProcessingHere(aChecked); // Enable the apply button slotDialogUpdated(); } } void KMFilterDialog::slotConfigureShortcutButtonToggled(bool aChecked) { if (mFilter) { mFilter->setConfigureShortcut(aChecked); mKeySeqWidget->setEnabled(aChecked); mConfigureToolbar->setEnabled(aChecked); mFilterActionIconButton->setEnabled(aChecked); mFilterActionLabel->setEnabled(aChecked); // Enable the apply button slotDialogUpdated(); } } void KMFilterDialog::slotShortcutChanged(const QKeySequence &newSeq) { if (mFilter) { mKeySeqWidget->applyStealShortcut(); mFilter->setShortcut(newSeq); // Enable the apply button slotDialogUpdated(); } } void KMFilterDialog::slotConfigureToolbarButtonToggled(bool aChecked) { if (mFilter) { mFilter->setConfigureToolbar(aChecked); // Enable the apply button slotDialogUpdated(); } } void KMFilterDialog::slotFilterActionIconChanged(const QString &icon) { if (mFilter) { mFilter->setIcon(icon); // Enable the apply button slotDialogUpdated(); } } void KMFilterDialog::slotUpdateAccountList() { mAccountList->updateAccountList(mFilter); } void KMFilterDialog::slotImportFilter(QAction *act) { if (act) { importFilters(act->data().value()); } } void KMFilterDialog::importFilters(MailCommon::FilterImporterExporter::FilterType type) { MailCommon::FilterImporterPathCache::self()->clear(); FilterImporterExporter importer(this); bool canceled = false; QVector filters = importer.importFilters(canceled, type); if (canceled) { return; } if (filters.isEmpty()) { KMessageBox::information(this, i18n("No filter was imported.")); return; } QStringList listOfFilter; QVector::ConstIterator end(filters.constEnd()); for (QVector::ConstIterator it = filters.constBegin(); it != end; ++it) { mFilterList->appendFilter(*it); // no need to deep copy, ownership passes to the list listOfFilter << (*it)->name(); } KMessageBox::informationList( this, i18n("Filters which were imported:"), listOfFilter); } void KMFilterDialog::slotExportFilters() { bool wasCanceled = false; const QVector filters = mFilterList->filtersForSaving(false, wasCanceled); if (filters.isEmpty()) { KMessageBox::information( this, i18n("Any filter found.")); return; } if (wasCanceled) { qDeleteAll(filters); return; } FilterImporterExporter exporter(this); exporter.exportFilters(filters); } void KMFilterDialog::slotDisableAccept() { mDoNotClose = true; } void KMFilterDialog::slotDialogUpdated() { qCDebug(MAILCOMMON_LOG) << "Detected a change in data bound to the dialog!"; if (!mIgnoreFilterUpdates) { mApplyButton->setEnabled(true); } } void KMFilterDialog::slotExportAsSieveScript() { if (mApplyButton->isEnabled()) { KMessageBox::information( this, i18nc("@info", "Some filters were changed and not saved yet.
" "You must save your filters before they can be exported."), i18n("Filters changed.")); return; } KMessageBox::information(this, i18n("We cannot convert all KMail filters to sieve scripts but we can try :)"), i18n("Convert KMail filters to sieve scripts")); bool wasCanceled = false; const QVector filters = mFilterList->filtersForSaving(false, wasCanceled); if (filters.isEmpty()) { return; } if (!wasCanceled) { QPointer dlg = new FilterSelectionDialog(this); dlg->setFilters(filters); if (dlg->exec() == QDialog::Accepted) { QVector lst = dlg->selectedFilters(); if (!lst.isEmpty()) { FilterConvertToSieve convert(lst); convert.convert(); qDeleteAll(lst); } else { KMessageBox::information(this, i18n("No filters selected."), i18n("Convert KMail filters to sieve scripts")); } } delete dlg; } else { qDeleteAll(filters); } } void KMFilterDialog::slotHelp() { PimCommon::Util::invokeHelp(QStringLiteral("kmail2/filters.html")); } diff --git a/src/search/widgethandler/statusrulewidgethandler.cpp b/src/search/widgethandler/statusrulewidgethandler.cpp index 0c21f51..7679848 100644 --- a/src/search/widgethandler/statusrulewidgethandler.cpp +++ b/src/search/widgethandler/statusrulewidgethandler.cpp @@ -1,256 +1,256 @@ /* 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; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "statusrulewidgethandler.h" #include "search/searchrule/searchrulestatus.h" -#include #include +#include #include using namespace MailCommon; static const struct { SearchRule::Function id; const char *displayName; } StatusFunctions[] = { { SearchRule::FuncContains, I18N_NOOP("is") }, { SearchRule::FuncContainsNot, I18N_NOOP("is not") } }; static const int StatusFunctionCount = sizeof(StatusFunctions) / sizeof(*StatusFunctions); //--------------------------------------------------------------------------- QWidget *StatusRuleWidgetHandler::createFunctionWidget( int number, QStackedWidget *functionStack, const QObject *receiver, bool /*isBalooSearch*/) const { if (number != 0) { return nullptr; } auto *funcCombo = new QComboBox(functionStack); funcCombo->setMinimumWidth(50); funcCombo->setObjectName(QStringLiteral("statusRuleFuncCombo")); for (int i = 0; i < StatusFunctionCount; ++i) { funcCombo->addItem(i18n(StatusFunctions[i].displayName)); } funcCombo->adjustSize(); QObject::connect(funcCombo, SIGNAL(activated(int)), receiver, SLOT(slotFunctionChanged())); return funcCombo; } //--------------------------------------------------------------------------- QWidget *StatusRuleWidgetHandler::createValueWidget(int number, QStackedWidget *valueStack, const QObject *receiver) const { if (number != 0) { return nullptr; } auto *statusCombo = new QComboBox(valueStack); statusCombo->setMinimumWidth(50); statusCombo->setObjectName(QStringLiteral("statusRuleValueCombo")); for (int i = 0; i < MailCommon::StatusValueCountWithoutHidden; ++i) { if (MailCommon::StatusValues[ i ].icon != nullptr) { statusCombo->addItem( - SmallIcon(QLatin1String(MailCommon::StatusValues[ i ].icon)), + QIcon::fromTheme(QLatin1String(MailCommon::StatusValues[ i ].icon)), i18nc("message status", MailCommon::StatusValues[ i ].text)); } else { statusCombo->addItem( i18nc("message status", MailCommon::StatusValues[ i ].text)); } } statusCombo->adjustSize(); QObject::connect(statusCombo, SIGNAL(activated(int)), receiver, SLOT(slotValueChanged())); return statusCombo; } //--------------------------------------------------------------------------- SearchRule::Function StatusRuleWidgetHandler::currentFunction( const QStackedWidget *functionStack) const { const auto funcCombo = functionStack->findChild(QStringLiteral("statusRuleFuncCombo")); if (funcCombo && funcCombo->currentIndex() >= 0) { return StatusFunctions[funcCombo->currentIndex()].id; } return SearchRule::FuncNone; } //--------------------------------------------------------------------------- SearchRule::Function StatusRuleWidgetHandler::function(const QByteArray &field, const QStackedWidget *functionStack) const { if (!handlesField(field)) { return SearchRule::FuncNone; } return currentFunction(functionStack); } //--------------------------------------------------------------------------- int StatusRuleWidgetHandler::currentStatusValue(const QStackedWidget *valueStack) const { const auto statusCombo = valueStack->findChild(QStringLiteral("statusRuleValueCombo")); if (statusCombo) { return statusCombo->currentIndex(); } return -1; } //--------------------------------------------------------------------------- QString StatusRuleWidgetHandler::value(const QByteArray &field, const QStackedWidget *, const QStackedWidget *valueStack) const { if (!handlesField(field)) { return QString(); } const int status = currentStatusValue(valueStack); if (status != -1) { return QString::fromLatin1(MailCommon::StatusValues[ status ].text); } else { return QString(); } } //--------------------------------------------------------------------------- QString StatusRuleWidgetHandler::prettyValue(const QByteArray &field, const QStackedWidget *, const QStackedWidget *valueStack) const { if (!handlesField(field)) { return QString(); } const int status = currentStatusValue(valueStack); if (status != -1) { return i18nc("message status", MailCommon::StatusValues[ status ].text); } else { return QString(); } } //--------------------------------------------------------------------------- bool StatusRuleWidgetHandler::handlesField(const QByteArray &field) const { return field == ""; } //--------------------------------------------------------------------------- void StatusRuleWidgetHandler::reset(QStackedWidget *functionStack, QStackedWidget *valueStack) const { // reset the function combo box auto funcCombo = functionStack->findChild(QStringLiteral("statusRuleFuncCombo")); if (funcCombo) { funcCombo->blockSignals(true); funcCombo->setCurrentIndex(0); funcCombo->blockSignals(false); } // reset the status value combo box auto statusCombo = valueStack->findChild(QStringLiteral("statusRuleValueCombo")); if (statusCombo) { statusCombo->blockSignals(true); statusCombo->setCurrentIndex(0); statusCombo->blockSignals(false); } } //--------------------------------------------------------------------------- bool StatusRuleWidgetHandler::setRule(QStackedWidget *functionStack, QStackedWidget *valueStack, const SearchRule::Ptr rule, bool /*isBalooSearch*/) const { if (!rule || !handlesField(rule->field())) { reset(functionStack, valueStack); return false; } // set the function const SearchRule::Function func = rule->function(); int funcIndex = 0; for (; funcIndex < StatusFunctionCount; ++funcIndex) { if (func == StatusFunctions[funcIndex].id) { break; } } const auto funcCombo = functionStack->findChild(QStringLiteral("statusRuleFuncCombo")); if (funcCombo) { funcCombo->blockSignals(true); if (funcIndex < StatusFunctionCount) { funcCombo->setCurrentIndex(funcIndex); } else { funcCombo->setCurrentIndex(0); } funcCombo->blockSignals(false); functionStack->setCurrentWidget(funcCombo); } // set the value const QString value = rule->contents(); int valueIndex = 0; for (; valueIndex < MailCommon::StatusValueCountWithoutHidden; ++valueIndex) { if (value == QString::fromLatin1(MailCommon::StatusValues[ valueIndex ].text)) { break; } } const auto statusCombo = valueStack->findChild(QStringLiteral("statusRuleValueCombo")); if (statusCombo) { statusCombo->blockSignals(true); if (valueIndex < MailCommon::StatusValueCountWithoutHidden) { statusCombo->setCurrentIndex(valueIndex); } else { statusCombo->setCurrentIndex(0); } statusCombo->blockSignals(false); valueStack->setCurrentWidget(statusCombo); } return true; } //--------------------------------------------------------------------------- bool StatusRuleWidgetHandler::update(const QByteArray &field, QStackedWidget *functionStack, QStackedWidget *valueStack) const { if (!handlesField(field)) { return false; } // raise the correct function widget functionStack->setCurrentWidget(functionStack->findChild(QStringLiteral("statusRuleFuncCombo"))); // raise the correct value widget valueStack->setCurrentWidget(valueStack->findChild(QStringLiteral("statusRuleValueCombo"))); return true; }