This repository has been archived by the owner on Oct 29, 2019. It is now read-only.
/
accounts.rs
79 lines (62 loc) · 1.63 KB
/
accounts.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
///
/// Blitz Money
///
/// Module for manange accounts of user
///
/// Copyright 2018 Luis Fernando Batels <luisfbatels@gmail.com>
///
use qtbindingsinterface::AccountsList;
use qtbindingsinterface::AccountsEmitter;
use qtbindingsinterface::AccountsTrait;
use backend::storage::LOCKED_STORAGE;
#[derive(Default, Clone)]
struct Account {
bank: String,
id: i32,
name: String,
}
pub struct Accounts {
emit: AccountsEmitter,
#[allow(dead_code)] // Used on qml
model: AccountsList,
list: Vec<Account>,
}
impl AccountsTrait for Accounts {
fn new(emit: AccountsEmitter, model: AccountsList) -> Accounts {
LOCKED_STORAGE.lock().unwrap().start_section("accounts".to_string());
let mut ac = Accounts {
emit: emit,
model: model,
list: [].to_vec()
};
ac.list.push(Account{ bank: "BB".to_string(), id: 10, name: "Conta corrente".to_string()});
ac
}
fn emit(&self) -> &AccountsEmitter {
&self.emit
}
fn row_count(&self) -> usize {
self.list.len()
}
fn bank(&self, index: usize) -> &str {
&self.list[index].bank
}
fn set_bank(&mut self, index: usize, v: String) -> bool {
self.list[index].bank = v;
true
}
fn id(&self, index: usize) -> i32 {
self.list[index].id
}
fn set_id(&mut self, index: usize, v: i32) -> bool {
self.list[index].id = v;
true
}
fn name(&self, index: usize) -> &str {
&self.list[index].name
}
fn set_name(&mut self, index: usize, v: String) -> bool {
self.list[index].name = v;
true
}
}