|
Packit |
3ff832 |
/* vim:set et sts=4 sw=4:
|
|
Packit |
3ff832 |
*
|
|
Packit |
3ff832 |
* ibus - The Input Bus
|
|
Packit |
3ff832 |
*
|
|
Packit |
3ff832 |
* Copyright(c) 2013 Peng Huang <shawn.p.huang@gmail.com>
|
|
Packit |
3ff832 |
* Copyright(c) 2015-2018 Takao Fujiwara <takao.fujiwara1@gmail.com>
|
|
Packit |
3ff832 |
*
|
|
Packit |
3ff832 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
3ff832 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
3ff832 |
* License as published by the Free Software Foundation; either
|
|
Packit |
3ff832 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
3ff832 |
*
|
|
Packit |
3ff832 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
3ff832 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
3ff832 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
3ff832 |
* Lesser General Public License for more details.
|
|
Packit |
3ff832 |
*
|
|
Packit |
3ff832 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
3ff832 |
* License along with this library; if not, write to the Free Software
|
|
Packit |
3ff832 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
Packit |
3ff832 |
* USA
|
|
Packit |
3ff832 |
*/
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
private const string IBUS_SCHEMAS_GENERAL = "org.freedesktop.ibus.general";
|
|
Packit |
3ff832 |
private const string IBUS_SCHEMAS_GENERAL_HOTKEY =
|
|
Packit |
3ff832 |
"org.freedesktop.ibus.general.hotkey";
|
|
Packit |
3ff832 |
private const string IBUS_SCHEMAS_PANEL = "org.freedesktop.ibus.panel";
|
|
Packit |
3ff832 |
private const string IBUS_SCHEMAS_PANEL_EMOJI =
|
|
Packit |
3ff832 |
"org.freedesktop.ibus.panel.emoji";
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
bool name_only = false;
|
|
Packit |
3ff832 |
/* system() exists as a public API. */
|
|
Packit |
3ff832 |
bool is_system = false;
|
|
Packit |
3ff832 |
string cache_file = null;
|
|
Packit |
3ff832 |
string engine_id = null;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
class EngineList {
|
|
Packit |
3ff832 |
public IBus.EngineDesc[] data = {};
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
IBus.Bus? get_bus() {
|
|
Packit |
3ff832 |
var bus = new IBus.Bus();
|
|
Packit |
3ff832 |
if (!bus.is_connected ())
|
|
Packit |
3ff832 |
return null;
|
|
Packit |
3ff832 |
return bus;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
int list_engine(string[] argv) {
|
|
Packit |
3ff832 |
const OptionEntry[] options = {
|
|
Packit |
3ff832 |
{ "name-only", 0, 0, OptionArg.NONE, out name_only,
|
|
Packit |
3ff832 |
N_("List engine name only"), null },
|
|
Packit |
3ff832 |
{ null }
|
|
Packit |
3ff832 |
};
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
var option = new OptionContext();
|
|
Packit |
3ff832 |
option.add_main_entries(options, Config.GETTEXT_PACKAGE);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
try {
|
|
Packit |
3ff832 |
option.parse(ref argv);
|
|
Packit |
3ff832 |
} catch (OptionError e) {
|
|
Packit |
3ff832 |
stderr.printf("%s\n", e.message);
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
var bus = get_bus();
|
|
Packit |
3ff832 |
if (bus == null) {
|
|
Packit |
3ff832 |
stderr.printf(_("Can't connect to IBus.\n"));
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
var engines = bus.list_engines();
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (name_only) {
|
|
Packit |
3ff832 |
foreach (var engine in engines) {
|
|
Packit |
3ff832 |
print("%s\n", engine.get_name());
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
var map = new HashTable<string, EngineList>(GLib.str_hash, GLib.str_equal);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
foreach (var engine in engines) {
|
|
Packit |
3ff832 |
var list = map.get(engine.get_language());
|
|
Packit |
3ff832 |
if (list == null) {
|
|
Packit |
3ff832 |
list = new EngineList();
|
|
Packit |
3ff832 |
map.insert(engine.get_language(), list);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
list.data += engine;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
foreach (var language in map.get_keys()) {
|
|
Packit |
3ff832 |
var list = map.get(language);
|
|
Packit |
3ff832 |
print(_("language: %s\n"), IBus.get_language_name(language));
|
|
Packit |
3ff832 |
foreach (var engine in list.data) {
|
|
Packit |
3ff832 |
print(" %s - %s\n", engine.get_name(), engine.get_longname());
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
private int exec_setxkbmap(IBus.EngineDesc engine) {
|
|
Packit |
3ff832 |
string layout = engine.get_layout();
|
|
Packit |
3ff832 |
string variant = engine.get_layout_variant();
|
|
Packit |
3ff832 |
string option = engine.get_layout_option();
|
|
Packit |
3ff832 |
string standard_error = null;
|
|
Packit |
3ff832 |
int exit_status = 0;
|
|
Packit |
3ff832 |
string[] args = { "setxkbmap" };
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (layout != null && layout != "" && layout != "default") {
|
|
Packit |
3ff832 |
args += "-layout";
|
|
Packit |
3ff832 |
args += layout;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
if (variant != null && variant != "" && variant != "default") {
|
|
Packit |
3ff832 |
args += "-variant";
|
|
Packit |
3ff832 |
args += variant;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
if (option != null && option != "" && option != "default") {
|
|
Packit |
3ff832 |
/*TODO: Need to get the session XKB options */
|
|
Packit |
3ff832 |
args += "-option";
|
|
Packit |
3ff832 |
args += "-option";
|
|
Packit |
3ff832 |
args += option;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (args.length == 1) {
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
try {
|
|
Packit |
3ff832 |
if (!GLib.Process.spawn_sync(null, args, null,
|
|
Packit |
3ff832 |
GLib.SpawnFlags.SEARCH_PATH,
|
|
Packit |
3ff832 |
null, null,
|
|
Packit |
3ff832 |
out standard_error,
|
|
Packit |
3ff832 |
out exit_status)) {
|
|
Packit |
3ff832 |
warning("Switch xkb layout to %s failed.",
|
|
Packit |
3ff832 |
engine.get_layout());
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
} catch (GLib.SpawnError e) {
|
|
Packit |
3ff832 |
warning("Execute setxkbmap failed: %s", e.message);
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (exit_status != 0) {
|
|
Packit |
3ff832 |
warning("Execute setxkbmap failed: %s", standard_error ?? "(null)");
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
int get_set_engine(string[] argv) {
|
|
Packit |
3ff832 |
var bus = get_bus();
|
|
Packit |
3ff832 |
string engine = null;
|
|
Packit |
3ff832 |
if (argv.length > 1)
|
|
Packit |
3ff832 |
engine = argv[1];
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (engine == null) {
|
|
Packit |
3ff832 |
var desc = bus.get_global_engine();
|
|
Packit |
3ff832 |
if (desc == null) {
|
|
Packit |
3ff832 |
stderr.printf(_("No engine is set.\n"));
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
print("%s\n", desc.get_name());
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if(!bus.set_global_engine(engine)) {
|
|
Packit |
3ff832 |
stderr.printf(_("Set global engine failed.\n"));
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
var desc = bus.get_global_engine();
|
|
Packit |
3ff832 |
if (desc == null) {
|
|
Packit |
3ff832 |
stderr.printf(_("Get global engine failed.\n"));
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
var settings = new GLib.Settings(IBUS_SCHEMAS_GENERAL);
|
|
Packit |
3ff832 |
if (!settings.get_boolean("use-system-keyboard-layout"))
|
|
Packit |
3ff832 |
return exec_setxkbmap(desc);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
int message_watch(string[] argv) {
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
int restart_daemon(string[] argv) {
|
|
Packit |
3ff832 |
var bus = get_bus();
|
|
Packit |
3ff832 |
if (bus == null) {
|
|
Packit |
3ff832 |
stderr.printf(_("Can't connect to IBus.\n"));
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
bus.exit(true);
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
int exit_daemon(string[] argv) {
|
|
Packit |
3ff832 |
var bus = get_bus();
|
|
Packit |
3ff832 |
if (bus == null) {
|
|
Packit |
3ff832 |
stderr.printf(_("Can't connect to IBus.\n"));
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
bus.exit(false);
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
int print_version(string[] argv) {
|
|
Packit |
3ff832 |
print("IBus %s\n", Config.PACKAGE_VERSION);
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
int read_cache (string[] argv) {
|
|
Packit |
3ff832 |
const OptionEntry[] options = {
|
|
Packit |
3ff832 |
{ "system", 0, 0, OptionArg.NONE, out is_system,
|
|
Packit |
3ff832 |
N_("Read the system registry cache."), null },
|
|
Packit |
3ff832 |
{ "file", 0, 0, OptionArg.STRING, out cache_file,
|
|
Packit |
3ff832 |
N_("Read the registry cache FILE."), "FILE" },
|
|
Packit |
3ff832 |
{ null }
|
|
Packit |
3ff832 |
};
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
var option = new OptionContext();
|
|
Packit |
3ff832 |
option.add_main_entries(options, Config.GETTEXT_PACKAGE);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
try {
|
|
Packit |
3ff832 |
option.parse(ref argv);
|
|
Packit |
3ff832 |
} catch (OptionError e) {
|
|
Packit |
3ff832 |
stderr.printf("%s\n", e.message);
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
var registry = new IBus.Registry();
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (cache_file != null) {
|
|
Packit |
3ff832 |
if (!registry.load_cache_file(cache_file)) {
|
|
Packit |
3ff832 |
stderr.printf(_("The registry cache is invalid.\n"));
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
} else {
|
|
Packit |
3ff832 |
if (!registry.load_cache(!is_system)) {
|
|
Packit |
3ff832 |
stderr.printf(_("The registry cache is invalid.\n"));
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
var output = new GLib.StringBuilder();
|
|
Packit |
3ff832 |
registry.output(output, 1);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
print ("%s\n", output.str);
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
int write_cache (string[] argv) {
|
|
Packit |
3ff832 |
const OptionEntry[] options = {
|
|
Packit |
3ff832 |
{ "system", 0, 0, OptionArg.NONE, out is_system,
|
|
Packit |
3ff832 |
N_("Write the system registry cache."), null },
|
|
Packit |
3ff832 |
{ "file", 0, 0, OptionArg.STRING, out cache_file,
|
|
Packit |
3ff832 |
N_("Write the registry cache FILE."),
|
|
Packit |
3ff832 |
"FILE" },
|
|
Packit |
3ff832 |
{ null }
|
|
Packit |
3ff832 |
};
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
var option = new OptionContext();
|
|
Packit |
3ff832 |
option.add_main_entries(options, Config.GETTEXT_PACKAGE);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
try {
|
|
Packit |
3ff832 |
option.parse(ref argv);
|
|
Packit |
3ff832 |
} catch (OptionError e) {
|
|
Packit |
3ff832 |
stderr.printf("%s\n", e.message);
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
var registry = new IBus.Registry();
|
|
Packit |
3ff832 |
registry.load();
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (cache_file != null) {
|
|
Packit |
3ff832 |
return registry.save_cache_file(cache_file) ?
|
|
Packit |
3ff832 |
Posix.EXIT_SUCCESS : Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return registry.save_cache(!is_system) ?
|
|
Packit |
3ff832 |
Posix.EXIT_SUCCESS : Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
int print_address(string[] argv) {
|
|
Packit |
3ff832 |
string address = IBus.get_address();
|
|
Packit |
3ff832 |
print("%s\n", address != null ? address : "(null)");
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
private int read_config_options(string[] argv) {
|
|
Packit |
3ff832 |
const OptionEntry[] options = {
|
|
Packit |
3ff832 |
{ "engine-id", 0, 0, OptionArg.STRING, out engine_id,
|
|
Packit |
3ff832 |
N_("Use engine schema paths instead of ibus core, " +
|
|
Packit |
3ff832 |
"which can be comma-separated values."), "ENGINE_ID" },
|
|
Packit |
3ff832 |
{ null }
|
|
Packit |
3ff832 |
};
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
var option = new OptionContext();
|
|
Packit |
3ff832 |
option.add_main_entries(options, Config.GETTEXT_PACKAGE);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
try {
|
|
Packit |
3ff832 |
option.parse(ref argv);
|
|
Packit |
3ff832 |
} catch (OptionError e) {
|
|
Packit |
3ff832 |
stderr.printf("%s\n", e.message);
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
private GLib.SList<string> get_ibus_schemas() {
|
|
Packit |
3ff832 |
string[] ids = {};
|
|
Packit |
3ff832 |
if (engine_id != null) {
|
|
Packit |
3ff832 |
ids = engine_id.split(",");
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
GLib.SList<string> ibus_schemas = new GLib.SList<string>();
|
|
Packit |
3ff832 |
GLib.SettingsSchemaSource schema_source =
|
|
Packit |
3ff832 |
GLib.SettingsSchemaSource.get_default();
|
|
Packit |
3ff832 |
string[] list_schemas = {};
|
|
Packit |
3ff832 |
schema_source.list_schemas(true, out list_schemas, null);
|
|
Packit |
3ff832 |
foreach (string schema in list_schemas) {
|
|
Packit |
3ff832 |
if (ids.length != 0) {
|
|
Packit |
3ff832 |
foreach (unowned string id in ids) {
|
|
Packit |
3ff832 |
if (id == schema ||
|
|
Packit |
3ff832 |
schema.has_prefix("org.freedesktop.ibus.engine." + id)) {
|
|
Packit |
3ff832 |
ibus_schemas.prepend(schema);
|
|
Packit |
3ff832 |
break;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
} else if (schema.has_prefix("org.freedesktop.ibus") &&
|
|
Packit |
3ff832 |
!schema.has_prefix("org.freedesktop.ibus.engine")) {
|
|
Packit |
3ff832 |
ibus_schemas.prepend(schema);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
if (ibus_schemas.length() == 0) {
|
|
Packit |
3ff832 |
printerr("Not found schemas of \"org.freedesktop.ibus\"\n");
|
|
Packit |
3ff832 |
return ibus_schemas;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
ibus_schemas.sort(GLib.strcmp);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return ibus_schemas;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
int read_config(string[] argv) {
|
|
Packit |
3ff832 |
if (read_config_options(argv) == Posix.EXIT_FAILURE)
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
GLib.SList<string> ibus_schemas = get_ibus_schemas();
|
|
Packit |
3ff832 |
if (ibus_schemas.length() == 0)
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
GLib.SettingsSchemaSource schema_source =
|
|
Packit |
3ff832 |
GLib.SettingsSchemaSource.get_default();
|
|
Packit |
3ff832 |
var output = new GLib.StringBuilder();
|
|
Packit |
3ff832 |
foreach (string schema in ibus_schemas) {
|
|
Packit |
3ff832 |
GLib.SettingsSchema settings_schema = schema_source.lookup(schema,
|
|
Packit |
3ff832 |
false);
|
|
Packit |
3ff832 |
GLib.Settings settings = new GLib.Settings(schema);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
output.append_printf("SCHEMA: %s\n", schema);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
foreach (string key in settings_schema.list_keys()) {
|
|
Packit |
3ff832 |
GLib.Variant variant = settings.get_value(key);
|
|
Packit |
3ff832 |
output.append_printf(" %s: %s\n", key, variant.print(true));
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
print("%s", output.str);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
int reset_config(string[] argv) {
|
|
Packit |
3ff832 |
if (read_config_options(argv) == Posix.EXIT_FAILURE)
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
GLib.SList<string> ibus_schemas = get_ibus_schemas();
|
|
Packit |
3ff832 |
if (ibus_schemas.length() == 0)
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
print("%s\n", _("Resetting…"));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
GLib.SettingsSchemaSource schema_source =
|
|
Packit |
3ff832 |
GLib.SettingsSchemaSource.get_default();
|
|
Packit |
3ff832 |
foreach (string schema in ibus_schemas) {
|
|
Packit |
3ff832 |
GLib.SettingsSchema settings_schema = schema_source.lookup(schema,
|
|
Packit |
3ff832 |
false);
|
|
Packit |
3ff832 |
GLib.Settings settings = new GLib.Settings(schema);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
print("SCHEMA: %s\n", schema);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
foreach (string key in settings_schema.list_keys()) {
|
|
Packit |
3ff832 |
print(" %s\n", key);
|
|
Packit |
3ff832 |
settings.reset(key);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
GLib.Settings.sync();
|
|
Packit |
3ff832 |
print("%s\n", _("Done"));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
#if EMOJI_DICT
|
|
Packit |
3ff832 |
int emoji_dialog(string[] argv) {
|
|
Packit |
3ff832 |
string cmd = Config.LIBEXECDIR + "/ibus-ui-emojier";
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
var file = File.new_for_path(cmd);
|
|
Packit |
3ff832 |
if (!file.query_exists())
|
|
Packit |
3ff832 |
cmd = "../ui/gtk3/ibus-ui-emojier";
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
argv[0] = cmd;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
string[] env = Environ.get();
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
try {
|
|
Packit |
3ff832 |
// Non-blocking
|
|
Packit |
3ff832 |
Process.spawn_async(null, argv, env,
|
|
Packit |
3ff832 |
SpawnFlags.SEARCH_PATH,
|
|
Packit |
3ff832 |
null, null);
|
|
Packit |
3ff832 |
} catch (SpawnError e) {
|
|
Packit |
3ff832 |
stderr.printf("%s\n", e.message);
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
#endif
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
int print_help(string[] argv) {
|
|
Packit |
3ff832 |
print_usage(stdout);
|
|
Packit |
3ff832 |
return Posix.EXIT_SUCCESS;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
delegate int EntryFunc(string[] argv);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
struct CommandEntry {
|
|
Packit |
3ff832 |
unowned string name;
|
|
Packit |
3ff832 |
unowned string description;
|
|
Packit |
3ff832 |
unowned EntryFunc entry;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
const CommandEntry commands[] = {
|
|
Packit |
3ff832 |
{ "engine", N_("Set or get engine"), get_set_engine },
|
|
Packit |
3ff832 |
{ "exit", N_("Exit ibus-daemon"), exit_daemon },
|
|
Packit |
3ff832 |
{ "list-engine", N_("Show available engines"), list_engine },
|
|
Packit |
3ff832 |
{ "watch", N_("(Not implemented)"), message_watch },
|
|
Packit |
3ff832 |
{ "restart", N_("Restart ibus-daemon"), restart_daemon },
|
|
Packit |
3ff832 |
{ "version", N_("Show version"), print_version },
|
|
Packit |
3ff832 |
{ "read-cache", N_("Show the content of registry cache"), read_cache },
|
|
Packit |
3ff832 |
{ "write-cache", N_("Create registry cache"), write_cache },
|
|
Packit |
3ff832 |
{ "address", N_("Print the D-Bus address of ibus-daemon"), print_address },
|
|
Packit |
3ff832 |
{ "read-config", N_("Show the configuration values"), read_config },
|
|
Packit |
3ff832 |
{ "reset-config", N_("Reset the configuration values"), reset_config },
|
|
Packit |
3ff832 |
#if EMOJI_DICT
|
|
Packit |
3ff832 |
{ "emoji", N_("Save emoji on dialog to clipboard "), emoji_dialog },
|
|
Packit |
3ff832 |
#endif
|
|
Packit |
3ff832 |
{ "help", N_("Show this information"), print_help }
|
|
Packit |
3ff832 |
};
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
static string program_name;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
void print_usage(FileStream stream) {
|
|
Packit |
3ff832 |
stream.printf(_("Usage: %s COMMAND [OPTION...]\n\n"), program_name);
|
|
Packit |
3ff832 |
stream.printf(_("Commands:\n"));
|
|
Packit |
3ff832 |
for (int i = 0; i < commands.length; i++) {
|
|
Packit |
3ff832 |
stream.printf(" %-12s %s\n",
|
|
Packit |
3ff832 |
commands[i].name,
|
|
Packit |
3ff832 |
GLib.dgettext(null, commands[i].description));
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
public int main(string[] argv) {
|
|
Packit |
3ff832 |
GLib.Intl.setlocale(GLib.LocaleCategory.ALL, "");
|
|
Packit |
3ff832 |
GLib.Intl.bindtextdomain(Config.GETTEXT_PACKAGE, Config.GLIB_LOCALE_DIR);
|
|
Packit |
3ff832 |
GLib.Intl.bind_textdomain_codeset(Config.GETTEXT_PACKAGE, "UTF-8");
|
|
Packit |
3ff832 |
GLib.Intl.textdomain(Config.GETTEXT_PACKAGE);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
IBus.init();
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
program_name = Path.get_basename(argv[0]);
|
|
Packit |
3ff832 |
if (argv.length < 2) {
|
|
Packit |
3ff832 |
print_usage(stderr);
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
string[] new_argv = argv[1:argv.length];
|
|
Packit |
3ff832 |
new_argv[0] = "%s %s".printf(program_name, new_argv[0]);
|
|
Packit |
3ff832 |
for (int i = 0; i < commands.length; i++) {
|
|
Packit |
3ff832 |
if (commands[i].name == argv[1])
|
|
Packit |
3ff832 |
return commands[i].entry(new_argv);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
stderr.printf(_("%s is unknown command!\n"), argv[1]);
|
|
Packit |
3ff832 |
print_usage(stderr);
|
|
Packit |
3ff832 |
return Posix.EXIT_FAILURE;
|
|
Packit |
3ff832 |
}
|