From a47af86d64a22964174e72e1cec052c06cb7eccc Mon Sep 17 00:00:00 2001 From: samuel-w Date: Mon, 18 Jan 2021 02:32:58 -0600 Subject: [PATCH] Add option to disable exit dialog. By @samuel-w (#681) --- src/vorta/models.py | 14 ++++++++++++-- src/vorta/views/main_window.py | 26 +++++++++++++++++--------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/vorta/models.py b/src/vorta/models.py index ff5a236b..362507ae 100644 --- a/src/vorta/models.py +++ b/src/vorta/models.py @@ -14,7 +14,7 @@ from playhouse.migrate import SqliteMigrator, migrate from vorta.i18n import trans_late -from vorta.utils import slugify +from vorta.utils import slugify, is_system_tray_available SCHEMA_VERSION = 16 @@ -249,6 +249,16 @@ def get_misc_settings(): 'Include pre-release versions when checking for updates') }, ] + if not is_system_tray_available(): + settings += [{ + 'key': 'enable_background_question', 'value': True, 'type': 'checkbox', + 'label': trans_late('settings', + 'Display background exit dialog') + }, + { + 'key': 'disable_background_state', 'value': False, 'type': 'internal', + 'label': 'Previous background exit button state' + }] return settings @@ -358,7 +368,7 @@ def init_db(con=None): with db.atomic(): size = 1000 for i in range(0, len(data), size): - ArchiveModel.insert_many(data[i:i + size], fields=fields).execute() + ArchiveModel.insert_many(data[i: i + size], fields=fields).execute() _apply_schema_update(current_schema, 13) diff --git a/src/vorta/views/main_window.py b/src/vorta/views/main_window.py index 514f62b0..890fa2a4 100644 --- a/src/vorta/views/main_window.py +++ b/src/vorta/views/main_window.py @@ -1,9 +1,8 @@ from PyQt5 import QtCore, uic -from PyQt5.QtWidgets import QShortcut, QMessageBox +from PyQt5.QtWidgets import QShortcut, QMessageBox, QCheckBox from PyQt5.QtGui import QKeySequence from vorta.borg.borg_thread import BorgThread -from vorta.i18n import trans_late from vorta.models import BackupProfileModel, SettingsModel from vorta.utils import borg_compat, get_asset, is_system_tray_available, get_network_status_monitor from vorta.views.utils import get_colored_icon @@ -190,12 +189,21 @@ def closeEvent(self, event): .execute() if not is_system_tray_available(): - run_in_background = QMessageBox.question(self, - trans_late("MainWindow QMessagebox", - "Quit"), - trans_late("MainWindow QMessagebox", - "Should Vorta continue to run in the background?"), - QMessageBox.Yes | QMessageBox.No) - if run_in_background == QMessageBox.No: + if SettingsModel.get(key="enable_background_question").value: + msg = QMessageBox() + msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No) + msg.setParent(self, QtCore.Qt.Sheet) + msg.setText(self.tr("Should Vorta continue to run in the background?")) + msg.button(QMessageBox.Yes).clicked.connect( + lambda: self.miscTab.save_setting("disable_background_state", True)) + msg.button(QMessageBox.No).clicked.connect(lambda: (self.miscTab.save_setting( + "disable_background_state", False), self.app.quit())) + msg.setWindowTitle(self.tr("Quit")) + dont_show_box = QCheckBox(self.tr("Don't show this again")) + dont_show_box.clicked.connect(lambda x: self.miscTab.save_setting("enable_background_question", not x)) + dont_show_box.setTristate(False) + msg.setCheckBox(dont_show_box) + msg.exec() + elif not SettingsModel.get(key="disable_background_state").value: self.app.quit() event.accept()