/***********************************************************
** Copyright (c) 2009 NGuide
** 
** Contact: vasa_pmr@mail.ru
**
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact me   
 **********************************************************/

#ifndef ITASKBAR_H
#define ITASKBAR_H

#include <qwindowdefs.h>

#include <QtGui/QIcon>

namespace Windows7Support {

    namespace Private {
        struct ITaskbarList3;
    }

typedef unsigned long long ULONGLONG;
#define ITASKBARLIST_REFERENSE pTaskbarList
#define RETURN_ON_FAIL Private::ITaskbarList3 *ITASKBARLIST_REFERENSE = initInterface(); if (!ITASKBARLIST_REFERENSE) return false;
#ifdef Q_OS_WIN
#define CHECK_HRESULT_AND_RELEASE(s) RETURN_ON_FAIL bool result = (s == S_OK); releaseInterface(ITASKBARLIST_REFERENSE); return result;
#else
#define CHECK_HRESULT_AND_RELEASE(s) return false;
#endif

class ITaskBar
{
public:
    enum TaskBarProgress {NoProgress = 0,
                          ProgressIndeterminate = 0x1,
                          ProgressNormal = 0x2,
                          ProgressError = 0x4,
                          ProgressPaused = 0x8};

    struct ThumbinalBarButton {
        unsigned int id;
        QIcon icon;
        QString tip;

        bool enabled,
             visible,
             interactive,
             drawBackground,
             closeThumbBarAfterClick;
    };
    typedef QList<ThumbinalBarButton> ThumbinalBarButtonList;
public:
    ITaskBar();
    static ITaskBar *instance();

    bool setProgressState(WId window, TaskBarProgress state) const;
    bool setProgressValue(WId window, ULONGLONG completed, ULONGLONG total) const;
    bool setProgressValue(WId window, short int percents) const
    {
        return setProgressValue(window, percents, 100);
    }
    bool setOverlayIcon(WId window, const QIcon &overlayIcon, const QString &description) const;

    bool setThumbinalBarButtons(WId window, const QList<ThumbinalBarButton> &buttons) const;
    bool updateThumbinalBarButtons(WId window, const QList<ThumbinalBarButton> &buttons) const;


private:
    inline Private::ITaskbarList3 *initInterface() const;
    inline void releaseInterface(Private::ITaskbarList3 *intf) const;
    HICON iconToHICON(const QIcon &icon) const;
};

} // namespace Windows7Support

#endif // ITASKBAR_H
