mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-23 01:09:42 +01:00
Some more acl cleanup, and put Acl->ACL so we don't mess up peoples' existing configs
This commit is contained in:
parent
5547a9741d
commit
67e18c3b9d
@ -37,30 +37,30 @@
|
||||
#include "utils/Logger.h"
|
||||
|
||||
|
||||
AclRegistryImpl::AclRegistryImpl( QObject* parent )
|
||||
: AclRegistry( parent )
|
||||
ACLRegistryImpl::ACLRegistryImpl( QObject* parent )
|
||||
: ACLRegistry( parent )
|
||||
, m_jobCount( 0 )
|
||||
{
|
||||
AclRegistry::setInstance( this );
|
||||
ACLRegistry::setInstance( this );
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
AclRegistryImpl::~AclRegistryImpl()
|
||||
ACLRegistryImpl::~ACLRegistryImpl()
|
||||
{
|
||||
save();
|
||||
}
|
||||
|
||||
|
||||
AclRegistry::ACL
|
||||
AclRegistryImpl::isAuthorizedUser( const QString& dbid, const QString &username, AclRegistry::ACL globalType, bool skipEmission )
|
||||
ACLRegistry::ACL
|
||||
ACLRegistryImpl::isAuthorizedUser( const QString& dbid, const QString &username, ACLRegistry::ACL globalType, bool skipEmission )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO;
|
||||
if ( QThread::currentThread() != TOMAHAWK_APPLICATION::instance()->thread() )
|
||||
{
|
||||
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 ) );
|
||||
return AclRegistry::NotFound;
|
||||
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;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
@ -77,18 +77,18 @@ AclRegistryImpl::isAuthorizedUser( const QString& dbid, const QString &username,
|
||||
if ( account->accountFriendlyName() == username )
|
||||
{
|
||||
if ( !skipEmission )
|
||||
emit aclResult( dbid, username, AclRegistry::Stream );
|
||||
return AclRegistry::Stream;
|
||||
emit aclResult( dbid, username, ACLRegistry::Stream );
|
||||
return ACLRegistry::Stream;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool found = false;
|
||||
QMutableListIterator< AclRegistry::User > i( m_cache );
|
||||
QMutableListIterator< ACLRegistry::User > i( m_cache );
|
||||
while ( i.hasNext() )
|
||||
{
|
||||
AclRegistry::User user = i.next();
|
||||
ACLRegistry::User user = i.next();
|
||||
foreach ( QString knowndbid, user.knownDbids )
|
||||
{
|
||||
if ( dbid == knowndbid )
|
||||
@ -119,24 +119,24 @@ AclRegistryImpl::isAuthorizedUser( const QString& dbid, const QString &username,
|
||||
}
|
||||
|
||||
if ( skipEmission )
|
||||
return AclRegistry::NotFound;
|
||||
return ACLRegistry::NotFound;
|
||||
|
||||
// User was not found, create a new user entry
|
||||
AclRegistry::User user;
|
||||
ACLRegistry::User user;
|
||||
user.knownDbids.append( dbid );
|
||||
user.knownAccountIds.append( username );
|
||||
if ( globalType != AclRegistry::NotFound )
|
||||
if ( globalType != ACLRegistry::NotFound )
|
||||
user.acl = globalType;
|
||||
#ifdef ENABLE_HEADLESS
|
||||
user.acl = AclRegistry::Stream;
|
||||
user.acl = ACLRegistry::Stream;
|
||||
#else
|
||||
if ( !TomahawkUtils::headless() )
|
||||
{
|
||||
getUserDecision( user, username );
|
||||
return AclRegistry::NotFound;
|
||||
return ACLRegistry::NotFound;
|
||||
}
|
||||
else
|
||||
user.acl = AclRegistry::Stream;
|
||||
user.acl = ACLRegistry::Stream;
|
||||
#endif
|
||||
m_cache.append( user );
|
||||
save();
|
||||
@ -147,20 +147,20 @@ AclRegistryImpl::isAuthorizedUser( const QString& dbid, const QString &username,
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
void
|
||||
AclRegistryImpl::getUserDecision( AclRegistry::User user, const QString &username )
|
||||
ACLRegistryImpl::getUserDecision( ACLRegistry::User user, const QString &username )
|
||||
{
|
||||
if ( TomahawkUtils::headless() )
|
||||
return;
|
||||
|
||||
tLog() << Q_FUNC_INFO;
|
||||
AclJobItem* job = new AclJobItem( user, username );
|
||||
ACLJobItem* job = new ACLJobItem( user, username );
|
||||
m_jobQueue.enqueue( job );
|
||||
QTimer::singleShot( 0, this, SLOT( queueNextJob() ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AclRegistryImpl::userDecision( AclRegistry::User user )
|
||||
ACLRegistryImpl::userDecision( ACLRegistry::User user )
|
||||
{
|
||||
if ( TomahawkUtils::headless() )
|
||||
return;
|
||||
@ -177,7 +177,7 @@ AclRegistryImpl::userDecision( AclRegistry::User user )
|
||||
|
||||
|
||||
void
|
||||
AclRegistryImpl::queueNextJob()
|
||||
ACLRegistryImpl::queueNextJob()
|
||||
{
|
||||
if ( TomahawkUtils::headless() )
|
||||
return;
|
||||
@ -194,13 +194,13 @@ AclRegistryImpl::queueNextJob()
|
||||
|
||||
if ( !m_jobQueue.isEmpty() )
|
||||
{
|
||||
AclJobItem* job = m_jobQueue.dequeue();
|
||||
AclRegistry::User user = job->user();
|
||||
ACLJobItem* job = m_jobQueue.dequeue();
|
||||
ACLRegistry::User user = job->user();
|
||||
bool found = false;
|
||||
foreach( QString dbid, user.knownDbids )
|
||||
{
|
||||
AclRegistry::ACL acl = isAuthorizedUser( dbid, job->username(), AclRegistry::NotFound, true );
|
||||
if ( acl != AclRegistry::NotFound )
|
||||
ACLRegistry::ACL acl = isAuthorizedUser( dbid, job->username(), ACLRegistry::NotFound, true );
|
||||
if ( acl != ACLRegistry::NotFound )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO << "Found existing acl entry for = " << user.knownAccountIds.first();
|
||||
found = true;
|
||||
@ -219,15 +219,54 @@ AclRegistryImpl::queueNextJob()
|
||||
tLog() << Q_FUNC_INFO << "activating job for user" << user.knownAccountIds.first();
|
||||
m_jobCount++;
|
||||
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
|
||||
|
||||
void
|
||||
AclRegistryImpl::wipeEntries()
|
||||
ACLRegistryImpl::wipeEntries()
|
||||
{
|
||||
AclRegistry::wipeEntries();
|
||||
ACLRegistry::wipeEntries();
|
||||
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 );
|
||||
}
|
||||
|
@ -34,43 +34,46 @@
|
||||
#include "HeadlessCheck.h"
|
||||
#include "DllMacro.h"
|
||||
|
||||
class AclJobItem;
|
||||
class ACLJobItem;
|
||||
|
||||
class AclRegistryImpl : public AclRegistry
|
||||
class ACLRegistryImpl : public ACLRegistry
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
AclRegistryImpl( QObject *parent = 0 );
|
||||
virtual ~AclRegistryImpl();
|
||||
ACLRegistryImpl( QObject *parent = 0 );
|
||||
virtual ~ACLRegistryImpl();
|
||||
|
||||
signals:
|
||||
void aclResult( QString nodeid, QString username, AclRegistry::ACL peerStatus );
|
||||
void aclResult( QString nodeid, QString username, ACLRegistry::ACL peerStatus );
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief Checks if peer is authorized; optionally, can authorize peer with given type if not found
|
||||
*
|
||||
* @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().
|
||||
* @return AclRegistry::ACL
|
||||
* @return ACLRegistry::ACL
|
||||
**/
|
||||
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 ACLRegistry::ACL isAuthorizedUser( const QString &dbid, const QString &username, ACLRegistry::ACL globalType = ACLRegistry::NotFound, bool skipEmission = false );
|
||||
virtual void wipeEntries();
|
||||
|
||||
protected:
|
||||
virtual void load();
|
||||
virtual void save();
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
void getUserDecision( ACLRegistry::User user, const QString &username );
|
||||
|
||||
private slots:
|
||||
void userDecision( AclRegistry::User user );
|
||||
void userDecision( ACLRegistry::User user );
|
||||
void queueNextJob();
|
||||
#endif
|
||||
|
||||
private:
|
||||
QQueue< AclJobItem* > m_jobQueue;
|
||||
QQueue< ACLJobItem* > m_jobQueue;
|
||||
int m_jobCount;
|
||||
};
|
||||
|
||||
|
@ -510,7 +510,7 @@ SettingsDialog::aclEntryClearButtonClicked()
|
||||
);
|
||||
if ( button == QMessageBox::Ok )
|
||||
{
|
||||
AclRegistry::instance()->wipeEntries();
|
||||
ACLRegistry::instance()->wipeEntries();
|
||||
ui->aclEntryClearButton->setEnabled( false );
|
||||
}
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ TomahawkApp::init()
|
||||
|
||||
TomahawkSettings* s = TomahawkSettings::instance();
|
||||
|
||||
AclRegistryImpl* ari = new AclRegistryImpl( this );
|
||||
new ACLRegistryImpl( this );
|
||||
|
||||
tDebug( LOGINFO ) << "Setting NAM.";
|
||||
// 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() )
|
||||
delete m_servent.data();
|
||||
|
||||
delete dynamic_cast< ACLRegistryImpl* >( ACLRegistry::instance() );
|
||||
|
||||
if ( !m_scanManager.isNull() )
|
||||
delete m_scanManager.data();
|
||||
|
||||
|
@ -22,14 +22,10 @@
|
||||
#include <QThread>
|
||||
#include <QVariant>
|
||||
|
||||
#include "TomahawkSettings.h"
|
||||
#include "TomahawkApp.h"
|
||||
#include "Source.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
|
||||
QDataStream& operator<<( QDataStream &out, const AclRegistry::User &user )
|
||||
QDataStream& operator<<( QDataStream &out, const ACLRegistry::User &user )
|
||||
{
|
||||
out << ACLUSERVERSION;
|
||||
out << user.uuid;
|
||||
@ -44,7 +40,7 @@ QDataStream& operator<<( QDataStream &out, const AclRegistry::User &user )
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream& operator>>( QDataStream &in, AclRegistry::User &user )
|
||||
QDataStream& operator>>( QDataStream &in, ACLRegistry::User &user )
|
||||
{
|
||||
int ver;
|
||||
in >> ver;
|
||||
@ -70,84 +66,56 @@ QDataStream& operator>>( QDataStream &in, AclRegistry::User &user )
|
||||
}
|
||||
int aclIn;
|
||||
in >> aclIn;
|
||||
user.acl = (AclRegistry::ACL)( aclIn );
|
||||
user.acl = (ACLRegistry::ACL)( aclIn );
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
AclRegistry* AclRegistry::s_instance = 0;
|
||||
ACLRegistry* ACLRegistry::s_instance = 0;
|
||||
|
||||
AclRegistry*
|
||||
AclRegistry::instance()
|
||||
ACLRegistry*
|
||||
ACLRegistry::instance()
|
||||
{
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AclRegistry::setInstance( AclRegistry* instance )
|
||||
ACLRegistry::setInstance( ACLRegistry* instance )
|
||||
{
|
||||
s_instance = instance;
|
||||
}
|
||||
|
||||
|
||||
AclRegistry::AclRegistry( QObject* parent )
|
||||
ACLRegistry::ACLRegistry( QObject* parent )
|
||||
: QObject( parent )
|
||||
{
|
||||
qRegisterMetaType< AclRegistry::ACL >( "AclRegistry::ACL" );
|
||||
qRegisterMetaType< AclRegistry::User >( "AclRegistry::User" );
|
||||
qRegisterMetaTypeStreamOperators< AclRegistry::User >( "AclRegistry::User" );
|
||||
qRegisterMetaType< ACLRegistry::ACL >( "ACLRegistry::ACL" );
|
||||
qRegisterMetaType< ACLRegistry::User >( "ACLRegistry::User" );
|
||||
qRegisterMetaTypeStreamOperators< ACLRegistry::User >( "ACLRegistry::User" );
|
||||
}
|
||||
|
||||
|
||||
AclRegistry::~AclRegistry()
|
||||
ACLRegistry::~ACLRegistry()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
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
|
||||
AclRegistry::wipeEntries()
|
||||
ACLRegistry::wipeEntries()
|
||||
{
|
||||
tLog() << Q_FUNC_INFO;
|
||||
m_cache.clear();
|
||||
|
@ -35,14 +35,14 @@
|
||||
|
||||
#define ACLUSERVERSION 1
|
||||
|
||||
class DLLEXPORT AclRegistry : public QObject
|
||||
class DLLEXPORT ACLRegistry : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
static AclRegistry* instance();
|
||||
static void setInstance( AclRegistry* instance );
|
||||
static ACLRegistry* instance();
|
||||
static void setInstance( ACLRegistry* instance );
|
||||
|
||||
enum ACL {
|
||||
NotFound = 0,
|
||||
@ -56,20 +56,20 @@ public:
|
||||
QString friendlyName;
|
||||
QStringList knownDbids;
|
||||
QStringList knownAccountIds;
|
||||
AclRegistry::ACL acl;
|
||||
ACLRegistry::ACL acl;
|
||||
|
||||
User()
|
||||
: uuid( QUuid::createUuid().toString() )
|
||||
, friendlyName()
|
||||
, knownDbids()
|
||||
, knownAccountIds()
|
||||
, acl( AclRegistry::NotFound )
|
||||
, acl( ACLRegistry::NotFound )
|
||||
{}
|
||||
|
||||
~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 )
|
||||
, friendlyName( p_friendlyName )
|
||||
, knownDbids( p_knownDbids )
|
||||
@ -86,22 +86,22 @@ public:
|
||||
{}
|
||||
};
|
||||
|
||||
AclRegistry( QObject *parent = 0 );
|
||||
virtual ~AclRegistry();
|
||||
ACLRegistry( QObject *parent = 0 );
|
||||
virtual ~ACLRegistry();
|
||||
|
||||
signals:
|
||||
void aclResult( QString nodeid, QString username, AclRegistry::ACL peerStatus );
|
||||
void aclResult( QString nodeid, QString username, ACLRegistry::ACL peerStatus );
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief Checks if peer is authorized; optionally, can authorize peer with given type if not found
|
||||
*
|
||||
* @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().
|
||||
* @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();
|
||||
|
||||
protected:
|
||||
@ -113,12 +113,12 @@ protected:
|
||||
virtual void save();
|
||||
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::User );
|
||||
Q_DECLARE_METATYPE( ACLRegistry::ACL );
|
||||
Q_DECLARE_METATYPE( ACLRegistry::User );
|
||||
|
||||
#endif // TOMAHAWK_ACLREGISTRY_H
|
||||
|
@ -37,23 +37,23 @@
|
||||
#define PADDING 2
|
||||
|
||||
|
||||
AclJobDelegate::AclJobDelegate( QObject* parent )
|
||||
ACLJobDelegate::ACLJobDelegate( QObject* parent )
|
||||
: QStyledItemDelegate ( parent )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
|
||||
AclJobDelegate::~AclJobDelegate()
|
||||
ACLJobDelegate::~ACLJobDelegate()
|
||||
{
|
||||
tLog() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
|
||||
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 )
|
||||
return;
|
||||
//tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
|
||||
@ -106,7 +106,7 @@ AclJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
||||
}
|
||||
|
||||
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 );
|
||||
return size;
|
||||
@ -114,7 +114,7 @@ AclJobDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex&
|
||||
|
||||
|
||||
void
|
||||
AclJobDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect, bool red ) const
|
||||
ACLJobDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect, bool red ) const
|
||||
{
|
||||
if ( !red )
|
||||
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
|
||||
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( model )
|
||||
@ -148,9 +148,9 @@ AclJobDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QSt
|
||||
{
|
||||
QMouseEvent* me = static_cast< QMouseEvent* >( event );
|
||||
if ( m_savedAcceptRect.contains( me->pos() ) )
|
||||
emit aclResult( AclRegistry::Stream );
|
||||
emit aclResult( ACLRegistry::Stream );
|
||||
else if ( m_savedDenyRect.contains( me->pos() ) )
|
||||
emit aclResult( AclRegistry::Deny );
|
||||
emit aclResult( ACLRegistry::Deny );
|
||||
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_user( user )
|
||||
, m_username( username )
|
||||
@ -168,36 +168,36 @@ AclJobItem::AclJobItem( AclRegistry::User user, const QString &username )
|
||||
}
|
||||
|
||||
|
||||
AclJobItem::~AclJobItem()
|
||||
ACLJobItem::~ACLJobItem()
|
||||
{
|
||||
tLog() << Q_FUNC_INFO;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AclJobItem::createDelegate( QObject* parent )
|
||||
ACLJobItem::createDelegate( QObject* parent )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO;
|
||||
|
||||
if ( m_delegate )
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AclJobDelegate::emitSizeHintChanged( const QModelIndex& index )
|
||||
ACLJobDelegate::emitSizeHintChanged( const QModelIndex& index )
|
||||
{
|
||||
emit sizeHintChanged( index );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AclJobItem::aclResult( AclRegistry::ACL result )
|
||||
ACLJobItem::aclResult( ACLRegistry::ACL result )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO;
|
||||
m_user.acl = result;
|
||||
|
@ -28,13 +28,13 @@
|
||||
|
||||
class QListView;
|
||||
|
||||
class DLLEXPORT AclJobDelegate : public QStyledItemDelegate
|
||||
class DLLEXPORT ACLJobDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AclJobDelegate ( QObject* parent = 0 );
|
||||
virtual ~AclJobDelegate();
|
||||
explicit ACLJobDelegate ( QObject* parent = 0 );
|
||||
virtual ~ACLJobDelegate();
|
||||
|
||||
virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
@ -43,7 +43,7 @@ public:
|
||||
|
||||
signals:
|
||||
void update( const QModelIndex& idx );
|
||||
void aclResult( AclRegistry::ACL result );
|
||||
void aclResult( ACLRegistry::ACL result );
|
||||
|
||||
protected:
|
||||
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
|
||||
public:
|
||||
explicit AclJobItem( AclRegistry::User user, const QString &username );
|
||||
virtual ~AclJobItem();
|
||||
explicit ACLJobItem( ACLRegistry::User user, const QString &username );
|
||||
virtual ~ACLJobItem();
|
||||
|
||||
virtual QString rightColumnText() const { return QString(); }
|
||||
virtual QString mainText() const { return QString(); }
|
||||
@ -75,18 +75,18 @@ public:
|
||||
virtual void createDelegate( QObject* parent = 0 );
|
||||
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; }
|
||||
|
||||
signals:
|
||||
void userDecision( AclRegistry::User user );
|
||||
void userDecision( ACLRegistry::User user );
|
||||
|
||||
public slots:
|
||||
void aclResult( AclRegistry::ACL result );
|
||||
void aclResult( ACLRegistry::ACL result );
|
||||
|
||||
private:
|
||||
QStyledItemDelegate* m_delegate;
|
||||
AclRegistry::User m_user;
|
||||
ACLRegistry::User m_user;
|
||||
const QString m_username;
|
||||
};
|
||||
|
||||
|
@ -108,12 +108,12 @@ JobStatusView::customDelegateJobInserted( int row, JobStatusItem* item )
|
||||
item->createDelegate( m_view );
|
||||
tLog() << Q_FUNC_INFO << "item delegate is" << item->customDelegate();
|
||||
m_view->setItemDelegateForRow( row, item->customDelegate() );
|
||||
AclJobDelegate* delegate = qobject_cast< AclJobDelegate* >( item->customDelegate() );
|
||||
ACLJobDelegate* delegate = qobject_cast< ACLJobDelegate* >( item->customDelegate() );
|
||||
if ( delegate )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO << "delegate found";
|
||||
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 ) );
|
||||
}
|
||||
else
|
||||
|
@ -208,13 +208,13 @@ Connection::checkACL()
|
||||
QString nodeid = property( "nodeid" ).toString();
|
||||
QString bareName = name().contains( '/' ) ? name().left( name().indexOf( "/" ) ) : 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 );
|
||||
QMetaObject::invokeMethod( AclRegistry::instance(), "isAuthorizedUser", Qt::QueuedConnection, Q_ARG( QString, nodeid ), Q_ARG( QString, bareName ), Q_ARG( AclRegistry::ACL, AclRegistry::NotFound ) );
|
||||
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 ) );
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
if ( nodeid != property( "nodeid" ).toString() || username != bareName )
|
||||
@ -223,9 +223,9 @@ Connection::checkACLResult( const QString &nodeid, const QString &username, AclR
|
||||
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;
|
||||
if ( peerStatus == AclRegistry::Stream )
|
||||
if ( peerStatus == ACLRegistry::Stream )
|
||||
{
|
||||
QTimer::singleShot( 0, this, SLOT( doSetup() ) );
|
||||
return;
|
||||
|
@ -120,7 +120,7 @@ private slots:
|
||||
void readyRead();
|
||||
void doSetup();
|
||||
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 bytesWritten( qint64 );
|
||||
void calcStats();
|
||||
|
@ -65,7 +65,6 @@ Servent::Servent( QObject* parent )
|
||||
s_instance = this;
|
||||
|
||||
m_lanHack = qApp->arguments().contains( "--lanhack" );
|
||||
AclRegistry::instance();
|
||||
setProxy( QNetworkProxy::NoProxy );
|
||||
|
||||
{
|
||||
@ -90,7 +89,6 @@ Servent::Servent( QObject* parent )
|
||||
|
||||
Servent::~Servent()
|
||||
{
|
||||
delete AclRegistry::instance();
|
||||
delete m_portfwd;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user