mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-02 04:10:20 +02:00
Update deletefiles commands to, well, work. Maybe.
This commit is contained in:
@@ -60,21 +60,18 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
|
|||||||
// qDebug() << Q_FUNC_INFO;
|
// qDebug() << Q_FUNC_INFO;
|
||||||
Q_ASSERT( !source().isNull() );
|
Q_ASSERT( !source().isNull() );
|
||||||
|
|
||||||
int deleted = 0;
|
|
||||||
QVariant srcid = source()->isLocal() ? QVariant( QVariant::Int ) : source()->id();
|
QVariant srcid = source()->isLocal() ? QVariant( QVariant::Int ) : source()->id();
|
||||||
TomahawkSqlQuery delquery = dbi->newquery();
|
TomahawkSqlQuery delquery = dbi->newquery();
|
||||||
QString lastPath;
|
QString lastPath;
|
||||||
|
|
||||||
if ( m_dir.path() != QString( "." ) && source()->isLocal() )
|
if ( source()->isLocal() )
|
||||||
|
{
|
||||||
|
if ( m_dir.path() != QString( "." ) )
|
||||||
{
|
{
|
||||||
qDebug() << "Deleting" << m_dir.path() << "from db for localsource" << srcid;
|
qDebug() << "Deleting" << m_dir.path() << "from db for localsource" << srcid;
|
||||||
TomahawkSqlQuery dirquery = dbi->newquery();
|
TomahawkSqlQuery dirquery = dbi->newquery();
|
||||||
|
|
||||||
dirquery.prepare( QString( "SELECT id, url FROM file WHERE source %1 AND url LIKE ?" )
|
dirquery.prepare( QString( "SELECT id, url FROM file WHERE source IS NULL AND url LIKE ?" ) );
|
||||||
.arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) );
|
|
||||||
delquery.prepare( QString( "DELETE FROM file WHERE source %1 AND id = ?" )
|
|
||||||
.arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) );
|
|
||||||
|
|
||||||
dirquery.bindValue( 0, "file://" + m_dir.canonicalPath() + "/%" );
|
dirquery.bindValue( 0, "file://" + m_dir.canonicalPath() + "/%" );
|
||||||
dirquery.exec();
|
dirquery.exec();
|
||||||
|
|
||||||
@@ -90,52 +87,68 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ids << dirquery.value( 0 ).toUInt();
|
|
||||||
m_files << dirquery.value( 1 ).toString();
|
m_files << dirquery.value( 1 ).toString();
|
||||||
|
m_ids << dirquery.value( 1 ).toUInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( !m_ids.isEmpty() )
|
||||||
|
{
|
||||||
|
TomahawkSqlQuery dirquery = dbi->newquery();
|
||||||
|
|
||||||
|
dirquery.prepare( QString( "SELECT url FROM file WHERE source IS NULL AND id IN ( ? )" ) );
|
||||||
|
|
||||||
|
QString idstring;
|
||||||
|
foreach( const QVariant& id, m_ids )
|
||||||
|
idstring.append( id.toString() + ", " );
|
||||||
|
idstring.chop( 2 ); //remove the trailing ", "
|
||||||
|
|
||||||
|
dirquery.bindValue( 0, idstring );
|
||||||
|
dirquery.exec();
|
||||||
|
while ( dirquery.next() )
|
||||||
|
m_files << dirquery.value( 0 ).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach( const QVariant& id, m_ids )
|
||||||
|
m_files << QString( "servent://%1\t%2" ).arg( source()->userName() ).arg( id.toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( const QVariant& id, m_ids )
|
if ( m_deleteAll )
|
||||||
{
|
{
|
||||||
delquery.bindValue( 0, id.toUInt() );
|
delquery.prepare( QString( "DELETE FROM file WHERE source %1" )
|
||||||
if( !delquery.exec() )
|
|
||||||
{
|
|
||||||
qDebug() << "Failed to delete file:"
|
|
||||||
<< delquery.lastError().databaseText()
|
|
||||||
<< delquery.lastError().driverText()
|
|
||||||
<< delquery.boundValues();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
deleted++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( !m_ids.isEmpty() && source()->isLocal() )
|
|
||||||
{
|
|
||||||
delquery.prepare( QString( "DELETE FROM file WHERE source %1 AND url = ?" )
|
|
||||||
.arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) );
|
.arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) );
|
||||||
|
|
||||||
foreach( const QVariant& id, m_ids )
|
|
||||||
{
|
|
||||||
// qDebug() << "Deleting" << id.toUInt() << "from db for source" << srcid;
|
|
||||||
|
|
||||||
const QString url = QString( "servent://%1\t%2" ).arg( source()->userName() ).arg( id.toString() );
|
|
||||||
m_files << url;
|
|
||||||
|
|
||||||
delquery.bindValue( 0, id.toUInt() );
|
|
||||||
if( !delquery.exec() )
|
if( !delquery.exec() )
|
||||||
{
|
{
|
||||||
qDebug() << "Failed to delete file:"
|
qDebug() << "Failed to delete file:"
|
||||||
<< delquery.lastError().databaseText()
|
<< delquery.lastError().databaseText()
|
||||||
<< delquery.lastError().driverText()
|
<< delquery.lastError().driverText()
|
||||||
<< delquery.boundValues();
|
<< delquery.boundValues();
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deleted++;
|
emit done( m_files, source()->collection() );
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
else if ( !m_ids.isEmpty() )
|
||||||
|
{
|
||||||
|
delquery.prepare( QString( "DELETE FROM file WHERE source %1 AND url IN ( ? )" )
|
||||||
|
.arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) );
|
||||||
|
|
||||||
// qDebug() << "Deleted" << deleted << m_ids << m_files;
|
QString idstring;
|
||||||
|
foreach( const QVariant& id, m_ids )
|
||||||
|
idstring.append( id.toString() + ", " );
|
||||||
|
idstring.chop( 2 ); //remove the trailing ", "
|
||||||
|
|
||||||
|
delquery.bindValue( 0, idstring );
|
||||||
|
if( !delquery.exec() )
|
||||||
|
{
|
||||||
|
qDebug() << "Failed to delete file:"
|
||||||
|
<< delquery.lastError().databaseText()
|
||||||
|
<< delquery.lastError().driverText()
|
||||||
|
<< delquery.boundValues();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emit done( m_files, source()->collection() );
|
emit done( m_files, source()->collection() );
|
||||||
}
|
}
|
||||||
|
@@ -32,20 +32,27 @@ class DLLEXPORT DatabaseCommand_DeleteFiles : public DatabaseCommandLoggable
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY( QVariantList ids READ ids WRITE setIds )
|
Q_PROPERTY( QVariantList ids READ ids WRITE setIds )
|
||||||
|
Q_PROPERTY( bool deleteAll READ deleteAll WRITE setDeleteAll )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DatabaseCommand_DeleteFiles( QObject* parent = 0 )
|
explicit DatabaseCommand_DeleteFiles( QObject* parent = 0 )
|
||||||
: DatabaseCommandLoggable( parent )
|
: DatabaseCommandLoggable( parent )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
explicit DatabaseCommand_DeleteFiles( const Tomahawk::source_ptr& source, QObject* parent = 0 )
|
||||||
|
: DatabaseCommandLoggable( parent ), m_deleteAll( true )
|
||||||
|
{
|
||||||
|
setSource( source );
|
||||||
|
}
|
||||||
|
|
||||||
explicit DatabaseCommand_DeleteFiles( const QDir& dir, const Tomahawk::source_ptr& source, QObject* parent = 0 )
|
explicit DatabaseCommand_DeleteFiles( const QDir& dir, const Tomahawk::source_ptr& source, QObject* parent = 0 )
|
||||||
: DatabaseCommandLoggable( parent ), m_dir( dir )
|
: DatabaseCommandLoggable( parent ), m_dir( dir ), m_deleteAll( false )
|
||||||
{
|
{
|
||||||
setSource( source );
|
setSource( source );
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit DatabaseCommand_DeleteFiles( const QVariantList& ids, const Tomahawk::source_ptr& source, QObject* parent = 0 )
|
explicit DatabaseCommand_DeleteFiles( const QVariantList& ids, const Tomahawk::source_ptr& source, QObject* parent = 0 )
|
||||||
: DatabaseCommandLoggable( parent ), m_ids( ids )
|
: DatabaseCommandLoggable( parent ), m_ids( ids ), m_deleteAll( false )
|
||||||
{
|
{
|
||||||
setSource( source );
|
setSource( source );
|
||||||
}
|
}
|
||||||
@@ -54,23 +61,24 @@ public:
|
|||||||
|
|
||||||
virtual void exec( DatabaseImpl* );
|
virtual void exec( DatabaseImpl* );
|
||||||
virtual bool doesMutates() const { return true; }
|
virtual bool doesMutates() const { return true; }
|
||||||
virtual bool localOnly() const { return m_files.isEmpty(); }
|
virtual bool localOnly() const { return false; }
|
||||||
virtual void postCommitHook();
|
virtual void postCommitHook();
|
||||||
|
|
||||||
QStringList files() const { return m_files; }
|
|
||||||
void setFiles( const QStringList& f ) { m_files = f; }
|
|
||||||
|
|
||||||
QVariantList ids() const { return m_ids; }
|
QVariantList ids() const { return m_ids; }
|
||||||
void setIds( const QVariantList& i ) { m_ids = i; }
|
void setIds( const QVariantList& i ) { m_ids = i; }
|
||||||
|
|
||||||
|
bool deleteAll() const { return m_deleteAll; }
|
||||||
|
void setDeleteAll( const bool deleteAll ) { m_deleteAll = deleteAll; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void done( const QStringList&, const Tomahawk::collection_ptr& );
|
void done( const QStringList&, const Tomahawk::collection_ptr& );
|
||||||
void notify( const QStringList& );
|
void notify( const QStringList& );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QDir m_dir;
|
|
||||||
QStringList m_files;
|
QStringList m_files;
|
||||||
|
QDir m_dir;
|
||||||
QVariantList m_ids;
|
QVariantList m_ids;
|
||||||
|
bool m_deleteAll;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DATABASECOMMAND_DELETEFILES_H
|
#endif // DATABASECOMMAND_DELETEFILES_H
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include "database/database.h"
|
#include "database/database.h"
|
||||||
#include "database/databasecommand_dirmtimes.h"
|
#include "database/databasecommand_dirmtimes.h"
|
||||||
|
#include "database/databasecommand_deletefiles.h"
|
||||||
|
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
|
||||||
@@ -147,6 +148,9 @@ ScanManager::runDirScan( const QStringList& paths, bool manualFull )
|
|||||||
if ( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) )
|
if ( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if ( paths.isEmpty() )
|
||||||
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( new DatabaseCommand_DeleteFiles( SourceList::instance()->getLocal() ) ) );
|
||||||
|
|
||||||
if ( !m_musicScannerThreadController && m_scanner.isNull() ) //still running if these are not zero
|
if ( !m_musicScannerThreadController && m_scanner.isNull() ) //still running if these are not zero
|
||||||
{
|
{
|
||||||
m_scanTimer->stop();
|
m_scanTimer->stop();
|
||||||
|
Reference in New Issue
Block a user