mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 00:24:12 +02:00
Add a lot more acl job plumbing; it's pretty much ready to go except for
the actual drawing
This commit is contained in:
@@ -36,6 +36,7 @@ set( libGuiSources
|
|||||||
jobview/JobStatusModel.cpp
|
jobview/JobStatusModel.cpp
|
||||||
jobview/JobStatusDelegate.cpp
|
jobview/JobStatusDelegate.cpp
|
||||||
jobview/JobStatusItem.cpp
|
jobview/JobStatusItem.cpp
|
||||||
|
jobview/AclJobItem.cpp
|
||||||
jobview/PipelineStatusItem.cpp
|
jobview/PipelineStatusItem.cpp
|
||||||
jobview/TransferStatusItem.cpp
|
jobview/TransferStatusItem.cpp
|
||||||
jobview/LatchedStatusItem.cpp
|
jobview/LatchedStatusItem.cpp
|
||||||
|
@@ -26,6 +26,9 @@
|
|||||||
#include "tomahawkapp.h"
|
#include "tomahawkapp.h"
|
||||||
|
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
#include "jobview/AclJobItem.h"
|
||||||
|
#include "jobview/JobStatusView.h"
|
||||||
|
#include "jobview/JobStatusModel.h"
|
||||||
|
|
||||||
|
|
||||||
ACLRegistry* ACLRegistry::s_instance = 0;
|
ACLRegistry* ACLRegistry::s_instance = 0;
|
||||||
@@ -64,6 +67,10 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//FIXME: Remove when things are working
|
||||||
|
emit aclResult( dbid, username, ACLRegistry::Stream );
|
||||||
|
return;
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
QMutableListIterator< ACLRegistry::User > i( m_cache );
|
QMutableListIterator< ACLRegistry::User > i( m_cache );
|
||||||
while ( i.hasNext() )
|
while ( i.hasNext() )
|
||||||
@@ -103,24 +110,13 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL
|
|||||||
user.knownAccountIds.append( username );
|
user.knownAccountIds.append( username );
|
||||||
if ( globalType != ACLRegistry::NotFound )
|
if ( globalType != ACLRegistry::NotFound )
|
||||||
user.acl = globalType;
|
user.acl = globalType;
|
||||||
|
#ifndef ENABLE_HEADLESS
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ACLRegistry::ACL acl = globalType;
|
getUserDecision( user );
|
||||||
tDebug( LOGVERBOSE ) << "ACL is intially" << acl;
|
return;
|
||||||
#ifndef ENABLE_HEADLESS
|
|
||||||
acl = getUserDecision( username );
|
|
||||||
tDebug( LOGVERBOSE ) << "after getUserDecision acl is" << acl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ( acl == ACLRegistry::NotFound )
|
|
||||||
{
|
|
||||||
emit aclResult( dbid, username, acl );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
user.acl = acl;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
m_cache.append( user );
|
m_cache.append( user );
|
||||||
emit aclResult( dbid, username, user.acl );
|
emit aclResult( dbid, username, user.acl );
|
||||||
return;
|
return;
|
||||||
@@ -128,39 +124,24 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL
|
|||||||
|
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
|
void
|
||||||
#include <QMessageBox>
|
ACLRegistry::getUserDecision( User user )
|
||||||
|
|
||||||
ACLRegistry::ACL
|
|
||||||
ACLRegistry::getUserDecision( const QString &username )
|
|
||||||
{
|
{
|
||||||
return ACLRegistry::Stream;
|
AclJobItem* job = new AclJobItem( user );
|
||||||
QMessageBox msgBox;
|
connect( job, SIGNAL( userDecision( ACLRegistry::User ) ), this, SLOT( userDecision( ACLRegistry::User ) ) );
|
||||||
msgBox.setIcon( QMessageBox::Question );
|
JobStatusView::instance()->model()->addJob( job );
|
||||||
msgBox.setText( tr( "Connect to Peer?" ) );
|
|
||||||
msgBox.setInformativeText( tr( "Another Tomahawk instance that claims to be owned by %1 is attempting to connect to you. Select whether to allow or deny this connection.\n\nRemember: Only allow peers to connect if you trust who they are and if you have the legal right for them to stream music from you.").arg( username ) );
|
|
||||||
QPushButton *denyButton = msgBox.addButton( tr( "Deny" ), QMessageBox::YesRole );
|
|
||||||
QPushButton *allowButton = msgBox.addButton( tr( "Allow" ), QMessageBox::ActionRole );
|
|
||||||
|
|
||||||
msgBox.setDefaultButton( allowButton );
|
|
||||||
msgBox.setEscapeButton( denyButton );
|
|
||||||
|
|
||||||
msgBox.exec();
|
|
||||||
|
|
||||||
if( msgBox.clickedButton() == denyButton )
|
|
||||||
return ACLRegistry::Deny;
|
|
||||||
else if( msgBox.clickedButton() == allowButton )
|
|
||||||
return ACLRegistry::Stream;
|
|
||||||
|
|
||||||
//How could we get here?
|
|
||||||
tDebug( LOGVERBOSE ) << "ERROR: returning NotFound";
|
|
||||||
Q_ASSERT( false );
|
|
||||||
return ACLRegistry::NotFound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ACLRegistry::userDecision( ACLRegistry::User user )
|
||||||
|
{
|
||||||
|
m_cache.append( user );
|
||||||
|
emit aclResult( user.knownDbids.first(), user.knownAccountIds.first(), user.acl );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ACLRegistry::load()
|
ACLRegistry::load()
|
||||||
{
|
{
|
||||||
|
@@ -53,6 +53,7 @@ public:
|
|||||||
|
|
||||||
User()
|
User()
|
||||||
: uuid( QUuid::createUuid().toString() )
|
: uuid( QUuid::createUuid().toString() )
|
||||||
|
, acl( ACLRegistry::NotFound )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
User( QString p_uuid, QStringList p_knownDbids, QStringList p_knownAccountIds, ACL p_acl )
|
User( QString p_uuid, QStringList p_knownDbids, QStringList p_knownAccountIds, ACL p_acl )
|
||||||
@@ -80,10 +81,12 @@ public slots:
|
|||||||
**/
|
**/
|
||||||
void isAuthorizedUser( const QString &dbid, const QString &username, ACLRegistry::ACL globalType = ACLRegistry::NotFound );
|
void isAuthorizedUser( const QString &dbid, const QString &username, ACLRegistry::ACL globalType = ACLRegistry::NotFound );
|
||||||
|
|
||||||
|
#ifndef ENABLE_HEADLESS
|
||||||
|
void getUserDecision( User user );
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
private slots:
|
||||||
ACLRegistry::ACL getUserDecision( const QString &username );
|
void userDecision( ACLRegistry::User user );
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
|
@@ -25,10 +25,8 @@
|
|||||||
#include <QListView>
|
#include <QListView>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
static QPixmap* s_indexIcon = 0;
|
|
||||||
|
|
||||||
|
#define ROW_HEIGHT 40
|
||||||
#define ROW_HEIGHT 20
|
|
||||||
#define ICON_PADDING 1
|
#define ICON_PADDING 1
|
||||||
#define PADDING 2
|
#define PADDING 2
|
||||||
AclJobDelegate::AclJobDelegate( QObject* parent )
|
AclJobDelegate::AclJobDelegate( QObject* parent )
|
||||||
@@ -42,6 +40,7 @@ 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 );
|
||||||
@@ -80,46 +79,32 @@ AclJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
|||||||
else
|
else
|
||||||
to.setWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere );
|
to.setWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere );
|
||||||
painter->drawText( QRect( iconRect.right() + 2*PADDING, PADDING + opt.rect.y(), mainW, opt.rect.height() - 2*PADDING ), mainText, to );
|
painter->drawText( QRect( iconRect.right() + 2*PADDING, PADDING + opt.rect.y(), mainW, opt.rect.height() - 2*PADDING ), mainText, to );
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize
|
QSize
|
||||||
AclJobDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
AclJobDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||||
{
|
{
|
||||||
const bool allowMultiLine = index.data( JobStatusModel::AllowMultiLineRole ).toBool();
|
return QSize( QStyledItemDelegate::sizeHint ( option, index ).width(), ROW_HEIGHT );
|
||||||
|
|
||||||
if ( !allowMultiLine )
|
|
||||||
return QSize( QStyledItemDelegate::sizeHint ( option, index ).width(), ROW_HEIGHT );
|
|
||||||
else if ( m_cachedMultiLineHeights.contains( index ) )
|
|
||||||
return QSize( QStyledItemDelegate::sizeHint ( option, index ).width(), m_cachedMultiLineHeights[ index ] );
|
|
||||||
|
|
||||||
// Don't elide, but stretch across as many rows as required
|
|
||||||
QStyleOptionViewItemV4 opt = option;
|
|
||||||
initStyleOption( &opt, index );
|
|
||||||
|
|
||||||
const QString text = index.data( Qt::DisplayRole ).toString();
|
|
||||||
const int leftEdge = ICON_PADDING + ROW_HEIGHT + 2*PADDING;
|
|
||||||
const QRect rect = opt.fontMetrics.boundingRect( leftEdge, opt.rect.top(), m_parentView->width() - leftEdge, 200, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, text );
|
|
||||||
|
|
||||||
m_cachedMultiLineHeights.insert( index, rect.height() + 4*PADDING );
|
|
||||||
|
|
||||||
return QSize( QStyledItemDelegate::sizeHint ( option, index ).width(), rect.height() + 4*PADDING );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AclJobItem::AclJobItem()
|
AclJobItem::AclJobItem( ACLRegistry::User user )
|
||||||
: m_delegate( 0 )
|
: m_delegate( 0 )
|
||||||
|
, m_user( user )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AclJobItem::~AclJobItem()
|
AclJobItem::~AclJobItem()
|
||||||
{
|
{
|
||||||
if ( m_delegate );
|
if ( m_delegate )
|
||||||
delete m_delegate;
|
delete m_delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
AclJobItem::createDelegate( QObject* parent )
|
AclJobItem::createDelegate( QObject* parent )
|
||||||
{
|
{
|
||||||
if ( m_delegate )
|
if ( m_delegate )
|
||||||
|
@@ -20,9 +20,10 @@
|
|||||||
#ifndef ACLJOBITEM_H
|
#ifndef ACLJOBITEM_H
|
||||||
#define ACLJOBITEM_H
|
#define ACLJOBITEM_H
|
||||||
|
|
||||||
#include <QStyledItemDelegate>
|
|
||||||
|
|
||||||
#include <jobview/JobStatusItem.h>
|
#include <jobview/JobStatusItem.h>
|
||||||
|
#include "aclregistry.h"
|
||||||
|
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
class QListView;
|
class QListView;
|
||||||
|
|
||||||
@@ -32,13 +33,11 @@ class AclJobDelegate : public QStyledItemDelegate
|
|||||||
|
|
||||||
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;
|
||||||
|
|
||||||
virtual void setParent( QObject* parent );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable QHash< QPersistentModelIndex, int > m_cachedMultiLineHeights;
|
mutable QHash< QPersistentModelIndex, int > m_cachedMultiLineHeights;
|
||||||
QListView* m_parentView;
|
QListView* m_parentView;
|
||||||
@@ -49,8 +48,8 @@ class AclJobItem : public JobStatusItem
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit AclJobItem();
|
explicit AclJobItem( ACLRegistry::User user );
|
||||||
~AclJobItem();
|
virtual ~AclJobItem();
|
||||||
|
|
||||||
void done();
|
void done();
|
||||||
|
|
||||||
@@ -61,12 +60,18 @@ public:
|
|||||||
|
|
||||||
virtual int concurrentJobLimit() const { return 3; }
|
virtual int concurrentJobLimit() const { return 3; }
|
||||||
|
|
||||||
virtual bool hasCustomDelegate() { return true; }
|
virtual bool hasCustomDelegate() const { return true; }
|
||||||
virtual void createDelegate( QObject* parent );
|
virtual void createDelegate( QObject* parent );
|
||||||
virtual QStyledItemDelegate* customDelegate() { return m_delegate; }
|
virtual QStyledItemDelegate* customDelegate() const { return m_delegate; }
|
||||||
|
|
||||||
|
virtual ACLRegistry::User user() const { return m_user; }
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void userDecision( ACLRegistry::User user );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStyledItemDelegate* m_delegate;
|
QStyledItemDelegate* m_delegate;
|
||||||
|
ACLRegistry::User m_user;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ACLJOBITEMJOBITEM_H
|
#endif // ACLJOBITEM_H
|
||||||
|
Reference in New Issue
Block a user