mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
[tool] Add helper to list all artists in the database
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
|
add_subdirectory( database-reader )
|
||||||
add_subdirectory( tomahawk-test-musicscan )
|
add_subdirectory( tomahawk-test-musicscan )
|
||||||
|
20
src/tools/database-reader/CMakeLists.txt
Normal file
20
src/tools/database-reader/CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
set( tomahawk_db_list_artists_src
|
||||||
|
listartists.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
|
add_executable( tomahawk_db_list_artists_bin WIN32 MACOSX_BUNDLE
|
||||||
|
${tomahawk_db_list_artists_src} )
|
||||||
|
set_target_properties( tomahawk_db_list_artists_bin
|
||||||
|
PROPERTIES
|
||||||
|
AUTOMOC TRUE
|
||||||
|
RUNTIME_OUTPUT_NAME tomahawk-db-list-artists
|
||||||
|
)
|
||||||
|
target_link_libraries( tomahawk_db_list_artists_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} )
|
||||||
|
|
83
src/tools/database-reader/listartists.cpp
Normal file
83
src/tools/database-reader/listartists.cpp
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
#include "database/Database.h"
|
||||||
|
#include "database/DatabaseCommand_AllArtists.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( runDbCmd() ), Qt::QueuedConnection );
|
||||||
|
database->loadIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
Tomahawk::dbcmd_ptr cmd;
|
||||||
|
QSharedPointer<Tomahawk::Database> database;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void runDbCmd()
|
||||||
|
{
|
||||||
|
// TODO FIX database so that ready is emitted after the index is loaded and at least one worker runs.
|
||||||
|
database->enqueue( cmd );
|
||||||
|
}
|
||||||
|
|
||||||
|
void dbCmdDone( const QList<Tomahawk::artist_ptr>& artists )
|
||||||
|
{
|
||||||
|
std::cout << "=== ARTISTS - START ===" << std::endl;
|
||||||
|
foreach ( const Tomahawk::artist_ptr& artist, artists )
|
||||||
|
{
|
||||||
|
std::cout << artist->name().toStdString() << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << "=== ARTISTS - END ===" << std::endl;
|
||||||
|
QMetaObject::invokeMethod( thread(), "quit", Qt::QueuedConnection );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Include needs to go here as Tasks needs to be defined before.
|
||||||
|
#include "listartists.moc"
|
||||||
|
|
||||||
|
int main( int argc, char* argv[] )
|
||||||
|
{
|
||||||
|
QCoreApplication app( argc, argv );
|
||||||
|
// TODO: Add an argument to change the path
|
||||||
|
app.setOrganizationName( QLatin1String( TOMAHAWK_ORGANIZATION_NAME ) );
|
||||||
|
|
||||||
|
// 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( 0 );
|
||||||
|
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::DatabaseCommand_AllArtists* cmd = new Tomahawk::DatabaseCommand_AllArtists();
|
||||||
|
tasks.cmd = Tomahawk::dbcmd_ptr( cmd );
|
||||||
|
tasks.cmd->moveToThread( &thread );
|
||||||
|
qRegisterMetaType< QList< Tomahawk::artist_ptr > >();
|
||||||
|
QObject::connect( cmd, SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
|
||||||
|
&tasks, SLOT( dbCmdDone( QList<Tomahawk::artist_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::artist_ptr > )
|
||||||
|
#endif
|
Reference in New Issue
Block a user