1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-08 07:07:05 +02:00

Add necessary hooks for hatchet dbcmd syncing

This commit is contained in:
Jeff Mitchell
2013-03-05 01:24:48 -05:00
parent c4fbcdfcbc
commit 9d827819d8
5 changed files with 31 additions and 7 deletions

View File

@@ -27,6 +27,7 @@
#include "network/ControlConnection.h" #include "network/ControlConnection.h"
#include "database/DatabaseCommand_AddSource.h" #include "database/DatabaseCommand_AddSource.h"
#include "database/DatabaseCommand_CollectionStats.h" #include "database/DatabaseCommand_CollectionStats.h"
#include "database/DatabaseCommand_LoadAllSources.h"
#include "database/DatabaseCommand_SourceOffline.h" #include "database/DatabaseCommand_SourceOffline.h"
#include "database/DatabaseCommand_UpdateSearchIndex.h" #include "database/DatabaseCommand_UpdateSearchIndex.h"
#include "database/Database.h" #include "database/Database.h"
@@ -415,6 +416,15 @@ Source::lastCmdGuid() const
} }
void
Source::setLastCmdGuid( const QString& guid )
{
tLog() << Q_FUNC_INFO << "name is " << friendlyName() << " and guid is " << guid;
QMutexLocker lock( &m_cmdMutex );
m_lastCmdGuid = guid;
}
void void
Source::addCommand( const QSharedPointer<DatabaseCommand>& command ) Source::addCommand( const QSharedPointer<DatabaseCommand>& command )
{ {

View File

@@ -33,10 +33,11 @@
#include "DllMacro.h" #include "DllMacro.h"
class ControlConnection; class ControlConnection;
class DatabaseCommand_DeleteFiles;
class DatabaseCommand_LoadAllSources;
class DatabaseCommand_LogPlayback; class DatabaseCommand_LogPlayback;
class DatabaseCommand_SocialAction; class DatabaseCommand_SocialAction;
class DatabaseCommand_UpdateSearchIndex; class DatabaseCommand_UpdateSearchIndex;
class DatabaseCommand_DeleteFiles;
class MusicScanner; class MusicScanner;
namespace Tomahawk namespace Tomahawk
@@ -48,10 +49,11 @@ Q_OBJECT
friend class ::DBSyncConnection; friend class ::DBSyncConnection;
friend class ::ControlConnection; friend class ::ControlConnection;
friend class ::DatabaseCommand_LogPlayback;
friend class ::DatabaseCommand_SocialAction;
friend class ::DatabaseCommand_AddFiles; friend class ::DatabaseCommand_AddFiles;
friend class ::DatabaseCommand_DeleteFiles; friend class ::DatabaseCommand_DeleteFiles;
friend class ::DatabaseCommand_LoadAllSources;
friend class ::DatabaseCommand_LogPlayback;
friend class ::DatabaseCommand_SocialAction;
friend class ::MusicScanner; friend class ::MusicScanner;
public: public:
@@ -124,10 +126,11 @@ signals:
public slots: public slots:
void setStats( const QVariantMap& m ); void setStats( const QVariantMap& m );
QString lastCmdGuid() const;
private slots: private slots:
void setLastCmdGuid( const QString& guid );
void dbLoaded( unsigned int id, const QString& fname ); void dbLoaded( unsigned int id, const QString& fname );
QString lastCmdGuid() const;
void updateIndexWhenSynced(); void updateIndexWhenSynced();
void setOffline(); void setOffline();

View File

@@ -21,7 +21,7 @@
#include <QSqlQuery> #include <QSqlQuery>
#include "network/Servent.h" #include "network/Servent.h"
#include "Source.h" #include "SourceList.h"
#include "DatabaseImpl.h" #include "DatabaseImpl.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@@ -33,7 +33,15 @@ DatabaseCommand_LoadAllSources::exec( DatabaseImpl* dbi )
{ {
TomahawkSqlQuery query = dbi->newquery(); TomahawkSqlQuery query = dbi->newquery();
query.exec( QString( "SELECT id, name, friendlyname " query.exec( QString( "SELECT guid "
"FROM oplog "
"WHERE source IS NULL "
"ORDER BY id DESC LIMIT 1" ) );
if ( query.next() )
if ( SourceList::instance() && !SourceList::instance()->getLocal().isNull() )
SourceList::instance()->getLocal()->setLastCmdGuid( query.value( 0 ).toString() );
query.exec( QString( "SELECT id, name, friendlyname, lastop "
"FROM source" ) ); "FROM source" ) );
QList<source_ptr> sources; QList<source_ptr> sources;
@@ -41,6 +49,7 @@ DatabaseCommand_LoadAllSources::exec( DatabaseImpl* dbi )
{ {
source_ptr src( new Source( query.value( 0 ).toUInt(), query.value( 1 ).toString() ) ); source_ptr src( new Source( query.value( 0 ).toUInt(), query.value( 1 ).toString() ) );
src->setDbFriendlyName( query.value( 2 ).toString() ); src->setDbFriendlyName( query.value( 2 ).toString() );
src->setLastCmdGuid( query.value( 3 ).toString() );
sources << src; sources << src;
} }

View File

@@ -1051,7 +1051,7 @@ void
Servent::triggerDBSync() Servent::triggerDBSync()
{ {
// tell peers we have new stuff they should sync // tell peers we have new stuff they should sync
QList<source_ptr> sources = SourceList::instance()->sources(); QList< source_ptr > sources = SourceList::instance()->sources();
foreach ( const source_ptr& src, sources ) foreach ( const source_ptr& src, sources )
{ {
// skip local source // skip local source
@@ -1061,6 +1061,7 @@ Servent::triggerDBSync()
if ( src->controlConnection() && src->controlConnection()->dbSyncConnection() ) // source online? if ( src->controlConnection() && src->controlConnection()->dbSyncConnection() ) // source online?
src->controlConnection()->dbSyncConnection()->trigger(); src->controlConnection()->dbSyncConnection()->trigger();
} }
emit dbSyncTriggered();
} }

View File

@@ -137,6 +137,7 @@ public:
bool isReady() const { return m_ready; }; bool isReady() const { return m_ready; };
signals: signals:
void dbSyncTriggered();
void streamStarted( StreamConnection* ); void streamStarted( StreamConnection* );
void streamFinished( StreamConnection* ); void streamFinished( StreamConnection* );
void ready(); void ready();