]> Pileus Git - ~andy/gtk/blob - gtk/gtksearchengine.c
Merge branch 'win32-theme2'
[~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 "gtksearchenginesimple.h"
26 #include "gtksearchenginetracker.h"
27 #include "gtksearchenginequartz.h"
28
29 #include <gdk/gdk.h> /* for GDK_WINDOWING_QUARTZ */
30
31 #ifndef G_OS_WIN32  /* No tracker on Windows */
32 #define HAVE_TRACKER 1
33 #endif
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 GDK_WINDOWING_QUARTZ
119   engine = _gtk_search_engine_quartz_new ();
120   if (engine)
121     return engine;
122 #endif
123
124   if (g_thread_supported ())
125     engine = _gtk_search_engine_simple_new ();
126   
127   return engine;
128 }
129
130 void
131 _gtk_search_engine_set_query (GtkSearchEngine *engine, 
132                               GtkQuery        *query)
133 {
134   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
135   g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->set_query != NULL);
136   
137   GTK_SEARCH_ENGINE_GET_CLASS (engine)->set_query (engine, query);
138 }
139
140 void
141 _gtk_search_engine_start (GtkSearchEngine *engine)
142 {
143   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
144   g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->start != NULL);
145   
146   GTK_SEARCH_ENGINE_GET_CLASS (engine)->start (engine);
147 }
148
149 void
150 _gtk_search_engine_stop (GtkSearchEngine *engine)
151 {
152   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
153   g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->stop != NULL);
154   
155   GTK_SEARCH_ENGINE_GET_CLASS (engine)->stop (engine);
156 }
157
158 gboolean
159 _gtk_search_engine_is_indexed (GtkSearchEngine *engine)
160 {
161   g_return_val_if_fail (GTK_IS_SEARCH_ENGINE (engine), FALSE);
162   g_return_val_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->is_indexed != NULL, FALSE);
163   
164   return GTK_SEARCH_ENGINE_GET_CLASS (engine)->is_indexed (engine);
165 }
166
167 void           
168 _gtk_search_engine_hits_added (GtkSearchEngine *engine, 
169                                GList           *hits)
170 {
171   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
172   
173   g_signal_emit (engine, signals[HITS_ADDED], 0, hits);
174 }
175
176
177 void           
178 _gtk_search_engine_hits_subtracted (GtkSearchEngine *engine, 
179                                     GList           *hits)
180 {
181   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
182   
183   g_signal_emit (engine, signals[HITS_SUBTRACTED], 0, hits);
184 }
185
186
187 void           
188 _gtk_search_engine_finished (GtkSearchEngine *engine)
189 {
190   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
191   
192   g_signal_emit (engine, signals[FINISHED], 0);
193 }
194
195 void
196 _gtk_search_engine_error (GtkSearchEngine *engine, 
197                           const gchar     *error_message)
198 {
199   g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
200   
201   g_signal_emit (engine, signals[ERROR], 0, error_message);
202 }