mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 11:04:01 +02:00
* Code cleanups. Remove plenty of dupe asserts.
This commit is contained in:
@@ -28,7 +28,7 @@ public:
|
|||||||
virtual unsigned int weight() const = 0;
|
virtual unsigned int weight() const = 0;
|
||||||
virtual unsigned int preference() const { return 100; };
|
virtual unsigned int preference() const { return 100; };
|
||||||
virtual unsigned int timeout() const = 0;
|
virtual unsigned int timeout() const = 0;
|
||||||
virtual void resolve( QVariant ) = 0;
|
virtual void resolve( const QVariant& ) = 0;
|
||||||
|
|
||||||
//virtual QWidget * configUI() { return 0; };
|
//virtual QWidget * configUI() { return 0; };
|
||||||
//etc
|
//etc
|
||||||
|
@@ -21,12 +21,14 @@ Database::~Database()
|
|||||||
delete m_impl;
|
delete m_impl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Database::loadIndex()
|
Database::loadIndex()
|
||||||
{
|
{
|
||||||
m_impl->loadIndex();
|
m_impl->loadIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Database::enqueue( QSharedPointer<DatabaseCommand> lc )
|
Database::enqueue( QSharedPointer<DatabaseCommand> lc )
|
||||||
{
|
{
|
||||||
|
@@ -171,4 +171,3 @@ DatabaseCommand_AddFiles::exec( DatabaseImpl* dbi )
|
|||||||
qDebug() << "Done.";
|
qDebug() << "Done.";
|
||||||
emit done( m_files, source()->collection() );
|
emit done( m_files, source()->collection() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,8 +35,7 @@ DatabaseCommand_addSource::exec( DatabaseImpl* dbi )
|
|||||||
query.addBindValue( m_username );
|
query.addBindValue( m_username );
|
||||||
query.addBindValue( m_fname );
|
query.addBindValue( m_fname );
|
||||||
query.addBindValue( true );
|
query.addBindValue( true );
|
||||||
bool ok = query.exec();
|
query.exec();
|
||||||
Q_ASSERT( ok );
|
|
||||||
|
|
||||||
unsigned int id = query.lastInsertId().toUInt();
|
unsigned int id = query.lastInsertId().toUInt();
|
||||||
qDebug() << "Inserted new source to DB, id:" << id << " friendlyname" << m_username;
|
qDebug() << "Inserted new source to DB, id:" << id << " friendlyname" << m_username;
|
||||||
|
@@ -14,6 +14,7 @@ DatabaseCommand_CreatePlaylist::DatabaseCommand_CreatePlaylist( QObject* parent
|
|||||||
qDebug() << Q_FUNC_INFO << "def";
|
qDebug() << Q_FUNC_INFO << "def";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DatabaseCommand_CreatePlaylist::DatabaseCommand_CreatePlaylist( const source_ptr& author,
|
DatabaseCommand_CreatePlaylist::DatabaseCommand_CreatePlaylist( const source_ptr& author,
|
||||||
const playlist_ptr& playlist )
|
const playlist_ptr& playlist )
|
||||||
: DatabaseCommandLoggable( author )
|
: DatabaseCommandLoggable( author )
|
||||||
@@ -28,12 +29,12 @@ void
|
|||||||
DatabaseCommand_CreatePlaylist::exec( DatabaseImpl* lib )
|
DatabaseCommand_CreatePlaylist::exec( DatabaseImpl* lib )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
Q_ASSERT( !m_playlist.isNull() );
|
||||||
|
Q_ASSERT( !source().isNull() );
|
||||||
|
|
||||||
TomahawkSqlQuery cre = lib->newquery();
|
TomahawkSqlQuery cre = lib->newquery();
|
||||||
cre.prepare( "INSERT INTO playlist( guid, source, shared, title, info, creator, lastmodified) "
|
cre.prepare( "INSERT INTO playlist( guid, source, shared, title, info, creator, lastmodified) "
|
||||||
"VALUES( :guid, :source, :shared, :title, :info, :creator, :lastmodified )" );
|
"VALUES( :guid, :source, :shared, :title, :info, :creator, :lastmodified )" );
|
||||||
Q_ASSERT( !m_playlist.isNull() );
|
|
||||||
Q_ASSERT( !source().isNull() );
|
|
||||||
cre.bindValue( ":guid", m_playlist->guid() );
|
cre.bindValue( ":guid", m_playlist->guid() );
|
||||||
cre.bindValue( ":source", source()->isLocal() ? QVariant(QVariant::Int) : source()->id() );
|
cre.bindValue( ":source", source()->isLocal() ? QVariant(QVariant::Int) : source()->id() );
|
||||||
cre.bindValue( ":shared", m_playlist->shared() );
|
cre.bindValue( ":shared", m_playlist->shared() );
|
||||||
@@ -44,15 +45,7 @@ DatabaseCommand_CreatePlaylist::exec( DatabaseImpl* lib )
|
|||||||
|
|
||||||
qDebug() << "CREATE PLAYLIST:" << cre.boundValues();
|
qDebug() << "CREATE PLAYLIST:" << cre.boundValues();
|
||||||
|
|
||||||
bool ok = cre.exec();
|
cre.exec();
|
||||||
if( !ok )
|
|
||||||
{
|
|
||||||
qDebug() << cre.lastError().databaseText()
|
|
||||||
<< cre.lastError().driverText()
|
|
||||||
<< cre.executedQuery()
|
|
||||||
<< cre.boundValues();
|
|
||||||
Q_ASSERT( ok );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -26,15 +26,7 @@ DatabaseCommand_DeletePlaylist::exec( DatabaseImpl* lib )
|
|||||||
cre.prepare( sql );
|
cre.prepare( sql );
|
||||||
cre.bindValue( ":id", m_playlistguid );
|
cre.bindValue( ":id", m_playlistguid );
|
||||||
|
|
||||||
bool ok = cre.exec();
|
cre.exec();
|
||||||
if( !ok )
|
|
||||||
{
|
|
||||||
qDebug() << cre.lastError().databaseText()
|
|
||||||
<< cre.lastError().driverText()
|
|
||||||
<< cre.executedQuery()
|
|
||||||
<< cre.boundValues();
|
|
||||||
Q_ASSERT( ok );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -45,9 +45,7 @@ DatabaseCommand_LoadPlaylistEntries::exec( DatabaseImpl* dbi )
|
|||||||
"WHERE guid IN %1").arg( inclause );
|
"WHERE guid IN %1").arg( inclause );
|
||||||
//qDebug() << sql;
|
//qDebug() << sql;
|
||||||
|
|
||||||
bool xok = query.exec( sql );
|
query.exec( sql );
|
||||||
Q_ASSERT( xok );
|
|
||||||
|
|
||||||
while( query.next() )
|
while( query.next() )
|
||||||
{
|
{
|
||||||
plentry_ptr e( new PlaylistEntry );
|
plentry_ptr e( new PlaylistEntry );
|
||||||
@@ -86,9 +84,8 @@ DatabaseCommand_LoadPlaylistEntries::exec( DatabaseImpl* dbi )
|
|||||||
query_entries_old.addBindValue( m_guid );
|
query_entries_old.addBindValue( m_guid );
|
||||||
query_entries_old.addBindValue( query_entries.value( 1 ).toString() );
|
query_entries_old.addBindValue( query_entries.value( 1 ).toString() );
|
||||||
query_entries_old.addBindValue( prevrev );
|
query_entries_old.addBindValue( prevrev );
|
||||||
bool ex = query_entries_old.exec();
|
|
||||||
Q_ASSERT( ex );
|
|
||||||
|
|
||||||
|
query_entries_old.exec();
|
||||||
if( !query_entries_old.next() )
|
if( !query_entries_old.next() )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
DatabaseCommand_ModifyPlaylist::DatabaseCommand_ModifyPlaylist( Playlist* playlist, QList< plentry_ptr > entries, Mode mode )
|
DatabaseCommand_ModifyPlaylist::DatabaseCommand_ModifyPlaylist( Playlist* playlist, const QList< plentry_ptr >& entries, Mode mode )
|
||||||
: DatabaseCommand()
|
: DatabaseCommand()
|
||||||
, m_playlist( playlist )
|
, m_playlist( playlist )
|
||||||
, m_entries( entries )
|
, m_entries( entries )
|
||||||
|
@@ -21,7 +21,7 @@ public:
|
|||||||
UPDATE = 3
|
UPDATE = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit DatabaseCommand_ModifyPlaylist( Tomahawk::Playlist* playlist, QList< Tomahawk::plentry_ptr > entries, Mode mode );
|
explicit DatabaseCommand_ModifyPlaylist( Tomahawk::Playlist* playlist, const QList< Tomahawk::plentry_ptr >& entries, Mode mode );
|
||||||
|
|
||||||
virtual bool doesMutates() const { return true; }
|
virtual bool doesMutates() const { return true; }
|
||||||
|
|
||||||
|
@@ -29,15 +29,7 @@ DatabaseCommand_RenamePlaylist::exec( DatabaseImpl* lib )
|
|||||||
cre.bindValue( ":id", m_playlistguid );
|
cre.bindValue( ":id", m_playlistguid );
|
||||||
cre.bindValue( ":title", m_playlistTitle );
|
cre.bindValue( ":title", m_playlistTitle );
|
||||||
|
|
||||||
bool ok = cre.exec();
|
cre.exec();
|
||||||
if( !ok )
|
|
||||||
{
|
|
||||||
qDebug() << cre.lastError().databaseText()
|
|
||||||
<< cre.lastError().driverText()
|
|
||||||
<< cre.executedQuery()
|
|
||||||
<< cre.boundValues();
|
|
||||||
Q_ASSERT( ok );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
DatabaseCommand_Resolve::DatabaseCommand_Resolve( QVariant v, bool searchlocal )
|
DatabaseCommand_Resolve::DatabaseCommand_Resolve( const QVariant& v, bool searchlocal )
|
||||||
: DatabaseCommand()
|
: DatabaseCommand()
|
||||||
, m_v( v )
|
, m_v( v )
|
||||||
, m_searchlocal( searchlocal )
|
, m_searchlocal( searchlocal )
|
||||||
@@ -18,8 +18,6 @@ DatabaseCommand_Resolve::DatabaseCommand_Resolve( QVariant v, bool searchlocal )
|
|||||||
void
|
void
|
||||||
DatabaseCommand_Resolve::exec( DatabaseImpl* lib )
|
DatabaseCommand_Resolve::exec( DatabaseImpl* lib )
|
||||||
{
|
{
|
||||||
QTime timer;
|
|
||||||
|
|
||||||
const Tomahawk::QID qid = m_v.toMap().value("qid").toString();
|
const Tomahawk::QID qid = m_v.toMap().value("qid").toString();
|
||||||
const QString artistname = m_v.toMap().value("artist").toString();
|
const QString artistname = m_v.toMap().value("artist").toString();
|
||||||
const QString albumname = m_v.toMap().value("album").toString();
|
const QString albumname = m_v.toMap().value("album").toString();
|
||||||
@@ -37,7 +35,6 @@ DatabaseCommand_Resolve::exec( DatabaseImpl* lib )
|
|||||||
typedef QPair<int,float> scorepair_t;
|
typedef QPair<int,float> scorepair_t;
|
||||||
|
|
||||||
// STEP 1
|
// STEP 1
|
||||||
timer.start();
|
|
||||||
QList< int > artists = lib->searchTable( "artist", artistname, 10 );
|
QList< int > artists = lib->searchTable( "artist", artistname, 10 );
|
||||||
QList< int > tracks = lib->searchTable( "track", trackname, 10 );
|
QList< int > tracks = lib->searchTable( "track", trackname, 10 );
|
||||||
QList< int > albums = lib->searchTable( "album", albumname, 10 );
|
QList< int > albums = lib->searchTable( "album", albumname, 10 );
|
||||||
@@ -52,41 +49,37 @@ DatabaseCommand_Resolve::exec( DatabaseImpl* lib )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// STEP 2
|
// STEP 2
|
||||||
|
|
||||||
TomahawkSqlQuery files_query = lib->newquery();
|
TomahawkSqlQuery files_query = lib->newquery();
|
||||||
|
|
||||||
QStringList artsl, trksl;
|
QStringList artsl, trksl;
|
||||||
foreach( int i, artists ) artsl.append( QString::number(i) );
|
foreach( int i, artists ) artsl.append( QString::number(i) );
|
||||||
foreach( int i, tracks ) trksl.append( QString::number(i) );
|
foreach( int i, tracks ) trksl.append( QString::number(i) );
|
||||||
|
|
||||||
QString sql = QString("SELECT "
|
QString sql = QString( "SELECT "
|
||||||
"url, mtime, size, md5, mimetype, duration, bitrate, file_join.artist, file_join.album, file_join.track, "
|
"url, mtime, size, md5, mimetype, duration, bitrate, file_join.artist, file_join.album, file_join.track, "
|
||||||
"artist.name as artname, "
|
"artist.name as artname, "
|
||||||
"album.name as albname, "
|
"album.name as albname, "
|
||||||
"track.name as trkname, "
|
"track.name as trkname, "
|
||||||
"file.source, "
|
"file.source, "
|
||||||
"file_join.albumpos "
|
"file_join.albumpos "
|
||||||
"FROM file, file_join, artist, track "
|
"FROM file, file_join, artist, track "
|
||||||
"LEFT JOIN album ON album.id = file_join.album "
|
"LEFT JOIN album ON album.id = file_join.album "
|
||||||
"WHERE "
|
"WHERE "
|
||||||
"artist.id = file_join.artist AND "
|
"artist.id = file_join.artist AND "
|
||||||
"track.id = file_join.track AND "
|
"track.id = file_join.track AND "
|
||||||
"file.source %1 AND "
|
"file.source %1 AND "
|
||||||
"file.id = file_join.file AND "
|
"file.id = file_join.file AND "
|
||||||
"file_join.artist IN (%2) AND "
|
"file_join.artist IN (%2) AND "
|
||||||
"file_join.track IN (%3) "
|
"file_join.track IN (%3) "
|
||||||
"ORDER by file_join.artist,file_join.track"
|
"ORDER by file_join.artist,file_join.track"
|
||||||
).arg( m_searchlocal ? "IS NULL" : " IN (SELECT id FROM source WHERE isonline = 'true') " )
|
).arg( m_searchlocal ? "IS NULL" : " IN (SELECT id FROM source WHERE isonline = 'true') " )
|
||||||
.arg( artsl.join(",") )
|
.arg( artsl.join(",") )
|
||||||
.arg( trksl.join(",") );
|
.arg( trksl.join(",") );
|
||||||
|
|
||||||
timer.start();
|
|
||||||
|
|
||||||
files_query.prepare( sql );
|
files_query.prepare( sql );
|
||||||
|
|
||||||
bool ok = files_query.exec();
|
bool ok = files_query.exec();
|
||||||
Q_ASSERT( ok );
|
if(!ok)
|
||||||
if(!ok) throw "Error";
|
throw "Error";
|
||||||
|
|
||||||
//qDebug() << "SQL exec() duration, ms, " << timer.elapsed()
|
//qDebug() << "SQL exec() duration, ms, " << timer.elapsed()
|
||||||
// << "numresults" << files_query.numRowsAffected();
|
// << "numresults" << files_query.numRowsAffected();
|
||||||
@@ -141,21 +134,19 @@ DatabaseCommand_Resolve::exec( DatabaseImpl* lib )
|
|||||||
//int albid = files_query.value( 8 ).toInt();
|
//int albid = files_query.value( 8 ).toInt();
|
||||||
//int trkid = files_query.value( 9 ).toInt();
|
//int trkid = files_query.value( 9 ).toInt();
|
||||||
|
|
||||||
timer.start();
|
|
||||||
float score = how_similar( m_v.toMap(), m );
|
float score = how_similar( m_v.toMap(), m );
|
||||||
//qDebug() << "Score calc:" << timer.elapsed();
|
//qDebug() << "Score calc:" << timer.elapsed();
|
||||||
|
|
||||||
m["score"] = score;
|
m["score"] = score;
|
||||||
|
|
||||||
//qDebug() << "RESULT" << score << m;
|
//qDebug() << "RESULT" << score << m;
|
||||||
|
|
||||||
if( score < MINSCORE ) continue;
|
if( score < MINSCORE )
|
||||||
|
continue;
|
||||||
|
|
||||||
res << Tomahawk::result_ptr( new Tomahawk::Result( m, coll ) );
|
res << Tomahawk::result_ptr( new Tomahawk::Result( m, coll ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// return results, if any found
|
// return results, if any found
|
||||||
|
|
||||||
if( res.length() > 0 )
|
if( res.length() > 0 )
|
||||||
{
|
{
|
||||||
emit results( qid, res );
|
emit results( qid, res );
|
||||||
|
@@ -1,16 +1,17 @@
|
|||||||
#ifndef DATABASECOMMAND_RESOLVE_H
|
#ifndef DATABASECOMMAND_RESOLVE_H
|
||||||
#define DATABASECOMMAND_RESOLVE_H
|
#define DATABASECOMMAND_RESOLVE_H
|
||||||
|
|
||||||
#include "databasecommand.h"
|
#include "databasecommand.h"
|
||||||
#include "databaseimpl.h"
|
#include "databaseimpl.h"
|
||||||
#include "tomahawk/result.h"
|
#include "tomahawk/result.h"
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
class DatabaseCommand_Resolve : public DatabaseCommand
|
class DatabaseCommand_Resolve : public DatabaseCommand
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
//explicit DatabaseCommand_Resolve(QObject *parent = 0);
|
explicit DatabaseCommand_Resolve( const QVariant& v, bool searchlocal );
|
||||||
explicit DatabaseCommand_Resolve( QVariant v, bool searchlocal );
|
|
||||||
|
|
||||||
virtual QString commandname() const { return "dbresolve"; }
|
virtual QString commandname() const { return "dbresolve"; }
|
||||||
virtual bool doesMutates() const { return false; }
|
virtual bool doesMutates() const { return false; }
|
||||||
|
@@ -8,11 +8,11 @@
|
|||||||
|
|
||||||
DatabaseCommand_SetPlaylistRevision::DatabaseCommand_SetPlaylistRevision(
|
DatabaseCommand_SetPlaylistRevision::DatabaseCommand_SetPlaylistRevision(
|
||||||
const source_ptr& s,
|
const source_ptr& s,
|
||||||
QString playlistguid,
|
const QString& playlistguid,
|
||||||
QString newrev,
|
const QString& newrev,
|
||||||
QString oldrev,
|
const QString& oldrev,
|
||||||
QStringList orderedguids,
|
const QStringList& orderedguids,
|
||||||
QList<plentry_ptr> addedentries )
|
const QList<plentry_ptr>& addedentries )
|
||||||
: DatabaseCommandLoggable( s )
|
: DatabaseCommandLoggable( s )
|
||||||
, m_newrev( newrev )
|
, m_newrev( newrev )
|
||||||
, m_oldrev( oldrev )
|
, m_oldrev( oldrev )
|
||||||
@@ -84,7 +84,6 @@ DatabaseCommand_SetPlaylistRevision::exec( DatabaseImpl* lib )
|
|||||||
}
|
}
|
||||||
|
|
||||||
QVariantList vlist = m_orderedguids;
|
QVariantList vlist = m_orderedguids;
|
||||||
|
|
||||||
QJson::Serializer ser;
|
QJson::Serializer ser;
|
||||||
const QByteArray entries = ser.serialize( vlist );
|
const QByteArray entries = ser.serialize( vlist );
|
||||||
|
|
||||||
@@ -111,17 +110,7 @@ DatabaseCommand_SetPlaylistRevision::exec( DatabaseImpl* lib )
|
|||||||
adde.bindValue( 7, e->lastmodified() );
|
adde.bindValue( 7, e->lastmodified() );
|
||||||
adde.bindValue( 8, source()->isLocal() ? QVariant(QVariant::Int) : source()->id() );
|
adde.bindValue( 8, source()->isLocal() ? QVariant(QVariant::Int) : source()->id() );
|
||||||
adde.bindValue( 9, "" );
|
adde.bindValue( 9, "" );
|
||||||
bool ok = adde.exec();
|
adde.exec();
|
||||||
if( !ok )
|
|
||||||
{
|
|
||||||
qDebug() << adde.lastError().databaseText() << adde.lastError().driverText() << "\n"
|
|
||||||
<< sql << endl
|
|
||||||
<< adde.boundValues().size() ;
|
|
||||||
int i = 0;
|
|
||||||
foreach(QVariant param, adde.boundValues()) qDebug() << i++ << param;
|
|
||||||
Q_ASSERT( ok );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the new revision:
|
// add the new revision:
|
||||||
@@ -138,11 +127,7 @@ DatabaseCommand_SetPlaylistRevision::exec( DatabaseImpl* lib )
|
|||||||
query.addBindValue( source()->isLocal() ? QVariant(QVariant::Int) : source()->id() );
|
query.addBindValue( source()->isLocal() ? QVariant(QVariant::Int) : source()->id() );
|
||||||
query.addBindValue( 0 ); //ts
|
query.addBindValue( 0 ); //ts
|
||||||
query.addBindValue( m_oldrev.isEmpty() ? QVariant(QVariant::String) : m_oldrev );
|
query.addBindValue( m_oldrev.isEmpty() ? QVariant(QVariant::String) : m_oldrev );
|
||||||
|
query.exec();
|
||||||
//qDebug() << sql << "\n" << query.boundValues();
|
|
||||||
|
|
||||||
bool ok = query.exec();
|
|
||||||
Q_ASSERT( ok );
|
|
||||||
|
|
||||||
qDebug() << "Currentrevision:" << currentrevision << "oldrev:" << m_oldrev;
|
qDebug() << "Currentrevision:" << currentrevision << "oldrev:" << m_oldrev;
|
||||||
// if optimistic locking is ok, update current revision to this new one
|
// if optimistic locking is ok, update current revision to this new one
|
||||||
@@ -153,22 +138,22 @@ DatabaseCommand_SetPlaylistRevision::exec( DatabaseImpl* lib )
|
|||||||
query2.prepare("UPDATE playlist SET currentrevision = ? WHERE guid = ?");
|
query2.prepare("UPDATE playlist SET currentrevision = ? WHERE guid = ?");
|
||||||
query2.bindValue( 0, m_newrev );
|
query2.bindValue( 0, m_newrev );
|
||||||
query2.bindValue( 1, m_playlistguid );
|
query2.bindValue( 1, m_playlistguid );
|
||||||
bool uok = query2.exec();
|
query2.exec();
|
||||||
Q_ASSERT( uok );
|
|
||||||
m_applied = true;
|
|
||||||
|
|
||||||
|
m_applied = true;
|
||||||
|
|
||||||
// load previous revision entries, which we need to pass on
|
// load previous revision entries, which we need to pass on
|
||||||
// so the change can be diffed
|
// so the change can be diffed
|
||||||
TomahawkSqlQuery query_entries = lib->newquery();
|
TomahawkSqlQuery query_entries = lib->newquery();
|
||||||
query_entries.prepare("SELECT entries, playlist, author, timestamp, previous_revision "
|
query_entries.prepare( "SELECT entries, playlist, author, timestamp, previous_revision "
|
||||||
"FROM playlist_revision "
|
"FROM playlist_revision "
|
||||||
"WHERE guid = :guid");
|
"WHERE guid = :guid" );
|
||||||
query_entries.bindValue( ":guid", m_oldrev );
|
query_entries.bindValue( ":guid", m_oldrev );
|
||||||
query_entries.exec();
|
query_entries.exec();
|
||||||
if( query_entries.next() )
|
if( query_entries.next() )
|
||||||
{
|
{
|
||||||
// entries should be a list of strings:
|
// entries should be a list of strings:
|
||||||
|
bool ok;
|
||||||
QJson::Parser parser;
|
QJson::Parser parser;
|
||||||
QVariant v = parser.parse( query_entries.value(0).toByteArray(), &ok );
|
QVariant v = parser.parse( query_entries.value(0).toByteArray(), &ok );
|
||||||
Q_ASSERT( ok && v.type() == QVariant::List ); //TODO
|
Q_ASSERT( ok && v.type() == QVariant::List ); //TODO
|
||||||
@@ -179,5 +164,4 @@ DatabaseCommand_SetPlaylistRevision::exec( DatabaseImpl* lib )
|
|||||||
{
|
{
|
||||||
qDebug() << "Not updating current revision, optimistic locking fail";
|
qDebug() << "Not updating current revision, optimistic locking fail";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -24,11 +24,11 @@ public:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
explicit DatabaseCommand_SetPlaylistRevision( const source_ptr& s,
|
explicit DatabaseCommand_SetPlaylistRevision( const source_ptr& s,
|
||||||
QString playlistguid,
|
const QString& playlistguid,
|
||||||
QString newrev,
|
const QString& newrev,
|
||||||
QString oldrev,
|
const QString& oldrev,
|
||||||
QStringList orderedguids,
|
const QStringList& orderedguids,
|
||||||
QList<Tomahawk::plentry_ptr> addedentries );
|
const QList<Tomahawk::plentry_ptr>& addedentries );
|
||||||
|
|
||||||
QString commandname() const { return "setplaylistrevision"; }
|
QString commandname() const { return "setplaylistrevision"; }
|
||||||
|
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
#include "databasecommand_updatesearchindex.h"
|
#include "databasecommand_updatesearchindex.h"
|
||||||
|
|
||||||
|
|
||||||
DatabaseCommand_UpdateSearchIndex::DatabaseCommand_UpdateSearchIndex( const QString& t, int p )
|
DatabaseCommand_UpdateSearchIndex::DatabaseCommand_UpdateSearchIndex( const QString& t, int p )
|
||||||
: DatabaseCommand()
|
: DatabaseCommand()
|
||||||
, table( t )
|
, table( t )
|
||||||
@@ -11,6 +13,7 @@ DatabaseCommand_UpdateSearchIndex::DatabaseCommand_UpdateSearchIndex( const QStr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DatabaseCommand_UpdateSearchIndex::exec(DatabaseImpl *db)
|
void DatabaseCommand_UpdateSearchIndex::exec(DatabaseImpl *db)
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
#ifndef DATABASECOMMAND_UPDATESEARCHINDEX_H
|
#ifndef DATABASECOMMAND_UPDATESEARCHINDEX_H
|
||||||
#define DATABASECOMMAND_UPDATESEARCHINDEX_H
|
#define DATABASECOMMAND_UPDATESEARCHINDEX_H
|
||||||
|
|
||||||
#include "databasecommand.h"
|
#include "databasecommand.h"
|
||||||
#include "databaseimpl.h"
|
#include "databaseimpl.h"
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
DatabaseCommandLoggable*
|
DatabaseCommandLoggable*
|
||||||
DatabaseCommandLoggable::factory( QVariantMap c )
|
DatabaseCommandLoggable::factory( const QVariantMap& c )
|
||||||
{
|
{
|
||||||
const QString name = c.value( "command" ).toString();
|
const QString name = c.value( "command" ).toString();
|
||||||
//TODO dynamic class loading, factory blah
|
//TODO dynamic class loading, factory blah
|
||||||
|
@@ -22,7 +22,7 @@ public:
|
|||||||
|
|
||||||
virtual bool loggable() const { return true; }
|
virtual bool loggable() const { return true; }
|
||||||
|
|
||||||
static DatabaseCommandLoggable* factory( QVariantMap c );
|
static DatabaseCommandLoggable* factory( const QVariantMap& c );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -105,6 +105,7 @@ DatabaseImpl::~DatabaseImpl()
|
|||||||
m_indexThread.wait(5000);
|
m_indexThread.wait(5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DatabaseImpl::loadIndex()
|
DatabaseImpl::loadIndex()
|
||||||
{
|
{
|
||||||
@@ -115,6 +116,7 @@ DatabaseImpl::loadIndex()
|
|||||||
m_indexThread.start();
|
m_indexThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DatabaseImpl::updateSearchIndex( const QString& table, int pkey )
|
DatabaseImpl::updateSearchIndex( const QString& table, int pkey )
|
||||||
{
|
{
|
||||||
|
@@ -17,11 +17,14 @@
|
|||||||
#include "fuzzyindex.h"
|
#include "fuzzyindex.h"
|
||||||
|
|
||||||
class Database;
|
class Database;
|
||||||
|
|
||||||
class DatabaseImpl : public QObject
|
class DatabaseImpl : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
friend class FuzzyIndex;
|
friend class FuzzyIndex;
|
||||||
friend class DatabaseCommand_UpdateSearchIndex;
|
friend class DatabaseCommand_UpdateSearchIndex;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DatabaseImpl( const QString& dbname, Database* parent = 0 );
|
DatabaseImpl( const QString& dbname, Database* parent = 0 );
|
||||||
~DatabaseImpl();
|
~DatabaseImpl();
|
||||||
|
@@ -13,7 +13,7 @@ DatabaseResolver::DatabaseResolver( bool searchlocal, int weight )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DatabaseResolver::resolve( QVariant v )
|
DatabaseResolver::resolve( const QVariant& v )
|
||||||
{
|
{
|
||||||
//qDebug() << Q_FUNC_INFO << v;
|
//qDebug() << Q_FUNC_INFO << v;
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ public:
|
|||||||
virtual unsigned int preference() const { return 100; }
|
virtual unsigned int preference() const { return 100; }
|
||||||
virtual unsigned int timeout() const { return 1000; }
|
virtual unsigned int timeout() const { return 1000; }
|
||||||
|
|
||||||
virtual void resolve( QVariant v );
|
virtual void resolve( const QVariant& v );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void gotResults( const Tomahawk::QID qid, QList< Tomahawk::result_ptr> results );
|
void gotResults( const Tomahawk::QID qid, QList< Tomahawk::result_ptr> results );
|
||||||
|
@@ -1,12 +1,17 @@
|
|||||||
#include "fuzzyindex.h"
|
#include "fuzzyindex.h"
|
||||||
|
|
||||||
#include "databaseimpl.h"
|
#include "databaseimpl.h"
|
||||||
|
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
|
||||||
FuzzyIndex::FuzzyIndex(DatabaseImpl &db) :
|
FuzzyIndex::FuzzyIndex( DatabaseImpl &db )
|
||||||
QObject(), m_db( db ), m_loaded( false )
|
: QObject()
|
||||||
|
, m_db( db )
|
||||||
|
, m_loaded( false )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FuzzyIndex::loadNgramIndex()
|
FuzzyIndex::loadNgramIndex()
|
||||||
{
|
{
|
||||||
@@ -61,7 +66,8 @@ FuzzyIndex::loadNgramIndex_helper( QHash< QString, QMap<quint32, quint16> >& idx
|
|||||||
<< "in" << t.elapsed();
|
<< "in" << t.elapsed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FuzzyIndex::mergeIndex(const QString& table, QHash< QString, QMap<quint32, quint16> > tomerge)
|
|
||||||
|
void FuzzyIndex::mergeIndex( const QString& table, QHash< QString, QMap<quint32, quint16> > tomerge )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << table << tomerge.keys().size();
|
qDebug() << Q_FUNC_INFO << table << tomerge.keys().size();
|
||||||
|
|
||||||
@@ -98,7 +104,9 @@ void FuzzyIndex::mergeIndex(const QString& table, QHash< QString, QMap<quint32,
|
|||||||
qDebug() << Q_FUNC_INFO << table << "merge complete, num items:" << tomerge.size();
|
qDebug() << Q_FUNC_INFO << table << "merge complete, num items:" << tomerge.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap< int, float > FuzzyIndex::search( const QString& table, const QString& name )
|
|
||||||
|
QMap< int, float >
|
||||||
|
FuzzyIndex::search( const QString& table, const QString& name )
|
||||||
{
|
{
|
||||||
QMap< int, float > resultsmap;
|
QMap< int, float > resultsmap;
|
||||||
|
|
||||||
|
@@ -21,16 +21,15 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
void loadNgramIndex();
|
void loadNgramIndex();
|
||||||
QMap< int, float > search( const QString& table, const QString& name );
|
QMap< int, float > search( const QString& table, const QString& name );
|
||||||
void mergeIndex(const QString& table, QHash< QString, QMap<quint32, quint16> > tomerge);
|
void mergeIndex( const QString& table, QHash< QString, QMap<quint32, quint16> > tomerge );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadNgramIndex_helper( QHash< QString, QMap<quint32, quint16> >& idx, const QString& table, unsigned int fromkey = 0);
|
void loadNgramIndex_helper( QHash< QString, QMap<quint32, quint16> >& idx, const QString& table, unsigned int fromkey = 0 );
|
||||||
|
|
||||||
// maps an ngram to {track id, num occurences}
|
// maps an ngram to {track id, num occurences}
|
||||||
QHash< QString, QMap<quint32, quint16> > m_artist_ngrams, m_album_ngrams, m_track_ngrams;
|
QHash< QString, QMap<quint32, quint16> > m_artist_ngrams, m_album_ngrams, m_track_ngrams;
|
||||||
|
|
||||||
DatabaseImpl & m_db;
|
DatabaseImpl & m_db;
|
||||||
|
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -17,11 +17,13 @@ ScriptResolver::ScriptResolver(const QString& exe) :
|
|||||||
m_proc.start( m_cmd );
|
m_proc.start( m_cmd );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScriptResolver::readStderr()
|
void ScriptResolver::readStderr()
|
||||||
{
|
{
|
||||||
qDebug() << "SCRIPT_STDERR" << m_cmd << m_proc.readAllStandardError();
|
qDebug() << "SCRIPT_STDERR" << m_cmd << m_proc.readAllStandardError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScriptResolver::readStdout()
|
void ScriptResolver::readStdout()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << m_proc.bytesAvailable();
|
qDebug() << Q_FUNC_INFO << m_proc.bytesAvailable();
|
||||||
@@ -48,6 +50,7 @@ void ScriptResolver::readStdout()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScriptResolver::sendMsg( const QByteArray& msg )
|
void ScriptResolver::sendMsg( const QByteArray& msg )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << m_ready << msg;
|
qDebug() << Q_FUNC_INFO << m_ready << msg;
|
||||||
@@ -60,6 +63,7 @@ void ScriptResolver::sendMsg( const QByteArray& msg )
|
|||||||
m_proc.write( msg );
|
m_proc.write( msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScriptResolver::handleMsg( const QByteArray& msg )
|
void ScriptResolver::handleMsg( const QByteArray& msg )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << msg.size() << QString::fromAscii(msg);
|
qDebug() << Q_FUNC_INFO << msg.size() << QString::fromAscii(msg);
|
||||||
@@ -114,7 +118,8 @@ void ScriptResolver::cmdExited(int code, QProcess::ExitStatus status)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptResolver::resolve( QVariant v )
|
|
||||||
|
void ScriptResolver::resolve( const QVariant& v )
|
||||||
{
|
{
|
||||||
QVariantMap m = v.toMap();
|
QVariantMap m = v.toMap();
|
||||||
m.insert( "_msgtype", "rq" );
|
m.insert( "_msgtype", "rq" );
|
||||||
@@ -122,6 +127,7 @@ void ScriptResolver::resolve( QVariant v )
|
|||||||
sendMsg( msg );
|
sendMsg( msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScriptResolver::doSetup( const QVariantMap& m )
|
void ScriptResolver::doSetup( const QVariantMap& m )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << m;
|
qDebug() << Q_FUNC_INFO << m;
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
#ifndef SCRIPTRESOLVER_H
|
#ifndef SCRIPTRESOLVER_H
|
||||||
#define SCRIPTRESOLVER_H
|
#define SCRIPTRESOLVER_H
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
#include <qjson/parser.h>
|
#include <qjson/parser.h>
|
||||||
@@ -20,7 +21,7 @@ public:
|
|||||||
virtual unsigned int preference() const { return m_preference; }
|
virtual unsigned int preference() const { return m_preference; }
|
||||||
virtual unsigned int timeout() const { return m_timeout; }
|
virtual unsigned int timeout() const { return m_timeout; }
|
||||||
|
|
||||||
virtual void resolve( QVariant v );
|
virtual void resolve( const QVariant& v );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
@@ -36,7 +37,6 @@ private:
|
|||||||
void sendMsg( const QByteArray& msg );
|
void sendMsg( const QByteArray& msg );
|
||||||
void doSetup( const QVariantMap& m );
|
void doSetup( const QVariantMap& m );
|
||||||
|
|
||||||
|
|
||||||
QProcess m_proc;
|
QProcess m_proc;
|
||||||
QString m_name, m_cmd;
|
QString m_name, m_cmd;
|
||||||
unsigned int m_weight, m_preference, m_timeout, m_num_restarts;
|
unsigned int m_weight, m_preference, m_timeout, m_num_restarts;
|
||||||
|
@@ -13,12 +13,13 @@ XSPFLoader::load( const QUrl& url )
|
|||||||
{
|
{
|
||||||
QNetworkRequest request( url );
|
QNetworkRequest request( url );
|
||||||
QNetworkReply* reply = APP->nam()->get( request );
|
QNetworkReply* reply = APP->nam()->get( request );
|
||||||
|
|
||||||
// isn't there a race condition here? something could happen before we connect()
|
// isn't there a race condition here? something could happen before we connect()
|
||||||
connect( reply, SIGNAL( finished() ),
|
connect( reply, SIGNAL( finished() ),
|
||||||
this, SLOT( networkLoadFinished() ) );
|
SLOT( networkLoadFinished() ) );
|
||||||
|
|
||||||
connect( reply, SIGNAL(error(QNetworkReply::NetworkError)),
|
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
|
||||||
this, SLOT( networkError(QNetworkReply::NetworkError) ) );
|
SLOT( networkError( QNetworkReply::NetworkError ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -106,13 +107,10 @@ XSPFLoader::gotBody()
|
|||||||
v.insert( "track", e.firstChildElement( "title" ).text() );
|
v.insert( "track", e.firstChildElement( "title" ).text() );
|
||||||
|
|
||||||
p->setQuery( Tomahawk::query_ptr(new Tomahawk::Query(v)) );
|
p->setQuery( Tomahawk::query_ptr(new Tomahawk::Query(v)) );
|
||||||
|
|
||||||
entries << p;
|
entries << p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
m_playlist->createNewRevision( uuid(), m_playlist->currentrevision(), entries );
|
m_playlist->createNewRevision( uuid(), m_playlist->currentrevision(), entries );
|
||||||
|
|
||||||
emit ok( m_playlist );
|
emit ok( m_playlist );
|
||||||
|
|
||||||
deleteLater();
|
deleteLater();
|
||||||
|
Reference in New Issue
Block a user