Add button to fetch current IP address
This commit is contained in:
@@ -60,15 +60,6 @@ public class Allesapp.Application : Adw.Application {
|
||||
|
||||
private void on_preferences_action () {
|
||||
message ("app.preferences action activated");
|
||||
|
||||
var session = new Soup.Session ();
|
||||
var msg = new Soup.Message ("GET", "http://ip4.clerie.de");
|
||||
|
||||
var input_stream = session.send (msg);
|
||||
var data_input_stream = new DataInputStream (input_stream);
|
||||
|
||||
message (data_input_stream.read_line_utf8());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,50 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!-- Created with Cambalache 0.94.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<!-- interface-name window.ui -->
|
||||
<requires lib="Adw" version="1.0"/>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<requires lib="gio" version="2.0"/>
|
||||
<requires lib="libadwaita" version="1.4"/>
|
||||
<template class="AllesappWindow" parent="AdwApplicationWindow">
|
||||
<property name="title" translatable="yes">Allesapp</property>
|
||||
<property name="default-width">800</property>
|
||||
<property name="default-height">600</property>
|
||||
<property name="content">
|
||||
<object class="AdwToolbarView">
|
||||
<child type="top">
|
||||
<object class="AdwHeaderBar">
|
||||
<child type="end">
|
||||
<object class="GtkMenuButton">
|
||||
<property name="primary">True</property>
|
||||
<property name="icon-name">open-menu-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Main Menu</property>
|
||||
<property name="menu-model">primary_menu</property>
|
||||
<property name="primary">True</property>
|
||||
<property name="tooltip-text" translatable="yes">Main Menu</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<property name="content">
|
||||
<object class="GtkLabel" id="label">
|
||||
<property name="label" translatable="yes">Hello, World!</property>
|
||||
<style>
|
||||
<class name="title-1"/>
|
||||
</style>
|
||||
<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>
|
||||
</property>
|
||||
<property name="default-height">600</property>
|
||||
<property name="default-width">800</property>
|
||||
<property name="title" translatable="yes">Allesapp</property>
|
||||
</template>
|
||||
<menu id="primary_menu">
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Preferences</attribute>
|
||||
<attribute name="action">app.preferences</attribute>
|
||||
<attribute name="label" translatable="yes">_Preferences</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
|
||||
<attribute name="action">win.show-help-overlay</attribute>
|
||||
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_About Allesapp</attribute>
|
||||
<attribute name="action">app.about</attribute>
|
||||
<attribute name="label" translatable="yes">_About Allesapp</attribute>
|
||||
</item>
|
||||
</section>
|
||||
</menu>
|
||||
<object class="GtkButton"/>
|
||||
<object class="AdwClampScrollable"/>
|
||||
</interface>
|
||||
|
@@ -21,9 +21,22 @@
|
||||
[GtkTemplate (ui = "/de/clerie/allesapp/window.ui")]
|
||||
public class Allesapp.Window : Adw.ApplicationWindow {
|
||||
[GtkChild]
|
||||
private unowned Gtk.Label label;
|
||||
private unowned Gtk.Label my_ip_address_label;
|
||||
|
||||
public Window (Gtk.Application app) {
|
||||
Object (application: app);
|
||||
}
|
||||
|
||||
[GtkCallback]
|
||||
private void on_fetch_my_ip_address () {
|
||||
|
||||
var session = new Soup.Session ();
|
||||
var msg = new Soup.Message ("GET", "http://ip6.clerie.de");
|
||||
|
||||
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());
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user