~ubuntu-branches/ubuntu/gutsy/kde4libs/gutsy

« back to all changes in this revision

Viewing changes to khtml/ecma/kjs_audio.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-02-21 11:00:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070221110012-6kw8khr9knv6lmg1
Tags: 3.80.3-0ubuntu1
New upstream unstable release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  This file is part of the KDE libraries
 
3
 *  Copyright (C) 2006 Germain Garand <germain@ebooksfrance.org>
 
4
 *
 
5
 *  This library is free software; you can redistribute it and/or
 
6
 *  modify it under the terms of the GNU Lesser General Public
 
7
 *  License as published by the Free Software Foundation; either
 
8
 *  version 2 of the License, or (at your option) any later version.
 
9
 *
 
10
 *  This library is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 *  Lesser General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU Lesser General Public
 
16
 *  License along with this library; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#ifndef KJS_AUDIO_H
 
21
#define KJS_AUDIO_H
 
22
 
 
23
#include "ecma/kjs_dom.h"
 
24
#include "ecma/kjs_binding.h"
 
25
#include <kjs/object.h>
 
26
#include <QPointer>
 
27
#include <phonon/phononnamespace.h>
 
28
 
 
29
#include "misc/loader.h"
 
30
 
 
31
namespace Phonon {
 
32
    class ByteStream;
 
33
    class AudioPath;
 
34
    class AudioOutput;
 
35
}
 
36
 
 
37
namespace KJS {
 
38
 
 
39
  class AudioConstructorImp : public ObjectImp {
 
40
  public:
 
41
    AudioConstructorImp(ExecState *exec, DOM::DocumentImpl* d);
 
42
    virtual bool implementsConstruct() const;
 
43
    virtual ObjectImp* construct(ExecState *exec, const List &args);
 
44
  private:
 
45
    SharedPtr<DOM::DocumentImpl> doc;
 
46
  };
 
47
 
 
48
  ////////////////////// Audio Object ////////////////////////
 
49
 
 
50
  class JSEventListener;
 
51
  class AudioQObject;
 
52
 
 
53
  class Audio : public DOMObject, private khtml::CachedObjectClient {
 
54
  public:
 
55
    Audio(ExecState *, DOM::DocumentImpl* d, const QString& url);
 
56
    virtual ~Audio();
 
57
 
 
58
    bool getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot);
 
59
    ValueImp *getValueProperty(ExecState *exec, int token) const;
 
60
    virtual void put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr = None);
 
61
    void putValueProperty(ExecState *exec, int token, ValueImp *value, int /*attr*/);
 
62
    virtual bool toBoolean(ExecState *) const { return true; }
 
63
    virtual const ClassInfo* classInfo() const { return &info; }
 
64
    static const ClassInfo info;
 
65
    enum { Onload, Onerror, Loop, Play, Stop };
 
66
 
 
67
    void play();
 
68
    void stop();
 
69
    void loop(int n=-1);
 
70
 
 
71
  private:
 
72
    friend class AudioProtoFunc;
 
73
    friend class AudioQObject;
 
74
 
 
75
    // from CachedObjectClient
 
76
    virtual void notifyFinished(khtml::CachedObject *);
 
77
    virtual void error(int err, const QString &text);
 
78
 
 
79
    void refLoader();
 
80
 
 
81
    QString m_url;
 
82
    QPointer<DOM::DocumentImpl> m_doc;
 
83
    khtml::CachedSound* m_cs;
 
84
 
 
85
    AudioQObject* m_qObj;
 
86
 
 
87
    JSEventListener *m_onLoadListener;
 
88
    JSEventListener *m_onErrorListener;
 
89
  };
 
90
 
 
91
  // Needs a separate class as QObjects confuse the hell out of
 
92
  // KJS's garbage collector
 
93
  class AudioQObject: public QObject {
 
94
      Q_OBJECT
 
95
  public:
 
96
      AudioQObject(Audio* jObj);
 
97
      virtual ~AudioQObject();
 
98
 
 
99
      void setSound( const QByteArray& s ) { m_sound = s; }
 
100
      void setupPlayer();
 
101
 
 
102
      void play();
 
103
      void stop();
 
104
      void loop(int n=-1);
 
105
 
 
106
  protected Q_SLOTS:
 
107
    void nextIteration();
 
108
    void refLoader();
 
109
    void finished();
 
110
    void slotStateChanged(Phonon::State newstate, Phonon::State oldstate);
 
111
    
 
112
  protected:
 
113
    void reset();
 
114
 
 
115
  private:
 
116
    Audio* m_jObj;
 
117
 
 
118
    Phonon::ByteStream*  m_media;
 
119
    QByteArray m_sound;
 
120
    int m_playCount;
 
121
    bool m_stopping;
 
122
 
 
123
    static Phonon::AudioPath*   s_audioPath;
 
124
    static Phonon::AudioOutput* s_audioOutput;
 
125
    static int s_refs;
 
126
};
 
127
 
 
128
} // namespace KJS
 
129
 
 
130
#endif