mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 00:09:47 +01:00
Initial work towards merging accounts into GetNewStuffModel
This commit is contained in:
parent
39c7af6262
commit
e319aa248c
@ -111,28 +111,31 @@ GetNewStuffDelegate::paint( QPainter* painter, const QStyleOptionViewItem& optio
|
||||
// Go from right edge now, stars, install button, and downloaded info
|
||||
|
||||
// install / status button
|
||||
AtticaManager::ResolverState state = static_cast< AtticaManager::ResolverState >( index.data( GetNewStuffModel::StateRole ).toInt() );
|
||||
GetNewStuffModel::ItemState state = static_cast< GetNewStuffModel::ItemState >( index.data( GetNewStuffModel::StateRole ).toInt() );
|
||||
QString actionText;
|
||||
switch( state )
|
||||
{
|
||||
case AtticaManager::Uninstalled:
|
||||
case GetNewStuffModel::Uninstalled:
|
||||
actionText = tr( "Install" );
|
||||
break;
|
||||
case AtticaManager::Installing:
|
||||
case GetNewStuffModel::Installing:
|
||||
actionText = tr( "Installing" );
|
||||
break;
|
||||
case AtticaManager::Upgrading:
|
||||
case GetNewStuffModel::Upgrading:
|
||||
actionText = tr( "Upgrading" );
|
||||
break;
|
||||
case AtticaManager::Failed:
|
||||
case GetNewStuffModel::Failed:
|
||||
actionText = tr( "Failed" );
|
||||
break;
|
||||
case AtticaManager::Installed:
|
||||
case GetNewStuffModel::Installed:
|
||||
actionText = tr( "Uninstall" );
|
||||
break;
|
||||
case AtticaManager::NeedsUpgrade:
|
||||
case GetNewStuffModel::NeedsUpgrade:
|
||||
actionText = tr( "Upgrade" );
|
||||
break;
|
||||
case GetNewStuffModel::CanInstallMore:
|
||||
actionText = tr( "Install Another" );
|
||||
break;
|
||||
}
|
||||
|
||||
const int btnWidth = m_widestTextWidth + 7;
|
||||
|
@ -21,6 +21,9 @@
|
||||
#include "ui_GetNewStuffDialog.h"
|
||||
#include "GetNewStuffDelegate.h"
|
||||
#include "GetNewStuffModel.h"
|
||||
#include "tomahawksettings.h"
|
||||
|
||||
#include <QtGui/QFileDialog>
|
||||
|
||||
GetNewStuffDialog::GetNewStuffDialog( QWidget* parent, Qt::WindowFlags f )
|
||||
: QDialog( parent, f )
|
||||
@ -29,13 +32,13 @@ GetNewStuffDialog::GetNewStuffDialog( QWidget* parent, Qt::WindowFlags f )
|
||||
{
|
||||
ui->setupUi( this );
|
||||
|
||||
ui->listView->setModel( m_model );
|
||||
GetNewStuffDelegate* del = new GetNewStuffDelegate( ui->listView );
|
||||
connect( del, SIGNAL( update( QModelIndex ) ), ui->listView, SLOT( update( QModelIndex ) ) );
|
||||
ui->listView->setItemDelegate( del );
|
||||
ui->listView->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
|
||||
ui->accountsList->setModel( m_model );
|
||||
GetNewStuffDelegate* del = new GetNewStuffDelegate( ui->accountsList );
|
||||
connect( del, SIGNAL( update( QModelIndex ) ), ui->accountsList, SLOT( update( QModelIndex ) ) );
|
||||
ui->accountsList->setItemDelegate( del );
|
||||
ui->accountsList->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
|
||||
|
||||
ui->listView->setMouseTracking( true );
|
||||
ui->accountsList->setMouseTracking( true );
|
||||
|
||||
setMinimumSize( 560, 350 );
|
||||
|
||||
@ -43,8 +46,10 @@ GetNewStuffDialog::GetNewStuffDialog( QWidget* parent, Qt::WindowFlags f )
|
||||
setMaximumSize( 560, 350 );
|
||||
setSizeGripEnabled( false );
|
||||
|
||||
ui->listView->setAttribute( Qt::WA_MacShowFocusRect, false );
|
||||
ui->accountsList->setAttribute( Qt::WA_MacShowFocusRect, false );
|
||||
#endif
|
||||
|
||||
connect( ui->installFromFileBtn, SIGNAL( clicked( bool ) ), this, SLOT( installFromFile() ) );
|
||||
}
|
||||
|
||||
|
||||
@ -52,3 +57,19 @@ GetNewStuffDialog::~GetNewStuffDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GetNewStuffDialog::installFromFile()
|
||||
{
|
||||
QString resolver = QFileDialog::getOpenFileName( this, tr( "Load script resolver file" ), TomahawkSettings::instance()->scriptDefaultPath() );
|
||||
|
||||
// m_resolversModel->addResolver( resolver, true );
|
||||
// TODO
|
||||
if( !resolver.isEmpty() )
|
||||
{
|
||||
|
||||
QFileInfo resolverAbsoluteFilePath = resolver;
|
||||
TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() );
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,9 @@ public:
|
||||
explicit GetNewStuffDialog( QWidget *parent = 0, Qt::WindowFlags f = 0 );
|
||||
~GetNewStuffDialog();
|
||||
|
||||
private slots:
|
||||
void installFromFile();
|
||||
|
||||
private:
|
||||
Ui::GetNewStuffDialog *ui;
|
||||
GetNewStuffModel* m_model;
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>449</width>
|
||||
<height>282</height>
|
||||
<height>327</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -15,17 +15,41 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QListView" name="listView"/>
|
||||
<widget class="QListView" name="accountsList"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="installFromFileBtn">
|
||||
<property name="text">
|
||||
<string>Install from file...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
@ -20,32 +20,73 @@
|
||||
|
||||
#include "utils/tomahawkutils.h"
|
||||
#include "utils/logger.h"
|
||||
#include "AtticaManager.h"
|
||||
#include "accounts/AccountManager.h"
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QUrl>
|
||||
#include "AtticaManager.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
using namespace Accounts;
|
||||
|
||||
GetNewStuffModel::GetNewStuffModel( QObject* parent )
|
||||
: QAbstractListModel ( parent )
|
||||
{
|
||||
|
||||
if ( AtticaManager::instance()->resolversLoaded() )
|
||||
m_contentList = AtticaManager::instance()->resolvers();
|
||||
|
||||
connect( AtticaManager::instance(), SIGNAL( resolversReloaded( Attica::Content::List ) ), this, SLOT( resolversReloaded( Attica::Content::List ) ) );
|
||||
connect( AtticaManager::instance(), SIGNAL( resolverStateChanged( QString ) ), this, SLOT( resolverStateChanged( QString ) ) );
|
||||
|
||||
loadData();
|
||||
}
|
||||
|
||||
GetNewStuffModel::~GetNewStuffModel()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
GetNewStuffModel::loadData()
|
||||
{
|
||||
foreach ( const QVariant& content, m_contentList )
|
||||
{
|
||||
if ( !isAttica( content ) )
|
||||
{
|
||||
AccountItem* item = content.value< GetNewStuffModel::AccountItem* >();
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
m_contentList.clear();
|
||||
|
||||
Attica::Content::List fromAttica = AtticaManager::instance()->resolvers();
|
||||
foreach ( const Attica::Content& content, fromAttica )
|
||||
m_contentList.append( QVariant::fromValue< Attica::Content >( content ) );
|
||||
|
||||
QList< AccountFactory* > factories = AccountManager::instance()->factories();
|
||||
QList< Account* > allAccounts = AccountManager::instance()->accounts();
|
||||
foreach ( AccountFactory* fac, factories )
|
||||
{
|
||||
if ( !fac->allowUserCreation() )
|
||||
continue;
|
||||
|
||||
AccountItem* item = new AccountItem;
|
||||
item->factory = fac;
|
||||
|
||||
foreach ( Account* acct, allAccounts )
|
||||
{
|
||||
if ( AccountManager::instance()->factoryForAccount( acct ) == fac )
|
||||
item->alreadyExists = true;
|
||||
else
|
||||
item->alreadyExists = false;
|
||||
}
|
||||
|
||||
m_contentList.append( QVariant::fromValue< GetNewStuffModel::AccountItem* >( item ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GetNewStuffModel::resolversReloaded( const Attica::Content::List& resolvers )
|
||||
{
|
||||
beginResetModel();
|
||||
m_contentList = resolvers;
|
||||
loadData();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
@ -54,7 +95,10 @@ GetNewStuffModel::resolverStateChanged( const QString& resolverId )
|
||||
{
|
||||
for ( int i = 0; i < m_contentList.count(); i++ )
|
||||
{
|
||||
const Attica::Content resolver = m_contentList[ i ];
|
||||
if ( !isAttica( m_contentList.at( i ) ) )
|
||||
continue;
|
||||
|
||||
const Attica::Content resolver = atticaFromItem( m_contentList.at( i ) );
|
||||
if ( resolver.id() == resolverId )
|
||||
{
|
||||
QModelIndex idx = index( i, 0, QModelIndex() );
|
||||
@ -70,33 +114,82 @@ GetNewStuffModel::data( const QModelIndex& index, int role ) const
|
||||
if ( !index.isValid() || !hasIndex( index.row(), index.column(), index.parent() ) )
|
||||
return QVariant();
|
||||
|
||||
Attica::Content resolver = m_contentList[ index.row() ];
|
||||
switch ( role )
|
||||
if ( isAttica( m_contentList.at( index.row() ) ) )
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
return resolver.name();
|
||||
case Qt::DecorationRole:
|
||||
return QVariant::fromValue< QPixmap >( AtticaManager::instance()->iconForResolver( resolver ) );
|
||||
case DownloadUrlRole:
|
||||
// TODO
|
||||
return QUrl();
|
||||
case RatingRole:
|
||||
return resolver.rating() / 20; // rating is out of 100
|
||||
case DownloadCounterRole:
|
||||
return resolver.downloads();
|
||||
case VersionRole:
|
||||
return resolver.version();
|
||||
case DescriptionRole:
|
||||
return resolver.description();
|
||||
case TypeRole:
|
||||
return ResolverType;
|
||||
case AuthorRole:
|
||||
return resolver.author();
|
||||
case StateRole:
|
||||
return (int)AtticaManager::instance()->resolverState( resolver );
|
||||
case UserHasRatedRole:
|
||||
return AtticaManager::instance()->userHasRated( resolver );
|
||||
const Attica::Content resolver = atticaFromItem( m_contentList.at( index.row() ) );
|
||||
switch ( role )
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
return resolver.name();
|
||||
case Qt::DecorationRole:
|
||||
return QVariant::fromValue< QPixmap >( AtticaManager::instance()->iconForResolver( resolver ) );
|
||||
case DownloadUrlRole:
|
||||
// TODO
|
||||
return QUrl();
|
||||
case RatingRole:
|
||||
return resolver.rating() / 20; // rating is out of 100
|
||||
case DownloadCounterRole:
|
||||
return resolver.downloads();
|
||||
case VersionRole:
|
||||
return resolver.version();
|
||||
case DescriptionRole:
|
||||
return resolver.description();
|
||||
case TypeRole:
|
||||
return AtticaType;
|
||||
case AuthorRole:
|
||||
return resolver.author();
|
||||
case StateRole:
|
||||
return (int)AtticaManager::instance()->resolverState( resolver );
|
||||
case UserHasRatedRole:
|
||||
return AtticaManager::instance()->userHasRated( resolver );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Account, not from Attica
|
||||
AccountItem* item = accountFromItem( m_contentList.at( index.row() ) );
|
||||
Q_ASSERT( item );
|
||||
switch ( role )
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
return item->factory->prettyName();
|
||||
case Qt::DecorationRole:
|
||||
return QVariant::fromValue< QPixmap >( item->factory->icon() );
|
||||
case RatingRole:
|
||||
// TODO
|
||||
return 3;
|
||||
// return resolver.rating() / 20; // rating is out of 100
|
||||
case DownloadCounterRole:
|
||||
// TODO
|
||||
return 10;
|
||||
// return resolver.downloads();
|
||||
case VersionRole:
|
||||
return "1.0";
|
||||
// return resolver.version();
|
||||
case DescriptionRole:
|
||||
return item->factory->description();
|
||||
case TypeRole:
|
||||
return AccountType;
|
||||
case AuthorRole:
|
||||
return "Tomahawk Developers";
|
||||
case StateRole:
|
||||
{
|
||||
GetNewStuffModel::ItemState state = Uninstalled;
|
||||
if ( item->factory->isUnique() && item->alreadyExists )
|
||||
state = Installed;
|
||||
else if ( !item->factory->isUnique() && item->alreadyExists )
|
||||
state = CanInstallMore;
|
||||
else if ( !item->alreadyExists )
|
||||
state = Uninstalled;
|
||||
return (int)state;
|
||||
}
|
||||
case UserHasRatedRole:
|
||||
// TODO
|
||||
return true;
|
||||
// return AtticaManager::instance()->userHasRated( resolver );
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
@ -114,43 +207,84 @@ GetNewStuffModel::setData( const QModelIndex &index, const QVariant &value, int
|
||||
if ( !hasIndex( index.row(), index.column(), index.parent() ) )
|
||||
return false;
|
||||
|
||||
|
||||
Attica::Content resolver = m_contentList[ index.row() ];
|
||||
AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( resolver );
|
||||
if ( role == Qt::EditRole )
|
||||
if ( isAttica( m_contentList.at( index.row() ) ) )
|
||||
{
|
||||
switch( state )
|
||||
Attica::Content resolver = atticaFromItem( m_contentList.at( index.row() ) );
|
||||
AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( resolver );
|
||||
if ( role == Qt::EditRole )
|
||||
{
|
||||
case AtticaManager::Uninstalled:
|
||||
// install
|
||||
AtticaManager::instance()->installResolver( resolver );
|
||||
break;
|
||||
case AtticaManager::Installing:
|
||||
case AtticaManager::Upgrading:
|
||||
// Do nothing, busy
|
||||
break;
|
||||
case AtticaManager::Installed:
|
||||
// Uninstall
|
||||
AtticaManager::instance()->uninstallResolver( resolver );
|
||||
break;
|
||||
case AtticaManager::NeedsUpgrade:
|
||||
AtticaManager::instance()->upgradeResolver( resolver );
|
||||
break;
|
||||
default:
|
||||
//FIXME -- this handles e.g. Failed
|
||||
break;
|
||||
};
|
||||
} else if ( role == RatingRole )
|
||||
{
|
||||
// For now only allow rating if a resolver is installed!
|
||||
if ( state != AtticaManager::Installed && state != AtticaManager::NeedsUpgrade )
|
||||
return false;
|
||||
if ( AtticaManager::instance()->userHasRated( resolver ) )
|
||||
return false;
|
||||
m_contentList[ index.row() ].setRating( value.toInt() * 20 );
|
||||
AtticaManager::instance()->uploadRating( m_contentList[ index.row() ] );
|
||||
switch( state )
|
||||
{
|
||||
case AtticaManager::Uninstalled:
|
||||
// install
|
||||
AtticaManager::instance()->installResolver( resolver );
|
||||
break;
|
||||
case AtticaManager::Installing:
|
||||
case AtticaManager::Upgrading:
|
||||
// Do nothing, busy
|
||||
break;
|
||||
case AtticaManager::Installed:
|
||||
// Uninstall
|
||||
AtticaManager::instance()->uninstallResolver( resolver );
|
||||
break;
|
||||
case AtticaManager::NeedsUpgrade:
|
||||
AtticaManager::instance()->upgradeResolver( resolver );
|
||||
break;
|
||||
default:
|
||||
//FIXME -- this handles e.g. Failed
|
||||
break;
|
||||
};
|
||||
} else if ( role == RatingRole )
|
||||
{
|
||||
// For now only allow rating if a resolver is installed!
|
||||
if ( state != AtticaManager::Installed && state != AtticaManager::NeedsUpgrade )
|
||||
return false;
|
||||
if ( AtticaManager::instance()->userHasRated( resolver ) )
|
||||
return false;
|
||||
resolver.setRating( value.toInt() * 20 );
|
||||
m_contentList[ index.row() ] = QVariant::fromValue< Attica::Content >( resolver );
|
||||
AtticaManager::instance()->uploadRating( resolver );
|
||||
}
|
||||
emit dataChanged( index, index );
|
||||
}
|
||||
else
|
||||
{
|
||||
AccountItem* item = accountFromItem( m_contentList.at( index.row() ) );
|
||||
if ( role == Qt::EditRole )
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
else if ( role == RatingRole )
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
emit dataChanged( index, index );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GetNewStuffModel::isAttica( const QVariant& item ) const
|
||||
{
|
||||
return qstrcmp( item.typeName(),"Attica::Content" ) == 0;
|
||||
}
|
||||
|
||||
|
||||
GetNewStuffModel::AccountItem*
|
||||
GetNewStuffModel::accountFromItem( const QVariant& item ) const
|
||||
{
|
||||
Q_ASSERT( !isAttica( item ) );
|
||||
|
||||
return item.value< GetNewStuffModel::AccountItem* >();
|
||||
}
|
||||
|
||||
|
||||
Attica::Content
|
||||
GetNewStuffModel::atticaFromItem( const QVariant& item ) const
|
||||
{
|
||||
Q_ASSERT( isAttica( item ) );
|
||||
|
||||
return item.value< Attica::Content >();
|
||||
|
||||
}
|
||||
|
@ -19,14 +19,17 @@
|
||||
#ifndef GETNEWSTUFFMODEL_H
|
||||
#define GETNEWSTUFFMODEL_H
|
||||
|
||||
#include <QModelIndex>
|
||||
#include "accounts/Account.h"
|
||||
|
||||
#include <attica/content.h>
|
||||
|
||||
#include <QModelIndex>
|
||||
#include <QPixmap>
|
||||
|
||||
class GetNewStuffModel: public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum NewStuffRoles {
|
||||
// DisplayRole is title
|
||||
@ -43,9 +46,26 @@ public:
|
||||
};
|
||||
|
||||
enum Types {
|
||||
ResolverType = 0,
|
||||
AtticaType = 0,
|
||||
AccountType = 1
|
||||
};
|
||||
|
||||
enum ItemState {
|
||||
Uninstalled = 0,
|
||||
Installing,
|
||||
Installed,
|
||||
NeedsUpgrade,
|
||||
Upgrading,
|
||||
Failed,
|
||||
CanInstallMore, // accounts that are not unique
|
||||
};
|
||||
|
||||
// plz don't use me kthxbbq
|
||||
typedef struct {
|
||||
Tomahawk::Accounts::AccountFactory* factory;
|
||||
bool alreadyExists;
|
||||
} AccountItem;
|
||||
|
||||
explicit GetNewStuffModel( QObject* parent = 0 );
|
||||
virtual ~GetNewStuffModel();
|
||||
|
||||
@ -58,7 +78,14 @@ private slots:
|
||||
void resolverStateChanged( const QString& resolverId );
|
||||
|
||||
private:
|
||||
Attica::Content::List m_contentList;
|
||||
void loadData();
|
||||
bool isAttica( const QVariant& item ) const;
|
||||
Attica::Content atticaFromItem( const QVariant& item ) const;
|
||||
AccountItem* accountFromItem( const QVariant& item ) const;
|
||||
|
||||
QVariantList m_contentList;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE( GetNewStuffModel::AccountItem* );
|
||||
|
||||
#endif // GETNEWSTUFFMODEL_H
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
|
||||
QString prettyName() const { return "Twitter"; }
|
||||
QString factoryId() const { return "twitteraccount"; }
|
||||
QString description() const { return tr( "Connect to your Twitter followers." ); }
|
||||
QPixmap icon() const { return QPixmap( ":/twitter-icon.png" ); }
|
||||
Account* createAccount( const QString& pluginId = QString() );
|
||||
};
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
|
||||
virtual QString prettyName() const { return "Google"; }
|
||||
virtual QString factoryId() const { return "googleaccount"; }
|
||||
QString description() const { return tr( "Connect to GChat to find your friends" ); }
|
||||
virtual QPixmap icon() const;
|
||||
virtual Account* createAccount( const QString& pluginId );
|
||||
};
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
virtual ~XmppAccountFactory() {}
|
||||
|
||||
QString prettyName() const { return "XMPP (Jabber)"; }
|
||||
QString description() const { return tr( "Log on to your Jabber/XMPP account to connect to your friends" ); }
|
||||
QString factoryId() const { return "xmppaccount"; }
|
||||
QPixmap icon() const { return QPixmap( ":/xmpp-icon.png" ); }
|
||||
Account* createAccount( const QString& pluginId = QString() );
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
|
||||
virtual QString factoryId() const { return "zeroconfaccount"; }
|
||||
virtual QString prettyName() const { return "Local Network"; }
|
||||
QString description() const { return tr( "Automatically connect to Tomahawks on the local network" ); }
|
||||
virtual bool isUnique() const { return true; }
|
||||
#ifndef ENABLE_HEADLESS
|
||||
virtual QPixmap icon() const;
|
||||
|
@ -165,10 +165,14 @@ public:
|
||||
virtual QString prettyName() const = 0;
|
||||
// internal name
|
||||
virtual QString factoryId() const = 0;
|
||||
// description to be shown when user views a list of account types
|
||||
virtual QString description() const = 0;
|
||||
// if the user can create multiple
|
||||
virtual QPixmap icon() const { return QPixmap(); }
|
||||
virtual bool isUnique() const { return false; }
|
||||
|
||||
virtual QPixmap icon() const { return QPixmap(); }
|
||||
virtual bool allowUserCreation() const { return true; }
|
||||
|
||||
virtual Account* createAccount( const QString& accountId = QString() ) = 0;
|
||||
};
|
||||
|
||||
|
@ -36,7 +36,9 @@ public:
|
||||
|
||||
virtual Account* createAccount(const QString& accountId = QString());
|
||||
virtual QString factoryId() const { return "resolveraccount"; }
|
||||
virtual QString description() const { return QString(); }
|
||||
virtual QString prettyName() const { return QString(); } // Internal, not displayed
|
||||
virtual bool allowUserCreation() const { return false; }
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -61,14 +61,6 @@
|
||||
using namespace Tomahawk;
|
||||
using namespace Accounts;
|
||||
|
||||
static QString
|
||||
md5( const QByteArray& src )
|
||||
{
|
||||
QByteArray const digest = QCryptographicHash::hash( src, QCryptographicHash::Md5 );
|
||||
return QString::fromLatin1( digest.toHex() ).rightJustified( 32, '0' );
|
||||
}
|
||||
|
||||
|
||||
SettingsDialog::SettingsDialog( QWidget *parent )
|
||||
: QDialog( parent )
|
||||
, ui( new Ui_StackedSettingsDialog )
|
||||
@ -83,9 +75,6 @@ SettingsDialog::SettingsDialog( QWidget *parent )
|
||||
TomahawkUtils::unmarginLayout( layout() );
|
||||
ui->stackedWidget->setContentsMargins( 4, 4, 4, 0 );
|
||||
|
||||
ui->addScript->setFixedWidth( 42 );
|
||||
ui->removeScript->setFixedWidth( ui->addScript->width() );
|
||||
|
||||
ui->checkBoxReporter->setChecked( s->crashReporterEnabled() );
|
||||
ui->checkBoxHttp->setChecked( s->httpEnabled() );
|
||||
ui->checkBoxStaticPreferred->setChecked( s->preferStaticHostPort() );
|
||||
@ -123,6 +112,14 @@ SettingsDialog::SettingsDialog( QWidget *parent )
|
||||
m_accountModel = new AccountModel( this );
|
||||
ui->accountsView->setModel( m_accountModel );
|
||||
|
||||
connect( ui->addNewServiceBtn, SIGNAL( clicked( bool ) ), this, SLOT( getMoreResolvers() ) );
|
||||
connect( ui->removeServiceBtn, SIGNAL( clicked( bool ) ), this, SLOT( accountDeleted( bool ) ) );
|
||||
|
||||
connect( AtticaManager::instance(), SIGNAL( resolverInstalled( QString ) ), this, SLOT( accountAdded( Tomahawk::Accounts::Account* ) ) );
|
||||
connect( AtticaManager::instance(), SIGNAL( resolverUninstalled( QString ) ), this, SLOT( accountUninstalled( QString ) ) );
|
||||
|
||||
connect( ui->accountsView->selectionModel(), SIGNAL( selectionChanged( QItemSelection,QItemSelection ) ), this, SLOT( accountsSelectionChanged() ) );
|
||||
|
||||
if ( !Servent::instance()->isReady() )
|
||||
{
|
||||
m_sipSpinner = new LoadingSpinner( ui->accountsView );
|
||||
@ -132,9 +129,6 @@ SettingsDialog::SettingsDialog( QWidget *parent )
|
||||
ui->removeServiceBtn->setEnabled( false );
|
||||
connect( Servent::instance(), SIGNAL( ready() ), this, SLOT( serventReady() ) );
|
||||
}
|
||||
|
||||
setupAccountButtons();
|
||||
|
||||
ui->staticHostName->setText( s->externalHostname() );
|
||||
ui->staticPort->setValue( s->externalPort() );
|
||||
ui->proxyButton->setVisible( true );
|
||||
@ -178,18 +172,6 @@ SettingsDialog::SettingsDialog( QWidget *parent )
|
||||
ui->pushButtonTestLastfmLogin->setVisible( false );
|
||||
#endif
|
||||
|
||||
// SCRIPT RESOLVER
|
||||
ui->removeScript->setEnabled( false );
|
||||
ui->scriptList->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
|
||||
|
||||
connect( ui->getMoreResolvers, SIGNAL( clicked() ), this, SLOT( getMoreResolvers() ) );
|
||||
|
||||
connect( AtticaManager::instance(), SIGNAL( resolverInstalled( QString ) ), this, SLOT( atticaResolverInstalled( QString ) ) );
|
||||
connect( AtticaManager::instance(), SIGNAL( resolverUninstalled( QString ) ), this, SLOT( atticaResolverUninstalled( QString ) ) );
|
||||
|
||||
connect( ui->scriptList->selectionModel(), SIGNAL( selectionChanged( QItemSelection,QItemSelection ) ), this, SLOT( scriptSelectionChanged() ) );
|
||||
connect( ui->addScript, SIGNAL( clicked( bool ) ), this, SLOT( addScriptResolver() ) );
|
||||
connect( ui->removeScript, SIGNAL( clicked( bool ) ), this, SLOT( removeScriptResolver() ) );
|
||||
connect( ui->proxyButton, SIGNAL( clicked() ), SLOT( showProxySettings() ) );
|
||||
connect( ui->checkBoxStaticPreferred, SIGNAL( toggled(bool) ), SLOT( toggleUpnp(bool) ) );
|
||||
connect( ui->checkBoxStaticPreferred, SIGNAL( toggled(bool) ), SLOT( requiresRestart() ) );
|
||||
@ -244,7 +226,7 @@ SettingsDialog::serventReady()
|
||||
{
|
||||
m_sipSpinner->fadeOut();
|
||||
ui->addNewServiceBtn->setEnabled( true );
|
||||
ui->removeScript->setEnabled( true );
|
||||
ui->removeServiceBtn->setEnabled( true );
|
||||
}
|
||||
|
||||
|
||||
@ -310,27 +292,6 @@ SettingsDialog::createIcons()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsDialog::setupAccountButtons()
|
||||
{
|
||||
// foreach( AccountFactory* f, AccountManager::instance()->factories() )
|
||||
// {
|
||||
// if( f->isUnique() && AccountManager::instance()->hasPluginWithFactory( f->factoryId() ) )
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// QAction* action = new QAction( f->icon(), f->prettyName(), ui->addSipButton );
|
||||
// action->setProperty( "factory", QVariant::fromValue< QObject* >( f ) );
|
||||
// ui->addSipButton->addAction( action );
|
||||
//
|
||||
// connect( action, SIGNAL( triggered(bool) ), this, SLOT( factoryActionTriggered( bool ) ) );
|
||||
// }
|
||||
|
||||
connect( ui->removeServiceBtn, SIGNAL( clicked( bool ) ), this, SLOT( accountDeleted( bool ) ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsDialog::changePage( QListWidgetItem* current, QListWidgetItem* previous )
|
||||
{
|
||||
@ -470,32 +431,6 @@ SettingsDialog::onLastFmFinished()
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
void
|
||||
SettingsDialog::addScriptResolver()
|
||||
{
|
||||
QString resolver = QFileDialog::getOpenFileName( this, tr( "Load script resolver file" ), TomahawkSettings::instance()->scriptDefaultPath() );
|
||||
if( !resolver.isEmpty() )
|
||||
{
|
||||
|
||||
QFileInfo resolverAbsoluteFilePath = resolver;
|
||||
TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsDialog::removeScriptResolver()
|
||||
{
|
||||
// only one selection
|
||||
if( !ui->scriptList->selectionModel()->selectedIndexes().isEmpty() )
|
||||
{
|
||||
QString resolver = ui->scriptList->selectionModel()->selectedIndexes().first().data( ResolversModel::ResolverPath ).toString();
|
||||
AtticaManager::instance()->uninstallResolver( resolver );
|
||||
m_resolversModel->removeResolver( resolver );
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
void
|
||||
SettingsDialog::getMoreResolvers()
|
||||
@ -513,30 +448,30 @@ SettingsDialog::getMoreResolvers()
|
||||
}
|
||||
|
||||
|
||||
// void
|
||||
// SettingsDialog::atticaResolverInstalled( const QString& resolverId )
|
||||
// {
|
||||
void
|
||||
SettingsDialog::accountInstalled(Account* account)
|
||||
{
|
||||
// m_resolversModel->atticaResolverInstalled( resolverId );
|
||||
// }
|
||||
//
|
||||
//
|
||||
// void
|
||||
// SettingsDialog::atticaResolverUninstalled ( const QString& resolverId )
|
||||
// {
|
||||
// m_resolversModel->removeResolver( AtticaManager::instance()->pathFromId( resolverId ) );
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsDialog::scriptSelectionChanged()
|
||||
SettingsDialog::accountUninstalled(const QString& acct)
|
||||
{
|
||||
if( !ui->scriptList->selectionModel()->selectedIndexes().isEmpty() )
|
||||
// m_resolversModel->removeResolver( AtticaManager::instance()->pathFromId( resolverId ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsDialog::accountsSelectionChanged()
|
||||
{
|
||||
if( !ui->accountsView->selectionModel()->selectedIndexes().isEmpty() )
|
||||
{
|
||||
ui->removeScript->setEnabled( true );
|
||||
ui->removeServiceBtn->setEnabled( true );
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->removeScript->setEnabled( false );
|
||||
ui->addNewServiceBtn->setEnabled( false );
|
||||
}
|
||||
}
|
||||
|
||||
@ -545,46 +480,7 @@ void
|
||||
SettingsDialog::getMoreResolversFinished( int ret )
|
||||
{
|
||||
Q_UNUSED( ret );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsDialog::openResolverConfig( const QString& resolver )
|
||||
{
|
||||
Tomahawk::ExternalResolver* r = Tomahawk::Pipeline::instance()->resolverForPath( resolver );
|
||||
Tomahawk::ExternalResolverGui* res = qobject_cast< Tomahawk::ExternalResolverGui* >( r );
|
||||
if( res && res->configUI() )
|
||||
{
|
||||
#ifndef Q_WS_MAC
|
||||
DelegateConfigWrapper dialog( res->configUI(), "Resolver Configuration", this );
|
||||
QWeakPointer< DelegateConfigWrapper > watcher( &dialog );
|
||||
int ret = dialog.exec();
|
||||
if( !watcher.isNull() && ret == QDialog::Accepted )
|
||||
{
|
||||
// send changed config to resolver
|
||||
r->saveConfig();
|
||||
}
|
||||
#else
|
||||
// on osx a sheet needs to be non-modal
|
||||
DelegateConfigWrapper* dialog = new DelegateConfigWrapper( res->configUI(), "Resolver Configuration", this, Qt::Sheet );
|
||||
dialog->setProperty( "resolver", QVariant::fromValue< QObject* >( res ) );
|
||||
connect( dialog, SIGNAL( finished( int ) ), this, SLOT( resolverConfigClosed( int ) ) );
|
||||
|
||||
dialog->show();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsDialog::resolverConfigClosed( int value )
|
||||
{
|
||||
if( value == QDialog::Accepted )
|
||||
{
|
||||
DelegateConfigWrapper* dialog = qobject_cast< DelegateConfigWrapper* >( sender() );
|
||||
Tomahawk::ExternalResolver* r = qobject_cast< Tomahawk::ExternalResolver* >( dialog->property( "resolver" ).value< QObject* >() );
|
||||
r->saveConfig();
|
||||
}
|
||||
sender()->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
@ -627,20 +523,7 @@ SettingsDialog::accountConfigClosed( int value )
|
||||
|
||||
|
||||
void
|
||||
SettingsDialog::factoryActionTriggered( bool )
|
||||
{
|
||||
Q_ASSERT( sender() && qobject_cast< QAction* >( sender() ) );
|
||||
|
||||
QAction* a = qobject_cast< QAction* >( sender() );
|
||||
Q_ASSERT( qobject_cast< AccountFactory* >( a->property( "factory" ).value< QObject* >() ) );
|
||||
|
||||
AccountFactory* f = qobject_cast< AccountFactory* >( a->property( "factory" ).value< QObject* >() );
|
||||
accountFactoryClicked( f );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsDialog::accountFactoryClicked( AccountFactory* factory )
|
||||
SettingsDialog::createAccountFromFactory( AccountFactory* factory )
|
||||
{
|
||||
//if exited with OK, create it, if not, delete it immediately!
|
||||
Account* account = factory->createAccount();
|
||||
@ -708,22 +591,6 @@ SettingsDialog::handleAccountAdded( Account* account, bool added )
|
||||
TomahawkSettings::instance()->addAccount( account->accountId() );
|
||||
AccountManager::instance()->addAccount( account );
|
||||
AccountManager::instance()->hookupAndEnable( account );
|
||||
|
||||
// if ( f && f->isUnique() )
|
||||
// {
|
||||
// // remove from actions list
|
||||
// QAction* toremove = 0;
|
||||
// foreach( QAction* a, ui->addSipButton->actions() )
|
||||
// {
|
||||
// if( f == qobject_cast< AccountFactory* >( a->property( "factory" ).value< QObject* >() ) )
|
||||
// {
|
||||
// toremove = a;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if ( toremove )
|
||||
// ui->addSipButton->removeAction( toremove );
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -741,7 +608,7 @@ SettingsDialog::accountContextMenuRequest( const QPoint& p )
|
||||
if( idx.isValid() )
|
||||
{
|
||||
QList< QAction* > acts;
|
||||
acts << new QAction( tr( "Delete Account" ), this );
|
||||
acts << new QAction( tr( "Delete Service" ), this );
|
||||
acts.first()->setProperty( "accountplugin", idx.data( AccountModel::AccountData ) );
|
||||
connect( acts.first(), SIGNAL( triggered( bool ) ), this, SLOT( onAccountRowDeleted( bool ) ) );
|
||||
QMenu::exec( acts, ui->accountsView->mapToGlobal( p ) );
|
||||
@ -754,18 +621,6 @@ SettingsDialog::onAccountRowDeleted( bool )
|
||||
{
|
||||
Account* account = qobject_cast< Account* >( qobject_cast< QAction* >( sender() )->property( "accountplugin" ).value< QObject* >() );
|
||||
|
||||
if( AccountFactory* f = AccountManager::instance()->factoryForAccount( account ) )
|
||||
{
|
||||
// if( f->isUnique() ) // just deleted a unique plugin->re-add to add menu
|
||||
// {
|
||||
// QAction* action = new QAction( f->icon(), f->prettyName(), ui->addSipButton );
|
||||
// action->setProperty( "factory", QVariant::fromValue< QObject* >( f ) );
|
||||
// ui->addSipButton->addAction( action );
|
||||
//
|
||||
// connect( action, SIGNAL( triggered(bool) ), this, SLOT( factoryActionTriggered( bool ) ) );
|
||||
// }
|
||||
}
|
||||
|
||||
AccountManager::instance()->removeAccount( account );
|
||||
}
|
||||
|
||||
@ -780,18 +635,6 @@ SettingsDialog::accountDeleted( bool )
|
||||
if( idx.isValid() )
|
||||
{
|
||||
Account* account = qobject_cast< Account* >( idx.data( AccountModel::AccountData ).value< QObject* >() );
|
||||
|
||||
if( AccountFactory* f = AccountManager::instance()->factoryForAccount( account ) )
|
||||
{
|
||||
// if( f->isUnique() ) // just deleted a unique plugin->re-add to add menu
|
||||
// {
|
||||
// QAction* action = new QAction( f->icon(), f->prettyName(), ui->addSipButton );
|
||||
// action->setProperty( "factory", QVariant::fromValue< QObject* >( f ) );
|
||||
// ui->addSipButton->addAction( action );
|
||||
//
|
||||
// connect( action, SIGNAL( triggered(bool) ), this, SLOT( factoryActionTriggered( bool ) ) );
|
||||
// }
|
||||
}
|
||||
AccountManager::instance()->removeAccount( account );
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ namespace Tomahawk
|
||||
class AccountModel;
|
||||
class Account;
|
||||
class AccountFactory;
|
||||
class Account;
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,21 +88,18 @@ private slots:
|
||||
void testLastFmLogin();
|
||||
void onLastFmFinished();
|
||||
|
||||
void scriptSelectionChanged();
|
||||
void getMoreResolvers();
|
||||
void getMoreResolversFinished( int );
|
||||
|
||||
void openResolverConfig( const QString& );
|
||||
|
||||
void openAccountConfig( Tomahawk::Accounts::Account* );
|
||||
void factoryActionTriggered ( bool );
|
||||
void accountFactoryClicked( Tomahawk::Accounts::AccountFactory* );
|
||||
void createAccountFromFactory( Tomahawk::Accounts::AccountFactory* );
|
||||
void accountContextMenuRequest( const QPoint& );
|
||||
void accountDeleted( bool );
|
||||
void onAccountRowDeleted( bool );
|
||||
|
||||
// dialog slots
|
||||
void resolverConfigClosed( int value );
|
||||
void accountsSelectionChanged();
|
||||
void getMoreResolvers();
|
||||
void getMoreResolversFinished( int );
|
||||
|
||||
void accountInstalled( Tomahawk::Accounts::Account* account );
|
||||
void accountUninstalled( const QString& acct );
|
||||
|
||||
void accountConfigClosed( int value );
|
||||
void accountCreateConfigClosed( int value );
|
||||
@ -115,7 +113,6 @@ private slots:
|
||||
|
||||
private:
|
||||
void createIcons();
|
||||
void setupAccountButtons();
|
||||
void handleAccountAdded( Tomahawk::Accounts::Account* p, bool added );
|
||||
|
||||
Ui_StackedSettingsDialog* ui;
|
||||
|
@ -365,107 +365,6 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="resolversPage">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_10">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>Script Resolvers</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_9">
|
||||
<property name="margin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Script resolvers search for a given track to make it playable.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="getMoreResolvers">
|
||||
<property name="text">
|
||||
<string>Get more resolvers...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QTreeView" name="scriptList">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="uniformRowHeights">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="itemsExpandable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="animated">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="headerHidden">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_8">
|
||||
<item>
|
||||
<widget class="QToolButton" name="addScript">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/data/images/list-add.png</normaloff>:/data/images/list-add.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="removeScript">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/data/images/list-remove.png</normaloff>:/data/images/list-remove.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="advancedPage">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="margin">
|
||||
|
Loading…
x
Reference in New Issue
Block a user