- 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QFile>
****************************************************************/
#include <QFile>
#include <QFileInfo>
#include "rshare.h"
#include "common/vmessagebox.h"
#include "util/rsversion.h"
#include "util/rsversion.h"
#include "NetworkDialog.h"
#include "NetworkView.h"
#include "connect/ConnectDialog.h"
@ -39,30 +39,30 @@
#include <QPoint>
#include <QMouseEvent>
#include <QPixmap>
#include <QHeaderView>
/* Images for context menu icons */
#include <QHeaderView>
/* Images for context menu icons */
#define IMAGE_LOADCERT ":/images/loadcert16.png"
#define IMAGE_PEERDETAILS ":/images/peerdetails_16x16.png"
#define IMAGE_AUTH ":/images/encrypted16.png"
/* Images for Status icons */
#define IMAGE_AUTHED ":/images/accepted16.png"
#define IMAGE_DENIED ":/images/denied16.png"
RsCertId getNeighRsCertId(QTreeWidgetItem *i);
/******
* #define NET_DEBUG 1
*****/
/** Constructor */
NetworkDialog::NetworkDialog(QWidget *parent)
/** Constructor */
NetworkDialog::NetworkDialog(QWidget *parent)
: MainPage(parent), connectdialog(NULL)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
connect( ui.connecttreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( connecttreeWidgetCostumPopupMenu( QPoint ) ) );
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
connect( ui.connecttreeWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( connecttreeWidgetCostumPopupMenu( QPoint ) ) );
/* create a single connect dialog */
connectdialog = new ConnectDialog();
@ -73,18 +73,18 @@ NetworkDialog::NetworkDialog(QWidget *parent)
ui.connecttreeWidget -> setRootIsDecorated( false );
/* Set header resize modes and initial section sizes */
QHeaderView * _header = ui.connecttreeWidget->header () ;
_header->setResizeMode (0, QHeaderView::Custom);
_header->setResizeMode (1, QHeaderView::Interactive);
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);
_header->setResizeMode (3, QHeaderView::Interactive);
_header->setResizeMode (4, QHeaderView::Interactive);
_header->setResizeMode (5, QHeaderView::Interactive);
_header->setResizeMode (5, QHeaderView::Interactive);
_header->setResizeMode (6, QHeaderView::Interactive);
_header->setResizeMode (7, QHeaderView::Interactive);
_header->setResizeMode (7, QHeaderView::Interactive);
_header->setResizeMode (8, QHeaderView::Interactive);
_header->setResizeMode (9, QHeaderView::Interactive);
_header->setResizeMode (9, QHeaderView::Interactive);
_header->resizeSection ( 0, 25 );
_header->resizeSection ( 1, 100 );
_header->resizeSection ( 2, 100 );
@ -110,45 +110,59 @@ NetworkDialog::NetworkDialog(QWidget *parent)
headerItem->setTextAlignment(9, Qt::AlignHCenter | Qt::AlignVCenter);
networkview = new NetworkView(ui.networkviewTab);
QVBoxLayout *layout = new QVBoxLayout;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(networkview);
ui.networkviewTab->setLayout(layout);
layout->setSpacing( 0 );
layout->setSpacing( 0 );
layout->setMargin( 0 );
// Set Log infos
setLogInfo(tr("RetroShare %1 started.", "e.g: RetroShare v0.x started.").arg(retroshareVersion()));
// Set Log infos
setLogInfo(tr("RetroShare %1 started.", "e.g: RetroShare v0.x started.").arg(retroshareVersion()));
setLogInfo(tr("Welcome to RetroShare."), QString::fromUtf8("blue"));
/* Hide platform specific features */
#ifdef Q_WS_WIN
#endif
}
/* Hide platform specific features */
#ifdef Q_WS_WIN
void NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint point )
{
QMenu contextMnu( this );
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 );
connect( peerdetailsAct , SIGNAL( triggered() ), this, SLOT( peerdetails() ) );
loadcertAct = new QAction(QIcon(IMAGE_LOADCERT), tr( "Load Certificate" ), this );
connect( loadcertAct , SIGNAL( triggered() ), this, SLOT( loadneighbour() ) );
contextMnu.clear();
contextMnu.addAction( peerdetailsAct);
contextMnu.addAction( loadcertAct);
contextMnu.exec( mevent->globalPos() );
}
/** Shows Peer Information/Auth Dialog */
void NetworkDialog::peerdetails()
#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();
if(wi->text(9).toStdString() == rsPeers->getOwnId())
{
peerdetailsAct = new QAction(QIcon(IMAGE_PEERDETAILS), tr( "Peer Details" ), this );
connect( peerdetailsAct , SIGNAL( triggered() ), this, SLOT( 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
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. */
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);
}
/** 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);
}
@ -367,6 +381,33 @@ void NetworkDialog::insertConnect()
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 ??? */
connectWidget->clear();
connectWidget->setColumnCount(10);
@ -456,26 +497,26 @@ void NetworkDialog::authneighbour()
*/
}
// 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?
myLogMenu.exec(mapToGlobal(pos)+QPoint(0,320));
// 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?
myLogMenu.exec(mapToGlobal(pos)+QPoint(0,320));
}