diff --git a/common-rust/src/implementation.rs b/common-rust/src/implementation.rs index 4c3fef5..aefa8ba 100644 --- a/common-rust/src/implementation.rs +++ b/common-rust/src/implementation.rs @@ -1,5 +1,4 @@ -use interface::HelloNotifier; -use interface::HelloTrait; +use interface::*; pub struct Hello { notifier: HelloNotifier, @@ -26,3 +25,15 @@ impl Drop for Hello { fn drop(&mut self) { } } + +pub struct RItemModel { + notifier: RItemModelNotifier +} + +impl RItemModelTrait for RItemModel { + fn create(notifier: RItemModelNotifier) -> Self { + RItemModel { + notifier: notifier + } + } +} diff --git a/common-rust/src/interface.rs b/common-rust/src/interface.rs index f16d938..910615b 100644 --- a/common-rust/src/interface.rs +++ b/common-rust/src/interface.rs @@ -2,6 +2,7 @@ use std::slice; use libc::{uint8_t, uint16_t, size_t}; use implementation::Hello; +use implementation::RItemModel; pub struct HelloQObject {} @@ -32,6 +33,12 @@ pub extern fn hello_new(qobject: *const HelloQObject, changed: fn(*const HelloQO Box::into_raw(Box::new(hello)) } +#[no_mangle] +pub extern fn hello_free(ptr: *mut Hello) { + if ptr.is_null() { return } + unsafe { Box::from_raw(ptr); } +} + #[no_mangle] pub extern fn hello_set(ptr: *mut Hello, s: *const uint16_t, len: size_t) { let (hello, data) = unsafe { @@ -56,8 +63,30 @@ pub extern fn hello_get(ptr: *mut Hello) -> *const uint8_t { hello.get_hello().as_ptr() } +pub struct RItemModelQObject {} + +pub struct RItemModelNotifier { + qobject: *const RItemModelQObject +} + +impl RItemModelNotifier { +} + +pub trait RItemModelTrait { + fn create(notifier: RItemModelNotifier) -> Self; +} + #[no_mangle] -pub extern fn hello_free(ptr: *mut Hello) { +pub extern fn ritemmodel_new(qobject: *const RItemModelQObject) -> *mut RItemModel { + let notifier = RItemModelNotifier { + qobject: qobject + }; + let ritemmodel = RItemModel::create(notifier); + Box::into_raw(Box::new(ritemmodel)) +} + +#[no_mangle] +pub extern fn ritemmodel_free(ptr: *mut RItemModel) { if ptr.is_null() { return } unsafe { Box::from_raw(ptr); } } diff --git a/dev b/dev index 6ea0b6a..3f00c6c 100644 --- a/dev +++ b/dev @@ -1,2 +1,3 @@ #!/usr/bin/bash +rm -rf __nix_qt5__/ nix-shell -p qtcreator cmake ninja gcc rustc cargo qt5.full extra-cmake-modules kdeFrameworks.kwidgetsaddons kdeFrameworks.kcoreaddons kdeFrameworks.ki18n appstream diff --git a/src/RMailObject.cpp b/src/RMailObject.cpp index b1bbc09..43c4901 100644 --- a/src/RMailObject.cpp +++ b/src/RMailObject.cpp @@ -4,10 +4,13 @@ extern "C" { RMailObjectInterface* hello_new(void*, void (*)(RMailObject*)); + void hello_free(RMailObjectInterface*); void hello_set(RMailObjectInterface*, const uint16_t *, size_t); size_t hello_size(RMailObjectInterface*); const char* hello_get(RMailObjectInterface*); - void hello_free(RMailObjectInterface*); + + RItemModelInterface* ritemmodel_new(void*); + void ritemmodel_free(RItemModelInterface*); } RMailObject::RMailObject(QObject *parent): @@ -42,3 +45,34 @@ RMailObject::setTree(const QVariantMap& tree) { m_tree = tree; emit treeChanged(); } + +RItemModel::RItemModel(QObject *parent): + QAbstractItemModel(parent), + d(ritemmodel_new(this)) +{ +} + +RItemModel::~RItemModel() { + ritemmodel_free(d); +} + +int RItemModel::columnCount(const QModelIndex &parent) const +{ + return 0; +} +QVariant RItemModel::data(const QModelIndex &index, int role) const +{ + return 0; +} +QModelIndex RItemModel::index(int row, int column, const QModelIndex &parent) const +{ + return QModelIndex(); +} +QModelIndex RItemModel::parent(const QModelIndex &index) const +{ + return QModelIndex(); +} +int RItemModel::rowCount(const QModelIndex &parent) const +{ + return 0; +} diff --git a/src/RMailObject.h b/src/RMailObject.h index 4f15e19..f1ae001 100644 --- a/src/RMailObject.h +++ b/src/RMailObject.h @@ -4,6 +4,7 @@ #include #include #include +#include class RMailObjectInterface; class RMailObject : public QObject @@ -31,4 +32,19 @@ private: QString m_userName; }; +class RItemModelInterface; +class RItemModel : public QAbstractItemModel { + Q_OBJECT + RItemModelInterface* d; +public: + explicit RItemModel(QObject *parent = nullptr); + ~RItemModel(); + + int columnCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + QModelIndex index(int row, int column, const QModelIndex &parent) const; + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &parent) const; +}; + #endif // RMAIL_OBJECT_H diff --git a/src/rust.h b/src/rust.h deleted file mode 100644 index 450330e..0000000 --- a/src/rust.h +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -extern "C" { - uint32_t add(uint32_t lhs, uint32_t rhs); - void* hello_new(void (*)(void*)); - void hello_set(void*, const uint16_t *, size_t); - size_t hello_size(void*); - const char* hello_get(void*); - void hello_free(void *); -}