Fix crash if canceling the icon theme download while covers are downloading

This commit is contained in:
Kovid Goyal 2019-10-21 08:16:32 +05:30
parent 39e28b3fdb
commit efb6405ff1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -483,10 +483,14 @@ def get_cover(metadata):
return cached or b'' return cached or b''
def get_covers(themes, callback, num_of_workers=8): def get_covers(themes, dialog, num_of_workers=8):
items = Queue() items = Queue()
tuple(map(items.put, themes)) tuple(map(items.put, themes))
def callback(metadata, x):
if not sip.isdeleted(dialog) and not dialog.dialog_closed:
dialog.cover_downloaded.emit(metadata, x)
def run(): def run():
while True: while True:
try: try:
@ -579,12 +583,17 @@ class ChooseTheme(Dialog):
except Exception: except Exception:
self.current_theme = None self.current_theme = None
Dialog.__init__(self, _('Choose an icon theme'), 'choose-icon-theme-dialog', parent) Dialog.__init__(self, _('Choose an icon theme'), 'choose-icon-theme-dialog', parent)
self.finished.connect(self.on_finish)
self.dialog_closed = False
self.themes_downloaded.connect(self.show_themes, type=Qt.QueuedConnection) self.themes_downloaded.connect(self.show_themes, type=Qt.QueuedConnection)
self.cover_downloaded.connect(self.set_cover, type=Qt.QueuedConnection) self.cover_downloaded.connect(self.set_cover, type=Qt.QueuedConnection)
self.keep_downloading = True self.keep_downloading = True
self.commit_changes = None self.commit_changes = None
self.new_theme_title = None self.new_theme_title = None
def on_finish(self):
self.dialog_closed = True
def sizeHint(self): def sizeHint(self):
desktop = QApplication.instance().desktop() desktop = QApplication.instance().desktop()
h = desktop.availableGeometry(self).height() h = desktop.availableGeometry(self).height()
@ -707,7 +716,7 @@ class ChooseTheme(Dialog):
for theme in self.themes: for theme in self.themes:
theme['usage'] = self.usage.get(theme['name'], 0) theme['usage'] = self.usage.get(theme['name'], 0)
self.re_sort() self.re_sort()
get_covers(self.themes, self.cover_downloaded.emit) get_covers(self.themes, self)
def __iter__(self): def __iter__(self):
for i in range(self.theme_list.count()): for i in range(self.theme_list.count()):