[gnome-maps/wip/mlundblad/es6] WIP: Use ES6 classes with GObject extensions
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/es6] WIP: Use ES6 classes with GObject extensions
- Date: Fri, 29 Dec 2017 22:33:13 +0000 (UTC)
commit 0c10c79a9425e28eff169f73f119dee907bdc746
Author: Marcus Lundblad <ml update uu se>
Date: Mon Nov 20 21:27:49 2017 +0100
WIP: Use ES6 classes with GObject extensions
src/accountListBox.js | 26 +++++-------
src/application.js | 88 +++++++++++++++++++--------------------
src/busyMarker.js | 8 +--
src/checkIn.js | 55 +++++++++++--------------
src/checkInDialog.js | 58 +++++++++++++--------------
src/contactPlace.js | 16 +++----
src/contextMenu.js | 48 ++++++++++-----------
src/exportViewDialog.js | 40 +++++++++---------
src/facebookBackend.js | 52 +++++++++++------------
src/favoritesPopover.js | 20 ++++-----
src/foursquareBackend.js | 51 +++++++++++------------
src/foursquareGoaAuthorizer.js | 29 ++++++-------
src/geoclue.js | 26 +++++------
src/geocodeService.js | 15 ++-----
src/serviceBackend.js | 44 ++++++++++----------
15 files changed, 270 insertions(+), 306 deletions(-)
---
diff --git a/src/accountListBox.js b/src/accountListBox.js
index e45a21e..e829535 100644
--- a/src/accountListBox.js
+++ b/src/accountListBox.js
@@ -21,25 +21,23 @@
const Gio = imports.gi.Gio;
const Goa = imports.gi.Goa;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
const Application = imports.application;
-var AccountRow = new Lang.Class({
- Name: 'AccountRow',
- Extends: Gtk.ListBoxRow,
+var AccountRow = GObject.registerClass({
Template: 'resource:///org/gnome/Maps/ui/account-row.ui',
InternalChildren: [ 'providerLabel',
'identityLabel',
'providerImage',
'attentionNeededImage' ],
-
- _init: function(params) {
+}, class AccountRow extends Gtk.ListBoxRow {
+ _init(params) {
this.account = params.account;
delete params.account;
- this.parent(params);
+ super._init(params);
let account = this.account.get_account();
@@ -50,16 +48,14 @@ var AccountRow = new Lang.Class({
}
});
-var AccountListBox = new Lang.Class({
- Name: 'AccountListBox',
- Extends: Gtk.ListBox,
+var AccountListBox = GObject.registerClass({
Signals: {
'account-selected': { param_types: [Goa.Object] }
},
-
- _init: function(params) {
+}, class AccountListBox extends Gtk.ListBox {
+ _init(params) {
params.activate_on_single_click = true;
- this.parent(params);
+ super._init(params);
Application.checkInManager.connect('accounts-refreshed', () => { this.refresh(); });
@@ -67,9 +63,9 @@ var AccountListBox = new Lang.Class({
(list, row) => { this.emit('account-selected', row.account); });
this.refresh();
- },
+ }
- refresh: function() {
+ refresh() {
let accounts = Application.checkInManager.accounts;
this.forall(function(row) {
diff --git a/src/application.js b/src/application.js
index c155ba3..6e2fb9f 100644
--- a/src/application.js
+++ b/src/application.js
@@ -25,7 +25,6 @@ const GObject = imports.gi.GObject;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const GtkClutter = imports.gi.GtkClutter;
-const Lang = imports.lang;
const WebKit2 = imports.gi.WebKit2;
const CheckIn = imports.checkIn;
@@ -62,9 +61,7 @@ var routeQuery = null;
const _ensuredTypes = [WebKit2.WebView,
OSMTypeSearchEntry.OSMTypeSearchEntry];
-var Application = new Lang.Class({
- Name: 'Application',
- Extends: Gtk.Application,
+var Application = GObject.registerClass({
Properties: {
'connected': GObject.ParamSpec.boolean('connected',
'',
@@ -72,24 +69,25 @@ var Application = new Lang.Class({
GObject.ParamFlags.READABLE |
GObject.ParamFlags.WRITABLE)
},
+}, class Application extends Gtk.Application {
set connected(p) {
this._connected = p;
this.notify('connected');
- },
+ }
get connected() {
return this._connected;
- },
+ }
- _init: function() {
+ _init() {
/* Translators: This is the program name. */
GLib.set_application_name(_("Maps"));
/* Needed to be able to use in UI files */
_ensuredTypes.forEach((type) => { GObject.type_ensure(type); });
- this.parent({ application_id: 'org.gnome.Maps',
+ super._init({ application_id: 'org.gnome.Maps',
flags: Gio.ApplicationFlags.HANDLES_OPEN });
this._connected = false;
@@ -118,13 +116,13 @@ var Application = new Lang.Class({
return -1;
});
- },
+ }
- _checkNetwork: function() {
+ _checkNetwork() {
this.connected = networkMonitor.connectivity === Gio.NetworkConnectivity.FULL;
- },
+ }
- _showContact: function(id) {
+ _showContact(id) {
contactStore.lookup(id, (contact) => {
this._mainWindow.markBusy();
if (!contact) {
@@ -136,9 +134,9 @@ var Application = new Lang.Class({
this._mainWindow.mapView.showContact(contact);
});
});
- },
+ }
- _onShowContactActivate: function(action, parameter) {
+ _onShowContactActivate(action, parameter) {
this._createWindow();
this._checkNetwork();
this._mainWindow.present();
@@ -153,20 +151,20 @@ var Application = new Lang.Class({
this._showContact(id);
});
}
- },
+ }
- _onQuitActivate: function() {
+ _onQuitActivate() {
this._mainWindow.destroy();
- },
+ }
- _onOsmAccountSetupActivate: function() {
+ _onOsmAccountSetupActivate() {
let dialog = osmEdit.createAccountDialog(this._mainWindow, false);
dialog.show();
dialog.connect('response', () => { dialog.destroy(); });
- },
+ }
- _addContacts: function() {
+ _addContacts() {
contactStore.get_contacts().forEach((contact) => {
contact.geocode(function() {
contact.get_places().forEach((p) => {
@@ -180,9 +178,9 @@ var Application = new Lang.Class({
});
});
});
- },
+ }
- _initPlaceStore: function() {
+ _initPlaceStore() {
placeStore = new PlaceStore.PlaceStore({
recentPlacesLimit: settings.get('recent-places-limit'),
recentRoutesLimit: settings.get('recent-routes-limit')
@@ -202,18 +200,18 @@ var Application = new Lang.Class({
this._addContacts();
});
}
- },
+ }
- _initAppMenu: function() {
+ _initAppMenu() {
let builder = new Gtk.Builder();
builder.add_from_resource('/org/gnome/Maps/ui/app-menu.ui');
let menu = builder.get_object('app-menu');
this.set_app_menu(menu);
- },
+ }
- vfunc_startup: function() {
- this.parent();
+ vfunc_startup() {
+ super.vfunc_startup();
GtkClutter.init(null);
@@ -237,9 +235,9 @@ var Application = new Lang.Class({
'icons']));
this._initPlaceStore();
this._initAppMenu();
- },
+ }
- _initServices: function() {
+ _initServices() {
settings = Settings.getSettings('org.gnome.Maps');
routeQuery = new RouteQuery.RouteQuery();
routingDelegator = new RoutingDelegator.RoutingDelegator({ query: routeQuery });
@@ -252,9 +250,9 @@ var Application = new Lang.Class({
contactStore = new Maps.ContactStore();
contactStore.load();
osmEdit = new OSMEdit.OSMEdit();
- },
+ }
- _createWindow: function() {
+ _createWindow() {
if (this._mainWindow)
return;
@@ -268,24 +266,24 @@ var Application = new Lang.Class({
log('* focus widget: %s'.format(widget));
});
}
- },
+ }
- vfunc_dbus_register: function(connection, path) {
- this.parent(connection, path);
+ vfunc_dbus_register(connection, path) {
+ super.vfunc_dbus_register(connection, path);
return true;
- },
+ }
- vfunc_dbus_unregister: function(connection, path) {
- this.parent(connection, path);
- },
+ vfunc_dbus_unregister(connection, path) {
+ super.vfunc_dbus_register(connection, path);
+ }
- vfunc_activate: function() {
+ vfunc_activate() {
this._createWindow();
this._checkNetwork();
this._mainWindow.present();
- },
+ }
- _openInternal: function(files) {
+ _openInternal(files) {
if (!this._mainWindow || !this._mainWindow.mapView.view.realized)
return;
@@ -298,9 +296,9 @@ var Application = new Lang.Class({
} else {
this._mainWindow.mapView.openShapeLayers(files);
}
- },
+ }
- vfunc_open: function(files) {
+ vfunc_open(files) {
normalStartup = false;
this.activate();
@@ -310,9 +308,9 @@ var Application = new Lang.Class({
else
mapView.view.connect('notify::realized',
this._openInternal.bind(this, files));
- },
+ }
- _onWindowDestroy: function(window) {
+ _onWindowDestroy(window) {
this._mainWindow = null;
}
});
diff --git a/src/busyMarker.js b/src/busyMarker.js
index b53962d..3f99c3d 100644
--- a/src/busyMarker.js
+++ b/src/busyMarker.js
@@ -18,10 +18,8 @@
*/
const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
+const GObject = imports.gi.GObject;
-var BusyMarker = new Lang.Class({
- Name: 'BusyMarker',
- Extends: Gtk.Frame,
+var BusyMarker = GObject.registerClass({
Template: 'resource:///org/gnome/Maps/ui/busy-marker.ui'
-});
+}, class BusyMarker extends Gtk.Frame {});
diff --git a/src/checkIn.js b/src/checkIn.js
index d75d492..e314da7 100644
--- a/src/checkIn.js
+++ b/src/checkIn.js
@@ -22,15 +22,12 @@
const GObject = imports.gi.GObject;
const Goa = imports.gi.Goa;
const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
const CheckInDialog = imports.checkInDialog;
const FacebookBackend = imports.facebookBackend;
const FoursquareBackend = imports.foursquareBackend;
-var CheckInManager = new Lang.Class({
- Name: 'CheckInManager',
- Extends: GObject.Object,
+var CheckInManager = GObject.registerClass({
Signals: {
'accounts-refreshed': { }
},
@@ -39,10 +36,10 @@ var CheckInManager = new Lang.Class({
'',
'',
GObject.ParamFlags.READABLE)
- },
-
- _init: function() {
- this.parent();
+ }
+}, class CheckInManager extends GObject.Object {
+ _init() {
+ super._init();
try {
this._goaClient = Goa.Client.new_sync(null);
@@ -66,17 +63,17 @@ var CheckInManager = new Lang.Class({
}
this._refreshGoaAccounts();
- },
+ }
- _initBackends: function() {
+ _initBackends() {
let facebookBackend = new FacebookBackend.FacebookBackend();
this._backends[facebookBackend.name] = facebookBackend;
let foursquareBackend = new FoursquareBackend.FoursquareBackend();
this._backends[foursquareBackend.name] = foursquareBackend;
- },
+ }
- _refreshGoaAccounts: function() {
+ _refreshGoaAccounts() {
if (!this._goaClient)
return;
let accounts = this._goaClient.get_accounts();
@@ -99,39 +96,39 @@ var CheckInManager = new Lang.Class({
this.emit('accounts-refreshed');
this.notify('hasCheckIn');
- },
+ }
get client() {
return this._goaClient;
- },
+ }
get accounts() {
return this._accounts;
- },
+ }
get hasCheckIn() {
return this._accounts.length > 0;
- },
+ }
- _getAuthorizer: function(account) {
+ _getAuthorizer(account) {
return this._authorizers[account.get_account().id];
- },
+ }
- _getBackend: function(account) {
+ _getBackend(account) {
return this._backends[account.get_account().provider_type];
- },
+ }
- performCheckIn: function(account, checkIn, callback, cancellable) {
+ performCheckIn(account, checkIn, callback, cancellable) {
this._getBackend(account)
.performCheckIn(this._getAuthorizer(account), checkIn, callback, cancellable);
- },
+ }
- findPlaces: function(account, latitude, longitude, distance, callback, cancellable) {
+ findPlaces(account, latitude, longitude, distance, callback, cancellable) {
this._getBackend(account)
.findPlaces(this._getAuthorizer(account), latitude, longitude, distance, callback, cancellable);
- },
+ }
- showCheckInDialog: function(parentWindow, place, matchPlace) {
+ showCheckInDialog(parentWindow, place, matchPlace) {
let dialog = new CheckInDialog.CheckInDialog({ transient_for: parentWindow,
matchPlace: matchPlace,
place: place });
@@ -170,14 +167,12 @@ var CheckInManager = new Lang.Class({
}
});
-var CheckIn = new Lang.Class({
- Name: 'CheckIn',
-
- _init: function() {
+var CheckIn = class {
+ _init() {
this.message = null;
this.place = null;
this.privacy = null;
this.broadcastFacebook = false;
this.broadcastTwitter = false;
}
-});
+};
diff --git a/src/checkInDialog.js b/src/checkInDialog.js
index 66dd6e9..371465b 100644
--- a/src/checkInDialog.js
+++ b/src/checkInDialog.js
@@ -20,8 +20,8 @@
*/
const Gio = imports.gi.Gio;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
const Mainloop = imports.mainloop;
const AccountListBox = imports.accountListBox;
@@ -39,9 +39,7 @@ var Response = {
FAILURE_CHECKIN_DISABLED: 5
};
-var CheckInDialog = new Lang.Class({
- Name: 'CheckInDialog',
- Extends: Gtk.Dialog,
+var CheckInDialog = GObject.registerClass({
Template: 'resource:///org/gnome/Maps/ui/check-in-dialog.ui',
InternalChildren: [ 'cancelButton',
'okButton',
@@ -59,8 +57,8 @@ var CheckInDialog = new Lang.Class({
'foursquareOptionsPrivacyComboBox',
'foursquareOptionsBroadcastFacebookCheckButton',
'foursquareOptionsBroadcastTwitterCheckButton' ],
-
- _init: function(params) {
+}, class CheckInDialog extends Gtk.Dialog {
+ _init(params) {
this._place = params.place;
delete params.place;
@@ -70,7 +68,7 @@ var CheckInDialog = new Lang.Class({
// This is a construct-only property and cannot be set by GtkBuilder
params.use_header_bar = true;
- this.parent(params);
+ super._init(params);
this._account = null;
this._checkIn = new CheckIn.CheckIn();
@@ -86,16 +84,16 @@ var CheckInDialog = new Lang.Class({
this._initHeaderBar();
this._initWidgets();
- },
+ }
- _initHeaderBar: function() {
+ _initHeaderBar() {
this._cancelButton.connect('clicked',
() => { this._cancellable.cancel(); });
this._okButton.connect('clicked', () => { this._startCheckInStep(); });
- },
+ }
- _initWidgets: function() {
+ _initWidgets() {
// Limitations in Gjs means we can't do this in UI files yet
this._accountListBox = new AccountListBox.AccountListBox({ visible: true });
this._accountFrame.add(this._accountListBox);
@@ -128,14 +126,14 @@ var CheckInDialog = new Lang.Class({
this._checkIn.place = place;
this._startMessageStep();
});
- },
+ }
- vfunc_show: function() {
+ vfunc_show() {
this._startup();
- this.parent();
- },
+ super.vfunc_show();
+ }
- _startup: function() {
+ _startup() {
let accounts = Application.checkInManager.accounts;
if (accounts.length > 1)
@@ -148,9 +146,9 @@ var CheckInDialog = new Lang.Class({
this.response(Response.FAILURE_CHECKIN_DISABLED);
});
}
- },
+ }
- _onAccountRefreshed: function() {
+ _onAccountRefreshed() {
let accounts = Application.checkInManager.accounts;
if (!Application.checkInManager.hasCheckIn)
@@ -163,14 +161,14 @@ var CheckInDialog = new Lang.Class({
this.response(Response.FAILURE_ACCOUNT_DISABLED);
}
- },
+ }
- _startAccountStep: function() {
+ _startAccountStep() {
this.set_title(_("Select an account"));
this._stack.set_visible_child_name('account');
- },
+ }
- _startPlaceStep: function() {
+ _startPlaceStep() {
this.set_title(_("Loading"));
this._stack.set_visible_child_name('loading');
@@ -180,9 +178,9 @@ var CheckInDialog = new Lang.Class({
100,
this._onFindPlacesFinished.bind(this),
this._cancellable);
- },
+ }
- _onFindPlacesFinished: function(account, places, error) {
+ _onFindPlacesFinished(account, places, error) {
if (!error) {
if (places.length === 0) {
this.response(Response.FAILURE_NO_PLACES);
@@ -212,9 +210,9 @@ var CheckInDialog = new Lang.Class({
this.error = error;
this.response(Response.FAILURE_GET_PLACES);
}
- },
+ }
- _startMessageStep: function() {
+ _startMessageStep() {
/* Translators: %s is the name of the place to check in.
*/
this.set_title(_("Check in to %s").format(this._checkIn.place.name));
@@ -240,9 +238,9 @@ var CheckInDialog = new Lang.Class({
optionsGrids[provider].show();
else
optionsGrids[provider].hide();
- },
+ }
- _startCheckInStep: function() {
+ _startCheckInStep() {
this.set_title(_("Loading"));
this._stack.set_visible_child_name('loading');
@@ -268,9 +266,9 @@ var CheckInDialog = new Lang.Class({
this._checkIn,
this._onPerformCheckInFinished.bind(this),
this._cancellable);
- },
+ }
- _onPerformCheckInFinished: function (account, data, error) {
+ _onPerformCheckInFinished(account, data, error) {
if (!error)
this.response(Response.SUCCESS);
else {
diff --git a/src/contactPlace.js b/src/contactPlace.js
index b2d8876..961ea29 100644
--- a/src/contactPlace.js
+++ b/src/contactPlace.js
@@ -19,25 +19,23 @@
* Author: Jonas Danielsson <jonas threetimestwo org>
*/
-const Lang = imports.lang;
+const GObject = imports.gi.GObject;
const Place = imports.place;
-var ContactPlace = new Lang.Class({
- Name: 'ContactPlace',
- Extends: Place.Place,
-
- _init: function(params) {
+var ContactPlace = GObject.registerClass({},
+class ContactPlace extends Place.Place {
+ _init(params) {
this._contact = params.contact;
delete params.contact;
params.store = false;
- this.parent(params);
- },
+ super._init(params);
+ }
get icon() {
return this._contact.icon;
- },
+ }
get uniqueID() {
return [this.name,
diff --git a/src/contextMenu.js b/src/contextMenu.js
index c80b42b..d604991 100644
--- a/src/contextMenu.js
+++ b/src/contextMenu.js
@@ -22,12 +22,12 @@
const Champlain = imports.gi.Champlain;
const Gdk = imports.gi.Gdk;
const Geocode = imports.gi.GeocodeGlib;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Mainloop = imports.mainloop;
const Application = imports.application;
const ExportViewDialog = imports.exportViewDialog;
-const Lang = imports.lang;
const Location = imports.location;
const OSMAccountDialog = imports.osmAccountDialog;
const OSMEdit = imports.osmEdit;
@@ -36,24 +36,22 @@ const Place = imports.place;
const Utils = imports.utils;
const ZoomInNotification = imports.zoomInNotification;
-var ContextMenu = new Lang.Class({
- Name: 'ContextMenu',
- Extends: Gtk.Menu,
+var ContextMenu = GObject.registerClass({
Template: 'resource:///org/gnome/Maps/ui/context-menu.ui',
InternalChildren: [ 'whatsHereItem',
'geoURIItem',
'exportItem',
'addOSMLocationItem',
'routeItem' ],
-
- _init: function(params) {
+}, class ContextMenu extends Gtk.Menu {
+ _init(params) {
this._mapView = params.mapView;
delete params.mapView;
this._mainWindow = params.mainWindow;
delete params.mainWindow;
- this.parent(params);
+ super._init(params);
this._mapView.connect('button-release-event',
this._onButtonReleaseEvent.bind(this));
@@ -72,9 +70,9 @@ var ContextMenu = new Lang.Class({
this._routingUpdate.bind(this));
this._routeItem.visible = false;
this._routingUpdate();
- },
+ }
- _onButtonReleaseEvent: function(widget, event) {
+ _onButtonReleaseEvent(widget, event) {
let [, button] = event.get_button();
let [, x, y] = event.get_coords();
this._longitude = this._mapView.view.x_to_longitude(x);
@@ -84,9 +82,9 @@ var ContextMenu = new Lang.Class({
// Need idle to avoid Clutter dead-lock on re-entrance
Mainloop.idle_add(() => { this.popup_at_pointer(event); });
}
- },
+ }
- _routingUpdate: function() {
+ _routingUpdate() {
let query = Application.routeQuery;
if (query.points.length === 0)
@@ -100,9 +98,9 @@ var ContextMenu = new Lang.Class({
} else {
this._routeItem.label = _("Route to here");
}
- },
+ }
- _onRouteActivated: function() {
+ _onRouteActivated() {
let query = Application.routeQuery;
let location = new Location.Location({ latitude: this._latitude,
longitude: this._longitude,
@@ -116,9 +114,9 @@ var ContextMenu = new Lang.Class({
} else {
query.points[query.points.length - 1].place = place;
}
- },
+ }
- _onWhatsHereActivated: function() {
+ _onWhatsHereActivated() {
let location = new Location.Location({ latitude: this._latitude,
longitude: this._longitude,
accuracy: 0 });
@@ -131,9 +129,9 @@ var ContextMenu = new Lang.Class({
Application.notificationManager.showMessage(msg);
}
});
- },
+ }
- _onGeoURIActivated: function() {
+ _onGeoURIActivated() {
let location = new Location.Location({ latitude: this._latitude,
longitude: this._longitude,
accuracy: 0 });
@@ -142,9 +140,9 @@ var ContextMenu = new Lang.Class({
let uri = location.to_uri(Geocode.LocationURIScheme.GEO);
clipboard.set_text(uri, uri.length);
- },
+ }
- _onAddOSMLocationActivated: function() {
+ _onAddOSMLocationActivated() {
let osmEdit = Application.osmEdit;
/* if the user is not alread signed in, show the account dialog */
if (!osmEdit.isSignedIn) {
@@ -161,9 +159,9 @@ var ContextMenu = new Lang.Class({
}
this._addOSMLocation();
- },
+ }
- _addOSMLocation: function() {
+ _addOSMLocation() {
let osmEdit = Application.osmEdit;
if (this._mapView.view.get_zoom_level() < OSMEdit.MIN_ADD_LOCATION_ZOOM_LEVEL) {
@@ -187,9 +185,9 @@ var ContextMenu = new Lang.Class({
_("Location was added to the map, note that it may take a while before it shows on the
map and in search results."));
}
});
- },
+ }
- _activateExport: function() {
+ _activateExport() {
let view = this._mapView.view;
let surface = view.to_surface(true);
let bbox = view.get_bounding_box();
@@ -206,9 +204,9 @@ var ContextMenu = new Lang.Class({
dialog.connect('response', () => { dialog.destroy(); });
dialog.show_all();
- },
+ }
- _onExportActivated: function() {
+ _onExportActivated() {
if (this._mapView.view.state === Champlain.State.DONE) {
this._activateExport();
} else {
diff --git a/src/exportViewDialog.js b/src/exportViewDialog.js
index c946563..55295dc 100644
--- a/src/exportViewDialog.js
+++ b/src/exportViewDialog.js
@@ -21,8 +21,8 @@ const Cairo = imports.cairo;
const Gdk = imports.gi.Gdk;
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
+const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
const Utils = imports.utils;
@@ -33,9 +33,7 @@ var Response = {
const _PREVIEW_WIDTH = 150;
-var ExportViewDialog = new Lang.Class({
- Name: 'ExportViewDialog',
- Extends: Gtk.Dialog,
+var ExportViewDialog = GObject.registerClass({
Template: 'resource:///org/gnome/Maps/ui/export-view-dialog.ui',
InternalChildren: [ 'exportButton',
'cancelButton',
@@ -43,8 +41,8 @@ var ExportViewDialog = new Lang.Class({
'fileChooserButton',
'previewArea',
'layersCheckButton' ],
-
- _init: function(params) {
+}, class ExportViewDialog extends Gtk.Dialog {
+ _init(params) {
this._surface = params.surface;
delete params.surface;
@@ -58,7 +56,7 @@ var ExportViewDialog = new Lang.Class({
delete params.mapView;
params.use_header_bar = true;
- this.parent(params);
+ super._init(params);
this._cancelButton.connect('clicked', () => { this.response(Response.CANCEL); });
this._exportButton.connect('clicked', () => { this._exportView(); });
@@ -74,18 +72,18 @@ var ExportViewDialog = new Lang.Class({
this._filenameEntry.text = this._fileName = this._getName();
this._fileChooserButton.set_current_folder(this._folder);
this._setupPreviewArea();
- },
+ }
- _getName: function() {
+ _getName() {
/* Translators: This is a format string for a PNG filename for an
* exported image with coordinates. The .png extension should be kept
* intact in the translated string.
*/
return _("Maps at %f, %f.png").format(this._latitude.toFixed(2),
this._longitude.toFixed(2));
- },
+ }
- _setupPreviewArea: function() {
+ _setupPreviewArea() {
let [surfaceWidth, surfaceHeight] = this._mapView.view.get_size();
let width = _PREVIEW_WIDTH;
@@ -95,9 +93,9 @@ var ExportViewDialog = new Lang.Class({
this._previewArea.set_size_request(width, height);
this._previewArea.connect('draw',
(w, cr) => { this._drawPreview(w, cr); });
- },
+ }
- _drawPreview: function(widget, cr) {
+ _drawPreview(widget, cr) {
cr.setOperator(Cairo.Operator.CLEAR);
cr.paint();
cr.setOperator(Cairo.Operator.OVER);
@@ -105,9 +103,9 @@ var ExportViewDialog = new Lang.Class({
cr.scale(this._scaleFactor, this._scaleFactor);
cr.setSourceSurface(this._surface, 0, 0);
cr.paint();
- },
+ }
- _onFileNameChanged: function() {
+ _onFileNameChanged() {
let name = GLib.filename_from_utf8(this._filenameEntry.text, -1)[0];
name = name.toString();
if (!name) {
@@ -122,9 +120,9 @@ var ExportViewDialog = new Lang.Class({
} catch(e) {
this._exportButton.sensitive = false;
}
- },
+ }
- _onFolderChanged: function() {
+ _onFolderChanged() {
let folder = this._fileChooserButton.get_filename();
if (!GLib.file_test(folder, GLib.FileTest.IS_DIR)) {
@@ -138,9 +136,9 @@ var ExportViewDialog = new Lang.Class({
this._exportButton.sensitive = true;
this._folder = folder;
- },
+ }
- _exportView: function() {
+ _exportView() {
let [width, height] = this._mapView.view.get_size();
let pixbuf = Gdk.pixbuf_get_from_surface(this._surface, 0, 0, width, height);
let path = GLib.build_filenamev([this._folder, this._fileName]);
@@ -174,9 +172,9 @@ var ExportViewDialog = new Lang.Class({
dialog.connect('response', () => { dialog.destroy(); });
dialog.show_all();
}
- },
+ }
- _includeLayersChanged: function() {
+ _includeLayersChanged() {
let includeLayers = this._layersCheckButton.get_active();
this._surface = this._mapView.view.to_surface(includeLayers);
diff --git a/src/facebookBackend.js b/src/facebookBackend.js
index c01306f..9bf0f7d 100644
--- a/src/facebookBackend.js
+++ b/src/facebookBackend.js
@@ -20,43 +20,41 @@
*/
const GFBGraph = imports.gi.GFBGraph;
-const Lang = imports.lang;
+const GObject = imports.gi.GObject;
const ServiceBackend = imports.serviceBackend;
const SocialPlace = imports.socialPlace;
const _PLACE_LINK_FORMAT = 'https://www.facebook.com/%s';
-var FacebookBackend = new Lang.Class({
- Name: 'SocialServiceFacebookBackend',
- Extends: ServiceBackend.ServiceBackend,
-
+var FacebookBackend = GObject.registerClass({},
+class FacebookBackend extends ServiceBackend.ServiceBackend {
get name() {
return 'facebook';
- },
+ }
- createRestCall: function(authorizer) {
+ createRestCall(authorizer) {
return GFBGraph.new_rest_call(authorizer);
- },
+ }
- refreshAuthorization: function(authorizer, cancellable) {
+ refreshAuthorization(authorizer, cancellable) {
return authorizer.refresh_authorization(cancellable);
- },
+ }
- getAuthorizerAccount: function(authorizer) {
+ getAuthorizerAccount(authorizer) {
return authorizer.goa_object;
- },
+ }
- createAuthorizer: function(account) {
+ createAuthorizer(account) {
return new GFBGraph.GoaAuthorizer({ goa_object: account });
- },
+ }
- isTokenInvalid: function(restCall, data) {
+ isTokenInvalid(restCall, data) {
return data.error &&
(data.error.code === 2500 || data.error.code === 104 || data.error.code === 190);
- },
+ }
- isInvalidCall: function(restCall, data) {
+ isInvalidCall(restCall, data) {
if (!data) {
return true;
} else if (data.error) {
@@ -64,21 +62,21 @@ var FacebookBackend = new Lang.Class({
} else {
return false;
}
- },
+ }
- getCallResultCode: function(restCall, data) {
+ getCallResultCode(restCall, data) {
return data ?
(data.error ? data.error.code : null) :
restCall.get_status_code();
- },
+ }
- getCallResultMessage: function(restCall, data) {
+ getCallResultMessage(restCall, data) {
return data ?
(data.error ? data.error.message : null) :
restCall.get_status_message();
- },
+ }
- _realPerformCheckIn: function(authorizer, checkIn, callback, cancellable) {
+ _realPerformCheckIn(authorizer, checkIn, callback, cancellable) {
this.callAsync(authorizer,
'POST',
'me/feed',
@@ -89,9 +87,9 @@ var FacebookBackend = new Lang.Class({
},
callback,
cancellable);
- },
+ }
- _realFindPlaces: function(authorizer, latitude, longitude, distance, callback, cancellable) {
+ _realFindPlaces(authorizer, latitude, longitude, distance, callback, cancellable) {
this.callAsync(authorizer,
'GET',
'search',
@@ -102,9 +100,9 @@ var FacebookBackend = new Lang.Class({
},
callback,
cancellable);
- },
+ }
- createPlaces: function(rawData) {
+ createPlaces(rawData) {
return rawData.data.map(function(place) {
let link = _PLACE_LINK_FORMAT.format(place.id);
diff --git a/src/favoritesPopover.js b/src/favoritesPopover.js
index e6a5a0d..34e4ad2 100644
--- a/src/favoritesPopover.js
+++ b/src/favoritesPopover.js
@@ -20,7 +20,6 @@
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
const Application = imports.application;
const PlaceListRow = imports.placeListRow;
@@ -28,9 +27,7 @@ const PlaceStore = imports.placeStore;
const _N_VISIBLE = 6;
-var FavoritesPopover = new Lang.Class({
- Name: 'FavoritesPopover',
- Extends: Gtk.Popover,
+var FavoritesPopover = GObject.registerClass({
Template: 'resource:///org/gnome/Maps/ui/favorites-popover.ui',
InternalChildren: [ 'mainGrid',
'revealer',
@@ -44,16 +41,17 @@ var FavoritesPopover = new Lang.Class({
GObject.ParamFlags.READABLE |
GObject.ParamFlags.WRITABLE,
0, GLib.MAXINT32, 0)
- },
+ }
+}, class FavoritesPopover extends Gtk.Popover {
- _init: function(params) {
+ _init(params) {
params = params || { };
this._mapView = params.mapView;
delete params.mapView;
params.transitions_enabled = false;
- this.parent(params);
+ super._init(params);
this._rows = 0;
@@ -92,20 +90,20 @@ var FavoritesPopover = new Lang.Class({
});
this._updateList();
- },
+ }
set rows(rows) {
if (rows !== this._rows) {
this._rows = rows;
this.notify('rows');
}
- },
+ }
get rows() {
return this._rows;
- },
+ }
- _updateList: function() {
+ _updateList() {
this._list.forall((row) => { row.destroy(); });
let rows = 0;
diff --git a/src/foursquareBackend.js b/src/foursquareBackend.js
index 014c9da..b3c0015 100644
--- a/src/foursquareBackend.js
+++ b/src/foursquareBackend.js
@@ -19,7 +19,7 @@
* Author: Damián Nohales <damiannohales gmail com>
*/
-const Lang = imports.lang;
+const GObject = imports.gi.GObject;
const FoursquareGoaAuthorizer = imports.foursquareGoaAuthorizer;
const ServiceBackend = imports.serviceBackend;
@@ -27,47 +27,46 @@ const SocialPlace = imports.socialPlace;
const _PLACE_LINK_FORMAT = 'https://foursquare.com/v/foursquare-hq/%s';
-var FoursquareBackend = new Lang.Class({
- Name: 'SocialServiceFoursquareBackend',
- Extends: ServiceBackend.ServiceBackend,
+var FoursquareBackend = GObject.registerClass({},
+class SocialServiceFoursquareBackend extends ServiceBackend.ServiceBackend {
get name() {
return 'foursquare';
- },
+ }
- createRestCall: function(authorizer) {
+ createRestCall(authorizer) {
return FoursquareGoaAuthorizer.newRestCall(authorizer);
- },
+ }
- refreshAuthorization: function(authorizer, cancellable) {
+ refreshAuthorization(authorizer, cancellable) {
return authorizer.refreshAuthorization(cancellable);
- },
+ }
- getAuthorizerAccount: function(authorizer) {
+ getAuthorizerAccount(authorizer) {
return authorizer.goaObject;
- },
+ }
- createAuthorizer: function(account) {
+ createAuthorizer(account) {
return new FoursquareGoaAuthorizer.FoursquareGoaAuthorizer({ goaObject: account });
- },
+ }
- isTokenInvalid: function(restCall, data) {
+ isTokenInvalid(restCall, data) {
return data.meta.code === 401 || data.meta.code === 403;
- },
+ }
- isInvalidCall: function(restCall, data) {
+ isInvalidCall(restCall, data) {
return !data || data.meta.code !== 200;
- },
+ }
- getCallResultCode: function(restCall, data) {
+ getCallResultCode(restCall, data) {
return data ? data.meta.code : restCall.get_status_code();
- },
+ }
- getCallResultMessage: function(restCall, data) {
+ getCallResultMessage(restCall, data) {
return data ? data.meta.errorDetail : restCall.get_status_message();
- },
+ }
- _realPerformCheckIn: function(authorizer, checkIn, callback, cancellable) {
+ _realPerformCheckIn(authorizer, checkIn, callback, cancellable) {
let broadcast = checkIn.privacy;
if (checkIn.broadcastFacebook)
@@ -86,9 +85,9 @@ var FoursquareBackend = new Lang.Class({
},
callback,
cancellable);
- },
+ }
- _realFindPlaces: function(authorizer, latitude, longitude, distance, callback, cancellable) {
+ _realFindPlaces(authorizer, latitude, longitude, distance, callback, cancellable) {
this.callAsync(authorizer,
'GET',
'venues/search',
@@ -99,9 +98,9 @@ var FoursquareBackend = new Lang.Class({
},
callback,
cancellable);
- },
+ }
- createPlaces: function(rawData) {
+ createPlaces(rawData) {
return rawData.response.venues.map(function(place) {
let link = _PLACE_LINK_FORMAT.format(place.id);
diff --git a/src/foursquareGoaAuthorizer.js b/src/foursquareGoaAuthorizer.js
index ba7538e..71005b7 100644
--- a/src/foursquareGoaAuthorizer.js
+++ b/src/foursquareGoaAuthorizer.js
@@ -20,32 +20,29 @@
*/
const Rest = imports.gi.Rest;
-const Lang = imports.lang;
const _FOURSQUARE_API_VERSION = '20140226';
-var FoursquareGoaAuthorizer = new Lang.Class({
- Name: 'FoursquareGoaAuthorizer',
-
- _init: function(params) {
+var FoursquareGoaAuthorizer = class FoursquareGoaAuthorizer {
+ _init(params) {
if (!params.goaObject) {
logError('FoursquareGoaAuthorizer requires goaObject parameter');
return;
}
this.goaObject = params.goaObject;
- },
+ }
get goaObject() {
return this._goaObject;
- },
+ }
set goaObject(object) {
this._goaObject = object;
this._accessToken = null;
- },
+ }
- _refreshAccessToken: function(cancellable) {
+ _refreshAccessToken(cancellable) {
if (this._accessToken)
return true;
@@ -57,21 +54,21 @@ var FoursquareGoaAuthorizer = new Lang.Class({
}
return false;
- },
+ }
- processCall: function(restCall) {
+ processCall(restCall) {
this._refreshAccessToken(null);
restCall.add_param('oauth_token', this._accessToken);
restCall.add_param('v', _FOURSQUARE_API_VERSION);
- },
+ }
- processMessage: function(soupMessage) {
+ processMessage(soupMessage) {
this._refreshAccessToken(null);
let uri = soupMessage.get_uri();
uri.set_query(uri, 'oauth_token' + this._accessToken + '&v=' + _FOURSQUARE_API_VERSION);
- },
+ }
- refreshAuthorization: function(cancellable) {
+ refreshAuthorization(cancellable) {
let ensureCredentialsResult = this.goaObject.get_account().call_ensure_credentials_sync(cancellable);
if (ensureCredentialsResult[0]) {
this._accessToken = null;
@@ -80,7 +77,7 @@ var FoursquareGoaAuthorizer = new Lang.Class({
return false;
}
-});
+};
function newRestCall(authorizer)
{
diff --git a/src/geoclue.js b/src/geoclue.js
index 66f847b..19d2224 100644
--- a/src/geoclue.js
+++ b/src/geoclue.js
@@ -22,7 +22,6 @@
const GObject = imports.gi.GObject;
const GClue = imports.gi.Geoclue;
const Gio = imports.gi.Gio;
-const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Place = imports.place;
@@ -37,9 +36,7 @@ var State = {
FAILED: 3
};
-var Geoclue = new Lang.Class({
- Name: 'Geoclue',
- Extends: GObject.Object,
+var Geoclue = GObject.registerClass({
Signals: {
'location-changed': { }
},
@@ -53,25 +50,26 @@ var Geoclue = new Lang.Class({
State.FAILED,
State.INITIAL)
},
+}, class Geoclue extends GObject.Object {
set state(s) {
this._state = s;
this.notify('state');
- },
+ }
get state() {
return this._state;
- },
+ }
- _init: function() {
- this.parent();
+ _init() {
+ super._init();
this.place = null;
this._state = State.INITIAL;
this.start(null);
- },
+ }
- start: function(callback) {
+ start(callback) {
let id = 'org.gnome.Maps';
let level = GClue.AccuracyLevel.EXACT;
@@ -101,9 +99,9 @@ var Geoclue = new Lang.Class({
if (callback)
callback(true);
});
- },
+ }
- _onLocationNotify: function(simple) {
+ _onLocationNotify(simple) {
let geoclueLocation = simple.get_location();
let location = new Location.Location({
latitude: geoclueLocation.latitude,
@@ -113,9 +111,9 @@ var Geoclue = new Lang.Class({
description: geoclueLocation.description
});
this._updateLocation(location);
- },
+ }
- _updateLocation: function(location) {
+ _updateLocation(location) {
if (!this.place)
this.place = new Place.Place({ name: _("Current location") });
diff --git a/src/geocodeService.js b/src/geocodeService.js
index 8c90cfb..441925a 100644
--- a/src/geocodeService.js
+++ b/src/geocodeService.js
@@ -22,18 +22,13 @@
*/
const Geocode = imports.gi.GeocodeGlib;
-const Lang = imports.lang;
const Application = imports.application;
const Place = imports.place;
const Utils = imports.utils;
-var GeocodeService = new Lang.Class({
- Name: 'GeocodeService',
-
- _init: function() { },
-
- search: function(string, bbox, cancellable, callback) {
+var GeocodeService = class GeocodeService {
+ search(string, bbox, cancellable, callback) {
let answerCount = Application.settings.get('max-search-results');
let forward = Geocode.Forward.new_for_string(string);
@@ -60,9 +55,9 @@ var GeocodeService = new Lang.Class({
callback(null);
}
});
- },
+ }
- reverse: function(location, cancellable, callback) {
+ reverse(location, cancellable, callback) {
let reverse = Geocode.Reverse.new_for_location(location);
Application.application.mark_busy();
@@ -80,4 +75,4 @@ var GeocodeService = new Lang.Class({
}
});
}
-});
+};
diff --git a/src/serviceBackend.js b/src/serviceBackend.js
index bbe7165..edcfdeb 100644
--- a/src/serviceBackend.js
+++ b/src/serviceBackend.js
@@ -19,42 +19,42 @@
* Author: Damián Nohales <damiannohales gmail com>
*/
-const Lang = imports.lang;
+const GObject = imports.gi.GObject;
const Utils = imports.utils;
-var ServiceBackend = new Lang.Class({
- Name: 'SocialServiceServiceBackend',
- Abstract: true,
+var ServiceBackend = GObject.registerClass({
+ Abstract: true
+}, class ServiceBackend extends GObject.Object {
//Abstract
- get name() { },
+ get name() { }
//Abstract
- createRestCall: function(authorizer) { },
+ createRestCall(authorizer) { }
//Abstract
- refreshAuthorization: function(authorizer, cancellable) { },
+ refreshAuthorization(authorizer, cancellable) { }
//Abstract
- getAuthorizerAccount: function(authorizer) { },
+ getAuthorizerAccount(authorizer) { }
//Abstract
- createAuthorizer: function(account) { },
+ createAuthorizer(account) { }
//Abstract
- isTokenInvalid: function(restCall, parsedPayload) { },
+ isTokenInvalid(restCall, parsedPayload) { }
//Abstract
- isInvalidCall: function(restCall, parsedPayload) { },
+ isInvalidCall(restCall, parsedPayload) { }
//Abstract
- getCallResultCode: function(restCall, parsedPayload) { },
+ getCallResultCode(restCall, parsedPayload) { }
//Abstract
- getCallResultMessage: function(restCall, parsedPayload) { },
+ getCallResultMessage(restCall, parsedPayload) { }
- callAsync: function(authorizer, method, func, params, callback, cancellable, mustRefreshToken) {
+ callAsync(authorizer, method, func, params, callback, cancellable, mustRefreshToken) {
mustRefreshToken = mustRefreshToken || true;
cancellable = cancellable || null;
@@ -94,17 +94,17 @@ var ServiceBackend = new Lang.Class({
else
callback(account, data, null);
});
- },
+ }
- performCheckIn: function(authorizer, checkIn, callback, cancellable) {
+ performCheckIn(authorizer, checkIn, callback, cancellable) {
callback = callback || function() {};
this._realPerformCheckIn(authorizer, checkIn, callback, cancellable);
- },
+ }
//Abstract
- _realPerformCheckIn: function(authorizer, checkIn, callback, cancellable) { },
+ _realPerformCheckIn(authorizer, checkIn, callback, cancellable) { }
- findPlaces: function(authorizer, latitude, longitude, distance, callback, cancellable) {
+ findPlaces(authorizer, latitude, longitude, distance, callback, cancellable) {
callback = callback || function() {};
this._realFindPlaces(authorizer,
latitude,
@@ -117,11 +117,11 @@ var ServiceBackend = new Lang.Class({
callback(account, [], error);
},
cancellable);
- },
+ }
//Abstract
- _realFindPlaces: function(authorizer, latitude, longitude, distance, callback, cancellable) { },
+ _realFindPlaces(authorizer, latitude, longitude, distance, callback, cancellable) { }
//Abstract
- createPlaces: function(rawData) { }
+ createPlaces(rawData) { }
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]