summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRagnar Thomsen <[email protected]>2015-10-20 20:25:42 +0200
committerRagnar Thomsen <[email protected]>2015-10-20 20:28:59 +0200
commitb0fbbbd4992f2d4c2379481a27c42445f9beab64 (patch)
tree6d9c2d889f7d69a0e9568b3a4e0013d5010c8b5c
parent11c94a48e076702dae200c216f7edfe891bf9409 (diff)
cli7z: Parse version of p7zip
This will come in handy later. For now just output the version in debug output.
-rw-r--r--plugins/cli7zplugin/cliplugin.cpp27
-rw-r--r--plugins/cli7zplugin/cliplugin.h3
2 files changed, 20 insertions, 10 deletions
diff --git a/plugins/cli7zplugin/cliplugin.cpp b/plugins/cli7zplugin/cliplugin.cpp
index 95d615d..afcbe63 100644
--- a/plugins/cli7zplugin/cliplugin.cpp
+++ b/plugins/cli7zplugin/cliplugin.cpp
@@ -27,6 +27,7 @@
#include <QDateTime>
#include <QDir>
+#include <QRegularExpression>
#include <KPluginFactory>
@@ -37,7 +38,7 @@ K_PLUGIN_FACTORY( CliPluginFactory, registerPlugin< CliPlugin >(); )
CliPlugin::CliPlugin(QObject *parent, const QVariantList & args)
: CliInterface(parent, args)
, m_archiveType(ArchiveType7z)
- , m_parseState(ParseStateHeader)
+ , m_parseState(ParseStateTitle)
{
qCDebug(ARK) << "Loaded cli_7z plugin";
}
@@ -48,7 +49,7 @@ CliPlugin::~CliPlugin()
void CliPlugin::resetParsing()
{
- m_parseState = ParseStateHeader;
+ m_parseState = ParseStateTitle;
}
ParameterList CliPlugin::parameterList() const
@@ -104,8 +105,18 @@ bool CliPlugin::readListLine(const QString& line)
static const QLatin1String archiveInfoDelimiter2("----"); // 7z 9.04
static const QLatin1String entryInfoDelimiter("----------");
- switch (m_parseState) {
- case ParseStateHeader:
+ if (m_parseState == ParseStateTitle) {
+
+ const QRegularExpression rxVersionLine(QStringLiteral("^p7zip Version ([\\d\\.]+) .*$"));
+ QRegularExpressionMatch matchVersion = rxVersionLine.match(line);
+ if (matchVersion.hasMatch()) {
+ m_parseState = ParseStateHeader;
+ const QString p7zipVersion = matchVersion.captured(1);
+ qCDebug(ARK) << "p7zip version" << p7zipVersion << "detected";
+ }
+
+ } else if (m_parseState == ParseStateHeader) {
+
if (line.startsWith(QStringLiteral("Listing archive:"))) {
qCDebug(ARK) << "Archive name: "
<< line.right(line.size() - 16).trimmed();
@@ -115,9 +126,9 @@ bool CliPlugin::readListLine(const QString& line)
} else if (line.contains(QStringLiteral("Error: "))) {
qCWarning(ARK) << line.mid(7);
}
- break;
- case ParseStateArchiveInformation:
+ } else if (m_parseState == ParseStateArchiveInformation) {
+
if (line == entryInfoDelimiter) {
m_parseState = ParseStateEntryInformation;
} else if (line.startsWith(QStringLiteral("Type = "))) {
@@ -145,9 +156,8 @@ bool CliPlugin::readListLine(const QString& line)
}
}
- break;
+ } else if (m_parseState == ParseStateEntryInformation) {
- case ParseStateEntryInformation:
if (line.startsWith(QStringLiteral("Path = "))) {
const QString entryFilename =
QDir::fromNativeSeparators(line.mid(7).trimmed());
@@ -197,7 +207,6 @@ bool CliPlugin::readListLine(const QString& line)
emit entry(m_currentArchiveEntry);
}
}
- break;
}
return true;
diff --git a/plugins/cli7zplugin/cliplugin.h b/plugins/cli7zplugin/cliplugin.h
index 2fd41f8..afe3794 100644
--- a/plugins/cli7zplugin/cliplugin.h
+++ b/plugins/cli7zplugin/cliplugin.h
@@ -50,7 +50,8 @@ private:
} m_archiveType;
enum ParseState {
- ParseStateHeader = 0,
+ ParseStateTitle = 0,
+ ParseStateHeader,
ParseStateArchiveInformation,
ParseStateEntryInformation
} m_parseState;