rino/src/tab.rs
2024-06-04 19:57:27 +02:00

69 lines
1.9 KiB
Rust

// xmpp-client: A sample GTK client in Rust
// Copyright (C) 2024 Link Mauve <linkmauve@linkmauve.fr>
//
// 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 <http://www.gnu.org/licenses/>.
use gtk::glib;
mod imp {
use gtk::glib;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use std::cell::RefCell;
#[derive(glib::Properties)]
#[properties(wrapper_type = super::Tab)]
pub struct Tab {
#[property(get, set)]
avatar_hash: RefCell<Option<String>>,
#[property(get, construct_only)]
jid: RefCell<String>,
#[property(get, set)]
name: RefCell<String>,
}
impl Default for Tab {
fn default() -> Self {
Tab {
avatar_hash: RefCell::new(None),
jid: RefCell::new(String::new()),
name: RefCell::new(String::new()),
}
}
}
#[glib::object_subclass]
impl ObjectSubclass for Tab {
const NAME: &'static str = "Tab";
type Type = super::Tab;
type ParentType = glib::Object;
}
#[glib::derived_properties]
impl ObjectImpl for Tab {}
}
glib::wrapper! {
pub struct Tab(ObjectSubclass<imp::Tab>);
}
impl Tab {
pub fn new(jid: &str, name: &str) -> Self {
glib::Object::builder()
.property("jid", jid)
.property("name", name)
.build()
}
}