Add toast overlay with signal
This commit is contained in:
@@ -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",
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -21,6 +21,8 @@
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwToastOverlay" id="toast_overlay">
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
@@ -54,6 +56,8 @@
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
<property name="default-height">600</property>
|
||||
<property name="default-width">800</property>
|
||||
|
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user