summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-03-18 01:50:17 (UTC)
committer llornkcor <llornkcor>2002-03-18 01:50:17 (UTC)
commitc09cb25eb6bbf31bed0d4a415802469cfd1efedf (patch) (unidiff)
tree86ced0fa482bd5fb244629f2baa1b1a4f25c9189
parent848182342d81b4e6ab4ce6b75bdaa0b109828af3 (diff)
downloadopie-c09cb25eb6bbf31bed0d4a415802469cfd1efedf.zip
opie-c09cb25eb6bbf31bed0d4a415802469cfd1efedf.tar.gz
opie-c09cb25eb6bbf31bed0d4a415802469cfd1efedf.tar.bz2
added stuff and fixed stuff that I dont remember- plays w/o going to playlist among other things
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/audiodevice.cpp2
-rw-r--r--core/multimedia/opieplayer/audiowidget.cpp142
-rw-r--r--core/multimedia/opieplayer/audiowidget.h45
-rw-r--r--core/multimedia/opieplayer/loopcontrol.cpp29
-rw-r--r--core/multimedia/opieplayer/playlistselection.cpp9
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp212
-rw-r--r--core/multimedia/opieplayer/playlistwidget.h17
-rw-r--r--core/multimedia/opieplayer/videowidget.cpp110
-rw-r--r--core/multimedia/opieplayer/videowidget.h3
9 files changed, 356 insertions, 213 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp
index 5fef792..2087c7f 100644
--- a/core/multimedia/opieplayer/audiodevice.cpp
+++ b/core/multimedia/opieplayer/audiodevice.cpp
@@ -1,371 +1,369 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20// L.J.Potter added better error code Fri 02-15-2002 14:37:47 20// L.J.Potter added better error code Fri 02-15-2002 14:37:47
21 21
22#include <stdlib.h> 22#include <stdlib.h>
23#include <stdio.h> 23#include <stdio.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25#include <qpe/config.h> 25#include <qpe/config.h>
26#include "audiodevice.h" 26#include "audiodevice.h"
27 27
28#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 28#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
29#include "qpe/qcopenvelope_qws.h" 29#include "qpe/qcopenvelope_qws.h"
30#endif 30#endif
31 31
32#ifdef Q_WS_WIN 32#ifdef Q_WS_WIN
33#include <windows.h> 33#include <windows.h>
34#include <mmsystem.h> 34#include <mmsystem.h>
35#include <mmreg.h> 35#include <mmreg.h>
36#endif 36#endif
37 37
38#if defined(Q_WS_X11) || defined(Q_WS_QWS) 38#if defined(Q_WS_X11) || defined(Q_WS_QWS)
39#include <fcntl.h> 39#include <fcntl.h>
40#include <sys/ioctl.h> 40#include <sys/ioctl.h>
41#include <sys/soundcard.h> 41#include <sys/soundcard.h>
42#include <sys/stat.h> 42#include <sys/stat.h>
43#include <sys/time.h> 43#include <sys/time.h>
44#include <sys/types.h> 44#include <sys/types.h>
45#include <unistd.h> 45#include <unistd.h>
46#endif 46#endif
47 47
48#if defined(Q_OS_WIN32) 48#if defined(Q_OS_WIN32)
49static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000; 49static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000;
50static const int timerResolutionMilliSeconds = 30; 50static const int timerResolutionMilliSeconds = 30;
51static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond; 51static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond;
52#else 52#else
53# if defined(QT_QWS_IPAQ) 53# if defined(QT_QWS_IPAQ)
54static const int sound_fragment_shift = 14; 54static const int sound_fragment_shift = 14;
55# else 55# else
56static const int sound_fragment_shift = 16; 56static const int sound_fragment_shift = 16;
57# endif 57# endif
58static const int sound_fragment_bytes = (1<<sound_fragment_shift); 58static const int sound_fragment_bytes = (1<<sound_fragment_shift);
59#endif 59#endif
60 60
61 61
62class AudioDevicePrivate { 62class AudioDevicePrivate {
63public: 63public:
64 int handle; 64 int handle;
65 unsigned int frequency; 65 unsigned int frequency;
66 unsigned int channels; 66 unsigned int channels;
67 unsigned int bytesPerSample; 67 unsigned int bytesPerSample;
68 unsigned int bufferSize; 68 unsigned int bufferSize;
69#ifndef Q_OS_WIN32 69#ifndef Q_OS_WIN32
70 bool can_GETOSPACE; 70 bool can_GETOSPACE;
71 char* unwrittenBuffer; 71 char* unwrittenBuffer;
72 unsigned int unwritten; 72 unsigned int unwritten;
73#endif 73#endif
74 74
75 static int dspFd; 75 static int dspFd;
76 static bool muted; 76 static bool muted;
77 static unsigned int leftVolume; 77 static unsigned int leftVolume;
78 static unsigned int rightVolume; 78 static unsigned int rightVolume;
79}; 79};
80 80
81 81
82#ifdef Q_WS_QWS 82#ifdef Q_WS_QWS
83// This is for keeping the device open in-between playing files when 83// This is for keeping the device open in-between playing files when
84// the device makes clicks and it starts to drive you insane! :) 84// the device makes clicks and it starts to drive you insane! :)
85// Best to have the device not open when not using it though 85// Best to have the device not open when not using it though
86//#define KEEP_DEVICE_OPEN 86//#define KEEP_DEVICE_OPEN
87#endif 87#endif
88 88
89 89
90int AudioDevicePrivate::dspFd = 0; 90int AudioDevicePrivate::dspFd = 0;
91bool AudioDevicePrivate::muted = FALSE; 91bool AudioDevicePrivate::muted = FALSE;
92unsigned int AudioDevicePrivate::leftVolume = 0; 92unsigned int AudioDevicePrivate::leftVolume = 0;
93unsigned int AudioDevicePrivate::rightVolume = 0; 93unsigned int AudioDevicePrivate::rightVolume = 0;
94 94
95 95
96void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { 96void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) {
97 muted = AudioDevicePrivate::muted; 97 muted = AudioDevicePrivate::muted;
98 unsigned int volume; 98 unsigned int volume;
99#ifdef Q_OS_WIN32 99#ifdef Q_OS_WIN32
100 HWAVEOUT handle; 100 HWAVEOUT handle;
101 WAVEFORMATEX formatData; 101 WAVEFORMATEX formatData;
102 formatData.cbSize = sizeof(WAVEFORMATEX); 102 formatData.cbSize = sizeof(WAVEFORMATEX);
103 formatData.wFormatTag = WAVE_FORMAT_PCM; 103 formatData.wFormatTag = WAVE_FORMAT_PCM;
104 formatData.nAvgBytesPerSec = 4 * 44000; 104 formatData.nAvgBytesPerSec = 4 * 44000;
105 formatData.nBlockAlign = 4; 105 formatData.nBlockAlign = 4;
106 formatData.nChannels = 2; 106 formatData.nChannels = 2;
107 formatData.nSamplesPerSec = 44000; 107 formatData.nSamplesPerSec = 44000;
108 formatData.wBitsPerSample = 16; 108 formatData.wBitsPerSample = 16;
109 waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); 109 waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL);
110 if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) 110 if ( waveOutGetVolume( handle, (LPDWORD)&volume ) )
111// qDebug( "get volume of audio device failed" ); 111// qDebug( "get volume of audio device failed" );
112 waveOutClose( handle ); 112 waveOutClose( handle );
113 leftVolume = volume & 0xFFFF; 113 leftVolume = volume & 0xFFFF;
114 rightVolume = volume >> 16; 114 rightVolume = volume >> 16;
115#else 115#else
116 int mixerHandle = open( "/dev/mixer", O_RDWR ); 116 int mixerHandle = open( "/dev/mixer", O_RDWR );
117 if ( mixerHandle >= 0 ) { 117 if ( mixerHandle >= 0 ) {
118 if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) 118 if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1)
119 perror("ioctl(\"MIXER_READ\")"); 119 perror("ioctl(\"MIXER_READ\")");
120 close( mixerHandle ); 120 close( mixerHandle );
121 } else 121 } else
122 perror("open(\"/dev/mixer\")"); 122 perror("open(\"/dev/mixer\")");
123 leftVolume = ((volume & 0x00FF) << 16) / 101; 123 leftVolume = ((volume & 0x00FF) << 16) / 101;
124 rightVolume = ((volume & 0xFF00) << 8) / 101; 124 rightVolume = ((volume & 0xFF00) << 8) / 101;
125#endif 125#endif
126} 126}
127 127
128 128
129void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { 129void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) {
130 AudioDevicePrivate::muted = muted; 130 AudioDevicePrivate::muted = muted;
131 if ( muted ) { 131 if ( muted ) {
132 AudioDevicePrivate::leftVolume = leftVolume; 132 AudioDevicePrivate::leftVolume = leftVolume;
133 AudioDevicePrivate::rightVolume = rightVolume; 133 AudioDevicePrivate::rightVolume = rightVolume;
134 leftVolume = 0; 134 leftVolume = 0;
135 rightVolume = 0; 135 rightVolume = 0;
136 } else { 136 } else {
137 leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); 137 leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume );
138 rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); 138 rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume );
139 } 139 }
140#ifdef Q_OS_WIN32 140#ifdef Q_OS_WIN32
141 HWAVEOUT handle; 141 HWAVEOUT handle;
142 WAVEFORMATEX formatData; 142 WAVEFORMATEX formatData;
143 formatData.cbSize = sizeof(WAVEFORMATEX); 143 formatData.cbSize = sizeof(WAVEFORMATEX);
144 formatData.wFormatTag = WAVE_FORMAT_PCM; 144 formatData.wFormatTag = WAVE_FORMAT_PCM;
145 formatData.nAvgBytesPerSec = 4 * 44000; 145 formatData.nAvgBytesPerSec = 4 * 44000;
146 formatData.nBlockAlign = 4; 146 formatData.nBlockAlign = 4;
147 formatData.nChannels = 2; 147 formatData.nChannels = 2;
148 formatData.nSamplesPerSec = 44000; 148 formatData.nSamplesPerSec = 44000;
149 formatData.wBitsPerSample = 16; 149 formatData.wBitsPerSample = 16;
150 waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); 150 waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL);
151 unsigned int volume = (rightVolume << 16) | leftVolume; 151 unsigned int volume = (rightVolume << 16) | leftVolume;
152 if ( waveOutSetVolume( handle, volume ) ) 152 if ( waveOutSetVolume( handle, volume ) )
153// qDebug( "set volume of audio device failed" ); 153// qDebug( "set volume of audio device failed" );
154 waveOutClose( handle ); 154 waveOutClose( handle );
155#else 155#else
156 // Volume can be from 0 to 100 which is 101 distinct values 156 // Volume can be from 0 to 100 which is 101 distinct values
157 unsigned int rV = (rightVolume * 101) >> 16; 157 unsigned int rV = (rightVolume * 101) >> 16;
158 158
159# if 0 159# if 0
160 unsigned int lV = (leftVolume * 101) >> 16; 160 unsigned int lV = (leftVolume * 101) >> 16;
161 unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); 161 unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF);
162 int mixerHandle = 0; 162 int mixerHandle = 0;
163 if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 163 if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
164 if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) 164 if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1)
165 perror("ioctl(\"MIXER_WRITE\")"); 165 perror("ioctl(\"MIXER_WRITE\")");
166 close( mixerHandle ); 166 close( mixerHandle );
167 } else 167 } else
168 perror("open(\"/dev/mixer\")"); 168 perror("open(\"/dev/mixer\")");
169 169
170# else 170# else
171 // This is the way this has to be done now I guess, doesn't allow for 171 // This is the way this has to be done now I guess, doesn't allow for
172 // independant right and left channel setting, or setting for different outputs 172 // independant right and left channel setting, or setting for different outputs
173 Config cfg("Sound"); 173 Config cfg("Sound");
174 cfg.setGroup("System"); 174 cfg.setGroup("System");
175 cfg.writeEntry("Volume",(int)rV); 175 cfg.writeEntry("Volume",(int)rV);
176# endif 176# endif
177 177
178#endif 178#endif
179// qDebug( "setting volume to: 0x%x", volume ); 179// qDebug( "setting volume to: 0x%x", volume );
180#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 180#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
181 // Send notification that the volume has changed 181 // Send notification that the volume has changed
182 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; 182 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
183#endif 183#endif
184} 184}
185 185
186 186
187 187
188 188
189AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { 189AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
190 qDebug("creating new audio device"); 190 qDebug("creating new audio device");
191 d = new AudioDevicePrivate; 191 d = new AudioDevicePrivate;
192 d->frequency = f; 192 d->frequency = f;
193 d->channels = chs; 193 d->channels = chs;
194 d->bytesPerSample = bps; 194 d->bytesPerSample = bps;
195 qDebug("%d",bps); 195 qDebug("%d",bps);
196 int format=0; 196 int format=0;
197 if( bps == 8) format = AFMT_U8; 197 if( bps == 8) format = AFMT_U8;
198 else if( bps <= 0) format = AFMT_S16_LE; 198 else if( bps <= 0) format = AFMT_S16_LE;
199 else format = AFMT_S16_LE; 199 else format = AFMT_S16_LE;
200
201 qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); 200 qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format);
202 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); 201 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
203 202
204
205 int fragments = 0x10000 * 8 + sound_fragment_shift; 203 int fragments = 0x10000 * 8 + sound_fragment_shift;
206 int capabilities = 0; 204 int capabilities = 0;
207 205
208#ifdef KEEP_DEVICE_OPEN 206#ifdef KEEP_DEVICE_OPEN
209 if ( AudioDevicePrivate::dspFd == 0 ) { 207 if ( AudioDevicePrivate::dspFd == 0 ) {
210#endif 208#endif
211 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { 209 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) {
212 perror("open(\"/dev/dsp\") sending to /dev/null instead"); 210 perror("open(\"/dev/dsp\") sending to /dev/null instead");
213 d->handle = ::open( "/dev/null", O_WRONLY ); 211 d->handle = ::open( "/dev/null", O_WRONLY );
214 } 212 }
215#ifdef KEEP_DEVICE_OPEN 213#ifdef KEEP_DEVICE_OPEN
216 AudioDevicePrivate::dspFd = d->handle; 214 AudioDevicePrivate::dspFd = d->handle;
217 } else { 215 } else {
218 d->handle = AudioDevicePrivate::dspFd; 216 d->handle = AudioDevicePrivate::dspFd;
219 } 217 }
220#endif 218#endif
221 219
222 if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) 220 if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1)
223 perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); 221 perror("ioctl(\"SNDCTL_DSP_GETCAPS\")");
224 if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) 222 if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1)
225 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); 223 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")");
226 if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) 224 if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1)
227 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 225 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
228 qDebug("freq %d", d->frequency); 226 qDebug("freq %d", d->frequency);
229 if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) 227 if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1)
230 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 228 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
231 qDebug("channels %d",d->channels); 229 qDebug("channels %d",d->channels);
232 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { 230 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) {
233 d->channels = ( d->channels == 1 ) ? 2 : d->channels; 231 d->channels = ( d->channels == 1 ) ? 2 : d->channels;
234 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) 232 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1)
235 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 233 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
236 } 234 }
237 235
238 d->bufferSize = sound_fragment_bytes; 236 d->bufferSize = sound_fragment_bytes;
239 d->unwrittenBuffer = new char[d->bufferSize]; 237 d->unwrittenBuffer = new char[d->bufferSize];
240 d->unwritten = 0; 238 d->unwritten = 0;
241 d->can_GETOSPACE = TRUE; // until we find otherwise 239 d->can_GETOSPACE = TRUE; // until we find otherwise
242 240
243 //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); 241 //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels );
244 //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); 242 //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency );
245 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); 243 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" );
246 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); 244 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" );
247 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); 245 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" );
248 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); 246 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" );
249} 247}
250 248
251 249
252AudioDevice::~AudioDevice() { 250AudioDevice::~AudioDevice() {
253#ifdef Q_OS_WIN32 251#ifdef Q_OS_WIN32
254 waveOutClose( (HWAVEOUT)d->handle ); 252 waveOutClose( (HWAVEOUT)d->handle );
255#else 253#else
256# ifndef KEEP_DEVICE_OPEN 254# ifndef KEEP_DEVICE_OPEN
257 close( d->handle ); // Now it should be safe to shut the handle 255 close( d->handle ); // Now it should be safe to shut the handle
258# endif 256# endif
259 delete d->unwrittenBuffer; 257 delete d->unwrittenBuffer;
260 delete d; 258 delete d;
261#endif 259#endif
262} 260}
263 261
264 262
265void AudioDevice::volumeChanged( bool muted ) 263void AudioDevice::volumeChanged( bool muted )
266{ 264{
267 AudioDevicePrivate::muted = muted; 265 AudioDevicePrivate::muted = muted;
268} 266}
269 267
270 268
271void AudioDevice::write( char *buffer, unsigned int length ) 269void AudioDevice::write( char *buffer, unsigned int length )
272{ 270{
273#ifdef Q_OS_WIN32 271#ifdef Q_OS_WIN32
274 // returns immediately and (to be implemented) emits completedIO() when finished writing 272 // returns immediately and (to be implemented) emits completedIO() when finished writing
275 WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) ); 273 WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) );
276 // maybe the buffer should be copied so that this fool proof, but its a performance hit 274 // maybe the buffer should be copied so that this fool proof, but its a performance hit
277 lpWaveHdr->lpData = buffer; 275 lpWaveHdr->lpData = buffer;
278 lpWaveHdr->dwBufferLength = length; 276 lpWaveHdr->dwBufferLength = length;
279 lpWaveHdr->dwFlags = 0L; 277 lpWaveHdr->dwFlags = 0L;
280 lpWaveHdr->dwLoops = 0L; 278 lpWaveHdr->dwLoops = 0L;
281 waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ); 279 waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) );
282 // waveOutWrite returns immediately. the data is sent in the background. 280 // waveOutWrite returns immediately. the data is sent in the background.
283 if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) ) 281 if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) )
284 qDebug( "failed to write block to audio device" ); 282 qDebug( "failed to write block to audio device" );
285 // emit completedIO(); 283 // emit completedIO();
286#else 284#else
287 int t = ::write( d->handle, buffer, length ); 285 int t = ::write( d->handle, buffer, length );
288 if ( t<0 ) t = 0; 286 if ( t<0 ) t = 0;
289 if ( t != (int)length) { 287 if ( t != (int)length) {
290 qDebug("Ahhh!! memcpys 1"); 288 qDebug("Ahhh!! memcpys 1");
291 memcpy(d->unwrittenBuffer,buffer+t,length-t); 289 memcpy(d->unwrittenBuffer,buffer+t,length-t);
292 d->unwritten = length-t; 290 d->unwritten = length-t;
293 } 291 }
294#endif 292#endif
295} 293}
296 294
297 295
298unsigned int AudioDevice::channels() const 296unsigned int AudioDevice::channels() const
299{ 297{
300 return d->channels; 298 return d->channels;
301} 299}
302 300
303 301
304unsigned int AudioDevice::frequency() const 302unsigned int AudioDevice::frequency() const
305{ 303{
306 return d->frequency; 304 return d->frequency;
307} 305}
308 306
309 307
310unsigned int AudioDevice::bytesPerSample() const 308unsigned int AudioDevice::bytesPerSample() const
311{ 309{
312 return d->bytesPerSample; 310 return d->bytesPerSample;
313} 311}
314 312
315 313
316unsigned int AudioDevice::bufferSize() const 314unsigned int AudioDevice::bufferSize() const
317{ 315{
318 return d->bufferSize; 316 return d->bufferSize;
319} 317}
320 318
321unsigned int AudioDevice::canWrite() const 319unsigned int AudioDevice::canWrite() const
322{ 320{
323#ifdef Q_OS_WIN32 321#ifdef Q_OS_WIN32
324 return bufferSize(); // Any better? 322 return bufferSize(); // Any better?
325#else 323#else
326 audio_buf_info info; 324 audio_buf_info info;
327 if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { 325 if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) {
328 d->can_GETOSPACE = FALSE; 326 d->can_GETOSPACE = FALSE;
329 fcntl( d->handle, F_SETFL, O_NONBLOCK ); 327 fcntl( d->handle, F_SETFL, O_NONBLOCK );
330 } 328 }
331 if ( d->can_GETOSPACE ) { 329 if ( d->can_GETOSPACE ) {
332 int t = info.fragments * sound_fragment_bytes; 330 int t = info.fragments * sound_fragment_bytes;
333 return QMIN(t,(int)bufferSize()); 331 return QMIN(t,(int)bufferSize());
334 } else { 332 } else {
335 if ( d->unwritten ) { 333 if ( d->unwritten ) {
336 int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); 334 int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten );
337 if ( t<0 ) t = 0; 335 if ( t<0 ) t = 0;
338 if ( (unsigned)t!=d->unwritten ) { 336 if ( (unsigned)t!=d->unwritten ) {
339 memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); 337 memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t);
340 d->unwritten -= t; 338 d->unwritten -= t;
341 } else { 339 } else {
342 d->unwritten = 0; 340 d->unwritten = 0;
343 } 341 }
344 } 342 }
345 if ( d->unwritten ) 343 if ( d->unwritten )
346 return 0; 344 return 0;
347 else 345 else
348 return d->bufferSize; 346 return d->bufferSize;
349 } 347 }
350#endif 348#endif
351} 349}
352 350
353 351
354int AudioDevice::bytesWritten() { 352int AudioDevice::bytesWritten() {
355#ifdef Q_OS_WIN32 353#ifdef Q_OS_WIN32
356 MMTIME pmmt = { TIME_BYTES, 0 }; 354 MMTIME pmmt = { TIME_BYTES, 0 };
357 if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) { 355 if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) {
358 qDebug( "failed to get audio device position" ); 356 qDebug( "failed to get audio device position" );
359 return -1; 357 return -1;
360 } 358 }
361 return pmmt.u.cb; 359 return pmmt.u.cb;
362#else 360#else
363 int buffered = 0; 361 int buffered = 0;
364 if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { 362 if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) {
365 qDebug( "failed to get audio device position" ); 363 qDebug( "failed to get audio device position" );
366 return -1; 364 return -1;
367 } 365 }
368 return buffered; 366 return buffered;
369#endif 367#endif
370} 368}
371 369
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp
index 582660c..3901446 100644
--- a/core/multimedia/opieplayer/audiowidget.cpp
+++ b/core/multimedia/opieplayer/audiowidget.cpp
@@ -1,276 +1,336 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qpe/qpeapplication.h>
21#include <qpe/resource.h>
22
20#include <qwidget.h> 23#include <qwidget.h>
21#include <qpixmap.h> 24#include <qpixmap.h>
22#include <qbutton.h> 25#include <qbutton.h>
23#include <qpainter.h> 26#include <qpainter.h>
24#include <qframe.h> 27#include <qframe.h>
25#include <qpe/resource.h> 28
26#include "audiowidget.h" 29#include "audiowidget.h"
27#include "mediaplayerstate.h" 30#include "mediaplayerstate.h"
28 31
29extern MediaPlayerState *mediaPlayerState; 32extern MediaPlayerState *mediaPlayerState;
30 33
31 34
32static const int xo = -2; // movable x offset 35static const int xo = -2; // movable x offset
33static const int yo = 22; // movable y offset 36static const int yo = 22; // movable y offset
34 37
35 38
36struct MediaButton { 39struct MediaButton {
37 int xPos, yPos; 40 int xPos, yPos;
38 int color; 41 int color;
39 bool isToggle, isBig, isHeld, isDown; 42 bool isToggle, isBig, isHeld, isDown;
40}; 43};
41 44
42 45
43// Layout information for the audioButtons (and if it is a toggle button or not) 46// Layout information for the audioButtons (and if it is a toggle button or not)
44MediaButton audioButtons[] = { 47MediaButton audioButtons[] = {
45 { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play 48 { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play
46 { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop 49 { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop
47 { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause 50 { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause
48 { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next 51 { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next
49 { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous 52 { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous
50 { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up 53 { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up
51 { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down 54 { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down
52 { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop 55 { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop
53 { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist 56 { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist
54}; 57};
55 58
56 59
57static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); 60static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton));
58 61
59 62
60AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : 63AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
61 QWidget( parent, name, f ) 64 QWidget( parent, name, f )
62{ 65{
66// QPEApplication::grabKeyboard();
63 setCaption( tr("OpiePlayer") ); 67 setCaption( tr("OpiePlayer") );
64 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 68 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
65 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsAll" ) ); 69 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsAll" ) );
66 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsBig" ) ); 70 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButtonsBig" ) );
67 pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls" ) ); 71 pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls" ) );
68 pixmaps[3] = new QPixmap( Resource::loadPixmap( "mpegplayer/animatedButton" ) ); 72 pixmaps[3] = new QPixmap( Resource::loadPixmap( "mpegplayer/animatedButton" ) );
69 73
70 songInfo = new Ticker( this ); 74 songInfo = new Ticker( this );
71 songInfo->setFocusPolicy( QWidget::NoFocus ); 75 songInfo->setFocusPolicy( QWidget::NoFocus );
72 songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); 76 songInfo->setGeometry( QRect( 7, 3, 220, 20 ) );
73 77
74 slider = new QSlider( Qt::Horizontal, this ); 78 slider = new QSlider( Qt::Horizontal, this );
75 slider->setFixedWidth( 220 ); 79 slider->setFixedWidth( 220 );
76 slider->setFixedHeight( 20 ); 80 slider->setFixedHeight( 20 );
77 slider->setMinValue( 0 ); 81 slider->setMinValue( 0 );
78 slider->setMaxValue( 1 ); 82 slider->setMaxValue( 1 );
79 slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 83 slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
80 slider->setFocusPolicy( QWidget::NoFocus ); 84 slider->setFocusPolicy( QWidget::NoFocus );
81 slider->setGeometry( QRect( 7, 262, 220, 20 ) ); 85 slider->setGeometry( QRect( 7, 262, 220, 20 ) );
82 86
83 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 87 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
84 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 88 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
85 89
86 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); 90 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) );
87 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 91 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
88 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 92 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
89 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); 93 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) );
90 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 94 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
91 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); 95 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
92 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); 96 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) );
93 97
94 // Intialise state 98 // Intialise state
95 setLength( mediaPlayerState->length() ); 99 setLength( mediaPlayerState->length() );
96 setPosition( mediaPlayerState->position() ); 100 setPosition( mediaPlayerState->position() );
97 setLooping( mediaPlayerState->fullscreen() ); 101 setLooping( mediaPlayerState->fullscreen() );
98 setPaused( mediaPlayerState->paused() ); 102 setPaused( mediaPlayerState->paused() );
99 setPlaying( mediaPlayerState->playing() ); 103 setPlaying( mediaPlayerState->playing() );
100 104
101} 105}
102 106
103 107
104AudioWidget::~AudioWidget() { 108AudioWidget::~AudioWidget() {
105 for ( int i = 0; i < 4; i++ ) 109 for ( int i = 0; i < 4; i++ )
106 delete pixmaps[i]; 110 delete pixmaps[i];
107} 111}
108 112
109 113
110static bool audioSliderBeingMoved = FALSE; 114static bool audioSliderBeingMoved = FALSE;
111 115
112 116
113void AudioWidget::sliderPressed() { 117void AudioWidget::sliderPressed() {
114 audioSliderBeingMoved = TRUE; 118 audioSliderBeingMoved = TRUE;
115} 119}
116 120
117 121
118void AudioWidget::sliderReleased() { 122void AudioWidget::sliderReleased() {
119 audioSliderBeingMoved = FALSE; 123 audioSliderBeingMoved = FALSE;
120 if ( slider->width() == 0 ) 124 if ( slider->width() == 0 )
121 return; 125 return;
122 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); 126 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width());
123 mediaPlayerState->setPosition( val ); 127 mediaPlayerState->setPosition( val );
124} 128}
125 129
126 130
127void AudioWidget::setPosition( long i ) { 131void AudioWidget::setPosition( long i ) {
128 updateSlider( i, mediaPlayerState->length() ); 132 updateSlider( i, mediaPlayerState->length() );
129} 133}
130 134
131 135
132void AudioWidget::setLength( long max ) { 136void AudioWidget::setLength( long max ) {
133 updateSlider( mediaPlayerState->position(), max ); 137 updateSlider( mediaPlayerState->position(), max );
134} 138}
135 139
136 140
137void AudioWidget::setView( char view ) { 141void AudioWidget::setView( char view ) {
138 if ( view == 'a' ) { 142 if ( view == 'a' ) {
139 startTimer( 150 ); 143 startTimer( 150 );
140 showMaximized(); 144 showMaximized();
141 } else { 145 } else {
142 killTimers(); 146 killTimers();
143 hide(); 147 hide();
144 } 148 }
145} 149}
146 150
147 151
148void AudioWidget::updateSlider( long i, long max ) { 152void AudioWidget::updateSlider( long i, long max ) {
149 if ( max == 0 ) 153 if ( max == 0 )
150 return; 154 return;
151 // Will flicker too much if we don't do this 155 // Will flicker too much if we don't do this
152 // Scale to something reasonable 156 // Scale to something reasonable
153 int width = slider->width(); 157 int width = slider->width();
154 int val = int((double)i * width / max); 158 int val = int((double)i * width / max);
155 if ( !audioSliderBeingMoved ) { 159 if ( !audioSliderBeingMoved ) {
156 if ( slider->value() != val ) 160 if ( slider->value() != val )
157 slider->setValue( val ); 161 slider->setValue( val );
158 if ( slider->maxValue() != width ) 162 if ( slider->maxValue() != width )
159 slider->setMaxValue( width ); 163 slider->setMaxValue( width );
160 } 164 }
161} 165}
162 166
163 167
164void AudioWidget::setToggleButton( int i, bool down ) { 168void AudioWidget::setToggleButton( int i, bool down ) {
165 if ( down != audioButtons[i].isDown ) 169 if ( down != audioButtons[i].isDown )
166 toggleButton( i ); 170 toggleButton( i );
167} 171}
168 172
169 173
170void AudioWidget::toggleButton( int i ) { 174void AudioWidget::toggleButton( int i ) {
171 audioButtons[i].isDown = !audioButtons[i].isDown; 175 audioButtons[i].isDown = !audioButtons[i].isDown;
172 QPainter p(this); 176 QPainter p(this);
173 paintButton ( &p, i ); 177 paintButton ( &p, i );
174} 178}
175 179
176 180
177void AudioWidget::paintButton( QPainter *p, int i ) { 181void AudioWidget::paintButton( QPainter *p, int i ) {
178 int x = audioButtons[i].xPos; 182 int x = audioButtons[i].xPos;
179 int y = audioButtons[i].yPos; 183 int y = audioButtons[i].yPos;
180 int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; 184 int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown;
181 int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); 185 int buttonSize = 64 + audioButtons[i].isBig * (90 - 64);
182 p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); 186 p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize );
183 p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); 187 p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 );
184} 188}
185 189
186 190
187void AudioWidget::timerEvent( QTimerEvent * ) { 191void AudioWidget::timerEvent( QTimerEvent * ) {
188 static int frame = 0; 192 static int frame = 0;
189 if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { 193 if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) {
190 frame = frame >= 7 ? 0 : frame + 1; 194 frame = frame >= 7 ? 0 : frame + 1;
191 int x = audioButtons[AudioPlay].xPos; 195 int x = audioButtons[AudioPlay].xPos;
192 int y = audioButtons[AudioPlay].yPos; 196 int y = audioButtons[AudioPlay].yPos;
193 QPainter p( this ); 197 QPainter p( this );
194 // Optimize to only draw the little bit of the changing images which is different 198 // Optimize to only draw the little bit of the changing images which is different
195 p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); 199 p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 );
196 p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); 200 p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 );
197 } 201 }
198} 202}
199 203
200 204
201void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { 205void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
202 for ( int i = 0; i < numButtons; i++ ) { 206 for ( int i = 0; i < numButtons; i++ ) {
203 int size = audioButtons[i].isBig; 207 int size = audioButtons[i].isBig;
204 int x = audioButtons[i].xPos; 208 int x = audioButtons[i].xPos;
205 int y = audioButtons[i].yPos; 209 int y = audioButtons[i].yPos;
206 if ( event->state() == QMouseEvent::LeftButton ) { 210 if ( event->state() == QMouseEvent::LeftButton ) {
207 // The test to see if the mouse click is inside the circular button or not 211 // The test to see if the mouse click is inside the circular button or not
208 // (compared with the radius squared to avoid a square-root of our distance) 212 // (compared with the radius squared to avoid a square-root of our distance)
209 int radius = 32 + 13 * size; 213 int radius = 32 + 13 * size;
210 QPoint center = QPoint( x + radius, y + radius ); 214 QPoint center = QPoint( x + radius, y + radius );
211 QPoint dXY = center - event->pos(); 215 QPoint dXY = center - event->pos();
212 int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); 216 int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y();
213 bool isOnButton = dist <= (radius * radius); 217 bool isOnButton = dist <= (radius * radius);
214// QRect r( x, y, 64 + 22*size, 64 + 22*size ); 218// QRect r( x, y, 64 + 22*size, 64 + 22*size );
215// bool isOnButton = r.contains( event->pos() ); // Rectangular Button code 219// bool isOnButton = r.contains( event->pos() ); // Rectangular Button code
216 if ( isOnButton && !audioButtons[i].isHeld ) { 220 if ( isOnButton && !audioButtons[i].isHeld ) {
217 audioButtons[i].isHeld = TRUE; 221 audioButtons[i].isHeld = TRUE;
218 toggleButton(i); 222 toggleButton(i);
219 switch (i) { 223 qDebug("button toggled %d",i);
220 case AudioVolumeUp: emit moreClicked(); return; 224 switch (i) {
221 case AudioVolumeDown: emit lessClicked(); return; 225 case AudioVolumeUp: emit moreClicked(); return;
222 } 226 case AudioVolumeDown: emit lessClicked(); return;
223 } else if ( !isOnButton && audioButtons[i].isHeld ) { 227 }
224 audioButtons[i].isHeld = FALSE; 228 } else if ( !isOnButton && audioButtons[i].isHeld ) {
225 toggleButton(i); 229 audioButtons[i].isHeld = FALSE;
226 } 230 toggleButton(i);
227 } else { 231 }
228 if ( audioButtons[i].isHeld ) { 232 } else {
229 audioButtons[i].isHeld = FALSE; 233 if ( audioButtons[i].isHeld ) {
230 if ( !audioButtons[i].isToggle ) 234 audioButtons[i].isHeld = FALSE;
231 setToggleButton( i, FALSE ); 235 if ( !audioButtons[i].isToggle )
232 switch (i) { 236 setToggleButton( i, FALSE );
233 case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; 237 switch (i) {
234 case AudioStop: mediaPlayerState->setPlaying(FALSE); return; 238 case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return;
235 case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; 239 case AudioStop: mediaPlayerState->setPlaying(FALSE); return;
236 case AudioNext: mediaPlayerState->setNext(); return; 240 case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return;
237 case AudioPrevious: mediaPlayerState->setPrev(); return; 241 case AudioNext: mediaPlayerState->setNext(); return;
238 case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; 242 case AudioPrevious: mediaPlayerState->setPrev(); return;
239 case AudioVolumeUp: emit moreReleased(); return; 243 case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return;
240 case AudioVolumeDown: emit lessReleased(); return; 244 case AudioVolumeUp: emit moreReleased(); return;
241 case AudioPlayList: mediaPlayerState->setList(); return; 245 case AudioVolumeDown: emit lessReleased(); return;
242 } 246 case AudioPlayList: mediaPlayerState->setList(); return;
243 } 247 }
244 } 248 }
249 }
245 } 250 }
246} 251}
247 252
248 253
249void AudioWidget::mousePressEvent( QMouseEvent *event ) { 254void AudioWidget::mousePressEvent( QMouseEvent *event ) {
250 mouseMoveEvent( event ); 255 mouseMoveEvent( event );
251} 256}
252 257
253 258
254void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { 259void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) {
255 mouseMoveEvent( event ); 260 mouseMoveEvent( event );
256} 261}
257 262
258 263
259void AudioWidget::showEvent( QShowEvent* ) { 264void AudioWidget::showEvent( QShowEvent* ) {
260 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); 265 QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 );
261 mouseMoveEvent( &event ); 266 mouseMoveEvent( &event );
262} 267}
263 268
264 269
265void AudioWidget::closeEvent( QCloseEvent* ) { 270void AudioWidget::closeEvent( QCloseEvent* ) {
266 mediaPlayerState->setList(); 271 mediaPlayerState->setList();
267} 272}
268 273
269 274
270void AudioWidget::paintEvent( QPaintEvent * ) { 275void AudioWidget::paintEvent( QPaintEvent * ) {
271 QPainter p( this ); 276 QPainter p( this );
272 for ( int i = 0; i < numButtons; i++ ) 277 for ( int i = 0; i < numButtons; i++ )
273 paintButton( &p, i ); 278 paintButton( &p, i );
274} 279}
275 280
276 281
282void AudioWidget::keyReleaseEvent( QKeyEvent *e)
283{
284 switch ( e->key() ) {
285////////////////////////////// Zaurus keys
286 case Key_Home:
287 break;
288 case Key_F9: //activity
289 break;
290 case Key_F10: //contacts
291 break;
292 case Key_F11: //menu
293 break;
294 case Key_F12: //home
295 break;
296 case Key_F13: //mail
297 break;
298 case Key_Space: {
299 if(mediaPlayerState->playing()) {
300// toggleButton(1);
301 mediaPlayerState->setPlaying(FALSE);
302// toggleButton(1);
303 } else {
304// toggleButton(0);
305 mediaPlayerState->setPlaying(TRUE);
306// toggleButton(0);
307 }
308 }
309 break;
310 case Key_Down:
311 toggleButton(6);
312 emit lessClicked();
313 emit lessReleased();
314 toggleButton(6);
315 break;
316 case Key_Up:
317 toggleButton(5);
318 emit moreClicked();
319 emit moreReleased();
320 toggleButton(5);
321 break;
322 case Key_Right:
323// toggleButton(3);
324 mediaPlayerState->setNext();
325// toggleButton(3);
326 break;
327 case Key_Left:
328// toggleButton(4);
329 mediaPlayerState->setPrev();
330// toggleButton(4);
331 break;
332 case Key_Escape:
333 break;
334
335 };
336}
diff --git a/core/multimedia/opieplayer/audiowidget.h b/core/multimedia/opieplayer/audiowidget.h
index 53e84b3..a2850aa 100644
--- a/core/multimedia/opieplayer/audiowidget.h
+++ b/core/multimedia/opieplayer/audiowidget.h
@@ -1,143 +1,144 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef AUDIO_WIDGET_H 20#ifndef AUDIO_WIDGET_H
21#define AUDIO_WIDGET_H 21#define AUDIO_WIDGET_H
22 22
23#include <qwidget.h> 23#include <qwidget.h>
24#include <qpainter.h> 24#include <qpainter.h>
25#include <qdrawutil.h> 25#include <qdrawutil.h>
26#include <qpixmap.h> 26#include <qpixmap.h>
27#include <qstring.h> 27#include <qstring.h>
28#include <qslider.h> 28#include <qslider.h>
29#include <qframe.h> 29#include <qframe.h>
30 30
31 31
32class QPixmap; 32class QPixmap;
33 33
34 34
35enum AudioButtons { 35enum AudioButtons {
36 AudioPlay, 36 AudioPlay,
37 AudioStop, 37 AudioStop,
38 AudioPause, 38 AudioPause,
39 AudioNext, 39 AudioNext,
40 AudioPrevious, 40 AudioPrevious,
41 AudioVolumeUp, 41 AudioVolumeUp,
42 AudioVolumeDown, 42 AudioVolumeDown,
43 AudioLoop, 43 AudioLoop,
44 AudioPlayList 44 AudioPlayList
45}; 45};
46 46
47 47
48#define USE_DBLBUF 48#define USE_DBLBUF
49 49
50 50
51class Ticker : public QFrame { 51class Ticker : public QFrame {
52 Q_OBJECT 52 Q_OBJECT
53public: 53public:
54 Ticker( QWidget* parent=0 ) : QFrame( parent ) { 54 Ticker( QWidget* parent=0 ) : QFrame( parent ) {
55 setFrameStyle( WinPanel | Sunken ); 55 setFrameStyle( WinPanel | Sunken );
56 setText( "No Song" ); 56 setText( "No Song" );
57 } 57 }
58 ~Ticker() { } 58 ~Ticker() { }
59 void setText( const QString& text ) { 59 void setText( const QString& text ) {
60 pos = 0; // reset it everytime the text is changed 60 pos = 0; // reset it everytime the text is changed
61 scrollText = text; 61 scrollText = text;
62 pixelLen = fontMetrics().width( scrollText ); 62 pixelLen = fontMetrics().width( scrollText );
63 killTimers(); 63 killTimers();
64 if ( pixelLen > width() ) 64 if ( pixelLen > width() )
65 startTimer( 50 ); 65 startTimer( 50 );
66 update(); 66 update();
67 } 67 }
68protected: 68protected:
69 void timerEvent( QTimerEvent * ) { 69 void timerEvent( QTimerEvent * ) {
70 pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; 70 pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1;
71#ifndef USE_DBLBUF 71#ifndef USE_DBLBUF
72 scroll( -1, 0, contentsRect() ); 72 scroll( -1, 0, contentsRect() );
73#else 73#else
74 repaint( FALSE ); 74 repaint( FALSE );
75#endif 75#endif
76 } 76 }
77 void drawContents( QPainter *p ) { 77 void drawContents( QPainter *p ) {
78#ifndef USE_DBLBUF 78#ifndef USE_DBLBUF
79 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) 79 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen )
80 p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); 80 p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText );
81#else 81#else
82 // Double buffering code. 82 // Double buffering code.
83 // Looks like qvfb makes it look like it flickers but I don't think it really is 83 // Looks like qvfb makes it look like it flickers but I don't think it really is
84 QPixmap pm( width(), height() ); 84 QPixmap pm( width(), height() );
85 pm.fill( colorGroup().base() ); 85 pm.fill( colorGroup().base() );
86 QPainter pmp( &pm ); 86 QPainter pmp( &pm );
87 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) 87 for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen )
88 pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); 88 pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText );
89 p->drawPixmap( 0, 0, pm ); 89 p->drawPixmap( 0, 0, pm );
90#endif 90#endif
91 } 91 }
92private: 92private:
93 QString scrollText; 93 QString scrollText;
94 int pos, pixelLen; 94 int pos, pixelLen;
95}; 95};
96 96
97 97
98class AudioWidget : public QWidget { 98class AudioWidget : public QWidget {
99 Q_OBJECT 99 Q_OBJECT
100public: 100public:
101 AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 ); 101 AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 );
102 ~AudioWidget(); 102 ~AudioWidget();
103 void setTickerText( const QString &text ) { songInfo->setText( text ); } 103 void setTickerText( const QString &text ) { songInfo->setText( text ); }
104 104
105public slots: 105public slots:
106 void updateSlider( long, long ); 106 void updateSlider( long, long );
107 void sliderPressed( ); 107 void sliderPressed( );
108 void sliderReleased( ); 108 void sliderReleased( );
109 void setPaused( bool b) { setToggleButton( AudioPause, b ); } 109 void setPaused( bool b) { setToggleButton( AudioPause, b ); }
110 void setLooping( bool b) { setToggleButton( AudioLoop, b ); } 110 void setLooping( bool b) { setToggleButton( AudioLoop, b ); }
111 void setPlaying( bool b) { setToggleButton( AudioPlay, b ); } 111 void setPlaying( bool b) { setToggleButton( AudioPlay, b ); }
112 void setPosition( long ); 112 void setPosition( long );
113 void setLength( long ); 113 void setLength( long );
114 void setView( char ); 114 void setView( char );
115 115
116signals: 116signals:
117 void moreClicked(); 117 void moreClicked();
118 void lessClicked(); 118 void lessClicked();
119 void moreReleased(); 119 void moreReleased();
120 void lessReleased(); 120 void lessReleased();
121 void sliderMoved(long); 121 void sliderMoved(long);
122 122
123protected: 123protected:
124 void paintEvent( QPaintEvent *pe ); 124 void paintEvent( QPaintEvent *pe );
125 void showEvent( QShowEvent *se ); 125 void showEvent( QShowEvent *se );
126 void mouseMoveEvent( QMouseEvent *event ); 126 void mouseMoveEvent( QMouseEvent *event );
127 void mousePressEvent( QMouseEvent *event ); 127 void mousePressEvent( QMouseEvent *event );
128 void mouseReleaseEvent( QMouseEvent *event ); 128 void mouseReleaseEvent( QMouseEvent *event );
129 void timerEvent( QTimerEvent *event ); 129 void timerEvent( QTimerEvent *event );
130 void closeEvent( QCloseEvent *event ); 130 void closeEvent( QCloseEvent *event );
131 void keyReleaseEvent( QKeyEvent *e);
131 132
132private: 133private:
133 void toggleButton( int ); 134 void toggleButton( int );
134 void setToggleButton( int, bool ); 135 void setToggleButton( int, bool );
135 void paintButton( QPainter *p, int i ); 136 void paintButton( QPainter *p, int i );
136 QPixmap *pixmaps[4]; 137 QPixmap *pixmaps[4];
137 Ticker *songInfo; 138 Ticker *songInfo;
138 QSlider *slider; 139 QSlider *slider;
139}; 140};
140 141
141 142
142#endif // AUDIO_WIDGET_H 143#endif // AUDIO_WIDGET_H
143 144
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp
index cb8de8a..4b2827e 100644
--- a/core/multimedia/opieplayer/loopcontrol.cpp
+++ b/core/multimedia/opieplayer/loopcontrol.cpp
@@ -1,475 +1,476 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20// L.J.Potter added changes Fri 02-15-2002 20// L.J.Potter added changes Fri 02-15-2002
21 21
22 22
23#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
24 24
25#ifdef Q_WS_QWS 25#ifdef Q_WS_QWS
26#include <qpe/qcopenvelope_qws.h> 26#include <qpe/qcopenvelope_qws.h>
27#endif 27#endif
28#include <stdio.h> 28#include <stdio.h>
29#include <stdlib.h> 29#include <stdlib.h>
30#include <string.h> 30#include <string.h>
31#include <pthread.h> 31#include <pthread.h>
32#include <errno.h> 32#include <errno.h>
33#include <unistd.h> 33#include <unistd.h>
34#include "loopcontrol.h" 34#include "loopcontrol.h"
35#include "videowidget.h" 35#include "videowidget.h"
36#include "audiodevice.h" 36#include "audiodevice.h"
37#include <qpe/mediaplayerplugininterface.h> 37#include <qpe/mediaplayerplugininterface.h>
38#include "mediaplayerstate.h" 38#include "mediaplayerstate.h"
39 39
40 40
41extern VideoWidget *videoUI; // now only needed to tell it to play a frame 41extern VideoWidget *videoUI; // now only needed to tell it to play a frame
42extern MediaPlayerState *mediaPlayerState; 42extern MediaPlayerState *mediaPlayerState;
43 43
44 44
45//#define DecodeLoopDebug(x) qDebug x 45//#define DecodeLoopDebug(x) qDebug x
46#define DecodeLoopDebug(x) 46#define DecodeLoopDebug(x)
47 47
48 48
49static char *audioBuffer = NULL; 49static char *audioBuffer = NULL;
50static AudioDevice *audioDevice = NULL; 50static AudioDevice *audioDevice = NULL;
51static bool disabledSuspendScreenSaver = FALSE; 51static bool disabledSuspendScreenSaver = FALSE;
52static bool previousSuspendMode = FALSE; 52static bool previousSuspendMode = FALSE;
53 53
54 54
55pthread_t audio_tid; 55pthread_t audio_tid;
56pthread_attr_t audio_attr; 56pthread_attr_t audio_attr;
57bool threadOkToGo = FALSE; 57bool threadOkToGo = FALSE;
58 58
59 59
60class Mutex { 60class Mutex {
61public: 61public:
62 Mutex() { 62 Mutex() {
63 pthread_mutexattr_t attr; 63 pthread_mutexattr_t attr;
64 pthread_mutexattr_init( &attr ); 64 pthread_mutexattr_init( &attr );
65 pthread_mutex_init( &mutex, &attr ); 65 pthread_mutex_init( &mutex, &attr );
66 pthread_mutexattr_destroy( &attr ); 66 pthread_mutexattr_destroy( &attr );
67 } 67 }
68 68
69 ~Mutex() { 69 ~Mutex() {
70 pthread_mutex_destroy( &mutex ); 70 pthread_mutex_destroy( &mutex );
71 } 71 }
72 72
73 void lock() { 73 void lock() {
74 pthread_mutex_lock( &mutex ); 74 pthread_mutex_lock( &mutex );
75 } 75 }
76 76
77 void unlock() { 77 void unlock() {
78 pthread_mutex_unlock( &mutex ); 78 pthread_mutex_unlock( &mutex );
79 } 79 }
80private: 80private:
81 pthread_mutex_t mutex; 81 pthread_mutex_t mutex;
82}; 82};
83 83
84 84
85void *startAudioThread( void *ptr ) { 85void *startAudioThread( void *ptr ) {
86 LoopControl *mpegView = (LoopControl *)ptr; 86 LoopControl *mpegView = (LoopControl *)ptr;
87 while ( TRUE ) { 87 while ( TRUE ) {
88 if ( threadOkToGo && mpegView->moreAudio ) 88 if ( threadOkToGo && mpegView->moreAudio )
89 mpegView->startAudio(); 89 mpegView->startAudio();
90 else 90 else
91 usleep( 10000 ); // Semi-buzy-wait till we are playing again 91 usleep( 10000 ); // Semi-buzy-wait till we are playing again
92 } 92 }
93 return 0; 93 return 0;
94} 94}
95 95
96 96
97Mutex *audioMutex; 97Mutex *audioMutex;
98 98
99 99
100LoopControl::LoopControl( QObject *parent, const char *name ) 100LoopControl::LoopControl( QObject *parent, const char *name )
101 : QObject( parent, name ) { 101 : QObject( parent, name ) {
102 isMuted = FALSE; 102 isMuted = FALSE;
103 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); 103 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) );
104//qDebug("starting loopcontrol"); 104//qDebug("starting loopcontrol");
105 audioMutex = new Mutex; 105 audioMutex = new Mutex;
106 106
107 pthread_attr_init(&audio_attr); 107 pthread_attr_init(&audio_attr);
108#define USE_REALTIME_AUDIO_THREAD 108#define USE_REALTIME_AUDIO_THREAD
109#ifdef USE_REALTIME_AUDIO_THREAD 109#ifdef USE_REALTIME_AUDIO_THREAD
110 // Attempt to set it to real-time round robin 110 // Attempt to set it to real-time round robin
111 if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { 111 if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) {
112 sched_param params; 112 sched_param params;
113 params.sched_priority = 50; 113 params.sched_priority = 50;
114 pthread_attr_setschedparam(&audio_attr,&params); 114 pthread_attr_setschedparam(&audio_attr,&params);
115 } else { 115 } else {
116 qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); 116 qDebug( "Error setting up a realtime thread, reverting to using a normal thread." );
117 pthread_attr_destroy(&audio_attr); 117 pthread_attr_destroy(&audio_attr);
118 pthread_attr_init(&audio_attr); 118 pthread_attr_init(&audio_attr);
119 } 119 }
120#endif 120#endif
121//qDebug("create audio thread"); 121//qDebug("create audio thread");
122 pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); 122 pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this);
123} 123}
124 124
125 125
126LoopControl::~LoopControl() { 126LoopControl::~LoopControl() {
127 stop(); 127 stop();
128} 128}
129 129
130 130
131static long prev_frame = 0; 131static long prev_frame = 0;
132static int currentSample = 0; 132static int currentSample = 0;
133 133
134 134
135void LoopControl::timerEvent( QTimerEvent *te ) { 135void LoopControl::timerEvent( QTimerEvent *te ) {
136 136
137 if ( te->timerId() == videoId ) 137 if ( te->timerId() == videoId )
138 startVideo(); 138 startVideo();
139 139
140 if ( te->timerId() == sliderId ) { 140 if ( te->timerId() == sliderId ) {
141 if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { 141 if ( hasAudioChannel && !hasVideoChannel && moreAudio ) {
142 mediaPlayerState->updatePosition( audioSampleCounter ); 142 mediaPlayerState->updatePosition( audioSampleCounter );
143 } else if ( hasVideoChannel && moreVideo ) { 143 } else if ( hasVideoChannel && moreVideo ) {
144 mediaPlayerState->updatePosition( current_frame ); 144 mediaPlayerState->updatePosition( current_frame );
145 } 145 }
146 } 146 }
147 147
148 if ( !moreVideo && !moreAudio ) { 148 if ( !moreVideo && !moreAudio ) {
149 mediaPlayerState->setPlaying( FALSE ); 149 mediaPlayerState->setPlaying( FALSE );
150 mediaPlayerState->setNext(); 150 mediaPlayerState->setNext();
151 } 151 }
152} 152}
153 153
154 154
155void LoopControl::setPosition( long pos ) { 155void LoopControl::setPosition( long pos ) {
156 audioMutex->lock(); 156 audioMutex->lock();
157 157
158 if ( hasVideoChannel && hasAudioChannel ) { 158 if ( hasVideoChannel && hasAudioChannel ) {
159 playtime.restart(); 159 playtime.restart();
160 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); 160 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) );
161 current_frame = pos + 1; 161 current_frame = pos + 1;
162 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); 162 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
163 prev_frame = current_frame - 1; 163 prev_frame = current_frame - 1;
164 currentSample = (int)( (double)current_frame * freq / framerate ); 164 currentSample = (int)( (double)current_frame * freq / framerate );
165 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); 165 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream );
166 audioSampleCounter = currentSample - 1; 166 audioSampleCounter = currentSample - 1;
167 } else if ( hasVideoChannel ) { 167 } else if ( hasVideoChannel ) {
168 playtime.restart(); 168 playtime.restart();
169 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); 169 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) );
170 current_frame = pos + 1; 170 current_frame = pos + 1;
171 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); 171 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
172 prev_frame = current_frame - 1; 172 prev_frame = current_frame - 1;
173 } else if ( hasAudioChannel ) { 173 } else if ( hasAudioChannel ) {
174 playtime.restart(); 174 playtime.restart();
175 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); 175 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) );
176 currentSample = pos + 1; 176 currentSample = pos + 1;
177 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); 177 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream );
178 audioSampleCounter = currentSample - 1; 178 audioSampleCounter = currentSample - 1;
179 } 179 }
180 180
181 audioMutex->unlock(); 181 audioMutex->unlock();
182} 182}
183 183
184 184
185void LoopControl::startVideo() { 185void LoopControl::startVideo() {
186 186
187 if ( moreVideo ) { 187 if ( moreVideo ) {
188 188
189 if ( mediaPlayerState->curDecoder() ) { 189 if ( mediaPlayerState->curDecoder() ) {
190 190
191 if ( hasAudioChannel && !isMuted ) { 191 if ( hasAudioChannel && !isMuted ) {
192 192
193 current_frame = long( playtime.elapsed() * framerate / 1000 ); 193 current_frame = long( playtime.elapsed() * framerate / 1000 );
194 194
195 if ( prev_frame != -1 && current_frame <= prev_frame ) 195 if ( prev_frame != -1 && current_frame <= prev_frame )
196 return; 196 return;
197 197
198 } else { 198 } else {
199 // Don't skip 199 // Don't skip
200 current_frame++; 200 current_frame++;
201 } 201 }
202 202
203 if ( prev_frame == -1 || current_frame > prev_frame ) { 203 if ( prev_frame == -1 || current_frame > prev_frame ) {
204 if ( current_frame > prev_frame + 1 ) { 204 if ( current_frame > prev_frame + 1 ) {
205 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); 205 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
206 } 206 }
207 moreVideo = videoUI->playVideo(); 207 moreVideo = videoUI->playVideo();
208 prev_frame = current_frame; 208 prev_frame = current_frame;
209 } 209 }
210 210
211 } else { 211 } else {
212 212
213 moreVideo = FALSE; 213 moreVideo = FALSE;
214 killTimer( videoId ); 214 killTimer( videoId );
215 215
216 } 216 }
217 217
218 } 218 }
219} 219}
220 220
221 221
222void LoopControl::startAudio() { 222void LoopControl::startAudio() {
223 223
224//qDebug("start audio");
225 audioMutex->lock(); 224 audioMutex->lock();
226 if ( moreAudio ) { 225 if ( moreAudio ) {
227 226
228 if ( !isMuted && mediaPlayerState->curDecoder() ) { 227 if ( !isMuted && mediaPlayerState->curDecoder() ) {
229 228
230 currentSample = audioSampleCounter + 1; 229 currentSample = audioSampleCounter + 1;
231 230
232 if ( currentSample != audioSampleCounter + 1 ) 231 if ( currentSample != audioSampleCounter + 1 )
233 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); 232 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter);
234 233
235 long samplesRead = 0; 234 long samplesRead = 0;
236 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); 235 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream );
237 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; 236 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000;
238 long sampleWaitTime = currentSample - sampleWeShouldBeAt; 237 long sampleWaitTime = currentSample - sampleWeShouldBeAt;
239 238
240// if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { 239// if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) {
241// usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); 240// usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) );
242// } 241// }
243// else if ( sampleWaitTime <= -5000 ) { 242// else if ( sampleWaitTime <= -5000 ) {
244// qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); 243// // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt );
245// //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); 244// //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
246// currentSample = sampleWeShouldBeAt; 245// currentSample = sampleWeShouldBeAt;
247// } 246// }
248 247
249 audioDevice->write( audioBuffer, samplesRead * 2 * channels ); 248 audioDevice->write( audioBuffer, samplesRead * 2 * channels );
250 audioSampleCounter = currentSample + samplesRead - 1; 249 audioSampleCounter = currentSample + samplesRead - 1;
251 250
252 moreAudio = readOk && (audioSampleCounter <= total_audio_samples); 251 moreAudio = readOk && (audioSampleCounter <= total_audio_samples);
253 252
254 } else { 253 } else {
255 254
256 moreAudio = FALSE; 255 moreAudio = FALSE;
257 256
258 } 257 }
259 258
260 } 259 }
261 260
262 audioMutex->unlock(); 261 audioMutex->unlock();
263} 262}
264 263
265 264
266void LoopControl::killTimers() { 265void LoopControl::killTimers() {
267 266
268 audioMutex->lock(); 267 audioMutex->lock();
269 268
270 if ( hasVideoChannel ) 269 if ( hasVideoChannel )
271 killTimer( videoId ); 270 killTimer( videoId );
272 killTimer( sliderId ); 271 killTimer( sliderId );
273 threadOkToGo = FALSE; 272 threadOkToGo = FALSE;
274 273
275 audioMutex->unlock(); 274 audioMutex->unlock();
276} 275}
277 276
278 277
279void LoopControl::startTimers() { 278void LoopControl::startTimers() {
280 279
281 audioMutex->lock(); 280 audioMutex->lock();
282 281
283 moreVideo = FALSE; 282 moreVideo = FALSE;
284 moreAudio = FALSE; 283 moreAudio = FALSE;
285 284
286 if ( hasVideoChannel ) { 285 if ( hasVideoChannel ) {
287 moreVideo = TRUE; 286 moreVideo = TRUE;
288 int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value 287 int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value
289 videoId = startTimer( mSecsBetweenFrames ); 288 videoId = startTimer( mSecsBetweenFrames );
290 } 289 }
291 290
292 if ( hasAudioChannel ) { 291 if ( hasAudioChannel ) {
293 moreAudio = TRUE; 292 moreAudio = TRUE;
294 threadOkToGo = TRUE; 293 threadOkToGo = TRUE;
295 } 294 }
296 295
297 sliderId = startTimer( 300 ); // update slider every 1/3 second 296 sliderId = startTimer( 300 ); // update slider every 1/3 second
298 297
299 audioMutex->unlock(); 298 audioMutex->unlock();
300} 299}
301 300
302 301
303void LoopControl::setPaused( bool pause ) { 302void LoopControl::setPaused( bool pause ) {
304 303
305 if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) 304 if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() )
306 return; 305 return;
307 306
308 if ( pause ) { 307 if ( pause ) {
309 killTimers(); 308 killTimers();
310 } else { 309 } else {
311 // Force an update of the position 310 // Force an update of the position
312 mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); 311 mediaPlayerState->setPosition( mediaPlayerState->position() + 1 );
313 mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); 312 mediaPlayerState->setPosition( mediaPlayerState->position() - 1 );
314 // Just like we never stopped 313 // Just like we never stopped
315 startTimers(); 314 startTimers();
316 } 315 }
317} 316}
318 317
319 318
320void LoopControl::stop( bool willPlayAgainShortly ) { 319void LoopControl::stop( bool willPlayAgainShortly ) {
321 320
322#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 321#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
323 if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { 322 if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) {
324 disabledSuspendScreenSaver = FALSE; 323 disabledSuspendScreenSaver = FALSE;
325 // Re-enable the suspend mode 324 // Re-enable the suspend mode
326 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 325 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
327 } 326 }
328#endif 327#endif
329 328
330 if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { 329 if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) {
331 330
332 killTimers(); 331 killTimers();
333 332
334 audioMutex->lock(); 333 audioMutex->lock();
335 334
336 mediaPlayerState->curDecoder()->close(); 335 mediaPlayerState->curDecoder()->close();
337 336
338 if ( audioDevice ) { 337 if ( audioDevice ) {
339 delete audioDevice; 338 delete audioDevice;
340 delete audioBuffer; 339 delete audioBuffer;
341 audioDevice = 0; 340 audioDevice = 0;
342 audioBuffer = 0; 341 audioBuffer = 0;
343 } 342 }
344 343
345 audioMutex->unlock(); 344 audioMutex->unlock();
346 345
347 } 346 }
348} 347}
349 348
350 349
351bool LoopControl::init( const QString& filename ) { 350bool LoopControl::init( const QString& filename ) {
352 stop(); 351 stop();
353 352
354 audioMutex->lock(); 353 audioMutex->lock();
355 354
356 fileName = filename; 355 fileName = filename;
357 stream = 0; // only play stream 0 for now 356 stream = 0; // only play stream 0 for now
358 current_frame = total_video_frames = total_audio_samples = 0; 357 current_frame = total_video_frames = total_audio_samples = 0;
359 358
360 qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); 359 qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() );
361 360
362 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin 361 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin
363 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { 362 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) {
364 if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { 363 if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) {
365 total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); 364 total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 );
366 mediaPlayerState->libMpeg3Decoder()->close(); 365 mediaPlayerState->libMpeg3Decoder()->close();
367 } 366 }
368 } 367 }
369 368
370 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { 369 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) {
371 audioMutex->unlock(); 370 audioMutex->unlock();
372 return FALSE; 371 return FALSE;
373 } 372 }
374 373
375 hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; 374 hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0;
376 hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; 375 hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0;
377 376
378 if ( hasAudioChannel ) { 377 if ( hasAudioChannel ) {
379 int astream = 0; 378 int astream = 0;
380 379
381 channels = mediaPlayerState->curDecoder()->audioChannels( astream ); 380 channels = mediaPlayerState->curDecoder()->audioChannels( astream );
382 qDebug( "LC- channels = %d", channels ); 381// qDebug( "LC- channels = %d", channels );
383 382
384 if ( !total_audio_samples ) 383 if ( !total_audio_samples )
385 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); 384 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream );
386 385
387// total_audio_samples += 1000; 386// total_audio_samples += 1000;
388 387
389 mediaPlayerState->setLength( total_audio_samples ); 388 mediaPlayerState->setLength( total_audio_samples );
390 389
391 freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); 390 freq = mediaPlayerState->curDecoder()->audioFrequency( astream );
392 qDebug( "LC- frequency = %d", freq ); 391// qDebug( "LC- frequency = %d", freq );
393 392
394 audioSampleCounter = 0; 393 audioSampleCounter = 0;
395 int bits_per_sample; 394 int bits_per_sample;
396 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { 395 if ( mediaPlayerState->curDecoder()->pluginName() == QString("WavPlugin") ) {
397 bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); 396 bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime();
398 qDebug("using stupid hack"); 397// qDebug("using stupid hack");
399 } else { 398 } else {
400 bits_per_sample=0; 399 bits_per_sample=0;
400// freq=44100;
401 channels=2;
401 } 402 }
402 403
403 audioDevice = new AudioDevice( freq, channels, bits_per_sample); 404 audioDevice = new AudioDevice( freq, channels, bits_per_sample);
404 audioBuffer = new char[ audioDevice->bufferSize() ]; 405 audioBuffer = new char[ audioDevice->bufferSize() ];
405 channels = audioDevice->channels(); 406 channels = audioDevice->channels();
406 407
407 //### must check which frequency is actually used. 408 //### must check which frequency is actually used.
408 static const int size = 1; 409 static const int size = 1;
409 short int buf[size]; 410 short int buf[size];
410 long samplesRead = 0; 411 long samplesRead = 0;
411 mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); 412 mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream );
412 } 413 }
413 414
414 if ( hasVideoChannel ) { 415 if ( hasVideoChannel ) {
415 total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); 416 total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream );
416 417
417 mediaPlayerState->setLength( total_video_frames ); 418 mediaPlayerState->setLength( total_video_frames );
418 419
419 framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); 420 framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream );
420 DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); 421 DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames ));
421 422
422 if ( framerate <= 1.0 ) { 423 if ( framerate <= 1.0 ) {
423 DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); 424 DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" ));
424 framerate = 25; 425 framerate = 25;
425 } 426 }
426 427
427 if ( total_video_frames == 1 ) { 428 if ( total_video_frames == 1 ) {
428 DecodeLoopDebug(( "Cannot seek to frame" )); 429 DecodeLoopDebug(( "Cannot seek to frame" ));
429 } 430 }
430 431
431 } 432 }
432 433
433 current_frame = 0; 434 current_frame = 0;
434 prev_frame = -1; 435 prev_frame = -1;
435 436
436 connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); 437 connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) );
437 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); 438 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) );
438 439
439 audioMutex->unlock(); 440 audioMutex->unlock();
440 441
441 return TRUE; 442 return TRUE;
442} 443}
443 444
444 445
445void LoopControl::play() { 446void LoopControl::play() {
446 qDebug("LC- play"); 447 qDebug("LC- play");
447#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 448#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
448 if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { 449 if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) {
449 disabledSuspendScreenSaver = TRUE; 450 disabledSuspendScreenSaver = TRUE;
450 previousSuspendMode = hasVideoChannel; 451 previousSuspendMode = hasVideoChannel;
451 // Stop the screen from blanking and power saving state 452 // Stop the screen from blanking and power saving state
452 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) 453 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" )
453 << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); 454 << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend );
454 } 455 }
455#endif 456#endif
456 457
457 playtime.start(); 458 playtime.start();
458 startTimers(); 459 startTimers();
459} 460}
460 461
461 462
462void LoopControl::setMute( bool on ) { 463void LoopControl::setMute( bool on ) {
463 if ( on != isMuted ) { 464 if ( on != isMuted ) {
464 isMuted = on; 465 isMuted = on;
465 if ( !on ) { 466 if ( !on ) {
466 // Force an update of the position 467 // Force an update of the position
467 mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); 468 mediaPlayerState->setPosition( mediaPlayerState->position() + 1 );
468 mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); 469 mediaPlayerState->setPosition( mediaPlayerState->position() - 1 );
469 // Resume playing audio 470 // Resume playing audio
470 moreAudio = TRUE; 471 moreAudio = TRUE;
471 } 472 }
472 } 473 }
473} 474}
474 475
475 476
diff --git a/core/multimedia/opieplayer/playlistselection.cpp b/core/multimedia/opieplayer/playlistselection.cpp
index 4019d12..47fc731 100644
--- a/core/multimedia/opieplayer/playlistselection.cpp
+++ b/core/multimedia/opieplayer/playlistselection.cpp
@@ -1,184 +1,183 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qpe/applnk.h> 20#include <qpe/applnk.h>
21#include <qpe/resource.h> 21#include <qpe/resource.h>
22#include <qpainter.h> 22#include <qpainter.h>
23#include <qimage.h> 23#include <qimage.h>
24#include <qheader.h> 24#include <qheader.h>
25#include <qlistview.h> 25#include <qlistview.h>
26#include <qlist.h> 26#include <qlist.h>
27#include <qpixmap.h> 27#include <qpixmap.h>
28 28
29#include "playlistselection.h" 29#include "playlistselection.h"
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33class PlayListSelectionItem : public QListViewItem { 33class PlayListSelectionItem : public QListViewItem {
34public: 34public:
35 PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) { 35 PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) {
36 setText( 0, f->name() ); 36 setText( 0, f->name() );
37 setPixmap( 0, f->pixmap() ); 37 setPixmap( 0, f->pixmap() );
38 } 38 }
39 39
40 ~PlayListSelectionItem() { 40 ~PlayListSelectionItem() {
41 }; 41 };
42 42
43 const DocLnk *file() const { return fl; } 43 const DocLnk *file() const { return fl; }
44 44
45private: 45private:
46 const DocLnk *fl; 46 const DocLnk *fl;
47}; 47};
48 48
49 49
50PlayListSelection::PlayListSelection( QWidget *parent, const char *name ) 50PlayListSelection::PlayListSelection( QWidget *parent, const char *name )
51 : QListView( parent, name ) 51 : QListView( parent, name )
52{ 52{
53 qDebug("starting playlistselector"); 53 qDebug("starting playlistselector");
54// #ifdef USE_PLAYLIST_BACKGROUND 54// #ifdef USE_PLAYLIST_BACKGROUND
55// setStaticBackground( TRUE ); 55// setStaticBackground( TRUE );
56// setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/background" ) ); 56// setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/background" ) );
57 57
58// setBackgroundPixmap( Resource::loadPixmap( "opielogo" ) ); 58 setBackgroundPixmap( Resource::loadPixmap( "opielogo" ) );
59// #endif 59// #endif
60// addColumn("Title",236); 60// addColumn("Title",236);
61// setAllColumnsShowFocus( TRUE ); 61// setAllColumnsShowFocus( TRUE );
62 addColumn( tr( "Playlist Selection" ) ); 62 addColumn( tr( "Playlist Selection" ) );
63 header()->hide(); 63 header()->hide();
64 setSorting( -1, FALSE ); 64 setSorting( -1, FALSE );
65} 65}
66 66
67 67
68PlayListSelection::~PlayListSelection() { 68PlayListSelection::~PlayListSelection() {
69} 69}
70 70
71 71
72// #ifdef USE_PLAYLIST_BACKGROUND 72// #ifdef USE_PLAYLIST_BACKGROUND
73void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) { 73void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) {
74// qDebug("drawBackground"); 74// qDebug("drawBackground");
75 p->fillRect( r, QBrush( white ) ); 75 p->fillRect( r, QBrush( white ) );
76// QImage logo = Resource::loadImage( "mpegplayer/background" ); 76 QImage logo = Resource::loadImage( "opielogo" );
77// // QImage logo = Resource::loadImage( "opielogo" ); 77 if ( !logo.isNull() )
78// if ( !logo.isNull() ) 78 p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo );
79// p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo );
80} 79}
81// #endif 80// #endif
82 81
83 82
84void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) { 83void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) {
85 if ( event->state() == QMouseEvent::LeftButton ) { 84 if ( event->state() == QMouseEvent::LeftButton ) {
86 QListViewItem *currentItem = selectedItem(); 85 QListViewItem *currentItem = selectedItem();
87 QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) ); 86 QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) );
88 if ( currentItem && currentItem->itemAbove() == itemUnder ) 87 if ( currentItem && currentItem->itemAbove() == itemUnder )
89 moveSelectedUp(); 88 moveSelectedUp();
90 else if ( currentItem && currentItem->itemBelow() == itemUnder ) 89 else if ( currentItem && currentItem->itemBelow() == itemUnder )
91 moveSelectedDown(); 90 moveSelectedDown();
92 } 91 }
93} 92}
94 93
95 94
96const DocLnk *PlayListSelection::current() { 95const DocLnk *PlayListSelection::current() {
97 PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem(); 96 PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem();
98 if ( item ) 97 if ( item )
99 return item->file(); 98 return item->file();
100 return NULL; 99 return NULL;
101} 100}
102 101
103 102
104void PlayListSelection::addToSelection( const DocLnk &lnk ) { 103void PlayListSelection::addToSelection( const DocLnk &lnk ) {
105 PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) ); 104 PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) );
106 QListViewItem *current = selectedItem(); 105 QListViewItem *current = selectedItem();
107 if ( current ) 106 if ( current )
108 item->moveItem( current ); 107 item->moveItem( current );
109 setSelected( item, TRUE ); 108 setSelected( item, TRUE );
110 ensureItemVisible( selectedItem() ); 109 ensureItemVisible( selectedItem() );
111} 110}
112 111
113 112
114void PlayListSelection::removeSelected() { 113void PlayListSelection::removeSelected() {
115 QListViewItem *item = selectedItem(); 114 QListViewItem *item = selectedItem();
116 if ( item ) 115 if ( item )
117 delete item; 116 delete item;
118 setSelected( currentItem(), TRUE ); 117 setSelected( currentItem(), TRUE );
119 ensureItemVisible( selectedItem() ); 118 ensureItemVisible( selectedItem() );
120} 119}
121 120
122 121
123void PlayListSelection::moveSelectedUp() { 122void PlayListSelection::moveSelectedUp() {
124 QListViewItem *item = selectedItem(); 123 QListViewItem *item = selectedItem();
125 if ( item && item->itemAbove() ) 124 if ( item && item->itemAbove() )
126 item->itemAbove()->moveItem( item ); 125 item->itemAbove()->moveItem( item );
127 ensureItemVisible( selectedItem() ); 126 ensureItemVisible( selectedItem() );
128} 127}
129 128
130 129
131void PlayListSelection::moveSelectedDown() { 130void PlayListSelection::moveSelectedDown() {
132 QListViewItem *item = selectedItem(); 131 QListViewItem *item = selectedItem();
133 if ( item && item->itemBelow() ) 132 if ( item && item->itemBelow() )
134 item->moveItem( item->itemBelow() ); 133 item->moveItem( item->itemBelow() );
135 ensureItemVisible( selectedItem() ); 134 ensureItemVisible( selectedItem() );
136} 135}
137 136
138 137
139bool PlayListSelection::prev() { 138bool PlayListSelection::prev() {
140 QListViewItem *item = selectedItem(); 139 QListViewItem *item = selectedItem();
141 if ( item && item->itemAbove() ) 140 if ( item && item->itemAbove() )
142 setSelected( item->itemAbove(), TRUE ); 141 setSelected( item->itemAbove(), TRUE );
143 else 142 else
144 return FALSE; 143 return FALSE;
145 ensureItemVisible( selectedItem() ); 144 ensureItemVisible( selectedItem() );
146 return TRUE; 145 return TRUE;
147} 146}
148 147
149 148
150bool PlayListSelection::next() { 149bool PlayListSelection::next() {
151 QListViewItem *item = selectedItem(); 150 QListViewItem *item = selectedItem();
152 if ( item && item->itemBelow() ) 151 if ( item && item->itemBelow() )
153 setSelected( item->itemBelow(), TRUE ); 152 setSelected( item->itemBelow(), TRUE );
154 else 153 else
155 return FALSE; 154 return FALSE;
156 ensureItemVisible( selectedItem() ); 155 ensureItemVisible( selectedItem() );
157 return TRUE; 156 return TRUE;
158} 157}
159 158
160 159
161bool PlayListSelection::first() { 160bool PlayListSelection::first() {
162 QListViewItem *item = firstChild(); 161 QListViewItem *item = firstChild();
163 if ( item ) 162 if ( item )
164 setSelected( item, TRUE ); 163 setSelected( item, TRUE );
165 else 164 else
166 return FALSE; 165 return FALSE;
167 ensureItemVisible( selectedItem() ); 166 ensureItemVisible( selectedItem() );
168 return TRUE; 167 return TRUE;
169} 168}
170 169
171 170
172bool PlayListSelection::last() { 171bool PlayListSelection::last() {
173 QListViewItem *prevItem = NULL; 172 QListViewItem *prevItem = NULL;
174 QListViewItem *item = firstChild(); 173 QListViewItem *item = firstChild();
175 while ( ( item = item->nextSibling() ) ) 174 while ( ( item = item->nextSibling() ) )
176 prevItem = item; 175 prevItem = item;
177 if ( prevItem ) 176 if ( prevItem )
178 setSelected( prevItem, TRUE ); 177 setSelected( prevItem, TRUE );
179 else 178 else
180 return FALSE; 179 return FALSE;
181 ensureItemVisible( selectedItem() ); 180 ensureItemVisible( selectedItem() );
182 return TRUE; 181 return TRUE;
183} 182}
184 183
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp
index 9969526..524747e 100644
--- a/core/multimedia/opieplayer/playlistwidget.cpp
+++ b/core/multimedia/opieplayer/playlistwidget.cpp
@@ -1,784 +1,814 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20// code added by L. J. Potter Sat 03-02-2002 06:17:54 20// code added by L. J. Potter Sat 03-02-2002 06:17:54
21#include <qpe/qpemenubar.h> 21#include <qpe/qpemenubar.h>
22#include <qpe/qpetoolbar.h> 22#include <qpe/qpetoolbar.h>
23#include <qpe/fileselector.h> 23#include <qpe/fileselector.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25 25
26#include <qpe/applnk.h> 26#include <qpe/applnk.h>
27#include <qpe/config.h> 27#include <qpe/config.h>
28#include <qpe/global.h> 28#include <qpe/global.h>
29#include <qpe/resource.h> 29#include <qpe/resource.h>
30#include <qaction.h> 30#include <qaction.h>
31#include <qimage.h> 31#include <qimage.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qdir.h> 33#include <qdir.h>
34#include <qlayout.h> 34#include <qlayout.h>
35#include <qlabel.h> 35#include <qlabel.h>
36#include <qlist.h> 36#include <qlist.h>
37#include <qlistbox.h> 37#include <qlistbox.h>
38#include <qmainwindow.h> 38#include <qmainwindow.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qtoolbutton.h> 40#include <qtoolbutton.h>
41#include <qtabwidget.h> 41#include <qtabwidget.h>
42#include <qlistview.h> 42#include <qlistview.h>
43#include <qpoint.h> 43#include <qpoint.h>
44#include <qlineedit.h> 44#include <qlineedit.h>
45#include <qpushbutton.h> 45#include <qpushbutton.h>
46 46
47//#include <qtimer.h> 47//#include <qtimer.h>
48 48
49#include "playlistselection.h" 49#include "playlistselection.h"
50#include "playlistwidget.h" 50#include "playlistwidget.h"
51#include "mediaplayerstate.h" 51#include "mediaplayerstate.h"
52 52
53#include "inputDialog.h" 53#include "inputDialog.h"
54 54
55#include <stdlib.h> 55#include <stdlib.h>
56 56
57#define BUTTONS_ON_TOOLBAR 57#define BUTTONS_ON_TOOLBAR
58#define SIDE_BUTTONS 58#define SIDE_BUTTONS
59#define CAN_SAVE_LOAD_PLAYLISTS 59#define CAN_SAVE_LOAD_PLAYLISTS
60 60
61extern MediaPlayerState *mediaPlayerState; 61extern MediaPlayerState *mediaPlayerState;
62 62
63// class myFileSelector { 63// class myFileSelector {
64 64
65// }; 65// };
66class PlayListWidgetPrivate { 66class PlayListWidgetPrivate {
67public: 67public:
68 QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; 68 QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove;
69 QFrame *playListFrame; 69 QFrame *playListFrame;
70 FileSelector *files; 70 FileSelector *files;
71 PlayListSelection *selectedFiles; 71 PlayListSelection *selectedFiles;
72 bool setDocumentUsed; 72 bool setDocumentUsed;
73 DocLnk *current; 73 DocLnk *current;
74}; 74};
75 75
76 76
77class ToolButton : public QToolButton { 77class ToolButton : public QToolButton {
78public: 78public:
79 ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) 79 ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE )
80 : QToolButton( parent, name ) { 80 : QToolButton( parent, name ) {
81 setTextLabel( name ); 81 setTextLabel( name );
82 setPixmap( Resource::loadPixmap( icon ) ); 82 setPixmap( Resource::loadPixmap( icon ) );
83 setAutoRaise( TRUE ); 83 setAutoRaise( TRUE );
84 setFocusPolicy( QWidget::NoFocus ); 84 setFocusPolicy( QWidget::NoFocus );
85 setToggleButton( t ); 85 setToggleButton( t );
86 connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); 86 connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot );
87 QPEMenuToolFocusManager::manager()->addWidget( this ); 87 QPEMenuToolFocusManager::manager()->addWidget( this );
88 } 88 }
89}; 89};
90 90
91 91
92class MenuItem : public QAction { 92class MenuItem : public QAction {
93public: 93public:
94 MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) 94 MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot )
95 : QAction( text, QString::null, 0, 0 ) { 95 : QAction( text, QString::null, 0, 0 ) {
96 connect( this, SIGNAL( activated() ), handler, slot ); 96 connect( this, SIGNAL( activated() ), handler, slot );
97 addTo( parent ); 97 addTo( parent );
98 } 98 }
99}; 99};
100 100
101 101
102PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) 102PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
103 : QMainWindow( parent, name, fl ) { 103 : QMainWindow( parent, name, fl ) {
104 104
105 d = new PlayListWidgetPrivate; 105 d = new PlayListWidgetPrivate;
106 d->setDocumentUsed = FALSE; 106 d->setDocumentUsed = FALSE;
107 d->current = NULL; 107 d->current = NULL;
108 fromSetDocument = FALSE;
108// menuTimer = new QTimer( this ,"menu timer"), 109// menuTimer = new QTimer( this ,"menu timer"),
109// connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); 110// connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) );
110 111
111 setBackgroundMode( PaletteButton ); 112 setBackgroundMode( PaletteButton );
112 113
113 setCaption( tr("OpiePlayer") ); 114 setCaption( tr("OpiePlayer") );
114 setIcon( Resource::loadPixmap( "MPEGPlayer" ) ); 115 setIcon( Resource::loadPixmap( "MPEGPlayer" ) );
115 116
116 setToolBarsMovable( FALSE ); 117 setToolBarsMovable( FALSE );
117 118
118 // Create Toolbar 119 // Create Toolbar
119 QPEToolBar *toolbar = new QPEToolBar( this ); 120 QPEToolBar *toolbar = new QPEToolBar( this );
120 toolbar->setHorizontalStretchable( TRUE ); 121 toolbar->setHorizontalStretchable( TRUE );
121 122
122 // Create Menubar 123 // Create Menubar
123 QPEMenuBar *menu = new QPEMenuBar( toolbar ); 124 QPEMenuBar *menu = new QPEMenuBar( toolbar );
124 menu->setMargin( 0 ); 125 menu->setMargin( 0 );
125 126
126 QPEToolBar *bar = new QPEToolBar( this ); 127 QPEToolBar *bar = new QPEToolBar( this );
127 bar->setLabel( tr( "Play Operations" ) ); 128 bar->setLabel( tr( "Play Operations" ) );
128// d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "mpegplayer/play_current_list", 129// d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "mpegplayer/play_current_list",
129// this , SLOT( addSelected()) ); 130// this , SLOT( addSelected()) );
130 tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); 131 tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close");
131 tbDeletePlaylist->setFlat(TRUE); 132 tbDeletePlaylist->setFlat(TRUE);
132 tbDeletePlaylist->setFixedSize(20,20); 133 tbDeletePlaylist->setFixedSize(20,20);
133 connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); 134 connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist()));
134 135
135 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "mpegplayer/add_to_playlist", 136 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "mpegplayer/add_to_playlist",
136 this , SLOT(addSelected()) ); 137 this , SLOT(addSelected()) );
137 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "mpegplayer/remove_from_playlist", 138 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "mpegplayer/remove_from_playlist",
138 this , SLOT(removeSelected()) ); 139 this , SLOT(removeSelected()) );
139// d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); 140// d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE );
140 d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", 141 d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play",
141 this , SLOT( btnPlay(bool) ), TRUE ); 142 this , SLOT( btnPlay(bool) ), TRUE );
142 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"mpegplayer/shuffle", 143 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"mpegplayer/shuffle",
143 mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); 144 mediaPlayerState, SLOT(setShuffled(bool)), TRUE );
144 d->tbLoop = new ToolButton( bar, tr( "Loop" ),"mpegplayer/loop", 145 d->tbLoop = new ToolButton( bar, tr( "Loop" ),"mpegplayer/loop",
145 mediaPlayerState, SLOT(setLooping(bool)), TRUE ); 146 mediaPlayerState, SLOT(setLooping(bool)), TRUE );
146 tbDeletePlaylist->hide(); 147 tbDeletePlaylist->hide();
147 148
148 QPopupMenu *pmPlayList = new QPopupMenu( this ); 149 QPopupMenu *pmPlayList = new QPopupMenu( this );
149 menu->insertItem( tr( "File" ), pmPlayList ); 150 menu->insertItem( tr( "File" ), pmPlayList );
150 new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); 151 new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) );
151 new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); 152 new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) );
152 new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); 153 new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) );
153 new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); 154 new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) );
154 new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); 155 new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) );
155 // new MenuItem( pmPlayList, tr( "Load PlayList" ), this, SLOT( loadList() ) ); 156 // new MenuItem( pmPlayList, tr( "Load PlayList" ), this, SLOT( loadList() ) );
156 157
157 QPopupMenu *pmView = new QPopupMenu( this ); 158 QPopupMenu *pmView = new QPopupMenu( this );
158 menu->insertItem( tr( "View" ), pmView ); 159 menu->insertItem( tr( "View" ), pmView );
159 160
160 fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); 161 fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0);
161 connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); 162 connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) );
162 fullScreenButton->addTo(pmView); 163 fullScreenButton->addTo(pmView);
163 scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("mpegplayer/scale"), QString::null, 0, this, 0); 164 scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("mpegplayer/scale"), QString::null, 0, this, 0);
164 connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); 165 connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) );
165 scaleButton->addTo(pmView); 166 scaleButton->addTo(pmView);
166 167
167 QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); 168 QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton );
168 QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); 169 QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton );
169 170
170 QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); 171 QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton );
171 172
172 tabWidget = new QTabWidget( hbox6, "tabWidget" ); 173 tabWidget = new QTabWidget( hbox6, "tabWidget" );
173 tabWidget->setTabShape(QTabWidget::Triangular); 174 tabWidget->setTabShape(QTabWidget::Triangular);
174 175
175 QWidget *pTab; 176 QWidget *pTab;
176 pTab = new QWidget( tabWidget, "pTab" ); 177 pTab = new QWidget( tabWidget, "pTab" );
177 playlistView = new QListView( pTab, "Videoview" ); 178// playlistView = new QListView( pTab, "playlistview" );
178 playlistView->setMinimumSize(236,260); 179// playlistView->setMinimumSize(236,260);
179 tabWidget->insertTab( pTab,"Playlist"); 180 tabWidget->insertTab( pTab,"Playlist");
180 181
182
181 // Add the playlist area 183 // Add the playlist area
182 184
183 QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); 185 QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton );
184 d->playListFrame = vbox3; 186 d->playListFrame = vbox3;
185 d->playListFrame ->setMinimumSize(235,260); 187 d->playListFrame ->setMinimumSize(235,260);
186 188
187 QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); 189 QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton );
188 190
189 d->selectedFiles = new PlayListSelection( hbox2); 191 d->selectedFiles = new PlayListSelection( hbox2);
190 QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); 192 QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton );
191 193
194 QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold);
195 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
196 this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) );
197
198
192 QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch 199 QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch
193 new ToolButton( vbox1, tr( "Move Up" ), "mpegplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); 200 new ToolButton( vbox1, tr( "Move Up" ), "mpegplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) );
194 new ToolButton( vbox1, tr( "Remove" ), "mpegplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); 201 new ToolButton( vbox1, tr( "Remove" ), "mpegplayer/cut", d->selectedFiles, SLOT(removeSelected()) );
195 new ToolButton( vbox1, tr( "Move Down" ), "mpegplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); 202 new ToolButton( vbox1, tr( "Move Down" ), "mpegplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) );
196 QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch 203 QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch
197 204
198 QWidget *aTab; 205 QWidget *aTab;
199 aTab = new QWidget( tabWidget, "aTab" ); 206 aTab = new QWidget( tabWidget, "aTab" );
200 audioView = new QListView( aTab, "Audioview" ); 207 audioView = new QListView( aTab, "Audioview" );
201 audioView->setMinimumSize(233,260); 208 audioView->setMinimumSize(233,260);
202 audioView->addColumn( "Title",150); 209 audioView->addColumn( "Title",150);
203 audioView->addColumn("Size", 45); 210 audioView->addColumn("Size", 45);
204 audioView->addColumn("Media",35); 211 audioView->addColumn("Media",35);
205 audioView->setColumnAlignment(1, Qt::AlignRight); 212 audioView->setColumnAlignment(1, Qt::AlignRight);
206 audioView->setColumnAlignment(2, Qt::AlignRight); 213 audioView->setColumnAlignment(2, Qt::AlignRight);
214 audioView->setAllColumnsShowFocus(TRUE);
207 tabWidget->insertTab(aTab,"Audio"); 215 tabWidget->insertTab(aTab,"Audio");
216
217 QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold);
218 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
219 this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) );
220
221
208// audioView 222// audioView
209 Global::findDocuments(&files, "audio/*"); 223 Global::findDocuments(&files, "audio/*");
210 QListIterator<DocLnk> dit( files.children() ); 224 QListIterator<DocLnk> dit( files.children() );
211 QString storage; 225 QString storage;
212 for ( ; dit.current(); ++dit ) { 226 for ( ; dit.current(); ++dit ) {
213 QListViewItem * newItem; 227 QListViewItem * newItem;
214 if(dit.current()->file().find("/mnt/cf") != -1 ) storage="CF"; 228 if(dit.current()->file().find("/mnt/cf") != -1 ) storage="CF";
215 else if(dit.current()->file().find("/mnt/hda") != -1 ) storage="CF"; 229 else if(dit.current()->file().find("/mnt/hda") != -1 ) storage="CF";
216 else if(dit.current()->file().find("/mnt/card") != -1 ) storage="SD"; 230 else if(dit.current()->file().find("/mnt/card") != -1 ) storage="SD";
217 else storage="RAM"; 231 else storage="RAM";
218 if ( QFile( dit.current()->file()).exists() ) { 232 if ( QFile( dit.current()->file()).exists() ) {
219 newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage); 233 newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage);
220 newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/musicfile" )); 234 newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/musicfile" ));
221 } 235 }
222 } 236 }
223// videowidget 237// videowidget
224 238
225 QWidget *vTab; 239 QWidget *vTab;
226 vTab = new QWidget( tabWidget, "vTab" ); 240 vTab = new QWidget( tabWidget, "vTab" );
227 videoView = new QListView( vTab, "Videoview" ); 241 videoView = new QListView( vTab, "Videoview" );
228 videoView->setMinimumSize(233,260); 242 videoView->setMinimumSize(233,260);
229 243
230 videoView->addColumn("Title",150); 244 videoView->addColumn("Title",150);
231 videoView->addColumn("Size",45); 245 videoView->addColumn("Size",45);
232 videoView->addColumn("Media",35); 246 videoView->addColumn("Media",35);
233 videoView->setColumnAlignment(1, Qt::AlignRight); 247 videoView->setColumnAlignment(1, Qt::AlignRight);
234 videoView->setColumnAlignment(2, Qt::AlignRight); 248 videoView->setColumnAlignment(2, Qt::AlignRight);
249 videoView->setAllColumnsShowFocus(TRUE);
250 QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold);
251 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
252 this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) );
235 253
236 tabWidget->insertTab( vTab,"Video"); 254 tabWidget->insertTab( vTab,"Video");
237 255
238 Global::findDocuments(&vFiles, "video/*"); 256 Global::findDocuments(&vFiles, "video/*");
239 QListIterator<DocLnk> Vdit( vFiles.children() ); 257 QListIterator<DocLnk> Vdit( vFiles.children() );
240 for ( ; Vdit.current(); ++Vdit ) { 258 for ( ; Vdit.current(); ++Vdit ) {
241 if( Vdit.current()->file().find("/mnt/cf") != -1 ) storage="CF"; 259 if( Vdit.current()->file().find("/mnt/cf") != -1 ) storage="CF";
242 else if( Vdit.current()->file().find("/mnt/hda") != -1 ) storage="CF"; 260 else if( Vdit.current()->file().find("/mnt/hda") != -1 ) storage="CF";
243 else if( Vdit.current()->file().find("/mnt/card") != -1 ) storage="SD"; 261 else if( Vdit.current()->file().find("/mnt/card") != -1 ) storage="SD";
244 else storage="RAM"; 262 else storage="RAM";
245 QListViewItem * newItem; 263 QListViewItem * newItem;
246 if ( QFile( Vdit.current()->file()).exists() ) { 264 if ( QFile( Vdit.current()->file()).exists() ) {
247 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage); 265 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage);
248 newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/videofile" )); 266 newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/videofile" ));
249 } 267 }
250 } 268 }
251 269
252//playlists list 270//playlists list
253 QWidget *LTab; 271 QWidget *LTab;
254 LTab = new QWidget( tabWidget, "LTab" ); 272 LTab = new QWidget( tabWidget, "LTab" );
255 playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy 273 playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy
256 playLists->setMinimumSize(233,260);; 274 playLists->setMinimumSize(233,260);;
257 tabWidget->insertTab(LTab,"Lists"); 275 tabWidget->insertTab(LTab,"Lists");
258 276
259 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); 277 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) );
260// connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); 278// connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
261 279
262 280
263// add the library area 281// add the library area
264 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
265
266 282
267// connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), 283// connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)),
268// this, SLOT( fauxPlay( QListViewItem *) ) ); 284// this, SLOT( fauxPlay( QListViewItem *) ) );
269// connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), 285// connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)),
270// this, SLOT( fauxPlay( QListViewItem *)) ); 286// this, SLOT( fauxPlay( QListViewItem *)) );
271 287
272// connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); 288// connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) );
273// connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); 289// connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) );
274 290
275 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); 291 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) );
276 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); 292 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) );
277 293
278 connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); 294 connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*)));
279 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); 295 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) );
280 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); 296 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) );
281 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); 297 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) );
282 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); 298 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) );
283 299
284 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); 300 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) );
285// connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); 301// connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) );
286 302
287 setCentralWidget( vbox5 ); 303 setCentralWidget( vbox5 );
288 304
289 Config cfg( "MediaPlayer" ); 305 Config cfg( "MediaPlayer" );
290 readConfig( cfg ); 306 readConfig( cfg );
291 QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); 307 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
292// qDebug("currentList is "+currentPlaylist); 308// qDebug("currentList is "+currentPlaylist);
293 loadList(DocLnk( currentPlaylist)); 309 loadList(DocLnk( currentPlaylist));
294 setCaption("OpiePlayer: "+ currentPlaylist ); 310 setCaption("OpiePlayer: "+ currentPlaylist );
295 311
296 initializeStates(); 312 initializeStates();
297} 313}
298 314
299 315
300PlayListWidget::~PlayListWidget() { 316PlayListWidget::~PlayListWidget() {
301 Config cfg( "MediaPlayer" ); 317 Config cfg( "MediaPlayer" );
302 writeConfig( cfg ); 318 writeConfig( cfg );
303 319
304 320
305 if ( d->current ) 321 if ( d->current )
306 delete d->current; 322 delete d->current;
307 delete d; 323 delete d;
308} 324}
309 325
310 326
311void PlayListWidget::initializeStates() { 327void PlayListWidget::initializeStates() {
312 328
313 d->tbPlay->setOn( mediaPlayerState->playing() ); 329 d->tbPlay->setOn( mediaPlayerState->playing() );
314 d->tbLoop->setOn( mediaPlayerState->looping() ); 330 d->tbLoop->setOn( mediaPlayerState->looping() );
315 d->tbShuffle->setOn( mediaPlayerState->shuffled() ); 331 d->tbShuffle->setOn( mediaPlayerState->shuffled() );
316// d->tbFull->setOn( mediaPlayerState->fullscreen() ); 332// d->tbFull->setOn( mediaPlayerState->fullscreen() );
317// d->tbScale->setOn( mediaPlayerState->scaled() ); 333// d->tbScale->setOn( mediaPlayerState->scaled() );
318// d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); 334// d->tbScale->setEnabled( mediaPlayerState->fullscreen() );
319// setPlaylist( mediaPlayerState->playlist() ); 335// setPlaylist( mediaPlayerState->playlist() );
320 setPlaylist( true); 336 setPlaylist( true);
321 d->selectedFiles->first(); 337 d->selectedFiles->first();
322} 338}
323 339
324 340
325void PlayListWidget::readConfig( Config& cfg ) { 341void PlayListWidget::readConfig( Config& cfg ) {
326 cfg.setGroup("PlayList"); 342 cfg.setGroup("PlayList");
327 343
328 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 344 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
329 345
330 for ( int i = 0; i < noOfFiles; i++ ) { 346 for ( int i = 0; i < noOfFiles; i++ ) {
331 QString entryName; 347 QString entryName;
332 entryName.sprintf( "File%i", i + 1 ); 348 entryName.sprintf( "File%i", i + 1 );
333 QString linkFile = cfg.readEntry( entryName ); 349 QString linkFile = cfg.readEntry( entryName );
334 DocLnk lnk( linkFile ); 350 DocLnk lnk( linkFile );
335 if ( lnk.isValid() ) 351 if ( lnk.isValid() )
336 d->selectedFiles->addToSelection( lnk ); 352 d->selectedFiles->addToSelection( lnk );
337 } 353 }
338} 354}
339 355
340 356
341void PlayListWidget::writeConfig( Config& cfg ) const { 357void PlayListWidget::writeConfig( Config& cfg ) const {
342 cfg.setGroup("PlayList"); 358 cfg.setGroup("PlayList");
343 359
344 int noOfFiles = 0; 360 int noOfFiles = 0;
345 361
346 d->selectedFiles->first(); 362 d->selectedFiles->first();
347 do { 363 do {
348 const DocLnk *lnk = d->selectedFiles->current(); 364 const DocLnk *lnk = d->selectedFiles->current();
349 if ( lnk ) { 365 if ( lnk ) {
350 QString entryName; 366 QString entryName;
351 entryName.sprintf( "File%i", noOfFiles + 1 ); 367 entryName.sprintf( "File%i", noOfFiles + 1 );
352 cfg.writeEntry( entryName, lnk->linkFile() ); 368 cfg.writeEntry( entryName, lnk->linkFile() );
353 // if this link does exist, add it so we have the file 369 // if this link does exist, add it so we have the file
354 // next time... 370 // next time...
355 if ( !QFile::exists( lnk->linkFile() ) ) { 371 if ( !QFile::exists( lnk->linkFile() ) ) {
356 // the way writing lnks doesn't really check for out 372 // the way writing lnks doesn't really check for out
357 // of disk space, but check it anyway. 373 // of disk space, but check it anyway.
358 if ( !lnk->writeLink() ) { 374 if ( !lnk->writeLink() ) {
359 QMessageBox::critical( 0, tr("Out of space"), 375 QMessageBox::critical( 0, tr("Out of space"),
360 tr( "There was a problem saving " 376 tr( "There was a problem saving "
361 "the playlist.\n" 377 "the playlist.\n"
362 "Your playlist " 378 "Your playlist "
363 "may be missing some entries\n" 379 "may be missing some entries\n"
364 "the next time you start it." ) 380 "the next time you start it." )
365 ); 381 );
366 } 382 }
367 } 383 }
368 noOfFiles++; 384 noOfFiles++;
369 } 385 }
370 } while ( d->selectedFiles->next() ); 386 } while ( d->selectedFiles->next() );
371 387
372 cfg.writeEntry("NumberOfFiles", noOfFiles ); 388 cfg.writeEntry("NumberOfFiles", noOfFiles );
373 389
374 390
375} 391}
376 392
377 393
378void PlayListWidget::addToSelection( const DocLnk& lnk ) { 394void PlayListWidget::addToSelection( const DocLnk& lnk ) {
379// qDebug("add"); 395// qDebug("add");
380 d->setDocumentUsed = FALSE; 396 d->setDocumentUsed = FALSE;
381 if ( mediaPlayerState->playlist() ) 397 if ( mediaPlayerState->playlist() )
382 d->selectedFiles->addToSelection( lnk ); 398 d->selectedFiles->addToSelection( lnk );
383 else 399 else
384 mediaPlayerState->setPlaying( TRUE ); 400 mediaPlayerState->setPlaying( TRUE );
385} 401}
386 402
387 403
388void PlayListWidget::clearList() { 404void PlayListWidget::clearList() {
389 while ( first() ) 405 while ( first() )
390 d->selectedFiles->removeSelected(); 406 d->selectedFiles->removeSelected();
391} 407}
392 408
393 409
394void PlayListWidget::addAllToList() { 410void PlayListWidget::addAllToList() {
395 DocLnkSet files; 411 DocLnkSet files;
396 Global::findDocuments(&files, "video/*;audio/*"); 412 Global::findDocuments(&files, "video/*;audio/*");
397 QListIterator<DocLnk> dit( files.children() ); 413 QListIterator<DocLnk> dit( files.children() );
398 for ( ; dit.current(); ++dit ) 414 for ( ; dit.current(); ++dit )
399 d->selectedFiles->addToSelection( **dit ); 415 d->selectedFiles->addToSelection( **dit );
400} 416}
401 417
402 418
403void PlayListWidget::addAllMusicToList() { 419void PlayListWidget::addAllMusicToList() {
404 DocLnkSet files; 420 DocLnkSet files;
405 Global::findDocuments(&files, "audio/*"); 421 Global::findDocuments(&files, "audio/*");
406 QListIterator<DocLnk> dit( files.children() ); 422 QListIterator<DocLnk> dit( files.children() );
407 for ( ; dit.current(); ++dit ) 423 for ( ; dit.current(); ++dit )
408 d->selectedFiles->addToSelection( **dit ); 424 d->selectedFiles->addToSelection( **dit );
409} 425}
410 426
411 427
412void PlayListWidget::addAllVideoToList() { 428void PlayListWidget::addAllVideoToList() {
413 DocLnkSet files; 429 DocLnkSet files;
414 Global::findDocuments(&files, "video/*"); 430 Global::findDocuments(&files, "video/*");
415 QListIterator<DocLnk> dit( files.children() ); 431 QListIterator<DocLnk> dit( files.children() );
416 for ( ; dit.current(); ++dit ) 432 for ( ; dit.current(); ++dit )
417 d->selectedFiles->addToSelection( **dit ); 433 d->selectedFiles->addToSelection( **dit );
418} 434}
419 435
420 436
421void PlayListWidget::setDocument(const QString& fileref) { 437void PlayListWidget::setDocument(const QString& fileref) {
438 fromSetDocument = TRUE;
422 if ( fileref.isNull() ) { 439 if ( fileref.isNull() ) {
423 QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); 440 QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) );
424 return; 441 return;
425 } 442 }
426// qDebug("setDocument"); 443// qDebug("setDocument "+fileref);
427 if(fileref.find("playlist",0,TRUE) == -1) { 444 if(fileref.find("playlist",0,TRUE) == -1) {
428 addToSelection( DocLnk( fileref ) ); 445 clearList();
429 d->setDocumentUsed = TRUE; 446 addToSelection( DocLnk( fileref ) );
430 qApp->processEvents(); 447 d->setDocumentUsed = TRUE;
431 mediaPlayerState->setPlaying( FALSE ); 448 mediaPlayerState->setPlaying( FALSE );
432 qApp->processEvents(); 449 qApp->processEvents();
433 mediaPlayerState->setPlaying( TRUE ); 450 mediaPlayerState->setPlaying( TRUE );
434 d->selectedFiles->removeSelected( ); 451 qApp->processEvents();
435 } else { 452 setCaption("OpiePlayer");
453
454 } else { //is playlist
455 clearList();
436 loadList(DocLnk(fileref)); 456 loadList(DocLnk(fileref));
437 d->selectedFiles->first(); 457 d->selectedFiles->first();
438// mediaPlayerState->setPlaying( TRUE );
439// mediaPlayerState->setPlaying( FALSE );
440
441 } 458 }
442} 459}
443 460
444 461
445void PlayListWidget::setActiveWindow() { 462void PlayListWidget::setActiveWindow() {
446 // When we get raised we need to ensure that it switches views 463 // When we get raised we need to ensure that it switches views
447 char origView = mediaPlayerState->view(); 464 char origView = mediaPlayerState->view();
448 mediaPlayerState->setView( 'l' ); // invalidate 465 mediaPlayerState->setView( 'l' ); // invalidate
449 mediaPlayerState->setView( origView ); // now switch back 466 mediaPlayerState->setView( origView ); // now switch back
450} 467}
451 468
452 469
453void PlayListWidget::useSelectedDocument() { 470void PlayListWidget::useSelectedDocument() {
454 d->setDocumentUsed = FALSE; 471 d->setDocumentUsed = FALSE;
455} 472}
456 473
457 474
458const DocLnk *PlayListWidget::current() { 475const DocLnk *PlayListWidget::current() { // this is fugly
459 476
460// qDebug("in Playlist widget ::current"); 477// if( fromSetDocument) {
461 if ( mediaPlayerState->playlist() ) { 478// qDebug("from setDoc");
462 return d->selectedFiles->current(); 479// DocLnkSet files;
463 } 480// Global::findDocuments(&files, "video/*;audio/*");
464 else if ( d->setDocumentUsed && d->current ) { 481// QListIterator<DocLnk> dit( files.children() );
465 return d->current; 482// for ( ; dit.current(); ++dit ) {
466 } else { 483// if(dit.current()->linkFile() == setDocFileRef) {
467 return d->files->selected(); 484// qDebug(setDocFileRef);
468 } 485// return dit;
486// }
487// }
488// } else
489 switch (tabWidget->currentPageIndex()) {
490 case 0: //playlist
491 {
492 if ( mediaPlayerState->playlist() ) {
493 return d->selectedFiles->current();
494 }
495 else if ( d->setDocumentUsed && d->current ) {
496 return d->current;
497 } else {
498 return d->files->selected();
499 }
500 }
501 break;
502 case 1: { //audio
503 Global::findDocuments(&files, "audio/*");
504 QListIterator<DocLnk> dit( files.children() );
505 for ( ; dit.current(); ++dit ) {
506 if( dit.current()->name() == audioView->currentItem()->text(0))
507 return dit;
508 }
509 }
510 break;
511 case 2: { // video
512 Global::findDocuments(&vFiles, "video/*");
513 QListIterator<DocLnk> Vdit( vFiles.children() );
514 for ( ; Vdit.current(); ++Vdit ) {
515 if( Vdit.current()->name() == videoView->currentItem()->text(0))
516 return Vdit;
517 }
518 }
519 break;
520 };
469} 521}
470 522
471
472bool PlayListWidget::prev() { 523bool PlayListWidget::prev() {
473 if ( mediaPlayerState->playlist() ) { 524 if ( mediaPlayerState->playlist() ) {
474 if ( mediaPlayerState->shuffled() ) { 525 if ( mediaPlayerState->shuffled() ) {
475 const DocLnk *cur = current(); 526 const DocLnk *cur = current();
476 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 527 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
477 for ( int i = 0; i < j; i++ ) { 528 for ( int i = 0; i < j; i++ ) {
478 if ( !d->selectedFiles->next() ) 529 if ( !d->selectedFiles->next() )
479 d->selectedFiles->first(); 530 d->selectedFiles->first();
480 } 531 }
481 if ( cur == current() ) 532 if ( cur == current() )
482 if ( !d->selectedFiles->next() ) 533 if ( !d->selectedFiles->next() )
483 d->selectedFiles->first(); 534 d->selectedFiles->first();
484 return TRUE; 535 return TRUE;
485 } else { 536 } else {
486 if ( !d->selectedFiles->prev() ) { 537 if ( !d->selectedFiles->prev() ) {
487 if ( mediaPlayerState->looping() ) { 538 if ( mediaPlayerState->looping() ) {
488 return d->selectedFiles->last(); 539 return d->selectedFiles->last();
489 } else { 540 } else {
490 return FALSE; 541 return FALSE;
491 } 542 }
492 } 543 }
493 return TRUE; 544 return TRUE;
494 } 545 }
495 } else { 546 } else {
496 return mediaPlayerState->looping(); 547 return mediaPlayerState->looping();
497 } 548 }
498} 549}
499 550
500 551
501bool PlayListWidget::next() { 552bool PlayListWidget::next() {
502 if ( mediaPlayerState->playlist() ) { 553 if ( mediaPlayerState->playlist() ) {
503 if ( mediaPlayerState->shuffled() ) { 554 if ( mediaPlayerState->shuffled() ) {
504 return prev(); 555 return prev();
505 } else { 556 } else {
506 if ( !d->selectedFiles->next() ) { 557 if ( !d->selectedFiles->next() ) {
507 if ( mediaPlayerState->looping() ) { 558 if ( mediaPlayerState->looping() ) {
508 return d->selectedFiles->first(); 559 return d->selectedFiles->first();
509 } else { 560 } else {
510 return FALSE; 561 return FALSE;
511 } 562 }
512 } 563 }
513 return TRUE; 564 return TRUE;
514 } 565 }
515 } else { 566 } else {
516 return mediaPlayerState->looping(); 567 return mediaPlayerState->looping();
517 } 568 }
518} 569}
519 570
520 571
521bool PlayListWidget::first() { 572bool PlayListWidget::first() {
522 if ( mediaPlayerState->playlist() ) 573 if ( mediaPlayerState->playlist() )
523 return d->selectedFiles->first(); 574 return d->selectedFiles->first();
524 else 575 else
525 return mediaPlayerState->looping(); 576 return mediaPlayerState->looping();
526} 577}
527 578
528 579
529bool PlayListWidget::last() { 580bool PlayListWidget::last() {
530 if ( mediaPlayerState->playlist() ) 581 if ( mediaPlayerState->playlist() )
531 return d->selectedFiles->last(); 582 return d->selectedFiles->last();
532 else 583 else
533 return mediaPlayerState->looping(); 584 return mediaPlayerState->looping();
534} 585}
535 586
536 587
537void PlayListWidget::saveList() { 588void PlayListWidget::saveList() {
538 589
539 QString filename; 590 QString filename;
540 InputDialog *fileDlg; 591 InputDialog *fileDlg;
541 fileDlg = new InputDialog(this,"Save Playlist",TRUE, 0); 592 fileDlg = new InputDialog(this,"Save Playlist",TRUE, 0);
542 fileDlg->exec(); 593 fileDlg->exec();
543 if( fileDlg->result() == 1 ) { 594 if( fileDlg->result() == 1 ) {
544 if ( d->current ) 595 if ( d->current )
545 delete d->current; 596 delete d->current;
546 filename = fileDlg->LineEdit1->text();//+".playlist"; 597 filename = fileDlg->LineEdit1->text();//+".playlist";
547// qDebug("saving playlist "+filename+".playlist"); 598// qDebug("saving playlist "+filename+".playlist");
548 Config cfg( filename +".playlist"); 599 Config cfg( filename +".playlist");
549 writeConfig( cfg ); 600 writeConfig( cfg );
550 if( playLists->selected()->name() == filename) { 601 if( playLists->selected()->name() == filename) {
551// qDebug("same name so delete lnk"); 602// qDebug("same name so delete lnk");
552 QFile().remove(playLists->selected()->file()); 603 QFile().remove(playLists->selected()->file());
553 QFile().remove(playLists->selected()->linkFile()); 604 QFile().remove(playLists->selected()->linkFile());
554 playLists->reread(); 605 playLists->reread();
555 } 606 }
556 607
557 DocLnk lnk; 608 DocLnk lnk;
558// lnk.setComment( ""); 609// lnk.setComment( "");
559 lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property 610 lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property
560 lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D 611 lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D
561 lnk.setIcon("mpegplayer/playlist2"); 612 lnk.setIcon("mpegplayer/playlist2");
562 lnk.setName( filename); //sets file name 613 lnk.setName( filename); //sets file name
563 if(!lnk.writeLink()) 614 if(!lnk.writeLink())
564 qDebug("Writing doclink did not work"); 615 qDebug("Writing doclink did not work");
565 } 616 }
566 Config config( "MediaPlayer" ); 617 Config config( "MediaPlayer" );
567 config.writeEntry("CurrentPlaylist",filename); 618 config.writeEntry("CurrentPlaylist",filename);
568 setCaption("OpiePlayer: "+filename); 619 setCaption("OpiePlayer: "+filename);
569 d->selectedFiles->first(); 620 d->selectedFiles->first();
570 if(fileDlg) 621 if(fileDlg)
571 delete fileDlg; 622 delete fileDlg;
572
573} 623}
574 624
575
576void PlayListWidget::loadList( const DocLnk & lnk) { 625void PlayListWidget::loadList( const DocLnk & lnk) {
577 QString name= lnk.name(); 626 QString name= lnk.name();
578// qDebug("currentList is "+name); 627// qDebug("currentList is "+name);
579 if( name.length()>1) { 628 if( name.length()>1) {
580 setCaption("OpiePlayer: "+name); 629 setCaption("OpiePlayer: "+name);
581// qDebug("load list "+ name+".playlist"); 630// qDebug("load list "+ name+".playlist");
582 clearList(); 631 clearList();
583 Config cfg( name+".playlist"); 632 Config cfg( name+".playlist");
584 readConfig(cfg); 633 readConfig(cfg);
585 tabWidget->setCurrentPage(0); 634 tabWidget->setCurrentPage(0);
586 Config config( "MediaPlayer" ); 635 Config config( "MediaPlayer" );
587 config.writeEntry("CurrentPlaylist", name); 636 config.writeEntry("CurrentPlaylist", name);
588 d->selectedFiles->first(); 637 d->selectedFiles->first();
589 } 638 }
590} 639}
591 640
592
593void PlayListWidget::setPlaylist( bool shown ) { 641void PlayListWidget::setPlaylist( bool shown ) {
594 if ( shown ) 642 if ( shown )
595 d->playListFrame->show(); 643 d->playListFrame->show();
596 else 644 else
597 d->playListFrame->hide(); 645 d->playListFrame->hide();
598} 646}
599 647
600
601void PlayListWidget::setView( char view ) { 648void PlayListWidget::setView( char view ) {
602 if ( view == 'l' ) 649 if ( view == 'l' )
603 showMaximized(); 650 showMaximized();
604 else 651 else
605 hide(); 652 hide();
606} 653}
607 654
608void PlayListWidget::addSelected() { 655void PlayListWidget::addSelected() {
609 656
610 switch (tabWidget->currentPageIndex()) { 657 switch (tabWidget->currentPageIndex()) {
611 case 0: //playlist 658 case 0: //playlist
612 break; 659 break;
613 case 1: { //audio 660 case 1: { //audio
614 addToSelection( audioView->selectedItem() ); 661 addToSelection( audioView->selectedItem() );
615 } 662 }
616 break; 663 break;
617 case 2: { // video 664 case 2: { // video
618 addToSelection( videoView->selectedItem() ); 665 addToSelection( videoView->selectedItem() );
619 } 666 }
620 break; 667 break;
621 }; 668 };
622} 669}
623 670
624void PlayListWidget::removeSelected() { 671void PlayListWidget::removeSelected() {
625 d->selectedFiles->removeSelected( ); 672 d->selectedFiles->removeSelected( );
626} 673}
627 674
628 675
629void PlayListWidget::playIt( QListViewItem *it) { 676void PlayListWidget::playIt( QListViewItem *it) {
630// d->setDocumentUsed = FALSE; 677// d->setDocumentUsed = FALSE;
631 mediaPlayerState->setPlaying(TRUE); 678 mediaPlayerState->setPlaying(TRUE);
632} 679}
633 680
634void PlayListWidget::addToSelection( QListViewItem *it) { 681void PlayListWidget::addToSelection( QListViewItem *it) {
635 d->setDocumentUsed = FALSE; 682 d->setDocumentUsed = FALSE;
636 683
637 if(it) { 684 if(it) {
638// qDebug("add to selection"); 685// qDebug("add to selection");
639 switch (tabWidget->currentPageIndex()) { 686 switch (tabWidget->currentPageIndex()) {
640 case 1: { 687 case 1: {
641// qDebug("case 1"); 688// qDebug("case 1");
642 QListIterator<DocLnk> dit( files.children() ); 689 QListIterator<DocLnk> dit( files.children() );
643 for ( ; dit.current(); ++dit ) { 690 for ( ; dit.current(); ++dit ) {
644// qDebug(dit.current()->name()); 691// qDebug(dit.current()->name());
645 if( dit.current()->name() == it->text(0)) { 692 if( dit.current()->name() == it->text(0)) {
646 d->selectedFiles->addToSelection( **dit ); 693 d->selectedFiles->addToSelection( **dit );
647 } 694 }
648 } 695 }
649 } 696 }
650 break; 697 break;
651 case 2: { 698 case 2: {
652// qDebug("case 2"); 699// qDebug("case 2");
653 QListIterator<DocLnk> dit( vFiles.children() ); 700 QListIterator<DocLnk> dit( vFiles.children() );
654 for ( ; dit.current(); ++dit ) { 701 for ( ; dit.current(); ++dit ) {
655// qDebug(dit.current()->name()); 702// qDebug(dit.current()->name());
656 if( dit.current()->name() == it->text(0)) { 703 if( dit.current()->name() == it->text(0)) {
657 d->selectedFiles->addToSelection( **dit ); 704 d->selectedFiles->addToSelection( **dit );
658 } 705 }
659 } 706 }
660 } 707 }
661 break; 708 break;
662 case 0: 709 case 0:
663 break; 710 break;
664 }; 711 };
665 tabWidget->setCurrentPage(0); 712 tabWidget->setCurrentPage(0);
666// mediaPlayerState->setPlaying( TRUE ); 713// mediaPlayerState->setPlaying( TRUE );
667 } 714 }
668} 715}
669 716
670void PlayListWidget::tabChanged(QWidget *widg) { 717void PlayListWidget::tabChanged(QWidget *widg) {
671 718
672 switch ( tabWidget->currentPageIndex()) { 719 switch ( tabWidget->currentPageIndex()) {
673 case 0: 720 case 0:
674 { 721 {
675 if( !tbDeletePlaylist->isHidden()) 722 if( !tbDeletePlaylist->isHidden())
676 tbDeletePlaylist->hide(); 723 tbDeletePlaylist->hide();
677 d->tbRemoveFromList->setEnabled(TRUE); 724 d->tbRemoveFromList->setEnabled(TRUE);
678 d->tbAddToList->setEnabled(FALSE); 725 d->tbAddToList->setEnabled(FALSE);
679 } 726 }
680 break; 727 break;
681 case 1: 728 case 1:
682 { 729 {
683 if( !tbDeletePlaylist->isHidden()) 730 if( !tbDeletePlaylist->isHidden())
684 tbDeletePlaylist->hide(); 731 tbDeletePlaylist->hide();
685 d->tbRemoveFromList->setEnabled(FALSE); 732 d->tbRemoveFromList->setEnabled(FALSE);
686 d->tbAddToList->setEnabled(TRUE); 733 d->tbAddToList->setEnabled(TRUE);
687 } 734 }
688 break; 735 break;
689 case 2: 736 case 2:
690 { 737 {
691 if( !tbDeletePlaylist->isHidden()) 738 if( !tbDeletePlaylist->isHidden())
692 tbDeletePlaylist->hide(); 739 tbDeletePlaylist->hide();
693 d->tbRemoveFromList->setEnabled(FALSE); 740 d->tbRemoveFromList->setEnabled(FALSE);
694 d->tbAddToList->setEnabled(TRUE); 741 d->tbAddToList->setEnabled(TRUE);
695 } 742 }
696 break; 743 break;
697 case 3: 744 case 3:
698 { 745 {
699 if( tbDeletePlaylist->isHidden()) 746 if( tbDeletePlaylist->isHidden())
700 tbDeletePlaylist->show(); 747 tbDeletePlaylist->show();
701 playLists->reread(); 748 playLists->reread();
702 } 749 }
703 break; 750 break;
704 }; 751 };
705} 752}
706 753
707/*
708 list is right clicked*/
709void PlayListWidget::fauxPlay(QListViewItem *it) {
710
711 switch (tabWidget->currentPageIndex()) {
712 case 0: //playlist
713 break;
714 case 1: { //audio
715 QListIterator<DocLnk> dit( files.children() );
716 for ( ; dit.current(); ++dit ) {
717// qDebug(dit.current()->name());
718 if( dit.current()->name() == it->text(0)) {
719 d->selectedFiles->addToSelection( **dit );
720 }
721 }
722 }
723 break;
724 case 2: { // video
725 QListIterator<DocLnk> dit( vFiles.children() );
726 for ( ; dit.current(); ++dit ) {
727// qDebug(dit.current()->name());
728 if( dit.current()->name() == it->text(0)) {
729 d->selectedFiles->addToSelection( **dit );
730 }
731 }
732 }
733 break;
734 };
735 mediaPlayerState->setPlaying( TRUE );
736// tabWidget->setCurrentPage(0);
737 d->selectedFiles->removeSelected();
738}
739 754
740/* 755/*
741 play button is pressed*/ 756 play button is pressed*/
742void PlayListWidget::btnPlay(bool b) { // this is fugly 757void PlayListWidget::btnPlay(bool b) {
743 switch ( tabWidget->currentPageIndex()) { 758 mediaPlayerState->setPlaying(b);
744 case 0:
745 {
746 mediaPlayerState->setPlaying(b);
747 }
748 break;
749 case 1:
750 {
751 addToSelection( audioView->selectedItem() );
752 mediaPlayerState->setPlaying(b);
753 qApp->processEvents();
754 d->selectedFiles->removeSelected( );
755 tabWidget->setCurrentPage(1);
756 }
757 break;
758 case 2:
759 {
760 addToSelection( videoView->selectedItem() );
761 mediaPlayerState->setPlaying(b);
762 qApp->processEvents();
763 d->selectedFiles->removeSelected( );
764 tabWidget->setCurrentPage(2);
765 }
766 break;
767 };
768
769} 759}
770 760
771void PlayListWidget::deletePlaylist() { 761void PlayListWidget::deletePlaylist() {
772 switch( QMessageBox::information( this, (tr("Remove Playlist?")), 762 switch( QMessageBox::information( this, (tr("Remove Playlist?")),
773 (tr("You really want to delete\nthis playlist?")), 763 (tr("You really want to delete\nthis playlist?")),
774 (tr("Yes")), (tr("No")), 0 )){ 764 (tr("Yes")), (tr("No")), 0 )){
775 case 0: // Yes clicked, 765 case 0: // Yes clicked,
776 QFile().remove(playLists->selected()->file()); 766 QFile().remove(playLists->selected()->file());
777 QFile().remove(playLists->selected()->linkFile()); 767 QFile().remove(playLists->selected()->linkFile());
778 playLists->reread(); 768 playLists->reread();
779 break; 769 break;
780 case 1: // Cancel 770 case 1: // Cancel
781 break; 771 break;
782 }; 772 };
783 773
784} 774}
775
776void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i)
777{
778 switch (mouse) {
779 case 1:
780 break;
781 case 2:{
782 QPopupMenu m;
783 m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
784 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() ));
785// m.insertSeparator();
786// m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() ));
787 m.exec( QCursor::pos() );
788 }
789 break;
790 };
791
792}
793
794void PlayListWidget::playSelected()
795{
796 btnPlay( TRUE);
797}
798
799void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *item, const QPoint& point, int i)
800{
801 switch (mouse) {
802 case 1:
803 break;
804 case 2:{
805 QPopupMenu m;
806 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() ));
807 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
808// m.insertSeparator();
809 m.exec( QCursor::pos() );
810 }
811 break;
812 };
813
814}
diff --git a/core/multimedia/opieplayer/playlistwidget.h b/core/multimedia/opieplayer/playlistwidget.h
index e72551b..effc600 100644
--- a/core/multimedia/opieplayer/playlistwidget.h
+++ b/core/multimedia/opieplayer/playlistwidget.h
@@ -1,102 +1,107 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef PLAY_LIST_WIDGET_H 20#ifndef PLAY_LIST_WIDGET_H
21#define PLAY_LIST_WIDGET_H 21#define PLAY_LIST_WIDGET_H
22 22
23#include <qmainwindow.h> 23#include <qmainwindow.h>
24#include <qpe/applnk.h> 24#include <qpe/applnk.h>
25#include <qtabwidget.h> 25#include <qtabwidget.h>
26#include <qpe/fileselector.h> 26#include <qpe/fileselector.h>
27#include <qpushbutton.h> 27#include <qpushbutton.h>
28 28
29/* #include <qtimer.h> */ 29/* #include <qtimer.h> */
30 30
31 31
32class PlayListWidgetPrivate; 32class PlayListWidgetPrivate;
33class Config; 33class Config;
34class QListViewItem; 34class QListViewItem;
35class QListView; 35class QListView;
36class QPoint; 36class QPoint;
37class QAction; 37class QAction;
38class QLabel; 38class QLabel;
39 39
40class PlayListWidget : public QMainWindow { 40class PlayListWidget : public QMainWindow {
41 Q_OBJECT 41 Q_OBJECT
42public: 42public:
43 PlayListWidget( QWidget* parent=0, const char* name=0, WFlags fl=0 ); 43 PlayListWidget( QWidget* parent=0, const char* name=0, WFlags fl=0 );
44 ~PlayListWidget(); 44 ~PlayListWidget();
45 QTabWidget * tabWidget; 45 QTabWidget * tabWidget;
46 QAction *fullScreenButton, *scaleButton; 46 QAction *fullScreenButton, *scaleButton;
47 DocLnkSet files; 47 DocLnkSet files;
48 DocLnkSet vFiles; 48 DocLnkSet vFiles;
49 QListView *audioView, *videoView, *playlistView; 49 QListView *audioView, *videoView, *playlistView;
50 QLabel *libString; 50 QLabel *libString;
51 bool fromSetDocument;
52 QString setDocFileRef;
51 // retrieve the current playlist entry (media file link) 53 // retrieve the current playlist entry (media file link)
52 const DocLnk *current(); 54 const DocLnk *current();
53 void useSelectedDocument(); 55 void useSelectedDocument();
54/* QTimer * menuTimer; */ 56/* QTimer * menuTimer; */
55 FileSelector* playLists; 57 FileSelector* playLists;
56 QPushButton *tbDeletePlaylist; 58 QPushButton *tbDeletePlaylist;
57public slots: 59public slots:
58 void setDocument( const QString& fileref ); 60 void setDocument( const QString& fileref );
59 void addToSelection( const DocLnk& ); // Add a media file to the playlist 61 void addToSelection( const DocLnk& ); // Add a media file to the playlist
60 void addToSelection( QListViewItem* ); // Add a media file to the playlist 62 void addToSelection( QListViewItem* ); // Add a media file to the playlist
61 void setActiveWindow(); // need to handle this to show the right view 63 void setActiveWindow(); // need to handle this to show the right view
62 void setPlaylist( bool ); // Show/Hide the playlist 64 void setPlaylist( bool ); // Show/Hide the playlist
63 void setView( char ); 65 void setView( char );
64 void clearList(); 66 void clearList();
65 void addAllToList(); 67 void addAllToList();
66 void addAllMusicToList(); 68 void addAllMusicToList();
67 void addAllVideoToList(); 69 void addAllVideoToList();
68 void saveList(); // Save the playlist 70 void saveList(); // Save the playlist
69 void loadList( const DocLnk &); // Load a playlist 71 void loadList( const DocLnk &); // Load a playlist
70 void playIt( QListViewItem *); 72 void playIt( QListViewItem *);
71 void fauxPlay(QListViewItem *); 73
72 void btnPlay(bool); 74 void btnPlay(bool);
73 void deletePlaylist(); 75 void deletePlaylist();
74 bool first(); 76 bool first();
75 bool last(); 77 bool last();
76 bool next(); 78 bool next();
77 bool prev(); 79 bool prev();
78 void addSelected(); 80 void addSelected();
79 void removeSelected(); 81 void removeSelected();
80 void tabChanged(QWidget*); 82 void tabChanged(QWidget*);
83 void viewPressed( int, QListViewItem *, const QPoint&, int);
84 void playlistViewPressed( int, QListViewItem *, const QPoint&, int);
85 void playSelected();
81/* void setFullScreen(); */ 86/* void setFullScreen(); */
82/* void setScaled(); */ 87/* void setScaled(); */
83protected: 88protected:
84/* void contentsMousePressEvent( QMouseEvent * e ); */ 89/* void contentsMousePressEvent( QMouseEvent * e ); */
85/* void contentsMouseReleaseEvent( QMouseEvent * e ); */ 90/* void contentsMouseReleaseEvent( QMouseEvent * e ); */
86 91
87private: 92private:
88 void initializeStates(); 93 void initializeStates();
89 void readConfig( Config& cfg ); 94 void readConfig( Config& cfg );
90 void writeConfig( Config& cfg ) const; 95 void writeConfig( Config& cfg ) const;
91 PlayListWidgetPrivate *d; // Private implementation data 96 PlayListWidgetPrivate *d; // Private implementation data
92 97
93protected slots: 98protected slots:
94/* void cancelMenuTimer(); */ 99/* void cancelMenuTimer(); */
95/* void showFileMenu(); */ 100/* void showFileMenu(); */
96 101
97 102
98}; 103};
99 104
100 105
101#endif // PLAY_LIST_WIDGET_H 106#endif // PLAY_LIST_WIDGET_H
102 107
diff --git a/core/multimedia/opieplayer/videowidget.cpp b/core/multimedia/opieplayer/videowidget.cpp
index be838c4..bb5f9e8 100644
--- a/core/multimedia/opieplayer/videowidget.cpp
+++ b/core/multimedia/opieplayer/videowidget.cpp
@@ -1,423 +1,471 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qpe/resource.h> 20#include <qpe/resource.h>
21#include <qpe/mediaplayerplugininterface.h> 21#include <qpe/mediaplayerplugininterface.h>
22#include <qwidget.h> 22#include <qwidget.h>
23#include <qpainter.h> 23#include <qpainter.h>
24#include <qpixmap.h> 24#include <qpixmap.h>
25#include <qslider.h> 25#include <qslider.h>
26#include <qdrawutil.h> 26#include <qdrawutil.h>
27#include "videowidget.h" 27#include "videowidget.h"
28#include "mediaplayerstate.h" 28#include "mediaplayerstate.h"
29 29
30 30
31#ifdef Q_WS_QWS 31#ifdef Q_WS_QWS
32# define USE_DIRECT_PAINTER 32# define USE_DIRECT_PAINTER
33# include <qdirectpainter_qws.h> 33# include <qdirectpainter_qws.h>
34# include <qgfxraster_qws.h> 34# include <qgfxraster_qws.h>
35#endif 35#endif
36 36
37 37
38extern MediaPlayerState *mediaPlayerState; 38extern MediaPlayerState *mediaPlayerState;
39 39
40 40
41static const int xo = 2; // movable x offset 41static const int xo = 2; // movable x offset
42static const int yo = 0; // movable y offset 42static const int yo = 0; // movable y offset
43 43
44 44
45struct MediaButton { 45struct MediaButton {
46 int xPos, yPos; 46 int xPos, yPos;
47 bool isToggle, isHeld, isDown; 47 bool isToggle, isHeld, isDown;
48 int controlType; 48 int controlType;
49}; 49};
50 50
51 51
52// Layout information for the videoButtons (and if it is a toggle button or not) 52// Layout information for the videoButtons (and if it is a toggle button or not)
53MediaButton videoButtons[] = { 53MediaButton videoButtons[] = {
54 { 5+0*32+xo, 200+yo, FALSE, FALSE, FALSE, 4 }, // previous 54 { 5+0*32+xo, 200+yo, FALSE, FALSE, FALSE, 4 }, // previous
55 { 5+1*32+xo, 200+yo, FALSE, FALSE, FALSE, 1 }, // stop 55 { 5+1*32+xo, 200+yo, FALSE, FALSE, FALSE, 1 }, // stop
56 { 5+2*32+xo, 200+yo, TRUE, FALSE, FALSE, 0 }, // play 56 { 5+2*32+xo, 200+yo, TRUE, FALSE, FALSE, 0 }, // play
57 { 5+3*32+xo, 200+yo, TRUE, FALSE, FALSE, 2 }, // pause 57 { 5+3*32+xo, 200+yo, TRUE, FALSE, FALSE, 2 }, // pause
58 { 5+4*32+xo, 200+yo, FALSE, FALSE, FALSE, 3 }, // next 58 { 5+4*32+xo, 200+yo, FALSE, FALSE, FALSE, 3 }, // next
59 { 5+5*32+xo, 200+yo, FALSE, FALSE, FALSE, 8 }, // playlist 59 { 5+5*32+xo, 200+yo, FALSE, FALSE, FALSE, 8 }, // playlist
60 { 5+6*32+xo, 200+yo, TRUE, FALSE, FALSE, 9 } // fullscreen 60 { 5+6*32+xo, 200+yo, TRUE, FALSE, FALSE, 9 } // fullscreen
61}; 61};
62 62
63 63
64static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); 64static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton));
65 65
66 66
67VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : 67VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) :
68 QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) { 68 QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) {
69 setCaption( tr("OpiePlayer") ); 69 setCaption( tr("OpiePlayer") );
70 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 70 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
71 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0a" ) ); 71 pixmaps[0] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0a" ) );
72 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0b" ) ); 72 pixmaps[1] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaButton0b" ) );
73 pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls0" ) ); 73 pixmaps[2] = new QPixmap( Resource::loadPixmap( "mpegplayer/mediaControls0" ) );
74 currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); 74 currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 );
75 75
76 slider = new QSlider( Qt::Horizontal, this ); 76 slider = new QSlider( Qt::Horizontal, this );
77 slider->setMinValue( 0 ); 77 slider->setMinValue( 0 );
78 slider->setMaxValue( 1 ); 78 slider->setMaxValue( 1 );
79 slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 79 slider->setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
80 slider->setFocusPolicy( QWidget::NoFocus ); 80 slider->setFocusPolicy( QWidget::NoFocus );
81 slider->setGeometry( QRect( 7, 250, 220, 20 ) ); 81 slider->setGeometry( QRect( 7, 250, 220, 20 ) );
82 82
83 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 83 connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
84 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 84 connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
85 85
86 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); 86 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) );
87 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); 87 connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) );
88 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); 88 connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) );
89 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); 89 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) );
90 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); 90 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
91 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); 91 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) );
92 92
93 // Intialise state 93 // Intialise state
94 setLength( mediaPlayerState->length() ); 94 setLength( mediaPlayerState->length() );
95 setPosition( mediaPlayerState->position() ); 95 setPosition( mediaPlayerState->position() );
96 setFullscreen( mediaPlayerState->fullscreen() ); 96 setFullscreen( mediaPlayerState->fullscreen() );
97 setPaused( mediaPlayerState->paused() ); 97 setPaused( mediaPlayerState->paused() );
98 setPlaying( mediaPlayerState->playing() ); 98 setPlaying( mediaPlayerState->playing() );
99} 99}
100 100
101 101
102VideoWidget::~VideoWidget() { 102VideoWidget::~VideoWidget() {
103 for ( int i = 0; i < 3; i++ ) 103 for ( int i = 0; i < 3; i++ )
104 delete pixmaps[i]; 104 delete pixmaps[i];
105 delete currentFrame; 105 delete currentFrame;
106} 106}
107 107
108 108
109static bool videoSliderBeingMoved = FALSE; 109static bool videoSliderBeingMoved = FALSE;
110 110
111 111
112void VideoWidget::sliderPressed() { 112void VideoWidget::sliderPressed() {
113 videoSliderBeingMoved = TRUE; 113 videoSliderBeingMoved = TRUE;
114} 114}
115 115
116 116
117void VideoWidget::sliderReleased() { 117void VideoWidget::sliderReleased() {
118 videoSliderBeingMoved = FALSE; 118 videoSliderBeingMoved = FALSE;
119 if ( slider->width() == 0 ) 119 if ( slider->width() == 0 )
120 return; 120 return;
121 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); 121 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width());
122 mediaPlayerState->setPosition( val ); 122 mediaPlayerState->setPosition( val );
123} 123}
124 124
125 125
126void VideoWidget::setPosition( long i ) { 126void VideoWidget::setPosition( long i ) {
127 updateSlider( i, mediaPlayerState->length() ); 127 updateSlider( i, mediaPlayerState->length() );
128} 128}
129 129
130 130
131void VideoWidget::setLength( long max ) { 131void VideoWidget::setLength( long max ) {
132 updateSlider( mediaPlayerState->position(), max ); 132 updateSlider( mediaPlayerState->position(), max );
133} 133}
134 134
135 135
136void VideoWidget::setView( char view ) { 136void VideoWidget::setView( char view ) {
137 if ( view == 'v' ) { 137 if ( view == 'v' ) {
138 makeVisible(); 138 makeVisible();
139 } else { 139 } else {
140 // Effectively blank the view next time we show it so it looks nicer 140 // Effectively blank the view next time we show it so it looks nicer
141 scaledWidth = 0; 141 scaledWidth = 0;
142 scaledHeight = 0; 142 scaledHeight = 0;
143 hide(); 143 hide();
144 } 144 }
145} 145}
146 146
147 147
148void VideoWidget::updateSlider( long i, long max ) { 148void VideoWidget::updateSlider( long i, long max ) {
149 // Will flicker too much if we don't do this 149 // Will flicker too much if we don't do this
150 if ( max == 0 ) 150 if ( max == 0 )
151 return; 151 return;
152 int width = slider->width(); 152 int width = slider->width();
153 int val = int((double)i * width / max); 153 int val = int((double)i * width / max);
154 if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) { 154 if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) {
155 if ( slider->value() != val ) 155 if ( slider->value() != val )
156 slider->setValue( val ); 156 slider->setValue( val );
157 if ( slider->maxValue() != width ) 157 if ( slider->maxValue() != width )
158 slider->setMaxValue( width ); 158 slider->setMaxValue( width );
159 } 159 }
160} 160}
161 161
162 162
163void VideoWidget::setToggleButton( int i, bool down ) { 163void VideoWidget::setToggleButton( int i, bool down ) {
164 if ( down != videoButtons[i].isDown ) 164 if ( down != videoButtons[i].isDown )
165 toggleButton( i ); 165 toggleButton( i );
166} 166}
167 167
168 168
169void VideoWidget::toggleButton( int i ) { 169void VideoWidget::toggleButton( int i ) {
170 videoButtons[i].isDown = !videoButtons[i].isDown; 170 videoButtons[i].isDown = !videoButtons[i].isDown;
171 QPainter p(this); 171 QPainter p(this);
172 paintButton ( &p, i ); 172 paintButton ( &p, i );
173} 173}
174 174
175 175
176void VideoWidget::paintButton( QPainter *p, int i ) { 176void VideoWidget::paintButton( QPainter *p, int i ) {
177 int x = videoButtons[i].xPos; 177 int x = videoButtons[i].xPos;
178 int y = videoButtons[i].yPos; 178 int y = videoButtons[i].yPos;
179 int offset = 10 + videoButtons[i].isDown; 179 int offset = 10 + videoButtons[i].isDown;
180 p->drawPixmap( x, y, *pixmaps[videoButtons[i].isDown] ); 180 p->drawPixmap( x, y, *pixmaps[videoButtons[i].isDown] );
181 p->drawPixmap( x + 1 + offset, y + offset, *pixmaps[2], 9 * videoButtons[i].controlType, 0, 9, 9 ); 181 p->drawPixmap( x + 1 + offset, y + offset, *pixmaps[2], 9 * videoButtons[i].controlType, 0, 9, 9 );
182} 182}
183 183
184 184
185void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { 185void VideoWidget::mouseMoveEvent( QMouseEvent *event ) {
186 for ( int i = 0; i < numButtons; i++ ) { 186 for ( int i = 0; i < numButtons; i++ ) {
187 int x = videoButtons[i].xPos; 187 int x = videoButtons[i].xPos;
188 int y = videoButtons[i].yPos; 188 int y = videoButtons[i].yPos;
189 if ( event->state() == QMouseEvent::LeftButton ) { 189 if ( event->state() == QMouseEvent::LeftButton ) {
190 // The test to see if the mouse click is inside the circular button or not 190 // The test to see if the mouse click is inside the circular button or not
191 // (compared with the radius squared to avoid a square-root of our distance) 191 // (compared with the radius squared to avoid a square-root of our distance)
192 int radius = 16; 192 int radius = 16;
193 QPoint center = QPoint( x + radius, y + radius ); 193 QPoint center = QPoint( x + radius, y + radius );
194 QPoint dXY = center - event->pos(); 194 QPoint dXY = center - event->pos();
195 int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); 195 int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y();
196 bool isOnButton = dist <= (radius * radius); 196 bool isOnButton = dist <= (radius * radius);
197 if ( isOnButton != videoButtons[i].isHeld ) { 197 if ( isOnButton != videoButtons[i].isHeld ) {
198 videoButtons[i].isHeld = isOnButton; 198 videoButtons[i].isHeld = isOnButton;
199 toggleButton(i); 199 toggleButton(i);
200 } 200 }
201 } else { 201 } else {
202 if ( videoButtons[i].isHeld ) { 202 if ( videoButtons[i].isHeld ) {
203 videoButtons[i].isHeld = FALSE; 203 videoButtons[i].isHeld = FALSE;
204 if ( !videoButtons[i].isToggle ) 204 if ( !videoButtons[i].isToggle )
205 setToggleButton( i, FALSE ); 205 setToggleButton( i, FALSE );
206 switch (i) { 206 switch (i) {
207 case VideoPlay: mediaPlayerState->setPlaying(videoButtons[i].isDown); return; 207 case VideoPlay: mediaPlayerState->setPlaying(videoButtons[i].isDown); return;
208 case VideoStop: mediaPlayerState->setPlaying(FALSE); return; 208 case VideoStop: mediaPlayerState->setPlaying(FALSE); return;
209 case VideoPause: mediaPlayerState->setPaused(videoButtons[i].isDown); return; 209 case VideoPause: mediaPlayerState->setPaused(videoButtons[i].isDown); return;
210 case VideoNext: mediaPlayerState->setNext(); return; 210 case VideoNext: mediaPlayerState->setNext(); return;
211 case VideoPrevious: mediaPlayerState->setPrev(); return; 211 case VideoPrevious: mediaPlayerState->setPrev(); return;
212 case VideoPlayList: mediaPlayerState->setList(); return; 212 case VideoPlayList: mediaPlayerState->setList(); return;
213 case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; 213 case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return;
214 } 214 }
215 } 215 }
216 } 216 }
217 } 217 }
218} 218}
219 219
220 220
221void VideoWidget::mousePressEvent( QMouseEvent *event ) { 221void VideoWidget::mousePressEvent( QMouseEvent *event ) {
222 mouseMoveEvent( event ); 222 mouseMoveEvent( event );
223} 223}
224 224
225 225
226void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { 226void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) {
227 if ( mediaPlayerState->fullscreen() ) { 227 if ( mediaPlayerState->fullscreen() ) {
228 mediaPlayerState->setFullscreen( FALSE ); 228 mediaPlayerState->setFullscreen( FALSE );
229 makeVisible(); 229 makeVisible();
230 } else { 230
231 mouseMoveEvent( event ); 231 mouseMoveEvent( event );
232 } 232 }
233} 233}
234 234
235 235
236void VideoWidget::makeVisible() { 236void VideoWidget::makeVisible() {
237 if ( mediaPlayerState->fullscreen() ) { 237 if ( mediaPlayerState->fullscreen() ) {
238 setBackgroundMode( QWidget::NoBackground ); 238 setBackgroundMode( QWidget::NoBackground );
239 showFullScreen(); 239 showFullScreen();
240 resize( qApp->desktop()->size() ); 240 resize( qApp->desktop()->size() );
241 slider->hide(); 241 slider->hide();
242 } else { 242 } else {
243 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) ); 243 setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/metalFinish" ) );
244 showNormal(); 244 showNormal();
245 showMaximized(); 245 showMaximized();
246 slider->show(); 246 slider->show();
247 } 247 }
248} 248}
249 249
250 250
251void VideoWidget::paintEvent( QPaintEvent * ) { 251void VideoWidget::paintEvent( QPaintEvent * ) {
252 QPainter p( this ); 252 QPainter p( this );
253 253
254 if ( mediaPlayerState->fullscreen() ) { 254 if ( mediaPlayerState->fullscreen() ) {
255 // Clear the background 255 // Clear the background
256 p.setBrush( QBrush( Qt::black ) ); 256 p.setBrush( QBrush( Qt::black ) );
257 p.drawRect( rect() ); 257 p.drawRect( rect() );
258 258
259 // Draw the current frame 259 // Draw the current frame
260 //p.drawImage( ); // If using directpainter we won't have a copy except whats on the screen 260 //p.drawImage( ); // If using directpainter we won't have a copy except whats on the screen
261 } else { 261 } else {
262 // draw border 262 // draw border
263 qDrawShadePanel( &p, 4, 15, 230, 170, colorGroup(), TRUE, 5, NULL ); 263 qDrawShadePanel( &p, 4, 15, 230, 170, colorGroup(), TRUE, 5, NULL );
264 264
265 // Clear the movie screen first 265 // Clear the movie screen first
266 p.setBrush( QBrush( Qt::black ) ); 266 p.setBrush( QBrush( Qt::black ) );
267 p.drawRect( 9, 20, 220, 160 ); 267 p.drawRect( 9, 20, 220, 160 );
268 268
269 // draw current frame (centrally positioned from scaling to maintain aspect ratio) 269 // draw current frame (centrally positioned from scaling to maintain aspect ratio)
270 p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); 270 p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight );
271 271
272 // draw the buttons 272 // draw the buttons
273 for ( int i = 0; i < numButtons; i++ ) 273 for ( int i = 0; i < numButtons; i++ )
274 paintButton( &p, i ); 274 paintButton( &p, i );
275 275
276 // draw the slider 276 // draw the slider
277 slider->repaint( TRUE ); 277 slider->repaint( TRUE );
278 } 278 }
279} 279}
280 280
281 281
282void VideoWidget::closeEvent( QCloseEvent* ) { 282void VideoWidget::closeEvent( QCloseEvent* ) {
283 mediaPlayerState->setList(); 283 mediaPlayerState->setList();
284} 284}
285 285
286 286
287bool VideoWidget::playVideo() { 287bool VideoWidget::playVideo() {
288 bool result = FALSE; 288 bool result = FALSE;
289 289
290 int stream = 0; 290 int stream = 0;
291 291
292 int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); 292 int sw = mediaPlayerState->curDecoder()->videoWidth( stream );
293 int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); 293 int sh = mediaPlayerState->curDecoder()->videoHeight( stream );
294 int dd = QPixmap::defaultDepth(); 294 int dd = QPixmap::defaultDepth();
295 int w = height(); 295 int w = height();
296 int h = width(); 296 int h = width();
297 297
298 ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; 298 ColorFormat format = (dd == 16) ? RGB565 : BGRA8888;
299 299
300 if ( mediaPlayerState->fullscreen() ) { 300 if ( mediaPlayerState->fullscreen() ) {
301#ifdef USE_DIRECT_PAINTER 301#ifdef USE_DIRECT_PAINTER
302 QDirectPainter p(this); 302 QDirectPainter p(this);
303 303
304 if ( ( qt_screen->transformOrientation() == 3 ) && 304 if ( ( qt_screen->transformOrientation() == 3 ) &&
305 ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) { 305 ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) {
306 306
307 w = 320; 307 w = 320;
308 h = 240; 308 h = 240;
309 309
310 if ( mediaPlayerState->scaled() ) { 310 if ( mediaPlayerState->scaled() ) {
311 // maintain aspect ratio 311 // maintain aspect ratio
312 if ( w * sh > sw * h ) 312 if ( w * sh > sw * h )
313 w = sw * h / sh; 313 w = sw * h / sh;
314 else 314 else
315 h = sh * w / sw; 315 h = sh * w / sw;
316 } else { 316 } else {
317 w = sw; 317 w = sw;
318 h = sh; 318 h = sh;
319 } 319 }
320 320
321 w--; // we can't allow libmpeg to overwrite. 321 w--; // we can't allow libmpeg to overwrite.
322 QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); 322 QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) );
323 323
324 int ox = roff.x() - height() + 2 + (height() - w) / 2; 324 int ox = roff.x() - height() + 2 + (height() - w) / 2;
325 int oy = roff.y() + (width() - h) / 2; 325 int oy = roff.y() + (width() - h) / 2;
326 int sx = 0, sy = 0; 326 int sx = 0, sy = 0;
327 327
328 uchar* fp = p.frameBuffer() + p.lineStep() * oy; 328 uchar* fp = p.frameBuffer() + p.lineStep() * oy;
329 fp += dd * ox / 8; 329 fp += dd * ox / 8;
330 uchar **jt = new uchar*[h]; 330 uchar **jt = new uchar*[h];
331 for ( int i = h; i; i-- ) { 331 for ( int i = h; i; i-- ) {
332 jt[h - i] = fp; 332 jt[h - i] = fp;
333 fp += p.lineStep(); 333 fp += p.lineStep();
334 } 334 }
335 335
336 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; 336 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0;
337 337
338 delete [] jt; 338 delete [] jt;
339 } else { 339 } else {
340#endif 340#endif
341 QPainter p(this); 341 QPainter p(this);
342 342
343 w = 320; 343 w = 320;
344 h = 240; 344 h = 240;
345 345
346 if ( mediaPlayerState->scaled() ) { 346 if ( mediaPlayerState->scaled() ) {
347 // maintain aspect ratio 347 // maintain aspect ratio
348 if ( w * sh > sw * h ) 348 if ( w * sh > sw * h )
349 w = sw * h / sh; 349 w = sw * h / sh;
350 else 350 else
351 h = sh * w / sw; 351 h = sh * w / sw;
352 } else { 352 } else {
353 w = sw; 353 w = sw;
354 h = sh; 354 h = sh;
355 } 355 }
356 356
357 int bytes = ( dd == 16 ) ? 2 : 4; 357 int bytes = ( dd == 16 ) ? 2 : 4;
358 QImage tempFrame( w, h, bytes << 3 ); 358 QImage tempFrame( w, h, bytes << 3 );
359 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), 359 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(),
360 0, 0, sw, sh, w, h, format, 0) == 0; 360 0, 0, sw, sh, w, h, format, 0) == 0;
361 if ( result && mediaPlayerState->fullscreen() ) { 361 if ( result && mediaPlayerState->fullscreen() ) {
362 362
363 int rw = h, rh = w; 363 int rw = h, rh = w;
364 QImage rotatedFrame( rw, rh, bytes << 3 ); 364 QImage rotatedFrame( rw, rh, bytes << 3 );
365 365
366 ushort* in = (ushort*)tempFrame.bits(); 366 ushort* in = (ushort*)tempFrame.bits();
367 ushort* out = (ushort*)rotatedFrame.bits(); 367 ushort* out = (ushort*)rotatedFrame.bits();
368 int spl = rotatedFrame.bytesPerLine() / bytes; 368 int spl = rotatedFrame.bytesPerLine() / bytes;
369 for (int x=0; x<h; x++) { 369 for (int x=0; x<h; x++) {
370 if ( bytes == 2 ) { 370 if ( bytes == 2 ) {
371 ushort* lout = out++ + (w - 1)*spl; 371 ushort* lout = out++ + (w - 1)*spl;
372 for (int y=0; y<w; y++) { 372 for (int y=0; y<w; y++) {
373 *lout=*in++; 373 *lout=*in++;
374 lout-=spl; 374 lout-=spl;
375 } 375 }
376 } else { 376 } else {
377 ulong* lout = ((ulong *)out)++ + (w - 1)*spl; 377 ulong* lout = ((ulong *)out)++ + (w - 1)*spl;
378 for (int y=0; y<w; y++) { 378 for (int y=0; y<w; y++) {
379 *lout=*((ulong*)in)++; 379 *lout=*((ulong*)in)++;
380 lout-=spl; 380 lout-=spl;
381 } 381 }
382 } 382 }
383 } 383 }
384 384
385 p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); 385 p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh );
386 } 386 }
387#ifdef USE_DIRECT_PAINTER 387#ifdef USE_DIRECT_PAINTER
388 } 388 }
389#endif 389#endif
390 } else { 390 } else {
391 391
392 w = 220; 392 w = 220;
393 h = 160; 393 h = 160;
394 394
395 // maintain aspect ratio 395 // maintain aspect ratio
396 if ( w * sh > sw * h ) 396 if ( w * sh > sw * h )
397 w = sw * h / sh; 397 w = sw * h / sh;
398 else 398 else
399 h = sh * w / sw; 399 h = sh * w / sw;
400 400
401 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; 401 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0;
402 402
403 QPainter p( this ); 403 QPainter p( this );
404 404
405 // Image changed size, therefore need to blank the possibly unpainted regions first 405 // Image changed size, therefore need to blank the possibly unpainted regions first
406 if ( scaledWidth != w || scaledHeight != h ) { 406 if ( scaledWidth != w || scaledHeight != h ) {
407 p.setBrush( QBrush( Qt::black ) ); 407 p.setBrush( QBrush( Qt::black ) );
408 p.drawRect( 9, 20, 220, 160 ); 408 p.drawRect( 9, 20, 220, 160 );
409 } 409 }
410 410
411 scaledWidth = w; 411 scaledWidth = w;
412 scaledHeight = h; 412 scaledHeight = h;
413 413
414 if ( result ) { 414 if ( result ) {
415 p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); 415 p.drawImage( 9 + (220 - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight );
416 } 416 }
417 417
418 } 418 }
419 419
420 return result; 420 return result;
421} 421}
422 422
423 423
424
425void VideoWidget::keyReleaseEvent( QKeyEvent *e)
426{
427 switch ( e->key() ) {
428////////////////////////////// Zaurus keys
429 case Key_Home:
430 break;
431 case Key_F9: //activity
432 break;
433 case Key_F10: //contacts
434 break;
435 case Key_F11: //menu
436 break;
437 case Key_F12: //home
438 break;
439 case Key_F13: //mail
440 break;
441 case Key_Space: {
442 if(mediaPlayerState->playing()) {
443 mediaPlayerState->setPlaying(FALSE);
444 } else {
445 mediaPlayerState->setPlaying(TRUE);
446 }
447 }
448 break;
449 case Key_Down:
450// toggleButton(6);
451// emit lessClicked();
452// emit lessReleased();
453// toggleButton(6);
454 break;
455 case Key_Up:
456// toggleButton(5);
457// emit moreClicked();
458// emit moreReleased();
459// toggleButton(5);
460 break;
461 case Key_Right:
462 mediaPlayerState->setNext();
463 break;
464 case Key_Left:
465 mediaPlayerState->setPrev();
466 break;
467 case Key_Escape:
468 break;
469
470 };
471}
diff --git a/core/multimedia/opieplayer/videowidget.h b/core/multimedia/opieplayer/videowidget.h
index cf13743..fe56ca1 100644
--- a/core/multimedia/opieplayer/videowidget.h
+++ b/core/multimedia/opieplayer/videowidget.h
@@ -1,87 +1,88 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef VIDEO_WIDGET_H 20#ifndef VIDEO_WIDGET_H
21#define VIDEO_WIDGET_H 21#define VIDEO_WIDGET_H
22 22
23 23
24#include <qwidget.h> 24#include <qwidget.h>
25 25
26class QPixmap; 26class QPixmap;
27class QSlider; 27class QSlider;
28 28
29 29
30enum VideoButtons { 30enum VideoButtons {
31 VideoPrevious, 31 VideoPrevious,
32 VideoStop, 32 VideoStop,
33 VideoPlay, 33 VideoPlay,
34 VideoPause, 34 VideoPause,
35 VideoNext, 35 VideoNext,
36 VideoPlayList, 36 VideoPlayList,
37 VideoFullscreen 37 VideoFullscreen
38}; 38};
39 39
40 40
41class VideoWidget : public QWidget { 41class VideoWidget : public QWidget {
42 Q_OBJECT 42 Q_OBJECT
43public: 43public:
44 VideoWidget( QWidget* parent=0, const char* name=0, WFlags f=0 ); 44 VideoWidget( QWidget* parent=0, const char* name=0, WFlags f=0 );
45 ~VideoWidget(); 45 ~VideoWidget();
46 46
47 bool playVideo(); 47 bool playVideo();
48 48
49public slots: 49public slots:
50 void updateSlider( long, long ); 50 void updateSlider( long, long );
51 void sliderPressed( ); 51 void sliderPressed( );
52 void sliderReleased( ); 52 void sliderReleased( );
53 void setPaused( bool b) { setToggleButton( VideoPause, b ); } 53 void setPaused( bool b) { setToggleButton( VideoPause, b ); }
54 void setPlaying( bool b) { setToggleButton( VideoPlay, b ); } 54 void setPlaying( bool b) { setToggleButton( VideoPlay, b ); }
55 void setFullscreen( bool b ) { setToggleButton( VideoFullscreen, b ); } 55 void setFullscreen( bool b ) { setToggleButton( VideoFullscreen, b ); }
56 void makeVisible(); 56 void makeVisible();
57 void setPosition( long ); 57 void setPosition( long );
58 void setLength( long ); 58 void setLength( long );
59 void setView( char ); 59 void setView( char );
60 60
61signals: 61signals:
62 void sliderMoved( long ); 62 void sliderMoved( long );
63 63
64protected: 64protected:
65 void paintEvent( QPaintEvent *pe ); 65 void paintEvent( QPaintEvent *pe );
66 void mouseMoveEvent( QMouseEvent *event ); 66 void mouseMoveEvent( QMouseEvent *event );
67 void mousePressEvent( QMouseEvent *event ); 67 void mousePressEvent( QMouseEvent *event );
68 void mouseReleaseEvent( QMouseEvent *event ); 68 void mouseReleaseEvent( QMouseEvent *event );
69 void closeEvent( QCloseEvent *event ); 69 void closeEvent( QCloseEvent *event );
70 void keyReleaseEvent( QKeyEvent *e);
70 71
71private: 72private:
72 void paintButton( QPainter *p, int i ); 73 void paintButton( QPainter *p, int i );
73 void toggleButton( int ); 74 void toggleButton( int );
74 void setToggleButton( int, bool ); 75 void setToggleButton( int, bool );
75 76
76 QSlider *slider; 77 QSlider *slider;
77 QPixmap *pixmaps[3]; 78 QPixmap *pixmaps[3];
78 QImage *currentFrame; 79 QImage *currentFrame;
79 intscaledWidth; 80 int scaledWidth;
80 int scaledHeight; 81 int scaledHeight;
81}; 82};
82 83
83 84
84#endif // VIDEO_WIDGET_H 85#endif // VIDEO_WIDGET_H
85 86
86 87
87 88