updated on Thu Jan 12 04:00:44 UTC 2012
[aur-mirror.git] / thunar-extended / preview.patch
blob5346018978ce44d668d99b5930ba87a05381cff0
1 diff -ru Thunar-1.3.0.orig/configure.in Thunar-1.3.0/configure.in
2 --- Thunar-1.3.0.orig/configure.in 2011-02-14 08:45:05.000000000 -0500
3 +++ Thunar-1.3.0/configure.in 2011-08-28 12:36:31.000000000 -0400
4 @@ -191,6 +191,14 @@
5 [0.4], [startup-notification],
6 [startup notification library])
8 +dnl *************************************************
9 +dnl *** Optional support for gstreamer ***
10 +dnl *************************************************
11 +XDT_CHECK_OPTIONAL_PACKAGE([GSTREAMER],
12 + [gstreamer-0.10],
13 + [0.10], [gstreamer],
14 + [nautilus-like mouseover preview])
16 dnl ***************************************************************
17 dnl *** Optional support for GUDev (required for thunar-volman) ***
18 dnl ***************************************************************
19 @@ -338,6 +346,11 @@
20 else
21 echo "* Startup Notification: no"
23 +if test x"$GSTREAMER_FOUND" = x"yes"; then
24 +echo "* GStreamer: yes"
25 +else
26 +echo "* GStreamer: no"
27 +fi
28 if test x"$GUDEV_FOUND" = x"yes"; then
29 echo "* GUDev (required for thunar-volman): yes"
30 else
31 diff -ru Thunar-1.3.0.orig/thunar/Makefile.am Thunar-1.3.0/thunar/Makefile.am
32 --- Thunar-1.3.0.orig/thunar/Makefile.am 2011-02-14 08:09:15.000000000 -0500
33 +++ Thunar-1.3.0/thunar/Makefile.am 2011-08-28 12:36:31.000000000 -0400
34 @@ -281,6 +281,14 @@
35 $(DBUS_LIBS)
36 endif
38 +if HAVE_GSTREAMER
39 +Thunar_CFLAGS += \
40 + $(GSTREAMER_CFLAGS)
42 +Thunar_LDADD += \
43 + $(GSTREAMER_LIBS)
44 +endif
46 if HAVE_GIO_UNIX
47 Thunar_CFLAGS += \
48 $(GIO_UNIX_CFLAGS)
49 diff -ru Thunar-1.3.0.orig/thunar/thunar-abstract-icon-view.c Thunar-1.3.0/thunar/thunar-abstract-icon-view.c
50 --- Thunar-1.3.0.orig/thunar/thunar-abstract-icon-view.c 2011-02-04 10:27:17.000000000 -0500
51 +++ Thunar-1.3.0/thunar/thunar-abstract-icon-view.c 2011-08-28 12:36:31.000000000 -0400
52 @@ -468,9 +468,17 @@
53 GtkTreeIter iter;
54 ThunarFile *file;
55 GtkAction *action;
57 + ThunarStandardView *standard_view = THUNAR_STANDARD_VIEW (abstract_icon_view);
58 + GtkWidget *real_view = GTK_BIN (standard_view)->child;
60 if (event->type == GDK_BUTTON_PRESS && event->button == 3)
62 +#ifdef HAVE_GSTREAMER
63 + /* we don't want audio-preview to interfere when clicks are going on */
64 + g_signal_handlers_disconnect_by_func (real_view, thunar_standard_view_try_preview, standard_view);
65 +#endif
67 /* open the context menu on right clicks */
68 if (exo_icon_view_get_item_at_pos (view, event->x, event->y, &path, NULL))
70 @@ -496,12 +504,22 @@
72 /* open the context menu */
73 thunar_standard_view_context_menu (THUNAR_STANDARD_VIEW (abstract_icon_view), event->button, event->time);
75 +#ifdef HAVE_GSTREAMER
76 + /* turn audio-preview back on */
77 + g_signal_connect (G_OBJECT (real_view), "motion-notify-event", G_CALLBACK (thunar_standard_view_try_preview), standard_view);
78 +#endif
81 return TRUE;
83 else if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_2BUTTON_PRESS) && event->button == 2)
85 +#ifdef HAVE_GSTREAMER
86 + /* again, this type of click should override audio-preview */
87 + g_signal_handlers_disconnect_by_func (real_view, thunar_standard_view_try_preview, standard_view);
88 +#endif
90 /* unselect all currently selected items */
91 exo_icon_view_unselect_all (view);
93 @@ -536,6 +554,11 @@
95 /* cleanup */
96 gtk_tree_path_free (path);
98 +#ifdef HAVE_GSTREAMER
99 + /* we just clicked on a file so let the audio-preview work again */
100 + g_signal_connect (G_OBJECT (real_view), "motion-notify-event", G_CALLBACK (thunar_standard_view_try_preview), standard_view);
101 +#endif
103 else if (event->type == GDK_BUTTON_PRESS)
105 @@ -567,6 +590,9 @@
106 ThunarAbstractIconView *abstract_icon_view)
108 GtkAction *action;
110 + ThunarStandardView *standard_view = THUNAR_STANDARD_VIEW (abstract_icon_view);
111 + GtkWidget *real_view = GTK_BIN (standard_view)->child;
113 _thunar_return_val_if_fail (EXO_IS_ICON_VIEW (view), FALSE);
114 _thunar_return_val_if_fail (THUNAR_IS_ABSTRACT_ICON_VIEW (abstract_icon_view), FALSE);
115 @@ -594,6 +620,11 @@
116 /* redraw the abstract_icon view */
117 gtk_widget_queue_draw (GTK_WIDGET (view));
119 +#ifdef HAVE_GSTREAMER
120 + /* re-allow the audio-preview */
121 + g_signal_connect (G_OBJECT (real_view), "motion-notify-event", G_CALLBACK (thunar_standard_view_try_preview), standard_view);
122 +#endif
124 return FALSE;
127 diff -ru Thunar-1.3.0.orig/thunar/thunar-standard-view.c Thunar-1.3.0/thunar/thunar-standard-view.c
128 --- Thunar-1.3.0.orig/thunar/thunar-standard-view.c 2011-02-14 08:09:15.000000000 -0500
129 +++ Thunar-1.3.0/thunar/thunar-standard-view.c 2011-08-28 14:03:03.000000000 -0400
130 @@ -31,6 +31,7 @@
131 #endif
133 #include <gdk/gdkkeysyms.h>
134 +#include <gdk/gdkcursor.h>
136 #include <thunar/thunar-application.h>
137 #include <thunar/thunar-create-dialog.h>
138 @@ -57,7 +58,7 @@
139 #endif
143 +#define MUSIC_NOTE { 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x80, 0x1f, 0x80, 0x39, 0x80, 0x21, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xfc, 0x01, 0xfe, 0x01, 0xfe, 0x01, 0xfe, 0x00, 0x7c, 0x00, 0x00, 0x00 };
144 #define THUNAR_STANDARD_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), THUNAR_TYPE_STANDARD_VIEW, ThunarStandardViewPrivate))
147 @@ -262,6 +263,7 @@
148 static void thunar_standard_view_drag_scroll_timer_destroy (gpointer user_data);
149 static gboolean thunar_standard_view_drag_timer (gpointer user_data);
150 static void thunar_standard_view_drag_timer_destroy (gpointer user_data);
151 +static gboolean thunar_standard_view_preview_timer (GList *user_data);
152 static void thunar_standard_view_cancel_thumbnailing (ThunarStandardView *standard_view);
153 static void thunar_standard_view_schedule_thumbnail_timeout (ThunarStandardView *standard_view);
154 static void thunar_standard_view_schedule_thumbnail_idle (ThunarStandardView *standard_view);
155 @@ -671,6 +673,15 @@
156 /* stay informed about changes to the sort column/order */
157 g_signal_connect (G_OBJECT (standard_view->model), "sort-column-changed", G_CALLBACK (thunar_standard_view_sort_column_changed), standard_view);
159 +#ifdef HAVE_GSTREAMER
160 + /* stay informed about what audio-preview might need to happen */
161 + g_signal_connect (G_OBJECT (view), "motion-notify-event", G_CALLBACK (thunar_standard_view_try_preview), standard_view);
163 + /* initialize the player */
164 + gst_init (NULL, NULL);
165 + standard_view->play = gst_element_factory_make ("playbin", "play");
166 +#endif
168 /* setup support to navigate using a horizontal mouse wheel and the back and forward buttons */
169 g_signal_connect (G_OBJECT (view), "scroll-event", G_CALLBACK (thunar_standard_view_scroll_event), object);
170 g_signal_connect (G_OBJECT (view), "button-press-event", G_CALLBACK (thunar_standard_view_button_press_event), object);
171 @@ -796,7 +807,13 @@
173 /* free the statusbar text (if any) */
174 g_free (standard_view->statusbar_text);
177 +#ifdef HAVE_GSTREAMER
178 + /* stop audio-preview and release the gstreamer reference */
179 + gst_element_set_state (standard_view->play, GST_STATE_NULL);
180 + gst_object_unref (GST_OBJECT (standard_view->play));
181 +#endif
183 (*G_OBJECT_CLASS (thunar_standard_view_parent_class)->finalize) (object);
186 @@ -2472,6 +2489,214 @@
190 +#ifdef HAVE_GSTREAMER
192 +/**
193 + * thunar_standard_view_try_preview:
194 + * @real_view : a GtkIconView or GtkTreeView.
195 + * @event : another motion_notify_event for the times when no mouse button is held down.
196 + * @standard_view : a #ThunarStandardView instance.
198 + * An alternative motion_notify_event signal handler that checks whether any audio files are under the cursor
199 + * and plays them in a short amount of time if the cursor stays there.
200 + **/
201 +gboolean
202 +thunar_standard_view_try_preview (GtkWidget *real_view,
203 + GdkEventMotion *event,
204 + ThunarStandardView *standard_view)
206 + ThunarPreferences *preferences;
207 + gchar *view_type;
208 + gboolean item_found;
209 + gboolean wrong_mime = TRUE;
211 + GtkTreePath *path = NULL;
212 + GtkTreeIter iter;
214 + ThunarFile *file;
215 + gchar *mime_type;
216 + GList *preview_timer_list = NULL;
218 + preferences = thunar_preferences_get();
219 + g_object_get(G_OBJECT(preferences), "last-view", &view_type, NULL);
220 + g_object_unref(preferences);
222 + if (strncmp(view_type, "ThunarDetailsView", 17) == 0)
224 + item_found = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW(real_view), event->x, event->y, &path, NULL, NULL, NULL);
226 + else
228 + item_found = exo_icon_view_get_item_at_pos (EXO_ICON_VIEW (real_view), event->x, event->y, &path, NULL);
231 + g_free(view_type);
233 + if (G_LIKELY (item_found))
235 + gtk_tree_model_get_iter (GTK_TREE_MODEL (standard_view->model), &iter, path);
236 + file = thunar_list_model_get_file (standard_view->model, &iter);
238 + if (G_LIKELY (file != NULL))
240 + mime_type = g_file_info_get_content_type (file->info);
241 + if (G_LIKELY (mime_type != NULL))
243 + wrong_mime = strncmp(mime_type, "audio/", 6);
247 + if (G_UNLIKELY (!wrong_mime))
248 + {
249 + if (G_LIKELY (path != NULL))
251 + preview_timer_list = g_list_append(preview_timer_list, standard_view);
252 + preview_timer_list = g_list_append(preview_timer_list, g_file_get_uri(file->gfile));
254 + gtk_tree_path_free(path);
255 + g_timeout_add (50, (GtkFunction)thunar_standard_view_preview_timer, preview_timer_list);
256 + g_signal_handlers_disconnect_by_func (real_view, thunar_standard_view_try_preview, standard_view);
258 + return FALSE;
261 + else
263 + g_object_unref (G_OBJECT (file));
267 + if (standard_view->playing)
269 + gdk_window_set_cursor (GTK_WIDGET (standard_view)->window, NULL);
270 + gst_element_set_state (standard_view->play, GST_STATE_NULL);
271 + standard_view->playing = FALSE;
273 + return FALSE;
278 +static gboolean
279 +thunar_standard_view_preview_timer (GList *user_data)
281 + ThunarStandardView *standard_view = user_data->data;
282 + gchar *absolute_path = user_data->next->data;
284 + GtkWidget *real_view = GTK_BIN (standard_view)->child;
285 + ThunarPreferences *preferences;
286 + gchar *view_type;
287 + gboolean item_found;
289 + GdkCursor *cursor;
290 + GdkPixmap *bitmap;
291 + GdkColor fg = { 0, 0, 0, 0 };
292 + GdkColor bg = { 0, 65535, 65535, 65535 };
293 + static unsigned char music_note_bits[] = MUSIC_NOTE;
295 + GtkTreePath *new_path = NULL;
296 + GtkTreeIter iter;
297 + ThunarFile *file;
298 + gint x, y;
299 + gint wx, wy;
300 + gint bx, by;
302 + static int call_number = 0;
304 + g_signal_handlers_disconnect_by_func (real_view, thunar_standard_view_try_preview, standard_view);
305 + gtk_widget_get_pointer (GTK_WIDGET (standard_view), &wx, &wy);
307 + preferences = thunar_preferences_get();
308 + g_object_get(G_OBJECT(preferences), "last-view", &view_type, NULL);
309 + g_object_unref(preferences);
311 + if (strncmp(view_type, "ThunarDetailsView", 17) == 0)
313 + gtk_tree_view_convert_widget_to_bin_window_coords (GTK_TREE_VIEW(real_view), wx, wy, &bx, &by);
314 + item_found = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW(real_view), bx, by, &new_path, NULL, NULL, NULL);
316 + else
318 + exo_icon_view_widget_to_icon_coords(EXO_ICON_VIEW (real_view), wx, wy, &x, &y);
319 + item_found = exo_icon_view_get_item_at_pos (EXO_ICON_VIEW (real_view), x, y, &new_path, NULL);
322 + g_free(view_type);
324 + if (standard_view->playing)
326 + if (!item_found)
328 + gdk_window_set_cursor (GTK_WIDGET (standard_view)->window, NULL);
329 + gst_element_set_state (standard_view->play, GST_STATE_NULL);
330 + standard_view->playing = FALSE;
332 + else
334 + gtk_tree_model_get_iter (GTK_TREE_MODEL (standard_view->model), &iter, new_path);
335 + file = thunar_list_model_get_file (standard_view->model, &iter);
337 + if (strcmp(g_file_get_uri(file->gfile), absolute_path))
339 + gdk_window_set_cursor (GTK_WIDGET (standard_view)->window, NULL);
340 + gst_element_set_state (standard_view->play, GST_STATE_NULL);
341 + standard_view->playing = FALSE;
345 + else
347 + if (item_found)
349 + gtk_tree_model_get_iter (GTK_TREE_MODEL (standard_view->model), &iter, new_path);
350 + file = thunar_list_model_get_file (standard_view->model, &iter);
352 + if (!strcmp(g_file_get_uri(file->gfile), absolute_path))
354 + call_number++;
356 + if (call_number == 1)
358 + bitmap = gdk_bitmap_create_from_data (NULL, music_note_bits, 16, 16);
359 + cursor = gdk_cursor_new_from_pixmap (bitmap, bitmap, &fg, &bg, 8, 8);
360 + gdk_window_set_cursor (GTK_WIDGET (standard_view)->window, cursor);
362 + g_object_set (G_OBJECT (standard_view->play), "uri", g_file_get_uri(file->gfile), NULL);
365 + if (call_number > 40)
367 + gst_element_set_state (standard_view->play, GST_STATE_PLAYING);
368 + standard_view->playing = TRUE;
370 + call_number = 0;
371 + gtk_tree_path_free (new_path);
372 + g_signal_connect (G_OBJECT (real_view), "motion-notify-event", G_CALLBACK (thunar_standard_view_try_preview), standard_view);
373 + return FALSE;
375 + return TRUE;
377 + else
379 + gdk_window_set_cursor (GTK_WIDGET (standard_view)->window, NULL);
382 + else
384 + gdk_window_set_cursor (GTK_WIDGET (standard_view)->window, NULL);
388 + call_number = 0;
389 + gtk_tree_path_free (new_path);
390 + g_signal_connect (G_OBJECT (real_view), "motion-notify-event", G_CALLBACK (thunar_standard_view_try_preview), standard_view);
391 + return FALSE;
394 +#endif
398 static gboolean
399 thunar_standard_view_scroll_event (GtkWidget *view,
400 GdkEventScroll *event,
401 @@ -3286,12 +3511,20 @@
402 static void
403 thunar_standard_view_drag_timer_destroy (gpointer user_data)
405 + ThunarStandardView *standard_view = THUNAR_STANDARD_VIEW (user_data);
406 + GtkWidget *view = GTK_BIN (standard_view)->child;
408 /* unregister the motion notify and button release event handlers (thread-safe) */
409 - g_signal_handlers_disconnect_by_func (GTK_BIN (user_data)->child, thunar_standard_view_button_release_event, user_data);
410 - g_signal_handlers_disconnect_by_func (GTK_BIN (user_data)->child, thunar_standard_view_motion_notify_event, user_data);
411 + g_signal_handlers_disconnect_by_func (view, thunar_standard_view_button_release_event, user_data);
412 + g_signal_handlers_disconnect_by_func (view, thunar_standard_view_motion_notify_event, user_data);
414 /* reset the drag timer source id */
415 - THUNAR_STANDARD_VIEW (user_data)->priv->drag_timer_id = -1;
416 + standard_view->priv->drag_timer_id = -1;
418 +#ifdef HAVE_GSTREAMER
419 + /* enables audio-preview again */
420 + g_signal_connect (G_OBJECT (view), "motion-notify-event", G_CALLBACK (thunar_standard_view_try_preview), standard_view);
421 +#endif
425 diff -ru Thunar-1.3.0.orig/thunar/thunar-standard-view.h Thunar-1.3.0/thunar/thunar-standard-view.h
426 --- Thunar-1.3.0.orig/thunar/thunar-standard-view.h 2011-02-06 18:14:06.000000000 -0500
427 +++ Thunar-1.3.0/thunar/thunar-standard-view.h 2011-08-28 12:36:31.000000000 -0400
428 @@ -26,6 +26,10 @@
429 #include <thunar/thunar-preferences.h>
430 #include <thunar/thunar-view.h>
432 +#ifdef HAVE_GSTREAMER
433 +#include <gst/gst.h>
434 +#endif
436 G_BEGIN_DECLS;
438 typedef struct _ThunarStandardViewPrivate ThunarStandardViewPrivate;
439 @@ -138,6 +142,11 @@
440 ExoBinding *loading_binding;
441 gboolean loading;
443 +#ifdef HAVE_GSTREAMER
444 + gboolean playing;
445 + GstElement *play;
446 +#endif
448 ThunarStandardViewPrivate *priv;
451 @@ -152,6 +161,10 @@
453 void thunar_standard_view_selection_changed (ThunarStandardView *standard_view);
455 +gboolean thunar_standard_view_try_preview (GtkWidget *real_view,
456 + GdkEventMotion *event,
457 + ThunarStandardView *standard_view);
459 G_END_DECLS;
461 #endif /* !__THUNAR_STANDARD_VIEW_H__ */