Move main application to demo folder
parent
b57ece2caf
commit
62512ce321
|
@ -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)
|
||||
|
||||
|
|
|
@ -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"]
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"cppFile": "src/tmp.cpp",
|
||||
"rust": {
|
||||
"dir": "common-rust",
|
||||
"dir": "rust",
|
||||
"interfaceModule": "testinterface",
|
||||
"implementationModule": "testimplementation",
|
||||
"typesModule": "types"
|
|
@ -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
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>demo.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
libc = "*"
|
||||
|
||||
[lib]
|
||||
name = "rust"
|
||||
crate-type = ["staticlib"]
|
|
@ -1,3 +1,4 @@
|
|||
#![allow(unused_imports)]
|
||||
use libc::c_int;
|
||||
use types::*;
|
||||
use testinterface::*;
|
|
@ -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};
|
|
@ -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;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include "RMailObject.h"
|
||||
#include "DemoObject.h"
|
||||
#include <QSize>
|
||||
#include <QDebug>
|
||||
#include <cstdint>
|
||||
|
@ -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();
|
||||
}
|
|
@ -1,23 +1,23 @@
|
|||
#ifndef RMAIL_OBJECT_H
|
||||
#define RMAIL_OBJECT_H
|
||||
#ifndef DEMO_OBJECT_H
|
||||
#define DEMO_OBJECT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QVariantMap>
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
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
|
|
@ -1,4 +1,4 @@
|
|||
#include "RMailObject.h"
|
||||
#include "DemoObject.h"
|
||||
#include "tmp.h"
|
||||
#include <cstdlib>
|
||||
|
||||
|
@ -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;
|
||||
*/
|
||||
}
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#![allow(unused_imports)]
|
||||
use libc::c_int;
|
||||
use types::*;
|
||||
use interface::*;
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#![allow(unused_imports)]
|
||||
use libc::c_int;
|
||||
use types::*;
|
||||
use interface::*;
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue