Commit 7257b0bb authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

Simplify helper functions for mimetypes support

Now all the supportedXXXMimeTypes() static functions behave consistently.
A set of mimetypes is always returned, and it's converted to a list only when
(and if) needed.
parent f42c5801
......@@ -222,7 +222,7 @@ void MainWindow::openArchive()
Q_UNUSED(iface);
QPointer<QFileDialog> dlg = new QFileDialog(this, i18nc("to open an archive", "Open Archive"));
dlg->setMimeTypeFilters(Kerfuffle::supportedMimeTypes());
dlg->setMimeTypeFilters(Kerfuffle::supportedMimeTypes().toList());
QStringList filters = dlg->nameFilters();
filters.removeDuplicates();
......
......@@ -373,24 +373,17 @@ void Archive::enableHeaderEncryption(bool enable)
m_iface->setHeaderEncryptionEnabled(enable);
}
QStringList supportedMimeTypes()
QSet<QString> supportedMimeTypes()
{
const QLatin1String constraint("(exist Library)");
const QLatin1String basePartService("Kerfuffle/Plugin");
const KService::List offers = KServiceTypeTrader::self()->query(basePartService,
QStringLiteral("(exist Library)"));
QSet<QString> supported;
const KService::List offers = KServiceTypeTrader::self()->query(basePartService, constraint);
KService::List::ConstIterator it = offers.constBegin();
KService::List::ConstIterator itEnd = offers.constEnd();
QStringList supported;
for (; it != itEnd; ++it) {
KService::Ptr service = *it;
QStringList mimeTypes = service->serviceTypes();
foreach (const QString& mimeType, mimeTypes) {
if (mimeType != basePartService && !supported.contains(mimeType)) {
supported.append(mimeType);
foreach (const KService::Ptr& service, offers) {
foreach (const QString& mimeType, service->serviceTypes()) {
if (mimeType != basePartService) {
supported.insert(mimeType);
}
}
}
......@@ -400,24 +393,17 @@ QStringList supportedMimeTypes()
return supported;
}
QStringList supportedWriteMimeTypes()
QSet<QString> supportedWriteMimeTypes()
{
const QLatin1String constraint("(exist Library) and ([X-KDE-Kerfuffle-ReadWrite] == true)");
const QLatin1String basePartService("Kerfuffle/Plugin");
const KService::List offers = KServiceTypeTrader::self()->query(basePartService,
QStringLiteral("(exist Library) and ([X-KDE-Kerfuffle-ReadWrite] == true)"));
QSet<QString> supported;
const KService::List offers = KServiceTypeTrader::self()->query(basePartService, constraint);
KService::List::ConstIterator it = offers.constBegin();
KService::List::ConstIterator itEnd = offers.constEnd();
QStringList supported;
for (; it != itEnd; ++it) {
KService::Ptr service = *it;
QStringList mimeTypes = service->serviceTypes();
foreach (const QString& mimeType, mimeTypes) {
if (mimeType != basePartService && !supported.contains(mimeType)) {
supported.append(mimeType);
foreach (const KService::Ptr& service, offers) {
foreach (const QString& mimeType, service->serviceTypes()) {
if (mimeType != basePartService) {
supported.insert(mimeType);
}
}
}
......
......@@ -31,7 +31,6 @@
#include "kerfuffle_export.h"
#include <QString>
#include <QStringList>
#include <QHash>
#include <QObject>
#include <QVariant>
......@@ -202,8 +201,8 @@ private:
ArchiveError m_error;
};
KERFUFFLE_EXPORT QStringList supportedMimeTypes();
KERFUFFLE_EXPORT QStringList supportedWriteMimeTypes();
KERFUFFLE_EXPORT QSet<QString> supportedMimeTypes();
KERFUFFLE_EXPORT QSet<QString> supportedWriteMimeTypes();
KERFUFFLE_EXPORT QSet<QString> supportedEncryptEntriesMimeTypes();
KERFUFFLE_EXPORT QSet<QString> supportedEncryptHeaderMimeTypes();
} // namespace Kerfuffle
......
......@@ -221,7 +221,7 @@ void CreateDialog::loadConfiguration()
const QString defaultMimeType = QStringLiteral("application/x-compressed-tar");
const QString lastMimeType = m_config.readEntry("LastMimeType", defaultMimeType);
QStringList writeMimeTypes = Kerfuffle::supportedWriteMimeTypes();
QStringList writeMimeTypes = Kerfuffle::supportedWriteMimeTypes().toList();
// The filters need to be sorted by comment, so create a QMap with
// comment as key (QMaps are always sorted by key) and QMimeType
......
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