3
public class Weather : Gazette.Service {
5
public string weather_id = "";
6
public string weather_unit = "'Celsius'";
9
base (_("Weather Forecast"), "preferences-desktop-online-accounts");
13
Process.spawn_command_line_sync ("gsettings get org.pantheon.gazette.weather weather-id", out weather_id);
14
Process.spawn_command_line_sync ("gsettings get org.pantheon.gazette.weather weather-unit", out weather_unit);
15
weather_id = weather_id.escape("");
18
stderr.printf ("Unable to find settings: %s\n", e.message);
23
var weatherIdLabel = new Gtk.Label ("* "+ _("Location ID") + " :");
24
this.container.attach(weatherIdLabel, 0, 0, 1, 1);
25
weatherIdLabel.set_alignment (1, 0);
28
var weatherIdEntry = new Gtk.Entry ();
29
weatherIdEntry.text = this.weather_id.substring(0, this.weather_id.length-2);
30
this.container.attach(weatherIdEntry, 1, 0, 2, 1);
33
var weatherIdHelp = new Gtk.Label (_("* You can find your city's ID on <a href='http://weather.yahoo.com'>weather.yahoo.com</a>. For example the URL for London is <i>http://weather.yahoo.com/united-kingdom/england/london-44418/</i> so the city's ID is 44418."));
34
weatherIdHelp.set_use_markup (true);
35
weatherIdHelp.set_line_wrap (true);
36
this.container.attach(weatherIdHelp, 0, 10, 3, 1);
37
weatherIdHelp.set_alignment (0, 0);
41
var weatherUnitLabel = new Gtk.Label (_("Unit")+ " :");
42
this.container.attach(weatherUnitLabel, 0, 1, 1, 1);
43
weatherUnitLabel.set_alignment (1, 0);
46
var weatherUnitBox = new Gtk.ComboBoxText ();
47
weatherUnitBox.append_text ("Celsius");
48
weatherUnitBox.append_text ("Fahrenheit");
50
if (this.weather_unit == "'Celsius'")
51
weatherUnitBox.active = 1;
53
weatherUnitBox.active = 0;
54
this.container.attach(weatherUnitBox, 1, 1, 2, 1);
58
var applyButton = new Gtk.Button.with_label (_("Apply"));
59
this.container.attach(applyButton, 1, 2, 1, 1);
60
applyButton.clicked.connect(() => {
62
string str = "gsettings set org.pantheon.gazette.";
63
Process.spawn_command_line_sync (str.concat("weather weather-id '", weatherIdEntry.get_text(), "'"));
64
if (weatherUnitBox.get_active_text() == "Celsius")
65
Process.spawn_command_line_sync (str.concat("weather weather-unit 'Celsius'"));
67
Process.spawn_command_line_sync (str.concat("weather weather-unit 'Fahrenheit'"));
69
Process.spawn_command_line_sync ("killall gazette");
70
Process.spawn_command_line_async ("gazette");
74
stderr.printf ("Unable to find settings: %s\n", e.message);
80
var resetButton = new Gtk.Button.with_label (_("Reset"));
81
this.container.attach(resetButton, 2, 2, 1, 1);
82
resetButton.clicked.connect(() => {
84
Process.spawn_command_line_sync ("gsettings reset org.pantheon.gazette.weather weather-id");
85
Process.spawn_command_line_sync ("gsettings reset org.pantheon.gazette.weather weather-unit");
86
Process.spawn_command_line_sync ("killall gazette");
87
Process.spawn_command_line_async ("gazette");
88
Process.spawn_command_line_sync ("gsettings get org.pantheon.gazette.weather weather-id", out this.weather_id);
89
Process.spawn_command_line_sync ("gsettings get org.pantheon.gazette.weather weather-unit", out this.weather_unit);
90
weather_id = weather_id.escape("");
91
weatherIdEntry.text = this.weather_id.substring(0, this.weather_id.length-2);
92
if (this.weather_unit == "'Celsius'")
93
weatherUnitBox.active = 1;
95
weatherUnitBox.active = 0;
98
stderr.printf ("Unable to find settings: %s\n", e.message);
106
public override void run (File file){
110
FileUtils.get_contents (file.get_path (), out content);
111
}catch (Error e){warning (e.message);}
113
var command = "xdg-open 'http://www.wikipedia.org/wiki/"+content+"'";
117
Process.spawn_command_line_sync (command, out ret);
118
}catch (Error e){error (e.message);}