0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the Qt Designer of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include "videoplayertaskmenu.h"
|
|
43 |
|
|
44 |
#include <QtDesigner/QDesignerFormWindowInterface>
|
|
45 |
#include <QtDesigner/QDesignerFormWindowCursorInterface>
|
|
46 |
#include <QtDesigner/QDesignerFormEditorInterface>
|
|
47 |
#include <QtDesigner/QExtensionManager>
|
|
48 |
|
|
49 |
#include <phonon/videoplayer.h>
|
|
50 |
#include <phonon/mediaobject.h>
|
|
51 |
|
|
52 |
#include <QtGui/QPlainTextEdit>
|
|
53 |
#include <QtGui/QDialogButtonBox>
|
|
54 |
#include <QtGui/QAction>
|
|
55 |
#include <QtGui/QVBoxLayout>
|
|
56 |
#include <QtGui/QFileDialog>
|
|
57 |
#include <QtGui/QMessageBox>
|
|
58 |
|
|
59 |
QT_BEGIN_NAMESPACE
|
|
60 |
|
|
61 |
// ----------------- MimeTypeDialog: Display mime types in scrollable text
|
|
62 |
|
|
63 |
class MimeTypeDialog : public QDialog {
|
|
64 |
Q_DISABLE_COPY(MimeTypeDialog)
|
|
65 |
public:
|
|
66 |
explicit MimeTypeDialog(QWidget *parent = 0);
|
|
67 |
|
|
68 |
void setMimeTypes(const QStringList &);
|
|
69 |
|
|
70 |
private:
|
|
71 |
QPlainTextEdit *m_plainTextEdit;
|
|
72 |
};
|
|
73 |
|
|
74 |
MimeTypeDialog::MimeTypeDialog(QWidget *parent) :
|
|
75 |
QDialog(parent),
|
|
76 |
m_plainTextEdit(new QPlainTextEdit)
|
|
77 |
{
|
|
78 |
setModal(true);
|
|
79 |
setWindowTitle(VideoPlayerTaskMenu::tr("Available Mime Types"));
|
|
80 |
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
81 |
|
|
82 |
QVBoxLayout *layout = new QVBoxLayout;
|
|
83 |
m_plainTextEdit->setReadOnly(true);
|
|
84 |
layout->addWidget(m_plainTextEdit);
|
|
85 |
|
|
86 |
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
|
|
87 |
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
|
88 |
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
|
89 |
layout->addWidget(buttonBox);
|
|
90 |
|
|
91 |
setLayout(layout);
|
|
92 |
}
|
|
93 |
|
|
94 |
void MimeTypeDialog::setMimeTypes(const QStringList &l)
|
|
95 |
{
|
|
96 |
m_plainTextEdit->setPlainText(l.join(QString(1, QLatin1Char('\n'))));
|
|
97 |
}
|
|
98 |
|
|
99 |
// ----------------- VideoPlayerTaskMenu
|
|
100 |
VideoPlayerTaskMenu::VideoPlayerTaskMenu(Phonon::VideoPlayer *object, QObject *parent) :
|
|
101 |
QObject(parent),
|
|
102 |
m_widget(object),
|
|
103 |
m_displayMimeTypesAction(new QAction(tr("Display supported mime types..."), this)),
|
|
104 |
m_loadAction(new QAction(tr("Load..."), this)),
|
|
105 |
m_playAction(new QAction(tr("Play"), this)),
|
|
106 |
m_pauseAction(new QAction(tr("Pause"), this)),
|
|
107 |
m_stopAction(new QAction(tr("Stop"), this))
|
|
108 |
{
|
|
109 |
m_taskActions << m_displayMimeTypesAction << m_loadAction << m_playAction << m_pauseAction << m_stopAction;
|
|
110 |
|
|
111 |
connect(m_widget->mediaObject(), SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(mediaObjectStateChanged(Phonon::State,Phonon::State)));
|
|
112 |
connect(m_displayMimeTypesAction, SIGNAL(triggered()), this, SLOT(slotMimeTypes()));
|
|
113 |
connect(m_loadAction, SIGNAL(triggered()), this, SLOT(slotLoad()));
|
|
114 |
connect(m_playAction, SIGNAL(triggered()), object, SLOT(play()));
|
|
115 |
connect(m_pauseAction, SIGNAL(triggered()), object, SLOT(pause()));
|
|
116 |
connect(m_stopAction, SIGNAL(triggered()), object, SLOT(stop()));
|
|
117 |
}
|
|
118 |
|
|
119 |
QList<QAction*> VideoPlayerTaskMenu::taskActions() const
|
|
120 |
{
|
|
121 |
const bool isPlaying = m_widget->isPlaying();
|
|
122 |
const bool isPaused = m_widget->isPlaying();
|
|
123 |
m_loadAction->setEnabled(!isPlaying && !isPaused);
|
|
124 |
m_playAction->setEnabled(!isPlaying);
|
|
125 |
m_pauseAction->setEnabled(isPlaying);
|
|
126 |
m_stopAction->setEnabled(isPlaying || isPaused);
|
|
127 |
return m_taskActions;
|
|
128 |
}
|
|
129 |
|
|
130 |
void VideoPlayerTaskMenu::slotMimeTypes()
|
|
131 |
{
|
|
132 |
MimeTypeDialog mimeTypeDialog(m_widget->window());
|
|
133 |
mimeTypeDialog.setMimeTypes(Phonon::BackendCapabilities::availableMimeTypes());
|
|
134 |
mimeTypeDialog.exec();
|
|
135 |
}
|
|
136 |
|
|
137 |
void VideoPlayerTaskMenu::slotLoad()
|
|
138 |
{
|
|
139 |
const QString fileName = QFileDialog::getOpenFileName(m_widget->window(), tr("Choose Video Player Media Source"));
|
|
140 |
if (fileName.isEmpty())
|
|
141 |
return;
|
|
142 |
m_widget->load(Phonon::MediaSource(fileName));
|
|
143 |
|
|
144 |
}
|
|
145 |
|
|
146 |
void VideoPlayerTaskMenu::mediaObjectStateChanged(Phonon::State newstate, Phonon::State /* oldstate */)
|
|
147 |
{
|
|
148 |
if (newstate == Phonon::ErrorState) {
|
|
149 |
const QString msg = tr("An error has occurred in '%1': %2").arg(m_widget->objectName(), m_widget->mediaObject()->errorString());
|
|
150 |
QMessageBox::warning(m_widget->window(), tr("Video Player Error"), msg);
|
|
151 |
}
|
|
152 |
}
|
|
153 |
|
|
154 |
QT_END_NAMESPACE
|