mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 21:57:41 +02:00
Initial work on ACL system. Also makes much of Tomahawk handle a QStringList for collection directories.
This commit is contained in:
@@ -165,7 +165,7 @@ private:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoGenericMap )
|
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoGenericMap );
|
||||||
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoCustomDataHash );
|
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoCustomDataHash );
|
||||||
|
|
||||||
#endif // TOMAHAWK_INFOSYSTEM_H
|
#endif // TOMAHAWK_INFOSYSTEM_H
|
||||||
|
@@ -16,6 +16,7 @@ set( libSources
|
|||||||
sourcelist.cpp
|
sourcelist.cpp
|
||||||
pipeline.cpp
|
pipeline.cpp
|
||||||
|
|
||||||
|
aclsystem.cpp
|
||||||
artist.cpp
|
artist.cpp
|
||||||
album.cpp
|
album.cpp
|
||||||
collection.cpp
|
collection.cpp
|
||||||
@@ -155,6 +156,7 @@ set( libHeaders
|
|||||||
pipeline.h
|
pipeline.h
|
||||||
functimeout.h
|
functimeout.h
|
||||||
|
|
||||||
|
aclsystem.h
|
||||||
collection.h
|
collection.h
|
||||||
query.h
|
query.h
|
||||||
resolver.h
|
resolver.h
|
||||||
|
72
src/libtomahawk/aclsystem.cpp
Normal file
72
src/libtomahawk/aclsystem.cpp
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "aclsystem.h"
|
||||||
|
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
|
#include <tomahawksettings.h>
|
||||||
|
|
||||||
|
ACLSystem::ACLSystem( QObject* parent )
|
||||||
|
: QObject( parent ),
|
||||||
|
m_saveTimer( this )
|
||||||
|
{
|
||||||
|
//TODO: read from settings file into cache
|
||||||
|
m_saveTimer.setSingleShot( false );
|
||||||
|
m_saveTimer.setInterval( 60000 );
|
||||||
|
connect( &m_saveTimer, SIGNAL( timeout() ), this, SLOT( saveTimerFired() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
ACLSystem::~ACLSystem()
|
||||||
|
{
|
||||||
|
//TODO: save from cache into settings file
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ACLSystem::authorize( const QString& dbid, const QString& path, ACLType type )
|
||||||
|
{
|
||||||
|
TomahawkSettings *s = TomahawkSettings::instance();
|
||||||
|
if ( !s->scannerPath().contains( path ) )
|
||||||
|
{
|
||||||
|
qDebug() << "path selected is not in our scanner path!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QHash< QString, ACLType > peerHash;
|
||||||
|
if ( m_cache.contains( "dbid" ) )
|
||||||
|
peerHash = m_cache["dbid"];
|
||||||
|
peerHash[path] = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ACLSystem::isAuthorized( const QString& dbid, const QString& path )
|
||||||
|
{
|
||||||
|
if ( !m_cache.contains( "dbid" ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QHash< QString, ACLType > peerHash = m_cache["dbid"];
|
||||||
|
if ( !peerHash.contains( path ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return peerHash[path] == ACLSystem::Allow;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ACLSystem::saveTimerFired()
|
||||||
|
{
|
||||||
|
//TODO: save from cache into settings file
|
||||||
|
}
|
54
src/libtomahawk/aclsystem.h
Normal file
54
src/libtomahawk/aclsystem.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TOMAHAWK_ACLSYSTEM_H
|
||||||
|
#define TOMAHAWK_ACLSYSTEM_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include <QHash>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "dllmacro.h"
|
||||||
|
|
||||||
|
class DLLEXPORT ACLSystem : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
enum ACLType {
|
||||||
|
Allow,
|
||||||
|
Deny
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ACLSystem( QObject *parent = 0 );
|
||||||
|
~ACLSystem();
|
||||||
|
|
||||||
|
bool isAuthorized( const QString &dbid, const QString &path );
|
||||||
|
void authorize( const QString &dbid, const QString &path, ACLType type );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void saveTimerFired();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QHash< QString, QHash< QString, ACLType> > m_cache;
|
||||||
|
QTimer m_saveTimer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TOMAHAWK_ACLSYSTEM_H
|
@@ -65,19 +65,19 @@ TomahawkSettings::~TomahawkSettings()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QStringList
|
||||||
TomahawkSettings::scannerPath() const
|
TomahawkSettings::scannerPath() const
|
||||||
{
|
{
|
||||||
#ifndef TOMAHAWK_HEADLESS
|
#ifndef TOMAHAWK_HEADLESS
|
||||||
return value( "scannerpath", QDesktopServices::storageLocation( QDesktopServices::MusicLocation ) ).toString();
|
return value( "scannerpath", QDesktopServices::storageLocation( QDesktopServices::MusicLocation ) ).toStringList();
|
||||||
#else
|
#else
|
||||||
return value( "scannerpath", "" ).toString();
|
return value( "scannerpath", "" ).toStringList();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TomahawkSettings::setScannerPath( const QString& path )
|
TomahawkSettings::setScannerPath( const QStringList& path )
|
||||||
{
|
{
|
||||||
setValue( "scannerpath", path );
|
setValue( "scannerpath", path );
|
||||||
}
|
}
|
||||||
|
@@ -41,8 +41,8 @@ public:
|
|||||||
void applyChanges() { emit changed(); }
|
void applyChanges() { emit changed(); }
|
||||||
|
|
||||||
/// General settings
|
/// General settings
|
||||||
QString scannerPath() const; /// QDesktopServices::MusicLocation by default
|
QStringList scannerPath() const; /// QDesktopServices::MusicLocation by default
|
||||||
void setScannerPath( const QString& path );
|
void setScannerPath( const QStringList& path );
|
||||||
bool hasScannerPath() const;
|
bool hasScannerPath() const;
|
||||||
|
|
||||||
bool acceptedLegalWarning() const;
|
bool acceptedLegalWarning() const;
|
||||||
|
@@ -70,9 +70,9 @@ DirLister::scanDir( QDir dir, int depth )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MusicScanner::MusicScanner( const QString& dir, quint32 bs )
|
MusicScanner::MusicScanner( const QStringList& dirs, quint32 bs )
|
||||||
: QObject()
|
: QObject()
|
||||||
, m_dir( dir )
|
, m_dirs( dirs )
|
||||||
, m_batchsize( bs )
|
, m_batchsize( bs )
|
||||||
, m_dirLister( 0 )
|
, m_dirLister( 0 )
|
||||||
, m_dirListerThreadController( 0 )
|
, m_dirListerThreadController( 0 )
|
||||||
@@ -122,7 +122,8 @@ MusicScanner::startScan()
|
|||||||
m_skippedFiles.clear();
|
m_skippedFiles.clear();
|
||||||
|
|
||||||
// trigger the scan once we've loaded old mtimes for dirs below our path
|
// trigger the scan once we've loaded old mtimes for dirs below our path
|
||||||
DatabaseCommand_DirMtimes* cmd = new DatabaseCommand_DirMtimes( m_dir );
|
//FIXME: MULTIPLECOLLECTIONDIRS
|
||||||
|
DatabaseCommand_DirMtimes* cmd = new DatabaseCommand_DirMtimes( m_dirs.first() );
|
||||||
connect( cmd, SIGNAL( done( QMap<QString, unsigned int> ) ),
|
connect( cmd, SIGNAL( done( QMap<QString, unsigned int> ) ),
|
||||||
SLOT( setMtimes( QMap<QString, unsigned int> ) ) );
|
SLOT( setMtimes( QMap<QString, unsigned int> ) ) );
|
||||||
connect( cmd, SIGNAL( done( QMap<QString, unsigned int> ) ),
|
connect( cmd, SIGNAL( done( QMap<QString, unsigned int> ) ),
|
||||||
@@ -148,7 +149,9 @@ MusicScanner::scan()
|
|||||||
SLOT( commitBatch( QVariantList ) ), Qt::DirectConnection );
|
SLOT( commitBatch( QVariantList ) ), Qt::DirectConnection );
|
||||||
|
|
||||||
m_dirListerThreadController = new QThread( this );
|
m_dirListerThreadController = new QThread( this );
|
||||||
m_dirLister = new DirLister( QDir( m_dir, 0 ), m_dirmtimes );
|
|
||||||
|
//FIXME: MULTIPLECOLLECTIONDIRS
|
||||||
|
m_dirLister = new DirLister( QDir( m_dirs.first(), 0 ), m_dirmtimes );
|
||||||
m_dirLister->moveToThread( m_dirListerThreadController );
|
m_dirLister->moveToThread( m_dirListerThreadController );
|
||||||
|
|
||||||
connect( m_dirLister, SIGNAL( fileToScan( QFileInfo ) ),
|
connect( m_dirLister, SIGNAL( fileToScan( QFileInfo ) ),
|
||||||
|
@@ -69,7 +69,7 @@ class MusicScanner : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MusicScanner( const QString& dir, quint32 bs = 0 );
|
MusicScanner( const QStringList& dirs, quint32 bs = 0 );
|
||||||
~MusicScanner();
|
~MusicScanner();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@@ -92,7 +92,7 @@ private slots:
|
|||||||
void commitBatch( const QVariantList& );
|
void commitBatch( const QVariantList& );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_dir;
|
QStringList m_dirs;
|
||||||
QMap<QString, QString> m_ext2mime; // eg: mp3 -> audio/mpeg
|
QMap<QString, QString> m_ext2mime; // eg: mp3 -> audio/mpeg
|
||||||
unsigned int m_scanned;
|
unsigned int m_scanned;
|
||||||
unsigned int m_skipped;
|
unsigned int m_skipped;
|
||||||
|
@@ -89,9 +89,10 @@ ScanManager::onSettingsChanged()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScanManager::runManualScan( const QString& path )
|
ScanManager::runManualScan( const QStringList& path )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
if ( !m_musicScannerThreadController && !m_scanner ) //still running if these are not zero
|
if ( !m_musicScannerThreadController && !m_scanner ) //still running if these are not zero
|
||||||
{
|
{
|
||||||
m_musicScannerThreadController = new QThread( this );
|
m_musicScannerThreadController = new QThread( this );
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#define SCANMANAGER_H
|
#define SCANMANAGER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
|
|
||||||
@@ -36,7 +37,7 @@ public:
|
|||||||
explicit ScanManager( QObject* parent = 0 );
|
explicit ScanManager( QObject* parent = 0 );
|
||||||
virtual ~ScanManager();
|
virtual ~ScanManager();
|
||||||
|
|
||||||
void runManualScan( const QString& path );
|
void runManualScan( const QStringList& path );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void finished();
|
void finished();
|
||||||
@@ -53,7 +54,7 @@ private:
|
|||||||
|
|
||||||
MusicScanner* m_scanner;
|
MusicScanner* m_scanner;
|
||||||
QThread* m_musicScannerThreadController;
|
QThread* m_musicScannerThreadController;
|
||||||
QString m_currScannerPath;
|
QStringList m_currScannerPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -86,7 +86,8 @@ SettingsDialog::SettingsDialog( QWidget *parent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MUSIC SCANNER
|
// MUSIC SCANNER
|
||||||
ui->lineEditMusicPath->setText( s->scannerPath() );
|
//FIXME: MULTIPLECOLLECTIONDIRS
|
||||||
|
ui->lineEditMusicPath->setText( s->scannerPath().first() );
|
||||||
|
|
||||||
// LAST FM
|
// LAST FM
|
||||||
ui->checkBoxEnableLastfm->setChecked( s->scrobblingEnabled() );
|
ui->checkBoxEnableLastfm->setChecked( s->scrobblingEnabled() );
|
||||||
@@ -133,7 +134,7 @@ SettingsDialog::~SettingsDialog()
|
|||||||
s->setExternalHostname( ui->staticHostName->text() );
|
s->setExternalHostname( ui->staticHostName->text() );
|
||||||
s->setExternalPort( ui->staticPort->value() );
|
s->setExternalPort( ui->staticPort->value() );
|
||||||
|
|
||||||
s->setScannerPath( ui->lineEditMusicPath->text() );
|
s->setScannerPath( QStringList( ui->lineEditMusicPath->text() ) );
|
||||||
|
|
||||||
s->setScrobblingEnabled( ui->checkBoxEnableLastfm->isChecked() );
|
s->setScrobblingEnabled( ui->checkBoxEnableLastfm->isChecked() );
|
||||||
s->setLastFmUsername( ui->lineEditLastfmUsername->text() );
|
s->setLastFmUsername( ui->lineEditLastfmUsername->text() );
|
||||||
|
Reference in New Issue
Block a user