1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-23 09:19:41 +01:00

Merge remote-tracking branch 'origin/master' into mhd

This commit is contained in:
Leo Franchi 2012-04-21 14:42:56 -04:00
commit 012bc8949e
15 changed files with 4052 additions and 76 deletions

3656
lang/tomahawk_zh_TW.ts Normal file

File diff suppressed because it is too large Load Diff

View File

@ -54,6 +54,7 @@ signals:
public slots:
void resolved( QHostInfo i )
{
qDebug() << Q_FUNC_INFO << "zeroconf-derived IP has resolved to name " << i.hostName();
if ( i.hostName().length() )
emit tomahawkHostFound( ip, port, i.hostName(), nid );
else
@ -63,6 +64,7 @@ public slots:
void resolve()
{
qDebug() << Q_FUNC_INFO << "Resolving zeroconf-derived IP " << ip;
QHostInfo::lookupHost( ip, this, SLOT( resolved( QHostInfo ) ) );
}
@ -95,13 +97,20 @@ public:
public slots:
void advertise()
{
qDebug() << "Advertising us on the LAN";
qDebug() << "Advertising us on the LAN (both versions)";
QByteArray advert = QString( "TOMAHAWKADVERT:%1:%2" )
.arg( m_port )
.arg( Database::instance()->dbid() )
.toAscii();
m_sock.writeDatagram( advert.data(), advert.size(),
QHostAddress::Broadcast, ZCONF_PORT );
advert = QString( "TOMAHAWKADVERT:%1:%2:%3" )
.arg( m_port )
.arg( Database::instance()->dbid() )
.arg( QHostInfo::localHostName() )
.toAscii();
m_sock.writeDatagram( advert.data(), advert.size(),
QHostAddress::Broadcast, ZCONF_PORT );
}
signals:
@ -126,11 +135,20 @@ private slots:
Servent::isIPWhitelisted( sender ) )
{
QStringList parts = QString::fromAscii( datagram ).split( ':' );
if ( parts.length() == 3 )
if ( parts.length() == 4 )
{
bool ok;
int port = parts.at(1).toInt( &ok );
if(ok && Database::instance()->dbid() != parts.at( 2 ) )
if ( ok && Database::instance()->dbid() != parts.at( 2 ) )
{
emit tomahawkHostFound( sender.toString(), port, parts.at( 3 ), parts.at( 2 ) );
}
}
else if ( parts.length() == 3 )
{
bool ok;
int port = parts.at(1).toInt( &ok );
if ( ok && Database::instance()->dbid() != parts.at( 2 ) )
{
qDebug() << "ADVERT received:" << sender << port;
Node *n = new Node( sender.toString(), parts.at( 2 ), port );

View File

@ -36,6 +36,7 @@ set( libGuiSources
jobview/JobStatusModel.cpp
jobview/JobStatusDelegate.cpp
jobview/JobStatusItem.cpp
jobview/AclJobItem.cpp
jobview/PipelineStatusItem.cpp
jobview/TransferStatusItem.cpp
jobview/LatchedStatusItem.cpp

View File

@ -26,6 +26,9 @@
#include "tomahawkapp.h"
#include "utils/logger.h"
#include "jobview/AclJobItem.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
ACLRegistry* ACLRegistry::s_instance = 0;
@ -64,6 +67,10 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL
return;
}
//FIXME: Remove when things are working
emit aclResult( dbid, username, ACLRegistry::Stream );
return;
bool found = false;
QMutableListIterator< ACLRegistry::User > i( m_cache );
while ( i.hasNext() )
@ -103,24 +110,13 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL
user.knownAccountIds.append( username );
if ( globalType != ACLRegistry::NotFound )
user.acl = globalType;
#ifndef ENABLE_HEADLESS
else
{
ACLRegistry::ACL acl = globalType;
tDebug( LOGVERBOSE ) << "ACL is intially" << acl;
#ifndef ENABLE_HEADLESS
acl = getUserDecision( username );
tDebug( LOGVERBOSE ) << "after getUserDecision acl is" << acl;
#endif
if ( acl == ACLRegistry::NotFound )
{
emit aclResult( dbid, username, acl );
return;
}
user.acl = acl;
{
getUserDecision( user );
return;
}
#endif
m_cache.append( user );
emit aclResult( dbid, username, user.acl );
return;
@ -128,39 +124,24 @@ ACLRegistry::isAuthorizedUser( const QString& dbid, const QString &username, ACL
#ifndef ENABLE_HEADLESS
#include <QMessageBox>
ACLRegistry::ACL
ACLRegistry::getUserDecision( const QString &username )
void
ACLRegistry::getUserDecision( User user )
{
return ACLRegistry::Stream;
QMessageBox msgBox;
msgBox.setIcon( QMessageBox::Question );
msgBox.setText( tr( "Connect to Peer?" ) );
msgBox.setInformativeText( tr( "Another Tomahawk instance that claims to be owned by %1 is attempting to connect to you. Select whether to allow or deny this connection.\n\nRemember: Only allow peers to connect if you trust who they are and if you have the legal right for them to stream music from you.").arg( username ) );
QPushButton *denyButton = msgBox.addButton( tr( "Deny" ), QMessageBox::YesRole );
QPushButton *allowButton = msgBox.addButton( tr( "Allow" ), QMessageBox::ActionRole );
msgBox.setDefaultButton( allowButton );
msgBox.setEscapeButton( denyButton );
msgBox.exec();
if( msgBox.clickedButton() == denyButton )
return ACLRegistry::Deny;
else if( msgBox.clickedButton() == allowButton )
return ACLRegistry::Stream;
//How could we get here?
tDebug( LOGVERBOSE ) << "ERROR: returning NotFound";
Q_ASSERT( false );
return ACLRegistry::NotFound;
AclJobItem* job = new AclJobItem( user );
connect( job, SIGNAL( userDecision( ACLRegistry::User ) ), this, SLOT( userDecision( ACLRegistry::User ) ) );
JobStatusView::instance()->model()->addJob( job );
}
#endif
void
ACLRegistry::userDecision( ACLRegistry::User user )
{
m_cache.append( user );
emit aclResult( user.knownDbids.first(), user.knownAccountIds.first(), user.acl );
}
void
ACLRegistry::load()
{

View File

@ -53,6 +53,7 @@ public:
User()
: uuid( QUuid::createUuid().toString() )
, acl( ACLRegistry::NotFound )
{}
User( QString p_uuid, QStringList p_knownDbids, QStringList p_knownAccountIds, ACL p_acl )
@ -80,10 +81,12 @@ public slots:
**/
void isAuthorizedUser( const QString &dbid, const QString &username, ACLRegistry::ACL globalType = ACLRegistry::NotFound );
#ifndef ENABLE_HEADLESS
ACLRegistry::ACL getUserDecision( const QString &username );
#endif
#ifndef ENABLE_HEADLESS
void getUserDecision( User user );
#endif
private slots:
void userDecision( ACLRegistry::User user );
private:
/**

View File

@ -0,0 +1,122 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 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 "AclJobItem.h"
#include "utils/tomahawkutils.h"
#include <QPixmap>
#include <QListView>
#include <QApplication>
#define ROW_HEIGHT 40
#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
{
/*
QStyleOptionViewItemV4 opt = option;
initStyleOption( &opt, index );
QFontMetrics fm( opt.font );
const bool allowMultiLine = index.data( JobStatusModel::AllowMultiLineRole ).toBool();
opt.state &= ~QStyle::State_MouseOver;
QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget );
// 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();
}
const int mainW = rightEdge - 3*PADDING - iconRect.right();
QString mainText = index.data( Qt::DisplayRole ).toString();
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 );
*/
}
QSize
AclJobDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
return QSize( QStyledItemDelegate::sizeHint ( option, index ).width(), ROW_HEIGHT );
}
AclJobItem::AclJobItem( ACLRegistry::User user )
: m_delegate( 0 )
, m_user( user )
{
}
AclJobItem::~AclJobItem()
{
if ( m_delegate )
delete m_delegate;
}
void
AclJobItem::createDelegate( QObject* parent )
{
if ( m_delegate )
return;
m_delegate = new AclJobDelegate( parent );
}
void
AclJobItem::done()
{
emit finished();
}

View File

@ -0,0 +1,77 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 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 ACLJOBITEM_H
#define ACLJOBITEM_H
#include <jobview/JobStatusItem.h>
#include "aclregistry.h"
#include <QStyledItemDelegate>
class QListView;
class AclJobDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit AclJobDelegate ( QObject* parent = 0 );
virtual ~AclJobDelegate() {}
virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
private:
mutable QHash< QPersistentModelIndex, int > m_cachedMultiLineHeights;
QListView* m_parentView;
};
class AclJobItem : public JobStatusItem
{
Q_OBJECT
public:
explicit AclJobItem( ACLRegistry::User user );
virtual ~AclJobItem();
void done();
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 );
virtual QStyledItemDelegate* customDelegate() const { return m_delegate; }
virtual ACLRegistry::User user() const { return m_user; }
signals:
void userDecision( ACLRegistry::User user );
private:
QStyledItemDelegate* m_delegate;
ACLRegistry::User m_user;
};
#endif // ACLJOBITEM_H

View File

@ -31,12 +31,44 @@ JobStatusItem::~JobStatusItem()
}
bool JobStatusItem::allowMultiLine() const
bool
JobStatusItem::allowMultiLine() const
{
return false;
}
bool JobStatusItem::collapseItem() const
bool
JobStatusItem::collapseItem() const
{
return false;
}
int
JobStatusItem::concurrentJobLimit() const
{
return 0;
}
bool
JobStatusItem::hasCustomDelegate() const
{
return false;
}
void
JobStatusItem::createDelegate( QObject* parent )
{
Q_UNUSED( parent );
return;
}
QStyledItemDelegate*
JobStatusItem::customDelegate() const
{
return 0;
}

View File

@ -20,7 +20,9 @@
#define JOB_STATUS_ITEM
#include <QObject>
#include <QMetaType>
class QStyledItemDelegate;
class QPixmap;
/**
@ -56,6 +58,12 @@ public:
virtual bool collapseItem() const;
virtual bool allowMultiLine() const;
virtual int concurrentJobLimit() const;
virtual bool hasCustomDelegate() const;
virtual void createDelegate( QObject* parent );
virtual QStyledItemDelegate* customDelegate() const;
signals:
/// Ask for an update
void statusChanged();
@ -64,4 +72,6 @@ signals:
void finished();
};
Q_DECLARE_METATYPE( JobStatusItem* );
#endif

View File

@ -41,6 +41,19 @@ JobStatusModel::~JobStatusModel()
void
JobStatusModel::addJob( JobStatusItem* item )
{
if ( item->concurrentJobLimit() > 0 )
{
if ( m_jobTypeCount[ item->type() ] >= item->concurrentJobLimit() )
{
m_jobQueue[ item->type() ].enqueue( item );
return;
}
int currentJobCount = m_jobTypeCount[ item->type() ];
currentJobCount++;
m_jobTypeCount[ item->type() ] = currentJobCount;
}
connect( item, SIGNAL( statusChanged() ), this, SLOT( itemUpdated() ) );
connect( item, SIGNAL( finished() ), this, SLOT( itemFinished() ) );
@ -60,9 +73,12 @@ JobStatusModel::addJob( JobStatusItem* item )
}
qDebug() << "Adding item:" << item;
beginInsertRows( QModelIndex(), m_items.count(), m_items.count() );
int currentEndRow = m_items.count();
beginInsertRows( QModelIndex(), currentEndRow, currentEndRow );
m_items.append( item );
endInsertRows();
if ( item->hasCustomDelegate() )
emit customDelegateJobInserted( currentEndRow, item );
}
@ -85,25 +101,32 @@ JobStatusModel::data( const QModelIndex& index, int role ) const
switch ( role )
{
case Qt::DecorationRole:
return item->icon();
case Qt::ToolTipRole:
case Qt::DisplayRole:
{
if ( m_collapseCount.contains( item->type() ) )
return m_collapseCount[ item->type() ].last()->mainText();
else
return item->mainText();
}
case RightColumnRole:
{
if ( m_collapseCount.contains( item->type() ) )
return m_collapseCount[ item->type() ].count();
else
return item->rightColumnText();
}
case AllowMultiLineRole:
return item->allowMultiLine();
case Qt::DecorationRole:
return item->icon();
case Qt::ToolTipRole:
case Qt::DisplayRole:
{
if ( m_collapseCount.contains( item->type() ) )
return m_collapseCount[ item->type() ].last()->mainText();
else
return item->mainText();
}
case RightColumnRole:
{
if ( m_collapseCount.contains( item->type() ) )
return m_collapseCount[ item->type() ].count();
else
return item->rightColumnText();
}
case AllowMultiLineRole:
return item->allowMultiLine();
case JobDataRole:
return QVariant::fromValue< JobStatusItem* >( item );
}
return QVariant();
@ -171,6 +194,22 @@ JobStatusModel::itemFinished()
m_items.removeAll( item );
endRemoveRows();
if ( item->customDelegate() )
emit customDelegateJobRemoved( idx );
if ( item->concurrentJobLimit() > 0 )
{
int currentJobs = m_jobTypeCount[ item->type() ];
currentJobs--;
m_jobTypeCount[ item->type() ] = currentJobs;
if ( !m_jobQueue[ item->type() ].isEmpty() )
{
JobStatusItem* item = m_jobQueue[ item->type() ].dequeue();
QMetaObject::invokeMethod( this, "addJob", Qt::QueuedConnection, Q_ARG( JobStatusItem*, item ) );
}
}
item->deleteLater();
}

View File

@ -22,8 +22,11 @@
#include "dllmacro.h"
#include <QModelIndex>
#include <QQueue>
class QStyledItemDelegate;
class JobStatusItem;
class DLLEXPORT JobStatusModel : public QAbstractListModel
{
Q_OBJECT
@ -32,7 +35,8 @@ public:
// DecorationRole is icon
// DisplayRole is main col
RightColumnRole = Qt::UserRole + 1,
AllowMultiLineRole = Qt::UserRole + 2
AllowMultiLineRole = Qt::UserRole + 2,
JobDataRole = Qt::UserRole + 3
};
explicit JobStatusModel( QObject* parent = 0 );
@ -42,9 +46,14 @@ public:
virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const;
signals:
void customDelegateJobInserted( int row, JobStatusItem* item );
void customDelegateJobRemoved( int row );
public slots:
/// Takes ownership of job
void addJob( JobStatusItem* item );
private slots:
void itemUpdated();
void itemFinished();
@ -52,6 +61,8 @@ private slots:
private:
QList< JobStatusItem* > m_items;
QHash< QString, QList< JobStatusItem* > > m_collapseCount;
QHash< QString, QQueue< JobStatusItem* > > m_jobQueue;
QHash< QString, int > m_jobTypeCount;
};
#endif // JOBSTATUSMODEL_H

View File

@ -21,6 +21,7 @@
#include "pipeline.h"
#include "JobStatusModel.h"
#include "JobStatusItem.h"
#include "JobStatusDelegate.h"
#include "PipelineStatusItem.h"
#include "TransferStatusItem.h"
@ -86,6 +87,26 @@ JobStatusView::setModel( JobStatusModel* m )
connect( m_view->model(), SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( checkCount() ) );
connect( m_view->model(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( checkCount() ) );
connect( m_view->model(), SIGNAL( modelReset() ), this, SLOT( checkCount() ) );
connect( m_view->model(), SIGNAL( customDelegateJobInserted( int, QStyledItemDelegate* ) ), this, SLOT( customDelegateJobInserted( int, QStyledItemDelegate* ) ) );
connect( m_view->model(), SIGNAL( customDelegateJobRemoved( int, QStyledItemDelegate* ) ), this, SLOT( customDelegateJobRemoved( int, QStyledItemDelegate* ) ) );
}
void
JobStatusView::customDelegateJobInserted( int row, JobStatusItem* item )
{
if ( !item )
return;
item->createDelegate( m_view );
m_view->setItemDelegateForRow( row, item->customDelegate() );
}
void
JobStatusView::customDelegateJobRemoved( int row )
{
m_view->setItemDelegateForRow( row, m_view->itemDelegate() );
}

View File

@ -27,7 +27,9 @@
class QAbstractItemModel;
class QListView;
class JobStatusModel;
class JobStatusItem;
class StreamConnection;
class QStyledItemDelegate;
class DLLEXPORT JobStatusView : public AnimatedWidget
{
@ -51,6 +53,8 @@ public:
private slots:
void checkCount();
void customDelegateJobInserted( int row, JobStatusItem* item );
void customDelegateJobRemoved( int row );
private:
QListView* m_view;

View File

@ -49,7 +49,7 @@ TomahawkSettings::TomahawkSettings( QObject* parent )
#ifdef Q_OS_LINUX
QFile file( fileName() );
file.setPermissions( file.permissions() & ~(QFile::ReadGroup | QFile::WriteGroup | QFile::ExeGroup | QFile::ReadOther | QFile::WriteOther | QFile::ExeOther ) );
file.setPermissions( file.permissions() & ~( QFile::ReadGroup | QFile::WriteGroup | QFile::ExeGroup | QFile::ReadOther | QFile::WriteOther | QFile::ExeOther ) );
#endif
if ( !contains( "configversion" ) )

View File

@ -409,6 +409,7 @@ TomahawkApp::registerMetaTypes()
qRegisterMetaType< QHash< QString, QMap<quint32, quint16> > >("QHash< QString, QMap<quint32, quint16> >");
qRegisterMetaType< QMap< QString, QMap< unsigned int, unsigned int > > >("QMap< QString, QMap< unsigned int, unsigned int > >");
qRegisterMetaType< PairList >("PairList");
qRegisterMetaType< JobStatusItem* >("JobStatusItem*");
qRegisterMetaType< GeneratorMode>("GeneratorMode");
qRegisterMetaType<Tomahawk::GeneratorMode>("Tomahawk::GeneratorMode");