20 |
20 |
21 class FeedsDialog(QDialog, Ui_FeedsDialog): |
21 class FeedsDialog(QDialog, Ui_FeedsDialog): |
22 """ |
22 """ |
23 Class implementing a dialog to add RSS feeds. |
23 Class implementing a dialog to add RSS feeds. |
24 """ |
24 """ |
|
25 |
25 def __init__(self, availableFeeds, browser, parent=None): |
26 def __init__(self, availableFeeds, browser, parent=None): |
26 """ |
27 """ |
27 Constructor |
28 Constructor |
28 |
29 |
29 @param availableFeeds list of available RSS feeds (list of tuple of |
30 @param availableFeeds list of available RSS feeds (list of tuple of |
30 two strings) |
31 two strings) |
31 @param browser reference to the browser widget (WebBrowserView) |
32 @param browser reference to the browser widget (WebBrowserView) |
32 @param parent reference to the parent widget (QWidget) |
33 @param parent reference to the parent widget (QWidget) |
33 """ |
34 """ |
34 super().__init__(parent) |
35 super().__init__(parent) |
35 self.setupUi(self) |
36 self.setupUi(self) |
36 |
37 |
37 self.iconLabel.setPixmap(UI.PixmapCache.getPixmap("rss48")) |
38 self.iconLabel.setPixmap(UI.PixmapCache.getPixmap("rss48")) |
38 |
39 |
39 self.__browser = browser |
40 self.__browser = browser |
40 |
41 |
41 self.__availableFeeds = availableFeeds[:] |
42 self.__availableFeeds = availableFeeds[:] |
42 for row in range(len(self.__availableFeeds)): |
43 for row in range(len(self.__availableFeeds)): |
43 feed = self.__availableFeeds[row] |
44 feed = self.__availableFeeds[row] |
44 button = QPushButton(self) |
45 button = QPushButton(self) |
45 button.setText(self.tr("Add")) |
46 button.setText(self.tr("Add")) |
46 button.feed = feed |
47 button.feed = feed |
47 label = QLabel(self) |
48 label = QLabel(self) |
48 label.setText(feed[0]) |
49 label.setText(feed[0]) |
49 self.feedsLayout.addWidget(label, row, 0) |
50 self.feedsLayout.addWidget(label, row, 0) |
50 self.feedsLayout.addWidget(button, row, 1) |
51 self.feedsLayout.addWidget(button, row, 1) |
51 button.clicked.connect( |
52 button.clicked.connect(functools.partial(self.__addFeed, button)) |
52 functools.partial(self.__addFeed, button)) |
53 |
53 |
|
54 msh = self.minimumSizeHint() |
54 msh = self.minimumSizeHint() |
55 self.resize(max(self.width(), msh.width()), msh.height()) |
55 self.resize(max(self.width(), msh.width()), msh.height()) |
56 |
56 |
57 def __addFeed(self, button): |
57 def __addFeed(self, button): |
58 """ |
58 """ |
59 Private slot to add a RSS feed. |
59 Private slot to add a RSS feed. |
60 |
60 |
61 @param button reference to the feed button |
61 @param button reference to the feed button |
62 @type QPushButton |
62 @type QPushButton |
63 """ |
63 """ |
64 urlString = button.feed[1] |
64 urlString = button.feed[1] |
65 url = QUrl(urlString) |
65 url = QUrl(urlString) |
66 if url.isRelative(): |
66 if url.isRelative(): |
67 url = self.__browser.url().resolved(url) |
67 url = self.__browser.url().resolved(url) |
68 urlString = url.toDisplayString( |
68 urlString = url.toDisplayString(QUrl.ComponentFormattingOption.FullyDecoded) |
69 QUrl.ComponentFormattingOption.FullyDecoded) |
69 |
70 |
|
71 if not url.isValid(): |
70 if not url.isValid(): |
72 return |
71 return |
73 |
72 |
74 title = (button.feed[0] if button.feed[0] |
73 title = button.feed[0] if button.feed[0] else self.__browser.url().host() |
75 else self.__browser.url().host()) |
74 |
76 |
|
77 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
75 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
76 |
78 feedsManager = WebBrowserWindow.feedsManager() |
77 feedsManager = WebBrowserWindow.feedsManager() |
79 if feedsManager.addFeed(urlString, title, self.__browser.icon()): |
78 if feedsManager.addFeed(urlString, title, self.__browser.icon()): |
80 WebBrowserWindow.showNotification( |
79 WebBrowserWindow.showNotification( |
81 UI.PixmapCache.getPixmap("rss48"), |
80 UI.PixmapCache.getPixmap("rss48"), |
82 self.tr("Add RSS Feed"), |
81 self.tr("Add RSS Feed"), |
83 self.tr("""The feed was added successfully.""")) |
82 self.tr("""The feed was added successfully."""), |
|
83 ) |
84 else: |
84 else: |
85 WebBrowserWindow.showNotification( |
85 WebBrowserWindow.showNotification( |
86 UI.PixmapCache.getPixmap("rss48"), |
86 UI.PixmapCache.getPixmap("rss48"), |
87 self.tr("Add RSS Feed"), |
87 self.tr("Add RSS Feed"), |
88 self.tr("""The feed was already added before."""), |
88 self.tr("""The feed was already added before."""), |
89 kind=NotificationTypes.WARNING, |
89 kind=NotificationTypes.WARNING, |
90 timeout=0) |
90 timeout=0, |
91 |
91 ) |
|
92 |
92 self.close() |
93 self.close() |