1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

RunAction: Fix string conversion from bytestring, correct codestyle

Summary:
- Fix action execution when url wrongly converted to string as bytestring.
  This resulted in not working actions (loading b"b"url"")
- Make codestyle more pythonic
- Remove not required imports
- Configue dialog:
 - Set label weight to bold in QtDesigner (UI file)
 - Make listview scroll per pixel

Reviewers: #falkon, drosca

Reviewed By: #falkon, drosca

Subscribers: falkon

Tags: #falkon

Differential Revision: https://phabricator.kde.org/D21718
This commit is contained in:
Juraj Oravec 2019-06-10 12:04:47 +02:00 committed by David Rosca
parent 44730ae16d
commit 493421dd84
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
6 changed files with 38 additions and 15 deletions

View File

@ -16,9 +16,13 @@
# 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 Falkon
import os, re, enum, shlex import os
import re
import enum
import shlex
from PySide2 import QtCore, QtGui from PySide2 import QtCore, QtGui
class Action(): class Action():
class Type(enum.Enum): class Type(enum.Enum):
Invalid, Url, Command = range(3) Invalid, Url, Command = range(3)
@ -53,19 +57,22 @@ class Action():
self.supported = data.tryExec() self.supported = data.tryExec()
def testAction(self, condition, url): def testAction(self, condition, url):
if not self.supported: return False if not self.supported:
if not condition in self.typeCondition: return False return False
if not re.match(self.urlCondition, url.toString()): return False if condition not in self.typeCondition:
return False
if not re.match(self.urlCondition, url.toString()):
return False
return True return True
def execAction(self, url, text=""): def execAction(self, url, text=""):
url = str(url.toEncoded()) url = str(url.toEncoded(), "utf-8")
if self.actionType == Action.Type.Command: if self.actionType == Action.Type.Command:
url = shlex.quote(url) url = shlex.quote(url)
text = shlex.quote(text) text = shlex.quote(text)
elif self.actionType == Action.Type.Url: elif self.actionType == Action.Type.Url:
url = str(QtCore.QUrl.toPercentEncoding(url)) url = str(QtCore.QUrl.toPercentEncoding(url), "utf-8")
text = str(QtCore.QUrl.toPercentEncoding(text)) text = str(QtCore.QUrl.toPercentEncoding(text), "utf-8")
command = self.normalExec if text == "" else self.textExec command = self.normalExec if text == "" else self.textExec
command = command.replace("{url}", url) command = command.replace("{url}", url)
command = command.replace("{text}", text) command = command.replace("{text}", text)

View File

@ -16,11 +16,13 @@
# 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 Falkon
import os, subprocess import os
from PySide2 import QtCore, QtGui, QtWidgets, QtUiTools import subprocess
from PySide2 import QtCore
from runaction.action import Action from runaction.action import Action
from runaction.settingsdialog import SettingsDialog from runaction.settingsdialog import SettingsDialog
class ActionManager(QtCore.QObject): class ActionManager(QtCore.QObject):
actions = [] actions = []
@ -58,7 +60,7 @@ class ActionManager(QtCore.QObject):
act = Falkon.Action(action.icon, action.title, self) act = Falkon.Action(action.icon, action.title, self)
act.triggered.connect(lambda a=action, w=webView, u=url, t=text: self.execAction(a, w, u, t)) act.triggered.connect(lambda a=action, w=webView, u=url, t=text: self.execAction(a, w, u, t))
if action.submenu: if action.submenu:
if not action.submenu in menus: if action.submenu not in menus:
menu = Falkon.Menu(action.menuTitle, webView) menu = Falkon.Menu(action.menuTitle, webView)
menus[action.submenu] = menu menus[action.submenu] = menu
out.append(menu) out.append(menu)

View File

@ -20,6 +20,7 @@ import os
from PySide2 import QtGui, QtWidgets from PySide2 import QtGui, QtWidgets
from runaction.i18n import i18n from runaction.i18n import i18n
class RunActionButton(Falkon.AbstractButtonInterface): class RunActionButton(Falkon.AbstractButtonInterface):
def __init__(self, manager): def __init__(self, manager):
super().__init__() super().__init__()

View File

@ -19,6 +19,7 @@ import Falkon
from PySide2 import QtCore from PySide2 import QtCore
from runaction import actionmanager, button from runaction import actionmanager, button
class RunActionPlugin(Falkon.PluginInterface, QtCore.QObject): class RunActionPlugin(Falkon.PluginInterface, QtCore.QObject):
buttons = {} buttons = {}
manager = None manager = None
@ -61,10 +62,12 @@ class RunActionPlugin(Falkon.PluginInterface, QtCore.QObject):
self.buttons[window] = b self.buttons[window] = b
def mainWindowDeleted(self, window): def mainWindowDeleted(self, window):
if not window in self.buttons: return if window not in self.buttons:
return
b = self.buttons[window] b = self.buttons[window]
window.statusBar().removeButton(b) window.statusBar().removeButton(b)
window.navigationBar().removeToolButton(b) window.navigationBar().removeToolButton(b)
del self.buttons[window] del self.buttons[window]
Falkon.registerPlugin(RunActionPlugin()) Falkon.registerPlugin(RunActionPlugin())

View File

@ -15,7 +15,14 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QLabel" name="label"/> <widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QListWidget" name="listWidget"> <widget class="QListWidget" name="listWidget">
@ -28,6 +35,9 @@
<height>16</height> <height>16</height>
</size> </size>
</property> </property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="uniformItemSizes"> <property name="uniformItemSizes">
<bool>true</bool> <bool>true</bool>
</property> </property>

View File

@ -15,11 +15,11 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# 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 PySide2 import QtCore, QtWidgets, QtUiTools
from runaction.i18n import i18n from runaction.i18n import i18n
class SettingsDialog(QtWidgets.QDialog): class SettingsDialog(QtWidgets.QDialog):
def __init__(self, manager, parent=None): def __init__(self, manager, parent=None):
super().__init__(parent) super().__init__(parent)
@ -36,7 +36,7 @@ class SettingsDialog(QtWidgets.QDialog):
self.setMinimumSize(400, 250) self.setMinimumSize(400, 250)
self.setWindowTitle(i18n("Run Action Settings")) self.setWindowTitle(i18n("Run Action Settings"))
self.ui.label.setText("<b>{}</b>".format(i18n("Available actions"))) self.ui.label.setText(i18n("Available actions"))
for action in self.manager.actions: for action in self.manager.actions:
item = QtWidgets.QListWidgetItem(self.ui.listWidget) item = QtWidgets.QListWidgetItem(self.ui.listWidget)