6 """ |
6 """ |
7 Module implementing a RSS feeds manager dialog. |
7 Module implementing a RSS feeds manager dialog. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt4.QtCore import pyqtSlot, pyqtSignal, Qt, QUrl, QXmlStreamReader |
10 from PyQt4.QtCore import pyqtSlot, pyqtSignal, Qt, QUrl, QXmlStreamReader |
11 from PyQt4.QtGui import QDialog, QIcon, QTreeWidgetItem, QMenu, QCursor, QApplication |
11 from PyQt4.QtGui import QDialog, QIcon, QTreeWidgetItem, QMenu, QCursor, \ |
|
12 QApplication |
12 from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply |
13 from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply |
13 from PyQt4.QtWebKit import QWebSettings |
14 from PyQt4.QtWebKit import QWebSettings |
14 |
15 |
15 from E5Gui import E5MessageBox |
16 from E5Gui import E5MessageBox |
16 |
17 |
84 if feed[0] == urlString: |
85 if feed[0] == urlString: |
85 return False |
86 return False |
86 |
87 |
87 # step 2: add the feed |
88 # step 2: add the feed |
88 if icon.isNull() or \ |
89 if icon.isNull() or \ |
89 icon == QIcon(QWebSettings.webGraphic(QWebSettings.DefaultFrameIconGraphic)): |
90 icon == QIcon(QWebSettings.webGraphic( |
|
91 QWebSettings.DefaultFrameIconGraphic)): |
90 icon = UI.PixmapCache.getIcon("rss16.png") |
92 icon = UI.PixmapCache.getIcon("rss16.png") |
91 feed = (urlString, title, icon) |
93 feed = (urlString, title, icon) |
92 self.__feeds.append(feed) |
94 self.__feeds.append(feed) |
93 self.__addFeedItem(feed) |
95 self.__addFeedItem(feed) |
94 self.__save() |
96 self.__save() |
170 urlString, title = dlg.getData() |
172 urlString, title = dlg.getData() |
171 for feed in self.__feeds: |
173 for feed in self.__feeds: |
172 if feed[0] == urlString: |
174 if feed[0] == urlString: |
173 E5MessageBox.critical(self, |
175 E5MessageBox.critical(self, |
174 self.trUtf8("Duplicate Feed URL"), |
176 self.trUtf8("Duplicate Feed URL"), |
175 self.trUtf8("""A feed with the URL {0} exists already.""" |
177 self.trUtf8( |
176 """ Aborting...""".format(urlString))) |
178 """A feed with the URL {0} exists already.""" |
|
179 """ Aborting...""".format(urlString))) |
177 return |
180 return |
178 |
181 |
179 self.__feeds[feedIndex] = (urlString, title, feedToChange[2]) |
182 self.__feeds[feedIndex] = (urlString, title, feedToChange[2]) |
180 self.__save() |
183 self.__save() |
181 |
184 |
191 itm = self.feedsTree.selectedItems()[0] |
194 itm = self.feedsTree.selectedItems()[0] |
192 title = itm.text(0) |
195 title = itm.text(0) |
193 res = E5MessageBox.yesNo(self, |
196 res = E5MessageBox.yesNo(self, |
194 self.trUtf8("Delete Feed"), |
197 self.trUtf8("Delete Feed"), |
195 self.trUtf8( |
198 self.trUtf8( |
196 """<p>Do you really want to delete the feed <b>{0}</b>?</p>""".format( |
199 """<p>Do you really want to delete the feed""" |
197 title))) |
200 """ <b>{0}</b>?</p>""".format(title))) |
198 if res: |
201 if res: |
199 urlString = itm.data(0, FeedsManager.UrlStringRole) |
202 urlString = itm.data(0, FeedsManager.UrlStringRole) |
200 if urlString: |
203 if urlString: |
201 feedToDelete = None |
204 feedToDelete = None |
202 for feed in self.__feeds: |
205 for feed in self.__feeds: |
247 for child in itm.takeChildren(): |
250 for child in itm.takeChildren(): |
248 del child |
251 del child |
249 |
252 |
250 import Helpviewer.HelpWindow |
253 import Helpviewer.HelpWindow |
251 request = QNetworkRequest(QUrl(urlString)) |
254 request = QNetworkRequest(QUrl(urlString)) |
252 reply = Helpviewer.HelpWindow.HelpWindow.networkAccessManager().get(request) |
255 reply = Helpviewer.HelpWindow.HelpWindow.networkAccessManager()\ |
|
256 .get(request) |
253 reply.finished[()].connect(self.__feedLoaded) |
257 reply.finished[()].connect(self.__feedLoaded) |
254 self.__replies[id(reply)] = (reply, itm) |
258 self.__replies[id(reply)] = (reply, itm) |
255 |
259 |
256 def __feedLoaded(self): |
260 def __feedLoaded(self): |
257 """ |
261 """ |
297 |
301 |
298 if topItem.childCount() == 0: |
302 if topItem.childCount() == 0: |
299 itm = QTreeWidgetItem(topItem) |
303 itm = QTreeWidgetItem(topItem) |
300 itm.setText(0, self.trUtf8("Error fetching feed")) |
304 itm.setText(0, self.trUtf8("Error fetching feed")) |
301 itm.setData(0, FeedsManager.UrlStringRole, "") |
305 itm.setData(0, FeedsManager.UrlStringRole, "") |
302 itm.setData(0, FeedsManager.ErrorDataRole, str(xmlData, encoding="utf-8")) |
306 itm.setData(0, FeedsManager.ErrorDataRole, |
|
307 str(xmlData, encoding="utf-8")) |
303 |
308 |
304 topItem.setExpanded(True) |
309 topItem.setExpanded(True) |
305 else: |
310 else: |
306 linkString = "" |
311 linkString = "" |
307 titleString = reply.errorString() |
312 titleString = reply.errorString() |
324 return |
329 return |
325 |
330 |
326 urlString = itm.data(0, FeedsManager.UrlStringRole) |
331 urlString = itm.data(0, FeedsManager.UrlStringRole) |
327 if urlString: |
332 if urlString: |
328 menu = QMenu() |
333 menu = QMenu() |
329 menu.addAction(self.trUtf8("&Open"), self.__openMessageInCurrentTab) |
334 menu.addAction( |
330 menu.addAction(self.trUtf8("Open in New &Tab"), self.__openMessageInNewTab) |
335 self.trUtf8("&Open"), self.__openMessageInCurrentTab) |
|
336 menu.addAction( |
|
337 self.trUtf8("Open in New &Tab"), self.__openMessageInNewTab) |
331 menu.addSeparator() |
338 menu.addSeparator() |
332 menu.addAction(self.trUtf8("&Copy URL to Clipboard"), |
339 menu.addAction(self.trUtf8("&Copy URL to Clipboard"), |
333 self.__copyUrlToClipboard) |
340 self.__copyUrlToClipboard) |
334 menu.exec_(QCursor.pos()) |
341 menu.exec_(QCursor.pos()) |
335 else: |
342 else: |
336 errorString = itm.data(0, FeedsManager.ErrorDataRole) |
343 errorString = itm.data(0, FeedsManager.ErrorDataRole) |
337 if errorString: |
344 if errorString: |
338 menu = QMenu() |
345 menu = QMenu() |
339 menu.addAction(self.trUtf8("&Show error data"), self.__showError) |
346 menu.addAction( |
|
347 self.trUtf8("&Show error data"), self.__showError) |
340 menu.exec_(QCursor.pos()) |
348 menu.exec_(QCursor.pos()) |
341 |
349 |
342 def __itemActivated(self, itm, column): |
350 def __itemActivated(self, itm, column): |
343 """ |
351 """ |
344 Private slot to handle the activation of an item. |
352 Private slot to handle the activation of an item. |
348 """ |
356 """ |
349 if self.feedsTree.indexOfTopLevelItem(itm) != -1: |
357 if self.feedsTree.indexOfTopLevelItem(itm) != -1: |
350 return |
358 return |
351 |
359 |
352 self.__openMessage( |
360 self.__openMessage( |
353 QApplication.keyboardModifiers() & Qt.ControlModifier == Qt.ControlModifier) |
361 QApplication.keyboardModifiers() & |
|
362 Qt.ControlModifier == Qt.ControlModifier) |
354 |
363 |
355 def __openMessageInCurrentTab(self): |
364 def __openMessageInCurrentTab(self): |
356 """ |
365 """ |
357 Private slot to open a feed message in the current browser tab. |
366 Private slot to open a feed message in the current browser tab. |
358 """ |
367 """ |