summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <[email protected]>2017-06-04 17:50:24 +0200
committerElvis Angelaccio <[email protected]>2017-06-04 17:50:24 +0200
commita99455be9428266375000dfe8450289131329590 (patch)
tree73cccb0071274567e899108b27469a67be2ce5f5
parentcf5e04c7817e9e1fc6bb78e0a62729c8b7328d57 (diff)
Use custom part factory and honour KParts::ReadOnlyPart requests
If we are asked to create an ArkPart of type `KParts::ReadOnlyPart`, we should honour the request and set the part to read-only. To do so, we need to use a custom KPluginFactory instead of the default one created by the `K_PLUGIN_FACTORY` macro.
-rw-r--r--part/CMakeLists.txt17
-rw-r--r--part/factory.cpp34
-rw-r--r--part/factory.h37
-rw-r--r--part/part.cpp2
4 files changed, 80 insertions, 10 deletions
diff --git a/part/CMakeLists.txt b/part/CMakeLists.txt
index 47c3348..cc263bd 100644
--- a/part/CMakeLists.txt
+++ b/part/CMakeLists.txt
@@ -1,12 +1,13 @@
set(arkpart_PART_SRCS
- part.cpp
- infopanel.cpp
- arkviewer.cpp
- archivemodel.cpp
- archivesortfiltermodel.cpp
- archiveview.cpp
- jobtracker.cpp
- overwritedialog.cpp
+ factory.cpp
+ part.cpp
+ infopanel.cpp
+ arkviewer.cpp
+ archivemodel.cpp
+ archivesortfiltermodel.cpp
+ archiveview.cpp
+ jobtracker.cpp
+ overwritedialog.cpp
)
ecm_qt_declare_logging_category(arkpart_PART_SRCS
diff --git a/part/factory.cpp b/part/factory.cpp
new file mode 100644
index 0000000..6e9d7bd
--- /dev/null
+++ b/part/factory.cpp
@@ -0,0 +1,34 @@
+/*
+ * ark -- archiver for the KDE project
+ *
+ * Copyright (c) 2017 Elvis Angelaccio <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "factory.h"
+#include "part.h"
+
+QObject *Factory::create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword)
+{
+ Q_UNUSED(keyword)
+
+ auto part = new Ark::Part(parentWidget, parent, args);
+ part->setReadWrite(QByteArray(iface) == QByteArray(KParts::ReadWritePart::staticMetaObject.className()));
+
+ return part;
+}
+
diff --git a/part/factory.h b/part/factory.h
new file mode 100644
index 0000000..c7c3ab6
--- /dev/null
+++ b/part/factory.h
@@ -0,0 +1,37 @@
+/*
+ * ark -- archiver for the KDE project
+ *
+ * Copyright (c) 2017 Elvis Angelaccio <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef FACTORY_H
+#define FACTORY_H
+
+#include <KPluginFactory>
+
+class Factory: public KPluginFactory
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID KPluginFactory_iid FILE "ark_part.json")
+ Q_INTERFACES(KPluginFactory)
+
+protected:
+ QObject *create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword) override;
+};
+
+#endif
diff --git a/part/part.cpp b/part/part.cpp
index 3dc4184..dd9fb34 100644
--- a/part/part.cpp
+++ b/part/part.cpp
@@ -81,8 +81,6 @@
using namespace Kerfuffle;
-K_PLUGIN_FACTORY_WITH_JSON(Factory, "ark_part.json", registerPlugin<Ark::Part>();)
-
namespace Ark
{