2 * Copyright (C) 2004 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifdef HAVE_LIBCHAMPLAIN
24 #ifdef HAVE_LIBCHAMPLAIN_GTK
37 #include <clutter-gtk/clutter-gtk.h>
38 #include <champlain/champlain.h>
39 #include <champlain-gtk/champlain-gtk.h>
41 #define MARKER_COLOUR 0x00, 0x00, 0xff, 0xff
42 #define TEXT_COLOUR 0x00, 0x00, 0x00, 0xff
43 #define THUMB_COLOUR 0xff, 0xff, 0xff, 0xff
44 #define THUMB_SIZE 100
47 *-------------------------------------------------------------------
49 *-------------------------------------------------------------------
52 typedef struct _PaneGPSData PaneGPSData;
60 ClutterActor *gps_view;
61 ChamplainMarkerLayer *icon_layer;
62 GList *selection_list;
64 ChamplainBoundingBox *bbox;
66 guint create_markers_id;
71 gboolean centre_map_checked;
72 gboolean enable_markers_checked;
75 static void bar_pane_gps_thumb_done_cb(ThumbLoader *tl, gpointer data)
81 marker = CLUTTER_ACTOR(data);
82 fd = g_object_get_data(G_OBJECT(marker), "file_fd");
83 if (fd->thumb_pixbuf != NULL)
85 actor = gtk_clutter_texture_new();
86 gtk_clutter_texture_set_from_pixbuf(GTK_CLUTTER_TEXTURE(actor), fd->thumb_pixbuf, NULL);
87 champlain_label_set_image(CHAMPLAIN_LABEL(marker), actor);
89 thumb_loader_free(tl);
92 static void bar_pane_gps_thumb_error_cb(ThumbLoader *tl, gpointer data)
94 thumb_loader_free(tl);
97 static gboolean bar_pane_gps_marker_keypress_cb(GtkWidget *widget, ClutterButtonEvent *bevent, gpointer data)
99 //PaneGPSData *pgd = data;
101 ClutterActor *marker;
102 ClutterColor marker_colour = { MARKER_COLOUR };
103 ClutterColor text_colour = { TEXT_COLOUR };
104 ClutterColor thumb_colour = { THUMB_COLOUR };
107 ClutterActor *current_image;
109 gint height, width, rotate;
110 gchar *altitude = NULL;
113 if (bevent->button == MOUSE_BUTTON_LEFT)
115 marker = CLUTTER_ACTOR(widget);
116 fd = g_object_get_data(G_OBJECT(marker), "file_fd");
118 /* If the marker is showing a thumbnail, delete it
120 current_image = champlain_label_get_image(CHAMPLAIN_LABEL(marker));
121 if (current_image != NULL)
123 clutter_actor_destroy(CLUTTER_ACTOR(current_image));
124 champlain_label_set_image(CHAMPLAIN_LABEL(marker), NULL);
127 current_text = g_strdup(champlain_label_get_text(CHAMPLAIN_LABEL(marker)));
129 /* If the marker is showing only the text character, replace it with a
130 * thumbnail and date and altitude
132 if (g_strcmp0(current_text, "i") == 0)
134 /* If a thumbail has already been generated, use that. If not try the pixbuf of the full image.
135 * If not, call the thumb_loader to generate a thumbnail and update the marker later in the
136 * thumb_loader callback
138 if (fd->thumb_pixbuf != NULL)
140 actor = gtk_clutter_texture_new();
141 gtk_clutter_texture_set_from_pixbuf(GTK_CLUTTER_TEXTURE(actor), fd->thumb_pixbuf, NULL);
142 champlain_label_set_image(CHAMPLAIN_LABEL(marker), actor);
144 else if (fd->pixbuf != NULL)
146 actor = gtk_clutter_texture_new();
147 width = gdk_pixbuf_get_width (fd->pixbuf);
148 height = gdk_pixbuf_get_height (fd->pixbuf);
149 switch (fd->exif_orientation)
152 rotate = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
155 rotate = GDK_PIXBUF_ROTATE_UPSIDEDOWN;
158 rotate = GDK_PIXBUF_ROTATE_CLOCKWISE;
161 rotate = GDK_PIXBUF_ROTATE_NONE;
164 gtk_clutter_texture_set_from_pixbuf(GTK_CLUTTER_TEXTURE(actor),
165 gdk_pixbuf_rotate_simple(gdk_pixbuf_scale_simple(fd->pixbuf, THUMB_SIZE, height * THUMB_SIZE / width,
166 GDK_INTERP_NEAREST), rotate), NULL);
167 champlain_label_set_image(CHAMPLAIN_LABEL(marker), actor);
171 tl = thumb_loader_new(THUMB_SIZE, THUMB_SIZE);
172 thumb_loader_set_callbacks(tl,
173 bar_pane_gps_thumb_done_cb,
174 bar_pane_gps_thumb_error_cb,
177 thumb_loader_start(tl, fd);
180 text = g_string_new(fd->name);
181 g_string_append(text, "\n");
182 g_string_append(text, text_from_time(fd->date));
183 g_string_append(text, "\n");
184 altitude = metadata_read_string(fd, "formatted.GPSAltitude", METADATA_FORMATTED);
185 if (altitude != NULL)
187 g_string_append(text, altitude);
190 champlain_label_set_text(CHAMPLAIN_LABEL(marker), text->str);
191 champlain_label_set_color(CHAMPLAIN_LABEL(marker), &thumb_colour);
192 champlain_label_set_text_color(CHAMPLAIN_LABEL(marker), &text_colour);
193 champlain_label_set_font_name(CHAMPLAIN_LABEL(marker), "sans 8");
196 g_string_free(text, TRUE);
198 /* otherwise, revert to the hidden text marker
202 champlain_label_set_text(CHAMPLAIN_LABEL(marker), "i");
203 champlain_label_set_color(CHAMPLAIN_LABEL(marker), &marker_colour);
204 champlain_label_set_text_color(CHAMPLAIN_LABEL(marker), &marker_colour);
205 champlain_label_set_font_name(CHAMPLAIN_LABEL(marker), "courier 5");
208 g_free(current_text);
215 static gboolean bar_pane_gps_create_markers_cb(gpointer data)
217 PaneGPSData *pgd = data;
220 ClutterActor *marker;
222 ClutterColor marker_colour = { MARKER_COLOUR };
225 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pgd->progress),
226 (gdouble)(pgd->selection_count - g_list_length(pgd->not_added)) /
227 (gdouble)pgd->selection_count);
229 message = g_string_new("");
230 g_string_printf(message, "%i/%i", (pgd->selection_count - g_list_length(pgd->not_added)),
231 pgd->selection_count);
232 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pgd->progress), message->str);
233 g_string_free(message, TRUE);
237 fd = pgd->not_added->data;
238 pgd->not_added = pgd->not_added->next;
240 latitude = metadata_read_GPS_coord(fd, "Xmp.exif.GPSLatitude", 0);
241 longitude = metadata_read_GPS_coord(fd, "Xmp.exif.GPSLongitude", 0);
243 if ((latitude != 0) && (longitude != 0))
247 marker = champlain_label_new_with_text("i","courier 5", &marker_colour, &marker_colour);
249 champlain_location_set_location(CHAMPLAIN_LOCATION(marker), latitude, longitude);
250 champlain_marker_layer_add_marker(pgd->icon_layer, CHAMPLAIN_MARKER(marker));
251 clutter_actor_set_reactive(marker, TRUE);
253 g_signal_connect(G_OBJECT(marker), "button_release_event",
254 G_CALLBACK(bar_pane_gps_marker_keypress_cb), pgd);
256 g_object_set_data(G_OBJECT(marker), "file_fd", fd);
258 champlain_bounding_box_extend(pgd->bbox, latitude, longitude);
263 if (pgd->centre_map_checked)
265 if (pgd->num_added == 1)
267 champlain_bounding_box_get_center(pgd->bbox, &latitude, &longitude);
268 champlain_view_go_to(CHAMPLAIN_VIEW(pgd->gps_view), latitude, longitude);
270 else if (pgd->num_added > 1)
272 champlain_view_ensure_visible(CHAMPLAIN_VIEW(pgd->gps_view), pgd->bbox, TRUE);
275 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pgd->progress), 0);
276 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pgd->progress), NULL);
277 pgd->create_markers_id = 0;
282 static void bar_pane_gps_update(PaneGPSData *pgd)
286 /* The widget does not have a parent during bar_pane_gps_new, so calling gtk_widget_show_all there gives a
287 * "Gtk-CRITICAL **: gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed"
288 * error. gtk_widget_show_all can be given after it has been added to the bar.
290 if (gtk_widget_get_parent(pgd->widget) != NULL)
291 gtk_widget_show_all(pgd->widget);
293 /* If a create-marker background process is running, kill it
296 if (pgd->create_markers_id != 0)
298 if (g_idle_remove_by_data(pgd))
300 pgd->create_markers_id = 0;
308 /* Delete any markers currently displayed
311 champlain_marker_layer_remove_all(pgd->icon_layer);
313 if (!pgd->enable_markers_checked)
318 /* For each selected photo that has GPS data, create a marker containing
319 * a single, small text character the same colour as the marker background.
320 * Use a background process in case the user selects a large number of files.
322 filelist_free(pgd->selection_list);
323 if (pgd->bbox) champlain_bounding_box_free(pgd->bbox);
325 list = layout_selection_list(pgd->pane.lw);
326 list = file_data_process_groups_in_selection(list, FALSE, NULL);
328 pgd->selection_list = list;
329 pgd->not_added = list;
331 pgd->bbox = champlain_bounding_box_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);
337 void bar_pane_gps_set_map_source(PaneGPSData *pgd, const gchar *map_id)
339 ChamplainMapSource *map_source;
340 ChamplainMapSourceFactory *map_factory;
342 map_factory = champlain_map_source_factory_dup_default();
343 map_source = champlain_map_source_factory_create(map_factory, map_id);
345 if (map_source != NULL)
347 g_object_set(G_OBJECT(pgd->gps_view), "map-source", map_source, NULL);
350 g_object_unref(map_factory);
353 void bar_pane_gps_enable_markers_checked_toggle_cb(GtkWidget *menu_widget, gpointer data)
355 PaneGPSData *pgd = data;
357 if (pgd->enable_markers_checked)
359 pgd->enable_markers_checked = FALSE;
363 pgd->enable_markers_checked = TRUE;
367 static void bar_pane_gps_centre_map_checked_toggle_cb(GtkWidget *menu_widget, gpointer data)
369 PaneGPSData *pgd = data;
371 if (pgd->centre_map_checked)
373 pgd->centre_map_checked = FALSE;
377 pgd->centre_map_checked = TRUE;
381 static void bar_pane_gps_change_map_cb(GtkWidget *widget, gpointer data)
383 PaneGPSData *pgd = data;
386 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))
391 mapsource = g_object_get_data(G_OBJECT(widget), "menu_item_radio_data");
392 bar_pane_gps_set_map_source(pgd, mapsource);
395 static void bar_pane_gps_notify_selection(GtkWidget *bar, gint count)
399 if (count == 0) return;
401 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
404 bar_pane_gps_update(pgd);
407 static void bar_pane_gps_set_fd(GtkWidget *bar, FileData *fd)
411 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
414 file_data_unref(pgd->fd);
415 pgd->fd = file_data_ref(fd);
417 bar_pane_gps_update(pgd);
420 static gint bar_pane_gps_event(GtkWidget *bar, GdkEvent *event)
424 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
425 if (!pgd) return FALSE;
427 if (gtk_widget_has_focus(pgd->widget)) return gtk_widget_event(GTK_WIDGET(pgd->widget), event);
432 static void bar_pane_gps_write_config(GtkWidget *pane, GString *outstr, gint indent)
436 ChamplainMapSource *mapsource;
439 GString *buffer = g_string_new(str);
443 pgd = g_object_get_data(G_OBJECT(pane), "pane_data");
447 WRITE_STRING("<pane_gps ");
448 write_char_option(outstr, indent, "id", pgd->pane.id);
449 write_char_option(outstr, indent, "title", gtk_label_get_text(GTK_LABEL(pgd->pane.title)));
450 WRITE_BOOL(pgd->pane, expanded);
451 WRITE_INT(*pgd, height);
454 g_object_get(G_OBJECT(pgd->gps_view), "map-source", &mapsource, NULL);
455 map_id = champlain_map_source_get_id(mapsource);
457 write_char_option(outstr, indent, "map-id", map_id);
459 g_object_get(G_OBJECT(pgd->gps_view), "zoom-level", &zoom, NULL);
460 g_string_printf(buffer, "%d", zoom);
462 write_char_option(outstr, indent, "zoom-level", buffer->str);
464 g_object_get(G_OBJECT(pgd->gps_view), "latitude", &position, NULL);
465 int_position = position * 1000000;
466 g_string_printf(buffer, "%i", int_position);
468 write_char_option(outstr, indent, "latitude", buffer->str);
470 g_object_get(G_OBJECT(pgd->gps_view), "longitude", &position, NULL);
471 int_position = position * 1000000;
472 g_string_printf(buffer, "%i", int_position);
474 write_char_option(outstr, indent, "longitude", buffer->str);
480 g_object_unref(mapsource);
484 static void bar_pane_gps_slider_changed_cb(GtkScaleButton *slider,
488 PaneGPSData *pgd = data;
491 message = g_string_new("");
492 g_string_printf(message, _("Zoom %i"), (gint)zoom);
494 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "zoom-level", (gint)zoom, NULL);
495 gtk_widget_set_tooltip_text(GTK_WIDGET(slider), message->str);
496 g_string_free(message, TRUE);
499 static void bar_pane_gps_view_state_changed_cb(ChamplainView *view,
503 PaneGPSData *pgd = data;
504 ChamplainState status;
508 g_object_get(G_OBJECT(view), "zoom-level", &zoom, NULL);
509 message = g_string_new("");
510 g_string_printf(message, _("Zoom level %i"), zoom);
512 g_object_get(G_OBJECT(view), "state", &status, NULL);
513 if (status == CHAMPLAIN_STATE_LOADING)
515 gtk_label_set_text(GTK_LABEL(pgd->state), _("Loading map"));
519 gtk_label_set_text(GTK_LABEL(pgd->state), message->str);
522 gtk_widget_set_tooltip_text(GTK_WIDGET(pgd->slider), message->str);
523 gtk_scale_button_set_value(GTK_SCALE_BUTTON(pgd->slider), (gdouble)zoom);
525 g_string_free(message, TRUE);
528 static void bar_pane_gps_notify_cb(FileData *fd, NotifyType type, gpointer data)
530 PaneGPSData *pgd = data;
532 if ((type & (NOTIFY_REREAD | NOTIFY_CHANGE | NOTIFY_METADATA)) &&
533 g_list_find(pgd->selection_list, fd))
535 bar_pane_gps_update(pgd);
539 const gchar *bar_pane_gps_get_map_id(PaneGPSData *pgd)
542 ChamplainMapSource *mapsource;
544 g_object_get(G_OBJECT(pgd->gps_view), "map-source", &mapsource, NULL);
545 map_id = champlain_map_source_get_id(mapsource);
547 g_object_unref(mapsource);
552 static GtkWidget *bar_pane_gps_menu(PaneGPSData *pgd)
555 GtkWidget *map_centre;
556 ChamplainMapSourceFactory *map_factory;
558 ChamplainMapSourceDesc *map_desc;
559 const gchar *current;
561 menu = popup_menu_short_lived();
563 map_factory = champlain_map_source_factory_dup_default();
564 map_list = champlain_map_source_factory_get_registered(map_factory);
565 current = bar_pane_gps_get_map_id(pgd);
569 map_desc = (ChamplainMapSourceDesc *)(map_list->data);
571 menu_item_add_radio(menu,
572 champlain_map_source_desc_get_name(map_desc),
573 (gpointer)champlain_map_source_desc_get_id(map_desc),
574 strcmp(champlain_map_source_desc_get_id(map_desc), current) == 0,
575 G_CALLBACK(bar_pane_gps_change_map_cb), pgd);
577 map_list = g_slist_next(map_list);
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)
587 gtk_widget_set_sensitive(map_centre, FALSE);
590 g_slist_free(map_list);
591 g_object_unref(map_factory);
596 /* Determine if the map is to be re-centred on the marker when another photo is selected
598 void bar_pane_gps_map_centreing(PaneGPSData *pgd)
601 GString *message = g_string_new("");
603 if (pgd->centre_map_checked)
605 message = g_string_append(message, _("Move map centre to marker\n is disabled"));
606 pgd->centre_map_checked = FALSE;
610 message = g_string_append(message, _("Move map centre to marker\n is enabled"));
611 pgd->centre_map_checked = TRUE;
614 dialog = gtk_message_dialog_new(NULL,
615 GTK_DIALOG_DESTROY_WITH_PARENT,
619 gtk_window_set_title(GTK_WINDOW(dialog), _("Map Centreing"));
620 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);
621 gtk_dialog_run(GTK_DIALOG(dialog));
623 gtk_widget_destroy(dialog);
624 g_string_free(message, TRUE);
627 static gboolean bar_pane_gps_map_keypress_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
629 PaneGPSData *pgd = data;
632 if (bevent->button == MOUSE_BUTTON_RIGHT)
634 menu = bar_pane_gps_menu(pgd);
635 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
638 else if (bevent->button == MOUSE_BUTTON_MIDDLE)
640 bar_pane_gps_map_centreing(pgd);
643 else if (bevent->button == MOUSE_BUTTON_LEFT)
653 static void bar_pane_gps_destroy(GtkWidget *widget, gpointer data)
655 PaneGPSData *pgd = data;
657 file_data_unregister_notify_func(bar_pane_gps_notify_cb, pgd);
659 g_idle_remove_by_data(pgd);
661 filelist_free(pgd->selection_list);
662 if (pgd->bbox) champlain_bounding_box_free(pgd->bbox);
664 file_data_unref(pgd->fd);
665 g_free(pgd->map_source);
666 g_free(pgd->pane.id);
667 clutter_actor_destroy(pgd->gps_view);
672 GtkWidget *bar_pane_gps_new(const gchar *id, const gchar *title, const gchar *map_id,
673 const gint zoom, const gdouble latitude, const gdouble longitude,
674 gboolean expanded, gint height)
677 GtkWidget *vbox, *frame;
678 GtkWidget *gpswidget;
679 GtkWidget *status, *state, *progress, *slider;
680 ChamplainMarkerLayer *layer;
682 const gchar *slider_list[] = {"zoom-in", "zoom-out", NULL};
683 const gchar **slider_icons = slider_list;
685 pgd = g_new0(PaneGPSData, 1);
687 pgd->pane.pane_set_fd = bar_pane_gps_set_fd;
688 pgd->pane.pane_notify_selection = bar_pane_gps_notify_selection;
689 pgd->pane.pane_event = bar_pane_gps_event;
690 pgd->pane.pane_write_config = bar_pane_gps_write_config;
691 pgd->pane.title = bar_pane_expander_title(title);
692 pgd->pane.id = g_strdup(id);
693 pgd->pane.type = PANE_GPS;
694 pgd->pane.expanded = expanded;
695 pgd->height = height;
697 frame = gtk_frame_new(NULL);
698 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
700 gpswidget = gtk_champlain_embed_new();
701 view = gtk_champlain_embed_get_view(GTK_CHAMPLAIN_EMBED(gpswidget));
703 gtk_box_pack_start(GTK_BOX(vbox), gpswidget, TRUE, TRUE, 0);
704 gtk_container_add(GTK_CONTAINER(frame), vbox);
706 status = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0);
707 slider = gtk_scale_button_new(GTK_ICON_SIZE_SMALL_TOOLBAR, 1, 17, 1, slider_icons);
708 gtk_widget_set_tooltip_text(slider, "Zoom");
709 gtk_scale_button_set_value(GTK_SCALE_BUTTON(slider), (gdouble)zoom);
711 progress = gtk_progress_bar_new();
712 state = gtk_label_new("");
713 gtk_label_set_justify(GTK_LABEL(state), GTK_JUSTIFY_CENTER);
715 gtk_box_pack_start(GTK_BOX(status), GTK_WIDGET(slider), FALSE, FALSE, 0);
716 gtk_box_pack_start(GTK_BOX(status), GTK_WIDGET(state), FALSE, FALSE, 5);
717 gtk_box_pack_end(GTK_BOX(status), GTK_WIDGET(progress), FALSE, FALSE, 0);
718 gtk_box_pack_end(GTK_BOX(vbox),GTK_WIDGET(status), FALSE, FALSE, 0);
720 layer = champlain_marker_layer_new();
721 champlain_view_add_layer(view, CHAMPLAIN_LAYER(layer));
723 pgd->icon_layer = layer;
724 pgd->gps_view = CLUTTER_ACTOR(view);
726 pgd->progress = progress;
727 pgd->slider = slider;
730 bar_pane_gps_set_map_source(pgd, map_id);
732 g_object_set(G_OBJECT(view), "kinetic-mode", TRUE,
734 "keep-center-on-resize", TRUE,
736 "zoom-on-double-click", FALSE,
737 "max-zoom-level", 17,
740 champlain_view_center_on(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);
745 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
747 gtk_widget_set_size_request(pgd->widget, -1, height);
749 g_signal_connect(G_OBJECT(gpswidget), "button_press_event", G_CALLBACK(bar_pane_gps_map_keypress_cb), pgd);
750 g_signal_connect(pgd->gps_view, "notify::state", G_CALLBACK(bar_pane_gps_view_state_changed_cb), pgd);
751 g_signal_connect(pgd->gps_view, "notify::zoom-level", G_CALLBACK(bar_pane_gps_view_state_changed_cb), pgd);
752 g_signal_connect(G_OBJECT(slider), "value-changed", G_CALLBACK(bar_pane_gps_slider_changed_cb), pgd);
754 file_data_register_notify_func(bar_pane_gps_notify_cb, pgd, NOTIFY_PRIORITY_LOW);
756 pgd->create_markers_id = 0;
757 pgd->enable_markers_checked = TRUE;
758 pgd->centre_map_checked = TRUE;
763 GtkWidget *bar_pane_gps_new_from_config(const gchar **attribute_names, const gchar **attribute_values)
765 gchar *title = g_strdup(_("GPS Map"));
766 gchar *map_id = NULL;
767 gboolean expanded = TRUE;
772 /* Latitude and longitude are stored in the config file as an integer of
773 * (actual value * 1,000,000). There is no READ_DOUBLE utilty function.
775 gint int_latitude = 54000000;
776 gint int_longitude = -4000000;
777 gchar *id = g_strdup("gps");
780 while (*attribute_names)
782 const gchar *option = *attribute_names++;
783 const gchar *value = *attribute_values++;
785 if (READ_CHAR_FULL("title", title))
787 if (READ_CHAR_FULL("map-id", map_id))
789 if (READ_INT_CLAMP_FULL("zoom-level", zoom, 1, 20))
791 if (READ_INT_CLAMP_FULL("latitude", int_latitude, -90000000, +90000000))
793 if (READ_INT_CLAMP_FULL("longitude", int_longitude, -90000000, +90000000))
795 if (READ_BOOL_FULL("expanded", expanded))
797 if (READ_INT_FULL("height", height))
799 if (READ_CHAR_FULL("id", id))
802 log_printf("unknown attribute %s = %s\n", option, value);
805 bar_pane_translate_title(PANE_COMMENT, id, &title);
806 latitude = int_latitude / 1000000;
807 longitude = int_longitude / 1000000;
808 ret = bar_pane_gps_new(id, title, map_id, zoom, latitude, longitude, expanded, height);
815 void bar_pane_gps_update_from_config(GtkWidget *pane, const gchar **attribute_names,
816 const gchar **attribute_values)
820 gint int_longitude, int_latitude;
821 gdouble longitude, latitude;
823 pgd = g_object_get_data(G_OBJECT(pane), "pane_data");
829 while (*attribute_names)
831 const gchar *option = *attribute_names++;
832 const gchar *value = *attribute_values++;
834 if (READ_CHAR_FULL("title", title))
836 if (READ_CHAR_FULL("map-id", pgd->map_source))
838 if (READ_BOOL_FULL("expanded", pgd->pane.expanded))
840 if (READ_INT_FULL("height", pgd->height))
842 if (READ_CHAR_FULL("id", pgd->pane.id))
844 if (READ_INT_CLAMP_FULL("zoom-level", zoom, 1, 8))
846 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "zoom-level", zoom, NULL);
849 if (READ_INT_CLAMP_FULL("longitude", int_longitude, -90000000, +90000000))
851 longitude = int_longitude / 1000000;
852 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "longitude", longitude, NULL);
855 if (READ_INT_CLAMP_FULL("latitude", int_latitude, -90000000, +90000000))
857 latitude = int_latitude / 1000000;
858 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "latitude", latitude, NULL);
861 log_printf("unknown attribute %s = %s\n", option, value);
866 bar_pane_translate_title(PANE_COMMENT, pgd->pane.id, &title);
867 gtk_label_set_text(GTK_LABEL(pgd->pane.title), title);
871 gtk_widget_set_size_request(pgd->widget, -1, pgd->height);
872 bar_update_expander(pane);
878 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */