mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-01 17:58:29 +00:00
Starting to make use of the Preferences class in the Indexer and Library::LocalDB.
This commit is contained in:
parent
5631f10064
commit
991f517ba5
@ -40,6 +40,7 @@
|
||||
#include <core/db/Connection.h>
|
||||
#include <core/db/Statement.h>
|
||||
#include <core/PluginFactory.h>
|
||||
#include <core/Preferences.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
@ -48,7 +49,12 @@
|
||||
|
||||
using namespace musik::core;
|
||||
|
||||
Indexer::Indexer(void) : oThread(NULL),iTimeout(3600),iProgress(0),iStatus(0){
|
||||
Indexer::Indexer(void)
|
||||
:oThread(NULL)
|
||||
,iProgress(0)
|
||||
,iStatus(0)
|
||||
,bRestart(false)
|
||||
{
|
||||
}
|
||||
|
||||
Indexer::~Indexer(void){
|
||||
@ -423,26 +429,46 @@ void Indexer::SyncDirectory(utfstring &sFolder,DBINT iParentFolderId,DBINT iPath
|
||||
//////////////////////////////////////////
|
||||
void Indexer::ThreadLoop(){
|
||||
|
||||
bool firstTime(true);
|
||||
|
||||
while(!this->Exit()){
|
||||
|
||||
this->SynchronizeStart();
|
||||
// Get preferences
|
||||
Preferences prefs("Indexer");
|
||||
|
||||
// Database should only be open when synchronizing
|
||||
this->dbConnection.Open(this->database.c_str(),0,4096);
|
||||
this->RestartSync(false);
|
||||
this->Synchronize();
|
||||
this->dbConnection.Close();
|
||||
if(!firstTime || (firstTime && prefs.GetBool("SyncOnStartup",true))){
|
||||
|
||||
this->SynchronizeEnd();
|
||||
this->SynchronizeStart();
|
||||
|
||||
int dbCache = prefs.GetInt("DatabaseCache",4096);
|
||||
|
||||
boost::xtime oWaitTime;
|
||||
boost::xtime_get(&oWaitTime, boost::TIME_UTC);
|
||||
oWaitTime.sec += this->iTimeout;
|
||||
// Database should only be open when synchronizing
|
||||
this->dbConnection.Open(this->database.c_str(),0,dbCache);
|
||||
this->RestartSync(false);
|
||||
this->Synchronize();
|
||||
this->dbConnection.Close();
|
||||
|
||||
if(!this->Restarted()){
|
||||
this->NotificationTimedWait(oWaitTime);
|
||||
this->SynchronizeEnd();
|
||||
}
|
||||
firstTime = false;
|
||||
|
||||
|
||||
int syncTimeout = prefs.GetInt("SyncTimeout",3600);
|
||||
|
||||
if(syncTimeout){
|
||||
// Sync every "syncTimeout" second
|
||||
boost::xtime oWaitTime;
|
||||
boost::xtime_get(&oWaitTime, boost::TIME_UTC);
|
||||
oWaitTime.sec += syncTimeout;
|
||||
|
||||
if(!this->Restarted()){
|
||||
this->NotificationTimedWait(oWaitTime);
|
||||
}
|
||||
}else{
|
||||
// No continous syncing
|
||||
if(!this->Restarted()){
|
||||
this->NotificationWait();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -62,8 +62,6 @@ namespace musik{ namespace core{
|
||||
bool Startup(utfstring setLibraryPath);
|
||||
void ThreadLoop();
|
||||
|
||||
int iTimeout;
|
||||
|
||||
utfstring GetStatus();
|
||||
void RestartSync(bool bNewRestart=true);
|
||||
bool Restarted();
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "pch.hpp"
|
||||
#include <core/Library/LocalDB.h>
|
||||
#include <core/Query/Base.h>
|
||||
#include <core/Preferences.h>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
@ -239,8 +240,10 @@ void Library::LocalDB::CreateDatabase(){
|
||||
//////////////////////////////////////////
|
||||
void Library::LocalDB::ThreadLoop(){
|
||||
|
||||
Preferences prefs("Library");
|
||||
|
||||
utfstring database(this->GetDBPath());
|
||||
this->db.Open(database.c_str(),0,4096);
|
||||
this->db.Open(database.c_str(),0,prefs.GetInt("DatabaseCache",4096));
|
||||
|
||||
this->CreateDatabase();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user