2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2019-02-08 22:21:36 -05:00
|
|
|
const { Gio, GLib } = imports.gi;
|
2018-09-05 20:04:47 -04:00
|
|
|
const Config = imports.misc.config;
|
2010-09-30 17:08:22 -04:00
|
|
|
|
2013-11-04 10:07:44 -05:00
|
|
|
function collectFromDatadirs(subdir, includeUserDir, processFile) {
|
2012-11-30 10:36:12 -05:00
|
|
|
let dataDirs = GLib.get_system_data_dirs();
|
2013-11-04 10:07:44 -05:00
|
|
|
if (includeUserDir)
|
2012-11-30 10:36:12 -05:00
|
|
|
dataDirs.unshift(GLib.get_user_data_dir());
|
|
|
|
|
|
|
|
for (let i = 0; i < dataDirs.length; i++) {
|
|
|
|
let path = GLib.build_filenamev([dataDirs[i], 'gnome-shell', subdir]);
|
|
|
|
let dir = Gio.File.new_for_path(path);
|
|
|
|
|
2013-11-04 10:07:44 -05:00
|
|
|
let fileEnum;
|
|
|
|
try {
|
|
|
|
fileEnum = dir.enumerate_children('standard::name,standard::type',
|
|
|
|
Gio.FileQueryInfoFlags.NONE, null);
|
|
|
|
} catch (e) {
|
|
|
|
fileEnum = null;
|
|
|
|
}
|
|
|
|
if (fileEnum != null) {
|
|
|
|
let info;
|
|
|
|
while ((info = fileEnum.next_file(null)))
|
|
|
|
processFile(fileEnum.get_child(info), info);
|
|
|
|
}
|
2012-11-30 10:36:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-10 17:10:50 -04:00
|
|
|
function deleteGFile(file) {
|
|
|
|
// Work around 'delete' being a keyword in JS.
|
|
|
|
return file['delete'](null);
|
|
|
|
}
|
|
|
|
|
2012-06-26 20:47:44 -04:00
|
|
|
function recursivelyDeleteDir(dir, deleteParent) {
|
2011-09-10 17:10:50 -04:00
|
|
|
let children = dir.enumerate_children('standard::name,standard::type',
|
|
|
|
Gio.FileQueryInfoFlags.NONE, null);
|
|
|
|
|
2019-01-31 09:04:56 -05:00
|
|
|
let info;
|
2011-09-10 17:10:50 -04:00
|
|
|
while ((info = children.next_file(null)) != null) {
|
|
|
|
let type = info.get_file_type();
|
|
|
|
let child = dir.get_child(info.get_name());
|
|
|
|
if (type == Gio.FileType.REGULAR)
|
|
|
|
deleteGFile(child);
|
2011-11-30 21:46:52 -05:00
|
|
|
else if (type == Gio.FileType.DIRECTORY)
|
2012-06-26 20:47:44 -04:00
|
|
|
recursivelyDeleteDir(child, true);
|
2011-09-10 17:10:50 -04:00
|
|
|
}
|
|
|
|
|
2012-06-26 20:47:44 -04:00
|
|
|
if (deleteParent)
|
|
|
|
deleteGFile(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
function recursivelyMoveDir(srcDir, destDir) {
|
|
|
|
let children = srcDir.enumerate_children('standard::name,standard::type',
|
|
|
|
Gio.FileQueryInfoFlags.NONE, null);
|
|
|
|
|
|
|
|
if (!destDir.query_exists(null))
|
|
|
|
destDir.make_directory_with_parents(null);
|
|
|
|
|
2019-01-31 09:04:56 -05:00
|
|
|
let info;
|
2012-06-26 20:47:44 -04:00
|
|
|
while ((info = children.next_file(null)) != null) {
|
|
|
|
let type = info.get_file_type();
|
|
|
|
let srcChild = srcDir.get_child(info.get_name());
|
|
|
|
let destChild = destDir.get_child(info.get_name());
|
|
|
|
if (type == Gio.FileType.REGULAR)
|
|
|
|
srcChild.move(destChild, Gio.FileCopyFlags.NONE, null, null);
|
|
|
|
else if (type == Gio.FileType.DIRECTORY)
|
|
|
|
recursivelyMoveDir(srcChild, destChild);
|
|
|
|
}
|
2011-09-10 17:10:50 -04:00
|
|
|
}
|
2018-09-05 20:04:47 -04:00
|
|
|
|
|
|
|
let _ifaceResource = null;
|
|
|
|
function loadInterfaceXML(iface) {
|
|
|
|
if (!_ifaceResource) {
|
2018-10-08 15:24:00 -04:00
|
|
|
// don't use global.datadir so the method is usable from tests/tools
|
|
|
|
let dir = GLib.getenv ('GNOME_SHELL_DATADIR') || Config.PKGDATADIR;
|
|
|
|
let path = dir + '/gnome-shell-dbus-interfaces.gresource';
|
2018-09-05 20:04:47 -04:00
|
|
|
_ifaceResource = Gio.Resource.load(path);
|
|
|
|
_ifaceResource._register();
|
|
|
|
}
|
|
|
|
|
|
|
|
let xml = null;
|
|
|
|
let uri = 'resource:///org/gnome/shell/dbus-interfaces/' + iface + '.xml';
|
|
|
|
let f = Gio.File.new_for_uri(uri);
|
|
|
|
|
|
|
|
try {
|
|
|
|
let [ok, bytes] = f.load_contents(null);
|
|
|
|
if (bytes instanceof Uint8Array)
|
2019-01-28 20:18:52 -05:00
|
|
|
xml = imports.byteArray.toString(bytes);
|
2018-09-05 20:04:47 -04:00
|
|
|
else
|
2018-09-17 06:56:37 -04:00
|
|
|
xml = bytes.toString();
|
2018-09-05 20:04:47 -04:00
|
|
|
} catch (e) {
|
2019-01-29 19:18:24 -05:00
|
|
|
log(`Failed to load D-Bus interface ${iface}`);
|
2018-09-05 20:04:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return xml;
|
|
|
|
}
|