void UIImageOverview::addThumbnail(QString filename, QString tnFilename) {
    QListWidgetItem* item;

    if (pendingThumbnails.contains(filename)) {     // The generated thumbnail is needed
        pendingThumbnails.removeAll(filename);
        item = new QListWidgetItem(
                    QIcon(tnFilename),
                    filename,
                    ui->listWidget);

        ui->listWidget->addItem(item);
        thumbnailsizeLocked = true;

        if (++thumbnailCount >= expectedThumbnailCount) {
    //    if (isDownloadFinished()) {
            updateDownloadStatus();
        }
    }
}
FramelessMainWindow::FramelessMainWindow( QWidget *parent ) :
   QMainWindow( parent ),
   m_scene( new QGraphicsScene( this ) ),
   m_browser( new GraphicsBrowser( m_scene, *this ) ),
   m_mouseFilter( *this, *qApp ),
   m_video( new EventfulVidgetVideo( this ) ),
   m_intro( new QGraphicsScene ),
   m_control( new VideoControl( this ) ),
   m_closeControl( new QFrame( this ) ),
   m_hostApp( new HostApp( m_browser->webView(), this ) )
{
    m_video->hide();
    m_control->hide();
    m_browser->webView()->page()->settings()->setAttribute( QWebSettings::JavascriptCanOpenWindows, true );

    m_control->setVolume( m_hostApp->getVolume() );

    m_closeControl->hide();
    m_closeControl->setStyleSheet( "QFrame{background-color:black; } "
                                   "QPushButton { background-image: url(':/close-styled'); width:31;} "
                                   "QWidget{border:none; padding:0; spacing:0; height:30;}" );
    QHBoxLayout *hl = new QHBoxLayout( m_closeControl );
    hl->setContentsMargins( QMargins() );
    hl->addSpacerItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );

    m_closeButton = new QPushButton();
    m_closeButton->setCursor( Qt::PointingHandCursor );
//  btn->setFlat( true );
    hl->addWidget( m_closeButton );
    connect( m_control, SIGNAL( uiShow() ), m_closeButton, SLOT( show() ) );
    connect( m_control, SIGNAL( uiHide() ), m_closeButton, SLOT( hide() ) );


    setWindowTitle( "Popcorn Time" );
    m_intro->addPixmap( QPixmap( ":/intro" ).scaled( DEFAULT_WIDTH, DEFAULT_HEIGHT, Qt::IgnoreAspectRatio ) );
    m_browser->setScene( m_intro );
    new QShortcut( QKeySequence( "Ctrl+M" ), this, SLOT( minimize() ) );

    QObject::connect( m_hostApp->thread(), SIGNAL( torrentUrlAvailable( QString ) ),
                      this, SLOT( playMedia( QString ) ) );
    QObject::connect( m_browser->webView(), SIGNAL( loadFinished( bool ) ),
                      this, SLOT( removeIntro() ) );
    QObject::connect( m_hostApp, SIGNAL( commandedClose() ),
                      this, SLOT( close() ) );
    QObject::connect( m_hostApp, SIGNAL( commandedMinimize() ),
                      this, SLOT( minimize() ) );
    QObject::connect( m_hostApp, SIGNAL( toggledMaximize() ),
                      this, SLOT( toggleMaximize() ) );
    QObject::connect( m_hostApp, SIGNAL( haveSubtitles( SubtitleItem ) ),
                      m_control, SLOT( addSubtitle( SubtitleItem ) ) );
    QObject::connect( m_hostApp, SIGNAL( downloadInfoChanged( DownloadInfo ) ),
                      m_control, SLOT( updateDownloadStatus( DownloadInfo ) ) );
    QObject::connect( m_control, SIGNAL( volumeChanged( int ) ),
                      m_hostApp, SLOT( setVolume( int ) ) );

    QObject::connect( m_control, SIGNAL( newImage( QString ) ),
                      m_video, SLOT( setImage( QString ) ) );

    QObject::connect( m_control->fullscreenButton(), SIGNAL( clicked() ),
                      this, SLOT( toggleMaximize() ) );
    QObject::connect( &m_mouseFilter, SIGNAL( enterPressed() ),
                      this, SLOT( toggleMaximize() ) );
    QObject::connect( &m_mouseFilter, SIGNAL( upPressed() ),
                      m_control, SLOT( volumeUp() ) );
    QObject::connect( &m_mouseFilter, SIGNAL( downPressed() ),
                      m_control, SLOT( volumeDown() ) );
    QObject::connect( &m_mouseFilter, SIGNAL( pausePressed() ),
                      m_control, SLOT( pauseToggleReq() ) );

    connect( m_video, SIGNAL( mouseEnter() ), m_control, SLOT( showForDefaultPeriod() ) );

    this->setWindowFlags( Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint );
#ifdef Q_OS_MAC
    fixNativeWindow( this );
#endif
    this->setMinimumSize( 800, 330 );
    this->setMouseTracking( true );
    this->setCentralWidget( m_browser );
    qApp->installEventFilter( this );

    reconnectMediaPlayer();

    QObject::connect( VLC::VLCObject(), SIGNAL( mediaPlayerReplaced() ),
                      this, SLOT( reconnectMediaPlayer() ) );
}