4 * Copyright (C) 2008 - 2012 The Geeqie Team
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!
14 #ifdef HAVE_LIBCHAMPLAIN
15 #ifdef HAVE_LIBCHAMPLAIN_GTK
28 #include <clutter-gtk/clutter-gtk.h>
29 #include <champlain/champlain.h>
30 #include <champlain-gtk/champlain-gtk.h>
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
38 *-------------------------------------------------------------------
40 *-------------------------------------------------------------------
43 typedef struct _PaneGPSData PaneGPSData;
51 ClutterActor *gps_view;
52 ChamplainMarkerLayer *icon_layer;
53 GList *selection_list;
55 ChamplainBoundingBox *bbox;
57 guint create_markers_id;
62 gboolean centre_map_checked;
63 gboolean enable_markers_checked;
66 static void bar_pane_gps_thumb_done_cb(ThumbLoader *tl, gpointer data)
72 marker = CLUTTER_ACTOR(data);
73 fd = g_object_get_data(G_OBJECT(marker), "file_fd");
74 if (fd->thumb_pixbuf != NULL)
76 actor = gtk_clutter_texture_new();
77 gtk_clutter_texture_set_from_pixbuf(GTK_CLUTTER_TEXTURE(actor), fd->thumb_pixbuf, NULL);
78 champlain_label_set_image(CHAMPLAIN_LABEL(marker), actor);
80 thumb_loader_free(tl);
83 static void bar_pane_gps_thumb_error_cb(ThumbLoader *tl, gpointer data)
85 thumb_loader_free(tl);
88 static gboolean bar_pane_gps_marker_keypress_cb(GtkWidget *widget, ClutterButtonEvent *bevent, gpointer data)
90 //PaneGPSData *pgd = data;
93 ClutterColor marker_colour = { MARKER_COLOUR };
94 ClutterColor text_colour = { TEXT_COLOUR };
95 ClutterColor thumb_colour = { THUMB_COLOUR };
98 ClutterActor *current_image;
100 gint height, width, rotate;
101 gchar *altitude = NULL;
104 if (bevent->button == MOUSE_BUTTON_LEFT)
106 marker = CLUTTER_ACTOR(widget);
107 fd = g_object_get_data(G_OBJECT(marker), "file_fd");
109 /* If the marker is showing a thumbnail, delete it
111 current_image = champlain_label_get_image(CHAMPLAIN_LABEL(marker));
112 if (current_image != NULL)
114 clutter_actor_destroy(CLUTTER_ACTOR(current_image));
115 champlain_label_set_image(CHAMPLAIN_LABEL(marker), NULL);
118 current_text = g_strdup(champlain_label_get_text(CHAMPLAIN_LABEL(marker)));
120 /* If the marker is showing only the text character, replace it with a
121 * thumbnail and date and altitude
123 if (g_strcmp0(current_text, "i") == 0)
125 /* If a thumbail has already been generated, use that. If not try the pixbuf of the full image.
126 * If not, call the thumb_loader to generate a thumbnail and update the marker later in the
127 * thumb_loader callback
129 if (fd->thumb_pixbuf != NULL)
131 actor = gtk_clutter_texture_new();
132 gtk_clutter_texture_set_from_pixbuf(GTK_CLUTTER_TEXTURE(actor), fd->thumb_pixbuf, NULL);
133 champlain_label_set_image(CHAMPLAIN_LABEL(marker), actor);
135 else if (fd->pixbuf != NULL)
137 actor = gtk_clutter_texture_new();
138 width = gdk_pixbuf_get_width (fd->pixbuf);
139 height = gdk_pixbuf_get_height (fd->pixbuf);
140 switch (fd->exif_orientation)
143 rotate = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE;
146 rotate = GDK_PIXBUF_ROTATE_UPSIDEDOWN;
149 rotate = GDK_PIXBUF_ROTATE_CLOCKWISE;
152 rotate = GDK_PIXBUF_ROTATE_NONE;
155 gtk_clutter_texture_set_from_pixbuf(GTK_CLUTTER_TEXTURE(actor),
156 gdk_pixbuf_rotate_simple(gdk_pixbuf_scale_simple(fd->pixbuf, THUMB_SIZE, height * THUMB_SIZE / width,
157 GDK_INTERP_NEAREST), rotate), NULL);
158 champlain_label_set_image(CHAMPLAIN_LABEL(marker), actor);
162 tl = thumb_loader_new(THUMB_SIZE, THUMB_SIZE);
163 thumb_loader_set_callbacks(tl,
164 bar_pane_gps_thumb_done_cb,
165 bar_pane_gps_thumb_error_cb,
168 thumb_loader_start(tl, fd);
171 text = g_string_new(fd->name);
172 g_string_append(text, "\n");
173 g_string_append(text, text_from_time(fd->date));
174 g_string_append(text, "\n");
175 altitude = metadata_read_string(fd, "formatted.GPSAltitude", METADATA_FORMATTED);
176 if (altitude != NULL)
178 g_string_append(text, altitude);
181 champlain_label_set_text(CHAMPLAIN_LABEL(marker), text->str);
182 champlain_label_set_color(CHAMPLAIN_LABEL(marker), &thumb_colour);
183 champlain_label_set_text_color(CHAMPLAIN_LABEL(marker), &text_colour);
184 champlain_label_set_font_name(CHAMPLAIN_LABEL(marker), "sans 8");
187 g_string_free(text, TRUE);
189 /* otherwise, revert to the hidden text marker
193 champlain_label_set_text(CHAMPLAIN_LABEL(marker), "i");
194 champlain_label_set_color(CHAMPLAIN_LABEL(marker), &marker_colour);
195 champlain_label_set_text_color(CHAMPLAIN_LABEL(marker), &marker_colour);
196 champlain_label_set_font_name(CHAMPLAIN_LABEL(marker), "courier 5");
199 g_free(current_text);
206 static gboolean bar_pane_gps_create_markers_cb(gpointer data)
208 PaneGPSData *pgd = data;
212 ClutterActor *marker;
214 ClutterColor marker_colour = { MARKER_COLOUR };
217 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pgd->progress),
218 (gdouble)(pgd->selection_count - g_list_length(pgd->not_added)) /
219 (gdouble)pgd->selection_count);
221 message = g_string_new("");
222 g_string_printf(message, "%i/%i", (pgd->selection_count - g_list_length(pgd->not_added)),
223 pgd->selection_count);
224 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pgd->progress), message->str);
225 g_string_free(message, TRUE);
229 fd = pgd->not_added->data;
230 pgd->not_added = pgd->not_added->next;
232 latitude = metadata_read_GPS_coord(fd, "Xmp.exif.GPSLatitude", 1000);
233 longitude = metadata_read_GPS_coord(fd, "Xmp.exif.GPSLongitude", 1000);
235 if ((latitude != 1000) && (longitude != 1000))
239 marker = champlain_label_new_with_text("i","courier 5", &marker_colour, &marker_colour);
241 champlain_location_set_location(CHAMPLAIN_LOCATION(marker), latitude, longitude);
242 champlain_marker_layer_add_marker(pgd->icon_layer, CHAMPLAIN_MARKER(marker));
243 clutter_actor_set_reactive(marker, TRUE);
245 g_signal_connect(G_OBJECT(marker), "button_release_event",
246 G_CALLBACK(bar_pane_gps_marker_keypress_cb), pgd);
248 g_object_set_data(G_OBJECT(marker), "file_fd", fd);
250 champlain_bounding_box_extend(pgd->bbox, latitude, longitude);
255 if (pgd->centre_map_checked)
257 if (pgd->num_added == 1)
259 champlain_bounding_box_get_center(pgd->bbox, &latitude, &longitude);
260 champlain_view_go_to(CHAMPLAIN_VIEW(pgd->gps_view), latitude, longitude);
262 else if (pgd->num_added > 1)
264 champlain_view_ensure_visible(CHAMPLAIN_VIEW(pgd->gps_view), pgd->bbox, TRUE);
267 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pgd->progress), 0);
268 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pgd->progress), NULL);
269 pgd->create_markers_id = 0;
274 static void bar_pane_gps_update(PaneGPSData *pgd)
278 /* The widget does not have a parent during bar_pane_gps_new, so calling gtk_widget_show_all there gives a
279 * "Gtk-CRITICAL **: gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed"
280 * error. gtk_widget_show_all can be given after it has been added to the bar.
282 if (gtk_widget_get_parent(pgd->widget) != NULL)
283 gtk_widget_show_all(pgd->widget);
285 /* If a create-marker background process is running, kill it
288 if (pgd->create_markers_id != 0)
290 if (g_idle_remove_by_data(pgd))
292 pgd->create_markers_id = 0;
300 /* Delete any markers currently displayed
303 champlain_marker_layer_remove_all(pgd->icon_layer);
305 if (!pgd->enable_markers_checked)
310 /* For each selected photo that has GPS data, create a marker containing
311 * a single, small text character the same colour as the marker background.
312 * Use a background process in case the user selects a large number of files.
314 filelist_free(pgd->selection_list);
315 if (pgd->bbox) champlain_bounding_box_free(pgd->bbox);
317 list = layout_selection_list(pgd->pane.lw);
318 list = file_data_process_groups_in_selection(list, FALSE, NULL);
320 pgd->selection_list = list;
321 pgd->not_added = list;
323 pgd->bbox = champlain_bounding_box_new();
324 pgd->selection_count = g_list_length(pgd->selection_list);
325 pgd->create_markers_id = g_idle_add(bar_pane_gps_create_markers_cb, pgd);
329 void bar_pane_gps_set_map_source(PaneGPSData *pgd, const gchar *map_id)
331 ChamplainMapSource *map_source;
332 ChamplainMapSourceFactory *map_factory;
334 map_factory = champlain_map_source_factory_dup_default();
335 map_source = champlain_map_source_factory_create(map_factory, map_id);
337 if (map_source != NULL)
339 g_object_set(G_OBJECT(pgd->gps_view), "map-source", map_source, NULL);
340 //g_object_unref(map_source);
343 g_object_unref(map_factory);
346 void bar_pane_gps_enable_markers_checked_toggle_cb(GtkWidget *menu_widget, gpointer data)
348 PaneGPSData *pgd = data;
350 if (pgd->enable_markers_checked)
352 pgd->enable_markers_checked = FALSE;
356 pgd->enable_markers_checked = TRUE;
360 static void bar_pane_gps_centre_map_checked_toggle_cb(GtkWidget *menu_widget, gpointer data)
362 PaneGPSData *pgd = data;
364 if (pgd->centre_map_checked)
366 pgd->centre_map_checked = FALSE;
370 pgd->centre_map_checked = TRUE;
374 static void bar_pane_gps_change_map_cb(GtkWidget *widget, gpointer data)
376 PaneGPSData *pgd = data;
379 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)))
384 mapsource = g_object_get_data(G_OBJECT(widget), "menu_item_radio_data");
385 bar_pane_gps_set_map_source(pgd, mapsource);
388 static void bar_pane_gps_notify_selection(GtkWidget *bar, gint count)
392 if (count == 0) return;
394 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
397 bar_pane_gps_update(pgd);
400 static void bar_pane_gps_set_fd(GtkWidget *bar, FileData *fd)
404 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
407 file_data_unref(pgd->fd);
408 pgd->fd = file_data_ref(fd);
410 bar_pane_gps_update(pgd);
413 static gint bar_pane_gps_event(GtkWidget *bar, GdkEvent *event)
417 pgd = g_object_get_data(G_OBJECT(bar), "pane_data");
418 if (!pgd) return FALSE;
420 if (gtk_widget_has_focus(pgd->widget)) return gtk_widget_event(GTK_WIDGET(pgd->widget), event);
425 static void bar_pane_gps_write_config(GtkWidget *pane, GString *outstr, gint indent)
429 ChamplainMapSource *mapsource;
432 GString *buffer = g_string_new(str);
436 pgd = g_object_get_data(G_OBJECT(pane), "pane_data");
440 WRITE_STRING("<pane_gps ");
441 write_char_option(outstr, indent, "id", pgd->pane.id);
442 write_char_option(outstr, indent, "title", gtk_label_get_text(GTK_LABEL(pgd->pane.title)));
443 WRITE_BOOL(pgd->pane, expanded);
444 WRITE_INT(*pgd, height);
447 g_object_get(G_OBJECT(pgd->gps_view), "map-source", &mapsource, NULL);
448 map_id = champlain_map_source_get_id(mapsource);
450 write_char_option(outstr, indent, "map-id", map_id);
452 g_object_get(G_OBJECT(pgd->gps_view), "zoom-level", &zoom, NULL);
453 g_string_printf(buffer, "%d", zoom);
455 write_char_option(outstr, indent, "zoom-level", buffer->str);
457 g_object_get(G_OBJECT(pgd->gps_view), "latitude", &position, NULL);
458 int_position = position * 1000000;
459 g_string_printf(buffer, "%i", int_position);
461 write_char_option(outstr, indent, "latitude", buffer->str);
463 g_object_get(G_OBJECT(pgd->gps_view), "longitude", &position, NULL);
464 int_position = position * 1000000;
465 g_string_printf(buffer, "%i", int_position);
467 write_char_option(outstr, indent, "longitude", buffer->str);
473 g_object_unref(mapsource);
477 static void bar_pane_gps_slider_changed_cb(GtkScaleButton *slider,
481 PaneGPSData *pgd = data;
484 message = g_string_new("");
485 g_string_printf(message, _("Zoom %i"), (gint)zoom);
487 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "zoom-level", (gint)zoom, NULL);
488 gtk_widget_set_tooltip_text(GTK_WIDGET(slider), message->str);
489 g_string_free(message, TRUE);
492 static void bar_pane_gps_view_state_changed_cb(ChamplainView *view,
496 PaneGPSData *pgd = data;
497 ChamplainState status;
501 g_object_get(G_OBJECT(view), "zoom-level", &zoom, NULL);
502 message = g_string_new("");
503 g_string_printf(message, _("Zoom level %i"), zoom);
505 g_object_get(G_OBJECT(view), "state", &status, NULL);
506 if (status == CHAMPLAIN_STATE_LOADING)
508 gtk_label_set_text(GTK_LABEL(pgd->state), _("Loading map"));
512 gtk_label_set_text(GTK_LABEL(pgd->state), message->str);
515 gtk_widget_set_tooltip_text(GTK_WIDGET(pgd->slider), message->str);
516 gtk_scale_button_set_value(GTK_SCALE_BUTTON(pgd->slider), (gdouble)zoom);
518 g_string_free(message, TRUE);
521 static void bar_pane_gps_notify_cb(FileData *fd, NotifyType type, gpointer data)
523 PaneGPSData *pgd = data;
525 if ((type & (NOTIFY_REREAD | NOTIFY_CHANGE | NOTIFY_METADATA)) &&
526 g_list_find(pgd->selection_list, fd))
528 bar_pane_gps_update(pgd);
532 const gchar *bar_pane_gps_get_map_id(PaneGPSData *pgd)
535 ChamplainMapSource *mapsource;
537 g_object_get(G_OBJECT(pgd->gps_view), "map-source", &mapsource, NULL);
538 map_id = champlain_map_source_get_id(mapsource);
540 g_object_unref(mapsource);
545 static GtkWidget *bar_pane_gps_menu(PaneGPSData *pgd)
548 GtkWidget *map_centre;
550 ChamplainMapSourceFactory *map_factory;
552 ChamplainMapSourceDesc *map_desc;
553 const gchar *current;
555 menu = popup_menu_short_lived();
557 map_factory = champlain_map_source_factory_dup_default();
558 map_list = champlain_map_source_factory_get_registered(map_factory);
559 current = bar_pane_gps_get_map_id(pgd);
563 map_desc = (ChamplainMapSourceDesc *)(map_list->data);
565 menu_item_add_radio(menu,
566 champlain_map_source_desc_get_name(map_desc),
567 (gpointer)champlain_map_source_desc_get_id(map_desc),
568 strcmp(champlain_map_source_desc_get_id(map_desc), current) == 0,
569 G_CALLBACK(bar_pane_gps_change_map_cb), pgd);
571 map_list = g_slist_next(map_list);
574 menu_item_add_divider(menu);
575 menu_item_add_check(menu, _("Enable markers"), pgd->enable_markers_checked,
576 G_CALLBACK(bar_pane_gps_enable_markers_checked_toggle_cb), pgd);
577 map_centre = menu_item_add_check(menu, _("Centre map on marker"), pgd->centre_map_checked,
578 G_CALLBACK(bar_pane_gps_centre_map_checked_toggle_cb), pgd);
579 if (!pgd->enable_markers_checked)
581 gtk_widget_set_sensitive(map_centre, FALSE);
584 g_slist_free(map_list);
585 g_object_unref(map_factory);
586 //g_object_unref(map_centre);
591 /* Determine if the map is to be re-centred on the marker when another photo is selected
593 void bar_pane_gps_map_centreing(PaneGPSData *pgd)
596 GString *message = g_string_new("");
598 if (pgd->centre_map_checked)
600 message = g_string_append(message, _("Move map centre to marker\n is disabled"));
601 pgd->centre_map_checked = FALSE;
605 message = g_string_append(message, _("Move map centre to marker\n is enabled"));
606 pgd->centre_map_checked = TRUE;
609 dialog = gtk_message_dialog_new(NULL,
610 GTK_DIALOG_DESTROY_WITH_PARENT,
614 gtk_window_set_title(GTK_WINDOW(dialog), _("Map Centreing"));
615 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);
616 gtk_dialog_run(GTK_DIALOG(dialog));
618 gtk_widget_destroy(dialog);
619 g_string_free(message, TRUE);
622 static gboolean bar_pane_gps_map_keypress_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
624 PaneGPSData *pgd = data;
627 if (bevent->button == MOUSE_BUTTON_RIGHT)
629 menu = bar_pane_gps_menu(pgd);
630 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
633 else if (bevent->button == MOUSE_BUTTON_MIDDLE)
635 bar_pane_gps_map_centreing(pgd);
638 else if (bevent->button == MOUSE_BUTTON_LEFT)
648 static void bar_pane_gps_destroy(GtkWidget *widget, gpointer data)
650 PaneGPSData *pgd = data;
652 file_data_unregister_notify_func(bar_pane_gps_notify_cb, pgd);
654 g_idle_remove_by_data(pgd);
656 filelist_free(pgd->selection_list);
657 if (pgd->bbox) champlain_bounding_box_free(pgd->bbox);
659 file_data_unref(pgd->fd);
660 g_free(pgd->map_source);
661 g_free(pgd->pane.id);
662 clutter_actor_destroy(pgd->gps_view);
667 GtkWidget *bar_pane_gps_new(const gchar *id, const gchar *title, const gchar *map_id,
668 const gint zoom, const gdouble latitude, const gdouble longitude,
669 gboolean expanded, gint height)
672 GtkWidget *vbox, *frame;
673 GtkWidget *gpswidget, *viewport;
674 GtkWidget *status, *state, *progress, *slider;
675 ChamplainMarkerLayer *layer;
677 const gchar *slider_list[] = {GTK_STOCK_ZOOM_IN, GTK_STOCK_ZOOM_OUT, NULL};
678 const gchar **slider_icons = slider_list;
680 pgd = g_new0(PaneGPSData, 1);
682 pgd->pane.pane_set_fd = bar_pane_gps_set_fd;
683 pgd->pane.pane_notify_selection = bar_pane_gps_notify_selection;
684 pgd->pane.pane_event = bar_pane_gps_event;
685 pgd->pane.pane_write_config = bar_pane_gps_write_config;
686 pgd->pane.title = bar_pane_expander_title(title);
687 pgd->pane.id = g_strdup(id);
688 pgd->pane.type = PANE_GPS;
689 pgd->pane.expanded = expanded;
690 pgd->height = height;
692 frame = gtk_frame_new(NULL);
693 vbox = gtk_vbox_new(FALSE, 0);
695 gpswidget = gtk_champlain_embed_new();
696 view = gtk_champlain_embed_get_view(GTK_CHAMPLAIN_EMBED(gpswidget));
698 gtk_box_pack_start(GTK_BOX(vbox), gpswidget, TRUE, TRUE, 0);
699 gtk_container_add(GTK_CONTAINER(frame), vbox);
701 status = gtk_hbox_new(FALSE,0);
702 slider = gtk_scale_button_new(GTK_ICON_SIZE_SMALL_TOOLBAR, 1, 17, 1, slider_icons);
703 gtk_widget_set_tooltip_text(slider, "Zoom");
704 gtk_scale_button_set_value(GTK_SCALE_BUTTON(slider), (gdouble)zoom);
706 progress = gtk_progress_bar_new();
707 state = gtk_label_new("");
708 gtk_label_set_justify(GTK_LABEL(state), GTK_JUSTIFY_CENTER);
710 gtk_box_pack_start(GTK_BOX(status), GTK_WIDGET(slider), FALSE, FALSE, 0);
711 gtk_box_pack_start(GTK_BOX(status), GTK_WIDGET(state), FALSE, FALSE, 5);
712 gtk_box_pack_end(GTK_BOX(status), GTK_WIDGET(progress), FALSE, FALSE, 0);
713 gtk_box_pack_end(GTK_BOX(vbox),GTK_WIDGET(status), FALSE, FALSE, 0);
715 layer = champlain_marker_layer_new();
716 champlain_view_add_layer(view, CHAMPLAIN_LAYER(layer));
718 pgd->icon_layer = layer;
719 pgd->gps_view = CLUTTER_ACTOR(view);
721 pgd->progress = progress;
722 pgd->slider = slider;
725 bar_pane_gps_set_map_source(pgd, map_id);
727 g_object_set(G_OBJECT(view), "kinetic-mode", TRUE,
729 "keep-center-on-resize", TRUE,
730 /* This seems to be broken, https://bugzilla.gnome.org/show_bug.cgi?id=596419
733 "zoom-on-double-click", FALSE,
734 "max-zoom-level", 17,
737 champlain_view_center_on(view, latitude, longitude);
738 pgd->centre_map_checked = TRUE;
739 g_object_set_data(G_OBJECT(pgd->widget), "pane_data", pgd);
740 g_signal_connect(G_OBJECT(pgd->widget), "destroy", G_CALLBACK(bar_pane_gps_destroy), pgd);
742 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
744 gtk_widget_set_size_request(pgd->widget, -1, height);
746 clutter_set_motion_events_enabled(TRUE);
747 g_signal_connect(G_OBJECT(gpswidget), "button_press_event", G_CALLBACK(bar_pane_gps_map_keypress_cb), pgd);
748 g_signal_connect(pgd->gps_view, "notify::state", G_CALLBACK(bar_pane_gps_view_state_changed_cb), pgd);
749 g_signal_connect(pgd->gps_view, "notify::zoom-level", G_CALLBACK(bar_pane_gps_view_state_changed_cb), pgd);
750 g_signal_connect(G_OBJECT(slider), "value-changed", G_CALLBACK(bar_pane_gps_slider_changed_cb), pgd);
752 file_data_register_notify_func(bar_pane_gps_notify_cb, pgd, NOTIFY_PRIORITY_LOW);
754 pgd->create_markers_id = 0;
755 pgd->enable_markers_checked = TRUE;
756 pgd->centre_map_checked = TRUE;
761 GtkWidget *bar_pane_gps_new_from_config(const gchar **attribute_names, const gchar **attribute_values)
763 gchar *title = g_strdup(_("GPS Map"));
764 gchar *map_id = NULL;
765 gboolean expanded = TRUE;
770 /* Latitude and longitude are stored in the config file as an integer of
771 * (actual value * 1,000,000). There is no READ_DOUBLE utilty function.
773 gint int_latitude = 54000000;
774 gint int_longitude = -4000000;
775 gchar *id = g_strdup("gps");
778 while (*attribute_names)
780 const gchar *option = *attribute_names++;
781 const gchar *value = *attribute_values++;
783 if (READ_CHAR_FULL("title", title))
785 if (READ_CHAR_FULL("map-id", map_id))
787 /* There is a bug in the libchamplain libraries which prevents correct
788 * initialisation if the zoom level starts higher than 8
790 if (READ_INT_CLAMP_FULL("zoom-level", zoom, 1, 8))
792 if (READ_INT_CLAMP_FULL("latitude", int_latitude, -90000000, +90000000))
794 if (READ_INT_CLAMP_FULL("longitude", int_longitude, -90000000, +90000000))
796 if (READ_BOOL_FULL("expanded", expanded))
798 if (READ_INT_FULL("height", height))
800 if (READ_CHAR_FULL("id", id))
803 log_printf("unknown attribute %s = %s\n", option, value);
806 bar_pane_translate_title(PANE_COMMENT, id, &title);
807 latitude = int_latitude / 1000000;
808 longitude = int_longitude / 1000000;
809 ret = bar_pane_gps_new(id, title, map_id, zoom, latitude, longitude, expanded, height);
816 void bar_pane_gps_update_from_config(GtkWidget *pane, const gchar **attribute_names,
817 const gchar **attribute_values)
821 gint int_longitude, int_latitude;
822 gdouble longitude, latitude;
824 pgd = g_object_get_data(G_OBJECT(pane), "pane_data");
830 while (*attribute_names)
832 const gchar *option = *attribute_names++;
833 const gchar *value = *attribute_values++;
835 if (READ_CHAR_FULL("title", title))
837 if (READ_CHAR_FULL("map-id", pgd->map_source))
839 if (READ_BOOL_FULL("expanded", pgd->pane.expanded))
841 if (READ_INT_FULL("height", pgd->height))
843 if (READ_CHAR_FULL("id", pgd->pane.id))
845 if (READ_INT_CLAMP_FULL("zoom-level", zoom, 1, 8))
847 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "zoom-level", zoom, NULL);
850 if (READ_INT_CLAMP_FULL("longitude", int_longitude, -90000000, +90000000))
852 longitude = int_longitude / 1000000;
853 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "longitude", longitude, NULL);
856 if (READ_INT_CLAMP_FULL("latitude", int_latitude, -90000000, +90000000))
858 latitude = int_latitude / 1000000;
859 g_object_set(G_OBJECT(CHAMPLAIN_VIEW(pgd->gps_view)), "latitude", latitude, NULL);
862 log_printf("unknown attribute %s = %s\n", option, value);
867 bar_pane_translate_title(PANE_COMMENT, pgd->pane.id, &title);
868 gtk_label_set_text(GTK_LABEL(pgd->pane.title), title);
872 gtk_widget_set_size_request(pgd->widget, -1, pgd->height);
873 bar_update_expander(pane);
879 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */