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)); }
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(); }
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; }