31 @param parent reference to the parent widget (QWidget) |
41 @param parent reference to the parent widget (QWidget) |
32 """ |
42 """ |
33 super(HgUserConfigDialog, self).__init__(parent) |
43 super(HgUserConfigDialog, self).__init__(parent) |
34 self.setupUi(self) |
44 self.setupUi(self) |
35 |
45 |
36 msh = self.minimumSizeHint() |
46 self.lfUserCachePicker.setMode(E5PathPickerModes.DirectoryMode) |
37 self.resize(max(self.width(), msh.width()), msh.height()) |
47 if Globals.isLinuxPlatform(): |
|
48 self.lfUserCachePicker.setDefaultDirectory(os.path.expanduser( |
|
49 "~/.cache/largefiles")) |
|
50 elif Globals.isMacPlatform(): |
|
51 self.lfUserCachePicker.setDefaultDirectory(os.path.expanduser( |
|
52 "~/Library/Caches/largefiles")) |
|
53 else: |
|
54 self.lfUserCachePicker.setDefaultDirectory(os.path.expanduser( |
|
55 "~\\AppData\\Local\\largefiles")) |
|
56 |
|
57 self.fpAddButton.setIcon(UI.PixmapCache.getIcon("plus.png")) |
|
58 self.fpDeleteButton.setIcon(UI.PixmapCache.getIcon("minus.png")) |
|
59 self.fpEditButton.setIcon(UI.PixmapCache.getIcon("edit.png")) |
|
60 |
|
61 self.tabWidget.setCurrentIndex(0) |
|
62 |
|
63 self.__editor = None |
38 |
64 |
39 self.__config = None |
65 self.__config = None |
40 self.readUserConfig() |
66 self.readUserConfig() |
|
67 |
|
68 self.__updateFingerprintsButtons() |
41 |
69 |
42 def writeUserConfig(self): |
70 def writeUserConfig(self): |
43 """ |
71 """ |
44 Public method to write the user configuration file. |
72 Public method to write the user configuration file. |
45 """ |
73 """ |
46 if self.__config is None: |
74 if self.__config is None: |
47 self.__config = E5ConfigParser() |
75 self.__config = E5ConfigParser() |
48 |
76 |
49 self.__config["ui"] = { |
77 ################################################################### |
50 "username": "{0} <{1}>".format( |
78 ## ui section |
51 self.userNameEdit.text(), |
79 ################################################################### |
52 self.emailEdit.text(), |
80 if "ui" not in self.__config: |
53 ) |
81 self.__config["ui"] = {} |
54 } |
82 self.__config["ui"]["username"] = "{0} <{1}>".format( |
55 self.__config["extensions"] = {} |
83 self.userNameEdit.text(), |
|
84 self.emailEdit.text(), |
|
85 ) |
|
86 ################################################################### |
|
87 ## extensions section |
|
88 ################################################################### |
|
89 if "extensions" not in self.__config: |
|
90 self.__config["extensions"] = {} |
56 if self.fetchCheckBox.isChecked(): |
91 if self.fetchCheckBox.isChecked(): |
57 self.__config["extensions"]["fetch"] = "" |
92 self.__config["extensions"]["fetch"] = "" |
|
93 else: |
|
94 if "fetch" in self.__config["extensions"]: |
|
95 del self.__config["extensions"]["fetch"] |
|
96 self.__config["extensions"]["#fetch"] = "" |
|
97 |
58 if self.gpgCheckBox.isChecked(): |
98 if self.gpgCheckBox.isChecked(): |
59 self.__config["extensions"]["gpg"] = "" |
99 self.__config["extensions"]["gpg"] = "" |
|
100 else: |
|
101 if "gpg" in self.__config["extensions"]: |
|
102 del self.__config["extensions"]["gpg"] |
|
103 self.__config["extensions"]["#gpg"] = "" |
|
104 |
60 if self.purgeCheckBox.isChecked(): |
105 if self.purgeCheckBox.isChecked(): |
61 self.__config["extensions"]["purge"] = "" |
106 self.__config["extensions"]["purge"] = "" |
|
107 else: |
|
108 if "purge" in self.__config["extensions"]: |
|
109 del self.__config["extensions"]["purge"] |
|
110 self.__config["extensions"]["#purge"] = "" |
|
111 |
62 if self.queuesCheckBox.isChecked(): |
112 if self.queuesCheckBox.isChecked(): |
63 self.__config["extensions"]["mq"] = "" |
113 self.__config["extensions"]["mq"] = "" |
|
114 else: |
|
115 if "mq" in self.__config["extensions"]: |
|
116 del self.__config["extensions"]["mq"] |
|
117 self.__config["extensions"]["#mq"] = "" |
|
118 |
64 if self.rebaseCheckBox.isChecked(): |
119 if self.rebaseCheckBox.isChecked(): |
65 self.__config["extensions"]["rebase"] = "" |
120 self.__config["extensions"]["rebase"] = "" |
|
121 else: |
|
122 if "rebase" in self.__config["extensions"]: |
|
123 del self.__config["extensions"]["rebase"] |
|
124 self.__config["extensions"]["#rebase"] = "" |
|
125 |
66 if self.shelveCheckBox.isChecked(): |
126 if self.shelveCheckBox.isChecked(): |
67 self.__config["extensions"]["shelve"] = "" |
127 self.__config["extensions"]["shelve"] = "" |
|
128 else: |
|
129 if "shelve" in self.__config["extensions"]: |
|
130 del self.__config["extensions"]["shelve"] |
|
131 self.__config["extensions"]["#shelve"] = "" |
|
132 |
68 if self.largefilesCheckBox.isChecked(): |
133 if self.largefilesCheckBox.isChecked(): |
69 self.__config["extensions"]["largefiles"] = "" |
134 self.__config["extensions"]["largefiles"] = "" |
70 self.__config["largefiles"] = { |
135 ############################################################### |
71 "minsize": self.lfFileSizeSpinBox.value(), |
136 ## largefiles section |
72 } |
137 ############################################################### |
|
138 if "largefiles" not in self.__config: |
|
139 self.__config["largefiles"] = {} |
|
140 self.__config["largefiles"]["minsize"] = \ |
|
141 str(self.lfFileSizeSpinBox.value()) |
73 lfFilePatterns = self.lfFilePatternsEdit.text() |
142 lfFilePatterns = self.lfFilePatternsEdit.text() |
74 if lfFilePatterns: |
143 if lfFilePatterns: |
75 self.__config["largefiles"]["patterns"] = lfFilePatterns |
144 self.__config["largefiles"]["patterns"] = lfFilePatterns |
|
145 elif "patterns" in self.__config["largefiles"]: |
|
146 del self.__config["largefiles"]["patterns"] |
|
147 lfUserCache = self.lfUserCachePicker.text() |
|
148 if lfUserCache: |
|
149 self.__config["largefiles"]["usercache"] = lfUserCache |
|
150 elif "usercache" in self.__config["largefiles"]: |
|
151 del self.__config["largefiles"]["usercache"] |
|
152 else: |
|
153 if "largefiles" in self.__config["extensions"]: |
|
154 del self.__config["extensions"]["largefiles"] |
|
155 self.__config["extensions"]["#largefiles"] = "" |
|
156 ################################################################### |
|
157 ## http_proxy section |
|
158 ################################################################### |
|
159 if self.proxyHostEdit.text(): |
|
160 self.__config["http_proxy"] = { |
|
161 "host": self.proxyHostEdit.text(), |
|
162 "user": self.proxyUserEdit.text(), |
|
163 "passwd": self.proxyPasswordEdit.text() |
|
164 } |
|
165 if self.proxyBypassEdit.text(): |
|
166 self.__config["http_proxy"]["no"] = \ |
|
167 self.proxyBypassEdit.text() |
|
168 else: |
|
169 if "http_proxy" in self.__config: |
|
170 del self.__config["http_proxy"] |
|
171 ################################################################### |
|
172 ## hostfingerprints section |
|
173 ################################################################### |
|
174 if self.fingerprintsList.topLevelItemCount() > 0: |
|
175 self.__config["hostfingerprints"] = {} |
|
176 for row in range(self.fingerprintsList.topLevelItemCount()): |
|
177 itm = self.fingerprintsList.topLevelItem(row) |
|
178 self.__config["hostfingerprints"][itm.text(0)] = itm.text(1) |
|
179 else: |
|
180 if "hostfingerprints" in self.__config: |
|
181 del self.__config["hostfingerprints"] |
|
182 ################################################################### |
76 |
183 |
77 cfgFile = getConfigPath() |
184 cfgFile = getConfigPath() |
78 with open(cfgFile, "w") as configFile: |
185 with open(cfgFile, "w") as configFile: |
79 self.__config.write(configFile) |
186 self.__config.write(configFile) |
80 |
187 |
122 self.lfFileSizeSpinBox.setValue( |
229 self.lfFileSizeSpinBox.setValue( |
123 self.__config.getint("largefiles", "minsize")) |
230 self.__config.getint("largefiles", "minsize")) |
124 if "patterns" in self.__config["largefiles"]: |
231 if "patterns" in self.__config["largefiles"]: |
125 self.lfFilePatternsEdit.setText( |
232 self.lfFilePatternsEdit.setText( |
126 self.__config["largefiles"]["patterns"]) |
233 self.__config["largefiles"]["patterns"]) |
|
234 if "usercache" in self.__config["largefiles"]: |
|
235 self.lfUserCachePicker.setText( |
|
236 self.__config["largefiles"]["usercache"]) |
|
237 |
|
238 # step 4: extract http proxy information |
|
239 if "http_proxy" in self.__config: |
|
240 if "host" in self.__config["http_proxy"]: |
|
241 self.proxyHostEdit.setText( |
|
242 self.__config["http_proxy"]["host"]) |
|
243 if "user" in self.__config["http_proxy"]: |
|
244 self.proxyUserEdit.setText( |
|
245 self.__config["http_proxy"]["user"]) |
|
246 if "passwd" in self.__config["http_proxy"]: |
|
247 self.proxyPasswordEdit.setText( |
|
248 self.__config["http_proxy"]["passwd"]) |
|
249 if "no" in self.__config["http_proxy"]: |
|
250 self.proxyBypassEdit.setText( |
|
251 self.__config["http_proxy"]["no"]) |
|
252 |
|
253 # step 5: extract host fingerprints |
|
254 if "hostfingerprints" in self.__config: |
|
255 for host in self.__config["hostfingerprints"]: |
|
256 QTreeWidgetItem(self.fingerprintsList, [ |
|
257 host, |
|
258 self.__config["hostfingerprints"][host] |
|
259 ]) |
|
260 self.__finalizeFingerprintsColumns() |
127 |
261 |
128 @pyqtSlot() |
262 @pyqtSlot() |
129 def accept(self): |
263 def accept(self): |
130 """ |
264 """ |
131 Public slot to accept the dialog. |
265 Public slot to accept the dialog. |
132 """ |
266 """ |
133 self.writeUserConfig() |
267 self.writeUserConfig() |
134 |
268 |
135 super(HgUserConfigDialog, self).accept() |
269 super(HgUserConfigDialog, self).accept() |
|
270 |
|
271 def __clearDialog(self): |
|
272 """ |
|
273 Private method to clear the data of the dialog. |
|
274 """ |
|
275 self.userNameEdit.clear() |
|
276 self.emailEdit.clear() |
|
277 |
|
278 self.fetchCheckBox.setChecked(False) |
|
279 self.gpgCheckBox.setChecked(False) |
|
280 self.purgeCheckBox.setChecked(False) |
|
281 self.queuesCheckBox.setChecked(False) |
|
282 self.rebaseCheckBox.setChecked(False) |
|
283 self.shelveCheckBox.setChecked(False) |
|
284 self.largefilesCheckBox.setChecked(False) |
|
285 self.lfFileSizeSpinBox.setValue(10) |
|
286 self.lfFilePatternsEdit.clear() |
|
287 self.lfUserCachePicker.clear() |
|
288 |
|
289 self.proxyHostEdit.clear() |
|
290 self.proxyUserEdit.clear() |
|
291 self.proxyPasswordEdit.clear() |
|
292 self.proxyBypassEdit.clear() |
|
293 |
|
294 self.fingerprintsList.clear() |
|
295 self.__updateFingerprintsButtons() |
|
296 |
|
297 ####################################################################### |
|
298 ## Methods and slots for the host fingerprint handling below |
|
299 ####################################################################### |
|
300 |
|
301 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
|
302 def on_fingerprintsList_currentItemChanged(self, current, previous): |
|
303 """ |
|
304 Private slot handling a change of the current fingerprints item. |
|
305 |
|
306 @param current reference to the current item |
|
307 @type QTreeWidgetItem |
|
308 @param previous reference to the previous current item |
|
309 @type QTreeWidgetItem |
|
310 """ |
|
311 self.__updateFingerprintsButtons() |
|
312 |
|
313 @pyqtSlot() |
|
314 def on_fpAddButton_clicked(self): |
|
315 """ |
|
316 Private slot to add a fingerprints entry. |
|
317 """ |
|
318 dlg = HgUserConfigHostFingerprintDialog(self) |
|
319 if dlg.exec_() == QDialog.Accepted: |
|
320 host, fingerprint = dlg.getData() |
|
321 itm = QTreeWidgetItem(self.fingerprintsList, [host, fingerprint]) |
|
322 self.__finalizeFingerprintsColumns() |
|
323 self.fingerprintsList.setCurrentItem(itm) |
|
324 self.fingerprintsList.scrollToItem(itm) |
|
325 |
|
326 @pyqtSlot() |
|
327 def on_fpDeleteButton_clicked(self): |
|
328 """ |
|
329 Private slot to delete the current fingerprints item. |
|
330 """ |
|
331 itm = self.fingerprintsList.currentItem() |
|
332 if itm is not None: |
|
333 host = itm.text(0) |
|
334 yes = E5MessageBox.yesNo( |
|
335 self, |
|
336 self.tr("Delete Host Fingerprint"), |
|
337 self.tr("""<p>Shall the fingerprint for host <b>{0}</b>""" |
|
338 """ really be deleted?</p>""").format(host)) |
|
339 if yes: |
|
340 self.fingerprintsList.takeTopLevelItem( |
|
341 self.fingerprintsList.indexOfTopLevelItem(itm)) |
|
342 del itm |
|
343 |
|
344 @pyqtSlot() |
|
345 def on_fpEditButton_clicked(self): |
|
346 """ |
|
347 Private slot to edit the current fingerprints item. |
|
348 """ |
|
349 itm = self.fingerprintsList.currentItem() |
|
350 if itm is not None: |
|
351 host = itm.text(0) |
|
352 fingerprint = itm.text(1) |
|
353 dlg = HgUserConfigHostFingerprintDialog(self, host, fingerprint) |
|
354 if dlg.exec_() == QDialog.Accepted: |
|
355 host, fingerprint = dlg.getData() |
|
356 itm.setText(0, host) |
|
357 itm.setText(1, fingerprint) |
|
358 self.__finalizeFingerprintsColumns() |
|
359 self.fingerprintsList.scrollToItem(itm) |
|
360 |
|
361 def __finalizeFingerprintsColumns(self): |
|
362 """ |
|
363 Private method to resize and sort the host fingerprints columns. |
|
364 """ |
|
365 for col in range(self.fingerprintsList.columnCount()): |
|
366 self.fingerprintsList.resizeColumnToContents(col) |
|
367 self.fingerprintsList.sortItems(0, Qt.AscendingOrder) |
|
368 |
|
369 def __updateFingerprintsButtons(self): |
|
370 """ |
|
371 Private slot to update the host fingerprints edit buttons. |
|
372 """ |
|
373 enable = self.fingerprintsList.currentItem() is not None |
|
374 self.fpDeleteButton.setEnabled(enable) |
|
375 self.fpEditButton.setEnabled(enable) |
|
376 |
|
377 ####################################################################### |
|
378 ## Slot to edit the user configuration in an editor below |
|
379 ####################################################################### |
|
380 |
|
381 @pyqtSlot() |
|
382 def on_editorButton_clicked(self): |
|
383 """ |
|
384 Private slot to open the user configuration file in a text editor. |
|
385 """ |
|
386 from QScintilla.MiniEditor import MiniEditor |
|
387 cfgFile = getConfigPath() |
|
388 |
|
389 yes = E5MessageBox.yesNo( |
|
390 self, |
|
391 self.tr("Edit User Configuration"), |
|
392 self.tr("""You will loose all changes made in this dialog.""" |
|
393 """ Shall the data be saved first?"""), |
|
394 icon=E5MessageBox.Warning, |
|
395 yesDefault=True) |
|
396 if yes: |
|
397 self.writeUserConfig() |
|
398 |
|
399 self.__editor = MiniEditor(cfgFile, "Properties", self) |
|
400 self.__editor.setWindowModality(Qt.WindowModal) |
|
401 self.__editor.installEventFilter(self) |
|
402 self.__editor.show() |
|
403 |
|
404 def eventFilter(self, watched, event): |
|
405 """ |
|
406 Public method called to filter the event queue. |
|
407 |
|
408 @param watched reference to the object being watched |
|
409 @type QObject |
|
410 @param event event to be handled |
|
411 @type QEvent |
|
412 @return flag indicating, if we handled the event |
|
413 @rtype bool |
|
414 """ |
|
415 if watched is self.__editor and event.type() == QEvent.Close: |
|
416 self.__editor.closeEvent(event) |
|
417 if event.isAccepted(): |
|
418 self.__clearDialog() |
|
419 self.readUserConfig() |
|
420 return True |
|
421 |
|
422 return False |