mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-04 17:15:31 -05:00
dynamic update of networkview from p3disc info. Disabled friend level for now.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3752 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
3fa3e2d6db
commit
a32bcbb635
@ -199,6 +199,7 @@ class NotifyBase
|
||||
/* one or more peers has changed the states */
|
||||
virtual void notifyPeerStatusChangedSummary() {}
|
||||
virtual void notifyChannelMsgReadSatusChanged(const std::string& /* channelId */, const std::string& /* msgId */, uint32_t /* status */) {}
|
||||
virtual void notifyDiscInfoChanged() {}
|
||||
|
||||
virtual std::string askForPassword(const std::string& /* key_details */ ,bool /* prev_is_bad */ ) { return "" ;}
|
||||
};
|
||||
|
@ -618,9 +618,15 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
||||
return;
|
||||
}
|
||||
|
||||
bool should_notify_discovery = false ;
|
||||
|
||||
for (std::list<RsPeerNetItem>::iterator pitem = item->rsPeerList.begin(); pitem != item->rsPeerList.end(); pitem++)
|
||||
{
|
||||
addDiscoveryData(item->PeerId(), pitem->pid, pitem->currentlocaladdr, pitem->currentremoteaddr, 0, time(NULL));
|
||||
bool new_info ;
|
||||
addDiscoveryData(item->PeerId(), pitem->pid, pitem->currentlocaladdr, pitem->currentremoteaddr, 0, time(NULL),new_info);
|
||||
|
||||
if(new_info)
|
||||
should_notify_discovery = true ;
|
||||
|
||||
#ifdef P3DISC_DEBUG
|
||||
std::cerr << "p3disc::recvPeerFriendMsg() Peer Config Item:" << std::endl;
|
||||
@ -725,6 +731,9 @@ void p3disc::recvPeerDetails(RsDiscReply *item, const std::string &certGpgId)
|
||||
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_NEIGHBOURS, NOTIFY_TYPE_MOD);
|
||||
|
||||
if(should_notify_discovery)
|
||||
rsicontrol->getNotify().notifyDiscInfoChanged();
|
||||
|
||||
/* cleanup (handled by caller) */
|
||||
}
|
||||
|
||||
@ -894,10 +903,12 @@ void p3disc::setGPGOperation(AuthGPGOperation *operation)
|
||||
/*************************************************************************************/
|
||||
/* Storing Network Graph */
|
||||
/*************************************************************************************/
|
||||
int p3disc::addDiscoveryData(std::string fromId, std::string aboutId, struct sockaddr_in laddr, struct sockaddr_in raddr, uint32_t flags, time_t ts)
|
||||
int p3disc::addDiscoveryData(std::string fromId, std::string aboutId, struct sockaddr_in laddr, struct sockaddr_in raddr, uint32_t flags, time_t ts,bool& new_info)
|
||||
{
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
new_info = false ;
|
||||
std::cerr << "Adding discovery data " << fromId << " - " << aboutId << std::endl ;
|
||||
/* Store Network information */
|
||||
std::map<std::string, autoneighbour>::iterator it;
|
||||
if (neighbours.end() == (it = neighbours.find(aboutId)))
|
||||
@ -914,6 +925,7 @@ int p3disc::addDiscoveryData(std::string fromId, std::string aboutId, struct soc
|
||||
neighbours[aboutId] = an;
|
||||
|
||||
it = neighbours.find(aboutId);
|
||||
new_info = true ;
|
||||
}
|
||||
|
||||
/* it always valid */
|
||||
@ -943,7 +955,11 @@ int p3disc::addDiscoveryData(std::string fromId, std::string aboutId, struct soc
|
||||
it->second.discFlags = as.discFlags;
|
||||
}
|
||||
|
||||
(it->second).neighbour_of[fromId] = as;
|
||||
if(it->second.neighbour_of.find(fromId) == it->second.neighbour_of.end())
|
||||
{
|
||||
(it->second).neighbour_of[fromId] = as;
|
||||
new_info =true ;
|
||||
}
|
||||
|
||||
/* do we update network address info??? */
|
||||
return 1;
|
||||
@ -959,6 +975,9 @@ bool p3disc::potentialproxies(std::string id, std::list<std::string> &proxyIds)
|
||||
{
|
||||
/* find id -> and extract the neighbour_of ids */
|
||||
|
||||
if(id == rsPeers->getOwnId()) // SSL id // This is treated appart, because otherwise we don't receive any disc info about us
|
||||
return rsPeers->getFriendList(proxyIds) ;
|
||||
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<std::string, autoneighbour>::iterator it;
|
||||
|
@ -132,7 +132,7 @@ void removeFriend(std::string ssl_id); //keep tracks of removed friend so we're
|
||||
/* handle network shape */
|
||||
int addDiscoveryData(std::string fromId, std::string aboutId,
|
||||
struct sockaddr_in laddr, struct sockaddr_in raddr,
|
||||
uint32_t flags, time_t ts);
|
||||
uint32_t flags, time_t ts,bool& new_info);
|
||||
|
||||
int idServers();
|
||||
|
||||
|
@ -146,7 +146,7 @@ NetworkDialog::NetworkDialog(QWidget *parent)
|
||||
ui.unvalidGPGkeyWidget->sortItems( 1, Qt::AscendingOrder );
|
||||
|
||||
ui.networkTab->addTab(new TrustView(),QString(tr("Authentication matrix")));
|
||||
ui.networkTab->addTab(new NetworkView(),QString(tr("Network View")));
|
||||
ui.networkTab->addTab(networkview = new NetworkView(),QString(tr("Network View")));
|
||||
|
||||
QString version = "-";
|
||||
std::map<std::string, std::string>::iterator vit;
|
||||
@ -201,6 +201,13 @@ NetworkDialog::NetworkDialog(QWidget *parent)
|
||||
#endif
|
||||
}
|
||||
|
||||
void NetworkDialog::updateNewDiscoveryInfo()
|
||||
{
|
||||
std::cerr << "Received new p3disc info. Updating networkview." << std::endl;
|
||||
networkview->update();
|
||||
networkview->updateDisplay();
|
||||
}
|
||||
|
||||
void NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint point )
|
||||
{
|
||||
std::cerr << "NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint point ) called" << std::endl;
|
||||
|
@ -42,6 +42,7 @@ public slots:
|
||||
std::string loadneighbour();
|
||||
/* void loadneighbour(); */
|
||||
void setLogInfo(QString info, QColor color=QApplication::palette().color(QPalette::WindowText));
|
||||
void updateNewDiscoveryInfo() ;
|
||||
|
||||
|
||||
private slots:
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "NetworkView.h"
|
||||
#include <retroshare/rspeers.h>
|
||||
#include <retroshare/rsdisc.h>
|
||||
|
||||
#include <gpgme.h>
|
||||
|
||||
@ -31,9 +32,14 @@
|
||||
|
||||
#include "gui/elastic/node.h"
|
||||
|
||||
/********
|
||||
* #define DEBUG_NETWORKVIEW
|
||||
********/
|
||||
#define DEBUG_NETWORKVIEW
|
||||
|
||||
/** Constructor */
|
||||
NetworkView::NetworkView(QWidget *parent)
|
||||
: MainPage(parent)
|
||||
: RsAutoUpdatePage(60000,parent)
|
||||
{
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
ui.setupUi(this);
|
||||
@ -45,7 +51,7 @@ NetworkView::NetworkView(QWidget *parent)
|
||||
setMaxFriendLevel(ui.maxFriendLevelSB->value()) ;
|
||||
|
||||
/* add button */
|
||||
connect( ui.refreshButton, SIGNAL( clicked( void ) ), this, SLOT( insertPeers( void ) ) );
|
||||
connect( ui.refreshButton, SIGNAL( clicked( void ) ), this, SLOT( updateDisplay( void ) ) );
|
||||
connect( mScene, SIGNAL( changed ( const QList<QRectF> & ) ), this, SLOT ( changedScene( void ) ) );
|
||||
|
||||
/* Hide Settings frame */
|
||||
@ -53,7 +59,7 @@ NetworkView::NetworkView(QWidget *parent)
|
||||
connect( ui.maxFriendLevelSB, SIGNAL(valueChanged(int)), this, SLOT(setMaxFriendLevel(int)));
|
||||
connect( ui.edgeLengthSB, SIGNAL(valueChanged(int)), this, SLOT(setEdgeLength(int)));
|
||||
|
||||
insertPeers();
|
||||
_should_update = true ;
|
||||
}
|
||||
|
||||
void NetworkView::setEdgeLength(int l)
|
||||
@ -63,21 +69,11 @@ void NetworkView::setEdgeLength(int l)
|
||||
void NetworkView::setMaxFriendLevel(int m)
|
||||
{
|
||||
_max_friend_level = m ;
|
||||
insertPeers() ;
|
||||
updateDisplay() ;
|
||||
}
|
||||
void NetworkView::changedFoFCheckBox( )
|
||||
{
|
||||
insertPeers();
|
||||
}
|
||||
|
||||
void NetworkView::changedDrawSignatures( )
|
||||
{
|
||||
insertPeers();
|
||||
}
|
||||
|
||||
void NetworkView::changedDrawFriends( )
|
||||
{
|
||||
insertPeers();
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
void NetworkView::clearPeerItems()
|
||||
@ -120,47 +116,60 @@ void NetworkView::clearLineItems()
|
||||
class NodeInfo
|
||||
{
|
||||
public:
|
||||
NodeInfo(const std::string& id,uint32_t lev) : gpg_id(id),friend_level(lev) {}
|
||||
NodeInfo(const std::string& _gpg_id,const std::string& _ssl_id,uint32_t lev) : gpg_id(_gpg_id),ssl_id(_ssl_id),friend_level(lev) {}
|
||||
|
||||
std::string gpg_id ;
|
||||
std::string ssl_id ;
|
||||
uint32_t friend_level ;
|
||||
} ;
|
||||
|
||||
void NetworkView::insertPeers()
|
||||
void NetworkView::update()
|
||||
{
|
||||
/* clear graphics scene */
|
||||
ui.graphicsView->clearGraph();
|
||||
_should_update = true ;
|
||||
}
|
||||
void NetworkView::updateDisplay()
|
||||
{
|
||||
if(!isVisible())
|
||||
return ;
|
||||
if(!_should_update)
|
||||
return ;
|
||||
|
||||
/* add all friends */
|
||||
std::string ownId = rsPeers->getGPGOwnId();
|
||||
std::cerr << "NetworkView::insertPeers()" << std::endl;
|
||||
std::string ownGPGId = rsPeers->getGPGOwnId();
|
||||
std::string ownSSLId = rsPeers->getOwnId();
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << "NetworkView::updateDisplay()" << std::endl;
|
||||
#endif
|
||||
|
||||
int i = 0;
|
||||
|
||||
std::map<std::string,GraphWidget::NodeId> node_ids ; // node ids of the created nodes.
|
||||
std::deque<NodeInfo> nodes_to_treat ; // list of nodes to be treated. Used as a queue. The int is the level of friendness
|
||||
std::set<std::string> nodes_considered ; // list of nodes already considered. Eases lookup.
|
||||
|
||||
nodes_to_treat.push_front(NodeInfo(ownId,0)) ; // initialize queue with own id.
|
||||
nodes_considered.insert(ownId) ;
|
||||
nodes_to_treat.push_front(NodeInfo(ownGPGId,ownSSLId,0)) ; // initialize queue with own id.
|
||||
nodes_considered.insert(rsPeers->getOwnId()) ;
|
||||
|
||||
// compute the list of GPG friends
|
||||
|
||||
std::set<std::string> gpg_friends ;
|
||||
std::list<std::string> ssl_friends ;
|
||||
std::list<std::string> friends ;
|
||||
std::set<std::string> ssl_friends ;
|
||||
|
||||
if(!rsPeers->getFriendList(ssl_friends))
|
||||
if(!rsPeers->getFriendList(friends))
|
||||
return ;
|
||||
|
||||
for(std::list<std::string>::const_iterator it(ssl_friends.begin());it!=ssl_friends.end();++it)
|
||||
for(std::list<std::string>::const_iterator it(friends.begin());it!=friends.end();++it)
|
||||
{
|
||||
RsPeerDetails d ;
|
||||
if(!rsPeers->getPeerDetails(*it,d))
|
||||
continue ;
|
||||
|
||||
gpg_friends.insert(d.gpg_id) ;
|
||||
ssl_friends.insert(d.id) ;
|
||||
}
|
||||
std::cerr << "Found " << gpg_friends.size() << " gpg friends." << std::endl ;
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << "Found " << ssl_friends.size() << " gpg friends." << std::endl ;
|
||||
#endif
|
||||
|
||||
// Put own id in queue, and empty the queue, treating all nodes.
|
||||
//
|
||||
@ -168,19 +177,23 @@ void NetworkView::insertPeers()
|
||||
{
|
||||
NodeInfo info(nodes_to_treat.back()) ;
|
||||
nodes_to_treat.pop_back() ;
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << " Poped out of queue: " << info.ssl_id << ", with level " << info.friend_level << std::endl ;
|
||||
#endif
|
||||
std::list<std::string> friendList;
|
||||
rsDisc->getDiscFriends(info.ssl_id, friendList);
|
||||
|
||||
std::cerr << " Poped out of queue: " << info.gpg_id << ", with level " << info.friend_level << std::endl ;
|
||||
RsPeerDetails detail ;
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << " Got a list of " << friendList.size() << " friends for this peer." << std::endl ;
|
||||
#endif
|
||||
// if(!rsPeers->getPeerDetails(info.gpg_id,detail))
|
||||
// {
|
||||
// std::cerr << "Could not request GPG details for node " << info.gpg_id << std::endl ;
|
||||
// continue ;
|
||||
// }
|
||||
|
||||
if(!rsPeers->getPeerDetails(info.gpg_id,detail))
|
||||
// if(info.friend_level <= _max_friend_level && (info.friend_level != 1 || ssl_friends.find(info.ssl_id) != ssl_friends.end()))
|
||||
{
|
||||
std::cerr << "Could not request GPG details for node " << info.gpg_id << std::endl ;
|
||||
continue ;
|
||||
}
|
||||
|
||||
if(info.friend_level <= _max_friend_level && (info.friend_level != 1 || gpg_friends.find(info.gpg_id) != gpg_friends.end()))
|
||||
{
|
||||
|
||||
GraphWidget::NodeType type ;
|
||||
GraphWidget::AuthType auth ;
|
||||
|
||||
@ -196,6 +209,10 @@ void NetworkView::insertPeers()
|
||||
type = GraphWidget::ELASTIC_NODE_TYPE_UNKNOWN ;
|
||||
}
|
||||
|
||||
RsPeerDetails detail ;
|
||||
if (!rsPeers->getPeerDetails(info.ssl_id, detail))
|
||||
continue ;
|
||||
|
||||
switch(detail.validLvl)
|
||||
{
|
||||
case GPGME_VALIDITY_MARGINAL: auth = GraphWidget::ELASTIC_NODE_AUTH_MARGINAL ; break;
|
||||
@ -207,16 +224,22 @@ void NetworkView::insertPeers()
|
||||
default: auth = GraphWidget::ELASTIC_NODE_AUTH_UNKNOWN ; break ;
|
||||
}
|
||||
|
||||
node_ids[info.gpg_id] = ui.graphicsView->addNode(" "+detail.name, detail.name+"@"+info.gpg_id,type,auth);
|
||||
std::cerr << " inserted node " << info.gpg_id << ", type=" << type << ", auth=" << auth << std::endl ;
|
||||
if(_node_ids.find(info.ssl_id) == _node_ids.end())
|
||||
{
|
||||
_node_ids[info.ssl_id] = ui.graphicsView->addNode(" "+detail.name +"("+detail.location+")", "("+detail.name+","+info.ssl_id+","+detail.gpg_id+")",type,auth);
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << " inserted node " << info.ssl_id << ", type=" << type << ", auth=" << auth << std::endl ;
|
||||
std::cerr << " NetworkView::updateDisplay() Added Friend: " << info.ssl_id << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::cerr << "NetworkView::insertPeers() Added Friend: " << info.gpg_id << std::endl;
|
||||
|
||||
for(std::list<std::string>::const_iterator sit(detail.gpgSigners.begin()); sit != detail.gpgSigners.end(); ++sit)
|
||||
for(std::list<std::string>::const_iterator sit(friendList.begin()); sit != friendList.end(); ++sit)
|
||||
if(nodes_considered.find(*sit) == nodes_considered.end())
|
||||
{
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << " adding to queue: " << *sit << ", with level " << info.friend_level+1 << std::endl ;
|
||||
nodes_to_treat.push_front( NodeInfo(*sit,info.friend_level + 1) ) ;
|
||||
#endif
|
||||
nodes_to_treat.push_front( NodeInfo("unknown",*sit,info.friend_level + 1) ) ;
|
||||
nodes_considered.insert(*sit) ;
|
||||
}
|
||||
}
|
||||
@ -224,114 +247,32 @@ void NetworkView::insertPeers()
|
||||
|
||||
/* iterate through all friends */
|
||||
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << "NetworkView::insertSignatures()" << std::endl;
|
||||
|
||||
for(std::map<std::string,GraphWidget::NodeId>::const_iterator it(node_ids.begin()); it != node_ids.end(); it++)
|
||||
{
|
||||
RsPeerDetails detail;
|
||||
if (!rsPeers->getPeerDetails(it->first, detail))
|
||||
continue;
|
||||
|
||||
for(std::list<std::string>::const_iterator sit(detail.gpgSigners.begin()); sit != detail.gpgSigners.end(); sit++)
|
||||
{
|
||||
if(it->first < *sit)
|
||||
{
|
||||
std::cerr << "NetworkView: Adding Arrow: ";
|
||||
std::cerr << *sit << " <-> " << it->first;
|
||||
std::cerr << std::endl;
|
||||
|
||||
if(node_ids.find(*sit) != node_ids.end())
|
||||
ui.graphicsView->addEdge(node_ids[*sit], it->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void NetworkView::insertConnections()
|
||||
{
|
||||
#if 0
|
||||
/* iterate through all friends */
|
||||
std::list<std::string> fids, ids;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
std::string ownId = rsPeers->getGPGOwnId();
|
||||
rsPeers->getPGPAllList(ids);
|
||||
rsPeers->getPGPFriendList(fids);
|
||||
|
||||
std::cerr << "NetworkView::insertConnections()" << std::endl;
|
||||
|
||||
// For the moment, only add friends.
|
||||
for(it = fids.begin(); it != fids.end(); it++)
|
||||
{
|
||||
ui.graphicsView->addEdge("", *it);
|
||||
std::cerr << "NetworkView: Adding Edge: Self -> " << *it;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for(it = ids.begin(); it != ids.end(); it++, i++)
|
||||
{
|
||||
if (rsPeers->isFriend(*it))
|
||||
{
|
||||
/* add own connection (check for it first) */
|
||||
std::list<std::string> &refList = connLists[*it];
|
||||
if (refList.end() == std::find(refList.begin(), refList.end(), ownId))
|
||||
{
|
||||
connLists[ownId].push_back(*it);
|
||||
connLists[*it].push_back(ownId);
|
||||
|
||||
ui.graphicsView->addEdge("", *it);
|
||||
std::cerr << "NetworkView: Adding Edge: Self -> " << *it;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "NetworkView: Already Edge: Self -> " << *it;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::list<std::string> friendList;
|
||||
std::list<std::string>::iterator it2;
|
||||
|
||||
rsDisc->getDiscFriends(*it, friendList);
|
||||
int j = 0;
|
||||
|
||||
for(it2 = friendList.begin(); it2 != friendList.end(); it2++)
|
||||
{
|
||||
if (*it == *it2)
|
||||
continue;
|
||||
|
||||
/* check that we haven't added this one already */
|
||||
std::list<std::string> &refList = connLists[*it];
|
||||
if (refList.end() == std::find(refList.begin(), refList.end(), *it2))
|
||||
{
|
||||
connLists[*it2].push_back(*it);
|
||||
connLists[*it].push_back(*it2);
|
||||
|
||||
ui.graphicsView->addEdge(*it, *it2);
|
||||
std::cerr << "NetworkView: Adding Edge: " << *it << " <-> " << *it2;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "NetworkView: Already Edge: " << *it << " <-> " << *it2;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
for(std::map<std::string,GraphWidget::NodeId>::const_iterator it(_node_ids.begin()); it != _node_ids.end(); it++)
|
||||
{
|
||||
std::list<std::string> friendList ;
|
||||
|
||||
void NetworkView::insertSignatures()
|
||||
{
|
||||
}
|
||||
if(rsDisc->getDiscFriends(it->first,friendList))
|
||||
for(std::list<std::string>::const_iterator sit(friendList.begin()); sit != friendList.end(); sit++)
|
||||
{
|
||||
if(it->first < *sit)
|
||||
{
|
||||
#ifdef DEBUG_NETWORKVIEW
|
||||
std::cerr << "NetworkView: Adding Arrow: ";
|
||||
std::cerr << *sit << " <-> " << it->first;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
void NetworkView::changedScene()
|
||||
{
|
||||
if(_node_ids.find(*sit) != _node_ids.end())
|
||||
ui.graphicsView->addEdge(_node_ids[*sit], it->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_should_update = false ;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,53 +24,53 @@
|
||||
|
||||
#include <QGraphicsScene>
|
||||
|
||||
#include "mainpage.h"
|
||||
#include "RsAutoUpdatePage.h"
|
||||
#include "ui_NetworkView.h"
|
||||
|
||||
|
||||
class NetworkView : public MainPage
|
||||
class NetworkView : public RsAutoUpdatePage
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NetworkView(QWidget *parent = 0);
|
||||
public:
|
||||
NetworkView(QWidget *parent = 0);
|
||||
|
||||
virtual void updateDisplay() ; // derived from RsAutoUpdatePage
|
||||
|
||||
public slots:
|
||||
void update() ;
|
||||
|
||||
private slots:
|
||||
|
||||
void setMaxFriendLevel(int) ;
|
||||
void setEdgeLength(int) ;
|
||||
|
||||
void changedFoFCheckBox( );
|
||||
|
||||
/** Called when Settings button is toggled */
|
||||
void shownwSettingsFrame(bool show);
|
||||
|
||||
private:
|
||||
|
||||
void clearPeerItems();
|
||||
void clearOtherItems();
|
||||
void clearLineItems();
|
||||
|
||||
QGraphicsScene *mScene;
|
||||
|
||||
std::map<std::string, QGraphicsItem *> mPeerItems;
|
||||
std::list<QGraphicsItem *> mOtherItems;
|
||||
|
||||
std::list<QGraphicsItem *> mLineItems;
|
||||
bool mLineChanged;
|
||||
|
||||
|
||||
private slots:
|
||||
/** Qt Designer generated object */
|
||||
Ui::NetworkView ui;
|
||||
int _max_friend_level ;
|
||||
std::map<std::string,GraphWidget::NodeId> _node_ids ;
|
||||
|
||||
void setMaxFriendLevel(int) ;
|
||||
void setEdgeLength(int) ;
|
||||
void insertPeers();
|
||||
void insertSignatures();
|
||||
void insertConnections();
|
||||
|
||||
void changedScene();
|
||||
|
||||
void changedFoFCheckBox( );
|
||||
void changedDrawSignatures( );
|
||||
void changedDrawFriends( );
|
||||
|
||||
/** Called when Settings button is toggled */
|
||||
void shownwSettingsFrame(bool show);
|
||||
|
||||
private:
|
||||
|
||||
void clearPeerItems();
|
||||
void clearOtherItems();
|
||||
void clearLineItems();
|
||||
|
||||
QGraphicsScene *mScene;
|
||||
|
||||
std::map<std::string, QGraphicsItem *> mPeerItems;
|
||||
std::list<QGraphicsItem *> mOtherItems;
|
||||
|
||||
std::list<QGraphicsItem *> mLineItems;
|
||||
bool mLineChanged;
|
||||
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::NetworkView ui;
|
||||
int _max_friend_level ;
|
||||
bool _should_update ;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -125,6 +125,7 @@ GraphWidget::GraphWidget(QWidget *)
|
||||
{
|
||||
QGraphicsScene *scene = new QGraphicsScene(this);
|
||||
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
|
||||
scene->clear() ;
|
||||
scene->setSceneRect(-200, -200, 1000, 1000);
|
||||
setScene(scene);
|
||||
|
||||
@ -167,15 +168,25 @@ GraphWidget::NodeId GraphWidget::addNode(const std::string& node_short_string,co
|
||||
node->setToolTip(QString::fromStdString(node_complete_string)) ;
|
||||
_nodes.push_back(node) ;
|
||||
scene()->addItem(node);
|
||||
node->setPos(-50+rand()%1000/53.0f, -50+rand()%1000/53.0f);
|
||||
node->setPos(rand()%1000/53.0f, rand()%1000/53.0f);
|
||||
std::cerr << "Added node " << _nodes.size()-1 << std::endl ;
|
||||
return _nodes.size()-1 ;
|
||||
}
|
||||
GraphWidget::EdgeId GraphWidget::addEdge(NodeId n1,NodeId n2)
|
||||
{
|
||||
Edge *edge = new Edge(_nodes[n1],_nodes[n2]);
|
||||
scene()->addItem(edge);
|
||||
return 0 ;
|
||||
std::pair<NodeId,NodeId> ed(std::min(n1,n2),std::max(n1,n2)) ;
|
||||
|
||||
if( _edges.find(ed) == _edges.end() )
|
||||
{
|
||||
Edge *edge = new Edge(_nodes[n1],_nodes[n2]);
|
||||
scene()->addItem(edge);
|
||||
_edges[ed] = edge ;
|
||||
std::cerr << "Added edge " << n1 << " - " << n2 << std::endl ;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
void GraphWidget::itemMoved()
|
||||
{
|
||||
if (!timerId)
|
||||
|
@ -42,10 +42,12 @@
|
||||
#ifndef GRAPHWIDGET_H
|
||||
#define GRAPHWIDGET_H
|
||||
|
||||
#include <map>
|
||||
#include <QtGui/QGraphicsView>
|
||||
#include <stdint.h>
|
||||
|
||||
class Node;
|
||||
class Edge;
|
||||
|
||||
class GraphWidget : public QGraphicsView
|
||||
{
|
||||
@ -93,7 +95,7 @@ private:
|
||||
bool mDeterminedBB ;
|
||||
|
||||
std::vector<Node *> _nodes ;
|
||||
std::vector<Node *> _edges ;
|
||||
std::map<std::pair<NodeId,NodeId>,Edge *> _edges ;
|
||||
|
||||
uint32_t _edge_length ;
|
||||
};
|
||||
|
@ -73,7 +73,7 @@ void Node::addEdge(Edge *edge)
|
||||
edge->adjust();
|
||||
}
|
||||
|
||||
QList<Edge *> Node::edges() const
|
||||
const QList<Edge *>& Node::edges() const
|
||||
{
|
||||
return edgeList;
|
||||
}
|
||||
@ -163,8 +163,6 @@ void Node::calculateForces(const double *map,int width,int height,int W,int H,fl
|
||||
yforce += 0.01*pos.y() * val / weight;
|
||||
}
|
||||
|
||||
static const float friction = 0.4 ;
|
||||
|
||||
xforce -= FRICTION_FACTOR * _speedx ;
|
||||
yforce -= FRICTION_FACTOR * _speedy ;
|
||||
|
||||
@ -193,10 +191,13 @@ void Node::calculateForces(const double *map,int width,int height,int W,int H,fl
|
||||
|
||||
bool Node::advance()
|
||||
{
|
||||
if(_type == GraphWidget::ELASTIC_NODE_TYPE_OWN)
|
||||
return false;
|
||||
|
||||
float f = std::max(fabs(newPos.x() - pos().x()), fabs(newPos.y() - pos().y())) ;
|
||||
|
||||
setPos(newPos);
|
||||
return f > 0.05;
|
||||
return f > 0.5;
|
||||
}
|
||||
|
||||
QRectF Node::boundingRect() const
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
Node(const std::string& node_string,GraphWidget::NodeType type,GraphWidget::AuthType auth,GraphWidget *graphWidget);
|
||||
|
||||
void addEdge(Edge *edge);
|
||||
QList<Edge *> edges() const;
|
||||
const QList<Edge *>& edges() const;
|
||||
|
||||
int type() const { return Type; }
|
||||
|
||||
|
@ -71,6 +71,12 @@ std::string NotifyQt::askForPassword(const std::string& key_details,bool prev_is
|
||||
return res ;
|
||||
}
|
||||
|
||||
void NotifyQt::notifyDiscInfoChanged()
|
||||
{
|
||||
std::cerr << "Notifyqt:: notified that discoveryInfo changed" << std::endl ;
|
||||
|
||||
emit discInfoChanged() ;
|
||||
}
|
||||
void NotifyQt::notifyDiskFull(uint32_t loc,uint32_t size_in_mb)
|
||||
{
|
||||
std::cerr << "Notifyqt:: notified that disk is full" << std::endl ;
|
||||
|
@ -46,6 +46,7 @@ class NotifyQt: public QObject, public NotifyBase
|
||||
virtual void notifyPeerStatusChangedSummary();
|
||||
virtual void notifyChannelMsgReadSatusChanged(const std::string& channelId, const std::string& msgId, uint32_t status);
|
||||
|
||||
virtual void notifyDiscInfoChanged() ;
|
||||
virtual std::string askForPassword(const std::string& key_details,bool prev_is_bad) ;
|
||||
|
||||
/* Notify from GUI */
|
||||
@ -80,6 +81,7 @@ class NotifyQt: public QObject, public NotifyBase
|
||||
void publicChatChanged(int type) const ;
|
||||
void privateChatChanged(int list, int type) const ;
|
||||
void groupsChanged(int type) const ;
|
||||
void discInfoChanged() const ;
|
||||
void channelMsgReadSatusChanged(const QString& channelId, const QString& msgId, int status);
|
||||
|
||||
/* Notify from GUI */
|
||||
|
@ -260,7 +260,8 @@ int main(int argc, char *argv[])
|
||||
QObject::connect(notify,SIGNAL(ownAvatarChanged()),w->peersDialog,SLOT(updateAvatar()));
|
||||
QObject::connect(notify,SIGNAL(ownStatusMessageChanged()),w->peersDialog,SLOT(loadmypersonalstatus()));
|
||||
|
||||
QObject::connect(notify,SIGNAL(logInfoChanged(const QString&)),w->networkDialog,SLOT(setLogInfo(QString))) ;
|
||||
QObject::connect(notify,SIGNAL(logInfoChanged(const QString&)) ,w->networkDialog,SLOT(setLogInfo(QString))) ;
|
||||
QObject::connect(notify,SIGNAL(discInfoChanged()) ,w->networkDialog,SLOT(updateNewDiscoveryInfo()),Qt::QueuedConnection) ;
|
||||
QObject::connect(notify,SIGNAL(errorOccurred(int,int,const QString&)),w,SLOT(displayErrorMessage(int,int,const QString&))) ;
|
||||
|
||||
QObject::connect(w->peersDialog,SIGNAL(friendsUpdated()),w->networkDialog,SLOT(insertConnect())) ;
|
||||
|
Loading…
x
Reference in New Issue
Block a user