From 8a207a32c325716bd9411eceead3be7a9aa1b06f Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Sat, 9 May 2015 12:18:51 +0200
Subject: [PATCH] Refresh account quality status

---
 src/cutecoin/gui/community_tab.py | 53 +++++++++++++++++++------------
 src/cutecoin/gui/currency_tab.py  |  6 ++--
 src/cutecoin/gui/wallets_tab.py   |  1 -
 3 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py
index f42db2b8..5fd4194e 100644
--- a/src/cutecoin/gui/community_tab.py
+++ b/src/cutecoin/gui/community_tab.py
@@ -5,7 +5,7 @@ Created on 2 févr. 2014
 '''
 
 import logging
-from PyQt5.QtCore import Qt
+from PyQt5.QtCore import Qt, pyqtSlot
 from PyQt5.QtGui import QIcon, QCursor
 from PyQt5.QtWidgets import QWidget, QMessageBox, QAction, QMenu, QDialog, \
                             QAbstractItemView
@@ -51,25 +51,7 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget):
         self.table_identities.setSelectionBehavior(QAbstractItemView.SelectRows)
         self.table_identities.customContextMenuRequested.connect(self.identity_context_menu)
         self.table_identities.sortByColumn(0, Qt.AscendingOrder)
-
-        try:
-            if self.account.published_uid(self.community):
-                if self.account.member_of(self.community):
-                    self.button_membership.setText("Renew membership")
-                    self.button_publish_uid.hide()
-                    self.button_leaving.show()
-                else:
-                    self.button_membership.setText("Send membership demand")
-                    self.button_leaving.hide()
-                    self.button_publish_uid.hide()
-            else:
-                self.button_membership.hide()
-                self.button_leaving.hide()
-                self.button_publish_uid.show()
-        except PersonNotFoundError:
-            self.button_membership.hide()
-            self.button_leaving.hide()
-            self.button_publish_uid.show()
+        app.monitor.persons_watcher(self.community).person_changed.connect(self.refresh_person)
 
         self.wot_tab = WotTabWidget(app, account, community, password_asker, self)
         self.tabs_information.addTab(self.wot_tab, QIcon(':/icons/wot_icon'), "WoT")
@@ -80,6 +62,7 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget):
         direct_connections.triggered.connect(self.search_direct_connections)
         self.button_search.addAction(direct_connections)
         self.refresh()
+        self.refresh_quality_buttons()
 
     def identity_context_menu(self, point):
         index = self.table_identities.indexAt(point)
@@ -316,9 +299,39 @@ Publishing your UID cannot be canceled.""")
 
         self.table_identities.model().sourceModel().refresh_identities(persons)
 
+    def refresh_quality_buttons(self):
+        try:
+            if self.account.published_uid(self.community):
+                logging.debug("UID Published")
+                if self.account.member_of(self.community):
+                    self.button_membership.setText("Renew membership")
+                    self.button_membership.show()
+                    self.button_publish_uid.hide()
+                    self.button_leaving.show()
+                else:
+                    logging.debug("Not a member")
+                    self.button_membership.setText("Send membership demand")
+                    self.button_membership.show()
+                    self.button_leaving.hide()
+                    self.button_publish_uid.hide()
+            else:
+                logging.debug("UID not published")
+                self.button_membership.hide()
+                self.button_leaving.hide()
+                self.button_publish_uid.show()
+        except PersonNotFoundError:
+            self.button_membership.hide()
+            self.button_leaving.hide()
+            self.button_publish_uid.show()
+
+    @pyqtSlot(str)
     def refresh_person(self, pubkey):
+        logging.debug("Refresh person {0}".format(pubkey))
         if self is None:
             logging.error("community_tab self is None in refresh_person. Watcher connected to a destroyed tab")
         else:
+            if pubkey == self.account.pubkey:
+                self.refresh_quality_buttons()
+
             index = self.table_identities.model().sourceModel().person_index(pubkey)
             self.table_identities.model().sourceModel().dataChanged.emit(index[0], index[1])
diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py
index 90c64dbd..f72f041c 100644
--- a/src/cutecoin/gui/currency_tab.py
+++ b/src/cutecoin/gui/currency_tab.py
@@ -52,8 +52,6 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
 
         self.community.network.new_block_mined.connect(self.refresh_block)
         self.community.network.nodes_changed.connect(self.refresh_status)
-        persons_watcher = self.app.monitor.persons_watcher(self.community)
-        persons_watcher.person_changed.connect(self.tab_community.refresh_person)
         bc_watcher = self.app.monitor.blockchain_watcher(self.community)
         bc_watcher.error.connect(self.display_error)
         bc_watcher.watching_stopped.connect(self.refresh_data)
@@ -145,7 +143,7 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
         '''
         logging.debug("Refresh block")
         self.tab_history.progressbar.show()
-        self.app.monitor.blockchain_watcher(self.community).thread().start()
+        #self.app.monitor.blockchain_watcher(self.community).thread().start()
         self.app.monitor.persons_watcher(self.community).thread().start()
         self.refresh_status()
 
@@ -160,9 +158,9 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
         if self.tab_history.table_history.model():
             self.tab_history.table_history.model().sourceModel().refresh_transfers()
 
+        #self.tab_history.refresh_balance()
         self.tab_history.progressbar.hide()
         self.refresh_status()
-        self.tab_history.refresh_balance()
 
     @pyqtSlot()
     def refresh_status(self):
diff --git a/src/cutecoin/gui/wallets_tab.py b/src/cutecoin/gui/wallets_tab.py
index 0f0dce81..7ffa3fc1 100644
--- a/src/cutecoin/gui/wallets_tab.py
+++ b/src/cutecoin/gui/wallets_tab.py
@@ -106,7 +106,6 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab):
         else:
             localized_maximum = QLocale().toString(self.get_referential_value(maximum), 'f', 6)
 
-        logging.debug(self.tr("{:} {:} in [{:.2f} - {:}] {:}"))
         # set infos in label
         self.label_balance.setText(
             self.tr("""
-- 
GitLab