From 2ba62f7d84324971742b01fc7351d503e9174fd6 Mon Sep 17 00:00:00 2001
From: Inso <insomniak.fr@gmail.com>
Date: Sat, 21 Feb 2015 15:38:39 +0100
Subject: [PATCH] Adding missing files

---
 res/ui/network_tab.ui           | 38 +++++++++++++
 src/cutecoin/gui/network_tab.py | 28 ++++++++++
 src/cutecoin/models/network.py  | 95 +++++++++++++++++++++++++++++++++
 3 files changed, 161 insertions(+)
 create mode 100644 res/ui/network_tab.ui
 create mode 100644 src/cutecoin/gui/network_tab.py
 create mode 100644 src/cutecoin/models/network.py

diff --git a/res/ui/network_tab.ui b/res/ui/network_tab.ui
new file mode 100644
index 00000000..62812626
--- /dev/null
+++ b/res/ui/network_tab.ui
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>NetworkTabWidget</class>
+ <widget class="QWidget" name="NetworkTabWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_2">
+   <item>
+    <layout class="QVBoxLayout" name="verticalLayout">
+     <item>
+      <widget class="QTableView" name="table_network">
+       <attribute name="horizontalHeaderShowSortIndicator" stdset="0">
+        <bool>true</bool>
+       </attribute>
+       <attribute name="horizontalHeaderStretchLastSection">
+        <bool>true</bool>
+       </attribute>
+       <attribute name="verticalHeaderVisible">
+        <bool>false</bool>
+       </attribute>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/cutecoin/gui/network_tab.py b/src/cutecoin/gui/network_tab.py
new file mode 100644
index 00000000..b1da42f0
--- /dev/null
+++ b/src/cutecoin/gui/network_tab.py
@@ -0,0 +1,28 @@
+'''
+Created on 20 févr. 2015
+
+@author: inso
+'''
+
+from PyQt5.QtWidgets import QWidget
+from ..models.network import NetworkTableModel, NetworkFilterProxyModel
+from ..gen_resources.network_tab_uic import Ui_NetworkTabWidget
+
+
+class NetworkTabWidget(QWidget, Ui_NetworkTabWidget):
+    '''
+    classdocs
+    '''
+
+    def __init__(self, community):
+        '''
+        Constructor
+        '''
+        super().__init__()
+        self.setupUi(self)
+        model = NetworkTableModel(community)
+        proxy = NetworkFilterProxyModel()
+        proxy.setSourceModel(model)
+        self.table_network.setModel(proxy)
+
+
diff --git a/src/cutecoin/models/network.py b/src/cutecoin/models/network.py
new file mode 100644
index 00000000..d0b00066
--- /dev/null
+++ b/src/cutecoin/models/network.py
@@ -0,0 +1,95 @@
+'''
+Created on 5 févr. 2014
+
+@author: inso
+'''
+
+import logging
+from ..core.transfer import Transfer, Received
+from ..core.person import Person
+from ..tools.exceptions import PersonNotFoundError
+from ucoinpy.documents.peer import BMAEndpoint
+from ucoinpy.api import bma
+from PyQt5.QtCore import QAbstractTableModel, Qt, QVariant, QSortFilterProxyModel, \
+                        QDateTime
+from PyQt5.QtGui import QFont, QColor
+
+
+class NetworkFilterProxyModel(QSortFilterProxyModel):
+    def __init__(self, parent=None):
+        super().__init__(parent)
+        self.community = None
+
+    def columnCount(self, parent):
+        return self.sourceModel().columnCount(None)
+
+    def setSourceModel(self, sourceModel):
+        self.community = sourceModel.community
+        super().setSourceModel(sourceModel)
+
+    def lessThan(self, left, right):
+        """
+        Sort table by given column number.
+        """
+        left_data = self.sourceModel().data(left, Qt.DisplayRole)
+        right_data = self.sourceModel().data(right, Qt.DisplayRole)
+        return (left_data < right_data)
+
+    def data(self, index, role):
+        source_index = self.mapToSource(index)
+        source_data = self.sourceModel().data(source_index, role)
+        return source_data
+
+
+class NetworkTableModel(QAbstractTableModel):
+
+    '''
+    A Qt abstract item model to display
+    '''
+
+    def __init__(self, community, parent=None):
+        '''
+        Constructor
+        '''
+        super().__init__(parent)
+        self.community = community
+        self.column_types = (
+            'address',
+            'port'
+        )
+
+    @property
+    def peers(self):
+        return self.community.peers
+
+    def rowCount(self, parent):
+        return len(self.peers)
+
+    def columnCount(self, parent):
+        return len(self.column_types)
+
+    def headerData(self, section, orientation, role):
+        return self.column_types[section]
+
+    def data_peer(self, peer):
+        e = next((e for e in peer.endpoints if type(e) is BMAEndpoint))
+        informations = bma.network.peering.Peers(e.conn_handler()).get()
+        if e.server:
+            address = e.server
+        elif e.ipv4:
+            address = e.port
+
+    def data(self, index, role):
+        row = index.row()
+        col = index.column()
+
+        if not index.isValid():
+            return QVariant()
+
+        peer = self.peers[row]
+        if role == Qt.DisplayRole:
+            return self.data_peer(peer)[col]
+
+    def flags(self, index):
+        return Qt.ItemIsSelectable | Qt.ItemIsEnabled
+
-- 
GitLab