Compare commits

..

No commits in common. "master" and "v1.1.0" have entirely different histories.

12 changed files with 71 additions and 180 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
__pycache__

View File

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

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

View File

@ -1,125 +0,0 @@
# 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)

11
unloader/Messages.sh Normal file
View File

@ -0,0 +1,11 @@
#! /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
from PySide6 import QtCore
from PySide2 import QtCore
from unloader.manager import UnloaderManager

View File

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

View File

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

View File

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

View File

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