Пример #1
0
void Browser::GetDirectory(std::string dir, std::string subdir)
{
	if (dir.empty())
		dir = "/";
	
	int highlightme = -1;
	itsScrollBeginning = 0;
	if (itsBrowsedDir != dir)
		w->Reset();
	itsBrowsedDir = dir;
	
	locale_to_utf(dir);
	
	for (size_t i = 0; i < w->Size(); ++i)
		if (w->at(i).type == itSong)
			delete w->at(i).song;
	
	w->Clear();
	
	if (dir != "/")
	{
		MPD::Item parent;
		size_t slash = dir.rfind("/");
		parent.song = reinterpret_cast<MPD::Song *>(1); // in that way we assume that's really parent dir
		parent.name = slash != std::string::npos ? dir.substr(0, slash) : "/";
		parent.type = itDirectory;
		utf_to_locale(parent.name);
		w->AddOption(parent);
	}
	
	MPD::ItemList list;
#	ifndef WIN32
	isLocal() ? GetLocalDirectory(list) : Mpd.GetDirectory(dir, list);
#	else
	Mpd.GetDirectory(dir, list);
#	endif // !WIN32
	if (!isLocal()) // local directory is already sorted
		sort(list.begin(), list.end(), CaseInsensitiveSorting());
	
	for (MPD::ItemList::iterator it = list.begin(); it != list.end(); ++it)
	{
		switch (it->type)
		{
			case itPlaylist:
			{
				utf_to_locale(it->name);
				w->AddOption(*it);
				break;
			}
			case itDirectory:
			{
				utf_to_locale(it->name);
				if (it->name == subdir)
					highlightme = w->Size();
				w->AddOption(*it);
				break;
			}
			case itSong:
			{
				bool bold = 0;
				for (size_t i = 0; i < myPlaylist->Items->Size(); ++i)
				{
					if (myPlaylist->Items->at(i).GetHash() == it->song->GetHash())
					{
						bold = 1;
						break;
					}
				}
				w->AddOption(*it, bold);
				break;
			}
		}
	}
	if (highlightme >= 0)
		w->Highlight(highlightme);
}
Пример #2
0
void Browser::SpacePressed()
{
	if (w->Empty())
		return;
	
	if (Config.space_selects && w->Choice() >= (itsBrowsedDir != "/" ? 1 : 0))
	{
		w->Select(w->Choice(), !w->isSelected());
		w->Scroll(wDown);
		return;
	}
	
	if (itsBrowsedDir != "/" && w->Choice() == 0 /* parent dir */)
		return;
	
	const MPD::Item &item = w->Current();
	switch (item.type)
	{
		case itDirectory:
		{
			if (itsBrowsedDir != "/" && !w->Choice())
				break; // do not let add parent dir.
			
			MPD::SongList list;
#			ifndef WIN32
			if (isLocal())
			{
				MPD::ItemList items;
				ShowMessage(_("Scanning \"%s\"..."), item.name.c_str());
				myBrowser->GetLocalDirectory(items, item.name, 1);
				list.reserve(items.size());
				for (MPD::ItemList::const_iterator it = items.begin(); it != items.end(); ++it)
					list.push_back(it->song);
			}
			else
#			endif // !WIN32
				Mpd.GetDirectoryRecursive(locale_to_utf_cpy(item.name), list);
			
			if (myPlaylist->Add(list, 0))
				ShowMessage(_("Added folder: %s"), item.name.c_str());
			
			FreeSongList(list);
			break;
		}
		case itSong:
		{
			w->Bold(w->Choice(), myPlaylist->Add(*item.song, w->isBold(), 0));
			break;
		}
		case itPlaylist:
		{
			std::string name = item.name;
			ShowMessage(_("Loading playlist %s..."), name.c_str());
			locale_to_utf(name);
			if (!Mpd.LoadPlaylist(name))
				ShowMessage(_("Couldn't load playlist."));
			break;
		}
	}
	w->Scroll(wDown);
}