fractal/session/view/content/explore/
server_row.rs1use gtk::{glib, prelude::*, subclass::prelude::*, CompositeTemplate};
2
3use super::ExploreServer;
4use crate::utils::TemplateCallbacks;
5
6mod imp {
7 use std::cell::RefCell;
8
9 use glib::subclass::InitializingObject;
10
11 use super::*;
12
13 #[derive(Debug, Default, CompositeTemplate, glib::Properties)]
14 #[template(resource = "/org/gnome/Fractal/ui/session/view/content/explore/server_row.ui")]
15 #[properties(wrapper_type = super::ExploreServerRow)]
16 pub struct ExploreServerRow {
17 #[template_child]
18 remove_button: TemplateChild<gtk::Button>,
19 #[property(get, set = Self::set_server, construct_only)]
21 server: RefCell<Option<ExploreServer>>,
22 }
23
24 #[glib::object_subclass]
25 impl ObjectSubclass for ExploreServerRow {
26 const NAME: &'static str = "ExploreServerRow";
27 type Type = super::ExploreServerRow;
28 type ParentType = gtk::ListBoxRow;
29
30 fn class_init(klass: &mut Self::Class) {
31 Self::bind_template(klass);
32 TemplateCallbacks::bind_template_callbacks(klass);
33 }
34
35 fn instance_init(obj: &InitializingObject<Self>) {
36 obj.init_template();
37 }
38 }
39
40 #[glib::derived_properties]
41 impl ObjectImpl for ExploreServerRow {}
42
43 impl WidgetImpl for ExploreServerRow {}
44 impl ListBoxRowImpl for ExploreServerRow {}
45
46 impl ExploreServerRow {
47 fn set_server(&self, server: ExploreServer) {
49 if let Some(server_string) = server.server_string() {
50 self.remove_button.set_action_target(Some(server_string));
51 self.remove_button
52 .set_action_name(Some("explore-servers-popover.remove-server"));
53 }
54
55 self.server.replace(Some(server));
56 }
57 }
58}
59
60glib::wrapper! {
61 pub struct ExploreServerRow(ObjectSubclass<imp::ExploreServerRow>)
63 @extends gtk::Widget, gtk::ListBoxRow, @implements gtk::Accessible;
64}
65
66impl ExploreServerRow {
67 pub fn new(server: &ExploreServer) -> Self {
68 glib::Object::builder().property("server", server).build()
69 }
70}