# HG changeset patch # User Dirk Olmes # Date 1272516467 -7200 # Node ID bdd1296a4b8c015c24aafce604751bcb66ca5a41 # Parent f9a3223182c51712507d2273e1f1f226ea582545 implemented adding a feed diff -r f9a3223182c5 -r bdd1296a4b8c AddFeed.py --- /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) diff -r f9a3223182c5 -r bdd1296a4b8c FeedUpdater.py --- 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 diff -r f9a3223182c5 -r bdd1296a4b8c MainWindow.py --- 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() diff -r f9a3223182c5 -r bdd1296a4b8c Ui_AddFeed.ui --- /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 @@ + + + AddFeed + + + + 0 + 0 + 557 + 108 + + + + Add Feed + + + true + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + Feed URL + + + + + + + url + buttonBox + + + + + buttonBox + accepted() + AddFeed + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AddFeed + reject() + + + 316 + 260 + + + 286 + 274 + + + + +