Ejemplo n.º 1
0
QVariant MPDSongModel::data(const QModelIndex &index, int role) const {
	Q_ASSERT(m_header);
	if (!index.isValid() || index.row() < 0 || index.row() >= m_visible.size() || index.column() >= m_header->columns().size())
		return QVariant();

	MPDSong song = m_visible.at(index.row());
	if (song.isNull())
		return QVariant();

	if (role == Qt::DisplayRole) {
		switch (m_header->columns().at(index.column())) {
			case HeaderView::TRACK:
				return song.track();
			case HeaderView::TITLE:
				return song.title();
			case HeaderView::LENGTH:
				return song.time();
			case HeaderView::ALBUM:
				return song.album();
			case HeaderView::ARTIST:
				return song.artist();
			case HeaderView::FILENAME:
				return song.filename();
			case HeaderView::URL:
				return song.url();
			case HeaderView::GENRE:
				return song.genre();
			case HeaderView::DATE:
				return song.date();
			case HeaderView::COMPOSER:
				return song.composer();
			case HeaderView::PERFORMER:
				return song.performer();
			case HeaderView::COMMENT:
				return song.comment();
			case HeaderView::DISC:
				return song.disc();
			default:
				return "?";
		}
	}

	if (role == Qt::TextAlignmentRole && m_header->columns().at(index.column()) == HeaderView::LENGTH)
		return Qt::AlignRight;

	return QVariant();
}
Ejemplo n.º 2
0
	int compareTrack(MPDSong l, MPDSong r) const {
		bool ok1, ok2;
		int ltrack = l.track().toInt(&ok1);
		// Try to handle "8/18" style formated fields
		if (!ok1) ltrack = l.track().section('/', 0, 0).toInt(&ok1);
		int rtrack = r.track().toInt(&ok2);
		if (!ok2) rtrack = r.track().section('/', 0, 0).toInt(&ok2);
		if (ok1 && ok2) {
			return compareCols(ltrack, rtrack);
		} else if (ok1) {
			return -1;
		} else if (ok2) {
			return 1;
		}
		return compareCols(l.track(), r.track());
	}
Ejemplo n.º 3
0
void TagGuesser::guessTags(MPDSong &song) {
	QString pattern = Config::instance()->guessPattern();

	// Check that we have a pattern at all
	if (pattern.isEmpty())
		return;

	// Cant guess from URL's
	if (song.url().contains("://"))
		return;

	// Return if we already have everything we can guess
	if (!(song.title().isEmpty() || song.album().isEmpty() || song.artist().isEmpty() || song.track().isEmpty()))
		return;

	DEBUG4("Guessing..");
	// Tokens to expand. %a=album, %b=band, %n=tracknr, %t=title, %i=ignore
	QStringList matchers = pattern.split(QRegExp("%[abnti]"), QString::SkipEmptyParts);
	QStringList markers = pattern.split('%', QString::SkipEmptyParts);

	// Check that we actually have any matchers, if not, return filename as title, the rest empty.

	DEBUG4("Matchers size: %d %d", matchers.size(), markers.size());
	if (matchers.isEmpty() || markers.isEmpty()) {

		DEBUG4("No matchers or no markers");
		if (song.title().isEmpty())
			song.setTitle(song.url());
		return;
	}

	// Remove bogus markers

	DEBUG4("Removing bogus markers");
	markers = markers.filter(QRegExp("^[abnti]"));
	// Remove trailing garbage on markers

	DEBUG4("Removing trailing garbage on markers");
	markers = markers.replaceInStrings(QRegExp("^([abnti]).*"), "%\\1");


	DEBUG4("Adding greedy front matcher");
	// If pattern does not have leading characters, add a greedy matcher at front so we get the whole start
	if (pattern.contains(QRegExp("^%[abnti]")))
		matchers.push_front("^");

	// If pattern contains trailing characters, add a dummy marker at the end.
	DEBUG4("Finding last matcher");
	QString lastMarker = markers.last();

	DEBUG4("Finding end of last marker");
	int endOfLastMatcher = pattern.lastIndexOf(lastMarker) + lastMarker.size();

	DEBUG4("Adding dummy end marker");
	if (endOfLastMatcher < pattern.size())
		markers += "trailingcharacters";

	foreach (QString p, markers) {
		DEBUG4("marker : %s", qPrintable(p));
	}