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.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include "rsiface/rspeers.h" //for rsPeers variable
|
|
|
|
#include "rsiface/rsiface.h"
|
|
|
|
|
|
|
|
#include <QtGui>
|
|
|
|
#include <QClipboard>
|
|
|
|
|
|
|
|
#include <rshare.h>
|
|
|
|
#include "CryptoPage.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
/** 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);
|
|
|
|
|
|
|
|
/* Create RshareSettings object */
|
|
|
|
_settings = new RshareSettings();
|
|
|
|
|
|
|
|
connect(ui.copykeyButton, SIGNAL(clicked()), this, SLOT(copyPublicKey()));
|
2010-01-29 18:34:16 -05:00
|
|
|
connect(ui.saveButton, SIGNAL(clicked()), this, SLOT(fileSaveAs()));
|
2009-07-23 13:11:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
loadPublicKey();
|
|
|
|
|
|
|
|
|
|
|
|
/* Hide platform specific features */
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CryptoPage::closeEvent (QCloseEvent * event)
|
|
|
|
{
|
|
|
|
|
|
|
|
QWidget::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Saves the changes on this page */
|
|
|
|
bool
|
|
|
|
CryptoPage::save(QString &errmsg)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Loads the settings for this page */
|
|
|
|
void
|
|
|
|
CryptoPage::load()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Loads ouer default Puplickey */
|
|
|
|
void
|
|
|
|
CryptoPage::loadPublicKey()
|
|
|
|
{
|
2010-01-30 06:25:41 -05:00
|
|
|
ui.certtextEdit->setPlainText(QString::fromStdString(rsPeers->GetRetroshareInvite()));
|
2009-07-23 13:11:51 -04:00
|
|
|
ui.certtextEdit->setReadOnly(true);
|
|
|
|
ui.certtextEdit->setMinimumHeight(200);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2009-08-19 18:15:16 -04:00
|
|
|
clipboard->setText(ui.certtextEdit->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"));
|
|
|
|
ts << ui.certtextEdit->document()->toPlainText();
|
|
|
|
ui.certtextEdit->document()->setModified(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CryptoPage::fileSaveAs()
|
|
|
|
{
|
|
|
|
QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."),
|
2010-01-30 10:33:25 -05:00
|
|
|
QString(), tr("RetroShare Certificate (*.rsc );;All Files (*)"));
|
2010-01-29 18:34:16 -05:00
|
|
|
if (fn.isEmpty())
|
|
|
|
return false;
|
|
|
|
setCurrentFileName(fn);
|
2010-02-09 15:04:44 -05:00
|
|
|
return fileSave();
|
2010-01-29 18:34:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void CryptoPage::setCurrentFileName(const QString &fileName)
|
|
|
|
{
|
|
|
|
this->fileName = fileName;
|
|
|
|
ui.certtextEdit->document()->setModified(false);
|
|
|
|
|
|
|
|
setWindowModified(false);
|
2010-01-30 06:25:41 -05:00
|
|
|
}
|