From 96db7af68ada1d2e24fb2bb3f63320613c7db37b Mon Sep 17 00:00:00 2001
From: Vincent Texier <vit@free.fr>
Date: Sat, 7 Mar 2015 18:19:59 +0100
Subject: [PATCH] Display path to account member in member window (unstable)

---
 src/cutecoin/core/account.py |  3 +++
 src/cutecoin/core/graph.py   |  7 +++++++
 src/cutecoin/gui/member.py   | 37 ++++++++++++++++++++++++++++--------
 3 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py
index aa2f4205..094da3a1 100644
--- a/src/cutecoin/core/account.py
+++ b/src/cutecoin/core/account.py
@@ -259,3 +259,6 @@ class Account(object):
                 'wallets': data_wallets,
                 'contacts': data_contacts}
         return data
+
+    def get_person(self):
+        return Person(self.name, self.pubkey)
diff --git a/src/cutecoin/core/graph.py b/src/cutecoin/core/graph.py
index ef2e9db3..b4f1aa8e 100644
--- a/src/cutecoin/core/graph.py
+++ b/src/cutecoin/core/graph.py
@@ -18,6 +18,13 @@ class Graph(dict):
         path = list()
         graph_tmp = copy.deepcopy(self)
 
+        if from_person.pubkey not in graph_tmp.keys():
+            graph_tmp.add_person(from_person)
+            certifier_list = from_person.certifiers_of(self.community)
+            graph_tmp.add_certifier_list(certifier_list, from_person, to_person)
+            certified_list = from_person.certified_by(self.community)
+            graph_tmp.add_certified_list(certified_list, from_person, to_person)
+
         if to_person.pubkey not in graph_tmp.keys():
             # recursively feed graph searching for account node...
             graph_tmp.explore_to_find_member(to_person, graph_tmp[from_person.pubkey]['nodes'], list())
diff --git a/src/cutecoin/gui/member.py b/src/cutecoin/gui/member.py
index fbb38d31..d961db04 100644
--- a/src/cutecoin/gui/member.py
+++ b/src/cutecoin/gui/member.py
@@ -1,6 +1,4 @@
-import logging
-import datetime
-import math
+from cutecoin.core.graph import Graph
 from PyQt5.QtWidgets import QDialog
 from ..gen_resources.member_uic import Ui_DialogMember
 
@@ -25,18 +23,41 @@ class MemberDialog(QDialog, Ui_DialogMember):
         if join_date is None:
             join_date = 'not a member'
 
-        # set infos in label
-        self.label_properties.setText(
-            """
+        # calculate path to account member
+        graph = Graph(self.community)
+        path = None
+        # if selected member is not the account member...
+        if person.pubkey != self.account.pubkey:
+            # add path from selected member to account member
+            path = graph.get_shortest_path_between_members(person, self.account.get_person())
+
+        text = """
             <table cellpadding="5">
             <tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>
             <tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>
-            </table>
             """.format(
                 'Public key',
                 self.person.pubkey,
                 'Join date',
                 join_date
             )
-        )
+
+        if path:
+            distance = len(path) - 1
+            text += """<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""".format('Distance', distance)
+            if distance > 1:
+                index = 0
+                for node in path:
+                    if index == 0:
+                        text += """<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""".format('Path', node['text'])
+                    else:
+                        text += """<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""".format('', node['text'])
+                    if index == distance and node['id'] != self.account.pubkey:
+                        text += """<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""".format('', self.account.name)
+                    index += 1
+        # close html text
+        text += "</table>"
+
+        # set text in label
+        self.label_properties.setText(text)
 
-- 
GitLab