From 45e6d52db77c161bc47e9610800685853df10918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 20 Oct 2014 17:05:17 +0200 Subject: [PATCH 1/7] DropJob: don't touch iterator after erasing element Also drops a redundant condition --- src/libtomahawk/DropJob.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/libtomahawk/DropJob.cpp b/src/libtomahawk/DropJob.cpp index 17f517a2f..4ff08893a 100644 --- a/src/libtomahawk/DropJob.cpp +++ b/src/libtomahawk/DropJob.cpp @@ -263,9 +263,14 @@ bool DropJob::validateLocalFiles(const QString &paths, const QString &suffix) { QStringList filePaths = paths.split( QRegExp( "\\s+" ), QString::SkipEmptyParts ); - for ( QStringList::iterator it = filePaths.begin(); it != filePaths.end(); ++it ) + QStringList::iterator it = filePaths.begin(); + while (it != filePaths.end()) + { if ( !validateLocalFile( *it, suffix ) ) - filePaths.erase( it ); + it = filePaths.erase( it ); + else + ++it; + } return !filePaths.isEmpty(); } @@ -977,7 +982,7 @@ DropJob::removeRemoteSources() foreach ( const Tomahawk::result_ptr& result, item->results() ) { if ( !result->collection().isNull() && !result->collection()->source().isNull() && - !result->collection()->source().isNull() && result->collection()->source()->isLocal() ) + result->collection()->source()->isLocal() ) hasLocalSource = true; } if ( hasLocalSource ) From 655edf3e98567007d16fc0a2e9c9e929e81c1b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 20 Oct 2014 17:10:52 +0200 Subject: [PATCH 2/7] Catch exception by reference --- src/libtomahawk/accounts/lastfm/LastFmConfig.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/accounts/lastfm/LastFmConfig.cpp b/src/libtomahawk/accounts/lastfm/LastFmConfig.cpp index 085ae9b20..e2076b015 100644 --- a/src/libtomahawk/accounts/lastfm/LastFmConfig.cpp +++ b/src/libtomahawk/accounts/lastfm/LastFmConfig.cpp @@ -184,7 +184,7 @@ LastFmConfig::onHistoryLoaded() else finished = true; } - catch( lastfm::ws::ParseError e ) + catch( lastfm::ws::ParseError& e ) { tDebug() << "XmlQuery error:" << e.message(); finished = true; @@ -326,7 +326,7 @@ LastFmConfig::onLovedFinished( QNetworkReply* reply ) emit sizeHintChanged(); } } - catch( lastfm::ws::ParseError e ) + catch( lastfm::ws::ParseError& e ) { m_ui->syncLovedTracks->setText( "Failed" ); m_ui->progressBar->hide(); From eee50b2f9362c2a9473c7352aa5002230b7814ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 20 Oct 2014 17:13:44 +0200 Subject: [PATCH 3/7] Remove dead code Q_ASSERT(Compiler isn't a total moron); --- src/libtomahawk/database/DatabaseCommand_LoadPlaylistEntries.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libtomahawk/database/DatabaseCommand_LoadPlaylistEntries.cpp b/src/libtomahawk/database/DatabaseCommand_LoadPlaylistEntries.cpp index 01606b7af..e55b7f6d4 100644 --- a/src/libtomahawk/database/DatabaseCommand_LoadPlaylistEntries.cpp +++ b/src/libtomahawk/database/DatabaseCommand_LoadPlaylistEntries.cpp @@ -119,7 +119,6 @@ DatabaseCommand_LoadPlaylistEntries::generateEntries( DatabaseImpl* dbi ) if ( !query_entries_old.next() ) { return; - Q_ASSERT( false ); } if ( !query_entries_old.value( 0 ).isNull() ) From 46239947f527316fa07413d3f9c72bc7ee6c576b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 20 Oct 2014 17:23:34 +0200 Subject: [PATCH 4/7] Servent: Fix IP protocol version distinction Uwe failed at C&P! --- src/libtomahawk/network/Servent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtomahawk/network/Servent.cpp b/src/libtomahawk/network/Servent.cpp index 2be1618a2..3ec755140 100644 --- a/src/libtomahawk/network/Servent.cpp +++ b/src/libtomahawk/network/Servent.cpp @@ -274,7 +274,7 @@ Servent::isValidExternalIP( const QHostAddress& addr ) if ( addr.isInSubnet(QHostAddress::parseSubnet( "224.0.0.0/4" ) ) ) return false; } - else if (addr.protocol() == QAbstractSocket::IPv4Protocol) + else if (addr.protocol() == QAbstractSocket::IPv6Protocol) { // "unspecified address" if ( addr.isInSubnet(QHostAddress::parseSubnet( "::/128" ) ) ) From 69653c4934b9ea450327c4dee237df05d6852628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 20 Oct 2014 17:35:41 +0200 Subject: [PATCH 5/7] Reduce variable scopes --- src/libtomahawk/Source.cpp | 7 ++----- src/libtomahawk/playlist/AlbumModel.cpp | 9 +++------ src/libtomahawk/playlist/PlayableModel.cpp | 3 +-- src/libtomahawk/playlist/PlaylistModel.cpp | 3 +-- src/libtomahawk/playlist/TreeModel.cpp | 9 +++------ src/libtomahawk/resolvers/JSResolver.cpp | 3 +-- src/libtomahawk/resolvers/ScriptEngine.cpp | 3 +-- 7 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/libtomahawk/Source.cpp b/src/libtomahawk/Source.cpp index 630456814..aab6e2b85 100644 --- a/src/libtomahawk/Source.cpp +++ b/src/libtomahawk/Source.cpp @@ -235,9 +235,6 @@ Source::friendlyNamesLessThan( const QString& first, const QString& second ) favored.append( QRegExp( "\\b([A-Z][a-z']* ?){2,10}" ) ); //properly capitalized person's name favored.append( QRegExp( "[a-zA-Z ']+" ) ); //kind of person's name - bool matchFirst = false; - bool matchSecond = false; - //We check if the strings match the regexps. The regexps represent friendly name patterns we do //*not* want (penalties) or want (favored), prioritized. If none of the strings match a regexp, //we go to the next regexp. If one of the strings matches, and we're matching penalties, we say @@ -261,8 +258,8 @@ Source::friendlyNamesLessThan( const QString& first, const QString& second ) isPenalty = false; } - matchFirst = rx.exactMatch( first ); - matchSecond = rx.exactMatch( second ); + bool matchFirst = rx.exactMatch( first ); + bool matchSecond = rx.exactMatch( second ); if ( matchFirst == false && matchSecond == false ) continue; diff --git a/src/libtomahawk/playlist/AlbumModel.cpp b/src/libtomahawk/playlist/AlbumModel.cpp index 9996c7871..a144215de 100644 --- a/src/libtomahawk/playlist/AlbumModel.cpp +++ b/src/libtomahawk/playlist/AlbumModel.cpp @@ -144,10 +144,9 @@ AlbumModel::addAlbums( const QList& albums ) emit beginInsertRows( QModelIndex(), crows.first, crows.second ); - PlayableItem* albumitem; foreach( const album_ptr& album, trimmedAlbums ) { - albumitem = new PlayableItem( album, rootItem() ); + PlayableItem* albumitem = new PlayableItem( album, rootItem() ); albumitem->index = createIndex( rootItem()->children.count() - 1, 0, albumitem ); connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); @@ -190,10 +189,9 @@ AlbumModel::addArtists( const QList& artists ) emit beginInsertRows( QModelIndex(), crows.first, crows.second ); - PlayableItem* albumitem; foreach ( const artist_ptr& artist, trimmedArtists ) { - albumitem = new PlayableItem( artist, rootItem() ); + PlayableItem* albumitem = new PlayableItem( artist, rootItem() ); albumitem->index = createIndex( rootItem()->children.count() - 1, 0, albumitem ); connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); @@ -219,10 +217,9 @@ AlbumModel::addQueries( const QList& queries ) emit beginInsertRows( QModelIndex(), crows.first, crows.second ); - PlayableItem* albumitem; foreach ( const query_ptr& query, queries ) { - albumitem = new PlayableItem( query, rootItem() ); + PlayableItem* albumitem = new PlayableItem( query, rootItem() ); albumitem->index = createIndex( rootItem()->children.count() - 1, 0, albumitem ); connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index d00ae45c6..0f261c98e 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -679,11 +679,10 @@ PlayableModel::insertInternal( const QList< T >& items, int row, const QList< To emit beginInsertRows( parent, crows.first, crows.second ); int i = 0; - PlayableItem* plitem; foreach ( const T& item, items ) { PlayableItem* pItem = itemFromIndex( parent ); - plitem = new PlayableItem( item, pItem, row + i ); + PlayableItem* plitem = new PlayableItem( item, pItem, row + i ); plitem->index = createIndex( row + i, 0, plitem ); if ( plitem->query() ) diff --git a/src/libtomahawk/playlist/PlaylistModel.cpp b/src/libtomahawk/playlist/PlaylistModel.cpp index 6051d2ff8..46b955443 100644 --- a/src/libtomahawk/playlist/PlaylistModel.cpp +++ b/src/libtomahawk/playlist/PlaylistModel.cpp @@ -290,11 +290,10 @@ PlaylistModel::insertEntries( const QList< Tomahawk::plentry_ptr >& entries, int QList< Tomahawk::query_ptr > queries; int i = 0; - PlayableItem* plitem; foreach( const plentry_ptr& entry, entries ) { PlayableItem* pItem = itemFromIndex( parent ); - plitem = new PlayableItem( entry, pItem, row + i ); + PlayableItem* plitem = new PlayableItem( entry, pItem, row + i ); plitem->index = createIndex( row + i, 0, plitem ); if ( logs.count() > i ) diff --git a/src/libtomahawk/playlist/TreeModel.cpp b/src/libtomahawk/playlist/TreeModel.cpp index 45cbdc2b5..47c27ed0d 100644 --- a/src/libtomahawk/playlist/TreeModel.cpp +++ b/src/libtomahawk/playlist/TreeModel.cpp @@ -193,10 +193,9 @@ TreeModel::addAlbums( const QModelIndex& parent, const QListindex = createIndex( parentItem->children.count() - 1, 0, albumitem ); connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); @@ -283,10 +282,9 @@ TreeModel::onArtistsAdded( const QList& artists ) emit beginInsertRows( QModelIndex(), crows.first, crows.second ); - PlayableItem* artistitem; foreach( const artist_ptr& artist, artists ) { - artistitem = new PlayableItem( artist, rootItem() ); + PlayableItem* artistitem = new PlayableItem( artist, rootItem() ); artistitem->index = createIndex( rootItem()->children.count() - 1, 0, artistitem ); connect( artistitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); } @@ -312,10 +310,9 @@ TreeModel::onTracksAdded( const QList& tracks, const QModel emit beginInsertRows( parent, crows.first, crows.second ); - PlayableItem* item = 0; foreach( const query_ptr& query, tracks ) { - item = new PlayableItem( query, parentItem ); + PlayableItem* item = new PlayableItem( query, parentItem ); item->index = createIndex( parentItem->children.count() - 1, 0, item ); connect( item, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); diff --git a/src/libtomahawk/resolvers/JSResolver.cpp b/src/libtomahawk/resolvers/JSResolver.cpp index 235bc159c..9aa0580da 100644 --- a/src/libtomahawk/resolvers/JSResolver.cpp +++ b/src/libtomahawk/resolvers/JSResolver.cpp @@ -846,12 +846,11 @@ JSResolver::loadCollections() if ( collectionInfo.contains( "iconfile" ) ) { - bool ok = false; QString iconPath = QFileInfo( filePath() ).path() + "/" + collectionInfo.value( "iconfile" ).toString(); QPixmap iconPixmap; - ok = iconPixmap.load( iconPath ); + bool ok = iconPixmap.load( iconPath ); if ( ok && !iconPixmap.isNull() ) sc->setIcon( QIcon( iconPixmap ) ); } diff --git a/src/libtomahawk/resolvers/ScriptEngine.cpp b/src/libtomahawk/resolvers/ScriptEngine.cpp index 933d7b7e1..a347cd729 100644 --- a/src/libtomahawk/resolvers/ScriptEngine.cpp +++ b/src/libtomahawk/resolvers/ScriptEngine.cpp @@ -74,7 +74,6 @@ ScriptEngine::sslErrorHandler( QNetworkReply* qnr, const QList& errli tDebug() << Q_FUNC_INFO; QByteArray digest = errlist.first().certificate().digest(); - int result = -1; if ( !TomahawkSettings::instance()->isSslCertKnown( digest ) ) { @@ -92,7 +91,7 @@ ScriptEngine::sslErrorHandler( QNetworkReply* qnr, const QList& errli question.setStandardButtons( QMessageBox::No ); question.addButton( tr( "Trust certificate" ), QMessageBox::AcceptRole ); - result = question.exec(); + int result = question.exec(); //FIXME: discuss whether we want to store rejects, too (needs settings management to remove the decision?) if ( result == QMessageBox::AcceptRole ) From d74c465e5822f7041f49af3a7ff40daa7778abd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 20 Oct 2014 17:36:20 +0200 Subject: [PATCH 6/7] Remove break after return, it is redundant --- src/libtomahawk/playlist/PlayableModel.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index 0f261c98e..5f33b7184 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -269,7 +269,6 @@ PlayableModel::queryData( const query_ptr& query, int column, int role ) const case Age: return TomahawkUtils::ageToString( QDateTime::fromTime_t( query->results().first()->modificationTime() ) ); - break; case Year: if ( query->results().first()->track()->year() != 0 ) @@ -278,11 +277,9 @@ PlayableModel::queryData( const query_ptr& query, int column, int role ) const case Filesize: return TomahawkUtils::filesizeToString( query->results().first()->size() ); - break; case Origin: return query->results().first()->friendlySource(); - break; case Score: { @@ -293,7 +290,6 @@ PlayableModel::queryData( const query_ptr& query, int column, int role ) const score = 0.0; return scoreText( score ); - break; } default: From 8bb14cc26cb0e8ea322f6c2616dddfbecaa8e6a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 20 Oct 2014 17:36:36 +0200 Subject: [PATCH 7/7] Unsigned comparison <= 0 is identical to check for 0 --- src/libtomahawk/resolvers/JSResolver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtomahawk/resolvers/JSResolver.cpp b/src/libtomahawk/resolvers/JSResolver.cpp index 9aa0580da..719133f93 100644 --- a/src/libtomahawk/resolvers/JSResolver.cpp +++ b/src/libtomahawk/resolvers/JSResolver.cpp @@ -557,7 +557,7 @@ JSResolver::parseResultVariantList( const QVariantList& reslist ) continue; unsigned int duration = m.value( "duration", 0 ).toUInt(); - if ( duration <= 0 && m.contains( "durationString" ) ) + if ( duration == 0 && m.contains( "durationString" ) ) { QTime time = QTime::fromString( m.value( "durationString" ).toString(), "hh:mm:ss" ); duration = time.secsTo( QTime( 0, 0 ) ) * -1;