Browse Source

use refs

master
yggverse 2 months ago
parent
commit
aad0e266f6
  1. 8
      src/app.rs
  2. 12
      src/app/browser.rs
  3. 6
      src/app/browser/database.rs
  4. 12
      src/app/browser/widget.rs
  5. 20
      src/app/browser/widget/database.rs
  6. 2
      src/app/database.rs

8
src/app.rs

@ -115,7 +115,7 @@ impl App { @@ -115,7 +115,7 @@ impl App {
match database.records() {
Ok(records) => {
for record in records {
browser.restore(record.id);
browser.restore(&record.id);
}
}
Err(error) => panic!("{error}"), // @TODO
@ -138,10 +138,10 @@ impl App { @@ -138,10 +138,10 @@ impl App {
Ok(records) => {
// Cleanup previous session records
for record in records {
match database.delete(record.id) {
match database.delete(&record.id) {
Ok(_) => {
// Delegate clean action to childs
browser.clean(record.id);
browser.clean(&record.id);
}
Err(error) => panic!("{error}"), // @TODO
}
@ -151,7 +151,7 @@ impl App { @@ -151,7 +151,7 @@ impl App {
match database.add() {
Ok(_) => {
// Delegate save action to childs
browser.save(database.last_insert_id());
browser.save(&database.last_insert_id());
}
Err(error) => panic!("{error}"), // @TODO
}

12
src/app/browser.rs

@ -227,17 +227,17 @@ impl Browser { @@ -227,17 +227,17 @@ impl Browser {
}
// Actions
pub fn clean(&self, app_id: i64) {
pub fn clean(&self, app_id: &i64) {
match self.database.records(app_id) {
Ok(records) => {
for record in records {
match self.database.delete(record.id) {
match self.database.delete(&record.id) {
Ok(_) => {
// Delegate clean action to childs
// @TODO
// self.header.clean(record.id);
// self.main.clean(record.id);
self.widget.clean(record.id);
self.widget.clean(&record.id);
}
Err(error) => panic!("{error}"), // @TODO
}
@ -247,11 +247,11 @@ impl Browser { @@ -247,11 +247,11 @@ impl Browser {
}
}
pub fn restore(&self, app_id: i64) {
pub fn restore(&self, app_id: &i64) {
// @TODO
}
pub fn save(&self, app_id: i64) {
pub fn save(&self, app_id: &i64) {
match self.database.add(app_id) {
Ok(_) => {
// Delegate save action to childs
@ -259,7 +259,7 @@ impl Browser { @@ -259,7 +259,7 @@ impl Browser {
// @TODO
// self.header.save(id);
// self.main.save(id);
self.widget.save(id);
self.widget.save(&id);
}
Err(error) => panic!("{error}"), // @TODO
}

6
src/app/browser/database.rs

@ -24,12 +24,12 @@ impl Database { @@ -24,12 +24,12 @@ impl Database {
Ok(Self { connection })
}
pub fn add(&self, app_id: i64) -> Result<usize, Error> {
pub fn add(&self, app_id: &i64) -> Result<usize, Error> {
self.connection
.execute("INSERT INTO `app_browser` (`app_id`) VALUES (?)", [app_id])
}
pub fn records(&self, app_id: i64) -> Result<Vec<Table>, Error> {
pub fn records(&self, app_id: &i64) -> Result<Vec<Table>, Error> {
let mut statement = self
.connection
.prepare("SELECT `id`, `app_id` WHERE `app_id` = ?")?;
@ -51,7 +51,7 @@ impl Database { @@ -51,7 +51,7 @@ impl Database {
Ok(records)
}
pub fn delete(&self, id: i64) -> Result<usize, Error> {
pub fn delete(&self, id: &i64) -> Result<usize, Error> {
self.connection
.execute("DELETE FROM `app_browser` WHERE `id` = ?", [id])
}

12
src/app/browser/widget.rs

@ -45,11 +45,11 @@ impl Widget { @@ -45,11 +45,11 @@ impl Widget {
}
// Actions
pub fn clean(&self, app_browser_id: i64) {
pub fn clean(&self, app_browser_id: &i64) {
match self.database.records(app_browser_id) {
Ok(records) => {
for record in records {
match self.database.delete(record.id) {
match self.database.delete(&record.id) {
Ok(_) => {
// Delegate clean action to childs
// nothing yet..
@ -66,12 +66,12 @@ impl Widget { @@ -66,12 +66,12 @@ impl Widget {
// @TODO
}
pub fn save(&self, app_browser_id: i64) {
pub fn save(&self, app_browser_id: &i64) {
match self.database.add(
app_browser_id,
self.application_window.default_width(),
self.application_window.default_height(),
self.application_window.is_maximized(),
&self.application_window.default_width(),
&self.application_window.default_height(),
&self.application_window.is_maximized(),
) {
Ok(_) => {
// Delegate save action to childs

20
src/app/browser/widget/database.rs

@ -32,10 +32,10 @@ impl Database { @@ -32,10 +32,10 @@ impl Database {
pub fn add(
&self,
app_browser_id: i64,
default_width: i32,
default_height: i32,
is_maximized: bool,
app_browser_id: &i64,
default_width: &i32,
default_height: &i32,
is_maximized: &bool,
) -> Result<usize, Error> {
self.connection.execute(
"INSERT INTO `app_browser_widget` (
@ -46,17 +46,17 @@ impl Database { @@ -46,17 +46,17 @@ impl Database {
) VALUES (?, ?, ?, ?)",
[
app_browser_id,
default_width as i64,
default_height as i64,
&(*default_width as i64),
&(*default_height as i64),
match is_maximized {
true => 1,
false => 0,
true => &1,
false => &0,
},
],
)
}
pub fn records(&self, app_browser_id: i64) -> Result<Vec<Table>, Error> {
pub fn records(&self, app_browser_id: &i64) -> Result<Vec<Table>, Error> {
let mut statement = self.connection.prepare(
"SELECT `id`,
`app_browser_id`,
@ -85,7 +85,7 @@ impl Database { @@ -85,7 +85,7 @@ impl Database {
Ok(records)
}
pub fn delete(&self, id: i64) -> Result<usize, Error> {
pub fn delete(&self, id: &i64) -> Result<usize, Error> {
self.connection
.execute("DELETE FROM `app_browser_widget` WHERE `id` = ?", [id])
}

2
src/app/database.rs

@ -44,7 +44,7 @@ impl Database { @@ -44,7 +44,7 @@ impl Database {
Ok(records)
}
pub fn delete(&self, id: i64) -> Result<usize, Error> {
pub fn delete(&self, id: &i64) -> Result<usize, Error> {
self.connection
.execute("DELETE FROM `app` WHERE `id` = ?", [id])
}

Loading…
Cancel
Save