Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WFindOnWebMenu: Implementing the factory pattern #4836

Merged
merged 1 commit into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,10 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/waveform/waveform.cpp
src/waveform/waveformfactory.cpp
src/widget/controlwidgetconnection.cpp
src/widget/findonwebmenufactory.cpp
src/widget/findonwebmenuservices/findonwebmenudiscogs.cpp
src/widget/findonwebmenuservices/findonwebmenulastfm.cpp
src/widget/findonwebmenuservices/findonwebmenusoundcloud.cpp
src/widget/hexspinbox.cpp
src/widget/paintable.cpp
src/widget/wanalysislibrarytableview.cpp
Expand Down
26 changes: 26 additions & 0 deletions src/widget/findonwebmenufactory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "findonwebmenufactory.h"

#include <QMenu>

#include "findonwebmenuservices/findonwebmenudiscogs.h"
#include "findonwebmenuservices/findonwebmenulastfm.h"
#include "findonwebmenuservices/findonwebmenusoundcloud.h"

namespace mixxx {

namespace library {

void createFindOnWebSubmenus(QMenu* pFindOnWebMenu, const Track& track) {
auto pFindOnWebMenuSoundcloud = make_parented<QMenu>(
new FindOnWebMenuSoundcloud(pFindOnWebMenu, track));

auto pFindOnWebMenuDiscogs = make_parented<QMenu>(
new FindOnWebMenuDiscogs(pFindOnWebMenu, track));

auto pFindOnWebMenuLastfm = make_parented<QMenu>(
new FindOnWebMenuLastfm(pFindOnWebMenu, track));
}

} // namespace library

} // namespace mixxx
15 changes: 15 additions & 0 deletions src/widget/findonwebmenufactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <QMenu>

class Track;

namespace mixxx {

namespace library {

void createFindOnWebSubmenus(QMenu* pFindOnWebMenu, const Track& track);

} // namespace library

} // namespace mixxx
76 changes: 76 additions & 0 deletions src/widget/findonwebmenuservices/findonwebmenudiscogs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "findonwebmenudiscogs.h"

#include <QMenu>
#include <QUrlQuery>

#include "track/track.h"
#include "util/parented_ptr.h"

namespace {
const QString kServiceTitle = QStringLiteral("Discogs");

const QString kQueryTypeRelease = QStringLiteral("release");

const QString kQueryTypeArtist = QStringLiteral("artist");

const QString kSearchUrl = QStringLiteral(
"https://www.discogs.com/search/?");

const QUrl composeDiscogsUrl(const QString& serviceDefaultUrl,
const QString& query,
const QString& queryType) {
QUrlQuery urlQuery;
urlQuery.addQueryItem("q", query);
urlQuery.addQueryItem("type", queryType);
QUrl url(serviceDefaultUrl);
url.setQuery(urlQuery);
return url;
}
} //namespace

FindOnWebMenuDiscogs::FindOnWebMenuDiscogs(QMenu* pFindOnWebMenu, const Track& track) {
const QString artist = track.getArtist();
const QString trackTitle = track.getTitle();
const QString album = track.getAlbum();
auto pDiscogsMenu = make_parented<QMenu>(pFindOnWebMenu);
pDiscogsMenu->setTitle(kServiceTitle);
pFindOnWebMenu->addMenu(pDiscogsMenu);
addSeparator();
if (!artist.isEmpty()) {
const QUrl discogsUrlArtist = composeDiscogsUrl(kSearchUrl, artist, kQueryTypeArtist);
addActionToServiceMenu(pDiscogsMenu,
composeActionText(tr("Artist"), artist),
discogsUrlArtist);
}
if (!trackTitle.isEmpty()) {
if (!artist.isEmpty()) {
const QString artistWithTrackTitle = composeSearchQuery(artist, trackTitle);
const QUrl discogsUrlArtistWithTrackTitle = composeDiscogsUrl(
kSearchUrl, artistWithTrackTitle, kQueryTypeRelease);
addActionToServiceMenu(pDiscogsMenu,
composeActionText(
tr("Artist + Title"), artistWithTrackTitle),
discogsUrlArtistWithTrackTitle);
}
const QUrl discogsUrlTrackTitle =
composeDiscogsUrl(kSearchUrl, trackTitle, kQueryTypeRelease);
addActionToServiceMenu(pDiscogsMenu,
composeActionText(tr("Title"), trackTitle),
discogsUrlTrackTitle);
}
if (!album.isEmpty()) {
if (!artist.isEmpty()) {
const QString artistWithAlbum = composeSearchQuery(artist, album);
const QUrl discogsUrlArtistWithAlbum = composeDiscogsUrl(
kSearchUrl, artistWithAlbum, kQueryTypeRelease);
addActionToServiceMenu(pDiscogsMenu,
composeActionText(tr("Artist + Album"), artistWithAlbum),
discogsUrlArtistWithAlbum);
} else {
const QUrl discogsUrlAlbum = composeDiscogsUrl(kSearchUrl, album, kQueryTypeRelease);
addActionToServiceMenu(pDiscogsMenu,
composeActionText(tr("Album"), album),
discogsUrlAlbum);
}
}
}
10 changes: 10 additions & 0 deletions src/widget/findonwebmenuservices/findonwebmenudiscogs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include "track/track.h"
#include "util/parented_ptr.h"
#include "widget/wfindonwebmenu.h"

class FindOnWebMenuDiscogs : public WFindOnWebMenu {
public:
FindOnWebMenuDiscogs(QMenu* pFindOnWebMenu, const Track& track);
};
73 changes: 73 additions & 0 deletions src/widget/findonwebmenuservices/findonwebmenulastfm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "findonwebmenulastfm.h"

#include <QMenu>
#include <QUrlQuery>

#include "track/track.h"
#include "util/parented_ptr.h"

namespace {
const QString kServiceTitle = QStringLiteral("LastFm");

const QString kSearchUrlArtist = QStringLiteral("https://www.last.fm/search/artists?");

const QString kSearchUrlTitle = QStringLiteral("https://www.last.fm/search/tracks?");

const QString kSearchUrlAlbum = QStringLiteral("https://www.last.fm/search/albums?");

const QUrl composeLastfmUrl(const QString& serviceSearchUrl,
const QString& query) {
QUrlQuery urlQuery;
urlQuery.addQueryItem("q", query);
QUrl url(serviceSearchUrl);
url.setQuery(urlQuery);
return url;
}

} //namespace

FindOnWebMenuLastfm::FindOnWebMenuLastfm(QMenu* pFindOnWebMenu, const Track& track) {
const QString artist = track.getArtist();
const QString trackTitle = track.getTitle();
const QString album = track.getAlbum();
auto pLastfmMenu = make_parented<QMenu>(pFindOnWebMenu);
pLastfmMenu->setTitle(kServiceTitle);
pFindOnWebMenu->addMenu(pLastfmMenu);
pLastfmMenu->addSeparator();
if (!artist.isEmpty()) {
const QUrl lastfmUrlArtist = composeLastfmUrl(kSearchUrlArtist, artist);
addActionToServiceMenu(pLastfmMenu,
composeActionText(tr("Artist"), artist),
lastfmUrlArtist);
}
if (!trackTitle.isEmpty()) {
if (!artist.isEmpty()) {
const QString artistWithTrackTitle = composeSearchQuery(artist, trackTitle);
const QUrl lastfmUrlArtistWithTrackTitle =
composeLastfmUrl(kSearchUrlTitle, artistWithTrackTitle);
addActionToServiceMenu(pLastfmMenu,
composeActionText(
tr("Artist + Title"), artistWithTrackTitle),
lastfmUrlArtistWithTrackTitle);
}
const QUrl lastfmUrlTrackTitle = composeLastfmUrl(kSearchUrlTitle, trackTitle);
addActionToServiceMenu(pLastfmMenu,
composeActionText(tr("Title"), trackTitle),
lastfmUrlTrackTitle);
}
if (!album.isEmpty()) {
if (!artist.isEmpty()) {
const QString artistWithAlbum = composeSearchQuery(artist, album);
const QUrl lastfmUrlArtistWithAlbum =
composeLastfmUrl(kSearchUrlAlbum, artistWithAlbum);
addActionToServiceMenu(pLastfmMenu,
composeActionText(tr("Artist + Album"), artistWithAlbum),
lastfmUrlArtistWithAlbum);
} else {
const QUrl lastfmUrlAlbum = composeLastfmUrl(kSearchUrlAlbum, album);
addActionToServiceMenu(pLastfmMenu,
composeActionText(tr("Album"), album),
lastfmUrlAlbum);
}
}
}
10 changes: 10 additions & 0 deletions src/widget/findonwebmenuservices/findonwebmenulastfm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include "track/track.h"
#include "util/parented_ptr.h"
#include "widget/wfindonwebmenu.h"

class FindOnWebMenuLastfm : public WFindOnWebMenu {
public:
FindOnWebMenuLastfm(QMenu* pFindOnWebMenu, const Track& track);
};
73 changes: 73 additions & 0 deletions src/widget/findonwebmenuservices/findonwebmenusoundcloud.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "findonwebmenusoundcloud.h"

#include <QMenu>
#include <QUrlQuery>

#include "track/track.h"
#include "util/parented_ptr.h"

namespace {
const QString kServiceTitle = QStringLiteral("Soundcloud");

const QString kSearchUrlArtist = QStringLiteral("https://soundcloud.com/search/people?");

const QString kSearchUrlTitle = QStringLiteral("https://soundcloud.com/search/sounds?");

const QString kSearchUrlAlbum = QStringLiteral("https://soundcloud.com/search/albums?");

const QUrl composeSoundcloudUrl(const QString& serviceSearchUrl,
const QString& query) {
QUrlQuery urlQuery;
urlQuery.addQueryItem("q", query);
QUrl url(serviceSearchUrl);
url.setQuery(urlQuery);
return url;
}
} // namespace

FindOnWebMenuSoundcloud::FindOnWebMenuSoundcloud(
QMenu* pFindOnWebMenu, const Track& track) {
const QString artist = track.getArtist();
const QString trackTitle = track.getTitle();
const QString album = track.getAlbum();
auto pSoundcloudMenu = make_parented<QMenu>(pFindOnWebMenu);
pSoundcloudMenu->setTitle(kServiceTitle);
pFindOnWebMenu->addMenu(pSoundcloudMenu);
pSoundcloudMenu->addSeparator();
if (!artist.isEmpty()) {
const QUrl SoundcloudUrlArtist = composeSoundcloudUrl(kSearchUrlArtist, artist);
addActionToServiceMenu(pSoundcloudMenu,
composeActionText(tr("Artist"), artist),
SoundcloudUrlArtist);
}
if (!trackTitle.isEmpty()) {
if (!artist.isEmpty()) {
const QString artistWithTrackTitle = composeSearchQuery(artist, trackTitle);
const QUrl SoundcloudUrlArtistWithTrackTitle =
composeSoundcloudUrl(kSearchUrlTitle, artistWithTrackTitle);
addActionToServiceMenu(pSoundcloudMenu,
composeActionText(
tr("Artist + Title"), artistWithTrackTitle),
SoundcloudUrlArtistWithTrackTitle);
}
const QUrl SoundcloudUrlTrackTitle = composeSoundcloudUrl(kSearchUrlTitle, trackTitle);
addActionToServiceMenu(pSoundcloudMenu,
composeActionText(tr("Title"), trackTitle),
SoundcloudUrlTrackTitle);
}
if (!album.isEmpty()) {
if (!artist.isEmpty()) {
const QString artistWithAlbum = composeSearchQuery(artist, album);
const QUrl SoundcloudUrlArtistWithAlbum =
composeSoundcloudUrl(kSearchUrlAlbum, artistWithAlbum);
addActionToServiceMenu(pSoundcloudMenu,
composeActionText(tr("Artist + Album"), artistWithAlbum),
SoundcloudUrlArtistWithAlbum);
} else {
const QUrl SoundcloudUrlAlbum = composeSoundcloudUrl(kSearchUrlAlbum, album);
addActionToServiceMenu(pSoundcloudMenu,
composeActionText(tr("Album"), album),
SoundcloudUrlAlbum);
}
}
}
10 changes: 10 additions & 0 deletions src/widget/findonwebmenuservices/findonwebmenusoundcloud.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include "track/track.h"
#include "util/parented_ptr.h"
#include "widget/wfindonwebmenu.h"

class FindOnWebMenuSoundcloud : public WFindOnWebMenu {
public:
FindOnWebMenuSoundcloud(QMenu* pFindOnWebMenu, const Track& track);
};
Loading