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 "util/DateTime.h"
#include "chat/CreateLobbyDialog.h" #include "chat/CreateLobbyDialog.h"
#include "FriendRecommendDialog.h" #include "FriendRecommendDialog.h"
#include "FriendsDialog.h" #include "FriendsDialog.h"
#include "ServicePermissionDialog.h"
/* Images for Newsfeed icons */ /* Images for Newsfeed icons */
#define IMAGE_NEWSFEED "" #define IMAGE_NEWSFEED ""
@ -87,6 +87,7 @@ FriendsDialog::FriendsDialog(QWidget *parent)
connect( ui.actionAdd_Friend, SIGNAL(triggered()), this, SLOT(addFriend())); connect( ui.actionAdd_Friend, SIGNAL(triggered()), this, SLOT(addFriend()));
connect( ui.actionCreate_new_Chat_lobby, SIGNAL(triggered()), this, SLOT(createChatLobby())); connect( ui.actionCreate_new_Chat_lobby, SIGNAL(triggered()), this, SLOT(createChatLobby()));
connect( ui.actionFriendRecommendations, SIGNAL(triggered()), this, SLOT(recommendFriends())); 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))); connect( ui.filter_lineEdit, SIGNAL(textChanged(QString)), ui.friendList, SLOT(filterItems(QString)));
ui.filter_lineEdit->setPlaceholderText(tr("Search")) ; ui.filter_lineEdit->setPlaceholderText(tr("Search")) ;
@ -169,6 +170,7 @@ FriendsDialog::FriendsDialog(QWidget *parent)
menu->addAction(ui.actionAdd_Group); menu->addAction(ui.actionAdd_Group);
menu->addAction(ui.actionCreate_new_Chat_lobby); menu->addAction(ui.actionCreate_new_Chat_lobby);
menu->addAction(ui.actionFriendRecommendations); menu->addAction(ui.actionFriendRecommendations);
menu->addAction(ui.actionServicePermission);
menu->addSeparator(); menu->addSeparator();
menu->addAction(ui.actionSet_your_Avatar); menu->addAction(ui.actionSet_your_Avatar);
@ -876,6 +878,12 @@ void FriendsDialog::recommendFriends()
FriendRecommendDialog::showYourself(); FriendRecommendDialog::showYourself();
} }
void FriendsDialog::servicePermission()
{
ServicePermissionDialog dlg;
dlg.exec();
}
/*static*/ ChatTabWidget *FriendsDialog::getTabWidget() /*static*/ ChatTabWidget *FriendsDialog::getTabWidget()
{ {
return instance ? instance->ui.tabWidget : NULL; return instance ? instance->ui.tabWidget : NULL;

View File

@ -115,6 +115,7 @@ private slots:
void createChatLobby(); void createChatLobby();
void recommendFriends(); void recommendFriends();
void servicePermission();
signals: signals:
void notifyGroupChat(const QString&,const QString&) ; void notifyGroupChat(const QString&,const QString&) ;

View File

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

View File

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

View File

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