[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [ark] /: Merge branch 'Applications/16.04'
From: Elvis Angelaccio <elvis.angelaccio () kdemail ! net>
Date: 2016-06-05 19:02:24
Message-ID: E1b9dJY-00026G-Tb () scm ! kde ! org
[Download RAW message or body]
Git commit 6f768813da573aef6d99a98cdf713dc8188f3e23 by Elvis Angelaccio.
Committed on 05/06/2016 at 18:57.
Pushed by elvisangelaccio into branch 'master'.
Merge branch 'Applications/16.04'
This adapts the patch in D1725 to our new PluginManager class.
CCBUG: 363717
M +6 -0 autotests/kerfuffle/archivetest.cpp
A +10 -2 kerfuffle/pluginmanager.cpp [License: BSD]
A +2 -2 kerfuffle/pluginmanager.h [License: BSD]
http://commits.kde.org/ark/6f768813da573aef6d99a98cdf713dc8188f3e23
diff --cc autotests/kerfuffle/archivetest.cpp
index e56bcc1,9a3012c..c746d16
--- a/autotests/kerfuffle/archivetest.cpp
+++ b/autotests/kerfuffle/archivetest.cpp
@@@ -149,11 -162,11 +149,17 @@@ void ArchiveTest::testProperties_data(
qDebug() << "lrzip executable not found in path. Skipping lrzip test.";
}
+ QTest::newRow("xar archive")
+ << QFINDTESTDATA("data/simplearchive.xar")
+ << QStringLiteral("simplearchive")
+ << true << false << false << Archive::Unencrypted
+ << QStringLiteral("simplearchive");
++
+ QTest::newRow("mimetype child of application/zip")
+ << QFINDTESTDATA("data/test.odt")
+ << QStringLiteral("test")
+ << false << true << false << Archive::Unencrypted
+ << QStringLiteral("test");
}
void ArchiveTest::testProperties()
diff --cc kerfuffle/pluginmanager.cpp
index 05944a0,0000000..9e1288d
mode 100644,000000..100644
--- a/kerfuffle/pluginmanager.cpp
+++ b/kerfuffle/pluginmanager.cpp
@@@ -1,196 -1,0 +1,204 @@@
+/*
+ * ark -- archiver for the KDE project
+ *
+ * Copyright (C) 2016 Elvis Angelaccio <elvis.angelaccio@kdemail.net>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "pluginmanager.h"
+
+#include <KConfigGroup>
+#include <KPluginLoader>
+#include <KSharedConfig>
+
+#include <QMimeDatabase>
+#include <QSet>
+
+#include <algorithm>
+
+namespace Kerfuffle
+{
+
+PluginManager::PluginManager(QObject *parent) : QObject(parent)
+{
+ loadPlugins();
+}
+
+QVector<Plugin*> PluginManager::installedPlugins() const
+{
+ return m_plugins;
+}
+
+QVector<Plugin*> PluginManager::availablePlugins() const
+{
+ QVector<Plugin*> availablePlugins;
+ foreach (Plugin *plugin, m_plugins) {
+ if (plugin->isValid()) {
+ availablePlugins << plugin;
+ }
+ }
+
+ return availablePlugins;
+}
+
+QVector<Plugin*> PluginManager::availableWritePlugins() const
+{
+ QVector<Plugin*> availableWritePlugins;
+ foreach (Plugin *plugin, availablePlugins()) {
+ if (plugin->isReadWrite()) {
+ availableWritePlugins << plugin;
+ }
+ }
+
+ return availableWritePlugins;
+}
+
+QVector<Plugin*> PluginManager::enabledPlugins() const
+{
+ QVector<Plugin*> enabledPlugins;
+ foreach (Plugin *plugin, m_plugins) {
+ if (plugin->isEnabled()) {
+ enabledPlugins << plugin;
+ }
+ }
+
+ return enabledPlugins;
+}
+
+QVector<Plugin*> PluginManager::preferredPluginsFor(const QMimeType &mimeType) \
const +{
+ return preferredPluginsFor(mimeType, false);
+}
+
+QVector<Plugin*> PluginManager::preferredWritePluginsFor(const QMimeType &mimeType) \
const +{
+ return preferredPluginsFor(mimeType, true);
+}
+
+Plugin *PluginManager::preferredPluginFor(const QMimeType &mimeType) const
+{
+ const QVector<Plugin*> preferredPlugins = preferredPluginsFor(mimeType);
+ return preferredPlugins.isEmpty() ? new Plugin() : preferredPlugins.first();
+}
+
+Plugin *PluginManager::preferredWritePluginFor(const QMimeType &mimeType) const
+{
+ const QVector<Plugin*> preferredWritePlugins = \
preferredWritePluginsFor(mimeType); + return preferredWritePlugins.isEmpty() ? \
new Plugin() : preferredWritePlugins.first(); +}
+
+QStringList PluginManager::supportedMimeTypes() const
+{
+ QSet<QString> supported;
+ foreach (Plugin *plugin, availablePlugins()) {
+ supported += plugin->metaData().mimeTypes().toSet();
+ }
+
+ // Remove entry for lrzipped tar if lrzip executable not found in path.
+ if (QStandardPaths::findExecutable(QStringLiteral("lrzip")).isEmpty()) {
+ supported.remove(QStringLiteral("application/x-lrzip-compressed-tar"));
+ }
+
+ return sortByComment(supported);
+}
+
+QStringList PluginManager::supportedWriteMimeTypes() const
+{
+ QSet<QString> supported;
+ foreach (Plugin *plugin, availableWritePlugins()) {
+ supported += plugin->metaData().mimeTypes().toSet();
+ }
+
+ // Remove entry for lrzipped tar if lrzip executable not found in path.
+ if (QStandardPaths::findExecutable(QStringLiteral("lrzip")).isEmpty()) {
+ supported.remove(QStringLiteral("application/x-lrzip-compressed-tar"));
+ }
+
+ return sortByComment(supported);
+}
+
- QVector<Plugin*> PluginManager::filterBy(const QVector<Plugin*> &plugins, const \
QMimeType &mimeType) ++QVector<Plugin*> PluginManager::filterBy(const \
QVector<Plugin*> &plugins, const QMimeType &mimeType) const +{
++ const bool supportedMime = supportedMimeTypes().contains(mimeType.name());
+ QVector<Plugin*> filteredPlugins;
+ foreach (Plugin *plugin, plugins) {
- if (plugin->metaData().mimeTypes().contains(mimeType.name())) {
++ if (!supportedMime) {
++ // Check whether the mimetype inherits from a supported mimetype.
++ foreach (const QString &mime, plugin->metaData().mimeTypes()) {
++ if (mimeType.inherits(mime)) {
++ filteredPlugins << plugin;
++ }
++ }
++ } else if (plugin->metaData().mimeTypes().contains(mimeType.name())) {
+ filteredPlugins << plugin;
+ }
+ }
+
+ return filteredPlugins;
+}
+
+void PluginManager::loadPlugins()
+{
+ const QVector<KPluginMetaData> plugins = \
KPluginLoader::findPlugins(QStringLiteral("kerfuffle")); + // TODO: once we have \
a GUI in the settings dialog, + // use this group to write whether a plugin gets \
disabled. + const KConfigGroup conf(KSharedConfig::openConfig(), \
"EnabledPlugins"); +
+ foreach (const KPluginMetaData &metaData, plugins) {
+ Plugin *plugin = new Plugin(this, metaData);
+ plugin->setEnabled(conf.readEntry(metaData.pluginId(), true));
+ m_plugins << plugin;
+ }
+}
+
+QVector<Plugin*> PluginManager::preferredPluginsFor(const QMimeType &mimeType, bool \
readWrite) const +{
+ QVector<Plugin*> preferredPlugins = filterBy((readWrite ? \
availableWritePlugins() : availablePlugins()), mimeType); +
+ std::sort(preferredPlugins.begin(), preferredPlugins.end(), [](Plugin* p1, \
Plugin* p2) { + return p1->priority() > p2->priority();
+ });
+
+ return preferredPlugins;
+}
+
+QStringList PluginManager::sortByComment(const QSet<QString> &mimeTypes)
+{
+ QMap<QString,QString> map;
+
+ // Initialize the QMap to sort by comment.
+ foreach (const QString &mimeType, mimeTypes) {
+ QMimeType mime(QMimeDatabase().mimeTypeForName(mimeType));
+ map[mime.comment().toLower()] = mime.name();
+ }
+
+ // Convert to sorted QStringList.
+ QStringList sortedMimeTypes;
+ foreach (const QString &value, map) {
+ sortedMimeTypes << value;
+ }
+
+ return sortedMimeTypes;
+}
+
+}
diff --cc kerfuffle/pluginmanager.h
index 8dbe823,0000000..2115f67
mode 100644,000000..100644
--- a/kerfuffle/pluginmanager.h
+++ b/kerfuffle/pluginmanager.h
@@@ -1,128 -1,0 +1,128 @@@
+/*
+ * ark -- archiver for the KDE project
+ *
+ * Copyright (C) 2016 Elvis Angelaccio <elvis.angelaccio@kdemail.net>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PLUGINMANAGER_H
+#define PLUGINMANAGER_H
+
+#include "plugin.h"
+
+#include <QMimeType>
+
+namespace Kerfuffle
+{
+
+class KERFUFFLE_EXPORT PluginManager : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit PluginManager(QObject *parent = Q_NULLPTR);
+
+ /**
+ * @return The list of all installed plugins.
+ * An installed plugin is not necessarily available to the app.
+ * The user could have disabled it from the settings, or the needed executables \
could not be found. + */
+ QVector<Plugin*> installedPlugins() const;
+
+ /**
+ * @return The list of plugins ready to be used. Includes read-only and \
read-write ones. + */
+ QVector<Plugin*> availablePlugins() const;
+
+ /**
+ * @return The list of read-write plugins ready to be used.
+ */
+ QVector<Plugin*> availableWritePlugins() const;
+
+ /**
+ * @return The list of plugins enabled by the user in the settings dialog.
+ */
+ QVector<Plugin*> enabledPlugins() const;
+
+ /**
+ * @return The list of preferred plugins for the given @p mimeType, among all \
the available ones. + * The list is sorted according to the plugins priority.
+ * If no plugin is available, returns an empty list.
+ */
+ QVector<Plugin*> preferredPluginsFor(const QMimeType &mimeType) const;
+
+ /**
+ * @return The list of preferred read-write plugins for the given @p mimeType, \
among all the available ones. + * The list is sorted according to the plugins \
priority. + * If no read-write plugin is available, returns an empty list.
+ */
+ QVector<Plugin*> preferredWritePluginsFor(const QMimeType &mimeType) const;
+
+ /**
+ * @return The preferred plugin for the given @p mimeType, among all the \
available ones. + * If no plugin is available, returns an invalid plugin.
+ */
+ Plugin *preferredPluginFor(const QMimeType &mimeType) const;
+
+ /**
+ * @return The preferred read-write plugin for the given @p mimeType, among all \
the available ones. + * If no read-write plugin is available, returns an invalid \
plugin. + */
+ Plugin *preferredWritePluginFor(const QMimeType &mimeType) const;
+
+ /**
+ * @return The list of all mimetypes that Ark can open, sorted according to \
their comment. + */
+ QStringList supportedMimeTypes() const;
+
+ /**
+ * @return The list of all read-write mimetypes supported by Ark, sorted \
according to their comment. + */
+ QStringList supportedWriteMimeTypes() const;
+
+ /**
- * @return The given list of @p plugins filtered by @p mimeType.
++ * @return The subset of @p plugins that support either @p mimetype or a parent \
of @p mimetype. + */
- static QVector<Plugin*> filterBy(const QVector<Plugin*> &plugins, const \
QMimeType &mimeType); ++ QVector<Plugin*> filterBy(const QVector<Plugin*> \
&plugins, const QMimeType &mimeType) const; +
+private:
+
+ void loadPlugins();
+
+ /**
+ * @param readWrite whether to return only the read-write plugins.
+ * @return The list of preferred plugins for @p mimeType among the available \
ones, sorted by priority. + */
+ QVector<Plugin*> preferredPluginsFor(const QMimeType &mimeType, bool readWrite) \
const; +
+ /**
+ * @return A list with the given @p mimeTypes, alphabetically sorted according \
to their comment. + */
+ static QStringList sortByComment(const QSet<QString> &mimeTypes);
+
+ QVector<Plugin*> m_plugins;
+};
+
+}
+
+#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic