Commit d1e81828 authored by Ragnar Thomsen's avatar Ragnar Thomsen
Browse files

QLatin1String -> QStringLiteral in 7z and zip plugins

Replace usage of QLatin1String with QStringLiteral in clizip and cli7z
plugins where sensible, to avoid generation of QStrings at runtime.
parent 72e363ac
......@@ -28,8 +28,6 @@
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QLatin1String>
#include <QString>
#include <KPluginFactory>
......@@ -57,40 +55,40 @@ ParameterList CliPlugin::parameterList() const
if (p.isEmpty()) {
//p[CaptureProgress] = true;
p[ListProgram] = p[ExtractProgram] = p[DeleteProgram] = p[AddProgram] = QStringList() << QLatin1String( "7z" )
<< QLatin1String( "7za" )
<< QLatin1String( "7zr" );
p[ListArgs] = QStringList() << QLatin1String( "l" )
<< QLatin1String( "-slt" )
<< QLatin1String("$PasswordSwitch")
<< QLatin1String( "$Archive" );
p[ExtractArgs] = QStringList() << QLatin1String( "$PreservePathSwitch" )
<< QLatin1String( "$PasswordSwitch" )
<< QLatin1String( "$Archive" )
<< QLatin1String( "$Files" );
p[PreservePathSwitch] = QStringList() << QLatin1String( "x" )
<< QLatin1String( "e" );
p[PasswordSwitch] = QStringList() << QLatin1String( "-p$Password" );
p[EncryptHeaderSwitch] = QStringList() << QLatin1String("-mhe=$Enabled");
p[WrongPasswordPatterns] = QStringList() << QLatin1String( "Wrong password" );
p[AddArgs] = QStringList() << QLatin1String( "a" )
<< QLatin1String( "$Archive" )
<< QLatin1String("$EncryptHeaderSwitch")
<< QLatin1String( "$PasswordSwitch" )
<< QLatin1String( "$Files" );
p[DeleteArgs] = QStringList() << QLatin1String( "d" )
<< QLatin1String( "$Archive" )
<< QLatin1String( "$Files" );
p[FileExistsExpression] = QLatin1String( "^\\(Y\\)es / \\(N\\)o / \\(A\\)lways / \\(S\\)kip all / A\\(u\\)to rename all / \\(Q\\)uit\\? $" );
p[FileExistsFileName] = QStringList() << QLatin1String("^file \\./(.*)$");
p[FileExistsInput] = QStringList() << QLatin1String( "Y" ) //overwrite
<< QLatin1String( "N" ) //skip
<< QLatin1String( "A" ) //overwrite all
<< QLatin1String( "S" ) //autoskip
<< QLatin1String( "Q" ); //cancel
p[PasswordPromptPattern] = QLatin1String("Enter password \\(will not be echoed\\) :");
p[ListProgram] = p[ExtractProgram] = p[DeleteProgram] = p[AddProgram] = QStringList() << QStringLiteral("7z")
<< QStringLiteral("7za")
<< QStringLiteral("7zr");
p[ListArgs] = QStringList() << QStringLiteral("l")
<< QStringLiteral("-slt")
<< QStringLiteral("$PasswordSwitch")
<< QStringLiteral("$Archive");
p[ExtractArgs] = QStringList() << QStringLiteral("$PreservePathSwitch")
<< QStringLiteral("$PasswordSwitch")
<< QStringLiteral("$Archive")
<< QStringLiteral("$Files");
p[PreservePathSwitch] = QStringList() << QStringLiteral("x")
<< QStringLiteral("e");
p[PasswordSwitch] = QStringList() << QStringLiteral("-p$Password");
p[EncryptHeaderSwitch] = QStringList() << QStringLiteral("-mhe=$Enabled");
p[WrongPasswordPatterns] = QStringList() << QStringLiteral("Wrong password");
p[AddArgs] = QStringList() << QStringLiteral("a")
<< QStringLiteral("$Archive")
<< QStringLiteral("$EncryptHeaderSwitch")
<< QStringLiteral("$PasswordSwitch")
<< QStringLiteral("$Files");
p[DeleteArgs] = QStringList() << QStringLiteral("d")
<< QStringLiteral("$Archive")
<< QStringLiteral("$Files");
p[FileExistsExpression] = QStringLiteral("^\\(Y\\)es / \\(N\\)o / \\(A\\)lways / \\(S\\)kip all / A\\(u\\)to rename all / \\(Q\\)uit\\? $");
p[FileExistsFileName] = QStringList() << QStringLiteral("^file \\./(.*)$");
p[FileExistsInput] = QStringList() << QStringLiteral("Y") //overwrite
<< QStringLiteral("N") //skip
<< QStringLiteral("A") //overwrite all
<< QStringLiteral("S") //autoskip
<< QStringLiteral("Q"); //cancel
p[PasswordPromptPattern] = QStringLiteral("Enter password \\(will not be echoed\\) :");
}
return p;
......@@ -104,13 +102,13 @@ bool CliPlugin::readListLine(const QString& line)
switch (m_state) {
case ReadStateHeader:
if (line.startsWith(QLatin1String("Listing archive:"))) {
if (line.startsWith(QStringLiteral("Listing archive:"))) {
qCDebug(KERFUFFLE_PLUGIN) << "Archive name: "
<< line.right(line.size() - 16).trimmed();
} else if ((line == archiveInfoDelimiter1) ||
(line == archiveInfoDelimiter2)) {
m_state = ReadStateArchiveInformation;
} else if (line.contains(QLatin1String( "Error: " ))) {
} else if (line.contains(QStringLiteral("Error: "))) {
qCWarning(KERFUFFLE_PLUGIN) << line.mid(7);
}
break;
......@@ -118,7 +116,7 @@ bool CliPlugin::readListLine(const QString& line)
case ReadStateArchiveInformation:
if (line == entryInfoDelimiter) {
m_state = ReadStateEntryInformation;
} else if (line.startsWith(QLatin1String("Type = "))) {
} else if (line.startsWith(QStringLiteral("Type = "))) {
const QString type = line.mid(7).trimmed();
qCDebug(KERFUFFLE_PLUGIN) << "Archive type: " << type;
......@@ -142,51 +140,51 @@ bool CliPlugin::readListLine(const QString& line)
break;
case ReadStateEntryInformation:
if (line.startsWith(QLatin1String("Path = "))) {
if (line.startsWith(QStringLiteral("Path = "))) {
const QString entryFilename =
QDir::fromNativeSeparators(line.mid(7).trimmed());
m_currentArchiveEntry.clear();
m_currentArchiveEntry[FileName] = entryFilename;
m_currentArchiveEntry[InternalID] = entryFilename;
} else if (line.startsWith(QLatin1String("Size = "))) {
} else if (line.startsWith(QStringLiteral("Size = "))) {
m_currentArchiveEntry[ Size ] = line.mid(7).trimmed();
} else if (line.startsWith(QLatin1String("Packed Size = "))) {
} else if (line.startsWith(QStringLiteral("Packed Size = "))) {
// #236696: 7z files only show a single Packed Size value
// corresponding to the whole archive.
if (m_archiveType != ArchiveType7z) {
m_currentArchiveEntry[CompressedSize] = line.mid(14).trimmed();
}
} else if (line.startsWith(QLatin1String("Modified = "))) {
} else if (line.startsWith(QStringLiteral("Modified = "))) {
m_currentArchiveEntry[ Timestamp ] =
QDateTime::fromString(line.mid(11).trimmed(),
QLatin1String( "yyyy-MM-dd hh:mm:ss" ));
} else if (line.startsWith(QLatin1String("Attributes = "))) {
QStringLiteral("yyyy-MM-dd hh:mm:ss"));
} else if (line.startsWith(QStringLiteral("Attributes = "))) {
const QString attributes = line.mid(13).trimmed();
const bool isDirectory = attributes.startsWith(QLatin1Char( 'D' ));
const bool isDirectory = attributes.startsWith(QLatin1Char('D'));
m_currentArchiveEntry[ IsDirectory ] = isDirectory;
if (isDirectory) {
const QString directoryName =
m_currentArchiveEntry[FileName].toString();
if (!directoryName.endsWith(QLatin1Char( '/' ))) {
const bool isPasswordProtected = (line.at(12) == QLatin1Char( '+' ));
if (!directoryName.endsWith(QLatin1Char('/'))) {
const bool isPasswordProtected = (line.at(12) == QLatin1Char('+'));
m_currentArchiveEntry[FileName] =
m_currentArchiveEntry[InternalID] = QString(directoryName + QLatin1Char( '/' ));
m_currentArchiveEntry[InternalID] = QString(directoryName + QLatin1Char('/'));
m_currentArchiveEntry[ IsPasswordProtected ] =
isPasswordProtected;
}
}
m_currentArchiveEntry[ Permissions ] = attributes.mid(1);
} else if (line.startsWith(QLatin1String("CRC = "))) {
} else if (line.startsWith(QStringLiteral("CRC = "))) {
m_currentArchiveEntry[ CRC ] = line.mid(6).trimmed();
} else if (line.startsWith(QLatin1String("Method = "))) {
} else if (line.startsWith(QStringLiteral("Method = "))) {
m_currentArchiveEntry[ Method ] = line.mid(9).trimmed();
} else if (line.startsWith(QLatin1String("Encrypted = ")) &&
} else if (line.startsWith(QStringLiteral("Encrypted = ")) &&
line.size() >= 13) {
m_currentArchiveEntry[ IsPasswordProtected ] = (line.at(12) == QLatin1Char( '+' ));
} else if (line.startsWith(QLatin1String("Block = ")) ||
line.startsWith(QLatin1String("Version = "))) {
m_currentArchiveEntry[ IsPasswordProtected ] = (line.at(12) == QLatin1Char('+'));
} else if (line.startsWith(QStringLiteral("Block = ")) ||
line.startsWith(QStringLiteral("Version = "))) {
if (m_currentArchiveEntry.contains(FileName)) {
emit entry(m_currentArchiveEntry);
}
......
......@@ -76,39 +76,39 @@ ParameterList CliPlugin::parameterList() const
if (p.isEmpty()) {
p[CaptureProgress] = false;
p[ListProgram] = QStringList() << QLatin1String("zipinfo");
p[ExtractProgram] = QStringList() << QLatin1String("unzip");
p[DeleteProgram] = p[AddProgram] = QStringList() << QLatin1String("zip");
p[ListArgs] = QStringList() << QLatin1String("-l")
<< QLatin1String("-T")
<< QLatin1String("$Archive");
p[ExtractArgs] = QStringList() << QLatin1String("$PreservePathSwitch")
<< QLatin1String("$PasswordSwitch")
<< QLatin1String("$Archive")
<< QLatin1String("$Files");
p[PreservePathSwitch] = QStringList() << QLatin1String("")
<< QLatin1String("-j");
p[PasswordSwitch] = QStringList() << QLatin1String("-P$Password");
p[DeleteArgs] = QStringList() << QLatin1String("-d")
<< QLatin1String("$Archive")
<< QLatin1String("$Files");
p[FileExistsExpression] = QLatin1String("^replace (.+)\\? \\[y\\]es, \\[n\\]o, \\[A\\]ll, \\[N\\]one, \\[r\\]ename: $");
p[ListProgram] = QStringList() << QStringLiteral("zipinfo");
p[ExtractProgram] = QStringList() << QStringLiteral("unzip");
p[DeleteProgram] = p[AddProgram] = QStringList() << QStringLiteral("zip");
p[ListArgs] = QStringList() << QStringLiteral("-l")
<< QStringLiteral("-T")
<< QStringLiteral("$Archive");
p[ExtractArgs] = QStringList() << QStringLiteral("$PreservePathSwitch")
<< QStringLiteral("$PasswordSwitch")
<< QStringLiteral("$Archive")
<< QStringLiteral("$Files");
p[PreservePathSwitch] = QStringList() << QStringLiteral("")
<< QStringLiteral("-j");
p[PasswordSwitch] = QStringList() << QStringLiteral("-P$Password");
p[DeleteArgs] = QStringList() << QStringLiteral("-d")
<< QStringLiteral("$Archive")
<< QStringLiteral("$Files");
p[FileExistsExpression] = QStringLiteral("^replace (.+)\\? \\[y\\]es, \\[n\\]o, \\[A\\]ll, \\[N\\]one, \\[r\\]ename: $");
p[FileExistsFileName] = QStringList() << p[FileExistsExpression].toString();
p[FileExistsInput] = QStringList() << QLatin1String("y") //overwrite
<< QLatin1String("n") //skip
<< QLatin1String("A") //overwrite all
<< QLatin1String("N"); //autoskip
p[AddArgs] = QStringList() << QLatin1String("-r")
<< QLatin1String("$Archive")
<< QLatin1String("$PasswordSwitch")
<< QLatin1String("$Files");
p[PasswordPromptPattern] = QLatin1String(" password: ");
p[WrongPasswordPatterns] = QStringList() << QLatin1String("incorrect password");
p[FileExistsInput] = QStringList() << QStringLiteral("y") //overwrite
<< QStringLiteral("n") //skip
<< QStringLiteral("A") //overwrite all
<< QStringLiteral("N"); //autoskip
p[AddArgs] = QStringList() << QStringLiteral("-r")
<< QStringLiteral("$Archive")
<< QStringLiteral("$PasswordSwitch")
<< QStringLiteral("$Files");
p[PasswordPromptPattern] = QStringLiteral(" password: ");
p[WrongPasswordPatterns] = QStringList() << QStringLiteral("incorrect password");
//p[ExtractionFailedPatterns] = QStringList() << "CRC failed";
}
return p;
......@@ -116,7 +116,7 @@ ParameterList CliPlugin::parameterList() const
bool CliPlugin::readListLine(const QString &line)
{
static const QRegularExpression entryPattern(QLatin1String(
static const QRegularExpression entryPattern(QStringLiteral(
"^(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\d{8}).(\\d{6})\\s+(.+)$") );
switch (m_status) {
......@@ -140,8 +140,8 @@ bool CliPlugin::readListLine(const QString &line)
}
e[CompressedSize] = rxMatch.captured(6).toInt();
const QDateTime ts(QDate::fromString(rxMatch.captured(8), QLatin1String( "yyyyMMdd" )),
QTime::fromString(rxMatch.captured(9), QLatin1String( "hhmmss" )));
const QDateTime ts(QDate::fromString(rxMatch.captured(8), QStringLiteral("yyyyMMdd")),
QTime::fromString(rxMatch.captured(9), QStringLiteral("hhmmss")));
e[Timestamp] = ts;
e[FileName] = e[InternalID] = rxMatch.captured(10);
......
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