diff --git a/src/tools/database-reader/CMakeLists.txt b/src/tools/database-reader/CMakeLists.txt index bd3489057..d5fad61ec 100644 --- a/src/tools/database-reader/CMakeLists.txt +++ b/src/tools/database-reader/CMakeLists.txt @@ -18,3 +18,23 @@ target_link_libraries( tomahawk_db_list_artists_bin qt5_use_modules(tomahawk_db_list_artists_bin Core) 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} ) + diff --git a/src/tools/database-reader/fuzzysearch.cpp b/src/tools/database-reader/fuzzysearch.cpp new file mode 100644 index 000000000..10cfed2b9 --- /dev/null +++ b/src/tools/database-reader/fuzzysearch.cpp @@ -0,0 +1,82 @@ +#include "database/Database.h" +#include "database/DatabaseCommand_Resolve.h" +#include "utils/TomahawkUtils.h" +#include "TomahawkVersion.h" +#include "Typedefs.h" + +#include +#include + +#include + + +class Tasks: public QObject +{ +Q_OBJECT +public: + Q_INVOKABLE void startDatabase( QString dbpath ) + { + database = QSharedPointer( new Tomahawk::Database( dbpath ) ); + connect( database.data(), SIGNAL( ready() ), SLOT( runCmd() ), Qt::QueuedConnection ); + database->loadIndex(); + } + + Tomahawk::dbcmd_ptr cmd; + QSharedPointer 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 ) ), + &tasks, SLOT( onResults(Tomahawk::QID, QList) ), + 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 +