Commit 804fc115 authored by Raphael Kubo da Costa's avatar Raphael Kubo da Costa
Browse files

Don't rely on Archive::factory to guess the mimetype when creating an

archive, otherwise we may end up creating a ReadOnlyInterface and crash.
For AddToArchive we set the mimetype from the file dialog (and remember
it with KConfig), for the KPart we only ask the user to choose a
mimetype that supports writing.

BUG: 195212

svn path=/trunk/KDE/kdeutils/ark/; revision=978424
parent 549181df
......@@ -2,6 +2,7 @@
* ark -- archiver for the KDE project
*
* Copyright (C) 2008 Harald Hvaal <haraldhv atatatat stud.ntnu.no>
* Copyright (C) 2009 Raphael Kubo da Costa <kubito@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -23,8 +24,11 @@
#include "ui_adddialog.h"
#include "kerfuffle/archive.h"
#include <KConfigGroup>
#include <KFilePlacesModel>
#include <KGlobal>
#include <QStandardItemModel>
#include <kfileplacesmodel.h>
namespace Kerfuffle
{
......@@ -39,18 +43,21 @@ namespace Kerfuffle
};
AddDialog::AddDialog(const QStringList& itemsToAdd,
const KUrl & startDir,
const QString & filter,
QWidget * parent,
QWidget * widget
const KUrl & startDir,
const QString & filter,
QWidget * parent,
QWidget * widget
)
: KFileDialog(startDir, filter, parent, widget)
{
setOperationMode(KFileDialog::Saving);
setMode(KFile::File |
KFile::LocalOnly );
setMode(KFile::File | KFile::LocalOnly );
setCaption(i18n("Compress to Archive"));
loadConfiguration();
connect( this, SIGNAL( okClicked() ), SLOT( updateDefaultMimeType() ) );
m_ui = new AddDialogUI( this );
mainWidget()->layout()->addWidget(m_ui);
......@@ -59,15 +66,27 @@ namespace Kerfuffle
//These extra options will be implemented in a 4.2+ version of
//ark
m_ui->groupExtraOptions->hide();
}
void AddDialog::loadConfiguration()
{
m_config = KConfigGroup( KGlobal::config()->group( "AddDialog" ) );
setMimeFilter(Kerfuffle::supportedWriteMimeTypes());
QString defaultMimeType = "application/x-compressed-tar";
QStringList writeMimeTypes = Kerfuffle::supportedWriteMimeTypes();
QString lastMimeType = m_config.readEntry( "LastMimeType", defaultMimeType );
if (writeMimeTypes.contains( lastMimeType ))
setMimeFilter( writeMimeTypes, lastMimeType );
else
setMimeFilter( writeMimeTypes, defaultMimeType );
}
void AddDialog::setupIconList(const QStringList& itemsToAdd)
{
QStandardItemModel* listModel = new QStandardItemModel(this);
QStringList sortedList(itemsToAdd);
sortedList.sort();
Q_FOREACH(const QString& urlString, sortedList) {
......@@ -85,6 +104,12 @@ namespace Kerfuffle
}
m_ui->compressList->setModel(listModel);
}
void AddDialog::updateDefaultMimeType()
{
m_config.writeEntry( "LastMimeType", currentMimeFilter() );
}
}
#include "adddialog.moc"
......@@ -2,6 +2,7 @@
* ark -- archiver for the KDE project
*
* Copyright (C) 2008 Harald Hvaal <haraldhv atatatat stud.ntnu.no>
* Copyright (C) 2009 Raphael Kubo da Costa <kubito@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -24,25 +25,32 @@
#include "kerfuffle_export.h"
#include <KConfigGroup>
#include <KFileDialog>
namespace Kerfuffle
{
class KERFUFFLE_EXPORT AddDialog : public KFileDialog
{
Q_OBJECT
public:
AddDialog(const QStringList& itemsToAdd,
const KUrl & startDir,
const QString & filter,
QWidget * parent,
QWidget * widget = 0
AddDialog(const QStringList & itemsToAdd,
const KUrl & startDir,
const QString & filter,
QWidget * parent,
QWidget * widget = 0
);
private:
class AddDialogUI *m_ui;
KConfigGroup m_config;
void loadConfiguration();
void setupIconList(const QStringList& itemsToAdd);
private slots:
void updateDefaultMimeType();
};
}
......
......@@ -2,6 +2,7 @@
* ark -- archiver for the KDE project
*
* Copyright (C) 2008 Harald Hvaal <haraldhv (at@at) stud.ntnu.no>
* Copyright (C) 2009 Raphael Kubo da Costa <kubito@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -24,8 +25,8 @@
#include <QFileInfo>
#include <QDir>
#include <QCoreApplication>
#include <KConfig>
#include <kdebug.h>
#include <kjobtrackerinterface.h>
#include <kmessagebox.h>
......@@ -55,15 +56,16 @@ namespace Kerfuffle
bool ret = dialog.exec();
if (ret) {
kDebug( 1601 ) << "Dialog succeeded, returned url " <<
dialog.selectedUrl();
kDebug( 1601 ) << "Returned URL:" << dialog.selectedUrl();
kDebug( 1601 ) << "Returned mime:" << dialog.currentMimeFilter();
setFilename(dialog.selectedUrl());
setMimeType(dialog.currentMimeFilter());
}
return ret;
}
bool AddToArchive::addInput( const KUrl& url)
bool AddToArchive::addInput( const KUrl& url )
{
m_inputs << url.path(
QFileInfo(url.path()).isDir() ?
......@@ -79,6 +81,8 @@ namespace Kerfuffle
return true;
}
// TODO: If this class should ever be called outside main.cpp,
// the returns should be preceded by emitResult().
void AddToArchive::start( void )
{
kDebug( 1601 );
......@@ -92,7 +96,7 @@ namespace Kerfuffle
Kerfuffle::Archive *archive;
if (!m_filename.isEmpty()) {
archive = Kerfuffle::factory(m_filename);
archive = Kerfuffle::factory(m_filename, m_mimeType);
kDebug( 1601 ) << "Set filename to " + m_filename;
}
else {
......@@ -129,10 +133,10 @@ namespace Kerfuffle
archive = Kerfuffle::factory(finalName, m_mimeType);
}
if (archive == NULL) {
// TODO Post-4.3 string freeze: the check for read-only must cause a separate error
if (archive == NULL || archive->isReadOnly()) {
KMessageBox::error( NULL, i18n("Failed to create the new archive. Permissions might not be sufficient.") );
QCoreApplication::instance()->quit();
return ;
return;
}
if (m_changeToFirstPath) {
......
......@@ -2,6 +2,7 @@
* ark -- archiver for the KDE project
*
* Copyright (C) 2008 Harald Hvaal <haraldhv (at@at) stud.ntnu.no>
* Copyright (C) 2009 Raphael Kubo da Costa <kubito@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -53,6 +54,7 @@ namespace Kerfuffle
public slots:
bool addInput( const KUrl& url);
void setFilename( const KUrl& path ) { m_filename = path.path(); }
void setMimeType( const QString & mimeType ) { m_mimeType = mimeType; }
void setAutoFilenameSuffix( const QString& suffix ) { m_autoFilenameSuffix = suffix; }
void start();
......@@ -64,6 +66,7 @@ namespace Kerfuffle
QString m_strippedPath;
QString m_autoFilenameSuffix;
QString m_firstPath;
QString m_mimeType;
QStringList m_inputs;
bool m_changeToFirstPath;
};
......
......@@ -335,7 +335,9 @@ bool Part::openFile()
Kerfuffle::Archive *archive = Kerfuffle::factory( localFile );
if (!archive) {
// TODO Post 4.3 string freeze:
// the isReadOnly check must be separate; see addtoarchive.cpp
if (!archive || (arguments().metaData()["createNewArchive"] == "true" && !archive->isReadOnly())) {
QStringList mimeTypeList;
QHash<QString, QString> mimeTypes;
......
......@@ -96,7 +96,6 @@ class Part: public KParts::ReadWritePart, public Interface
QList<QVariant> selectedFilesWithChildren();
void registerJob(KJob *job);
QString lastExtractionFolder;
ArchiveModel *m_model;
......
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