void LLParticipantList::sort()
{
	if ( !mAvatarList )
		return;

	switch ( getSortOrder() ) 
	{
		case E_SORT_BY_NAME :
			// if mExcludeAgent == true , then no need to keep agent on top of the list
			if(mExcludeAgent)
			{
				mAvatarList->sortByName();
			}
			else
			{
				mAvatarList->setComparator(&AGENT_ON_TOP_NAME_COMPARATOR);
				mAvatarList->sort();
			}
			break;
		case E_SORT_BY_RECENT_SPEAKERS:
			if (mSortByRecentSpeakers.isNull())
				mSortByRecentSpeakers = new LLAvatarItemRecentSpeakerComparator(*this);
			mAvatarList->setComparator(mSortByRecentSpeakers.get());
			mAvatarList->sort();
			break;
		default :
			llwarns << "Unrecognized sort order for " << mAvatarList->getName() << llendl;
			return;
	}
}
bool CWizCategoryViewItemBase::operator < (const QTreeWidgetItem &other) const
{
    const CWizCategoryViewItemBase* pOther = dynamic_cast<const CWizCategoryViewItemBase*>(&other);
    if (!pOther)
        return false;
    //
    int nThis = getSortOrder();
    int nOther = pOther->getSortOrder();
    //
    if (nThis != nOther)
    {
        return nThis < nOther;
    }
    //
    QString strThis = text(0).toLower();
    QString strOther = pOther->text(0).toLower();
    //
    static bool isSimpChinese = IsSimpChinese();
    if (isSimpChinese)
    {
        if (QTextCodec* pCodec = QTextCodec::codecForName("GBK"))
        {
            QByteArray arrThis = pCodec->fromUnicode(strThis);
            QByteArray arrOther = pCodec->fromUnicode(strOther);
            //
            std::string strThisA(arrThis.data(), arrThis.size());
            std::string strOtherA(arrOther.data(), arrOther.size());
            //
            return strThisA.compare(strOtherA.c_str()) < 0;
        }
    }
    //
    return strThis.compare(strOther) < 0;
}
void LLParticipantList::updateRecentSpeakersOrder()
{
	if (E_SORT_BY_RECENT_SPEAKERS == getSortOrder() && !isHovered())
	{
		// Need to update speakers to sort list correctly
		mSpeakerMgr->update(true);
		// Resort avatar list
		sort();
	}
}
void FSParticipantList::update()
{
	mSpeakerMgr->update(true);

	if (E_SORT_BY_RECENT_SPEAKERS == getSortOrder() && !isHovered())
	{
		// Resort avatar list
		sort();
	}
}
void LLInventoryFilter::toLLSD(LLSD& data) const
{
	data["filter_types"] = (LLSD::Integer)getFilterObjectTypes();
	data["min_date"] = (LLSD::Integer)getMinDate();
	data["max_date"] = (LLSD::Integer)getMaxDate();
	data["hours_ago"] = (LLSD::Integer)getHoursAgo();
	data["show_folder_state"] = (LLSD::Integer)getShowFolderState();
	data["permissions"] = (LLSD::Integer)getFilterPermissions();
	data["substring"] = (LLSD::String)getFilterSubString();
	data["sort_order"] = (LLSD::Integer)getSortOrder();
	data["since_logoff"] = (LLSD::Boolean)isSinceLogoff();
}
void SortCommandTokeniser::tokeniseSortEnd(std::string userInput, CommandTokens* outputCommandTokens) {
	outputCommandTokens->setSecondaryCommand(CommandTokens::SecondaryCommandType::End);

	std::string sortOrder = getSortOrder(userInput);
	outputCommandTokens->setOtherCommandParameter(sortOrder);
}