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

Keep list of active transfers and ensure device widgets show any ongoing transfers #179

Merged
merged 22 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
5 changes: 3 additions & 2 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class BluetoothIndicator.Indicator : Wingpanel.Indicator {
private Widgets.PopoverWidget popover_widget;
private Widgets.DisplayWidget dynamic_icon;
private Services.ObjectManager object_manager;
private Services.ObexManager obex_manager;

public Indicator (bool is_in_session) {
Object (
Expand All @@ -35,7 +36,7 @@ public class BluetoothIndicator.Indicator : Wingpanel.Indicator {

object_manager = new BluetoothIndicator.Services.ObjectManager ();
object_manager.bind_property ("has-object", this, "visible", GLib.BindingFlags.SYNC_CREATE);

obex_manager = new BluetoothIndicator.Services.ObexManager ();
if (object_manager.has_object) {
object_manager.set_last_state.begin ();
}
Expand All @@ -57,7 +58,7 @@ public class BluetoothIndicator.Indicator : Wingpanel.Indicator {

public override Gtk.Widget? get_widget () {
if (popover_widget == null) {
popover_widget = new Widgets.PopoverWidget (object_manager, is_in_session);
popover_widget = new Widgets.PopoverWidget (object_manager, obex_manager, is_in_session);
}

return popover_widget;
Expand Down
12 changes: 10 additions & 2 deletions src/Services/ObexManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public class BluetoothIndicator.Services.ObexManager : Object {
public signal void transfer_removed (BluetoothIndicator.Services.Obex.Transfer transfer);
public signal void transfer_active (string address);
private GLib.DBusObjectManagerClient object_manager;
public GLib.HashTable<BluetoothIndicator.Services.Obex.Transfer, string> transferact;
torikulhabib marked this conversation as resolved.
Show resolved Hide resolved

construct {
transferact = new GLib.HashTable <BluetoothIndicator.Services.Obex.Transfer, string> (GLib.str_hash, GLib.str_equal);
create_manager.begin ();
}

Expand Down Expand Up @@ -75,15 +77,21 @@ public class BluetoothIndicator.Services.ObexManager : Object {
} catch (Error e) {
critical (e.message);
}
transfer_added (session.destination, transfer);
transferact[transfer] = session.destination;
((DBusProxy) transfer).g_properties_changed.connect ((changed, invalid) => {
transfer_active (session.destination);
});
transfer_added (session.destination, transfer);
}
}

private void on_interface_removed (GLib.DBusObject object, GLib.DBusInterface iface) {
if (iface is BluetoothIndicator.Services.Obex.Transfer) {
transfer_removed ((BluetoothIndicator.Services.Obex.Transfer) iface);
unowned BluetoothIndicator.Services.Obex.Transfer transfer = (BluetoothIndicator.Services.Obex.Transfer) iface;
if (transferact.contains (transfer)) {
transferact.remove (transfer);
}
transfer_removed (transfer);
}
}
}
11 changes: 8 additions & 3 deletions src/Widgets/Device.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class BluetoothIndicator.Widgets.Device : Gtk.ListBoxRow {
private const string OBEX_PATH = "/org/bluez/obex/elementary";
public signal void show_device (BluetoothIndicator.Services.Device device);
public BluetoothIndicator.Services.Device device { get; construct; }
public BluetoothIndicator.Services.ObexManager obex_manager { get; construct; }
public BluetoothIndicator.Services.Obex.Transfer transfer;
private Gtk.Label status_label;
private Gtk.Label name_label;
Expand All @@ -32,12 +33,13 @@ public class BluetoothIndicator.Widgets.Device : Gtk.ListBoxRow {
private Gtk.Revealer progress_revealer;
private Gtk.ProgressBar progressbar;

public Device (BluetoothIndicator.Services.Device device) {
Object (device: device);
public Device (BluetoothIndicator.Services.Device device, BluetoothIndicator.Services.ObexManager obex_manager) {
Object (device: device,
obex_manager: obex_manager
);
}

construct {
var obex_manager = new BluetoothIndicator.Services.ObexManager ();
obex_manager.transfer_added.connect (transfer_added);
obex_manager.transfer_removed.connect (transfer_removed);
obex_manager.transfer_active.connect (transfer_active);
Expand Down Expand Up @@ -126,6 +128,9 @@ public class BluetoothIndicator.Widgets.Device : Gtk.ListBoxRow {
update_status ();
get_style_context ().add_class (Gtk.STYLE_CLASS_MENUITEM);
selectable = false;
obex_manager.transferact.foreach ((transfer, address)=> {
transfer_added (address, transfer);
});
}

private void transfer_removed (BluetoothIndicator.Services.Obex.Transfer transfer) {
Expand Down
6 changes: 4 additions & 2 deletions src/Widgets/PopoverWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ public class BluetoothIndicator.Widgets.PopoverWidget : Gtk.Box {
public signal void discovery_requested ();

public BluetoothIndicator.Services.ObjectManager object_manager { get; construct; }
public BluetoothIndicator.Services.ObexManager obex_manager { get; construct; }
public bool is_in_session { get; construct; }

private Granite.SwitchModelButton main_switch;
private Gtk.ListBox devices_list;
private Gtk.Revealer revealer;

public PopoverWidget (BluetoothIndicator.Services.ObjectManager object_manager, bool is_in_session) {
public PopoverWidget (BluetoothIndicator.Services.ObjectManager object_manager, BluetoothIndicator.Services.ObexManager obex_manager, bool is_in_session) {
Object (
object_manager: object_manager,
obex_manager: obex_manager,
is_in_session: is_in_session
);
}
Expand Down Expand Up @@ -161,7 +163,7 @@ public class BluetoothIndicator.Widgets.PopoverWidget : Gtk.Box {
}

private void add_device (BluetoothIndicator.Services.Device device) {
var device_widget = new Widgets.Device (device);
var device_widget = new Widgets.Device (device, obex_manager);
devices_list.add (device_widget);
devices_list.show_all ();

Expand Down