2019-05-15 19:42:17 +02:00
|
|
|
# ============================================================
|
|
|
|
# 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
|
|
|
|
from autoZoomer.settingsDialog import SettingsDialog
|
|
|
|
from autoZoomer.str2bool import str2bool
|
|
|
|
|
|
|
|
class AutoZoomer(QtCore.QObject):
|
|
|
|
data = None
|
|
|
|
remove = None
|
|
|
|
config = None
|
|
|
|
|
|
|
|
def __init__(self, settingsPath, parent=None):
|
|
|
|
super().__init__(parent)
|
|
|
|
|
|
|
|
self.config = {
|
|
|
|
"settingsFile": os.path.join(settingsPath, "autoZoomer", "settings.ini"),
|
2019-05-15 21:30:22 +02:00
|
|
|
"active": True,
|
|
|
|
"defaultZoom": True
|
2019-05-15 19:42:17 +02:00
|
|
|
}
|
|
|
|
self.data = {}
|
|
|
|
self.remove = []
|
|
|
|
|
|
|
|
self.loadSettings()
|
|
|
|
|
|
|
|
def showSettings(self, parent=None):
|
|
|
|
settings = SettingsDialog(self.config, self.data, self.remove, parent)
|
2019-05-16 19:46:43 +02:00
|
|
|
settings.accepted.connect(self.saveSettings)
|
2019-05-15 19:42:17 +02:00
|
|
|
settings.exec_()
|
|
|
|
|
|
|
|
def loadSettings(self):
|
|
|
|
settings = QtCore.QSettings(self.config["settingsFile"], QtCore.QSettings.IniFormat)
|
|
|
|
|
|
|
|
settings.beginGroup("AutoZoomer")
|
|
|
|
self.config["active"] = str2bool(settings.value("active", True))
|
2019-05-15 21:30:22 +02:00
|
|
|
self.config["defaultZoom"] = str2bool(settings.value("defaultZoom", True))
|
2019-05-15 19:42:17 +02:00
|
|
|
settings.endGroup()
|
|
|
|
|
|
|
|
for group in settings.childGroups():
|
|
|
|
if group == "AutoZoomer":
|
|
|
|
continue
|
|
|
|
|
|
|
|
settings.beginGroup(group)
|
|
|
|
self.data[group] = {
|
|
|
|
"active": str2bool(settings.value("active", False)),
|
|
|
|
"zoom": int(settings.value("zoom", 6))
|
|
|
|
}
|
|
|
|
settings.endGroup()
|
|
|
|
|
|
|
|
def saveSettings(self):
|
|
|
|
settings = QtCore.QSettings(self.config["settingsFile"], QtCore.QSettings.IniFormat)
|
|
|
|
|
|
|
|
settings.beginGroup("AutoZoomer")
|
|
|
|
settings.setValue("active", self.config["active"])
|
2019-05-15 21:30:22 +02:00
|
|
|
settings.setValue("defaultZoom", self.config["defaultZoom"])
|
2019-05-15 19:42:17 +02:00
|
|
|
settings.endGroup()
|
|
|
|
|
|
|
|
for host in self.remove:
|
|
|
|
settings.remove(host)
|
|
|
|
self.remove.clear()
|
|
|
|
|
|
|
|
for key, value in self.data.items():
|
|
|
|
settings.beginGroup(key)
|
|
|
|
settings.setValue("active", value["active"])
|
|
|
|
settings.setValue("zoom", value["zoom"])
|
|
|
|
settings.endGroup()
|
|
|
|
|
|
|
|
settings.sync()
|
|
|
|
|
|
|
|
def onLoadFinished(self, page):
|
|
|
|
if not self.config["active"]:
|
|
|
|
return
|
|
|
|
|
|
|
|
view = page.view()
|
|
|
|
host = page.url().host()
|
|
|
|
|
|
|
|
if host in self.data.keys():
|
|
|
|
if self.data[host]["active"]:
|
2019-05-17 18:31:13 +02:00
|
|
|
if view.zoomLevel() != self.data[host]["zoom"]:
|
|
|
|
view.setZoomLevel(self.data[host]["zoom"])
|
2019-05-15 21:30:22 +02:00
|
|
|
elif self.config["defaultZoom"]:
|
2019-05-17 18:31:13 +02:00
|
|
|
defaultZoom = Falkon.Settings.staticSettings().defaultZoomLevel
|
|
|
|
|
|
|
|
if view.zoomLevel() != defaultZoom:
|
|
|
|
view.setZoomLevel(defaultZoom)
|
2019-05-15 19:42:17 +02:00
|
|
|
|
|
|
|
def addItem(self, host, zoom=6, active=True):
|
|
|
|
if not host:
|
|
|
|
return
|
|
|
|
|
|
|
|
if host in self.data.keys():
|
|
|
|
self.data[host]["zoom"] = zoom
|
|
|
|
self.data[host]["active"] = active
|
|
|
|
else:
|
|
|
|
self.data[host] = {
|
|
|
|
"active": active,
|
|
|
|
"zoom": zoom
|
|
|
|
}
|