Skip to content

Commit 28adbbb

Browse files
committed
Add first binding experiment
1 parent 4d70a7c commit 28adbbb

File tree

10 files changed

+110
-9
lines changed

10 files changed

+110
-9
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = cr
6+
7+
[*.{hpp,cpp,h,ts,js,json}]
8+
indent_size = 2

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ string(REPLACE "\"" "" NODEGUI_PLUGIN_CMAKE_HELPER ${NODEGUI_PLUGIN_CMAKE_HELPER
99
include("${NODEGUI_PLUGIN_CMAKE_HELPER}")
1010

1111
# -------------- User Config ---------------
12-
set(PLUGIN_ADDON_NAME "nodegui_plugin_statusbar")
12+
set(PLUGIN_ADDON_NAME "nodegui_plugin_qtmultimedia")
1313

1414
project(${PLUGIN_ADDON_NAME})
1515

@@ -18,15 +18,24 @@ add_library(${PLUGIN_ADDON_NAME} SHARED
1818
"${PROJECT_SOURCE_DIR}/src/cpp/main.cpp"
1919
"${PROJECT_SOURCE_DIR}/src/cpp/QStatusBar/qstatusbar_wrap.cpp"
2020
"${PROJECT_SOURCE_DIR}/src/cpp/QStatusBar/nstatusbar.hpp"
21+
"${PROJECT_SOURCE_DIR}/src/cpp/QMediaContent/qmediacontent_wrap.cpp"
22+
"${PROJECT_SOURCE_DIR}/src/cpp/QMediaContent/nmediacontent.hpp"
2123
)
2224

2325
AddPluginConfig(${PLUGIN_ADDON_NAME})
2426

27+
#execute_process(COMMAND node -p "require('@nodegui/qode').qtHome"
28+
# WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
29+
# OUTPUT_VARIABLE QT_HOME_DIR
30+
# )
31+
2532
target_include_directories(${PLUGIN_ADDON_NAME} PRIVATE
2633
"${CMAKE_JS_INC}"
2734
"${PROJECT_SOURCE_DIR}"
2835
)
2936
target_link_libraries(${PLUGIN_ADDON_NAME} PRIVATE
3037
"${CMAKE_JS_LIB}"
38+
"/usr/lib/libQt5Multimedia.so"
39+
"/usr/lib/libQt5MultimediaWidgets.so"
3140
)
3241

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"name": "nodegui-plugin",
2+
"name": "nodegui-plugin-qtmultimedia",
33
"version": "1.0.0",
4-
"description": "A sample native plugin example for NodeGUI",
4+
"description": "NodeGUI oriented wrapper around the QtMultimedia API",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
77
"scripts": {
88
"build": "tsc && npm run build:addon",
99
"build:addon": "cross-env CMAKE_BUILD_PARALLEL_LEVEL=8 cmake-js compile",
1010
"dev": "npm run build && qode dist/demo.js"
1111
},
12-
"author": "Atul R",
12+
"author": "Andrés Rodríguez",
1313
"license": "MIT",
1414
"peerDependencies": {
1515
"@nodegui/nodegui": "*"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
// #include <nodegui/core/NodeWidget/nodewidget.h>
4+
#include <QMediaContent>
5+
6+
class NStatusBar : public QMediaContent {
7+
public:
8+
Q_OBJECT
9+
public:
10+
using QMediaContent::QMediaContent;
11+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "QMediaContent/qmediacontent_wrap.h"
2+
3+
#include <QMediaContent>
4+
5+
#include "Extras/Utils/nutils.h"
6+
7+
Napi::FunctionReference QMediaContentWrap::constructor;
8+
9+
Napi::Object QMediaContentWrap::init(Napi::Env env, Napi::Object exports) {
10+
Napi::HandleScope scope(env);
11+
char CLASSNAME[] = "QMediaContent";
12+
Napi::Function func =
13+
DefineClass(env, CLASSNAME,
14+
{InstanceMethod("isNull", &QMediaContentWrap::isNull),
15+
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QMediaContentWrap)});
16+
constructor = Napi::Persistent(func);
17+
exports.Set(CLASSNAME, func);
18+
return exports;
19+
}
20+
21+
QMediaContentWrap::QMediaContentWrap(const Napi::CallbackInfo& info)
22+
: Napi::ObjectWrap<QMediaContentWrap>(info) {
23+
Napi::Env env = info.Env();
24+
Napi::HandleScope scope(env);
25+
26+
if (info.Length() == 0) {
27+
this->instance = std::make_unique<QMediaContent>();
28+
} else {
29+
Napi::TypeError::New(env, "Wrong number of arguments")
30+
.ThrowAsJavaScriptException();
31+
}
32+
this->rawData = extrautils::configureComponent(this->getInternalInstance());
33+
}
34+
35+
QMediaContentWrap::~QMediaContentWrap() { this->instance.reset(); }
36+
37+
QMediaContent* QMediaContentWrap::getInternalInstance() {
38+
return this->instance.get();
39+
}
40+
41+
Napi::Value QMediaContentWrap::isNull(const Napi::CallbackInfo& info) {
42+
Napi::Env env = info.Env();
43+
Napi::HandleScope scope(env);
44+
return Napi::Value::From(env, this->instance->isNull());
45+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
#include <napi.h>
3+
4+
#include <QMediaContent>
5+
6+
#include "nmediacontent.hpp"
7+
#include "nodegui/Extras/Utils/nutils.h"
8+
#include "nodegui/core/Component/component_macro.h"
9+
10+
class DLL_EXPORT QMediaContentWrap : public Napi::ObjectWrap<QMediaContent> {
11+
COMPONENT_WRAPPED_METHODS_DECLARATION
12+
private:
13+
std::unique_ptr<QMediaContent> instance;
14+
15+
public:
16+
static Napi::FunctionReference constructor;
17+
static Napi::Object init(Napi::Env env, Napi::Object exports);
18+
QMediaContentWrap(const Napi::CallbackInfo& info);
19+
~QMediaContentWrap();
20+
QMediaContent* getInternalInstance();
21+
// Wrapped methods
22+
Napi::Value isNull(const Napi::CallbackInfo& info);
23+
};

src/cpp/QStatusBar/qstatusbar_wrap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#pragma once
22
#include <napi.h>
33
#include <nodegui/QtWidgets/QWidget/qwidget_macro.h>
4+
45
#include <QPointer>
6+
57
#include "nstatusbar.hpp"
68

79
class QStatusBarWrap : public Napi::ObjectWrap<QStatusBarWrap> {

src/cpp/main.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
#include "src/cpp/QStatusBar/qstatusbar_wrap.h"
21
#include <napi.h>
32

3+
#include "src/cpp/QMediaContent/qmediacontent_wrap.h"
4+
#include "src/cpp/QStatusBar/qstatusbar_wrap.h"
5+
46
Napi::Object Main(Napi::Env env, Napi::Object exports) {
5-
QStatusBarWrap::init(env, exports);
6-
return exports;
7+
QStatusBarWrap::init(env, exports);
8+
QMediaContentWrap::init(env, exports);
9+
return exports;
710
}
811

912
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Main)

src/lib/utils/addon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const addon = require("../../../build/Release/nodegui_plugin_statusbar.node");
1+
const addon = require("../../../build/Release/nodegui_plugin_qtmultimedia.node");
22

33
export default addon;

0 commit comments

Comments
 (0)