mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 11:04:01 +02:00
Add fuzzy search tool
This commit is contained in:
@@ -18,3 +18,23 @@ target_link_libraries( tomahawk_db_list_artists_bin
|
|||||||
qt5_use_modules(tomahawk_db_list_artists_bin Core)
|
qt5_use_modules(tomahawk_db_list_artists_bin Core)
|
||||||
install( TARGETS tomahawk_db_list_artists_bin BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
|
install( TARGETS tomahawk_db_list_artists_bin BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
|
||||||
|
|
||||||
|
set( tomahawk_db_fuzzysearch_src
|
||||||
|
fuzzysearch.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
|
add_executable( tomahawk_db_fuzzysearch_bin WIN32 MACOSX_BUNDLE
|
||||||
|
${tomahawk_db_fuzzysearch_src} )
|
||||||
|
set_target_properties( tomahawk_db_fuzzysearch_bin
|
||||||
|
PROPERTIES
|
||||||
|
AUTOMOC TRUE
|
||||||
|
RUNTIME_OUTPUT_NAME tomahawk-db-fuzzysearch
|
||||||
|
)
|
||||||
|
target_link_libraries( tomahawk_db_fuzzysearch_bin
|
||||||
|
${TOMAHAWK_LIBRARIES}
|
||||||
|
)
|
||||||
|
|
||||||
|
qt5_use_modules(tomahawk_db_list_artists_bin Core)
|
||||||
|
install( TARGETS tomahawk_db_list_artists_bin BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
|
||||||
|
|
||||||
|
82
src/tools/database-reader/fuzzysearch.cpp
Normal file
82
src/tools/database-reader/fuzzysearch.cpp
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#include "database/Database.h"
|
||||||
|
#include "database/DatabaseCommand_Resolve.h"
|
||||||
|
#include "utils/TomahawkUtils.h"
|
||||||
|
#include "TomahawkVersion.h"
|
||||||
|
#include "Typedefs.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
|
class Tasks: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE void startDatabase( QString dbpath )
|
||||||
|
{
|
||||||
|
database = QSharedPointer<Tomahawk::Database>( new Tomahawk::Database( dbpath ) );
|
||||||
|
connect( database.data(), SIGNAL( ready() ), SLOT( runCmd() ), Qt::QueuedConnection );
|
||||||
|
database->loadIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
Tomahawk::dbcmd_ptr cmd;
|
||||||
|
QSharedPointer<Tomahawk::Database> database;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void runCmd()
|
||||||
|
{
|
||||||
|
database->enqueue( cmd );
|
||||||
|
}
|
||||||
|
|
||||||
|
void onResults( const Tomahawk::QID, QList< Tomahawk::result_ptr> results )
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
QMetaObject::invokeMethod( thread(), "quit", Qt::QueuedConnection );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Include needs to go here as Tasks needs to be defined before.
|
||||||
|
#include "fuzzysearch.moc"
|
||||||
|
|
||||||
|
int main( int argc, char* argv[] )
|
||||||
|
{
|
||||||
|
QCoreApplication app( argc, argv );
|
||||||
|
// TODO: Add an argument to change the path
|
||||||
|
app.setOrganizationName( TOMAHAWK_ORGANIZATION_NAME );
|
||||||
|
|
||||||
|
qRegisterMetaType< QList< Tomahawk::result_ptr > >();
|
||||||
|
qRegisterMetaType< Tomahawk::QID >("Tomahawk::QID");
|
||||||
|
|
||||||
|
// Helper QObject to connect slots and actions in the correct thread.
|
||||||
|
Tasks tasks;
|
||||||
|
|
||||||
|
// Start a thread so we can actually block main until the end of the DbCmd
|
||||||
|
QThread thread( nullptr );
|
||||||
|
thread.start();
|
||||||
|
|
||||||
|
// We need to do this or the finished() signal/quit() SLOT is not called.
|
||||||
|
thread.moveToThread( &thread );
|
||||||
|
tasks.moveToThread( &thread );
|
||||||
|
|
||||||
|
// Load the Database
|
||||||
|
Tomahawk::query_ptr query( Tomahawk::Query::get( "Bloc Party", QString() ) );
|
||||||
|
Tomahawk::DatabaseCommand_Resolve* cmd = new Tomahawk::DatabaseCommand_Resolve( query );
|
||||||
|
tasks.cmd = Tomahawk::dbcmd_ptr( cmd );
|
||||||
|
tasks.cmd->moveToThread( &thread );
|
||||||
|
QObject::connect( cmd, SIGNAL( results( Tomahawk::QID, QList<Tomahawk::result_ptr> ) ),
|
||||||
|
&tasks, SLOT( onResults(Tomahawk::QID, QList<Tomahawk::result_ptr>) ),
|
||||||
|
Qt::QueuedConnection );
|
||||||
|
QString dbpath = TomahawkUtils::appDataDir().absoluteFilePath( "tomahawk.db" );
|
||||||
|
QMetaObject::invokeMethod( &tasks, "startDatabase", Qt::QueuedConnection, Q_ARG( QString, dbpath ) );
|
||||||
|
|
||||||
|
// Wait until the dbcmd was executed.
|
||||||
|
thread.wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 )
|
||||||
|
Q_DECLARE_METATYPE( QList< Tomahawk::result_ptr > )
|
||||||
|
Q_DECLARE_METATYPE( Tomahawk::QID )
|
||||||
|
#endif
|
||||||
|
|
Reference in New Issue
Block a user