]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtksearchenginesimple.c
filechooserbutton: When the combo box changes, set the *file*, not the current folder
[~andy/gtk] / gtk / gtksearchenginesimple.c
index ede5e85214771724f800ae6a53435a41a0e2d5f2..8d0e07f44e6afbca06b0b6683cc22d9193d88cea 100644 (file)
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  *
  * Author: Alexander Larsson <alexl@redhat.com>
  *
  * Based on nautilus-search-engine-simple.c
  */
 
-#include <config.h>
+#include "config.h"
 
-#ifdef HAVE_GNU_FTW
-#define _XOPEN_SOURCE 500
-#define _GNU_SOURCE 
-#endif
+/* these must be defined even when HAVE_GNU_FTW is not defined
+ * because (really) old versions of GNU libc have ftw.h but do
+ * export ftw() and friends only if _XOPEN_SOURCE and _GNU_SOURCE
+ * are defined. see bug #444097.
+ */
+#define _XOPEN_SOURCE 600
+#define _GNU_SOURCE
 
 #ifdef HAVE_FTW_H
 #include <ftw.h>
 #endif
 
-#include "gtksearchenginesimple.h"
+#include <gdk/gdk.h>
 
-#define XDG_PREFIX _gtk_xdg
-#include "xdgmime/xdgmime.h"
+#include "gtksearchenginesimple.h"
+#include "gtkprivate.h"
 
 #include <string.h>
 
-#include <glib/gstrfuncs.h>
-
 #define BATCH_SIZE 500
 
 typedef struct 
@@ -47,7 +47,6 @@ typedef struct
   GtkSearchEngineSimple *engine;
   
   gchar *path;
-  GList *mime_types;
   gchar **words;
   GList *found_list;
   
@@ -72,19 +71,27 @@ struct _GtkSearchEngineSimplePrivate
 G_DEFINE_TYPE (GtkSearchEngineSimple, _gtk_search_engine_simple, GTK_TYPE_SEARCH_ENGINE);
 
 static void
-finalize (GObject *object)
+gtk_search_engine_simple_dispose (GObject *object)
 {
   GtkSearchEngineSimple *simple;
+  GtkSearchEngineSimplePrivate *priv;
   
   simple = GTK_SEARCH_ENGINE_SIMPLE (object);
+  priv = simple->priv;
   
-  if (simple->priv->query) 
+  if (priv->query) 
     {
-      g_object_unref (simple->priv->query);
-      simple->priv->query = NULL;
+      g_object_unref (priv->query);
+      priv->query = NULL;
+    }
+
+  if (priv->active_search)
+    {
+      priv->active_search->cancelled = TRUE;
+      priv->active_search = NULL;
     }
   
-  G_OBJECT_CLASS (_gtk_search_engine_simple_parent_class)->finalize (object);
+  G_OBJECT_CLASS (_gtk_search_engine_simple_parent_class)->dispose (object);
 }
 
 static SearchThreadData *
@@ -96,7 +103,7 @@ search_thread_data_new (GtkSearchEngineSimple *engine,
   
   data = g_new0 (SearchThreadData, 1);
   
-  data->engine = engine;
+  data->engine = g_object_ref (engine);
   uri = _gtk_query_get_location (query);
   if (uri != NULL) 
     {
@@ -112,18 +119,15 @@ search_thread_data_new (GtkSearchEngineSimple *engine,
   g_free (text);
   g_free (lower);
   
-  data->mime_types = _gtk_query_get_mime_types (query);
-  
   return data;
 }
 
 static void 
 search_thread_data_free (SearchThreadData *data)
 {
+  g_object_unref (data->engine);
   g_free (data->path);
   g_strfreev (data->words);
-  g_list_foreach (data->mime_types, (GFunc)g_free, NULL);
-  g_list_free (data->mime_types);
   g_free (data);
 }
 
@@ -134,12 +138,10 @@ search_thread_done_idle (gpointer user_data)
 
   data = user_data;
   
-  if (!data->cancelled) 
-    {
-      _gtk_search_engine_finished (GTK_SEARCH_ENGINE (data->engine));
-      data->engine->priv->active_search = NULL;
-    }
-  
+  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;
@@ -165,8 +167,7 @@ search_thread_add_hits_idle (gpointer user_data)
                                    hits->uris);
     }
 
-  g_list_foreach (hits->uris, (GFunc)g_free, NULL);
-  g_list_free (hits->uris);
+  g_list_free_full (hits->uris, g_free);
   g_free (hits);
        
   return FALSE;
@@ -184,12 +185,14 @@ send_batch (SearchThreadData *data)
       hits = g_new (SearchHits, 1);
       hits->uris = data->uri_hits;
       hits->thread_data = data;
-      g_idle_add (search_thread_add_hits_idle, hits);
+      
+      gdk_threads_add_idle (search_thread_add_hits_idle, hits);
     }
+
   data->uri_hits = NULL;
 }
 
-static GStaticPrivate search_thread_data = G_STATIC_PRIVATE_INIT;
+static GPrivate search_thread_data;
 
 #ifdef HAVE_FTW_H
 static int
@@ -200,14 +203,13 @@ search_visit_func (const char        *fpath,
 {
   SearchThreadData *data;
   gint i;
-  const gchar *name; 
-  gchar *lower_name, *mime_type;
+  const gchar *name;
+  gchar *lower_name;
   gchar *uri;
   gboolean hit;
-  GList *l;
   gboolean is_hidden;
-  
-  data = (SearchThreadData*)g_static_private_get (&search_thread_data);
+
+  data = (SearchThreadData*)g_private_get (&search_thread_data);
 
   if (data->cancelled)
 #ifdef HAVE_GNU_FTW
@@ -242,22 +244,6 @@ search_visit_func (const char        *fpath,
       g_free (lower_name);
     }
 
-  if (hit && data->mime_types != NULL) 
-    {
-      hit = FALSE;
-      mime_type = xdg_mime_get_mime_type_for_file (fpath, (struct stat *)sb);
-      for (l = data->mime_types; l != NULL; l = l->next) 
-       {
-         if (strcmp (mime_type, l->data) == 0) 
-           {
-             hit = TRUE;
-             break;
-           }
-       }
-
-      g_free (mime_type);
-    }
-
   if (hit) 
     {
       uri = g_filename_to_uri (fpath, NULL, NULL);
@@ -288,7 +274,7 @@ search_thread_func (gpointer user_data)
   
   data = user_data;
   
-  g_static_private_set (&search_thread_data, data, NULL);
+  g_private_set (&search_thread_data, data);
 
   nftw (data->path, search_visit_func, 20,
 #ifdef HAVE_GNU_FTW
@@ -298,7 +284,7 @@ search_thread_func (gpointer user_data)
 
   send_batch (data);
   
-  g_idle_add (search_thread_done_idle, data);
+  gdk_threads_add_idle (search_thread_done_idle, data);
 #endif /* HAVE_FTW_H */
   
   return NULL;
@@ -320,7 +306,7 @@ gtk_search_engine_simple_start (GtkSearchEngine *engine)
        
   data = search_thread_data_new (simple, simple->priv->query);
   
-  g_thread_create (search_thread_func, data, FALSE, NULL);
+  g_thread_unref (g_thread_new ("file-search", search_thread_func, data));
   
   simple->priv->active_search = data;
 }
@@ -369,7 +355,7 @@ _gtk_search_engine_simple_class_init (GtkSearchEngineSimpleClass *class)
   GtkSearchEngineClass *engine_class;
   
   gobject_class = G_OBJECT_CLASS (class);
-  gobject_class->finalize = finalize;
+  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;