1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 16:44:05 +02:00

Add a config setting to script resolvers

Save them across sessions
This commit is contained in:
Leo Franchi
2011-02-08 22:49:07 -05:00
parent ffa6583be1
commit 1a68116b36
8 changed files with 217 additions and 23 deletions

View File

@@ -19,6 +19,7 @@
#include "utils/tomahawkutils.h"
class ScriptResolver;
class AudioEngine;
class Database;
class SipHandler;
@@ -65,6 +66,8 @@ public:
TomahawkWindow* mainWindow() const { return m_mainwindow; }
#endif
void addScriptResolver( const QString& scriptPath );
signals:
void settingsChanged();
@@ -82,7 +85,8 @@ private:
QList<Tomahawk::collection_ptr> m_collections;
QList<TomahawkPlugin*> m_plugins;
QList<ScriptResolver*> m_scriptResolvers;
Database* m_database;
AudioEngine* m_audioEngine;
SipHandler* m_sipHandler;

View File

@@ -445,3 +445,21 @@ TomahawkSettings::setXmppBotPort( const int port )
{
setValue( "xmppBot/port", -1 );
}
void
TomahawkSettings::addScriptResolver(const QString& resolver)
{
setValue( "script/resolvers", scriptResolvers() << resolver );
}
QStringList
TomahawkSettings::scriptResolvers() const
{
return value( "script/resolvers" ).toStringList();
}
void
TomahawkSettings::setScriptResolvers( const QStringList& resolver )
{
setValue( "script/resolvers", resolver );
}

View File

@@ -109,6 +109,12 @@ public:
int xmppBotPort() const;
void setXmppBotPort( const int port );
/// Script resolver settings
QStringList scriptResolvers() const;
void setScriptResolvers( const QStringList& resolver );
void addScriptResolver( const QString& resolver );
private:
static TomahawkSettings* s_instance;
};

View File

@@ -128,6 +128,7 @@ void ScriptResolver::resolve( const QVariant& v )
QVariantMap m = v.toMap();
m.insert( "_msgtype", "rq" );
const QByteArray msg = m_serializer.serialize( m );
qDebug() << "ASKING SCRIPT RESOLVER TO RESOLVE:" << msg;
sendMsg( msg );
}

View File

@@ -72,6 +72,17 @@ SettingsDialog::SettingsDialog( QWidget *parent )
ui->lineEditLastfmPassword->setText(s->lastFmPassword() );
connect( ui->pushButtonTestLastfmLogin, SIGNAL( clicked( bool) ), this, SLOT( testLastFmLogin() ) );
// SCRIPT RESOLVER
ui->removeScript->setEnabled( false );
foreach( const QString& resolver, s->scriptResolvers() ) {
QFileInfo info( resolver );
ui->scriptList->addTopLevelItem( new QTreeWidgetItem( QStringList() << info.baseName() << resolver ) );
}
connect( ui->scriptList, SIGNAL( itemClicked( QTreeWidgetItem*, int ) ), this, SLOT( scriptSelectionChanged() ) );
connect( ui->addScript, SIGNAL( clicked( bool ) ), this, SLOT( addScriptResolver() ) );
connect( ui->removeScript, SIGNAL( clicked( bool ) ), this, SLOT( removeScriptResolver() ) );
connect( ui->buttonBrowse, SIGNAL( clicked() ), SLOT( showPathSelector() ) );
connect( ui->proxyButton, SIGNAL( clicked() ), SLOT( showProxySettings() ) );
connect( this, SIGNAL( rejected() ), SLOT( onRejected() ) );
@@ -113,6 +124,12 @@ SettingsDialog::~SettingsDialog()
s->setLastFmUsername( ui->lineEditLastfmUsername->text() );
s->setLastFmPassword( ui->lineEditLastfmPassword->text() );
QStringList resolvers;
for( int i = 0; i < ui->scriptList->topLevelItemCount(); i++ ) {
resolvers << ui->scriptList->topLevelItem( i )->data( 1, Qt::DisplayRole ).toString();
}
s->setScriptResolvers( resolvers );
if( rescan )
{
MusicScanner* scanner = new MusicScanner(s->scannerPath() );
@@ -313,3 +330,34 @@ ProxyDialog::saveSettings()
QNetworkProxy::setApplicationProxy( proxy );
}
void
SettingsDialog::addScriptResolver()
{
QString resolver = QFileDialog::getOpenFileName( this, tr( "Load script resolver file" ), qApp->applicationDirPath() );
if( !resolver.isEmpty() ) {
QFileInfo info( resolver );
ui->scriptList->addTopLevelItem( new QTreeWidgetItem( QStringList() << info.baseName() << resolver ) );
TomahawkApp::instance()->addScriptResolver( resolver );
}
}
void
SettingsDialog::removeScriptResolver()
{
// only one selection
if( !ui->scriptList->selectedItems().isEmpty() ) {
delete ui->scriptList->takeTopLevelItem( ui->scriptList->indexOfTopLevelItem( ui->scriptList->selectedItems().first() ) );
}
}
void
SettingsDialog::scriptSelectionChanged()
{
if( !ui->scriptList->selectedItems().isEmpty() ) {
ui->removeScript->setEnabled( true );
} else {
ui->removeScript->setEnabled( false );
}
}

View File

@@ -51,6 +51,10 @@ private slots:
void testLastFmLogin();
void onLastFmFinished();
void addScriptResolver();
void scriptSelectionChanged();
void removeScriptResolver();
private:
Ui::SettingsDialog *ui;

View File

@@ -23,7 +23,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<widget class="QWidget" name="tabJabber">
<attribute name="title">
@@ -456,6 +456,110 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tabScriptResolvers">
<attribute name="title">
<string>Script Resolvers</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QLabel" name="scriptLabel">
<property name="text">
<string>Loaded script resolvers:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QTreeWidget" 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="itemsExpandable">
<bool>false</bool>
</property>
<property name="animated">
<bool>true</bool>
</property>
<property name="columnCount">
<number>2</number>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<attribute name="headerCascadingSectionResizes">
<bool>true</bool>
</attribute>
<attribute name="headerDefaultSectionSize">
<number>150</number>
</attribute>
<attribute name="headerHighlightSections">
<bool>true</bool>
</attribute>
<attribute name="headerStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
<column>
<property name="text">
<string notr="true">2</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_7">
<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>
</widget>
</item>
<item>
@@ -470,7 +574,9 @@
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
@@ -479,8 +585,8 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>398</x>
<y>374</y>
<x>402</x>
<y>348</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
@@ -495,8 +601,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>466</x>
<y>380</y>
<x>470</x>
<y>348</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
@@ -511,12 +617,12 @@
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>480</x>
<y>124</y>
<x>489</x>
<y>117</y>
</hint>
<hint type="destinationlabel">
<x>496</x>
<y>154</y>
<x>595</x>
<y>145</y>
</hint>
</hints>
</connection>
@@ -527,12 +633,12 @@
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>483</x>
<y>124</y>
<x>492</x>
<y>117</y>
</hint>
<hint type="destinationlabel">
<x>114</x>
<y>154</y>
<x>123</x>
<y>145</y>
</hint>
</hints>
</connection>
@@ -543,12 +649,12 @@
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>461</x>
<y>124</y>
<x>470</x>
<y>117</y>
</hint>
<hint type="destinationlabel">
<x>114</x>
<y>182</y>
<x>123</x>
<y>173</y>
</hint>
</hints>
</connection>
@@ -563,8 +669,8 @@
<y>112</y>
</hint>
<hint type="destinationlabel">
<x>439</x>
<y>163</y>
<x>594</x>
<y>172</y>
</hint>
</hints>
</connection>

View File

@@ -321,10 +321,17 @@ TomahawkApp::setupPipeline()
{
// setup resolvers for local content, and (cached) remote collection content
Pipeline::instance()->addResolver( new DatabaseResolver( 100 ) );
// new ScriptResolver("/home/rj/src/tomahawk-core/contrib/magnatune/magnatune-resolver.php");
// load script resolvers
foreach( QString resolver,TomahawkSettings::instance()->scriptResolvers() )
addScriptResolver( resolver );
}
void
TomahawkApp::addScriptResolver( const QString& path )
{
m_scriptResolvers << new ScriptResolver( path );
}
void
TomahawkApp::initLocalCollection()