~ubuntu-branches/ubuntu/quantal/qtmobility/quantal

« back to all changes in this revision

Viewing changes to plugins/feedback/mmk/qfeedback.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-16 16:18:07 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20101116161807-k2dzt2nyse975r3l
Tags: 1.1.0-0ubuntu1
* New upstream release
* Syncronise with Debian, no remaining changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2010 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 Mobility Components.
 
8
**
 
9
** $QT_BEGIN_LICENSE:LGPL$
 
10
** Commercial Usage
 
11
** Licensees holding valid Qt Commercial licenses may use this file in 
 
12
** accordance with the Qt Commercial License Agreement provided with
 
13
** the Software or, alternatively, in accordance with the terms
 
14
** contained in a written agreement between you and Nokia.
 
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
** GNU General Public License Usage
 
29
** Alternatively, this file may be used under the terms of the GNU
 
30
** General Public License version 3.0 as published by the Free Software
 
31
** Foundation and appearing in the file LICENSE.GPL included in the
 
32
** packaging of this file.  Please review the following information to
 
33
** ensure the GNU General Public License version 3.0 requirements will be
 
34
** met: http://www.gnu.org/copyleft/gpl.html.
 
35
**
 
36
** If you are unsure which license is appropriate for your use, please
 
37
** contact the sales department at qt-sales@nokia.com.
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include <QtCore/QtPlugin>
 
43
#include <QtCore/QCoreApplication>
 
44
 
 
45
#include <QDebug>
 
46
#include "qfeedback.h"
 
47
 
 
48
Q_EXPORT_PLUGIN2(feedback_mmk, QFeedbackMMK)
 
49
 
 
50
QFeedbackMMK::QFeedbackMMK() : QObject(qApp)
 
51
{
 
52
}
 
53
 
 
54
QFeedbackMMK::~QFeedbackMMK()
 
55
{
 
56
    foreach(FeedbackInfo fi, mEffects.values()) {
 
57
        delete fi.soundEffect;
 
58
    }
 
59
}
 
60
 
 
61
void QFeedbackMMK::setLoaded(QFeedbackFileEffect *effect, bool load)
 
62
{
 
63
    if (!effect)
 
64
        return;
 
65
 
 
66
    // See if we have seen this effect before
 
67
    FeedbackInfo fi = mEffects.value(effect);
 
68
 
 
69
    if (load) {
 
70
        // Well.. we might already have an effect, since we don't create them until
 
71
        // we load...
 
72
        if (fi.loaded) {
 
73
            // We've already loaded?
 
74
            return;
 
75
        } else {
 
76
            if (fi.soundEffect) {
 
77
                // We've started a load, they must just be impatient
 
78
                // Pushing this elevator button does nothing..
 
79
                return;
 
80
            } else {
 
81
                // New sound effect!
 
82
                fi.soundEffect = new QSoundEffect(this);
 
83
                connect(fi.soundEffect, SIGNAL(loadedChanged()), this, SLOT(soundEffectLoaded()));
 
84
                fi.soundEffect->setSource(effect->source());
 
85
                mEffects.insert(effect, fi);
 
86
                mEffectMap.insert(fi.soundEffect, effect);
 
87
            }
 
88
        }
 
89
    } else {
 
90
        // Time to unload.
 
91
        if (fi.soundEffect) {
 
92
            mEffectMap.remove(fi.soundEffect);
 
93
            delete fi.soundEffect;
 
94
        }
 
95
        mEffects.remove(effect);
 
96
    }
 
97
}
 
98
 
 
99
void QFeedbackMMK::setEffectState(QFeedbackFileEffect *effect, QFeedbackEffect::State state)
 
100
{
 
101
    FeedbackInfo fi = mEffects.value(effect);
 
102
    switch (state)
 
103
    {
 
104
        case QFeedbackEffect::Stopped:
 
105
            if (fi.playing) {
 
106
                Q_ASSERT(fi.soundEffect);
 
107
                fi.soundEffect->stop();
 
108
                fi.playing = false;
 
109
            }
 
110
            break;
 
111
 
 
112
        case QFeedbackEffect::Paused:
 
113
            // Well, we can't pause, really
 
114
            reportError(effect, QFeedbackEffect::UnknownError);
 
115
            break;
 
116
 
 
117
        case QFeedbackEffect::Running:
 
118
            if (fi.playing) {
 
119
                // We're already playing.
 
120
            } else if (fi.soundEffect){
 
121
                fi.soundEffect->play();
 
122
                fi.playing = true;
 
123
            }
 
124
            break;
 
125
        default:
 
126
            break;
 
127
    }
 
128
}
 
129
 
 
130
QFeedbackEffect::State QFeedbackMMK::effectState(const QFeedbackFileEffect *effect)
 
131
{
 
132
    FeedbackInfo fi = mEffects.value(effect);
 
133
 
 
134
    if (fi.soundEffect) {
 
135
        if (fi.playing)
 
136
            return QFeedbackEffect::Running;
 
137
        if (fi.loaded)
 
138
            return QFeedbackEffect::Stopped; // No idle?
 
139
        return QFeedbackEffect::Loading;
 
140
    }
 
141
    return QFeedbackEffect::Stopped;
 
142
}
 
143
 
 
144
int QFeedbackMMK::effectDuration(const QFeedbackFileEffect *effect)
 
145
{
 
146
    Q_UNUSED(effect);
 
147
    // XXX This isn't supported by MMK currently
 
148
    return 0;
 
149
}
 
150
 
 
151
QStringList QFeedbackMMK::supportedMimeTypes()
 
152
{
 
153
    return QSoundEffect::supportedMimeTypes();
 
154
}
 
155
 
 
156
void QFeedbackMMK::soundEffectLoaded()
 
157
{
 
158
    QSoundEffect* se = qobject_cast<QSoundEffect*>(sender());
 
159
    if (se) {
 
160
        // Hmm, now look up the right sound effect
 
161
        QFeedbackFileEffect* fe = mEffectMap.value(se);
 
162
 
 
163
        if (fe) {
 
164
            reportLoadFinished(fe, se->isLoaded());
 
165
        }
 
166
    }
 
167
}