#include <QDesktopServices>
#include "menu.h"
+#include "videoplayer.h"
#include "videowidget.h"
#include "aniplayer.h"
#include "directoryplaylist.h"
#ifdef Q_WS_X11
setFocusPolicy(Qt::StrongFocus);
#endif
- resize(640, 480);
-
destroyed = menuMoving = windowMoving = m_closeOnStop = false;
- m_currentFile = "";
#ifndef NO_ANIDBUDPCLIENT
anidb = new AniDBUdpClient(this);
m_automark = 0;
#endif
-
- mediaObject = new Phonon::MediaObject(this);
- mediaController = new Phonon::MediaController(mediaObject);
+ videoPlayer = new VideoPlayer(this, this);
#ifdef GRAPHICS_VIEW_VIDEO
- videoWidget = new VideoWidget();
+ videoWidget = new VideoWidget(); // TODO
#else
- videoWidget = new VideoWidget(this);
#endif
- audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this);
-
- Phonon::createPath(mediaObject, videoWidget);
- Phonon::createPath(mediaObject, audioOutput);
#ifdef GRAPHICS_VIEW_VIDEO
videoScene = new QGraphicsScene(this);
// videoView->resize(size());
#else
- setCentralWidget(videoWidget);
+ setCentralWidget(videoPlayer->videoWidget());
#endif
playlist = new DirectoryPlaylist(this);
addAction("skip85sec", "Skip 1:25", QKeySequence("/"));
- videoWidget->addActions(actions());
+ videoPlayer->videoWidget()->addActions(actions());
- connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(handleStateChange(Phonon::State,Phonon::State)));
- connect(mediaController, SIGNAL(availableSubtitlesChanged()), this, SLOT(updateSubtitles()));
+ connect(videoPlayer, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(handleStateChange(Phonon::State,Phonon::State)));
+ connect(videoPlayer->mediaController(), SIGNAL(availableSubtitlesChanged()), this, SLOT(updateSubtitles()));
#ifndef NO_ANIDBUDPCLIENT
connect(m_actions["markWatched"], SIGNAL(triggered()), this, SLOT(markWatched()));
connect(m_actions["settings"], SIGNAL(triggered()), this, SLOT(anidbSettings()));
connect(m_actions["open"], SIGNAL(triggered()), this, SLOT(open()));
connect(m_actions["play"], SIGNAL(triggered()), this, SLOT(play()));
#ifndef BROWSERPLUGIN_BUILD
- connect(m_actions["togglePlay"], SIGNAL(triggered()), this, SLOT(togglePlay()));
+ connect(m_actions["togglePlay"], SIGNAL(triggered()), videoPlayer, SLOT(togglePlay()));
connect(m_actions["togglePinMenu"], SIGNAL(toggled(bool)), this, SLOT(setPinMenu(bool)));
connect(m_actions["toggleStayOnTop"], SIGNAL(toggled(bool)), this, SLOT(toggleStayOnTop()));
#endif
- connect(m_actions["pause"], SIGNAL(triggered()), this, SLOT(pause()));
- connect(m_actions["stop"], SIGNAL(triggered()), this, SLOT(stop()));
+ connect(m_actions["pause"], SIGNAL(triggered()), videoPlayer, SLOT(pause()));
+ connect(m_actions["stop"], SIGNAL(triggered()), videoPlayer, SLOT(stop()));
- connect(m_actions["volUp"], SIGNAL(triggered()), this, SLOT(volumeUp()));
- connect(m_actions["volDown"], SIGNAL(triggered()), this, SLOT(volumeDown()));
+ connect(m_actions["volUp"], SIGNAL(triggered()), videoPlayer, SLOT(volumeUp()));
+ connect(m_actions["volDown"], SIGNAL(triggered()), videoPlayer, SLOT(volumeDown()));
- connect(m_actions["skip85sec"], SIGNAL(triggered()), this, SLOT(skip()));
+ connect(m_actions["skip85sec"], SIGNAL(triggered()), videoPlayer, SLOT(skip()));
- connect(videoWidget, SIGNAL(menuToggleRequested()), this, SLOT(toggleMenu()));
- connect(videoWidget, SIGNAL(volumeChangeRequested(int)), this, SLOT(changeVolume(int)));
+ connect(videoPlayer->videoWidget(), SIGNAL(menuToggleRequested()), this, SLOT(toggleMenu()));
connect(m_actions["next"], SIGNAL(triggered()), playlist, SLOT(next()));
connect(m_actions["previous"], SIGNAL(triggered()), playlist, SLOT(previous()));
#ifndef BROWSERPLUGIN_BUILD
connect(menu, SIGNAL(positionChanged()), this, SLOT(moveWithMenu()));
#endif
- connect(mediaObject, SIGNAL(totalTimeChanged(qint64)), menu, SLOT(setTotalTime(qint64)));
- connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
+ connect(videoPlayer, SIGNAL(totalTimeChanged(qint64)), menu, SLOT(setTotalTime(qint64)));
+ connect(videoPlayer, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
- menu->oldSeekSlider()->setMediaObject(mediaObject);
- menu->seekSlider()->setMediaObject(mediaObject);
- menu->volumeSlider()->setAudioOutput(audioOutput);
+ menu->oldSeekSlider()->setMediaObject(videoPlayer);
+ menu->seekSlider()->setMediaObject(videoPlayer);
+ menu->volumeSlider()->setAudioOutput(videoPlayer->audioOutput());
#ifdef GRAPHICS_VIEW_VIDEO
- videoSceneMenu->seekSlider()->setMediaObject(mediaObject);
- videoSceneMenu->volumeSlider()->setAudioOutput(audioOutput);
+ videoSceneMenu->seekSlider()->setMediaObject(videoPlayer);
+ videoSceneMenu->volumeSlider()->setAudioOutput(videoPlayer->audioOutput());
#endif
- menu->show();
#ifndef BROWSERPLUGIN_BUILD
move(50, 50);
#endif
anidb->setIdlePolicy(AniDBUdpClient::LogoutIdlePolicy);
#endif
- open(m_currentFile);
}
VideoWindow::~VideoWindow()
destroyed = true;
// HAX
- mediaObject->setCurrentSource(Phonon::MediaSource());
+ videoPlayer->setCurrentSource(Phonon::MediaSource());
+}
+
+QString VideoWindow::currentFile() const
+{
+ return videoPlayer->currentFile();
}
void VideoWindow::toggleMenu()
{
QString dir;
- if (m_currentFile == "")
+ if (videoPlayer->currentFile() == "")
{
dir = QDesktopServices::storageLocation(QDesktopServices::MoviesLocation);
}
else
{
- QFileInfo fileInfo(m_currentFile);
+ QFileInfo fileInfo(videoPlayer->currentFile());
QDir dirObj = fileInfo.absoluteDir();
while (!dirObj.exists())
dirObj = dirObj.absolutePath() + "/..";
menu->showMessage(tr("File %1 does not exist").arg(file));
return;
}
- m_currentFile = file;
- m_currentUrl = "";
playlist->setDirectory(fileInfo.absoluteDir());
playlist->setCurrent(playlist->indexOfFile(file));
menu->showMessage(tr("Opening: %1").arg(file));
Phonon::MediaSource mediaSource(file);
- mediaObject->setCurrentSource(mediaSource);
+ videoPlayer->open(mediaSource);
m_closeOnStop = closeOnStop;
}
menu->showMessage(tr("Opening: %1").arg(url.toString(QUrl::RemovePassword)));
Phonon::MediaSource mediaSource(url);
- mediaObject->setCurrentSource(mediaSource);
- m_currentUrl = url;
+ videoPlayer->open(mediaSource);
m_closeOnStop = false;
play(m_closeOnStop);
void VideoWindow::play(bool closeOnStop)
{
- if ((m_currentFile == "" && !m_currentUrl.isValid()) || mediaObject->currentSource().type() == Phonon::MediaSource::Invalid)
+ if (videoPlayer->currentSource().type() == Phonon::MediaSource::Invalid)
{
open(closeOnStop);
}
- mediaObject->play();
+ videoPlayer->play();
}
void VideoWindow::play(const QString &file, bool closeOnStop)
play(closeOnStop);
}
-void VideoWindow::togglePlay()
-{
- Phonon::State state = mediaObject->state();
-
- switch(state)
- {
- case Phonon::PlayingState:
- mediaObject->pause();
- break;
- case Phonon::LoadingState:
- case Phonon::PausedState:
- case Phonon::StoppedState:
- play();
- break;
- default:
- break;
- }
-}
-
-void VideoWindow::pause()
-{
- mediaObject->pause();
-}
-
-void VideoWindow::stop()
-{
- mediaObject->stop();
-}
-
-void VideoWindow::volumeUp(int by)
-{
- qreal volume = qBound(qreal(0), audioOutput->volume() + qreal(by) * 0.01, qreal(1.0));
- audioOutput->setVolume(volume);
-}
-
-void VideoWindow::volumeDown(int by)
-{
- qreal volume = qBound(qreal(0), audioOutput->volume() - qreal(by) * 0.01, qreal(1.0));
- audioOutput->setVolume(volume);
-}
-
-void VideoWindow::changeVolume(int by)
-{
- qreal volume = qBound(qreal(0), audioOutput->volume() + qreal(by) * 0.01, qreal(1.0));
- audioOutput->setVolume(volume);
-}
-
void VideoWindow::resizeToVideo()
{
#ifdef GRAPHICS_VIEW_VIDEO
videoScene->setSceneRect(videoWidget->rect());
videoView->centerOn(videoWidgetProxy);
#endif
- resize(videoWidget->sizeHint());
+ resize(videoPlayer->videoWidget()->sizeHint());
}
void VideoWindow::setPinMenu(bool pinned)
show();
}
-void VideoWindow::skip(int msec)
-{
- mediaObject->seek(mediaObject->currentTime() + msec);
-}
-
void VideoWindow::about()
{
VersionDialog dialog(this);
switch(newstate)
{
case Phonon::ErrorState:
- //QMessageBox::warning(this, tr("Phonon error"), mediaObject->errorString());
- menu->showMessage(mediaObject->errorString());
+ //QMessageBox::warning(this, tr("Phonon error"), videoPlayer->errorString());
+ menu->showMessage(videoPlayer->errorString());
m_actions["play"]->setDisabled(false);
m_actions["pause"]->setDisabled(true);
if (!m_marked)
addCommand->deleteLater();
- addCommand = new MylistAddCommand(m_currentFile, this);
+ addCommand = new MylistAddCommand(videoPlayer->currentFile(), this);
m_marked = false;
#endif
break;
case Phonon::PlayingState:
- if (newstate == Phonon::PausedState && mediaObject->remainingTime() == 0)
+ if (newstate == Phonon::PausedState && videoPlayer->remainingTime() == 0)
{
playlist->next();
}
if (!m_automark || m_marked)
return;
- int percentPlayed = int(double(time) / double(mediaObject->totalTime()) * double(100));
+ int percentPlayed = int(double(time) / double(videoPlayer->totalTime()) * double(100));
if (percentPlayed < m_automark)
return;
#endif
}
-void VideoWindow::updateChapters()
-{
-
-}
-
-void VideoWindow::updateSubtitles()
-{
- QList<Phonon::SubtitleDescription> subtitles = mediaController->availableSubtitles();
-
- foreach (const Phonon::SubtitleDescription &subtitle, subtitles)
- {
- qDebug() << subtitle;
- if (subtitle.name() == "eng")
- {
-qDebug() << "yep!";
- mediaController->setCurrentSubtitle(subtitle);
- }
- }
-}
-
void VideoWindow::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
menu->hide();
}
#else
- videoWidget->toggleFullScreen();
+ videoPlayer->videoWidget()->toggleFullScreen();
event->accept();
#endif
}
{
// Wheel Up
if (event->delta() > 0)
- changeVolume(5);
+ videoPlayer->changeVolume(5);
// Wheel Down
else
- changeVolume(-5);
+ videoPlayer->changeVolume(-5);
event->accept();
}
settings.beginGroup("settings");
settings.setValue("isMenuPinned", isMenuPinned());
- settings.setValue("currentFile", m_currentFile);
- settings.setValue("volume", audioOutput->volume());
+ settings.setValue("currentFile", videoPlayer->currentFile());
+ settings.setValue("volume", videoPlayer->audioOutput()->volume());
settings.endGroup();
settings.beginGroup("videoWindow");
settings.setValue("geometry", saveGeometry());
settings.beginGroup("settings");
m_actions["togglePinMenu"]->setChecked(settings.value("isMenuPinned", true).toBool());
if (!m_closeOnStop)
- m_currentFile = settings.value("currentFile", "").toString();
- audioOutput->setVolume(settings.value("volume", qreal(1.0)).toDouble());
+ videoPlayer->open(settings.value("currentFile", "").toString());
+ videoPlayer->audioOutput()->setVolume(settings.value("volume", qreal(1.0)).toDouble());
settings.endGroup();
settings.beginGroup("videoWindow");
restoreGeometry(settings.value("geometry", saveGeometry()).toByteArray());
QUrl url(m_currentUrl);
Phonon::MediaSource mediaSource(url);
- mediaObject->setCurrentSource(mediaSource);
- mediaObject->play();
+ videoPlayer->open(mediaSource);
+ videoPlayer->play();
return true;
}