summaryrefslogtreecommitdiffstats
path: root/demos/qmediaplayer/mediaplayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'demos/qmediaplayer/mediaplayer.cpp')
-rw-r--r--demos/qmediaplayer/mediaplayer.cpp79
1 files changed, 73 insertions, 6 deletions
diff --git a/demos/qmediaplayer/mediaplayer.cpp b/demos/qmediaplayer/mediaplayer.cpp
index 624bab7..f8ca8ea 100644
--- a/demos/qmediaplayer/mediaplayer.cpp
+++ b/demos/qmediaplayer/mediaplayer.cpp
@@ -266,11 +266,14 @@ MediaPlayer::MediaPlayer(const QString &filePath,
fileMenu = new QMenu(this);
QAction *openFileAction = fileMenu->addAction(tr("Open &File..."));
QAction *openUrlAction = fileMenu->addAction(tr("Open &Location..."));
+ QAction *const openLinkAction = fileMenu->addAction(tr("Open &RAM File..."));
+
+ connect(openLinkAction, SIGNAL(triggered(bool)), this, SLOT(openRamFile()));
fileMenu->addSeparator();
QMenu *aspectMenu = fileMenu->addMenu(tr("&Aspect ratio"));
QActionGroup *aspectGroup = new QActionGroup(aspectMenu);
- connect(aspectGroup, SIGNAL(triggered(QAction *)), this, SLOT(aspectChanged(QAction *)));
+ connect(aspectGroup, SIGNAL(triggered(QAction*)), this, SLOT(aspectChanged(QAction*)));
aspectGroup->setExclusive(true);
QAction *aspectActionAuto = aspectMenu->addAction(tr("Auto"));
aspectActionAuto->setCheckable(true);
@@ -288,7 +291,7 @@ MediaPlayer::MediaPlayer(const QString &filePath,
QMenu *scaleMenu = fileMenu->addMenu(tr("&Scale mode"));
QActionGroup *scaleGroup = new QActionGroup(scaleMenu);
- connect(scaleGroup, SIGNAL(triggered(QAction *)), this, SLOT(scaleChanged(QAction *)));
+ connect(scaleGroup, SIGNAL(triggered(QAction*)), this, SLOT(scaleChanged(QAction*)));
scaleGroup->setExclusive(true);
QAction *scaleActionFit = scaleMenu->addAction(tr("Fit in view"));
scaleActionFit->setCheckable(true);
@@ -313,13 +316,13 @@ MediaPlayer::MediaPlayer(const QString &filePath,
connect(openUrlAction, SIGNAL(triggered(bool)), this, SLOT(openUrl()));
connect(openFileAction, SIGNAL(triggered(bool)), this, SLOT(openFile()));
- connect(m_videoWidget, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(showContextMenu(const QPoint &)));
- connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(showContextMenu(const QPoint &)));
+ connect(m_videoWidget, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showContextMenu(QPoint)));
+ connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showContextMenu(QPoint)));
connect(&m_MediaObject, SIGNAL(metaDataChanged()), this, SLOT(updateInfo()));
connect(&m_MediaObject, SIGNAL(totalTimeChanged(qint64)), this, SLOT(updateTime()));
connect(&m_MediaObject, SIGNAL(tick(qint64)), this, SLOT(updateTime()));
connect(&m_MediaObject, SIGNAL(finished()), this, SLOT(finished()));
- connect(&m_MediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(stateChanged(Phonon::State, Phonon::State)));
+ connect(&m_MediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(stateChanged(Phonon::State,Phonon::State)));
connect(&m_MediaObject, SIGNAL(bufferStatus(int)), this, SLOT(bufferStatus(int)));
connect(&m_MediaObject, SIGNAL(hasVideoChanged(bool)), this, SLOT(hasVideoChanged(bool)));
@@ -355,13 +358,13 @@ void MediaPlayer::stateChanged(Phonon::State newstate, Phonon::State oldstate)
switch (newstate) {
case Phonon::ErrorState:
- QMessageBox::warning(this, "Phonon Mediaplayer", m_MediaObject.errorString(), QMessageBox::Close);
if (m_MediaObject.errorType() == Phonon::FatalError) {
playButton->setEnabled(false);
rewindButton->setEnabled(false);
} else {
m_MediaObject.pause();
}
+ QMessageBox::warning(this, "Phonon Mediaplayer", m_MediaObject.errorString(), QMessageBox::Close);
break;
case Phonon::PausedState:
case Phonon::StoppedState:
@@ -471,6 +474,8 @@ void MediaPlayer::effectChanged()
void MediaPlayer::showSettingsDialog()
{
+ playPauseForDialog();
+
if (!settingsDialog)
initSettingsDialog();
@@ -516,6 +521,8 @@ void MediaPlayer::showSettingsDialog()
m_videoWidget->setScaleMode(oldScale);
ui->audioEffectsCombo->setCurrentIndex(currentEffect);
}
+
+ playPauseForDialog();
}
void MediaPlayer::initVideoWindow()
@@ -652,10 +659,25 @@ void MediaPlayer::setFile(const QString &fileName)
m_MediaObject.play();
}
+void MediaPlayer::playPauseForDialog()
+{
+ // If we're running on a small screen, we want to pause the video
+ // when popping up dialogs.
+ if (m_hasSmallScreen &&
+ (Phonon::PlayingState == m_MediaObject.state() ||
+ Phonon::PausedState == m_MediaObject.state()))
+ playPause();
+}
+
void MediaPlayer::openFile()
{
+ playPauseForDialog();
+
QStringList fileNames = QFileDialog::getOpenFileNames(this, QString(),
QDesktopServices::storageLocation(QDesktopServices::MusicLocation));
+
+ playPauseForDialog();
+
m_MediaObject.clearQueue();
if (fileNames.size() > 0) {
QString fileName = fileNames[0];
@@ -816,6 +838,51 @@ void MediaPlayer::openUrl()
}
}
+/*!
+ \since 4.6
+ */
+void MediaPlayer::openRamFile()
+{
+ QSettings settings;
+ settings.beginGroup(QLatin1String("BrowserMainWindow"));
+
+ const QStringList fileNameList(QFileDialog::getOpenFileNames(this,
+ QString(),
+ settings.value("openRamFile").toString(),
+ QLatin1String("RAM files (*.ram)")));
+
+ if (fileNameList.isEmpty())
+ return;
+
+ QFile linkFile;
+ QList<QUrl> list;
+ QByteArray sourceURL;
+ for (int i = 0; i < fileNameList.count(); i++ ) {
+ linkFile.setFileName(fileNameList[i]);
+ if (linkFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ while (!linkFile.atEnd()) {
+ sourceURL = linkFile.readLine().trimmed();
+ if (!sourceURL.isEmpty()) {
+ const QUrl url(QUrl::fromEncoded(sourceURL));
+ if (url.isValid())
+ list.append(url);
+ }
+ }
+ linkFile.close();
+ }
+ }
+
+ if (!list.isEmpty()) {
+ m_MediaObject.setCurrentSource(Phonon::MediaSource(list[0]));
+ m_MediaObject.play();
+ for (int i = 1; i < list.count(); i++)
+ m_MediaObject.enqueue(Phonon::MediaSource(list[i]));
+ }
+
+ forwardButton->setEnabled(!m_MediaObject.queue().isEmpty());
+ settings.setValue("openRamFile", fileNameList[0]);
+}
+
void MediaPlayer::finished()
{
}