Add toast overlay with signal

This commit is contained in:
2025-09-27 21:15:56 +02:00
parent 6ac432070c
commit cd8b293005
4 changed files with 48 additions and 27 deletions

View File

@@ -19,6 +19,8 @@
*/ */
public class Allesapp.Application : Adw.Application { public class Allesapp.Application : Adw.Application {
public signal void toast (string message, int timeout = 5);
public Application () { public Application () {
Object ( Object (
application_id: "de.clerie.allesapp", application_id: "de.clerie.allesapp",

View File

@@ -18,11 +18,13 @@
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
public static Allesapp.Application app;
int main (string[] args) { int main (string[] args) {
Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR); Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8"); Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
Intl.textdomain (Config.GETTEXT_PACKAGE); Intl.textdomain (Config.GETTEXT_PACKAGE);
var app = new Allesapp.Application (); app = new Allesapp.Application ();
return app.run (args); return app.run (args);
} }

View File

@@ -22,33 +22,37 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkBox"> <object class="AdwToastOverlay" id="toast_overlay">
<property name="orientation">vertical</property>
<child> <child>
<object class="AdwBanner"> <object class="GtkBox">
<property name="revealed">True</property> <property name="orientation">vertical</property>
<property name="title">Meow meow meow</property> <child>
</object> <object class="AdwBanner">
</child> <property name="revealed">True</property>
<child> <property name="title">Meow meow meow</property>
<object class="AdwClampScrollable">
<property name="child">
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="my_ip_address_label">
<property name="label">Meowwww</property>
</object>
</child>
<child>
<object class="GtkButton" id="fetch_my_ip_address">
<property name="icon-name">processes-symbolic</property>
<property name="label">Fetch my IP address</property>
<signal name="clicked" handler="on_fetch_my_ip_address"/>
</object>
</child>
</object> </object>
</property> </child>
<child>
<object class="AdwClampScrollable">
<property name="child">
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="my_ip_address_label">
<property name="label">Meowwww</property>
</object>
</child>
<child>
<object class="GtkButton" id="fetch_my_ip_address">
<property name="icon-name">processes-symbolic</property>
<property name="label">Fetch my IP address</property>
<signal name="clicked" handler="on_fetch_my_ip_address"/>
</object>
</child>
</object>
</property>
</object>
</child>
</object> </object>
</child> </child>
</object> </object>

View File

@@ -23,10 +23,17 @@ public class Allesapp.Window : Adw.ApplicationWindow {
[GtkChild] [GtkChild]
private unowned Gtk.Label my_ip_address_label; private unowned Gtk.Label my_ip_address_label;
[GtkChild]
private unowned Adw.ToastOverlay toast_overlay;
public Window (Gtk.Application app) { public Window (Gtk.Application app) {
Object (application: app); Object (application: app);
} }
construct {
app.toast.connect (add_toast);
}
[GtkCallback] [GtkCallback]
private void on_fetch_my_ip_address () { private void on_fetch_my_ip_address () {
@@ -36,7 +43,13 @@ public class Allesapp.Window : Adw.ApplicationWindow {
var input_stream = session.send (msg); var input_stream = session.send (msg);
var data_input_stream = new DataInputStream (input_stream); var data_input_stream = new DataInputStream (input_stream);
my_ip_address_label.set_label (data_input_stream.read_line_utf8()); app.toast (data_input_stream.read_line_utf8());
} }
private void add_toast (string message, int timeout) {
toast_overlay.add_toast (new Adw.Toast (message) {
timeout = timeout
});
}
} }