mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-14 04:51:53 +02:00
add a dynamicview class
this takes care of showing errors and information for the automatic playlists and stations
This commit is contained in:
parent
1f3dd091a2
commit
f21f95a2c8
@ -95,6 +95,7 @@ set( libSources
|
||||
playlist/dynamic/DynamicControl.cpp
|
||||
playlist/dynamic/GeneratorFactory.cpp
|
||||
playlist/dynamic/GeneratorInterface.cpp
|
||||
playlist/dynamic/DynamicView.cpp
|
||||
playlist/dynamic/echonest/EchonestGenerator.cpp
|
||||
playlist/dynamic/echonest/EchonestControl.cpp
|
||||
playlist/dynamic/widgets/DynamicWidget.cpp
|
||||
@ -227,6 +228,7 @@ set( libHeaders
|
||||
playlist/dynamic/DynamicControl.h
|
||||
playlist/dynamic/GeneratorFactory.h
|
||||
playlist/dynamic/GeneratorInterface.h
|
||||
playlist/dynamic/DynamicView.h
|
||||
playlist/dynamic/echonest/EchonestGenerator.h
|
||||
playlist/dynamic/echonest/EchonestControl.h
|
||||
playlist/dynamic/widgets/DynamicWidget.h
|
||||
|
62
src/libtomahawk/playlist/dynamic/DynamicView.cpp
Normal file
62
src/libtomahawk/playlist/dynamic/DynamicView.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/****************************************************************************************
|
||||
* Copyright (c) 2011 Leo Franchi <lfranchi@kde.org> *
|
||||
* *
|
||||
* This program 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 2 of the License, or (at your option) any later *
|
||||
* version. *
|
||||
* *
|
||||
* This program 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 *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include "DynamicView.h"
|
||||
#include <QPainter>
|
||||
#include <widgets/overlaywidget.h>
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
|
||||
DynamicView::DynamicView( QWidget* parent )
|
||||
: PlaylistView( parent )
|
||||
{
|
||||
m_showTimer.setInterval( 5000 );
|
||||
m_showTimer.setSingleShot( true );
|
||||
|
||||
m_fadeOut = new QPropertyAnimation( overlay(), "opacity" );
|
||||
m_fadeOut->setDuration( 500 );
|
||||
m_fadeOut->setEndValue( 0 );
|
||||
|
||||
connect( &m_showTimer, SIGNAL( timeout() ), m_fadeOut, SLOT( start() ) );
|
||||
|
||||
}
|
||||
|
||||
DynamicView::~DynamicView()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
DynamicView::showMessageTimeout( const QString& title, const QString& body )
|
||||
{
|
||||
m_title = title;
|
||||
m_body = body;
|
||||
m_showTimer.start();
|
||||
}
|
||||
|
||||
void
|
||||
DynamicView::paintEvent( QPaintEvent* event )
|
||||
{
|
||||
if ( m_showTimer.isActive() || m_fadeOut->state() == QPropertyAnimation::Running )
|
||||
{
|
||||
QPainter painter( viewport() );
|
||||
overlay()->setText( QString( "%1\n%2" ).arg( m_title, m_body ) );
|
||||
overlay()->paint( &painter );
|
||||
} else {
|
||||
PlaylistView::paintEvent( event );
|
||||
}
|
||||
}
|
51
src/libtomahawk/playlist/dynamic/DynamicView.h
Normal file
51
src/libtomahawk/playlist/dynamic/DynamicView.h
Normal file
@ -0,0 +1,51 @@
|
||||
/****************************************************************************************
|
||||
* Copyright (c) 2011 Leo Franchi <lfranchi@kde.org> *
|
||||
* *
|
||||
* This program 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 2 of the License, or (at your option) any later *
|
||||
* version. *
|
||||
* *
|
||||
* This program 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 *
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef DYNAMIC_VIEW_H
|
||||
#define DYNAMIC_VIEW_H
|
||||
|
||||
#include "playlist/playlistview.h"
|
||||
#include <QTimer>
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
|
||||
class DynamicView : public PlaylistView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DynamicView( QWidget* parent = 0 );
|
||||
virtual ~DynamicView();
|
||||
|
||||
public slots:
|
||||
void showMessageTimeout( const QString& title, const QString& body );
|
||||
|
||||
protected:
|
||||
virtual void paintEvent( QPaintEvent* event );
|
||||
|
||||
private:
|
||||
QTimer m_showTimer;
|
||||
QPropertyAnimation* m_fadeOut;
|
||||
|
||||
QString m_title;
|
||||
QString m_body;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -94,8 +94,7 @@ public:
|
||||
void removeControl( const dyncontrol_ptr& control );
|
||||
|
||||
signals:
|
||||
void controlsInvalid( const QString& shortTitle, const QString& message );
|
||||
void onDemandFailed();
|
||||
void error( const QString& title, const QString& body);
|
||||
void generated( const QList< Tomahawk::query_ptr>& queries );
|
||||
void nextTrackGenerated( const Tomahawk::query_ptr& track );
|
||||
|
||||
|
@ -85,7 +85,7 @@ EchonestGenerator::generate ( int number )
|
||||
connect( reply, SIGNAL( finished() ), this, SLOT( staticFinished() ) );
|
||||
} catch( std::runtime_error& e ) {
|
||||
qWarning() << "Got invalid controls!" << e.what();
|
||||
emit controlsInvalid( "Controls were not valid", QString::fromLatin1( e.what() ) );
|
||||
emit error( "Filters are not valid", e.what() );
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ EchonestGenerator::startOnDemand()
|
||||
connect( reply, SIGNAL( finished() ), this, SLOT( dynamicStarted() ) );
|
||||
} catch( std::runtime_error& e ) {
|
||||
qWarning() << "Got invalid controls!" << e.what();
|
||||
emit controlsInvalid( "Controls were not valid", QString::fromLatin1( e.what() ) );
|
||||
emit error( "Filters are not valid", e.what() );
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,8 +131,9 @@ EchonestGenerator::staticFinished()
|
||||
try {
|
||||
songs = Echonest::DynamicPlaylist::parseStaticPlaylist( reply );
|
||||
} catch( const Echonest::ParseError& e ) {
|
||||
qWarning() << "libechonest threw an error trying to parse the static playlist!" << e.errorType() << e.what();
|
||||
qWarning() << "libechonest threw an error trying to parse the static playlist! code" << e.errorType() << "error desc:" << e.what();
|
||||
|
||||
emit error( "The Echo Nest returned an error creating the playlist", e.what() );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -170,7 +171,7 @@ EchonestGenerator::dynamicStarted()
|
||||
emit nextTrackGenerated( songQuery );
|
||||
} catch( const Echonest::ParseError& e ) {
|
||||
qWarning() << "libechonest threw an error parsing the start of the dynamic playlist:" << e.errorType() << e.what();
|
||||
emit onDemandFailed();
|
||||
emit error( "The Echo Nest returned an error starting the station", e.what() );
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,6 +189,7 @@ EchonestGenerator::dynamicFetched()
|
||||
emit nextTrackGenerated( songQuery );
|
||||
} catch( const Echonest::ParseError& e ) {
|
||||
qWarning() << "libechonest threw an error parsing the next song of the dynamic playlist:" << e.errorType() << e.what();
|
||||
emit error( "The Echo Nest returned an error getting the next song", e.what() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "ReadOrWriteWidget.h"
|
||||
#include "CollapsibleControls.h"
|
||||
#include "DynamicControlWrapper.h"
|
||||
#include "dynamic/DynamicView.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@ -86,7 +87,7 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
|
||||
m_layout->addWidget( m_controls );
|
||||
|
||||
m_model = new PlaylistModel( this );
|
||||
m_view = new PlaylistView( this );
|
||||
m_view = new DynamicView( this );
|
||||
m_view->setModel( m_model );
|
||||
m_view->setContentsMargins( 0, 0, 0, 0 );
|
||||
m_layout->addWidget( m_view );
|
||||
@ -125,6 +126,7 @@ DynamicWidget::loadDynamicPlaylist( const Tomahawk::dynplaylist_ptr& playlist )
|
||||
disconnect( m_playlist->generator().data(), SIGNAL( generated( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksGenerated( QList<Tomahawk::query_ptr> ) ) );
|
||||
disconnect( m_playlist.data(), SIGNAL( dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision) ), this, SLOT(onRevisionLoaded( Tomahawk::DynamicPlaylistRevision) ) );
|
||||
disconnect( m_playlist->generator().data(), SIGNAL( nextTrackGenerated( Tomahawk::query_ptr ) ), this, SLOT( onDemandFetched( Tomahawk::query_ptr ) ) );
|
||||
disconnect( m_playlist->generator().data(), SIGNAL( error( QString, QString ) ), m_view, SLOT( showMessageTimeout( QString, QString ) ) );
|
||||
}
|
||||
|
||||
m_playlist = playlist;
|
||||
@ -140,6 +142,7 @@ DynamicWidget::loadDynamicPlaylist( const Tomahawk::dynplaylist_ptr& playlist )
|
||||
connect( m_playlist->generator().data(), SIGNAL( generated( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksGenerated( QList<Tomahawk::query_ptr> ) ) );
|
||||
connect( m_playlist.data(), SIGNAL( dynamicRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ), this, SLOT( onRevisionLoaded( Tomahawk::DynamicPlaylistRevision ) ) );
|
||||
connect( m_playlist->generator().data(), SIGNAL( nextTrackGenerated( Tomahawk::query_ptr ) ), this, SLOT( onDemandFetched( Tomahawk::query_ptr ) ) );
|
||||
connect( m_playlist->generator().data(), SIGNAL( error( QString, QString ) ), m_view, SLOT( showMessageTimeout( QString, QString ) ) );
|
||||
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,9 @@ class ReadOrWriteWidget;
|
||||
namespace Tomahawk
|
||||
{
|
||||
|
||||
class DynamicView;
|
||||
|
||||
|
||||
class CollapsibleControls;
|
||||
|
||||
|
||||
@ -93,7 +96,7 @@ private:
|
||||
|
||||
CollapsibleControls* m_controls;
|
||||
|
||||
PlaylistView* m_view;
|
||||
DynamicView* m_view;
|
||||
PlaylistModel* m_model;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user