2011-10-20 18:48:50 -04:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2011 RetroShare Team
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program 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 General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
* Boston , MA 02110 - 1301 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <algorithm>
# include <QShortcut>
# include <QTimer>
# include <QTreeWidgetItem>
# include <QWidgetAction>
2012-01-17 15:36:36 -05:00
# include <QDateTime>
2015-08-08 14:27:19 -04:00
# include <QPainter>
2015-08-19 13:02:28 -04:00
# include <QtXml>
2011-10-20 18:48:50 -04:00
2015-08-18 17:05:22 -04:00
# include "rsserver/rsaccounts.h"
2011-10-20 18:48:50 -04:00
# include "retroshare/rspeers.h"
# include "GroupDefs.h"
2012-01-17 15:36:36 -05:00
# include "gui/chat/ChatDialog.h"
2013-07-16 18:33:45 -04:00
//#include "gui/chat/CreateLobbyDialog.h"
2011-10-20 18:48:50 -04:00
# include "gui/common/AvatarDefs.h"
2013-07-16 18:33:45 -04:00
2011-10-20 18:48:50 -04:00
# include "gui/connect/ConfCertDialog.h"
2015-05-12 16:30:44 -04:00
# include "gui/connect/PGPKeyDialog.h"
2011-10-20 18:48:50 -04:00
# include "gui/connect/ConnectFriendWizard.h"
# include "gui/groups/CreateGroup.h"
# include "gui/msgs/MessageComposer.h"
# include "gui/notifyqt.h"
# include "gui/RetroShareLink.h"
2012-02-19 10:03:07 -05:00
# include "retroshare-gui/RsAutoUpdatePage.h"
2012-02-13 13:43:15 -05:00
# ifdef UNFINISHED_FD
2011-10-20 18:48:50 -04:00
# include "gui/unfinished/profile/ProfileView.h"
# endif
# include "RSTreeWidgetItem.h"
# include "StatusDefs.h"
# include "util/misc.h"
# include "vmessagebox.h"
2013-10-19 09:25:06 -04:00
# include "util/QtVersion.h"
2015-01-10 08:13:41 -05:00
# include "gui/chat/ChatUserNotify.h"
2013-08-22 03:30:54 -04:00
# include "gui/connect/ConnectProgressDialog.h"
2015-08-19 03:59:14 -04:00
# include "gui/common/ElidedLabel.h"
2013-08-22 03:30:54 -04:00
2011-10-20 18:48:50 -04:00
# include "FriendList.h"
# include "ui_FriendList.h"
/* Images for context menu icons */
# define IMAGE_DENYFRIEND ": / images / denied16.png"
2013-07-16 18:33:45 -04:00
# define IMAGE_REMOVEFRIEND ": / images / remove_user24.png"
2012-05-07 10:43:25 -04:00
# define IMAGE_EXPORTFRIEND ": / images / user / friend_suggestion16.png"
2011-10-20 18:48:50 -04:00
# define IMAGE_ADDFRIEND ": / images / user / add_user16.png"
2013-08-28 19:27:46 -04:00
# define IMAGE_FRIENDINFO ": / images / info16.png"
# define IMAGE_CHAT ": / images / chat_24.png"
2011-10-20 18:48:50 -04:00
# define IMAGE_MSG ": / images / mail_new.png"
# define IMAGE_CONNECT ": / images / connect_friend.png"
# define IMAGE_COPYLINK ": / images / copyrslink.png"
# define IMAGE_GROUP16 ": / images / user / group16.png"
# define IMAGE_EDIT ": / images / edit_16.png"
# define IMAGE_REMOVE ": / images / delete.png"
# define IMAGE_EXPAND ": / images / edit_add24.png"
# define IMAGE_COLLAPSE ": / images / edit_remove24.png"
/* Images for Status icons */
# define IMAGE_AVAILABLE ": / images / user / identityavaiblecyan24.png"
# define IMAGE_PASTELINK ": / images / pasterslink.png"
# define IMAGE_GROUP24 ": / images / user / group24.png"
# define COLUMN_DATA 0 // column for storing the userdata id
2015-08-08 14:27:19 -04:00
# define ROLE_ID Qt::UserRole
# define ROLE_STANDARD Qt::UserRole + 1
# define ROLE_SORT_GROUP Qt::UserRole + 2
# define ROLE_SORT_STANDARD_GROUP Qt::UserRole + 3
# define ROLE_SORT_NAME Qt::UserRole + 4
# define ROLE_SORT_STATE Qt::UserRole + 5
2015-08-26 13:26:20 -04:00
# define ROLE_FILTER Qt::UserRole + 6
2011-10-20 18:48:50 -04:00
# define TYPE_GPG 0
# define TYPE_SSL 1
# define TYPE_GROUP 2
// states for sorting (equal values are possible)
// used in BuildSortString - state + name
# define PEER_STATE_ONLINE 1
# define PEER_STATE_BUSY 2
# define PEER_STATE_AWAY 3
# define PEER_STATE_AVAILABLE 4
# define PEER_STATE_INACTIVE 5
# define PEER_STATE_OFFLINE 6
/******
* # define FRIENDS_DEBUG 1
* * * * */
2015-08-19 03:59:14 -04:00
Q_DECLARE_METATYPE ( ElidedLabel * )
2011-10-20 18:48:50 -04:00
FriendList : : FriendList ( QWidget * parent ) :
RsAutoUpdatePage ( 1500 , parent ) ,
ui ( new Ui : : FriendList ) ,
2015-08-08 14:27:19 -04:00
mCompareRole ( new RSTreeWidgetItemCompareRole ) ,
2011-11-11 20:26:26 -05:00
mShowGroups ( true ) ,
2015-08-08 14:27:19 -04:00
mShowState ( false ) ,
2011-10-20 18:48:50 -04:00
mHideUnconnected ( false ) ,
2016-07-05 23:49:43 -04:00
groupsHasChanged ( false )
2011-10-20 18:48:50 -04:00
{
ui - > setupUi ( this ) ;
2015-05-09 17:43:01 -04:00
connect ( ui - > peerTreeWidget , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( peerTreeWidgetCustomPopupMenu ( ) ) ) ;
2011-10-20 18:48:50 -04:00
connect ( ui - > peerTreeWidget , SIGNAL ( itemDoubleClicked ( QTreeWidgetItem * , int ) ) , this , SLOT ( chatfriend ( QTreeWidgetItem * ) ) ) ;
2017-03-01 15:18:16 -05:00
connect ( ui - > peerTreeWidget , SIGNAL ( itemExpanded ( QTreeWidgetItem * ) ) , this , SLOT ( expandItem ( QTreeWidgetItem * ) ) ) ;
connect ( ui - > peerTreeWidget , SIGNAL ( itemCollapsed ( QTreeWidgetItem * ) ) , this , SLOT ( collapseItem ( QTreeWidgetItem * ) ) ) ;
2011-10-20 18:48:50 -04:00
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( groupsChanged ( int ) ) , this , SLOT ( groupsChanged ( ) ) ) ;
connect ( NotifyQt : : getInstance ( ) , SIGNAL ( friendsChanged ( ) ) , this , SLOT ( insertPeers ( ) ) ) ;
2011-11-11 20:26:26 -05:00
connect ( ui - > actionHideOfflineFriends , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setHideUnconnected ( bool ) ) ) ;
2015-08-08 14:27:19 -04:00
connect ( ui - > actionShowState , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowState ( bool ) ) ) ;
2011-11-11 20:26:26 -05:00
connect ( ui - > actionShowGroups , SIGNAL ( triggered ( bool ) ) , this , SLOT ( setShowGroups ( bool ) ) ) ;
2015-08-18 17:05:22 -04:00
connect ( ui - > actionExportFriendlist , SIGNAL ( triggered ( ) ) , this , SLOT ( exportFriendlistClicked ( ) ) ) ;
connect ( ui - > actionImportFriendlist , SIGNAL ( triggered ( ) ) , this , SLOT ( importFriendlistClicked ( ) ) ) ;
2011-11-11 20:26:26 -05:00
2013-08-30 08:24:39 -04:00
connect ( ui - > filterLineEdit , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( filterItems ( QString ) ) ) ;
ui - > filterLineEdit - > setPlaceholderText ( tr ( " Search " ) ) ;
ui - > filterLineEdit - > showFilterIcon ( ) ;
2017-07-17 08:10:26 -04:00
/* Add filter actions */
QTreeWidgetItem * headerItem = ui - > peerTreeWidget - > headerItem ( ) ;
QString headerText = headerItem - > text ( COLUMN_NAME ) ;
ui - > filterLineEdit - > addFilter ( QIcon ( ) , headerText , COLUMN_NAME , QString ( " %1 %2 " ) . arg ( tr ( " Search " ) , headerText ) ) ;
ui - > filterLineEdit - > addFilter ( QIcon ( ) , tr ( " ID " ) , COLUMN_ID , tr ( " Search ID " ) ) ;
2015-08-21 18:57:26 -04:00
mActionSortByState = new QAction ( tr ( " Sort by state " ) , this ) ;
mActionSortByState - > setCheckable ( true ) ;
connect ( mActionSortByState , SIGNAL ( toggled ( bool ) ) , this , SLOT ( sortByState ( bool ) ) ) ;
2016-08-05 12:15:21 -04:00
ui - > peerTreeWidget - > addContextMenuAction ( mActionSortByState ) ;
2015-08-21 18:57:26 -04:00
2015-08-08 14:27:19 -04:00
/* Set sort */
2015-08-21 18:57:26 -04:00
sortByColumn ( COLUMN_NAME , Qt : : AscendingOrder ) ;
sortByState ( false ) ;
2011-10-20 18:48:50 -04:00
// workaround for Qt bug, should be solved in next Qt release 4.7.0
// http://bugreports.qt.nokia.com/browse/QTBUG-8270
QShortcut * Shortcut = new QShortcut ( QKeySequence ( Qt : : Key_Delete ) , ui - > peerTreeWidget , 0 , 0 , Qt : : WidgetShortcut ) ;
connect ( Shortcut , SIGNAL ( activated ( ) ) , this , SLOT ( removefriend ( ) ) ) ;
2013-08-30 08:24:39 -04:00
2015-07-09 16:53:28 -04:00
/* Initialize tree */
2015-08-08 14:27:19 -04:00
ui - > peerTreeWidget - > enableColumnCustomize ( true ) ;
ui - > peerTreeWidget - > setColumnCustomizable ( COLUMN_NAME , false ) ;
2015-07-09 16:53:28 -04:00
connect ( ui - > peerTreeWidget , SIGNAL ( columnVisibleChanged ( int , bool ) ) , this , SLOT ( peerTreeColumnVisibleChanged ( int , bool ) ) ) ;
2015-08-19 03:59:14 -04:00
connect ( ui - > peerTreeWidget , SIGNAL ( itemCollapsed ( QTreeWidgetItem * ) ) , this , SLOT ( peerTreeItemCollapsedExpanded ( QTreeWidgetItem * ) ) ) ;
connect ( ui - > peerTreeWidget , SIGNAL ( itemExpanded ( QTreeWidgetItem * ) ) , this , SLOT ( peerTreeItemCollapsedExpanded ( QTreeWidgetItem * ) ) ) ;
QFontMetricsF fontMetrics ( ui - > peerTreeWidget - > font ( ) ) ;
2015-07-09 16:53:28 -04:00
2015-08-08 14:27:19 -04:00
/* Set initial column width */
2015-08-19 03:59:14 -04:00
int fontWidth = fontMetrics . width ( " W " ) ;
2015-08-08 14:27:19 -04:00
ui - > peerTreeWidget - > setColumnWidth ( COLUMN_NAME , 22 * fontWidth ) ;
ui - > peerTreeWidget - > setColumnWidth ( COLUMN_LAST_CONTACT , 12 * fontWidth ) ;
ui - > peerTreeWidget - > setColumnWidth ( COLUMN_IP , 15 * fontWidth ) ;
2017-07-17 08:10:26 -04:00
ui - > peerTreeWidget - > setColumnWidth ( COLUMN_ID , 32 * fontWidth ) ;
2015-08-08 14:27:19 -04:00
2015-08-19 03:59:14 -04:00
int avatarHeight = fontMetrics . height ( ) * 3 ;
ui - > peerTreeWidget - > setIconSize ( QSize ( avatarHeight , avatarHeight ) ) ;
2013-08-30 08:24:39 -04:00
/* Initialize display menu */
createDisplayMenu ( ) ;
2011-10-20 18:48:50 -04:00
}
FriendList : : ~ FriendList ( )
{
delete ui ;
2015-08-08 14:27:19 -04:00
delete ( mCompareRole ) ;
2011-10-20 18:48:50 -04:00
}
2013-08-30 08:24:39 -04:00
void FriendList : : addToolButton ( QToolButton * toolButton )
{
if ( ! toolButton ) {
return ;
}
/* Initialize button */
toolButton - > setAutoRaise ( true ) ;
2016-07-30 07:27:23 -04:00
float S = QFontMetricsF ( ui - > filterLineEdit - > font ( ) ) . height ( ) ;
toolButton - > setIconSize ( QSize ( S * 1.5 , S * 1.5 ) ) ;
toolButton - > setFocusPolicy ( Qt : : NoFocus ) ;
2013-08-30 08:24:39 -04:00
ui - > titleBarFrame - > layout ( ) - > addWidget ( toolButton ) ;
}
2015-07-09 16:53:28 -04:00
void FriendList : : processSettings ( bool load )
2011-11-11 20:26:26 -05:00
{
2015-07-09 16:53:28 -04:00
// state of peer tree
2015-08-21 18:57:26 -04:00
ui - > peerTreeWidget - > setSettingsVersion ( 2 ) ;
2015-07-09 16:53:28 -04:00
ui - > peerTreeWidget - > processSettings ( load ) ;
2011-11-11 20:26:26 -05:00
2015-07-09 16:53:28 -04:00
if ( load ) {
2011-11-11 20:26:26 -05:00
// load settings
// ui->peerTreeWidget->header()->doItemsLayout(); // is needed because I added a third column
// restoreState would corrupt the internal sectionCount
// states
setHideUnconnected ( Settings - > value ( " hideUnconnected " , mHideUnconnected ) . toBool ( ) ) ;
2015-08-08 14:27:19 -04:00
setShowState ( Settings - > value ( " showState " , mShowState ) . toBool ( ) ) ;
2011-11-11 20:26:26 -05:00
setShowGroups ( Settings - > value ( " showGroups " , mShowGroups ) . toBool ( ) ) ;
2015-08-08 14:27:19 -04:00
// sort
2015-08-21 18:57:26 -04:00
sortByState ( Settings - > value ( " sortByState " , isSortByState ( ) ) . toBool ( ) ) ;
2015-08-08 14:27:19 -04:00
2011-11-11 20:26:26 -05:00
// open groups
int arrayIndex = Settings - > beginReadArray ( " Groups " ) ;
2014-10-21 18:33:02 -04:00
for ( int index = 0 ; index < arrayIndex ; + + index ) {
2011-11-11 20:26:26 -05:00
Settings - > setArrayIndex ( index ) ;
2016-07-06 22:02:56 -04:00
std : : string gids = Settings - > value ( " open " ) . toString ( ) . toStdString ( ) ;
RsGroupInfo ginfo ;
if ( rsPeers - > getGroupInfoByName ( gids , ginfo ) ) // backward compatibility
addGroupToExpand ( ginfo . id ) ;
else if ( rsPeers - > getGroupInfo ( RsNodeGroupId ( gids ) , ginfo ) ) // backward compatibility
addGroupToExpand ( ginfo . id ) ;
else
std : : cerr < < " (EE) Cannot find group info for openned group \" " < < gids < < " \" " < < std : : endl ;
2011-11-11 20:26:26 -05:00
}
Settings - > endArray ( ) ;
} else {
// save settings
// states
Settings - > setValue ( " hideUnconnected " , mHideUnconnected ) ;
2015-08-08 14:27:19 -04:00
Settings - > setValue ( " showState " , mShowState ) ;
2011-11-11 20:26:26 -05:00
Settings - > setValue ( " showGroups " , mShowGroups ) ;
2015-08-08 14:27:19 -04:00
// sort
2015-08-21 18:57:26 -04:00
Settings - > setValue ( " sortByState " , isSortByState ( ) ) ;
2015-08-08 14:27:19 -04:00
2011-11-11 20:26:26 -05:00
// open groups
Settings - > beginWriteArray ( " Groups " ) ;
int arrayIndex = 0 ;
2016-07-05 23:49:43 -04:00
std : : set < RsNodeGroupId > expandedPeers ;
2011-11-11 20:26:26 -05:00
getExpandedGroups ( expandedPeers ) ;
2016-07-05 23:49:43 -04:00
foreach ( RsNodeGroupId groupId , expandedPeers ) {
2011-11-11 20:26:26 -05:00
Settings - > setArrayIndex ( arrayIndex + + ) ;
2016-07-05 23:49:43 -04:00
Settings - > setValue ( " open " , QString : : fromStdString ( groupId . toStdString ( ) ) ) ;
2011-11-11 20:26:26 -05:00
}
Settings - > endArray ( ) ;
}
}
2012-11-19 11:01:21 -05:00
void FriendList : : changeEvent ( QEvent * e )
{
QWidget : : changeEvent ( e ) ;
switch ( e - > type ( ) ) {
case QEvent : : StyleChange :
insertPeers ( ) ;
break ;
default :
// remove compiler warnings
break ;
}
}
2011-10-20 18:48:50 -04:00
/* Utility Fns */
inline std : : string getRsId ( QTreeWidgetItem * item )
{
return item - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ;
}
/**
* Creates the context popup menu and its submenus ,
* then shows it at the current cursor position .
*/
2015-05-09 17:43:01 -04:00
void FriendList : : peerTreeWidgetCustomPopupMenu ( )
2011-10-20 18:48:50 -04:00
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
2016-08-05 12:15:21 -04:00
QMenu * contextMenu = new QMenu ( this ) ;
2011-10-20 18:48:50 -04:00
2016-08-05 12:15:21 -04:00
QWidget * widget = new QWidget ( contextMenu ) ;
2011-10-20 18:48:50 -04:00
widget - > setStyleSheet ( " .QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;} " ) ;
// create menu header
QHBoxLayout * hbox = new QHBoxLayout ( widget ) ;
hbox - > setMargin ( 0 ) ;
hbox - > setSpacing ( 6 ) ;
QLabel * iconLabel = new QLabel ( widget ) ;
2016-08-05 12:15:21 -04:00
QPixmap pix = QPixmap ( " :/images/user/friends24.png " ) . scaledToHeight ( QFontMetricsF ( iconLabel - > font ( ) ) . height ( ) * 1.5 ) ;
iconLabel - > setPixmap ( pix ) ;
iconLabel - > setMaximumSize ( iconLabel - > frameSize ( ) . height ( ) + pix . height ( ) , pix . width ( ) ) ;
2011-10-20 18:48:50 -04:00
hbox - > addWidget ( iconLabel ) ;
QLabel * textLabel = new QLabel ( " <strong>RetroShare</strong> " , widget ) ;
hbox - > addWidget ( textLabel ) ;
QSpacerItem * spacerItem = new QSpacerItem ( 40 , 20 , QSizePolicy : : Expanding , QSizePolicy : : Minimum ) ;
hbox - > addItem ( spacerItem ) ;
widget - > setLayout ( hbox ) ;
QWidgetAction * widgetAction = new QWidgetAction ( this ) ;
widgetAction - > setDefaultWidget ( widget ) ;
2016-08-05 12:15:21 -04:00
contextMenu - > addAction ( widgetAction ) ;
2011-10-20 18:48:50 -04:00
// create menu entries
2012-01-27 15:53:17 -05:00
if ( c )
{ // if a peer is selected
int type = c - > type ( ) ;
// define header
switch ( type ) {
case TYPE_GROUP :
//this is a GPG key
textLabel - > setText ( " <strong> " + tr ( " Group " ) + " </strong> " ) ;
break ;
case TYPE_GPG :
//this is a GPG key
textLabel - > setText ( " <strong> " + tr ( " Friend " ) + " </strong> " ) ;
break ;
case TYPE_SSL :
//this is a SSL key
2014-12-30 06:11:08 -05:00
textLabel - > setText ( " <strong> " + tr ( " Node " ) + " </strong> " ) ;
2012-01-27 15:53:17 -05:00
break ;
}
2013-07-16 18:33:45 -04:00
// QMenu *lobbyMenu = NULL;
2012-01-27 15:53:17 -05:00
2018-01-15 15:42:58 -05:00
switch ( type )
{
2012-01-27 15:53:17 -05:00
case TYPE_GROUP :
{
bool standard = c - > data ( COLUMN_DATA , ROLE_STANDARD ) . toBool ( ) ;
2016-08-05 12:15:21 -04:00
contextMenu - > addAction ( QIcon ( IMAGE_MSG ) , tr ( " Send message to whole group " ) , this , SLOT ( msgfriend ( ) ) ) ;
contextMenu - > addSeparator ( ) ;
contextMenu - > addAction ( QIcon ( IMAGE_EDIT ) , tr ( " Edit Group " ) , this , SLOT ( editGroup ( ) ) ) ;
2012-01-27 15:53:17 -05:00
2016-08-05 12:15:21 -04:00
QAction * action = contextMenu - > addAction ( QIcon ( IMAGE_REMOVE ) , tr ( " Remove Group " ) , this , SLOT ( removeGroup ( ) ) ) ;
2012-01-27 15:53:17 -05:00
action - > setDisabled ( standard ) ;
}
break ;
case TYPE_GPG :
2015-05-09 17:43:01 -04:00
{
2016-08-05 12:15:21 -04:00
contextMenu - > addAction ( QIcon ( IMAGE_CHAT ) , tr ( " Chat " ) , this , SLOT ( chatfriendproxy ( ) ) ) ;
contextMenu - > addAction ( QIcon ( IMAGE_MSG ) , tr ( " Send message " ) , this , SLOT ( msgfriend ( ) ) ) ;
2015-05-29 06:07:12 -04:00
2016-08-05 12:15:21 -04:00
contextMenu - > addSeparator ( ) ;
2015-05-29 06:07:12 -04:00
2017-02-28 17:05:19 -05:00
contextMenu - > addAction ( QIcon ( IMAGE_FRIENDINFO ) , tr ( " Profile details " ) , this , SLOT ( configurefriend ( ) ) ) ;
contextMenu - > addAction ( QIcon ( IMAGE_DENYFRIEND ) , tr ( " Deny connections " ) , this , SLOT ( removefriend ( ) ) ) ;
2015-05-09 17:43:01 -04:00
if ( mShowGroups )
2012-01-27 15:53:17 -05:00
{
2015-05-09 17:43:01 -04:00
QMenu * addToGroupMenu = NULL ;
QMenu * moveToGroupMenu = NULL ;
2012-01-27 15:53:17 -05:00
2015-05-09 17:43:01 -04:00
std : : list < RsGroupInfo > groupInfoList ;
rsPeers - > getGroupInfoList ( groupInfoList ) ;
2012-01-27 15:53:17 -05:00
2015-05-09 17:43:01 -04:00
GroupDefs : : sortByName ( groupInfoList ) ;
2012-01-27 15:53:17 -05:00
2015-05-09 17:43:01 -04:00
RsPgpId gpgId ( getRsId ( c ) ) ;
2012-01-27 15:53:17 -05:00
2015-05-09 17:43:01 -04:00
QTreeWidgetItem * parent = c - > parent ( ) ;
2012-01-27 15:53:17 -05:00
2015-05-09 17:43:01 -04:00
bool foundGroup = false ;
// add action for all groups, except the own group
for ( std : : list < RsGroupInfo > : : iterator groupIt = groupInfoList . begin ( ) ; groupIt ! = groupInfoList . end ( ) ; + + groupIt ) {
if ( std : : find ( groupIt - > peerIds . begin ( ) , groupIt - > peerIds . end ( ) , gpgId ) = = groupIt - > peerIds . end ( ) ) {
if ( parent ) {
if ( addToGroupMenu = = NULL ) {
2016-08-05 12:15:21 -04:00
addToGroupMenu = new QMenu ( tr ( " Add to group " ) , contextMenu ) ;
2015-05-09 17:43:01 -04:00
}
QAction * addToGroupAction = new QAction ( GroupDefs : : name ( * groupIt ) , addToGroupMenu ) ;
2016-07-05 23:49:43 -04:00
addToGroupAction - > setData ( QString : : fromStdString ( groupIt - > id . toStdString ( ) ) ) ;
2015-05-09 17:43:01 -04:00
connect ( addToGroupAction , SIGNAL ( triggered ( ) ) , this , SLOT ( addToGroup ( ) ) ) ;
addToGroupMenu - > addAction ( addToGroupAction ) ;
}
2012-01-27 15:53:17 -05:00
2015-05-09 17:43:01 -04:00
if ( moveToGroupMenu = = NULL ) {
2016-08-05 12:15:21 -04:00
moveToGroupMenu = new QMenu ( tr ( " Move to group " ) , contextMenu ) ;
2015-05-09 17:43:01 -04:00
}
QAction * moveToGroupAction = new QAction ( GroupDefs : : name ( * groupIt ) , moveToGroupMenu ) ;
2016-07-05 23:49:43 -04:00
moveToGroupAction - > setData ( QString : : fromStdString ( groupIt - > id . toStdString ( ) ) ) ;
2015-05-09 17:43:01 -04:00
connect ( moveToGroupAction , SIGNAL ( triggered ( ) ) , this , SLOT ( moveToGroup ( ) ) ) ;
moveToGroupMenu - > addAction ( moveToGroupAction ) ;
} else {
foundGroup = true ;
}
2012-01-27 15:53:17 -05:00
}
2016-08-05 12:15:21 -04:00
QMenu * groupsMenu = contextMenu - > addMenu ( QIcon ( IMAGE_GROUP16 ) , tr ( " Groups " ) ) ;
2015-05-09 17:43:01 -04:00
groupsMenu - > addAction ( QIcon ( IMAGE_EXPAND ) , tr ( " Create new group " ) , this , SLOT ( createNewGroup ( ) ) ) ;
2013-09-27 17:40:51 -04:00
2015-05-09 17:43:01 -04:00
if ( addToGroupMenu | | moveToGroupMenu | | foundGroup ) {
if ( addToGroupMenu ) {
groupsMenu - > addMenu ( addToGroupMenu ) ;
}
2012-01-27 15:53:17 -05:00
2015-05-09 17:43:01 -04:00
if ( moveToGroupMenu ) {
groupsMenu - > addMenu ( moveToGroupMenu ) ;
}
2012-01-27 15:53:17 -05:00
2015-05-09 17:43:01 -04:00
if ( foundGroup ) {
// add remove from group
if ( parent & & parent - > type ( ) = = TYPE_GROUP ) {
QAction * removeFromGroup = groupsMenu - > addAction ( tr ( " Remove from group " ) ) ;
removeFromGroup - > setData ( parent - > data ( COLUMN_DATA , ROLE_ID ) ) ;
connect ( removeFromGroup , SIGNAL ( triggered ( ) ) , this , SLOT ( removeFromGroup ( ) ) ) ;
}
2012-01-27 15:53:17 -05:00
2015-05-09 17:43:01 -04:00
QAction * removeFromAllGroups = groupsMenu - > addAction ( tr ( " Remove from all groups " ) ) ;
removeFromAllGroups - > setData ( " " ) ;
connect ( removeFromAllGroups , SIGNAL ( triggered ( ) ) , this , SLOT ( removeFromGroup ( ) ) ) ;
}
}
}
2012-01-27 15:53:17 -05:00
2015-05-09 17:43:01 -04:00
}
break ;
2012-01-27 15:53:17 -05:00
2015-05-09 17:43:01 -04:00
case TYPE_SSL :
{
2016-08-05 12:15:21 -04:00
contextMenu - > addAction ( QIcon ( IMAGE_CHAT ) , tr ( " Chat " ) , this , SLOT ( chatfriendproxy ( ) ) ) ;
2017-02-28 17:05:19 -05:00
contextMenu - > addAction ( QIcon ( IMAGE_MSG ) , tr ( " Send message to this node " ) , this , SLOT ( msgfriend ( ) ) ) ;
2012-01-27 15:53:17 -05:00
2016-08-05 12:15:21 -04:00
contextMenu - > addSeparator ( ) ;
2012-01-27 15:53:17 -05:00
2017-02-28 17:05:19 -05:00
contextMenu - > addAction ( QIcon ( IMAGE_FRIENDINFO ) , tr ( " Node details " ) , this , SLOT ( configurefriend ( ) ) ) ;
2012-01-27 15:53:17 -05:00
2015-05-09 17:43:01 -04:00
if ( type = = TYPE_GPG | | type = = TYPE_SSL ) {
2017-02-28 17:05:19 -05:00
contextMenu - > addAction ( QIcon ( IMAGE_EXPORTFRIEND ) , tr ( " Recommend this node to... " ) , this , SLOT ( recommendfriend ( ) ) ) ;
2015-05-09 17:43:01 -04:00
}
2012-01-27 15:53:17 -05:00
2018-01-15 15:42:58 -05:00
if ( ! rsPeers - > isHiddenNode ( rsPeers - > getOwnId ( ) ) | | rsPeers - > isHiddenNode ( RsPeerId ( getRsId ( c ) ) ) )
contextMenu - > addAction ( QIcon ( IMAGE_CONNECT ) , tr ( " Attempt to connect " ) , this , SLOT ( connectfriend ( ) ) ) ;
2013-07-16 18:33:45 -04:00
2016-08-05 12:15:21 -04:00
contextMenu - > addAction ( QIcon ( IMAGE_COPYLINK ) , tr ( " Copy certificate link " ) , this , SLOT ( copyFullCertificate ( ) ) ) ;
2012-01-27 15:53:17 -05:00
2016-08-05 12:15:21 -04:00
//this is a SSL key
contextMenu - > addAction ( QIcon ( IMAGE_REMOVEFRIEND ) , tr ( " Remove Friend Node " ) , this , SLOT ( removefriend ( ) ) ) ;
2012-01-27 15:53:17 -05:00
}
}
2015-05-09 17:43:01 -04:00
}
2013-07-16 18:33:45 -04:00
2016-08-05 12:15:21 -04:00
contextMenu - > addSeparator ( ) ;
QAction * action = contextMenu - > addAction ( QIcon ( IMAGE_PASTELINK ) , tr ( " Paste certificate link " ) , this , SLOT ( pastePerson ( ) ) ) ;
if ( RSLinkClipboard : : empty ( RetroShareLink : : TYPE_CERTIFICATE ) )
action - > setDisabled ( true ) ;
2011-10-20 18:48:50 -04:00
2016-08-05 12:15:21 -04:00
contextMenu - > addAction ( QIcon ( IMAGE_EXPAND ) , tr ( " Expand all " ) , ui - > peerTreeWidget , SLOT ( expandAll ( ) ) ) ;
contextMenu - > addAction ( QIcon ( IMAGE_COLLAPSE ) , tr ( " Collapse all " ) , ui - > peerTreeWidget , SLOT ( collapseAll ( ) ) ) ;
2015-05-09 17:43:01 -04:00
2016-08-05 12:15:21 -04:00
contextMenu = ui - > peerTreeWidget - > createStandardContextMenu ( contextMenu ) ;
2011-10-20 18:48:50 -04:00
2016-08-05 12:15:21 -04:00
contextMenu - > exec ( QCursor : : pos ( ) ) ;
delete contextMenu ;
2011-10-20 18:48:50 -04:00
}
2013-09-02 18:51:26 -04:00
2013-07-16 18:33:45 -04:00
void FriendList : : createNewGroup ( )
{
2016-07-05 23:49:43 -04:00
CreateGroup createGrpDialog ( RsNodeGroupId ( ) , this ) ;
2013-07-16 18:33:45 -04:00
createGrpDialog . exec ( ) ;
}
2011-10-20 18:48:50 -04:00
void FriendList : : updateDisplay ( )
{
insertPeers ( ) ;
}
void FriendList : : groupsChanged ( )
{
groupsHasChanged = true ;
insertPeers ( ) ;
}
2015-08-08 14:27:19 -04:00
static QIcon createAvatar ( const QPixmap & avatar , const QPixmap & overlay )
2011-10-20 18:48:50 -04:00
{
2015-08-11 07:40:02 -04:00
int avatarWidth = avatar . width ( ) ;
int avatarHeight = avatar . height ( ) ;
2015-08-08 14:27:19 -04:00
QPixmap pixmap ( avatar ) ;
2011-10-20 18:48:50 -04:00
2015-08-11 07:40:02 -04:00
int overlayWidth = avatarWidth / 2.5 ;
int overlayHeight = avatarHeight / 2.5 ;
int overlayX = avatarWidth - overlayWidth ;
int overlayY = avatarHeight - overlayHeight ;
2015-08-08 14:27:19 -04:00
QPainter painter ( & pixmap ) ;
2015-08-11 07:40:02 -04:00
painter . drawPixmap ( overlayX , overlayY , overlayWidth , overlayHeight , overlay ) ;
2015-08-08 14:27:19 -04:00
QIcon icon ;
icon . addPixmap ( pixmap ) ;
return icon ;
2011-10-20 18:48:50 -04:00
}
2015-08-19 03:59:14 -04:00
static void getNameWidget ( QTreeWidget * treeWidget , QTreeWidgetItem * item , ElidedLabel * & nameLabel , ElidedLabel * & textLabel )
{
QWidget * widget = treeWidget - > itemWidget ( item , FriendList : : COLUMN_NAME ) ;
if ( ! widget ) {
widget = new QWidget ;
2016-10-16 09:48:50 -04:00
widget - > setAttribute ( Qt : : WA_TranslucentBackground ) ;
2015-08-19 03:59:14 -04:00
nameLabel = new ElidedLabel ( widget ) ;
textLabel = new ElidedLabel ( widget ) ;
widget - > setProperty ( " nameLabel " , qVariantFromValue ( nameLabel ) ) ;
widget - > setProperty ( " textLabel " , qVariantFromValue ( textLabel ) ) ;
QVBoxLayout * layout = new QVBoxLayout ;
layout - > setSpacing ( 0 ) ;
layout - > setContentsMargins ( 3 , 0 , 0 , 0 ) ;
nameLabel - > setSizePolicy ( QSizePolicy : : Preferred , QSizePolicy : : Maximum ) ;
textLabel - > setSizePolicy ( QSizePolicy : : Preferred , QSizePolicy : : Maximum ) ;
layout - > addWidget ( nameLabel ) ;
layout - > addWidget ( textLabel ) ;
widget - > setLayout ( layout ) ;
treeWidget - > setItemWidget ( item , FriendList : : COLUMN_NAME , widget ) ;
} else {
nameLabel = widget - > property ( " nameLabel " ) . value < ElidedLabel * > ( ) ;
textLabel = widget - > property ( " textLabel " ) . value < ElidedLabel * > ( ) ;
}
}
2011-10-20 18:48:50 -04:00
/**
* Get the list of peers from the RsIface .
2014-12-30 06:11:08 -05:00
* Adds all friend gpg ids , with their nodes as children to the peerTreeWidget .
2011-10-20 18:48:50 -04:00
* If enabled , peers are sorted in their associated groups .
* Groups are only updated , when groupsHasChanged is true .
*/
2015-08-08 14:27:19 -04:00
void FriendList : : insertPeers ( )
2011-10-20 18:48:50 -04:00
{
if ( RsAutoUpdatePage : : eventsLocked ( ) )
return ;
# ifdef FRIENDS_DEBUG
std : : cerr < < " FriendList::insertPeers() called. " < < std : : endl ;
# endif
2015-07-09 16:53:28 -04:00
int columnCount = ui - > peerTreeWidget - > columnCount ( ) ;
2011-11-11 20:26:26 -05:00
2011-10-20 18:48:50 -04:00
std : : list < StatusInfo > statusInfo ;
rsStatus - > getStatusList ( statusInfo ) ;
if ( ! rsPeers ) {
/* not ready yet! */
std : : cerr < < " FriendList::insertPeers() not ready yet : rsPeers unintialized. " < < std : : endl ;
return ;
}
2015-01-10 08:13:41 -05:00
// get peers with waiting incoming chats
std : : vector < RsPeerId > privateChatIds ;
ChatUserNotify : : getPeersWithWaitingChat ( privateChatIds ) ;
2011-10-20 18:48:50 -04:00
// get existing groups
std : : list < RsGroupInfo > groupInfoList ;
std : : list < RsGroupInfo > : : iterator groupIt ;
rsPeers - > getGroupInfoList ( groupInfoList ) ;
2014-03-17 16:56:06 -04:00
std : : list < RsPgpId > gpgFriends ;
std : : list < RsPgpId > : : iterator gpgIt ;
2011-10-20 18:48:50 -04:00
rsPeers - > getGPGAcceptedList ( gpgFriends ) ;
2014-12-30 06:11:08 -05:00
//add own gpg id, if we have more than on node (ssl client)
2014-03-17 16:56:06 -04:00
std : : list < RsPeerId > ownSslContacts ;
RsPgpId ownId = rsPeers - > getGPGOwnId ( ) ;
2011-10-20 18:48:50 -04:00
rsPeers - > getAssociatedSSLIds ( ownId , ownSslContacts ) ;
if ( ownSslContacts . size ( ) > 0 ) {
gpgFriends . push_back ( ownId ) ;
}
/* get a link to the table */
QTreeWidget * peerTreeWidget = ui - > peerTreeWidget ;
// remove items don't exist anymore
QTreeWidgetItemIterator itemIterator ( peerTreeWidget ) ;
QTreeWidgetItem * item ;
while ( ( item = * itemIterator ) ! = NULL ) {
2014-10-21 18:33:02 -04:00
+ + itemIterator ;
2011-10-20 18:48:50 -04:00
switch ( item - > type ( ) ) {
case TYPE_GPG :
2015-08-08 14:27:19 -04:00
{
QTreeWidgetItem * parent = item - > parent ( ) ;
RsPgpId gpg_widget_id ( getRsId ( item ) ) ;
// remove items that are not friends anymore
if ( std : : find ( gpgFriends . begin ( ) , gpgFriends . end ( ) , gpg_widget_id ) = = gpgFriends . end ( ) ) {
if ( parent ) {
delete ( parent - > takeChild ( parent - > indexOfChild ( item ) ) ) ;
} else {
delete ( peerTreeWidget - > takeTopLevelItem ( peerTreeWidget - > indexOfTopLevelItem ( item ) ) ) ;
}
break ;
2011-10-20 18:48:50 -04:00
}
2015-08-08 14:27:19 -04:00
if ( mShowGroups & & groupsHasChanged ) {
if ( parent ) {
if ( parent - > type ( ) = = TYPE_GROUP ) {
2016-07-05 23:49:43 -04:00
RsNodeGroupId groupId ( getRsId ( parent ) ) ;
2015-08-08 14:27:19 -04:00
// the parent is a group, check if the gpg id is assigned to the group
for ( groupIt = groupInfoList . begin ( ) ; groupIt ! = groupInfoList . end ( ) ; + + groupIt ) {
if ( groupIt - > id = = groupId ) {
if ( std : : find ( groupIt - > peerIds . begin ( ) , groupIt - > peerIds . end ( ) , gpg_widget_id ) = = groupIt - > peerIds . end ( ) ) {
delete ( parent - > takeChild ( parent - > indexOfChild ( item ) ) ) ;
}
break ;
2011-10-20 18:48:50 -04:00
}
}
}
2015-08-08 14:27:19 -04:00
} else {
// gpg item without group, check if the gpg id is assigned to a group
for ( groupIt = groupInfoList . begin ( ) ; groupIt ! = groupInfoList . end ( ) ; + + groupIt ) {
if ( std : : find ( groupIt - > peerIds . begin ( ) , groupIt - > peerIds . end ( ) , gpg_widget_id ) ! = groupIt - > peerIds . end ( ) ) {
delete ( peerTreeWidget - > takeTopLevelItem ( peerTreeWidget - > indexOfTopLevelItem ( item ) ) ) ;
break ;
}
2011-10-20 18:48:50 -04:00
}
}
}
}
break ;
case TYPE_GROUP :
2015-08-08 14:27:19 -04:00
{
if ( ! mShowGroups ) {
2011-10-20 18:48:50 -04:00
if ( item - > parent ( ) ) {
delete ( item - > parent ( ) - > takeChild ( item - > parent ( ) - > indexOfChild ( item ) ) ) ;
} else {
delete ( peerTreeWidget - > takeTopLevelItem ( peerTreeWidget - > indexOfTopLevelItem ( item ) ) ) ;
}
2015-08-08 14:27:19 -04:00
} else if ( groupsHasChanged ) {
// remove deleted groups
2016-07-05 23:49:43 -04:00
RsNodeGroupId groupId ( getRsId ( item ) ) ;
2015-08-08 14:27:19 -04:00
for ( groupIt = groupInfoList . begin ( ) ; groupIt ! = groupInfoList . end ( ) ; + + groupIt ) {
if ( groupIt - > id = = groupId ) {
break ;
}
}
if ( groupIt = = groupInfoList . end ( ) | | groupIt - > peerIds . empty ( ) ) {
if ( item - > parent ( ) ) {
delete ( item - > parent ( ) - > takeChild ( item - > parent ( ) - > indexOfChild ( item ) ) ) ;
} else {
delete ( peerTreeWidget - > takeTopLevelItem ( peerTreeWidget - > indexOfTopLevelItem ( item ) ) ) ;
}
}
2011-10-20 18:48:50 -04:00
}
}
break ;
}
}
2014-03-17 16:56:06 -04:00
std : : list < RsPgpId > fillGpgIds ;
2011-10-20 18:48:50 -04:00
// start with groups
groupIt = groupInfoList . begin ( ) ;
while ( true ) {
QTreeWidgetItem * groupItem = NULL ;
RsGroupInfo * groupInfo = NULL ;
int onlineCount = 0 ;
int availableCount = 0 ;
2011-11-11 20:26:26 -05:00
if ( mShowGroups & & groupIt ! = groupInfoList . end ( ) ) {
2011-10-20 18:48:50 -04:00
groupInfo = & ( * groupIt ) ;
2014-10-21 18:33:02 -04:00
if ( ( groupInfo - > flag & RS_GROUP_FLAG_STANDARD ) & & groupInfo - > peerIds . empty ( ) ) {
2011-10-20 18:48:50 -04:00
// don't show empty standard groups
2014-10-21 18:33:02 -04:00
+ + groupIt ;
2011-10-20 18:48:50 -04:00
continue ;
}
// search existing group item
int itemCount = peerTreeWidget - > topLevelItemCount ( ) ;
2014-10-21 18:33:02 -04:00
for ( int index = 0 ; index < itemCount ; + + index ) {
2011-10-20 18:48:50 -04:00
QTreeWidgetItem * groupItemLoop = peerTreeWidget - > topLevelItem ( index ) ;
2016-07-05 23:49:43 -04:00
if ( groupItemLoop - > type ( ) = = TYPE_GROUP & & RsNodeGroupId ( getRsId ( groupItemLoop ) ) = = groupInfo - > id ) {
2011-10-20 18:48:50 -04:00
groupItem = groupItemLoop ;
break ;
}
}
if ( groupItem = = NULL ) {
// add group item
2015-08-08 14:27:19 -04:00
groupItem = new RSTreeWidgetItem ( mCompareRole , TYPE_GROUP ) ;
2011-10-20 18:48:50 -04:00
/* Add item to the list. Add here, because for setHidden the item must be added */
peerTreeWidget - > addTopLevelItem ( groupItem ) ;
groupItem - > setChildIndicatorPolicy ( QTreeWidgetItem : : DontShowIndicatorWhenChildless ) ;
groupItem - > setTextAlignment ( COLUMN_NAME , Qt : : AlignLeft | Qt : : AlignVCenter ) ;
groupItem - > setIcon ( COLUMN_NAME , QIcon ( IMAGE_GROUP24 ) ) ;
2012-11-19 11:01:21 -05:00
groupItem - > setForeground ( COLUMN_NAME , QBrush ( textColorGroup ( ) ) ) ;
2011-10-20 18:48:50 -04:00
/* used to find back the item */
2017-07-17 08:10:26 -04:00
QString strID = QString : : fromStdString ( groupInfo - > id . toStdString ( ) ) ;
groupItem - > setData ( COLUMN_DATA , ROLE_ID , strID ) ;
//No needs for group ???
//groupItem->setText(COLUMN_ID, strID);
//groupItem->setData(COLUMN_ID, ROLE_SORT_NAME, strID);
//groupItem->setData(COLUMN_ID, ROLE_FILTER, strID);
2011-10-20 18:48:50 -04:00
groupItem - > setData ( COLUMN_DATA , ROLE_STANDARD , ( groupInfo - > flag & RS_GROUP_FLAG_STANDARD ) ? true : false ) ;
2015-08-08 14:27:19 -04:00
/* Sort data */
2015-08-21 18:57:26 -04:00
for ( int i = 0 ; i < columnCount ; + + i ) {
groupItem - > setData ( i , ROLE_SORT_GROUP , 1 ) ;
groupItem - > setData ( i , ROLE_SORT_STANDARD_GROUP , ( groupInfo - > flag & RS_GROUP_FLAG_STANDARD ) ? 0 : 1 ) ;
groupItem - > setData ( i , ROLE_SORT_STATE , 0 ) ;
}
2011-10-20 18:48:50 -04:00
} else {
// remove all gpg items that are not more assigned
int childCount = groupItem - > childCount ( ) ;
int childIndex = 0 ;
while ( childIndex < childCount ) {
QTreeWidgetItem * gpgItemLoop = groupItem - > child ( childIndex ) ;
if ( gpgItemLoop - > type ( ) = = TYPE_GPG ) {
2014-03-17 16:56:06 -04:00
if ( std : : find ( groupInfo - > peerIds . begin ( ) , groupInfo - > peerIds . end ( ) , RsPgpId ( getRsId ( gpgItemLoop ) ) ) = = groupInfo - > peerIds . end ( ) ) {
2011-10-20 18:48:50 -04:00
delete ( groupItem - > takeChild ( groupItem - > indexOfChild ( gpgItemLoop ) ) ) ;
childCount = groupItem - > childCount ( ) ;
continue ;
}
}
2014-10-21 18:33:02 -04:00
+ + childIndex ;
2011-10-20 18:48:50 -04:00
}
}
2016-07-05 23:49:43 -04:00
if ( openGroups . find ( groupInfo - > id ) ! = openGroups . end ( ) ) {
2011-10-20 18:48:50 -04:00
groupItem - > setExpanded ( true ) ;
}
// name is set after calculation of online/offline items
}
// iterate through gpg friends
2015-05-15 10:45:44 -04:00
for ( gpgIt = gpgFriends . begin ( ) ; gpgIt ! = gpgFriends . end ( ) ; + + gpgIt )
2015-08-08 14:27:19 -04:00
{
RsPgpId gpgId = * gpgIt ;
2015-05-15 10:45:44 -04:00
2015-08-08 14:27:19 -04:00
if ( mShowGroups ) {
if ( groupInfo ) {
// we fill a group, check if gpg id is assigned
if ( std : : find ( groupInfo - > peerIds . begin ( ) , groupInfo - > peerIds . end ( ) , gpgId ) = = groupInfo - > peerIds . end ( ) ) {
continue ;
}
} else {
// we fill the not assigned gpg ids
if ( std : : find ( fillGpgIds . begin ( ) , fillGpgIds . end ( ) , gpgId ) ! = fillGpgIds . end ( ) ) {
continue ;
}
2011-10-20 18:48:50 -04:00
}
2015-08-08 14:27:19 -04:00
// add equal too, its no problem
fillGpgIds . push_back ( gpgId ) ;
}
2015-05-15 10:45:44 -04:00
2015-08-08 14:27:19 -04:00
//add the gpg friends
2011-10-20 18:48:50 -04:00
# ifdef FRIENDS_DEBUG
2015-08-08 14:27:19 -04:00
std : : cerr < < " FriendList::insertPeers() inserting gpg_id : " < < gpgId < < std : : endl ;
2011-10-20 18:48:50 -04:00
# endif
2015-08-08 14:27:19 -04:00
/* make a widget per friend */
QTreeWidgetItem * gpgItem = NULL ;
QTreeWidgetItem * gpgItemLoop = NULL ;
// search existing gpg item
int itemCount = groupItem ? groupItem - > childCount ( ) : peerTreeWidget - > topLevelItemCount ( ) ;
for ( int index = 0 ; index < itemCount ; + + index ) {
gpgItemLoop = groupItem ? groupItem - > child ( index ) : peerTreeWidget - > topLevelItem ( index ) ;
if ( gpgItemLoop - > type ( ) = = TYPE_GPG & & getRsId ( gpgItemLoop ) = = gpgId . toStdString ( ) ) {
gpgItem = gpgItemLoop ;
break ;
}
2011-10-20 18:48:50 -04:00
}
2015-08-08 14:27:19 -04:00
RsPeerDetails detail ;
if ( ( ! rsPeers - > getGPGDetails ( gpgId , detail ) | | ! detail . accept_connection ) & & detail . gpg_id ! = ownId ) {
// don't accept anymore connection, remove from the view
if ( gpgItem ) {
if ( groupItem ) {
delete ( groupItem - > takeChild ( groupItem - > indexOfChild ( gpgItem ) ) ) ;
} else {
delete ( peerTreeWidget - > takeTopLevelItem ( peerTreeWidget - > indexOfTopLevelItem ( gpgItem ) ) ) ;
}
2011-10-20 18:48:50 -04:00
}
2015-08-08 14:27:19 -04:00
continue ;
2011-10-20 18:48:50 -04:00
}
2015-05-15 10:45:44 -04:00
2015-08-08 14:27:19 -04:00
if ( gpgItem = = NULL ) {
// create gpg item and add it to tree
gpgItem = new RSTreeWidgetItem ( mCompareRole , TYPE_GPG ) ; //set type to 0 for custom popup menu
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
/* Add gpg item to the list. Add here, because for setHidden the item must be added */
if ( groupItem ) {
groupItem - > addChild ( gpgItem ) ;
} else {
peerTreeWidget - > addTopLevelItem ( gpgItem ) ;
}
2011-11-11 20:26:26 -05:00
2015-08-08 14:27:19 -04:00
gpgItem - > setChildIndicatorPolicy ( QTreeWidgetItem : : DontShowIndicatorWhenChildless ) ;
gpgItem - > setTextAlignment ( COLUMN_NAME , Qt : : AlignLeft | Qt : : AlignVCenter ) ;
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
/* not displayed, used to find back the item */
2017-07-17 08:10:26 -04:00
QString strID = QString : : fromStdString ( detail . gpg_id . toStdString ( ) ) ;
gpgItem - > setData ( COLUMN_DATA , ROLE_ID , strID ) ;
gpgItem - > setText ( COLUMN_ID , strID ) ;
gpgItem - > setData ( COLUMN_ID , ROLE_SORT_NAME , strID ) ;
gpgItem - > setData ( COLUMN_ID , ROLE_FILTER , strID ) ;
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
/* Sort data */
2015-08-21 18:57:26 -04:00
for ( int i = 0 ; i < columnCount ; + + i ) {
gpgItem - > setData ( i , ROLE_SORT_GROUP , 2 ) ;
gpgItem - > setData ( i , ROLE_SORT_STANDARD_GROUP , 1 ) ;
}
2015-08-08 14:27:19 -04:00
}
2015-05-15 10:45:44 -04:00
2015-08-08 14:27:19 -04:00
+ + availableCount ;
2015-05-15 10:45:44 -04:00
2015-08-08 14:27:19 -04:00
// remove items that are not friends anymore
int childCount = gpgItem - > childCount ( ) ;
int childIndex = 0 ;
while ( childIndex < childCount ) {
std : : string ssl_id = getRsId ( gpgItem - > child ( childIndex ) ) ;
if ( ! rsPeers - > isFriend ( RsPeerId ( ssl_id ) ) ) {
delete ( gpgItem - > takeChild ( childIndex ) ) ;
// count again
childCount = gpgItem - > childCount ( ) ;
} else {
+ + childIndex ;
}
2015-05-15 10:45:44 -04:00
}
2015-08-08 14:27:19 -04:00
// update the childs (ssl certs)
bool gpg_connected = false ;
bool gpg_online = false ;
bool gpg_hasPrivateChat = false ;
int bestPeerState = 0 ; // for gpg item
unsigned int bestRSState = 0 ; // for gpg item
QString bestCustomStateString ; // for gpg item
std : : list < RsPeerId > sslContacts ;
QDateTime bestLastContact ;
QString bestIP ;
QPixmap bestAvatar ;
rsPeers - > getAssociatedSSLIds ( detail . gpg_id , sslContacts ) ;
for ( std : : list < RsPeerId > : : iterator sslIt = sslContacts . begin ( ) ; sslIt ! = sslContacts . end ( ) ; + + sslIt ) {
QTreeWidgetItem * sslItem = NULL ;
RsPeerId sslId = * sslIt ;
// find the corresponding sslItem child item of the gpg item
bool newChild = true ;
childCount = gpgItem - > childCount ( ) ;
for ( int childIndex = 0 ; childIndex < childCount ; + + childIndex ) {
// we assume, that only ssl items are child of the gpg item, so we don't need to test the type
if ( getRsId ( gpgItem - > child ( childIndex ) ) = = sslId . toStdString ( ) ) {
sslItem = gpgItem - > child ( childIndex ) ;
newChild = false ;
break ;
}
2011-10-20 18:48:50 -04:00
}
2015-08-08 14:27:19 -04:00
RsPeerDetails sslDetail ;
if ( ! rsPeers - > getPeerDetails ( sslId , sslDetail ) | | ! rsPeers - > isFriend ( sslId ) ) {
2011-10-20 18:48:50 -04:00
# ifdef FRIENDS_DEBUG
2015-08-08 14:27:19 -04:00
std : : cerr < < " Removing widget from the view : id : " < < sslId < < std : : endl ;
2011-10-20 18:48:50 -04:00
# endif
2015-08-08 14:27:19 -04:00
// child has disappeared, remove it from the gpg_item
if ( sslItem ) {
gpgItem - > removeChild ( sslItem ) ;
delete ( sslItem ) ;
}
continue ;
2011-10-20 18:48:50 -04:00
}
2015-08-08 14:27:19 -04:00
if ( newChild ) {
sslItem = new RSTreeWidgetItem ( mCompareRole , TYPE_SSL ) ; //set type to 1 for custom popup menu
2011-10-20 18:48:50 -04:00
# ifdef FRIENDS_DEBUG
2015-08-08 14:27:19 -04:00
std : : cerr < < " FriendList::insertPeers() inserting sslItem. " < < std : : endl ;
2011-10-20 18:48:50 -04:00
# endif
2015-08-08 14:27:19 -04:00
/* Add ssl child to the list. Add here, because for setHidden the item must be added */
gpgItem - > addChild ( sslItem ) ;
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
/* Sort data */
2015-08-21 18:57:26 -04:00
for ( int i = 0 ; i < columnCount ; + + i ) {
sslItem - > setData ( i , ROLE_SORT_GROUP , 2 ) ;
sslItem - > setData ( i , ROLE_SORT_STANDARD_GROUP , 1 ) ;
}
2015-08-08 14:27:19 -04:00
}
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
/* not displayed, used to find back the item */
2017-07-17 08:10:26 -04:00
QString strID = QString : : fromStdString ( sslDetail . id . toStdString ( ) ) ;
sslItem - > setData ( COLUMN_DATA , ROLE_ID , strID ) ;
sslItem - > setText ( COLUMN_ID , strID ) ;
sslItem - > setData ( COLUMN_ID , ROLE_SORT_NAME , strID ) ;
sslItem - > setData ( COLUMN_ID , ROLE_FILTER , strID ) ;
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
/* Custom state string */
QString customStateString ;
if ( sslDetail . state & RS_PEER_STATE_CONNECTED ) {
customStateString = QString : : fromUtf8 ( rsMsgs - > getCustomStateString ( sslDetail . id ) . c_str ( ) ) ;
}
2011-11-11 20:26:26 -05:00
2015-08-08 14:27:19 -04:00
QPixmap sslAvatar ;
AvatarDefs : : getAvatarFromSslId ( RsPeerId ( sslDetail . id . toStdString ( ) ) , sslAvatar ) ;
2013-12-08 09:12:02 -05:00
2015-08-08 14:27:19 -04:00
/* last contact */
QDateTime sslLastContact = QDateTime : : fromTime_t ( sslDetail . lastConnect ) ;
sslItem - > setData ( COLUMN_LAST_CONTACT , Qt : : DisplayRole , QVariant ( sslLastContact ) ) ;
2015-08-21 18:57:26 -04:00
sslItem - > setData ( COLUMN_LAST_CONTACT , ROLE_SORT_NAME , QVariant ( sslLastContact ) ) ;
2015-08-08 14:27:19 -04:00
if ( sslLastContact > bestLastContact ) {
bestLastContact = sslLastContact ;
}
2013-07-04 16:11:36 -04:00
2015-08-08 14:27:19 -04:00
/* IP */
QString sslIP = ( sslDetail . state & RS_PEER_STATE_CONNECTED ) ? StatusDefs : : connectStateIpString ( sslDetail ) : QString ( " --- " ) ;
sslItem - > setText ( COLUMN_IP , sslIP ) ;
2015-08-21 18:57:26 -04:00
sslItem - > setData ( COLUMN_IP , ROLE_SORT_NAME , sslIP ) ;
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
/* change color and icon */
QPixmap sslOverlayIcon ;
QFont sslFont ;
QColor sslColor ;
2015-05-15 10:45:44 -04:00
int peerState = 0 ;
2015-08-08 14:27:19 -04:00
QString connectStateString ;
if ( sslDetail . state & RS_PEER_STATE_CONNECTED ) {
// get the status info for this ssl id
int rsState = 0 ;
std : : list < StatusInfo > : : iterator it ;
for ( it = statusInfo . begin ( ) ; it ! = statusInfo . end ( ) ; + + it ) {
if ( it - > id = = sslId ) {
rsState = it - > status ;
switch ( rsState ) {
case RS_STATUS_INACTIVE :
peerState = PEER_STATE_INACTIVE ;
break ;
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
case RS_STATUS_ONLINE :
peerState = PEER_STATE_ONLINE ;
break ;
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
case RS_STATUS_AWAY :
peerState = PEER_STATE_AWAY ;
break ;
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
case RS_STATUS_BUSY :
peerState = PEER_STATE_BUSY ;
break ;
}
2015-05-15 10:45:44 -04:00
2015-08-08 14:27:19 -04:00
/* find the best ssl contact for the gpg item */
if ( bestPeerState = = 0 | | peerState < bestPeerState ) {
/* first ssl contact or higher state */
2011-10-20 18:48:50 -04:00
bestPeerState = peerState ;
bestRSState = rsState ;
bestCustomStateString = customStateString ;
2015-08-08 14:27:19 -04:00
bestIP = sslIP ;
if ( ! sslAvatar . isNull ( ) ) {
bestAvatar = sslAvatar ;
}
} else if ( peerState = = bestPeerState ) {
/* equal state */
if ( bestCustomStateString . isEmpty ( ) & & ! customStateString . isEmpty ( ) ) {
/* when customStateString is shown in name item, use sslId with customStateString.
second with a custom state string . . . use second */
bestPeerState = peerState ;
bestRSState = rsState ;
bestCustomStateString = customStateString ;
}
if ( bestAvatar . isNull ( ) & & ! sslAvatar . isNull ( ) ) {
/* Use available avatar */
bestAvatar = sslAvatar ;
}
2011-10-20 18:48:50 -04:00
}
2015-08-08 14:27:19 -04:00
break ;
2011-10-20 18:48:50 -04:00
}
}
2015-08-08 14:27:19 -04:00
sslItem - > setHidden ( false ) ;
gpg_connected = true ;
sslOverlayIcon = QPixmap ( StatusDefs : : imageStatus ( bestRSState ) ) ;
connectStateString = StatusDefs : : name ( rsState ) ;
if ( rsState = = 0 ) {
sslFont . setBold ( true ) ;
sslColor = mTextColorStatus [ RS_STATUS_ONLINE ] ;
} else {
sslFont = StatusDefs : : font ( rsState ) ;
sslColor = mTextColorStatus [ rsState ] ;
}
} else if ( sslDetail . state & RS_PEER_STATE_ONLINE ) {
sslItem - > setHidden ( mHideUnconnected ) ;
gpg_online = true ;
peerState = PEER_STATE_AVAILABLE ;
if ( sslDetail . connectState ) {
sslOverlayIcon = QPixmap ( " :/images/connect_creating.png " ) ;
} else {
sslOverlayIcon = QPixmap ( StatusDefs : : imageStatus ( RS_STATUS_ONLINE ) ) ;
}
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
connectStateString = StatusDefs : : name ( RS_STATUS_ONLINE ) ;
2011-10-20 18:48:50 -04:00
sslFont . setBold ( true ) ;
2012-11-19 11:01:21 -05:00
sslColor = mTextColorStatus [ RS_STATUS_ONLINE ] ;
2011-10-20 18:48:50 -04:00
} else {
2015-08-08 14:27:19 -04:00
peerState = PEER_STATE_OFFLINE ;
sslItem - > setHidden ( mHideUnconnected ) ;
if ( sslDetail . connectState ) {
sslOverlayIcon = QPixmap ( " :/images/connect_creating.png " ) ;
} else {
sslOverlayIcon = QPixmap ( StatusDefs : : imageStatus ( RS_STATUS_OFFLINE ) ) ;
}
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
connectStateString = StatusDefs : : connectStateWithoutTransportTypeString ( sslDetail ) ;
sslFont . setBold ( false ) ;
sslColor = mTextColorStatus [ RS_STATUS_OFFLINE ] ;
2011-10-20 18:48:50 -04:00
}
2015-08-08 14:27:19 -04:00
/* Location */
2015-08-19 03:59:14 -04:00
QString sslName = QString : : fromUtf8 ( sslDetail . location . c_str ( ) ) ;
QString sslText ;
2015-08-08 14:27:19 -04:00
if ( mShowState ) {
if ( ! connectStateString . isEmpty ( ) ) {
2015-08-19 03:59:14 -04:00
sslText = connectStateString ;
2015-08-08 14:27:19 -04:00
if ( ! customStateString . isEmpty ( ) ) {
2015-08-19 03:59:14 -04:00
sslText + = " [ " + customStateString + " ] " ;
2015-08-08 14:27:19 -04:00
}
} else {
if ( ! customStateString . isEmpty ( ) ) {
2015-08-19 03:59:14 -04:00
sslText = customStateString ;
2015-08-08 14:27:19 -04:00
}
}
sslItem - > setToolTip ( COLUMN_NAME , " " ) ;
2015-05-15 10:45:44 -04:00
} else {
2015-08-08 14:27:19 -04:00
if ( ! customStateString . isEmpty ( ) ) {
2015-08-19 03:59:14 -04:00
sslText = customStateString ;
2015-08-08 14:27:19 -04:00
}
/* Show the state as tooltip */
sslItem - > setToolTip ( COLUMN_NAME , connectStateString ) ;
2011-10-20 18:48:50 -04:00
}
2015-08-19 03:59:14 -04:00
/* Create or get ssl label */
ElidedLabel * sslNameLabel = NULL ;
ElidedLabel * sslTextLabel = NULL ;
getNameWidget ( ui - > peerTreeWidget , sslItem , sslNameLabel , sslTextLabel ) ;
if ( sslNameLabel ) {
sslNameLabel - > setText ( sslName ) ;
sslNameLabel - > setFont ( sslFont ) ;
QPalette palette = sslNameLabel - > palette ( ) ;
palette . setColor ( sslNameLabel - > foregroundRole ( ) , sslColor ) ;
sslNameLabel - > setPalette ( palette ) ;
}
if ( sslTextLabel ) {
sslTextLabel - > setText ( sslText ) ;
sslTextLabel - > setVisible ( ! sslText . isEmpty ( ) ) ;
}
2011-10-20 18:48:50 -04:00
2015-08-26 13:26:20 -04:00
// Filter
sslItem - > setData ( COLUMN_NAME , ROLE_FILTER , sslName ) ;
2015-08-08 14:27:19 -04:00
if ( std : : find ( privateChatIds . begin ( ) , privateChatIds . end ( ) , sslDetail . id ) ! = privateChatIds . end ( ) ) {
// private chat is available
sslOverlayIcon = QPixmap ( " :/images/chat.png " ) ;
gpg_hasPrivateChat = true ;
}
sslItem - > setIcon ( COLUMN_NAME , createAvatar ( sslAvatar , sslOverlayIcon ) ) ;
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
/* Sort data */
2015-08-21 18:57:26 -04:00
sslItem - > setData ( COLUMN_NAME , ROLE_SORT_NAME , sslName ) ;
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
for ( int i = 0 ; i < columnCount ; + + i ) {
2015-08-21 18:57:26 -04:00
sslItem - > setData ( i , ROLE_SORT_STATE , peerState ) ;
2015-08-08 14:27:19 -04:00
sslItem - > setTextColor ( i , sslColor ) ;
sslItem - > setFont ( i , sslFont ) ;
}
2015-05-15 10:45:44 -04:00
}
2011-10-20 18:48:50 -04:00
2015-08-19 03:59:14 -04:00
QString gpgName = QString : : fromUtf8 ( detail . name . c_str ( ) ) ;
QString gpgText ;
QFont gpgFont ;
QColor gpgColor ;
bool showInfoAtGpgItem = ! gpgItem - > isExpanded ( ) ;
2015-08-08 14:27:19 -04:00
QPixmap gpgOverlayIcon ;
if ( gpg_connected ) {
gpgItem - > setHidden ( false ) ;
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
+ + onlineCount ;
2011-10-20 18:48:50 -04:00
2015-08-08 14:27:19 -04:00
if ( bestPeerState = = 0 ) {
// show as online
bestPeerState = PEER_STATE_ONLINE ;
bestRSState = RS_STATUS_ONLINE ;
}
2011-10-20 18:48:50 -04:00
2015-08-19 03:59:14 -04:00
gpgColor = mTextColorStatus [ bestRSState ] ;
gpgFont = StatusDefs : : font ( bestRSState ) ;
2011-10-20 18:48:50 -04:00
2015-08-19 03:59:14 -04:00
if ( showInfoAtGpgItem ) {
gpgOverlayIcon = QPixmap ( StatusDefs : : imageStatus ( bestRSState ) ) ;
2011-10-20 18:48:50 -04:00
2015-08-19 03:59:14 -04:00
if ( mShowState ) {
gpgText = StatusDefs : : name ( bestRSState ) ;
if ( ! bestCustomStateString . isEmpty ( ) ) {
gpgText + = " [ " + bestCustomStateString + " ] " ;
}
} else {
if ( ! bestCustomStateString . isEmpty ( ) ) {
gpgText = bestCustomStateString ;
}
2015-08-08 14:27:19 -04:00
}
}
} else if ( gpg_online ) {
gpgItem - > setHidden ( mHideUnconnected ) ;
2015-08-19 03:59:14 -04:00
+ + onlineCount ;
bestPeerState = PEER_STATE_AVAILABLE ;
gpgFont . setBold ( true ) ;
gpgColor = mTextColorStatus [ RS_STATUS_ONLINE ] ;
if ( showInfoAtGpgItem ) {
if ( mShowState ) {
gpgText + = tr ( " Available " ) ;
}
gpgOverlayIcon = QPixmap ( IMAGE_AVAILABLE ) ;
2015-08-08 14:27:19 -04:00
}
} else {
bestPeerState = PEER_STATE_OFFLINE ;
gpgItem - > setHidden ( mHideUnconnected ) ;
2011-10-20 18:48:50 -04:00
2015-08-19 03:59:14 -04:00
gpgFont = StatusDefs : : font ( RS_STATUS_OFFLINE ) ;
gpgColor = mTextColorStatus [ RS_STATUS_OFFLINE ] ;
if ( showInfoAtGpgItem ) {
if ( mShowState ) {
gpgText + = StatusDefs : : name ( RS_STATUS_OFFLINE ) ;
}
gpgOverlayIcon = QPixmap ( StatusDefs : : imageStatus ( RS_STATUS_OFFLINE ) ) ;
2015-08-08 14:27:19 -04:00
}
2011-10-20 18:48:50 -04:00
}
2015-08-08 14:27:19 -04:00
if ( gpg_hasPrivateChat ) {
gpgOverlayIcon = QPixmap ( " :/images/chat.png " ) ;
}
2015-05-15 10:45:44 -04:00
2015-08-08 14:27:19 -04:00
gpgItem - > setIcon ( COLUMN_NAME , createAvatar ( bestAvatar . isNull ( ) ? QPixmap ( AVATAR_DEFAULT_IMAGE ) : bestAvatar , gpgOverlayIcon ) ) ;
2015-05-15 10:45:44 -04:00
2015-08-19 03:59:14 -04:00
/* Create or get gpg label */
ElidedLabel * gpgNameLabel = NULL ;
ElidedLabel * gpgTextLabel = NULL ;
getNameWidget ( ui - > peerTreeWidget , gpgItem , gpgNameLabel , gpgTextLabel ) ;
if ( gpgNameLabel ) {
gpgNameLabel - > setText ( gpgName ) ;
gpgNameLabel - > setFont ( gpgFont ) ;
QPalette palette = gpgNameLabel - > palette ( ) ;
palette . setColor ( gpgNameLabel - > foregroundRole ( ) , gpgColor ) ;
gpgNameLabel - > setPalette ( palette ) ;
}
if ( gpgTextLabel ) {
gpgTextLabel - > setText ( gpgText ) ;
gpgTextLabel - > setVisible ( ! gpgText . isEmpty ( ) ) ;
}
2015-08-26 13:26:20 -04:00
// Filter
gpgItem - > setData ( COLUMN_NAME , ROLE_FILTER , gpgName ) ;
2015-08-19 03:59:14 -04:00
gpgItem - > setData ( COLUMN_LAST_CONTACT , Qt : : DisplayRole , showInfoAtGpgItem ? QVariant ( bestLastContact ) : " " ) ;
2016-07-30 07:58:02 -04:00
gpgItem - > setData ( COLUMN_LAST_CONTACT , ROLE_SORT_NAME , QVariant ( bestLastContact ) ) ;
2015-08-19 03:59:14 -04:00
gpgItem - > setText ( COLUMN_IP , showInfoAtGpgItem ? bestIP : " " ) ;
2016-07-30 07:58:02 -04:00
gpgItem - > setData ( COLUMN_IP , ROLE_SORT_NAME , bestIP ) ;
2015-08-08 14:27:19 -04:00
/* Sort data */
2015-08-21 18:57:26 -04:00
gpgItem - > setData ( COLUMN_NAME , ROLE_SORT_NAME , gpgName ) ;
2015-08-08 14:27:19 -04:00
2015-08-19 03:59:14 -04:00
for ( int i = 0 ; i < columnCount ; + + i ) {
2015-08-21 18:57:26 -04:00
gpgItem - > setData ( i , ROLE_SORT_STATE , bestPeerState ) ;
2015-08-19 03:59:14 -04:00
gpgItem - > setTextColor ( i , gpgColor ) ;
gpgItem - > setFont ( i , gpgFont ) ;
}
2016-11-27 06:21:14 -05:00
if ( openPeers . find ( gpgId ) ! = openPeers . end ( ) ) {
2015-08-08 14:27:19 -04:00
gpgItem - > setExpanded ( true ) ;
}
2015-05-15 10:45:44 -04:00
}
2011-10-20 18:48:50 -04:00
if ( groupInfo & & groupItem ) {
if ( ( groupInfo - > flag & RS_GROUP_FLAG_STANDARD ) & & groupItem - > childCount ( ) = = 0 ) {
// there are some dead id's assigned
groupItem - > setHidden ( true ) ;
} else {
groupItem - > setHidden ( false ) ;
QString groupName = GroupDefs : : name ( * groupInfo ) ;
groupItem - > setText ( COLUMN_NAME , QString ( " %1 (%2/%3) " ) . arg ( groupName ) . arg ( onlineCount ) . arg ( availableCount ) ) ;
2015-08-08 14:27:19 -04:00
2015-08-26 13:26:20 -04:00
// Filter
groupItem - > setData ( COLUMN_NAME , ROLE_FILTER , groupName ) ;
2015-08-08 14:27:19 -04:00
/* Sort data */
2015-08-21 18:57:26 -04:00
groupItem - > setData ( COLUMN_NAME , ROLE_SORT_NAME , groupName ) ;
2011-10-20 18:48:50 -04:00
}
}
2011-11-11 20:26:26 -05:00
if ( mShowGroups & & groupIt ! = groupInfoList . end ( ) ) {
2014-10-21 18:33:02 -04:00
+ + groupIt ;
2011-10-20 18:48:50 -04:00
} else {
// all done
break ;
}
}
2015-07-09 16:53:28 -04:00
if ( mFilterText . isEmpty ( ) = = false ) {
filterItems ( mFilterText ) ;
2011-10-20 18:48:50 -04:00
}
groupsHasChanged = false ;
2015-08-08 14:27:19 -04:00
2015-08-21 18:57:26 -04:00
ui - > peerTreeWidget - > resort ( ) ;
2011-10-20 18:48:50 -04:00
}
/**
* Returns a list with all groupIds that are expanded
*/
2016-07-05 23:49:43 -04:00
bool FriendList : : getExpandedGroups ( std : : set < RsNodeGroupId > & groups ) const
2011-10-20 18:48:50 -04:00
{
int itemCount = ui - > peerTreeWidget - > topLevelItemCount ( ) ;
2014-10-21 18:33:02 -04:00
for ( int index = 0 ; index < itemCount ; + + index ) {
2011-10-20 18:48:50 -04:00
QTreeWidgetItem * item = ui - > peerTreeWidget - > topLevelItem ( index ) ;
if ( item - > type ( ) = = TYPE_GROUP & & item - > isExpanded ( ) ) {
2016-07-05 23:49:43 -04:00
groups . insert ( RsNodeGroupId ( item - > data ( COLUMN_DATA , ROLE_ID ) . toString ( ) . toStdString ( ) ) ) ;
2011-10-20 18:48:50 -04:00
}
}
return true ;
}
/**
* Returns a list with all gpg ids that are expanded
*/
2016-11-27 06:21:14 -05:00
bool FriendList : : getExpandedPeers ( std : : set < RsPgpId > & peers ) const
2011-10-20 18:48:50 -04:00
{
peers . clear ( ) ;
QTreeWidgetItemIterator it ( ui - > peerTreeWidget ) ;
while ( * it ) {
QTreeWidgetItem * item = * it ;
if ( item - > type ( ) = = TYPE_GPG & & item - > isExpanded ( ) ) {
2016-11-27 06:21:14 -05:00
peers . insert ( peers . end ( ) , RsPgpId ( getRsId ( item ) ) ) ;
2011-10-20 18:48:50 -04:00
}
+ + it ;
}
return true ;
}
2017-03-01 15:18:16 -05:00
void FriendList : : collapseItem ( QTreeWidgetItem * item )
{
switch ( item - > type ( ) )
{
case TYPE_GROUP :
openGroups . erase ( RsNodeGroupId ( getRsId ( item ) ) ) ;
break ;
case TYPE_GPG :
openPeers . erase ( RsPgpId ( getRsId ( item ) ) ) ;
default :
break ;
}
}
void FriendList : : expandItem ( QTreeWidgetItem * item )
{
switch ( item - > type ( ) )
{
case TYPE_GROUP :
openGroups . insert ( RsNodeGroupId ( getRsId ( item ) ) ) ;
break ;
case TYPE_GPG :
openPeers . insert ( RsPgpId ( getRsId ( item ) ) ) ;
default :
break ;
}
}
2011-10-20 18:48:50 -04:00
void FriendList : : chatfriendproxy ( )
{
2017-03-01 15:18:16 -05:00
chatfriend ( getCurrentPeer ( ) ) ;
2011-10-20 18:48:50 -04:00
}
/**
* Start a chat with a friend
*
* @ param pPeer the gpg or ssl QTreeWidgetItem to chat with
*/
2014-10-25 08:26:09 -04:00
void FriendList : : chatfriend ( QTreeWidgetItem * item )
2011-10-20 18:48:50 -04:00
{
2014-10-25 08:26:09 -04:00
if ( item = = NULL ) {
2011-10-20 18:48:50 -04:00
return ;
}
2014-10-25 08:26:09 -04:00
switch ( item - > type ( ) ) {
case TYPE_GROUP :
break ;
case TYPE_GPG :
ChatDialog : : chatFriend ( RsPgpId ( getRsId ( item ) ) ) ;
break ;
case TYPE_SSL :
2014-12-29 16:41:05 -05:00
ChatDialog : : chatFriend ( ChatId ( RsPeerId ( getRsId ( item ) ) ) ) ;
2014-10-25 08:26:09 -04:00
break ;
}
2011-10-20 18:48:50 -04:00
}
void FriendList : : addFriend ( )
{
std : : string groupId = getSelectedGroupId ( ) ;
ConnectFriendWizard connwiz ( this ) ;
if ( groupId . empty ( ) = = false ) {
connwiz . setGroup ( groupId ) ;
}
connwiz . exec ( ) ;
}
void FriendList : : msgfriend ( )
{
2015-05-29 06:07:12 -04:00
QTreeWidgetItem * item = getCurrentPeer ( ) ;
2011-10-20 18:48:50 -04:00
2015-05-29 06:07:12 -04:00
if ( ! item )
2011-10-20 18:48:50 -04:00
return ;
2015-05-29 06:07:12 -04:00
switch ( item - > type ( ) ) {
case TYPE_GROUP :
break ;
case TYPE_GPG :
MessageComposer : : msgFriend ( RsPgpId ( getRsId ( item ) ) ) ;
break ;
case TYPE_SSL :
MessageComposer : : msgFriend ( RsPeerId ( getRsId ( item ) ) ) ;
break ;
}
2011-10-20 18:48:50 -04:00
}
void FriendList : : recommendfriend ( )
{
QTreeWidgetItem * peer = getCurrentPeer ( ) ;
if ( ! peer )
return ;
2012-01-23 17:38:50 -05:00
std : : string peerId = getRsId ( peer ) ;
2014-03-17 16:56:06 -04:00
std : : list < RsPeerId > ids ;
2012-01-23 17:38:50 -05:00
2014-03-17 16:56:06 -04:00
switch ( peer - > type ( ) )
{
2012-01-23 17:38:50 -05:00
case TYPE_SSL :
2014-03-17 16:56:06 -04:00
ids . push_back ( RsPeerId ( peerId ) ) ;
2012-01-23 17:38:50 -05:00
break ;
case TYPE_GPG :
2014-03-17 16:56:06 -04:00
rsPeers - > getAssociatedSSLIds ( RsPgpId ( peerId ) , ids ) ;
2012-01-23 17:38:50 -05:00
break ;
default :
return ;
}
2015-04-17 17:36:22 -04:00
std : : set < RsPeerId > sids ;
for ( std : : list < RsPeerId > : : const_iterator it ( ids . begin ( ) ) ; it ! = ids . end ( ) ; + + it )
sids . insert ( * it ) ;
2012-01-23 17:38:50 -05:00
2015-04-17 17:36:22 -04:00
MessageComposer : : recommendFriend ( sids ) ;
2011-10-20 18:48:50 -04:00
}
void FriendList : : pastePerson ( )
{
2013-09-27 17:40:51 -04:00
//RSLinkClipboard::process(RetroShareLink::TYPE_PERSON);
2012-03-30 15:43:39 -04:00
RSLinkClipboard : : process ( RetroShareLink : : TYPE_CERTIFICATE ) ;
2011-10-20 18:48:50 -04:00
}
2012-01-18 15:31:30 -05:00
void FriendList : : copyFullCertificate ( )
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
QList < RetroShareLink > urls ;
2017-07-16 07:11:47 -04:00
RetroShareLink link = RetroShareLink : : createCertificate ( RsPeerId ( getRsId ( c ) ) ) ;
2012-01-18 15:31:30 -05:00
urls . push_back ( link ) ;
std : : cerr < < " link: " < < std : : endl ;
std : : cerr < < link . toString ( ) . toStdString ( ) < < std : : endl ;
2017-07-16 07:11:47 -04:00
2012-01-18 15:31:30 -05:00
RSLinkClipboard : : copyLinks ( urls ) ;
}
2013-09-27 17:40:51 -04:00
// void FriendList::copyLink()
// {
// QTreeWidgetItem *c = getCurrentPeer();
//
// if (c == NULL) {
// return;
// }
//
// QList<RetroShareLink> urls;
// RetroShareLink link;
// if (link.createPerson(getRsId(c))) {
// urls.push_back(link);
// }
//
// RSLinkClipboard::copyLinks(urls);
// }
2011-10-20 18:48:50 -04:00
/**
* Find out which group is selected
*
* @ return If a group item is selected , its groupId otherwise an empty string
*/
std : : string FriendList : : getSelectedGroupId ( ) const
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
if ( c & & c - > type ( ) = = TYPE_GROUP ) {
return getRsId ( c ) ;
}
return std : : string ( ) ;
}
QTreeWidgetItem * FriendList : : getCurrentPeer ( ) const
{
/* get the current, and extract the Id */
QTreeWidgetItem * item = ui - > peerTreeWidget - > currentItem ( ) ;
# ifdef FRIENDS_DEBUG
if ( ! item )
{
std : : cerr < < " Invalid Current Item " < < std : : endl ;
return NULL ;
}
/* Display the columns of this item. */
2012-03-28 14:02:49 -04:00
QString out = " CurrentPeerItem: \n " ;
2011-10-20 18:48:50 -04:00
2014-10-21 18:33:02 -04:00
for ( int i = 1 ; i < COLUMN_COUNT ; + + i )
2011-10-20 18:48:50 -04:00
{
QString txt = item - > text ( i ) ;
2012-03-28 14:02:49 -04:00
out + = QString ( " \t %1:%2 \n " ) . arg ( i ) . arg ( txt ) ;
2011-10-20 18:48:50 -04:00
}
2012-03-28 14:02:49 -04:00
std : : cerr < < out . toStdString ( ) ;
2011-10-20 18:48:50 -04:00
# endif
return item ;
}
2012-02-13 13:43:15 -05:00
# ifdef UNFINISHED_FD
2011-10-20 18:48:50 -04:00
/* GUI stuff -> don't do anything directly with Control */
void FriendsDialog : : viewprofile ( )
{
/* display Dialog */
QTreeWidgetItem * c = getCurrentPeer ( ) ;
// static ProfileView *profileview = new ProfileView();
if ( ! c )
return ;
/* set the Id */
std : : string id = getRsId ( c ) ;
profileview - > setPeerId ( id ) ;
profileview - > show ( ) ;
}
# endif
/* So from the Peers Dialog we can call the following control Functions:
* ( 1 ) Remove Current . FriendRemove ( id )
* ( 2 ) Allow / DisAllow . FriendStatus ( id , accept )
* ( 2 ) Connect . FriendConnectAttempt ( id , accept )
* ( 3 ) Set Address . FriendSetAddress ( id , str , port )
* ( 4 ) Set Trust . FriendTrustSignature ( id , bool )
* ( 5 ) Configure ( GUI Only ) - > 3 / 4
*
* All of these rely on the finding of the current Id .
*/
void FriendList : : removefriend ( )
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
# ifdef FRIENDS_DEBUG
std : : cerr < < " FriendList::removefriend() " < < std : : endl ;
# endif
if ( ! c )
{
# ifdef FRIENDS_DEBUG
std : : cerr < < " FriendList::removefriend() None Selected -- sorry " < < std : : endl ;
# endif
return ;
}
if ( rsPeers )
{
2015-01-23 19:59:32 -05:00
switch ( c - > type ( ) ) {
case TYPE_GPG :
if ( ! RsPgpId ( getRsId ( c ) ) . isNull ( ) ) {
if ( ( QMessageBox : : question ( this , " RetroShare " , tr ( " Do you want to remove this Friend? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) ) = = QMessageBox : : Yes )
{
rsPeers - > removeFriend ( RsPgpId ( getRsId ( c ) ) ) ;
}
}
break ;
case TYPE_SSL :
if ( ! RsPeerId ( getRsId ( c ) ) . isNull ( ) ) {
if ( ( QMessageBox : : question ( this , " RetroShare " , tr ( " Do you want to remove this node? " ) , QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) ) = = QMessageBox : : Yes )
{
rsPeers - > removeFriendLocation ( RsPeerId ( getRsId ( c ) ) ) ;
}
}
break ;
2011-10-20 18:48:50 -04:00
}
}
}
void FriendList : : connectfriend ( )
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
# ifdef FRIENDS_DEBUG
std : : cerr < < " FriendList::connectfriend() " < < std : : endl ;
# endif
if ( ! c )
{
# ifdef FRIENDS_DEBUG
std : : cerr < < " FriendList::connectfriend() None Selected -- sorry " < < std : : endl ;
# endif
return ;
}
if ( rsPeers )
{
if ( c - > type ( ) = = TYPE_GPG ) {
int childCount = c - > childCount ( ) ;
2014-10-21 18:33:02 -04:00
for ( int childIndex = 0 ; childIndex < childCount ; + + childIndex ) {
2011-10-20 18:48:50 -04:00
QTreeWidgetItem * item = c - > child ( childIndex ) ;
if ( item - > type ( ) = = TYPE_SSL ) {
2014-03-17 16:56:06 -04:00
rsPeers - > connectAttempt ( RsPeerId ( getRsId ( item ) ) ) ;
2013-08-26 03:24:37 -04:00
// Launch ProgressDialog, only if single SSL child.
if ( childCount = = 1 )
{
2014-03-17 16:56:06 -04:00
ConnectProgressDialog : : showProgress ( RsPeerId ( getRsId ( item ) ) ) ;
2013-08-26 03:24:37 -04:00
}
2011-10-20 18:48:50 -04:00
}
}
} else {
//this is a SSL key
2014-03-17 16:56:06 -04:00
rsPeers - > connectAttempt ( RsPeerId ( getRsId ( c ) ) ) ;
2013-08-26 03:24:37 -04:00
// Launch ProgressDialog.
2014-03-17 16:56:06 -04:00
ConnectProgressDialog : : showProgress ( RsPeerId ( getRsId ( c ) ) ) ;
2011-10-20 18:48:50 -04:00
}
}
}
/* GUI stuff -> don't do anything directly with Control */
void FriendList : : configurefriend ( )
{
2014-03-17 16:56:06 -04:00
if ( ! RsPeerId ( getRsId ( getCurrentPeer ( ) ) ) . isNull ( ) )
ConfCertDialog : : showIt ( RsPeerId ( getRsId ( getCurrentPeer ( ) ) ) , ConfCertDialog : : PageDetails ) ;
else if ( ! RsPgpId ( getRsId ( getCurrentPeer ( ) ) ) . isNull ( ) )
2015-05-12 16:30:44 -04:00
PGPKeyDialog : : showIt ( RsPgpId ( getRsId ( getCurrentPeer ( ) ) ) , PGPKeyDialog : : PageDetails ) ;
2014-03-17 16:56:06 -04:00
else
std : : cerr < < " FriendList::configurefriend: id is not an SSL nor a PGP id. " < < std : : endl ;
2011-10-20 18:48:50 -04:00
}
2013-07-16 18:33:45 -04:00
// void FriendList::showLobby()
// {
// std::string lobby_id = qobject_cast<QAction*>(sender())->data().toString().toStdString();
//
// if (lobby_id.empty())
// return;
//
// std::string vpeer_id;
//
// if (rsMsgs->getVirtualPeerId(ChatLobbyId(QString::fromStdString(lobby_id).toULongLong()), vpeer_id))
// ChatDialog::chatFriend(vpeer_id);
// }
//
// void FriendList::unsubscribeToLobby()
// {
// std::string lobby_id = qobject_cast<QAction*>(sender())->data().toString().toStdString();
//
// if (lobby_id.empty())
// return;
//
// std::string vpeer_id ;
// rsMsgs->getVirtualPeerId (ChatLobbyId(QString::fromStdString(lobby_id).toULongLong()), vpeer_id);
//
// if (QMessageBox::Ok == QMessageBox::question(this,tr("Unsubscribe to lobby"),tr("You are about to unsubscribe a chat lobby<br>You can only re-enter if your friends invite you again."),QMessageBox::Ok | QMessageBox::Cancel))
// rsMsgs->unsubscribeChatLobby(ChatLobbyId(QString::fromStdString(lobby_id).toULongLong())) ;
//
// // we should also close existing windows.
// ChatDialog::closeChat(vpeer_id);
// }
2011-12-27 08:47:37 -05:00
2014-03-17 16:56:06 -04:00
void FriendList : : getSslIdsFromItem ( QTreeWidgetItem * item , std : : list < RsPeerId > & sslIds )
2011-11-23 17:10:37 -05:00
{
2012-01-27 15:53:17 -05:00
if ( item = = NULL ) {
2011-11-23 17:10:37 -05:00
return ;
}
2012-01-27 15:53:17 -05:00
std : : string peerId = getRsId ( item ) ;
switch ( item - > type ( ) ) {
case TYPE_SSL :
2014-03-17 16:56:06 -04:00
sslIds . push_back ( RsPeerId ( peerId ) ) ;
2012-01-27 15:53:17 -05:00
break ;
case TYPE_GPG :
2014-03-17 16:56:06 -04:00
rsPeers - > getAssociatedSSLIds ( RsPgpId ( peerId ) , sslIds ) ;
2012-01-27 15:53:17 -05:00
break ;
case TYPE_GROUP :
{
RsGroupInfo groupInfo ;
2016-07-05 23:49:43 -04:00
if ( rsPeers - > getGroupInfo ( RsNodeGroupId ( peerId ) , groupInfo ) ) {
2015-04-17 17:36:22 -04:00
std : : set < RsPgpId > : : iterator gpgIt ;
2012-01-27 15:53:17 -05:00
for ( gpgIt = groupInfo . peerIds . begin ( ) ; gpgIt ! = groupInfo . peerIds . end ( ) ; + + gpgIt ) {
rsPeers - > getAssociatedSSLIds ( * gpgIt , sslIds ) ;
}
}
}
break ;
2011-11-23 17:10:37 -05:00
}
2012-01-27 15:53:17 -05:00
}
2011-10-20 18:48:50 -04:00
void FriendList : : addToGroup ( )
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
if ( c = = NULL ) {
return ;
}
if ( c - > type ( ) ! = TYPE_GPG ) {
// wrong type
return ;
}
2016-07-05 23:49:43 -04:00
RsNodeGroupId groupId ( qobject_cast < QAction * > ( sender ( ) ) - > data ( ) . toString ( ) . toStdString ( ) ) ;
2014-03-17 16:56:06 -04:00
RsPgpId gpgId ( getRsId ( c ) ) ;
2011-10-20 18:48:50 -04:00
2016-07-05 23:49:43 -04:00
if ( gpgId . isNull ( ) | | groupId . isNull ( ) ) {
2011-10-20 18:48:50 -04:00
return ;
}
// automatically expand the group, the peer is added to
addGroupToExpand ( groupId ) ;
// add to group
rsPeers - > assignPeerToGroup ( groupId , gpgId , true ) ;
}
void FriendList : : moveToGroup ( )
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
if ( c = = NULL ) {
return ;
}
if ( c - > type ( ) ! = TYPE_GPG ) {
// wrong type
return ;
}
2016-07-05 23:49:43 -04:00
RsNodeGroupId groupId ( qobject_cast < QAction * > ( sender ( ) ) - > data ( ) . toString ( ) . toStdString ( ) ) ;
2014-03-17 16:56:06 -04:00
RsPgpId gpgId ( getRsId ( c ) ) ;
2011-10-20 18:48:50 -04:00
2016-07-05 23:49:43 -04:00
if ( gpgId . isNull ( ) | | groupId . isNull ( ) ) {
2011-10-20 18:48:50 -04:00
return ;
}
// remove from all groups
2016-07-05 23:49:43 -04:00
rsPeers - > assignPeerToGroup ( RsNodeGroupId ( ) , gpgId , false ) ;
2011-10-20 18:48:50 -04:00
// automatically expand the group, the peer is added to
addGroupToExpand ( groupId ) ;
// add to group
rsPeers - > assignPeerToGroup ( groupId , gpgId , true ) ;
}
void FriendList : : removeFromGroup ( )
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
if ( c = = NULL ) {
return ;
}
if ( c - > type ( ) ! = TYPE_GPG ) {
// wrong type
return ;
}
2016-07-05 23:49:43 -04:00
RsNodeGroupId groupId ( qobject_cast < QAction * > ( sender ( ) ) - > data ( ) . toString ( ) . toStdString ( ) ) ;
2014-03-17 16:56:06 -04:00
RsPgpId gpgId ( getRsId ( c ) ) ;
2011-10-20 18:48:50 -04:00
2014-03-17 16:56:06 -04:00
if ( gpgId . isNull ( ) ) {
2011-10-20 18:48:50 -04:00
return ;
}
// remove from (all) group(s)
rsPeers - > assignPeerToGroup ( groupId , gpgId , false ) ;
}
void FriendList : : editGroup ( )
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
if ( c = = NULL ) {
return ;
}
if ( c - > type ( ) ! = TYPE_GROUP ) {
// wrong type
return ;
}
2016-07-05 23:49:43 -04:00
RsNodeGroupId groupId ( getRsId ( c ) ) ;
2011-10-20 18:48:50 -04:00
2016-07-05 23:49:43 -04:00
if ( ! groupId . isNull ( ) )
{
CreateGroup editGrpDialog ( groupId , this ) ;
editGrpDialog . exec ( ) ;
2011-10-20 18:48:50 -04:00
}
}
void FriendList : : removeGroup ( )
{
QTreeWidgetItem * c = getCurrentPeer ( ) ;
if ( c = = NULL ) {
return ;
}
if ( c - > type ( ) ! = TYPE_GROUP ) {
// wrong type
return ;
}
2016-07-05 23:49:43 -04:00
RsNodeGroupId groupId ( getRsId ( c ) ) ;
2011-10-20 18:48:50 -04:00
2016-07-05 23:49:43 -04:00
if ( ! groupId . isNull ( ) )
rsPeers - > removeGroup ( groupId ) ;
2011-10-20 18:48:50 -04:00
}
2015-08-18 17:05:22 -04:00
void FriendList : : exportFriendlistClicked ( )
{
QString fileName ;
if ( ! importExportFriendlistFileDialog ( fileName , false ) )
// error was already shown - just return
return ;
if ( ! exportFriendlist ( fileName ) )
// error was already shown - just return
return ;
QMessageBox mbox ;
mbox . setIcon ( QMessageBox : : Information ) ;
mbox . setText ( tr ( " Done! " ) ) ;
2015-08-19 13:02:28 -04:00
mbox . setInformativeText ( tr ( " Your friendlist is stored at: \n " ) + fileName +
tr ( " \n (keep in mind that the file is unencrypted!) " ) ) ;
2015-08-18 17:05:22 -04:00
mbox . setStandardButtons ( QMessageBox : : Ok ) ;
mbox . exec ( ) ;
}
void FriendList : : importFriendlistClicked ( )
{
QString fileName ;
if ( ! importExportFriendlistFileDialog ( fileName , true ) )
// error was already shown - just return
return ;
bool errorPeers , errorGroups ;
if ( importFriendlist ( fileName , errorPeers , errorGroups ) ) {
QMessageBox mbox ;
mbox . setIcon ( QMessageBox : : Information ) ;
mbox . setText ( tr ( " Done! " ) ) ;
2015-08-19 13:02:28 -04:00
mbox . setInformativeText ( tr ( " Your friendlist was imported from: \n " ) + fileName ) ;
2015-08-18 17:05:22 -04:00
mbox . setStandardButtons ( QMessageBox : : Ok ) ;
mbox . exec ( ) ;
} else {
QMessageBox mbox ;
mbox . setIcon ( QMessageBox : : Warning ) ;
mbox . setText ( tr ( " Done - but errors happened! " ) ) ;
2015-08-19 13:02:28 -04:00
mbox . setInformativeText ( tr ( " Your friendlist was imported from: \n " ) + fileName +
( errorPeers ? tr ( " \n at least one peer was not added " ) : " " ) +
( errorGroups ? tr ( " \n at least one peer was not added to a group " ) : " " )
2015-08-18 17:05:22 -04:00
) ;
mbox . setStandardButtons ( QMessageBox : : Ok ) ;
mbox . exec ( ) ;
}
}
/**
* @ brief opens a file dialog to select a file containing a friendlist
* @ param fileName file containing a friendlist
* @ param import show dialog for importing ( true ) or exporting ( false ) friendlist
* @ return success or failure
*
* This function also shows an error message when no valid file was selected
*/
bool FriendList : : importExportFriendlistFileDialog ( QString & fileName , bool import )
{
2017-05-01 06:48:11 -04:00
bool res = true ;
if ( import ) {
res = misc : : getOpenFileName ( this , RshareSettings : : LASTDIR_CERT
, tr ( " Select file for importing your friendlist from " )
, tr ( " XML File (*.xml);;All Files (*) " )
, fileName
, QFileDialog : : DontConfirmOverwrite
) ;
} else {
res = misc : : getSaveFileName ( this , RshareSettings : : LASTDIR_CERT
, tr ( " Select a file for exporting your friendlist to " )
, tr ( " XML File (*.xml);;All Files (*) " )
, fileName , NULL
, ( QFileDialog : : Options ) 0
) ;
}
if ( res & & ! fileName . endsWith ( " .xml " , Qt : : CaseInsensitive ) )
fileName = fileName . append ( " .xml " ) ;
return res ;
2015-08-18 17:05:22 -04:00
}
/**
* @ brief exports friendlist to a given file
* @ param fileName file for storing friendlist
* @ return success or failure
*
* This function also shows an error message when the selected file is invalid / not writable
*/
bool FriendList : : exportFriendlist ( QString & fileName )
{
2015-08-19 13:02:28 -04:00
QDomDocument doc ( " FriendListWithGroups " ) ;
QDomElement root = doc . createElement ( " root " ) ;
doc . appendChild ( root ) ;
QFile file ( fileName ) ;
if ( ! file . open ( QIODevice : : WriteOnly | QIODevice : : Truncate | QIODevice : : Text ) ) {
2015-08-18 17:05:22 -04:00
// show error to user
QMessageBox mbox ;
mbox . setIcon ( QMessageBox : : Warning ) ;
mbox . setText ( tr ( " Error " ) ) ;
2015-08-19 13:02:28 -04:00
mbox . setInformativeText ( tr ( " File is not writeable! \n " ) + fileName ) ;
2015-08-18 17:05:22 -04:00
mbox . setStandardButtons ( QMessageBox : : Ok ) ;
mbox . exec ( ) ;
return false ;
}
std : : list < RsPgpId > gpg_ids ;
rsPeers - > getGPGAcceptedList ( gpg_ids ) ;
std : : list < RsGroupInfo > group_info_list ;
rsPeers - > getGroupInfoList ( group_info_list ) ;
2015-08-19 13:02:28 -04:00
QDomElement pgpIDs = doc . createElement ( " pgpIDs " ) ;
2015-08-23 03:58:31 -04:00
RsPeerDetails detailPGP ;
2015-08-18 17:05:22 -04:00
for ( std : : list < RsPgpId > : : iterator list_iter = gpg_ids . begin ( ) ; list_iter ! = gpg_ids . end ( ) ; list_iter + + ) {
2015-08-23 03:58:31 -04:00
rsPeers - > getGPGDetails ( * list_iter , detailPGP ) ;
2015-08-19 13:02:28 -04:00
QDomElement pgpID = doc . createElement ( " pgpID " ) ;
// these values aren't used and just stored for better human readability
2015-08-23 03:58:31 -04:00
pgpID . setAttribute ( " id " , QString : : fromStdString ( detailPGP . gpg_id . toStdString ( ) ) ) ;
pgpID . setAttribute ( " name " , QString : : fromUtf8 ( detailPGP . name . c_str ( ) ) ) ;
2015-08-19 13:02:28 -04:00
2015-08-18 17:05:22 -04:00
std : : list < RsPeerId > ssl_ids ;
rsPeers - > getAssociatedSSLIds ( * list_iter , ssl_ids ) ;
for ( std : : list < RsPeerId > : : iterator list_iter = ssl_ids . begin ( ) ; list_iter ! = ssl_ids . end ( ) ; list_iter + + ) {
2015-08-23 03:58:31 -04:00
RsPeerDetails detailSSL ;
if ( ! rsPeers - > getPeerDetails ( * list_iter , detailSSL ) )
2015-08-18 17:05:22 -04:00
continue ;
2015-08-23 10:43:34 -04:00
std : : string certificate = rsPeers - > GetRetroshareInvite ( detailSSL . id , true ) ;
// remove \n from certificate
certificate . erase ( std : : remove ( certificate . begin ( ) , certificate . end ( ) , ' \n ' ) , certificate . end ( ) ) ;
2015-08-18 17:05:22 -04:00
2015-08-19 13:02:28 -04:00
QDomElement sslID = doc . createElement ( " sslID " ) ;
// these values aren't used and just stored for better human readability
2015-08-23 03:58:31 -04:00
sslID . setAttribute ( " sslID " , QString : : fromStdString ( detailSSL . id . toStdString ( ) ) ) ;
if ( ! detailSSL . location . empty ( ) )
sslID . setAttribute ( " location " , QString : : fromUtf8 ( detailSSL . location . c_str ( ) ) ) ;
2015-08-19 13:02:28 -04:00
// required values
2015-08-23 10:43:34 -04:00
sslID . setAttribute ( " certificate " , QString : : fromStdString ( certificate ) ) ;
2015-08-23 03:58:31 -04:00
sslID . setAttribute ( " service_perm_flags " , detailSSL . service_perm_flags . toUInt32 ( ) ) ;
2015-08-19 13:02:28 -04:00
pgpID . appendChild ( sslID ) ;
}
pgpIDs . appendChild ( pgpID ) ;
2015-08-18 17:05:22 -04:00
}
2015-08-19 13:02:28 -04:00
root . appendChild ( pgpIDs ) ;
2015-08-18 17:05:22 -04:00
2015-08-19 13:02:28 -04:00
QDomElement groups = doc . createElement ( " groups " ) ;
2015-08-18 17:05:22 -04:00
for ( std : : list < RsGroupInfo > : : iterator list_iter = group_info_list . begin ( ) ; list_iter ! = group_info_list . end ( ) ; list_iter + + ) {
RsGroupInfo group_info = * list_iter ;
2015-08-19 13:02:28 -04:00
//skip groups without peers
if ( group_info . peerIds . empty ( ) )
continue ;
QDomElement group = doc . createElement ( " group " ) ;
2015-08-18 17:05:22 -04:00
// id is not needed since it may differ between locatiosn / pgp ids (groups are identified by name)
2015-08-19 13:12:38 -04:00
group . setAttribute ( " name " , QString : : fromUtf8 ( group_info . name . c_str ( ) ) ) ;
2015-08-19 13:02:28 -04:00
group . setAttribute ( " flag " , group_info . flag ) ;
2015-08-18 17:05:22 -04:00
for ( std : : set < RsPgpId > : : iterator i = group_info . peerIds . begin ( ) ; i ! = group_info . peerIds . end ( ) ; i + + ) {
2015-08-19 13:02:28 -04:00
QDomElement pgpID = doc . createElement ( " pgpID " ) ;
2015-08-18 17:05:22 -04:00
std : : string pid = i - > toStdString ( ) ;
2015-08-19 13:02:28 -04:00
pgpID . setAttribute ( " id " , QString : : fromStdString ( pid ) ) ;
group . appendChild ( pgpID ) ;
2015-08-18 17:05:22 -04:00
}
2015-08-19 13:02:28 -04:00
groups . appendChild ( group ) ;
2015-08-18 17:05:22 -04:00
}
2015-08-19 13:02:28 -04:00
root . appendChild ( groups ) ;
QTextStream ts ( & file ) ;
ts . setCodec ( " UTF-8 " ) ;
ts < < doc . toString ( ) ;
file . close ( ) ;
2015-08-18 17:05:22 -04:00
return true ;
}
2015-08-19 13:02:28 -04:00
/**
* @ brief helper function to show a message box
*/
void showXMLParsingError ( )
{
// show error to user
QMessageBox mbox ;
mbox . setIcon ( QMessageBox : : Warning ) ;
mbox . setText ( QObject : : tr ( " Error " ) ) ;
mbox . setInformativeText ( QObject : : tr ( " unable to parse XML file! " ) ) ;
mbox . setStandardButtons ( QMessageBox : : Ok ) ;
mbox . exec ( ) ;
}
2015-08-18 17:05:22 -04:00
/**
* @ brief Imports friends from a given file
* @ param fileName file to load friends from
* @ param errorPeers an error occured while adding a peer
* @ param errorGroups an error occured while adding a peer to a group
2015-08-19 13:02:28 -04:00
* @ return success or failure ( an error can also happen when adding a peer and / or adding a peer to a group fails at least once )
2015-08-18 17:05:22 -04:00
*/
bool FriendList : : importFriendlist ( QString & fileName , bool & errorPeers , bool & errorGroups )
{
2015-08-19 13:02:28 -04:00
QDomDocument doc ;
// load from file
{
QFile file ( fileName ) ;
if ( ! file . open ( QIODevice : : ReadOnly ) ) {
// show error to user
QMessageBox mbox ;
mbox . setIcon ( QMessageBox : : Warning ) ;
mbox . setText ( tr ( " Error " ) ) ;
mbox . setInformativeText ( tr ( " File is not readable! \n " ) + fileName ) ;
mbox . setStandardButtons ( QMessageBox : : Ok ) ;
mbox . exec ( ) ;
return false ;
}
bool ok = doc . setContent ( & file ) ;
file . close ( ) ;
if ( ! ok ) {
showXMLParsingError ( ) ;
return false ;
}
}
QDomElement root = doc . documentElement ( ) ;
if ( root . tagName ( ) ! = " root " ) {
showXMLParsingError ( ) ;
return false ;
}
2015-08-18 17:05:22 -04:00
errorPeers = false ;
errorGroups = false ;
uint32_t error_code ;
std : : string error_string ;
RsPeerDetails rsPeerDetails ;
RsPeerId rsPeerID ;
RsPgpId rsPgpID ;
// lock all events for faster processing
RsAutoUpdatePage : : lockAllEvents ( ) ;
2015-08-19 13:02:28 -04:00
// pgp and ssl IDs
QDomElement pgpIDs ;
{
QDomNodeList nodes = root . elementsByTagName ( " pgpIDs " ) ;
if ( nodes . isEmpty ( ) | | nodes . size ( ) ! = 1 ) {
showXMLParsingError ( ) ;
return false ;
}
2015-08-18 17:05:22 -04:00
2015-08-19 13:02:28 -04:00
pgpIDs = nodes . item ( 0 ) . toElement ( ) ;
if ( pgpIDs . isNull ( ) ) {
showXMLParsingError ( ) ;
return false ;
}
}
QDomNode pgpIDElem = pgpIDs . firstChildElement ( " pgpID " ) ;
while ( ! pgpIDElem . isNull ( ) ) {
QDomElement sslIDElem = pgpIDElem . firstChildElement ( " sslID " ) ;
while ( ! sslIDElem . isNull ( ) ) {
2015-08-18 17:05:22 -04:00
rsPeerID . clear ( ) ;
rsPgpID . clear ( ) ;
// load everything needed from the pubkey string
2015-08-23 03:55:43 -04:00
std : : string pubkey = sslIDElem . attribute ( " certificate " ) . toStdString ( ) ;
2015-08-18 17:05:22 -04:00
if ( rsPeers - > loadDetailsFromStringCert ( pubkey , rsPeerDetails , error_code ) ) {
if ( rsPeers - > loadCertificateFromString ( pubkey , rsPeerID , rsPgpID , error_string ) ) {
2015-08-19 13:02:28 -04:00
ServicePermissionFlags service_perm_flags ( sslIDElem . attribute ( " service_perm_flags " ) . toInt ( ) ) ;
2015-08-18 17:05:22 -04:00
// everything is loaded - start setting things
if ( ! rsPeerDetails . id . isNull ( ) & & ! rsPeerDetails . gpg_id . isNull ( ) ) {
// pgp and ssl ID are available
rsPeers - > addFriend ( rsPeerDetails . id , rsPeerDetails . gpg_id , service_perm_flags ) ;
if ( rsPeerDetails . isHiddenNode ) {
// for hidden notes
if ( ! rsPeerDetails . hiddenNodeAddress . empty ( ) & & rsPeerDetails . hiddenNodePort )
rsPeers - > setHiddenNode ( rsPeerDetails . id , rsPeerDetails . hiddenNodeAddress , rsPeerDetails . hiddenNodePort ) ;
} else {
// for normal nodes
if ( ! rsPeerDetails . extAddr . empty ( ) & & rsPeerDetails . extPort )
rsPeers - > setExtAddress ( rsPeerDetails . id , rsPeerDetails . extAddr , rsPeerDetails . extPort ) ;
if ( ! rsPeerDetails . localAddr . empty ( ) & & rsPeerDetails . localPort )
rsPeers - > setLocalAddress ( rsPeerDetails . id , rsPeerDetails . localAddr , rsPeerDetails . localPort ) ;
if ( ! rsPeerDetails . dyndns . empty ( ) )
rsPeers - > setDynDNS ( rsPeerDetails . id , rsPeerDetails . dyndns ) ;
if ( ! rsPeerDetails . location . empty ( ) )
rsPeers - > setLocation ( rsPeerDetails . id , rsPeerDetails . location ) ;
}
} else if ( ! rsPeerDetails . gpg_id . isNull ( ) ) {
// only pgp id is avaiable
RsPeerId pid ;
rsPeers - > addFriend ( pid , rsPeerDetails . gpg_id , service_perm_flags ) ;
} else {
errorPeers = true ;
2015-08-19 13:02:28 -04:00
std : : cerr < < " FriendList::importFriendlist(): error while processing SSL id: " < < sslIDElem . attribute ( " sslID " , " invalid " ) . toStdString ( ) < < std : : endl ;
2015-08-18 17:05:22 -04:00
}
} else {
errorPeers = true ;
2015-08-19 13:02:28 -04:00
std : : cerr < < " FriendList::importFriendlist(): failed to get peer detaisl from public key (SSL id: " < < sslIDElem . attribute ( " sslID " , " invalid " ) . toStdString ( ) < < " - error: " < < error_string < < " ) " < < std : : endl ;
2015-08-18 17:05:22 -04:00
}
} else {
errorPeers = true ;
2015-08-19 13:02:28 -04:00
std : : cerr < < " FriendList::importFriendlist(): failed to get peer detaisl from public key (SSL id: " < < sslIDElem . attribute ( " sslID " , " invalid " ) . toStdString ( ) < < " - error: " < < error_code < < " ) " < < std : : endl ;
2015-08-18 17:05:22 -04:00
}
2015-08-19 13:02:28 -04:00
sslIDElem = sslIDElem . nextSiblingElement ( " sslID " ) ;
2015-08-18 17:05:22 -04:00
}
2015-08-19 13:02:28 -04:00
pgpIDElem = pgpIDElem . nextSiblingElement ( " pgpID " ) ;
2015-08-18 17:05:22 -04:00
}
2015-08-19 13:02:28 -04:00
// groups
QDomElement groups ;
{
QDomNodeList nodes = root . elementsByTagName ( " groups " ) ;
if ( nodes . isEmpty ( ) | | nodes . size ( ) ! = 1 ) {
showXMLParsingError ( ) ;
return false ;
}
2015-08-18 17:05:22 -04:00
2015-08-19 13:02:28 -04:00
groups = nodes . item ( 0 ) . toElement ( ) ;
if ( groups . isNull ( ) ) {
showXMLParsingError ( ) ;
return false ;
}
}
QDomElement group = groups . firstChildElement ( " group " ) ;
while ( ! group . isNull ( ) ) {
2015-08-18 17:05:22 -04:00
// get name and flags and try to get the group ID
2015-08-19 13:02:28 -04:00
std : : string groupName = group . attribute ( " name " ) . toStdString ( ) ;
uint32_t flag = group . attribute ( " flag " ) . toInt ( ) ;
2016-07-05 23:49:43 -04:00
RsNodeGroupId groupId ;
2015-08-18 17:05:22 -04:00
if ( getOrCreateGroup ( groupName , flag , groupId ) ) {
// group id found!
2015-08-19 13:02:28 -04:00
QDomElement pgpID = group . firstChildElement ( " pgpID " ) ;
while ( ! pgpID . isNull ( ) ) {
2015-08-18 17:05:22 -04:00
// add pgp id to group
2015-08-19 13:02:28 -04:00
RsPgpId rsPgpId ( pgpID . attribute ( " id " ) . toStdString ( ) ) ;
if ( rsPgpID . isNull ( ) | | ! rsPeers - > assignPeerToGroup ( groupId , rsPgpId , true ) ) {
2015-08-18 17:17:29 -04:00
errorGroups = true ;
2015-08-18 17:05:22 -04:00
std : : cerr < < " FriendList::importFriendlist(): failed to add ' " < < rsPeers - > getGPGName ( rsPgpId ) < < " '' to group ' " < < groupName < < " ' " < < std : : endl ;
}
2015-08-19 13:02:28 -04:00
pgpID = pgpID . nextSiblingElement ( " pgpID " ) ;
2015-08-18 17:05:22 -04:00
}
2015-08-19 13:02:28 -04:00
pgpID = pgpID . nextSiblingElement ( " pgpID " ) ;
2015-08-18 17:05:22 -04:00
} else {
errorGroups = true ;
std : : cerr < < " FriendList::importFriendlist(): failed to find/create group ' " < < groupName < < " ' " < < std : : endl ;
}
2015-08-19 13:02:28 -04:00
group = group . nextSiblingElement ( " group " ) ;
2015-08-18 17:05:22 -04:00
}
// unlock events
RsAutoUpdatePage : : unlockAllEvents ( ) ;
return ! ( errorPeers | | errorGroups ) ;
}
/**
* @ brief Gets the groups ID for a given group name
* @ param name group name to search for
* @ param id groupd id for the given name
* @ return success or fail
*/
2016-07-05 23:49:43 -04:00
bool FriendList : : getGroupIdByName ( const std : : string & name , RsNodeGroupId & id )
2015-08-18 17:05:22 -04:00
{
std : : list < RsGroupInfo > grpList ;
if ( ! rsPeers - > getGroupInfoList ( grpList ) )
return false ;
foreach ( const RsGroupInfo & grp , grpList ) {
if ( grp . name = = name ) {
id = grp . id ;
return true ;
}
}
return false ;
}
/**
* @ brief Gets the groups ID for a given group name . If no groupd was it will create one
* @ param name group name to search for
* @ param flag flag to use when creating the group
* @ param id groupd id
* @ return success or failure
*/
2016-07-05 23:49:43 -04:00
bool FriendList : : getOrCreateGroup ( const std : : string & name , const uint & flag , RsNodeGroupId & id )
2015-08-18 17:05:22 -04:00
{
if ( getGroupIdByName ( name , id ) )
return true ;
// -> create one
RsGroupInfo grp ;
2016-07-05 23:49:43 -04:00
grp . id . clear ( ) ; // RS will generate an ID
2015-08-18 17:05:22 -04:00
grp . name = name ;
grp . flag = flag ;
if ( ! rsPeers - > addGroup ( grp ) )
return false ;
// try again
return getGroupIdByName ( name , id ) ;
}
2011-11-11 20:26:26 -05:00
void FriendList : : setHideUnconnected ( bool hidden )
{
2011-10-20 18:48:50 -04:00
if ( mHideUnconnected ! = hidden ) {
mHideUnconnected = hidden ;
insertPeers ( ) ;
}
}
2015-07-09 16:53:28 -04:00
void FriendList : : setColumnVisible ( Column column , bool visible )
2011-10-20 18:48:50 -04:00
{
2015-07-09 16:53:28 -04:00
ui - > peerTreeWidget - > setColumnHidden ( column , ! visible ) ;
peerTreeColumnVisibleChanged ( column , visible ) ;
2011-10-20 18:48:50 -04:00
}
2015-08-21 18:57:26 -04:00
void FriendList : : sortByColumn ( Column column , Qt : : SortOrder sortOrder )
{
ui - > peerTreeWidget - > sortByColumn ( column , sortOrder ) ;
}
2015-08-08 14:27:19 -04:00
void FriendList : : peerTreeColumnVisibleChanged ( int /*column*/ , bool visible )
2011-10-20 18:48:50 -04:00
{
2015-08-08 14:27:19 -04:00
if ( visible ) {
insertPeers ( ) ;
}
2011-11-11 20:26:26 -05:00
}
2015-08-19 03:59:14 -04:00
void FriendList : : peerTreeItemCollapsedExpanded ( QTreeWidgetItem * item )
{
if ( ! item ) {
return ;
}
if ( item - > type ( ) = = TYPE_GPG ) {
insertPeers ( ) ;
}
}
2015-08-08 14:27:19 -04:00
void FriendList : : setShowState ( bool show )
2013-07-04 16:11:36 -04:00
{
2015-08-08 14:27:19 -04:00
if ( mShowState ! = show ) {
mShowState = show ;
insertPeers ( ) ;
2015-07-09 16:53:28 -04:00
}
2015-08-08 14:27:19 -04:00
}
2013-07-04 16:11:36 -04:00
2015-08-21 18:57:26 -04:00
void FriendList : : sortByState ( bool sort )
2015-08-08 14:27:19 -04:00
{
2015-08-21 18:57:26 -04:00
int columnCount = ui - > peerTreeWidget - > columnCount ( ) ;
for ( int i = 0 ; i < columnCount ; + + i ) {
mCompareRole - > setRole ( i , ROLE_SORT_GROUP ) ;
mCompareRole - > addRole ( i , ROLE_SORT_STANDARD_GROUP ) ;
2015-08-08 14:27:19 -04:00
2015-08-21 18:57:26 -04:00
if ( sort ) {
mCompareRole - > addRole ( i , ROLE_SORT_STATE ) ;
mCompareRole - > addRole ( i , ROLE_SORT_NAME ) ;
} else {
mCompareRole - > addRole ( i , ROLE_SORT_NAME ) ;
mCompareRole - > addRole ( i , ROLE_SORT_STATE ) ;
}
2013-07-04 16:11:36 -04:00
}
2015-08-08 14:27:19 -04:00
2015-08-21 18:57:26 -04:00
mActionSortByState - > setChecked ( sort ) ;
ui - > peerTreeWidget - > resort ( ) ;
2013-07-04 16:11:36 -04:00
}
2015-08-21 18:57:26 -04:00
bool FriendList : : isSortByState ( )
2011-10-20 18:48:50 -04:00
{
2015-08-21 18:57:26 -04:00
return mActionSortByState - > isChecked ( ) ;
2011-10-20 18:48:50 -04:00
}
2011-11-11 20:26:26 -05:00
void FriendList : : setShowGroups ( bool show )
2011-10-20 18:48:50 -04:00
{
2011-11-11 20:26:26 -05:00
if ( mShowGroups ! = show ) {
mShowGroups = show ;
if ( mShowGroups ) {
// remove all not assigned gpg ids
int childCount = ui - > peerTreeWidget - > topLevelItemCount ( ) ;
int childIndex = 0 ;
while ( childIndex < childCount ) {
QTreeWidgetItem * item = ui - > peerTreeWidget - > topLevelItem ( childIndex ) ;
if ( item - > type ( ) = = TYPE_GPG ) {
delete ( ui - > peerTreeWidget - > takeTopLevelItem ( childIndex ) ) ;
childCount = ui - > peerTreeWidget - > topLevelItemCount ( ) ;
continue ;
}
2014-10-21 18:33:02 -04:00
+ + childIndex ;
2011-11-11 20:26:26 -05:00
}
}
2011-10-20 18:48:50 -04:00
insertPeers ( ) ;
}
}
/**
2015-07-09 16:53:28 -04:00
* Hides all items that don ' t contain text in the name column .
2011-10-20 18:48:50 -04:00
*/
2012-04-05 17:03:03 -04:00
void FriendList : : filterItems ( const QString & text )
2011-10-20 18:48:50 -04:00
{
2017-07-17 08:10:26 -04:00
int filterColumn = ui - > filterLineEdit - > currentFilter ( ) ;
mFilterText = text ;
ui - > peerTreeWidget - > filterItems ( filterColumn , mFilterText , ROLE_FILTER ) ;
2011-10-20 18:48:50 -04:00
}
/**
* Add a groupId to the openGroups list . These groups
* will be expanded , when they ' re added to the QTreeWidget
*/
2016-07-05 23:49:43 -04:00
void FriendList : : addGroupToExpand ( const RsNodeGroupId & groupId )
2011-10-20 18:48:50 -04:00
{
2016-07-05 23:49:43 -04:00
openGroups . insert ( groupId ) ;
2011-10-20 18:48:50 -04:00
}
/**
* Add a gpgId to the openPeers list . These peers
* will be expanded , when they ' re added to the QTreeWidget
*/
2016-11-27 06:21:14 -05:00
void FriendList : : addPeerToExpand ( const RsPgpId & gpgId )
2011-10-20 18:48:50 -04:00
{
2016-07-05 23:49:43 -04:00
openPeers . insert ( gpgId ) ;
2011-10-20 18:48:50 -04:00
}
2011-11-11 20:26:26 -05:00
2013-08-30 08:24:39 -04:00
void FriendList : : createDisplayMenu ( )
2011-11-11 20:26:26 -05:00
{
2016-08-05 12:15:21 -04:00
QMenu * displayMenu = new QMenu ( tr ( " Show Items " ) , this ) ;
2011-11-11 20:26:26 -05:00
connect ( displayMenu , SIGNAL ( aboutToShow ( ) ) , this , SLOT ( updateMenu ( ) ) ) ;
displayMenu - > addAction ( ui - > actionHideOfflineFriends ) ;
2015-08-08 14:27:19 -04:00
displayMenu - > addAction ( ui - > actionShowState ) ;
2011-11-11 20:26:26 -05:00
displayMenu - > addAction ( ui - > actionShowGroups ) ;
2016-08-05 12:15:21 -04:00
ui - > peerTreeWidget - > addContextMenuMenu ( displayMenu ) ;
ui - > peerTreeWidget - > addContextMenuAction ( ui - > actionExportFriendlist ) ;
ui - > peerTreeWidget - > addContextMenuAction ( ui - > actionImportFriendlist ) ;
2011-11-11 20:26:26 -05:00
}
void FriendList : : updateMenu ( )
{
ui - > actionHideOfflineFriends - > setChecked ( mHideUnconnected ) ;
2015-08-08 14:27:19 -04:00
ui - > actionShowState - > setChecked ( mShowState ) ;
2011-11-11 20:26:26 -05:00
ui - > actionShowGroups - > setChecked ( mShowGroups ) ;
}