changeset 27:bdd1296a4b8c

implemented adding a feed
author Dirk Olmes <dirk@xanthippe.ping.de>
date Thu, 29 Apr 2010 06:47:47 +0200
parents f9a3223182c5
children 72dfae865899
files AddFeed.py FeedUpdater.py MainWindow.py Ui_AddFeed.ui
diffstat 4 files changed, 119 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AddFeed.py	Thu Apr 29 06:47:47 2010 +0200
@@ -0,0 +1,16 @@
+
+from PyQt4 import QtGui
+from Ui_AddFeed import Ui_AddFeed
+
+class AddFeed(QtGui.QDialog):
+    def __init__(self, session=None):
+        QtGui.QWidget.__init__(self, None)
+        self.session = session
+        self.ui = Ui_AddFeed()
+        self.ui.setupUi(self)
+        self.ui.url.setFocus()
+    
+    def getUrl(self):
+        text = self.ui.url.text()
+        # the content of a QLineEdit is a QString, convert it to a Python string
+        return str(text)
--- a/FeedUpdater.py	Thu Apr 29 06:47:22 2010 +0200
+++ b/FeedUpdater.py	Thu Apr 29 06:47:47 2010 +0200
@@ -17,6 +17,15 @@
             logger.warn("problems while updating feed " + feed.rss_url)
         session.commit()
 
+def createNewFeed(url, session):
+    result = feedparser.parse(url)
+    title = result["feed"].title
+    newFeed = Feed(title, url)
+    session.add(newFeed)
+    session.commit()
+    FeedUpdater(newFeed).update()
+    session.commit()
+
 class FeedUpdater(object):
     def __init__(self, session, feed):
         self.session = session
--- a/MainWindow.py	Thu Apr 29 06:47:22 2010 +0200
+++ b/MainWindow.py	Thu Apr 29 06:47:47 2010 +0200
@@ -1,7 +1,9 @@
 
+from AddFeed import AddFeed
 from DisplayModel import DisplayModel
 from Feed import Feed
 from FeedEntry import FeedEntry
+import FeedUpdater
 from PyQt4 import QtGui
 from PyQt4.QtCore import QUrl
 from Ui_MainWindow import Ui_MainWindow
@@ -12,13 +14,14 @@
         self.session = session
         self.ui = Ui_MainWindow()
         self.ui.setupUi(self)
-        self.setupFeedList()
+        self.updateFeedList()
         
-    def setupFeedList(self):
+    def updateFeedList(self):
         self.allFeeds = Feed.all(self.session)
         feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString)
         self.ui.feedList.setModel(feedModel)
-        
+        self.ui.feedList.update()
+
     def feedSelected(self, index):
         self.selectedFeed = self.allFeeds[index.row()]
         model = DisplayModel(self, self.selectedFeed.entries, FeedEntry.userPresentableString)
@@ -32,5 +35,10 @@
         self.ui.webView.setHtml(entry.summary, baseUrl)
     
     def addFeed(self):
-        print("Add Feed!")
-    
\ No newline at end of file
+        addFeed = AddFeed(self.session)
+        success = addFeed.exec_()
+        if success:
+            url = addFeed.getUrl()
+            FeedUpdater.createNewFeed(url, self.session)
+            # TODO get status from feedUpdater and display in status area of the main window
+            self.updateFeedList()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ui_AddFeed.ui	Thu Apr 29 06:47:47 2010 +0200
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>AddFeed</class>
+ <widget class="QDialog" name="AddFeed">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>557</width>
+    <height>108</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Add Feed</string>
+  </property>
+  <property name="modal">
+   <bool>true</bool>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="2" column="1">
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="1">
+    <widget class="QLineEdit" name="url"/>
+   </item>
+   <item row="1" column="0">
+    <widget class="QLabel" name="label">
+     <property name="text">
+      <string>Feed URL</string>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <tabstops>
+  <tabstop>url</tabstop>
+  <tabstop>buttonBox</tabstop>
+ </tabstops>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>AddFeed</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>AddFeed</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>