def closeEvent(self, event): # Save window state in SettingsModel SettingsModel.update({SettingsModel.str_value: str(self.width())}) \ .where(SettingsModel.key == 'previous_window_width') \ .execute() SettingsModel.update({SettingsModel.str_value: str(self.height())}) \ .where(SettingsModel.key == 'previous_window_height') \ .execute() if not is_system_tray_available(): 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()
def closeEvent(self, event): if not is_system_tray_available() and not self.tests_running: 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: self.app.quit() event.accept()
def closeEvent(self, event): # Save window state in SettingsModel SettingsModel.update({SettingsModel.str_value: str(self.width())})\ .where(SettingsModel.key == 'previous_window_width')\ .execute() SettingsModel.update({SettingsModel.str_value: str(self.height())})\ .where(SettingsModel.key == 'previous_window_height')\ .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: self.app.quit() event.accept()
def init_db(con): os.umask(0o0077) db.initialize(con) db.connect() db.create_tables([RepoModel, RepoPassword, BackupProfileModel, SourceFileModel, SettingsModel, ArchiveModel, WifiSettingModel, EventLogModel, SchemaVersion]) if BackupProfileModel.select().count() == 0: default_profile = BackupProfileModel(name='Default') default_profile.save() # Create missing settings and update labels. Leave setting values untouched. for setting in get_misc_settings(): s, created = SettingsModel.get_or_create(key=setting['key'], defaults=setting) if created and setting['key'] == "use_dark_theme": # Check if macOS with enabled dark mode s.value = bool(uses_dark_mode()) if created and setting['key'] == "use_light_icon": # Check if macOS with enabled dark mode or Linux with GNOME DE s.value = bool(uses_dark_mode()) or 'GNOME' in os.environ.get('XDG_CURRENT_DESKTOP', '') if created and setting['key'] == "enable_notifications_success": s.value = not bool(is_system_tray_available()) s.label = setting['label'] s.save() # Delete old log entries after 3 months. three_months_ago = datetime.now() - timedelta(days=180) EventLogModel.delete().where(EventLogModel.start_time < three_months_ago) # Migrations # See http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#schema-migrations current_schema, created = SchemaVersion.get_or_create(id=1, defaults={'version': SCHEMA_VERSION}) current_schema.save() if created or current_schema.version == SCHEMA_VERSION: pass else: migrator = SqliteMigrator(con) if current_schema.version < 4: # version 3 to 4 _apply_schema_update( current_schema, 4, migrator.add_column(ArchiveModel._meta.table_name, 'duration', pw.FloatField(null=True)), migrator.add_column(ArchiveModel._meta.table_name, 'size', pw.IntegerField(null=True)) ) if current_schema.version < 5: _apply_schema_update( current_schema, 5, migrator.drop_not_null(WifiSettingModel._meta.table_name, 'last_connected'), ) if current_schema.version < 6: _apply_schema_update( current_schema, 6, migrator.add_column(EventLogModel._meta.table_name, 'repo_url', pw.CharField(null=True)) ) if current_schema.version < 7: _apply_schema_update( current_schema, 7, migrator.rename_column(SourceFileModel._meta.table_name, 'config_id', 'profile_id'), migrator.drop_column(EventLogModel._meta.table_name, 'profile_id'), migrator.add_column(EventLogModel._meta.table_name, 'profile', pw.CharField(null=True)) ) if current_schema.version < 8: _apply_schema_update( current_schema, 8, migrator.add_column(BackupProfileModel._meta.table_name, 'prune_keep_within', pw.CharField(null=True))) if current_schema.version < 9: _apply_schema_update( current_schema, 9, migrator.add_column(BackupProfileModel._meta.table_name, 'new_archive_name', pw.CharField(default="{hostname}-{profile_slug}-{now:%Y-%m-%dT%H:%M:%S}")), migrator.add_column(BackupProfileModel._meta.table_name, 'prune_prefix', pw.CharField(default="{hostname}-{profile_slug}-")), ) if current_schema.version < 10: _apply_schema_update( current_schema, 10, migrator.add_column(BackupProfileModel._meta.table_name, 'pre_backup_cmd', pw.CharField(default='')), migrator.add_column(BackupProfileModel._meta.table_name, 'post_backup_cmd', pw.CharField(default='')), ) if current_schema.version < 11: _apply_schema_update(current_schema, 11) for profile in BackupProfileModel: if profile.compression == 'zstd': profile.compression = 'zstd,3' if profile.compression == 'lzma,6': profile.compression = 'auto,lzma,6' profile.save() if current_schema.version < 12: _apply_schema_update( current_schema, 12, migrator.add_column(RepoModel._meta.table_name, 'extra_borg_arguments', pw.CharField(default=''))) if current_schema.version < 13: """ Migrate ArchiveModel data to new table to remove unique constraint from snapshot_id column. """ tables = db.get_tables() if ArchiveModel.select().count() == 0 and 'snapshotmodel' in tables: cursor = db.execute_sql('select * from snapshotmodel;') fields = [ArchiveModel.id, ArchiveModel.snapshot_id, ArchiveModel.name, ArchiveModel.repo, ArchiveModel.time, ArchiveModel.duration, ArchiveModel.size] data = [row for row in cursor.fetchall()] with db.atomic(): size = 1000 for i in range(0, len(data), size): ArchiveModel.insert_many(data[i:i + size], fields=fields).execute() _apply_schema_update(current_schema, 13)
def get_misc_settings(): # Default settings for all platforms. settings = [ { 'key': 'enable_notifications', 'value': True, 'type': 'checkbox', 'label': trans_late('settings', 'Display notifications when background tasks fail') }, { 'key': 'enable_notifications_success', 'value': False, 'type': 'checkbox', 'label': trans_late('settings', 'Also notify about successful background tasks') }, { 'key': 'autostart', 'value': False, 'type': 'checkbox', 'label': trans_late('settings', 'Automatically start Vorta at login') }, { 'key': 'foreground', 'value': True, 'type': 'checkbox', 'label': trans_late('settings', 'Open main window on startup') }, { 'key': 'get_srcpath_datasize', 'value': True, 'type': 'checkbox', 'label': trans_late('settings', 'Get statistics of file/folder when added') }, { 'key': 'previous_profile_id', 'str_value': '1', 'type': 'internal', 'label': 'Previously selected profile' }, { 'key': 'previous_window_width', 'str_value': '800', 'type': 'internal', 'label': 'Previous window width' }, { 'key': 'previous_window_height', 'str_value': '600', 'type': 'internal', 'label': 'Previous window height' }, ] if sys.platform == 'darwin': settings += [ { 'key': 'check_for_updates', 'value': True, 'type': 'checkbox', 'label': trans_late('settings', 'Check for updates on startup') }, { 'key': 'updates_include_beta', 'value': False, 'type': 'checkbox', 'label': trans_late( '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