<commit_before>#include "csrplayer.h"
#include "ui_csrplayer.h"
#include "playercontrols.h"
#include "playlistmodel.h"
#include "filedialog.h"

#include <QMediaService>
#include <QMediaPlaylist>
#include <QVideoProbe>
#include <QMediaMetaData>
#include <QtWidgets>
#include <QMediaContent>

#ifdef DEBUG_OPEN
#include <QDebug>
#endif

csrplayer::csrplayer(QWidget *parent)
    : QMainWindow(parent)
	, ui(new Ui::csrplayer)
    , coverLabel(0)
{
#ifdef DEBUG_OPEN
	qDebug() << "player created";
#endif
	ui->setupUi(this);
//! [create-objs]
    player = new QMediaPlayer(this);
    // owned by PlaylistModel
    playlist = new QMediaPlaylist();
    player->setPlaylist(playlist);
//! [create-objs]

    connect(player, SIGNAL(durationChanged(qint64)), SLOT(durationChanged(qint64)));
    connect(player, SIGNAL(positionChanged(qint64)), SLOT(positionChanged(qint64)));
    connect(player, SIGNAL(metaDataChanged()), SLOT(metaDataChanged()));
    connect(playlist, SIGNAL(currentIndexChanged(int)), SLOT(playlistPositionChanged(int)));
    connect(player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
            this, SLOT(statusChanged(QMediaPlayer::MediaStatus)));
    connect(player, SIGNAL(bufferStatusChanged(int)), this, SLOT(bufferingProgress(int)));
    connect(player, SIGNAL(videoAvailableChanged(bool)), this, SLOT(videoAvailableChanged(bool)));
    connect(player, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(displayErrorMessage()));

//! [2]
    player->setVideoOutput(ui->videoWidget);

    playlistModel = new PlaylistModel(this);
    playlistModel->setPlaylist(playlist);
//! [2]

#ifdef ENABLE_PLAYLISTVIEW
    playlistView = new QListView();
    QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Preferred);
    sizePolicy1.setHeightForWidth(playlistView->sizePolicy().hasHeightForWidth());
    playlistView->setObjectName(QStringLiteral("playlistView"));
    playlistView->setSizePolicy(sizePolicy1);
    playlistView->setMinimumSize(QSize(0, 0));
    playlistView->setMaximumSize(QSize(16777215, 16777215));
    playlistView->setStyleSheet(QStringLiteral(""));
    playlistView->setModel(playlistModel);
    playlistView->setStyleSheet ("font: 24pt \"Courier\";");
    playlistView->setCurrentIndex(playlistModel->index(playlist->currentIndex(), 0));
    ui->displayLayout->addWidget(playlistView);

    connect(playlistView, SIGNAL(activated(QModelIndex)), this, SLOT(jump(QModelIndex)));
#endif

    ui->slider->setRange(0, player->duration() / 1000);

    connect(ui->slider, SIGNAL(sliderMoved(int)), this, SLOT(seek(int)));

    ui->openButton->setIcon(style()->standardIcon(QStyle::SP_ComputerIcon));
    ui->openButton->setIconSize(QSize(40, 40));
	ui->openButton->setEnabled(true);
    connect(player, SIGNAL(stateChanged(QMediaPlayer::State)),
            this, SLOT(setOpenEnabled(QMediaPlayer::State)));
    ui->closeButton->setIcon(style()->standardIcon(QStyle::SP_DialogCloseButton));
    ui->closeButton->setIconSize(QSize(40, 40));
    connect(ui->openButton, SIGNAL(clicked()), this, SLOT(open()));

    ui->controls->setState(player->state());
    ui->controls->setVolume(player->volume());
    ui->controls->setMuted(ui->controls->isMuted());

    connect(ui->controls, SIGNAL(play()), player, SLOT(play()));
    connect(ui->controls, SIGNAL(pause()), player, SLOT(pause()));
    connect(ui->controls, SIGNAL(stop()), player, SLOT(stop()));
    connect(ui->controls, SIGNAL(next()), playlist, SLOT(next()));
    connect(ui->controls, SIGNAL(previous()), this, SLOT(previousClicked()));
    connect(ui->controls, SIGNAL(changeVolume(int)), player, SLOT(setVolume(int)));
    connect(ui->controls, SIGNAL(changeMuting(bool)), player, SLOT(setMuted(bool)));

    connect(ui->controls, SIGNAL(stop()), ui->videoWidget, SLOT(update()));

    connect(player, SIGNAL(stateChanged(QMediaPlayer::State)),
            ui->controls, SLOT(setState(QMediaPlayer::State)));
    connect(player, SIGNAL(volumeChanged(int)), ui->controls, SLOT(setVolume(int)));
    connect(player, SIGNAL(mutedChanged(bool)), ui->controls, SLOT(setMuted(bool)));

    if (!player->isAvailable()) {
        QMessageBox::warning(this, tr("Service not available"),
                             tr("The QMediaPlayer object does not have a valid service.\n"\
                                "Please check the media service plugins are installed."));

        ui->controls->setEnabled(false);
#ifdef ENABLE_PLAYLISTVIEW
        playlistView->setEnabled(false);
#endif
    }

    metaDataChanged();

    QStringList arguments = qApp->arguments();
    arguments.removeAt(0);
    addToPlaylist(arguments);
}

csrplayer::~csrplayer()
{
#ifdef DEBUG_OPEN
	qDebug() << "Player disconstructed";
#endif
	delete ui;
	delete player;
	delete playlist;
	delete coverLabel;
	delete playlistModel;
}

void csrplayer::open()
{
#ifdef DEBUG_OPEN
	qDebug() << "Open button pressed";
	qDebug() << ui->videoWidget->geometry();
#endif

#if 0
    QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open Files"));
    addToPlaylist(fileNames);
#else
    Dialog *fileDialog = new Dialog(this, "/media/mmcblk1p1/", QFileDialog::List);
	fileDialog->setWindowTitle(tr("Open File"));
    fileDialog->setStyleSheet ("font: 20pt \"Courier\";");
    fileDialog->resize(1024, 600);
    /*if(fileDialog->exec() == QDialog::Accepted) {
        QString fileNames = fileDialog->GetFile();
        qDebug()<<fileNames;
        addToPlaylist(QStringList(fileNames));
    }*/
    fileDialog->exec();
#ifdef DEBUG_OPEN
    qDebug()<<fileDialog->GetFile();
#endif
    addToPlaylist(QStringList(fileDialog->GetFile()));

#endif

#ifdef USE_V4L2sink
#ifdef ENABLE_PLAYLISTVIEW
    player->setOverlay(ui->videoWidget->geometry().x(), ui->videoWidget->geometry().y(), ui->videoWidget->geometry().width(), ui->videoWidget->geometry().height());
#else
    int x, y, w, h;
    qDebug() << DEFAULE_W << DEFAULT_H;
    if (ui->videoWidget->geometry().width() * DEFAULT_H > ui->videoWidget->geometry().height() * DEFAULE_W)
    {
        x = ui->videoWidget->geometry().x() + ui->videoWidget->geometry().width() / 2 - ui->videoWidget->geometry().height() * DEFAULE_W / 2 / DEFAULT_H;
        y = ui->videoWidget->geometry().y();
        w = ui->videoWidget->geometry().height() * DEFAULE_W / DEFAULT_H;
        h = ui->videoWidget->geometry().height();
    }
    else
    {
        x = ui->videoWidget->geometry().x();
        y = ui->videoWidget->geometry().y() + ui->videoWidget->geometry().height() / 2 - ui->videoWidget->geometry().width() * DEFAULT_H / 2 / DEFAULE_W;
        w = ui->videoWidget->geometry().width();
        h = ui->videoWidget->geometry().width() * DEFAULT_H / DEFAULE_W;
    }
    qDebug() << x << y << w << h;
    player->setOverlay(x, y, w, h);
#endif
#endif
}

void csrplayer::setOpenEnabled(QMediaPlayer::State state)
{
    switch (state) {
		case QMediaPlayer::StoppedState:
		ui->openButton->setEnabled(true);
        break;
        case QMediaPlayer::PlayingState:
        ui->openButton->setEnabled(false);
        break;
        case QMediaPlayer::PausedState:
        ui->openButton->setEnabled(false);
        break;
		}
}<commit_msg>bugfix<commit_after>#include "csrplayer.h"
#include "ui_csrplayer.h"
#include "playercontrols.h"
#include "playlistmodel.h"
#include "filedialog.h"

#include <QMediaService>
#include <QMediaPlaylist>
#include <QVideoProbe>
#include <QMediaMetaData>
#include <QtWidgets>
#include <QMediaContent>

#ifdef DEBUG_OPEN
#include <QDebug>
#endif

csrplayer::csrplayer(QWidget *parent)
    : QMainWindow(parent)
	, ui(new Ui::csrplayer)
    , coverLabel(0)
{
#ifdef DEBUG_OPEN
	qDebug() << "player created";
#endif
	ui->setupUi(this);
//! [create-objs]
    player = new QMediaPlayer(this);
    // owned by PlaylistModel
    playlist = new QMediaPlaylist();
    player->setPlaylist(playlist);
//! [create-objs]

    connect(player, SIGNAL(durationChanged(qint64)), SLOT(durationChanged(qint64)));
    connect(player, SIGNAL(positionChanged(qint64)), SLOT(positionChanged(qint64)));
    connect(player, SIGNAL(metaDataChanged()), SLOT(metaDataChanged()));
    connect(playlist, SIGNAL(currentIndexChanged(int)), SLOT(playlistPositionChanged(int)));
    connect(player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
            this, SLOT(statusChanged(QMediaPlayer::MediaStatus)));
    connect(player, SIGNAL(bufferStatusChanged(int)), this, SLOT(bufferingProgress(int)));
    connect(player, SIGNAL(videoAvailableChanged(bool)), this, SLOT(videoAvailableChanged(bool)));
    connect(player, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(displayErrorMessage()));

//! [2]
    player->setVideoOutput(ui->videoWidget);

    playlistModel = new PlaylistModel(this);
    playlistModel->setPlaylist(playlist);
//! [2]

#ifdef ENABLE_PLAYLISTVIEW
    playlistView = new QListView();
    QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Preferred);
    sizePolicy1.setHeightForWidth(playlistView->sizePolicy().hasHeightForWidth());
    playlistView->setObjectName(QStringLiteral("playlistView"));
    playlistView->setSizePolicy(sizePolicy1);
    playlistView->setMinimumSize(QSize(0, 0));
    playlistView->setMaximumSize(QSize(16777215, 16777215));
    playlistView->setStyleSheet(QStringLiteral(""));
    playlistView->setModel(playlistModel);
    playlistView->setStyleSheet ("font: 24pt \"Courier\";");
    playlistView->setCurrentIndex(playlistModel->index(playlist->currentIndex(), 0));
    ui->displayLayout->addWidget(playlistView);

    connect(playlistView, SIGNAL(activated(QModelIndex)), this, SLOT(jump(QModelIndex)));
#endif

    ui->slider->setRange(0, player->duration() / 1000);

    connect(ui->slider, SIGNAL(sliderMoved(int)), this, SLOT(seek(int)));

    ui->openButton->setIcon(style()->standardIcon(QStyle::SP_ComputerIcon));
    ui->openButton->setIconSize(QSize(40, 40));
	ui->openButton->setEnabled(true);
    connect(player, SIGNAL(stateChanged(QMediaPlayer::State)),
            this, SLOT(setOpenEnabled(QMediaPlayer::State)));
    ui->closeButton->setIcon(style()->standardIcon(QStyle::SP_DialogCloseButton));
    ui->closeButton->setIconSize(QSize(40, 40));
    connect(ui->openButton, SIGNAL(clicked()), this, SLOT(open()));

    ui->controls->setState(player->state());
    ui->controls->setVolume(player->volume());
    ui->controls->setMuted(ui->controls->isMuted());

    connect(ui->controls, SIGNAL(play()), player, SLOT(play()));
    connect(ui->controls, SIGNAL(pause()), player, SLOT(pause()));
    connect(ui->controls, SIGNAL(stop()), player, SLOT(stop()));
    connect(ui->controls, SIGNAL(next()), playlist, SLOT(next()));
    connect(ui->controls, SIGNAL(previous()), this, SLOT(previousClicked()));
    connect(ui->controls, SIGNAL(changeVolume(int)), player, SLOT(setVolume(int)));
    connect(ui->controls, SIGNAL(changeMuting(bool)), player, SLOT(setMuted(bool)));

    connect(ui->controls, SIGNAL(stop()), ui->videoWidget, SLOT(update()));

    connect(player, SIGNAL(stateChanged(QMediaPlayer::State)),
            ui->controls, SLOT(setState(QMediaPlayer::State)));
    connect(player, SIGNAL(volumeChanged(int)), ui->controls, SLOT(setVolume(int)));
    connect(player, SIGNAL(mutedChanged(bool)), ui->controls, SLOT(setMuted(bool)));

    if (!player->isAvailable()) {
        QMessageBox::warning(this, tr("Service not available"),
                             tr("The QMediaPlayer object does not have a valid service.\n"\
                                "Please check the media service plugins are installed."));

        ui->controls->setEnabled(false);
#ifdef ENABLE_PLAYLISTVIEW
        playlistView->setEnabled(false);
#endif
    }

    metaDataChanged();

    QStringList arguments = qApp->arguments();
    arguments.removeAt(0);
    addToPlaylist(arguments);
}

csrplayer::~csrplayer()
{
#ifdef DEBUG_OPEN
	qDebug() << "Player disconstructed";
#endif
	delete ui;
	delete player;
	delete playlist;
	delete coverLabel;
	delete playlistModel;
}

void csrplayer::open()
{
#ifdef DEBUG_OPEN
	qDebug() << "Open button pressed";
	qDebug() << ui->videoWidget->geometry();
#endif

#if 0
    QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open Files"));
    addToPlaylist(fileNames);
#else
    Dialog *fileDialog = new Dialog(this, "/media/mmcblk1p1/", QFileDialog::List);
	fileDialog->setWindowTitle(tr("Open File"));
    fileDialog->setStyleSheet ("font: 20pt \"Courier\";");
    fileDialog->resize(1024, 600);
    /*if(fileDialog->exec() == QDialog::Accepted) {
        QString fileNames = fileDialog->GetFile();
        qDebug()<<fileNames;
        addToPlaylist(QStringList(fileNames));
    }*/
    fileDialog->exec();
#ifdef DEBUG_OPEN
    qDebug()<<fileDialog->GetFile();
#endif
    addToPlaylist(QStringList(fileDialog->GetFile()));

#endif

#ifdef USE_V4L2sink
#ifdef ENABLE_PLAYLISTVIEW
    player->setOverlay(ui->videoWidget->geometry().y(), ui->videoWidget->geometry().x(), ui->videoWidget->geometry().width(), ui->videoWidget->geometry().height());
#else
    int x, y, w, h;

    if (ui->videoWidget->geometry().width() * DEFAULT_H > ui->videoWidget->geometry().height() * DEFAULE_W)
    {
        x = ui->videoWidget->geometry().x() + ui->videoWidget->geometry().width() / 2 - ui->videoWidget->geometry().height() * DEFAULE_W / 2 / DEFAULT_H;
        y = ui->videoWidget->geometry().y();
        w = ui->videoWidget->geometry().height() * DEFAULE_W / DEFAULT_H;
        h = ui->videoWidget->geometry().height();
    }
    else
    {
        x = ui->videoWidget->geometry().x();
        y = ui->videoWidget->geometry().y() + ui->videoWidget->geometry().height() / 2 - ui->videoWidget->geometry().width() * DEFAULT_H / 2 / DEFAULE_W;
        w = ui->videoWidget->geometry().width();
        h = ui->videoWidget->geometry().width() * DEFAULT_H / DEFAULE_W;
    }
#ifdef DEBUG_OPEN
    qDebug() << DEFAULE_W << DEFAULT_H;
    qDebug() << x << y << w << h;
#endif
    player->setOverlay(y, x, w, h);
#endif
#endif
}

void csrplayer::setOpenEnabled(QMediaPlayer::State state)
{
    switch (state) {
		case QMediaPlayer::StoppedState:
		ui->openButton->setEnabled(true);
        break;
        case QMediaPlayer::PlayingState:
        ui->openButton->setEnabled(false);
        break;
        case QMediaPlayer::PausedState:
        ui->openButton->setEnabled(false);
        break;
		}
}
{'fraction_non_alphanumeric': 0.1694702310323166, 'fraction_numerical': 0.009352969916940044, 'mean_word_length': 4.738085702843412, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 251, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '291713', 'n_tokens_mistral': 4666, 'n_tokens_neox': 4507, 'n_words': 737}