1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 23:39:42 +01:00

Merge branch 'whatshot'

This commit is contained in:
Casey Link 2011-08-29 18:56:12 -05:00
commit 6e6ff2ae53
22 changed files with 1133 additions and 26 deletions

1
.gitignore vendored
View File

@ -16,3 +16,4 @@ thirdparty/qtweetlib/WARNING-twitter-api-keys
clang/
win/
gcc/
tags

View File

@ -85,6 +85,7 @@
<file>data/images/automatic-playlist.png</file>
<file>data/images/station.png</file>
<file>data/images/new-additions.png</file>
<file>data/images/charts.png</file>
<file>data/images/loved_playlist.png</file>
<file>data/images/dashboard.png</file>
<file>data/images/artist-icon.png</file>

View File

@ -175,16 +175,20 @@ set( libSources
utils/spotifyparser.cpp
utils/rdioparser.cpp
utils/shortenedlinkparser.cpp
utils/stylehelper.cpp
widgets/newplaylistwidget.cpp
widgets/searchwidget.cpp
widgets/SeekSlider.cpp
widgets/playlisttypeselectordlg.cpp
widgets/welcomewidget.cpp
widgets/whatshotwidget.cpp
widgets/RecentlyPlayedPlaylistsModel.cpp
widgets/RecentPlaylistsModel.cpp
widgets/overlaywidget.cpp
widgets/HeaderLabel.cpp
widgets/HeaderWidget.cpp
widgets/combobox.cpp
widgets/SocialPlaylistWidget.cpp
widgets/infowidgets/sourceinfowidget.cpp
widgets/infowidgets/ArtistInfoWidget.cpp
@ -357,16 +361,20 @@ set( libHeaders
utils/spotifyparser.h
utils/rdioparser.h
utils/shortenedlinkparser.h
utils/stylehelper.h
widgets/newplaylistwidget.h
widgets/searchwidget.h
widgets/SeekSlider.h
widgets/playlisttypeselectordlg.h
widgets/welcomewidget.h
widgets/whatshotwidget.h
widgets/RecentlyPlayedPlaylistsModel.h
widgets/RecentPlaylistsModel.h
widgets/overlaywidget.h
widgets/HeaderLabel.h
widgets/HeaderWidget.h
widgets/combobox.h
widgets/SocialPlaylistWidget.h
widgets/infowidgets/sourceinfowidget.h
widgets/infowidgets/ArtistInfoWidget.h
@ -391,6 +399,7 @@ set( libUI ${libUI}
widgets/newplaylistwidget.ui
widgets/searchwidget.ui
widgets/welcomewidget.ui
widgets/whatshotwidget.ui
widgets/SocialPlaylistWidget.ui
widgets/infowidgets/sourceinfowidget.ui
widgets/infowidgets/ArtistInfoWidget.ui

View File

@ -47,7 +47,7 @@ LastFmPlugin::LastFmPlugin()
: InfoPlugin()
, m_scrobbler( 0 )
{
m_supportedGetTypes << InfoAlbumCoverArt << InfoArtistImages << InfoArtistSimilars << InfoArtistSongs;
m_supportedGetTypes << InfoAlbumCoverArt << InfoArtistImages << InfoArtistSimilars << InfoArtistSongs << InfoChartArtists << InfoChartTracks;
m_supportedPushTypes << InfoSubmitScrobble << InfoSubmitNowPlaying << InfoLove << InfoUnLove;
/*
@ -147,6 +147,14 @@ LastFmPlugin::getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData req
fetchTopTracks( requestId, requestData );
break;
case InfoChartArtists:
fetchChartArtists( requestId, requestData );
break;
case InfoChartTracks:
fetchChartTracks( requestId, requestData );
break;
default:
dataError( requestId, requestData );
}
@ -298,6 +306,43 @@ LastFmPlugin::fetchTopTracks( uint requestId, Tomahawk::InfoSystem::InfoRequestD
emit getCachedInfo( requestId, criteria, 2419200000, requestData );
}
void
LastFmPlugin::fetchChartArtists( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData )
{
if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() )
{
dataError( requestId, requestData );
return;
}
InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
if ( hash.contains( "country" ) )
{
criteria["country"] = hash["country"];
}
emit getCachedInfo( requestId, criteria, 2419200000, requestData );
}
void
LastFmPlugin::fetchChartTracks( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData )
{
if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() )
{
dataError( requestId, requestData );
return;
}
InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
if ( hash.contains( "country" ) )
{
criteria["country"] = hash["country"];
}
emit getCachedInfo( requestId, criteria, 2419200000, requestData );
}
void
LastFmPlugin::fetchCoverArt( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData )
@ -356,6 +401,44 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
switch ( requestData.type )
{
case InfoChartArtists:
{
tDebug() << "LastfmPlugin: InfoChartArtists notin cache, fetching";
QMap<QString, QString> args;
if( criteria.contains( "country" ) ) {
args["method"] = "geo.getTopArtists";
args["country"] = criteria["country"];
} else {
args["method"] = "chart.getTopArtists";
}
args["limit"] = "100";
QNetworkReply* reply = lastfm::ws::get(args);
reply->setProperty( "requestId", requestId );
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
connect( reply, SIGNAL( finished() ), SLOT( chartTopArtistsReturned() ) );
return;
}
case InfoChartTracks:
{
tDebug() << "LastfmPlugin: InfoChartTracks not in cache, fetching";
QMap<QString, QString> args;
if( criteria.contains( "country" ) ) {
args["method"] = "geo.getTopTracks";
args["country"] = criteria["country"];
} else {
args["method"] = "chart.getTopTracks";
}
args["limit"] = "100";
QNetworkReply* reply = lastfm::ws::get(args);
reply->setProperty( "requestId", requestId );
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
connect( reply, SIGNAL( finished() ), SLOT( chartTopTracksReturned() ) );
return;
}
case InfoArtistSimilars:
{
lastfm::Artist a( criteria["artist"] );
@ -447,6 +530,72 @@ LastFmPlugin::similarArtistsReturned()
emit updateCache( criteria, 2419200000, requestData.type, returnedData );
}
void
LastFmPlugin::chartTopArtistsReturned()
{
tDebug() << "LastfmPlugin: InfoChartArtists data returned!";
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
QList<lastfm::Artist> list = lastfm::Artist::list( reply );
QStringList al;
tDebug() << "\tgot " << list.size() << " artists";
foreach ( const lastfm::Artist& a, list )
al << a.toString();
QVariantMap returnedData;
returnedData["artists"] = al;
Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
emit info(
reply->property( "requestId" ).toUInt(),
requestData,
returnedData
);
Tomahawk::InfoSystem::InfoCriteriaHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash>();
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
if( origData.contains("country") )
criteria["country"] = origData["country"];
emit updateCache( criteria, 2419200000, requestData.type, returnedData );
}
void
LastFmPlugin::chartTopTracksReturned()
{
tDebug() << "LastfmPlugin: InfoChartTracks data returned!";
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
QList<lastfm::Track> tracks = parseTrackList( reply );
QList<ArtistTrackPair> top_tracks;
foreach( const lastfm::Track &t, tracks ) {
ArtistTrackPair pair;
pair.artist = t.artist().toString();
pair.track = t.title();
top_tracks << pair;
}
tDebug() << "\tgot " << top_tracks.size() << " tracks";
QVariantMap returnedData;
returnedData["tracks"] = QVariant::fromValue( top_tracks );
Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
emit info(
reply->property( "requestId" ).toUInt(),
requestData,
returnedData
);
Tomahawk::InfoSystem::InfoCriteriaHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash>();
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
if( origData.contains("country") )
criteria["country"] = origData["country"];
emit updateCache( criteria, 0, requestData.type, returnedData );
}
void
LastFmPlugin::topTracksReturned()
@ -468,7 +617,7 @@ LastFmPlugin::topTracksReturned()
Tomahawk::InfoSystem::InfoCriteriaHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash>();
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
criteria["artist"] = origData["artist"];
emit updateCache( criteria, 2419200000, requestData.type, returnedData );
emit updateCache( criteria, 0, requestData.type, returnedData );
}
@ -675,3 +824,21 @@ LastFmPlugin::createScrobbler()
}
}
QList<lastfm::Track>
LastFmPlugin::parseTrackList( QNetworkReply * reply )
{
QList<lastfm::Track> tracks;
try {
lastfm::XmlQuery lfm = lastfm::ws::parse(reply);
foreach (lastfm::XmlQuery xq, lfm.children( "track" )) {
tracks.append( lastfm::Track( xq ) );
}
}
catch (lastfm::ws::ParseError& e)
{
qWarning() << e.what();
}
return tracks;
}

View File

@ -52,6 +52,8 @@ public slots:
void artistImagesReturned();
void similarArtistsReturned();
void topTracksReturned();
void chartTopArtistsReturned();
void chartTopTracksReturned();
void namChangedSlot( QNetworkAccessManager *nam );
@ -66,6 +68,8 @@ private:
void fetchArtistImages( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
void fetchSimilarArtists( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
void fetchTopTracks( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
void fetchChartArtists( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
void fetchChartTracks( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
void createScrobbler();
void nowPlaying( const QVariant &input );
@ -74,6 +78,8 @@ private:
void dataError( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
QList<lastfm::Track> parseTrackList( QNetworkReply * reply );
lastfm::MutableTrack m_track;
lastfm::Audioscrobbler* m_scrobbler;
QString m_pw;

View File

@ -92,6 +92,10 @@ enum InfoType { // as items are saved in cache, mark them here to not change the
InfoAlbumComposer = 48,
InfoAlbumSongs = 49,
InfoChartArtists = 50,
InfoChartAlbums = 51,
InfoChartTracks = 52,
InfoMiscTopHotttness = 60,
InfoMiscTopTerms = 61,
@ -118,6 +122,11 @@ struct InfoRequestData {
QVariantMap customData;
};
struct ArtistTrackPair {
QString artist;
QString track;
};
typedef QMap< InfoType, QVariant > InfoTypeMap;
typedef QMap< InfoType, uint > InfoTimeoutMap;
typedef QMap< QString, QMap< QString, QString > > InfoGenericMap;
@ -254,5 +263,7 @@ Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoRequestData );
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoGenericMap );
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoCriteriaHash );
Q_DECLARE_METATYPE( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > );
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::ArtistTrackPair );
Q_DECLARE_METATYPE( QList<Tomahawk::InfoSystem::ArtistTrackPair> );
#endif // TOMAHAWK_INFOSYSTEM_H

View File

@ -0,0 +1,151 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Casey Link <unnamedrambler@gmail.com>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stylehelper.h"
#include <QPainter>
#include <QPixmapCache>
#include <QApplication>
QColor StyleHelper::headerUpperColor()
{
return QColor( 80, 80, 80 );
}
QColor StyleHelper::headerLowerColor()
{
return QColor( 72, 72, 72 );
}
QColor StyleHelper::headerHighlightColor()
{
return QColor( "#333" );
}
void StyleHelper::horizontalHeader(QPainter *painter, const QRect &r)
{
QRect upperHalf( 0, 0, r.width(), r.height() / 2 );
QRect lowerHalf( 0, upperHalf.height(), r.width(), r.height() );
painter->fillRect( upperHalf, StyleHelper::headerUpperColor() );
painter->fillRect( lowerHalf, StyleHelper::headerLowerColor() );
{
QColor lineColor( 100, 100, 100 );
QLine line( 0, 0, r.width(), 0 );
painter->setPen( lineColor );
painter->drawLine( line );
}
{
QColor lineColor( 30, 30, 30 );
QLine line( 0, r.height() - 1, r.width(), r.height() - 1 );
painter->setPen( lineColor );
painter->drawLine( line );
}
}
QColor StyleHelper::headerTextColor()
{
return Qt::white;
}
/*
* This implementation is from QWindowsStyle (Qt 7.2)
*
* It is licensed under the GPL 3:
* Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
* Contact: Nokia Corporation (qt-info@nokia.com)
*/
void StyleHelper::drawArrow(QStyle::PrimitiveElement element, QPainter *p, const QStyleOption *opt)
{
if (opt->rect.width() <= 1 || opt->rect.height() <= 1)
return;
QRect r = opt->rect;
int size = qMin(r.height(), r.width());
QPixmap pixmap;
QString pixmapName;
pixmapName.sprintf("arrow-%s-%d-%d-%d-%lld",
"$qt_ia",
uint(opt->state), element,
size, opt->palette.cacheKey());
if (!QPixmapCache::find(pixmapName, pixmap)) {
int border = size/5;
int sqsize = 2*(size/2);
QImage image(sqsize, sqsize, QImage::Format_ARGB32);
image.fill(0);
QPainter imagePainter(&image);
imagePainter.setRenderHint(QPainter::Antialiasing, true);
QPolygon a;
switch (element) {
case QStyle::PE_IndicatorArrowUp:
a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2);
break;
case QStyle::PE_IndicatorArrowDown:
a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2);
break;
case QStyle::PE_IndicatorArrowRight:
a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border);
break;
case QStyle::PE_IndicatorArrowLeft:
a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border);
break;
default:
break;
}
int bsx = 0;
int bsy = 0;
if (opt->state & QStyle::State_Sunken) {
bsx = qApp->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal);
bsy = qApp->style()->pixelMetric(QStyle::PM_ButtonShiftVertical);
}
QRect bounds = a.boundingRect();
int sx = sqsize / 2 - bounds.center().x() - 1;
int sy = sqsize / 2 - bounds.center().y() - 1;
imagePainter.translate(sx + bsx, sy + bsy);
imagePainter.setPen(opt->palette.buttonText().color());
imagePainter.setBrush(opt->palette.buttonText());
if (!(opt->state & QStyle::State_Enabled)) {
QColor foreGround(150, 150, 150, 150);
imagePainter.setBrush(opt->palette.mid().color());
imagePainter.setPen(opt->palette.mid().color());
} else {
QColor shadow(0, 0, 0, 100);
imagePainter.translate(0, 1);
imagePainter.setPen(shadow);
imagePainter.setBrush(shadow);
QColor foreGround(255, 255, 255, 210);
imagePainter.drawPolygon(a);
imagePainter.translate(0, -1);
imagePainter.setPen(foreGround);
imagePainter.setBrush(foreGround);
}
imagePainter.drawPolygon(a);
imagePainter.end();
pixmap = QPixmap::fromImage(image);
QPixmapCache::insert(pixmapName, pixmap);
}
int xOffset = r.x() + (r.width() - size)/2;
int yOffset = r.y() + (r.height() - size)/2;
p->drawPixmap(xOffset, yOffset, pixmap);
}

View File

@ -0,0 +1,46 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Casey Link <unnamedrambler@gmail.com>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STYLEHELPER_H
#define STYLEHELPER_H
#include <QColor>
#include <QStyle>
#include <QStyleOption>
class QPalette;
class QPainter;
class StyleHelper
{
public:
static QColor headerUpperColor();
static QColor headerLowerColor();
static QColor headerTextColor();
static QColor headerHighlightColor();
static void horizontalHeader(QPainter *painter, const QRect &rect);
static void drawArrow(QStyle::PrimitiveElement, QPainter *painter, const QStyleOption *opt);
private:
static QColor m_baseColor;
static QColor m_requestedBaseColor;
};
#endif // STYLEHELPER_H

View File

@ -44,6 +44,7 @@
#include "dynamic/widgets/DynamicWidget.h"
#include "widgets/welcomewidget.h"
#include "widgets/whatshotwidget.h"
#include "widgets/infowidgets/sourceinfowidget.h"
#include "widgets/infowidgets/ArtistInfoWidget.h"
#include "widgets/infowidgets/AlbumInfoWidget.h"
@ -69,6 +70,7 @@ ViewManager::ViewManager( QObject* parent )
: QObject( parent )
, m_widget( new QWidget() )
, m_welcomeWidget( new WelcomeWidget() )
, m_whatsHotWidget( new WhatsHotWidget() )
, m_currentMode( PlaylistInterface::Tree )
{
s_instance = this;
@ -439,6 +441,13 @@ ViewManager::showWelcomePage()
return show( m_welcomeWidget );
}
Tomahawk::ViewPage*
ViewManager::showWhatsHotPage()
{
return show( m_whatsHotWidget );
}
void
ViewManager::setTableMode()

View File

@ -27,6 +27,7 @@
#include "playlistinterface.h"
#include "viewpage.h"
#include "widgets/welcomewidget.h"
#include "widgets/whatshotwidget.h"
#include "dllmacro.h"
@ -51,6 +52,7 @@ class SourceInfoWidget;
class InfoBar;
class TopBar;
class WelcomeWidget;
class WhatsHotWidget;
class QPushButton;
namespace Tomahawk
@ -82,6 +84,7 @@ public:
Tomahawk::ViewPage* show( Tomahawk::ViewPage* page );
Tomahawk::ViewPage* welcomeWidget() const { return m_welcomeWidget; }
Tomahawk::ViewPage* whatsHotWidget() const { return m_whatsHotWidget; }
ArtistView* superCollectionView() const { return m_superCollectionView; }
/// Get the view page for the given item. Not pretty...
@ -120,6 +123,7 @@ signals:
public slots:
Tomahawk::ViewPage* showSuperCollection();
Tomahawk::ViewPage* showWelcomePage();
Tomahawk::ViewPage* showWhatsHotPage();
void showCurrentTrack();
// Returns the shown viewpage
@ -181,6 +185,7 @@ private:
TreeModel* m_superCollectionModel;
ArtistView* m_superCollectionView;
WelcomeWidget* m_welcomeWidget;
WhatsHotWidget* m_whatsHotWidget;
QList< Tomahawk::collection_ptr > m_superCollections;

View File

@ -21,6 +21,7 @@
#include <QPainter>
#include "utils/logger.h"
#include "utils/stylehelper.h"
#define FONT_SIZE 16
@ -55,29 +56,10 @@ HeaderLabel::paintEvent( QPaintEvent* /* event */ )
{
QPainter p( this );
QRect r = contentsRect();
// p.setRenderHint( QPainter::Antialiasing );
QRect upperHalf( 0, 0, r.width(), r.height() / 2 );
QRect lowerHalf( 0, upperHalf.height(), r.width(), r.height() );
p.fillRect( upperHalf, QColor( 80, 80, 80 ) );
p.fillRect( lowerHalf, QColor( 72, 72, 72 ) );
{
QColor lineColor( 100, 100, 100 );
QLine line( 0, 0, r.width(), 0 );
p.setPen( lineColor );
p.drawLine( line );
}
{
QColor lineColor( 30, 30, 30 );
QLine line( 0, r.height() - 1, r.width(), r.height() - 1 );
p.setPen( lineColor );
p.drawLine( line );
}
StyleHelper::horizontalHeader(&p, r);
QTextOption to( Qt::AlignVCenter );
r.adjust( 8, 0, -8, 0 );
p.setPen( Qt::white );
p.setPen( StyleHelper::headerTextColor() );
p.drawText( r, text(), to );
}

View File

@ -0,0 +1,42 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Casey Link <unnamedrambler@gmail.com>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "HeaderWidget.h"
#include "utils/stylehelper.h"
#include <QStyle>
#include <QStylePainter>
#include <QStyleOption>
HeaderWidget::HeaderWidget(QWidget *parent) : QWidget(parent)
{
}
HeaderWidget::~HeaderWidget()
{
}
void HeaderWidget::paintEvent(QPaintEvent *e)
{
QStylePainter p(this);
QRect r = e->rect();
StyleHelper::horizontalHeader(&p, r);
}

View File

@ -0,0 +1,45 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Casey Link <unnamedrambler@gmail.com>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef HEADERWIDGET_H
#define HEADERWIDGET_H
#include <QWidget>
#include <QPaintEvent>
#include "dllmacro.h"
class DLLEXPORT HeaderWidget : public QWidget
{
Q_OBJECT
public:
HeaderWidget(QWidget *parent = 0);
virtual ~HeaderWidget();
virtual void paintEvent(QPaintEvent *);
private:
};
#endif

View File

@ -0,0 +1,79 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Casey Link <unnamedrambler@gmail.com>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "combobox.h"
#include "utils/stylehelper.h"
#include <QStyle>
#include <QTextOption>
#include <QStylePainter>
#include <QStyleOptionComboBox>
ComboBox::ComboBox(QWidget *parent) : QComboBox(parent)
{
}
ComboBox::~ComboBox()
{
}
void ComboBox::paintEvent(QPaintEvent *)
{
QStylePainter p(this);
p.setPen(palette().color(QPalette::Text));
QStyleOptionComboBox cb;
initStyleOption(&cb);
QRect r = cb.rect;
StyleHelper::horizontalHeader(&p, r);
if( cb.state & QStyle::State_MouseOver ) {
QRect highlightRect(r);
QSize shrink(3,4);
QSize hS(highlightRect.size());
hS -= shrink;
highlightRect.setSize(hS);
highlightRect.translate(0,2);
p.save();
p.setRenderHint(QPainter::Antialiasing);
p.setBrush( StyleHelper::headerHighlightColor() );
p.drawRoundedRect(highlightRect, 10.0, 10.0);
p.restore();
}
QTextOption to( Qt::AlignVCenter );
r.adjust( 8, 0, -8, 0 );
p.setPen( Qt::white );
p.setBrush( StyleHelper::headerTextColor() );
p.drawText( r, cb.currentText, to );
bool reverse = cb.direction == Qt::RightToLeft;
int menuButtonWidth = 12;
int left = !reverse ? r.right() - menuButtonWidth : r.left();
int right = !reverse ? r.right() : r.left() + menuButtonWidth;
QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), r.center().y() - 3, 9, 9);
QStyleOption arrowOpt = cb;
arrowOpt.rect = arrowRect;
StyleHelper::drawArrow(QStyle::PE_IndicatorArrowDown, &p, &arrowOpt);
}

View File

@ -0,0 +1,44 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Casey Link <unnamedrambler@gmail.com>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef COMBOBOX_H
#define COMBOBOX_H
#include <QComboBox>
#include <QPaintEvent>
#include "dllmacro.h"
class DLLEXPORT ComboBox : public QComboBox
{
Q_OBJECT
public:
ComboBox(QWidget *parent = 0);
virtual ~ComboBox();
virtual void paintEvent(QPaintEvent *);
private:
};
#endif

View File

@ -0,0 +1,193 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "whatshotwidget.h"
#include "ui_whatshotwidget.h"
#include <QPainter>
#include "viewmanager.h"
#include "sourcelist.h"
#include "tomahawksettings.h"
#include "RecentPlaylistsModel.h"
#include "audio/audioengine.h"
#include "playlist/playlistmodel.h"
#include "playlist/treeproxymodel.h"
#include "widgets/overlaywidget.h"
#include "utils/tomahawkutils.h"
#include "utils/logger.h"
#include <dynamic/GeneratorInterface.h>
#define HISTORY_TRACK_ITEMS 25
#define HISTORY_PLAYLIST_ITEMS 10
#define HISTORY_RESOLVING_TIMEOUT 2500
using namespace Tomahawk;
static QString s_whatsHotIdentifier = QString( "WhatsHotWidget" );
WhatsHotWidget::WhatsHotWidget( QWidget* parent )
: QWidget( parent )
, ui( new Ui::WhatsHotWidget )
{
ui->setupUi( this );
TomahawkUtils::unmarginLayout( layout() );
TomahawkUtils::unmarginLayout( ui->verticalLayout->layout() );
TomahawkUtils::unmarginLayout( ui->verticalLayout_2->layout() );
TomahawkUtils::unmarginLayout( ui->horizontalLayout->layout() );
TomahawkUtils::unmarginLayout( ui->horizontalLayout_3->layout() );
m_tracksModel = new PlaylistModel( ui->tracksView );
m_tracksModel->setStyle( TrackModel::Short );
ui->tracksView->setFrameShape( QFrame::NoFrame );
ui->tracksView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
ui->tracksView->overlay()->setEnabled( false );
ui->tracksView->setTrackModel( m_tracksModel );
ui->tracksView->setHeaderHidden( true );
ui->tracksView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
m_artistsModel = new TreeModel( ui->artistsView );
m_artistsModel->setColumnStyle( TreeModel::TrackOnly );
m_artistsProxy = new TreeProxyModel( ui->artistsView );
m_artistsProxy->setFilterCaseSensitivity( Qt::CaseInsensitive );
m_artistsProxy->setDynamicSortFilter( true );
ui->artistsView->setProxyModel( m_artistsProxy );
ui->artistsView->setTreeModel( m_artistsModel );
ui->artistsView->setFrameShape( QFrame::NoFrame );
ui->artistsView->setAttribute( Qt::WA_MacShowFocusRect, 0 );
m_artistsProxy->sort( -1 ); // disable sorting, must be called after artistsView->setTreeModel
ui->artistsView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
ui->artistsView->header()->setVisible( false );
m_timer = new QTimer( this );
connect( m_timer, SIGNAL( timeout() ), SLOT( checkQueries() ) );
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );
connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
Tomahawk::InfoSystem::InfoCriteriaHash artistInfo;
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = s_whatsHotIdentifier;
requestData.customData = QVariantMap();
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( artistInfo );
requestData.type = Tomahawk::InfoSystem::InfoChartArtists;
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
requestData.type = Tomahawk::InfoSystem::InfoChartTracks;
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
tDebug() << "WhatsHot: requested InfoChartArtists+Tracks";
}
WhatsHotWidget::~WhatsHotWidget()
{
delete ui;
}
void
WhatsHotWidget::checkQueries()
{
m_timer->stop();
m_tracksModel->ensureResolved();
}
void
WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
{
if ( requestData.caller != s_whatsHotIdentifier )
{
// tDebug() << "Info of wrong type or not with our identifier";
return;
}
tDebug() << "WhatsHot: got something...";
QVariantMap returnedData = output.value< QVariantMap >();
switch ( requestData.type )
{
case InfoSystem::InfoChartArtists:
{
const QStringList artists = returnedData["artists"].toStringList();
tDebug() << "WhatsHot: got artists! " << artists.size();
tDebug() << artists;
foreach ( const QString& artist, artists )
{
m_artistsModel->addArtists( Artist::get( artist ) );
}
break;
}
case InfoSystem::InfoChartTracks:
{
const QList<Tomahawk::InfoSystem::ArtistTrackPair> tracks = returnedData["tracks"].value<QList<Tomahawk::InfoSystem::ArtistTrackPair> >();
tDebug() << "WhatsHot: got tracks! " << tracks.size();
foreach ( const Tomahawk::InfoSystem::ArtistTrackPair& track, tracks )
{
query_ptr query = Query::get( track.artist, track.track, QString(), uuid() );
m_tracksModel->append( query );
}
break;
}
default:
return;
}
}
void
WhatsHotWidget::infoSystemFinished( QString target )
{
Q_UNUSED( target );
}
void
WhatsHotWidget::changeEvent( QEvent* e )
{
QWidget::changeEvent( e );
switch ( e->type() )
{
case QEvent::LanguageChange:
ui->retranslateUi( this );
break;
default:
break;
}
}

View File

@ -0,0 +1,88 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Tomahawk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WHATSHOTWIDGET_H
#define WHATSHOTWIDGET_H
#include <QWidget>
#include <QListWidgetItem>
#include <QStyledItemDelegate>
#include "playlistinterface.h"
#include "infosystem/infosystem.h"
#include "playlist.h"
#include "result.h"
#include "viewpage.h"
#include "utils/tomahawkutils.h"
#include "dllmacro.h"
class TreeModel;
class PlaylistModel;
class OverlayWidget;
class TreeProxyModel;
namespace Ui
{
class WhatsHotWidget;
}
class DLLEXPORT WhatsHotWidget : public QWidget, public Tomahawk::ViewPage
{
Q_OBJECT
public:
WhatsHotWidget( QWidget* parent = 0 );
~WhatsHotWidget();
virtual QWidget* widget() { return this; }
virtual Tomahawk::PlaylistInterface* playlistInterface() const { return 0; }
virtual QString title() const { return tr( "Charts" ); }
virtual QString description() const { return QString(); }
virtual bool showStatsBar() const { return false; }
virtual bool showInfoBar() const { return false; }
virtual bool jumpToCurrentTrack() { return false; }
protected:
void changeEvent( QEvent* e );
signals:
void destroyed( QWidget* widget );
public slots:
private slots:
void checkQueries();
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
void infoSystemFinished( QString target );
private:
Ui::WhatsHotWidget *ui;
PlaylistModel* m_tracksModel;
TreeModel* m_artistsModel;
TreeProxyModel* m_artistsProxy;
QTimer* m_timer;
};
#endif // WHATSHOTWIDGET_H

View File

@ -0,0 +1,196 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WhatsHotWidget</class>
<widget class="QWidget" name="WhatsHotWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>875</width>
<height>513</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="HeaderWidget" name="bg1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="ComboBox" name="sourceComobLeft">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContentsOnFirstShow</enum>
</property>
<property name="iconSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<item>
<property name="text">
<string>Billboard</string>
</property>
</item>
<item>
<property name="text">
<string>Last.fm</string>
</property>
</item>
<item>
<property name="text">
<string>iTunes</string>
</property>
</item>
<item>
<property name="text">
<string/>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="ComboBox" name="typeComboLeft">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContentsOnFirstShow</enum>
</property>
<item>
<property name="text">
<string>Top 100 Tracks</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="PlaylistView" name="tracksView">
<property name="minimumSize">
<size>
<width>320</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="HeaderWidget" name="bg2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="ComboBox" name="sourceComboRight">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContentsOnFirstShow</enum>
</property>
<property name="iconSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<item>
<property name="text">
<string>Billboard</string>
</property>
</item>
<item>
<property name="text">
<string>Last.fm</string>
</property>
</item>
<item>
<property name="text">
<string>iTunes</string>
</property>
</item>
<item>
<property name="text">
<string/>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="ComboBox" name="typeComboRight">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContentsOnFirstShow</enum>
</property>
<item>
<property name="text">
<string>Top 100 Tracks</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="ArtistView" name="artistsView">
<property name="minimumSize">
<size>
<width>320</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>PlaylistView</class>
<extends>QTreeView</extends>
<header>playlist/playlistview.h</header>
</customwidget>
<customwidget>
<class>ArtistView</class>
<extends>QTreeView</extends>
<header location="global">artistview.h</header>
</customwidget>
<customwidget>
<class>ComboBox</class>
<extends>QComboBox</extends>
<header location="global">widgets/combobox.h</header>
</customwidget>
<customwidget>
<class>HeaderWidget</class>
<extends>QWidget</extends>
<header location="global">widgets/HeaderWidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -44,6 +44,7 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
, m_sourceInfoPage( 0 )
, m_coolPlaylistsPage( 0 )
, m_lovedTracksPage( 0 )
, m_whatsHotPage( 0 )
{
m_lovedTracksItem = new GenericPageItem( model(), this, ( m_source.isNull() ? tr( "Top Loved Tracks" ) : tr( "Loved Tracks" ) ), QIcon( RESPATH "images/loved_playlist.png" ),
boost::bind( &CollectionItem::lovedTracksClicked, this ),
@ -62,6 +63,13 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
);
recent->setSortValue( -300 );
GenericPageItem* hot = new GenericPageItem( model(), this, tr( "Charts" ), QIcon( RESPATH "images/charts.png" ),
boost::bind( &ViewManager::showWhatsHotPage, ViewManager::instance() ),
boost::bind( &ViewManager::whatsHotWidget, ViewManager::instance() )
);
hot->setSortValue( -300 );
// TODO finish implementing and making pretty
// m_coolPlaylistsItem = new GenericPageItem( model(), this, tr( "Cool Stuff" ), QIcon( RESPATH "images/new-additions.png" ),
// boost::bind( &CollectionItem::coolPlaylistsClicked, this ),

View File

@ -86,6 +86,7 @@ private:
Tomahawk::ViewPage* m_sourceInfoPage;
Tomahawk::ViewPage* m_coolPlaylistsPage;
Tomahawk::ViewPage* m_lovedTracksPage;
Tomahawk::ViewPage* m_whatsHotPage;
};

View File

@ -389,6 +389,8 @@ TomahawkApp::registerMetaTypes()
qRegisterMetaType< QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > >( "QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache >" );
qRegisterMetaType< DirLister::Mode >("DirLister::Mode");
qRegisterMetaType< Tomahawk::InfoSystem::ArtistTrackPair >("Tomahawk::InfoSystem::ArtistTrackPair");
qRegisterMetaType< QList<Tomahawk::InfoSystem::ArtistTrackPair> >("QList<Tomahawk::InfoSystem::ArtistTrackPair>");
qRegisterMetaType< QPersistentModelIndex >( "QPersistentModelIndex" );
}

View File

@ -51,11 +51,32 @@ lastfm::Track::Track( const QDomElement& e )
d = new TrackData;
if (e.isNull()) { d->null = true; return; }
d->artist = e.namedItem( "artist" ).toElement().text();
//TODO: not sure of lastfm's xml changed, but <track> nodes have
// <artist><name>Artist Name</name><mbid>..<url></artist>
// as children isntead of <artist>Artist Name<artist>
// we detect both here.
QDomNode artistName = e.namedItem( "artist" ).namedItem( "name" );
if( artistName.isNull() ) {
d->artist = e.namedItem( "artist" ).toElement().text();
} else {
d->artist = artistName.toElement().text();
}
d->albumArtist = e.namedItem( "albumArtist" ).toElement().text();
d->album = e.namedItem( "album" ).toElement().text();
d->title = e.namedItem( "track" ).toElement().text();
//TODO: not sure if lastfm xml's changed, or if chart.getTopTracks uses
//a different format, but the title is stored at
//<track><name>Title</name>...
//we detect both here.
QDomNode trackTitle = e.namedItem( "name" );
if( trackTitle.isNull() )
d->title = e.namedItem( "track" ).toElement().text();
else
d->title = trackTitle.toElement().text();
d->correctedArtist = e.namedItem( "correctedArtist" ).toElement().text();
d->correctedAlbumArtist = e.namedItem( "correctedAlbumArtist" ).toElement().text();
d->correctedAlbum = e.namedItem( "correctedAlbum" ).toElement().text();