From d88eaacf8d9daf62959b52f5ceee67870c9a9a1c Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 6 Nov 2011 06:49:26 +0100 Subject: [PATCH 01/12] * Get rid of query_ptrs in Collection. --- src/libtomahawk/collection.cpp | 54 ++++--------------- src/libtomahawk/collection.h | 9 ++-- .../database/databasecommand_addfiles.cpp | 16 +++--- .../database/databasecommand_addfiles.h | 6 +-- .../database/databasecommand_deletefiles.cpp | 52 ++++++------------ .../database/databasecommand_deletefiles.h | 2 +- src/tomahawkapp.cpp | 9 ++-- src/tomahawkapp.h | 2 +- 8 files changed, 48 insertions(+), 102 deletions(-) diff --git a/src/libtomahawk/collection.cpp b/src/libtomahawk/collection.cpp index a229562d5..740315673 100644 --- a/src/libtomahawk/collection.cpp +++ b/src/libtomahawk/collection.cpp @@ -68,7 +68,6 @@ Collection::addPlaylist( const Tomahawk::playlist_ptr& p ) QList toadd; toadd << p; -// qDebug() << "Inserted playlist with guid:" << p->guid(); m_playlists.insert( p->guid(), p ); /* qDebug() << Q_FUNC_INFO << "Collection name" << name() @@ -83,7 +82,6 @@ Collection::addAutoPlaylist( const Tomahawk::dynplaylist_ptr& p ) { QList toadd; toadd << p; -// qDebug() << "Inserted dynamic playlist with guid:" << p->guid(); m_autoplaylists.insert( p->guid(), p ); /* qDebug() << Q_FUNC_INFO << "Collection name" << name() @@ -98,7 +96,6 @@ Collection::addStation( const dynplaylist_ptr& s ) { QList toadd; toadd << s; -// qDebug() << "Inserted station with guid:" << s->guid(); m_stations.insert( s->guid(), s ); /* qDebug() << Q_FUNC_INFO << "Collection name" << name() @@ -167,7 +164,6 @@ Collection::autoPlaylist( const QString& guid ) dynplaylist_ptr Collection::station( const QString& guid ) { - return m_stations.value( guid, dynplaylist_ptr() ); } @@ -175,7 +171,6 @@ Collection::station( const QString& guid ) void Collection::setPlaylists( const QList& plists ) { -// qDebug() << Q_FUNC_INFO << plists.count(); foreach ( const playlist_ptr& p, plists ) { // qDebug() << "Batch inserting playlist:" << p->guid(); @@ -190,8 +185,6 @@ Collection::setPlaylists( const QList& plists ) void Collection::setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& plists ) { -// qDebug() << Q_FUNC_INFO << plists.count(); - foreach ( const dynplaylist_ptr& p, plists ) { // qDebug() << "Batch inserting dynamic playlist:" << p->guid(); @@ -204,8 +197,6 @@ Collection::setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& plists ) void Collection::setStations( const QList< dynplaylist_ptr >& stations ) { -// qDebug() << Q_FUNC_INFO << stations.count(); - foreach ( const dynplaylist_ptr& s, stations ) { // qDebug() << "Batch inserting station:" << s->guid(); @@ -216,56 +207,29 @@ Collection::setStations( const QList< dynplaylist_ptr >& stations ) void -Collection::setTracks( const QList& tracks ) +Collection::setTracks( const QList& ids ) { -// qDebug() << Q_FUNC_INFO << tracks.count() << name(); + qDebug() << Q_FUNC_INFO << ids.count() << name(); - emit tracksAdded( tracks ); + emit tracksAdded( ids ); emit changed(); } void -Collection::delTracks( const QStringList& files ) +Collection::delTracks( const QList& ids ) { - qDebug() << Q_FUNC_INFO << files.count() << name(); + qDebug() << Q_FUNC_INFO << ids.count() << name(); + + emit tracksRemoved( ids ); emit changed(); - -/* QList tracks; - int i = 0; - foreach ( const query_ptr& query, m_tracks ) - { - foreach ( const QString& file, files ) - { - bool found = false; - foreach ( const result_ptr& result, query->results() ) - { - if ( file == result->url() ) - { -// qDebug() << Q_FUNC_INFO << "Found deleted result:" << file; - tracks << query; - m_tracks.removeAt( i ); - i--; - found = true; - break; - } - } - if ( found ) - break; - } - - i++; - } - - tDebug() << "Emitting tracks removed:" << tracks.size(); - emit tracksRemoved( tracks );*/ } void Collection::moveAutoToStation( const QString& guid ) { - if( m_autoplaylists.contains( guid ) ) + if ( m_autoplaylists.contains( guid ) ) m_stations.insert( guid, m_autoplaylists.take( guid ) ); } @@ -273,6 +237,6 @@ Collection::moveAutoToStation( const QString& guid ) void Collection::moveStationToAuto( const QString& guid ) { - if( m_stations.contains( guid ) ) + if ( m_stations.contains( guid ) ) m_autoplaylists.insert( guid, m_stations.take( guid ) ); } diff --git a/src/libtomahawk/collection.h b/src/libtomahawk/collection.h index 7bc713313..7a8b2df37 100644 --- a/src/libtomahawk/collection.h +++ b/src/libtomahawk/collection.h @@ -35,7 +35,6 @@ #include "functimeout.h" #include "playlist.h" #include "playlist/dynamic/DynamicPlaylist.h" -#include "query.h" #include "dllmacro.h" @@ -79,8 +78,8 @@ public: unsigned int lastmodified() const { return m_lastmodified; } signals: - void tracksAdded( const QList& tracks ); - void tracksRemoved( const QList& tracks ); + void tracksAdded( const QList& ids ); + void tracksRemoved( const QList& ids ); void playlistsAdded( const QList& ); void playlistsDeleted( const QList& ); @@ -101,8 +100,8 @@ public slots: void setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& autoplists ); void setStations( const QList< Tomahawk::dynplaylist_ptr >& stations ); - void setTracks( const QList& tracks ); - void delTracks( const QStringList& files ); + void setTracks( const QList& ids ); + void delTracks( const QList& ids ); protected: QString m_name; diff --git a/src/libtomahawk/database/databasecommand_addfiles.cpp b/src/libtomahawk/database/databasecommand_addfiles.cpp index d0680bb18..6d840a766 100644 --- a/src/libtomahawk/database/databasecommand_addfiles.cpp +++ b/src/libtomahawk/database/databasecommand_addfiles.cpp @@ -56,7 +56,6 @@ DatabaseCommand_AddFiles::files() const void DatabaseCommand_AddFiles::postCommitHook() { - qDebug() << Q_FUNC_INFO; if ( source().isNull() || source()->collection().isNull() ) { qDebug() << "Source has gone offline, not emitting to GUI."; @@ -67,13 +66,13 @@ DatabaseCommand_AddFiles::postCommitHook() // collection browser will update/fade in etc. Collection* coll = source()->collection().data(); - connect( this, SIGNAL( notify( QList ) ), - coll, SLOT( setTracks( QList ) ), + connect( this, SIGNAL( notify( QList ) ), + coll, SLOT( setTracks( QList ) ), Qt::QueuedConnection ); - emit notify( m_queries ); + emit notify( m_ids ); - if( source()->isLocal() ) + if ( source()->isLocal() ) { Servent::instance()->triggerDBSync(); @@ -185,7 +184,7 @@ DatabaseCommand_AddFiles::exec( DatabaseImpl* dbi ) query_trackattr.bindValue( 2, year ); query_trackattr.exec(); - QVariantMap attr; +/* QVariantMap attr; Tomahawk::query_ptr query = Tomahawk::Query::get( artist, track, album ); attr["releaseyear"] = m.value( "year" ); @@ -210,12 +209,13 @@ DatabaseCommand_AddFiles::exec( DatabaseImpl* dbi ) results << result; query->addResults( results ); - m_queries << query; + m_queries << query;*/ + + m_ids << trackid; added++; } qDebug() << "Inserted" << added << "tracks to database"; - // TODO building the index could be a separate job, outside this transaction if ( added ) source()->updateIndexWhenSynced(); diff --git a/src/libtomahawk/database/databasecommand_addfiles.h b/src/libtomahawk/database/databasecommand_addfiles.h index 5d82ec9ac..9666a02ab 100644 --- a/src/libtomahawk/database/databasecommand_addfiles.h +++ b/src/libtomahawk/database/databasecommand_addfiles.h @@ -1,5 +1,5 @@ /* === This file is part of Tomahawk Player - === - * + * * Copyright 2010-2011, Christian Muehlhaeuser * * Tomahawk is free software: you can redistribute it and/or modify @@ -55,11 +55,11 @@ public: signals: void done( const QList&, const Tomahawk::collection_ptr& ); - void notify( const QList& ); + void notify( const QList& ids ); private: QVariantList m_files; - QList m_queries; + QList m_ids; }; #endif // DATABASECOMMAND_ADDFILES_H diff --git a/src/libtomahawk/database/databasecommand_deletefiles.cpp b/src/libtomahawk/database/databasecommand_deletefiles.cpp index a9e3b4406..65e54755a 100644 --- a/src/libtomahawk/database/databasecommand_deletefiles.cpp +++ b/src/libtomahawk/database/databasecommand_deletefiles.cpp @@ -45,11 +45,14 @@ DatabaseCommand_DeleteFiles::postCommitHook() // collection browser will update/fade in etc. Collection* coll = source()->collection().data(); - connect( this, SIGNAL( notify( QStringList ) ), - coll, SLOT( delTracks( QStringList ) ), Qt::QueuedConnection ); + connect( this, SIGNAL( notify( QList ) ), + coll, SLOT( delTracks( QList ) ), Qt::QueuedConnection ); - tDebug() << "Notifying of deleted tracks: " << m_files.size() << " from source " << source()->id(); - emit notify( m_files ); + tDebug() << "Notifying of deleted tracks:" << m_ids.size() << "from source" << source()->id(); + QList ids; + foreach ( QVariant id, m_ids ) + ids << id.toUInt(); + emit notify( ids ); if( source()->isLocal() ) Servent::instance()->triggerDBSync(); @@ -59,7 +62,6 @@ DatabaseCommand_DeleteFiles::postCommitHook() void DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi ) { -// qDebug() << Q_FUNC_INFO; Q_ASSERT( !source().isNull() ); QVariant srcid = source()->isLocal() ? QVariant( QVariant::Int ) : source()->id(); @@ -68,7 +70,6 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi ) if ( source()->isLocal() ) { - tDebug() << Q_FUNC_INFO << " source is local"; if ( m_dir.path() != QString( "." ) ) { tDebug() << "Deleting" << m_dir.path() << "from db for localsource" << srcid; @@ -95,7 +96,7 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi ) } else if ( !m_ids.isEmpty() ) { - tDebug() << Q_FUNC_INFO << " deleting given ids"; + tDebug() << Q_FUNC_INFO << "deleting given ids"; TomahawkSqlQuery dirquery = dbi->newquery(); QString idstring; @@ -104,23 +105,19 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi ) idstring.chop( 2 ); //remove the trailing ", " dirquery.prepare( QString( "SELECT id, url FROM file WHERE source IS NULL AND id IN ( %1 )" ).arg( idstring ) ); - + dirquery.exec(); while ( dirquery.next() ) { - //tDebug() << Q_FUNC_INFO << " found dirquery value 0: " << dirquery.value( 0 ).toString() << " and value 1: " << dirquery.value( 1 ).toString(); m_files << dirquery.value( 1 ).toString(); } - - //tDebug() << Q_FUNC_INFO << " executed query was: " << dirquery.executedQuery(); - //tDebug() << Q_FUNC_INFO << " files selected for delete: " << m_files; } else if ( m_deleteAll ) { TomahawkSqlQuery dirquery = dbi->newquery(); - + dirquery.prepare( QString( "SELECT id, url FROM file WHERE source IS NULL" ) ); - + dirquery.exec(); while ( dirquery.next() ) { @@ -134,10 +131,10 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi ) if ( m_deleteAll ) { TomahawkSqlQuery dirquery = dbi->newquery(); - + dirquery.prepare( QString( "SELECT url FROM file WHERE source = %1" ).arg( source()->id() ) ); - dirquery.exec(); + while ( dirquery.next() ) m_ids << dirquery.value( 0 ).toString(); } @@ -151,43 +148,28 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi ) if ( !m_ids.isEmpty() ) { delquery.prepare( QString( "DELETE FROM file WHERE source %1" ) - .arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) ); + .arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) ); - if( !delquery.exec() ) - { - qDebug() << "Failed to delete file:" - << delquery.lastError().databaseText() - << delquery.lastError().driverText() - << delquery.boundValues(); - } + delquery.exec(); } } else if ( !m_ids.isEmpty() ) { - tDebug() << Q_FUNC_INFO << " executing delete"; delquery.prepare( QString( "DELETE FROM file WHERE source %1 AND %2 IN ( ? )" ) .arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) .arg( source()->isLocal() ? "id" : "url" ) ); QString idstring; foreach( const QVariant& id, m_ids ) - idstring.append( id.toString() + ", " ); + idstring.append( id.toString() + ", " ); idstring.chop( 2 ); //remove the trailing ", " delquery.prepare( QString( "DELETE FROM file WHERE source %1 AND %2 IN ( %3 )" ) .arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) .arg( source()->isLocal() ? "id" : "url" ) .arg( idstring ) ); - - if( !delquery.exec() ) - { - qDebug() << "Failed to delete file:" - << delquery.lastError().databaseText() - << delquery.lastError().driverText() - << delquery.boundValues(); - } - //tDebug() << Q_FUNC_INFO << " executed query was: " << delquery.executedQuery(); + delquery.exec(); } emit done( m_files, source()->collection() ); diff --git a/src/libtomahawk/database/databasecommand_deletefiles.h b/src/libtomahawk/database/databasecommand_deletefiles.h index 11f6d5fad..fd007b145 100644 --- a/src/libtomahawk/database/databasecommand_deletefiles.h +++ b/src/libtomahawk/database/databasecommand_deletefiles.h @@ -74,7 +74,7 @@ public: signals: void done( const QStringList&, const Tomahawk::collection_ptr& ); - void notify( const QStringList& ); + void notify( const QList& ids ); private: QStringList m_files; diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index dc9dba5da..93cbb330c 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -502,6 +502,7 @@ TomahawkApp::initServent() } } + void TomahawkApp::initSIP() { @@ -518,6 +519,7 @@ TomahawkApp::initSIP() } } + void TomahawkApp::spotifyApiCheckFinished() { @@ -543,7 +545,6 @@ TomahawkApp::activate() bool TomahawkApp::loadUrl( const QString& url ) { - activate(); if ( url.startsWith( "tomahawk://" ) ) return GlobalActionManager::instance()->parseTomahawkLink( url ); else if ( url.contains( "open.spotify.com" ) || url.contains( "spotify:track" ) ) @@ -561,7 +562,8 @@ TomahawkApp::loadUrl( const QString& url ) l->load( QUrl::fromUserInput( url ) ); return true; - } else if ( info.suffix() == "jspf" ) + } + else if ( info.suffix() == "jspf" ) { JSPFLoader* l = new JSPFLoader( true, this ); tDebug( LOGINFO ) << "Loading j-spiff:" << url; @@ -580,10 +582,9 @@ TomahawkApp::instanceStarted( KDSingleApplicationGuard::Instance instance ) { tDebug( LOGINFO ) << "Instance started!" << instance.pid << instance.arguments; + activate(); if ( instance.arguments.size() < 2 ) - { return; - } QString arg1 = instance.arguments[ 1 ]; loadUrl( arg1 ); diff --git a/src/tomahawkapp.h b/src/tomahawkapp.h index 769c8caad..9d76916b1 100644 --- a/src/tomahawkapp.h +++ b/src/tomahawkapp.h @@ -137,7 +137,7 @@ private: }; Q_DECLARE_METATYPE( QPersistentModelIndex ) -Q_DECLARE_METATYPE(PairList) +Q_DECLARE_METATYPE( PairList ) #endif // TOMAHAWKAPP_H From e3bb4c9b14b2533e70a05e029c8c2b4afb50d860 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 6 Nov 2011 07:55:06 +0100 Subject: [PATCH 02/12] * CrashReporter now also sends Tomahawk.log and the proper version number to our breakpad server. --- src/breakpad/CrashReporter/CMakeLists.txt | 4 ++-- src/breakpad/CrashReporter/CrashReporter.cpp | 25 +++++++++++--------- src/libtomahawk/utils/logger.cpp | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/breakpad/CrashReporter/CMakeLists.txt b/src/breakpad/CrashReporter/CMakeLists.txt index 02dfedf1e..8b019947b 100644 --- a/src/breakpad/CrashReporter/CMakeLists.txt +++ b/src/breakpad/CrashReporter/CMakeLists.txt @@ -13,8 +13,8 @@ QT4_WRAP_UI( crashreporter_UI_HEADERS ${crashreporter_UI} ) QT4_ADD_RESOURCES( crashreporter_RC_RCC ${crashreporter_RC} ) INCLUDE( ${QT_USE_FILE} ) -INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} ) +INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src ../../libtomahawk ) ADD_DEFINITIONS( ${QT_DEFINITIONS} ) ADD_EXECUTABLE( CrashReporter ${crashreporter_SOURCES} ${crashreporter_HEADERS_MOC} ${crashreporter_UI_HEADERS} ${crashreporter_RC_RCC} ) -TARGET_LINK_LIBRARIES( CrashReporter ${QT_LIBRARIES} ) +TARGET_LINK_LIBRARIES( CrashReporter ${QT_LIBRARIES} tomahawklib ) diff --git a/src/breakpad/CrashReporter/CrashReporter.cpp b/src/breakpad/CrashReporter/CrashReporter.cpp index 468e6a4ed..15e563529 100644 --- a/src/breakpad/CrashReporter/CrashReporter.cpp +++ b/src/breakpad/CrashReporter/CrashReporter.cpp @@ -25,6 +25,9 @@ #include #include +#include "utils/tomahawkutils.h" + +#define LOGFILE TomahawkUtils::appLogDir().filePath( "Tomahawk.log" ).toLocal8Bit() #define RESPATH ":/data/" @@ -40,7 +43,6 @@ CrashReporter::CrashReporter( const QStringList& args ) ui.progressLabel->setPalette( Qt::gray ); #ifdef Q_WS_MAC - // macify++ QFont f = ui.bottomLabel->font(); f.setPointSize( 10 ); ui.bottomLabel->setFont( f ); @@ -55,12 +57,14 @@ CrashReporter::CrashReporter( const QStringList& args ) ui.bottomLabel->setIndent( 1 ); // adjust the spacer since we adjusted the spacing above - for (int x = 0; x < ui.vboxLayout->count(); ++x) - if (QSpacerItem* spacer = ui.vboxLayout->itemAt( x )->spacerItem()) + for ( int x = 0; x < ui.vboxLayout->count(); ++x ) + { + if ( QSpacerItem* spacer = ui.vboxLayout->itemAt( x )->spacerItem() ) { spacer->changeSize( 6, 2, QSizePolicy::Minimum, QSizePolicy::Fixed ); break; } + } #endif //Q_WS_MAC m_http = new QHttp( "oops.tomahawk-player.org", 80, this ); @@ -72,9 +76,9 @@ CrashReporter::CrashReporter( const QStringList& args ) m_minidump = m_dir + '/' + args.value( 2 ) + ".dmp"; m_product_name = args.value( 3 ); - QTimer::singleShot( 0, this, SLOT(send()) ); - setFixedSize( sizeHint() ); + + QTimer::singleShot( 0, this, SLOT( send() ) ); } @@ -94,7 +98,7 @@ CrashReporter::send() // socorro expects a 10 digit build id QRegExp rx( "(\\d+\\.\\d+\\.\\d+).(\\d+)" ); - rx.exactMatch( "0.2.99" ); + rx.exactMatch( TomahawkUtils::appFriendlyVersion() ); QString const version = rx.cap( 1 ); QString const buildId = rx.cap( 2 ).leftJustified( 10, '0' ); @@ -103,7 +107,7 @@ CrashReporter::send() QList pairs; pairs << Pair( "BuildID", buildId.toUtf8() ) << Pair( "ProductName", m_product_name.toUtf8() ) - << Pair( "Version", version.toUtf8() ) + << Pair( "Version", TomahawkUtils::appFriendlyVersion().toLocal8Bit() ) << Pair( "Vendor", "Tomahawk" ) << Pair( "timestamp", QByteArray::number( QDateTime::currentDateTime().toTime_t() ) ); @@ -126,14 +130,13 @@ CrashReporter::send() // add logfile body += "--thkboundary\r\n"; - body += "Content-Disposition: form-data; name=\"upload_file_containerlog\"; filename=\"container.log\"\r\n"; + body += "Content-Disposition: form-data; name=\"upload_file_tomahawklog\"; filename=\"Tomahawk.log\"\r\n"; body += "Content-Type: application/x-gzip\r\n"; body += "\r\n"; -// body += qCompress( contents( "Tomahawk.log" ) ); + body += qCompress( contents( LOGFILE ) ); body += "\r\n"; body += "--thkboundary--\r\n"; -////// QHttpRequestHeader header( "POST", "/addreport.php" ); header.setContentType( "multipart/form-data; boundary=thkboundary" ); header.setValue( "HOST", "oops.tomahawk-player.org" ); @@ -179,5 +182,5 @@ CrashReporter::onFail( int error, const QString& errorString ) { ui.button->setText( tr( "Close" ) ); ui.progressLabel->setText( tr( "Failed to send crash info." ) ); - qDebug() << "Error: " << error << errorString; + qDebug() << "Error:" << error << errorString; } diff --git a/src/libtomahawk/utils/logger.cpp b/src/libtomahawk/utils/logger.cpp index 846e2586b..ea7c3bada 100644 --- a/src/libtomahawk/utils/logger.cpp +++ b/src/libtomahawk/utils/logger.cpp @@ -31,7 +31,7 @@ #include "utils/tomahawkutils.h" #define LOGFILE TomahawkUtils::appLogDir().filePath( "Tomahawk.log" ).toLocal8Bit() -#define LOGFILE_SIZE 1024 * 512 +#define LOGFILE_SIZE 1024 * 256 #define RELEASE_LEVEL_THRESHOLD 0 #define DEBUG_LEVEL_THRESHOLD LOGEXTRA From ac8a4b5a3a2d53164671e8ee066d377094b4b1ff Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 6 Nov 2011 11:45:50 +0100 Subject: [PATCH 03/12] * Don't duplicate signal / slot connections in TreeModel. --- src/libtomahawk/playlist/treemodel.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libtomahawk/playlist/treemodel.cpp b/src/libtomahawk/playlist/treemodel.cpp index 41920f2fb..68b7937a2 100644 --- a/src/libtomahawk/playlist/treemodel.cpp +++ b/src/libtomahawk/playlist/treemodel.cpp @@ -559,7 +559,7 @@ TreeModel::addAllCollections() QList sources = SourceList::instance()->sources(); foreach ( const source_ptr& source, sources ) { - connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ) ); + connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); } m_title = tr( "All Artists" ); @@ -668,7 +668,7 @@ TreeModel::addCollection( const collection_ptr& collection ) Database::instance()->enqueue( QSharedPointer( cmd ) ); - connect( collection.data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ) ); + connect( collection.data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); if ( !collection->source()->avatar().isNull() ) setIcon( collection->source()->avatar() ); @@ -708,7 +708,7 @@ TreeModel::addFilteredCollection( const collection_ptr& collection, unsigned int void TreeModel::onSourceAdded( const Tomahawk::source_ptr& source ) { - connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ) ); + connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); } From 0ead914d027355457d4c32ee939f3c6eb55295ce Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 6 Nov 2011 11:56:43 +0100 Subject: [PATCH 04/12] * Updated / fixed ChangeLog a bit. --- ChangeLog | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 15f431f6f..7ef76fabb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,58 +1,53 @@ Version 0.3.0: - * Fixed bug where we would download http:// tracks twice. * Make artist names in the album view clickable. * Don't start playing if a tomahawk:// link was clicked while Tomahawk is paused. * Make artist name clickable in header of Album pages. - * Fixed adding social actions such as loved tracks from other sources. - * Added a drop shadow to cover images, and put CD placeholder in jewel - case. + * Added a drop shadow to cover images, and put placeholder in jewel case. * Added shuffle and repeat support to tree view. * Draw a speaker next to the currently playing playlist. * Refresh station previews whenever a filter is changed. * Support and show official releases on album and track pages. * Filter out duplicates from station previews and upcoming tracks. - * Resolve lists top-down. * Added YouTube resolver. * Fixed bug where going offline then online would not re-connect to many peers. - * Added support for auto-updating live xspf playlists. - * Don't show an age of 41 for tracks that have no age information. - * Show config UI for resolvers that have them as so on as you add the resolver. + * Added support for auto-updating live XSPF playlists. + * Don't show an age of 41 years for tracks that have no age information. + * Show config UI for resolvers that have them as soon as you add them. * Add support for Echo Nest Personal Catalogs and User Radio. Synchronize your catalog with The Echo Nest and enable personal recommendations from you and your friends. * Added support for Grooveshark resolver (requires Grooveshark Anywhere). - * Fixed re-resolving when resolvers or sources go offline. + * Fixed re-resolving when resolvers or sources go off- / online. * Correctly sort recently played tracks on the Dashboard. * Show a Lion full-screen toggle button if running on Lion. - * Display list of who is currently listening along to you. + * Show a list of users who are currently listening along to you. * Show headphone icon in source item to allow users to listen along; paint - headphones red on a source if the user is listening along to it. + headphones red on a source if you are currently listening along to it. * Added new job status view in the bottom of the source list that displays current jobs such as resolving, parsing playlists, and loading from database. * Parse and convert a Spotify playlist url when dropped anywhere on the - sidebar + sidebar. * Convert resolvers to use asynchronous calls to avoid blocking Tomahawk's UI, greatly increasing responsiveness of Tomahawk while resolving. * Fixed no playlists overlay not disappearing when playlists were added. * Add support for parsing itunes track, artist and album links. * Fixed crash when syncing playlists with peers. - * Add support for browsing, downloading and rating resolvers - from inside Tomahawk directly. + * Add support for browsing, downloading and rating resolvers from within + Tomahawk directly. * Support multi-folder selection and scanning. - * Actually remove deleted files from the collection. * Fixed handling of special characters in tomahawk:// links * Improve sidebar performance by caching pixmaps and shrinking them. * Send updated playlists to peers when tracks are moved/copied. - * Remove splitter handles in sidebar - * Fixed Tomahawk preventing system shutdown / logut. + * Remove splitter handles in sidebar. + * Fixed Tomahawk preventing system shutdown / logout. * Ignore leading 'The' when sorting artists. * Added Charts page, which shows various sources' top hits & artists. * The Collection tree-views can now be filtered. * Fixed crash when pressing enter in an empty playlist. - * Moved the song queue below to the left, below the sidebar. + * Moved the song queue to the bottom of the sidebar. * Added Footnotes, a contextual view that you can slide it. * Show recently added playlists in dashboard rather than recently opened playlists. From 06ba09f35745c05767f29234b665578602aa4048 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 6 Nov 2011 19:53:23 +0100 Subject: [PATCH 05/12] * DbCmd_AddFiles should emit the file-IDs, not the track-IDs. --- src/libtomahawk/database/databasecommand_addfiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtomahawk/database/databasecommand_addfiles.cpp b/src/libtomahawk/database/databasecommand_addfiles.cpp index 6d840a766..4e776178f 100644 --- a/src/libtomahawk/database/databasecommand_addfiles.cpp +++ b/src/libtomahawk/database/databasecommand_addfiles.cpp @@ -211,7 +211,7 @@ DatabaseCommand_AddFiles::exec( DatabaseImpl* dbi ) m_queries << query;*/ - m_ids << trackid; + m_ids << fileid; added++; } qDebug() << "Inserted" << added << "tracks to database"; From 85662bb478b78398823495cfbd93f4cead597c8c Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sun, 6 Nov 2011 17:57:39 -0500 Subject: [PATCH 06/12] Port echonest catalog sync to new collection add/remove --- src/libtomahawk/CMakeLists.txt | 4 +- .../EchonestCatalogSynchronizer.cpp | 71 ++++++++++--------- src/libtomahawk/EchonestCatalogSynchronizer.h | 6 +- src/libtomahawk/collection.h | 8 +-- .../database/databasecommand_loadfile.cpp | 49 ------------- .../database/databasecommand_loadfile.h | 47 ------------ src/libtomahawk/network/streamconnection.cpp | 4 +- src/libtomahawk/result.cpp | 1 - 8 files changed, 49 insertions(+), 141 deletions(-) delete mode 100644 src/libtomahawk/database/databasecommand_loadfile.cpp delete mode 100644 src/libtomahawk/database/databasecommand_loadfile.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index ed0e7c4c9..d2f192676 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -68,7 +68,7 @@ set( libSources database/databasecommand_deletefiles.cpp database/databasecommand_dirmtimes.cpp database/databasecommand_filemtimes.cpp - database/databasecommand_loadfile.cpp + database/databasecommand_loadfiles.cpp database/databasecommand_logplayback.cpp database/databasecommand_addsource.cpp database/databasecommand_sourceoffline.cpp @@ -296,7 +296,7 @@ set( libHeaders database/databasecommand_deletefiles.h database/databasecommand_dirmtimes.h database/databasecommand_filemtimes.h - database/databasecommand_loadfile.h + database/databasecommand_loadfiles.h database/databasecommand_logplayback.h database/databasecommand_addsource.h database/databasecommand_sourceoffline.h diff --git a/src/libtomahawk/EchonestCatalogSynchronizer.cpp b/src/libtomahawk/EchonestCatalogSynchronizer.cpp index 324ac46be..059b87f4c 100644 --- a/src/libtomahawk/EchonestCatalogSynchronizer.cpp +++ b/src/libtomahawk/EchonestCatalogSynchronizer.cpp @@ -22,6 +22,7 @@ #include "database/database.h" #include "database/databasecommand_genericselect.h" #include "database/databasecommand_setcollectionattributes.h" +#include "database/databasecommand_loadfiles.h" #include "tomahawksettings.h" #include "sourcelist.h" #include "query.h" @@ -41,8 +42,8 @@ EchonestCatalogSynchronizer::EchonestCatalogSynchronizer( QObject *parent ) qRegisterMetaType >("QList"); connect( TomahawkSettings::instance(), SIGNAL( changed() ), this, SLOT( checkSettingsChanged() ) ); - connect( SourceList::instance()->getLocal()->collection().data(), SIGNAL( tracksAdded( QList ) ), this, SLOT( tracksAdded( QList ) ), Qt::QueuedConnection ); - connect( SourceList::instance()->getLocal()->collection().data(), SIGNAL( tracksRemoved( QList ) ), this, SLOT( tracksRemoved( QList ) ), Qt::QueuedConnection ); + connect( SourceList::instance()->getLocal()->collection().data(), SIGNAL( tracksAdded( QList ) ), this, SLOT( tracksAdded( QList ) ), Qt::QueuedConnection ); + connect( SourceList::instance()->getLocal()->collection().data(), SIGNAL( tracksRemoved( QList ) ), this, SLOT( tracksRemoved( QList ) ), Qt::QueuedConnection ); const QByteArray artist = TomahawkSettings::instance()->value( "collection/artistCatalog" ).toByteArray(); const QByteArray song = TomahawkSettings::instance()->value( "collection/songCatalog" ).toByteArray(); @@ -81,7 +82,7 @@ EchonestCatalogSynchronizer::checkSettingsChanged() } else if ( !TomahawkSettings::instance()->enableEchonestCatalogs() && m_syncing ) { - tDebug() << "FOund echonest change, doing catalog deletes!"; + tDebug() << "Found echonest change, doing catalog deletes!"; // delete all track nums and catalog ids from our peers { DatabaseCommand_SetTrackAttributes* cmd = new DatabaseCommand_SetTrackAttributes( DatabaseCommand_SetTrackAttributes::EchonestCatalogId ); @@ -123,7 +124,9 @@ EchonestCatalogSynchronizer::catalogDeleted() // If we didn't throw, no errors, so clear our config TomahawkSettings::instance()->setValue( toDel, QString() ); } catch ( const Echonest::ParseError& e ) - {} + { + tLog() << "Error in libechonest parsing catalog delete:" << e.what(); + } } @@ -293,60 +296,60 @@ EchonestCatalogSynchronizer::checkTicket() } void -EchonestCatalogSynchronizer::tracksAdded( const QList< query_ptr >& tracks ) +EchonestCatalogSynchronizer::tracksAdded( const QList< unsigned int >& tracks ) { if ( !m_syncing || m_songCatalog.id().isEmpty() || tracks.isEmpty() ) return; + qDebug() << Q_FUNC_INFO << "Got tracks added from db, fetching metadata" << tracks; + // Get the result_ptrs from the tracks + DatabaseCommand_LoadFiles* cmd = new DatabaseCommand_LoadFiles( tracks ); + connect( cmd, SIGNAL( results( QList ) ), this, SLOT( loadedResults( QList ) ) ); + Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) ); +} + + +void +EchonestCatalogSynchronizer::loadedResults( const QList& results ) +{ QList< QStringList > rawTracks; - foreach( const query_ptr& track, tracks ) + qDebug() << Q_FUNC_INFO << "Got track metadata..." << results.size(); + + foreach( const result_ptr& result, results ) { - // DatabaseCommand_AddFiles sets the track id on the result - int id = -1; - if ( track->results().size() == 1 ) - id = track->results().first()->dbid(); - else - { - tLog() << Q_FUNC_INFO << "No dbid for track we got in tracksAdded()!"; + if ( result.isNull() ) continue; - } - rawTracks << ( QStringList() << QString::number( id ) << track->track() << track->artist() << track->album() ); + + qDebug() << "Metadata for item:" << result->fileId(); + + const QString artist = result->artist().isNull() ? QString() : result->artist()->name(); + const QString album = result->album().isNull() ? QString() : result->album()->name(); + rawTracks << ( QStringList() << QString::number( result->fileId() ) << result->track() << artist << album ); } rawTracksAdd( rawTracks ); } void -EchonestCatalogSynchronizer::tracksRemoved( const QList< query_ptr >& tracks ) +EchonestCatalogSynchronizer::tracksRemoved( const QList< unsigned int >& trackIds ) { - if ( !m_syncing || m_songCatalog.id().isEmpty() || tracks.isEmpty() ) + if ( !m_syncing || m_songCatalog.id().isEmpty() || trackIds.isEmpty() ) return; Echonest::CatalogUpdateEntries entries; - entries.reserve( tracks.size() ); + entries.reserve( trackIds.size() ); - foreach ( const query_ptr& q, tracks ) + foreach ( unsigned int id, trackIds ) { - QByteArray itemId; - if ( q->results().size() > 0 ) - { - // Should always be the case, should have the local result from the db that we are deleting! - itemId = QString::number( q->results().first()->dbid() ).toLatin1(); - } - else - { - tLog() << "Got deleted query_ptr with no local result! Wtf!" << q->track() << q->artist() << q->results(); - continue; - } - - tDebug() << "Deleting item with id:" << itemId; + tDebug() << "Deleting item with id:" << id; Echonest::CatalogUpdateEntry e( Echonest::CatalogTypes::Delete ); - e.setItemId( itemId ); + e.setItemId( QString::number( id ).toLatin1() ); entries.append( e ); } - m_songCatalog.update( entries ); + QNetworkReply* reply = m_songCatalog.update( entries ); + connect( reply, SIGNAL( finished() ), this, SLOT( songUpdateFinished() ) ); } QByteArray diff --git a/src/libtomahawk/EchonestCatalogSynchronizer.h b/src/libtomahawk/EchonestCatalogSynchronizer.h index 408c7583a..c2e4cd06d 100644 --- a/src/libtomahawk/EchonestCatalogSynchronizer.h +++ b/src/libtomahawk/EchonestCatalogSynchronizer.h @@ -54,8 +54,10 @@ signals: private slots: void checkSettingsChanged(); - void tracksAdded( const QList& ); - void tracksRemoved( const QList& ); + void tracksAdded( const QList& ); + void tracksRemoved( const QList& ); + + void loadedResults( const QList& results ); // Echonest slots void songCreateFinished(); diff --git a/src/libtomahawk/collection.h b/src/libtomahawk/collection.h index 7a8b2df37..84fdbb8c2 100644 --- a/src/libtomahawk/collection.h +++ b/src/libtomahawk/collection.h @@ -78,8 +78,8 @@ public: unsigned int lastmodified() const { return m_lastmodified; } signals: - void tracksAdded( const QList& ids ); - void tracksRemoved( const QList& ids ); + void tracksAdded( const QList& fileids ); + void tracksRemoved( const QList& fileids ); void playlistsAdded( const QList& ); void playlistsDeleted( const QList& ); @@ -100,8 +100,8 @@ public slots: void setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& autoplists ); void setStations( const QList< Tomahawk::dynplaylist_ptr >& stations ); - void setTracks( const QList& ids ); - void delTracks( const QList& ids ); + void setTracks( const QList& fileids ); + void delTracks( const QList& fileids ); protected: QString m_name; diff --git a/src/libtomahawk/database/databasecommand_loadfile.cpp b/src/libtomahawk/database/databasecommand_loadfile.cpp deleted file mode 100644 index a7b38b52b..000000000 --- a/src/libtomahawk/database/databasecommand_loadfile.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2010-2011, Christian Muehlhaeuser - * - * 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 . - */ - -#include "databasecommand_loadfile.h" - -#include "databaseimpl.h" -#include "collection.h" -#include "utils/logger.h" - - -DatabaseCommand_LoadFile::DatabaseCommand_LoadFile( const QString& id, QObject* parent ) - : DatabaseCommand( parent ) - , m_id( id ) -{ -} - - -void -DatabaseCommand_LoadFile::exec( DatabaseImpl* dbi ) -{ - Tomahawk::result_ptr r; - // file ids internally are really ints, at least for now: - bool ok; - do - { - unsigned int fid = m_id.toInt( &ok ); - if( !ok ) - break; - - r = dbi->file( fid ); - } while( false ); - - emit result( r ); -} diff --git a/src/libtomahawk/database/databasecommand_loadfile.h b/src/libtomahawk/database/databasecommand_loadfile.h deleted file mode 100644 index 5165b3971..000000000 --- a/src/libtomahawk/database/databasecommand_loadfile.h +++ /dev/null @@ -1,47 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2010-2011, Christian Muehlhaeuser - * - * 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 . - */ - -#ifndef DATABASECOMMAND_LOADFILE_H -#define DATABASECOMMAND_LOADFILE_H - -#include -#include -#include - -#include "databasecommand.h" -#include "result.h" -#include "dllmacro.h" - -class DLLEXPORT DatabaseCommand_LoadFile : public DatabaseCommand -{ -Q_OBJECT - -public: - explicit DatabaseCommand_LoadFile( const QString& id, QObject* parent = 0 ); - virtual void exec( DatabaseImpl* ); - virtual bool doesMutates() const { return false; } - virtual QString commandname() const { return "loadfile"; } - -signals: - void result( const Tomahawk::result_ptr& result ); - -private: - QString m_id; -}; - -#endif // DATABASECOMMAND_LOADFILE_H diff --git a/src/libtomahawk/network/streamconnection.cpp b/src/libtomahawk/network/streamconnection.cpp index d9baee950..e0a655210 100644 --- a/src/libtomahawk/network/streamconnection.cpp +++ b/src/libtomahawk/network/streamconnection.cpp @@ -25,7 +25,7 @@ #include "bufferiodevice.h" #include "network/controlconnection.h" #include "network/servent.h" -#include "database/databasecommand_loadfile.h" +#include "database/databasecommand_loadfiles.h" #include "database/database.h" #include "sourcelist.h" #include "utils/logger.h" @@ -158,7 +158,7 @@ StreamConnection::setup() qDebug() << "in TX mode, fid:" << m_fid; - DatabaseCommand_LoadFile* cmd = new DatabaseCommand_LoadFile( m_fid ); + DatabaseCommand_LoadFiles* cmd = new DatabaseCommand_LoadFiles( m_fid.toUInt() ); connect( cmd, SIGNAL( result( Tomahawk::result_ptr ) ), SLOT( startSending( Tomahawk::result_ptr ) ) ); Database::instance()->enqueue( QSharedPointer( cmd ) ); } diff --git a/src/libtomahawk/result.cpp b/src/libtomahawk/result.cpp index 9df76c3b4..0483a62d6 100644 --- a/src/libtomahawk/result.cpp +++ b/src/libtomahawk/result.cpp @@ -24,7 +24,6 @@ #include "database/databasecommand_resolve.h" #include "database/databasecommand_alltracks.h" #include "database/databasecommand_addfiles.h" -#include "database/databasecommand_loadfile.h" #include "database/databasecommand_loadsocialactions.h" #include "utils/logger.h" From fa5728d773ba20bd1f13772e420f6634e3e5d1c1 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sun, 6 Nov 2011 17:58:20 -0500 Subject: [PATCH 07/12] And add files --- .../database/databasecommand_loadfiles.cpp | 58 +++++++++++++++++++ .../database/databasecommand_loadfiles.h | 57 ++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 src/libtomahawk/database/databasecommand_loadfiles.cpp create mode 100644 src/libtomahawk/database/databasecommand_loadfiles.h diff --git a/src/libtomahawk/database/databasecommand_loadfiles.cpp b/src/libtomahawk/database/databasecommand_loadfiles.cpp new file mode 100644 index 000000000..4cf7a1add --- /dev/null +++ b/src/libtomahawk/database/databasecommand_loadfiles.cpp @@ -0,0 +1,58 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#include "databasecommand_loadfiles.h" + +#include "databaseimpl.h" +#include "collection.h" +#include "utils/logger.h" + + +DatabaseCommand_LoadFiles::DatabaseCommand_LoadFiles( unsigned int id, QObject* parent ) + : DatabaseCommand( parent ) + , m_single( true ) +{ + m_ids << id; +} + +DatabaseCommand_LoadFiles::DatabaseCommand_LoadFiles( const QList& ids, QObject* parent ) + : DatabaseCommand( parent ) + , m_single( false ) + , m_ids( ids ) +{ +} + + +void +DatabaseCommand_LoadFiles::exec( DatabaseImpl* dbi ) +{ + QList resultList; + // file ids internally are really ints, at least for now: + foreach ( unsigned int id, m_ids ) + { + qDebug() << "Loading file from db with id:" << id; + resultList << dbi->file( id ); + } + + Q_ASSERT( !m_single || resultList.size() <= 1 ); + + if ( m_single && !resultList.isEmpty() ) + emit result( resultList.first() ); + else + emit results( resultList ); +} diff --git a/src/libtomahawk/database/databasecommand_loadfiles.h b/src/libtomahawk/database/databasecommand_loadfiles.h new file mode 100644 index 000000000..cfbabe68b --- /dev/null +++ b/src/libtomahawk/database/databasecommand_loadfiles.h @@ -0,0 +1,57 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#ifndef DATABASECOMMAND_LOADFILES_H +#define DATABASECOMMAND_LOADFILES_H + +#include +#include +#include +#include + +#include "databasecommand.h" +#include "result.h" +#include "dllmacro.h" + +/** + Loads a result_ptr from the database from a track dbid. + + If use use the QStringList constructor, isten to results() instead of result() + */ +class DLLEXPORT DatabaseCommand_LoadFiles : public DatabaseCommand +{ +Q_OBJECT + +public: + explicit DatabaseCommand_LoadFiles( unsigned int id, QObject* parent = 0 ); + explicit DatabaseCommand_LoadFiles( const QList& ids, QObject* parent = 0 ); + + virtual void exec( DatabaseImpl* ); + virtual bool doesMutates() const { return false; } + virtual QString commandname() const { return "loadfiles"; } + +signals: + void result( const Tomahawk::result_ptr& result ); + void results( const QList& results ); + +private: + bool m_single; + QList m_ids; +}; + +#endif // DATABASECOMMAND_LOADFILE_H From b53f83aa95a0a492e845249dc990886804a09b84 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sun, 6 Nov 2011 17:58:33 -0500 Subject: [PATCH 08/12] Add fileid to result and rename dbid to trackid --- src/libtomahawk/database/databasecommand_alltracks.cpp | 4 ++-- src/libtomahawk/database/databasecommand_resolve.cpp | 10 +++++----- src/libtomahawk/database/databaseimpl.cpp | 6 ++++-- src/libtomahawk/playlist/trackproxymodel.cpp | 4 ++-- src/libtomahawk/result.cpp | 3 ++- src/libtomahawk/result.h | 8 +++++--- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/libtomahawk/database/databasecommand_alltracks.cpp b/src/libtomahawk/database/databasecommand_alltracks.cpp index 161c72534..8f528bd81 100644 --- a/src/libtomahawk/database/databasecommand_alltracks.cpp +++ b/src/libtomahawk/database/databasecommand_alltracks.cpp @@ -120,7 +120,7 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi ) Tomahawk::artist_ptr artistptr = Tomahawk::Artist::get( query.value( 12 ).toUInt(), artist ); Tomahawk::album_ptr albumptr = Tomahawk::Album::get( query.value( 13 ).toUInt(), album, artistptr ); - result->setId( query.value( 14 ).toUInt() ); + result->setTrackId( query.value( 14 ).toUInt() ); result->setArtist( artistptr ); result->setAlbum( albumptr ); result->setTrack( query.value( 3 ).toString() ); @@ -137,7 +137,7 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi ) QVariantMap attr; attrQuery.prepare( "SELECT k, v FROM track_attributes WHERE id = ?" ); - attrQuery.bindValue( 0, result->dbid() ); + attrQuery.bindValue( 0, result->trackId() ); attrQuery.exec(); while ( attrQuery.next() ) { diff --git a/src/libtomahawk/database/databasecommand_resolve.cpp b/src/libtomahawk/database/databasecommand_resolve.cpp index 8b841ca51..f60e5afee 100644 --- a/src/libtomahawk/database/databasecommand_resolve.cpp +++ b/src/libtomahawk/database/databasecommand_resolve.cpp @@ -156,14 +156,14 @@ DatabaseCommand_Resolve::resolve( DatabaseImpl* lib ) result->setTrack( files_query.value( 12 ).toString() ); result->setRID( uuid() ); result->setAlbumPos( files_query.value( 14 ).toUInt() ); - result->setId( files_query.value( 9 ).toUInt() ); + result->setTrackId( files_query.value( 9 ).toUInt() ); result->setYear( files_query.value( 17 ).toUInt() ); TomahawkSqlQuery attrQuery = lib->newquery(); QVariantMap attr; attrQuery.prepare( "SELECT k, v FROM track_attributes WHERE id = ?" ); - attrQuery.bindValue( 0, result->dbid() ); + attrQuery.bindValue( 0, result->trackId() ); attrQuery.exec(); while ( attrQuery.next() ) { @@ -268,12 +268,12 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib ) result->setTrack( files_query.value( 12 ).toString() ); result->setRID( uuid() ); result->setAlbumPos( files_query.value( 14 ).toUInt() ); - result->setId( files_query.value( 9 ).toUInt() ); + result->setTrackId( files_query.value( 9 ).toUInt() ); result->setYear( files_query.value( 17 ).toUInt() ); for ( int k = 0; k < tracks.count(); k++ ) { - if ( tracks.at( k ).first == (int)result->dbid() ) + if ( tracks.at( k ).first == (int)result->trackId() ) { result->setScore( tracks.at( k ).second ); break; @@ -284,7 +284,7 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib ) QVariantMap attr; attrQuery.prepare( "SELECT k, v FROM track_attributes WHERE id = ?" ); - attrQuery.bindValue( 0, result->dbid() ); + attrQuery.bindValue( 0, result->trackId() ); attrQuery.exec(); while ( attrQuery.next() ) { diff --git a/src/libtomahawk/database/databaseimpl.cpp b/src/libtomahawk/database/databaseimpl.cpp index 9c36e5986..72153c9e6 100644 --- a/src/libtomahawk/database/databaseimpl.cpp +++ b/src/libtomahawk/database/databaseimpl.cpp @@ -249,9 +249,11 @@ DatabaseImpl::file( int fid ) r->setArtist( artist ); r->setAlbum( album ); r->setTrack( query.value( 12 ).toString() ); - r->setId( query.value( 9 ).toUInt() ); + r->setTrackId( query.value( 9 ).toUInt() ); r->setCollection( s->collection() ); r->setScore( 1.0 ); + r->setRID( query.value( 14 ).toString() ); + r->setFileId( fid ); } return r; @@ -608,7 +610,7 @@ DatabaseImpl::resultFromHint( const Tomahawk::query_ptr& origquery ) res->setTrack( query.value( 12 ).toString() ); res->setAlbumPos( query.value( 14 ).toUInt() ); res->setRID( uuid() ); - res->setId( query.value( 9 ).toUInt() ); + res->setTrackId( query.value( 9 ).toUInt() ); res->setCollection( s->collection() ); res->setYear( query.value( 17 ).toUInt() ); } diff --git a/src/libtomahawk/playlist/trackproxymodel.cpp b/src/libtomahawk/playlist/trackproxymodel.cpp index 13ef4c365..cfbea42a7 100644 --- a/src/libtomahawk/playlist/trackproxymodel.cpp +++ b/src/libtomahawk/playlist/trackproxymodel.cpp @@ -331,7 +331,7 @@ TrackProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) c albumpos1 = r->albumpos(); bitrate1 = r->bitrate(); mtime1 = r->modificationTime(); - id1 = r->dbid(); + id1 = r->trackId(); size1 = r->size(); } if ( q2->numResults() ) @@ -343,7 +343,7 @@ TrackProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) c albumpos2 = r->albumpos(); bitrate2 = r->bitrate(); mtime2 = r->modificationTime(); - id2 = r->dbid(); + id2 = r->trackId(); size2 = r->size(); } diff --git a/src/libtomahawk/result.cpp b/src/libtomahawk/result.cpp index 0483a62d6..1fd270c7a 100644 --- a/src/libtomahawk/result.cpp +++ b/src/libtomahawk/result.cpp @@ -60,7 +60,8 @@ Result::Result( const QString& url ) , m_modtime( 0 ) , m_year( 0 ) , m_score( 0 ) - , m_id( 0 ) + , m_trackId( 0 ) + , m_fileId( 0 ) { } diff --git a/src/libtomahawk/result.h b/src/libtomahawk/result.h index 11bfedded..9b9642922 100644 --- a/src/libtomahawk/result.h +++ b/src/libtomahawk/result.h @@ -83,7 +83,8 @@ public: QList< Tomahawk::SocialAction > allSocialActions(); void setScore( float score ) { m_score = score; } - void setId( unsigned int id ) { m_id = id; } + void setTrackId( unsigned int id ) { m_trackId = id; } + void setFileId( unsigned int id ) { m_fileId = id; } void setRID( RID id ) { m_rid = id; } void setCollection( const Tomahawk::collection_ptr& collection ); void setFriendlySource( const QString& s ) { m_friendlySource = s; } @@ -104,7 +105,8 @@ public: QVariantMap attributes() const { return m_attributes; } void setAttributes( const QVariantMap& map ) { m_attributes = map; updateAttributes(); } - unsigned int dbid() const { return m_id; } + unsigned int trackId() const { return m_trackId; } + unsigned int fileId() const { return m_fileId; } public slots: void onSocialActionsLoaded(); @@ -148,7 +150,7 @@ private: QVariantMap m_attributes; - unsigned int m_id; + unsigned int m_trackId, m_fileId; QHash< QString, QVariant > m_currentSocialActions; QList< SocialAction > m_allSocialActions; From 2d92cdade05dff3dc73db77a6bdceca1c64c472f Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sun, 6 Nov 2011 20:33:52 -0500 Subject: [PATCH 09/12] oops --- src/libtomahawk/database/databaseimpl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libtomahawk/database/databaseimpl.cpp b/src/libtomahawk/database/databaseimpl.cpp index 72153c9e6..3a240ec53 100644 --- a/src/libtomahawk/database/databaseimpl.cpp +++ b/src/libtomahawk/database/databaseimpl.cpp @@ -252,7 +252,6 @@ DatabaseImpl::file( int fid ) r->setTrackId( query.value( 9 ).toUInt() ); r->setCollection( s->collection() ); r->setScore( 1.0 ); - r->setRID( query.value( 14 ).toString() ); r->setFileId( fid ); } From c7ac6b5670b266eb17e16171f5349853d5dff359 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 7 Nov 2011 15:42:02 +0100 Subject: [PATCH 10/12] * Don't emit changed() twice in TomahawkSettings. --- src/libtomahawk/tomahawksettings.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/tomahawksettings.cpp b/src/libtomahawk/tomahawksettings.cpp index 6719f63b2..71fc08c21 100644 --- a/src/libtomahawk/tomahawksettings.cpp +++ b/src/libtomahawk/tomahawksettings.cpp @@ -489,32 +489,35 @@ TomahawkSettings::setVerboseNotifications( bool notifications ) setValue( "ui/notifications/verbose", notifications ); } + bool TomahawkSettings::showOfflineSources() const { return value( "collection/sources/showoffline", false ).toBool(); } + void TomahawkSettings::setShowOfflineSources( bool show ) { setValue( "collection/sources/showoffline", show ); } + bool TomahawkSettings::enableEchonestCatalogs() const { return value( "collection/enable_catalogs", false ).toBool(); } + void TomahawkSettings::setEnableEchonestCatalogs( bool enable ) { setValue( "collection/enable_catalogs", enable ); - - emit changed(); } + QByteArray TomahawkSettings::playlistColumnSizes( const QString& playlistid ) const { From f542e97a7025e54d41339bf50bfa1fcb73c7e308 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 7 Nov 2011 16:33:05 +0100 Subject: [PATCH 11/12] * Register QList manually. --- src/tomahawkapp.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index 93cbb330c..c3c401ae4 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -155,8 +155,6 @@ TomahawkApp::init() QFontMetrics fm( f ); TomahawkUtils::setHeaderHeight( fm.height() + 8 ); - registerMetaTypes(); - new TomahawkSettings( this ); TomahawkSettings* s = TomahawkSettings::instance(); @@ -359,11 +357,12 @@ void TomahawkApp::registerMetaTypes() { qRegisterMetaType< QSharedPointer >("QSharedPointer"); - qRegisterMetaType< QList >("QList"); qRegisterMetaType< DBSyncConnection::State >("DBSyncConnection::State"); qRegisterMetaType< msg_ptr >("msg_ptr"); qRegisterMetaType< QList >("QList"); + qRegisterMetaType< QList >("QList"); qRegisterMetaType< QList >("QList"); + qRegisterMetaType< QList >("QList"); qRegisterMetaType< Connection* >("Connection*"); qRegisterMetaType< QAbstractSocket::SocketError >("QAbstractSocket::SocketError"); qRegisterMetaType< QTcpSocket* >("QTcpSocket*"); From 475633c328d6fb8c113e2575956f49692337183c Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 7 Nov 2011 13:52:10 -0500 Subject: [PATCH 12/12] Remove all the QNAM-fuckery, since echonest and liblastfm are probably good now. (Note: will be pushing the change to liblastfm to libechonest as well) --- .../infoplugins/generic/RoviPlugin.cpp | 13 +--- .../infoplugins/generic/RoviPlugin.h | 3 - .../infoplugins/generic/chartsplugin.cpp | 58 +++++--------- .../infoplugins/generic/chartsplugin.h | 1 - .../infoplugins/generic/echonestplugin.cpp | 38 ++++------ .../infoplugins/generic/echonestplugin.h | 3 - .../infoplugins/generic/hypemPlugin.cpp | 24 +----- .../infoplugins/generic/hypemPlugin.h | 3 - .../infoplugins/generic/lastfmplugin.cpp | 28 ------- .../infoplugins/generic/lastfmplugin.h | 2 - .../infoplugins/generic/musicbrainzPlugin.cpp | 19 ++--- .../infoplugins/generic/musicbrainzPlugin.h | 5 -- .../infoplugins/generic/musixmatchplugin.cpp | 16 +--- .../infoplugins/generic/musixmatchplugin.h | 4 - .../infoplugins/generic/spotifyPlugin.cpp | 39 +++------- .../infoplugins/generic/spotifyPlugin.h | 2 - .../infoplugins/mac/adiumplugin.cpp | 5 -- .../infosystem/infoplugins/mac/adiumplugin.h | 2 - .../infoplugins/unix/fdonotifyplugin.h | 2 - .../infosystem/infoplugins/unix/mprisplugin.h | 2 - src/libtomahawk/infosystem/infosystem.cpp | 10 --- src/libtomahawk/infosystem/infosystem.h | 5 -- .../infosystem/infosystemworker.cpp | 75 ------------------- src/libtomahawk/infosystem/infosystemworker.h | 6 -- src/libtomahawk/utils/tomahawkutils.cpp | 2 +- src/settingsdialog.cpp | 18 +---- src/tomahawkapp.cpp | 9 ++- thirdparty/liblastfm2/src/ws/ws.cpp | 5 ++ 28 files changed, 65 insertions(+), 334 deletions(-) diff --git a/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.cpp index c5810440e..3ae3edfc4 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.cpp @@ -52,17 +52,6 @@ RoviPlugin::~RoviPlugin() } - -void -RoviPlugin::namChangedSlot( QNetworkAccessManager* nam ) -{ - if ( !nam ) - return; - - m_nam = nam; -} - - void RoviPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) { @@ -194,7 +183,7 @@ RoviPlugin::makeRequest( QUrl url ) url.addEncodedQueryItem( "sig", generateSig() ); qDebug() << "Rovi request url:" << url.toString(); - return m_nam->get( QNetworkRequest( url ) ); + return TomahawkUtils::nam()->get( QNetworkRequest( url ) ); } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.h b/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.h index 21c81c5a9..4d91caad8 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/RoviPlugin.h @@ -39,7 +39,6 @@ public: virtual ~RoviPlugin(); protected: - virtual void namChangedSlot( QNetworkAccessManager* nam ); virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void pushInfo( QString, Tomahawk::InfoSystem::InfoType, QVariant ) @@ -54,8 +53,6 @@ private: QNetworkReply* makeRequest( QUrl url ); QByteArray generateSig() const; - QNetworkAccessManager* m_nam; - QByteArray m_apiKey; QByteArray m_secret; }; diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index a0b3f9475..1a5094cdb 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -52,6 +52,22 @@ ChartsPlugin::ChartsPlugin() m_chartResources << "billboard" << "itunes" << "rdio" << "wearehunted"; m_supportedGetTypes << InfoChart << InfoChartCapabilities; + + /// Then get each chart from resource + /// We want to prepopulate the breadcrumb to fetch them before they are asked for + if ( !m_chartResources.isEmpty() && m_allChartsMap.isEmpty() ) + { + tDebug() << "ChartsPlugin: InfoChart fetching possible resources"; + foreach ( QVariant resource, m_chartResources ) + { + QUrl url = QUrl( QString( CHART_URL "source/%1" ).arg(resource.toString() ) ); + QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); + tDebug() << "fetching:" << url; + connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) ); + + m_chartsFetchJobs++; + } + } } @@ -61,38 +77,6 @@ ChartsPlugin::~ChartsPlugin() } -void -ChartsPlugin::namChangedSlot( QNetworkAccessManager *nam ) -{ - tDebug() << "ChartsPlugin: namChangedSLot"; - - qDebug() << Q_FUNC_INFO; - if( !nam ) - return; - - m_nam = QWeakPointer< QNetworkAccessManager >( nam ); - - /// Then get each chart from resource - /// We want to prepopulate the breadcrumb to fetch them before they are asked for - - if ( !m_chartResources.isEmpty() && m_nam && m_allChartsMap.isEmpty() ) - { - - tDebug() << "ChartsPlugin: InfoChart fetching possible resources"; - foreach ( QVariant resource, m_chartResources ) - { - QUrl url = QUrl( QString( CHART_URL "source/%1" ).arg(resource.toString() ) ); - QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) ); - tDebug() << "fetching:" << url; - connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) ); - - m_chartsFetchJobs++; - } - - } -} - - void ChartsPlugin::dataError( Tomahawk::InfoSystem::InfoRequestData requestData ) { @@ -202,14 +186,6 @@ ChartsPlugin::fetchChartCapabilities( Tomahawk::InfoSystem::InfoRequestData requ void ChartsPlugin::notInCacheSlot( QHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) { - if ( !m_nam.data() ) - { - tLog() << "Have a null QNAM, uh oh"; - emit info( requestData, QVariant() ); - return; - } - - switch ( requestData.type ) { case InfoChart: @@ -218,7 +194,7 @@ ChartsPlugin::notInCacheSlot( QHash criteria, Tomahawk::InfoSy QUrl url = QUrl( QString( CHART_URL "source/%1/chart/%2" ).arg( criteria["chart_source"] ).arg( criteria["chart_id"] ) ); qDebug() << Q_FUNC_INFO << "Getting chart url" << url; - QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) ); + QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) ); connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) ); diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h index c44b88ccf..285420a14 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h @@ -53,7 +53,6 @@ public: public slots: void chartReturned(); void chartTypes(); - void namChangedSlot( QNetworkAccessManager *nam ); protected slots: virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); diff --git a/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.cpp index 3d4b1e02b..2303a6d22 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.cpp @@ -37,35 +37,12 @@ EchoNestPlugin::EchoNestPlugin() m_supportedGetTypes << Tomahawk::InfoSystem::InfoArtistBiography << Tomahawk::InfoSystem::InfoArtistFamiliarity << Tomahawk::InfoSystem::InfoArtistHotttness << Tomahawk::InfoSystem::InfoArtistTerms << Tomahawk::InfoSystem::InfoMiscTopTerms; } + EchoNestPlugin::~EchoNestPlugin() { qDebug() << Q_FUNC_INFO; } -void -EchoNestPlugin::namChangedSlot( QNetworkAccessManager *nam ) -{ - qDebug() << Q_FUNC_INFO; - if( !nam ) - return; - - QNetworkAccessManager* currNam = Echonest::Config::instance()->nam(); - TomahawkUtils::NetworkProxyFactory* oldProxyFactory = dynamic_cast< TomahawkUtils::NetworkProxyFactory* >( nam->proxyFactory() ); - - if ( !oldProxyFactory ) - { - qDebug() << "Could not get old proxyFactory!"; - return; - } - - currNam->setConfiguration( nam->configuration() ); - currNam->setNetworkAccessible( nam->networkAccessible() ); - TomahawkUtils::NetworkProxyFactory* newProxyFactory = new TomahawkUtils::NetworkProxyFactory(); - newProxyFactory->setNoProxyHosts( oldProxyFactory->noProxyHosts() ); - QNetworkProxy newProxy( oldProxyFactory->proxy() ); - newProxyFactory->setProxy( newProxy ); - currNam->setProxyFactory( newProxyFactory ); -} void EchoNestPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) @@ -92,6 +69,7 @@ EchoNestPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) } } + void EchoNestPlugin::getSongProfile( const Tomahawk::InfoSystem::InfoRequestData &requestData, const QString &item ) { @@ -109,6 +87,7 @@ EchoNestPlugin::getSongProfile( const Tomahawk::InfoSystem::InfoRequestData &req // connect(reply, SIGNAL(finished()), SLOT(getArtistBiographySlot())); } + void EchoNestPlugin::getArtistBiography( const Tomahawk::InfoSystem::InfoRequestData &requestData ) { @@ -122,6 +101,7 @@ EchoNestPlugin::getArtistBiography( const Tomahawk::InfoSystem::InfoRequestData connect( reply, SIGNAL( finished() ), SLOT( getArtistBiographySlot() ) ); } + void EchoNestPlugin::getArtistFamiliarity( const Tomahawk::InfoSystem::InfoRequestData &requestData ) { @@ -136,6 +116,7 @@ EchoNestPlugin::getArtistFamiliarity( const Tomahawk::InfoSystem::InfoRequestDat connect( reply, SIGNAL( finished() ), SLOT( getArtistFamiliaritySlot() ) ); } + void EchoNestPlugin::getArtistHotttnesss( const Tomahawk::InfoSystem::InfoRequestData &requestData ) { @@ -149,6 +130,7 @@ EchoNestPlugin::getArtistHotttnesss( const Tomahawk::InfoSystem::InfoRequestData connect( reply, SIGNAL( finished() ), SLOT( getArtistHotttnesssSlot() ) ); } + void EchoNestPlugin::getArtistTerms( const Tomahawk::InfoSystem::InfoRequestData &requestData ) { @@ -162,6 +144,7 @@ EchoNestPlugin::getArtistTerms( const Tomahawk::InfoSystem::InfoRequestData &req connect( reply, SIGNAL( finished() ), SLOT( getArtistTermsSlot() ) ); } + void EchoNestPlugin::getMiscTopTerms( const Tomahawk::InfoSystem::InfoRequestData &requestData ) { @@ -194,6 +177,7 @@ EchoNestPlugin::getArtistBiographySlot() reply->deleteLater(); } + void EchoNestPlugin::getArtistFamiliaritySlot() { @@ -205,6 +189,7 @@ EchoNestPlugin::getArtistFamiliaritySlot() reply->deleteLater(); } + void EchoNestPlugin::getArtistHotttnesssSlot() { @@ -216,6 +201,7 @@ EchoNestPlugin::getArtistHotttnesssSlot() reply->deleteLater(); } + void EchoNestPlugin::getArtistTermsSlot() { @@ -234,6 +220,7 @@ EchoNestPlugin::getArtistTermsSlot() reply->deleteLater(); } + void EchoNestPlugin::getMiscTopSlot() { @@ -251,6 +238,7 @@ EchoNestPlugin::getMiscTopSlot() reply->deleteLater(); } + bool EchoNestPlugin::isValidArtistData( const Tomahawk::InfoSystem::InfoRequestData &requestData ) { @@ -268,6 +256,7 @@ EchoNestPlugin::isValidArtistData( const Tomahawk::InfoSystem::InfoRequestData & return true; } + bool EchoNestPlugin::isValidTrackData( const Tomahawk::InfoSystem::InfoRequestData &requestData ) { @@ -290,6 +279,7 @@ EchoNestPlugin::isValidTrackData( const Tomahawk::InfoSystem::InfoRequestData &r return true; } + Artist EchoNestPlugin::artistFromReply( QNetworkReply* reply ) { diff --git a/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.h index bd59193c8..73b7932de 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/echonestplugin.h @@ -61,9 +61,6 @@ protected slots: Q_UNUSED( requestData ); } -public slots: - void namChangedSlot( QNetworkAccessManager *nam ); - private: void getSongProfile( const Tomahawk::InfoSystem::InfoRequestData &requestData, const QString &item = QString() ); void getArtistBiography( const Tomahawk::InfoSystem::InfoRequestData &requestData ); diff --git a/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.cpp index dd6a4b7b1..a1df2b20c 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.cpp @@ -102,20 +102,6 @@ hypemPlugin::~hypemPlugin() } -void -hypemPlugin::namChangedSlot( QNetworkAccessManager *nam ) -{ - tDebug() << "hypemPlugin: namChangedSLot"; - qDebug() << Q_FUNC_INFO; - if( !nam ) - return; - - m_nam = QWeakPointer< QNetworkAccessManager >( nam ); - - -} - - void hypemPlugin::dataError( Tomahawk::InfoSystem::InfoRequestData requestData ) { @@ -207,14 +193,6 @@ hypemPlugin::fetchChartCapabilities( Tomahawk::InfoSystem::InfoRequestData reque void hypemPlugin::notInCacheSlot( QHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) { - if ( !m_nam.data() ) - { - tLog() << "Have a null QNAM, uh oh"; - emit info( requestData, QVariant() ); - return; - } - - switch ( requestData.type ) { case InfoChart: @@ -224,7 +202,7 @@ hypemPlugin::notInCacheSlot( QHash criteria, Tomahawk::InfoSys QUrl url = QUrl( QString( HYPEM_URL "%1/%2" ).arg( criteria["chart_id"].toLower() ).arg(HYPEM_END_URL) ); qDebug() << Q_FUNC_INFO << "Getting chart url" << url; - QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) ); + QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) ); connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) ); return; diff --git a/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.h b/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.h index a13c0299d..cbdfb000d 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.h @@ -53,7 +53,6 @@ public: public slots: void chartReturned(); void chartTypes(); - void namChangedSlot( QNetworkAccessManager *nam ); protected slots: virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); @@ -82,8 +81,6 @@ private: QList< InfoRequestData > m_cachedRequests; QHash< QString, QString > m_cachedCountries; - - QWeakPointer< QNetworkAccessManager > m_nam; }; } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp index ed7681642..9d950ad9d 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp @@ -94,34 +94,6 @@ LastFmPlugin::~LastFmPlugin() } -void -LastFmPlugin::namChangedSlot( QNetworkAccessManager *nam ) -{ - if ( !nam ) - return; - - TomahawkUtils::NetworkProxyFactory* oldProxyFactory = dynamic_cast< TomahawkUtils::NetworkProxyFactory* >( nam->proxyFactory() ); - if ( !oldProxyFactory ) - { - tLog() << Q_FUNC_INFO << "Could not get old proxyFactory!"; - return; - } - - //WARNING: there's a chance liblastfm2 will clobber the application proxy factory it if it constructs a nam due to the below call - //but it is unsafe to re-set it here - QNetworkAccessManager* currNam = lastfm::nam(); - - currNam->setConfiguration( nam->configuration() ); - currNam->setNetworkAccessible( nam->networkAccessible() ); - TomahawkUtils::NetworkProxyFactory* newProxyFactory = new TomahawkUtils::NetworkProxyFactory(); - newProxyFactory->setNoProxyHosts( oldProxyFactory->noProxyHosts() ); - QNetworkProxy newProxy( oldProxyFactory->proxy() ); - newProxyFactory->setProxy( newProxy ); - currNam->setProxyFactory( newProxyFactory ); - settingsChanged(); // to get the scrobbler set up -} - - void LastFmPlugin::dataError( Tomahawk::InfoSystem::InfoRequestData requestData ) { diff --git a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.h index fbd372e02..4850fb44c 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.h @@ -53,8 +53,6 @@ public slots: void topTracksReturned(); void chartReturned(); - void namChangedSlot( QNetworkAccessManager *nam ); - protected slots: virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ); diff --git a/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.cpp index 8c0b3c2f4..12f96599e 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.cpp @@ -41,15 +41,6 @@ MusicBrainzPlugin::~MusicBrainzPlugin() } -void -MusicBrainzPlugin::namChangedSlot( QNetworkAccessManager *nam ) -{ - if ( !nam ) - return; - - m_nam = QWeakPointer< QNetworkAccessManager >( nam ); -} - void MusicBrainzPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) { @@ -107,7 +98,7 @@ MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ QString requestString( "http://musicbrainz.org/ws/2/artist" ); QUrl url( requestString ); url.addQueryItem( "query", criteria["artist"] ); - QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) ); + QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) ); connect( reply, SIGNAL( finished() ), SLOT( artistSearchSlot() ) ); @@ -119,7 +110,7 @@ MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ QString requestString( "http://musicbrainz.org/ws/2/artist" ); QUrl url( requestString ); url.addQueryItem( "query", criteria["artist"] ); - QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) ); + QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) ); connect( reply, SIGNAL( finished() ), SLOT( albumSearchSlot() ) ); @@ -182,7 +173,7 @@ MusicBrainzPlugin::artistSearchSlot() QUrl url( requestString ); url.addQueryItem( "artist", artist_id ); - QNetworkReply* newReply = m_nam.data()->get( QNetworkRequest( url ) ); + QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); newReply->setProperty( "requestData", oldReply->property( "requestData" ) ); connect( newReply, SIGNAL( finished() ), SLOT( albumFoundSlot() ) ); } @@ -209,7 +200,7 @@ MusicBrainzPlugin::albumSearchSlot() QUrl url( requestString ); url.addQueryItem( "artist", artist_id ); - QNetworkReply* newReply = m_nam.data()->get( QNetworkRequest( url ) ); + QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); newReply->setProperty( "requestData", oldReply->property( "requestData" ) ); connect( newReply, SIGNAL( finished() ), SLOT( tracksSearchSlot() ) ); } @@ -252,7 +243,7 @@ MusicBrainzPlugin::tracksSearchSlot() QString requestString = QString( "http://musicbrainz.org/ws/2/release/%1?inc=recordings" ).arg( release_id ); QUrl url( requestString ); - QNetworkReply* newReply = m_nam.data()->get( QNetworkRequest( url ) ); + QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); newReply->setProperty( "requestData", oldReply->property( "requestData" ) ); connect( newReply, SIGNAL( finished() ), SLOT( tracksFoundSlot() ) ); } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.h b/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.h index 444b30809..5a2414cc0 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/musicbrainzPlugin.h @@ -38,9 +38,6 @@ public: MusicBrainzPlugin(); virtual ~MusicBrainzPlugin(); -public slots: - void namChangedSlot( QNetworkAccessManager *nam ); - protected slots: virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void notInCacheSlot( InfoStringHash criteria, InfoRequestData requestData ); @@ -63,8 +60,6 @@ private slots: private: bool isValidTrackData( Tomahawk::InfoSystem::InfoRequestData requestData ); - - QWeakPointer< QNetworkAccessManager > m_nam; }; } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.cpp index 05811765a..48eec09bd 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.cpp @@ -42,21 +42,11 @@ MusixMatchPlugin::~MusixMatchPlugin() qDebug() << Q_FUNC_INFO; } -void -MusixMatchPlugin::namChangedSlot( QNetworkAccessManager *nam ) -{ - qDebug() << Q_FUNC_INFO; - if( !nam ) - return; - - m_nam = QWeakPointer< QNetworkAccessManager >( nam ); -} - void MusixMatchPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) { qDebug() << Q_FUNC_INFO; - if( !isValidTrackData( requestData ) || !requestData.input.canConvert< QVariantMap >() || m_nam.isNull() || requestData.type != Tomahawk::InfoSystem::InfoTrackLyrics ) + if( !isValidTrackData( requestData ) || !requestData.input.canConvert< QVariantMap >() || requestData.type != Tomahawk::InfoSystem::InfoTrackLyrics ) return; QVariantMap hash = requestData.input.value< QVariantMap >(); QString artist = hash["artistName"].toString(); @@ -72,7 +62,7 @@ MusixMatchPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) url.addQueryItem( "apikey", m_apiKey ); url.addQueryItem( "q_artist", artist ); url.addQueryItem( "q_track", track ); - QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) ); + QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) ); connect( reply, SIGNAL( finished() ), SLOT( trackSearchSlot() ) ); @@ -126,7 +116,7 @@ MusixMatchPlugin::trackSearchSlot() QUrl url( requestString ); url.addQueryItem( "apikey", m_apiKey ); url.addQueryItem( "track_id", track_id ); - QNetworkReply* newReply = m_nam.data()->get( QNetworkRequest( url ) ); + QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); newReply->setProperty( "requestData", oldReply->property( "requestData" ) ); connect( newReply, SIGNAL( finished() ), SLOT( trackLyricsSlot() ) ); } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.h index 40b1cc536..d0c437b77 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/musixmatchplugin.h @@ -42,8 +42,6 @@ public slots: void trackSearchSlot(); void trackLyricsSlot(); - void namChangedSlot( QNetworkAccessManager *nam ); - protected slots: virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); @@ -64,8 +62,6 @@ private: bool isValidTrackData( Tomahawk::InfoSystem::InfoRequestData requestData ); QString m_apiKey; - - QWeakPointer< QNetworkAccessManager > m_nam; }; } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.cpp index 245ceb593..3ce6cdb3a 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.cpp @@ -47,26 +47,7 @@ SpotifyPlugin::SpotifyPlugin() m_supportedGetTypes << InfoChart << InfoChartCapabilities; -} - - -SpotifyPlugin::~SpotifyPlugin() -{ - qDebug() << Q_FUNC_INFO; -} - - -void -SpotifyPlugin::namChangedSlot( QNetworkAccessManager *nam ) -{ - tDebug() << "SpotifyPlugin: namChangedSLot"; - qDebug() << Q_FUNC_INFO; - if( !nam ) - return; - - m_nam = QWeakPointer< QNetworkAccessManager >( nam ); - - // we never need to re-fetch + // we never need to re-fetch if ( !m_allChartsMap.isEmpty() ) return; @@ -74,7 +55,7 @@ SpotifyPlugin::namChangedSlot( QNetworkAccessManager *nam ) tDebug() << "SpotifyPlugin: InfoChart fetching possible resources"; QUrl url = QUrl( QString( SPOTIFY_API_URL "toplist/charts" ) ); - QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) ); + QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); tDebug() << Q_FUNC_INFO << "fetching:" << url; connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) ); m_chartsFetchJobs++; @@ -82,6 +63,12 @@ SpotifyPlugin::namChangedSlot( QNetworkAccessManager *nam ) } +SpotifyPlugin::~SpotifyPlugin() +{ + qDebug() << Q_FUNC_INFO; +} + + void SpotifyPlugin::dataError( Tomahawk::InfoSystem::InfoRequestData requestData ) { @@ -164,14 +151,6 @@ SpotifyPlugin::fetchChartCapabilities( Tomahawk::InfoSystem::InfoRequestData req void SpotifyPlugin::notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) { - if ( !m_nam.data() ) - { - tLog() << Q_FUNC_INFO << "Have a null QNAM, uh oh"; - emit info( requestData, QVariant() ); - return; - } - - switch ( requestData.type ) { @@ -181,7 +160,7 @@ SpotifyPlugin::notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, To QUrl url = QUrl( QString( SPOTIFY_API_URL "toplist/%1/" ).arg( criteria["chart_id"] ) ); qDebug() << Q_FUNC_INFO << "Getting chart url" << url; - QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) ); + QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) ); connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) ); return; diff --git a/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.h b/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.h index 4a27d826c..e691d5aef 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.h @@ -53,7 +53,6 @@ public: public slots: void chartReturned(); void chartTypes(); - void namChangedSlot( QNetworkAccessManager *nam ); protected slots: virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); @@ -70,7 +69,6 @@ private: QVariantMap m_allChartsMap; uint m_chartsFetchJobs; QList< InfoRequestData > m_cachedRequests; - QWeakPointer< QNetworkAccessManager > m_nam; }; } diff --git a/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.cpp b/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.cpp index 20b907bcc..81626dcbd 100644 --- a/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.cpp @@ -160,11 +160,6 @@ AdiumPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVar m_pauseTimer->stop(); } -void -AdiumPlugin::namChangedSlot( QNetworkAccessManager* nam ) -{ - Q_UNUSED( nam ) -} /** Audio state slots */ void diff --git a/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.h b/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.h index 5f12a510f..5c9d8b5c2 100644 --- a/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/mac/adiumplugin.h @@ -49,8 +49,6 @@ protected slots: void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input ); public slots: - void namChangedSlot( QNetworkAccessManager* nam ); - virtual void notInCacheSlot( const Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) { Q_UNUSED( criteria ); diff --git a/src/libtomahawk/infosystem/infoplugins/unix/fdonotifyplugin.h b/src/libtomahawk/infosystem/infoplugins/unix/fdonotifyplugin.h index d5fbc4759..da0e75c54 100644 --- a/src/libtomahawk/infosystem/infoplugins/unix/fdonotifyplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/unix/fdonotifyplugin.h @@ -35,8 +35,6 @@ public: FdoNotifyPlugin(); virtual ~FdoNotifyPlugin(); - virtual void namChangedSlot( QNetworkAccessManager* ) {} - protected slots: virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) { diff --git a/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h b/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h index 81d8d1507..2ba684808 100644 --- a/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/unix/mprisplugin.h @@ -117,8 +117,6 @@ public: void setVolume( double value ); public slots: - void namChangedSlot( QNetworkAccessManager* /*nam*/ ) {} // unused - virtual void notInCacheSlot( const Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) { Q_UNUSED( criteria ); diff --git a/src/libtomahawk/infosystem/infosystem.cpp b/src/libtomahawk/infosystem/infosystem.cpp index 505aa2119..0ebac2411 100644 --- a/src/libtomahawk/infosystem/infosystem.cpp +++ b/src/libtomahawk/infosystem/infosystem.cpp @@ -72,8 +72,6 @@ InfoSystem::InfoSystem( QObject *parent ) QMetaObject::invokeMethod( m_worker.data(), "init", Qt::QueuedConnection, Q_ARG( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache >, m_cache ) ); - connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( newNam() ) ); - connect( m_cache.data(), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), m_worker.data(), SLOT( infoSlot( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection ); @@ -115,14 +113,6 @@ InfoSystem::~InfoSystem() } -void -InfoSystem::newNam() const -{ - qDebug() << Q_FUNC_INFO; - QMetaObject::invokeMethod( m_worker.data(), "newNam", Qt::QueuedConnection ); -} - - void InfoSystem::getInfo( const InfoRequestData &requestData ) { diff --git a/src/libtomahawk/infosystem/infosystem.h b/src/libtomahawk/infosystem/infosystem.h index 01be362e5..3a95520af 100644 --- a/src/libtomahawk/infosystem/infosystem.h +++ b/src/libtomahawk/infosystem/infosystem.h @@ -185,8 +185,6 @@ protected slots: virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant data ) = 0; virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) = 0; - virtual void namChangedSlot( QNetworkAccessManager *nam ) = 0; - protected: InfoType m_type; QSet< InfoType > m_supportedGetTypes; @@ -251,9 +249,6 @@ signals: void finished( QString target ); void finished( QString target, Tomahawk::InfoSystem::InfoType type ); -public slots: - void newNam() const; - private: QWeakPointer< InfoSystemCache > m_cache; QWeakPointer< InfoSystemWorker > m_worker; diff --git a/src/libtomahawk/infosystem/infosystemworker.cpp b/src/libtomahawk/infosystem/infosystemworker.cpp index b58394130..229c79536 100644 --- a/src/libtomahawk/infosystem/infosystemworker.cpp +++ b/src/libtomahawk/infosystem/infosystemworker.cpp @@ -141,15 +141,7 @@ InfoSystemWorker::init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache> cac cache.data(), SLOT( updateCacheSlot( Tomahawk::InfoSystem::InfoStringHash, qint64, Tomahawk::InfoSystem::InfoType, QVariant ) ) ); - connect( - this, - SIGNAL( namChanged( QNetworkAccessManager* ) ), - plugin.data(), - SLOT( namChangedSlot( QNetworkAccessManager* ) ) - ); } - - QMetaObject::invokeMethod( this, "newNam" ); } @@ -348,73 +340,6 @@ InfoSystemWorker::checkTimeoutsTimerFired() } -QNetworkAccessManager* -InfoSystemWorker::nam() const -{ - if ( m_nam.isNull() ) - return 0; - - return m_nam.data(); -} - - -void -InfoSystemWorker::newNam() -{ - QNetworkAccessManager *oldNam = TomahawkUtils::nam(); - if ( oldNam && oldNam->thread() == thread() ) - { - if ( m_nam.data() != oldNam ) - { - m_nam = QWeakPointer< QNetworkAccessManager >( oldNam ); - emit namChanged( m_nam.data() ); - } - return; - } - - if - ( - oldNam && - !m_nam.isNull() && - oldNam->configuration() == m_nam.data()->configuration() && - oldNam->networkAccessible() == m_nam.data()->networkAccessible() - ) - { - TomahawkUtils::NetworkProxyFactory fac1 = *( dynamic_cast< TomahawkUtils::NetworkProxyFactory * >( oldNam->proxyFactory() ) ); - TomahawkUtils::NetworkProxyFactory fac2 = *( dynamic_cast< TomahawkUtils::NetworkProxyFactory * >( m_nam.data()->proxyFactory() ) ); - if ( fac1 == fac2 ) - return; - } - - QNetworkAccessManager* newNam; -#ifdef LIBLASTFM_FOUND - newNam = new lastfm::NetworkAccessManager( this ); -#else - newNam = new QNetworkAccessManager( this ); -#endif - if ( !m_nam.isNull() ) - delete m_nam.data(); - - if ( !oldNam ) - oldNam = new QNetworkAccessManager(); - - TomahawkUtils::NetworkProxyFactory* oldProxyFactory = TomahawkUtils::proxyFactory(); - if ( !oldProxyFactory ) - oldProxyFactory = new TomahawkUtils::NetworkProxyFactory(); - - newNam->setConfiguration( oldNam->configuration() ); - newNam->setNetworkAccessible( oldNam->networkAccessible() ); - TomahawkUtils::NetworkProxyFactory* newProxyFactory = new TomahawkUtils::NetworkProxyFactory(); - newProxyFactory->setNoProxyHosts( oldProxyFactory->noProxyHosts() ); - newProxyFactory->setProxy( oldProxyFactory->proxy() ); - newNam->setProxyFactory( newProxyFactory ); - m_nam = QWeakPointer< QNetworkAccessManager >( newNam ); - - emit namChanged( m_nam.data() ); - - //FIXME: Currently leaking nam/proxyfactory above -- how to change in a thread-safe way? -} - } //namespace InfoSystem } //namespace Tomahawk diff --git a/src/libtomahawk/infosystem/infosystemworker.h b/src/libtomahawk/infosystem/infosystemworker.h index 3bcdd1b62..2368f28bf 100644 --- a/src/libtomahawk/infosystem/infosystemworker.h +++ b/src/libtomahawk/infosystem/infosystemworker.h @@ -54,8 +54,6 @@ signals: void finished( QString target ); void finished( QString target, Tomahawk::InfoSystem::InfoType type ); - void namChanged( QNetworkAccessManager* ); - public slots: void init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > cache ); void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); @@ -63,8 +61,6 @@ public slots: void infoSlot( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); - void newNam(); - private slots: void checkTimeoutsTimerFired(); @@ -84,8 +80,6 @@ private: QMap< InfoType, QList< InfoPluginPtr > > m_infoGetMap; QMap< InfoType, QList< InfoPluginPtr > > m_infoPushMap; - QWeakPointer< QNetworkAccessManager> m_nam; - QTimer m_checkTimeoutsTimer; }; diff --git a/src/libtomahawk/utils/tomahawkutils.cpp b/src/libtomahawk/utils/tomahawkutils.cpp index 3797557da..c56700ed6 100644 --- a/src/libtomahawk/utils/tomahawkutils.cpp +++ b/src/libtomahawk/utils/tomahawkutils.cpp @@ -539,7 +539,7 @@ setProxyFactory( NetworkProxyFactory* factory ) s_proxyFactory = factory; NetworkProxyFactory::setApplicationProxyFactory( s_proxyFactory ); //nam takes ownership so set a copy, not the global one - if ( s_nam ) + if ( !s_nam.isNull() ) { TomahawkUtils::NetworkProxyFactory* newProxyFactory = new TomahawkUtils::NetworkProxyFactory(); newProxyFactory->setNoProxyHosts( factory->noProxyHosts() ); diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 676888071..0c75b151c 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -415,21 +415,9 @@ SettingsDialog::testLastFmLogin() query[ "username" ] = ui->lineEditLastfmUsername->text().toLower(); query[ "authToken" ] = authToken; - TomahawkUtils::NetworkProxyFactory* oldProxyFactory = TomahawkUtils::proxyFactory(); - QNetworkAccessManager* nam = TomahawkUtils::nam(); - - //WARNING: there's a chance liblastfm2 will clobber the application proxy factory it if it constructs a nam due to the below call - //but it is unsafe to re-set it here - QNetworkAccessManager* currNam = lastfm::nam(); - - currNam->setConfiguration( nam->configuration() ); - currNam->setNetworkAccessible( nam->networkAccessible() ); - TomahawkUtils::NetworkProxyFactory* newProxyFactory = new TomahawkUtils::NetworkProxyFactory(); - newProxyFactory->setNoProxyHosts( oldProxyFactory->noProxyHosts() ); - QNetworkProxy newProxy( oldProxyFactory->proxy() ); - newProxyFactory->setProxy( newProxy ); - currNam->setProxyFactory( newProxyFactory ); - + // ensure they have up-to-date settings + lastfm::setNetworkAccessManager( TomahawkUtils::nam() ); + QNetworkReply* authJob = lastfm::ws::post( query ); connect( authJob, SIGNAL( finished() ), SLOT( onLastFmFinished() ) ); diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index c3c401ae4..d4e0c2add 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -159,10 +159,12 @@ TomahawkApp::init() TomahawkSettings* s = TomahawkSettings::instance(); tDebug( LOGINFO ) << "Setting NAM."; -#ifdef LIBLASTFM_FOUND - TomahawkUtils::setNam( lastfm::nam() ); -#else +#ifndef LIBLASTFM_FOUND TomahawkUtils::setNam( new QNetworkAccessManager() ); +#else + TomahawkUtils::setNam( lastfm::nam() ); + //Ensure that liblastfm2 won't delete the nam out from under us, even though they created it + lastfm::setNetworkAccessManager( TomahawkUtils::nam() ); #endif TomahawkUtils::NetworkProxyFactory* proxyFactory = new TomahawkUtils::NetworkProxyFactory(); @@ -178,6 +180,7 @@ TomahawkApp::init() proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ',', QString::SkipEmptyParts ) ); TomahawkUtils::setProxyFactory( proxyFactory ); + m_audioEngine = QWeakPointer( new AudioEngine ); m_scanManager = QWeakPointer( new ScanManager( this ) ); diff --git a/thirdparty/liblastfm2/src/ws/ws.cpp b/thirdparty/liblastfm2/src/ws/ws.cpp index 956fa5adb..b2ad56860 100644 --- a/thirdparty/liblastfm2/src/ws/ws.cpp +++ b/thirdparty/liblastfm2/src/ws/ws.cpp @@ -160,7 +160,12 @@ lastfm::setNetworkAccessManager( QNetworkAccessManager* nam ) oldNam = threadNamHash[thread]; if ( oldNam == nam ) + { + // If we're being passed back our own NAM, assume they want to + // ensure that we don't delete it out from under them + ourNamSet.remove( thread ); return; + } threadNamHash[thread] = nam; ourNamSet.remove( thread );