static void contact_widget_location_update (EmpathyContactWidget *information) { GHashTable *location; GValue *value; gdouble lat = 0.0, lon = 0.0; gboolean has_position = TRUE; GtkWidget *label; guint row = 0; static const gchar* ordered_geolocation_keys[] = { EMPATHY_LOCATION_TEXT, EMPATHY_LOCATION_URI, EMPATHY_LOCATION_DESCRIPTION, EMPATHY_LOCATION_BUILDING, EMPATHY_LOCATION_FLOOR, EMPATHY_LOCATION_ROOM, EMPATHY_LOCATION_STREET, EMPATHY_LOCATION_AREA, EMPATHY_LOCATION_LOCALITY, EMPATHY_LOCATION_REGION, EMPATHY_LOCATION_COUNTRY, NULL }; int i; const gchar *skey; gboolean display_map = FALSE; if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION)) { gtk_widget_hide (information->vbox_location); return; } location = empathy_contact_get_location (information->contact); if (location == NULL || g_hash_table_size (location) == 0) { gtk_widget_hide (information->vbox_location); return; } value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT); if (value == NULL) has_position = FALSE; else lat = g_value_get_double (value); value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON); if (value == NULL) has_position = FALSE; else lon = g_value_get_double (value); value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP); if (value == NULL) { gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location")); gtk_label_set_markup (GTK_LABEL (information->label_location), loc); g_free (loc); } else { gchar *user_date; gchar *text; gint64 stamp; time_t time_; stamp = g_value_get_int64 (value); time_ = stamp; user_date = empathy_time_to_string_relative (time_); text = g_strconcat ( _("<b>Location</b>, "), user_date, NULL); gtk_label_set_markup (GTK_LABEL (information->label_location), text); g_free (text); } /* Prepare the location information table */ if (information->table_location != NULL) { gtk_widget_destroy (information->table_location); } information->table_location = gtk_table_new (1, 2, FALSE); gtk_box_pack_start (GTK_BOX (information->subvbox_location), information->table_location, FALSE, FALSE, 5); for (i = 0; (skey = ordered_geolocation_keys[i]); i++) { const gchar* user_label; GValue *gvalue; char *svalue = NULL; gvalue = g_hash_table_lookup (location, (gpointer) skey); if (gvalue == NULL) continue; user_label = location_key_to_label (skey); label = gtk_label_new (user_label); gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); gtk_table_attach (GTK_TABLE (information->table_location), label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0); gtk_widget_show (label); if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE) { gdouble dvalue; dvalue = g_value_get_double (gvalue); svalue = g_strdup_printf ("%f", dvalue); } else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING) { svalue = g_value_dup_string (gvalue); } else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64) { time_t time_; time_ = g_value_get_int64 (value); svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC")); } if (svalue != NULL) { label = gtk_label_new (svalue); gtk_table_attach_defaults (GTK_TABLE (information->table_location), label, 1, 2, row, row + 1); gtk_misc_set_alignment (GTK_MISC (label), 0, 0); gtk_widget_show (label); if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) gtk_label_set_selectable (GTK_LABEL (label), TRUE); } g_free (svalue); row++; } #if HAVE_LIBCHAMPLAIN if (has_position && !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) { /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such * windows */ display_map = TRUE; } #endif if (row > 0) { /* We can display some fields */ gtk_widget_show (information->table_location); } else if (!display_map) { /* Can't display either fields or map */ gtk_widget_hide (information->vbox_location); return; } #if HAVE_LIBCHAMPLAIN if (display_map) { ClutterActor *marker; ChamplainLayer *layer; information->map_view_embed = gtk_champlain_embed_new (); information->map_view = gtk_champlain_embed_get_view ( GTK_CHAMPLAIN_EMBED (information->map_view_embed)); gtk_container_add (GTK_CONTAINER (information->viewport_map), information->map_view_embed); g_object_set (G_OBJECT (information->map_view), "show-license", TRUE, "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC, "zoom-level", 10, NULL); layer = champlain_layer_new (); champlain_view_add_layer (information->map_view, layer); marker = champlain_marker_new_with_text ( empathy_contact_get_name (information->contact), NULL, NULL, NULL); champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon); clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL); champlain_view_center_on (information->map_view, lat, lon); gtk_widget_show_all (information->viewport_map); } #endif gtk_widget_show (information->vbox_location); }
static void contact_widget_location_update (EmpathyContactWidget *information) { GHashTable *location; GValue *value; gdouble lat = 0.0, lon = 0.0; gboolean has_position = TRUE; GtkWidget *label; guint row = 0; GHashTableIter iter; gpointer key, pvalue; if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION)) { gtk_widget_hide (information->vbox_location); return; } location = empathy_contact_get_location (information->contact); if (location == NULL || g_hash_table_size (location) == 0) { gtk_widget_hide (information->vbox_location); return; } value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT); if (value == NULL) has_position = FALSE; else lat = g_value_get_double (value); value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON); if (value == NULL) has_position = FALSE; else lon = g_value_get_double (value); value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP); if (value == NULL) gtk_label_set_markup (GTK_LABEL (information->label_location), _("<b>Location</b>")); else { gchar *user_date; gchar *text; gint64 stamp; time_t time; stamp = g_value_get_int64 (value); time = stamp; user_date = empathy_time_to_string_relative (time); text = g_strconcat ( _("<b>Location</b>, "), user_date, NULL); gtk_label_set_markup (GTK_LABEL (information->label_location), text); g_free (text); } /* Prepare the location information table */ if (information->table_location != NULL) { gtk_widget_destroy (information->table_location); } information->table_location = gtk_table_new (1, 2, FALSE); gtk_box_pack_start (GTK_BOX (information->subvbox_location), information->table_location, FALSE, FALSE, 5); g_hash_table_iter_init (&iter, location); while (g_hash_table_iter_next (&iter, &key, &pvalue)) { const gchar *skey; const gchar* user_label; GValue *gvalue; char *svalue = NULL; skey = (const gchar *) key; user_label = location_key_to_label (skey); gvalue = (GValue *) pvalue; label = gtk_label_new (user_label); gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); gtk_table_attach (GTK_TABLE (information->table_location), label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0); gtk_widget_show (label); if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE) { gdouble dvalue; dvalue = g_value_get_double (gvalue); svalue = g_strdup_printf ("%f", dvalue); } else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING) { svalue = g_value_dup_string (gvalue); } else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64) { time_t time; time = g_value_get_int64 (value); svalue = empathy_time_to_string_utc (time, _("%B %e, %Y at %R UTC")); } if (svalue != NULL) { label = gtk_label_new (svalue); gtk_table_attach_defaults (GTK_TABLE (information->table_location), label, 1, 2, row, row + 1); gtk_misc_set_alignment (GTK_MISC (label), 0, 0); gtk_widget_show (label); } g_free (svalue); row++; } gtk_widget_show (information->table_location); #if HAVE_LIBCHAMPLAIN /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such * windows */ if (has_position && !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) { ClutterActor *marker; ChamplainLayer *layer; information->map_view_embed = gtk_champlain_embed_new (); information->map_view = gtk_champlain_embed_get_view ( GTK_CHAMPLAIN_EMBED (information->map_view_embed)); gtk_container_add (GTK_CONTAINER (information->viewport_map), information->map_view_embed); g_object_set (G_OBJECT (information->map_view), "show-license", FALSE, "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC, NULL); layer = champlain_layer_new (); champlain_view_add_layer (information->map_view, layer); marker = champlain_marker_new_with_text ( empathy_contact_get_name (information->contact), NULL, NULL, NULL); champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon); clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL); champlain_view_center_on (information->map_view, lat, lon); gtk_widget_show_all (information->viewport_map); } #endif gtk_widget_show (information->vbox_location); }
GtkWidget *bar_pane_gps_new(const gchar *id, const gchar *title, const gchar *map_id, const gint zoom, const gdouble latitude, const gdouble longitude, gboolean expanded, gint height) { PaneGPSData *pgd; GtkWidget *vbox, *frame; GtkWidget *gpswidget, *viewport; GtkWidget *status, *state, *progress, *slider; ChamplainLayer *layer; ChamplainView *view; const gchar *slider_list[] = {GTK_STOCK_ZOOM_IN, GTK_STOCK_ZOOM_OUT, NULL}; const gchar **slider_icons = slider_list; pgd = g_new0(PaneGPSData, 1); pgd->pane.pane_set_fd = bar_pane_gps_set_fd; pgd->pane.pane_notify_selection = bar_pane_gps_notify_selection; pgd->pane.pane_event = bar_pane_gps_event; pgd->pane.pane_write_config = bar_pane_gps_write_config; pgd->pane.title = bar_pane_expander_title(title); pgd->pane.id = g_strdup(id); pgd->pane.type = PANE_GPS; pgd->pane.expanded = expanded; pgd->height = height; frame = gtk_frame_new(NULL); vbox = gtk_vbox_new(FALSE, 0); gpswidget = gtk_champlain_embed_new(); view = gtk_champlain_embed_get_view(GTK_CHAMPLAIN_EMBED(gpswidget)); gtk_box_pack_start(GTK_BOX(vbox), gpswidget, TRUE, TRUE, 0); gtk_container_add(GTK_CONTAINER(frame), vbox); status = gtk_hbox_new(FALSE,0); slider = gtk_scale_button_new(GTK_ICON_SIZE_SMALL_TOOLBAR, 1, 17, 1, slider_icons); gtk_widget_set_tooltip_text(slider, "Zoom"); gtk_scale_button_set_value(GTK_SCALE_BUTTON(slider), (gdouble)zoom); progress = gtk_progress_bar_new(); state = gtk_label_new(""); gtk_label_set_justify(GTK_LABEL(state), GTK_JUSTIFY_CENTER); gtk_box_pack_start(GTK_BOX(status), GTK_WIDGET(slider), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(status), GTK_WIDGET(state), FALSE, FALSE, 5); gtk_box_pack_end(GTK_BOX(status), GTK_WIDGET(progress), FALSE, FALSE, 0); gtk_box_pack_end(GTK_BOX(vbox),GTK_WIDGET(status), FALSE, FALSE, 0); layer = champlain_layer_new(); champlain_view_add_layer(view, layer); pgd->icon_layer = layer; pgd->gps_view = CLUTTER_ACTOR(view); pgd->widget = frame; pgd->progress = progress; pgd->slider = slider; pgd->state = state; bar_pane_gps_set_map_source(pgd, map_id); g_object_set(G_OBJECT(view), "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC, "zoom-level", zoom, "keep-center-on-resize", TRUE, /* This seems to be broken, https://bugzilla.gnome.org/show_bug.cgi?id=596419 "decel-rate", 1.0, */ "show-license", TRUE, "zoom-on-double-click", FALSE, "max-zoom-level", 17, "min-zoom-level", 1, NULL); champlain_view_center_on(view, latitude, longitude); pgd->centre_map_checked = TRUE; g_object_set_data(G_OBJECT(pgd->widget), "pane_data", pgd); g_signal_connect(G_OBJECT(pgd->widget), "destroy", G_CALLBACK(bar_pane_gps_destroy), pgd); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); gtk_widget_set_size_request(pgd->widget, -1, height); clutter_set_motion_events_enabled(TRUE); g_signal_connect(G_OBJECT(gpswidget), "button_press_event", G_CALLBACK(bar_pane_gps_map_keypress_cb), pgd); g_signal_connect(pgd->gps_view, "notify::state", G_CALLBACK(bar_pane_gps_view_state_changed_cb), pgd); g_signal_connect(pgd->gps_view, "notify::zoom-level", G_CALLBACK(bar_pane_gps_view_state_changed_cb), pgd); g_signal_connect(G_OBJECT(slider), "value-changed", G_CALLBACK(bar_pane_gps_slider_changed_cb), pgd); file_data_register_notify_func(bar_pane_gps_notify_cb, pgd, NOTIFY_PRIORITY_LOW); pgd->create_markers_id = 0; pgd->enable_markers_checked = TRUE; pgd->centre_map_checked = TRUE; return pgd->widget; }