~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to kaboodle/engine.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
 
 
3
Copyright (c) 2000-2001 the noatun authors. See file AUTHORS.
 
4
 
 
5
Permission is hereby granted, free of charge, to any person obtaining a copy
 
6
of this software and associated documentation files (the "Software"), to deal
 
7
in the Software without restriction, including without limitation the rights
 
8
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
9
copies of the Software, and to permit persons to whom the Software is
 
10
furnished to do so, subject to the following conditions:
 
11
 
 
12
The above copyright notice and this permission notice shall be included in
 
13
all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
18
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIAB\ILITY, WHETHER IN
 
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
21
 
 
22
******************************************************************/
 
23
 
 
24
extern "C"
 
25
{
 
26
#include <sys/wait.h>
 
27
}
 
28
 
 
29
#include <kconfig.h>
 
30
#include <kdebug.h>
 
31
#include <klocale.h>
 
32
#include <kmessagebox.h>
 
33
#include <kmimetype.h>
 
34
#include <kstandarddirs.h>
 
35
#include <kurl.h>
 
36
#include <qtimer.h>
 
37
#include <qfile.h>
 
38
#include <qdir.h>
 
39
 
 
40
#include <connect.h>
 
41
#include <dynamicrequest.h>
 
42
#include <flowsystem.h>
 
43
#include <kartsdispatcher.h>
 
44
#include <kartsserver.h>
 
45
#include <kplayobjectfactory.h>
 
46
#include <soundserver.h>
 
47
 
 
48
#include "engine.h"
 
49
#include <string.h>
 
50
 
 
51
using namespace std;
 
52
 
 
53
class Kaboodle::Engine::EnginePrivate
 
54
{
 
55
public:
 
56
        EnginePrivate()
 
57
                : playobj(0)
 
58
                , dispatcher()
 
59
                , server()
 
60
        {
 
61
        }
 
62
        
 
63
        ~EnginePrivate()
 
64
        {
 
65
                delete playobj;
 
66
        }
 
67
 
 
68
        KDE::PlayObject *playobj;
 
69
        KArtsDispatcher dispatcher;
 
70
        KArtsServer server;
 
71
        KURL file;
 
72
};
 
73
 
 
74
Kaboodle::Engine::Engine(QObject *parent)
 
75
        : QObject(parent)
 
76
        , d(new EnginePrivate)
 
77
{
 
78
}
 
79
 
 
80
Kaboodle::Engine::~Engine()
 
81
{
 
82
        stop();
 
83
        delete d;
 
84
}
 
85
 
 
86
bool Kaboodle::Engine::load(const KURL &file)
 
87
{
 
88
        if(file.path().length())
 
89
        {
 
90
                d->file = file;
 
91
                return reload();
 
92
        }
 
93
        else return false;
 
94
}
 
95
 
 
96
bool Kaboodle::Engine::reload(void)
 
97
{
 
98
        // Only You can prevent memory leaks
 
99
        delete d->playobj;
 
100
        d->playobj = 0;
 
101
 
 
102
        KDE::PlayObjectFactory factory(d->server.server());
 
103
        d->playobj = factory.createPlayObject(d->file, true);
 
104
        
 
105
        needReload = false;
 
106
 
 
107
        return !d->playobj->isNull();
 
108
}
 
109
 
 
110
void Kaboodle::Engine::play()
 
111
{
 
112
        if(d->playobj)
 
113
        {
 
114
                switch(d->playobj->state())
 
115
                {
 
116
                case Arts::posIdle:
 
117
                        if(needReload)
 
118
                                reload();
 
119
                        d->playobj->play();
 
120
                        break;
 
121
                case Arts::posPaused:
 
122
                        d->playobj->play();
 
123
                        break;
 
124
                default:
 
125
                        break;
 
126
                }
 
127
        }
 
128
}
 
129
 
 
130
void Kaboodle::Engine::pause()
 
131
{
 
132
        if(d->playobj && !d->playobj->isNull())
 
133
                d->playobj->pause();
 
134
}
 
135
 
 
136
void Kaboodle::Engine::stop()
 
137
{
 
138
        if(d->playobj && !d->playobj->isNull())
 
139
        {
 
140
                d->playobj->halt();
 
141
                needReload = true;
 
142
        }
 
143
}
 
144
 
 
145
// pass time in msecs
 
146
void Kaboodle::Engine::seek(unsigned long msec)
 
147
{
 
148
        Arts::poTime t;
 
149
 
 
150
        t.ms = (long) msec % 1000;
 
151
        t.seconds = (long) ((long)msec - t.ms) / 1000;
 
152
 
 
153
        if(d->playobj && !d->playobj->isNull())
 
154
                d->playobj->seek(t);
 
155
}
 
156
 
 
157
// return position in milliseconds
 
158
long Kaboodle::Engine::position()
 
159
{
 
160
        if(!d->playobj || d->playobj->isNull()) return 0;
 
161
 
 
162
        Arts::poTime time(d->playobj->currentTime());
 
163
        return (time.ms + (time.seconds*1000));
 
164
}
 
165
 
 
166
// return track-length in milliseconds
 
167
unsigned long Kaboodle::Engine::length()
 
168
{
 
169
        if(!d->playobj || d->playobj->isNull()) return 0;
 
170
 
 
171
        Arts::poTime time(d->playobj->overallTime());
 
172
        return (time.ms + (time.seconds*1000));
 
173
}
 
174
 
 
175
KMediaPlayer::Player::State Kaboodle::Engine::state()
 
176
{
 
177
        if(!d->playobj || d->playobj->isNull()) return KMediaPlayer::Player::Empty;
 
178
 
 
179
        switch(d->playobj->state())
 
180
        {
 
181
        case Arts::posIdle:
 
182
                return KMediaPlayer::Player::Stop;
 
183
                break;
 
184
        case Arts::posPlaying:
 
185
                return KMediaPlayer::Player::Play;
 
186
                break;
 
187
        case Arts::posPaused:
 
188
                return KMediaPlayer::Player::Pause;
 
189
                break;
 
190
        default:
 
191
                return KMediaPlayer::Player::Stop;
 
192
                break;
 
193
        }
 
194
}
 
195
 
 
196
bool Kaboodle::Engine::seekable(void)
 
197
{
 
198
        if(!d->playobj || d->playobj->isNull()) return false;
 
199
        return d->playobj->capabilities() & Arts::capSeek;
 
200
}
 
201
 
 
202
Arts::PlayObject Kaboodle::Engine::playObject() const
 
203
{
 
204
        return d->playobj ? d->playobj->object() : Arts::PlayObject::null();
 
205
}
 
206
 
 
207
#include "engine.moc"