38 #include <KPluginLoader>
40 #include <KMimeTypeTrader>
41 #include <KServiceTypeTrader>
45 return (p1->property(QLatin1String(
"X-KDE-Priority" )).toInt()) > (p2->property(QLatin1String(
"X-KDE-Priority" )).toInt());
50 if (!QFile::exists(filename)) {
51 return KMimeType::findByPath(filename)->name();
55 if (!file.open(QIODevice::ReadOnly)) {
59 const qint64 maxSize = 0x100000;
60 const qint64 bufferSize = qMin(maxSize, file.size());
61 const QByteArray buffer = file.read(bufferSize);
63 return KMimeType::findByNameAndContent(filename, buffer)->name();
66 static KService::List
findPluginOffers(
const QString& filename,
const QString& fixedMimeType)
68 KService::List offers;
70 const QString mimeType = fixedMimeType.isEmpty() ?
determineMimeType(filename) : fixedMimeType;
72 if (!mimeType.isEmpty()) {
73 offers = KMimeTypeTrader::self()->query(mimeType, QLatin1String(
"Kerfuffle/Plugin" ), QLatin1String(
"(exist Library)" ));
85 return create(fileName, QString(), parent);
90 qRegisterMetaType<ArchiveEntry>(
"ArchiveEntry");
94 if (offers.isEmpty()) {
95 kDebug() <<
"Could not find a plugin to handle" <<
fileName;
99 const QString pluginName = offers.first()->library();
100 kDebug() <<
"Loading plugin" << pluginName;
102 KPluginFactory *
const factory = KPluginLoader(pluginName).factory();
104 kDebug() <<
"Invalid plugin factory for" << pluginName;
109 args.append(QVariant(QFileInfo(fileName).absoluteFilePath()));
113 kDebug() <<
"Could not create plugin instance" << pluginName <<
"for" <<
fileName;
117 return new Archive(iface, parent);
122 m_iface(archiveInterface),
123 m_hasBeenListed(false),
124 m_isPasswordProtected(false),
125 m_isSingleFolderArchive(false)
127 Q_ASSERT(archiveInterface);
128 archiveInterface->setParent(
this);
153 job->setAutoDelete(
false);
157 if (!m_hasBeenListed) {
158 connect(job, SIGNAL(result(
KJob*)),
159 this, SLOT(onListFinished(
KJob*)));
169 DeleteJob *newJob =
new DeleteJob(files, static_cast<ReadWriteArchiveInterface*>(m_iface),
this);
177 AddJob *newJob =
new AddJob(files, options, static_cast<ReadWriteArchiveInterface*>(m_iface),
this);
178 connect(newJob, SIGNAL(result(
KJob*)),
179 this, SLOT(onAddFinished(
KJob*)));
187 newOptions[QLatin1String(
"PasswordProtectedHint" )] =
true;
199 void Archive::onAddFinished(
KJob* job)
207 if (m_isSingleFolderArchive && !job->error()) {
208 m_isSingleFolderArchive =
false;
212 void Archive::onListFinished(
KJob* job)
214 ListJob *ljob = qobject_cast<ListJob*>(job);
215 m_extractedFilesSize = ljob->extractedFilesSize();
216 m_isSingleFolderArchive = ljob->isSingleFolderArchive();
217 m_isPasswordProtected = ljob->isPasswordProtected();
218 m_subfolderName = ljob->subfolderName();
219 if (m_subfolderName.isEmpty()) {
221 QString base = fi.completeBaseName();
224 if (base.right(4).toUpper() == QLatin1String(
".TAR")) {
228 m_subfolderName = base;
231 m_hasBeenListed =
true;
234 void Archive::listIfNotListed()
236 if (!m_hasBeenListed) {
242 QEventLoop loop(
this);
244 connect(job, SIGNAL(result(
KJob*)),
245 &loop, SLOT(quit()));
251 void Archive::onUserQuery(Query* query)
259 return m_isSingleFolderArchive;
265 return m_isPasswordProtected;
271 return m_subfolderName;
281 const QLatin1String constraint(
"(exist Library)");
282 const QLatin1String basePartService(
"Kerfuffle/Plugin");
284 const KService::List offers = KServiceTypeTrader::self()->query(basePartService, constraint);
285 KService::List::ConstIterator it = offers.constBegin();
286 KService::List::ConstIterator itEnd = offers.constEnd();
288 QStringList supported;
290 for (; it != itEnd; ++it) {
291 KService::Ptr service = *it;
292 QStringList mimeTypes = service->serviceTypes();
294 foreach (
const QString& mimeType, mimeTypes) {
295 if (mimeType != basePartService && !supported.contains(mimeType)) {
296 supported.append(mimeType);
301 kDebug() <<
"Returning" << supported;
308 const QLatin1String constraint(
"(exist Library) and ([X-KDE-Kerfuffle-ReadWrite] == true)");
309 const QLatin1String basePartService(
"Kerfuffle/Plugin");
311 const KService::List offers = KServiceTypeTrader::self()->query(basePartService, constraint);
312 KService::List::ConstIterator it = offers.constBegin();
313 KService::List::ConstIterator itEnd = offers.constEnd();
315 QStringList supported;
317 for (; it != itEnd; ++it) {
318 KService::Ptr service = *it;
319 QStringList mimeTypes = service->serviceTypes();
321 foreach (
const QString& mimeType, mimeTypes) {
322 if (mimeType != basePartService && !supported.contains(mimeType)) {
323 supported.append(mimeType);
328 kDebug() <<
"Returning" << supported;
static KService::List findPluginOffers(const QString &filename, const QString &fixedMimeType)
QStringList supportedWriteMimeTypes()
QString filename() const
Returns the filename of the archive currently being handled.
bool isPasswordProtected()
QStringList supportedMimeTypes()
bool isSingleFolderArchive()
void setPassword(const QString &password)
static QString determineMimeType(const QString &filename)
QHash< QString, QVariant > CompressionOptions
These are the extra options for doing the compression.
static bool comparePlugins(const KService::Ptr &p1, const KService::Ptr &p2)
virtual bool isReadOnly() const
Returns whether the file can only be read.
QHash< QString, QVariant > ExtractionOptions
ExtractJob * copyFiles(const QList< QVariant > &files, const QString &destinationDir, ExtractionOptions options=ExtractionOptions())
void setPassword(const QString &password)
DeleteJob * deleteFiles(const QList< QVariant > &files)
AddJob * addFiles(const QStringList &files, const CompressionOptions &options=CompressionOptions())
Compression options that should be handled by all interfaces: