From d67f935022b834d383f32f5dd011de4c586cfd7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Rudowicz?= Date: Fri, 13 May 2022 08:12:41 +0200 Subject: [PATCH] Refresh button --- src/application.vala | 15 ++++++++++----- src/window.ui | 5 +++++ src/window.vala | 11 ++++++++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/application.vala b/src/application.vala index 6e68f11..8dab814 100644 --- a/src/application.vala +++ b/src/application.vala @@ -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); }); } diff --git a/src/window.ui b/src/window.ui index 1057ca1..3429e20 100644 --- a/src/window.ui +++ b/src/window.ui @@ -6,6 +6,11 @@ 300 + + + view-refresh-symbolic + + open-menu-symbolic diff --git a/src/window.vala b/src/window.vala index 7321197..9e1fe4f 100644 --- a/src/window.vala +++ b/src/window.vala @@ -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; + } } }