Commit 33216eb2 authored by Laurent Montel's avatar Laurent Montel 😁

Remove duplicate code

parent 1272468a
......@@ -24,6 +24,7 @@ using namespace PimCommon::ConfigureImmutableWidgetUtils;
#include "pimcommon/autocorrection/autocorrectionwidget.h"
#include "messagecomposer/imagescaling/imagescalingwidget.h"
#include "messagecomposer/settings/messagecomposersettings.h"
#include "messagecore/settings/globalsettings.h"
#include "settings/globalsettings.h"
#include "configuredialog/configuredialoglistview.h"
#include "pimcommon/widgets/simplestringlisteditor.h"
......@@ -1316,8 +1317,8 @@ void ComposerPage::AttachmentsTab::doLoadFromGlobalSettings()
loadWidget(mOutlookCompatibleCheck, MessageComposer::MessageComposerSettings::self()->outlookCompatibleAttachmentsItem());
loadWidget(mMissingAttachmentDetectionCheck, GlobalSettings::self()->showForgottenAttachmentWarningItem());
loadWidget(mAttachWordsListEditor, GlobalSettings::self()->attachmentKeywordsItem() );
const int maximumAttachmentSize(MessageComposer::MessageComposerSettings::self()->maximumAttachmentSize());
mMaximumAttachmentSize->setValue(maximumAttachmentSize == -1 ? -1 : MessageComposer::MessageComposerSettings::self()->maximumAttachmentSize()/1024);
const int maximumAttachmentSize(MessageCore::GlobalSettings::self()->maximumAttachmentSize());
mMaximumAttachmentSize->setValue(maximumAttachmentSize == -1 ? -1 : MessageCore::GlobalSettings::self()->maximumAttachmentSize()/1024);
mStorageServiceWidget->doLoadFromGlobalSettings();
}
......@@ -1329,7 +1330,7 @@ void ComposerPage::AttachmentsTab::save()
KMime::setUseOutlookAttachmentEncoding( mOutlookCompatibleCheck->isChecked() );
const int maximumAttachmentSize(mMaximumAttachmentSize->value());
MessageComposer::MessageComposerSettings::self()->setMaximumAttachmentSize(maximumAttachmentSize == -1 ? -1 : maximumAttachmentSize*1024);
MessageCore::GlobalSettings::self()->setMaximumAttachmentSize(maximumAttachmentSize == -1 ? -1 : maximumAttachmentSize*1024);
mStorageServiceWidget->save();
}
......
......@@ -63,6 +63,7 @@
#include <messagecore/attachment/attachmentfromurljob.h>
#include <messagecore/attachment/attachmentpropertiesdialog.h>
#include <messagecore/attachment/attachmentupdatejob.h>
#include <messagecore/attachment/attachmentfromurlutils.h>
#include <settings/messagecomposersettings.h>
#include <KIO/Job>
......@@ -858,25 +859,9 @@ void AttachmentControllerBase::addAttachment( AttachmentPart::Ptr part )
emit fileAttached();
}
MessageCore::AttachmentFromUrlBaseJob * AttachmentControllerBase::createAttachmentJob(const KUrl &url)
{
MessageCore::AttachmentFromUrlBaseJob *ajob = 0;
if( KMimeType::findByUrl( url )->name() == QLatin1String( "inode/directory" ) ) {
kDebug() << "Creating attachment from folder";
ajob = new AttachmentFromFolderJob ( url, this );
} else {
ajob = new AttachmentFromUrlJob( url, this );
kDebug() << "Creating attachment from file";
}
if( MessageComposer::MessageComposerSettings::maximumAttachmentSize() > 0 ) {
ajob->setMaximumAllowedSize( MessageComposer::MessageComposerSettings::maximumAttachmentSize() );
}
return ajob;
}
void AttachmentControllerBase::addAttachmentUrlSync(const KUrl &url)
{
MessageCore::AttachmentFromUrlBaseJob *ajob = createAttachmentJob(url);
MessageCore::AttachmentFromUrlBaseJob *ajob = MessageCore::AttachmentFromUrlUtils::createAttachmentJob(url, this);
if(ajob->exec()) {
AttachmentPart::Ptr part = ajob->attachmentPart();
addAttachment( part );
......@@ -889,7 +874,7 @@ void AttachmentControllerBase::addAttachmentUrlSync(const KUrl &url)
void AttachmentControllerBase::addAttachment( const KUrl &url )
{
MessageCore::AttachmentFromUrlBaseJob *ajob = createAttachmentJob(url);
MessageCore::AttachmentFromUrlBaseJob *ajob = MessageCore::AttachmentFromUrlUtils::createAttachmentJob(url, this);
connect( ajob, SIGNAL(result(KJob*)), this, SLOT(loadJobResult(KJob*)) );
ajob->start();
}
......
......@@ -96,8 +96,6 @@ protected:
void enableAttachMyPublicKey( bool enable );
void byteArrayToRemoteFile(const QByteArray &aData, const KUrl &aURL, bool overwrite = false);
void openWith(KService::Ptr offer = KService::Ptr());
private:
MessageCore::AttachmentFromUrlBaseJob * createAttachmentJob(const KUrl &url);
private slots:
void slotPutResult(KJob *job);
void slotOpenWithDialog();
......
......@@ -85,10 +85,6 @@ xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 http://www.kde.org/sta
<default>false</default>
</entry>
<entry name="MaximumAttachmentSize" type="Int">
<label>The maximum size in bits that email attachments are allowed to have (-1 for no limit)</label>
<default>-1</default>
</entry>
<entry name="OutlookCompatibleAttachments" type="Bool" key="outlook-compatible-attachments">
<label>Outlook-compatible attachment naming</label>
<whatsthis>Turn this option on to make Outlook &#8482; understand attachment names containing non-English characters</whatsthis>
......
......@@ -24,6 +24,7 @@ set(messagecore_attachment_LIB_SRCS
attachment/attachmentpart.cpp
attachment/attachmentpropertiesdialog.cpp
attachment/attachmentupdatejob.cpp
attachment/attachmentfromurlutils.cpp
)
set(messagecore_misc_LIB_SRCS
......
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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 "attachmentfromfolderjob.h"
#include "attachmentfromurljob.h"
#include "attachmentfromurlutils.h"
#include "messagecore/settings/globalsettings.h"
#include <KMimeType>
#include <QDebug>
namespace MessageCore {
MessageCore::AttachmentFromUrlBaseJob *AttachmentFromUrlUtils::createAttachmentJob(const KUrl &url, QObject *parent)
{
MessageCore::AttachmentFromUrlBaseJob *ajob = 0;
if( KMimeType::findByUrl( url )->name() == QLatin1String( "inode/directory" ) ) {
qDebug() << "Creating attachment from folder";
ajob = new MessageCore::AttachmentFromFolderJob ( url, parent );
} else {
ajob = new MessageCore::AttachmentFromUrlJob( url, parent );
qDebug() << "Creating attachment from file";
}
if( MessageCore::GlobalSettings::maximumAttachmentSize() > 0 ) {
ajob->setMaximumAllowedSize( MessageCore::GlobalSettings::maximumAttachmentSize() );
}
return ajob;
}
}
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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
*/
#ifndef ATTACHMENTFROMURLUTILS_H
#define ATTACHMENTFROMURLUTILS_H
#include <QObject>
#include "messagecore_export.h"
namespace MessageCore {
class AttachmentFromUrlBaseJob;
namespace AttachmentFromUrlUtils {
MESSAGECORE_EXPORT MessageCore::AttachmentFromUrlBaseJob *createAttachmentJob(const KUrl &url, QObject *parent);
}
}
#endif // ATTACHMENTFROMURLUTILS_H
......@@ -18,6 +18,7 @@
#include "attachmentfromurlbasejob.h"
#include "attachmentfromurljob.h"
#include "attachmentupdatejob.h"
#include "attachmentfromurlutils.h"
#include <KUrl>
#include <KMimeType>
#include <QDebug>
......@@ -32,8 +33,6 @@ public:
void doStart(); // slot
void loadJobResult(KJob*);
MessageCore::AttachmentFromUrlBaseJob *createAttachmentJob(const KUrl &url);
AttachmentUpdateJob *const q;
AttachmentPart::Ptr mOriginalPart;
AttachmentPart::Ptr mUpdatedPart;
......@@ -54,7 +53,7 @@ void AttachmentUpdateJob::Private::doStart()
q->emitResult();
return;
}
MessageCore::AttachmentFromUrlBaseJob *job = createAttachmentJob(mOriginalPart->url());
MessageCore::AttachmentFromUrlBaseJob *job = MessageCore::AttachmentFromUrlUtils::createAttachmentJob(mOriginalPart->url(), q);
connect( job, SIGNAL(result(KJob*)), q, SLOT(loadJobResult(KJob*)) );
job->start();
}
......@@ -81,25 +80,6 @@ void AttachmentUpdateJob::Private::loadJobResult(KJob *job)
q->emitResult(); // Success.
}
MessageCore::AttachmentFromUrlBaseJob *AttachmentUpdateJob::Private::createAttachmentJob(const KUrl &url)
{
MessageCore::AttachmentFromUrlBaseJob *ajob = 0;
if( KMimeType::findByUrl( url )->name() == QLatin1String( "inode/directory" ) ) {
qDebug() << "Creating attachment from folder";
ajob = new AttachmentFromFolderJob ( url, q );
} else {
ajob = new AttachmentFromUrlJob( url, q );
qDebug() << "Creating attachment from file";
}
/*
if( MessageComposer::MessageComposerSettings::maximumAttachmentSize() > 0 ) {
ajob->setMaximumAllowedSize( MessageComposer::MessageComposerSettings::maximumAttachmentSize() );
}
*/
return ajob;
}
AttachmentUpdateJob::AttachmentUpdateJob(const AttachmentPart::Ptr &part, QObject *parent)
: KJob(parent),
d( new Private( this ) )
......
......@@ -79,6 +79,10 @@
<group name="Composer">
<entry name="ReplyPrefixes" key="reply-prefixes" type="StringList"/>
<entry name="ForwardPrefixes" key="forward-prefixes" type="StringList"/>
<entry name="MaximumAttachmentSize" type="Int">
<label>The maximum size in bits that email attachments are allowed to have (-1 for no limit)</label>
<default>-1</default>
</entry>
</group>
</kcfg>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment