1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-07 22:56:42 +02:00

Merge remote branch 'origin' into phonon

This commit is contained in:
Christian Muehlhaeuser
2011-02-24 03:25:57 +01:00
4 changed files with 57 additions and 62 deletions

View File

@@ -9,6 +9,38 @@
using namespace Tomahawk; using namespace Tomahawk;
void
DirLister::scanDir( QDir dir, int depth )
{
QFileInfoList dirs;
const uint mtime = QFileInfo( dir.absolutePath() ).lastModified().toUTC().toTime_t();
m_newdirmtimes.insert( dir.absolutePath(), mtime );
if ( m_dirmtimes.contains( dir.absolutePath() ) &&
mtime == m_dirmtimes.value( dir.absolutePath() ) )
{
// dont scan this dir, unchanged since last time.
}
else
{
dir.setFilter( QDir::Files | QDir::Readable | QDir::NoDotAndDotDot );
dir.setSorting( QDir::Name );
dirs = dir.entryInfoList();
foreach( const QFileInfo& di, dirs )
{
emit fileToScan( di );
}
}
dir.setFilter( QDir::Dirs | QDir::Readable | QDir::NoDotAndDotDot );
dirs = dir.entryInfoList();
foreach( const QFileInfo& di, dirs )
{
scanDir( di.absoluteFilePath(), depth + 1 );
}
}
MusicScanner::MusicScanner( const QString& dir, quint32 bs ) MusicScanner::MusicScanner( const QString& dir, quint32 bs )
: QObject() : QObject()
, m_dir( dir ) , m_dir( dir )
@@ -26,9 +58,11 @@ MusicScanner::MusicScanner( const QString& dir, quint32 bs )
m_ext2mime.insert( "mp4", "audio/mp4" ); m_ext2mime.insert( "mp4", "audio/mp4" );
} }
MusicScanner::~MusicScanner() MusicScanner::~MusicScanner()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if( m_dirListerThreadController ) if( m_dirListerThreadController )
{ {
m_dirListerThreadController->quit(); m_dirListerThreadController->quit();
@@ -36,7 +70,7 @@ MusicScanner::~MusicScanner()
while( !m_dirListerThreadController->isFinished() ) while( !m_dirListerThreadController->isFinished() )
{ {
QCoreApplication::processEvents( QEventLoop::AllEvents, 200 ); QCoreApplication::processEvents( QEventLoop::AllEvents, 200 );
TomahawkUtils::Sleep::msleep(100); TomahawkUtils::Sleep::msleep( 100 );
} }
if( m_dirLister ) if( m_dirLister )
@@ -50,6 +84,7 @@ MusicScanner::~MusicScanner()
} }
} }
void void
MusicScanner::startScan() MusicScanner::startScan()
{ {
@@ -59,9 +94,9 @@ MusicScanner::startScan()
// trigger the scan once we've loaded old mtimes for dirs below our path // trigger the scan once we've loaded old mtimes for dirs below our path
DatabaseCommand_DirMtimes* cmd = new DatabaseCommand_DirMtimes( m_dir ); DatabaseCommand_DirMtimes* cmd = new DatabaseCommand_DirMtimes( m_dir );
connect( cmd, SIGNAL( done( const QMap<QString, unsigned int>& ) ), connect( cmd, SIGNAL( done( QMap<QString, unsigned int> ) ),
SLOT( setMtimes( const QMap<QString, unsigned int>& ) ) ); SLOT( setMtimes( QMap<QString, unsigned int> ) ) );
connect( cmd, SIGNAL( done( const QMap<QString,unsigned int>& ) ), connect( cmd, SIGNAL( done( QMap<QString, unsigned int> ) ),
SLOT( scan() ) ); SLOT( scan() ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) ); Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
@@ -91,8 +126,8 @@ MusicScanner::scan()
SLOT( scanFile( QFileInfo ) ), Qt::QueuedConnection ); SLOT( scanFile( QFileInfo ) ), Qt::QueuedConnection );
// queued, so will only fire after all dirs have been scanned: // queued, so will only fire after all dirs have been scanned:
connect( m_dirLister, SIGNAL( finished( const QMap<QString, unsigned int>& ) ), connect( m_dirLister, SIGNAL( finished( QMap<QString, unsigned int> ) ),
SLOT( listerFinished( const QMap<QString, unsigned int>& ) ), Qt::QueuedConnection ); SLOT( listerFinished( QMap<QString, unsigned int> ) ), Qt::QueuedConnection );
m_dirListerThreadController->start(); m_dirListerThreadController->start();
QMetaObject::invokeMethod( m_dirLister, "go" ); QMetaObject::invokeMethod( m_dirLister, "go" );
@@ -123,6 +158,7 @@ MusicScanner::listerFinished( const QMap<QString, unsigned int>& newmtimes )
qDebug() << s; qDebug() << s;
} }
void void
MusicScanner::deleteLister() MusicScanner::deleteLister()
{ {
@@ -131,6 +167,7 @@ MusicScanner::deleteLister()
m_dirListerThreadController->quit(); m_dirListerThreadController->quit();
} }
void void
MusicScanner::listerQuit() MusicScanner::listerQuit()
{ {
@@ -140,6 +177,7 @@ MusicScanner::listerQuit()
m_dirLister = 0; m_dirLister = 0;
} }
void void
MusicScanner::listerDestroyed( QObject* dirLister ) MusicScanner::listerDestroyed( QObject* dirLister )
{ {
@@ -149,6 +187,7 @@ MusicScanner::listerDestroyed( QObject* dirLister )
emit finished(); emit finished();
} }
void void
MusicScanner::commitBatch( const QVariantList& tracks ) MusicScanner::commitBatch( const QVariantList& tracks )
{ {
@@ -167,12 +206,11 @@ void
MusicScanner::scanFile( const QFileInfo& fi ) MusicScanner::scanFile( const QFileInfo& fi )
{ {
QVariant m = readFile( fi ); QVariant m = readFile( fi );
if( m.toMap().isEmpty() ) if ( m.toMap().isEmpty() )
return; return;
m_scannedfiles << m; m_scannedfiles << m;
if( m_batchsize != 0 && if ( m_batchsize != 0 && (quint32)m_scannedfiles.length() >= m_batchsize )
(quint32)m_scannedfiles.length() >= m_batchsize )
{ {
qDebug() << "batchReady, size:" << m_scannedfiles.length(); qDebug() << "batchReady, size:" << m_scannedfiles.length();
emit batchReady( m_scannedfiles ); emit batchReady( m_scannedfiles );
@@ -215,17 +253,16 @@ MusicScanner::readFile( const QFileInfo& fi )
int bitrate = 0; int bitrate = 0;
int duration = 0; int duration = 0;
TagLib::Tag *tag = f.tag(); TagLib::Tag *tag = f.tag();
if ( f.audioProperties() ) if ( f.audioProperties() )
{ {
TagLib::AudioProperties *properties = f.audioProperties(); TagLib::AudioProperties *properties = f.audioProperties();
duration = properties->length(); duration = properties->length();
bitrate = properties->bitrate(); bitrate = properties->bitrate();
} }
QString artist = TStringToQString( tag->artist() ).trimmed(); QString artist = TStringToQString( tag->artist() ).trimmed();
QString album = TStringToQString( tag->album() ).trimmed(); QString album = TStringToQString( tag->album() ).trimmed();
QString track = TStringToQString( tag->title() ).trimmed(); QString track = TStringToQString( tag->title() ).trimmed();
if ( artist.isEmpty() || track.isEmpty() ) if ( artist.isEmpty() || track.isEmpty() )
{ {
// FIXME: do some clever filename guessing // FIXME: do some clever filename guessing

View File

@@ -10,8 +10,6 @@
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#include <QDateTime> #include <QDateTime>
#include <QTimer> #include <QTimer>
// descend dir tree comparing dir mtimes to last known mtime // descend dir tree comparing dir mtimes to last known mtime
@@ -19,7 +17,8 @@
// finally, emit the list of new mtimes we observed. // finally, emit the list of new mtimes we observed.
class DirLister : public QObject class DirLister : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
DirLister( QDir d, QMap<QString, unsigned int>& mtimes ) DirLister( QDir d, QMap<QString, unsigned int>& mtimes )
: QObject(), m_dir( d ), m_dirmtimes( mtimes ) : QObject(), m_dir( d ), m_dirmtimes( mtimes )
@@ -43,36 +42,7 @@ private slots:
emit finished( m_newdirmtimes ); emit finished( m_newdirmtimes );
} }
void scanDir( QDir dir, int depth ) void scanDir( QDir dir, int depth );
{
QFileInfoList dirs;
const uint mtime = QFileInfo( dir.absolutePath() ).lastModified().toUTC().toTime_t();
m_newdirmtimes.insert( dir.absolutePath(), mtime );
if ( m_dirmtimes.contains( dir.absolutePath() ) &&
mtime == m_dirmtimes.value( dir.absolutePath() )
)
{
// dont scan this dir, unchanged since last time.
}
else
{
dir.setFilter( QDir::Files | QDir::Readable | QDir::NoDotAndDotDot );
dir.setSorting( QDir::Name );
dirs = dir.entryInfoList();
foreach( QFileInfo di, dirs )
{
emit fileToScan( di );
}
}
dir.setFilter( QDir::Dirs | QDir::Readable | QDir::NoDotAndDotDot );
dirs = dir.entryInfoList();
foreach( QFileInfo di, dirs )
{
scanDir( di.absoluteFilePath(), depth + 1 );
}
}
private: private:
QDir m_dir; QDir m_dir;

View File

@@ -40,7 +40,7 @@ ScanManager::~ScanManager()
while( !m_musicScannerThreadController->isFinished() ) while( !m_musicScannerThreadController->isFinished() )
{ {
QCoreApplication::processEvents( QEventLoop::AllEvents, 200 ); QCoreApplication::processEvents( QEventLoop::AllEvents, 200 );
TomahawkUtils::Sleep::msleep(100); TomahawkUtils::Sleep::msleep( 100 );
} }
if( m_scanner ) if( m_scanner )
@@ -80,6 +80,7 @@ ScanManager::runManualScan( const QString& path )
qDebug() << "Could not run manual scan, old scan still running"; qDebug() << "Could not run manual scan, old scan still running";
} }
void void
ScanManager::scannerFinished() ScanManager::scannerFinished()
{ {
@@ -88,6 +89,7 @@ ScanManager::scannerFinished()
m_musicScannerThreadController->quit(); m_musicScannerThreadController->quit();
} }
void void
ScanManager::scannerQuit() ScanManager::scannerQuit()
{ {
@@ -97,6 +99,7 @@ ScanManager::scannerQuit()
m_scanner = 0; m_scanner = 0;
} }
void void
ScanManager::scannerDestroyed( QObject* scanner ) ScanManager::scannerDestroyed( QObject* scanner )
{ {

View File

@@ -321,7 +321,8 @@ TomahawkWindow::createAutomaticPlaylist()
} }
void TomahawkWindow::createStation() void
TomahawkWindow::createStation()
{ {
bool ok; bool ok;
QString name = QInputDialog::getText( this, "Create New Station", "Name:", QLineEdit::Normal, "New Station", &ok ); QString name = QInputDialog::getText( this, "Create New Station", "Name:", QLineEdit::Normal, "New Station", &ok );
@@ -341,23 +342,7 @@ void TomahawkWindow::createStation()
void void
TomahawkWindow::createPlaylist() TomahawkWindow::createPlaylist()
{ {
PlaylistManager::instance()->show( new NewPlaylistWidget() ); PlaylistManager::instance()->show( new NewPlaylistWidget() );
/* bool ok;
QString name = QInputDialog::getText( this, "Create New Playlist", "Name:", QLineEdit::Normal, "New Playlist", &ok );
if ( !ok || name.isEmpty() )
return;
source_ptr author = SourceList::instance()->getLocal();
QString id = uuid();
QString info = ""; // FIXME
QString creator = "someone"; // FIXME
if( dynamic )
DynamicPlaylist::create( author, id, name, info, creator, false );
else
Playlist::create( author, id, name, info, creator, false ); */
} }