mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-12-16 09:03:51 -05:00
added a GroupChooser class to choose groups of friend nodes
This commit is contained in:
parent
0125f91b2d
commit
d089e2ef1a
6 changed files with 218 additions and 86 deletions
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;
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue