Initial location services support

main
Michał Rudowicz 2022-05-12 16:50:22 +02:00
rodzic f38dc91554
commit 29079a6da4
5 zmienionych plików z 50 dodań i 5 usunięć

Wyświetl plik

@ -9,7 +9,8 @@
"--share=ipc",
"--socket=fallback-x11",
"--device=dri",
"--socket=wayland"
"--socket=wayland",
"--system-talk-name=org.freedesktop.GeoClue2"
],
"cleanup" : [
"/include",
@ -31,9 +32,21 @@
"sources" : [
{
"type" : "git",
"url" : "file:///home/michal/Projects/hamlocator"
"url" : "."
}
]
},
{
"name": "geocode-glib",
"buildsystem": "meson",
"sources": [
{
"type": "git",
"url": "https://github.com/GNOME/geocode-glib.git",
"tag": "3.26.2",
"commit": "34f420cbe1ff3f45fde9179ba07e0259b9ce505b"
}
]
}
]
}

Wyświetl plik

@ -10,8 +10,6 @@ i18n = import('i18n')
gnome = import('gnome')
subdir('data')
subdir('src')
subdir('po')

Wyświetl plik

@ -18,6 +18,8 @@
namespace Hamlocator {
public class Application : Adw.Application {
private Location location;
public Application () {
Object (application_id: "eu.fl9.hamlocator", flags: ApplicationFlags.FLAGS_NONE);
}
@ -28,6 +30,7 @@ namespace Hamlocator {
{ "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"});
}
@ -39,6 +42,11 @@ namespace Hamlocator {
win = new Hamlocator.Window (this);
}
win.present ();
location.get_current_location.begin((obj, loc) => {
var w = (Hamlocator.Window) this.active_window;
w.SetLabel("got location");
});
}
private void on_about_action () {

24
src/location.vala 100644
Wyświetl plik

@ -0,0 +1,24 @@
// Taken from https://github.com/ryonakano/atlas/blob/main/src/GeoClue.vala
namespace Hamlocator {
public class Location : Object {
private GClue.Simple? simple;
public Location () {
}
public async GClue.Location? get_current_location () {
if (simple == null) {
try {
simple = yield new GClue.Simple ("eu.fl9.hamlocator", GClue.AccuracyLevel.NEIGHBORHOOD, null);
} catch (Error e) {
warning ("Failed to connect to GeoClue2 service: %s", e.message);
return null;
}
}
return simple.get_location ();
}
}
}

Wyświetl plik

@ -2,10 +2,12 @@ hamlocator_sources = [
'main.vala',
'window.vala',
'application.vala',
'location.vala'
]
hamlocator_deps = [
dependency('libadwaita-1', version: '>= 1.0'),
dependency('libgeoclue-2.0'),
]
gnome = import('gnome')
@ -16,6 +18,6 @@ hamlocator_sources += gnome.compile_resources('hamlocator-resources',
)
executable('hamlocator', hamlocator_sources,
vala_args: '--target-glib=2.50', dependencies: hamlocator_deps,
vala_args: '--target-glib=2.50 --pkg=gio-2.0', dependencies: hamlocator_deps,
install: true,
)