File indexing completed on 2024-05-19 04:49:44
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 "FastForwardConfigWidget.h" 0018 0019 #include <QDir> 0020 #include <QLayout> 0021 #include <QMetaEnum> 0022 0023 using namespace StatSyncing; 0024 0025 FastForwardConfigWidget::FastForwardConfigWidget( const QVariantMap &config, 0026 QWidget *parent, Qt::WindowFlags f ) 0027 : ProviderConfigWidget( parent, f ) 0028 , m_config( config ) 0029 { 0030 setupUi( this ); 0031 0032 m_embeddedDbSettings << m_databaseLocation << m_databaseLocationLabel; 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, &FastForwardConfigWidget::connectionTypeChanged ); 0039 populateFields(); 0040 } 0041 0042 FastForwardConfigWidget::~FastForwardConfigWidget() 0043 { 0044 } 0045 0046 QVariantMap 0047 FastForwardConfigWidget::config() const 0048 { 0049 QVariantMap cfg = m_config; 0050 0051 const int enumId = metaObject()->indexOfEnumerator( "Driver" ); 0052 QMetaEnum driverEnum = metaObject()->enumerator( enumId ); 0053 0054 cfg.insert( "name", m_targetName->text() ); 0055 cfg.insert( "dbDriver", driverEnum.valueToKey( 0056 Driver( m_connectionType->currentIndex() ) ) ); 0057 0058 cfg.insert( "dbPath", m_databaseLocation->text() ); 0059 cfg.insert( "dbName", m_databaseName->text() ); 0060 cfg.insert( "dbHost", m_hostname->text() ); 0061 cfg.insert( "dbUser", m_username->text() ); 0062 cfg.insert( "dbPass", m_password->text() ); 0063 cfg.insert( "dbPort", m_port->value() ); 0064 0065 return cfg; 0066 } 0067 0068 void 0069 FastForwardConfigWidget::connectionTypeChanged( const int index ) 0070 { 0071 const bool embedded = ( index == QSQLITE ); 0072 const QList<QWidget*> &hide = embedded ? m_externalDbSettings : m_embeddedDbSettings; 0073 const QList<QWidget*> &show = embedded ? m_embeddedDbSettings : m_externalDbSettings; 0074 0075 foreach( QWidget *widget, hide ) 0076 widget->hide(); 0077 foreach( QWidget *widget, show ) 0078 widget->show(); 0079 } 0080 0081 void 0082 FastForwardConfigWidget::populateFields() 0083 { 0084 m_targetName->setText( m_config.value( "name", "Amarok 1.4" ).toString() ); 0085 0086 const int enumId = metaObject()->indexOfEnumerator( "Driver" ); 0087 QMetaEnum driverEnum = metaObject()->enumerator( enumId ); 0088 0089 m_connectionType->insertItem( QMYSQL, "MySQL" ); 0090 m_connectionType->insertItem( QPSQL, "PostgreSQL" ); 0091 m_connectionType->insertItem( QSQLITE, "SQLite" ); 0092 0093 const QByteArray dbDriver = m_config.value( "dbDriver", 0094 driverEnum.valueToKey( QSQLITE ) ).toByteArray(); 0095 0096 int index = driverEnum.keyToValue( dbDriver.constData() ); 0097 if( index == -1 ) 0098 index = QSQLITE; 0099 0100 m_connectionType->setCurrentIndex( index ); 0101 0102 const QString defaultPath = QDir::toNativeSeparators( 0103 QDir::homePath() + QStringLiteral("/.kde/share/apps/amarok/collection.db") ); 0104 0105 m_databaseLocation->setText( m_config.value( "dbPath", defaultPath ).toString() ); 0106 m_databaseName->setText( m_config.value( "dbName", "amarokdb" ).toString() ); 0107 m_hostname->setText( m_config.value( "dbHost", "localhost" ).toString() ); 0108 m_username->setText( m_config.value( "dbUser", "amarokuser" ).toString() ); 0109 m_password->setText( m_config.value( "dbPass", "" ).toString() ); 0110 m_port->setValue( m_config.value( "dbPort", 3306 ).toInt() ); 0111 }