Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BtScan: rewrite as granite.messagedialog, gtk4 prep #14

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class BluetoothApp : Gtk.Application {

if (files.length > 0) {
if (bt_scan == null) {
bt_scan = new BtScan (this, object_manager);
bt_scan = new BtScan (object_manager);
Idle.add (() => { // Wait for async BtScan initialisation
bt_scan.show_all ();
return Source.REMOVE;
Expand Down
115 changes: 32 additions & 83 deletions src/Dialog/BtScan.vala
Original file line number Diff line number Diff line change
@@ -1,104 +1,62 @@
// -*- 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 <http://www.gnu.org/licenses/>.
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
* SPDX-FileCopyrightText: 2016-2024 elementary, Inc. (https://elementary.io)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* SPDX-License-Identifier: LGPL-3.0-or-later
* SPDX-License-Identifier: GPL-3.0-or-later

Because the previous (deleted) comments says GNU General Public License, and plus this is not a library.

*
* Authored by: Corentin Noël <[email protected]>
* Oleksandr Lynok <[email protected]>
* Torikulhabib <[email protected]>
*/

public class BtScan : Granite.Dialog {
public class BtScan : Granite.MessageDialog {
public signal void send_file (Bluetooth.Device device);
private Gtk.ListBox list_box;

public Bluetooth.ObjectManager manager { get; construct;}

public BtScan (Gtk.Application application, Bluetooth.ObjectManager manager) {
Object (application: application,
manager: manager,
resizable: false
);
private Gtk.ListBox list_box;

public BtScan (Bluetooth.ObjectManager manager) {
Object (manager: manager);
}

construct {
var icon_image = new Gtk.Image.from_icon_name ("io.elementary.bluetooth", Gtk.IconSize.DIALOG) {
valign = Gtk.Align.CENTER,
halign = Gtk.Align.CENTER
};

var title_label = new Gtk.Label (_("Bluetooth File Transfer")) {
max_width_chars = 45,
use_markup = true,
wrap = true,
xalign = 0
};
title_label.get_style_context ().add_class ("primary");

var info_label = new Gtk.Label (_("Select a Bluetooth Device Below to Send Files")) {
max_width_chars = 45,
use_markup = true,
wrap = true,
xalign = 0
};
image_icon = new ThemedIcon ("io.elementary.bluetooth");
primary_text = _("Bluetooth File Transfer");
secondary_text = _("Select a Bluetooth Device Below to Send Files");
resizable = true;

var empty_alert = new Granite.Widgets.AlertView (
var placeholder = new Granite.Widgets.AlertView (
_("No Devices Found"),
_("Please ensure that your devices are visible and ready for pairing."),
""
);
empty_alert.show_all ();
placeholder.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);
list_box.set_placeholder (placeholder);

var scrolled = new Gtk.ScrolledWindow (null, null) {
expand = true,
hexpand = true,
vexpand = true,
child = list_box,
hscrollbar_policy = NEVER,
propagate_natural_height = true,
max_content_height = 350
};
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
};
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
};
frame_device.add (image_label);
frame_device.add (frame);
get_content_area ().add (frame_device);
custom_bin.add (overlay);

manager.device_added.connect (add_device);
manager.device_removed.connect (device_removed);
Expand All @@ -107,11 +65,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 ();
Expand Down Expand Up @@ -151,6 +111,7 @@ public class BtScan : Granite.Dialog {
}
}
}

[CCode (instance_pos = -1)]
private int compare_rows (DeviceRow row1, DeviceRow row2) {
unowned Bluetooth.Device device1 = row1.device;
Expand Down Expand Up @@ -183,16 +144,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);
}
}
}
Loading