1 /* gdict-context.h - Abstract class for dictionary contexts
2  *
3  * Copyright (C) 2005  Emmanuele Bassi <ebassi@gmail.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __GDICT_CONTEXT_H__
20 #define __GDICT_CONTEXT_H__
21 
22 #include <glib-object.h>
23 
24 G_BEGIN_DECLS
25 
26 #define GDICT_TYPE_DATABASE	      (gdict_database_get_type ())
27 #define GDICT_TYPE_STRATEGY	      (gdict_strategy_get_type ())
28 #define GDICT_TYPE_MATCH              (gdict_match_get_type ())
29 #define GDICT_TYPE_DEFINITION         (gdict_definition_get_type ())
30 
31 #define GDICT_TYPE_CONTEXT	      (gdict_context_get_type ())
32 #define GDICT_CONTEXT(obj)	      (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDICT_TYPE_CONTEXT, GdictContext))
33 #define GDICT_IS_CONTEXT(obj)	      (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDICT_TYPE_CONTEXT))
34 #define GDICT_CONTEXT_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GDICT_TYPE_CONTEXT, GdictContextIface))
35 
36 /* These are the boxed containers for action results. */
37 typedef struct _GdictDatabase     GdictDatabase;
38 typedef struct _GdictStrategy     GdictStrategy;
39 typedef struct _GdictMatch        GdictMatch;
40 typedef struct _GdictDefinition   GdictDefinition;
41 
42 typedef struct _GdictContext      GdictContext; /* dummy typedef */
43 typedef struct _GdictContextIface GdictContextIface;
44 
45 #define GDICT_CONTEXT_ERROR	(gdict_context_error_quark ())
46 
47 /**
48  * GdictContextError:
49  * @GDICT_CONTEXT_ERROR_PARSE:
50  * @GDICT_CONTEXT_ERROR_NOT_IMPLEMENTED:
51  * @GDICT_CONTEXT_ERROR_INVALID_DATABASE:
52  * @GDICT_CONTEXT_ERROR_INVALID_STRATEGY:
53  * @GDICT_CONTEXT_ERROR_INVALID_COMMAND:
54  * @GDICT_CONTEXT_ERROR_NO_MATCH:
55  * @GDICT_CONTEXT_ERROR_NO_DATABASES:
56  * @GDICT_CONTEXT_ERROR_NO_STRATEGIES:
57  *
58  * #GdictContext error enumeration.
59  */
60 typedef enum {
61   GDICT_CONTEXT_ERROR_PARSE,
62   GDICT_CONTEXT_ERROR_NOT_IMPLEMENTED,
63   GDICT_CONTEXT_ERROR_INVALID_DATABASE,
64   GDICT_CONTEXT_ERROR_INVALID_STRATEGY,
65   GDICT_CONTEXT_ERROR_INVALID_COMMAND,
66   GDICT_CONTEXT_ERROR_NO_MATCH,
67   GDICT_CONTEXT_ERROR_NO_DATABASES,
68   GDICT_CONTEXT_ERROR_NO_STRATEGIES
69 } GdictContextError;
70 
71 GQuark gdict_context_error_quark (void);
72 
73 /**
74  * GdictDatabase:
75  *
76  * A #GdictDatabase represents a database inside a dictionary source.
77  *
78  * The #GdictDatabase structure is private and should only be accessed
79  * using the available functions.
80  */
81 GType                 gdict_database_get_type        (void) G_GNUC_CONST;
82 GdictDatabase *       gdict_database_ref             (GdictDatabase   *db);
83 void                  gdict_database_unref           (GdictDatabase   *db);
84 const gchar *         gdict_database_get_name        (GdictDatabase   *db);
85 const gchar *         gdict_database_get_full_name   (GdictDatabase   *db);
86 
87 /**
88  * GdictStrategy:
89  *
90  * A #GdictStrategy represents a matching strategy implemented by
91  * a dictionary source.
92  *
93  * The #GdictStrategy structure is private and should only be accessed
94  * using the available functions.
95  */
96 GType                 gdict_strategy_get_type        (void) G_GNUC_CONST;
97 GdictStrategy *       gdict_strategy_ref             (GdictStrategy   *strat);
98 void                  gdict_strategy_unref           (GdictStrategy   *strat);
99 const gchar *         gdict_strategy_get_name        (GdictStrategy   *strat);
100 const gchar *         gdict_strategy_get_description (GdictStrategy   *strat);
101 
102 /**
103  * GdictMatch:
104  *
105  * A #GdictMatch represents a single match for the searched word.
106  *
107  * The #GdictMatch structure is private and should only be accessed
108  * using the available functions.
109  */
110 GType                 gdict_match_get_type           (void) G_GNUC_CONST;
111 GdictMatch *          gdict_match_ref                (GdictMatch      *match);
112 void                  gdict_match_unref              (GdictMatch      *match);
113 const gchar *         gdict_match_get_word           (GdictMatch      *match);
114 const gchar *         gdict_match_get_database       (GdictMatch      *match);
115 
116 /**
117  * GdictDefinition:
118  *
119  * A #GdictDefinition represents a single definition for the searched
120  * word.
121  *
122  * The #GdictDefinition structure is private and should only be
123  * accessed using the available functions.
124  */
125 GType                 gdict_definition_get_type      (void) G_GNUC_CONST;
126 GdictDefinition *     gdict_definition_ref           (GdictDefinition *def);
127 void                  gdict_definition_unref         (GdictDefinition *def);
128 gint                  gdict_definition_get_total     (GdictDefinition *def);
129 const gchar *         gdict_definition_get_word      (GdictDefinition *def);
130 const gchar *         gdict_definition_get_database  (GdictDefinition *def);
131 const gchar *         gdict_definition_get_text      (GdictDefinition *def);
132 
133 /**
134  * GdictContextIface:
135  *
136  * Interface defintion
137  */
138 struct _GdictContextIface
139 {
140   /*< private >*/
141   GTypeInterface base_iface;
142 
143   /*< public >*/
144   /* methods, not signals */
145   gboolean (*get_databases)     (GdictContext  *context,
146   			         GError       **error);
147   gboolean (*get_strategies)    (GdictContext  *context,
148   			         GError       **error);
149   gboolean (*match_word)        (GdictContext  *context,
150   			         const gchar   *database,
151   			         const gchar   *strategy,
152   			         const gchar   *word,
153   			         GError       **error);
154   gboolean (*define_word)       (GdictContext  *context,
155   			         const gchar   *database,
156   			         const gchar   *word,
157   			         GError       **error);
158 
159   /* signals */
160   void (*lookup_start)              (GdictContext    *context);
161   void (*lookup_end)                (GdictContext    *context);
162 
163   void (*database_lookup_start)     (GdictContext    *context);
164   void (*database_lookup_end)       (GdictContext    *context);
165   void (*database_found)            (GdictContext    *context,
166   			             GdictDatabase   *database);
167   void (*strategy_found)            (GdictContext    *context,
168   			             GdictStrategy   *strategy);
169   void (*match_found)               (GdictContext    *context,
170   			             GdictMatch      *match);
171   void (*definition_lookup_start)   (GdictContext    *context);
172   void (*definition_lookup_end)     (GdictContext    *context);
173   void (*definition_found)          (GdictContext    *context,
174   			             GdictDefinition *definition);
175 
176   /* fired each time there's an error; the GError is owned
177    * by the context, and should never be modified or freed
178    */
179   void (*error)            (GdictContext    *context,
180   			    const GError    *error);
181 };
182 
183 GType    gdict_context_get_type          (void) G_GNUC_CONST;
184 
185 /* Configuration */
186 void     gdict_context_set_local_only    (GdictContext  *context,
187 				          gboolean       local_only);
188 gboolean gdict_context_get_local_only    (GdictContext  *context);
189 
190 /* Actions */
191 gboolean gdict_context_lookup_databases  (GdictContext  *context,
192 					  GError       **error);
193 gboolean gdict_context_lookup_strategies (GdictContext  *context,
194 					  GError       **error);
195 gboolean gdict_context_match_word        (GdictContext  *context,
196 					  const gchar   *database,
197 					  const gchar   *strategy,
198 					  const gchar   *word,
199 					  GError       **error);
200 gboolean gdict_context_define_word       (GdictContext  *context,
201 					  const gchar   *database,
202 					  const gchar   *word,
203 					  GError       **error);
204 
205 G_END_DECLS
206 
207 #endif /* __GDICT_CONTEXT_H__ */
208