161 lines
5.3 KiB
Python
161 lines
5.3 KiB
Python
# ============================================================
|
|
# Auto Zoomer - plugin for Falkon
|
|
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
# ============================================================
|
|
|
|
import Falkon
|
|
import os
|
|
from PySide2 import QtCore, QtGui, QtWidgets, QtUiTools
|
|
from autoZoomer.listItem import ListItem
|
|
from autoZoomer.i18n import i18n
|
|
|
|
|
|
class SettingsDialog(QtWidgets.QDialog):
|
|
ui = None
|
|
data = None
|
|
remove = None
|
|
prepareRemove = None
|
|
config = None
|
|
|
|
def __init__(self, config, data, remove, parent=None):
|
|
super().__init__(parent)
|
|
|
|
self.config = config
|
|
self.data = data
|
|
self.remove = remove
|
|
self.prepareRemove = []
|
|
|
|
file = QtCore.QFile(os.path.join(os.path.dirname(__file__), "settings.ui"))
|
|
file.open(QtCore.QFile.ReadOnly)
|
|
self.ui = QtUiTools.QUiLoader().load(file, self)
|
|
file.close()
|
|
|
|
layout = QtWidgets.QVBoxLayout(self)
|
|
layout.addWidget(self.ui)
|
|
self.setLayout(layout)
|
|
|
|
self.translations()
|
|
|
|
for level in Falkon.WebView.zoomLevels():
|
|
self.ui.comboBoxNew.addItem(str(level) + '%')
|
|
self.ui.comboBoxNew.setCurrentIndex(Falkon.WebView.zoomLevels().index(100))
|
|
|
|
self.ui.checkBoxEnableAutoZoomer.setChecked(self.config["active"])
|
|
self.ui.checkBoxDefaultZoom.setChecked(self.config["defaultZoom"])
|
|
|
|
if self.config["shortcut"]:
|
|
self.ui.keySequenceEditShortcut.setKeySequence(
|
|
QtGui.QKeySequence(self.config["shortcut"])
|
|
)
|
|
|
|
for key, value in self.data.items():
|
|
widget = ListItem()
|
|
widget.setHost(key)
|
|
widget.setActive(value["active"])
|
|
widget.setZoom(value["zoom"])
|
|
|
|
item = QtWidgets.QListWidgetItem(self.ui.listWidget)
|
|
item.setSizeHint(widget.sizeHint() * 1.2)
|
|
self.ui.listWidget.setItemWidget(item, widget)
|
|
|
|
self.ui.pushButtonRemove.clicked.connect(self.handleItemRemove)
|
|
self.ui.pushButtonAdd.clicked.connect(self.handleItemAdd)
|
|
|
|
self.ui.buttonBoxConfirm.accepted.connect(self.accept)
|
|
self.ui.buttonBoxConfirm.rejected.connect(self.reject)
|
|
|
|
def translations(self):
|
|
self.setWindowTitle(i18n("Auto Zoomer Settings"))
|
|
self.ui.pushButtonAdd.setText(i18n("Add"))
|
|
self.ui.pushButtonRemove.setText(i18n("Remove"))
|
|
self.ui.checkBoxEnableAutoZoomer.setText(i18n("Enable Auto Zoomer"))
|
|
self.ui.checkBoxDefaultZoom.setText(i18n("On unknown host zoom to default zoom level"))
|
|
self.ui.pushButtonClear.setText(i18n("Clear"))
|
|
|
|
def addListItem(self, host, zoom=6, active=True):
|
|
if not host:
|
|
return
|
|
|
|
if host in self.data.keys():
|
|
for i in range(0, self.ui.listWidget.count()):
|
|
item = self.ui.listWidget.item(i)
|
|
widget = self.ui.listWidget.itemWidget(item)
|
|
|
|
if widget.host() == host:
|
|
widget.setActive(active)
|
|
widget.setZoom(zoom)
|
|
|
|
break
|
|
else:
|
|
widget = ListItem()
|
|
widget.setHost(host)
|
|
widget.setActive(active)
|
|
widget.setZoom(zoom)
|
|
|
|
item = QtWidgets.QListWidgetItem(self.ui.listWidget)
|
|
item.setSizeHint(widget.sizeHint() * 1.2)
|
|
self.ui.listWidget.setItemWidget(item, widget)
|
|
|
|
def updateData(self):
|
|
self.config["active"] = self.ui.checkBoxEnableAutoZoomer.isChecked()
|
|
self.config["defaultZoom"] = self.ui.checkBoxDefaultZoom.isChecked()
|
|
self.config["shortcut"] = self.ui.keySequenceEditShortcut.keySequence().toString()
|
|
|
|
self.data.clear()
|
|
|
|
for i in range(0, self.ui.listWidget.count()):
|
|
item = self.ui.listWidget.item(i)
|
|
widget = self.ui.listWidget.itemWidget(item)
|
|
|
|
self.data[widget.host()] = {
|
|
"active": widget.active(),
|
|
"zoom": widget.zoom()
|
|
}
|
|
|
|
self.remove.clear()
|
|
|
|
for host in self.prepareRemove:
|
|
self.remove.append(host)
|
|
|
|
self.prepareRemove.clear()
|
|
|
|
def handleItemAdd(self):
|
|
host = self.ui.lineEditNew.text()
|
|
zoom = self.ui.comboBoxNew.currentIndex()
|
|
|
|
if not host:
|
|
return
|
|
|
|
self.ui.lineEditNew.clear()
|
|
|
|
self.addListItem(host, zoom=zoom)
|
|
|
|
def handleItemRemove(self):
|
|
listWidget = self.ui.listWidget
|
|
itemList = listWidget.selectedItems()
|
|
|
|
if not itemList:
|
|
return
|
|
|
|
self.prepareRemove.append(listWidget.itemWidget(itemList[-1]).host())
|
|
|
|
listWidget.takeItem(listWidget.row(itemList[-1]))
|
|
|
|
def accept(self):
|
|
self.updateData()
|
|
|
|
super().accept()
|