diff --git a/readability/__init__.py b/readability/__init__.py index 3bb4a68..8d2a587 100644 --- a/readability/__init__.py +++ b/readability/__init__.py @@ -1,12 +1,20 @@ import Falkon import os from PySide2 import QtCore, QtGui +from readability.settingsDialog import SettingsDialog class Readability(Falkon.PluginInterface, QtCore.QObject): view = None + config = None def init(self, state, settingsPath): + self.config = { + "settingsFile": os.path.join(settingsPath, "readability", "settings.ini"), + "icon": "dark" + } + self.loadSettings() + plugins = Falkon.MainApplication.instance().plugins() plugins.mainWindowCreated.connect(self.onMainWindowCreated) @@ -37,8 +45,9 @@ class Readability(Falkon.PluginInterface, QtCore.QObject): and hitTestResult.mediaUrl().isEmpty() and not hitTestResult.isContentEditable() and not hitTestResult.isContentSelected()): + icon = "icon-light.png" if self.config["icon"] == "light" else "icon-dark.png" menu.addAction( - QtGui.QIcon(os.path.join(os.path.dirname(__file__), "data", "icon.png")), + QtGui.QIcon(os.path.join(os.path.dirname(__file__), "data", icon)), "Readability", self.makeReadability ) @@ -94,5 +103,26 @@ class Readability(Falkon.PluginInterface, QtCore.QObject): self.view.page().runJavaScript(call) + def showSettings(self, parent): + settings = SettingsDialog(self.config, parent) + settings.accepted.connect(self.saveSettings) + settings.exec_() + + def saveSettings(self): + settings = QtCore.QSettings(self.config["settingsFile"], QtCore.QSettings.IniFormat) + + settings.beginGroup("Readability") + settings.setValue("icon", self.config["icon"]) + settings.endGroup() + + settings.sync() + + def loadSettings(self): + settings = QtCore.QSettings(self.config["settingsFile"], QtCore.QSettings.IniFormat) + + settings.beginGroup("Readability") + self.config["icon"] = str(settings.value("icon", self.config["icon"])) + settings.endGroup() + Falkon.registerPlugin(Readability()) diff --git a/readability/data/icon.png b/readability/data/icon-dark.png similarity index 100% rename from readability/data/icon.png rename to readability/data/icon-dark.png diff --git a/readability/data/icon-light.png b/readability/data/icon-light.png new file mode 100644 index 0000000..80e0ee4 Binary files /dev/null and b/readability/data/icon-light.png differ diff --git a/readability/i18n.py b/readability/i18n.py new file mode 100644 index 0000000..3db8440 --- /dev/null +++ b/readability/i18n.py @@ -0,0 +1,40 @@ +# ============================================================ +# Falkon - Qt web browser +# Copyright (C) 2018 David Rosca +# Copyright (C) 2019 Juraj Oravec +# +# 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 . +# ============================================================ +import gettext +import os +from PySide2 import QtCore + +locale = QtCore.QLocale.system() +languages = [ + locale.name(), + locale.bcp47Name() +] +i = locale.name().find('_') +if i > 0: + languages.append(locale.name()[:i]) + +localedir = QtCore.QStandardPaths.locate( + QtCore.QStandardPaths.GenericDataLocation, + os.path.join(os.path.dirname(__file__), "locale"), + QtCore.QStandardPaths.LocateDirectory +) + +t = gettext.translation(__package__, localedir, languages, fallback=True) +i18n = t.gettext +i18np = t.ngettext diff --git a/readability/metadata.desktop b/readability/metadata.desktop index 30584a1..7ff65fa 100644 --- a/readability/metadata.desktop +++ b/readability/metadata.desktop @@ -2,11 +2,11 @@ Name=Readability Comment=Transform webpage to easy reading. -Icon=data/icon.png +Icon=data/icon-dark.png Type=Service X-Falkon-Type=Extension/Python X-Falkon-Author=Juraj Oravec X-Falkon-Email=sgd.orava@gmail.com X-Falkon-Version=1.0.0 -X-Falkon-Settings=false +X-Falkon-Settings=true diff --git a/readability/settingsDialog.py b/readability/settingsDialog.py new file mode 100644 index 0000000..766feaa --- /dev/null +++ b/readability/settingsDialog.py @@ -0,0 +1,62 @@ +# ============================================================ +# Auto Zoomer - plugin for Falkon +# Copyright (C) 2019 Juraj Oravec +# +# 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 . +# ============================================================ + +import Falkon +import os +from PySide2 import QtCore, QtWidgets, QtUiTools +from readability.i18n import i18n + + +class SettingsDialog(QtWidgets.QDialog): + ui = None + config = None + + def __init__(self, config, parent=None): + super().__init__(parent) + + self.config = config + + file = QtCore.QFile(os.path.join(os.path.dirname(__file__), "settingsDialog.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() + + self.ui.radioButtonLight.setChecked(self.config["icon"] == "light") + self.ui.radioButtonDark.setChecked(self.config["icon"] == "dark") + + self.ui.buttonBoxConfirm.accepted.connect(self.accept) + self.ui.buttonBoxConfirm.rejected.connect(self.reject) + + def translations(self): + self.setWindowTitle(i18n("Readability Settings")) + self.ui.radioButtonLight.setText(i18n("Light")) + self.ui.radioButtonDark.setText(i18n("Dark")) + + def updateData(self): + self.config["icon"] = "light" if self.ui.radioButtonLight.isChecked() else "dark" + + def accept(self): + self.updateData() + + super().accept() diff --git a/readability/settingsDialog.ui b/readability/settingsDialog.ui new file mode 100644 index 0000000..9e00d5f --- /dev/null +++ b/readability/settingsDialog.ui @@ -0,0 +1,58 @@ + + + Form + + + + 0 + 0 + 399 + 180 + + + + Readability Settings + + + + + + + + true + + + Menu icon: + + + + + + Light + + + + + + + Dark + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + +