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