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