Commit e8c3dfe0 authored by Laurent Montel's avatar Laurent Montel 😁

Don't duplicate url in each class

parent 998cc6a8
...@@ -40,7 +40,6 @@ public: ...@@ -40,7 +40,6 @@ public:
void addEntity( const QFileInfoList &f, const QString &path ); void addEntity( const QFileInfoList &f, const QString &path );
AttachmentFromFolderJob *const q; AttachmentFromFolderJob *const q;
KUrl mUrl;
KZip::Compression mCompression; KZip::Compression mCompression;
AttachmentPart::Ptr mCompressedFolder; AttachmentPart::Ptr mCompressedFolder;
QScopedPointer<KZip> mZip; QScopedPointer<KZip> mZip;
...@@ -58,7 +57,7 @@ AttachmentFromFolderJob::Private::Private( AttachmentFromFolderJob* qq ) : ...@@ -58,7 +57,7 @@ AttachmentFromFolderJob::Private::Private( AttachmentFromFolderJob* qq ) :
void AttachmentFromFolderJob::Private::compressFolder() void AttachmentFromFolderJob::Private::compressFolder()
{ {
kDebug() << "starting compression"; kDebug() << "starting compression";
QString fileName = mUrl.fileName(); QString fileName = q->url().fileName();
QByteArray array; QByteArray array;
QBuffer dev( &array ); QBuffer dev( &array );
mZip.reset( new KZip( &dev ) ); mZip.reset( new KZip( &dev ) );
...@@ -69,9 +68,9 @@ void AttachmentFromFolderJob::Private::compressFolder() ...@@ -69,9 +68,9 @@ void AttachmentFromFolderJob::Private::compressFolder()
return; return;
} }
mZip->setCompression( mCompression ); mZip->setCompression( mCompression );
mZip->writeDir( mUrl.fileName(),QString(),QString(), 040755, mArchiveTime, mArchiveTime, mArchiveTime ); mZip->writeDir( q->url().fileName(),QString(),QString(), 040755, mArchiveTime, mArchiveTime, mArchiveTime );
kDebug() << "writing root directory : " << mUrl.fileName(); kDebug() << "writing root directory : " << q->url().fileName();
addEntity( QDir( mUrl.path() ).entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot | addEntity( QDir( q->url().path() ).entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot |
QDir::NoSymLinks | QDir::Files, QDir::DirsFirst ), fileName + QLatin1Char('/') ); QDir::NoSymLinks | QDir::Files, QDir::DirsFirst ), fileName + QLatin1Char('/') );
mZip->close(); mZip->close();
...@@ -140,7 +139,6 @@ AttachmentFromFolderJob::AttachmentFromFolderJob( const KUrl &url, QObject *pare ...@@ -140,7 +139,6 @@ AttachmentFromFolderJob::AttachmentFromFolderJob( const KUrl &url, QObject *pare
AttachmentFromUrlBaseJob ( url, parent ), AttachmentFromUrlBaseJob ( url, parent ),
d( new Private( this ) ) d( new Private( this ) )
{ {
d->mUrl = url;
} }
AttachmentFromFolderJob::~AttachmentFromFolderJob() AttachmentFromFolderJob::~AttachmentFromFolderJob()
......
...@@ -43,7 +43,6 @@ public: ...@@ -43,7 +43,6 @@ public:
void transferJobResult( KJob *job ); void transferJobResult( KJob *job );
AttachmentFromUrlJob *const q; AttachmentFromUrlJob *const q;
KUrl mUrl;
QByteArray mData; QByteArray mData;
}; };
...@@ -77,7 +76,7 @@ void AttachmentFromUrlJob::Private::transferJobResult( KJob *job ) ...@@ -77,7 +76,7 @@ void AttachmentFromUrlJob::Private::transferJobResult( KJob *job )
const QString mimeType = transferJob->mimetype(); const QString mimeType = transferJob->mimetype();
kDebug() << "Mimetype is" << mimeType; kDebug() << "Mimetype is" << mimeType;
QString fileName = mUrl.fileName(); QString fileName = q->url().fileName();
if ( fileName.isEmpty() ) { if ( fileName.isEmpty() ) {
const KMimeType::Ptr mimeTypePtr = KMimeType::mimeType( mimeType, KMimeType::ResolveAliases ); const KMimeType::Ptr mimeTypePtr = KMimeType::mimeType( mimeType, KMimeType::ResolveAliases );
if ( mimeTypePtr ) { if ( mimeTypePtr ) {
...@@ -108,11 +107,11 @@ void AttachmentFromUrlJob::Private::transferJobResult( KJob *job ) ...@@ -108,11 +107,11 @@ void AttachmentFromUrlJob::Private::transferJobResult( KJob *job )
Q_ASSERT( q->attachmentPart() == 0 ); // Not created before. Q_ASSERT( q->attachmentPart() == 0 ); // Not created before.
AttachmentPart::Ptr part = AttachmentPart::Ptr( new AttachmentPart ); AttachmentPart::Ptr part = AttachmentPart::Ptr( new AttachmentPart );
part->setCharset( mUrl.fileEncoding().toLatin1() ); part->setCharset( q->url().fileEncoding().toLatin1() );
part->setMimeType( mimeType.toLatin1() ); part->setMimeType( mimeType.toLatin1() );
part->setName( fileName ); part->setName( fileName );
part->setFileName( fileName ); part->setFileName( fileName );
part->setUrl(mUrl); part->setUrl(q->url());
part->setData( mData ); part->setData( mData );
q->setAttachmentPart( part ); q->setAttachmentPart( part );
q->emitResult(); // Success. q->emitResult(); // Success.
...@@ -123,7 +122,6 @@ AttachmentFromUrlJob::AttachmentFromUrlJob( const KUrl &url, QObject *parent ) ...@@ -123,7 +122,6 @@ AttachmentFromUrlJob::AttachmentFromUrlJob( const KUrl &url, QObject *parent )
: AttachmentFromUrlBaseJob( url, parent ), : AttachmentFromUrlBaseJob( url, parent ),
d( new Private( this ) ) d( new Private( this ) )
{ {
d->mUrl = url;
} }
AttachmentFromUrlJob::~AttachmentFromUrlJob() AttachmentFromUrlJob::~AttachmentFromUrlJob()
...@@ -133,15 +131,15 @@ AttachmentFromUrlJob::~AttachmentFromUrlJob() ...@@ -133,15 +131,15 @@ AttachmentFromUrlJob::~AttachmentFromUrlJob()
void AttachmentFromUrlJob::doStart() void AttachmentFromUrlJob::doStart()
{ {
if ( !d->mUrl.isValid() ) { if ( !url().isValid() ) {
setError( KJob::UserDefinedError ); setError( KJob::UserDefinedError );
setErrorText( i18n( "\"%1\" not found. Please specify the full path.", d->mUrl.prettyUrl() ) ); setErrorText( i18n( "\"%1\" not found. Please specify the full path.", url().prettyUrl() ) );
emitResult(); emitResult();
return; return;
} }
if ( maximumAllowedSize() != -1 && d->mUrl.isLocalFile() ) { if ( maximumAllowedSize() != -1 && url().isLocalFile() ) {
const qint64 size = QFileInfo( d->mUrl.toLocalFile() ).size(); const qint64 size = QFileInfo( url().toLocalFile() ).size();
if ( size > maximumAllowedSize() ) { if ( size > maximumAllowedSize() ) {
setError( KJob::UserDefinedError ); setError( KJob::UserDefinedError );
setErrorText( i18n( "You may not attach files bigger than %1. Share it with storage service.", setErrorText( i18n( "You may not attach files bigger than %1. Share it with storage service.",
...@@ -154,7 +152,7 @@ void AttachmentFromUrlJob::doStart() ...@@ -154,7 +152,7 @@ void AttachmentFromUrlJob::doStart()
Q_ASSERT( d->mData.isEmpty() ); // Not started twice. Q_ASSERT( d->mData.isEmpty() ); // Not started twice.
#ifndef KDEPIM_MOBILE_UI #ifndef KDEPIM_MOBILE_UI
KIO::TransferJob *job = KIO::get( d->mUrl, KIO::NoReload, KIO::TransferJob *job = KIO::get( url(), KIO::NoReload,
( uiDelegate() ? KIO::DefaultFlags : KIO::HideProgressInfo ) ); ( uiDelegate() ? KIO::DefaultFlags : KIO::HideProgressInfo ) );
QObject::connect( job, SIGNAL(result(KJob*)), QObject::connect( job, SIGNAL(result(KJob*)),
this, SLOT(transferJobResult(KJob*)) ); this, SLOT(transferJobResult(KJob*)) );
......
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