mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-13 20:39:57 +01: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:
parent
50ce4d3c55
commit
9419c77069
@ -36,6 +36,7 @@ set( libGuiSources
|
||||
jobview/JobStatusModel.cpp
|
||||
jobview/JobStatusDelegate.cpp
|
||||
jobview/JobStatusItem.cpp
|
||||
jobview/AclJobItem.cpp
|
||||
jobview/PipelineStatusItem.cpp
|
||||
jobview/TransferStatusItem.cpp
|
||||
jobview/LatchedStatusItem.cpp
|
||||
|
@ -26,6 +26,9 @@
|
||||
#include "tomahawkapp.h"
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include "jobview/AclJobItem.h"
|
||||
#include "jobview/JobStatusView.h"
|
||||
#include "jobview/JobStatusModel.h"
|
||||
|
||||
|
||||
ACLRegistry* ACLRegistry::s_instance = 0;
|
||||
@ -64,6 +67,10 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL
|
||||
return;
|
||||
}
|
||||
|
||||
//FIXME: Remove when things are working
|
||||
emit aclResult( dbid, username, ACLRegistry::Stream );
|
||||
return;
|
||||
|
||||
bool found = false;
|
||||
QMutableListIterator< ACLRegistry::User > i( m_cache );
|
||||
while ( i.hasNext() )
|
||||
@ -103,24 +110,13 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL
|
||||
user.knownAccountIds.append( username );
|
||||
if ( globalType != ACLRegistry::NotFound )
|
||||
user.acl = globalType;
|
||||
#ifndef ENABLE_HEADLESS
|
||||
else
|
||||
{
|
||||
ACLRegistry::ACL acl = globalType;
|
||||
tDebug( LOGVERBOSE ) << "ACL is intially" << acl;
|
||||
#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;
|
||||
{
|
||||
getUserDecision( user );
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
m_cache.append( user );
|
||||
emit aclResult( dbid, username, user.acl );
|
||||
return;
|
||||
@ -128,39 +124,24 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL
|
||||
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
ACLRegistry::ACL
|
||||
ACLRegistry::getUserDecision( const QString &username )
|
||||
void
|
||||
ACLRegistry::getUserDecision( User user )
|
||||
{
|
||||
return ACLRegistry::Stream;
|
||||
QMessageBox msgBox;
|
||||
msgBox.setIcon( QMessageBox::Question );
|
||||
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;
|
||||
AclJobItem* job = new AclJobItem( user );
|
||||
connect( job, SIGNAL( userDecision( ACLRegistry::User ) ), this, SLOT( userDecision( ACLRegistry::User ) ) );
|
||||
JobStatusView::instance()->model()->addJob( job );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
ACLRegistry::userDecision( ACLRegistry::User user )
|
||||
{
|
||||
m_cache.append( user );
|
||||
emit aclResult( user.knownDbids.first(), user.knownAccountIds.first(), user.acl );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ACLRegistry::load()
|
||||
{
|
||||
|
@ -53,6 +53,7 @@ public:
|
||||
|
||||
User()
|
||||
: uuid( QUuid::createUuid().toString() )
|
||||
, acl( ACLRegistry::NotFound )
|
||||
{}
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
ACLRegistry::ACL getUserDecision( const QString &username );
|
||||
#endif
|
||||
#ifndef ENABLE_HEADLESS
|
||||
void getUserDecision( User user );
|
||||
#endif
|
||||
|
||||
private slots:
|
||||
void userDecision( ACLRegistry::User user );
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -25,10 +25,8 @@
|
||||
#include <QListView>
|
||||
#include <QApplication>
|
||||
|
||||
static QPixmap* s_indexIcon = 0;
|
||||
|
||||
|
||||
#define ROW_HEIGHT 20
|
||||
#define ROW_HEIGHT 40
|
||||
#define ICON_PADDING 1
|
||||
#define PADDING 2
|
||||
AclJobDelegate::AclJobDelegate( QObject* parent )
|
||||
@ -42,6 +40,7 @@ AclJobDelegate::AclJobDelegate( QObject* parent )
|
||||
void
|
||||
AclJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||
{
|
||||
/*
|
||||
QStyleOptionViewItemV4 opt = option;
|
||||
initStyleOption( &opt, index );
|
||||
QFontMetrics fm( opt.font );
|
||||
@ -80,46 +79,32 @@ AclJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
||||
else
|
||||
to.setWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere );
|
||||
painter->drawText( QRect( iconRect.right() + 2*PADDING, PADDING + opt.rect.y(), mainW, opt.rect.height() - 2*PADDING ), mainText, to );
|
||||
*/
|
||||
}
|
||||
|
||||
QSize
|
||||
AclJobDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||
{
|
||||
const bool allowMultiLine = index.data( JobStatusModel::AllowMultiLineRole ).toBool();
|
||||
|
||||
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 );
|
||||
return QSize( QStyledItemDelegate::sizeHint ( option, index ).width(), ROW_HEIGHT );
|
||||
}
|
||||
|
||||
|
||||
|
||||
AclJobItem::AclJobItem()
|
||||
AclJobItem::AclJobItem( ACLRegistry::User user )
|
||||
: m_delegate( 0 )
|
||||
, m_user( user )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AclJobItem::~AclJobItem()
|
||||
{
|
||||
if ( m_delegate );
|
||||
if ( m_delegate )
|
||||
delete m_delegate;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AclJobItem::createDelegate( QObject* parent )
|
||||
{
|
||||
if ( m_delegate )
|
||||
|
@ -20,9 +20,10 @@
|
||||
#ifndef ACLJOBITEM_H
|
||||
#define ACLJOBITEM_H
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
#include <jobview/JobStatusItem.h>
|
||||
#include "aclregistry.h"
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class QListView;
|
||||
|
||||
@ -32,13 +33,11 @@ class AclJobDelegate : public QStyledItemDelegate
|
||||
|
||||
public:
|
||||
explicit AclJobDelegate ( QObject* parent = 0 );
|
||||
virtual ~AclJobDelegate();
|
||||
virtual ~AclJobDelegate() {}
|
||||
|
||||
virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
|
||||
virtual void setParent( QObject* parent );
|
||||
|
||||
private:
|
||||
mutable QHash< QPersistentModelIndex, int > m_cachedMultiLineHeights;
|
||||
QListView* m_parentView;
|
||||
@ -49,8 +48,8 @@ class AclJobItem : public JobStatusItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AclJobItem();
|
||||
~AclJobItem();
|
||||
explicit AclJobItem( ACLRegistry::User user );
|
||||
virtual ~AclJobItem();
|
||||
|
||||
void done();
|
||||
|
||||
@ -61,12 +60,18 @@ public:
|
||||
|
||||
virtual int concurrentJobLimit() const { return 3; }
|
||||
|
||||
virtual bool hasCustomDelegate() { return true; }
|
||||
virtual bool hasCustomDelegate() const { return true; }
|
||||
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:
|
||||
QStyledItemDelegate* m_delegate;
|
||||
ACLRegistry::User m_user;
|
||||
};
|
||||
|
||||
#endif // ACLJOBITEMJOBITEM_H
|
||||
#endif // ACLJOBITEM_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user