[vlc-devel] [RFC 21/82] qt: add a context object that will be usable from QML to get a reference to the main interface/playlist

Pierre Lamot pierre at videolabs.io
Fri Feb 1 14:01:25 CET 2019


---
 modules/gui/qt/Makefile.am                    |  3 ++
 .../gui/qt/components/qml_main_context.cpp    | 42 ++++++++++++++++
 .../gui/qt/components/qml_main_context.hpp    | 48 +++++++++++++++++++
 3 files changed, 93 insertions(+)
 create mode 100644 modules/gui/qt/components/qml_main_context.cpp
 create mode 100644 modules/gui/qt/components/qml_main_context.hpp

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index c80da69165..0f6b7d2904 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -79,6 +79,8 @@ libqt_plugin_la_SOURCES = \
 	gui/qt/dialogs/extensions.cpp gui/qt/dialogs/extensions.hpp \
 	gui/qt/dialogs/fingerprintdialog.cpp \
 	gui/qt/dialogs/fingerprintdialog.hpp \
+	gui/qt/components/qml_main_context.cpp \
+	gui/qt/components/qml_main_context.hpp \
 	gui/qt/components/extended_panels.cpp \
 	gui/qt/components/extended_panels.hpp \
 	gui/qt/components/info_panels.cpp gui/qt/components/info_panels.hpp \
@@ -194,6 +196,7 @@ nodist_libqt_plugin_la_SOURCES = \
 	gui/qt/dialogs/firstrun.moc.cpp \
 	gui/qt/dialogs/extensions.moc.cpp \
 	gui/qt/dialogs/fingerprintdialog.moc.cpp \
+	gui/qt/components/qml_main_context.moc.cpp \
 	gui/qt/components/extended_panels.moc.cpp \
 	gui/qt/components/info_panels.moc.cpp \
 	gui/qt/components/info_widgets.moc.cpp \
diff --git a/modules/gui/qt/components/qml_main_context.cpp b/modules/gui/qt/components/qml_main_context.cpp
new file mode 100644
index 0000000000..165198c02c
--- /dev/null
+++ b/modules/gui/qt/components/qml_main_context.cpp
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * 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 "qml_main_context.hpp"
+#include "main_interface.hpp"
+
+QmlMainContext::QmlMainContext(intf_thread_t* intf, MainInterface* mainInterface, QObject* parent)
+    : QObject(parent)
+    , m_intf( intf )
+    , m_playlist(intf->p_sys->p_playlist)
+    , m_mainInterface(mainInterface)
+{
+}
+
+MainInterface*QmlMainContext::getMainInterface() const
+{
+    return m_mainInterface;
+}
+
+intf_thread_t*QmlMainContext::getIntf() const
+{
+    return m_intf;
+}
+
+PlaylistPtr QmlMainContext::getPlaylist() const
+{
+    return m_playlist;
+}
diff --git a/modules/gui/qt/components/qml_main_context.hpp b/modules/gui/qt/components/qml_main_context.hpp
new file mode 100644
index 0000000000..688d125c75
--- /dev/null
+++ b/modules/gui/qt/components/qml_main_context.hpp
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * Copyright (C) 2019 VLC authors and VideoLAN
+ *
+ * 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 QML_MAIN_CONTEXT_HPP
+#define QML_MAIN_CONTEXT_HPP
+
+#include "qt.hpp"
+
+#include <QObject>
+#include <components/playlist/playlist_common.hpp>
+
+class MainInterface;
+/**
+ * @brief The QmlMainContext class
+ */
+class QmlMainContext : public QObject
+{
+    Q_OBJECT
+    Q_PROPERTY(PlaylistPtr playlist READ getPlaylist CONSTANT)
+
+public:
+    explicit QmlMainContext(intf_thread_t *intf,  MainInterface *mainInterface, QObject* parent = nullptr);
+
+    MainInterface* getMainInterface() const;
+    intf_thread_t* getIntf() const;
+    PlaylistPtr getPlaylist() const;
+
+private:
+    intf_thread_t* m_intf;
+    PlaylistPtr m_playlist;
+    MainInterface* m_mainInterface;
+};
+
+#endif // QML_MAIN_CONTEXT_HPP
-- 
2.19.1



More information about the vlc-devel mailing list