From 8c1a3b383197f97e64a4e4fecee82c2a3b14192a Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Sun, 22 Nov 2015 11:51:54 +0100
Subject: [PATCH] Copy identities pubkey (#239)

---
 src/cutecoin/gui/identities_tab.py | 16 ++++++++++++++++
 src/cutecoin/gui/views/wot.py      | 14 ++++++++++++++
 src/cutecoin/gui/wot_tab.py        |  6 ++++++
 3 files changed, 36 insertions(+)

diff --git a/src/cutecoin/gui/identities_tab.py b/src/cutecoin/gui/identities_tab.py
index dd395728..f774a59d 100644
--- a/src/cutecoin/gui/identities_tab.py
+++ b/src/cutecoin/gui/identities_tab.py
@@ -125,11 +125,16 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab):
             view_wot.triggered.connect(self.view_wot)
             view_wot.setData(identity)
 
+            copy_pubkey = QAction(self.tr("Copy pubkey"), self)
+            copy_pubkey.triggered.connect(self.copy_identity_pubkey)
+            copy_pubkey.setData(identity)
+
             menu.addAction(informations)
             menu.addAction(add_contact)
             menu.addAction(send_money)
             menu.addAction(certify)
             menu.addAction(view_wot)
+            menu.addAction(copy_pubkey)
 
             # Show the context menu.
             menu.popup(QCursor.pos())
@@ -175,6 +180,17 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab):
         yield from CertificationDialog.certify_identity(self.app, self.account, self.password_asker,
                                              self.community, identity)
 
+    def copy_identity_pubkey(self):
+        """
+        Copy the identity pubkey to the clipboard
+
+        :param cutecoin.core.registry.Identity identity: The identity
+        """
+        identity = self.sender().data()
+        cb = self.app.qapp.clipboard()
+        cb.clear(mode=cb.Clipboard)
+        cb.setText(identity.pubkey, mode=cb.Clipboard)
+
     def view_wot(self):
         identity = self.sender().data()
         self.view_in_wot.emit(identity)
diff --git a/src/cutecoin/gui/views/wot.py b/src/cutecoin/gui/views/wot.py
index cfa426ac..cae6725a 100644
--- a/src/cutecoin/gui/views/wot.py
+++ b/src/cutecoin/gui/views/wot.py
@@ -63,6 +63,7 @@ class Scene(QGraphicsScene):
     node_transaction = pyqtSignal(dict, name='nodeTransaction')
     node_contact = pyqtSignal(dict, name='nodeContact')
     node_member = pyqtSignal(dict, name='nodeMember')
+    node_copy_pubkey = pyqtSignal(dict, name='nodeCopyPubkey')
 
     def __init__(self, parent=None):
         """
@@ -308,6 +309,12 @@ class Node(QGraphicsEllipseItem):
         self.action_sign = QAction(QCoreApplication.translate('WoT.Node', 'Certify identity'), self.scene())
         self.menu.addAction(self.action_sign)
         self.action_sign.triggered.connect(self.sign_action)
+        # action copy identity pubkey
+        QT_TRANSLATE_NOOP('WoT.Node', 'Copy pubkey')
+        self.action_copy = QAction(QCoreApplication.translate('WoT.Node', 'Copy pubkey'), self.scene())
+        self.menu.addAction(self.action_copy)
+        self.action_copy.triggered.connect(self.copy_action)
+
         # run menu
         self.menu.exec(event.screenPos())
 
@@ -340,6 +347,13 @@ class Node(QGraphicsEllipseItem):
         # trigger scene signal
         self.scene().node_signed.emit(self.metadata)
 
+    def copy_action(self):
+        """
+        Copy identity node pubkey
+        """
+        # trigger scene signal
+        self.scene().node_copy_pubkey.emit(self.metadata)
+
     def transaction_action(self):
         """
         Transaction action to identity node
diff --git a/src/cutecoin/gui/wot_tab.py b/src/cutecoin/gui/wot_tab.py
index 4d06eef5..d8fd8081 100644
--- a/src/cutecoin/gui/wot_tab.py
+++ b/src/cutecoin/gui/wot_tab.py
@@ -50,6 +50,7 @@ class WotTabWidget(QWidget, Ui_WotTabWidget):
         self.graphicsView.scene().node_transaction.connect(self.send_money_to_node)
         self.graphicsView.scene().node_contact.connect(self.add_node_as_contact)
         self.graphicsView.scene().node_member.connect(self.identity_informations)
+        self.graphicsView.scene().node_copy_pubkey.connect(self.copy_node_pubkey)
 
         self.account = None
         self.community = None
@@ -334,6 +335,11 @@ class WotTabWidget(QWidget, Ui_WotTabWidget):
         if result == QDialog.Accepted:
             self.money_sent.emit()
 
+    def copy_node_pubkey(self, metadata):
+        cb = self.app.qapp.clipboard()
+        cb.clear(mode=cb.Clipboard)
+        cb.setText(metadata['id'], mode=cb.Clipboard)
+
     def add_node_as_contact(self, metadata):
         # check if contact already exists...
         if metadata['id'] == self.account.pubkey \
-- 
GitLab