on xenial help sign in
Added result property to the preview.
commitbf799c58e17ecfdf68b9c176d55b6d7935159b40 authorPawel Stolowski <pawel.stolowski@canonical.com> dateTue 24 Sep 2013, 14:52 (13 years ago) parent3643755
8 files changed+173−1
plugins/Unity/CMakeLists.txt+1 plugins/Unity/plugin.cpp+2 plugins/Unity/preview.cpp+8−1 plugins/Unity/preview.h+4 plugins/Unity/result.cpp+82 plugins/Unity/result.h+66 plugins/Unity/variantutils.cpp+9 plugins/Unity/variantutils.h+1
plugins/Unity/CMakeLists.txt+1
@@ -43,6 +43,7 @@ set(QMLPLUGIN_SRC
4343 preview.cpp
4444 previewaction.cpp
4545 previewinfohint.cpp
46+ result.cpp
4647 showallfilteroption.cpp
4748 signalslist.cpp
4849 socialpreview.cpp
plugins/Unity/plugin.cpp+2
@@ -35,6 +35,7 @@
3535#include "categoryresults.h"
3636#include "bottombarvisibilitycommunicatorshell.h"
3737#include "genericoptionsmodel.h"
38+#include "result.h"
3839
3940// libqtdee
4041#include "deelistmodel.h"
@@ -50,6 +51,7 @@ void UnityPlugin::registerTypes(const char *uri)
5051 qmlRegisterUncreatableType<PreviewInfoHint>(uri, 0, 1, "PreviewInfoHint", "Can't create PreviewInfoHint object in QML.");
5152 qmlRegisterUncreatableType<SocialPreviewComment>(uri, 0, 1, "SocialPreviewComment", "Can't create SocialPreviewComment object in QML.");
5253 qmlRegisterUncreatableType<GenericOptionsModel>(uri, 0, 1, "GenericOptionsModel", "Can't create options model in QML.");
54+ qmlRegisterUncreatableType<Result>(uri, 0, 1, "Result", "Can't create result object in QML.");
5355 qmlRegisterType<Scope>(uri, 0, 1, "Scope");
5456 qmlRegisterType<Scopes>(uri, 0, 1, "Scopes");
5557 qmlRegisterType<Categories>(uri, 0, 1, "Categories");
plugins/Unity/preview.cpp+8−1
@@ -41,7 +41,8 @@
4141
4242Preview::Preview(QObject *parent):
4343 QObject(parent),
44− m_unityPreview(nullptr)
44+ m_unityPreview(nullptr),
45+ m_result(new Result(this))
4546{
4647}
4748
@@ -123,6 +124,11 @@ QString Preview::imageSourceUri() const
123124 return QString::null;
124125}
125126
127+Result* Preview::result() const
128+{
129+ return m_result;
130+}
131+
126132Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
127133{
128134 Preview* preview = nullptr;
@@ -151,6 +157,7 @@ Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
151157void Preview::setUnityPreviewBase(unity::dash::Preview::Ptr unityPreview)
152158{
153159 m_unityPreview = unityPreview;
160+ m_result->setPreview(unityPreview);
154161
155162 qDeleteAll(m_infoHints);
156163 m_infoHints.clear();
plugins/Unity/preview.h+4
@@ -31,6 +31,7 @@
3131#include <UnityCore/Preview.h>
3232
3333// local
34+#include "result.h"
3435#include "previewaction.h"
3536
3637class Q_DECL_EXPORT Preview : public QObject
@@ -46,6 +47,7 @@ class Q_DECL_EXPORT Preview : public QObject
4647 Q_PROPERTY(QVariantMap infoMap READ infoHintsHash NOTIFY previewChanged)
4748 Q_PROPERTY(QString image READ image NOTIFY previewChanged)
4849 Q_PROPERTY(QString imageSourceUri READ imageSourceUri NOTIFY previewChanged)
50+ Q_PROPERTY(Result result READ result NOTIFY previewChanged)
4951
5052public:
5153 explicit Preview(QObject *parent = 0);
@@ -60,6 +62,7 @@ public:
6062 QVariantMap infoHintsHash() const;
6163 QString image() const;
6264 QString imageSourceUri() const;
65+ Result* result() const;
6366
6467 Q_INVOKABLE void execute(const QString& actionId, const QHash<QString, QVariant>& hints);
6568
@@ -70,6 +73,7 @@ protected:
7073 virtual void setUnityPreview(unity::dash::Preview::Ptr unityPreview);
7174
7275 unity::dash::Preview::Ptr m_unityPreview;
76+ Result* m_result;
7377
7478private:
7579 void setUnityPreviewBase(unity::dash::Preview::Ptr unityPreview);
plugins/Unity/result.cppnew file+82
@@ -0,0 +1,82 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@canonical.com>
6+ *
7+ * This program is free software; you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation; version 3.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ */
19+
20+#include "result.h"
21+#include "variantutils.h"
22+
23+Result::Result(QObject *parent) :
24+ QObject(parent)
25+{
26+}
27+
28+Result::Result(unity::dash::Preview::Ptr preview, QObject *parent) :
29+ QObject(parent),
30+ m_preview(preview)
31+{
32+}
33+
34+void Result::setPreview(unity::dash::Preview::Ptr preview)
35+{
36+ m_preview = preview;
37+}
38+
39+QString Result::uri() const
40+{
41+ return m_preview != nullptr ? QString::fromStdString(m_preview->preview_result.uri) : QString::null;
42+}
43+
44+QString Result::iconHint() const
45+{
46+ return m_preview != nullptr ? QString::fromStdString(m_preview->preview_result.icon_hint) : QString::null;
47+}
48+
49+unsigned Result::categoryIndex() const
50+{
51+ return m_preview != nullptr ? m_preview->preview_result.category_index : 0;
52+}
53+
54+unsigned Result::resultType() const
55+{
56+ return m_preview != nullptr ? m_preview->preview_result.result_type : 0;
57+}
58+
59+QString Result::mimeType() const
60+{
61+ return m_preview != nullptr ? QString::fromStdString(m_preview->preview_result.mimetype) : QString::null;
62+}
63+
64+QString Result::title() const
65+{
66+ return m_preview != nullptr ? QString::fromStdString(m_preview->preview_result.name) : QString::null;
67+}
68+
69+QString Result::comment() const
70+{
71+ return m_preview != nullptr ? QString::fromStdString(m_preview->preview_result.comment) : QString::null;
72+}
73+
74+QString Result::dndUri() const
75+{
76+ return m_preview != nullptr ? QString::fromStdString(m_preview->preview_result.dnd_uri) : QString::null;
77+}
78+
79+QVariant Result::metadata() const
80+{
81+ return m_preview != nullptr ? convertToQVariantHash(m_preview->preview_result.hints) : QVariant();
82+}
plugins/Unity/result.hnew file+66
@@ -0,0 +1,66 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Pawel Stolowski <pawel.stolowski@canonical.com>
6+ *
7+ * This program is free software; you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation; version 3.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ */
19+
20+#ifndef RESULT_H
21+#define RESULT_H
22+
23+// Qt
24+#include <QObject>
25+#include <QVariant>
26+
27+// libunity-core
28+#include <UnityCore/Preview.h>
29+
30+class Result : public QObject
31+{
32+ Q_OBJECT
33+
34+ Q_PROPERTY(QString uri READ uri CONSTANT)
35+ Q_PROPERTY(QString iconHint READ iconHint CONSTANT)
36+ Q_PROPERTY(unsigned categoryIndex READ categoryIndex CONSTANT)
37+ Q_PROPERTY(unsigned resultType READ resultType CONSTANT)
38+ Q_PROPERTY(QString mimeType READ mimeType CONSTANT)
39+ Q_PROPERTY(QString title READ title CONSTANT)
40+ Q_PROPERTY(QString comment READ comment CONSTANT)
41+ Q_PROPERTY(QString dndUri READ dndUri CONSTANT)
42+ Q_PROPERTY(QVariant metadata READ metadata CONSTANT)
43+
44+public:
45+ Result(QObject *parent = nullptr);
46+ Result(unity::dash::Preview::Ptr preview, QObject *parent = nullptr);
47+
48+ void setPreview(unity::dash::Preview::Ptr preview);
49+
50+ QString uri() const;
51+ QString iconHint() const;
52+ unsigned categoryIndex() const;
53+ unsigned resultType() const;
54+ QString mimeType() const;
55+ QString title() const;
56+ QString comment() const;
57+ QString dndUri() const;
58+ QVariant metadata() const;
59+
60+private:
61+ unity::dash::Preview::Ptr m_preview;
62+};
63+
64+Q_DECLARE_METATYPE(Result *)
65+
66+#endif
plugins/Unity/variantutils.cpp+9
@@ -40,3 +40,12 @@ unity::glib::HintsMap convertToHintsMap(const QVariant &var)
4040 }
4141 return unity::glib::HintsMap();
4242}
43+
44+QVariantHash convertToQVariantHash(const unity::glib::HintsMap& var)
45+{
46+ QVariantHash hash;
47+ for (auto hint: var) {
48+ hash.insert(QString::fromStdString(hint.first), DeeListModel::VariantForData(hint.second));
49+ }
50+ return hash;
51+}
plugins/Unity/variantutils.h+1
@@ -28,5 +28,6 @@
2828
2929unity::glib::HintsMap convertToHintsMap(const QHash<QString, QVariant> &val);
3030unity::glib::HintsMap convertToHintsMap(const QVariant &var);
31+QVariantHash convertToQVariantHash(const unity::glib::HintsMap& var);
3132
3233#endif