-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
danirabbit
wants to merge
2
commits into
main
Choose a base branch
from
danirabbit/btscan-gtk4prep
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+33
−84
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
* | ||
* 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); | ||
|
@@ -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 (); | ||
|
@@ -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; | ||
|
@@ -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); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the previous (deleted) comments says
GNU General Public License
, and plus this is not a library.