def go(self, code): self.reset() self.invite_code_widget.hide() self.progressbar.show() if self.invite_code_widget.tor_checkbox.isChecked(): use_tor = True self.tor_label.show() self.progressbar.setStyleSheet( 'QProgressBar::chunk {{ background-color: {}; }}'.format( TOR_PURPLE)) else: use_tor = False self.update_progress("Verifying invitation...") # 1 self.invite_receiver = InviteReceiver(self.gateways, use_tor) self.invite_receiver.got_welcome.connect(self.got_welcome) self.invite_receiver.got_message.connect(self.got_message) self.invite_receiver.grid_already_joined.connect( self.on_grid_already_joined) self.invite_receiver.update_progress.connect(self.update_progress) self.invite_receiver.got_icon.connect(self.on_got_icon) self.invite_receiver.joined_folders.connect(self.set_joined_folders) self.invite_receiver.done.connect(self.on_done) d = self.invite_receiver.receive(code) d.addErrback(self.handle_failure) reactor.callLater(30, d.cancel)
def go(self, code, settings=None): if self.tor_checkbox.isChecked(): self.use_tor = True self.page_2.tor_label.show() self.progressbar.setStyleSheet( "QProgressBar::chunk {{ background-color: {}; }}".format( TOR_PURPLE)) self.setCurrentIndex(1) self.progressbar.setValue(1) self.update_progress("Verifying invitation code...") invite_receiver = InviteReceiver(self.known_gateways, self.use_tor) invite_receiver.grid_already_joined.connect(self.on_already_joined) invite_receiver.update_progress.connect(self.update_progress) invite_receiver.got_icon.connect(self.load_service_icon) invite_receiver.client_started.connect( lambda gateway: self.gui.populate([gateway])) invite_receiver.done.connect(self.on_done) d = invite_receiver.receive(code, settings) d.addErrback(self.handle_failure) reactor.callLater(30, d.cancel)
class InviteReceiverDialog(QDialog): done = pyqtSignal(object) # Tahoe gateway closed = pyqtSignal(QWidget) def __init__(self, gateways): super(InviteReceiverDialog, self).__init__() self.gateways = gateways self.invite_receiver = None self.joined_folders = [] self.setMinimumSize(500, 300) self.mail_closed_icon = QLabel() self.mail_closed_icon.setPixmap( QPixmap(resource('mail-envelope-closed.png')).scaled(128, 128)) self.mail_closed_icon.setAlignment(Qt.AlignCenter) self.mail_open_icon = QLabel() self.mail_open_icon.setPixmap( QPixmap(resource('mail-envelope-open.png')).scaled(128, 128)) self.mail_open_icon.setAlignment(Qt.AlignCenter) self.folder_icon = QLabel() icon = QFileIconProvider().icon(QFileInfo(config_dir)) self.folder_icon.setPixmap(icon.pixmap(128, 128)) self.folder_icon.setAlignment(Qt.AlignCenter) self.invite_code_widget = InviteCodeWidget(self) self.invite_code_widget.lineedit.go.connect(self.go) # XXX self.tor_label = QLabel() self.tor_label.setToolTip( "This connection is being routed through the Tor network.") self.tor_label.setPixmap( QPixmap(resource('tor-onion.png')).scaled(24, 24, Qt.KeepAspectRatio, Qt.SmoothTransformation)) self.checkmark = QLabel() self.checkmark.setAlignment(Qt.AlignCenter) self.checkmark.setPixmap( QPixmap(resource('green_checkmark.png')).scaled(32, 32)) self.progressbar = QProgressBar(self) self.progressbar.setValue(0) self.progressbar.setMaximum(6) # XXX self.progressbar.setTextVisible(False) self.message_label = QLabel(' ') self.message_label.setStyleSheet("color: grey") self.message_label.setAlignment(Qt.AlignCenter) self.error_label = QLabel() self.error_label.setStyleSheet("color: red") self.error_label.setAlignment(Qt.AlignCenter) self.close_button = QPushButton("Close") self.close_button.clicked.connect(self.close) layout = QGridLayout(self) layout.addItem(QSpacerItem(0, 0, 0, QSizePolicy.Expanding), 0, 0) layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, 0), 1, 1) layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, 0), 1, 2) layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, 0), 1, 3) layout.addWidget(self.mail_closed_icon, 1, 2, 1, 3) layout.addWidget(self.mail_open_icon, 1, 2, 1, 3) layout.addWidget(self.folder_icon, 1, 2, 1, 3) layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, 0), 1, 4) layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, 0), 1, 5) layout.addWidget(self.invite_code_widget, 2, 2, 1, 3) layout.addWidget(self.checkmark, 2, 3, 1, 1) layout.addWidget(self.tor_label, 3, 1, 1, 1, Qt.AlignRight | Qt.AlignVCenter) layout.addWidget(self.progressbar, 3, 2, 1, 3) layout.addWidget(self.message_label, 5, 1, 1, 5) layout.addWidget(self.error_label, 5, 2, 1, 3) layout.addWidget(self.close_button, 6, 3) layout.addItem(QSpacerItem(0, 0, 0, QSizePolicy.Expanding), 7, 1) self.reset() def reset(self): self.mail_open_icon.hide() self.folder_icon.hide() self.mail_closed_icon.show() self.progressbar.hide() self.error_label.setText('') self.error_label.hide() self.close_button.hide() self.tor_label.hide() self.checkmark.hide() self.progressbar.setStyleSheet('') def show_error(self, text): self.error_label.setText(text) self.message_label.hide() self.error_label.show() reactor.callLater(3, self.error_label.hide) reactor.callLater(3, self.message_label.show) def update_progress(self, message): step = self.progressbar.value() + 1 self.progressbar.setValue(step) self.message_label.setText(message) if step == 3: self.mail_closed_icon.hide() self.mail_open_icon.show() def set_joined_folders(self, folders): self.joined_folders = folders if folders: self.mail_open_icon.hide() self.folder_icon.show() def on_got_icon(self, path): self.mail_open_icon.setPixmap(QPixmap(path).scaled(128, 128)) self.mail_closed_icon.hide() self.mail_open_icon.show() def on_done(self, gateway): self.progressbar.setValue(self.progressbar.maximum()) self.close_button.show() self.checkmark.show() self.done.emit(gateway) if self.joined_folders and len(self.joined_folders) == 1: target = self.joined_folders[0] self.message_label.setText( 'Successfully joined folder "{0}"!\n"{0}" is now available ' 'for download'.format(target)) elif self.joined_folders: target = humanized_list(self.joined_folders, 'folders') self.message_label.setText( 'Successfully joined {0}!\n{0} are now available for ' 'download'.format(target)) self.close() # TODO: Cleanup def on_grid_already_joined(self, grid_name): QMessageBox.information( self, "Already connected", 'You are already connected to "{}"'.format(grid_name)) self.close() def got_message(self, _): self.update_progress("Reading invitation...") # 3 def got_welcome(self): self.update_progress("Connected; waiting for message...") # 2 def handle_failure(self, failure): logging.error(str(failure)) if failure.type == CancelledError and self.progressbar.value() > 2: return show_failure(failure, self) self.close() def go(self, code): self.reset() self.invite_code_widget.hide() self.progressbar.show() if self.invite_code_widget.tor_checkbox.isChecked(): use_tor = True self.tor_label.show() self.progressbar.setStyleSheet( 'QProgressBar::chunk {{ background-color: {}; }}'.format( TOR_PURPLE)) else: use_tor = False self.update_progress("Verifying invitation...") # 1 self.invite_receiver = InviteReceiver(self.gateways, use_tor) self.invite_receiver.got_welcome.connect(self.got_welcome) self.invite_receiver.got_message.connect(self.got_message) self.invite_receiver.grid_already_joined.connect( self.on_grid_already_joined) self.invite_receiver.update_progress.connect(self.update_progress) self.invite_receiver.got_icon.connect(self.on_got_icon) self.invite_receiver.joined_folders.connect(self.set_joined_folders) self.invite_receiver.done.connect(self.on_done) d = self.invite_receiver.receive(code) d.addErrback(self.handle_failure) reactor.callLater(30, d.cancel) def enterEvent(self, event): event.accept() self.invite_code_widget.lineedit.update_action_button() # XXX def closeEvent(self, event): event.accept() try: self.invite_receiver.cancel() except AttributeError: pass self.closed.emit(self) def keyPressEvent(self, event): if event.key() == Qt.Key_Escape: self.close()