/*
    This file is part of kenvy24 KDE multimedia utility
    Copyright (c) 2007  Valentin RUSU kenvy24@rusu.info

    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) version 3 or, at the discretion of KDE e.V. (which shall
    act as a proxy as in section 14 of the GPLv3), 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/>.
*/

#ifndef MAINPART_H_INCLUDED
#define MAINPART_H_INCLUDED

#include <kparts/part.h>
#include "ui_mainpart.h"
#include "kenvy24part.h"

class Ui_MainPart;
class QWidget;
class KEnvy24PartBase;

/**
 * This macro is used to compile in the surround part or not
 * when set to 0, the surround part will not be included
 */
#define LOAD_PART_SURROUND 0

/**
 * This is the main part of the application
 * When initialized it loads the other parts, so it
 * can be used by client application to conveniently
 * embed all the kenvy24 functionality
 *
 * All important initialization take place into initTimerShot()
 */
class MainPart : public KEnvy24Part< Ui_MainPart>
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.kde.kenvy24.MainPart")

private:
    KEnvy24PartBase*  mixerPart;
#if LOAD_PART_SURROUND>0
    KEnvy24PartBase*  surroundPart;
#endif
    EnvyCard*         currentCard;
    /**
     * this config group is used when saving settings
     */
    KConfigGroup*     settingsConfigGroup;

public:
    MainPart( QWidget* parentWidget, QObject* parent, const QVariantList& );
    ~MainPart();


protected Q_SLOTS:
    void initTimerShot();
    void cardChanged(const QString&);
    void configNameChanged(const QString&);
    void configSelectionChanged(const QString&);

public Q_SLOTS:
    void selectCard(QString cardName);
    void saveConfig();
    void deleteConfig();

Q_SIGNALS:
    Q_SCRIPTABLE void cardSelected(QString cardName);
    /**
     * this is emmitted when the user click "save settings" button
     * all parts are connected to this signal and must then save their
     * settings using the given configGroup
     */
    void saveConfigNow( KConfigGroup* configGroup );
    void loadConfigNow( KConfigGroup* configGroup );

protected:
    virtual bool saveFile ();
    virtual bool openFile ();
    virtual void setActiveCard( EnvyCard* );
    virtual void saveConfig( KConfigGroup* configGroup );
    virtual void loadConfig( KConfigGroup* configGroup );

    void restoreConfig();

private:
    /**
     * this will return the KConfigGroup wich holds the settings for
     * a "configuration" as configured by the user into the UI (combo)
     */
    KConfigGroup* configGroup( QString configName );
    void saveConfigNames();
};


#endif // MAINPART_H_INCLUDED
