2013-06-25 23:14:44 +02:00
|
|
|
from PyQt4 import QtCore, QtGui
|
|
|
|
|
2016-10-28 22:07:16 +02:00
|
|
|
from addresses import addBMIfNotPresent
|
|
|
|
from addressvalidator import AddressValidator, PassPhraseValidator
|
2017-02-08 13:41:56 +01:00
|
|
|
from queues import apiAddressGeneratorReturnQueue, addressGeneratorQueue, UISignalQueue
|
2016-10-28 22:07:16 +02:00
|
|
|
from retranslateui import RetranslateMixin
|
|
|
|
from tr import _translate
|
|
|
|
from utils import str_chan
|
|
|
|
import widgets
|
|
|
|
|
|
|
|
class NewChanDialog(QtGui.QDialog, RetranslateMixin):
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
super(NewChanDialog, self).__init__(parent)
|
|
|
|
widgets.load('newchandialog.ui', self)
|
|
|
|
self.parent = parent
|
|
|
|
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))
|
|
|
|
|
|
|
|
self.timer = QtCore.QTimer()
|
|
|
|
QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.delayedUpdateStatus)
|
|
|
|
self.timer.start(500) # milliseconds
|
|
|
|
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
|
|
|
|
self.show()
|
|
|
|
|
|
|
|
def delayedUpdateStatus(self):
|
|
|
|
self.chanPassPhrase.validator().checkQueue()
|
|
|
|
|
|
|
|
def accept(self):
|
|
|
|
self.timer.stop()
|
|
|
|
self.hide()
|
|
|
|
apiAddressGeneratorReturnQueue.queue.clear()
|
|
|
|
if self.chanAddress.text().toUtf8() == "":
|
|
|
|
addressGeneratorQueue.put(('createChan', 4, 1, str_chan + ' ' + str(self.chanPassPhrase.text().toUtf8()), self.chanPassPhrase.text().toUtf8(), True))
|
|
|
|
else:
|
|
|
|
addressGeneratorQueue.put(('joinChan', addBMIfNotPresent(self.chanAddress.text().toUtf8()), str_chan + ' ' + str(self.chanPassPhrase.text().toUtf8()), self.chanPassPhrase.text().toUtf8(), True))
|
|
|
|
addressGeneratorReturnValue = apiAddressGeneratorReturnQueue.get(True)
|
|
|
|
if len(addressGeneratorReturnValue) > 0 and addressGeneratorReturnValue[0] != 'chan name does not match address':
|
2017-10-03 17:01:54 +02:00
|
|
|
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):
|
|
|
|
self.timer.stop()
|
|
|
|
self.hide()
|
|
|
|
UISignalQueue.put(('updateStatusBar', _translate("newchandialog", "Chan creation / joining cancelled")))
|
|
|
|
self.done(QtGui.QDialog.Rejected)
|