[gnome-weather/wip/christopherdavis/es6: 6/9] Use ES6 classes



commit 5ffa4deca16c0c627a5d8ba1b5086ced41efc5e9
Author: Christopher Davis <brainblasted disroot org>
Date:   Fri Feb 22 02:53:49 2019 -0500

    Use ES6 classes
    
    The way we set up our classes was old and too verbose. Using
    ES6 classes allows our code to be cleaner.

 src/app/city.js           | 82 +++++++++++++++++++++++------------------------
 src/app/forecast.js       | 30 ++++++++---------
 src/app/main.js           | 47 +++++++++++++--------------
 src/app/weeklyForecast.js | 23 +++++++------
 src/app/window.js         | 47 +++++++++++++--------------
 src/app/world.js          | 36 ++++++++++-----------
 src/service/main.js       | 39 +++++++++++-----------
 src/shared/world.js       | 78 ++++++++++++++++++++++----------------------
 8 files changed, 185 insertions(+), 197 deletions(-)
---
diff --git a/src/app/city.js b/src/app/city.js
index ee49168..0e75cf2 100644
--- a/src/app/city.js
+++ b/src/app/city.js
@@ -19,8 +19,8 @@
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
 const Gnome = imports.gi.GnomeDesktop;
+const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
 
 const Forecast = imports.app.forecast;
 const WForecast = imports.app.weeklyForecast;
@@ -31,9 +31,7 @@ const SPINNER_SIZE = 128;
 
 const SCROLLING_ANIMATION_TIME = 400000; //us
 
-var WeatherWidget = new Lang.Class({
-    Name: 'WeatherWidget',
-    Extends: Gtk.Frame,
+var WeatherWidget = GObject.registerClass({
     Template: 'resource:///org/gnome/Weather/weather-widget.ui',
     InternalChildren: ['contentFrame', 'outerGrid', 'conditionsImage',
                        'temperatureLabel', 'conditionsLabel',
@@ -41,11 +39,12 @@ var WeatherWidget = new Lang.Class({
                        'leftButton', 'rightButton',
                        'forecast-today-grid', 'forecast-tomorrow-grid',
                        'forecast-today', 'forecast-tomorrow'],
+}, class WeatherWidget extends Gtk.Frame {
 
-    _init: function(params) {
+    _init(params) {
         params = Params.fill(params, { shadow_type: Gtk.ShadowType.NONE,
                                        name: 'weather-page' });
-        this.parent(params);
+        super._init(params);
 
         this._currentStyle = null;
         this._info = null;
@@ -100,9 +99,9 @@ var WeatherWidget = new Lang.Class({
 
             this._beginScrollAnimation(target);
         });
-    },
+    }
 
-    _syncLeftRightButtons: function() {
+    _syncLeftRightButtons() {
         let hadjustment = this._forecastStack.visible_child.get_hadjustment();
         if ((hadjustment.get_upper() - hadjustment.get_lower()) == hadjustment.page_size) {
             this._leftButton.set_sensitive(false);
@@ -117,9 +116,9 @@ var WeatherWidget = new Lang.Class({
             this._leftButton.set_sensitive(true);
             this._rightButton.set_sensitive(true);
         }
-    },
+    }
 
-    _beginScrollAnimation: function(target) {
+    _beginScrollAnimation(target) {
         let start = this.get_frame_clock().get_frame_time();
         let end = start + SCROLLING_ANIMATION_TIME;
 
@@ -127,9 +126,9 @@ var WeatherWidget = new Lang.Class({
             this.remove_tick_callback(this._tickId);
 
         this._tickId = this.add_tick_callback(() => this._animate(target, start, end));
-    },
+    }
 
-    _animate: function(target, start, end) {
+    _animate(target, start, end) {
         let hadjustment = this._forecastStack.visible_child.get_hadjustment();
         let value = hadjustment.value;
         let t = 1.0;
@@ -145,9 +144,9 @@ var WeatherWidget = new Lang.Class({
             this._tickId = 0;
             return false;
         }
-    },
+    }
 
-    clear: function() {
+    clear() {
         for (let t of ['today', 'tomorrow'])
             this._forecasts[t].clear();
 
@@ -155,23 +154,23 @@ var WeatherWidget = new Lang.Class({
             this.remove_tick_callback(this._tickId);
             this._tickId = 0;
         }
-    },
+    }
 
-    _getStyleClass: function(info) {
+    _getStyleClass(info) {
         let icon = info.get_icon_name();
         let name = icon.replace(/(-\d{3})/, "");
         return name;
-    },
+    }
 
-    setTimeVisible: function(visible) {
+    setTimeVisible(visible) {
         this._timeGrid.visible = visible;
-    },
+    }
 
-    setTime: function(time) {
+    setTime(time) {
         this._timeLabel.label = time;
-    },
+    }
 
-    update: function(info) {
+    update(info) {
         this._info = info;
 
         this._conditionsLabel.label = Util.getWeatherConditions(info);
@@ -201,14 +200,13 @@ var WeatherWidget = new Lang.Class({
     }
 });
 
-var WeatherView = new Lang.Class({
-    Name: 'WeatherView',
-    Extends: Gtk.Stack,
+var WeatherView = GObject.registerClass({
     Template: 'resource:///org/gnome/Weather/city.ui',
-    InternalChildren: ['spinner'],
+    InternalChildren: ['spinner']
+}, class WeatherView extends Gtk.Stack {
 
-    _init: function(params) {
-        this.parent(params);
+    _init(params) {
+        super._init(params);
 
         this._infoPage = new WeatherWidget();
         this.add_named(this._infoPage, 'info');
@@ -222,11 +220,11 @@ var WeatherView = new Lang.Class({
         this._clockHandlerId = 0;
 
         this._desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
-    },
+    }
 
     get info() {
         return this._info;
-    },
+    }
 
     set info(info) {
         if (this._updateId) {
@@ -243,32 +241,32 @@ var WeatherView = new Lang.Class({
             if (info.is_valid())
                 this._onUpdate(info);
         }
-    },
+    }
 
-    _onDestroy: function() {
+    _onDestroy() {
         if (this._updateId) {
             this._info.disconnect(this._updateId);
             this._updateId = 0;
         }
-    },
+    }
 
-    update: function() {
+    update() {
         this.visible_child_name = 'loading';
         this._spinner.start();
         this._infoPage.clear();
 
         getApp().model.updateInfo(this._info);
-    },
+    }
 
-    _onUpdate: function(info) {
+    _onUpdate(info) {
         this._infoPage.clear();
         this._infoPage.update(info);
         this._updateTime();
         this._spinner.stop();
         this.visible_child_name = 'info';
-    },
+    }
 
-    setTimeVisible: function(visible) {
+    setTimeVisible(visible) {
         if (this._clockHandlerId && !visible) {
             this._wallClock.disconnect(this._clockHandlerId);
             this._clockHandlerId = 0;
@@ -279,13 +277,13 @@ var WeatherView = new Lang.Class({
         }
 
         this._infoPage.setTimeVisible(visible);
-    },
+    }
 
-    _updateTime: function() {
+    _updateTime() {
         this._infoPage.setTime(this._getTime());
-    },
+    }
 
-    _getTime: function() {
+    _getTime() {
         if (this._info != null) {
             let location = this._info.location;
             let tz = GLib.TimeZone.new(location.get_timezone().get_tzid());
diff --git a/src/app/forecast.js b/src/app/forecast.js
index d39f27e..6263c89 100644
--- a/src/app/forecast.js
+++ b/src/app/forecast.js
@@ -18,8 +18,8 @@
 
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
 
 const Params = imports.misc.params;
 const Util = imports.misc.util;
@@ -27,13 +27,11 @@ const Util = imports.misc.util;
 // In microseconds
 const ONE_HOUR = 3600*1000*1000;
 
-var ForecastBox = new Lang.Class({
-    Name: 'ForecastBox',
-    Extends: Gtk.Frame,
+var ForecastBox = GObject.registerClass(class ForecastBox extends Gtk.Frame {
 
-    _init: function(params) {
+    _init(params) {
         params = Params.fill(params, { shadow_type: Gtk.ShadowType.NONE });
-        this.parent(params);
+        super._init(params);
         this.get_accessible().accessible_name = _("Forecast");
 
         this._settings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
@@ -47,11 +45,11 @@ var ForecastBox = new Lang.Class({
         this.add(this._grid);
 
         this._hasForecastInfo = false;
-    },
+    }
 
     // Ensure that infos are sufficiently spaced, and
     // remove infos for the wrong day
-    _preprocess: function(now, infos) {
+    _preprocess(now, infos) {
         let ret = [];
         let i;
         let current;
@@ -91,9 +89,9 @@ var ForecastBox = new Lang.Class({
         }
 
         return ret;
-    },
+    }
 
-    update: function(infos, day) {
+    update(infos, day) {
         let now = GLib.DateTime.new_now_local();
         if (day == 'tomorrow')
             now = now.add_days(1);
@@ -115,9 +113,9 @@ var ForecastBox = new Lang.Class({
                                         visible: true });
             this._grid.attach(label, 0, 0, 1, 1);
         }
-    },
+    }
 
-    _addOneInfo: function(info, col) {
+    _addOneInfo(info, col) {
         let [ok, date] = info.get_value_update();
         let datetime = GLib.DateTime.new_from_unix_local(date);
 
@@ -149,13 +147,13 @@ var ForecastBox = new Lang.Class({
         this._grid.attach(temperature, col, 2, 1, 1);
 
         this._hasForecastInfo = true;
-    },
+    }
 
-    clear: function() {
+    clear() {
         this._grid.foreach(function(w) { w.destroy(); });
-    },
+    }
 
-    hasForecastInfo: function() {
+    hasForecastInfo() {
         return this._hasForecastInfo;
     }
 });
diff --git a/src/app/main.js b/src/app/main.js
index 291620c..33a425c 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -28,9 +28,9 @@ pkg.require({ 'Gdk': '3.0',
 const Gdk = imports.gi.Gdk;
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
 const GWeather = imports.gi.GWeather;
-const Lang = imports.lang;
 
 const Util = imports.misc.util;
 const Window = imports.app.window;
@@ -43,40 +43,39 @@ function initEnvironment() {
     };
 }
 
-const Application = new Lang.Class({
-    Name: 'WeatherApplication',
-    Extends: Gtk.Application,
+const Application = GObject.registerClass(
+    class WeatherApplication extends Gtk.Application {
 
-    _init: function() {
-        this.parent({ application_id: pkg.name,
+    _init() {
+        super._init({ application_id: pkg.name,
                       flags: (Gio.ApplicationFlags.CAN_OVERRIDE_APP_ID |  Gio.ApplicationFlags.FLAGS_NONE) 
});
         GLib.set_application_name(_("Weather"));
         Gtk.Window.set_default_icon_name("org.gnome.Weather");
-    },
+    }
 
-    _onQuit: function() {
+    _onQuit() {
         this.quit();
-    },
+    }
 
-    _onShowLocation: function(action, parameter) {
+    _onShowLocation(action, parameter) {
         let location = this.world.deserialize(parameter.deep_unpack());
         let win = this._createWindow();
 
         let info = this.model.addNewLocation(location, false);
         win.showInfo(info, false);
         this._showWindowWhenReady(win);
-    },
+    }
 
-    _onShowSearch: function(action, parameter) {
+    _onShowSearch(action, parameter) {
         let text = parameter.deep_unpack();
         let win = this._createWindow();
 
         win.showSearch(text);
         this._showWindowWhenReady(win);
-    },
+    }
 
-    vfunc_startup: function() {
-        this.parent();
+    vfunc_startup() {
+        super.vfunc_startup();
         // ensure the type before we call to GtkBuilder
         GWeather.LocationEntry;
 
@@ -144,13 +143,13 @@ const Application = new Lang.Class({
         this.add_accelerator("Escape", "win.selection-mode", new GLib.Variant('b', false));
         this.add_accelerator("<Primary>a", "win.select-all", null);
         this.add_accelerator("<Primary>q", "app.quit", null);
-    },
+    }
 
-    _createWindow: function() {
+    _createWindow() {
         return new Window.MainWindow({ application: this });
-    },
+    }
 
-    _showWindowWhenReady: function(win) {
+    _showWindowWhenReady(win) {
         let notifyId;
 
         if (this.model.loading) {
@@ -176,19 +175,19 @@ const Application = new Lang.Class({
         }
 
         return win;
-    },
+    }
 
-    vfunc_activate: function() {
+    vfunc_activate() {
         let win = this._createWindow();
         win.showDefault();
         this._showWindowWhenReady(win);
-    },
+    }
 
-    vfunc_shutdown: function() {
+    vfunc_shutdown() {
         GWeather.Info.store_cache();
         this.model.saveSettingsNow();
 
-        this.parent();
+        super.vfunc_shutdown();
     }
 });
 
diff --git a/src/app/weeklyForecast.js b/src/app/weeklyForecast.js
index 1c7709e..c2929bd 100644
--- a/src/app/weeklyForecast.js
+++ b/src/app/weeklyForecast.js
@@ -18,21 +18,20 @@
 
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
 
 const Params = imports.misc.params;
 const Util = imports.misc.util;
 
-var WeeklyForecastFrame = new Lang.Class({
-    Name: 'WeeklyForecastFrame',
-    Extends: Gtk.Frame,
+var WeeklyForecastFrame = GObject.registerClass(
+    class WeeklyForecastFrame extends Gtk.Frame {
 
-    _init: function(params) {
+    _init(params) {
         params = Params.fill(params, { shadow_type: Gtk.ShadowType.NONE,
                                        name: 'weekly-forecast-frame',
                                        width_request: 150 });
-        this.parent(params);
+        super._init(params);
         this.get_accessible().accessible_name = _("Weekly Forecast");
 
         this._settings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
@@ -45,10 +44,10 @@ var WeeklyForecastFrame = new Lang.Class({
                                     row_homogeneous: true });
 
         this.add(this._grid);
-    },
+    }
 
     // get infos for the correct day
-    _preprocess: function(infos, day) {
+    _preprocess(infos, day) {
         let ret = [];
         let i;
 
@@ -103,9 +102,9 @@ var WeeklyForecastFrame = new Lang.Class({
             infoCount++;
         }
         return ret;
-    },
+    }
 
-    update: function(infos) {
+    update(infos) {
         let day = GLib.DateTime.new_now_local();
         day = day.add_days(1);
 
@@ -145,9 +144,9 @@ var WeeklyForecastFrame = new Lang.Class({
             grid.show();
             this._grid.attach(grid, 0, i, 1, 1);
         }
-    },
+    }
 
-    clear: function() {
+    clear() {
         this._grid.foreach(function(w) { w.destroy(); });
     }
 });
diff --git a/src/app/window.js b/src/app/window.js
index 4486439..35c6f6c 100644
--- a/src/app/window.js
+++ b/src/app/window.js
@@ -16,9 +16,9 @@
 // with Gnome Weather; if not, write to the Free Software Foundation,
 // Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
+const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
 const GWeather = imports.gi.GWeather;
-const Lang = imports.lang;
 
 const City = imports.app.city;
 const CurrentLocationController = imports.app.currentLocationController;
@@ -32,12 +32,11 @@ const Page = {
     CITY: 1
 };
 
-var MainWindow = new Lang.Class({
-    Name: 'MainWindow',
-    Extends: Gtk.ApplicationWindow,
+var MainWindow = GObject.registerClass(
+    class MainWindow extends Gtk.ApplicationWindow {
 
-    _init: function(params) {
-        this.parent(params);
+    _init(params) {
+        super._init(params);
 
         this._world = this.application.world;
         this.currentInfo = null;
@@ -102,20 +101,20 @@ var MainWindow = new Lang.Class({
             this._pageWidgets[Page.CITY][i].hide();
 
         this._showingDefault = false;
-    },
+    }
 
-    update: function() {
+    update() {
         this._cityView.update();
-    },
+    }
 
-    _searchLocationChanged: function(entry) {
+    _searchLocationChanged(entry) {
         if (entry.location) {
             let info = this._model.addNewLocation(entry.location, false);
             this.showInfo(info, false);
         }
-    },
+    }
 
-    _getTitle: function() {
+    _getTitle() {
         if (this._currentPage == Page.SEARCH)
             return [_("Select Location"), null];
 
@@ -133,9 +132,9 @@ var MainWindow = new Lang.Class({
             return [city.get_name(), country.get_name()];
         else
             return [city.get_name(), null];
-    },
+    }
 
-    _goToPage: function(page) {
+    _goToPage(page) {
         for (let i = 0; i < this._pageWidgets[this._currentPage].length; i++)
             this._pageWidgets[this._currentPage][i].hide();
 
@@ -150,9 +149,9 @@ var MainWindow = new Lang.Class({
         let [title, subtitle] = this._getTitle();
         this._header.title = title;
         this._header.subtitle = subtitle;
-    },
+    }
 
-    showDefault: function() {
+    showDefault() {
         this._showingDefault = true;
         let clc = this.application.currentLocationController;
         let autoLocation = clc.autoLocation;
@@ -161,9 +160,9 @@ var MainWindow = new Lang.Class({
             this.showInfo(this._model.getCurrentLocation(), false);
         else if (autoLocation != CurrentLocationController.AutoLocation.ENABLED)
             this.showInfo(this._model.getRecent(), false);
-    },
+    }
 
-    showSearch: function(text) {
+    showSearch(text) {
         this._showingDefault = false;
         this._cityView.setTimeVisible(false);
         this._stack.set_visible_child(this._searchView);
@@ -171,9 +170,9 @@ var MainWindow = new Lang.Class({
         this._searchEntry.text = text;
         if (text.length > 0)
             this._searchEntry.get_completion().complete();
-    },
+    }
 
-    showInfo: function(info, isCurrentLocation) {
+    showInfo(info, isCurrentLocation) {
         if (!info) {
             if (isCurrentLocation && this._showingDefault)
                 this.showDefault();
@@ -209,9 +208,9 @@ var MainWindow = new Lang.Class({
         this._worldView.refilter();
         this._stack.set_visible_child(this._cityView);
         this._goToPage(Page.CITY);
-    },
+    }
 
-    _showAbout: function() {
+    _showAbout() {
         let artists = [ 'Jakub Steiner <jimmac gmail com>',
                         'Pink Sherbet Photography (D. Sharon Pruitt)',
                         'Elliott Brown',
@@ -252,9 +251,9 @@ var MainWindow = new Lang.Class({
         aboutDialog.connect('response', function() {
             aboutDialog.destroy();
         });
-    },
+    }
 
-    _close: function() {
+    _close() {
         this.destroy();
     }
 });
diff --git a/src/app/world.js b/src/app/world.js
index 2eafbb3..e942b83 100644
--- a/src/app/world.js
+++ b/src/app/world.js
@@ -21,20 +21,18 @@ const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
 const GWeather = imports.gi.GWeather;
-const Lang = imports.lang;
 
 const CurrentLocationController = imports.app.currentLocationController;
 const Params = imports.misc.params;
 const Util = imports.misc.util;
 
 
-var WorldContentView = new Lang.Class({
-    Name: 'WorldContentView',
-    Extends: Gtk.Popover,
+var WorldContentView = GObject.registerClass(
+    class WorldContentView extends Gtk.Popover {
 
-    _init: function(application, window, params) {
+    _init(application, window, params) {
         params = Params.fill(params, { hexpand: false, vexpand: false });
-        this.parent(params);
+        super._init(params);
 
         this.get_accessible().accessible_name = _("World view");
 
@@ -113,34 +111,34 @@ var WorldContentView = new Lang.Class({
         let list = this.model.getAll();
         for (let i = list.length - 1; i >= 0; i--)
             this._onLocationAdded(this.model, list[i], list[i]._isCurrentLocation);
-    },
+    }
 
-    refilter: function() {
+    refilter() {
         this._listbox.invalidate_filter();
-    },
+    }
 
-    _syncStackPopover: function() {
+    _syncStackPopover() {
         if (this.model.length == 1)
             this._stackPopover.set_visible_child_name("search-grid");
         else
             this._stackPopover.set_visible_child_name("locations-grid");
-    },
+    }
 
-    _filterListbox: function(row) {
+    _filterListbox(row) {
         return this._window.currentInfo == null ||
             row._info != this._window.currentInfo;
-    },
+    }
 
-    _locationChanged: function(entry) {
+    _locationChanged(entry) {
         if (entry.location) {
             let info = this.model.addNewLocation(entry.location, false);
             this._window.showInfo(info, false);
             this.hide();
             entry.location = null;
         }
-    },
+    }
 
-    _onLocationAdded: function(model, info, isCurrentLocation) {
+    _onLocationAdded(model, info, isCurrentLocation) {
         let location = info.location;
 
         let grid = new Gtk.Grid({ orientation: Gtk.Orientation.HORIZONTAL,
@@ -212,9 +210,9 @@ var WorldContentView = new Lang.Class({
         });
 
         this._syncStackPopover();
-    },
+    }
 
-    _onLocationRemoved: function(model, info) {
+    _onLocationRemoved(model, info) {
         let rows = this._listbox.get_children();
 
         for (let row of rows) {
@@ -232,5 +230,5 @@ var WorldContentView = new Lang.Class({
             this._currentLocationAdded = false;
 
         this._syncStackPopover();
-    },
+    }
 });
diff --git a/src/service/main.js b/src/service/main.js
index bf09bc1..ec1ad20 100644
--- a/src/service/main.js
+++ b/src/service/main.js
@@ -25,8 +25,8 @@ pkg.require({ 'Gio': '2.0',
 
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
 const GWeather = imports.gi.GWeather;
-const Lang = imports.lang;
 
 const Util = imports.misc.util;
 const SearchProvider = imports.service.searchProvider;
@@ -38,12 +38,11 @@ function initEnvironment() {
     };
 }
 
-const BackgroundService = new Lang.Class({
-    Name: 'WeatherBackgroundService',
-    Extends: Gio.Application,
+const BackgroundService = GObject.registerClass(
+    class WeatherBackgroundService extends Gio.Application {
 
-    _init: function() {
-        this.parent({ application_id: pkg.name,
+    _init() {
+        super._init({ application_id: pkg.name,
                       flags: Gio.ApplicationFlags.IS_SERVICE,
                       inactivity_timeout: 60000 });
         GLib.set_application_name(_("Weather"));
@@ -52,31 +51,31 @@ const BackgroundService = new Lang.Class({
 
         if (!pkg.moduledir.startsWith('resource://'))
             this.debug = true;
-    },
+    }
 
-    _onQuit: function() {
+    _onQuit() {
         this.quit();
-    },
+    }
 
-    vfunc_dbus_register: function(connection, path) {
+    vfunc_dbus_register(connection, path) {
         this.parent(connection, path);
 
         this._searchProvider.export(connection, path);
         return true;
-    },
+    }
 
 /*
   Can't do until GApplication is fixed.
 
-    vfunc_dbus_unregister: function(connection, path) {
+    vfunc_dbus_unregister(connection, path) {
         this._searchProvider.unexport(connection);
 
-        this.parent(connection, path);
+        super.vfunc_dbus_unregister(connection, path);
     },
 */
 
-    vfunc_startup: function() {
-        this.parent();
+    vfunc_startup() {
+        super.vfunc_startup();
 
         this.world = GWeather.Location.get_world();
         this.model = new World.WorldModel(this.world, false);
@@ -91,16 +90,16 @@ const BackgroundService = new Lang.Class({
         Util.initActions(this,
                          [{ name: 'quit',
                             activate: this._onQuit }]);
-    },
+    }
 
-    vfunc_activate: function() {
+    vfunc_activate() {
         // do nothing, this is a background service
-    },
+    }
 
-    vfunc_shutdown: function() {
+    vfunc_shutdown() {
         GWeather.Info.store_cache();
 
-        this.parent();
+        super.vfunc_shutdown();
     }
 });
 
diff --git a/src/shared/world.js b/src/shared/world.js
index 4cf0bc1..95400b7 100644
--- a/src/shared/world.js
+++ b/src/shared/world.js
@@ -19,14 +19,11 @@
 const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
 const GWeather = imports.gi.GWeather;
-const Lang = imports.lang;
 
 const Params = imports.misc.params;
 const Util = imports.misc.util;
 
-var WorldModel = new Lang.Class({
-    Name: 'WorldModel',
-    Extends: GObject.Object,
+var WorldModel = GObject.registerClass({
     Signals: {
         'current-location-changed': { param_types: [ GWeather.Info ] },
         'location-added': { param_types: [ GWeather.Info, GObject.Boolean ] },
@@ -35,9 +32,10 @@ var WorldModel = new Lang.Class({
     Properties: {
         'loading': GObject.ParamSpec.boolean('loading', '', '', GObject.ParamFlags.READABLE, false)
     },
+}, class WorldModel extends GObject.Object {
 
-    _init: function(world, enableGtk) {
-        this.parent();
+    _init(world, enableGtk) {
+        super._init();
 
         this._world = world;
 
@@ -48,20 +46,20 @@ var WorldModel = new Lang.Class({
 
         this._currentLocationInfo = null;
         this._infoList = [];
-    },
+    }
 
     get length() {
         return this._infoList.length + (this._currentLocationInfo ? 1 : 0);
-    },
+    }
 
-    getAll: function() {
+    getAll() {
         if (this._currentLocationInfo)
             return [this._currentLocationInfo].concat(this._infoList);
         else
             return [].concat(this._infoList);
-    },
+    }
 
-    getAtIndex: function(index) {
+    getAtIndex(index) {
         if (this._currentLocationInfo) {
             if (index == 0)
                 return this._currentLocationInfo;
@@ -70,13 +68,13 @@ var WorldModel = new Lang.Class({
         }
 
         return this._infoList[index];
-    },
+    }
 
-    getCurrentLocation: function() {
+    getCurrentLocation() {
         return this._currentLocationInfo;
-    },
+    }
 
-    currentLocationChanged: function(location) {
+    currentLocationChanged(location) {
         if (this._currentLocationInfo)
             this._removeLocationInternal(this._currentLocationInfo, false);
 
@@ -86,16 +84,16 @@ var WorldModel = new Lang.Class({
         else
             info = null;
         this.emit('current-location-changed', info);
-    },
+    }
 
-    getRecent: function() {
+    getRecent() {
         if (this._infoList.length > 0)
             return this._infoList[0];
         else
             return null;
-    },
+    }
 
-    load: function () {
+    load () {
         let locations = this._settings.get_value('locations').deep_unpack();
 
         if (locations.length > 5) {
@@ -110,18 +108,18 @@ var WorldModel = new Lang.Class({
 
             info = this._addLocationInternal(location, false);
         }
-    },
+    }
 
-    _updateLoadingCount: function(delta) {
+    _updateLoadingCount(delta) {
         let wasLoading = this._loadingCount > 0;
         this._loadingCount += delta;
         let isLoading = this._loadingCount > 0;
 
         if (wasLoading != isLoading)
             this.notify('loading');
-    },
+    }
 
-    updateInfo: function(info) {
+    updateInfo(info) {
         if (info._loadingId)
             return;
 
@@ -134,13 +132,13 @@ var WorldModel = new Lang.Class({
 
         info.update();
         this._updateLoadingCount(+1);
-    },
+    }
 
     get loading() {
         return this._loadingCount > 0;
-    },
+    }
 
-    addNewLocation: function(newLocation, isCurrentLocation) {
+    addNewLocation(newLocation, isCurrentLocation) {
         if (!isCurrentLocation) {
             for (let info of this._infoList) {
                 let location = info.location;
@@ -157,9 +155,9 @@ var WorldModel = new Lang.Class({
             this._queueSaveSettings();
 
         return info;
-    },
+    }
 
-    _queueSaveSettings: function() {
+    _queueSaveSettings() {
         if (this._queueSaveSettingsId)
             return;
 
@@ -169,9 +167,9 @@ var WorldModel = new Lang.Class({
             return false;
         });
         this._queueSaveSettingsId = id;
-    },
+    }
 
-    _saveSettingsInternal: function() {
+    _saveSettingsInternal() {
         let locations = [];
 
         for (let i = 0; i < this._infoList.length; i++) {
@@ -180,9 +178,9 @@ var WorldModel = new Lang.Class({
         }
 
         this._settings.set_value('locations', new GLib.Variant('av', locations));
-    },
+    }
 
-    saveSettingsNow: function() {
+    saveSettingsNow() {
         if (!this._queueSaveSettingsId)
             return;
 
@@ -190,9 +188,9 @@ var WorldModel = new Lang.Class({
         this._queueSaveSettingsId = 0;
 
         this._saveSettingsInternal();
-    },
+    }
 
-    moveLocationToFront: function(info) {
+    moveLocationToFront(info) {
         if (this._infoList.length == 0 || this._infoList[0] == info)
             return;
 
@@ -204,9 +202,9 @@ var WorldModel = new Lang.Class({
         info._isCurrentLocation = false;
 
         this._queueSaveSettings();
-    },
+    }
 
-    _removeLocationInternal: function(oldInfo, skipDisconnect) {
+    _removeLocationInternal(oldInfo, skipDisconnect) {
         if (oldInfo._loadingId && !skipDisconnect) {
             oldInfo.disconnect(oldInfo._loadingId);
             oldInfo._loadingId = 0;
@@ -224,17 +222,17 @@ var WorldModel = new Lang.Class({
         }
 
         this.emit('location-removed', oldInfo);
-    },
+    }
 
-    _addLocationInternal: function(newLocation, isCurrentLocation) {
+    _addLocationInternal(newLocation, isCurrentLocation) {
         let info = new GWeather.Info({ location: newLocation,
                                        enabled_providers: this._providers });
         this._addInfoInternal(info, isCurrentLocation);
 
         return info;
-    },
+    }
 
-    _addInfoInternal: function(info, isCurrentLocation) {
+    _addInfoInternal(info, isCurrentLocation) {
         info._isCurrentLocation = isCurrentLocation;
         this._infoList.unshift(info);
         this.updateInfo(info);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]