Allow showing db query result in browser
This commit is contained in:
parent
3c1c7839d1
commit
a3b8048156
|
@ -15,7 +15,8 @@ using namespace Media;
|
|||
|
||||
namespace QtGui {
|
||||
|
||||
SongDescription::SongDescription() :
|
||||
SongDescription::SongDescription(const QString &songId) :
|
||||
songId(songId),
|
||||
track(0),
|
||||
totalTracks(0),
|
||||
disk(0),
|
||||
|
@ -45,6 +46,12 @@ void QueryResultsModel::setFetchingCover(bool fetchingCover)
|
|||
void QueryResultsModel::abort()
|
||||
{}
|
||||
|
||||
QUrl QueryResultsModel::webUrl(const QModelIndex &index)
|
||||
{
|
||||
Q_UNUSED(index)
|
||||
return QUrl();
|
||||
}
|
||||
|
||||
#define returnValue(field) return qstringToTagValue(res.field, TagTextEncoding::Utf16LittleEndian)
|
||||
|
||||
TagValue QueryResultsModel::fieldValue(int row, KnownField knownField) const
|
||||
|
|
|
@ -22,8 +22,9 @@ namespace QtGui {
|
|||
|
||||
struct SongDescription
|
||||
{
|
||||
SongDescription();
|
||||
SongDescription(const QString &songId = QString());
|
||||
|
||||
QString songId;
|
||||
QString title;
|
||||
QString album;
|
||||
QString albumId;
|
||||
|
@ -50,7 +51,7 @@ public:
|
|||
GenreCol,
|
||||
YearCol,
|
||||
TrackCol,
|
||||
TotalTracksCol
|
||||
TotalTracksCol,
|
||||
};
|
||||
|
||||
const QList<SongDescription> &results() const;
|
||||
|
@ -69,6 +70,7 @@ public:
|
|||
const QString *lyrics(const QModelIndex &index) const;
|
||||
virtual bool fetchLyrics(const QModelIndex &index);
|
||||
virtual void abort();
|
||||
virtual QUrl webUrl(const QModelIndex &index);
|
||||
|
||||
signals:
|
||||
void resultsAvailable();
|
||||
|
|
|
@ -356,6 +356,25 @@ void LyricsWikiaResultsModel::parseAlbumDetailsAndFetchCover(int row, const QByt
|
|||
addReply(reply, bind(&LyricsWikiaResultsModel::handleCoverReplyFinished, this, reply, assocDesc.albumId, row));
|
||||
}
|
||||
|
||||
QUrl LyricsWikiaResultsModel::webUrl(const QModelIndex &index)
|
||||
{
|
||||
if(index.parent().isValid() || index.row() >= results().size()) {
|
||||
return QUrl();
|
||||
}
|
||||
|
||||
SongDescription &desc = m_results[index.row()];
|
||||
|
||||
// lazy initialize song ID
|
||||
if(desc.songId.isEmpty()) {
|
||||
desc.songId = desc.artist % QChar(':') % desc.title;
|
||||
desc.songId.replace(QChar(' '), QChar('_'));
|
||||
}
|
||||
// return URL
|
||||
QUrl url(lyricsWikiaApiUrl());
|
||||
url.setPath(QStringLiteral("/wiki/") + desc.songId);
|
||||
return url;
|
||||
}
|
||||
|
||||
QueryResultsModel *queryLyricsWikia(SongDescription &&songDescription)
|
||||
{
|
||||
// compose URL
|
||||
|
|
|
@ -15,6 +15,7 @@ public:
|
|||
LyricsWikiaResultsModel(SongDescription &&initialSongDescription, QNetworkReply *reply);
|
||||
bool fetchCover(const QModelIndex &index);
|
||||
bool fetchLyrics(const QModelIndex &index);
|
||||
QUrl webUrl(const QModelIndex &index);
|
||||
|
||||
protected:
|
||||
void parseInitialResults(const QByteArray &data);
|
||||
|
|
|
@ -47,6 +47,14 @@ bool MusicBrainzResultsModel::fetchCover(const QModelIndex &index)
|
|||
return true;
|
||||
}
|
||||
|
||||
QUrl MusicBrainzResultsModel::webUrl(const QModelIndex &index)
|
||||
{
|
||||
if(index.parent().isValid() || index.row() >= results().size()) {
|
||||
return QUrl();
|
||||
}
|
||||
return QUrl(QStringLiteral("https://musicbrainz.org/recording/") + results().at(index.row()).songId);
|
||||
}
|
||||
|
||||
void MusicBrainzResultsModel::parseInitialResults(const QByteArray &data)
|
||||
{
|
||||
// prepare parsing MusicBrainz meta data
|
||||
|
@ -62,7 +70,7 @@ void MusicBrainzResultsModel::parseInitialResults(const QByteArray &data)
|
|||
iftag("recording-list") {
|
||||
children {
|
||||
iftag("recording") {
|
||||
SongDescription currentDescription;
|
||||
SongDescription currentDescription(attribute("id").toString());
|
||||
children {
|
||||
iftag("title") {
|
||||
currentDescription.title = text;
|
||||
|
|
|
@ -21,6 +21,7 @@ private:
|
|||
public:
|
||||
MusicBrainzResultsModel(SongDescription &&initialSongDescription, QNetworkReply *reply);
|
||||
bool fetchCover(const QModelIndex &index);
|
||||
QUrl webUrl(const QModelIndex &index);
|
||||
|
||||
protected:
|
||||
void parseInitialResults(const QByteArray &data);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <QGraphicsView>
|
||||
#include <QGraphicsItem>
|
||||
#include <QTextBrowser>
|
||||
#include <QDesktopServices>
|
||||
|
||||
#include <functional>
|
||||
|
||||
|
@ -431,8 +432,12 @@ void DbQueryWidget::showResultsContextMenu()
|
|||
contextMenu.addAction(m_ui->applyPushButton->icon(), tr("Use selected row"), this, static_cast<void(DbQueryWidget::*)(void)>(&DbQueryWidget::applySelectedResults));
|
||||
}
|
||||
if(m_model && m_model->areResultsAvailable()) {
|
||||
if(!contextMenu.isEmpty()) {
|
||||
contextMenu.addSeparator();
|
||||
}
|
||||
contextMenu.addAction(QIcon::fromTheme(QStringLiteral("view-preview")), tr("Show cover"), this, &DbQueryWidget::fetchAndShowCoverForSelection);
|
||||
contextMenu.addAction(QIcon::fromTheme(QStringLiteral("view-media-lyrics")), tr("Show lyrics"), this, &DbQueryWidget::fetchAndShowLyricsForSelection);
|
||||
contextMenu.addAction(QIcon::fromTheme(QStringLiteral("internet-web-browser")), tr("Show in browser"), this, &DbQueryWidget::openSelectionInBrowser);
|
||||
}
|
||||
contextMenu.exec(QCursor::pos());
|
||||
}
|
||||
|
@ -495,6 +500,22 @@ void DbQueryWidget::fetchAndShowLyricsForSelection()
|
|||
}
|
||||
}
|
||||
|
||||
void DbQueryWidget::openSelectionInBrowser()
|
||||
{
|
||||
const QModelIndex selectedIndex = this->selectedIndex();
|
||||
if(!selectedIndex.isValid()) {
|
||||
return;
|
||||
}
|
||||
const QUrl url(m_model->webUrl(selectedIndex));
|
||||
if(url.isEmpty()) {
|
||||
m_ui->notificationLabel->appendLine(tr("No web URL available."));
|
||||
return;
|
||||
}
|
||||
if(!QDesktopServices::openUrl(url)) {
|
||||
m_ui->notificationLabel->appendLine(tr("Unable to open URL: ") + url.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void DbQueryWidget::showCover(const QByteArray &data)
|
||||
{
|
||||
QDialog dlg;
|
||||
|
|
|
@ -54,6 +54,7 @@ private slots:
|
|||
void showResultsContextMenu();
|
||||
void fetchAndShowCoverForSelection();
|
||||
void fetchAndShowLyricsForSelection();
|
||||
void openSelectionInBrowser();
|
||||
void showCover(const QByteArray &data);
|
||||
void showCoverFromIndex(const QModelIndex &index);
|
||||
void showLyrics(const QString &data);
|
||||
|
|
Loading…
Reference in New Issue