From f4baa5fdb005eca6d5e32086c199b0cdce2c0e32 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Sat, 24 Jan 2015 20:43:32 +0100
Subject: [PATCH] Qtify password asker

---
 src/cutecoin/gui/certification.py         |  2 +-
 src/cutecoin/gui/community_tab.py         | 11 ++++++-----
 src/cutecoin/gui/password_asker.py        |  6 ++++--
 src/cutecoin/gui/process_cfg_account.py   |  4 ++--
 src/cutecoin/gui/process_cfg_community.py |  4 ++--
 src/cutecoin/gui/transfer.py              |  4 ++--
 6 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/cutecoin/gui/certification.py b/src/cutecoin/gui/certification.py
index a70d4820..7ff30f86 100644
--- a/src/cutecoin/gui/certification.py
+++ b/src/cutecoin/gui/certification.py
@@ -37,7 +37,7 @@ class CertificationDialog(QDialog, Ui_CertificationDialog):
         else:
             pubkey = self.edit_pubkey.text()
 
-        password = self.password_asker.ask()
+        password = self.password_asker.exec_()
         if password == "":
             return
 
diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py
index 752ef8f9..976e7402 100644
--- a/src/cutecoin/gui/community_tab.py
+++ b/src/cutecoin/gui/community_tab.py
@@ -7,7 +7,7 @@ Created on 2 févr. 2014
 import logging
 from PyQt5.QtCore import Qt
 from PyQt5.QtGui import QIcon
-from PyQt5.QtWidgets import QWidget, QMessageBox, QAction, QMenu, QInputDialog, QLineEdit
+from PyQt5.QtWidgets import QWidget, QMessageBox, QAction, QMenu, QDialog, QLineEdit
 from ..models.members import MembersListModel
 from ..gen_resources.community_tab_uic import Ui_CommunityTabWidget
 from .add_contact import AddContactDialog
@@ -95,8 +95,8 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget):
         dialog.exec_()
 
     def send_membership_demand(self):
-        password = self.password_asker.ask()
-        if password == "":
+        password = self.password_asker.exec_()
+        if self.password_asker.result() == QDialog.Rejected:
             return
 
         try:
@@ -126,8 +126,9 @@ Sending a membership demand  cannot be canceled.
 The process to join back the community later will have to be done again."""
 .format(self.account.pubkey), QMessageBox.Ok | QMessageBox.Cancel)
         if reply == QMessageBox.Ok:
-            password = PasswordAskerDialog(self.app.current_account).ask()
-            if password == "":
+            password_asker = PasswordAskerDialog(self.app.current_account)
+            password = password_asker.exec_()
+            if password_asker.result() == QDialog.Rejected:
                 return
 
             try:
diff --git a/src/cutecoin/gui/password_asker.py b/src/cutecoin/gui/password_asker.py
index cae09d02..96d1dbcd 100644
--- a/src/cutecoin/gui/password_asker.py
+++ b/src/cutecoin/gui/password_asker.py
@@ -27,14 +27,15 @@ class PasswordAskerDialog(QDialog, Ui_PasswordAskerDialog):
         self.password = ""
         self.remember = False
 
-    def ask(self):
+    def exec_(self):
         if not self.remember:
-            self.exec_()
+            super().exec_()
             pwd = self.password
             if not self.remember:
                 self.password = ""
             return pwd
         else:
+            self.setResult(QDialog.Accepted)
             return self.password
 
     def accept(self):
@@ -53,5 +54,6 @@ class PasswordAskerDialog(QDialog, Ui_PasswordAskerDialog):
     def reject(self):
         self.edit_password.setText("")
         logging.debug("Cancelled")
+        self.setResult(QDialog.Accepted)
         self.password = ""
         super().reject()
diff --git a/src/cutecoin/gui/process_cfg_account.py b/src/cutecoin/gui/process_cfg_account.py
index b620be5e..7ef72a8a 100644
--- a/src/cutecoin/gui/process_cfg_account.py
+++ b/src/cutecoin/gui/process_cfg_account.py
@@ -234,8 +234,8 @@ class ProcessConfigureAccount(QDialog, Ui_AccountConfigurationDialog):
                                      str(e), QMessageBox.Ok)
             password = self.edit_password.text()
         else:
-            password = self.password_asker.ask()
-            if password == "":
+            password = self.password_asker.exec_()
+            if self.password_asker.result() == QDialog.Rejected:
                 return
 
         nb_wallets = self.spinbox_wallets.value()
diff --git a/src/cutecoin/gui/process_cfg_community.py b/src/cutecoin/gui/process_cfg_community.py
index fd36c316..e3f75e11 100644
--- a/src/cutecoin/gui/process_cfg_community.py
+++ b/src/cutecoin/gui/process_cfg_community.py
@@ -179,8 +179,8 @@ class ProcessConfigureCommunity(QDialog, Ui_CommunityConfigurationDialog):
 {0}\n
 Would you like to publish the key ?""".format(self.account.pubkey))
             if reply == QMessageBox.Yes:
-                password = self.password_asker.ask()
-                if password == "":
+                password = self.password_asker.exec_()
+                if self.password_asker.result() == QDialog.Rejected:
                     return
                 try:
                     self.account.send_pubkey(password, self.community)
diff --git a/src/cutecoin/gui/transfer.py b/src/cutecoin/gui/transfer.py
index 3931789a..344a7d13 100644
--- a/src/cutecoin/gui/transfer.py
+++ b/src/cutecoin/gui/transfer.py
@@ -55,8 +55,8 @@ class TransferMoneyDialog(QDialog, Ui_TransferMoneyDialog):
             recipient = self.edit_pubkey.text()
         amount = self.spinbox_amount.value()
 
-        password = self.password_asker.ask()
-        if password == "":
+        password = self.password_asker.exec_()
+        if self.password_asker.result() == QDialog.Rejected:
             return
 
         try:
-- 
GitLab