Skip to content

Commit

Permalink
Refactored profile combobox to a list, added settings wheel icon, mod…
Browse files Browse the repository at this point in the history
…ified profile add button
  • Loading branch information
bigtedde committed Sep 6, 2023
1 parent 8e6aaff commit 2155997
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 27 deletions.
43 changes: 34 additions & 9 deletions src/vorta/assets/UI/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="profileSelector">
<widget class="QListWidget" name="profileSelector">
<property name="fixedSize">
<size>
<width>150</width>
<height>50</height>
<width>200</width>
<height>200</height>
</size>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="profileAddButton">
<property name="toolTip">
<string>Add a new profile (Dropdown: Import from file)</string>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
Expand All @@ -60,7 +60,7 @@
</size>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
Expand Down Expand Up @@ -117,8 +117,33 @@
<property name="text">
<string>Settings</string>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>50</height>
</size>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="bottomSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>100</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -155,7 +180,7 @@
</widget>
<widget class="QWidget" name="profileTabSlot">
<attribute name="title">
<string>Profile Settings</string>
<string>Profile Management</string>
</attribute>
</widget>
</widget>
Expand Down
19 changes: 19 additions & 0 deletions src/vorta/assets/icons/settings_wheel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 35 additions & 18 deletions src/vorta/views/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from pathlib import Path

from PyQt6 import QtCore, uic
from PyQt6.QtCore import QPoint
from PyQt6.QtCore import QPoint, Qt
from PyQt6.QtGui import QFontMetrics, QKeySequence, QShortcut
from PyQt6.QtWidgets import (
QApplication,
QCheckBox,
QFileDialog,
QMenu,
QListWidgetItem,
QMessageBox,
QToolTip,
)
Expand Down Expand Up @@ -96,14 +96,12 @@ def __init__(self, parent=None):

# Init profile list
self.populate_profile_selector()
self.profileSelector.currentIndexChanged.connect(self.profile_select_action)
self.profileSelector.currentItemChanged.connect(self.profile_select_action)
self.profileRenameButton.clicked.connect(self.profile_rename_action)
self.profileExportButton.clicked.connect(self.profile_export_action)
self.profileDeleteButton.clicked.connect(self.profile_delete_action)
profile_add_menu = QMenu()
profile_add_menu.addAction(self.tr('Import from file…'), self.profile_import_action)
self.profileAddButton.setMenu(profile_add_menu)
self.profileAddButton.clicked.connect(self.profile_add_action)
self.profileAddButton.addAction(self.tr("Create new profile"), self.profile_add_action)
self.profileAddButton.addAction(self.tr("Import from file…"), self.profile_import_action)

# OS-specific startup options:
if not get_network_status_monitor().is_network_status_available():
Expand Down Expand Up @@ -132,6 +130,7 @@ def set_icons(self):
self.profileRenameButton.setIcon(get_colored_icon('edit'))
self.profileExportButton.setIcon(get_colored_icon('file-import-solid'))
self.profileDeleteButton.setIcon(get_colored_icon('trash'))
self.settingsButton.setIcon(get_colored_icon('settings_wheel'))

def set_progress(self, text=''):
self.progressText.setText(text)
Expand All @@ -152,14 +151,29 @@ def _toggle_buttons(self, create_enabled=True):
self.cancelButton.repaint()

def populate_profile_selector(self):
# Clear the previous entries
self.profileSelector.clear()

# Keep track of the current item to be selected (if any)
current_item = None

# Add items to the QListWidget
for profile in BackupProfileModel.select().order_by(BackupProfileModel.name):
self.profileSelector.addItem(profile.name, profile.id)
current_profile_index = self.profileSelector.findData(self.current_profile.id)
self.profileSelector.setCurrentIndex(current_profile_index)
item = QListWidgetItem(profile.name)
item.setData(Qt.ItemDataRole.UserRole, profile.id)

self.profileSelector.addItem(item)

if profile.id == self.current_profile.id:
current_item = item

# Set the current profile as selected
if current_item:
self.profileSelector.setCurrentItem(current_item)

def profile_select_action(self, index):
backup_profile_id = self.profileSelector.currentData()
profile = self.profileSelector.currentItem()
backup_profile_id = profile.data(Qt.ItemDataRole.UserRole) if profile else None
if not backup_profile_id:
return
self.current_profile = BackupProfileModel.get(id=backup_profile_id)
Expand All @@ -173,7 +187,8 @@ def profile_select_action(self, index):
self.archiveTab.toggle_compact_button_visibility()

def profile_rename_action(self):
window = EditProfileWindow(rename_existing_id=self.profileSelector.currentData())
backup_profile_id = self.profileSelector.currentItem().data(Qt.ItemDataRole.UserRole)
window = EditProfileWindow(rename_existing_id=backup_profile_id)
self.window = window # For tests
window.setParent(self, QtCore.Qt.WindowType.Sheet)
window.open()
Expand All @@ -182,7 +197,7 @@ def profile_rename_action(self):

def profile_delete_action(self):
if self.profileSelector.count() > 1:
to_delete_id = self.profileSelector.currentData()
to_delete_id = self.profileSelector.currentItem().data(Qt.ItemDataRole.UserRole)
to_delete = BackupProfileModel.get(id=to_delete_id)

msg = self.tr("Are you sure you want to delete profile '{}'?".format(to_delete.name))
Expand All @@ -197,7 +212,7 @@ def profile_delete_action(self):
if reply == QMessageBox.StandardButton.Yes:
to_delete.delete_instance(recursive=True)
self.app.scheduler.remove_job(to_delete_id) # Remove pending jobs
self.profileSelector.removeItem(self.profileSelector.currentIndex())
self.profileSelector.takeItem(self.profileSelector.currentRow())
self.profile_select_action(0)

else:
Expand Down Expand Up @@ -261,12 +276,14 @@ def profile_imported_event(profile):

def profile_add_edit_result(self, profile_name, profile_id):
# Profile is renamed
if self.profileSelector.currentData() == profile_id:
self.profileSelector.setItemText(self.profileSelector.currentIndex(), profile_name)
if self.profileSelector.currentItem().data(Qt.ItemDataRole.UserRole) == profile_id:
self.profileSelector.currentItem().setText(profile_name)
# Profile is added
else:
self.profileSelector.addItem(profile_name, profile_id)
self.profileSelector.setCurrentIndex(self.profileSelector.count() - 1)
profile = QListWidgetItem(profile_name)
profile.setData(Qt.ItemDataRole.UserRole, profile_id)
self.profileSelector.addItem(profile)
self.profileSelector.setCurrentItem(profile)

def loadMiscTab(self):
if self.settingsWidget.isVisible():
Expand Down

0 comments on commit 2155997

Please sign in to comment.