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

View File

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