• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

ark

  • sources
  • kde-4.14
  • kdeutils
  • ark
  • plugins
  • clilhaplugin
clilhaplugin/cliplugin.cpp
Go to the documentation of this file.
1 /*
2  * ark -- archiver for the KDE project
3  *
4  * Copyright (C) 2011 Intzoglou Theofilos <int.teo@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  */
21 
22 #include "cliplugin.h"
23 
24 #include "kerfuffle/kerfuffle_export.h"
25 #include <QDate>
26 #include <QTime>
27 #include <kdebug.h>
28 
29 using namespace Kerfuffle;
30 
31 CliPlugin::CliPlugin(QObject *parent, const QVariantList &args)
32  : CliInterface(parent, args),
33  m_status(Header),
34  m_firstLine(true)
35 {
36 }
37 
38 CliPlugin::~CliPlugin()
39 {
40 }
41 
42 ParameterList CliPlugin::parameterList() const
43 {
44  static ParameterList p;
45  if (p.isEmpty()) {
46  p[CaptureProgress] = true;
47  p[ListProgram] = p[ExtractProgram] = p[DeleteProgram] = p[AddProgram] = QStringList() << QLatin1String("lha");
48 
49  p[ListArgs] = QStringList() << QLatin1String("v") << QLatin1String("-v") << QLatin1String("$Archive");
50  p[ExtractArgs] = QStringList() << QLatin1String("e") << QLatin1String("-v") << QLatin1String("$PreservePathSwitch") << QLatin1String("$Archive") << QLatin1String("$Files");
51 
52  p[DeleteArgs] = QStringList() << QLatin1String("d") << QLatin1String("-v") << QLatin1String("$Archive") << QLatin1String("$Files");
53 
54  p[FileExistsExpression] = QLatin1String("^(.+) OverWrite \\?");
55  p[FileExistsMode] = 1; // Watch for messages in stdout
56  p[FileExistsInput] = QStringList()
57  << QLatin1String("Y") //overwrite
58  << QLatin1String("N") //skip
59  << QLatin1String("A") //overwrite all
60  << QLatin1String("S") //autoskip
61  ;
62 
63  p[AddArgs] = QStringList() << QLatin1String("a") << QLatin1String("-v") << QLatin1String("$Archive") << QLatin1String("$Files");
64 
65  p[ExtractionFailedPatterns] = QStringList() << QLatin1String("Error");
66  p[PreservePathSwitch] = QStringList() << QLatin1String( "" ) << QLatin1String( "-i" );
67  }
68  return p;
69 }
70 
71 bool CliPlugin::readListLine(const QString &line)
72 {
73  const QString m_headerString = QLatin1String("----------");
74 
75  switch(m_status) {
76  case Header:
77  if (line.startsWith(m_headerString)) {
78  m_status = Entry;
79  m_firstLine = true;
80  }
81  break;
82  case Entry:
83  const QStringList entryList = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
84 
85  if (m_firstLine) { // This line will contain the filename
86  if (entryList.count() == 8) { // End of entries
87  m_status = Header;
88  }
89  else {
90  m_internalId = line;
91  m_firstLine = false;
92  }
93  }
94  else { // This line contains the rest of the information
95  ArchiveEntry e;
96 
97  if (!entryList[0].startsWith(QLatin1Char('['))) {
98  e[Permissions] = entryList[0];
99  }
100 
101  e[IsDirectory] = m_internalId.endsWith(QLatin1Char('/'));
102  m_entryFilename = m_internalId;
103  e[FileName] = m_entryFilename;
104  e[InternalID] = m_internalId;
105 
106  if (entryList.count() == 9) { // UID/GID is missing
107  e[CompressedSize] = entryList[1];
108  e[Size] = entryList[2];
109  e[Ratio] = entryList[3];
110  e[Method] = entryList[4];
111  e[CRC] = entryList[5];
112 
113  QDateTime timestamp(
114  QDate::fromString(entryList[6], QLatin1String("yyyy-MM-dd")),
115  QTime::fromString(entryList[7], QLatin1String("HH:mm:ss")));
116  e[Timestamp] = timestamp;
117  emit entry(e);
118  }
119  else if (entryList.count() == 10) { // All info is available
120  const QStringList ownerList = entryList[1].split(QLatin1Char('/')); // Separate uid from gui
121  e[Owner] = ownerList.at(0);
122  e[Group] = ownerList.at(1);
123  e[CompressedSize] = entryList[2];
124  e[Size] = entryList[3];
125  e[Ratio] = entryList[4];
126  e[Method] = entryList[5];
127  e[CRC] = entryList[6];
128 
129  QDateTime timestamp(
130  QDate::fromString(entryList[7], QLatin1String("yyyy-MM-dd")),
131  QTime::fromString(entryList[8], QLatin1String("HH:mm:ss")));
132  e[Timestamp] = timestamp;
133  emit entry(e);
134  }
135 
136  m_firstLine = true;
137  }
138  break;
139  }
140  return true;
141 }
142 
143 KERFUFFLE_EXPORT_PLUGIN(CliPlugin)
144 
Kerfuffle::Ratio
The compression ratio for the entry.
Definition: archive.h:67
Kerfuffle::Owner
The user the entry belongs to.
Definition: archive.h:62
Kerfuffle::ExtractionFailedPatterns
QStringList Default: empty A list of regexp patterns that will cause the extraction to exit with a ge...
Definition: cliinterface.h:194
Kerfuffle::ExtractProgram
QStringList The names to the program that will handle extracting of this archive (eg "rar")...
Definition: cliinterface.h:84
Kerfuffle::FileExistsMode
int This sets on what output channel the FileExistsExpression regex should be applied on...
Definition: cliinterface.h:157
Kerfuffle::IsDirectory
The entry is a directory.
Definition: archive.h:72
Kerfuffle::AddProgram
QStringList The names to the program that will handle adding in this archive format (eg "rar")...
Definition: cliinterface.h:210
kerfuffle_export.h
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
Kerfuffle::CliInterface
Definition: cliinterface.h:224
CliPlugin
Definition: cli7zplugin/cliplugin.h:29
Kerfuffle::ListArgs
QStringList The arguments that are passed to the program above for listing the archive.
Definition: cliinterface.h:75
QList::at
const T & at(int i) const
Kerfuffle::CompressedSize
The compressed size for the entry.
Definition: archive.h:65
QTime::fromString
QTime fromString(const QString &string, Qt::DateFormat format)
Kerfuffle::ReadOnlyArchiveInterface::entry
void entry(const ArchiveEntry &archiveEntry)
QDate::fromString
QDate fromString(const QString &string, Qt::DateFormat format)
QList::count
int count(const T &value) const
Kerfuffle::ArchiveEntry
QHash< int, QVariant > ArchiveEntry
Definition: archive.h:78
CliPlugin::parameterList
virtual Kerfuffle::ParameterList parameterList() const
Definition: cli7zplugin/cliplugin.cpp:47
Kerfuffle::PreservePathSwitch
QStringList This should be a qstringlist with either two elements.
Definition: cliinterface.h:122
QHash
QObject
cliplugin.h
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
Kerfuffle::ExtractArgs
QStringList The arguments that are passed to the program above for extracting the archive...
Definition: cliinterface.h:100
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
Kerfuffle::FileExistsExpression
QString This is a regexp, defining how to recognize a "File already exists" prompt when extracting...
Definition: cliinterface.h:148
CliPlugin::CliPlugin
CliPlugin(QObject *parent, const QVariantList &args)
Definition: cli7zplugin/cliplugin.cpp:36
QString
Kerfuffle::Timestamp
The timestamp for the current entry.
Definition: archive.h:71
CliPlugin::~CliPlugin
virtual ~CliPlugin()
Definition: cli7zplugin/cliplugin.cpp:43
QStringList
Kerfuffle::FileName
The entry's file name.
Definition: archive.h:59
Kerfuffle::CRC
The entry's CRC.
Definition: archive.h:68
QLatin1Char
Kerfuffle::CaptureProgress
Bool (default false) Will look for the %-sign in the stdout while working, in the form of (2%...
Definition: cliinterface.h:51
Kerfuffle::Permissions
The entry's permissions.
Definition: archive.h:61
Kerfuffle::DeleteArgs
QStringList The arguments that are passed to the program above for deleting from the archive...
Definition: cliinterface.h:187
Kerfuffle::DeleteProgram
QStringList The names to the program that will handle deleting of elements in this archive format (eg...
Definition: cliinterface.h:178
QLatin1String
QHash::isEmpty
bool isEmpty() const
Kerfuffle::FileExistsInput
QStringList The various responses that can be supplied as a response to the "file exists" prompt...
Definition: cliinterface.h:169
Kerfuffle::Method
The compression method used on the entry.
Definition: archive.h:69
Kerfuffle::Size
The entry's original size.
Definition: archive.h:64
Kerfuffle::AddArgs
QStringList The arguments that are passed to the program above for adding to the archive.
Definition: cliinterface.h:219
CliPlugin::readListLine
virtual bool readListLine(const QString &line)
Definition: cli7zplugin/cliplugin.cpp:78
QStringList::split
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
KERFUFFLE_EXPORT_PLUGIN
#define KERFUFFLE_EXPORT_PLUGIN(p)
Definition: kerfuffle_export.h:49
Kerfuffle::Group
The user group the entry belongs to.
Definition: archive.h:63
Kerfuffle::InternalID
The entry's ID for Ark's internal manipulation.
Definition: archive.h:60
QDateTime
Kerfuffle::ListProgram
QStringList The names to the program that will handle listing of this archive (eg "rar")...
Definition: cliinterface.h:67
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:37 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ark

Skip menu "ark"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal