mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 21:57:41 +02:00
Validate localfiles
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "DropJob.h"
|
#include "DropJob.h"
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
#include "Artist.h"
|
#include "Artist.h"
|
||||||
#include "Album.h"
|
#include "Album.h"
|
||||||
@@ -113,13 +114,15 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
|
|||||||
|
|
||||||
|
|
||||||
const QString url = data->data( "text/plain" );
|
const QString url = data->data( "text/plain" );
|
||||||
|
const QString urlList = data->data( "text/uri-list" ).trimmed();
|
||||||
|
|
||||||
if ( acceptedType.testFlag( Playlist ) )
|
if ( acceptedType.testFlag( Playlist ) )
|
||||||
{
|
{
|
||||||
if ( url.contains( "xml" ) && url.contains( "iTunes") )
|
if ( url.contains( "xml" ) && url.contains( "iTunes" ) )
|
||||||
return true;
|
return validateLocalFile( url, "xml" );
|
||||||
|
|
||||||
if ( data->data( "text/uri-list" ).contains( "xml" ) && data->data( "text/uri-list" ).contains( "iTunes") )
|
if ( urlList.contains( "xml" ) && urlList.contains( "iTunes" ) )
|
||||||
return true;
|
return validateLocalFiles( urlList, "xml" );
|
||||||
|
|
||||||
if ( url.contains( "xspf" ) )
|
if ( url.contains( "xspf" ) )
|
||||||
return true;
|
return true;
|
||||||
@@ -127,10 +130,10 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
|
|||||||
if ( url.contains( "m3u" ) )
|
if ( url.contains( "m3u" ) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( data->data( "text/uri-list" ).contains( "xspf" ) )
|
if ( urlList.contains( "m3u" ) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( data->data( "text/uri-list" ).contains( "m3u" ) )
|
if ( urlList.contains( "xspf" ) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Not the most elegant
|
// Not the most elegant
|
||||||
@@ -152,7 +155,7 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
|
|||||||
if ( url.contains( "m3u" ) )
|
if ( url.contains( "m3u" ) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( data->data( "text/uri-list" ).contains( "m3u" ) )
|
if ( urlList.contains( "m3u" ) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( url.contains( "itunes" ) && url.contains( "album" ) ) // YES itunes is fucked up and song links have album/ in the url.
|
if ( url.contains( "itunes" ) && url.contains( "album" ) ) // YES itunes is fucked up and song links have album/ in the url.
|
||||||
@@ -205,22 +208,45 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
DropJob::validateLocalFile( const QString &path, const QString &suffix )
|
||||||
|
{
|
||||||
|
QFileInfo info( QUrl::fromUserInput( path ).toLocalFile() );
|
||||||
|
if ( suffix.isEmpty() )
|
||||||
|
return info.exists();
|
||||||
|
return ( info.exists() && info.suffix() == suffix );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 )
|
||||||
|
if ( !validateLocalFile( *it, suffix ) )
|
||||||
|
filePaths.erase( it );
|
||||||
|
return !filePaths.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
DropJob::isDropType( DropJob::DropType desired, const QMimeData* data )
|
DropJob::isDropType( DropJob::DropType desired, const QMimeData* data )
|
||||||
{
|
{
|
||||||
const QString url = data->data( "text/plain" );
|
const QString url = data->data( "text/plain" );
|
||||||
|
const QString urlList = data->data( "text/uri-list" ).trimmed();
|
||||||
|
|
||||||
if ( desired == Playlist )
|
if ( desired == Playlist )
|
||||||
{
|
{
|
||||||
if ( url.contains( "xml" ) && url.contains( "iTunes") )
|
if ( url.contains( "xml" ) && url.contains( "iTunes" ) )
|
||||||
|
return validateLocalFile( url, "xml" );
|
||||||
|
|
||||||
|
if ( urlList.contains( "xml" ) && urlList.contains( "iTunes" ) )
|
||||||
|
return validateLocalFiles( urlList, "xml" );
|
||||||
|
|
||||||
|
if( url.contains( "xspf" ) || urlList.contains( "xspf" ) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( data->data( "text/uri-list" ).contains( "xml" ) && data->data( "text/uri-list" ).contains( "iTunes") )
|
if( url.contains( "m3u" ) || urlList.contains( "m3u" ) )
|
||||||
return true;
|
|
||||||
|
|
||||||
if( url.contains( "xspf" ) || data->data( "text/uri-list").contains( "xspf" ) )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if( url.contains( "m3u" ) || data->data( "text/uri-list").contains( "m3u" ) )
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Not the most elegant
|
// Not the most elegant
|
||||||
@@ -698,7 +724,8 @@ DropJob::handleTrackUrls( const QString& urls )
|
|||||||
|
|
||||||
if ( urls.contains( "xml" ) && urls.contains( "iTunes" ) )
|
if ( urls.contains( "xml" ) && urls.contains( "iTunes" ) )
|
||||||
{
|
{
|
||||||
new ItunesLoader( urls, this );
|
QStringList paths = urls.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
|
||||||
|
new ItunesLoader( paths.first(), this );
|
||||||
}
|
}
|
||||||
else if ( urls.contains( "itunes.apple.com") )
|
else if ( urls.contains( "itunes.apple.com") )
|
||||||
{
|
{
|
||||||
|
@@ -137,6 +137,9 @@ private:
|
|||||||
void removeDuplicates();
|
void removeDuplicates();
|
||||||
void removeRemoteSources();
|
void removeRemoteSources();
|
||||||
|
|
||||||
|
static bool validateLocalFile( const QString& path, const QString& suffix = QString() );
|
||||||
|
static bool validateLocalFiles( const QString& paths, const QString& suffix = QString() );
|
||||||
|
|
||||||
int m_queryCount;
|
int m_queryCount;
|
||||||
bool m_allowDuplicates;
|
bool m_allowDuplicates;
|
||||||
bool m_onlyLocal;
|
bool m_onlyLocal;
|
||||||
|
Reference in New Issue
Block a user