• 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
  • cliplugin-example
cliplugin-example/cliplugin.cpp
Go to the documentation of this file.
1 /*
2  * ark -- archiver for the KDE project
3  *
4  * Copyright (C) 2008 Claudio Bantaloukas <rockdreamer@gmail.com>
5  * Copyright (C) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "cliplugin.h"
24 #include "kerfuffle/kerfuffle_export.h"
25 
26 #include <kdebug.h>
27 
28 #include <QDir>
29 #include <QDate>
30 #include <QTime>
31 
32 CliPlugin::CliPlugin(QObject *parent, const QVariantList &args)
33  : CliInterface(parent, args),
34  m_isFirstLine(true),
35  m_incontent(false),
36  m_isPasswordProtected(false)
37 {
38 }
39 
40 CliPlugin::~CliPlugin()
41 {
42 }
43 
44 ParameterList CliPlugin::parameterList() const
45 {
46  static ParameterList p;
47 
48  if (p.isEmpty()) {
49  p[CaptureProgress] = true;
50  p[ListProgram] = p[ExtractProgram] = p[DeleteProgram] = p[AddProgram] = QLatin1String("rar");
51 
52  p[ListArgs] = QStringList() << QLatin1String("v") << QLatin1String("-c-") << QLatin1String("$Archive");
53  p[ExtractArgs] = QStringList() << QLatin1String("-p-") << QLatin1String("$PreservePathSwitch") << QLatin1String("$PasswordSwitch") << QLatin1String("$RootNodeSwitch") << QLatin1String("$Archive") << QLatin1String("$Files");
54  p[PreservePathSwitch] = QStringList() << QLatin1String("x") << QLatin1String("e");
55  p[RootNodeSwitch] = QStringList() << QLatin1String("-ap$Path");
56  p[PasswordSwitch] = QStringList() << QLatin1String("-p$Password");
57 
58  p[DeleteArgs] = QStringList() << QLatin1String("d") << QLatin1String("$Archive") << QLatin1String("$Files");
59 
60  p[FileExistsExpression] = QLatin1String("^(.+) already exists. Overwrite it");
61  p[FileExistsInput] = QStringList()
62  << QLatin1String("Y") //overwrite
63  << QLatin1String("N") //skip
64  << QLatin1String("A") //overwrite all
65  << QLatin1String("E") //autoskip
66  << QLatin1String("Q") //cancel
67  ;
68 
69  p[AddArgs] = QStringList() << QLatin1String("a") << QLatin1String("$Archive") << QLatin1String("$Files");
70 
71  p[WrongPasswordPatterns] = QStringList() << QLatin1String("password incorrect");
72  p[ExtractionFailedPatterns] = QStringList() << QLatin1String("CRC failed");
73  }
74 
75  return p;
76 }
77 
78 bool CliPlugin::readListLine(const QString &line)
79 {
80  const QString m_headerString = QLatin1String("-----------------------------------------");
81 
82  // skip the heading
83  if (!m_incontent) {
84  if (line.startsWith(m_headerString)) {
85  m_incontent = true;
86  }
87  return true;
88  }
89 
90  // catch final line
91  if (line.startsWith(m_headerString)) {
92  m_incontent = false;
93  return true;
94  }
95 
96  // rar gives one line for the filename and a line after it with some file properties
97  if (m_isFirstLine) {
98  m_internalId = line.trimmed();
99  //m_entryFilename.chop(1); // handle newline
100  if (!m_internalId.isEmpty() && m_internalId.at(0) == QLatin1Char('*')) {
101  m_isPasswordProtected = true;
102  m_internalId.remove(0, 1); // and the spaces in front
103  } else
104  m_isPasswordProtected = false;
105 
106  m_isFirstLine = false;
107  return true;
108  }
109 
110  QStringList fileprops = line.split(QLatin1Char(' '), QString::SkipEmptyParts);
111  m_internalId = QDir::fromNativeSeparators(m_internalId);
112  bool isDirectory = (bool)(fileprops[ 5 ].contains(QLatin1Char('d'), Qt::CaseInsensitive));
113 
114  QDateTime ts(QDate::fromString(fileprops[ 3 ], QLatin1String("dd-MM-yy")),
115  QTime::fromString(fileprops[ 4 ], QLatin1String("hh:mm")));
116  // rar output date with 2 digit year but QDate takes is as 19??
117  // let's take 1950 is cut-off; similar to KDateTime
118  if (ts.date().year() < 1950) {
119  ts = ts.addYears(100);
120  }
121 
122  m_entryFilename = m_internalId;
123  if (isDirectory && !m_internalId.endsWith(QLatin1Char('/'))) {
124  m_entryFilename += QLatin1Char('/');
125  }
126 
127  //kDebug() << m_entryFilename << " : " << fileprops;
128  ArchiveEntry e;
129  e[ FileName ] = m_entryFilename;
130  e[ InternalID ] = m_internalId;
131  e[ Size ] = fileprops[ 0 ];
132  e[ CompressedSize] = fileprops[ 1 ];
133  e[ Ratio ] = fileprops[ 2 ];
134  e[ Timestamp ] = ts;
135  e[ IsDirectory ] = isDirectory;
136  e[ Permissions ] = fileprops[ 5 ].remove(0, 1);
137  e[ CRC ] = fileprops[ 6 ];
138  e[ Method ] = fileprops[ 7 ];
139  e[ Version ] = fileprops[ 8 ];
140  e[ IsPasswordProtected] = m_isPasswordProtected;
141  kDebug() << "Added entry: " << e;
142 
143  emit entry(e);
144  m_isFirstLine = true;
145  return true;
146 }
147 
148 KERFUFFLE_EXPORT_PLUGIN(CliPlugin)
Kerfuffle::Ratio
The compression ratio for the entry.
Definition: archive.h:67
Kerfuffle::ExtractionFailedPatterns
QStringList Default: empty A list of regexp patterns that will cause the extraction to exit with a ge...
Definition: cliinterface.h:194
QList::remove
iterator remove(iterator pos)
Kerfuffle::ExtractProgram
QStringList The names to the program that will handle extracting of this archive (eg "rar")...
Definition: cliinterface.h:84
Kerfuffle::IsPasswordProtected
The entry is password-protected.
Definition: archive.h:74
QDir::fromNativeSeparators
QString fromNativeSeparators(const QString &pathName)
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
Kerfuffle::CompressedSize
The compressed size for the entry.
Definition: archive.h:65
QTime::fromString
QTime fromString(const QString &string, Qt::DateFormat format)
QString::remove
QString & remove(int position, int n)
Kerfuffle::Version
The archiver version needed to extract the entry.
Definition: archive.h:70
Kerfuffle::ReadOnlyArchiveInterface::entry
void entry(const ArchiveEntry &archiveEntry)
QDate::fromString
QDate fromString(const QString &string, Qt::DateFormat format)
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
Kerfuffle::WrongPasswordPatterns
QStringList Default: empty A list of regexp patterns that will alert the user that the password was w...
Definition: cliinterface.h:201
QString::isEmpty
bool isEmpty() const
QString::trimmed
QString trimmed() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
cliplugin.h
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::PasswordSwitch
QStringList (default empty) The format of the root node switch.
Definition: cliinterface.h:141
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
QString::at
const QChar at(int position) const
CliPlugin::readListLine
virtual bool readListLine(const QString &line)
Definition: cli7zplugin/cliplugin.cpp:78
KERFUFFLE_EXPORT_PLUGIN
#define KERFUFFLE_EXPORT_PLUGIN(p)
Definition: kerfuffle_export.h:49
Kerfuffle::InternalID
The entry's ID for Ark's internal manipulation.
Definition: archive.h:60
Kerfuffle::RootNodeSwitch
QStringList (default empty) The format of the root node switch.
Definition: cliinterface.h:130
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