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

Split cli7zplugin into a header and a source file.

svn path=/trunk/KDE/kdeutils/ark/; revision=956956
parent 1d99a9dc
/*
* ark -- archiver for the KDE project
*
* Copyright (C) 2008 Claudio Bantaloukas <rockdreamer@gmail.com>
* Copyright (C) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
* Copyright (C) 2009 Harald Hvaal <haraldhv@stud.ntnu.no>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -19,144 +18,140 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "kerfuffle/cliinterface.h"
#include "cliplugin.h"
#include "kerfuffle/archivefactory.h"
#include <kdebug.h>
#include "kerfuffle/cliinterface.h"
#include <QDir>
#include <KDebug>
using namespace Kerfuffle;
class CliPlugin: public CliInterface
CliPlugin::CliPlugin( const QString & filename, QObject *parent )
: CliInterface( filename, parent )
, m_state(0)
{
public:
explicit CliPlugin( const QString & filename, QObject *parent = 0 )
: CliInterface( filename, parent ),
m_state(0)
{
}
}
virtual ~CliPlugin()
{
}
CliPlugin::~CliPlugin()
{
protected:
virtual ParameterList parameterList() const
{
static ParameterList p;
if (p.isEmpty()) {
}
//p[CaptureProgress] = true;
p[ListProgram] = p[ExtractProgram] = p[DeleteProgram] = p[AddProgram] = "7z";
ParameterList CliPlugin::parameterList() const
{
static ParameterList p;
p[ListArgs] = QStringList() << "l" << "-slt" << "$Archive";
p[ExtractArgs] = QStringList() << "$PreservePathSwitch" << "$RootNodeSwitch" << "$Archive" << "$Files";
p[PreservePathSwitch] = QStringList() << "x" << "e";
p[RootNodeSwitch] = QStringList() << "-w$Path";
p[FileExistsExpression] = "^(.+) already exists. Overwrite it";
if (p.isEmpty()) {
//p[CaptureProgress] = true;
p[ListProgram] = p[ExtractProgram] = p[DeleteProgram] = p[AddProgram] = "7z";
}
return p;
}
p[ListArgs] = QStringList() << "l" << "-slt" << "$Archive";
p[ExtractArgs] = QStringList() << "$PreservePathSwitch" << "$RootNodeSwitch" << "$Archive" << "$Files";
p[PreservePathSwitch] = QStringList() << "x" << "e";
p[RootNodeSwitch] = QStringList() << "-w$Path";
p[FileExistsExpression] = "^(.+) already exists. Overwrite it";
}
int m_state;
ArchiveEntry m_currentArchiveEntry;
return p;
}
bool readListLine(QString line)
{
switch (m_state)
bool CliPlugin::readListLine(QString line)
{
switch (m_state)
{
case 0: // header
if (line.startsWith("Listing archive:"))
{
case 0: // header
if (line.startsWith("Listing archive:"))
{
kDebug( 1601 ) << "Archive name: " << line.right(line.size() - 16).trimmed() ;
}
else if (line.startsWith("----------"))
{
m_state = 1;
}
else if (line.contains("Error:"))
{
kDebug( 1601 ) << line.mid(6);
//m_errorMessages << line.mid(6);
}
break;
case 1: // beginning of a file detail
if (line.startsWith("Path ="))
{
m_currentArchiveEntry.clear();
QString entryFilename = QDir::fromNativeSeparators(line.mid( 6).trimmed());
m_currentArchiveEntry[FileName] = entryFilename;
m_currentArchiveEntry[InternalID] = entryFilename;
m_state = 2;
}
break;
kDebug( 1601 ) << "Archive name: " << line.right(line.size() - 16).trimmed();
}
else if (line.startsWith("----------"))
{
m_state = 1;
}
else if (line.contains("Error:"))
{
kDebug( 1601 ) << line.mid(6);
//m_errorMessages << line.mid(6);
}
break;
case 1: // beginning of a file detail
if (line.startsWith("Path ="))
{
m_currentArchiveEntry.clear();
QString entryFilename = QDir::fromNativeSeparators(line.mid( 6).trimmed());
m_currentArchiveEntry[FileName] = entryFilename;
m_currentArchiveEntry[InternalID] = entryFilename;
m_state = 2;
}
break;
case 2: // file details
if (line.startsWith("Size = "))
{
m_currentArchiveEntry[ Size ] = line.mid( 7).trimmed();
}
else if (line.startsWith("Packed Size = "))
{
m_currentArchiveEntry[ CompressedSize ] = line.mid( 14).trimmed();
}
else if (line.startsWith("Modified = "))
{
QDateTime ts = QDateTime::fromString(line.mid(11).trimmed(), "yyyy-MM-dd hh:mm:ss");
m_currentArchiveEntry[ Timestamp ] = ts;
}
else if (line.startsWith("Attributes = "))
{
QString attributes = line.mid(13).trimmed();
bool isDirectory = attributes.startsWith('D');
m_currentArchiveEntry[ IsDirectory ] = isDirectory;
if (isDirectory)
{
QString directoryName = m_currentArchiveEntry[FileName].toString();
if (!directoryName.endsWith('/'))
{
m_currentArchiveEntry[FileName] = m_currentArchiveEntry[InternalID] = directoryName + '/';
}
}
m_currentArchiveEntry[ Permissions ] = attributes.mid(1);
}
else if (line.startsWith("CRC = "))
{
m_currentArchiveEntry[ CRC ] = line.mid(6).trimmed();
}
else if (line.startsWith("Method = "))
{
QString method = line.mid(9).trimmed();
m_currentArchiveEntry[ Method ] = method;
}
else if (line.startsWith("Encrypted = ") && line.size() >= 13)
case 2: // file details
if (line.startsWith("Size = "))
{
m_currentArchiveEntry[ Size ] = line.mid( 7).trimmed();
}
else if (line.startsWith("Packed Size = "))
{
m_currentArchiveEntry[ CompressedSize ] = line.mid( 14).trimmed();
}
else if (line.startsWith("Modified = "))
{
QDateTime ts = QDateTime::fromString(line.mid(11).trimmed(), "yyyy-MM-dd hh:mm:ss");
m_currentArchiveEntry[ Timestamp ] = ts;
}
else if (line.startsWith("Attributes = "))
{
QString attributes = line.mid(13).trimmed();
bool isDirectory = attributes.startsWith('D');
m_currentArchiveEntry[ IsDirectory ] = isDirectory;
if (isDirectory)
{
QString directoryName = m_currentArchiveEntry[FileName].toString();
if (!directoryName.endsWith('/'))
{
setPasswordProtected((line.at(12) == '+'));
m_currentArchiveEntry[ IsPasswordProtected ] = isPasswordProtected();
m_currentArchiveEntry[FileName] = m_currentArchiveEntry[InternalID] = directoryName + '/';
}
else if (line.startsWith("Block = "))
{
if (m_currentArchiveEntry.contains(FileName))
{
entry(m_currentArchiveEntry);
}
}
m_state = 1;
}
break;
m_currentArchiveEntry[ Permissions ] = attributes.mid(1);
}
else if (line.startsWith("CRC = "))
{
m_currentArchiveEntry[ CRC ] = line.mid(6).trimmed();
}
else if (line.startsWith("Method = "))
{
QString method = line.mid(9).trimmed();
m_currentArchiveEntry[ Method ] = method;
}
else if (line.startsWith("Encrypted = ") && line.size() >= 13)
{
setPasswordProtected((line.at(12) == '+'));
m_currentArchiveEntry[ IsPasswordProtected ] = isPasswordProtected();
}
else if (line.startsWith("Block = "))
{
if (m_currentArchiveEntry.contains(FileName))
{
entry(m_currentArchiveEntry);
}
default:
break;
m_state = 1;
}
return true;
}
};
break;
default:
break;
}
return true;
}
KERFUFFLE_PLUGIN_FACTORY(CliPlugin)
#include "cliplugin.moc"
/*
* ark -- archiver for the KDE project
*
* Copyright (C) 2009 Harald Hvaal <haraldhv@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
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef CLIPLUGIN_H
#define CLIPLUGIN_H
#include "kerfuffle/cliinterface.h"
class CliPlugin : public Kerfuffle::CliInterface
{
Q_OBJECT
public:
explicit CliPlugin( const QString & filename, QObject *parent = 0 );
virtual ~CliPlugin();
protected:
virtual Kerfuffle::ParameterList parameterList() const;
virtual bool readListLine(QString line);
private:
Kerfuffle::ArchiveEntry m_currentArchiveEntry;
int m_state;
};
#endif // CLIPLUGIN_H
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