|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2015 - 2017 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter data for a Fetch operation. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot |
|
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
14 |
|
15 from .Ui_GitFetchDialog import Ui_GitFetchDialog |
|
16 |
|
17 |
|
18 class GitFetchDialog(QDialog, Ui_GitFetchDialog): |
|
19 """ |
|
20 Class implementing a dialog to enter data for a Fetch operation. |
|
21 """ |
|
22 def __init__(self, vcs, repodir, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param vcs reference to the git object |
|
27 @param repodir directory name of the local repository (string) |
|
28 @param parent reference to the parent widget (QWidget) |
|
29 """ |
|
30 super(GitFetchDialog, self).__init__(parent) |
|
31 self.setupUi(self) |
|
32 |
|
33 self.__vcs = vcs |
|
34 self.__repodir = repodir |
|
35 |
|
36 self.__all = self.tr("<All>") |
|
37 self.__custom = self.tr("<Custom>") |
|
38 |
|
39 remoteUrlsList = self.__vcs.gitGetRemoteUrlsList(self.__repodir) |
|
40 self.__repos = {name: url for name, url in remoteUrlsList} |
|
41 |
|
42 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
|
43 |
|
44 self.remotesComboBox.addItems(sorted(self.__repos.keys())) |
|
45 self.remotesComboBox.addItem(self.__all) |
|
46 self.remotesComboBox.addItem(self.__custom) |
|
47 |
|
48 index = self.remotesComboBox.findText("origin") |
|
49 if index == -1: |
|
50 index = 0 |
|
51 self.remotesComboBox.setCurrentIndex(index) |
|
52 |
|
53 localBranches = self.__vcs.gitGetBranchesList( |
|
54 self.__repodir, withMaster=True) |
|
55 self.localBranchComboBox.addItems([""] + sorted(localBranches)) |
|
56 self.localBranchComboBox.setEnabled(False) |
|
57 |
|
58 def __okButtonEnable(self): |
|
59 """ |
|
60 Private slot to set the enabled state of the OK button. |
|
61 """ |
|
62 self.__okButton.setEnabled( |
|
63 self.remoteBranchesList.count() > 0 or |
|
64 self.remotesComboBox.currentText() == self.__all |
|
65 ) |
|
66 |
|
67 def __updateButtonEnable(self): |
|
68 """ |
|
69 Private slot to set the enabled state of the update button. |
|
70 """ |
|
71 remote = self.remotesComboBox.currentText() |
|
72 enable = remote != self.__all |
|
73 if remote == self.__custom: |
|
74 enable = self.remoteEdit.text() != "" |
|
75 |
|
76 self.updateButton.setEnabled(enable) |
|
77 |
|
78 @pyqtSlot(str) |
|
79 def on_remotesComboBox_currentTextChanged(self, txt): |
|
80 """ |
|
81 Private slot to handle changes of the selected repository. |
|
82 |
|
83 @param txt current text of the combo box (string) |
|
84 """ |
|
85 self.remoteEdit.setReadOnly(txt != self.__custom) |
|
86 self.remoteBranchesList.setEnabled(txt != self.__all) |
|
87 self.remoteEdit.clear() |
|
88 self.remoteBranchesList.clear() |
|
89 self.__updateButtonEnable() |
|
90 self.__okButtonEnable() |
|
91 |
|
92 if txt not in [self.__all, self.__custom]: |
|
93 remoteBranches = self.__vcs.gitGetRemoteBranchesList( |
|
94 self.__repodir, txt) |
|
95 self.remoteBranchesList.addItems(sorted(remoteBranches)) |
|
96 |
|
97 if txt in self.__repos: |
|
98 self.remoteEdit.setText(self.__repos[txt]) |
|
99 |
|
100 @pyqtSlot(str) |
|
101 def on_remoteEdit_textChanged(self, txt): |
|
102 """ |
|
103 Private slot to handle changes of the URL edit. |
|
104 |
|
105 @param txt current text of the URL edit (string) |
|
106 """ |
|
107 self.__updateButtonEnable() |
|
108 |
|
109 if self.remotesComboBox.currentText() == self.__custom and \ |
|
110 txt != "": |
|
111 remoteBranches = self.__vcs.gitGetRemoteBranchesList( |
|
112 self.__repodir, txt) |
|
113 self.remoteBranchesList.clear() |
|
114 self.remoteBranchesList.addItems(sorted(remoteBranches)) |
|
115 |
|
116 self.__okButtonEnable() |
|
117 |
|
118 @pyqtSlot() |
|
119 def on_remoteBranchesList_itemSelectionChanged(self): |
|
120 """ |
|
121 Private slot to handle a change of selected remote branches. |
|
122 """ |
|
123 singleSelection = len(self.remoteBranchesList.selectedItems()) == 1 |
|
124 self.localBranchComboBox.setEnabled(singleSelection) |
|
125 if singleSelection: |
|
126 txt = self.remoteBranchesList.selectedItems()[0].text() |
|
127 else: |
|
128 txt = "" |
|
129 index = self.localBranchComboBox.findText(txt) |
|
130 if index == -1: |
|
131 self.localBranchComboBox.setEditText(txt) |
|
132 else: |
|
133 self.localBranchComboBox.setCurrentIndex(index) |
|
134 |
|
135 @pyqtSlot() |
|
136 def on_updateButton_clicked(self): |
|
137 """ |
|
138 Private slot to update the list of remote branches. |
|
139 """ |
|
140 remote = self.remotesComboBox.currentText() |
|
141 if remote == self.__all: |
|
142 # shouldn't happen |
|
143 return |
|
144 |
|
145 if remote == self.__custom: |
|
146 remote = self.remoteEdit.text() |
|
147 if remote == "": |
|
148 # shouldn't happen either |
|
149 return |
|
150 |
|
151 remoteBranches = self.__vcs.gitGetRemoteBranchesList( |
|
152 self.__repodir, remote) |
|
153 self.remoteBranchesList.clear() |
|
154 self.remoteBranchesList.addItems(sorted(remoteBranches)) |
|
155 |
|
156 self.__okButtonEnable() |
|
157 |
|
158 def getData(self): |
|
159 """ |
|
160 Public method to get the entered data. |
|
161 |
|
162 @return tuple of remote name, remote url (for custom remotes), |
|
163 remote branches, local branch, a flag indicating to fetch from |
|
164 all repositories, a flag indicating to remove obsolete tracking |
|
165 references and a flag indicating to fetch tags as well |
|
166 (string, string, list of strings, string, boolean, boolean, |
|
167 boolean) |
|
168 """ |
|
169 remote = "" |
|
170 url = "" |
|
171 remoteBranches = [] |
|
172 allRepos = False |
|
173 localBranch = "" |
|
174 |
|
175 remoteRepo = self.remotesComboBox.currentText() |
|
176 if remoteRepo == self.__all: |
|
177 allRepos = True |
|
178 else: |
|
179 if remoteRepo == self.__custom: |
|
180 url = self.remoteEdit.text() |
|
181 else: |
|
182 remote = remoteRepo |
|
183 for itm in self.remoteBranchesList.selectedItems(): |
|
184 remoteBranches.append(itm.text()) |
|
185 if len(remoteBranches) == 1: |
|
186 localBranch = self.localBranchComboBox.currentText() |
|
187 |
|
188 return (remote, url, remoteBranches, localBranch, allRepos, |
|
189 self.pruneCheckBox.isChecked(), self.tagsCheckBox.isChecked()) |