1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-02-25 20:33:20 +01:00

Merge remote branch 'origin' into phonon

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

View File

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

View File

@ -10,8 +10,6 @@
#include <QString>
#include <QDebug>
#include <QDateTime>
#include <QTimer>
// descend dir tree comparing dir mtimes to last known mtime
@ -19,7 +17,8 @@
// finally, emit the list of new mtimes we observed.
class DirLister : public QObject
{
Q_OBJECT
Q_OBJECT
public:
DirLister( QDir d, QMap<QString, unsigned int>& mtimes )
: QObject(), m_dir( d ), m_dirmtimes( mtimes )
@ -43,36 +42,7 @@ private slots:
emit finished( m_newdirmtimes );
}
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 );
}
}
void scanDir( QDir dir, int depth );
private:
QDir m_dir;

View File

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

View File

@ -321,7 +321,8 @@ TomahawkWindow::createAutomaticPlaylist()
}
void TomahawkWindow::createStation()
void
TomahawkWindow::createStation()
{
bool ok;
QString name = QInputDialog::getText( this, "Create New Station", "Name:", QLineEdit::Normal, "New Station", &ok );
@ -341,23 +342,7 @@ void TomahawkWindow::createStation()
void
TomahawkWindow::createPlaylist()
{
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 ); */
}