diff --git a/res/ui/preferences.ui b/res/ui/preferences.ui index a00cfadfb47d845d9a426cfc29abb2d80652a4c7..f4af53d09b701235bf8bff4706e420d2b42b2313 100644 --- a/res/ui/preferences.ui +++ b/res/ui/preferences.ui @@ -242,6 +242,33 @@ </item> </layout> </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_8"> + <property name="topMargin"> + <number>6</number> + </property> + <item> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QCheckBox" name="checkbox_notifications"> + <property name="text"> + <string>Enable notifications</string> + </property> + </widget> + </item> + </layout> + </item> <item> <spacer name="verticalSpacer_2"> <property name="orientation"> diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py index d7111fa8819576f0325fa7899b61700c1f8525ad..7ba205acc8397ca894c3f87e87dd7693cd7ba159 100644 --- a/src/cutecoin/core/account.py +++ b/src/cutecoin/core/account.py @@ -427,13 +427,15 @@ class Account(QObject): strdata = bytes(reply.readAll()).decode('utf-8') logging.debug("Received reply : {0} : {1}".format(reply.error(), strdata)) if reply.error() == QNetworkReply.NoError: - self.selfcert_broadcasted.emit() for r in replies: try: r.disconnect() except TypeError as e: if "disconnect()" in str(e): logging.debug("Could not disconnect a reply") + else: + raise + self.selfcert_broadcasted.emit() else: for r in replies: if not r.isFinished() or r.error() == QNetworkReply.NoError: @@ -480,13 +482,15 @@ class Account(QObject): strdata = bytes(reply.readAll()).decode('utf-8') logging.debug("Received reply : {0} : {1}".format(reply.error(), strdata)) if reply.error() == QNetworkReply.NoError: - self.membership_broadcasted.emit() for r in replies: try: r.disconnect() except TypeError as e: if "disconnect()" in str(e): logging.debug("Could not disconnect a reply") + else: + raise + self.membership_broadcasted.emit() else: for r in replies: if not r.isFinished() or r.error() == QNetworkReply.NoError: @@ -535,13 +539,15 @@ class Account(QObject): strdata = bytes(reply.readAll()).decode('utf-8') logging.debug("Received reply : {0} : {1}".format(reply.error(), strdata)) if reply.error() == QNetworkReply.NoError: - self.certification_broadcasted.emit() for r in replies: try: r.disconnect() except TypeError as e: if "disconnect()" in str(e): logging.debug("Could not disconnect a reply") + else: + raise + self.certification_broadcasted.emit() else: for r in replies: if not r.isFinished() or r.error() == QNetworkReply.NoError: @@ -589,13 +595,15 @@ class Account(QObject): strdata = bytes(reply.readAll()).decode('utf-8') logging.debug("Received reply : {0} : {1}".format(reply.error(), strdata)) if reply.error() == QNetworkReply.NoError: - self.revoke_broadcasted.emit() for r in replies: try: r.disconnect() except TypeError as e: if "disconnect()" in str(e): logging.debug("Could not disconnect a reply") + else: + raise + self.revoke_broadcasted.emit() else: for r in replies: if not r.isFinished() or r.error() == QNetworkReply.NoError: diff --git a/src/cutecoin/core/app.py b/src/cutecoin/core/app.py index dae6046b05f112a4a9e691fcefa1f4a156b533ae..7b8195377cd8740a65aa63716ba1e11fe979d96d 100644 --- a/src/cutecoin/core/app.py +++ b/src/cutecoin/core/app.py @@ -54,7 +54,8 @@ class Application(QObject): 'ref': 0, 'expert_mode': False, 'digits_after_comma': 6, - 'maximized': False + 'maximized': False, + 'notifications': True } @classmethod diff --git a/src/cutecoin/gui/certification.py b/src/cutecoin/gui/certification.py index 25f860710127a02bf4cc545a0fcf874d251efae9..1ef4d400f4af4bb1f509ae0bab5491399fcb903c 100644 --- a/src/cutecoin/gui/certification.py +++ b/src/cutecoin/gui/certification.py @@ -62,7 +62,10 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): @pyqtSlot(int, str) def handle_error(self, error_code, text): - toast.display(self.tr("Error"), self.tr("{0} : {1}".format(error_code, text))) + if self.app.preferences['notifications']: + toast.display(self.tr("Error"), self.tr("{0} : {1}".format(error_code, text))) + else: + QMessageBox.Critical(self, self.tr("Error", self.tr("{0} : {1}".format(error_code, text)))) self.account.certification_broadcasted.disconnect() self.account.broadcast_error.disconnect(self.handle_error) QApplication.restoreOverrideCursor() diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py index 89717f7dc504e5f83a132d280ee2589f244c2583..ae672340d2c7fbe3f5b2bc9f808fc04f2cae3bec 100644 --- a/src/cutecoin/gui/community_tab.py +++ b/src/cutecoin/gui/community_tab.py @@ -66,17 +66,29 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): self.account.identity(self.community).inner_data_changed.connect(self.handle_account_identity_change) self.search_direct_connections() - self.account.membership_broadcasted.connect(lambda: - toast.display(self.tr("Membership"), - self.tr("Success sending Membership demand"))) - self.account.revoke_broadcasted.connect(lambda: - toast.display(self.tr("Revoke"), - self.tr("Success sending Revoke demand"))) - self.account.selfcert_broadcasted.connect(lambda: - toast.display(self.tr("Self Certification"), - self.tr("Success sending Self Certification document"))) + self.account.membership_broadcasted.connect(self.handle_membership_broadcasted) + self.account.revoke_broadcasted.connect(self.handle_revoke_broadcasted) + self.account.selfcert_broadcasted.connect(self.handle_selfcert_broadcasted) self.refresh_quality_buttons() + def handle_membership_broadcasted(self): + if self.app.preferences['notifications']: + toast.display(self.tr("Membership"), self.tr("Success sending Membership demand")) + else: + QMessageBox.information(self, self.tr("Membership"), self.tr("Success sending Membership demand")) + + def handle_revoke_broadcasted(self): + if self.app.preferences['notifications']: + toast.display(self.tr("Revoke"), self.tr("Success sending Revoke demand")) + else: + QMessageBox.information(self, self.tr("Revoke"), self.tr("Success sending Revoke demand")) + + def handle_selfcert_broadcasted(self): + if self.app.preferences['notifications']: + toast.display(self.tr("Self Certification"), self.tr("Success sending Self Certification document")) + else: + QMessageBox.information(self.tr("Self Certification"), self.tr("Success sending Self Certification document")) + def identity_context_menu(self, point): index = self.table_identities.indexAt(point) model = self.table_identities.model() diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index 8f62ea386f51f311cf5f5215161fa80c6a8bab59..e59049623b92b4c42dc3f694b743ab4f3b215148 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -118,12 +118,16 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): days = int(expiration_time / 3600 / 24) if days > 0: self.status_info.append('membership_expire_soon') - toast.display(self.tr("Membership expiration"), + + if self.app.preferences['notifications']: + toast.display(self.tr("Membership expiration"), self.tr("<b>Warning : Membership expiration in {0} days</b>").format(days)) + certifiers_of = person.unique_valid_certifiers_of(self.community) if len(certifiers_of) < self.community.parameters['sigQty']: self.status_info.append('warning_certifications') - toast.display(self.tr("Certifications number"), + if self.app.preferences['notifications']: + toast.display(self.tr("Certifications number"), self.tr("<b>Warning : You are certified by only {0} persons, need {1}</b>") .format(len(certifiers_of), self.community.parameters['sigQty'])) diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py index a9c5f5e2dda5e0ccbcba65583cf6650504b74ab8..d991775e06602eccfed4554371b5a9002887573f 100644 --- a/src/cutecoin/gui/mainwindow.py +++ b/src/cutecoin/gui/mainwindow.py @@ -227,7 +227,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): .format(version=latest[1]) version_url = latest[2] - toast.display("Cutecoin", """<p>{version_info}</br> + if self.app.preferences['notifications']: + toast.display("Cutecoin", """<p>{version_info}</br> <a href={version_url}>Download link</a></p>""".format( version_info=version_info, version_url=version_url)) diff --git a/src/cutecoin/gui/preferences.py b/src/cutecoin/gui/preferences.py index 6a1e5320c10122ca0d799890c7ebc98e617c5c41..902b5d624fdb16d45a6bc7dc6d7c4c4f6f08ff0f 100644 --- a/src/cutecoin/gui/preferences.py +++ b/src/cutecoin/gui/preferences.py @@ -40,6 +40,7 @@ class PreferencesDialog(QDialog, Ui_PreferencesDialog): self.combo_language.setCurrentText(self.app.preferences['lang']) self.checkbox_expertmode.setChecked(self.app.preferences['expert_mode']) self.checkbox_maximize.setChecked(self.app.preferences['maximized']) + self.checkbox_notifications.setChecked(self.app.preferences['notifications']) self.spinbox_digits_comma.setValue(self.app.preferences['digits_after_comma']) self.spinbox_digits_comma.setMaximum(12) self.spinbox_digits_comma.setMinimum(1) @@ -53,7 +54,8 @@ class PreferencesDialog(QDialog, Ui_PreferencesDialog): 'ref': self.combo_referential.currentIndex(), 'expert_mode': self.checkbox_expertmode.isChecked(), 'maximized': self.checkbox_maximize.isChecked(), - 'digits_after_comma': self.spinbox_digits_comma.value()} + 'digits_after_comma': self.spinbox_digits_comma.value(), + 'notifications': self.checkbox_notifications.isChecked()} self.app.save_preferences(pref) toast.display(self.tr("Preferences"), self.tr("A restart is needed to apply your new preferences.")) diff --git a/src/cutecoin/gui/process_cfg_community.py b/src/cutecoin/gui/process_cfg_community.py index 6ebd82b5f0d38bd4426085df9d0865275a33cad4..993b6e57eeffc5d5871b76ec6ec35d02052840cb 100644 --- a/src/cutecoin/gui/process_cfg_community.py +++ b/src/cutecoin/gui/process_cfg_community.py @@ -101,10 +101,10 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): """ Constructor - :type app: cutecoin.core.App - :type account: cutecoin.core.Account - :type community: cutecoin.core.Community - :type password_asker: cutecoin.gui.password_asker.Password_Asker + :param cutecoin.core.Application app: The application + :param cutecoin.core.Account account: The configured account + :param cutecoin.core.Community community: The configured community + :param cutecoin.gui.password_asker.Password_Asker password_asker: The password asker """ super().__init__() self.setupUi(self) @@ -197,7 +197,11 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): menu.exec_(QCursor.pos()) def selfcert_sent(self, pubkey, currency): - toast.display(self.tr("UID Publishing"), + if self.app.preferences['notifications']: + toast.display(self.tr("UID Publishing"), + self.tr("Success publishing your UID").format(pubkey, currency)) + else: + QMessageBox.information(self, self.tr("UID Publishing"), self.tr("Success publishing your UID").format(pubkey, currency)) self.account.certification_broadcasted.disconnect() self.account.broadcast_error.disconnect(self.handle_error) @@ -206,7 +210,10 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): @pyqtSlot(int, str) def handle_error(self, error_code, text): - toast.display(self.tr("Error"), self.tr("{0} : {1}".format(error_code, text))) + if self.app.preferences['notifications']: + toast.display(self.tr("Error"), self.tr("{0} : {1}".format(error_code, text))) + else: + QMessageBox.critical(self, self.tr("Error"), self.tr("{0} : {1}".format(error_code, text))) self.account.certification_broadcasted.disconnect() self.account.broadcast_error.disconnect(self.handle_error) QApplication.restoreOverrideCursor() diff --git a/src/cutecoin/gui/toast.py b/src/cutecoin/gui/toast.py index a259e9e9acbe78a7163f379bbd6d23925caf42c5..afd30d7776087dab85ee0b9420ffd8eba5ae2927 100644 --- a/src/cutecoin/gui/toast.py +++ b/src/cutecoin/gui/toast.py @@ -17,7 +17,6 @@ def display(title, msg): logging.debug("NOTIFY DISPLAY") if sys.platform == "linux": import notify2 - import dbus if not notify2.is_initted(): logging.debug("Initialising notify2") notify2.init("cutecoin") diff --git a/src/cutecoin/gui/transactions_tab.py b/src/cutecoin/gui/transactions_tab.py index 777274f902152f0ccf522e839a9da3191de25457..302c8fbc1f0a13b78391699d40cf4a4f457a9570 100644 --- a/src/cutecoin/gui/transactions_tab.py +++ b/src/cutecoin/gui/transactions_tab.py @@ -93,7 +93,8 @@ class TransactionsTabWidget(QWidget, Ui_transactionsTabWidget): text = self.tr("Received {0} {1} from {2} transfers").format(amount, self.community.currency, len(received_list)) - toast.display(self.tr("New transactions received"), text) + if self.app.preferences['notifications']: + toast.display(self.tr("New transactions received"), text) self.table_history.model().sourceModel().refresh_transfers() self.table_history.resizeColumnsToContents() diff --git a/src/cutecoin/gui/transfer.py b/src/cutecoin/gui/transfer.py index b62f1e7acc0764a6330f875515816704b7abfab1..d514c90022ec3e949144ddc37ed2f12d8f72ec20 100644 --- a/src/cutecoin/gui/transfer.py +++ b/src/cutecoin/gui/transfer.py @@ -18,9 +18,13 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): classdocs """ - def __init__(self, sender, password_asker): + def __init__(self, app, sender, password_asker): """ Constructor + :param cutecoin.core.Application app: The application + :param cutecoin.core.Account sender: The sender + :param cutecoin.gui.password_asker.Password_Asker password_asker: The password asker + :return: """ super().__init__() self.setupUi(self) @@ -79,7 +83,11 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): @pyqtSlot(str) def money_sent(self, receiver_uid): - toast.display(self.tr("Transfer"), + if self.app.preferences['notifications']: + toast.display(self.tr("Transfer"), + self.tr("Success sending money to {0}").format(receiver_uid)) + else: + QMessageBox.information(self, self.tr("Transfer"), self.tr("Success sending money to {0}").format(receiver_uid)) self.wallet.transfer_broadcasted.disconnect() self.wallet.broadcast_error.disconnect(self.handle_error) @@ -88,7 +96,10 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): @pyqtSlot(int, str) def handle_error(self, error_code, text): - toast.display(self.tr("Error"), self.tr("{0} : {1}".format(error_code, text))) + if self.app.preferences['notifications']: + toast.display(self.tr("Error"), self.tr("{0} : {1}".format(error_code, text))) + else: + QMessageBox.critical(self, self.tr("Error"), self.tr("{0} : {1}".format(error_code, text))) self.wallet.transfer_broadcasted.disconnect() self.wallet.broadcast_error.disconnect(self.handle_error) QApplication.restoreOverrideCursor()