Port to GDBus 2

The GDBus bindings in gjs have been updated to leverage metaclasses
and gobject inheritance, which should result in cleaner and more
maintainable code.
This commit is contained in:
Giovanni Campagna
2011-12-10 14:54:39 +01:00
parent aef9b733e5
commit a6b4d68a1d
20 changed files with 543 additions and 286 deletions

View File

@ -29,8 +29,15 @@ const SearchProviderIface = <interface name="org.gnome.Shell.SearchProvider">
</method>
</interface>;
var SearchProviderProxy = Gio.DBusProxy.makeProxyWrapper(SearchProviderIface);
var SearchProviderProxy = new Gio.DBusProxyClass({
Name: 'SearchProviderProxy',
Interface: SearchProviderIface,
_init: function(params) {
params.g_bus_type = Gio.BusType.SESSION;
this.parent(params);
}
});
function loadRemoteSearchProviders(addProviderCallback) {
let dataDirs = GLib.get_system_data_dirs();
@ -107,8 +114,9 @@ const RemoteSearchProvider = new Lang.Class({
Extends: Search.SearchProvider,
_init: function(title, icon, dbusName, dbusPath) {
this._proxy = new SearchProviderProxy(Gio.DBus.session,
dbusName, dbusPath);
this._proxy = new SearchProviderProxy({ g_name: dbusName,
g_object_path: dbusPath });
this._proxy.init(null);
this.parent(title.toUpperCase());
this._cancellable = new Gio.Cancellable();
@ -131,10 +139,17 @@ const RemoteSearchProvider = new Lang.Class({
icon_size: size });
},
_getResultsFinished: function(results, error) {
if (error)
return;
this.searchSystem.pushResults(this, results[0]);
_getResultsFinished: function(proxy, result) {
try {
// We rely on a small implementation detail of the
// GDBus bindings here: all *Finish are equal
let [results] = proxy.GetInitialResultSetFinish(result);
this.searchSystem.pushResults(this, results);
} catch(e) {
if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
log('Received error from search provider %s: %s'.format(this.title, String(e)));
}
},
getInitialResultSet: function(terms) {
@ -142,8 +157,8 @@ const RemoteSearchProvider = new Lang.Class({
this._cancellable.reset();
try {
this._proxy.GetInitialResultSetRemote(terms,
Lang.bind(this, this._getResultsFinished),
this._cancellable);
this._cancellable,
Lang.bind(this, this._getResultsFinished));
} catch(e) {
log('Error calling GetInitialResultSet for provider %s: %s'.format( this.title, e.toString()));
this.searchSystem.pushResults(this, []);
@ -155,30 +170,30 @@ const RemoteSearchProvider = new Lang.Class({
this._cancellable.reset();
try {
this._proxy.GetSubsearchResultSetRemote(previousResults, newTerms,
Lang.bind(this, this._getResultsFinished),
this._cancellable);
this._cancellable,
Lang.bind(this, this._getResultsFinished))
} catch(e) {
log('Error calling GetSubsearchResultSet for provider %s: %s'.format(this.title, e.toString()));
this.searchSystem.pushResults(this, []);
}
},
_getResultMetasFinished: function(results, error, callback) {
if (error) {
_getResultMetasFinished: function(proxy, result, callback) {
try {
let [metas] = results.GetResultMetasFinish(result);
let resultMetas = [];
for (let i = 0; i < metas.length; i++) {
for (let prop in metas[i])
metas[i][prop] = metas[i][prop].deep_unpack();
resultMetas.push({ id: metas[i]['id'],
name: metas[i]['name'],
createIcon: Lang.bind(this,
this.createIcon, metas[i]) });
}
callback(resultMetas);
} catch(e) {
callback([]);
return;
}
let metas = results[0];
let resultMetas = [];
for (let i = 0; i < metas.length; i++) {
for (let prop in metas[i])
metas[i][prop] = metas[i][prop].deep_unpack();
resultMetas.push({ id: metas[i]['id'],
name: metas[i]['name'],
createIcon: Lang.bind(this,
this.createIcon, metas[i]) });
}
callback(resultMetas);
},
getResultMetas: function(ids, callback) {
@ -186,8 +201,8 @@ const RemoteSearchProvider = new Lang.Class({
this._cancellable.reset();
try {
this._proxy.GetResultMetasRemote(ids,
Lang.bind(this, this._getResultMetasFinished, callback),
this._cancellable);
this._cancellable,
Lang.bind(this, this._getResultMetasFinished, callback));
} catch(e) {
log('Error calling GetResultMetas for provider %s: %s'.format(this.title, e.toString()));
callback([]);
@ -195,7 +210,7 @@ const RemoteSearchProvider = new Lang.Class({
},
activateResult: function(id) {
this._proxy.ActivateResultRemote(id);
this._proxy.ActivateResultRemote(id, null, null);
}
});