qml 0.0.7 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/.travis.yml +5 -9
- data/LICENSE.txt +1 -1
- data/README.md +84 -114
- data/changes.md +5 -0
- data/examples/fizzbuzz/fizzbuzz.rb +3 -4
- data/examples/todo_array/todo_array.rb +4 -4
- data/examples/todo_sequel/todo_sequel.rb +7 -7
- data/examples/twitter/twitter.rb +5 -3
- data/ext/qml/application.c +88 -0
- data/ext/qml/application.h +9 -0
- data/ext/qml/component.c +89 -0
- data/ext/qml/component.h +10 -0
- data/ext/qml/conversion.c +60 -0
- data/ext/qml/conversion.h +8 -0
- data/ext/qml/dispatcher.c +31 -0
- data/ext/qml/dispatcher.h +7 -0
- data/ext/qml/engine.c +135 -0
- data/ext/qml/engine.h +10 -0
- data/ext/qml/exporter.c +93 -0
- data/ext/qml/exporter.h +7 -0
- data/ext/qml/extconf.rb +38 -97
- data/ext/qml/interface.c +156 -0
- data/ext/qml/interface.h +11 -0
- data/ext/qml/js_array.c +47 -0
- data/ext/qml/js_array.h +7 -0
- data/ext/qml/js_function.c +109 -0
- data/ext/qml/js_function.h +7 -0
- data/ext/qml/js_object.c +284 -0
- data/ext/qml/js_object.h +19 -0
- data/ext/qml/js_wrapper.c +19 -0
- data/ext/qml/js_wrapper.h +7 -0
- data/ext/qml/lib/libqmlbind/.gitignore +38 -0
- data/ext/qml/lib/libqmlbind/.gitmodules +3 -0
- data/ext/qml/lib/libqmlbind/.travis.yml +14 -0
- data/ext/qml/lib/libqmlbind/LICENSE.txt +22 -0
- data/ext/qml/lib/libqmlbind/libqmlbind.pro +3 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind.h +14 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/application.h +18 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/component.h +21 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/engine.h +34 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/exporter.h +37 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/interface.h +16 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/iterator.h +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/metaobject.h +13 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/plugin.h +17 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/qmlbind_global.h +78 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/register.h +17 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/signal_emitter.h +15 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/string.h +15 -0
- data/ext/qml/lib/libqmlbind/qmlbind/include/qmlbind/value.h +100 -0
- data/ext/qml/lib/libqmlbind/qmlbind/qmlbind.pro +62 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_application.cpp +103 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_component.cpp +54 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_engine.cpp +65 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_exporter.cpp +52 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_interface.cpp +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_iterator.cpp +32 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_metaobject.cpp +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_plugin.cpp +27 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_register.cpp +17 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_signal_emitter.cpp +27 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_string.cpp +22 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/api_value.cpp +215 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/backref.cpp +54 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/backref.h +29 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/engine.cpp +32 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/engine.h +27 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/exporter.cpp +73 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/exporter.h +46 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/interface.cpp +75 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/interface.h +37 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/metaobject.cpp +101 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/metaobject.h +29 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/signalemitter.cpp +33 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/signalemitter.h +25 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/ticktimer.cpp +15 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/ticktimer.h +19 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/typeregisterer.cpp +112 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/typeregisterer.h +28 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/util.h +13 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/wrapper.cpp +23 -0
- data/ext/qml/lib/libqmlbind/qmlbind/src/wrapper.h +29 -0
- data/ext/qml/lib/libqmlbind/readme.md +14 -0
- data/ext/qml/lib/libqmlbind/test/api.c +1 -0
- data/ext/qml/lib/libqmlbind/test/application_test.cpp +16 -0
- data/ext/qml/lib/libqmlbind/test/component_test.cpp +57 -0
- data/ext/qml/lib/libqmlbind/test/engine_test.cpp +94 -0
- data/ext/qml/lib/libqmlbind/test/exporter_test.cpp +312 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/emptyhandlers.cpp +36 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/emptyhandlers.h +6 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/test.qml +5 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/testmodule/qmldir +2 -0
- data/ext/qml/lib/libqmlbind/test/fixtures/testmodule/test.qml +5 -0
- data/ext/qml/lib/libqmlbind/test/iterator_test.cpp +37 -0
- data/ext/qml/lib/libqmlbind/test/main.cpp +11 -0
- data/ext/qml/lib/libqmlbind/test/plugin_test.cpp +41 -0
- data/ext/qml/lib/libqmlbind/test/test.pro +26 -0
- data/ext/qml/lib/libqmlbind/test/test_helper.h +20 -0
- data/ext/qml/lib/libqmlbind/test/value_test.cpp +252 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.cpp +11 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.h +21 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.json +3 -0
- data/ext/qml/lib/libqmlbind/testplugin/testplugin.pro +21 -0
- data/ext/qml/meta_object.c +81 -0
- data/ext/qml/meta_object.h +8 -0
- data/ext/qml/plugin_loader.c +71 -0
- data/ext/qml/plugin_loader.h +7 -0
- data/ext/qml/qml.c +95 -0
- data/ext/qml/qml.h +10 -0
- data/ext/qml/rubyqml-plugin/listmodel.cpp +102 -0
- data/ext/qml/rubyqml-plugin/listmodel.h +37 -0
- data/ext/qml/rubyqml-plugin/rubyqml-plugin.pro +19 -0
- data/ext/qml/rubyqml-plugin/rubyqmlplugin.cpp +25 -0
- data/ext/qml/rubyqml-plugin/rubyqmlplugin.h +19 -0
- data/ext/qml/signal_emitter.c +71 -0
- data/ext/qml/signal_emitter.h +9 -0
- data/lib/qml.rb +11 -10
- data/lib/qml/access.rb +64 -86
- data/lib/qml/application.rb +20 -71
- data/lib/qml/component.rb +41 -33
- data/lib/qml/core_ext.rb +1 -0
- data/lib/qml/core_ext/to_qml.rb +70 -0
- data/lib/qml/data.rb +1 -0
- data/lib/qml/data/array_model.rb +99 -101
- data/lib/qml/data/list_model.rb +107 -131
- data/lib/qml/data/list_model_access.rb +44 -0
- data/lib/qml/data/query_model.rb +45 -47
- data/lib/qml/dispatcher.rb +5 -13
- data/lib/qml/engine.rb +9 -58
- data/lib/qml/errors.rb +0 -21
- data/lib/qml/interface.rb +21 -0
- data/lib/qml/js_array.rb +8 -0
- data/lib/qml/js_object.rb +69 -0
- data/lib/qml/js_util.rb +18 -0
- data/lib/qml/plugin_loader.rb +1 -13
- data/lib/qml/plugins.rb +3 -17
- data/lib/qml/proc_access.rb +28 -0
- data/lib/qml/qt.rb +21 -3
- data/lib/qml/reactive.rb +147 -8
- data/lib/qml/signal.rb +67 -0
- data/lib/qml/version.rb +1 -1
- data/qml.gemspec +8 -2
- data/spec/qml/access_spec.rb +33 -120
- data/spec/qml/application_spec.rb +11 -24
- data/spec/qml/component_spec.rb +4 -4
- data/spec/qml/data/array_model_spec.rb +2 -2
- data/spec/qml/data/list_model_spec.rb +2 -2
- data/spec/qml/data/query_model_spec.rb +4 -4
- data/spec/qml/engine_spec.rb +23 -21
- data/spec/qml/interface_spec.rb +20 -0
- data/spec/qml/js_array_spec.rb +29 -0
- data/spec/qml/js_function_spec.rb +32 -0
- data/spec/qml/js_object_spec.rb +113 -0
- data/spec/qml/plugin_loader_spec.rb +9 -11
- data/spec/qml/qt_spec.rb +9 -0
- data/spec/qml/reactive_spec.rb +37 -0
- data/spec/qml/signal_connect_spec.rb +27 -0
- data/spec/qml/signal_spec.rb +73 -0
- data/spec/qml/to_qml_spec.rb +76 -0
- data/spec/shared/qml/access_example.rb +21 -0
- data/spec/shared/qml/data/list_model.rb +12 -13
- data/spec/spec_helper.rb +2 -3
- metadata +141 -166
- data/examples/imageprovider/imageprovider.rb +0 -57
- data/examples/imageprovider/main.qml +0 -51
- data/ext/qml/accessclass.cpp +0 -65
- data/ext/qml/accessclass.h +0 -19
- data/ext/qml/accessobject.cpp +0 -30
- data/ext/qml/accessobject.h +0 -22
- data/ext/qml/common.h +0 -18
- data/ext/qml/conversionerror.h +0 -14
- data/ext/qml/ext_accesswrapperfactory.cpp +0 -75
- data/ext/qml/ext_accesswrapperfactory.h +0 -39
- data/ext/qml/ext_anywrapper.cpp +0 -34
- data/ext/qml/ext_anywrapper.h +0 -23
- data/ext/qml/ext_kernel.cpp +0 -81
- data/ext/qml/ext_kernel.h +0 -9
- data/ext/qml/ext_metaobject.cpp +0 -399
- data/ext/qml/ext_metaobject.h +0 -60
- data/ext/qml/ext_pluginloader.cpp +0 -53
- data/ext/qml/ext_pluginloader.h +0 -30
- data/ext/qml/ext_pointer.cpp +0 -132
- data/ext/qml/ext_pointer.h +0 -41
- data/ext/qml/ext_testutil.cpp +0 -40
- data/ext/qml/ext_testutil.h +0 -9
- data/ext/qml/foreignclass.cpp +0 -72
- data/ext/qml/foreignclass.h +0 -88
- data/ext/qml/foreignmetaobject.cpp +0 -345
- data/ext/qml/foreignmetaobject.h +0 -46
- data/ext/qml/foreignobject.cpp +0 -22
- data/ext/qml/foreignobject.h +0 -21
- data/ext/qml/functioninfo.h +0 -16
- data/ext/qml/init.cpp +0 -67
- data/ext/qml/kernel.cpp +0 -39
- data/ext/qml/kernel.h +0 -32
- data/ext/qml/listmodel.cpp +0 -137
- data/ext/qml/listmodel.h +0 -45
- data/ext/qml/markable.h +0 -12
- data/ext/qml/objectdata.cpp +0 -26
- data/ext/qml/objectdata.h +0 -20
- data/ext/qml/objectgc.cpp +0 -69
- data/ext/qml/objectgc.h +0 -28
- data/ext/qml/plugins/core/applicationextension.cpp +0 -29
- data/ext/qml/plugins/core/applicationextension.h +0 -25
- data/ext/qml/plugins/core/componentextension.cpp +0 -41
- data/ext/qml/plugins/core/componentextension.h +0 -28
- data/ext/qml/plugins/core/contextextension.cpp +0 -39
- data/ext/qml/plugins/core/contextextension.h +0 -29
- data/ext/qml/plugins/core/core.pro +0 -29
- data/ext/qml/plugins/core/coreplugin.cpp +0 -87
- data/ext/qml/plugins/core/coreplugin.h +0 -49
- data/ext/qml/plugins/core/engineextension.cpp +0 -43
- data/ext/qml/plugins/core/engineextension.h +0 -31
- data/ext/qml/plugins/core/imageprovider.cpp +0 -38
- data/ext/qml/plugins/core/imageprovider.h +0 -18
- data/ext/qml/plugins/core/imagerequestpromise.cpp +0 -19
- data/ext/qml/plugins/core/imagerequestpromise.h +0 -21
- data/ext/qml/plugins/core/qmlexception.cpp +0 -11
- data/ext/qml/plugins/core/qmlexception.h +0 -17
- data/ext/qml/plugins/testutil/imageprovidertest.cpp +0 -40
- data/ext/qml/plugins/testutil/imageprovidertest.h +0 -17
- data/ext/qml/plugins/testutil/objectlifechecker.cpp +0 -17
- data/ext/qml/plugins/testutil/objectlifechecker.h +0 -24
- data/ext/qml/plugins/testutil/ownershiptest.cpp +0 -26
- data/ext/qml/plugins/testutil/ownershiptest.h +0 -30
- data/ext/qml/plugins/testutil/testobject.cpp +0 -6
- data/ext/qml/plugins/testutil/testobject.h +0 -108
- data/ext/qml/plugins/testutil/testobjectsubclass.cpp +0 -10
- data/ext/qml/plugins/testutil/testobjectsubclass.h +0 -19
- data/ext/qml/plugins/testutil/testutil.pro +0 -22
- data/ext/qml/plugins/testutil/testutilplugin.cpp +0 -55
- data/ext/qml/plugins/testutil/testutilplugin.h +0 -36
- data/ext/qml/qmltyperegisterer.cpp +0 -74
- data/ext/qml/qmltyperegisterer.h +0 -30
- data/ext/qml/rubyclass.cpp +0 -82
- data/ext/qml/rubyclass.h +0 -230
- data/ext/qml/rubyvalue.cpp +0 -656
- data/ext/qml/rubyvalue.h +0 -224
- data/ext/qml/signalforwarder.cpp +0 -64
- data/ext/qml/signalforwarder.h +0 -29
- data/ext/qml/util.cpp +0 -112
- data/ext/qml/util.h +0 -82
- data/ext/qml/valuereference.cpp +0 -50
- data/ext/qml/valuereference.h +0 -22
- data/ext/qml/weakvaluereference.cpp +0 -51
- data/ext/qml/weakvaluereference.h +0 -21
- data/lib/qml/context.rb +0 -71
- data/lib/qml/data/error.rb +0 -5
- data/lib/qml/dispatchable.rb +0 -34
- data/lib/qml/error_converter.rb +0 -16
- data/lib/qml/geometry.rb +0 -3
- data/lib/qml/geometry/point.rb +0 -5
- data/lib/qml/geometry/rectangle.rb +0 -5
- data/lib/qml/geometry/size.rb +0 -5
- data/lib/qml/image_provider.rb +0 -87
- data/lib/qml/init.rb +0 -29
- data/lib/qml/meta_object.rb +0 -20
- data/lib/qml/models.rb +0 -1
- data/lib/qml/qt_classes.rb +0 -9
- data/lib/qml/qt_object_base.rb +0 -233
- data/lib/qml/reactive/bindable.rb +0 -79
- data/lib/qml/reactive/chained_signal.rb +0 -25
- data/lib/qml/reactive/error.rb +0 -5
- data/lib/qml/reactive/object.rb +0 -293
- data/lib/qml/reactive/property.rb +0 -19
- data/lib/qml/reactive/signal.rb +0 -115
- data/lib/qml/reactive/signal_spy.rb +0 -27
- data/lib/qml/reactive/signals/map_signal.rb +0 -21
- data/lib/qml/reactive/signals/merge_signal.rb +0 -21
- data/lib/qml/reactive/signals/select_signal.rb +0 -21
- data/lib/qml/reactive/simple_property.rb +0 -17
- data/lib/qml/reactive/unbound_property.rb +0 -42
- data/lib/qml/reactive/unbound_signal.rb +0 -51
- data/lib/qml/test_util.rb +0 -1
- data/lib/qml/test_util/object_life_checker.rb +0 -17
- data/lib/qml/wrappable.rb +0 -9
- data/spec/qml/context_spec.rb +0 -43
- data/spec/qml/conversion_spec.rb +0 -60
- data/spec/qml/dispatchable_spec.rb +0 -26
- data/spec/qml/dispatcher_spec.rb +0 -71
- data/spec/qml/geometry/point_spec.rb +0 -4
- data/spec/qml/geometry/rectangle_spec.rb +0 -4
- data/spec/qml/geometry/size_spec.rb +0 -4
- data/spec/qml/image_provider_spec.rb +0 -33
- data/spec/qml/qt_object_base_spec.rb +0 -119
- data/spec/qml/reactive/object_spec.rb +0 -249
- data/spec/qml/reactive/property_spec.rb +0 -70
- data/spec/qml/reactive/signal_spec.rb +0 -191
- data/spec/qml/reactive/signal_spy_spec.rb +0 -26
- data/spec/qml/reactive/unbound_property_spec.rb +0 -40
- data/spec/qml/reactive/unbound_signal_spec.rb +0 -70
- data/spec/qml/test_object_spec.rb +0 -186
- data/spec/qml/wrappable_spec.rb +0 -10
- data/spec/shared/qml/reactive/object.rb +0 -39
data/examples/twitter/twitter.rb
CHANGED
|
@@ -2,7 +2,6 @@ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
|
|
|
2
2
|
require 'qml'
|
|
3
3
|
require 'twitter'
|
|
4
4
|
require 'yaml'
|
|
5
|
-
require 'celluloid'
|
|
6
5
|
|
|
7
6
|
module Examples
|
|
8
7
|
module Twitter
|
|
@@ -43,7 +42,7 @@ module Examples
|
|
|
43
42
|
include QML::Access
|
|
44
43
|
register_to_qml
|
|
45
44
|
|
|
46
|
-
property
|
|
45
|
+
property(:model) { QML::ArrayModel.new(:tweet_text, :user_name, :user_icon) }
|
|
47
46
|
property :word
|
|
48
47
|
|
|
49
48
|
def initialize
|
|
@@ -64,9 +63,12 @@ module Examples
|
|
|
64
63
|
word = self.word
|
|
65
64
|
@thread = Thread.new do
|
|
66
65
|
TweetFetcher.new.start(word) do |tweet|
|
|
67
|
-
|
|
66
|
+
QML.next_tick do
|
|
67
|
+
add_tweet(tweet)
|
|
68
|
+
end
|
|
68
69
|
end
|
|
69
70
|
end
|
|
71
|
+
nil
|
|
70
72
|
end
|
|
71
73
|
end
|
|
72
74
|
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#include "application.h"
|
|
2
|
+
#include "interface.h"
|
|
3
|
+
|
|
4
|
+
VALUE rbqml_cApplication = Qnil;
|
|
5
|
+
|
|
6
|
+
typedef struct {
|
|
7
|
+
qmlbind_application application;
|
|
8
|
+
} application_t;
|
|
9
|
+
|
|
10
|
+
static void application_free(void *p) {
|
|
11
|
+
application_t *data = (application_t*)p;
|
|
12
|
+
// application is never released
|
|
13
|
+
// qmlbind_application_release(data->application);
|
|
14
|
+
xfree(data);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static const rb_data_type_t data_type = {
|
|
18
|
+
"QML::Application",
|
|
19
|
+
{ NULL, &application_free }
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
qmlbind_application rbqml_get_application(VALUE self) {
|
|
23
|
+
application_t *data;
|
|
24
|
+
TypedData_Get_Struct(self, application_t, &data_type, data);
|
|
25
|
+
return data->application;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static VALUE application_alloc(VALUE klass) {
|
|
29
|
+
application_t *data = ALLOC(application_t);
|
|
30
|
+
data->application = NULL;
|
|
31
|
+
return TypedData_Wrap_Struct(klass, &data_type, data);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static VALUE application_initialize(VALUE self, VALUE args) {
|
|
35
|
+
if (rb_thread_main() != rb_thread_current()) {
|
|
36
|
+
rb_raise(rb_eThreadError, "Initializing QML::Application outside the main thread");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
application_t *data;
|
|
40
|
+
TypedData_Get_Struct(self, application_t, &data_type, data);
|
|
41
|
+
|
|
42
|
+
if (rb_type(args) != T_ARRAY) {
|
|
43
|
+
rb_raise(rb_eTypeError, "Expected Array");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
args = rb_ary_concat(rb_ary_new_from_args(1, rb_argv0), args);
|
|
47
|
+
|
|
48
|
+
int argc = RARRAY_LEN(args);
|
|
49
|
+
char **argv = malloc(argc * sizeof(char *));
|
|
50
|
+
|
|
51
|
+
for (int i = 0; i < argc; ++i) {
|
|
52
|
+
VALUE arg = RARRAY_AREF(args, i);
|
|
53
|
+
argv[i] = rb_string_value_cstr(&arg);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
data->application = qmlbind_application_new(argc, argv);
|
|
57
|
+
|
|
58
|
+
return self;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
* Starts the event loop of the application.
|
|
63
|
+
* This method never returns until the application quits.
|
|
64
|
+
*/
|
|
65
|
+
static VALUE application_exec(VALUE self) {
|
|
66
|
+
qmlbind_application app = rbqml_get_application(self);
|
|
67
|
+
int ret = (int)rb_thread_call_without_gvl((void *(*)(void *))&qmlbind_application_exec, app, RUBY_UBF_IO, NULL);
|
|
68
|
+
return INT2NUM(ret);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/*
|
|
72
|
+
* Processes queued events in the event loop manually.
|
|
73
|
+
* This method is useful when you are combining an external event loop like EventMachine.
|
|
74
|
+
*/
|
|
75
|
+
static VALUE application_process_events(VALUE application) {
|
|
76
|
+
rb_thread_call_without_gvl((void *(*)(void *))&qmlbind_process_events, NULL, RUBY_UBF_IO, NULL);
|
|
77
|
+
return Qnil;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
void rbqml_init_application(void) {
|
|
81
|
+
VALUE mQML = rb_define_module("QML");
|
|
82
|
+
rbqml_cApplication = rb_define_class_under(mQML, "Application", rb_cObject);
|
|
83
|
+
rb_define_alloc_func(rbqml_cApplication, application_alloc);
|
|
84
|
+
|
|
85
|
+
rb_define_private_method(rbqml_cApplication, "initialize", application_initialize, 1);
|
|
86
|
+
rb_define_method(rbqml_cApplication, "exec", application_exec, 0);
|
|
87
|
+
rb_define_method(rbqml_cApplication, "process_events", application_process_events, 0);
|
|
88
|
+
}
|
data/ext/qml/component.c
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#include "qml.h"
|
|
2
|
+
#include "component.h"
|
|
3
|
+
#include "engine.h"
|
|
4
|
+
#include "conversion.h"
|
|
5
|
+
|
|
6
|
+
VALUE rbqml_cComponent;
|
|
7
|
+
|
|
8
|
+
typedef struct {
|
|
9
|
+
qmlbind_component component;
|
|
10
|
+
} component_t;
|
|
11
|
+
|
|
12
|
+
static void component_free(void *p) {
|
|
13
|
+
component_t *data = (component_t *)p;
|
|
14
|
+
rb_thread_call_without_gvl((void *(*)(void *))&qmlbind_component_release, data->component, RUBY_UBF_IO, NULL);
|
|
15
|
+
xfree(data);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static const rb_data_type_t data_type = {
|
|
19
|
+
"QML::Component",
|
|
20
|
+
{ NULL, &component_free }
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
qmlbind_component rbqml_get_component(VALUE self) {
|
|
24
|
+
component_t *data;
|
|
25
|
+
TypedData_Get_Struct(self, component_t, &data_type, data);
|
|
26
|
+
return data->component;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static VALUE component_alloc(VALUE klass) {
|
|
30
|
+
component_t *data = ALLOC(component_t);
|
|
31
|
+
data->component = NULL;
|
|
32
|
+
return TypedData_Wrap_Struct(klass, &data_type, data);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static VALUE component_initialize(VALUE self) {
|
|
36
|
+
component_t *data;
|
|
37
|
+
TypedData_Get_Struct(self, component_t, &data_type, data);
|
|
38
|
+
data->component = qmlbind_component_new(rbqml_get_engine(rbqml_engine));
|
|
39
|
+
|
|
40
|
+
return self;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static VALUE component_load_path(VALUE self, VALUE path) {
|
|
44
|
+
qmlbind_component component = rbqml_get_component(self);
|
|
45
|
+
qmlbind_component_load_path(component, rb_string_value_cstr(&path));
|
|
46
|
+
|
|
47
|
+
return self;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static VALUE component_load_data(VALUE self, VALUE data, VALUE path) {
|
|
51
|
+
qmlbind_component component = rbqml_get_component(self);
|
|
52
|
+
qmlbind_component_set_data(component, rb_string_value_cstr(&data), rb_string_value_cstr(&path));
|
|
53
|
+
|
|
54
|
+
return self;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static VALUE component_error_string(VALUE self) {
|
|
58
|
+
qmlbind_component component = rbqml_get_component(self);
|
|
59
|
+
qmlbind_string error = qmlbind_component_get_error_string(component);
|
|
60
|
+
if (error) {
|
|
61
|
+
VALUE str = rb_enc_str_new(qmlbind_string_get_chars(error), qmlbind_string_get_length(error), rb_utf8_encoding());
|
|
62
|
+
qmlbind_string_release(error);
|
|
63
|
+
return str;
|
|
64
|
+
} else {
|
|
65
|
+
return Qnil;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static VALUE component_create(VALUE self) {
|
|
70
|
+
component_t *data;
|
|
71
|
+
TypedData_Get_Struct(self, component_t, &data_type, data);
|
|
72
|
+
|
|
73
|
+
qmlbind_value obj = rb_thread_call_without_gvl((void *(*)(void *))&qmlbind_component_create, data->component, RUBY_UBF_IO, NULL);
|
|
74
|
+
VALUE result = rbqml_to_ruby(obj);
|
|
75
|
+
qmlbind_value_release(obj);
|
|
76
|
+
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
void rbqml_init_component() {
|
|
81
|
+
rbqml_cComponent = rb_define_class_under(rb_path2class("QML"), "Component", rb_cObject);
|
|
82
|
+
rb_define_alloc_func(rbqml_cComponent, &component_alloc);
|
|
83
|
+
|
|
84
|
+
rb_define_private_method(rbqml_cComponent, "initialize_impl", &component_initialize, 0);
|
|
85
|
+
rb_define_private_method(rbqml_cComponent, "load_path_impl", &component_load_path, 1);
|
|
86
|
+
rb_define_private_method(rbqml_cComponent, "load_data_impl", &component_load_data, 2);
|
|
87
|
+
rb_define_private_method(rbqml_cComponent, "error_string", &component_error_string, 0);
|
|
88
|
+
rb_define_private_method(rbqml_cComponent, "create_impl", &component_create, 0);
|
|
89
|
+
}
|
data/ext/qml/component.h
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#include "qml.h"
|
|
2
|
+
#include "conversion.h"
|
|
3
|
+
#include "js_object.h"
|
|
4
|
+
#include "js_array.h"
|
|
5
|
+
#include "js_function.h"
|
|
6
|
+
#include "js_wrapper.h"
|
|
7
|
+
|
|
8
|
+
VALUE rbqml_to_ruby(qmlbind_value value)
|
|
9
|
+
{
|
|
10
|
+
if (qmlbind_value_is_undefined(value) || qmlbind_value_is_null(value)) {
|
|
11
|
+
return Qnil;
|
|
12
|
+
}
|
|
13
|
+
if (qmlbind_value_is_boolean(value)) {
|
|
14
|
+
return qmlbind_value_get_boolean(value) ? Qtrue : Qfalse;
|
|
15
|
+
}
|
|
16
|
+
if (qmlbind_value_is_number(value)) {
|
|
17
|
+
double num = qmlbind_value_get_number(value);
|
|
18
|
+
return rb_float_new(num);
|
|
19
|
+
}
|
|
20
|
+
if (qmlbind_value_is_string(value)) {
|
|
21
|
+
qmlbind_string str = qmlbind_value_get_string(value);
|
|
22
|
+
return rb_enc_str_new(qmlbind_string_get_chars(str), qmlbind_string_get_length(str), rb_utf8_encoding());
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
VALUE klass;
|
|
26
|
+
|
|
27
|
+
if (qmlbind_value_is_array(value)) {
|
|
28
|
+
klass = rbqml_cJSArray;
|
|
29
|
+
} else if (qmlbind_value_is_function(value)) {
|
|
30
|
+
klass = rbqml_cJSFunction;
|
|
31
|
+
} else if (qmlbind_value_is_wrapper(value)) {
|
|
32
|
+
klass = rbqml_cJSWrapper;
|
|
33
|
+
} else {
|
|
34
|
+
klass = rbqml_cJSObject;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return rbqml_js_object_new(klass, value);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
qmlbind_value rbqml_to_qml(VALUE value)
|
|
41
|
+
{
|
|
42
|
+
value = rb_funcall(value, rb_intern("to_qml"), 0);
|
|
43
|
+
|
|
44
|
+
switch (rb_type(value)) {
|
|
45
|
+
case T_NIL:
|
|
46
|
+
return qmlbind_value_new_null();
|
|
47
|
+
case T_TRUE:
|
|
48
|
+
return qmlbind_value_new_boolean(true);
|
|
49
|
+
case T_FALSE:
|
|
50
|
+
return qmlbind_value_new_boolean(false);
|
|
51
|
+
case T_FLOAT:
|
|
52
|
+
return qmlbind_value_new_number(rb_float_value(value));
|
|
53
|
+
case T_STRING:
|
|
54
|
+
return qmlbind_value_new_string(RSTRING_LEN(value), RSTRING_PTR(value));
|
|
55
|
+
default:
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return rbqml_js_object_get(value);
|
|
60
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#include "dispatcher.h"
|
|
2
|
+
|
|
3
|
+
VALUE rbqml_cDispatcher;
|
|
4
|
+
int callback_enabled = 1;
|
|
5
|
+
|
|
6
|
+
static void tick_callback_impl() {
|
|
7
|
+
VALUE dispatcher = rb_funcall(rbqml_cDispatcher, rb_intern("instance"), 0);
|
|
8
|
+
rb_funcall(dispatcher, rb_intern("run_tasks"), 0);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static void tick_callback() {
|
|
12
|
+
if (__sync_fetch_and_add(&callback_enabled, 0)) {
|
|
13
|
+
rb_thread_call_with_gvl((void *(*)(void *))&tick_callback_impl, NULL);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static VALUE dispatcher_callback_enabled_set(VALUE self, VALUE enabled) {
|
|
18
|
+
if (RTEST(enabled)) {
|
|
19
|
+
__sync_fetch_and_or(&callback_enabled, 1);
|
|
20
|
+
} else {
|
|
21
|
+
__sync_fetch_and_and(&callback_enabled, 0);
|
|
22
|
+
}
|
|
23
|
+
return enabled;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
void rbqml_init_dispatcher(void) {
|
|
27
|
+
rbqml_cDispatcher = rb_define_class_under(rb_path2class("QML"), "Dispatcher", rb_cObject);
|
|
28
|
+
rb_define_private_method(rbqml_cDispatcher, "callback_enabled=", &dispatcher_callback_enabled_set, 1);
|
|
29
|
+
|
|
30
|
+
qmlbind_set_tick_callback(&tick_callback);
|
|
31
|
+
}
|
data/ext/qml/engine.c
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#include "engine.h"
|
|
2
|
+
#include "conversion.h"
|
|
3
|
+
#include "application.h"
|
|
4
|
+
#include "js_object.h"
|
|
5
|
+
#include "js_array.h"
|
|
6
|
+
|
|
7
|
+
VALUE rbqml_cEngine;
|
|
8
|
+
|
|
9
|
+
typedef struct {
|
|
10
|
+
qmlbind_engine engine;
|
|
11
|
+
} engine_t;
|
|
12
|
+
|
|
13
|
+
static void engine_free(void *p) {
|
|
14
|
+
engine_t *data = (engine_t *)p;
|
|
15
|
+
|
|
16
|
+
//rb_thread_call_without_gvl((void *(*)(void *))&qmlbind_engine_release, data->engine, RUBY_UBF_IO, NULL);
|
|
17
|
+
xfree(data);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static const rb_data_type_t data_type = {
|
|
21
|
+
"QML::Engine",
|
|
22
|
+
{ NULL, &engine_free }
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
qmlbind_engine rbqml_get_engine(VALUE self) {
|
|
26
|
+
engine_t *data;
|
|
27
|
+
TypedData_Get_Struct(self, engine_t, &data_type, data);
|
|
28
|
+
return data->engine;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static VALUE engine_alloc(VALUE klass) {
|
|
32
|
+
engine_t *data = ALLOC(engine_t);
|
|
33
|
+
data->engine = NULL;
|
|
34
|
+
return TypedData_Wrap_Struct(klass, &data_type, data);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static VALUE engine_initialize(VALUE self) {
|
|
38
|
+
engine_t *data;
|
|
39
|
+
TypedData_Get_Struct(self, engine_t, &data_type, data);
|
|
40
|
+
data->engine = qmlbind_engine_new();
|
|
41
|
+
return self;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
* Adds a QML import path to the {Engine}.
|
|
46
|
+
* @param path [String]
|
|
47
|
+
* @see http://doc.qt.io/qt-5/qtqml-syntax-imports.html#qml-import-path
|
|
48
|
+
*/
|
|
49
|
+
static VALUE engine_add_import_path(VALUE self, VALUE path) {
|
|
50
|
+
qmlbind_engine engine = rbqml_get_engine(self);
|
|
51
|
+
path = rb_funcall(path, rb_intern("to_s"), 0);
|
|
52
|
+
qmlbind_engine_add_import_path(engine, rb_string_value_cstr(&path));
|
|
53
|
+
return self;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
typedef struct {
|
|
57
|
+
qmlbind_engine engine;
|
|
58
|
+
const char *str;
|
|
59
|
+
const char *file;
|
|
60
|
+
int lineNum;
|
|
61
|
+
} evaluate_data;
|
|
62
|
+
|
|
63
|
+
static void *evaluate_impl(void *p) {
|
|
64
|
+
evaluate_data *data = p;
|
|
65
|
+
return qmlbind_engine_eval(data->engine, data->str, data->file, data->lineNum);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static VALUE engine_evaluate(VALUE self, VALUE str, VALUE file, VALUE lineNum) {
|
|
69
|
+
qmlbind_engine engine = rbqml_get_engine(self);
|
|
70
|
+
|
|
71
|
+
evaluate_data data;
|
|
72
|
+
data.engine = engine;
|
|
73
|
+
data.str = rb_string_value_cstr(&str);
|
|
74
|
+
data.file = rb_string_value_cstr(&file);
|
|
75
|
+
data.lineNum = NUM2INT(lineNum);
|
|
76
|
+
|
|
77
|
+
qmlbind_value value = rb_thread_call_without_gvl(&evaluate_impl, &data, RUBY_UBF_IO, NULL);
|
|
78
|
+
|
|
79
|
+
VALUE result = rbqml_to_ruby(value);
|
|
80
|
+
qmlbind_value_release(value);
|
|
81
|
+
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* @paran [Integer] len
|
|
87
|
+
* @return [QML::JSArray]
|
|
88
|
+
*/
|
|
89
|
+
static VALUE engine_new_array(VALUE self, VALUE len) {
|
|
90
|
+
qmlbind_engine engine = rbqml_get_engine(self);
|
|
91
|
+
|
|
92
|
+
qmlbind_value array = qmlbind_engine_new_array(engine, NUM2INT(len));
|
|
93
|
+
VALUE value = rbqml_js_object_new(rbqml_cJSArray, array);
|
|
94
|
+
qmlbind_value_release(array);
|
|
95
|
+
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/*
|
|
100
|
+
* @return [QML::JSObject]
|
|
101
|
+
*/
|
|
102
|
+
static VALUE engine_new_object(VALUE self) {
|
|
103
|
+
qmlbind_engine engine = rbqml_get_engine(self);
|
|
104
|
+
|
|
105
|
+
qmlbind_value obj = qmlbind_engine_new_object(engine);
|
|
106
|
+
VALUE value = rbqml_js_object_new(rbqml_cJSObject, obj);
|
|
107
|
+
qmlbind_value_release(obj);
|
|
108
|
+
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/*
|
|
113
|
+
* Starts garbage collection on the {Engine}.
|
|
114
|
+
*/
|
|
115
|
+
static VALUE engine_collect_garbage(VALUE self) {
|
|
116
|
+
qmlbind_engine engine = rbqml_get_engine(self);
|
|
117
|
+
qmlbind_engine_collect_garbage(engine);
|
|
118
|
+
return self;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
void rbqml_init_engine() {
|
|
122
|
+
rb_require("qml/errors");
|
|
123
|
+
|
|
124
|
+
VALUE mQML = rb_define_module("QML");
|
|
125
|
+
|
|
126
|
+
rbqml_cEngine = rb_define_class_under(mQML, "Engine", rb_cObject);
|
|
127
|
+
rb_define_alloc_func(rbqml_cEngine, &engine_alloc);
|
|
128
|
+
|
|
129
|
+
rb_define_private_method(rbqml_cEngine, "initialize", engine_initialize, 0);
|
|
130
|
+
rb_define_method(rbqml_cEngine, "add_import_path", engine_add_import_path, 1);
|
|
131
|
+
rb_define_private_method(rbqml_cEngine, "evaluate_impl", engine_evaluate, 3);
|
|
132
|
+
rb_define_method(rbqml_cEngine, "new_array", engine_new_array, 1);
|
|
133
|
+
rb_define_method(rbqml_cEngine, "new_object", engine_new_object, 0);
|
|
134
|
+
rb_define_method(rbqml_cEngine, "collect_garbage", engine_collect_garbage, 0);
|
|
135
|
+
}
|