WebBrowser/AdBlock/AdBlockDialog.py

Sun, 13 Mar 2016 20:54:42 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 13 Mar 2016 20:54:42 +0100
branch
QtWebEngine
changeset 4858
19dff9c9cf26
parent 4631
Helpviewer/AdBlock/AdBlockDialog.py@5c1a96925da4
child 4859
36c4b21c9f7b
permissions
-rw-r--r--

Continued porting the web browser.

- continued porting the AdBlock code

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
4631
5c1a96925da4 Updated copyright for 2016.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
3 # Copyright (c) 2009 - 2016 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the AdBlock configuration dialog.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3060
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
11
4278
ccd1e13cb9bd Fixed issues where dialogs could not be minimized on some desktop environments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
12 from PyQt5.QtCore import pyqtSlot, Qt, QTimer, QCoreApplication
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
13 from PyQt5.QtWidgets import QDialog, QMenu, QToolButton
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
15 from E5Gui import E5MessageBox
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
17 from .Ui_AdBlockDialog import Ui_AdBlockDialog
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 import UI.PixmapCache
1854
191efdc54c62 Made the AdBlock update period configurable between 1 and 14 days.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1649
diff changeset
20 import Preferences
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
22
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 class AdBlockDialog(QDialog, Ui_AdBlockDialog):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Class implementing the AdBlock configuration dialog.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
27 def __init__(self, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Constructor
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
30
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
31 @param parent reference to the parent object (QWidget)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
33 super(AdBlockDialog, self).__init__(parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.setupUi(self)
4278
ccd1e13cb9bd Fixed issues where dialogs could not be minimized on some desktop environments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
35 self.setWindowFlags(Qt.Window)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
1649
1b7cd7409170 Enhanced the optics of the AdBlock dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
37 self.iconLabel.setPixmap(UI.PixmapCache.getPixmap("adBlockPlus48.png"))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
1854
191efdc54c62 Made the AdBlock update period configurable between 1 and 14 days.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1649
diff changeset
39 self.updateSpinBox.setValue(Preferences.getHelp("AdBlockUpdatePeriod"))
191efdc54c62 Made the AdBlock update period configurable between 1 and 14 days.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1649
diff changeset
40
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
41 self.searchEdit.setInactiveText(self.tr("Search..."))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
43 from WebBrowser.WebBrowserWindow import WebBrowserWindow
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
44 self.__manager = WebBrowserWindow.adBlockManager()
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
45 self.adBlockGroup.setChecked(self.__manager.isEnabled())
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
46 self.__manager.requiredSubscriptionLoaded.connect(self.addSubscription)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
48 self.__currentTreeWidget = None
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
49 self.__currentSubscription = None
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
50 self.__loaded = False
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 menu = QMenu(self)
461
34528aaedf1c Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 134
diff changeset
53 menu.aboutToShow.connect(self.__aboutToShowActionMenu)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.actionButton.setMenu(menu)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.actionButton.setIcon(UI.PixmapCache.getIcon("adBlockAction.png"))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.actionButton.setPopupMode(QToolButton.InstantPopup)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
58 self.__load()
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
59
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
60 self.buttonBox.setFocus()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
62 def __loadSubscriptions(self):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
63 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
64 Private slot to load the AdBlock subscription rules.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
66 for index in range(self.subscriptionsTabWidget.count()):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
67 tree = self.subscriptionsTabWidget.widget(index)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
68 tree.refresh()
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
69
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
70 def __load(self):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
71 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
72 Private slot to populate the tab widget with subscriptions.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
74 if self.__loaded or not self.adBlockGroup.isChecked():
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
75 return
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
76
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
77 from .AdBlockTreeWidget import AdBlockTreeWidget
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
78 for subscription in self.__manager.subscriptions():
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
79 tree = AdBlockTreeWidget(subscription, self.subscriptionsTabWidget)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
80 if subscription.isEnabled():
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
81 icon = UI.PixmapCache.getIcon("adBlockPlus.png")
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
82 else:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
83 icon = UI.PixmapCache.getIcon("adBlockPlusDisabled.png")
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
84 self.subscriptionsTabWidget.addTab(
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
85 tree, icon, subscription.title())
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
86
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
87 self.__loaded = True
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
88 QCoreApplication.processEvents()
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
89
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
90 QTimer.singleShot(50, self.__loadSubscriptions)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
92 def addSubscription(self, subscription, refresh=True):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 """
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
94 Public slot adding a subscription to the list.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
96 @param subscription reference to the subscription to be
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
97 added (AdBlockSubscription)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
98 @param refresh flag indicating to refresh the tree (boolean)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 """
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
100 from .AdBlockTreeWidget import AdBlockTreeWidget
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
101 tree = AdBlockTreeWidget(subscription, self.subscriptionsTabWidget)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
102 index = self.subscriptionsTabWidget.insertTab(
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
103 self.subscriptionsTabWidget.count() - 1, tree,
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
104 subscription.title())
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
105 self.subscriptionsTabWidget.setCurrentIndex(index)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
106 QCoreApplication.processEvents()
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
107 if refresh:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
108 tree.refresh()
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
109 self.__setSubscriptionEnabled(subscription, True)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 def __aboutToShowActionMenu(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 Private slot to show the actions menu.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 """
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
115 subscriptionEditable = self.__currentSubscription and \
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
116 self.__currentSubscription.canEditRules()
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
117 subscriptionRemovable = self.__currentSubscription and \
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
118 self.__currentSubscription.canBeRemoved()
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
119 subscriptionEnabled = self.__currentSubscription and \
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
120 self.__currentSubscription.isEnabled()
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
121
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 menu = self.actionButton.menu()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 menu.clear()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
125 menu.addAction(self.tr("Add Rule"), self.__addCustomRule)\
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
126 .setEnabled(subscriptionEditable)
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
127 menu.addAction(self.tr("Remove Rule"), self.__removeCustomRule)\
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
128 .setEnabled(subscriptionEditable)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
129 menu.addSeparator()
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
130 menu.addAction(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
131 self.tr("Browse Subscriptions..."), self.__browseSubscriptions)
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
132 menu.addAction(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
133 self.tr("Remove Subscription"), self.__removeSubscription)\
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
134 .setEnabled(subscriptionRemovable)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
135 if self.__currentSubscription:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
136 menu.addSeparator()
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
137 if subscriptionEnabled:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
138 txt = self.tr("Disable Subscription")
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
139 else:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
140 txt = self.tr("Enable Subscription")
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
141 menu.addAction(txt, self.__switchSubscriptionEnabled)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
142 menu.addSeparator()
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
143 menu.addAction(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
144 self.tr("Update Subscription"), self.__updateSubscription)\
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
145 .setEnabled(not subscriptionEditable)
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
146 menu.addAction(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
147 self.tr("Update All Subscriptions"),
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
148 self.__updateAllSubscriptions)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
149 menu.addSeparator()
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
150 menu.addAction(self.tr("Learn more about writing rules..."),
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 self.__learnAboutWritingFilters)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152
1973
c643c1d33c7b Fixed an issue in the new AdBlock code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1972
diff changeset
153 def addCustomRule(self, filter):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 """
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1970
diff changeset
155 Public slot to add a custom AdBlock rule.
1973
c643c1d33c7b Fixed an issue in the new AdBlock code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1972
diff changeset
156
c643c1d33c7b Fixed an issue in the new AdBlock code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1972
diff changeset
157 @param filter filter to be added (string)
c643c1d33c7b Fixed an issue in the new AdBlock code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1972
diff changeset
158 """
c643c1d33c7b Fixed an issue in the new AdBlock code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1972
diff changeset
159 self.subscriptionsTabWidget.setCurrentIndex(
c643c1d33c7b Fixed an issue in the new AdBlock code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1972
diff changeset
160 self.subscriptionsTabWidget.count() - 1)
c643c1d33c7b Fixed an issue in the new AdBlock code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1972
diff changeset
161 self.__currentTreeWidget.addRule(filter)
c643c1d33c7b Fixed an issue in the new AdBlock code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1972
diff changeset
162
c643c1d33c7b Fixed an issue in the new AdBlock code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1972
diff changeset
163 def __addCustomRule(self):
c643c1d33c7b Fixed an issue in the new AdBlock code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1972
diff changeset
164 """
c643c1d33c7b Fixed an issue in the new AdBlock code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1972
diff changeset
165 Private slot to add a custom AdBlock rule.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 """
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
167 self.__currentTreeWidget.addRule()
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
168
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
169 def __removeCustomRule(self):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
170 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
171 Private slot to remove a custom AdBlock rule.
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
172 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
173 self.__currentTreeWidget.removeRule()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 def __updateSubscription(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 Private slot to update the selected subscription.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 """
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
179 self.__currentSubscription.updateNow()
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
180
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
181 def __updateAllSubscriptions(self):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
182 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
183 Private slot to update all subscriptions.
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
184 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
185 self.__manager.updateAllSubscriptions()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 def __browseSubscriptions(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 Private slot to browse the list of available AdBlock subscriptions.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 """
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
191 from WebBrowser.WebBrowserWindow import WebBrowserWindow
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
192 mw = WebBrowserWindow.mainWindow()
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
193 mw.newTab("http://adblockplus.org/en/subscriptions")
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
194 mw.raise_()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 def __learnAboutWritingFilters(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 Private slot to show the web page about how to write filters.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 """
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
200 from WebBrowser.WebBrowserWindow import WebBrowserWindow
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
201 mw = WebBrowserWindow.mainWindow()
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
202 mw.newTab("http://adblockplus.org/en/filters")
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
203 mw.raise_()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 def __removeSubscription(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 Private slot to remove the selected subscription.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 """
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
209 requiresTitles = []
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
210 requiresSubscriptions = \
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
211 self.__manager.getRequiresSubscriptions(self.__currentSubscription)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
212 for subscription in requiresSubscriptions:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
213 requiresTitles.append(subscription.title())
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
214 if requiresTitles:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
215 message = self.tr(
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
216 "<p>Do you really want to remove subscription"
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
217 " <b>{0}</b> and all subscriptions requiring it?</p>"
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
218 "<ul><li>{1}</li></ul>").format(
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
219 self.__currentSubscription.title(),
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
220 "</li><li>".join(requiresTitles))
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
221 else:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
222 message = self.tr(
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
223 "<p>Do you really want to remove subscription"
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
224 " <b>{0}</b>?</p>").format(self.__currentSubscription.title())
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3000
diff changeset
225 res = E5MessageBox.yesNo(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3000
diff changeset
226 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
227 self.tr("Remove Subscription"),
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
228 message)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
229
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
230 if res:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
231 removeSubscription = self.__currentSubscription
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
232 removeTrees = [self.__currentTreeWidget]
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
233 for index in range(self.subscriptionsTabWidget.count()):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
234 tree = self.subscriptionsTabWidget.widget(index)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
235 if tree.subscription() in requiresSubscriptions:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
236 removeTrees.append(tree)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
237 for tree in removeTrees:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
238 self.subscriptionsTabWidget.removeTab(
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
239 self.subscriptionsTabWidget.indexOf(tree))
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
240 self.__manager.removeSubscription(removeSubscription)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
241
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
242 def __switchSubscriptionEnabled(self):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
243 """
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
244 Private slot to switch the enabled state of the selected subscription.
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
245 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
246 newState = not self.__currentSubscription.isEnabled()
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
247 self.__setSubscriptionEnabled(self.__currentSubscription, newState)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
248
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
249 def __setSubscriptionEnabled(self, subscription, enable):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
250 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
251 Private slot to set the enabled state of a subscription.
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
252
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
253 @param subscription subscription to set the state for
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
254 (AdBlockSubscription)
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
255 @param enable state to set to (boolean)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
256 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
257 if enable:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
258 # enable required one as well
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
259 sub = self.__manager.subscription(subscription.requiresLocation())
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
260 requiresSubscriptions = [] if sub is None else [sub]
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
261 icon = UI.PixmapCache.getIcon("adBlockPlus.png")
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
262 else:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
263 # disable dependent ones as well
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
264 requiresSubscriptions = \
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
265 self.__manager.getRequiresSubscriptions(subscription)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
266 icon = UI.PixmapCache.getIcon("adBlockPlusDisabled.png")
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
267 requiresSubscriptions.append(subscription)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
268 for sub in requiresSubscriptions:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
269 sub.setEnabled(enable)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
270
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
271 for index in range(self.subscriptionsTabWidget.count()):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
272 tree = self.subscriptionsTabWidget.widget(index)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
273 if tree.subscription() in requiresSubscriptions:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
274 self.subscriptionsTabWidget.setTabIcon(
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
275 self.subscriptionsTabWidget.indexOf(tree), icon)
1854
191efdc54c62 Made the AdBlock update period configurable between 1 and 14 days.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1649
diff changeset
276
191efdc54c62 Made the AdBlock update period configurable between 1 and 14 days.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1649
diff changeset
277 @pyqtSlot(int)
191efdc54c62 Made the AdBlock update period configurable between 1 and 14 days.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1649
diff changeset
278 def on_updateSpinBox_valueChanged(self, value):
191efdc54c62 Made the AdBlock update period configurable between 1 and 14 days.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1649
diff changeset
279 """
191efdc54c62 Made the AdBlock update period configurable between 1 and 14 days.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1649
diff changeset
280 Private slot to handle changes of the update period.
191efdc54c62 Made the AdBlock update period configurable between 1 and 14 days.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1649
diff changeset
281
191efdc54c62 Made the AdBlock update period configurable between 1 and 14 days.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1649
diff changeset
282 @param value update period (integer)
191efdc54c62 Made the AdBlock update period configurable between 1 and 14 days.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1649
diff changeset
283 """
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
284 if value != Preferences.getWebBrowser("AdBlockUpdatePeriod"):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
285 Preferences.setWebBrowser("AdBlockUpdatePeriod", value)
1854
191efdc54c62 Made the AdBlock update period configurable between 1 and 14 days.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1649
diff changeset
286
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
287 from WebBrowser.WebBrowserWindow import WebBrowserWindow
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
288 manager = WebBrowserWindow.adBlockManager()
1854
191efdc54c62 Made the AdBlock update period configurable between 1 and 14 days.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1649
diff changeset
289 for subscription in manager.subscriptions():
191efdc54c62 Made the AdBlock update period configurable between 1 and 14 days.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1649
diff changeset
290 subscription.checkForUpdate()
1963
9c5b3235abf9 Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1854
diff changeset
291
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
292 @pyqtSlot(int)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
293 def on_subscriptionsTabWidget_currentChanged(self, index):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
294 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
295 Private slot handling the selection of another tab.
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
296
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
297 @param index index of the new current tab (integer)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
298 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
299 if index != -1:
3000
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
300 self.__currentTreeWidget = \
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
301 self.subscriptionsTabWidget.widget(index)
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
302 self.__currentSubscription = \
971d84f7a6d6 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
303 self.__currentTreeWidget.subscription()
1970
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
304
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
305 @pyqtSlot(str)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
306 def on_searchEdit_textChanged(self, filter):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
307 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
308 Private slot to set a new filter on the current widget.
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
309
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
310 @param filter filter to be set (string)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
311 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
312 if self.__currentTreeWidget and self.adBlockGroup.isChecked():
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
313 self.__currentTreeWidget.filterString(filter)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
314
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
315 @pyqtSlot(bool)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
316 def on_adBlockGroup_toggled(self, state):
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
317 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
318 Private slot handling the enabling/disabling of AdBlock.
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
319
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
320 @param state state of the toggle (boolean)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
321 """
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
322 self.__manager.setEnabled(state)
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
323
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
324 if state:
02cf3bac079b Rewrote huge part of AdBlock to speed up and added support for dependent AdBlock subscriptions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1963
diff changeset
325 self.__load()

eric ide

mercurial