2008-03-04 16:31:11 -05:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Robert Fernie
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include "NetworkView.h"
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rspeers.h>
|
2009-05-25 07:54:43 -04:00
|
|
|
|
2010-02-14 09:18:53 -05:00
|
|
|
#include <gpgme.h>
|
2009-05-23 11:13:01 -04:00
|
|
|
|
2010-11-01 10:17:18 -04:00
|
|
|
#include <deque>
|
|
|
|
#include <set>
|
2008-03-04 16:31:11 -05:00
|
|
|
#include <iostream>
|
2008-11-02 10:20:42 -05:00
|
|
|
#include <algorithm>
|
2008-03-04 16:31:11 -05:00
|
|
|
|
2009-05-12 19:44:51 -04:00
|
|
|
#include "gui/elastic/node.h"
|
|
|
|
|
2008-03-04 16:31:11 -05:00
|
|
|
/** Constructor */
|
|
|
|
NetworkView::NetworkView(QWidget *parent)
|
|
|
|
: MainPage(parent)
|
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
2010-10-22 16:47:08 -04:00
|
|
|
mScene = new QGraphicsScene();
|
|
|
|
ui.graphicsView->setScene(mScene);
|
2010-11-01 10:17:18 -04:00
|
|
|
ui.graphicsView->setEdgeLength(ui.edgeLengthSB->value()) ;
|
|
|
|
|
|
|
|
setMaxFriendLevel(ui.maxFriendLevelSB->value()) ;
|
2008-03-04 16:31:11 -05:00
|
|
|
|
|
|
|
/* add button */
|
|
|
|
connect( ui.refreshButton, SIGNAL( clicked( void ) ), this, SLOT( insertPeers( void ) ) );
|
2010-10-22 16:47:08 -04:00
|
|
|
connect( mScene, SIGNAL( changed ( const QList<QRectF> & ) ), this, SLOT ( changedScene( void ) ) );
|
2008-03-21 19:31:00 -04:00
|
|
|
|
2010-10-22 16:47:08 -04:00
|
|
|
/* Hide Settings frame */
|
|
|
|
shownwSettingsFrame(false);
|
2010-11-01 10:17:18 -04:00
|
|
|
connect( ui.maxFriendLevelSB, SIGNAL(valueChanged(int)), this, SLOT(setMaxFriendLevel(int)));
|
|
|
|
connect( ui.edgeLengthSB, SIGNAL(valueChanged(int)), this, SLOT(setEdgeLength(int)));
|
2010-10-22 16:47:08 -04:00
|
|
|
|
|
|
|
insertPeers();
|
2008-03-20 19:49:12 -04:00
|
|
|
|
|
|
|
|
2008-03-04 16:31:11 -05:00
|
|
|
/* hide the Tree +/- */
|
|
|
|
// ui.linkTreeWidget -> setRootIsDecorated( false );
|
|
|
|
|
|
|
|
/* Set header resize modes and initial section sizes */
|
|
|
|
// QHeaderView * _header = ui.linkTreeWidget->header () ;
|
|
|
|
// _header->setResizeMode (0, QHeaderView::Interactive);
|
|
|
|
// _header->setResizeMode (1, QHeaderView::Interactive);
|
|
|
|
// _header->setResizeMode (2, QHeaderView::Interactive);
|
|
|
|
//
|
|
|
|
// _header->resizeSection ( 0, 400 );
|
|
|
|
// _header->resizeSection ( 1, 50 );
|
|
|
|
// _header->resizeSection ( 2, 150 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-11-01 10:17:18 -04:00
|
|
|
void NetworkView::setEdgeLength(int l)
|
|
|
|
{
|
|
|
|
ui.graphicsView->setEdgeLength(l);
|
|
|
|
}
|
|
|
|
void NetworkView::setMaxFriendLevel(int m)
|
|
|
|
{
|
|
|
|
_max_friend_level = m ;
|
|
|
|
insertPeers() ;
|
|
|
|
}
|
2008-03-04 16:31:11 -05:00
|
|
|
void NetworkView::changedFoFCheckBox( )
|
|
|
|
{
|
|
|
|
insertPeers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkView::changedDrawSignatures( )
|
|
|
|
{
|
|
|
|
insertPeers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkView::changedDrawFriends( )
|
|
|
|
{
|
|
|
|
insertPeers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkView::clearPeerItems()
|
|
|
|
{
|
|
|
|
std::map<std::string, QGraphicsItem *>::iterator pit;
|
|
|
|
|
|
|
|
for(pit = mPeerItems.begin(); pit != mPeerItems.end(); pit++)
|
|
|
|
{
|
2010-10-22 16:47:08 -04:00
|
|
|
mScene->destroyItemGroup((QGraphicsItemGroup *) pit->second);
|
2008-03-04 16:31:11 -05:00
|
|
|
}
|
|
|
|
mPeerItems.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NetworkView::clearOtherItems()
|
|
|
|
{
|
|
|
|
std::list<QGraphicsItem *>::iterator oit;
|
|
|
|
|
|
|
|
for(oit = mOtherItems.begin(); oit != mOtherItems.end(); oit++)
|
|
|
|
{
|
2010-10-22 16:47:08 -04:00
|
|
|
mScene->removeItem(*oit);
|
2008-03-04 16:31:11 -05:00
|
|
|
delete (*oit);
|
|
|
|
}
|
|
|
|
mOtherItems.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NetworkView::clearLineItems()
|
|
|
|
{
|
|
|
|
std::list<QGraphicsItem *>::iterator oit;
|
|
|
|
|
|
|
|
for(oit = mLineItems.begin(); oit != mLineItems.end(); oit++)
|
|
|
|
{
|
2010-10-22 16:47:08 -04:00
|
|
|
mScene->removeItem(*oit);
|
2008-03-04 16:31:11 -05:00
|
|
|
delete (*oit);
|
|
|
|
}
|
|
|
|
mLineItems.clear();
|
|
|
|
}
|
|
|
|
|
2010-11-01 10:17:18 -04:00
|
|
|
class NodeInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NodeInfo(const std::string& id,uint32_t lev) : gpg_id(id),friend_level(lev) {}
|
|
|
|
|
|
|
|
std::string gpg_id ;
|
|
|
|
uint32_t friend_level ;
|
|
|
|
} ;
|
2008-03-04 16:31:11 -05:00
|
|
|
|
|
|
|
void NetworkView::insertPeers()
|
|
|
|
{
|
|
|
|
/* clear graphics scene */
|
2008-03-20 19:49:12 -04:00
|
|
|
ui.graphicsView->clearGraph();
|
2008-03-04 16:31:11 -05:00
|
|
|
|
|
|
|
/* add all friends */
|
2010-10-22 16:47:08 -04:00
|
|
|
std::string ownId = rsPeers->getGPGOwnId();
|
2010-11-01 10:17:18 -04:00
|
|
|
std::cerr << "NetworkView::insertPeers()" << std::endl;
|
2008-03-04 16:31:11 -05:00
|
|
|
|
2010-11-01 10:17:18 -04:00
|
|
|
int i = 0;
|
2010-10-22 16:47:08 -04:00
|
|
|
|
2010-11-01 10:17:18 -04:00
|
|
|
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.
|
2010-10-22 16:47:08 -04:00
|
|
|
|
2010-11-01 10:17:18 -04:00
|
|
|
nodes_to_treat.push_front(NodeInfo(ownId,0)) ; // initialize queue with own id.
|
|
|
|
nodes_considered.insert(ownId) ;
|
2009-05-23 11:13:01 -04:00
|
|
|
|
2010-11-01 10:17:18 -04:00
|
|
|
// compute the list of GPG friends
|
|
|
|
|
|
|
|
std::set<std::string> gpg_friends ;
|
|
|
|
std::list<std::string> ssl_friends ;
|
2010-10-22 16:47:08 -04:00
|
|
|
|
2010-11-01 10:17:18 -04:00
|
|
|
if(!rsPeers->getFriendList(ssl_friends))
|
|
|
|
return ;
|
2010-10-22 16:47:08 -04:00
|
|
|
|
2010-11-01 10:17:18 -04:00
|
|
|
for(std::list<std::string>::const_iterator it(ssl_friends.begin());it!=ssl_friends.end();++it)
|
2008-03-04 16:31:11 -05:00
|
|
|
{
|
2010-11-01 10:17:18 -04:00
|
|
|
RsPeerDetails d ;
|
|
|
|
if(!rsPeers->getPeerDetails(*it,d))
|
|
|
|
continue ;
|
|
|
|
|
|
|
|
gpg_friends.insert(d.gpg_id) ;
|
|
|
|
}
|
|
|
|
std::cerr << "Found " << gpg_friends.size() << " gpg friends." << std::endl ;
|
2008-03-04 16:31:11 -05:00
|
|
|
|
2010-11-01 10:17:18 -04:00
|
|
|
// Put own id in queue, and empty the queue, treating all nodes.
|
|
|
|
//
|
|
|
|
while(!nodes_to_treat.empty())
|
|
|
|
{
|
|
|
|
NodeInfo info(nodes_to_treat.back()) ;
|
|
|
|
nodes_to_treat.pop_back() ;
|
|
|
|
|
|
|
|
std::cerr << " Poped out of queue: " << info.gpg_id << ", with level " << info.friend_level << std::endl ;
|
|
|
|
RsPeerDetails detail ;
|
|
|
|
|
|
|
|
if(!rsPeers->getPeerDetails(info.gpg_id,detail))
|
2008-03-04 16:31:11 -05:00
|
|
|
{
|
2010-11-01 10:17:18 -04:00
|
|
|
std::cerr << "Could not request GPG details for node " << info.gpg_id << std::endl ;
|
|
|
|
continue ;
|
2008-03-04 16:31:11 -05:00
|
|
|
}
|
2010-11-01 10:17:18 -04:00
|
|
|
|
|
|
|
if(info.friend_level <= _max_friend_level && (info.friend_level != 1 || gpg_friends.find(info.gpg_id) != gpg_friends.end()))
|
2008-03-04 16:31:11 -05:00
|
|
|
{
|
2010-11-01 10:17:18 -04:00
|
|
|
|
|
|
|
GraphWidget::NodeType type ;
|
|
|
|
GraphWidget::AuthType auth ;
|
|
|
|
|
|
|
|
switch(info.friend_level)
|
|
|
|
{
|
|
|
|
case 0: type = GraphWidget::ELASTIC_NODE_TYPE_OWN ;
|
|
|
|
break ;
|
|
|
|
case 1: type = GraphWidget::ELASTIC_NODE_TYPE_FRIEND ;
|
|
|
|
break ;
|
|
|
|
case 2: type = GraphWidget::ELASTIC_NODE_TYPE_F_OF_F ;
|
|
|
|
break ;
|
|
|
|
default:
|
|
|
|
type = GraphWidget::ELASTIC_NODE_TYPE_UNKNOWN ;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(detail.validLvl)
|
|
|
|
{
|
|
|
|
case GPGME_VALIDITY_MARGINAL: auth = GraphWidget::ELASTIC_NODE_AUTH_MARGINAL ; break;
|
|
|
|
case GPGME_VALIDITY_FULL:
|
|
|
|
case GPGME_VALIDITY_ULTIMATE: auth = GraphWidget::ELASTIC_NODE_AUTH_FULL ; break;
|
|
|
|
case GPGME_VALIDITY_UNKNOWN:
|
|
|
|
case GPGME_VALIDITY_UNDEFINED:
|
|
|
|
case GPGME_VALIDITY_NEVER:
|
|
|
|
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 ;
|
2009-05-23 11:13:01 -04:00
|
|
|
}
|
2010-10-22 16:47:08 -04:00
|
|
|
|
2010-11-01 10:17:18 -04:00
|
|
|
std::cerr << "NetworkView::insertPeers() Added Friend: " << info.gpg_id << std::endl;
|
2009-05-25 07:54:43 -04:00
|
|
|
|
2010-11-01 10:17:18 -04:00
|
|
|
for(std::list<std::string>::const_iterator sit(detail.gpgSigners.begin()); sit != detail.gpgSigners.end(); ++sit)
|
|
|
|
if(nodes_considered.find(*sit) == nodes_considered.end())
|
|
|
|
{
|
|
|
|
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) ) ;
|
|
|
|
nodes_considered.insert(*sit) ;
|
|
|
|
}
|
2008-03-04 16:31:11 -05:00
|
|
|
}
|
|
|
|
|
2010-10-22 16:47:08 -04:00
|
|
|
/* iterate through all friends */
|
|
|
|
|
|
|
|
std::cerr << "NetworkView::insertSignatures()" << std::endl;
|
|
|
|
|
2010-11-01 10:17:18 -04:00
|
|
|
for(std::map<std::string,GraphWidget::NodeId>::const_iterator it(node_ids.begin()); it != node_ids.end(); it++)
|
2010-10-22 16:47:08 -04:00
|
|
|
{
|
|
|
|
RsPeerDetails detail;
|
2010-11-01 10:17:18 -04:00
|
|
|
if (!rsPeers->getPeerDetails(it->first, detail))
|
2010-10-22 16:47:08 -04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
for(std::list<std::string>::const_iterator sit(detail.gpgSigners.begin()); sit != detail.gpgSigners.end(); sit++)
|
|
|
|
{
|
2010-11-01 10:17:18 -04:00
|
|
|
if(it->first < *sit)
|
2010-10-22 16:47:08 -04:00
|
|
|
{
|
|
|
|
std::cerr << "NetworkView: Adding Arrow: ";
|
2010-11-01 10:17:18 -04:00
|
|
|
std::cerr << *sit << " <-> " << it->first;
|
2010-10-22 16:47:08 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
if(node_ids.find(*sit) != node_ids.end())
|
2010-11-01 10:17:18 -04:00
|
|
|
ui.graphicsView->addEdge(node_ids[*sit], it->second);
|
2010-10-22 16:47:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-04 16:31:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NetworkView::insertConnections()
|
|
|
|
{
|
2010-10-22 16:47:08 -04:00
|
|
|
#if 0
|
2008-03-20 19:49:12 -04:00
|
|
|
/* iterate through all friends */
|
2009-05-23 11:13:01 -04:00
|
|
|
std::list<std::string> fids, ids;
|
2008-03-20 19:49:12 -04:00
|
|
|
std::list<std::string>::iterator it;
|
2008-03-04 16:31:11 -05:00
|
|
|
|
2010-10-22 16:47:08 -04:00
|
|
|
std::string ownId = rsPeers->getGPGOwnId();
|
|
|
|
rsPeers->getPGPAllList(ids);
|
|
|
|
rsPeers->getPGPFriendList(fids);
|
2008-03-20 19:49:12 -04:00
|
|
|
|
|
|
|
std::cerr << "NetworkView::insertConnections()" << std::endl;
|
2008-03-04 16:31:11 -05:00
|
|
|
|
2009-05-23 11:13:01 -04:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2008-03-04 16:31:11 -05:00
|
|
|
int i = 0;
|
2008-03-20 19:49:12 -04:00
|
|
|
for(it = ids.begin(); it != ids.end(); it++, i++)
|
2008-03-04 16:31:11 -05:00
|
|
|
{
|
2008-03-20 19:49:12 -04:00
|
|
|
if (rsPeers->isFriend(*it))
|
2008-03-04 16:31:11 -05:00
|
|
|
{
|
2008-03-20 19:49:12 -04:00
|
|
|
/* add own connection (check for it first) */
|
|
|
|
std::list<std::string> &refList = connLists[*it];
|
|
|
|
if (refList.end() == std::find(refList.begin(), refList.end(), ownId))
|
2008-03-04 16:31:11 -05:00
|
|
|
{
|
2008-03-20 19:49:12 -04:00
|
|
|
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;
|
2008-03-04 16:31:11 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-20 19:49:12 -04:00
|
|
|
std::list<std::string> friendList;
|
|
|
|
std::list<std::string>::iterator it2;
|
2008-03-04 16:31:11 -05:00
|
|
|
|
2008-03-20 19:49:12 -04:00
|
|
|
rsDisc->getDiscFriends(*it, friendList);
|
|
|
|
int j = 0;
|
2008-03-04 16:31:11 -05:00
|
|
|
|
2008-03-20 19:49:12 -04:00
|
|
|
for(it2 = friendList.begin(); it2 != friendList.end(); it2++)
|
|
|
|
{
|
|
|
|
if (*it == *it2)
|
|
|
|
continue;
|
2008-03-04 16:31:11 -05:00
|
|
|
|
2008-03-20 19:49:12 -04:00
|
|
|
/* 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);
|
2008-03-04 16:31:11 -05:00
|
|
|
|
2008-03-20 19:49:12 -04:00
|
|
|
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;
|
|
|
|
}
|
2008-03-04 16:31:11 -05:00
|
|
|
}
|
|
|
|
}
|
2009-05-23 11:13:01 -04:00
|
|
|
#endif
|
|
|
|
|
2008-03-04 16:31:11 -05:00
|
|
|
}
|
|
|
|
|
2009-05-23 11:13:01 -04:00
|
|
|
void NetworkView::insertSignatures()
|
|
|
|
{
|
|
|
|
}
|
2008-03-04 16:31:11 -05:00
|
|
|
|
|
|
|
void NetworkView::changedScene()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-03-21 19:31:00 -04:00
|
|
|
/**
|
|
|
|
Toggles the Settings pane on and off, changes toggle button text
|
|
|
|
*/
|
|
|
|
void NetworkView::shownwSettingsFrame(bool show)
|
|
|
|
{
|
|
|
|
if (show) {
|
2010-11-01 10:17:18 -04:00
|
|
|
// ui.viewsettingsframe->setVisible(true);
|
|
|
|
// ui.nviewsettingsButton->setChecked(true);
|
|
|
|
// ui.nviewsettingsButton->setToolTip(tr("Hide Settings"));
|
2008-03-21 19:31:00 -04:00
|
|
|
} else {
|
2010-11-01 10:17:18 -04:00
|
|
|
// ui.viewsettingsframe->setVisible(false);
|
|
|
|
// ui.nviewsettingsButton->setChecked(false);
|
|
|
|
// ui.nviewsettingsButton->setToolTip(tr("Show Settings"));
|
2008-03-21 19:31:00 -04:00
|
|
|
}
|
|
|
|
}
|
2008-03-04 16:31:11 -05:00
|
|
|
|