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 all 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
7 changes: 4 additions & 3 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2015-2018 elementary LLC. (https://elementary.io)
* Copyright (c) 2015-2023 elementary LLC. (https://elementary.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
Expand All @@ -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
14 changes: 11 additions & 3 deletions src/Services/ObexManager.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2015-2018 elementary LLC. (https://elementary.io)
* Copyright (c) 2015-2023 elementary LLC. (https://elementary.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
Expand All @@ -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> active_transfers;

construct {
active_transfers = new GLib.HashTable <BluetoothIndicator.Services.Obex.Transfer, string> (GLib.direct_hash, GLib.direct_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);
active_transfers[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 (active_transfers.contains (transfer)) {
active_transfers.remove (transfer);
}
transfer_removed (transfer);
}
}
}
29 changes: 17 additions & 12 deletions src/Widgets/Device.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2015-2018 elementary LLC. (https://elementary.io)
* Copyright (c) 2015-2023 elementary LLC. (https://elementary.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
Expand All @@ -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,15 +33,16 @@ 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);
obex_manager.transfer_added.connect (on_obex_transfer_added);
obex_manager.transfer_removed.connect (on_obex_transfer_removed);
obex_manager.transfer_active.connect (on_obex_transfer_active);

name_label = new Gtk.Label (null) {
halign = Gtk.Align.START,
Expand Down Expand Up @@ -126,25 +128,28 @@ public class BluetoothIndicator.Widgets.Device : Gtk.ListBoxRow {
update_status ();
get_style_context ().add_class (Gtk.STYLE_CLASS_MENUITEM);
selectable = false;
obex_manager.active_transfers.foreach ((transfer, address)=> {
on_obex_transfer_added (address, transfer);
});
}

private void transfer_removed (BluetoothIndicator.Services.Obex.Transfer transfer) {
private void on_obex_transfer_removed (BluetoothIndicator.Services.Obex.Transfer transfer) {
hide_action ();
}

private void transfer_active (string address) {
private void on_obex_transfer_active (string address) {
if (address == device.address) {
tranfer_progress ();
update_transfer_progress ();
}
}

private void transfer_added (string address, BluetoothIndicator.Services.Obex.Transfer transfer) {
private void on_obex_transfer_added (string address, BluetoothIndicator.Services.Obex.Transfer transfer) {
if (address == device.address) {
this.transfer = transfer;
}
}

private void tranfer_progress () {
private void update_transfer_progress () {
switch (transfer.status) {
case "error":
hide_action ();
Expand Down
11 changes: 8 additions & 3 deletions src/Widgets/PopoverWidget.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2015-2021 elementary LLC. (https://elementary.io)
* Copyright (c) 2015-2023 elementary LLC. (https://elementary.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
Expand All @@ -20,15 +20,20 @@ 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 +166,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