diff --git a/po/POTFILES b/po/POTFILES index d9ae5b6..d83fbe0 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -1,2 +1,3 @@ src/Application.vala src/MainWindow.vala +src/SearchResultItem.vala diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 611f398..75207e4 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -30,7 +30,6 @@ public class Maps.MainWindow : Adw.ApplicationWindow { }; private int current_busy_reason = 0; private uint search_begin_timeout = 0; - private string unknown_text = _("Unknown"); private ListStore location_store; private Cancellable? search_cancellable = null; @@ -77,6 +76,7 @@ public class Maps.MainWindow : Adw.ApplicationWindow { search_res_list = new Gtk.ListBox () { selection_mode = Gtk.SelectionMode.BROWSE }; + search_res_list.add_css_class (Granite.STYLE_CLASS_RICH_LIST); search_res_list.bind_model (location_store, construct_search_res); search_res_list.set_placeholder (search_placeholder); @@ -288,39 +288,12 @@ public class Maps.MainWindow : Adw.ApplicationWindow { private Gtk.Widget construct_search_res (Object item) { unowned var place = item as Geocode.Place; - var icon = new Gtk.Image.from_gicon (place.icon); - - var place_name_label = new Gtk.Label (place.name) { - halign = Gtk.Align.START - }; - place_name_label.add_css_class ("title-4"); - - string street = place.street ?? unknown_text; - string postal_code = place.postal_code ?? unknown_text; - string town = place.town ?? unknown_text; - - string info_text = "%s, %s, %s".printf (street, postal_code, town); - - var info_label = new Gtk.Label (info_text) { - halign = Gtk.Align.START - }; - info_label.add_css_class ("dim-label"); - - var label_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6); - label_box.append (place_name_label); - label_box.append (info_label); - - var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) { - margin_top = 6, - margin_bottom = 6, - margin_start = 6, - margin_end = 6 + var result_item = new Maps.SearchResultItem () { + place = place }; - box.append (icon); - box.append (label_box); var row = new PlaceListBoxRow (place) { - child = box + child = result_item }; return row; diff --git a/src/SearchResultItem.vala b/src/SearchResultItem.vala new file mode 100644 index 0000000..536c2a4 --- /dev/null +++ b/src/SearchResultItem.vala @@ -0,0 +1,59 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) + * 2018-2025 Ryo Nakano + * 2014-2015 Atlas Developers + */ + +public class Maps.SearchResultItem : Granite.Bin { + private Geocode.Place? _place = null; + public Geocode.Place place { + get { + return _place; + } + + set { + _place = value; + + var street = place.street ?? unknown_text; + var postal_code = place.postal_code ?? unknown_text; + var town = place.town ?? unknown_text; + + image.gicon = place.icon; + name_label.label = place.name; + info_label.label = "%s, %s, %s".printf (street, postal_code, town); + } + } + + private string unknown_text = _("Unknown"); + + private Gtk.Image image; + private Gtk.Label name_label; + private Gtk.Label info_label; + + construct { + image = new Gtk.Image () { + icon_size = LARGE + }; + + name_label = new Gtk.Label (null) { + halign = START + }; + + info_label = new Gtk.Label (null) { + halign = START + }; + info_label.add_css_class (Granite.STYLE_CLASS_SMALL_LABEL); + info_label.add_css_class (Granite.STYLE_CLASS_DIM_LABEL); + + var label_box = new Gtk.Box (VERTICAL, 0); + label_box.append (name_label); + label_box.append (info_label); + + var box = new Gtk.Box (HORIZONTAL, 6); + box.append (image); + box.append (label_box); + + child = box; + } +} diff --git a/src/meson.build b/src/meson.build index 831d6d6..61815a5 100644 --- a/src/meson.build +++ b/src/meson.build @@ -14,8 +14,8 @@ dependencies = [ dependency('gio-2.0'), # Version limitation for GLib.ApplicationFlags.DEFAULT_FLAGS dependency('glib-2.0', version: '>= 2.74'), - # Version limitation for automatic load of Application.css in Granite.init() - dependency('granite-7', version: '>= 7.3.0'), + # Version limitation for Granite.Bin + dependency('granite-7', version: '>= 7.6.0'), dependency('gtk4'), dependency('libadwaita-1'), dependency('libgeoclue-2.0'), @@ -27,6 +27,7 @@ sources = files( 'Define.vala', 'MainWindow.vala', 'MapWidget.vala', + 'SearchResultItem.vala', 'Util.vala', )