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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
// Furtherance - Track your time without being tracked
// Copyright (C) 2022 Ricky Kresslein <rk@lakoliu.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::{glib, CompositeTemplate};
use glib::subclass;
use crate::ui::FurTasksPage;
use crate::FurtheranceApplication;
use crate::database;
enum View {
Loading,
Empty,
Tasks,
}
mod imp {
use super::*;
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/com/lakoliu/Furtherance/gtk/history_box.ui")]
pub struct FurHistoryBox {
// Template widgets
#[template_child]
pub stack: TemplateChild<gtk::Stack>,
#[template_child]
pub spinner: TemplateChild<gtk::Spinner>,
#[template_child]
pub welcome_page: TemplateChild<adw::StatusPage>,
#[template_child]
pub tasks_page: TemplateChild<FurTasksPage>,
}
#[glib::object_subclass]
impl ObjectSubclass for FurHistoryBox {
const NAME: &'static str = "FurHistoryBox";
type Type = super::FurHistoryBox;
type ParentType = gtk::Box;
fn class_init(klass: &mut Self::Class) {
Self::bind_template(klass);
}
fn instance_init(obj: &subclass::InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for FurHistoryBox {
fn constructed(&self, obj: &Self::Type) {
obj.setup_widgets();
self.parent_constructed(obj);
}
}
impl WidgetImpl for FurHistoryBox {}
impl BoxImpl for FurHistoryBox {}
}
glib::wrapper! {
pub struct FurHistoryBox(
ObjectSubclass<imp::FurHistoryBox>)
@extends gtk::Widget, gtk::Box;
}
impl FurHistoryBox {
fn setup_widgets(&self) {
self.set_view(View::Loading);
let is_saved_task: bool = match database::check_for_tasks() {
Ok(_) => true,
Err(_) => false,
};
if is_saved_task {
self.set_view(View::Tasks);
} else {
self.set_view(View::Empty);
}
}
fn set_view(&self, view: View) {
let imp = imp::FurHistoryBox::from_instance(self);
let app = FurtheranceApplication::default();
app.delete_enabled(false);
imp.spinner.set_spinning(false);
let name = match view {
View::Loading => {
imp.spinner.set_spinning(true);
"loading"
}
View::Empty => "empty",
View::Tasks => {
app.delete_enabled(true);
"tasks"
}
};
imp.stack.set_visible_child_name(name);
}
pub fn create_tasks_page(&self) {
let imp = imp::FurHistoryBox::from_instance(self);
imp.tasks_page.clear_task_list();
let is_saved_task: bool = match database::check_for_tasks() {
Ok(_) => true,
Err(_) => false,
};
if is_saved_task {
self.set_view(View::Loading);
imp.tasks_page.build_task_list();
self.set_view(View::Tasks);
} else {
self.set_view(View::Empty);
}
}
pub fn empty_view(&self) {
self.set_view(View::Empty);
}
}
|