diff --git a/messageviewer/src/CMakeLists.txt b/messageviewer/src/CMakeLists.txt index 7032bae2..64a88a18 100644 --- a/messageviewer/src/CMakeLists.txt +++ b/messageviewer/src/CMakeLists.txt @@ -1,429 +1,428 @@ add_definitions( -DQT_NO_CAST_FROM_ASCII ) add_definitions( -DQT_NO_CAST_TO_ASCII ) add_definitions(-DTRANSLATION_DOMAIN=\"libmessageviewer\") # KCFG files: # The main messageviewer.kcfg is configured by CMake and put in the build directory. if(KDEPIM_ENTERPRISE_BUILD) set(LEGACY_MANGLE_FROM_TO_HEADERS true) set(LEGACY_BODY_INVITES true) set(EXCHANGE_COMPATIBLE_INVITATIONS true) else() set(LEGACY_MANGLE_FROM_TO_HEADERS false) set(LEGACY_BODY_INVITES false) set(EXCHANGE_COMPATIBLE_INVITATIONS false) endif() configure_file(settings/messageviewer.kcfg.cmake ${CMAKE_CURRENT_BINARY_DIR}/messageviewer.kcfg) include(CheckIncludeFiles) find_package(Inotify) set_package_properties(Inotify PROPERTIES PURPOSE "Filesystem alteration notifications using inotify") if(Inotify_FOUND) set(HAVE_SYS_INOTIFY_H 1) else() set(HAVE_SYS_INOTIFY_H 0) endif() configure_file(config-messageviewer.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-messageviewer.h) # target_include_directories does not handle empty include paths include_directories(${GPGME_INCLUDES}) if(BUILD_TESTING) add_subdirectory(scamdetection/autotests) add_subdirectory(scamdetection/tests) add_subdirectory(viewerplugins/tests/) add_subdirectory(htmlwriter/autotests) add_subdirectory(viewer/webengine/tests) add_subdirectory(messagepartthemes/default/autotests) add_subdirectory(viewer/webengine/autotests) endif() add_subdirectory(pics) add_subdirectory(kconf_update) add_subdirectory(about) add_subdirectory(messageviewerheaderplugins) if(DEBUG_SIGNATURE) add_definitions(-DDEBUG_SIGNATURE) endif() set(libmessageviewer_mailviewer_SRCS viewer/webengine/mailwebengineview.cpp viewer/webengine/mailwebenginepage.cpp viewer/webengine/loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.cpp viewer/webengine/cidreferencesurlinterceptor/cidreferencesurlinterceptor.cpp viewer/webengine/blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.cpp viewer/webengine/mailwebenginescript.cpp ) set(libmessageviewer_viewer_SRCS viewer/bodypartformatterfactory.cpp viewer/bodypartformatterfactorysingleton.cpp viewer/csshelper.cpp viewer/csshelperbase.cpp viewer/editorwatcher.cpp viewer/objecttreeemptysource.cpp viewer/objecttreeviewersource.cpp - viewer/pluginloaderbase.cpp viewer/viewer.cpp viewer/viewer_p.cpp viewer/messagedisplayformatattribute.cpp viewer/urlhandlermanager.cpp viewer/mimeparttree/mimeparttreeview.cpp viewer/mimeparttree/mimetreemodel.cpp ) set(libmessageviewer_widgets_SRCS widgets/attachmentdialog.cpp widgets/configurewidget.cpp widgets/printingsettings.cpp widgets/htmlstatusbar.cpp widgets/vcardviewer.cpp widgets/invitationsettings.cpp widgets/openattachmentfolderwidget.cpp widgets/mailsourceviewtextbrowserwidget.cpp widgets/submittedformwarningwidget.cpp ) set(libmessageviewer_widgets_webengine_SRCS widgets/mailsourcewebengineviewer.cpp ) set(libmessageviewer_header_SRCS header/contactdisplaymessagememento.cpp header/headerstrategy.cpp header/richheaderstrategy.cpp header/headerstyle.cpp header/grantleeheaderstyle.cpp header/plainheaderstyle.cpp header/headerstyle_util.cpp header/grantleeheaderformatter.cpp header/grantleeheaderteststyle.cpp header/kxface.cpp header/headerstyleplugin.cpp header/headerstylepluginmanager.cpp header/headerstyleinterface.cpp header/headerstylemenumanager.cpp ) set(libmessageviewer_scamdetection_SRCS scamdetection/scamdetectionwarningwidget.cpp scamdetection/scamdetectiondetailsdialog.cpp scamdetection/scamattribute.cpp scamdetection/scamcheckshorturl.cpp scamdetection/scamexpandurljob.cpp scamdetection/scamcheckshorturlmanager.cpp ) set(libmessageviewer_scamdetection_webengine_SRCS scamdetection/scamdetectionwebengine.cpp ) set(libmessageviewer_findbar_SRCS findbar/findbarsourceview.cpp ) set(libmessageviewer_utils_SRCS utils/iconnamecache.cpp utils/markmessagereadhandler.cpp utils/messageviewerutil.cpp utils/mimetype.cpp ) set(libmessageviewer_htmlwriter_webengine_SRCS htmlwriter/webengineparthtmlwriter.cpp htmlwriter/webengineembedpart.cpp ) set(libmessageviewer_htmlwriter_SRCS htmlwriter/teehtmlwriter.cpp ) set(libmessageviewer_antispam_SRCS antispam/spamheaderanalyzer.cpp antispam/antispamconfig.cpp ) set(libmessageviewer_job_SRCS job/attachmenteditjob.cpp job/modifymessagedisplayformatjob.cpp ) set(libmessageviewer_viewerplugins_SRCS viewerplugins/viewerpluginmanager.cpp viewerplugins/viewerplugin.cpp viewerplugins/viewerplugininterface.cpp viewerplugins/viewerplugintoolmanager.cpp ) set(libmessageviewer_messagepartthemes_default_SRCS messagepartthemes/default/converthtmltoplaintext.cpp messagepartthemes/default/defaultrenderer.cpp messagepartthemes/default/htmlblock.cpp messagepartthemes/default/messagepartrenderermanager.cpp messagepartthemes/default/partrendered.cpp messagepartthemes/default/rendererpluginfactorysingleton.cpp messagepartthemes/default/plugins/attachmentmessagepartrenderer.cpp messagepartthemes/default/plugins/messagepartrenderer.cpp messagepartthemes/default/plugins/textmessagepartrenderer.cpp messagepartthemes/default/plugins/plugins.cpp messagepartthemes/default/plugins/quotehtml.cpp messagepartthemes/default/messagepartrenderbase.cpp messagepartthemes/default/messagepartrendererfactorybase.cpp ) set(libmessageviewer_SRCS ${libmessageviewer_messagepartthemes_default_SRCS} ${libmessageviewer_htmlwriter_webengine_SRCS} ${libmessageviewer_messagepartthemes_SRCS} ${libmessageviewer_scamdetection_webengine_SRCS} ${libmessageviewer_widgets_webengine_SRCS} ${libmessageviewer_viewer_SRCS} ${libmessageviewer_widgets_SRCS} ${libmessageviewer_header_SRCS} ${libmessageviewer_scamdetection_SRCS} ${libmessageviewer_findbar_SRCS} ${libmessageviewer_utils_SRCS} ${libmessageviewer_htmlwriter_SRCS} ${libmessageviewer_antispam_SRCS} ${libmessageviewer_job_SRCS} ${libmessageviewer_viewerplugins_SRCS} settings/messageviewersettings.cpp ${libmessageviewer_mailviewer_SRCS} ) qt5_add_resources(libmessageviewer_SRCS messagepartthemes.qrc) ecm_qt_declare_logging_category(libmessageviewer_SRCS HEADER messageviewer_debug.h IDENTIFIER MESSAGEVIEWER_LOG CATEGORY_NAME org.kde.pim.messageviewer) kconfig_add_kcfg_files(libmessageviewer_SRCS settings/globalsettings_messageviewer.kcfgc ) ki18n_wrap_ui(libmessageviewer_SRCS ui/settings.ui ui/invitationsettings.ui ui/printingsettings.ui ) add_library(KF5MessageViewer ${libmessageviewer_SRCS}) generate_export_header(KF5MessageViewer BASE_NAME messageviewer) add_library(KF5::MessageViewer ALIAS KF5MessageViewer) target_include_directories(KF5MessageViewer INTERFACE "$") target_link_libraries(KF5MessageViewer PUBLIC KF5::MessageCore KF5::PimCommon KF5::AkonadiCore KF5::AkonadiMime KF5::Contacts KF5::Libkleo KF5::MimeTreeParser PRIVATE KF5::SyntaxHighlighting KF5::ItemViews Qt5::Network KF5::WebEngineViewer KF5::LibkdepimAkonadi KF5::GrantleeTheme KF5::KaddressbookGrantlee Grantlee5::Templates KF5::MailTransportAkonadi KF5::Mime KF5::Mbox KF5::PimTextEdit KF5::Gravatar KF5::IconThemes KF5::I18n KF5::KIOFileWidgets KF5::KIOWidgets KF5::WindowSystem KF5::XmlGui Grantlee5::TextDocument Grantlee5::Templates Qt5::PrintSupport QGpgme ) set_target_properties(KF5MessageViewer PROPERTIES VERSION ${MESSAGEVIEWER_VERSION_STRING} SOVERSION ${MESSAGEVIEWER_SOVERSION} EXPORT_NAME MessageViewer ) install(TARGETS KF5MessageViewer EXPORT KF5MessageViewerTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK} ) ecm_generate_headers(MessageViewer_Camelcasewebengine_HEADERS HEADER_NAMES MailWebEnginePage MailWebEngineView REQUIRED_HEADERS MessageViewer_webengine_HEADERS PREFIX MessageViewer RELATIVE viewer/webengine ) ecm_generate_headers(MessageViewer_Camelcasescam_HEADERS HEADER_NAMES ScamExpandUrlJob ScamCheckShortUrlManager ScamCheckShortUrl REQUIRED_HEADERS MessageViewer_scam_HEADERS PREFIX MessageViewer RELATIVE scamdetection ) ecm_generate_headers(MessageViewer_Camelcaseviewer_HEADERS HEADER_NAMES Viewer CSSHelperBase CSSHelper ObjectTreeEmptySource EditorWatcher Stl_Util BodyPartFormatterFactory REQUIRED_HEADERS MessageViewer_viewer_HEADERS PREFIX MessageViewer RELATIVE viewer ) ecm_generate_headers(MessageViewer_Camelcasewidgets_HEADERS HEADER_NAMES InvitationSettings PrintingSettings ConfigureWidget REQUIRED_HEADERS MessageViewer_widgets_HEADERS PREFIX MessageViewer RELATIVE widgets ) ecm_generate_headers(MessageViewer_Camelcaseutils_HEADERS HEADER_NAMES IconNameCache MarkMessageReadHandler MessageViewerUtil MimeType REQUIRED_HEADERS MessageViewer_utils_HEADERS PREFIX MessageViewer RELATIVE utils ) ecm_generate_headers(MessageViewer_Camelcaseantispam_HEADERS HEADER_NAMES SpamHeaderAnalyzer REQUIRED_HEADERS MessageViewer_antispam_HEADERS PREFIX MessageViewer RELATIVE antispam ) ecm_generate_headers(MessageViewer_Camelcaseinterfaces_HEADERS HEADER_NAMES BodyPartURLHandler URLHandler REQUIRED_HEADERS MessageViewer_interfaces_HEADERS PREFIX MessageViewer RELATIVE interfaces ) ecm_generate_headers(MessageViewer_Camelcasesettings_HEADERS HEADER_NAMES MessageViewerSettings REQUIRED_HEADERS MessageViewer_settings_HEADERS PREFIX MessageViewer RELATIVE settings ) ecm_generate_headers(MessageViewer_Camelcaseheader_HEADERS HEADER_NAMES HeaderStrategy GrantleeHeaderTestStyle GrantleeHeaderStyle HeaderStyle KXFace HeaderStyle_Util HeaderStylePlugin HeaderStyleInterface PlainHeaderStyle RichHeaderStrategy HeaderStylePluginManager HeaderStyleMenuManager REQUIRED_HEADERS MessageViewer_header_HEADERS PREFIX MessageViewer RELATIVE header ) ecm_generate_headers(MessageViewer_Camelcaseviewerplugin_HEADERS HEADER_NAMES ViewerPluginManager ViewerPlugin ViewerPluginInterface ViewerPluginToolManager REQUIRED_HEADERS MessageViewer_viewerplugin_HEADERS PREFIX MessageViewer RELATIVE viewerplugins ) ecm_generate_pri_file(BASE_NAME MessageViewer LIB_NAME KF5MessageViewer DEPS "PimCommon MessageCore AkonadiCore AkonadiMime Contacts Libkleo MimeTreeParser" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/MessageViewer ) install(FILES ${MessageViewer_Camelcasewebengine_HEADERS} ${MessageViewer_Camelcaseheader_HEADERS} ${MessageViewer_Camelcaseviewerplugin_HEADERS} ${MessageViewer_Camelcasesettings_HEADERS} ${MessageViewer_Camelcaseutils_HEADERS} ${MessageViewer_Camelcaseinterfaces_HEADERS} ${MessageViewer_Camelcaseviewer_HEADERS} ${MessageViewer_Camelcasewidgets_HEADERS} ${MessageViewer_Camelcaseantispam_HEADERS} ${MessageViewer_Camelfindbar_HEADERS} ${MessageViewer_Camelcasescam_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/MessageViewer COMPONENT Devel ) install(FILES ${MessageViewer_webengine_HEADERS} ${MessageViewer_scam_HEADERS} ${MessageViewer_viewerplugin_HEADERS} ${MessageViewer_settings_HEADERS} ${MessageViewer_header_HEADERS} ${MessageViewer_utils_HEADERS} ${MessageViewer_interfaces_HEADERS} ${MessageViewer_HEADERS} ${MessageViewer_viewer_HEADERS} ${MessageViewer_widgets_HEADERS} ${MessageViewer_antispam_HEADERS} ${MessageViewer_findbar_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/messageviewer_export.h ${CMAKE_CURRENT_BINARY_DIR}/globalsettings_messageviewer.h ${CMAKE_CURRENT_BINARY_DIR}/messageviewer_debug.h ${CMAKE_CURRENT_BINARY_DIR}/config-messageviewer.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/messageviewer COMPONENT Devel ) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) install(FILES header/data/messageviewer_header_themes.knsrc DESTINATION ${KDE_INSTALL_CONFDIR} ) install(FILES notify/messageviewer.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFY5RCDIR} ) install(FILES scamdetection/data/longurlServices.json DESTINATION ${KDE_INSTALL_DATADIR}/messageviewer ) diff --git a/messageviewer/src/viewer/bodypartformatterfactory.cpp b/messageviewer/src/viewer/bodypartformatterfactory.cpp index e54de2a1..1ac8cd77 100644 --- a/messageviewer/src/viewer/bodypartformatterfactory.cpp +++ b/messageviewer/src/viewer/bodypartformatterfactory.cpp @@ -1,100 +1,88 @@ /* bodypartformatterfactory.cpp This file is part of KMail, the KDE mail client. Copyright (c) 2004 Marc Mutz , Ingo Kloecker KMail 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. KMail 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 In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #include "bodypartformatterfactory.h" -#include "pluginloader.h" #include "urlhandlermanager.h" #include "messageviewer_debug.h" #include -using namespace MessageViewer; +#include -namespace { -DEFINE_PLUGIN_LOADER(BodyPartFormatterPluginLoader, - MimeTreeParser::Interface::BodyPartFormatterPlugin, - "create_bodypart_formatter_plugin", - "messageviewer/plugins/bodypartformatter/") -} +using namespace MessageViewer; BodyPartFormatterFactory::BodyPartFormatterFactory() : MimeTreeParser::BodyPartFormatterBaseFactory() { } BodyPartFormatterFactory::~BodyPartFormatterFactory() { } void BodyPartFormatterFactory::loadPlugins() { - const BodyPartFormatterPluginLoader *pl = BodyPartFormatterPluginLoader::instance(); - if (!pl) { - qCWarning(MESSAGEVIEWER_LOG) - << "BodyPartFormatterFactory: cannot instantiate plugin loader!"; - return; - } - const QStringList types = pl->types(); - qCDebug(MESSAGEVIEWER_LOG) << "BodyPartFormatterFactory: found" << types.size() << "plugins."; - for (QStringList::const_iterator it = types.begin(); it != types.end(); ++it) { - const MimeTreeParser::Interface::BodyPartFormatterPlugin *plugin = pl->createForName(*it); + KPluginLoader::forEachPlugin(QStringLiteral("messageviewer/bodypartformatter"), [this](const QString &path) { + QPluginLoader loader(path); + auto plugin = qobject_cast(loader.instance()); if (!plugin) { - qCWarning(MESSAGEVIEWER_LOG) << "BodyPartFormatterFactory: plugin" << *it + qCWarning(MESSAGEVIEWER_LOG) << "BodyPartFormatterFactory: plugin" << path << "is not valid!"; - continue; + return; } + const MimeTreeParser::Interface::BodyPartFormatter *bfp = nullptr; for (int i = 0; (bfp = plugin->bodyPartFormatter(i)); ++i) { const char *type = plugin->type(i); if (!type || !*type) { - qCWarning(MESSAGEVIEWER_LOG) << "BodyPartFormatterFactory: plugin" << *it + qCWarning(MESSAGEVIEWER_LOG) << "BodyPartFormatterFactory: plugin" << path << "returned empty type specification for index" << i; break; } const char *subtype = plugin->subtype(i); if (!subtype || !*subtype) { - qCWarning(MESSAGEVIEWER_LOG) << "BodyPartFormatterFactory: plugin" << *it + qCWarning(MESSAGEVIEWER_LOG) << "BodyPartFormatterFactory: plugin" << path << "returned empty subtype specification for index" << i; break; } qCDebug(MESSAGEVIEWER_LOG) << "plugin for " << type << subtype; insert(type, subtype, bfp); } const MimeTreeParser::Interface::BodyPartURLHandler *handler = nullptr; for (int i = 0; (handler = plugin->urlHandler(i)); ++i) { URLHandlerManager::instance()->registerHandler(handler); } - } + }); } diff --git a/messageviewer/src/viewer/pluginloader.h b/messageviewer/src/viewer/pluginloader.h deleted file mode 100644 index 0dd4a0e4..00000000 --- a/messageviewer/src/viewer/pluginloader.h +++ /dev/null @@ -1,141 +0,0 @@ -/* -*- c++ -*- - This file is part of libkdepim. - - Copyright (c) 2002,2004 Marc Mutz - - 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 PLUGINLOADER_H -#define PLUGINLOADER_H - -#include "pluginloaderbase.h" - -/** - * @short A generic plugin loader for when KPart::Plugin is overkill - * @author Marc Mutz based on KABC's FormatFactory - * - * This is a generic plugin loader / factory for small plugins that - * don't want to be QObjects. - * - * @section Usage - * - * A PluginLoader takes two template arguments, T and - * T_config: - * - *
- *
T
The type of object to return
- *
T_config::mainfunc
The suffix of the factory function to call - * in the library to obtain a new object of type T. - * The string passed to KLibrary::symbol() is - * libName_mainfunc.
- *
T_config::path
The search pattern for .desktop files - * containing the plugin descriptions. This is the string passed as - * the @p filter argument to - * KStandardDirs::findAllResources.
- *
- * - * The last two parameters being strings, they are passed via an - * encapsulating class, of which mainfunc and - * path are public static members: - * - *
- * struct MyObjectPluginLoaderConfig {
- *   static const char * const mainfunc;
- *   static const char * const path;
- * };
- * const char * const MyObjectPluginLoaderConfig::mainfunc = "myapp_create_myobject";
- * const char * const MyObjectPluginLoaderConfig::path = "myapp/plugins/ *.desktop";
- * 
- * - * You would then use a typedef to create a less unwieldy - * name for your plugin loader: - * - *
- * typedef PluginLoader< MyObject, MyObjectPluginLoaderConfig > MyObjectPluginLoader;
- * 
- * - * All of this is what the - * DEFINE_PLUGIN_LOADER(pluginloadername,type,mainfunc,path) macro - * achieves. - * - **/ -template< typename T, typename T_config > -class PluginLoader : public PluginLoaderBase -{ -protected: - PluginLoader() : PluginLoaderBase() - { - } - -private: - static PluginLoader *mSelf; - -public: - virtual ~PluginLoader() - { - mSelf = nullptr; - } - - /** Returns the single instance of this loader. */ - static PluginLoader *instance() - { - if (!mSelf) { - mSelf = new PluginLoader(); - mSelf->scan(); - } - return mSelf; - } - - /** Rescans the plugin directory to find any newly installed - plugins. - **/ - void scan() override - { - doScan(T_config::path); - } - - /** Returns a pointer to a plugin object (of type @p T) or a null - pointer if the type wasn't found. You can extend this method - for when you want to handle builtin types */ - virtual T *createForName(const QString &type) const - { - auto main_func = mainFunc(type, T_config::mainfunc); - if (!main_func) { - return nullptr; - } - - // cast to a pointer to a function returning T*, call it and - // return the result; don't you love C? ;-) - return ((T * (*)())(main_func))(); - } -}; - -template< typename T, typename T_config > -PluginLoader *PluginLoader::mSelf = nullptr; - -#define DEFINE_PLUGIN_LOADER(pl, t, mf, p) \ - namespace { /* don't pollute namespaces */ \ - struct Q_DECL_EXPORT pl ## Config { \ - static const char *const mainfunc; \ - static const char *const path; \ - }; \ - const char *const pl ## Config::mainfunc = mf; \ - const char *const pl ## Config::path = p; \ - } \ - typedef PluginLoader< t, pl ## Config > pl; \ - -#endif // PLUGINLOADER_H diff --git a/messageviewer/src/viewer/pluginloaderbase.cpp b/messageviewer/src/viewer/pluginloaderbase.cpp deleted file mode 100644 index 87619b92..00000000 --- a/messageviewer/src/viewer/pluginloaderbase.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* -*- c++ -*- - This file is part of libkdepim. - - Copyright (c) 2002,2004 Marc Mutz - - 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 "pluginloaderbase.h" -#include "messageviewer_debug.h" - -#include -#include -#include -#include - -#include -#include - -PluginLoaderBase::PluginLoaderBase() -{ -} - -PluginLoaderBase::~PluginLoaderBase() -{ -} - -QStringList PluginLoaderBase::types() const -{ - QStringList result; - result.reserve(mPluginMap.count()); - QMap< QString, PluginMetaData >::const_iterator end(mPluginMap.constEnd()); - for (QMap< QString, PluginMetaData >::const_iterator it = mPluginMap.constBegin(); it != end; - ++it) { - result.push_back(it.key()); - } - return result; -} - -const PluginMetaData *PluginLoaderBase::infoForName(const QString &type) const -{ - return mPluginMap.contains(type) ? &(const_cast(this)->mPluginMap[type]) - : nullptr; -} - -void PluginLoaderBase::doScan(const char *path) -{ - mPluginMap.clear(); - - const QStringList list = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString::fromLatin1( - path), QStandardPaths::LocateDirectory); - for (const QString &folder : list) { - doScanOneFolder(folder); - } -} - -void PluginLoaderBase::doScanOneFolder(const QString &folder) -{ - QDir dir(folder); - const auto list = dir.entryList(QStringList() << QStringLiteral( - "*.desktop"), QDir::Files | QDir::Readable); - for (QStringList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it) { - const QString fileName = folder + QLatin1Char('/') + *it; - KConfig config(fileName, KConfig::SimpleConfig); - if (config.hasGroup("Misc") && config.hasGroup("Plugin")) { - KConfigGroup group(&config, "Plugin"); - - const QString type = group.readEntry("Type").toLower(); - if (type.isEmpty()) { - qCWarning(MESSAGEVIEWER_LOG) << "missing or empty [Plugin]Type value in \"" - << *it << "\" - skipping"; - continue; - } - - const QString library = group.readEntry("X-KDE-Library"); - if (library.isEmpty()) { - qCWarning(MESSAGEVIEWER_LOG) - << "missing or empty [Plugin]X-KDE-Library value in \"" << *it - << "\" - skipping"; - continue; - } - - KConfigGroup group2(&config, "Misc"); - - QString name = group2.readEntry("Name"); - if (name.isEmpty()) { - qCWarning(MESSAGEVIEWER_LOG) << "missing or empty [Misc]Name value in \"" << *it - << "\" - inserting default name"; - name = i18n("Unnamed plugin"); - } - - QString comment = group2.readEntry("Comment"); - if (comment.isEmpty()) { - qCWarning(MESSAGEVIEWER_LOG) << "missing or empty [Misc]Comment value in \"" - << *it << "\" - inserting default name"; - comment = i18n("No description available"); - } - - mPluginMap.insert(type, PluginMetaData(library, name, comment)); - } else { - qCWarning(MESSAGEVIEWER_LOG) << "Desktop file \"" << *it - << "\" doesn't seem to describe a plugin " - << "(misses Misc and/or Plugin group)"; - } - } -} - -QFunctionPointer PluginLoaderBase::mainFunc(const QString &type, const char *mf_name) const -{ - if (type.isEmpty() || !mPluginMap.contains(type)) { - return nullptr; - } - - const QString libName = mPluginMap[ type ].library; - if (libName.isEmpty()) { - return nullptr; - } - - const QLibrary *lib = openLibrary(libName); - if (!lib) { - return nullptr; - } - - PluginMetaData pmd = mPluginMap.value(type); - pmd.loaded = true; - mPluginMap[ type ] = pmd; - - const QString factory_name = libName + QLatin1Char('_') + QString::fromLatin1(mf_name); - auto sym = const_cast(lib)->resolve(factory_name.toLatin1().constData()); - if (!sym) { - qCWarning(MESSAGEVIEWER_LOG) << "No symbol named \"" << factory_name.toLatin1() << "\" (" - << factory_name << ") was found in library \"" << libName - << "\""; - return nullptr; - } - - return sym; -} - -const QLibrary *PluginLoaderBase::openLibrary(const QString &libName) const -{ - auto library = new QLibrary(KPluginLoader::findPlugin(libName)); - if (library->fileName().isEmpty() || !library->load()) { - qCWarning(MESSAGEVIEWER_LOG) << "Could not load plugin library" << libName << "error:" - << library->errorString() << library->fileName(); - delete library; - return nullptr; - } - - return library; -} diff --git a/messageviewer/src/viewer/pluginloaderbase.h b/messageviewer/src/viewer/pluginloaderbase.h deleted file mode 100644 index 2c74299c..00000000 --- a/messageviewer/src/viewer/pluginloaderbase.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- c++ -*- - This file is part of libkdepim. - - Copyright (c) 2002,2004 Marc Mutz - - 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 PLUGINLOADERBASE_H -#define PLUGINLOADERBASE_H - -#include -#include -#include - -class QStringList; - -class PluginMetaData -{ -public: - PluginMetaData() : loaded(false) - { - } - - PluginMetaData(const QString &lib, const QString &name, const QString &comment) - : library(lib) - , nameLabel(name) - , descriptionLabel(comment) - , loaded(false) - { - } - - QString library; - QString nameLabel; - QString descriptionLabel; - bool loaded; -}; - -class PluginLoaderBase -{ -protected: - PluginLoaderBase(); - virtual ~PluginLoaderBase(); - -public: - /** Returns a list of all available plugin objects (of kind @p T) */ - QStringList types() const; - - /** Returns the @ref PluginMetaData structure for a given type */ - const PluginMetaData *infoForName(const QString &type) const; - - /** Overload this method in subclasses to call @ref doScan with - the right @p path argument */ - virtual void scan() = 0; - -protected: - /** Rescans the plugin directory to find any newly installed - plugins. Extend this method in subclasses to add any - builtins. Subclasses must call this explicitly. It's not - called for them in the constructor. - **/ - void doScan(const char *path); - - /** Returns a pointer to symbol @p main_func in the library that - implements the plugin of type @p type */ - QFunctionPointer mainFunc(const QString &type, const char *main_func) const; - -private: - void doScanOneFolder(const QString &folder); - const QLibrary *openLibrary(const QString &libName) const; - mutable QMap< QString, PluginMetaData > mPluginMap; -}; - -#endif // PLUGINLOADERBASE_H diff --git a/mimetreeparser/src/interfaces/bodypartformatter.cpp b/mimetreeparser/src/interfaces/bodypartformatter.cpp index 52e5bd21..b8cd4191 100644 --- a/mimetreeparser/src/interfaces/bodypartformatter.cpp +++ b/mimetreeparser/src/interfaces/bodypartformatter.cpp @@ -1,150 +1,160 @@ /* -*- mode: C++; c-file-style: "gnu" -*- bodypartformatter.cpp This file is part of KMail's plugin interface. Copyright (c) 2016 Sandro Knauß KMail 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. KMail 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 In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #include "bodypartformatter.h" #include "bodypart.h" #include "htmlwriter/queuehtmlwriter.h" #include "viewer/objecttreeparser.h" using namespace MimeTreeParser::Interface; namespace MimeTreeParser { namespace Interface { class MessagePartPrivate { public: MessagePartPrivate(const BodyPart *part) : mHtmlWriter(nullptr) , mPart(part) , mParentPart(nullptr) , mCreatedWriter(false) { } ~MessagePartPrivate() { if (mCreatedWriter) { delete mHtmlWriter; } } MimeTreeParser::HtmlWriter *htmlWriter() { if (!mHtmlWriter && mPart) { mHtmlWriter = mPart->objectTreeParser()->htmlWriter(); } return mHtmlWriter; } MimeTreeParser::HtmlWriter *mHtmlWriter = nullptr; const BodyPart *mPart = nullptr; MessagePart *mParentPart = nullptr; bool mCreatedWriter; }; } } MessagePart::MessagePart() : QObject() , d(new MessagePartPrivate(nullptr)) { } MessagePart::MessagePart(const BodyPart &part) : QObject() , d(new MessagePartPrivate(&part)) { } MessagePart::~MessagePart() { delete d; } void MessagePart::html(bool decorate) { Q_UNUSED(decorate); static_cast(d->mHtmlWriter)->replay(); } QString MessagePart::text() const { return QString(); } MessagePart *MessagePart::parentPart() const { return d->mParentPart; } void MessagePart::setParentPart(MessagePart *parentPart) { d->mParentPart = parentPart; } QString MessagePart::htmlContent() const { return text(); } QString MessagePart::plaintextContent() const { return text(); } MimeTreeParser::HtmlWriter *MessagePart::htmlWriter() const { return d->htmlWriter(); } void MessagePart::setHtmlWriter(MimeTreeParser::HtmlWriter *htmlWriter) const { if (d->mHtmlWriter) { d->mHtmlWriter = htmlWriter; } } BodyPartFormatter::Result BodyPartFormatter::format(BodyPart *part, MimeTreeParser::HtmlWriter *writer) const { Q_UNUSED(part); Q_UNUSED(writer); return Failed; } MessagePart::Ptr BodyPartFormatter::process(BodyPart &part) const { auto mp = MessagePart::Ptr(new MessagePart(part)); mp->setHtmlWriter(new QueueHtmlWriter(mp->htmlWriter())); mp->d->mCreatedWriter = true; return mp; } + +BodyPartFormatterPlugin::~BodyPartFormatterPlugin() +{ +} + +const BodyPartURLHandler* BodyPartFormatterPlugin::urlHandler(int idx) const +{ + Q_UNUSED(idx); + return nullptr; +} diff --git a/mimetreeparser/src/interfaces/bodypartformatter.h b/mimetreeparser/src/interfaces/bodypartformatter.h index aba94ba9..5839940e 100644 --- a/mimetreeparser/src/interfaces/bodypartformatter.h +++ b/mimetreeparser/src/interfaces/bodypartformatter.h @@ -1,144 +1,145 @@ /* -*- mode: C++; c-file-style: "gnu" -*- bodypartformatter.h This file is part of KMail's plugin interface. Copyright (c) 2004 Marc Mutz , Ingo Kloecker KMail 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. KMail 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 In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifndef __MIMETREEPARSER_INTERFACE_BODYPARTFORMATTER_H__ #define __MIMETREEPARSER_INTERFACE_BODYPARTFORMATTER_H__ #include "mimetreeparser_export.h" #include #include #include "mimetreeparser/objecttreeparser.h" namespace MimeTreeParser { class HtmlWriter; namespace Interface { class BodyPartURLHandler; class BodyPart; class MessagePartPrivate; class MIMETREEPARSER_EXPORT MessagePart : public QObject { Q_OBJECT Q_PROPERTY(QString plaintextContent READ plaintextContent) Q_PROPERTY(QString htmlContent READ htmlContent) public: typedef QSharedPointer Ptr; explicit MessagePart(); explicit MessagePart(const BodyPart &part); virtual ~MessagePart(); virtual void html(bool decorate); virtual QString text() const; void setParentPart(MessagePart *parentPart); MessagePart *parentPart() const; virtual QString plaintextContent() const; virtual QString htmlContent() const; virtual MimeTreeParser::HtmlWriter *htmlWriter() const; virtual void setHtmlWriter(MimeTreeParser::HtmlWriter *htmlWriter) const; private: MessagePartPrivate *d; friend class BodyPartFormatter; }; class MIMETREEPARSER_EXPORT BodyPartFormatter { public: virtual ~BodyPartFormatter() { } /** @li Ok returned when format() generated some HTML @li NeedContent returned when format() needs the body of the part @li AsIcon returned when the part should be shown iconified @li Failed returned when formatting failed. Currently equivalent to Ok */ enum Result { Ok, NeedContent, AsIcon, Failed }; /** Format body part \a part by generating some HTML and writing that to \a writer. If you a async process and need to send an update information you can use MimeTreeParser::NodeHelper::Update signal with the corresponding instance of BodyPart::nodeHelper() @return the result code (see above) */ virtual Result format(BodyPart *part, MimeTreeParser::HtmlWriter *writer) const; virtual void adaptProcessResult(ProcessResult &result) const { Q_UNUSED(result); } virtual MessagePart::Ptr process(BodyPart &part) const; }; /** @short interface for BodyPartFormatter plugins The interface is queried by for types, subtypes, and the corresponding bodypart formatter, and the result inserted into the bodypart formatter factory. Subtype alone or both type and subtype may be "*", which is taken as a wildcard, so that e.g. type=text subtype=* matches any text subtype, but with lesser specificity than a concrete mimetype such as text/plain. type=* is only allowed when subtype=*, too. */ -class BodyPartFormatterPlugin +class MIMETREEPARSER_EXPORT BodyPartFormatterPlugin { public: - virtual ~BodyPartFormatterPlugin() - { - } + virtual ~BodyPartFormatterPlugin(); virtual const BodyPartFormatter *bodyPartFormatter(int idx) const = 0; virtual const char *type(int idx) const = 0; virtual const char *subtype(int idx) const = 0; - virtual const BodyPartURLHandler *urlHandler(int idx) const = 0; + virtual const BodyPartURLHandler *urlHandler(int idx) const; }; } // namespace Interface } + +Q_DECLARE_INTERFACE(MimeTreeParser::Interface::BodyPartFormatterPlugin, "org.kde.messageviewer.bodypartformatter/1.0") + #endif // __MIMETREEPARSER_INTERFACE_BODYPARTFORMATTER_H__