/*  This file is part of the KDE project
    Copyright (C) 2007 Matthias Kretz <kretz@kde.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) version 3.

    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.

*/

#include "bufferprogress.h"
#include <Phonon/MediaObject>
#include <QtCore/QRect>
#include <QtCore/QUrl>
#include <QtGui/QApplication>
#include <QtGui/QDesktopWidget>
#include <QtGui/QLabel>
#include <QtGui/QX11Info>
#include <QtGui/QProgressBar>
#include <QtGui/QVBoxLayout>
#include <klocale.h>
#include <netwm.h>

BufferProgress::BufferProgress(Phonon::MediaObject *media)
    : QWidget(0, Qt::WindowStaysOnTopHint)
{
    QVBoxLayout *l = new QVBoxLayout(this);
    QLabel *label = new QLabel(i18n("Buffering %1", media->currentSource().url().toString(QUrl::RemoveUserInfo)));
    QProgressBar *bar = new QProgressBar(this);
    l->addWidget(label);
    l->addWidget(bar);
    connect(media, SIGNAL(bufferStatus(int)), bar, SLOT(setValue(int)));
    connect(media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), SLOT(deleteLater()));
    const unsigned long properties[2] = { NET::WMWindowType | NET::WMState, NET::WM2Opacity };
    NETWinInfo info(QX11Info::display(), winId(), QX11Info::appRootWindow(), properties, 2);
    info.setWindowType(NET::Notification);
    info.setOpacity(0xbfffffff);
    info.setState(NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager, NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager);
    const QRect screenRect = QApplication::desktop()->availableGeometry();
    QRect r = rect();
    r.setSize(sizeHint());
    r.moveTopRight(screenRect.topRight());
    setGeometry(r);
    show();
}
