mirror of
https://github.com/evilsocket/opensnitch.git
synced 2025-03-04 16:44:46 +01:00
ui, prefs, notifications: fixes
- Fixed preferences dialog status error messages. - Improved notifications
This commit is contained in:
parent
1c523784a8
commit
7e5d809683
4 changed files with 38 additions and 31 deletions
|
@ -38,6 +38,7 @@ class PreferencesDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
||||||
|
|
||||||
self._notification_callback.connect(self._cb_notification_callback)
|
self._notification_callback.connect(self._cb_notification_callback)
|
||||||
self._notifications_sent = {}
|
self._notifications_sent = {}
|
||||||
|
self._desktop_notifications = DesktopNotifications()
|
||||||
|
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
|
@ -59,6 +60,7 @@ class PreferencesDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
||||||
self.cmdDBPurgesUp.clicked.connect(lambda: self._cb_cmd_spin_clicked(self.spinDBPurgeInterval, self.SUM))
|
self.cmdDBPurgesUp.clicked.connect(lambda: self._cb_cmd_spin_clicked(self.spinDBPurgeInterval, self.SUM))
|
||||||
self.cmdDBPurgesDown.clicked.connect(lambda: self._cb_cmd_spin_clicked(self.spinDBPurgeInterval, self.REST))
|
self.cmdDBPurgesDown.clicked.connect(lambda: self._cb_cmd_spin_clicked(self.spinDBPurgeInterval, self.REST))
|
||||||
self.cmdTestNotifs.clicked.connect(self._cb_test_notifs_clicked)
|
self.cmdTestNotifs.clicked.connect(self._cb_test_notifs_clicked)
|
||||||
|
self.radioSysNotifs.clicked.connect(self._cb_radio_system_notifications)
|
||||||
self.helpButton.setToolTipDuration(30 * 1000)
|
self.helpButton.setToolTipDuration(30 * 1000)
|
||||||
|
|
||||||
if QtGui.QIcon.hasThemeIcon("emblem-default") == False:
|
if QtGui.QIcon.hasThemeIcon("emblem-default") == False:
|
||||||
|
@ -147,12 +149,13 @@ class PreferencesDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
||||||
self.dstPortCheck.setChecked(self._cfg.getBool(self._cfg.DEFAULT_POPUP_ADVANCED_DSTPORT))
|
self.dstPortCheck.setChecked(self._cfg.getBool(self._cfg.DEFAULT_POPUP_ADVANCED_DSTPORT))
|
||||||
self.uidCheck.setChecked(self._cfg.getBool(self._cfg.DEFAULT_POPUP_ADVANCED_UID))
|
self.uidCheck.setChecked(self._cfg.getBool(self._cfg.DEFAULT_POPUP_ADVANCED_UID))
|
||||||
|
|
||||||
self.groupNotifs.setChecked(self._cfg.getBool(Config.NOTIFICATIONS_ENABLED))
|
# by default, if no configuration exists, enable notifications.
|
||||||
|
self.groupNotifs.setChecked(self._cfg.getBool(Config.NOTIFICATIONS_ENABLED, True))
|
||||||
self.radioSysNotifs.setChecked(
|
self.radioSysNotifs.setChecked(
|
||||||
True if self._cfg.getInt(Config.NOTIFICATIONS_TYPE) == Config.NOTIFICATION_TYPE_SYSTEM else False
|
True if self._cfg.getInt(Config.NOTIFICATIONS_TYPE) == Config.NOTIFICATION_TYPE_SYSTEM and self._desktop_notifications.is_available() == True else False
|
||||||
)
|
)
|
||||||
self.radioQtNotifs.setChecked(
|
self.radioQtNotifs.setChecked(
|
||||||
True if self._cfg.getInt(Config.NOTIFICATIONS_TYPE) == Config.NOTIFICATION_TYPE_QT else False
|
True if self._cfg.getInt(Config.NOTIFICATIONS_TYPE) == Config.NOTIFICATION_TYPE_QT or self._desktop_notifications.is_available() == False else False
|
||||||
)
|
)
|
||||||
|
|
||||||
self.dbType = self._cfg.getInt(self._cfg.DEFAULT_DB_TYPE_KEY)
|
self.dbType = self._cfg.getInt(self._cfg.DEFAULT_DB_TYPE_KEY)
|
||||||
|
@ -408,19 +411,23 @@ class PreferencesDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
||||||
self.statusLabel.show()
|
self.statusLabel.show()
|
||||||
|
|
||||||
def _set_status_error(self, msg):
|
def _set_status_error(self, msg):
|
||||||
|
self._show_status_label()
|
||||||
self.statusLabel.setStyleSheet('color: red')
|
self.statusLabel.setStyleSheet('color: red')
|
||||||
self.statusLabel.setText(msg)
|
self.statusLabel.setText(msg)
|
||||||
|
|
||||||
def _set_status_successful(self, msg):
|
def _set_status_successful(self, msg):
|
||||||
|
self._show_status_label()
|
||||||
self.statusLabel.setStyleSheet('color: green')
|
self.statusLabel.setStyleSheet('color: green')
|
||||||
self.statusLabel.setText(msg)
|
self.statusLabel.setText(msg)
|
||||||
|
|
||||||
def _set_status_message(self, msg):
|
def _set_status_message(self, msg):
|
||||||
|
self._show_status_label()
|
||||||
self.statusLabel.setStyleSheet('color: darkorange')
|
self.statusLabel.setStyleSheet('color: darkorange')
|
||||||
self.statusLabel.setText(msg)
|
self.statusLabel.setText(msg)
|
||||||
|
|
||||||
def _reset_status_message(self):
|
def _reset_status_message(self):
|
||||||
self.statusLabel.setText("")
|
self.statusLabel.setText("")
|
||||||
|
self._hide_status_label()
|
||||||
|
|
||||||
def _enable_db_cleaner_options(self, enable, db_max_days):
|
def _enable_db_cleaner_options(self, enable, db_max_days):
|
||||||
self.checkDBMaxDays.setChecked(enable)
|
self.checkDBMaxDays.setChecked(enable)
|
||||||
|
@ -500,8 +507,19 @@ class PreferencesDialog(QtWidgets.QDialog, uic.loadUiType(DIALOG_UI_PATH)[0]):
|
||||||
else:
|
else:
|
||||||
spinWidget.setValue(spinWidget.value() - 1)
|
spinWidget.setValue(spinWidget.value() - 1)
|
||||||
|
|
||||||
|
def _cb_radio_system_notifications(self):
|
||||||
|
if self._desktop_notifications.is_available() == False:
|
||||||
|
self.radioSysNotifs.setChecked(False)
|
||||||
|
self.radioQtNotifs.setChecked(True)
|
||||||
|
self._set_status_error(QC.translate("notifications", "System notifications are not available, you need to install python3-notify2."))
|
||||||
|
return
|
||||||
|
|
||||||
def _cb_test_notifs_clicked(self):
|
def _cb_test_notifs_clicked(self):
|
||||||
|
if self._desktop_notifications.is_available() == False:
|
||||||
|
self._set_status_error(QC.translate("notifications", "System notifications are not available, you need to install python3-notify2."))
|
||||||
|
return
|
||||||
|
|
||||||
if self.radioSysNotifs.isChecked():
|
if self.radioSysNotifs.isChecked():
|
||||||
DesktopNotifications().show("title", "body")
|
self._desktop_notifications.show("title", "body")
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -68,7 +68,10 @@ class DesktopNotifications():
|
||||||
self.IS_LIBNOTIFY_AVAILABLE = False
|
self.IS_LIBNOTIFY_AVAILABLE = False
|
||||||
|
|
||||||
def is_available(self):
|
def is_available(self):
|
||||||
return self.IS_LIBNOTIFY_AVAILABLE and self._cfg.getBool(Config.NOTIFICATIONS_ENABLED)
|
return self.IS_LIBNOTIFY_AVAILABLE
|
||||||
|
|
||||||
|
def are_enabled(self):
|
||||||
|
return self._cfg.getBool(Config.NOTIFICATIONS_ENABLED, True)
|
||||||
|
|
||||||
def support_actions(self):
|
def support_actions(self):
|
||||||
"""Returns true if the notifications daemon support actions(buttons).
|
"""Returns true if the notifications daemon support actions(buttons).
|
||||||
|
@ -86,8 +89,8 @@ class DesktopNotifications():
|
||||||
# -1 and 0 are special values
|
# -1 and 0 are special values
|
||||||
if timeout > 0:
|
if timeout > 0:
|
||||||
timeout = timeout * 1000
|
timeout = timeout * 1000
|
||||||
ntf.set_timeout(timeout)
|
ntf.set_timeout(timeout * 1000)
|
||||||
ntf.timeout = timeout
|
ntf.timeout = timeout * 1000
|
||||||
|
|
||||||
ntf.set_category(self.CATEGORY_NETWORK)
|
ntf.set_category(self.CATEGORY_NETWORK)
|
||||||
# used to display our app icon an name.
|
# used to display our app icon an name.
|
||||||
|
@ -100,16 +103,12 @@ class DesktopNotifications():
|
||||||
def ask(self, connection, timeout, callback):
|
def ask(self, connection, timeout, callback):
|
||||||
c = connection
|
c = connection
|
||||||
title = QC.translate("popups", "New outgoing connection")
|
title = QC.translate("popups", "New outgoing connection")
|
||||||
body = """
|
body = c.process_path + "\n"
|
||||||
{0}
|
body = body + QC.translate("popups", "is connecting to <b>%s</b> on %s port %d") % ( \
|
||||||
|
c.dst_host or c.dst_ip,
|
||||||
|
c.protocol.upper(),
|
||||||
|
c.dst_port )
|
||||||
|
|
||||||
{1} {2}:{3} -> {4}:{5}
|
|
||||||
UID: {6} PID: {7}
|
|
||||||
""".format(c.process_path, c.protocol.upper(),
|
|
||||||
c.src_port, c.src_ip,
|
|
||||||
c.dst_host if c.dst_host != "" else c.dst_ip, c.dst_port,
|
|
||||||
c.user_id, c.process_id
|
|
||||||
)
|
|
||||||
ntf = self.ntf2.Notification(title, body, "dialog-warning")
|
ntf = self.ntf2.Notification(title, body, "dialog-warning")
|
||||||
timeout = self._cfg.getInt(Config.DEFAULT_TIMEOUT_KEY, 15)
|
timeout = self._cfg.getInt(Config.DEFAULT_TIMEOUT_KEY, 15)
|
||||||
ntf.set_timeout(timeout * 1000)
|
ntf.set_timeout(timeout * 1000)
|
||||||
|
@ -122,11 +121,3 @@ class DesktopNotifications():
|
||||||
ntf.set_category(self.CATEGORY_NETWORK)
|
ntf.set_category(self.CATEGORY_NETWORK)
|
||||||
ntf.set_hint(self.HINT_DESKTOP_ENTRY, "opensnitch_ui")
|
ntf.set_hint(self.HINT_DESKTOP_ENTRY, "opensnitch_ui")
|
||||||
ntf.show()
|
ntf.show()
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def areEnabled():
|
|
||||||
"""Return if notifications are enabled.
|
|
||||||
|
|
||||||
Default: True
|
|
||||||
"""
|
|
||||||
return DesktopNotifications._cfg.getBool(DesktopNotifications._cfg.NOTIFICATIONS_ENABLED, True)
|
|
||||||
|
|
|
@ -1376,9 +1376,6 @@
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="statusLabel">
|
<widget class="QLabel" name="statusLabel">
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap">
|
<property name="wordWrap">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
@ -264,12 +264,13 @@ class UIService(ui_pb2_grpc.UIServicer, QtWidgets.QGraphicsObject):
|
||||||
|
|
||||||
@QtCore.pyqtSlot(str, str, int)
|
@QtCore.pyqtSlot(str, str, int)
|
||||||
def _show_systray_message(self, title, body, icon):
|
def _show_systray_message(self, title, body, icon):
|
||||||
if DesktopNotifications.areEnabled():
|
if self._desktop_notifications.are_enabled():
|
||||||
if self._desktop_notifications.is_available() and self._cfg.getInt(Config.NOTIFICATIONS_TYPE) == Config.NOTIFICATION_TYPE_SYSTEM:
|
timeout = self._cfg.getInt(Config.DEFAULT_TIMEOUT_KEY, 15)
|
||||||
|
|
||||||
|
if self._desktop_notifications.is_available() and self._cfg.getInt(Config.NOTIFICATIONS_TYPE, 1) == Config.NOTIFICATION_TYPE_SYSTEM:
|
||||||
self._desktop_notifications.show(title, body, os.path.join(self._path, "res/icon-white.svg"))
|
self._desktop_notifications.show(title, body, os.path.join(self._path, "res/icon-white.svg"))
|
||||||
else:
|
else:
|
||||||
timeout = self._cfg.getInt(Config.DEFAULT_TIMEOUT_KEY, 15)
|
self._tray.showMessage(title, body, icon, timeout * 1000)
|
||||||
self._tray.showMessage(title, body, icon, timeout)
|
|
||||||
|
|
||||||
if icon == QtWidgets.QSystemTrayIcon.NoIcon:
|
if icon == QtWidgets.QSystemTrayIcon.NoIcon:
|
||||||
self._tray.setIcon(self.alert_icon)
|
self._tray.setIcon(self.alert_icon)
|
||||||
|
|
Loading…
Add table
Reference in a new issue