Skip to content

Commit

Permalink
update to libadwaita 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ranfdev committed Feb 12, 2024
1 parent fe3ae28 commit 75c59df
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 150 deletions.
142 changes: 73 additions & 69 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ members = [
[dependencies]
ntfy-daemon = { path = "./ntfy-daemon" }
gettext-rs = { version = "0.7", features = ["gettext-system"] }
gtk = { version = "0.7", package = "gtk4", features = ["gnome_45"] }
gsv = { package = "sourceview5", version = "0.7" }
gtk = { version = "0.8", package = "gtk4", features = ["gnome_45"] }
gsv = { package = "sourceview5", version = "0.8" }
once_cell = "1.14"
tracing = "0.1.37"
tracing-subscriber = "0.3"
adw = { version = "0.5", package = "libadwaita", features = ["v1_4"] }
adw = { version = "0.6", package = "libadwaita", features = ["v1_5"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
capnp = "0.18.0"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ https://ntfy.sh client application to receive everyday's notifications.

The code is split between the GUI and the underlying ntfy-daemon.

## How to run
Use gnome-builder to clone and run the project. Note: after clicking the "run"
button a terminal may appear at the bottom: run the command "notify" in it.
2 changes: 1 addition & 1 deletion build-aux/com.ranfdev.Notify.Devel.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "com.ranfdev.Notify.Devel",
"runtime": "org.gnome.Platform",
"runtime-version": "45",
"runtime-version": "master",
"sdk": "org.gnome.Sdk",
"sdk-extensions": [
"org.freedesktop.Sdk.Extension.rust-stable",
Expand Down
4 changes: 1 addition & 3 deletions data/resources/ui/subscription_info_dialog.blp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Gtk 4.0;
using Adw 1;

template $SubscriptionInfoDialog : Adw.Window {
modal: true;
template $SubscriptionInfoDialog : Adw.Dialog {
title: "Subscription Info";
width-request: 240;
Adw.ToolbarView {
[top]
Adw.HeaderBar {}
Expand Down
2 changes: 1 addition & 1 deletion data/resources/ui/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ menu subscription_menu {
}

template $NotifyWindow : Adw.ApplicationWindow {
width-request: 240;
width-request: 360;
height-request: 360;
Adw.Breakpoint {
condition ("max-width: 640sp")
Expand Down
118 changes: 56 additions & 62 deletions src/widgets/add_subscription_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::cell::RefCell;

use adw::prelude::*;
use adw::subclass::prelude::*;
use glib::once_cell::sync::Lazy;
use glib::subclass::Signal;
use gtk::gio;
use gtk::glib;
use ntfy_daemon::models;
use once_cell::sync::Lazy;

#[derive(Default, Debug, Clone)]
pub struct Widgets {
Expand All @@ -28,14 +28,13 @@ mod imp {
impl ObjectSubclass for AddSubscriptionDialog {
const NAME: &'static str = "AddSubscriptionDialog";
type Type = super::AddSubscriptionDialog;
type ParentType = adw::Window;
type ParentType = adw::Dialog;

fn class_init(klass: &mut Self::Class) {
klass.add_binding_action(
gtk::gdk::Key::Escape,
gtk::gdk::ModifierType::empty(),
"window.close",
None,
);
klass.install_action("default.activate", None, |this, _, _| {
this.emit_subscribe_request();
Expand All @@ -51,13 +50,12 @@ mod imp {
}
}
impl WidgetImpl for AddSubscriptionDialog {}
impl WindowImpl for AddSubscriptionDialog {}
impl AdwWindowImpl for AddSubscriptionDialog {}
impl AdwDialogImpl for AddSubscriptionDialog {}
}

glib::wrapper! {
pub struct AddSubscriptionDialog(ObjectSubclass<imp::AddSubscriptionDialog>)
@extends gtk::Widget, gtk::Window, adw::Window,
@extends gtk::Widget, adw::Dialog,
@implements gio::ActionMap, gio::ActionGroup, gtk::Root;
}

Expand All @@ -75,72 +73,67 @@ impl AddSubscriptionDialog {
fn build_ui(&self) {
let imp = self.imp();
let obj = self.clone();
obj.set_title(Some("Subscribe To Topic"));
obj.set_modal(true);
obj.set_default_width(360);
obj.set_title("Subscribe To Topic");

relm4_macros::view! {
toolbar_view = adw::ToolbarView {
add_top_bar: &adw::HeaderBar::new(),
#[wrap(Some)]
set_content = &adw::Clamp {
#[wrap(Some)]
set_child = &gtk::Box {
set_orientation: gtk::Orientation::Vertical,
set_spacing: 12,
set_margin_end: 12,
set_margin_start: 12,
set_margin_top: 12,
set_margin_bottom: 12,
append = &gtk::Label {
add_css_class: "dim-label",
set_label: "Topics may not be password-protected, so choose a name that's not easy to guess. \
Once subscribed, you can PUT/POST notifications.",
set_wrap: true,
set_xalign: 0.0,
set_wrap_mode: gtk::pango::WrapMode::WordChar
},
append = &gtk::ListBox {
add_css_class: "boxed-list",
append: topic_entry = &adw::EntryRow {
set_title: "Topic",
set_activates_default: true,
add_suffix = &gtk::Button {
set_icon_name: "dice3-symbolic",
set_tooltip_text: Some("Generate name"),
set_valign: gtk::Align::Center,
add_css_class: "flat",
connect_clicked[topic_entry] => move |_| {
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
let mut rng = thread_rng();
let chars: String = (0..10).map(|_| rng.sample(Alphanumeric) as char).collect();
topic_entry.set_text(&chars);
}
}
},
append: server_expander = &adw::ExpanderRow {
set_title: "Custom server...",
set_enable_expansion: imp.init_custom_server.get().is_some(),
set_expanded: imp.init_custom_server.get().is_some(),
set_show_enable_switch: true,
add_row: server_entry = &adw::EntryRow {
set_title: "Server",
set_text: imp.init_custom_server.get().map(|x| x.as_str()).unwrap_or(""),
set_content = &gtk::Box {
set_orientation: gtk::Orientation::Vertical,
set_spacing: 12,
set_margin_end: 12,
set_margin_start: 12,
set_margin_top: 12,
set_margin_bottom: 12,
append = &gtk::Label {
add_css_class: "dim-label",
set_label: "Topics may not be password-protected, so choose a name that's not easy to guess. \
Once subscribed, you can PUT/POST notifications.",
set_wrap: true,
set_xalign: 0.0,
set_wrap_mode: gtk::pango::WrapMode::WordChar
},
append = &gtk::ListBox {
add_css_class: "boxed-list",
append: topic_entry = &adw::EntryRow {
set_title: "Topic",
set_activates_default: true,
add_suffix = &gtk::Button {
set_icon_name: "dice3-symbolic",
set_tooltip_text: Some("Generate name"),
set_valign: gtk::Align::Center,
add_css_class: "flat",
connect_clicked[topic_entry] => move |_| {
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
let mut rng = thread_rng();
let chars: String = (0..10).map(|_| rng.sample(Alphanumeric) as char).collect();
topic_entry.set_text(&chars);
}
}
},
append: sub_btn = &gtk::Button {
set_label: "Subscribe",
add_css_class: "suggested-action",
add_css_class: "pill",
set_halign: gtk::Align::Center,
set_sensitive: false,
connect_clicked[obj] => move |_| {
obj.emit_subscribe_request();
append: server_expander = &adw::ExpanderRow {
set_title: "Custom server...",
set_enable_expansion: imp.init_custom_server.get().is_some(),
set_expanded: imp.init_custom_server.get().is_some(),
set_show_enable_switch: true,
add_row: server_entry = &adw::EntryRow {
set_title: "Server",
set_text: imp.init_custom_server.get().map(|x| x.as_str()).unwrap_or(""),
}
}
},
append: sub_btn = &gtk::Button {
set_label: "Subscribe",
add_css_class: "suggested-action",
add_css_class: "pill",
set_halign: gtk::Align::Center,
set_sensitive: false,
connect_clicked[obj] => move |_| {
obj.emit_subscribe_request();
}
}
},
},
}
Expand Down Expand Up @@ -175,7 +168,8 @@ impl AddSubscriptionDialog {
sub_btn,
});

obj.set_content(Some(&toolbar_view));
obj.set_content_width(480);
obj.set_child(Some(&toolbar_view));
}
pub fn subscription(&self) -> Result<models::Subscription, Vec<ntfy_daemon::Error>> {
let w = { self.imp().widgets.borrow().clone() };
Expand Down
8 changes: 3 additions & 5 deletions src/widgets/subscription_info_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ mod imp {
impl ObjectSubclass for SubscriptionInfoDialog {
const NAME: &'static str = "SubscriptionInfoDialog";
type Type = super::SubscriptionInfoDialog;
type ParentType = adw::Window;
type ParentType = adw::Dialog;

fn class_init(klass: &mut Self::Class) {
klass.bind_template();
klass.add_binding_action(
gtk::gdk::Key::Escape,
gtk::gdk::ModifierType::empty(),
"window.close",
None,
);
}

Expand Down Expand Up @@ -73,13 +72,12 @@ mod imp {
}
}
impl WidgetImpl for SubscriptionInfoDialog {}
impl WindowImpl for SubscriptionInfoDialog {}
impl AdwWindowImpl for SubscriptionInfoDialog {}
impl AdwDialogImpl for SubscriptionInfoDialog {}
}

glib::wrapper! {
pub struct SubscriptionInfoDialog(ObjectSubclass<imp::SubscriptionInfoDialog>)
@extends gtk::Widget, gtk::Window, adw::Window,
@extends gtk::Widget, adw::Dialog,
@implements gio::ActionMap, gio::ActionGroup, gtk::Root;
}

Expand Down
10 changes: 4 additions & 6 deletions src/widgets/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait SpawnWithToast {
);
}

impl<W: glib::IsA<gtk::Widget>> SpawnWithToast for W {
impl<W: IsA<gtk::Widget>> SpawnWithToast for W {
fn spawn_with_near_toast<T, R: std::fmt::Display>(
&self,
f: impl Future<Output = Result<T, R>> + 'static,
Expand Down Expand Up @@ -125,8 +125,7 @@ mod imp {
let this = self.obj().clone();
let dialog =
AddSubscriptionDialog::new(this.selected_subscription().map(|x| x.server()));
dialog.set_transient_for(Some(&self.obj().clone()));
dialog.present();
dialog.present(&self.obj().clone());

let dc = dialog.clone();
dialog.connect_local("subscribe-request", true, move |_| {
Expand Down Expand Up @@ -272,8 +271,7 @@ impl NotifyWindow {
}
fn show_subscription_info(&self) {
let sub = SubscriptionInfoDialog::new(self.selected_subscription().unwrap());
sub.set_transient_for(Some(self));
sub.present();
sub.present(self);
}
fn connect_items_changed(&self) {
let this = self.clone();
Expand Down Expand Up @@ -448,7 +446,7 @@ impl NotifyWindow {
chip
}

fn build_subscription_row(sub: &Subscription) -> impl glib::IsA<gtk::Widget> {
fn build_subscription_row(sub: &Subscription) -> impl IsA<gtk::Widget> {
let b = gtk::Box::builder().spacing(4).build();

let label = gtk::Label::builder()
Expand Down

0 comments on commit 75c59df

Please sign in to comment.