80 @type QUrl |
80 @type QUrl |
81 """ |
81 """ |
82 from .GreaseMonkeyDownloader import GreaseMonkeyDownloader |
82 from .GreaseMonkeyDownloader import GreaseMonkeyDownloader |
83 downloader = GreaseMonkeyDownloader( |
83 downloader = GreaseMonkeyDownloader( |
84 url, self, GreaseMonkeyDownloader.DownloadMainScript) |
84 url, self, GreaseMonkeyDownloader.DownloadMainScript) |
85 downloader.finished.connect(self.__downloaderFinished) |
85 downloader.finished.connect( |
|
86 lambda f: self.__downloaderFinished(f, downloader)) |
86 self.__downloaders.append(downloader) |
87 self.__downloaders.append(downloader) |
87 |
88 |
88 def __downloaderFinished(self, fileName): |
89 def __downloaderFinished(self, fileName, downloader): |
89 """ |
90 """ |
90 Private slot to handle the completion of a script download. |
91 Private slot to handle the completion of a script download. |
91 |
92 |
92 @param fileName name of the downloaded script |
93 @param fileName name of the downloaded script |
93 @type str |
94 @type str |
94 """ |
95 @param downloader reference to the downloader object |
95 downloader = self.sender() |
96 @type GreaseMonkeyDownloader |
96 if downloader is None or downloader not in self.__downloaders: |
97 """ |
97 return |
98 if downloader in self.__downloaders: |
98 |
99 self.__downloaders.remove(downloader) |
99 self.__downloaders.remove(downloader) |
100 |
100 |
101 deleteScript = True |
101 deleteScript = True |
102 from .GreaseMonkeyScript import GreaseMonkeyScript |
102 from .GreaseMonkeyScript import GreaseMonkeyScript |
103 script = GreaseMonkeyScript(self, fileName) |
103 script = GreaseMonkeyScript(self, fileName) |
104 if script.isValid(): |
104 if script.isValid(): |
105 if not self.containsScript(script.fullName()): |
105 if not self.containsScript(script.fullName()): |
106 from .GreaseMonkeyAddScriptDialog import \ |
106 from .GreaseMonkeyAddScriptDialog import \ |
107 GreaseMonkeyAddScriptDialog |
107 GreaseMonkeyAddScriptDialog |
108 dlg = GreaseMonkeyAddScriptDialog(self, script) |
108 dlg = GreaseMonkeyAddScriptDialog(self, script) |
109 deleteScript = dlg.exec_() != QDialog.Accepted |
109 deleteScript = dlg.exec_() != QDialog.Accepted |
110 else: |
110 else: |
111 E5MessageBox.information( |
111 E5MessageBox.information( |
112 None, |
112 None, |
113 QCoreApplication.translate( |
113 QCoreApplication.translate( |
114 "GreaseMonkeyManager", |
114 "GreaseMonkeyManager", |
115 "Install GreaseMonkey Script"), |
115 "Install GreaseMonkey Script"), |
116 QCoreApplication.translate( |
116 QCoreApplication.translate( |
117 "GreaseMonkeyManager", |
117 "GreaseMonkeyManager", |
118 """'{0}' is already installed.""").format( |
118 """'{0}' is already installed.""").format( |
119 script.fullName()) |
119 script.fullName()) |
120 ) |
120 ) |
121 |
121 |
122 if deleteScript: |
122 if deleteScript: |
123 try: |
123 try: |
124 os.remove(fileName) |
124 os.remove(fileName) |
125 except (IOError, OSError): |
125 except (IOError, OSError): |
126 # ignore |
126 # ignore |
127 pass |
127 pass |
|
128 |
128 |
129 def scriptsDirectory(self): |
129 def scriptsDirectory(self): |
130 """ |
130 """ |
131 Public method to get the path of the scripts directory. |
131 Public method to get the path of the scripts directory. |
132 |
132 |
321 script.setEnabled(False) |
321 script.setEnabled(False) |
322 else: |
322 else: |
323 collection = WebBrowserWindow.webProfile().scripts() |
323 collection = WebBrowserWindow.webProfile().scripts() |
324 collection.insert(script.webScript()) |
324 collection.insert(script.webScript()) |
325 |
325 |
326 def __scriptChanged(self): |
326 def __scriptChanged(self, script): |
327 """ |
327 """ |
328 Private slot handling a changed script. |
328 Private slot handling a changed script. |
329 """ |
329 |
330 script = self.sender() |
330 @param script reference to the changed script |
331 if not script: |
331 @type GreaseMonkeyScript |
332 return |
332 """ |
333 |
|
334 fullName = script.fullName() |
333 fullName = script.fullName() |
335 collection = WebBrowserWindow.webProfile().scripts() |
334 collection = WebBrowserWindow.webProfile().scripts() |
336 collection.remove(collection.findScript(fullName)) |
335 collection.remove(collection.findScript(fullName)) |
337 collection.insert(script.webScript()) |
336 collection.insert(script.webScript()) |