<commit_before> /* Copyright 2009-2012 Yorba Foundation
 *
 * This software is licensed under the GNU LGPL (version 2.1 or later).
 * See the COPYING file in this distribution.
 */

private class PositionMarker : Object {
    public PositionMarker(MapWidget map_widget, DataView view, Champlain.Marker marker) {
        this.view = view;
        // marker.reactive = true;
        marker.selectable = true;
        marker.button_release_event.connect ((event) => {
            if (event.button > 1)
                return true;
            map_widget.select_data_view(this);
            return true;
        });
        marker.enter_event.connect ((event) => {
            map_widget.highlight_data_view(this);
            return true;
        });
        marker.leave_event.connect ((event) => {
            map_widget.unhighlight_data_view(this);
            return true;
        });
        this.marker = marker;
    }

    public Champlain.Marker marker { get; private set; }
    // Geo lookup
    // public string location_country { get; set; }
    // public string location_city { get; set; }
    public unowned DataView view { get; private set; }
}

private class MapWidget : GtkChamplain.Embed {
    private const int DEFAULT_ZOOM_LEVEL = 8;
    private static MapWidget instance = null;
    private Champlain.View map_view = null;
    private Champlain.Scale map_scale = new Champlain.Scale();
    private Champlain.MarkerLayer marker_layer = new Champlain.MarkerLayer();
    private Cogl.Handle marker_cogl_texture = null;
    private Gee.Map<DataView, PositionMarker> position_markers = new Gee.HashMap<DataView, PositionMarker>();
    private unowned Page page = null;

    public static MapWidget get_instance() {
        if (instance == null)
            instance = new MapWidget();
        return instance;
    }

    public void set_page(Page page) {
        this.page = page;
    }

    public void setup_map() {
        // add scale to bottom left corner of the map
        map_view = get_view();
        map_view.add_layer(marker_layer);
        map_scale.connect_view(map_view);
        map_view.bin_layout_add(map_scale, Clutter.BinAlignment.START, Clutter.BinAlignment.END);

        map_view.set_zoom_on_double_click(false);

        Gtk.TargetEntry[] dnd_targets = {
            LibraryWindow.DND_TARGET_ENTRIES[LibraryWindow.TargetType.URI_LIST],
            LibraryWindow.DND_TARGET_ENTRIES[LibraryWindow.TargetType.MEDIA_LIST]
        };
        Gtk.drag_dest_set(this, Gtk.DestDefaults.ALL, dnd_targets,
            Gdk.DragAction.COPY | Gdk.DragAction.LINK | Gdk.DragAction.ASK);
        button_press_event.connect(map_zoom_handler);
        set_size_request(200, 200);

        // Load gdk pixbuf via Resources class
        Gdk.Pixbuf gdk_marker = Resources.get_icon(Resources.ICON_GPS_MARKER);
        try {
            // this is what GtkClutter.Texture.set_from_pixmap does
            var tex = new Clutter.Texture();
            tex.set_from_rgb_data(gdk_marker.get_pixels(),
                                            gdk_marker.get_has_alpha(),
                                            gdk_marker.get_width(),
                                            gdk_marker.get_height(),
                                            gdk_marker.get_rowstride(),
                                            gdk_marker.get_has_alpha() ? 4 : 3,
                                            Clutter.TextureFlags.NONE);
            marker_cogl_texture = tex.get_cogl_texture();
        } catch (GLib.Error e) {
            marker_cogl_texture = null;
        }
    }

    private PositionMarker? create_position_marker(DataView view) {
        DataSource data_source = view.get_source();
        Positionable p = (Positionable) data_source;
        GpsCoords gps_coords = p.get_gps_coords();
        if (gps_coords.has_gps != 0) {
            Champlain.Marker champlain_marker;
            if (marker_cogl_texture == null) {
                // Fall back to the generic champlain marker
                champlain_marker = new Champlain.Point.full(12, { red:10, green:10, blue:255, alpha:255 });
            } else {
                champlain_marker = new Champlain.CustomMarker();
                var t = new Clutter.Texture();
                t.set_cogl_texture(marker_cogl_texture);
                ((Champlain.CustomMarker) champlain_marker).add_actor(t);
            }
            // set_position doesn't work (remains 0.0), we therefor resort to properties
            // champlain_marker.set_position((float) gps_coords.latitude, (float) gps_coords.longitude);

            champlain_marker.latitude = (float) gps_coords.latitude;
            champlain_marker.longitude = (float) gps_coords.longitude;
            return new PositionMarker(this, view, champlain_marker);
        }
        return null;
    }

    public void clear() {
        marker_layer.remove_all();
        position_markers.clear();
    }

    public void add_position_marker(DataView view) {
        PositionMarker? position_marker = null;
        if (view.get_source() is Positionable) {
            position_marker = create_position_marker(view);
        }
        if (position_marker != null) {
            add_marker(position_marker.marker);
            position_markers.set(view, position_marker);
        }
    }

    public void show_position_markers() {
        if (!position_markers.is_empty) {
            if (map_view.get_zoom_level() < DEFAULT_ZOOM_LEVEL) {
                map_view.set_zoom_level(DEFAULT_ZOOM_LEVEL);<commit_msg>Set center anchor on marker, use set_location interface<commit_after> /* Copyright 2009-2012 Yorba Foundation
 *
 * This software is licensed under the GNU LGPL (version 2.1 or later).
 * See the COPYING file in this distribution.
 */

private class PositionMarker : Object {
    public PositionMarker(MapWidget map_widget, DataView view, Champlain.Marker marker) {
        this.view = view;
        // marker.reactive = true;
        marker.selectable = true;
        marker.button_release_event.connect ((event) => {
            if (event.button > 1)
                return true;
            map_widget.select_data_view(this);
            return true;
        });
        marker.enter_event.connect ((event) => {
            map_widget.highlight_data_view(this);
            return true;
        });
        marker.leave_event.connect ((event) => {
            map_widget.unhighlight_data_view(this);
            return true;
        });
        this.marker = marker;
    }

    public Champlain.Marker marker { get; private set; }
    // Geo lookup
    // public string location_country { get; set; }
    // public string location_city { get; set; }
    public unowned DataView view { get; private set; }
}

private class MapWidget : GtkChamplain.Embed {
    private const int DEFAULT_ZOOM_LEVEL = 8;
    private static MapWidget instance = null;
    private Champlain.View map_view = null;
    private Champlain.Scale map_scale = new Champlain.Scale();
    private Champlain.MarkerLayer marker_layer = new Champlain.MarkerLayer();
    private Cogl.Handle marker_cogl_texture = null;
    private Gee.Map<DataView, PositionMarker> position_markers = new Gee.HashMap<DataView, PositionMarker>();
    private unowned Page page = null;

    public static MapWidget get_instance() {
        if (instance == null)
            instance = new MapWidget();
        return instance;
    }

    public void set_page(Page page) {
        this.page = page;
    }

    public void setup_map() {
        // add scale to bottom left corner of the map
        map_view = get_view();
        map_view.add_layer(marker_layer);
        map_scale.connect_view(map_view);
        map_view.bin_layout_add(map_scale, Clutter.BinAlignment.START, Clutter.BinAlignment.END);

        map_view.set_zoom_on_double_click(false);

        Gtk.TargetEntry[] dnd_targets = {
            LibraryWindow.DND_TARGET_ENTRIES[LibraryWindow.TargetType.URI_LIST],
            LibraryWindow.DND_TARGET_ENTRIES[LibraryWindow.TargetType.MEDIA_LIST]
        };
        Gtk.drag_dest_set(this, Gtk.DestDefaults.ALL, dnd_targets,
            Gdk.DragAction.COPY | Gdk.DragAction.LINK | Gdk.DragAction.ASK);
        button_press_event.connect(map_zoom_handler);
        set_size_request(200, 200);

        // Load gdk pixbuf via Resources class
        Gdk.Pixbuf gdk_marker = Resources.get_icon(Resources.ICON_GPS_MARKER);
        try {
            // this is what GtkClutter.Texture.set_from_pixmap does
            var tex = new Clutter.Texture();
            tex.set_from_rgb_data(gdk_marker.get_pixels(),
                                            gdk_marker.get_has_alpha(),
                                            gdk_marker.get_width(),
                                            gdk_marker.get_height(),
                                            gdk_marker.get_rowstride(),
                                            gdk_marker.get_has_alpha() ? 4 : 3,
                                            Clutter.TextureFlags.NONE);
            marker_cogl_texture = tex.get_cogl_texture();
        } catch (GLib.Error e) {
            marker_cogl_texture = null;
        }
    }

    private PositionMarker? create_position_marker(DataView view) {
        DataSource data_source = view.get_source();
        Positionable p = (Positionable) data_source;
        GpsCoords gps_coords = p.get_gps_coords();
        if (gps_coords.has_gps != 0) {
            Champlain.Marker champlain_marker;
            if (marker_cogl_texture == null) {
                // Fall back to the generic champlain marker
                champlain_marker = new Champlain.Point.full(12, { red:10, green:10, blue:255, alpha:255 });
            } else {
                champlain_marker = new Champlain.CustomMarker();
                var t = new Clutter.Texture();
                t.set_cogl_texture(marker_cogl_texture);
                ((Champlain.CustomMarker) champlain_marker).add_actor(t);
            }
            champlain_marker.set_anchor_point_from_gravity(Clutter.Gravity.CENTER);
            champlain_marker.set_location(gps_coords.latitude, gps_coords.longitude);
            return new PositionMarker(this, view, champlain_marker);
        }
        return null;
    }

    public void clear() {
        marker_layer.remove_all();
        position_markers.clear();
    }

    public void add_position_marker(DataView view) {
        PositionMarker? position_marker = null;
        if (view.get_source() is Positionable) {
            position_marker = create_position_marker(view);
        }
        if (position_marker != null) {
            add_marker(position_marker.marker);
            position_markers.set(view, position_marker);
        }
    }

    public void show_position_markers() {
        if (!position_markers.is_empty) {
            if (map_view.get_zoom_level() < DEFAULT_ZOOM_LEVEL) {
                map_view.set_zoom_level(DEFAULT_ZOOM_LEVEL);
{'fraction_non_alphanumeric': 0.08828089375284998, 'fraction_numerical': 0.006201550387596899, 'mean_word_length': 2.1349342481417954, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1503410', 'n_tokens_mistral': 3210, 'n_tokens_neox': 3064, 'n_words': 639}