Modified the Id Gui to use new async call interface.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5200 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-06-07 17:11:57 +00:00
parent d29f158a66
commit bf4c250e51
4 changed files with 211 additions and 368 deletions

View File

@ -46,6 +46,11 @@
#define RSID_REQ_IDLIST 1
#define RSID_REQ_IDDETAILS 2
#define RSID_REQ_IDLISTDATA 3
#define RSID_REQ_IDEDIT 4
/** Constructor */ /** Constructor */
IdDialog::IdDialog(QWidget *parent) IdDialog::IdDialog(QWidget *parent)
: MainPage(parent) : MainPage(parent)
@ -71,14 +76,14 @@ IdDialog::IdDialog(QWidget *parent)
timer->start(1000); timer->start(1000);
rsIdentity->generateDummyData(); rsIdentity->generateDummyData();
mWaitingForRequest = false;
} }
void IdDialog::ListTypeToggled(bool checked) void IdDialog::ListTypeToggled(bool checked)
{ {
if (checked) if (checked)
{ {
insertIdList(); requestIdList();
} }
} }
@ -91,116 +96,103 @@ void IdDialog::updateSelection()
if (!item) if (!item)
{ {
/* blank it all - and fix buttons */ blankSelection();
ui.lineEdit_Nickname->setText("");
ui.lineEdit_KeyId->setText("");
ui.lineEdit_GpgHash->setText("");
ui.lineEdit_GpgId->setText("");
ui.lineEdit_GpgName->setText("");
ui.lineEdit_GpgEmail->setText("");
ui.pushButton_Reputation->setEnabled(false);
ui.pushButton_Delete->setEnabled(false);
ui.pushButton_EditId->setEnabled(false);
ui.pushButton_NewId->setEnabled(true);
} }
else else
{ {
/* get details from libretroshare */ std::string id = item->text(RSID_COL_KEYID).toStdString();
RsIdData data; requestIdDetails(id);
if (!rsIdentity->getIdentity(item->text(RSID_COL_KEYID).toStdString(), data))
{
ui.lineEdit_KeyId->setText("ERROR GETTING KEY!");
return;
}
/* get GPG Details from rsPeers */
std::string gpgid = rsPeers->getGPGOwnId();
RsPeerDetails details;
rsPeers->getPeerDetails(gpgid, details);
ui.lineEdit_Nickname->setText(QString::fromStdString(data.mNickname));
ui.lineEdit_KeyId->setText(QString::fromStdString(data.mKeyId));
ui.lineEdit_GpgHash->setText(QString::fromStdString(data.mGpgIdHash));
ui.lineEdit_GpgId->setText(QString::fromStdString(data.mGpgId));
ui.lineEdit_GpgName->setText(QString::fromStdString(data.mGpgName));
ui.lineEdit_GpgEmail->setText(QString::fromStdString(data.mGpgEmail));
if (data.mIdType & RSID_RELATION_YOURSELF)
{
ui.radioButton_IdYourself->setChecked(true);
}
else if (data.mIdType & RSID_TYPE_PSEUDONYM)
{
ui.radioButton_IdPseudo->setChecked(true);
}
else if (data.mIdType & RSID_RELATION_FRIEND)
{
ui.radioButton_IdFriend->setChecked(true);
}
else if (data.mIdType & RSID_RELATION_FOF)
{
ui.radioButton_IdFOF->setChecked(true);
}
else
{
ui.radioButton_IdOther->setChecked(true);
}
ui.pushButton_NewId->setEnabled(true);
if (data.mIdType & RSID_RELATION_YOURSELF)
{
ui.pushButton_Reputation->setEnabled(false);
ui.pushButton_Delete->setEnabled(true);
ui.pushButton_EditId->setEnabled(true);
}
else
{
ui.pushButton_Reputation->setEnabled(true);
ui.pushButton_Delete->setEnabled(false);
ui.pushButton_EditId->setEnabled(false);
}
} }
} }
#if 0
void IdDialog::notifySelection(PulseItem *item, int ptype) void IdDialog::blankSelection()
{ {
std::cerr << "IdDialog::notifySelection() from : " << ptype << " " << item; /* blank it all - and fix buttons */
std::cerr << std::endl; ui.lineEdit_Nickname->setText("");
ui.lineEdit_KeyId->setText("");
ui.lineEdit_GpgHash->setText("");
ui.lineEdit_GpgId->setText("");
ui.lineEdit_GpgName->setText("");
ui.lineEdit_GpgEmail->setText("");
notifyPulseSelection(item); ui.pushButton_Reputation->setEnabled(false);
ui.pushButton_Delete->setEnabled(false);
switch(ptype) ui.pushButton_EditId->setEnabled(false);
{ ui.pushButton_NewId->setEnabled(true);
default:
case PHOTO_ITEM_TYPE_ALBUM:
notifyAlbumSelection(item);
break;
case PHOTO_ITEM_TYPE_PHOTO:
notifyPhotoSelection(item);
break;
}
} }
void IdDialog::notifyPulseSelection(PulseItem *item)
void IdDialog::requestIdDetails(std::string &id)
{ {
std::cerr << "IdDialog::notifyPulseSelection() from : " << item; uint32_t token;
std::cerr << std::endl;
std::list<std::string> ids;
if (mPulseSelected) ids.push_back(id);
{
std::cerr << "IdDialog::notifyPulseSelection() unselecting old one : " << mPulseSelected; rsIdentity->requestIdentities(token, ids);
std::cerr << std::endl; lockForRequest(token, RSID_REQ_IDDETAILS);
mPulseSelected->setSelected(false);
}
mPulseSelected = item;
} }
#endif
void IdDialog::insertIdDetails(uint32_t token)
{
/* get details from libretroshare */
RsIdData data;
if (!rsIdentity->getIdentity(token, data))
{
ui.lineEdit_KeyId->setText("ERROR GETTING KEY!");
return;
}
/* get GPG Details from rsPeers */
std::string gpgid = rsPeers->getGPGOwnId();
RsPeerDetails details;
rsPeers->getPeerDetails(gpgid, details);
ui.lineEdit_Nickname->setText(QString::fromStdString(data.mNickname));
ui.lineEdit_KeyId->setText(QString::fromStdString(data.mKeyId));
ui.lineEdit_GpgHash->setText(QString::fromStdString(data.mGpgIdHash));
ui.lineEdit_GpgId->setText(QString::fromStdString(data.mGpgId));
ui.lineEdit_GpgName->setText(QString::fromStdString(data.mGpgName));
ui.lineEdit_GpgEmail->setText(QString::fromStdString(data.mGpgEmail));
if (data.mIdType & RSID_RELATION_YOURSELF)
{
ui.radioButton_IdYourself->setChecked(true);
}
else if (data.mIdType & RSID_TYPE_PSEUDONYM)
{
ui.radioButton_IdPseudo->setChecked(true);
}
else if (data.mIdType & RSID_RELATION_FRIEND)
{
ui.radioButton_IdFriend->setChecked(true);
}
else if (data.mIdType & RSID_RELATION_FOF)
{
ui.radioButton_IdFOF->setChecked(true);
}
else
{
ui.radioButton_IdOther->setChecked(true);
}
ui.pushButton_NewId->setEnabled(true);
if (data.mIdType & RSID_RELATION_YOURSELF)
{
ui.pushButton_Reputation->setEnabled(false);
ui.pushButton_Delete->setEnabled(true);
ui.pushButton_EditId->setEnabled(true);
}
else
{
ui.pushButton_Reputation->setEnabled(true);
ui.pushButton_Delete->setEnabled(false);
ui.pushButton_EditId->setEnabled(false);
}
}
void IdDialog::checkUpdate() void IdDialog::checkUpdate()
{ {
@ -208,16 +200,16 @@ void IdDialog::checkUpdate()
if (!rsIdentity) if (!rsIdentity)
return; return;
checkForRequest();
if (rsIdentity->updated()) if (rsIdentity->updated())
{ {
insertIdList(); requestIdList();
} }
return; return;
} }
/*************** New Photo Dialog ***************/
void IdDialog::OpenOrShowAddDialog() void IdDialog::OpenOrShowAddDialog()
{ {
if (!mEditDialog) if (!mEditDialog)
@ -251,97 +243,58 @@ void IdDialog::OpenOrShowEditDialog()
} }
std::string keyId = item->text(RSID_COL_KEYID).toStdString(); std::string keyId = item->text(RSID_COL_KEYID).toStdString();
mEditDialog->setupExistingId(keyId); requestIdEdit(keyId);
mEditDialog->show();
} }
bool IdDialog::matchesAlbumFilter(const RsPhotoAlbum &album) void IdDialog::requestIdEdit(std::string &id)
{ {
uint32_t token;
return true; std::list<std::string> ids;
} ids.push_back(id);
rsIdentity->requestIdentities(token, ids);
lockForRequest(token, RSID_REQ_IDEDIT);
double IdDialog::AlbumScore(const RsPhotoAlbum &album)
{
return 1;
} }
bool IdDialog::matchesPhotoFilter(const RsPhotoPhoto &photo) void IdDialog::showIdEdit(uint32_t token)
{ {
if (mEditDialog)
{
mEditDialog->setupExistingId(token);
return true; mEditDialog->show();
} }
double IdDialog::PhotoScore(const RsPhotoPhoto &photo)
{
return 1;
} }
bool IdDialog::FilterNSortAlbums(const std::list<std::string> &albumIds, std::list<std::string> &filteredAlbumIds, int count)
void IdDialog::requestIdList()
{ {
#if 0 uint32_t token;
std::multimap<double, std::string> sortedAlbums;
std::multimap<double, std::string>::iterator sit; rsIdentity->requestIdentityList(token);
std::list<std::string>::const_iterator it;
for(it = albumIds.begin(); it != albumIds.end(); it++) lockForRequest(token, RSID_REQ_IDLIST);
{
RsPhotoAlbum album;
rsPhoto->getAlbum(*it, album);
if (matchesAlbumFilter(album))
{
double score = AlbumScore(album);
sortedAlbums.insert(std::make_pair(score, *it));
}
}
int i;
for (sit = sortedAlbums.begin(), i = 0; (sit != sortedAlbums.end()) && (i < count); sit++, i++)
{
filteredAlbumIds.push_back(sit->second);
}
#endif
return true;
} }
bool IdDialog::FilterNSortPhotos(const std::list<std::string> &photoIds, std::list<std::string> &filteredPhotoIds, int count) void IdDialog::requestIdData(std::list<std::string> &ids)
{ {
#if 0 uint32_t token;
std::multimap<double, std::string> sortedPhotos;
std::multimap<double, std::string>::iterator sit;
std::list<std::string>::const_iterator it;
int i = 0; rsIdentity->requestIdentities(token, ids);
for(it = photoIds.begin(); it != photoIds.end(); it++, i++)
{ lockForRequest(token, RSID_REQ_IDLISTDATA);
RsPhotoPhoto photo;
rsPhoto->getPhoto(*it, photo);
if (matchesPhotoFilter(photo))
{
double score = i; //PhotoScore(album);
sortedPhotos.insert(std::make_pair(score, *it));
}
}
for (sit = sortedPhotos.begin(), i = 0; (sit != sortedPhotos.end()) && (i < count); sit++, i++)
{
filteredPhotoIds.push_back(sit->second);
}
#endif
return true;
} }
void IdDialog::insertIdList()
void IdDialog::insertIdList(uint32_t token)
{ {
QTreeWidget *tree = ui.treeWidget_IdList; QTreeWidget *tree = ui.treeWidget_IdList;
@ -356,15 +309,13 @@ void IdDialog::insertIdList()
bool acceptFriends = ui.radioButton_ListFriends->isChecked(); bool acceptFriends = ui.radioButton_ListFriends->isChecked();
bool acceptOthers = ui.radioButton_ListOthers->isChecked(); bool acceptOthers = ui.radioButton_ListOthers->isChecked();
rsIdentity->getIdentityList(ids); //rsIdentity->getIdentityList(ids);
for(it = ids.begin(); it != ids.end(); it++) //for(it = ids.begin(); it != ids.end(); it++)
//{
RsIdData data;
while(rsIdentity->getIdentity(token, data))
{ {
RsIdData data;
if (!rsIdentity->getIdentity(*it, data))
{
continue;
}
/* do filtering */ /* do filtering */
bool ok = false; bool ok = false;
@ -430,202 +381,99 @@ void IdDialog::insertIdList()
void IdDialog::lockForRequest(uint32_t token, uint32_t reqtype)
void IdDialog::insertPhotosForSelectedAlbum()
{ {
#if 0
std::cerr << "IdDialog::insertPhotosForSelectedAlbum()"; /* store token for later results retrival */
if (mWaitingForRequest)
{
std::cerr << "IdDialog::lockForRequest() LOCKED ALREADY - BIG ERROR";
std::cerr << std::endl;
}
mWaitingForRequest = true;
mRequestToken = token;
mRequestType = reqtype;
std::cerr << "IdDialog::lockForRequest() Token: " << token << " ReqType: " << reqtype;
std::cerr << std::endl; std::cerr << std::endl;
clearPhotos(); }
std::list<std::string> albumIds;
if (mAlbumSelected) void IdDialog::checkForRequest()
{
if (mWaitingForRequest)
{ {
albumIds.push_back(mAlbumSelected->mDetails.mAlbumId); /* check token */
if (4 == rsIdentity->requestStatus(mRequestToken))
loadRequest();
}
}
std::cerr << "IdDialog::insertPhotosForSelectedAlbum() AlbumId: " << mAlbumSelected->mDetails.mAlbumId;
void IdDialog::loadRequest()
{
if (!mWaitingForRequest)
{
std::cerr << "IdDialog::loadRequest() NOT LOCKED - BIG ERROR";
std::cerr << std::endl; std::cerr << std::endl;
} }
insertPhotosForAlbum(albumIds); /* unlock gui */
#endif mWaitingForRequest = false;
}
void IdDialog::addAlbum(const std::string &id) switch (mRequestType)
{
#if 0
RsPhotoAlbum album;
rsPhoto->getAlbum(id, album);
RsPhotoThumbnail thumbnail;
rsPhoto->getAlbumThumbnail(id, thumbnail);
std::cerr << " IdDialog::addAlbum() AlbumId: " << album.mAlbumId << std::endl;
PulseItem *item = new PulseItem(this, album, thumbnail);
QLayout *alayout = ui.scrollAreaWidgetContents->layout();
alayout->addWidget(item);
#endif
}
void IdDialog::clearAlbums()
{
#if 0
std::cerr << "IdDialog::clearAlbums()" << std::endl;
std::list<PulseItem *> photoItems;
std::list<PulseItem *>::iterator pit;
QLayout *alayout = ui.scrollAreaWidgetContents->layout();
int count = alayout->count();
for(int i = 0; i < count; i++)
{ {
QLayoutItem *litem = alayout->itemAt(i); case RSID_REQ_IDLIST:
if (!litem)
{ {
std::cerr << "IdDialog::clearAlbums() missing litem"; std::cerr << "IdDialog::loadRequest() RSID_REQ_IDLIST";
std::cerr << std::endl; std::cerr << std::endl;
continue;
}
PulseItem *item = dynamic_cast<PulseItem *>(litem->widget());
if (item)
{
std::cerr << "IdDialog::clearAlbums() item: " << item;
std::cerr << std::endl;
photoItems.push_back(item);
}
else
{
std::cerr << "IdDialog::clearAlbums() Found Child, which is not a PulseItem???";
std::cerr << std::endl;
}
}
for(pit = photoItems.begin(); pit != photoItems.end(); pit++)
{
PulseItem *item = *pit;
alayout->removeWidget(item);
delete item;
}
mAlbumSelected = NULL;
#endif
}
void IdDialog::clearPhotos() std::list<std::string> ids;
{ rsIdentity->getIdentityList(mRequestToken, ids);
#if 0
std::cerr << "IdDialog::clearPhotos()" << std::endl; /* request data - straight away */
std::list<PulseItem *> photoItems; requestIdData(ids);
std::list<PulseItem *>::iterator pit;
QLayout *alayout = ui.scrollAreaWidgetContents_2->layout();
int count = alayout->count();
for(int i = 0; i < count; i++)
{
QLayoutItem *litem = alayout->itemAt(i);
if (!litem)
{
std::cerr << "IdDialog::clearPhotos() missing litem";
std::cerr << std::endl;
continue;
} }
break;
PulseItem *item = dynamic_cast<PulseItem *>(litem->widget());
if (item) case RSID_REQ_IDLISTDATA:
{ {
std::cerr << "IdDialog::clearPhotos() item: " << item; std::cerr << "IdDialog::loadRequest() RSID_REQ_IDLISTDATA";
std::cerr << std::endl; std::cerr << std::endl;
insertIdList(mRequestToken);
photoItems.push_back(item);
} }
else break;
case RSID_REQ_IDDETAILS:
{ {
std::cerr << "IdDialog::clearPhotos() Found Child, which is not a PulseItem???"; std::cerr << "IdDialog::loadRequest() RSID_REQ_IDDETAILS";
std::cerr << std::endl; std::cerr << std::endl;
insertIdDetails(mRequestToken);
} }
break;
case RSID_REQ_IDEDIT:
{
std::cerr << "IdDialog::loadRequest() RSID_REQ_IDEDIT";
std::cerr << std::endl;
showIdEdit(mRequestToken);
}
break;
default:
break;
} }
for(pit = photoItems.begin(); pit != photoItems.end(); pit++)
{
PulseItem *item = *pit;
alayout->removeWidget(item);
delete item;
}
mPhotoSelected = NULL;
#endif
} }
void IdDialog::insertPhotosForAlbum(const std::list<std::string> &albumIds)
{
#if 0
/* clear it all */
clearPhotos();
//ui.photoLayout->clear();
/* create a list of albums */
std::list<std::string> ids;
std::list<std::string> photoIds;
std::list<std::string> filteredPhotoIds;
std::list<std::string>::const_iterator it;
for(it = albumIds.begin(); it != albumIds.end(); it++)
{
rsPhoto->getPhotoList(*it, photoIds);
}
/* Filter Albums */ /* Sort Albums */
#define MAX_PHOTOS 50
int count = MAX_PHOTOS;
FilterNSortPhotos(photoIds, filteredPhotoIds, MAX_PHOTOS);
for(it = filteredPhotoIds.begin(); it != filteredPhotoIds.end(); it++)
{
addPhoto(*it);
}
#endif
}
void IdDialog::addPhoto(const std::string &id)
{
#if 0
RsPhotoPhoto photo;
rsPhoto->getPhoto(id,photo);
RsPhotoThumbnail thumbnail;
rsPhoto->getPhotoThumbnail(id, thumbnail);
std::cerr << "IdDialog::addPhoto() AlbumId: " << photo.mAlbumId;
std::cerr << " PhotoId: " << photo.mId;
std::cerr << std::endl;
PulseItem *item = new PulseItem(this, photo, thumbnail);
QLayout *alayout = ui.scrollAreaWidgetContents_2->layout();
alayout->addWidget(item);
#endif
}
#if 0
void IdDialog::deletePulseItem(PulseItem *item, uint32_t type)
{
return;
}
#endif

View File

@ -53,34 +53,26 @@ private slots:
private: private:
void insertIdList(); void blankSelection();
void requestIdDetails(std::string &id);
void insertIdDetails(uint32_t token);
/* TODO: These functions must be filled in for proper filtering to work void requestIdList();
* and tied to the GUI input void requestIdData(std::list<std::string> &ids);
*/ void insertIdList(uint32_t token);
bool matchesAlbumFilter(const RsPhotoAlbum &album); void requestIdEdit(std::string &id);
double AlbumScore(const RsPhotoAlbum &album); void showIdEdit(uint32_t token);
bool matchesPhotoFilter(const RsPhotoPhoto &photo);
double PhotoScore(const RsPhotoPhoto &photo);
/* Grunt work of setting up the GUI */ void lockForRequest(uint32_t token, uint32_t reqtype);
void checkForRequest();
bool FilterNSortAlbums(const std::list<std::string> &albumIds, std::list<std::string> &filteredAlbumIds, int count); void loadRequest();
bool FilterNSortPhotos(const std::list<std::string> &photoIds, std::list<std::string> &filteredPhotoIds, int count);
void insertAlbums();
void insertPhotosForAlbum(const std::list<std::string> &albumIds);
void insertPhotosForSelectedAlbum();
void addAlbum(const std::string &id);
void addPhoto(const std::string &id);
void clearAlbums();
void clearPhotos();
IdEditDialog *mEditDialog; IdEditDialog *mEditDialog;
//PulseItem *mPulseSelected; bool mWaitingForRequest;
uint32_t mRequestToken;
uint32_t mRequestType;
/* UI - from Designer */ /* UI - from Designer */
Ui::IdDialog ui; Ui::IdDialog ui;

View File

@ -98,16 +98,17 @@ void IdEditDialog::updateIdType(bool pseudo)
} }
void IdEditDialog::setupExistingId(std::string keyId) void IdEditDialog::setupExistingId(uint32_t token)
{ {
ui.checkBox_NewId->setChecked(false); ui.checkBox_NewId->setChecked(false);
ui.checkBox_NewId->setEnabled(false); ui.checkBox_NewId->setEnabled(false);
ui.radioButton_GpgId->setEnabled(false); ui.radioButton_GpgId->setEnabled(false);
ui.radioButton_Pseudo->setEnabled(false); ui.radioButton_Pseudo->setEnabled(false);
RsIdData data; /* get details from libretroshare */
if (!rsIdentity->getIdentity(keyId, data)) RsIdData data;
{ if (!rsIdentity->getIdentity(token, data))
{
ui.lineEdit_KeyId->setText("ERROR KEYID INVALID"); ui.lineEdit_KeyId->setText("ERROR KEYID INVALID");
ui.lineEdit_Nickname->setText(""); ui.lineEdit_Nickname->setText("");

View File

@ -26,6 +26,8 @@
#include "ui_IdEditDialog.h" #include "ui_IdEditDialog.h"
#include <inttypes.h>
class IdEditDialog : public QWidget class IdEditDialog : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -34,7 +36,7 @@ public:
IdEditDialog(QWidget *parent = 0); IdEditDialog(QWidget *parent = 0);
void setupNewId(bool pseudo); void setupNewId(bool pseudo);
void setupExistingId(std::string keyId); void setupExistingId(uint32_t token);
private slots: private slots: