Move main application to demo folder

master
Jos van den Oever 2017-08-12 15:16:10 +02:00
parent b57ece2caf
commit 62512ce321
25 changed files with 138 additions and 110 deletions

View File

@ -1,4 +1,4 @@
project (RMail) project (rust_qt_binding_generator)
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
cmake_policy(SET CMP0046 NEW) 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) 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) string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER)
if(CMAKE_BUILD_TYPE_UPPER STREQUAL DEBUG) if(CMAKE_BUILD_TYPE_UPPER STREQUAL DEBUG)
set(RUST_TARGET_DIR target/debug/) set(RUST_TARGET_DIR target/debug/)
@ -45,47 +43,7 @@ else()
set(RUST_BUILD_FLAG --release) set(RUST_BUILD_FLAG --release)
endif() endif()
add_custom_command( add_subdirectory(rust_qt_binding_generator)
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(tests) add_subdirectory(tests)
add_subdirectory(demo)

View File

@ -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"]

View File

@ -1,7 +1,7 @@
{ {
"cppFile": "src/tmp.cpp", "cppFile": "src/tmp.cpp",
"rust": { "rust": {
"dir": "common-rust", "dir": "rust",
"interfaceModule": "testinterface", "interfaceModule": "testinterface",
"implementationModule": "testimplementation", "implementationModule": "testimplementation",
"typesModule": "types" "typesModule": "types"

72
demo/demo.qml Normal file
View File

@ -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
}
*/
}
}

5
demo/resource_file.qrc Normal file
View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/">
<file>demo.qml</file>
</qresource>
</RCC>

10
demo/rust/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "rust"
version = "0.1.0"
[dependencies]
libc = "*"
[lib]
name = "rust"
crate-type = ["staticlib"]

View File

@ -1,3 +1,4 @@
#![allow(unused_imports)]
use libc::c_int; use libc::c_int;
use types::*; use types::*;
use testinterface::*; use testinterface::*;

View File

@ -1,6 +1,7 @@
/* generated by rust_qt_binding_generator */ /* generated by rust_qt_binding_generator */
#![allow(unknown_lints)] #![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)] #![allow(mutex_atomic, needless_pass_by_value)]
#![allow(unused_imports)]
use libc::{c_int, c_void}; use libc::{c_int, c_void};
use types::*; use types::*;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};

View File

@ -1,6 +1,7 @@
/* generated by rust_qt_binding_generator */ /* generated by rust_qt_binding_generator */
#![allow(dead_code)]
use std::slice; 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::ptr::null;
use std::marker::PhantomData; use std::marker::PhantomData;

View File

@ -1,4 +1,4 @@
#include "RMailObject.h" #include "DemoObject.h"
#include <QSize> #include <QSize>
#include <QDebug> #include <QDebug>
#include <cstdint> #include <cstdint>
@ -64,10 +64,10 @@ namespace {
typedef void (*qvariant_set)(void*, qvariant_t*); typedef void (*qvariant_set)(void*, qvariant_t*);
extern "C" { extern "C" {
RMailObjectInterface* hello_new(RMailObject*, void (*)(RMailObject*)); DemoObjectInterface* hello_new(DemoObject*, void (*)(DemoObject*));
void hello_free(RMailObjectInterface*); void hello_free(DemoObjectInterface*);
void hello_set(RMailObjectInterface*, const uint16_t *, size_t); void hello_set(DemoObjectInterface*, const uint16_t *, size_t);
qstring_t hello_get(RMailObjectInterface*); qstring_t hello_get(DemoObjectInterface*);
RItemModelInterface* ritemmodel_new(RItemModel*, void (*)(RItemModel*)); RItemModelInterface* ritemmodel_new(RItemModel*, void (*)(RItemModel*));
void ritemmodel_free(RItemModelInterface*); void ritemmodel_free(RItemModelInterface*);
@ -78,35 +78,35 @@ extern "C" {
void ritemmodel_data(RItemModelInterface*, qmodelindex_t, int, QVariant*, qvariant_set); void ritemmodel_data(RItemModelInterface*, qmodelindex_t, int, QVariant*, qvariant_set);
} }
RMailObject::RMailObject(QObject *parent): DemoObject::DemoObject(QObject *parent):
QObject(parent), QObject(parent),
d(hello_new(this, d(hello_new(this,
[](RMailObject* o) { emit o->userNameChanged(); } [](DemoObject* o) { emit o->userNameChanged(); }
)) ))
{ {
} }
RMailObject::~RMailObject() { DemoObject::~DemoObject() {
hello_free(d); hello_free(d);
} }
QString QString
RMailObject::userName() const { DemoObject::userName() const {
return hello_get(d); return hello_get(d);
} }
void void
RMailObject::setUserName(const QString& name) { DemoObject::setUserName(const QString& name) {
hello_set(d, name.utf16(), name.size()); hello_set(d, name.utf16(), name.size());
} }
const QVariantMap& const QVariantMap&
RMailObject::tree() const { DemoObject::tree() const {
return m_tree; return m_tree;
} }
void void
RMailObject::setTree(const QVariantMap& tree) { DemoObject::setTree(const QVariantMap& tree) {
m_tree = tree; m_tree = tree;
emit treeChanged(); emit treeChanged();
} }

View File

@ -1,23 +1,23 @@
#ifndef RMAIL_OBJECT_H #ifndef DEMO_OBJECT_H
#define RMAIL_OBJECT_H #define DEMO_OBJECT_H
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QVariantMap> #include <QVariantMap>
#include <QAbstractItemModel> #include <QAbstractItemModel>
class RMailObjectInterface; class DemoObjectInterface;
class RMailObject : public QObject class DemoObject : public QObject
{ {
Q_OBJECT Q_OBJECT
RMailObjectInterface* d; DemoObjectInterface* d;
QVariantMap m_tree; QVariantMap m_tree;
Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged FINAL) Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged FINAL)
Q_PROPERTY(QVariantMap tree READ tree WRITE setTree NOTIFY treeChanged FINAL) Q_PROPERTY(QVariantMap tree READ tree WRITE setTree NOTIFY treeChanged FINAL)
public: public:
explicit RMailObject(QObject *parent = nullptr); explicit DemoObject(QObject *parent = nullptr);
~RMailObject(); ~DemoObject();
QString userName() const; QString userName() const;
void setUserName(const QString &userName); void setUserName(const QString &userName);
@ -53,4 +53,4 @@ signals:
void newDataReady(); void newDataReady();
}; };
#endif // RMAIL_OBJECT_H #endif // DEMO_OBJECT_H

View File

@ -1,4 +1,4 @@
#include "RMailObject.h" #include "DemoObject.h"
#include "tmp.h" #include "tmp.h"
#include <cstdlib> #include <cstdlib>
@ -16,17 +16,17 @@
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
KLocalizedString::setApplicationDomain("RMail"); KLocalizedString::setApplicationDomain("Demo");
KAboutData aboutData( KAboutData aboutData(
// The program name used internally. (componentName) // The program name used internally. (componentName)
QStringLiteral("RMail"), QStringLiteral("Demo"),
// A displayable program name string. (displayName) // A displayable program name string. (displayName)
i18n("RMail"), i18n("Demo"),
// The program version string. (version) // The program version string. (version)
QStringLiteral("0.1"), QStringLiteral("0.1"),
// Short description of what the app does. (shortDescription) // 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 // The license this code is released under
KAboutLicense::GPL, KAboutLicense::GPL,
// Copyright Statement (copyrightStatement = QString()) // Copyright Statement (copyrightStatement = QString())
@ -62,21 +62,7 @@ int main (int argc, char *argv[])
view.show(); view.show();
engine.rootContext()->setContextProperty("fsModel", &model); engine.rootContext()->setContextProperty("fsModel", &model);
engine.load(QUrl(QStringLiteral("../test.qml"))); engine.load(QUrl(QStringLiteral("qrc:///demo.qml")));
return app.exec(); 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;
*/
} }

View File

@ -3,3 +3,7 @@ add_executable(rust_qt_binding_generator rust_qt_binding_generator.cpp)
target_link_libraries(rust_qt_binding_generator target_link_libraries(rust_qt_binding_generator
Qt5::Core Qt5::Core
) )
set_target_properties(rust_qt_binding_generator PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
)

View File

@ -809,6 +809,7 @@ void writeRustInterface(const Configuration& conf) {
r << QString(R"(/* generated by rust_qt_binding_generator */ r << QString(R"(/* generated by rust_qt_binding_generator */
#![allow(unknown_lints)] #![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)] #![allow(mutex_atomic, needless_pass_by_value)]
#![allow(unused_imports)]
use libc::{c_int, c_void}; use libc::{c_int, c_void};
use types::*; use types::*;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@ -886,7 +887,8 @@ void writeRustImplementation(const Configuration& conf) {
DifferentFileWriter w(rustFile(conf.rustdir, conf.implementationModule), DifferentFileWriter w(rustFile(conf.rustdir, conf.implementationModule),
conf.overwriteImplementation); conf.overwriteImplementation);
QTextStream r(&w.buffer); QTextStream r(&w.buffer);
r << QString(R"(use libc::c_int; r << QString(R"(#![allow(unused_imports)]
use libc::c_int;
use types::*; use types::*;
use %1::*; use %1::*;
@ -901,8 +903,9 @@ void writeRustTypes(const Configuration& conf) {
DifferentFileWriter w(rustFile(conf.rustdir, conf.typesModule)); DifferentFileWriter w(rustFile(conf.rustdir, conf.typesModule));
QTextStream r(&w.buffer); QTextStream r(&w.buffer);
r << QString(R"(/* generated by rust_qt_binding_generator */ r << QString(R"(/* generated by rust_qt_binding_generator */
#![allow(dead_code)]
use std::slice; 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::ptr::null;
use std::marker::PhantomData; use std::marker::PhantomData;

View File

@ -1,3 +1,4 @@
#![allow(unused_imports)]
use libc::c_int; use libc::c_int;
use types::*; use types::*;
use interface::*; use interface::*;

View File

@ -1,6 +1,7 @@
/* generated by rust_qt_binding_generator */ /* generated by rust_qt_binding_generator */
#![allow(unknown_lints)] #![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)] #![allow(mutex_atomic, needless_pass_by_value)]
#![allow(unused_imports)]
use libc::{c_int, c_void}; use libc::{c_int, c_void};
use types::*; use types::*;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};

View File

@ -1,6 +1,7 @@
/* generated by rust_qt_binding_generator */ /* generated by rust_qt_binding_generator */
#![allow(dead_code)]
use std::slice; 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::ptr::null;
use std::marker::PhantomData; use std::marker::PhantomData;

View File

@ -1,3 +1,4 @@
#![allow(unused_imports)]
use libc::c_int; use libc::c_int;
use types::*; use types::*;
use interface::*; use interface::*;

View File

@ -1,6 +1,7 @@
/* generated by rust_qt_binding_generator */ /* generated by rust_qt_binding_generator */
#![allow(unknown_lints)] #![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)] #![allow(mutex_atomic, needless_pass_by_value)]
#![allow(unused_imports)]
use libc::{c_int, c_void}; use libc::{c_int, c_void};
use types::*; use types::*;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};

View File

@ -1,6 +1,7 @@
/* generated by rust_qt_binding_generator */ /* generated by rust_qt_binding_generator */
#![allow(dead_code)]
use std::slice; 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::ptr::null;
use std::marker::PhantomData; use std::marker::PhantomData;