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"
|
|
|
|
#include "rsiface/rspeers.h"
|
|
|
|
#include "rsiface/rsdisc.h"
|
|
|
|
|
2009-05-25 07:54:43 -04:00
|
|
|
#include "rsiface/rsinit.h"
|
|
|
|
|
|
|
|
#ifdef RS_USE_PGPSSL
|
|
|
|
#include <gpgme.h>
|
|
|
|
#endif
|
2009-05-23 11:13:01 -04:00
|
|
|
|
2008-03-04 16:31:11 -05:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QGraphicsItem>
|
|
|
|
|
|
|
|
#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);
|
|
|
|
|
2008-03-20 19:49:12 -04:00
|
|
|
//mScene = new QGraphicsScene();
|
|
|
|
//ui.graphicsView->setScene(mScene);
|
2008-03-04 16:31:11 -05:00
|
|
|
|
|
|
|
/* add button */
|
|
|
|
connect( ui.refreshButton, SIGNAL( clicked( void ) ), this, SLOT( insertPeers( void ) ) );
|
2009-05-09 16:53:40 -04:00
|
|
|
//connect( mScene, SIGNAL( changed ( const QList<QRectF> & ) ), this, SLOT ( changedScene( void ) ) );
|
2008-03-21 19:31:00 -04:00
|
|
|
|
|
|
|
/* Hide Settings frame */
|
|
|
|
shownwSettingsFrame(false);
|
|
|
|
connect( ui.nviewsettingsButton, SIGNAL(toggled(bool)), this, SLOT(shownwSettingsFrame(bool)));
|
2009-05-09 16:53:40 -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 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkView::peerCustomPopupMenu( QPoint point )
|
|
|
|
{
|
|
|
|
|
|
|
|
QMenu contextMnu( this );
|
|
|
|
QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
|
|
|
|
|
|
|
|
//QAction * voteupAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Vote Link Up" ), this );
|
|
|
|
//connect( voteupAct , SIGNAL( triggered() ), this, SLOT( voteup() ) );
|
|
|
|
|
|
|
|
contextMnu.clear();
|
|
|
|
//contextMnu.addAction(voteupAct);
|
|
|
|
contextMnu.exec( mevent->globalPos() );
|
|
|
|
}
|
|
|
|
|
|
|
|
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++)
|
|
|
|
{
|
2008-03-20 19:49:12 -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++)
|
|
|
|
{
|
2008-03-20 19:49:12 -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++)
|
|
|
|
{
|
2008-03-20 19:49:12 -04:00
|
|
|
//mScene->removeItem(*oit);
|
2008-03-04 16:31:11 -05:00
|
|
|
delete (*oit);
|
|
|
|
}
|
|
|
|
mLineItems.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 */
|
|
|
|
std::list<std::string> ids;
|
|
|
|
std::list<std::string>::iterator it;
|
2009-05-23 11:13:01 -04:00
|
|
|
rsPeers->getPGPAllList(ids);
|
|
|
|
std::string ownId = rsPeers->getPGPOwnId();
|
2008-03-04 16:31:11 -05:00
|
|
|
|
|
|
|
std::cerr << "NetworkView::insertPeers()" << std::endl;
|
|
|
|
|
2009-05-23 11:13:01 -04:00
|
|
|
/* get the list of friends' issuers, as we flag them specially */
|
|
|
|
std::list<std::string> fids;
|
|
|
|
rsPeers->getPGPFriendList(fids);
|
|
|
|
|
|
|
|
|
2008-03-04 16:31:11 -05:00
|
|
|
int i = 0;
|
2008-03-20 19:49:12 -04:00
|
|
|
uint32_t type = 0;
|
2008-03-04 16:31:11 -05:00
|
|
|
for(it = ids.begin(); it != ids.end(); it++, i++)
|
|
|
|
{
|
2009-05-23 11:13:01 -04:00
|
|
|
if (*it == ownId)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2008-03-04 16:31:11 -05:00
|
|
|
|
2009-05-25 07:54:43 -04:00
|
|
|
#ifdef RS_USE_PGPSSL
|
|
|
|
|
2009-05-23 11:13:01 -04:00
|
|
|
/* *** */
|
|
|
|
RsPeerDetails detail;
|
|
|
|
if (!rsPeers->getPeerDetails(*it, detail))
|
2008-03-04 16:31:11 -05:00
|
|
|
{
|
2009-05-23 11:13:01 -04:00
|
|
|
continue;
|
2008-03-04 16:31:11 -05:00
|
|
|
}
|
2009-05-25 07:45:07 -04:00
|
|
|
switch(detail.validLvl)
|
2008-03-04 16:31:11 -05:00
|
|
|
{
|
2009-05-23 11:13:01 -04:00
|
|
|
default:
|
|
|
|
case GPGME_VALIDITY_UNKNOWN:
|
|
|
|
case GPGME_VALIDITY_UNDEFINED:
|
|
|
|
case GPGME_VALIDITY_NEVER:
|
|
|
|
/* lots of fall through */
|
|
|
|
type = ELASTIC_NODE_TYPE_FOF;
|
|
|
|
break;
|
2009-05-12 19:44:51 -04:00
|
|
|
|
2009-05-23 11:13:01 -04:00
|
|
|
case GPGME_VALIDITY_MARGINAL:
|
|
|
|
/* lots of fall through */
|
2009-05-12 19:44:51 -04:00
|
|
|
type = ELASTIC_NODE_TYPE_MARGINALAUTH;
|
2009-05-23 11:13:01 -04:00
|
|
|
break;
|
2008-03-04 16:31:11 -05:00
|
|
|
|
2009-05-23 11:13:01 -04:00
|
|
|
|
|
|
|
case GPGME_VALIDITY_FULL:
|
|
|
|
case GPGME_VALIDITY_ULTIMATE:
|
|
|
|
/* lots of fall through */
|
|
|
|
type = ELASTIC_NODE_TYPE_AUTHED;
|
|
|
|
|
|
|
|
if (fids.end() != std::find(fids.begin(), fids.end(), *it))
|
|
|
|
{
|
|
|
|
type = ELASTIC_NODE_TYPE_FRIEND;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ui.graphicsView->addNode(type, *it, detail.name);
|
2009-05-25 07:54:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* *** */
|
|
|
|
std::string name = rsPeers->getPeerName(*it);
|
|
|
|
|
|
|
|
if (rsPeers->isFriend(*it))
|
|
|
|
{
|
|
|
|
type = ELASTIC_NODE_TYPE_FRIEND;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RsPeerDetails detail;
|
|
|
|
rsPeers->getPeerDetails(*it, detail);
|
|
|
|
|
|
|
|
if(detail.trustLvl > RS_TRUST_LVL_MARGINAL)
|
|
|
|
{
|
|
|
|
type = ELASTIC_NODE_TYPE_AUTHED;
|
|
|
|
}
|
|
|
|
else if (detail.trustLvl >= RS_TRUST_LVL_MARGINAL)
|
|
|
|
{
|
|
|
|
type = ELASTIC_NODE_TYPE_MARGINALAUTH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = ELASTIC_NODE_TYPE_FOF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ui.graphicsView->addNode(type, *it, name);
|
|
|
|
#endif
|
|
|
|
|
2008-03-04 16:31:11 -05:00
|
|
|
std::cerr << "NetworkView::insertPeers() Added Friend: " << *it << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
insertConnections();
|
2009-05-23 11:13:01 -04:00
|
|
|
insertSignatures();
|
2008-03-04 16:31:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NetworkView::insertConnections()
|
|
|
|
{
|
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
|
|
|
|
2009-05-23 11:13:01 -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;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
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()
|
|
|
|
{
|
|
|
|
/* iterate through all friends */
|
|
|
|
std::list<std::string> ids;
|
|
|
|
std::list<std::string>::iterator it, sit;
|
|
|
|
std::string ownId = rsPeers->getPGPOwnId();
|
|
|
|
|
|
|
|
rsPeers->getPGPAllList(ids);
|
|
|
|
|
|
|
|
std::cerr << "NetworkView::insertSignatures()" << std::endl;
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
for(it = ids.begin(); it != ids.end(); it++, i++)
|
|
|
|
{
|
|
|
|
RsPeerDetails detail;
|
|
|
|
if (!rsPeers->getPeerDetails(*it, detail))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(sit = detail.signers.begin(); sit != detail.signers.end(); sit++)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (*it != *sit)
|
|
|
|
{
|
|
|
|
std::cerr << "NetworkView: Adding Arrow: ";
|
|
|
|
std::cerr << *sit << " <-> " << *it;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
ui.graphicsView->addArrow(*sit, *it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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) {
|
|
|
|
ui.viewsettingsframe->setVisible(true);
|
|
|
|
ui.nviewsettingsButton->setChecked(true);
|
|
|
|
ui.nviewsettingsButton->setToolTip(tr("Hide Settings"));
|
|
|
|
} else {
|
|
|
|
ui.viewsettingsframe->setVisible(false);
|
|
|
|
ui.nviewsettingsButton->setChecked(false);
|
|
|
|
ui.nviewsettingsButton->setToolTip(tr("Show Settings"));
|
|
|
|
}
|
|
|
|
}
|
2008-03-04 16:31:11 -05:00
|
|
|
|