]> Pileus Git - ~andy/gtk/blob - gtk/gtksearchengine.c
Merge libgdk and libgtk
[~andy/gtk] / gtk / gtksearchengine.c
1 /*
2  * Copyright (C) 2005 Novell, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  *
18  * Author: Anders Carlsson <andersca@imendio.com>
19  *
20  * Based on nautilus-search-engine.c
21  */
22
23 #include "config.h"
24 #include "gtksearchengine.h"
25 #include "gtksearchenginebeagle.h"
26 #include "gtksearchenginesimple.h"
27 #include "gtksearchenginetracker.h"
28 #include "gtksearchenginequartz.h"
29
30 #include <gdk/gdk.h> /* for GDK_WINDOWING_QUARTZ */
31
32 #ifndef G_OS_WIN32              /* Beagle and tracker are not ported
33                                  * to Windows, as far as I know.
34                                  */
35
36 #define HAVE_BEAGLE  1
37 #define HAVE_TRACKER 1
38
39 #endif
40
41 enum 
42 {
43   HITS_ADDED,
44   HITS_SUBTRACTED,
45   FINISHED,
46   ERROR,
47   LAST_SIGNAL
48 }; 
49
50 static guint signals[LAST_SIGNAL];
51
52 G_DEFINE_ABSTRACT_TYPE (GtkSearchEngine, _gtk_search_engine, G_TYPE_OBJECT);
53
54 static void
55 finalize (GObject *object)
56 {
57   G_OBJECT_CLASS (_gtk_search_engine_parent_class)->finalize (object);
58 }
59
60 static void
61 _gtk_search_engine_class_init (GtkSearchEngineClass *class)
62 {
63   GObjectClass *gobject_class;
64   
65   gobject_class = G_OBJECT_CLASS (class);
66   gobject_class->finalize = finalize;
67   
68   signals[HITS_ADDED] =
69     g_signal_new ("hits-added",
70                   G_TYPE_FROM_CLASS (class),
71                   G_SIGNAL_RUN_LAST,
72                   G_STRUCT_OFFSET (GtkSearchEngineClass, hits_added),
73                   NULL, NULL,
74                   g_cclosure_marshal_VOID__POINTER,
75                   G_TYPE_NONE, 1,
76                   G_TYPE_POINTER);
77   
78   signals[HITS_SUBTRACTED] =
79     g_signal_new ("hits-subtracted",
80                   G_TYPE_FROM_CLASS (class),
81                   G_SIGNAL_RUN_LAST,
82                   G_STRUCT_OFFSET (GtkSearchEngineClass, hits_subtracted),
83                   NULL, NULL,
84                   g_cclosure_marshal_VOID__POINTER,
85                   G_TYPE_NONE, 1,
86                   G_TYPE_POINTER);
87   
88   signals[FINISHED] =
89     g_signal_new ("finished",
90                   G_TYPE_FROM_CLASS (class),
91                   G_SIGNAL_RUN_LAST,
92                   G_STRUCT_OFFSET (GtkSearchEngineClass, finished),
93                   NULL, NULL,
94                   g_cclosure_marshal_VOID__VOID,
95                   G_TYPE_NONE, 0);
96   
97   signals[ERROR] =
98     g_signal_new ("error",
99                   G_TYPE_FROM_CLASS (class),
100                   G_SIGNAL_RUN_LAST,
101                   G_STRUCT_OFFSET (GtkSearchEngineClass, error),
102                   NULL, NULL,
103                   g_cclosure_marshal_VOID__STRING,
104                   G_TYPE_NONE, 1,
105                   G_TYPE_STRING);  
106 }
107
108 static void
109 _gtk_search_engine_init (GtkSearchEngine *engine)
110 {
111 }
112
113 GtkSearchEngine *
114 _gtk_search_engine_new (void)
115 {
116   GtkSearchEngine *engine = NULL;
117         
118 #ifdef HAVE_TRACKER
119   engine = _gtk_search_engine_tracker_new ();
120   if (engine)
121     return engine;
122 #endif
123   
124 #ifdef HAVE_BEAGLE
125   engine = _gtk_search_engine_beagle_new ();
126   if (engine)
127     return engine;
128 #endif
129
130 #ifdef GDK_WINDOWING_QUARTZ
131   engine = _gtk_search_engine_quartz_new ();
132   if (engine)
133     return engine;
134 #endif
135
136   if (g_thread_supported ())
137     engine = _gtk_search_engine_simple_new ();
138   
139   return engine;
140 }
141
142 void
143 _gtk_search_engine_set_query (GtkSearchEngine *engine, 
144                               GtkQuery        *query)
145 {
146   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
147   g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->set_query != NULL);
148   
149   GTK_SEARCH_ENGINE_GET_CLASS (engine)->set_query (engine, query);
150 }
151
152 void
153 _gtk_search_engine_start (GtkSearchEngine *engine)
154 {
155   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
156   g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->start != NULL);
157   
158   GTK_SEARCH_ENGINE_GET_CLASS (engine)->start (engine);
159 }
160
161 void
162 _gtk_search_engine_stop (GtkSearchEngine *engine)
163 {
164   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
165   g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->stop != NULL);
166   
167   GTK_SEARCH_ENGINE_GET_CLASS (engine)->stop (engine);
168 }
169
170 gboolean
171 _gtk_search_engine_is_indexed (GtkSearchEngine *engine)
172 {
173   g_return_val_if_fail (GTK_IS_SEARCH_ENGINE (engine), FALSE);
174   g_return_val_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->is_indexed != NULL, FALSE);
175   
176   return GTK_SEARCH_ENGINE_GET_CLASS (engine)->is_indexed (engine);
177 }
178
179 void           
180 _gtk_search_engine_hits_added (GtkSearchEngine *engine, 
181                                GList           *hits)
182 {
183   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
184   
185   g_signal_emit (engine, signals[HITS_ADDED], 0, hits);
186 }
187
188
189 void           
190 _gtk_search_engine_hits_subtracted (GtkSearchEngine *engine, 
191                                     GList           *hits)
192 {
193   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
194   
195   g_signal_emit (engine, signals[HITS_SUBTRACTED], 0, hits);
196 }
197
198
199 void           
200 _gtk_search_engine_finished (GtkSearchEngine *engine)
201 {
202   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
203   
204   g_signal_emit (engine, signals[FINISHED], 0);
205 }
206
207 void
208 _gtk_search_engine_error (GtkSearchEngine *engine, 
209                           const gchar     *error_message)
210 {
211   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
212   
213   g_signal_emit (engine, signals[ERROR], 0, error_message);
214 }