2017-08-13 11:01:53 -07:00
|
|
|
/* generated by rust_qt_binding_generator */
|
2017-08-08 11:07:24 -07:00
|
|
|
#![allow(unknown_lints)]
|
2017-08-13 11:01:53 -07:00
|
|
|
#![allow(mutex_atomic, needless_pass_by_value)]
|
2017-08-25 06:10:07 -07:00
|
|
|
use libc::{c_int, c_void, uint8_t, uint16_t};
|
|
|
|
use std::slice;
|
|
|
|
|
2017-08-05 02:37:01 -07:00
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
use std::ptr::null;
|
2017-08-03 02:18:52 -07:00
|
|
|
|
2017-08-04 13:26:53 -07:00
|
|
|
use implementation::*;
|
2017-08-03 02:18:52 -07:00
|
|
|
|
2017-08-25 06:10:07 -07:00
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct COption<T> {
|
|
|
|
data: T,
|
|
|
|
some: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> From<Option<T>> for COption<T> where T: Default {
|
|
|
|
fn from(t: Option<T>) -> COption <T> {
|
|
|
|
if let Some(v) = t {
|
|
|
|
COption {
|
|
|
|
data: v,
|
|
|
|
some: true
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
COption {
|
|
|
|
data: T::default(),
|
|
|
|
some: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct QString {
|
|
|
|
data: *const uint8_t,
|
|
|
|
len: c_int,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct QStringIn {
|
|
|
|
data: *const uint16_t,
|
|
|
|
len: c_int,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QStringIn {
|
|
|
|
fn convert(&self) -> String {
|
|
|
|
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
|
|
|
|
String::from_utf16_lossy(data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> From<&'a String> for QString {
|
|
|
|
fn from(string: &'a String) -> QString {
|
|
|
|
QString {
|
|
|
|
len: string.len() as c_int,
|
|
|
|
data: string.as_ptr(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct QByteArray {
|
|
|
|
data: *const uint8_t,
|
|
|
|
len: c_int,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QByteArray {
|
|
|
|
fn convert(&self) -> Vec<u8> {
|
|
|
|
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
|
|
|
|
Vec::from(data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> From<&'a Vec<u8>> for QByteArray {
|
|
|
|
fn from(value: &'a Vec<u8>) -> QByteArray {
|
|
|
|
QByteArray {
|
|
|
|
len: value.len() as c_int,
|
|
|
|
data: value.as_ptr(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct QModelIndex {
|
|
|
|
row: c_int,
|
|
|
|
internal_id: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl QModelIndex {
|
|
|
|
fn invalid() -> QModelIndex {
|
|
|
|
QModelIndex {
|
|
|
|
row: -1,
|
|
|
|
internal_id: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn create(row: c_int, id: usize) -> QModelIndex {
|
|
|
|
QModelIndex {
|
|
|
|
row: row,
|
|
|
|
internal_id: id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
pub enum SortOrder {
|
|
|
|
Ascending = 0,
|
|
|
|
Descending = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-13 11:01:53 -07:00
|
|
|
pub struct TreeQObject {}
|
2017-08-03 02:18:52 -07:00
|
|
|
|
2017-08-13 11:01:53 -07:00
|
|
|
#[derive (Clone)]
|
|
|
|
pub struct TreeEmitter {
|
|
|
|
qobject: Arc<Mutex<*const TreeQObject>>,
|
|
|
|
path_changed: fn(*const TreeQObject),
|
2017-08-22 10:17:35 -07:00
|
|
|
new_data_ready: fn(*const TreeQObject, item: usize, valid: bool),
|
2017-08-03 02:18:52 -07:00
|
|
|
}
|
|
|
|
|
2017-08-13 11:01:53 -07:00
|
|
|
unsafe impl Send for TreeEmitter {}
|
2017-08-03 02:18:52 -07:00
|
|
|
|
2017-08-13 11:01:53 -07:00
|
|
|
impl TreeEmitter {
|
|
|
|
fn clear(&self) {
|
|
|
|
*self.qobject.lock().unwrap() = null();
|
|
|
|
}
|
|
|
|
pub fn path_changed(&self) {
|
|
|
|
let ptr = *self.qobject.lock().unwrap();
|
|
|
|
if !ptr.is_null() {
|
|
|
|
(self.path_changed)(ptr);
|
|
|
|
}
|
|
|
|
}
|
2017-08-22 10:17:35 -07:00
|
|
|
pub fn new_data_ready(&self, item: Option<usize>) {
|
2017-08-15 04:06:17 -07:00
|
|
|
let ptr = *self.qobject.lock().unwrap();
|
|
|
|
if !ptr.is_null() {
|
2017-08-22 10:17:35 -07:00
|
|
|
(self.new_data_ready)(ptr, item.unwrap_or(13), item.is_some());
|
2017-08-15 04:06:17 -07:00
|
|
|
}
|
|
|
|
}
|
2017-08-03 02:18:52 -07:00
|
|
|
}
|
|
|
|
|
2017-08-13 11:01:53 -07:00
|
|
|
pub struct TreeUniformTree {
|
|
|
|
qobject: *const TreeQObject,
|
2017-08-14 00:06:05 -07:00
|
|
|
begin_reset_model: fn(*const TreeQObject),
|
|
|
|
end_reset_model: fn(*const TreeQObject),
|
2017-08-22 10:17:35 -07:00
|
|
|
begin_insert_rows: fn(*const TreeQObject, item: usize, valid: bool, usize, usize),
|
2017-08-13 15:26:49 -07:00
|
|
|
end_insert_rows: fn(*const TreeQObject),
|
2017-08-22 10:17:35 -07:00
|
|
|
begin_remove_rows: fn(*const TreeQObject, item: usize, valid: bool, usize, usize),
|
2017-08-13 15:26:49 -07:00
|
|
|
end_remove_rows: fn(*const TreeQObject),
|
2017-08-03 02:18:52 -07:00
|
|
|
}
|
|
|
|
|
2017-08-13 11:01:53 -07:00
|
|
|
impl TreeUniformTree {
|
2017-08-14 00:06:05 -07:00
|
|
|
pub fn begin_reset_model(&self) {
|
|
|
|
(self.begin_reset_model)(self.qobject);
|
|
|
|
}
|
|
|
|
pub fn end_reset_model(&self) {
|
|
|
|
(self.end_reset_model)(self.qobject);
|
|
|
|
}
|
2017-08-22 10:17:35 -07:00
|
|
|
pub fn begin_insert_rows(&self, item: Option<usize>, first: usize, last: usize) {
|
|
|
|
(self.begin_insert_rows)(self.qobject, item.unwrap_or(13), item.is_some(), first, last);
|
2017-08-13 11:01:53 -07:00
|
|
|
}
|
2017-08-13 15:26:49 -07:00
|
|
|
pub fn end_insert_rows(&self) {
|
|
|
|
(self.end_insert_rows)(self.qobject);
|
2017-08-13 11:01:53 -07:00
|
|
|
}
|
2017-08-22 10:17:35 -07:00
|
|
|
pub fn begin_remove_rows(&self, item: Option<usize>, first: usize, last: usize) {
|
|
|
|
(self.begin_remove_rows)(self.qobject, item.unwrap_or(13), item.is_some(), first, last);
|
2017-08-13 11:01:53 -07:00
|
|
|
}
|
2017-08-13 15:26:49 -07:00
|
|
|
pub fn end_remove_rows(&self) {
|
|
|
|
(self.end_remove_rows)(self.qobject);
|
2017-08-08 11:33:46 -07:00
|
|
|
}
|
2017-08-03 12:27:32 -07:00
|
|
|
}
|
|
|
|
|
2017-08-13 11:01:53 -07:00
|
|
|
pub trait TreeTrait {
|
|
|
|
fn create(emit: TreeEmitter, model: TreeUniformTree) -> Self;
|
|
|
|
fn emit(&self) -> &TreeEmitter;
|
2017-08-18 02:44:37 -07:00
|
|
|
fn get_path(&self) -> Option<String>;
|
|
|
|
fn set_path(&mut self, value: Option<String>);
|
2017-08-22 10:17:35 -07:00
|
|
|
fn row_count(&self, Option<usize>) -> usize;
|
|
|
|
fn can_fetch_more(&self, Option<usize>) -> bool { false }
|
|
|
|
fn fetch_more(&mut self, Option<usize>) {}
|
2017-08-22 04:45:34 -07:00
|
|
|
fn sort(&mut self, u8, SortOrder) {}
|
2017-08-22 10:17:35 -07:00
|
|
|
fn index(&self, item: Option<usize>, row: usize) -> usize;
|
|
|
|
fn parent(&self, item: usize) -> Option<usize>;
|
|
|
|
fn row(&self, item: usize) -> usize;
|
2017-08-22 04:45:34 -07:00
|
|
|
fn file_icon(&self, item: usize) -> Vec<u8>;
|
|
|
|
fn file_name(&self, item: usize) -> String;
|
|
|
|
fn file_path(&self, item: usize) -> Option<String>;
|
|
|
|
fn file_permissions(&self, item: usize) -> i32;
|
|
|
|
fn file_size(&self, item: usize) -> Option<u64>;
|
|
|
|
fn file_type(&self, item: usize) -> i32;
|
2017-08-03 02:18:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-08-13 11:01:53 -07:00
|
|
|
pub extern "C" fn tree_new(qobject: *const TreeQObject,
|
|
|
|
path_changed: fn(*const TreeQObject),
|
2017-08-22 10:17:35 -07:00
|
|
|
new_data_ready: fn(*const TreeQObject, item: usize, valid: bool),
|
2017-08-14 00:06:05 -07:00
|
|
|
begin_reset_model: fn(*const TreeQObject),
|
|
|
|
end_reset_model: fn(*const TreeQObject),
|
2017-08-22 10:17:35 -07:00
|
|
|
begin_insert_rows: fn(*const TreeQObject, item: usize, valid: bool,
|
2017-08-22 04:45:34 -07:00
|
|
|
usize,
|
|
|
|
usize),
|
2017-08-13 15:26:49 -07:00
|
|
|
end_insert_rows: fn(*const TreeQObject),
|
2017-08-22 10:17:35 -07:00
|
|
|
begin_remove_rows: fn(*const TreeQObject, item: usize, valid: bool,
|
2017-08-22 04:45:34 -07:00
|
|
|
usize,
|
|
|
|
usize),
|
2017-08-13 15:26:49 -07:00
|
|
|
end_remove_rows: fn(*const TreeQObject))
|
2017-08-13 11:01:53 -07:00
|
|
|
-> *mut Tree {
|
|
|
|
let emit = TreeEmitter {
|
|
|
|
qobject: Arc::new(Mutex::new(qobject)),
|
|
|
|
path_changed: path_changed,
|
2017-08-15 04:06:17 -07:00
|
|
|
new_data_ready: new_data_ready,
|
2017-08-13 11:01:53 -07:00
|
|
|
};
|
|
|
|
let model = TreeUniformTree {
|
|
|
|
qobject: qobject,
|
2017-08-14 00:06:05 -07:00
|
|
|
begin_reset_model: begin_reset_model,
|
|
|
|
end_reset_model: end_reset_model,
|
2017-08-13 15:26:49 -07:00
|
|
|
begin_insert_rows: begin_insert_rows,
|
|
|
|
end_insert_rows: end_insert_rows,
|
|
|
|
begin_remove_rows: begin_remove_rows,
|
|
|
|
end_remove_rows: end_remove_rows,
|
2017-08-13 11:01:53 -07:00
|
|
|
};
|
|
|
|
let d = Tree::create(emit, model);
|
|
|
|
Box::into_raw(Box::new(d))
|
2017-08-03 02:18:52 -07:00
|
|
|
}
|
|
|
|
|
2017-08-13 11:01:53 -07:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn tree_free(ptr: *mut Tree) {
|
|
|
|
Box::from_raw(ptr).emit().clear();
|
2017-08-03 12:27:32 -07:00
|
|
|
}
|
|
|
|
|
2017-08-13 11:01:53 -07:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn tree_path_get(ptr: *const Tree,
|
|
|
|
p: *mut c_void,
|
|
|
|
set: fn(*mut c_void, QString)) {
|
|
|
|
let data = (&*ptr).get_path();
|
2017-08-18 02:44:37 -07:00
|
|
|
if let Some(data) = data {
|
|
|
|
set(p, QString::from(&data));
|
|
|
|
}
|
2017-08-03 12:27:32 -07:00
|
|
|
}
|
|
|
|
|
2017-08-13 11:01:53 -07:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn tree_path_set(ptr: *mut Tree, v: QStringIn) {
|
2017-08-18 02:44:37 -07:00
|
|
|
(&mut *ptr).set_path(Some(v.convert()));
|
2017-08-03 12:27:32 -07:00
|
|
|
}
|
2017-08-18 03:03:02 -07:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn tree_path_set_none(ptr: *mut Tree) {
|
|
|
|
(&mut *ptr).set_path(None);
|
|
|
|
}
|
2017-08-03 12:27:32 -07:00
|
|
|
|
2017-08-03 02:18:52 -07:00
|
|
|
#[no_mangle]
|
2017-08-22 10:17:35 -07:00
|
|
|
pub unsafe extern "C" fn tree_row_count(ptr: *const Tree, item: usize, valid: bool) -> c_int {
|
|
|
|
if valid {
|
|
|
|
(&*ptr).row_count(Some(item)) as c_int
|
|
|
|
} else {
|
|
|
|
(&*ptr).row_count(None) as c_int
|
|
|
|
}
|
2017-08-03 12:27:32 -07:00
|
|
|
}
|
|
|
|
#[no_mangle]
|
2017-08-22 10:17:35 -07:00
|
|
|
pub unsafe extern "C" fn tree_can_fetch_more(ptr: *const Tree, item: usize, valid: bool) -> bool {
|
|
|
|
if valid {
|
|
|
|
(&*ptr).can_fetch_more(Some(item))
|
|
|
|
} else {
|
|
|
|
(&*ptr).can_fetch_more(None)
|
|
|
|
}
|
2017-08-03 02:18:52 -07:00
|
|
|
}
|
2017-08-04 04:21:11 -07:00
|
|
|
#[no_mangle]
|
2017-08-22 10:17:35 -07:00
|
|
|
pub unsafe extern "C" fn tree_fetch_more(ptr: *mut Tree, item: usize, valid: bool) {
|
|
|
|
if valid {
|
|
|
|
(&mut *ptr).fetch_more(Some(item))
|
|
|
|
} else {
|
|
|
|
(&mut *ptr).fetch_more(None)
|
|
|
|
}
|
2017-08-04 04:21:11 -07:00
|
|
|
}
|
2017-08-15 14:12:43 -07:00
|
|
|
#[no_mangle]
|
2017-08-22 04:45:34 -07:00
|
|
|
pub unsafe extern "C" fn tree_sort(ptr: *mut Tree, column: u8, order: SortOrder) {
|
2017-08-15 14:12:43 -07:00
|
|
|
(&mut *ptr).sort(column, order)
|
|
|
|
}
|
2017-08-22 10:17:35 -07:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn tree_index(ptr: *const Tree, item: usize, valid: bool, row: c_int) -> usize {
|
|
|
|
if !valid {
|
|
|
|
(&*ptr).index(None, row as usize)
|
|
|
|
} else {
|
|
|
|
(&*ptr).index(Some(item), row as usize)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn tree_parent(ptr: *const Tree, index: usize) -> QModelIndex {
|
|
|
|
if let Some(parent) = (&*ptr).parent(index) {
|
|
|
|
QModelIndex::create((&*ptr).row(parent) as c_int, parent)
|
|
|
|
} else {
|
|
|
|
QModelIndex::invalid()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn tree_row(ptr: *const Tree, item: usize) -> c_int {
|
|
|
|
(&*ptr).row(item) as c_int
|
|
|
|
}
|
2017-08-04 04:21:11 -07:00
|
|
|
|
|
|
|
#[no_mangle]
|
2017-08-22 10:17:35 -07:00
|
|
|
pub unsafe extern "C" fn tree_data_file_icon(ptr: *const Tree, item: usize,
|
2017-08-13 11:01:53 -07:00
|
|
|
d: *mut c_void,
|
2017-08-21 15:51:48 -07:00
|
|
|
set: fn(*mut c_void, QByteArray)) {
|
2017-08-22 10:17:35 -07:00
|
|
|
let data = (&*ptr).file_icon(item);
|
2017-08-21 15:51:48 -07:00
|
|
|
set(d, QByteArray::from(&data));
|
2017-08-19 04:58:40 -07:00
|
|
|
}
|
|
|
|
|
2017-08-04 04:21:11 -07:00
|
|
|
#[no_mangle]
|
2017-08-22 10:17:35 -07:00
|
|
|
pub unsafe extern "C" fn tree_data_file_name(ptr: *const Tree, item: usize,
|
2017-08-13 11:01:53 -07:00
|
|
|
d: *mut c_void,
|
2017-08-21 15:51:48 -07:00
|
|
|
set: fn(*mut c_void, QString)) {
|
2017-08-22 10:17:35 -07:00
|
|
|
let data = (&*ptr).file_name(item);
|
2017-08-21 15:51:48 -07:00
|
|
|
set(d, QString::from(&data));
|
2017-08-04 04:21:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-08-22 10:17:35 -07:00
|
|
|
pub unsafe extern "C" fn tree_data_file_path(ptr: *const Tree, item: usize,
|
2017-08-12 15:00:48 -07:00
|
|
|
d: *mut c_void,
|
|
|
|
set: fn(*mut c_void, QString)) {
|
2017-08-22 10:17:35 -07:00
|
|
|
let data = (&*ptr).file_path(item);
|
2017-08-18 02:44:37 -07:00
|
|
|
if let Some(data) = data {
|
|
|
|
set(d, QString::from(&data));
|
|
|
|
}
|
2017-08-12 15:00:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-08-22 10:17:35 -07:00
|
|
|
pub unsafe extern "C" fn tree_data_file_permissions(ptr: *const Tree, item: usize) -> i32 {
|
|
|
|
(&*ptr).file_permissions(item).into()
|
2017-08-13 23:54:05 -07:00
|
|
|
}
|
|
|
|
|
2017-08-19 04:58:40 -07:00
|
|
|
#[no_mangle]
|
2017-08-22 10:17:35 -07:00
|
|
|
pub unsafe extern "C" fn tree_data_file_size(ptr: *const Tree, item: usize) -> COption<u64> {
|
|
|
|
(&*ptr).file_size(item).into()
|
2017-08-19 04:58:40 -07:00
|
|
|
}
|
|
|
|
|
2017-08-13 11:01:53 -07:00
|
|
|
#[no_mangle]
|
2017-08-22 10:17:35 -07:00
|
|
|
pub unsafe extern "C" fn tree_data_file_type(ptr: *const Tree, item: usize) -> i32 {
|
|
|
|
(&*ptr).file_type(item).into()
|
2017-08-04 04:21:11 -07:00
|
|
|
}
|