class GooglePlugin : Plugin {
List<MovieSource> sources;
+ List<string> locations;
+ string last_location;
public override void hello (Gtk.Window window, Osso.Context context) {
stdout.printf ("Google Plugin Loaded.\n");
sources = new List<MovieSource> ();
sources.append (source);
+ locations = null;
+ try {
+ var config_file = Path.build_filename (Environment.get_user_config_dir (), "cinaest", "cinaest.cfg");
+ var keyfile = new KeyFile ();
+ if (keyfile.load_from_file (config_file, KeyFileFlags.NONE)
+ && keyfile.has_group ("GooglePlugin")) {
+ if (keyfile.has_key ("GooglePlugin", "KnownLocations")) {
+ var l = keyfile.get_string_list ("GooglePlugin", "KnownLocations");
+ for (int i = 0; i < l.length; i++)
+ locations.append (l[i]);
+ }
+ if (keyfile.has_key ("GooglePlugin", "LastLocation")) {
+ source.location = last_location = keyfile.get_string ("GooglePlugin", "LastLocation");
+ }
+ }
+ } catch (Error e) {
+ if (!(e is KeyFileError.NOT_FOUND))
+ stdout.printf ("Error loading configuration: %s\n", e.message);
+ }
+
// FIXME - this forces the inclusion of config.h
(void) Config.GETTEXT_PACKAGE;
}
dialog.set_title (_("Google plugin settings"));
var selector = new TouchSelectorEntry.text ();
- selector.append_text ("Berlin");
+ insert_location_sorted (source.location);
+ foreach (string l in locations)
+ selector.append_text (l);
var button = new PickerButton (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL);
button.set_title (_("Location"));
int res = dialog.run ();
if (res == ResponseType.ACCEPT) {
source.location = button.get_value ();
+ if (insert_location_sorted (source.location) || source.location != last_location) {
+ var config_dir = Path.build_filename (Environment.get_user_config_dir (), "cinaest");
+ var config_file = Path.build_filename (config_dir, "cinaest.cfg");
+
+ // Make sure the directory is available
+ DirUtils.create_with_parents (config_dir, 0770);
+
+ var keyfile = new KeyFile ();
+ try {
+ keyfile.load_from_file (config_file, KeyFileFlags.NONE);
+ } catch (Error e) {
+ if (!(e is KeyFileError.NOT_FOUND))
+ stdout.printf ("Error loading configuration: %s\n", e.message);
+ }
+ var l = new string[locations.length ()];
+ for (int i = 0; i < l.length; i++) {
+ l[i] = locations.nth_data (i);
+ }
+ keyfile.set_string_list ("GooglePlugin", "KnownLocations", l);
+ keyfile.set_string ("GooglePlugin", "LastLocation", source.location);
+ last_location = source.location;
+
+ try {
+ var file = File.new_for_path (config_file + ".part");
+ var stream = file.create (FileCreateFlags.REPLACE_DESTINATION, null);
+ var data = keyfile.to_data ();
+
+ stream.write (data, data.length, null);
+ FileUtils.rename (config_file + ".part", config_file);
+ } catch (Error e) {
+ stdout.printf ("Failed to store configuration: %s\n", e.message);
+ }
+ }
}
dialog.destroy ();
}
+ private bool insert_location_sorted (string? location) {
+ if (location == null)
+ return false;
+ if (locations != null) {
+ for (unowned List<string> l = locations.first (); l != null; l = l.next) {
+ if (l.data == location) {
+ return false;
+ }
+ if (l.data > location) {
+ l.insert (location, 0);
+ return true;
+ }
+ }
+ }
+ locations.append (location);
+ return true;
+ }
+
public override unowned string get_name () {
return "Google";
}