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
|
|
|
****************************************************************/
|
|
|
|
|
2010-07-23 14:52:58 -04:00
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QTime>
|
|
|
|
#include <QMenu>
|
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rsiface.h>
|
|
|
|
#include <retroshare/rspeers.h>
|
|
|
|
#include <retroshare/rsdisc.h>
|
2008-08-31 12:52:35 -04:00
|
|
|
|
2008-03-21 19:31:00 -04:00
|
|
|
#include "common/vmessagebox.h"
|
2010-09-19 20:10:51 -04:00
|
|
|
#include "common/RSTreeWidgetItem.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "NetworkDialog.h"
|
2008-11-15 09:29:34 -05:00
|
|
|
#include "TrustView.h"
|
2009-08-04 19:37:01 -04:00
|
|
|
#include "GenCertDialog.h"
|
2010-07-23 14:52:58 -04:00
|
|
|
#include "connect/ConfCertDialog.h"
|
2010-05-11 16:02:52 -04:00
|
|
|
#include "settings/rsharesettings.h"
|
2009-05-23 11:13:01 -04:00
|
|
|
|
2009-05-07 18:43:11 -04:00
|
|
|
|
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"
|
2009-07-16 10:36:03 -04:00
|
|
|
#define IMAGE_EXPIORT ":/images/exportpeers_16x16.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
|
|
|
|
2010-06-09 06:29:34 -04:00
|
|
|
#define COLUMN_PEERNAME 1
|
|
|
|
#define COLUMN_PEERID 4
|
|
|
|
|
|
|
|
static int FilterColumnFromComboBox(int nIndex)
|
|
|
|
{
|
|
|
|
switch (nIndex) {
|
|
|
|
case 0:
|
|
|
|
return COLUMN_PEERNAME;
|
|
|
|
case 1:
|
|
|
|
return COLUMN_PEERID;
|
|
|
|
}
|
|
|
|
|
|
|
|
return COLUMN_PEERNAME;
|
|
|
|
}
|
2009-07-16 10:36:03 -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)
|
2010-05-02 09:12:46 -04:00
|
|
|
: RsAutoUpdatePage(10000,parent) // updates every 10 sec.
|
2008-08-31 12:52:35 -04:00
|
|
|
{
|
2010-06-09 11:56:07 -04:00
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
2009-07-10 20:45:17 -04:00
|
|
|
|
2010-06-09 11:56:07 -04:00
|
|
|
connect( ui.connecttreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( connecttreeWidgetCostumPopupMenu( QPoint ) ) );
|
|
|
|
connect( ui.connecttreeWidget, SIGNAL( itemSelectionChanged()), ui.unvalidGPGkeyWidget, SLOT( clearSelection() ) );
|
|
|
|
connect( ui.unvalidGPGkeyWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( connecttreeWidgetCostumPopupMenu( QPoint ) ) );
|
|
|
|
connect( ui.unvalidGPGkeyWidget, SIGNAL( itemSelectionChanged()), ui.connecttreeWidget, SLOT( clearSelection() ) );
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-06-09 11:56:07 -04:00
|
|
|
connect( ui.infoLog, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayInfoLogMenu(const QPoint&)));
|
2010-06-09 06:29:34 -04:00
|
|
|
|
2010-06-09 11:56:07 -04:00
|
|
|
connect( ui.filterPatternLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterRegExpChanged()));
|
|
|
|
connect( ui.filterColumnComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterColumnChanged()));
|
|
|
|
connect( ui.clearButton, SIGNAL(clicked()), this, SLOT(clearFilter()));
|
2010-01-13 16:14:49 -05:00
|
|
|
|
2010-06-09 11:56:07 -04:00
|
|
|
connect( ui.showUnvalidKeys, SIGNAL(clicked()), this, SLOT(insertConnect()));
|
2010-01-13 16:14:49 -05:00
|
|
|
|
|
|
|
|
2010-06-09 11:56:07 -04:00
|
|
|
/* hide the Tree +/- */
|
|
|
|
ui.connecttreeWidget -> setRootIsDecorated( false );
|
|
|
|
ui.connecttreeWidget -> setColumnCount(5);
|
|
|
|
ui.unvalidGPGkeyWidget-> setColumnCount(5);
|
2010-03-06 16:30:18 -05:00
|
|
|
|
2010-06-09 11:56:07 -04:00
|
|
|
/* Set header resize modes and initial section sizes */
|
2010-01-13 16:08:46 -05:00
|
|
|
QHeaderView * _header = ui.connecttreeWidget->header () ;
|
|
|
|
_header->setResizeMode (0, QHeaderView::Custom);
|
|
|
|
_header->setResizeMode (1, QHeaderView::Interactive);
|
|
|
|
_header->setResizeMode (2, QHeaderView::Interactive);
|
|
|
|
_header->setResizeMode (3, QHeaderView::Interactive);
|
2010-01-13 16:14:49 -05:00
|
|
|
_header->setResizeMode (4, QHeaderView::Interactive);
|
2010-01-13 16:08:46 -05:00
|
|
|
|
|
|
|
_header->resizeSection ( 0, 25 );
|
|
|
|
_header->resizeSection ( 1, 200 );
|
|
|
|
_header->resizeSection ( 2, 200 );
|
2010-01-13 16:14:49 -05:00
|
|
|
_header->resizeSection ( 3, 200 );
|
2010-01-13 16:08:46 -05:00
|
|
|
|
|
|
|
// set header text aligment
|
|
|
|
QTreeWidgetItem * headerItem = ui.connecttreeWidget->headerItem();
|
|
|
|
headerItem->setTextAlignment(0, Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
headerItem->setTextAlignment(1, Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
headerItem->setTextAlignment(2, Qt::AlignHCenter | Qt::AlignVCenter);
|
2010-01-13 16:14:49 -05:00
|
|
|
headerItem->setTextAlignment(3, Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
headerItem->setTextAlignment(4, Qt::AlignVCenter);
|
2010-01-13 16:08:46 -05:00
|
|
|
|
2010-01-13 16:32:56 -05:00
|
|
|
/* hide the Tree +/- */
|
|
|
|
ui.unvalidGPGkeyWidget -> setRootIsDecorated( false );
|
|
|
|
|
|
|
|
/* Set header resize modes and initial section sizes */
|
|
|
|
ui.unvalidGPGkeyWidget->header()->setResizeMode (0, QHeaderView::Custom);
|
|
|
|
ui.unvalidGPGkeyWidget->header()->setResizeMode (1, QHeaderView::Interactive);
|
|
|
|
ui.unvalidGPGkeyWidget->header()->setResizeMode (2, QHeaderView::Interactive);
|
|
|
|
ui.unvalidGPGkeyWidget->header()->setResizeMode (3, QHeaderView::Interactive);
|
|
|
|
ui.unvalidGPGkeyWidget->header()->setResizeMode (4, QHeaderView::Interactive);
|
|
|
|
|
|
|
|
ui.unvalidGPGkeyWidget->header()->resizeSection ( 0, 25 );
|
|
|
|
ui.unvalidGPGkeyWidget->header()->resizeSection ( 1, 200 );
|
|
|
|
ui.unvalidGPGkeyWidget->header()->resizeSection ( 2, 200 );
|
|
|
|
ui.unvalidGPGkeyWidget->header()->resizeSection ( 3, 200 );
|
|
|
|
|
|
|
|
// set header text aligment
|
|
|
|
ui.unvalidGPGkeyWidget->headerItem()->setTextAlignment(0, Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
ui.unvalidGPGkeyWidget->headerItem()->setTextAlignment(1, Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
ui.unvalidGPGkeyWidget->headerItem()->setTextAlignment(2, Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
ui.unvalidGPGkeyWidget->headerItem()->setTextAlignment(3, Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
ui.unvalidGPGkeyWidget->headerItem()->setTextAlignment(4, Qt::AlignVCenter);
|
|
|
|
|
2010-02-26 18:43:26 -05:00
|
|
|
ui.connecttreeWidget->sortItems( 1, Qt::AscendingOrder );
|
|
|
|
ui.unvalidGPGkeyWidget->sortItems( 1, Qt::AscendingOrder );
|
|
|
|
|
2010-01-13 16:32:56 -05:00
|
|
|
//ui.networkTab->addTab(new NetworkView(),QString(tr("Network View")));
|
2010-03-16 14:53:52 -04:00
|
|
|
ui.networkTab->addTab(new TrustView(),QString(tr("Authentication matrix")));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-10 19:11:17 -04:00
|
|
|
QString version = "-";
|
|
|
|
std::map<std::string, std::string>::iterator vit;
|
|
|
|
std::map<std::string, std::string> versions;
|
|
|
|
bool retv = rsDisc->getDiscVersions(versions);
|
|
|
|
if (retv && versions.end() != (vit = versions.find(rsPeers->getOwnId()))) {
|
|
|
|
version = QString::fromStdString(vit->second);
|
|
|
|
}
|
|
|
|
|
2008-08-31 12:52:35 -04:00
|
|
|
// Set Log infos
|
2009-08-10 19:11:17 -04:00
|
|
|
setLogInfo(tr("RetroShare %1 started.").arg(version));
|
2008-08-31 12:52:35 -04:00
|
|
|
|
2008-03-21 19:31:00 -04:00
|
|
|
setLogInfo(tr("Welcome to RetroShare."), QString::fromUtf8("blue"));
|
2009-04-30 22:39:57 -04:00
|
|
|
|
2010-09-12 20:27:50 -04:00
|
|
|
QMenu *menu = new QMenu();
|
2009-09-22 19:00:27 -04:00
|
|
|
//menu->addAction(ui.actionAddFriend);
|
2009-07-16 10:36:03 -04:00
|
|
|
//menu->addAction(ui.actionCopyKey);
|
2009-09-22 19:00:27 -04:00
|
|
|
//menu->addAction(ui.actionExportKey);
|
|
|
|
//menu->addAction(ui.actionCreate_New_Profile);
|
|
|
|
//menu->addSeparator();
|
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-07-10 20:45:17 -04:00
|
|
|
loadtabsettings();
|
2010-02-17 16:24:06 -05:00
|
|
|
|
|
|
|
#ifdef RS_RELEASE_VERSION
|
|
|
|
ui.tabBottom->removeTab(0); //hide the logs tab
|
|
|
|
#endif
|
2009-04-30 22:39:57 -04:00
|
|
|
|
2010-06-09 06:29:34 -04:00
|
|
|
ui.clearButton->hide();
|
|
|
|
|
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 )
|
|
|
|
{
|
2010-01-13 16:32:56 -05:00
|
|
|
std::cerr << "NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint point ) called" << std::endl;
|
2008-08-31 12:52:35 -04:00
|
|
|
QTreeWidgetItem *wi = getCurrentNeighbour();
|
|
|
|
if (!wi)
|
|
|
|
return;
|
|
|
|
|
2010-06-09 06:29:34 -04:00
|
|
|
QMenu contextMnu( this );
|
2008-08-31 12:52:35 -04:00
|
|
|
|
2010-06-09 06:29:34 -04:00
|
|
|
std::string peer_id = wi->text(4).toStdString() ;
|
2009-03-21 16:29:23 -04:00
|
|
|
|
2010-06-09 11:56:07 -04:00
|
|
|
// That's what context menus are made for
|
2009-04-07 17:01:45 -04:00
|
|
|
RsPeerDetails detail;
|
2010-06-09 06:29:34 -04:00
|
|
|
if(!rsPeers->getGPGDetails(peer_id, detail)) // that is not suppose to fail.
|
2009-04-07 17:01:45 -04:00
|
|
|
return ;
|
2008-08-31 12:52:35 -04:00
|
|
|
|
2010-06-09 11:56:07 -04:00
|
|
|
if(peer_id != rsPeers->getGPGOwnId())
|
2009-05-23 11:13:01 -04:00
|
|
|
{
|
2010-06-09 11:56:07 -04:00
|
|
|
if(detail.accept_connection)
|
2009-04-07 17:01:45 -04:00
|
|
|
{
|
2010-07-15 07:25:34 -04:00
|
|
|
QAction* denyFriendAct = new QAction(QIcon(IMAGE_DENIED), tr( "Deny friend" ), &contextMnu );
|
2009-04-07 17:01:45 -04:00
|
|
|
|
|
|
|
connect( denyFriendAct , SIGNAL( triggered() ), this, SLOT( denyFriend() ) );
|
|
|
|
contextMnu.addAction( denyFriendAct);
|
|
|
|
}
|
|
|
|
else // not a friend
|
|
|
|
{
|
2010-07-15 07:25:34 -04:00
|
|
|
QAction* makefriendAct = new QAction(QIcon(IMAGE_MAKEFRIEND), tr( "Make friend" ), &contextMnu );
|
2009-04-07 17:01:45 -04:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2010-07-15 07:25:34 -04:00
|
|
|
QAction* deleteCertAct = new QAction(QIcon(IMAGE_PEERDETAILS), tr( "Delete certificate" ), &contextMnu );
|
2009-04-07 17:01:45 -04:00
|
|
|
connect( deleteCertAct, SIGNAL( triggered() ), this, SLOT( deleteCert() ) );
|
|
|
|
contextMnu.addAction( deleteCertAct );
|
|
|
|
}
|
2009-07-16 10:36:03 -04:00
|
|
|
|
2009-04-07 17:01:45 -04:00
|
|
|
#endif
|
|
|
|
}
|
2009-05-23 11:13:01 -04:00
|
|
|
}
|
2010-06-09 11:56:07 -04:00
|
|
|
if(peer_id == rsPeers->getGPGOwnId())
|
2009-07-16 10:36:03 -04:00
|
|
|
{
|
2010-07-15 07:25:34 -04:00
|
|
|
QAction* exportcertAct = new QAction(QIcon(IMAGE_EXPIORT), tr( "Export my Cert" ), &contextMnu );
|
2009-07-16 10:36:03 -04:00
|
|
|
connect( exportcertAct , SIGNAL( triggered() ), this, SLOT( on_actionExportKey_activated() ) );
|
|
|
|
contextMnu.addAction( exportcertAct);
|
|
|
|
}
|
2009-04-07 17:01:45 -04:00
|
|
|
|
2010-07-15 07:25:34 -04:00
|
|
|
QAction* peerdetailsAct = new QAction(QIcon(IMAGE_PEERDETAILS), tr( "Peer details..." ), &contextMnu );
|
2009-04-07 17:01:45 -04:00
|
|
|
connect( peerdetailsAct , SIGNAL( triggered() ), this, SLOT( peerdetails() ) );
|
|
|
|
contextMnu.addAction( peerdetailsAct);
|
|
|
|
|
2009-07-16 10:36:03 -04:00
|
|
|
|
2010-05-14 16:55:44 -04:00
|
|
|
contextMnu.exec(QCursor::pos());
|
2009-04-07 17:01:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkDialog::denyFriend()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem *wi = getCurrentNeighbour();
|
2010-01-13 16:14:49 -05:00
|
|
|
std::string peer_id = wi->text(4).toStdString() ;
|
2009-04-07 17:01:45 -04:00
|
|
|
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()
|
|
|
|
{
|
2010-06-09 11:56:07 -04:00
|
|
|
ConfCertDialog::showTrust(getCurrentNeighbour()->text(4).toStdString());
|
2009-03-21 16:29:23 -04:00
|
|
|
}
|
|
|
|
|
2008-08-31 12:52:35 -04:00
|
|
|
/** Shows Peer Information/Auth Dialog */
|
|
|
|
void NetworkDialog::peerdetails()
|
2008-07-09 05:53:47 -04:00
|
|
|
{
|
2010-06-09 11:56:07 -04:00
|
|
|
ConfCertDialog::show(getCurrentNeighbour()->text(4).toStdString());
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
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 */
|
2010-05-02 09:12:46 -04:00
|
|
|
QFileDialog dialog (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);
|
2008-08-31 12:52:35 -04:00
|
|
|
|
|
|
|
/* Prompt the user to select a file or create a new one */
|
2010-05-02 09:12:46 -04:00
|
|
|
if (!dialog.exec() || dialog.selectedFiles().isEmpty()) {
|
2008-08-31 12:52:35 -04:00
|
|
|
return;
|
|
|
|
}
|
2010-05-02 09:12:46 -04:00
|
|
|
QString filename = QDir::convertSeparators(dialog.selectedFiles().at(0));
|
2008-08-31 12:52:35 -04:00
|
|
|
|
|
|
|
/* 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>
|
|
|
|
|
2009-11-17 07:45:06 -05:00
|
|
|
void NetworkDialog::updateDisplay()
|
|
|
|
{
|
|
|
|
insertConnect() ;
|
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* 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
|
|
|
|
2010-06-09 06:29:34 -04:00
|
|
|
std::list<std::string> neighs; //these are GPG ids
|
2008-01-25 03:49:40 -05:00
|
|
|
std::list<std::string>::iterator it;
|
2010-06-09 06:29:34 -04:00
|
|
|
rsPeers->getGPGAllList(neighs);
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* get a link to the table */
|
2010-06-09 06:29:34 -04:00
|
|
|
QTreeWidget *connectWidget = ui.connecttreeWidget;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-03-06 16:30:18 -05:00
|
|
|
//remove items
|
|
|
|
int index = 0;
|
|
|
|
while (index < connectWidget->topLevelItemCount()) {
|
|
|
|
std::string gpg_widget_id = (connectWidget->topLevelItem(index))->text(4).toStdString();
|
|
|
|
RsPeerDetails detail;
|
2010-05-02 09:12:46 -04:00
|
|
|
if (!rsPeers->getGPGDetails(gpg_widget_id, detail) || (detail.validLvl < 3 && !detail.accept_connection)) {
|
2010-05-05 18:03:43 -04:00
|
|
|
delete (connectWidget->takeTopLevelItem(index));
|
2010-03-06 16:30:18 -05:00
|
|
|
} else {
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
index = 0;
|
|
|
|
while (index < ui.unvalidGPGkeyWidget->topLevelItemCount()) {
|
|
|
|
std::string gpg_widget_id = (ui.unvalidGPGkeyWidget->topLevelItem(index))->text(4).toStdString();
|
|
|
|
RsPeerDetails detail;
|
2010-05-02 09:12:46 -04:00
|
|
|
if (!rsPeers->getGPGDetails(gpg_widget_id, detail) || detail.validLvl >= 3 || detail.accept_connection) {
|
2010-05-05 18:03:43 -04:00
|
|
|
delete (ui.unvalidGPGkeyWidget->takeTopLevelItem(index));
|
2010-03-06 16:30:18 -05:00
|
|
|
} else {
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
2010-01-13 16:08:46 -05:00
|
|
|
|
2010-01-13 16:32:56 -05:00
|
|
|
QList<QTreeWidgetItem *> validItems;
|
|
|
|
QList<QTreeWidgetItem *> unvalidItems;
|
2007-11-14 22:18:48 -05:00
|
|
|
for(it = neighs.begin(); it != neighs.end(); it++)
|
|
|
|
{
|
2010-03-06 16:30:18 -05:00
|
|
|
#ifdef NET_DEBUG
|
|
|
|
std::cerr << "NetworkDialog::insertConnect() inserting gpg key : " << *it << std::endl;
|
|
|
|
#endif
|
2010-01-13 16:22:52 -05:00
|
|
|
if (*it == rsPeers->getGPGOwnId()) {
|
2010-01-13 16:08:46 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsPeerDetails detail;
|
2010-01-13 16:22:52 -05:00
|
|
|
if (!rsPeers->getGPGDetails(*it, detail))
|
2010-01-13 16:08:46 -05:00
|
|
|
{
|
|
|
|
continue; /* BAD */
|
|
|
|
}
|
2010-03-06 16:30:18 -05:00
|
|
|
|
2010-01-13 16:08:46 -05:00
|
|
|
/* make a widget per friend */
|
2010-03-06 16:30:18 -05:00
|
|
|
QTreeWidgetItem *item;
|
|
|
|
QList<QTreeWidgetItem *> list = connectWidget->findItems(QString::fromStdString(*it), Qt::MatchExactly, 4);
|
|
|
|
if (list.size() == 1) {
|
|
|
|
item = list.front();
|
|
|
|
} else {
|
|
|
|
list = ui.unvalidGPGkeyWidget->findItems(QString::fromStdString(*it), Qt::MatchExactly, 4);
|
|
|
|
if (list.size() == 1) {
|
|
|
|
item = list.front();
|
|
|
|
} else {
|
|
|
|
//create new item
|
|
|
|
#ifdef NET_DEBUG
|
|
|
|
std::cerr << "NetworkDialog::insertConnect() creating new tree widget item : " << *it << std::endl;
|
|
|
|
#endif
|
2010-09-19 20:10:51 -04:00
|
|
|
item = new RSTreeWidgetItem(NULL, 0);
|
2010-06-21 08:26:23 -04:00
|
|
|
item -> setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
|
|
|
|
item -> setSizeHint(0, QSize( 18,18 ) );
|
2010-03-06 16:30:18 -05:00
|
|
|
|
2010-03-10 11:18:33 -05:00
|
|
|
/* (1) Person */
|
2010-06-09 06:29:34 -04:00
|
|
|
item -> setText(COLUMN_PEERNAME, QString::fromStdString(detail.name));
|
2010-01-13 16:08:46 -05:00
|
|
|
|
2010-03-10 11:18:33 -05:00
|
|
|
/* (4) key id */
|
2010-06-09 06:29:34 -04:00
|
|
|
item -> setText(COLUMN_PEERID, QString::fromStdString(detail.id));
|
2010-03-10 11:18:33 -05:00
|
|
|
}
|
|
|
|
}
|
2010-01-13 16:08:46 -05:00
|
|
|
|
2010-01-13 16:14:49 -05:00
|
|
|
/* (2) Key validity */
|
2010-02-26 18:43:26 -05:00
|
|
|
if (detail.ownsign) {
|
|
|
|
item -> setText(2, tr("Authenticated"));
|
|
|
|
item -> setToolTip(2, tr("GPG key signed"));
|
|
|
|
} else {
|
|
|
|
item -> setText(2, tr("Not Authenticated"));
|
|
|
|
item -> setToolTip(2, tr("GPG key not signed"));
|
2010-01-13 16:14:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* (3) has me auth */
|
2010-01-13 16:12:56 -05:00
|
|
|
if (detail.hasSignedMe)
|
2010-01-13 16:14:49 -05:00
|
|
|
item -> setText(3, tr("Has authenticated me"));
|
2009-04-05 09:04:18 -04:00
|
|
|
else
|
2010-01-13 16:14:49 -05:00
|
|
|
item -> setText(3, tr("Unknown"));
|
2008-09-27 10:48:57 -04:00
|
|
|
|
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
|
|
|
|
2010-06-09 11:56:07 -04:00
|
|
|
if (detail.accept_connection)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-06-09 11:56:07 -04:00
|
|
|
if (detail.ownsign)
|
2010-06-09 06:29:34 -04:00
|
|
|
{
|
2010-06-09 11:56:07 -04:00
|
|
|
item -> setText(0, "0");
|
2010-06-09 06:29:34 -04:00
|
|
|
item -> setIcon(0,(QIcon(IMAGE_AUTHED)));
|
2010-06-09 11:56:07 -04:00
|
|
|
backgrndcolor=QColor("#45ff45");//bright green
|
|
|
|
}
|
2010-06-09 06:29:34 -04:00
|
|
|
else
|
|
|
|
{
|
2010-06-09 11:56:07 -04:00
|
|
|
item -> setText(0, "0");
|
|
|
|
item -> setIcon(0,(QIcon(IMAGE_AUTHED)));
|
|
|
|
backgrndcolor=QColor("#43C043");//light green
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 06:29:34 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
item -> setText(0, "1");
|
2010-06-09 11:56:07 -04:00
|
|
|
|
2010-06-09 06:29:34 -04:00
|
|
|
if (detail.hasSignedMe)
|
2008-12-23 11:25:32 -05:00
|
|
|
{
|
2010-06-09 06:29:34 -04:00
|
|
|
backgrndcolor=QColor("#42B2B2"); //kind of darkCyan
|
|
|
|
item -> setIcon(0,(QIcon(IMAGE_DENIED)));
|
2008-12-24 12:09:41 -05:00
|
|
|
for(int k=0;k<8;++k)
|
2010-09-28 16:33:34 -04:00
|
|
|
item -> setToolTip(k, QString::fromStdString(detail.name) + tr(" has authenticated you. \nRight-click and select 'make friend' to be able to connect."));
|
2008-09-27 11:10:55 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-09 11:56:07 -04:00
|
|
|
backgrndcolor=Qt::lightGray;
|
2008-09-27 11:10:55 -04:00
|
|
|
item -> setIcon(0,(QIcon(IMAGE_DENIED)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Color each Background column in the Network Tab except the first one => 1-9
|
|
|
|
// whith the determinated color
|
2010-06-09 06:29:34 -04:00
|
|
|
for(int i = 0; i <10; i++)
|
2008-09-27 11:10:55 -04:00
|
|
|
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 */
|
2010-06-09 11:56:07 -04:00
|
|
|
if (detail.accept_connection || detail.validLvl >= 3)
|
2010-06-09 06:29:34 -04:00
|
|
|
{
|
|
|
|
/* add gpg item to the list. If item is already in the list, it won't be duplicated thanks to Qt */
|
|
|
|
connectWidget->addTopLevelItem(item);
|
2010-06-09 11:56:07 -04:00
|
|
|
}
|
2010-06-09 06:29:34 -04:00
|
|
|
else
|
|
|
|
{
|
2010-06-09 11:56:07 -04:00
|
|
|
ui.unvalidGPGkeyWidget->addTopLevelItem(item);
|
|
|
|
}
|
2010-01-13 16:08:46 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2008-08-31 12:52:35 -04:00
|
|
|
// add self to network.
|
2010-03-06 16:30:18 -05:00
|
|
|
RsPeerDetails ownGPGDetails;
|
|
|
|
rsPeers->getGPGDetails(rsPeers->getGPGOwnId(), ownGPGDetails);
|
|
|
|
/* make a widget per friend */
|
|
|
|
QTreeWidgetItem *self_item;
|
|
|
|
QList<QTreeWidgetItem *> list = connectWidget->findItems(QString::fromStdString(ownGPGDetails.gpg_id), Qt::MatchExactly, 4);
|
|
|
|
if (list.size() == 1) {
|
|
|
|
self_item = list.front();
|
|
|
|
} else {
|
2010-09-19 20:10:51 -04:00
|
|
|
self_item = new RSTreeWidgetItem(NULL, 0);
|
2010-03-06 16:30:18 -05:00
|
|
|
self_item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
|
|
|
|
}
|
2010-02-26 18:43:26 -05:00
|
|
|
self_item -> setText(0, "0");
|
2010-02-26 18:44:27 -05:00
|
|
|
self_item->setIcon(0,(QIcon(IMAGE_AUTHED)));
|
2010-09-28 16:33:34 -04:00
|
|
|
self_item->setText(COLUMN_PEERNAME, QString::fromStdString(ownGPGDetails.name) + " (" + tr("yourself") + ")");
|
2010-01-13 16:08:46 -05:00
|
|
|
self_item->setText(2,"N/A");
|
2010-06-09 06:29:34 -04:00
|
|
|
self_item->setText(COLUMN_PEERID, QString::fromStdString(ownGPGDetails.id));
|
2008-08-31 12:52:35 -04:00
|
|
|
|
2010-01-13 16:08:46 -05:00
|
|
|
// Color each Background column in the Network Tab except the first one => 1-9
|
2010-02-26 18:44:27 -05:00
|
|
|
for(int i=0;i<10;++i)
|
2010-01-13 16:08:46 -05:00
|
|
|
{
|
2010-02-27 16:44:04 -05:00
|
|
|
self_item->setBackground(i,QBrush(QColor("#45ff45")));
|
2010-01-13 16:08:46 -05:00
|
|
|
}
|
2010-03-06 16:30:18 -05:00
|
|
|
connectWidget->addTopLevelItem(self_item);
|
2010-01-13 16:32:56 -05:00
|
|
|
|
|
|
|
if (ui.showUnvalidKeys->isChecked()) {
|
|
|
|
ui.unvalidGPGkeyWidget->show();
|
|
|
|
} else {
|
|
|
|
ui.unvalidGPGkeyWidget->hide();
|
|
|
|
}
|
|
|
|
connectWidget->update(); /* update display */
|
|
|
|
ui.unvalidGPGkeyWidget->update(); /* update display */
|
2010-06-09 06:29:34 -04:00
|
|
|
|
|
|
|
if (ui.filterPatternLineEdit->text().isEmpty() == false) {
|
|
|
|
FilterItems();
|
|
|
|
}
|
2010-01-13 16:32:56 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QTreeWidgetItem *NetworkDialog::getCurrentNeighbour()
|
|
|
|
{
|
2010-01-13 16:32:56 -05:00
|
|
|
if (ui.connecttreeWidget->selectedItems().size() != 0) {
|
|
|
|
return ui.connecttreeWidget -> currentItem();
|
|
|
|
} else if (ui.unvalidGPGkeyWidget->selectedItems().size() != 0) {
|
|
|
|
return ui.unvalidGPGkeyWidget->currentItem();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2010-01-13 16:32:56 -05:00
|
|
|
return NULL;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Utility Fns */
|
|
|
|
RsCertId getNeighRsCertId(QTreeWidgetItem *i)
|
|
|
|
{
|
2010-01-13 16:14:49 -05:00
|
|
|
RsCertId id = (i -> text(4)).toStdString();
|
2007-11-14 22:18:48 -05:00
|
|
|
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)
|
2010-01-13 16:14:49 -05:00
|
|
|
* (4) Neigh Add NeighAddFriend(id)
|
2007-11-14 22:18:48 -05:00
|
|
|
*
|
|
|
|
* 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
|
2009-11-23 15:37:47 -05:00
|
|
|
std::cerr << "NetworkDialog::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;
|
2010-01-13 16:22:52 -05:00
|
|
|
std::string gpg_id;
|
2007-11-14 22:18:48 -05:00
|
|
|
if (file != "")
|
|
|
|
{
|
2010-01-13 16:22:52 -05:00
|
|
|
rsPeers->loadCertificateFromFile(file, id, gpg_id);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkDialog::addneighbour()
|
|
|
|
{
|
2010-05-02 09:12:46 -04:00
|
|
|
// QTreeWidgetItem *c = getCurrentNeighbour();
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef NET_DEBUG
|
2009-11-23 15:37:47 -05:00
|
|
|
std::cerr << "NetworkDialog::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()
|
|
|
|
{
|
2010-05-02 09:12:46 -04:00
|
|
|
// QTreeWidgetItem *c = getCurrentNeighbour();
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef NET_DEBUG
|
2009-11-23 15:37:47 -05:00
|
|
|
std::cerr << "NetworkDialog::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);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2009-07-16 10:36:03 -04:00
|
|
|
/** Open a QFileDialog to browse for a pem/pqi file. */
|
|
|
|
void NetworkDialog::on_actionAddFriend_activated()
|
|
|
|
{
|
|
|
|
/* Create a new input dialog, which allows users to create files, too */
|
2010-05-02 09:12:46 -04:00
|
|
|
QFileDialog dialog (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);
|
2009-07-16 10:36:03 -04:00
|
|
|
|
|
|
|
/* Prompt the user to select a file or create a new one */
|
2010-05-02 09:12:46 -04:00
|
|
|
if (!dialog.exec() || dialog.selectedFiles().isEmpty()) {
|
2009-07-16 10:36:03 -04:00
|
|
|
return;
|
|
|
|
}
|
2010-05-02 09:12:46 -04:00
|
|
|
QString filename = QDir::convertSeparators(dialog.selectedFiles().at(0));
|
2009-07-16 10:36:03 -04:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NetworkDialog::on_actionExportKey_activated()
|
|
|
|
{
|
|
|
|
qDebug() << " exportcert";
|
|
|
|
|
2010-06-16 14:01:23 -04:00
|
|
|
std::string cert = rsPeers->GetRetroshareInvite();
|
2010-06-15 07:34:58 -04:00
|
|
|
if (cert.empty()) {
|
2009-07-16 10:36:03 -04:00
|
|
|
QMessageBox::information(this, tr("RetroShare"),
|
2010-06-15 07:34:58 -04:00
|
|
|
tr("Sorry, create certificate failed"),
|
2009-07-16 10:36:03 -04:00
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
2010-06-15 07:34:58 -04:00
|
|
|
return;
|
2009-07-16 10:36:03 -04:00
|
|
|
}
|
2010-06-15 07:34:58 -04:00
|
|
|
|
|
|
|
QString qdir = QFileDialog::getSaveFileName(this,
|
|
|
|
tr("Please choose a filename"),
|
|
|
|
QDir::homePath(),
|
|
|
|
tr("RetroShare Certificate (*.rsc );;All Files (*)"));
|
|
|
|
//Todo: move save to file to p3Peers::SaveCertificateToFile
|
|
|
|
|
|
|
|
if (qdir.isEmpty() == false) {
|
|
|
|
QFile CertFile (qdir);
|
2010-06-16 14:01:23 -04:00
|
|
|
if (CertFile.open(QIODevice::WriteOnly/* | QIODevice::Text*/)) {
|
2010-06-15 07:34:58 -04:00
|
|
|
if (CertFile.write(QByteArray(cert.c_str())) > 0) {
|
|
|
|
QMessageBox::information(this, tr("RetroShare"),
|
|
|
|
tr("Certificate file successfully created"),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
} else {
|
|
|
|
QMessageBox::information(this, tr("RetroShare"),
|
|
|
|
tr("Sorry, certificate file creation failed"),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
}
|
|
|
|
CertFile.close();
|
|
|
|
} else {
|
|
|
|
QMessageBox::information(this, tr("RetroShare"),
|
|
|
|
tr("Sorry, certificate file creation failed"),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
|
|
|
}
|
2009-07-16 10:36:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2009-08-04 19:37:01 -04:00
|
|
|
void NetworkDialog::on_actionCreate_New_Profile_activated()
|
|
|
|
{
|
2010-05-02 09:12:46 -04:00
|
|
|
// GenCertDialog gencertdialog (this);
|
|
|
|
// gencertdialog.exec ();
|
2009-08-04 19:37:01 -04:00
|
|
|
}
|
|
|
|
|
2008-08-31 12:52:35 -04:00
|
|
|
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()
|
|
|
|
{
|
2010-04-19 17:50:03 -04:00
|
|
|
if(RsAutoUpdatePage::eventsLocked())
|
|
|
|
return ;
|
|
|
|
|
2009-04-30 22:39:57 -04:00
|
|
|
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)
|
|
|
|
{
|
2009-10-29 20:41:24 -04:00
|
|
|
setLogInfo(tr("DHT OK."), QString::fromUtf8("green"));
|
2009-04-30 22:39:57 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setLogInfo(tr("DHT is not working (down)."), QString::fromUtf8("red"));
|
|
|
|
}
|
2009-10-29 20:41:24 -04:00
|
|
|
|
|
|
|
if(config.netStunOk)
|
2009-04-30 22:39:57 -04:00
|
|
|
{
|
2009-10-29 20:41:24 -04:00
|
|
|
setLogInfo(tr("Stun external address detection is working."), QString::fromUtf8("green"));
|
2009-04-30 22:39:57 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-29 20:41:24 -04:00
|
|
|
setLogInfo(tr("Stun is not working."), QString::fromUtf8("red"));
|
2009-04-30 22:39:57 -04:00
|
|
|
}
|
|
|
|
|
2009-10-29 20:41:24 -04:00
|
|
|
if (config.netLocalOk)
|
2009-04-30 22:39:57 -04:00
|
|
|
{
|
2009-10-29 20:41:24 -04:00
|
|
|
setLogInfo(tr("Local network detected"), QString::fromUtf8("magenta"));
|
2009-04-30 22:39:57 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-29 20:41:24 -04:00
|
|
|
setLogInfo(tr("No local network detected"), QString::fromUtf8("red"));
|
2009-04-30 22:39:57 -04:00
|
|
|
}
|
2009-10-29 20:41:24 -04:00
|
|
|
|
|
|
|
if (config.netExtraAddressOk)
|
2009-04-30 22:39:57 -04:00
|
|
|
{
|
2009-10-29 20:41:24 -04:00
|
|
|
setLogInfo(tr("ip found via external address finder"), QString::fromUtf8("magenta"));
|
2009-04-30 22:39:57 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-29 20:41:24 -04:00
|
|
|
setLogInfo(tr("external address finder didn't found anything"), QString::fromUtf8("red"));
|
2009-04-30 22:39:57 -04:00
|
|
|
}
|
2009-10-29 20:41:24 -04:00
|
|
|
|
2009-05-03 20:30:24 -04:00
|
|
|
rsiface->unlockData(); /* UnLock Interface */
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkDialog::updateNetworkStatus()
|
|
|
|
{
|
2010-04-19 17:50:03 -04:00
|
|
|
if(RsAutoUpdatePage::eventsLocked())
|
|
|
|
return ;
|
|
|
|
|
2009-05-03 20:30:24 -04:00
|
|
|
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)
|
|
|
|
{
|
2010-06-14 07:57:22 -04:00
|
|
|
ui.iconlabel_upnp->setPixmap(QPixmap(":/images/ledon1.png"));
|
2009-05-13 12:53:20 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-14 07:57:22 -04:00
|
|
|
ui.iconlabel_upnp->setPixmap(QPixmap(":/images/ledoff1.png"));
|
2009-05-13 12:53:20 -04:00
|
|
|
}
|
2010-02-06 15:49:24 -05:00
|
|
|
|
2009-10-29 20:41:24 -04:00
|
|
|
if (config.netLocalOk)
|
2009-05-13 12:53:20 -04:00
|
|
|
{
|
2010-06-14 07:57:22 -04:00
|
|
|
ui.iconlabel_netLimited->setPixmap(QPixmap(":/images/ledon1.png"));
|
2009-05-13 12:53:20 -04:00
|
|
|
}
|
|
|
|
else
|
2009-10-29 20:36:33 -04:00
|
|
|
{
|
2010-06-14 07:57:22 -04:00
|
|
|
ui.iconlabel_netLimited->setPixmap(QPixmap(":/images/ledoff1.png"));
|
2009-05-13 12:53:20 -04:00
|
|
|
}
|
2009-10-29 20:41:24 -04:00
|
|
|
|
|
|
|
if (config.netExtraAddressOk)
|
|
|
|
{
|
2010-06-14 07:57:22 -04:00
|
|
|
ui.iconlabel_ext->setPixmap(QPixmap(":/images/ledon1.png"));
|
2009-10-29 20:41:24 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-14 07:57:22 -04:00
|
|
|
ui.iconlabel_ext->setPixmap(QPixmap(":/images/ledoff1.png"));
|
2009-10-29 20:41:24 -04:00
|
|
|
}
|
|
|
|
|
2009-04-30 22:39:57 -04:00
|
|
|
rsiface->unlockData(); /* UnLock Interface */
|
|
|
|
}
|
|
|
|
|
2009-04-29 13:07:28 -04:00
|
|
|
void NetworkDialog::on_actionTabsnorth_activated()
|
|
|
|
{
|
|
|
|
ui.networkTab->setTabPosition(QTabWidget::North);
|
2009-07-10 20:45:17 -04:00
|
|
|
|
2010-05-20 17:53:27 -04:00
|
|
|
Settings->setValueToGroup("NetworkDialog", "TabWidget_Position",ui.networkTab->tabPosition());
|
2009-04-29 13:07:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkDialog::on_actionTabssouth_activated()
|
|
|
|
{
|
|
|
|
ui.networkTab->setTabPosition(QTabWidget::South);
|
2010-05-20 17:53:27 -04:00
|
|
|
|
|
|
|
Settings->setValueToGroup("NetworkDialog", "TabWidget_Position",ui.networkTab->tabPosition());
|
|
|
|
|
2009-04-29 13:07:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkDialog::on_actionTabswest_activated()
|
|
|
|
{
|
|
|
|
ui.networkTab->setTabPosition(QTabWidget::West);
|
2010-05-20 17:53:27 -04:00
|
|
|
|
|
|
|
Settings->setValueToGroup("NetworkDialog", "TabWidget_Position",ui.networkTab->tabPosition());
|
2009-07-10 20:45:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkDialog::on_actionTabsright_activated()
|
|
|
|
{
|
|
|
|
ui.networkTab->setTabPosition(QTabWidget::East);
|
2010-05-20 17:53:27 -04:00
|
|
|
|
|
|
|
Settings->setValueToGroup("NetworkDialog", "TabWidget_Position",ui.networkTab->tabPosition());
|
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()
|
|
|
|
{
|
2010-05-20 17:53:27 -04:00
|
|
|
Settings->beginGroup("NetworkDialog");
|
2009-07-10 20:45:17 -04:00
|
|
|
|
2010-05-20 17:53:27 -04:00
|
|
|
if(Settings->value("TabWidget_Position","0").toInt() == 0)
|
2010-05-11 16:02:52 -04:00
|
|
|
{
|
|
|
|
qDebug() << "Tab North";
|
|
|
|
ui.networkTab->setTabPosition(QTabWidget::North);
|
|
|
|
}
|
2010-05-20 17:53:27 -04:00
|
|
|
else if (Settings->value("TabWidget_Position","1").toInt() == 1)
|
2010-05-11 16:02:52 -04:00
|
|
|
{
|
|
|
|
qDebug() << "Tab South";
|
|
|
|
ui.networkTab->setTabPosition(QTabWidget::South);
|
|
|
|
}
|
2010-05-20 17:53:27 -04:00
|
|
|
else if (Settings->value("TabWidget_Position","2").toInt() ==2)
|
2010-05-11 16:02:52 -04:00
|
|
|
{
|
|
|
|
qDebug() << "Tab West";
|
|
|
|
ui.networkTab->setTabPosition(QTabWidget::West);
|
|
|
|
}
|
2010-05-20 17:53:27 -04:00
|
|
|
else if(Settings->value("TabWidget_Position","3").toInt() ==3)
|
2010-05-11 16:02:52 -04:00
|
|
|
{
|
|
|
|
qDebug() << "Tab East";
|
|
|
|
ui.networkTab->setTabPosition(QTabWidget::East);
|
|
|
|
}
|
2009-07-10 20:45:17 -04:00
|
|
|
|
2010-05-20 17:53:27 -04:00
|
|
|
Settings->endGroup();
|
2009-07-10 20:45:17 -04:00
|
|
|
}
|
2010-06-09 06:29:34 -04:00
|
|
|
|
|
|
|
/* clear Filter */
|
|
|
|
void NetworkDialog::clearFilter()
|
|
|
|
{
|
|
|
|
ui.filterPatternLineEdit->clear();
|
|
|
|
ui.filterPatternLineEdit->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkDialog::filterRegExpChanged()
|
|
|
|
{
|
|
|
|
|
|
|
|
QString text = ui.filterPatternLineEdit->text();
|
|
|
|
|
|
|
|
if (text.isEmpty()) {
|
|
|
|
ui.clearButton->hide();
|
|
|
|
} else {
|
|
|
|
ui.clearButton->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
FilterItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkDialog::filterColumnChanged()
|
|
|
|
{
|
|
|
|
|
|
|
|
FilterItems();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkDialog::FilterItems()
|
|
|
|
{
|
|
|
|
QString sPattern = ui.filterPatternLineEdit->text();
|
|
|
|
int nFilterColumn = FilterColumnFromComboBox(ui.filterColumnComboBox->currentIndex());
|
|
|
|
|
|
|
|
int nCount = ui.connecttreeWidget->topLevelItemCount ();
|
|
|
|
for (int nIndex = 0; nIndex < nCount; nIndex++) {
|
|
|
|
FilterItem(ui.connecttreeWidget->topLevelItem(nIndex), sPattern, nFilterColumn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NetworkDialog::FilterItem(QTreeWidgetItem *pItem, QString &sPattern, int nFilterColumn)
|
|
|
|
{
|
|
|
|
bool bVisible = true;
|
|
|
|
|
|
|
|
if (sPattern.isEmpty() == false) {
|
|
|
|
if (pItem->text(nFilterColumn).contains(sPattern, Qt::CaseInsensitive) == false) {
|
|
|
|
bVisible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int nVisibleChildCount = 0;
|
|
|
|
int nCount = pItem->childCount();
|
|
|
|
for (int nIndex = 0; nIndex < nCount; nIndex++) {
|
|
|
|
if (FilterItem(pItem->child(nIndex), sPattern, nFilterColumn)) {
|
|
|
|
nVisibleChildCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bVisible || nVisibleChildCount) {
|
|
|
|
pItem->setHidden(false);
|
|
|
|
} else {
|
|
|
|
pItem->setHidden(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (bVisible || nVisibleChildCount);
|
2010-06-10 03:50:14 -04:00
|
|
|
}
|