|
1 | 1 | // dlgtrackinfo.cpp
|
2 | 2 | // Created 11/10/2009 by RJ Ryan ([email protected])
|
3 | 3 |
|
| 4 | +#include <QDesktopServices> |
| 5 | +#include <QFileDialog> |
| 6 | +#include <QMenu> |
4 | 7 | #include <QtDebug>
|
5 | 8 |
|
6 | 9 | #include "dlgtrackinfo.h"
|
| 10 | +#include "library/coverartcache.h" |
7 | 11 | #include "library/dao/cue.h"
|
8 | 12 | #include "trackinfoobject.h"
|
9 | 13 |
|
@@ -62,10 +66,41 @@ void DlgTrackInfo::init(){
|
62 | 66 | this, SLOT(slotBpmTap()));
|
63 | 67 | connect(btnReloadFromFile, SIGNAL(clicked()),
|
64 | 68 | this, SLOT(reloadTrackMetadata()));
|
| 69 | + connect(btnOpenFileBrowser, SIGNAL(clicked()), |
| 70 | + this, SLOT(slotOpenInFileBrowser())); |
65 | 71 | m_bpmTapTimer.start();
|
66 | 72 | for (int i = 0; i < kFilterLength; ++i) {
|
67 | 73 | m_bpmTapFilter[i] = 0.0f;
|
68 | 74 | }
|
| 75 | + |
| 76 | + connect(CoverArtCache::instance(), SIGNAL(pixmapFound(int, QPixmap)), |
| 77 | + this, SLOT(slotPixmapFound(int, QPixmap)), Qt::DirectConnection); |
| 78 | + |
| 79 | + // Cover art actions |
| 80 | + // change cover art location |
| 81 | + QAction* changeCover = new QAction( |
| 82 | + QIcon(":/images/library/ic_cover_change.png"), |
| 83 | + tr("&Change"), this); |
| 84 | + connect(changeCover, SIGNAL(triggered()), |
| 85 | + this, SLOT(slotChangeCoverArt())); |
| 86 | + // unset cover art - load default |
| 87 | + QAction* unsetCover = new QAction( |
| 88 | + QIcon(":/images/library/ic_cover_unset.png"), |
| 89 | + tr("&Unset"), this); |
| 90 | + connect(unsetCover, SIGNAL(triggered()), |
| 91 | + this, SLOT(slotUnsetCoverArt())); |
| 92 | + // reload just cover art using the search algorithm (in CoverArtCache) |
| 93 | + QAction* reloadCover = new QAction( |
| 94 | + QIcon(":/images/library/ic_cover_reload.png"), |
| 95 | + tr("&Reload"), this); |
| 96 | + connect(reloadCover, SIGNAL(triggered()), |
| 97 | + this, SLOT(slotReloadCover())); |
| 98 | + // Cover art popup menu |
| 99 | + QMenu* coverMenu = new QMenu(this); |
| 100 | + coverMenu->addAction(changeCover); |
| 101 | + coverMenu->addAction(unsetCover); |
| 102 | + coverMenu->addAction(reloadCover); |
| 103 | + coverArt->setMenu(coverMenu); |
69 | 104 | }
|
70 | 105 |
|
71 | 106 | void DlgTrackInfo::OK() {
|
@@ -119,7 +154,7 @@ void DlgTrackInfo::cueDelete() {
|
119 | 154 | }
|
120 | 155 |
|
121 | 156 | void DlgTrackInfo::populateFields(TrackPointer pTrack) {
|
122 |
| - setWindowTitle(pTrack->getTitle()); |
| 157 | + setWindowTitle(pTrack->getArtist() % " - " % pTrack->getTitle()); |
123 | 158 |
|
124 | 159 | // Editable fields
|
125 | 160 | txtTrackName->setText(pTrack->getTitle());
|
@@ -160,6 +195,124 @@ void DlgTrackInfo::loadTrack(TrackPointer pTrack) {
|
160 | 195 |
|
161 | 196 | populateFields(m_pLoadedTrack);
|
162 | 197 | populateCues(m_pLoadedTrack);
|
| 198 | + |
| 199 | + // Load Default Cover Art |
| 200 | + coverArt->setIcon(scaledCoverArt(CoverArtCache::instance()->getDefaultCoverArt())); |
| 201 | + m_sLoadedCoverLocation.clear(); |
| 202 | +} |
| 203 | + |
| 204 | +QPixmap DlgTrackInfo::scaledCoverArt(QPixmap original) { |
| 205 | + return original.scaled(110, 110, |
| 206 | + Qt::KeepAspectRatio, |
| 207 | + Qt::SmoothTransformation); |
| 208 | +} |
| 209 | + |
| 210 | +void DlgTrackInfo::slotPixmapFound(int trackId, QPixmap pixmap) { |
| 211 | + if (m_pLoadedTrack == NULL) |
| 212 | + return; |
| 213 | + |
| 214 | + if (m_pLoadedTrack->getId() == trackId) { |
| 215 | + coverArt->setIcon(scaledCoverArt(pixmap)); |
| 216 | + update(); |
| 217 | + } |
| 218 | +} |
| 219 | + |
| 220 | +void DlgTrackInfo::slotLoadCoverArt(const QString& coverLocation, |
| 221 | + const QString& md5Hash, |
| 222 | + int trackId) { |
| 223 | + m_sLoadedCoverLocation = coverLocation; |
| 224 | + CoverArtCache::instance()->requestPixmap(trackId, |
| 225 | + m_sLoadedCoverLocation, |
| 226 | + md5Hash); |
| 227 | +} |
| 228 | + |
| 229 | +void DlgTrackInfo::slotUnsetCoverArt() { |
| 230 | + if (m_pLoadedTrack == NULL) { |
| 231 | + return; |
| 232 | + } |
| 233 | + bool res = CoverArtCache::instance()->changeCoverArt( |
| 234 | + m_pLoadedTrack->getId(), |
| 235 | + CoverArtCache::instance()->getDefaultCoverLocation()); |
| 236 | + if (!res) { |
| 237 | + QMessageBox::warning(this, tr("Unset Cover Art"), |
| 238 | + tr("Could not unset the cover art!")); |
| 239 | + } |
| 240 | +} |
| 241 | + |
| 242 | +void DlgTrackInfo::slotChangeCoverArt() { |
| 243 | + if (m_pLoadedTrack == NULL) { |
| 244 | + return; |
| 245 | + } |
| 246 | + |
| 247 | + // get initial directory (trackdir or coverdir) |
| 248 | + QString initialDir; |
| 249 | + QString trackPath = m_pLoadedTrack->getDirectory(); |
| 250 | + if (m_sLoadedCoverLocation.isEmpty() || |
| 251 | + m_sLoadedCoverLocation == CoverArtCache::instance() |
| 252 | + ->getDefaultCoverLocation()) { |
| 253 | + initialDir = trackPath; |
| 254 | + } else { |
| 255 | + initialDir = m_sLoadedCoverLocation; |
| 256 | + } |
| 257 | + |
| 258 | + // open file dialog |
| 259 | + QString selectedCover = QFileDialog::getOpenFileName( |
| 260 | + this, tr("Change Cover Art"), initialDir, |
| 261 | + tr("Image Files (*.png *.jpg *.jpeg *.bmp)")); |
| 262 | + |
| 263 | + if (selectedCover.isEmpty()) { |
| 264 | + return; |
| 265 | + } |
| 266 | + |
| 267 | + // if the cover comes from an external dir, |
| 268 | + // we copy it to the track directory. |
| 269 | + QString newCover; |
| 270 | + QFileInfo coverInfo(selectedCover); |
| 271 | + QString coverPath = coverInfo.absolutePath(); |
| 272 | + if (trackPath != coverPath) { |
| 273 | + QString ext = coverInfo.suffix(); |
| 274 | + QStringList filepaths; |
| 275 | + filepaths << trackPath % "/cover." % ext |
| 276 | + << trackPath % "/album." % ext |
| 277 | + << trackPath % "/mixxx-cover." % ext; |
| 278 | + |
| 279 | + foreach (QString filepath, filepaths) { |
| 280 | + if (QFile::copy(selectedCover, filepath)) { |
| 281 | + newCover = filepath; |
| 282 | + break; |
| 283 | + } |
| 284 | + } |
| 285 | + |
| 286 | + if (newCover.isEmpty()) { |
| 287 | + // overwrites "mixxx-cover" |
| 288 | + QFile::remove(filepaths.last()); |
| 289 | + if (QFile::copy(selectedCover, filepaths.last())) { |
| 290 | + newCover = filepaths.last(); |
| 291 | + } |
| 292 | + } |
| 293 | + } else { |
| 294 | + newCover = selectedCover; |
| 295 | + } |
| 296 | + |
| 297 | + bool res = CoverArtCache::instance()->changeCoverArt( |
| 298 | + m_pLoadedTrack->getId(), newCover); |
| 299 | + if (res) { |
| 300 | + m_sLoadedCoverLocation = newCover; |
| 301 | + } else { |
| 302 | + QMessageBox::warning(this, tr("Change Cover Art"), |
| 303 | + tr("Could not change the cover art!")); |
| 304 | + } |
| 305 | +} |
| 306 | + |
| 307 | +void DlgTrackInfo::slotOpenInFileBrowser() { |
| 308 | + if (m_pLoadedTrack == NULL) { |
| 309 | + return; |
| 310 | + } |
| 311 | + QDir directory(m_pLoadedTrack->getDirectory()); |
| 312 | + if (!directory.exists()) { |
| 313 | + directory = QDir::home(); |
| 314 | + } |
| 315 | + QDesktopServices::openUrl(QUrl::fromLocalFile(directory.absolutePath())); |
163 | 316 | }
|
164 | 317 |
|
165 | 318 | void DlgTrackInfo::populateCues(TrackPointer pTrack) {
|
@@ -223,6 +376,7 @@ void DlgTrackInfo::populateCues(TrackPointer pTrack) {
|
223 | 376 | row += 1;
|
224 | 377 | }
|
225 | 378 | cueTable->setSortingEnabled(true);
|
| 379 | + cueTable->horizontalHeader()->setStretchLastSection(true); |
226 | 380 | }
|
227 | 381 |
|
228 | 382 | void DlgTrackInfo::saveTrack() {
|
@@ -377,6 +531,13 @@ void DlgTrackInfo::reloadTrackMetadata() {
|
377 | 531 | }
|
378 | 532 | }
|
379 | 533 |
|
| 534 | +void DlgTrackInfo::slotReloadCover() { |
| 535 | + if (m_pLoadedTrack) { |
| 536 | + m_sLoadedCoverLocation.clear(); |
| 537 | + CoverArtCache::instance()->requestPixmap(m_pLoadedTrack->getId()); |
| 538 | + } |
| 539 | +} |
| 540 | + |
380 | 541 | void DlgTrackInfo::fetchTag() {
|
381 | 542 | m_DlgTagFetcher.init(m_pLoadedTrack);
|
382 | 543 | m_DlgTagFetcher.show();
|
|
0 commit comments