2012-02-13 13:43:15 -05:00
|
|
|
/*
|
|
|
|
* Retroshare Identity
|
|
|
|
*
|
|
|
|
* Copyright 2012-2012 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2.1 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gui/Identity/IdEditDialog.h"
|
2013-07-10 17:57:23 -04:00
|
|
|
#include "gui/common/UIStateHelper.h"
|
2012-06-13 20:36:25 -04:00
|
|
|
#include "util/TokenQueue.h"
|
2012-02-13 13:43:15 -05:00
|
|
|
|
|
|
|
#include <retroshare/rsidentity.h>
|
|
|
|
#include <retroshare/rspeers.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2012-06-13 20:36:25 -04:00
|
|
|
#define IDEDITDIALOG_LOADID 1
|
|
|
|
|
2012-02-13 13:43:15 -05:00
|
|
|
/** Constructor */
|
|
|
|
IdEditDialog::IdEditDialog(QWidget *parent)
|
2013-07-10 17:57:23 -04:00
|
|
|
: QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
|
2012-02-13 13:43:15 -05:00
|
|
|
{
|
2013-07-10 17:57:23 -04:00
|
|
|
mIsNew = true;
|
|
|
|
|
2012-02-13 13:43:15 -05:00
|
|
|
ui.setupUi(this);
|
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
/* Setup UI helper */
|
|
|
|
mStateHelper = new UIStateHelper(this);
|
|
|
|
|
|
|
|
mStateHelper->addWidget(IDEDITDIALOG_LOADID, ui.lineEdit_Nickname);
|
|
|
|
mStateHelper->addWidget(IDEDITDIALOG_LOADID, ui.lineEdit_KeyId);
|
|
|
|
mStateHelper->addWidget(IDEDITDIALOG_LOADID, ui.lineEdit_GpgHash);
|
|
|
|
mStateHelper->addWidget(IDEDITDIALOG_LOADID, ui.lineEdit_GpgId);
|
|
|
|
mStateHelper->addWidget(IDEDITDIALOG_LOADID, ui.lineEdit_GpgName);
|
|
|
|
mStateHelper->addWidget(IDEDITDIALOG_LOADID, ui.radioButton_GpgId);
|
|
|
|
mStateHelper->addWidget(IDEDITDIALOG_LOADID, ui.radioButton_Pseudo);
|
|
|
|
|
|
|
|
mStateHelper->addLoadPlaceholder(IDEDITDIALOG_LOADID, ui.lineEdit_Nickname);
|
|
|
|
mStateHelper->addLoadPlaceholder(IDEDITDIALOG_LOADID, ui.lineEdit_GpgName);
|
|
|
|
mStateHelper->addLoadPlaceholder(IDEDITDIALOG_LOADID, ui.lineEdit_KeyId);
|
|
|
|
mStateHelper->addLoadPlaceholder(IDEDITDIALOG_LOADID, ui.lineEdit_GpgHash);
|
|
|
|
mStateHelper->addLoadPlaceholder(IDEDITDIALOG_LOADID, ui.lineEdit_GpgId);
|
|
|
|
mStateHelper->addLoadPlaceholder(IDEDITDIALOG_LOADID, ui.lineEdit_GpgName);
|
|
|
|
|
|
|
|
/* Connect signals */
|
|
|
|
connect(ui.radioButton_GpgId, SIGNAL(toggled(bool)), this, SLOT(idTypeToggled(bool)));
|
|
|
|
connect(ui.radioButton_Pseudo, SIGNAL(toggled(bool)), this, SLOT(idTypeToggled(bool)));
|
|
|
|
connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(updateId()));
|
|
|
|
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(close()));
|
|
|
|
|
2012-11-01 20:49:06 -04:00
|
|
|
mIdQueue = new TokenQueue(rsIdentity->getTokenService(), this);
|
2012-02-13 13:43:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void IdEditDialog::setupNewId(bool pseudo)
|
|
|
|
{
|
2013-07-10 17:57:23 -04:00
|
|
|
setWindowTitle(tr("New identity"));
|
|
|
|
|
|
|
|
mIsNew = true;
|
|
|
|
|
|
|
|
ui.lineEdit_KeyId->setText(tr("To be generated"));
|
2012-02-13 13:43:15 -05:00
|
|
|
ui.lineEdit_Nickname->setText("");
|
|
|
|
ui.radioButton_GpgId->setEnabled(true);
|
|
|
|
ui.radioButton_Pseudo->setEnabled(true);
|
|
|
|
|
|
|
|
if (pseudo)
|
|
|
|
{
|
|
|
|
ui.radioButton_Pseudo->setChecked(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui.radioButton_GpgId->setChecked(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// force - incase it wasn't triggered.
|
2013-07-10 17:57:23 -04:00
|
|
|
idTypeToggled(true);
|
2012-02-13 13:43:15 -05:00
|
|
|
}
|
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
void IdEditDialog::idTypeToggled(bool checked)
|
2012-02-13 13:43:15 -05:00
|
|
|
{
|
|
|
|
if (checked)
|
|
|
|
{
|
|
|
|
bool pseudo = ui.radioButton_Pseudo->isChecked();
|
|
|
|
updateIdType(pseudo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IdEditDialog::updateIdType(bool pseudo)
|
|
|
|
{
|
|
|
|
if (pseudo)
|
|
|
|
{
|
2013-07-10 17:57:23 -04:00
|
|
|
ui.lineEdit_GpgHash->setText(tr("N/A"));
|
|
|
|
ui.lineEdit_GpgId->setText(tr("N/A"));
|
|
|
|
ui.lineEdit_GpgName->setText(tr("N/A"));
|
2012-02-13 13:43:15 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* get GPG Details from rsPeers */
|
|
|
|
std::string gpgid = rsPeers->getGPGOwnId();
|
|
|
|
RsPeerDetails details;
|
|
|
|
rsPeers->getPeerDetails(gpgid, details);
|
|
|
|
|
|
|
|
ui.lineEdit_GpgId->setText(QString::fromStdString(gpgid));
|
2013-07-10 17:57:23 -04:00
|
|
|
ui.lineEdit_GpgHash->setText(tr("To be generated"));
|
2012-02-13 13:43:15 -05:00
|
|
|
ui.lineEdit_GpgName->setText(QString::fromStdString(details.name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-13 20:36:25 -04:00
|
|
|
void IdEditDialog::setupExistingId(std::string keyId)
|
|
|
|
{
|
2013-07-10 17:57:23 -04:00
|
|
|
setWindowTitle(tr("Edit identity"));
|
2012-06-13 20:36:25 -04:00
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
mIsNew = false;
|
2012-06-13 20:36:25 -04:00
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
mStateHelper->setLoading(IDEDITDIALOG_LOADID, true);
|
2012-06-13 20:36:25 -04:00
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
|
|
|
|
|
|
|
std::list<std::string> groupIds;
|
|
|
|
groupIds.push_back(keyId);
|
|
|
|
|
|
|
|
uint32_t token;
|
|
|
|
mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, IDEDITDIALOG_LOADID);
|
|
|
|
}
|
2012-06-13 20:36:25 -04:00
|
|
|
|
|
|
|
void IdEditDialog::loadExistingId(uint32_t token)
|
2012-02-13 13:43:15 -05:00
|
|
|
{
|
2013-07-10 17:57:23 -04:00
|
|
|
mStateHelper->setLoading(IDEDITDIALOG_LOADID, false);
|
2012-02-13 13:43:15 -05:00
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
/* get details from libretroshare */
|
2012-11-01 20:49:06 -04:00
|
|
|
RsGxsIdGroup data;
|
|
|
|
std::vector<RsGxsIdGroup> datavector;
|
|
|
|
if (!rsIdentity->getGroupData(token, datavector))
|
|
|
|
{
|
2013-07-10 17:57:23 -04:00
|
|
|
ui.lineEdit_KeyId->setText(tr("Error getting key!"));
|
2012-11-01 20:49:06 -04:00
|
|
|
return;
|
|
|
|
}
|
2013-07-11 04:14:38 -04:00
|
|
|
|
2012-11-01 20:49:06 -04:00
|
|
|
if (datavector.size() != 1)
|
|
|
|
{
|
|
|
|
std::cerr << "IdDialog::insertIdDetails() Invalid datavector size";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
ui.lineEdit_KeyId->setText(tr("Error KeyID invalid"));
|
2012-02-13 13:43:15 -05:00
|
|
|
ui.lineEdit_Nickname->setText("");
|
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
ui.lineEdit_GpgHash->setText(tr("N/A"));
|
|
|
|
ui.lineEdit_GpgId->setText(tr("N/A"));
|
|
|
|
ui.lineEdit_GpgName->setText(tr("N/A"));
|
2012-02-13 13:43:15 -05:00
|
|
|
return;
|
|
|
|
}
|
2012-11-01 20:49:06 -04:00
|
|
|
|
|
|
|
data = datavector[0];
|
|
|
|
|
2012-11-06 14:18:56 -05:00
|
|
|
bool realid = (data.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID);
|
2012-11-05 17:32:52 -05:00
|
|
|
|
2012-11-06 14:18:56 -05:00
|
|
|
if (realid)
|
2012-02-13 13:43:15 -05:00
|
|
|
{
|
2012-11-06 14:18:56 -05:00
|
|
|
ui.radioButton_GpgId->setChecked(true);
|
2012-02-13 13:43:15 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-06 14:18:56 -05:00
|
|
|
ui.radioButton_Pseudo->setChecked(true);
|
2012-02-13 13:43:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// DOES THIS TRIGGER ALREADY???
|
|
|
|
// force - incase it wasn't triggered.
|
2013-07-10 17:57:23 -04:00
|
|
|
idTypeToggled(true);
|
2012-02-13 13:43:15 -05:00
|
|
|
|
2012-06-13 20:36:25 -04:00
|
|
|
ui.lineEdit_Nickname->setText(QString::fromStdString(data.mMeta.mGroupName));
|
2013-07-10 17:57:23 -04:00
|
|
|
ui.lineEdit_KeyId->setText(QString::fromStdString(data.mMeta.mGroupId));
|
2012-02-13 13:43:15 -05:00
|
|
|
|
2012-11-06 14:18:56 -05:00
|
|
|
if (realid)
|
2012-02-13 13:43:15 -05:00
|
|
|
{
|
2012-11-05 17:32:52 -05:00
|
|
|
ui.lineEdit_GpgHash->setText(QString::fromStdString(data.mPgpIdHash));
|
2012-02-13 13:43:15 -05:00
|
|
|
|
2012-11-06 14:18:56 -05:00
|
|
|
if (data.mPgpKnown)
|
2012-02-13 13:43:15 -05:00
|
|
|
{
|
2012-11-06 14:18:56 -05:00
|
|
|
RsPeerDetails details;
|
|
|
|
rsPeers->getGPGDetails(data.mPgpId, details);
|
|
|
|
ui.lineEdit_GpgName->setText(QString::fromStdString(details.name));
|
|
|
|
|
|
|
|
ui.lineEdit_GpgId->setText(QString::fromStdString(data.mPgpId));
|
2012-02-13 13:43:15 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-10 17:57:23 -04:00
|
|
|
ui.lineEdit_GpgId->setText(tr("Unknown GpgId"));
|
|
|
|
ui.lineEdit_GpgName->setText(tr("Unknown real name"));
|
2012-02-13 13:43:15 -05:00
|
|
|
}
|
|
|
|
}
|
2012-11-06 14:18:56 -05:00
|
|
|
else
|
|
|
|
{
|
2013-07-10 17:57:23 -04:00
|
|
|
ui.lineEdit_GpgHash->setText(tr("N/A"));
|
|
|
|
ui.lineEdit_GpgId->setText(tr("N/A"));
|
|
|
|
ui.lineEdit_GpgName->setText(tr("N/A"));
|
2012-11-06 14:18:56 -05:00
|
|
|
}
|
2012-02-13 13:43:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void IdEditDialog::updateId()
|
|
|
|
{
|
2012-10-31 19:32:56 -04:00
|
|
|
RsGxsIdGroup rid;
|
2012-02-13 13:43:15 -05:00
|
|
|
// Must set, Nickname, KeyId(if existing), mIdType, GpgId.
|
|
|
|
|
2012-06-13 20:36:25 -04:00
|
|
|
rid.mMeta.mGroupName = ui.lineEdit_Nickname->text().toStdString();
|
2012-02-13 13:43:15 -05:00
|
|
|
|
2012-06-13 20:36:25 -04:00
|
|
|
if (rid.mMeta.mGroupName.size() < 2)
|
2012-02-13 13:43:15 -05:00
|
|
|
{
|
|
|
|
std::cerr << "IdEditDialog::updateId() Nickname too short";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-05 17:32:52 -05:00
|
|
|
//rid.mIdType = RSID_RELATION_YOURSELF;
|
2013-07-10 17:57:23 -04:00
|
|
|
if (mIsNew)
|
2012-02-13 13:43:15 -05:00
|
|
|
{
|
2012-06-13 20:36:25 -04:00
|
|
|
rid.mMeta.mGroupId = "";
|
2012-02-13 13:43:15 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-13 20:36:25 -04:00
|
|
|
rid.mMeta.mGroupId = ui.lineEdit_KeyId->text().toStdString();
|
2012-02-13 13:43:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ui.radioButton_GpgId->isChecked())
|
|
|
|
{
|
2012-11-05 17:32:52 -05:00
|
|
|
//rid.mIdType |= RSID_TYPE_REALID;
|
2012-02-13 13:43:15 -05:00
|
|
|
|
2012-11-05 17:32:52 -05:00
|
|
|
//rid.mGpgId = ui.lineEdit_GpgId->text().toStdString();
|
|
|
|
rid.mPgpIdHash = ui.lineEdit_GpgHash->text().toStdString();
|
|
|
|
//rid.mGpgName = ui.lineEdit_GpgName->text().toStdString();
|
2012-02-13 13:43:15 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-05 17:32:52 -05:00
|
|
|
//rid.mIdType |= RSID_TYPE_PSEUDONYM;
|
2012-02-13 13:43:15 -05:00
|
|
|
|
2012-11-05 17:32:52 -05:00
|
|
|
//rid.mGpgId = "";
|
|
|
|
rid.mPgpIdHash = "";
|
|
|
|
//rid.mGpgName = "";
|
|
|
|
//rid.mGpgEmail = "";
|
2012-02-13 13:43:15 -05:00
|
|
|
}
|
2013-07-11 04:14:38 -04:00
|
|
|
|
2012-11-07 16:40:07 -05:00
|
|
|
// Can only create Identities for the moment!
|
|
|
|
RsIdentityParameters params;
|
|
|
|
params.nickname = rid.mMeta.mGroupName;
|
|
|
|
params.isPgpLinked = (ui.radioButton_GpgId->isChecked());
|
|
|
|
|
|
|
|
uint32_t dummyToken = 0;
|
|
|
|
rsIdentity->createIdentity(dummyToken, params);
|
2012-02-13 13:43:15 -05:00
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
close();
|
2012-02-13 13:43:15 -05:00
|
|
|
}
|
|
|
|
|
2013-07-10 17:57:23 -04:00
|
|
|
void IdEditDialog::loadRequest(const TokenQueue */*queue*/, const TokenRequest &req)
|
2012-06-13 20:36:25 -04:00
|
|
|
{
|
|
|
|
std::cerr << "IdDialog::loadRequest() UserType: " << req.mUserType;
|
|
|
|
std::cerr << std::endl;
|
2013-07-11 04:14:38 -04:00
|
|
|
|
2012-06-13 20:36:25 -04:00
|
|
|
// only one here!
|
|
|
|
loadExistingId(req.mToken);
|
|
|
|
}
|