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
|
2009-07-17 17:41:20 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2007-11-14 22:18:48 -05:00
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
#include "ConfCertDialog.h"
|
|
|
|
|
|
|
|
#include "rsiface/rsiface.h"
|
2008-01-25 03:49:40 -05:00
|
|
|
#include "rsiface/rspeers.h"
|
2009-07-17 17:41:20 -04:00
|
|
|
#include "rsiface/rsdisc.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-01-01 19:55:03 -05:00
|
|
|
#include <QTime>
|
2010-01-13 16:11:02 -05:00
|
|
|
#include <QtGui>
|
2009-01-01 19:55:03 -05:00
|
|
|
|
2009-05-07 18:43:11 -04:00
|
|
|
ConfCertDialog *ConfCertDialog::instance()
|
|
|
|
{
|
|
|
|
static ConfCertDialog *confdialog = new ConfCertDialog ;
|
|
|
|
|
|
|
|
return confdialog ;
|
|
|
|
}
|
2009-01-01 19:55:03 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* Define the format used for displaying the date and time */
|
|
|
|
#define DATETIME_FMT "MMM dd hh:mm:ss"
|
|
|
|
|
|
|
|
/** Default constructor */
|
|
|
|
ConfCertDialog::ConfCertDialog(QWidget *parent, Qt::WFlags flags)
|
2008-04-07 20:31:46 -04:00
|
|
|
: QDialog(parent, flags)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
/* Invoke Qt Designer generated QObject setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
|
|
|
|
connect(ui.applyButton, SIGNAL(clicked()), this, SLOT(applyDialog()));
|
|
|
|
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(closeinfodlg()));
|
2010-01-13 16:11:02 -05:00
|
|
|
connect(ui.sign_button, SIGNAL(clicked()), this, SLOT(makeFriend()));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-17 17:41:20 -04:00
|
|
|
|
2009-05-16 13:17:46 -04:00
|
|
|
ui.applyButton->setToolTip(tr("Apply and Close"));
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-05-07 18:43:11 -04:00
|
|
|
void ConfCertDialog::show(const std::string& peer_id)
|
|
|
|
{
|
|
|
|
/* set the Id */
|
|
|
|
|
|
|
|
instance()->loadId(peer_id);
|
|
|
|
instance()->show();
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
2009-07-17 17:41:20 -04:00
|
|
|
/**
|
2007-11-14 22:18:48 -05:00
|
|
|
Overloads the default show() slot so we can set opacity*/
|
|
|
|
|
|
|
|
void
|
|
|
|
ConfCertDialog::show()
|
|
|
|
{
|
|
|
|
//loadSettings();
|
|
|
|
if(!this->isVisible()) {
|
2008-04-07 20:31:46 -04:00
|
|
|
QDialog::show();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfCertDialog::closeEvent (QCloseEvent * event)
|
|
|
|
{
|
|
|
|
QWidget::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfCertDialog::closeinfodlg()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfCertDialog::loadId(std::string id)
|
|
|
|
{
|
|
|
|
mId = id;
|
|
|
|
loadDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ConfCertDialog::loadDialog()
|
|
|
|
{
|
2010-01-13 16:11:02 -05:00
|
|
|
isPGPId = false;
|
2008-01-25 03:49:40 -05:00
|
|
|
RsPeerDetails detail;
|
|
|
|
if (!rsPeers->getPeerDetails(mId, detail))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-01-13 16:11:02 -05:00
|
|
|
isPGPId = true;
|
|
|
|
if (!rsPeers->getPGPDetails(mId, detail)) {
|
|
|
|
QMessageBox::information(this,
|
|
|
|
tr("RetroShare"),
|
|
|
|
tr("Error : cannot get peer details."));
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
}
|
2009-07-17 17:41:20 -04:00
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
ui.name->setText(QString::fromStdString(detail.name));
|
2009-01-01 19:55:03 -05:00
|
|
|
ui.peerid->setText(QString::fromStdString(detail.id));
|
2010-01-13 16:11:02 -05:00
|
|
|
if (!isPGPId) {
|
|
|
|
ui.orgloc->setText(QString::fromStdString(detail.org));
|
|
|
|
ui.country->setText(QString::fromStdString(detail.location));
|
|
|
|
// Dont Show a timestamp in RS calculate the day
|
|
|
|
QDateTime date = QDateTime::fromTime_t(detail.lastConnect);
|
|
|
|
QString stime = date.toString(Qt::LocalDate);
|
|
|
|
ui.lastcontact-> setText(stime);
|
|
|
|
|
|
|
|
/* set retroshare 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(detail.id)))
|
|
|
|
{
|
|
|
|
ui.version->setText(QString::fromStdString(vit->second));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set local address */
|
|
|
|
ui.localAddress->setText(QString::fromStdString(detail.localAddr));
|
|
|
|
ui.localPort -> setValue(detail.localPort);
|
|
|
|
/* set the server address */
|
|
|
|
ui.extAddress->setText(QString::fromStdString(detail.extAddr));
|
|
|
|
ui.extPort -> setValue(detail.extPort);
|
|
|
|
|
|
|
|
ui.ipAddressList->clear();
|
|
|
|
for(std::list<std::string>::const_iterator it(detail.ipAddressList.begin());it!=detail.ipAddressList.end();++it)
|
|
|
|
ui.ipAddressList->addItem(QString::fromStdString(*it));
|
|
|
|
} else {
|
|
|
|
ui.orgloc->hide();
|
|
|
|
ui.label_11->hide();
|
|
|
|
ui.country->hide();
|
|
|
|
ui.label_8->hide();
|
|
|
|
ui.lastcontact->hide();
|
|
|
|
ui.label_7->hide();
|
|
|
|
ui.version->hide();
|
|
|
|
ui.label_3->hide();
|
|
|
|
|
|
|
|
ui.groupBox->hide();
|
|
|
|
}
|
2009-11-11 17:12:50 -05:00
|
|
|
|
2008-01-25 03:49:40 -05:00
|
|
|
/* set the url for DNS access (OLD) */
|
2009-05-07 18:43:11 -04:00
|
|
|
//ui.extName->setText(QString::fromStdString(""));
|
2008-01-25 03:49:40 -05:00
|
|
|
|
|
|
|
/**** TODO ****/
|
|
|
|
//ui.chkFirewall ->setChecked(ni->firewalled);
|
|
|
|
//ui.chkForwarded ->setChecked(ni->forwardPort);
|
2008-04-05 08:14:49 -04:00
|
|
|
//ui.chkFirewall ->setChecked(0);
|
|
|
|
//ui.chkForwarded ->setChecked(0);
|
2009-07-17 17:41:20 -04:00
|
|
|
|
2008-04-05 08:14:49 -04:00
|
|
|
//ui.indivRate->setValue(0);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-05-07 18:43:11 -04:00
|
|
|
//ui.trustLvl->setText(QString::fromStdString(RsPeerTrustString(detail.trustLvl)));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-01-13 16:11:02 -05:00
|
|
|
if (detail.ownsign) {
|
|
|
|
ui.sign_button->hide();
|
|
|
|
ui.signed_already_label->show();
|
|
|
|
} else {
|
|
|
|
ui.sign_button->show();
|
|
|
|
ui.signed_already_label->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasSignedMe = false;
|
|
|
|
RsPeerDetails ownGPGDetails ;
|
|
|
|
rsPeers->getPGPDetails(rsPeers->getPGPOwnId(), ownGPGDetails);
|
|
|
|
std::list<std::string>::iterator signersIt;
|
|
|
|
for(signersIt = ownGPGDetails.gpgSigners.begin(); signersIt != ownGPGDetails.gpgSigners.end() ; ++signersIt) {
|
|
|
|
if (*signersIt == detail.id) {
|
|
|
|
hasSignedMe = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasSignedMe) {
|
|
|
|
ui.is_signing_me->setText(tr("Peer has acepted me as a friend and did not signed my GPG key"));
|
|
|
|
} else {
|
|
|
|
ui.is_signing_me->setText(tr("Peer has not acepted me as a friend and did not signed my GPG key"));
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.signers->clear() ;
|
|
|
|
for(std::list<std::string>::const_iterator it(detail.gpgSigners.begin());it!=detail.gpgSigners.end();++it) {
|
|
|
|
RsPeerDetails signerDetail;
|
|
|
|
if (rsPeers->getPGPDetails(*it, signerDetail)) {
|
|
|
|
ui.signers->append(QString::fromStdString(signerDetail.name));
|
|
|
|
}
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ConfCertDialog::applyDialog()
|
|
|
|
{
|
2009-05-07 18:43:11 -04:00
|
|
|
std::cerr << "In apply dialog" << std::endl ;
|
2008-01-25 03:49:40 -05:00
|
|
|
RsPeerDetails detail;
|
|
|
|
if (!rsPeers->getPeerDetails(mId, detail))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-05-07 18:43:11 -04:00
|
|
|
std::cerr << "Could not get details from " << mId << std::endl ;
|
2007-11-14 22:18:48 -05:00
|
|
|
/* fail */
|
|
|
|
return;
|
|
|
|
}
|
2009-07-17 17:41:20 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* check if the data is the same */
|
|
|
|
bool localChanged = false;
|
|
|
|
bool extChanged = false;
|
|
|
|
bool fwChanged = false;
|
|
|
|
|
|
|
|
/* set local address */
|
2009-05-07 18:43:11 -04:00
|
|
|
if ((detail.localAddr != ui.localAddress->text().toStdString()) || (detail.localPort != ui.localPort -> value()))
|
2007-11-14 22:18:48 -05:00
|
|
|
localChanged = true;
|
|
|
|
|
2009-05-07 18:43:11 -04:00
|
|
|
if ((detail.extAddr != ui.extAddress->text().toStdString()) || (detail.extPort != ui.extPort -> value()))
|
2007-11-14 22:18:48 -05:00
|
|
|
extChanged = true;
|
|
|
|
|
|
|
|
/* now we can action the changes */
|
|
|
|
if (localChanged)
|
2009-05-07 18:43:11 -04:00
|
|
|
rsPeers->setLocalAddress(mId, ui.localAddress->text().toStdString(), ui.localPort->value());
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
if (extChanged)
|
2009-05-07 18:43:11 -04:00
|
|
|
rsPeers->setExtAddress(mId,ui.extAddress->text().toStdString(), ui.extPort->value());
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* reload now */
|
|
|
|
loadDialog();
|
2009-07-17 17:41:20 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* close the Dialog after the Changes applied */
|
|
|
|
closeinfodlg();
|
2009-05-07 18:43:11 -04:00
|
|
|
|
2010-01-13 16:11:02 -05:00
|
|
|
if(localChanged || extChanged)
|
2009-05-07 18:43:11 -04:00
|
|
|
emit configChanged() ;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-05-07 18:43:11 -04:00
|
|
|
void ConfCertDialog::makeFriend()
|
|
|
|
{
|
2010-01-13 16:11:02 -05:00
|
|
|
rsPeers->SignGPGCertificate(mId);
|
|
|
|
loadDialog();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|