view PreferencesDialog.py @ 219:38d1898e7d82

include the time when logging
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sun, 27 Apr 2014 06:19:04 +0200
parents 699d8f1cebd4
children f0b5bdce1189
line wrap: on
line source

# -*- coding: utf-8 -*-
from PyQt4.QtGui import QDialog
from Ui_Preferences import Ui_Preferences

class PreferencesDialog(QDialog):
    def __init__(self, backend=None):
        super(PreferencesDialog, self).__init__(None)
        self.backend = backend
        self.preferences = backend.preferences()
        self.ui = Ui_Preferences()
        self.ui.setupUi(self)
        self.fillUi()

    def fillUi(self):
        self.fillMaximized()
        self.fillHideReadFeedEntries()
        self.fillShowOnlyUnreadFeeds()
        self.fillProxySettings()
        self.fillDaysToKeepFeedEntries()

    def fillMaximized(self):
        maximized = self.preferences.startMaximized()
        self.ui.startMaximized.setChecked(maximized)

    def fillHideReadFeedEntries(self):
        hideRead = self.preferences.hideReadFeedEntries()
        self.ui.hideReadFeedEntries.setChecked(hideRead)

    def fillShowOnlyUnreadFeeds(self):
        showOnlyUnreadFeeds = self.preferences.showOnlyUnreadFeeds()
        self.ui.showOnlyUnreadFeeds.setChecked(showOnlyUnreadFeeds)

    def fillProxySettings(self):
        if self.preferences.isProxyConfigured():
            self.ui.useProxy.setChecked(self.preferences.useProxy())
            self.ui.proxyHost.setText(self.preferences.proxyHost())
            port = self.preferences.proxyPort()
            if port is not None:
                self.ui.proxyPort.setText(str(port))

    def fillDaysToKeepFeedEntries(self):
        days = self.preferences.daysToKeepFeedEntries()
        self.ui.daysToKeepFeedEntries.setText(str(days))

    def startMaximizedChanged(self, change):
        if change:
            self.preferences.setStartMaximized(True)
        else:
            self.preferences.setStartMaximized(False)

    def hideReadFeedEntriesChanged(self, change):
        if change:
            self.preferences.setHideReadFeedEntries(True)
        else:
            self.preferences.setHideReadFeedEntries(False)

    def showOnlyFeedsWithUnreadEntries(self, change):
        if change:
            self.preferences.setShowOnlyUnreadFeeds(True)
        else:
            self.preferences.setShowOnlyUnreadFeeds(False)

    def storeProxySettings(self):
        proxyHost = self.ui.proxyHost.text()
        self.preferences.setUseProxy(self.ui.useProxy.isChecked())
        if proxyHost.isEmpty():
            self.preferences.setProxyHost(None)
        else:
            self.preferences.setProxyHost(str(proxyHost))

        proxyPort = self.ui.proxyPort.text()
        if proxyPort.isEmpty():
            self.preferences.setProxyPort(None)
        else:
            self.preferences.setProxyPort(int(proxyPort))

    def daysToKeepFeedEntriesFinishedEditing(self):
        text = self.ui.daysToKeepFeedEntries.text()
        if not text.isEmpty():
            text = str(text)
            self.preferences.setDaysToKeepFeedEntries(text)

    def accept(self):
        self.storeProxySettings()
        self.preferences.commit();
        super(PreferencesDialog, self).accept()

    def reject(self):
        self.preferences.rollback()
        super(PreferencesDialog, self).reject()