/****************************************************************************************
 * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org>                                *
 * Copyright (c) 2008 Casey Link <unnamedrambler@gmail.com>                             *
 *                                                                                      *
 * This program is free software; you can redistribute it and/or modify it under        *
 * the terms of the GNU General Public License as published by the Free Software        *
 * Foundation; either version 2 of the License, or (at your option) any later           *
 * version.                                                                             *
 *                                                                                      *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
 *                                                                                      *
 * You should have received a copy of the GNU General Public License along with         *
 * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
 ****************************************************************************************/

#include "Mp3tunesSettingsModule.h"

#include "ui_Mp3tunesConfigWidget.h"

#include <KPluginFactory>

K_PLUGIN_FACTORY_WITH_JSON( Mp3tunesSettingsFactory, "amarok_service_mp3tunes_config.json", registerPlugin<Mp3tunesSettingsModule>(); )

Mp3tunesSettingsModule::Mp3tunesSettingsModule( QWidget *parent, const QVariantList &args )
    : KCModule( parent, args )
{
    m_configDialog = new Ui::Mp3tunesConfigWidget;
    m_configDialog->setupUi( this );
    //m_configDialog->pinEdit->setReadOnly( true );

    m_configDialog->passwordEdit->setEchoMode( QLineEdit::Password );
    connect ( m_configDialog->emailEdit, &QLineEdit::textChanged, this, &Mp3tunesSettingsModule::settingsChanged );
    connect ( m_configDialog->passwordEdit, &QLineEdit::textChanged, this, &Mp3tunesSettingsModule::settingsChanged );

    load();
}


Mp3tunesSettingsModule::~Mp3tunesSettingsModule()
{
    delete m_configDialog;
}


void Mp3tunesSettingsModule::save()
{
    m_config.setEmail( m_configDialog->emailEdit->text() );
    m_config.setPassword( m_configDialog->passwordEdit->text() );
    //m_config.setPin( m_configDialog->pinEdit->text() );
    //m_config.setHarmonyEnabled( m_configDialog->enableHarmony->isChecked() );

    m_config.save();
    KCModule::save();
}

void Mp3tunesSettingsModule::load()
{
    m_configDialog->emailEdit->setText( m_config.email() );
    m_configDialog->passwordEdit->setText( m_config.password() );
    //m_configDialog->enableHarmony->setChecked( m_config.harmonyEnabled() );
    //m_configDialog->pinEdit->setText( m_config.pin() );

    KCModule::load();
}

void Mp3tunesSettingsModule::defaults()
{
    m_config.setEmail( QString() );
    m_config.setPassword( QString() );
    //m_config.setHarmonyEnabled( false );
    load();
}

void Mp3tunesSettingsModule::settingsChanged()
{
    emit changed( true );
}

#include "Mp3tunesSettingsModule.moc"
