1604
|
1 /*
|
|
2 * Geeqie
|
|
3 * (C) 2004 John Ellis
|
|
4 * Copyright (C) 2008 - 2009 The Geeqie Team
|
|
5 *
|
|
6 * Author: Colin Clark
|
|
7 *
|
|
8 * This software is released under the GNU General Public License (GNU GPL).
|
|
9 * Please read the included file COPYING for more information.
|
|
10 * This software comes with no warranty of any kind, use at your own risk!
|
|
11 */
|
|
12
|
|
13 #include "main.h"
|
|
14 #ifdef HAVE_LIBCHAMPLAIN
|
|
15 #ifdef HAVE_LIBCHAMPLAIN_GTK
|
|
16
|
|
17 #include "bar_gps.h"
|
|
18
|
|
19 #include "bar.h"
|
|
20 #include "filedata.h"
|
|
21 #include "layout.h"
|
|
22 #include "metadata.h"
|
|
23 #include "menu.h"
|
|
24 #include "rcfile.h"
|
|
25 #include "thumb.h"
|
|
26 #include "ui_menu.h"
|
|
27
|
|
28 #include <clutter-gtk/gtk-clutter-embed.h>
|
|
29 #include <champlain/champlain.h>
|
|
30 #include <champlain-gtk/champlain-gtk.h>
|
|
31
|
|
32 #define MARKER_COLOUR 0x00, 0x00, 0xff, 0xff
|
|
33 #define TEXT_COLOUR 0x00, 0x00, 0x00, 0xff
|
|
34 #define THUMB_COLOUR 0xff, 0xff, 0xff, 0xff
|
|
35 #define THUMB_SIZE 100
|
|
36
|
|
37 /*
|
|
38 *-------------------------------------------------------------------
|
|
39 * GPS Map utils
|
|
40 *-------------------------------------------------------------------
|
|
41 */
|
|
42
|
|
43 typedef struct _PaneGPSData PaneGPSData;
|
|
44 struct _PaneGPSData
|
|
45 {
|
|
46 PaneData pane;
|
|
47 GtkWidget *widget;
|
|
48 FileData *fd;
|
|
49 gchar *map_source;
|
|
50 gint height;
|
|
51 ClutterActor *gps_view;
|
|
52 ChamplainLayer *icon_layer;
|
|
53 GList *selection_list;
|
|
54 GPtrArray *marker_list;
|
|
55 guint create_markers_id;
|
|
56 GtkWidget *progress;
|
|
57 GtkWidget *slider;
|
|
58 GtkWidget *state;
|
|
59 gint selection_count;
|
|
60 gboolean centre_map_checked;
|
|
61 gboolean enable_markers_checked;
|
|
62 };
|
|
63
|
|
64 static void bar_pane_gps_thumb_done_cb(ThumbLoader *tl, gpointer data)
|
|
65 {
|
|
66 FileData *fd;
|
|
67 ClutterActor *marker;
|
|
68 ClutterActor *actor;
|
|
69
|
|
70 marker = CLUTTER_ACTOR(data);
|
|
71 fd = g_object_get_data(G_OBJECT(marker), "file_fd");
|
|
72 if (fd->thumb_pixbuf != NULL)
|
|
73 {
|
|
74 actor = clutter_texture_new();
|
|
75 gtk_clutter_texture_set_from_pixbuf(CLUTTER_TEXTURE(actor), fd->thumb_pixbuf);
|
|
76 champlain_marker_set_image(CHAMPLAIN_MARKER(marker), actor);
|
|
77 }
|
|
78 thumb_loader_free(tl);
|
|
79 }
|
|
80
|
|
81 static void bar_pane_gps_thumb_error_cb(ThumbLoader *tl, gpointer data)
|
|
82 {
|
|
83 thumb_loader_free(tl);
|
|
84 }
|
|
85
|
|
86 static gboolean bar_pane_gps_marker_keypress_cb(GtkWidget *widget, ClutterButtonEvent *bevent, gpointer data)
|
|
87 {
|
|
88 //PaneGPSData *pgd = data;
|
|
89 FileData *fd;
|
|
90 ClutterActor *marker;
|
|
91 ClutterColor marker_colour = { MARKER_COLOUR };
|
|
92 ClutterColor text_colour = { TEXT_COLOUR };
|
|
93 ClutterColor thumb_colour = { THUMB_COLOUR };
|
|
94 gchar *current_text;
|
|
95 ClutterActor *actor;
|
|
96 ClutterActor *current_image;
|
|
97 GString *text;
|
|
98 gint height, width, rotate;
|
|
99 gchar *altitude = NULL;
|
|
100 ThumbLoader *tl;
|
|
101
|
|
102 if (bevent->button == MOUSE_BUTTON_LEFT)
|
|
103 {
|
|
104 marker = CLUTTER_ACTOR(widget);
|
|
105 fd = g_object_get_data(G_OBJECT(marker), "file_fd");
|
|
106
|
|
107 /* If the marker is showing a thumbnail, delete it
|
|
108 */
|
|
109 current_image = champlain_marker_get_image(CHAMPLAIN_MARKER(marker));
|
|
110 if (current_image != NULL)
|
|
111 {
|
|
112 clutter_actor_destroy(CLUTTER_ACTOR(current_image));
|
|
113 champlain_marker_set_image(CHAMPLAIN_MARKER(marker), NULL);
|
|
114 }
|
|
115
|
|
116 current_text = g_strdup(champlain_marker_get_text(CHAMPLAIN_MARKER(marker)));
|
|
117
|
|
118 /* If the marker is showing only the text character, replace it with a
|
|
119 * thumbnail and date and altitude
|
|
120 */
|
|
121 if (g_strcmp0(current_text, "i") == 0)
|
|
122 {
|
|
123 /* If a thumbail has already been generated, use that. If not try the pixbuf of the full image.
|
|
124 * If not, call the thumb_loader to generate a thumbnail and update the marker later in the
|
|
125 * thumb_loader callback
|
|
126 */
|
|
127 if (fd->thumb_pixbuf != NULL)
|
|
128 {
|
|
129 actor = clutter_texture_new();
|
|
130 gtk_clutter_texture_set_from_pixbuf(CLUTTER_TEXTURE(actor), fd->thumb_pixbuf);
|
|
131 champlain_marker_set_image(CHAMPLAIN_MARKER(marker), actor);
|
|
132 }
|
|
133 else if (fd->pixbuf != NULL)
|
|
134 {
|
|
135 actor = clutter_texture_new();
|
|
136 width = gdk_pixbuf_get_width (fd->pixbuf);
|
|
137 height = gdk_pixbuf_get_height (fd->pixbuf);
|
|
138 switch (fd->exif_orientation)
|
|
139 {
|
|
140 case 8:
|
|
141 rotate = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
|
|
142 break;
|
|
143 case 3:
|
|
144 rotate = GDK_PIXBUF_ROTATE_UPSIDEDOWN;
|
|
145 break;
|
|
146 case 6:
|
|
147 rotate = GDK_PIXBUF_ROTATE_CLOCKWISE;
|
|
148 break;
|
|
149 default:
|
|
150 rotate = GDK_PIXBUF_ROTATE_NONE;
|
|
151 }
|
|
152
|
|
153 gtk_clutter_texture_set_from_pixbuf(CLUTTER_TEXTURE(actor),
|
|
154 gdk_pixbuf_rotate_simple(gdk_pixbuf_scale_simple(fd->pixbuf, THUMB_SIZE, height * THUMB_SIZE / width,
|
|
155 GDK_INTERP_NEAREST), rotate));
|
|
156 champlain_marker_set_image(CHAMPLAIN_MARKER(marker), actor);
|
|
157 }
|
|
158 else
|
|
159 {
|
|
160 tl = thumb_loader_new(THUMB_SIZE, THUMB_SIZE);
|
|
161 thumb_loader_set_callbacks(tl,
|
|
162 bar_pane_gps_thumb_done_cb,
|
|
163 bar_pane_gps_thumb_error_cb,
|
|
164 NULL,
|
|
165 marker);
|
|
166 thumb_loader_start(tl, fd);
|
|
167 }
|
|
168
|
|
169 text = g_string_new(fd->name);
|
|
170 g_string_append(text, "\n");
|
|
171 g_string_append(text, text_from_time(fd->date));
|
|
172 g_string_append(text, "\n");
|
|
173 altitude = metadata_read_string(fd, "formatted.GPSAltitude", METADATA_FORMATTED);
|
|
174 if (altitude != NULL)
|
|
175 {
|
|
176 g_string_append(text, altitude);
|
|
177 }
|
|
178
|
|
179 champlain_marker_set_text(CHAMPLAIN_MARKER(marker), text->str);
|
|
180 champlain_marker_set_color(CHAMPLAIN_MARKER(marker), &thumb_colour);
|
|
181 champlain_marker_set_text_color(CHAMPLAIN_MARKER(marker), &text_colour);
|
|
182 champlain_marker_set_font_name(CHAMPLAIN_MARKER(marker), "sans 8");
|
|
183
|
|
184 g_free(altitude);
|
|
185 g_string_free(text, TRUE);
|
|
186 }
|
|
187 /* otherwise, revert to the hidden text marker
|
|
188 */
|
|
189 else
|
|
190 {
|
|
191 champlain_marker_set_text(CHAMPLAIN_MARKER(marker), "i");
|
|
192 champlain_marker_set_color(CHAMPLAIN_MARKER(marker), &marker_colour);
|
|
193 champlain_marker_set_text_color(CHAMPLAIN_MARKER(marker), &marker_colour);
|
|
194 champlain_marker_set_font_name(CHAMPLAIN_MARKER(marker), "courier 5");
|
|
195 }
|
|
196
|
|
197 g_free(current_text);
|
|
198
|
|
199 return TRUE;
|
|
200 }
|
|
201 return TRUE;
|
|
202 }
|
|
203
|
|
204 static gboolean bar_pane_gps_create_markers_cb(gpointer data)
|
|
205 {
|
|
206 PaneGPSData *pgd = data;
|
|
207 gdouble latitude;
|
|
208 gdouble longitude;
|
|
209 GList *work;
|
|
210 ClutterActor *marker;
|
|
211 FileData *fd;
|
|
212 ClutterColor marker_colour = { MARKER_COLOUR };
|
|
213 GString *message;
|
|
214
|
|
215 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pgd->progress),
|
|
216 (gdouble)(pgd->selection_count - g_list_length(pgd->selection_list)) /
|
|
217 (gdouble)pgd->selection_count);
|
|
218
|
|
219 message = g_string_new("");
|
|
220 g_string_printf(message, "%i/%i", (pgd->selection_count - g_list_length(pgd->selection_list)),
|
|
221 pgd->selection_count);
|
|
222 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pgd->progress), message->str);
|
|
223 g_string_free(message, TRUE);
|
|
224
|
|
225 work = pgd->selection_list;
|
|
226 while (work)
|
|
227 {
|
|
228 fd = work->data;
|
|
229 pgd->selection_list = g_list_remove(pgd->selection_list, work->data);
|
|
230 if (fd != NULL)
|
|
231 {
|
|
232 latitude = metadata_read_GPS_coord(fd, "Xmp.exif.GPSLatitude", 1000);
|
|
233 longitude = metadata_read_GPS_coord(fd, "Xmp.exif.GPSLongitude", 1000);
|
|
234
|
|
235 if ((latitude != 1000) && (longitude != 1000))
|
|
236 {
|
|
237 marker = champlain_marker_new_with_text("i","courier 5", &marker_colour, &marker_colour);
|
|
238
|
|
239 champlain_base_marker_set_position(CHAMPLAIN_BASE_MARKER(marker), latitude, longitude);
|
|
240 clutter_container_add(CLUTTER_CONTAINER(pgd->icon_layer), marker, NULL);
|
|
241 clutter_actor_set_reactive(marker, TRUE);
|
|
242
|
|
243 g_signal_connect(G_OBJECT(marker), "button_press_event",
|
|
244 G_CALLBACK(bar_pane_gps_marker_keypress_cb), pgd);
|
|
245
|
|
246 g_object_set_data(G_OBJECT(marker), "file_fd", fd);
|
|
247
|
|
248 g_ptr_array_add(pgd->marker_list, marker);
|
|
249 if (pgd->centre_map_checked)
|
|
250 {
|
|
251 g_ptr_array_add(pgd->marker_list, NULL);
|
|
252 champlain_view_ensure_markers_visible(CHAMPLAIN_VIEW(pgd->gps_view),
|
|
253 (void *)pgd->marker_list->pdata, FALSE);
|
|
254 g_ptr_array_remove(pgd->marker_list, NULL);
|
|
255 }
|
|
256 }
|
|
257 }
|
|
258 return TRUE;
|
|
259 }
|
|
260
|
|
261 if (pgd->marker_list->len >= 1)
|
|
262 {
|
|
263 g_ptr_array_add(pgd->marker_list, NULL);
|
|
264
|
|
265 if (pgd->centre_map_checked)
|
|
266 {
|
|
267 champlain_view_ensure_markers_visible(CHAMPLAIN_VIEW(pgd->gps_view), (void *)pgd->marker_list->pdata, FALSE);
|
|
268 }
|
|
269 }
|
|
270
|
|
271 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pgd->progress), 0);
|
|
272 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pgd->progress), NULL);
|
|
273 g_list_free(pgd->selection_list);
|
|
274 g_ptr_array_free(pgd->marker_list, TRUE);
|
|
275 pgd->create_markers_id = 0;
|
|
276
|
|
277 return FALSE;
|
|
278 }
|
|
279
|
|
280 static void bar_pane_gps_update(PaneGPSData *pgd)
|
|
281 {
|
|
282 GList *list;
|
|
283 GList *work;
|
|
284
|
|
285 /* The widget does not have a parent during bar_pane_gps_new, so calling gtk_widget_show_all there gives a
|
|
286 * "Gtk-CRITICAL **: gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed"
|
|
287 * error. gtk_widget_show_all can be given after it has been added to the bar.
|
|
288 */
|
|
289 if (gtk_widget_get_parent(pgd->widget) != NULL)
|
|
290 gtk_widget_show_all(pgd->widget);
|
|
291
|
|
292 /* If a create-marker background process is running, kill it
|
|
293 * and start again
|
|
294 */
|
|
295 if (pgd->create_markers_id != 0)
|
|
296 {
|
|
297 if (g_idle_remove_by_data(pgd))
|
|
298 {
|
|
299 pgd->create_markers_id = 0;
|
|
300 }
|
|
301 else
|
|
302 {
|
|
303 return;
|
|
304 }
|
|
305 }
|
|
306
|
|
307 /* Delete any markers currently displayed
|
|
308 */
|
|
309 work = clutter_container_get_children(CLUTTER_CONTAINER(pgd->icon_layer));
|
|
310 while (work)
|
|
311 {
|
|
312 clutter_container_remove(CLUTTER_CONTAINER(pgd->icon_layer), work->data, NULL);
|
|
313 work = work->next;
|
|
314 }
|
|
315 g_list_free(work);
|
|
316
|
|
317 if (!pgd->enable_markers_checked)
|
|
318 {
|
|
319 return;
|
|
320 }
|
|
321
|
|
322 /* For each selected photo that has GPS data, create a marker containing
|
|
323 * a single, small text character the same colour as the marker background.
|
|
324 * Use a background process in case the user selects a large number of files.
|
|
325 */
|
|
326 list = layout_selection_list(pgd->pane.lw);
|
|
327
|
|
328 if (list != NULL)
|
|
329 {
|
|
330 pgd->selection_list = g_list_copy(list);
|
|
331 pgd->marker_list = g_ptr_array_new();
|
|
332 pgd->selection_count = g_list_length(pgd->selection_list);
|
|
333 pgd->create_markers_id = g_idle_add(bar_pane_gps_create_markers_cb, pgd);
|
|
334 }
|
|
335
|
|
336 g_list_free(list);
|
|
337 g_list_free(work);
|
|
338 }
|
|
339
|
|
340 void bar_pane_gps_set_map_source(PaneGPSData *pgd, const gchar *map_id)
|
|
341 {
|
|
342 ChamplainMapSource *map_source;
|
|
343 ChamplainMapSourceFactory *map_factory;
|
|
344
|
|
345 map_factory = champlain_map_source_factory_get_default();
|
|
346 map_source = champlain_map_source_factory_create(map_factory, map_id);
|
|
347
|
|
348 if (map_source != NULL)
|
|
349 {
|
|
350 g_object_set(G_OBJECT(pgd->gps_view), "map-source", map_source, NULL);
|
|
351 g_object_unref(map_factory);
|
|
352 }
|
|
353
|
|
354 g_object_unref(map_source);
|
|
355 }
|
|
356
|
|
357 void bar_pane_gps_enable_markers_checked_toggle_cb(GtkWidget *menu_widget, gpointer data)
|
|
358 {
|
|
359 PaneGPSData *pgd = data;
|
|
360
|
|
361 if (pgd->enable_markers_checked)
|
|
362 {
|
|
363 pgd->enable_markers_checked = FALSE;
|
|
364 }
|
|
365 else
|
|
366 {
|
|
367 pgd->enable_markers_checked = TRUE;
|
|
368 }
|
|
369 }
|
|
370
|
|
371 static void bar_pane_gps_centre_map_checked_toggle_cb(GtkWidget *menu_widget, gpointer data)
|
|
372 {
|
|
373 PaneGPSData *pgd = data;
|
|
374
|
|
375 if (pgd->centre_map_checked)
|
|
376 {
|
|
377 pgd->centre_map_checked = FALSE;
|
|
378 }
|
|
379 else
|
|
380 {
|
|
381 pgd->centre_map_checked = TRUE;
|
|
382 }
|
|
383 }
|
|
384
|
|
385 static void bar_pane_gps_change_map_cb(GtkWidget *widget, gpointer data)
|
|
386 {
|
1667
|
387 PaneGPSData *pgd = data;
|
1604
|
388 gchar *mapsource;
|
|
389
|
|
390 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))
|
|
391 return;
|
|
392
|
|
393 if (!pgd) return;
|
|
394
|
1667
|
395 mapsource = g_object_get_data(G_OBJECT(widget), "menu_item_radio_data");
|
1604
|
396 bar_pane_gps_set_map_source(pgd, mapsource);
|
|
397 }
|
|
398
|
|
399 static void bar_pane_gps_notify_selection(GtkWidget *bar, gint count)
|
|
400 {
|
|
401 PaneGPSData *pgd;
|
|
402
|
|
403 if (count == 0) return;
|
|
404
|
|
405 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
|
|
406 if (!pgd) return;
|
|
407
|
|
408 bar_pane_gps_update(pgd);
|
|
409 }
|
|
410
|
|
411 static void bar_pane_gps_set_fd(GtkWidget *bar, FileData *fd)
|
|
412 {
|
|
413 PaneGPSData *pgd;
|
|
414
|
|
415 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
|
|
416 if (!pgd) return;
|
|
417
|
|
418 file_data_unref(pgd->fd);
|
|
419 pgd->fd = file_data_ref(fd);
|
|
420
|
|
421 bar_pane_gps_update(pgd);
|
|
422 }
|
|
423
|
|
424 static gint bar_pane_gps_event(GtkWidget *bar, GdkEvent *event)
|
|
425 {
|
|
426 PaneGPSData *pgd;
|
|
427
|
|
428 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
|
|
429 if (!pgd) return FALSE;
|
|
430
|
|
431 if (GTK_WIDGET_HAS_FOCUS(pgd->widget)) return gtk_widget_event(GTK_WIDGET(pgd->widget), event);
|
|
432
|
|
433 return FALSE;
|
|
434 }
|
|
435
|
|
436 static void bar_pane_gps_write_config(GtkWidget *pane, GString *outstr, gint indent)
|
|
437 {
|
|
438 PaneGPSData *pgd;
|
|
439 gint zoom;
|
|
440 ChamplainMapSource *mapsource;
|
|
441 const gchar *map_id;
|
|
442 gchar *str = NULL;
|
|
443 GString *buffer = g_string_new(str);
|
|
444 gdouble position;
|
|
445 gint int_position;
|
|
446
|
|
447 pgd = g_object_get_data(G_OBJECT(pane), "pane_data");
|
|
448 if (!pgd) return;
|
|
449
|
|
450 WRITE_NL();
|
|
451 WRITE_STRING("<pane_gps ");
|
|
452 write_char_option(outstr, indent, "id", pgd->pane.id);
|
|
453 write_char_option(outstr, indent, "title", gtk_label_get_text(GTK_LABEL(pgd->pane.title)));
|
|
454 WRITE_BOOL(pgd->pane, expanded);
|
|
455 WRITE_INT(*pgd, height);
|
|
456 indent++;
|
|
457
|
|
458 g_object_get(G_OBJECT(pgd->gps_view), "map-source", &mapsource, NULL);
|
|
459 map_id = champlain_map_source_get_id(mapsource);
|
|
460 WRITE_NL();
|
|
461 write_char_option(outstr, indent, "map-id", map_id);
|
|
462
|
|
463 g_object_get(G_OBJECT(pgd->gps_view), "zoom-level", &zoom, NULL);
|
|
464 g_string_printf(buffer, "%d", zoom);
|
|
465 WRITE_NL();
|
|
466 write_char_option(outstr, indent, "zoom-level", buffer->str);
|
|
467
|
|
468 g_object_get(G_OBJECT(pgd->gps_view), "latitude", &position, NULL);
|
|
469 int_position = position * 1000000;
|
|
470 g_string_printf(buffer, "%i", int_position);
|
|
471 WRITE_NL();
|
|
472 write_char_option(outstr, indent, "latitude", buffer->str);
|
|
473
|
|
474 g_object_get(G_OBJECT(pgd->gps_view), "longitude", &position, NULL);
|
|
475 int_position = position * 1000000;
|
|
476 g_string_printf(buffer, "%i", int_position);
|
|
477 WRITE_NL();
|
|
478 write_char_option(outstr, indent, "longitude", buffer->str);
|
|
479
|
|
480 indent--;
|
|
481 WRITE_NL();
|
|
482 WRITE_STRING("/>");
|
|
483
|
|
484 g_object_unref(mapsource);
|
|
485
|
|
486 }
|
|
487
|
|
488 static void bar_pane_gps_slider_changed_cb(GtkScaleButton *slider,
|
|
489 gdouble zoom,
|
|
490 gpointer data)
|
|
491 {
|
|
492 PaneGPSData *pgd = data;
|
|
493 GString *message;
|
|
494
|
|
495 message = g_string_new("");
|
|
496 g_string_printf(message, _("Zoom %i"), (gint)zoom);
|
|
497
|
|
498 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "zoom-level", (gint)zoom, NULL);
|
|
499 gtk_widget_set_tooltip_text(GTK_WIDGET(slider), message->str);
|
|
500 g_string_free(message, TRUE);
|
|
501
|
|
502 }
|
|
503 static void bar_pane_gps_view_state_changed_cb(ChamplainView *view,
|
|
504 GParamSpec *gobject,
|
|
505 gpointer data)
|
|
506 {
|
|
507 PaneGPSData *pgd = data;
|
|
508 ChamplainState status;
|
|
509 gint zoom;
|
|
510 GString *message;
|
|
511
|
|
512 g_object_get(G_OBJECT(view), "zoom-level", &zoom, NULL);
|
|
513 message = g_string_new("");
|
|
514 g_string_printf(message, _("Zoom level %i"), zoom);
|
|
515
|
|
516 g_object_get(G_OBJECT(view), "state", &status, NULL);
|
|
517 if (status == CHAMPLAIN_STATE_LOADING)
|
|
518 {
|
|
519 gtk_label_set_text(GTK_LABEL(pgd->state), _("Loading map"));
|
|
520 }
|
|
521 else
|
|
522 {
|
|
523 gtk_label_set_text(GTK_LABEL(pgd->state), message->str);
|
|
524 }
|
|
525
|
|
526 gtk_widget_set_tooltip_text(GTK_WIDGET(pgd->slider), message->str);
|
|
527 gtk_scale_button_set_value(GTK_SCALE_BUTTON(pgd->slider), (gdouble)zoom);
|
|
528
|
|
529 g_string_free(message, TRUE);
|
|
530 }
|
|
531
|
|
532 static void bar_pane_gps_notify_cb(FileData *fd, NotifyType type, gpointer data)
|
|
533 {
|
|
534 PaneGPSData *pgd = data;
|
|
535
|
|
536 if ((type & (NOTIFY_REREAD | NOTIFY_CHANGE | NOTIFY_METADATA)) && fd == pgd->fd)
|
|
537 {
|
|
538 bar_pane_gps_update(pgd);
|
|
539 }
|
|
540 }
|
|
541
|
|
542 const gchar *bar_pane_gps_get_map_id(PaneGPSData *pgd)
|
|
543 {
|
|
544 const gchar *map_id;
|
|
545 ChamplainMapSource *mapsource;
|
|
546
|
|
547 g_object_get(G_OBJECT(pgd->gps_view), "map-source", &mapsource, NULL);
|
|
548 map_id = champlain_map_source_get_id(mapsource);
|
|
549
|
|
550 g_object_unref(mapsource);
|
|
551
|
|
552 return map_id;
|
|
553 }
|
|
554
|
|
555 static GtkWidget *bar_pane_gps_menu(PaneGPSData *pgd)
|
|
556 {
|
|
557 GtkWidget *menu;
|
|
558 GtkWidget *map_centre;
|
|
559 GtkWidget *parent;
|
|
560 ChamplainMapSourceFactory *map_factory;
|
|
561 GSList *map_list;
|
|
562 ChamplainMapSourceDesc *map_desc;
|
1667
|
563 const gchar *current;
|
1604
|
564
|
|
565 menu = popup_menu_short_lived();
|
|
566
|
|
567 map_factory = champlain_map_source_factory_get_default();
|
|
568 map_list = champlain_map_source_factory_get_list(map_factory);
|
1667
|
569 current = bar_pane_gps_get_map_id(pgd);
|
1604
|
570
|
|
571 while (map_list)
|
|
572 {
|
1667
|
573 map_desc = (ChamplainMapSourceDesc *)(map_list->data);
|
|
574
|
|
575 menu_item_add_radio(menu, map_desc->name, map_desc->id, strcmp(map_desc->id, current) == 0, G_CALLBACK(bar_pane_gps_change_map_cb), pgd);
|
|
576
|
1604
|
577 map_list = g_slist_next(map_list);
|
|
578 }
|
|
579
|
|
580 menu_item_add_divider(menu);
|
|
581 menu_item_add_check(menu, _("Enable markers"), pgd->enable_markers_checked,
|
|
582 G_CALLBACK(bar_pane_gps_enable_markers_checked_toggle_cb), pgd);
|
|
583 map_centre = menu_item_add_check(menu, _("Centre map on marker"), pgd->centre_map_checked,
|
|
584 G_CALLBACK(bar_pane_gps_centre_map_checked_toggle_cb), pgd);
|
|
585 if (!pgd->enable_markers_checked)
|
|
586 {
|
|
587 gtk_widget_set_sensitive(map_centre, FALSE);
|
|
588 }
|
|
589
|
|
590 g_slist_free(map_list);
|
|
591 g_object_unref(map_factory);
|
|
592 //g_object_unref(map_centre);
|
|
593
|
|
594 return menu;
|
|
595 }
|
|
596
|
|
597 /* Determine if the map is to be re-centred on the marker when another photo is selected
|
|
598 */
|
|
599 void bar_pane_gps_map_centreing(PaneGPSData *pgd)
|
|
600 {
|
|
601 GtkWidget *dialog;
|
|
602 GString *message = g_string_new("");
|
|
603
|
|
604 if (pgd->centre_map_checked)
|
|
605 {
|
|
606 message = g_string_append(message, _("Move map centre to marker\n is disabled"));
|
|
607 pgd->centre_map_checked = FALSE;
|
|
608 }
|
|
609 else
|
|
610 {
|
|
611 message = g_string_append(message, _("Move map centre to marker\n is enabled"));
|
|
612 pgd->centre_map_checked = TRUE;
|
|
613 }
|
|
614
|
|
615 dialog = gtk_message_dialog_new(NULL,
|
|
616 GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
617 GTK_MESSAGE_INFO,
|
|
618 GTK_BUTTONS_CLOSE,
|
|
619 "%s", message->str);
|
|
620 gtk_window_set_title(GTK_WINDOW(dialog), _("Map Centreing"));
|
|
621 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);
|
|
622 gtk_dialog_run(GTK_DIALOG(dialog));
|
|
623
|
|
624 gtk_widget_destroy(dialog);
|
|
625 g_string_free(message, TRUE);
|
|
626 }
|
|
627
|
|
628 static gboolean bar_pane_gps_map_keypress_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
|
|
629 {
|
|
630 PaneGPSData *pgd = data;
|
|
631 GtkWidget *menu;
|
|
632
|
|
633 if (bevent->button == MOUSE_BUTTON_RIGHT)
|
|
634 {
|
|
635 menu = bar_pane_gps_menu(pgd);
|
|
636 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
|
|
637 return TRUE;
|
|
638 }
|
|
639 else if (bevent->button == MOUSE_BUTTON_MIDDLE)
|
|
640 {
|
|
641 bar_pane_gps_map_centreing(pgd);
|
|
642 return TRUE;
|
|
643 }
|
|
644 else if (bevent->button == MOUSE_BUTTON_LEFT)
|
|
645 {
|
|
646 return FALSE;
|
|
647 }
|
|
648 else
|
|
649 {
|
|
650 return FALSE;
|
|
651 }
|
|
652 }
|
|
653
|
|
654 static void bar_pane_gps_destroy(GtkWidget *widget, gpointer data)
|
|
655 {
|
|
656 PaneGPSData *pgd = data;
|
|
657
|
|
658 file_data_unregister_notify_func(bar_pane_gps_notify_cb, pgd);
|
|
659
|
|
660 file_data_unref(pgd->fd);
|
|
661 g_free(pgd->map_source);
|
|
662 g_free(pgd->pane.id);
|
|
663 clutter_actor_destroy(pgd->gps_view);
|
|
664 g_free(pgd);
|
|
665 }
|
|
666
|
|
667
|
|
668 GtkWidget *bar_pane_gps_new(const gchar *id, const gchar *title, const gchar *map_id,
|
|
669 const gint zoom, const gdouble latitude, const gdouble longitude,
|
|
670 gboolean expanded, gint height)
|
|
671 {
|
|
672 PaneGPSData *pgd;
|
|
673 GtkWidget *vbox, *scrolled;
|
|
674 GtkWidget *gpswidget, *viewport;
|
|
675 GtkWidget *status, *state, *progress, *slider;
|
|
676 ChamplainLayer *layer;
|
|
677 ClutterActor *view;
|
|
678 const gchar *slider_list[] = {GTK_STOCK_ZOOM_IN, GTK_STOCK_ZOOM_OUT, NULL};
|
|
679 const gchar **slider_icons = slider_list;
|
|
680
|
|
681 pgd = g_new0(PaneGPSData, 1);
|
|
682
|
|
683 pgd->pane.pane_set_fd = bar_pane_gps_set_fd;
|
|
684 pgd->pane.pane_notify_selection = bar_pane_gps_notify_selection;
|
|
685 pgd->pane.pane_event = bar_pane_gps_event;
|
|
686 pgd->pane.pane_write_config = bar_pane_gps_write_config;
|
|
687 pgd->pane.title = bar_pane_expander_title(title);
|
|
688 pgd->pane.id = g_strdup(id);
|
|
689 pgd->pane.type = PANE_GPS;
|
|
690 pgd->pane.expanded = expanded;
|
|
691 pgd->height = height;
|
|
692
|
|
693 scrolled = gtk_scrolled_window_new(NULL, NULL);
|
|
694 vbox = gtk_vbox_new(FALSE, 0);
|
1667
|
695
|
|
696 gpswidget = gtk_champlain_embed_new ();
|
|
697 view = gtk_champlain_embed_get_view (GTK_CHAMPLAIN_EMBED (gpswidget));
|
|
698
|
1604
|
699 viewport = gtk_viewport_new(NULL, NULL);
|
|
700
|
|
701 gtk_container_add(GTK_CONTAINER(viewport), gpswidget);
|
|
702 gtk_box_pack_start(GTK_BOX(vbox),viewport, TRUE, TRUE, 0);
|
|
703 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled), vbox);
|
|
704
|
|
705 status = gtk_hbox_new(FALSE,0);
|
|
706 slider = gtk_scale_button_new(GTK_ICON_SIZE_SMALL_TOOLBAR, 1, 17, 1, slider_icons);
|
|
707 gtk_widget_set_tooltip_text(slider, "Zoom");
|
|
708 gtk_scale_button_set_value(GTK_SCALE_BUTTON(slider), (gdouble)zoom);
|
|
709
|
|
710 progress = gtk_progress_bar_new();
|
|
711 state = gtk_label_new("");
|
|
712 gtk_label_set_justify(GTK_LABEL(state), GTK_JUSTIFY_CENTER);
|
|
713
|
|
714 gtk_box_pack_start(GTK_BOX(status), GTK_WIDGET(slider), FALSE, FALSE, 0);
|
|
715 gtk_box_pack_start(GTK_BOX(status), GTK_WIDGET(state), FALSE, FALSE, 5);
|
|
716 gtk_box_pack_end(GTK_BOX(status), GTK_WIDGET(progress), FALSE, FALSE, 0);
|
|
717 gtk_box_pack_end(GTK_BOX(vbox),GTK_WIDGET(status), FALSE, FALSE, 0);
|
|
718
|
|
719 layer = champlain_layer_new();
|
|
720 champlain_view_add_layer(CHAMPLAIN_VIEW(view), layer);
|
|
721
|
|
722 pgd->icon_layer = layer;
|
|
723 pgd->gps_view = view;
|
|
724 pgd->widget = scrolled;
|
|
725 pgd->progress = progress;
|
|
726 pgd->slider = slider;
|
|
727 pgd->state = state;
|
|
728
|
|
729 bar_pane_gps_set_map_source(pgd, map_id);
|
|
730
|
|
731 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(view)), "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
|
|
732 "zoom-level", zoom,
|
|
733 "keep-center-on-resize", TRUE,
|
|
734 "decel-rate", 1.0,
|
|
735 "show-license", TRUE,
|
|
736 "zoom-on-double-click", FALSE,
|
|
737 "max-zoom-level", 17,
|
|
738 "min-zoom-level", 1,
|
|
739 NULL);
|
|
740 champlain_view_center_on(CHAMPLAIN_VIEW(view), latitude, longitude);
|
|
741 pgd->centre_map_checked = TRUE;
|
|
742 g_object_set_data(G_OBJECT(pgd->widget), "pane_data", pgd);
|
|
743 g_signal_connect(G_OBJECT(pgd->widget), "destroy", G_CALLBACK(bar_pane_gps_destroy), pgd);
|
|
744
|
|
745 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
|
|
746 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
|
|
747
|
|
748 gtk_widget_set_size_request(pgd->widget, -1, height);
|
|
749
|
|
750 clutter_set_motion_events_enabled(TRUE);
|
|
751 g_signal_connect(G_OBJECT(vbox), "button_press_event", G_CALLBACK(bar_pane_gps_map_keypress_cb), pgd);
|
|
752 g_signal_connect(pgd->gps_view, "notify::state", G_CALLBACK(bar_pane_gps_view_state_changed_cb), pgd);
|
|
753 g_signal_connect(pgd->gps_view, "notify::zoom-level", G_CALLBACK(bar_pane_gps_view_state_changed_cb), pgd);
|
|
754 g_signal_connect(G_OBJECT(slider), "value-changed", G_CALLBACK(bar_pane_gps_slider_changed_cb), pgd);
|
|
755
|
|
756 file_data_register_notify_func(bar_pane_gps_notify_cb, pgd, NOTIFY_PRIORITY_LOW);
|
|
757
|
|
758 pgd->create_markers_id = 0;
|
|
759 pgd->enable_markers_checked = TRUE;
|
|
760 pgd->centre_map_checked = TRUE;
|
|
761
|
|
762 return pgd->widget;
|
|
763 }
|
|
764
|
|
765 GtkWidget *bar_pane_gps_new_from_config(const gchar **attribute_names, const gchar **attribute_values)
|
|
766 {
|
|
767 gchar *title = g_strdup(_("GPS Map"));
|
|
768 gchar *map_id = NULL;
|
|
769 gboolean expanded = TRUE;
|
|
770 gint height = 350;
|
|
771 gint zoom = 7;
|
|
772 gdouble latitude;
|
|
773 gdouble longitude;
|
|
774 /* Latitude and longitude are stored in the config file as an integer of
|
|
775 * (actual value * 1,000,000). There is no READ_DOUBLE utilty function.
|
|
776 */
|
|
777 gint int_latitude = 54000000;
|
|
778 gint int_longitude = -4000000;
|
|
779 gchar *id = g_strdup("gps");
|
|
780 GtkWidget *ret;
|
|
781
|
|
782 while (*attribute_names)
|
|
783 {
|
|
784 const gchar *option = *attribute_names++;
|
|
785 const gchar *value = *attribute_values++;
|
|
786
|
|
787 if (READ_CHAR_FULL("title", title))
|
|
788 continue;
|
|
789 if (READ_CHAR_FULL("map-id", map_id))
|
|
790 continue;
|
|
791 /* There is a bug in the libchamplain libraries which prevents correct
|
|
792 * initialisation if the zoom level starts higher than 8
|
|
793 */
|
|
794 if (READ_INT_CLAMP_FULL("zoom-level", zoom, 1, 8))
|
|
795 continue;
|
|
796 if (READ_INT_CLAMP_FULL("latitude", int_latitude, -90000000, +90000000))
|
|
797 continue;
|
|
798 if (READ_INT_CLAMP_FULL("longitude", int_longitude, -90000000, +90000000))
|
|
799 continue;
|
|
800 if (READ_BOOL_FULL("expanded", expanded))
|
|
801 continue;
|
|
802 if (READ_INT_FULL("height", height))
|
|
803 continue;
|
|
804 if (READ_CHAR_FULL("id", id))
|
|
805 continue;
|
|
806
|
|
807 log_printf("unknown attribute %s = %s\n", option, value);
|
|
808 }
|
|
809
|
|
810 bar_pane_translate_title(PANE_COMMENT, id, &title);
|
|
811 latitude = int_latitude / 1000000;
|
|
812 longitude = int_longitude / 1000000;
|
|
813 ret = bar_pane_gps_new(id, title, map_id, zoom, latitude, longitude, expanded, height);
|
|
814 g_free(title);
|
|
815 g_free(map_id);
|
|
816 g_free(id);
|
|
817 return ret;
|
|
818 }
|
|
819
|
|
820 void bar_pane_gps_update_from_config(GtkWidget *pane, const gchar **attribute_names,
|
|
821 const gchar **attribute_values)
|
|
822 {
|
|
823 PaneGPSData *pgd;
|
|
824 gint zoom;
|
|
825 gint int_longitude, int_latitude;
|
|
826 gdouble longitude, latitude;
|
|
827
|
|
828 pgd = g_object_get_data(G_OBJECT(pane), "pane_data");
|
|
829 if (!pgd)
|
|
830 return;
|
|
831
|
|
832 gchar *title = NULL;
|
|
833
|
|
834 while (*attribute_names)
|
|
835 {
|
|
836 const gchar *option = *attribute_names++;
|
|
837 const gchar *value = *attribute_values++;
|
|
838
|
|
839 if (READ_CHAR_FULL("title", title))
|
|
840 continue;
|
|
841 if (READ_CHAR_FULL("map-id", pgd->map_source))
|
|
842 continue;
|
|
843 if (READ_BOOL_FULL("expanded", pgd->pane.expanded))
|
|
844 continue;
|
|
845 if (READ_INT_FULL("height", pgd->height))
|
|
846 continue;
|
|
847 if (READ_CHAR_FULL("id", pgd->pane.id))
|
|
848 continue;
|
|
849 if (READ_INT_CLAMP_FULL("zoom-level", zoom, 1, 8))
|
|
850 {
|
|
851 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "zoom-level", zoom, NULL);
|
|
852 continue;
|
|
853 }
|
|
854 if (READ_INT_CLAMP_FULL("longitude", int_longitude, -90000000, +90000000))
|
|
855 {
|
|
856 longitude = int_longitude / 1000000;
|
|
857 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "longitude", longitude, NULL);
|
|
858 continue;
|
|
859 }
|
|
860 if (READ_INT_CLAMP_FULL("latitude", int_latitude, -90000000, +90000000))
|
|
861 {
|
|
862 latitude = int_latitude / 1000000;
|
|
863 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "latitude", latitude, NULL);
|
|
864 continue;
|
|
865 }
|
|
866 log_printf("unknown attribute %s = %s\n", option, value);
|
|
867 }
|
|
868
|
|
869 if (title)
|
|
870 {
|
|
871 bar_pane_translate_title(PANE_COMMENT, pgd->pane.id, &title);
|
|
872 gtk_label_set_text(GTK_LABEL(pgd->pane.title), title);
|
|
873 g_free(title);
|
|
874 }
|
|
875
|
|
876 gtk_widget_set_size_request(pgd->widget, -1, pgd->height);
|
|
877 bar_update_expander(pane);
|
|
878 }
|
|
879
|
|
880 #endif
|
|
881 #endif
|
|
882
|
|
883 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
|