Skip to content

Commit

Permalink
[GTK3] Fix changing torrent ownership
Browse files Browse the repository at this point in the history
The change ownership menu item was broken due to Gtk deprecation
changes in commit #bcaaeac.

Fixed by correctly setting the RadioMenuItem group

Refactored to simplify the code
Removed dead or unneeded code

Fixes: https://dev.deluge-torrent.org/ticket/3610
  • Loading branch information
cas-- committed Dec 2, 2023
1 parent 0c1a02d commit fa8d193
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
44 changes: 14 additions & 30 deletions deluge/ui/gtk3/menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,42 +578,26 @@ def on_menuitem_sidebar_owners_toggled(self, widget):
component.get('FilterTreeView').update()

def _on_known_accounts(self, known_accounts):
known_accounts_to_log = []
for account in known_accounts:
account_to_log = {}
for key, value in account.copy().items():
if key == 'password':
value = '*' * 10
account_to_log[key] = value
known_accounts_to_log.append(account_to_log)
log.debug('_on_known_accounts: %s', known_accounts_to_log)
menuitem_change_owner = self.builder.get_object('menuitem_change_owner')
if len(known_accounts) <= 1:
menuitem_change_owner.set_visible(False)
return

self.builder.get_object('menuitem_change_owner').set_visible(True)

self.change_owner_submenu = Gtk.Menu()
self.change_owner_submenu_items = {}
maingroup = Gtk.RadioMenuItem()

self.change_owner_submenu_items[None] = Gtk.RadioMenuItem(maingroup)
self.users_menu = Gtk.Menu()
self.users_menu_items = {}
menu_group = None

for account in known_accounts:
username = account['username']
item = Gtk.RadioMenuItem.new_with_label(maingroup, username)
self.change_owner_submenu_items[username] = item
self.change_owner_submenu.append(item)
item = Gtk.RadioMenuItem.new_with_label(menu_group, username)
menu_group = item.get_group()
item.connect('toggled', self._on_change_owner_toggled, username)
self.users_menu_items[username] = item
self.users_menu.append(item)

self.change_owner_submenu.show_all()
self.change_owner_submenu_items[None].set_active(True)
self.change_owner_submenu_items[None].hide()
self.builder.get_object('menuitem_change_owner').connect(
'activate', self._on_change_owner_submenu_active
)
self.builder.get_object('menuitem_change_owner').set_submenu(
self.change_owner_submenu
)
self.users_menu.show_all()
menuitem_change_owner.set_submenu(self.users_menu)
menuitem_change_owner.set_visible(True)

def _on_known_accounts_fail(self, reason):
self.builder.get_object('menuitem_change_owner').set_visible(False)
Expand All @@ -622,13 +606,13 @@ def _on_change_owner_submenu_active(self, widget):
log.debug('_on_change_owner_submenu_active')
selected = component.get('TorrentView').get_selected_torrents()
if len(selected) > 1:
self.change_owner_submenu_items[None].set_active(True)
self.users_menu_items[None].set_active(True)
return

torrent_owner = component.get('TorrentView').get_torrent_status(selected[0])[
'owner'
]
for username, item in self.change_owner_submenu_items.items():
for username, item in self.users_menu_items.items():
item.set_active(username == torrent_owner)

def _on_change_owner_toggled(self, widget, username):
Expand Down
1 change: 0 additions & 1 deletion deluge/ui/gtk3/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def set_separator(model, _iter, data=None):

# Setup accounts tab lisview
self.accounts_levels_mapping = None
self.accounts_authlevel = self.builder.get_object('accounts_authlevel')
self.accounts_liststore = Gtk.ListStore(str, str, str, int)
self.accounts_liststore.set_sort_column_id(
ACCOUNTS_USERNAME, Gtk.SortType.ASCENDING
Expand Down

0 comments on commit fa8d193

Please sign in to comment.