File indexing completed on 2024-05-19 04:49:43
0001 /**************************************************************************************** 0002 * Copyright (c) 2013 Konrad Zemek <konrad.zemek@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "AmarokConfigWidget.h" 0018 0019 #include <QDir> 0020 #include <QLayout> 0021 0022 using namespace StatSyncing; 0023 0024 AmarokConfigWidget::AmarokConfigWidget( const QVariantMap &config, 0025 QWidget *parent, Qt::WindowFlags f ) 0026 : ProviderConfigWidget( parent, f ) 0027 , m_config( config ) 0028 { 0029 setupUi( this ); 0030 0031 m_embeddedDbSettings << m_databaseLocation << m_databaseLocationLabel 0032 << m_mysqlBinary << m_mysqlBinaryLabel; 0033 m_externalDbSettings << m_databaseName << m_databaseNameLabel << m_hostname 0034 << m_hostnameLabel << m_password << m_passwordLabel 0035 << m_port << m_portLabel << m_username << m_usernameLabel; 0036 0037 connect( m_connectionType, QOverload<int>::of( &KComboBox::currentIndexChanged ), 0038 this, &AmarokConfigWidget::connectionTypeChanged ); 0039 populateFields(); 0040 } 0041 0042 AmarokConfigWidget::~AmarokConfigWidget() 0043 { 0044 } 0045 0046 QVariantMap 0047 AmarokConfigWidget::config() const 0048 { 0049 QVariantMap cfg( m_config ); 0050 cfg.insert( "name", m_targetName->text() ); 0051 cfg.insert( "embedded", m_connectionType->currentIndex() == Embedded ); 0052 cfg.insert( "mysqlBinary", m_mysqlBinary->text() ); 0053 cfg.insert( "dbPath", m_databaseLocation->text() ); 0054 cfg.insert( "dbName", m_databaseName->text() ); 0055 cfg.insert( "dbHost", m_hostname->text() ); 0056 cfg.insert( "dbUser", m_username->text() ); 0057 cfg.insert( "dbPass", m_password->text() ); 0058 cfg.insert( "dbPort", m_port->value() ); 0059 0060 return cfg; 0061 } 0062 0063 void 0064 AmarokConfigWidget::connectionTypeChanged( const int index ) 0065 { 0066 const bool embedded = ( index == Embedded ); 0067 const QList<QWidget*> &hide = embedded ? m_externalDbSettings : m_embeddedDbSettings; 0068 const QList<QWidget*> &show = embedded ? m_embeddedDbSettings : m_externalDbSettings; 0069 0070 foreach( QWidget *widget, hide ) 0071 widget->hide(); 0072 foreach( QWidget *widget, show ) 0073 widget->show(); 0074 } 0075 0076 void 0077 AmarokConfigWidget::populateFields() 0078 { 0079 m_targetName->setText( m_config.value( "name", "Amarok" ).toString() ); 0080 0081 m_connectionType->insertItem( Embedded, i18nc( "Database type", "embedded" ) ); 0082 m_connectionType->insertItem( External, i18nc( "Database type", "external" ) ); 0083 0084 m_connectionType->setCurrentIndex( 0085 m_config.value( "embedded" ).toBool() 0086 ? Embedded : External ); 0087 0088 const QString defaultPath( "/usr/bin/mysqld" ); 0089 m_mysqlBinary->setText( m_config.value( "mysqlBinary", defaultPath ).toString() ); 0090 m_databaseLocation->setText( m_config.value( "dbPath", "" ).toString() ); 0091 m_databaseName->setText( m_config.value( "dbName", "amarokdb" ).toString() ); 0092 m_hostname->setText( m_config.value( "dbHost", "localhost" ).toString() ); 0093 m_username->setText( m_config.value( "dbUser", "amarokuser" ).toString() ); 0094 m_password->setText( m_config.value( "dbPass", "" ).toString() ); 0095 m_port->setValue( m_config.value( "dbPort", 3306 ).toInt() ); 0096 }