mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 02:54:33 +02:00
Move config data handling into AccountConfigWidget
This commit is contained in:
@@ -18,6 +18,12 @@
|
|||||||
|
|
||||||
#include "AccountConfigWidget.h"
|
#include "AccountConfigWidget.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "../utils/Logger.h"
|
||||||
|
|
||||||
|
#include <QMetaProperty>
|
||||||
|
|
||||||
|
|
||||||
AccountConfigWidget::AccountConfigWidget( QWidget* parent )
|
AccountConfigWidget::AccountConfigWidget( QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
{
|
{
|
||||||
@@ -49,3 +55,85 @@ AccountConfigWidget::settingsValid() const
|
|||||||
{
|
{
|
||||||
return m_errors.empty();
|
return m_errors.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AccountConfigWidget::setDataWidgets( const QVariantList& dataWidgets )
|
||||||
|
{
|
||||||
|
m_dataWidgets = dataWidgets;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const QVariantMap
|
||||||
|
AccountConfigWidget::readData()
|
||||||
|
{
|
||||||
|
|
||||||
|
QVariantMap saveData;
|
||||||
|
foreach( const QVariant& dataWidget, m_dataWidgets )
|
||||||
|
{
|
||||||
|
QVariantMap data = dataWidget.toMap();
|
||||||
|
|
||||||
|
QString widgetName = data["widget"].toString();
|
||||||
|
QWidget* widget= findChild<QWidget*>( widgetName );
|
||||||
|
|
||||||
|
QVariant value = widgetData( widget, data["property"].toString() );
|
||||||
|
|
||||||
|
saveData[ data["name"].toString() ] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return saveData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariant
|
||||||
|
AccountConfigWidget::widgetData( QWidget* widget, const QString& property )
|
||||||
|
{
|
||||||
|
for ( int i = 0; i < widget->metaObject()->propertyCount(); i++ )
|
||||||
|
{
|
||||||
|
if ( widget->metaObject()->property( i ).name() == property )
|
||||||
|
{
|
||||||
|
return widget->property( property.toLatin1() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AccountConfigWidget::fillDataInWidgets( const QVariantMap& data )
|
||||||
|
{
|
||||||
|
foreach(const QVariant& dataWidget, m_dataWidgets)
|
||||||
|
{
|
||||||
|
const QVariantMap m = dataWidget.toMap();
|
||||||
|
QString widgetName = m["widget"].toString();
|
||||||
|
QWidget* widget= findChild<QWidget*>( widgetName );
|
||||||
|
if ( !widget )
|
||||||
|
{
|
||||||
|
tLog() << Q_FUNC_INFO << "Widget specified in resolver was not found:" << widgetName;
|
||||||
|
Q_ASSERT(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString propertyName = m["property"].toString();
|
||||||
|
QString name = m["name"].toString();
|
||||||
|
|
||||||
|
setWidgetData( data[ name ], widget, propertyName );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AccountConfigWidget::setWidgetData( const QVariant& value, QWidget* widget, const QString& property )
|
||||||
|
{
|
||||||
|
const QMetaObject *metaObject = widget->metaObject();
|
||||||
|
for ( int i = 0; i < metaObject->propertyCount(); i++ )
|
||||||
|
{
|
||||||
|
const QMetaProperty &prop = metaObject->property( i );
|
||||||
|
if ( prop.name() == property )
|
||||||
|
{
|
||||||
|
prop.write( widget, value );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -19,9 +19,10 @@
|
|||||||
#ifndef ACCOUNTCONFIGWIDGET_H
|
#ifndef ACCOUNTCONFIGWIDGET_H
|
||||||
#define ACCOUNTCONFIGWIDGET_H
|
#define ACCOUNTCONFIGWIDGET_H
|
||||||
|
|
||||||
#include "DllMacro.h"
|
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QVariantMap>
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
class DLLEXPORT AccountConfigWidget : public QWidget
|
class DLLEXPORT AccountConfigWidget : public QWidget
|
||||||
{
|
{
|
||||||
@@ -35,8 +36,16 @@ public:
|
|||||||
|
|
||||||
virtual bool settingsValid() const;
|
virtual bool settingsValid() const;
|
||||||
|
|
||||||
|
void setDataWidgets( const QVariantList& dataWidgets );
|
||||||
|
const QVariantMap readData();
|
||||||
|
static QVariant widgetData( QWidget* widget, const QString& property );
|
||||||
|
static void setWidgetData( const QVariant& value, QWidget* widget, const QString& property );
|
||||||
|
void fillDataInWidgets( const QVariantMap& data );
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QStringList m_errors;
|
QStringList m_errors;
|
||||||
|
QVariantList m_dataWidgets;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ACCOUNTCONFIGWIDGET_H
|
#endif // ACCOUNTCONFIGWIDGET_H
|
||||||
|
@@ -290,8 +290,10 @@ JSResolver::init()
|
|||||||
|
|
||||||
// load config widget and apply settings
|
// load config widget and apply settings
|
||||||
loadUi();
|
loadUi();
|
||||||
QVariantMap config = resolverUserConfig();
|
if ( !d->configWidget.isNull() )
|
||||||
fillDataInWidgets( config );
|
{
|
||||||
|
d->configWidget->fillDataInWidgets( resolverUserConfig() );
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "JS" << filePath() << "READY," << "name" << d->name << "weight" << d->weight << "timeout" << d->timeout << "icon received" << success;
|
qDebug() << "JS" << filePath() << "READY," << "name" << d->name << "weight" << d->weight << "timeout" << d->timeout << "icon received" << success;
|
||||||
|
|
||||||
@@ -687,7 +689,6 @@ JSResolver::loadUi()
|
|||||||
Q_D( JSResolver );
|
Q_D( JSResolver );
|
||||||
|
|
||||||
QVariantMap m = callOnResolver( "getConfigUi()" ).toMap();
|
QVariantMap m = callOnResolver( "getConfigUi()" ).toMap();
|
||||||
d->dataWidgets = m["fields"].toList();
|
|
||||||
|
|
||||||
bool compressed = m.value( "compressed", "false" ).toBool();
|
bool compressed = m.value( "compressed", "false" ).toBool();
|
||||||
qDebug() << "Resolver has a preferences widget! compressed?" << compressed;
|
qDebug() << "Resolver has a preferences widget! compressed?" << compressed;
|
||||||
@@ -709,6 +710,10 @@ JSResolver::loadUi()
|
|||||||
uiData = fixDataImagePaths( uiData, compressed, images );
|
uiData = fixDataImagePaths( uiData, compressed, images );
|
||||||
|
|
||||||
d->configWidget = QPointer< AccountConfigWidget >( widgetFromData( uiData, 0 ) );
|
d->configWidget = QPointer< AccountConfigWidget >( widgetFromData( uiData, 0 ) );
|
||||||
|
if ( !d->configWidget.isNull() )
|
||||||
|
{
|
||||||
|
d->configWidget->setDataWidgets( m["fields"].toList() );
|
||||||
|
}
|
||||||
|
|
||||||
emit changed();
|
emit changed();
|
||||||
}
|
}
|
||||||
@@ -739,81 +744,12 @@ JSResolver::saveConfig()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant
|
|
||||||
JSResolver::widgetData( QWidget* widget, const QString& property )
|
|
||||||
{
|
|
||||||
for ( int i = 0; i < widget->metaObject()->propertyCount(); i++ )
|
|
||||||
{
|
|
||||||
if ( widget->metaObject()->property( i ).name() == property )
|
|
||||||
{
|
|
||||||
return widget->property( property.toLatin1() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
JSResolver::setWidgetData( const QVariant& value, QWidget* widget, const QString& property )
|
|
||||||
{
|
|
||||||
const QMetaObject *metaObject = widget->metaObject();
|
|
||||||
for ( int i = 0; i < metaObject->propertyCount(); i++ )
|
|
||||||
{
|
|
||||||
const QMetaProperty &prop = metaObject->property( i );
|
|
||||||
if ( prop.name() == property )
|
|
||||||
{
|
|
||||||
prop.write( widget, value );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QVariantMap
|
QVariantMap
|
||||||
JSResolver::loadDataFromWidgets()
|
JSResolver::loadDataFromWidgets()
|
||||||
{
|
{
|
||||||
Q_D( JSResolver );
|
Q_D( JSResolver );
|
||||||
|
|
||||||
QVariantMap saveData;
|
return d->configWidget->readData();
|
||||||
foreach( const QVariant& dataWidget, d->dataWidgets )
|
|
||||||
{
|
|
||||||
QVariantMap data = dataWidget.toMap();
|
|
||||||
|
|
||||||
QString widgetName = data["widget"].toString();
|
|
||||||
QWidget* widget= d->configWidget.data()->findChild<QWidget*>( widgetName );
|
|
||||||
|
|
||||||
QVariant value = widgetData( widget, data["property"].toString() );
|
|
||||||
|
|
||||||
saveData[ data["name"].toString() ] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return saveData;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
JSResolver::fillDataInWidgets( const QVariantMap& data )
|
|
||||||
{
|
|
||||||
Q_D( JSResolver );
|
|
||||||
|
|
||||||
foreach(const QVariant& dataWidget, d->dataWidgets)
|
|
||||||
{
|
|
||||||
const QVariantMap m = dataWidget.toMap();
|
|
||||||
QString widgetName = m["widget"].toString();
|
|
||||||
QWidget* widget= d->configWidget.data()->findChild<QWidget*>( widgetName );
|
|
||||||
if ( !widget )
|
|
||||||
{
|
|
||||||
tLog() << Q_FUNC_INFO << "Widget specified in resolver was not found:" << widgetName;
|
|
||||||
Q_ASSERT(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString propertyName = m["property"].toString();
|
|
||||||
QString name = m["name"].toString();
|
|
||||||
|
|
||||||
setWidgetData( data[ name ], widget, propertyName );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -98,9 +98,6 @@ private:
|
|||||||
void init();
|
void init();
|
||||||
|
|
||||||
void loadUi();
|
void loadUi();
|
||||||
void setWidgetData( const QVariant& value, QWidget* widget, const QString& property );
|
|
||||||
QVariant widgetData( QWidget* widget, const QString& property );
|
|
||||||
void fillDataInWidgets( const QVariantMap& data );
|
|
||||||
void onCapabilitiesChanged( Capabilities capabilities );
|
void onCapabilitiesChanged( Capabilities capabilities );
|
||||||
void loadCollections();
|
void loadCollections();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user