main
Michał Rudowicz 2022-05-13 08:12:41 +02:00
rodzic 2408d9f042
commit d67f935022
3 zmienionych plików z 25 dodań i 6 usunięć

Wyświetl plik

@ -37,20 +37,25 @@ namespace Hamlocator {
public override void activate () {
base.activate ();
var win = this.active_window;
var win = (Hamlocator.Window) this.active_window;
if (win == null) {
win = new Hamlocator.Window (this);
win = new Hamlocator.Window (this, this.refresh_location);
}
refresh_location();
win.present ();
}
private void refresh_location() {
var win = (Hamlocator.Window) this.active_window;
win.SetRefreshButtonEnabled(false);
location.get_current_location.begin((obj, res) => {
var w = (Hamlocator.Window) this.active_window;
GClue.Location pos = location.get_current_location.end(res);
if (pos == null) {
w.SetLabel("unable to get location");
win.SetLabel("unable to get location");
} else {
w.SetLabel(@"got location: lat:$(pos.latitude) lon:$(pos.longitude)");
win.SetLabel(@"got location: lat:$(pos.latitude) lon:$(pos.longitude)");
}
win.SetRefreshButtonEnabled(true);
});
}

Wyświetl plik

@ -6,6 +6,11 @@
<property name="default-height">300</property>
<child type="titlebar">
<object class="GtkHeaderBar" id="header_bar">
<child>
<object class="GtkButton" id="refresh_btn">
<property name="icon-name">view-refresh-symbolic</property>
</object>
</child>
<child type="end">
<object class="GtkMenuButton">
<property name="icon-name">open-menu-symbolic</property>

Wyświetl plik

@ -17,17 +17,26 @@
*/
namespace Hamlocator {
public delegate void TriggerRefreshFunc();
[GtkTemplate (ui = "/eu/fl9/hamlocator/window.ui")]
public class Window : Gtk.ApplicationWindow {
[GtkChild]
private unowned Gtk.Label label;
[GtkChild]
private unowned Gtk.Button refresh_btn;
public Window (Gtk.Application app) {
public Window (Gtk.Application app, TriggerRefreshFunc trigger_refresh) {
Object (application: app);
refresh_btn.clicked.connect(() => { trigger_refresh(); });
}
public void SetLabel(string text) {
label.label = text;
}
public void SetRefreshButtonEnabled(bool e) {
refresh_btn.sensitive = e;
}
}
}