-
Notifications
You must be signed in to change notification settings - Fork 0
/
address_dialogs.py
354 lines (319 loc) · 13.8 KB
/
address_dialogs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
from PyQt4 import QtCore, QtGui
from addresses import decodeAddress, encodeVarint, addBMIfNotPresent
from account import (
GatewayAccount, MailchuckAccount, AccountMixin, accountClass,
getSortedAccounts
)
from tr import _translate
from retranslateui import RetranslateMixin
import widgets
import queues
import hashlib
from inventory import Inventory
class AddressCheckMixin(object):
def __init__(self):
self.valid = False
QtCore.QObject.connect(self.lineEditAddress, QtCore.SIGNAL(
"textChanged(QString)"), self.addressChanged)
def _onSuccess(self, addressVersion, streamNumber, ripe):
pass
def addressChanged(self, QString):
status, addressVersion, streamNumber, ripe = decodeAddress(
str(QString))
self.valid = status == 'success'
if self.valid:
self.labelAddressCheck.setText(
_translate("MainWindow", "Address is valid."))
self._onSuccess(addressVersion, streamNumber, ripe)
elif status == 'missingbm':
self.labelAddressCheck.setText(_translate(
"MainWindow", # dialog name should be here
"The address should start with ''BM-''"
))
elif status == 'checksumfailed':
self.labelAddressCheck.setText(_translate(
"MainWindow",
"The address is not typed or copied correctly"
" (the checksum failed)."
))
elif status == 'versiontoohigh':
self.labelAddressCheck.setText(_translate(
"MainWindow",
"The version number of this address is higher than this"
" software can support. Please upgrade Bitmessage."
))
elif status == 'invalidcharacters':
self.labelAddressCheck.setText(_translate(
"MainWindow",
"The address contains invalid characters."
))
elif status == 'ripetooshort':
self.labelAddressCheck.setText(_translate(
"MainWindow",
"Some data encoded in the address is too short."
))
elif status == 'ripetoolong':
self.labelAddressCheck.setText(_translate(
"MainWindow",
"Some data encoded in the address is too long."
))
elif status == 'varintmalformed':
self.labelAddressCheck.setText(_translate(
"MainWindow",
"Some data encoded in the address is malformed."
))
class AddressDataDialog(QtGui.QDialog, AddressCheckMixin):
def __init__(self, parent):
super(AddressDataDialog, self).__init__(parent)
self.parent = parent
def accept(self):
if self.valid:
self.data = (
addBMIfNotPresent(str(self.lineEditAddress.text())),
str(self.lineEditLabel.text().toUtf8())
)
else:
queues.UISignalQueue.put(('updateStatusBar', _translate(
"MainWindow",
"The address you entered was invalid. Ignoring it."
)))
super(AddressDataDialog, self).accept()
class AddAddressDialog(AddressDataDialog, RetranslateMixin):
def __init__(self, parent=None, address=None):
super(AddAddressDialog, self).__init__(parent)
widgets.load('addaddressdialog.ui', self)
AddressCheckMixin.__init__(self)
if address:
self.lineEditAddress.setText(address)
class NewAddressDialog(QtGui.QDialog, RetranslateMixin):
def __init__(self, parent=None):
super(NewAddressDialog, self).__init__(parent)
widgets.load('newaddressdialog.ui', self)
# Let's fill out the 'existing address' combo box with addresses
# from the 'Your Identities' tab.
for address in getSortedAccounts():
self.radioButtonExisting.click()
self.comboBoxExisting.addItem(address)
self.groupBoxDeterministic.setHidden(True)
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
self.show()
def accept(self):
self.hide()
# self.buttonBox.enabled = False
if self.radioButtonRandomAddress.isChecked():
if self.radioButtonMostAvailable.isChecked():
streamNumberForAddress = 1
else:
# User selected 'Use the same stream as an existing
# address.'
streamNumberForAddress = decodeAddress(
self.comboBoxExisting.currentText())[2]
queues.addressGeneratorQueue.put((
'createRandomAddress', 4, streamNumberForAddress,
str(self.newaddresslabel.text().toUtf8()), 1, "",
self.checkBoxEighteenByteRipe.isChecked()
))
else:
if self.lineEditPassphrase.text() != \
self.lineEditPassphraseAgain.text():
QtGui.QMessageBox.about(
self, _translate("MainWindow", "Passphrase mismatch"),
_translate(
"MainWindow",
"The passphrase you entered twice doesn\'t"
" match. Try again.")
)
elif self.lineEditPassphrase.text() == "":
QtGui.QMessageBox.about(
self, _translate("MainWindow", "Choose a passphrase"),
_translate(
"MainWindow", "You really do need a passphrase.")
)
else:
# this will eventually have to be replaced by logic
# to determine the most available stream number.
streamNumberForAddress = 1
queues.addressGeneratorQueue.put((
'createDeterministicAddresses', 4, streamNumberForAddress,
"unused deterministic address",
self.spinBoxNumberOfAddressesToMake.value(),
self.lineEditPassphrase.text().toUtf8(),
self.checkBoxEighteenByteRipe.isChecked()
))
class NewSubscriptionDialog(AddressDataDialog, RetranslateMixin):
def __init__(self, parent=None):
super(NewSubscriptionDialog, self).__init__(parent)
widgets.load('newsubscriptiondialog.ui', self)
AddressCheckMixin.__init__(self)
def _onSuccess(self, addressVersion, streamNumber, ripe):
if addressVersion <= 3:
self.checkBoxDisplayMessagesAlreadyInInventory.setText(_translate(
"MainWindow",
"Address is an old type. We cannot display its past"
" broadcasts."
))
else:
Inventory().flush()
doubleHashOfAddressData = hashlib.sha512(hashlib.sha512(
encodeVarint(addressVersion) +
encodeVarint(streamNumber) + ripe
).digest()).digest()
tag = doubleHashOfAddressData[32:]
self.recent = Inventory().by_type_and_tag(3, tag)
count = len(self.recent)
if count == 0:
self.checkBoxDisplayMessagesAlreadyInInventory.setText(
_translate(
"MainWindow",
"There are no recent broadcasts from this address"
" to display."
))
else:
self.checkBoxDisplayMessagesAlreadyInInventory.setEnabled(True)
self.checkBoxDisplayMessagesAlreadyInInventory.setText(
_translate(
"MainWindow",
"Display the %n recent broadcast(s) from this address.",
None,
QtCore.QCoreApplication.CodecForTr,
count
))
class RegenerateAddressesDialog(QtGui.QDialog, RetranslateMixin):
def __init__(self, parent=None):
super(RegenerateAddressesDialog, self).__init__(parent)
widgets.load('regenerateaddresses.ui', self)
self.groupBox.setTitle('')
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
class SpecialAddressBehaviorDialog(QtGui.QDialog, RetranslateMixin):
def __init__(self, parent=None, config=None):
super(SpecialAddressBehaviorDialog, self).__init__(parent)
widgets.load('specialaddressbehavior.ui', self)
self.address = parent.getCurrentAccount()
self.parent = parent
self.config = config
try:
self.address_is_chan = config.safeGetBoolean(
self.address, 'chan'
)
except AttributeError:
pass
else:
if self.address_is_chan: # address is a chan address
self.radioButtonBehaviorMailingList.setDisabled(True)
self.lineEditMailingListName.setText(_translate(
"SpecialAddressBehaviorDialog",
"This is a chan address. You cannot use it as a"
" pseudo-mailing list."
))
else:
if config.safeGetBoolean(self.address, 'mailinglist'):
self.radioButtonBehaviorMailingList.click()
else:
self.radioButtonBehaveNormalAddress.click()
try:
mailingListName = config.get(
self.address, 'mailinglistname')
except:
mailingListName = ''
self.lineEditMailingListName.setText(
unicode(mailingListName, 'utf-8')
)
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
self.show()
def accept(self):
self.hide()
if self.address_is_chan:
return
if self.radioButtonBehaveNormalAddress.isChecked():
self.config.set(str(self.address), 'mailinglist', 'false')
# Set the color to either black or grey
if self.config.getboolean(self.address, 'enabled'):
self.parent.setCurrentItemColor(
QtGui.QApplication.palette().text().color()
)
else:
self.parent.setCurrentItemColor(QtGui.QColor(128, 128, 128))
else:
self.config.set(str(self.address), 'mailinglist', 'true')
self.config.set(str(self.address), 'mailinglistname', str(
self.lineEditMailingListName.text().toUtf8()))
self.parent.setCurrentItemColor(
QtGui.QColor(137, 04, 177)) # magenta
self.parent.rerenderComboBoxSendFrom()
self.parent.rerenderComboBoxSendFromBroadcast()
self.config.save()
self.parent.rerenderMessagelistToLabels()
class EmailGatewayDialog(QtGui.QDialog, RetranslateMixin):
def __init__(self, parent, config=None, account=None):
super(EmailGatewayDialog, self).__init__(parent)
widgets.load('emailgateway.ui', self)
self.parent = parent
self.config = config
if account:
self.acct = account
self.setWindowTitle(_translate(
"EmailGatewayDialog", "Registration failed:"))
self.label.setText(_translate(
"EmailGatewayDialog",
"The requested email address is not available,"
" please try a new one."
))
self.radioButtonRegister.hide()
self.radioButtonStatus.hide()
self.radioButtonSettings.hide()
self.radioButtonUnregister.hide()
else:
address = parent.getCurrentAccount()
self.acct = accountClass(address)
try:
label = config.get(address, 'label')
except AttributeError:
pass
else:
if "@" in label:
self.lineEditEmail.setText(label)
if isinstance(self.acct, GatewayAccount):
self.radioButtonUnregister.setEnabled(True)
self.radioButtonStatus.setEnabled(True)
self.radioButtonStatus.setChecked(True)
self.radioButtonSettings.setEnabled(True)
self.lineEditEmail.setEnabled(False)
else:
self.acct = MailchuckAccount(address)
self.lineEditEmail.setFocus()
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
def accept(self):
self.hide()
# no chans / mailinglists
if self.acct.type != AccountMixin.NORMAL:
return
if not isinstance(self.acct, GatewayAccount):
return
if self.radioButtonRegister.isChecked() \
or self.radioButtonRegister.isHidden():
email = str(self.lineEditEmail.text().toUtf8())
self.acct.register(email)
self.config.set(self.acct.fromAddress, 'label', email)
self.config.set(self.acct.fromAddress, 'gateway', 'mailchuck')
self.config.save()
queues.UISignalQueue.put(('updateStatusBar', _translate(
"EmailGatewayDialog",
"Sending email gateway registration request"
)))
elif self.radioButtonUnregister.isChecked():
self.acct.unregister()
self.config.remove_option(self.acct.fromAddress, 'gateway')
self.config.save()
queues.UISignalQueue.put(('updateStatusBar', _translate(
"EmailGatewayDialog",
"Sending email gateway unregistration request"
)))
elif self.radioButtonStatus.isChecked():
self.acct.status()
queues.UISignalQueue.put(('updateStatusBar', _translate(
"EmailGatewayDialog",
"Sending email gateway status request"
)))
elif self.radioButtonSettings.isChecked():
self.data = self.acct
super(EmailGatewayDialog, self).accept()