Exemple #1
0
void eListboxServiceContent::sort()
{
	if (!m_lst)
		m_service_center->list(m_root, m_lst);
	if (m_lst)
	{
		m_list.sort(iListableServiceCompare(m_lst));
			/* FIXME: is this really required or can we somehow keep the current entry? */
		cursorHome();
		if (m_listbox)
			m_listbox->entryReset();
	}
}
RESULT eServiceFS::getContent(std::list<eServiceReference> &list, bool sorted)
{
	DIR *d=opendir(path.c_str());
	if (!d)
		return -errno;

	ePtr<eServiceCenter> sc;
	eServiceCenter::getPrivInstance(sc);

	while (dirent *e=readdir(d))
	{
		if (!(strcmp(e->d_name, ".") && strcmp(e->d_name, "..")))
			continue;
		
		std::string filename;
		
		filename = path;
		filename += e->d_name;
		
		struct stat s;
		if (::stat(filename.c_str(), &s) < 0)
			continue;
		
		if (S_ISDIR(s.st_mode) || S_ISLNK(s.st_mode))
		{
			filename += "/";
			eServiceReference service(eServiceFactoryFS::id, 
				eServiceReference::isDirectory|
				eServiceReference::canDescent|eServiceReference::mustDescent|
				eServiceReference::shouldSort|eServiceReference::sort1,
				filename);
			service.data[0] = 1;
			list.push_back(service);
		} else
		{
			size_t e = filename.rfind('.');
			if (e != std::string::npos && e+1 < filename.length())
			{
				std::string extension = filename.substr(e+1);
				std::transform(extension.begin(), extension.end(), extension.begin(), lower);
				int type = getServiceTypeForExtension(extension);

				if (type == -1)
				{
					type = sc->getServiceTypeForExtension(extension);
				}
			
				if (type != -1)
				{
					eServiceReference service(type,
						0,
						filename);
					service.data[0] = 0;
					list.push_back(service);
				}
			}
		}
	}
	closedir(d);

	if (sorted)
		list.sort(iListableServiceCompare(this));

	return 0;
}