diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 230d4a792..5c9a332e8 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -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 diff --git a/src/libtomahawk/aclregistry.cpp b/src/libtomahawk/aclregistry.cpp index d3261f15c..fadab1b50 100644 --- a/src/libtomahawk/aclregistry.cpp +++ b/src/libtomahawk/aclregistry.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 - -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() { diff --git a/src/libtomahawk/aclregistry.h b/src/libtomahawk/aclregistry.h index c9231ad90..8b9f0b3d2 100644 --- a/src/libtomahawk/aclregistry.h +++ b/src/libtomahawk/aclregistry.h @@ -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: /** diff --git a/src/libtomahawk/jobview/AclJobItem.cpp b/src/libtomahawk/jobview/AclJobItem.cpp index 4ee6e6b97..3c153f75f 100644 --- a/src/libtomahawk/jobview/AclJobItem.cpp +++ b/src/libtomahawk/jobview/AclJobItem.cpp @@ -25,10 +25,8 @@ #include #include -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 ) diff --git a/src/libtomahawk/jobview/AclJobItem.h b/src/libtomahawk/jobview/AclJobItem.h index 067a61fdf..af7c1f42a 100644 --- a/src/libtomahawk/jobview/AclJobItem.h +++ b/src/libtomahawk/jobview/AclJobItem.h @@ -20,9 +20,10 @@ #ifndef ACLJOBITEM_H #define ACLJOBITEM_H -#include - #include +#include "aclregistry.h" + +#include 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