/***************************************************************************
   This file is part of LinTV
   lintvscreenshotwidgets.h
   Contains the ScreenshotsListWidget, ScreenshotLoader, and ScreenshotViewer
   classes. 

   Author: Jesse L. Zamora <xtremek2009@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, write to the
   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
 ***************************************************************************/
 
#ifndef LINTVSCREENSHOTWIDGETS_H
#define LINTVSCREENSHOTWIDGETS_H

#include <klistwidget.h>

#include <QWidget>
#include <QThread>

class KAction;
class KMenu;
class KFileItemList;
class KDirWatch;

class QPushButton;

class ScreenshotLoader : public QThread
{
    Q_OBJECT
public:
    ScreenshotLoader(QObject *parent = 0);
    void run();

signals:
    void foundScreenshot(QString , QString );
};

class ScreenshotListWidget : public KListWidget 
{
    Q_OBJECT
public:
    ScreenshotListWidget(QWidget *parent = 0);
    ~ScreenshotListWidget();

    void loadScreenshots();

    int currentScreenshot() const { return m_currentScreenshot; }

    KMenu * contextMenu();

    void reloadMenus() { loadOpenWithMenu(); }
signals:
    void disableScreenshotSupport();

    void displayScreenshot(QPixmap screenshot);

    void deletedScreenshot(QPixmap);
    void deletedAllScreenshots();

public slots:
    void viewScreenshot();
    void saveScreenshotAs();

    void addScreenshot(QPixmap image);
    //void trashScreenshots();
    void renameScreenshot();
    void deleteScreenshot();
    void deleteAllScreenshots();

    QString nextScreenshotName();

    void openWith(QAction *);
    void showProperties();

    void deletedScreenshot(const QString &);
    void dirtyScreenshot(const QString &);

    void itemMouseEnter(QListWidgetItem *);
    
private slots:
    void foundScreenshot(QString, QString );

protected:
    void updateScreenshotList();
    void mouseDoubleClickEvent(QMouseEvent *event);
    void contextMenuEvent(QContextMenuEvent *);

private:
    void loadOpenWithMenu();

    int findScreenshotIndex(const QString & );
    void checkTextSize(QListWidgetItem * item);

private:
    KMenu *m_contextMenu;
    KMenu *m_openWithMenu;

    KAction *viewScreenshotAction;
    //KAction *takeScreenshotAction;
    KAction *saveAsAction;

    KAction *renameAction;
    KAction *deleteAction;
    KAction *deleteAllAction;

    KAction *propertiesAction;

    int m_currentScreenshot;

    QString m_screenshotName;

    KFileItemList *m_screenshotsList;
    KDirWatch *m_screenshotWatcher;
    ScreenshotLoader *loader;
};

class ScreenshotViewer : public QWidget
{
    Q_OBJECT
public:
    ScreenshotViewer(QWidget *parent = 0);

    QPixmap pixmap() const { return m_pixmap; }
    void setPixmap(const QPixmap & pixmap) { m_pixmap = pixmap; update(); }

signals:
    void returnToTV();

protected:
    void paintEvent(QPaintEvent *);

private:
    QPushButton *returnToTVPushButton;

    QPixmap m_pixmap;
};

#endif