mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 02:54:33 +02:00
Check in interim work
This commit is contained in:
@@ -410,6 +410,7 @@ TomahawkApp::registerMetaTypes()
|
|||||||
qRegisterMetaType< QMap< QString, QMap< unsigned int, unsigned int > > >("QMap< QString, QMap< unsigned int, unsigned int > >");
|
qRegisterMetaType< QMap< QString, QMap< unsigned int, unsigned int > > >("QMap< QString, QMap< unsigned int, unsigned int > >");
|
||||||
qRegisterMetaType< PairList >("PairList");
|
qRegisterMetaType< PairList >("PairList");
|
||||||
qRegisterMetaType< JobStatusItem* >("JobStatusItem*");
|
qRegisterMetaType< JobStatusItem* >("JobStatusItem*");
|
||||||
|
qRegisterMetaType< AclJobItem* >("AclJobItem*");
|
||||||
|
|
||||||
qRegisterMetaType< GeneratorMode>("GeneratorMode");
|
qRegisterMetaType< GeneratorMode>("GeneratorMode");
|
||||||
qRegisterMetaType<Tomahawk::GeneratorMode>("Tomahawk::GeneratorMode");
|
qRegisterMetaType<Tomahawk::GeneratorMode>("Tomahawk::GeneratorMode");
|
||||||
|
@@ -44,6 +44,7 @@ ACLRegistry::instance()
|
|||||||
|
|
||||||
ACLRegistry::ACLRegistry( QObject* parent )
|
ACLRegistry::ACLRegistry( QObject* parent )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
|
, m_jobCount( 0 )
|
||||||
{
|
{
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
qRegisterMetaType< ACLRegistry::ACL >( "ACLRegistry::ACL" );
|
qRegisterMetaType< ACLRegistry::ACL >( "ACLRegistry::ACL" );
|
||||||
@@ -58,18 +59,19 @@ ACLRegistry::~ACLRegistry()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
ACLRegistry::ACL
|
||||||
ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACLRegistry::ACL globalType )
|
ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACLRegistry::ACL globalType, bool skipEmission )
|
||||||
{
|
{
|
||||||
if ( QThread::currentThread() != TOMAHAWK_APPLICATION::instance()->thread() )
|
if ( QThread::currentThread() != TOMAHAWK_APPLICATION::instance()->thread() )
|
||||||
{
|
{
|
||||||
emit aclResult( dbid, username, globalType );
|
if ( !skipEmission )
|
||||||
return;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME: Remove when things are working
|
//FIXME: Remove when things are working
|
||||||
emit aclResult( dbid, username, ACLRegistry::Stream );
|
emit aclResult( dbid, username, ACLRegistry::Stream );
|
||||||
return;
|
return ACLRegistry::NotFound;
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
QMutableListIterator< ACLRegistry::User > i( m_cache );
|
QMutableListIterator< ACLRegistry::User > i( m_cache );
|
||||||
@@ -98,12 +100,16 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL
|
|||||||
|
|
||||||
if ( found )
|
if ( found )
|
||||||
{
|
{
|
||||||
emit aclResult( dbid, username, user.acl );
|
if ( !skipEmission )
|
||||||
|
emit aclResult( dbid, username, user.acl );
|
||||||
i.setValue( user );
|
i.setValue( user );
|
||||||
return;
|
return user.acl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( skipEmission )
|
||||||
|
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 );
|
||||||
@@ -113,23 +119,23 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL
|
|||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
getUserDecision( user );
|
getUserDecision( user, username );
|
||||||
return;
|
return ACLRegistry::NotFound;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
m_cache.append( user );
|
m_cache.append( user );
|
||||||
emit aclResult( dbid, username, user.acl );
|
emit aclResult( dbid, username, user.acl );
|
||||||
return;
|
return user.acl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
void
|
void
|
||||||
ACLRegistry::getUserDecision( User user )
|
ACLRegistry::getUserDecision( ACLRegistry::User user, const QString &username )
|
||||||
{
|
{
|
||||||
AclJobItem* job = new AclJobItem( user );
|
AclJobItem* job = new AclJobItem( user, username );
|
||||||
connect( job, SIGNAL( userDecision( ACLRegistry::User ) ), this, SLOT( userDecision( ACLRegistry::User ) ) );
|
m_jobQueue.enqueue( job );
|
||||||
JobStatusView::instance()->model()->addJob( job );
|
queueNextJob();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -138,7 +144,48 @@ void
|
|||||||
ACLRegistry::userDecision( ACLRegistry::User user )
|
ACLRegistry::userDecision( ACLRegistry::User user )
|
||||||
{
|
{
|
||||||
m_cache.append( user );
|
m_cache.append( user );
|
||||||
|
save();
|
||||||
emit aclResult( user.knownDbids.first(), user.knownAccountIds.first(), user.acl );
|
emit aclResult( user.knownDbids.first(), user.knownAccountIds.first(), user.acl );
|
||||||
|
|
||||||
|
m_jobCount--;
|
||||||
|
if ( !m_jobQueue.isEmpty() )
|
||||||
|
queueNextJob();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ACLRegistry::queueNextJob()
|
||||||
|
{
|
||||||
|
if ( m_jobCount != 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( !m_jobQueue.isEmpty() )
|
||||||
|
{
|
||||||
|
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 )
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( found )
|
||||||
|
{
|
||||||
|
delete job;
|
||||||
|
QTimer::singleShot( 0, this, SLOT( queueNextJob() ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_jobCount++;
|
||||||
|
JobStatusView::instance()->model()->addJob( job );
|
||||||
|
connect( job, SIGNAL( userDecision( ACLRegistry::User ) ), this, SLOT( userDecision( ACLRegistry::User ) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -30,6 +30,8 @@
|
|||||||
#include "HeadlessCheck.h"
|
#include "HeadlessCheck.h"
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
class AclJobItem;
|
||||||
|
|
||||||
class DLLEXPORT ACLRegistry : public QObject
|
class DLLEXPORT ACLRegistry : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -79,14 +81,15 @@ public slots:
|
|||||||
* @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
|
||||||
**/
|
**/
|
||||||
void isAuthorizedUser( const QString &dbid, const QString &username, ACLRegistry::ACL globalType = ACLRegistry::NotFound );
|
ACLRegistry::ACL isAuthorizedUser( const QString &dbid, const QString &username, ACLRegistry::ACL globalType = ACLRegistry::NotFound, bool skipEmission = false );
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
void getUserDecision( User user );
|
void getUserDecision( ACLRegistry::User user, const QString &username );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void userDecision( ACLRegistry::User user );
|
void userDecision( ACLRegistry::User user );
|
||||||
|
void queueNextJob();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
@@ -101,6 +104,9 @@ private:
|
|||||||
QList< ACLRegistry::User > m_cache;
|
QList< ACLRegistry::User > m_cache;
|
||||||
|
|
||||||
static ACLRegistry* s_instance;
|
static ACLRegistry* s_instance;
|
||||||
|
|
||||||
|
QQueue< AclJobItem* > m_jobQueue;
|
||||||
|
int m_jobCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE( ACLRegistry::ACL );
|
Q_DECLARE_METATYPE( ACLRegistry::ACL );
|
||||||
|
@@ -19,9 +19,11 @@
|
|||||||
|
|
||||||
#include "AclJobItem.h"
|
#include "AclJobItem.h"
|
||||||
|
|
||||||
|
#include "JobStatusModel.h"
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QPainter>
|
||||||
#include <QListView>
|
#include <QListView>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
@@ -40,11 +42,9 @@ AclJobDelegate::AclJobDelegate( QObject* parent )
|
|||||||
void
|
void
|
||||||
AclJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
AclJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
QStyleOptionViewItemV4 opt = option;
|
QStyleOptionViewItemV4 opt = option;
|
||||||
initStyleOption( &opt, index );
|
initStyleOption( &opt, index );
|
||||||
QFontMetrics fm( opt.font );
|
QFontMetrics fm( opt.font );
|
||||||
const bool allowMultiLine = index.data( JobStatusModel::AllowMultiLineRole ).toBool();
|
|
||||||
|
|
||||||
opt.state &= ~QStyle::State_MouseOver;
|
opt.state &= ~QStyle::State_MouseOver;
|
||||||
QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget );
|
QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget );
|
||||||
@@ -52,24 +52,20 @@ AclJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
|||||||
// painter->drawLine( opt.rect.topLeft(), opt.rect.topRight() );
|
// painter->drawLine( opt.rect.topLeft(), opt.rect.topRight() );
|
||||||
|
|
||||||
painter->setRenderHint( QPainter::Antialiasing );
|
painter->setRenderHint( QPainter::Antialiasing );
|
||||||
QRect iconRect( ICON_PADDING, ICON_PADDING + opt.rect.y(), ROW_HEIGHT - 2*ICON_PADDING, ROW_HEIGHT - 2*ICON_PADDING );
|
//QRect iconRect( ICON_PADDING, ICON_PADDING + opt.rect.y(), ROW_HEIGHT - 2*ICON_PADDING, ROW_HEIGHT - 2*ICON_PADDING );
|
||||||
if ( allowMultiLine )
|
//QPixmap p = index.data( Qt::DecorationRole ).value< QPixmap >();
|
||||||
iconRect.moveTop( opt.rect.top() + opt.rect.height() / 2 - iconRect.height() / 2);
|
//p = p.scaledToHeight( iconRect.height(), Qt::SmoothTransformation );
|
||||||
QPixmap p = index.data( Qt::DecorationRole ).value< QPixmap >();
|
//painter->drawPixmap( iconRect, p );
|
||||||
p = p.scaledToHeight( iconRect.height(), Qt::SmoothTransformation );
|
|
||||||
painter->drawPixmap( iconRect, p );
|
|
||||||
|
|
||||||
// draw right column if there is one
|
// draw right column if there is one
|
||||||
const QString rCol = index.data( JobStatusModel::RightColumnRole ).toString();
|
AclJobItem* item = index.data( JobStatusModel::JobDataRole ).value< AclJobItem* >();
|
||||||
int rightEdge = opt.rect.right();
|
const QString text = QString( tr( "Allow %1 to\nconnect and stream from you?" ) ).arg( item->username() );
|
||||||
if ( !rCol.isEmpty() )
|
const int w = fm.width( text );
|
||||||
{
|
const QRect rRect( opt.rect.left() + PADDING, opt.rect.y() - PADDING, opt.rect.width() - 2*PADDING, opt.rect.height() - 2*PADDING );
|
||||||
const int w = fm.width( rCol );
|
painter->drawText( rRect, Qt::AlignCenter, text );
|
||||||
const QRect rRect( opt.rect.right() - PADDING - w, PADDING + opt.rect.y(), w, opt.rect.height() - 2*PADDING );
|
|
||||||
painter->drawText( rRect, Qt::AlignCenter, rCol );
|
|
||||||
|
|
||||||
rightEdge = rRect.left();
|
/*
|
||||||
}
|
rightEdge = rRect.left();
|
||||||
|
|
||||||
const int mainW = rightEdge - 3*PADDING - iconRect.right();
|
const int mainW = rightEdge - 3*PADDING - iconRect.right();
|
||||||
QString mainText = index.data( Qt::DisplayRole ).toString();
|
QString mainText = index.data( Qt::DisplayRole ).toString();
|
||||||
@@ -90,9 +86,10 @@ AclJobDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex&
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
AclJobItem::AclJobItem( ACLRegistry::User user )
|
AclJobItem::AclJobItem( ACLRegistry::User user, const QString &username )
|
||||||
: m_delegate( 0 )
|
: m_delegate( 0 )
|
||||||
, m_user( user )
|
, m_user( user )
|
||||||
|
, m_username( username )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -48,7 +48,7 @@ class AclJobItem : public JobStatusItem
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit AclJobItem( ACLRegistry::User user );
|
explicit AclJobItem( ACLRegistry::User user, const QString &username );
|
||||||
virtual ~AclJobItem();
|
virtual ~AclJobItem();
|
||||||
|
|
||||||
void done();
|
void done();
|
||||||
@@ -65,13 +65,17 @@ public:
|
|||||||
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; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void userDecision( ACLRegistry::User user );
|
void userDecision( ACLRegistry::User user );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStyledItemDelegate* m_delegate;
|
QStyledItemDelegate* m_delegate;
|
||||||
ACLRegistry::User m_user;
|
ACLRegistry::User m_user;
|
||||||
|
const QString m_username;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE( AclJobItem* );
|
||||||
|
|
||||||
#endif // ACLJOBITEM_H
|
#endif // ACLJOBITEM_H
|
||||||
|
@@ -193,12 +193,13 @@ Connection::checkACL()
|
|||||||
{
|
{
|
||||||
if ( !property( "nodeid" ).isValid() )
|
if ( !property( "nodeid" ).isValid() )
|
||||||
{
|
{
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Not checking ACL, nodeid is empty";
|
||||||
QTimer::singleShot( 0, this, SLOT( doSetup() ) );
|
QTimer::singleShot( 0, this, SLOT( doSetup() ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString nodeid = property( "nodeid" ).toString();
|
QString nodeid = property( "nodeid" ).toString();
|
||||||
tDebug( LOGVERBOSE ) << "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, name() ), Q_ARG( ACLRegistry::ACL, ACLRegistry::NotFound ) );
|
QMetaObject::invokeMethod( ACLRegistry::instance(), "isAuthorizedUser", Qt::QueuedConnection, Q_ARG( QString, nodeid ), Q_ARG( QString, name() ), Q_ARG( ACLRegistry::ACL, ACLRegistry::NotFound ) );
|
||||||
}
|
}
|
||||||
@@ -211,7 +212,7 @@ 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 ) << "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() ) );
|
||||||
|
@@ -668,6 +668,7 @@ Servent::claimOffer( ControlConnection* cc, const QString &nodeid, const QString
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "nodeid is: " << nodeid;
|
||||||
if( !nodeid.isEmpty() )
|
if( !nodeid.isEmpty() )
|
||||||
{
|
{
|
||||||
// Used by the connection for the ACL check
|
// Used by the connection for the ACL check
|
||||||
|
Reference in New Issue
Block a user