From 4fcfbf8e069f1b82436b2dcff47fb1c259ce7da9 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sun, 22 Apr 2012 14:40:15 -0400 Subject: [PATCH 01/18] Semi-working ACL state. --- src/AccountDelegate.cpp | 48 +----- src/libtomahawk/AclRegistry.cpp | 11 +- src/libtomahawk/jobview/AclJobItem.cpp | 161 +++++++++++---------- src/libtomahawk/jobview/AclJobItem.h | 19 ++- src/libtomahawk/jobview/JobStatusView.cpp | 11 ++ src/libtomahawk/network/Servent.cpp | 2 + src/libtomahawk/utils/TomahawkUtilsGui.cpp | 50 +++++++ src/libtomahawk/utils/TomahawkUtilsGui.h | 5 +- 8 files changed, 182 insertions(+), 125 deletions(-) diff --git a/src/AccountDelegate.cpp b/src/AccountDelegate.cpp index ddff13f7a..1b9295447 100644 --- a/src/AccountDelegate.cpp +++ b/src/AccountDelegate.cpp @@ -26,6 +26,7 @@ #include "accounts/Account.h" #include "utils/TomahawkUtils.h" +#include "utils/TomahawkUtilsGui.h" #include "utils/Logger.h" #define CHILD_ACCOUNT_HEIGHT 24 @@ -523,53 +524,10 @@ AccountDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QS void AccountDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect, bool red ) const { - QPainterPath btnPath; - const int radius = 3; - // draw top half gradient - const int btnCenter = btnRect.bottom() - ( btnRect.height() / 2 ); - btnPath.moveTo( btnRect.left(), btnCenter ); - btnPath.lineTo( btnRect.left(), btnRect.top() + radius ); - btnPath.quadTo( QPoint( btnRect.topLeft() ), QPoint( btnRect.left() + radius, btnRect.top() ) ); - btnPath.lineTo( btnRect.right() - radius, btnRect.top() ); - btnPath.quadTo( QPoint( btnRect.topRight() ), QPoint( btnRect.right(), btnRect.top() + radius ) ); - btnPath.lineTo( btnRect.right(),btnCenter ); - btnPath.lineTo( btnRect.left(), btnCenter ); - - QLinearGradient g; if ( !red ) - { - g.setColorAt( 0, QColor(54, 127, 211) ); - g.setColorAt( 0.5, QColor(43, 104, 182) ); - } + TomahawkUtils::drawRoundedButton( painter, btnRect, QColor(54, 127, 211), QColor(43, 104, 182), QColor(34, 85, 159), QColor(35, 79, 147) ); else - { - g.setColorAt( 0, QColor(206, 63, 63) ); - g.setColorAt( 0.5, QColor(170, 52, 52) ); - } - //painter->setPen( bg.darker() ); - painter->fillPath( btnPath, g ); - //painter->drawPath( btnPath ); - - btnPath = QPainterPath(); - btnPath.moveTo( btnRect.left(), btnCenter ); - btnPath.lineTo( btnRect.left(), btnRect.bottom() - radius ); - btnPath.quadTo( QPoint( btnRect.bottomLeft() ), QPoint( btnRect.left() + radius, btnRect.bottom() ) ); - btnPath.lineTo( btnRect.right() - radius, btnRect.bottom() ); - btnPath.quadTo( QPoint( btnRect.bottomRight() ), QPoint( btnRect.right(), btnRect.bottom() - radius ) ); - btnPath.lineTo( btnRect.right(), btnCenter ); - btnPath.lineTo( btnRect.left(), btnCenter ); - - if ( !red ) - { - g.setColorAt( 0, QColor(34, 85, 159) ); - g.setColorAt( 0.5, QColor(35, 79, 147) ); - } - else - { - g.setColorAt( 0, QColor(150, 50, 50) ); - g.setColorAt( 0.5, QColor(130, 40, 40) ); - } - painter->fillPath( btnPath, g ); + TomahawkUtils::drawRoundedButton( painter, btnRect, QColor(206, 63, 63), QColor(170, 52, 52), QColor(150, 50, 50), QColor(130, 40, 40) ); } diff --git a/src/libtomahawk/AclRegistry.cpp b/src/libtomahawk/AclRegistry.cpp index 78f370ee5..3f9b40303 100644 --- a/src/libtomahawk/AclRegistry.cpp +++ b/src/libtomahawk/AclRegistry.cpp @@ -70,8 +70,8 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL } //FIXME: Remove when things are working - emit aclResult( dbid, username, ACLRegistry::Stream ); - return ACLRegistry::NotFound; +// emit aclResult( dbid, username, ACLRegistry::Stream ); +// return ACLRegistry::NotFound; bool found = false; QMutableListIterator< ACLRegistry::User > i( m_cache ); @@ -156,9 +156,11 @@ ACLRegistry::userDecision( ACLRegistry::User user ) void ACLRegistry::queueNextJob() { + tDebug() << Q_FUNC_INFO << "jobCount = " << m_jobCount; if ( m_jobCount != 0 ) return; - + + tDebug() << Q_FUNC_INFO << "jobQueue size = " << m_jobQueue.length(); if ( !m_jobQueue.isEmpty() ) { AclJobItem* job = m_jobQueue.dequeue(); @@ -169,18 +171,21 @@ ACLRegistry::queueNextJob() ACLRegistry::ACL acl = isAuthorizedUser( dbid, job->username(), ACLRegistry::NotFound, true ); if ( acl != ACLRegistry::NotFound ) { + tDebug() << Q_FUNC_INFO << "Found existing acl entry for = " << user.knownAccountIds.first(); found = true; break; } } if ( found ) { + tDebug() << Q_FUNC_INFO << "deleting job, already have ACL for " << user.knownAccountIds.first(); delete job; QTimer::singleShot( 0, this, SLOT( queueNextJob() ) ); return; } else { + tDebug() << 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 ) ) ); diff --git a/src/libtomahawk/jobview/AclJobItem.cpp b/src/libtomahawk/jobview/AclJobItem.cpp index 45793cbf1..ea8d93f96 100644 --- a/src/libtomahawk/jobview/AclJobItem.cpp +++ b/src/libtomahawk/jobview/AclJobItem.cpp @@ -21,30 +21,31 @@ #include "JobStatusModel.h" #include "utils/TomahawkUtils.h" +#include "utils/TomahawkUtilsGui.h" +#include "libtomahawk/infosystem/InfoSystem.h" #include #include #include #include +#include -#define ROW_HEIGHT 40 +#define ROW_HEIGHT 20 #define ICON_PADDING 1 #define PADDING 2 AclJobDelegate::AclJobDelegate( QObject* parent ) : QStyledItemDelegate ( parent ) - , m_parentView( qobject_cast< QListView* >( parent ) ) { - Q_ASSERT( m_parentView ); } void AclJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { - tDebug( LOGVERBOSE ) << Q_FUNC_INFO; + //tDebug( LOGVERBOSE ) << Q_FUNC_INFO; QStyleOptionViewItemV4 opt = option; initStyleOption( &opt, index ); QFontMetrics fm( opt.font ); @@ -54,95 +55,90 @@ AclJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co painter->setRenderHint( QPainter::Antialiasing ); + painter->fillRect( opt.rect, Qt::lightGray ); + QString mainText; AclJobItem* item = dynamic_cast< AclJobItem* >( index.data( JobStatusModel::JobDataRole ).value< JobStatusItem* >() ); if ( !item ) mainText = tr( "Error displaying ACL info" ); else mainText = QString( tr( "Allow %1 to\nconnect and stream from you?" ) ).arg( item->username() ); - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Displaying text:" << mainText; + //tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Displaying text:" << mainText; const QString text = QString( tr( "Allow %1 to\nconnect and stream from you?" ) ).arg( item->username() ); - const int w = fm.width( text ); - const QRect rRect( opt.rect.left() + PADDING, ROW_HEIGHT + PADDING, opt.rect.width() - 2*PADDING, opt.rect.height() - 2*PADDING ); - painter->drawText( rRect, Qt::AlignCenter, text ); + const QRect rRect( opt.rect.left() + PADDING, opt.rect.top() + 4*PADDING, opt.rect.width() - 2*PADDING, opt.rect.height() - 2*PADDING ); + painter->drawText( rRect, Qt::AlignHCenter, text ); - -/* - QStyleOptionViewItemV4 opt = option; - initStyleOption( &opt, index ); - QFontMetrics fm( opt.font ); - const bool allowMultiLine = index.data( JobStatusModel::AllowMultiLineRole ).toBool(); + //tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Using rect " << rRect << ", opt rect is " << opt.rect; - opt.state &= ~QStyle::State_MouseOver; - QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget ); + int totalwidth = opt.rect.width(); + int thirds = totalwidth/3; + QRect btnRect; + painter->setPen( Qt::white ); + + QString btnText = tr( "Allow Streaming" ); + int btnWidth = fm.width( btnText ) + 2*PADDING; + btnRect = QRect( opt.rect.left() + thirds - btnWidth/2, opt.rect.bottom() - fm.height() - 4*PADDING, btnWidth + 2*PADDING, fm.height() + 2*PADDING ); + drawRoundedButton( painter, btnRect, btnRect.contains( m_savedHoverPos ) ); + painter->drawText( btnRect, Qt::AlignCenter, btnText ); + m_savedAcceptRect = btnRect; -// painter->drawLine( opt.rect.topLeft(), opt.rect.topRight() ); - - painter->setRenderHint( QPainter::Antialiasing ); - QRect iconRect( ICON_PADDING, ICON_PADDING + opt.rect.y(), ROW_HEIGHT - 2*ICON_PADDING, ROW_HEIGHT - 2*ICON_PADDING ); - if ( allowMultiLine ) - iconRect.moveTop( opt.rect.top() + opt.rect.height() / 2 - iconRect.height() / 2); - QPixmap p = index.data( Qt::DecorationRole ).value< QPixmap >(); - p = p.scaledToHeight( iconRect.height(), Qt::SmoothTransformation ); - painter->drawPixmap( iconRect, p ); - - // draw right column if there is one - const QString rCol = index.data( JobStatusModel::RightColumnRole ).toString(); - int rightEdge = opt.rect.right(); - if ( !rCol.isEmpty() ) - { - const int w = fm.width( rCol ); - 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(); - } - - QString mainText; - AclJobItem* item = dynamic_cast< AclJobItem* >( index.data( JobStatusModel::JobDataRole ).value< JobStatusItem* >() ); - //QString mainText = index.data( Qt::DisplayRole ).toString(); - if ( !item ) - mainText = tr( "Error displaying ACL info" ); - else - mainText = QString( tr( "Allow %1 to\nconnect and stream from you?" ) ).arg( item->username() ); - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Displaying text:" << mainText; - const int mainW = rightEdge - 3*PADDING - iconRect.right(); - QTextOption to( Qt::AlignLeft | Qt::AlignVCenter ); - if ( !allowMultiLine ) - mainText = fm.elidedText( mainText, Qt::ElideRight, mainW ); - else - to.setWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere ); - painter->drawText( QRect( iconRect.right() + 2*PADDING, PADDING + opt.rect.y(), mainW, opt.rect.height() - 2*PADDING ), mainText, to ); - */ + btnText = tr( "Deny Access" ); + btnWidth = fm.width( btnText ) + 2*PADDING; + btnRect = QRect( opt.rect.right() - thirds - btnWidth/2, opt.rect.bottom() - fm.height() - 4*PADDING, btnWidth + 2*PADDING, fm.height() + 2*PADDING ); + drawRoundedButton( painter, btnRect, btnRect.contains( m_savedHoverPos ) ); + painter->drawText( btnRect, Qt::AlignCenter, btnText ); + m_savedDenyRect = btnRect; } QSize AclJobDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const +{ + QSize size( QStyledItemDelegate::sizeHint ( option, index ).width(), ROW_HEIGHT * 3 ); + return size; +} + + +void +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) ); + else + TomahawkUtils::drawRoundedButton( painter, btnRect, QColor(206, 63, 63), QColor(170, 52, 52), QColor(150, 50, 50), QColor(130, 40, 40) ); +} + + +bool +AclJobDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO; - return QSize( QStyledItemDelegate::sizeHint ( option, index ).width(), ROW_HEIGHT ); + if ( event->type() != QEvent::MouseButtonPress && + event->type() != QEvent::MouseButtonRelease && + event->type() != QEvent::MouseButtonDblClick && + event->type() != QEvent::MouseMove ) + return false; - /* - const bool allowMultiLine = index.data( JobStatusModel::AllowMultiLineRole ).toBool(); + if ( event->type() == QEvent::MouseMove ) + { + QMouseEvent* me = static_cast< QMouseEvent* >( event ); + m_savedHoverPos = me->pos(); + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Setting position to " << m_savedHoverPos; + emit update( index ); + return true; + } - 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 ] ); + if ( event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::MouseButtonDblClick ) + { + QMouseEvent* me = static_cast< QMouseEvent* >( event ); + if ( m_savedAcceptRect.contains( me->pos() ) ) + emit aclResult( ACLRegistry::Stream ); + else if ( m_savedDenyRect.contains( me->pos() ) ) + emit aclResult( ACLRegistry::Deny ); + return true; + } - // 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 false; } @@ -167,6 +163,25 @@ AclJobItem::createDelegate( QObject* parent ) return; 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::InfoSystem::instance()->pushInfo( pushData ); +} + + +void +AclJobDelegate::emitSizeHintChanged( const QModelIndex& index ) +{ + emit sizeHintChanged( index ); +} + + +void +AclJobItem::aclResult( ACLRegistry::ACL result ) +{ + m_user.acl = result; + emit userDecision( m_user ); + done(); } diff --git a/src/libtomahawk/jobview/AclJobItem.h b/src/libtomahawk/jobview/AclJobItem.h index fd5377ca1..df6bd425a 100644 --- a/src/libtomahawk/jobview/AclJobItem.h +++ b/src/libtomahawk/jobview/AclJobItem.h @@ -38,9 +38,21 @@ public: virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; + virtual void emitSizeHintChanged( const QModelIndex &index ); + +signals: + void update( const QModelIndex& idx ); + void aclResult( ACLRegistry::ACL result ); + +protected: + virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index ); + private: - mutable QHash< QPersistentModelIndex, int > m_cachedMultiLineHeights; - QListView* m_parentView; + void drawRoundedButton( QPainter* painter, const QRect& btnRect, bool red = false ) const; + + QPoint m_savedHoverPos; + mutable QRect m_savedAcceptRect; + mutable QRect m_savedDenyRect; }; @@ -69,6 +81,9 @@ public: signals: void userDecision( ACLRegistry::User user ); + +public slots: + void aclResult( ACLRegistry::ACL result ); private: QStyledItemDelegate* m_delegate; diff --git a/src/libtomahawk/jobview/JobStatusView.cpp b/src/libtomahawk/jobview/JobStatusView.cpp index 204ae9182..a758ed28b 100644 --- a/src/libtomahawk/jobview/JobStatusView.cpp +++ b/src/libtomahawk/jobview/JobStatusView.cpp @@ -20,6 +20,7 @@ #include "JobStatusView.h" #include "Pipeline.h" +#include "AclJobItem.h" #include "JobStatusModel.h" #include "JobStatusItem.h" #include "JobStatusDelegate.h" @@ -74,6 +75,9 @@ JobStatusView::JobStatusView( AnimatedSplitter* parent ) new PipelineStatusManager( this ); new TransferStatusManager( this ); new LatchedStatusManager( this ); + + setMouseTracking( true ); + m_view->setMouseTracking( true ); } @@ -103,6 +107,13 @@ JobStatusView::customDelegateJobInserted( int row, JobStatusItem* item ) item->createDelegate( m_view ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "item delegate is " << item->customDelegate(); m_view->setItemDelegateForRow( row, item->customDelegate() ); + AclJobDelegate* delegate = qobject_cast< AclJobDelegate* >( item->customDelegate() ); + if ( delegate ) + { + connect( delegate, SIGNAL( update( const QModelIndex& ) ), m_view, SLOT( update( const QModelIndex & ) ) ); + connect( delegate, SIGNAL( aclResult( ACLRegistry::ACL ) ), item, SLOT( aclResult( ACLRegistry::ACL ) ) ); + delegate->emitSizeHintChanged( m_model->index( row ) ); + } } diff --git a/src/libtomahawk/network/Servent.cpp b/src/libtomahawk/network/Servent.cpp index f1f29b018..323a99016 100644 --- a/src/libtomahawk/network/Servent.cpp +++ b/src/libtomahawk/network/Servent.cpp @@ -536,6 +536,8 @@ Servent::connectToPeer( const QString& ha, int port, const QString &key, const Q if( id.length() ) conn->setId( id ); + conn->setProperty( "nodeid", id ); + connectToPeer( ha, port, key, conn ); } diff --git a/src/libtomahawk/utils/TomahawkUtilsGui.cpp b/src/libtomahawk/utils/TomahawkUtilsGui.cpp index 5e9f5478d..9c9ede8f4 100644 --- a/src/libtomahawk/utils/TomahawkUtilsGui.cpp +++ b/src/libtomahawk/utils/TomahawkUtilsGui.cpp @@ -414,4 +414,54 @@ prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, Tr } } + +void +drawRoundedButton( QPainter* painter, const QRect& btnRect, const QColor& color, const QColor &gradient1bottom, const QColor& gradient2top, const QColor& gradient2bottom ) +{ + QPainterPath btnPath; + const int radius = 3; + // draw top half gradient + const int btnCenter = btnRect.bottom() - ( btnRect.height() / 2 ); + btnPath.moveTo( btnRect.left(), btnCenter ); + btnPath.lineTo( btnRect.left(), btnRect.top() + radius ); + btnPath.quadTo( QPoint( btnRect.topLeft() ), QPoint( btnRect.left() + radius, btnRect.top() ) ); + btnPath.lineTo( btnRect.right() - radius, btnRect.top() ); + btnPath.quadTo( QPoint( btnRect.topRight() ), QPoint( btnRect.right(), btnRect.top() + radius ) ); + btnPath.lineTo( btnRect.right(),btnCenter ); + btnPath.lineTo( btnRect.left(), btnCenter ); + + QLinearGradient g; + if ( gradient1bottom.isValid() ) + { + g.setColorAt( 0, color ); + g.setColorAt( 0.5, gradient1bottom ); + painter->fillPath( btnPath, g ); + } + else + painter->fillPath( btnPath, color ); + //painter->setPen( bg.darker() ); + + //painter->drawPath( btnPath ); + + btnPath = QPainterPath(); + btnPath.moveTo( btnRect.left(), btnCenter ); + btnPath.lineTo( btnRect.left(), btnRect.bottom() - radius ); + btnPath.quadTo( QPoint( btnRect.bottomLeft() ), QPoint( btnRect.left() + radius, btnRect.bottom() ) ); + btnPath.lineTo( btnRect.right() - radius, btnRect.bottom() ); + btnPath.quadTo( QPoint( btnRect.bottomRight() ), QPoint( btnRect.right(), btnRect.bottom() - radius ) ); + btnPath.lineTo( btnRect.right(), btnCenter ); + btnPath.lineTo( btnRect.left(), btnCenter ); + + if ( gradient2top.isValid() && gradient2bottom.isValid() ) + { + g.setColorAt( 0, gradient2top ); + g.setColorAt( 0.5, gradient2bottom ); + painter->fillPath( btnPath, g ); + } + else + painter->fillPath( btnPath, color ); + +} + + } // ns diff --git a/src/libtomahawk/utils/TomahawkUtilsGui.h b/src/libtomahawk/utils/TomahawkUtilsGui.h index 48f03cb2f..475f64ba1 100644 --- a/src/libtomahawk/utils/TomahawkUtilsGui.h +++ b/src/libtomahawk/utils/TomahawkUtilsGui.h @@ -22,6 +22,8 @@ #include #include +#include +#include #include "TomahawkUtils.h" #include "DllMacro.h" @@ -29,11 +31,9 @@ class TrackModelItem; class QStyleOptionViewItemV4; class QPainter; -class QColor; class QPixmap; class QLayout; class QPalette; -class QRect; namespace TomahawkUtils { @@ -57,6 +57,7 @@ namespace TomahawkUtils DLLEXPORT void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, TrackModelItem* item ); + DLLEXPORT void drawRoundedButton( QPainter* painter, const QRect& btnRect, const QColor& color, const QColor &gradient1bottom = QColor(), const QColor& gradient2top = QColor(), const QColor& gradient2bottom = QColor() ); } #endif // TOMAHAWKUTILSGUI_H From 261aa7b6775268815c9b22067f6e853dc6d4090f Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sun, 22 Apr 2012 16:05:14 -0400 Subject: [PATCH 02/18] W. T. F. Why can my simple struct no longer be serialized by QVariant. Even adding destructor/copy constructor didn't help. --- src/libtomahawk/AclRegistry.cpp | 12 ++++++++++-- src/libtomahawk/AclRegistry.h | 14 +++++++++++++- src/libtomahawk/TomahawkSettings.cpp | 3 +++ src/libtomahawk/jobview/AclJobItem.cpp | 4 ++-- src/libtomahawk/jobview/JobStatusDelegate.cpp | 7 +++++-- src/libtomahawk/jobview/JobStatusView.cpp | 5 ++++- src/libtomahawk/jobview/JobStatusView.h | 1 + 7 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/libtomahawk/AclRegistry.cpp b/src/libtomahawk/AclRegistry.cpp index 3f9b40303..8171a664f 100644 --- a/src/libtomahawk/AclRegistry.cpp +++ b/src/libtomahawk/AclRegistry.cpp @@ -49,7 +49,6 @@ ACLRegistry::ACLRegistry( QObject* parent ) s_instance = this; qRegisterMetaType< ACLRegistry::ACL >( "ACLRegistry::ACL" ); qRegisterMetaType< ACLRegistry::User >( "ACLRegistry::User" ); - load(); } @@ -62,13 +61,14 @@ ACLRegistry::~ACLRegistry() ACLRegistry::ACL ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACLRegistry::ACL globalType, bool skipEmission ) { + tDebug() << 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; } - + tDebug() << Q_FUNC_INFO << "in right thread"; //FIXME: Remove when things are working // emit aclResult( dbid, username, ACLRegistry::Stream ); // return ACLRegistry::NotFound; @@ -133,6 +133,7 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL void ACLRegistry::getUserDecision( ACLRegistry::User user, const QString &username ) { + tDebug() << Q_FUNC_INFO; AclJobItem* job = new AclJobItem( user, username ); m_jobQueue.enqueue( job ); queueNextJob(); @@ -143,6 +144,7 @@ ACLRegistry::getUserDecision( ACLRegistry::User user, const QString &username ) void ACLRegistry::userDecision( ACLRegistry::User user ) { + tDebug() << Q_FUNC_INFO; m_cache.append( user ); save(); emit aclResult( user.knownDbids.first(), user.knownAccountIds.first(), user.acl ); @@ -197,11 +199,13 @@ ACLRegistry::queueNextJob() void ACLRegistry::load() { + tDebug() << Q_FUNC_INFO; QVariantList entryList = TomahawkSettings::instance()->aclEntries(); foreach ( QVariant entry, entryList ) { if ( !entry.isValid() || !entry.canConvert< ACLRegistry::User >() ) continue; + tDebug() << Q_FUNC_INFO << "loading entry"; ACLRegistry::User entryUser = entry.value< ACLRegistry::User >(); m_cache.append( entryUser ); } @@ -211,8 +215,12 @@ ACLRegistry::load() void ACLRegistry::save() { + tDebug() << Q_FUNC_INFO; QVariantList entryList; foreach ( ACLRegistry::User user, m_cache ) + { + tDebug() << Q_FUNC_INFO << "user is " << user.uuid << " with known name " << user.knownAccountIds.first(); entryList.append( QVariant::fromValue< ACLRegistry::User >( user ) ); + } TomahawkSettings::instance()->setAclEntries( entryList ); } \ No newline at end of file diff --git a/src/libtomahawk/AclRegistry.h b/src/libtomahawk/AclRegistry.h index 1530a843f..96e655e6f 100644 --- a/src/libtomahawk/AclRegistry.h +++ b/src/libtomahawk/AclRegistry.h @@ -55,15 +55,27 @@ public: User() : uuid( QUuid::createUuid().toString() ) + , knownDbids() + , knownAccountIds() , acl( ACLRegistry::NotFound ) {} - User( QString p_uuid, QStringList p_knownDbids, QStringList p_knownAccountIds, ACL p_acl ) + ~User() + {} + + User( QString p_uuid, QStringList p_knownDbids, QStringList p_knownAccountIds, ACLRegistry::ACL p_acl ) : uuid( p_uuid ) , knownDbids( p_knownDbids ) , knownAccountIds( p_knownAccountIds ) , acl( p_acl ) {} + + User( const User &other ) + : uuid( other.uuid ) + , knownDbids( other.knownDbids ) + , knownAccountIds( other.knownAccountIds ) + , acl( other.acl ) + {} }; ACLRegistry( QObject *parent = 0 ); diff --git a/src/libtomahawk/TomahawkSettings.cpp b/src/libtomahawk/TomahawkSettings.cpp index 66bea27b5..938558f6c 100644 --- a/src/libtomahawk/TomahawkSettings.cpp +++ b/src/libtomahawk/TomahawkSettings.cpp @@ -642,7 +642,10 @@ TomahawkSettings::aclEntries() const void TomahawkSettings::setAclEntries( const QVariantList &entries ) { + tDebug() << "Setting entries"; setValue( "acl/entries", entries ); + sync(); + tDebug() << "Done setting entries"; } diff --git a/src/libtomahawk/jobview/AclJobItem.cpp b/src/libtomahawk/jobview/AclJobItem.cpp index ea8d93f96..0aebf8137 100644 --- a/src/libtomahawk/jobview/AclJobItem.cpp +++ b/src/libtomahawk/jobview/AclJobItem.cpp @@ -112,7 +112,7 @@ AclJobDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect, bool bool AclJobDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index ) { - tDebug( LOGVERBOSE ) << Q_FUNC_INFO; + //tDebug( LOGVERBOSE ) << Q_FUNC_INFO; if ( event->type() != QEvent::MouseButtonPress && event->type() != QEvent::MouseButtonRelease && event->type() != QEvent::MouseButtonDblClick && @@ -123,7 +123,7 @@ AclJobDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QSt { QMouseEvent* me = static_cast< QMouseEvent* >( event ); m_savedHoverPos = me->pos(); - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Setting position to " << m_savedHoverPos; + //tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Setting position to " << m_savedHoverPos; emit update( index ); return true; } diff --git a/src/libtomahawk/jobview/JobStatusDelegate.cpp b/src/libtomahawk/jobview/JobStatusDelegate.cpp index cf07b6b92..e78e53837 100644 --- a/src/libtomahawk/jobview/JobStatusDelegate.cpp +++ b/src/libtomahawk/jobview/JobStatusDelegate.cpp @@ -59,8 +59,11 @@ JobStatusDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, if ( allowMultiLine ) iconRect.moveTop( opt.rect.top() + opt.rect.height() / 2 - iconRect.height() / 2); QPixmap p = index.data( Qt::DecorationRole ).value< QPixmap >(); - p = p.scaledToHeight( iconRect.height(), Qt::SmoothTransformation ); - painter->drawPixmap( iconRect, p ); + if ( !p.isNull() ) + { + p = p.scaledToHeight( iconRect.height(), Qt::SmoothTransformation ); + painter->drawPixmap( iconRect, p ); + } // draw right column if there is one const QString rCol = index.data( JobStatusModel::RightColumnRole ).toString(); diff --git a/src/libtomahawk/jobview/JobStatusView.cpp b/src/libtomahawk/jobview/JobStatusView.cpp index a758ed28b..35bc801b8 100644 --- a/src/libtomahawk/jobview/JobStatusView.cpp +++ b/src/libtomahawk/jobview/JobStatusView.cpp @@ -107,6 +107,7 @@ JobStatusView::customDelegateJobInserted( int row, JobStatusItem* item ) item->createDelegate( m_view ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "item delegate is " << item->customDelegate(); m_view->setItemDelegateForRow( row, item->customDelegate() ); + m_customDelegateRefCounter[ row ] = m_customDelegateRefCounter[ row ] + 1; AclJobDelegate* delegate = qobject_cast< AclJobDelegate* >( item->customDelegate() ); if ( delegate ) { @@ -120,7 +121,9 @@ JobStatusView::customDelegateJobInserted( int row, JobStatusItem* item ) void JobStatusView::customDelegateJobRemoved( int row ) { - m_view->setItemDelegateForRow( row, m_view->itemDelegate() ); + if ( m_customDelegateRefCounter[ row ] == 1 ) + m_view->setItemDelegateForRow( row, m_view->itemDelegate() ); + m_customDelegateRefCounter[ row ] = m_customDelegateRefCounter[ row ] - 1; } diff --git a/src/libtomahawk/jobview/JobStatusView.h b/src/libtomahawk/jobview/JobStatusView.h index 1a5edf665..43b5a398a 100644 --- a/src/libtomahawk/jobview/JobStatusView.h +++ b/src/libtomahawk/jobview/JobStatusView.h @@ -61,6 +61,7 @@ private: JobStatusModel* m_model; AnimatedSplitter* m_parent; mutable int m_cachedHeight; + QHash< int, int > m_customDelegateRefCounter; static JobStatusView* s_instance; }; From 456d6f74bbecb42a4279e79b1674e66f5296cd14 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sun, 22 Apr 2012 16:57:50 -0400 Subject: [PATCH 03/18] Fix invalid variant conversion; need to make sure it's actually working properly, though --- src/libtomahawk/AclRegistry.cpp | 38 +++++++++++++++++++++++++++++++++ src/libtomahawk/AclRegistry.h | 4 +++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/AclRegistry.cpp b/src/libtomahawk/AclRegistry.cpp index 8171a664f..e7161bd23 100644 --- a/src/libtomahawk/AclRegistry.cpp +++ b/src/libtomahawk/AclRegistry.cpp @@ -31,6 +31,43 @@ #include "jobview/JobStatusModel.h" +QDataStream& operator<<( QDataStream &out, const ACLRegistry::User &user ) +{ + out << ACLUSERVERSION; + out << user.uuid; + out << user.knownDbids.length(); + foreach( QString knownDbid, user.knownDbids ) + out << knownDbid; + out << user.knownAccountIds.length(); + foreach( QString knownAccount, user.knownAccountIds ) + out << user.knownAccountIds; + out << (int)( user.acl ); + return out; +} + +QDataStream& operator>>( QDataStream &in, ACLRegistry::User &user ) +{ + int ver; + in >> ver; + if ( ver == ACLUSERVERSION ) + { + in >> user.uuid; + int dbidsLength; + in >> dbidsLength; + for ( int i = 0; i < dbidsLength; i++ ) + in >> user.knownDbids; + int accountsLength; + in >> accountsLength; + for ( int i = 0; i < accountsLength; i++ ) + in >> user.knownAccountIds; + int aclIn; + in >> aclIn; + user.acl = (ACLRegistry::ACL)( aclIn ); + } + return in; +} + + ACLRegistry* ACLRegistry::s_instance = 0; ACLRegistry* @@ -49,6 +86,7 @@ ACLRegistry::ACLRegistry( QObject* parent ) s_instance = this; qRegisterMetaType< ACLRegistry::ACL >( "ACLRegistry::ACL" ); qRegisterMetaType< ACLRegistry::User >( "ACLRegistry::User" ); + qRegisterMetaTypeStreamOperators< ACLRegistry::User >( "ACLRegistry::User" ); load(); } diff --git a/src/libtomahawk/AclRegistry.h b/src/libtomahawk/AclRegistry.h index 96e655e6f..c6e61211a 100644 --- a/src/libtomahawk/AclRegistry.h +++ b/src/libtomahawk/AclRegistry.h @@ -30,6 +30,8 @@ #include "HeadlessCheck.h" #include "DllMacro.h" +#define ACLUSERVERSION 1 + class AclJobItem; class DLLEXPORT ACLRegistry : public QObject @@ -51,7 +53,7 @@ public: QString uuid; QStringList knownDbids; QStringList knownAccountIds; - ACL acl; + ACLRegistry::ACL acl; User() : uuid( QUuid::createUuid().toString() ) From a36693bd4c2186db7e9907f192b70095bcd59935 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sat, 19 May 2012 17:40:53 -0400 Subject: [PATCH 04/18] Fix merge --- src/libtomahawk/AclRegistry.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libtomahawk/AclRegistry.cpp b/src/libtomahawk/AclRegistry.cpp index be8a5bbd3..f1554ede2 100644 --- a/src/libtomahawk/AclRegistry.cpp +++ b/src/libtomahawk/AclRegistry.cpp @@ -200,10 +200,7 @@ ACLRegistry::queueNextJob() if ( m_jobCount != 0 ) return; -<<<<<<< HEAD tDebug() << Q_FUNC_INFO << "jobQueue size = " << m_jobQueue.length(); -======= ->>>>>>> master if ( !m_jobQueue.isEmpty() ) { AclJobItem* job = m_jobQueue.dequeue(); From 067138b9ac0f77f4ac0390c143623dddc0837a2a Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sat, 19 May 2012 18:25:10 -0400 Subject: [PATCH 05/18] Update view sizehint when we get a custom delegate in case it is non-standard in height --- src/libtomahawk/jobview/JobStatusView.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libtomahawk/jobview/JobStatusView.cpp b/src/libtomahawk/jobview/JobStatusView.cpp index fd1784a02..4555ae73f 100644 --- a/src/libtomahawk/jobview/JobStatusView.cpp +++ b/src/libtomahawk/jobview/JobStatusView.cpp @@ -116,6 +116,8 @@ JobStatusView::customDelegateJobInserted( int row, JobStatusItem* item ) connect( delegate, SIGNAL( aclResult( ACLRegistry::ACL ) ), item, SLOT( aclResult( ACLRegistry::ACL ) ) ); delegate->emitSizeHintChanged( m_model->index( row ) ); } + + checkCount(); } @@ -125,6 +127,8 @@ JobStatusView::customDelegateJobRemoved( int row ) if ( m_customDelegateRefCounter[ row ] == 1 ) m_view->setItemDelegateForRow( row, m_view->itemDelegate() ); m_customDelegateRefCounter[ row ] = m_customDelegateRefCounter[ row ] - 1; + + checkCount(); } From 805a942cf627f0c9650c125103344491d66cfdff Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Fri, 15 Jun 2012 14:32:01 -0400 Subject: [PATCH 06/18] Fix possible crash due to saving invalid qvariants --- src/libtomahawk/AclRegistry.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/AclRegistry.cpp b/src/libtomahawk/AclRegistry.cpp index 2adbe3683..7330d0468 100644 --- a/src/libtomahawk/AclRegistry.cpp +++ b/src/libtomahawk/AclRegistry.cpp @@ -264,7 +264,9 @@ ACLRegistry::save() foreach ( ACLRegistry::User user, m_cache ) { tDebug() << Q_FUNC_INFO << "user is " << user.uuid << " with known name " << user.knownAccountIds.first(); - entryList.append( QVariant::fromValue< ACLRegistry::User >( user ) ); + QVariant val = QVariant::fromValue< ACLRegistry::User >( user ); + if ( val.isValid() ) + entryList.append( val ); } TomahawkSettings::instance()->setAclEntries( entryList ); } From 285498d63803f640371b7bc54f2f16350f89dbe7 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Fri, 15 Jun 2012 14:35:57 -0400 Subject: [PATCH 07/18] Fix half-baked fix --- src/libtomahawk/jobview/AclJobItem.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libtomahawk/jobview/AclJobItem.cpp b/src/libtomahawk/jobview/AclJobItem.cpp index ab8f14879..b46232657 100644 --- a/src/libtomahawk/jobview/AclJobItem.cpp +++ b/src/libtomahawk/jobview/AclJobItem.cpp @@ -66,9 +66,8 @@ AclJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co mainText = QString( tr( "Allow %1 to\nconnect and stream from you?" ) ).arg( item->username() ); //tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Displaying text:" << mainText; - const QString text = QString( tr( "Allow %1 to\nconnect and stream from you?" ) ).arg( item->username() ); const QRect rRect( opt.rect.left() + PADDING, opt.rect.top() + 4*PADDING, opt.rect.width() - 2*PADDING, opt.rect.height() - 2*PADDING ); - painter->drawText( rRect, Qt::AlignHCenter, text ); + painter->drawText( rRect, Qt::AlignHCenter, mainText ); //tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Using rect " << rRect << ", opt rect is " << opt.rect; From 10bb33590bd951770d342a0d52b8755adc4a1e19 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Fri, 15 Jun 2012 15:01:30 -0400 Subject: [PATCH 08/18] Fix crash from loading invalid entries from cache --- src/libtomahawk/AclRegistry.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libtomahawk/AclRegistry.cpp b/src/libtomahawk/AclRegistry.cpp index 7330d0468..66132a629 100644 --- a/src/libtomahawk/AclRegistry.cpp +++ b/src/libtomahawk/AclRegistry.cpp @@ -251,6 +251,8 @@ ACLRegistry::load() continue; tDebug() << Q_FUNC_INFO << "loading entry"; ACLRegistry::User entryUser = entry.value< ACLRegistry::User >(); + if ( entryUser.knownAccountIds.empty() || entryUser.knownDbids.empty() ) + continue; m_cache.append( entryUser ); } } From 554cb5d7a125e68adf6b9d158d824e6708b47073 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sun, 17 Jun 2012 18:52:07 -0400 Subject: [PATCH 09/18] Properly handle delegates so that a) we don't crash and b) we actually show the proper delegates for items when there are more than two in the queue. This pretty much makes the job view stuff fully work, except somehow saving got broken. --- src/libtomahawk/AclRegistry.cpp | 35 ++++++++++++---------- src/libtomahawk/jobview/AclJobItem.cpp | 20 ++++++++----- src/libtomahawk/jobview/AclJobItem.h | 4 +-- src/libtomahawk/jobview/JobStatusModel.cpp | 9 ++++-- src/libtomahawk/jobview/JobStatusView.cpp | 31 ++++++++++++++----- src/libtomahawk/jobview/JobStatusView.h | 1 - 6 files changed, 65 insertions(+), 35 deletions(-) diff --git a/src/libtomahawk/AclRegistry.cpp b/src/libtomahawk/AclRegistry.cpp index 66132a629..09e63cdc2 100644 --- a/src/libtomahawk/AclRegistry.cpp +++ b/src/libtomahawk/AclRegistry.cpp @@ -103,14 +103,14 @@ ACLRegistry::~ACLRegistry() ACLRegistry::ACL ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACLRegistry::ACL globalType, bool skipEmission ) { - tDebug() << Q_FUNC_INFO; + 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; } - tDebug() << Q_FUNC_INFO << "in right thread"; + tLog() << Q_FUNC_INFO << "in right thread"; //FIXME: Remove when things are working // emit aclResult( dbid, username, ACLRegistry::Stream ); // return ACLRegistry::NotFound; @@ -176,35 +176,40 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL void ACLRegistry::getUserDecision( ACLRegistry::User user, const QString &username ) { - tDebug() << Q_FUNC_INFO; + tLog() << Q_FUNC_INFO; AclJobItem* job = new AclJobItem( user, username ); m_jobQueue.enqueue( job ); - queueNextJob(); + QTimer::singleShot( 0, this, SLOT( queueNextJob() ) ); } void ACLRegistry::userDecision( ACLRegistry::User user ) { - tDebug() << Q_FUNC_INFO; + tLog() << Q_FUNC_INFO; m_cache.append( user ); save(); emit aclResult( user.knownDbids.first(), user.knownAccountIds.first(), user.acl ); m_jobCount--; if ( !m_jobQueue.isEmpty() ) - queueNextJob(); + QTimer::singleShot( 0, this, SLOT( queueNextJob() ) ); } void ACLRegistry::queueNextJob() { - tDebug() << Q_FUNC_INFO << "jobCount = " << m_jobCount; + if ( QThread::currentThread() != TOMAHAWK_APPLICATION::instance()->thread() ) + { + QMetaObject::invokeMethod( this, "queueNextJob", Qt::QueuedConnection ); + return; + } + tLog() << Q_FUNC_INFO << "jobCount = " << m_jobCount; + tLog() << Q_FUNC_INFO << "jobQueue size = " << m_jobQueue.length(); if ( m_jobCount != 0 ) return; - tDebug() << Q_FUNC_INFO << "jobQueue size = " << m_jobQueue.length(); if ( !m_jobQueue.isEmpty() ) { AclJobItem* job = m_jobQueue.dequeue(); @@ -215,21 +220,21 @@ ACLRegistry::queueNextJob() ACLRegistry::ACL acl = isAuthorizedUser( dbid, job->username(), ACLRegistry::NotFound, true ); if ( acl != ACLRegistry::NotFound ) { - tDebug() << Q_FUNC_INFO << "Found existing acl entry for = " << user.knownAccountIds.first(); + tLog() << Q_FUNC_INFO << "Found existing acl entry for = " << user.knownAccountIds.first(); found = true; break; } } if ( found ) { - tDebug() << Q_FUNC_INFO << "deleting job, already have ACL for " << user.knownAccountIds.first(); + tLog() << Q_FUNC_INFO << "deleting job, already have ACL for " << user.knownAccountIds.first(); delete job; QTimer::singleShot( 0, this, SLOT( queueNextJob() ) ); return; } else { - tDebug() << Q_FUNC_INFO << "activating job for user" << user.knownAccountIds.first(); + 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 ) ) ); @@ -243,13 +248,13 @@ ACLRegistry::queueNextJob() void ACLRegistry::load() { - tDebug() << Q_FUNC_INFO; + tLog() << Q_FUNC_INFO; QVariantList entryList = TomahawkSettings::instance()->aclEntries(); foreach ( QVariant entry, entryList ) { if ( !entry.isValid() || !entry.canConvert< ACLRegistry::User >() ) continue; - tDebug() << Q_FUNC_INFO << "loading entry"; + tLog() << Q_FUNC_INFO << "loading entry"; ACLRegistry::User entryUser = entry.value< ACLRegistry::User >(); if ( entryUser.knownAccountIds.empty() || entryUser.knownDbids.empty() ) continue; @@ -261,11 +266,11 @@ ACLRegistry::load() void ACLRegistry::save() { - tDebug() << Q_FUNC_INFO; + tLog() << Q_FUNC_INFO; QVariantList entryList; foreach ( ACLRegistry::User user, m_cache ) { - tDebug() << Q_FUNC_INFO << "user is " << user.uuid << " with known name " << user.knownAccountIds.first(); + 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 ); diff --git a/src/libtomahawk/jobview/AclJobItem.cpp b/src/libtomahawk/jobview/AclJobItem.cpp index b46232657..12a46bab1 100644 --- a/src/libtomahawk/jobview/AclJobItem.cpp +++ b/src/libtomahawk/jobview/AclJobItem.cpp @@ -40,6 +40,13 @@ AclJobDelegate::AclJobDelegate( QObject* parent ) : QStyledItemDelegate ( parent ) { + tLog() << Q_FUNC_INFO; +} + + +AclJobDelegate::~AclJobDelegate() +{ + tLog() << Q_FUNC_INFO; } @@ -148,17 +155,22 @@ AclJobItem::AclJobItem( ACLRegistry::User user, const QString &username ) , m_user( user ) , m_username( username ) { + tLog() << Q_FUNC_INFO; } AclJobItem::~AclJobItem() { + tLog() << Q_FUNC_INFO; + if ( m_delegate ) + delete m_delegate; } void AclJobItem::createDelegate( QObject* parent ) { + tLog() << Q_FUNC_INFO; if ( m_delegate ) return; @@ -179,15 +191,9 @@ AclJobDelegate::emitSizeHintChanged( const QModelIndex& index ) void AclJobItem::aclResult( ACLRegistry::ACL result ) { + tLog() << Q_FUNC_INFO; m_user.acl = result; emit userDecision( m_user ); - done(); -} - - -void -AclJobItem::done() -{ emit finished(); } diff --git a/src/libtomahawk/jobview/AclJobItem.h b/src/libtomahawk/jobview/AclJobItem.h index df6bd425a..d258ed1f3 100644 --- a/src/libtomahawk/jobview/AclJobItem.h +++ b/src/libtomahawk/jobview/AclJobItem.h @@ -33,7 +33,7 @@ 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; @@ -63,8 +63,6 @@ public: explicit AclJobItem( ACLRegistry::User user, const QString &username ); virtual ~AclJobItem(); - void done(); - virtual QString rightColumnText() const { return QString(); } virtual QString mainText() const { return QString(); } virtual QPixmap icon() const { return QPixmap(); } diff --git a/src/libtomahawk/jobview/JobStatusModel.cpp b/src/libtomahawk/jobview/JobStatusModel.cpp index e3ec86e9a..28e1ce36c 100644 --- a/src/libtomahawk/jobview/JobStatusModel.cpp +++ b/src/libtomahawk/jobview/JobStatusModel.cpp @@ -41,6 +41,7 @@ JobStatusModel::~JobStatusModel() void JobStatusModel::addJob( JobStatusItem* item ) { + tLog() << Q_FUNC_INFO << "current jobs of item type: " << m_jobTypeCount[ item->type() ] << ", current queue size of item type: " << m_jobQueue[ item->type() ].size(); if ( item->concurrentJobLimit() > 0 ) { if ( m_jobTypeCount[ item->type() ] >= item->concurrentJobLimit() ) @@ -53,6 +54,8 @@ JobStatusModel::addJob( JobStatusItem* item ) m_jobTypeCount[ item->type() ] = currentJobCount; } + tLog() << Q_FUNC_INFO << "new current jobs of item type: " << m_jobTypeCount[ item->type() ]; + connect( item, SIGNAL( statusChanged() ), SLOT( itemUpdated() ) ); connect( item, SIGNAL( finished() ), SLOT( itemFinished() ) ); @@ -70,7 +73,7 @@ JobStatusModel::addJob( JobStatusItem* item ) } } - qDebug() << "Adding item:" << item; + tLog() << Q_FUNC_INFO << "Adding item:" << item; int currentEndRow = m_items.count(); beginInsertRows( QModelIndex(), currentEndRow, currentEndRow ); @@ -79,7 +82,7 @@ JobStatusModel::addJob( JobStatusItem* item ) if ( item->hasCustomDelegate() ) { - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "job has custom delegate"; + tLog() << Q_FUNC_INFO << "job has custom delegate"; emit customDelegateJobInserted( currentEndRow, item ); } } @@ -200,6 +203,8 @@ JobStatusModel::itemFinished() if ( item->customDelegate() ) emit customDelegateJobRemoved( idx ); + + tLog() << Q_FUNC_INFO << "current jobs of item type: " << m_jobTypeCount[ item->type() ] << ", current queue size of item type: " << m_jobQueue[ item->type() ].size(); if ( item->concurrentJobLimit() > 0 ) { int currentJobs = m_jobTypeCount[ item->type() ]; diff --git a/src/libtomahawk/jobview/JobStatusView.cpp b/src/libtomahawk/jobview/JobStatusView.cpp index 4555ae73f..393b47ba3 100644 --- a/src/libtomahawk/jobview/JobStatusView.cpp +++ b/src/libtomahawk/jobview/JobStatusView.cpp @@ -100,22 +100,24 @@ JobStatusView::setModel( JobStatusModel* m ) void JobStatusView::customDelegateJobInserted( int row, JobStatusItem* item ) { - tDebug( LOGVERBOSE ) << Q_FUNC_INFO; + tLog() << Q_FUNC_INFO << "item is " << item << ", row is " << row; if ( !item ) return; - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "telling item to create delegate"; + tLog() << Q_FUNC_INFO << "telling item to create delegate"; item->createDelegate( m_view ); - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "item delegate is " << item->customDelegate(); + tLog() << Q_FUNC_INFO << "item delegate is " << item->customDelegate(); m_view->setItemDelegateForRow( row, item->customDelegate() ); - m_customDelegateRefCounter[ row ] = m_customDelegateRefCounter[ row ] + 1; 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 ) ) ); delegate->emitSizeHintChanged( m_model->index( row ) ); } + else + tLog() << Q_FUNC_INFO << "delegate was not properly found!"; checkCount(); } @@ -124,9 +126,24 @@ JobStatusView::customDelegateJobInserted( int row, JobStatusItem* item ) void JobStatusView::customDelegateJobRemoved( int row ) { - if ( m_customDelegateRefCounter[ row ] == 1 ) - m_view->setItemDelegateForRow( row, m_view->itemDelegate() ); - m_customDelegateRefCounter[ row ] = m_customDelegateRefCounter[ row ] - 1; + tLog() << Q_FUNC_INFO << "row is " << row; + int count = m_model->rowCount(); + for ( int i = 0; i < count; i++ ) + { + tLog() << Q_FUNC_INFO << "checking row " << i; + QModelIndex index = m_model->index( i ); + QVariant itemVar = index.data( JobStatusModel::JobDataRole ); + if ( !itemVar.canConvert< JobStatusItem* >() || !itemVar.value< JobStatusItem* >() ) + { + tLog() << Q_FUNC_INFO << "unable to fetch JobStatusItem* at row " << i; + continue; + } + JobStatusItem* item = itemVar.value< JobStatusItem* >(); + if ( item->hasCustomDelegate() ) + m_view->setItemDelegateForRow( i, item->customDelegate() ); + else + m_view->setItemDelegateForRow( i, m_view->itemDelegate() ); + } checkCount(); } diff --git a/src/libtomahawk/jobview/JobStatusView.h b/src/libtomahawk/jobview/JobStatusView.h index 43b5a398a..1a5edf665 100644 --- a/src/libtomahawk/jobview/JobStatusView.h +++ b/src/libtomahawk/jobview/JobStatusView.h @@ -61,7 +61,6 @@ private: JobStatusModel* m_model; AnimatedSplitter* m_parent; mutable int m_cachedHeight; - QHash< int, int > m_customDelegateRefCounter; static JobStatusView* s_instance; }; From 259e4f3da9b0430a42e7b0cbf2851152e9db3a92 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sun, 17 Jun 2012 22:24:49 -0400 Subject: [PATCH 10/18] Fix ACL saving/loading --- src/libtomahawk/AclRegistry.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/libtomahawk/AclRegistry.cpp b/src/libtomahawk/AclRegistry.cpp index 09e63cdc2..dedd8bc25 100644 --- a/src/libtomahawk/AclRegistry.cpp +++ b/src/libtomahawk/AclRegistry.cpp @@ -44,7 +44,7 @@ QDataStream& operator<<( QDataStream &out, const ACLRegistry::User &user ) out << knownDbid; out << user.knownAccountIds.length(); foreach( QString knownAccount, user.knownAccountIds ) - out << user.knownAccountIds; + out << knownAccount; out << (int)( user.acl ); return out; } @@ -58,12 +58,20 @@ QDataStream& operator>>( QDataStream &in, ACLRegistry::User &user ) in >> user.uuid; int dbidsLength; in >> dbidsLength; + QString knownDbid; for ( int i = 0; i < dbidsLength; i++ ) - in >> user.knownDbids; + { + in >> knownDbid; + user.knownDbids << knownDbid; + } int accountsLength; in >> accountsLength; + QString knownAccountId; for ( int i = 0; i < accountsLength; i++ ) - in >> user.knownAccountIds; + { + in >> knownAccountId; + user.knownAccountIds << knownAccountId; + } int aclIn; in >> aclIn; user.acl = (ACLRegistry::ACL)( aclIn ); @@ -253,11 +261,17 @@ ACLRegistry::load() 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 ); } } From 4f1579274e5611f111ced93d8b04bf0676d2c16c Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sun, 17 Jun 2012 23:10:06 -0400 Subject: [PATCH 11/18] Always refresh delegates on item finish, not just when that item had a custom delegate, in case it's switched rows --- src/libtomahawk/jobview/JobStatusModel.cpp | 2 ++ src/libtomahawk/jobview/JobStatusModel.h | 1 + src/libtomahawk/jobview/JobStatusView.cpp | 8 ++++++++ src/libtomahawk/jobview/JobStatusView.h | 1 + 4 files changed, 12 insertions(+) diff --git a/src/libtomahawk/jobview/JobStatusModel.cpp b/src/libtomahawk/jobview/JobStatusModel.cpp index 28e1ce36c..08df1b614 100644 --- a/src/libtomahawk/jobview/JobStatusModel.cpp +++ b/src/libtomahawk/jobview/JobStatusModel.cpp @@ -187,6 +187,7 @@ JobStatusModel::itemFinished() // One less to count, but item is still there const QModelIndex idx = index( indexOf, 0, QModelIndex() ); emit dataChanged( idx, idx ); + emit refreshDelegates(); return; } } @@ -203,6 +204,7 @@ JobStatusModel::itemFinished() if ( item->customDelegate() ) emit customDelegateJobRemoved( idx ); + emit refreshDelegates(); tLog() << Q_FUNC_INFO << "current jobs of item type: " << m_jobTypeCount[ item->type() ] << ", current queue size of item type: " << m_jobQueue[ item->type() ].size(); if ( item->concurrentJobLimit() > 0 ) diff --git a/src/libtomahawk/jobview/JobStatusModel.h b/src/libtomahawk/jobview/JobStatusModel.h index ff4d19b83..7db63267f 100644 --- a/src/libtomahawk/jobview/JobStatusModel.h +++ b/src/libtomahawk/jobview/JobStatusModel.h @@ -49,6 +49,7 @@ public: signals: void customDelegateJobInserted( int row, JobStatusItem* item ); void customDelegateJobRemoved( int row ); + void refreshDelegates(); public slots: /// Takes ownership of job diff --git a/src/libtomahawk/jobview/JobStatusView.cpp b/src/libtomahawk/jobview/JobStatusView.cpp index 393b47ba3..8b29013fe 100644 --- a/src/libtomahawk/jobview/JobStatusView.cpp +++ b/src/libtomahawk/jobview/JobStatusView.cpp @@ -94,6 +94,7 @@ JobStatusView::setModel( JobStatusModel* m ) connect( m_view->model(), SIGNAL( modelReset() ), this, SLOT( checkCount() ) ); connect( m_view->model(), SIGNAL( customDelegateJobInserted( int, JobStatusItem* ) ), this, SLOT( customDelegateJobInserted( int, JobStatusItem* ) ) ); connect( m_view->model(), SIGNAL( customDelegateJobRemoved( int ) ), this, SLOT( customDelegateJobRemoved( int ) ) ); + connect( m_view->model(), SIGNAL( refreshDelegates() ), this, SLOT( refreshDelegates() ) ); } @@ -127,6 +128,13 @@ void JobStatusView::customDelegateJobRemoved( int row ) { tLog() << Q_FUNC_INFO << "row is " << row; +} + + +void +JobStatusView::refreshDelegates() +{ + tLog() << Q_FUNC_INFO; int count = m_model->rowCount(); for ( int i = 0; i < count; i++ ) { diff --git a/src/libtomahawk/jobview/JobStatusView.h b/src/libtomahawk/jobview/JobStatusView.h index 1a5edf665..c845815de 100644 --- a/src/libtomahawk/jobview/JobStatusView.h +++ b/src/libtomahawk/jobview/JobStatusView.h @@ -55,6 +55,7 @@ private slots: void checkCount(); void customDelegateJobInserted( int row, JobStatusItem* item ); void customDelegateJobRemoved( int row ); + void refreshDelegates(); private: QListView* m_view; From 2c28325ae39b3caaf57181ec3d00798e5519a9dc Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sun, 17 Jun 2012 23:53:48 -0400 Subject: [PATCH 12/18] Fix item 1) in remaining ACL issues for 0.5...change text of adding-friend prompt to prevent confusion --- src/accounts/xmpp/sip/XmppSip.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/accounts/xmpp/sip/XmppSip.cpp b/src/accounts/xmpp/sip/XmppSip.cpp index 2c202f589..7375bb041 100644 --- a/src/accounts/xmpp/sip/XmppSip.cpp +++ b/src/accounts/xmpp/sip/XmppSip.cpp @@ -799,7 +799,7 @@ XmppSipPlugin::onSubscriptionReceived( const Jreen::RosterItem::Ptr& item, const QMessageBox *confirmBox = new QMessageBox( QMessageBox::Question, tr( "Authorize User" ), - QString( tr( "Do you want to grant %1 access to your Collection?" ) ).arg( presence.from().bare() ), + QString( tr( "Do you want to add %1 to your friend list?" ) ).arg( presence.from().bare() ), QMessageBox::Yes | QMessageBox::No, TomahawkUtils::tomahawkWindow() ); From 860366727003433a9c4f0e7f2042de3c65519c5b Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 18 Jun 2012 00:08:40 -0400 Subject: [PATCH 13/18] Knock down acl issue num 3: XMPP shows and auths against full jid with resource, sometimes --- src/libtomahawk/sip/SipHandler.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libtomahawk/sip/SipHandler.cpp b/src/libtomahawk/sip/SipHandler.cpp index dbfdad92b..d4816c651 100644 --- a/src/libtomahawk/sip/SipHandler.cpp +++ b/src/libtomahawk/sip/SipHandler.cpp @@ -169,6 +169,8 @@ SipHandler::onSipInfo( const QString& peerId, const SipInfo& info ) { tDebug() << Q_FUNC_INFO << "SIP Message:" << peerId << info; + QString barePeerId = peerId.left( peerId.indexOf( "/" ) ); + /* If only one party is externally visible, connection is obvious If both are, peer with lowest IP address initiates the connection. @@ -179,11 +181,11 @@ SipHandler::onSipInfo( const QString& peerId, const SipInfo& info ) if( !Servent::instance()->visibleExternally() || Servent::instance()->externalAddress() <= info.host().hostName() ) { - qDebug() << "Initiate connection to" << peerId; + qDebug() << "Initiate connection to" << barePeerId; Servent::instance()->connectToPeer( info.host().hostName(), info.port(), info.key(), - peerId, + barePeerId, info.uniqname() ); } else @@ -199,7 +201,7 @@ SipHandler::onSipInfo( const QString& peerId, const SipInfo& info ) m_peersSipInfos.insert( peerId, info ); } -void SipHandler::onSoftwareVersion(const QString& peerId, const QString& versionString) +void SipHandler::onSoftwareVersion( const QString& peerId, const QString& versionString ) { m_peersSoftwareVersions.insert( peerId, versionString ); } From f1a0de0f53b06411c8f29a2b1727f9dd39bd9732 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 18 Jun 2012 00:22:06 -0400 Subject: [PATCH 14/18] Start on acl entry clearing; also change where we strip the JID --- src/libtomahawk/AclRegistry.cpp | 9 +++++++++ src/libtomahawk/AclRegistry.h | 5 ++++- src/libtomahawk/network/Connection.cpp | 3 ++- src/libtomahawk/sip/SipHandler.cpp | 7 +++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/libtomahawk/AclRegistry.cpp b/src/libtomahawk/AclRegistry.cpp index dedd8bc25..ef99879fb 100644 --- a/src/libtomahawk/AclRegistry.cpp +++ b/src/libtomahawk/AclRegistry.cpp @@ -291,3 +291,12 @@ ACLRegistry::save() } TomahawkSettings::instance()->setAclEntries( entryList ); } + + +void +ACLRegistry::wipeEntries() +{ + tLog() << Q_FUNC_INFO; + m_cache.clear(); + save(); +} diff --git a/src/libtomahawk/AclRegistry.h b/src/libtomahawk/AclRegistry.h index 05c4c7435..37011ec48 100644 --- a/src/libtomahawk/AclRegistry.h +++ b/src/libtomahawk/AclRegistry.h @@ -102,11 +102,14 @@ public slots: #ifndef ENABLE_HEADLESS void getUserDecision( ACLRegistry::User user, const QString &username ); - +#endif + private slots: +#ifndef ENABLE_HEADLESS void userDecision( ACLRegistry::User user ); void queueNextJob(); #endif + void wipeEntries(); private: /** diff --git a/src/libtomahawk/network/Connection.cpp b/src/libtomahawk/network/Connection.cpp index 286965d88..def888eee 100644 --- a/src/libtomahawk/network/Connection.cpp +++ b/src/libtomahawk/network/Connection.cpp @@ -200,9 +200,10 @@ Connection::checkACL() } QString nodeid = property( "nodeid" ).toString(); + QString barePeerId = nodeid.left( nodeid.indexOf( "/" ) ); 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, name() ), Q_ARG( ACLRegistry::ACL, ACLRegistry::NotFound ) ); + QMetaObject::invokeMethod( ACLRegistry::instance(), "isAuthorizedUser", Qt::QueuedConnection, Q_ARG( QString, barePeerId ), Q_ARG( QString, name() ), Q_ARG( ACLRegistry::ACL, ACLRegistry::NotFound ) ); } diff --git a/src/libtomahawk/sip/SipHandler.cpp b/src/libtomahawk/sip/SipHandler.cpp index d4816c651..4044ddd6d 100644 --- a/src/libtomahawk/sip/SipHandler.cpp +++ b/src/libtomahawk/sip/SipHandler.cpp @@ -171,6 +171,9 @@ SipHandler::onSipInfo( const QString& peerId, const SipInfo& info ) QString barePeerId = peerId.left( peerId.indexOf( "/" ) ); + //FIXME: We should probably be using barePeerId in the connectToPeer call below. + //But, verify this doesn't cause any problems (there is still a uniquename after all) + /* If only one party is externally visible, connection is obvious If both are, peer with lowest IP address initiates the connection. @@ -181,11 +184,11 @@ SipHandler::onSipInfo( const QString& peerId, const SipInfo& info ) if( !Servent::instance()->visibleExternally() || Servent::instance()->externalAddress() <= info.host().hostName() ) { - qDebug() << "Initiate connection to" << barePeerId; + qDebug() << "Initiate connection to" << peerId; Servent::instance()->connectToPeer( info.host().hostName(), info.port(), info.key(), - barePeerId, + peerId, info.uniqname() ); } else From a82a8b2abe1cd73cf5dbaeb9b5fc0fc674b9e93d Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 18 Jun 2012 01:03:34 -0400 Subject: [PATCH 15/18] Add ACL-clearing button to settings --- src/SettingsDialog.cpp | 21 +++++++++++++++++++++ src/SettingsDialog.h | 2 ++ src/StackedSettingsDialog.ui | 24 ++++++++++++++++++++++++ src/libtomahawk/AclRegistry.h | 6 ++---- src/libtomahawk/jobview/AclJobItem.cpp | 2 ++ 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index 54fab5fa5..f8d3860f9 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -30,6 +30,7 @@ #include #include "AtticaManager.h" +#include "AclRegistry.h" #include "TomahawkApp.h" #include "TomahawkSettings.h" #include "accounts/DelegateConfigWrapper.h" @@ -98,6 +99,8 @@ SettingsDialog::SettingsDialog( QWidget *parent ) ui->enableProxyCheckBox->setChecked( useProxy ); ui->proxyButton->setEnabled( useProxy ); + ui->aclEntryClearButton->setEnabled( TomahawkSettings::instance()->aclEntries().size() > 0 ); + connect( ui->aclEntryClearButton, SIGNAL( clicked( bool ) ), this, SLOT( aclEntryClearButtonClicked() ) ); createIcons(); #ifdef Q_WS_X11 @@ -497,6 +500,24 @@ SettingsDialog::installFromFile() } +void +SettingsDialog::aclEntryClearButtonClicked() +{ + QMessageBox::StandardButton button = QMessageBox::question( + ui->stackedWidget, + tr( "Delete all Access Control entries?" ), + tr( "Do you really want to delete all Access Control entries? You will be be asked for a decision again for each peer that you connect to." ), + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Ok + ); + if ( button == QMessageBox::Ok ) + { + ACLRegistry::instance()->wipeEntries(); + ui->aclEntryClearButton->setEnabled( false ); + } +} + + void SettingsDialog::scrollTo( const QModelIndex& idx ) { diff --git a/src/SettingsDialog.h b/src/SettingsDialog.h index cbd8eb724..487f6e4ae 100644 --- a/src/SettingsDialog.h +++ b/src/SettingsDialog.h @@ -97,6 +97,8 @@ private slots: void changePage( QListWidgetItem*, QListWidgetItem* ); void serventReady(); + void aclEntryClearButtonClicked(); + void requiresRestart(); private: diff --git a/src/StackedSettingsDialog.ui b/src/StackedSettingsDialog.ui index 9c1d9ef37..08dcdf48b 100644 --- a/src/StackedSettingsDialog.ui +++ b/src/StackedSettingsDialog.ui @@ -418,6 +418,30 @@ + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Clear All Access Control Entries + + + + + diff --git a/src/libtomahawk/AclRegistry.h b/src/libtomahawk/AclRegistry.h index 37011ec48..f2ee66997 100644 --- a/src/libtomahawk/AclRegistry.h +++ b/src/libtomahawk/AclRegistry.h @@ -99,17 +99,15 @@ public slots: * @return ACLRegistry::ACL **/ ACLRegistry::ACL isAuthorizedUser( const QString &dbid, const QString &username, ACLRegistry::ACL globalType = ACLRegistry::NotFound, bool skipEmission = false ); - + void wipeEntries(); + #ifndef ENABLE_HEADLESS void getUserDecision( ACLRegistry::User user, const QString &username ); -#endif private slots: -#ifndef ENABLE_HEADLESS void userDecision( ACLRegistry::User user ); void queueNextJob(); #endif - void wipeEntries(); private: /** diff --git a/src/libtomahawk/jobview/AclJobItem.cpp b/src/libtomahawk/jobview/AclJobItem.cpp index 12a46bab1..81f9869d8 100644 --- a/src/libtomahawk/jobview/AclJobItem.cpp +++ b/src/libtomahawk/jobview/AclJobItem.cpp @@ -119,6 +119,8 @@ AclJobDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect, bool bool AclJobDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index ) { + Q_UNUSED( option ) + Q_UNUSED( model ) //tDebug( LOGVERBOSE ) << Q_FUNC_INFO; if ( event->type() != QEvent::MouseButtonPress && event->type() != QEvent::MouseButtonRelease && From 4a1adbfb8ae579438b394eff7e434527133a5773 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 18 Jun 2012 01:20:13 -0400 Subject: [PATCH 16/18] Eep, use name, not nodeid, in the shortening --- src/libtomahawk/network/Connection.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/network/Connection.cpp b/src/libtomahawk/network/Connection.cpp index def888eee..bdc52646c 100644 --- a/src/libtomahawk/network/Connection.cpp +++ b/src/libtomahawk/network/Connection.cpp @@ -200,10 +200,10 @@ Connection::checkACL() } QString nodeid = property( "nodeid" ).toString(); - QString barePeerId = nodeid.left( nodeid.indexOf( "/" ) ); + QString bareName = name().left( name().indexOf( "/" ) ); 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, barePeerId ), Q_ARG( QString, name() ), Q_ARG( ACLRegistry::ACL, ACLRegistry::NotFound ) ); + QMetaObject::invokeMethod( ACLRegistry::instance(), "isAuthorizedUser", Qt::QueuedConnection, Q_ARG( QString, nodeid ), Q_ARG( QString, bareName ), Q_ARG( ACLRegistry::ACL, ACLRegistry::NotFound ) ); } From 7896d155362e78a33453f5d677eab15f4bebb017 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 18 Jun 2012 01:29:40 -0400 Subject: [PATCH 17/18] For custom JobItems, the delegate is parented to the view, so don't attempt to delete it in the destructor of the item --- src/libtomahawk/jobview/AclJobItem.cpp | 3 +-- src/libtomahawk/jobview/AclJobItem.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libtomahawk/jobview/AclJobItem.cpp b/src/libtomahawk/jobview/AclJobItem.cpp index 81f9869d8..7d94bf9fa 100644 --- a/src/libtomahawk/jobview/AclJobItem.cpp +++ b/src/libtomahawk/jobview/AclJobItem.cpp @@ -164,8 +164,6 @@ AclJobItem::AclJobItem( ACLRegistry::User user, const QString &username ) AclJobItem::~AclJobItem() { tLog() << Q_FUNC_INFO; - if ( m_delegate ) - delete m_delegate; } @@ -173,6 +171,7 @@ void AclJobItem::createDelegate( QObject* parent ) { tLog() << Q_FUNC_INFO; + if ( m_delegate ) return; diff --git a/src/libtomahawk/jobview/AclJobItem.h b/src/libtomahawk/jobview/AclJobItem.h index d258ed1f3..18c90bcba 100644 --- a/src/libtomahawk/jobview/AclJobItem.h +++ b/src/libtomahawk/jobview/AclJobItem.h @@ -71,7 +71,7 @@ public: virtual int concurrentJobLimit() const { return 3; } virtual bool hasCustomDelegate() const { return true; } - virtual void createDelegate( QObject* parent ); + virtual void createDelegate( QObject* parent = 0 ); virtual QStyledItemDelegate* customDelegate() const { return m_delegate; } virtual ACLRegistry::User user() const { return m_user; } From df269ae7a6197a89503689ac6afa25bb0aa05f78 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 18 Jun 2012 01:42:45 -0400 Subject: [PATCH 18/18] Update ChangeLog --- ChangeLog | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0fa6c3c4b..696ba4ba2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ Version 0.5.0: + * Initial Access Control support. Entries can be cleared en masse in the Advanced area of Settings. * Priortize resolution of a track on double-click * New Tomahawk logo and icon * Spotify Resolver shipped with Tomahawk and installable via new Preferences interface @@ -11,7 +12,7 @@ Version 0.5.0: * You can now import your entire Last.fm playback history into Tomahawk * Related Artists now sorted by relatedness * Support for multimedia keys (Play, Pause, Next etc.) on Windows & Linux - * When listening privately scrobbling to Last.fm and Adium is now disabled + * When listening privately, scrobbling to Last.fm and sending updates to Adium/MRPIS is now disabled * Added a toolbar with page back / forward buttons and the global search * New grid view with direct playback controls (Charts, Album Page, Artist Page, Track Page) * New Releases (by Genre) pages added