mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 13:47:26 +02:00
* Style fixes.
This commit is contained in:
@@ -41,13 +41,13 @@ Cache* Cache::instance()
|
|||||||
|
|
||||||
|
|
||||||
Cache::Cache()
|
Cache::Cache()
|
||||||
: QObject ( 0 )
|
: QObject( 0 )
|
||||||
, m_cacheBaseDir ( TomahawkSettings::instance()->storageCacheLocation() + "/GenericCache/" )
|
, m_cacheBaseDir( TomahawkSettings::instance()->storageCacheLocation() + "/GenericCache/" )
|
||||||
, m_cacheManifest ( m_cacheBaseDir + "cachemanifest.ini", QSettings::IniFormat )
|
, m_cacheManifest( m_cacheBaseDir + "cachemanifest.ini", QSettings::IniFormat )
|
||||||
{
|
{
|
||||||
m_pruneTimer.setInterval ( 300000 );
|
m_pruneTimer.setInterval( 300000 );
|
||||||
m_pruneTimer.setSingleShot ( false );
|
m_pruneTimer.setSingleShot( false );
|
||||||
connect ( &m_pruneTimer, SIGNAL ( timeout() ), SLOT ( pruneTimerFired() ) );
|
connect( &m_pruneTimer, SIGNAL( timeout() ), SLOT( pruneTimerFired() ) );
|
||||||
m_pruneTimer.start();
|
m_pruneTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,26 +65,26 @@ Cache::pruneTimerFired()
|
|||||||
qDebug() << Q_FUNC_INFO << "Pruning tomahawkcache";
|
qDebug() << Q_FUNC_INFO << "Pruning tomahawkcache";
|
||||||
qlonglong currentMSecsSinceEpoch = QDateTime::currentMSecsSinceEpoch();
|
qlonglong currentMSecsSinceEpoch = QDateTime::currentMSecsSinceEpoch();
|
||||||
|
|
||||||
QVariantList clients = m_cacheManifest.value ( "clients" ).toList();
|
QVariantList clients = m_cacheManifest.value( "clients" ).toList();
|
||||||
foreach ( const QVariant& client, clients )
|
foreach ( const QVariant& client, clients )
|
||||||
{
|
{
|
||||||
const QString client_identifier = client.toString();
|
const QString client_identifier = client.toString();
|
||||||
const QString cache_dir = m_cacheBaseDir + client_identifier;
|
const QString cache_dir = m_cacheBaseDir + client_identifier;
|
||||||
|
|
||||||
QSettings cached_settings ( cache_dir, QSettings::IniFormat );
|
QSettings cached_settings( cache_dir, QSettings::IniFormat );
|
||||||
const QStringList keys = cached_settings.allKeys();
|
const QStringList keys = cached_settings.allKeys();
|
||||||
foreach ( const QString& key, keys )
|
foreach ( const QString& key, keys )
|
||||||
{
|
{
|
||||||
CacheData data = cached_settings.value ( key ).value<TomahawkUtils::CacheData>();
|
CacheData data = cached_settings.value( key ).value<TomahawkUtils::CacheData>();
|
||||||
if ( data.maxAge < currentMSecsSinceEpoch )
|
if ( data.maxAge < currentMSecsSinceEpoch )
|
||||||
{
|
{
|
||||||
cached_settings.remove ( key );
|
cached_settings.remove( key );
|
||||||
tLog() << Q_FUNC_INFO << "Removed stale entry: " << client_identifier << key;
|
tLog() << Q_FUNC_INFO << "Removed stale entry: " << client_identifier << key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cached_settings.sync();
|
cached_settings.sync();
|
||||||
if ( cached_settings.allKeys().size() == 0 )
|
if ( cached_settings.allKeys().size() == 0 )
|
||||||
removeClient ( client_identifier );
|
removeClient( client_identifier );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,23 +95,23 @@ Cache::getData( const QString& identifier, const QString& key )
|
|||||||
QMutexLocker mutex_locker( &m_mutex );
|
QMutexLocker mutex_locker( &m_mutex );
|
||||||
|
|
||||||
const QString cacheDir = m_cacheBaseDir + identifier;
|
const QString cacheDir = m_cacheBaseDir + identifier;
|
||||||
QSettings cached_settings ( cacheDir, QSettings::IniFormat );
|
QSettings cached_settings( cacheDir, QSettings::IniFormat );
|
||||||
|
|
||||||
if ( cached_settings.contains ( key ) )
|
if ( cached_settings.contains( key ) )
|
||||||
{
|
{
|
||||||
CacheData data = cached_settings.value ( key ).value<TomahawkUtils::CacheData>();
|
CacheData data = cached_settings.value( key ).value<TomahawkUtils::CacheData>();
|
||||||
|
|
||||||
if ( data.maxAge < QDateTime::currentMSecsSinceEpoch() )
|
if ( data.maxAge < QDateTime::currentMSecsSinceEpoch() )
|
||||||
{
|
{
|
||||||
cached_settings.remove ( key );
|
cached_settings.remove( key );
|
||||||
tLog() << Q_FUNC_INFO << "Removed stale entry:" << identifier << key;
|
tLog() << Q_FUNC_INFO << "Removed stale entry:" << identifier << key;
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
// tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Fetched data for" << identifier << key;
|
tDebug() << Q_FUNC_INFO << "Fetched data for" << identifier << key;
|
||||||
return data.data;
|
return data.data;
|
||||||
|
|
||||||
}
|
}
|
||||||
// tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "No such key" << key;
|
tDebug() << Q_FUNC_INFO << "No such key" << key;
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,9 +122,9 @@ Cache::putData( const QString& identifier, qint64 maxAge, const QString& key, co
|
|||||||
QMutexLocker mutex_locker( &m_mutex );
|
QMutexLocker mutex_locker( &m_mutex );
|
||||||
|
|
||||||
const QString cacheDir = m_cacheBaseDir + identifier;
|
const QString cacheDir = m_cacheBaseDir + identifier;
|
||||||
addClient ( identifier );
|
addClient( identifier );
|
||||||
QSettings cached_settings ( cacheDir, QSettings::IniFormat );
|
QSettings cached_settings( cacheDir, QSettings::IniFormat );
|
||||||
cached_settings.setValue ( key, QVariant::fromValue ( CacheData ( QDateTime::currentMSecsSinceEpoch() + maxAge, value ) ) );
|
cached_settings.setValue( key, QVariant::fromValue( CacheData( QDateTime::currentMSecsSinceEpoch() + maxAge, value ) ) );
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Storing from client" << identifier << maxAge << key << value;
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Storing from client" << identifier << maxAge << key << value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,16 +132,17 @@ Cache::putData( const QString& identifier, qint64 maxAge, const QString& key, co
|
|||||||
void
|
void
|
||||||
Cache::addClient( const QString& identifier )
|
Cache::addClient( const QString& identifier )
|
||||||
{
|
{
|
||||||
QVariantList clients = m_cacheManifest.value ( "clients" ).toList();
|
QVariantList clients = m_cacheManifest.value( "clients" ).toList();
|
||||||
foreach ( const QVariant& client, clients )
|
foreach ( const QVariant& client, clients )
|
||||||
{
|
{
|
||||||
const QString client_identifier = client.toString();
|
const QString client_identifier = client.toString();
|
||||||
if ( identifier == client_identifier ) return;
|
if ( identifier == client_identifier )
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tLog() << Q_FUNC_INFO << "adding client" << identifier;
|
tLog() << Q_FUNC_INFO << "adding client" << identifier;
|
||||||
clients.append ( identifier );
|
clients.append( identifier );
|
||||||
m_cacheManifest.setValue ( "clients", clients );
|
m_cacheManifest.setValue( "clients", clients );
|
||||||
m_cacheManifest.sync();
|
m_cacheManifest.sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +150,7 @@ Cache::addClient( const QString& identifier )
|
|||||||
void
|
void
|
||||||
Cache::removeClient( const QString& identifier )
|
Cache::removeClient( const QString& identifier )
|
||||||
{
|
{
|
||||||
QVariantList clients = m_cacheManifest.value ( "clients" ).toList();
|
QVariantList clients = m_cacheManifest.value( "clients" ).toList();
|
||||||
QVariantList::iterator it = clients.begin();
|
QVariantList::iterator it = clients.begin();
|
||||||
while ( it != clients.end() )
|
while ( it != clients.end() )
|
||||||
{
|
{
|
||||||
@@ -157,7 +158,7 @@ Cache::removeClient( const QString& identifier )
|
|||||||
if ( identifier == client_identifier )
|
if ( identifier == client_identifier )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "removing client" << identifier;
|
tLog() << Q_FUNC_INFO << "removing client" << identifier;
|
||||||
clients.erase ( it );
|
clients.erase( it );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++it;
|
++it;
|
||||||
|
Reference in New Issue
Block a user