diff --git a/unloader/__init__.py b/unloader/__init__.py
index efd72a6..3c4cf01 100644
--- a/unloader/__init__.py
+++ b/unloader/__init__.py
@@ -46,7 +46,7 @@ class UnloaderPlugin(Falkon.PluginInterface, QtCore.QObject):
return True
def showSettings(self, parent):
- pass
+ self.manager.showSettings(parent)
Falkon.registerPlugin(UnloaderPlugin())
diff --git a/unloader/manager.py b/unloader/manager.py
index 482d68e..13d4ae1 100644
--- a/unloader/manager.py
+++ b/unloader/manager.py
@@ -19,34 +19,37 @@
"""
import Falkon
+import os
from PySide2 import QtCore
+from unloader.settingsDialog import SettingsDialog
class UnloaderManager(QtCore.QObject):
tabs = None
timer = None
- threshold = None
config = None
+ configChanged = QtCore.Signal()
+
def __init__(self, settingsPath, parent=None):
super().__init__(parent)
self.config = {
- "settingsPath": settingsPath,
+ "settingsFile": os.path.join(settingsPath, "unloader", "settings.ini"),
"threshold": 600,
"updateInterval": 5
}
- self.threshold = self.config["threshold"]
+ self.tabs = {}
self.timer = QtCore.QTimer(self)
self.timer.setTimerType(QtCore.Qt.VeryCoarseTimer)
- self.timer.setInterval(5000)
-
+ self.timer.setInterval(self.config["updateInterval"] * 1000)
self.timer.timeout.connect(self.onTimeout)
-
self.timer.start()
+ self.configChanged.connect(self.onConfigChanged)
+
def onMainWindowCreated(self, window):
tabs = window.tabWidget().allTabs()
@@ -84,8 +87,8 @@ class UnloaderManager(QtCore.QObject):
self.tabs[tab] = time + int(self.timer.interval() / 1000)
- if self.threshold:
- if self.tabs[tab] > self.threshold and tab.isRestored():
+ if self.config["threshold"]:
+ if self.tabs[tab] > self.config["threshold"] and tab.isRestored():
self.tabs[tab] = 0
tab.unload()
@@ -98,3 +101,32 @@ class UnloaderManager(QtCore.QObject):
for tab in winTabs:
self.tabs[tab] = oldTabs.get(tab, 0)
+
+ def loadSettings(self):
+ settings = QtCore.QSettings(self.config["settingsFile"], QtCore.QSettings.IniFormat)
+
+ settings.beginGroup("Unloader")
+ self.config["threshold"] = int(settings.value("active", self.config["threshold"]))
+ self.config["updateInterval"] = int(
+ settings.value("defaultZoom", self.config["updateInterval"])
+ )
+ settings.endGroup()
+
+ def saveSettings(self):
+ settings = QtCore.QSettings(self.config["settingsFile"], QtCore.QSettings.IniFormat)
+
+ settings.beginGroup("Unloader")
+ settings.setValue("threshold", self.config["threshold"])
+ settings.setValue("updateInterval", self.config["updateInterval"])
+ settings.endGroup()
+
+ settings.sync()
+
+ def showSettings(self, parent=None):
+ settings = SettingsDialog(self.config, parent)
+ settings.accepted.connect(self.saveSettings)
+ settings.accepted.connect(self.configChanged)
+ settings.exec_()
+
+ def onConfigChanged(self):
+ self.timer.setInterval(self.config["updateInterval"] * 1000)
diff --git a/unloader/settings.ui b/unloader/settings.ui
new file mode 100644
index 0000000..4e577da
--- /dev/null
+++ b/unloader/settings.ui
@@ -0,0 +1,88 @@
+
+
+ SettingsDialog
+
+
+
+ 0
+ 0
+ 412
+ 118
+
+
+
+ Unloader Settings
+
+
+ -
+
+
-
+
+
-
+
+
+ Update interval (in seconds):
+
+
+
+ -
+
+
+ QAbstractSpinBox::PlusMinus
+
+
+ 5
+
+
+ 60
+
+
+ 5
+
+
+
+ -
+
+
+ Discard inactive tab after (in seconds):
+
+
+
+ -
+
+
+ QAbstractSpinBox::PlusMinus
+
+
+ 60
+
+
+ 86400
+
+
+ 10
+
+
+ 600
+
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+
+
+
+
+
+
+
diff --git a/unloader/settingsDialog.py b/unloader/settingsDialog.py
new file mode 100644
index 0000000..144e18a
--- /dev/null
+++ b/unloader/settingsDialog.py
@@ -0,0 +1,65 @@
+# ============================================================
+# Unloader - 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, QtGui, QtWidgets, QtUiTools
+from unloader.i18n import i18n
+
+
+class SettingsDialog(QtWidgets.QDialog):
+ ui = None
+ config = None
+
+ def __init__(self, config, remove, parent=None):
+ super().__init__(parent)
+
+ self.config = config
+
+ 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()
+
+ self.ui.updateIntervalSpinBox.setValue(self.config["updateInterval"])
+ self.ui.discardInactiveTabAfterSpinBox.setValue(self.config["threshold"])
+
+ self.ui.buttonBoxConfirm.accepted.connect(self.accept)
+ self.ui.buttonBoxConfirm.rejected.connect(self.reject)
+
+ def translations(self):
+ self.setWindowTitle(i18n("Unloader Settings"))
+ self.ui.updateIntervalLabel.setText(i18n("Update interval (in seconds):"))
+ self.ui.discardInactiveTabAfterLabel.setText(
+ i18n("Discard inactive tab after (in seconds):")
+ )
+
+ def updateData(self):
+ self.config["updateInterval"] = self.ui.updateIntervalSpinBox.value()
+ self.config["threshold"] = self.ui.discardInactiveTabAfterSpinBox.value()
+
+ def accept(self):
+ self.updateData()
+
+ super().accept()