コード例 #1
0
void FlatStyle_RDM::updateRefs()
{
	if(RsAutoUpdatePage::eventsLocked())
	{
		_needs_update = true ;
		return ;
	}

	RetroshareDirModel::preMods() ;

	static const uint32_t MAX_REFS_PER_SECOND = 2000 ;
	uint32_t nb_treated_refs = 0 ;

	while(!_ref_stack.empty())
	{
		void *ref = _ref_stack.back() ;
#ifdef RDM_DEBUG
		std::cerr << "FlatStyle_RDM::postMods(): poped ref " << ref << std::endl;
#endif
		_ref_stack.pop_back() ;
		uint32_t flags = DIR_FLAGS_DETAILS;
		DirDetails details ;

		if (requestDirDetails(ref, details, flags))
		{
			if(details.type == DIR_TYPE_FILE)		// only push files, not directories nor persons.
				_ref_entries.push_back(std::pair<void*,QString>(ref,computeDirectoryPath(details)));
#ifdef RDM_DEBUG
			std::cerr << "FlatStyle_RDM::postMods(): addign ref " << ref << std::endl;
#endif
			for(std::list<DirStub>::iterator it = details.children.begin(); it != details.children.end(); it++) 
				_ref_stack.push_back(it->ref) ;
		}
		if(++nb_treated_refs > MAX_REFS_PER_SECOND) 	// we've done enough, let's give back hand to 
		{															// the user and setup a timer to finish the job later.
			_needs_update = true ;

			if(visible())
				QTimer::singleShot(2000,this,SLOT(updateRefs())) ;
			else
				std::cerr << "Not visible: suspending update"<< std::endl;
			break ;
		}
	}
	std::cerr << "reference tab contains " << _ref_entries.size() << " files" << std::endl;

	if(_ref_stack.empty())
		_needs_update = false ;

	RetroshareDirModel::postMods() ;
}
コード例 #2
0
QVariant FlatStyle_RDM::displayRole(const DirDetails& details,int coln) const
{
	if (details.type == DIR_TYPE_FILE) /* File */
		switch(coln)
		{
			case 0: return QString::fromUtf8(details.name.c_str());
			case 1: return misc::friendlyUnit(details.count);
			case 2: return misc::userFriendlyDuration(details.age);
			case 3: return QString::fromUtf8(rsPeers->getPeerName(details.id).c_str());
			case 4: return computeDirectoryPath(details);
			default:
				return QVariant() ;
		}

	return QVariant();
} /* end of DisplayRole */