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

Refactoring for the New Version Dialog #7101

Merged
merged 1 commit into from Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tribler/gui/i18n/pt_BR.ts
Expand Up @@ -644,7 +644,7 @@ If unsure, press 'No'. You will be able to remove those directories fr
</message>
<message>
<location filename="../tribler_window.py" line="595"/>
<source>Version %s of Tribler is available.Do you want to visit the website to download the newest version?</source>
<source>Version %s of Tribler is available. Do you want to visit the website to download the newest version?</source>
<translation>Versão %s disponível. Quer visitar o site para baixar a versão mais recente?</translation>
</message>
<message>
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/gui/i18n/ru_RU.ts
Expand Up @@ -632,7 +632,7 @@ If unsure, press &apos;No&apos;. You will be able to remove those directories fr
</message>
<message>
<location filename="../tribler_window.py" line="649"/>
<source>Version %s of Tribler is available.Do you want to visit the website to download the newest version?</source>
<source>Version %s of Tribler is available. Do you want to visit the website to download the newest version?</source>
drew2a marked this conversation as resolved.
Show resolved Hide resolved
<translation>Доступна новая версия Tribler: %s. Перейти к веб-сайту разработчиков чтобы загрузить её?</translation>
</message>
<message>
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/gui/i18n/zh_CN.ts
Expand Up @@ -638,7 +638,7 @@ If unsure, press &apos;No&apos;. You will be able to remove those directories fr
</message>
<message>
<location filename="../tribler_window.py" line="595"/>
<source>Version %s of Tribler is available.Do you want to visit the website to download the newest version?</source>
<source>Version %s of Tribler is available. Do you want to visit the website to download the newest version?</source>
<translation>Tribler 版本 %s 可用。你想要访问网站下载最新版本吗?</translation>
</message>
<message>
Expand Down
35 changes: 1 addition & 34 deletions src/tribler/gui/tribler_window.py
Expand Up @@ -206,7 +206,6 @@ def __init__(
self.dialog = None
self.create_dialog = None
self.chosen_dir = None
self.new_version_dialog = None
self.new_version_dialog_postponed = False
self.start_download_dialog_active = False
self.selected_torrent_files = []
Expand Down Expand Up @@ -731,39 +730,7 @@ def on_add_button_pressed(channel_id):
self.window().add_to_channel_dialog.show_dialog(on_add_button_pressed, confirm_button_text="Add torrent")

def on_new_version_available(self, version):
if version == str(self.gui_settings.value('last_reported_version')):
return
if self.new_version_dialog_postponed:
return

# To prevent multiple dialogs on top of each other,
# close any existing dialog first.
if self.new_version_dialog:
self.new_version_dialog.close_dialog()
self.new_version_dialog = None

self.new_version_dialog = ConfirmationDialog(
self,
tr("New version available"),
tr("Version %s of Tribler is available.Do you want to visit the " "website to download the newest version?")
% version,
[(tr("IGNORE"), BUTTON_TYPE_NORMAL), (tr("LATER"), BUTTON_TYPE_NORMAL), (tr("OK"), BUTTON_TYPE_NORMAL)],
)
connect(self.new_version_dialog.button_clicked, lambda action: self.on_new_version_dialog_done(version, action))
self.new_version_dialog.show()

def on_new_version_dialog_done(self, version, action):
if action == 0: # ignore
self.gui_settings.setValue("last_reported_version", version)
elif action == 1: # postpone
self.new_version_dialog_postponed = True
elif action == 2: # ok
import webbrowser

webbrowser.open("https://tribler.org")
if self.new_version_dialog:
self.new_version_dialog.close_dialog()
self.new_version_dialog = None
self.upgrade_manager.on_new_version_available(tribler_window=self, new_version=version)

def on_search_text_change(self, text):
# We do not want to bother the database on petty 1-character queries
Expand Down
45 changes: 43 additions & 2 deletions src/tribler/gui/upgrade_manager.py
@@ -1,14 +1,22 @@
from __future__ import annotations

import logging
from typing import List
import webbrowser
from typing import List, Optional, TYPE_CHECKING

from PyQt5.QtCore import QObject, QThread, pyqtSignal
from PyQt5.QtWidgets import QMessageBox

from tribler.core.upgrade.version_manager import TriblerVersion, VersionHistory
from tribler.gui.defs import BUTTON_TYPE_NORMAL
from tribler.gui.dialogs.confirmationdialog import ConfirmationDialog
from tribler.gui.exceptions import UpgradeError
from tribler.gui.utilities import connect, format_size, tr
from tribler.run_tribler_upgrader import upgrade_state_dir

if TYPE_CHECKING:
from tribler.gui.tribler_window import TriblerWindow


class StateDirUpgradeWorker(QObject):
finished = pyqtSignal(object)
Expand Down Expand Up @@ -55,12 +63,45 @@ class UpgradeManager(QObject):
def __init__(self, version_history: VersionHistory):
QObject.__init__(self, None)

self.version_history = version_history
self._logger = logging.getLogger(self.__class__.__name__)

self.version_history = version_history
self.new_version_dialog_postponed: bool = False
self.dialog: Optional[ConfirmationDialog] = None

self._upgrade_worker = None
self._upgrade_thread = None

def on_new_version_available(self, tribler_window: TriblerWindow, new_version: str):
last_reported_version = str(tribler_window.gui_settings.value('last_reported_version'))
if new_version == last_reported_version:
return

if self.new_version_dialog_postponed or self.dialog:
return

self.dialog = ConfirmationDialog(
tribler_window,
tr("New version available"),
tr("Version %s of Tribler is available. Do you want to visit the website to download the newest version?")
% new_version,
[(tr("IGNORE"), BUTTON_TYPE_NORMAL), (tr("LATER"), BUTTON_TYPE_NORMAL), (tr("OK"), BUTTON_TYPE_NORMAL)],
)

def on_button_clicked(click_result: int):
self.dialog.close_dialog()
self.dialog = None

if click_result == 0: # ignore
tribler_window.gui_settings.setValue("last_reported_version", new_version)
elif click_result == 1: # later
self.new_version_dialog_postponed = True
elif click_result == 2: # ok
webbrowser.open("https://tribler.org")

connect(self.dialog.button_clicked, on_button_clicked)
self.dialog.show()

def _show_question_box(self, title, body, additional_text, default_button=None):
message_box = QMessageBox()
message_box.setIcon(QMessageBox.Question)
Expand Down