2018-12-23 11:49:01 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* gui/settings/CryptoPage.cpp *
|
|
|
|
* *
|
|
|
|
* Copyright 2006, Retroshare Team <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2013-02-22 16:42:27 -05:00
|
|
|
#include <QDate>
|
2010-07-23 14:52:58 -04:00
|
|
|
#include <QMessageBox>
|
2009-07-23 13:11:51 -04:00
|
|
|
#include <QClipboard>
|
2010-12-02 19:54:40 -05:00
|
|
|
#include <QFile>
|
2010-07-23 14:52:58 -04:00
|
|
|
#include <QTextStream>
|
|
|
|
#include <QTextCodec>
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2013-04-22 17:12:38 -04:00
|
|
|
#include "rshare.h"
|
2009-07-23 13:11:51 -04:00
|
|
|
#include "CryptoPage.h"
|
2010-12-02 19:54:40 -05:00
|
|
|
#include "util/misc.h"
|
2013-02-22 16:42:27 -05:00
|
|
|
#include "util/DateTime.h"
|
2012-01-24 17:31:53 -05:00
|
|
|
#include <gui/RetroShareLink.h>
|
2018-10-20 11:31:52 -04:00
|
|
|
#include <gui/connect/ConfCertDialog.h>
|
2013-02-22 16:42:27 -05:00
|
|
|
#include <gui/profile/ProfileManager.h>
|
2015-05-21 07:18:55 -04:00
|
|
|
#include <gui/statistics/StatisticsWindow.h>
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rspeers.h> //for rsPeers variable
|
2013-02-22 16:42:27 -05:00
|
|
|
#include <retroshare/rsdisc.h> //for rsPeers variable
|
2009-07-23 13:11:51 -04:00
|
|
|
|
|
|
|
/** Constructor */
|
2013-10-18 17:10:33 -04:00
|
|
|
CryptoPage::CryptoPage(QWidget * parent, Qt::WindowFlags flags)
|
2009-08-19 18:15:16 -04:00
|
|
|
: ConfigPage(parent, flags)
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
2019-06-06 15:41:38 -04:00
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2019-06-06 15:41:38 -04:00
|
|
|
ui._shortFormat_CB->setChecked(true);
|
2014-01-18 11:53:19 -05:00
|
|
|
|
2019-06-06 15:41:38 -04:00
|
|
|
// connect(ui.copykeyButton, SIGNAL(clicked()), this, SLOT(copyPublicKey()));
|
|
|
|
connect(ui.saveButton, SIGNAL(clicked()), this, SLOT(fileSaveAs()));
|
|
|
|
connect(ui._includeSignatures_CB, SIGNAL(toggled(bool)), this, SLOT(load()));
|
|
|
|
connect(ui._shortFormat_CB, SIGNAL(toggled(bool)), this, SLOT(load()));
|
|
|
|
connect(ui._includeAllIPs_CB, SIGNAL(toggled(bool)), this, SLOT(load()));
|
|
|
|
connect(ui._copyLink_PB, SIGNAL(clicked()), this, SLOT(copyRSLink()));
|
|
|
|
connect(ui.showStats_PB, SIGNAL(clicked()), this, SLOT(showStats()));
|
2013-03-18 10:16:22 -04:00
|
|
|
|
2019-06-06 15:41:38 -04:00
|
|
|
// hide profile manager as it causes bugs when generating a new profile.
|
|
|
|
//ui.profile_Button->hide() ;
|
2013-02-22 16:42:27 -05:00
|
|
|
|
2019-06-06 15:41:38 -04:00
|
|
|
connect(ui.createNewNode_PB,SIGNAL(clicked()), this, SLOT(profilemanager()));
|
|
|
|
|
|
|
|
ui.onlinesince->setText(DateTime::formatLongDateTime(Rshare::startupTime()));
|
2013-02-22 16:42:27 -05:00
|
|
|
}
|
2013-04-22 17:12:38 -04:00
|
|
|
|
2013-02-22 16:42:27 -05:00
|
|
|
void CryptoPage::profilemanager()
|
|
|
|
{
|
2014-09-25 16:14:21 -04:00
|
|
|
ProfileManager().exec();
|
2013-02-22 16:42:27 -05:00
|
|
|
}
|
|
|
|
void CryptoPage::showEvent ( QShowEvent * /*event*/ )
|
|
|
|
{
|
|
|
|
RsPeerDetails detail;
|
|
|
|
if (rsPeers->getPeerDetails(rsPeers->getOwnId(),detail))
|
|
|
|
{
|
|
|
|
ui.name->setText(QString::fromUtf8(detail.name.c_str()));
|
|
|
|
ui.country->setText(QString::fromUtf8(detail.location.c_str()));
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
ui.peerid->setText(QString::fromStdString(detail.id.toStdString()));
|
|
|
|
ui.pgpid->setText(QString::fromStdString(detail.gpg_id.toStdString()));
|
|
|
|
ui.pgpfingerprint->setText(misc::fingerPrintStyleSplit(QString::fromStdString(detail.fpr.toStdString())));
|
2013-02-22 16:42:27 -05:00
|
|
|
|
|
|
|
/* set retroshare version */
|
2015-03-08 09:31:44 -04:00
|
|
|
ui.version->setText(Rshare::retroshareVersion(true));
|
2013-02-22 16:42:27 -05:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
std::list<RsPgpId> ids;
|
2013-02-22 16:42:27 -05:00
|
|
|
ids.clear();
|
|
|
|
rsPeers->getGPGAcceptedList(ids);
|
|
|
|
int friends = ids.size();
|
|
|
|
|
|
|
|
ui.friendsEdit->setText(QString::number(friends));
|
|
|
|
}
|
|
|
|
load() ;
|
2009-07-23 13:11:51 -04:00
|
|
|
}
|
|
|
|
|
2013-02-22 16:42:27 -05:00
|
|
|
|
2010-05-07 19:58:17 -04:00
|
|
|
CryptoPage::~CryptoPage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
/** Loads the settings for this page */
|
|
|
|
void
|
|
|
|
CryptoPage::load()
|
|
|
|
{
|
2019-06-06 15:41:38 -04:00
|
|
|
std::string cert ;
|
|
|
|
|
|
|
|
if(ui._shortFormat_CB->isChecked())
|
|
|
|
rsPeers->getShortInvite(cert,rsPeers->getOwnId(), true, !ui._includeAllIPs_CB->isChecked());
|
|
|
|
else
|
|
|
|
cert = rsPeers->GetRetroshareInvite( rsPeers->getOwnId(), ui._includeSignatures_CB->isChecked(), ui._includeAllIPs_CB->isChecked() );
|
|
|
|
|
|
|
|
ui.certplainTextEdit->setPlainText( QString::fromUtf8( cert.c_str() ) );
|
2018-10-20 11:31:52 -04:00
|
|
|
|
|
|
|
RsPeerDetails detail;
|
|
|
|
rsPeers->getPeerDetails(rsPeers->getOwnId(),detail);
|
|
|
|
|
2019-06-06 15:41:38 -04:00
|
|
|
ui.certplainTextEdit->setToolTip(ConfCertDialog::getCertificateDescription(detail, ui._includeSignatures_CB->isChecked(), ui._shortFormat_CB->isChecked(), ui._includeAllIPs_CB->isChecked() ));
|
2009-07-23 13:11:51 -04:00
|
|
|
}
|
2019-06-06 15:41:38 -04:00
|
|
|
|
2012-01-24 17:31:53 -05:00
|
|
|
void
|
|
|
|
CryptoPage::copyRSLink()
|
|
|
|
{
|
2014-03-17 16:56:06 -04:00
|
|
|
RsPeerId ownId = rsPeers->getOwnId() ;
|
2017-07-16 07:11:47 -04:00
|
|
|
RetroShareLink link = RetroShareLink::createCertificate(ownId);
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2017-07-16 07:11:47 -04:00
|
|
|
if( link.valid() )
|
2012-01-24 17:31:53 -05:00
|
|
|
{
|
|
|
|
QList<RetroShareLink> urls ;
|
|
|
|
|
|
|
|
urls.push_back(link) ;
|
|
|
|
RSLinkClipboard::copyLinks(urls) ;
|
|
|
|
QMessageBox::information(this,
|
2012-02-05 16:05:11 -05:00
|
|
|
"RetroShare",
|
2012-01-24 17:31:53 -05:00
|
|
|
tr("A RetroShare link with your Public Key is copied to Clipboard, paste and send it to your"
|
|
|
|
" friend via email or some other way"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
QMessageBox::warning(this,
|
|
|
|
tr("Error"),
|
2012-10-11 06:28:24 -04:00
|
|
|
tr("Your certificate could not be parsed correctly. Please contact the developers."));
|
2012-01-24 17:31:53 -05:00
|
|
|
}
|
2009-07-23 13:11:51 -04:00
|
|
|
void
|
|
|
|
CryptoPage::copyPublicKey()
|
|
|
|
{
|
|
|
|
QMessageBox::information(this,
|
|
|
|
tr("RetroShare"),
|
2010-01-30 06:25:41 -05:00
|
|
|
tr("Your Public Key is copied to Clipboard, paste and send it to your"
|
|
|
|
" friend via email or some other way"));
|
2009-07-23 13:11:51 -04:00
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
2013-04-22 17:12:38 -04:00
|
|
|
clipboard->setText(ui.certplainTextEdit->toPlainText());
|
2009-07-23 13:11:51 -04:00
|
|
|
}
|
|
|
|
|
2010-01-29 18:34:16 -05:00
|
|
|
bool CryptoPage::fileSave()
|
|
|
|
{
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
return fileSaveAs();
|
|
|
|
|
|
|
|
QFile file(fileName);
|
|
|
|
if (!file.open(QFile::WriteOnly))
|
|
|
|
return false;
|
|
|
|
QTextStream ts(&file);
|
|
|
|
ts.setCodec(QTextCodec::codecForName("UTF-8"));
|
2013-04-22 17:12:38 -04:00
|
|
|
ts << ui.certplainTextEdit->document()->toPlainText();
|
2010-01-29 18:34:16 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CryptoPage::fileSaveAs()
|
|
|
|
{
|
2010-12-02 19:54:40 -05:00
|
|
|
QString fn;
|
|
|
|
if (misc::getSaveFileName(this, RshareSettings::LASTDIR_CERT, tr("Save as..."), tr("RetroShare Certificate (*.rsc );;All Files (*)"), fn)) {
|
2013-04-22 17:12:38 -04:00
|
|
|
fileName = fn;
|
2010-12-02 19:54:40 -05:00
|
|
|
return fileSave();
|
|
|
|
}
|
|
|
|
return false;
|
2010-01-29 18:34:16 -05:00
|
|
|
}
|
2015-05-21 07:18:55 -04:00
|
|
|
|
|
|
|
void CryptoPage::showStats()
|
|
|
|
{
|
|
|
|
StatisticsWindow::showYourself();
|
|
|
|
}
|