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 "GxsIdChooser.h"
#include "GxsIdDetails.h" #include "GxsIdDetails.h"
#include "RsGxsUpdateBroadcastBase.h" #include "RsGxsUpdateBroadcastBase.h"
#include "gui/Identity/IdDialog.h"
#include <QTimer>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <algorithm> #include <algorithm>
@ -33,26 +33,28 @@
#include <iostream> #include <iostream>
#define MAX_TRY 10 // 5 seconds
#define ROLE_SORT Qt::UserRole + 1 // Qt::UserRole is reserved for data #define ROLE_SORT Qt::UserRole + 1 // Qt::UserRole is reserved for data
#define ROLE_TYPE Qt::UserRole + 2 // #define ROLE_TYPE Qt::UserRole + 2 //
/* Used for sorting too */
#define TYPE_NO_ID 1 #define TYPE_NO_ID 1
#define TYPE_FOUND_ID 2 #define TYPE_FOUND_ID 2
#define TYPE_UNKNOWN_ID 3 #define TYPE_UNKNOWN_ID 3
#define TYPE_CREATE_ID 4
#define IDCHOOSER_REFRESH 1 #define IDCHOOSER_REFRESH 1
//#define IDCHOOSER_DEBUG
/** Constructor */ /** Constructor */
GxsIdChooser::GxsIdChooser(QWidget *parent) GxsIdChooser::GxsIdChooser(QWidget *parent)
: QComboBox(parent), mFlags(IDCHOOSER_ANON_DEFAULT) : QComboBox(parent), mFlags(IDCHOOSER_ANON_DEFAULT)
{ {
mBase = new RsGxsUpdateBroadcastBase(rsIdentity, this); mBase = new RsGxsUpdateBroadcastBase(rsIdentity, this);
connect(mBase, SIGNAL(fillDisplay(bool)), this, SLOT(fillDisplay(bool))); connect(mBase, SIGNAL(fillDisplay(bool)), this, SLOT(fillDisplay(bool)));
mIdQueue = NULL; mIdQueue = NULL;
mFirstLoad=true; mFirstLoad = true;
mDefaultId.clear() ; mDefaultId.clear() ;
mDefaultIdName.clear(); mDefaultIdName.clear();
@ -64,16 +66,20 @@ GxsIdChooser::GxsIdChooser(QWidget *parent)
setModel(proxy); setModel(proxy);
proxy->setSortRole(ROLE_SORT); proxy->setSortRole(ROLE_SORT);
connect(this, SIGNAL(currentIndexChanged(int)),this,SLOT(myCurrentIndexChanged(int)));
/* 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); mIdQueue = new TokenQueue(rsIdentity->getTokenService(), this);
} }
void GxsIdChooser::setFlags(uint32_t flags) void GxsIdChooser::setFlags(uint32_t flags)
{ {
mFlags = flags ; mFlags = flags ;
updateDisplay(true); updateDisplay(true);
} }
GxsIdChooser::~GxsIdChooser() GxsIdChooser::~GxsIdChooser()
{ {
if (mIdQueue) { 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) void GxsIdChooser::fillDisplay(bool complete)
{ {
updateDisplay(complete); updateDisplay(complete);
@ -109,7 +100,6 @@ void GxsIdChooser::showEvent(QShowEvent *event)
QComboBox::showEvent(event); QComboBox::showEvent(event);
} }
void GxsIdChooser::loadIds(uint32_t chooserFlags, RsGxsId defId) void GxsIdChooser::loadIds(uint32_t chooserFlags, RsGxsId defId)
{ {
mFlags = chooserFlags; mFlags = chooserFlags;
@ -138,14 +128,16 @@ static void loadPrivateIdsCallback(GxsIdDetailsType type, const RsIdentityDetail
index = chooser->count() - 1; 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->setItemData(index, (type == GXS_ID_DETAILS_TYPE_DONE) ? TYPE_FOUND_ID : TYPE_UNKNOWN_ID, ROLE_TYPE);
chooser->model()->sort(0); chooser->model()->sort(0);
} }
void GxsIdChooser::loadPrivateIds(uint32_t token) void GxsIdChooser::loadPrivateIds(uint32_t token)
{ {
if (mFirstLoad) { clear();} if (mFirstLoad) {
clear();
}
std::list<RsGxsId> ids; std::list<RsGxsId> ids;
//rsIdentity->getOwnIds(ids); //rsIdentity->getOwnIds(ids);
@ -154,71 +146,77 @@ void GxsIdChooser::loadPrivateIds(uint32_t token)
std::cerr << "GxsIdChooser::loadPrivateIds() Error getting GroupData"; std::cerr << "GxsIdChooser::loadPrivateIds() Error getting GroupData";
std::cerr << std::endl; std::cerr << std::endl;
return; return;
} }
for (std::vector<RsGxsIdGroup>::iterator vit = datavector.begin(); for (std::vector<RsGxsIdGroup>::iterator vit = datavector.begin(); vit != datavector.end(); ++vit) {
vit != datavector.end(); ++vit) {
RsGxsIdGroup data = (*vit); RsGxsIdGroup data = (*vit);
if (data.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN) { if (data.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN) {
ids.push_back((RsGxsId) data.mMeta.mGroupId); ids.push_back((RsGxsId) data.mMeta.mGroupId);
} }
if (mDefaultIdName == data.mMeta.mGroupName) { if (mDefaultIdName == data.mMeta.mGroupName) {
mDefaultId=(RsGxsId) data.mMeta.mGroupId; mDefaultId = (RsGxsId) data.mMeta.mGroupId;
} }
} }
//rsIdentity->getDefaultId(defId); //rsIdentity->getDefaultId(defId);
// Prefer to use an application specific default??? // Prefer to use an application specific default???
if (mFirstLoad) { if (mFirstLoad) {
if (!(mFlags & IDCHOOSER_ID_REQUIRED)) { if (!(mFlags & IDCHOOSER_ID_REQUIRED)) {
/* add No Signature option */ /* add No Signature option */
QString str = tr("No Signature"); QString str = tr("No Signature");
QString id = ""; QString id = "";
addItem(str, 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); 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);
for (int idx=0; idx < count(); ++idx) { setItemData(count() - 1, QString("%1_%2").arg(TYPE_CREATE_ID).arg(str), ROLE_SORT);
QVariant type = itemData(idx,ROLE_TYPE); 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()) { switch (type.toInt()) {
case TYPE_NO_ID: case TYPE_NO_ID:
case TYPE_CREATE_ID:
break; break;
case TYPE_FOUND_ID: case TYPE_FOUND_ID:
case TYPE_UNKNOWN_ID: case TYPE_UNKNOWN_ID:
default: { {
QVariant var = itemData(idx); QVariant var = itemData(idx);
RsGxsId gxsId = RsGxsId(var.toString().toStdString()); RsGxsId gxsId = RsGxsId(var.toString().toStdString());
std::list<RsGxsId>::iterator lit = std::find( ids.begin(), ids.end(), gxsId); std::list<RsGxsId>::iterator lit = std::find(ids.begin(), ids.end(), gxsId);
if (lit == ids.end()) { if (lit == ids.end()) {
removeItem(idx); removeItem(idx);
idx--; idx--;
} }
} }
} }
} }
} }
mFirstLoad = false;
if (ids.empty()) { if (ids.empty()) {
std::cerr << "GxsIdChooser::loadPrivateIds() ERROR no ids"; std::cerr << "GxsIdChooser::loadPrivateIds() ERROR no ids";
std::cerr << std::endl; std::cerr << std::endl;
mFirstLoad = false;
return; return;
} }
for(std::list<RsGxsId>::iterator it = ids.begin(); it != ids.end(); ++it) { for (std::list<RsGxsId>::iterator it = ids.begin(); it != ids.end(); ++it) {
/* add to Chooser */ /* add to Chooser */
GxsIdDetails::process(*it, loadPrivateIdsCallback, this); GxsIdDetails::process(*it, loadPrivateIdsCallback, this);
} }
setDefaultItem(); setDefaultItem();
mFirstLoad=false;
} }
void GxsIdChooser::setDefaultItem() void GxsIdChooser::setDefaultItem()
@ -230,16 +228,15 @@ void GxsIdChooser::setDefaultItem()
} else { } else {
QString id = QString::fromStdString(mDefaultId.toStdString()); QString id = QString::fromStdString(mDefaultId.toStdString());
def = findData(id); def = findData(id);
} }
if (def >= 0) { if (def >= 0) {
setCurrentIndex(def); setCurrentIndex(def);
} }
} }
bool GxsIdChooser::setChosenId(RsGxsId &gxsId) bool GxsIdChooser::setChosenId(RsGxsId &gxsId)
{ {
QString id = QString::fromStdString(gxsId.toStdString()); QString id = QString::fromStdString(gxsId.toStdString());
/* Find text of exisiting item */ /* Find text of exisiting item */
@ -247,55 +244,72 @@ bool GxsIdChooser::setChosenId(RsGxsId &gxsId)
if (index >= 0) { if (index >= 0) {
setCurrentIndex(index); setCurrentIndex(index);
return true; return true;
}
return false;
} }
return false;
}
GxsIdChooser::ChosenId_Ret GxsIdChooser::getChosenId(RsGxsId &gxsId) GxsIdChooser::ChosenId_Ret GxsIdChooser::getChosenId(RsGxsId &gxsId)
{ {
if (count() < 1) { if (count() < 1) {
return None; return None;
} }
int idx = currentIndex(); int idx = currentIndex();
QVariant var = itemData(idx); QVariant var = itemData(idx);
gxsId = RsGxsId(var.toString().toStdString()); gxsId = RsGxsId(var.toString().toStdString());
QVariant type = itemData(idx,ROLE_TYPE); QVariant type = itemData(idx, ROLE_TYPE);
switch (type.toInt()) { switch (type.toInt()) {
case TYPE_NO_ID: case TYPE_NO_ID:
return NoId; return NoId;
case TYPE_FOUND_ID: case TYPE_FOUND_ID:
return KnowId; return KnowId;
case TYPE_UNKNOWN_ID: case TYPE_UNKNOWN_ID:
return UnKnowId; return UnKnowId;
} case TYPE_CREATE_ID:
break;
}
return None; return None;
} }
void GxsIdChooser::myCurrentIndexChanged(int index) void GxsIdChooser::myCurrentIndexChanged(int index)
{ {
Q_UNUSED(index) Q_UNUSED(index);
QFontMetrics fm = QFontMetrics(font()); QFontMetrics fm = QFontMetrics(font());
QString text = currentText(); QString text = currentText();
if (width()<fm.boundingRect(text).width()) { if (width() < fm.boundingRect(text).width()) {
setToolTip(text); setToolTip(text);
} else { } else {
setToolTip(""); setToolTip("");
} }
}
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) void GxsIdChooser::updateDisplay(bool complete)
{ {
Q_UNUSED(complete) Q_UNUSED(complete)
/* Update identity list */ /* Update identity list */
requestIdList(); requestIdList();
} }
void GxsIdChooser::requestIdList() void GxsIdChooser::requestIdList()
{ {
if (!mIdQueue) return; if (!mIdQueue) {
return;
}
mIdQueue->cancelActiveRequestTokens(IDCHOOSER_REFRESH); mIdQueue->cancelActiveRequestTokens(IDCHOOSER_REFRESH);
@ -310,21 +324,19 @@ void GxsIdChooser::requestIdList()
void GxsIdChooser::loadRequest(const TokenQueue *queue, const TokenRequest &req) void GxsIdChooser::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{ {
Q_UNUSED(queue) Q_UNUSED(queue)
#ifdef IDCHOOSER_DEBUG
std::cerr << "IdDialog::loadRequest() UserType: " << req.mUserType; std::cerr << "IdDialog::loadRequest() UserType: " << req.mUserType;
std::cerr << std::endl; std::cerr << std::endl;
#endif
switch(req.mUserType) { switch(req.mUserType) {
case IDCHOOSER_REFRESH: case IDCHOOSER_REFRESH:
insertIdList(req.mToken); loadPrivateIds(req.mToken);
break; break;
default: default:
std::cerr << "IdDialog::loadRequest() ERROR"; std::cerr << "IdDialog::loadRequest() ERROR";
std::cerr << std::endl; std::cerr << std::endl;
break; break;
} }
}
void GxsIdChooser::insertIdList(uint32_t token)
{
loadPrivateIds(token);
} }

View File

@ -21,7 +21,6 @@
* *
*/ */
#ifndef _GXS_ID_CHOOSER_H #ifndef _GXS_ID_CHOOSER_H
#define _GXS_ID_CHOOSER_H #define _GXS_ID_CHOOSER_H
@ -38,23 +37,20 @@
class RsGxsIfaceHelper; class RsGxsIfaceHelper;
class RsGxsUpdateBroadcastBase; class RsGxsUpdateBroadcastBase;
#define IDCHOOSER_ID_REQUIRED 0x0001 #define IDCHOOSER_ID_REQUIRED 0x0001
#define IDCHOOSER_ANON_DEFAULT 0x0002 #define IDCHOOSER_ANON_DEFAULT 0x0002
#define IDCHOOSER_NO_CREATE 0x0004
class GxsIdChooser : public QComboBox, public TokenResponse class GxsIdChooser : public QComboBox, public TokenResponse
{ {
Q_OBJECT Q_OBJECT
public: public:
GxsIdChooser(RsGxsIfaceHelper* ifaceImpl, QWidget *parent = NULL); GxsIdChooser(RsGxsIfaceHelper* ifaceImpl, QWidget *parent = NULL);
GxsIdChooser(QWidget *parent = NULL); GxsIdChooser(QWidget *parent = NULL);
virtual ~GxsIdChooser(); virtual ~GxsIdChooser();
void setFlags(uint32_t flags) ; 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 void loadRequest(const TokenQueue *queue, const TokenRequest &req);//TokenResponse
@ -68,16 +64,16 @@ public:
protected: protected:
virtual void showEvent(QShowEvent *event); virtual void showEvent(QShowEvent *event);
virtual void updateDisplay(bool complete); void updateDisplay(bool complete);
private slots: private slots:
void fillDisplay(bool complete); void fillDisplay(bool complete);
void myCurrentIndexChanged(int index); void myCurrentIndexChanged(int index);
void indexActivated(int index);
private: private:
void requestIdList() ; void requestIdList() ;
void loadPrivateIds(uint32_t token); void loadPrivateIds(uint32_t token);
void insertIdList(uint32_t token);
void setDefaultItem(); void setDefaultItem();
uint32_t mFlags; uint32_t mFlags;
@ -91,4 +87,3 @@ private:
}; };
#endif #endif