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-11-09 19:57:05 +00:00
|
|
|
#include "util/misc.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"
|
2010-09-21 16:11:19 +00:00
|
|
|
|
|
|
|
/** Default constructor */
|
2012-11-06 23:26:47 +00:00
|
|
|
CreateGroup::CreateGroup(const std::string groupId, QWidget *parent)
|
|
|
|
: QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
|
2010-09-21 16:11:19 +00:00
|
|
|
{
|
2010-09-22 22:37:57 +00:00
|
|
|
/* Invoke Qt Designer generated QObject setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
2012-08-24 10:49:08 +00:00
|
|
|
ui.headerFrame->setHeaderImage(QPixmap(":/images/user/add_group256.png"));
|
|
|
|
|
2010-09-22 22:37:57 +00:00
|
|
|
m_groupId = groupId;
|
|
|
|
|
|
|
|
if (m_groupId.empty() == false) {
|
|
|
|
/* edit exisiting group */
|
|
|
|
RsGroupInfo groupInfo;
|
|
|
|
if (rsPeers->getGroupInfo(m_groupId, groupInfo)) {
|
2010-11-09 19:57:05 +00:00
|
|
|
ui.groupname->setText(misc::removeNewLine(groupInfo.name));
|
2010-09-23 18:49:52 +00:00
|
|
|
|
|
|
|
setWindowTitle(tr("Edit Group"));
|
2012-08-24 10:49:08 +00:00
|
|
|
ui.headerFrame->setHeaderText(tr("Edit Group"));
|
2010-09-22 22:37:57 +00:00
|
|
|
} else {
|
|
|
|
/* Group not found, create new */
|
|
|
|
m_groupId.clear();
|
|
|
|
}
|
2012-08-24 10:49:08 +00:00
|
|
|
} else {
|
|
|
|
ui.headerFrame->setHeaderText(tr("Create a Group"));
|
2010-09-22 22:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::list<RsGroupInfo> groupInfoList;
|
|
|
|
rsPeers->getGroupInfoList(groupInfoList);
|
|
|
|
|
|
|
|
std::list<RsGroupInfo>::iterator groupIt;
|
|
|
|
for (groupIt = groupInfoList.begin(); groupIt != groupInfoList.end(); groupIt++) {
|
2010-09-23 18:49:52 +00:00
|
|
|
if (m_groupId.empty() || groupIt->id != m_groupId) {
|
|
|
|
usedGroupNames.append(GroupDefs::name(*groupIt));
|
|
|
|
}
|
2010-09-22 22:37:57 +00:00
|
|
|
}
|
2010-09-21 16:11:19 +00:00
|
|
|
|
2010-09-22 22:37:57 +00:00
|
|
|
on_groupname_textChanged(ui.groupname->text());
|
2010-09-21 16:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Destructor. */
|
|
|
|
CreateGroup::~CreateGroup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-22 22:37:57 +00:00
|
|
|
void CreateGroup::on_groupname_textChanged(QString text)
|
|
|
|
{
|
2010-11-09 19:57:05 +00:00
|
|
|
if (text.isEmpty() || usedGroupNames.contains(misc::removeNewLine(text))) {
|
2010-09-22 22:37:57 +00:00
|
|
|
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreateGroup::on_buttonBox_accepted()
|
|
|
|
{
|
|
|
|
RsGroupInfo groupInfo;
|
|
|
|
|
|
|
|
if (m_groupId.empty()) {
|
|
|
|
// add new group
|
2010-11-09 19:57:05 +00:00
|
|
|
groupInfo.name = misc::removeNewLine(ui.groupname->text()).toUtf8().constData();
|
2010-09-22 22:37:57 +00:00
|
|
|
if (rsPeers->addGroup(groupInfo)) {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (rsPeers->getGroupInfo(m_groupId, groupInfo) == true) {
|
2010-11-09 19:57:05 +00:00
|
|
|
groupInfo.name = misc::removeNewLine(ui.groupname->text()).toUtf8().constData();
|
2010-09-22 22:37:57 +00:00
|
|
|
if (rsPeers->editGroup(m_groupId, groupInfo)) {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|