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,7 +634,7 @@ 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,6 +711,9 @@ 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) ;
} }
@ -693,9 +723,26 @@ void IdDialog::CircleListCustomPopupMenu( QPoint )
QTreeWidgetItem *item = ui->treeWidget_membership->currentItem(); QTreeWidgetItem *item = ui->treeWidget_membership->currentItem();
if (item) if(!item)
return ;
RsGxsId current_gxs_id ;
RsGxsCircleId circle_id ;
RsGxsId item_id(item->text(CIRCLEGROUP_CIRCLE_COL_GROUPID).toStdString());
bool is_circle ;
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,21 +751,26 @@ 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;
is_circle = true ;
contextMnu.addSeparator() ; contextMnu.addSeparator() ;
}
RsGxsCircleId circle_id(item->data(CIRCLEGROUP_CIRCLE_COL_GROUPID, Qt::UserRole).toString().toStdString());
RsGxsCircleDetails details ; RsGxsCircleDetails details ;
rsGxsCircles->getCircleDetails(circle_id,details) ;
static const int REQUES = 0 ; // Admin list: no Subscribed: no if(!rsGxsCircles->getCircleDetails(circle_id,details))// grab real circle ID from parent. Make sure circle id is used correctly afterwards!
static const int ACCEPT = 1 ; // Admin list: yes Subscribed: no {
static const int REMOVE = 2 ; // Admin list: yes Subscribed: yes std::cerr << " (EE) cannot get circle info for ID " << circle_id << ". Not in cache?" << std::endl;
static const int CANCEL = 3 ; // Admin list: no Subscribed: yes return ;
}
const QString menu_titles[4] = { tr("Accept circle invitation"), tr("Remove from this circle"),tr("Cancel subscribe request"), tr("Request subscription") } ; 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) ;
@ -726,7 +778,14 @@ void IdDialog::CircleListCustomPopupMenu( QPoint )
std::list<RsGxsId> own_identities ; std::list<RsGxsId> own_identities ;
rsIdentity->getOwnIds(own_identities) ; rsIdentity->getOwnIds(own_identities) ;
// policy is:
// - if on a circle item
// => add possible subscription requests for all ids
// - if on a Id item
// => only add subscription requests for that ID
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)
if(is_circle || current_gxs_id == *it)
{ {
std::map<RsGxsId,uint32_t>::const_iterator vit = details.mSubscriptionFlags.find(*it) ; std::map<RsGxsId,uint32_t>::const_iterator vit = details.mSubscriptionFlags.find(*it) ;
uint32_t subscribe_flags = (vit == details.mSubscriptionFlags.end())?0:(vit->second) ; uint32_t subscribe_flags = (vit == details.mSubscriptionFlags.end())?0:(vit->second) ;
@ -755,7 +814,12 @@ void IdDialog::CircleListCustomPopupMenu( QPoint )
else else
id_name = tr("for identity ")+QString::fromStdString(ids[i][0].toStdString()) ; 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) ; QAction *action ;
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) if(i <2)
QObject::connect(action,SIGNAL(triggered()), this, SLOT(acceptCircleSubscription())); QObject::connect(action,SIGNAL(triggered()), this, SLOT(acceptCircleSubscription()));
@ -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) ;