Exemplo n.º 1
0
void PlaylistDialog::populatePreviewFromSaved(const QItemSelection &, const QItemSelection &)
{
	static const int MAX_TRACKS_PREVIEW_AREA = 30;
	QModelIndexList indexes = savedPlaylists->selectionModel()->selectedIndexes();
	bool empty = indexes.isEmpty();
	this->clearPreview(!empty);
	if (indexes.size() == 1) {
		uint playlistId = _savedPlaylistModel->itemFromIndex(indexes.first())->data(PlaylistID).toUInt();
		QList<TrackDAO> tracks = SqlDatabase::instance()->selectPlaylistTracks(playlistId);
		for (int i = 0; i < tracks.size(); i++) {
			TrackDAO track = tracks.at(i);
			QTreeWidgetItem *item = new QTreeWidgetItem;
			item->setText(0, QString("%1 (%2 - %3)").arg(track.title(), track.artist(), track.album()));
			previewPlaylist->addTopLevelItem(item);

			if (i + 1 == MAX_TRACKS_PREVIEW_AREA) {
				QTreeWidgetItem *item = new QTreeWidgetItem;
				item->setText(0, tr("And more tracks..."));
				previewPlaylist->addTopLevelItem(item);
				break;
			}
		}
	}
	loadPlaylists->setDisabled(empty);
	deletePlaylists->setDisabled(empty);
	exportPlaylists->setEnabled(indexes.size() == 1);

	// Some work for the Save button
	if (empty) {
		savePlaylists->setEnabled(false);
	} else {
		bool allPlaylistsAreModified = true;
		QMap<uint, Playlist*> map;
		for (int i = 0; i < _playlists.count(); i++) {
			Playlist *p = _playlists.at(i);
			map.insert(p->id(), p);
		}
		for (QModelIndex idx : indexes) {
			uint playlistId = idx.data(PlaylistID).toUInt();
			if (map.contains(playlistId)) {
				Playlist *p = map.value(playlistId);
				allPlaylistsAreModified = allPlaylistsAreModified && p->isModified();
			}
		}
		savePlaylists->setEnabled(allPlaylistsAreModified);
	}
}
Exemplo n.º 2
0
/** Update saved playlists when one is adding a new one. */
void PlaylistDialog::updatePlaylists()
{
	// Populate saved playlists area
	_savedPlaylistModel->clear();
	_savedPlaylistModel->blockSignals(true);

	QMap<uint, Playlist*> map;
	for (int i = 0; i < _playlists.count(); i++) {
		Playlist *p = _playlists.at(i);
		if (p->id() != 0) {
			map.insert(p->id(), p);
		}
	}

	for (PlaylistDAO playlist : SqlDatabase::instance()->selectPlaylists()) {
		QStandardItem *item = new QStandardItem(playlist.title());
		item->setData(playlist.id(), PlaylistID);
		if (playlist.icon().isEmpty()) {
			Playlist *p = map.value(playlist.id().toUInt());
			if (p && p->isModified()) {
				item->setIcon(QIcon(":/icons/playlist_modified"));
				item->setData(true, PlaylistModified);
				item->setToolTip(tr("This playlist has changed"));
			} else {
				item->setIcon(QIcon(":/icons/playlist"));
			}
		} else {
			item->setIcon(QIcon(playlist.icon()));
		}
		_savedPlaylistModel->appendRow(item);
		_saved.insert(item, playlist);
	}
	_savedPlaylistModel->blockSignals(false);

	// Reset buttons status
	loadPlaylists->setEnabled(false);
	savePlaylists->setEnabled(false);
	deletePlaylists->setEnabled(false);
	exportPlaylists->setEnabled(false);
}