2018-10-21 18:14:20 +02:00
|
|
|
"""
|
|
|
|
src/bitmessageqt/newchandialog.py
|
|
|
|
=================================
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2013-06-25 23:14:44 +02:00
|
|
|
from PyQt4 import QtCore, QtGui
|
|
|
|
|
2018-10-21 18:14:20 +02:00
|
|
|
import widgets
|
2016-10-28 22:07:16 +02:00
|
|
|
from addresses import addBMIfNotPresent
|
|
|
|
from addressvalidator import AddressValidator, PassPhraseValidator
|
2018-11-20 13:11:18 +01:00
|
|
|
from queues import (
|
|
|
|
addressGeneratorQueue, apiAddressGeneratorReturnQueue, UISignalQueue)
|
2016-10-28 22:07:16 +02:00
|
|
|
from tr import _translate
|
|
|
|
from utils import str_chan
|
2018-10-21 18:14:20 +02:00
|
|
|
|
2016-10-28 22:07:16 +02:00
|
|
|
|
2018-11-20 13:11:18 +01:00
|
|
|
class NewChanDialog(QtGui.QDialog):
|
2018-10-21 18:14:20 +02:00
|
|
|
"""The `New Chan` dialog"""
|
2016-10-28 22:07:16 +02:00
|
|
|
def __init__(self, parent=None):
|
|
|
|
super(NewChanDialog, self).__init__(parent)
|
|
|
|
widgets.load('newchandialog.ui', self)
|
|
|
|
self.parent = parent
|
2018-10-21 18:14:20 +02:00
|
|
|
self.chanAddress.setValidator(
|
|
|
|
AddressValidator(
|
|
|
|
self.chanAddress,
|
|
|
|
self.chanPassPhrase,
|
|
|
|
self.validatorFeedback,
|
|
|
|
self.buttonBox,
|
|
|
|
False))
|
|
|
|
self.chanPassPhrase.setValidator(
|
|
|
|
PassPhraseValidator(
|
|
|
|
self.chanPassPhrase,
|
|
|
|
self.chanAddress,
|
|
|
|
self.validatorFeedback,
|
|
|
|
self.buttonBox,
|
|
|
|
False))
|
2016-10-28 22:07:16 +02:00
|
|
|
|
|
|
|
self.timer = QtCore.QTimer()
|
2018-10-21 18:14:20 +02:00
|
|
|
QtCore.QObject.connect( # pylint: disable=no-member
|
|
|
|
self.timer, QtCore.SIGNAL("timeout()"), self.delayedUpdateStatus)
|
|
|
|
self.timer.start(500) # milliseconds
|
2016-10-28 22:07:16 +02:00
|
|
|
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
|
|
|
self.show()
|
|
|
|
|
|
|
|
def delayedUpdateStatus(self):
|
2018-10-21 18:14:20 +02:00
|
|
|
"""Related to updating the UI for the chan passphrase validity"""
|
2016-10-28 22:07:16 +02:00
|
|
|
self.chanPassPhrase.validator().checkQueue()
|
|
|
|
|
|
|
|
def accept(self):
|
2018-10-21 18:14:20 +02:00
|
|
|
"""Proceed in joining the chan"""
|
2016-10-28 22:07:16 +02:00
|
|
|
self.timer.stop()
|
|
|
|
self.hide()
|
|
|
|
apiAddressGeneratorReturnQueue.queue.clear()
|
|
|
|
if self.chanAddress.text().toUtf8() == "":
|
2018-10-21 18:14:20 +02:00
|
|
|
addressGeneratorQueue.put(
|
|
|
|
('createChan', 4, 1, str_chan + ' ' + str(self.chanPassPhrase.text().toUtf8()),
|
|
|
|
self.chanPassPhrase.text().toUtf8(),
|
|
|
|
True))
|
2016-10-28 22:07:16 +02:00
|
|
|
else:
|
2018-10-21 18:14:20 +02:00
|
|
|
addressGeneratorQueue.put(
|
|
|
|
('joinChan', addBMIfNotPresent(self.chanAddress.text().toUtf8()),
|
|
|
|
str_chan + ' ' + str(self.chanPassPhrase.text().toUtf8()),
|
|
|
|
self.chanPassPhrase.text().toUtf8(),
|
|
|
|
True))
|
2016-10-28 22:07:16 +02:00
|
|
|
addressGeneratorReturnValue = apiAddressGeneratorReturnQueue.get(True)
|
2018-10-21 18:14:20 +02:00
|
|
|
if addressGeneratorReturnValue and addressGeneratorReturnValue[0] != 'chan name does not match address':
|
|
|
|
UISignalQueue.put(('updateStatusBar', _translate(
|
|
|
|
"newchandialog", "Successfully created / joined chan %1").arg(unicode(self.chanPassPhrase.text()))))
|
2018-01-18 15:14:29 +01:00
|
|
|
self.parent.ui.tabWidget.setCurrentIndex(
|
|
|
|
self.parent.ui.tabWidget.indexOf(self.parent.ui.chans)
|
|
|
|
)
|
2016-10-28 22:07:16 +02:00
|
|
|
self.done(QtGui.QDialog.Accepted)
|
|
|
|
else:
|
|
|
|
UISignalQueue.put(('updateStatusBar', _translate("newchandialog", "Chan creation / joining failed")))
|
|
|
|
self.done(QtGui.QDialog.Rejected)
|
|
|
|
|
|
|
|
def reject(self):
|
2018-10-21 18:14:20 +02:00
|
|
|
"""Cancel joining the chan"""
|
2016-10-28 22:07:16 +02:00
|
|
|
self.timer.stop()
|
|
|
|
self.hide()
|
|
|
|
UISignalQueue.put(('updateStatusBar', _translate("newchandialog", "Chan creation / joining cancelled")))
|
|
|
|
self.done(QtGui.QDialog.Rejected)
|