Added new entry to GxsIdChooser to create a new identity.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7787 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2014-12-23 19:07:57 +00:00
parent 4ae50dd1f8
commit 47f0f7236e
2 changed files with 105 additions and 98 deletions

View File

@ -24,8 +24,8 @@
#include "GxsIdChooser.h"
#include "GxsIdDetails.h"
#include "RsGxsUpdateBroadcastBase.h"
#include "gui/Identity/IdDialog.h"
#include <QTimer>
#include <QSortFilterProxyModel>
#include <algorithm>
@ -33,17 +33,19 @@
#include <iostream>
#define MAX_TRY 10 // 5 seconds
#define ROLE_SORT Qt::UserRole + 1 // Qt::UserRole is reserved for data
#define ROLE_TYPE Qt::UserRole + 2 //
/* Used for sorting too */
#define TYPE_NO_ID 1
#define TYPE_FOUND_ID 2
#define TYPE_UNKNOWN_ID 3
#define TYPE_CREATE_ID 4
#define IDCHOOSER_REFRESH 1
//#define IDCHOOSER_DEBUG
/** Constructor */
GxsIdChooser::GxsIdChooser(QWidget *parent)
: QComboBox(parent), mFlags(IDCHOOSER_ANON_DEFAULT)
@ -64,7 +66,10 @@ GxsIdChooser::GxsIdChooser(QWidget *parent)
setModel(proxy);
proxy->setSortRole(ROLE_SORT);
/* Connect signals */
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(myCurrentIndexChanged(int)));
connect(this, SIGNAL(activated(int)), this, SLOT(indexActivated(int)));
mIdQueue = new TokenQueue(rsIdentity->getTokenService(), this);
}
@ -74,6 +79,7 @@ void GxsIdChooser::setFlags(uint32_t flags)
mFlags = flags ;
updateDisplay(true);
}
GxsIdChooser::~GxsIdChooser()
{
if (mIdQueue) {
@ -82,21 +88,6 @@ GxsIdChooser::~GxsIdChooser()
}
}
void GxsIdChooser::setUpdateWhenInvisible(bool update)
{
mBase->setUpdateWhenInvisible(update);
}
const std::list<RsGxsGroupId> &GxsIdChooser::getGrpIds()
{
return mBase->getGrpIds();
}
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &GxsIdChooser::getMsgIds()
{
return mBase->getMsgIds();
}
void GxsIdChooser::fillDisplay(bool complete)
{
updateDisplay(complete);
@ -109,7 +100,6 @@ void GxsIdChooser::showEvent(QShowEvent *event)
QComboBox::showEvent(event);
}
void GxsIdChooser::loadIds(uint32_t chooserFlags, RsGxsId defId)
{
mFlags = chooserFlags;
@ -138,14 +128,16 @@ static void loadPrivateIdsCallback(GxsIdDetailsType type, const RsIdentityDetail
index = chooser->count() - 1;
}
chooser->setItemData(index, QString("%1_%2").arg((type == GXS_ID_DETAILS_TYPE_DONE) ? "1" : "2").arg(text), ROLE_SORT);
chooser->setItemData(index, QString("%1_%2").arg((type == GXS_ID_DETAILS_TYPE_DONE) ? TYPE_FOUND_ID : TYPE_UNKNOWN_ID).arg(text), ROLE_SORT);
chooser->setItemData(index, (type == GXS_ID_DETAILS_TYPE_DONE) ? TYPE_FOUND_ID : TYPE_UNKNOWN_ID, ROLE_TYPE);
chooser->model()->sort(0);
}
void GxsIdChooser::loadPrivateIds(uint32_t token)
{
if (mFirstLoad) { clear();}
if (mFirstLoad) {
clear();
}
std::list<RsGxsId> ids;
//rsIdentity->getOwnIds(ids);
@ -156,8 +148,7 @@ void GxsIdChooser::loadPrivateIds(uint32_t token)
return;
}
for (std::vector<RsGxsIdGroup>::iterator vit = datavector.begin();
vit != datavector.end(); ++vit) {
for (std::vector<RsGxsIdGroup>::iterator vit = datavector.begin(); vit != datavector.end(); ++vit) {
RsGxsIdGroup data = (*vit);
if (data.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN) {
ids.push_back((RsGxsId) data.mMeta.mGroupId);
@ -178,20 +169,28 @@ void GxsIdChooser::loadPrivateIds(uint32_t token)
QString id = "";
addItem(str, id);
setItemData(count() - 1, QString("0_%2").arg(str), ROLE_SORT);
setItemData(count() - 1, QString("%1_%2").arg(TYPE_NO_ID).arg(str), ROLE_SORT);
setItemData(count() - 1, TYPE_NO_ID, ROLE_TYPE);
}
}
if (!(mFlags & IDCHOOSER_NO_CREATE)) {
/* add Create Identity option */
QString str = tr("Create new Identity");
QString id = "";
if (!mFirstLoad) {
addItem(str, id);
setItemData(count() - 1, QString("%1_%2").arg(TYPE_CREATE_ID).arg(str), ROLE_SORT);
setItemData(count() - 1, TYPE_CREATE_ID, ROLE_TYPE);
}
} else {
for (int idx = 0; idx < count(); ++idx) {
QVariant type = itemData(idx, ROLE_TYPE);
switch (type.toInt()) {
case TYPE_NO_ID:
case TYPE_CREATE_ID:
break;
case TYPE_FOUND_ID:
case TYPE_UNKNOWN_ID:
default: {
{
QVariant var = itemData(idx);
RsGxsId gxsId = RsGxsId(var.toString().toStdString());
std::list<RsGxsId>::iterator lit = std::find(ids.begin(), ids.end(), gxsId);
@ -204,10 +203,11 @@ void GxsIdChooser::loadPrivateIds(uint32_t token)
}
}
mFirstLoad = false;
if (ids.empty()) {
std::cerr << "GxsIdChooser::loadPrivateIds() ERROR no ids";
std::cerr << std::endl;
mFirstLoad = false;
return;
}
@ -217,8 +217,6 @@ void GxsIdChooser::loadPrivateIds(uint32_t token)
}
setDefaultItem();
mFirstLoad=false;
}
void GxsIdChooser::setDefaultItem()
@ -235,7 +233,6 @@ void GxsIdChooser::setDefaultItem()
if (def >= 0) {
setCurrentIndex(def);
}
}
bool GxsIdChooser::setChosenId(RsGxsId &gxsId)
@ -269,6 +266,8 @@ GxsIdChooser::ChosenId_Ret GxsIdChooser::getChosenId(RsGxsId &gxsId)
return KnowId;
case TYPE_UNKNOWN_ID:
return UnKnowId;
case TYPE_CREATE_ID:
break;
}
return None;
@ -276,7 +275,8 @@ GxsIdChooser::ChosenId_Ret GxsIdChooser::getChosenId(RsGxsId &gxsId)
void GxsIdChooser::myCurrentIndexChanged(int index)
{
Q_UNUSED(index)
Q_UNUSED(index);
QFontMetrics fm = QFontMetrics(font());
QString text = currentText();
if (width() < fm.boundingRect(text).width()) {
@ -286,16 +286,30 @@ void GxsIdChooser::myCurrentIndexChanged(int index)
}
}
void GxsIdChooser::indexActivated(int index)
{
int type = itemData(index, ROLE_TYPE).toInt();
if (type == TYPE_CREATE_ID) {
IdEditDialog dlg(this);
dlg.setupNewId(false);
dlg.exec();
// ui.idChooser->setDefaultId(dlg.getLastIdName());
}
}
void GxsIdChooser::updateDisplay(bool complete)
{
Q_UNUSED(complete)
/* Update identity list */
requestIdList();
}
void GxsIdChooser::requestIdList()
{
if (!mIdQueue) return;
if (!mIdQueue) {
return;
}
mIdQueue->cancelActiveRequestTokens(IDCHOOSER_REFRESH);
@ -310,12 +324,15 @@ void GxsIdChooser::requestIdList()
void GxsIdChooser::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
Q_UNUSED(queue)
#ifdef IDCHOOSER_DEBUG
std::cerr << "IdDialog::loadRequest() UserType: " << req.mUserType;
std::cerr << std::endl;
#endif
switch(req.mUserType) {
case IDCHOOSER_REFRESH:
insertIdList(req.mToken);
loadPrivateIds(req.mToken);
break;
default:
std::cerr << "IdDialog::loadRequest() ERROR";
@ -323,8 +340,3 @@ void GxsIdChooser::loadRequest(const TokenQueue *queue, const TokenRequest &req)
break;
}
}
void GxsIdChooser::insertIdList(uint32_t token)
{
loadPrivateIds(token);
}

View File

@ -21,7 +21,6 @@
*
*/
#ifndef _GXS_ID_CHOOSER_H
#define _GXS_ID_CHOOSER_H
@ -40,6 +39,7 @@ class RsGxsUpdateBroadcastBase;
#define IDCHOOSER_ID_REQUIRED 0x0001
#define IDCHOOSER_ANON_DEFAULT 0x0002
#define IDCHOOSER_NO_CREATE 0x0004
class GxsIdChooser : public QComboBox, public TokenResponse
{
@ -52,10 +52,6 @@ public:
void setFlags(uint32_t flags) ;
void setUpdateWhenInvisible(bool update);
const std::list<RsGxsGroupId> &getGrpIds();
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &getMsgIds();
void loadRequest(const TokenQueue *queue, const TokenRequest &req);//TokenResponse
enum ChosenId_Ret {None, KnowId, UnKnowId, NoId} ;
@ -68,16 +64,16 @@ public:
protected:
virtual void showEvent(QShowEvent *event);
virtual void updateDisplay(bool complete);
void updateDisplay(bool complete);
private slots:
void fillDisplay(bool complete);
void myCurrentIndexChanged(int index);
void indexActivated(int index);
private:
void requestIdList() ;
void loadPrivateIds(uint32_t token);
void insertIdList(uint32_t token);
void setDefaultItem();
uint32_t mFlags;
@ -91,4 +87,3 @@ private:
};
#endif