2018-11-14 15:14:40 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* retroshare-gui/src/gui/gxs/GxsCircleChooser.cpp *
|
|
|
|
* *
|
|
|
|
* Copyright 2012-2013 by Robert Fernie <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2012-12-15 18:11:11 -05:00
|
|
|
|
|
|
|
#include "GxsCircleChooser.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <retroshare/rspeers.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
/** Constructor */
|
|
|
|
GxsCircleChooser::GxsCircleChooser(QWidget *parent)
|
2016-07-11 18:30:12 -04:00
|
|
|
: QComboBox(parent)
|
2012-12-15 18:11:11 -05:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-11 18:30:12 -04:00
|
|
|
void GxsCircleChooser::loadCircles(const RsGxsCircleId &defaultId)
|
2012-12-15 18:11:11 -05:00
|
|
|
{
|
2014-01-28 02:57:58 -05:00
|
|
|
mDefaultCircleId = defaultId;
|
2012-12-15 18:11:11 -05:00
|
|
|
loadGxsCircles();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MakeGxsCircleDesc(const RsGxsCircleId &id, QString &desc)
|
|
|
|
{
|
|
|
|
RsGxsCircleDetails details;
|
|
|
|
|
|
|
|
if (rsGxsCircles->getCircleDetails(id, details))
|
|
|
|
{
|
|
|
|
desc = QString::fromUtf8(details.mCircleName.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
desc += "Unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
desc += " (Ext) [";
|
2014-03-17 16:56:06 -04:00
|
|
|
desc += QString::fromStdString(id.toStdString().substr(0,5));
|
2012-12-15 18:11:11 -05:00
|
|
|
desc += "...]";
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GxsCircleChooser::loadGxsCircles()
|
|
|
|
{
|
|
|
|
std::list<RsGxsCircleId> ids;
|
2016-07-11 18:30:12 -04:00
|
|
|
rsGxsCircles->getCircleExternalIdList(ids);
|
2012-12-15 18:11:11 -05:00
|
|
|
|
|
|
|
if (ids.empty())
|
|
|
|
{
|
|
|
|
std::cerr << "GxsCircleChooser::loadGxsCircles() ERROR no ids";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list<RsGxsCircleId>::iterator it;
|
2014-01-28 02:57:58 -05:00
|
|
|
int i = 0;
|
|
|
|
int def = -1;
|
2014-10-21 18:33:02 -04:00
|
|
|
for(it = ids.begin(); it != ids.end(); ++it, ++i)
|
2012-12-15 18:11:11 -05:00
|
|
|
{
|
|
|
|
/* add to Chooser */
|
|
|
|
QString str;
|
|
|
|
if (!MakeGxsCircleDesc(*it, str))
|
|
|
|
{
|
|
|
|
std::cerr << "GxsCircleChooser::loadGxsCircles() ERROR Desc for Id: " << *it;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
continue;
|
|
|
|
}
|
2014-03-17 16:56:06 -04:00
|
|
|
QString id = QString::fromStdString((*it).toStdString());
|
2012-12-15 18:11:11 -05:00
|
|
|
|
|
|
|
addItem(str, id);
|
2014-01-28 02:57:58 -05:00
|
|
|
|
|
|
|
if (mDefaultCircleId == *it)
|
|
|
|
{
|
|
|
|
def = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (def >= 0)
|
|
|
|
{
|
|
|
|
setCurrentIndex(def);
|
2012-12-15 18:11:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GxsCircleChooser::getChosenCircle(RsGxsCircleId &id)
|
|
|
|
{
|
|
|
|
if (count() < 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int idx = currentIndex();
|
|
|
|
|
|
|
|
QVariant var = itemData(idx);
|
2014-04-20 12:34:26 -04:00
|
|
|
id = RsGxsCircleId(var.toString().toStdString());
|
2012-12-15 18:11:11 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|