]> Pileus Git - ~andy/gtk/blob - gtk/gtksearchengine.c
Add a search engine which queries the Spotlight database on MacOS X (only
[~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/gdkconfig.h> /* for GDK_WINDOWING_QUARTZ */
31
32 #define HAVE_BEAGLE  1 
33 #define HAVE_TRACKER 1
34
35 enum 
36 {
37   HITS_ADDED,
38   HITS_SUBTRACTED,
39   FINISHED,
40   ERROR,
41   LAST_SIGNAL
42 }; 
43
44 static guint signals[LAST_SIGNAL];
45
46 G_DEFINE_ABSTRACT_TYPE (GtkSearchEngine, _gtk_search_engine, G_TYPE_OBJECT);
47
48 static void
49 finalize (GObject *object)
50 {
51   G_OBJECT_CLASS (_gtk_search_engine_parent_class)->finalize (object);
52 }
53
54 static void
55 _gtk_search_engine_class_init (GtkSearchEngineClass *class)
56 {
57   GObjectClass *gobject_class;
58   
59   gobject_class = G_OBJECT_CLASS (class);
60   gobject_class->finalize = finalize;
61   
62   signals[HITS_ADDED] =
63     g_signal_new ("hits-added",
64                   G_TYPE_FROM_CLASS (class),
65                   G_SIGNAL_RUN_LAST,
66                   G_STRUCT_OFFSET (GtkSearchEngineClass, hits_added),
67                   NULL, NULL,
68                   g_cclosure_marshal_VOID__POINTER,
69                   G_TYPE_NONE, 1,
70                   G_TYPE_POINTER);
71   
72   signals[HITS_SUBTRACTED] =
73     g_signal_new ("hits-subtracted",
74                   G_TYPE_FROM_CLASS (class),
75                   G_SIGNAL_RUN_LAST,
76                   G_STRUCT_OFFSET (GtkSearchEngineClass, hits_subtracted),
77                   NULL, NULL,
78                   g_cclosure_marshal_VOID__POINTER,
79                   G_TYPE_NONE, 1,
80                   G_TYPE_POINTER);
81   
82   signals[FINISHED] =
83     g_signal_new ("finished",
84                   G_TYPE_FROM_CLASS (class),
85                   G_SIGNAL_RUN_LAST,
86                   G_STRUCT_OFFSET (GtkSearchEngineClass, finished),
87                   NULL, NULL,
88                   g_cclosure_marshal_VOID__VOID,
89                   G_TYPE_NONE, 0);
90   
91   signals[ERROR] =
92     g_signal_new ("error",
93                   G_TYPE_FROM_CLASS (class),
94                   G_SIGNAL_RUN_LAST,
95                   G_STRUCT_OFFSET (GtkSearchEngineClass, error),
96                   NULL, NULL,
97                   g_cclosure_marshal_VOID__STRING,
98                   G_TYPE_NONE, 1,
99                   G_TYPE_STRING);  
100 }
101
102 static void
103 _gtk_search_engine_init (GtkSearchEngine *engine)
104 {
105 }
106
107 GtkSearchEngine *
108 _gtk_search_engine_new (void)
109 {
110   GtkSearchEngine *engine = NULL;
111         
112 #ifdef HAVE_TRACKER
113   engine = _gtk_search_engine_tracker_new ();
114   if (engine)
115     return engine;
116 #endif
117   
118 #ifdef HAVE_BEAGLE
119   engine = _gtk_search_engine_beagle_new ();
120   if (engine)
121     return engine;
122 #endif
123
124 #ifdef GDK_WINDOWING_QUARTZ
125   engine = _gtk_search_engine_quartz_new ();
126   if (engine)
127     return engine;
128 #endif
129
130   if (g_thread_supported ())
131     engine = _gtk_search_engine_simple_new ();
132   
133   return engine;
134 }
135
136 void
137 _gtk_search_engine_set_query (GtkSearchEngine *engine, 
138                               GtkQuery        *query)
139 {
140   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
141   g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->set_query != NULL);
142   
143   GTK_SEARCH_ENGINE_GET_CLASS (engine)->set_query (engine, query);
144 }
145
146 void
147 _gtk_search_engine_start (GtkSearchEngine *engine)
148 {
149   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
150   g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->start != NULL);
151   
152   GTK_SEARCH_ENGINE_GET_CLASS (engine)->start (engine);
153 }
154
155 void
156 _gtk_search_engine_stop (GtkSearchEngine *engine)
157 {
158   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
159   g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->stop != NULL);
160   
161   GTK_SEARCH_ENGINE_GET_CLASS (engine)->stop (engine);
162 }
163
164 gboolean
165 _gtk_search_engine_is_indexed (GtkSearchEngine *engine)
166 {
167   g_return_val_if_fail (GTK_IS_SEARCH_ENGINE (engine), FALSE);
168   g_return_val_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->is_indexed != NULL, FALSE);
169   
170   return GTK_SEARCH_ENGINE_GET_CLASS (engine)->is_indexed (engine);
171 }
172
173 void           
174 _gtk_search_engine_hits_added (GtkSearchEngine *engine, 
175                                GList           *hits)
176 {
177   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
178   
179   g_signal_emit (engine, signals[HITS_ADDED], 0, hits);
180 }
181
182
183 void           
184 _gtk_search_engine_hits_subtracted (GtkSearchEngine *engine, 
185                                     GList           *hits)
186 {
187   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
188   
189   g_signal_emit (engine, signals[HITS_SUBTRACTED], 0, hits);
190 }
191
192
193 void           
194 _gtk_search_engine_finished (GtkSearchEngine *engine)
195 {
196   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
197   
198   g_signal_emit (engine, signals[FINISHED], 0);
199 }
200
201 void
202 _gtk_search_engine_error (GtkSearchEngine *engine, 
203                           const gchar     *error_message)
204 {
205   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
206   
207   g_signal_emit (engine, signals[ERROR], 0, error_message);
208 }