2012-01-26 19:32:17 -05:00
|
|
|
/****************************************************************
|
|
|
|
*
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012, 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.
|
|
|
|
****************************************************************/
|
|
|
|
|
2013-02-22 16:42:27 -05:00
|
|
|
#include <QDialogButtonBox>
|
2012-01-26 19:32:17 -05:00
|
|
|
#include "FriendSelectionWidget.h"
|
|
|
|
#include "ui_FriendSelectionWidget.h"
|
2013-06-18 05:58:47 -04:00
|
|
|
#include <retroshare-gui/RsAutoUpdatePage.h>
|
2012-01-26 19:32:17 -05:00
|
|
|
#include "gui/notifyqt.h"
|
|
|
|
#include "gui/common/RSTreeWidgetItem.h"
|
|
|
|
#include "gui/common/StatusDefs.h"
|
|
|
|
#include "gui/common/PeerDefs.h"
|
|
|
|
#include "gui/common/GroupDefs.h"
|
2012-11-19 11:01:21 -05:00
|
|
|
#include "rshare.h"
|
2012-01-26 19:32:17 -05:00
|
|
|
|
|
|
|
#include <retroshare/rspeers.h>
|
|
|
|
#include <retroshare/rsstatus.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#define COLUMN_NAME 0
|
|
|
|
#define COLUMN_CHECK 0
|
|
|
|
#define COLUMN_DATA 0
|
2013-01-22 19:22:17 -05:00
|
|
|
#define COLUMN_COUNT 1
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
#define IDDIALOG_IDLIST 1
|
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
#define ROLE_ID Qt::UserRole
|
|
|
|
#define ROLE_SORT Qt::UserRole + 1
|
|
|
|
|
|
|
|
#define IMAGE_GROUP16 ":/images/user/group16.png"
|
|
|
|
#define IMAGE_FRIENDINFO ":/images/peerdetails_16x16.png"
|
|
|
|
|
|
|
|
static bool isSelected(FriendSelectionWidget::Modus modus, QTreeWidgetItem *item)
|
|
|
|
{
|
|
|
|
switch (modus) {
|
|
|
|
case FriendSelectionWidget::MODUS_SINGLE:
|
|
|
|
case FriendSelectionWidget::MODUS_MULTI:
|
|
|
|
return item->isSelected();
|
|
|
|
case FriendSelectionWidget::MODUS_CHECK:
|
|
|
|
return (item->checkState(COLUMN_CHECK) == Qt::Checked);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setSelected(FriendSelectionWidget::Modus modus, QTreeWidgetItem *item, bool select)
|
|
|
|
{
|
|
|
|
switch (modus) {
|
|
|
|
case FriendSelectionWidget::MODUS_SINGLE:
|
|
|
|
case FriendSelectionWidget::MODUS_MULTI:
|
|
|
|
item->setSelected(select);
|
|
|
|
break;
|
|
|
|
case FriendSelectionWidget::MODUS_CHECK:
|
|
|
|
item->setCheckState(COLUMN_CHECK, select ? Qt::Checked : Qt::Unchecked);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
FriendSelectionWidget::FriendSelectionWidget(QWidget *parent)
|
|
|
|
: RsGxsUpdateBroadcastPage(rsIdentity,parent), ui(new Ui::FriendSelectionWidget)
|
2012-01-26 19:32:17 -05:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
mStarted = false;
|
|
|
|
mListModus = MODUS_SINGLE;
|
|
|
|
mShowTypes = SHOW_GROUP | SHOW_SSL;
|
|
|
|
mInGroupItemChanged = false;
|
|
|
|
mInGpgItemChanged = false;
|
|
|
|
mInSslItemChanged = false;
|
|
|
|
mInFillList = false;
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
mIdQueue = new TokenQueue(rsIdentity->getTokenService(), this);
|
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
connect(ui->friendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
|
|
|
|
connect(ui->friendList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*,int)));
|
|
|
|
connect(ui->friendList, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*,int)));
|
2013-05-29 17:32:02 -04:00
|
|
|
connect(ui->selectAll_PB, SIGNAL(clicked()), this, SLOT(selectAll()));
|
|
|
|
connect(ui->deselectAll_PB, SIGNAL(clicked()), this, SLOT(deselectAll()));
|
2012-04-05 17:03:03 -04:00
|
|
|
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString)));
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2013-06-20 08:27:51 -04:00
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(groupsChanged(int)));
|
2012-01-26 19:32:17 -05:00
|
|
|
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&,int)), this, SLOT(peerStatusChanged(const QString&,int)));
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
mCompareRole = new RSTreeWidgetItemCompareRole;
|
|
|
|
mCompareRole->setRole(COLUMN_NAME, ROLE_SORT);
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
/* initialize list */
|
|
|
|
ui->friendList->setColumnCount(COLUMN_COUNT);
|
|
|
|
ui->friendList->headerItem()->setText(COLUMN_NAME, tr("Name"));
|
|
|
|
|
|
|
|
/* sort list by name ascending */
|
2012-01-26 19:32:17 -05:00
|
|
|
ui->friendList->sortItems(COLUMN_NAME, Qt::AscendingOrder);
|
2012-10-29 06:59:26 -04:00
|
|
|
|
|
|
|
ui->filterLineEdit->setPlaceholderText(tr("Search Friends"));
|
2012-11-05 19:28:11 -05:00
|
|
|
ui->filterLineEdit->showFilterIcon();
|
2012-11-19 11:01:21 -05:00
|
|
|
|
|
|
|
/* Refresh style to have the correct text color */
|
|
|
|
Rshare::refreshStyleSheet(this, false);
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
FriendSelectionWidget::~FriendSelectionWidget()
|
|
|
|
{
|
2014-10-12 06:46:09 -04:00
|
|
|
delete(mIdQueue);
|
2012-01-26 19:32:17 -05:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2012-11-19 11:01:21 -05:00
|
|
|
void FriendSelectionWidget::changeEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
QWidget::changeEvent(e);
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::StyleChange:
|
|
|
|
fillList();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// remove compiler warnings
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
void FriendSelectionWidget::setHeaderText(const QString &text)
|
|
|
|
{
|
|
|
|
ui->friendList->headerItem()->setText(COLUMN_NAME, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FriendSelectionWidget::setModus(Modus modus)
|
|
|
|
{
|
2013-01-22 19:22:17 -05:00
|
|
|
mListModus = modus;
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
switch (mListModus) {
|
2012-01-26 19:32:17 -05:00
|
|
|
case MODUS_SINGLE:
|
|
|
|
case MODUS_CHECK:
|
|
|
|
ui->friendList->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
break;
|
|
|
|
case MODUS_MULTI:
|
|
|
|
ui->friendList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-05-29 17:32:02 -04:00
|
|
|
if(modus == MODUS_CHECK)
|
|
|
|
{
|
|
|
|
ui->selectAll_PB->setHidden(false) ;
|
|
|
|
ui->deselectAll_PB->setHidden(false) ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->selectAll_PB->setHidden(true) ;
|
|
|
|
ui->deselectAll_PB->setHidden(true) ;
|
|
|
|
}
|
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
fillList();
|
|
|
|
}
|
|
|
|
|
2012-11-24 09:48:31 -05:00
|
|
|
void FriendSelectionWidget::setShowType(ShowTypes types)
|
2012-01-26 19:32:17 -05:00
|
|
|
{
|
2013-01-22 19:22:17 -05:00
|
|
|
mShowTypes = types;
|
2012-01-26 19:32:17 -05:00
|
|
|
|
|
|
|
fillList();
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
int FriendSelectionWidget::addColumn(const QString &title)
|
|
|
|
{
|
|
|
|
int column = ui->friendList->columnCount();
|
|
|
|
ui->friendList->setColumnCount(column + 1);
|
|
|
|
ui->friendList->headerItem()->setText(column, title);
|
|
|
|
return column;
|
|
|
|
}
|
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
void FriendSelectionWidget::start()
|
|
|
|
{
|
2013-01-22 19:22:17 -05:00
|
|
|
mStarted = true;
|
2013-06-18 16:32:10 -04:00
|
|
|
secured_fillList();
|
2013-01-22 19:22:17 -05:00
|
|
|
|
|
|
|
for (int i = 0; i < ui->friendList->columnCount(); ++i) {
|
|
|
|
ui->friendList->resizeColumnToContents(i);
|
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
|
2012-11-24 09:48:31 -05:00
|
|
|
static void initSslItem(QTreeWidgetItem *item, const RsPeerDetails &detail, const std::list<StatusInfo> &statusInfo, QColor textColorOnline)
|
|
|
|
{
|
|
|
|
QString name = PeerDefs::nameWithLocation(detail);
|
|
|
|
item->setText(COLUMN_NAME, name);
|
|
|
|
|
|
|
|
int state = RS_STATUS_OFFLINE;
|
|
|
|
if (detail.state & RS_PEER_STATE_CONNECTED) {
|
|
|
|
std::list<StatusInfo>::const_iterator it;
|
2014-10-21 18:33:02 -04:00
|
|
|
for (it = statusInfo.begin(); it != statusInfo.end() ; ++it) {
|
2012-11-24 09:48:31 -05:00
|
|
|
if (it->id == detail.id) {
|
|
|
|
state = it->status;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state != (int) RS_STATUS_OFFLINE) {
|
|
|
|
item->setTextColor(COLUMN_NAME, textColorOnline);
|
|
|
|
}
|
|
|
|
|
|
|
|
item->setIcon(COLUMN_NAME, QIcon(StatusDefs::imageUser(state)));
|
2014-03-17 16:56:06 -04:00
|
|
|
item->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.id.toStdString()));
|
2012-11-24 09:48:31 -05:00
|
|
|
item->setData(COLUMN_DATA, ROLE_SORT, "2 " + name);
|
|
|
|
}
|
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
void FriendSelectionWidget::fillList()
|
|
|
|
{
|
2013-01-22 19:22:17 -05:00
|
|
|
if (!mStarted) {
|
2012-01-26 19:32:17 -05:00
|
|
|
return;
|
|
|
|
}
|
2013-06-18 05:58:47 -04:00
|
|
|
if(!isVisible())
|
|
|
|
return ;
|
|
|
|
if(RsAutoUpdatePage::eventsLocked())
|
|
|
|
return ;
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2013-06-18 16:32:10 -04:00
|
|
|
secured_fillList() ;
|
|
|
|
}
|
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
void FriendSelectionWidget::loadRequest(const TokenQueue */*queue*/, const TokenRequest &req)
|
|
|
|
{
|
|
|
|
// store all IDs locally, and call fillList() ;
|
|
|
|
|
|
|
|
uint32_t token = req.mToken ;
|
|
|
|
|
|
|
|
RsGxsIdGroup data;
|
|
|
|
std::vector<RsGxsIdGroup> datavector;
|
|
|
|
std::vector<RsGxsIdGroup>::iterator vit;
|
|
|
|
|
|
|
|
if (!rsIdentity->getGroupData(token, datavector))
|
|
|
|
{
|
|
|
|
std::cerr << "FriendSelectionWidget::loadRequest() ERROR. Cannot load data from rsIdentity." << std::endl;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
gxsIds.clear() ;
|
|
|
|
|
|
|
|
for(uint32_t i=0;i<datavector.size();++i)
|
|
|
|
{
|
|
|
|
gxsIds.push_back(datavector[i].mMeta.mGroupId) ;
|
|
|
|
std::cerr << " got ID = " << datavector[i].mMeta.mGroupId << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "Got all " << datavector.size() << " ids from rsIdentity. Calling update of list." << std::endl;
|
|
|
|
fillList() ;
|
|
|
|
}
|
|
|
|
|
2013-06-18 16:32:10 -04:00
|
|
|
void FriendSelectionWidget::secured_fillList()
|
|
|
|
{
|
2013-01-22 19:22:17 -05:00
|
|
|
mInFillList = true;
|
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
// get selected items
|
2014-03-17 16:56:06 -04:00
|
|
|
std::list<RsPeerId> sslIdsSelected;
|
2013-01-22 19:22:17 -05:00
|
|
|
if (mShowTypes & SHOW_SSL) {
|
2014-03-17 16:56:06 -04:00
|
|
|
selectedIds<RsPeerId,IDTYPE_SSL>(sslIdsSelected,true);
|
2012-11-24 09:48:31 -05:00
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
|
|
|
|
std::list<std::string> groupIdsSelected;
|
2013-01-22 19:22:17 -05:00
|
|
|
if (mShowTypes & SHOW_GROUP) {
|
2014-03-17 16:56:06 -04:00
|
|
|
selectedIds<std::string,IDTYPE_GROUP>(groupIdsSelected,true);
|
2012-11-24 09:48:31 -05:00
|
|
|
}
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
std::list<RsPgpId> gpgIdsSelected;
|
2013-05-29 17:32:02 -04:00
|
|
|
if (mShowTypes & (SHOW_GPG | SHOW_NON_FRIEND_GPG)) {
|
2014-03-17 16:56:06 -04:00
|
|
|
selectedIds<RsPgpId,IDTYPE_GPG>(gpgIdsSelected,true);
|
2012-11-24 09:48:31 -05:00
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
std::list<RsGxsId> gxsIdsSelected;
|
|
|
|
if (mShowTypes & SHOW_GXS)
|
|
|
|
selectedIds<RsGxsId,IDTYPE_GXS>(gxsIdsSelected,true);
|
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
// remove old items
|
|
|
|
ui->friendList->clear();
|
|
|
|
|
|
|
|
// 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> gpgIds;
|
|
|
|
std::list<RsPgpId>::iterator gpgIt;
|
2013-05-29 17:32:02 -04:00
|
|
|
|
|
|
|
if(mShowTypes & SHOW_NON_FRIEND_GPG)
|
|
|
|
rsPeers->getGPGAllList(gpgIds);
|
|
|
|
else
|
|
|
|
rsPeers->getGPGAcceptedList(gpgIds);
|
2012-11-24 09:48:31 -05:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
std::list<RsPeerId> sslIds;
|
|
|
|
std::list<RsPeerId>::iterator sslIt;
|
2013-05-29 17:32:02 -04:00
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
if ((mShowTypes & (SHOW_SSL | SHOW_GPG)) == SHOW_SSL) {
|
2012-11-24 09:48:31 -05:00
|
|
|
rsPeers->getFriendList(sslIds);
|
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
|
|
|
|
std::list<StatusInfo> statusInfo;
|
2012-11-24 09:48:31 -05:00
|
|
|
std::list<StatusInfo>::iterator statusIt;
|
2012-01-26 19:32:17 -05:00
|
|
|
rsStatus->getStatusList(statusInfo);
|
|
|
|
|
2012-11-24 09:48:31 -05:00
|
|
|
std::list<std::string> filledIds; // gpg or ssl id
|
2012-01-26 19:32:17 -05:00
|
|
|
|
|
|
|
// start with groups
|
|
|
|
groupIt = groupInfoList.begin();
|
|
|
|
while (true) {
|
|
|
|
QTreeWidgetItem *groupItem = NULL;
|
2012-11-24 09:48:31 -05:00
|
|
|
QTreeWidgetItem *gpgItem = NULL;
|
2014-03-29 10:18:05 -04:00
|
|
|
QTreeWidgetItem *gxsItem = NULL;
|
|
|
|
RsGroupInfo *groupInfo = NULL;
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
if ((mShowTypes & SHOW_GROUP) && groupIt != groupInfoList.end())
|
|
|
|
{
|
2012-01-26 19:32:17 -05:00
|
|
|
groupInfo = &(*groupIt);
|
|
|
|
|
2014-10-21 18:33:02 -04:00
|
|
|
if (groupInfo->peerIds.empty()) {
|
2012-01-26 19:32:17 -05:00
|
|
|
// don't show empty groups
|
2014-10-21 18:33:02 -04:00
|
|
|
++groupIt;
|
2012-01-26 19:32:17 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add group item
|
2013-01-22 19:22:17 -05:00
|
|
|
groupItem = new RSTreeWidgetItem(mCompareRole, IDTYPE_GROUP);
|
2012-01-26 19:32:17 -05:00
|
|
|
|
|
|
|
// Add item to the list
|
|
|
|
ui->friendList->addTopLevelItem(groupItem);
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
groupItem->setFlags(Qt::ItemIsUserCheckable | groupItem->flags());
|
2012-01-26 19:32:17 -05:00
|
|
|
groupItem->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
|
|
|
|
groupItem->setTextAlignment(COLUMN_NAME, Qt::AlignLeft | Qt::AlignVCenter);
|
|
|
|
groupItem->setIcon(COLUMN_NAME, QIcon(IMAGE_GROUP16));
|
|
|
|
|
|
|
|
groupItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(groupInfo->id));
|
|
|
|
|
|
|
|
groupItem->setExpanded(true);
|
|
|
|
|
|
|
|
QString groupName = GroupDefs::name(*groupInfo);
|
|
|
|
groupItem->setText(COLUMN_NAME, groupName);
|
|
|
|
groupItem->setData(COLUMN_DATA, ROLE_SORT, ((groupInfo->flag & RS_GROUP_FLAG_STANDARD) ? "0 " : "1 ") + groupName);
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
if (mListModus == MODUS_CHECK) {
|
2012-01-26 19:32:17 -05:00
|
|
|
groupItem->setCheckState(0, Qt::Unchecked);
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
emit itemAdded(IDTYPE_GROUP, QString::fromStdString(groupInfo->id), groupItem);
|
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
if (std::find(groupIdsSelected.begin(), groupIdsSelected.end(), groupInfo->id) != groupIdsSelected.end()) {
|
2013-01-22 19:22:17 -05:00
|
|
|
setSelected(mListModus, groupItem, true);
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
if (mShowTypes & (SHOW_GPG | SHOW_NON_FRIEND_GPG))
|
|
|
|
{
|
2012-11-24 09:48:31 -05:00
|
|
|
// iterate through gpg ids
|
2014-10-21 18:33:02 -04:00
|
|
|
for (gpgIt = gpgIds.begin(); gpgIt != gpgIds.end(); ++gpgIt) {
|
2012-11-24 09:48:31 -05:00
|
|
|
if (groupInfo) {
|
|
|
|
// we fill a group, check if gpg id is assigned
|
|
|
|
if (std::find(groupInfo->peerIds.begin(), groupInfo->peerIds.end(), *gpgIt) == groupInfo->peerIds.end()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// we fill the not assigned gpg ids
|
2014-03-17 16:56:06 -04:00
|
|
|
if (std::find(filledIds.begin(), filledIds.end(), (*gpgIt).toStdString()) != filledIds.end()) {
|
2012-11-24 09:48:31 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2012-11-24 09:48:31 -05:00
|
|
|
// add equal too, its no problem
|
2014-03-17 16:56:06 -04:00
|
|
|
filledIds.push_back((*gpgIt).toStdString());
|
2012-11-24 09:48:31 -05:00
|
|
|
|
|
|
|
RsPeerDetails detail;
|
2014-03-17 16:56:06 -04:00
|
|
|
if (!rsPeers->getGPGDetails(*gpgIt, detail)) {
|
2012-11-24 09:48:31 -05:00
|
|
|
continue; /* BAD */
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
2012-11-24 09:48:31 -05:00
|
|
|
|
|
|
|
// make a widget per friend
|
2013-01-22 19:22:17 -05:00
|
|
|
gpgItem = new RSTreeWidgetItem(mCompareRole, IDTYPE_GPG);
|
2012-11-24 09:48:31 -05:00
|
|
|
|
|
|
|
QString name = QString::fromUtf8(detail.name.c_str());
|
2014-03-17 16:56:06 -04:00
|
|
|
gpgItem->setText(COLUMN_NAME, name + " ("+QString::fromStdString( (*gpgIt).toStdString() )+")");
|
2012-11-24 09:48:31 -05:00
|
|
|
|
|
|
|
sslIds.clear();
|
|
|
|
rsPeers->getAssociatedSSLIds(*gpgIt, sslIds);
|
|
|
|
|
|
|
|
int state = RS_STATUS_OFFLINE;
|
2014-10-21 18:33:02 -04:00
|
|
|
for (statusIt = statusInfo.begin(); statusIt != statusInfo.end() ; ++statusIt) {
|
2012-11-24 09:48:31 -05:00
|
|
|
if (std::find(sslIds.begin(), sslIds.end(), statusIt->id) != sslIds.end()) {
|
|
|
|
if (statusIt->status != RS_STATUS_OFFLINE) {
|
|
|
|
state = RS_STATUS_ONLINE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
|
2012-11-24 09:48:31 -05:00
|
|
|
if (state != (int) RS_STATUS_OFFLINE) {
|
|
|
|
gpgItem->setTextColor(COLUMN_NAME, textColorOnline());
|
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
gpgItem->setFlags(Qt::ItemIsUserCheckable | gpgItem->flags());
|
2012-11-24 09:48:31 -05:00
|
|
|
gpgItem->setIcon(COLUMN_NAME, QIcon(StatusDefs::imageUser(state)));
|
2014-03-17 16:56:06 -04:00
|
|
|
gpgItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.gpg_id.toStdString()));
|
2012-11-24 09:48:31 -05:00
|
|
|
gpgItem->setData(COLUMN_DATA, ROLE_SORT, "2 " + name);
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
if (mListModus == MODUS_CHECK) {
|
2012-11-24 09:48:31 -05:00
|
|
|
gpgItem->setCheckState(0, Qt::Unchecked);
|
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2012-11-24 09:48:31 -05:00
|
|
|
// add to the list
|
|
|
|
if (groupItem) {
|
|
|
|
groupItem->addChild(gpgItem);
|
|
|
|
} else {
|
|
|
|
ui->friendList->addTopLevelItem(gpgItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
gpgItem->setExpanded(true);
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
emit itemAdded(IDTYPE_GPG, QString::fromStdString(detail.gpg_id.toStdString()), gpgItem);
|
2013-01-22 19:22:17 -05:00
|
|
|
|
|
|
|
if (mShowTypes & SHOW_SSL) {
|
2012-11-24 09:48:31 -05:00
|
|
|
// iterate through associated ssl ids
|
2014-10-21 18:33:02 -04:00
|
|
|
for (sslIt = sslIds.begin(); sslIt != sslIds.end(); ++sslIt) {
|
2012-11-24 09:48:31 -05:00
|
|
|
RsPeerDetails detail;
|
|
|
|
if (!rsPeers->getPeerDetails(*sslIt, detail)) {
|
|
|
|
continue; /* BAD */
|
|
|
|
}
|
|
|
|
|
|
|
|
// make a widget per friend
|
2013-01-22 19:22:17 -05:00
|
|
|
QTreeWidgetItem *item = new RSTreeWidgetItem(mCompareRole, IDTYPE_SSL);
|
2012-11-24 09:48:31 -05:00
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
item->setFlags(Qt::ItemIsUserCheckable | item->flags());
|
2012-11-24 09:48:31 -05:00
|
|
|
initSslItem(item, detail, statusInfo, textColorOnline());
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
if (mListModus == MODUS_CHECK) {
|
2012-11-24 09:48:31 -05:00
|
|
|
item->setCheckState(0, Qt::Unchecked);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add to the list
|
|
|
|
gpgItem->addChild(item);
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
emit itemAdded(IDTYPE_SSL, QString::fromStdString(detail.id.toStdString()), item);
|
2013-01-22 19:22:17 -05:00
|
|
|
|
2012-11-24 09:48:31 -05:00
|
|
|
if (std::find(sslIdsSelected.begin(), sslIdsSelected.end(), detail.id) != sslIdsSelected.end()) {
|
2013-01-22 19:22:17 -05:00
|
|
|
setSelected(mListModus, item, true);
|
2012-11-24 09:48:31 -05:00
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-24 09:48:31 -05:00
|
|
|
if (std::find(gpgIdsSelected.begin(), gpgIdsSelected.end(), detail.gpg_id) != gpgIdsSelected.end()) {
|
2013-01-22 19:22:17 -05:00
|
|
|
setSelected(mListModus, gpgItem, true);
|
2012-11-24 09:48:31 -05:00
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
2014-03-29 10:18:05 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-24 09:48:31 -05:00
|
|
|
// iterate through ssl ids
|
2014-10-21 18:33:02 -04:00
|
|
|
for (sslIt = sslIds.begin(); sslIt != sslIds.end(); ++sslIt) {
|
2012-11-24 09:48:31 -05:00
|
|
|
RsPeerDetails detail;
|
|
|
|
if (!rsPeers->getPeerDetails(*sslIt, detail)) {
|
|
|
|
continue; /* BAD */
|
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2012-11-24 09:48:31 -05:00
|
|
|
if (groupInfo) {
|
|
|
|
// we fill a group, check if gpg id is assigned
|
|
|
|
if (std::find(groupInfo->peerIds.begin(), groupInfo->peerIds.end(), detail.gpg_id) == groupInfo->peerIds.end()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// we fill the not assigned ssl ids
|
2014-03-17 16:56:06 -04:00
|
|
|
if (std::find(filledIds.begin(), filledIds.end(), (*sslIt).toStdString()) != filledIds.end()) {
|
2012-11-24 09:48:31 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2012-11-24 09:48:31 -05:00
|
|
|
// add equal too, its no problem
|
2014-03-17 16:56:06 -04:00
|
|
|
filledIds.push_back(detail.id.toStdString());
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2012-11-24 09:48:31 -05:00
|
|
|
// make a widget per friend
|
2013-01-22 19:22:17 -05:00
|
|
|
QTreeWidgetItem *item = new RSTreeWidgetItem(mCompareRole, IDTYPE_SSL);
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2012-11-24 09:48:31 -05:00
|
|
|
initSslItem(item, detail, statusInfo, textColorOnline());
|
2013-01-22 19:22:17 -05:00
|
|
|
item->setFlags(Qt::ItemIsUserCheckable | item->flags());
|
2012-11-24 09:48:31 -05:00
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
if (mListModus == MODUS_CHECK) {
|
2012-11-24 09:48:31 -05:00
|
|
|
item->setCheckState(0, Qt::Unchecked);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add to the list
|
|
|
|
if (groupItem) {
|
|
|
|
groupItem->addChild(item);
|
|
|
|
} else {
|
|
|
|
ui->friendList->addTopLevelItem(item);
|
|
|
|
}
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
emit itemAdded(IDTYPE_SSL, QString::fromStdString(detail.id.toStdString()), item);
|
2013-01-22 19:22:17 -05:00
|
|
|
|
2012-11-24 09:48:31 -05:00
|
|
|
if (std::find(sslIdsSelected.begin(), sslIdsSelected.end(), detail.id) != sslIdsSelected.end()) {
|
2013-01-22 19:22:17 -05:00
|
|
|
setSelected(mListModus, item, true);
|
2012-11-24 09:48:31 -05:00
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-29 10:18:05 -04:00
|
|
|
if(mShowTypes & SHOW_GXS)
|
|
|
|
{
|
|
|
|
// iterate through gpg ids
|
2014-10-21 18:33:02 -04:00
|
|
|
for (std::vector<RsGxsGroupId>::const_iterator gxsIt = gxsIds.begin(); gxsIt != gxsIds.end(); ++gxsIt)
|
2014-03-29 10:18:05 -04:00
|
|
|
{
|
|
|
|
// we fill the not assigned gpg ids
|
|
|
|
if (std::find(filledIds.begin(), filledIds.end(), (*gxsIt).toStdString()) != filledIds.end())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// add equal too, its no problem
|
|
|
|
filledIds.push_back((*gxsIt).toStdString());
|
|
|
|
|
|
|
|
RsIdentityDetails detail;
|
|
|
|
if (!rsIdentity->getIdDetails(RsGxsId(*gxsIt), detail))
|
|
|
|
continue; /* BAD */
|
|
|
|
|
|
|
|
// make a widget per friend
|
|
|
|
gxsItem = new RSTreeWidgetItem(mCompareRole, IDTYPE_GXS);
|
|
|
|
|
|
|
|
QString name = QString::fromUtf8(detail.mNickname.c_str());
|
|
|
|
gxsItem->setText(COLUMN_NAME, name + " ("+QString::fromStdString( (*gxsIt).toStdString() )+")");
|
|
|
|
|
|
|
|
gxsItem->setTextColor(COLUMN_NAME, textColorOnline());
|
|
|
|
gxsItem->setFlags(Qt::ItemIsUserCheckable | gxsItem->flags());
|
|
|
|
gxsItem->setIcon(COLUMN_NAME, QIcon(StatusDefs::imageUser(RS_STATUS_ONLINE)));
|
|
|
|
gxsItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.mId.toStdString()));
|
|
|
|
gxsItem->setData(COLUMN_DATA, ROLE_SORT, "2 " + name);
|
|
|
|
|
|
|
|
if (mListModus == MODUS_CHECK)
|
|
|
|
gxsItem->setCheckState(0, Qt::Unchecked);
|
|
|
|
|
|
|
|
ui->friendList->addTopLevelItem(gxsItem);
|
|
|
|
|
|
|
|
gxsItem->setExpanded(true);
|
|
|
|
|
|
|
|
emit itemAdded(IDTYPE_GXS, QString::fromStdString(detail.mId.toStdString()), gxsItem);
|
|
|
|
|
|
|
|
if (std::find(gxsIdsSelected.begin(), gxsIdsSelected.end(), detail.mId) != gxsIdsSelected.end())
|
|
|
|
setSelected(mListModus, gxsItem, true);
|
|
|
|
}
|
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
if (groupIt != groupInfoList.end()) {
|
2014-10-21 18:33:02 -04:00
|
|
|
++groupIt;
|
2012-01-26 19:32:17 -05:00
|
|
|
} else {
|
|
|
|
// all done
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-05 17:03:03 -04:00
|
|
|
if (ui->filterLineEdit->text().isEmpty() == false) {
|
|
|
|
filterItems(ui->filterLineEdit->text());
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ui->friendList->update(); /* update display */
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
mInFillList = false;
|
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
emit contentChanged();
|
|
|
|
}
|
2014-03-29 10:18:05 -04:00
|
|
|
void FriendSelectionWidget::updateDisplay(bool)
|
|
|
|
{
|
|
|
|
requestGXSIdList() ;
|
|
|
|
}
|
|
|
|
void FriendSelectionWidget::requestGXSIdList()
|
|
|
|
{
|
|
|
|
if (!mIdQueue)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//mStateHelper->setLoading(IDDIALOG_IDLIST, true);
|
|
|
|
//mStateHelper->setLoading(IDDIALOG_IDDETAILS, true);
|
|
|
|
//mStateHelper->setLoading(IDDIALOG_REPLIST, true);
|
|
|
|
|
|
|
|
mIdQueue->cancelActiveRequestTokens(IDDIALOG_IDLIST);
|
|
|
|
|
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
|
|
|
|
|
|
|
uint32_t token;
|
|
|
|
|
|
|
|
mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, IDDIALOG_IDLIST);
|
|
|
|
}
|
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2013-06-20 08:27:51 -04:00
|
|
|
void FriendSelectionWidget::groupsChanged(int /*type*/)
|
|
|
|
{
|
|
|
|
if (mShowTypes & SHOW_GROUP) {
|
|
|
|
fillList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
void FriendSelectionWidget::peerStatusChanged(const QString& peerId, int status)
|
|
|
|
{
|
2013-06-18 05:58:47 -04:00
|
|
|
if(!isVisible())
|
|
|
|
return ;
|
|
|
|
if(RsAutoUpdatePage::eventsLocked())
|
|
|
|
return ;
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
RsPeerId peerid(peerId.toStdString()) ;
|
2012-11-24 09:48:31 -05:00
|
|
|
QString gpgId;
|
|
|
|
int gpgStatus = RS_STATUS_OFFLINE;
|
|
|
|
|
2013-05-29 17:32:02 -04:00
|
|
|
if (mShowTypes & (SHOW_GPG | SHOW_NON_FRIEND_GPG)) {
|
2012-11-24 09:48:31 -05:00
|
|
|
/* need gpg id and online state */
|
|
|
|
RsPeerDetails detail;
|
2014-03-17 16:56:06 -04:00
|
|
|
if (rsPeers->getPeerDetails(peerid, detail))
|
|
|
|
{
|
|
|
|
gpgId = QString::fromStdString(detail.gpg_id.toStdString());
|
2012-11-24 09:48:31 -05:00
|
|
|
|
|
|
|
if (status == (int) RS_STATUS_OFFLINE) {
|
|
|
|
/* try other locations */
|
2014-03-17 16:56:06 -04:00
|
|
|
std::list<RsPeerId> sslIds;
|
2012-11-24 09:48:31 -05:00
|
|
|
rsPeers->getAssociatedSSLIds(detail.gpg_id, sslIds);
|
|
|
|
|
|
|
|
std::list<StatusInfo> statusInfo;
|
|
|
|
std::list<StatusInfo>::iterator statusIt;
|
|
|
|
rsStatus->getStatusList(statusInfo);
|
|
|
|
|
2014-10-21 18:33:02 -04:00
|
|
|
for (statusIt = statusInfo.begin(); statusIt != statusInfo.end() ; ++statusIt) {
|
2012-11-24 09:48:31 -05:00
|
|
|
if (std::find(sslIds.begin(), sslIds.end(), statusIt->id) != sslIds.end()) {
|
|
|
|
if (statusIt->status != RS_STATUS_OFFLINE) {
|
|
|
|
gpgStatus = RS_STATUS_ONLINE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* one location is online */
|
|
|
|
gpgStatus = RS_STATUS_ONLINE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
QTreeWidgetItemIterator itemIterator(ui->friendList);
|
|
|
|
QTreeWidgetItem *item;
|
|
|
|
while ((item = *itemIterator) != NULL) {
|
2014-10-21 18:33:02 -04:00
|
|
|
++itemIterator;
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2013-06-19 09:18:15 -04:00
|
|
|
bool bFoundGPG = false;
|
|
|
|
bool bFoundSSL = false;
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
switch (idTypeFromItem(item)) {
|
2012-11-24 09:48:31 -05:00
|
|
|
case IDTYPE_NONE:
|
|
|
|
case IDTYPE_GROUP:
|
|
|
|
break;
|
|
|
|
case IDTYPE_GPG:
|
|
|
|
{
|
|
|
|
if (item->data(COLUMN_DATA, ROLE_ID).toString() == gpgId) {
|
|
|
|
QColor color;
|
|
|
|
if (status != (int) RS_STATUS_OFFLINE) {
|
|
|
|
color = textColorOnline();
|
|
|
|
} else {
|
|
|
|
color = ui->friendList->palette().color(QPalette::Text);
|
|
|
|
}
|
|
|
|
|
|
|
|
item->setTextColor(COLUMN_NAME, color);
|
|
|
|
item->setIcon(COLUMN_NAME, QIcon(StatusDefs::imageUser(gpgStatus)));
|
2013-06-19 09:18:15 -04:00
|
|
|
|
|
|
|
bFoundGPG = true;
|
2012-11-24 09:48:31 -05:00
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
2012-11-24 09:48:31 -05:00
|
|
|
break;
|
|
|
|
case IDTYPE_SSL:
|
|
|
|
{
|
|
|
|
if (item->data(COLUMN_DATA, ROLE_ID).toString() == peerId) {
|
|
|
|
QColor color;
|
|
|
|
if (status != (int) RS_STATUS_OFFLINE) {
|
|
|
|
color = textColorOnline();
|
|
|
|
} else {
|
|
|
|
color = ui->friendList->palette().color(QPalette::Text);
|
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2012-11-24 09:48:31 -05:00
|
|
|
item->setTextColor(COLUMN_NAME, color);
|
|
|
|
item->setIcon(COLUMN_NAME, QIcon(StatusDefs::imageUser(status)));
|
2013-06-19 09:18:15 -04:00
|
|
|
|
|
|
|
bFoundSSL = true;
|
2012-11-24 09:48:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
2013-06-19 09:18:15 -04:00
|
|
|
|
|
|
|
if (bFoundGPG) {
|
|
|
|
if (mShowTypes & SHOW_GROUP) {
|
|
|
|
// a friend can be assigned to more than one group
|
|
|
|
} else {
|
|
|
|
if (mShowTypes & SHOW_SSL) {
|
|
|
|
// search for ssl id
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bFoundSSL) {
|
|
|
|
if (mShowTypes & SHOW_GROUP) {
|
|
|
|
// a friend can be assigned to more than one group
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FriendSelectionWidget::contextMenuRequested(const QPoint &pos)
|
|
|
|
{
|
|
|
|
emit customContextMenuRequested(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FriendSelectionWidget::itemDoubleClicked(QTreeWidgetItem *item, int /*column*/)
|
|
|
|
{
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
emit doubleClicked(idTypeFromItem(item), item->data(COLUMN_DATA, ROLE_ID).toString());
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void FriendSelectionWidget::itemChanged(QTreeWidgetItem *item, int column)
|
|
|
|
{
|
2013-01-22 19:22:17 -05:00
|
|
|
if (mInFillList) {
|
2012-01-26 19:32:17 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (column != COLUMN_CHECK) {
|
2013-01-22 19:22:17 -05:00
|
|
|
emit itemChanged(idTypeFromItem(item), item->data(COLUMN_DATA, ROLE_ID).toString(), item, column);
|
2012-01-26 19:32:17 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
if (mListModus != MODUS_CHECK) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (idTypeFromItem(item)) {
|
2012-01-26 19:32:17 -05:00
|
|
|
case IDTYPE_NONE:
|
|
|
|
break;
|
|
|
|
case IDTYPE_GROUP:
|
|
|
|
{
|
2013-01-22 19:22:17 -05:00
|
|
|
if (mInGroupItemChanged || mInGpgItemChanged || mInSslItemChanged) {
|
2012-11-24 09:48:31 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
mInGroupItemChanged = true;
|
2012-11-24 09:48:31 -05:00
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
bool selected = isSelected(mListModus, item);
|
2012-01-26 19:32:17 -05:00
|
|
|
|
|
|
|
int childCount = item->childCount();
|
|
|
|
for (int i = 0; i < childCount; ++i) {
|
2013-01-22 19:22:17 -05:00
|
|
|
setSelected(mListModus, item->child(i), selected);
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
2012-11-24 09:48:31 -05:00
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
mInGroupItemChanged = false;
|
2012-11-24 09:48:31 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDTYPE_GPG:
|
2014-03-29 10:18:05 -04:00
|
|
|
case IDTYPE_GXS:
|
|
|
|
{
|
2013-01-22 19:22:17 -05:00
|
|
|
if (mInGpgItemChanged) {
|
2012-11-24 09:48:31 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
mInGpgItemChanged = true;
|
2012-11-24 09:48:31 -05:00
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
if (!mInSslItemChanged) {
|
|
|
|
bool selected = isSelected(mListModus, item);
|
2012-11-24 09:48:31 -05:00
|
|
|
|
|
|
|
int childCount = item->childCount();
|
|
|
|
for (int i = 0; i < childCount; ++i) {
|
2013-01-22 19:22:17 -05:00
|
|
|
setSelected(mListModus, item->child(i), selected);
|
2012-11-24 09:48:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
if (!mInGroupItemChanged) {
|
2012-11-24 09:48:31 -05:00
|
|
|
QTreeWidgetItem *itemParent = item->parent();
|
|
|
|
if (itemParent) {
|
|
|
|
int childCount = itemParent->childCount();
|
|
|
|
bool foundUnselected = false;
|
|
|
|
for (int index = 0; index < childCount; ++index) {
|
2013-01-22 19:22:17 -05:00
|
|
|
if (!isSelected(mListModus, itemParent->child(index))) {
|
2012-11-24 09:48:31 -05:00
|
|
|
foundUnselected = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-22 19:22:17 -05:00
|
|
|
setSelected(mListModus, itemParent, !foundUnselected);
|
2012-11-24 09:48:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
mInGpgItemChanged = false;
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IDTYPE_SSL:
|
|
|
|
{
|
2013-01-22 19:22:17 -05:00
|
|
|
if (mInGroupItemChanged || mInGpgItemChanged || mInSslItemChanged) {
|
2012-01-26 19:32:17 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
mInSslItemChanged = true;
|
2012-11-24 09:48:31 -05:00
|
|
|
|
|
|
|
QTreeWidgetItem *itemParent = item->parent();
|
|
|
|
if (itemParent) {
|
|
|
|
int childCount = itemParent->childCount();
|
|
|
|
bool foundUnselected = false;
|
|
|
|
for (int index = 0; index < childCount; ++index) {
|
2013-01-22 19:22:17 -05:00
|
|
|
if (!isSelected(mListModus, itemParent->child(index))) {
|
2012-11-24 09:48:31 -05:00
|
|
|
foundUnselected = true;
|
|
|
|
break;
|
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
2013-01-22 19:22:17 -05:00
|
|
|
setSelected(mListModus, itemParent, !foundUnselected);
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
2012-11-24 09:48:31 -05:00
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
mInSslItemChanged = false;
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-05 17:03:03 -04:00
|
|
|
void FriendSelectionWidget::filterItems(const QString& text)
|
2012-01-26 19:32:17 -05:00
|
|
|
{
|
|
|
|
int count = ui->friendList->topLevelItemCount();
|
2014-10-21 18:33:02 -04:00
|
|
|
for (int index = 0; index < count; ++index) {
|
2012-04-05 17:03:03 -04:00
|
|
|
filterItem(ui->friendList->topLevelItem(index), text);
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FriendSelectionWidget::filterItem(QTreeWidgetItem *item, const QString &text)
|
|
|
|
{
|
|
|
|
bool visible = true;
|
|
|
|
|
|
|
|
if (text.isEmpty() == false) {
|
|
|
|
if (item->text(0).contains(text, Qt::CaseInsensitive) == false) {
|
|
|
|
visible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int visibleChildCount = 0;
|
|
|
|
int count = item->childCount();
|
2014-10-21 18:33:02 -04:00
|
|
|
for (int index = 0; index < count; ++index) {
|
2012-01-26 19:32:17 -05:00
|
|
|
if (filterItem(item->child(index), text)) {
|
2014-10-21 18:33:02 -04:00
|
|
|
++visibleChildCount;
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (visible || visibleChildCount) {
|
|
|
|
item->setHidden(false);
|
|
|
|
} else {
|
|
|
|
item->setHidden(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (visible || visibleChildCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
int FriendSelectionWidget::selectedItemCount()
|
|
|
|
{
|
|
|
|
return ui->friendList->selectedItems().count();
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
std::string FriendSelectionWidget::selectedId(IdType &idType)
|
2012-01-26 19:32:17 -05:00
|
|
|
{
|
|
|
|
QTreeWidgetItem *item = ui->friendList->currentItem();
|
|
|
|
if (!item) {
|
|
|
|
idType = IDTYPE_NONE;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
idType = idTypeFromItem(item);
|
|
|
|
return idFromItem(item);
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void FriendSelectionWidget::selectedIds(IdType idType, std::list<std::string> &ids, bool onlyDirectSelected)
|
|
|
|
{
|
|
|
|
QTreeWidgetItemIterator itemIterator(ui->friendList);
|
|
|
|
QTreeWidgetItem *item;
|
|
|
|
while ((item = *itemIterator) != NULL) {
|
2014-10-21 18:33:02 -04:00
|
|
|
++itemIterator;
|
2012-01-26 19:32:17 -05:00
|
|
|
|
|
|
|
std::string id;
|
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
switch (idTypeFromItem(item)) {
|
2012-01-26 19:32:17 -05:00
|
|
|
case IDTYPE_NONE:
|
|
|
|
break;
|
|
|
|
case IDTYPE_GROUP:
|
|
|
|
if (idType == IDTYPE_GROUP) {
|
2013-01-22 19:22:17 -05:00
|
|
|
if (isSelected(mListModus, item)) {
|
|
|
|
id = idFromItem(item);
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-11-24 09:48:31 -05:00
|
|
|
case IDTYPE_GPG:
|
2014-03-29 10:18:05 -04:00
|
|
|
case IDTYPE_GXS:
|
|
|
|
if (idType == IDTYPE_GPG || idType == IDTYPE_GXS)
|
|
|
|
{
|
2013-01-22 19:22:17 -05:00
|
|
|
if (isSelected(mListModus, item)) {
|
|
|
|
id = idFromItem(item);
|
2012-11-24 09:48:31 -05:00
|
|
|
} else {
|
|
|
|
if (!onlyDirectSelected) {
|
|
|
|
QTreeWidgetItem *itemParent = item;
|
|
|
|
while ((itemParent = itemParent->parent()) != NULL) {
|
2013-01-22 19:22:17 -05:00
|
|
|
if (isSelected(mListModus, itemParent)) {
|
|
|
|
id = idFromItem(item);
|
2012-11-24 09:48:31 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-01-26 19:32:17 -05:00
|
|
|
case IDTYPE_SSL:
|
|
|
|
if (idType == IDTYPE_SSL) {
|
2013-01-22 19:22:17 -05:00
|
|
|
if (isSelected(mListModus, item)) {
|
|
|
|
id = idFromItem(item);
|
2012-01-26 19:32:17 -05:00
|
|
|
} else {
|
|
|
|
if (!onlyDirectSelected) {
|
2012-11-24 09:48:31 -05:00
|
|
|
QTreeWidgetItem *itemParent = item;
|
|
|
|
while ((itemParent = itemParent->parent()) != NULL) {
|
2013-01-22 19:22:17 -05:00
|
|
|
if (isSelected(mListModus, itemParent)) {
|
|
|
|
id = idFromItem(item);
|
2012-11-24 09:48:31 -05:00
|
|
|
break;
|
|
|
|
}
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!id.empty() && std::find(ids.begin(), ids.end(), id) == ids.end()) {
|
|
|
|
ids.push_back(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-29 17:32:02 -04:00
|
|
|
void FriendSelectionWidget::deselectAll()
|
|
|
|
{
|
|
|
|
for(QTreeWidgetItemIterator itemIterator(ui->friendList);*itemIterator!=NULL;++itemIterator)
|
|
|
|
setSelected(mListModus, *itemIterator, false);
|
|
|
|
}
|
2013-06-20 08:27:51 -04:00
|
|
|
|
2013-05-29 17:32:02 -04:00
|
|
|
void FriendSelectionWidget::selectAll()
|
|
|
|
{
|
|
|
|
for(QTreeWidgetItemIterator itemIterator(ui->friendList);*itemIterator!=NULL;++itemIterator)
|
|
|
|
setSelected(mListModus, *itemIterator, true);
|
|
|
|
}
|
|
|
|
|
2012-01-26 19:32:17 -05:00
|
|
|
void FriendSelectionWidget::setSelectedIds(IdType idType, const std::list<std::string> &ids, bool add)
|
|
|
|
{
|
|
|
|
QTreeWidgetItemIterator itemIterator(ui->friendList);
|
|
|
|
QTreeWidgetItem *item;
|
|
|
|
while ((item = *itemIterator) != NULL) {
|
2014-10-21 18:33:02 -04:00
|
|
|
++itemIterator;
|
2012-01-26 19:32:17 -05:00
|
|
|
|
2013-01-22 19:22:17 -05:00
|
|
|
std::string id = idFromItem(item);
|
|
|
|
IdType itemType = idTypeFromItem(item);
|
2012-01-26 19:32:17 -05:00
|
|
|
|
|
|
|
switch (itemType) {
|
|
|
|
case IDTYPE_NONE:
|
|
|
|
break;
|
|
|
|
case IDTYPE_GROUP:
|
2012-11-24 09:48:31 -05:00
|
|
|
case IDTYPE_GPG:
|
2012-01-26 19:32:17 -05:00
|
|
|
case IDTYPE_SSL:
|
2014-03-29 10:18:05 -04:00
|
|
|
case IDTYPE_GXS:
|
|
|
|
if (idType == itemType) {
|
2012-01-26 19:32:17 -05:00
|
|
|
if (std::find(ids.begin(), ids.end(), id) != ids.end()) {
|
2013-01-22 19:22:17 -05:00
|
|
|
setSelected(mListModus, item, true);
|
2012-01-26 19:32:17 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!add) {
|
2013-01-22 19:22:17 -05:00
|
|
|
setSelected(mListModus, item, false);
|
2012-01-26 19:32:17 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-22 19:22:17 -05:00
|
|
|
|
|
|
|
void FriendSelectionWidget::itemsFromId(IdType idType, const std::string &id, QList<QTreeWidgetItem*> &items)
|
|
|
|
{
|
|
|
|
QTreeWidgetItemIterator itemIterator(ui->friendList);
|
|
|
|
QTreeWidgetItem *item;
|
|
|
|
while ((item = *itemIterator) != NULL) {
|
2014-10-21 18:33:02 -04:00
|
|
|
++itemIterator;
|
2013-01-22 19:22:17 -05:00
|
|
|
|
|
|
|
if (idType == idTypeFromItem(item) && idFromItem(item) == id) {
|
|
|
|
items.push_back(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FriendSelectionWidget::items(QList<QTreeWidgetItem*> &_items, IdType idType)
|
|
|
|
{
|
|
|
|
QTreeWidgetItemIterator itemIterator(ui->friendList);
|
|
|
|
QTreeWidgetItem *item;
|
|
|
|
while ((item = *itemIterator) != NULL) {
|
2014-10-21 18:33:02 -04:00
|
|
|
++itemIterator;
|
2013-01-22 19:22:17 -05:00
|
|
|
|
|
|
|
if (idType == IDTYPE_NONE || idType == idTypeFromItem(item)) {
|
|
|
|
_items.push_back(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FriendSelectionWidget::IdType FriendSelectionWidget::idTypeFromItem(QTreeWidgetItem *item)
|
|
|
|
{
|
|
|
|
if (!item) {
|
|
|
|
return IDTYPE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (IdType) item->type();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string FriendSelectionWidget::idFromItem(QTreeWidgetItem *item)
|
|
|
|
{
|
|
|
|
if (!item) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return item->data(COLUMN_DATA, ROLE_ID).toString().toStdString();
|
|
|
|
}
|
2013-02-22 16:42:27 -05:00
|
|
|
|