Commit e0be4299 authored by Toni Asensi Esteve's avatar Toni Asensi Esteve
Browse files

First steps to normalize some compressed file types and to deduplicate code in...

First steps to normalize some compressed file types and to deduplicate code in krarc.cpp and krarchandler.cpp.

Review D1707

Note: This doesn't fix the task T2768
parent fce43a62
......@@ -721,8 +721,10 @@ void kio_krarcProtocol::copy(const QUrl &url, const QUrl &dest, int, KIO::JobFla
QDir::setCurrent(destDir);
QString escapedFilename = file;
if(arcType == "zip") // left bracket needs to be escaped
if(arcType == "zip") {
// left bracket needs to be escaped
escapedFilename.replace("[", "[[]");
}
KrLinecountingProcess proc;
proc << copyCmd << getPath(arcFile->url(), QUrl::StripTrailingSlash) << escapedFilename;
......@@ -888,8 +890,7 @@ bool kio_krarcProtocol::setArcFile(const QUrl &url)
if (arcType.isEmpty()) {
arcType = arcFile->mimetype();
arcType = arcType.mid(arcType.lastIndexOf("-") + 1);
arcType = getShortTypeFromMime(arcType);
if (arcType == "jar")
arcType = "zip";
}
......
......@@ -32,6 +32,7 @@ KrArcBaseManager::AutoDetectParams KrArcBaseManager::autoDetectParams[] = {{"zip
};
int KrArcBaseManager::autoDetectElems = sizeof(autoDetectParams) / sizeof(AutoDetectParams);
const int KrArcBaseManager::maxLenType = 5;
QString KrArcBaseManager::detectArchive(bool &encrypted, QString fileName, bool checkEncrypted, bool fast)
{
......@@ -173,3 +174,37 @@ QString KrArcBaseManager::detectArchive(bool &encrypted, QString fileName, bool
return QString();
}
//! Returns a short identifier of the type of a file, obtained from the mime type of the file
/*!
\param mime The mime type of the file.
\return A short QString which contains an identifier of the type of the file.
*/
QString KrArcBaseManager::getShortTypeFromMime(const QString &mime)
{
// 7zip files are a not a normal case because their mimetype does not
// follow the norm of other types: zip, tar, lha, ace, arj, etc.
if (mime == "application/x-7z-compressed")
return "7z";
// If it's a rar file but its mimetype isn't "application/x-rar"
if (mime == "application/x-rar-compressed")
return "rar";
// The short type that will be returned
QString sType = mime;
int lastHyphen = sType.lastIndexOf('-');
if (lastHyphen != -1)
sType = sType.mid(lastHyphen + 1);
else {
int lastSlash = sType.lastIndexOf('/');
if (lastSlash != -1)
sType = sType.mid(lastSlash + 1);
}
// The identifier kept short
if (sType.length() > maxLenType)
sType = sType.right(maxLenType);
return sType;
}
......@@ -36,10 +36,15 @@ private:
static AutoDetectParams autoDetectParams[]; //! Information used to detect if a file is an archive
static int autoDetectElems; //!< The size of autoDetectParams[]
protected:
//! The maximum length of a short QString that represents the type of a file
static const int maxLenType;
public:
KrArcBaseManager() {}
QString detectArchive(bool &, QString, bool = true, bool = false);
virtual void checkIf7zIsEncrypted(bool &, QString) = 0;
static QString getShortTypeFromMime(const QString &);
virtual ~KrArcBaseManager() {}
};
......
......@@ -328,7 +328,8 @@ CreateChecksumDlg::CreateChecksumDlg(const QStringList& files, bool containFolde
proc.start();
// TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking
// it would be better to connect to started(), error() and finished()
if (proc.waitForStarted()) while (proc.state() == QProcess::Running) {
if (proc.waitForStarted())
while (proc.state() == QProcess::Running) {
usleep(500);
qApp->processEvents();
if (krApp->wasWaitingCancelled()) { // user cancelled
......@@ -472,7 +473,8 @@ MatchChecksumDlg::MatchChecksumDlg(const QStringList& files, bool containFolders
proc.start();
// TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking
// it would be better to connect to started(), error() and finished()
if (proc.waitForStarted()) while (proc.state() == QProcess::Running) {
if (proc.waitForStarted())
while (proc.state() == QProcess::Running) {
usleep(500);
qApp->processEvents();
if (krApp->wasWaitingCancelled()) { // user cancelled
......
......@@ -165,7 +165,7 @@ void KRSearchMod::scanLocalDir(QUrl urlToScan)
QString realType = arcHandler.getType(encrypted, url.path(), mime);
if (!encrypted) {
if (realType == "-tbz" || realType == "-tgz" || realType == "tarz" || realType == "-tar" || realType == "-tlz")
if (realType == "tbz" || realType == "tgz" || realType == "tarz" || realType == "tar" || realType == "tlz")
archiveURL.setScheme("tar");
else
archiveURL.setScheme("krarc");
......
This diff is collapsed.
......@@ -88,6 +88,7 @@ public:
private:
// checks if the returned status is correct
static bool checkStatus(QString type, int exitCode);
static bool openWallet();
static KWallet::Wallet * wallet;
......
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