1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-07 17:42:35 +02:00

More updates for file-mtime scanning

This commit is contained in:
Jeff Mitchell 2011-05-20 14:24:59 -04:00
parent 0a8e0daa57
commit c2884e696f
6 changed files with 44 additions and 18 deletions

View File

@ -33,14 +33,19 @@ DatabaseCommand_FileMtimes::exec( DatabaseImpl* dbi )
void
DatabaseCommand_FileMtimes::execSelect( DatabaseImpl* dbi )
{
qDebug() << Q_FUNC_INFO;
//FIXME: If ever needed for a non-local source this will have to be fixed/updated
QMap<QString,unsigned int> mtimes;
QMap< QString, QMap< unsigned int, unsigned int > > mtimes;
TomahawkSqlQuery query = dbi->newquery();
if( m_prefix.isEmpty() && m_prefixes.isEmpty() )
{
query.exec( "SELECT id, mtime FROM file WHERE souce IS NULL" );
query.exec( "SELECT url, id, mtime FROM file WHERE source IS NULL" );
while( query.next() )
mtimes.insert( query.value( 0 ).toString(), query.value( 1 ).toUInt() );
{
QMap< unsigned int, unsigned int > map;
map.insert( query.value( 1 ).toUInt(), query.value( 2 ).toUInt() );
mtimes.insert( query.value( 0 ).toString(), map );
}
}
else if( m_prefixes.isEmpty() )
execSelectPath( dbi, m_prefix, mtimes );
@ -55,10 +60,10 @@ DatabaseCommand_FileMtimes::execSelect( DatabaseImpl* dbi )
}
void
DatabaseCommand_FileMtimes::execSelectPath( DatabaseImpl *dbi, const QDir& path, QMap<QString, unsigned int> &mtimes )
DatabaseCommand_FileMtimes::execSelectPath( DatabaseImpl *dbi, const QDir& path, QMap<QString, QMap< unsigned int, unsigned int > > &mtimes )
{
TomahawkSqlQuery query = dbi->newquery();
query.prepare( QString( "SELECT id, mtime "
query.prepare( QString( "SELECT url, id, mtime "
"FROM file "
"WHERE source IS NULL "
"AND url LIKE :prefix" ) );
@ -67,5 +72,9 @@ DatabaseCommand_FileMtimes::execSelectPath( DatabaseImpl *dbi, const QDir& path,
query.exec();
while( query.next() )
mtimes.insert( query.value( 0 ).toString(), query.value( 1 ).toUInt() );
{
QMap< unsigned int, unsigned int > map;
map.insert( query.value( 1 ).toUInt(), query.value( 2 ).toUInt() );
mtimes.insert( query.value( 0 ).toString(), map );
}
}

View File

@ -47,18 +47,15 @@ public:
virtual QString commandname() const { return "filemtimes"; }
signals:
void done( const QMap<QString, unsigned int>& );
void done( const QMap< QString, QMap< unsigned int, unsigned int > >& );
public slots:
private:
void execSelectPath( DatabaseImpl *dbi, const QDir& path, QMap<QString, unsigned int> &mtimes );
void execSelectPath( DatabaseImpl *dbi, const QDir& path, QMap< QString, QMap< unsigned int, unsigned int > > &mtimes );
void execSelect( DatabaseImpl* dbi );
void execUpdate( DatabaseImpl* dbi );
QString m_prefix;
QStringList m_prefixes;
QMap<QString, unsigned int> m_tosave;
};
#endif // DATABASECOMMAND_FILEMTIMES_H

View File

@ -192,8 +192,8 @@ MusicScanner::setDirMtimes( const QMap<QString, unsigned int>& m )
if ( m_mode == TomahawkSettings::Files )
{
DatabaseCommand_FileMtimes *cmd = new DatabaseCommand_FileMtimes();
connect( cmd, SIGNAL( done( QMap<QString, unsigned int> ) ),
SLOT( setFileMtimes( QMap<QString, unsigned int> ) ) );
connect( cmd, SIGNAL( done( QMap<QString, QMap< unsigned int, unsigned int > > ) ),
SLOT( setFileMtimes( QMap<QString, QMap< unsigned int, unsigned int > > ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
return;
@ -203,7 +203,7 @@ MusicScanner::setDirMtimes( const QMap<QString, unsigned int>& m )
void
MusicScanner::setFileMtimes( const QMap<QString, unsigned int>& m )
MusicScanner::setFileMtimes( const QMap<QString, QMap< unsigned int, unsigned int > >& m )
{
qDebug() << Q_FUNC_INFO << m.count();
m_filemtimes = m;
@ -324,6 +324,24 @@ MusicScanner::commitBatch( const QVariantList& tracks )
void
MusicScanner::scanFile( const QFileInfo& fi )
{
//qDebug() << "Scanning file with canonical file path " << fi.canonicalFilePath();
//qDebug() << "is directory ? " << ( fi.isDir() ? " yes" : " no");
if ( m_mode == TomahawkSettings::Files && m_filemtimes.contains( "file://" + fi.canonicalFilePath() ) )
{
//qDebug() << "All keys: " << m_filemtimes.keys();
//qDebug() << "Checking " << fi.canonicalFilePath() << " with last modified time " << fi.lastModified().toUTC().toTime_t() << " << against value in m_filemtimes " << m_filemtimes.value( "file://" + fi.canonicalFilePath() ).values().first();
if ( fi.lastModified().toUTC().toTime_t() == m_filemtimes.value( "file://" + fi.canonicalFilePath() ).values().first() )
{
qDebug() << "Same mtime";
return;
}
else
{
qDebug() << "Different mtime";
return;
}
}
QVariant m = readFile( fi );
if ( m.toMap().isEmpty() )
return;

View File

@ -100,8 +100,8 @@ private slots:
void scanFile( const QFileInfo& fi );
void startScan();
void scan();
void setDirMtimes( const QMap<QString, unsigned int>& m );
void setFileMtimes( const QMap<QString, unsigned int>& m );
void setDirMtimes( const QMap< QString, unsigned int >& m );
void setFileMtimes( const QMap< QString, QMap< unsigned int, unsigned int > >& m );
void commitBatch( const QVariantList& );
private:
@ -114,7 +114,7 @@ private:
QList<QString> m_skippedFiles;
QMap<QString, unsigned int> m_dirmtimes;
QMap<QString, unsigned int> m_filemtimes;
QMap<QString, QMap< unsigned int, unsigned int > > m_filemtimes;
QMap<QString, unsigned int> m_newdirmtimes;
QList<QVariant> m_scannedfiles;

View File

@ -56,7 +56,8 @@ ScanManager::ScanManager( QObject* parent )
connect( m_scanTimer, SIGNAL( timeout() ), SLOT( scanTimerTimeout() ) );
// FIXME: Disable this until we find something nondeprecated and working (e.g. not QFileSystemWatcher)
//TomahawkSettings::instance()->setWatchForChanges( true );
TomahawkSettings::instance()->setWatchForChanges( true );
TomahawkSettings::instance()->setScannerMode( TomahawkSettings::Files );
if ( TomahawkSettings::instance()->hasScannerPaths() )
{

View File

@ -368,6 +368,7 @@ TomahawkApp::registerMetaTypes()
qRegisterMetaType< QMap<QString, unsigned int> >("QMap<QString, unsigned int>");
qRegisterMetaType< QMap< QString, plentry_ptr > >("QMap< QString, plentry_ptr >");
qRegisterMetaType< QHash< QString, QMap<quint32, quint16> > >("QHash< QString, QMap<quint32, quint16> >");
qRegisterMetaType< QMap< QString, QMap< unsigned int, unsigned int > > >("QMap< QString, QMap< unsigned int, unsigned int > >");
qRegisterMetaType< GeneratorMode>("GeneratorMode");
qRegisterMetaType<Tomahawk::GeneratorMode>("Tomahawk::GeneratorMode");