Skip to content

Commit

Permalink
firewall-applet: Enable global applet settings, reload user settings …
Browse files Browse the repository at this point in the history
…if changed

Adds new global settings file in /etc/firewall/applet.conf

Reload settings on changed user settings in ~/.config/firewall/applet.conf
using a file watch.
  • Loading branch information
t-woerner committed Jun 29, 2015
1 parent ca9597c commit 2a701fe
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
3 changes: 3 additions & 0 deletions config/Makefile.am
Expand Up @@ -14,6 +14,9 @@ applet_desktop_FILES = firewall-applet.desktop.in
applet_desktopdir = $(sysconfdir)/xdg/autostart
applet_desktop_DATA = $(applet_desktop_FILES:.in=)

confdir = $(sysconfdir)/firewall
dist_conf_DATA = applet.conf

polkit1_action_FILES = org.fedoraproject.FirewallD1.server.policy.in \
org.fedoraproject.FirewallD1.desktop.policy.in
polkit1_actiondir = $(datadir)/polkit-1/actions
Expand Down
5 changes: 5 additions & 0 deletions config/applet.conf
@@ -0,0 +1,5 @@
[General]
notifications=false
show-inactive=false
blink=true
blink-count=5
2 changes: 2 additions & 0 deletions firewalld.spec
Expand Up @@ -268,6 +268,8 @@ fi
%{_bindir}/firewall-applet
%defattr(0644,root,root)
%{_sysconfdir}/xdg/autostart/firewall-applet.desktop
%dir %{_sysconfdir}/firewall
%{_sysconfdir}/firewall/applet.conf
%{_datadir}/icons/hicolor/*/apps/firewall-applet*.*
%{_mandir}/man1/firewall-applet*.1*

Expand Down
42 changes: 36 additions & 6 deletions src/firewall-applet
Expand Up @@ -311,10 +311,12 @@ class TrayApplet(QtGui.QSystemTrayIcon):

self.settings = QtCore.QSettings("firewall", "applet")

self.blink = self.settings.value("blink", False, type=bool)
self.blink_count = self.settings.value("blink-count", 5, type=int)
self.show_inactive = self.settings.value("show-inactive", False,
type=bool)
# file system watcher

self.watcher = QtCore.QFileSystemWatcher(self)
if os.path.exists(self.settings.fileName()):
self.watcher.addPath(self.settings.fileName())
self.watcher.fileChanged.connect(self.load_settings)

# about dialog

Expand All @@ -335,8 +337,7 @@ class TrayApplet(QtGui.QSystemTrayIcon):
self.notificationsAction = QtGui.QAction(
fromUTF8(escape(_("Enable Notifications"))), self)
self.notificationsAction.setCheckable(True)
self.notificationsAction.setChecked(
self.settings.value("notifications", False, type=bool))
self.notificationsAction.setChecked(False)
self.notificationsAction.triggered.connect(self.notification_changed_cb)

self.settingsAction = QtGui.QAction(
Expand Down Expand Up @@ -436,6 +437,8 @@ class TrayApplet(QtGui.QSystemTrayIcon):
member_keyword='member')
self.nm_signal_receiver()

self.load_settings()

def _exception_handler(self, exception_message):
if "NotAuthorizedException" in exception_message:
self.error(fromUTF8(escape(_("Authorization failed."))))
Expand All @@ -457,6 +460,32 @@ class TrayApplet(QtGui.QSystemTrayIcon):
def set_icon(self, mode):
self.setIcon(self.icons[mode])

def load_settings(self):
self.settings.sync()

# fix lost watch file by file move
files = [ str(name) for name in self.watcher.files()]
if self.settings.fileName() not in files:
if os.path.exists(self.settings.fileName()):
self.watcher.addPath(self.settings.fileName())

notifications = self.settings.value("notifications", False, type=bool)
self.notificationsAction.setChecked(notifications)
self.show_inactive = self.settings.value("show-inactive", False,
type=bool)
self.blink = self.settings.value("blink", False, type=bool)
self.blink_count = self.settings.value("blink-count", 5, type=int)

#print("notifications=%s" % notifications)
#print("blink=%s" % self.blink)
#print("blink-count=%s" % self.blink_count)
#print("show-inactive=%s" % self.show_inactive)

if not self.connected:
self.setVisible(self.show_inactive)
else:
self.setVisible(True)

def activated_cb(self, reason):
if reason == QtGui.QSystemTrayIcon.Trigger:
self.left_menu.popup(QtGui.QCursor.pos())
Expand Down Expand Up @@ -627,6 +656,7 @@ class TrayApplet(QtGui.QSystemTrayIcon):
def notification_changed_cb(self):
self.settings.setValue("notifications",
self.notificationsAction.isChecked())
self.settings.sync()

def __blink(self, arg=None):
if self._blink_count != 0:
Expand Down

0 comments on commit 2a701fe

Please sign in to comment.