2010-09-21 16:11:19 +00:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 - 2010 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.
|
|
|
|
****************************************************************/
|
|
|
|
|
2010-09-22 22:37:57 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
#include <retroshare/rspeers.h>
|
|
|
|
|
2010-09-21 16:11:19 +00:00
|
|
|
#include "CreateGroup.h"
|
2010-09-22 22:37:57 +00:00
|
|
|
#include "gui/common/GroupDefs.h"
|
2012-11-24 14:48:31 +00:00
|
|
|
#include "gui/settings/rsharesettings.h"
|
|
|
|
#include "util/misc.h"
|
2010-09-21 16:11:19 +00:00
|
|
|
|
2012-11-25 10:58:53 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2010-09-21 16:11:19 +00:00
|
|
|
/** Default constructor */
|
2012-11-24 14:48:31 +00:00
|
|
|
CreateGroup::CreateGroup(const std::string &groupId, QWidget *parent)
|
2012-11-06 23:26:47 +00:00
|
|
|
: QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
|
2010-09-21 16:11:19 +00:00
|
|
|
{
|
2012-11-24 14:48:31 +00:00
|
|
|
/* Invoke Qt Designer generated QObject setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
Settings->loadWidgetInformation(this);
|
|
|
|
|
|
|
|
mIsStandard = false;
|
|
|
|
|
|
|
|
ui.headerFrame->setHeaderImage(QPixmap(":/images/user/add_group256.png"));
|
|
|
|
|
|
|
|
mGroupId = groupId;
|
|
|
|
|
|
|
|
/* 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();
|
|
|
|
|
|
|
|
if (mGroupId.empty() == false) {
|
|
|
|
/* edit exisiting group */
|
|
|
|
RsGroupInfo groupInfo;
|
|
|
|
if (rsPeers->getGroupInfo(mGroupId, groupInfo)) {
|
|
|
|
mIsStandard = (groupInfo.flag & RS_GROUP_FLAG_STANDARD);
|
|
|
|
|
|
|
|
if (mIsStandard) {
|
|
|
|
ui.groupName->setText(GroupDefs::name(groupInfo));
|
|
|
|
} else {
|
|
|
|
ui.groupName->setText(misc::removeNewLine(groupInfo.name));
|
|
|
|
}
|
|
|
|
|
|
|
|
setWindowTitle(tr("Edit Group"));
|
2013-08-21 23:53:39 +00:00
|
|
|
ui.headerFrame->setHeaderImage(QPixmap(":/images/user/edit_group64.png"));
|
2012-11-24 14:48:31 +00:00
|
|
|
ui.headerFrame->setHeaderText(tr("Edit Group"));
|
|
|
|
|
|
|
|
ui.groupName->setDisabled(mIsStandard);
|
|
|
|
|
2014-03-17 20:56:06 +00:00
|
|
|
ui.friendList->setSelectedIds<RsPgpId,FriendSelectionWidget::IDTYPE_GPG>(groupInfo.peerIds, false);
|
2012-11-24 14:48:31 +00:00
|
|
|
} else {
|
|
|
|
/* Group not found, create new */
|
|
|
|
mGroupId.clear();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ui.headerFrame->setHeaderText(tr("Create a Group"));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list<RsGroupInfo> groupInfoList;
|
|
|
|
rsPeers->getGroupInfoList(groupInfoList);
|
|
|
|
|
|
|
|
std::list<RsGroupInfo>::iterator groupIt;
|
2014-10-21 22:33:02 +00:00
|
|
|
for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); ++groupIt) {
|
2012-11-24 14:48:31 +00:00
|
|
|
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());
|
2010-09-21 16:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Destructor. */
|
|
|
|
CreateGroup::~CreateGroup()
|
|
|
|
{
|
2012-11-24 14:48:31 +00:00
|
|
|
Settings->saveWidgetInformation(this);
|
2010-09-21 16:11:19 +00:00
|
|
|
}
|
|
|
|
|
2012-11-24 14:48:31 +00:00
|
|
|
void CreateGroup::groupNameChanged(QString text)
|
2010-09-22 22:37:57 +00:00
|
|
|
{
|
2012-11-24 14:48:31 +00:00
|
|
|
if (text.isEmpty() || mUsedGroupNames.contains(misc::removeNewLine(text))) {
|
|
|
|
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
|
|
|
}
|
2010-09-22 22:37:57 +00:00
|
|
|
}
|
|
|
|
|
2012-11-24 14:48:31 +00:00
|
|
|
void CreateGroup::changeGroup()
|
2010-09-22 22:37:57 +00:00
|
|
|
{
|
2012-11-24 14:48:31 +00:00
|
|
|
RsGroupInfo groupInfo;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-17 21:36:22 +00:00
|
|
|
std::set<RsPgpId> gpgIds;
|
2014-03-17 20:56:06 +00:00
|
|
|
ui.friendList->selectedIds<RsPgpId,FriendSelectionWidget::IDTYPE_GPG>(gpgIds, true);
|
2012-11-24 14:48:31 +00:00
|
|
|
|
2015-04-17 21:36:22 +00:00
|
|
|
std::set<RsPgpId>::iterator it;
|
2012-11-24 14:48:31 +00:00
|
|
|
for (it = groupInfo.peerIds.begin(); it != groupInfo.peerIds.end(); ++it) {
|
2015-04-17 21:36:22 +00:00
|
|
|
std::set<RsPgpId>::iterator gpgIt = std::find(gpgIds.begin(), gpgIds.end(), *it);
|
2012-11-24 14:48:31 +00:00
|
|
|
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();
|
2010-09-22 22:37:57 +00:00
|
|
|
}
|