-
-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Originally UI config file was saved to ~/.opensnitch/ui-config.json Now those values are saved to ~/.config/opensnitch/settings.conf, along with new ones. Closes #3
- Loading branch information
1 parent
a5f8d5b
commit 1e6d2c0
Showing
4 changed files
with
21 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,28 @@ | ||
import os | ||
import json | ||
from PyQt5 import QtCore | ||
|
||
class Config: | ||
__instance = None | ||
|
||
@staticmethod | ||
def init(filename): | ||
Config.__instance = Config(filename) | ||
def init(): | ||
Config.__instance = Config() | ||
return Config.__instance | ||
|
||
@staticmethod | ||
def get(): | ||
return Config.__instance | ||
|
||
def __init__(self, filename): | ||
self.filename = os.path.abspath( os.path.expanduser(filename) ) | ||
self.exists = os.path.isfile(self.filename) | ||
|
||
def __init__(self): | ||
self.settings = QtCore.QSettings("opensnitch", "settings") | ||
|
||
self.default_timeout = 15 | ||
self.default_action = "allow" | ||
self.default_duration = "until restart" | ||
|
||
if self.exists: | ||
# print( "Loading configuration from %s ..." % self.filename ) | ||
data = json.load(open(self.filename)) | ||
|
||
self.default_timeout = data["default_timeout"] | ||
self.default_action = data["default_action"] | ||
self.default_duration = data["default_duration"] | ||
if self.settings.value("global/default_timeout") == None: | ||
self.setSettings("global/default_timeout", 15) | ||
self.setSettings("global/default_action", "allow") | ||
self.setSettings("global/default_duration", "until restart") | ||
|
||
def setSettings(self, path, value): | ||
self.settings.setValue(path, value) | ||
|
||
def getSettings(self, path): | ||
return self.settings.value(path) | ||
|
||
def save(self): | ||
dirname = os.path.dirname(self.filename) | ||
if os.path.isdir(dirname) == False: | ||
os.makedirs(dirname, exist_ok=True) | ||
|
||
with open(self.filename, 'w') as fp: | ||
data = { | ||
'default_timeout': self.default_timeout, | ||
'default_action': self.default_action, | ||
'default_duration': self.default_duration | ||
} | ||
json.dump(data, fp) | ||
self.exists = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters