changeset 153:65c4bb6d5add

move management of the selected feed entry into the backend - sqlachemy backend works, couchdb backend currently broken
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sat, 27 Aug 2011 07:29:33 +0200
parents a1c0459e1eeb
children 2682db280be0
files MainWindow.py backend/sqlalchemy/SqlAlchemyBackend.py
diffstat 2 files changed, 50 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/MainWindow.py	Sat Aug 27 07:11:08 2011 +0200
+++ b/MainWindow.py	Sat Aug 27 07:29:33 2011 +0200
@@ -49,19 +49,14 @@
         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.entriesForSelectedFeed(hideReadEntries)
-        self.initFeedEntriesDisplayModel()
-
-    def initFeedEntriesDisplayModel(self):
         self.setupFeedEntriesTableModel()
         self.ui.feedEntryList.update()
         self.setupFeedEntriesTableHeaderWidths()
         self.scrollFirstRowInFeedEntriesTableToVisible()
 
     def setupFeedEntriesTableModel(self):
-        model = FeedEntryTableModel(self.feedEntries)
+        feedEntries = self.backend.entriesForSelectedFeed()
+        model = FeedEntryTableModel(feedEntries)
         self.ui.feedEntryList.setModel(model)
 
     def setupFeedEntriesTableHeaderWidths(self):
@@ -79,10 +74,10 @@
         self.ui.actionOpenLink.setEnabled(True)
 
         row = index.row()
-        self.selectedEntry = self.feedEntries[row]
-        self.selectedEntry.markRead()
+        feedEntry = self.backend.selectFeedEntry(row)
 
-        if self.selectedEntry.feed.auto_load_entry_link:
+        # TODO this is not compatible with the couchdb backend
+        if feedEntry.feed.auto_load_entry_link:
             self.openLinkFromSelectedEntry()
         else:
             self.openSummaryFromSelectedEntry()
@@ -93,31 +88,36 @@
 
     def openSummaryFromSelectedEntry(self):
         # TODO this is the wrong base url, figure out the correct one
-        baseUrl = QUrl(self.selectedEntry.link)
-        self.ui.webView.setHtml(self.selectedEntry.summary, baseUrl)
+        feedEntry = self.backend.selectedFeedEntry
+        baseUrl = QUrl(feedEntry.link)
+        self.ui.webView.setHtml(feedEntry.summary, baseUrl)
 
     def openLinkFromSelectedEntry(self):
-        if self.selectedEntry.feed.always_open_in_browser:
+        feedEntry = self.backend.selectedFeedEntry
+        # TODO this is not compatible with the couchdb backend
+        if feedEntry.feed.always_open_in_browser:
             self.openSelectedEntryInBrowser()
         else:
             self.openSelectedEntryInWebView()
 
     def openSelectedEntryInWebView(self):
-        message = "Open %s ..." % (self.selectedEntry.title)
+        feedEntry = self.backend.selectedFeedEntry
+        message = "Open %s ..." % (feedEntry.title)
         self._updateStatusBar(message)
-        url = QUrl(self.selectedEntry.link)
+        url = QUrl(feedEntry.link)
         self.ui.webView.load(url)
         self.ui.webView.show()
 
     def openSelectedEntryInBrowser(self):
-        message = "Open %s in external browser" % (self.selectedEntry.title)
+        feedEntry = self.backend.selectedFeedEntry
+        message = "Open %s in external browser" % (feedEntry.title)
         self._updateStatusBar(message)
         # TODO make browser configurable
         browser = "/usr/local/bin/opera"
-        subprocess.Popen([browser, self.selectedEntry.link])
+        subprocess.Popen([browser, feedEntry.link])
 
     def toggleReadOnSelectedEntry(self):
-        self.backend.toggleRead(self.selectedEntry)
+        self.backend.toggleSelectedFeedEntryRead()
         self.ui.feedEntryList.doItemsLayout()
 
     def markSelectedFeedRead(self):
@@ -125,7 +125,7 @@
         self.ui.feedEntryList.doItemsLayout()
 
     def markSelectedEntriesRead(self):
-        entriesToBeMarked = []
+        indexes = []
         selectedIndexes = self.ui.feedEntryList.selectedIndexes()
         for index in selectedIndexes:
             # selectedIndexes returns one QModelIndex instance per row/column combo.
@@ -133,9 +133,8 @@
             # column
             if index.column() == 0:
                 row = index.row()
-                entriesToBeMarked.append(self.feedEntries[row])
-        self.backend.markFeedEntriesAsRead(entriesToBeMarked)
-        self.selectedEntry = None
+                indexes.append(row)
+        self.backend.markFeedEntriesAsRead(indexes)
         self.ui.feedEntryList.doItemsLayout()
 
     def addFeed(self):
@@ -175,4 +174,4 @@
 
     def copyArticleURLToClipboard(self):
         clipboard = QApplication.clipboard()
-        clipboard.setText(self.selectedEntry.link)
+        clipboard.setText(self.backend.selectedFeedEntry.link)
--- a/backend/sqlalchemy/SqlAlchemyBackend.py	Sat Aug 27 07:11:08 2011 +0200
+++ b/backend/sqlalchemy/SqlAlchemyBackend.py	Sat Aug 27 07:29:33 2011 +0200
@@ -23,6 +23,8 @@
         self.updater = None
         self.feeds = []
         self.selectedFeed = None
+        self.feedEntries = None
+        self.selectedFeedEntry = None
 
     def _initLogging(self):
         logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN)
@@ -35,6 +37,10 @@
     def preferences(self):
         return self.prefs
 
+    #
+    # handling of feeds
+    #
+
     def getFeeds(self):
         if self.preferences().showOnlyUnreadFeeds():
             self.feeds = self._getUnreadFeeds()
@@ -55,10 +61,14 @@
 
     def selectFeed(self, index):
         self.selectedFeed = self.feeds[index]
+        self.feedEntries = None
         return self.selectedFeed
 
-    def entriesForSelectedFeed(self, hideReadEntries):
-        return self.selectedFeed.entriesSortedByUpdateDate(hideReadEntries)
+    def entriesForSelectedFeed(self):
+        hideReadEntries = self.prefs.hideReadFeedEntries()
+        if self.feedEntries is None:
+            self.feedEntries = self.selectedFeed.entriesSortedByUpdateDate(hideReadEntries)
+        return self.feedEntries
 
     def markSelectedFeedAsRead(self):
         self.selectedFeed.markAllEntriesRead()
@@ -68,11 +78,24 @@
         self.session.delete(self.selectedFeed)
         self.session.commit()
 
+    #
+    # handling of the selected feed entry
+    #
+    def selectFeedEntry(self, index):
+        self.selectedFeedEntry = self.feedEntries[index]
+        self.selectedFeedEntry.markRead()
+        return self.selectedFeedEntry
+
+    def markFeedEntriesAsRead(self, indices):
+        for index in indices:
+            self.feedEntries[index].markRead()
+        self.session.commit()
+
+    def toggleSelectedFeedEntryRead(self):
+        self.selectedFeedEntry.toggleRead()
+        self.session.commit()
 
 
-    def toggleRead(self, feedEntry):
-        feedEntry.toggleRead()
-        self.session.commit()
 
     def createFeed(self, url):
         try:
@@ -88,10 +111,6 @@
         self.session.commit()
 
 
-    def markFeedEntriesAsRead(self, entries):
-        for entry in entries:
-            entry.markRead()
-        self.session.commit()
 
     def updateAllFeeds(self):
         FeedUpdater.updateAllFeeds(self.session)