From 09f42dbc3c5b195267a573440c16fb7980928507 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Sat, 24 Nov 2012 14:48:31 +0000 Subject: [PATCH] Added new level gpg id to FriendSelectionWidget (groups, gpg id, ssl id). Added friend selection to the group dialog for better assigning of friends to groups. Updated english translation. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5881 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/p3peermgr.cc | 2 + .../src/gui/FriendRecommendDialog.cpp | 1 + .../src/gui/channels/CreateChannel.cpp | 1 + retroshare-gui/src/gui/channels/ShareKey.cpp | 1 + .../src/gui/chat/CreateLobbyDialog.cpp | 1 + retroshare-gui/src/gui/common/FriendList.cpp | 5 +- .../src/gui/common/FriendSelectionWidget.cpp | 425 ++++++++++++++---- .../src/gui/common/FriendSelectionWidget.h | 23 +- retroshare-gui/src/gui/forums/CreateForum.cpp | 1 + retroshare-gui/src/gui/groups/CreateGroup.cpp | 151 ++++--- retroshare-gui/src/gui/groups/CreateGroup.h | 31 +- retroshare-gui/src/gui/groups/CreateGroup.ui | 93 ++-- .../src/gui/msgs/MessageComposer.cpp | 1 + retroshare-gui/src/lang/retroshare_en.ts | 4 + 14 files changed, 505 insertions(+), 235 deletions(-) diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index fbe1ce488..2e745f4d2 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -1592,6 +1592,8 @@ bool p3PeerMgrIMPL::addGroup(RsGroupInfo &groupInfo) groupItem->PeerId(getOwnId()); groupList.push_back(groupItem); + + groupInfo.id = groupItem->id; } rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_ADD); diff --git a/retroshare-gui/src/gui/FriendRecommendDialog.cpp b/retroshare-gui/src/gui/FriendRecommendDialog.cpp index 735fd4982..fde8c2905 100644 --- a/retroshare-gui/src/gui/FriendRecommendDialog.cpp +++ b/retroshare-gui/src/gui/FriendRecommendDialog.cpp @@ -47,6 +47,7 @@ FriendRecommendDialog::FriendRecommendDialog() : ui->recommendList->setHeaderText(tr("Recommend friends")); ui->recommendList->setModus(FriendSelectionWidget::MODUS_CHECK); + ui->recommendList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL); ui->recommendList->start(); ui->toList->setHeaderText(tr("To")); diff --git a/retroshare-gui/src/gui/channels/CreateChannel.cpp b/retroshare-gui/src/gui/channels/CreateChannel.cpp index 2f69fe6ee..4342204b0 100644 --- a/retroshare-gui/src/gui/channels/CreateChannel.cpp +++ b/retroshare-gui/src/gui/channels/CreateChannel.cpp @@ -60,6 +60,7 @@ CreateChannel::CreateChannel() /* initialize key share list */ ui.keyShareList->setHeaderText(tr("Contacts:")); ui.keyShareList->setModus(FriendSelectionWidget::MODUS_CHECK); + ui.keyShareList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL); ui.keyShareList->start(); newChannel(); diff --git a/retroshare-gui/src/gui/channels/ShareKey.cpp b/retroshare-gui/src/gui/channels/ShareKey.cpp index 6ff9d45fe..52adf91e5 100644 --- a/retroshare-gui/src/gui/channels/ShareKey.cpp +++ b/retroshare-gui/src/gui/channels/ShareKey.cpp @@ -45,6 +45,7 @@ ShareKey::ShareKey(QWidget *parent, std::string grpId, int grpType) : /* initialize key share list */ ui->keyShareList->setHeaderText(tr("Contacts:")); ui->keyShareList->setModus(FriendSelectionWidget::MODUS_CHECK); + ui->keyShareList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL); ui->keyShareList->start(); } diff --git a/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp b/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp index 5a134688f..93148ecc9 100644 --- a/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp +++ b/retroshare-gui/src/gui/chat/CreateLobbyDialog.cpp @@ -58,6 +58,7 @@ CreateLobbyDialog::CreateLobbyDialog(const std::list& peer_list, in /* initialize key share list */ ui->keyShareList->setHeaderText(tr("Contacts:")); ui->keyShareList->setModus(FriendSelectionWidget::MODUS_CHECK); + ui->keyShareList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL); ui->keyShareList->start(); ui->keyShareList->setSelectedSslIds(peer_list, false); diff --git a/retroshare-gui/src/gui/common/FriendList.cpp b/retroshare-gui/src/gui/common/FriendList.cpp index d0b812b21..ebec9f5a4 100644 --- a/retroshare-gui/src/gui/common/FriendList.cpp +++ b/retroshare-gui/src/gui/common/FriendList.cpp @@ -338,10 +338,9 @@ void FriendList::peerTreeWidgetCostumPopupMenu() contextMnu.addSeparator(); - QAction *action = contextMnu.addAction(QIcon(IMAGE_EDIT), tr("Edit Group"), this, SLOT(editGroup())); - action->setDisabled(standard); + contextMnu.addAction(QIcon(IMAGE_EDIT), tr("Edit Group"), this, SLOT(editGroup())); - action = contextMnu.addAction(QIcon(IMAGE_REMOVE), tr("Remove Group"), this, SLOT(removeGroup())); + QAction *action = contextMnu.addAction(QIcon(IMAGE_REMOVE), tr("Remove Group"), this, SLOT(removeGroup())); action->setDisabled(standard); lobbyMenu = contextMnu.addMenu(QIcon(IMAGE_CHAT), tr("Chat lobbies")) ; diff --git a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp index 9c27f3ae7..56801d980 100644 --- a/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp +++ b/retroshare-gui/src/gui/common/FriendSelectionWidget.cpp @@ -78,8 +78,10 @@ FriendSelectionWidget::FriendSelectionWidget(QWidget *parent) : started = false; listModus = MODUS_SINGLE; - showGroups = true; - inItemChanged = false; + showTypes = SHOW_GROUP | SHOW_SSL; + inGroupItemChanged = false; + inGpgItemChanged = false; + inSslItemChanged = false; connect(ui->friendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint))); connect(ui->friendList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*,int))); @@ -142,9 +144,9 @@ void FriendSelectionWidget::setModus(Modus modus) fillList(); } -void FriendSelectionWidget::setShowGroups(bool show) +void FriendSelectionWidget::setShowType(ShowTypes types) { - showGroups = show; + showTypes = types; fillList(); } @@ -155,6 +157,31 @@ void FriendSelectionWidget::start() fillList(); } +static void initSslItem(QTreeWidgetItem *item, const RsPeerDetails &detail, const std::list &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::const_iterator it; + for (it = statusInfo.begin(); it != statusInfo.end() ; it++) { + 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))); + item->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.id)); + item->setData(COLUMN_DATA, ROLE_SORT, "2 " + name); +} + void FriendSelectionWidget::fillList() { if (!started) { @@ -163,10 +190,19 @@ void FriendSelectionWidget::fillList() // get selected items std::list sslIdsSelected; - selectedSslIds(sslIdsSelected, true); + if (showTypes & SHOW_SSL) { + selectedSslIds(sslIdsSelected, true); + } std::list groupIdsSelected; - selectedGroupIds(groupIdsSelected); + if (showTypes & SHOW_GROUP) { + selectedGroupIds(groupIdsSelected); + } + + std::list gpgIdsSelected; + if (showTypes & SHOW_GPG) { + selectedGpgIds(gpgIdsSelected, true); + } // remove old items ui->friendList->clear(); @@ -176,22 +212,30 @@ void FriendSelectionWidget::fillList() std::list::iterator groupIt; rsPeers->getGroupInfoList(groupInfoList); + std::list gpgIds; + std::list::iterator gpgIt; + rsPeers->getGPGAcceptedList(gpgIds); + std::list sslIds; std::list::iterator sslIt; - rsPeers->getFriendList(sslIds); + if ((showTypes & (SHOW_SSL | SHOW_GPG)) == SHOW_SSL) { + rsPeers->getFriendList(sslIds); + } std::list statusInfo; + std::list::iterator statusIt; rsStatus->getStatusList(statusInfo); - std::list filledSslIds; + std::list filledIds; // gpg or ssl id // start with groups groupIt = groupInfoList.begin(); while (true) { QTreeWidgetItem *groupItem = NULL; + QTreeWidgetItem *gpgItem = NULL; RsGroupInfo *groupInfo = NULL; - if (showGroups && groupIt != groupInfoList.end()) { + if ((showTypes & SHOW_GROUP) && groupIt != groupInfoList.end()) { groupInfo = &(*groupIt); if (groupInfo->peerIds.size() == 0) { @@ -228,67 +272,144 @@ void FriendSelectionWidget::fillList() } } - // iterate through ssl ids - for (sslIt = sslIds.begin(); sslIt != sslIds.end(); sslIt++) { - RsPeerDetails detail; - if (!rsPeers->getPeerDetails(*sslIt, detail)) { - continue; /* BAD */ - } - - 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 - if (std::find(filledSslIds.begin(), filledSslIds.end(), *sslIt) != filledSslIds.end()) { - continue; - } - } - - // add equal too, its no problem - filledSslIds.push_back(detail.id); - - // make a widget per friend - QTreeWidgetItem *item = new RSTreeWidgetItem(compareRole, IDTYPE_SSL); - - QString name = PeerDefs::nameWithLocation(detail); - item->setText(COLUMN_NAME, name); - - int state = RS_STATUS_OFFLINE; - if (detail.state & RS_PEER_STATE_CONNECTED) { - std::list::iterator it; - for (it = statusInfo.begin(); it != statusInfo.end() ; it++) { - if (it->id == detail.id) { - state = it->status; - break; + if (showTypes & SHOW_GPG) { + // iterate through gpg ids + for (gpgIt = gpgIds.begin(); gpgIt != gpgIds.end(); gpgIt++) { + 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 + if (std::find(filledIds.begin(), filledIds.end(), *gpgIt) != filledIds.end()) { + continue; } } + + // add equal too, its no problem + filledIds.push_back(*gpgIt); + + RsPeerDetails detail; + if (!rsPeers->getPeerDetails(*gpgIt, detail)) { + continue; /* BAD */ + } + + // make a widget per friend + gpgItem = new RSTreeWidgetItem(compareRole, IDTYPE_GPG); + + QString name = QString::fromUtf8(detail.name.c_str()); + gpgItem->setText(COLUMN_NAME, name); + + sslIds.clear(); + rsPeers->getAssociatedSSLIds(*gpgIt, sslIds); + + int state = RS_STATUS_OFFLINE; + for (statusIt = statusInfo.begin(); statusIt != statusInfo.end() ; statusIt++) { + if (std::find(sslIds.begin(), sslIds.end(), statusIt->id) != sslIds.end()) { + if (statusIt->status != RS_STATUS_OFFLINE) { + state = RS_STATUS_ONLINE; + break; + } + } + } + + if (state != (int) RS_STATUS_OFFLINE) { + gpgItem->setTextColor(COLUMN_NAME, textColorOnline()); + } + + 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()); + gpgItem->setCheckState(0, Qt::Unchecked); + } + + // add to the list + if (groupItem) { + groupItem->addChild(gpgItem); + } else { + ui->friendList->addTopLevelItem(gpgItem); + } + + gpgItem->setExpanded(true); + + if (showTypes & SHOW_SSL) { + // iterate through associated ssl ids + for (sslIt = sslIds.begin(); sslIt != sslIds.end(); sslIt++) { + RsPeerDetails detail; + if (!rsPeers->getPeerDetails(*sslIt, detail)) { + continue; /* BAD */ + } + + // make a widget per friend + QTreeWidgetItem *item = new RSTreeWidgetItem(compareRole, IDTYPE_SSL); + + initSslItem(item, detail, statusInfo, textColorOnline()); + + if (listModus == MODUS_CHECK) { + item->setFlags(Qt::ItemIsUserCheckable | item->flags()); + item->setCheckState(0, Qt::Unchecked); + } + + // add to the list + gpgItem->addChild(item); + + if (std::find(sslIdsSelected.begin(), sslIdsSelected.end(), detail.id) != sslIdsSelected.end()) { + setSelected(listModus, item, true); + } + } + } + + if (std::find(gpgIdsSelected.begin(), gpgIdsSelected.end(), detail.gpg_id) != gpgIdsSelected.end()) { + setSelected(listModus, gpgItem, true); + } } + } else { + // iterate through ssl ids + for (sslIt = sslIds.begin(); sslIt != sslIds.end(); sslIt++) { + RsPeerDetails detail; + if (!rsPeers->getPeerDetails(*sslIt, detail)) { + continue; /* BAD */ + } - if (state != (int) RS_STATUS_OFFLINE) { - item->setTextColor(COLUMN_NAME, textColorOnline()); - } + 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 + if (std::find(filledIds.begin(), filledIds.end(), *sslIt) != filledIds.end()) { + continue; + } + } - item->setIcon(COLUMN_NAME, QIcon(StatusDefs::imageUser(state))); - item->setData(COLUMN_DATA, ROLE_ID, QString::fromStdString(detail.id)); - item->setData(COLUMN_DATA, ROLE_SORT, "2 " + name); + // add equal too, its no problem + filledIds.push_back(detail.id); - if (listModus == MODUS_CHECK) { - item->setFlags(Qt::ItemIsUserCheckable | item->flags()); - item->setCheckState(0, Qt::Unchecked); - } + // make a widget per friend + QTreeWidgetItem *item = new RSTreeWidgetItem(compareRole, IDTYPE_SSL); - // add to the list - if (groupItem) { - groupItem->addChild(item); - } else { - ui->friendList->addTopLevelItem(item); - } + initSslItem(item, detail, statusInfo, textColorOnline()); - if (std::find(sslIdsSelected.begin(), sslIdsSelected.end(), detail.id) != sslIdsSelected.end()) { - setSelected(listModus, item, true); + if (listModus == MODUS_CHECK) { + item->setFlags(Qt::ItemIsUserCheckable | item->flags()); + item->setCheckState(0, Qt::Unchecked); + } + + // add to the list + if (groupItem) { + groupItem->addChild(item); + } else { + ui->friendList->addTopLevelItem(item); + } + + if (std::find(sslIdsSelected.begin(), sslIdsSelected.end(), detail.id) != sslIdsSelected.end()) { + setSelected(listModus, item, true); + } } } @@ -311,21 +432,79 @@ void FriendSelectionWidget::fillList() void FriendSelectionWidget::peerStatusChanged(const QString& peerId, int status) { + QString gpgId; + int gpgStatus = RS_STATUS_OFFLINE; + + if (showTypes & SHOW_GPG) { + /* need gpg id and online state */ + RsPeerDetails detail; + if (rsPeers->getPeerDetails(peerId.toStdString(), detail)) { + gpgId = QString::fromStdString(detail.gpg_id); + + if (status == (int) RS_STATUS_OFFLINE) { + /* try other locations */ + std::list sslIds; + rsPeers->getAssociatedSSLIds(detail.gpg_id, sslIds); + + std::list statusInfo; + std::list::iterator statusIt; + rsStatus->getStatusList(statusInfo); + + for (statusIt = statusInfo.begin(); statusIt != statusInfo.end() ; statusIt++) { + 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; + } + } + } QTreeWidgetItemIterator itemIterator(ui->friendList); QTreeWidgetItem *item; while ((item = *itemIterator) != NULL) { itemIterator++; - if (item->data(COLUMN_DATA, ROLE_ID).toString() == peerId) { - QColor color; - if (status != (int) RS_STATUS_OFFLINE) { - color = textColorOnline(); - } + switch ((IdType) item->type()) { + 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(status))); - //break; no break, friend can assigned to groups more than one + item->setTextColor(COLUMN_NAME, color); + item->setIcon(COLUMN_NAME, QIcon(StatusDefs::imageUser(gpgStatus))); + } + } + 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); + } + + item->setTextColor(COLUMN_NAME, color); + item->setIcon(COLUMN_NAME, QIcon(StatusDefs::imageUser(status))); + } + } + break; } + // friend can assigned to groups more than one } } @@ -345,10 +524,6 @@ void FriendSelectionWidget::itemDoubleClicked(QTreeWidgetItem *item, int /*colum void FriendSelectionWidget::itemChanged(QTreeWidgetItem *item, int column) { - if (inItemChanged) { - return; - } - if (listModus != MODUS_CHECK) { return; } @@ -357,46 +532,87 @@ void FriendSelectionWidget::itemChanged(QTreeWidgetItem *item, int column) return; } - if (!showGroups) { - return; - } - - inItemChanged = true; - switch ((IdType) item->type()) { case IDTYPE_NONE: break; case IDTYPE_GROUP: { + if (inGroupItemChanged || inGpgItemChanged || inSslItemChanged) { + break; + } + + inGroupItemChanged = true; + bool selected = isSelected(listModus, item); int childCount = item->childCount(); for (int i = 0; i < childCount; ++i) { setSelected(listModus, item->child(i), selected); } + + inGroupItemChanged = false; + } + break; + case IDTYPE_GPG: + { + if (inGpgItemChanged) { + break; + } + + inGpgItemChanged = true; + + if (!inSslItemChanged) { + bool selected = isSelected(listModus, item); + + int childCount = item->childCount(); + for (int i = 0; i < childCount; ++i) { + setSelected(listModus, item->child(i), selected); + } + } + + if (!inGroupItemChanged) { + 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))) { + foundUnselected = true; + break; + } + } + setSelected(listModus, itemParent, !foundUnselected); + } + } + + inGpgItemChanged = false; } break; case IDTYPE_SSL: { - QTreeWidgetItem *itemParent = item->parent(); - if (itemParent == NULL) { + if (inGroupItemChanged || inGpgItemChanged || inSslItemChanged) { break; } - int childCount = itemParent->childCount(); - bool foundUnselected = false; - for (int index = 0; index < childCount; ++index) { - if (!isSelected(listModus, itemParent->child(index))) { - foundUnselected = true; - break; + inSslItemChanged = 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))) { + foundUnselected = true; + break; + } } + setSelected(listModus, itemParent, !foundUnselected); } - setSelected(listModus, itemParent, !foundUnselected); + + inSslItemChanged = false; } break; } - - inItemChanged = false; } void FriendSelectionWidget::filterItems(const QString& text) @@ -470,15 +686,35 @@ void FriendSelectionWidget::selectedIds(IdType idType, std::list &i } } break; + case IDTYPE_GPG: + if (idType == IDTYPE_GPG) { + if (isSelected(listModus, item)) { + id = item->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); + } else { + if (!onlyDirectSelected) { + QTreeWidgetItem *itemParent = item; + while ((itemParent = itemParent->parent()) != NULL) { + if (isSelected(listModus, itemParent)) { + id = item->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); + break; + } + } + } + } + } + break; case IDTYPE_SSL: if (idType == IDTYPE_SSL) { if (isSelected(listModus, item)) { id = item->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); } else { if (!onlyDirectSelected) { - QTreeWidgetItem *itemParent = item->parent(); - if (itemParent && isSelected(listModus, itemParent)) { - id = item->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); + QTreeWidgetItem *itemParent = item; + while ((itemParent = itemParent->parent()) != NULL) { + if (isSelected(listModus, itemParent)) { + id = item->data(COLUMN_DATA, ROLE_ID).toString().toStdString(); + break; + } } } } @@ -505,6 +741,7 @@ void FriendSelectionWidget::setSelectedIds(IdType idType, const std::list &sslIds, bool onlyDirectSelected) { selectedIds(IDTYPE_SSL, sslIds, onlyDirectSelected); } + void selectedGpgIds(std::list &gpgIds, bool onlyDirectSelected) { selectedIds(IDTYPE_GPG, gpgIds, onlyDirectSelected); } void selectedGroupIds(std::list &groupIds) { selectedIds(IDTYPE_GROUP, groupIds, true); } void setSelectedSslIds(const std::list &sslIds, bool add) { setSelectedIds(IDTYPE_SSL, sslIds, add); } + void setSelectedGpgIds(const std::list &gpgIds, bool add) { setSelectedIds(IDTYPE_GPG, gpgIds, add); } void setSelectedGroupIds(const std::list &groupIds, bool add) { setSelectedIds(IDTYPE_GROUP, groupIds, add); } QColor textColorOnline() const { return mTextColorOnline; } @@ -99,8 +110,10 @@ private: bool started; RSTreeWidgetItemCompareRole *compareRole; Modus listModus; - bool showGroups; - bool inItemChanged; + ShowTypes showTypes; + bool inGroupItemChanged; + bool inGpgItemChanged; + bool inSslItemChanged; /* Color definitions (for standard see qss.default) */ QColor mTextColorOnline; @@ -108,4 +121,6 @@ private: Ui::FriendSelectionWidget *ui; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(FriendSelectionWidget::ShowTypes) + #endif // FRIENDSELECTIONWIDGET_H diff --git a/retroshare-gui/src/gui/forums/CreateForum.cpp b/retroshare-gui/src/gui/forums/CreateForum.cpp index c7ddc4a1c..08a128fb1 100644 --- a/retroshare-gui/src/gui/forums/CreateForum.cpp +++ b/retroshare-gui/src/gui/forums/CreateForum.cpp @@ -55,6 +55,7 @@ CreateForum::CreateForum() /* initialize key share list */ ui.keyShareList->setHeaderText(tr("Contacts:")); ui.keyShareList->setModus(FriendSelectionWidget::MODUS_CHECK); + ui.keyShareList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL); ui.keyShareList->start(); newForum(); diff --git a/retroshare-gui/src/gui/groups/CreateGroup.cpp b/retroshare-gui/src/gui/groups/CreateGroup.cpp index 995d74ba3..5004f263e 100644 --- a/retroshare-gui/src/gui/groups/CreateGroup.cpp +++ b/retroshare-gui/src/gui/groups/CreateGroup.cpp @@ -23,81 +23,128 @@ #include -#include "util/misc.h" - #include "CreateGroup.h" #include "gui/common/GroupDefs.h" +#include "gui/settings/rsharesettings.h" +#include "util/misc.h" /** Default constructor */ -CreateGroup::CreateGroup(const std::string groupId, QWidget *parent) +CreateGroup::CreateGroup(const std::string &groupId, QWidget *parent) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint) { - /* Invoke Qt Designer generated QObject setup routine */ - ui.setupUi(this); + /* Invoke Qt Designer generated QObject setup routine */ + ui.setupUi(this); - ui.headerFrame->setHeaderImage(QPixmap(":/images/user/add_group256.png")); + Settings->loadWidgetInformation(this); - m_groupId = groupId; + mIsStandard = false; - if (m_groupId.empty() == false) { - /* edit exisiting group */ - RsGroupInfo groupInfo; - if (rsPeers->getGroupInfo(m_groupId, groupInfo)) { - ui.groupname->setText(misc::removeNewLine(groupInfo.name)); + ui.headerFrame->setHeaderImage(QPixmap(":/images/user/add_group256.png")); - setWindowTitle(tr("Edit Group")); - ui.headerFrame->setHeaderText(tr("Edit Group")); - } else { - /* Group not found, create new */ - m_groupId.clear(); - } - } else { - ui.headerFrame->setHeaderText(tr("Create a Group")); - } + mGroupId = groupId; - std::list groupInfoList; - rsPeers->getGroupInfoList(groupInfoList); + /* Initialize friends list */ + ui.friendList->setHeaderText(tr("Friends")); + ui.friendList->setModus(FriendSelectionWidget::MODUS_CHECK); + ui.friendList->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_GPG); + ui.friendList->start(); - std::list::iterator groupIt; - for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); groupIt++) { - if (m_groupId.empty() || groupIt->id != m_groupId) { - usedGroupNames.append(GroupDefs::name(*groupIt)); - } - } + if (mGroupId.empty() == false) { + /* edit exisiting group */ + RsGroupInfo groupInfo; + if (rsPeers->getGroupInfo(mGroupId, groupInfo)) { + mIsStandard = (groupInfo.flag & RS_GROUP_FLAG_STANDARD); - on_groupname_textChanged(ui.groupname->text()); + if (mIsStandard) { + ui.groupName->setText(GroupDefs::name(groupInfo)); + } else { + ui.groupName->setText(misc::removeNewLine(groupInfo.name)); + } + + setWindowTitle(tr("Edit Group")); + ui.headerFrame->setHeaderText(tr("Edit Group")); + + ui.groupName->setDisabled(mIsStandard); + + ui.friendList->setSelectedGpgIds(groupInfo.peerIds, false); + } else { + /* Group not found, create new */ + mGroupId.clear(); + } + } else { + ui.headerFrame->setHeaderText(tr("Create a Group")); + } + + std::list groupInfoList; + rsPeers->getGroupInfoList(groupInfoList); + + std::list::iterator groupIt; + for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); groupIt++) { + if (mGroupId.empty() || groupIt->id != mGroupId) { + mUsedGroupNames.append(GroupDefs::name(*groupIt)); + } + } + + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(changeGroup())); + connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(ui.groupName, SIGNAL(textChanged(QString)), this, SLOT(groupNameChanged(QString))); + + groupNameChanged(ui.groupName->text()); } /** Destructor. */ CreateGroup::~CreateGroup() { + Settings->saveWidgetInformation(this); } -void CreateGroup::on_groupname_textChanged(QString text) +void CreateGroup::groupNameChanged(QString text) { - if (text.isEmpty() || usedGroupNames.contains(misc::removeNewLine(text))) { - ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); - } else { - ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); - } + if (text.isEmpty() || mUsedGroupNames.contains(misc::removeNewLine(text))) { + ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + } else { + ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + } } -void CreateGroup::on_buttonBox_accepted() +void CreateGroup::changeGroup() { - RsGroupInfo groupInfo; + RsGroupInfo groupInfo; - if (m_groupId.empty()) { - // add new group - groupInfo.name = misc::removeNewLine(ui.groupname->text()).toUtf8().constData(); - if (rsPeers->addGroup(groupInfo)) { - close(); - } - } else { - if (rsPeers->getGroupInfo(m_groupId, groupInfo) == true) { - groupInfo.name = misc::removeNewLine(ui.groupname->text()).toUtf8().constData(); - if (rsPeers->editGroup(m_groupId, groupInfo)) { - close(); - } - } - } + if (mGroupId.empty()) { + // add new group + groupInfo.name = misc::removeNewLine(ui.groupName->text()).toUtf8().constData(); + if (!rsPeers->addGroup(groupInfo)) { + return; + } + } else { + if (rsPeers->getGroupInfo(mGroupId, groupInfo) == true) { + if (!mIsStandard) { + groupInfo.name = misc::removeNewLine(ui.groupName->text()).toUtf8().constData(); + if (!rsPeers->editGroup(mGroupId, groupInfo)) { + return; + } + } + } + } + + std::list gpgIds; + ui.friendList->selectedGpgIds(gpgIds, true); + + std::list::iterator it; + for (it = groupInfo.peerIds.begin(); it != groupInfo.peerIds.end(); ++it) { + std::list::iterator gpgIt = std::find(gpgIds.begin(), gpgIds.end(), *it); + if (gpgIt == gpgIds.end()) { + rsPeers->assignPeerToGroup(groupInfo.id, *it, false); + continue; + } + + gpgIds.erase(gpgIt); + } + + for (it = gpgIds.begin(); it != gpgIds.end(); ++it) { + rsPeers->assignPeerToGroup(groupInfo.id, *it, true); + } + + accept(); } diff --git a/retroshare-gui/src/gui/groups/CreateGroup.h b/retroshare-gui/src/gui/groups/CreateGroup.h index 69eb67166..b8177c611 100644 --- a/retroshare-gui/src/gui/groups/CreateGroup.h +++ b/retroshare-gui/src/gui/groups/CreateGroup.h @@ -19,39 +19,32 @@ * Boston, MA 02110-1301, USA. ****************************************************************/ - #ifndef _CREATEGROUP_H #define _CREATEGROUP_H #include "ui_CreateGroup.h" - class CreateGroup : public QDialog { - Q_OBJECT + Q_OBJECT public: - /** Default constructor */ - CreateGroup(const std::string groupId, QWidget *parent = 0); - /** Default destructor */ - ~CreateGroup(); - -public slots: + /** Default constructor */ + CreateGroup(const std::string &groupId, QWidget *parent = 0); + /** Default destructor */ + ~CreateGroup(); private slots: + void changeGroup(); + void groupNameChanged(QString); private: - std::string m_groupId; + std::string mGroupId; + QStringList mUsedGroupNames; + bool mIsStandard; - QStringList usedGroupNames; - - /** Qt Designer generated object */ - Ui::CreateGroup ui; - -private slots: - void on_buttonBox_accepted(); - void on_groupname_textChanged(QString ); + /** Qt Designer generated object */ + Ui::CreateGroup ui; }; #endif - diff --git a/retroshare-gui/src/gui/groups/CreateGroup.ui b/retroshare-gui/src/gui/groups/CreateGroup.ui index c5ea1ce73..3eb4bc2fd 100644 --- a/retroshare-gui/src/gui/groups/CreateGroup.ui +++ b/retroshare-gui/src/gui/groups/CreateGroup.ui @@ -7,7 +7,7 @@ 0 0 386 - 158 + 298 @@ -27,77 +27,55 @@ - + QFrame::StyledPanel QFrame::Raised - - - - - 0 - + + + 6 - - + + 0 + + + Group Name - - + + Enter a name for your group - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 24 - 20 - - - - - - - - Qt::Vertical + + + + + 0 + 0 + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - Qt::Vertical - - - - 208 - 21 - - - - @@ -110,24 +88,13 @@
gui/common/HeaderFrame.h
1 + + FriendSelectionWidget + QWidget +
gui/common/FriendSelectionWidget.h
+ 1 +
- - - buttonBox - rejected() - CreateGroup - reject() - - - 338 - 116 - - - 192 - 78 - - - - + diff --git a/retroshare-gui/src/gui/msgs/MessageComposer.cpp b/retroshare-gui/src/gui/msgs/MessageComposer.cpp index 3c4408f5d..6e991082f 100644 --- a/retroshare-gui/src/gui/msgs/MessageComposer.cpp +++ b/retroshare-gui/src/gui/msgs/MessageComposer.cpp @@ -209,6 +209,7 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WFlags flags) /* initialize friends list */ ui.friendSelectionWidget->setHeaderText(tr("Send To:")); ui.friendSelectionWidget->setModus(FriendSelectionWidget::MODUS_MULTI); + ui.friendSelectionWidget->setShowType(FriendSelectionWidget::SHOW_GROUP | FriendSelectionWidget::SHOW_SSL); ui.friendSelectionWidget->start(); QActionGroup *grp = new QActionGroup(this); diff --git a/retroshare-gui/src/lang/retroshare_en.ts b/retroshare-gui/src/lang/retroshare_en.ts index 605d6d5e8..65fc019e2 100644 --- a/retroshare-gui/src/lang/retroshare_en.ts +++ b/retroshare-gui/src/lang/retroshare_en.ts @@ -2787,6 +2787,10 @@ p, li { white-space: pre-wrap; } Edit Group + + Friends + + CreateLobbyDialog