Beispiel #1
0
 def __init__(self, parent):
     """
     Constructor
     """
     super().__init__(parent)
     self.setupUi(self)
     self.busy = Busy(self.graphics_view)
     self.busy.hide()
Beispiel #2
0
class WotView(BaseGraphView, Ui_WotWidget):
    """
    Wot graph view
    """
    def __init__(self, parent):
        """
        Constructor
        """
        super().__init__(parent)
        self.setupUi(self)
        self.busy = Busy(self.graphics_view)
        self.busy.hide()

    def set_search_user(self, search_user):
        """
        Set the search user view in the gui
        :param sakia.gui.search_user.view.SearchUserView search_user: the view
        :return:
        """
        self.layout().insertWidget(0, search_user)

    def scene(self):
        """
        Get the scene of the underlying graphics view
        :return:
        """
        return self.graphics_view.scene()

    def display_wot(self, nx_graph, identity):
        """
        Display given wot around given identity
        :param nx_graph:
        :param identity:
        :return:
        """
        # draw graph in qt scene
        self.graphics_view.scene().update_wot(nx_graph, identity)

    def resizeEvent(self, event):
        self.busy.resize(event.size())
        super().resizeEvent(event)
Beispiel #3
0
 def __init__(self, parent, app, community):
     super().__init__(parent)
     self.app = app
     self.community = community
     self.community.network.nodes_changed.connect(self.handle_nodes_change)
     self.text_label = QLabel()
     self.setLayout(QVBoxLayout())
     self.layout().setSizeConstraint(QLayout.SetFixedSize)
     self.layout().addWidget(self.text_label)
     self.setFrameShape(QFrame.StyledPanel)
     self.setFrameShadow(QFrame.Raised)
     self.busy = Busy(self)
     self.busy.hide()
     self._state = CommunityState.NOT_INIT
     self.refresh()
Beispiel #4
0
    def __init__(self, app):
        """
        Init
        :param sakia.core.account.Account account: Account instance
        :param sakia.core.community.Community community: Community instance
        :param sakia.gui.password_asker.PasswordAskerDialog password_asker: Password asker dialog
        :return:
        """
        super().__init__()
        self.app = app
        self.community = None
        self.account = None
        self.password_asker = None

        self.members_action = QAction(self.tr(IdentitiesTabWidget._members_action_text), self)
        self.direct_connections = QAction(self.tr(IdentitiesTabWidget._direct_connections_text), self)
        self.setupUi(self)

        identities_model = IdentitiesTableModel()
        proxy = IdentitiesFilterProxyModel()
        proxy.setSourceModel(identities_model)
        self.table_identities.setModel(proxy)
        self.table_identities.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table_identities.customContextMenuRequested.connect(self.identity_context_menu)
        self.table_identities.sortByColumn(0, Qt.AscendingOrder)
        self.table_identities.resizeColumnsToContents()
        identities_model.modelAboutToBeReset.connect(lambda: self.table_identities.setEnabled(False))
        identities_model.modelReset.connect(lambda: self.table_identities.setEnabled(True))

        self.members_action.triggered.connect(self._async_search_members)
        self.button_search.addAction(self.members_action)
        self.direct_connections.triggered.connect(self._async_search_direct_connections)
        self.button_search.addAction(self.direct_connections)
        self.button_search.clicked.connect(self._async_execute_search_text)

        self.busy = Busy(self.table_identities)
        self.busy.hide()
Beispiel #5
0
    def __init__(self, app):
        """
        Init

        :param sakia.core.app.Application app: Application instance
        :return:
        """

        super().__init__()
        self.setupUi(self)
        self.app = app
        self.account = None
        self.community = None
        self.password_asker = None
        self.busy_balance = Busy(self.groupbox_balance)
        self.busy_balance.hide()

        ts_from = self.date_from.dateTime().toTime_t()
        ts_to = self.date_to.dateTime().toTime_t()
        model = HistoryTableModel(self.app, self.account, self.community)
        proxy = TxFilterProxyModel(ts_from, ts_to)
        proxy.setSourceModel(model)
        proxy.setDynamicSortFilter(True)
        proxy.setSortRole(Qt.DisplayRole)

        self.table_history.setModel(proxy)
        self.table_history.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table_history.setSortingEnabled(True)
        self.table_history.horizontalHeader().setSectionResizeMode(QHeaderView.Interactive)
        self.table_history.resizeColumnsToContents()

        model.modelAboutToBeReset.connect(lambda: self.table_history.setEnabled(False))
        model.modelReset.connect(lambda: self.table_history.setEnabled(True))

        self.progressbar.hide()
        self.refresh()
Beispiel #6
0
class CommunityTile(QFrame):
    clicked = pyqtSignal()

    def __init__(self, parent, app, community):
        super().__init__(parent)
        self.app = app
        self.community = community
        self.community.network.nodes_changed.connect(self.handle_nodes_change)
        self.text_label = QLabel()
        self.setLayout(QVBoxLayout())
        self.layout().setSizeConstraint(QLayout.SetFixedSize)
        self.layout().addWidget(self.text_label)
        self.setFrameShape(QFrame.StyledPanel)
        self.setFrameShadow(QFrame.Raised)
        self.busy = Busy(self)
        self.busy.hide()
        self._state = CommunityState.NOT_INIT
        self.refresh()

    def sizeHint(self):
        return QSize(250, 250)

    def handle_nodes_change(self):
        if len(self.community.network.online_nodes) > 0:
            if self.community.network.current_blockid.sha_hash == Block.Empty_Hash:
                state = CommunityState.NOT_INIT
            else:
                state = CommunityState.READY
        else:
            state = CommunityState.OFFLINE

        if state != self._state:
            self.refresh()

    def cancel_refresh(self):
        cancel_once_task(self, self.refresh)

    @once_at_a_time
    @asyncify
    @asyncio.coroutine
    def refresh(self):
        self.busy.show()
        self.setFixedSize(QSize(150, 150))
        try:
            current_block = yield from self.community.get_block()
            members_pubkeys = yield from self.community.members_pubkeys()
            amount = yield from self.app.current_account.amount(self.community)
            localized_amount = yield from self.app.current_account.current_ref(amount,
                                                        self.community, self.app).localized(units=True,
                                            international_system=self.app.preferences['international_system_of_units'])
            if current_block['monetaryMass']:
                localized_monetary_mass = yield from self.app.current_account.current_ref(current_block['monetaryMass'],
                                                        self.community, self.app).localized(units=True,
                                            international_system=self.app.preferences['international_system_of_units'])
            else:
                localized_monetary_mass = ""
            status = self.tr("Member") if self.app.current_account.pubkey in members_pubkeys \
                else self.tr("Non-Member")
            description = """<html>
            <body>
            <p>
            <span style=" font-size:16pt; font-weight:600;">{currency}</span>
            </p>
            <p>{nb_members} {members_label}</p>
            <p><span style=" font-weight:600;">{monetary_mass_label}</span> : {monetary_mass}</p>
            <p><span style=" font-weight:600;">{status_label}</span> : {status}</p>
            <p><span style=" font-weight:600;">{balance_label}</span> : {balance}</p>
            </body>
            </html>""".format(currency=self.community.currency,
                              nb_members=len(members_pubkeys),
                              members_label=self.tr("members"),
                              monetary_mass_label=self.tr("Monetary mass"),
                              monetary_mass=localized_monetary_mass,
                              status_label=self.tr("Status"),
                              status=status,
                              balance_label=self.tr("Balance"),
                              balance=localized_amount)
            self.text_label.setText(description)
            self._state = CommunityState.READY
        except NoPeerAvailable:
            description = """<html>
            <body>
            <p>
            <span style=" font-size:16pt; font-weight:600;">{currency}</span>
            </p>
            <p>{message}</p>
            </body>
            </html>""".format(currency=self.community.currency,
                              message=self.tr("Not connected"))
            self.text_label.setText(description)
            self._state = CommunityState.OFFLINE
        except ValueError as e:
            if '404' in str(e):
                description = """<html>
                <body>
                <p>
                <span style=" font-size:16pt; font-weight:600;">{currency}</span>
                </p>
                <p>{message}</p>
                </body>
                </html>""".format(currency=self.community.currency,
                              message=self.tr("Community not initialized"))
                self.text_label.setText(description)
                self._state = CommunityState.NOT_INIT
            else:
                raise

        self.busy.hide()

    def mousePressEvent(self, event):
        self.clicked.emit()
        return super().mousePressEvent(event)

    def resizeEvent(self, event):
        self.busy.resize(event.size())
        super().resizeEvent(event)

    def enterEvent(self, event):
        self.setStyleSheet("color: rgb(0, 115, 173);")
        return super().enterEvent(event)

    def leaveEvent(self, event):
        self.setStyleSheet("")
        return super().leaveEvent(event)
Beispiel #7
0
class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab):

    """
    classdocs
    """
    view_in_wot = pyqtSignal(Identity)
    money_sent = pyqtSignal()

    _members_action_text = QT_TRANSLATE_NOOP("IdentitiesTabWidget", "Members")
    _direct_connections_text = QT_TRANSLATE_NOOP("IdentitiesTabWidget", "Direct connections")

    def __init__(self, app):
        """
        Init
        :param sakia.core.account.Account account: Account instance
        :param sakia.core.community.Community community: Community instance
        :param sakia.gui.password_asker.PasswordAskerDialog password_asker: Password asker dialog
        :return:
        """
        super().__init__()
        self.app = app
        self.community = None
        self.account = None
        self.password_asker = None

        self.members_action = QAction(self.tr(IdentitiesTabWidget._members_action_text), self)
        self.direct_connections = QAction(self.tr(IdentitiesTabWidget._direct_connections_text), self)
        self.setupUi(self)

        identities_model = IdentitiesTableModel()
        proxy = IdentitiesFilterProxyModel()
        proxy.setSourceModel(identities_model)
        self.table_identities.setModel(proxy)
        self.table_identities.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table_identities.customContextMenuRequested.connect(self.identity_context_menu)
        self.table_identities.sortByColumn(0, Qt.AscendingOrder)
        self.table_identities.resizeColumnsToContents()
        identities_model.modelAboutToBeReset.connect(lambda: self.table_identities.setEnabled(False))
        identities_model.modelReset.connect(lambda: self.table_identities.setEnabled(True))

        self.members_action.triggered.connect(self._async_search_members)
        self.button_search.addAction(self.members_action)
        self.direct_connections.triggered.connect(self._async_search_direct_connections)
        self.button_search.addAction(self.direct_connections)
        self.button_search.clicked.connect(self._async_execute_search_text)

        self.busy = Busy(self.table_identities)
        self.busy.hide()

    def cancel_once_tasks(self):
        cancel_once_task(self, self.identity_context_menu)
        cancel_once_task(self, self._async_execute_search_text)
        cancel_once_task(self, self._async_search_members)
        cancel_once_task(self, self._async_search_direct_connections)
        cancel_once_task(self, self.refresh_identities)

    def change_account(self, account, password_asker):
        self.cancel_once_tasks()
        self.account = account
        self.password_asker = password_asker
        if self.account is None:
            self.community = None

    def change_community(self, community):
        self.cancel_once_tasks()
        self.community = community
        self.table_identities.model().change_community(community)
        self._async_search_direct_connections()

    @once_at_a_time
    @asyncify
    @asyncio.coroutine
    def identity_context_menu(self, point):
        index = self.table_identities.indexAt(point)
        model = self.table_identities.model()
        if index.isValid() and index.row() < model.rowCount():
            source_index = model.mapToSource(index)
            pubkey_col = model.sourceModel().columns_ids.index('pubkey')
            pubkey_index = model.sourceModel().index(source_index.row(),
                                                   pubkey_col)
            pubkey = model.sourceModel().data(pubkey_index, Qt.DisplayRole)
            identity = yield from self.app.identities_registry.future_find(pubkey, self.community)
            menu = QMenu(self)

            informations = QAction(self.tr("Informations"), self)
            informations.triggered.connect(self.menu_informations)
            informations.setData(identity)
            add_contact = QAction(self.tr("Add as contact"), self)
            add_contact.triggered.connect(self.menu_add_as_contact)
            add_contact.setData(identity)

            send_money = QAction(self.tr("Send money"), self)
            send_money.triggered.connect(self.menu_send_money)
            send_money.setData(identity)

            certify = QAction(self.tr("Certify identity"), self)
            certify.triggered.connect(self.menu_certify_member)
            certify.setData(identity)

            view_wot = QAction(self.tr("View in Web of Trust"), self)
            view_wot.triggered.connect(self.view_wot)
            view_wot.setData(identity)

            copy_pubkey = QAction(self.tr("Copy pubkey"), self)
            copy_pubkey.triggered.connect(self.copy_identity_pubkey)
            copy_pubkey.setData(identity)

            menu.addAction(informations)
            menu.addAction(add_contact)
            menu.addAction(send_money)
            menu.addAction(certify)
            menu.addAction(view_wot)
            menu.addAction(copy_pubkey)

            # Show the context menu.
            menu.popup(QCursor.pos())

    def menu_informations(self):
        person = self.sender().data()
        self.identity_informations(person)

    def menu_add_as_contact(self):
        person = self.sender().data()
        self.add_identity_as_contact({'name': person.uid,
                                    'pubkey': person.pubkey})

    def menu_send_money(self):
        person = self.sender().data()
        self.send_money_to_identity(person)

    def menu_certify_member(self):
        person = self.sender().data()
        self.certify_identity(person)

    def identity_informations(self, person):
        dialog = MemberDialog(self.app, self.account, self.community, person)
        dialog.exec_()

    def add_identity_as_contact(self, person):
        dialog = ConfigureContactDialog(self.account, self.window(), person)
        result = dialog.exec_()
        if result == QDialog.Accepted:
            self.window().refresh_contacts()

    @asyncify
    @asyncio.coroutine
    def send_money_to_identity(self, identity):
        result = yield from TransferMoneyDialog.send_money_to_identity(self.app, self.account, self.password_asker,
                                                            self.community, identity)
        if result == QDialog.Accepted:
            self.money_sent.emit()

    @asyncify
    @asyncio.coroutine
    def certify_identity(self, identity):
        yield from CertificationDialog.certify_identity(self.app, self.account, self.password_asker,
                                             self.community, identity)

    def copy_identity_pubkey(self):
        """
        Copy the identity pubkey to the clipboard

        :param sakia.core.registry.Identity identity: The identity
        """
        identity = self.sender().data()
        cb = self.app.qapp.clipboard()
        cb.clear(mode=cb.Clipboard)
        cb.setText(identity.pubkey, mode=cb.Clipboard)

    def view_wot(self):
        identity = self.sender().data()
        self.view_in_wot.emit(identity)

    @once_at_a_time
    @asyncify
    @asyncio.coroutine
    def _async_execute_search_text(self, checked):
        cancel_once_task(self, self._async_search_members)
        cancel_once_task(self, self._async_search_direct_connections)

        self.busy.show()
        text = self.edit_textsearch.text()
        if len(text) < 2:
            return
        try:
            response = yield from self.community.bma_access.future_request(bma.wot.Lookup, {'search': text})
            identities = []
            for identity_data in response['results']:
                for uid_data in identity_data['uids']:
                    identity = Identity.from_handled_data(uid_data['uid'],
                                                         identity_data['pubkey'],
                                                         uid_data['meta']['timestamp'],
                                                         BlockchainState.BUFFERED)
                    identities.append(identity)

            self.edit_textsearch.clear()
            yield from self.refresh_identities(identities)
        except ValueError as e:
            logging.debug(str(e))
        finally:
            self.busy.hide()

    @once_at_a_time
    @asyncify
    @asyncio.coroutine
    def _async_search_members(self, checked=False):
        """
        Search members of community and display found members
        """
        cancel_once_task(self, self._async_execute_search_text)
        cancel_once_task(self, self._async_search_direct_connections)

        if self.community:
            self.busy.show()
            pubkeys = yield from self.community.members_pubkeys()
            identities = []
            for p in pubkeys:
                identity = yield from self.app.identities_registry.future_find(p, self.community)
                identities.append(identity)

            self.edit_textsearch.clear()
            yield from self.refresh_identities(identities)
            self.busy.hide()

    @once_at_a_time
    @asyncify
    @asyncio.coroutine
    def _async_search_direct_connections(self, checked=False):
        """
        Search members of community and display found members
        """
        cancel_once_task(self, self._async_search_members)
        cancel_once_task(self, self._async_execute_search_text)

        if self.account and self.community:
            try:
                yield from self.refresh_identities([])
                self.busy.show()
                self_identity = yield from self.account.identity(self.community)
                account_connections = []
                certs_of = yield from self_identity.unique_valid_certifiers_of(self.app.identities_registry, self.community)
                for p in certs_of:
                    account_connections.append(p['identity'])
                certifiers_of = [p for p in account_connections]
                certs_by = yield from self_identity.unique_valid_certified_by(self.app.identities_registry, self.community)
                for p in certs_by:
                    account_connections.append(p['identity'])
                certified_by = [p for p in account_connections
                          if p.pubkey not in [i.pubkey for i in certifiers_of]]
                identities = certifiers_of + certified_by
                self.busy.hide()
                yield from self.refresh_identities(identities)
            except NoPeerAvailable:
                self.busy.hide()

    @asyncio.coroutine
    def refresh_identities(self, identities):
        """
        Refresh the table with specified identities.
        If no identities is passed, use the account connections.
        """
        yield from self.table_identities.model().sourceModel().refresh_identities(identities)
        self.table_identities.resizeColumnsToContents()

    def retranslateUi(self, widget):
        self.members_action.setText(self.tr(IdentitiesTabWidget._members_action_text))
        self.direct_connections.setText(self.tr(IdentitiesTabWidget._direct_connections_text))
        super().retranslateUi(self)

    def resizeEvent(self, event):
        self.busy.resize(event.size())
        super().resizeEvent(event)

    def changeEvent(self, event):
        """
        Intercepte LanguageChange event to translate UI
        :param QEvent QEvent: Event
        :return:
        """
        if event.type() == QEvent.LanguageChange:
            self.retranslateUi(self)
        return super(IdentitiesTabWidget, self).changeEvent(event)
Beispiel #8
0
class UserInformationView(QWidget, Ui_UserInformationWidget):
    """
    User information view
    """

    def __init__(self, parent):
        """
        Constructor
        """
        super().__init__(parent)
        self.setupUi(self)
        self.busy = Busy(self)
        self.busy.hide()

    def display_identity_timestamps(self, pubkey, publish_time, join_date,
                                    mstime_remaining, nb_certs):
        """
        Display identity timestamps in localized format
        :param str pubkey:
        :param int publish_time:
        :param int join_date:
        :return:
        """
        if join_date:
            localized_join_date = QLocale.toString(
                QLocale(),
                QDateTime.fromTime_t(join_date),
                QLocale.dateTimeFormat(QLocale(), QLocale.ShortFormat)
            )
        else:
            localized_join_date = "###"

        if publish_time:
            localized_publish_date = QLocale.toString(
                QLocale(),
                QDateTime.fromTime_t(publish_time),
                QLocale.dateTimeFormat(QLocale(), QLocale.ShortFormat)
            )
        else:
            localized_publish_date = "###"

        if mstime_remaining:
            days, remainder = divmod(mstime_remaining, 3600 * 24)
            hours, remainder = divmod(remainder, 3600)
            minutes, seconds = divmod(remainder, 60)
            if days > 0:
                localized_mstime_remaining = "{days} days".format(days=days)
            else:
                localized_mstime_remaining = "{hours} hours and {min} min.".format(hours=hours,
                                                                               min=minutes)
        else:
            localized_mstime_remaining = "###"


        text = self.tr("""
            <table cellpadding="5">
            <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr>
            <tr><td align="right"><b>{:}</b></td><td>{:} BAT</td></tr>
            <tr><td align="right"><b>{:}</b></td><td>{:} BAT</td></tr>
            <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr>
            <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr>
            """).format(
            self.tr('Public key'),
            pubkey,
            self.tr('UID Published on'),
            localized_publish_date,
            self.tr('Join date'),
            localized_join_date,
            self.tr("Expires in"),
            localized_mstime_remaining,
            self.tr("Certs. received"),
            nb_certs
        )

        # close html text
        text += "</table>"

        # set text in label
        self.label_properties.setText(text)

    def display_uid(self, uid, member):
        """
        Display the uid in the label
        :param str uid:
        """
        status_label = self.tr("Member") if member else self.tr("Non-Member")
        status_color = '#00AA00' if member else self.tr('#FF0000')
        text = "<b>{uid}</b> <p style='color: {status_color};'>({status_label})</p>".format(
            uid=uid, status_color=status_color, status_label=status_label
        )
        self.label_uid.setText(text)

    def show_busy(self):
        self.busy.show()

    def hide_busy(self):
        self.busy.hide()

    def clear(self):
        self.label_properties.setText("")
        self.label_uid.setText("")

    def resizeEvent(self, event):
        self.busy.resize(event.size())
        super().resizeEvent(event)
Beispiel #9
0
class TransactionsTabWidget(QWidget, Ui_transactionsTabWidget):
    """
    classdocs
    """
    view_in_wot = pyqtSignal(Identity)

    def __init__(self, app):
        """
        Init

        :param sakia.core.app.Application app: Application instance
        :return:
        """

        super().__init__()
        self.setupUi(self)
        self.app = app
        self.account = None
        self.community = None
        self.password_asker = None
        self.busy_balance = Busy(self.groupbox_balance)
        self.busy_balance.hide()

        ts_from = self.date_from.dateTime().toTime_t()
        ts_to = self.date_to.dateTime().toTime_t()
        model = HistoryTableModel(self.app, self.account, self.community)
        proxy = TxFilterProxyModel(ts_from, ts_to)
        proxy.setSourceModel(model)
        proxy.setDynamicSortFilter(True)
        proxy.setSortRole(Qt.DisplayRole)

        self.table_history.setModel(proxy)
        self.table_history.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table_history.setSortingEnabled(True)
        self.table_history.horizontalHeader().setSectionResizeMode(QHeaderView.Interactive)
        self.table_history.resizeColumnsToContents()

        model.modelAboutToBeReset.connect(lambda: self.table_history.setEnabled(False))
        model.modelReset.connect(lambda: self.table_history.setEnabled(True))

        self.progressbar.hide()
        self.refresh()

    def cancel_once_tasks(self):
        cancel_once_task(self, self.refresh_minimum_maximum)
        cancel_once_task(self, self.refresh_balance)
        cancel_once_task(self, self.history_context_menu)

    def change_account(self, account, password_asker):
        self.cancel_once_tasks()
        self.account = account
        self.password_asker = password_asker
        self.table_history.model().sourceModel().change_account(account)
        if account:
            self.connect_progress()

    def change_community(self, community):
        self.cancel_once_tasks()
        self.community = community
        self.progressbar.hide()
        self.table_history.model().sourceModel().change_community(self.community)
        self.refresh()

    @once_at_a_time
    @asyncify
    @asyncio.coroutine
    def refresh_minimum_maximum(self):
        try:
            block = yield from self.community.get_block(1)
            minimum_datetime = QDateTime()
            minimum_datetime.setTime_t(block['medianTime'])
            minimum_datetime.setTime(QTime(0, 0))

            self.date_from.setMinimumDateTime(minimum_datetime)
            self.date_from.setDateTime(minimum_datetime)
            self.date_from.setMaximumDateTime(QDateTime().currentDateTime())

            self.date_to.setMinimumDateTime(minimum_datetime)
            tomorrow_datetime = QDateTime().currentDateTime().addDays(1)
            self.date_to.setDateTime(tomorrow_datetime)
            self.date_to.setMaximumDateTime(tomorrow_datetime)
        except NoPeerAvailable as e:
            logging.debug(str(e))
        except ValueError as e:
            logging.debug(str(e))

    def refresh(self):
        if self.community:
            self.table_history.model().sourceModel().refresh_transfers()
            self.table_history.resizeColumnsToContents()
            self.refresh_minimum_maximum()
            self.refresh_balance()

    def connect_progress(self):
        def progressing(community, value, maximum):
            if community == self.community:
                self.progressbar.show()
                self.progressbar.setValue(value)
                self.progressbar.setMaximum(maximum)
        self.account.loading_progressed.connect(progressing)
        self.account.loading_finished.connect(self.stop_progress)

    def stop_progress(self, community, received_list):
        if community == self.community:
            self.progressbar.hide()
            self.table_history.model().sourceModel().refresh_transfers()
            self.table_history.resizeColumnsToContents()
            self.notification_reception(received_list)

    @asyncify
    @asyncio.coroutine
    def notification_reception(self, received_list):
        if len(received_list) > 0:
            amount = 0
            for r in received_list:
                amount += r.metadata['amount']
            localized_amount = yield from self.app.current_account.current_ref(amount, self.community, self.app)\
                                            .localized(units=True,
                                    international_system=self.app.preferences['international_system_of_units'])
            text = self.tr("Received {amount} from {number} transfers").format(amount=localized_amount ,
                                                                            number=len(received_list))
            if self.app.preferences['notifications']:
                toast.display(self.tr("New transactions received"), text)

    @once_at_a_time
    @asyncify
    @asyncio.coroutine
    def refresh_balance(self):
        self.busy_balance.show()
        amount = yield from self.app.current_account.amount(self.community)
        localized_amount = yield from self.app.current_account.current_ref(amount, self.community,
                                                                           self.app).localized(units=True,
                                        international_system=self.app.preferences['international_system_of_units'])

        # set infos in label
        self.label_balance.setText(
            self.tr("{:}")
            .format(
                localized_amount
            )
        )
        self.busy_balance.hide()

    @once_at_a_time
    @asyncify
    @asyncio.coroutine
    def history_context_menu(self, point):
        index = self.table_history.indexAt(point)
        model = self.table_history.model()
        if index.isValid() and index.row() < model.rowCount(QModelIndex()):
            menu = QMenu(self.tr("Actions"), self)
            source_index = model.mapToSource(index)
            state_col = model.sourceModel().columns_types.index('state')
            state_index = model.sourceModel().index(source_index.row(),
                                                   state_col)
            state_data = model.sourceModel().data(state_index, Qt.DisplayRole)

            pubkey_col = model.sourceModel().columns_types.index('pubkey')
            pubkey_index = model.sourceModel().index(source_index.row(),
                                                    pubkey_col)
            pubkey = model.sourceModel().data(pubkey_index, Qt.DisplayRole)
            identity = yield from self.app.identities_registry.future_find(pubkey, self.community)

            transfer = model.sourceModel().transfers()[source_index.row()]
            if state_data == TransferState.REFUSED or state_data == TransferState.TO_SEND:
                send_back = QAction(self.tr("Send again"), self)
                send_back.triggered.connect(lambda checked, tr=transfer: self.send_again(checked, tr))
                send_back.setData(transfer)
                menu.addAction(send_back)

                cancel = QAction(self.tr("Cancel"), self)
                cancel.triggered.connect(self.cancel_transfer)
                cancel.setData(transfer)
                menu.addAction(cancel)
            else:
                if isinstance(identity, Identity):
                    informations = QAction(self.tr("Informations"), self)
                    informations.triggered.connect(self.menu_informations)
                    informations.setData(identity)
                    menu.addAction(informations)

                    add_as_contact = QAction(self.tr("Add as contact"), self)
                    add_as_contact.triggered.connect(self.menu_add_as_contact)
                    add_as_contact.setData(identity)
                    menu.addAction(add_as_contact)

                send_money = QAction(self.tr("Send money"), self)
                send_money.triggered.connect(self.menu_send_money)
                send_money.setData(identity)
                menu.addAction(send_money)

                if isinstance(identity, Identity):
                    view_wot = QAction(self.tr("View in Web of Trust"), self)
                    view_wot.triggered.connect(self.view_wot)
                    view_wot.setData(identity)
                    menu.addAction(view_wot)

            copy_pubkey = QAction(self.tr("Copy pubkey to clipboard"), self)
            copy_pubkey.triggered.connect(self.copy_pubkey_to_clipboard)
            copy_pubkey.setData(identity)
            menu.addAction(copy_pubkey)

            # Show the context menu.
            menu.popup(QCursor.pos())

    def copy_pubkey_to_clipboard(self):
        data = self.sender().data()
        clipboard = QApplication.clipboard()
        if data.__class__ is Wallet:
            clipboard.setText(data.pubkey)
        elif data.__class__ is Identity:
            clipboard.setText(data.pubkey)
        elif data.__class__ is str:
            clipboard.setText(data)

    def menu_informations(self):
        person = self.sender().data()
        self.identity_informations(person)

    def menu_add_as_contact(self):
        person = self.sender().data()
        self.add_identity_as_contact({'name': person.uid,
                                    'pubkey': person.pubkey})

    def menu_send_money(self):
        identity = self.sender().data()
        self.send_money_to_identity(identity)

    def identity_informations(self, person):
        dialog = MemberDialog(self.app, self.account, self.community, person)
        dialog.exec_()

    def add_identity_as_contact(self, person):
        dialog = ConfigureContactDialog(self.account, self.window(), person)
        result = dialog.exec_()
        if result == QDialog.Accepted:
            self.window().refresh_contacts()

    @asyncify
    @asyncio.coroutine
    def send_money_to_identity(self, identity):
        yield from TransferMoneyDialog.send_money_to_identity(self.app, self.account, self.password_asker,
                                                            self.community, identity)
        self.table_history.model().sourceModel().refresh_transfers()

    @asyncify
    @asyncio.coroutine
    def certify_identity(self, identity):
        yield from CertificationDialog.certify_identity(self.app, self.account, self.password_asker,
                                             self.community, identity)

    def view_wot(self):
        identity = self.sender().data()
        self.view_in_wot.emit(identity)

    @asyncify
    @asyncio.coroutine
    def send_again(self, checked=False, transfer=None):
        result = yield from TransferMoneyDialog.send_transfer_again(self.app, self.app.current_account,
                                     self.password_asker, self.community, transfer)
        self.table_history.model().sourceModel().refresh_transfers()

    def cancel_transfer(self):
        reply = QMessageBox.warning(self, self.tr("Warning"),
                             self.tr("""Are you sure ?
This money transfer will be removed and not sent."""),
QMessageBox.Ok | QMessageBox.Cancel)
        if reply == QMessageBox.Ok:
            transfer = self.sender().data()
            transfer.cancel()
            self.table_history.model().sourceModel().refresh_transfers()

    def dates_changed(self):
        logging.debug("Changed dates")
        if self.table_history.model():
            qdate_from = self.date_from
            qdate_from.setTime(QTime(0, 0, 0))
            qdate_to = self.date_to
            qdate_to.setTime(QTime(0, 0, 0))
            ts_from = qdate_from.dateTime().toTime_t()
            ts_to = qdate_to.dateTime().toTime_t()

            self.table_history.model().set_period(ts_from, ts_to)

            self.refresh_balance()

    def resizeEvent(self, event):
        self.busy_balance.resize(event.size())
        super().resizeEvent(event)

    def changeEvent(self, event):
        """
        Intercepte LanguageChange event to translate UI
        :param QEvent QEvent: Event
        :return:
        """
        if event.type() == QEvent.LanguageChange:
            self.retranslateUi(self)
            self.refresh()
        return super(TransactionsTabWidget, self).changeEvent(event)