Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
1da3a86ba2 | |||
fd218ba841 | |||
1aee607573 | |||
65b7b8b562 | |||
cac7ff84ae | |||
34f2a78fbe | |||
97db403adc | |||
551bc468de | |||
629788068e | |||
b87c793229 | |||
1db4510e61 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
__pycache__
|
@ -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
11
Messages.sh
Normal 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
|
@ -1,12 +1,16 @@
|
|||||||
# Unloader
|
# Unloader
|
||||||
|
|
||||||
Plugin for [Falkon](https://www.falkon.org/) web browser.
|
Plugin for [Falkon](https://www.falkon.org/) web browser.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## 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/`
|
||||||
|
BIN
screenshots/settingsWindow.png
Normal file
BIN
screenshots/settingsWindow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
125
unloader/Config.py
Normal file
125
unloader/Config.py
Normal 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)
|
@ -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
|
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
@ -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 = [
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user