From faef2f5101287ad8ce94cf8e7a4d574a7d6267fd Mon Sep 17 00:00:00 2001 From: Frans Englich Date: Fri, 9 Oct 2009 11:29:51 +0200 Subject: Symbian fix: rename examples ftp and musicplayer to start with q. Symbian already has the executables musicplayer.exe, mediaplayer.exe and ftp.exe, with the result that we overwrite them with Qt. We solve this by renaming the examples, and do it not only on Symbian, such that Qt remains consistent across platforms. This was previously partly done for mediaplayer. The folder name needs to be consistent with the executable, for qtdemo to work. Done jointly with Alessandro. Task-number: QTBUG-4743 Reviewed-by: Alessandro Portale Reviewed-by: Frans Englich --- demos/demos.pro | 2 +- demos/embedded/fluidlauncher/config_s60/config.xml | 2 +- demos/embedded/fluidlauncher/fluidlauncher.pro | 6 +- demos/mediaplayer/images/screen.png | Bin 4358 -> 0 bytes demos/mediaplayer/main.cpp | 89 --- demos/mediaplayer/mediaplayer.cpp | 845 --------------------- demos/mediaplayer/mediaplayer.h | 139 ---- demos/mediaplayer/mediaplayer.pro | 36 - demos/mediaplayer/mediaplayer.qrc | 5 - demos/mediaplayer/settings.ui | 464 ----------- demos/qmediaplayer/images/screen.png | Bin 0 -> 4358 bytes demos/qmediaplayer/main.cpp | 89 +++ demos/qmediaplayer/mediaplayer.cpp | 845 +++++++++++++++++++++ demos/qmediaplayer/mediaplayer.h | 139 ++++ demos/qmediaplayer/mediaplayer.qrc | 5 + demos/qmediaplayer/qmediaplayer.pro | 35 + demos/qmediaplayer/settings.ui | 464 +++++++++++ demos/qtdemo/xml/examples.xml | 4 +- doc/src/demos/mediaplayer.qdoc | 2 +- doc/src/examples/ftp.qdoc | 34 +- doc/src/examples/musicplayerexample.qdoc | 38 +- doc/src/getting-started/demos.qdoc | 2 +- doc/src/getting-started/examples.qdoc | 2 +- examples/network/ftp/ftp.pro | 20 - examples/network/ftp/ftp.qrc | 7 - examples/network/ftp/ftpwindow.cpp | 379 --------- examples/network/ftp/ftpwindow.h | 108 --- examples/network/ftp/images/cdtoparent.png | Bin 139 -> 0 bytes examples/network/ftp/images/dir.png | Bin 154 -> 0 bytes examples/network/ftp/images/file.png | Bin 129 -> 0 bytes examples/network/ftp/main.cpp | 67 -- examples/network/ftp/sym_iap_util.h | 510 ------------- examples/network/network.pro | 4 +- examples/network/qftp/ftp.qrc | 7 + examples/network/qftp/ftpwindow.cpp | 379 +++++++++ examples/network/qftp/ftpwindow.h | 108 +++ examples/network/qftp/images/cdtoparent.png | Bin 0 -> 139 bytes examples/network/qftp/images/dir.png | Bin 0 -> 154 bytes examples/network/qftp/images/file.png | Bin 0 -> 129 bytes examples/network/qftp/main.cpp | 67 ++ examples/network/qftp/qftp.pro | 20 + examples/network/qftp/sym_iap_util.h | 510 +++++++++++++ examples/phonon/musicplayer/main.cpp | 57 -- examples/phonon/musicplayer/mainwindow.cpp | 355 --------- examples/phonon/musicplayer/mainwindow.h | 112 --- examples/phonon/musicplayer/musicplayer.pro | 17 - examples/phonon/phonon.pro | 2 +- examples/phonon/qmusicplayer/main.cpp | 57 ++ examples/phonon/qmusicplayer/mainwindow.cpp | 355 +++++++++ examples/phonon/qmusicplayer/mainwindow.h | 112 +++ examples/phonon/qmusicplayer/qmusicplayer.pro | 17 + 51 files changed, 3258 insertions(+), 3259 deletions(-) delete mode 100644 demos/mediaplayer/images/screen.png delete mode 100644 demos/mediaplayer/main.cpp delete mode 100644 demos/mediaplayer/mediaplayer.cpp delete mode 100644 demos/mediaplayer/mediaplayer.h delete mode 100644 demos/mediaplayer/mediaplayer.pro delete mode 100644 demos/mediaplayer/mediaplayer.qrc delete mode 100644 demos/mediaplayer/settings.ui create mode 100644 demos/qmediaplayer/images/screen.png create mode 100644 demos/qmediaplayer/main.cpp create mode 100644 demos/qmediaplayer/mediaplayer.cpp create mode 100644 demos/qmediaplayer/mediaplayer.h create mode 100644 demos/qmediaplayer/mediaplayer.qrc create mode 100644 demos/qmediaplayer/qmediaplayer.pro create mode 100644 demos/qmediaplayer/settings.ui delete mode 100644 examples/network/ftp/ftp.pro delete mode 100644 examples/network/ftp/ftp.qrc delete mode 100644 examples/network/ftp/ftpwindow.cpp delete mode 100644 examples/network/ftp/ftpwindow.h delete mode 100644 examples/network/ftp/images/cdtoparent.png delete mode 100644 examples/network/ftp/images/dir.png delete mode 100644 examples/network/ftp/images/file.png delete mode 100644 examples/network/ftp/main.cpp delete mode 100644 examples/network/ftp/sym_iap_util.h create mode 100644 examples/network/qftp/ftp.qrc create mode 100644 examples/network/qftp/ftpwindow.cpp create mode 100644 examples/network/qftp/ftpwindow.h create mode 100644 examples/network/qftp/images/cdtoparent.png create mode 100644 examples/network/qftp/images/dir.png create mode 100644 examples/network/qftp/images/file.png create mode 100644 examples/network/qftp/main.cpp create mode 100644 examples/network/qftp/qftp.pro create mode 100644 examples/network/qftp/sym_iap_util.h delete mode 100644 examples/phonon/musicplayer/main.cpp delete mode 100644 examples/phonon/musicplayer/mainwindow.cpp delete mode 100644 examples/phonon/musicplayer/mainwindow.h delete mode 100644 examples/phonon/musicplayer/musicplayer.pro create mode 100644 examples/phonon/qmusicplayer/main.cpp create mode 100644 examples/phonon/qmusicplayer/mainwindow.cpp create mode 100644 examples/phonon/qmusicplayer/mainwindow.h create mode 100644 examples/phonon/qmusicplayer/qmusicplayer.pro diff --git a/demos/demos.pro b/demos/demos.pro index c4b8872..4a9d451 100644 --- a/demos/demos.pro +++ b/demos/demos.pro @@ -64,7 +64,7 @@ demos_arthurplugin.subdir = arthurplugin demos_sqlbrowser.subdir = sqlbrowser demos_undo.subdir = undo demos_qtdemo.subdir = qtdemo -demos_mediaplayer.subdir = mediaplayer +demos_mediaplayer.subdir = qmediaplayer demos_browser.subdir = browser diff --git a/demos/embedded/fluidlauncher/config_s60/config.xml b/demos/embedded/fluidlauncher/config_s60/config.xml index fefa3dd..2c61baf 100644 --- a/demos/embedded/fluidlauncher/config_s60/config.xml +++ b/demos/embedded/fluidlauncher/config_s60/config.xml @@ -6,7 +6,7 @@ - + diff --git a/demos/embedded/fluidlauncher/fluidlauncher.pro b/demos/embedded/fluidlauncher/fluidlauncher.pro index f2abde6..dd931e6 100644 --- a/demos/embedded/fluidlauncher/fluidlauncher.pro +++ b/demos/embedded/fluidlauncher/fluidlauncher.pro @@ -66,7 +66,7 @@ symbian { deform.exe \ pathstroke.exe \ wiggly.exe \ - ftp.exe \ + qftp.exe \ saxbookmarks.exe \ desktopservices.exe \ fridgemagnets.exe \ @@ -85,7 +85,7 @@ symbian { $${EPOCROOT}$$HW_ZDIR$$REG_RESOURCE_IMPORT_DIR/deform_reg.rsc \ $${EPOCROOT}$$HW_ZDIR$$REG_RESOURCE_IMPORT_DIR/pathstroke_reg.rsc \ $${EPOCROOT}$$HW_ZDIR$$REG_RESOURCE_IMPORT_DIR/wiggly_reg.rsc \ - $${EPOCROOT}$$HW_ZDIR$$REG_RESOURCE_IMPORT_DIR/ftp_reg.rsc\ + $${EPOCROOT}$$HW_ZDIR$$REG_RESOURCE_IMPORT_DIR/qftp_reg.rsc\ $${EPOCROOT}$$HW_ZDIR$$REG_RESOURCE_IMPORT_DIR/saxbookmarks_reg.rsc \ $${EPOCROOT}$$HW_ZDIR$$REG_RESOURCE_IMPORT_DIR/desktopservices_reg.rsc \ $${EPOCROOT}$$HW_ZDIR$$REG_RESOURCE_IMPORT_DIR/fridgemagnets_reg.rsc \ @@ -109,7 +109,7 @@ symbian { $${EPOCROOT}$$HW_ZDIR$$APP_RESOURCE_DIR/deform.rsc \ $${EPOCROOT}$$HW_ZDIR$$APP_RESOURCE_DIR/pathstroke.rsc \ $${EPOCROOT}$$HW_ZDIR$$APP_RESOURCE_DIR/wiggly.rsc \ - $${EPOCROOT}$$HW_ZDIR$$APP_RESOURCE_DIR/ftp.rsc\ + $${EPOCROOT}$$HW_ZDIR$$APP_RESOURCE_DIR/qftp.rsc\ $${EPOCROOT}$$HW_ZDIR$$APP_RESOURCE_DIR/saxbookmarks.rsc \ $${EPOCROOT}$$HW_ZDIR$$APP_RESOURCE_DIR/desktopservices.rsc \ $${EPOCROOT}$$HW_ZDIR$$APP_RESOURCE_DIR/fridgemagnets.rsc \ diff --git a/demos/mediaplayer/images/screen.png b/demos/mediaplayer/images/screen.png deleted file mode 100644 index a15df92..0000000 Binary files a/demos/mediaplayer/images/screen.png and /dev/null differ diff --git a/demos/mediaplayer/main.cpp b/demos/mediaplayer/main.cpp deleted file mode 100644 index 66aa445..0000000 --- a/demos/mediaplayer/main.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -***************************************************************************/ - -#include -#include "mediaplayer.h" - -int main (int argc, char *argv[]) -{ - Q_INIT_RESOURCE(mediaplayer); - QApplication app(argc, argv); - app.setApplicationName("Media Player"); - app.setOrganizationName("Qt"); - app.setQuitOnLastWindowClosed(true); - - bool hasSmallScreen = -#ifdef Q_OS_SYMBIAN - /* On Symbian, we always want fullscreen. One reason is that it's not - * possible to launch any demos from the fluidlauncher due to a - * limitation in the emulator. */ - true -#else - false -#endif - ; - - QString fileString; - const QStringList args(app.arguments()); - /* We have a minor problem here, we accept two arguments, both are - * optional: - * - A file name - * - the option "-small-screen", so let's try to cope with that. - */ - for (int i = 0; i < args.count(); ++i) { - const QString &at = args.at(i); - - if (at == QLatin1String("-small-screen")) - hasSmallScreen = true; - else if (i > 0) // We don't want the app name. - fileString = at; - } - - MediaPlayer player(fileString, hasSmallScreen); - - if (hasSmallScreen) - player.showMaximized(); - else - player.show(); - - return app.exec(); -} - diff --git a/demos/mediaplayer/mediaplayer.cpp b/demos/mediaplayer/mediaplayer.cpp deleted file mode 100644 index baac236..0000000 --- a/demos/mediaplayer/mediaplayer.cpp +++ /dev/null @@ -1,845 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -***************************************************************************/ - -#include - -#define SLIDER_RANGE 8 - -#include "mediaplayer.h" -#include "ui_settings.h" - - -class MediaVideoWidget : public Phonon::VideoWidget -{ -public: - MediaVideoWidget(MediaPlayer *player, QWidget *parent = 0) : - Phonon::VideoWidget(parent), m_player(player), m_action(this) - { - m_action.setCheckable(true); - m_action.setChecked(false); - m_action.setShortcut(QKeySequence( Qt::AltModifier + Qt::Key_Return)); - m_action.setShortcutContext(Qt::WindowShortcut); - connect(&m_action, SIGNAL(toggled(bool)), SLOT(setFullScreen(bool))); - addAction(&m_action); - setAcceptDrops(true); - } - -protected: - void mouseDoubleClickEvent(QMouseEvent *e) - { - Phonon::VideoWidget::mouseDoubleClickEvent(e); - setFullScreen(!isFullScreen()); - } - - void keyPressEvent(QKeyEvent *e) - { - if (e->key() == Qt::Key_Space && !e->modifiers()) { - m_player->playPause(); - e->accept(); - return; - } else if (e->key() == Qt::Key_Escape && !e->modifiers()) { - setFullScreen(false); - e->accept(); - return; - } - Phonon::VideoWidget::keyPressEvent(e); - } - - bool event(QEvent *e) - { - switch(e->type()) - { - case QEvent::Close: - //we just ignore the cose events on the video widget - //this prevents ALT+F4 from having an effect in fullscreen mode - e->ignore(); - return true; - case QEvent::MouseMove: -#ifndef QT_NO_CURSOR - unsetCursor(); -#endif - //fall through - case QEvent::WindowStateChange: - { - //we just update the state of the checkbox, in case it wasn't already - m_action.setChecked(windowState() & Qt::WindowFullScreen); - const Qt::WindowFlags flags = m_player->windowFlags(); - if (windowState() & Qt::WindowFullScreen) { - m_timer.start(1000, this); - } else { - m_timer.stop(); -#ifndef QT_NO_CURSOR - unsetCursor(); -#endif - } - } - break; - default: - break; - } - - return Phonon::VideoWidget::event(e); - } - - void timerEvent(QTimerEvent *e) - { - if (e->timerId() == m_timer.timerId()) { - //let's store the cursor shape -#ifndef QT_NO_CURSOR - setCursor(Qt::BlankCursor); -#endif - } - Phonon::VideoWidget::timerEvent(e); - } - - void dropEvent(QDropEvent *e) - { - m_player->handleDrop(e); - } - - void dragEnterEvent(QDragEnterEvent *e) { - if (e->mimeData()->hasUrls()) - e->acceptProposedAction(); - } - -private: - MediaPlayer *m_player; - QBasicTimer m_timer; - QAction m_action; -}; - - -MediaPlayer::MediaPlayer(const QString &filePath, - const bool hasSmallScreen) : - playButton(0), nextEffect(0), settingsDialog(0), ui(0), - m_AudioOutput(Phonon::VideoCategory), - m_videoWidget(new MediaVideoWidget(this)), - m_hasSmallScreen(hasSmallScreen) -{ - setWindowTitle(tr("Media Player")); - setContextMenuPolicy(Qt::CustomContextMenu); - m_videoWidget->setContextMenuPolicy(Qt::CustomContextMenu); - - QSize buttonSize(34, 28); - - QPushButton *openButton = new QPushButton(this); - - openButton->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton)); - QPalette bpal; - QColor arrowcolor = bpal.buttonText().color(); - if (arrowcolor == Qt::black) - arrowcolor = QColor(80, 80, 80); - bpal.setBrush(QPalette::ButtonText, arrowcolor); - openButton->setPalette(bpal); - - rewindButton = new QPushButton(this); - rewindButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipBackward)); - - forwardButton = new QPushButton(this); - forwardButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipForward)); - forwardButton->setEnabled(false); - - playButton = new QPushButton(this); - playIcon = style()->standardIcon(QStyle::SP_MediaPlay); - pauseIcon = style()->standardIcon(QStyle::SP_MediaPause); - playButton->setIcon(playIcon); - - slider = new Phonon::SeekSlider(this); - slider->setMediaObject(&m_MediaObject); - volume = new Phonon::VolumeSlider(&m_AudioOutput); - - QVBoxLayout *vLayout = new QVBoxLayout(this); - vLayout->setContentsMargins(8, 8, 8, 8); - - QHBoxLayout *layout = new QHBoxLayout(); - - info = new QLabel(this); - info->setMinimumHeight(70); - info->setAcceptDrops(false); - info->setMargin(2); - info->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); - info->setLineWidth(2); - info->setAutoFillBackground(true); - - QPalette palette; - palette.setBrush(QPalette::WindowText, Qt::white); -#ifndef Q_WS_MAC - openButton->setMinimumSize(54, buttonSize.height()); - rewindButton->setMinimumSize(buttonSize); - forwardButton->setMinimumSize(buttonSize); - playButton->setMinimumSize(buttonSize); -#endif - info->setStyleSheet("border-image:url(:/images/screen.png) ; border-width:3px"); - info->setPalette(palette); - info->setText(tr("
No media
")); - - volume->setFixedWidth(120); - - layout->addWidget(openButton); - layout->addWidget(rewindButton); - layout->addWidget(playButton); - layout->addWidget(forwardButton); - - layout->addStretch(); - layout->addWidget(volume); - - vLayout->addWidget(info); - initVideoWindow(); - vLayout->addWidget(&m_videoWindow); - QVBoxLayout *buttonPanelLayout = new QVBoxLayout(); - m_videoWindow.hide(); - buttonPanelLayout->addLayout(layout); - - timeLabel = new QLabel(this); - progressLabel = new QLabel(this); - QWidget *sliderPanel = new QWidget(this); - QHBoxLayout *sliderLayout = new QHBoxLayout(); - sliderLayout->addWidget(slider); - sliderLayout->addWidget(timeLabel); - sliderLayout->addWidget(progressLabel); - sliderLayout->setContentsMargins(0, 0, 0, 0); - sliderPanel->setLayout(sliderLayout); - - buttonPanelLayout->addWidget(sliderPanel); - buttonPanelLayout->setContentsMargins(0, 0, 0, 0); -#ifdef Q_OS_MAC - layout->setSpacing(4); - buttonPanelLayout->setSpacing(0); - info->setMinimumHeight(100); - info->setFont(QFont("verdana", 15)); - // QStyle *flatButtonStyle = new QWindowsStyle; - openButton->setFocusPolicy(Qt::NoFocus); - // openButton->setStyle(flatButtonStyle); - // playButton->setStyle(flatButtonStyle); - // rewindButton->setStyle(flatButtonStyle); - // forwardButton->setStyle(flatButtonStyle); - #endif - QWidget *buttonPanelWidget = new QWidget(this); - buttonPanelWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - buttonPanelWidget->setLayout(buttonPanelLayout); - vLayout->addWidget(buttonPanelWidget); - - QHBoxLayout *labelLayout = new QHBoxLayout(); - - vLayout->addLayout(labelLayout); - setLayout(vLayout); - - // Create menu bar: - fileMenu = new QMenu(this); - QAction *openFileAction = fileMenu->addAction(tr("Open &File...")); - QAction *openUrlAction = fileMenu->addAction(tr("Open &Location...")); - - fileMenu->addSeparator(); - QMenu *aspectMenu = fileMenu->addMenu(tr("&Aspect ratio")); - QActionGroup *aspectGroup = new QActionGroup(aspectMenu); - connect(aspectGroup, SIGNAL(triggered(QAction *)), this, SLOT(aspectChanged(QAction *))); - aspectGroup->setExclusive(true); - QAction *aspectActionAuto = aspectMenu->addAction(tr("Auto")); - aspectActionAuto->setCheckable(true); - aspectActionAuto->setChecked(true); - aspectGroup->addAction(aspectActionAuto); - QAction *aspectActionScale = aspectMenu->addAction(tr("Scale")); - aspectActionScale->setCheckable(true); - aspectGroup->addAction(aspectActionScale); - QAction *aspectAction16_9 = aspectMenu->addAction(tr("16/9")); - aspectAction16_9->setCheckable(true); - aspectGroup->addAction(aspectAction16_9); - QAction *aspectAction4_3 = aspectMenu->addAction(tr("4/3")); - aspectAction4_3->setCheckable(true); - aspectGroup->addAction(aspectAction4_3); - - QMenu *scaleMenu = fileMenu->addMenu(tr("&Scale mode")); - QActionGroup *scaleGroup = new QActionGroup(scaleMenu); - connect(scaleGroup, SIGNAL(triggered(QAction *)), this, SLOT(scaleChanged(QAction *))); - scaleGroup->setExclusive(true); - QAction *scaleActionFit = scaleMenu->addAction(tr("Fit in view")); - scaleActionFit->setCheckable(true); - scaleActionFit->setChecked(true); - scaleGroup->addAction(scaleActionFit); - QAction *scaleActionCrop = scaleMenu->addAction(tr("Scale and crop")); - scaleActionCrop->setCheckable(true); - scaleGroup->addAction(scaleActionCrop); - - fileMenu->addSeparator(); - QAction *settingsAction = fileMenu->addAction(tr("&Settings...")); - - // Setup signal connections: - connect(rewindButton, SIGNAL(clicked()), this, SLOT(rewind())); - //connect(openButton, SIGNAL(clicked()), this, SLOT(openFile())); - openButton->setMenu(fileMenu); - - connect(playButton, SIGNAL(clicked()), this, SLOT(playPause())); - connect(forwardButton, SIGNAL(clicked()), this, SLOT(forward())); - //connect(openButton, SIGNAL(clicked()), this, SLOT(openFile())); - connect(settingsAction, SIGNAL(triggered(bool)), this, SLOT(showSettingsDialog())); - 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_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(bufferStatus(int)), this, SLOT(bufferStatus(int))); - - rewindButton->setEnabled(false); - playButton->setEnabled(false); - setAcceptDrops(true); - - m_audioOutputPath = Phonon::createPath(&m_MediaObject, &m_AudioOutput); - Phonon::createPath(&m_MediaObject, m_videoWidget); - - if (!filePath.isEmpty()) - setFile(filePath); - resize(minimumSizeHint()); -} - -void MediaPlayer::stateChanged(Phonon::State newstate, Phonon::State oldstate) -{ - Q_UNUSED(oldstate); - - if (oldstate == Phonon::LoadingState) { - m_videoWindow.setVisible(m_MediaObject.hasVideo()); - info->setVisible(!m_MediaObject.hasVideo()); - QRect videoHintRect = QRect(QPoint(0, 0), m_videoWindow.sizeHint()); - QRect newVideoRect = QApplication::desktop()->screenGeometry().intersected(videoHintRect); - if (!m_hasSmallScreen) { - if (m_MediaObject.hasVideo()) { - // Flush event que so that sizeHint takes the - // recently shown/hidden m_videoWindow into account: - qApp->processEvents(); - resize(sizeHint()); - } else - resize(minimumSize()); - } - } - - 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(); - } - break; - case Phonon::PausedState: - case Phonon::StoppedState: - playButton->setIcon(playIcon); - if (m_MediaObject.currentSource().type() != Phonon::MediaSource::Invalid){ - playButton->setEnabled(true); - rewindButton->setEnabled(true); - } else { - playButton->setEnabled(false); - rewindButton->setEnabled(false); - } - break; - case Phonon::PlayingState: - playButton->setEnabled(true); - playButton->setIcon(pauseIcon); - if (m_MediaObject.hasVideo()) - m_videoWindow.show(); - // Fall through - case Phonon::BufferingState: - rewindButton->setEnabled(true); - break; - case Phonon::LoadingState: - rewindButton->setEnabled(false); - break; - } - -} - -void MediaPlayer::initSettingsDialog() -{ - settingsDialog = new QDialog(this); - ui = new Ui_settings(); - ui->setupUi(settingsDialog); - - connect(ui->brightnessSlider, SIGNAL(valueChanged(int)), this, SLOT(setBrightness(int))); - connect(ui->hueSlider, SIGNAL(valueChanged(int)), this, SLOT(setHue(int))); - connect(ui->saturationSlider, SIGNAL(valueChanged(int)), this, SLOT(setSaturation(int))); - connect(ui->contrastSlider , SIGNAL(valueChanged(int)), this, SLOT(setContrast(int))); - connect(ui->aspectCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setAspect(int))); - connect(ui->scalemodeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setScale(int))); - - ui->brightnessSlider->setValue(int(m_videoWidget->brightness() * SLIDER_RANGE)); - ui->hueSlider->setValue(int(m_videoWidget->hue() * SLIDER_RANGE)); - ui->saturationSlider->setValue(int(m_videoWidget->saturation() * SLIDER_RANGE)); - ui->contrastSlider->setValue(int(m_videoWidget->contrast() * SLIDER_RANGE)); - ui->aspectCombo->setCurrentIndex(m_videoWidget->aspectRatio()); - ui->scalemodeCombo->setCurrentIndex(m_videoWidget->scaleMode()); - connect(ui->effectButton, SIGNAL(clicked()), this, SLOT(configureEffect())); - -#ifdef Q_WS_X11 - //Cross fading is not currently implemented in the GStreamer backend - ui->crossFadeSlider->setVisible(false); - ui->crossFadeLabel->setVisible(false); - ui->crossFadeLabel1->setVisible(false); - ui->crossFadeLabel2->setVisible(false); - ui->crossFadeLabel3->setVisible(false); -#endif - ui->crossFadeSlider->setValue((int)(2 * m_MediaObject.transitionTime() / 1000.0f)); - - // Insert audio devices: - QList devices = Phonon::BackendCapabilities::availableAudioOutputDevices(); - for (int i=0; ideviceCombo->addItem(itemText); - if (devices[i] == m_AudioOutput.outputDevice()) - ui->deviceCombo->setCurrentIndex(i); - } - - // Insert audio effects: - ui->audioEffectsCombo->addItem(tr("")); - QList currEffects = m_audioOutputPath.effects(); - Phonon::Effect *currEffect = currEffects.size() ? currEffects[0] : 0; - QList availableEffects = Phonon::BackendCapabilities::availableAudioEffects(); - for (int i=0; iaudioEffectsCombo->addItem(availableEffects[i].name()); - if (currEffect && availableEffects[i] == currEffect->description()) - ui->audioEffectsCombo->setCurrentIndex(i+1); - } - connect(ui->audioEffectsCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(effectChanged())); - -} - -void MediaPlayer::effectChanged() -{ - int currentIndex = ui->audioEffectsCombo->currentIndex(); - if (currentIndex) { - QList availableEffects = Phonon::BackendCapabilities::availableAudioEffects(); - Phonon::EffectDescription chosenEffect = availableEffects[currentIndex - 1]; - - QList currEffects = m_audioOutputPath.effects(); - Phonon::Effect *currentEffect = currEffects.size() ? currEffects[0] : 0; - - // Deleting the running effect will stop playback, it is deleted when removed from path - if (nextEffect && !(currentEffect && (currentEffect->description().name() == nextEffect->description().name()))) - delete nextEffect; - - nextEffect = new Phonon::Effect(chosenEffect); - } - ui->effectButton->setEnabled(currentIndex); -} - -void MediaPlayer::showSettingsDialog() -{ - if (!settingsDialog) - initSettingsDialog(); - - float oldBrightness = m_videoWidget->brightness(); - float oldHue = m_videoWidget->hue(); - float oldSaturation = m_videoWidget->saturation(); - float oldContrast = m_videoWidget->contrast(); - Phonon::VideoWidget::AspectRatio oldAspect = m_videoWidget->aspectRatio(); - Phonon::VideoWidget::ScaleMode oldScale = m_videoWidget->scaleMode(); - int currentEffect = ui->audioEffectsCombo->currentIndex(); - settingsDialog->exec(); - - if (settingsDialog->result() == QDialog::Accepted){ - m_MediaObject.setTransitionTime((int)(1000 * float(ui->crossFadeSlider->value()) / 2.0f)); - QList devices = Phonon::BackendCapabilities::availableAudioOutputDevices(); - m_AudioOutput.setOutputDevice(devices[ui->deviceCombo->currentIndex()]); - QList currEffects = m_audioOutputPath.effects(); - QList availableEffects = Phonon::BackendCapabilities::availableAudioEffects(); - - if (ui->audioEffectsCombo->currentIndex() > 0){ - Phonon::Effect *currentEffect = currEffects.size() ? currEffects[0] : 0; - if (!currentEffect || currentEffect->description() != nextEffect->description()){ - foreach(Phonon::Effect *effect, currEffects) { - m_audioOutputPath.removeEffect(effect); - delete effect; - } - m_audioOutputPath.insertEffect(nextEffect); - } - } else { - foreach(Phonon::Effect *effect, currEffects) { - m_audioOutputPath.removeEffect(effect); - delete effect; - nextEffect = 0; - } - } - } else { - // Restore previous settings - m_videoWidget->setBrightness(oldBrightness); - m_videoWidget->setSaturation(oldSaturation); - m_videoWidget->setHue(oldHue); - m_videoWidget->setContrast(oldContrast); - m_videoWidget->setAspectRatio(oldAspect); - m_videoWidget->setScaleMode(oldScale); - ui->audioEffectsCombo->setCurrentIndex(currentEffect); - } -} - -void MediaPlayer::initVideoWindow() -{ - QVBoxLayout *videoLayout = new QVBoxLayout(); - videoLayout->addWidget(m_videoWidget); - videoLayout->setContentsMargins(0, 0, 0, 0); - m_videoWindow.setLayout(videoLayout); - m_videoWindow.setMinimumSize(100, 100); -} - - -void MediaPlayer::configureEffect() -{ - if (!nextEffect) - return; - - - QList currEffects = m_audioOutputPath.effects(); - const QList availableEffects = Phonon::BackendCapabilities::availableAudioEffects(); - if (ui->audioEffectsCombo->currentIndex() > 0) { - Phonon::EffectDescription chosenEffect = availableEffects[ui->audioEffectsCombo->currentIndex() - 1]; - - QDialog effectDialog; - effectDialog.setWindowTitle(tr("Configure effect")); - QVBoxLayout *topLayout = new QVBoxLayout(&effectDialog); - - QLabel *description = new QLabel("Description:
" + chosenEffect.description(), &effectDialog); - description->setWordWrap(true); - topLayout->addWidget(description); - - QScrollArea *scrollArea = new QScrollArea(&effectDialog); - topLayout->addWidget(scrollArea); - - QVariantList savedParamValues; - foreach(Phonon::EffectParameter param, nextEffect->parameters()) { - savedParamValues << nextEffect->parameterValue(param); - } - - QWidget *scrollWidget = new Phonon::EffectWidget(nextEffect); - scrollWidget->setMinimumWidth(320); - scrollWidget->setContentsMargins(10, 10, 10,10); - scrollArea->setWidget(scrollWidget); - - QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &effectDialog); - connect(bbox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), &effectDialog, SLOT(accept())); - connect(bbox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), &effectDialog, SLOT(reject())); - topLayout->addWidget(bbox); - - effectDialog.exec(); - - if (effectDialog.result() != QDialog::Accepted) { - //we need to restore the paramaters values - int currentIndex = 0; - foreach(Phonon::EffectParameter param, nextEffect->parameters()) { - nextEffect->setParameterValue(param, savedParamValues.at(currentIndex++)); - } - - } - } -} - -void MediaPlayer::handleDrop(QDropEvent *e) -{ - QList urls = e->mimeData()->urls(); - if (e->proposedAction() == Qt::MoveAction){ - // Just add to the queue: - for (int i=0; i 0) { - QString fileName = urls[0].toLocalFile(); - QDir dir(fileName); - if (dir.exists()) { - dir.setFilter(QDir::Files); - QStringList entries = dir.entryList(); - if (entries.size() > 0) { - setFile(fileName + QDir::separator() + entries[0]); - for (int i=1; i< entries.size(); ++i) - m_MediaObject.enqueue(fileName + QDir::separator() + entries[i]); - } - } else { - setFile(fileName); - for (int i=1; isetEnabled(m_MediaObject.queue().size() > 0); - m_MediaObject.play(); -} - -void MediaPlayer::dropEvent(QDropEvent *e) -{ - if (e->mimeData()->hasUrls() && e->proposedAction() != Qt::LinkAction) { - e->acceptProposedAction(); - handleDrop(e); - } else { - e->ignore(); - } -} - -void MediaPlayer::dragEnterEvent(QDragEnterEvent *e) -{ - dragMoveEvent(e); -} - -void MediaPlayer::dragMoveEvent(QDragMoveEvent *e) -{ - if (e->mimeData()->hasUrls()) { - if (e->proposedAction() == Qt::CopyAction || e->proposedAction() == Qt::MoveAction){ - e->acceptProposedAction(); - } - } -} - -void MediaPlayer::playPause() -{ - if (m_MediaObject.state() == Phonon::PlayingState) - m_MediaObject.pause(); - else { - if (m_MediaObject.currentTime() == m_MediaObject.totalTime()) - m_MediaObject.seek(0); - m_MediaObject.play(); - } -} - -void MediaPlayer::setFile(const QString &fileName) -{ - setWindowTitle(fileName.right(fileName.length() - fileName.lastIndexOf('/') - 1)); - m_MediaObject.setCurrentSource(Phonon::MediaSource(fileName)); - m_MediaObject.play(); -} - -void MediaPlayer::openFile() -{ - QStringList fileNames = QFileDialog::getOpenFileNames(this, QString(), - QDesktopServices::storageLocation(QDesktopServices::MusicLocation)); - m_MediaObject.clearQueue(); - if (fileNames.size() > 0) { - QString fileName = fileNames[0]; - setFile(fileName); - for (int i=1; isetEnabled(m_MediaObject.queue().size() > 0); -} - -void MediaPlayer::bufferStatus(int percent) -{ - if (percent == 0 || percent == 100) - progressLabel->setText(QString()); - else { - QString str = QString::fromLatin1("(%1%)").arg(percent); - progressLabel->setText(str); - } -} - -void MediaPlayer::setSaturation(int val) -{ - m_videoWidget->setSaturation(val / qreal(SLIDER_RANGE)); -} - -void MediaPlayer::setHue(int val) -{ - m_videoWidget->setHue(val / qreal(SLIDER_RANGE)); -} - -void MediaPlayer::setAspect(int val) -{ - m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatio(val)); -} - -void MediaPlayer::setScale(int val) -{ - m_videoWidget->setScaleMode(Phonon::VideoWidget::ScaleMode(val)); -} - -void MediaPlayer::setBrightness(int val) -{ - m_videoWidget->setBrightness(val / qreal(SLIDER_RANGE)); -} - -void MediaPlayer::setContrast(int val) -{ - m_videoWidget->setContrast(val / qreal(SLIDER_RANGE)); -} - -void MediaPlayer::updateInfo() -{ - int maxLength = 30; - QString font = ""; - QString fontmono = ""; - - QMap metaData = m_MediaObject.metaData(); - QString trackArtist = metaData.value("ARTIST"); - if (trackArtist.length() > maxLength) - trackArtist = trackArtist.left(maxLength) + "..."; - - QString trackTitle = metaData.value("TITLE"); - int trackBitrate = metaData.value("BITRATE").toInt(); - - QString fileName; - if (m_MediaObject.currentSource().type() == Phonon::MediaSource::Url) { - fileName = m_MediaObject.currentSource().url().toString(); - } else { - fileName = m_MediaObject.currentSource().fileName(); - fileName = fileName.right(fileName.length() - fileName.lastIndexOf('/') - 1); - if (fileName.length() > maxLength) - fileName = fileName.left(maxLength) + "..."; - } - - QString title; - if (!trackTitle.isEmpty()) { - if (trackTitle.length() > maxLength) - trackTitle = trackTitle.left(maxLength) + "..."; - title = "Title: " + font + trackTitle + "
"; - } else if (!fileName.isEmpty()) { - if (fileName.length() > maxLength) - fileName = fileName.left(maxLength) + "..."; - title = font + fileName + "
"; - if (m_MediaObject.currentSource().type() == Phonon::MediaSource::Url) { - title.prepend("Url: "); - } else { - title.prepend("File: "); - } - } - - QString artist; - if (!trackArtist.isEmpty()) - artist = "Artist: " + font + trackArtist + ""; - - QString bitrate; - if (trackBitrate != 0) - bitrate = "
Bitrate: " + font + QString::number(trackBitrate/1000) + "kbit"; - - info->setText(title + artist + bitrate); -} - -void MediaPlayer::updateTime() -{ - long len = m_MediaObject.totalTime(); - long pos = m_MediaObject.currentTime(); - QString timeString; - if (pos || len) - { - int sec = pos/1000; - int min = sec/60; - int hour = min/60; - int msec = pos; - - QTime playTime(hour%60, min%60, sec%60, msec%1000); - sec = len / 1000; - min = sec / 60; - hour = min / 60; - msec = len; - - QTime stopTime(hour%60, min%60, sec%60, msec%1000); - QString timeFormat = "m:ss"; - if (hour > 0) - timeFormat = "h:mm:ss"; - timeString = playTime.toString(timeFormat); - if (len) - timeString += " / " + stopTime.toString(timeFormat); - } - timeLabel->setText(timeString); -} - -void MediaPlayer::rewind() -{ - m_MediaObject.seek(0); -} - -void MediaPlayer::forward() -{ - QList queue = m_MediaObject.queue(); - if (queue.size() > 0) { - m_MediaObject.setCurrentSource(queue[0]); - forwardButton->setEnabled(queue.size() > 1); - m_MediaObject.play(); - } -} - -void MediaPlayer::openUrl() -{ - QSettings settings; - settings.beginGroup(QLatin1String("BrowserMainWindow")); - QString sourceURL = settings.value("location").toString(); - bool ok = false; - sourceURL = QInputDialog::getText(this, tr("Open Location"), tr("Please enter a valid address here:"), QLineEdit::Normal, sourceURL, &ok); - if (ok && !sourceURL.isEmpty()) { - setWindowTitle(sourceURL.right(sourceURL.length() - sourceURL.lastIndexOf('/') - 1)); - m_MediaObject.setCurrentSource(Phonon::MediaSource(QUrl::fromEncoded(sourceURL.toUtf8()))); - m_MediaObject.play(); - settings.setValue("location", sourceURL); - } -} - -void MediaPlayer::finished() -{ -} - -void MediaPlayer::showContextMenu(const QPoint &p) -{ - fileMenu->popup(m_videoWidget->isFullScreen() ? p : mapToGlobal(p)); -} - -void MediaPlayer::scaleChanged(QAction *act) -{ - if (act->text() == tr("Scale and crop")) - m_videoWidget->setScaleMode(Phonon::VideoWidget::ScaleAndCrop); - else - m_videoWidget->setScaleMode(Phonon::VideoWidget::FitInView); -} - -void MediaPlayer::aspectChanged(QAction *act) -{ - if (act->text() == tr("16/9")) - m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatio16_9); - else if (act->text() == tr("Scale")) - m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatioWidget); - else if (act->text() == tr("4/3")) - m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatio4_3); - else - m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatioAuto); -} - diff --git a/demos/mediaplayer/mediaplayer.h b/demos/mediaplayer/mediaplayer.h deleted file mode 100644 index 40ffa40..0000000 --- a/demos/mediaplayer/mediaplayer.h +++ /dev/null @@ -1,139 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the demonstration applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -***************************************************************************/ - -#ifndef MEDIALAYER_H -#define MEDIAPLAYER_H - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QPushButton; -class QLabel; -class QSlider; -class QTextEdit; -class QMenu; -class Ui_settings; -QT_END_NAMESPACE - -class MediaPlayer : - public QWidget -{ - Q_OBJECT -public: - MediaPlayer(const QString &, - const bool hasSmallScreen); - - void dragEnterEvent(QDragEnterEvent *e); - void dragMoveEvent(QDragMoveEvent *e); - void dropEvent(QDropEvent *e); - void handleDrop(QDropEvent *e); - void setFile(const QString &text); - void initVideoWindow(); - void initSettingsDialog(); - -public slots: - void openFile(); - void rewind(); - void forward(); - void updateInfo(); - void updateTime(); - void finished(); - void playPause(); - void scaleChanged(QAction *); - void aspectChanged(QAction *); - -private slots: - void setAspect(int); - void setScale(int); - void setSaturation(int); - void setContrast(int); - void setHue(int); - void setBrightness(int); - void stateChanged(Phonon::State newstate, Phonon::State oldstate); - void effectChanged(); - void showSettingsDialog(); - void showContextMenu(const QPoint &); - void bufferStatus(int percent); - void openUrl(); - void configureEffect(); - -private: - QIcon playIcon; - QIcon pauseIcon; - QMenu *fileMenu; - QPushButton *playButton; - QPushButton *rewindButton; - QPushButton *forwardButton; - Phonon::SeekSlider *slider; - QLabel *timeLabel; - QLabel *progressLabel; - Phonon::VolumeSlider *volume; - QSlider *m_hueSlider; - QSlider *m_satSlider; - QSlider *m_contSlider; - QLabel *info; - Phonon::Effect *nextEffect; - QDialog *settingsDialog; - Ui_settings *ui; - - QWidget m_videoWindow; - Phonon::MediaObject m_MediaObject; - Phonon::AudioOutput m_AudioOutput; - Phonon::VideoWidget *m_videoWidget; - Phonon::Path m_audioOutputPath; - const bool m_hasSmallScreen; -}; - -#endif //MEDIAPLAYER_H diff --git a/demos/mediaplayer/mediaplayer.pro b/demos/mediaplayer/mediaplayer.pro deleted file mode 100644 index a420cc3..0000000 --- a/demos/mediaplayer/mediaplayer.pro +++ /dev/null @@ -1,36 +0,0 @@ -###################################################################### -# Automatically generated by qmake (2.01a) Thu Aug 23 18:02:14 2007 -###################################################################### - -TEMPLATE = app -TARGET = qmediaplayer -DEPENDPATH += . build src ui - -QT += phonon - -FORMS += settings.ui -RESOURCES += mediaplayer.qrc - -!win32:CONFIG += CONSOLE - -SOURCES += main.cpp mediaplayer.cpp -HEADERS += mediaplayer.h - -target.path = $$[QT_INSTALL_DEMOS]/qmediaplayer -sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.html *.doc images -sources.path = $$[QT_INSTALL_DEMOS]/mediaplayer -INSTALLS += target sources - -wince*{ -DEPLOYMENT_PLUGIN += phonon_ds9 phonon_waveout -} - -symbian { - TARGET.UID3 = 0xA000C613 - - addFiles.sources = ../embedded/desktopservices/data/sax.mp3 - addFiles.path = /data/sounds/ - DEPLOYMENT += addFiles - - include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri) -} diff --git a/demos/mediaplayer/mediaplayer.qrc b/demos/mediaplayer/mediaplayer.qrc deleted file mode 100644 index bcdf404..0000000 --- a/demos/mediaplayer/mediaplayer.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - images/screen.png - - diff --git a/demos/mediaplayer/settings.ui b/demos/mediaplayer/settings.ui deleted file mode 100644 index d2cedd4..0000000 --- a/demos/mediaplayer/settings.ui +++ /dev/null @@ -1,464 +0,0 @@ - - settings - - - - 0 - 0 - 360 - 362 - - - - Settings - - - - - - Video options: - - - true - - - - - - Contrast: - - - - - - - -8 - - - 8 - - - Qt::Horizontal - - - QSlider::TicksBelow - - - 4 - - - - - - - Brightness: - - - - - - - -8 - - - 8 - - - Qt::Horizontal - - - QSlider::TicksBelow - - - 4 - - - - - - - Saturation: - - - - - - - -8 - - - 8 - - - Qt::Horizontal - - - QSlider::TicksBelow - - - 4 - - - - - - - Hue: - - - - - - - -8 - - - 8 - - - Qt::Horizontal - - - QSlider::TicksBelow - - - 4 - - - - - - - Aspect ratio: - - - - - - - - 180 - 0 - - - - - Auto - - - - - Stretch - - - - - 4/3 - - - - - 16/9 - - - - - - - - Scale Mode: - - - - - - - - 180 - 0 - - - - - Fit in view - - - - - Scale and crop - - - - - - - - - - - Audio options: - - - true - - - - - - - - - 0 - 0 - - - - - 90 - 0 - - - - Audio device: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - - 0 - 0 - - - - - - - - - - - - - 0 - 0 - - - - - 90 - 0 - - - - Audio effect: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - - 0 - 0 - - - - - - - - false - - - Setup - - - - - - - - - - - - 0 - 0 - - - - - 90 - 0 - - - - Cross fade: - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - - - - 0 - 0 - - - - -20 - - - 20 - - - 1 - - - 2 - - - 0 - - - Qt::Horizontal - - - QSlider::TicksBelow - - - - - - - - - - 9 - - - - -10 Sec - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 9 - - - - 0 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 9 - - - - 10 Sec - - - - - - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - settings - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - settings - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/demos/qmediaplayer/images/screen.png b/demos/qmediaplayer/images/screen.png new file mode 100644 index 0000000..a15df92 Binary files /dev/null and b/demos/qmediaplayer/images/screen.png differ diff --git a/demos/qmediaplayer/main.cpp b/demos/qmediaplayer/main.cpp new file mode 100644 index 0000000..66aa445 --- /dev/null +++ b/demos/qmediaplayer/main.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include +#include "mediaplayer.h" + +int main (int argc, char *argv[]) +{ + Q_INIT_RESOURCE(mediaplayer); + QApplication app(argc, argv); + app.setApplicationName("Media Player"); + app.setOrganizationName("Qt"); + app.setQuitOnLastWindowClosed(true); + + bool hasSmallScreen = +#ifdef Q_OS_SYMBIAN + /* On Symbian, we always want fullscreen. One reason is that it's not + * possible to launch any demos from the fluidlauncher due to a + * limitation in the emulator. */ + true +#else + false +#endif + ; + + QString fileString; + const QStringList args(app.arguments()); + /* We have a minor problem here, we accept two arguments, both are + * optional: + * - A file name + * - the option "-small-screen", so let's try to cope with that. + */ + for (int i = 0; i < args.count(); ++i) { + const QString &at = args.at(i); + + if (at == QLatin1String("-small-screen")) + hasSmallScreen = true; + else if (i > 0) // We don't want the app name. + fileString = at; + } + + MediaPlayer player(fileString, hasSmallScreen); + + if (hasSmallScreen) + player.showMaximized(); + else + player.show(); + + return app.exec(); +} + diff --git a/demos/qmediaplayer/mediaplayer.cpp b/demos/qmediaplayer/mediaplayer.cpp new file mode 100644 index 0000000..baac236 --- /dev/null +++ b/demos/qmediaplayer/mediaplayer.cpp @@ -0,0 +1,845 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include + +#define SLIDER_RANGE 8 + +#include "mediaplayer.h" +#include "ui_settings.h" + + +class MediaVideoWidget : public Phonon::VideoWidget +{ +public: + MediaVideoWidget(MediaPlayer *player, QWidget *parent = 0) : + Phonon::VideoWidget(parent), m_player(player), m_action(this) + { + m_action.setCheckable(true); + m_action.setChecked(false); + m_action.setShortcut(QKeySequence( Qt::AltModifier + Qt::Key_Return)); + m_action.setShortcutContext(Qt::WindowShortcut); + connect(&m_action, SIGNAL(toggled(bool)), SLOT(setFullScreen(bool))); + addAction(&m_action); + setAcceptDrops(true); + } + +protected: + void mouseDoubleClickEvent(QMouseEvent *e) + { + Phonon::VideoWidget::mouseDoubleClickEvent(e); + setFullScreen(!isFullScreen()); + } + + void keyPressEvent(QKeyEvent *e) + { + if (e->key() == Qt::Key_Space && !e->modifiers()) { + m_player->playPause(); + e->accept(); + return; + } else if (e->key() == Qt::Key_Escape && !e->modifiers()) { + setFullScreen(false); + e->accept(); + return; + } + Phonon::VideoWidget::keyPressEvent(e); + } + + bool event(QEvent *e) + { + switch(e->type()) + { + case QEvent::Close: + //we just ignore the cose events on the video widget + //this prevents ALT+F4 from having an effect in fullscreen mode + e->ignore(); + return true; + case QEvent::MouseMove: +#ifndef QT_NO_CURSOR + unsetCursor(); +#endif + //fall through + case QEvent::WindowStateChange: + { + //we just update the state of the checkbox, in case it wasn't already + m_action.setChecked(windowState() & Qt::WindowFullScreen); + const Qt::WindowFlags flags = m_player->windowFlags(); + if (windowState() & Qt::WindowFullScreen) { + m_timer.start(1000, this); + } else { + m_timer.stop(); +#ifndef QT_NO_CURSOR + unsetCursor(); +#endif + } + } + break; + default: + break; + } + + return Phonon::VideoWidget::event(e); + } + + void timerEvent(QTimerEvent *e) + { + if (e->timerId() == m_timer.timerId()) { + //let's store the cursor shape +#ifndef QT_NO_CURSOR + setCursor(Qt::BlankCursor); +#endif + } + Phonon::VideoWidget::timerEvent(e); + } + + void dropEvent(QDropEvent *e) + { + m_player->handleDrop(e); + } + + void dragEnterEvent(QDragEnterEvent *e) { + if (e->mimeData()->hasUrls()) + e->acceptProposedAction(); + } + +private: + MediaPlayer *m_player; + QBasicTimer m_timer; + QAction m_action; +}; + + +MediaPlayer::MediaPlayer(const QString &filePath, + const bool hasSmallScreen) : + playButton(0), nextEffect(0), settingsDialog(0), ui(0), + m_AudioOutput(Phonon::VideoCategory), + m_videoWidget(new MediaVideoWidget(this)), + m_hasSmallScreen(hasSmallScreen) +{ + setWindowTitle(tr("Media Player")); + setContextMenuPolicy(Qt::CustomContextMenu); + m_videoWidget->setContextMenuPolicy(Qt::CustomContextMenu); + + QSize buttonSize(34, 28); + + QPushButton *openButton = new QPushButton(this); + + openButton->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton)); + QPalette bpal; + QColor arrowcolor = bpal.buttonText().color(); + if (arrowcolor == Qt::black) + arrowcolor = QColor(80, 80, 80); + bpal.setBrush(QPalette::ButtonText, arrowcolor); + openButton->setPalette(bpal); + + rewindButton = new QPushButton(this); + rewindButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipBackward)); + + forwardButton = new QPushButton(this); + forwardButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipForward)); + forwardButton->setEnabled(false); + + playButton = new QPushButton(this); + playIcon = style()->standardIcon(QStyle::SP_MediaPlay); + pauseIcon = style()->standardIcon(QStyle::SP_MediaPause); + playButton->setIcon(playIcon); + + slider = new Phonon::SeekSlider(this); + slider->setMediaObject(&m_MediaObject); + volume = new Phonon::VolumeSlider(&m_AudioOutput); + + QVBoxLayout *vLayout = new QVBoxLayout(this); + vLayout->setContentsMargins(8, 8, 8, 8); + + QHBoxLayout *layout = new QHBoxLayout(); + + info = new QLabel(this); + info->setMinimumHeight(70); + info->setAcceptDrops(false); + info->setMargin(2); + info->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); + info->setLineWidth(2); + info->setAutoFillBackground(true); + + QPalette palette; + palette.setBrush(QPalette::WindowText, Qt::white); +#ifndef Q_WS_MAC + openButton->setMinimumSize(54, buttonSize.height()); + rewindButton->setMinimumSize(buttonSize); + forwardButton->setMinimumSize(buttonSize); + playButton->setMinimumSize(buttonSize); +#endif + info->setStyleSheet("border-image:url(:/images/screen.png) ; border-width:3px"); + info->setPalette(palette); + info->setText(tr("
No media
")); + + volume->setFixedWidth(120); + + layout->addWidget(openButton); + layout->addWidget(rewindButton); + layout->addWidget(playButton); + layout->addWidget(forwardButton); + + layout->addStretch(); + layout->addWidget(volume); + + vLayout->addWidget(info); + initVideoWindow(); + vLayout->addWidget(&m_videoWindow); + QVBoxLayout *buttonPanelLayout = new QVBoxLayout(); + m_videoWindow.hide(); + buttonPanelLayout->addLayout(layout); + + timeLabel = new QLabel(this); + progressLabel = new QLabel(this); + QWidget *sliderPanel = new QWidget(this); + QHBoxLayout *sliderLayout = new QHBoxLayout(); + sliderLayout->addWidget(slider); + sliderLayout->addWidget(timeLabel); + sliderLayout->addWidget(progressLabel); + sliderLayout->setContentsMargins(0, 0, 0, 0); + sliderPanel->setLayout(sliderLayout); + + buttonPanelLayout->addWidget(sliderPanel); + buttonPanelLayout->setContentsMargins(0, 0, 0, 0); +#ifdef Q_OS_MAC + layout->setSpacing(4); + buttonPanelLayout->setSpacing(0); + info->setMinimumHeight(100); + info->setFont(QFont("verdana", 15)); + // QStyle *flatButtonStyle = new QWindowsStyle; + openButton->setFocusPolicy(Qt::NoFocus); + // openButton->setStyle(flatButtonStyle); + // playButton->setStyle(flatButtonStyle); + // rewindButton->setStyle(flatButtonStyle); + // forwardButton->setStyle(flatButtonStyle); + #endif + QWidget *buttonPanelWidget = new QWidget(this); + buttonPanelWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + buttonPanelWidget->setLayout(buttonPanelLayout); + vLayout->addWidget(buttonPanelWidget); + + QHBoxLayout *labelLayout = new QHBoxLayout(); + + vLayout->addLayout(labelLayout); + setLayout(vLayout); + + // Create menu bar: + fileMenu = new QMenu(this); + QAction *openFileAction = fileMenu->addAction(tr("Open &File...")); + QAction *openUrlAction = fileMenu->addAction(tr("Open &Location...")); + + fileMenu->addSeparator(); + QMenu *aspectMenu = fileMenu->addMenu(tr("&Aspect ratio")); + QActionGroup *aspectGroup = new QActionGroup(aspectMenu); + connect(aspectGroup, SIGNAL(triggered(QAction *)), this, SLOT(aspectChanged(QAction *))); + aspectGroup->setExclusive(true); + QAction *aspectActionAuto = aspectMenu->addAction(tr("Auto")); + aspectActionAuto->setCheckable(true); + aspectActionAuto->setChecked(true); + aspectGroup->addAction(aspectActionAuto); + QAction *aspectActionScale = aspectMenu->addAction(tr("Scale")); + aspectActionScale->setCheckable(true); + aspectGroup->addAction(aspectActionScale); + QAction *aspectAction16_9 = aspectMenu->addAction(tr("16/9")); + aspectAction16_9->setCheckable(true); + aspectGroup->addAction(aspectAction16_9); + QAction *aspectAction4_3 = aspectMenu->addAction(tr("4/3")); + aspectAction4_3->setCheckable(true); + aspectGroup->addAction(aspectAction4_3); + + QMenu *scaleMenu = fileMenu->addMenu(tr("&Scale mode")); + QActionGroup *scaleGroup = new QActionGroup(scaleMenu); + connect(scaleGroup, SIGNAL(triggered(QAction *)), this, SLOT(scaleChanged(QAction *))); + scaleGroup->setExclusive(true); + QAction *scaleActionFit = scaleMenu->addAction(tr("Fit in view")); + scaleActionFit->setCheckable(true); + scaleActionFit->setChecked(true); + scaleGroup->addAction(scaleActionFit); + QAction *scaleActionCrop = scaleMenu->addAction(tr("Scale and crop")); + scaleActionCrop->setCheckable(true); + scaleGroup->addAction(scaleActionCrop); + + fileMenu->addSeparator(); + QAction *settingsAction = fileMenu->addAction(tr("&Settings...")); + + // Setup signal connections: + connect(rewindButton, SIGNAL(clicked()), this, SLOT(rewind())); + //connect(openButton, SIGNAL(clicked()), this, SLOT(openFile())); + openButton->setMenu(fileMenu); + + connect(playButton, SIGNAL(clicked()), this, SLOT(playPause())); + connect(forwardButton, SIGNAL(clicked()), this, SLOT(forward())); + //connect(openButton, SIGNAL(clicked()), this, SLOT(openFile())); + connect(settingsAction, SIGNAL(triggered(bool)), this, SLOT(showSettingsDialog())); + 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_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(bufferStatus(int)), this, SLOT(bufferStatus(int))); + + rewindButton->setEnabled(false); + playButton->setEnabled(false); + setAcceptDrops(true); + + m_audioOutputPath = Phonon::createPath(&m_MediaObject, &m_AudioOutput); + Phonon::createPath(&m_MediaObject, m_videoWidget); + + if (!filePath.isEmpty()) + setFile(filePath); + resize(minimumSizeHint()); +} + +void MediaPlayer::stateChanged(Phonon::State newstate, Phonon::State oldstate) +{ + Q_UNUSED(oldstate); + + if (oldstate == Phonon::LoadingState) { + m_videoWindow.setVisible(m_MediaObject.hasVideo()); + info->setVisible(!m_MediaObject.hasVideo()); + QRect videoHintRect = QRect(QPoint(0, 0), m_videoWindow.sizeHint()); + QRect newVideoRect = QApplication::desktop()->screenGeometry().intersected(videoHintRect); + if (!m_hasSmallScreen) { + if (m_MediaObject.hasVideo()) { + // Flush event que so that sizeHint takes the + // recently shown/hidden m_videoWindow into account: + qApp->processEvents(); + resize(sizeHint()); + } else + resize(minimumSize()); + } + } + + 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(); + } + break; + case Phonon::PausedState: + case Phonon::StoppedState: + playButton->setIcon(playIcon); + if (m_MediaObject.currentSource().type() != Phonon::MediaSource::Invalid){ + playButton->setEnabled(true); + rewindButton->setEnabled(true); + } else { + playButton->setEnabled(false); + rewindButton->setEnabled(false); + } + break; + case Phonon::PlayingState: + playButton->setEnabled(true); + playButton->setIcon(pauseIcon); + if (m_MediaObject.hasVideo()) + m_videoWindow.show(); + // Fall through + case Phonon::BufferingState: + rewindButton->setEnabled(true); + break; + case Phonon::LoadingState: + rewindButton->setEnabled(false); + break; + } + +} + +void MediaPlayer::initSettingsDialog() +{ + settingsDialog = new QDialog(this); + ui = new Ui_settings(); + ui->setupUi(settingsDialog); + + connect(ui->brightnessSlider, SIGNAL(valueChanged(int)), this, SLOT(setBrightness(int))); + connect(ui->hueSlider, SIGNAL(valueChanged(int)), this, SLOT(setHue(int))); + connect(ui->saturationSlider, SIGNAL(valueChanged(int)), this, SLOT(setSaturation(int))); + connect(ui->contrastSlider , SIGNAL(valueChanged(int)), this, SLOT(setContrast(int))); + connect(ui->aspectCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setAspect(int))); + connect(ui->scalemodeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setScale(int))); + + ui->brightnessSlider->setValue(int(m_videoWidget->brightness() * SLIDER_RANGE)); + ui->hueSlider->setValue(int(m_videoWidget->hue() * SLIDER_RANGE)); + ui->saturationSlider->setValue(int(m_videoWidget->saturation() * SLIDER_RANGE)); + ui->contrastSlider->setValue(int(m_videoWidget->contrast() * SLIDER_RANGE)); + ui->aspectCombo->setCurrentIndex(m_videoWidget->aspectRatio()); + ui->scalemodeCombo->setCurrentIndex(m_videoWidget->scaleMode()); + connect(ui->effectButton, SIGNAL(clicked()), this, SLOT(configureEffect())); + +#ifdef Q_WS_X11 + //Cross fading is not currently implemented in the GStreamer backend + ui->crossFadeSlider->setVisible(false); + ui->crossFadeLabel->setVisible(false); + ui->crossFadeLabel1->setVisible(false); + ui->crossFadeLabel2->setVisible(false); + ui->crossFadeLabel3->setVisible(false); +#endif + ui->crossFadeSlider->setValue((int)(2 * m_MediaObject.transitionTime() / 1000.0f)); + + // Insert audio devices: + QList devices = Phonon::BackendCapabilities::availableAudioOutputDevices(); + for (int i=0; ideviceCombo->addItem(itemText); + if (devices[i] == m_AudioOutput.outputDevice()) + ui->deviceCombo->setCurrentIndex(i); + } + + // Insert audio effects: + ui->audioEffectsCombo->addItem(tr("")); + QList currEffects = m_audioOutputPath.effects(); + Phonon::Effect *currEffect = currEffects.size() ? currEffects[0] : 0; + QList availableEffects = Phonon::BackendCapabilities::availableAudioEffects(); + for (int i=0; iaudioEffectsCombo->addItem(availableEffects[i].name()); + if (currEffect && availableEffects[i] == currEffect->description()) + ui->audioEffectsCombo->setCurrentIndex(i+1); + } + connect(ui->audioEffectsCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(effectChanged())); + +} + +void MediaPlayer::effectChanged() +{ + int currentIndex = ui->audioEffectsCombo->currentIndex(); + if (currentIndex) { + QList availableEffects = Phonon::BackendCapabilities::availableAudioEffects(); + Phonon::EffectDescription chosenEffect = availableEffects[currentIndex - 1]; + + QList currEffects = m_audioOutputPath.effects(); + Phonon::Effect *currentEffect = currEffects.size() ? currEffects[0] : 0; + + // Deleting the running effect will stop playback, it is deleted when removed from path + if (nextEffect && !(currentEffect && (currentEffect->description().name() == nextEffect->description().name()))) + delete nextEffect; + + nextEffect = new Phonon::Effect(chosenEffect); + } + ui->effectButton->setEnabled(currentIndex); +} + +void MediaPlayer::showSettingsDialog() +{ + if (!settingsDialog) + initSettingsDialog(); + + float oldBrightness = m_videoWidget->brightness(); + float oldHue = m_videoWidget->hue(); + float oldSaturation = m_videoWidget->saturation(); + float oldContrast = m_videoWidget->contrast(); + Phonon::VideoWidget::AspectRatio oldAspect = m_videoWidget->aspectRatio(); + Phonon::VideoWidget::ScaleMode oldScale = m_videoWidget->scaleMode(); + int currentEffect = ui->audioEffectsCombo->currentIndex(); + settingsDialog->exec(); + + if (settingsDialog->result() == QDialog::Accepted){ + m_MediaObject.setTransitionTime((int)(1000 * float(ui->crossFadeSlider->value()) / 2.0f)); + QList devices = Phonon::BackendCapabilities::availableAudioOutputDevices(); + m_AudioOutput.setOutputDevice(devices[ui->deviceCombo->currentIndex()]); + QList currEffects = m_audioOutputPath.effects(); + QList availableEffects = Phonon::BackendCapabilities::availableAudioEffects(); + + if (ui->audioEffectsCombo->currentIndex() > 0){ + Phonon::Effect *currentEffect = currEffects.size() ? currEffects[0] : 0; + if (!currentEffect || currentEffect->description() != nextEffect->description()){ + foreach(Phonon::Effect *effect, currEffects) { + m_audioOutputPath.removeEffect(effect); + delete effect; + } + m_audioOutputPath.insertEffect(nextEffect); + } + } else { + foreach(Phonon::Effect *effect, currEffects) { + m_audioOutputPath.removeEffect(effect); + delete effect; + nextEffect = 0; + } + } + } else { + // Restore previous settings + m_videoWidget->setBrightness(oldBrightness); + m_videoWidget->setSaturation(oldSaturation); + m_videoWidget->setHue(oldHue); + m_videoWidget->setContrast(oldContrast); + m_videoWidget->setAspectRatio(oldAspect); + m_videoWidget->setScaleMode(oldScale); + ui->audioEffectsCombo->setCurrentIndex(currentEffect); + } +} + +void MediaPlayer::initVideoWindow() +{ + QVBoxLayout *videoLayout = new QVBoxLayout(); + videoLayout->addWidget(m_videoWidget); + videoLayout->setContentsMargins(0, 0, 0, 0); + m_videoWindow.setLayout(videoLayout); + m_videoWindow.setMinimumSize(100, 100); +} + + +void MediaPlayer::configureEffect() +{ + if (!nextEffect) + return; + + + QList currEffects = m_audioOutputPath.effects(); + const QList availableEffects = Phonon::BackendCapabilities::availableAudioEffects(); + if (ui->audioEffectsCombo->currentIndex() > 0) { + Phonon::EffectDescription chosenEffect = availableEffects[ui->audioEffectsCombo->currentIndex() - 1]; + + QDialog effectDialog; + effectDialog.setWindowTitle(tr("Configure effect")); + QVBoxLayout *topLayout = new QVBoxLayout(&effectDialog); + + QLabel *description = new QLabel("Description:
" + chosenEffect.description(), &effectDialog); + description->setWordWrap(true); + topLayout->addWidget(description); + + QScrollArea *scrollArea = new QScrollArea(&effectDialog); + topLayout->addWidget(scrollArea); + + QVariantList savedParamValues; + foreach(Phonon::EffectParameter param, nextEffect->parameters()) { + savedParamValues << nextEffect->parameterValue(param); + } + + QWidget *scrollWidget = new Phonon::EffectWidget(nextEffect); + scrollWidget->setMinimumWidth(320); + scrollWidget->setContentsMargins(10, 10, 10,10); + scrollArea->setWidget(scrollWidget); + + QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &effectDialog); + connect(bbox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), &effectDialog, SLOT(accept())); + connect(bbox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), &effectDialog, SLOT(reject())); + topLayout->addWidget(bbox); + + effectDialog.exec(); + + if (effectDialog.result() != QDialog::Accepted) { + //we need to restore the paramaters values + int currentIndex = 0; + foreach(Phonon::EffectParameter param, nextEffect->parameters()) { + nextEffect->setParameterValue(param, savedParamValues.at(currentIndex++)); + } + + } + } +} + +void MediaPlayer::handleDrop(QDropEvent *e) +{ + QList urls = e->mimeData()->urls(); + if (e->proposedAction() == Qt::MoveAction){ + // Just add to the queue: + for (int i=0; i 0) { + QString fileName = urls[0].toLocalFile(); + QDir dir(fileName); + if (dir.exists()) { + dir.setFilter(QDir::Files); + QStringList entries = dir.entryList(); + if (entries.size() > 0) { + setFile(fileName + QDir::separator() + entries[0]); + for (int i=1; i< entries.size(); ++i) + m_MediaObject.enqueue(fileName + QDir::separator() + entries[i]); + } + } else { + setFile(fileName); + for (int i=1; isetEnabled(m_MediaObject.queue().size() > 0); + m_MediaObject.play(); +} + +void MediaPlayer::dropEvent(QDropEvent *e) +{ + if (e->mimeData()->hasUrls() && e->proposedAction() != Qt::LinkAction) { + e->acceptProposedAction(); + handleDrop(e); + } else { + e->ignore(); + } +} + +void MediaPlayer::dragEnterEvent(QDragEnterEvent *e) +{ + dragMoveEvent(e); +} + +void MediaPlayer::dragMoveEvent(QDragMoveEvent *e) +{ + if (e->mimeData()->hasUrls()) { + if (e->proposedAction() == Qt::CopyAction || e->proposedAction() == Qt::MoveAction){ + e->acceptProposedAction(); + } + } +} + +void MediaPlayer::playPause() +{ + if (m_MediaObject.state() == Phonon::PlayingState) + m_MediaObject.pause(); + else { + if (m_MediaObject.currentTime() == m_MediaObject.totalTime()) + m_MediaObject.seek(0); + m_MediaObject.play(); + } +} + +void MediaPlayer::setFile(const QString &fileName) +{ + setWindowTitle(fileName.right(fileName.length() - fileName.lastIndexOf('/') - 1)); + m_MediaObject.setCurrentSource(Phonon::MediaSource(fileName)); + m_MediaObject.play(); +} + +void MediaPlayer::openFile() +{ + QStringList fileNames = QFileDialog::getOpenFileNames(this, QString(), + QDesktopServices::storageLocation(QDesktopServices::MusicLocation)); + m_MediaObject.clearQueue(); + if (fileNames.size() > 0) { + QString fileName = fileNames[0]; + setFile(fileName); + for (int i=1; isetEnabled(m_MediaObject.queue().size() > 0); +} + +void MediaPlayer::bufferStatus(int percent) +{ + if (percent == 0 || percent == 100) + progressLabel->setText(QString()); + else { + QString str = QString::fromLatin1("(%1%)").arg(percent); + progressLabel->setText(str); + } +} + +void MediaPlayer::setSaturation(int val) +{ + m_videoWidget->setSaturation(val / qreal(SLIDER_RANGE)); +} + +void MediaPlayer::setHue(int val) +{ + m_videoWidget->setHue(val / qreal(SLIDER_RANGE)); +} + +void MediaPlayer::setAspect(int val) +{ + m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatio(val)); +} + +void MediaPlayer::setScale(int val) +{ + m_videoWidget->setScaleMode(Phonon::VideoWidget::ScaleMode(val)); +} + +void MediaPlayer::setBrightness(int val) +{ + m_videoWidget->setBrightness(val / qreal(SLIDER_RANGE)); +} + +void MediaPlayer::setContrast(int val) +{ + m_videoWidget->setContrast(val / qreal(SLIDER_RANGE)); +} + +void MediaPlayer::updateInfo() +{ + int maxLength = 30; + QString font = ""; + QString fontmono = ""; + + QMap metaData = m_MediaObject.metaData(); + QString trackArtist = metaData.value("ARTIST"); + if (trackArtist.length() > maxLength) + trackArtist = trackArtist.left(maxLength) + "..."; + + QString trackTitle = metaData.value("TITLE"); + int trackBitrate = metaData.value("BITRATE").toInt(); + + QString fileName; + if (m_MediaObject.currentSource().type() == Phonon::MediaSource::Url) { + fileName = m_MediaObject.currentSource().url().toString(); + } else { + fileName = m_MediaObject.currentSource().fileName(); + fileName = fileName.right(fileName.length() - fileName.lastIndexOf('/') - 1); + if (fileName.length() > maxLength) + fileName = fileName.left(maxLength) + "..."; + } + + QString title; + if (!trackTitle.isEmpty()) { + if (trackTitle.length() > maxLength) + trackTitle = trackTitle.left(maxLength) + "..."; + title = "Title: " + font + trackTitle + "
"; + } else if (!fileName.isEmpty()) { + if (fileName.length() > maxLength) + fileName = fileName.left(maxLength) + "..."; + title = font + fileName + "
"; + if (m_MediaObject.currentSource().type() == Phonon::MediaSource::Url) { + title.prepend("Url: "); + } else { + title.prepend("File: "); + } + } + + QString artist; + if (!trackArtist.isEmpty()) + artist = "Artist: " + font + trackArtist + ""; + + QString bitrate; + if (trackBitrate != 0) + bitrate = "
Bitrate: " + font + QString::number(trackBitrate/1000) + "kbit"; + + info->setText(title + artist + bitrate); +} + +void MediaPlayer::updateTime() +{ + long len = m_MediaObject.totalTime(); + long pos = m_MediaObject.currentTime(); + QString timeString; + if (pos || len) + { + int sec = pos/1000; + int min = sec/60; + int hour = min/60; + int msec = pos; + + QTime playTime(hour%60, min%60, sec%60, msec%1000); + sec = len / 1000; + min = sec / 60; + hour = min / 60; + msec = len; + + QTime stopTime(hour%60, min%60, sec%60, msec%1000); + QString timeFormat = "m:ss"; + if (hour > 0) + timeFormat = "h:mm:ss"; + timeString = playTime.toString(timeFormat); + if (len) + timeString += " / " + stopTime.toString(timeFormat); + } + timeLabel->setText(timeString); +} + +void MediaPlayer::rewind() +{ + m_MediaObject.seek(0); +} + +void MediaPlayer::forward() +{ + QList queue = m_MediaObject.queue(); + if (queue.size() > 0) { + m_MediaObject.setCurrentSource(queue[0]); + forwardButton->setEnabled(queue.size() > 1); + m_MediaObject.play(); + } +} + +void MediaPlayer::openUrl() +{ + QSettings settings; + settings.beginGroup(QLatin1String("BrowserMainWindow")); + QString sourceURL = settings.value("location").toString(); + bool ok = false; + sourceURL = QInputDialog::getText(this, tr("Open Location"), tr("Please enter a valid address here:"), QLineEdit::Normal, sourceURL, &ok); + if (ok && !sourceURL.isEmpty()) { + setWindowTitle(sourceURL.right(sourceURL.length() - sourceURL.lastIndexOf('/') - 1)); + m_MediaObject.setCurrentSource(Phonon::MediaSource(QUrl::fromEncoded(sourceURL.toUtf8()))); + m_MediaObject.play(); + settings.setValue("location", sourceURL); + } +} + +void MediaPlayer::finished() +{ +} + +void MediaPlayer::showContextMenu(const QPoint &p) +{ + fileMenu->popup(m_videoWidget->isFullScreen() ? p : mapToGlobal(p)); +} + +void MediaPlayer::scaleChanged(QAction *act) +{ + if (act->text() == tr("Scale and crop")) + m_videoWidget->setScaleMode(Phonon::VideoWidget::ScaleAndCrop); + else + m_videoWidget->setScaleMode(Phonon::VideoWidget::FitInView); +} + +void MediaPlayer::aspectChanged(QAction *act) +{ + if (act->text() == tr("16/9")) + m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatio16_9); + else if (act->text() == tr("Scale")) + m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatioWidget); + else if (act->text() == tr("4/3")) + m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatio4_3); + else + m_videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatioAuto); +} + diff --git a/demos/qmediaplayer/mediaplayer.h b/demos/qmediaplayer/mediaplayer.h new file mode 100644 index 0000000..40ffa40 --- /dev/null +++ b/demos/qmediaplayer/mediaplayer.h @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#ifndef MEDIALAYER_H +#define MEDIAPLAYER_H + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QPushButton; +class QLabel; +class QSlider; +class QTextEdit; +class QMenu; +class Ui_settings; +QT_END_NAMESPACE + +class MediaPlayer : + public QWidget +{ + Q_OBJECT +public: + MediaPlayer(const QString &, + const bool hasSmallScreen); + + void dragEnterEvent(QDragEnterEvent *e); + void dragMoveEvent(QDragMoveEvent *e); + void dropEvent(QDropEvent *e); + void handleDrop(QDropEvent *e); + void setFile(const QString &text); + void initVideoWindow(); + void initSettingsDialog(); + +public slots: + void openFile(); + void rewind(); + void forward(); + void updateInfo(); + void updateTime(); + void finished(); + void playPause(); + void scaleChanged(QAction *); + void aspectChanged(QAction *); + +private slots: + void setAspect(int); + void setScale(int); + void setSaturation(int); + void setContrast(int); + void setHue(int); + void setBrightness(int); + void stateChanged(Phonon::State newstate, Phonon::State oldstate); + void effectChanged(); + void showSettingsDialog(); + void showContextMenu(const QPoint &); + void bufferStatus(int percent); + void openUrl(); + void configureEffect(); + +private: + QIcon playIcon; + QIcon pauseIcon; + QMenu *fileMenu; + QPushButton *playButton; + QPushButton *rewindButton; + QPushButton *forwardButton; + Phonon::SeekSlider *slider; + QLabel *timeLabel; + QLabel *progressLabel; + Phonon::VolumeSlider *volume; + QSlider *m_hueSlider; + QSlider *m_satSlider; + QSlider *m_contSlider; + QLabel *info; + Phonon::Effect *nextEffect; + QDialog *settingsDialog; + Ui_settings *ui; + + QWidget m_videoWindow; + Phonon::MediaObject m_MediaObject; + Phonon::AudioOutput m_AudioOutput; + Phonon::VideoWidget *m_videoWidget; + Phonon::Path m_audioOutputPath; + const bool m_hasSmallScreen; +}; + +#endif //MEDIAPLAYER_H diff --git a/demos/qmediaplayer/mediaplayer.qrc b/demos/qmediaplayer/mediaplayer.qrc new file mode 100644 index 0000000..bcdf404 --- /dev/null +++ b/demos/qmediaplayer/mediaplayer.qrc @@ -0,0 +1,5 @@ + + + images/screen.png + + diff --git a/demos/qmediaplayer/qmediaplayer.pro b/demos/qmediaplayer/qmediaplayer.pro new file mode 100644 index 0000000..2f15c28 --- /dev/null +++ b/demos/qmediaplayer/qmediaplayer.pro @@ -0,0 +1,35 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Thu Aug 23 18:02:14 2007 +###################################################################### + +TEMPLATE = app +DEPENDPATH += . build src ui + +QT += phonon + +FORMS += settings.ui +RESOURCES += mediaplayer.qrc + +!win32:CONFIG += CONSOLE + +SOURCES += main.cpp mediaplayer.cpp +HEADERS += mediaplayer.h + +target.path = $$[QT_INSTALL_DEMOS]/qmediaplayer +sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.html *.doc images +sources.path = $$[QT_INSTALL_DEMOS]/qmediaplayer +INSTALLS += target sources + +wince*{ +DEPLOYMENT_PLUGIN += phonon_ds9 phonon_waveout +} + +symbian { + TARGET.UID3 = 0xA000C613 + + addFiles.sources = ../embedded/desktopservices/data/sax.mp3 + addFiles.path = /data/sounds/ + DEPLOYMENT += addFiles + + include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri) +} diff --git a/demos/qmediaplayer/settings.ui b/demos/qmediaplayer/settings.ui new file mode 100644 index 0000000..d2cedd4 --- /dev/null +++ b/demos/qmediaplayer/settings.ui @@ -0,0 +1,464 @@ + + settings + + + + 0 + 0 + 360 + 362 + + + + Settings + + + + + + Video options: + + + true + + + + + + Contrast: + + + + + + + -8 + + + 8 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 4 + + + + + + + Brightness: + + + + + + + -8 + + + 8 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 4 + + + + + + + Saturation: + + + + + + + -8 + + + 8 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 4 + + + + + + + Hue: + + + + + + + -8 + + + 8 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 4 + + + + + + + Aspect ratio: + + + + + + + + 180 + 0 + + + + + Auto + + + + + Stretch + + + + + 4/3 + + + + + 16/9 + + + + + + + + Scale Mode: + + + + + + + + 180 + 0 + + + + + Fit in view + + + + + Scale and crop + + + + + + + + + + + Audio options: + + + true + + + + + + + + + 0 + 0 + + + + + 90 + 0 + + + + Audio device: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + 0 + 0 + + + + + + + + + + + + + 0 + 0 + + + + + 90 + 0 + + + + Audio effect: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + 0 + 0 + + + + + + + + false + + + Setup + + + + + + + + + + + + 0 + 0 + + + + + 90 + 0 + + + + Cross fade: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + + 0 + 0 + + + + -20 + + + 20 + + + 1 + + + 2 + + + 0 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + + + + + + + + 9 + + + + -10 Sec + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 9 + + + + 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 9 + + + + 10 Sec + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + settings + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + settings + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/demos/qtdemo/xml/examples.xml b/demos/qtdemo/xml/examples.xml index 3f0cd25..2c31484 100644 --- a/demos/qtdemo/xml/examples.xml +++ b/demos/qtdemo/xml/examples.xml @@ -121,7 +121,7 @@ - + @@ -152,7 +152,7 @@ - + diff --git a/doc/src/demos/mediaplayer.qdoc b/doc/src/demos/mediaplayer.qdoc index 9e6b3f9..17ae79b 100644 --- a/doc/src/demos/mediaplayer.qdoc +++ b/doc/src/demos/mediaplayer.qdoc @@ -40,7 +40,7 @@ ****************************************************************************/ /*! - \example demos/mediaplayer + \example demos/qmediaplayer \title Media Player The Media Player demonstration shows how \l{Phonon Module}{Phonon} diff --git a/doc/src/examples/ftp.qdoc b/doc/src/examples/ftp.qdoc index ec8584c..8fded88 100644 --- a/doc/src/examples/ftp.qdoc +++ b/doc/src/examples/ftp.qdoc @@ -78,13 +78,13 @@ \l{QFtp::Command}{commands} we request are finished, the progress of current commands, and information about files on the server. - \snippet examples/network/ftp/ftpwindow.h 0 + \snippet examples/network/qftp/ftpwindow.h 0 We will look at each slot when we examine the \c FtpWindow implementation in the next section. We also make use of a few private variables: - \snippet examples/network/ftp/ftpwindow.h 1 + \snippet examples/network/qftp/ftpwindow.h 1 The \c isDirectory hash keeps a history of all entries explored on the FTP server, and registers whether an entry represents a @@ -98,7 +98,7 @@ We move on to the slots, starting with \c connectOrDisconnect(). - \snippet examples/network/ftp/ftpwindow.cpp 0 + \snippet examples/network/qftp/ftpwindow.cpp 0 If \c ftp is already pointing to a QFtp object, we QFtp::Close its FTP connection and delete the object it points to. Note that we do @@ -106,7 +106,7 @@ to finish its abort operation. \dots - \snippet examples/network/ftp/ftpwindow.cpp 1 + \snippet examples/network/qftp/ftpwindow.cpp 1 If we get here, \c connectOrDisconnect() was called to establish a new FTP connection. We create a new QFtp for our new connection, @@ -118,7 +118,7 @@ is emitted repeatedly during an FTP file transfer, giving us progress reports. - \snippet examples/network/ftp/ftpwindow.cpp 2 + \snippet examples/network/qftp/ftpwindow.cpp 2 The \gui {Ftp Server} line edit contains the IP address or hostname of the server to which we want to connect. We first check @@ -134,39 +134,39 @@ We move on to the \c downloadFile() slot: - \snippet examples/network/ftp/ftpwindow.cpp 3 + \snippet examples/network/qftp/ftpwindow.cpp 3 \dots - \snippet examples/network/ftp/ftpwindow.cpp 4 + \snippet examples/network/qftp/ftpwindow.cpp 4 We first fetch the name of the file, which we find in the selected item of \c fileList. We then start the download by using QFtp::get(). QFtp will send progress signals during the download and a signal when the download is completed. - \snippet examples/network/ftp/ftpwindow.cpp 5 + \snippet examples/network/qftp/ftpwindow.cpp 5 QFtp supports canceling the download of files. - \snippet examples/network/ftp/ftpwindow.cpp 6 + \snippet examples/network/qftp/ftpwindow.cpp 6 The \c ftpCommandFinished() slot is called when QFtp has finished a QFtp::Command. If an error occurred during the command, QFtp will set \c error to one of the values in the QFtp::Error enum; otherwise, \c error is zero. - \snippet examples/network/ftp/ftpwindow.cpp 7 + \snippet examples/network/qftp/ftpwindow.cpp 7 After login, the QFtp::list() function will list the top-level directory on the server. addToList() is connected to QFtp::listInfo(), and will be invoked for each entry in that directory. - \snippet examples/network/ftp/ftpwindow.cpp 8 + \snippet examples/network/qftp/ftpwindow.cpp 8 When a \l{QFtp::}{Get} command is finished, a file has finished downloading (or an error occurred during the download). - \snippet examples/network/ftp/ftpwindow.cpp 9 + \snippet examples/network/qftp/ftpwindow.cpp 9 After a \l{QFtp::}{List} command is performed, we have to check if no entries were found (in which case our \c addToList() function @@ -174,7 +174,7 @@ Let's continue with the \c addToList() slot: - \snippet examples/network/ftp/ftpwindow.cpp 10 + \snippet examples/network/qftp/ftpwindow.cpp 10 When a new file has been resolved during a QFtp::List command, this slot is invoked with a QUrlInfo describing the file. We @@ -182,26 +182,26 @@ does not have a current item, we set the new item to be the current item. - \snippet examples/network/ftp/ftpwindow.cpp 11 + \snippet examples/network/qftp/ftpwindow.cpp 11 The \c processItem() slot is called when an item is double clicked in the \gui {File List}. If the item represents a directory, we want to load the contents of that directory with QFtp::list(). - \snippet examples/network/ftp/ftpwindow.cpp 12 + \snippet examples/network/qftp/ftpwindow.cpp 12 \c cdToParent() is invoked when the user requests to go to the parent directory of the one displayed in the file list. After changing the directory, we QFtp::List its contents. - \snippet examples/network/ftp/ftpwindow.cpp 13 + \snippet examples/network/qftp/ftpwindow.cpp 13 The \c updateDataTransferProgress() slot is called regularly by QFtp::dataTransferProgress() when a file download is in progress. We use a QProgressDialog to show the download progression to the user. - \snippet examples/network/ftp/ftpwindow.cpp 14 + \snippet examples/network/qftp/ftpwindow.cpp 14 The \c enableDownloadButton() is called whenever the current item in \c fileList changes. If the item represents a file, the \gui diff --git a/doc/src/examples/musicplayerexample.qdoc b/doc/src/examples/musicplayerexample.qdoc index 41c9f3a..7145583 100644 --- a/doc/src/examples/musicplayerexample.qdoc +++ b/doc/src/examples/musicplayerexample.qdoc @@ -40,7 +40,7 @@ ****************************************************************************/ /*! - \example phonon/musicplayer + \example phonon/qmusicplayer \title Music Player Example The Music Player Example shows how to use Phonon - the multimedia @@ -90,7 +90,7 @@ look at them when we walk through the \c MainWindow implementation. - \snippet examples/phonon/musicplayer/mainwindow.h 2 + \snippet examples/phonon/qmusicplayer/mainwindow.h 2 We use the \l{Phonon::}{SeekSlider} to move the current playback position in the media stream, and the \l{Phonon::}{VolumeSlider} @@ -99,7 +99,7 @@ metaInformationProvider, to get the meta information from the music files. More on this later. - \snippet examples/phonon/musicplayer/mainwindow.h 1 + \snippet examples/phonon/qmusicplayer/mainwindow.h 1 The \l{Phonon::}{MediaObject} informs us of the state of the playback and properties of the media it is playing back through a series of @@ -116,7 +116,7 @@ We start with the constructor: - \snippet examples/phonon/musicplayer/mainwindow.cpp 0 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 0 We start by instantiating our media and audio output objects. As mentioned, the media object knows how to playback @@ -130,20 +130,20 @@ paths. Objects are connected using the \c createPath() function, which is part of the Phonon namespace. - \snippet examples/phonon/musicplayer/mainwindow.cpp 1 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 1 We also connect signals of the media object to slots in our \c MainWindow. We will examine them shortly. - \snippet examples/phonon/musicplayer/mainwindow.cpp 2 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 2 Finally, we call private helper functions to set up the GUI. The \c setupUi() function contains code for setting up the seek , and volume slider. We move on to \c setupUi(): - \snippet examples/phonon/musicplayer/mainwindow.cpp 3 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 3 \dots - \snippet examples/phonon/musicplayer/mainwindow.cpp 4 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 4 After creating the widgets, they must be supplied with the \l{Phonon::}{MediaObject} and \l{Phonon::}{AudioOutput} objects @@ -152,12 +152,12 @@ In the \c setupActions(), we connect the actions for the play, pause, and stop tool buttons, to slots of the media object. - \snippet examples/phonon/musicplayer/mainwindow.cpp 5 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 5 We move on to the slots of \c MainWindow, starting with \c addFiles(): - \snippet examples/phonon/musicplayer/mainwindow.cpp 6 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 6 In the \c addFiles() slot, we add files selected by the user to the \c sources list. We then set the first source selected on the @@ -169,7 +169,7 @@ stateChanged() signal. The \c stateChanged() slot is connected to this signal. - \snippet examples/phonon/musicplayer/mainwindow.cpp 9 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 9 The \l{Phonon::MediaObject::}{errorString()} function gives a description of the error that is suitable for users of a Phonon @@ -177,7 +177,7 @@ helps us determine whether it is possible to try to play the same file again. - \snippet examples/phonon/musicplayer/mainwindow.cpp 10 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 10 We update the GUI when the playback state changes, i.e., when it starts, pauses, stops, or resumes. @@ -188,26 +188,26 @@ The \c tick() slot is connected to a \l{Phonon::}{MediaObject} signal which is emitted when the playback position changes: - \snippet examples/phonon/musicplayer/mainwindow.cpp 11 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 11 The \c time is given in milliseconds. When the table is clicked on with the mouse, \c tableClick() is invoked: - \snippet examples/phonon/musicplayer/mainwindow.cpp 12 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 12 Since we stop the media object, we first check whether it is currently playing. \c row contains the row in the table that was clicked upon; the indices of \c sources follows the table, so we can simply use \c row to find the new source. - \snippet examples/phonon/musicplayer/mainwindow.cpp 13 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 13 When the media source changes, we simply need to select the corresponding row in the table. - \snippet examples/phonon/musicplayer/mainwindow.cpp 14 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 14 When \c metaStateChanged() is invoked, \c metaInformationProvider has resolved the meta data for its current @@ -220,7 +220,7 @@ music table. A file might not contain the meta data requested, in which case an empty string is returned. - \snippet examples/phonon/musicplayer/mainwindow.cpp 15 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 15 If we have media sources in \c sources of which meta information is not resolved, we set a new source on the \c @@ -229,7 +229,7 @@ We move on to the \c aboutToFinish() slot: - \snippet examples/phonon/musicplayer/mainwindow.cpp 16 + \snippet examples/phonon/qmusicplayer/mainwindow.cpp 16 When a file is finished playing, the Music Player will move on and play the next file in the table. This slot is connected to the @@ -244,5 +244,5 @@ \l{QCoreApplication::}{setApplicationName()}. This is because D-Bus, which is used by Phonon on Linux systems, demands this. - \snippet examples/phonon/musicplayer/main.cpp 1 + \snippet examples/phonon/qmusicplayer/main.cpp 1 */ diff --git a/doc/src/getting-started/demos.qdoc b/doc/src/getting-started/demos.qdoc index 532715e..8f2829a 100644 --- a/doc/src/getting-started/demos.qdoc +++ b/doc/src/getting-started/demos.qdoc @@ -157,7 +157,7 @@ \section1 Phonon \list - \o \l{demos/mediaplayer}{Media Player} demonstrates how the \l{Phonon Module} can be + \o \l{demos/qmediaplayer}{Media Player} demonstrates how the \l{Phonon Module} can be used to implement a basic media player application. \endlist diff --git a/doc/src/getting-started/examples.qdoc b/doc/src/getting-started/examples.qdoc index 30dae88..2ad730a7 100644 --- a/doc/src/getting-started/examples.qdoc +++ b/doc/src/getting-started/examples.qdoc @@ -827,7 +827,7 @@ \list \o \l{phonon/capabilities}{Capabilities}\raisedaster - \o \l{phonon/musicplayer}{Music Player}\raisedaster + \o \l{phonon/qmusicplayer}{Music Player}\raisedaster \endlist */ diff --git a/examples/network/ftp/ftp.pro b/examples/network/ftp/ftp.pro deleted file mode 100644 index ce2a97b..0000000 --- a/examples/network/ftp/ftp.pro +++ /dev/null @@ -1,20 +0,0 @@ -HEADERS = ftpwindow.h -SOURCES = ftpwindow.cpp \ - main.cpp -RESOURCES += ftp.qrc -QT += network - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/network/ftp -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS ftp.pro images -sources.path = $$[QT_INSTALL_EXAMPLES]/network/ftp -INSTALLS += target sources - -symbian { - TARGET.UID3 = 0xA000A648 - include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) - HEADERS += sym_iap_util.h - INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE - TARGET.CAPABILITY="NetworkServices ReadUserData WriteUserData" - LIBS+=-lesock -lcommdb -linsock # For IAP selection -} diff --git a/examples/network/ftp/ftp.qrc b/examples/network/ftp/ftp.qrc deleted file mode 100644 index b598ab8..0000000 --- a/examples/network/ftp/ftp.qrc +++ /dev/null @@ -1,7 +0,0 @@ - - - images/cdtoparent.png - images/dir.png - images/file.png - - diff --git a/examples/network/ftp/ftpwindow.cpp b/examples/network/ftp/ftpwindow.cpp deleted file mode 100644 index f3fc52b..0000000 --- a/examples/network/ftp/ftpwindow.cpp +++ /dev/null @@ -1,379 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#include "ftpwindow.h" - -#ifdef Q_OS_SYMBIAN -#include "sym_iap_util.h" -#endif - -FtpWindow::FtpWindow(QWidget *parent) - : QDialog(parent), ftp(0) -{ - ftpServerLabel = new QLabel(tr("Ftp &server:")); - ftpServerLineEdit = new QLineEdit("ftp.qt.nokia.com"); - ftpServerLabel->setBuddy(ftpServerLineEdit); - - statusLabel = new QLabel(tr("Please enter the name of an FTP server.")); -#ifdef Q_OS_SYMBIAN - // Use word wrapping to fit the text on screen - statusLabel->setWordWrap( true ); -#endif - - fileList = new QTreeWidget; - fileList->setEnabled(false); - fileList->setRootIsDecorated(false); - fileList->setHeaderLabels(QStringList() << tr("Name") << tr("Size") << tr("Owner") << tr("Group") << tr("Time")); - fileList->header()->setStretchLastSection(false); - - connectButton = new QPushButton(tr("Connect")); - connectButton->setDefault(true); - - cdToParentButton = new QPushButton; - cdToParentButton->setIcon(QPixmap(":/images/cdtoparent.png")); - cdToParentButton->setEnabled(false); - - downloadButton = new QPushButton(tr("Download")); - downloadButton->setEnabled(false); - - quitButton = new QPushButton(tr("Quit")); - - buttonBox = new QDialogButtonBox; - buttonBox->addButton(downloadButton, QDialogButtonBox::ActionRole); - buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); - - progressDialog = new QProgressDialog(this); - - connect(fileList, SIGNAL(itemActivated(QTreeWidgetItem *, int)), - this, SLOT(processItem(QTreeWidgetItem *, int))); - connect(fileList, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), - this, SLOT(enableDownloadButton())); - connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload())); - connect(connectButton, SIGNAL(clicked()), this, SLOT(connectOrDisconnect())); - connect(cdToParentButton, SIGNAL(clicked()), this, SLOT(cdToParent())); - connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile())); - connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); - - QHBoxLayout *topLayout = new QHBoxLayout; - topLayout->addWidget(ftpServerLabel); - topLayout->addWidget(ftpServerLineEdit); -#ifndef Q_OS_SYMBIAN - topLayout->addWidget(cdToParentButton); - topLayout->addWidget(connectButton); -#else - // Make app better lookin on small screen - QHBoxLayout *topLayout2 = new QHBoxLayout; - topLayout2->addWidget(cdToParentButton); - topLayout2->addWidget(connectButton); -#endif - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addLayout(topLayout); -#ifdef Q_OS_SYMBIAN - // Make app better lookin on small screen - mainLayout->addLayout(topLayout2); -#endif - mainLayout->addWidget(fileList); - mainLayout->addWidget(statusLabel); - mainLayout->addWidget(buttonBox); - setLayout(mainLayout); - -#ifdef Q_OS_SYMBIAN - bDefaultIapSet = false; -#endif - - setWindowTitle(tr("FTP")); -} - -QSize FtpWindow::sizeHint() const -{ - return QSize(500, 300); -} - -//![0] -void FtpWindow::connectOrDisconnect() -{ -#ifdef Q_OS_SYMBIAN - if(!bDefaultIapSet) { - qt_SetDefaultIap(); - bDefaultIapSet = true; - } -#endif - if (ftp) { - ftp->abort(); - ftp->deleteLater(); - ftp = 0; -//![0] - fileList->setEnabled(false); - cdToParentButton->setEnabled(false); - downloadButton->setEnabled(false); - connectButton->setEnabled(true); - connectButton->setText(tr("Connect")); -#ifndef QT_NO_CURSOR - setCursor(Qt::ArrowCursor); -#endif - statusLabel->setText(tr("Please enter the name of an FTP server.")); - return; - } - -#ifndef QT_NO_CURSOR - setCursor(Qt::WaitCursor); -#endif - -//![1] - ftp = new QFtp(this); - connect(ftp, SIGNAL(commandFinished(int, bool)), - this, SLOT(ftpCommandFinished(int, bool))); - connect(ftp, SIGNAL(listInfo(const QUrlInfo &)), - this, SLOT(addToList(const QUrlInfo &))); - connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)), - this, SLOT(updateDataTransferProgress(qint64, qint64))); - - fileList->clear(); - currentPath.clear(); - isDirectory.clear(); -//![1] - -//![2] - QUrl url(ftpServerLineEdit->text()); - if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) { - ftp->connectToHost(ftpServerLineEdit->text(), 21); - ftp->login(); - } else { - ftp->connectToHost(url.host(), url.port(21)); - - if (!url.userName().isEmpty()) - ftp->login(QUrl::fromPercentEncoding(url.userName().toLatin1()), url.password()); - else - ftp->login(); - if (!url.path().isEmpty()) - ftp->cd(url.path()); - } -//![2] - - fileList->setEnabled(true); - connectButton->setEnabled(false); - connectButton->setText(tr("Disconnect")); - statusLabel->setText(tr("Connecting to FTP server %1...") - .arg(ftpServerLineEdit->text())); -} - -//![3] -void FtpWindow::downloadFile() -{ - QString fileName = fileList->currentItem()->text(0); -//![3] -// - if (QFile::exists(fileName)) { - QMessageBox::information(this, tr("FTP"), - tr("There already exists a file called %1 in " - "the current directory.") - .arg(fileName)); - return; - } - -//![4] - file = new QFile(fileName); - if (!file->open(QIODevice::WriteOnly)) { - QMessageBox::information(this, tr("FTP"), - tr("Unable to save the file %1: %2.") - .arg(fileName).arg(file->errorString())); - delete file; - return; - } - - ftp->get(fileList->currentItem()->text(0), file); - - progressDialog->setLabelText(tr("Downloading %1...").arg(fileName)); - downloadButton->setEnabled(false); - progressDialog->exec(); -} -//![4] - -//![5] -void FtpWindow::cancelDownload() -{ - ftp->abort(); -} -//![5] - -//![6] -void FtpWindow::ftpCommandFinished(int, bool error) -{ -#ifndef QT_NO_CURSOR - setCursor(Qt::ArrowCursor); -#endif - - if (ftp->currentCommand() == QFtp::ConnectToHost) { - if (error) { - QMessageBox::information(this, tr("FTP"), - tr("Unable to connect to the FTP server " - "at %1. Please check that the host " - "name is correct.") - .arg(ftpServerLineEdit->text())); - connectOrDisconnect(); - return; - } - statusLabel->setText(tr("Logged onto %1.") - .arg(ftpServerLineEdit->text())); - fileList->setFocus(); - downloadButton->setDefault(true); - connectButton->setEnabled(true); - return; - } -//![6] - -//![7] - if (ftp->currentCommand() == QFtp::Login) - ftp->list(); -//![7] - -//![8] - if (ftp->currentCommand() == QFtp::Get) { - if (error) { - statusLabel->setText(tr("Canceled download of %1.") - .arg(file->fileName())); - file->close(); - file->remove(); - } else { - statusLabel->setText(tr("Downloaded %1 to current directory.") - .arg(file->fileName())); - file->close(); - } - delete file; - enableDownloadButton(); - progressDialog->hide(); -//![8] -//![9] - } else if (ftp->currentCommand() == QFtp::List) { - if (isDirectory.isEmpty()) { - fileList->addTopLevelItem(new QTreeWidgetItem(QStringList() << tr(""))); - fileList->setEnabled(false); - } - } -//![9] -} - -//![10] -void FtpWindow::addToList(const QUrlInfo &urlInfo) -{ - QTreeWidgetItem *item = new QTreeWidgetItem; - item->setText(0, urlInfo.name()); - item->setText(1, QString::number(urlInfo.size())); - item->setText(2, urlInfo.owner()); - item->setText(3, urlInfo.group()); - item->setText(4, urlInfo.lastModified().toString("MMM dd yyyy")); - - QPixmap pixmap(urlInfo.isDir() ? ":/images/dir.png" : ":/images/file.png"); - item->setIcon(0, pixmap); - - isDirectory[urlInfo.name()] = urlInfo.isDir(); - fileList->addTopLevelItem(item); - if (!fileList->currentItem()) { - fileList->setCurrentItem(fileList->topLevelItem(0)); - fileList->setEnabled(true); - } -} -//![10] - -//![11] -void FtpWindow::processItem(QTreeWidgetItem *item, int /*column*/) -{ - QString name = item->text(0); - if (isDirectory.value(name)) { - fileList->clear(); - isDirectory.clear(); - currentPath += "/" + name; - ftp->cd(name); - ftp->list(); - cdToParentButton->setEnabled(true); -#ifndef QT_NO_CURSOR - setCursor(Qt::WaitCursor); -#endif - return; - } -} -//![11] - -//![12] -void FtpWindow::cdToParent() -{ -#ifndef QT_NO_CURSOR - setCursor(Qt::WaitCursor); -#endif - fileList->clear(); - isDirectory.clear(); - currentPath = currentPath.left(currentPath.lastIndexOf('/')); - if (currentPath.isEmpty()) { - cdToParentButton->setEnabled(false); - ftp->cd("/"); - } else { - ftp->cd(currentPath); - } - ftp->list(); -} -//![12] - -//![13] -void FtpWindow::updateDataTransferProgress(qint64 readBytes, - qint64 totalBytes) -{ - progressDialog->setMaximum(totalBytes); - progressDialog->setValue(readBytes); -} -//![13] - -//![14] -void FtpWindow::enableDownloadButton() -{ - QTreeWidgetItem *current = fileList->currentItem(); - if (current) { - QString currentFile = current->text(0); - downloadButton->setEnabled(!isDirectory.value(currentFile)); - } else { - downloadButton->setEnabled(false); - } -} -//![14] - diff --git a/examples/network/ftp/ftpwindow.h b/examples/network/ftp/ftpwindow.h deleted file mode 100644 index f92c36a..0000000 --- a/examples/network/ftp/ftpwindow.h +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef FTPWINDOW_H -#define FTPWINDOW_H - -#include -#include - -QT_BEGIN_NAMESPACE -class QDialogButtonBox; -class QFile; -class QFtp; -class QLabel; -class QLineEdit; -class QTreeWidget; -class QTreeWidgetItem; -class QProgressDialog; -class QPushButton; -class QUrlInfo; -QT_END_NAMESPACE - -class FtpWindow : public QDialog -{ - Q_OBJECT - -public: - FtpWindow(QWidget *parent = 0); - QSize sizeHint() const; - -//![0] -private slots: - void connectOrDisconnect(); - void downloadFile(); - void cancelDownload(); - - void ftpCommandFinished(int commandId, bool error); - void addToList(const QUrlInfo &urlInfo); - void processItem(QTreeWidgetItem *item, int column); - void cdToParent(); - void updateDataTransferProgress(qint64 readBytes, - qint64 totalBytes); - void enableDownloadButton(); -//![0] - -private: - QLabel *ftpServerLabel; - QLineEdit *ftpServerLineEdit; - QLabel *statusLabel; - QTreeWidget *fileList; - QPushButton *cdToParentButton; - QPushButton *connectButton; - QPushButton *downloadButton; - QPushButton *quitButton; - QDialogButtonBox *buttonBox; - QProgressDialog *progressDialog; - -//![1] - QHash isDirectory; - QString currentPath; - QFtp *ftp; - QFile *file; - -#ifdef Q_OS_SYMBIAN - bool bDefaultIapSet; -#endif -//![1] -}; - -#endif diff --git a/examples/network/ftp/images/cdtoparent.png b/examples/network/ftp/images/cdtoparent.png deleted file mode 100644 index 24b6180..0000000 Binary files a/examples/network/ftp/images/cdtoparent.png and /dev/null differ diff --git a/examples/network/ftp/images/dir.png b/examples/network/ftp/images/dir.png deleted file mode 100644 index 0ce5ae7..0000000 Binary files a/examples/network/ftp/images/dir.png and /dev/null differ diff --git a/examples/network/ftp/images/file.png b/examples/network/ftp/images/file.png deleted file mode 100644 index be6c530..0000000 Binary files a/examples/network/ftp/images/file.png and /dev/null differ diff --git a/examples/network/ftp/main.cpp b/examples/network/ftp/main.cpp deleted file mode 100644 index d44ccd7..0000000 --- a/examples/network/ftp/main.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include "ftpwindow.h" - -#ifdef Q_OS_SYMBIAN -#include -#include -#endif - -int main(int argc, char *argv[]) -{ - Q_INIT_RESOURCE(ftp); -#ifdef Q_OS_SYMBIAN - // Change current directory from default private to c:\data - // in order that user can access the downloaded content - QDir::setCurrent( "c:\\data" ); -#endif - QApplication app(argc, argv); - FtpWindow ftpWin; -#ifdef Q_OS_SYMBIAN - // Make application better looking and more usable on small screen - ftpWin.showMaximized(); -#else - ftpWin.show(); -#endif - return ftpWin.exec(); -} diff --git a/examples/network/ftp/sym_iap_util.h b/examples/network/ftp/sym_iap_util.h deleted file mode 100644 index ebeae0a..0000000 --- a/examples/network/ftp/sym_iap_util.h +++ /dev/null @@ -1,510 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QSYM_IAP_UTIL_H -#define QSYM_IAP_UTIL_H - -// Symbian -#include -#include -#include -#include -#include -#include -#include - -// OpenC -#include -#include - -//Qt -#include -#include -//#include - -_LIT(KIapNameSetting, "IAP\\Name"); // text - mandatory -_LIT(KIapDialogPref, "IAP\\DialogPref"); // TUnit32 - optional -_LIT(KIapService, "IAP\\IAPService"); // TUnit32 - mandatory -_LIT(KIapServiceType, "IAP\\IAPServiceType"); // text - mandatory -_LIT(KIapBearer, "IAP\\IAPBearer"); // TUint32 - optional -_LIT(KIapBearerType, "IAP\\IAPBearerType"); // text - optional -_LIT(KIapNetwork, "IAP\\IAPNetwork"); // TUint32 - optional - -const QLatin1String qtOrganizationTag("Trolltech"); -const QLatin1String qtNetworkModuleTag("QtNetwork"); -const QLatin1String iapGroupTag("IAP"); -const QLatin1String iapNamesArrayTag("Names"); -const QLatin1String iapNameItemTag("Name"); - -static QTextCodec *utf16LETextCodec = 0; - -void clearIapNamesSettings(QSettings &settings) { - settings.beginGroup(qtNetworkModuleTag); - settings.beginGroup(iapGroupTag); - settings.remove(iapNamesArrayTag); - settings.endGroup(); - settings.endGroup(); -} - -void writeIapNamesSettings(QSettings &settings, const QStringList& iapNames) { - clearIapNamesSettings(settings); - settings.beginGroup(qtNetworkModuleTag); - settings.beginGroup(iapGroupTag); - settings.beginWriteArray(iapNamesArrayTag); - for (int index = 0; index < iapNames.size(); ++index) { - settings.setArrayIndex(index); - settings.setValue(iapNameItemTag, iapNames.at(index)); - } - settings.endArray(); - settings.endGroup(); - settings.endGroup(); -} - -void readIapNamesSettings(QSettings &settings, QStringList& iapNames) { - settings.beginGroup(qtNetworkModuleTag); - settings.beginGroup(iapGroupTag); - int last = settings.beginReadArray(iapNamesArrayTag); - for (int index = 0; index < last; ++index) { - settings.setArrayIndex(index); - iapNames.append(settings.value(iapNameItemTag).toString()); - } - settings.endArray(); - settings.endGroup(); - settings.endGroup(); -} - -static QString qt_TNameToQString(TName data) { - if(utf16LETextCodec == 0) - utf16LETextCodec = QTextCodec::codecForName("UTF-16LE"); - - QByteArray tmpByteArray = QByteArray::fromRawData((char*)(data.PtrZ()), data.Length() * 2); - return utf16LETextCodec->toUnicode(tmpByteArray); -} - -static QString qt_InterfaceInfoL() -{ - QString output; - - TBuf8<512> buffer; - TBuf<128> t; - TAutoClose ss; - User::LeaveIfError(ss.iObj.Connect()); - ss.PushL(); - - TAutoClose sock; - User::LeaveIfError(sock.iObj.Open(ss.iObj, _L("udp"))); - sock.PushL(); - - User::LeaveIfError(sock.iObj.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl)); - - TProtocolDesc in; - User::LeaveIfError(sock.iObj.Info(in)); - printf("EPOC32 IP Configuration TCPIP Version %d.%d.%d\n", in.iVersion.iMajor, in.iVersion.iMinor, in.iVersion.iBuild); - - TPckgBuf info, next; - - TInt res=sock.iObj.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, info); - if(res!=KErrNone) - User::Leave(res); - TInt count = 0; - while(res==KErrNone) { - res=sock.iObj.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, next); - - if(info().iName != _L("") && info().iName != _L("loop6") && info().iName != _L("loop4")) { - printf("Interface %d\n", count++); - - printf("Name \"%s\"\n", qt_TNameToQString(info().iName).toLatin1().data()); - printf("NIF tag \"%s\"\n", qt_TNameToQString(info().iTag).toLatin1().data()); - - printf("State "); - switch (info().iState) - { - case EIfPending: - printf("pending\n"); - break; - case EIfUp: - printf("up\n"); - break; - case EIfBusy: - printf("busy\n"); - break; - default: - printf("down\n"); - break; - } - - printf("Mtu %d\n", info().iMtu); - printf("Speed Metric %d\n", info().iSpeedMetric); - - printf("Features:"); - info().iFeatures & KIfIsLoopback ? printf(" loopback") : printf(""); - info().iFeatures & KIfIsDialup ? printf(" dialup") : printf(""); - info().iFeatures & KIfIsPointToPoint ? printf(" pointtopoint") : printf(""); - info().iFeatures & KIfCanBroadcast ? printf(" canbroadcast") : printf(""); - info().iFeatures & KIfCanMulticast ? printf(" canmulticast") : printf(""); - info().iFeatures & KIfCanSetMTU ? printf(" cansetmtu") : printf(""); - info().iFeatures & KIfHasHardwareAddr ? printf(" hardwareaddr") : printf(""); - info().iFeatures & KIfCanSetHardwareAddr ? printf(" cansethardwareaddr") : printf(""); - printf("\n"); - - TName address; - info().iAddress.Output(address); - printf("Addr: %s\n", qt_TNameToQString(address).toLatin1().data()); - - if(info().iAddress.IsLinkLocal()) { - printf(" -link local\n"); - } else if(info().iAddress.IsSiteLocal()) { - printf(" -site local\n"); - } else { - printf(" -global\n"); - } - - info().iNetMask.Output(address); - printf("Netmask %s\n", qt_TNameToQString(address).toLatin1().data()); - - info().iBrdAddr.Output(address); - printf("Broadcast address %s\n", qt_TNameToQString(address).toLatin1().data()); - - info().iDefGate.Output(address); - printf("Gatew: %s\n", qt_TNameToQString(address).toLatin1().data()); - - info().iNameSer1.Output(address); - printf("DNS 1: %s\n", qt_TNameToQString(address).toLatin1().data()); - - info().iNameSer2.Output(address); - printf("DNS 2: %s\n", qt_TNameToQString(address).toLatin1().data()); - - if (info().iHwAddr.Family() != KAFUnspec) { - printf("Hardware address "); - TUint j; - for(j = sizeof(SSockAddr) ; j < sizeof(SSockAddr) + 6 ; ++j) { - if(j < (TUint)info().iHwAddr.Length()) { - printf("%02X", info().iHwAddr[j]); - } else { - printf("??"); - } - if(j < sizeof(SSockAddr) + 5) - printf("-"); - else - printf("\n"); - } - } - } - if(res == KErrNone) { - info = next; - printf("\n"); - } else { - printf("\n"); - } - } - - sock.Pop(); - ss.Pop(); - - return output; -} - -static QString qt_RouteInfoL() { - QString output; - TAutoClose ss; - User::LeaveIfError(ss.iObj.Connect()); - ss.PushL(); - - TAutoClose sock; - User::LeaveIfError(sock.iObj.Open(ss.iObj, _L("udp"))); - sock.PushL(); - - TSoInetRouteInfo routeInfo; - TPckg routeInfoPkg(routeInfo); - - TName destAddr; - TName netMask; - TName gateway; - TName ifAddr; - - // Begins enumeration of routes by setting this option - User::LeaveIfError(sock.iObj.SetOpt(KSoInetEnumRoutes, KSolInetRtCtrl)); - - // The TSoInetRouteInfo contains information for a new route each time GetOpt returns KErrNone - for(TInt i = 0; sock.iObj.GetOpt(KSoInetNextRoute, KSolInetRtCtrl, routeInfoPkg) == KErrNone ; i++) - { - // Extract the destination and netmask - routeInfo.iDstAddr.Output(destAddr); - routeInfo.iNetMask.Output(netMask); - routeInfo.iGateway.Output(gateway); - routeInfo.iIfAddr.Output(ifAddr); -/* - if(destAddr.Length() <= 2) - continue; - - if(netMask.Find(_L("255.255.255.255")) != KErrNotFound - || netMask.Find(_L("0.0.0.0")) != KErrNotFound - || netMask.Find(_L("ffff:ffff:ffff:ffff")) != KErrNotFound) - continue; -*/ - printf("Route Info #[%i]\n", i); - printf("DstAddr %s\n", qt_TNameToQString(destAddr).toLatin1().data()); - printf("NetMask %s\n", qt_TNameToQString(netMask).toLatin1().data()); - printf("Gateway %s\n", qt_TNameToQString(gateway).toLatin1().data()); - printf("IfAddr %s\n", qt_TNameToQString(ifAddr).toLatin1().data()); - printf("\n"); - } - - sock.Pop(); - ss.Pop(); - - return output; -} - -QString qt_TDesC2QStringL(const TDesC& aDescriptor) -{ -#ifdef QT_NO_UNICODE - return QString::fromLocal8Bit(aDescriptor.Ptr(), aDescriptor.Length()); -#else - return QString::fromUtf16(aDescriptor.Ptr(), aDescriptor.Length()); -#endif -} - -static bool qt_SetDefaultIapName(const QString &iapName, int &error) { - struct ifreq ifReq; - // clear structure - memset(&ifReq, 0, sizeof(struct ifreq)); - // set IAP name value - // make sure it is in UTF8 - strcpy(ifReq.ifr_name, iapName.toUtf8().data()); - - if(setdefaultif(&ifReq) == 0) { - // OK - error = 0; - return true; - } else { - error = errno; - return false; - } - -} -static bool qt_SetDefaultSnapId(const int snapId, int &error) { - struct ifreq ifReq; - // clear structure - memset(&ifReq, 0, sizeof(struct ifreq)); - // set SNAP ID value - ifReq.ifr_ifru.snap_id = snapId; - - if(setdefaultif(&ifReq) == 0) { - // OK - error = 0; - return true; - } else { - error = errno; - return false; - } - -} - -static void qt_SaveIapName(QSettings& settings, QStringList& iapNames, QString& iapNameValue) { - if(iapNames.contains(iapNameValue) && iapNames.first() == iapNameValue) { - // no need to update - } else { - if(iapNameValue != QString("Easy WLAN")) { - // new selection alway on top - iapNames.removeAll(iapNameValue); - iapNames.prepend(iapNameValue); - writeIapNamesSettings(settings, iapNames); - } else { - // Unbeliveable ... if IAP dodn't exist before - // no matter what you choose from IAP selection list - // you will get "Easy WLAN" as IAP name value - - // somehow commsdb is not in sync - } - } -} - -static QString qt_OfferIapDialog() { - TBuf8<256> iapName; - - RSocketServ socketServ; - CleanupClosePushL(socketServ); - - RConnection connection; - CleanupClosePushL(connection); - - socketServ.Connect(); - connection.Open(socketServ); - connection.Start(); - - connection.GetDesSetting(TPtrC(KIapNameSetting), iapName); - - //connection.Stop(); - - iapName.ZeroTerminate(); - QString strIapName((char*)iapName.Ptr()); - - int error = 0; - if(!qt_SetDefaultIapName(strIapName, error)) { - //printf("failed setdefaultif @ %i with %s and errno = %d \n", __LINE__, strIapName.toUtf8().data(), error); - strIapName = QString(""); - } - - CleanupStack::PopAndDestroy(&connection); - CleanupStack::PopAndDestroy(&socketServ); - - return strIapName; -} - -static QString qt_CheckForActiveConnection() { - TUint count; - - RSocketServ serv; - CleanupClosePushL(serv); - - RConnection conn; - CleanupClosePushL(conn); - - serv.Connect(); - conn.Open(serv); - - TConnectionInfoBuf connInfo; - - TBuf8<256> iapName; - TBuf8<256> iapServiceType; - - QString strIapName; - - if (conn.EnumerateConnections(count) == KErrNone) { - if(count > 0) { - for (TUint i = 1; i <= count; i++) { - if (conn.GetConnectionInfo(i, connInfo) == KErrNone) { - RConnection tempConn; - CleanupClosePushL(tempConn); - tempConn.Open(serv); - if (tempConn.Attach(connInfo, RConnection::EAttachTypeNormal) == KErrNone) { - tempConn.GetDesSetting(TPtrC(KIapNameSetting), iapName); - tempConn.GetDesSetting(TPtrC(KIapServiceType), iapServiceType); - //tempConn.Stop(); - iapName.ZeroTerminate(); - iapServiceType.ZeroTerminate(); - -// if(iapServiceType.Find(_L8("LANService")) != KErrNotFound) { -// activeLanConnectionFound = ETrue; -// break; -// } - strIapName = QString((char*)iapName.Ptr()); - int error = 0; - if(!qt_SetDefaultIapName(strIapName, error)) { - //printf("failed setdefaultif @ %i with %s and errno = %d \n", __LINE__, strIapName.toUtf8().data(), error); - strIapName = QString(""); - } - - CleanupStack::PopAndDestroy(&tempConn); - break; - } - } - } - } - } - - //conn.Stop(); - - CleanupStack::PopAndDestroy(&conn); - CleanupStack::PopAndDestroy(&serv); - - return strIapName; -} - -static QString qt_CheckSettingsForConnection(QStringList& iapNames) { - QString strIapName; - for(int index = 0; index < iapNames.size(); ++index) { - strIapName = iapNames.at(index); - int error = 0; - if(!qt_SetDefaultIapName(strIapName, error)) { - //printf("failed setdefaultif @ %i with %s and errno = %d \n", __LINE__, strIapName.toUtf8().data(), error); - strIapName = QString(""); - } else { - return strIapName; - } - } - return strIapName; -} - -static void qt_SetDefaultIapL() -{ - // settings @ /c/data/.config/Trolltech.com - QSettings settings(QSettings::UserScope, qtOrganizationTag); - // populate iap name list - QStringList iapNames; - readIapNamesSettings(settings, iapNames); - - QString iapNameValue; - - iapNameValue = qt_CheckForActiveConnection(); - - if(!iapNameValue.isEmpty()) { - qt_SaveIapName(settings, iapNames, iapNameValue); - return; - } - - iapNameValue = qt_CheckSettingsForConnection(iapNames); - - if(!iapNameValue.isEmpty()) { - qt_SaveIapName(settings, iapNames, iapNameValue); - return; - } - - /* - * no active LAN connections yet - * no IAP in settings - * offer IAP dialog to user - */ - iapNameValue = qt_OfferIapDialog(); - qt_SaveIapName(settings, iapNames, iapNameValue); - return; - -} - -static int qt_SetDefaultIap() -{ - TRAPD(err1, qt_SetDefaultIapL()); -// TRAPD(err2, qt_InterfaceInfoL()); -// TRAPD(err3, qt_RouteInfoL()); - return err1; -} - -#endif // QSYM_IAP_UTIL_H diff --git a/examples/network/network.pro b/examples/network/network.pro index 38cdae8..0849271 100644 --- a/examples/network/network.pro +++ b/examples/network/network.pro @@ -6,7 +6,7 @@ SUBDIRS = blockingfortuneclient \ downloadmanager \ fortuneclient \ fortuneserver \ - ftp \ + qftp \ http \ loopback \ threadedfortuneserver \ @@ -16,7 +16,7 @@ SUBDIRS = blockingfortuneclient \ # no QProcess !vxworks:!qnx:SUBDIRS += network-chat -symbian: SUBDIRS = ftp +symbian: SUBDIRS = qftp contains(QT_CONFIG, openssl):SUBDIRS += securesocketclient diff --git a/examples/network/qftp/ftp.qrc b/examples/network/qftp/ftp.qrc new file mode 100644 index 0000000..b598ab8 --- /dev/null +++ b/examples/network/qftp/ftp.qrc @@ -0,0 +1,7 @@ + + + images/cdtoparent.png + images/dir.png + images/file.png + + diff --git a/examples/network/qftp/ftpwindow.cpp b/examples/network/qftp/ftpwindow.cpp new file mode 100644 index 0000000..f3fc52b --- /dev/null +++ b/examples/network/qftp/ftpwindow.cpp @@ -0,0 +1,379 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "ftpwindow.h" + +#ifdef Q_OS_SYMBIAN +#include "sym_iap_util.h" +#endif + +FtpWindow::FtpWindow(QWidget *parent) + : QDialog(parent), ftp(0) +{ + ftpServerLabel = new QLabel(tr("Ftp &server:")); + ftpServerLineEdit = new QLineEdit("ftp.qt.nokia.com"); + ftpServerLabel->setBuddy(ftpServerLineEdit); + + statusLabel = new QLabel(tr("Please enter the name of an FTP server.")); +#ifdef Q_OS_SYMBIAN + // Use word wrapping to fit the text on screen + statusLabel->setWordWrap( true ); +#endif + + fileList = new QTreeWidget; + fileList->setEnabled(false); + fileList->setRootIsDecorated(false); + fileList->setHeaderLabels(QStringList() << tr("Name") << tr("Size") << tr("Owner") << tr("Group") << tr("Time")); + fileList->header()->setStretchLastSection(false); + + connectButton = new QPushButton(tr("Connect")); + connectButton->setDefault(true); + + cdToParentButton = new QPushButton; + cdToParentButton->setIcon(QPixmap(":/images/cdtoparent.png")); + cdToParentButton->setEnabled(false); + + downloadButton = new QPushButton(tr("Download")); + downloadButton->setEnabled(false); + + quitButton = new QPushButton(tr("Quit")); + + buttonBox = new QDialogButtonBox; + buttonBox->addButton(downloadButton, QDialogButtonBox::ActionRole); + buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); + + progressDialog = new QProgressDialog(this); + + connect(fileList, SIGNAL(itemActivated(QTreeWidgetItem *, int)), + this, SLOT(processItem(QTreeWidgetItem *, int))); + connect(fileList, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), + this, SLOT(enableDownloadButton())); + connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload())); + connect(connectButton, SIGNAL(clicked()), this, SLOT(connectOrDisconnect())); + connect(cdToParentButton, SIGNAL(clicked()), this, SLOT(cdToParent())); + connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile())); + connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); + + QHBoxLayout *topLayout = new QHBoxLayout; + topLayout->addWidget(ftpServerLabel); + topLayout->addWidget(ftpServerLineEdit); +#ifndef Q_OS_SYMBIAN + topLayout->addWidget(cdToParentButton); + topLayout->addWidget(connectButton); +#else + // Make app better lookin on small screen + QHBoxLayout *topLayout2 = new QHBoxLayout; + topLayout2->addWidget(cdToParentButton); + topLayout2->addWidget(connectButton); +#endif + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(topLayout); +#ifdef Q_OS_SYMBIAN + // Make app better lookin on small screen + mainLayout->addLayout(topLayout2); +#endif + mainLayout->addWidget(fileList); + mainLayout->addWidget(statusLabel); + mainLayout->addWidget(buttonBox); + setLayout(mainLayout); + +#ifdef Q_OS_SYMBIAN + bDefaultIapSet = false; +#endif + + setWindowTitle(tr("FTP")); +} + +QSize FtpWindow::sizeHint() const +{ + return QSize(500, 300); +} + +//![0] +void FtpWindow::connectOrDisconnect() +{ +#ifdef Q_OS_SYMBIAN + if(!bDefaultIapSet) { + qt_SetDefaultIap(); + bDefaultIapSet = true; + } +#endif + if (ftp) { + ftp->abort(); + ftp->deleteLater(); + ftp = 0; +//![0] + fileList->setEnabled(false); + cdToParentButton->setEnabled(false); + downloadButton->setEnabled(false); + connectButton->setEnabled(true); + connectButton->setText(tr("Connect")); +#ifndef QT_NO_CURSOR + setCursor(Qt::ArrowCursor); +#endif + statusLabel->setText(tr("Please enter the name of an FTP server.")); + return; + } + +#ifndef QT_NO_CURSOR + setCursor(Qt::WaitCursor); +#endif + +//![1] + ftp = new QFtp(this); + connect(ftp, SIGNAL(commandFinished(int, bool)), + this, SLOT(ftpCommandFinished(int, bool))); + connect(ftp, SIGNAL(listInfo(const QUrlInfo &)), + this, SLOT(addToList(const QUrlInfo &))); + connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64)), + this, SLOT(updateDataTransferProgress(qint64, qint64))); + + fileList->clear(); + currentPath.clear(); + isDirectory.clear(); +//![1] + +//![2] + QUrl url(ftpServerLineEdit->text()); + if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) { + ftp->connectToHost(ftpServerLineEdit->text(), 21); + ftp->login(); + } else { + ftp->connectToHost(url.host(), url.port(21)); + + if (!url.userName().isEmpty()) + ftp->login(QUrl::fromPercentEncoding(url.userName().toLatin1()), url.password()); + else + ftp->login(); + if (!url.path().isEmpty()) + ftp->cd(url.path()); + } +//![2] + + fileList->setEnabled(true); + connectButton->setEnabled(false); + connectButton->setText(tr("Disconnect")); + statusLabel->setText(tr("Connecting to FTP server %1...") + .arg(ftpServerLineEdit->text())); +} + +//![3] +void FtpWindow::downloadFile() +{ + QString fileName = fileList->currentItem()->text(0); +//![3] +// + if (QFile::exists(fileName)) { + QMessageBox::information(this, tr("FTP"), + tr("There already exists a file called %1 in " + "the current directory.") + .arg(fileName)); + return; + } + +//![4] + file = new QFile(fileName); + if (!file->open(QIODevice::WriteOnly)) { + QMessageBox::information(this, tr("FTP"), + tr("Unable to save the file %1: %2.") + .arg(fileName).arg(file->errorString())); + delete file; + return; + } + + ftp->get(fileList->currentItem()->text(0), file); + + progressDialog->setLabelText(tr("Downloading %1...").arg(fileName)); + downloadButton->setEnabled(false); + progressDialog->exec(); +} +//![4] + +//![5] +void FtpWindow::cancelDownload() +{ + ftp->abort(); +} +//![5] + +//![6] +void FtpWindow::ftpCommandFinished(int, bool error) +{ +#ifndef QT_NO_CURSOR + setCursor(Qt::ArrowCursor); +#endif + + if (ftp->currentCommand() == QFtp::ConnectToHost) { + if (error) { + QMessageBox::information(this, tr("FTP"), + tr("Unable to connect to the FTP server " + "at %1. Please check that the host " + "name is correct.") + .arg(ftpServerLineEdit->text())); + connectOrDisconnect(); + return; + } + statusLabel->setText(tr("Logged onto %1.") + .arg(ftpServerLineEdit->text())); + fileList->setFocus(); + downloadButton->setDefault(true); + connectButton->setEnabled(true); + return; + } +//![6] + +//![7] + if (ftp->currentCommand() == QFtp::Login) + ftp->list(); +//![7] + +//![8] + if (ftp->currentCommand() == QFtp::Get) { + if (error) { + statusLabel->setText(tr("Canceled download of %1.") + .arg(file->fileName())); + file->close(); + file->remove(); + } else { + statusLabel->setText(tr("Downloaded %1 to current directory.") + .arg(file->fileName())); + file->close(); + } + delete file; + enableDownloadButton(); + progressDialog->hide(); +//![8] +//![9] + } else if (ftp->currentCommand() == QFtp::List) { + if (isDirectory.isEmpty()) { + fileList->addTopLevelItem(new QTreeWidgetItem(QStringList() << tr(""))); + fileList->setEnabled(false); + } + } +//![9] +} + +//![10] +void FtpWindow::addToList(const QUrlInfo &urlInfo) +{ + QTreeWidgetItem *item = new QTreeWidgetItem; + item->setText(0, urlInfo.name()); + item->setText(1, QString::number(urlInfo.size())); + item->setText(2, urlInfo.owner()); + item->setText(3, urlInfo.group()); + item->setText(4, urlInfo.lastModified().toString("MMM dd yyyy")); + + QPixmap pixmap(urlInfo.isDir() ? ":/images/dir.png" : ":/images/file.png"); + item->setIcon(0, pixmap); + + isDirectory[urlInfo.name()] = urlInfo.isDir(); + fileList->addTopLevelItem(item); + if (!fileList->currentItem()) { + fileList->setCurrentItem(fileList->topLevelItem(0)); + fileList->setEnabled(true); + } +} +//![10] + +//![11] +void FtpWindow::processItem(QTreeWidgetItem *item, int /*column*/) +{ + QString name = item->text(0); + if (isDirectory.value(name)) { + fileList->clear(); + isDirectory.clear(); + currentPath += "/" + name; + ftp->cd(name); + ftp->list(); + cdToParentButton->setEnabled(true); +#ifndef QT_NO_CURSOR + setCursor(Qt::WaitCursor); +#endif + return; + } +} +//![11] + +//![12] +void FtpWindow::cdToParent() +{ +#ifndef QT_NO_CURSOR + setCursor(Qt::WaitCursor); +#endif + fileList->clear(); + isDirectory.clear(); + currentPath = currentPath.left(currentPath.lastIndexOf('/')); + if (currentPath.isEmpty()) { + cdToParentButton->setEnabled(false); + ftp->cd("/"); + } else { + ftp->cd(currentPath); + } + ftp->list(); +} +//![12] + +//![13] +void FtpWindow::updateDataTransferProgress(qint64 readBytes, + qint64 totalBytes) +{ + progressDialog->setMaximum(totalBytes); + progressDialog->setValue(readBytes); +} +//![13] + +//![14] +void FtpWindow::enableDownloadButton() +{ + QTreeWidgetItem *current = fileList->currentItem(); + if (current) { + QString currentFile = current->text(0); + downloadButton->setEnabled(!isDirectory.value(currentFile)); + } else { + downloadButton->setEnabled(false); + } +} +//![14] + diff --git a/examples/network/qftp/ftpwindow.h b/examples/network/qftp/ftpwindow.h new file mode 100644 index 0000000..f92c36a --- /dev/null +++ b/examples/network/qftp/ftpwindow.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FTPWINDOW_H +#define FTPWINDOW_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QDialogButtonBox; +class QFile; +class QFtp; +class QLabel; +class QLineEdit; +class QTreeWidget; +class QTreeWidgetItem; +class QProgressDialog; +class QPushButton; +class QUrlInfo; +QT_END_NAMESPACE + +class FtpWindow : public QDialog +{ + Q_OBJECT + +public: + FtpWindow(QWidget *parent = 0); + QSize sizeHint() const; + +//![0] +private slots: + void connectOrDisconnect(); + void downloadFile(); + void cancelDownload(); + + void ftpCommandFinished(int commandId, bool error); + void addToList(const QUrlInfo &urlInfo); + void processItem(QTreeWidgetItem *item, int column); + void cdToParent(); + void updateDataTransferProgress(qint64 readBytes, + qint64 totalBytes); + void enableDownloadButton(); +//![0] + +private: + QLabel *ftpServerLabel; + QLineEdit *ftpServerLineEdit; + QLabel *statusLabel; + QTreeWidget *fileList; + QPushButton *cdToParentButton; + QPushButton *connectButton; + QPushButton *downloadButton; + QPushButton *quitButton; + QDialogButtonBox *buttonBox; + QProgressDialog *progressDialog; + +//![1] + QHash isDirectory; + QString currentPath; + QFtp *ftp; + QFile *file; + +#ifdef Q_OS_SYMBIAN + bool bDefaultIapSet; +#endif +//![1] +}; + +#endif diff --git a/examples/network/qftp/images/cdtoparent.png b/examples/network/qftp/images/cdtoparent.png new file mode 100644 index 0000000..24b6180 Binary files /dev/null and b/examples/network/qftp/images/cdtoparent.png differ diff --git a/examples/network/qftp/images/dir.png b/examples/network/qftp/images/dir.png new file mode 100644 index 0000000..0ce5ae7 Binary files /dev/null and b/examples/network/qftp/images/dir.png differ diff --git a/examples/network/qftp/images/file.png b/examples/network/qftp/images/file.png new file mode 100644 index 0000000..be6c530 Binary files /dev/null and b/examples/network/qftp/images/file.png differ diff --git a/examples/network/qftp/main.cpp b/examples/network/qftp/main.cpp new file mode 100644 index 0000000..d44ccd7 --- /dev/null +++ b/examples/network/qftp/main.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "ftpwindow.h" + +#ifdef Q_OS_SYMBIAN +#include +#include +#endif + +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(ftp); +#ifdef Q_OS_SYMBIAN + // Change current directory from default private to c:\data + // in order that user can access the downloaded content + QDir::setCurrent( "c:\\data" ); +#endif + QApplication app(argc, argv); + FtpWindow ftpWin; +#ifdef Q_OS_SYMBIAN + // Make application better looking and more usable on small screen + ftpWin.showMaximized(); +#else + ftpWin.show(); +#endif + return ftpWin.exec(); +} diff --git a/examples/network/qftp/qftp.pro b/examples/network/qftp/qftp.pro new file mode 100644 index 0000000..b3106c3 --- /dev/null +++ b/examples/network/qftp/qftp.pro @@ -0,0 +1,20 @@ +HEADERS = ftpwindow.h +SOURCES = ftpwindow.cpp \ + main.cpp +RESOURCES += ftp.qrc +QT += network + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/network/qftp +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro images +sources.path = $$[QT_INSTALL_EXAMPLES]/network/qftp +INSTALLS += target sources + +symbian { + TARGET.UID3 = 0xA000A648 + include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) + HEADERS += sym_iap_util.h + INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE + TARGET.CAPABILITY="NetworkServices ReadUserData WriteUserData" + LIBS+=-lesock -lcommdb -linsock # For IAP selection +} diff --git a/examples/network/qftp/sym_iap_util.h b/examples/network/qftp/sym_iap_util.h new file mode 100644 index 0000000..ebeae0a --- /dev/null +++ b/examples/network/qftp/sym_iap_util.h @@ -0,0 +1,510 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QSYM_IAP_UTIL_H +#define QSYM_IAP_UTIL_H + +// Symbian +#include +#include +#include +#include +#include +#include +#include + +// OpenC +#include +#include + +//Qt +#include +#include +//#include + +_LIT(KIapNameSetting, "IAP\\Name"); // text - mandatory +_LIT(KIapDialogPref, "IAP\\DialogPref"); // TUnit32 - optional +_LIT(KIapService, "IAP\\IAPService"); // TUnit32 - mandatory +_LIT(KIapServiceType, "IAP\\IAPServiceType"); // text - mandatory +_LIT(KIapBearer, "IAP\\IAPBearer"); // TUint32 - optional +_LIT(KIapBearerType, "IAP\\IAPBearerType"); // text - optional +_LIT(KIapNetwork, "IAP\\IAPNetwork"); // TUint32 - optional + +const QLatin1String qtOrganizationTag("Trolltech"); +const QLatin1String qtNetworkModuleTag("QtNetwork"); +const QLatin1String iapGroupTag("IAP"); +const QLatin1String iapNamesArrayTag("Names"); +const QLatin1String iapNameItemTag("Name"); + +static QTextCodec *utf16LETextCodec = 0; + +void clearIapNamesSettings(QSettings &settings) { + settings.beginGroup(qtNetworkModuleTag); + settings.beginGroup(iapGroupTag); + settings.remove(iapNamesArrayTag); + settings.endGroup(); + settings.endGroup(); +} + +void writeIapNamesSettings(QSettings &settings, const QStringList& iapNames) { + clearIapNamesSettings(settings); + settings.beginGroup(qtNetworkModuleTag); + settings.beginGroup(iapGroupTag); + settings.beginWriteArray(iapNamesArrayTag); + for (int index = 0; index < iapNames.size(); ++index) { + settings.setArrayIndex(index); + settings.setValue(iapNameItemTag, iapNames.at(index)); + } + settings.endArray(); + settings.endGroup(); + settings.endGroup(); +} + +void readIapNamesSettings(QSettings &settings, QStringList& iapNames) { + settings.beginGroup(qtNetworkModuleTag); + settings.beginGroup(iapGroupTag); + int last = settings.beginReadArray(iapNamesArrayTag); + for (int index = 0; index < last; ++index) { + settings.setArrayIndex(index); + iapNames.append(settings.value(iapNameItemTag).toString()); + } + settings.endArray(); + settings.endGroup(); + settings.endGroup(); +} + +static QString qt_TNameToQString(TName data) { + if(utf16LETextCodec == 0) + utf16LETextCodec = QTextCodec::codecForName("UTF-16LE"); + + QByteArray tmpByteArray = QByteArray::fromRawData((char*)(data.PtrZ()), data.Length() * 2); + return utf16LETextCodec->toUnicode(tmpByteArray); +} + +static QString qt_InterfaceInfoL() +{ + QString output; + + TBuf8<512> buffer; + TBuf<128> t; + TAutoClose ss; + User::LeaveIfError(ss.iObj.Connect()); + ss.PushL(); + + TAutoClose sock; + User::LeaveIfError(sock.iObj.Open(ss.iObj, _L("udp"))); + sock.PushL(); + + User::LeaveIfError(sock.iObj.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl)); + + TProtocolDesc in; + User::LeaveIfError(sock.iObj.Info(in)); + printf("EPOC32 IP Configuration TCPIP Version %d.%d.%d\n", in.iVersion.iMajor, in.iVersion.iMinor, in.iVersion.iBuild); + + TPckgBuf info, next; + + TInt res=sock.iObj.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, info); + if(res!=KErrNone) + User::Leave(res); + TInt count = 0; + while(res==KErrNone) { + res=sock.iObj.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, next); + + if(info().iName != _L("") && info().iName != _L("loop6") && info().iName != _L("loop4")) { + printf("Interface %d\n", count++); + + printf("Name \"%s\"\n", qt_TNameToQString(info().iName).toLatin1().data()); + printf("NIF tag \"%s\"\n", qt_TNameToQString(info().iTag).toLatin1().data()); + + printf("State "); + switch (info().iState) + { + case EIfPending: + printf("pending\n"); + break; + case EIfUp: + printf("up\n"); + break; + case EIfBusy: + printf("busy\n"); + break; + default: + printf("down\n"); + break; + } + + printf("Mtu %d\n", info().iMtu); + printf("Speed Metric %d\n", info().iSpeedMetric); + + printf("Features:"); + info().iFeatures & KIfIsLoopback ? printf(" loopback") : printf(""); + info().iFeatures & KIfIsDialup ? printf(" dialup") : printf(""); + info().iFeatures & KIfIsPointToPoint ? printf(" pointtopoint") : printf(""); + info().iFeatures & KIfCanBroadcast ? printf(" canbroadcast") : printf(""); + info().iFeatures & KIfCanMulticast ? printf(" canmulticast") : printf(""); + info().iFeatures & KIfCanSetMTU ? printf(" cansetmtu") : printf(""); + info().iFeatures & KIfHasHardwareAddr ? printf(" hardwareaddr") : printf(""); + info().iFeatures & KIfCanSetHardwareAddr ? printf(" cansethardwareaddr") : printf(""); + printf("\n"); + + TName address; + info().iAddress.Output(address); + printf("Addr: %s\n", qt_TNameToQString(address).toLatin1().data()); + + if(info().iAddress.IsLinkLocal()) { + printf(" -link local\n"); + } else if(info().iAddress.IsSiteLocal()) { + printf(" -site local\n"); + } else { + printf(" -global\n"); + } + + info().iNetMask.Output(address); + printf("Netmask %s\n", qt_TNameToQString(address).toLatin1().data()); + + info().iBrdAddr.Output(address); + printf("Broadcast address %s\n", qt_TNameToQString(address).toLatin1().data()); + + info().iDefGate.Output(address); + printf("Gatew: %s\n", qt_TNameToQString(address).toLatin1().data()); + + info().iNameSer1.Output(address); + printf("DNS 1: %s\n", qt_TNameToQString(address).toLatin1().data()); + + info().iNameSer2.Output(address); + printf("DNS 2: %s\n", qt_TNameToQString(address).toLatin1().data()); + + if (info().iHwAddr.Family() != KAFUnspec) { + printf("Hardware address "); + TUint j; + for(j = sizeof(SSockAddr) ; j < sizeof(SSockAddr) + 6 ; ++j) { + if(j < (TUint)info().iHwAddr.Length()) { + printf("%02X", info().iHwAddr[j]); + } else { + printf("??"); + } + if(j < sizeof(SSockAddr) + 5) + printf("-"); + else + printf("\n"); + } + } + } + if(res == KErrNone) { + info = next; + printf("\n"); + } else { + printf("\n"); + } + } + + sock.Pop(); + ss.Pop(); + + return output; +} + +static QString qt_RouteInfoL() { + QString output; + TAutoClose ss; + User::LeaveIfError(ss.iObj.Connect()); + ss.PushL(); + + TAutoClose sock; + User::LeaveIfError(sock.iObj.Open(ss.iObj, _L("udp"))); + sock.PushL(); + + TSoInetRouteInfo routeInfo; + TPckg routeInfoPkg(routeInfo); + + TName destAddr; + TName netMask; + TName gateway; + TName ifAddr; + + // Begins enumeration of routes by setting this option + User::LeaveIfError(sock.iObj.SetOpt(KSoInetEnumRoutes, KSolInetRtCtrl)); + + // The TSoInetRouteInfo contains information for a new route each time GetOpt returns KErrNone + for(TInt i = 0; sock.iObj.GetOpt(KSoInetNextRoute, KSolInetRtCtrl, routeInfoPkg) == KErrNone ; i++) + { + // Extract the destination and netmask + routeInfo.iDstAddr.Output(destAddr); + routeInfo.iNetMask.Output(netMask); + routeInfo.iGateway.Output(gateway); + routeInfo.iIfAddr.Output(ifAddr); +/* + if(destAddr.Length() <= 2) + continue; + + if(netMask.Find(_L("255.255.255.255")) != KErrNotFound + || netMask.Find(_L("0.0.0.0")) != KErrNotFound + || netMask.Find(_L("ffff:ffff:ffff:ffff")) != KErrNotFound) + continue; +*/ + printf("Route Info #[%i]\n", i); + printf("DstAddr %s\n", qt_TNameToQString(destAddr).toLatin1().data()); + printf("NetMask %s\n", qt_TNameToQString(netMask).toLatin1().data()); + printf("Gateway %s\n", qt_TNameToQString(gateway).toLatin1().data()); + printf("IfAddr %s\n", qt_TNameToQString(ifAddr).toLatin1().data()); + printf("\n"); + } + + sock.Pop(); + ss.Pop(); + + return output; +} + +QString qt_TDesC2QStringL(const TDesC& aDescriptor) +{ +#ifdef QT_NO_UNICODE + return QString::fromLocal8Bit(aDescriptor.Ptr(), aDescriptor.Length()); +#else + return QString::fromUtf16(aDescriptor.Ptr(), aDescriptor.Length()); +#endif +} + +static bool qt_SetDefaultIapName(const QString &iapName, int &error) { + struct ifreq ifReq; + // clear structure + memset(&ifReq, 0, sizeof(struct ifreq)); + // set IAP name value + // make sure it is in UTF8 + strcpy(ifReq.ifr_name, iapName.toUtf8().data()); + + if(setdefaultif(&ifReq) == 0) { + // OK + error = 0; + return true; + } else { + error = errno; + return false; + } + +} +static bool qt_SetDefaultSnapId(const int snapId, int &error) { + struct ifreq ifReq; + // clear structure + memset(&ifReq, 0, sizeof(struct ifreq)); + // set SNAP ID value + ifReq.ifr_ifru.snap_id = snapId; + + if(setdefaultif(&ifReq) == 0) { + // OK + error = 0; + return true; + } else { + error = errno; + return false; + } + +} + +static void qt_SaveIapName(QSettings& settings, QStringList& iapNames, QString& iapNameValue) { + if(iapNames.contains(iapNameValue) && iapNames.first() == iapNameValue) { + // no need to update + } else { + if(iapNameValue != QString("Easy WLAN")) { + // new selection alway on top + iapNames.removeAll(iapNameValue); + iapNames.prepend(iapNameValue); + writeIapNamesSettings(settings, iapNames); + } else { + // Unbeliveable ... if IAP dodn't exist before + // no matter what you choose from IAP selection list + // you will get "Easy WLAN" as IAP name value + + // somehow commsdb is not in sync + } + } +} + +static QString qt_OfferIapDialog() { + TBuf8<256> iapName; + + RSocketServ socketServ; + CleanupClosePushL(socketServ); + + RConnection connection; + CleanupClosePushL(connection); + + socketServ.Connect(); + connection.Open(socketServ); + connection.Start(); + + connection.GetDesSetting(TPtrC(KIapNameSetting), iapName); + + //connection.Stop(); + + iapName.ZeroTerminate(); + QString strIapName((char*)iapName.Ptr()); + + int error = 0; + if(!qt_SetDefaultIapName(strIapName, error)) { + //printf("failed setdefaultif @ %i with %s and errno = %d \n", __LINE__, strIapName.toUtf8().data(), error); + strIapName = QString(""); + } + + CleanupStack::PopAndDestroy(&connection); + CleanupStack::PopAndDestroy(&socketServ); + + return strIapName; +} + +static QString qt_CheckForActiveConnection() { + TUint count; + + RSocketServ serv; + CleanupClosePushL(serv); + + RConnection conn; + CleanupClosePushL(conn); + + serv.Connect(); + conn.Open(serv); + + TConnectionInfoBuf connInfo; + + TBuf8<256> iapName; + TBuf8<256> iapServiceType; + + QString strIapName; + + if (conn.EnumerateConnections(count) == KErrNone) { + if(count > 0) { + for (TUint i = 1; i <= count; i++) { + if (conn.GetConnectionInfo(i, connInfo) == KErrNone) { + RConnection tempConn; + CleanupClosePushL(tempConn); + tempConn.Open(serv); + if (tempConn.Attach(connInfo, RConnection::EAttachTypeNormal) == KErrNone) { + tempConn.GetDesSetting(TPtrC(KIapNameSetting), iapName); + tempConn.GetDesSetting(TPtrC(KIapServiceType), iapServiceType); + //tempConn.Stop(); + iapName.ZeroTerminate(); + iapServiceType.ZeroTerminate(); + +// if(iapServiceType.Find(_L8("LANService")) != KErrNotFound) { +// activeLanConnectionFound = ETrue; +// break; +// } + strIapName = QString((char*)iapName.Ptr()); + int error = 0; + if(!qt_SetDefaultIapName(strIapName, error)) { + //printf("failed setdefaultif @ %i with %s and errno = %d \n", __LINE__, strIapName.toUtf8().data(), error); + strIapName = QString(""); + } + + CleanupStack::PopAndDestroy(&tempConn); + break; + } + } + } + } + } + + //conn.Stop(); + + CleanupStack::PopAndDestroy(&conn); + CleanupStack::PopAndDestroy(&serv); + + return strIapName; +} + +static QString qt_CheckSettingsForConnection(QStringList& iapNames) { + QString strIapName; + for(int index = 0; index < iapNames.size(); ++index) { + strIapName = iapNames.at(index); + int error = 0; + if(!qt_SetDefaultIapName(strIapName, error)) { + //printf("failed setdefaultif @ %i with %s and errno = %d \n", __LINE__, strIapName.toUtf8().data(), error); + strIapName = QString(""); + } else { + return strIapName; + } + } + return strIapName; +} + +static void qt_SetDefaultIapL() +{ + // settings @ /c/data/.config/Trolltech.com + QSettings settings(QSettings::UserScope, qtOrganizationTag); + // populate iap name list + QStringList iapNames; + readIapNamesSettings(settings, iapNames); + + QString iapNameValue; + + iapNameValue = qt_CheckForActiveConnection(); + + if(!iapNameValue.isEmpty()) { + qt_SaveIapName(settings, iapNames, iapNameValue); + return; + } + + iapNameValue = qt_CheckSettingsForConnection(iapNames); + + if(!iapNameValue.isEmpty()) { + qt_SaveIapName(settings, iapNames, iapNameValue); + return; + } + + /* + * no active LAN connections yet + * no IAP in settings + * offer IAP dialog to user + */ + iapNameValue = qt_OfferIapDialog(); + qt_SaveIapName(settings, iapNames, iapNameValue); + return; + +} + +static int qt_SetDefaultIap() +{ + TRAPD(err1, qt_SetDefaultIapL()); +// TRAPD(err2, qt_InterfaceInfoL()); +// TRAPD(err3, qt_RouteInfoL()); + return err1; +} + +#endif // QSYM_IAP_UTIL_H diff --git a/examples/phonon/musicplayer/main.cpp b/examples/phonon/musicplayer/main.cpp deleted file mode 100644 index fc7baa3..0000000 --- a/examples/phonon/musicplayer/main.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include - -#include "mainwindow.h" - -//![1] -int main(int argv, char **args) -{ - QApplication app(argv, args); - app.setApplicationName("Music Player"); - app.setQuitOnLastWindowClosed(true); - - MainWindow window; - window.show(); - - return app.exec(); -} -//![1] diff --git a/examples/phonon/musicplayer/mainwindow.cpp b/examples/phonon/musicplayer/mainwindow.cpp deleted file mode 100644 index 787ae53..0000000 --- a/examples/phonon/musicplayer/mainwindow.cpp +++ /dev/null @@ -1,355 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -***************************************************************************/ - -#include - -#include "mainwindow.h" - -//![0] -MainWindow::MainWindow() -{ - audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); - mediaObject = new Phonon::MediaObject(this); - metaInformationResolver = new Phonon::MediaObject(this); - - mediaObject->setTickInterval(1000); -//![0] -//![2] - connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64))); - connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)), - this, SLOT(stateChanged(Phonon::State, Phonon::State))); - connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this, SLOT(metaStateChanged(Phonon::State, Phonon::State))); - connect(mediaObject, SIGNAL(currentSourceChanged(const Phonon::MediaSource &)), - this, SLOT(sourceChanged(const Phonon::MediaSource &))); - connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish())); -//![2] - -//![1] - Phonon::createPath(mediaObject, audioOutput); -//![1] - - setupActions(); - setupMenus(); - setupUi(); - timeLcd->display("00:00"); -} - -//![6] -void MainWindow::addFiles() -{ - QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Music Files"), - QDesktopServices::storageLocation(QDesktopServices::MusicLocation)); - - if (files.isEmpty()) - return; - - int index = sources.size(); - foreach (QString string, files) { - Phonon::MediaSource source(string); - - sources.append(source); - } - if (!sources.isEmpty()) - metaInformationResolver->setCurrentSource(sources.at(index)); - -} -//![6] - -void MainWindow::about() -{ - QMessageBox::information(this, tr("About Music Player"), - tr("The Music Player example shows how to use Phonon - the multimedia" - " framework that comes with Qt - to create a simple music player.")); -} - -//![9] -void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */) -{ - switch (newState) { - case Phonon::ErrorState: - if (mediaObject->errorType() == Phonon::FatalError) { - QMessageBox::warning(this, tr("Fatal Error"), - mediaObject->errorString()); - } else { - QMessageBox::warning(this, tr("Error"), - mediaObject->errorString()); - } - break; -//![9] -//![10] - case Phonon::PlayingState: - playAction->setEnabled(false); - pauseAction->setEnabled(true); - stopAction->setEnabled(true); - break; - case Phonon::StoppedState: - stopAction->setEnabled(false); - playAction->setEnabled(true); - pauseAction->setEnabled(false); - timeLcd->display("00:00"); - break; - case Phonon::PausedState: - pauseAction->setEnabled(false); - stopAction->setEnabled(true); - playAction->setEnabled(true); - break; -//![10] - case Phonon::BufferingState: - break; - default: - ; - } -} - -//![11] -void MainWindow::tick(qint64 time) -{ - QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60); - - timeLcd->display(displayTime.toString("mm:ss")); -} -//![11] - -//![12] -void MainWindow::tableClicked(int row, int /* column */) -{ - bool wasPlaying = mediaObject->state() == Phonon::PlayingState; - - mediaObject->stop(); - mediaObject->clearQueue(); - - if (row >= sources.size()) - return; - - mediaObject->setCurrentSource(sources[row]); - - if (wasPlaying) - mediaObject->play(); - else - mediaObject->stop(); -} -//![12] - -//![13] -void MainWindow::sourceChanged(const Phonon::MediaSource &source) -{ - musicTable->selectRow(sources.indexOf(source)); - timeLcd->display("00:00"); -} -//![13] - -//![14] -void MainWindow::metaStateChanged(Phonon::State newState, Phonon::State /* oldState */) -{ - if (newState == Phonon::ErrorState) { - QMessageBox::warning(this, tr("Error opening files"), - metaInformationResolver->errorString()); - while (!sources.isEmpty() && - !(sources.takeLast() == metaInformationResolver->currentSource())) {} /* loop */; - return; - } - - if (newState != Phonon::StoppedState && newState != Phonon::PausedState) - return; - - if (metaInformationResolver->currentSource().type() == Phonon::MediaSource::Invalid) - return; - - QMap metaData = metaInformationResolver->metaData(); - - QString title = metaData.value("TITLE"); - if (title == "") - title = metaInformationResolver->currentSource().fileName(); - - QTableWidgetItem *titleItem = new QTableWidgetItem(title); - titleItem->setFlags(titleItem->flags() ^ Qt::ItemIsEditable); - QTableWidgetItem *artistItem = new QTableWidgetItem(metaData.value("ARTIST")); - artistItem->setFlags(artistItem->flags() ^ Qt::ItemIsEditable); - QTableWidgetItem *albumItem = new QTableWidgetItem(metaData.value("ALBUM")); - albumItem->setFlags(albumItem->flags() ^ Qt::ItemIsEditable); - QTableWidgetItem *yearItem = new QTableWidgetItem(metaData.value("DATE")); - yearItem->setFlags(yearItem->flags() ^ Qt::ItemIsEditable); -//![14] - - int currentRow = musicTable->rowCount(); - musicTable->insertRow(currentRow); - musicTable->setItem(currentRow, 0, titleItem); - musicTable->setItem(currentRow, 1, artistItem); - musicTable->setItem(currentRow, 2, albumItem); - musicTable->setItem(currentRow, 3, yearItem); - -//![15] - if (musicTable->selectedItems().isEmpty()) { - musicTable->selectRow(0); - mediaObject->setCurrentSource(metaInformationResolver->currentSource()); - } - - Phonon::MediaSource source = metaInformationResolver->currentSource(); - int index = sources.indexOf(metaInformationResolver->currentSource()) + 1; - if (sources.size() > index) { - metaInformationResolver->setCurrentSource(sources.at(index)); - } - else { - musicTable->resizeColumnsToContents(); - if (musicTable->columnWidth(0) > 300) - musicTable->setColumnWidth(0, 300); - } -} -//![15] - -//![16] -void MainWindow::aboutToFinish() -{ - int index = sources.indexOf(mediaObject->currentSource()) + 1; - if (sources.size() > index) { - mediaObject->enqueue(sources.at(index)); - } -} -//![16] - -void MainWindow::setupActions() -{ - playAction = new QAction(style()->standardIcon(QStyle::SP_MediaPlay), tr("Play"), this); - playAction->setShortcut(tr("Crl+P")); - playAction->setDisabled(true); - pauseAction = new QAction(style()->standardIcon(QStyle::SP_MediaPause), tr("Pause"), this); - pauseAction->setShortcut(tr("Ctrl+A")); - pauseAction->setDisabled(true); - stopAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop), tr("Stop"), this); - stopAction->setShortcut(tr("Ctrl+S")); - stopAction->setDisabled(true); - nextAction = new QAction(style()->standardIcon(QStyle::SP_MediaSkipForward), tr("Next"), this); - nextAction->setShortcut(tr("Ctrl+N")); - previousAction = new QAction(style()->standardIcon(QStyle::SP_MediaSkipBackward), tr("Previous"), this); - previousAction->setShortcut(tr("Ctrl+R")); - addFilesAction = new QAction(tr("Add &Files"), this); - addFilesAction->setShortcut(tr("Ctrl+F")); - exitAction = new QAction(tr("E&xit"), this); - exitAction->setShortcuts(QKeySequence::Quit); - aboutAction = new QAction(tr("A&bout"), this); - aboutAction->setShortcut(tr("Ctrl+B")); - aboutQtAction = new QAction(tr("About &Qt"), this); - aboutQtAction->setShortcut(tr("Ctrl+Q")); - -//![5] - connect(playAction, SIGNAL(triggered()), mediaObject, SLOT(play())); - connect(pauseAction, SIGNAL(triggered()), mediaObject, SLOT(pause()) ); - connect(stopAction, SIGNAL(triggered()), mediaObject, SLOT(stop())); -//![5] - connect(addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles())); - connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); - connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); - connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); -} - -void MainWindow::setupMenus() -{ - QMenu *fileMenu = menuBar()->addMenu(tr("&File")); - fileMenu->addAction(addFilesAction); - fileMenu->addSeparator(); - fileMenu->addAction(exitAction); - - QMenu *aboutMenu = menuBar()->addMenu(tr("&Help")); - aboutMenu->addAction(aboutAction); - aboutMenu->addAction(aboutQtAction); -} - -//![3] -void MainWindow::setupUi() -{ -//![3] - QToolBar *bar = new QToolBar; - - bar->addAction(playAction); - bar->addAction(pauseAction); - bar->addAction(stopAction); - -//![4] - seekSlider = new Phonon::SeekSlider(this); - seekSlider->setMediaObject(mediaObject); - - volumeSlider = new Phonon::VolumeSlider(this); - volumeSlider->setAudioOutput(audioOutput); -//![4] - volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); - - QLabel *volumeLabel = new QLabel; - volumeLabel->setPixmap(QPixmap("images/volume.png")); - - QPalette palette; - palette.setBrush(QPalette::Light, Qt::darkGray); - - timeLcd = new QLCDNumber; - timeLcd->setPalette(palette); - - QStringList headers; - headers << tr("Title") << tr("Artist") << tr("Album") << tr("Year"); - - musicTable = new QTableWidget(0, 4); - musicTable->setHorizontalHeaderLabels(headers); - musicTable->setSelectionMode(QAbstractItemView::SingleSelection); - musicTable->setSelectionBehavior(QAbstractItemView::SelectRows); - connect(musicTable, SIGNAL(cellPressed(int, int)), - this, SLOT(tableClicked(int, int))); - - QHBoxLayout *seekerLayout = new QHBoxLayout; - seekerLayout->addWidget(seekSlider); - seekerLayout->addWidget(timeLcd); - - QHBoxLayout *playbackLayout = new QHBoxLayout; - playbackLayout->addWidget(bar); - playbackLayout->addStretch(); - playbackLayout->addWidget(volumeLabel); - playbackLayout->addWidget(volumeSlider); - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(musicTable); - mainLayout->addLayout(seekerLayout); - mainLayout->addLayout(playbackLayout); - - QWidget *widget = new QWidget; - widget->setLayout(mainLayout); - - setCentralWidget(widget); - setWindowTitle("Phonon Music Player"); -} - diff --git a/examples/phonon/musicplayer/mainwindow.h b/examples/phonon/musicplayer/mainwindow.h deleted file mode 100644 index 41f8147..0000000 --- a/examples/phonon/musicplayer/mainwindow.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QAction; -class QTableWidget; -class QLCDNumber; -QT_END_NAMESPACE - -//![0] - -class MainWindow : public QMainWindow -{ -//![0] - Q_OBJECT - -public: - MainWindow(); - - QSize sizeHint() const { - return QSize(500, 300); - } - -private slots: - void addFiles(); - void about(); -//![1] - void stateChanged(Phonon::State newState, Phonon::State oldState); - void tick(qint64 time); - void sourceChanged(const Phonon::MediaSource &source); - void metaStateChanged(Phonon::State newState, Phonon::State oldState); - void aboutToFinish(); - void tableClicked(int row, int column); -//![1] - -private: - void setupActions(); - void setupMenus(); - void setupUi(); - -//![2] - Phonon::SeekSlider *seekSlider; - Phonon::MediaObject *mediaObject; - Phonon::MediaObject *metaInformationResolver; - Phonon::AudioOutput *audioOutput; - Phonon::VolumeSlider *volumeSlider; - QList sources; -//![2] - - QAction *playAction; - QAction *pauseAction; - QAction *stopAction; - QAction *nextAction; - QAction *previousAction; - QAction *addFilesAction; - QAction *exitAction; - QAction *aboutAction; - QAction *aboutQtAction; - QLCDNumber *timeLcd; - QTableWidget *musicTable; -}; - -#endif diff --git a/examples/phonon/musicplayer/musicplayer.pro b/examples/phonon/musicplayer/musicplayer.pro deleted file mode 100644 index a0c953a..0000000 --- a/examples/phonon/musicplayer/musicplayer.pro +++ /dev/null @@ -1,17 +0,0 @@ -QT += phonon - -HEADERS += mainwindow.h -SOURCES += main.cpp \ - mainwindow.cpp - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/phonon/musicplayer -sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png images -sources.path = $$[QT_INSTALL_EXAMPLES]/phonon/musicplayer -INSTALLS += target sources - -wince*{ -DEPLOYMENT_PLUGIN += phonon_ds9 phonon_waveout -} - -symbian:TARGET.UID3 = 0xA000CF6A diff --git a/examples/phonon/phonon.pro b/examples/phonon/phonon.pro index 0ddf767..aa6ac13 100644 --- a/examples/phonon/phonon.pro +++ b/examples/phonon/phonon.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS = musicplayer \ +SUBDIRS = qmusicplayer \ capabilities # install diff --git a/examples/phonon/qmusicplayer/main.cpp b/examples/phonon/qmusicplayer/main.cpp new file mode 100644 index 0000000..fc7baa3 --- /dev/null +++ b/examples/phonon/qmusicplayer/main.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include + +#include "mainwindow.h" + +//![1] +int main(int argv, char **args) +{ + QApplication app(argv, args); + app.setApplicationName("Music Player"); + app.setQuitOnLastWindowClosed(true); + + MainWindow window; + window.show(); + + return app.exec(); +} +//![1] diff --git a/examples/phonon/qmusicplayer/mainwindow.cpp b/examples/phonon/qmusicplayer/mainwindow.cpp new file mode 100644 index 0000000..787ae53 --- /dev/null +++ b/examples/phonon/qmusicplayer/mainwindow.cpp @@ -0,0 +1,355 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +***************************************************************************/ + +#include + +#include "mainwindow.h" + +//![0] +MainWindow::MainWindow() +{ + audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); + mediaObject = new Phonon::MediaObject(this); + metaInformationResolver = new Phonon::MediaObject(this); + + mediaObject->setTickInterval(1000); +//![0] +//![2] + connect(mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick(qint64))); + connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)), + this, SLOT(stateChanged(Phonon::State, Phonon::State))); + connect(metaInformationResolver, SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this, SLOT(metaStateChanged(Phonon::State, Phonon::State))); + connect(mediaObject, SIGNAL(currentSourceChanged(const Phonon::MediaSource &)), + this, SLOT(sourceChanged(const Phonon::MediaSource &))); + connect(mediaObject, SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish())); +//![2] + +//![1] + Phonon::createPath(mediaObject, audioOutput); +//![1] + + setupActions(); + setupMenus(); + setupUi(); + timeLcd->display("00:00"); +} + +//![6] +void MainWindow::addFiles() +{ + QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Music Files"), + QDesktopServices::storageLocation(QDesktopServices::MusicLocation)); + + if (files.isEmpty()) + return; + + int index = sources.size(); + foreach (QString string, files) { + Phonon::MediaSource source(string); + + sources.append(source); + } + if (!sources.isEmpty()) + metaInformationResolver->setCurrentSource(sources.at(index)); + +} +//![6] + +void MainWindow::about() +{ + QMessageBox::information(this, tr("About Music Player"), + tr("The Music Player example shows how to use Phonon - the multimedia" + " framework that comes with Qt - to create a simple music player.")); +} + +//![9] +void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState */) +{ + switch (newState) { + case Phonon::ErrorState: + if (mediaObject->errorType() == Phonon::FatalError) { + QMessageBox::warning(this, tr("Fatal Error"), + mediaObject->errorString()); + } else { + QMessageBox::warning(this, tr("Error"), + mediaObject->errorString()); + } + break; +//![9] +//![10] + case Phonon::PlayingState: + playAction->setEnabled(false); + pauseAction->setEnabled(true); + stopAction->setEnabled(true); + break; + case Phonon::StoppedState: + stopAction->setEnabled(false); + playAction->setEnabled(true); + pauseAction->setEnabled(false); + timeLcd->display("00:00"); + break; + case Phonon::PausedState: + pauseAction->setEnabled(false); + stopAction->setEnabled(true); + playAction->setEnabled(true); + break; +//![10] + case Phonon::BufferingState: + break; + default: + ; + } +} + +//![11] +void MainWindow::tick(qint64 time) +{ + QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60); + + timeLcd->display(displayTime.toString("mm:ss")); +} +//![11] + +//![12] +void MainWindow::tableClicked(int row, int /* column */) +{ + bool wasPlaying = mediaObject->state() == Phonon::PlayingState; + + mediaObject->stop(); + mediaObject->clearQueue(); + + if (row >= sources.size()) + return; + + mediaObject->setCurrentSource(sources[row]); + + if (wasPlaying) + mediaObject->play(); + else + mediaObject->stop(); +} +//![12] + +//![13] +void MainWindow::sourceChanged(const Phonon::MediaSource &source) +{ + musicTable->selectRow(sources.indexOf(source)); + timeLcd->display("00:00"); +} +//![13] + +//![14] +void MainWindow::metaStateChanged(Phonon::State newState, Phonon::State /* oldState */) +{ + if (newState == Phonon::ErrorState) { + QMessageBox::warning(this, tr("Error opening files"), + metaInformationResolver->errorString()); + while (!sources.isEmpty() && + !(sources.takeLast() == metaInformationResolver->currentSource())) {} /* loop */; + return; + } + + if (newState != Phonon::StoppedState && newState != Phonon::PausedState) + return; + + if (metaInformationResolver->currentSource().type() == Phonon::MediaSource::Invalid) + return; + + QMap metaData = metaInformationResolver->metaData(); + + QString title = metaData.value("TITLE"); + if (title == "") + title = metaInformationResolver->currentSource().fileName(); + + QTableWidgetItem *titleItem = new QTableWidgetItem(title); + titleItem->setFlags(titleItem->flags() ^ Qt::ItemIsEditable); + QTableWidgetItem *artistItem = new QTableWidgetItem(metaData.value("ARTIST")); + artistItem->setFlags(artistItem->flags() ^ Qt::ItemIsEditable); + QTableWidgetItem *albumItem = new QTableWidgetItem(metaData.value("ALBUM")); + albumItem->setFlags(albumItem->flags() ^ Qt::ItemIsEditable); + QTableWidgetItem *yearItem = new QTableWidgetItem(metaData.value("DATE")); + yearItem->setFlags(yearItem->flags() ^ Qt::ItemIsEditable); +//![14] + + int currentRow = musicTable->rowCount(); + musicTable->insertRow(currentRow); + musicTable->setItem(currentRow, 0, titleItem); + musicTable->setItem(currentRow, 1, artistItem); + musicTable->setItem(currentRow, 2, albumItem); + musicTable->setItem(currentRow, 3, yearItem); + +//![15] + if (musicTable->selectedItems().isEmpty()) { + musicTable->selectRow(0); + mediaObject->setCurrentSource(metaInformationResolver->currentSource()); + } + + Phonon::MediaSource source = metaInformationResolver->currentSource(); + int index = sources.indexOf(metaInformationResolver->currentSource()) + 1; + if (sources.size() > index) { + metaInformationResolver->setCurrentSource(sources.at(index)); + } + else { + musicTable->resizeColumnsToContents(); + if (musicTable->columnWidth(0) > 300) + musicTable->setColumnWidth(0, 300); + } +} +//![15] + +//![16] +void MainWindow::aboutToFinish() +{ + int index = sources.indexOf(mediaObject->currentSource()) + 1; + if (sources.size() > index) { + mediaObject->enqueue(sources.at(index)); + } +} +//![16] + +void MainWindow::setupActions() +{ + playAction = new QAction(style()->standardIcon(QStyle::SP_MediaPlay), tr("Play"), this); + playAction->setShortcut(tr("Crl+P")); + playAction->setDisabled(true); + pauseAction = new QAction(style()->standardIcon(QStyle::SP_MediaPause), tr("Pause"), this); + pauseAction->setShortcut(tr("Ctrl+A")); + pauseAction->setDisabled(true); + stopAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop), tr("Stop"), this); + stopAction->setShortcut(tr("Ctrl+S")); + stopAction->setDisabled(true); + nextAction = new QAction(style()->standardIcon(QStyle::SP_MediaSkipForward), tr("Next"), this); + nextAction->setShortcut(tr("Ctrl+N")); + previousAction = new QAction(style()->standardIcon(QStyle::SP_MediaSkipBackward), tr("Previous"), this); + previousAction->setShortcut(tr("Ctrl+R")); + addFilesAction = new QAction(tr("Add &Files"), this); + addFilesAction->setShortcut(tr("Ctrl+F")); + exitAction = new QAction(tr("E&xit"), this); + exitAction->setShortcuts(QKeySequence::Quit); + aboutAction = new QAction(tr("A&bout"), this); + aboutAction->setShortcut(tr("Ctrl+B")); + aboutQtAction = new QAction(tr("About &Qt"), this); + aboutQtAction->setShortcut(tr("Ctrl+Q")); + +//![5] + connect(playAction, SIGNAL(triggered()), mediaObject, SLOT(play())); + connect(pauseAction, SIGNAL(triggered()), mediaObject, SLOT(pause()) ); + connect(stopAction, SIGNAL(triggered()), mediaObject, SLOT(stop())); +//![5] + connect(addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles())); + connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); + connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} + +void MainWindow::setupMenus() +{ + QMenu *fileMenu = menuBar()->addMenu(tr("&File")); + fileMenu->addAction(addFilesAction); + fileMenu->addSeparator(); + fileMenu->addAction(exitAction); + + QMenu *aboutMenu = menuBar()->addMenu(tr("&Help")); + aboutMenu->addAction(aboutAction); + aboutMenu->addAction(aboutQtAction); +} + +//![3] +void MainWindow::setupUi() +{ +//![3] + QToolBar *bar = new QToolBar; + + bar->addAction(playAction); + bar->addAction(pauseAction); + bar->addAction(stopAction); + +//![4] + seekSlider = new Phonon::SeekSlider(this); + seekSlider->setMediaObject(mediaObject); + + volumeSlider = new Phonon::VolumeSlider(this); + volumeSlider->setAudioOutput(audioOutput); +//![4] + volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + + QLabel *volumeLabel = new QLabel; + volumeLabel->setPixmap(QPixmap("images/volume.png")); + + QPalette palette; + palette.setBrush(QPalette::Light, Qt::darkGray); + + timeLcd = new QLCDNumber; + timeLcd->setPalette(palette); + + QStringList headers; + headers << tr("Title") << tr("Artist") << tr("Album") << tr("Year"); + + musicTable = new QTableWidget(0, 4); + musicTable->setHorizontalHeaderLabels(headers); + musicTable->setSelectionMode(QAbstractItemView::SingleSelection); + musicTable->setSelectionBehavior(QAbstractItemView::SelectRows); + connect(musicTable, SIGNAL(cellPressed(int, int)), + this, SLOT(tableClicked(int, int))); + + QHBoxLayout *seekerLayout = new QHBoxLayout; + seekerLayout->addWidget(seekSlider); + seekerLayout->addWidget(timeLcd); + + QHBoxLayout *playbackLayout = new QHBoxLayout; + playbackLayout->addWidget(bar); + playbackLayout->addStretch(); + playbackLayout->addWidget(volumeLabel); + playbackLayout->addWidget(volumeSlider); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(musicTable); + mainLayout->addLayout(seekerLayout); + mainLayout->addLayout(playbackLayout); + + QWidget *widget = new QWidget; + widget->setLayout(mainLayout); + + setCentralWidget(widget); + setWindowTitle("Phonon Music Player"); +} + diff --git a/examples/phonon/qmusicplayer/mainwindow.h b/examples/phonon/qmusicplayer/mainwindow.h new file mode 100644 index 0000000..41f8147 --- /dev/null +++ b/examples/phonon/qmusicplayer/mainwindow.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QAction; +class QTableWidget; +class QLCDNumber; +QT_END_NAMESPACE + +//![0] + +class MainWindow : public QMainWindow +{ +//![0] + Q_OBJECT + +public: + MainWindow(); + + QSize sizeHint() const { + return QSize(500, 300); + } + +private slots: + void addFiles(); + void about(); +//![1] + void stateChanged(Phonon::State newState, Phonon::State oldState); + void tick(qint64 time); + void sourceChanged(const Phonon::MediaSource &source); + void metaStateChanged(Phonon::State newState, Phonon::State oldState); + void aboutToFinish(); + void tableClicked(int row, int column); +//![1] + +private: + void setupActions(); + void setupMenus(); + void setupUi(); + +//![2] + Phonon::SeekSlider *seekSlider; + Phonon::MediaObject *mediaObject; + Phonon::MediaObject *metaInformationResolver; + Phonon::AudioOutput *audioOutput; + Phonon::VolumeSlider *volumeSlider; + QList sources; +//![2] + + QAction *playAction; + QAction *pauseAction; + QAction *stopAction; + QAction *nextAction; + QAction *previousAction; + QAction *addFilesAction; + QAction *exitAction; + QAction *aboutAction; + QAction *aboutQtAction; + QLCDNumber *timeLcd; + QTableWidget *musicTable; +}; + +#endif diff --git a/examples/phonon/qmusicplayer/qmusicplayer.pro b/examples/phonon/qmusicplayer/qmusicplayer.pro new file mode 100644 index 0000000..25ab7eb --- /dev/null +++ b/examples/phonon/qmusicplayer/qmusicplayer.pro @@ -0,0 +1,17 @@ +QT += phonon + +HEADERS += mainwindow.h +SOURCES += main.cpp \ + mainwindow.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/phonon/qmusicplayer +sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png images +sources.path = $$[QT_INSTALL_EXAMPLES]/phonon/qmusicplayer +INSTALLS += target sources + +wince*{ +DEPLOYMENT_PLUGIN += phonon_ds9 phonon_waveout +} + +symbian:TARGET.UID3 = 0xA000CF6A -- cgit v0.12