1
0
mirror of https://github.com/bpozdena/OneDriveGUI.git synced 2026-10-24 04:59:17 +03:00

added logic for checkboxes

This commit is contained in:
Boris Pozdena
2022-01-28 09:44:23 +01:00
parent 97e7e7dd59
commit d1e1bf921b
3 changed files with 202 additions and 80 deletions

View File

@@ -5,7 +5,7 @@ import subprocess
import sys
from configparser import ConfigParser
from PySide6.QtCore import QThread, QTimer, QUrl, Signal, QFileInfo
from PySide6.QtCore import QThread, QTimer, QUrl, Signal, QFileInfo, Qt
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import ( QWidget, QApplication, QMainWindow, QMenu, QSystemTrayIcon,
QListWidget, QListWidgetItem, QFileIconProvider, QStackedLayout,
@@ -92,18 +92,31 @@ class ProfileSettingsPage(QWidget, Ui_profile_settings):
self.setupUi(self)
temp_global_config = global_config
self.temp_profile_config = temp_global_config[self.profile]
self.temp_profile_config = temp_global_config[self.profile]['onedrive']
self.label_profile_name.setText(self.profile)
self.lineEdit_sync_dir.setText(self.temp_profile_config['onedrive']['sync_dir'].strip('"'))
#
# Monitored files tab
#
self.lineEdit_sync_dir.setText(self.temp_profile_config['sync_dir'].strip('"'))
self.lineEdit_sync_dir.textChanged.connect(self.set_sync_dir)
self.checkBox_sync_root_files.setChecked(self.get_toggle_state('sync_root_files'))
self.checkBox_sync_root_files.stateChanged.connect(self.set_check_state)
# self.ui.lineEdit.setText(settings['onedrive']['log_dir'].strip('"'))
# self.ui.lineEdit.textChanged.connect(
# lambda: settings.set('onedrive', 'log_dir', f'"{self.ui.lineEdit.text()}"'))
#
# Excluded files tab
#
# Skip_file section
self.skip_files = self.temp_profile_config['onedrive']['skip_file'].strip('"').split('|')
self.skip_files = self.temp_profile_config['skip_file'].strip('"').split('|')
self.listWidget_skip_file.addItems(self.skip_files)
self.listWidget_skip_file.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.pushButton_add_skip_file.clicked.connect(self.add_skip_file)
@@ -112,48 +125,157 @@ class ProfileSettingsPage(QWidget, Ui_profile_settings):
# Skip_dir section
self.skip_dirs = self.temp_profile_config['onedrive']['skip_dir'].strip('"').split('|')
self.skip_dirs = self.temp_profile_config['skip_dir'].strip('"').split('|')
self.listWidget_skip_dir.addItems(self.skip_dirs)
self.listWidget_skip_dir.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.pushButton_add_skip_dir.clicked.connect(self.add_skip_dir)
self.pushButton_add_skip_dir.clicked.connect(self.lineEdit_skip_dir.clear)
self.pushButton_rm_skip_dir.clicked.connect(self.remove_skip_dir)
self.checkBox_skip_dir_strict_match.setChecked(self.get_toggle_state('skip_dir_strict_match'))
self.checkBox_skip_dir_strict_match.stateChanged.connect(self.set_check_state)
# Rate limit
self.lineEdit_rate_limit.setText(self.temp_profile_config['onedrive']['rate_limit'].strip('"'))
self.checkBox_check_nosync.setChecked(self.get_toggle_state('check_nosync'))
self.checkBox_check_nosync.stateChanged.connect(self.set_check_state)
self.checkBox_skip_symlinks.setChecked(self.get_toggle_state('skip_symlinks'))
self.checkBox_skip_symlinks.stateChanged.connect(self.set_check_state)
self.checkBox_skip_dotfiles.setChecked(self.get_toggle_state('skip_dotfiles'))
self.checkBox_skip_dotfiles.stateChanged.connect(self.set_check_state)
#
# Sync Options tab
#
self.checkBox_download_only.setChecked(self.get_toggle_state('download_only'))
self.checkBox_download_only.stateChanged.connect(self.set_check_state)
self.checkBox_upload_only.setChecked(self.get_toggle_state('upload_only'))
self.checkBox_upload_only.stateChanged.connect(self.set_check_state)
self.checkBox_force_http_2.setChecked(self.get_toggle_state('force_http_2'))
self.checkBox_force_http_2.stateChanged.connect(self.set_check_state)
self.checkBox_disable_upload_validation.setChecked(self.get_toggle_state('disable_upload_validation'))
self.checkBox_disable_upload_validation.stateChanged.connect(self.set_check_state)
self.checkBox_check_nomount.setChecked(self.get_toggle_state('check_nomount'))
self.checkBox_check_nomount.stateChanged.connect(self.set_check_state)
self.checkBox_local_first.setChecked(self.get_toggle_state('local_first'))
self.checkBox_local_first.stateChanged.connect(self.set_check_state)
self.checkBox_no_remote_delete.setChecked(self.get_toggle_state('no_remote_delete'))
self.checkBox_no_remote_delete.stateChanged.connect(self.set_check_state)
self.checkBox_sync_business_shared_folders.setChecked(self.get_toggle_state('sync_business_shared_folders'))
self.checkBox_sync_business_shared_folders.stateChanged.connect(self.set_check_state)
self.checkBox_dry_run.setChecked(self.get_toggle_state('dry_run'))
self.checkBox_dry_run.stateChanged.connect(self.set_check_state)
self.checkBox_remove_source_files.setChecked(self.get_toggle_state('remove_source_files'))
self.checkBox_remove_source_files.stateChanged.connect(self.set_check_state)
self.checkBox_resync.setChecked(self.get_toggle_state('resync'))
self.checkBox_resync.stateChanged.connect(self.set_check_state)
self.checkBox_bypass_data_preservation.setChecked(self.get_toggle_state('bypass_data_preservation'))
self.checkBox_bypass_data_preservation.stateChanged.connect(self.set_check_state)
self.checkBox_webhook_enabled.setChecked(self.get_toggle_state('webhook_enabled'))
self.checkBox_webhook_enabled.stateChanged.connect(self.set_check_state)
#
# Logging tab
#
self.checkBox_enable_logging.setChecked(self.get_toggle_state('enable_logging'))
self.checkBox_enable_logging.stateChanged.connect(self.set_check_state)
self.checkBox_debug_https.setChecked(self.get_toggle_state('debug_https'))
self.checkBox_debug_https.stateChanged.connect(self.set_check_state)
self.checkBox_disable_notifications.setChecked(self.get_toggle_state('disable_notifications'))
self.checkBox_disable_notifications.stateChanged.connect(self.set_check_state)
#
# Rate limit tab
#
self.lineEdit_rate_limit.setText(self.temp_profile_config['rate_limit'].strip('"'))
self.label_rate_limit_mbps.setText(str(round(int(self.lineEdit_rate_limit.text()) * 8 / 1000 / 1000, 2)) + " Mbit/s")
self.lineEdit_rate_limit.textChanged.connect(self.set_rate_limit)
# buttons
# Buttons
self.pushButton_discart.hide()
# TODO: how to discart unsaved changes and refresh the widgets or close window?
# TODO: How to discart unsaved changes and refresh the widgets or close window?
# self.pushButton_discart.clicked.connect(self.discart_changes)
self.pushButton_save.clicked.connect(self.save_profile_settings)
# if self.temp_profile_config['sync_root_files'].strip('"') == 'true':
# self.checkBox_sync_root_files.setCheckState(Qt.Checked)
# else:
# self.checkBox_sync_root_files.setCheckState(Qt.Unchecked)
# self.checkBox_sync_root_files.stateChanged.connect(lambda: )
# self.checkBox_sync_root_files.toggled.connect(lambda: self.set_check_state(self.checkBox_sync_root_files))
# self.checkBox_sync_root_files.setChecked(lambda: self.get_toggle_state())
# self.checkBox_sync_root_files.setChecked(self.str2bool(self.temp_profile_config['sync_root_files'].strip('"')))
def str2bool(self, value):
return value.lower() in "true"
def set_check_state(self, state):
_property = self.sender().objectName()
property = re.search(r"checkBox_(.+)", _property).group(1)
print(property)
if state == Qt.Checked:
print("is checked")
self.temp_profile_config[f'{property}'] = '"true"'
else:
print("is unchecked")
self.temp_profile_config[f'{property}'] = '"false"'
def get_toggle_state(self, property):
return self.temp_profile_config[f'{property}'].strip('"') in 'true'
def add_skip_file(self):
self.add_item_to_qlist(self.lineEdit_skip_file, self.listWidget_skip_file, self.skip_files)
self.temp_profile_config['onedrive']['skip_file'] = '"' + '|'.join(self.skip_files) + '"'
self.temp_profile_config['skip_file'] = '"' + '|'.join(self.skip_files) + '"'
def remove_skip_file(self):
self.remove_item_from_qlist(self.listWidget_skip_file, self.skip_files)
self.temp_profile_config['onedrive']['skip_file'] = '"' + '|'.join(self.skip_files) + '"'
self.temp_profile_config['skip_file'] = '"' + '|'.join(self.skip_files) + '"'
def add_skip_dir(self):
self.add_item_to_qlist(self.lineEdit_skip_dir, self.listWidget_skip_dir, self.skip_dirs)
self.temp_profile_config['onedrive']['skip_dir'] = '"' + '|'.join(self.skip_dirs) + '"'
self.temp_profile_config['skip_dir'] = '"' + '|'.join(self.skip_dirs) + '"'
def remove_skip_dir(self):
self.remove_item_from_qlist(self.listWidget_skip_dir, self.skip_dirs)
self.temp_profile_config['onedrive']['skip_dir'] = '"' + '|'.join(self.skip_dirs) + '"'
self.temp_profile_config['skip_dir'] = '"' + '|'.join(self.skip_dirs) + '"'
def set_rate_limit(self):
self.temp_profile_config['onedrive']['rate_limit'] = f'"{self.lineEdit_rate_limit.text()}"'
self.temp_profile_config['rate_limit'] = f'"{self.lineEdit_rate_limit.text()}"'
self.label_rate_limit_mbps.setText(str(round(int(self.lineEdit_rate_limit.text()) * 8 / 1000 / 1000, 2)) + " Mbit/s")
def set_sync_dir(self):
self.temp_profile_config['onedrive']['sync_dir'] = f'"{self.lineEdit_sync_dir.text()}"'
self.temp_profile_config['sync_dir'] = f'"{self.lineEdit_sync_dir.text()}"'
def add_item_to_qlist(self, source_widget, destination_widget, list):
if source_widget.text() == "":

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>614</width>
<height>785</height>
<width>751</width>
<height>718</height>
</rect>
</property>
<property name="windowTitle">
@@ -49,34 +49,34 @@
<string>Monitored Files</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="2">
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_sync_dir">
<property name="text">
<string>Sync Folder:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_sync_dir"/>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox_8">
<property name="title">
<string>Options</string>
<string>Monitored directory</string>
</property>
<layout class="QGridLayout" name="gridLayout_9">
<item row="0" column="0">
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="2">
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_sync_dir">
<property name="text">
<string>Sync Folder:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit_sync_dir"/>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBox_sync_root_files">
<property name="text">
<string>Sync root files</string>
@@ -238,7 +238,7 @@
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Sync options</string>
<string>Sync Options</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
@@ -350,7 +350,7 @@
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="checkBox_no_mount">
<widget class="QCheckBox" name="checkBox_check_nomount">
<property name="text">
<string>Check for .nomount</string>
</property>
@@ -679,27 +679,27 @@
</widget>
<widget class="QWidget" name="tab_6">
<attribute name="title">
<string>Page</string>
<string>GUI Behaviour</string>
</attribute>
</widget>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_discart">
<property name="text">
<string>Discard changes</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_save">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="pushButton_save">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_discart">
<property name="text">
<string>Discard changes</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>

View File

@@ -25,7 +25,7 @@ class Ui_profile_settings(object):
def setupUi(self, profile_settings):
if not profile_settings.objectName():
profile_settings.setObjectName(u"profile_settings")
profile_settings.resize(614, 785)
profile_settings.resize(751, 718)
self.verticalLayout_2 = QVBoxLayout(profile_settings)
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
self.label_profile_name = QLabel(profile_settings)
@@ -47,34 +47,34 @@ class Ui_profile_settings(object):
self.exemptions_tab_2.setObjectName(u"exemptions_tab_2")
self.verticalLayout_5 = QVBoxLayout(self.exemptions_tab_2)
self.verticalLayout_5.setObjectName(u"verticalLayout_5")
self.groupBox_8 = QGroupBox(self.exemptions_tab_2)
self.groupBox_8.setObjectName(u"groupBox_8")
self.gridLayout_9 = QGridLayout(self.groupBox_8)
self.gridLayout_9.setObjectName(u"gridLayout_9")
self.gridLayout_5 = QGridLayout()
self.gridLayout_5.setObjectName(u"gridLayout_5")
self.pushButton_3 = QPushButton(self.exemptions_tab_2)
self.pushButton_3 = QPushButton(self.groupBox_8)
self.pushButton_3.setObjectName(u"pushButton_3")
self.gridLayout_5.addWidget(self.pushButton_3, 0, 2, 1, 1)
self.label_sync_dir = QLabel(self.exemptions_tab_2)
self.label_sync_dir = QLabel(self.groupBox_8)
self.label_sync_dir.setObjectName(u"label_sync_dir")
self.gridLayout_5.addWidget(self.label_sync_dir, 0, 0, 1, 1)
self.lineEdit_sync_dir = QLineEdit(self.exemptions_tab_2)
self.lineEdit_sync_dir = QLineEdit(self.groupBox_8)
self.lineEdit_sync_dir.setObjectName(u"lineEdit_sync_dir")
self.gridLayout_5.addWidget(self.lineEdit_sync_dir, 0, 1, 1, 1)
self.verticalLayout_5.addLayout(self.gridLayout_5)
self.gridLayout_9.addLayout(self.gridLayout_5, 1, 0, 1, 1)
self.groupBox_8 = QGroupBox(self.exemptions_tab_2)
self.groupBox_8.setObjectName(u"groupBox_8")
self.gridLayout_9 = QGridLayout(self.groupBox_8)
self.gridLayout_9.setObjectName(u"gridLayout_9")
self.checkBox_sync_root_files = QCheckBox(self.groupBox_8)
self.checkBox_sync_root_files.setObjectName(u"checkBox_sync_root_files")
self.gridLayout_9.addWidget(self.checkBox_sync_root_files, 0, 0, 1, 1)
self.gridLayout_9.addWidget(self.checkBox_sync_root_files, 2, 0, 1, 1)
self.verticalLayout_5.addWidget(self.groupBox_8)
@@ -294,10 +294,10 @@ class Ui_profile_settings(object):
self.gridLayout_4.addWidget(self.checkBox_force_http_2, 2, 1, 1, 1)
self.checkBox_no_mount = QCheckBox(self.groupBox_5)
self.checkBox_no_mount.setObjectName(u"checkBox_no_mount")
self.checkBox_check_nomount = QCheckBox(self.groupBox_5)
self.checkBox_check_nomount.setObjectName(u"checkBox_check_nomount")
self.gridLayout_4.addWidget(self.checkBox_no_mount, 4, 1, 1, 1)
self.gridLayout_4.addWidget(self.checkBox_check_nomount, 4, 1, 1, 1)
self.checkBox_resync = QCheckBox(self.groupBox_5)
self.checkBox_resync.setObjectName(u"checkBox_resync")
@@ -549,18 +549,18 @@ class Ui_profile_settings(object):
self.horizontalLayout.addWidget(self.tabWidget)
self.pushButton_discart = QPushButton(profile_settings)
self.pushButton_discart.setObjectName(u"pushButton_discart")
self.horizontalLayout.addWidget(self.pushButton_discart)
self.verticalLayout_2.addLayout(self.horizontalLayout)
self.pushButton_save = QPushButton(profile_settings)
self.pushButton_save.setObjectName(u"pushButton_save")
self.horizontalLayout.addWidget(self.pushButton_save)
self.verticalLayout_2.addWidget(self.pushButton_save)
self.pushButton_discart = QPushButton(profile_settings)
self.pushButton_discart.setObjectName(u"pushButton_discart")
self.verticalLayout_2.addLayout(self.horizontalLayout)
self.verticalLayout_2.addWidget(self.pushButton_discart)
self.retranslateUi(profile_settings)
@@ -574,9 +574,9 @@ class Ui_profile_settings(object):
def retranslateUi(self, profile_settings):
profile_settings.setWindowTitle(QCoreApplication.translate("profile_settings", u"Form", None))
self.label_profile_name.setText(QCoreApplication.translate("profile_settings", u"Profile name", None))
self.groupBox_8.setTitle(QCoreApplication.translate("profile_settings", u"Monitored directory", None))
self.pushButton_3.setText(QCoreApplication.translate("profile_settings", u"Browse", None))
self.label_sync_dir.setText(QCoreApplication.translate("profile_settings", u"Sync Folder:", None))
self.groupBox_8.setTitle(QCoreApplication.translate("profile_settings", u"Options", None))
self.checkBox_sync_root_files.setText(QCoreApplication.translate("profile_settings", u"Sync root files", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.exemptions_tab_2), QCoreApplication.translate("profile_settings", u"Monitored Files", None))
self.groupBox.setTitle(QCoreApplication.translate("profile_settings", u"Excluded files", None))
@@ -601,7 +601,7 @@ class Ui_profile_settings(object):
self.label_sync_file_permissions.setText(QCoreApplication.translate("profile_settings", u"Sync file permissions", None))
self.groupBox_5.setTitle(QCoreApplication.translate("profile_settings", u"Advanced options", None))
self.checkBox_force_http_2.setText(QCoreApplication.translate("profile_settings", u"Force HTTP2", None))
self.checkBox_no_mount.setText(QCoreApplication.translate("profile_settings", u"Check for .nomount", None))
self.checkBox_check_nomount.setText(QCoreApplication.translate("profile_settings", u"Check for .nomount", None))
self.checkBox_resync.setText(QCoreApplication.translate("profile_settings", u"Full re-sync", None))
self.checkBox_download_only.setText(QCoreApplication.translate("profile_settings", u"Download only", None))
self.checkBox_local_first.setText(QCoreApplication.translate("profile_settings", u"Local first", None))
@@ -620,7 +620,7 @@ class Ui_profile_settings(object):
self.label_webhook_listening_host.setText(QCoreApplication.translate("profile_settings", u"Listening host", None))
self.label_webhook_renewal_interval.setText(QCoreApplication.translate("profile_settings", u"Renewal interval", None))
self.label_operation_timeout.setText(QCoreApplication.translate("profile_settings", u"Operation timeout", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QCoreApplication.translate("profile_settings", u"Sync options", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QCoreApplication.translate("profile_settings", u"Sync Options", None))
self.groupBox_7.setTitle(QCoreApplication.translate("profile_settings", u"Logging", None))
self.checkBox_enable_logging.setText(QCoreApplication.translate("profile_settings", u"Enable Logging", None))
self.pushButton_log_dir.setText(QCoreApplication.translate("profile_settings", u"Browse", None))
@@ -635,8 +635,8 @@ class Ui_profile_settings(object):
self.label_rate_limit.setText(QCoreApplication.translate("profile_settings", u"Rate Limit [B/s]", None))
self.label_rate_limit_mbps.setText(QCoreApplication.translate("profile_settings", u"(Mbit/s)", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_5), QCoreApplication.translate("profile_settings", u"Rate Limit", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_6), QCoreApplication.translate("profile_settings", u"Page", None))
self.pushButton_discart.setText(QCoreApplication.translate("profile_settings", u"Discard changes", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_6), QCoreApplication.translate("profile_settings", u"GUI Behaviour", None))
self.pushButton_save.setText(QCoreApplication.translate("profile_settings", u"Save", None))
self.pushButton_discart.setText(QCoreApplication.translate("profile_settings", u"Discard changes", None))
# retranslateUi