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 signal void toast (string message, int timeout = 5);
public Application () {
Object (
application_id: "de.clerie.allesapp",

View File

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

View File

@@ -22,33 +22,37 @@
</object>
</child>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<object class="AdwToastOverlay" id="toast_overlay">
<child>
<object class="AdwBanner">
<property name="revealed">True</property>
<property name="title">Meow meow meow</property>
</object>
</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 class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="AdwBanner">
<property name="revealed">True</property>
<property name="title">Meow meow meow</property>
</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>
</child>
</object>

View File

@@ -23,10 +23,17 @@ public class Allesapp.Window : Adw.ApplicationWindow {
[GtkChild]
private unowned Gtk.Label my_ip_address_label;
[GtkChild]
private unowned Adw.ToastOverlay toast_overlay;
public Window (Gtk.Application app) {
Object (application: app);
}
construct {
app.toast.connect (add_toast);
}
[GtkCallback]
private void on_fetch_my_ip_address () {
@@ -36,7 +43,13 @@ public class Allesapp.Window : Adw.ApplicationWindow {
var input_stream = session.send (msg);
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
});
}
}