mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-11 07:29:38 -05:00
added a GroupChooser class to choose groups of friend nodes
This commit is contained in:
parent
0125f91b2d
commit
d089e2ef1a
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,5 +1,8 @@
|
||||
/RetroShare.pro.user
|
||||
*.o
|
||||
*.sw?
|
||||
*.so
|
||||
*.so.*
|
||||
moc_*.cpp
|
||||
qrc_*.cpp
|
||||
ui_*.h
|
||||
|
111
retroshare-gui/src/gui/common/GroupChooser.cpp
Normal file
111
retroshare-gui/src/gui/common/GroupChooser.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Retroshare Gxs Support
|
||||
*
|
||||
* Copyright 2012-2013 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "GroupChooser.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#include <retroshare/rspeers.h>
|
||||
|
||||
/** Constructor */
|
||||
GroupChooser::GroupChooser(QWidget *parent)
|
||||
: QComboBox(parent), mFlags(0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void GroupChooser::loadGroups(uint32_t chooserFlags, const RsNodeGroupId& defaultId)
|
||||
{
|
||||
mFlags = chooserFlags;
|
||||
mDefaultGroupId = defaultId;
|
||||
|
||||
loadGroups();
|
||||
}
|
||||
|
||||
|
||||
static bool MakeNodeGroupDesc(const RsGroupInfo& info, QString &desc)
|
||||
{
|
||||
desc.clear();
|
||||
desc = QString::fromUtf8(info.name.c_str());
|
||||
|
||||
desc += " (Node group) [";
|
||||
desc += QString::fromStdString(info.id.toStdString().substr(0,5));
|
||||
desc += "...]";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void GroupChooser::loadGroups()
|
||||
{
|
||||
std::list<RsGroupInfo> ids;
|
||||
|
||||
rsPeers->getGroupInfoList(ids);
|
||||
|
||||
if (ids.empty())
|
||||
{
|
||||
std::cerr << "GroupChooser::loadGroups() ERROR no ids";
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
int def = -1;
|
||||
for( std::list<RsGroupInfo>::iterator it = ids.begin(); it != ids.end(); ++it, ++i)
|
||||
{
|
||||
/* add to Chooser */
|
||||
QString str;
|
||||
if (!MakeNodeGroupDesc(*it, str))
|
||||
{
|
||||
std::cerr << "GroupChooser::loadGroups() ERROR Desc for Id: " << it->id;
|
||||
std::cerr << std::endl;
|
||||
continue;
|
||||
}
|
||||
QString id = QString::fromStdString(it->id.toStdString());
|
||||
|
||||
addItem(str, id);
|
||||
|
||||
if (mDefaultGroupId == it->id)
|
||||
def = i;
|
||||
}
|
||||
|
||||
if (def >= 0)
|
||||
{
|
||||
setCurrentIndex(def);
|
||||
}
|
||||
}
|
||||
|
||||
bool GroupChooser::getChosenGroup(RsNodeGroupId& id)
|
||||
{
|
||||
if (count() < 1)
|
||||
return false;
|
||||
|
||||
int idx = currentIndex();
|
||||
|
||||
QVariant var = itemData(idx);
|
||||
id = RsNodeGroupId(var.toString().toStdString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
44
retroshare-gui/src/gui/common/GroupChooser.h
Normal file
44
retroshare-gui/src/gui/common/GroupChooser.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Retroshare Gxs Support
|
||||
*
|
||||
* Copyright 2012-2013 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2.1 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QComboBox>
|
||||
#include <retroshare/rsgxscircles.h>
|
||||
|
||||
class GroupChooser : public QComboBox
|
||||
{
|
||||
public:
|
||||
GroupChooser(QWidget *parent = NULL);
|
||||
|
||||
void loadGroups(uint32_t chooserFlags, const RsNodeGroupId& defaultId);
|
||||
bool getChosenGroup(RsNodeGroupId& id);
|
||||
|
||||
private:
|
||||
void loadGroups();
|
||||
uint32_t mFlags;
|
||||
|
||||
RsNodeGroupId mDefaultGroupId;
|
||||
};
|
||||
|
@ -125,7 +125,7 @@ void GxsGroupDialog::init()
|
||||
|
||||
ui.idChooser->loadIds(0,RsGxsId());
|
||||
ui.circleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, RsGxsCircleId());
|
||||
ui.localComboBox->loadCircles(GXS_CIRCLE_CHOOSER_PERSONAL, RsGxsCircleId());
|
||||
ui.localComboBox->loadGroups(0, RsNodeGroupId());
|
||||
|
||||
ui.groupDesc->setPlaceholderText(tr("Set a descriptive description here"));
|
||||
|
||||
@ -444,19 +444,21 @@ void GxsGroupDialog::updateFromExistingMeta(const QString &description)
|
||||
case GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY:
|
||||
ui.typeLocal->setChecked(true);
|
||||
distribution_string = tr("Your friends only") ;
|
||||
ui.localComboBox->loadCircles(GXS_CIRCLE_CHOOSER_PERSONAL, mGrpMeta.mInternalCircle);
|
||||
ui.distributionCircleComboBox->setVisible(true) ;
|
||||
ui.distributionCircleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_PERSONAL, mGrpMeta.mInternalCircle);
|
||||
break;
|
||||
ui.localComboBox->loadGroups(0, RsNodeGroupId(mGrpMeta.mInternalCircle));
|
||||
ui.distributionCircleComboBox->setVisible(false) ;
|
||||
ui.localComboBox->setVisible(true) ;
|
||||
break;
|
||||
case GXS_CIRCLE_TYPE_PUBLIC:
|
||||
ui.typePublic->setChecked(true);
|
||||
distribution_string = tr("Public") ;
|
||||
ui.distributionCircleComboBox->setVisible(false) ;
|
||||
break;
|
||||
ui.localComboBox->setVisible(false) ;
|
||||
break;
|
||||
case GXS_CIRCLE_TYPE_EXTERNAL:
|
||||
ui.typeGroup->setChecked(true);
|
||||
distribution_string = tr("Restricted to circle:") ;
|
||||
ui.distributionCircleComboBox->setVisible(true) ;
|
||||
ui.localComboBox->setVisible(false) ;
|
||||
ui.distributionCircleComboBox->setVisible(true) ;
|
||||
ui.distributionCircleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, mGrpMeta.mCircleId);
|
||||
ui.circleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, mGrpMeta.mCircleId);
|
||||
break;
|
||||
@ -720,41 +722,42 @@ void GxsGroupDialog::updateCircleOptions()
|
||||
|
||||
bool GxsGroupDialog::setCircleParameters(RsGroupMetaData &meta)
|
||||
{
|
||||
meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
|
||||
meta.mCircleId.clear();
|
||||
meta.mOriginator.clear();
|
||||
meta.mInternalCircle.clear();
|
||||
meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
|
||||
meta.mCircleId.clear();
|
||||
meta.mOriginator.clear();
|
||||
meta.mInternalCircle.clear();
|
||||
|
||||
if (ui.typePublic->isChecked())
|
||||
{
|
||||
meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
|
||||
meta.mCircleId.clear();
|
||||
}
|
||||
else if (ui.typeGroup->isChecked())
|
||||
{
|
||||
meta.mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
|
||||
if (!ui.circleComboBox->getChosenCircle(meta.mCircleId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (ui.typeLocal->isChecked())
|
||||
{
|
||||
meta.mCircleType = GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY;
|
||||
meta.mCircleId.clear();
|
||||
meta.mOriginator.clear();
|
||||
meta.mInternalCircle.clear() ;
|
||||
|
||||
if (!ui.localComboBox->getChosenCircle(meta.mInternalCircle))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
if (ui.typePublic->isChecked())
|
||||
{
|
||||
meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
|
||||
meta.mCircleId.clear();
|
||||
}
|
||||
else if (ui.typeGroup->isChecked())
|
||||
{
|
||||
meta.mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
|
||||
if (!ui.circleComboBox->getChosenCircle(meta.mCircleId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (ui.typeLocal->isChecked())
|
||||
{
|
||||
meta.mCircleType = GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY;
|
||||
meta.mCircleId.clear();
|
||||
meta.mOriginator.clear();
|
||||
meta.mInternalCircle.clear() ;
|
||||
|
||||
RsNodeGroupId ngi ;
|
||||
|
||||
if (!ui.localComboBox->getChosenGroup(ngi))
|
||||
return false;
|
||||
|
||||
meta.mInternalCircle = RsGxsCircleId(ngi) ;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GxsGroupDialog::cancelDialog()
|
||||
|
@ -6,32 +6,23 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>828</width>
|
||||
<height>612</height>
|
||||
<width>860</width>
|
||||
<height>775</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Create New</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="horizontalSpacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="HeaderFrame" name="headerFrame"/>
|
||||
</item>
|
||||
@ -57,16 +48,7 @@
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<property name="margin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<item>
|
||||
@ -130,16 +112,7 @@
|
||||
<property name="spacing">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<property name="margin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item>
|
||||
@ -261,16 +234,7 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="dockWidgetContents">
|
||||
<layout class="QGridLayout" name="_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
@ -408,7 +372,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="GxsCircleChooser" name="localComboBox"/>
|
||||
<widget class="GroupChooser" name="localComboBox"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
@ -874,6 +838,11 @@
|
||||
<extends>QTextEdit</extends>
|
||||
<header location="global">gui/common/MimeTextEdit.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>GroupChooser</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>gui/common/GroupChooser.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../images.qrc"/>
|
||||
|
@ -466,6 +466,7 @@ HEADERS += rshare.h \
|
||||
gui/common/AvatarDefs.h \
|
||||
gui/common/GroupFlagsWidget.h \
|
||||
gui/common/GroupSelectionBox.h \
|
||||
gui/common/GroupChooser.h \
|
||||
gui/common/StatusDefs.h \
|
||||
gui/common/TagDefs.h \
|
||||
gui/common/GroupDefs.h \
|
||||
@ -775,6 +776,7 @@ SOURCES += main.cpp \
|
||||
gui/common/AvatarDialog.cpp \
|
||||
gui/common/GroupFlagsWidget.cpp \
|
||||
gui/common/GroupSelectionBox.cpp \
|
||||
gui/common/GroupChooser.cpp \
|
||||
gui/common/StatusDefs.cpp \
|
||||
gui/common/TagDefs.cpp \
|
||||
gui/common/GroupDefs.cpp \
|
||||
|
Loading…
Reference in New Issue
Block a user