2009-07-23 13:11:51 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 - 2009 RetroShare Team
|
|
|
|
*
|
|
|
|
* 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-08-19 18:15:16 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2009-07-23 13:11:51 -04:00
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
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>
|
2013-02-22 16:42:27 -05:00
|
|
|
#include <gui/profile/ProfileManager.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 */
|
|
|
|
CryptoPage::CryptoPage(QWidget * parent, Qt::WFlags flags)
|
2009-08-19 18:15:16 -04:00
|
|
|
: ConfigPage(parent, flags)
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
2013-02-22 16:42:27 -05:00
|
|
|
// connect(ui.copykeyButton, SIGNAL(clicked()), this, SLOT(copyPublicKey()));
|
2010-01-29 18:34:16 -05:00
|
|
|
connect(ui.saveButton, SIGNAL(clicked()), this, SLOT(fileSaveAs()));
|
2012-01-24 17:31:53 -05:00
|
|
|
connect(ui._includeSignatures_CB, SIGNAL(toggled(bool)), this, SLOT(load()));
|
|
|
|
connect(ui._copyLink_PB, SIGNAL(clicked()), this, SLOT(copyRSLink()));
|
2012-08-27 18:15:27 -04:00
|
|
|
connect(ui._useOldFormat_CB, SIGNAL(toggled(bool)), this, SLOT(load()));
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2013-03-18 10:16:22 -04:00
|
|
|
// hide profile manager as it causes bugs when generating a new profile.
|
2013-03-19 17:10:54 -04:00
|
|
|
//ui.profile_Button->hide() ;
|
2013-03-18 10:16:22 -04:00
|
|
|
|
2009-07-23 13:11:51 -04:00
|
|
|
/* Hide platform specific features */
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
|
|
|
|
#endif
|
2013-02-22 16:42:27 -05:00
|
|
|
connect(ui.profile_Button,SIGNAL(clicked()), this, SLOT(profilemanager()));
|
|
|
|
|
2013-04-22 17:12:38 -04:00
|
|
|
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()
|
|
|
|
{
|
|
|
|
ProfileManager profilemanager;
|
|
|
|
profilemanager.exec();
|
|
|
|
}
|
|
|
|
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()));
|
|
|
|
|
|
|
|
ui.peerid->setText(QString::fromStdString(detail.id));
|
|
|
|
ui.pgpid->setText(QString::fromStdString(detail.gpg_id));
|
2013-10-07 17:01:05 -04:00
|
|
|
ui.pgpfingerprint->setText(QString::fromStdString(detail.fpr));
|
2013-02-22 16:42:27 -05:00
|
|
|
|
|
|
|
/* 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));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list<std::string> ids;
|
|
|
|
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
|
|
|
/** Saves the changes on this page */
|
|
|
|
bool
|
2011-08-12 10:06:29 -04:00
|
|
|
CryptoPage::save(QString &/*errmsg*/)
|
2009-07-23 13:11:51 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Loads the settings for this page */
|
|
|
|
void
|
|
|
|
CryptoPage::load()
|
|
|
|
{
|
2011-06-14 20:40:07 -04:00
|
|
|
/* Loads ouer default Puplickey */
|
2013-04-22 17:12:38 -04:00
|
|
|
ui.certplainTextEdit->setPlainText(QString::fromUtf8(rsPeers->GetRetroshareInvite(ui._includeSignatures_CB->isChecked(),ui._useOldFormat_CB->isChecked()).c_str()));
|
2009-07-23 13:11:51 -04:00
|
|
|
}
|
2012-01-24 17:31:53 -05:00
|
|
|
void
|
|
|
|
CryptoPage::copyRSLink()
|
|
|
|
{
|
|
|
|
RetroShareLink link ;
|
|
|
|
std::string ownId = rsPeers->getOwnId() ;
|
2009-07-23 13:11:51 -04:00
|
|
|
|
2012-01-24 17:31:53 -05:00
|
|
|
if( link.createCertificate(ownId) )
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|