2019-06-24 23:33:59 +02:00
|
|
|
# Toolbar Tools - Falkon plugin
|
|
|
|
# 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/>.
|
|
|
|
|
2019-06-24 20:57:25 +02:00
|
|
|
import Falkon
|
2019-06-24 23:33:59 +02:00
|
|
|
import os
|
2024-12-07 15:43:56 +01:00
|
|
|
from PySide6 import QtCore
|
2019-06-26 00:59:35 +02:00
|
|
|
from toolbartools.Config import Config
|
2019-06-24 23:33:59 +02:00
|
|
|
from toolbartools.Spacer import Spacer
|
2019-06-25 12:31:08 +02:00
|
|
|
from toolbartools.Separator import Separator
|
2019-06-26 09:53:43 +02:00
|
|
|
from toolbartools.settingsDialog import SettingsDialog
|
2019-06-24 20:57:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
|
2019-06-24 23:33:59 +02:00
|
|
|
spacers = None
|
2019-06-25 12:31:08 +02:00
|
|
|
separators = None
|
2019-06-24 23:33:59 +02:00
|
|
|
config = None
|
|
|
|
|
2019-06-24 20:57:25 +02:00
|
|
|
def init(self, state, settingsPath):
|
2019-06-24 23:33:59 +02:00
|
|
|
self.spacers = {}
|
2019-06-25 12:31:08 +02:00
|
|
|
self.separators = {}
|
2019-06-24 23:33:59 +02:00
|
|
|
|
2019-06-26 00:59:35 +02:00
|
|
|
self.config = Config()
|
|
|
|
self.config.settingsFile = os.path.join(settingsPath, "ToolbarTools", "settings.ini")
|
2019-06-26 09:00:33 +02:00
|
|
|
self.config.load()
|
2019-06-24 23:33:59 +02:00
|
|
|
|
2019-06-26 16:28:08 +02:00
|
|
|
self.config.spacerCountChanged.connect(self.onSpacerCountChanged)
|
|
|
|
self.config.separatorCountChanged.connect(self.onSeparatorCountChanged)
|
|
|
|
|
2019-06-24 20:57:25 +02:00
|
|
|
plugins = Falkon.MainApplication.instance().plugins()
|
|
|
|
|
|
|
|
plugins.mainWindowCreated.connect(self.onMainWindowCreated)
|
|
|
|
plugins.mainWindowDeleted.connect(self.mainWindowDeleted)
|
|
|
|
|
|
|
|
if state == Falkon.PluginInterface.LateInitState:
|
|
|
|
for window in Falkon.MainApplication.instance().windows():
|
|
|
|
self.onMainWindowCreated(window)
|
|
|
|
|
|
|
|
def unload(self):
|
2019-06-26 09:00:33 +02:00
|
|
|
self.config.save()
|
|
|
|
|
2019-06-24 20:57:25 +02:00
|
|
|
for window in Falkon.MainApplication.instance().windows():
|
|
|
|
self.mainWindowDeleted(window)
|
|
|
|
|
|
|
|
def testPlugin(self):
|
|
|
|
return True
|
|
|
|
|
2019-06-26 09:53:43 +02:00
|
|
|
def showSettings(self, parent):
|
|
|
|
settings = SettingsDialog(self.config, parent)
|
|
|
|
settings.exec_()
|
|
|
|
|
2019-06-26 16:28:08 +02:00
|
|
|
def addSpacer(self, window, id):
|
|
|
|
spacer = Spacer(id, self.config.spacerMaxWidth)
|
|
|
|
self.config.spacerMaxWidthChanged.connect(spacer.setMaximumWidth)
|
|
|
|
window.navigationBar().addWidget(spacer, spacer.id(), spacer.name())
|
2019-06-24 23:33:59 +02:00
|
|
|
|
2019-06-26 16:28:08 +02:00
|
|
|
if window not in self.spacers:
|
|
|
|
self.spacers[window] = {}
|
|
|
|
if id not in self.spacers[window]:
|
2019-06-24 23:33:59 +02:00
|
|
|
self.spacers[window][id] = spacer
|
2019-06-24 20:57:25 +02:00
|
|
|
|
2019-06-26 16:28:08 +02:00
|
|
|
def addSeparator(self, window, id):
|
|
|
|
separator = Separator(id, self.config.separatorWidth)
|
|
|
|
self.config.separatorWidthChanged.connect(separator.setMinimumWidth)
|
|
|
|
window.navigationBar().addWidget(separator, separator.id(), separator.name())
|
2019-06-25 12:31:08 +02:00
|
|
|
|
2019-06-26 16:28:08 +02:00
|
|
|
if window not in self.separators:
|
|
|
|
self.separators[window] = {}
|
|
|
|
if id not in self.separators[window]:
|
2019-06-25 12:31:08 +02:00
|
|
|
self.separators[window][id] = separator
|
|
|
|
|
2019-06-26 16:28:08 +02:00
|
|
|
def onSpacerCountChanged(self, count):
|
|
|
|
count = count + 1
|
|
|
|
|
|
|
|
for window in Falkon.MainApplication.instance().windows():
|
|
|
|
if window in self.spacers:
|
|
|
|
lenght = len(self.spacers[window]) + 1
|
|
|
|
|
|
|
|
if count > lenght:
|
|
|
|
for id in range(lenght, count):
|
|
|
|
self.addSpacer(window, id)
|
|
|
|
elif count < lenght:
|
|
|
|
for id in range(count, lenght):
|
|
|
|
if id in self.spacers[window]:
|
|
|
|
window.navigationBar().removeWidget(self.spacers[window][id].id())
|
|
|
|
del self.spacers[window][id]
|
|
|
|
|
|
|
|
def onSeparatorCountChanged(self, count):
|
|
|
|
count = count + 1
|
|
|
|
|
|
|
|
for window in Falkon.MainApplication.instance().windows():
|
|
|
|
if window in self.separators:
|
|
|
|
lenght = len(self.separators[window]) + 1
|
|
|
|
|
|
|
|
if count > lenght:
|
|
|
|
for id in range(lenght, count):
|
|
|
|
self.addSeparator(window, id)
|
|
|
|
elif count < lenght:
|
|
|
|
for id in range(count, lenght):
|
|
|
|
if id in self.separators[window]:
|
|
|
|
window.navigationBar().removeWidget(self.separators[window][id].id())
|
|
|
|
del self.separators[window][id]
|
|
|
|
|
|
|
|
def onMainWindowCreated(self, window):
|
|
|
|
for id in range(1, self.config.spacerCount + 1):
|
|
|
|
self.addSpacer(window, id)
|
|
|
|
|
|
|
|
for id in range(1, self.config.separatorCount + 1):
|
|
|
|
self.addSeparator(window, id)
|
|
|
|
|
2019-06-24 20:57:25 +02:00
|
|
|
def mainWindowDeleted(self, window):
|
2019-06-24 23:33:59 +02:00
|
|
|
if window in self.spacers:
|
|
|
|
for id, spacer in list(self.spacers[window].items()):
|
|
|
|
window.navigationBar().removeWidget(spacer.id())
|
|
|
|
del self.spacers[window][id]
|
|
|
|
del self.spacers[window]
|
2019-06-24 20:57:25 +02:00
|
|
|
|
2019-06-25 12:31:08 +02:00
|
|
|
if window in self.separators:
|
|
|
|
for id, separator in list(self.separators[window].items()):
|
|
|
|
window.navigationBar().removeWidget(separator.id())
|
|
|
|
del self.separators[window][id]
|
|
|
|
del self.separators[window]
|
|
|
|
|
2019-06-24 20:57:25 +02:00
|
|
|
|
|
|
|
Falkon.registerPlugin(ToolbarTools())
|