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);
|
1708
|
230 /* If the file has a parent, it must be a sidecar file. Do not process sidecar files
|
|
231 */
|
|
232 if (fd != NULL && fd->parent == NULL)
|
1604
|
233 {
|
|
234 latitude = metadata_read_GPS_coord(fd, "Xmp.exif.GPSLatitude", 1000);
|
|
235 longitude = metadata_read_GPS_coord(fd, "Xmp.exif.GPSLongitude", 1000);
|
|
236
|
|
237 if ((latitude != 1000) && (longitude != 1000))
|
|
238 {
|
|
239 marker = champlain_marker_new_with_text("i","courier 5", &marker_colour, &marker_colour);
|
|
240
|
|
241 champlain_base_marker_set_position(CHAMPLAIN_BASE_MARKER(marker), latitude, longitude);
|
|
242 clutter_container_add(CLUTTER_CONTAINER(pgd->icon_layer), marker, NULL);
|
|
243 clutter_actor_set_reactive(marker, TRUE);
|
|
244
|
|
245 g_signal_connect(G_OBJECT(marker), "button_press_event",
|
|
246 G_CALLBACK(bar_pane_gps_marker_keypress_cb), pgd);
|
|
247
|
|
248 g_object_set_data(G_OBJECT(marker), "file_fd", fd);
|
|
249
|
|
250 g_ptr_array_add(pgd->marker_list, marker);
|
|
251 if (pgd->centre_map_checked)
|
|
252 {
|
|
253 g_ptr_array_add(pgd->marker_list, NULL);
|
|
254 champlain_view_ensure_markers_visible(CHAMPLAIN_VIEW(pgd->gps_view),
|
|
255 (void *)pgd->marker_list->pdata, FALSE);
|
|
256 g_ptr_array_remove(pgd->marker_list, NULL);
|
|
257 }
|
|
258 }
|
|
259 }
|
|
260 return TRUE;
|
|
261 }
|
|
262
|
|
263 if (pgd->marker_list->len >= 1)
|
|
264 {
|
|
265 g_ptr_array_add(pgd->marker_list, NULL);
|
|
266
|
|
267 if (pgd->centre_map_checked)
|
|
268 {
|
|
269 champlain_view_ensure_markers_visible(CHAMPLAIN_VIEW(pgd->gps_view), (void *)pgd->marker_list->pdata, FALSE);
|
|
270 }
|
|
271 }
|
|
272
|
|
273 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pgd->progress), 0);
|
|
274 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pgd->progress), NULL);
|
|
275 g_list_free(pgd->selection_list);
|
|
276 g_ptr_array_free(pgd->marker_list, TRUE);
|
|
277 pgd->create_markers_id = 0;
|
|
278
|
|
279 return FALSE;
|
|
280 }
|
|
281
|
|
282 static void bar_pane_gps_update(PaneGPSData *pgd)
|
|
283 {
|
|
284 GList *list;
|
|
285 GList *work;
|
|
286
|
|
287 /* The widget does not have a parent during bar_pane_gps_new, so calling gtk_widget_show_all there gives a
|
|
288 * "Gtk-CRITICAL **: gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed"
|
|
289 * error. gtk_widget_show_all can be given after it has been added to the bar.
|
|
290 */
|
|
291 if (gtk_widget_get_parent(pgd->widget) != NULL)
|
|
292 gtk_widget_show_all(pgd->widget);
|
|
293
|
|
294 /* If a create-marker background process is running, kill it
|
|
295 * and start again
|
|
296 */
|
|
297 if (pgd->create_markers_id != 0)
|
|
298 {
|
|
299 if (g_idle_remove_by_data(pgd))
|
|
300 {
|
|
301 pgd->create_markers_id = 0;
|
|
302 }
|
|
303 else
|
|
304 {
|
|
305 return;
|
|
306 }
|
|
307 }
|
|
308
|
|
309 /* Delete any markers currently displayed
|
|
310 */
|
|
311 work = clutter_container_get_children(CLUTTER_CONTAINER(pgd->icon_layer));
|
|
312 while (work)
|
|
313 {
|
|
314 clutter_container_remove(CLUTTER_CONTAINER(pgd->icon_layer), work->data, NULL);
|
|
315 work = work->next;
|
|
316 }
|
|
317 g_list_free(work);
|
|
318
|
|
319 if (!pgd->enable_markers_checked)
|
|
320 {
|
|
321 return;
|
|
322 }
|
|
323
|
|
324 /* For each selected photo that has GPS data, create a marker containing
|
|
325 * a single, small text character the same colour as the marker background.
|
|
326 * Use a background process in case the user selects a large number of files.
|
|
327 */
|
|
328 list = layout_selection_list(pgd->pane.lw);
|
1754
|
329 list = file_data_process_groups_in_selection(list, FALSE, NULL);
|
1604
|
330
|
|
331 if (list != NULL)
|
|
332 {
|
|
333 pgd->selection_list = g_list_copy(list);
|
|
334 pgd->marker_list = g_ptr_array_new();
|
|
335 pgd->selection_count = g_list_length(pgd->selection_list);
|
|
336 pgd->create_markers_id = g_idle_add(bar_pane_gps_create_markers_cb, pgd);
|
|
337 }
|
|
338
|
|
339 g_list_free(list);
|
|
340 g_list_free(work);
|
|
341 }
|
|
342
|
|
343 void bar_pane_gps_set_map_source(PaneGPSData *pgd, const gchar *map_id)
|
|
344 {
|
|
345 ChamplainMapSource *map_source;
|
|
346 ChamplainMapSourceFactory *map_factory;
|
|
347
|
1733
|
348 #if CHAMPLAIN_CHECK_VERSION(0,3,2)
|
|
349 map_factory = champlain_map_source_factory_dup_default();
|
|
350 #else
|
1604
|
351 map_factory = champlain_map_source_factory_get_default();
|
1733
|
352 #endif
|
1604
|
353 map_source = champlain_map_source_factory_create(map_factory, map_id);
|
|
354
|
|
355 if (map_source != NULL)
|
|
356 {
|
|
357 g_object_set(G_OBJECT(pgd->gps_view), "map-source", map_source, NULL);
|
|
358 g_object_unref(map_factory);
|
|
359 }
|
|
360
|
|
361 g_object_unref(map_source);
|
|
362 }
|
|
363
|
|
364 void bar_pane_gps_enable_markers_checked_toggle_cb(GtkWidget *menu_widget, gpointer data)
|
|
365 {
|
|
366 PaneGPSData *pgd = data;
|
|
367
|
|
368 if (pgd->enable_markers_checked)
|
|
369 {
|
|
370 pgd->enable_markers_checked = FALSE;
|
|
371 }
|
|
372 else
|
|
373 {
|
|
374 pgd->enable_markers_checked = TRUE;
|
|
375 }
|
|
376 }
|
|
377
|
|
378 static void bar_pane_gps_centre_map_checked_toggle_cb(GtkWidget *menu_widget, gpointer data)
|
|
379 {
|
|
380 PaneGPSData *pgd = data;
|
|
381
|
|
382 if (pgd->centre_map_checked)
|
|
383 {
|
|
384 pgd->centre_map_checked = FALSE;
|
|
385 }
|
|
386 else
|
|
387 {
|
|
388 pgd->centre_map_checked = TRUE;
|
|
389 }
|
|
390 }
|
|
391
|
|
392 static void bar_pane_gps_change_map_cb(GtkWidget *widget, gpointer data)
|
|
393 {
|
1667
|
394 PaneGPSData *pgd = data;
|
1604
|
395 gchar *mapsource;
|
|
396
|
|
397 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))
|
|
398 return;
|
|
399
|
|
400 if (!pgd) return;
|
|
401
|
1667
|
402 mapsource = g_object_get_data(G_OBJECT(widget), "menu_item_radio_data");
|
1604
|
403 bar_pane_gps_set_map_source(pgd, mapsource);
|
|
404 }
|
|
405
|
|
406 static void bar_pane_gps_notify_selection(GtkWidget *bar, gint count)
|
|
407 {
|
|
408 PaneGPSData *pgd;
|
|
409
|
|
410 if (count == 0) return;
|
|
411
|
|
412 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
|
|
413 if (!pgd) return;
|
|
414
|
|
415 bar_pane_gps_update(pgd);
|
|
416 }
|
|
417
|
|
418 static void bar_pane_gps_set_fd(GtkWidget *bar, FileData *fd)
|
|
419 {
|
|
420 PaneGPSData *pgd;
|
|
421
|
|
422 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
|
|
423 if (!pgd) return;
|
|
424
|
|
425 file_data_unref(pgd->fd);
|
|
426 pgd->fd = file_data_ref(fd);
|
|
427
|
|
428 bar_pane_gps_update(pgd);
|
|
429 }
|
|
430
|
|
431 static gint bar_pane_gps_event(GtkWidget *bar, GdkEvent *event)
|
|
432 {
|
|
433 PaneGPSData *pgd;
|
|
434
|
|
435 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
|
|
436 if (!pgd) return FALSE;
|
|
437
|
|
438 if (GTK_WIDGET_HAS_FOCUS(pgd->widget)) return gtk_widget_event(GTK_WIDGET(pgd->widget), event);
|
|
439
|
|
440 return FALSE;
|
|
441 }
|
|
442
|
|
443 static void bar_pane_gps_write_config(GtkWidget *pane, GString *outstr, gint indent)
|
|
444 {
|
|
445 PaneGPSData *pgd;
|
|
446 gint zoom;
|
|
447 ChamplainMapSource *mapsource;
|
|
448 const gchar *map_id;
|
|
449 gchar *str = NULL;
|
|
450 GString *buffer = g_string_new(str);
|
|
451 gdouble position;
|
|
452 gint int_position;
|
|
453
|
|
454 pgd = g_object_get_data(G_OBJECT(pane), "pane_data");
|
|
455 if (!pgd) return;
|
|
456
|
|
457 WRITE_NL();
|
|
458 WRITE_STRING("<pane_gps ");
|
|
459 write_char_option(outstr, indent, "id", pgd->pane.id);
|
|
460 write_char_option(outstr, indent, "title", gtk_label_get_text(GTK_LABEL(pgd->pane.title)));
|
|
461 WRITE_BOOL(pgd->pane, expanded);
|
|
462 WRITE_INT(*pgd, height);
|
|
463 indent++;
|
|
464
|
|
465 g_object_get(G_OBJECT(pgd->gps_view), "map-source", &mapsource, NULL);
|
|
466 map_id = champlain_map_source_get_id(mapsource);
|
|
467 WRITE_NL();
|
|
468 write_char_option(outstr, indent, "map-id", map_id);
|
|
469
|
|
470 g_object_get(G_OBJECT(pgd->gps_view), "zoom-level", &zoom, NULL);
|
|
471 g_string_printf(buffer, "%d", zoom);
|
|
472 WRITE_NL();
|
|
473 write_char_option(outstr, indent, "zoom-level", buffer->str);
|
|
474
|
|
475 g_object_get(G_OBJECT(pgd->gps_view), "latitude", &position, NULL);
|
|
476 int_position = position * 1000000;
|
|
477 g_string_printf(buffer, "%i", int_position);
|
|
478 WRITE_NL();
|
|
479 write_char_option(outstr, indent, "latitude", buffer->str);
|
|
480
|
|
481 g_object_get(G_OBJECT(pgd->gps_view), "longitude", &position, NULL);
|
|
482 int_position = position * 1000000;
|
|
483 g_string_printf(buffer, "%i", int_position);
|
|
484 WRITE_NL();
|
|
485 write_char_option(outstr, indent, "longitude", buffer->str);
|
|
486
|
|
487 indent--;
|
|
488 WRITE_NL();
|
|
489 WRITE_STRING("/>");
|
|
490
|
|
491 g_object_unref(mapsource);
|
|
492
|
|
493 }
|
|
494
|
|
495 static void bar_pane_gps_slider_changed_cb(GtkScaleButton *slider,
|
1733
|
496 gdouble zoom,
|
|
497 gpointer data)
|
1604
|
498 {
|
|
499 PaneGPSData *pgd = data;
|
|
500 GString *message;
|
|
501
|
|
502 message = g_string_new("");
|
|
503 g_string_printf(message, _("Zoom %i"), (gint)zoom);
|
|
504
|
|
505 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "zoom-level", (gint)zoom, NULL);
|
|
506 gtk_widget_set_tooltip_text(GTK_WIDGET(slider), message->str);
|
|
507 g_string_free(message, TRUE);
|
|
508
|
|
509 }
|
|
510 static void bar_pane_gps_view_state_changed_cb(ChamplainView *view,
|
1733
|
511 GParamSpec *gobject,
|
|
512 gpointer data)
|
1604
|
513 {
|
|
514 PaneGPSData *pgd = data;
|
|
515 ChamplainState status;
|
|
516 gint zoom;
|
|
517 GString *message;
|
|
518
|
|
519 g_object_get(G_OBJECT(view), "zoom-level", &zoom, NULL);
|
|
520 message = g_string_new("");
|
|
521 g_string_printf(message, _("Zoom level %i"), zoom);
|
|
522
|
|
523 g_object_get(G_OBJECT(view), "state", &status, NULL);
|
|
524 if (status == CHAMPLAIN_STATE_LOADING)
|
|
525 {
|
|
526 gtk_label_set_text(GTK_LABEL(pgd->state), _("Loading map"));
|
|
527 }
|
|
528 else
|
|
529 {
|
|
530 gtk_label_set_text(GTK_LABEL(pgd->state), message->str);
|
|
531 }
|
|
532
|
|
533 gtk_widget_set_tooltip_text(GTK_WIDGET(pgd->slider), message->str);
|
|
534 gtk_scale_button_set_value(GTK_SCALE_BUTTON(pgd->slider), (gdouble)zoom);
|
|
535
|
|
536 g_string_free(message, TRUE);
|
|
537 }
|
|
538
|
|
539 static void bar_pane_gps_notify_cb(FileData *fd, NotifyType type, gpointer data)
|
|
540 {
|
|
541 PaneGPSData *pgd = data;
|
|
542
|
|
543 if ((type & (NOTIFY_REREAD | NOTIFY_CHANGE | NOTIFY_METADATA)) && fd == pgd->fd)
|
|
544 {
|
|
545 bar_pane_gps_update(pgd);
|
|
546 }
|
|
547 }
|
|
548
|
|
549 const gchar *bar_pane_gps_get_map_id(PaneGPSData *pgd)
|
|
550 {
|
|
551 const gchar *map_id;
|
|
552 ChamplainMapSource *mapsource;
|
|
553
|
|
554 g_object_get(G_OBJECT(pgd->gps_view), "map-source", &mapsource, NULL);
|
|
555 map_id = champlain_map_source_get_id(mapsource);
|
|
556
|
|
557 g_object_unref(mapsource);
|
|
558
|
|
559 return map_id;
|
|
560 }
|
|
561
|
|
562 static GtkWidget *bar_pane_gps_menu(PaneGPSData *pgd)
|
|
563 {
|
|
564 GtkWidget *menu;
|
|
565 GtkWidget *map_centre;
|
|
566 GtkWidget *parent;
|
|
567 ChamplainMapSourceFactory *map_factory;
|
|
568 GSList *map_list;
|
|
569 ChamplainMapSourceDesc *map_desc;
|
1667
|
570 const gchar *current;
|
1604
|
571
|
|
572 menu = popup_menu_short_lived();
|
|
573
|
1733
|
574 #if CHAMPLAIN_CHECK_VERSION(0,3,2)
|
|
575 map_factory = champlain_map_source_factory_dup_default();
|
|
576 map_list = champlain_map_source_factory_dup_list(map_factory);
|
|
577 #else
|
1604
|
578 map_factory = champlain_map_source_factory_get_default();
|
|
579 map_list = champlain_map_source_factory_get_list(map_factory);
|
1733
|
580 #endif
|
1667
|
581 current = bar_pane_gps_get_map_id(pgd);
|
1604
|
582
|
|
583 while (map_list)
|
|
584 {
|
1667
|
585 map_desc = (ChamplainMapSourceDesc *)(map_list->data);
|
|
586
|
|
587 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);
|
|
588
|
1604
|
589 map_list = g_slist_next(map_list);
|
|
590 }
|
|
591
|
|
592 menu_item_add_divider(menu);
|
|
593 menu_item_add_check(menu, _("Enable markers"), pgd->enable_markers_checked,
|
|
594 G_CALLBACK(bar_pane_gps_enable_markers_checked_toggle_cb), pgd);
|
|
595 map_centre = menu_item_add_check(menu, _("Centre map on marker"), pgd->centre_map_checked,
|
|
596 G_CALLBACK(bar_pane_gps_centre_map_checked_toggle_cb), pgd);
|
|
597 if (!pgd->enable_markers_checked)
|
|
598 {
|
|
599 gtk_widget_set_sensitive(map_centre, FALSE);
|
|
600 }
|
|
601
|
|
602 g_slist_free(map_list);
|
|
603 g_object_unref(map_factory);
|
|
604 //g_object_unref(map_centre);
|
|
605
|
|
606 return menu;
|
|
607 }
|
|
608
|
|
609 /* Determine if the map is to be re-centred on the marker when another photo is selected
|
|
610 */
|
|
611 void bar_pane_gps_map_centreing(PaneGPSData *pgd)
|
|
612 {
|
|
613 GtkWidget *dialog;
|
|
614 GString *message = g_string_new("");
|
|
615
|
|
616 if (pgd->centre_map_checked)
|
|
617 {
|
|
618 message = g_string_append(message, _("Move map centre to marker\n is disabled"));
|
|
619 pgd->centre_map_checked = FALSE;
|
|
620 }
|
|
621 else
|
|
622 {
|
|
623 message = g_string_append(message, _("Move map centre to marker\n is enabled"));
|
|
624 pgd->centre_map_checked = TRUE;
|
|
625 }
|
|
626
|
|
627 dialog = gtk_message_dialog_new(NULL,
|
|
628 GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
629 GTK_MESSAGE_INFO,
|
|
630 GTK_BUTTONS_CLOSE,
|
|
631 "%s", message->str);
|
|
632 gtk_window_set_title(GTK_WINDOW(dialog), _("Map Centreing"));
|
|
633 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);
|
|
634 gtk_dialog_run(GTK_DIALOG(dialog));
|
|
635
|
|
636 gtk_widget_destroy(dialog);
|
|
637 g_string_free(message, TRUE);
|
|
638 }
|
|
639
|
|
640 static gboolean bar_pane_gps_map_keypress_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
|
|
641 {
|
|
642 PaneGPSData *pgd = data;
|
|
643 GtkWidget *menu;
|
|
644
|
|
645 if (bevent->button == MOUSE_BUTTON_RIGHT)
|
|
646 {
|
|
647 menu = bar_pane_gps_menu(pgd);
|
|
648 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
|
|
649 return TRUE;
|
|
650 }
|
|
651 else if (bevent->button == MOUSE_BUTTON_MIDDLE)
|
|
652 {
|
|
653 bar_pane_gps_map_centreing(pgd);
|
|
654 return TRUE;
|
|
655 }
|
|
656 else if (bevent->button == MOUSE_BUTTON_LEFT)
|
|
657 {
|
|
658 return FALSE;
|
|
659 }
|
|
660 else
|
|
661 {
|
|
662 return FALSE;
|
|
663 }
|
|
664 }
|
|
665
|
|
666 static void bar_pane_gps_destroy(GtkWidget *widget, gpointer data)
|
|
667 {
|
|
668 PaneGPSData *pgd = data;
|
|
669
|
|
670 file_data_unregister_notify_func(bar_pane_gps_notify_cb, pgd);
|
|
671
|
|
672 file_data_unref(pgd->fd);
|
|
673 g_free(pgd->map_source);
|
|
674 g_free(pgd->pane.id);
|
|
675 clutter_actor_destroy(pgd->gps_view);
|
|
676 g_free(pgd);
|
|
677 }
|
|
678
|
|
679
|
|
680 GtkWidget *bar_pane_gps_new(const gchar *id, const gchar *title, const gchar *map_id,
|
|
681 const gint zoom, const gdouble latitude, const gdouble longitude,
|
|
682 gboolean expanded, gint height)
|
|
683 {
|
|
684 PaneGPSData *pgd;
|
|
685 GtkWidget *vbox, *scrolled;
|
|
686 GtkWidget *gpswidget, *viewport;
|
|
687 GtkWidget *status, *state, *progress, *slider;
|
|
688 ChamplainLayer *layer;
|
1733
|
689 ChamplainView *view;
|
1604
|
690 const gchar *slider_list[] = {GTK_STOCK_ZOOM_IN, GTK_STOCK_ZOOM_OUT, NULL};
|
|
691 const gchar **slider_icons = slider_list;
|
|
692
|
|
693 pgd = g_new0(PaneGPSData, 1);
|
|
694
|
|
695 pgd->pane.pane_set_fd = bar_pane_gps_set_fd;
|
|
696 pgd->pane.pane_notify_selection = bar_pane_gps_notify_selection;
|
|
697 pgd->pane.pane_event = bar_pane_gps_event;
|
|
698 pgd->pane.pane_write_config = bar_pane_gps_write_config;
|
|
699 pgd->pane.title = bar_pane_expander_title(title);
|
|
700 pgd->pane.id = g_strdup(id);
|
|
701 pgd->pane.type = PANE_GPS;
|
|
702 pgd->pane.expanded = expanded;
|
|
703 pgd->height = height;
|
|
704
|
|
705 scrolled = gtk_scrolled_window_new(NULL, NULL);
|
|
706 vbox = gtk_vbox_new(FALSE, 0);
|
1667
|
707
|
1679
|
708 #ifdef GTK_CHAMPLAIN_EMBED
|
1733
|
709 gpswidget = gtk_champlain_embed_new();
|
|
710 view = gtk_champlain_embed_get_view(GTK_CHAMPLAIN_EMBED(gpswidget));
|
1679
|
711 #else
|
|
712 view = champlain_view_new();
|
1733
|
713 gpswidget = champlain_view_embed_new(view);
|
1679
|
714 #endif
|
1604
|
715 viewport = gtk_viewport_new(NULL, NULL);
|
|
716
|
|
717 gtk_container_add(GTK_CONTAINER(viewport), gpswidget);
|
|
718 gtk_box_pack_start(GTK_BOX(vbox),viewport, TRUE, TRUE, 0);
|
|
719 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled), vbox);
|
|
720
|
|
721 status = gtk_hbox_new(FALSE,0);
|
|
722 slider = gtk_scale_button_new(GTK_ICON_SIZE_SMALL_TOOLBAR, 1, 17, 1, slider_icons);
|
|
723 gtk_widget_set_tooltip_text(slider, "Zoom");
|
|
724 gtk_scale_button_set_value(GTK_SCALE_BUTTON(slider), (gdouble)zoom);
|
|
725
|
|
726 progress = gtk_progress_bar_new();
|
|
727 state = gtk_label_new("");
|
|
728 gtk_label_set_justify(GTK_LABEL(state), GTK_JUSTIFY_CENTER);
|
|
729
|
|
730 gtk_box_pack_start(GTK_BOX(status), GTK_WIDGET(slider), FALSE, FALSE, 0);
|
|
731 gtk_box_pack_start(GTK_BOX(status), GTK_WIDGET(state), FALSE, FALSE, 5);
|
|
732 gtk_box_pack_end(GTK_BOX(status), GTK_WIDGET(progress), FALSE, FALSE, 0);
|
|
733 gtk_box_pack_end(GTK_BOX(vbox),GTK_WIDGET(status), FALSE, FALSE, 0);
|
|
734
|
|
735 layer = champlain_layer_new();
|
1733
|
736 champlain_view_add_layer(view, layer);
|
1604
|
737
|
|
738 pgd->icon_layer = layer;
|
1733
|
739 pgd->gps_view = CLUTTER_ACTOR(view);
|
1604
|
740 pgd->widget = scrolled;
|
|
741 pgd->progress = progress;
|
|
742 pgd->slider = slider;
|
|
743 pgd->state = state;
|
|
744
|
|
745 bar_pane_gps_set_map_source(pgd, map_id);
|
|
746
|
1733
|
747 g_object_set(G_OBJECT(view), "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
|
|
748 "zoom-level", zoom,
|
|
749 "keep-center-on-resize", TRUE,
|
|
750 "decel-rate", 1.0,
|
|
751 "show-license", TRUE,
|
|
752 "zoom-on-double-click", FALSE,
|
|
753 "max-zoom-level", 17,
|
|
754 "min-zoom-level", 1,
|
|
755 NULL);
|
|
756 champlain_view_center_on(view, latitude, longitude);
|
1604
|
757 pgd->centre_map_checked = TRUE;
|
|
758 g_object_set_data(G_OBJECT(pgd->widget), "pane_data", pgd);
|
|
759 g_signal_connect(G_OBJECT(pgd->widget), "destroy", G_CALLBACK(bar_pane_gps_destroy), pgd);
|
|
760
|
|
761 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
|
|
762 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
|
|
763
|
|
764 gtk_widget_set_size_request(pgd->widget, -1, height);
|
|
765
|
|
766 clutter_set_motion_events_enabled(TRUE);
|
|
767 g_signal_connect(G_OBJECT(vbox), "button_press_event", G_CALLBACK(bar_pane_gps_map_keypress_cb), pgd);
|
|
768 g_signal_connect(pgd->gps_view, "notify::state", G_CALLBACK(bar_pane_gps_view_state_changed_cb), pgd);
|
|
769 g_signal_connect(pgd->gps_view, "notify::zoom-level", G_CALLBACK(bar_pane_gps_view_state_changed_cb), pgd);
|
|
770 g_signal_connect(G_OBJECT(slider), "value-changed", G_CALLBACK(bar_pane_gps_slider_changed_cb), pgd);
|
|
771
|
|
772 file_data_register_notify_func(bar_pane_gps_notify_cb, pgd, NOTIFY_PRIORITY_LOW);
|
|
773
|
|
774 pgd->create_markers_id = 0;
|
|
775 pgd->enable_markers_checked = TRUE;
|
|
776 pgd->centre_map_checked = TRUE;
|
|
777
|
|
778 return pgd->widget;
|
|
779 }
|
|
780
|
|
781 GtkWidget *bar_pane_gps_new_from_config(const gchar **attribute_names, const gchar **attribute_values)
|
|
782 {
|
|
783 gchar *title = g_strdup(_("GPS Map"));
|
|
784 gchar *map_id = NULL;
|
|
785 gboolean expanded = TRUE;
|
|
786 gint height = 350;
|
|
787 gint zoom = 7;
|
|
788 gdouble latitude;
|
|
789 gdouble longitude;
|
|
790 /* Latitude and longitude are stored in the config file as an integer of
|
|
791 * (actual value * 1,000,000). There is no READ_DOUBLE utilty function.
|
|
792 */
|
|
793 gint int_latitude = 54000000;
|
|
794 gint int_longitude = -4000000;
|
|
795 gchar *id = g_strdup("gps");
|
|
796 GtkWidget *ret;
|
|
797
|
|
798 while (*attribute_names)
|
|
799 {
|
|
800 const gchar *option = *attribute_names++;
|
|
801 const gchar *value = *attribute_values++;
|
|
802
|
|
803 if (READ_CHAR_FULL("title", title))
|
|
804 continue;
|
|
805 if (READ_CHAR_FULL("map-id", map_id))
|
|
806 continue;
|
|
807 /* There is a bug in the libchamplain libraries which prevents correct
|
|
808 * initialisation if the zoom level starts higher than 8
|
|
809 */
|
|
810 if (READ_INT_CLAMP_FULL("zoom-level", zoom, 1, 8))
|
|
811 continue;
|
|
812 if (READ_INT_CLAMP_FULL("latitude", int_latitude, -90000000, +90000000))
|
|
813 continue;
|
|
814 if (READ_INT_CLAMP_FULL("longitude", int_longitude, -90000000, +90000000))
|
|
815 continue;
|
|
816 if (READ_BOOL_FULL("expanded", expanded))
|
|
817 continue;
|
|
818 if (READ_INT_FULL("height", height))
|
|
819 continue;
|
|
820 if (READ_CHAR_FULL("id", id))
|
|
821 continue;
|
|
822
|
|
823 log_printf("unknown attribute %s = %s\n", option, value);
|
|
824 }
|
|
825
|
|
826 bar_pane_translate_title(PANE_COMMENT, id, &title);
|
|
827 latitude = int_latitude / 1000000;
|
|
828 longitude = int_longitude / 1000000;
|
|
829 ret = bar_pane_gps_new(id, title, map_id, zoom, latitude, longitude, expanded, height);
|
|
830 g_free(title);
|
|
831 g_free(map_id);
|
|
832 g_free(id);
|
|
833 return ret;
|
|
834 }
|
|
835
|
|
836 void bar_pane_gps_update_from_config(GtkWidget *pane, const gchar **attribute_names,
|
|
837 const gchar **attribute_values)
|
|
838 {
|
|
839 PaneGPSData *pgd;
|
|
840 gint zoom;
|
|
841 gint int_longitude, int_latitude;
|
|
842 gdouble longitude, latitude;
|
|
843
|
|
844 pgd = g_object_get_data(G_OBJECT(pane), "pane_data");
|
|
845 if (!pgd)
|
|
846 return;
|
|
847
|
|
848 gchar *title = NULL;
|
|
849
|
|
850 while (*attribute_names)
|
|
851 {
|
|
852 const gchar *option = *attribute_names++;
|
|
853 const gchar *value = *attribute_values++;
|
|
854
|
|
855 if (READ_CHAR_FULL("title", title))
|
|
856 continue;
|
|
857 if (READ_CHAR_FULL("map-id", pgd->map_source))
|
|
858 continue;
|
|
859 if (READ_BOOL_FULL("expanded", pgd->pane.expanded))
|
|
860 continue;
|
|
861 if (READ_INT_FULL("height", pgd->height))
|
|
862 continue;
|
|
863 if (READ_CHAR_FULL("id", pgd->pane.id))
|
|
864 continue;
|
|
865 if (READ_INT_CLAMP_FULL("zoom-level", zoom, 1, 8))
|
|
866 {
|
|
867 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "zoom-level", zoom, NULL);
|
|
868 continue;
|
|
869 }
|
|
870 if (READ_INT_CLAMP_FULL("longitude", int_longitude, -90000000, +90000000))
|
|
871 {
|
|
872 longitude = int_longitude / 1000000;
|
|
873 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "longitude", longitude, NULL);
|
|
874 continue;
|
|
875 }
|
|
876 if (READ_INT_CLAMP_FULL("latitude", int_latitude, -90000000, +90000000))
|
|
877 {
|
|
878 latitude = int_latitude / 1000000;
|
|
879 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "latitude", latitude, NULL);
|
|
880 continue;
|
|
881 }
|
|
882 log_printf("unknown attribute %s = %s\n", option, value);
|
|
883 }
|
|
884
|
|
885 if (title)
|
|
886 {
|
|
887 bar_pane_translate_title(PANE_COMMENT, pgd->pane.id, &title);
|
|
888 gtk_label_set_text(GTK_LABEL(pgd->pane.title), title);
|
|
889 g_free(title);
|
|
890 }
|
|
891
|
|
892 gtk_widget_set_size_request(pgd->widget, -1, pgd->height);
|
|
893 bar_update_expander(pane);
|
|
894 }
|
|
895
|
|
896 #endif
|
|
897 #endif
|
|
898
|
|
899 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
|