eric6/Helpviewer/Feeds/FeedsDialog.py

branch
maintenance
changeset 7286
7eb04391adf7
parent 7226
babe80d84a3e
parent 7285
1ff497f33f31
child 7287
1c17f2191bdd
equal deleted inserted replaced
7226:babe80d84a3e 7286:7eb04391adf7
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to add RSS feeds.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import QUrl
13 from PyQt5.QtWidgets import QDialog, QPushButton, QLabel
14
15 from E5Gui import E5MessageBox
16
17 from .Ui_FeedsDialog import Ui_FeedsDialog
18
19 import UI.PixmapCache
20
21
22 class FeedsDialog(QDialog, Ui_FeedsDialog):
23 """
24 Class implementing a dialog to add RSS feeds.
25 """
26 def __init__(self, availableFeeds, browser, parent=None):
27 """
28 Constructor
29
30 @param availableFeeds list of available RSS feeds (list of tuple of
31 two strings)
32 @param browser reference to the browser widget (HelpBrowser)
33 @param parent reference to the parent widget (QWidget)
34 """
35 super(FeedsDialog, self).__init__(parent)
36 self.setupUi(self)
37
38 self.iconLabel.setPixmap(UI.PixmapCache.getPixmap("rss48.png"))
39
40 self.__browser = browser
41
42 self.__availableFeeds = availableFeeds[:]
43 for row in range(len(self.__availableFeeds)):
44 feed = self.__availableFeeds[row]
45 button = QPushButton(self)
46 button.setText(self.tr("Add"))
47 button.feed = feed
48 label = QLabel(self)
49 label.setText(feed[0])
50 self.feedsLayout.addWidget(label, row, 0)
51 self.feedsLayout.addWidget(button, row, 1)
52 button.clicked.connect(lambda: self.__addFeed(button))
53
54 msh = self.minimumSizeHint()
55 self.resize(max(self.width(), msh.width()), msh.height())
56
57 def __addFeed(self, button):
58 """
59 Private slot to add a RSS feed.
60
61 @param button reference to the feed button
62 @type QPushButton
63 """
64 urlString = button.feed[1]
65 url = QUrl(urlString)
66 if not url.host():
67 if not urlString.startswith("/"):
68 urlString = "/" + urlString
69 urlString = self.__browser.url().host() + urlString
70 tmpUrl = QUrl(urlString)
71 if not tmpUrl.scheme():
72 urlString = "http://" + urlString
73 tmpUrl = QUrl(urlString)
74 if not tmpUrl.scheme() or not tmpUrl.host():
75 return
76 if not url.isValid():
77 return
78
79 if button.feed[0]:
80 title = button.feed[0]
81 else:
82 title = self.__browser.url().host()
83
84 import Helpviewer.HelpWindow
85 feedsManager = Helpviewer.HelpWindow.HelpWindow.feedsManager()
86 if feedsManager.addFeed(urlString, title, self.__browser.icon()):
87 if Helpviewer.HelpWindow.HelpWindow.notificationsEnabled():
88 Helpviewer.HelpWindow.HelpWindow.showNotification(
89 UI.PixmapCache.getPixmap("rss48.png"),
90 self.tr("Add RSS Feed"),
91 self.tr("""The feed was added successfully."""))
92 else:
93 E5MessageBox.information(
94 self,
95 self.tr("Add RSS Feed"),
96 self.tr("""The feed was added successfully."""))
97 else:
98 E5MessageBox.warning(
99 self,
100 self.tr("Add RSS Feed"),
101 self.tr("""The feed was already added before."""))
102
103 self.close()

eric ide

mercurial