From 96937b7fdecb34597b06138d800f9a18100abbec Mon Sep 17 00:00:00 2001
From: Eric Garver <e@erig.me>
Date: Wed, 14 Nov 2018 12:59:57 -0500
Subject: [PATCH] fix qt4_applet patch
---
src/firewall-applet.in | 157 ++++++++++++++++++++---------------------
1 file changed, 78 insertions(+), 79 deletions(-)
diff --git a/src/firewall-applet.in b/src/firewall-applet.in
index 1d2cf7672174..05966ce1c80c 100755
--- a/src/firewall-applet.in
+++ b/src/firewall-applet.in
@@ -21,14 +21,14 @@
#
import sys
-from PyQt5 import QtGui, QtCore, QtWidgets
+from PyQt4 import QtGui, QtCore
import gi
gi.require_version('Notify', '0.7')
from gi.repository import Notify
import os
-from dbus.mainloop.pyqt5 import DBusQtMainLoop
+from dbus.mainloop.qt import DBusQtMainLoop
import functools
from firewall import config
@@ -78,20 +78,21 @@ def escape(text):
return text
def fromUTF8(text):
- if PY2 and QtCore.QT_VERSION < 0x050000:
+ if PY2:
return QtCore.QString.fromUtf8(text)
- return text
+ else:
+ return text
# ZoneInterfaceEditor #########################################################
-class ZoneInterfaceEditor(QtWidgets.QDialog):
+class ZoneInterfaceEditor(QtGui.QDialog):
def __init__(self, fw, interface, zone):
self.fw = fw
self.interface = interface
self.zone = None
self.title = _("Select zone for interface '%s'") % self.interface
- QtWidgets.QDialog.__init__(self)
+ QtGui.QDialog.__init__(self)
self.create_ui(zone)
def create_ui(self, zone):
@@ -100,19 +101,19 @@ class ZoneInterfaceEditor(QtWidgets.QDialog):
self.resize(100, 50)
- vbox = QtWidgets.QVBoxLayout()
+ vbox = QtGui.QVBoxLayout()
vbox.setSpacing(6)
- label = QtWidgets.QLabel(fromUTF8(escape(self.title)))
+ label = QtGui.QLabel(fromUTF8(escape(self.title)))
vbox.addWidget(label)
- self.combo = QtWidgets.QComboBox()
+ self.combo = QtGui.QComboBox()
self.fill_zone_combo()
vbox.addWidget(self.combo)
- buttonBox = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok
- | QtWidgets.QDialogButtonBox.Cancel)
- self.ok_button = buttonBox.button(QtWidgets.QDialogButtonBox.Ok)
+ buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok
+ | QtGui.QDialogButtonBox.Cancel)
+ self.ok_button = buttonBox.button(QtGui.QDialogButtonBox.Ok)
buttonBox.accepted.connect(self.ok)
buttonBox.rejected.connect(self.hide)
vbox.addWidget(buttonBox)
@@ -165,7 +166,7 @@ class ZoneConnectionEditor(ZoneInterfaceEditor):
self.zone = None
self.title = _("Select zone for connection '%s'") % self.connection_name
- QtWidgets.QDialog.__init__(self)
+ QtGui.QDialog.__init__(self)
self.create_ui(zone)
def ok(self):
@@ -174,7 +175,7 @@ class ZoneConnectionEditor(ZoneInterfaceEditor):
nm_set_zone_of_connection(self.get_zone(), self.connection)
except Exception:
text = _("Failed to set zone {zone} for connection {connection_name}")
- QtWidgets.QMessageBox.warning(None, fromUTF8(escape(self.title)),
+ QtGui.QMessageBox.warning(None, fromUTF8(escape(self.title)),
escape(text.format(
zone=self.get_zone(),
connection_name=self.connection_name)))
@@ -189,7 +190,7 @@ class ZoneSourceEditor(ZoneInterfaceEditor):
self.zone = None
self.title = _("Select zone for source '%s'") % self.source
- QtWidgets.QDialog.__init__(self)
+ QtGui.QDialog.__init__(self)
self.create_ui(zone)
def ok(self):
@@ -198,7 +199,7 @@ class ZoneSourceEditor(ZoneInterfaceEditor):
# ShieldsEditor #########################################################
-class ShieldsEditor(QtWidgets.QDialog):
+class ShieldsEditor(QtGui.QDialog):
def __init__(self, fw, settings, shields_up, shields_down):
self.fw = fw
self.settings = settings
@@ -206,63 +207,63 @@ class ShieldsEditor(QtWidgets.QDialog):
self.shields_down = shields_down
self.title = _("Configure Shields Up/Down Zones")
- QtWidgets.QDialog.__init__(self)
+ QtGui.QDialog.__init__(self)
self.create_ui()
def create_ui(self):
self.setWindowTitle(fromUTF8(escape(self.title)))
self.rejected.connect(self.hide)
- vbox = QtWidgets.QVBoxLayout()
+ vbox = QtGui.QVBoxLayout()
vbox.setSpacing(6)
- label = QtWidgets.QLabel(fromUTF8(escape(
+ label = QtGui.QLabel(fromUTF8(escape(
_("Here you can select the zones used for Shields Up and "
"Shields Down."))))
label.setWordWrap(True)
vbox.addWidget(label)
- label = QtWidgets.QLabel(fromUTF8(escape(
+ label = QtGui.QLabel(fromUTF8(escape(
_("This feature is useful for people using the default zones "
"mostly. For users, that are changing zones of connections, it "
"might be of limited use."))))
label.setWordWrap(True)
vbox.addWidget(label)
- grid = QtWidgets.QGridLayout()
+ grid = QtGui.QGridLayout()
grid.setSpacing(6)
- label = QtWidgets.QLabel(fromUTF8(escape(_("Shields Up Zone:"))))
+ label = QtGui.QLabel(fromUTF8(escape(_("Shields Up Zone:"))))
label.setWordWrap(True)
grid.addWidget(label, 0, 0, 1, 1)
- self.shields_up_combo = QtWidgets.QComboBox()
+ self.shields_up_combo = QtGui.QComboBox()
#self.fill_combo(self.shields_up_combo)
#self.set_shields_up(self.shields_up)
grid.addWidget(self.shields_up_combo, 0, 1, 1, 1)
- button = QtWidgets.QPushButton(_("Reset To Default"))
+ button = QtGui.QPushButton(_("Reset To Default"))
button.clicked.connect(self.reset_shields_up)
grid.addWidget(button, 0, 2, 1, 1)
- label = QtWidgets.QLabel(fromUTF8(escape(_("Shields Down Zone:"))))
+ label = QtGui.QLabel(fromUTF8(escape(_("Shields Down Zone:"))))
label.setWordWrap(True)
grid.addWidget(label, 1, 0, 1, 1)
- self.shields_down_combo = QtWidgets.QComboBox()
+ self.shields_down_combo = QtGui.QComboBox()
#self.fill_combo(self.shields_down_combo)
#self.set_shields_down(self.shields_down)
grid.addWidget(self.shields_down_combo, 1, 1, 1, 1)
- button = QtWidgets.QPushButton(_("Reset To Default"))
+ button = QtGui.QPushButton(_("Reset To Default"))
button.clicked.connect(self.reset_shields_down)
grid.addWidget(button, 1, 2, 1, 1)
vbox.addLayout(grid)
- buttonBox = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok
- | QtWidgets.QDialogButtonBox.Cancel)
- self.ok_button = buttonBox.button(QtWidgets.QDialogButtonBox.Ok)
+ buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok
+ | QtGui.QDialogButtonBox.Cancel)
+ self.ok_button = buttonBox.button(QtGui.QDialogButtonBox.Ok)
buttonBox.accepted.connect(self.ok)
buttonBox.rejected.connect(self.hide)
vbox.addWidget(buttonBox)
@@ -333,56 +334,56 @@ class ShieldsEditor(QtWidgets.QDialog):
# AboutDialog #################################################################
-class AboutDialog(QtWidgets.QDialog):
+class AboutDialog(QtGui.QDialog):
def __init__(self, name, icon, version, url, copyright, authors, license):
- QtWidgets.QDialog.__init__(self)
+ QtGui.QDialog.__init__(self)
self.setWindowIcon(icon)
self.setWindowTitle(fromUTF8(escape(_("About %s" % name))))
self.resize(500, 250)
- vbox = QtWidgets.QVBoxLayout()
+ vbox = QtGui.QVBoxLayout()
vbox.setSpacing(6)
- hbox = QtWidgets.QHBoxLayout()
+ hbox = QtGui.QHBoxLayout()
hbox.setSpacing(24)
- label = QtWidgets.QLabel()
+ label = QtGui.QLabel()
label.setPixmap(icon.pixmap(96))
label.setMinimumSize(96, 96)
label.setMaximumSize(96, 96)
hbox.addWidget(label)
- vbox2 = QtWidgets.QVBoxLayout()
+ vbox2 = QtGui.QVBoxLayout()
vbox2.setSpacing(3)
- label = QtWidgets.QLabel(name)
+ label = QtGui.QLabel(name)
font = label.font()
font.setPointSize(font.pointSize()*2)
font.setBold(True)
label.setFont(font)
vbox2.addWidget(label)
- vbox2.addWidget(QtWidgets.QLabel(version))
+ vbox2.addWidget(QtGui.QLabel(version))
- label = QtWidgets.QLabel("<a href=\"%s\">%s</a>" % (url, url))
+ label = QtGui.QLabel("<a href=\"%s\">%s</a>" % (url, url))
label.setTextFormat(QtCore.Qt.RichText)
label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
label.setOpenExternalLinks(True)
vbox2.addWidget(label)
- vbox2.addWidget(QtWidgets.QLabel(copyright))
+ vbox2.addWidget(QtGui.QLabel(copyright))
hbox.addLayout(vbox2)
vbox.addLayout(hbox)
- tabs = QtWidgets.QTabWidget()
+ tabs = QtGui.QTabWidget()
tabs.setStyleSheet("QTabWidget::tab { padding: 1px 1px 1px 1px; }")
- tab = QtWidgets.QWidget()
- vbox3 = QtWidgets.QVBoxLayout()
- textedit = QtWidgets.QPlainTextEdit()
+ tab = QtGui.QWidget()
+ vbox3 = QtGui.QVBoxLayout()
+ textedit = QtGui.QPlainTextEdit()
#textedit.setStyleSheet("QPlainTextEdit { border: 0; padding: 0; }")
textedit.setReadOnly(True)
textedit.setPlainText(fromUTF8("\n".join(authors)))
@@ -390,9 +391,9 @@ class AboutDialog(QtWidgets.QDialog):
tab.setLayout(vbox3)
tabs.addTab(tab, fromUTF8(escape(_("Authors"))))
- tab = QtWidgets.QWidget()
- vbox3 = QtWidgets.QVBoxLayout()
- textedit = QtWidgets.QPlainTextEdit()
+ tab = QtGui.QWidget()
+ vbox3 = QtGui.QVBoxLayout()
+ textedit = QtGui.QPlainTextEdit()
#textedit.setStyleSheet("QPlainTextEdit { border: 0; padding: 0; }")
textedit.setReadOnly(True)
textedit.setPlainText(license)
@@ -402,7 +403,7 @@ class AboutDialog(QtWidgets.QDialog):
vbox.addWidget(tabs)
- buttonBox = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Close)
+ buttonBox = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Close)
buttonBox.rejected.connect(self.hide)
vbox.addWidget(buttonBox)
@@ -410,7 +411,7 @@ class AboutDialog(QtWidgets.QDialog):
# TrayApplet ##################################################################
-class TrayApplet(QtWidgets.QSystemTrayIcon):
+class TrayApplet(QtGui.QSystemTrayIcon):
def __init__(self):
super(TrayApplet, self).__init__()
self.name = _("Firewall Applet")
@@ -458,67 +459,67 @@ class TrayApplet(QtWidgets.QSystemTrayIcon):
# urgencies
- self.urgencies = { "noicon": QtWidgets.QSystemTrayIcon.NoIcon,
- "information": QtWidgets.QSystemTrayIcon.Information,
- "warning": QtWidgets.QSystemTrayIcon.Warning,
- "critical": QtWidgets.QSystemTrayIcon.Critical }
+ self.urgencies = { "noicon": QtGui.QSystemTrayIcon.NoIcon,
+ "information": QtGui.QSystemTrayIcon.Information,
+ "warning": QtGui.QSystemTrayIcon.Warning,
+ "critical": QtGui.QSystemTrayIcon.Critical }
# actions
- self.shieldsupAction = QtWidgets.QAction(fromUTF8(escape(_("Shields Up"))),
+ self.shieldsupAction = QtGui.QAction(fromUTF8(escape(_("Shields Up"))),
self)
self.shieldsupAction.setCheckable(True)
self.shieldsupAction.setChecked(False)
self.shieldsupAction.triggered.connect(self.shieldsup_changed_cb)
- self.notificationsAction = QtWidgets.QAction(
+ self.notificationsAction = QtGui.QAction(
fromUTF8(escape(_("Enable Notifications"))), self)
self.notificationsAction.setCheckable(True)
self.notificationsAction.setChecked(False)
self.notificationsAction.triggered.connect(self.notification_changed_cb)
- self.settingsAction = QtWidgets.QAction(
+ self.settingsAction = QtGui.QAction(
fromUTF8(escape(_("Edit Firewall Settings..."))), self)
self.settingsAction.triggered.connect(self.configure_cb)
- self.changeZonesAction = QtWidgets.QAction(
+ self.changeZonesAction = QtGui.QAction(
fromUTF8(escape(_("Change Zones of Connections..."))), self)
self.changeZonesAction.triggered.connect(self.nm_connection_editor)
- self.shieldsAction = QtWidgets.QAction(
+ self.shieldsAction = QtGui.QAction(
fromUTF8(escape(_("Configure Shields UP/Down Zones..."))), self)
self.shieldsAction.triggered.connect(self.configure_shields)
- self.panicAction = QtWidgets.QAction(
+ self.panicAction = QtGui.QAction(
fromUTF8(escape(_("Block all network traffic"))), self)
self.panicAction.setCheckable(True)
self.panicAction.setChecked(False)
self.panicAction.triggered.connect(self.panic_mode_cb)
- self.aboutAction = QtWidgets.QAction(fromUTF8(escape(_("About"))), self)
+ self.aboutAction = QtGui.QAction(fromUTF8(escape(_("About"))), self)
self.aboutAction.triggered.connect(self.about_dialog.exec_)
- #self.quitAction = QtWidgets.QAction(fromUTF8(escape(_("Quit"))), self,
+ #self.quitAction = QtGui.QAction(fromUTF8(escape(_("Quit"))), self,
# triggered=self.quit)
- self.connectionsAction = QtWidgets.QWidgetAction(self)
- self.connectionsAction.setDefaultWidget(QtWidgets.QLabel(
+ self.connectionsAction = QtGui.QWidgetAction(self)
+ self.connectionsAction.setDefaultWidget(QtGui.QLabel(
fromUTF8("<b>"+escape(_("Connections"))+"</b> ")))
- self.interfacesAction = QtWidgets.QWidgetAction(self)
- self.interfacesAction.setDefaultWidget(QtWidgets.QLabel(
+ self.interfacesAction = QtGui.QWidgetAction(self)
+ self.interfacesAction.setDefaultWidget(QtGui.QLabel(
fromUTF8("<b>"+escape(_("Interfaces"))+"</b> ")))
- self.sourcesAction = QtWidgets.QWidgetAction(self)
- self.sourcesAction.setDefaultWidget(QtWidgets.QLabel(
+ self.sourcesAction = QtGui.QWidgetAction(self)
+ self.sourcesAction.setDefaultWidget(QtGui.QLabel(
fromUTF8("<b>"+escape(_("Sources"))+"</b> ")))
# init
- self.left_menu = QtWidgets.QMenu()
+ self.left_menu = QtGui.QMenu()
self.left_menu.setStyleSheet('QMenu { margin: 5px; }')
- self.right_menu = QtWidgets.QMenu()
+ self.right_menu = QtGui.QMenu()
self.right_menu.addAction(self.shieldsupAction)
self.right_menu.addAction(self.notificationsAction)
self.right_menu.addSeparator()
@@ -637,7 +638,7 @@ class TrayApplet(QtWidgets.QSystemTrayIcon):
self.setVisible(True)
def activated_cb(self, reason):
- if reason == QtWidgets.QSystemTrayIcon.Trigger:
+ if reason == QtGui.QSystemTrayIcon.Trigger:
self.left_menu.popup(QtGui.QCursor.pos())
def update_active_zones(self):
@@ -686,12 +687,12 @@ class TrayApplet(QtWidgets.QSystemTrayIcon):
connection_name = connections[connection][1]
if zone == "":
_binding = _("{entry} (Default Zone: {default_zone})")
- action = QtWidgets.QAction(
+ action = QtGui.QAction(
fromUTF8(escape(
_binding.format(default_zone=self.default_zone,
entry=connection_name))), self)
else:
- action = QtWidgets.QAction(
+ action = QtGui.QAction(
fromUTF8(escape(binding.format(zone=zone,
entry=connection_name))), self)
action.triggered.connect(functools.partial(
@@ -704,7 +705,7 @@ class TrayApplet(QtWidgets.QSystemTrayIcon):
# add other interfaces
for interface in sorted(interfaces):
zone = interfaces[interface]
- action = QtWidgets.QAction(
+ action = QtGui.QAction(
fromUTF8(escape(binding.format(zone=zone, entry=interface))),
self)
action.triggered.connect(functools.partial(
@@ -716,7 +717,7 @@ class TrayApplet(QtWidgets.QSystemTrayIcon):
for source in sorted(sources):
zone = sources[source]
- action = QtWidgets.QAction(
+ action = QtGui.QAction(
fromUTF8(escape(binding.format(zone=zone, entry=source))),
self)
action.triggered.connect(functools.partial(
@@ -938,10 +939,10 @@ class TrayApplet(QtWidgets.QSystemTrayIcon):
os.system("%s &" % NM_CONNECTION_EDITOR)
def warning(self, text):
- QtWidgets.QMessageBox.warning(None, fromUTF8(escape(self.name)), text)
+ QtGui.QMessageBox.warning(None, fromUTF8(escape(self.name)), text)
def error(self, text):
- QtWidgets.QMessageBox.critical(None, fromUTF8(escape(self.name)), text)
+ QtGui.QMessageBox.critical(None, fromUTF8(escape(self.name)), text)
def configure_cb(self, widget):
os.system("firewall-config &")
@@ -977,8 +978,6 @@ class TrayApplet(QtWidgets.QSystemTrayIcon):
def reloaded(self):
if self.notificationsAction.isChecked():
self.notify(escape(_("FirewallD has been reloaded.")))
- self.update_active_zones()
- self.update_tooltip()
def default_zone_changed(self, zone):
self.default_zone = zone
@@ -1124,7 +1123,7 @@ Options:
# reset SIGINT signal to default
signal.signal(signal.SIGINT, signal.SIG_DFL)
-app = QtWidgets.QApplication(sys.argv)
+app = QtGui.QApplication(sys.argv)
app.setQuitOnLastWindowClosed(False)
applet = TrayApplet()
--
2.18.0