/***************************************************************************
 *   Copyright (C) 2005 by James Thorniley                                 *
 *   james@uncommonlygood.co.uk                                            *
 *                                                                         *
 *   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.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef BURNDEVICEWIDGET_H
#define BURNDEVICEWIDGET_H

#include <qframe.h>
#include <dcopobject.h>
#include <k3bjobhandler.h>
#include "burnsidebarplugin.h"

namespace K3bDevice{
class Device;
}
class QDropEvent;
class K3bJobHandler;
class K3bBurnJob;
class QVBoxLayout;
class QLabel;
class KProgress;
class QWidgetStack;
class QHBoxLayout;
class QDragEnterEvent;
class QStringList;
class BurnSidebarPlugin;
class QTimer;
class QHBox;
class QVBox;
class QPushButton;
class QComboBox;
class K3bDataDoc;
/**
One of these widgets for each CD burning device. When a drop event is recieved, extracts
the k3b document from the drop event, and starts it burning with the associated device

@author James Thorniley
*/
class BurnDeviceWidget : public QFrame, K3bJobHandler, DCOPObject
{
Q_OBJECT
public:
    /**
    Creates a new BurnDeviceWidget to represent \p device and with \p dragSource as the source of
    drop events that should activate burning. I.e. dragSource points to the project selection
    widget.
    */
    BurnDeviceWidget(K3bDevice::Device *device, const QWidget *dragSource, BurnSidebarPlugin *plugin, QWidget *parent = 0, const char *name = 0);

    virtual ~BurnDeviceWidget();

    bool isJob(){ return false; }
    int waitForMedia(K3bDevice::Device*,
                             int mediaState = K3bDevice::STATE_EMPTY,
                             int mediaType = K3bDevice::MEDIA_WRITABLE_CD,
                             const QString& message = QString::null);

    bool questionYesNo(  const QString& text, const QString &caption=QString::null );
    void blockingInformation( const QString& text, const QString& caption = QString::null );

    virtual bool process(const QCString &fun, const QByteArray &data, QCString &replyType, QByteArray &replyData);
  public slots:
    void slotDiscTypeSelected( BurnSidebarPlugin::DiscType );

  protected:
    void dragEnterEvent( QDragEnterEvent *e );
    void dropEvent( QDropEvent *de );

  protected slots:
    ///replace progress bar with text label
    void slotFinished(bool);
    ///replace progress bar with text label
    void slotCanceled(){}
    ///replace text label with progress bar, set it to zero
    void slotStarted();
    void slotInfoMessage( const QString &, int );
    void slotErrorTimeout();
    void startBurning();
    void cancelClicked();
    void displayInfoMessages();
    void slotStartBurnClicked();
    /**update the speed slider to reflect whether the inserted media is CD or DVD
    */
    void configureSpeedCombo();
    void slotDocChanged();
    
  private:
    bool m_inLoop;
    bool m_isDVD;
    K3bDataDoc *m_dndBurn; //holds the document to burn when initiated from drag-and-drop from konqueror file view
    const QWidget *m_dragSource;
    K3bDevice::Device *m_device;
    QHBoxLayout *m_hLayout;
    QPushButton *m_deviceRescanButton;
    QLabel *m_textLabel;
    QLabel *m_errorLabel, *m_speedLabel;
    KProgress *m_progress;
    QWidgetStack *m_widgetStack;
    K3bBurnJob *m_burnJob;
    BurnSidebarPlugin *m_plugin;
    QHBox *m_burnHBox, *m_mainHBox;
    QWidget *m_burnVBox, *m_errorBox, *m_progressBox;
    QVBox *m_mainVBox;
    QLabel *m_burnLabel;
    QComboBox *m_speedCombo;
    QPushButton *m_burnButton, *m_burnCancelButton, *m_errorOkButton, *m_errorDetailsButton;
    QPushButton *m_startBurnButton;
    QStringList *m_infoMessages;

    void setRescanPixmap(const QString &iconname);
};

#endif
