File indexing completed on 2024-05-12 04:58:41

0001 # ============================================================
0002 # RunAction plugin for Falkon
0003 # Copyright (C) 2018 David Rosca <nowrep@gmail.com>
0004 #
0005 # This program is free software: you can redistribute it and/or modify
0006 # it under the terms of the GNU General Public License as published by
0007 # the Free Software Foundation, either version 3 of the License, or
0008 # (at your option) any later version.
0009 #
0010 # This program is distributed in the hope that it will be useful,
0011 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 # GNU General Public License for more details.
0014 #
0015 # You should have received a copy of the GNU General Public License
0016 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 # ============================================================
0018 import Falkon
0019 from PySide6 import QtCore
0020 from runaction import actionmanager, button
0021 
0022 
0023 class RunActionPlugin(Falkon.PluginInterface, QtCore.QObject):
0024     buttons = {}
0025     manager = None
0026 
0027     def init(self, state, settingsPath):
0028         plugins = Falkon.MainApplication.instance().plugins()
0029         plugins.mainWindowCreated.connect(self.mainWindowCreated)
0030         plugins.mainWindowDeleted.connect(self.mainWindowDeleted)
0031 
0032         self.manager = actionmanager.ActionManager(settingsPath)
0033 
0034         if state == Falkon.PluginInterface.LateInitState:
0035             for window in Falkon.MainApplication.instance().windows():
0036                 self.mainWindowCreated(window)
0037 
0038     def unload(self):
0039         for window in Falkon.MainApplication.instance().windows():
0040             self.mainWindowDeleted(window)
0041 
0042         self.manager = None
0043 
0044     def testPlugin(self):
0045         return True
0046 
0047     def populateWebViewMenu(self, menu, view, r):
0048         for action in self.manager.getActions(view, r):
0049             if action.inherits("QMenu"):
0050                 menu.addMenu(action).setParent(menu)
0051             else:
0052                 action.setParent(menu)
0053                 menu.addAction(action)
0054 
0055     def showSettings(self, parent):
0056         self.manager.showSettings(parent)
0057 
0058     def mainWindowCreated(self, window):
0059         b = button.RunActionButton(self.manager)
0060         window.statusBar().addButton(b)
0061         window.navigationBar().addToolButton(b)
0062         self.buttons[window] = b
0063 
0064     def mainWindowDeleted(self, window):
0065         if window not in self.buttons:
0066             return
0067         b = self.buttons[window]
0068         window.statusBar().removeButton(b)
0069         window.navigationBar().removeToolButton(b)
0070         del self.buttons[window]
0071 
0072 
0073 Falkon.registerPlugin(RunActionPlugin())