diff --git a/CMakeLists.txt b/CMakeLists.txt
index ea758fa..7296c14 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-project (RMail)
+project (rust_qt_binding_generator)
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
cmake_policy(SET CMP0046 NEW)
@@ -34,8 +34,6 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
-add_subdirectory(rust_qt_binding_generator)
-
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER)
if(CMAKE_BUILD_TYPE_UPPER STREQUAL DEBUG)
set(RUST_TARGET_DIR target/debug/)
@@ -45,47 +43,7 @@ else()
set(RUST_BUILD_FLAG --release)
endif()
-add_custom_command(
- OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/common-rust/src/testinterface.rs"
- "${CMAKE_CURRENT_SOURCE_DIR}/common-rust/src/testimplementation.rs"
- "${CMAKE_CURRENT_SOURCE_DIR}/common-rust/src/types.rs"
- COMMAND ${CMAKE_BINARY_DIR}/rust_qt_binding_generator/rust_qt_binding_generator "${CMAKE_CURRENT_SOURCE_DIR}/bindings.json"
- DEPENDS rust_qt_binding_generator bindings.json
-)
-
-add_custom_command(
- OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/common-rust/${RUST_TARGET_DIR}/librust.a"
- COMMAND cargo build ${RUST_BUILD_FLAG}
- DEPENDS common-rust/src/lib.rs
- common-rust/src/testimplementation.rs
- common-rust/src/testinterface.rs
- common-rust/src/implementation.rs
- common-rust/src/interface.rs
- common-rust/src/types.rs
- WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/common-rust"
-)
-add_custom_target(rust_target DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/common-rust/${RUST_TARGET_DIR}/librust.a")
-
-set(RMail_SRCS src/main.cpp src/RMailObject.cpp src/tmp.cpp)
-
-add_executable(RMail ${RMail_SRCS})
-add_dependencies(RMail rust_target)
-
-target_link_libraries(RMail
- Qt5::Quick
- Qt5::Widgets
- KF5::CoreAddons
- KF5::I18n
- KF5::WidgetsAddons
- "${CMAKE_CURRENT_SOURCE_DIR}/common-rust/${RUST_TARGET_DIR}/librust.a"
-)
-
-set_target_properties(RMail PROPERTIES
- CXX_STANDARD 11
- CXX_STANDARD_REQUIRED ON
-)
-
-install(TARGETS RMail ${INSTALL_TARGETS_DEFAULT_ARGS})
-
+add_subdirectory(rust_qt_binding_generator)
add_subdirectory(tests)
+add_subdirectory(demo)
diff --git a/common-rust/Cargo.toml b/common-rust/Cargo.toml
deleted file mode 100644
index 8d91ad9..0000000
--- a/common-rust/Cargo.toml
+++ /dev/null
@@ -1,19 +0,0 @@
-[package]
-name = "rust"
-version = "0.1.0"
-
-[dependencies]
-libc = "*"
-
-[dependencies.serde]
-version = "1.0"
-
-[dependencies.serde_json]
-version = "1.0"
-
-[dependencies.serde_derive]
-version = "1.0"
-
-[lib]
-name = "rust"
-crate-type = ["staticlib"]
diff --git a/bindings.json b/demo/bindings.json
similarity index 97%
rename from bindings.json
rename to demo/bindings.json
index 8def7d1..028f12a 100644
--- a/bindings.json
+++ b/demo/bindings.json
@@ -1,7 +1,7 @@
{
"cppFile": "src/tmp.cpp",
"rust": {
- "dir": "common-rust",
+ "dir": "rust",
"interfaceModule": "testinterface",
"implementationModule": "testimplementation",
"typesModule": "types"
diff --git a/demo/demo.qml b/demo/demo.qml
new file mode 100644
index 0000000..37ea836
--- /dev/null
+++ b/demo/demo.qml
@@ -0,0 +1,72 @@
+import QtQuick 2.6
+import QtQml.Models 2.2
+import QtQuick.Controls 1.5
+import rust 1.0
+
+ApplicationWindow {
+ width: 300
+ height: 480
+ visible: true
+ Directory {
+ id: directory
+ path: "/"
+ }
+ ItemSelectionModel {
+ id: selectionModel
+ model: fsModel
+ }
+ SplitView {
+ anchors.fill: parent
+ orientation: Qt.Horizontal
+ TreeView {
+ model: directory
+ TableViewColumn {
+ title: "Name"
+ role: "FileName"
+ }
+ TableViewColumn {
+ title: "Permissions"
+ role: "FilePermissions"
+ }
+ }
+ TreeView {
+ model: fsModel
+ selection: selectionModel
+ //selectionMode: SelectionMode.SingleSelection
+ TableViewColumn {
+ title: "Name"
+ role: "display"
+ width: 300
+ }
+ TableViewColumn {
+ title: "Permissions"
+ role: "display"
+ width: 100
+ }
+ itemDelegate: Item {
+ Text {
+ anchors.verticalCenter: parent.verticalCenter
+ color: "blue"//styleData.textColor
+ elide: styleData.elideMode
+ text: styleData.index.column + " " + styleData.value
+ }
+ }
+ onClicked: {
+ selectionModel.setCurrentIndex(index, ItemSelectionModel.Select)
+ }
+/*
+ rowDelegate: Item {
+ anchors.fill: parent
+ Text {
+ text: styleData.row
+ }
+ }
+*/
+ }
+/*
+ TableView {
+ model: fsModel
+ }
+*/
+ }
+}
diff --git a/demo/resource_file.qrc b/demo/resource_file.qrc
new file mode 100644
index 0000000..6d9c32d
--- /dev/null
+++ b/demo/resource_file.qrc
@@ -0,0 +1,5 @@
+
+
+ demo.qml
+
+
diff --git a/demo/rust/Cargo.toml b/demo/rust/Cargo.toml
new file mode 100644
index 0000000..b59d13e
--- /dev/null
+++ b/demo/rust/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "rust"
+version = "0.1.0"
+
+[dependencies]
+libc = "*"
+
+[lib]
+name = "rust"
+crate-type = ["staticlib"]
diff --git a/common-rust/src/implementation.rs b/demo/rust/src/implementation.rs
similarity index 100%
rename from common-rust/src/implementation.rs
rename to demo/rust/src/implementation.rs
diff --git a/common-rust/src/interface.rs b/demo/rust/src/interface.rs
similarity index 100%
rename from common-rust/src/interface.rs
rename to demo/rust/src/interface.rs
diff --git a/common-rust/src/lib.rs b/demo/rust/src/lib.rs
similarity index 100%
rename from common-rust/src/lib.rs
rename to demo/rust/src/lib.rs
diff --git a/common-rust/src/testimplementation.rs b/demo/rust/src/testimplementation.rs
similarity index 98%
rename from common-rust/src/testimplementation.rs
rename to demo/rust/src/testimplementation.rs
index 8ef1af5..a04a634 100644
--- a/common-rust/src/testimplementation.rs
+++ b/demo/rust/src/testimplementation.rs
@@ -1,3 +1,4 @@
+#![allow(unused_imports)]
use libc::c_int;
use types::*;
use testinterface::*;
diff --git a/common-rust/src/testinterface.rs b/demo/rust/src/testinterface.rs
similarity index 99%
rename from common-rust/src/testinterface.rs
rename to demo/rust/src/testinterface.rs
index 826d5ea..162ca05 100644
--- a/common-rust/src/testinterface.rs
+++ b/demo/rust/src/testinterface.rs
@@ -1,6 +1,7 @@
/* generated by rust_qt_binding_generator */
#![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)]
+#![allow(unused_imports)]
use libc::{c_int, c_void};
use types::*;
use std::sync::{Arc, Mutex};
diff --git a/common-rust/src/types.rs b/demo/rust/src/types.rs
similarity index 98%
rename from common-rust/src/types.rs
rename to demo/rust/src/types.rs
index 98a702f..005b78a 100644
--- a/common-rust/src/types.rs
+++ b/demo/rust/src/types.rs
@@ -1,6 +1,7 @@
/* generated by rust_qt_binding_generator */
+#![allow(dead_code)]
use std::slice;
-use libc::{c_int, c_uint, uint8_t, uint16_t};
+use libc::{c_int, uint8_t, uint16_t};
use std::ptr::null;
use std::marker::PhantomData;
diff --git a/src/RMailObject.cpp b/demo/src/DemoObject.cpp
similarity index 87%
rename from src/RMailObject.cpp
rename to demo/src/DemoObject.cpp
index f40962b..7eb8e46 100644
--- a/src/RMailObject.cpp
+++ b/demo/src/DemoObject.cpp
@@ -1,4 +1,4 @@
-#include "RMailObject.h"
+#include "DemoObject.h"
#include
#include
#include
@@ -64,10 +64,10 @@ namespace {
typedef void (*qvariant_set)(void*, qvariant_t*);
extern "C" {
- RMailObjectInterface* hello_new(RMailObject*, void (*)(RMailObject*));
- void hello_free(RMailObjectInterface*);
- void hello_set(RMailObjectInterface*, const uint16_t *, size_t);
- qstring_t hello_get(RMailObjectInterface*);
+ DemoObjectInterface* hello_new(DemoObject*, void (*)(DemoObject*));
+ void hello_free(DemoObjectInterface*);
+ void hello_set(DemoObjectInterface*, const uint16_t *, size_t);
+ qstring_t hello_get(DemoObjectInterface*);
RItemModelInterface* ritemmodel_new(RItemModel*, void (*)(RItemModel*));
void ritemmodel_free(RItemModelInterface*);
@@ -78,35 +78,35 @@ extern "C" {
void ritemmodel_data(RItemModelInterface*, qmodelindex_t, int, QVariant*, qvariant_set);
}
-RMailObject::RMailObject(QObject *parent):
+DemoObject::DemoObject(QObject *parent):
QObject(parent),
d(hello_new(this,
- [](RMailObject* o) { emit o->userNameChanged(); }
+ [](DemoObject* o) { emit o->userNameChanged(); }
))
{
}
-RMailObject::~RMailObject() {
+DemoObject::~DemoObject() {
hello_free(d);
}
QString
-RMailObject::userName() const {
+DemoObject::userName() const {
return hello_get(d);
}
void
-RMailObject::setUserName(const QString& name) {
+DemoObject::setUserName(const QString& name) {
hello_set(d, name.utf16(), name.size());
}
const QVariantMap&
-RMailObject::tree() const {
+DemoObject::tree() const {
return m_tree;
}
void
-RMailObject::setTree(const QVariantMap& tree) {
+DemoObject::setTree(const QVariantMap& tree) {
m_tree = tree;
emit treeChanged();
}
diff --git a/src/RMailObject.h b/demo/src/DemoObject.h
similarity index 82%
rename from src/RMailObject.h
rename to demo/src/DemoObject.h
index 34c12ce..3ca0166 100644
--- a/src/RMailObject.h
+++ b/demo/src/DemoObject.h
@@ -1,23 +1,23 @@
-#ifndef RMAIL_OBJECT_H
-#define RMAIL_OBJECT_H
+#ifndef DEMO_OBJECT_H
+#define DEMO_OBJECT_H
#include
#include
#include
#include
-class RMailObjectInterface;
-class RMailObject : public QObject
+class DemoObjectInterface;
+class DemoObject : public QObject
{
Q_OBJECT
- RMailObjectInterface* d;
+ DemoObjectInterface* d;
QVariantMap m_tree;
Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged FINAL)
Q_PROPERTY(QVariantMap tree READ tree WRITE setTree NOTIFY treeChanged FINAL)
public:
- explicit RMailObject(QObject *parent = nullptr);
- ~RMailObject();
+ explicit DemoObject(QObject *parent = nullptr);
+ ~DemoObject();
QString userName() const;
void setUserName(const QString &userName);
@@ -53,4 +53,4 @@ signals:
void newDataReady();
};
-#endif // RMAIL_OBJECT_H
+#endif // DEMO_OBJECT_H
diff --git a/src/main.cpp b/demo/src/main.cpp
similarity index 76%
rename from src/main.cpp
rename to demo/src/main.cpp
index 2b44d2c..9dfcf9a 100644
--- a/src/main.cpp
+++ b/demo/src/main.cpp
@@ -1,4 +1,4 @@
-#include "RMailObject.h"
+#include "DemoObject.h"
#include "tmp.h"
#include
@@ -16,17 +16,17 @@
int main (int argc, char *argv[])
{
QApplication app(argc, argv);
- KLocalizedString::setApplicationDomain("RMail");
+ KLocalizedString::setApplicationDomain("Demo");
KAboutData aboutData(
// The program name used internally. (componentName)
- QStringLiteral("RMail"),
+ QStringLiteral("Demo"),
// A displayable program name string. (displayName)
- i18n("RMail"),
+ i18n("Demo"),
// The program version string. (version)
QStringLiteral("0.1"),
// Short description of what the app does. (shortDescription)
- i18n("Displays a mails from a maildir"),
+ i18n("Demo application for Rust bindings"),
// The license this code is released under
KAboutLicense::GPL,
// Copyright Statement (copyrightStatement = QString())
@@ -62,21 +62,7 @@ int main (int argc, char *argv[])
view.show();
engine.rootContext()->setContextProperty("fsModel", &model);
- engine.load(QUrl(QStringLiteral("../test.qml")));
+ engine.load(QUrl(QStringLiteral("qrc:///demo.qml")));
return app.exec();
-/*
- RMailObject rmail;
- rmail.setUserName("RMail");
- rmail.userName();
-
- KGuiItem yesButton( rmail.userName(), rmail.userName(),
- i18n( "This is a tooltip" ),
- i18n( "This is a WhatsThis help text." ) );
-
- return
- KMessageBox::questionYesNo
- (0, i18n( "Hello World" ), i18n( "Hello" ), yesButton )
- == KMessageBox::Yes? EXIT_SUCCESS: EXIT_FAILURE;
-*/
}
diff --git a/src/tmp.cpp b/demo/src/tmp.cpp
similarity index 100%
rename from src/tmp.cpp
rename to demo/src/tmp.cpp
diff --git a/src/tmp.h b/demo/src/tmp.h
similarity index 100%
rename from src/tmp.h
rename to demo/src/tmp.h
diff --git a/rust_qt_binding_generator/CMakeLists.txt b/rust_qt_binding_generator/CMakeLists.txt
index 72b0f43..3739a2b 100644
--- a/rust_qt_binding_generator/CMakeLists.txt
+++ b/rust_qt_binding_generator/CMakeLists.txt
@@ -3,3 +3,7 @@ add_executable(rust_qt_binding_generator rust_qt_binding_generator.cpp)
target_link_libraries(rust_qt_binding_generator
Qt5::Core
)
+set_target_properties(rust_qt_binding_generator PROPERTIES
+ CXX_STANDARD 11
+ CXX_STANDARD_REQUIRED ON
+)
diff --git a/rust_qt_binding_generator/rust_qt_binding_generator.cpp b/rust_qt_binding_generator/rust_qt_binding_generator.cpp
index 0197864..2367d47 100644
--- a/rust_qt_binding_generator/rust_qt_binding_generator.cpp
+++ b/rust_qt_binding_generator/rust_qt_binding_generator.cpp
@@ -809,6 +809,7 @@ void writeRustInterface(const Configuration& conf) {
r << QString(R"(/* generated by rust_qt_binding_generator */
#![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)]
+#![allow(unused_imports)]
use libc::{c_int, c_void};
use types::*;
use std::sync::{Arc, Mutex};
@@ -886,7 +887,8 @@ void writeRustImplementation(const Configuration& conf) {
DifferentFileWriter w(rustFile(conf.rustdir, conf.implementationModule),
conf.overwriteImplementation);
QTextStream r(&w.buffer);
- r << QString(R"(use libc::c_int;
+ r << QString(R"(#![allow(unused_imports)]
+use libc::c_int;
use types::*;
use %1::*;
@@ -901,8 +903,9 @@ void writeRustTypes(const Configuration& conf) {
DifferentFileWriter w(rustFile(conf.rustdir, conf.typesModule));
QTextStream r(&w.buffer);
r << QString(R"(/* generated by rust_qt_binding_generator */
+#![allow(dead_code)]
use std::slice;
-use libc::{c_int, c_uint, uint8_t, uint16_t};
+use libc::{c_int, uint8_t, uint16_t};
use std::ptr::null;
use std::marker::PhantomData;
diff --git a/tests/rust_object/src/implementation.rs b/tests/rust_object/src/implementation.rs
index 2bd6f1e..219ac6d 100644
--- a/tests/rust_object/src/implementation.rs
+++ b/tests/rust_object/src/implementation.rs
@@ -1,3 +1,4 @@
+#![allow(unused_imports)]
use libc::c_int;
use types::*;
use interface::*;
diff --git a/tests/rust_object/src/interface.rs b/tests/rust_object/src/interface.rs
index 60e45bb..dc9bd44 100644
--- a/tests/rust_object/src/interface.rs
+++ b/tests/rust_object/src/interface.rs
@@ -1,6 +1,7 @@
/* generated by rust_qt_binding_generator */
#![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)]
+#![allow(unused_imports)]
use libc::{c_int, c_void};
use types::*;
use std::sync::{Arc, Mutex};
diff --git a/tests/rust_object/src/types.rs b/tests/rust_object/src/types.rs
index 98a702f..005b78a 100644
--- a/tests/rust_object/src/types.rs
+++ b/tests/rust_object/src/types.rs
@@ -1,6 +1,7 @@
/* generated by rust_qt_binding_generator */
+#![allow(dead_code)]
use std::slice;
-use libc::{c_int, c_uint, uint8_t, uint16_t};
+use libc::{c_int, uint8_t, uint16_t};
use std::ptr::null;
use std::marker::PhantomData;
diff --git a/tests/rust_object_types/src/implementation.rs b/tests/rust_object_types/src/implementation.rs
index 71a6b25..e484169 100644
--- a/tests/rust_object_types/src/implementation.rs
+++ b/tests/rust_object_types/src/implementation.rs
@@ -1,3 +1,4 @@
+#![allow(unused_imports)]
use libc::c_int;
use types::*;
use interface::*;
diff --git a/tests/rust_object_types/src/interface.rs b/tests/rust_object_types/src/interface.rs
index 41e38e3..9c905f2 100644
--- a/tests/rust_object_types/src/interface.rs
+++ b/tests/rust_object_types/src/interface.rs
@@ -1,6 +1,7 @@
/* generated by rust_qt_binding_generator */
#![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)]
+#![allow(unused_imports)]
use libc::{c_int, c_void};
use types::*;
use std::sync::{Arc, Mutex};
diff --git a/tests/rust_object_types/src/types.rs b/tests/rust_object_types/src/types.rs
index 98a702f..005b78a 100644
--- a/tests/rust_object_types/src/types.rs
+++ b/tests/rust_object_types/src/types.rs
@@ -1,6 +1,7 @@
/* generated by rust_qt_binding_generator */
+#![allow(dead_code)]
use std::slice;
-use libc::{c_int, c_uint, uint8_t, uint16_t};
+use libc::{c_int, uint8_t, uint16_t};
use std::ptr::null;
use std::marker::PhantomData;