fixed GUI for circle invites

This commit is contained in:
csoler 2016-05-22 18:21:48 -04:00
parent 6554832311
commit 68e618ba4c

View File

@ -50,6 +50,7 @@
/****** /******
* #define ID_DEBUG 1 * #define ID_DEBUG 1
*****/ *****/
#define ID_DEBUG 1
// Data Requests. // Data Requests.
#define IDDIALOG_IDLIST 1 #define IDDIALOG_IDLIST 1
@ -415,7 +416,7 @@ void IdDialog::loadCircleGroupMeta(const uint32_t &token)
QTreeWidgetItem *item = NULL ; QTreeWidgetItem *item = NULL ;
#ifdef ID_DEBUG #ifdef ID_DEBUG
std::cerr << "Loaded info for circle " << vit->mGroupId << ". ubscribed=" << subscribed << ", am_I_in_circle=" << am_I_in_circle << std::endl; std::cerr << "Loaded info for circle " << vit->mGroupId << ". am_I_in_circle=" << am_I_in_circle << std::endl;
#endif #endif
// find already existing items for this circle // find already existing items for this circle
@ -511,23 +512,40 @@ void IdDialog::loadCircleGroupMeta(const uint32_t &token)
// - own GXS id is is admin and subscribed // - own GXS id is is admin and subscribed
// - own GXS id is is subscribed // - own GXS id is is subscribed
#ifdef ID_DEBUG
std::cerr << " updating status of all identities for this circle:" << std::endl;
#endif
for(std::list<RsGxsId>::const_iterator it(own_identities.begin());it!=own_identities.end();++it) for(std::list<RsGxsId>::const_iterator it(own_identities.begin());it!=own_identities.end();++it)
{ {
#ifdef ID_DEBUG
std::cerr << " ID " << *it << ": " ;
#endif
std::map<RsGxsId,uint32_t>::const_iterator it2 = details.mSubscriptionFlags.find(*it) ; std::map<RsGxsId,uint32_t>::const_iterator it2 = details.mSubscriptionFlags.find(*it) ;
if(it2 == details.mSubscriptionFlags.end()) if(it2 == details.mSubscriptionFlags.end())
{
#ifdef ID_DEBUG
std::cerr << "not in subscription list. Skipping." << std::endl;
#endif
continue ; continue ;
}
bool invited ( it2->second & GXS_EXTERNAL_CIRCLE_FLAGS_IN_ADMIN_LIST ); bool invited ( it2->second & GXS_EXTERNAL_CIRCLE_FLAGS_IN_ADMIN_LIST );
bool subscrb ( it2->second & GXS_EXTERNAL_CIRCLE_FLAGS_SUBSCRIBED ); bool subscrb ( it2->second & GXS_EXTERNAL_CIRCLE_FLAGS_SUBSCRIBED );
#ifdef ID_DEBUG
std::cerr << "invited: " << invited << ", subscription: " << subscrb ;
#endif
QTreeWidgetItem *subitem = NULL ; QTreeWidgetItem *subitem = NULL ;
// see if the item already exists // see if the item already exists
for(QTreeWidgetItemIterator itt(item);(*itt);++itt) for(uint32_t k=0;k<item->childCount();++k)
if((*itt)->text(CIRCLEGROUP_CIRCLE_COL_GROUPID).toStdString() == (*it).toStdString()) if(item->child(k)->text(CIRCLEGROUP_CIRCLE_COL_GROUPID).toStdString() == (*it).toStdString())
{ {
subitem = *itt ; subitem = item->child(k);
#ifdef ID_DEBUG
std::cerr << " found existing sub item." << std::endl;
#endif
break ; break ;
} }
@ -535,11 +553,17 @@ void IdDialog::loadCircleGroupMeta(const uint32_t &token)
{ {
if(subitem != NULL) if(subitem != NULL)
delete subitem ; delete subitem ;
#ifdef ID_DEBUG
std::cerr << ". not relevant. Skipping." << std::endl;
#endif
continue ; continue ;
} }
if(!subitem) if(!subitem)
{ {
#ifdef ID_DEBUG
std::cerr << " no existing sub item. Creating new one." << std::endl;
#endif
subitem = new QTreeWidgetItem(item); subitem = new QTreeWidgetItem(item);
RsIdentityDetails idd ; RsIdentityDetails idd ;
@ -610,8 +634,8 @@ void IdDialog::loadCircleGroupData(const uint32_t& token)
if ((!item) || (!item->parent())) if ((!item) || (!item->parent()))
return; return;
QString coltext = item->text(CIRCLEGROUP_CIRCLE_COL_GROUPID); QString coltext = (item->parent()->parent())? (item->parent()->text(CIRCLEGROUP_CIRCLE_COL_GROUPID)) : (item->text(CIRCLEGROUP_CIRCLE_COL_GROUPID));
RsGxsCircleId id ( coltext.toStdString()) ; RsGxsCircleId id( coltext.toStdString()) ;
if(requested_cid != id) if(requested_cid != id)
{ {
@ -669,6 +693,9 @@ void IdDialog::acceptCircleSubscription()
QString coltext = item->text(CIRCLEGROUP_CIRCLE_COL_GROUPID); QString coltext = item->text(CIRCLEGROUP_CIRCLE_COL_GROUPID);
RsGxsCircleId circle_id ( coltext.toStdString()) ; RsGxsCircleId circle_id ( coltext.toStdString()) ;
if(RsGxsId(circle_id) == own_id) // we're on a ID item. The circle is the parent item
circle_id = RsGxsCircleId(item->parent()->text(CIRCLEGROUP_CIRCLE_COL_GROUPID).toStdString()) ;
rsGxsCircles->requestCircleMembership(own_id,circle_id) ; rsGxsCircles->requestCircleMembership(own_id,circle_id) ;
} }
@ -684,18 +711,38 @@ void IdDialog::refuseCircleSubscription()
QString coltext = item->text(CIRCLEGROUP_CIRCLE_COL_GROUPID); QString coltext = item->text(CIRCLEGROUP_CIRCLE_COL_GROUPID);
RsGxsCircleId circle_id ( coltext.toStdString()) ; RsGxsCircleId circle_id ( coltext.toStdString()) ;
if(RsGxsId(circle_id) == own_id) // we're on a ID item. The circle is the parent item
circle_id = RsGxsCircleId(item->parent()->text(CIRCLEGROUP_CIRCLE_COL_GROUPID).toStdString()) ;
rsGxsCircles->cancelCircleMembership(own_id,circle_id) ; rsGxsCircles->cancelCircleMembership(own_id,circle_id) ;
} }
void IdDialog::CircleListCustomPopupMenu( QPoint ) void IdDialog::CircleListCustomPopupMenu( QPoint )
{ {
QMenu contextMnu( this ); QMenu contextMnu( this );
QTreeWidgetItem *item = ui->treeWidget_membership->currentItem(); QTreeWidgetItem *item = ui->treeWidget_membership->currentItem();
if(!item)
return ;
RsGxsId current_gxs_id ;
RsGxsCircleId circle_id ;
RsGxsId item_id(item->text(CIRCLEGROUP_CIRCLE_COL_GROUPID).toStdString());
bool is_circle ;
if (item) if(rsIdentity->isOwnId(item_id))
{
current_gxs_id = RsGxsId(item_id);
circle_id = RsGxsCircleId(item->parent()->text(CIRCLEGROUP_CIRCLE_COL_GROUPID).toStdString());
is_circle =false ;
std::cerr << " Item is a GxsId item. Requesting flags/group id from parent: " << circle_id << std::endl;
}
else // item is for circle
{ {
uint32_t group_flags = item->data(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, Qt::UserRole).toUInt(); uint32_t group_flags = item->data(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, Qt::UserRole).toUInt();
circle_id = RsGxsCircleId(item_id) ;
if(item->parent() != NULL) if(item->parent() != NULL)
{ {
@ -704,95 +751,112 @@ void IdDialog::CircleListCustomPopupMenu( QPoint )
else else
contextMnu.addAction(QIcon(IMAGE_EDIT), tr("See details"), this, SLOT(showEditExistingCircle())); contextMnu.addAction(QIcon(IMAGE_EDIT), tr("See details"), this, SLOT(showEditExistingCircle()));
} }
}
std::cerr << " Item is a circle item. Adding Edit/Details menu entry." << std::endl;
contextMnu.addSeparator() ; is_circle = true ;
RsGxsCircleId circle_id(item->data(CIRCLEGROUP_CIRCLE_COL_GROUPID, Qt::UserRole).toString().toStdString());
RsGxsCircleDetails details ;
rsGxsCircles->getCircleDetails(circle_id,details) ;
static const int REQUES = 0 ; // Admin list: no Subscribed: no contextMnu.addSeparator() ;
static const int ACCEPT = 1 ; // Admin list: yes Subscribed: no }
static const int REMOVE = 2 ; // Admin list: yes Subscribed: yes RsGxsCircleDetails details ;
static const int CANCEL = 3 ; // Admin list: no Subscribed: yes
const QString menu_titles[4] = { tr("Accept circle invitation"), tr("Remove from this circle"),tr("Cancel subscribe request"), tr("Request subscription") } ; if(!rsGxsCircles->getCircleDetails(circle_id,details))// grab real circle ID from parent. Make sure circle id is used correctly afterwards!
{
std::cerr << " (EE) cannot get circle info for ID " << circle_id << ". Not in cache?" << std::endl;
return ;
}
static const int REQUES = 0 ; // Admin list: no Subscription request: no
static const int ACCEPT = 1 ; // Admin list: yes Subscription request: no
static const int REMOVE = 2 ; // Admin list: yes Subscription request: yes
static const int CANCEL = 3 ; // Admin list: no Subscription request: yes
const QString menu_titles[4] = { tr("Request subscription"), tr("Accept circle invitation"), tr("Quit this circle"),tr("Cancel subscribe request")} ;
const QString image_names[4] = { ":/images/edit_16.png",":/images/edit_16.png",":/images/edit_16.png",":/images/edit_16.png" } ; const QString image_names[4] = { ":/images/edit_16.png",":/images/edit_16.png",":/images/edit_16.png",":/images/edit_16.png" } ;
std::vector< std::vector<RsGxsId> > ids(4) ; std::vector< std::vector<RsGxsId> > ids(4) ;
std::list<RsGxsId> own_identities ; std::list<RsGxsId> own_identities ;
rsIdentity->getOwnIds(own_identities) ; rsIdentity->getOwnIds(own_identities) ;
for(std::list<RsGxsId>::const_iterator it(own_identities.begin());it!=own_identities.end();++it)
{
std::map<RsGxsId,uint32_t>::const_iterator vit = details.mSubscriptionFlags.find(*it) ;
uint32_t subscribe_flags = (vit == details.mSubscriptionFlags.end())?0:(vit->second) ;
if(subscribe_flags & GXS_EXTERNAL_CIRCLE_FLAGS_SUBSCRIBED) // policy is:
if(subscribe_flags & GXS_EXTERNAL_CIRCLE_FLAGS_IN_ADMIN_LIST) // - if on a circle item
ids[REMOVE].push_back(*it) ; // => add possible subscription requests for all ids
else // - if on a Id item
ids[CANCEL].push_back(*it) ; // => only add subscription requests for that ID
else
if(subscribe_flags & GXS_EXTERNAL_CIRCLE_FLAGS_IN_ADMIN_LIST) for(std::list<RsGxsId>::const_iterator it(own_identities.begin());it!=own_identities.end();++it)
ids[ACCEPT].push_back(*it) ; if(is_circle || current_gxs_id == *it)
else {
ids[REQUES].push_back(*it) ; std::map<RsGxsId,uint32_t>::const_iterator vit = details.mSubscriptionFlags.find(*it) ;
} uint32_t subscribe_flags = (vit == details.mSubscriptionFlags.end())?0:(vit->second) ;
if(subscribe_flags & GXS_EXTERNAL_CIRCLE_FLAGS_SUBSCRIBED)
if(subscribe_flags & GXS_EXTERNAL_CIRCLE_FLAGS_IN_ADMIN_LIST)
ids[REMOVE].push_back(*it) ;
else
ids[CANCEL].push_back(*it) ;
else
if(subscribe_flags & GXS_EXTERNAL_CIRCLE_FLAGS_IN_ADMIN_LIST)
ids[ACCEPT].push_back(*it) ;
else
ids[REQUES].push_back(*it) ;
}
contextMnu.addSeparator() ; contextMnu.addSeparator() ;
for(int i=0;i<4;++i) for(int i=0;i<4;++i)
{ {
if(ids[i].size() == 1) if(ids[i].size() == 1)
{
RsIdentityDetails det ;
QString id_name ;
if(rsIdentity->getIdDetails(ids[i][0],det))
id_name = tr("for identity ")+QString::fromUtf8(det.mNickname.c_str()) + "(ID=" + QString::fromStdString(ids[i][0].toStdString()) + ")" ;
else
id_name = tr("for identity ")+QString::fromStdString(ids[i][0].toStdString()) ;
QAction *action = new QAction(QIcon(image_names[i]), menu_titles[i] + " " + id_name,this) ;
if(i <2)
QObject::connect(action,SIGNAL(triggered()), this, SLOT(acceptCircleSubscription()));
else
QObject::connect(action,SIGNAL(triggered()), this, SLOT(cancelCircleSubscription()));
action->setData(QString::fromStdString(ids[i][0].toStdString()));
contextMnu.addAction(action) ;
}
else if(ids[i].size() > 1)
{
QMenu *menu = new QMenu(menu_titles[i],this) ;
for(uint32_t j=0;j<ids[i].size();++j)
{ {
RsIdentityDetails det ; RsIdentityDetails det ;
QString id_name ; QString id_name ;
if(rsIdentity->getIdDetails(ids[i][j],det)) if(rsIdentity->getIdDetails(ids[i][0],det))
id_name = tr("for identity ")+QString::fromUtf8(det.mNickname.c_str()) + "(ID=" + QString::fromStdString(ids[i][j].toStdString()) + ")" ; id_name = tr("for identity ")+QString::fromUtf8(det.mNickname.c_str()) + "(ID=" + QString::fromStdString(ids[i][0].toStdString()) + ")" ;
else else
id_name = tr("for identity ")+QString::fromStdString(ids[i][j].toStdString()) ; id_name = tr("for identity ")+QString::fromStdString(ids[i][0].toStdString()) ;
QAction *action = new QAction(QIcon(image_names[i]), id_name,this) ; QAction *action ;
if(i <2) if(is_circle)
action = new QAction(QIcon(image_names[i]), menu_titles[i] + " " + id_name,this) ;
else
action = new QAction(QIcon(image_names[i]), menu_titles[i],this) ;
if(i <2)
QObject::connect(action,SIGNAL(triggered()), this, SLOT(acceptCircleSubscription())); QObject::connect(action,SIGNAL(triggered()), this, SLOT(acceptCircleSubscription()));
else else
QObject::connect(action,SIGNAL(triggered()), this, SLOT(cancelCircleSubscription())); QObject::connect(action,SIGNAL(triggered()), this, SLOT(cancelCircleSubscription()));
action->setData(QString::fromStdString(ids[i][j].toStdString())); action->setData(QString::fromStdString(ids[i][0].toStdString()));
menu->addAction(action) ; contextMnu.addAction(action) ;
}
else if(ids[i].size() > 1)
{
QMenu *menu = new QMenu(menu_titles[i],this) ;
for(uint32_t j=0;j<ids[i].size();++j)
{
RsIdentityDetails det ;
QString id_name ;
if(rsIdentity->getIdDetails(ids[i][j],det))
id_name = tr("for identity ")+QString::fromUtf8(det.mNickname.c_str()) + "(ID=" + QString::fromStdString(ids[i][j].toStdString()) + ")" ;
else
id_name = tr("for identity ")+QString::fromStdString(ids[i][j].toStdString()) ;
QAction *action = new QAction(QIcon(image_names[i]), id_name,this) ;
if(i <2)
QObject::connect(action,SIGNAL(triggered()), this, SLOT(acceptCircleSubscription()));
else
QObject::connect(action,SIGNAL(triggered()), this, SLOT(cancelCircleSubscription()));
action->setData(QString::fromStdString(ids[i][j].toStdString()));
menu->addAction(action) ;
}
contextMnu.addMenu(menu) ;
} }
contextMnu.addMenu(menu) ;
}
} }
contextMnu.exec(QCursor::pos()); contextMnu.exec(QCursor::pos());
} }
@ -894,7 +958,7 @@ void IdDialog::circle_selected()
//set_item_background(item, BLUE_BACKGROUND); //set_item_background(item, BLUE_BACKGROUND);
QString coltext = item->text(CIRCLEGROUP_CIRCLE_COL_GROUPID); QString coltext = (item->parent()->parent())? (item->parent()->text(CIRCLEGROUP_CIRCLE_COL_GROUPID)) : (item->text(CIRCLEGROUP_CIRCLE_COL_GROUPID));
RsGxsCircleId id ( coltext.toStdString()) ; RsGxsCircleId id ( coltext.toStdString()) ;
requestCircleGroupData(id) ; requestCircleGroupData(id) ;