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