changeset 151:bca9341dc67f

move the selected feed into the backend - sqlalchemy backend works, couchdb backend currently broken
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sat, 27 Aug 2011 07:07:50 +0200
parents babe14449162
children a1c0459e1eeb
files FeedSettings.py MainWindow.py backend/sqlalchemy/SqlAlchemyBackend.py
diffstat 3 files changed, 34 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/FeedSettings.py	Sat Aug 27 06:43:28 2011 +0200
+++ b/FeedSettings.py	Sat Aug 27 07:07:50 2011 +0200
@@ -7,15 +7,15 @@
     Copy all feed properties into the GUI on initialization. Collect all changes
     in a separate dict that's passed into the backend along with the feed to modify.
     """
-    def __init__(self, feed, backend):
+    def __init__(self, backend):
         QtGui.QWidget.__init__(self, None)
-        self.feed = feed
         self.backend = backend
+        self.feed = backend.selectedFeed
         self.changes = {}
         self.ui = Ui_FeedSettings()
         self.ui.setupUi(self)
         self.initUi()
-        
+
     def initUi(self):
         self.ui.feedTitle.setText(self.feed.title)
         self.ui.updateInterval.setText(str(self.feed.update_interval))
@@ -25,7 +25,7 @@
     def editingTitleFinished(self):
         title = str(self.ui.feedTitle.text())
         self.changes["title"] = title
-        
+
     def editingUpdateIntervalFinished(self):
         updateInterval = int(str(self.ui.updateInterval.text()))
         self.changes["update_interval"] = updateInterval
--- a/MainWindow.py	Sat Aug 27 06:43:28 2011 +0200
+++ b/MainWindow.py	Sat Aug 27 07:07:50 2011 +0200
@@ -25,8 +25,8 @@
         self.initFeedEntryList()
 
     def updateFeedList(self):
-        self.allFeeds = self.backend.getFeeds()
-        feedModel = DisplayModel(self, self.allFeeds, "title")
+        allFeeds = self.backend.getFeeds()
+        feedModel = DisplayModel(self, allFeeds, "title")
         self.ui.feedList.setModel(feedModel)
         self.ui.feedList.update()
 
@@ -39,7 +39,7 @@
         self.ui.feedEntryList.horizontalHeader().setStretchLastSection(True)
 
     def feedSelected(self, index):
-        self.selectedFeed = self.allFeeds[index.row()]
+        self.backend.selectFeed(index.row())
         self.enableFeedRelatedWidgets()
         self.setupFeedEntries()
 
@@ -49,8 +49,9 @@
         self.ui.actionDeleteFeed.setEnabled(True)
 
     def setupFeedEntries(self):
+        # TODO move the access to preferences into the backend
         hideReadEntries = self.preferences.hideReadFeedEntries()
-        self.feedEntries = self.backend.entriesForFeed(self.selectedFeed, hideReadEntries)
+        self.feedEntries = self.backend.entriesForSelectedFeed(hideReadEntries)
         self.initFeedDisplayModel()
 
     def initFeedDisplayModel(self):
@@ -120,7 +121,7 @@
         self.ui.feedEntryList.doItemsLayout()
 
     def markSelectedFeedRead(self):
-        self.backend.markAllEntriesRead(self.selectedFeed)
+        self.backend.markSelectedFeedAsRead()
         self.ui.feedEntryList.doItemsLayout()
 
     def markSelectedEntriesRead(self):
@@ -151,7 +152,7 @@
 
     def deleteFeed(self):
         try:
-            self.backend.deleteFeed(self.selectedFeed)
+            self.backend.deleteSelectedFeed()
             self.updateFeedList()
         except Exception as exception:
             message = "Error while deleting feed: " + str(exception)
@@ -162,7 +163,7 @@
         preferences.exec_()
 
     def showFeedSettings(self):
-        feedSettings = FeedSettings(self.selectedFeed, self.backend)
+        feedSettings = FeedSettings(self.backend)
         feedSettings.exec_()
 
     def _updateStatusBar(self, message):
--- a/backend/sqlalchemy/SqlAlchemyBackend.py	Sat Aug 27 06:43:28 2011 +0200
+++ b/backend/sqlalchemy/SqlAlchemyBackend.py	Sat Aug 27 07:07:50 2011 +0200
@@ -21,6 +21,8 @@
         self.session = Database.createSession()
         self.prefs = Preferences(self.session)
         self.updater = None
+        self.feeds = []
+        self.selectedFeed = None
 
     def _initLogging(self):
         logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN)
@@ -35,9 +37,10 @@
 
     def getFeeds(self):
         if self.preferences().showOnlyUnreadFeeds():
-            return self._getUnreadFeeds()
+            self.feeds = self._getUnreadFeeds()
         else:
-            return Feed.all(self.session)
+            self.feeds = Feed.all(self.session)
+        return self.feeds
 
     def _getUnreadFeeds(self):
         query = self.session.query(FeedEntry).filter(FeedEntry.read == 0)
@@ -50,14 +53,27 @@
         uniqueFeeds = set(feeds)
         return list(uniqueFeeds)
 
+    def selectFeed(self, index):
+        self.selectedFeed = self.feeds[index]
+        return self.selectedFeed
+
+    def entriesForSelectedFeed(self, hideReadEntries):
+        return self.selectedFeed.entriesSortedByUpdateDate(hideReadEntries)
+
+    def markSelectedFeedAsRead(self):
+        self.selectedFeed.markAllEntriesRead()
+        self.session.commit()
+
+    def deleteSelectedFeed(self):
+        self.session.delete(self.selectedFeed)
+        self.session.commit()
+
+
+
     def toggleRead(self, feedEntry):
         feedEntry.toggleRead()
         self.session.commit()
 
-    def markAllEntriesRead(self, feed):
-        feed.markAllEntriesRead()
-        self.session.commit()
-
     def createFeed(self, url):
         try:
             FeedUpdater.createNewFeed(url, self.session)
@@ -71,12 +87,6 @@
         feed.incrementNextUpdateDate()
         self.session.commit()
 
-    def deleteFeed(self, feed):
-        self.session.delete(feed)
-        self.session.commit()
-
-    def entriesForFeed(self, feed, hideReadEntries):
-        return feed.entriesSortedByUpdateDate(hideReadEntries)
 
     def markFeedEntriesAsRead(self, entries):
         for entry in entries: