diff --git a/src/AclRegistryImpl.cpp b/src/AclRegistryImpl.cpp new file mode 100644 index 000000000..7d58499c3 --- /dev/null +++ b/src/AclRegistryImpl.cpp @@ -0,0 +1,233 @@ +/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === + * + * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> + * Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org> + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "AclRegistryImpl.h" + +#include <QThread> +#include <QVariant> + +#include "TomahawkSettings.h" +#include "TomahawkApp.h" +#include "Source.h" + +#ifndef ENABLE_HEADLESS + #include "accounts/AccountManager.h" + #include "accounts/Account.h" + #include "jobview/AclJobItem.h" + #include "jobview/JobStatusView.h" + #include "jobview/JobStatusModel.h" +#endif + +#include "utils/Logger.h" + + +AclRegistryImpl::AclRegistryImpl( QObject* parent ) + : AclRegistry( parent ) + , m_jobCount( 0 ) +{ + AclRegistry::setInstance( this ); + load(); +} + + +AclRegistryImpl::~AclRegistryImpl() +{ + save(); +} + + +AclRegistry::ACL +AclRegistryImpl::isAuthorizedUser( const QString& dbid, const QString &username, AclRegistry::ACL globalType, bool skipEmission ) +{ + 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; + } + +#ifndef ENABLE_HEADLESS + if ( Tomahawk::Accounts::AccountManager::instance() ) + { + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Checking account friendly names against" << username; + Tomahawk::Accounts::AccountManager* accountManager = Tomahawk::Accounts::AccountManager::instance(); + QList< Tomahawk::Accounts::Account* > accounts = accountManager->accounts(); + foreach( Tomahawk::Accounts::Account* account, accounts ) + { + if ( !( account->types() & Tomahawk::Accounts::SipType ) ) + continue; + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Checking against account friendly name" << account->accountFriendlyName(); + if ( account->accountFriendlyName() == username ) + { + if ( !skipEmission ) + emit aclResult( dbid, username, AclRegistry::Stream ); + return AclRegistry::Stream; + } + } + } +#endif + + bool found = false; + QMutableListIterator< AclRegistry::User > i( m_cache ); + while ( i.hasNext() ) + { + AclRegistry::User user = i.next(); + foreach ( QString knowndbid, user.knownDbids ) + { + if ( dbid == knowndbid ) + { + if ( !user.knownAccountIds.contains( username ) ) + user.knownAccountIds.append( username ); + found = true; + } + } + + foreach ( QString knownaccountid, user.knownAccountIds ) + { + if ( username == knownaccountid ) + { + if ( !user.knownDbids.contains( dbid ) ) + user.knownDbids.append( dbid ); + found = true; + } + } + + if ( found ) + { + if ( !skipEmission ) + emit aclResult( dbid, username, user.acl ); + i.setValue( user ); + return user.acl; + } + } + + if ( skipEmission ) + return AclRegistry::NotFound; + + // User was not found, create a new user entry + AclRegistry::User user; + user.knownDbids.append( dbid ); + user.knownAccountIds.append( username ); + if ( globalType != AclRegistry::NotFound ) + user.acl = globalType; +#ifdef ENABLE_HEADLESS + user.acl = AclRegistry::Stream; +#else + if ( !TomahawkUtils::headless() ) + { + getUserDecision( user, username ); + return AclRegistry::NotFound; + } + else + user.acl = AclRegistry::Stream; +#endif + m_cache.append( user ); + save(); + emit aclResult( dbid, username, user.acl ); + return user.acl; +} + + +#ifndef ENABLE_HEADLESS +void +AclRegistryImpl::getUserDecision( AclRegistry::User user, const QString &username ) +{ + if ( TomahawkUtils::headless() ) + return; + + tLog() << Q_FUNC_INFO; + AclJobItem* job = new AclJobItem( user, username ); + m_jobQueue.enqueue( job ); + QTimer::singleShot( 0, this, SLOT( queueNextJob() ) ); +} + + +void +AclRegistryImpl::userDecision( AclRegistry::User user ) +{ + if ( TomahawkUtils::headless() ) + return; + + 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() ) + QTimer::singleShot( 0, this, SLOT( queueNextJob() ) ); +} + + +void +AclRegistryImpl::queueNextJob() +{ + if ( TomahawkUtils::headless() ) + return; + + 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; + + if ( !m_jobQueue.isEmpty() ) + { + AclJobItem* job = m_jobQueue.dequeue(); + AclRegistry::User user = job->user(); + bool found = false; + foreach( QString dbid, user.knownDbids ) + { + AclRegistry::ACL acl = isAuthorizedUser( dbid, job->username(), AclRegistry::NotFound, true ); + if ( acl != AclRegistry::NotFound ) + { + tLog() << Q_FUNC_INFO << "Found existing acl entry for = " << user.knownAccountIds.first(); + found = true; + break; + } + } + if ( found ) + { + tLog() << Q_FUNC_INFO << "deleting job, already have ACL for " << user.knownAccountIds.first(); + delete job; + QTimer::singleShot( 0, this, SLOT( queueNextJob() ) ); + return; + } + else + { + 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 ) ) ); + } + } +} +#endif + +void +AclRegistryImpl::wipeEntries() +{ + AclRegistry::wipeEntries(); + save(); +} diff --git a/src/AclRegistryImpl.h b/src/AclRegistryImpl.h new file mode 100644 index 000000000..04bf642dd --- /dev/null +++ b/src/AclRegistryImpl.h @@ -0,0 +1,77 @@ +/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === + * + * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> + * Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org> + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef TOMAHAWK_ACLREGISTRYIMPL_H +#define TOMAHAWK_ACLREGISTRYIMPL_H + +#include <QObject> +#include <QString> +#include <QHash> +#include <QTimer> +#include <QMutex> +#include <QVariant> +#include <QQueue> +#include <QStringList> +#include <QUuid> + +#include "AclRegistry.h" +#include "HeadlessCheck.h" +#include "DllMacro.h" + +class AclJobItem; + +class AclRegistryImpl : public AclRegistry +{ + Q_OBJECT + +public: + + AclRegistryImpl( QObject *parent = 0 ); + virtual ~AclRegistryImpl(); + +signals: + void aclResult( QString nodeid, QString username, AclRegistry::ACL peerStatus ); + +public slots: + /** + * @brief Checks if peer is authorized; optionally, can authorize peer with given type if not found + * + * @param dbid DBID of peer + * @param globalType Global ACL to store if peer not found; if AclRegistry::NotFound, does not store the peer Defaults to AclRegistry::NotFound. + * @param username If not empty, will store the given username along with the new ACL value. Defaults to QString(). + * @return AclRegistry::ACL + **/ + virtual AclRegistry::ACL isAuthorizedUser( const QString &dbid, const QString &username, AclRegistry::ACL globalType = AclRegistry::NotFound, bool skipEmission = false ); + +#ifndef ENABLE_HEADLESS + void getUserDecision( AclRegistry::User user, const QString &username ); + + virtual void wipeEntries(); + +private slots: + void userDecision( AclRegistry::User user ); + void queueNextJob(); +#endif + +private: + QQueue< AclJobItem* > m_jobQueue; + int m_jobCount; +}; + +#endif // TOMAHAWK_ACLREGISTRYIMPL_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3cd2ddd5c..c18b9c555 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,6 +37,7 @@ ENDIF() SET( tomahawkSources ${tomahawkSources} web/Api_v1.cpp + AclRegistryImpl.cpp ShortcutHandler.cpp UbuntuUnityHack.cpp TomahawkApp.cpp diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index 213373ea0..699581ae2 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -510,7 +510,7 @@ SettingsDialog::aclEntryClearButtonClicked() ); if ( button == QMessageBox::Ok ) { - ACLRegistry::instance()->wipeEntries(); + AclRegistry::instance()->wipeEntries(); ui->aclEntryClearButton->setEnabled( false ); } } diff --git a/src/TomahawkApp.cpp b/src/TomahawkApp.cpp index 6b73a930b..7324889ac 100644 --- a/src/TomahawkApp.cpp +++ b/src/TomahawkApp.cpp @@ -31,8 +31,9 @@ #include <QtCore/QFileInfo> #include <QTranslator> -#include "Artist.h" +#include "AclRegistryImpl.h" #include "Album.h" +#include "Artist.h" #include "Collection.h" #include "infosystem/InfoSystem.h" #include "accounts/AccountManager.h" @@ -204,6 +205,8 @@ TomahawkApp::init() TomahawkSettings* s = TomahawkSettings::instance(); + AclRegistryImpl* ari = new AclRegistryImpl( this ); + tDebug( LOGINFO ) << "Setting NAM."; // Cause the creation of the nam, but don't need to address it directly, so prevent warning Q_UNUSED( TomahawkUtils::nam() ); diff --git a/src/libtomahawk/AclRegistry.cpp b/src/libtomahawk/AclRegistry.cpp index 7b6de5128..7061507b1 100644 --- a/src/libtomahawk/AclRegistry.cpp +++ b/src/libtomahawk/AclRegistry.cpp @@ -26,18 +26,10 @@ #include "TomahawkApp.h" #include "Source.h" -#ifndef ENABLE_HEADLESS - #include "accounts/AccountManager.h" - #include "accounts/Account.h" - #include "jobview/AclJobItem.h" - #include "jobview/JobStatusView.h" - #include "jobview/JobStatusModel.h" -#endif - #include "utils/Logger.h" -QDataStream& operator<<( QDataStream &out, const ACLRegistry::User &user ) +QDataStream& operator<<( QDataStream &out, const AclRegistry::User &user ) { out << ACLUSERVERSION; out << user.uuid; @@ -52,7 +44,7 @@ QDataStream& operator<<( QDataStream &out, const ACLRegistry::User &user ) return out; } -QDataStream& operator>>( QDataStream &in, ACLRegistry::User &user ) +QDataStream& operator>>( QDataStream &in, AclRegistry::User &user ) { int ver; in >> ver; @@ -78,231 +70,56 @@ QDataStream& operator>>( QDataStream &in, ACLRegistry::User &user ) } int aclIn; in >> aclIn; - user.acl = (ACLRegistry::ACL)( aclIn ); + user.acl = (AclRegistry::ACL)( aclIn ); } return in; } -ACLRegistry* ACLRegistry::s_instance = 0; +AclRegistry* AclRegistry::s_instance = 0; -ACLRegistry* -ACLRegistry::instance() +AclRegistry* +AclRegistry::instance() { - if( !s_instance ) - new ACLRegistry(); return s_instance; } -ACLRegistry::ACLRegistry( QObject* parent ) +void +AclRegistry::setInstance( AclRegistry* instance ) +{ + s_instance = instance; +} + + +AclRegistry::AclRegistry( QObject* parent ) : QObject( parent ) - , m_jobCount( 0 ) { - s_instance = this; - qRegisterMetaType< ACLRegistry::ACL >( "ACLRegistry::ACL" ); - qRegisterMetaType< ACLRegistry::User >( "ACLRegistry::User" ); - qRegisterMetaTypeStreamOperators< ACLRegistry::User >( "ACLRegistry::User" ); - load(); + qRegisterMetaType< AclRegistry::ACL >( "AclRegistry::ACL" ); + qRegisterMetaType< AclRegistry::User >( "AclRegistry::User" ); + qRegisterMetaTypeStreamOperators< AclRegistry::User >( "AclRegistry::User" ); } -ACLRegistry::~ACLRegistry() +AclRegistry::~AclRegistry() { } -ACLRegistry::ACL -ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACLRegistry::ACL globalType, bool skipEmission ) -{ - 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; - } - -#ifndef ENABLE_HEADLESS - if ( Tomahawk::Accounts::AccountManager::instance() ) - { - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Checking account friendly names against" << username; - Tomahawk::Accounts::AccountManager* accountManager = Tomahawk::Accounts::AccountManager::instance(); - QList< Tomahawk::Accounts::Account* > accounts = accountManager->accounts(); - foreach( Tomahawk::Accounts::Account* account, accounts ) - { - if ( !( account->types() & Tomahawk::Accounts::SipType ) ) - continue; - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Checking against account friendly name" << account->accountFriendlyName(); - if ( account->accountFriendlyName() == username ) - { - if ( !skipEmission ) - emit aclResult( dbid, username, ACLRegistry::Stream ); - return ACLRegistry::Stream; - } - } - } -#endif - - bool found = false; - QMutableListIterator< ACLRegistry::User > i( m_cache ); - while ( i.hasNext() ) - { - ACLRegistry::User user = i.next(); - foreach ( QString knowndbid, user.knownDbids ) - { - if ( dbid == knowndbid ) - { - if ( !user.knownAccountIds.contains( username ) ) - user.knownAccountIds.append( username ); - found = true; - } - } - - foreach ( QString knownaccountid, user.knownAccountIds ) - { - if ( username == knownaccountid ) - { - if ( !user.knownDbids.contains( dbid ) ) - user.knownDbids.append( dbid ); - found = true; - } - } - - if ( found ) - { - if ( !skipEmission ) - emit aclResult( dbid, username, user.acl ); - i.setValue( user ); - return user.acl; - } - } - - if ( skipEmission ) - return ACLRegistry::NotFound; - - // User was not found, create a new user entry - ACLRegistry::User user; - user.knownDbids.append( dbid ); - user.knownAccountIds.append( username ); - if ( globalType != ACLRegistry::NotFound ) - user.acl = globalType; -#ifdef ENABLE_HEADLESS - user.acl = ACLRegistry::Stream; -#else - if ( !TomahawkUtils::headless() ) - { - getUserDecision( user, username ); - return ACLRegistry::NotFound; - } - else - user.acl = ACLRegistry::Stream; -#endif - - m_cache.append( user ); - save(); - emit aclResult( dbid, username, user.acl ); - return user.acl; -} - - -#ifndef ENABLE_HEADLESS - -void -ACLRegistry::getUserDecision( ACLRegistry::User user, const QString &username ) -{ - if ( TomahawkUtils::headless() ) - return; - - tLog() << Q_FUNC_INFO; - AclJobItem* job = new AclJobItem( user, username ); - m_jobQueue.enqueue( job ); - QTimer::singleShot( 0, this, SLOT( queueNextJob() ) ); -} - - void -ACLRegistry::userDecision( ACLRegistry::User user ) -{ - if ( TomahawkUtils::headless() ) - return; - - 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() ) - QTimer::singleShot( 0, this, SLOT( queueNextJob() ) ); -} - - -void -ACLRegistry::queueNextJob() -{ - if ( TomahawkUtils::headless() ) - return; - - 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; - - if ( !m_jobQueue.isEmpty() ) - { - AclJobItem* job = m_jobQueue.dequeue(); - ACLRegistry::User user = job->user(); - bool found = false; - foreach( QString dbid, user.knownDbids ) - { - ACLRegistry::ACL acl = isAuthorizedUser( dbid, job->username(), ACLRegistry::NotFound, true ); - if ( acl != ACLRegistry::NotFound ) - { - tLog() << Q_FUNC_INFO << "Found existing acl entry for = " << user.knownAccountIds.first(); - found = true; - break; - } - } - if ( found ) - { - tLog() << Q_FUNC_INFO << "deleting job, already have ACL for " << user.knownAccountIds.first(); - delete job; - QTimer::singleShot( 0, this, SLOT( queueNextJob() ) ); - return; - } - else - { - 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 ) ) ); - } - } -} - -#endif - - -void -ACLRegistry::load() +AclRegistry::load() { tLog() << Q_FUNC_INFO; QVariantList entryList = TomahawkSettings::instance()->aclEntries(); foreach ( QVariant entry, entryList ) { - if ( !entry.isValid() || !entry.canConvert< ACLRegistry::User >() ) + 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 >(); + AclRegistry::User entryUser = entry.value< AclRegistry::User >(); if ( entryUser.knownAccountIds.empty() || entryUser.knownDbids.empty() ) { tLog() << Q_FUNC_INFO << "user known account/dbids is empty"; @@ -314,14 +131,14 @@ ACLRegistry::load() void -ACLRegistry::save() +AclRegistry::save() { tLog() << Q_FUNC_INFO; QVariantList entryList; - foreach ( ACLRegistry::User user, m_cache ) + foreach ( AclRegistry::User user, m_cache ) { tLog() << Q_FUNC_INFO << "user is " << user.uuid << " with known name " << user.knownAccountIds.first(); - QVariant val = QVariant::fromValue< ACLRegistry::User >( user ); + QVariant val = QVariant::fromValue< AclRegistry::User >( user ); if ( val.isValid() ) entryList.append( val ); } @@ -330,9 +147,9 @@ ACLRegistry::save() void -ACLRegistry::wipeEntries() +AclRegistry::wipeEntries() { tLog() << Q_FUNC_INFO; m_cache.clear(); - save(); } + diff --git a/src/libtomahawk/AclRegistry.h b/src/libtomahawk/AclRegistry.h index f583815b5..df4d59234 100644 --- a/src/libtomahawk/AclRegistry.h +++ b/src/libtomahawk/AclRegistry.h @@ -35,15 +35,14 @@ #define ACLUSERVERSION 1 -class AclJobItem; - -class DLLEXPORT ACLRegistry : public QObject +class DLLEXPORT AclRegistry : public QObject { Q_OBJECT public: - static ACLRegistry* instance(); + static AclRegistry* instance(); + static void setInstance( AclRegistry* instance ); enum ACL { NotFound = 0, @@ -57,20 +56,20 @@ public: QString friendlyName; QStringList knownDbids; QStringList knownAccountIds; - ACLRegistry::ACL acl; + AclRegistry::ACL acl; User() : uuid( QUuid::createUuid().toString() ) , friendlyName() , knownDbids() , knownAccountIds() - , acl( ACLRegistry::NotFound ) + , acl( AclRegistry::NotFound ) {} ~User() {} - User( QString p_uuid, QString p_friendlyName, QStringList p_knownDbids, QStringList p_knownAccountIds, ACLRegistry::ACL p_acl ) + User( QString p_uuid, QString p_friendlyName, QStringList p_knownDbids, QStringList p_knownAccountIds, AclRegistry::ACL p_acl ) : uuid( p_uuid ) , friendlyName( p_friendlyName ) , knownDbids( p_knownDbids ) @@ -87,51 +86,39 @@ public: {} }; - ACLRegistry( QObject *parent = 0 ); - ~ACLRegistry(); + AclRegistry( QObject *parent = 0 ); + virtual ~AclRegistry(); signals: - void aclResult( QString nodeid, QString username, ACLRegistry::ACL peerStatus ); + void aclResult( QString nodeid, QString username, AclRegistry::ACL peerStatus ); public slots: /** * @brief Checks if peer is authorized; optionally, can authorize peer with given type if not found * * @param dbid DBID of peer - * @param globalType Global ACL to store if peer not found; if ACLRegistry::NotFound, does not store the peer Defaults to ACLRegistry::NotFound. + * @param globalType Global ACL to store if peer not found; if AclRegistry::NotFound, does not store the peer Defaults to AclRegistry::NotFound. * @param username If not empty, will store the given username along with the new ACL value. Defaults to QString(). - * @return ACLRegistry::ACL + * @return AclRegistry::ACL **/ - 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 ); - -private slots: - void userDecision( ACLRegistry::User user ); - void queueNextJob(); -#endif + virtual AclRegistry::ACL isAuthorizedUser( const QString &dbid, const QString &username, AclRegistry::ACL globalType = AclRegistry::NotFound, bool skipEmission = false ) = 0; + virtual void wipeEntries(); -private: +protected: /** * @brief Saves the cache. * * @return void **/ - void save(); + virtual void save(); + virtual void load(); - void load(); + QList< AclRegistry::User > m_cache; - QList< ACLRegistry::User > m_cache; - - static ACLRegistry* s_instance; - - QQueue< AclJobItem* > m_jobQueue; - int m_jobCount; + static AclRegistry* s_instance; }; -Q_DECLARE_METATYPE( ACLRegistry::ACL ); -Q_DECLARE_METATYPE( ACLRegistry::User ); +Q_DECLARE_METATYPE( AclRegistry::ACL ); +Q_DECLARE_METATYPE( AclRegistry::User ); #endif // TOMAHAWK_ACLREGISTRY_H diff --git a/src/libtomahawk/jobview/AclJobItem.cpp b/src/libtomahawk/jobview/AclJobItem.cpp index a2d32a224..fac30bb66 100644 --- a/src/libtomahawk/jobview/AclJobItem.cpp +++ b/src/libtomahawk/jobview/AclJobItem.cpp @@ -148,9 +148,9 @@ AclJobDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QSt { QMouseEvent* me = static_cast< QMouseEvent* >( event ); if ( m_savedAcceptRect.contains( me->pos() ) ) - emit aclResult( ACLRegistry::Stream ); + emit aclResult( AclRegistry::Stream ); else if ( m_savedDenyRect.contains( me->pos() ) ) - emit aclResult( ACLRegistry::Deny ); + emit aclResult( AclRegistry::Deny ); return true; } @@ -159,7 +159,7 @@ AclJobDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QSt -AclJobItem::AclJobItem( ACLRegistry::User user, const QString &username ) +AclJobItem::AclJobItem( AclRegistry::User user, const QString &username ) : m_delegate( 0 ) , m_user( user ) , m_username( username ) @@ -197,7 +197,7 @@ AclJobDelegate::emitSizeHintChanged( const QModelIndex& index ) void -AclJobItem::aclResult( ACLRegistry::ACL result ) +AclJobItem::aclResult( AclRegistry::ACL result ) { tLog() << Q_FUNC_INFO; m_user.acl = result; diff --git a/src/libtomahawk/jobview/AclJobItem.h b/src/libtomahawk/jobview/AclJobItem.h index 18c90bcba..6d336f86f 100644 --- a/src/libtomahawk/jobview/AclJobItem.h +++ b/src/libtomahawk/jobview/AclJobItem.h @@ -20,14 +20,15 @@ #ifndef ACLJOBITEM_H #define ACLJOBITEM_H -#include <jobview/JobStatusItem.h> #include "AclRegistry.h" +#include "DllMacro.h" +#include "jobview/JobStatusItem.h" #include <QStyledItemDelegate> class QListView; -class AclJobDelegate : public QStyledItemDelegate +class DLLEXPORT AclJobDelegate : public QStyledItemDelegate { Q_OBJECT @@ -39,53 +40,53 @@ public: 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 ); - + void aclResult( AclRegistry::ACL result ); + protected: virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index ); - + private: void drawRoundedButton( QPainter* painter, const QRect& btnRect, bool red = false ) const; - + QPoint m_savedHoverPos; mutable QRect m_savedAcceptRect; mutable QRect m_savedDenyRect; }; -class AclJobItem : public JobStatusItem +class DLLEXPORT AclJobItem : public JobStatusItem { Q_OBJECT public: - explicit AclJobItem( ACLRegistry::User user, const QString &username ); + explicit AclJobItem( AclRegistry::User user, const QString &username ); virtual ~AclJobItem(); - + virtual QString rightColumnText() const { return QString(); } virtual QString mainText() const { return QString(); } virtual QPixmap icon() const { return QPixmap(); } virtual QString type() const { return "acljob"; } virtual int concurrentJobLimit() const { return 3; } - + virtual bool hasCustomDelegate() const { return true; } virtual void createDelegate( QObject* parent = 0 ); virtual QStyledItemDelegate* customDelegate() const { return m_delegate; } - virtual ACLRegistry::User user() const { return m_user; } + virtual AclRegistry::User user() const { return m_user; } virtual const QString& username() const { return m_username; } signals: - void userDecision( ACLRegistry::User user ); + void userDecision( AclRegistry::User user ); public slots: - void aclResult( ACLRegistry::ACL result ); + void aclResult( AclRegistry::ACL result ); private: QStyledItemDelegate* m_delegate; - ACLRegistry::User m_user; + AclRegistry::User m_user; const QString m_username; }; diff --git a/src/libtomahawk/jobview/JobStatusView.cpp b/src/libtomahawk/jobview/JobStatusView.cpp index 4762ab521..155e6a197 100644 --- a/src/libtomahawk/jobview/JobStatusView.cpp +++ b/src/libtomahawk/jobview/JobStatusView.cpp @@ -113,7 +113,7 @@ JobStatusView::customDelegateJobInserted( int row, JobStatusItem* item ) { 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 ) ) ); + connect( delegate, SIGNAL( aclResult( AclRegistry::ACL ) ), item, SLOT( aclResult( AclRegistry::ACL ) ) ); delegate->emitSizeHintChanged( m_model->index( row ) ); } else diff --git a/src/libtomahawk/network/Connection.cpp b/src/libtomahawk/network/Connection.cpp index 9d28a64b2..6983f7b95 100644 --- a/src/libtomahawk/network/Connection.cpp +++ b/src/libtomahawk/network/Connection.cpp @@ -208,13 +208,13 @@ Connection::checkACL() QString nodeid = property( "nodeid" ).toString(); QString bareName = name().contains( '/' ) ? name().left( name().indexOf( "/" ) ) : name(); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Checking ACL for" << name(); - connect( ACLRegistry::instance(), SIGNAL( aclResult( QString, QString, ACLRegistry::ACL ) ), this, SLOT( checkACLResult( QString, QString, ACLRegistry::ACL ) ), Qt::QueuedConnection ); - QMetaObject::invokeMethod( ACLRegistry::instance(), "isAuthorizedUser", Qt::QueuedConnection, Q_ARG( QString, nodeid ), Q_ARG( QString, bareName ), Q_ARG( ACLRegistry::ACL, ACLRegistry::NotFound ) ); + 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, bareName ), Q_ARG( AclRegistry::ACL, AclRegistry::NotFound ) ); } void -Connection::checkACLResult( const QString &nodeid, const QString &username, ACLRegistry::ACL peerStatus ) +Connection::checkACLResult( const QString &nodeid, const QString &username, AclRegistry::ACL peerStatus ) { QString bareName = name().contains( '/' ) ? name().left( name().indexOf( "/" ) ) : name(); if ( nodeid != property( "nodeid" ).toString() || username != bareName ) @@ -223,9 +223,9 @@ Connection::checkACLResult( const QString &nodeid, const QString &username, ACLR return; } - disconnect( ACLRegistry::instance(), SIGNAL( aclResult( QString, QString, ACLRegistry::ACL ) ) ); + disconnect( AclRegistry::instance(), SIGNAL( aclResult( QString, QString, AclRegistry::ACL ) ) ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "ACL status is" << peerStatus; - if ( peerStatus == ACLRegistry::Stream ) + if ( peerStatus == AclRegistry::Stream ) { QTimer::singleShot( 0, this, SLOT( doSetup() ) ); return; diff --git a/src/libtomahawk/network/Connection.h b/src/libtomahawk/network/Connection.h index 6bc1122bd..8d8f903a5 100644 --- a/src/libtomahawk/network/Connection.h +++ b/src/libtomahawk/network/Connection.h @@ -120,7 +120,7 @@ private slots: void readyRead(); void doSetup(); void checkACL(); - void checkACLResult( const QString &nodeid, const QString &username, ACLRegistry::ACL peerStatus ); + void checkACLResult( const QString &nodeid, const QString &username, AclRegistry::ACL peerStatus ); void authCheckTimeout(); void bytesWritten( qint64 ); void calcStats(); diff --git a/src/libtomahawk/network/Servent.cpp b/src/libtomahawk/network/Servent.cpp index 63d701a5f..c57223f52 100644 --- a/src/libtomahawk/network/Servent.cpp +++ b/src/libtomahawk/network/Servent.cpp @@ -65,7 +65,7 @@ Servent::Servent( QObject* parent ) s_instance = this; m_lanHack = qApp->arguments().contains( "--lanhack" ); - ACLRegistry::instance(); + AclRegistry::instance(); setProxy( QNetworkProxy::NoProxy ); { @@ -90,7 +90,7 @@ Servent::Servent( QObject* parent ) Servent::~Servent() { - delete ACLRegistry::instance(); + delete AclRegistry::instance(); delete m_portfwd; }