1/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2/* vim:set et sts=4: */
3/* bus - The Input Bus
4 * Copyright (C) 2013 Peng Huang <shawn.p.huang@gmail.com>
5 * Copyright (C) 2013 Takao Fujiwara <takao.fujiwara1@gmail.com>
6 * Copyright (C) 2013 Red Hat, Inc.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21 * USA
22 */
23
24#if !defined (__IBUS_H_INSIDE__) && !defined (IBUS_COMPILATION)
25#error "Only <ibus.h> can be included directly"
26#endif
27
28#ifndef __IBUS_REGISTRY_H_
29#define __IBUS_REGISTRY_H_
30
31/**
32 * SECTION: ibusregistry
33 * @short_description: Registry cache handling.
34 * @title: IBusRegistry
35 * @stability: Stable
36 *
37 * An #IBusRegistry loads IBus component files and generates the cache files.
38 *
39 * see_also: #IBusComponent
40 */
41
42#include "ibuscomponent.h"
43
44/*
45 * Type macros.
46 */
47
48/* define GOBJECT macros */
49#define IBUS_TYPE_REGISTRY \
50 (ibus_registry_get_type ())
51#define IBUS_REGISTRY(obj) \
52 (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_TYPE_REGISTRY, IBusRegistry))
53#define IBUS_REGISTRY_CLASS(klass) \
54 (G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_TYPE_REGISTRY, IBusRegistryClass))
55#define IBUS_IS_REGISTRY(obj) \
56 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_TYPE_REGISTRY))
57#define IBUS_IS_REGISTRY_CLASS(klass) \
58 (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_REGISTRY))
59#define IBUS_REGISTRY_GET_CLASS(obj) \
60 (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_TYPE_REGISTRY, IBusRegistryClass))
61
62G_BEGIN_DECLS
63
64typedef struct _IBusRegistry IBusRegistry;
65typedef struct _IBusRegistryPrivate IBusRegistryPrivate;
66typedef struct _IBusRegistryClass IBusRegistryClass;
67
68/**
69 * IBusRegistry:
70 *
71 * Registry cache handling.
72 * You can load the registry from compose files or a cache file.
73 */
74struct _IBusRegistry {
75 /* instance members */
76 /*< private >*/
77 IBusSerializable parent;
78 IBusRegistryPrivate *priv;
79};
80
81struct _IBusRegistryClass {
82 /* class members */
83 /*< private >*/
84 IBusSerializableClass parent;
85};
86
87GType ibus_registry_get_type (void);
88
89/**
90 * ibus_registry_new:
91 *
92 * Creates a new #IBusRegistry
93 *
94 * Returns: A newly allocated #IBusRegistry.
95 */
96IBusRegistry *ibus_registry_new (void);
97
98/**
99 * ibus_registry_load:
100 * @registry: An #IBusRegistry.
101 *
102 * Read all XML files in a IBus component directory (typically
103 * /usr/share/ibus/component/ *.xml) and update the registry object.
104 * IBUS_COMPONENT_PATH environment valuable is also available for
105 * the custom component directories, whose delimiter is ':'.
106 */
107void ibus_registry_load (IBusRegistry *registry);
108
109/**
110 * ibus_registry_load_in_dir:
111 * @registry: An #IBusRegistry.
112 * @dirname: IBus component directory which includes XML files.
113 *
114 * Read all XML files in @dirname, create a #IBusComponent object for each file,
115 * and add the component objects to the registry.
116 * If @dirname is "/usr/share/ibus/component", this API and
117 * ibus_registry_load() are same.
118 */
119void ibus_registry_load_in_dir (IBusRegistry *registry,
120 const gchar *dirname);
121
122/**
123 * ibus_registry_load_cache:
124 * @registry: An #IBusRegistry.
125 * @is_user: %TRUE if the registry cache is loaded in the user directory.
126 *
127 * Load the user or system registry cache.
128 *
129 * Returns: %TRUE if the cache exists and is loaded successfully,
130 * %FALSE otherwise.
131 */
132gboolean ibus_registry_load_cache (IBusRegistry *registry,
133 gboolean is_user);
134
135/**
136 * ibus_registry_load_cache_file:
137 * @registry: An #IBusRegistry.
138 * @filename: The file path of the registry cache
139 *
140 * Load the registry cache @filename.
141 *
142 * Returns: %TRUE if the cache exists and is loaded successfully,
143 * %FALSE otherwise.
144 */
145gboolean ibus_registry_load_cache_file (IBusRegistry *registry,
146 const gchar *filename);
147
148/**
149 * ibus_registry_save_cache:
150 * @registry: An #IBusRegistry.
151 * @is_user: %TRUE if the registry cache is saved in the user directory.
152 *
153 * Save the registry in a user directory or system directory.
154 *
155 * Returns: %TRUE if the cache is saved successfully, %FALSE otherwise.
156 */
157gboolean ibus_registry_save_cache (IBusRegistry *registry,
158 gboolean is_user);
159
160/**
161 * ibus_registry_save_cache_file:
162 * @registry: An #IBusRegistry.
163 * @filename: The file path of the registry cache
164 *
165 * Save the registry cache @filename.
166 *
167 * Returns: %TRUE if the cache is saved successfully, %FALSE otherwise.
168 */
169gboolean ibus_registry_save_cache_file (IBusRegistry *registry,
170 const gchar *filename);
171
172/**
173 * ibus_registry_output:
174 * @registry: An #IBusRegistry.
175 * @output: GString that holds the result.
176 * @indent: level of indent.
177 *
178 * Output #IBusRegistry as an XML-formatted string.
179 * The output string can be then shown on the screen or written to file.
180 */
181void ibus_registry_output (IBusRegistry *registry,
182 GString *output,
183 int indent);
184
185/**
186 * ibus_registry_check_modification:
187 * @registry: An #IBusRegistry.
188 *
189 * Check if the registry is updated.
190 *
191 * Returns: %TRUE if mtime is changed; %FALSE otherwise.
192 */
193gboolean ibus_registry_check_modification
194 (IBusRegistry *registry);
195
196/**
197 * ibus_registry_get_components:
198 * @registry: An #IBusRegistry.
199 *
200 * List components.
201 *
202 * Returns: (transfer container) (element-type IBusComponent):
203 * a list of #IBusComponent objects.
204 * The caller has to call g_list_free() for the returned list.
205 */
206GList *ibus_registry_get_components (IBusRegistry *registry);
207
208/**
209 * ibus_registry_get_observed_paths:
210 * @registry: An #IBusRegistry.
211 *
212 * List observed paths.
213 *
214 * Returns: (transfer container) (element-type IBusObservedPath):
215 * a list of #IBusObservedPath objects.
216 * The caller has to call g_list_free() for the returned list.
217 */
218GList *ibus_registry_get_observed_paths
219 (IBusRegistry *registry);
220
221/**
222 * ibus_registry_start_monitor_changes:
223 * @registry: An #IBusRegistry.
224 *
225 * Start to monitor observed paths.
226 */
227void ibus_registry_start_monitor_changes
228 (IBusRegistry *registry);
229
230G_END_DECLS
231#endif
232