changeset 111:c17a224bc251

make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
author Dirk Olmes <dirk@xanthippe.ping.de>
date Thu, 31 Mar 2011 03:15:39 +0200
parents 43c234c8fe87
children e4038dd8cc0e
files Preferences.py PreferencesDialog.py Ui_Preferences.ui
diffstat 3 files changed, 107 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/Preferences.py	Wed Mar 30 02:59:22 2011 +0200
+++ b/Preferences.py	Thu Mar 31 03:15:39 2011 +0200
@@ -19,7 +19,9 @@
             return self.cache[key]
         else:
             pref = Preference.forKey(key, self.session)
-            if pref is None and addIfMissing:
+            if pref is not None:
+                self.cache[key] = pref
+            elif pref is None and addIfMissing:
                 pref = Preference(key, str(defaultValue))
                 self.session.add(pref)
                 self.cache[key] = pref
@@ -54,16 +56,28 @@
         return pref.value
 
     def setProxyHost(self, hostname):
-        pref = self._cachedPreference(PROXY_HOST)
-        pref.value = hostname
+        if hostname is None:
+            pref = self._cachedPreference(PROXY_HOST, addIfMissing=False)
+            if pref is not None:
+                self.session.delete(pref)
+                del(self.cache[PROXY_HOST])
+        else:
+            pref = self._cachedPreference(PROXY_HOST)
+            pref.value = str(hostname)
 
     def proxyPort(self):
         pref = self._cachedPreference(PROXY_PORT, 3128)
         return int(pref.value)
 
     def setProxyPort(self, port):
-        pref = self._cachedPreference(PROXY_PORT)
-        pref.value = str(port)
+        if port is None:
+            pref = self._cachedPreference(PROXY_PORT, addIfMissing=False)
+            if pref is not None:
+                self.session.delete(pref)
+                del(self.cache[PROXY_PORT])
+        else:
+            pref = self._cachedPreference(PROXY_PORT)
+            pref.value = str(port)
 
     def isProxyConfigured(self):
         pref = self._cachedPreference(PROXY_HOST, addIfMissing=False)
@@ -72,3 +86,7 @@
     def daysToKeepFeedEntries(self):
         pref = self._cachedPreference(DAYS_TO_KEEP_FEED_ENTRIES, 90, addIfMissing=True)
         return int(pref.value)
+
+    def setDaysToKeepFeedEntries(self, dayString):
+        pref = self._cachedPreference(DAYS_TO_KEEP_FEED_ENTRIES)
+        pref.value = dayString
--- a/PreferencesDialog.py	Wed Mar 30 02:59:22 2011 +0200
+++ b/PreferencesDialog.py	Thu Mar 31 03:15:39 2011 +0200
@@ -13,22 +13,33 @@
         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)
 
-        self.fillProxySettings()
-
     def fillProxySettings(self):
         if self.preferences.isProxyConfigured():
             self.ui.proxyHost.setText(self.preferences.proxyHost())
             self.ui.proxyPort.setText(str(self.preferences.proxyPort()))
 
+    def fillDaysToKeepFeedEntries(self):
+        days = self.preferences.daysToKeepFeedEntries()
+        self.ui.daysToKeepFeedEntries.setText(str(days))
+
     def startMaximizedChanged(self, change):
         if change:
             self.preferences.setStartMaximized(True)
@@ -48,12 +59,22 @@
             self.preferences.setShowOnlyUnreadFeeds(False)
 
     def storeProxySettings(self):
-        proxyHost = str(self.ui.proxyHost.text())
+        proxyHost = self.ui.proxyHost.text()
+        if proxyHost.isEmpty():
+            proxyHost = None
         self.preferences.setProxyHost(proxyHost)
 
-        proxyPort = int(self.ui.proxyPort.text())
+        proxyPort = self.ui.proxyPort.text()
+        if proxyPort.isEmpty():
+            proxyPort = None
         self.preferences.setProxyPort(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.session.commit()
--- a/Ui_Preferences.ui	Wed Mar 30 02:59:22 2011 +0200
+++ b/Ui_Preferences.ui	Thu Mar 31 03:15:39 2011 +0200
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>390</width>
-    <height>247</height>
+    <height>277</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -21,7 +21,7 @@
    <property name="geometry">
     <rect>
      <x>10</x>
-     <y>210</y>
+     <y>240</y>
      <width>160</width>
      <height>27</height>
     </rect>
@@ -84,7 +84,7 @@
    <property name="title">
     <string>Web Proxy</string>
    </property>
-   <widget class="QWidget" name="">
+   <widget class="QWidget" name="layoutWidget">
     <property name="geometry">
      <rect>
       <x>6</x>
@@ -117,6 +117,45 @@
     </layout>
    </widget>
   </widget>
+  <widget class="QLabel" name="label_3">
+   <property name="geometry">
+    <rect>
+     <x>11</x>
+     <y>205</y>
+     <width>136</width>
+     <height>17</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Keep feed entries for </string>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="daysToKeepFeedEntries">
+   <property name="geometry">
+    <rect>
+     <x>150</x>
+     <y>200</y>
+     <width>31</width>
+     <height>23</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string/>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_4">
+   <property name="geometry">
+    <rect>
+     <x>190</x>
+     <y>205</y>
+     <width>31</width>
+     <height>17</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>days</string>
+   </property>
+  </widget>
  </widget>
  <resources>
   <include location="Feedworm.qrc"/>
@@ -202,10 +241,27 @@
     </hint>
    </hints>
   </connection>
+  <connection>
+   <sender>daysToKeepFeedEntries</sender>
+   <signal>editingFinished()</signal>
+   <receiver>Preferences</receiver>
+   <slot>daysToKeepFeedEntriesFinishedEditing()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>165</x>
+     <y>211</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>194</x>
+     <y>138</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
  <slots>
   <slot>startMaximizedChanged()</slot>
   <slot>hideReadFeedEntriesChanged()</slot>
   <slot>showOnlyFeedsWithUnreadEntries()</slot>
+  <slot>daysToKeepFeedEntriesFinishedEditing()</slot>
  </slots>
 </ui>