Skip to content
Snippets Groups Projects
Commit 892ccedd authored by inso's avatar inso
Browse files

Parameter to disable system notifications (#162)

parent 5399bb6d
No related branches found
No related tags found
No related merge requests found
...@@ -242,6 +242,33 @@ ...@@ -242,6 +242,33 @@
</item> </item>
</layout> </layout>
</item> </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> <item>
<spacer name="verticalSpacer_2"> <spacer name="verticalSpacer_2">
<property name="orientation"> <property name="orientation">
......
...@@ -427,13 +427,15 @@ class Account(QObject): ...@@ -427,13 +427,15 @@ class Account(QObject):
strdata = bytes(reply.readAll()).decode('utf-8') strdata = bytes(reply.readAll()).decode('utf-8')
logging.debug("Received reply : {0} : {1}".format(reply.error(), strdata)) logging.debug("Received reply : {0} : {1}".format(reply.error(), strdata))
if reply.error() == QNetworkReply.NoError: if reply.error() == QNetworkReply.NoError:
self.selfcert_broadcasted.emit()
for r in replies: for r in replies:
try: try:
r.disconnect() r.disconnect()
except TypeError as e: except TypeError as e:
if "disconnect()" in str(e): if "disconnect()" in str(e):
logging.debug("Could not disconnect a reply") logging.debug("Could not disconnect a reply")
else:
raise
self.selfcert_broadcasted.emit()
else: else:
for r in replies: for r in replies:
if not r.isFinished() or r.error() == QNetworkReply.NoError: if not r.isFinished() or r.error() == QNetworkReply.NoError:
...@@ -480,13 +482,15 @@ class Account(QObject): ...@@ -480,13 +482,15 @@ class Account(QObject):
strdata = bytes(reply.readAll()).decode('utf-8') strdata = bytes(reply.readAll()).decode('utf-8')
logging.debug("Received reply : {0} : {1}".format(reply.error(), strdata)) logging.debug("Received reply : {0} : {1}".format(reply.error(), strdata))
if reply.error() == QNetworkReply.NoError: if reply.error() == QNetworkReply.NoError:
self.membership_broadcasted.emit()
for r in replies: for r in replies:
try: try:
r.disconnect() r.disconnect()
except TypeError as e: except TypeError as e:
if "disconnect()" in str(e): if "disconnect()" in str(e):
logging.debug("Could not disconnect a reply") logging.debug("Could not disconnect a reply")
else:
raise
self.membership_broadcasted.emit()
else: else:
for r in replies: for r in replies:
if not r.isFinished() or r.error() == QNetworkReply.NoError: if not r.isFinished() or r.error() == QNetworkReply.NoError:
...@@ -535,13 +539,15 @@ class Account(QObject): ...@@ -535,13 +539,15 @@ class Account(QObject):
strdata = bytes(reply.readAll()).decode('utf-8') strdata = bytes(reply.readAll()).decode('utf-8')
logging.debug("Received reply : {0} : {1}".format(reply.error(), strdata)) logging.debug("Received reply : {0} : {1}".format(reply.error(), strdata))
if reply.error() == QNetworkReply.NoError: if reply.error() == QNetworkReply.NoError:
self.certification_broadcasted.emit()
for r in replies: for r in replies:
try: try:
r.disconnect() r.disconnect()
except TypeError as e: except TypeError as e:
if "disconnect()" in str(e): if "disconnect()" in str(e):
logging.debug("Could not disconnect a reply") logging.debug("Could not disconnect a reply")
else:
raise
self.certification_broadcasted.emit()
else: else:
for r in replies: for r in replies:
if not r.isFinished() or r.error() == QNetworkReply.NoError: if not r.isFinished() or r.error() == QNetworkReply.NoError:
...@@ -589,13 +595,15 @@ class Account(QObject): ...@@ -589,13 +595,15 @@ class Account(QObject):
strdata = bytes(reply.readAll()).decode('utf-8') strdata = bytes(reply.readAll()).decode('utf-8')
logging.debug("Received reply : {0} : {1}".format(reply.error(), strdata)) logging.debug("Received reply : {0} : {1}".format(reply.error(), strdata))
if reply.error() == QNetworkReply.NoError: if reply.error() == QNetworkReply.NoError:
self.revoke_broadcasted.emit()
for r in replies: for r in replies:
try: try:
r.disconnect() r.disconnect()
except TypeError as e: except TypeError as e:
if "disconnect()" in str(e): if "disconnect()" in str(e):
logging.debug("Could not disconnect a reply") logging.debug("Could not disconnect a reply")
else:
raise
self.revoke_broadcasted.emit()
else: else:
for r in replies: for r in replies:
if not r.isFinished() or r.error() == QNetworkReply.NoError: if not r.isFinished() or r.error() == QNetworkReply.NoError:
......
...@@ -54,7 +54,8 @@ class Application(QObject): ...@@ -54,7 +54,8 @@ class Application(QObject):
'ref': 0, 'ref': 0,
'expert_mode': False, 'expert_mode': False,
'digits_after_comma': 6, 'digits_after_comma': 6,
'maximized': False 'maximized': False,
'notifications': True
} }
@classmethod @classmethod
......
...@@ -62,7 +62,10 @@ class CertificationDialog(QDialog, Ui_CertificationDialog): ...@@ -62,7 +62,10 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
@pyqtSlot(int, str) @pyqtSlot(int, str)
def handle_error(self, error_code, text): def handle_error(self, error_code, text):
if self.app.preferences['notifications']:
toast.display(self.tr("Error"), self.tr("{0} : {1}".format(error_code, text))) 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.certification_broadcasted.disconnect()
self.account.broadcast_error.disconnect(self.handle_error) self.account.broadcast_error.disconnect(self.handle_error)
QApplication.restoreOverrideCursor() QApplication.restoreOverrideCursor()
......
...@@ -66,17 +66,29 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): ...@@ -66,17 +66,29 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget):
self.account.identity(self.community).inner_data_changed.connect(self.handle_account_identity_change) self.account.identity(self.community).inner_data_changed.connect(self.handle_account_identity_change)
self.search_direct_connections() self.search_direct_connections()
self.account.membership_broadcasted.connect(lambda: self.account.membership_broadcasted.connect(self.handle_membership_broadcasted)
toast.display(self.tr("Membership"), self.account.revoke_broadcasted.connect(self.handle_revoke_broadcasted)
self.tr("Success sending Membership demand"))) self.account.selfcert_broadcasted.connect(self.handle_selfcert_broadcasted)
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.refresh_quality_buttons() 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): def identity_context_menu(self, point):
index = self.table_identities.indexAt(point) index = self.table_identities.indexAt(point)
model = self.table_identities.model() model = self.table_identities.model()
......
...@@ -118,11 +118,15 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): ...@@ -118,11 +118,15 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
days = int(expiration_time / 3600 / 24) days = int(expiration_time / 3600 / 24)
if days > 0: if days > 0:
self.status_info.append('membership_expire_soon') self.status_info.append('membership_expire_soon')
if self.app.preferences['notifications']:
toast.display(self.tr("Membership expiration"), toast.display(self.tr("Membership expiration"),
self.tr("<b>Warning : Membership expiration in {0} days</b>").format(days)) self.tr("<b>Warning : Membership expiration in {0} days</b>").format(days))
certifiers_of = person.unique_valid_certifiers_of(self.community) certifiers_of = person.unique_valid_certifiers_of(self.community)
if len(certifiers_of) < self.community.parameters['sigQty']: if len(certifiers_of) < self.community.parameters['sigQty']:
self.status_info.append('warning_certifications') self.status_info.append('warning_certifications')
if self.app.preferences['notifications']:
toast.display(self.tr("Certifications number"), toast.display(self.tr("Certifications number"),
self.tr("<b>Warning : You are certified by only {0} persons, need {1}</b>") self.tr("<b>Warning : You are certified by only {0} persons, need {1}</b>")
.format(len(certifiers_of), .format(len(certifiers_of),
......
...@@ -227,6 +227,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): ...@@ -227,6 +227,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
.format(version=latest[1]) .format(version=latest[1])
version_url = latest[2] version_url = latest[2]
if self.app.preferences['notifications']:
toast.display("Cutecoin", """<p>{version_info}</br> toast.display("Cutecoin", """<p>{version_info}</br>
<a href={version_url}>Download link</a></p>""".format( <a href={version_url}>Download link</a></p>""".format(
version_info=version_info, version_info=version_info,
......
...@@ -40,6 +40,7 @@ class PreferencesDialog(QDialog, Ui_PreferencesDialog): ...@@ -40,6 +40,7 @@ class PreferencesDialog(QDialog, Ui_PreferencesDialog):
self.combo_language.setCurrentText(self.app.preferences['lang']) self.combo_language.setCurrentText(self.app.preferences['lang'])
self.checkbox_expertmode.setChecked(self.app.preferences['expert_mode']) self.checkbox_expertmode.setChecked(self.app.preferences['expert_mode'])
self.checkbox_maximize.setChecked(self.app.preferences['maximized']) 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.setValue(self.app.preferences['digits_after_comma'])
self.spinbox_digits_comma.setMaximum(12) self.spinbox_digits_comma.setMaximum(12)
self.spinbox_digits_comma.setMinimum(1) self.spinbox_digits_comma.setMinimum(1)
...@@ -53,7 +54,8 @@ class PreferencesDialog(QDialog, Ui_PreferencesDialog): ...@@ -53,7 +54,8 @@ class PreferencesDialog(QDialog, Ui_PreferencesDialog):
'ref': self.combo_referential.currentIndex(), 'ref': self.combo_referential.currentIndex(),
'expert_mode': self.checkbox_expertmode.isChecked(), 'expert_mode': self.checkbox_expertmode.isChecked(),
'maximized': self.checkbox_maximize.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) self.app.save_preferences(pref)
toast.display(self.tr("Preferences"), toast.display(self.tr("Preferences"),
self.tr("A restart is needed to apply your new preferences.")) self.tr("A restart is needed to apply your new preferences."))
......
...@@ -101,10 +101,10 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): ...@@ -101,10 +101,10 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog):
""" """
Constructor Constructor
:type app: cutecoin.core.App :param cutecoin.core.Application app: The application
:type account: cutecoin.core.Account :param cutecoin.core.Account account: The configured account
:type community: cutecoin.core.Community :param cutecoin.core.Community community: The configured community
:type password_asker: cutecoin.gui.password_asker.Password_Asker :param cutecoin.gui.password_asker.Password_Asker password_asker: The password asker
""" """
super().__init__() super().__init__()
self.setupUi(self) self.setupUi(self)
...@@ -197,8 +197,12 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): ...@@ -197,8 +197,12 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog):
menu.exec_(QCursor.pos()) menu.exec_(QCursor.pos())
def selfcert_sent(self, pubkey, currency): def selfcert_sent(self, pubkey, currency):
if self.app.preferences['notifications']:
toast.display(self.tr("UID Publishing"), toast.display(self.tr("UID Publishing"),
self.tr("Success publishing your UID").format(pubkey, currency)) 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.certification_broadcasted.disconnect()
self.account.broadcast_error.disconnect(self.handle_error) self.account.broadcast_error.disconnect(self.handle_error)
QApplication.restoreOverrideCursor() QApplication.restoreOverrideCursor()
...@@ -206,7 +210,10 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog): ...@@ -206,7 +210,10 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog):
@pyqtSlot(int, str) @pyqtSlot(int, str)
def handle_error(self, error_code, text): def handle_error(self, error_code, text):
if self.app.preferences['notifications']:
toast.display(self.tr("Error"), self.tr("{0} : {1}".format(error_code, text))) 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.certification_broadcasted.disconnect()
self.account.broadcast_error.disconnect(self.handle_error) self.account.broadcast_error.disconnect(self.handle_error)
QApplication.restoreOverrideCursor() QApplication.restoreOverrideCursor()
......
...@@ -17,7 +17,6 @@ def display(title, msg): ...@@ -17,7 +17,6 @@ def display(title, msg):
logging.debug("NOTIFY DISPLAY") logging.debug("NOTIFY DISPLAY")
if sys.platform == "linux": if sys.platform == "linux":
import notify2 import notify2
import dbus
if not notify2.is_initted(): if not notify2.is_initted():
logging.debug("Initialising notify2") logging.debug("Initialising notify2")
notify2.init("cutecoin") notify2.init("cutecoin")
......
...@@ -93,6 +93,7 @@ class TransactionsTabWidget(QWidget, Ui_transactionsTabWidget): ...@@ -93,6 +93,7 @@ class TransactionsTabWidget(QWidget, Ui_transactionsTabWidget):
text = self.tr("Received {0} {1} from {2} transfers").format(amount, text = self.tr("Received {0} {1} from {2} transfers").format(amount,
self.community.currency, self.community.currency,
len(received_list)) len(received_list))
if self.app.preferences['notifications']:
toast.display(self.tr("New transactions received"), text) toast.display(self.tr("New transactions received"), text)
self.table_history.model().sourceModel().refresh_transfers() self.table_history.model().sourceModel().refresh_transfers()
......
...@@ -18,9 +18,13 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): ...@@ -18,9 +18,13 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
classdocs classdocs
""" """
def __init__(self, sender, password_asker): def __init__(self, app, sender, password_asker):
""" """
Constructor 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__() super().__init__()
self.setupUi(self) self.setupUi(self)
...@@ -79,8 +83,12 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): ...@@ -79,8 +83,12 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
@pyqtSlot(str) @pyqtSlot(str)
def money_sent(self, receiver_uid): def money_sent(self, receiver_uid):
if self.app.preferences['notifications']:
toast.display(self.tr("Transfer"), toast.display(self.tr("Transfer"),
self.tr("Success sending money to {0}").format(receiver_uid)) 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.transfer_broadcasted.disconnect()
self.wallet.broadcast_error.disconnect(self.handle_error) self.wallet.broadcast_error.disconnect(self.handle_error)
QApplication.restoreOverrideCursor() QApplication.restoreOverrideCursor()
...@@ -88,7 +96,10 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog): ...@@ -88,7 +96,10 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
@pyqtSlot(int, str) @pyqtSlot(int, str)
def handle_error(self, error_code, text): def handle_error(self, error_code, text):
if self.app.preferences['notifications']:
toast.display(self.tr("Error"), self.tr("{0} : {1}".format(error_code, text))) 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.transfer_broadcasted.disconnect()
self.wallet.broadcast_error.disconnect(self.handle_error) self.wallet.broadcast_error.disconnect(self.handle_error)
QApplication.restoreOverrideCursor() QApplication.restoreOverrideCursor()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment