|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Mercurial Options Dialog for a new project from the repository. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 from PyQt4.QtCore import pyqtSlot, QDir |
|
13 from PyQt4.QtGui import QDialog, QFileDialog |
|
14 |
|
15 from E5Gui.E5Completers import E5DirCompleter |
|
16 |
|
17 from .Ui_HgNewProjectOptionsDialog import Ui_HgNewProjectOptionsDialog |
|
18 from .Config import ConfigHgProtocols |
|
19 |
|
20 import Utilities |
|
21 |
|
22 class HgNewProjectOptionsDialog(QDialog, Ui_HgNewProjectOptionsDialog): |
|
23 """ |
|
24 Class implementing the Options Dialog for a new project from the repository. |
|
25 """ |
|
26 def __init__(self, vcs, parent = None): |
|
27 """ |
|
28 Constructor |
|
29 |
|
30 @param vcs reference to the version control object |
|
31 @param parent parent widget (QWidget) |
|
32 """ |
|
33 QDialog.__init__(self, parent) |
|
34 self.setupUi(self) |
|
35 |
|
36 self.vcsDirectoryCompleter = E5DirCompleter(self.vcsUrlEdit) |
|
37 self.vcsProjectDirCompleter = E5DirCompleter(self.vcsProjectDirEdit) |
|
38 |
|
39 self.protocolCombo.addItems(ConfigHgProtocols) |
|
40 |
|
41 hd = Utilities.toNativeSeparators(QDir.homePath()) |
|
42 hd = os.path.join(hd, 'hgroot') |
|
43 self.vcsUrlEdit.setText(hd) |
|
44 |
|
45 self.vcs = vcs |
|
46 |
|
47 self.localPath = hd |
|
48 self.networkPath = "localhost/" |
|
49 self.localProtocol = True |
|
50 |
|
51 @pyqtSlot() |
|
52 def on_vcsUrlButton_clicked(self): |
|
53 """ |
|
54 Private slot to display a selection dialog. |
|
55 """ |
|
56 if self.protocolCombo.currentText() == "file://": |
|
57 directory = QFileDialog.getExistingDirectory(\ |
|
58 self, |
|
59 self.trUtf8("Select Repository-Directory"), |
|
60 self.vcsUrlEdit.text(), |
|
61 QFileDialog.Options(QFileDialog.ShowDirsOnly)) |
|
62 |
|
63 if directory: |
|
64 self.vcsUrlEdit.setText(Utilities.toNativeSeparators(directory)) |
|
65 ## else: |
|
66 ## dlg = SvnRepoBrowserDialog(self.vcs, mode = "select", parent = self) |
|
67 ## dlg.start(self.protocolCombo.currentText() + self.vcsUrlEdit.text()) |
|
68 ## if dlg.exec_() == QDialog.Accepted: |
|
69 ## url = dlg.getSelectedUrl() |
|
70 ## if url: |
|
71 ## protocol = url.split("://")[0] |
|
72 ## path = url.split("://")[1] |
|
73 ## self.protocolCombo.setCurrentIndex(\ |
|
74 ## self.protocolCombo.findText(protocol + "://")) |
|
75 ## self.vcsUrlEdit.setText(path) |
|
76 |
|
77 @pyqtSlot() |
|
78 def on_projectDirButton_clicked(self): |
|
79 """ |
|
80 Private slot to display a directory selection dialog. |
|
81 """ |
|
82 directory = QFileDialog.getExistingDirectory(\ |
|
83 self, |
|
84 self.trUtf8("Select Project Directory"), |
|
85 self.vcsProjectDirEdit.text(), |
|
86 QFileDialog.Options(QFileDialog.ShowDirsOnly)) |
|
87 |
|
88 if directory: |
|
89 self.vcsProjectDirEdit.setText(Utilities.toNativeSeparators(directory)) |
|
90 |
|
91 @pyqtSlot(str) |
|
92 def on_protocolCombo_activated(self, protocol): |
|
93 """ |
|
94 Private slot to switch the status of the directory selection button. |
|
95 |
|
96 @param protocol name of the selected protocol (string) |
|
97 """ |
|
98 self.vcsUrlButton.setEnabled(protocol == "file://") |
|
99 if protocol == "file://": |
|
100 self.networkPath = self.vcsUrlEdit.text() |
|
101 self.vcsUrlEdit.setText(self.localPath) |
|
102 self.localProtocol = True |
|
103 else: |
|
104 if self.localProtocol: |
|
105 self.localPath = self.vcsUrlEdit.text() |
|
106 self.vcsUrlEdit.setText(self.networkPath) |
|
107 self.localProtocol = False |
|
108 |
|
109 def getData(self): |
|
110 """ |
|
111 Public slot to retrieve the data entered into the dialog. |
|
112 |
|
113 @return a tuple of a string (project directory) and a dictionary |
|
114 containing the data entered. |
|
115 """ |
|
116 scheme = self.protocolCombo.currentText() |
|
117 url = self.vcsUrlEdit.text() |
|
118 if scheme == "file://" and url[0] not in ["\\", "/"]: |
|
119 url = "/%s" % url |
|
120 vcsdatadict = { |
|
121 "url" : '%s%s' % (scheme, url), |
|
122 "revision" : self.vcsRevisionEdit.text(), |
|
123 } |
|
124 return (self.vcsProjectDirEdit.text(), vcsdatadict) |