Debian Codegraph @

src/ui/folder_page.rs

raw ◀ ▶
1 Debian patch touch this file
1 // Fragments - folder_page.rs
•2 // Copyright (C) 2022-2025 Felix Häcker <[email protected]>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17 use std::cell::{Cell, OnceCell};
18
19 use adw::prelude::*;
20 use adw::subclass::prelude::*;
21 use glib::Properties;
22 use gtk::glib;
23 use transmission_gobject::TrFile;
24
25 use super::FrgFolderPageContents;
26 use crate::model::FrgFileSorter;
27
28 mod imp {
29 use super::*;
30
31 #[derive(Debug, Default, Properties)]
32 #[properties(wrapper_type = super::FrgFolderPage)]
33 pub struct FrgFolderPage {
34 #[property(get, set, construct_only)]
35 file: OnceCell<TrFile>,
36 #[property(get, set, construct_only)]
37 sorter: OnceCell<FrgFileSorter>,
38
39 scroll_pos: Cell<f64>,
40 }
41
42 #[glib::object_subclass]
43 impl ObjectSubclass for FrgFolderPage {
44 const NAME: &'static str = "FrgFolderPage";
45 type ParentType = adw::NavigationPage;
46 type Type = super::FrgFolderPage;
47 }
48
49 #[glib::derived_properties]
50 impl ObjectImpl for FrgFolderPage {
51 fn constructed(&self) {
52 self.parent_constructed();
53
54 let title = self.obj().file().title();
55 self.obj().set_title(&title);
56 }
57 }
58
59 impl WidgetImpl for FrgFolderPage {}
60
61 impl NavigationPageImpl for FrgFolderPage {
62 fn showing(&self) {
63 let obj = self.obj();
64
65 let contents =
66 FrgFolderPageContents::new(&obj.file(), &obj.sorter(), self.scroll_pos.get());
67 obj.set_child(Some(&contents));
68 }
69
70 fn hidden(&self) {
71 let contents = self
72 .obj()
73 .child()
74 .and_downcast::<FrgFolderPageContents>()
75 .unwrap();
76 self.scroll_pos.set(contents.scroll_pos());
77
78 self.obj().set_child(gtk::Widget::NONE);
79 }
80 }
81 }
82
83 glib::wrapper! {
84 pub struct FrgFolderPage(ObjectSubclass<imp::FrgFolderPage>)
•85 @extends gtk::Widget, adw::NavigationPage,
86 @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
87 }
88
89 impl FrgFolderPage {
90 pub fn new(file: &TrFile, sorter: &FrgFileSorter) -> Self {
91 glib::Object::builder()
92 .property("file", file)
93 .property("sorter", sorter)
94 .build()
95 }
96 }