Mercurial > hg > Feedworm
comparison 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 |
comparison
equal
deleted
inserted
replaced
152:a1c0459e1eeb | 153:65c4bb6d5add |
---|---|
47 self.ui.actionFeedSettings.setEnabled(True) | 47 self.ui.actionFeedSettings.setEnabled(True) |
48 self.ui.actionMarkFeedRead.setEnabled(True) | 48 self.ui.actionMarkFeedRead.setEnabled(True) |
49 self.ui.actionDeleteFeed.setEnabled(True) | 49 self.ui.actionDeleteFeed.setEnabled(True) |
50 | 50 |
51 def setupFeedEntries(self): | 51 def setupFeedEntries(self): |
52 # TODO move the access to preferences into the backend | |
53 hideReadEntries = self.preferences.hideReadFeedEntries() | |
54 self.feedEntries = self.backend.entriesForSelectedFeed(hideReadEntries) | |
55 self.initFeedEntriesDisplayModel() | |
56 | |
57 def initFeedEntriesDisplayModel(self): | |
58 self.setupFeedEntriesTableModel() | 52 self.setupFeedEntriesTableModel() |
59 self.ui.feedEntryList.update() | 53 self.ui.feedEntryList.update() |
60 self.setupFeedEntriesTableHeaderWidths() | 54 self.setupFeedEntriesTableHeaderWidths() |
61 self.scrollFirstRowInFeedEntriesTableToVisible() | 55 self.scrollFirstRowInFeedEntriesTableToVisible() |
62 | 56 |
63 def setupFeedEntriesTableModel(self): | 57 def setupFeedEntriesTableModel(self): |
64 model = FeedEntryTableModel(self.feedEntries) | 58 feedEntries = self.backend.entriesForSelectedFeed() |
59 model = FeedEntryTableModel(feedEntries) | |
65 self.ui.feedEntryList.setModel(model) | 60 self.ui.feedEntryList.setModel(model) |
66 | 61 |
67 def setupFeedEntriesTableHeaderWidths(self): | 62 def setupFeedEntriesTableHeaderWidths(self): |
68 width = self.ui.feedEntryList.width() | 63 width = self.ui.feedEntryList.width() |
69 firstColumnWidth = int(width * 0.8) | 64 firstColumnWidth = int(width * 0.8) |
77 def feedEntrySelected(self, index): | 72 def feedEntrySelected(self, index): |
78 self.ui.menuArticle.setEnabled(True) | 73 self.ui.menuArticle.setEnabled(True) |
79 self.ui.actionOpenLink.setEnabled(True) | 74 self.ui.actionOpenLink.setEnabled(True) |
80 | 75 |
81 row = index.row() | 76 row = index.row() |
82 self.selectedEntry = self.feedEntries[row] | 77 feedEntry = self.backend.selectFeedEntry(row) |
83 self.selectedEntry.markRead() | |
84 | 78 |
85 if self.selectedEntry.feed.auto_load_entry_link: | 79 # TODO this is not compatible with the couchdb backend |
80 if feedEntry.feed.auto_load_entry_link: | |
86 self.openLinkFromSelectedEntry() | 81 self.openLinkFromSelectedEntry() |
87 else: | 82 else: |
88 self.openSummaryFromSelectedEntry() | 83 self.openSummaryFromSelectedEntry() |
89 | 84 |
90 def feedEntryDoubleClicked(self, index): | 85 def feedEntryDoubleClicked(self, index): |
91 self.ui.menuArticle.setEnabled(True) | 86 self.ui.menuArticle.setEnabled(True) |
92 self.openSelectedEntryInBrowser() | 87 self.openSelectedEntryInBrowser() |
93 | 88 |
94 def openSummaryFromSelectedEntry(self): | 89 def openSummaryFromSelectedEntry(self): |
95 # TODO this is the wrong base url, figure out the correct one | 90 # TODO this is the wrong base url, figure out the correct one |
96 baseUrl = QUrl(self.selectedEntry.link) | 91 feedEntry = self.backend.selectedFeedEntry |
97 self.ui.webView.setHtml(self.selectedEntry.summary, baseUrl) | 92 baseUrl = QUrl(feedEntry.link) |
93 self.ui.webView.setHtml(feedEntry.summary, baseUrl) | |
98 | 94 |
99 def openLinkFromSelectedEntry(self): | 95 def openLinkFromSelectedEntry(self): |
100 if self.selectedEntry.feed.always_open_in_browser: | 96 feedEntry = self.backend.selectedFeedEntry |
97 # TODO this is not compatible with the couchdb backend | |
98 if feedEntry.feed.always_open_in_browser: | |
101 self.openSelectedEntryInBrowser() | 99 self.openSelectedEntryInBrowser() |
102 else: | 100 else: |
103 self.openSelectedEntryInWebView() | 101 self.openSelectedEntryInWebView() |
104 | 102 |
105 def openSelectedEntryInWebView(self): | 103 def openSelectedEntryInWebView(self): |
106 message = "Open %s ..." % (self.selectedEntry.title) | 104 feedEntry = self.backend.selectedFeedEntry |
105 message = "Open %s ..." % (feedEntry.title) | |
107 self._updateStatusBar(message) | 106 self._updateStatusBar(message) |
108 url = QUrl(self.selectedEntry.link) | 107 url = QUrl(feedEntry.link) |
109 self.ui.webView.load(url) | 108 self.ui.webView.load(url) |
110 self.ui.webView.show() | 109 self.ui.webView.show() |
111 | 110 |
112 def openSelectedEntryInBrowser(self): | 111 def openSelectedEntryInBrowser(self): |
113 message = "Open %s in external browser" % (self.selectedEntry.title) | 112 feedEntry = self.backend.selectedFeedEntry |
113 message = "Open %s in external browser" % (feedEntry.title) | |
114 self._updateStatusBar(message) | 114 self._updateStatusBar(message) |
115 # TODO make browser configurable | 115 # TODO make browser configurable |
116 browser = "/usr/local/bin/opera" | 116 browser = "/usr/local/bin/opera" |
117 subprocess.Popen([browser, self.selectedEntry.link]) | 117 subprocess.Popen([browser, feedEntry.link]) |
118 | 118 |
119 def toggleReadOnSelectedEntry(self): | 119 def toggleReadOnSelectedEntry(self): |
120 self.backend.toggleRead(self.selectedEntry) | 120 self.backend.toggleSelectedFeedEntryRead() |
121 self.ui.feedEntryList.doItemsLayout() | 121 self.ui.feedEntryList.doItemsLayout() |
122 | 122 |
123 def markSelectedFeedRead(self): | 123 def markSelectedFeedRead(self): |
124 self.backend.markSelectedFeedAsRead() | 124 self.backend.markSelectedFeedAsRead() |
125 self.ui.feedEntryList.doItemsLayout() | 125 self.ui.feedEntryList.doItemsLayout() |
126 | 126 |
127 def markSelectedEntriesRead(self): | 127 def markSelectedEntriesRead(self): |
128 entriesToBeMarked = [] | 128 indexes = [] |
129 selectedIndexes = self.ui.feedEntryList.selectedIndexes() | 129 selectedIndexes = self.ui.feedEntryList.selectedIndexes() |
130 for index in selectedIndexes: | 130 for index in selectedIndexes: |
131 # selectedIndexes returns one QModelIndex instance per row/column combo. | 131 # selectedIndexes returns one QModelIndex instance per row/column combo. |
132 # We are only interested in the rows here so just operate on the first | 132 # We are only interested in the rows here so just operate on the first |
133 # column | 133 # column |
134 if index.column() == 0: | 134 if index.column() == 0: |
135 row = index.row() | 135 row = index.row() |
136 entriesToBeMarked.append(self.feedEntries[row]) | 136 indexes.append(row) |
137 self.backend.markFeedEntriesAsRead(entriesToBeMarked) | 137 self.backend.markFeedEntriesAsRead(indexes) |
138 self.selectedEntry = None | |
139 self.ui.feedEntryList.doItemsLayout() | 138 self.ui.feedEntryList.doItemsLayout() |
140 | 139 |
141 def addFeed(self): | 140 def addFeed(self): |
142 addFeed = AddFeed(self.backend) | 141 addFeed = AddFeed(self.backend) |
143 success = addFeed.exec_() | 142 success = addFeed.exec_() |
173 self.backend.dispose() | 172 self.backend.dispose() |
174 QMainWindow.close(self) | 173 QMainWindow.close(self) |
175 | 174 |
176 def copyArticleURLToClipboard(self): | 175 def copyArticleURLToClipboard(self): |
177 clipboard = QApplication.clipboard() | 176 clipboard = QApplication.clipboard() |
178 clipboard.setText(self.selectedEntry.link) | 177 clipboard.setText(self.backend.selectedFeedEntry.link) |