- made the NetworkDialog display the self peer. This is useful to display who trusts oneself

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@712 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2008-08-31 16:52:35 +00:00
parent 213d24c1d8
commit cec173495e

View file

@ -17,14 +17,14 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, * Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
****************************************************************/ ****************************************************************/
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include "rshare.h" #include "rshare.h"
#include "common/vmessagebox.h" #include "common/vmessagebox.h"
#include "util/rsversion.h" #include "util/rsversion.h"
#include "NetworkDialog.h" #include "NetworkDialog.h"
#include "NetworkView.h" #include "NetworkView.h"
#include "connect/ConnectDialog.h" #include "connect/ConnectDialog.h"
@ -39,30 +39,30 @@
#include <QPoint> #include <QPoint>
#include <QMouseEvent> #include <QMouseEvent>
#include <QPixmap> #include <QPixmap>
#include <QHeaderView> #include <QHeaderView>
/* Images for context menu icons */ /* Images for context menu icons */
#define IMAGE_LOADCERT ":/images/loadcert16.png" #define IMAGE_LOADCERT ":/images/loadcert16.png"
#define IMAGE_PEERDETAILS ":/images/peerdetails_16x16.png" #define IMAGE_PEERDETAILS ":/images/peerdetails_16x16.png"
#define IMAGE_AUTH ":/images/encrypted16.png" #define IMAGE_AUTH ":/images/encrypted16.png"
/* Images for Status icons */ /* Images for Status icons */
#define IMAGE_AUTHED ":/images/accepted16.png" #define IMAGE_AUTHED ":/images/accepted16.png"
#define IMAGE_DENIED ":/images/denied16.png" #define IMAGE_DENIED ":/images/denied16.png"
RsCertId getNeighRsCertId(QTreeWidgetItem *i); RsCertId getNeighRsCertId(QTreeWidgetItem *i);
/****** /******
* #define NET_DEBUG 1 * #define NET_DEBUG 1
*****/ *****/
/** Constructor */ /** Constructor */
NetworkDialog::NetworkDialog(QWidget *parent) NetworkDialog::NetworkDialog(QWidget *parent)
: MainPage(parent), connectdialog(NULL) : MainPage(parent), connectdialog(NULL)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this); ui.setupUi(this);
connect( ui.connecttreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( connecttreeWidgetCostumPopupMenu( QPoint ) ) ); connect( ui.connecttreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( connecttreeWidgetCostumPopupMenu( QPoint ) ) );
/* create a single connect dialog */ /* create a single connect dialog */
connectdialog = new ConnectDialog(); connectdialog = new ConnectDialog();
@ -73,18 +73,18 @@ NetworkDialog::NetworkDialog(QWidget *parent)
ui.connecttreeWidget -> setRootIsDecorated( false ); ui.connecttreeWidget -> setRootIsDecorated( false );
/* Set header resize modes and initial section sizes */ /* Set header resize modes and initial section sizes */
QHeaderView * _header = ui.connecttreeWidget->header () ; QHeaderView * _header = ui.connecttreeWidget->header () ;
_header->setResizeMode (0, QHeaderView::Custom); _header->setResizeMode (0, QHeaderView::Custom);
_header->setResizeMode (1, QHeaderView::Interactive); _header->setResizeMode (1, QHeaderView::Interactive);
_header->setResizeMode (2, QHeaderView::Interactive); _header->setResizeMode (2, QHeaderView::Interactive);
_header->setResizeMode (3, QHeaderView::Interactive); _header->setResizeMode (3, QHeaderView::Interactive);
_header->setResizeMode (4, QHeaderView::Interactive); _header->setResizeMode (4, QHeaderView::Interactive);
_header->setResizeMode (5, QHeaderView::Interactive); _header->setResizeMode (5, QHeaderView::Interactive);
_header->setResizeMode (6, QHeaderView::Interactive); _header->setResizeMode (6, QHeaderView::Interactive);
_header->setResizeMode (7, QHeaderView::Interactive); _header->setResizeMode (7, QHeaderView::Interactive);
_header->setResizeMode (8, QHeaderView::Interactive); _header->setResizeMode (8, QHeaderView::Interactive);
_header->setResizeMode (9, QHeaderView::Interactive); _header->setResizeMode (9, QHeaderView::Interactive);
_header->resizeSection ( 0, 25 ); _header->resizeSection ( 0, 25 );
_header->resizeSection ( 1, 100 ); _header->resizeSection ( 1, 100 );
_header->resizeSection ( 2, 100 ); _header->resizeSection ( 2, 100 );
@ -110,45 +110,59 @@ NetworkDialog::NetworkDialog(QWidget *parent)
headerItem->setTextAlignment(9, Qt::AlignHCenter | Qt::AlignVCenter); headerItem->setTextAlignment(9, Qt::AlignHCenter | Qt::AlignVCenter);
networkview = new NetworkView(ui.networkviewTab); networkview = new NetworkView(ui.networkviewTab);
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(networkview); layout->addWidget(networkview);
ui.networkviewTab->setLayout(layout); ui.networkviewTab->setLayout(layout);
layout->setSpacing( 0 ); layout->setSpacing( 0 );
layout->setMargin( 0 ); layout->setMargin( 0 );
// Set Log infos // Set Log infos
setLogInfo(tr("RetroShare %1 started.", "e.g: RetroShare v0.x started.").arg(retroshareVersion())); setLogInfo(tr("RetroShare %1 started.", "e.g: RetroShare v0.x started.").arg(retroshareVersion()));
setLogInfo(tr("Welcome to RetroShare."), QString::fromUtf8("blue")); setLogInfo(tr("Welcome to RetroShare."), QString::fromUtf8("blue"));
/* Hide platform specific features */ /* Hide platform specific features */
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
#endif
}
void NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint point ) #endif
{ }
QMenu contextMnu( this ); void NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint point )
QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier ); {
peerdetailsAct = new QAction(QIcon(IMAGE_PEERDETAILS), tr( "Make Friend / Peer Details" ), this ); QTreeWidgetItem *wi = getCurrentNeighbour();
connect( peerdetailsAct , SIGNAL( triggered() ), this, SLOT( peerdetails() ) ); if (!wi)
return;
loadcertAct = new QAction(QIcon(IMAGE_LOADCERT), tr( "Load Certificate" ), this );
connect( loadcertAct , SIGNAL( triggered() ), this, SLOT( loadneighbour() ) ); // return ;
QMenu contextMnu( this );
contextMnu.clear(); QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
contextMnu.addAction( peerdetailsAct); contextMnu.clear();
contextMnu.addAction( loadcertAct);
contextMnu.exec( mevent->globalPos() ); if(wi->text(9).toStdString() == rsPeers->getOwnId())
} {
peerdetailsAct = new QAction(QIcon(IMAGE_PEERDETAILS), tr( "Peer Details" ), this );
/** Shows Peer Information/Auth Dialog */ connect( peerdetailsAct , SIGNAL( triggered() ), this, SLOT( peerdetails() ) );
void NetworkDialog::peerdetails() contextMnu.addAction( peerdetailsAct);
}
else
{
peerdetailsAct = new QAction(QIcon(IMAGE_PEERDETAILS), tr( "Make Friend / Peer Details" ), this );
connect( peerdetailsAct , SIGNAL( triggered() ), this, SLOT( peerdetails() ) );
contextMnu.addAction( peerdetailsAct);
loadcertAct = new QAction(QIcon(IMAGE_LOADCERT), tr( "Load Certificate" ), this );
connect( loadcertAct , SIGNAL( triggered() ), this, SLOT( loadneighbour() ) );
contextMnu.addAction( loadcertAct);
}
contextMnu.exec( mevent->globalPos() );
}
/** Shows Peer Information/Auth Dialog */
void NetworkDialog::peerdetails()
{ {
#ifdef NET_DEBUG #ifdef NET_DEBUG
std::cerr << "ConnectionsDialog::peerdetails()" << std::endl; std::cerr << "ConnectionsDialog::peerdetails()" << std::endl;
@ -178,48 +192,48 @@ void NetworkDialog::showpeerdetails(std::string id)
} }
/** Open a QFileDialog to browse for a pem/pqi file. */ /** Open a QFileDialog to browse for a pem/pqi file. */
void NetworkDialog::loadcert() void NetworkDialog::loadcert()
{ {
/* Create a new input dialog, which allows users to create files, too */ /* Create a new input dialog, which allows users to create files, too */
QFileDialog *dialog = new QFileDialog(this, tr("Select a pem/pqi File")); QFileDialog *dialog = new QFileDialog(this, tr("Select a pem/pqi File"));
//dialog->setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir()); //dialog->setDirectory(QFileInfo(ui.lineTorConfig->text()).absoluteDir());
//dialog->selectFile(QFileInfo(ui.lineTorConfig->text()).fileName()); //dialog->selectFile(QFileInfo(ui.lineTorConfig->text()).fileName());
dialog->setFileMode(QFileDialog::AnyFile); dialog->setFileMode(QFileDialog::AnyFile);
dialog->setReadOnly(false); dialog->setReadOnly(false);
/* Prompt the user to select a file or create a new one */ /* Prompt the user to select a file or create a new one */
if (!dialog->exec() || dialog->selectedFiles().isEmpty()) { if (!dialog->exec() || dialog->selectedFiles().isEmpty()) {
return; return;
} }
QString filename = QDir::convertSeparators(dialog->selectedFiles().at(0)); QString filename = QDir::convertSeparators(dialog->selectedFiles().at(0));
/* Check if the file exists */ /* Check if the file exists */
QFile torrcFile(filename); QFile torrcFile(filename);
if (!QFileInfo(filename).exists()) { if (!QFileInfo(filename).exists()) {
/* The given file does not exist. Should we create it? */ /* The given file does not exist. Should we create it? */
int response = VMessageBox::question(this, int response = VMessageBox::question(this,
tr("File Not Found"), tr("File Not Found"),
tr("%1 does not exist. Would you like to create it?") tr("%1 does not exist. Would you like to create it?")
.arg(filename), .arg(filename),
VMessageBox::Yes, VMessageBox::No); VMessageBox::Yes, VMessageBox::No);
if (response == VMessageBox::No) { if (response == VMessageBox::No) {
/* Don't create it. Just bail. */ /* Don't create it. Just bail. */
return; return;
} }
/* Attempt to create the specified file */ /* Attempt to create the specified file */
if (!torrcFile.open(QIODevice::WriteOnly)) { if (!torrcFile.open(QIODevice::WriteOnly)) {
VMessageBox::warning(this, VMessageBox::warning(this,
tr("Failed to Create File"), tr("Failed to Create File"),
tr("Unable to create %1 [%2]").arg(filename) tr("Unable to create %1 [%2]").arg(filename)
.arg(torrcFile.errorString()), .arg(torrcFile.errorString()),
VMessageBox::Ok); VMessageBox::Ok);
return; return;
} }
} }
//ui.lineTorConfig->setText(filename); //ui.lineTorConfig->setText(filename);
} }
@ -367,6 +381,33 @@ void NetworkDialog::insertConnect()
items.append(item); items.append(item);
} }
// add self to network.
RsPeerDetails pd ;
if(rsPeers->getPeerDetails(rsPeers->getOwnId(),pd))
{
QTreeWidgetItem *self_item = new QTreeWidgetItem((QTreeWidget*)0);
self_item->setText(1,"Accept");
self_item->setText(2,"Good");
self_item->setText(3,"0");
self_item->setText(4,QString::fromStdString(pd.name)) ;
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));
for(int i=1;i<10;++i)
{
self_item->setBackground(i,QBrush(Qt::darkGreen));
}
self_item->setIcon(0,(QIcon(IMAGE_AUTHED)));
items.append(self_item);
}
/* remove old items ??? */ /* remove old items ??? */
connectWidget->clear(); connectWidget->clear();
connectWidget->setColumnCount(10); connectWidget->setColumnCount(10);
@ -456,26 +497,26 @@ void NetworkDialog::authneighbour()
*/ */
} }
// Update Log Info information // Update Log Info information
void NetworkDialog::setLogInfo(QString info, QColor color) { void NetworkDialog::setLogInfo(QString info, QColor color) {
static unsigned int nbLines = 0; static unsigned int nbLines = 0;
++nbLines; ++nbLines;
// Check log size, clear it if too big // Check log size, clear it if too big
if(nbLines > 200) { if(nbLines > 200) {
ui.infoLog->clear(); ui.infoLog->clear();
nbLines = 1; 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>")); 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() { void NetworkDialog::on_actionClearLog_triggered() {
ui.infoLog->clear(); ui.infoLog->clear();
} }
void NetworkDialog::displayInfoLogMenu(const QPoint& pos) { void NetworkDialog::displayInfoLogMenu(const QPoint& pos) {
// Log Menu // Log Menu
QMenu myLogMenu(this); QMenu myLogMenu(this);
myLogMenu.addAction(ui.actionClearLog); myLogMenu.addAction(ui.actionClearLog);
// XXX: Why mapToGlobal() is not enough? // XXX: Why mapToGlobal() is not enough?
myLogMenu.exec(mapToGlobal(pos)+QPoint(0,320)); myLogMenu.exec(mapToGlobal(pos)+QPoint(0,320));
} }