Added new dialog to set service permissions for friends.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6085 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2013-01-23 00:22:17 +00:00
parent 62a22fe0fe
commit 439ccc94f4
11 changed files with 474 additions and 102 deletions

View File

@ -53,8 +53,8 @@
#include "util/DateTime.h"
#include "chat/CreateLobbyDialog.h"
#include "FriendRecommendDialog.h"
#include "FriendsDialog.h"
#include "ServicePermissionDialog.h"
/* Images for Newsfeed icons */
#define IMAGE_NEWSFEED ""
@ -87,6 +87,7 @@ FriendsDialog::FriendsDialog(QWidget *parent)
connect( ui.actionAdd_Friend, SIGNAL(triggered()), this, SLOT(addFriend()));
connect( ui.actionCreate_new_Chat_lobby, SIGNAL(triggered()), this, SLOT(createChatLobby()));
connect( ui.actionFriendRecommendations, SIGNAL(triggered()), this, SLOT(recommendFriends()));
connect( ui.actionServicePermission, SIGNAL(triggered()), this, SLOT(servicePermission()));
connect( ui.filter_lineEdit, SIGNAL(textChanged(QString)), ui.friendList, SLOT(filterItems(QString)));
ui.filter_lineEdit->setPlaceholderText(tr("Search")) ;
@ -169,6 +170,7 @@ FriendsDialog::FriendsDialog(QWidget *parent)
menu->addAction(ui.actionAdd_Group);
menu->addAction(ui.actionCreate_new_Chat_lobby);
menu->addAction(ui.actionFriendRecommendations);
menu->addAction(ui.actionServicePermission);
menu->addSeparator();
menu->addAction(ui.actionSet_your_Avatar);
@ -329,7 +331,7 @@ void FriendsDialog::addFriend()
connwiz.exec ();
}
void FriendsDialog::resetStatusBar()
void FriendsDialog::resetStatusBar()
{
#ifdef FRIENDS_DEBUG
std::cerr << "FriendsDialog: reseting status bar." << std::endl ;
@ -568,7 +570,7 @@ void FriendsDialog::insertSendList()
/* get a link to the table */
//QTreeWidget *sendWidget = ui.msgSendList;
QList<QTreeWidgetItem *> items;
QList<QTreeWidgetItem *> items;
for(it = peers.begin(); it != peers.end(); it++)
{
@ -579,8 +581,8 @@ void FriendsDialog::insertSendList()
continue; /* BAD */
}
/* make a widget per friend */
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
/* make a widget per friend */
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0);
/* add all the labels */
/* (0) Person */
@ -608,7 +610,7 @@ void FriendsDialog::insertSendList()
items.append(item);
}
/* remove old items */
/* remove old items */
//sendWidget->clear();
//sendWidget->setColumnCount(1);
@ -777,9 +779,9 @@ void FriendsDialog::fileHashingFinished(QList<HashedFile> hashedFiles)
HashedFile& hashedFile = *it;
RetroShareLink link;
if (!link.createExtraFile(hashedFile.filename, hashedFile.size, QString::fromStdString(hashedFile.hash),QString::fromStdString(rsPeers->getOwnId())))
if (!link.createExtraFile(hashedFile.filename, hashedFile.size, QString::fromStdString(hashedFile.hash),QString::fromStdString(rsPeers->getOwnId())))
continue;
mesgString += link.toHtmlSize();
if (it!= hashedFiles.end()) {
mesgString += "<BR>";
@ -876,9 +878,15 @@ void FriendsDialog::recommendFriends()
FriendRecommendDialog::showYourself();
}
void FriendsDialog::servicePermission()
{
ServicePermissionDialog dlg;
dlg.exec();
}
/*static*/ ChatTabWidget *FriendsDialog::getTabWidget()
{
return instance ? instance->ui.tabWidget : NULL;
return instance ? instance->ui.tabWidget : NULL;
}
/*static*/ bool FriendsDialog::isGroupChatActive()

View File

@ -15,7 +15,7 @@
*
* 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,
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
@ -115,6 +115,7 @@ private slots:
void createChatLobby();
void recommendFriends();
void servicePermission();
signals:
void notifyGroupChat(const QString&,const QString&) ;

View File

@ -839,6 +839,11 @@
<string>Reset font to default</string>
</property>
</action>
<action name="actionServicePermission">
<property name="text">
<string>Service permissions</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -0,0 +1,126 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2013, 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 <QTreeWidgetItem>
#include "ServicePermissionDialog.h"
#include "ui_ServicePermissionDialog.h"
#include "settings/rsharesettings.h"
ServicePermissionDialog::ServicePermissionDialog() :
QDialog(NULL, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
ui(new Ui::ServicePermissionDialog)
{
ui->setupUi(this);
Settings->loadWidgetInformation(this);
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(setPermissions()));
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(ui->servicePermissionList, SIGNAL(itemAdded(int,QString,QTreeWidgetItem*)), this, SLOT(itemAdded(int,QString,QTreeWidgetItem*)));
connect(ui->servicePermissionList, SIGNAL(itemChanged(int,QString,QTreeWidgetItem*,int)), this, SLOT(itemChanged(int,QString,QTreeWidgetItem*,int)));
ui->servicePermissionList->setModus(FriendSelectionWidget::MODUS_SINGLE);
ui->servicePermissionList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_GPG);
/* add columns */
int column = ui->servicePermissionList->addColumn(tr("Anonymous routing"));
mColumns[column] = RS_SERVICE_PERM_TURTLE;
column = ui->servicePermissionList->addColumn(tr("Discovery"));
mColumns[column] = RS_SERVICE_PERM_DISCOVERY;
column = ui->servicePermissionList->addColumn(tr("Forums/Channels"));
mColumns[column] = RS_SERVICE_PERM_DISTRIB;
ui->servicePermissionList->start();
}
ServicePermissionDialog::~ServicePermissionDialog()
{
Settings->saveWidgetInformation(this);
delete ui;
}
void ServicePermissionDialog::itemAdded(int idType, const QString &id, QTreeWidgetItem *item)
{
if (idType != FriendSelectionWidget::IDTYPE_GPG) {
return;
}
RsPeerDetails detail;
if (!rsPeers->getPeerDetails(id.toStdString(), detail)) {
return;
}
QMap<int, ServicePermissionFlags>::iterator it;
for (it = mColumns.begin(); it != mColumns.end(); ++it) {
item->setCheckState(it.key(), (detail.service_perm_flags & it.value()) ? Qt::Checked : Qt::Unchecked);
}
}
void ServicePermissionDialog::itemChanged(int idType, const QString &id, QTreeWidgetItem *item, int column)
{
if (idType != FriendSelectionWidget::IDTYPE_GPG) {
return;
}
if (!mColumns.contains(column)) {
return;
}
QList<QTreeWidgetItem*> items;
ui->servicePermissionList->itemsFromId((FriendSelectionWidget::IdType) idType, id.toStdString(), items);
/* set checkboxes for the same id in other groups */
QList<QTreeWidgetItem*>::iterator it;
for (it = items.begin(); it != items.end(); ++it) {
if (*it == item) {
continue;
}
(*it)->setCheckState(column, item->checkState(column));
}
}
void ServicePermissionDialog::setPermissions()
{
QList<QTreeWidgetItem*> items;
ui->servicePermissionList->items(items, FriendSelectionWidget::IDTYPE_GPG);
/* no problem when gpg id is assigned twice */
QList<QTreeWidgetItem*>::iterator itemIt;
for (itemIt = items.begin(); itemIt != items.end(); ++itemIt) {
QTreeWidgetItem *item = *itemIt;
ServicePermissionFlags flags(0);
QMap<int, ServicePermissionFlags>::iterator it;
for (it = mColumns.begin(); it != mColumns.end(); ++it) {
if (item->checkState(it.key()) == Qt::Checked) {
flags |= it.value();
}
}
rsPeers->setServicePermissionFlags(ui->servicePermissionList->idFromItem(item), flags);
}
done(Accepted);
}

View File

@ -0,0 +1,55 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2013, 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.
****************************************************************/
#ifndef SERVICEPERMISSIONDIALOG_H
#define SERVICEPERMISSIONDIALOG_H
#include <QDialog>
#include <QMap>
#include <retroshare/rspeers.h>
class QTreeWidgetItem;
namespace Ui {
class ServicePermissionDialog;
}
class ServicePermissionDialog : public QDialog
{
Q_OBJECT
public:
ServicePermissionDialog();
~ServicePermissionDialog();
private slots:
void itemAdded(int idType, const QString &id, QTreeWidgetItem *item);
void itemChanged(int idType, const QString &id, QTreeWidgetItem *item, int column);
void setPermissions();
private:
QMap<int, ServicePermissionFlags> mColumns;
Ui::ServicePermissionDialog *ui;
};
#endif // SERVICEPERMISSIONDIALOG_H

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ServicePermissionDialog</class>
<widget class="QDialog" name="ServicePermissionDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>493</width>
<height>362</height>
</rect>
</property>
<property name="windowTitle">
<string>Service permissions</string>
</property>
<property name="windowIcon">
<iconset resource="images.qrc">
<normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="FriendSelectionWidget" name="servicePermissionList" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>FriendSelectionWidget</class>
<extends>QWidget</extends>
<header>gui/common/FriendSelectionWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="images.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -37,6 +37,7 @@
#define COLUMN_NAME 0
#define COLUMN_CHECK 0
#define COLUMN_DATA 0
#define COLUMN_COUNT 1
#define ROLE_ID Qt::UserRole
#define ROLE_SORT Qt::UserRole + 1
@ -76,12 +77,13 @@ FriendSelectionWidget::FriendSelectionWidget(QWidget *parent) :
{
ui->setupUi(this);
started = false;
listModus = MODUS_SINGLE;
showTypes = SHOW_GROUP | SHOW_SSL;
inGroupItemChanged = false;
inGpgItemChanged = false;
inSslItemChanged = false;
mStarted = false;
mListModus = MODUS_SINGLE;
mShowTypes = SHOW_GROUP | SHOW_SSL;
mInGroupItemChanged = false;
mInGpgItemChanged = false;
mInSslItemChanged = false;
mInFillList = false;
connect(ui->friendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
connect(ui->friendList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*,int)));
@ -91,10 +93,14 @@ FriendSelectionWidget::FriendSelectionWidget(QWidget *parent) :
connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(fillList()));
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&,int)), this, SLOT(peerStatusChanged(const QString&,int)));
compareRole = new RSTreeWidgetItemCompareRole;
compareRole->setRole(COLUMN_NAME, ROLE_SORT);
mCompareRole = new RSTreeWidgetItemCompareRole;
mCompareRole->setRole(COLUMN_NAME, ROLE_SORT);
// sort list by name ascending
/* initialize list */
ui->friendList->setColumnCount(COLUMN_COUNT);
ui->friendList->headerItem()->setText(COLUMN_NAME, tr("Name"));
/* sort list by name ascending */
ui->friendList->sortItems(COLUMN_NAME, Qt::AscendingOrder);
ui->filterLineEdit->setPlaceholderText(tr("Search Friends"));
@ -129,9 +135,9 @@ void FriendSelectionWidget::setHeaderText(const QString &text)
void FriendSelectionWidget::setModus(Modus modus)
{
listModus = modus;
mListModus = modus;
switch (listModus) {
switch (mListModus) {
case MODUS_SINGLE:
case MODUS_CHECK:
ui->friendList->setSelectionMode(QAbstractItemView::SingleSelection);
@ -146,15 +152,27 @@ void FriendSelectionWidget::setModus(Modus modus)
void FriendSelectionWidget::setShowType(ShowTypes types)
{
showTypes = types;
mShowTypes = types;
fillList();
}
int FriendSelectionWidget::addColumn(const QString &title)
{
int column = ui->friendList->columnCount();
ui->friendList->setColumnCount(column + 1);
ui->friendList->headerItem()->setText(column, title);
return column;
}
void FriendSelectionWidget::start()
{
started = true;
mStarted = true;
fillList();
for (int i = 0; i < ui->friendList->columnCount(); ++i) {
ui->friendList->resizeColumnToContents(i);
}
}
static void initSslItem(QTreeWidgetItem *item, const RsPeerDetails &detail, const std::list<StatusInfo> &statusInfo, QColor textColorOnline)
@ -184,23 +202,25 @@ static void initSslItem(QTreeWidgetItem *item, const RsPeerDetails &detail, cons
void FriendSelectionWidget::fillList()
{
if (!started) {
if (!mStarted) {
return;
}
mInFillList = true;
// get selected items
std::list<std::string> sslIdsSelected;
if (showTypes & SHOW_SSL) {
if (mShowTypes & SHOW_SSL) {
selectedSslIds(sslIdsSelected, true);
}
std::list<std::string> groupIdsSelected;
if (showTypes & SHOW_GROUP) {
if (mShowTypes & SHOW_GROUP) {
selectedGroupIds(groupIdsSelected);
}
std::list<std::string> gpgIdsSelected;
if (showTypes & SHOW_GPG) {
if (mShowTypes & SHOW_GPG) {
selectedGpgIds(gpgIdsSelected, true);
}
@ -218,7 +238,7 @@ void FriendSelectionWidget::fillList()
std::list<std::string> sslIds;
std::list<std::string>::iterator sslIt;
if ((showTypes & (SHOW_SSL | SHOW_GPG)) == SHOW_SSL) {
if ((mShowTypes & (SHOW_SSL | SHOW_GPG)) == SHOW_SSL) {
rsPeers->getFriendList(sslIds);
}
@ -235,7 +255,7 @@ void FriendSelectionWidget::fillList()
QTreeWidgetItem *gpgItem = NULL;
RsGroupInfo *groupInfo = NULL;
if ((showTypes & SHOW_GROUP) && groupIt != groupInfoList.end()) {
if ((mShowTypes & SHOW_GROUP) && groupIt != groupInfoList.end()) {
groupInfo = &(*groupIt);
if (groupInfo->peerIds.size() == 0) {
@ -245,11 +265,12 @@ void FriendSelectionWidget::fillList()
}
// add group item
groupItem = new RSTreeWidgetItem(compareRole, IDTYPE_GROUP);
groupItem = new RSTreeWidgetItem(mCompareRole, IDTYPE_GROUP);
// Add item to the list
ui->friendList->addTopLevelItem(groupItem);
groupItem->setFlags(Qt::ItemIsUserCheckable | groupItem->flags());
groupItem->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
groupItem->setTextAlignment(COLUMN_NAME, Qt::AlignLeft | Qt::AlignVCenter);
groupItem->setIcon(COLUMN_NAME, QIcon(IMAGE_GROUP16));
@ -262,17 +283,18 @@ void FriendSelectionWidget::fillList()
groupItem->setText(COLUMN_NAME, groupName);
groupItem->setData(COLUMN_DATA, ROLE_SORT, ((groupInfo->flag & RS_GROUP_FLAG_STANDARD) ? "0 " : "1 ") + groupName);
if (listModus == MODUS_CHECK) {
groupItem->setFlags(Qt::ItemIsUserCheckable | groupItem->flags());
if (mListModus == MODUS_CHECK) {
groupItem->setCheckState(0, Qt::Unchecked);
}
emit itemAdded(IDTYPE_GROUP, QString::fromStdString(groupInfo->id), groupItem);
if (std::find(groupIdsSelected.begin(), groupIdsSelected.end(), groupInfo->id) != groupIdsSelected.end()) {
setSelected(listModus, groupItem, true);
setSelected(mListModus, groupItem, true);
}
}
if (showTypes & SHOW_GPG) {
if (mShowTypes & SHOW_GPG) {
// iterate through gpg ids
for (gpgIt = gpgIds.begin(); gpgIt != gpgIds.end(); gpgIt++) {
if (groupInfo) {
@ -296,7 +318,7 @@ void FriendSelectionWidget::fillList()
}
// make a widget per friend
gpgItem = new RSTreeWidgetItem(compareRole, IDTYPE_GPG);
gpgItem = new RSTreeWidgetItem(mCompareRole, IDTYPE_GPG);
QString name = QString::fromUtf8(detail.name.c_str());
gpgItem->setText(COLUMN_NAME, name);
@ -318,12 +340,12 @@ void FriendSelectionWidget::fillList()
gpgItem->setTextColor(COLUMN_NAME, textColorOnline());
}
gpgItem->setFlags(Qt::ItemIsUserCheckable | gpgItem->flags());
gpgItem->setIcon(COLUMN_NAME, QIcon(StatusDefs::imageUser(state)));
gpgItem->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.gpg_id));
gpgItem->setData(COLUMN_DATA, ROLE_SORT, "2 " + name);
if (listModus == MODUS_CHECK) {
gpgItem->setFlags(Qt::ItemIsUserCheckable | gpgItem->flags());
if (mListModus == MODUS_CHECK) {
gpgItem->setCheckState(0, Qt::Unchecked);
}
@ -336,7 +358,9 @@ void FriendSelectionWidget::fillList()
gpgItem->setExpanded(true);
if (showTypes & SHOW_SSL) {
emit itemAdded(IDTYPE_GPG, QString::fromStdString(detail.gpg_id), gpgItem);
if (mShowTypes & SHOW_SSL) {
// iterate through associated ssl ids
for (sslIt = sslIds.begin(); sslIt != sslIds.end(); sslIt++) {
RsPeerDetails detail;
@ -345,26 +369,28 @@ void FriendSelectionWidget::fillList()
}
// make a widget per friend
QTreeWidgetItem *item = new RSTreeWidgetItem(compareRole, IDTYPE_SSL);
QTreeWidgetItem *item = new RSTreeWidgetItem(mCompareRole, IDTYPE_SSL);
item->setFlags(Qt::ItemIsUserCheckable | item->flags());
initSslItem(item, detail, statusInfo, textColorOnline());
if (listModus == MODUS_CHECK) {
item->setFlags(Qt::ItemIsUserCheckable | item->flags());
if (mListModus == MODUS_CHECK) {
item->setCheckState(0, Qt::Unchecked);
}
// add to the list
gpgItem->addChild(item);
emit itemAdded(IDTYPE_SSL, QString::fromStdString(detail.id), item);
if (std::find(sslIdsSelected.begin(), sslIdsSelected.end(), detail.id) != sslIdsSelected.end()) {
setSelected(listModus, item, true);
setSelected(mListModus, item, true);
}
}
}
if (std::find(gpgIdsSelected.begin(), gpgIdsSelected.end(), detail.gpg_id) != gpgIdsSelected.end()) {
setSelected(listModus, gpgItem, true);
setSelected(mListModus, gpgItem, true);
}
}
} else {
@ -391,12 +417,12 @@ void FriendSelectionWidget::fillList()
filledIds.push_back(detail.id);
// make a widget per friend
QTreeWidgetItem *item = new RSTreeWidgetItem(compareRole, IDTYPE_SSL);
QTreeWidgetItem *item = new RSTreeWidgetItem(mCompareRole, IDTYPE_SSL);
initSslItem(item, detail, statusInfo, textColorOnline());
item->setFlags(Qt::ItemIsUserCheckable | item->flags());
if (listModus == MODUS_CHECK) {
item->setFlags(Qt::ItemIsUserCheckable | item->flags());
if (mListModus == MODUS_CHECK) {
item->setCheckState(0, Qt::Unchecked);
}
@ -407,8 +433,10 @@ void FriendSelectionWidget::fillList()
ui->friendList->addTopLevelItem(item);
}
emit itemAdded(IDTYPE_SSL, QString::fromStdString(detail.id), item);
if (std::find(sslIdsSelected.begin(), sslIdsSelected.end(), detail.id) != sslIdsSelected.end()) {
setSelected(listModus, item, true);
setSelected(mListModus, item, true);
}
}
}
@ -427,6 +455,8 @@ void FriendSelectionWidget::fillList()
ui->friendList->update(); /* update display */
mInFillList = false;
emit contentChanged();
}
@ -435,7 +465,7 @@ void FriendSelectionWidget::peerStatusChanged(const QString& peerId, int status)
QString gpgId;
int gpgStatus = RS_STATUS_OFFLINE;
if (showTypes & SHOW_GPG) {
if (mShowTypes & SHOW_GPG) {
/* need gpg id and online state */
RsPeerDetails detail;
if (rsPeers->getPeerDetails(peerId.toStdString(), detail)) {
@ -469,7 +499,7 @@ void FriendSelectionWidget::peerStatusChanged(const QString& peerId, int status)
while ((item = *itemIterator) != NULL) {
itemIterator++;
switch ((IdType) item->type()) {
switch (idTypeFromItem(item)) {
case IDTYPE_NONE:
case IDTYPE_GROUP:
break;
@ -519,97 +549,102 @@ void FriendSelectionWidget::itemDoubleClicked(QTreeWidgetItem *item, int /*colum
return;
}
emit doubleClicked((IdType) item->type(), item->data(COLUMN_DATA, ROLE_ID).toString());
emit doubleClicked(idTypeFromItem(item), item->data(COLUMN_DATA, ROLE_ID).toString());
}
void FriendSelectionWidget::itemChanged(QTreeWidgetItem *item, int column)
{
if (listModus != MODUS_CHECK) {
if (mInFillList) {
return;
}
if (column != COLUMN_CHECK) {
emit itemChanged(idTypeFromItem(item), item->data(COLUMN_DATA, ROLE_ID).toString(), item, column);
return;
}
switch ((IdType) item->type()) {
if (mListModus != MODUS_CHECK) {
return;
}
switch (idTypeFromItem(item)) {
case IDTYPE_NONE:
break;
case IDTYPE_GROUP:
{
if (inGroupItemChanged || inGpgItemChanged || inSslItemChanged) {
if (mInGroupItemChanged || mInGpgItemChanged || mInSslItemChanged) {
break;
}
inGroupItemChanged = true;
mInGroupItemChanged = true;
bool selected = isSelected(listModus, item);
bool selected = isSelected(mListModus, item);
int childCount = item->childCount();
for (int i = 0; i < childCount; ++i) {
setSelected(listModus, item->child(i), selected);
setSelected(mListModus, item->child(i), selected);
}
inGroupItemChanged = false;
mInGroupItemChanged = false;
}
break;
case IDTYPE_GPG:
{
if (inGpgItemChanged) {
if (mInGpgItemChanged) {
break;
}
inGpgItemChanged = true;
mInGpgItemChanged = true;
if (!inSslItemChanged) {
bool selected = isSelected(listModus, item);
if (!mInSslItemChanged) {
bool selected = isSelected(mListModus, item);
int childCount = item->childCount();
for (int i = 0; i < childCount; ++i) {
setSelected(listModus, item->child(i), selected);
setSelected(mListModus, item->child(i), selected);
}
}
if (!inGroupItemChanged) {
if (!mInGroupItemChanged) {
QTreeWidgetItem *itemParent = item->parent();
if (itemParent) {
int childCount = itemParent->childCount();
bool foundUnselected = false;
for (int index = 0; index < childCount; ++index) {
if (!isSelected(listModus, itemParent->child(index))) {
if (!isSelected(mListModus, itemParent->child(index))) {
foundUnselected = true;
break;
}
}
setSelected(listModus, itemParent, !foundUnselected);
setSelected(mListModus, itemParent, !foundUnselected);
}
}
inGpgItemChanged = false;
mInGpgItemChanged = false;
}
break;
case IDTYPE_SSL:
{
if (inGroupItemChanged || inGpgItemChanged || inSslItemChanged) {
if (mInGroupItemChanged || mInGpgItemChanged || mInSslItemChanged) {
break;
}
inSslItemChanged = true;
mInSslItemChanged = true;
QTreeWidgetItem *itemParent = item->parent();
if (itemParent) {
int childCount = itemParent->childCount();
bool foundUnselected = false;
for (int index = 0; index < childCount; ++index) {
if (!isSelected(listModus, itemParent->child(index))) {
if (!isSelected(mListModus, itemParent->child(index))) {
foundUnselected = true;
break;
}
}
setSelected(listModus, itemParent, !foundUnselected);
setSelected(mListModus, itemParent, !foundUnselected);
}
inSslItemChanged = false;
mInSslItemChanged = false;
}
break;
}
@ -655,7 +690,7 @@ int FriendSelectionWidget::selectedItemCount()
return ui->friendList->selectedItems().count();
}
QString FriendSelectionWidget::selectedId(IdType &idType)
std::string FriendSelectionWidget::selectedId(IdType &idType)
{
QTreeWidgetItem *item = ui->friendList->currentItem();
if (!item) {
@ -663,8 +698,8 @@ QString FriendSelectionWidget::selectedId(IdType &idType)
return "";
}
idType = (IdType) item->type();
return item->data(COLUMN_DATA, ROLE_ID).toString();
idType = idTypeFromItem(item);
return idFromItem(item);
}
void FriendSelectionWidget::selectedIds(IdType idType, std::list<std::string> &ids, bool onlyDirectSelected)
@ -676,26 +711,26 @@ void FriendSelectionWidget::selectedIds(IdType idType, std::list<std::string> &i
std::string id;
switch ((IdType) item->type()) {
switch (idTypeFromItem(item)) {
case IDTYPE_NONE:
break;
case IDTYPE_GROUP:
if (idType == IDTYPE_GROUP) {
if (isSelected(listModus, item)) {
id = item->data(COLUMN_DATA, ROLE_ID).toString().toStdString();
if (isSelected(mListModus, item)) {
id = idFromItem(item);
}
}
break;
case IDTYPE_GPG:
if (idType == IDTYPE_GPG) {
if (isSelected(listModus, item)) {
id = item->data(COLUMN_DATA, ROLE_ID).toString().toStdString();
if (isSelected(mListModus, item)) {
id = idFromItem(item);
} else {
if (!onlyDirectSelected) {
QTreeWidgetItem *itemParent = item;
while ((itemParent = itemParent->parent()) != NULL) {
if (isSelected(listModus, itemParent)) {
id = item->data(COLUMN_DATA, ROLE_ID).toString().toStdString();
if (isSelected(mListModus, itemParent)) {
id = idFromItem(item);
break;
}
}
@ -705,14 +740,14 @@ void FriendSelectionWidget::selectedIds(IdType idType, std::list<std::string> &i
break;
case IDTYPE_SSL:
if (idType == IDTYPE_SSL) {
if (isSelected(listModus, item)) {
id = item->data(COLUMN_DATA, ROLE_ID).toString().toStdString();
if (isSelected(mListModus, item)) {
id = idFromItem(item);
} else {
if (!onlyDirectSelected) {
QTreeWidgetItem *itemParent = item;
while ((itemParent = itemParent->parent()) != NULL) {
if (isSelected(listModus, itemParent)) {
id = item->data(COLUMN_DATA, ROLE_ID).toString().toStdString();
if (isSelected(mListModus, itemParent)) {
id = idFromItem(item);
break;
}
}
@ -734,8 +769,8 @@ void FriendSelectionWidget::setSelectedIds(IdType idType, const std::list<std::s
while ((item = *itemIterator) != NULL) {
itemIterator++;
std::string id = item->data(COLUMN_DATA, ROLE_ID).toString().toStdString();
IdType itemType = (IdType) item->type();
std::string id = idFromItem(item);
IdType itemType = idTypeFromItem(item);
switch (itemType) {
case IDTYPE_NONE:
@ -745,14 +780,58 @@ void FriendSelectionWidget::setSelectedIds(IdType idType, const std::list<std::s
case IDTYPE_SSL:
if (idType == itemType) {
if (std::find(ids.begin(), ids.end(), id) != ids.end()) {
setSelected(listModus, item, true);
setSelected(mListModus, item, true);
break;
}
}
if (!add) {
setSelected(listModus, item, false);
setSelected(mListModus, item, false);
}
break;
}
}
}
void FriendSelectionWidget::itemsFromId(IdType idType, const std::string &id, QList<QTreeWidgetItem*> &items)
{
QTreeWidgetItemIterator itemIterator(ui->friendList);
QTreeWidgetItem *item;
while ((item = *itemIterator) != NULL) {
itemIterator++;
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) {
itemIterator++;
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();
}

View File

@ -69,10 +69,11 @@ public:
void setHeaderText(const QString &text);
void setModus(Modus modus);
void setShowType(ShowTypes types);
int addColumn(const QString &title);
void start();
int selectedItemCount();
QString selectedId(IdType &idType);
std::string selectedId(IdType &idType);
void selectedSslIds(std::list<std::string> &sslIds, bool onlyDirectSelected) { selectedIds(IDTYPE_SSL, sslIds, onlyDirectSelected); }
void selectedGpgIds(std::list<std::string> &gpgIds, bool onlyDirectSelected) { selectedIds(IDTYPE_GPG, gpgIds, onlyDirectSelected); }
void selectedGroupIds(std::list<std::string> &groupIds) { selectedIds(IDTYPE_GROUP, groupIds, true); }
@ -81,6 +82,12 @@ public:
void setSelectedGpgIds(const std::list<std::string> &gpgIds, bool add) { setSelectedIds(IDTYPE_GPG, gpgIds, add); }
void setSelectedGroupIds(const std::list<std::string> &groupIds, bool add) { setSelectedIds(IDTYPE_GROUP, groupIds, add); }
void itemsFromId(IdType idType, const std::string &id, QList<QTreeWidgetItem*> &items);
void items(QList<QTreeWidgetItem*> &items, IdType = IDTYPE_NONE);
IdType idTypeFromItem(QTreeWidgetItem *item);
std::string idFromItem(QTreeWidgetItem *item);
QColor textColorOnline() const { return mTextColorOnline; }
void setTextColorOnline(QColor color) { mTextColorOnline = color; }
@ -89,9 +96,11 @@ protected:
void changeEvent(QEvent *e);
signals:
void itemAdded(int idType, const QString &id, QTreeWidgetItem *item);
void contentChanged();
void customContextMenuRequested(const QPoint &pos);
void doubleClicked(IdType idType, const QString &id);
void doubleClicked(int idType, const QString &id);
void itemChanged(int idType, const QString &id, QTreeWidgetItem *item, int column);
private slots:
void fillList();
@ -107,13 +116,14 @@ private:
void selectedIds(IdType idType, std::list<std::string> &ids, bool onlyDirectSelected);
void setSelectedIds(IdType idType, const std::list<std::string> &ids, bool add);
bool started;
RSTreeWidgetItemCompareRole *compareRole;
Modus listModus;
ShowTypes showTypes;
bool inGroupItemChanged;
bool inGpgItemChanged;
bool inSslItemChanged;
bool mStarted;
RSTreeWidgetItemCompareRole *mCompareRole;
Modus mListModus;
ShowTypes mShowTypes;
bool mInGroupItemChanged;
bool mInGpgItemChanged;
bool mInSslItemChanged;
bool mInFillList;
/* Color definitions (for standard see qss.default) */
QColor mTextColorOnline;

View File

@ -201,7 +201,7 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WFlags flags)
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&,int)), this, SLOT(peerStatusChanged(const QString&,int)));
connect(ui.friendSelectionWidget, SIGNAL(contentChanged()), this, SLOT(buildCompleter()));
connect(ui.friendSelectionWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuMsgSendList(QPoint)));
connect(ui.friendSelectionWidget, SIGNAL(doubleClicked(IdType,QString)), this, SLOT(addTo()));
connect(ui.friendSelectionWidget, SIGNAL(doubleClicked(int,QString)), this, SLOT(addTo()));
/* hide the Tree +/- */
ui.msgFileList -> setRootIsDecorated( false );
@ -2281,13 +2281,13 @@ void MessageComposer::addRecommend()
void MessageComposer::friendDetails()
{
FriendSelectionWidget::IdType idType;
QString id = ui.friendSelectionWidget->selectedId(idType);
std::string id = ui.friendSelectionWidget->selectedId(idType);
if (id.isEmpty() || idType != FriendSelectionWidget::IDTYPE_SSL) {
if (id.empty() || idType != FriendSelectionWidget::IDTYPE_SSL) {
return;
}
ConfCertDialog::showIt(id.toStdString(), ConfCertDialog::PageDetails);
ConfCertDialog::showIt(id, ConfCertDialog::PageDetails);
}
void MessageComposer::tagAboutToShow()

View File

@ -4733,6 +4733,10 @@ p, li { white-space: pre-wrap; }
<source>Search Friends</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Name</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>FriendsDialog</name>
@ -4900,6 +4904,10 @@ p, li { white-space: pre-wrap; }
<source>Edit your status message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Service permissions</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GamesDialog</name>
@ -10604,6 +10612,25 @@ peers still need to trust each other to allow connection. </source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ServicePermissionDialog</name>
<message>
<source>Service permissions</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Anonymous routing</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Discovery</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Forums/Channels</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Settings</name>
<message>

View File

@ -284,6 +284,7 @@ HEADERS += rshare.h \
gui/MessengerWindow.h \
gui/FriendsDialog.h \
gui/FriendRecommendDialog.h \
gui/ServicePermissionDialog.h \
gui/RemoteDirModel.h \
gui/RetroShareLink.h \
gui/SearchTreeWidget.h \
@ -485,6 +486,7 @@ FORMS += gui/StartDialog.ui \
gui/HelpDialog.ui \
gui/DetailsDialog.ui \
gui/FriendRecommendDialog.ui \
gui/ServicePermissionDialog.ui \
gui/bwgraph/bwgraph.ui \
gui/profile/ProfileWidget.ui \
gui/profile/StatusMessage.ui \
@ -586,6 +588,7 @@ SOURCES += main.cpp \
gui/MessengerWindow.cpp \
gui/FriendsDialog.cpp \
gui/FriendRecommendDialog.cpp \
gui/ServicePermissionDialog.cpp \
gui/RemoteDirModel.cpp \
gui/RsAutoUpdatePage.cpp \
gui/RetroShareLink.cpp \