1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-20 04:41:36 +02:00

W. T. F. Why can my simple struct no longer be serialized by QVariant.

Even adding destructor/copy constructor didn't help.
This commit is contained in:
Jeff Mitchell
2012-04-22 16:05:14 -04:00
parent 4fcfbf8e06
commit 261aa7b677
7 changed files with 38 additions and 8 deletions

View File

@@ -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 );
}

View File

@@ -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 );

View File

@@ -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";
}

View File

@@ -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;
}

View File

@@ -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 >();
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();

View File

@@ -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 )
{
if ( m_customDelegateRefCounter[ row ] == 1 )
m_view->setItemDelegateForRow( row, m_view->itemDelegate() );
m_customDelegateRefCounter[ row ] = m_customDelegateRefCounter[ row ] - 1;
}

View File

@@ -61,6 +61,7 @@ private:
JobStatusModel* m_model;
AnimatedSplitter* m_parent;
mutable int m_cachedHeight;
QHash< int, int > m_customDelegateRefCounter;
static JobStatusView* s_instance;
};