settings.py 3.22 KB
Newer Older
1 2 3 4 5
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal

class Settings(QObject):
    showTrayIconChanged = pyqtSignal(bool)
    closeToTrayChanged = pyqtSignal(bool)
librebob's avatar
librebob committed
6
    alwaysShowLogsChanged = pyqtSignal(bool)
librebob's avatar
librebob committed
7
    notificationsEnabledChanged = pyqtSignal(bool)
8
    themeChanged = pyqtSignal(str)
9

10
    def __init__(self, *args, settingRepository=None, **kwargs):
11
        super().__init__(*args, **kwargs)
12 13
        self._settingRepository = settingRepository
        showTrayIcon = self._settingRepository.get('show_tray_icon')
14
        self._showTrayIcon = True if showTrayIcon is None else showTrayIcon
15
        closeToTray = self._settingRepository.get('close_to_tray')
16
        self._closeToTray = True if closeToTray is None else closeToTray
17
        alwaysShowLogs = self._settingRepository.get('close_to_tray')
librebob's avatar
librebob committed
18
        self._alwaysShowLogs = False if alwaysShowLogs is None else alwaysShowLogs
19
        notificationsEnabled = self._settingRepository.get('notifications_enabled')
librebob's avatar
librebob committed
20
        self._notificationsEnabled = True if notificationsEnabled is None else notificationsEnabled
21
        theme = self._settingRepository.get('theme')
22
        self._theme = 'Dark' if theme is None else theme
23 24 25 26 27 28 29 30 31

    @pyqtProperty(bool, notify=showTrayIconChanged)
    def showTrayIcon(self):
        return self._showTrayIcon

    @showTrayIcon.setter
    def showTrayIcon(self, showTrayIcon):
        if showTrayIcon != self._showTrayIcon:
            self._showTrayIcon = showTrayIcon
32
            self._settingRepository.set('show_tray_icon', showTrayIcon)
33 34 35 36 37 38 39 40 41 42
            self.showTrayIconChanged.emit(showTrayIcon)

    @pyqtProperty(bool, notify=closeToTrayChanged)
    def closeToTray(self):
        return self._closeToTray

    @closeToTray.setter
    def closeToTray(self, closeToTray):
        if closeToTray != self._closeToTray:
            self._closeToTray = closeToTray
43
            self._settingRepository.set('close_to_tray', closeToTray)
44 45
            print(not closeToTray)
            self.closeToTrayChanged.emit(not closeToTray)
librebob's avatar
librebob committed
46 47 48 49 50 51 52 53 54

    @pyqtProperty(bool, notify=alwaysShowLogsChanged)
    def alwaysShowLogs(self):
        return self._alwaysShowLogs

    @alwaysShowLogs.setter
    def alwaysShowLogs(self, alwaysShowLogs):
        if alwaysShowLogs != self._alwaysShowLogs:
            self._alwaysShowLogs = alwaysShowLogs
55
            self._settingRepository.set('close_to_tray', alwaysShowLogs)
librebob's avatar
librebob committed
56
            self.alwaysShowLogsChanged.emit(alwaysShowLogs)
librebob's avatar
librebob committed
57 58 59 60 61 62 63 64 65

    @pyqtProperty(bool, notify=notificationsEnabledChanged)
    def notificationsEnabled(self):
        return self._notificationsEnabled

    @notificationsEnabled.setter
    def notificationsEnabled(self, notificationsEnabled):
        if notificationsEnabled != self._notificationsEnabled:
            self._notificationsEnabled = notificationsEnabled
66
            self._settingRepository.set('notifications_enabled', notificationsEnabled)
librebob's avatar
librebob committed
67
            self.notificationsEnabledChanged.emit(notificationsEnabled)
68 69 70 71 72 73 74 75 76
            
    @pyqtProperty(str, notify=themeChanged)
    def theme(self):
        return self._theme

    @theme.setter
    def theme(self, theme):
        if theme != self._theme:
            self._theme = theme
77
            self._settingRepository.set('theme', theme)
78 79
            self.themeChanged.emit(theme)