Formatting fixes

This commit is contained in:
Matthias Clasen 2015-02-28 16:13:18 -05:00
parent f126157bfa
commit 8a0d02c548
2 changed files with 108 additions and 108 deletions

View File

@ -31,14 +31,14 @@
#define HAVE_TRACKER 1 #define HAVE_TRACKER 1
#endif #endif
enum enum
{ {
HITS_ADDED, HITS_ADDED,
HITS_SUBTRACTED, HITS_SUBTRACTED,
FINISHED, FINISHED,
ERROR, ERROR,
LAST_SIGNAL LAST_SIGNAL
}; };
static guint signals[LAST_SIGNAL]; static guint signals[LAST_SIGNAL];
@ -49,42 +49,42 @@ _gtk_search_engine_class_init (GtkSearchEngineClass *class)
{ {
signals[HITS_ADDED] = signals[HITS_ADDED] =
g_signal_new ("hits-added", g_signal_new ("hits-added",
G_TYPE_FROM_CLASS (class), G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkSearchEngineClass, hits_added), G_STRUCT_OFFSET (GtkSearchEngineClass, hits_added),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__POINTER, g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_POINTER); G_TYPE_POINTER);
signals[HITS_SUBTRACTED] = signals[HITS_SUBTRACTED] =
g_signal_new ("hits-subtracted", g_signal_new ("hits-subtracted",
G_TYPE_FROM_CLASS (class), G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkSearchEngineClass, hits_subtracted), G_STRUCT_OFFSET (GtkSearchEngineClass, hits_subtracted),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__POINTER, g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_POINTER); G_TYPE_POINTER);
signals[FINISHED] = signals[FINISHED] =
g_signal_new ("finished", g_signal_new ("finished",
G_TYPE_FROM_CLASS (class), G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkSearchEngineClass, finished), G_STRUCT_OFFSET (GtkSearchEngineClass, finished),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__VOID, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
signals[ERROR] = signals[ERROR] =
g_signal_new ("error", g_signal_new ("error",
G_TYPE_FROM_CLASS (class), G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkSearchEngineClass, error), G_STRUCT_OFFSET (GtkSearchEngineClass, error),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__STRING, g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_STRING); G_TYPE_STRING);
} }
static void static void
@ -96,7 +96,7 @@ GtkSearchEngine *
_gtk_search_engine_new (void) _gtk_search_engine_new (void)
{ {
GtkSearchEngine *engine = NULL; GtkSearchEngine *engine = NULL;
#ifdef HAVE_TRACKER #ifdef HAVE_TRACKER
engine = _gtk_search_engine_tracker_new (); engine = _gtk_search_engine_tracker_new ();
if (engine) if (engine)
@ -105,7 +105,7 @@ _gtk_search_engine_new (void)
return engine; return engine;
} }
#endif #endif
#ifdef GDK_WINDOWING_QUARTZ #ifdef GDK_WINDOWING_QUARTZ
engine = _gtk_search_engine_quartz_new (); engine = _gtk_search_engine_quartz_new ();
if (engine) if (engine)
@ -125,12 +125,12 @@ _gtk_search_engine_new (void)
} }
void void
_gtk_search_engine_set_query (GtkSearchEngine *engine, _gtk_search_engine_set_query (GtkSearchEngine *engine,
GtkQuery *query) GtkQuery *query)
{ {
g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine)); g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->set_query != NULL); g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->set_query != NULL);
GTK_SEARCH_ENGINE_GET_CLASS (engine)->set_query (engine, query); GTK_SEARCH_ENGINE_GET_CLASS (engine)->set_query (engine, query);
} }
@ -139,7 +139,7 @@ _gtk_search_engine_start (GtkSearchEngine *engine)
{ {
g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine)); g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->start != NULL); g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->start != NULL);
GTK_SEARCH_ENGINE_GET_CLASS (engine)->start (engine); GTK_SEARCH_ENGINE_GET_CLASS (engine)->start (engine);
} }
@ -148,7 +148,7 @@ _gtk_search_engine_stop (GtkSearchEngine *engine)
{ {
g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine)); g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->stop != NULL); g_return_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->stop != NULL);
GTK_SEARCH_ENGINE_GET_CLASS (engine)->stop (engine); GTK_SEARCH_ENGINE_GET_CLASS (engine)->stop (engine);
} }
@ -157,43 +157,43 @@ _gtk_search_engine_is_indexed (GtkSearchEngine *engine)
{ {
g_return_val_if_fail (GTK_IS_SEARCH_ENGINE (engine), FALSE); g_return_val_if_fail (GTK_IS_SEARCH_ENGINE (engine), FALSE);
g_return_val_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->is_indexed != NULL, FALSE); g_return_val_if_fail (GTK_SEARCH_ENGINE_GET_CLASS (engine)->is_indexed != NULL, FALSE);
return GTK_SEARCH_ENGINE_GET_CLASS (engine)->is_indexed (engine); return GTK_SEARCH_ENGINE_GET_CLASS (engine)->is_indexed (engine);
} }
void void
_gtk_search_engine_hits_added (GtkSearchEngine *engine, _gtk_search_engine_hits_added (GtkSearchEngine *engine,
GList *hits) GList *hits)
{ {
g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine)); g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
g_signal_emit (engine, signals[HITS_ADDED], 0, hits); g_signal_emit (engine, signals[HITS_ADDED], 0, hits);
} }
void void
_gtk_search_engine_hits_subtracted (GtkSearchEngine *engine, _gtk_search_engine_hits_subtracted (GtkSearchEngine *engine,
GList *hits) GList *hits)
{ {
g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine)); g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
g_signal_emit (engine, signals[HITS_SUBTRACTED], 0, hits); g_signal_emit (engine, signals[HITS_SUBTRACTED], 0, hits);
} }
void void
_gtk_search_engine_finished (GtkSearchEngine *engine) _gtk_search_engine_finished (GtkSearchEngine *engine)
{ {
g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine)); g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
g_signal_emit (engine, signals[FINISHED], 0); g_signal_emit (engine, signals[FINISHED], 0);
} }
void void
_gtk_search_engine_error (GtkSearchEngine *engine, _gtk_search_engine_error (GtkSearchEngine *engine,
const gchar *error_message) const gchar *error_message)
{ {
g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine)); g_return_if_fail (GTK_IS_SEARCH_ENGINE (engine));
g_signal_emit (engine, signals[ERROR], 0, error_message); g_signal_emit (engine, signals[ERROR], 0, error_message);
} }

View File

@ -34,28 +34,28 @@
#define BATCH_SIZE 500 #define BATCH_SIZE 500
typedef struct typedef struct
{ {
GtkSearchEngineSimple *engine; GtkSearchEngineSimple *engine;
gchar *path; gchar *path;
gchar **words; gchar **words;
GList *found_list; GList *found_list;
gint n_processed_files; gint n_processed_files;
GList *uri_hits; GList *uri_hits;
/* accessed on both threads: */ /* accessed on both threads: */
volatile gboolean cancelled; volatile gboolean cancelled;
} SearchThreadData; } SearchThreadData;
struct _GtkSearchEngineSimplePrivate struct _GtkSearchEngineSimplePrivate
{ {
GtkQuery *query; GtkQuery *query;
SearchThreadData *active_search; SearchThreadData *active_search;
gboolean query_finished; gboolean query_finished;
}; };
@ -67,11 +67,11 @@ gtk_search_engine_simple_dispose (GObject *object)
{ {
GtkSearchEngineSimple *simple; GtkSearchEngineSimple *simple;
GtkSearchEngineSimplePrivate *priv; GtkSearchEngineSimplePrivate *priv;
simple = GTK_SEARCH_ENGINE_SIMPLE (object); simple = GTK_SEARCH_ENGINE_SIMPLE (object);
priv = simple->priv; priv = simple->priv;
if (priv->query) if (priv->query)
{ {
g_object_unref (priv->query); g_object_unref (priv->query);
priv->query = NULL; priv->query = NULL;
@ -82,7 +82,7 @@ gtk_search_engine_simple_dispose (GObject *object)
priv->active_search->cancelled = TRUE; priv->active_search->cancelled = TRUE;
priv->active_search = NULL; priv->active_search = NULL;
} }
G_OBJECT_CLASS (_gtk_search_engine_simple_parent_class)->dispose (object); G_OBJECT_CLASS (_gtk_search_engine_simple_parent_class)->dispose (object);
} }
@ -92,30 +92,30 @@ search_thread_data_new (GtkSearchEngineSimple *engine,
{ {
SearchThreadData *data; SearchThreadData *data;
char *text, *lower, *uri; char *text, *lower, *uri;
data = g_new0 (SearchThreadData, 1); data = g_new0 (SearchThreadData, 1);
data->engine = g_object_ref (engine); data->engine = g_object_ref (engine);
uri = _gtk_query_get_location (query); uri = _gtk_query_get_location (query);
if (uri != NULL) if (uri != NULL)
{ {
data->path = g_filename_from_uri (uri, NULL, NULL); data->path = g_filename_from_uri (uri, NULL, NULL);
g_free (uri); g_free (uri);
} }
if (data->path == NULL) if (data->path == NULL)
data->path = g_strdup (g_get_home_dir ()); data->path = g_strdup (g_get_home_dir ());
text = _gtk_query_get_text (query); text = _gtk_query_get_text (query);
lower = g_ascii_strdown (text, -1); lower = g_ascii_strdown (text, -1);
data->words = g_strsplit (lower, " ", -1); data->words = g_strsplit (lower, " ", -1);
g_free (text); g_free (text);
g_free (lower); g_free (lower);
return data; return data;
} }
#ifdef HAVE_FTW_H #ifdef HAVE_FTW_H
static void static void
search_thread_data_free (SearchThreadData *data) search_thread_data_free (SearchThreadData *data)
{ {
g_object_unref (data->engine); g_object_unref (data->engine);
@ -130,17 +130,17 @@ search_thread_done_idle (gpointer user_data)
SearchThreadData *data; SearchThreadData *data;
data = user_data; data = user_data;
if (!data->cancelled) if (!data->cancelled)
_gtk_search_engine_finished (GTK_SEARCH_ENGINE (data->engine)); _gtk_search_engine_finished (GTK_SEARCH_ENGINE (data->engine));
data->engine->priv->active_search = NULL; data->engine->priv->active_search = NULL;
search_thread_data_free (data); search_thread_data_free (data);
return FALSE; return FALSE;
} }
typedef struct typedef struct
{ {
GList *uris; GList *uris;
SearchThreadData *thread_data; SearchThreadData *thread_data;
@ -153,7 +153,7 @@ search_thread_add_hits_idle (gpointer user_data)
hits = user_data; hits = user_data;
if (!hits->thread_data->cancelled) if (!hits->thread_data->cancelled)
{ {
_gtk_search_engine_hits_added (GTK_SEARCH_ENGINE (hits->thread_data->engine), _gtk_search_engine_hits_added (GTK_SEARCH_ENGINE (hits->thread_data->engine),
hits->uris); hits->uris);
@ -161,7 +161,7 @@ search_thread_add_hits_idle (gpointer user_data)
g_list_free_full (hits->uris, g_free); g_list_free_full (hits->uris, g_free);
g_free (hits); g_free (hits);
return FALSE; return FALSE;
} }
@ -169,17 +169,17 @@ static void
send_batch (SearchThreadData *data) send_batch (SearchThreadData *data)
{ {
SearchHits *hits; SearchHits *hits;
data->n_processed_files = 0; data->n_processed_files = 0;
if (data->uri_hits) if (data->uri_hits)
{ {
guint id; guint id;
hits = g_new (SearchHits, 1); hits = g_new (SearchHits, 1);
hits->uris = data->uri_hits; hits->uris = data->uri_hits;
hits->thread_data = data; hits->thread_data = data;
id = gdk_threads_add_idle (search_thread_add_hits_idle, hits); id = gdk_threads_add_idle (search_thread_add_hits_idle, hits);
g_source_set_name_by_id (id, "[gtk+] search_thread_add_hits_idle"); g_source_set_name_by_id (id, "[gtk+] search_thread_add_hits_idle");
} }
@ -219,17 +219,17 @@ search_visit_func (const char *fpath,
name = fpath; name = fpath;
is_hidden = *name == '.'; is_hidden = *name == '.';
hit = FALSE; hit = FALSE;
if (!is_hidden) if (!is_hidden)
{ {
lower_name = g_ascii_strdown (name, -1); lower_name = g_ascii_strdown (name, -1);
hit = TRUE; hit = TRUE;
for (i = 0; data->words[i] != NULL; i++) for (i = 0; data->words[i] != NULL; i++)
{ {
if (strstr (lower_name, data->words[i]) == NULL) if (strstr (lower_name, data->words[i]) == NULL)
{ {
hit = FALSE; hit = FALSE;
break; break;
@ -238,14 +238,14 @@ search_visit_func (const char *fpath,
g_free (lower_name); g_free (lower_name);
} }
if (hit) if (hit)
{ {
uri = g_filename_to_uri (fpath, NULL, NULL); uri = g_filename_to_uri (fpath, NULL, NULL);
data->uri_hits = g_list_prepend (data->uri_hits, uri); data->uri_hits = g_list_prepend (data->uri_hits, uri);
} }
data->n_processed_files++; data->n_processed_files++;
if (data->n_processed_files > BATCH_SIZE) if (data->n_processed_files > BATCH_SIZE)
send_batch (data); send_batch (data);
@ -260,15 +260,15 @@ search_visit_func (const char *fpath,
} }
#endif /* HAVE_FTW_H */ #endif /* HAVE_FTW_H */
static gpointer static gpointer
search_thread_func (gpointer user_data) search_thread_func (gpointer user_data)
{ {
#ifdef HAVE_FTW_H #ifdef HAVE_FTW_H
guint id; guint id;
SearchThreadData *data; SearchThreadData *data;
data = user_data; data = user_data;
g_private_set (&search_thread_data, data); g_private_set (&search_thread_data, data);
nftw (data->path, search_visit_func, 20, nftw (data->path, search_visit_func, 20,
@ -278,11 +278,11 @@ search_thread_func (gpointer user_data)
FTW_PHYS); FTW_PHYS);
send_batch (data); send_batch (data);
id = gdk_threads_add_idle (search_thread_done_idle, data); id = gdk_threads_add_idle (search_thread_done_idle, data);
g_source_set_name_by_id (id, "[gtk+] search_thread_done_idle"); g_source_set_name_by_id (id, "[gtk+] search_thread_done_idle");
#endif /* HAVE_FTW_H */ #endif /* HAVE_FTW_H */
return NULL; return NULL;
} }
@ -291,19 +291,19 @@ gtk_search_engine_simple_start (GtkSearchEngine *engine)
{ {
GtkSearchEngineSimple *simple; GtkSearchEngineSimple *simple;
SearchThreadData *data; SearchThreadData *data;
simple = GTK_SEARCH_ENGINE_SIMPLE (engine); simple = GTK_SEARCH_ENGINE_SIMPLE (engine);
if (simple->priv->active_search != NULL) if (simple->priv->active_search != NULL)
return; return;
if (simple->priv->query == NULL) if (simple->priv->query == NULL)
return; return;
data = search_thread_data_new (simple, simple->priv->query); data = search_thread_data_new (simple, simple->priv->query);
g_thread_unref (g_thread_new ("file-search", search_thread_func, data)); g_thread_unref (g_thread_new ("file-search", search_thread_func, data));
simple->priv->active_search = data; simple->priv->active_search = data;
} }
@ -311,10 +311,10 @@ static void
gtk_search_engine_simple_stop (GtkSearchEngine *engine) gtk_search_engine_simple_stop (GtkSearchEngine *engine)
{ {
GtkSearchEngineSimple *simple; GtkSearchEngineSimple *simple;
simple = GTK_SEARCH_ENGINE_SIMPLE (engine); simple = GTK_SEARCH_ENGINE_SIMPLE (engine);
if (simple->priv->active_search != NULL) if (simple->priv->active_search != NULL)
{ {
simple->priv->active_search->cancelled = TRUE; simple->priv->active_search->cancelled = TRUE;
simple->priv->active_search = NULL; simple->priv->active_search = NULL;
@ -328,17 +328,17 @@ gtk_search_engine_simple_is_indexed (GtkSearchEngine *engine)
} }
static void static void
gtk_search_engine_simple_set_query (GtkSearchEngine *engine, gtk_search_engine_simple_set_query (GtkSearchEngine *engine,
GtkQuery *query) GtkQuery *query)
{ {
GtkSearchEngineSimple *simple; GtkSearchEngineSimple *simple;
simple = GTK_SEARCH_ENGINE_SIMPLE (engine); simple = GTK_SEARCH_ENGINE_SIMPLE (engine);
if (query) if (query)
g_object_ref (query); g_object_ref (query);
if (simple->priv->query) if (simple->priv->query)
g_object_unref (simple->priv->query); g_object_unref (simple->priv->query);
simple->priv->query = query; simple->priv->query = query;
@ -349,10 +349,10 @@ _gtk_search_engine_simple_class_init (GtkSearchEngineSimpleClass *class)
{ {
GObjectClass *gobject_class; GObjectClass *gobject_class;
GtkSearchEngineClass *engine_class; GtkSearchEngineClass *engine_class;
gobject_class = G_OBJECT_CLASS (class); gobject_class = G_OBJECT_CLASS (class);
gobject_class->dispose = gtk_search_engine_simple_dispose; gobject_class->dispose = gtk_search_engine_simple_dispose;
engine_class = GTK_SEARCH_ENGINE_CLASS (class); engine_class = GTK_SEARCH_ENGINE_CLASS (class);
engine_class->set_query = gtk_search_engine_simple_set_query; engine_class->set_query = gtk_search_engine_simple_set_query;
engine_class->start = gtk_search_engine_simple_start; engine_class->start = gtk_search_engine_simple_start;