Compare commits

...

11 Commits

Author SHA1 Message Date
1da3a86ba2 Port to PySide6
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
2024-12-07 15:13:22 +01:00
fd218ba841
SettingsDialog: Fix typo
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
2019-09-27 14:57:46 +02:00
1aee607573
Update CHANGELOG
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
2019-09-27 14:55:26 +02:00
65b7b8b562
settingsDialog: Remove unneeded imports
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
2019-09-26 23:57:56 +02:00
cac7ff84ae
Move Messages.sh to top level; update copyright
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
2019-07-01 13:37:33 +02:00
34f2a78fbe
Manager: Use signals provided by Config
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
2019-07-01 13:27:07 +02:00
97db403adc
Move settings load and save methods into Config
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
2019-07-01 13:20:42 +02:00
551bc468de
SettingsDialog: Remove unused variable from init
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
2019-06-29 00:53:01 +02:00
629788068e
Move config from dictionary to Config class
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
2019-06-29 00:45:16 +02:00
b87c793229
Add Config class
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
2019-06-29 00:44:53 +02:00
1db4510e61
Improve README
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
2019-06-28 23:11:04 +02:00
12 changed files with 180 additions and 71 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__

View File

@ -1,3 +1,9 @@
1.3.0:
- Port to PySide6
1.2.0:
- Refactoring - Config
1.1.0: 1.1.0:
- Fix loading settings - Fix loading settings
- Hook into tab restoreChanged event - Hook into tab restoreChanged event

11
Messages.sh Normal file
View File

@ -0,0 +1,11 @@
#! /bin/sh
XGETTEXT_FLAGS_PYTHON="\
--copyright-holder=Juraj_Oravec \
--msgid-bugs-address=https://github.com/SGOrava/Unloader/issues \
--from-code=UTF-8 \
-L Python \
-ki18n:1 -ki18np:1,2 \
"
$XGETTEXT_PROGRAM $XGETTEXT_FLAGS_PYTHON `find ./unloader -name '*.py'` -o $podir/unloader.pot

View File

@ -1,12 +1,16 @@
# Unloader # Unloader
Plugin for [Falkon](https://www.falkon.org/) web browser. Plugin for [Falkon](https://www.falkon.org/) web browser.
![Settings Window](screenshots/settingsWindow.png)
## Description ## Description
Unload unused tab after set time. Unload unused tab after set time.
Optionally close unloaded tabs after set time.
## Installation ## Installation
### Automatic ### Automatic
Go to https://store.falkon.org/p/1307514/ press `Install` and follow the instructions. Go to [Falkon store](https://store.falkon.org/p/1307514/) press `Install` and follow the instructions.
### Manual ### Manual
Copy the `unloader` directory into `~/.config/falkon/plugins/` Copy the `unloader` directory into `~/.config/falkon/plugins/`

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

125
unloader/Config.py Normal file
View File

@ -0,0 +1,125 @@
# Unloader - 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 os
from PySide6.QtCore import QObject, Signal, QSettings
class Config(QObject):
updateIntervalChanged = Signal(int)
closeThresholdChanged = Signal(int)
thresholdChanged = Signal(int)
settingsFileChanged = Signal(str)
configLoaded = Signal()
configSaved = Signal()
def __init__(self, updateInterval=None, closeThreshold=None, threshold=None, settingsFile=None):
super().__init__()
self._updateInterval = updateInterval
self._closeThreshold = closeThreshold
self._threshold = threshold
self._settingsFile = settingsFile
def load(self):
if not self.settingsFile:
return
if os.path.exists(self.settingsFile):
pass
settings = QSettings(self.settingsFile, QSettings.IniFormat)
settings.beginGroup("Unloader")
self.threshold = int(settings.value("threshold", self.threshold))
self.closeThreshold = int(
settings.value("closeThreshold", self.closeThreshold)
)
self.updateInterval = int(
settings.value("defaultZoom", self.updateInterval)
)
settings.endGroup()
self.configLoaded.emit()
def save(self):
settings = QSettings(self.settingsFile, QSettings.IniFormat)
settings.beginGroup("Unloader")
settings.setValue("threshold", self.threshold)
settings.setValue("closeThreshold", self.closeThreshold)
settings.setValue("updateInterval", self.updateInterval)
settings.endGroup()
settings.sync()
self.configSaved.emit()
@property
def updateInterval(self):
return self._updateInterval
@updateInterval.setter
def updateInterval(self, updateInterval):
if updateInterval < 1:
return
if self._updateInterval == updateInterval:
return
self._updateInterval = updateInterval
self.updateIntervalChanged.emit(updateInterval)
@property
def closeThreshold(self):
return self._closeThreshold
@closeThreshold.setter
def closeThreshold(self, closeThreshold):
if closeThreshold < 0:
return
if self._closeThreshold == closeThreshold:
return
self._closeThreshold = closeThreshold
self.closeThresholdChanged.emit(closeThreshold)
@property
def threshold(self):
return self._threshold
@threshold.setter
def threshold(self, threshold):
if threshold < 1:
return
if self._threshold == threshold:
return
self._threshold = threshold
self.thresholdChanged.emit(threshold)
@property
def settingsFile(self):
return self._settingsFile
@settingsFile.setter
def settingsFile(self, settingsFile):
if not settingsFile:
return
if self._settingsFile == settingsFile:
return
self._settingsFile = settingsFile
self.settingsFileChanged.emit(settingsFile)

View File

@ -1,11 +0,0 @@
#! /bin/sh
XGETTEXT_FLAGS_PYTHON="\
--copyright-holder=This_file_is_part_of_KDE \
--msgid-bugs-address=http://bugs.kde.org \
--from-code=UTF-8 \
-L Python \
-ki18n:1 -ki18np:1,2 \
"
$XGETTEXT_PROGRAM $XGETTEXT_FLAGS_PYTHON `find . -name '*.py'` -o $podir/unloader.pot

View File

@ -18,7 +18,7 @@
# ============================================================ # ============================================================
""" """
import Falkon import Falkon
from PySide2 import QtCore from PySide6 import QtCore
from unloader.manager import UnloaderManager from unloader.manager import UnloaderManager

View File

@ -18,7 +18,7 @@
# ============================================================ # ============================================================
import gettext import gettext
import os import os
from PySide2 import QtCore from PySide6 import QtCore
locale = QtCore.QLocale.system() locale = QtCore.QLocale.system()
languages = [ languages = [

View File

@ -20,7 +20,8 @@
import Falkon import Falkon
import os import os
from PySide2 import QtCore from PySide6 import QtCore
from unloader.Config import Config
from unloader.settingsDialog import SettingsDialog from unloader.settingsDialog import SettingsDialog
@ -29,28 +30,26 @@ class UnloaderManager(QtCore.QObject):
timer = None timer = None
config = None config = None
configChanged = QtCore.Signal()
def __init__(self, settingsPath, parent=None): def __init__(self, settingsPath, parent=None):
super().__init__(parent) super().__init__(parent)
self.config = { self.config = Config(
"settingsFile": os.path.join(settingsPath, "unloader", "settings.ini"), settingsFile=os.path.join(settingsPath, "unloader", "settings.ini"),
"threshold": 600, threshold=600,
"closeThreshold": 0, closeThreshold=0,
"updateInterval": 5 updateInterval=5
} )
self.loadSettings() self.config.load()
self.tabs = {} self.tabs = {}
self.timer = QtCore.QTimer(self) self.timer = QtCore.QTimer(self)
self.timer.setTimerType(QtCore.Qt.VeryCoarseTimer) self.timer.setTimerType(QtCore.Qt.VeryCoarseTimer)
self.timer.setInterval(self.config["updateInterval"] * 1000) self.timer.setInterval(self.config.updateInterval * 1000)
self.timer.timeout.connect(self.onTimeout) self.timer.timeout.connect(self.onTimeout)
self.timer.start() self.timer.start()
self.configChanged.connect(self.onConfigChanged) self.config.updateIntervalChanged.connect(self.onUpdateIntervalChanged)
def onMainWindowCreated(self, window): def onMainWindowCreated(self, window):
tabs = window.tabWidget().allTabs() tabs = window.tabWidget().allTabs()
@ -98,14 +97,14 @@ class UnloaderManager(QtCore.QObject):
self.tabs[tab] = time + int(self.timer.interval() / 1000) self.tabs[tab] = time + int(self.timer.interval() / 1000)
if not tab.isRestored() and self.config["closeThreshold"]: if not tab.isRestored() and self.config.closeThreshold:
if self.tabs[tab] > self.config["closeThreshold"]: if self.tabs[tab] > self.config.closeThreshold:
del self.tabs[tab] del self.tabs[tab]
tab.closeTab() tab.closeTab()
continue continue
if self.config["threshold"]: if self.config.threshold:
if self.tabs[tab] > self.config["threshold"] and tab.isRestored(): if self.tabs[tab] > self.config.threshold and tab.isRestored():
self.tabs[tab] = 0 self.tabs[tab] = 0
tab.unload() tab.unload()
@ -124,38 +123,13 @@ class UnloaderManager(QtCore.QObject):
lambda r: self.onTabRestoredChanged(tab, r) lambda r: self.onTabRestoredChanged(tab, r)
) )
def loadSettings(self):
settings = QtCore.QSettings(self.config["settingsFile"], QtCore.QSettings.IniFormat)
settings.beginGroup("Unloader")
self.config["threshold"] = int(settings.value("threshold", self.config["threshold"]))
self.config["closeThreshold"] = int(
settings.value("closeThreshold", self.config["closeThreshold"])
)
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("closeThreshold", self.config["closeThreshold"])
settings.setValue("updateInterval", self.config["updateInterval"])
settings.endGroup()
settings.sync()
def showSettings(self, parent=None): def showSettings(self, parent=None):
settings = SettingsDialog(self.config, parent) settings = SettingsDialog(self.config, parent)
settings.accepted.connect(self.saveSettings) settings.accepted.connect(self.config.save)
settings.accepted.connect(self.configChanged)
settings.exec_() settings.exec_()
def onConfigChanged(self): def onUpdateIntervalChanged(self, interval):
self.timer.setInterval(self.config["updateInterval"] * 1000) self.timer.setInterval(interval * 1000)
def onTabRestoredChanged(self, tab, restored): def onTabRestoredChanged(self, tab, restored):
self.tabs[tab] = 0 self.tabs[tab] = 0

View File

@ -6,6 +6,6 @@ Type=Service
X-Falkon-Type=Extension/Python X-Falkon-Type=Extension/Python
X-Falkon-Author=Juraj Oravec X-Falkon-Author=Juraj Oravec
X-Falkon-Email=sgd.orava@gmail.com X-Falkon-Email=jurajoravec@mailo.com
X-Falkon-Version=1.1.0 X-Falkon-Version=1.3.0
X-Falkon-Settings=true X-Falkon-Settings=true

View File

@ -16,9 +16,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# ============================================================ # ============================================================
import Falkon
import os import os
from PySide2 import QtCore, QtGui, QtWidgets, QtUiTools from PySide6 import QtCore, QtWidgets, QtUiTools
from unloader.i18n import i18n from unloader.i18n import i18n
@ -26,7 +25,7 @@ class SettingsDialog(QtWidgets.QDialog):
ui = None ui = None
config = None config = None
def __init__(self, config, remove, parent=None): def __init__(self, config, parent=None):
super().__init__(parent) super().__init__(parent)
self.config = config self.config = config
@ -42,9 +41,9 @@ class SettingsDialog(QtWidgets.QDialog):
self.translations() self.translations()
self.ui.updateIntervalSpinBox.setValue(self.config["updateInterval"]) self.ui.updateIntervalSpinBox.setValue(self.config.updateInterval)
self.ui.discardInactiveTabAfterSpinBox.setValue(self.config["threshold"]) self.ui.discardInactiveTabAfterSpinBox.setValue(self.config.threshold)
self.ui.closeTabForSpinBox.setValue(self.config["closeThreshold"]) self.ui.closeTabForSpinBox.setValue(self.config.closeThreshold)
self.ui.buttonBoxConfirm.accepted.connect(self.accept) self.ui.buttonBoxConfirm.accepted.connect(self.accept)
self.ui.buttonBoxConfirm.rejected.connect(self.reject) self.ui.buttonBoxConfirm.rejected.connect(self.reject)
@ -56,13 +55,13 @@ class SettingsDialog(QtWidgets.QDialog):
i18n("Discard inactive tab after (in seconds):") i18n("Discard inactive tab after (in seconds):")
) )
self.ui.closeTabWhenUnloadedForLabel.setText( self.ui.closeTabWhenUnloadedForLabel.setText(
i18n("Close tab when unloaded for:") i18n("Close tab when unloaded for (in seconds):")
) )
def updateData(self): def updateData(self):
self.config["updateInterval"] = self.ui.updateIntervalSpinBox.value() self.config.updateInterval = self.ui.updateIntervalSpinBox.value()
self.config["threshold"] = self.ui.discardInactiveTabAfterSpinBox.value() self.config.threshold = self.ui.discardInactiveTabAfterSpinBox.value()
self.config["closeThreshold"] = self.ui.closeTabForSpinBox.value() self.config.closeThreshold = self.ui.closeTabForSpinBox.value()
def accept(self): def accept(self):
self.updateData() self.updateData()