hamlocator/src/application.vala

76 wiersze
2.8 KiB
Vala
Czysty Zwykły widok Historia

2022-05-11 20:00:28 +00:00
/* 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 {
2022-05-12 14:50:22 +00:00
private Location location;
private MaidenheadConverter mc;
2022-05-12 14:50:22 +00:00
2022-05-11 20:00:28 +00:00
public Application () {
Object (application_id: "eu.fl9.hamlocator", flags: ApplicationFlags.FLAGS_NONE);
mc = new MaidenheadConverter();
2022-05-11 20:00:28 +00:00
}
construct {
ActionEntry[] action_entries = {
{ "about", this.on_about_action },
{ "quit", this.quit }
};
2022-05-12 14:50:22 +00:00
this.location = new Location();
2022-05-11 20:00:28 +00:00
this.add_action_entries (action_entries, this);
this.set_accels_for_action ("app.quit", {"<primary>q"});
}
public override void activate () {
base.activate ();
2022-05-13 06:12:41 +00:00
var win = (Hamlocator.Window) this.active_window;
2022-05-11 20:00:28 +00:00
if (win == null) {
2022-05-13 06:12:41 +00:00
win = new Hamlocator.Window (this, this.refresh_location);
2022-05-11 20:00:28 +00:00
}
2022-05-13 06:12:41 +00:00
refresh_location();
2022-05-11 20:00:28 +00:00
win.present ();
2022-05-13 06:12:41 +00:00
}
2022-05-12 14:50:22 +00:00
2022-05-13 06:12:41 +00:00
private void refresh_location() {
var win = (Hamlocator.Window) this.active_window;
win.SetRefreshButtonEnabled(false);
2022-05-14 16:53:05 +00:00
win.SetLabel("wait...");
win.SetDetails("Getting location");
2022-05-12 15:03:24 +00:00
location.get_current_location.begin((obj, res) => {
2022-05-14 16:53:05 +00:00
var pos = location.get_current_location.end(res);
if (pos.loc == null) {
win.SetLabel("unable to\nget location");
win.SetDetails(@"Reason:\n$(pos.err)");
2022-05-12 15:03:24 +00:00
} else {
win.SetLabel(mc.location_to_maidenhead(pos.loc));
2022-05-14 16:53:05 +00:00
win.SetDetails(@"lat: $(pos.loc.latitude)°\nlon: $(pos.loc.longitude)°");
2022-05-12 15:03:24 +00:00
}
2022-05-13 06:12:41 +00:00
win.SetRefreshButtonEnabled(true);
2022-05-12 14:50:22 +00:00
});
2022-05-11 20:00:28 +00:00
}
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");
}
}
}