2012-02-13 13:43:15 -05:00
/*
* Retroshare Identity .
*
* Copyright 2012 - 2012 by Robert Fernie .
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Library General Public
* License Version 2.1 as published by the Free Software Foundation .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Library General Public License for more details .
*
* You should have received a copy of the GNU Library General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307
* USA .
*
* Please report all bugs and problems to " retroshare@lunamutt.com " .
*
*/
2013-07-10 17:57:23 -04:00
# include <QMessageBox>
2014-05-03 13:56:12 -04:00
# include <QMenu>
2013-07-10 17:57:23 -04:00
2012-02-13 13:43:15 -05:00
# include "IdDialog.h"
2014-12-24 09:43:06 -05:00
# include "ui_IdDialog.h"
# include "IdEditDialog.h"
2014-09-14 12:28:02 -04:00
# include "gui/gxs/GxsIdDetails.h"
2013-07-10 17:57:23 -04:00
# include "gui/common/UIStateHelper.h"
2014-06-12 06:28:23 -04:00
# include "gui/chat/ChatDialog.h"
2014-12-24 09:43:06 -05:00
# include "gui/settings/rsharesettings.h"
2015-01-23 11:35:06 -05:00
# include "gui/msgs/MessageComposer.h"
2015-09-06 23:53:21 -04:00
# include "gui/Circles/CreateCircleDialog.h"
2015-12-24 08:31:52 -05:00
# include "gui/RetroShareLink.h"
2015-12-22 18:29:27 -05:00
# include "util/QtVersion.h"
2012-02-13 13:43:15 -05:00
# include <retroshare/rspeers.h>
2015-12-22 18:29:27 -05:00
# include <retroshare/rsreputations.h>
2013-02-28 16:58:38 -05:00
# include "retroshare/rsgxsflags.h"
2015-01-23 11:35:06 -05:00
# include "retroshare/rsmsgs.h"
2012-02-13 13:43:15 -05:00
# include <iostream>
2014-12-24 09:43:06 -05:00
# include <algorithm>
2012-02-13 13:43:15 -05:00
/******
* # define ID_DEBUG 1
* * * * */
2012-06-13 20:36:25 -04:00
// Data Requests.
2014-12-24 09:43:06 -05:00
# define IDDIALOG_IDLIST 1
# define IDDIALOG_IDDETAILS 2
# define IDDIALOG_REPLIST 3
# define IDDIALOG_REFRESH 4
2012-02-13 13:43:15 -05:00
2016-03-08 00:02:16 -05:00
# define CIRCLEGROUP_CIRCLE_COL_GROUPNAME 0
# define CIRCLEGROUP_CIRCLE_COL_GROUPID 1
# define CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS 2
2015-09-06 23:53:21 -04:00
# define CIRCLEGROUP_FRIEND_COL_NAME 0
# define CIRCLEGROUP_FRIEND_COL_ID 1
# define CLEAR_BACKGROUND 0
# define GREEN_BACKGROUND 1
# define BLUE_BACKGROUND 2
# define RED_BACKGROUND 3
# define GRAY_BACKGROUND 4
# define CIRCLESDIALOG_GROUPMETA 1
2012-02-13 13:43:15 -05:00
/****************************************************************
*/
2013-07-11 04:14:38 -04:00
# define RSID_COL_NICKNAME 0
# define RSID_COL_KEYID 1
2015-12-22 18:29:27 -05:00
# define RSID_COL_IDTYPE 2
# define RSID_COL_VOTES 3
2012-02-13 13:43:15 -05:00
2013-07-11 04:14:38 -04:00
# define RSIDREP_COL_NAME 0
# define RSIDREP_COL_OPINION 1
# define RSIDREP_COL_COMMENT 2
# define RSIDREP_COL_REPUTATION 3
2012-02-13 13:43:15 -05:00
2015-02-05 15:37:24 -05:00
# define RSID_FILTER_OWNED_BY_YOU 0x0001
2013-07-10 17:57:23 -04:00
# define RSID_FILTER_FRIENDS 0x0002
# define RSID_FILTER_OTHERS 0x0004
# define RSID_FILTER_PSEUDONYMS 0x0008
2015-02-05 15:37:24 -05:00
# define RSID_FILTER_YOURSELF 0x0010
2013-07-10 17:57:23 -04:00
# define RSID_FILTER_ALL 0xffff
2012-06-07 13:11:57 -04:00
2014-05-03 13:56:12 -04:00
# define IMAGE_EDIT ": / images / edit_16.png"
2016-01-16 08:50:12 -05:00
// quick solution for RSID_COL_VOTES sorting
class TreeWidgetItem : public QTreeWidgetItem {
public :
TreeWidgetItem ( int type = Type ) : QTreeWidgetItem ( type ) { }
TreeWidgetItem ( QTreeWidget * tree ) : QTreeWidgetItem ( tree ) { }
TreeWidgetItem ( const QStringList & strings ) : QTreeWidgetItem ( strings ) { }
bool operator < ( const QTreeWidgetItem & other ) const {
int column = treeWidget ( ) - > sortColumn ( ) ;
const QVariant v1 = data ( column , Qt : : DisplayRole ) ;
const QVariant v2 = other . data ( column , Qt : : DisplayRole ) ;
double value1 = v1 . toDouble ( ) ;
double value2 = v2 . toDouble ( ) ;
if ( value1 ! = value2 ) {
return value1 < value2 ;
}
else {
return ( v1 . toString ( ) . compare ( v2 . toString ( ) , Qt : : CaseInsensitive ) < 0 ) ;
}
}
} ;
2012-02-13 13:43:15 -05:00
/** Constructor */
2014-12-24 09:43:06 -05:00
IdDialog : : IdDialog ( QWidget * parent ) :
RsGxsUpdateBroadcastPage ( rsIdentity , parent ) ,
ui ( new Ui : : IdDialog )
2012-02-13 13:43:15 -05:00
{
2014-12-24 09:43:06 -05:00
ui - > setupUi ( this ) ;
2012-02-13 13:43:15 -05:00
2013-07-10 17:57:23 -04:00
mIdQueue = NULL ;
2015-12-22 18:29:27 -05:00
allItem = new QTreeWidgetItem ( ) ;
allItem - > setText ( 0 , tr ( " All " ) ) ;
2015-12-23 12:12:34 -05:00
contactsItem = new QTreeWidgetItem ( ) ;
contactsItem - > setText ( 0 , tr ( " Contacts " ) ) ;
2013-07-10 17:57:23 -04:00
/* Setup UI helper */
mStateHelper = new UIStateHelper ( this ) ;
2015-08-11 10:01:43 -04:00
// mStateHelper->addWidget(IDDIALOG_IDLIST, ui->idTreeWidget);
mStateHelper - > addLoadPlaceholder ( IDDIALOG_IDLIST , ui - > idTreeWidget , false ) ;
mStateHelper - > addClear ( IDDIALOG_IDLIST , ui - > idTreeWidget ) ;
2014-12-24 09:43:06 -05:00
mStateHelper - > addWidget ( IDDIALOG_IDDETAILS , ui - > lineEdit_Nickname ) ;
mStateHelper - > addWidget ( IDDIALOG_IDDETAILS , ui - > lineEdit_KeyId ) ;
// mStateHelper->addWidget(IDDIALOG_IDDETAILS, ui->lineEdit_GpgHash);
mStateHelper - > addWidget ( IDDIALOG_IDDETAILS , ui - > lineEdit_GpgId ) ;
mStateHelper - > addWidget ( IDDIALOG_IDDETAILS , ui - > lineEdit_GpgName ) ;
mStateHelper - > addWidget ( IDDIALOG_IDDETAILS , ui - > lineEdit_Type ) ;
2015-12-22 18:29:27 -05:00
mStateHelper - > addWidget ( IDDIALOG_IDDETAILS , ui - > lineEdit_LastUsed ) ;
mStateHelper - > addWidget ( IDDIALOG_IDDETAILS , ui - > ownOpinion_CB ) ;
mStateHelper - > addWidget ( IDDIALOG_IDDETAILS , ui - > overallOpinion_TF ) ;
mStateHelper - > addWidget ( IDDIALOG_IDDETAILS , ui - > neighborNodesOpinion_TF ) ;
2014-12-24 09:43:06 -05:00
mStateHelper - > addLoadPlaceholder ( IDDIALOG_IDDETAILS , ui - > lineEdit_Nickname ) ;
mStateHelper - > addLoadPlaceholder ( IDDIALOG_IDDETAILS , ui - > lineEdit_GpgName ) ;
mStateHelper - > addLoadPlaceholder ( IDDIALOG_IDDETAILS , ui - > lineEdit_KeyId ) ;
// mStateHelper->addLoadPlaceholder(IDDIALOG_IDDETAILS, ui->lineEdit_GpgHash);
mStateHelper - > addLoadPlaceholder ( IDDIALOG_IDDETAILS , ui - > lineEdit_GpgId ) ;
mStateHelper - > addLoadPlaceholder ( IDDIALOG_IDDETAILS , ui - > lineEdit_Type ) ;
mStateHelper - > addLoadPlaceholder ( IDDIALOG_IDDETAILS , ui - > lineEdit_GpgName ) ;
2015-12-22 18:29:27 -05:00
mStateHelper - > addLoadPlaceholder ( IDDIALOG_IDDETAILS , ui - > lineEdit_LastUsed ) ;
//mStateHelper->addLoadPlaceholder(IDDIALOG_IDDETAILS, ui->line_RatingOverall);
2014-12-24 09:43:06 -05:00
mStateHelper - > addClear ( IDDIALOG_IDDETAILS , ui - > lineEdit_Nickname ) ;
mStateHelper - > addClear ( IDDIALOG_IDDETAILS , ui - > lineEdit_KeyId ) ;
// mStateHelper->addClear(IDDIALOG_IDDETAILS, ui->lineEdit_GpgHash);
mStateHelper - > addClear ( IDDIALOG_IDDETAILS , ui - > lineEdit_GpgId ) ;
mStateHelper - > addClear ( IDDIALOG_IDDETAILS , ui - > lineEdit_Type ) ;
2015-12-22 18:29:27 -05:00
mStateHelper - > addClear ( IDDIALOG_IDDETAILS , ui - > lineEdit_GpgName ) ;
mStateHelper - > addClear ( IDDIALOG_IDDETAILS , ui - > lineEdit_LastUsed ) ;
2014-12-24 09:43:06 -05:00
//mStateHelper->addWidget(IDDIALOG_REPLIST, ui->treeWidget_RepList);
//mStateHelper->addLoadPlaceholder(IDDIALOG_REPLIST, ui->treeWidget_RepList);
//mStateHelper->addClear(IDDIALOG_REPLIST, ui->treeWidget_RepList);
2013-07-10 17:57:23 -04:00
/* Connect signals */
2014-12-24 09:43:06 -05:00
connect ( ui - > toolButton_NewId , SIGNAL ( clicked ( ) ) , this , SLOT ( addIdentity ( ) ) ) ;
2015-01-24 14:27:19 -05:00
2014-12-24 09:43:06 -05:00
connect ( ui - > removeIdentity , SIGNAL ( triggered ( ) ) , this , SLOT ( removeIdentity ( ) ) ) ;
connect ( ui - > editIdentity , SIGNAL ( triggered ( ) ) , this , SLOT ( editIdentity ( ) ) ) ;
connect ( ui - > chatIdentity , SIGNAL ( triggered ( ) ) , this , SLOT ( chatIdentity ( ) ) ) ;
2014-05-03 13:56:12 -04:00
2015-08-11 10:01:43 -04:00
connect ( ui - > idTreeWidget , SIGNAL ( itemSelectionChanged ( ) ) , this , SLOT ( updateSelection ( ) ) ) ;
connect ( ui - > idTreeWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( IdListCustomPopupMenu ( QPoint ) ) ) ;
2012-02-13 13:43:15 -05:00
2014-12-24 09:43:06 -05:00
connect ( ui - > filterComboBox , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( filterComboBoxChanged ( ) ) ) ;
connect ( ui - > filterLineEdit , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( filterChanged ( QString ) ) ) ;
2015-12-22 18:29:27 -05:00
connect ( ui - > ownOpinion_CB , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( modifyReputation ( ) ) ) ;
2015-02-09 20:14:44 -05:00
2015-12-24 08:31:52 -05:00
connect ( ui - > inviteButton , SIGNAL ( clicked ( ) ) , this , SLOT ( sendInvite ( ) ) ) ;
2014-09-09 15:45:38 -04:00
2015-09-10 11:37:42 -04:00
2015-02-09 20:14:44 -05:00
ui - > avlabel - > setPixmap ( QPixmap ( " :/images/user/friends64.png " ) ) ;
2015-09-10 11:37:42 -04:00
2015-02-09 20:14:44 -05:00
ui - > headerTextLabel - > setText ( tr ( " People " ) ) ;
2014-12-24 09:43:06 -05:00
/* Initialize splitter */
ui - > splitter - > setStretchFactor ( 0 , 1 ) ;
ui - > splitter - > setStretchFactor ( 1 , 0 ) ;
2013-07-10 17:57:23 -04:00
2015-02-16 10:45:53 -05:00
QList < int > sizes ;
sizes < < width ( ) < < 500 ; // Qt calculates the right sizes
ui - > splitter - > setSizes ( sizes ) ;
2013-07-10 17:57:23 -04:00
/* Add filter types */
2015-02-05 15:37:24 -05:00
ui - > filterComboBox - > addItem ( tr ( " All " ) , RSID_FILTER_ALL ) ;
ui - > filterComboBox - > addItem ( tr ( " Owned by you " ) , RSID_FILTER_OWNED_BY_YOU ) ;
ui - > filterComboBox - > addItem ( tr ( " Linked to your node " ) , RSID_FILTER_YOURSELF ) ;
ui - > filterComboBox - > addItem ( tr ( " Linked to neighbor nodes " ) , RSID_FILTER_FRIENDS ) ;
ui - > filterComboBox - > addItem ( tr ( " Linked to distant nodes " ) , RSID_FILTER_OTHERS ) ;
ui - > filterComboBox - > addItem ( tr ( " Anonymous " ) , RSID_FILTER_PSEUDONYMS ) ;
2014-12-24 09:43:06 -05:00
ui - > filterComboBox - > setCurrentIndex ( 0 ) ;
2013-07-10 17:57:23 -04:00
/* Add filter actions */
2015-08-11 10:01:43 -04:00
QTreeWidgetItem * headerItem = ui - > idTreeWidget - > headerItem ( ) ;
2013-07-10 17:57:23 -04:00
QString headerText = headerItem - > text ( RSID_COL_NICKNAME ) ;
2014-12-24 09:43:06 -05:00
ui - > filterLineEdit - > addFilter ( QIcon ( ) , headerText , RSID_COL_NICKNAME , QString ( " %1 %2 " ) . arg ( tr ( " Search " ) , headerText ) ) ;
2016-01-01 15:15:19 -05:00
2015-09-10 11:37:42 -04:00
/* Set initial section sizes */
QHeaderView * circlesheader = ui - > treeWidget_membership - > header ( ) ;
circlesheader - > resizeSection ( CIRCLEGROUP_CIRCLE_COL_GROUPNAME , 280 ) ;
2013-07-10 17:57:23 -04:00
2015-12-22 18:29:27 -05:00
ui - > filterLineEdit - > addFilter ( QIcon ( ) , tr ( " ID " ) , RSID_COL_KEYID , tr ( " Search ID " ) ) ;
2014-12-24 09:43:06 -05:00
/* Setup tree */
2015-08-11 10:01:43 -04:00
ui - > idTreeWidget - > sortByColumn ( RSID_COL_NICKNAME , Qt : : AscendingOrder ) ;
ui - > idTreeWidget - > enableColumnCustomize ( true ) ;
ui - > idTreeWidget - > setColumnCustomizable ( RSID_COL_NICKNAME , false ) ;
2016-01-01 15:15:19 -05:00
2015-09-10 11:37:42 -04:00
ui - > idTreeWidget - > setColumnHidden ( RSID_COL_IDTYPE , true ) ;
2015-12-22 18:29:27 -05:00
ui - > idTreeWidget - > setColumnHidden ( RSID_COL_KEYID , true ) ;
2015-09-10 11:37:42 -04:00
2015-08-11 10:01:43 -04:00
/* Set initial column width */
int fontWidth = QFontMetricsF ( ui - > idTreeWidget - > font ( ) ) . width ( " W " ) ;
2015-12-22 18:29:27 -05:00
ui - > idTreeWidget - > setColumnWidth ( RSID_COL_NICKNAME , 14 * fontWidth ) ;
ui - > idTreeWidget - > setColumnWidth ( RSID_COL_KEYID , 20 * fontWidth ) ;
2015-08-11 10:01:43 -04:00
ui - > idTreeWidget - > setColumnWidth ( RSID_COL_IDTYPE , 18 * fontWidth ) ;
2015-12-22 18:29:27 -05:00
ui - > idTreeWidget - > setColumnWidth ( RSID_COL_VOTES , 7 * fontWidth ) ;
//QHeaderView_setSectionResizeMode(ui->idTreeWidget->header(), QHeaderView::ResizeToContents);
2015-08-11 10:01:43 -04:00
2012-11-01 20:49:06 -04:00
mIdQueue = new TokenQueue ( rsIdentity - > getTokenService ( ) , this ) ;
2013-07-10 17:57:23 -04:00
mStateHelper - > setActive ( IDDIALOG_IDDETAILS , false ) ;
mStateHelper - > setActive ( IDDIALOG_REPLIST , false ) ;
2014-02-19 06:11:06 -05:00
2014-09-09 15:45:38 -04:00
QString hlp_str = tr (
2015-06-30 12:44:58 -04:00
" <h1><img width= \" 32 \" src= \" :/icons/help_64.png \" > Identities</h1> \
2015-09-06 23:53:21 -04:00
< p > In this tab you can create / edit pseudo - anonymous identities . < / p > \
2014-09-09 15:45:38 -04:00
< p > Identities are used to securely identify your data : sign forum and channel posts , \
and receive feedback using Retroshare built - in email system , post comments \
after channel posts , etc . < / p > \
2015-09-06 23:53:21 -04:00
< p > Identities can optionally be signed by your Retroshare node ' s certificate . \
Signed identities are easier to trust but are easily linked to your node ' s IP address . < / p > \
< p > Anonymous identities allow you to anonymously interact with other users . They cannot be \
spoofed , but noone can prove who really owns a given identity . < / p > " ) ;
2014-09-09 15:45:38 -04:00
2014-12-24 09:43:06 -05:00
registerHelpButton ( ui - > helpButton , hlp_str ) ;
// load settings
processSettings ( true ) ;
2015-02-18 17:09:51 -05:00
2015-09-06 23:53:21 -04:00
// circles stuff
connect ( ui - > pushButton_extCircle , SIGNAL ( clicked ( ) ) , this , SLOT ( createExternalCircle ( ) ) ) ;
connect ( ui - > pushButton_editCircle , SIGNAL ( clicked ( ) ) , this , SLOT ( editExistingCircle ( ) ) ) ;
connect ( ui - > treeWidget_membership , SIGNAL ( itemSelectionChanged ( ) ) , this , SLOT ( circle_selected ( ) ) ) ;
2015-09-10 20:46:34 -04:00
connect ( ui - > treeWidget_membership , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( CircleListCustomPopupMenu ( QPoint ) ) ) ;
2015-09-06 23:53:21 -04:00
/* Setup TokenQueue */
mCircleQueue = new TokenQueue ( rsGxsCircles - > getTokenService ( ) , this ) ;
requestCircleGroupMeta ( ) ;
}
/************************** Request / Response *************************/
/*** Loading Main Index ***/
void IdDialog : : requestCircleGroupMeta ( )
{
mStateHelper - > setLoading ( CIRCLESDIALOG_GROUPMETA , true ) ;
std : : cerr < < " CirclesDialog::requestGroupMeta() " ;
std : : cerr < < std : : endl ;
mCircleQueue - > cancelActiveRequestTokens ( CIRCLESDIALOG_GROUPMETA ) ;
RsTokReqOptions opts ;
opts . mReqType = GXS_REQUEST_TYPE_GROUP_META ;
uint32_t token ;
mCircleQueue - > requestGroupInfo ( token , RS_TOKREQ_ANSTYPE_SUMMARY , opts , CIRCLESDIALOG_GROUPMETA ) ;
2012-02-13 13:43:15 -05:00
}
2015-09-06 23:53:21 -04:00
void IdDialog : : loadCircleGroupMeta ( const uint32_t & token )
{
mStateHelper - > setLoading ( CIRCLESDIALOG_GROUPMETA , false ) ;
std : : cerr < < " CirclesDialog::loadCircleGroupMeta() " ;
std : : cerr < < std : : endl ;
ui - > treeWidget_membership - > clear ( ) ;
std : : list < RsGroupMetaData > groupInfo ;
std : : list < RsGroupMetaData > : : iterator vit ;
if ( ! rsGxsCircles - > getGroupSummary ( token , groupInfo ) )
{
std : : cerr < < " CirclesDialog::loadCircleGroupMeta() Error getting GroupMeta " ;
std : : cerr < < std : : endl ;
mStateHelper - > setActive ( CIRCLESDIALOG_GROUPMETA , false ) ;
return ;
}
mStateHelper - > setActive ( CIRCLESDIALOG_GROUPMETA , true ) ;
/* add the top level item */
2015-09-10 19:15:45 -04:00
//QTreeWidgetItem *personalCirclesItem = new QTreeWidgetItem();
//personalCirclesItem->setText(0, tr("Personal Circles"));
//ui->treeWidget_membership->addTopLevelItem(personalCirclesItem);
2016-03-08 00:02:16 -05:00
QTreeWidgetItem * externalOtherCirclesItem = new QTreeWidgetItem ( ) ;
externalOtherCirclesItem - > setText ( 0 , tr ( " Circles (Other) " ) ) ;
ui - > treeWidget_membership - > addTopLevelItem ( externalOtherCirclesItem ) ;
2015-09-06 23:53:21 -04:00
QTreeWidgetItem * externalSubCirclesItem = new QTreeWidgetItem ( ) ;
2015-09-10 19:15:45 -04:00
externalSubCirclesItem - > setText ( 0 , tr ( " Circles (Subscribed) " ) ) ;
2015-09-06 23:53:21 -04:00
ui - > treeWidget_membership - > addTopLevelItem ( externalSubCirclesItem ) ;
2016-03-08 00:02:16 -05:00
QTreeWidgetItem * externalAdminCirclesItem = new QTreeWidgetItem ( ) ;
externalAdminCirclesItem - > setText ( 0 , tr ( " Circles (Admin) " ) ) ;
ui - > treeWidget_membership - > addTopLevelItem ( externalAdminCirclesItem ) ;
2015-09-06 23:53:21 -04:00
for ( vit = groupInfo . begin ( ) ; vit ! = groupInfo . end ( ) ; + + vit )
{
/* Add Widget, and request Pages */
std : : cerr < < " CirclesDialog::loadCircleGroupMeta() GroupId: " < < vit - > mGroupId ;
std : : cerr < < " Group: " < < vit - > mGroupName ;
std : : cerr < < std : : endl ;
QTreeWidgetItem * groupItem = new QTreeWidgetItem ( ) ;
groupItem - > setText ( CIRCLEGROUP_CIRCLE_COL_GROUPNAME , QString : : fromUtf8 ( vit - > mGroupName . c_str ( ) ) ) ;
2016-03-08 00:02:16 -05:00
groupItem - > setText ( CIRCLEGROUP_CIRCLE_COL_GROUPID , QString : : fromStdString ( vit - > mGroupId . toStdString ( ) ) ) ;
groupItem - > setData ( CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS , Qt : : UserRole , QVariant ( vit - > mSubscribeFlags ) ) ;
2015-09-06 23:53:21 -04:00
if ( vit - > mCircleType = = GXS_CIRCLE_TYPE_LOCAL )
{
2015-09-10 19:15:45 -04:00
//personalCirclesItem->addChild(groupItem);
2015-09-06 23:53:21 -04:00
}
else
{
if ( vit - > mSubscribeFlags & GXS_SERV : : GROUP_SUBSCRIBE_ADMIN )
{
externalAdminCirclesItem - > addChild ( groupItem ) ;
}
else if ( vit - > mSubscribeFlags & GXS_SERV : : GROUP_SUBSCRIBE_SUBSCRIBED )
{
externalSubCirclesItem - > addChild ( groupItem ) ;
}
else
{
externalOtherCirclesItem - > addChild ( groupItem ) ;
}
}
}
}
void IdDialog : : createExternalCircle ( )
{
CreateCircleDialog dlg ;
dlg . editNewId ( true ) ;
dlg . exec ( ) ;
2016-02-11 21:59:45 -05:00
requestCircleGroupMeta ( ) ; // update GUI
2015-09-06 23:53:21 -04:00
}
void IdDialog : : editExistingCircle ( )
{
QTreeWidgetItem * item = ui - > treeWidget_membership - > currentItem ( ) ;
if ( ( ! item ) | | ( ! item - > parent ( ) ) )
{
return ;
}
QString coltext = item - > text ( CIRCLEGROUP_CIRCLE_COL_GROUPID ) ;
RsGxsGroupId id ( coltext . toStdString ( ) ) ;
CreateCircleDialog dlg ;
dlg . editExistingId ( id ) ;
dlg . exec ( ) ;
2016-02-11 21:59:45 -05:00
requestCircleGroupMeta ( ) ; // update GUI
2015-09-06 23:53:21 -04:00
}
2015-09-10 20:46:34 -04:00
void IdDialog : : CircleListCustomPopupMenu ( QPoint )
{
2016-03-09 20:53:49 -05:00
// (cyril) Removed this because we have a edit button already.
# ifdef SUSPENDED
2015-09-10 20:46:34 -04:00
QMenu contextMnu ( this ) ;
QTreeWidgetItem * item = ui - > treeWidget_membership - > currentItem ( ) ;
if ( item ) {
contextMnu . addAction ( QIcon ( IMAGE_EDIT ) , tr ( " Edit Circle " ) , this , SLOT ( editExistingCircle ( ) ) ) ;
}
contextMnu . exec ( QCursor : : pos ( ) ) ;
2016-03-09 20:53:49 -05:00
# endif
2015-09-10 20:46:34 -04:00
}
2015-09-06 23:53:21 -04:00
static void set_item_background ( QTreeWidgetItem * item , uint32_t type )
{
QBrush brush ;
switch ( type )
{
default :
case CLEAR_BACKGROUND :
brush = QBrush ( Qt : : white ) ;
break ;
case GREEN_BACKGROUND :
brush = QBrush ( Qt : : green ) ;
break ;
case BLUE_BACKGROUND :
brush = QBrush ( Qt : : blue ) ;
break ;
case RED_BACKGROUND :
brush = QBrush ( Qt : : red ) ;
break ;
case GRAY_BACKGROUND :
brush = QBrush ( Qt : : gray ) ;
break ;
}
item - > setBackground ( 0 , brush ) ;
}
static void update_children_background ( QTreeWidgetItem * item , uint32_t type )
{
int count = item - > childCount ( ) ;
for ( int i = 0 ; i < count ; + + i )
{
QTreeWidgetItem * child = item - > child ( i ) ;
if ( child - > childCount ( ) > 0 )
{
update_children_background ( child , type ) ;
}
set_item_background ( child , type ) ;
}
}
static void set_tree_background ( QTreeWidget * tree , uint32_t type )
{
std : : cerr < < " CirclesDialog set_tree_background() " ;
std : : cerr < < std : : endl ;
/* grab all toplevel */
int count = tree - > topLevelItemCount ( ) ;
for ( int i = 0 ; i < count ; + + i )
{
QTreeWidgetItem * item = tree - > topLevelItem ( i ) ;
/* resursively clear child backgrounds */
update_children_background ( item , type ) ;
set_item_background ( item , type ) ;
}
}
static void check_mark_item ( QTreeWidgetItem * item , const std : : set < RsPgpId > & names , uint32_t col , uint32_t type )
{
QString coltext = item - > text ( col ) ;
RsPgpId colstr ( coltext . toStdString ( ) ) ;
if ( names . end ( ) ! = names . find ( colstr ) )
{
set_item_background ( item , type ) ;
std : : cerr < < " CirclesDialog check_mark_item: found match: " < < colstr ;
std : : cerr < < std : : endl ;
}
}
void IdDialog : : circle_selected ( )
{
QTreeWidgetItem * item = ui - > treeWidget_membership - > currentItem ( ) ;
std : : cerr < < " CirclesDialog::circle_selected() valid circle chosen " ;
std : : cerr < < std : : endl ;
set_tree_background ( ui - > treeWidget_membership , CLEAR_BACKGROUND ) ;
//set_tree_background(ui->treeWidget_friends, CLEAR_BACKGROUND);
//set_tree_background(ui->treeWidget_category, CLEAR_BACKGROUND);
if ( ( ! item ) | | ( ! item - > parent ( ) ) )
{
mStateHelper - > setWidgetEnabled ( ui - > pushButton_editCircle , false ) ;
return ;
}
2016-03-08 00:02:16 -05:00
uint32_t subscribe_flags = item - > data ( CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS , Qt : : UserRole ) . toUInt ( ) ;
if ( subscribe_flags & GXS_SERV : : GROUP_SUBSCRIBE_ADMIN )
ui - > pushButton_editCircle - > setEnabled ( true ) ;
else
ui - > pushButton_editCircle - > setEnabled ( false ) ;
2015-09-06 23:53:21 -04:00
set_item_background ( item , BLUE_BACKGROUND ) ;
QString coltext = item - > text ( CIRCLEGROUP_CIRCLE_COL_GROUPID ) ;
2016-03-08 00:02:16 -05:00
RsGxsCircleId id ( coltext . toStdString ( ) ) ;
2015-09-06 23:53:21 -04:00
2016-03-08 00:02:16 -05:00
# ifdef SUSPENDED
2015-09-06 23:53:21 -04:00
/* update friend lists */
RsGxsCircleDetails details ;
if ( rsGxsCircles - > getCircleDetails ( id , details ) )
{
/* now mark all the members */
2016-03-08 00:02:16 -05:00
std : : set < RsPgpId > members ;
2015-09-06 23:53:21 -04:00
std : : map < RsPgpId , std : : list < RsGxsId > > : : iterator it ;
for ( it = details . mAllowedPeers . begin ( ) ; it ! = details . mAllowedPeers . end ( ) ; + + it )
{
members . insert ( it - > first ) ;
std : : cerr < < " Circle member: " < < it - > first ;
std : : cerr < < std : : endl ;
}
2016-03-08 00:02:16 -05:00
mark_matching_tree ( ui - > treeWidget_friends , members , CIRCLEGROUP_FRIEND_COL_ID , GREEN_BACKGROUND ) ;
2015-09-06 23:53:21 -04:00
}
else
{
2016-03-08 00:02:16 -05:00
set_tree_background ( ui - > treeWidget_friends , GRAY_BACKGROUND ) ;
2015-09-06 23:53:21 -04:00
}
2016-03-08 00:02:16 -05:00
# endif
2015-09-06 23:53:21 -04:00
mStateHelper - > setWidgetEnabled ( ui - > pushButton_editCircle , true ) ;
}
2014-10-12 06:46:09 -04:00
IdDialog : : ~ IdDialog ( )
{
2014-12-24 09:43:06 -05:00
// save settings
processSettings ( false ) ;
delete ( ui ) ;
2014-10-12 06:46:09 -04:00
delete ( mIdQueue ) ;
}
2015-09-10 11:37:42 -04:00
static QString getHumanReadableDuration ( uint32_t seconds )
{
if ( seconds < 60 )
return QString ( QObject : : tr ( " %1 seconds ago " ) ) . arg ( seconds ) ;
else if ( seconds < 120 )
return QString ( QObject : : tr ( " %1 minute ago " ) ) . arg ( seconds / 60 ) ;
else if ( seconds < 3600 )
return QString ( QObject : : tr ( " %1 minutes ago " ) ) . arg ( seconds / 60 ) ;
else if ( seconds < 7200 )
return QString ( QObject : : tr ( " %1 hour ago " ) ) . arg ( seconds / 3600 ) ;
else if ( seconds < 24 * 3600 )
return QString ( QObject : : tr ( " %1 hours ago " ) ) . arg ( seconds / 3600 ) ;
else if ( seconds < 2 * 24 * 3600 )
return QString ( QObject : : tr ( " %1 day ago " ) ) . arg ( seconds / 86400 ) ;
else
return QString ( QObject : : tr ( " %1 days ago " ) ) . arg ( seconds / 86400 ) ;
}
2014-12-24 09:43:06 -05:00
void IdDialog : : processSettings ( bool load )
{
Settings - > beginGroup ( " IdDialog " ) ;
2015-08-11 10:01:43 -04:00
// state of peer tree
ui - > idTreeWidget - > processSettings ( load ) ;
2014-12-24 09:43:06 -05:00
if ( load ) {
// load settings
// filterColumn
ui - > filterLineEdit - > setCurrentFilter ( Settings - > value ( " filterColumn " , RSID_COL_NICKNAME ) . toInt ( ) ) ;
// state of splitter
ui - > splitter - > restoreState ( Settings - > value ( " splitter " ) . toByteArray ( ) ) ;
} else {
// save settings
// filterColumn
Settings - > setValue ( " filterColumn " , ui - > filterLineEdit - > currentFilter ( ) ) ;
// state of splitter
Settings - > setValue ( " splitter " , ui - > splitter - > saveState ( ) ) ;
2015-12-27 13:14:20 -05:00
//save expanding
Settings - > setValue ( " ExpandAll " , allItem - > isExpanded ( ) ) ;
Settings - > setValue ( " ExpandContacts " , contactsItem - > isExpanded ( ) ) ;
2014-12-24 09:43:06 -05:00
}
Settings - > endGroup ( ) ;
2013-07-10 17:57:23 -04:00
}
void IdDialog : : filterComboBoxChanged ( )
2013-07-11 04:14:38 -04:00
{
requestIdList ( ) ;
}
2012-02-13 13:43:15 -05:00
2013-07-10 17:57:23 -04:00
void IdDialog : : filterChanged ( const QString & /*text*/ )
{
filterIds ( ) ;
}
2012-02-13 13:43:15 -05:00
void IdDialog : : updateSelection ( )
{
2015-08-11 10:01:43 -04:00
QTreeWidgetItem * item = ui - > idTreeWidget - > currentItem ( ) ;
2014-12-24 09:43:06 -05:00
RsGxsGroupId id ;
2013-07-10 17:57:23 -04:00
2014-12-24 09:43:06 -05:00
if ( item ) {
id = RsGxsGroupId ( item - > text ( RSID_COL_KEYID ) . toStdString ( ) ) ;
2013-07-10 17:57:23 -04:00
}
2014-12-24 09:43:06 -05:00
if ( id ! = mId ) {
mId = id ;
requestIdDetails ( ) ;
requestRepList ( ) ;
}
2013-07-10 17:57:23 -04:00
}
void IdDialog : : requestIdList ( )
{
2014-12-24 09:43:06 -05:00
//Disable by default, will be enable by insertIdDetails()
2015-01-25 09:14:03 -05:00
ui - > removeIdentity - > setEnabled ( false ) ;
ui - > editIdentity - > setEnabled ( false ) ;
2014-12-24 09:43:06 -05:00
2013-07-10 17:57:23 -04:00
if ( ! mIdQueue )
return ;
mStateHelper - > setLoading ( IDDIALOG_IDLIST , true ) ;
mIdQueue - > cancelActiveRequestTokens ( IDDIALOG_IDLIST ) ;
RsTokReqOptions opts ;
opts . mReqType = GXS_REQUEST_TYPE_GROUP_DATA ;
uint32_t token ;
mIdQueue - > requestGroupInfo ( token , RS_TOKREQ_ANSTYPE_DATA , opts , IDDIALOG_IDLIST ) ;
}
2014-03-17 16:56:06 -04:00
bool IdDialog : : fillIdListItem ( const RsGxsIdGroup & data , QTreeWidgetItem * & item , const RsPgpId & ownPgpId , int accept )
2013-07-10 17:57:23 -04:00
{
2015-02-05 15:37:24 -05:00
bool isLinkedToOwnNode = ( data . mPgpKnown & & ( data . mPgpId = = ownPgpId ) ) ;
bool isOwnId = ( data . mMeta . mSubscribeFlags & GXS_SERV : : GROUP_SUBSCRIBE_ADMIN ) ;
uint32_t item_flags = 0 ;
2013-07-10 17:57:23 -04:00
/* do filtering */
bool ok = false ;
if ( data . mMeta . mGroupFlags & RSGXSID_GROUPFLAG_REALID )
2015-02-05 15:37:24 -05:00
{
if ( isLinkedToOwnNode & & ( accept & RSID_FILTER_YOURSELF ) )
{
ok = true ;
item_flags | = RSID_FILTER_YOURSELF ;
}
if ( data . mPgpKnown & & ( accept & RSID_FILTER_FRIENDS ) )
{
ok = true ;
item_flags | = RSID_FILTER_FRIENDS ;
}
if ( accept & RSID_FILTER_OTHERS )
{
ok = true ;
item_flags | = RSID_FILTER_OTHERS ;
}
}
else if ( accept & RSID_FILTER_PSEUDONYMS )
{
ok = true ;
item_flags | = RSID_FILTER_PSEUDONYMS ;
}
if ( isOwnId & & ( accept & RSID_FILTER_OWNED_BY_YOU ) )
{
ok = true ;
item_flags | = RSID_FILTER_OWNED_BY_YOU ;
}
2013-07-10 17:57:23 -04:00
if ( ! ok )
return false ;
2012-02-13 13:43:15 -05:00
if ( ! item )
2016-01-16 08:50:12 -05:00
item = new TreeWidgetItem ( ) ;
2015-12-22 18:29:27 -05:00
RsReputations : : ReputationInfo info ;
rsReputations - > getReputationInfo ( RsGxsId ( data . mMeta . mGroupId ) , info ) ;
2015-02-05 15:37:24 -05:00
2015-04-09 15:53:01 -04:00
item - > setText ( RSID_COL_NICKNAME , QString : : fromUtf8 ( data . mMeta . mGroupName . c_str ( ) ) . left ( RSID_MAXIMUM_NICKNAME_SIZE ) ) ;
2015-02-05 15:37:24 -05:00
item - > setText ( RSID_COL_KEYID , QString : : fromStdString ( data . mMeta . mGroupId . toStdString ( ) ) ) ;
2015-09-10 11:37:42 -04:00
2016-01-01 21:37:27 -05:00
//time_t now = time(NULL) ;
//item->setText(RSID_COL_LASTUSED, getHumanReadableDuration(now - data.mLastUsageTS)) ;
2015-02-05 15:37:24 -05:00
item - > setData ( RSID_COL_KEYID , Qt : : UserRole , QVariant ( item_flags ) ) ;
2015-09-10 11:37:42 -04:00
2015-12-22 18:29:27 -05:00
item - > setTextAlignment ( RSID_COL_VOTES , Qt : : AlignRight ) ;
item - > setData ( RSID_COL_VOTES , Qt : : DisplayRole , QString : : number ( info . mOverallReputationScore - 1.0f , ' f ' , 3 ) ) ;
2014-09-24 17:00:40 -04:00
2014-09-24 16:13:19 -04:00
if ( isOwnId )
{
2015-02-05 15:37:24 -05:00
QFont font = item - > font ( RSID_COL_NICKNAME ) ;
2014-12-24 09:43:06 -05:00
font . setBold ( true ) ;
item - > setFont ( RSID_COL_NICKNAME , font ) ;
item - > setFont ( RSID_COL_IDTYPE , font ) ;
item - > setFont ( RSID_COL_KEYID , font ) ;
QString tooltip = tr ( " This identity is owned by you " ) ;
item - > setToolTip ( RSID_COL_NICKNAME , tooltip ) ;
item - > setToolTip ( RSID_COL_KEYID , tooltip ) ;
item - > setToolTip ( RSID_COL_IDTYPE , tooltip ) ;
2014-09-24 16:13:19 -04:00
}
2014-10-25 09:16:47 -04:00
# ifdef ID_DEBUG
2014-09-15 19:28:53 -04:00
std : : cerr < < " Setting item image : " < < pixmap . width ( ) < < " x " < < pixmap . height ( ) < < std : : endl ;
2014-10-25 09:16:47 -04:00
# endif
2015-01-25 17:09:12 -05:00
QPixmap pixmap ;
if ( data . mImage . mSize = = 0 | | ! pixmap . loadFromData ( data . mImage . mData , data . mImage . mSize , " PNG " ) )
pixmap = QPixmap : : fromImage ( GxsIdDetails : : makeDefaultIcon ( RsGxsId ( data . mMeta . mGroupId ) ) ) ;
item - > setIcon ( RSID_COL_NICKNAME , QIcon ( pixmap ) ) ;
2014-09-15 19:28:53 -04:00
2015-02-17 16:31:14 -05:00
QString tooltip ;
2013-07-10 17:57:23 -04:00
if ( data . mMeta . mGroupFlags & RSGXSID_GROUPFLAG_REALID )
{
if ( data . mPgpKnown )
{
RsPeerDetails details ;
rsPeers - > getGPGDetails ( data . mPgpId , details ) ;
item - > setText ( RSID_COL_IDTYPE , QString : : fromUtf8 ( details . name . c_str ( ) ) ) ;
2014-10-25 09:16:47 -04:00
item - > setToolTip ( RSID_COL_IDTYPE , QString : : fromStdString ( data . mPgpId . toStdString ( ) ) ) ;
2015-02-17 16:31:14 -05:00
2015-06-12 04:27:26 -04:00
tooltip + = tr ( " Node name: " ) + " " + QString : : fromUtf8 ( details . name . c_str ( ) ) + " \n " ;
tooltip + = tr ( " Node Id : " ) + " " + QString : : fromStdString ( data . mPgpId . toStdString ( ) ) ;
2015-02-17 16:31:14 -05:00
item - > setToolTip ( RSID_COL_KEYID , tooltip ) ;
2013-07-10 17:57:23 -04:00
}
2014-04-14 11:37:06 -04:00
else
{
2014-10-25 09:16:47 -04:00
item - > setText ( RSID_COL_IDTYPE , tr ( " Unknown PGP key " ) ) ;
2014-09-24 16:13:19 -04:00
item - > setToolTip ( RSID_COL_IDTYPE , tr ( " Unknown key ID " ) ) ;
2015-02-17 16:31:14 -05:00
item - > setToolTip ( RSID_COL_KEYID , tr ( " Unknown key ID " ) ) ;
2014-04-14 11:37:06 -04:00
}
2012-06-07 13:11:57 -04:00
}
2013-07-10 17:57:23 -04:00
else
{
2014-09-24 16:13:19 -04:00
item - > setText ( RSID_COL_IDTYPE , QString ( ) ) ;
item - > setToolTip ( RSID_COL_IDTYPE , QString ( ) ) ;
2013-07-10 17:57:23 -04:00
}
2012-02-13 13:43:15 -05:00
2013-07-10 17:57:23 -04:00
return true ;
}
2012-02-13 13:43:15 -05:00
2013-07-10 17:57:23 -04:00
void IdDialog : : insertIdList ( uint32_t token )
2012-06-07 13:11:57 -04:00
{
2013-07-10 17:57:23 -04:00
mStateHelper - > setLoading ( IDDIALOG_IDLIST , false ) ;
2014-12-24 09:43:06 -05:00
int accept = ui - > filterComboBox - > itemData ( ui - > filterComboBox - > currentIndex ( ) ) . toInt ( ) ;
2015-12-22 18:29:27 -05:00
2013-07-10 17:57:23 -04:00
RsGxsIdGroup data ;
std : : vector < RsGxsIdGroup > datavector ;
std : : vector < RsGxsIdGroup > : : iterator vit ;
2015-12-23 12:08:20 -05:00
2013-07-10 17:57:23 -04:00
if ( ! rsIdentity - > getGroupData ( token , datavector ) )
{
2014-10-25 09:16:47 -04:00
# ifdef ID_DEBUG
2013-07-10 17:57:23 -04:00
std : : cerr < < " IdDialog::insertIdList() Error getting GroupData " ;
std : : cerr < < std : : endl ;
2014-10-25 09:16:47 -04:00
# endif
2013-07-10 17:57:23 -04:00
mStateHelper - > setActive ( IDDIALOG_IDLIST , false ) ;
mStateHelper - > clear ( IDDIALOG_IDLIST ) ;
return ;
2014-04-14 11:37:06 -04:00
}
2015-12-23 12:08:20 -05:00
// turn that vector into a std::set, to avoid a linear search
std : : map < RsGxsGroupId , RsGxsIdGroup > ids_set ;
for ( uint32_t i = 0 ; i < datavector . size ( ) ; + + i )
ids_set [ datavector [ i ] . mMeta . mGroupId ] = datavector [ i ] ;
2012-02-13 13:43:15 -05:00
2013-07-10 17:57:23 -04:00
mStateHelper - > setActive ( IDDIALOG_IDLIST , true ) ;
2014-03-17 16:56:06 -04:00
RsPgpId ownPgpId = rsPeers - > getGPGOwnId ( ) ;
2012-02-13 13:43:15 -05:00
2015-12-23 12:08:20 -05:00
// Update existing and remove not existing items
// Also remove items that do not have the correct parent
2015-08-11 10:01:43 -04:00
QTreeWidgetItemIterator itemIterator ( ui - > idTreeWidget ) ;
2013-07-10 17:57:23 -04:00
QTreeWidgetItem * item = NULL ;
2015-12-23 12:08:20 -05:00
while ( ( item = * itemIterator ) ! = NULL )
{
2014-10-21 18:33:02 -04:00
+ + itemIterator ;
2015-12-23 12:08:20 -05:00
std : : map < RsGxsGroupId , RsGxsIdGroup > : : iterator it = ids_set . find ( RsGxsGroupId ( item - > text ( RSID_COL_KEYID ) . toStdString ( ) ) ) ;
2012-06-13 20:36:25 -04:00
2015-12-23 12:08:20 -05:00
if ( it = = ids_set . end ( ) )
2013-07-10 17:57:23 -04:00
{
2015-12-23 12:08:20 -05:00
if ( item ! = allItem & & item ! = contactsItem )
2013-07-10 17:57:23 -04:00
delete ( item ) ;
2015-12-23 12:08:20 -05:00
continue ;
}
QTreeWidgetItem * parent_item = item - > parent ( ) ;
if ( ( parent_item = = allItem & & it - > second . mIsAContact ) | | ( parent_item = = contactsItem & & ! it - > second . mIsAContact ) )
{
delete item ; // do not remove from the list, so that it is added again in the correct place.
continue ;
}
if ( ! fillIdListItem ( it - > second , item , ownPgpId , accept ) )
delete ( item ) ;
ids_set . erase ( it ) ; // erase, so it is not considered to be a new item
2013-07-10 17:57:23 -04:00
}
/* Insert new items */
2015-12-23 12:08:20 -05:00
for ( std : : map < RsGxsGroupId , RsGxsIdGroup > : : const_iterator vit = ids_set . begin ( ) ; vit ! = ids_set . end ( ) ; + + vit )
2013-07-10 17:57:23 -04:00
{
2015-12-23 12:08:20 -05:00
data = vit - > second ;
2013-07-10 17:57:23 -04:00
item = NULL ;
2015-12-22 18:29:27 -05:00
ui - > idTreeWidget - > insertTopLevelItem ( 0 , contactsItem ) ;
ui - > idTreeWidget - > insertTopLevelItem ( 0 , allItem ) ;
2015-12-27 13:14:20 -05:00
Settings - > beginGroup ( " IdDialog " ) ;
allItem - > setExpanded ( Settings - > value ( " ExpandAll " , QVariant ( true ) ) . toBool ( ) ) ;
contactsItem - > setExpanded ( Settings - > value ( " ExpandContacts " , QVariant ( true ) ) . toBool ( ) ) ;
Settings - > endGroup ( ) ;
2015-12-23 12:08:20 -05:00
if ( fillIdListItem ( vit - > second , item , ownPgpId , accept ) )
if ( vit - > second . mIsAContact )
contactsItem - > addChild ( item ) ;
else
allItem - > addChild ( item ) ;
2013-07-10 17:57:23 -04:00
}
2015-12-24 11:46:02 -05:00
/* count items */
int itemCount = contactsItem - > childCount ( ) + allItem - > childCount ( ) ;
ui - > label_count - > setText ( " ( " + QString : : number ( itemCount ) + " ) " ) ;
2013-07-10 17:57:23 -04:00
filterIds ( ) ;
updateSelection ( ) ;
}
2012-06-13 20:36:25 -04:00
2014-12-24 09:43:06 -05:00
void IdDialog : : requestIdDetails ( )
2012-02-13 13:43:15 -05:00
{
2013-07-10 17:57:23 -04:00
mIdQueue - > cancelActiveRequestTokens ( IDDIALOG_IDDETAILS ) ;
2014-12-24 09:43:06 -05:00
if ( mId . isNull ( ) )
2013-07-10 17:57:23 -04:00
{
mStateHelper - > setActive ( IDDIALOG_IDDETAILS , false ) ;
mStateHelper - > setLoading ( IDDIALOG_IDDETAILS , false ) ;
mStateHelper - > clear ( IDDIALOG_IDDETAILS ) ;
return ;
}
mStateHelper - > setLoading ( IDDIALOG_IDDETAILS , true ) ;
2012-06-13 20:36:25 -04:00
RsTokReqOptions opts ;
2013-07-11 04:14:38 -04:00
opts . mReqType = GXS_REQUEST_TYPE_GROUP_DATA ;
2012-02-13 13:43:15 -05:00
2012-06-13 20:36:25 -04:00
uint32_t token ;
2014-12-24 09:43:06 -05:00
std : : list < RsGxsGroupId > groupIds ;
groupIds . push_back ( mId ) ;
2012-02-13 13:43:15 -05:00
2013-07-11 04:14:38 -04:00
mIdQueue - > requestGroupInfo ( token , RS_TOKREQ_ANSTYPE_DATA , opts , groupIds , IDDIALOG_IDDETAILS ) ;
2012-02-13 13:43:15 -05:00
}
2012-06-07 13:11:57 -04:00
void IdDialog : : insertIdDetails ( uint32_t token )
2012-02-13 13:43:15 -05:00
{
2013-07-10 17:57:23 -04:00
mStateHelper - > setLoading ( IDDIALOG_IDDETAILS , false ) ;
2012-06-07 13:11:57 -04:00
/* get details from libretroshare */
2012-10-31 19:32:56 -04:00
RsGxsIdGroup data ;
2012-11-01 20:49:06 -04:00
std : : vector < RsGxsIdGroup > datavector ;
if ( ! rsIdentity - > getGroupData ( token , datavector ) )
2012-02-13 13:43:15 -05:00
{
2013-07-10 17:57:23 -04:00
mStateHelper - > setActive ( IDDIALOG_IDDETAILS , false ) ;
mStateHelper - > clear ( IDDIALOG_REPLIST ) ;
2014-12-24 09:43:06 -05:00
ui - > lineEdit_KeyId - > setText ( " ERROR GETTING KEY! " ) ;
2013-07-10 17:57:23 -04:00
2012-06-07 13:11:57 -04:00
return ;
}
2012-11-01 20:49:06 -04:00
if ( datavector . size ( ) ! = 1 )
{
2014-10-25 09:16:47 -04:00
# ifdef ID_DEBUG
2012-11-01 20:49:06 -04:00
std : : cerr < < " IdDialog::insertIdDetails() Invalid datavector size " ;
2014-10-25 09:16:47 -04:00
# endif
2013-07-10 17:57:23 -04:00
mStateHelper - > setActive ( IDDIALOG_IDDETAILS , false ) ;
mStateHelper - > clear ( IDDIALOG_IDDETAILS ) ;
2014-12-24 09:43:06 -05:00
ui - > lineEdit_KeyId - > setText ( " INVALID DV SIZE " ) ;
2013-07-10 17:57:23 -04:00
2012-11-01 20:49:06 -04:00
return ;
}
2013-07-10 17:57:23 -04:00
mStateHelper - > setActive ( IDDIALOG_IDDETAILS , true ) ;
2012-11-01 20:49:06 -04:00
data = datavector [ 0 ] ;
2012-06-07 13:11:57 -04:00
/* get GPG Details from rsPeers */
2014-03-17 16:56:06 -04:00
RsPgpId ownPgpId = rsPeers - > getGPGOwnId ( ) ;
2013-07-11 04:14:38 -04:00
2015-04-21 14:42:56 -04:00
ui - > lineEdit_Nickname - > setText ( QString : : fromUtf8 ( data . mMeta . mGroupName . c_str ( ) ) . left ( RSID_MAXIMUM_NICKNAME_SIZE ) ) ;
2014-12-24 09:43:06 -05:00
ui - > lineEdit_KeyId - > setText ( QString : : fromStdString ( data . mMeta . mGroupId . toStdString ( ) ) ) ;
//ui->lineEdit_GpgHash->setText(QString::fromStdString(data.mPgpIdHash.toStdString()));
2015-03-14 10:33:23 -04:00
ui - > lineEdit_GpgId - > setText ( QString : : fromStdString ( data . mPgpId . toStdString ( ) ) ) ;
time_t now = time ( NULL ) ;
ui - > lineEdit_LastUsed - > setText ( getHumanReadableDuration ( now - data . mLastUsageTS ) ) ;
2015-04-21 14:42:56 -04:00
ui - > headerTextLabel - > setText ( QString : : fromUtf8 ( data . mMeta . mGroupName . c_str ( ) ) . left ( RSID_MAXIMUM_NICKNAME_SIZE ) ) ;
2012-11-05 17:32:52 -05:00
2015-01-25 17:09:12 -05:00
QPixmap pixmap ;
if ( data . mImage . mSize = = 0 | | ! pixmap . loadFromData ( data . mImage . mData , data . mImage . mSize , " PNG " ) )
pixmap = QPixmap : : fromImage ( GxsIdDetails : : makeDefaultIcon ( RsGxsId ( data . mMeta . mGroupId ) ) ) ;
2014-10-25 09:16:47 -04:00
# ifdef ID_DEBUG
2014-12-24 09:43:06 -05:00
std : : cerr < < " Setting header frame image : " < < pix . width ( ) < < " x " < < pix . height ( ) < < std : : endl ;
2014-10-25 09:16:47 -04:00
# endif
2015-09-10 11:37:42 -04:00
2015-02-09 20:14:44 -05:00
ui - > avlabel - > setPixmap ( pixmap ) ;
2015-09-10 11:37:42 -04:00
2015-02-03 17:16:21 -05:00
ui - > avatarLabel - > setPixmap ( pixmap ) ;
2014-09-14 12:28:02 -04:00
2012-11-06 14:18:56 -05:00
if ( data . mPgpKnown )
2012-06-07 13:11:57 -04:00
{
2012-11-06 14:18:56 -05:00
RsPeerDetails details ;
rsPeers - > getGPGDetails ( data . mPgpId , details ) ;
2014-12-24 09:43:06 -05:00
ui - > lineEdit_GpgName - > setText ( QString : : fromUtf8 ( details . name . c_str ( ) ) ) ;
2012-06-07 13:11:57 -04:00
}
2012-11-06 14:18:56 -05:00
else
2012-06-07 13:11:57 -04:00
{
2012-11-06 14:18:56 -05:00
if ( data . mMeta . mGroupFlags & RSGXSID_GROUPFLAG_REALID )
{
2014-12-24 09:43:06 -05:00
ui - > lineEdit_GpgName - > setText ( tr ( " Unknown real name " ) ) ;
2012-11-06 14:18:56 -05:00
}
else
{
2014-12-24 09:43:06 -05:00
ui - > lineEdit_GpgName - > setText ( tr ( " Anonymous Id " ) ) ;
2012-11-06 14:18:56 -05:00
}
2012-06-07 13:11:57 -04:00
}
2012-11-06 14:18:56 -05:00
2014-09-24 16:13:19 -04:00
if ( data . mPgpId . isNull ( ) )
{
2014-12-24 09:43:06 -05:00
ui - > lineEdit_GpgId - > hide ( ) ;
ui - > lineEdit_GpgName - > hide ( ) ;
ui - > PgpId_LB - > hide ( ) ;
ui - > PgpName_LB - > hide ( ) ;
2014-09-24 16:13:19 -04:00
}
else
{
2014-12-24 09:43:06 -05:00
ui - > lineEdit_GpgId - > show ( ) ;
ui - > lineEdit_GpgName - > show ( ) ;
ui - > PgpId_LB - > show ( ) ;
ui - > PgpName_LB - > show ( ) ;
2014-09-24 16:13:19 -04:00
}
2015-02-05 15:37:24 -05:00
bool isLinkedToOwnPgpId = ( data . mPgpKnown & & ( data . mPgpId = = ownPgpId ) ) ;
bool isOwnId = ( data . mMeta . mSubscribeFlags & GXS_SERV : : GROUP_SUBSCRIBE_ADMIN ) ;
if ( isOwnId )
if ( isLinkedToOwnPgpId )
ui - > lineEdit_Type - > setText ( tr ( " Identity owned by you, linked to your Retroshare node " ) ) ;
else
ui - > lineEdit_Type - > setText ( tr ( " Anonymous identity, owned by you " ) ) ;
else if ( data . mMeta . mGroupFlags & RSGXSID_GROUPFLAG_REALID )
{
if ( data . mPgpKnown )
if ( rsPeers - > isGPGAccepted ( data . mPgpId ) )
ui - > lineEdit_Type - > setText ( tr ( " Linked to a friend Retroshare node " ) ) ;
else
ui - > lineEdit_Type - > setText ( tr ( " Linked to a known Retroshare node " ) ) ;
else
ui - > lineEdit_Type - > setText ( tr ( " Linked to unknown Retroshare node " ) ) ;
}
else
ui - > lineEdit_Type - > setText ( tr ( " Anonymous identity " ) ) ;
2012-11-06 14:18:56 -05:00
if ( isOwnId )
2012-06-07 13:11:57 -04:00
{
2015-12-22 18:29:27 -05:00
mStateHelper - > setWidgetEnabled ( ui - > ownOpinion_CB , false ) ;
2015-01-25 09:14:03 -05:00
ui - > editIdentity - > setEnabled ( true ) ;
ui - > removeIdentity - > setEnabled ( true ) ;
2014-12-24 09:43:06 -05:00
ui - > chatIdentity - > setEnabled ( false ) ;
2015-12-24 08:31:52 -05:00
ui - > inviteButton - > setEnabled ( false ) ;
2012-06-07 13:11:57 -04:00
}
else
{
2013-07-10 17:57:23 -04:00
// No Reputation yet!
2015-12-22 18:29:27 -05:00
mStateHelper - > setWidgetEnabled ( ui - > ownOpinion_CB , true ) ;
2015-01-25 09:14:03 -05:00
ui - > editIdentity - > setEnabled ( false ) ;
ui - > removeIdentity - > setEnabled ( false ) ;
2014-12-24 09:43:06 -05:00
ui - > chatIdentity - > setEnabled ( true ) ;
2015-12-24 08:31:52 -05:00
ui - > inviteButton - > setEnabled ( true ) ;
2012-06-07 13:11:57 -04:00
}
2013-06-04 17:00:43 -04:00
/* now fill in the reputation information */
2015-12-22 18:29:27 -05:00
# ifdef SUSPENDED
2013-06-04 17:00:43 -04:00
if ( data . mPgpKnown )
{
2015-06-01 14:46:33 -04:00
ui - > line_RatingImplicit - > setText ( tr ( " +50 Known PGP " ) ) ;
2013-06-04 17:00:43 -04:00
}
else if ( data . mMeta . mGroupFlags & RSGXSID_GROUPFLAG_REALID )
{
2015-06-01 14:46:33 -04:00
ui - > line_RatingImplicit - > setText ( tr ( " +10 UnKnown PGP " ) ) ;
2013-06-04 17:00:43 -04:00
}
2013-07-11 04:14:38 -04:00
else
2013-06-04 17:00:43 -04:00
{
2015-06-01 14:46:33 -04:00
ui - > line_RatingImplicit - > setText ( tr ( " +5 Anon Id " ) ) ;
2013-06-04 17:00:43 -04:00
}
2014-02-19 06:11:06 -05:00
{
QString rating = QString : : number ( data . mReputation . mIdScore ) ;
2014-12-24 09:43:06 -05:00
ui - > line_RatingImplicit - > setText ( rating ) ;
2014-02-19 06:11:06 -05:00
}
2015-12-22 18:29:27 -05:00
# endif
2014-02-19 06:11:06 -05:00
2015-12-22 18:29:27 -05:00
RsReputations : : ReputationInfo info ;
rsReputations - > getReputationInfo ( RsGxsId ( data . mMeta . mGroupId ) , info ) ;
ui - > neighborNodesOpinion_TF - > setText ( QString : : number ( info . mFriendAverage - 1.0f ) ) ;
ui - > overallOpinion_TF - > setText ( QString : : number ( info . mOverallReputationScore - 1.0f ) + " ( " +
( ( info . mAssessment = = RsReputations : : ASSESSMENT_OK ) ? tr ( " OK " ) : tr ( " Banned " ) ) + " ) " ) ;
switch ( info . mOwnOpinion )
2014-02-19 06:11:06 -05:00
{
2015-12-22 18:29:27 -05:00
case RsReputations : : OPINION_NEGATIVE : ui - > ownOpinion_CB - > setCurrentIndex ( 0 ) ; break ;
case RsReputations : : OPINION_NEUTRAL : ui - > ownOpinion_CB - > setCurrentIndex ( 1 ) ; break ;
case RsReputations : : OPINION_POSITIVE : ui - > ownOpinion_CB - > setCurrentIndex ( 2 ) ; break ;
default :
std : : cerr < < " Unexpected value in own opinion: " < < info . mOwnOpinion < < std : : endl ;
2014-02-19 06:11:06 -05:00
}
}
void IdDialog : : modifyReputation ( )
{
2014-10-25 09:16:47 -04:00
# ifdef ID_DEBUG
2014-02-19 06:11:06 -05:00
std : : cerr < < " IdDialog::modifyReputation() " ;
std : : cerr < < std : : endl ;
2014-10-25 09:16:47 -04:00
# endif
2014-02-19 06:11:06 -05:00
2014-12-24 09:43:06 -05:00
RsGxsId id ( ui - > lineEdit_KeyId - > text ( ) . toStdString ( ) ) ;
2015-12-22 18:29:27 -05:00
RsReputations : : Opinion op ;
2014-02-19 06:11:06 -05:00
2015-12-22 18:29:27 -05:00
switch ( ui - > ownOpinion_CB - > currentIndex ( ) )
{
case 0 : op = RsReputations : : OPINION_NEGATIVE ; break ;
case 1 : op = RsReputations : : OPINION_NEUTRAL ; break ;
case 2 : op = RsReputations : : OPINION_POSITIVE ; break ;
default :
std : : cerr < < " Wrong value from opinion combobox. Bug?? " < < std : : endl ;
}
rsReputations - > setOwnOpinion ( id , op ) ;
2014-02-19 06:11:06 -05:00
2014-10-25 09:16:47 -04:00
# ifdef ID_DEBUG
2014-02-19 06:11:06 -05:00
std : : cerr < < " IdDialog::modifyReputation() ID: " < < id < < " Mod: " < < mod ;
std : : cerr < < std : : endl ;
2014-10-25 09:16:47 -04:00
# endif
2014-02-19 06:11:06 -05:00
2015-12-22 18:29:27 -05:00
# ifdef SUSPENDED
// Cyril: apparently the old reputation system was in used here. It's based on GXS data exchange, and probably not
// very efficient because of this.
2014-02-19 06:11:06 -05:00
uint32_t token ;
2015-12-22 18:29:27 -05:00
if ( ! rsIdentity - > submitOpinion ( token , id , false , op ) )
2014-02-19 06:11:06 -05:00
{
2014-10-25 09:16:47 -04:00
# ifdef ID_DEBUG
2014-02-19 06:11:06 -05:00
std : : cerr < < " IdDialog::modifyReputation() Error submitting Opinion " ;
std : : cerr < < std : : endl ;
2014-10-25 09:16:47 -04:00
# endif
2014-02-19 06:11:06 -05:00
}
2015-12-22 18:29:27 -05:00
# endif
2014-02-19 06:11:06 -05:00
2014-10-25 09:16:47 -04:00
# ifdef ID_DEBUG
2014-02-19 06:11:06 -05:00
std : : cerr < < " IdDialog::modifyReputation() queuingRequest(), token: " < < token ;
std : : cerr < < std : : endl ;
2014-10-25 09:16:47 -04:00
# endif
2014-02-19 06:11:06 -05:00
// trigger refresh when finished.
// basic / anstype are not needed.
2015-12-22 18:29:27 -05:00
requestIdDetails ( ) ;
requestIdList ( ) ;
2014-02-19 06:11:06 -05:00
return ;
2012-02-13 13:43:15 -05:00
}
2014-02-19 06:11:06 -05:00
2014-12-24 09:43:06 -05:00
void IdDialog : : updateDisplay ( bool complete )
2012-02-13 13:43:15 -05:00
{
2013-07-14 14:48:40 -04:00
/* Update identity list */
2014-12-24 09:43:06 -05:00
if ( complete ) {
/* Fill complete */
requestIdList ( ) ;
requestIdDetails ( ) ;
requestRepList ( ) ;
return ;
}
std : : list < RsGxsGroupId > grpIds ;
getAllGrpIds ( grpIds ) ;
if ( ! getGrpIds ( ) . empty ( ) ) {
requestIdList ( ) ;
if ( ! mId . isNull ( ) & & std : : find ( grpIds . begin ( ) , grpIds . end ( ) , mId ) ! = grpIds . end ( ) ) {
requestIdDetails ( ) ;
requestRepList ( ) ;
}
}
2012-02-13 13:43:15 -05:00
}
2013-07-10 17:57:23 -04:00
void IdDialog : : addIdentity ( )
2012-02-13 13:43:15 -05:00
{
2013-07-10 17:57:23 -04:00
IdEditDialog dlg ( this ) ;
dlg . setupNewId ( false ) ;
dlg . exec ( ) ;
2014-04-14 11:37:06 -04:00
}
2012-02-13 13:43:15 -05:00
2014-05-06 13:15:20 -04:00
void IdDialog : : removeIdentity ( )
{
2015-08-11 10:01:43 -04:00
QTreeWidgetItem * item = ui - > idTreeWidget - > currentItem ( ) ;
2014-05-06 13:15:20 -04:00
if ( ! item )
{
2014-10-25 09:16:47 -04:00
# ifdef ID_DEBUG
2014-05-06 13:15:20 -04:00
std : : cerr < < " IdDialog::editIdentity() Invalid item " ;
std : : cerr < < std : : endl ;
2014-10-25 09:16:47 -04:00
# endif
2014-05-06 13:15:20 -04:00
return ;
}
2015-06-12 04:27:26 -04:00
if ( ( QMessageBox : : question ( this , tr ( " Really delete? " ) , tr ( " Do you really want to delete this identity? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : No ) ) = = QMessageBox : : Yes )
2014-12-24 09:43:06 -05:00
{
std : : string keyId = item - > text ( RSID_COL_KEYID ) . toStdString ( ) ;
2014-05-06 13:15:20 -04:00
2014-12-24 09:43:06 -05:00
uint32_t dummyToken = 0 ;
RsGxsIdGroup group ;
group . mMeta . mGroupId = RsGxsGroupId ( keyId ) ;
rsIdentity - > deleteIdentity ( dummyToken , group ) ;
}
2014-05-06 13:15:20 -04:00
}
2013-07-10 17:57:23 -04:00
void IdDialog : : editIdentity ( )
2012-02-13 13:43:15 -05:00
{
2015-08-11 10:01:43 -04:00
QTreeWidgetItem * item = ui - > idTreeWidget - > currentItem ( ) ;
2012-02-13 13:43:15 -05:00
if ( ! item )
{
2014-10-25 09:16:47 -04:00
# ifdef ID_DEBUG
2013-07-10 17:57:23 -04:00
std : : cerr < < " IdDialog::editIdentity() Invalid item " ;
2012-02-13 13:43:15 -05:00
std : : cerr < < std : : endl ;
2014-10-25 09:16:47 -04:00
# endif
2012-02-13 13:43:15 -05:00
return ;
}
2015-02-10 07:55:16 -05:00
RsGxsGroupId keyId = RsGxsGroupId ( item - > text ( RSID_COL_KEYID ) . toStdString ( ) ) ;
if ( keyId . isNull ( ) ) {
return ;
}
2012-02-13 13:43:15 -05:00
2013-07-10 17:57:23 -04:00
IdEditDialog dlg ( this ) ;
dlg . setupExistingId ( keyId ) ;
dlg . exec ( ) ;
2014-04-14 11:37:06 -04:00
}
2012-02-13 13:43:15 -05:00
2013-07-10 17:57:23 -04:00
void IdDialog : : filterIds ( )
2012-02-13 13:43:15 -05:00
{
2014-12-24 09:43:06 -05:00
int filterColumn = ui - > filterLineEdit - > currentFilter ( ) ;
QString text = ui - > filterLineEdit - > text ( ) ;
2012-02-13 13:43:15 -05:00
2015-08-11 10:01:43 -04:00
ui - > idTreeWidget - > filterItems ( filterColumn , text ) ;
2012-02-13 13:43:15 -05:00
}
2014-12-24 09:43:06 -05:00
void IdDialog : : requestRepList ( )
2012-02-13 13:43:15 -05:00
{
2014-12-24 09:43:06 -05:00
// Removing this for the moment.
return ;
2013-07-10 17:57:23 -04:00
mStateHelper - > setLoading ( IDDIALOG_REPLIST , true ) ;
2012-02-13 13:43:15 -05:00
2013-07-10 17:57:23 -04:00
mIdQueue - > cancelActiveRequestTokens ( IDDIALOG_REPLIST ) ;
2012-02-13 13:43:15 -05:00
2013-07-11 04:14:38 -04:00
std : : list < RsGxsGroupId > groupIds ;
2014-12-24 09:43:06 -05:00
groupIds . push_back ( mId ) ;
2013-06-04 17:00:43 -04:00
2013-07-11 04:14:38 -04:00
RsTokReqOptions opts ;
opts . mReqType = GXS_REQUEST_TYPE_MSG_DATA ;
2013-06-04 17:00:43 -04:00
2013-07-11 04:14:38 -04:00
uint32_t token ;
mIdQueue - > requestMsgInfo ( token , RS_TOKREQ_ANSTYPE_DATA , opts , groupIds , IDDIALOG_REPLIST ) ;
2013-06-04 17:00:43 -04:00
}
void IdDialog : : insertRepList ( uint32_t token )
{
2014-05-06 13:15:20 -04:00
Q_UNUSED ( token )
2013-07-10 17:57:23 -04:00
mStateHelper - > setLoading ( IDDIALOG_REPLIST , false ) ;
2014-02-19 06:11:06 -05:00
mStateHelper - > setActive ( IDDIALOG_REPLIST , true ) ;
2013-06-04 17:00:43 -04:00
}
2015-09-06 23:53:21 -04:00
void IdDialog : : loadRequest ( const TokenQueue * queue , const TokenRequest & req )
2012-02-13 13:43:15 -05:00
{
2014-10-25 09:16:47 -04:00
# ifdef ID_DEBUG
2013-07-11 04:14:38 -04:00
std : : cerr < < " IdDialog::loadRequest() UserType: " < < req . mUserType ;
std : : cerr < < std : : endl ;
2014-10-25 09:16:47 -04:00
# endif
2013-07-11 04:14:38 -04:00
2015-09-06 23:53:21 -04:00
if ( queue = = mIdQueue )
{
switch ( req . mUserType )
{
case IDDIALOG_IDLIST :
insertIdList ( req . mToken ) ;
break ;
case IDDIALOG_IDDETAILS :
insertIdDetails ( req . mToken ) ;
break ;
case IDDIALOG_REPLIST :
insertRepList ( req . mToken ) ;
break ;
case IDDIALOG_REFRESH :
// replaced by RsGxsUpdateBroadcastPage
// updateDisplay(true);
break ;
default :
std : : cerr < < " IdDialog::loadRequest() ERROR " ;
std : : cerr < < std : : endl ;
break ;
}
}
if ( queue = = mCircleQueue )
{
std : : cerr < < " CirclesDialog::loadRequest() UserType: " < < req . mUserType ;
std : : cerr < < std : : endl ;
/* now switch on req */
switch ( req . mUserType )
{
case CIRCLESDIALOG_GROUPMETA :
loadCircleGroupMeta ( req . mToken ) ;
break ;
default :
std : : cerr < < " CirclesDialog::loadRequest() ERROR: INVALID TYPE " ;
std : : cerr < < std : : endl ;
break ;
}
}
2012-02-13 13:43:15 -05:00
}
2014-05-03 13:56:12 -04:00
void IdDialog : : IdListCustomPopupMenu ( QPoint )
{
2016-01-16 20:44:52 -05:00
QMenu contextMnu ( this ) ;
2014-05-03 13:56:12 -04:00
2015-02-09 20:14:44 -05:00
2016-01-16 20:44:52 -05:00
std : : list < RsGxsId > own_identities ;
rsIdentity - > getOwnIds ( own_identities ) ;
2014-11-18 10:55:31 -05:00
2016-01-16 20:44:52 -05:00
// make some stats about what's selected. If the same value is used for all selected items, it can be switched.
2015-01-23 11:35:06 -05:00
2016-01-16 20:44:52 -05:00
QList < QTreeWidgetItem * > selected_items = ui - > idTreeWidget - > selectedItems ( ) ;
2014-11-20 18:18:14 -05:00
2016-01-16 20:44:52 -05:00
bool root_node_present = false ;
bool one_item_owned_by_you = false ;
uint32_t n_positive_reputations = 0 ;
uint32_t n_negative_reputations = 0 ;
uint32_t n_neutral_reputations = 0 ;
uint32_t n_is_a_contact = 0 ;
uint32_t n_is_not_a_contact = 0 ;
uint32_t n_selected_items = 0 ;
2014-11-18 10:55:31 -05:00
2016-01-16 20:44:52 -05:00
for ( QList < QTreeWidgetItem * > : : const_iterator it ( selected_items . begin ( ) ) ; it ! = selected_items . end ( ) ; + + it )
{
if ( * it = = allItem | | * it = = contactsItem )
{
root_node_present = true ;
continue ;
}
2014-11-18 10:55:31 -05:00
2016-01-16 20:44:52 -05:00
uint32_t item_flags = ( * it ) - > data ( RSID_COL_KEYID , Qt : : UserRole ) . toUInt ( ) ;
2015-01-25 17:09:12 -05:00
2016-01-16 20:44:52 -05:00
if ( item_flags & RSID_FILTER_OWNED_BY_YOU )
one_item_owned_by_you = true ;
std : : cerr < < " item flags = " < < item_flags < < std : : endl ;
RsGxsId keyId ( ( * it ) - > text ( RSID_COL_KEYID ) . toStdString ( ) ) ;
2014-11-18 10:55:31 -05:00
2016-01-16 20:44:52 -05:00
RsReputations : : ReputationInfo info ;
rsReputations - > getReputationInfo ( keyId , info ) ;
2015-02-05 15:37:24 -05:00
2016-01-16 20:44:52 -05:00
switch ( info . mOwnOpinion )
{
case RsReputations : : OPINION_NEGATIVE : + + n_negative_reputations ;
break ;
case RsReputations : : OPINION_POSITIVE : + + n_positive_reputations ;
break ;
case RsReputations : : OPINION_NEUTRAL : + + n_neutral_reputations ;
break ;
}
2015-12-22 18:29:27 -05:00
2016-01-16 20:44:52 -05:00
+ + n_selected_items ;
2015-12-22 18:29:27 -05:00
2016-01-16 20:44:52 -05:00
if ( rsIdentity - > isARegularContact ( keyId ) )
+ + n_is_a_contact ;
else
+ + n_is_not_a_contact ;
}
2015-12-22 18:29:27 -05:00
2016-01-16 20:44:52 -05:00
if ( root_node_present ) // don't show menu if some of the root nodes are present
return ;
2015-12-22 18:29:27 -05:00
2016-01-16 20:44:52 -05:00
if ( ! one_item_owned_by_you )
{
if ( n_selected_items = = 1 ) // if only one item is selected, allow to chat with this item
if ( own_identities . size ( ) < = 1 )
{
QAction * action = contextMnu . addAction ( QIcon ( " :/images/chat_24.png " ) , tr ( " Chat with this person " ) , this , SLOT ( chatIdentity ( ) ) ) ;
if ( own_identities . empty ( ) )
action - > setEnabled ( false ) ;
else
action - > setData ( QString : : fromStdString ( ( own_identities . front ( ) ) . toStdString ( ) ) ) ;
}
else
{
QMenu * mnu = contextMnu . addMenu ( QIcon ( " :/images/chat_24.png " ) , tr ( " Chat with this person as... " ) ) ;
for ( std : : list < RsGxsId > : : const_iterator it = own_identities . begin ( ) ; it ! = own_identities . end ( ) ; + + it )
{
RsIdentityDetails idd ;
rsIdentity - > getIdDetails ( * it , idd ) ;
QPixmap pixmap ;
if ( idd . mAvatar . mSize = = 0 | | ! pixmap . loadFromData ( idd . mAvatar . mData , idd . mAvatar . mSize , " PNG " ) )
pixmap = QPixmap : : fromImage ( GxsIdDetails : : makeDefaultIcon ( * it ) ) ;
QAction * action = mnu - > addAction ( QIcon ( pixmap ) , QString ( " %1 (%2) " ) . arg ( QString : : fromUtf8 ( idd . mNickname . c_str ( ) ) , QString : : fromStdString ( ( * it ) . toStdString ( ) ) ) , this , SLOT ( chatIdentity ( ) ) ) ;
action - > setData ( QString : : fromStdString ( ( * it ) . toStdString ( ) ) ) ;
}
}
// always allow to send messages
contextMnu . addAction ( QIcon ( " :/images/mail_new.png " ) , tr ( " Send message " ) , this , SLOT ( sendMsg ( ) ) ) ;
contextMnu . addSeparator ( ) ;
if ( n_is_a_contact = = 0 )
contextMnu . addAction ( QIcon ( ) , tr ( " Add to Contacts " ) , this , SLOT ( addtoContacts ( ) ) ) ;
if ( n_is_not_a_contact = = 0 )
contextMnu . addAction ( QIcon ( " :/images/cancel.png " ) , tr ( " Remove from Contacts " ) , this , SLOT ( removefromContacts ( ) ) ) ;
2015-12-22 18:29:27 -05:00
2016-01-16 20:44:52 -05:00
contextMnu . addSeparator ( ) ;
2015-12-22 18:29:27 -05:00
2016-01-16 20:44:52 -05:00
if ( n_positive_reputations = = 0 ) // only unban when all items are banned
contextMnu . addAction ( QIcon ( ) , tr ( " Set positive opinion " ) , this , SLOT ( positivePerson ( ) ) ) ;
2015-12-22 18:29:27 -05:00
2016-01-16 20:44:52 -05:00
if ( n_neutral_reputations = = 0 ) // only unban when all items are banned
contextMnu . addAction ( QIcon ( ) , tr ( " Set neutral opinion " ) , this , SLOT ( neutralPerson ( ) ) ) ;
if ( n_negative_reputations = = 0 )
contextMnu . addAction ( QIcon ( " :/images/denied16.png " ) , tr ( " Set negative opinion " ) , this , SLOT ( negativePerson ( ) ) ) ;
}
2015-02-05 15:37:24 -05:00
2016-01-16 20:44:52 -05:00
if ( one_item_owned_by_you & & n_selected_items = = 1 )
{
contextMnu . addSeparator ( ) ;
2015-01-23 11:35:06 -05:00
2016-01-16 20:44:52 -05:00
contextMnu . addAction ( ui - > editIdentity ) ;
contextMnu . addAction ( ui - > removeIdentity ) ;
}
2015-02-07 15:24:27 -05:00
2016-01-16 20:44:52 -05:00
contextMnu . addSeparator ( ) ;
contextMnu . exec ( QCursor : : pos ( ) ) ;
2014-05-06 13:15:20 -04:00
}
2014-06-12 06:28:23 -04:00
void IdDialog : : chatIdentity ( )
{
2015-08-11 10:01:43 -04:00
QTreeWidgetItem * item = ui - > idTreeWidget - > currentItem ( ) ;
2014-06-12 06:28:23 -04:00
if ( ! item )
{
std : : cerr < < " IdDialog::editIdentity() Invalid item " ;
std : : cerr < < std : : endl ;
return ;
}
2014-12-24 09:43:06 -05:00
std : : string keyId = item - > text ( RSID_COL_KEYID ) . toStdString ( ) ;
2014-11-18 10:55:31 -05:00
2014-12-24 09:43:06 -05:00
QAction * action = qobject_cast < QAction * > ( QObject : : sender ( ) ) ;
if ( ! action )
return ;
2014-06-12 06:28:23 -04:00
2014-12-24 09:43:06 -05:00
RsGxsId from_gxs_id ( action - > data ( ) . toString ( ) . toStdString ( ) ) ;
uint32_t error_code ;
2015-11-28 14:55:56 -05:00
DistantChatPeerId did ;
2014-06-12 06:28:23 -04:00
2015-11-28 14:55:56 -05:00
if ( ! rsMsgs - > initiateDistantChatConnexion ( RsGxsId ( keyId ) , from_gxs_id , did , error_code ) )
2015-01-23 11:35:06 -05:00
QMessageBox : : information ( NULL , tr ( " Distant chat cannot work " ) , QString ( " %1 %2: %3 " ) . arg ( tr ( " Distant chat refused with this person. " ) ) . arg ( tr ( " Error code " ) ) . arg ( error_code ) ) ;
}
void IdDialog : : sendMsg ( )
{
2016-01-16 20:44:52 -05:00
QList < QTreeWidgetItem * > selected_items = ui - > idTreeWidget - > selectedItems ( ) ;
2015-01-23 11:35:06 -05:00
2016-01-16 20:44:52 -05:00
if ( selected_items . empty ( ) )
return ;
2015-01-23 11:35:06 -05:00
2016-01-16 20:44:52 -05:00
MessageComposer * nMsgDialog = MessageComposer : : newMsg ( ) ;
if ( nMsgDialog = = NULL )
return ;
2015-01-23 11:35:06 -05:00
2016-01-16 20:44:52 -05:00
for ( QList < QTreeWidgetItem * > : : const_iterator it ( selected_items . begin ( ) ) ; it ! = selected_items . end ( ) ; + + it )
{
QTreeWidgetItem * item = * it ;
2015-01-23 11:35:06 -05:00
2016-01-16 20:44:52 -05:00
std : : string keyId = item - > text ( RSID_COL_KEYID ) . toStdString ( ) ;
2015-01-23 11:35:06 -05:00
2016-01-16 20:44:52 -05:00
nMsgDialog - > addRecipient ( MessageComposer : : TO , RsGxsId ( keyId ) ) ;
}
nMsgDialog - > show ( ) ;
nMsgDialog - > activateWindow ( ) ;
2015-12-22 18:29:27 -05:00
2016-01-16 20:44:52 -05:00
/* window will destroy itself! */
2014-06-12 06:28:23 -04:00
}
2015-12-22 18:29:27 -05:00
2015-12-24 08:31:52 -05:00
QString IdDialog : : inviteMessage ( )
{
return tr ( " Hi,<br>I want to be friends with you on RetroShare.<br> " ) ;
}
void IdDialog : : sendInvite ( )
{
QTreeWidgetItem * item = ui - > idTreeWidget - > currentItem ( ) ;
if ( ! item )
{
return ;
}
/* create a message */
MessageComposer * composer = MessageComposer : : newMsg ( ) ;
composer - > setTitleText ( tr ( " You have a friend invite " ) ) ;
RsPeerId ownId = rsPeers - > getOwnId ( ) ;
RetroShareLink link ;
link . createCertificate ( ownId ) ;
std : : string keyId = item - > text ( RSID_COL_KEYID ) . toStdString ( ) ;
QString sMsgText = inviteMessage ( ) ;
sMsgText + = " <br><br> " ;
sMsgText + = tr ( " Respond now: " ) + " <br> " ;
sMsgText + = link . toHtml ( ) + " <br> " ;
sMsgText + = " <br> " ;
sMsgText + = tr ( " Thanks, <br> " ) + QString : : fromUtf8 ( rsPeers - > getGPGName ( rsPeers - > getGPGOwnId ( ) ) . c_str ( ) ) ;
composer - > setMsgText ( sMsgText ) ;
composer - > addRecipient ( MessageComposer : : TO , RsGxsId ( keyId ) ) ;
composer - > show ( ) ;
}
2016-01-16 20:44:52 -05:00
void IdDialog : : negativePerson ( )
2015-12-22 18:29:27 -05:00
{
2016-01-16 20:44:52 -05:00
QList < QTreeWidgetItem * > selected_items = ui - > idTreeWidget - > selectedItems ( ) ;
for ( QList < QTreeWidgetItem * > : : const_iterator it ( selected_items . begin ( ) ) ; it ! = selected_items . end ( ) ; + + it )
{
QTreeWidgetItem * item = * it ;
2015-12-22 18:29:27 -05:00
std : : string Id = item - > text ( RSID_COL_KEYID ) . toStdString ( ) ;
rsReputations - > setOwnOpinion ( RsGxsId ( Id ) , RsReputations : : OPINION_NEGATIVE ) ;
2016-01-16 20:44:52 -05:00
}
2015-12-22 18:29:27 -05:00
requestIdDetails ( ) ;
requestIdList ( ) ;
}
2016-01-16 20:44:52 -05:00
void IdDialog : : neutralPerson ( )
2015-12-22 18:29:27 -05:00
{
2016-01-16 20:44:52 -05:00
QList < QTreeWidgetItem * > selected_items = ui - > idTreeWidget - > selectedItems ( ) ;
for ( QList < QTreeWidgetItem * > : : const_iterator it ( selected_items . begin ( ) ) ; it ! = selected_items . end ( ) ; + + it )
{
QTreeWidgetItem * item = * it ;
std : : string Id = item - > text ( RSID_COL_KEYID ) . toStdString ( ) ;
rsReputations - > setOwnOpinion ( RsGxsId ( Id ) , RsReputations : : OPINION_NEUTRAL ) ;
}
requestIdDetails ( ) ;
requestIdList ( ) ;
}
void IdDialog : : positivePerson ( )
{
QList < QTreeWidgetItem * > selected_items = ui - > idTreeWidget - > selectedItems ( ) ;
for ( QList < QTreeWidgetItem * > : : const_iterator it ( selected_items . begin ( ) ) ; it ! = selected_items . end ( ) ; + + it )
{
QTreeWidgetItem * item = * it ;
2015-12-22 18:29:27 -05:00
std : : string Id = item - > text ( RSID_COL_KEYID ) . toStdString ( ) ;
rsReputations - > setOwnOpinion ( RsGxsId ( Id ) , RsReputations : : OPINION_POSITIVE ) ;
2016-01-16 20:44:52 -05:00
}
2015-12-22 18:29:27 -05:00
requestIdDetails ( ) ;
requestIdList ( ) ;
}
void IdDialog : : addtoContacts ( )
{
2016-01-16 20:44:52 -05:00
QList < QTreeWidgetItem * > selected_items = ui - > idTreeWidget - > selectedItems ( ) ;
for ( QList < QTreeWidgetItem * > : : const_iterator it ( selected_items . begin ( ) ) ; it ! = selected_items . end ( ) ; + + it )
{
QTreeWidgetItem * item = * it ;
2015-12-22 18:29:27 -05:00
std : : string Id = item - > text ( RSID_COL_KEYID ) . toStdString ( ) ;
rsIdentity - > setAsRegularContact ( RsGxsId ( Id ) , true ) ;
2016-01-16 20:44:52 -05:00
}
2015-12-22 18:29:27 -05:00
requestIdList ( ) ;
}
void IdDialog : : removefromContacts ( )
{
2016-01-16 20:44:52 -05:00
QList < QTreeWidgetItem * > selected_items = ui - > idTreeWidget - > selectedItems ( ) ;
for ( QList < QTreeWidgetItem * > : : const_iterator it ( selected_items . begin ( ) ) ; it ! = selected_items . end ( ) ; + + it )
{
QTreeWidgetItem * item = * it ;
2015-12-22 18:29:27 -05:00
std : : string Id = item - > text ( RSID_COL_KEYID ) . toStdString ( ) ;
rsIdentity - > setAsRegularContact ( RsGxsId ( Id ) , false ) ;
2016-01-16 20:44:52 -05:00
}
2015-12-22 18:29:27 -05:00
requestIdList ( ) ;
}