From 221ed42fb250dde334d99b119c90e9fba666dce4 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Sat, 9 May 2015 09:20:29 +0200
Subject: [PATCH] Add the possibility to publish the UID later + Toasts instead
 of MessageBox

---
 res/ui/community_tab.ui           | 19 ++++++++++++++++++-
 src/cutecoin/gui/certification.py |  5 +++--
 src/cutecoin/gui/community_tab.py | 27 +++++++++++++++++++++++++++
 src/cutecoin/gui/transfer.py      |  5 +++--
 4 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/res/ui/community_tab.ui b/res/ui/community_tab.ui
index c7fa18c7..82fa382f 100644
--- a/res/ui/community_tab.ui
+++ b/res/ui/community_tab.ui
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>431</width>
+    <width>457</width>
     <height>369</height>
    </rect>
   </property>
@@ -218,11 +218,28 @@
     </hint>
    </hints>
   </connection>
+  <connection>
+   <sender>button_publish_uid</sender>
+   <signal>clicked()</signal>
+   <receiver>CommunityTabWidget</receiver>
+   <slot>publish_uid()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>123</x>
+     <y>334</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>228</x>
+     <y>184</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
  <slots>
   <slot>identity_context_menu(QPoint)</slot>
   <slot>send_membership_demand()</slot>
   <slot>send_membership_leaving()</slot>
   <slot>search_text()</slot>
+  <slot>publish_uid()</slot>
  </slots>
 </ui>
diff --git a/src/cutecoin/gui/certification.py b/src/cutecoin/gui/certification.py
index ef778167..d72e4491 100644
--- a/src/cutecoin/gui/certification.py
+++ b/src/cutecoin/gui/certification.py
@@ -7,6 +7,7 @@ from PyQt5.QtWidgets import QDialog, QMessageBox, QDialogButtonBox, QApplication
 from PyQt5.QtCore import Qt
 from ..tools.exceptions import NoPeerAvailable
 from ..gen_resources.certification_uic import Ui_CertificationDialog
+from . import toast
 
 
 class CertificationDialog(QDialog, Ui_CertificationDialog):
@@ -45,8 +46,8 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
         try:
             QApplication.setOverrideCursor(Qt.WaitCursor)
             self.account.certify(password, self.community, pubkey)
-            QMessageBox.information(self, self.tr("Certification"),
-                                 self.tr("Success certifying {0} from {1}").format(pubkey,
+            toast.display(self.tr("Certification"),
+                          self.tr("Success certifying {0} from {1}").format(pubkey,
                                                                           self.community.currency))
         except ValueError as e:
             QMessageBox.critical(self, self.tr("Certification"),
diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py
index 2def3e5d..f42db2b8 100644
--- a/src/cutecoin/gui/community_tab.py
+++ b/src/cutecoin/gui/community_tab.py
@@ -230,6 +230,33 @@ The process to join back the community later will have to be done again.""")
                                      "{0}".format(e),
                                      QMessageBox.Ok)
 
+    def publish_uid(self):
+        reply = QMessageBox.warning(self, self.tr("Warning"),
+                             self.tr("""Are you sure ?
+Publishing your UID cannot be canceled.""")
+.format(self.account.pubkey), QMessageBox.Ok | QMessageBox.Cancel)
+        if reply == QMessageBox.Ok:
+            password_asker = PasswordAskerDialog(self.account)
+            password = password_asker.exec_()
+            if password_asker.result() == QDialog.Rejected:
+                return
+
+            try:
+                self.account.send_selfcert(password, self.community)
+                toast.display(self.tr("UID Publishing"),
+                              self.tr("Success publishing your UID"))
+            except ValueError as e:
+                QMessageBox.critical(self, self.tr("Leaving demand error"),
+                                  e.message)
+            except NoPeerAvailable as e:
+                QMessageBox.critical(self, self.tr("Network error"),
+                                     self.tr("Couldn't connect to network : {0}").format(e),
+                                     QMessageBox.Ok)
+            except Exception as e:
+                QMessageBox.critical(self, self.tr("Error"),
+                                     "{0}".format(e),
+                                     QMessageBox.Ok)
+
     def search_text(self):
         """
         Search text and display found identities
diff --git a/src/cutecoin/gui/transfer.py b/src/cutecoin/gui/transfer.py
index 26005606..ad0aa4a2 100644
--- a/src/cutecoin/gui/transfer.py
+++ b/src/cutecoin/gui/transfer.py
@@ -9,6 +9,7 @@ from PyQt5.QtGui import QRegExpValidator
 
 from ..tools.exceptions import NotEnoughMoneyError, NoPeerAvailable
 from ..gen_resources.transfer_uic import Ui_TransferMoneyDialog
+from . import toast
 
 
 class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
@@ -74,8 +75,8 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
             QApplication.processEvents()
             self.wallet.send_money(self.account.salt, password, self.community,
                                        recipient, amount, comment)
-            QMessageBox.information(self, self.tr("Money transfer"),
-                                 self.tr("Success transfering {0} {1} to {2}").format(amount,
+            toast.display(self.tr("Money transfer"),
+                          self.tr("Success transfering {0} {1} to {2}").format(amount,
                                                                              self.community.currency,
                                                                              recipient))
         except ValueError as e:
-- 
GitLab