Skip to content

Commit

Permalink
Video player view now call the media file dialog instead of the model
Browse files Browse the repository at this point in the history
  • Loading branch information
Rouiller committed Oct 7, 2019
1 parent 955da87 commit 72fe784
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 36 deletions.
3 changes: 1 addition & 2 deletions c_plus_plus/src/steno/model/i_video_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class IVideoPlayer : public QWidget
public:
IVideoPlayer(QWidget *parent = nullptr) : QWidget(parent) {}
virtual ~IVideoPlayer() {}
virtual void openFile() = 0;
virtual void setMedia(const QUrl &url) = 0;
virtual void play() = 0;
virtual void setPosition(int position) = 0;
virtual void setVideoOutput(QVideoWidget *videoOutput) = 0;
Expand All @@ -29,7 +29,6 @@ class IVideoPlayer : public QWidget
void durationChanged(qint64 duration);
void volumeChanged(int volume);
void errorOccured(QString error);
void setUrlCompleted();
};

} // Model
Expand Down
26 changes: 1 addition & 25 deletions c_plus_plus/src/steno/model/video_player.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "video_player.h"

#include <QtWidgets>
#include <QVideoWidget>

namespace Model
Expand Down Expand Up @@ -38,32 +37,9 @@ int VideoPlayer::volume() const
return m_mediaPlayer->volume();
}

void VideoPlayer::openFile()
void VideoPlayer::setMedia(const QUrl &url)
{
QFileDialog fileDialog(this);
fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
fileDialog.setWindowTitle(tr("Open Media File"));

QStringList supportedMimeTypes = m_mediaPlayer->supportedMimeTypes();
if (!supportedMimeTypes.isEmpty())
{
fileDialog.setMimeTypeFilters(supportedMimeTypes);
}

fileDialog.setDirectory(QStandardPaths::standardLocations(QStandardPaths::MoviesLocation).value(0, QDir::homePath()));
if (fileDialog.exec() == QDialog::Accepted)
{
setUrl(fileDialog.selectedUrls().constFirst());
}
}

void VideoPlayer::setUrl(const QUrl &url)
{
setWindowFilePath(url.isLocalFile() ? url.toLocalFile() : QString());
m_mediaPlayer->setMedia(url);

emit setUrlCompleted();

}

void VideoPlayer::play()
Expand Down
3 changes: 1 addition & 2 deletions c_plus_plus/src/steno/model/video_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class VideoPlayer : public IVideoPlayer
public:
explicit VideoPlayer(QWidget *parent = nullptr);
virtual ~VideoPlayer() override;
virtual void openFile() override;
virtual void setMedia(const QUrl &url) override;
virtual void play() override;
virtual void setPosition(int position) override;
virtual void setVideoOutput(QVideoWidget *videoOutput) override;
Expand All @@ -25,7 +25,6 @@ class VideoPlayer : public IVideoPlayer

private:
void onErrorOccured();
void setUrl(const QUrl &url);

QMediaPlayer* m_mediaPlayer;
};
Expand Down
22 changes: 16 additions & 6 deletions c_plus_plus/src/steno/view/views/playback_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#include "model/i_video_player.h"

#include <QtWidgets>
#include <QFileDialog>
#include <QStandardPaths>
#include <QStyle>

namespace View
{
Expand All @@ -20,7 +22,7 @@ PlaybackView::PlaybackView(Model::IVideoPlayer &videoPlayer, QWidget *parent)

m_videoPlayer.setVideoOutput(m_ui->videoWidget);

connect(m_ui->openButton, &QAbstractButton::clicked, [=]{ m_videoPlayer.openFile(); });
connect(m_ui->openButton, &QAbstractButton::clicked, [=]{ openFile(); });
connect(m_ui->playButton, &QAbstractButton::clicked, [=]{ m_videoPlayer.play(); });
connect(m_ui->positionSlider, &QAbstractSlider::sliderMoved, [=](int position){ m_videoPlayer.setPosition(position); });
connect(m_ui->volumeSlider, &QSlider::valueChanged, [=]{ m_videoPlayer.setVolume(volume()); });
Expand All @@ -30,7 +32,6 @@ PlaybackView::PlaybackView(Model::IVideoPlayer &videoPlayer, QWidget *parent)
connect(&m_videoPlayer, &Model::IVideoPlayer::durationChanged, [=](qint64 duration){ onDurationChanged(duration); });
connect(&m_videoPlayer, &Model::IVideoPlayer::volumeChanged, [=](int volume){ setVolume(volume); });
connect(&m_videoPlayer, &Model::IVideoPlayer::errorOccured, [=](QString error){ onErrorOccured(error); });
connect(&m_videoPlayer, &Model::IVideoPlayer::setUrlCompleted, [=]{ onOpenFileAccepted(); });
}

PlaybackView::~PlaybackView()
Expand Down Expand Up @@ -67,10 +68,19 @@ void PlaybackView::onErrorOccured(QString error)
m_ui->errorLabel->setText(error);
}

void PlaybackView::onOpenFileAccepted()
void PlaybackView::openFile()
{
m_ui->errorLabel->setText(QString());
m_ui->playButton->setEnabled(true);
QFileDialog fileDialog(this);
fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
fileDialog.setWindowTitle(tr("Open Media File"));

fileDialog.setDirectory(QStandardPaths::standardLocations(QStandardPaths::MoviesLocation).value(0, QDir::homePath()));
if (fileDialog.exec() == QDialog::Accepted)
{
m_videoPlayer.setMedia(fileDialog.selectedUrls().constFirst());
m_ui->errorLabel->setText(QString());
m_ui->playButton->setEnabled(true);
}
}

int PlaybackView::volume() const
Expand Down
2 changes: 1 addition & 1 deletion c_plus_plus/src/steno/view/views/playback_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class PlaybackView : public AbstractView
void onPositionChanged(qint64 position);
void onDurationChanged(qint64 duration);
void onErrorOccured(QString error);
void onOpenFileAccepted();

private:
void openFile();
int volume() const;
void setVolume(int);

Expand Down

0 comments on commit 72fe784

Please sign in to comment.