diff --git a/src/editor/plugininterface/kmailplugineditorconverttextmanagerinterface.cpp b/src/editor/plugininterface/kmailplugineditorconverttextmanagerinterface.cpp index 0bf70e1f1..c1ebcd4ad 100644 --- a/src/editor/plugininterface/kmailplugineditorconverttextmanagerinterface.cpp +++ b/src/editor/plugininterface/kmailplugineditorconverttextmanagerinterface.cpp @@ -1,212 +1,212 @@ /* Copyright (C) 2018-2020 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kmailplugineditorconverttextmanagerinterface.h" #include "kmail_debug.h" #include #include #include #include KMailPluginEditorConvertTextManagerInterface::KMailPluginEditorConvertTextManagerInterface(QObject *parent) : QObject(parent) { } KMailPluginEditorConvertTextManagerInterface::~KMailPluginEditorConvertTextManagerInterface() { } void KMailPluginEditorConvertTextManagerInterface::enableDisablePluginActions(bool richText) { for (MessageComposer::PluginEditorConvertTextInterface *interface : qAsConst(mListPluginInterface)) { interface->enableDisablePluginActions(richText); } } void KMailPluginEditorConvertTextManagerInterface::reformatText() { for (MessageComposer::PluginEditorConvertTextInterface *interface : qAsConst(mListPluginInterface)) { if (interface->reformatText()) { //TODO signal that it was reformating. //Stop it.? } } Q_EMIT reformatingTextDone(); } MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus KMailPluginEditorConvertTextManagerInterface::convertTextToFormat(MessageComposer::TextPart *textPart) { MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus status = MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus::NotConverted; for (MessageComposer::PluginEditorConvertTextInterface *interface : qAsConst(mListPluginInterface)) { switch (interface->convertTextToFormat(textPart)) { case MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus::NotConverted: if (status != MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus::Converted) { status = MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus::NotConverted; } break; case MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus::Converted: status = MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus::Converted; break; case MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus::Error: status = MessageComposer::PluginEditorConvertTextInterface::ConvertTextStatus::Error; return status; } } return status; } void KMailPluginEditorConvertTextManagerInterface::setInitialData(const MessageComposer::PluginEditorConverterInitialData &data) { for (MessageComposer::PluginEditorConvertTextInterface *interface : qAsConst(mListPluginInterface)) { interface->setInitialData(data); } } void KMailPluginEditorConvertTextManagerInterface::setDataBeforeConvertingText(const MessageComposer::PluginEditorConverterBeforeConvertingData &data) { for (MessageComposer::PluginEditorConvertTextInterface *interface : qAsConst(mListPluginInterface)) { interface->setBeforeConvertingData(data); } } QWidget *KMailPluginEditorConvertTextManagerInterface::parentWidget() const { return mParentWidget; } void KMailPluginEditorConvertTextManagerInterface::setParentWidget(QWidget *parentWidget) { mParentWidget = parentWidget; } KActionCollection *KMailPluginEditorConvertTextManagerInterface::actionCollection() const { return mActionCollection; } void KMailPluginEditorConvertTextManagerInterface::setActionCollection(KActionCollection *actionCollection) { mActionCollection = actionCollection; } void KMailPluginEditorConvertTextManagerInterface::initializePlugins() { if (!mListPluginInterface.isEmpty()) { qCWarning(KMAIL_LOG) << "KMailPluginEditorConvertTextManagerInterface : Plugin was already initialized. This is a bug"; return; } if (!mRichTextEditor) { qCWarning(KMAIL_LOG) << "KMailPluginEditorConvertTextManagerInterface : Richtexteditor is null. This is a bug"; return; } if (!mParentWidget) { qCWarning(KMAIL_LOG) << "KMailPluginEditorConvertTextManagerInterface : Parent is null. This is a bug"; } const QVector lstPlugin = MessageComposer::PluginEditorConvertTextManager::self()->pluginsList(); for (MessageComposer::PluginEditorConvertText *plugin : lstPlugin) { if (plugin->isEnabled()) { - MessageComposer::PluginEditorConvertTextInterface *interface = static_cast(plugin->createInterface(this)); + MessageComposer::PluginEditorConvertTextInterface *interface = plugin->createInterface(this); interface->setRichTextEditor(mRichTextEditor); interface->setParentWidget(mParentWidget); interface->createAction(mActionCollection); interface->setPlugin(plugin); mListPluginInterface.append(interface); } } qCDebug(KMAIL_LOG) << "KMailPluginEditorConvertTextManagerInterface : Initialize done, number of plugins found: " << mListPluginInterface.count(); } KPIMTextEdit::RichTextComposer *KMailPluginEditorConvertTextManagerInterface::richTextEditor() const { return mRichTextEditor; } void KMailPluginEditorConvertTextManagerInterface::setRichTextEditor(KPIMTextEdit::RichTextComposer *richTextEditor) { mRichTextEditor = richTextEditor; } QHash > KMailPluginEditorConvertTextManagerInterface::actionsType() { if (mActionHash.isEmpty()) { for (MessageComposer::PluginEditorConvertTextInterface *interface : qAsConst(mListPluginInterface)) { for (const MessageComposer::PluginActionType &actionType : interface->actionTypes()) { MessageComposer::PluginActionType::Type type = actionType.type(); QAction *currentAction = actionType.action(); if (!currentAction) { continue; } QList lst = mActionHash.value(type); if (!lst.isEmpty()) { QAction *act = new QAction(this); act->setSeparator(true); lst << act << currentAction; mActionHash.insert(type, lst); } else { mActionHash.insert(type, QList() << currentAction); } if (interface->plugin()->hasPopupMenuSupport()) { type = MessageComposer::PluginActionType::PopupMenu; if (currentAction) { lst = mActionHash.value(type); if (!lst.isEmpty()) { QAction *act = new QAction(this); act->setSeparator(true); lst << act << currentAction; mActionHash.insert(type, lst); } else { mActionHash.insert(type, QList() << currentAction); } } } if (interface->plugin()->hasToolBarSupport()) { type = MessageComposer::PluginActionType::ToolBar; lst = mActionHash.value(type); if (!lst.isEmpty()) { QAction *act = new QAction(this); act->setSeparator(true); lst << act << currentAction; mActionHash.insert(type, lst); } else { mActionHash.insert(type, QList() << currentAction); } } } } } return mActionHash; } QList KMailPluginEditorConvertTextManagerInterface::actionsType(MessageComposer::PluginActionType::Type type) { return mActionHash.value(type); } QList KMailPluginEditorConvertTextManagerInterface::statusBarWidgetList() { if (mStatusBarWidget.isEmpty() && !mListPluginInterface.isEmpty()) { for (MessageComposer::PluginEditorConvertTextInterface *interface : qAsConst(mListPluginInterface)) { if (interface->plugin()->hasStatusBarSupport()) { mStatusBarWidget.append(interface->statusBarWidget()); } } } return mStatusBarWidget; } diff --git a/src/job/dndfromarkjob.cpp b/src/job/dndfromarkjob.cpp index 42643c2b5..b50b087d8 100644 --- a/src/job/dndfromarkjob.cpp +++ b/src/job/dndfromarkjob.cpp @@ -1,87 +1,88 @@ /* Copyright (C) 2018-2020 Laurent Montel 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 "dndfromarkjob.h" #include "editor/kmcomposerwin.h" #include "kmail_debug.h" #include #include #include #include #include #include #include DndFromArkJob::DndFromArkJob(QObject *parent) : QObject(parent) { } bool DndFromArkJob::dndFromArk(const QMimeData *source) { if (source->hasFormat(QStringLiteral("application/x-kde-ark-dndextract-service")) && source->hasFormat(QStringLiteral("application/x-kde-ark-dndextract-path"))) { return true; } return false; } bool DndFromArkJob::extract(const QMimeData *source) { if (dndFromArk(source)) { if (!mComposerWin) { qCWarning(KMAIL_LOG) << "mComposerWin is null, it's a bug"; deleteLater(); return false; } const QString remoteDBusClient = QString::fromLatin1(source->data(QStringLiteral("application/x-kde-ark-dndextract-service"))); const QString remoteDBusPath = QString::fromLatin1(source->data(QStringLiteral("application/x-kde-ark-dndextract-path"))); const QString tmpPath = QDir::tempPath() + QLatin1String("/attachments_ark"); QDir().mkpath(tmpPath); QTemporaryDir *linkDir = new QTemporaryDir(tmpPath); const QString arkPath = linkDir->path(); QDBusMessage message = QDBusMessage::createMethodCall(remoteDBusClient, remoteDBusPath, QStringLiteral("org.kde.ark.DndExtract"), QStringLiteral("extractSelectedFilesTo")); message.setArguments({arkPath}); QDBusConnection::sessionBus().call(message); QDir dir(arkPath); const QStringList list = dir.entryList(QDir::NoDotAndDotDot | QDir::Files); QList infoList; + infoList.reserve(list.size()); for (int i = 0; i < list.size(); ++i) { KMail::Composer::AttachmentInfo info; info.url = QUrl::fromLocalFile(list.at(i)); infoList.append(info); } mComposerWin->addAttachment(infoList, false); delete linkDir; deleteLater(); return true; } deleteLater(); return false; } void DndFromArkJob::setComposerWin(KMComposerWin *composerWin) { mComposerWin = composerWin; }