-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use PwProfileRow widget for profile dropdown and add checkmark for se…
…lected item
- Loading branch information
Showing
5 changed files
with
146 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- SPDX-License-Identifier: GPL-3.0-or-later --> | ||
<interface> | ||
<requires lib="gtk" version="4.0" /> | ||
<requires lib="Adw" version="1.0" /> | ||
<template class="PwProfileRow" parent="GtkBox"> | ||
<child> | ||
<object class="GtkLabel" id="label"> | ||
<property name="xalign">0.0</property> | ||
</object> | ||
</child> | ||
<child> | ||
<object class="GtkImage" id="unavailable_icon"> | ||
<property name="icon-name">action-unavailable-symbolic</property> | ||
</object> | ||
</child> | ||
<child> | ||
<object class="GtkImage" id="checkmark_icon"> | ||
<property name="icon-name">object-select-symbolic</property> | ||
</object> | ||
</child> | ||
</template> | ||
</interface> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
use glib::closure_local; | ||
use gtk::{prelude::*, subclass::prelude::*}; | ||
use std::cell::RefCell; | ||
|
||
use crate::backend::{PwProfileObject, ProfileAvailability}; | ||
|
||
mod imp { | ||
use super::*; | ||
|
||
#[derive(Default, gtk::CompositeTemplate)] | ||
#[template(resource = "/com/saivert/pwvucontrol/gtk/profilerow.ui")] | ||
pub struct PwProfileRow { | ||
#[template_child] | ||
pub label: TemplateChild<gtk::Label>, | ||
#[template_child] | ||
pub unavailable_icon: TemplateChild<gtk::Image>, | ||
#[template_child] | ||
pub checkmark_icon: TemplateChild<gtk::Image>, | ||
|
||
pub(super) signalid: RefCell<Option<glib::SignalHandlerId>>, | ||
} | ||
|
||
#[glib::object_subclass] | ||
impl ObjectSubclass for PwProfileRow { | ||
const NAME: &'static str = "PwProfileRow"; | ||
type Type = super::PwProfileRow; | ||
type ParentType = gtk::Box; | ||
|
||
fn class_init(klass: &mut Self::Class) { | ||
klass.bind_template(); | ||
} | ||
|
||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) { | ||
obj.init_template(); | ||
} | ||
} | ||
|
||
impl ObjectImpl for PwProfileRow {} | ||
impl WidgetImpl for PwProfileRow {} | ||
impl BoxImpl for PwProfileRow {} | ||
impl PwProfileRow {} | ||
} | ||
|
||
glib::wrapper! { | ||
pub struct PwProfileRow(ObjectSubclass<imp::PwProfileRow>) | ||
@extends gtk::Box, gtk::Widget, | ||
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable; | ||
} | ||
|
||
impl PwProfileRow { | ||
pub(crate) fn new() -> Self { | ||
glib::Object::builder().build() | ||
} | ||
|
||
pub fn setup(&self, item: >k::ListItem, list: bool) { | ||
let label = self.imp().label.get(); | ||
let unavailable_icon = self.imp().unavailable_icon.get(); | ||
|
||
if !list { | ||
label.set_ellipsize(gtk::pango::EllipsizeMode::End); | ||
} | ||
|
||
item.property_expression("item") | ||
.chain_property::<PwProfileObject>("description") | ||
.bind(&label, "label", gtk::Widget::NONE); | ||
|
||
let icon_closure = closure_local!(|_: Option<glib::Object>, availability: ProfileAvailability| { | ||
availability == ProfileAvailability::No | ||
}); | ||
|
||
item.property_expression("item") | ||
.chain_property::<PwProfileObject>("availability") | ||
.chain_closure::<bool>(icon_closure) | ||
.bind(&unavailable_icon, "visible", glib::Object::NONE); | ||
} | ||
|
||
pub fn set_selected(&self, selected: bool) { | ||
self.imp().checkmark_icon.set_opacity(if selected {1.0} else {0.0}); | ||
} | ||
|
||
pub fn set_handlerid(&self, id: Option<glib::SignalHandlerId>) { | ||
self.imp().signalid.replace(id); | ||
} | ||
} |