Commit 58b55d1a authored by Lukáš Tinkl's avatar Lukáš Tinkl
Browse files

--kdelibs4support, extraction fixes

ark can now successfully extract all archives; adding to up next :)
parent cd875ecf
......@@ -34,8 +34,7 @@
#include "kerfuffle/queries.h"
#include <KDebug>
#include <KGlobal>
#include <KLocale>
#include <KLocalizedString>
#include <KMessageBox>
#include <KRun>
#include <KIO/RenameDialog>
......
......@@ -25,11 +25,10 @@
#include "kerfuffle/archive.h"
#include "part/interface.h"
#include <KPluginLoader>
#include <KPluginFactory>
#include <KMessageBox>
#include <KApplication>
#include <KLocale>
#include <KLocalizedString>
#include <KActionCollection>
#include <KStandardAction>
#include <KFileDialog>
......
......@@ -36,9 +36,9 @@ public:
~MainWindow();
bool loadPart();
void dragEnterEvent(class QDragEnterEvent * event);
void dropEvent(class QDropEvent * event);
void dragMoveEvent(class QDragMoveEvent * event);
void dragEnterEvent(class QDragEnterEvent * event) Q_DECL_OVERRIDE;
void dropEvent(class QDropEvent * event) Q_DECL_OVERRIDE;
void dragMoveEvent(class QDragMoveEvent * event) Q_DECL_OVERRIDE;
public slots:
void openUrl(const QUrl &url);
......
......@@ -32,13 +32,13 @@
#include <KConfigGroup>
#include <KFilePlacesModel>
#include <KGlobal>
#include <KMimeType>
#include <KSharedConfig>
#include <QFileInfo>
#include <QStandardItemModel>
#include <QPushButton>
#include <QIcon>
#include <QMimeDatabase>
namespace Kerfuffle
{
......@@ -69,7 +69,8 @@ AddDialog::AddDialog(const QStringList& itemsToAdd,
connect(okButton(), &QPushButton::clicked, this, &AddDialog::updateDefaultMimeType);
m_ui = new AddDialogUI(this);
// mainWidget()->layout()->addWidget(m_ui);
setExtension(m_ui);
showExtension(true);
setupIconList(itemsToAdd);
......@@ -82,8 +83,7 @@ AddDialog::AddDialog(const QStringList& itemsToAdd,
// #272914: Add an extension when it is present, otherwise KFileDialog
// will not automatically add it as baseFileName is a file which
// already exists.
// FIXME KF5 Port : Enable again
//setSelection(fileName + currentFilterMimeType()->mainExtension());
setSelection(fileName + currentFilterMimeType().preferredSuffix());
}
//These extra options will be implemented in a 4.2+ version of
......@@ -119,7 +119,8 @@ void AddDialog::setupIconList(const QStringList& itemsToAdd)
QStandardItem* item = new QStandardItem;
item->setText(url.fileName());
QString iconName = KMimeType::iconNameForUrl(url);
QMimeDatabase db;
QString iconName = db.mimeTypeForUrl(url).iconName();
item->setIcon(QIcon::fromTheme(iconName));
item->setData(QVariant(url), KFilePlacesModel::UrlRole);
......@@ -135,5 +136,3 @@ void AddDialog::updateDefaultMimeType()
m_config.writeEntry("LastMimeType", currentMimeFilter());
}
}
......@@ -35,7 +35,7 @@
#include <kdebug.h>
#include <kjobtrackerinterface.h>
#include <kmessagebox.h>
#include <klocale.h>
#include <KLocalizedString>
#include <kio/job.h>
#include <QFileInfo>
......@@ -74,14 +74,14 @@ void AddToArchive::setMimeType(const QString & mimeType)
m_mimeType = mimeType;
}
bool AddToArchive::showAddDialog(void)
bool AddToArchive::showAddDialog()
{
QWeakPointer<Kerfuffle::AddDialog> dialog = new Kerfuffle::AddDialog(
m_inputs, // itemsToAdd
QUrl(m_firstPath), // startDir
QLatin1String( "" ), // filter
NULL, // parent
NULL); // widget
Q_NULLPTR, // parent
Q_NULLPTR); // widget
bool ret = dialog.data()->exec();
......
......@@ -33,10 +33,10 @@
#include <QEventLoop>
#include <QFile>
#include <QFileInfo>
#include <QMimeDatabase>
#include <KDebug>
#include <KPluginLoader>
#include <KMimeType>
#include <KMimeTypeTrader>
#include <KServiceTypeTrader>
......@@ -47,8 +47,9 @@ static bool comparePlugins(const KService::Ptr &p1, const KService::Ptr &p2)
static QString determineMimeType(const QString& filename)
{
QMimeDatabase db;
if (!QFile::exists(filename)) {
return KMimeType::findByPath(filename)->name();
return db.mimeTypeForFile(filename).name();
}
QFile file(filename);
......@@ -56,24 +57,26 @@ static QString determineMimeType(const QString& filename)
return QString();
}
const qint64 maxSize = 0x100000; // 1MB
const qint64 bufferSize = qMin(maxSize, file.size());
const QByteArray buffer = file.read(bufferSize);
return KMimeType::findByNameAndContent(filename, buffer)->name();
return db.mimeTypeForFileNameAndData(filename, &file).name();
}
static KService::List findPluginOffers(const QString& filename, const QString& fixedMimeType)
{
KService::List offers;
qDebug() << "Find plugin offers for" << filename << "and mime" << fixedMimeType;
const QString mimeType = fixedMimeType.isEmpty() ? determineMimeType(filename) : fixedMimeType;
qDebug() << "Detected MIME" << mimeType;
if (!mimeType.isEmpty()) {
offers = KMimeTypeTrader::self()->query(mimeType, QLatin1String( "Kerfuffle/Plugin" ), QLatin1String( "(exist Library)" ));
qSort(offers.begin(), offers.end(), comparePlugins);
}
qDebug() << "Have" << offers.count() << "offers";
return offers;
}
......@@ -93,16 +96,16 @@ Archive *Archive::create(const QString &fileName, const QString &fixedMimeType,
if (offers.isEmpty()) {
kDebug() << "Could not find a plugin to handle" << fileName;
return NULL;
return Q_NULLPTR;
}
const QString pluginName = offers.first()->library();
kDebug() << "Loading plugin" << pluginName;
qDebug() << "Loading plugin" << pluginName << "for" << offers.first()->mimeTypes();
KPluginFactory * const factory = KPluginLoader(pluginName).factory();
if (!factory) {
kDebug() << "Invalid plugin factory for" << pluginName;
return NULL;
return Q_NULLPTR;
}
QVariantList args;
......@@ -111,7 +114,7 @@ Archive *Archive::create(const QString &fileName, const QString &fixedMimeType,
ReadOnlyArchiveInterface * const iface = factory->create<ReadOnlyArchiveInterface>(0, args);
if (!iface) {
kDebug() << "Could not create plugin instance" << pluginName << "for" << fileName;
return NULL;
return Q_NULLPTR;
}
return new Archive(iface, parent);
......
......@@ -125,7 +125,7 @@ public:
explicit ReadWriteArchiveInterface(QObject *parent, const QVariantList & args);
virtual ~ReadWriteArchiveInterface();
virtual bool isReadOnly() const;
bool isReadOnly() const Q_DECL_OVERRIDE;
//see archive.h for a list of what the compressionoptions might
//contain
......
......@@ -36,9 +36,8 @@
# include <KPtyProcess>
#endif
#include <KStandardDirs>
#include <KDebug>
#include <KLocale>
#include <KLocalizedString>
#include <QApplication>
#include <QDateTime>
......@@ -48,6 +47,8 @@
#include <QProcess>
#include <QThread>
#include <QTimer>
#include <QStandardPaths>
#include <QUrl>
namespace Kerfuffle
{
......@@ -103,7 +104,8 @@ bool CliInterface::list()
bool CliInterface::copyFiles(const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options)
{
kDebug();
//qDebug() << Q_FUNC_INFO << "to" << destinationDirectory;
cacheParameterList();
m_operationMode = Copy;
......@@ -229,8 +231,9 @@ bool CliInterface::copyFiles(const QList<QVariant> & files, const QString & dest
}
}
kDebug() << "Setting current dir to " << destinationDirectory;
QDir::setCurrent(destinationDirectory);
QUrl destDir(destinationDirectory);
QDir::setCurrent(destDir.adjusted(QUrl::RemoveScheme).url());
//qDebug() << "Setting current dir to " << destinationDirectory;
if (!runProcess(m_param.value(ExtractProgram).toStringList(), args)) {
failOperation();
......@@ -329,14 +332,14 @@ bool CliInterface::runProcess(const QStringList& programNames, const QStringList
{
QString programPath;
for (int i = 0; i < programNames.count(); i++) {
programPath = KStandardDirs::findExe(programNames.at(i));
programPath = QStandardPaths::findExecutable(programNames.at(i));
if (!programPath.isEmpty())
break;
}
if (programPath.isEmpty()) {
const QString names = programNames.join(QLatin1String(", "));
emit error(i18ncp("@info", "Failed to locate program <filename>%2</filename> on disk.",
"Failed to locate programs <filename>%2</filename> on disk.", programNames.count(), names));
emit error(xi18ncp("@info", "Failed to locate program <filename>%2</filename> on disk.",
"Failed to locate programs <filename>%2</filename> on disk.", programNames.count(), names));
emit finished(false);
return false;
}
......
......@@ -234,17 +234,17 @@ public:
explicit CliInterface(QObject *parent, const QVariantList & args);
virtual ~CliInterface();
virtual bool list();
virtual bool copyFiles(const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options);
virtual bool addFiles(const QStringList & files, const CompressionOptions& options);
virtual bool deleteFiles(const QList<QVariant> & files);
virtual bool list() Q_DECL_OVERRIDE;
virtual bool copyFiles(const QList<QVariant> & files, const QString & destinationDirectory, ExtractionOptions options) Q_DECL_OVERRIDE;
virtual bool addFiles(const QStringList & files, const CompressionOptions& options) Q_DECL_OVERRIDE;
virtual bool deleteFiles(const QList<QVariant> & files) Q_DECL_OVERRIDE;
virtual ParameterList parameterList() const = 0;
virtual bool readListLine(const QString &line) = 0;
bool doKill();
bool doSuspend();
bool doResume();
bool doKill() Q_DECL_OVERRIDE;
bool doSuspend() Q_DECL_OVERRIDE;
bool doResume() Q_DECL_OVERRIDE;
/**
* Returns the list of characters which are preceded by a
......@@ -253,7 +253,7 @@ public:
*
* @see setEscapedCharacters().
*/
QString escapedCharacters();
QString escapedCharacters(); // FIXME not implemented?
/**
* Sets which characters will be preceded by a backslash when
......@@ -261,7 +261,7 @@ public:
*
* @see escapedCharacters().
*/
void setEscapedCharacters(const QString& characters);
void setEscapedCharacters(const QString& characters); // FIXME not implemented?
/**
* Sets if the listing should include empty lines.
......
......@@ -28,10 +28,9 @@
#include "extractiondialog.h"
#include "settings.h"
#include <KLocale>
#include <KLocalizedString>
#include <KIconLoader>
#include <KMessageBox>
#include <KStandardDirs>
#include <KDebug>
#include <KIO/NetAccess>
......@@ -52,13 +51,13 @@ public:
};
ExtractionDialog::ExtractionDialog(QWidget *parent)
: KDirSelectDialog(QUrl(), false, parent)
: KDirSelectDialog(QUrl::fromLocalFile(QDir::homePath()), true, parent)
{
m_ui = new ExtractionDialogUI(this);
// mainWidget()->layout()->addWidget(m_ui);
// setCaption(i18nc("@title:window", "Extract"));
m_ui->iconLabel->setPixmap(DesktopIcon(QLatin1String( "archive-extract" )));
setExtension(m_ui);
showExtension(true);
setWindowTitle(i18nc("@title:window", "Extract"));
m_ui->iconLabel->setPixmap(DesktopIcon(QLatin1String("archive-extract")));
m_ui->filesToExtractGroupBox->hide();
m_ui->allFilesButton->setChecked(true);
......@@ -97,7 +96,7 @@ void ExtractionDialog::accept()
{
if (extractToSubfolder()) {
if (subfolder().contains(QLatin1String( "/" ))) {
KMessageBox::error(NULL, i18n("The subfolder name may not contain the character '/'."));
KMessageBox::error(this, i18n("The subfolder name may not contain the character '/'."));
return;
}
......@@ -106,7 +105,7 @@ void ExtractionDialog::accept()
while (1) {
if (KIO::NetAccess::exists(pathWithSubfolder, KIO::NetAccess::SourceSide, 0)) {
if (QFileInfo(pathWithSubfolder).isDir()) {
int overwrite = KMessageBox::questionYesNoCancel(0, i18nc("@info", "The folder <filename>%1</filename> already exists. Are you sure you want to extract here?", pathWithSubfolder), i18n("Folder exists"), KGuiItem(i18n("Extract here")), KGuiItem(i18n("Retry")), KGuiItem(i18n("Cancel")));
int overwrite = KMessageBox::questionYesNoCancel(this, xi18nc("@info", "The folder <filename>%1</filename> already exists. Are you sure you want to extract here?", pathWithSubfolder), i18n("Folder exists"), KGuiItem(i18n("Extract here")), KGuiItem(i18n("Retry")), KGuiItem(i18n("Cancel")));
if (overwrite == KMessageBox::No) {
// The user clicked Retry.
......@@ -115,14 +114,14 @@ void ExtractionDialog::accept()
return;
}
} else {
KMessageBox::detailedError(0,
i18nc("@info", "The folder <filename>%1</filename> could not be created.", subfolder()),
i18nc("@info", "<filename>%1</filename> already exists, but is not a folder.", subfolder()));
KMessageBox::detailedError(this,
xi18nc("@info", "The folder <filename>%1</filename> could not be created.", subfolder()),
xi18nc("@info", "<filename>%1</filename> already exists, but is not a folder.", subfolder()));
return;
}
} else if (!KIO::NetAccess::mkdir(pathWithSubfolder, 0)) {
KMessageBox::detailedError(0,
i18nc("@info", "The folder <filename>%1</filename> could not be created.", subfolder()),
KMessageBox::detailedError(this,
xi18nc("@info", "The folder <filename>%1</filename> could not be created.", subfolder()),
i18n("Please check your permissions to create it."));
return;
}
......
......@@ -60,7 +60,7 @@ public:
bool preservePaths() const;
QUrl destinationDirectory() const;
QString subfolder() const;
virtual void accept();
virtual void accept() Q_DECL_OVERRIDE;
public Q_SLOTS:
void setSubfolder(const QString& subfolder);
......
......@@ -30,7 +30,7 @@
#include <QThread>
#include <KDebug>
#include <KLocale>
#include <KLocalizedString>
//#define DEBUG_RACECONDITION
......@@ -47,7 +47,7 @@ public:
connect(q, SIGNAL(result(KJob*)), SLOT(quit()));
}
virtual void run();
virtual void run() Q_DECL_OVERRIDE;
private:
Job *q;
......@@ -257,7 +257,7 @@ void ExtractJob::doWork()
connectToArchiveInterfaceSignals();
kDebug() << "Starting extraction with selected files:"
qDebug() << "Starting extraction with selected files:"
<< m_files
<< "Destination dir:" << m_destinationDir
<< "Options:" << m_options;
......
......@@ -102,7 +102,7 @@ public:
QString subfolderName() const;
public slots:
virtual void doWork();
virtual void doWork() Q_DECL_OVERRIDE;
private:
bool m_isSingleFolderArchive;
......@@ -126,7 +126,7 @@ public:
ExtractionOptions extractionOptions() const;
public slots:
virtual void doWork();
virtual void doWork() Q_DECL_OVERRIDE;
private:
// TODO: Maybe this should be a method if ExtractionOptions were a class?
......@@ -145,7 +145,7 @@ public:
AddJob(const QStringList& files, const CompressionOptions& options, ReadWriteArchiveInterface *interface, QObject *parent = 0);
public slots:
virtual void doWork();
virtual void doWork() Q_DECL_OVERRIDE;
private:
QStringList m_files;
......@@ -160,7 +160,7 @@ public:
DeleteJob(const QVariantList& files, ReadWriteArchiveInterface *interface, QObject *parent = 0);
public slots:
virtual void doWork();
virtual void doWork() Q_DECL_OVERRIDE;
private:
QVariantList m_files;
......
......@@ -31,7 +31,5 @@
#include <kpluginfactory.h>
#define KERFUFFLE_EXPORT_PLUGIN(p) \
K_PLUGIN_FACTORY( ArkPluginFactory, registerPlugin< p >(); ) \
K_EXPORT_PLUGIN( ArkPluginFactory("p") )
K_PLUGIN_FACTORY( p##PluginFactory, registerPlugin< p >(); )
#endif
......@@ -27,7 +27,7 @@
#include "queries.h"
#include <KLocale>
#include <KLocalizedString>
#include <KPasswordDialog>
#include <kdebug.h>
#include <kio/renamedialog.h>
......@@ -43,7 +43,7 @@ Query::Query()
m_responseMutex.lock();
}
QVariant Query::response()
QVariant Query::response() const
{
return m_data.value(QLatin1String( "response" ));
}
......@@ -59,7 +59,7 @@ void Query::waitForResponse()
m_responseMutex.unlock();
}
void Query::setResponse(QVariant response)
void Query::setResponse(const QVariant &response)
{
kDebug();
......@@ -95,7 +95,7 @@ void OverwriteQuery::execute()
//destUrl.cleanPath();
QWeakPointer<KIO::RenameDialog> dialog = new KIO::RenameDialog(
NULL,
Q_NULLPTR,
i18n("File already exists"),
sourceUrl,
destUrl,
......@@ -177,7 +177,8 @@ void PasswordNeededQuery::execute()
QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
QWeakPointer<KPasswordDialog> dlg = new KPasswordDialog;
dlg.data()->setPrompt(i18nc("@info", "The archive <filename>%1</filename> is password protected. Please enter the password to extract the file.", m_data.value(QLatin1String( "archiveFilename" )).toString()));
dlg.data()->setPrompt(xi18nc("@info", "The archive <filename>%1</filename> is password protected. Please enter the password to extract the file.",
m_data.value(QLatin1String( "archiveFilename" )).toString()));
if (m_data.value(QLatin1String("incorrectTryAgain")).toBool()) {
dlg.data()->showErrorMessage(i18n("Incorrect password, please try again."), KPasswordDialog::PasswordError);
......
......@@ -56,7 +56,7 @@ public:
*/
void waitForResponse();
QVariant response();
QVariant response() const;
protected:
/**
......@@ -65,7 +65,7 @@ protected:
Query();
virtual ~Query() {}
void setResponse(QVariant response);
void setResponse(const QVariant &response);
QueryData m_data;
......@@ -78,7 +78,7 @@ class KERFUFFLE_EXPORT OverwriteQuery : public Query
{
public:
explicit OverwriteQuery(const QString& filename);
void execute();
void execute() Q_DECL_OVERRIDE;
bool responseCancelled();
bool responseOverwriteAll();
bool responseOverwrite();
......@@ -100,7 +100,7 @@ class KERFUFFLE_EXPORT PasswordNeededQuery : public Query
{
public:
explicit PasswordNeededQuery(const QString& archiveFilename, bool incorrectTryAgain = false);
void execute();
void execute() Q_DECL_OVERRIDE;
bool responseCancelled();
QString password();
......
......@@ -25,11 +25,9 @@
#include "kerfuffle/archive.h"
#include "kerfuffle/jobs.h"
#include <KGlobal>
#include <KDebug>
#include <KIconLoader>
#include <KLocale>
#include <KMimeType>
#include <KLocalizedString>
#include <KIO/NetAccess>
#include <QDir>
......@@ -46,8 +44,8 @@ using namespace Kerfuffle;
class ArchiveDirNode;
//used to speed up the loading of large archives
static ArchiveNode* s_previousMatch = NULL;
K_GLOBAL_STATIC(QStringList, s_previousPieces)
static ArchiveNode* s_previousMatch = Q_NULLPTR;
Q_GLOBAL_STATIC(QStringList, s_previousPieces)
// TODO: This class hierarchy needs some love.
......@@ -78,11 +76,13 @@ public:
const QStringList pieces = entry[FileName].toString().split(QLatin1Char( '/' ), QString::SkipEmptyParts);
m_name = pieces.isEmpty() ? QString() : pieces.last();
QMimeDatabase db;
if (entry[IsDirectory].toBool()) {
m_icon = KIconLoader::global()->loadMimeTypeIcon(KMimeType::mimeType(QLatin1String("inode/directory"))->iconName(), KIconLoader::Small);
m_icon = KIconLoader::global()->loadMimeTypeIcon(db.mimeTypeForName("inode/directory").iconName(),
KIconLoader::Small);
} else {
const KMimeType::Ptr mimeType = KMimeType::findByPath(m_entry[FileName].toString(), 0, true);
m_icon = KIconLoader::global()->loadMimeTypeIcon(mimeType->iconName(), KIconLoader::Small);
m_icon = KIconLoader::global()->loadMimeTypeIcon(db.mimeTypeForFile(m_entry[FileName].toString()).iconName(),
KIconLoader::Small);
}
}
......@@ -342,7 +342,7 @@ QVariant ArchiveModel::data(const QModelIndex &index, int role) const
case Timestamp: {
const QDateTime timeStamp = node->entry().value(Timestamp).toDateTime();
return KLocale::global()->formatDateTime(timeStamp);
return QLocale().toString(timeStamp, QLocale::ShortFormat);
}
default:
......
......@@ -45,24 +45,23 @@ public:
ArchiveModel(const QString &dbusPathName, QObject *parent = 0);
~ArchiveModel();
QVariant data(const QModelIndex &index, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) Q_DECL_OVERRIDE;