1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 08:34:34 +02:00

Fix nullpointer crash, set resulthint

This commit is contained in:
Hugo Lindström
2012-09-22 14:26:01 +02:00
parent bed69b4838
commit 069c25ec95
2 changed files with 26 additions and 3 deletions

View File

@@ -22,10 +22,9 @@
#include "utils/TomahawkUtils.h"
#include "Query.h"
#include "SourceList.h"
#include "Playlist.h"
#include "DropJob.h"
#include "ViewManager.h"
#include <QFileInfo>
#include <QFile>
@@ -76,8 +75,11 @@ M3uLoader::getTags( const QFileInfo& info )
const char *encodedName = fileName.constData();
TagLib::FileRef f( encodedName );
if( f.isNull() )
return;
TagLib::Tag *tag = f.tag();
if( !tag )
return;
QString artist = TStringToQString( tag->artist() ).trimmed();
QString album = TStringToQString( tag->album() ).trimmed();
QString track = TStringToQString( tag->title() ).trimmed();
@@ -92,8 +94,13 @@ M3uLoader::getTags( const QFileInfo& info )
qDebug() << Q_FUNC_INFO << artist << track << album;
Tomahawk::query_ptr q = Tomahawk::Query::get( artist, track, album, uuid(), !m_createNewPlaylist );
if ( !q.isNull() )
{
q->setResultHint( "file://" + info.absoluteFilePath() );
q->setSaveHTTPResultHint( true );
qDebug() << "ADding resulthint" << q->resultHint();
m_tracks << q;
}
}
}
@@ -110,6 +117,7 @@ M3uLoader::parseM3u( const QString& fileLink )
}
m_title = fileInfo.baseName();
while ( !file.atEnd() )
{
QByteArray line = file.readLine();
@@ -122,16 +130,21 @@ M3uLoader::parseM3u( const QString& fileLink )
QFileInfo tmpFile( QUrl::fromUserInput( QString( line.simplified() ) ).toLocalFile() );
if( tmpFile.exists() )
{
getTags( tmpFile );
}
else
{
QUrl fileUrl = QUrl::fromUserInput( QString( QFileInfo(file).canonicalPath() + "/" + line.simplified() ) );
QFileInfo tmpFile( fileUrl.toLocalFile() );
if ( tmpFile.exists() )
{
getTags( tmpFile );
}
}
}
if ( m_tracks.isEmpty() )
{
tDebug() << Q_FUNC_INFO << "Could not parse M3U!";
@@ -155,3 +168,11 @@ M3uLoader::parseM3u( const QString& fileLink )
m_tracks.clear();
}
void
M3uLoader::playlistCreated()
{
ViewManager::instance()->show( m_playlist );
deleteLater();
}

View File

@@ -46,6 +46,8 @@ public:
public slots:
void parse();
private slots:
void playlistCreated();
signals:
void track( const Tomahawk::query_ptr& track );