diff --git a/src/sakia/core/account.py b/src/sakia/core/account.py index 15a20055ba1bb70056c84f9ee35471792a811ee7..386788b2c237e2c2a3b1d51632ba9e78b8a07102 100644 --- a/src/sakia/core/account.py +++ b/src/sakia/core/account.py @@ -61,6 +61,19 @@ class Account(QObject): self._identities_registry = identities_registry self._current_ref = 0 + self.notifications = {'membership_expire_soon': + [ + self.tr("Warning : Your membership is expiring soon."), + 0 + ], + 'warning_certifications': + [ + self.tr("Warning : Your could miss certifications soon."), + 0 + ], + 'warning_certifying_first_time': True, + } + @classmethod def create(cls, name, identities_registry): """ diff --git a/src/sakia/core/app.py b/src/sakia/core/app.py index 877976190e5cfe72de29109c9ddffa3e1026b85b..627d88960f30b6587722dc2b9914214859008731 100644 --- a/src/sakia/core/app.py +++ b/src/sakia/core/app.py @@ -71,18 +71,6 @@ class Application(QObject): 'auto_refresh': False } - self.notifications = {'membership_expire_soon': - [ - self.tr("Warning : Your membership is expiring soon."), - 0 - ], - 'warning_certifications': - [ - self.tr("Warning : Your could miss certifications soon."), - 0 - ] - } - @classmethod def startup(cls, argv, qapp, loop): config.parse_arguments(argv) @@ -204,6 +192,7 @@ class Application(QObject): and stop the coroutines """ self.save_cache(self.current_account) + self.save_notifications(self.current_account) self.current_account.stop_coroutines() def load(self): @@ -261,6 +250,17 @@ class Application(QObject): account.rollback_transaction(self, co)) community.network.root_nodes_changed.connect(lambda acc=account: self.save(acc)) + account_notifications_path = os.path.join(config.parameters['home'], + account_name, '__notifications__') + + try: + with open(account_notifications_path, 'r') as json_data: + data = json.load(json_data) + account.notifications = data + except FileNotFoundError: + logging.debug("Could not find notifications file") + pass + def load_cache(self, account): """ Load an account cache @@ -350,6 +350,18 @@ class Application(QObject): account_path = os.path.join(config.parameters['home'], account.name) shutil.rmtree(account_path) + def save_notifications(self, account): + """ + Save an account notifications + + :param account: The account object to save + """ + account_path = os.path.join(config.parameters['home'], + account.name) + notifications_path = os.path.join(account_path, '__notifications__') + with open(notifications_path, 'w') as outfile: + json.dump(account.notifications, outfile, indent=4, sort_keys=True) + def save_registries(self): """ Save the registries diff --git a/src/sakia/gui/certification.py b/src/sakia/gui/certification.py index 9f5ad92ea3da52c4f0c6d10088b9714d518403ea..bac7688cf17e8a524cac19dc17526b9a2a32c76e 100644 --- a/src/sakia/gui/certification.py +++ b/src/sakia/gui/certification.py @@ -6,7 +6,7 @@ Created on 24 dec. 2014 import asyncio import logging -from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QApplication +from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QApplication, QMessageBox from PyQt5.QtCore import Qt @@ -38,17 +38,27 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): for contact_name in sorted([c['name'] for c in certifier.contacts], key=str.lower): self.combo_contact.addItem(contact_name) + if len(certifier.contacts) == 0: self.radio_pubkey.setChecked(True) self.radio_contact.setEnabled(False) @classmethod async def certify_identity(cls, app, account, password_asker, community, identity): + """ + Certify and identity + :param sakia.core.Application app: the application + :param sakia.core.Account account: the account certifying the identity + :param sakia.gui.password_asker.PasswordAsker password_asker: the password asker + :param sakia.core.Community community: the community + :param sakia.core.registry.Identity identity: the identity certified + :return: + """ dialog = cls(app, account, password_asker) dialog.combo_community.setCurrentText(community.name) dialog.edit_pubkey.setText(identity.pubkey) dialog.radio_pubkey.setChecked(True) - return (await dialog.async_exec()) + return await dialog.async_exec() @asyncify async def accept(self): @@ -113,6 +123,19 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): self.button_box.button(QDialogButtonBox.Ok).setEnabled(False) self.button_box.button(QDialogButtonBox.Ok).setText(self.tr("Not a member")) + def showEvent(self, event): + super().showEvent(event) + self.first_certification_check() + + def first_certification_check(self): + if self.account.notifications['warning_certifying_first_time']: + self.account.notifications['warning_certifying_first_time'] = False + QMessageBox.warning(self, "Certifying individuals", """Please follow the following guidelines : +1.) Don't certify an account if you believe the issuers identity might be faked. +2.) Don't certify an account if you believe the issuer already has another certified account. +3.) Don't certify an account if you believe the issuer purposely or carelessly violates rule 1 or 2 (the issuer certifies faked or double accounts +""") + def recipient_mode_changed(self, pubkey_toggled): self.edit_pubkey.setEnabled(pubkey_toggled) self.combo_contact.setEnabled(not pubkey_toggled) diff --git a/src/sakia/gui/community_view.py b/src/sakia/gui/community_view.py index 5db08b0bb898ec57593cb1ac92cd9937ce34e607..9b243e8a6aa38a3de69d5e31a8c00068aea59cef 100644 --- a/src/sakia/gui/community_view.py +++ b/src/sakia/gui/community_view.py @@ -190,10 +190,10 @@ class CommunityWidget(QWidget, Ui_CommunityWidget): self.status_info.append('membership_expire_soon') if self.app.preferences['notifications'] and\ - self.app.notifications['membership_expire_soon'][1]+24*3600 < time.time(): + self.account.notifications['membership_expire_soon'][1]+24*3600 < time.time(): toast.display(self.tr("Membership expiration"), self.tr("<b>Warning : Membership expiration in {0} days</b>").format(days)) - self.app.notifications['membership_expire_soon'][1] = time.time() + self.account.notifications['membership_expire_soon'][1] = time.time() certifiers_of = await person.unique_valid_certifiers_of(self.app.identities_registry, self.community) @@ -201,12 +201,12 @@ class CommunityWidget(QWidget, Ui_CommunityWidget): if 'warning_certifications' not in self.status_info: self.status_info.append('warning_certifications') if self.app.preferences['notifications'] and\ - self.app.notifications['warning_certifications'][1]+24*3600 < time.time(): + self.account.notifications['warning_certifications'][1]+24*3600 < time.time(): toast.display(self.tr("Certifications number"), self.tr("<b>Warning : You are certified by only {0} persons, need {1}</b>") .format(len(certifiers_of), parameters['sigQty'])) - self.app.notifications['warning_certifications'][1] = time.time() + self.account.notifications['warning_certifications'][1] = time.time() except MembershipNotFoundError as e: pass diff --git a/src/sakia/gui/views/nodes/explorer_node.py b/src/sakia/gui/views/nodes/explorer_node.py index bedc9b9df18957407021d3a5e1058122b7cfa3ac..7f985e91950a9d25c3a4195568cd908892c7d827 100644 --- a/src/sakia/gui/views/nodes/explorer_node.py +++ b/src/sakia/gui/views/nodes/explorer_node.py @@ -3,7 +3,6 @@ from PyQt5.QtCore import Qt, QPointF, QTimeLine, QTimer from PyQt5.QtGui import QTransform, QColor, QPen, QBrush, QRadialGradient from ....core.graph.constants import NodeStatus from .base_node import BaseNode -import logging import math