summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <elvis.angelaccio@kde.org>2016-11-28 09:53:10 (GMT)
committerElvis Angelaccio <elvis.angelaccio@kde.org>2016-11-28 11:23:52 (GMT)
commit1b817f61f187eda4dc14a3227e0c0430c30d808e (patch)
treeb35a8f097274fb490b8027ef9e9ebfabc038c7fd
parent878709b99e8b17c7c44a24f0b068b8c5a6b7043a (diff)
Sort mimetypes by comment only when necessary
The list of supported mimetypes is quite long and sorting them by comment is a non-negligible operation. Now we do it only when the mimetypes are shown in user-visible dialogs. CCBUG: 372999
-rw-r--r--app/mainwindow.cpp2
-rw-r--r--kerfuffle/createdialog.cpp2
-rw-r--r--kerfuffle/pluginmanager.cpp16
-rw-r--r--kerfuffle/pluginmanager.h18
4 files changed, 28 insertions, 10 deletions
diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp
index e12db4b..f79d744 100644
--- a/app/mainwindow.cpp
+++ b/app/mainwindow.cpp
@@ -199,7 +199,7 @@ void MainWindow::openArchive()
Kerfuffle::PluginManager pluginManager;
auto dlg = new QFileDialog(this, i18nc("to open an archive", "Open Archive"));
- dlg->setMimeTypeFilters(pluginManager.supportedMimeTypes());
+ dlg->setMimeTypeFilters(pluginManager.supportedMimeTypes(Kerfuffle::PluginManager::SortByComment));
dlg->setFileMode(QFileDialog::ExistingFile);
dlg->setAcceptMode(QFileDialog::AcceptOpen);
diff --git a/kerfuffle/createdialog.cpp b/kerfuffle/createdialog.cpp
index cf5a429..8c19041 100644
--- a/kerfuffle/createdialog.cpp
+++ b/kerfuffle/createdialog.cpp
@@ -66,7 +66,7 @@ CreateDialog::CreateDialog(QWidget *parent,
setWindowTitle(caption);
setModal(true);
- m_supportedMimeTypes = m_pluginManger.supportedWriteMimeTypes();
+ m_supportedMimeTypes = m_pluginManger.supportedWriteMimeTypes(PluginManager::SortByComment);
m_vlayout = new QVBoxLayout();
setLayout(m_vlayout);
diff --git a/kerfuffle/pluginmanager.cpp b/kerfuffle/pluginmanager.cpp
index 2cfeeb6..1cccd76 100644
--- a/kerfuffle/pluginmanager.cpp
+++ b/kerfuffle/pluginmanager.cpp
@@ -107,7 +107,7 @@ Plugin *PluginManager::preferredWritePluginFor(const QMimeType &mimeType) const
return preferredWritePlugins.isEmpty() ? new Plugin() : preferredWritePlugins.first();
}
-QStringList PluginManager::supportedMimeTypes() const
+QStringList PluginManager::supportedMimeTypes(MimeSortingMode mode) const
{
QSet<QString> supported;
foreach (Plugin *plugin, availablePlugins()) {
@@ -124,10 +124,14 @@ QStringList PluginManager::supportedMimeTypes() const
supported.remove(QStringLiteral("application/x-lz4-compressed-tar"));
}
- return sortByComment(supported);
+ if (mode == SortByComment) {
+ return sortByComment(supported);
+ }
+
+ return supported.toList();
}
-QStringList PluginManager::supportedWriteMimeTypes() const
+QStringList PluginManager::supportedWriteMimeTypes(MimeSortingMode mode) const
{
QSet<QString> supported;
foreach (Plugin *plugin, availableWritePlugins()) {
@@ -144,7 +148,11 @@ QStringList PluginManager::supportedWriteMimeTypes() const
supported.remove(QStringLiteral("application/x-lz4-compressed-tar"));
}
- return sortByComment(supported);
+ if (mode == SortByComment) {
+ return sortByComment(supported);
+ }
+
+ return supported.toList();
}
QVector<Plugin*> PluginManager::filterBy(const QVector<Plugin*> &plugins, const QMimeType &mimeType) const
diff --git a/kerfuffle/pluginmanager.h b/kerfuffle/pluginmanager.h
index 5d046c8..e32d8fd 100644
--- a/kerfuffle/pluginmanager.h
+++ b/kerfuffle/pluginmanager.h
@@ -40,6 +40,16 @@ class KERFUFFLE_EXPORT PluginManager : public QObject
Q_OBJECT
public:
+
+ /**
+ * How the list of supported mimetypes can be sorted.
+ */
+ enum MimeSortingMode
+ {
+ Unsorted,
+ SortByComment
+ };
+
explicit PluginManager(QObject *parent = Q_NULLPTR);
/**
@@ -91,14 +101,14 @@ public:
Plugin *preferredWritePluginFor(const QMimeType &mimeType) const;
/**
- * @return The list of all mimetypes that Ark can open, sorted according to their comment.
+ * @return The list of all mimetypes that Ark can open, sorted according to @p mode.
*/
- QStringList supportedMimeTypes() const;
+ QStringList supportedMimeTypes(MimeSortingMode mode = Unsorted) const;
/**
- * @return The list of all read-write mimetypes supported by Ark, sorted according to their comment.
+ * @return The list of all read-write mimetypes supported by Ark, sorted according to @p mode.
*/
- QStringList supportedWriteMimeTypes() const;
+ QStringList supportedWriteMimeTypes(MimeSortingMode mode = Unsorted) const;
/**
* @return The subset of @p plugins that support either @p mimetype or a parent of @p mimetype.