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
|
1758
|
28 #include <clutter-gtk/clutter-gtk.h>
|
1604
|
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();
|
1758
|
75 gtk_clutter_texture_set_from_pixbuf(CLUTTER_TEXTURE(actor), fd->thumb_pixbuf, NULL);
|
1604
|
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();
|
1758
|
130 gtk_clutter_texture_set_from_pixbuf(CLUTTER_TEXTURE(actor), fd->thumb_pixbuf, NULL);
|
1604
|
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,
|
1758
|
155 GDK_INTERP_NEAREST), rotate), NULL);
|
1604
|
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 map_factory = champlain_map_source_factory_dup_default();
|
1604
|
349 map_source = champlain_map_source_factory_create(map_factory, map_id);
|
|
350
|
|
351 if (map_source != NULL)
|
|
352 {
|
|
353 g_object_set(G_OBJECT(pgd->gps_view), "map-source", map_source, NULL);
|
|
354 g_object_unref(map_factory);
|
|
355 }
|
|
356
|
|
357 g_object_unref(map_source);
|
|
358 }
|
|
359
|
|
360 void bar_pane_gps_enable_markers_checked_toggle_cb(GtkWidget *menu_widget, gpointer data)
|
|
361 {
|
|
362 PaneGPSData *pgd = data;
|
|
363
|
|
364 if (pgd->enable_markers_checked)
|
|
365 {
|
|
366 pgd->enable_markers_checked = FALSE;
|
|
367 }
|
|
368 else
|
|
369 {
|
|
370 pgd->enable_markers_checked = TRUE;
|
|
371 }
|
|
372 }
|
|
373
|
|
374 static void bar_pane_gps_centre_map_checked_toggle_cb(GtkWidget *menu_widget, gpointer data)
|
|
375 {
|
|
376 PaneGPSData *pgd = data;
|
|
377
|
|
378 if (pgd->centre_map_checked)
|
|
379 {
|
|
380 pgd->centre_map_checked = FALSE;
|
|
381 }
|
|
382 else
|
|
383 {
|
|
384 pgd->centre_map_checked = TRUE;
|
|
385 }
|
|
386 }
|
|
387
|
|
388 static void bar_pane_gps_change_map_cb(GtkWidget *widget, gpointer data)
|
|
389 {
|
1667
|
390 PaneGPSData *pgd = data;
|
1604
|
391 gchar *mapsource;
|
|
392
|
|
393 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))
|
|
394 return;
|
|
395
|
|
396 if (!pgd) return;
|
|
397
|
1667
|
398 mapsource = g_object_get_data(G_OBJECT(widget), "menu_item_radio_data");
|
1604
|
399 bar_pane_gps_set_map_source(pgd, mapsource);
|
|
400 }
|
|
401
|
|
402 static void bar_pane_gps_notify_selection(GtkWidget *bar, gint count)
|
|
403 {
|
|
404 PaneGPSData *pgd;
|
|
405
|
|
406 if (count == 0) return;
|
|
407
|
|
408 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
|
|
409 if (!pgd) return;
|
|
410
|
|
411 bar_pane_gps_update(pgd);
|
|
412 }
|
|
413
|
|
414 static void bar_pane_gps_set_fd(GtkWidget *bar, FileData *fd)
|
|
415 {
|
|
416 PaneGPSData *pgd;
|
|
417
|
|
418 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
|
|
419 if (!pgd) return;
|
|
420
|
|
421 file_data_unref(pgd->fd);
|
|
422 pgd->fd = file_data_ref(fd);
|
|
423
|
|
424 bar_pane_gps_update(pgd);
|
|
425 }
|
|
426
|
|
427 static gint bar_pane_gps_event(GtkWidget *bar, GdkEvent *event)
|
|
428 {
|
|
429 PaneGPSData *pgd;
|
|
430
|
|
431 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
|
|
432 if (!pgd) return FALSE;
|
|
433
|
|
434 if (GTK_WIDGET_HAS_FOCUS(pgd->widget)) return gtk_widget_event(GTK_WIDGET(pgd->widget), event);
|
|
435
|
|
436 return FALSE;
|
|
437 }
|
|
438
|
|
439 static void bar_pane_gps_write_config(GtkWidget *pane, GString *outstr, gint indent)
|
|
440 {
|
|
441 PaneGPSData *pgd;
|
|
442 gint zoom;
|
|
443 ChamplainMapSource *mapsource;
|
|
444 const gchar *map_id;
|
|
445 gchar *str = NULL;
|
|
446 GString *buffer = g_string_new(str);
|
|
447 gdouble position;
|
|
448 gint int_position;
|
|
449
|
|
450 pgd = g_object_get_data(G_OBJECT(pane), "pane_data");
|
|
451 if (!pgd) return;
|
|
452
|
|
453 WRITE_NL();
|
|
454 WRITE_STRING("<pane_gps ");
|
|
455 write_char_option(outstr, indent, "id", pgd->pane.id);
|
|
456 write_char_option(outstr, indent, "title", gtk_label_get_text(GTK_LABEL(pgd->pane.title)));
|
|
457 WRITE_BOOL(pgd->pane, expanded);
|
|
458 WRITE_INT(*pgd, height);
|
|
459 indent++;
|
|
460
|
|
461 g_object_get(G_OBJECT(pgd->gps_view), "map-source", &mapsource, NULL);
|
|
462 map_id = champlain_map_source_get_id(mapsource);
|
|
463 WRITE_NL();
|
|
464 write_char_option(outstr, indent, "map-id", map_id);
|
|
465
|
|
466 g_object_get(G_OBJECT(pgd->gps_view), "zoom-level", &zoom, NULL);
|
|
467 g_string_printf(buffer, "%d", zoom);
|
|
468 WRITE_NL();
|
|
469 write_char_option(outstr, indent, "zoom-level", buffer->str);
|
|
470
|
|
471 g_object_get(G_OBJECT(pgd->gps_view), "latitude", &position, NULL);
|
|
472 int_position = position * 1000000;
|
|
473 g_string_printf(buffer, "%i", int_position);
|
|
474 WRITE_NL();
|
|
475 write_char_option(outstr, indent, "latitude", buffer->str);
|
|
476
|
|
477 g_object_get(G_OBJECT(pgd->gps_view), "longitude", &position, NULL);
|
|
478 int_position = position * 1000000;
|
|
479 g_string_printf(buffer, "%i", int_position);
|
|
480 WRITE_NL();
|
|
481 write_char_option(outstr, indent, "longitude", buffer->str);
|
|
482
|
|
483 indent--;
|
|
484 WRITE_NL();
|
|
485 WRITE_STRING("/>");
|
|
486
|
|
487 g_object_unref(mapsource);
|
|
488
|
|
489 }
|
|
490
|
|
491 static void bar_pane_gps_slider_changed_cb(GtkScaleButton *slider,
|
1733
|
492 gdouble zoom,
|
|
493 gpointer data)
|
1604
|
494 {
|
|
495 PaneGPSData *pgd = data;
|
|
496 GString *message;
|
|
497
|
|
498 message = g_string_new("");
|
|
499 g_string_printf(message, _("Zoom %i"), (gint)zoom);
|
|
500
|
|
501 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "zoom-level", (gint)zoom, NULL);
|
|
502 gtk_widget_set_tooltip_text(GTK_WIDGET(slider), message->str);
|
|
503 g_string_free(message, TRUE);
|
|
504
|
|
505 }
|
|
506 static void bar_pane_gps_view_state_changed_cb(ChamplainView *view,
|
1733
|
507 GParamSpec *gobject,
|
|
508 gpointer data)
|
1604
|
509 {
|
|
510 PaneGPSData *pgd = data;
|
|
511 ChamplainState status;
|
|
512 gint zoom;
|
|
513 GString *message;
|
|
514
|
|
515 g_object_get(G_OBJECT(view), "zoom-level", &zoom, NULL);
|
|
516 message = g_string_new("");
|
|
517 g_string_printf(message, _("Zoom level %i"), zoom);
|
|
518
|
|
519 g_object_get(G_OBJECT(view), "state", &status, NULL);
|
|
520 if (status == CHAMPLAIN_STATE_LOADING)
|
|
521 {
|
|
522 gtk_label_set_text(GTK_LABEL(pgd->state), _("Loading map"));
|
|
523 }
|
|
524 else
|
|
525 {
|
|
526 gtk_label_set_text(GTK_LABEL(pgd->state), message->str);
|
|
527 }
|
|
528
|
|
529 gtk_widget_set_tooltip_text(GTK_WIDGET(pgd->slider), message->str);
|
|
530 gtk_scale_button_set_value(GTK_SCALE_BUTTON(pgd->slider), (gdouble)zoom);
|
|
531
|
|
532 g_string_free(message, TRUE);
|
|
533 }
|
|
534
|
|
535 static void bar_pane_gps_notify_cb(FileData *fd, NotifyType type, gpointer data)
|
|
536 {
|
|
537 PaneGPSData *pgd = data;
|
|
538
|
|
539 if ((type & (NOTIFY_REREAD | NOTIFY_CHANGE | NOTIFY_METADATA)) && fd == pgd->fd)
|
|
540 {
|
|
541 bar_pane_gps_update(pgd);
|
|
542 }
|
|
543 }
|
|
544
|
|
545 const gchar *bar_pane_gps_get_map_id(PaneGPSData *pgd)
|
|
546 {
|
|
547 const gchar *map_id;
|
|
548 ChamplainMapSource *mapsource;
|
|
549
|
|
550 g_object_get(G_OBJECT(pgd->gps_view), "map-source", &mapsource, NULL);
|
|
551 map_id = champlain_map_source_get_id(mapsource);
|
|
552
|
|
553 g_object_unref(mapsource);
|
|
554
|
|
555 return map_id;
|
|
556 }
|
|
557
|
|
558 static GtkWidget *bar_pane_gps_menu(PaneGPSData *pgd)
|
|
559 {
|
|
560 GtkWidget *menu;
|
|
561 GtkWidget *map_centre;
|
|
562 GtkWidget *parent;
|
|
563 ChamplainMapSourceFactory *map_factory;
|
|
564 GSList *map_list;
|
|
565 ChamplainMapSourceDesc *map_desc;
|
1667
|
566 const gchar *current;
|
1604
|
567
|
|
568 menu = popup_menu_short_lived();
|
|
569
|
1733
|
570 map_factory = champlain_map_source_factory_dup_default();
|
|
571 map_list = champlain_map_source_factory_dup_list(map_factory);
|
1667
|
572 current = bar_pane_gps_get_map_id(pgd);
|
1604
|
573
|
|
574 while (map_list)
|
|
575 {
|
1667
|
576 map_desc = (ChamplainMapSourceDesc *)(map_list->data);
|
|
577
|
|
578 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);
|
|
579
|
1604
|
580 map_list = g_slist_next(map_list);
|
|
581 }
|
|
582
|
|
583 menu_item_add_divider(menu);
|
|
584 menu_item_add_check(menu, _("Enable markers"), pgd->enable_markers_checked,
|
|
585 G_CALLBACK(bar_pane_gps_enable_markers_checked_toggle_cb), pgd);
|
|
586 map_centre = menu_item_add_check(menu, _("Centre map on marker"), pgd->centre_map_checked,
|
|
587 G_CALLBACK(bar_pane_gps_centre_map_checked_toggle_cb), pgd);
|
|
588 if (!pgd->enable_markers_checked)
|
|
589 {
|
|
590 gtk_widget_set_sensitive(map_centre, FALSE);
|
|
591 }
|
|
592
|
|
593 g_slist_free(map_list);
|
|
594 g_object_unref(map_factory);
|
|
595 //g_object_unref(map_centre);
|
|
596
|
|
597 return menu;
|
|
598 }
|
|
599
|
|
600 /* Determine if the map is to be re-centred on the marker when another photo is selected
|
|
601 */
|
|
602 void bar_pane_gps_map_centreing(PaneGPSData *pgd)
|
|
603 {
|
|
604 GtkWidget *dialog;
|
|
605 GString *message = g_string_new("");
|
|
606
|
|
607 if (pgd->centre_map_checked)
|
|
608 {
|
|
609 message = g_string_append(message, _("Move map centre to marker\n is disabled"));
|
|
610 pgd->centre_map_checked = FALSE;
|
|
611 }
|
|
612 else
|
|
613 {
|
|
614 message = g_string_append(message, _("Move map centre to marker\n is enabled"));
|
|
615 pgd->centre_map_checked = TRUE;
|
|
616 }
|
|
617
|
|
618 dialog = gtk_message_dialog_new(NULL,
|
|
619 GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
620 GTK_MESSAGE_INFO,
|
|
621 GTK_BUTTONS_CLOSE,
|
|
622 "%s", message->str);
|
|
623 gtk_window_set_title(GTK_WINDOW(dialog), _("Map Centreing"));
|
|
624 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);
|
|
625 gtk_dialog_run(GTK_DIALOG(dialog));
|
|
626
|
|
627 gtk_widget_destroy(dialog);
|
|
628 g_string_free(message, TRUE);
|
|
629 }
|
|
630
|
|
631 static gboolean bar_pane_gps_map_keypress_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
|
|
632 {
|
|
633 PaneGPSData *pgd = data;
|
|
634 GtkWidget *menu;
|
|
635
|
|
636 if (bevent->button == MOUSE_BUTTON_RIGHT)
|
|
637 {
|
|
638 menu = bar_pane_gps_menu(pgd);
|
|
639 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
|
|
640 return TRUE;
|
|
641 }
|
|
642 else if (bevent->button == MOUSE_BUTTON_MIDDLE)
|
|
643 {
|
|
644 bar_pane_gps_map_centreing(pgd);
|
|
645 return TRUE;
|
|
646 }
|
|
647 else if (bevent->button == MOUSE_BUTTON_LEFT)
|
|
648 {
|
|
649 return FALSE;
|
|
650 }
|
|
651 else
|
|
652 {
|
|
653 return FALSE;
|
|
654 }
|
|
655 }
|
|
656
|
|
657 static void bar_pane_gps_destroy(GtkWidget *widget, gpointer data)
|
|
658 {
|
|
659 PaneGPSData *pgd = data;
|
|
660
|
|
661 file_data_unregister_notify_func(bar_pane_gps_notify_cb, pgd);
|
|
662
|
|
663 file_data_unref(pgd->fd);
|
|
664 g_free(pgd->map_source);
|
|
665 g_free(pgd->pane.id);
|
|
666 clutter_actor_destroy(pgd->gps_view);
|
|
667 g_free(pgd);
|
|
668 }
|
|
669
|
|
670
|
|
671 GtkWidget *bar_pane_gps_new(const gchar *id, const gchar *title, const gchar *map_id,
|
|
672 const gint zoom, const gdouble latitude, const gdouble longitude,
|
|
673 gboolean expanded, gint height)
|
|
674 {
|
|
675 PaneGPSData *pgd;
|
1760
|
676 GtkWidget *vbox, *frame;
|
1604
|
677 GtkWidget *gpswidget, *viewport;
|
|
678 GtkWidget *status, *state, *progress, *slider;
|
|
679 ChamplainLayer *layer;
|
1733
|
680 ChamplainView *view;
|
1604
|
681 const gchar *slider_list[] = {GTK_STOCK_ZOOM_IN, GTK_STOCK_ZOOM_OUT, NULL};
|
|
682 const gchar **slider_icons = slider_list;
|
|
683
|
|
684 pgd = g_new0(PaneGPSData, 1);
|
|
685
|
|
686 pgd->pane.pane_set_fd = bar_pane_gps_set_fd;
|
|
687 pgd->pane.pane_notify_selection = bar_pane_gps_notify_selection;
|
|
688 pgd->pane.pane_event = bar_pane_gps_event;
|
|
689 pgd->pane.pane_write_config = bar_pane_gps_write_config;
|
|
690 pgd->pane.title = bar_pane_expander_title(title);
|
|
691 pgd->pane.id = g_strdup(id);
|
|
692 pgd->pane.type = PANE_GPS;
|
|
693 pgd->pane.expanded = expanded;
|
|
694 pgd->height = height;
|
|
695
|
1760
|
696 frame = gtk_frame_new(NULL);
|
1604
|
697 vbox = gtk_vbox_new(FALSE, 0);
|
1667
|
698
|
1733
|
699 gpswidget = gtk_champlain_embed_new();
|
|
700 view = gtk_champlain_embed_get_view(GTK_CHAMPLAIN_EMBED(gpswidget));
|
1760
|
701
|
|
702 gtk_box_pack_start(GTK_BOX(vbox), gpswidget, TRUE, TRUE, 0);
|
|
703 gtk_container_add(GTK_CONTAINER(frame), vbox);
|
1604
|
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();
|
1733
|
720 champlain_view_add_layer(view, layer);
|
1604
|
721
|
|
722 pgd->icon_layer = layer;
|
1733
|
723 pgd->gps_view = CLUTTER_ACTOR(view);
|
1760
|
724 pgd->widget = frame;
|
1604
|
725 pgd->progress = progress;
|
|
726 pgd->slider = slider;
|
|
727 pgd->state = state;
|
|
728
|
|
729 bar_pane_gps_set_map_source(pgd, map_id);
|
|
730
|
1733
|
731 g_object_set(G_OBJECT(view), "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
|
|
732 "zoom-level", zoom,
|
|
733 "keep-center-on-resize", TRUE,
|
1760
|
734 /* This seems to be broken, https://bugzilla.gnome.org/show_bug.cgi?id=596419
|
1733
|
735 "decel-rate", 1.0,
|
1760
|
736 */
|
1733
|
737 "show-license", TRUE,
|
|
738 "zoom-on-double-click", FALSE,
|
|
739 "max-zoom-level", 17,
|
|
740 "min-zoom-level", 1,
|
|
741 NULL);
|
|
742 champlain_view_center_on(view, latitude, longitude);
|
1604
|
743 pgd->centre_map_checked = TRUE;
|
|
744 g_object_set_data(G_OBJECT(pgd->widget), "pane_data", pgd);
|
|
745 g_signal_connect(G_OBJECT(pgd->widget), "destroy", G_CALLBACK(bar_pane_gps_destroy), pgd);
|
|
746
|
1760
|
747 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
|
1604
|
748
|
|
749 gtk_widget_set_size_request(pgd->widget, -1, height);
|
|
750
|
|
751 clutter_set_motion_events_enabled(TRUE);
|
1760
|
752 g_signal_connect(G_OBJECT(gpswidget), "button_press_event", G_CALLBACK(bar_pane_gps_map_keypress_cb), pgd);
|
1604
|
753 g_signal_connect(pgd->gps_view, "notify::state", G_CALLBACK(bar_pane_gps_view_state_changed_cb), pgd);
|
|
754 g_signal_connect(pgd->gps_view, "notify::zoom-level", G_CALLBACK(bar_pane_gps_view_state_changed_cb), pgd);
|
|
755 g_signal_connect(G_OBJECT(slider), "value-changed", G_CALLBACK(bar_pane_gps_slider_changed_cb), pgd);
|
|
756
|
|
757 file_data_register_notify_func(bar_pane_gps_notify_cb, pgd, NOTIFY_PRIORITY_LOW);
|
|
758
|
|
759 pgd->create_markers_id = 0;
|
|
760 pgd->enable_markers_checked = TRUE;
|
|
761 pgd->centre_map_checked = TRUE;
|
|
762
|
|
763 return pgd->widget;
|
|
764 }
|
|
765
|
|
766 GtkWidget *bar_pane_gps_new_from_config(const gchar **attribute_names, const gchar **attribute_values)
|
|
767 {
|
|
768 gchar *title = g_strdup(_("GPS Map"));
|
|
769 gchar *map_id = NULL;
|
|
770 gboolean expanded = TRUE;
|
|
771 gint height = 350;
|
|
772 gint zoom = 7;
|
|
773 gdouble latitude;
|
|
774 gdouble longitude;
|
|
775 /* Latitude and longitude are stored in the config file as an integer of
|
|
776 * (actual value * 1,000,000). There is no READ_DOUBLE utilty function.
|
|
777 */
|
|
778 gint int_latitude = 54000000;
|
|
779 gint int_longitude = -4000000;
|
|
780 gchar *id = g_strdup("gps");
|
|
781 GtkWidget *ret;
|
|
782
|
|
783 while (*attribute_names)
|
|
784 {
|
|
785 const gchar *option = *attribute_names++;
|
|
786 const gchar *value = *attribute_values++;
|
|
787
|
|
788 if (READ_CHAR_FULL("title", title))
|
|
789 continue;
|
|
790 if (READ_CHAR_FULL("map-id", map_id))
|
|
791 continue;
|
|
792 /* There is a bug in the libchamplain libraries which prevents correct
|
|
793 * initialisation if the zoom level starts higher than 8
|
|
794 */
|
|
795 if (READ_INT_CLAMP_FULL("zoom-level", zoom, 1, 8))
|
|
796 continue;
|
|
797 if (READ_INT_CLAMP_FULL("latitude", int_latitude, -90000000, +90000000))
|
|
798 continue;
|
|
799 if (READ_INT_CLAMP_FULL("longitude", int_longitude, -90000000, +90000000))
|
|
800 continue;
|
|
801 if (READ_BOOL_FULL("expanded", expanded))
|
|
802 continue;
|
|
803 if (READ_INT_FULL("height", height))
|
|
804 continue;
|
|
805 if (READ_CHAR_FULL("id", id))
|
|
806 continue;
|
|
807
|
|
808 log_printf("unknown attribute %s = %s\n", option, value);
|
|
809 }
|
|
810
|
|
811 bar_pane_translate_title(PANE_COMMENT, id, &title);
|
|
812 latitude = int_latitude / 1000000;
|
|
813 longitude = int_longitude / 1000000;
|
|
814 ret = bar_pane_gps_new(id, title, map_id, zoom, latitude, longitude, expanded, height);
|
|
815 g_free(title);
|
|
816 g_free(map_id);
|
|
817 g_free(id);
|
|
818 return ret;
|
|
819 }
|
|
820
|
|
821 void bar_pane_gps_update_from_config(GtkWidget *pane, const gchar **attribute_names,
|
|
822 const gchar **attribute_values)
|
|
823 {
|
|
824 PaneGPSData *pgd;
|
|
825 gint zoom;
|
|
826 gint int_longitude, int_latitude;
|
|
827 gdouble longitude, latitude;
|
|
828
|
|
829 pgd = g_object_get_data(G_OBJECT(pane), "pane_data");
|
|
830 if (!pgd)
|
|
831 return;
|
|
832
|
|
833 gchar *title = NULL;
|
|
834
|
|
835 while (*attribute_names)
|
|
836 {
|
|
837 const gchar *option = *attribute_names++;
|
|
838 const gchar *value = *attribute_values++;
|
|
839
|
|
840 if (READ_CHAR_FULL("title", title))
|
|
841 continue;
|
|
842 if (READ_CHAR_FULL("map-id", pgd->map_source))
|
|
843 continue;
|
|
844 if (READ_BOOL_FULL("expanded", pgd->pane.expanded))
|
|
845 continue;
|
|
846 if (READ_INT_FULL("height", pgd->height))
|
|
847 continue;
|
|
848 if (READ_CHAR_FULL("id", pgd->pane.id))
|
|
849 continue;
|
|
850 if (READ_INT_CLAMP_FULL("zoom-level", zoom, 1, 8))
|
|
851 {
|
|
852 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "zoom-level", zoom, NULL);
|
|
853 continue;
|
|
854 }
|
|
855 if (READ_INT_CLAMP_FULL("longitude", int_longitude, -90000000, +90000000))
|
|
856 {
|
|
857 longitude = int_longitude / 1000000;
|
|
858 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "longitude", longitude, NULL);
|
|
859 continue;
|
|
860 }
|
|
861 if (READ_INT_CLAMP_FULL("latitude", int_latitude, -90000000, +90000000))
|
|
862 {
|
|
863 latitude = int_latitude / 1000000;
|
|
864 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "latitude", latitude, NULL);
|
|
865 continue;
|
|
866 }
|
|
867 log_printf("unknown attribute %s = %s\n", option, value);
|
|
868 }
|
|
869
|
|
870 if (title)
|
|
871 {
|
|
872 bar_pane_translate_title(PANE_COMMENT, pgd->pane.id, &title);
|
|
873 gtk_label_set_text(GTK_LABEL(pgd->pane.title), title);
|
|
874 g_free(title);
|
|
875 }
|
|
876
|
|
877 gtk_widget_set_size_request(pgd->widget, -1, pgd->height);
|
|
878 bar_update_expander(pane);
|
|
879 }
|
|
880
|
|
881 #endif
|
|
882 #endif
|
|
883
|
|
884 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
|