/***************************************************************************
 *   Copyright (C) 2008  Tom Patzig <tpatzig@suse.de>                      *
 *   Copyright (C) 2008  Alex Fiestas <alex@eyeos.org>                     *
 *   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, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
 ***************************************************************************/

#ifndef WIZARDDIALOG_H
#define WIZARDDIALOG_H

#include "wizardpage.h"
#include "wizardagent.h"
#include "createremotedevice.h"
#include "createpaireddevice.h"

#include <QWizard>
#include <QListWidget>
#include <QLabel>
#include <QVBoxLayout>
#include <QProgressBar>

#include <KApplication>
#include <KConfig>
#include <kjob.h>
#include <solid/control/bluetoothmanager.h>
#include <solid/control/bluetoothinterface.h>
#include <solid/control/bluetoothinputdevice.h>
#include <QLineEdit>

class BTWizard :   public QWizard
{
    Q_OBJECT

public:
    BTWizard(KApplication* parent);
    ~BTWizard();

private:
    const Solid::Control::BluetoothManager& btmanager;
    QApplication* m_parent;
    Solid::Control::BluetoothInterface* m_iface;
    Solid::Control::BluetoothRemoteDeviceList m_devList;

    WizardPage* m_introPage;
    QLabel* m_introLabel;
    QVBoxLayout* m_introLayout;

    WizardPage* m_discoveryPage;
    QListWidget* m_discoveryWidget;
    QPushButton* m_discoveryButton;

    WizardPage* m_connPage;
    QLabel* m_connLabel;
    QLabel* m_connLabel1;
    QLabel* m_connLabel2;
    QLabel* m_connLabel3;
    QLabel* m_connLabel4;
    QLabel* m_connLabel5;
    QProgressBar *m_connInfiniteBar;

    WizardPage* m_finalPage;
    WizardPage* m_pinPage;
    bool m_manualPin;
    QLineEdit *m_pinLineEdit;
    QLabel* m_finalLabel;
    QLabel* m_hiddenFinalLabel;
    QProgressBar *m_finalInfiniteBar;
    QVBoxLayout* m_finalLayout;

    WizardPage* createIntroPage();
    WizardPage* createDiscoveryPage();
    WizardPage* createConnectionPage();
    WizardPage* createPinPage();
    WizardPage* createFinalPage();

    QString m_finalDev;
    QMap<QString, QMap< QString, QVariant > > m_macMap;

    QPixmap m_flashPixmap;
    QPixmap m_normalPixmap;
    QTimer* m_logoTimer;
    WizardAgent *m_wizardagent;
    CreateRemoteDevice *m_createThread;
    CreatePairedDevice *m_pairedThread;
    Solid::Control::BluetoothRemoteDevice* m_dev;
    bool m_paired;
    void addDeviceFound(const QString&, const QMap< QString, QVariant >&);
    void removeDeviceDisappeared(const QString&);
    void createRemoteDevice(const QString&);
    void waitForPairing();
    void connectToDevice();
    void showConnPageInformation(Solid::Control::BluetoothRemoteDevice *dev);

private slots:
    void slotCancel();
    void slotNext();
    void slotSearch();
    void slotDeviceFound(const QString&, const QMap< QString, QVariant > &);
    void slotDeviceDisappeared(const QString&);
    void slotDeviceCreated(Solid::Control::BluetoothRemoteDevice* dev);
    void slotFinish();
    void slotCreateThreadFinished();
    void slotPairedThreadFinished();
    void slotDeviceConnected();
    void slotDeviceSelectionChanged();

    void slotDevicePropertyChanged(const QString&, const QVariant&);

    void setFlashingLogo();
    void setNormalLogo();
    void pinRequested(const QString& pin);

    void manualPinSelected(bool checked);
    void checkManualPin(const QString& pin);

signals:
    void manualPinChanged(const QString& pin);

};
#endif
