9 |
9 |
10 from __future__ import unicode_literals # __IGNORE_WARNING__ |
10 from __future__ import unicode_literals # __IGNORE_WARNING__ |
11 |
11 |
12 import os |
12 import os |
13 |
13 |
14 from PyQt4.QtCore import pyqtSignal, QObject, QTimer, QFile, QDir, QSettings, QUrl, \ |
14 from PyQt4.QtCore import pyqtSignal, QObject, QTimer, QFile, QDir, QSettings, \ |
15 QByteArray |
15 QUrl, QByteArray |
16 from PyQt4.QtNetwork import QNetworkAccessManager |
16 from PyQt4.QtNetwork import QNetworkAccessManager |
17 |
17 |
18 import Utilities |
18 import Utilities |
19 import Preferences |
19 import Preferences |
20 |
20 |
44 """ |
44 """ |
45 Public method to show the configuration dialog. |
45 Public method to show the configuration dialog. |
46 |
46 |
47 @param parent reference to the parent widget (QWidget) |
47 @param parent reference to the parent widget (QWidget) |
48 """ |
48 """ |
49 from .GreaseMonkeyConfiguration.GreaseMonkeyConfigurationDialog import \ |
49 from .GreaseMonkeyConfiguration.GreaseMonkeyConfigurationDialog \ |
50 GreaseMonkeyConfigurationDialog |
50 import GreaseMonkeyConfigurationDialog |
51 self.__configDiaolg = GreaseMonkeyConfigurationDialog(self, parent) |
51 self.__configDiaolg = GreaseMonkeyConfigurationDialog(self, parent) |
52 self.__configDiaolg.show() |
52 self.__configDiaolg.show() |
53 |
53 |
54 def downloadScript(self, request): |
54 def downloadScript(self, request): |
55 """ |
55 """ |
76 """ |
76 """ |
77 Public method to get the path of the scripts directory. |
77 Public method to get the path of the scripts directory. |
78 |
78 |
79 @return path of the scripts directory (string) |
79 @return path of the scripts directory (string) |
80 """ |
80 """ |
81 return os.path.join(Utilities.getConfigDir(), "browser", "greasemonkey") |
81 return os.path.join( |
|
82 Utilities.getConfigDir(), "browser", "greasemonkey") |
82 |
83 |
83 def requireScriptsDirectory(self): |
84 def requireScriptsDirectory(self): |
84 """ |
85 """ |
85 Public method to get the path of the scripts directory. |
86 Public method to get the path of the scripts directory. |
86 |
87 |
99 if not requiresDir.exists() or len(urlList) == 0: |
100 if not requiresDir.exists() or len(urlList) == 0: |
100 return "" |
101 return "" |
101 |
102 |
102 script = "" |
103 script = "" |
103 |
104 |
104 settings = QSettings(os.path.join(self.requireScriptsDirectory(), "requires.ini"), |
105 settings = QSettings( |
105 QSettings.IniFormat) |
106 os.path.join(self.requireScriptsDirectory(), "requires.ini"), |
|
107 QSettings.IniFormat) |
106 settings.beginGroup("Files") |
108 settings.beginGroup("Files") |
107 for url in urlList: |
109 for url in urlList: |
108 if settings.contains(url): |
110 if settings.contains(url): |
109 fileName = settings.value(url) |
111 fileName = settings.value(url) |
110 try: |
112 try: |
119 |
121 |
120 def saveConfiguration(self): |
122 def saveConfiguration(self): |
121 """ |
123 """ |
122 Public method to save the configuration. |
124 Public method to save the configuration. |
123 """ |
125 """ |
124 Preferences.setHelp("GreaseMonkeyDisabledScripts", self.__disabledScripts) |
126 Preferences.setHelp("GreaseMonkeyDisabledScripts", |
|
127 self.__disabledScripts) |
125 |
128 |
126 def allScripts(self): |
129 def allScripts(self): |
127 """ |
130 """ |
128 Public method to get a list of all scripts. |
131 Public method to get a list of all scripts. |
129 |
132 |
261 scriptsDir.mkpath(self.scriptsDirectory()) |
264 scriptsDir.mkpath(self.scriptsDirectory()) |
262 |
265 |
263 if not scriptsDir.exists("requires"): |
266 if not scriptsDir.exists("requires"): |
264 scriptsDir.mkdir("requires") |
267 scriptsDir.mkdir("requires") |
265 |
268 |
266 self.__disabledScripts = Preferences.getHelp("GreaseMonkeyDisabledScripts") |
269 self.__disabledScripts = \ |
|
270 Preferences.getHelp("GreaseMonkeyDisabledScripts") |
267 |
271 |
268 from .GreaseMonkeyScript import GreaseMonkeyScript |
272 from .GreaseMonkeyScript import GreaseMonkeyScript |
269 for fileName in scriptsDir.entryList(["*.js"], QDir.Files): |
273 for fileName in scriptsDir.entryList(["*.js"], QDir.Files): |
270 absolutePath = scriptsDir.absoluteFilePath(fileName) |
274 absolutePath = scriptsDir.absoluteFilePath(fileName) |
271 script = GreaseMonkeyScript(self, absolutePath) |
275 script = GreaseMonkeyScript(self, absolutePath) |
282 """ |
286 """ |
283 Public method to allow the GreaseMonkey manager to connect to the page. |
287 Public method to allow the GreaseMonkey manager to connect to the page. |
284 |
288 |
285 @param page reference to the web page (HelpWebPage) |
289 @param page reference to the web page (HelpWebPage) |
286 """ |
290 """ |
287 page.mainFrame().javaScriptWindowObjectCleared.connect(self.pageLoadStarted) |
291 page.mainFrame().javaScriptWindowObjectCleared.connect( |
|
292 self.pageLoadStarted) |
288 |
293 |
289 def createRequest(self, op, request, outgoingData=None): |
294 def createRequest(self, op, request, outgoingData=None): |
290 """ |
295 """ |
291 Public method to create a request. |
296 Public method to create a request. |
292 |
297 |
293 @param op the operation to be performed (QNetworkAccessManager.Operation) |
298 @param op the operation to be performed |
|
299 (QNetworkAccessManager.Operation) |
294 @param request reference to the request object (QNetworkRequest) |
300 @param request reference to the request object (QNetworkRequest) |
295 @param outgoingData reference to an IODevice containing data to be sent |
301 @param outgoingData reference to an IODevice containing data to be sent |
296 (QIODevice) |
302 (QIODevice) |
297 @return reference to the created reply object (QNetworkReply) |
303 @return reference to the created reply object (QNetworkReply) |
298 """ |
304 """ |
299 if op == QNetworkAccessManager.GetOperation and \ |
305 if op == QNetworkAccessManager.GetOperation and \ |
300 request.rawHeader("X-Eric5-UserLoadAction") == QByteArray("1"): |
306 request.rawHeader("X-Eric5-UserLoadAction") == QByteArray("1"): |
301 urlString = request.url().toString(QUrl.RemoveFragment | QUrl.RemoveQuery) |
307 urlString = request.url().toString( |
|
308 QUrl.RemoveFragment | QUrl.RemoveQuery) |
302 if urlString.endswith(".user.js"): |
309 if urlString.endswith(".user.js"): |
303 self.downloadScript(request) |
310 self.downloadScript(request) |
304 from Helpviewer.Network.EmptyNetworkReply import EmptyNetworkReply |
311 from Helpviewer.Network.EmptyNetworkReply import \ |
|
312 EmptyNetworkReply |
305 return EmptyNetworkReply(self) |
313 return EmptyNetworkReply(self) |
306 |
314 |
307 return None |
315 return None |