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 */
|
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
|
|
|
{
|
|
|
|
/* 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()));
|
2014-01-18 11:53:19 -05: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
|
2014-09-25 16:14:21 -04:00
|
|
|
connect(ui.createNewLocation_PB,SIGNAL(clicked()), this, SLOT(profilemanager()));
|
2013-02-22 16:42:27 -05:00
|
|
|
|
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()
|
|
|
|
{
|
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 */
|
2013-09-29 03:10:19 -04:00
|
|
|
std::string version;
|
|
|
|
rsDisc->getPeerVersion(detail.id, version);
|
|
|
|
ui.version->setText(QString::fromStdString(version));
|
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
|
|
|
/** 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 */
|
2014-01-19 09:42:16 -05:00
|
|
|
ui.certplainTextEdit->setPlainText(QString::fromUtf8(rsPeers->GetRetroshareInvite(ui._includeSignatures_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 ;
|
2014-03-17 16:56:06 -04:00
|
|
|
RsPeerId 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
|
|
|
}
|