Debian Codegraph @

lib/send.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # QBrz - Qt frontend to Breezy commands
4 #
5 # Contributors:
6 # Javier Derderian <[email protected]>
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 import re
23 from PyQt5 import QtCore, QtGui, QtWidgets
24
25 from breezy import errors
26 from breezy.plugins.qbrz.lib.i18n import gettext
27 from breezy.plugins.qbrz.lib.subprocess import SubProcessDialog
28 from breezy.plugins.qbrz.lib.util import url_for_display
29
30 class SendWindow(SubProcessDialog):
31
32 def __init__(self, branch, ui_mode=False, parent=None):
33
34 title = "%s: %s" % (gettext("Send"), url_for_display(branch.base))
35 super(SendWindow, self).__init__(
36 title,
37 name = "send",
38 default_size = (400, 400),
39 ui_mode = ui_mode,
40 dialog = True,
41 parent = parent,
42 hide_progress=False,
43 )
44
45 self.branch = branch
46
47 gbMergeDirective = QtWidgets.QGroupBox(gettext("Merge Directive Options"), self)
48 vboxMergeDirective = QtWidgets.QVBoxLayout(gbMergeDirective)
49 vboxMergeDirective.addStrut(0)
50
51 submit_hbox = QtWidgets.QHBoxLayout()
52
53 submit_branch_label = QtWidgets.QLabel(gettext("Submit Branch:"))
54 submit_branch_combo = QtWidgets.QComboBox()
55 submit_branch_combo.setEditable(True)
56
57 submitbranch = branch.get_submit_branch()
58 if submitbranch != None:
59 submit_branch_combo.addItem(submitbranch)
60
61 self.submit_branch_combo = submit_branch_combo # to allow access from another function
62 browse_submit_button = QtWidgets.QPushButton(gettext("Browse"))
63 browse_submit_button.clicked[bool].connect(self.browse_submit_clicked)
64
65 submit_hbox.addWidget(submit_branch_label)
66 submit_hbox.addWidget(submit_branch_combo)
67 submit_hbox.addWidget(browse_submit_button)
68
69 submit_hbox.setStretchFactor(submit_branch_label,0)
70 submit_hbox.setStretchFactor(submit_branch_combo,1)
71 submit_hbox.setStretchFactor(browse_submit_button,0)
72
73 vboxMergeDirective.addLayout(submit_hbox)
74
75 public_hbox = QtWidgets.QHBoxLayout()
76
77 public_branch_label = QtWidgets.QLabel(gettext("Public Branch:"))
78 public_branch_combo = QtWidgets.QComboBox()
79 public_branch_combo.setEditable(True)
80
81 publicbranch = branch.get_public_branch()
82 if publicbranch != None:
83 public_branch_combo.addItem(publicbranch)
84
85 self.public_branch_combo = public_branch_combo # to allow access from another function
86 browse_public_button = QtWidgets.QPushButton(gettext("Browse"))
87 browse_public_button.clicked[bool].connect(self.browse_public_clicked)
88
89 public_hbox.addWidget(public_branch_label)
90 public_hbox.addWidget(public_branch_combo)
91 public_hbox.addWidget(browse_public_button)
92
93 public_hbox.setStretchFactor(public_branch_label,0)
94 public_hbox.setStretchFactor(public_branch_combo,1)
95 public_hbox.setStretchFactor(browse_public_button,0)
96
97 vboxMergeDirective.addLayout(public_hbox)
98
99 remember_check = QtWidgets.QCheckBox(gettext("Remember these locations as defaults"))
100 self.remember_check = remember_check
101 vboxMergeDirective.addWidget(remember_check)
102
103 bundle_check = QtWidgets.QCheckBox(gettext("Include a bundle in the merge directive"))
104 bundle_check.setChecked(True)
105 self.bundle_check = bundle_check
106 vboxMergeDirective.addWidget(bundle_check)
107 patch_check = QtWidgets.QCheckBox(gettext("Include a preview patch in the merge directive"))
108 patch_check.setChecked(True)
109 self.patch_check = patch_check
110 vboxMergeDirective.addWidget(patch_check)
111
112 gbAction = QtWidgets.QGroupBox(gettext("Action"), self)
113 vboxAction = QtWidgets.QVBoxLayout(gbAction)
114
115 submit_email_radio = QtWidgets.QRadioButton("Send e-mail")
116 submit_email_radio.toggle()
117 self.submit_email_radio = submit_email_radio
118 vboxAction.addWidget(submit_email_radio)
119
120 mailto_hbox = QtWidgets.QHBoxLayout()
121
122 mailto_label = QtWidgets.QLabel(gettext("Address:"))
123 mailto_edit = QtWidgets.QLineEdit()
124 self.mailto_edit = mailto_edit
125 mailto_hbox.insertSpacing(0,50)
126 mailto_hbox.addWidget(mailto_label)
127 mailto_hbox.addWidget(mailto_edit)
128
129 vboxAction.addLayout(mailto_hbox)
130
131 message_hbox = QtWidgets.QHBoxLayout()
132 message_label = QtWidgets.QLabel(gettext("Message:"))
133 message_edit = QtWidgets.QLineEdit()
134 self.message_edit = message_edit
135
136 message_hbox.insertSpacing(0,50)
137 message_hbox.addWidget(message_label)
138 message_hbox.addWidget(message_edit)
139
140 vboxAction.addLayout(message_hbox)
141
142 save_file_radio = QtWidgets.QRadioButton("Save to file")
143 self.save_file_radio = save_file_radio
144
145 vboxAction.addWidget(save_file_radio)
146
147 savefile_hbox = QtWidgets.QHBoxLayout()
148
149 savefile_label = QtWidgets.QLabel(gettext("Filename:"))
150 savefile_edit = QtWidgets.QLineEdit()
151 self.savefile_edit = savefile_edit # to allow access from callback function
152 savefile_button = QtWidgets.QPushButton(gettext("Browse"))
153 savefile_button.clicked[bool].connect(self.savefile_button_clicked)
154
155 savefile_hbox.insertSpacing(0,50)
156 savefile_hbox.addWidget(savefile_label)
157 savefile_hbox.addWidget(savefile_edit)
158 savefile_hbox.addWidget(savefile_button)
159
160 vboxAction.addLayout(savefile_hbox)
161
162 revisions_hbox = QtWidgets.QHBoxLayout()
163 revisions_label = QtWidgets.QLabel(gettext("Revisions:"))
164 revisions_edit = QtWidgets.QLineEdit()
165 self.revisions_edit = revisions_edit
166
167 revisions_hbox.addWidget(revisions_label)
168 revisions_hbox.addWidget(revisions_edit)
169
170 vboxAction.addLayout(revisions_hbox)
171
172 layout = QtWidgets.QVBoxLayout(self)
173
174 self.splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical)
175 self.splitter.addWidget(gbAction)
176 self.splitter.addWidget(gbMergeDirective)
177
178 self.splitter.addWidget(self.make_default_status_box())
179
180 self.splitter.setStretchFactor(0, 10)
181 self.restoreSplitterSizes([150, 150])
182
183 layout.addWidget(self.splitter)
184 layout.addWidget(self.buttonbox)
185
186 def savefile_button_clicked(self):
187 fileName = QtWidgets.QFileDialog.getSaveFileName(self, ("Select save location"));[0]
188 if fileName != '':
189 self.savefile_edit.setText(fileName)
190
191 def browse_submit_clicked(self):
192 fileName = QtWidgets.QFileDialog.getExistingDirectory(self, ("Select Submit branch"));
193 if fileName != '':
194 self.submit_branch_combo.insertItem(0,fileName)
195 self.submit_branch_combo.setCurrentIndex(0)
196
197 def browse_public_clicked(self):
198 fileName = QtWidgets.QFileDialog.getExistingDirectory(self, ("Select Public branch"));
199 if fileName != '':
200 self.public_branch_combo.insertItem(0,fileName)
201 self.public_branch_combo.setCurrentIndex(0)
202
203 def validate(self):
204 if self.submit_email_radio.isChecked():
205 location = str(self.mailto_edit.text())
206 if not location:
207 self.mailto_edit.setFocus()
208 self.operation_blocked(gettext("Email address not entered."))
209 return False
210 if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", location) is None:
211 self.mailto_edit.setFocus()
212 self.operation_blocked(gettext("Email address is not valid."))
213 return False
214 else:
215 location = str(self.savefile_edit.text())
216 if not location:
217 self.savefile_edit.setFocus()
218 self.operation_blocked(gettext("Filename not entered."))
219 return False
220
221 submit_branch = str(self.submit_branch_combo.currentText())
222 if not submit_branch:
223 self.submit_branch_combo.setFocus()
224 self.operation_blocked(gettext("No submit branch entered."))
225 return False
226 return True
227
228 def do_start(self):
229 args = []
230 submit_branch = str(self.submit_branch_combo.currentText())
231 public_branch = str(self.public_branch_combo.currentText())
232
233 if public_branch:
234 args.append(public_branch)
235
236 mylocation = url_for_display(self.branch.base)
237 args.append("-f")
238 args.append(mylocation)
239
240 if self.submit_email_radio.isChecked():
241 location = str(self.mailto_edit.text())
242 args.append("--mail-to=%s" % location)
243 else:
244 location = str(self.savefile_edit.text())
245 args.append("-o")
246 args.append(location)
247
248 if self.remember_check.isChecked():
249 args.append("--remember")
250
251 if not self.patch_check.isChecked():
252 args.append("--no-patch")
253
254 if not self.bundle_check.isChecked():
255 args.append("--no-bundle")
256
257 if str(self.message_edit.text()):
258 args.append("--message=%s" % str(self.message_edit.text()))
259
260 revision = str(self.revisions_edit.text())
261 if revision == '':
262 args.append("--revision=-1")
263 else:
264 args.append("--revision=%s" % revision)
265
266 self.process_widget.do_start(None, 'send', submit_branch, *args)
267
268 def _saveSize(self, config):
269 SubProcessDialog._saveSize(self, config)
270 self._saveSplitterSizes(config, self.splitter)