void GxsChannelDialog::insertChannelData(const std::list<RsGroupMetaData> &channelList)
{
	std::list<RsGroupMetaData>::const_iterator it;

	QList<GroupItemInfo> adminList;
	QList<GroupItemInfo> subList;
	QList<GroupItemInfo> popList;
	QList<GroupItemInfo> otherList;
	std::multimap<uint32_t, GroupItemInfo> popMap;

	for(it = channelList.begin(); it != channelList.end(); it++) {
		/* sort it into Publish (Own), Subscribed, Popular and Other */
		uint32_t flags = it->mSubscribeFlags;

		GroupItemInfo groupItemInfo;
		channelInfoToGroupItemInfo(*it, groupItemInfo);

		if (IS_GROUP_SUBSCRIBED(flags)) 
		{
			if (IS_GROUP_ADMIN(flags) || IS_GROUP_PUBLISHER(flags))
			{
				adminList.push_back(groupItemInfo);
			}
			else
			{
				/* subscribed forum */
				subList.push_back(groupItemInfo);
			}
		} 
		else 
		{
			/* rate the others by popularity */
			popMap.insert(std::make_pair(it->mPop, groupItemInfo));
		}
	}

	/* iterate backwards through popMap - take the top 5 or 10% of list */
	uint32_t popCount = 5;
	if (popCount < popMap.size() / 10) 
	{
		popCount = popMap.size() / 10;
	}

	uint32_t i = 0;
	std::multimap<uint32_t, GroupItemInfo>::reverse_iterator rit;
	for (rit = popMap.rbegin(); rit != popMap.rend(); rit++) 
	{
		if (i < popCount) 
		{
			popList.push_back(rit->second);
			i++;
		} 
		else 
		{
			otherList.push_back(rit->second);
		}
	}

	/* now we have our lists ---> update entries */

	ui.treeWidget->fillGroupItems(ownChannels, adminList);
	ui.treeWidget->fillGroupItems(subcribedChannels, subList);
	ui.treeWidget->fillGroupItems(popularChannels, popList);
	ui.treeWidget->fillGroupItems(otherChannels, otherList);

	updateMessageSummaryList("");
}
Beispiel #2
0
void ChannelFeed::updateChannelList()
{
	if (!rsChannels) {
		return;
	}

	std::list<ChannelInfo> channelList;
	std::list<ChannelInfo>::iterator it;
	rsChannels->getChannelList(channelList);

	std::list<std::string> keysAvailable;
	std::list<std::string>::iterator keyIt;
	rsChannels->getPubKeysAvailableGrpIds(keysAvailable);

	/* get the ids for our lists */
	QList<GroupItemInfo> adminList;
	QList<GroupItemInfo> subList;
	QList<GroupItemInfo> popList;
	QList<GroupItemInfo> otherList;
	std::multimap<uint32_t, GroupItemInfo> popMap;

	for(it = channelList.begin(); it != channelList.end(); it++) {
		/* sort it into Publish (Own), Subscribed, Popular and Other */
		uint32_t flags = it->channelFlags;

		GroupItemInfo groupItemInfo;
		channelInfoToGroupItemInfo(*it, groupItemInfo);

		if ((flags & RS_DISTRIB_ADMIN) && (flags & RS_DISTRIB_PUBLISH) && (flags & RS_DISTRIB_SUBSCRIBED)) {
			adminList.push_back(groupItemInfo);
		} else {
			for (keyIt = keysAvailable.begin(); keyIt != keysAvailable.end(); keyIt++) {
				if (it->channelId == *keyIt) {
					/* Found Key, set title text to bold and colored blue */
					groupItemInfo.privatekey = true;
					break;
				}
			}

			if ((flags & RS_DISTRIB_SUBSCRIBED) || ((flags & RS_DISTRIB_SUBSCRIBED) && (flags & RS_DISTRIB_PUBLISH)) ) {
				subList.push_back(groupItemInfo);
			} else {
				/* rate the others by popularity */
				popMap.insert(std::make_pair(it->pop, groupItemInfo));
			}
		}
	}

	/* iterate backwards through popMap - take the top 5 or 10% of list */
	uint32_t popCount = 5;
	if (popCount < popMap.size() / 10) {
		popCount = popMap.size() / 10;
	}

	uint32_t i = 0;
	std::multimap<uint32_t, GroupItemInfo>::reverse_iterator rit;
	for (rit = popMap.rbegin(); rit != popMap.rend(); rit++) {
		if (i < popCount) {
			popList.push_back(rit->second);
			i++;
		} else {
			otherList.push_back(rit->second);
		}
	}

    /* now we have our lists ---> update entries */

	treeWidget->fillGroupItems(ownChannels, adminList);
	treeWidget->fillGroupItems(subcribedChannels, subList);
	treeWidget->fillGroupItems(popularChannels, popList);
	treeWidget->fillGroupItems(otherChannels, otherList);

	updateMessageSummaryList("");
}