Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the user to define a location #56

Closed
wants to merge 9 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,34 @@ public class MainWindow : Gtk.Dialog {

public void on_location_updated (double latitude, double longitude) {
location = GWeather.Location.get_world ();
location = location.find_nearest_city (latitude, longitude);
if (location != null) {
weather_info.location = location;
weather_info.update ();
stack.visible_child_name = "weather";
string path = (Environment.get_home_dir() + "/.config/nimbus");
var file = File.new_for_path(path);
if (!file.query_exists ()) {
stderr.printf ("File '%s' doesn't exist.\n", file.get_path ());
}
try{
var dis = new DataInputStream (file.read ());
string line;
double latLong[] = {0, 0};
int i = 0;
while ((line = dis.read_line (null)) != null) {
latLong[i] = double.parse(line);
i++;
}
location = location.find_nearest_city (latLong[0], latLong[1]);
if (location != null) {
weather_info.location = location;
weather_info.update ();
stack.visible_child_name = "weather";
}
} catch (Error e){
stderr.printf("Note: config file not present, falling back to geoclue");
location = location.find_nearest_city (latitude, longitude);
if (location != null) {
weather_info.location = location;
weather_info.update ();
stack.visible_child_name = "weather";
}
}
}
}