Пример #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;
	}
Пример #2
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;
}
Пример #3
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();
}
Пример #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);
	}
}