From 833d31abaaff983a15b8169b55f000949de19f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Wed, 26 Feb 2025 14:45:35 -0800 Subject: [PATCH 1/3] ScanDialog: GTK4 prep --- po/POTFILES | 2 +- src/Application.vala | 4 +- src/Dialog/{BtScan.vala => ScanDialog.vala} | 115 ++++++++------------ src/meson.build | 2 +- 4 files changed, 52 insertions(+), 71 deletions(-) rename src/Dialog/{BtScan.vala => ScanDialog.vala} (57%) diff --git a/po/POTFILES b/po/POTFILES index ec7df26..f3a9db5 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -1,6 +1,6 @@ src/Application.vala src/Dialog/BtReceiver.vala -src/Dialog/BtScan.vala +src/Dialog/ScanDialog.vala src/Dialog/BtSender.vala src/Dialog/DeviceRow.vala src/Services/Adapter.vala diff --git a/src/Application.vala b/src/Application.vala index 3b29234..740decc 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -32,7 +32,7 @@ public class BluetoothApp : Gtk.Application { public Bluetooth.Obex.Transfer transfer; public BtReceiver bt_receiver; public BtSender bt_sender; - public BtScan bt_scan = null; + public ScanDialog bt_scan = null; public GLib.List bt_receivers; public GLib.List bt_senders; public static bool silent = true; @@ -68,7 +68,7 @@ public class BluetoothApp : Gtk.Application { private void scan_and_send_files (File[] files) { if (bt_scan == null) { - bt_scan = new BtScan (this, object_manager); + bt_scan = new ScanDialog (this, object_manager); Idle.add (() => { // Wait for async BtScan initialisation bt_scan.show_all (); return Source.REMOVE; diff --git a/src/Dialog/BtScan.vala b/src/Dialog/ScanDialog.vala similarity index 57% rename from src/Dialog/BtScan.vala rename to src/Dialog/ScanDialog.vala index 0eaf3c9..b5babd5 100644 --- a/src/Dialog/BtScan.vala +++ b/src/Dialog/ScanDialog.vala @@ -1,31 +1,20 @@ -// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*- -/*- - * Copyright (c) 2016-2018 elementary LLC. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2016-2024 elementary, Inc. (https://elementary.io) * * Authored by: Corentin Noël * Oleksandr Lynok * Torikulhabib */ -public class BtScan : Granite.Dialog { +public class ScanDialog : Granite.Dialog { public signal void send_file (Bluetooth.Device device); + + public Bluetooth.ObjectManager manager { get; construct; } + private Gtk.ListBox list_box; - public Bluetooth.ObjectManager manager { get; construct;} - public BtScan (Gtk.Application application, Bluetooth.ObjectManager manager) { + public ScanDialog (Gtk.Application application, Bluetooth.ObjectManager manager) { Object (application: application, manager: manager, resizable: false @@ -34,8 +23,8 @@ public class BtScan : Granite.Dialog { construct { var icon_image = new Gtk.Image.from_icon_name ("io.elementary.bluetooth", Gtk.IconSize.DIALOG) { - valign = Gtk.Align.CENTER, - halign = Gtk.Align.CENTER + valign = CENTER, + halign = CENTER }; var title_label = new Gtk.Label (_("Bluetooth File Transfer")) { @@ -59,46 +48,48 @@ public class BtScan : Granite.Dialog { "" ); empty_alert.show_all (); + list_box = new Gtk.ListBox () { activate_on_single_click = true, - selection_mode = Gtk.SelectionMode.BROWSE + selection_mode = BROWSE }; list_box.set_sort_func ((Gtk.ListBoxSortFunc) compare_rows); - list_box.set_header_func ((Gtk.ListBoxUpdateHeaderFunc) title_rows); list_box.set_placeholder (empty_alert); var scrolled = new Gtk.ScrolledWindow (null, null) { - expand = true, + child = list_box, + hexpand = true, + vexpand = true, + hscrollbar_policy = NEVER, + margin_end = 10, + margin_start = 10, + max_content_height = 350, + propagate_natural_height = true }; - scrolled.add (list_box); + scrolled.get_style_context ().add_class (Gtk.STYLE_CLASS_FRAME); - var overlay = new Gtk.Overlay (); - overlay.add (scrolled); + var overlay = new Gtk.Overlay () { + child = scrolled + }; var overlaybar = new Granite.Widgets.OverlayBar (overlay) { label = _("Discovering") }; - var frame = new Gtk.Frame (null) { - margin_left = 10, - margin_right = 10, - width_request = 350, - height_request = 350 - }; - frame.add (overlay); - var image_label = new Gtk.Grid () { - margin_bottom = 5 + var image_grid = new Gtk.Grid () { + margin_bottom = 6 }; - image_label.attach (icon_image, 0, 0, 1, 2); - image_label.attach (title_label, 1, 0, 1, 1); - image_label.attach (info_label, 1, 1, 1, 1); - var frame_device = new Gtk.Grid () { - orientation = Gtk.Orientation.VERTICAL, - valign = Gtk.Align.CENTER + image_grid.attach (icon_image, 0, 0, 1, 2); + image_grid.attach (title_label, 1, 0); + image_grid.attach (info_label, 1, 1); + + var content_box = new Gtk.Box (VERTICAL, 0) { + valign = CENTER }; - frame_device.add (image_label); - frame_device.add (frame); - get_content_area ().add (frame_device); + content_box.add (image_grid); + content_box.add (overlay); + + get_content_area ().add (content_box); manager.device_added.connect (add_device); manager.device_removed.connect (device_removed); @@ -107,11 +98,13 @@ public class BtScan : Granite.Dialog { }); add_button (_("Close"), Gtk.ResponseType.CLOSE); + response.connect ((response_id) => { manager.stop_discovery.begin (); destroy (); }); } + public override void show () { base.show (); var devices = manager.get_devices (); @@ -122,21 +115,20 @@ public class BtScan : Granite.Dialog { } private void add_device (Bluetooth.Device device) { - bool device_exist = false; - foreach (var row in list_box.get_children ()) { - if (((DeviceRow) row).device == device) { - device_exist = true; + for (int i = 0; list_box.get_row_at_index (i) != null; i++) { + if (((DeviceRow) list_box.get_row_at_index (i)).device == device) { + return; } } - if (device_exist) { - return; - } + var row = new DeviceRow (device, manager.get_adapter_from_path (device.adapter)); list_box.add (row); + if (list_box.get_selected_row () == null) { list_box.select_row (row); list_box.row_activated (row); } + row.send_file.connect ((device)=> { manager.stop_discovery.begin (); send_file (device); @@ -144,13 +136,14 @@ public class BtScan : Granite.Dialog { } public void device_removed (Bluetooth.Device device) { - foreach (var row in list_box.get_children ()) { - if (((DeviceRow) row).device == device) { - list_box.remove (row); + for (int i = 0; list_box.get_row_at_index (i) != null; i++) { + if (((DeviceRow) list_box.get_row_at_index (i)).device == device) { + list_box.remove (list_box.get_row_at_index (i)); break; } } } + [CCode (instance_pos = -1)] private int compare_rows (DeviceRow row1, DeviceRow row2) { unowned Bluetooth.Device device1 = row1.device; @@ -183,16 +176,4 @@ public class BtScan : Granite.Dialog { var name2 = device2.name ?? device2.address; return name1.collate (name2); } - [CCode (instance_pos = -1)] - private void title_rows (DeviceRow row1, DeviceRow? row2) { - if (row2 == null) { - var label = new Gtk.Label (_("Available Devices")); - label.xalign = 0; - label.margin = 3; - label.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL); - row1.set_header (label); - } else { - row1.set_header (null); - } - } } diff --git a/src/meson.build b/src/meson.build index a1509b8..bde6baa 100644 --- a/src/meson.build +++ b/src/meson.build @@ -9,7 +9,7 @@ executable( 'Services' / 'Transfer.vala', 'Dialog' / 'BtReceiver.vala', 'Dialog' / 'BtSender.vala', - 'Dialog' / 'BtScan.vala', + 'Dialog' / 'ScanDialog.vala', 'Dialog' / 'DeviceRow.vala', dependencies : [ granite_dep, From 39506fcc23b88728b02133026e9f9343d8cd4833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Wed, 26 Feb 2025 14:50:02 -0800 Subject: [PATCH 2/3] Fix more whitespace --- src/Dialog/ScanDialog.vala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Dialog/ScanDialog.vala b/src/Dialog/ScanDialog.vala index b5babd5..b52de61 100644 --- a/src/Dialog/ScanDialog.vala +++ b/src/Dialog/ScanDialog.vala @@ -15,9 +15,10 @@ public class ScanDialog : Granite.Dialog { private Gtk.ListBox list_box; public ScanDialog (Gtk.Application application, Bluetooth.ObjectManager manager) { - Object (application: application, - manager: manager, - resizable: false + Object ( + application: application, + manager: manager, + resizable: false ); } From baa380bb2ca2c154788879f493fe17114935ed67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sat, 1 Mar 2025 03:26:14 +0000 Subject: [PATCH 3/3] Update ScanDialog.vala Co-authored-by: Ryo Nakano --- src/Dialog/ScanDialog.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dialog/ScanDialog.vala b/src/Dialog/ScanDialog.vala index b52de61..ecffcf0 100644 --- a/src/Dialog/ScanDialog.vala +++ b/src/Dialog/ScanDialog.vala @@ -1,6 +1,6 @@ /* * SPDX-License-Identifier: GPL-3.0-or-later - * SPDX-FileCopyrightText: 2016-2024 elementary, Inc. (https://elementary.io) + * SPDX-FileCopyrightText: 2016-2025 elementary, Inc. (https://elementary.io) * * Authored by: Corentin Noël * Oleksandr Lynok