2007-11-14 22:18:48 -05:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2006 , crypton
*
* 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 .
2008-08-31 12:52:35 -04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <QFile>
2007-11-14 22:18:48 -05:00
# include <QFileInfo>
2009-07-10 18:49:46 -04:00
# include <QCursor>
2008-08-31 12:52:35 -04:00
2007-11-14 22:18:48 -05:00
# include "rshare.h"
2008-03-21 19:31:00 -04:00
# include "common/vmessagebox.h"
2008-08-31 12:52:35 -04:00
# include "util/rsversion.h"
2007-11-14 22:18:48 -05:00
# include "NetworkDialog.h"
2008-03-17 09:14:17 -04:00
# include "NetworkView.h"
2008-11-15 09:29:34 -05:00
# include "TrustView.h"
2007-11-14 22:18:48 -05:00
# include "connect/ConnectDialog.h"
# include "rsiface/rsiface.h"
2008-01-25 03:49:40 -05:00
# include "rsiface/rspeers.h"
2009-05-23 11:13:01 -04:00
/* for GPGME */
# include "rsiface/rsinit.h"
2009-05-25 07:54:43 -04:00
# ifdef RS_USE_PGPSSL
# include <gpgme.h>
# endif
2009-05-23 11:13:01 -04:00
2007-11-14 22:18:48 -05:00
# include <sstream>
2009-04-30 22:39:57 -04:00
# include <QTimer>
2008-03-21 19:31:00 -04:00
# include <QTime>
2007-11-14 22:18:48 -05:00
# include <QContextMenuEvent>
# include <QMenu>
# include <QCursor>
# include <QPoint>
# include <QMouseEvent>
# include <QPixmap>
2008-08-31 12:52:35 -04:00
# include <QHeaderView>
2009-05-07 18:43:11 -04:00
# include "connect/ConfCertDialog.h"
2008-08-31 12:52:35 -04:00
/* Images for context menu icons */
2007-11-14 22:18:48 -05:00
# define IMAGE_LOADCERT ": / images / loadcert16.png"
# define IMAGE_PEERDETAILS ": / images / peerdetails_16x16.png"
# define IMAGE_AUTH ": / images / encrypted16.png"
2009-03-26 11:45:58 -04:00
# define IMAGE_MAKEFRIEND ": / images / user / add_user16.png"
2007-11-14 22:18:48 -05:00
/* Images for Status icons */
2008-08-08 10:32:13 -04:00
# define IMAGE_AUTHED ": / images / accepted16.png"
# define IMAGE_DENIED ": / images / denied16.png"
2008-12-23 12:59:58 -05:00
# define IMAGE_TRUSTED ": / images / rs-2.png"
2008-08-31 12:52:35 -04:00
2007-11-14 22:18:48 -05:00
RsCertId getNeighRsCertId ( QTreeWidgetItem * i ) ;
2008-07-09 05:53:47 -04:00
/******
* # define NET_DEBUG 1
* * * * */
2008-08-31 12:52:35 -04:00
/** Constructor */
NetworkDialog : : NetworkDialog ( QWidget * parent )
2007-11-14 22:18:48 -05:00
: MainPage ( parent ) , connectdialog ( NULL )
2008-08-31 12:52:35 -04:00
{
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
2009-07-10 20:45:17 -04:00
/* Create RshareSettings object */
_settings = new RshareSettings ( ) ;
2008-08-31 12:52:35 -04:00
connect ( ui . connecttreeWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( connecttreeWidgetCostumPopupMenu ( QPoint ) ) ) ;
2007-11-14 22:18:48 -05:00
/* create a single connect dialog */
connectdialog = new ConnectDialog ( ) ;
2008-03-21 19:31:00 -04:00
connect ( ui . infoLog , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayInfoLogMenu ( const QPoint & ) ) ) ;
2007-11-14 22:18:48 -05:00
/* hide the Tree +/- */
ui . connecttreeWidget - > setRootIsDecorated ( false ) ;
/* Set header resize modes and initial section sizes */
2008-08-31 12:52:35 -04:00
QHeaderView * _header = ui . connecttreeWidget - > header ( ) ;
_header - > setResizeMode ( 0 , QHeaderView : : Custom ) ;
_header - > setResizeMode ( 1 , QHeaderView : : Interactive ) ;
2007-11-14 22:18:48 -05:00
_header - > setResizeMode ( 2 , QHeaderView : : Interactive ) ;
2008-08-31 12:52:35 -04:00
_header - > setResizeMode ( 3 , QHeaderView : : Interactive ) ;
2007-11-14 22:18:48 -05:00
_header - > setResizeMode ( 4 , QHeaderView : : Interactive ) ;
2008-08-31 12:52:35 -04:00
_header - > setResizeMode ( 5 , QHeaderView : : Interactive ) ;
2007-11-14 22:18:48 -05:00
_header - > setResizeMode ( 6 , QHeaderView : : Interactive ) ;
2008-08-31 12:52:35 -04:00
_header - > setResizeMode ( 7 , QHeaderView : : Interactive ) ;
2007-11-14 22:18:48 -05:00
_header - > setResizeMode ( 8 , QHeaderView : : Interactive ) ;
2008-08-31 12:52:35 -04:00
_header - > setResizeMode ( 9 , QHeaderView : : Interactive ) ;
2007-11-14 22:18:48 -05:00
_header - > resizeSection ( 0 , 25 ) ;
_header - > resizeSection ( 1 , 100 ) ;
_header - > resizeSection ( 2 , 100 ) ;
_header - > resizeSection ( 3 , 100 ) ;
_header - > resizeSection ( 4 , 100 ) ;
_header - > resizeSection ( 5 , 200 ) ;
_header - > resizeSection ( 6 , 100 ) ;
_header - > resizeSection ( 7 , 100 ) ;
_header - > resizeSection ( 8 , 100 ) ;
_header - > resizeSection ( 9 , 100 ) ;
2008-03-17 09:14:17 -04:00
2008-08-08 10:32:13 -04:00
// set header text aligment
QTreeWidgetItem * headerItem = ui . connecttreeWidget - > headerItem ( ) ;
headerItem - > setTextAlignment ( 0 , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
headerItem - > setTextAlignment ( 1 , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
2009-04-29 13:07:28 -04:00
headerItem - > setTextAlignment ( 2 , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
2008-08-08 10:32:13 -04:00
headerItem - > setTextAlignment ( 3 , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
headerItem - > setTextAlignment ( 4 , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
headerItem - > setTextAlignment ( 5 , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
headerItem - > setTextAlignment ( 6 , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
headerItem - > setTextAlignment ( 7 , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
headerItem - > setTextAlignment ( 8 , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
headerItem - > setTextAlignment ( 9 , Qt : : AlignHCenter | Qt : : AlignVCenter ) ;
2009-05-08 14:26:57 -04:00
/*networkview = new NetworkView(ui.networkviewTab);
2008-11-15 09:29:34 -05:00
QVBoxLayout * layout = new QVBoxLayout ;
layout - > addWidget ( networkview ) ;
ui . networkviewTab - > setLayout ( layout ) ;
layout - > setSpacing ( 0 ) ;
2009-05-08 14:26:57 -04:00
layout - > setMargin ( 0 ) ; */
2008-11-15 09:29:34 -05:00
2009-05-08 14:26:57 -04:00
ui . networkTab - > addTab ( new NetworkView ( ) , QString ( tr ( " Network View " ) ) ) ;
2009-04-29 13:48:25 -04:00
ui . networkTab - > addTab ( new TrustView ( ) , QString ( tr ( " Trust matrix " ) ) ) ;
2007-11-14 22:18:48 -05:00
2008-08-31 12:52:35 -04:00
// Set Log infos
setLogInfo ( tr ( " RetroShare %1 started. " , " e.g: RetroShare v0.x started. " ) . arg ( retroshareVersion ( ) ) ) ;
2008-03-21 19:31:00 -04:00
setLogInfo ( tr ( " Welcome to RetroShare. " ) , QString : : fromUtf8 ( " blue " ) ) ;
2009-04-30 22:39:57 -04:00
2009-04-29 13:48:25 -04:00
QMenu * menu = new QMenu ( tr ( " View " ) ) ;
2009-04-29 13:07:28 -04:00
menu - > addAction ( ui . actionTabsright ) ;
menu - > addAction ( ui . actionTabswest ) ;
menu - > addAction ( ui . actionTabssouth ) ;
2009-04-29 13:48:25 -04:00
menu - > addAction ( ui . actionTabsnorth ) ;
menu - > addSeparator ( ) ;
menu - > addAction ( ui . actionTabsTriangular ) ;
menu - > addAction ( ui . actionTabsRounded ) ;
2009-04-29 13:07:28 -04:00
ui . viewButton - > setMenu ( menu ) ;
2009-04-30 22:39:57 -04:00
QTimer * timer = new QTimer ( this ) ;
2009-07-10 18:49:46 -04:00
connect ( timer , SIGNAL ( timeout ( ) ) , this , SLOT ( getNetworkStatus ( ) ) ) ;
2009-04-30 22:39:57 -04:00
timer - > start ( 100000 ) ;
2009-05-03 20:30:24 -04:00
QTimer * timer2 = new QTimer ( this ) ;
2009-07-10 18:49:46 -04:00
connect ( timer2 , SIGNAL ( timeout ( ) ) , this , SLOT ( updateNetworkStatus ( ) ) ) ;
2009-05-03 20:30:24 -04:00
timer2 - > start ( 1000 ) ;
getNetworkStatus ( ) ;
updateNetworkStatus ( ) ;
2009-05-13 12:53:20 -04:00
//load();
2009-07-10 20:45:17 -04:00
loadtabsettings ( ) ;
2009-04-30 22:39:57 -04:00
2007-11-14 22:18:48 -05:00
2008-08-31 12:52:35 -04:00
/* Hide platform specific features */
# ifdef Q_WS_WIN
# endif
}
void NetworkDialog : : connecttreeWidgetCostumPopupMenu ( QPoint point )
{
QTreeWidgetItem * wi = getCurrentNeighbour ( ) ;
if ( ! wi )
return ;
// return ;
QMenu contextMnu ( this ) ;
QMouseEvent * mevent = new QMouseEvent ( QEvent : : MouseButtonPress , point , Qt : : RightButton , Qt : : RightButton , Qt : : NoModifier ) ;
contextMnu . clear ( ) ;
2009-04-07 17:01:45 -04:00
std : : string peer_id = wi - > text ( 9 ) . toStdString ( ) ;
2009-03-21 16:29:23 -04:00
2009-04-07 17:01:45 -04:00
// That's what context menus are made for
RsPeerDetails detail ;
if ( ! rsPeers - > getPeerDetails ( peer_id , detail ) ) // that is not suppose to fail.
return ;
2008-08-31 12:52:35 -04:00
2009-04-07 17:01:45 -04:00
if ( peer_id ! = rsPeers - > getOwnId ( ) )
2009-05-23 11:13:01 -04:00
{
2009-04-07 17:01:45 -04:00
if ( detail . state & RS_PEER_STATE_FRIEND )
{
2009-04-09 16:19:03 -04:00
denyFriendAct = new QAction ( QIcon ( IMAGE_DENIED ) , tr ( " Deny friend " ) , this ) ;
2009-04-07 17:01:45 -04:00
connect ( denyFriendAct , SIGNAL ( triggered ( ) ) , this , SLOT ( denyFriend ( ) ) ) ;
contextMnu . addAction ( denyFriendAct ) ;
}
else // not a friend
{
2009-05-25 07:45:07 -04:00
if ( detail . validLvl > RS_TRUST_LVL_MARGINAL ) // it's a denied old friend.
2009-04-07 17:01:45 -04:00
makefriendAct = new QAction ( QIcon ( IMAGE_MAKEFRIEND ) , tr ( " Accept friend " ) , this ) ;
else
makefriendAct = new QAction ( QIcon ( IMAGE_MAKEFRIEND ) , tr ( " Make friend " ) , this ) ;
connect ( makefriendAct , SIGNAL ( triggered ( ) ) , this , SLOT ( makeFriend ( ) ) ) ;
contextMnu . addAction ( makefriendAct ) ;
# ifdef TODO
2009-05-25 07:45:07 -04:00
if ( detail . validLvl > RS_TRUST_LVL_MARGINAL ) // it's a denied old friend.
2009-04-07 17:01:45 -04:00
{
deleteCertAct = new QAction ( QIcon ( IMAGE_PEERDETAILS ) , tr ( " Delete certificate " ) , this ) ;
connect ( deleteCertAct , SIGNAL ( triggered ( ) ) , this , SLOT ( deleteCert ( ) ) ) ;
contextMnu . addAction ( deleteCertAct ) ;
}
# endif
}
2009-05-23 11:13:01 -04:00
}
2009-04-07 17:01:45 -04:00
peerdetailsAct = new QAction ( QIcon ( IMAGE_PEERDETAILS ) , tr ( " Peer details... " ) , this ) ;
connect ( peerdetailsAct , SIGNAL ( triggered ( ) ) , this , SLOT ( peerdetails ( ) ) ) ;
contextMnu . addAction ( peerdetailsAct ) ;
contextMnu . exec ( mevent - > globalPos ( ) ) ;
}
void NetworkDialog : : denyFriend ( )
{
QTreeWidgetItem * wi = getCurrentNeighbour ( ) ;
std : : string peer_id = wi - > text ( 9 ) . toStdString ( ) ;
rsPeers - > removeFriend ( peer_id ) ;
insertConnect ( ) ;
}
void NetworkDialog : : deleteCert ( )
{
# ifdef TODO
// do whatever is needed to remove the certificate completely, hopping this
// will eventually remove the signature we've stamped on it.
std : : cout < < " Deleting friend ! " < < std : : endl ;
QTreeWidgetItem * wi = getCurrentNeighbour ( ) ;
std : : string peer_id = wi - > text ( 9 ) . toStdString ( ) ;
rsPeers - > deleteCertificate ( peer_id ) ;
2008-08-31 12:52:35 -04:00
2009-04-07 17:01:45 -04:00
insertConnect ( ) ;
# endif
2008-08-31 12:52:35 -04:00
}
2009-03-21 16:29:23 -04:00
void NetworkDialog : : makeFriend ( )
{
QTreeWidgetItem * wi = getCurrentNeighbour ( ) ;
std : : string authId = wi - > text ( 9 ) . toStdString ( ) ;
rsPeers - > AuthCertificate ( authId , " " ) ;
rsPeers - > addFriend ( authId ) ;
insertConnect ( ) ;
}
2008-08-31 12:52:35 -04:00
/** Shows Peer Information/Auth Dialog */
void NetworkDialog : : peerdetails ( )
2008-07-09 05:53:47 -04:00
{
2009-05-07 18:43:11 -04:00
#if 0
2008-07-09 05:53:47 -04:00
# ifdef NET_DEBUG
2007-11-14 22:18:48 -05:00
std : : cerr < < " ConnectionsDialog::peerdetails() " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
2009-05-07 18:43:11 -04:00
QTreeWidgetItem * wi =
2007-11-14 22:18:48 -05:00
if ( ! wi )
return ;
RsCertId id = getNeighRsCertId ( wi ) ;
std : : ostringstream out ;
out < < id ;
showpeerdetails ( out . str ( ) ) ;
2009-05-07 18:43:11 -04:00
# endif
ConfCertDialog : : show ( getCurrentNeighbour ( ) - > text ( 9 ) . toStdString ( ) ) ;
2007-11-14 22:18:48 -05:00
}
/** Shows Peer Information/Auth Dialog */
void NetworkDialog : : showpeerdetails ( std : : string id )
{
2008-07-09 05:53:47 -04:00
# ifdef NET_DEBUG
2007-11-14 22:18:48 -05:00
std : : cerr < < " ConnectionsDialog::showpeerdetails() " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
if ( ( connectdialog ) & & ( connectdialog - > loadPeer ( id ) ) )
{
connectdialog - > show ( ) ;
}
}
2008-08-31 12:52:35 -04:00
/** Open a QFileDialog to browse for a pem/pqi file. */
void NetworkDialog : : loadcert ( )
{
/* Create a new input dialog, which allows users to create files, too */
QFileDialog * dialog = new QFileDialog ( this , tr ( " Select a pem/pqi File " ) ) ;
//dialog->setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir());
//dialog->selectFile(QFileInfo(ui.lineTorConfig->text()).fileName());
dialog - > setFileMode ( QFileDialog : : AnyFile ) ;
dialog - > setReadOnly ( false ) ;
/* Prompt the user to select a file or create a new one */
if ( ! dialog - > exec ( ) | | dialog - > selectedFiles ( ) . isEmpty ( ) ) {
return ;
}
QString filename = QDir : : convertSeparators ( dialog - > selectedFiles ( ) . at ( 0 ) ) ;
/* Check if the file exists */
QFile torrcFile ( filename ) ;
if ( ! QFileInfo ( filename ) . exists ( ) ) {
/* The given file does not exist. Should we create it? */
int response = VMessageBox : : question ( this ,
tr ( " File Not Found " ) ,
tr ( " %1 does not exist. Would you like to create it? " )
. arg ( filename ) ,
VMessageBox : : Yes , VMessageBox : : No ) ;
if ( response = = VMessageBox : : No ) {
/* Don't create it. Just bail. */
return ;
}
/* Attempt to create the specified file */
if ( ! torrcFile . open ( QIODevice : : WriteOnly ) ) {
VMessageBox : : warning ( this ,
tr ( " Failed to Create File " ) ,
tr ( " Unable to create %1 [%2] " ) . arg ( filename )
. arg ( torrcFile . errorString ( ) ) ,
VMessageBox : : Ok ) ;
return ;
}
}
//ui.lineTorConfig->setText(filename);
}
2007-11-14 22:18:48 -05:00
# include <sstream>
/* get the list of Neighbours from the RsIface. */
void NetworkDialog : : insertConnect ( )
{
2008-01-25 03:49:40 -05:00
if ( ! rsPeers )
{
return ;
}
2007-11-14 22:18:48 -05:00
2008-01-25 03:49:40 -05:00
std : : list < std : : string > neighs ;
std : : list < std : : string > : : iterator it ;
rsPeers - > getOthersList ( neighs ) ;
2007-11-14 22:18:48 -05:00
/* get a link to the table */
QTreeWidget * connectWidget = ui . connecttreeWidget ;
QTreeWidgetItem * oldSelect = getCurrentNeighbour ( ) ;
QTreeWidgetItem * newSelect = NULL ;
std : : string oldId ;
if ( oldSelect )
{
oldId = ( oldSelect - > text ( 9 ) ) . toStdString ( ) ;
}
QList < QTreeWidgetItem * > items ;
for ( it = neighs . begin ( ) ; it ! = neighs . end ( ) ; it + + )
{
2008-01-25 03:49:40 -05:00
RsPeerDetails detail ;
if ( ! rsPeers - > getPeerDetails ( * it , detail ) )
{
continue ; /* BAD */
}
2007-11-14 22:18:48 -05:00
/* make a widget per friend */
QTreeWidgetItem * item = new QTreeWidgetItem ( ( QTreeWidget * ) 0 ) ;
/* add all the labels */
2008-01-25 03:49:40 -05:00
/* (0) Status Icon */
item - > setText ( 0 , " " ) ;
2007-11-14 22:18:48 -05:00
/* (1) Accept/Deny */
2008-01-25 03:49:40 -05:00
if ( detail . state & RS_PEER_STATE_FRIEND )
2009-04-05 09:04:18 -04:00
item - > setText ( 1 , tr ( " Trusted " ) ) ;
2008-01-25 03:49:40 -05:00
else
2009-04-05 09:04:18 -04:00
item - > setText ( 1 , tr ( " Denied " ) ) ;
2008-01-25 03:49:40 -05:00
2009-04-05 09:04:18 -04:00
if ( rsPeers - > isTrustingMe ( detail . id ) | | detail . lastConnect > 0 )
2009-04-29 13:48:25 -04:00
item - > setText ( 2 , tr ( " Is trusting me " ) ) ;
2009-04-05 09:04:18 -04:00
else
2009-04-29 13:48:25 -04:00
item - > setText ( 2 , tr ( " Unknown " ) ) ;
2008-01-25 03:49:40 -05:00
2007-11-14 22:18:48 -05:00
/* (3) Last Connect */
2008-01-25 03:49:40 -05:00
{
std : : ostringstream out ;
2008-09-21 18:04:49 -04:00
// Show anouncement if a friend never was connected.
2009-04-05 09:04:18 -04:00
if ( detail . lastConnect = = 0 )
2009-04-29 13:48:25 -04:00
item - > setText ( 3 , tr ( " Never seen " ) ) ;
2009-04-05 09:04:18 -04:00
else
{
2008-09-21 18:04:49 -04:00
// Dont Show a timestamp in RS calculate the day
2008-09-22 16:01:01 -04:00
QDateTime datum = QDateTime : : fromTime_t ( detail . lastConnect ) ;
// out << datum.toString(Qt::LocalDate);
QString stime = datum . toString ( Qt : : LocalDate ) ;
item - > setText ( 3 , stime ) ;
2008-09-21 18:04:49 -04:00
}
2008-01-25 03:49:40 -05:00
}
2008-09-27 10:48:57 -04:00
2008-01-25 03:49:40 -05:00
/* (4) Person */
item - > setText ( 4 , QString : : fromStdString ( detail . name ) ) ;
2007-11-14 22:18:48 -05:00
/* (5) Peer Address */
2008-01-25 03:49:40 -05:00
{
std : : ostringstream out ;
2008-09-27 10:48:57 -04:00
if ( detail . state & RS_PEER_STATE_FRIEND ) {
out < < detail . localAddr < < " : " ;
out < < detail . localPort < < " / " ;
out < < detail . extAddr < < " : " ;
out < < detail . extPort ;
} else {
// No Trust => no IP Information
2008-09-27 11:10:55 -04:00
out < < " 0.0.0.0:0/0.0.0.0:0 " ;
2008-09-27 10:48:57 -04:00
}
2008-01-25 03:49:40 -05:00
item - > setText ( 5 , QString : : fromStdString ( out . str ( ) ) ) ;
}
2007-11-14 22:18:48 -05:00
/* Others */
2008-01-25 03:49:40 -05:00
item - > setText ( 6 , QString : : fromStdString ( detail . org ) ) ;
item - > setText ( 7 , QString : : fromStdString ( detail . location ) ) ;
item - > setText ( 8 , QString : : fromStdString ( detail . email ) ) ;
2007-11-14 22:18:48 -05:00
{
2008-01-25 03:49:40 -05:00
item - > setText ( 9 , QString : : fromStdString ( detail . id ) ) ;
if ( ( oldSelect ) & & ( oldId = = detail . id ) )
2007-11-14 22:18:48 -05:00
{
newSelect = item ;
}
}
2008-08-08 10:32:13 -04:00
//item -> setText(10, QString::fromStdString(detail.authcode));
2007-11-14 22:18:48 -05:00
2008-09-27 11:10:55 -04:00
/**
* Determinated the Background Color
*/
QColor backgrndcolor ;
2008-09-21 18:04:49 -04:00
2008-09-27 11:10:55 -04:00
if ( detail . state & RS_PEER_STATE_FRIEND )
2007-11-14 22:18:48 -05:00
{
2009-04-07 17:01:45 -04:00
item - > setIcon ( 0 , ( QIcon ( IMAGE_AUTHED ) ) ) ;
2009-04-05 09:04:18 -04:00
backgrndcolor = Qt : : green ;
2008-09-27 11:10:55 -04:00
}
else
{
2008-12-23 11:25:32 -05:00
if ( rsPeers - > isTrustingMe ( detail . id ) )
{
backgrndcolor = Qt : : magenta ;
2008-12-23 12:59:58 -05:00
item - > setIcon ( 0 , ( QIcon ( IMAGE_TRUSTED ) ) ) ;
2008-12-24 12:09:41 -05:00
for ( int k = 0 ; k < 8 ; + + k )
item - > setToolTip ( k , QString : : fromStdString ( detail . name ) + QString ( tr ( " is trusting you. \n Right-click and select 'make friend' to be able to connect. " ) ) ) ;
2008-12-23 11:25:32 -05:00
}
2009-05-23 11:13:01 -04:00
# ifdef RS_USE_PGPSSL
2009-05-25 07:45:07 -04:00
else if ( detail . validLvl > GPGME_VALIDITY_MARGINAL )
2009-05-23 11:13:01 -04:00
{
backgrndcolor = Qt : : cyan ;
item - > setIcon ( 0 , ( QIcon ( IMAGE_DENIED ) ) ) ;
}
# else
2008-12-23 11:25:32 -05:00
else if ( detail . trustLvl > RS_TRUST_LVL_MARGINAL )
2008-09-27 11:10:55 -04:00
{
backgrndcolor = Qt : : cyan ;
item - > setIcon ( 0 , ( QIcon ( IMAGE_DENIED ) ) ) ;
}
2009-05-23 11:13:01 -04:00
# endif
2008-09-27 11:10:55 -04:00
else if ( detail . lastConnect < 10000 ) /* 3 hours? */
{
backgrndcolor = Qt : : yellow ;
item - > setIcon ( 0 , ( QIcon ( IMAGE_DENIED ) ) ) ;
}
else
{
backgrndcolor = Qt : : gray ;
item - > setIcon ( 0 , ( QIcon ( IMAGE_DENIED ) ) ) ;
}
}
// Color each Background column in the Network Tab except the first one => 1-9
// whith the determinated color
for ( int i = 1 ; i < 10 ; i + + )
item - > setBackground ( i , QBrush ( backgrndcolor ) ) ;
2009-04-05 09:04:18 -04:00
2007-11-14 22:18:48 -05:00
/* add to the list */
items . append ( item ) ;
}
2008-08-31 12:52:35 -04:00
// add self to network.
RsPeerDetails pd ;
if ( rsPeers - > getPeerDetails ( rsPeers - > getOwnId ( ) , pd ) )
{
QTreeWidgetItem * self_item = new QTreeWidgetItem ( ( QTreeWidget * ) 0 ) ;
2009-04-05 09:04:18 -04:00
self_item - > setText ( 1 , " N/A " ) ;
self_item - > setText ( 2 , " N/A " ) ;
self_item - > setText ( 3 , " N/A " ) ;
self_item - > setText ( 4 , QString : : fromStdString ( pd . name ) + " (yourself) " ) ;
2008-08-31 12:52:35 -04:00
std : : ostringstream out ;
out < < pd . localAddr < < " : " < < pd . localPort < < " / " < < pd . extAddr < < " : " < < pd . extPort ;
self_item - > setText ( 5 , QString : : fromStdString ( out . str ( ) ) ) ;
self_item - > setText ( 6 , QString : : fromStdString ( pd . org ) ) ;
self_item - > setText ( 7 , QString : : fromStdString ( pd . location ) ) ;
self_item - > setText ( 8 , QString : : fromStdString ( pd . email ) ) ;
self_item - > setText ( 9 , QString : : fromStdString ( pd . id ) ) ;
2008-09-27 11:10:55 -04:00
// Color each Background column in the Network Tab except the first one => 1-9
2008-08-31 12:52:35 -04:00
for ( int i = 1 ; i < 10 ; + + i )
{
2009-04-05 09:04:18 -04:00
self_item - > setBackground ( i , QBrush ( Qt : : green ) ) ;
2008-08-31 12:52:35 -04:00
}
self_item - > setIcon ( 0 , ( QIcon ( IMAGE_AUTHED ) ) ) ;
items . append ( self_item ) ;
}
2008-01-25 03:49:40 -05:00
/* remove old items ??? */
connectWidget - > clear ( ) ;
2008-08-08 10:32:13 -04:00
connectWidget - > setColumnCount ( 10 ) ;
2008-01-25 03:49:40 -05:00
2007-11-14 22:18:48 -05:00
/* add the items in! */
connectWidget - > insertTopLevelItems ( 0 , items ) ;
if ( newSelect )
{
connectWidget - > setCurrentItem ( newSelect ) ;
}
connectWidget - > update ( ) ; /* update display */
}
QTreeWidgetItem * NetworkDialog : : getCurrentNeighbour ( )
{
/* get the current, and extract the Id */
/* get a link to the table */
QTreeWidget * connectWidget = ui . connecttreeWidget ;
QTreeWidgetItem * item = connectWidget - > currentItem ( ) ;
if ( ! item )
{
2008-07-09 05:53:47 -04:00
# ifdef NET_DEBUG
2007-11-14 22:18:48 -05:00
std : : cerr < < " Invalid Current Item " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
return NULL ;
}
/* Display the columns of this item. */
return item ;
}
/* Utility Fns */
RsCertId getNeighRsCertId ( QTreeWidgetItem * i )
{
RsCertId id = ( i - > text ( 9 ) ) . toStdString ( ) ;
return id ;
}
/* So from the Neighbours Dialog we can call the following control Functions:
* ( 1 ) Load Certificate NeighLoadCertificate ( std : : string file )
* ( 2 ) Neigh Auth NeighAuthFriend ( id , code )
* ( 3 ) Neigh Add NeighAddFriend ( id )
*
* All of these rely on the finding of the current Id .
*/
std : : string NetworkDialog : : loadneighbour ( )
{
2008-07-09 05:53:47 -04:00
# ifdef NET_DEBUG
2007-11-14 22:18:48 -05:00
std : : cerr < < " ConnectionsDialog::loadneighbour() " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
QString fileName = QFileDialog : : getOpenFileName ( this , tr ( " Select Certificate " ) , " " ,
tr ( " Certificates (*.pqi *.pem) " ) ) ;
std : : string file = fileName . toStdString ( ) ;
std : : string id ;
if ( file ! = " " )
{
2008-01-25 03:49:40 -05:00
rsPeers - > LoadCertificateFromFile ( file , id ) ;
2007-11-14 22:18:48 -05:00
}
return id ;
}
void NetworkDialog : : addneighbour ( )
{
QTreeWidgetItem * c = getCurrentNeighbour ( ) ;
2008-07-09 05:53:47 -04:00
# ifdef NET_DEBUG
2007-11-14 22:18:48 -05:00
std : : cerr < < " ConnectionsDialog::addneighbour() " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
/*
rsServer - > NeighAddFriend ( getNeighRsCertId ( c ) ) ;
*/
}
void NetworkDialog : : authneighbour ( )
{
QTreeWidgetItem * c = getCurrentNeighbour ( ) ;
2008-07-09 05:53:47 -04:00
# ifdef NET_DEBUG
2007-11-14 22:18:48 -05:00
std : : cerr < < " ConnectionsDialog::authneighbour() " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
/*
RsAuthId code ;
rsServer - > NeighAuthFriend ( getNeighRsCertId ( c ) , code ) ;
*/
}
2008-08-31 12:52:35 -04:00
// Update Log Info information
void NetworkDialog : : setLogInfo ( QString info , QColor color ) {
static unsigned int nbLines = 0 ;
+ + nbLines ;
// Check log size, clear it if too big
if ( nbLines > 200 ) {
ui . infoLog - > clear ( ) ;
nbLines = 1 ;
}
ui . infoLog - > append ( QString : : fromUtf8 ( " <font color='grey'> " ) + QTime : : currentTime ( ) . toString ( QString : : fromUtf8 ( " hh:mm:ss " ) ) + QString : : fromUtf8 ( " </font> - <font color=' " ) + color . name ( ) + QString : : fromUtf8 ( " '><i> " ) + info + QString : : fromUtf8 ( " </i></font> " ) ) ;
}
void NetworkDialog : : on_actionClearLog_triggered ( ) {
ui . infoLog - > clear ( ) ;
}
void NetworkDialog : : displayInfoLogMenu ( const QPoint & pos ) {
// Log Menu
QMenu myLogMenu ( this ) ;
myLogMenu . addAction ( ui . actionClearLog ) ;
// XXX: Why mapToGlobal() is not enough?
2009-07-10 18:49:46 -04:00
// myLogMenu.exec(mapToGlobal(pos)+QPoint(0,320));
// No. Simple use QCursor::pos() to retrieve the position of the cursor.
myLogMenu . exec ( QCursor : : pos ( ) ) ;
2008-03-31 14:37:50 -04:00
}
2009-04-29 13:07:28 -04:00
2009-04-30 22:39:57 -04:00
void NetworkDialog : : getNetworkStatus ( )
{
rsiface - > lockData ( ) ; /* Lock Interface */
/* now the extra bit .... switch on check boxes */
const RsConfig & config = rsiface - > getConfig ( ) ;
2009-05-03 20:30:24 -04:00
/****** Log Tab **************************/
2009-04-30 22:39:57 -04:00
if ( config . netUpnpOk )
{
setLogInfo ( tr ( " UPNP is active. " ) , QString : : fromUtf8 ( " blue " ) ) ;
}
else
{
setLogInfo ( tr ( " UPNP NOT FOUND. " ) , QString : : fromUtf8 ( " red " ) ) ;
}
if ( config . netDhtOk )
{
setLogInfo ( tr ( " DHT OK " ) , QString : : fromUtf8 ( " green " ) ) ;
}
else
{
setLogInfo ( tr ( " DHT is not working (down). " ) , QString : : fromUtf8 ( " red " ) ) ;
}
if ( config . netExtOk )
{
2009-05-01 07:31:56 -04:00
setLogInfo ( tr ( " Stable External IP Address " ) , QString : : fromUtf8 ( " green " ) ) ;
2009-04-30 22:39:57 -04:00
}
else
{
setLogInfo ( tr ( " Not Found External Address " ) , QString : : fromUtf8 ( " red " ) ) ;
}
if ( config . netUdpOk )
{
2009-05-14 18:30:30 -04:00
setLogInfo ( tr ( " UDP Port is active (UDP Connections) " ) , QString : : fromUtf8 ( " green " ) ) ;
2009-04-30 22:39:57 -04:00
}
else
{
2009-05-14 18:30:30 -04:00
setLogInfo ( tr ( " UDP Port is not active " ) , QString : : fromUtf8 ( " red " ) ) ;
2009-04-30 22:39:57 -04:00
}
if ( config . netTcpOk )
{
2009-05-14 18:30:30 -04:00
setLogInfo ( tr ( " TCP Port is active (TCP Server) " ) , QString : : fromUtf8 ( " green " ) ) ;
2009-04-30 22:39:57 -04:00
}
else
{
2009-05-14 18:30:30 -04:00
setLogInfo ( tr ( " TCP Port is not active " ) , QString : : fromUtf8 ( " red " ) ) ;
2009-04-30 22:39:57 -04:00
}
if ( config . netExtOk )
{
if ( config . netUpnpOk | | config . netTcpOk )
{
setLogInfo ( tr ( " RetroShare Server " ) , QString : : fromUtf8 ( " green " ) ) ;
}
else
{
setLogInfo ( tr ( " UDP Server " ) , QString : : fromUtf8 ( " green " ) ) ;
}
}
else if ( config . netOk )
{
setLogInfo ( tr ( " Net Limited " ) , QString : : fromUtf8 ( " magenta " ) ) ;
}
else
{
setLogInfo ( tr ( " No Conectivity " ) , QString : : fromUtf8 ( " red " ) ) ;
}
2009-05-03 20:30:24 -04:00
rsiface - > unlockData ( ) ; /* UnLock Interface */
}
void NetworkDialog : : updateNetworkStatus ( )
{
rsiface - > lockData ( ) ; /* Lock Interface */
/* now the extra bit .... switch on check boxes */
const RsConfig & config = rsiface - > getConfig ( ) ;
/******* Network Status Tab *******/
2009-05-13 12:53:20 -04:00
if ( config . netUpnpOk )
{
ui . iconlabel_upnp - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledon1.png " ) ) ;
ui . textlabel_upnp - > setText ( tr ( " UPnP active " ) ) ;
}
else
{
ui . iconlabel_upnp - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
ui . textlabel_upnp - > setText ( tr ( " UPnP inactive " ) ) ;
}
if ( config . netDhtOk )
{
ui . iconlabel_dht - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledon1.png " ) ) ;
ui . textlabel_dht - > setText ( tr ( " DHT active " ) ) ;
}
else
{
ui . iconlabel_dht - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
ui . textlabel_dht - > setText ( tr ( " DHT inactive " ) ) ;
}
if ( config . netExtOk )
{
ui . iconlabel_ext - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledon1.png " ) ) ;
ui . textlabel_ext - > setText ( tr ( " Stabile External IP Address " ) ) ;
}
else
{
ui . iconlabel_ext - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
ui . textlabel_ext - > setText ( tr ( " Not Found External IP Address " ) ) ;
}
if ( config . netUdpOk )
{
ui . iconlabel_udp - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledon1.png " ) ) ;
2009-05-14 18:30:30 -04:00
ui . textlabel_udp - > setText ( tr ( " UDP Port is active ( UDP Connections ) " ) ) ;
2009-05-13 12:53:20 -04:00
}
else
{
ui . iconlabel_udp - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
2009-05-14 18:30:30 -04:00
ui . textlabel_udp - > setText ( tr ( " UDP Port is not active " ) ) ;
2009-05-13 12:53:20 -04:00
}
if ( config . netTcpOk )
{
ui . iconlabel_tcp - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledon1.png " ) ) ;
2009-05-14 18:30:30 -04:00
ui . textlabel_tcp - > setText ( tr ( " TCP Port is active (TCP Server) " ) ) ;
2009-05-13 12:53:20 -04:00
}
else
{
ui . iconlabel_tcp - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
2009-05-14 18:30:30 -04:00
ui . textlabel_tcp - > setText ( tr ( " TCP Port is not active " ) ) ;
2009-05-13 12:53:20 -04:00
}
if ( config . netExtOk )
{
if ( config . netUpnpOk | | config . netTcpOk )
{
ui . iconlabel_netServer - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledon1.png " ) ) ;
ui . iconlabel_netUdp - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
ui . iconlabel_netLimited - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
ui . iconlabel_nonet - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
}
else
{
ui . iconlabel_netUdp - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledon1.png " ) ) ;
ui . iconlabel_netServer - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
ui . iconlabel_netLimited - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
ui . iconlabel_nonet - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
}
}
else if ( config . netOk )
{
ui . iconlabel_netLimited - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledon1.png " ) ) ;
ui . iconlabel_netUdp - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
ui . iconlabel_netServer - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
ui . iconlabel_nonet - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
}
else
{
ui . iconlabel_nonet - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledon1.png " ) ) ;
ui . iconlabel_netUdp - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
ui . iconlabel_netServer - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
ui . iconlabel_netLimited - > setPixmap ( QPixmap : : QPixmap ( " :/images/ledoff1.png " ) ) ;
}
//ui.check_net->setChecked(config.netOk);
/*ui.check_upnp->setChecked(config.netUpnpOk);
2009-05-03 20:30:24 -04:00
ui . check_dht - > setChecked ( config . netDhtOk ) ;
ui . check_ext - > setChecked ( config . netExtOk ) ;
ui . check_udp - > setChecked ( config . netUdpOk ) ;
ui . check_tcp - > setChecked ( config . netTcpOk ) ;
if ( config . netExtOk )
{
if ( config . netUpnpOk | | config . netTcpOk )
{
ui . radio_netServer - > setChecked ( true ) ;
}
else
{
ui . radio_netUdp - > setChecked ( true ) ;
}
}
else if ( config . netOk )
{
ui . radio_netLimited - > setChecked ( true ) ;
}
else
{
ui . radio_nonet - > setChecked ( true ) ;
2009-05-13 12:53:20 -04:00
} */
2009-04-30 22:39:57 -04:00
rsiface - > unlockData ( ) ; /* UnLock Interface */
}
2009-05-13 12:53:20 -04:00
/*void NetworkDialog::load()
2009-05-03 20:30:24 -04:00
{
//ui.check_net->setCheckable(true);
ui . check_upnp - > setCheckable ( true ) ;
ui . check_dht - > setCheckable ( true ) ;
ui . check_ext - > setCheckable ( true ) ;
ui . check_udp - > setCheckable ( true ) ;
ui . check_tcp - > setCheckable ( true ) ;
//ui.check_net->setEnabled(false);
ui . check_upnp - > setEnabled ( false ) ;
ui . check_dht - > setEnabled ( false ) ;
ui . check_ext - > setEnabled ( false ) ;
ui . check_udp - > setEnabled ( false ) ;
ui . check_tcp - > setEnabled ( false ) ;
ui . radio_nonet - > setEnabled ( false ) ;
ui . radio_netLimited - > setEnabled ( false ) ;
ui . radio_netUdp - > setEnabled ( false ) ;
ui . radio_netServer - > setEnabled ( false ) ;
2009-05-13 12:53:20 -04:00
} */
2009-05-03 20:30:24 -04:00
2009-04-29 13:07:28 -04:00
void NetworkDialog : : on_actionTabsnorth_activated ( )
{
2009-07-10 20:45:17 -04:00
_settings - > beginGroup ( " NetworkDialog " ) ;
2009-04-29 13:07:28 -04:00
ui . networkTab - > setTabPosition ( QTabWidget : : North ) ;
2009-07-10 20:45:17 -04:00
_settings - > setValue ( " TabWidget_Position " , ui . networkTab - > tabPosition ( ) ) ;
_settings - > endGroup ( ) ;
2009-04-29 13:07:28 -04:00
}
void NetworkDialog : : on_actionTabssouth_activated ( )
{
2009-07-10 20:45:17 -04:00
_settings - > beginGroup ( " NetworkDialog " ) ;
2009-04-29 13:07:28 -04:00
ui . networkTab - > setTabPosition ( QTabWidget : : South ) ;
2009-07-10 20:45:17 -04:00
_settings - > setValue ( " TabWidget_Position " , ui . networkTab - > tabPosition ( ) ) ;
_settings - > endGroup ( ) ;
2009-04-29 13:07:28 -04:00
}
void NetworkDialog : : on_actionTabswest_activated ( )
{
2009-07-10 20:45:17 -04:00
_settings - > beginGroup ( " NetworkDialog " ) ;
2009-04-29 13:07:28 -04:00
ui . networkTab - > setTabPosition ( QTabWidget : : West ) ;
2009-07-10 20:45:17 -04:00
_settings - > setValue ( " TabWidget_Position " , ui . networkTab - > tabPosition ( ) ) ;
_settings - > endGroup ( ) ;
}
void NetworkDialog : : on_actionTabsright_activated ( )
{
_settings - > beginGroup ( " NetworkDialog " ) ;
ui . networkTab - > setTabPosition ( QTabWidget : : East ) ;
_settings - > setValue ( " TabWidget_Position " , ui . networkTab - > tabPosition ( ) ) ;
_settings - > endGroup ( ) ;
2009-04-29 13:07:28 -04:00
}
2009-04-29 13:48:25 -04:00
void NetworkDialog : : on_actionTabsTriangular_activated ( )
{
ui . networkTab - > setTabShape ( QTabWidget : : Triangular ) ;
ui . tabBottom - > setTabShape ( QTabWidget : : Triangular ) ;
}
void NetworkDialog : : on_actionTabsRounded_activated ( )
{
ui . networkTab - > setTabShape ( QTabWidget : : Rounded ) ;
ui . tabBottom - > setTabShape ( QTabWidget : : Rounded ) ;
2009-05-01 08:45:27 -04:00
}
2009-07-10 20:45:17 -04:00
void NetworkDialog : : loadtabsettings ( )
{
_settings - > beginGroup ( " NetworkDialog " ) ;
if ( _settings - > value ( " TabWidget_Position " , " 0 " ) . toInt ( ) = = 0 )
{
qDebug ( ) < < " Tab North " ;
ui . networkTab - > setTabPosition ( QTabWidget : : North ) ;
}
else if ( _settings - > value ( " TabWidget_Position " , " 1 " ) . toInt ( ) = = 1 )
{
qDebug ( ) < < " Tab South " ;
ui . networkTab - > setTabPosition ( QTabWidget : : South ) ;
}
else if ( _settings - > value ( " TabWidget_Position " , " 2 " ) . toInt ( ) = = 2 )
{
qDebug ( ) < < " Tab West " ;
ui . networkTab - > setTabPosition ( QTabWidget : : West ) ;
}
else if ( _settings - > value ( " TabWidget_Position " , " 3 " ) . toInt ( ) = = 3 )
{
qDebug ( ) < < " Tab East " ;
ui . networkTab - > setTabPosition ( QTabWidget : : East ) ;
}
_settings - > endGroup ( ) ;
}