hamlocator/src/application.vala

82 wiersze
3.0 KiB
Vala

/* application.vala
*
* Copyright 2022 Michał Rudowicz
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Hamlocator {
public class Application : Adw.Application {
private Location location;
private MaidenheadConverter mc;
public Application () {
Object (application_id: "eu.fl9.hamlocator", flags: ApplicationFlags.FLAGS_NONE);
mc = new MaidenheadConverter();
}
construct {
ActionEntry[] action_entries = {
{ "about", this.on_about_action },
{ "preferences", this.on_preferences_action },
{ "quit", this.quit }
};
this.location = new Location();
this.add_action_entries (action_entries, this);
this.set_accels_for_action ("app.quit", {"<primary>q"});
}
public override void activate () {
base.activate ();
var win = (Hamlocator.Window) this.active_window;
if (win == null) {
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);
win.SetLabel("wait...");
win.SetDetails("Getting location");
location.get_current_location.begin((obj, res) => {
var pos = location.get_current_location.end(res);
if (pos.loc == null) {
win.SetLabel("unable to\nget location");
win.SetDetails(@"Reason:\n$(pos.err)");
} else {
win.SetLabel(mc.location_to_maidenhead(pos.loc));
win.SetDetails(@"lat: $(pos.loc.latitude)°\nlon: $(pos.loc.longitude)°");
}
win.SetRefreshButtonEnabled(true);
});
}
private void on_about_action () {
string[] authors = { "Michał Rudowicz" };
Gtk.show_about_dialog (this.active_window,
"program-name", "hamlocator",
"authors", authors,
"version", "0.1.0");
}
private void on_preferences_action () {
var win = (Hamlocator.Window) this.active_window;
win.SetLabel("elo");
}
}
}