1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the demonstration applications of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ***************************************************************************/
44 #define SLIDER_RANGE 8
46 #include "mediaplayer.h"
47 #include "ui_settings.h"
55 MediaVideoWidget::MediaVideoWidget(MediaPlayer *player, QWidget *parent) :
56 Phonon::VideoWidget(parent), m_player(player), m_action(this)
58 m_action.setCheckable(true);
59 m_action.setChecked(false);
60 m_action.setShortcut(QKeySequence( Qt::AltModifier + Qt::Key_Return));
61 m_action.setShortcutContext(Qt::WindowShortcut);
62 connect(&m_action, SIGNAL(toggled(bool)), SLOT(setFullScreen(bool)));
67 void MediaVideoWidget::setFullScreen(bool enabled)
69 Phonon::VideoWidget::setFullScreen(enabled);
70 emit fullScreenChanged(enabled);
73 void MediaVideoWidget::mouseDoubleClickEvent(QMouseEvent *e)
75 Phonon::VideoWidget::mouseDoubleClickEvent(e);
76 setFullScreen(!isFullScreen());
79 void MediaVideoWidget::keyPressEvent(QKeyEvent *e)
82 // On non-QWERTY Symbian key-based devices, there is no space key.
83 // The zero key typically is marked with a space character.
84 if (e->key() == Qt::Key_Space || e->key() == Qt::Key_0) {
85 m_player->playPause();
90 // On Symbian devices, there is no key which maps to Qt::Key_Escape
91 // On devices which lack a backspace key (i.e. non-QWERTY devices),
92 // the 'C' key maps to Qt::Key_Backspace
93 else if (e->key() == Qt::Key_Escape || e->key() == Qt::Key_Backspace) {
99 Phonon::VideoWidget::keyPressEvent(e);
102 bool MediaVideoWidget::event(QEvent *e)
107 //we just ignore the cose events on the video widget
108 //this prevents ALT+F4 from having an effect in fullscreen mode
111 case QEvent::MouseMove:
116 case QEvent::WindowStateChange:
118 //we just update the state of the checkbox, in case it wasn't already
119 m_action.setChecked(windowState() & Qt::WindowFullScreen);
120 const Qt::WindowFlags flags = m_player->windowFlags();
121 if (windowState() & Qt::WindowFullScreen) {
122 m_timer.start(1000, this);
135 return Phonon::VideoWidget::event(e);
138 void MediaVideoWidget::timerEvent(QTimerEvent *e)
140 if (e->timerId() == m_timer.timerId()) {
141 //let's store the cursor shape
143 setCursor(Qt::BlankCursor);
146 Phonon::VideoWidget::timerEvent(e);
149 void MediaVideoWidget::dropEvent(QDropEvent *e)
151 m_player->handleDrop(e);
154 void MediaVideoWidget::dragEnterEvent(QDragEnterEvent *e) {
155 if (e->mimeData()->hasUrls())
156 e->acceptProposedAction();
160 MediaPlayer::MediaPlayer() :
161 playButton(0), nextEffect(0), settingsDialog(0), ui(0),
162 m_AudioOutput(Phonon::VideoCategory),
163 m_videoWidget(new MediaVideoWidget(this))
165 setWindowTitle(tr("Media Player"));
166 setContextMenuPolicy(Qt::CustomContextMenu);
167 m_videoWidget->setContextMenuPolicy(Qt::CustomContextMenu);
169 QSize buttonSize(34, 28);
171 QPushButton *openButton = new QPushButton(this);
173 openButton->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
175 QColor arrowcolor = bpal.buttonText().color();
176 if (arrowcolor == Qt::black)
177 arrowcolor = QColor(80, 80, 80);
178 bpal.setBrush(QPalette::ButtonText, arrowcolor);
179 openButton->setPalette(bpal);
181 rewindButton = new QPushButton(this);
182 rewindButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipBackward));
184 forwardButton = new QPushButton(this);
185 forwardButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipForward));
186 forwardButton->setEnabled(false);
188 playButton = new QPushButton(this);
189 playIcon = style()->standardIcon(QStyle::SP_MediaPlay);
190 pauseIcon = style()->standardIcon(QStyle::SP_MediaPause);
191 playButton->setIcon(playIcon);
193 slider = new Phonon::SeekSlider(this);
194 slider->setMediaObject(&m_MediaObject);
195 volume = new Phonon::VolumeSlider(&m_AudioOutput);
197 QVBoxLayout *vLayout = new QVBoxLayout(this);
198 vLayout->setContentsMargins(8, 8, 8, 8);
200 QHBoxLayout *layout = new QHBoxLayout();
202 info = new QLabel(this);
203 info->setMinimumHeight(70);
204 info->setAcceptDrops(false);
206 info->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
207 info->setLineWidth(2);
208 info->setAutoFillBackground(true);
211 palette.setBrush(QPalette::WindowText, Qt::white);
213 openButton->setMinimumSize(54, buttonSize.height());
214 rewindButton->setMinimumSize(buttonSize);
215 forwardButton->setMinimumSize(buttonSize);
216 playButton->setMinimumSize(buttonSize);
218 info->setStyleSheet("border-image:url(:/images/screen.png) ; border-width:3px");
219 info->setPalette(palette);
220 info->setText(tr("<center>No media</center>"));
222 volume->setFixedWidth(120);
224 layout->addWidget(openButton);
225 layout->addWidget(rewindButton);
226 layout->addWidget(playButton);
227 layout->addWidget(forwardButton);
229 layout->addStretch();
230 layout->addWidget(volume);
232 vLayout->addWidget(info);
234 vLayout->addWidget(&m_videoWindow);
235 QVBoxLayout *buttonPanelLayout = new QVBoxLayout();
236 m_videoWindow.hide();
237 buttonPanelLayout->addLayout(layout);
239 timeLabel = new QLabel(this);
240 progressLabel = new QLabel(this);
241 QWidget *sliderPanel = new QWidget(this);
242 QHBoxLayout *sliderLayout = new QHBoxLayout();
243 sliderLayout->addWidget(slider);
244 sliderLayout->addWidget(timeLabel);
245 sliderLayout->addWidget(progressLabel);
246 sliderLayout->setContentsMargins(0, 0, 0, 0);
247 sliderPanel->setLayout(sliderLayout);
249 buttonPanelLayout->addWidget(sliderPanel);
250 buttonPanelLayout->setContentsMargins(0, 0, 0, 0);
252 layout->setSpacing(4);
253 buttonPanelLayout->setSpacing(0);
254 info->setMinimumHeight(100);
255 info->setFont(QFont("verdana", 15));
256 // QStyle *flatButtonStyle = new QWindowsStyle;
257 openButton->setFocusPolicy(Qt::NoFocus);
258 // openButton->setStyle(flatButtonStyle);
259 // playButton->setStyle(flatButtonStyle);
260 // rewindButton->setStyle(flatButtonStyle);
261 // forwardButton->setStyle(flatButtonStyle);
263 QWidget *buttonPanelWidget = new QWidget(this);
264 buttonPanelWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
265 buttonPanelWidget->setLayout(buttonPanelLayout);
266 vLayout->addWidget(buttonPanelWidget);
268 QHBoxLayout *labelLayout = new QHBoxLayout();
270 vLayout->addLayout(labelLayout);
274 fileMenu = new QMenu(this);
275 QAction *openFileAction = fileMenu->addAction(tr("Open &File..."));
276 QAction *openUrlAction = fileMenu->addAction(tr("Open &Location..."));
278 QAction *selectIAPAction = fileMenu->addAction(tr("Select &IAP..."));
279 connect(selectIAPAction, SIGNAL(triggered(bool)), this, SLOT(selectIAP()));
281 QAction *const openLinkAction = fileMenu->addAction(tr("Open &RAM File..."));
283 connect(openLinkAction, SIGNAL(triggered(bool)), this, SLOT(openRamFile()));
285 fileMenu->addSeparator();
286 QMenu *aspectMenu = fileMenu->addMenu(tr("&Aspect ratio"));
287 QActionGroup *aspectGroup = new QActionGroup(aspectMenu);
288 connect(aspectGroup, SIGNAL(triggered(QAction*)), this, SLOT(aspectChanged(QAction*)));
289 aspectGroup->setExclusive(true);
290 QAction *aspectActionAuto = aspectMenu->addAction(tr("Auto"));
291 aspectActionAuto->setCheckable(true);
292 aspectActionAuto->setChecked(true);
293 aspectGroup->addAction(aspectActionAuto);
294 QAction *aspectActionScale = aspectMenu->addAction(tr("Scale"));
295 aspectActionScale->setCheckable(true);
296 aspectGroup->addAction(aspectActionScale);
297 QAction *aspectAction16_9 = aspectMenu->addAction(tr("16/9"));
298 aspectAction16_9->setCheckable(true);
299 aspectGroup->addAction(aspectAction16_9);
300 QAction *aspectAction4_3 = aspectMenu->addAction(tr("4/3"));
301 aspectAction4_3->setCheckable(true);
302 aspectGroup->addAction(aspectAction4_3);
304 QMenu *scaleMenu = fileMenu->addMenu(tr("&Scale mode"));
305 QActionGroup *scaleGroup = new QActionGroup(scaleMenu);
306 connect(scaleGroup, SIGNAL(triggered(QAction*)), this, SLOT(scaleChanged(QAction*)));
307 scaleGroup->setExclusive(true);
308 QAction *scaleActionFit = scaleMenu->addAction(tr("Fit in view"));
309 scaleActionFit->setCheckable(true);
310 scaleActionFit->setChecked(true);
311 scaleGroup->addAction(scaleActionFit);
312 QAction *scaleActionCrop = scaleMenu->addAction(tr("Scale and crop"));
313 scaleActionCrop->setCheckable(true);
314 scaleGroup->addAction(scaleActionCrop);
316 m_fullScreenAction = fileMenu->addAction(tr("Full screen video"));
317 m_fullScreenAction->setCheckable(true);
318 m_fullScreenAction->setEnabled(false); // enabled by hasVideoChanged
319 bool b = connect(m_fullScreenAction, SIGNAL(toggled(bool)), m_videoWidget, SLOT(setFullScreen(bool)));
321 b = connect(m_videoWidget, SIGNAL(fullScreenChanged(bool)), m_fullScreenAction, SLOT(setChecked(bool)));
324 fileMenu->addSeparator();
325 QAction *settingsAction = fileMenu->addAction(tr("&Settings..."));
327 // Setup signal connections:
328 connect(rewindButton, SIGNAL(clicked()), this, SLOT(rewind()));
329 //connect(openButton, SIGNAL(clicked()), this, SLOT(openFile()));
330 openButton->setMenu(fileMenu);
332 connect(playButton, SIGNAL(clicked()), this, SLOT(playPause()));
333 connect(forwardButton, SIGNAL(clicked()), this, SLOT(forward()));
334 //connect(openButton, SIGNAL(clicked()), this, SLOT(openFile()));
335 connect(settingsAction, SIGNAL(triggered(bool)), this, SLOT(showSettingsDialog()));
336 connect(openUrlAction, SIGNAL(triggered(bool)), this, SLOT(openUrl()));
337 connect(openFileAction, SIGNAL(triggered(bool)), this, SLOT(openFile()));
339 connect(m_videoWidget, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(showContextMenu(const QPoint &)));
340 connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(showContextMenu(const QPoint &)));
341 connect(&m_MediaObject, SIGNAL(metaDataChanged()), this, SLOT(updateInfo()));
342 connect(&m_MediaObject, SIGNAL(totalTimeChanged(qint64)), this, SLOT(updateTime()));
343 connect(&m_MediaObject, SIGNAL(tick(qint64)), this, SLOT(updateTime()));
344 connect(&m_MediaObject, SIGNAL(finished()), this, SLOT(finished()));
345 connect(&m_MediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(stateChanged(Phonon::State,Phonon::State)));
346 connect(&m_MediaObject, SIGNAL(bufferStatus(int)), this, SLOT(bufferStatus(int)));
347 connect(&m_MediaObject, SIGNAL(hasVideoChanged(bool)), this, SLOT(hasVideoChanged(bool)));
349 rewindButton->setEnabled(false);
350 playButton->setEnabled(false);
351 setAcceptDrops(true);
353 m_audioOutputPath = Phonon::createPath(&m_MediaObject, &m_AudioOutput);
354 Phonon::createPath(&m_MediaObject, m_videoWidget);
356 resize(minimumSizeHint());
359 void MediaPlayer::stateChanged(Phonon::State newstate, Phonon::State oldstate)
363 if (oldstate == Phonon::LoadingState) {
364 QRect videoHintRect = QRect(QPoint(0, 0), m_videoWindow.sizeHint());
365 QRect newVideoRect = QApplication::desktop()->screenGeometry().intersected(videoHintRect);
366 if (!m_smallScreen) {
367 if (m_MediaObject.hasVideo()) {
368 // Flush event que so that sizeHint takes the
369 // recently shown/hidden m_videoWindow into account:
370 qApp->processEvents();
373 resize(minimumSize());
378 case Phonon::ErrorState:
379 if (m_MediaObject.errorType() == Phonon::FatalError) {
380 playButton->setEnabled(false);
381 rewindButton->setEnabled(false);
383 m_MediaObject.pause();
385 QMessageBox::warning(this, "Phonon Mediaplayer", m_MediaObject.errorString(), QMessageBox::Close);
388 case Phonon::StoppedState:
389 m_videoWidget->setFullScreen(false);
391 case Phonon::PausedState:
392 playButton->setIcon(playIcon);
393 if (m_MediaObject.currentSource().type() != Phonon::MediaSource::Invalid){
394 playButton->setEnabled(true);
395 rewindButton->setEnabled(true);
397 playButton->setEnabled(false);
398 rewindButton->setEnabled(false);
401 case Phonon::PlayingState:
402 playButton->setEnabled(true);
403 playButton->setIcon(pauseIcon);
404 if (m_MediaObject.hasVideo())
405 m_videoWindow.show();
407 case Phonon::BufferingState:
408 rewindButton->setEnabled(true);
410 case Phonon::LoadingState:
411 rewindButton->setEnabled(false);
417 void MediaPlayer::initSettingsDialog()
419 settingsDialog = new QDialog(this);
420 ui = new Ui_settings();
421 ui->setupUi(settingsDialog);
423 connect(ui->brightnessSlider, SIGNAL(valueChanged(int)), this, SLOT(setBrightness(int)));
424 connect(ui->hueSlider, SIGNAL(valueChanged(int)), this, SLOT(setHue(int)));
425 connect(ui->saturationSlider, SIGNAL(valueChanged(int)), this, SLOT(setSaturation(int)));
426 connect(ui->contrastSlider , SIGNAL(valueChanged(int)), this, SLOT(setContrast(int)));
427 connect(ui->aspectCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setAspect(int)));
428 connect(ui->scalemodeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setScale(int)));
430 ui->brightnessSlider->setValue(int(m_videoWidget->brightness() * SLIDER_RANGE));
431 ui->hueSlider->setValue(int(m_videoWidget->hue() * SLIDER_RANGE));
432 ui->saturationSlider->setValue(int(m_videoWidget->saturation() * SLIDER_RANGE));
433 ui->contrastSlider->setValue(int(m_videoWidget->contrast() * SLIDER_RANGE));
434 ui->aspectCombo->setCurrentIndex(m_videoWidget->aspectRatio());
435 ui->scalemodeCombo->setCurrentIndex(m_videoWidget->scaleMode());
436 connect(ui->effectButton, SIGNAL(clicked()), this, SLOT(configureEffect()));
439 //Cross fading is not currently implemented in the GStreamer backend
440 ui->crossFadeSlider->setVisible(false);
441 ui->crossFadeLabel->setVisible(false);
442 ui->crossFadeLabel1->setVisible(false);
443 ui->crossFadeLabel2->setVisible(false);
444 ui->crossFadeLabel3->setVisible(false);
446 ui->crossFadeSlider->setValue((int)(2 * m_MediaObject.transitionTime() / 1000.0f));
448 // Insert audio devices:
449 QList<Phonon::AudioOutputDevice> devices = Phonon::BackendCapabilities::availableAudioOutputDevices();
450 for (int i=0; i<devices.size(); i++){
451 QString itemText = devices[i].name();
452 if (!devices[i].description().isEmpty()) {
453 itemText += QString::fromLatin1(" (%1)").arg(devices[i].description());
455 ui->deviceCombo->addItem(itemText);
456 if (devices[i] == m_AudioOutput.outputDevice())
457 ui->deviceCombo->setCurrentIndex(i);
460 // Insert audio effects:
461 ui->audioEffectsCombo->addItem(tr("<no effect>"));
462 QList<Phonon::Effect *> currEffects = m_audioOutputPath.effects();
463 Phonon::Effect *currEffect = currEffects.size() ? currEffects[0] : 0;
464 QList<Phonon::EffectDescription> availableEffects = Phonon::BackendCapabilities::availableAudioEffects();
465 for (int i=0; i<availableEffects.size(); i++){
466 ui->audioEffectsCombo->addItem(availableEffects[i].name());
467 if (currEffect && availableEffects[i] == currEffect->description())
468 ui->audioEffectsCombo->setCurrentIndex(i+1);
470 connect(ui->audioEffectsCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(effectChanged()));
474 void MediaPlayer::setVolume(qreal volume)
476 m_AudioOutput.setVolume(volume);
479 void MediaPlayer::setSmallScreen(bool smallScreen)
481 m_smallScreen = smallScreen;
484 void MediaPlayer::effectChanged()
486 int currentIndex = ui->audioEffectsCombo->currentIndex();
488 QList<Phonon::EffectDescription> availableEffects = Phonon::BackendCapabilities::availableAudioEffects();
489 Phonon::EffectDescription chosenEffect = availableEffects[currentIndex - 1];
491 QList<Phonon::Effect *> currEffects = m_audioOutputPath.effects();
492 Phonon::Effect *currentEffect = currEffects.size() ? currEffects[0] : 0;
494 // Deleting the running effect will stop playback, it is deleted when removed from path
495 if (nextEffect && !(currentEffect && (currentEffect->description().name() == nextEffect->description().name())))
498 nextEffect = new Phonon::Effect(chosenEffect);
500 ui->effectButton->setEnabled(currentIndex);
503 void MediaPlayer::showSettingsDialog()
505 const bool hasPausedForDialog = playPauseForDialog();
508 initSettingsDialog();
510 float oldBrightness = m_videoWidget->brightness();
511 float oldHue = m_videoWidget->hue();
512 float oldSaturation = m_videoWidget->saturation();
513 float oldContrast = m_videoWidget->contrast();
514 Phonon::VideoWidget::AspectRatio oldAspect = m_videoWidget->aspectRatio();
515 Phonon::VideoWidget::ScaleMode oldScale = m_videoWidget->scaleMode();
516 int currentEffect = ui->audioEffectsCombo->currentIndex();
517 settingsDialog->exec();
519 if (settingsDialog->result() == QDialog::Accepted){
520 m_MediaObject.setTransitionTime((int)(1000 * float(ui->crossFadeSlider->value()) / 2.0f));
521 QList<Phonon::AudioOutputDevice> devices = Phonon::BackendCapabilities::availableAudioOutputDevices();
522 m_AudioOutput.setOutputDevice(devices[ui->deviceCombo->currentIndex()]);
523 QList<Phonon::Effect *> currEffects = m_audioOutputPath.effects();
524 QList<Phonon::EffectDescription> availableEffects = Phonon::BackendCapabilities::availableAudioEffects();
526 if (ui->audioEffectsCombo->currentIndex() > 0){
527 Phonon::Effect *currentEffect = currEffects.size() ? currEffects[0] : 0;
528 if (!currentEffect || currentEffect->description() != nextEffect->description()){
529 foreach(Phonon::Effect *effect, currEffects) {
530 m_audioOutputPath.removeEffect(effect);
533 m_audioOutputPath.insertEffect(nextEffect);
536 foreach(Phonon::Effect *effect, currEffects) {
537 m_audioOutputPath.removeEffect(effect);
543 // Restore previous settings
544 m_videoWidget->setBrightness(oldBrightness);
545 m_videoWidget->setSaturation(oldSaturation);
546 m_videoWidget->setHue(oldHue);
547 m_videoWidget->setContrast(oldContrast);
548 m_videoWidget->setAspectRatio(oldAspect);
549 m_videoWidget->setScaleMode(oldScale);
550 ui->audioEffectsCombo->setCurrentIndex(currentEffect);
553 if (hasPausedForDialog)
554 m_MediaObject.play();
557 void MediaPlayer::initVideoWindow()
559 QVBoxLayout *videoLayout = new QVBoxLayout();
560 videoLayout->addWidget(m_videoWidget);
561 videoLayout->setContentsMargins(0, 0, 0, 0);
562 m_videoWindow.setLayout(videoLayout);
563 m_videoWindow.setMinimumSize(100, 100);
567 void MediaPlayer::configureEffect()
573 QList<Phonon::Effect *> currEffects = m_audioOutputPath.effects();
574 const QList<Phonon::EffectDescription> availableEffects = Phonon::BackendCapabilities::availableAudioEffects();
575 if (ui->audioEffectsCombo->currentIndex() > 0) {
576 Phonon::EffectDescription chosenEffect = availableEffects[ui->audioEffectsCombo->currentIndex() - 1];
578 QDialog effectDialog;
579 effectDialog.setWindowTitle(tr("Configure effect"));
580 QVBoxLayout *topLayout = new QVBoxLayout(&effectDialog);
582 QLabel *description = new QLabel("<b>Description:</b><br>" + chosenEffect.description(), &effectDialog);
583 description->setWordWrap(true);
584 topLayout->addWidget(description);
586 QScrollArea *scrollArea = new QScrollArea(&effectDialog);
587 topLayout->addWidget(scrollArea);
589 QVariantList savedParamValues;
590 foreach(Phonon::EffectParameter param, nextEffect->parameters()) {
591 savedParamValues << nextEffect->parameterValue(param);
594 QWidget *scrollWidget = new Phonon::EffectWidget(nextEffect);
595 scrollWidget->setMinimumWidth(320);
596 scrollWidget->setContentsMargins(10, 10, 10,10);
597 scrollArea->setWidget(scrollWidget);
599 QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &effectDialog);
600 connect(bbox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), &effectDialog, SLOT(accept()));
601 connect(bbox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), &effectDialog, SLOT(reject()));
602 topLayout->addWidget(bbox);
606 if (effectDialog.result() != QDialog::Accepted) {
607 //we need to restore the parameters values
608 int currentIndex = 0;
609 foreach(Phonon::EffectParameter param, nextEffect->parameters()) {
610 nextEffect->setParameterValue(param, savedParamValues.at(currentIndex++));
617 void MediaPlayer::handleDrop(QDropEvent *e)
619 QList<QUrl> urls = e->mimeData()->urls();
620 if (e->proposedAction() == Qt::MoveAction){
621 // Just add to the queue:
622 for (int i=0; i<urls.size(); i++)
623 m_MediaObject.enqueue(Phonon::MediaSource(urls[i].toLocalFile()));
626 m_MediaObject.clearQueue();
627 if (urls.size() > 0) {
628 QString fileName = urls[0].toLocalFile();
631 dir.setFilter(QDir::Files);
632 QStringList entries = dir.entryList();
633 if (entries.size() > 0) {
634 setFile(fileName + QDir::separator() + entries[0]);
635 for (int i=1; i< entries.size(); ++i)
636 m_MediaObject.enqueue(fileName + QDir::separator() + entries[i]);
640 for (int i=1; i<urls.size(); i++)
641 m_MediaObject.enqueue(Phonon::MediaSource(urls[i].toLocalFile()));
645 forwardButton->setEnabled(m_MediaObject.queue().size() > 0);
646 m_MediaObject.play();
649 void MediaPlayer::dropEvent(QDropEvent *e)
651 if (e->mimeData()->hasUrls() && e->proposedAction() != Qt::LinkAction) {
652 e->acceptProposedAction();
659 void MediaPlayer::dragEnterEvent(QDragEnterEvent *e)
664 void MediaPlayer::dragMoveEvent(QDragMoveEvent *e)
666 if (e->mimeData()->hasUrls()) {
667 if (e->proposedAction() == Qt::CopyAction || e->proposedAction() == Qt::MoveAction){
668 e->acceptProposedAction();
673 void MediaPlayer::playPause()
675 if (m_MediaObject.state() == Phonon::PlayingState)
676 m_MediaObject.pause();
678 if (m_MediaObject.currentTime() == m_MediaObject.totalTime())
679 m_MediaObject.seek(0);
680 m_MediaObject.play();
684 void MediaPlayer::setFile(const QString &fileName)
686 setWindowTitle(fileName.right(fileName.length() - fileName.lastIndexOf('/') - 1));
687 m_MediaObject.setCurrentSource(Phonon::MediaSource(fileName));
688 m_MediaObject.play();
691 void MediaPlayer::setLocation(const QString& location)
693 setWindowTitle(location.right(location.length() - location.lastIndexOf('/') - 1));
694 m_MediaObject.setCurrentSource(Phonon::MediaSource(QUrl::fromEncoded(location.toUtf8())));
695 m_MediaObject.play();
698 bool MediaPlayer::playPauseForDialog()
700 // If we're running on a small screen, we want to pause the video when
701 // popping up dialogs. We neither want to tamper with the state if the
703 if (m_smallScreen && m_MediaObject.hasVideo()) {
704 if (Phonon::PlayingState == m_MediaObject.state()) {
705 m_MediaObject.pause();
712 void MediaPlayer::openFile()
714 const bool hasPausedForDialog = playPauseForDialog();
716 QStringList fileNames = QFileDialog::getOpenFileNames(this, QString(),
717 QDesktopServices::storageLocation(QDesktopServices::MusicLocation));
719 if (hasPausedForDialog)
720 m_MediaObject.play();
722 m_MediaObject.clearQueue();
723 if (fileNames.size() > 0) {
724 QString fileName = fileNames[0];
726 for (int i=1; i<fileNames.size(); i++)
727 m_MediaObject.enqueue(Phonon::MediaSource(fileNames[i]));
729 forwardButton->setEnabled(m_MediaObject.queue().size() > 0);
732 void MediaPlayer::bufferStatus(int percent)
735 progressLabel->setText(QString());
737 QString str = QString::fromLatin1("(%1%)").arg(percent);
738 progressLabel->setText(str);
742 void MediaPlayer::setSaturation(int val)
744 m_videoWidget->setSaturation(val / qreal(SLIDER_RANGE));
747 void MediaPlayer::setHue(int val)
749 m_videoWidget->setHue(val / qreal(SLIDER_RANGE));
752 void MediaPlayer::setAspect(int val)
754 m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatio(val));
757 void MediaPlayer::setScale(int val)
759 m_videoWidget->setScaleMode(Phonon::VideoWidget::ScaleMode(val));
762 void MediaPlayer::setBrightness(int val)
764 m_videoWidget->setBrightness(val / qreal(SLIDER_RANGE));
767 void MediaPlayer::setContrast(int val)
769 m_videoWidget->setContrast(val / qreal(SLIDER_RANGE));
772 void MediaPlayer::updateInfo()
775 QString font = "<font color=#ffeeaa>";
776 QString fontmono = "<font family=\"monospace,courier new\" color=#ffeeaa>";
778 QMap <QString, QString> metaData = m_MediaObject.metaData();
779 QString trackArtist = metaData.value("ARTIST");
780 if (trackArtist.length() > maxLength)
781 trackArtist = trackArtist.left(maxLength) + "...";
783 QString trackTitle = metaData.value("TITLE");
784 int trackBitrate = metaData.value("BITRATE").toInt();
787 if (m_MediaObject.currentSource().type() == Phonon::MediaSource::Url) {
788 fileName = m_MediaObject.currentSource().url().toString();
790 fileName = m_MediaObject.currentSource().fileName();
791 fileName = fileName.right(fileName.length() - fileName.lastIndexOf('/') - 1);
792 if (fileName.length() > maxLength)
793 fileName = fileName.left(maxLength) + "...";
797 if (!trackTitle.isEmpty()) {
798 if (trackTitle.length() > maxLength)
799 trackTitle = trackTitle.left(maxLength) + "...";
800 title = "Title: " + font + trackTitle + "<br></font>";
801 } else if (!fileName.isEmpty()) {
802 if (fileName.length() > maxLength)
803 fileName = fileName.left(maxLength) + "...";
804 title = font + fileName + "</font>";
805 if (m_MediaObject.currentSource().type() == Phonon::MediaSource::Url) {
806 title.prepend("Url: ");
808 title.prepend("File: ");
813 if (!trackArtist.isEmpty())
814 artist = "Artist: " + font + trackArtist + "</font>";
817 if (trackBitrate != 0)
818 bitrate = "<br>Bitrate: " + font + QString::number(trackBitrate/1000) + "kbit</font>";
820 info->setText(title + artist + bitrate);
823 void MediaPlayer::updateTime()
825 long len = m_MediaObject.totalTime();
826 long pos = m_MediaObject.currentTime();
835 QTime playTime(hour%60, min%60, sec%60, msec%1000);
841 QTime stopTime(hour%60, min%60, sec%60, msec%1000);
842 QString timeFormat = "m:ss";
844 timeFormat = "h:mm:ss";
845 timeString = playTime.toString(timeFormat);
847 timeString += " / " + stopTime.toString(timeFormat);
849 timeLabel->setText(timeString);
852 void MediaPlayer::rewind()
854 m_MediaObject.seek(0);
857 void MediaPlayer::forward()
859 QList<Phonon::MediaSource> queue = m_MediaObject.queue();
860 if (queue.size() > 0) {
861 m_MediaObject.setCurrentSource(queue[0]);
862 forwardButton->setEnabled(queue.size() > 1);
863 m_MediaObject.play();
867 void MediaPlayer::openUrl()
870 settings.beginGroup(QLatin1String("BrowserMainWindow"));
871 QString sourceURL = settings.value("location").toString();
873 sourceURL = QInputDialog::getText(this, tr("Open Location"), tr("Please enter a valid address here:"), QLineEdit::Normal, sourceURL, &ok);
874 if (ok && !sourceURL.isEmpty()) {
875 setLocation(sourceURL);
876 settings.setValue("location", sourceURL);
883 void MediaPlayer::openRamFile()
886 settings.beginGroup(QLatin1String("BrowserMainWindow"));
888 const QStringList fileNameList(QFileDialog::getOpenFileNames(this,
890 settings.value("openRamFile").toString(),
891 QLatin1String("RAM files (*.ram)")));
893 if (fileNameList.isEmpty())
898 QByteArray sourceURL;
899 for (int i = 0; i < fileNameList.count(); i++ ) {
900 linkFile.setFileName(fileNameList[i]);
901 if (linkFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
902 while (!linkFile.atEnd()) {
903 sourceURL = linkFile.readLine().trimmed();
904 if (!sourceURL.isEmpty()) {
905 const QUrl url(QUrl::fromEncoded(sourceURL));
914 if (!list.isEmpty()) {
915 m_MediaObject.clearQueue();
916 setLocation(list[0].toString());
917 for (int i = 1; i < list.count(); i++)
918 m_MediaObject.enqueue(Phonon::MediaSource(list[i]));
919 m_MediaObject.play();
922 forwardButton->setEnabled(!m_MediaObject.queue().isEmpty());
923 settings.setValue("openRamFile", fileNameList[0]);
926 void MediaPlayer::finished()
930 void MediaPlayer::showContextMenu(const QPoint &p)
932 fileMenu->popup(m_videoWidget->isFullScreen() ? p : mapToGlobal(p));
935 void MediaPlayer::scaleChanged(QAction *act)
937 if (act->text() == tr("Scale and crop"))
938 m_videoWidget->setScaleMode(Phonon::VideoWidget::ScaleAndCrop);
940 m_videoWidget->setScaleMode(Phonon::VideoWidget::FitInView);
943 void MediaPlayer::aspectChanged(QAction *act)
945 if (act->text() == tr("16/9"))
946 m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatio16_9);
947 else if (act->text() == tr("Scale"))
948 m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatioWidget);
949 else if (act->text() == tr("4/3"))
950 m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatio4_3);
952 m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatioAuto);
955 void MediaPlayer::hasVideoChanged(bool bHasVideo)
957 info->setVisible(!bHasVideo);
958 m_videoWindow.setVisible(bHasVideo);
959 m_fullScreenAction->setEnabled(bHasVideo);
963 void MediaPlayer::selectIAP()
965 TRAPD(err, selectIAPL());
967 QMessageBox::warning(this, "Phonon Mediaplayer", "Error selecting IAP", QMessageBox::Close);
970 void MediaPlayer::selectIAPL()
972 QVariant currentIAPValue = m_MediaObject.property("InternetAccessPointName");
973 QString currentIAPString = currentIAPValue.toString();
975 CCommsDatabase *commsDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
976 CleanupStack::PushL(commsDb);
977 commsDb->ShowHiddenRecords();
978 CCommsDbTableView* view = commsDb->OpenTableLC(TPtrC(IAP));
981 for (TInt l = view->GotoFirstRecord(), i = 0; l != KErrNotFound; l = view->GotoNextRecord(), i++) {
982 TBuf<KCommsDbSvrMaxColumnNameLength> iapName;
983 view->ReadTextL(TPtrC(COMMDB_NAME), iapName);
984 QString iapString = QString::fromUtf16(iapName.Ptr(), iapName.Length());
986 if (iapString == currentIAPString)
989 currentIAPString = QInputDialog::getItem(this, tr("Select Access Point"), tr("Select Access Point"), items, currentIAP, false, &ok);
991 m_MediaObject.setProperty("InternetAccessPointName", currentIAPString);
992 CleanupStack::PopAndDestroy(2); //commsDB, view