Ejemplo n.º 1
0
MPDSongList MPDSongModel::songs(const QModelIndexList &indexes) const {
	MPDSongList songs;
	foreach (QModelIndex index, indexes) {
		MPDSong s = song(index);
		if (!s.isNull() && !songs.contains(s))
			songs << s;
	}
Ejemplo n.º 2
0
QString Notifications::makeTitle(const MPDSong &s) {
	int desktopWidth = QApplication::desktop()->width();
	QString title = elideRichText("", s.title().isEmpty() ? s.filename() : s.title()  , "", desktopWidth / 2) + "\n";
	QString artist = elideRichText("", s.artist(), "", desktopWidth / 4);
	QString album = elideRichText("", s.album(), "", desktopWidth / 4);
	
	if (!artist.isEmpty())
		title += artist + "\n";
	if (!album.isEmpty())
		title += album;
	return title;
}
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));
	}
Ejemplo n.º 4
0
void ControlPanel::setSong(const MPDSong &s) {
	if (s.isNull()) {
		titleLabel->setText(MPDConnection::instance()->isConnected() ? "" : QString("<h3>%1</h3>").arg(tr("Not connected", "qmpdclient is not connected to MPD")));
		artistLabel->setText("");
		timeSlider->setEnabled(true);
		return;
	}

	// Disable time counting for streams
	timeSlider->setEnabled(s.type() != MPDSong::PLAYLISTSTREAM);

	// Ensure labels are not too small if window is hidden
	const int titleWidth = isVisible() ? titleLabel->width() : width() - 200;
//	const int artistWidth = isVisible() ? artistLabel->width() : width() - 200;

	QString title = elideRichText("<h3>", s.title() , "</h3>", titleWidth);
	QString artist = s.artist();
	QString album = s.album();

	if (!artist.isEmpty() && !album.isEmpty())
		artist = QString("<b>%1</b> - <b>%2</b>").arg(artist, album);
	else if (!artist.isEmpty())
		artist += QString("<b>%1</b>").arg(artist);
	else if (!album.isEmpty())
		artist += QString("<b>%1</b>").arg(album);

	titleLabel->setText(title);
	artistLabel->setText(artist);

	if (Config::instance()->submitSongsToLastFm()) m_lastFm->setSong(s);
	m_lyricsDialog->setSong(s);

	if (!m_lyricsDialog->isHidden()) m_lyricsDialog->updateLyrics();

	if (Config::instance()->showCoverArt()) {
		m_coverArt->setSong(s);
		if (m_coverArt->hasCoverArt()) {
			coverArtButton->setIcon(m_coverArt->coverArt());
			coverArtButton->setIconSize(QSize(50, 50));
			coverArtButton->setVisible(true);
		}
		else coverArtButton->setVisible(false);
	}
}
Ejemplo n.º 5
0
void Notifications::setSong(const MPDSong &s) {
	if (m_previousSong.isNull() || m_previousSong == s || !Config::instance()->notificationsEnabled() || Config::instance()->notificationsTimeout() < 1) {
		m_previousSong = s;
		return;
	}
	if(!s.isNull())
	{
		notify(makeTitle(s));
	}
	m_previousSong = s;
}
Ejemplo n.º 6
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.º 7
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.º 8
0
	int compareRows(MPDSong l, MPDSong r) const {
		int res = 0;

		switch (m_sortColumn) {
			case HeaderView::TRACK:
				res = compareTrack(l, r);
				if (!res) res = compareCols(l.artist(), r.artist());
				if (!res) res = compareCols(l.album(), r.album());
				if (!res) res = compareCols(l.title(), r.title());
				break;

			case HeaderView::LENGTH:
				res = compareCols(l.secs(), r.secs());
				// Fall through
			case HeaderView::ARTIST:
				if (!res) res = compareCols(l.artist(), r.artist());
				if (!res) res = compareCols(l.album(), r.album());
				if (!res) res = compareTrack(l, r);
				if (!res) res = compareCols(l.title(), r.title());
				break;

			case HeaderView::COMPOSER:
				res = compareCols(l.composer(), r.composer());
				if (!res) res = compareCols(l.album(), r.album());
				if (!res) res = compareTrack(l, r);
				if (!res) res = compareCols(l.title(), r.title());
				break;

			case HeaderView::TITLE:
				res = normalizedCompareCols(l.title(), r.title());
				if (!res) res = compareCols(l.artist(), r.artist());
				if (!res) res = compareCols(l.album(), r.album());
				if (!res) res = compareTrack(l, r);
				break;

			case HeaderView::URL:
				res = compareCols(l.url(), r.url());
				break;

			// Similar ones..
			case HeaderView::FILENAME:
				STD_COMP(filename);
				break;

			case HeaderView::GENRE:
				STD_COMP(genre);
				break;

			case HeaderView::DATE:
				STD_COMP(date);
				res = compareCols(l.date(), r.date());
				break;

			case HeaderView::COMMENT:
				STD_COMP(comment);
				break;

			case HeaderView::DISC:
				STD_COMP(disc);
				break;

			case HeaderView::PERFORMER:
				STD_COMP(performer);
				break;

			default: // ALBUM
				res = normalizedCompareCols(l.album(), r.album());
				if (!res) res = compareCols(l.artist(), r.artist());
				if (!res) res = compareTrack(l, r);
				if (!res) res = compareCols(l.title(), r.title());
		}
		if (m_sortOrder != Qt::AscendingOrder)
			res = res * -1;
		return res;
	}
Ejemplo n.º 9
0
void LyricsDialog::setSong(const MPDSong &s) {
	m_artist=s.artist();
	m_title=s.title();
	if(!isHidden()) updateLyrics();
}