File indexing completed on 2024-05-12 04:58:40
0001 # ============================================================ 0002 # MiddleClickLoader - plugin for Falkon 0003 # Copyright (C) 2018 Juraj Oravec <sgd.orava@gmail.com> 0004 # 0005 # This program is free software: you can redistribute it and/or modify 0006 # it under the terms of the GNU General Public License as published by 0007 # the Free Software Foundation, either version 3 of the License, or 0008 # (at your option) any later version. 0009 # 0010 # This program is distributed in the hope that it will be useful, 0011 # but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 # GNU General Public License for more details. 0014 # 0015 # You should have received a copy of the GNU General Public License 0016 # along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 # ============================================================ 0018 0019 import os 0020 from PySide6 import QtCore, QtWidgets, QtUiTools 0021 from middleclickloader.i18n import i18n 0022 from middleclickloader.mcl_loadmode import MCL_LoadMode 0023 0024 0025 class MCL_Settings(QtWidgets.QDialog): 0026 settingsFile = "" 0027 ui = None 0028 0029 def __init__(self, settingsFile, parent=None): 0030 super().__init__(parent) 0031 0032 self.settingsFile = settingsFile 0033 0034 file = QtCore.QFile(os.path.join(os.path.dirname(__file__), "mcl_settings.ui")) 0035 file.open(QtCore.QFile.ReadOnly) 0036 self.ui = QtUiTools.QUiLoader().load(file, self) 0037 file.close() 0038 0039 layout = QtWidgets.QVBoxLayout(self) 0040 layout.addWidget(self.ui) 0041 self.setLayout(layout) 0042 0043 self.setWindowTitle(i18n("MiddleClickLoader Setting")) 0044 self.ui.label_header.setText("<h2>{}</h2>".format(i18n("MiddleClickLoader"))) 0045 self.ui.label_loadMode.setText(i18n("Open url in:")) 0046 self.ui.onlyValidUrl.setText(i18n("Use only valid url")) 0047 0048 self.ui.loadMode.addItem(i18n("New Tab"), MCL_LoadMode.NEW_TAB) 0049 self.ui.loadMode.addItem(i18n("Current Tab"), MCL_LoadMode.CURRENT_TAB) 0050 self.ui.loadMode.addItem(i18n("New Window"), MCL_LoadMode.NEW_WINDOW) 0051 0052 settings = QtCore.QSettings(self.settingsFile, QtCore.QSettings.IniFormat) 0053 settings.beginGroup("MiddleClickLoader") 0054 self.ui.loadMode.setCurrentIndex(int(settings.value("LoadMode", MCL_LoadMode.NEW_TAB))) 0055 self.ui.onlyValidUrl.setChecked(bool(settings.value("OnlyValidUrl", True))) 0056 settings.endGroup() 0057 0058 self.ui.buttonBox.accepted.connect(self.accept) 0059 self.ui.buttonBox.rejected.connect(self.reject) 0060 0061 def accept(self): 0062 settings = QtCore.QSettings(self.settingsFile, QtCore.QSettings.IniFormat) 0063 settings.beginGroup("MiddleClickLoader") 0064 settings.setValue("LoadMode", self.ui.loadMode.currentIndex()) 0065 settings.setValue("OnlyValidUrl", self.ui.onlyValidUrl.isChecked()) 0066 settings.endGroup() 0067 0068 super().accept() 0069 self.close()