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

Some more acl cleanup, and put Acl->ACL so we don't mess up peoples' existing configs

This commit is contained in:
Jeff Mitchell
2012-06-30 14:44:06 -04:00
parent 5547a9741d
commit 67e18c3b9d
12 changed files with 156 additions and 145 deletions

View File

@@ -37,30 +37,30 @@
#include "utils/Logger.h" #include "utils/Logger.h"
AclRegistryImpl::AclRegistryImpl( QObject* parent ) ACLRegistryImpl::ACLRegistryImpl( QObject* parent )
: AclRegistry( parent ) : ACLRegistry( parent )
, m_jobCount( 0 ) , m_jobCount( 0 )
{ {
AclRegistry::setInstance( this ); ACLRegistry::setInstance( this );
load(); load();
} }
AclRegistryImpl::~AclRegistryImpl() ACLRegistryImpl::~ACLRegistryImpl()
{ {
save(); save();
} }
AclRegistry::ACL ACLRegistry::ACL
AclRegistryImpl::isAuthorizedUser( const QString& dbid, const QString &username, AclRegistry::ACL globalType, bool skipEmission ) ACLRegistryImpl::isAuthorizedUser( const QString& dbid, const QString &username, ACLRegistry::ACL globalType, bool skipEmission )
{ {
tLog() << Q_FUNC_INFO; tLog() << Q_FUNC_INFO;
if ( QThread::currentThread() != TOMAHAWK_APPLICATION::instance()->thread() ) if ( QThread::currentThread() != TOMAHAWK_APPLICATION::instance()->thread() )
{ {
if ( !skipEmission ) if ( !skipEmission )
QMetaObject::invokeMethod( this, "isAuthorizedUser", Qt::QueuedConnection, Q_ARG( const QString&, dbid ), Q_ARG( const QString &, username ), Q_ARG( AclRegistry::ACL, globalType ), Q_ARG( bool, skipEmission ) ); QMetaObject::invokeMethod( this, "isAuthorizedUser", Qt::QueuedConnection, Q_ARG( const QString&, dbid ), Q_ARG( const QString &, username ), Q_ARG( ACLRegistry::ACL, globalType ), Q_ARG( bool, skipEmission ) );
return AclRegistry::NotFound; return ACLRegistry::NotFound;
} }
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS
@@ -77,18 +77,18 @@ AclRegistryImpl::isAuthorizedUser( const QString& dbid, const QString &username,
if ( account->accountFriendlyName() == username ) if ( account->accountFriendlyName() == username )
{ {
if ( !skipEmission ) if ( !skipEmission )
emit aclResult( dbid, username, AclRegistry::Stream ); emit aclResult( dbid, username, ACLRegistry::Stream );
return AclRegistry::Stream; return ACLRegistry::Stream;
} }
} }
} }
#endif #endif
bool found = false; bool found = false;
QMutableListIterator< AclRegistry::User > i( m_cache ); QMutableListIterator< ACLRegistry::User > i( m_cache );
while ( i.hasNext() ) while ( i.hasNext() )
{ {
AclRegistry::User user = i.next(); ACLRegistry::User user = i.next();
foreach ( QString knowndbid, user.knownDbids ) foreach ( QString knowndbid, user.knownDbids )
{ {
if ( dbid == knowndbid ) if ( dbid == knowndbid )
@@ -119,24 +119,24 @@ AclRegistryImpl::isAuthorizedUser( const QString& dbid, const QString &username,
} }
if ( skipEmission ) if ( skipEmission )
return AclRegistry::NotFound; return ACLRegistry::NotFound;
// User was not found, create a new user entry // User was not found, create a new user entry
AclRegistry::User user; ACLRegistry::User user;
user.knownDbids.append( dbid ); user.knownDbids.append( dbid );
user.knownAccountIds.append( username ); user.knownAccountIds.append( username );
if ( globalType != AclRegistry::NotFound ) if ( globalType != ACLRegistry::NotFound )
user.acl = globalType; user.acl = globalType;
#ifdef ENABLE_HEADLESS #ifdef ENABLE_HEADLESS
user.acl = AclRegistry::Stream; user.acl = ACLRegistry::Stream;
#else #else
if ( !TomahawkUtils::headless() ) if ( !TomahawkUtils::headless() )
{ {
getUserDecision( user, username ); getUserDecision( user, username );
return AclRegistry::NotFound; return ACLRegistry::NotFound;
} }
else else
user.acl = AclRegistry::Stream; user.acl = ACLRegistry::Stream;
#endif #endif
m_cache.append( user ); m_cache.append( user );
save(); save();
@@ -147,20 +147,20 @@ AclRegistryImpl::isAuthorizedUser( const QString& dbid, const QString &username,
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS
void void
AclRegistryImpl::getUserDecision( AclRegistry::User user, const QString &username ) ACLRegistryImpl::getUserDecision( ACLRegistry::User user, const QString &username )
{ {
if ( TomahawkUtils::headless() ) if ( TomahawkUtils::headless() )
return; return;
tLog() << Q_FUNC_INFO; tLog() << Q_FUNC_INFO;
AclJobItem* job = new AclJobItem( user, username ); ACLJobItem* job = new ACLJobItem( user, username );
m_jobQueue.enqueue( job ); m_jobQueue.enqueue( job );
QTimer::singleShot( 0, this, SLOT( queueNextJob() ) ); QTimer::singleShot( 0, this, SLOT( queueNextJob() ) );
} }
void void
AclRegistryImpl::userDecision( AclRegistry::User user ) ACLRegistryImpl::userDecision( ACLRegistry::User user )
{ {
if ( TomahawkUtils::headless() ) if ( TomahawkUtils::headless() )
return; return;
@@ -177,7 +177,7 @@ AclRegistryImpl::userDecision( AclRegistry::User user )
void void
AclRegistryImpl::queueNextJob() ACLRegistryImpl::queueNextJob()
{ {
if ( TomahawkUtils::headless() ) if ( TomahawkUtils::headless() )
return; return;
@@ -194,13 +194,13 @@ AclRegistryImpl::queueNextJob()
if ( !m_jobQueue.isEmpty() ) if ( !m_jobQueue.isEmpty() )
{ {
AclJobItem* job = m_jobQueue.dequeue(); ACLJobItem* job = m_jobQueue.dequeue();
AclRegistry::User user = job->user(); ACLRegistry::User user = job->user();
bool found = false; bool found = false;
foreach( QString dbid, user.knownDbids ) foreach( QString dbid, user.knownDbids )
{ {
AclRegistry::ACL acl = isAuthorizedUser( dbid, job->username(), AclRegistry::NotFound, true ); ACLRegistry::ACL acl = isAuthorizedUser( dbid, job->username(), ACLRegistry::NotFound, true );
if ( acl != AclRegistry::NotFound ) if ( acl != ACLRegistry::NotFound )
{ {
tLog() << Q_FUNC_INFO << "Found existing acl entry for = " << user.knownAccountIds.first(); tLog() << Q_FUNC_INFO << "Found existing acl entry for = " << user.knownAccountIds.first();
found = true; found = true;
@@ -219,15 +219,54 @@ AclRegistryImpl::queueNextJob()
tLog() << Q_FUNC_INFO << "activating job for user" << user.knownAccountIds.first(); tLog() << Q_FUNC_INFO << "activating job for user" << user.knownAccountIds.first();
m_jobCount++; m_jobCount++;
JobStatusView::instance()->model()->addJob( job ); JobStatusView::instance()->model()->addJob( job );
connect( job, SIGNAL( userDecision( AclRegistry::User ) ), this, SLOT( userDecision( AclRegistry::User ) ) ); connect( job, SIGNAL( userDecision( ACLRegistry::User ) ), this, SLOT( userDecision( ACLRegistry::User ) ) );
} }
} }
} }
#endif #endif
void void
AclRegistryImpl::wipeEntries() ACLRegistryImpl::wipeEntries()
{ {
AclRegistry::wipeEntries(); ACLRegistry::wipeEntries();
save(); save();
} }
void
ACLRegistryImpl::load()
{
tLog() << Q_FUNC_INFO;
QVariantList entryList = TomahawkSettings::instance()->aclEntries();
foreach ( QVariant entry, entryList )
{
if ( !entry.isValid() || !entry.canConvert< ACLRegistry::User >() )
{
tLog() << Q_FUNC_INFO << "entry is invalid";
continue;
}
tLog() << Q_FUNC_INFO << "loading entry";
ACLRegistry::User entryUser = entry.value< ACLRegistry::User >();
if ( entryUser.knownAccountIds.empty() || entryUser.knownDbids.empty() )
{
tLog() << Q_FUNC_INFO << "user known account/dbids is empty";
continue;
}
m_cache.append( entryUser );
}
}
void
ACLRegistryImpl::save()
{
tLog() << Q_FUNC_INFO;
QVariantList entryList;
foreach ( ACLRegistry::User user, m_cache )
{
tLog() << Q_FUNC_INFO << "user is " << user.uuid << " with known name " << user.knownAccountIds.first();
QVariant val = QVariant::fromValue< ACLRegistry::User >( user );
if ( val.isValid() )
entryList.append( val );
}
TomahawkSettings::instance()->setAclEntries( entryList );
}

View File

@@ -34,43 +34,46 @@
#include "HeadlessCheck.h" #include "HeadlessCheck.h"
#include "DllMacro.h" #include "DllMacro.h"
class AclJobItem; class ACLJobItem;
class AclRegistryImpl : public AclRegistry class ACLRegistryImpl : public ACLRegistry
{ {
Q_OBJECT Q_OBJECT
public: public:
AclRegistryImpl( QObject *parent = 0 ); ACLRegistryImpl( QObject *parent = 0 );
virtual ~AclRegistryImpl(); virtual ~ACLRegistryImpl();
signals: signals:
void aclResult( QString nodeid, QString username, AclRegistry::ACL peerStatus ); void aclResult( QString nodeid, QString username, ACLRegistry::ACL peerStatus );
public slots: public slots:
/** /**
* @brief Checks if peer is authorized; optionally, can authorize peer with given type if not found * @brief Checks if peer is authorized; optionally, can authorize peer with given type if not found
* *
* @param dbid DBID of peer * @param dbid DBID of peer
* @param globalType Global ACL to store if peer not found; if AclRegistry::NotFound, does not store the peer Defaults to AclRegistry::NotFound. * @param globalType Global ACL to store if peer not found; if ACLRegistry::NotFound, does not store the peer Defaults to ACLRegistry::NotFound.
* @param username If not empty, will store the given username along with the new ACL value. Defaults to QString(). * @param username If not empty, will store the given username along with the new ACL value. Defaults to QString().
* @return AclRegistry::ACL * @return ACLRegistry::ACL
**/ **/
virtual AclRegistry::ACL isAuthorizedUser( const QString &dbid, const QString &username, AclRegistry::ACL globalType = AclRegistry::NotFound, bool skipEmission = false ); virtual ACLRegistry::ACL isAuthorizedUser( const QString &dbid, const QString &username, ACLRegistry::ACL globalType = ACLRegistry::NotFound, bool skipEmission = false );
#ifndef ENABLE_HEADLESS
void getUserDecision( AclRegistry::User user, const QString &username );
virtual void wipeEntries(); virtual void wipeEntries();
protected:
virtual void load();
virtual void save();
#ifndef ENABLE_HEADLESS
void getUserDecision( ACLRegistry::User user, const QString &username );
private slots: private slots:
void userDecision( AclRegistry::User user ); void userDecision( ACLRegistry::User user );
void queueNextJob(); void queueNextJob();
#endif #endif
private: private:
QQueue< AclJobItem* > m_jobQueue; QQueue< ACLJobItem* > m_jobQueue;
int m_jobCount; int m_jobCount;
}; };

View File

@@ -510,7 +510,7 @@ SettingsDialog::aclEntryClearButtonClicked()
); );
if ( button == QMessageBox::Ok ) if ( button == QMessageBox::Ok )
{ {
AclRegistry::instance()->wipeEntries(); ACLRegistry::instance()->wipeEntries();
ui->aclEntryClearButton->setEnabled( false ); ui->aclEntryClearButton->setEnabled( false );
} }
} }

View File

@@ -205,7 +205,7 @@ TomahawkApp::init()
TomahawkSettings* s = TomahawkSettings::instance(); TomahawkSettings* s = TomahawkSettings::instance();
AclRegistryImpl* ari = new AclRegistryImpl( this ); new ACLRegistryImpl( this );
tDebug( LOGINFO ) << "Setting NAM."; tDebug( LOGINFO ) << "Setting NAM.";
// Cause the creation of the nam, but don't need to address it directly, so prevent warning // Cause the creation of the nam, but don't need to address it directly, so prevent warning
@@ -370,6 +370,9 @@ TomahawkApp::~TomahawkApp()
if ( !m_servent.isNull() ) if ( !m_servent.isNull() )
delete m_servent.data(); delete m_servent.data();
delete dynamic_cast< ACLRegistryImpl* >( ACLRegistry::instance() );
if ( !m_scanManager.isNull() ) if ( !m_scanManager.isNull() )
delete m_scanManager.data(); delete m_scanManager.data();

View File

@@ -22,14 +22,10 @@
#include <QThread> #include <QThread>
#include <QVariant> #include <QVariant>
#include "TomahawkSettings.h"
#include "TomahawkApp.h"
#include "Source.h"
#include "utils/Logger.h" #include "utils/Logger.h"
QDataStream& operator<<( QDataStream &out, const AclRegistry::User &user ) QDataStream& operator<<( QDataStream &out, const ACLRegistry::User &user )
{ {
out << ACLUSERVERSION; out << ACLUSERVERSION;
out << user.uuid; out << user.uuid;
@@ -44,7 +40,7 @@ QDataStream& operator<<( QDataStream &out, const AclRegistry::User &user )
return out; return out;
} }
QDataStream& operator>>( QDataStream &in, AclRegistry::User &user ) QDataStream& operator>>( QDataStream &in, ACLRegistry::User &user )
{ {
int ver; int ver;
in >> ver; in >> ver;
@@ -70,84 +66,56 @@ QDataStream& operator>>( QDataStream &in, AclRegistry::User &user )
} }
int aclIn; int aclIn;
in >> aclIn; in >> aclIn;
user.acl = (AclRegistry::ACL)( aclIn ); user.acl = (ACLRegistry::ACL)( aclIn );
} }
return in; return in;
} }
AclRegistry* AclRegistry::s_instance = 0; ACLRegistry* ACLRegistry::s_instance = 0;
AclRegistry* ACLRegistry*
AclRegistry::instance() ACLRegistry::instance()
{ {
return s_instance; return s_instance;
} }
void void
AclRegistry::setInstance( AclRegistry* instance ) ACLRegistry::setInstance( ACLRegistry* instance )
{ {
s_instance = instance; s_instance = instance;
} }
AclRegistry::AclRegistry( QObject* parent ) ACLRegistry::ACLRegistry( QObject* parent )
: QObject( parent ) : QObject( parent )
{ {
qRegisterMetaType< AclRegistry::ACL >( "AclRegistry::ACL" ); qRegisterMetaType< ACLRegistry::ACL >( "ACLRegistry::ACL" );
qRegisterMetaType< AclRegistry::User >( "AclRegistry::User" ); qRegisterMetaType< ACLRegistry::User >( "ACLRegistry::User" );
qRegisterMetaTypeStreamOperators< AclRegistry::User >( "AclRegistry::User" ); qRegisterMetaTypeStreamOperators< ACLRegistry::User >( "ACLRegistry::User" );
} }
AclRegistry::~AclRegistry() ACLRegistry::~ACLRegistry()
{ {
} }
void void
AclRegistry::load() ACLRegistry::load()
{ {
tLog() << Q_FUNC_INFO;
QVariantList entryList = TomahawkSettings::instance()->aclEntries();
foreach ( QVariant entry, entryList )
{
if ( !entry.isValid() || !entry.canConvert< AclRegistry::User >() )
{
tLog() << Q_FUNC_INFO << "entry is invalid";
continue;
}
tLog() << Q_FUNC_INFO << "loading entry";
AclRegistry::User entryUser = entry.value< AclRegistry::User >();
if ( entryUser.knownAccountIds.empty() || entryUser.knownDbids.empty() )
{
tLog() << Q_FUNC_INFO << "user known account/dbids is empty";
continue;
}
m_cache.append( entryUser );
}
} }
void void
AclRegistry::save() ACLRegistry::save()
{ {
tLog() << Q_FUNC_INFO;
QVariantList entryList;
foreach ( AclRegistry::User user, m_cache )
{
tLog() << Q_FUNC_INFO << "user is " << user.uuid << " with known name " << user.knownAccountIds.first();
QVariant val = QVariant::fromValue< AclRegistry::User >( user );
if ( val.isValid() )
entryList.append( val );
}
TomahawkSettings::instance()->setAclEntries( entryList );
} }
void void
AclRegistry::wipeEntries() ACLRegistry::wipeEntries()
{ {
tLog() << Q_FUNC_INFO; tLog() << Q_FUNC_INFO;
m_cache.clear(); m_cache.clear();

View File

@@ -35,14 +35,14 @@
#define ACLUSERVERSION 1 #define ACLUSERVERSION 1
class DLLEXPORT AclRegistry : public QObject class DLLEXPORT ACLRegistry : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
static AclRegistry* instance(); static ACLRegistry* instance();
static void setInstance( AclRegistry* instance ); static void setInstance( ACLRegistry* instance );
enum ACL { enum ACL {
NotFound = 0, NotFound = 0,
@@ -56,20 +56,20 @@ public:
QString friendlyName; QString friendlyName;
QStringList knownDbids; QStringList knownDbids;
QStringList knownAccountIds; QStringList knownAccountIds;
AclRegistry::ACL acl; ACLRegistry::ACL acl;
User() User()
: uuid( QUuid::createUuid().toString() ) : uuid( QUuid::createUuid().toString() )
, friendlyName() , friendlyName()
, knownDbids() , knownDbids()
, knownAccountIds() , knownAccountIds()
, acl( AclRegistry::NotFound ) , acl( ACLRegistry::NotFound )
{} {}
~User() ~User()
{} {}
User( QString p_uuid, QString p_friendlyName, QStringList p_knownDbids, QStringList p_knownAccountIds, AclRegistry::ACL p_acl ) User( QString p_uuid, QString p_friendlyName, QStringList p_knownDbids, QStringList p_knownAccountIds, ACLRegistry::ACL p_acl )
: uuid( p_uuid ) : uuid( p_uuid )
, friendlyName( p_friendlyName ) , friendlyName( p_friendlyName )
, knownDbids( p_knownDbids ) , knownDbids( p_knownDbids )
@@ -86,22 +86,22 @@ public:
{} {}
}; };
AclRegistry( QObject *parent = 0 ); ACLRegistry( QObject *parent = 0 );
virtual ~AclRegistry(); virtual ~ACLRegistry();
signals: signals:
void aclResult( QString nodeid, QString username, AclRegistry::ACL peerStatus ); void aclResult( QString nodeid, QString username, ACLRegistry::ACL peerStatus );
public slots: public slots:
/** /**
* @brief Checks if peer is authorized; optionally, can authorize peer with given type if not found * @brief Checks if peer is authorized; optionally, can authorize peer with given type if not found
* *
* @param dbid DBID of peer * @param dbid DBID of peer
* @param globalType Global ACL to store if peer not found; if AclRegistry::NotFound, does not store the peer Defaults to AclRegistry::NotFound. * @param globalType Global ACL to store if peer not found; if ACLRegistry::NotFound, does not store the peer Defaults to ACLRegistry::NotFound.
* @param username If not empty, will store the given username along with the new ACL value. Defaults to QString(). * @param username If not empty, will store the given username along with the new ACL value. Defaults to QString().
* @return AclRegistry::ACL * @return ACLRegistry::ACL
**/ **/
virtual AclRegistry::ACL isAuthorizedUser( const QString &dbid, const QString &username, AclRegistry::ACL globalType = AclRegistry::NotFound, bool skipEmission = false ) = 0; virtual ACLRegistry::ACL isAuthorizedUser( const QString &dbid, const QString &username, ACLRegistry::ACL globalType = ACLRegistry::NotFound, bool skipEmission = false ) = 0;
virtual void wipeEntries(); virtual void wipeEntries();
protected: protected:
@@ -113,12 +113,12 @@ protected:
virtual void save(); virtual void save();
virtual void load(); virtual void load();
QList< AclRegistry::User > m_cache; QList< ACLRegistry::User > m_cache;
static AclRegistry* s_instance; static ACLRegistry* s_instance;
}; };
Q_DECLARE_METATYPE( AclRegistry::ACL ); Q_DECLARE_METATYPE( ACLRegistry::ACL );
Q_DECLARE_METATYPE( AclRegistry::User ); Q_DECLARE_METATYPE( ACLRegistry::User );
#endif // TOMAHAWK_ACLREGISTRY_H #endif // TOMAHAWK_ACLREGISTRY_H

View File

@@ -37,23 +37,23 @@
#define PADDING 2 #define PADDING 2
AclJobDelegate::AclJobDelegate( QObject* parent ) ACLJobDelegate::ACLJobDelegate( QObject* parent )
: QStyledItemDelegate ( parent ) : QStyledItemDelegate ( parent )
{ {
tLog() << Q_FUNC_INFO; tLog() << Q_FUNC_INFO;
} }
AclJobDelegate::~AclJobDelegate() ACLJobDelegate::~ACLJobDelegate()
{ {
tLog() << Q_FUNC_INFO; tLog() << Q_FUNC_INFO;
} }
void void
AclJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const ACLJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{ {
AclJobItem* item = dynamic_cast< AclJobItem* >( index.data( JobStatusModel::JobDataRole ).value< JobStatusItem* >() ); ACLJobItem* item = dynamic_cast< ACLJobItem* >( index.data( JobStatusModel::JobDataRole ).value< JobStatusItem* >() );
if ( !item ) if ( !item )
return; return;
//tDebug( LOGVERBOSE ) << Q_FUNC_INFO; //tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
@@ -106,7 +106,7 @@ AclJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
} }
QSize QSize
AclJobDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const ACLJobDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
{ {
QSize size( QStyledItemDelegate::sizeHint ( option, index ).width(), ROW_HEIGHT * 3 ); QSize size( QStyledItemDelegate::sizeHint ( option, index ).width(), ROW_HEIGHT * 3 );
return size; return size;
@@ -114,7 +114,7 @@ AclJobDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex&
void void
AclJobDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect, bool red ) const ACLJobDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect, bool red ) const
{ {
if ( !red ) if ( !red )
TomahawkUtils::drawRoundedButton( painter, btnRect, QColor(54, 127, 211), QColor(43, 104, 182), QColor(34, 85, 159), QColor(35, 79, 147) ); TomahawkUtils::drawRoundedButton( painter, btnRect, QColor(54, 127, 211), QColor(43, 104, 182), QColor(34, 85, 159), QColor(35, 79, 147) );
@@ -124,7 +124,7 @@ AclJobDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect, bool
bool bool
AclJobDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index ) ACLJobDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
{ {
Q_UNUSED( option ) Q_UNUSED( option )
Q_UNUSED( model ) Q_UNUSED( model )
@@ -148,9 +148,9 @@ AclJobDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QSt
{ {
QMouseEvent* me = static_cast< QMouseEvent* >( event ); QMouseEvent* me = static_cast< QMouseEvent* >( event );
if ( m_savedAcceptRect.contains( me->pos() ) ) if ( m_savedAcceptRect.contains( me->pos() ) )
emit aclResult( AclRegistry::Stream ); emit aclResult( ACLRegistry::Stream );
else if ( m_savedDenyRect.contains( me->pos() ) ) else if ( m_savedDenyRect.contains( me->pos() ) )
emit aclResult( AclRegistry::Deny ); emit aclResult( ACLRegistry::Deny );
return true; return true;
} }
@@ -159,7 +159,7 @@ AclJobDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QSt
AclJobItem::AclJobItem( AclRegistry::User user, const QString &username ) ACLJobItem::ACLJobItem( ACLRegistry::User user, const QString &username )
: m_delegate( 0 ) : m_delegate( 0 )
, m_user( user ) , m_user( user )
, m_username( username ) , m_username( username )
@@ -168,36 +168,36 @@ AclJobItem::AclJobItem( AclRegistry::User user, const QString &username )
} }
AclJobItem::~AclJobItem() ACLJobItem::~ACLJobItem()
{ {
tLog() << Q_FUNC_INFO; tLog() << Q_FUNC_INFO;
} }
void void
AclJobItem::createDelegate( QObject* parent ) ACLJobItem::createDelegate( QObject* parent )
{ {
tLog() << Q_FUNC_INFO; tLog() << Q_FUNC_INFO;
if ( m_delegate ) if ( m_delegate )
return; return;
m_delegate = new AclJobDelegate( parent ); m_delegate = new ACLJobDelegate( parent );
Tomahawk::InfoSystem::InfoPushData pushData( "AclJobItem", Tomahawk::InfoSystem::InfoNotifyUser, tr( "Tomahawk needs you to decide whether %1 is allowed to connect." ).arg( m_username ), Tomahawk::InfoSystem::PushNoFlag ); Tomahawk::InfoSystem::InfoPushData pushData( "ACLJobItem", Tomahawk::InfoSystem::InfoNotifyUser, tr( "Tomahawk needs you to decide whether %1 is allowed to connect." ).arg( m_username ), Tomahawk::InfoSystem::PushNoFlag );
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( pushData ); Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( pushData );
} }
void void
AclJobDelegate::emitSizeHintChanged( const QModelIndex& index ) ACLJobDelegate::emitSizeHintChanged( const QModelIndex& index )
{ {
emit sizeHintChanged( index ); emit sizeHintChanged( index );
} }
void void
AclJobItem::aclResult( AclRegistry::ACL result ) ACLJobItem::aclResult( ACLRegistry::ACL result )
{ {
tLog() << Q_FUNC_INFO; tLog() << Q_FUNC_INFO;
m_user.acl = result; m_user.acl = result;

View File

@@ -28,13 +28,13 @@
class QListView; class QListView;
class DLLEXPORT AclJobDelegate : public QStyledItemDelegate class DLLEXPORT ACLJobDelegate : public QStyledItemDelegate
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AclJobDelegate ( QObject* parent = 0 ); explicit ACLJobDelegate ( QObject* parent = 0 );
virtual ~AclJobDelegate(); virtual ~ACLJobDelegate();
virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
@@ -43,7 +43,7 @@ public:
signals: signals:
void update( const QModelIndex& idx ); void update( const QModelIndex& idx );
void aclResult( AclRegistry::ACL result ); void aclResult( ACLRegistry::ACL result );
protected: protected:
virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index ); virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
@@ -57,12 +57,12 @@ private:
}; };
class DLLEXPORT AclJobItem : public JobStatusItem class DLLEXPORT ACLJobItem : public JobStatusItem
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AclJobItem( AclRegistry::User user, const QString &username ); explicit ACLJobItem( ACLRegistry::User user, const QString &username );
virtual ~AclJobItem(); virtual ~ACLJobItem();
virtual QString rightColumnText() const { return QString(); } virtual QString rightColumnText() const { return QString(); }
virtual QString mainText() const { return QString(); } virtual QString mainText() const { return QString(); }
@@ -75,18 +75,18 @@ public:
virtual void createDelegate( QObject* parent = 0 ); virtual void createDelegate( QObject* parent = 0 );
virtual QStyledItemDelegate* customDelegate() const { return m_delegate; } virtual QStyledItemDelegate* customDelegate() const { return m_delegate; }
virtual AclRegistry::User user() const { return m_user; } virtual ACLRegistry::User user() const { return m_user; }
virtual const QString& username() const { return m_username; } virtual const QString& username() const { return m_username; }
signals: signals:
void userDecision( AclRegistry::User user ); void userDecision( ACLRegistry::User user );
public slots: public slots:
void aclResult( AclRegistry::ACL result ); void aclResult( ACLRegistry::ACL result );
private: private:
QStyledItemDelegate* m_delegate; QStyledItemDelegate* m_delegate;
AclRegistry::User m_user; ACLRegistry::User m_user;
const QString m_username; const QString m_username;
}; };

View File

@@ -108,12 +108,12 @@ JobStatusView::customDelegateJobInserted( int row, JobStatusItem* item )
item->createDelegate( m_view ); item->createDelegate( m_view );
tLog() << Q_FUNC_INFO << "item delegate is" << item->customDelegate(); tLog() << Q_FUNC_INFO << "item delegate is" << item->customDelegate();
m_view->setItemDelegateForRow( row, item->customDelegate() ); m_view->setItemDelegateForRow( row, item->customDelegate() );
AclJobDelegate* delegate = qobject_cast< AclJobDelegate* >( item->customDelegate() ); ACLJobDelegate* delegate = qobject_cast< ACLJobDelegate* >( item->customDelegate() );
if ( delegate ) if ( delegate )
{ {
tLog() << Q_FUNC_INFO << "delegate found"; tLog() << Q_FUNC_INFO << "delegate found";
connect( delegate, SIGNAL( update( const QModelIndex& ) ), m_view, SLOT( update( const QModelIndex & ) ) ); connect( delegate, SIGNAL( update( const QModelIndex& ) ), m_view, SLOT( update( const QModelIndex & ) ) );
connect( delegate, SIGNAL( aclResult( AclRegistry::ACL ) ), item, SLOT( aclResult( AclRegistry::ACL ) ) ); connect( delegate, SIGNAL( aclResult( ACLRegistry::ACL ) ), item, SLOT( aclResult( ACLRegistry::ACL ) ) );
delegate->emitSizeHintChanged( m_model->index( row ) ); delegate->emitSizeHintChanged( m_model->index( row ) );
} }
else else

View File

@@ -208,13 +208,13 @@ Connection::checkACL()
QString nodeid = property( "nodeid" ).toString(); QString nodeid = property( "nodeid" ).toString();
QString bareName = name().contains( '/' ) ? name().left( name().indexOf( "/" ) ) : name(); QString bareName = name().contains( '/' ) ? name().left( name().indexOf( "/" ) ) : name();
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Checking ACL for" << name(); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Checking ACL for" << name();
connect( AclRegistry::instance(), SIGNAL( aclResult( QString, QString, AclRegistry::ACL ) ), this, SLOT( checkACLResult( QString, QString, AclRegistry::ACL ) ), Qt::QueuedConnection ); connect( ACLRegistry::instance(), SIGNAL( aclResult( QString, QString, ACLRegistry::ACL ) ), this, SLOT( checkACLResult( QString, QString, ACLRegistry::ACL ) ), Qt::QueuedConnection );
QMetaObject::invokeMethod( AclRegistry::instance(), "isAuthorizedUser", Qt::QueuedConnection, Q_ARG( QString, nodeid ), Q_ARG( QString, bareName ), Q_ARG( AclRegistry::ACL, AclRegistry::NotFound ) ); QMetaObject::invokeMethod( ACLRegistry::instance(), "isAuthorizedUser", Qt::QueuedConnection, Q_ARG( QString, nodeid ), Q_ARG( QString, bareName ), Q_ARG( ACLRegistry::ACL, ACLRegistry::NotFound ) );
} }
void void
Connection::checkACLResult( const QString &nodeid, const QString &username, AclRegistry::ACL peerStatus ) Connection::checkACLResult( const QString &nodeid, const QString &username, ACLRegistry::ACL peerStatus )
{ {
QString bareName = name().contains( '/' ) ? name().left( name().indexOf( "/" ) ) : name(); QString bareName = name().contains( '/' ) ? name().left( name().indexOf( "/" ) ) : name();
if ( nodeid != property( "nodeid" ).toString() || username != bareName ) if ( nodeid != property( "nodeid" ).toString() || username != bareName )
@@ -223,9 +223,9 @@ Connection::checkACLResult( const QString &nodeid, const QString &username, AclR
return; return;
} }
disconnect( AclRegistry::instance(), SIGNAL( aclResult( QString, QString, AclRegistry::ACL ) ) ); disconnect( ACLRegistry::instance(), SIGNAL( aclResult( QString, QString, ACLRegistry::ACL ) ) );
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "ACL status is" << peerStatus; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "ACL status is" << peerStatus;
if ( peerStatus == AclRegistry::Stream ) if ( peerStatus == ACLRegistry::Stream )
{ {
QTimer::singleShot( 0, this, SLOT( doSetup() ) ); QTimer::singleShot( 0, this, SLOT( doSetup() ) );
return; return;

View File

@@ -120,7 +120,7 @@ private slots:
void readyRead(); void readyRead();
void doSetup(); void doSetup();
void checkACL(); void checkACL();
void checkACLResult( const QString &nodeid, const QString &username, AclRegistry::ACL peerStatus ); void checkACLResult( const QString &nodeid, const QString &username, ACLRegistry::ACL peerStatus );
void authCheckTimeout(); void authCheckTimeout();
void bytesWritten( qint64 ); void bytesWritten( qint64 );
void calcStats(); void calcStats();

View File

@@ -65,7 +65,6 @@ Servent::Servent( QObject* parent )
s_instance = this; s_instance = this;
m_lanHack = qApp->arguments().contains( "--lanhack" ); m_lanHack = qApp->arguments().contains( "--lanhack" );
AclRegistry::instance();
setProxy( QNetworkProxy::NoProxy ); setProxy( QNetworkProxy::NoProxy );
{ {
@@ -90,7 +89,6 @@ Servent::Servent( QObject* parent )
Servent::~Servent() Servent::~Servent()
{ {
delete AclRegistry::instance();
delete m_portfwd; delete m_portfwd;
} }