diff MainWindow.py @ 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 a05719a6175e
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)