added a GroupChooser class to choose groups of friend nodes

This commit is contained in:
csoler 2016-07-09 18:06:59 -04:00
parent 0125f91b2d
commit d089e2ef1a
6 changed files with 218 additions and 86 deletions

3
.gitignore vendored
View File

@ -1,5 +1,8 @@
/RetroShare.pro.user /RetroShare.pro.user
*.o *.o
*.sw?
*.so
*.so.*
moc_*.cpp moc_*.cpp
qrc_*.cpp qrc_*.cpp
ui_*.h ui_*.h

View 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;
}

View 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;
};

View File

@ -125,7 +125,7 @@ void GxsGroupDialog::init()
ui.idChooser->loadIds(0,RsGxsId()); ui.idChooser->loadIds(0,RsGxsId());
ui.circleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, RsGxsCircleId()); 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")); 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: case GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY:
ui.typeLocal->setChecked(true); ui.typeLocal->setChecked(true);
distribution_string = tr("Your friends only") ; distribution_string = tr("Your friends only") ;
ui.localComboBox->loadCircles(GXS_CIRCLE_CHOOSER_PERSONAL, mGrpMeta.mInternalCircle); ui.localComboBox->loadGroups(0, RsNodeGroupId(mGrpMeta.mInternalCircle));
ui.distributionCircleComboBox->setVisible(true) ; ui.distributionCircleComboBox->setVisible(false) ;
ui.distributionCircleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_PERSONAL, mGrpMeta.mInternalCircle); ui.localComboBox->setVisible(true) ;
break; break;
case GXS_CIRCLE_TYPE_PUBLIC: case GXS_CIRCLE_TYPE_PUBLIC:
ui.typePublic->setChecked(true); ui.typePublic->setChecked(true);
distribution_string = tr("Public") ; distribution_string = tr("Public") ;
ui.distributionCircleComboBox->setVisible(false) ; ui.distributionCircleComboBox->setVisible(false) ;
break; ui.localComboBox->setVisible(false) ;
break;
case GXS_CIRCLE_TYPE_EXTERNAL: case GXS_CIRCLE_TYPE_EXTERNAL:
ui.typeGroup->setChecked(true); ui.typeGroup->setChecked(true);
distribution_string = tr("Restricted to circle:") ; 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.distributionCircleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, mGrpMeta.mCircleId);
ui.circleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, mGrpMeta.mCircleId); ui.circleComboBox->loadCircles(GXS_CIRCLE_CHOOSER_EXTERNAL, mGrpMeta.mCircleId);
break; break;
@ -720,41 +722,42 @@ void GxsGroupDialog::updateCircleOptions()
bool GxsGroupDialog::setCircleParameters(RsGroupMetaData &meta) bool GxsGroupDialog::setCircleParameters(RsGroupMetaData &meta)
{ {
meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC; meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
meta.mCircleId.clear(); meta.mCircleId.clear();
meta.mOriginator.clear(); meta.mOriginator.clear();
meta.mInternalCircle.clear(); meta.mInternalCircle.clear();
if (ui.typePublic->isChecked()) if (ui.typePublic->isChecked())
{ {
meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC; meta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
meta.mCircleId.clear(); meta.mCircleId.clear();
} }
else if (ui.typeGroup->isChecked()) else if (ui.typeGroup->isChecked())
{ {
meta.mCircleType = GXS_CIRCLE_TYPE_EXTERNAL; meta.mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
if (!ui.circleComboBox->getChosenCircle(meta.mCircleId)) if (!ui.circleComboBox->getChosenCircle(meta.mCircleId))
{ {
return false; return false;
} }
} }
else if (ui.typeLocal->isChecked()) else if (ui.typeLocal->isChecked())
{ {
meta.mCircleType = GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY; meta.mCircleType = GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY;
meta.mCircleId.clear(); meta.mCircleId.clear();
meta.mOriginator.clear(); meta.mOriginator.clear();
meta.mInternalCircle.clear() ; meta.mInternalCircle.clear() ;
if (!ui.localComboBox->getChosenCircle(meta.mInternalCircle)) RsNodeGroupId ngi ;
{
return false; if (!ui.localComboBox->getChosenGroup(ngi))
} return false;
}
else meta.mInternalCircle = RsGxsCircleId(ngi) ;
{ }
return false; else
} return false;
return true;
return true;
} }
void GxsGroupDialog::cancelDialog() void GxsGroupDialog::cancelDialog()

View File

@ -6,32 +6,23 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>828</width> <width>860</width>
<height>612</height> <height>775</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string notr="true">Create New</string> <string notr="true">Create New</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_5"> <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"> <property name="horizontalSpacing">
<number>6</number> <number>6</number>
</property> </property>
<property name="verticalSpacing"> <property name="verticalSpacing">
<number>0</number> <number>0</number>
</property> </property>
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="HeaderFrame" name="headerFrame"/> <widget class="HeaderFrame" name="headerFrame"/>
</item> </item>
@ -57,16 +48,7 @@
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<property name="leftMargin"> <property name="margin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number> <number>4</number>
</property> </property>
<item> <item>
@ -130,16 +112,7 @@
<property name="spacing"> <property name="spacing">
<number>9</number> <number>9</number>
</property> </property>
<property name="leftMargin"> <property name="margin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number> <number>3</number>
</property> </property>
<item> <item>
@ -261,16 +234,7 @@
</property> </property>
<widget class="QWidget" name="dockWidgetContents"> <widget class="QWidget" name="dockWidgetContents">
<layout class="QGridLayout" name="_2"> <layout class="QGridLayout" name="_2">
<property name="leftMargin"> <property name="margin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="spacing"> <property name="spacing">
@ -408,7 +372,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="GxsCircleChooser" name="localComboBox"/> <widget class="GroupChooser" name="localComboBox"/>
</item> </item>
</layout> </layout>
</item> </item>
@ -874,6 +838,11 @@
<extends>QTextEdit</extends> <extends>QTextEdit</extends>
<header location="global">gui/common/MimeTextEdit.h</header> <header location="global">gui/common/MimeTextEdit.h</header>
</customwidget> </customwidget>
<customwidget>
<class>GroupChooser</class>
<extends>QComboBox</extends>
<header>gui/common/GroupChooser.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../images.qrc"/> <include location="../images.qrc"/>

View File

@ -466,6 +466,7 @@ HEADERS += rshare.h \
gui/common/AvatarDefs.h \ gui/common/AvatarDefs.h \
gui/common/GroupFlagsWidget.h \ gui/common/GroupFlagsWidget.h \
gui/common/GroupSelectionBox.h \ gui/common/GroupSelectionBox.h \
gui/common/GroupChooser.h \
gui/common/StatusDefs.h \ gui/common/StatusDefs.h \
gui/common/TagDefs.h \ gui/common/TagDefs.h \
gui/common/GroupDefs.h \ gui/common/GroupDefs.h \
@ -775,6 +776,7 @@ SOURCES += main.cpp \
gui/common/AvatarDialog.cpp \ gui/common/AvatarDialog.cpp \
gui/common/GroupFlagsWidget.cpp \ gui/common/GroupFlagsWidget.cpp \
gui/common/GroupSelectionBox.cpp \ gui/common/GroupSelectionBox.cpp \
gui/common/GroupChooser.cpp \
gui/common/StatusDefs.cpp \ gui/common/StatusDefs.cpp \
gui/common/TagDefs.cpp \ gui/common/TagDefs.cpp \
gui/common/GroupDefs.cpp \ gui/common/GroupDefs.cpp \