mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
work on multiple updaters
This commit is contained in:
@@ -123,8 +123,18 @@ SpotifyAccount::aboutToShow( QAction* action, const playlist_ptr& playlist )
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// If it's not being synced, allow the option to sync
|
// If it's not being synced, allow the option to sync
|
||||||
SpotifyPlaylistUpdater* updater = qobject_cast< SpotifyPlaylistUpdater* >( playlist->updater() );
|
bool found = false;
|
||||||
if ( !updater || !updater->sync() )
|
SmartPointerList<PlaylistUpdaterInterface> updaters = playlist->updaters();
|
||||||
|
foreach ( PlaylistUpdaterInterface* updater, updaters )
|
||||||
|
{
|
||||||
|
if ( SpotifyPlaylistUpdater* spotifyUpdater = qobject_cast< SpotifyPlaylistUpdater* >( updater ) )
|
||||||
|
{
|
||||||
|
if ( spotifyUpdater->sync() )
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !found )
|
||||||
{
|
{
|
||||||
action->setText( tr( "Sync with Spotify" ) );
|
action->setText( tr( "Sync with Spotify" ) );
|
||||||
}
|
}
|
||||||
@@ -152,7 +162,15 @@ SpotifyAccount::syncActionTriggered( bool checked )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpotifyPlaylistUpdater* updater = qobject_cast< SpotifyPlaylistUpdater* >( playlist->updater() );
|
SpotifyPlaylistUpdater* updater = 0;
|
||||||
|
SmartPointerList<PlaylistUpdaterInterface> updaters = playlist->updaters();
|
||||||
|
foreach ( PlaylistUpdaterInterface* u, updaters )
|
||||||
|
{
|
||||||
|
if ( SpotifyPlaylistUpdater* spotifyUpdater = qobject_cast< SpotifyPlaylistUpdater* >( u ) )
|
||||||
|
{
|
||||||
|
updater = spotifyUpdater;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( !updater )
|
if ( !updater )
|
||||||
{
|
{
|
||||||
|
@@ -270,8 +270,11 @@ void
|
|||||||
Playlist::reportDeleted( const Tomahawk::playlist_ptr& self )
|
Playlist::reportDeleted( const Tomahawk::playlist_ptr& self )
|
||||||
{
|
{
|
||||||
Q_ASSERT( self.data() == this );
|
Q_ASSERT( self.data() == this );
|
||||||
if ( !m_updater.isNull() )
|
if ( !m_updaters.isEmpty() )
|
||||||
m_updater.data()->remove();
|
{
|
||||||
|
foreach( PlaylistUpdaterInterface* updater, m_updaters )
|
||||||
|
updater->remove();
|
||||||
|
}
|
||||||
|
|
||||||
m_deleted = true;
|
m_deleted = true;
|
||||||
m_source->collection()->deletePlaylist( self );
|
m_source->collection()->deletePlaylist( self );
|
||||||
@@ -280,25 +283,24 @@ Playlist::reportDeleted( const Tomahawk::playlist_ptr& self )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Playlist::setUpdater( PlaylistUpdaterInterface* pluinterface )
|
Playlist::addUpdater( PlaylistUpdaterInterface* updater )
|
||||||
{
|
{
|
||||||
if ( !m_updater.isNull() )
|
m_updaters << updater;
|
||||||
disconnect( m_updater.data(), SIGNAL( changed() ), this, SIGNAL( changed() ) );
|
|
||||||
|
|
||||||
m_updater = QWeakPointer< PlaylistUpdaterInterface >( pluinterface );
|
connect( updater, SIGNAL( changed() ), this, SIGNAL( changed() ), Qt::UniqueConnection );
|
||||||
|
connect( updater, SIGNAL( destroyed( QObject* ) ), this, SIGNAL( changed() ), Qt::QueuedConnection );
|
||||||
connect( m_updater.data(), SIGNAL( changed() ), this, SIGNAL( changed() ), Qt::UniqueConnection );
|
|
||||||
connect( m_updater.data(), SIGNAL( destroyed( QObject* ) ), this, SLOT( updaterDestroyed() ), Qt::QueuedConnection );
|
|
||||||
|
|
||||||
emit changed();
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Playlist::updaterDestroyed()
|
Playlist::removeUpdater( PlaylistUpdaterInterface* updater )
|
||||||
{
|
{
|
||||||
m_updater.clear();
|
m_updaters.removeAll( updater );
|
||||||
emit changed();
|
|
||||||
|
disconnect( updater, SIGNAL( changed() ), this, SIGNAL( changed() ) );
|
||||||
|
disconnect( updater, SIGNAL( destroyed( QObject* ) ), this, SIGNAL( changed() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -34,6 +34,7 @@
|
|||||||
#include "Query.h"
|
#include "Query.h"
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
#include "utils/SmartPointerList.h"
|
||||||
|
|
||||||
class DatabaseCommand_LoadAllPlaylists;
|
class DatabaseCommand_LoadAllPlaylists;
|
||||||
class DatabaseCommand_LoadAllSortedPlaylists;
|
class DatabaseCommand_LoadAllSortedPlaylists;
|
||||||
@@ -188,8 +189,10 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
QList<plentry_ptr> entriesFromQueries( const QList<Tomahawk::query_ptr>& queries, bool clearFirst = false );
|
QList<plentry_ptr> entriesFromQueries( const QList<Tomahawk::query_ptr>& queries, bool clearFirst = false );
|
||||||
void setUpdater( PlaylistUpdaterInterface* pluinterface );
|
|
||||||
PlaylistUpdaterInterface* updater() const { return m_updater.data(); }
|
void addUpdater( PlaylistUpdaterInterface* updater );
|
||||||
|
void removeUpdater( PlaylistUpdaterInterface* updater );
|
||||||
|
SmartPointerList<PlaylistUpdaterInterface> updaters() const { return m_updaters; }
|
||||||
|
|
||||||
Tomahawk::playlistinterface_ptr playlistInterface();
|
Tomahawk::playlistinterface_ptr playlistInterface();
|
||||||
|
|
||||||
@@ -278,7 +281,6 @@ protected:
|
|||||||
private slots:
|
private slots:
|
||||||
void onResultsFound( const QList<Tomahawk::result_ptr>& results );
|
void onResultsFound( const QList<Tomahawk::result_ptr>& results );
|
||||||
void onResolvingFinished();
|
void onResolvingFinished();
|
||||||
void updaterDestroyed();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Playlist();
|
Playlist();
|
||||||
@@ -300,7 +302,7 @@ private:
|
|||||||
QQueue<RevisionQueueItem> m_revisionQueue;
|
QQueue<RevisionQueueItem> m_revisionQueue;
|
||||||
QQueue<RevisionQueueItem> m_updateQueue;
|
QQueue<RevisionQueueItem> m_updateQueue;
|
||||||
|
|
||||||
QWeakPointer<PlaylistUpdaterInterface> m_updater;
|
SmartPointerList<PlaylistUpdaterInterface> m_updaters;
|
||||||
|
|
||||||
bool m_locallyChanged;
|
bool m_locallyChanged;
|
||||||
bool m_deleted;
|
bool m_deleted;
|
||||||
|
@@ -30,11 +30,51 @@
|
|||||||
|
|
||||||
#include "database/DatabaseCommand_UpdateSearchIndex.h"
|
#include "database/DatabaseCommand_UpdateSearchIndex.h"
|
||||||
#include "database/Database.h"
|
#include "database/Database.h"
|
||||||
|
#include "PlaylistUpdaterInterface.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
TomahawkSettings* TomahawkSettings::s_instance = 0;
|
TomahawkSettings* TomahawkSettings::s_instance = 0;
|
||||||
|
|
||||||
|
|
||||||
|
inline QDataStream&
|
||||||
|
operator<<(QDataStream& out, const PlaylistUpdaterInterface::SerializedUpdaters& updaters)
|
||||||
|
{
|
||||||
|
out << TOMAHAWK_SETTINGS_VERSION;
|
||||||
|
out << (quint32)updaters.count();
|
||||||
|
foreach( const QString& key, updaters.keys() )
|
||||||
|
{
|
||||||
|
PlaylistUpdaterInterface::SerializedUpdater updater = updaters[ key ];
|
||||||
|
out << key << updater.type << updater.sync << updater.customData;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline QDataStream&
|
||||||
|
operator>>(QDataStream& in, PlaylistUpdaterInterface::SerializedUpdaters& updaters)
|
||||||
|
{
|
||||||
|
quint32 count = 0, version = 0;
|
||||||
|
in >> version;
|
||||||
|
in >> count;
|
||||||
|
|
||||||
|
for ( uint i = 0; i < count; i++ )
|
||||||
|
{
|
||||||
|
QString key, type;
|
||||||
|
bool sync;
|
||||||
|
QVariantHash customData;
|
||||||
|
qint32 state, userRating;
|
||||||
|
in >> key;
|
||||||
|
in >> type;
|
||||||
|
in >> sync;
|
||||||
|
in >> customData;
|
||||||
|
updaters[ key ] = PlaylistUpdaterInterface::SerializedUpdater( type, sync, customData );
|
||||||
|
}
|
||||||
|
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TomahawkSettings*
|
TomahawkSettings*
|
||||||
TomahawkSettings::instance()
|
TomahawkSettings::instance()
|
||||||
{
|
{
|
||||||
@@ -444,6 +484,11 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion )
|
|||||||
setValue( "allaccounts", allAccounts );
|
setValue( "allaccounts", allAccounts );
|
||||||
endGroup();
|
endGroup();
|
||||||
}
|
}
|
||||||
|
else if ( oldVersion == 9 )
|
||||||
|
{
|
||||||
|
// Upgrade single-updater-per-playlist to list-per-playlist
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
#define TOMAHAWK_SETTINGS_VERSION 9
|
#define TOMAHAWK_SETTINGS_VERSION 10
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience wrapper around QSettings for tomahawk-specific config
|
* Convenience wrapper around QSettings for tomahawk-specific config
|
||||||
@@ -201,6 +201,8 @@ public:
|
|||||||
void setImportXspfPath( const QString& path );
|
void setImportXspfPath( const QString& path );
|
||||||
QString importXspfPath() const;
|
QString importXspfPath() const;
|
||||||
|
|
||||||
|
static void registerCustomSettingsHandlers();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed();
|
void changed();
|
||||||
void recentlyPlayedPlaylistAdded( const Tomahawk::playlist_ptr& playlist );
|
void recentlyPlayedPlaylistAdded( const Tomahawk::playlist_ptr& playlist );
|
||||||
|
@@ -23,6 +23,38 @@
|
|||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
inline QDataStream& operator<<(QDataStream& out, const AtticaManager::StateHash& states)
|
||||||
|
{
|
||||||
|
out << TOMAHAWK_SETTINGS_VERSION;
|
||||||
|
out << (quint32)states.count();
|
||||||
|
foreach( const QString& key, states.keys() )
|
||||||
|
{
|
||||||
|
AtticaManager::Resolver resolver = states[ key ];
|
||||||
|
out << key << resolver.version << resolver.scriptPath << (qint32)resolver.state << resolver.userRating;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline QDataStream& operator>>(QDataStream& in, AtticaManager::StateHash& states)
|
||||||
|
{
|
||||||
|
quint32 count = 0, version = 0;
|
||||||
|
in >> version;
|
||||||
|
in >> count;
|
||||||
|
for ( uint i = 0; i < count; i++ )
|
||||||
|
{
|
||||||
|
QString key, version, scriptPath;
|
||||||
|
qint32 state, userRating;
|
||||||
|
in >> key;
|
||||||
|
in >> version;
|
||||||
|
in >> scriptPath;
|
||||||
|
in >> state;
|
||||||
|
in >> userRating;
|
||||||
|
states[ key ] = AtticaManager::Resolver( version, scriptPath, userRating, (AtticaManager::ResolverState)state );
|
||||||
|
}
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
TomahawkSettingsGui*
|
TomahawkSettingsGui*
|
||||||
TomahawkSettingsGui::instanceGui()
|
TomahawkSettingsGui::instanceGui()
|
||||||
{
|
{
|
||||||
@@ -91,3 +123,11 @@ TomahawkSettingsGui::removeAtticaResolverState ( const QString& resolver )
|
|||||||
resolvers.remove( resolver );
|
resolvers.remove( resolver );
|
||||||
setValue( "script/atticaresolverstates", QVariant::fromValue< AtticaManager::StateHash >( resolvers ) );
|
setValue( "script/atticaresolverstates", QVariant::fromValue< AtticaManager::StateHash >( resolvers ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TomahawkSettingsGui::registerCustomSettingsHandlers()
|
||||||
|
{
|
||||||
|
qRegisterMetaType< AtticaManager::StateHash >( "AtticaManager::StateHash" );
|
||||||
|
qRegisterMetaTypeStreamOperators<AtticaManager::StateHash>("AtticaManager::StateHash");
|
||||||
|
}
|
||||||
|
@@ -47,6 +47,8 @@ public:
|
|||||||
|
|
||||||
void setAtticaResolverState( const QString& resolver, AtticaManager::ResolverState state );
|
void setAtticaResolverState( const QString& resolver, AtticaManager::ResolverState state );
|
||||||
void removeAtticaResolverState( const QString& resolver );
|
void removeAtticaResolverState( const QString& resolver );
|
||||||
|
|
||||||
|
static void registerCustomSettingsHandlers();
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(AtticaManager::StateHash);
|
Q_DECLARE_METATYPE(AtticaManager::StateHash);
|
||||||
|
@@ -745,7 +745,7 @@ ViewManager::updateView()
|
|||||||
m_infobar->setVisible( currentPage()->showInfoBar() );
|
m_infobar->setVisible( currentPage()->showInfoBar() );
|
||||||
m_infobar->setCaption( currentPage()->title() );
|
m_infobar->setCaption( currentPage()->title() );
|
||||||
|
|
||||||
m_infobar->setAutoUpdateInterface( currentPage()->autoUpdateInterface() );
|
m_infobar->setUpdaters( currentPage()->updaters() );
|
||||||
|
|
||||||
switch( currentPage()->descriptionType() )
|
switch( currentPage()->descriptionType() )
|
||||||
{
|
{
|
||||||
|
@@ -25,13 +25,14 @@
|
|||||||
#include "Artist.h"
|
#include "Artist.h"
|
||||||
#include "Album.h"
|
#include "Album.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
|
#include "utils/SmartPointerList.h"
|
||||||
|
#include "playlist/PlaylistUpdaterInterface.h"
|
||||||
|
|
||||||
#include <QtGui/QPixmap>
|
#include <QtGui/QPixmap>
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
|
|
||||||
class PlaylistUpdaterInterface;
|
|
||||||
|
|
||||||
class DLLEXPORT ViewPage
|
class DLLEXPORT ViewPage
|
||||||
{
|
{
|
||||||
@@ -69,8 +70,7 @@ public:
|
|||||||
virtual bool isTemporaryPage() const { return false; }
|
virtual bool isTemporaryPage() const { return false; }
|
||||||
virtual bool isBeingPlayed() const { return false; }
|
virtual bool isBeingPlayed() const { return false; }
|
||||||
|
|
||||||
virtual bool canAutoUpdate() const { return false; }
|
virtual SmartPointerList<PlaylistUpdaterInterface> updaters() const { return SmartPointerList<PlaylistUpdaterInterface>(); }
|
||||||
virtual PlaylistUpdaterInterface* autoUpdateInterface() const { return 0; }
|
|
||||||
|
|
||||||
/** subclasses implementing ViewPage can emit the following signals:
|
/** subclasses implementing ViewPage can emit the following signals:
|
||||||
* nameChanged( const QString& )
|
* nameChanged( const QString& )
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
*
|
*
|
||||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
* Copyright 2012, Leo Franchi <lfranchi@kde.org>
|
||||||
*
|
*
|
||||||
* Tomahawk is free software: you can redistribute it and/or modify
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -40,8 +41,6 @@ using namespace Tomahawk;
|
|||||||
InfoBar::InfoBar( QWidget* parent )
|
InfoBar::InfoBar( QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
, ui( new Ui::InfoBar )
|
, ui( new Ui::InfoBar )
|
||||||
, m_updaterInterface( 0 )
|
|
||||||
, m_updaterConfiguration( 0 )
|
|
||||||
, m_queryLabel( 0 )
|
, m_queryLabel( 0 )
|
||||||
{
|
{
|
||||||
ui->setupUi( this );
|
ui->setupUi( this );
|
||||||
@@ -202,21 +201,31 @@ InfoBar::setFilterAvailable( bool b )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
InfoBar::setAutoUpdateInterface( PlaylistUpdaterInterface *interface )
|
InfoBar::setUpdaters( const SmartPointerList<PlaylistUpdaterInterface>& updaters )
|
||||||
{
|
{
|
||||||
if ( m_updaterConfiguration )
|
QList< QWidget* > newUpdaterWidgets;
|
||||||
m_updaterConfiguration->hide();
|
foreach ( PlaylistUpdaterInterface* updater, updaters )
|
||||||
|
{
|
||||||
|
if ( updater->configurationWidget() )
|
||||||
|
newUpdaterWidgets << updater->configurationWidget();
|
||||||
|
}
|
||||||
|
|
||||||
if ( m_updaterConfiguration && ( interface ? (m_updaterConfiguration != interface->configurationWidget()) : true ) )
|
|
||||||
ui->horizontalLayout->removeWidget( m_updaterConfiguration );
|
|
||||||
|
|
||||||
m_updaterInterface = interface;
|
foreach ( QWidget* updaterWidget, m_updaterConfigurations )
|
||||||
m_updaterConfiguration = interface ? interface->configurationWidget() : 0;
|
{
|
||||||
|
updaterWidget->hide();
|
||||||
|
|
||||||
if ( !m_updaterInterface || !m_updaterConfiguration )
|
if ( !newUpdaterWidgets.contains( updaterWidget ) )
|
||||||
return;
|
{
|
||||||
|
// Old config widget no longer present, remove it
|
||||||
|
ui->horizontalLayout->removeWidget( updaterWidget );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_updaterConfiguration->setPalette( m_whitePal );
|
m_updaters = updaters;
|
||||||
|
m_updaterConfigurations = newUpdaterWidgets;
|
||||||
|
|
||||||
|
// Display each new widget in the proper place
|
||||||
int insertIdx = -1; // Ugh, no indexOf for QSpacerItem*
|
int insertIdx = -1; // Ugh, no indexOf for QSpacerItem*
|
||||||
for ( int i = 0; i < ui->horizontalLayout->count(); i++ )
|
for ( int i = 0; i < ui->horizontalLayout->count(); i++ )
|
||||||
{
|
{
|
||||||
@@ -227,9 +236,40 @@ InfoBar::setAutoUpdateInterface( PlaylistUpdaterInterface *interface )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
insertIdx++;
|
insertIdx++;
|
||||||
ui->horizontalLayout->insertWidget( insertIdx, m_updaterConfiguration );
|
|
||||||
|
|
||||||
m_updaterConfiguration->show();
|
foreach ( QWidget* updaterWidget, m_updaterConfigurations )
|
||||||
|
{
|
||||||
|
updaterWidget->setPalette( m_whitePal );
|
||||||
|
ui->horizontalLayout->insertWidget( insertIdx, updaterWidget );
|
||||||
|
updaterWidget->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// if ( m_updaterConfiguration )
|
||||||
|
// m_updaterConfiguration->hide();
|
||||||
|
//
|
||||||
|
// if ( m_updaterConfiguration && ( interface ? (m_updaterConfiguration != interface->configurationWidget()) : true ) )
|
||||||
|
// ui->horizontalLayout->removeWidget( m_updaterConfiguration );
|
||||||
|
//
|
||||||
|
// m_updaterInterface = interface;
|
||||||
|
// m_updaterConfiguration = interface ? interface->configurationWidget() : 0;
|
||||||
|
//
|
||||||
|
// if ( !m_updaterInterface || !m_updaterConfiguration )
|
||||||
|
// return;
|
||||||
|
//
|
||||||
|
// m_updaterConfiguration->setPalette( m_whitePal );
|
||||||
|
// int insertIdx = -1; // Ugh, no indexOf for QSpacerItem*
|
||||||
|
// for ( int i = 0; i < ui->horizontalLayout->count(); i++ )
|
||||||
|
// {
|
||||||
|
// if ( ui->horizontalLayout->itemAt( i )->spacerItem() == ui->horizontalSpacer_4 )
|
||||||
|
// {
|
||||||
|
// insertIdx = i;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// insertIdx++;
|
||||||
|
// ui->horizontalLayout->insertWidget( insertIdx, m_updaterConfiguration );
|
||||||
|
//
|
||||||
|
// m_updaterConfiguration->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
*
|
*
|
||||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
* Copyright 2012, Leo Franchi <lfranchi@kde.org>
|
||||||
*
|
*
|
||||||
* Tomahawk is free software: you can redistribute it and/or modify
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
#include "Artist.h"
|
#include "Artist.h"
|
||||||
|
#include <utils/SmartPointerList.h>
|
||||||
|
|
||||||
class QueryLabel;
|
class QueryLabel;
|
||||||
class QCheckBox;
|
class QCheckBox;
|
||||||
@@ -62,7 +64,7 @@ public slots:
|
|||||||
void setFilter( const QString& filter );
|
void setFilter( const QString& filter );
|
||||||
void setFilterAvailable( bool b );
|
void setFilterAvailable( bool b );
|
||||||
|
|
||||||
void setAutoUpdateInterface( Tomahawk::PlaylistUpdaterInterface* interface );
|
void setUpdaters( const SmartPointerList<Tomahawk::PlaylistUpdaterInterface>& updaters );
|
||||||
signals:
|
signals:
|
||||||
void filterTextChanged( const QString& filter );
|
void filterTextChanged( const QString& filter );
|
||||||
|
|
||||||
@@ -82,8 +84,8 @@ private:
|
|||||||
QPixmap m_bgTile;
|
QPixmap m_bgTile;
|
||||||
QPalette m_whitePal;
|
QPalette m_whitePal;
|
||||||
|
|
||||||
Tomahawk::PlaylistUpdaterInterface* m_updaterInterface;
|
SmartPointerList<Tomahawk::PlaylistUpdaterInterface> m_updaters;;
|
||||||
QWidget* m_updaterConfiguration;
|
QList<QWidget*> m_updaterConfigurations;
|
||||||
|
|
||||||
QSearchField* m_searchWidget;
|
QSearchField* m_searchWidget;
|
||||||
QueryLabel* m_queryLabel;
|
QueryLabel* m_queryLabel;
|
||||||
|
@@ -63,7 +63,7 @@ PlaylistUpdaterInterface::PlaylistUpdaterInterface( const playlist_ptr& pl )
|
|||||||
{
|
{
|
||||||
Q_ASSERT( !m_playlist.isNull() );
|
Q_ASSERT( !m_playlist.isNull() );
|
||||||
|
|
||||||
m_playlist->setUpdater( this );
|
m_playlist->addUpdater( this );
|
||||||
|
|
||||||
QTimer::singleShot( 0, this, SLOT( save() ) );
|
QTimer::singleShot( 0, this, SLOT( save() ) );
|
||||||
}
|
}
|
||||||
|
@@ -43,6 +43,17 @@ class DLLEXPORT PlaylistUpdaterInterface : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
// used when loading/saving from settings
|
||||||
|
struct SerializedUpdater {
|
||||||
|
QString type;
|
||||||
|
bool sync;
|
||||||
|
QVariantHash customData;
|
||||||
|
|
||||||
|
SerializedUpdater( const QString& t, bool s, const QVariantHash cd ) : type( t ), sync( s ), customData( cd ) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef QHash< QString, SerializedUpdater > SerializedUpdaters;
|
||||||
|
|
||||||
explicit PlaylistUpdaterInterface( const playlist_ptr& pl );
|
explicit PlaylistUpdaterInterface( const playlist_ptr& pl );
|
||||||
|
|
||||||
virtual ~PlaylistUpdaterInterface(){}
|
virtual ~PlaylistUpdaterInterface(){}
|
||||||
|
@@ -109,23 +109,13 @@ PlaylistView::deleteItems()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
SmartPointerList<PlaylistUpdaterInterface>
|
||||||
PlaylistView::canAutoUpdate() const
|
PlaylistView::updaters() const
|
||||||
{
|
{
|
||||||
if ( !m_model->playlist().isNull() && m_model->playlist()->updater() )
|
if ( !m_model->playlist().isNull() )
|
||||||
return true;
|
return m_model->playlist()->updaters();
|
||||||
|
|
||||||
return false;
|
return SmartPointerList<PlaylistUpdaterInterface>();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PlaylistUpdaterInterface*
|
|
||||||
PlaylistView::autoUpdateInterface() const
|
|
||||||
{
|
|
||||||
if ( !m_model->playlist().isNull() && m_model->playlist()->updater() )
|
|
||||||
return m_model->playlist()->updater();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -43,8 +43,7 @@ public:
|
|||||||
|
|
||||||
virtual bool showFilter() const { return true; }
|
virtual bool showFilter() const { return true; }
|
||||||
|
|
||||||
virtual bool canAutoUpdate() const;
|
virtual SmartPointerList<Tomahawk::PlaylistUpdaterInterface> updaters() const;
|
||||||
virtual Tomahawk::PlaylistUpdaterInterface* autoUpdateInterface() const;
|
|
||||||
|
|
||||||
virtual QString title() const { return playlistModel()->title(); }
|
virtual QString title() const { return playlistModel()->title(); }
|
||||||
virtual QString description() const { return m_model->description(); }
|
virtual QString description() const { return m_model->description(); }
|
||||||
|
@@ -57,7 +57,7 @@ XspfUpdater::XspfUpdater( const playlist_ptr& pl, int interval, bool autoUpdate,
|
|||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
m_toggleCheckbox = new QCheckBox( );
|
m_toggleCheckbox = new QCheckBox( );
|
||||||
m_toggleCheckbox->setText( tr( "Automatically update" ) );
|
m_toggleCheckbox->setText( tr( "Automatically update from XSPF" ) );
|
||||||
m_toggleCheckbox->setLayoutDirection( Qt::RightToLeft );
|
m_toggleCheckbox->setLayoutDirection( Qt::RightToLeft );
|
||||||
m_toggleCheckbox->setChecked( m_autoUpdate );
|
m_toggleCheckbox->setChecked( m_autoUpdate );
|
||||||
m_toggleCheckbox->hide();
|
m_toggleCheckbox->hide();
|
||||||
|
@@ -136,6 +136,11 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==( const SmartPointerList& that )
|
||||||
|
{
|
||||||
|
return QList<T*>::operator==( that );
|
||||||
|
}
|
||||||
|
|
||||||
void push_back( T* o )
|
void push_back( T* o )
|
||||||
{
|
{
|
||||||
append( o );
|
append( o );
|
||||||
@@ -180,7 +185,7 @@ public:
|
|||||||
using QList<T*>::swap;
|
using QList<T*>::swap;
|
||||||
using QList<T*>::value;
|
using QList<T*>::value;
|
||||||
using QList<T*>::operator!=;
|
using QList<T*>::operator!=;
|
||||||
using QList<T*>::operator==;
|
// using QList<T*>::operator==;
|
||||||
|
|
||||||
// can't use using directive here since we only want the const versions
|
// can't use using directive here since we only want the const versions
|
||||||
typename QList<T*>::const_iterator begin() const { return QList<T*>::constBegin(); }
|
typename QList<T*>::const_iterator begin() const { return QList<T*>::constBegin(); }
|
||||||
|
36
src/main.cpp
36
src/main.cpp
@@ -37,38 +37,6 @@
|
|||||||
#include "breakpad/BreakPad.h"
|
#include "breakpad/BreakPad.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline QDataStream& operator<<(QDataStream& out, const AtticaManager::StateHash& states)
|
|
||||||
{
|
|
||||||
out << TOMAHAWK_SETTINGS_VERSION;
|
|
||||||
out << (quint32)states.count();
|
|
||||||
foreach( const QString& key, states.keys() )
|
|
||||||
{
|
|
||||||
AtticaManager::Resolver resolver = states[ key ];
|
|
||||||
out << key << resolver.version << resolver.scriptPath << (qint32)resolver.state << resolver.userRating;
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline QDataStream& operator>>(QDataStream& in, AtticaManager::StateHash& states)
|
|
||||||
{
|
|
||||||
quint32 count = 0, version = 0;
|
|
||||||
in >> version;
|
|
||||||
in >> count;
|
|
||||||
for ( uint i = 0; i < count; i++ )
|
|
||||||
{
|
|
||||||
QString key, version, scriptPath;
|
|
||||||
qint32 state, userRating;
|
|
||||||
in >> key;
|
|
||||||
in >> version;
|
|
||||||
in >> scriptPath;
|
|
||||||
in >> state;
|
|
||||||
in >> userRating;
|
|
||||||
states[ key ] = AtticaManager::Resolver( version, scriptPath, userRating, (AtticaManager::ResolverState)state );
|
|
||||||
}
|
|
||||||
return in;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#define argc __argc
|
#define argc __argc
|
||||||
@@ -115,8 +83,8 @@ main( int argc, char *argv[] )
|
|||||||
TomahawkApp a( argc, argv );
|
TomahawkApp a( argc, argv );
|
||||||
|
|
||||||
// MUST register StateHash ****before*** initing TomahawkSettingsGui as constructor of settings does upgrade before Gui subclass registers type
|
// MUST register StateHash ****before*** initing TomahawkSettingsGui as constructor of settings does upgrade before Gui subclass registers type
|
||||||
qRegisterMetaType< AtticaManager::StateHash >( "AtticaManager::StateHash" );
|
TomahawkSettings::registerCustomSettingsHandlers();
|
||||||
qRegisterMetaTypeStreamOperators<AtticaManager::StateHash>("AtticaManager::StateHash");
|
TomahawkSettingsGui::registerCustomSettingsHandlers();
|
||||||
|
|
||||||
#ifdef ENABLE_HEADLESS
|
#ifdef ENABLE_HEADLESS
|
||||||
new TomahawkSettings( &a );
|
new TomahawkSettings( &a );
|
||||||
|
@@ -52,7 +52,7 @@ PlaylistItem::PlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, const pla
|
|||||||
if( ViewManager::instance()->pageForPlaylist( pl ) )
|
if( ViewManager::instance()->pageForPlaylist( pl ) )
|
||||||
model()->linkSourceItemToPage( this, ViewManager::instance()->pageForPlaylist( pl ) );
|
model()->linkSourceItemToPage( this, ViewManager::instance()->pageForPlaylist( pl ) );
|
||||||
|
|
||||||
if ( m_playlist->updater() && !m_playlist->updater()->typeIcon().isNull() )
|
if ( !m_playlist->updaters().isEmpty() )
|
||||||
createOverlay();
|
createOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,40 +251,66 @@ PlaylistItem::parsedDroppedTracks( const QList< query_ptr >& tracks )
|
|||||||
void
|
void
|
||||||
PlaylistItem::onUpdated()
|
PlaylistItem::onUpdated()
|
||||||
{
|
{
|
||||||
if ( m_playlist->updater() && !m_playlist->updater()->typeIcon().isNull() &&
|
// No work todo
|
||||||
m_overlaidIcon.isNull() ) // create overlay
|
if ( !m_overlaidIcon.isNull() && m_overlaidUpdaters.operator==( m_playlist->updaters() ) )
|
||||||
{
|
{
|
||||||
createOverlay();
|
emit updated();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if ( !m_playlist->updater() || ( m_playlist->updater()->typeIcon().isNull() && !m_overlaidIcon.isNull() ) )
|
|
||||||
{
|
const bool newOverlay = createOverlay();
|
||||||
// No longer an updater with an icon
|
if ( !newOverlay && !m_overlaidIcon.isNull() )
|
||||||
m_overlaidIcon = QIcon();
|
m_overlaidIcon = QIcon();
|
||||||
}
|
|
||||||
|
|
||||||
emit updated();
|
emit updated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
bool
|
||||||
PlaylistItem::createOverlay()
|
PlaylistItem::createOverlay()
|
||||||
{
|
{
|
||||||
Q_ASSERT( !m_playlist.isNull() );
|
Q_ASSERT( !m_playlist.isNull() );
|
||||||
Q_ASSERT( m_playlist->updater() );
|
|
||||||
Q_ASSERT( !m_playlist->updater()->typeIcon().isNull() );
|
if ( m_playlist->updaters().isEmpty() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QList< QPixmap > icons;
|
||||||
|
foreach ( PlaylistUpdaterInterface* updater, m_playlist->updaters() )
|
||||||
|
{
|
||||||
|
if ( !updater->typeIcon().isNull() )
|
||||||
|
icons << updater->typeIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( icons.isEmpty() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// For now we only support up to 2 overlaid updater icons,
|
||||||
|
// we need to add smarter scaling etc to manage more at once
|
||||||
|
if ( icons.size() > 2 )
|
||||||
|
icons = icons.mid( 0, 2 );
|
||||||
|
|
||||||
m_overlaidIcon = QIcon();
|
m_overlaidIcon = QIcon();
|
||||||
|
m_overlaidUpdaters = m_playlist->updaters();
|
||||||
|
|
||||||
QPixmap base = m_icon.pixmap( 48, 48 );
|
QPixmap base = m_icon.pixmap( 48, 48 );
|
||||||
const QPixmap overlay = m_playlist->updater()->typeIcon();
|
|
||||||
|
|
||||||
QPainter p( &base );
|
QPainter p( &base );
|
||||||
const int w = base.width() / 2;
|
const int w = base.width() / 2;
|
||||||
const QRect overlayRect( base.rect().right() - w, base.rect().height() - w, w, w );
|
QRect overlayRect( base.rect().right() - w, base.rect().height() - w, w, w );
|
||||||
p.drawPixmap( overlayRect, overlay );
|
|
||||||
|
foreach ( const QPixmap& overlay, icons )
|
||||||
|
{
|
||||||
|
p.drawPixmap( overlayRect, overlay );
|
||||||
|
|
||||||
|
// NOTE only works if icons.size == 2 as ensured above
|
||||||
|
overlayRect.moveLeft( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
m_overlaidIcon.addPixmap( base );
|
m_overlaidIcon.addPixmap( base );
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "SourceTreeItem.h"
|
#include "SourceTreeItem.h"
|
||||||
#include "playlist/dynamic/DynamicPlaylist.h"
|
#include "playlist/dynamic/DynamicPlaylist.h"
|
||||||
|
#include "utils/SmartPointerList.h"
|
||||||
|
|
||||||
class PlaylistItem : public SourceTreeItem
|
class PlaylistItem : public SourceTreeItem
|
||||||
{
|
{
|
||||||
@@ -56,11 +57,12 @@ private slots:
|
|||||||
|
|
||||||
void onUpdated();
|
void onUpdated();
|
||||||
private:
|
private:
|
||||||
void createOverlay();
|
bool createOverlay();
|
||||||
|
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
Tomahawk::playlist_ptr m_playlist;
|
Tomahawk::playlist_ptr m_playlist;
|
||||||
QIcon m_icon, m_overlaidIcon;
|
QIcon m_icon, m_overlaidIcon;
|
||||||
|
SmartPointerList<Tomahawk::PlaylistUpdaterInterface> m_overlaidUpdaters;
|
||||||
};
|
};
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(PlaylistItem::DropTypes)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(PlaylistItem::DropTypes)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user