author | llornkcor <llornkcor> | 2002-06-17 12:54:54 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-06-17 12:54:54 (UTC) |
commit | 282007e58a8a038a0db042341528510e73ac80fc (patch) (unidiff) | |
tree | f1a16c9a6a380bdc4217e9f92ac6ef6128d10717 | |
parent | 2917d7481dc8c1b053e3212a699e64948a90ec4c (diff) | |
download | opie-282007e58a8a038a0db042341528510e73ac80fc.zip opie-282007e58a8a038a0db042341528510e73ac80fc.tar.gz opie-282007e58a8a038a0db042341528510e73ac80fc.tar.bz2 |
fixes for goofy crap going on
-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 292 | ||||
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 2 | ||||
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol.cpp | 384 | ||||
-rw-r--r-- | core/multimedia/opieplayer/mediaplayer.cpp | 1 | ||||
-rw-r--r-- | core/multimedia/opieplayer/mediaplayerstate.cpp | 80 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 43 |
6 files changed, 406 insertions, 396 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp index 3262e38..4c5f12d 100644 --- a/core/multimedia/opieplayer/audiodevice.cpp +++ b/core/multimedia/opieplayer/audiodevice.cpp | |||
@@ -1,378 +1,378 @@ | |||
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 | 22 | ||
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <stdio.h> | 24 | #include <stdio.h> |
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | #include <qpe/config.h> | 26 | #include <qpe/config.h> |
27 | #include "audiodevice.h" | 27 | #include "audiodevice.h" |
28 | 28 | ||
29 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 29 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
30 | #include "qpe/qcopenvelope_qws.h" | 30 | #include "qpe/qcopenvelope_qws.h" |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #ifdef Q_WS_WIN | 33 | // #ifdef Q_WS_WIN |
34 | #include <windows.h> | 34 | // #include <windows.h> |
35 | #include <mmsystem.h> | 35 | // #include <mmsystem.h> |
36 | #include <mmreg.h> | 36 | // #include <mmreg.h> |
37 | #endif | 37 | // #endif |
38 | |||
39 | #if defined(Q_WS_X11) || defined(Q_WS_QWS) | 38 | #if defined(Q_WS_X11) || defined(Q_WS_QWS) |
40 | #include <fcntl.h> | 39 | #include <fcntl.h> |
41 | #include <sys/ioctl.h> | 40 | #include <sys/ioctl.h> |
42 | #include <sys/soundcard.h> | 41 | #include <sys/soundcard.h> |
43 | #include <sys/stat.h> | 42 | #include <sys/stat.h> |
44 | #include <sys/time.h> | 43 | #include <sys/time.h> |
45 | #include <sys/types.h> | 44 | #include <sys/types.h> |
46 | #include <unistd.h> | 45 | #include <unistd.h> |
47 | #endif | 46 | #endif |
48 | 47 | ||
49 | #if defined(Q_OS_WIN32) | 48 | // #if defined(Q_OS_WIN32) |
50 | static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000; | 49 | // static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000; |
51 | static const int timerResolutionMilliSeconds = 30; | 50 | // static const int timerResolutionMilliSeconds = 30; |
52 | static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond; | 51 | // static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond; |
53 | #else | 52 | // #else |
54 | # if defined(QT_QWS_IPAQ) | 53 | # if defined(QT_QWS_IPAQ) |
55 | static const int sound_fragment_shift = 14; | 54 | static const int sound_fragment_shift = 14; |
56 | # else | 55 | # else |
57 | static const int sound_fragment_shift = 16; | 56 | static const int sound_fragment_shift = 16; |
58 | # endif | 57 | # endif |
59 | static const int sound_fragment_bytes = (1<<sound_fragment_shift); | 58 | static const int sound_fragment_bytes = (1<<sound_fragment_shift); |
60 | #endif | 59 | //#endif |
61 | 60 | ||
62 | 61 | ||
63 | class AudioDevicePrivate { | 62 | class AudioDevicePrivate { |
64 | public: | 63 | public: |
65 | int handle; | 64 | int handle; |
66 | unsigned int frequency; | 65 | unsigned int frequency; |
67 | unsigned int channels; | 66 | unsigned int channels; |
68 | unsigned int bytesPerSample; | 67 | unsigned int bytesPerSample; |
69 | unsigned int bufferSize; | 68 | unsigned int bufferSize; |
70 | #ifndef Q_OS_WIN32 | 69 | //#ifndef Q_OS_WIN32 |
71 | bool can_GETOSPACE; | 70 | bool can_GETOSPACE; |
72 | char* unwrittenBuffer; | 71 | char* unwrittenBuffer; |
73 | unsigned int unwritten; | 72 | unsigned int unwritten; |
74 | #endif | 73 | //#endif |
75 | 74 | ||
76 | static int dspFd; | 75 | static int dspFd; |
77 | static bool muted; | 76 | static bool muted; |
78 | static unsigned int leftVolume; | 77 | static unsigned int leftVolume; |
79 | static unsigned int rightVolume; | 78 | static unsigned int rightVolume; |
80 | }; | 79 | }; |
81 | 80 | ||
82 | 81 | ||
83 | #ifdef Q_WS_QWS | 82 | #ifdef Q_WS_QWS |
84 | // 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 |
85 | // the device makes clicks and it starts to drive you insane! :) | 84 | // the device makes clicks and it starts to drive you insane! :) |
86 | // 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 |
87 | //#define KEEP_DEVICE_OPEN | 86 | //#define KEEP_DEVICE_OPEN |
88 | #endif | 87 | #endif |
89 | 88 | ||
90 | 89 | ||
91 | int AudioDevicePrivate::dspFd = 0; | 90 | int AudioDevicePrivate::dspFd = 0; |
92 | bool AudioDevicePrivate::muted = FALSE; | 91 | bool AudioDevicePrivate::muted = FALSE; |
93 | unsigned int AudioDevicePrivate::leftVolume = 0; | 92 | unsigned int AudioDevicePrivate::leftVolume = 0; |
94 | unsigned int AudioDevicePrivate::rightVolume = 0; | 93 | unsigned int AudioDevicePrivate::rightVolume = 0; |
95 | 94 | ||
96 | 95 | ||
97 | void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { | 96 | void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { |
98 | muted = AudioDevicePrivate::muted; | 97 | muted = AudioDevicePrivate::muted; |
99 | unsigned int volume; | 98 | unsigned int volume; |
100 | #ifdef Q_OS_WIN32 | 99 | // #ifdef Q_OS_WIN32 |
101 | HWAVEOUT handle; | 100 | // HWAVEOUT handle; |
102 | WAVEFORMATEX formatData; | 101 | // WAVEFORMATEX formatData; |
103 | formatData.cbSize = sizeof(WAVEFORMATEX); | 102 | // formatData.cbSize = sizeof(WAVEFORMATEX); |
104 | formatData.wFormatTag = WAVE_FORMAT_PCM; | 103 | // formatData.wFormatTag = WAVE_FORMAT_PCM; |
105 | formatData.nAvgBytesPerSec = 4 * 44000; | 104 | // formatData.nAvgBytesPerSec = 4 * 44000; |
106 | formatData.nBlockAlign = 4; | 105 | // formatData.nBlockAlign = 4; |
107 | formatData.nChannels = 2; | 106 | // formatData.nChannels = 2; |
108 | formatData.nSamplesPerSec = 44000; | 107 | // formatData.nSamplesPerSec = 44000; |
109 | formatData.wBitsPerSample = 16; | 108 | // formatData.wBitsPerSample = 16; |
110 | waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); | 109 | // waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); |
111 | if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) | 110 | // if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) |
112 | // qDebug( "get volume of audio device failed" ); | 111 | // // qDebug( "get volume of audio device failed" ); |
113 | waveOutClose( handle ); | 112 | // waveOutClose( handle ); |
114 | leftVolume = volume & 0xFFFF; | 113 | // leftVolume = volume & 0xFFFF; |
115 | rightVolume = volume >> 16; | 114 | // rightVolume = volume >> 16; |
116 | #else | 115 | // #else |
117 | int mixerHandle = open( "/dev/mixer", O_RDWR ); | 116 | int mixerHandle = open( "/dev/mixer", O_RDWR ); |
118 | if ( mixerHandle >= 0 ) { | 117 | if ( mixerHandle >= 0 ) { |
119 | if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) | 118 | if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) |
120 | perror("ioctl(\"MIXER_READ\")"); | 119 | perror("ioctl(\"MIXER_READ\")"); |
121 | close( mixerHandle ); | 120 | close( mixerHandle ); |
122 | } else | 121 | } else |
123 | perror("open(\"/dev/mixer\")"); | 122 | perror("open(\"/dev/mixer\")"); |
124 | leftVolume = ((volume & 0x00FF) << 16) / 101; | 123 | leftVolume = ((volume & 0x00FF) << 16) / 101; |
125 | rightVolume = ((volume & 0xFF00) << 8) / 101; | 124 | rightVolume = ((volume & 0xFF00) << 8) / 101; |
126 | #endif | 125 | //#endif |
127 | } | 126 | } |
128 | 127 | ||
129 | 128 | ||
130 | void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { | 129 | void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { |
131 | AudioDevicePrivate::muted = muted; | 130 | AudioDevicePrivate::muted = muted; |
132 | if ( muted ) { | 131 | if ( muted ) { |
133 | AudioDevicePrivate::leftVolume = leftVolume; | 132 | AudioDevicePrivate::leftVolume = leftVolume; |
134 | AudioDevicePrivate::rightVolume = rightVolume; | 133 | AudioDevicePrivate::rightVolume = rightVolume; |
135 | leftVolume = 0; | 134 | leftVolume = 0; |
136 | rightVolume = 0; | 135 | rightVolume = 0; |
137 | } else { | 136 | } else { |
138 | leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); | 137 | leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); |
139 | rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); | 138 | rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); |
140 | } | 139 | } |
141 | #ifdef Q_OS_WIN32 | 140 | // #ifdef Q_OS_WIN32 |
142 | HWAVEOUT handle; | 141 | // HWAVEOUT handle; |
143 | WAVEFORMATEX formatData; | 142 | // WAVEFORMATEX formatData; |
144 | formatData.cbSize = sizeof(WAVEFORMATEX); | 143 | // formatData.cbSize = sizeof(WAVEFORMATEX); |
145 | formatData.wFormatTag = WAVE_FORMAT_PCM; | 144 | // formatData.wFormatTag = WAVE_FORMAT_PCM; |
146 | formatData.nAvgBytesPerSec = 4 * 44000; | 145 | // formatData.nAvgBytesPerSec = 4 * 44000; |
147 | formatData.nBlockAlign = 4; | 146 | // formatData.nBlockAlign = 4; |
148 | formatData.nChannels = 2; | 147 | // formatData.nChannels = 2; |
149 | formatData.nSamplesPerSec = 44000; | 148 | // formatData.nSamplesPerSec = 44000; |
150 | formatData.wBitsPerSample = 16; | 149 | // formatData.wBitsPerSample = 16; |
151 | waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); | 150 | // waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); |
152 | unsigned int volume = (rightVolume << 16) | leftVolume; | 151 | // unsigned int volume = (rightVolume << 16) | leftVolume; |
153 | if ( waveOutSetVolume( handle, volume ) ) | 152 | // if ( waveOutSetVolume( handle, volume ) ) |
154 | // qDebug( "set volume of audio device failed" ); | 153 | // // qDebug( "set volume of audio device failed" ); |
155 | waveOutClose( handle ); | 154 | // waveOutClose( handle ); |
156 | #else | 155 | // #else |
157 | // 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 |
158 | unsigned int rV = (rightVolume * 101) >> 16; | 157 | unsigned int rV = (rightVolume * 101) >> 16; |
159 | 158 | ||
160 | # if 0 | 159 | # if 0 |
161 | unsigned int lV = (leftVolume * 101) >> 16; | 160 | unsigned int lV = (leftVolume * 101) >> 16; |
162 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); | 161 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); |
163 | int mixerHandle = 0; | 162 | int mixerHandle = 0; |
164 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 163 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
165 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) | 164 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) |
166 | perror("ioctl(\"MIXER_WRITE\")"); | 165 | perror("ioctl(\"MIXER_WRITE\")"); |
167 | close( mixerHandle ); | 166 | close( mixerHandle ); |
168 | } else | 167 | } else |
169 | perror("open(\"/dev/mixer\")"); | 168 | perror("open(\"/dev/mixer\")"); |
170 | 169 | ||
171 | # else | 170 | # else |
172 | // 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 |
173 | // independant right and left channel setting, or setting for different outputs | 172 | // independant right and left channel setting, or setting for different outputs |
174 | Config cfg("Sound"); | 173 | Config cfg("Sound"); |
175 | cfg.setGroup("System"); | 174 | cfg.setGroup("System"); |
176 | cfg.writeEntry("Volume",(int)rV); | 175 | cfg.writeEntry("Volume",(int)rV); |
177 | # endif | 176 | # endif |
178 | 177 | ||
179 | #endif | 178 | //#endif |
180 | // qDebug( "setting volume to: 0x%x", volume ); | 179 | // qDebug( "setting volume to: 0x%x", volume ); |
181 | #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) |
182 | // Send notification that the volume has changed | 181 | // Send notification that the volume has changed |
183 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; | 182 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; |
184 | #endif | 183 | #endif |
185 | } | 184 | } |
186 | 185 | ||
187 | 186 | ||
188 | 187 | ||
189 | 188 | ||
190 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | 189 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { |
191 | qDebug("creating new audio device"); | 190 | qDebug("creating new audio device"); |
192 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; | 191 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; |
193 | d = new AudioDevicePrivate; | 192 | d = new AudioDevicePrivate; |
194 | d->frequency = f; | 193 | d->frequency = f; |
195 | d->channels = chs; | 194 | d->channels = chs; |
196 | d->bytesPerSample = bps; | 195 | d->bytesPerSample = bps; |
197 | qDebug("%d",bps); | 196 | qDebug("%d",bps); |
198 | int format=0; | 197 | int format=0; |
199 | if( bps == 8) format = AFMT_U8; | 198 | if( bps == 8) format = AFMT_U8; |
200 | else if( bps <= 0) format = AFMT_S16_LE; | 199 | else if( bps <= 0) format = AFMT_S16_LE; |
201 | else format = AFMT_S16_LE; | 200 | else format = AFMT_S16_LE; |
202 | qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); | 201 | qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); |
203 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); | 202 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); |
204 | 203 | ||
205 | int fragments = 0x10000 * 8 + sound_fragment_shift; | 204 | int fragments = 0x10000 * 8 + sound_fragment_shift; |
206 | int capabilities = 0; | 205 | int capabilities = 0; |
207 | 206 | ||
208 | 207 | ||
209 | #ifdef KEEP_DEVICE_OPEN | 208 | #ifdef KEEP_DEVICE_OPEN |
210 | if ( AudioDevicePrivate::dspFd == 0 ) { | 209 | if ( AudioDevicePrivate::dspFd == 0 ) { |
211 | #endif | 210 | #endif |
212 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { | 211 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { |
213 | perror("open(\"/dev/dsp\") sending to /dev/null instead"); | 212 | perror("open(\"/dev/dsp\") sending to /dev/null instead"); |
214 | d->handle = ::open( "/dev/null", O_WRONLY ); | 213 | d->handle = ::open( "/dev/null", O_WRONLY ); |
215 | } | 214 | } |
216 | #ifdef KEEP_DEVICE_OPEN | 215 | #ifdef KEEP_DEVICE_OPEN |
217 | AudioDevicePrivate::dspFd = d->handle; | 216 | AudioDevicePrivate::dspFd = d->handle; |
218 | } else { | 217 | } else { |
219 | d->handle = AudioDevicePrivate::dspFd; | 218 | d->handle = AudioDevicePrivate::dspFd; |
220 | } | 219 | } |
221 | #endif | 220 | #endif |
222 | 221 | ||
223 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) | 222 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) |
224 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); | 223 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); |
225 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) | 224 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) |
226 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); | 225 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); |
227 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) | 226 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) |
228 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 227 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
229 | qDebug("freq %d", d->frequency); | 228 | qDebug("freq %d", d->frequency); |
230 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) | 229 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) |
231 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 230 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
232 | qDebug("channels %d",d->channels); | 231 | qDebug("channels %d",d->channels); |
233 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { | 232 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { |
234 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; | 233 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; |
235 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) | 234 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) |
236 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 235 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
237 | } | 236 | } |
238 | 237 | ||
239 | d->bufferSize = sound_fragment_bytes; | 238 | d->bufferSize = sound_fragment_bytes; |
240 | d->unwrittenBuffer = new char[d->bufferSize]; | 239 | d->unwrittenBuffer = new char[d->bufferSize]; |
241 | d->unwritten = 0; | 240 | d->unwritten = 0; |
242 | d->can_GETOSPACE = TRUE; // until we find otherwise | 241 | d->can_GETOSPACE = TRUE; // until we find otherwise |
243 | 242 | ||
244 | //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); | 243 | //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); |
245 | //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); | 244 | //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); |
246 | //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); | 245 | //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); |
247 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); | 246 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); |
248 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); | 247 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); |
249 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); | 248 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); |
250 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; | 249 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; |
251 | 250 | ||
252 | } | 251 | } |
253 | 252 | ||
254 | 253 | ||
255 | AudioDevice::~AudioDevice() { | 254 | AudioDevice::~AudioDevice() { |
256 | qDebug("destryo audiodevice"); | 255 | qDebug("destryo audiodevice"); |
257 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; | 256 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; |
258 | 257 | ||
259 | #ifdef Q_OS_WIN32 | 258 | // #ifdef Q_OS_WIN32 |
260 | waveOutClose( (HWAVEOUT)d->handle ); | 259 | // waveOutClose( (HWAVEOUT)d->handle ); |
261 | #else | 260 | // #else |
262 | # ifndef KEEP_DEVICE_OPEN | 261 | # ifndef KEEP_DEVICE_OPEN |
263 | close( d->handle ); // Now it should be safe to shut the handle | 262 | close( d->handle ); // Now it should be safe to shut the handle |
264 | # endif | 263 | # endif |
265 | delete d->unwrittenBuffer; | 264 | delete d->unwrittenBuffer; |
266 | delete d; | 265 | delete d; |
267 | #endif | 266 | //#endif |
267 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; | ||
268 | 268 | ||
269 | } | 269 | } |
270 | 270 | ||
271 | 271 | ||
272 | void AudioDevice::volumeChanged( bool muted ) | 272 | void AudioDevice::volumeChanged( bool muted ) |
273 | { | 273 | { |
274 | AudioDevicePrivate::muted = muted; | 274 | AudioDevicePrivate::muted = muted; |
275 | } | 275 | } |
276 | 276 | ||
277 | 277 | ||
278 | void AudioDevice::write( char *buffer, unsigned int length ) | 278 | void AudioDevice::write( char *buffer, unsigned int length ) |
279 | { | 279 | { |
280 | #ifdef Q_OS_WIN32 | 280 | // #ifdef Q_OS_WIN32 |
281 | // returns immediately and (to be implemented) emits completedIO() when finished writing | 281 | // // returns immediately and (to be implemented) emits completedIO() when finished writing |
282 | WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) ); | 282 | // WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) ); |
283 | // maybe the buffer should be copied so that this fool proof, but its a performance hit | 283 | // // maybe the buffer should be copied so that this fool proof, but its a performance hit |
284 | lpWaveHdr->lpData = buffer; | 284 | // lpWaveHdr->lpData = buffer; |
285 | lpWaveHdr->dwBufferLength = length; | 285 | // lpWaveHdr->dwBufferLength = length; |
286 | lpWaveHdr->dwFlags = 0L; | 286 | // lpWaveHdr->dwFlags = 0L; |
287 | lpWaveHdr->dwLoops = 0L; | 287 | // lpWaveHdr->dwLoops = 0L; |
288 | waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ); | 288 | // waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ); |
289 | // waveOutWrite returns immediately. the data is sent in the background. | 289 | // // waveOutWrite returns immediately. the data is sent in the background. |
290 | if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) ) | 290 | // if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) ) |
291 | qDebug( "failed to write block to audio device" ); | 291 | // qDebug( "failed to write block to audio device" ); |
292 | // emit completedIO(); | 292 | // // emit completedIO(); |
293 | #else | 293 | // #else |
294 | int t = ::write( d->handle, buffer, length ); | 294 | int t = ::write( d->handle, buffer, length ); |
295 | if ( t<0 ) t = 0; | 295 | if ( t<0 ) t = 0; |
296 | if ( t != (int)length) { | 296 | if ( t != (int)length) { |
297 | qDebug("Ahhh!! memcpys 1"); | 297 | qDebug("Ahhh!! memcpys 1"); |
298 | memcpy(d->unwrittenBuffer,buffer+t,length-t); | 298 | memcpy(d->unwrittenBuffer,buffer+t,length-t); |
299 | d->unwritten = length-t; | 299 | d->unwritten = length-t; |
300 | } | 300 | } |
301 | #endif | 301 | //#endif |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | unsigned int AudioDevice::channels() const | 305 | unsigned int AudioDevice::channels() const |
306 | { | 306 | { |
307 | return d->channels; | 307 | return d->channels; |
308 | } | 308 | } |
309 | 309 | ||
310 | 310 | ||
311 | unsigned int AudioDevice::frequency() const | 311 | unsigned int AudioDevice::frequency() const |
312 | { | 312 | { |
313 | return d->frequency; | 313 | return d->frequency; |
314 | } | 314 | } |
315 | 315 | ||
316 | 316 | ||
317 | unsigned int AudioDevice::bytesPerSample() const | 317 | unsigned int AudioDevice::bytesPerSample() const |
318 | { | 318 | { |
319 | return d->bytesPerSample; | 319 | return d->bytesPerSample; |
320 | } | 320 | } |
321 | 321 | ||
322 | 322 | ||
323 | unsigned int AudioDevice::bufferSize() const | 323 | unsigned int AudioDevice::bufferSize() const |
324 | { | 324 | { |
325 | return d->bufferSize; | 325 | return d->bufferSize; |
326 | } | 326 | } |
327 | 327 | ||
328 | unsigned int AudioDevice::canWrite() const | 328 | unsigned int AudioDevice::canWrite() const |
329 | { | 329 | { |
330 | #ifdef Q_OS_WIN32 | 330 | // #ifdef Q_OS_WIN32 |
331 | return bufferSize(); // Any better? | 331 | // return bufferSize(); // Any better? |
332 | #else | 332 | // #else |
333 | audio_buf_info info; | 333 | audio_buf_info info; |
334 | if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { | 334 | if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { |
335 | d->can_GETOSPACE = FALSE; | 335 | d->can_GETOSPACE = FALSE; |
336 | fcntl( d->handle, F_SETFL, O_NONBLOCK ); | 336 | fcntl( d->handle, F_SETFL, O_NONBLOCK ); |
337 | } | 337 | } |
338 | if ( d->can_GETOSPACE ) { | 338 | if ( d->can_GETOSPACE ) { |
339 | int t = info.fragments * sound_fragment_bytes; | 339 | int t = info.fragments * sound_fragment_bytes; |
340 | return QMIN(t,(int)bufferSize()); | 340 | return QMIN(t,(int)bufferSize()); |
341 | } else { | 341 | } else { |
342 | if ( d->unwritten ) { | 342 | if ( d->unwritten ) { |
343 | int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); | 343 | int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); |
344 | if ( t<0 ) t = 0; | 344 | if ( t<0 ) t = 0; |
345 | if ( (unsigned)t!=d->unwritten ) { | 345 | if ( (unsigned)t!=d->unwritten ) { |
346 | memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); | 346 | memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); |
347 | d->unwritten -= t; | 347 | d->unwritten -= t; |
348 | } else { | 348 | } else { |
349 | d->unwritten = 0; | 349 | d->unwritten = 0; |
350 | } | 350 | } |
351 | } | 351 | } |
352 | if ( d->unwritten ) | 352 | if ( d->unwritten ) |
353 | return 0; | 353 | return 0; |
354 | else | 354 | else |
355 | return d->bufferSize; | 355 | return d->bufferSize; |
356 | } | 356 | } |
357 | #endif | 357 | //#endif |
358 | } | 358 | } |
359 | 359 | ||
360 | 360 | ||
361 | int AudioDevice::bytesWritten() { | 361 | int AudioDevice::bytesWritten() { |
362 | #ifdef Q_OS_WIN32 | 362 | // #ifdef Q_OS_WIN32 |
363 | MMTIME pmmt = { TIME_BYTES, 0 }; | 363 | // MMTIME pmmt = { TIME_BYTES, 0 }; |
364 | if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) { | 364 | // if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) { |
365 | qDebug( "failed to get audio device position" ); | 365 | // qDebug( "failed to get audio device position" ); |
366 | return -1; | 366 | // return -1; |
367 | } | 367 | // } |
368 | return pmmt.u.cb; | 368 | // return pmmt.u.cb; |
369 | #else | 369 | // #else |
370 | int buffered = 0; | 370 | int buffered = 0; |
371 | if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { | 371 | if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { |
372 | qDebug( "failed to get audio device position" ); | 372 | qDebug( "failed to get audio device position" ); |
373 | return -1; | 373 | return -1; |
374 | } | 374 | } |
375 | return buffered; | 375 | return buffered; |
376 | #endif | 376 | //#endif |
377 | } | 377 | } |
378 | 378 | ||
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index ac8c935..54e7ceb 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -1,348 +1,348 @@ | |||
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> | 20 | #include <qpe/qpeapplication.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | 23 | ||
24 | #include <qwidget.h> | 24 | #include <qwidget.h> |
25 | #include <qpixmap.h> | 25 | #include <qpixmap.h> |
26 | #include <qbutton.h> | 26 | #include <qbutton.h> |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | #include <qframe.h> | 28 | #include <qframe.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | 30 | ||
31 | #include "audiowidget.h" | 31 | #include "audiowidget.h" |
32 | #include "mediaplayerstate.h" | 32 | #include "mediaplayerstate.h" |
33 | 33 | ||
34 | extern MediaPlayerState *mediaPlayerState; | 34 | extern MediaPlayerState *mediaPlayerState; |
35 | 35 | ||
36 | 36 | ||
37 | static const int xo = -2; // movable x offset | 37 | static const int xo = -2; // movable x offset |
38 | static const int yo = 22; // movable y offset | 38 | static const int yo = 22; // movable y offset |
39 | 39 | ||
40 | 40 | ||
41 | struct MediaButton { | 41 | struct MediaButton { |
42 | int xPos, yPos; | 42 | int xPos, yPos; |
43 | int color; | 43 | int color; |
44 | bool isToggle, isBig, isHeld, isDown; | 44 | bool isToggle, isBig, isHeld, isDown; |
45 | }; | 45 | }; |
46 | 46 | ||
47 | 47 | ||
48 | // Layout information for the audioButtons (and if it is a toggle button or not) | 48 | // Layout information for the audioButtons (and if it is a toggle button or not) |
49 | MediaButton audioButtons[] = { | 49 | MediaButton audioButtons[] = { |
50 | { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play | 50 | { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play |
51 | { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop | 51 | { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop |
52 | { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause | 52 | { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause |
53 | { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next | 53 | { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next |
54 | { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous | 54 | { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous |
55 | { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up | 55 | { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up |
56 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down | 56 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down |
57 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop | 57 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop |
58 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist | 58 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist |
59 | }; | 59 | }; |
60 | 60 | ||
61 | 61 | ||
62 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 62 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
63 | 63 | ||
64 | 64 | ||
65 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 65 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
66 | QWidget( parent, name, f ) | 66 | QWidget( parent, name, f ) |
67 | { | 67 | { |
68 | setCaption( tr("OpiePlayer") ); | 68 | setCaption( tr("OpiePlayer") ); |
69 | Config cfg("OpiePlayer"); | 69 | Config cfg("OpiePlayer"); |
70 | cfg.setGroup("AudioWidget"); | 70 | cfg.setGroup("AudioWidget"); |
71 | // QGridLayout *layout = new QGridLayout( this ); | 71 | // QGridLayout *layout = new QGridLayout( this ); |
72 | // layout->setSpacing( 2); | 72 | // layout->setSpacing( 2); |
73 | // layout->setMargin( 2); | 73 | // layout->setMargin( 2); |
74 | QString backgroundPix, buttonsAllPix, buttonsBigPix, controlsPix, animatedPix; | 74 | QString backgroundPix, buttonsAllPix, buttonsBigPix, controlsPix, animatedPix; |
75 | backgroundPix=cfg.readEntry( " backgroundPix", "opieplayer/metalFinish"); | 75 | backgroundPix=cfg.readEntry( " backgroundPix", "opieplayer/metalFinish"); |
76 | buttonsAllPix=cfg.readEntry( "buttonsAllPix","opieplayer/mediaButtonsAll"); | 76 | buttonsAllPix=cfg.readEntry( "buttonsAllPix","opieplayer/mediaButtonsAll"); |
77 | buttonsBigPix=cfg.readEntry( "buttonsBigPix","opieplayer/mediaButtonsBig"); | 77 | buttonsBigPix=cfg.readEntry( "buttonsBigPix","opieplayer/mediaButtonsBig"); |
78 | controlsPix=cfg.readEntry( "controlsPix","opieplayer/mediaControls"); | 78 | controlsPix=cfg.readEntry( "controlsPix","opieplayer/mediaControls"); |
79 | animatedPix=cfg.readEntry( "animatedPix", "opieplayer/animatedButton"); | 79 | animatedPix=cfg.readEntry( "animatedPix", "opieplayer/animatedButton"); |
80 | 80 | ||
81 | setBackgroundPixmap( Resource::loadPixmap( backgroundPix) ); | 81 | setBackgroundPixmap( Resource::loadPixmap( backgroundPix) ); |
82 | pixmaps[0] = new QPixmap( Resource::loadPixmap( buttonsAllPix ) ); | 82 | pixmaps[0] = new QPixmap( Resource::loadPixmap( buttonsAllPix ) ); |
83 | pixmaps[1] = new QPixmap( Resource::loadPixmap( buttonsBigPix ) ); | 83 | pixmaps[1] = new QPixmap( Resource::loadPixmap( buttonsBigPix ) ); |
84 | pixmaps[2] = new QPixmap( Resource::loadPixmap( controlsPix ) ); | 84 | pixmaps[2] = new QPixmap( Resource::loadPixmap( controlsPix ) ); |
85 | pixmaps[3] = new QPixmap( Resource::loadPixmap( animatedPix) ); | 85 | pixmaps[3] = new QPixmap( Resource::loadPixmap( animatedPix) ); |
86 | 86 | ||
87 | songInfo = new Ticker( this ); | 87 | songInfo = new Ticker( this ); |
88 | songInfo->setFocusPolicy( QWidget::NoFocus ); | 88 | songInfo->setFocusPolicy( QWidget::NoFocus ); |
89 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); | 89 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); |
90 | // layout->addMultiCellWidget( songInfo, 0, 0, 0, 2 ); | 90 | // layout->addMultiCellWidget( songInfo, 0, 0, 0, 2 ); |
91 | 91 | ||
92 | slider = new QSlider( Qt::Horizontal, this ); | 92 | slider = new QSlider( Qt::Horizontal, this ); |
93 | slider->setFixedWidth( 220 ); | 93 | slider->setFixedWidth( 220 ); |
94 | slider->setFixedHeight( 20 ); | 94 | slider->setFixedHeight( 20 ); |
95 | slider->setMinValue( 0 ); | 95 | slider->setMinValue( 0 ); |
96 | slider->setMaxValue( 1 ); | 96 | slider->setMaxValue( 1 ); |
97 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); | 97 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); |
98 | slider->setFocusPolicy( QWidget::NoFocus ); | 98 | slider->setFocusPolicy( QWidget::NoFocus ); |
99 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); | 99 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); |
100 | // layout->addMultiCellWidget( slider, 4, 4, 0, 2 ); | 100 | // layout->addMultiCellWidget( slider, 4, 4, 0, 2 ); |
101 | 101 | ||
102 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 102 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
103 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 103 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
104 | 104 | ||
105 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 105 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
106 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 106 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
107 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 107 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
108 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 108 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
109 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 109 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
110 | 110 | ||
111 | // Intialise state | 111 | // Intialise state |
112 | setLength( mediaPlayerState->length() ); | 112 | setLength( mediaPlayerState->length() ); |
113 | setPosition( mediaPlayerState->position() ); | 113 | setPosition( mediaPlayerState->position() ); |
114 | setLooping( mediaPlayerState->fullscreen() ); | 114 | setLooping( mediaPlayerState->fullscreen() ); |
115 | setPaused( mediaPlayerState->paused() ); | 115 | setPaused( mediaPlayerState->paused() ); |
116 | setPlaying( mediaPlayerState->playing() ); | 116 | setPlaying( mediaPlayerState->playing() ); |
117 | 117 | ||
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | AudioWidget::~AudioWidget() { | 121 | AudioWidget::~AudioWidget() { |
122 | mediaPlayerState->isStreaming = FALSE; | 122 | mediaPlayerState->isStreaming = FALSE; |
123 | for ( int i = 0; i < 4; i++ ) | 123 | for ( int i = 0; i < 4; i++ ) |
124 | delete pixmaps[i]; | 124 | delete pixmaps[i]; |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | static bool audioSliderBeingMoved = FALSE; | 128 | static bool audioSliderBeingMoved = FALSE; |
129 | 129 | ||
130 | 130 | ||
131 | void AudioWidget::sliderPressed() { | 131 | void AudioWidget::sliderPressed() { |
132 | audioSliderBeingMoved = TRUE; | 132 | audioSliderBeingMoved = TRUE; |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | void AudioWidget::sliderReleased() { | 136 | void AudioWidget::sliderReleased() { |
137 | audioSliderBeingMoved = FALSE; | 137 | audioSliderBeingMoved = FALSE; |
138 | if ( slider->width() == 0 ) | 138 | if ( slider->width() == 0 ) |
139 | return; | 139 | return; |
140 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 140 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
141 | mediaPlayerState->setPosition( val ); | 141 | mediaPlayerState->setPosition( val ); |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | void AudioWidget::setPosition( long i ) { | 145 | void AudioWidget::setPosition( long i ) { |
146 | // qDebug("set position %d",i); | ||
146 | updateSlider( i, mediaPlayerState->length() ); | 147 | updateSlider( i, mediaPlayerState->length() ); |
147 | } | 148 | } |
148 | 149 | ||
149 | 150 | ||
150 | void AudioWidget::setLength( long max ) { | 151 | void AudioWidget::setLength( long max ) { |
151 | updateSlider( mediaPlayerState->position(), max ); | 152 | updateSlider( mediaPlayerState->position(), max ); |
152 | } | 153 | } |
153 | 154 | ||
154 | 155 | ||
155 | void AudioWidget::setView( char view ) { | 156 | void AudioWidget::setView( char view ) { |
156 | |||
157 | if (mediaPlayerState->isStreaming) { | 157 | if (mediaPlayerState->isStreaming) { |
158 | if( !slider->isHidden()) slider->hide(); | 158 | if( !slider->isHidden()) slider->hide(); |
159 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 159 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
160 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 160 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
161 | } else { | 161 | } else { |
162 | // this stops the slider from being moved, thus | 162 | // this stops the slider from being moved, thus |
163 | // does not stop stream when it reaches the end | 163 | // does not stop stream when it reaches the end |
164 | slider->show(); | 164 | slider->show(); |
165 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 165 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
166 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 166 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
167 | } | 167 | } |
168 | 168 | ||
169 | if ( view == 'a' ) { | 169 | if ( view == 'a' ) { |
170 | startTimer( 150 ); | 170 | startTimer( 150 ); |
171 | // show(); | 171 | // show(); |
172 | showMaximized(); | 172 | showMaximized(); |
173 | } else { | 173 | } else { |
174 | killTimers(); | 174 | killTimers(); |
175 | hide(); | 175 | hide(); |
176 | } | 176 | } |
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | void AudioWidget::updateSlider( long i, long max ) { | 180 | void AudioWidget::updateSlider( long i, long max ) { |
181 | if ( max == 0 ) | 181 | if ( max == 0 ) |
182 | return; | 182 | return; |
183 | // Will flicker too much if we don't do this | 183 | // Will flicker too much if we don't do this |
184 | // Scale to something reasonable | 184 | // Scale to something reasonable |
185 | int width = slider->width(); | 185 | int width = slider->width(); |
186 | int val = int((double)i * width / max); | 186 | int val = int((double)i * width / max); |
187 | if ( !audioSliderBeingMoved ) { | 187 | if ( !audioSliderBeingMoved ) { |
188 | if ( slider->value() != val ) | 188 | if ( slider->value() != val ) |
189 | slider->setValue( val ); | 189 | slider->setValue( val ); |
190 | if ( slider->maxValue() != width ) | 190 | if ( slider->maxValue() != width ) |
191 | slider->setMaxValue( width ); | 191 | slider->setMaxValue( width ); |
192 | } | 192 | } |
193 | } | 193 | } |
194 | 194 | ||
195 | 195 | ||
196 | void AudioWidget::setToggleButton( int i, bool down ) { | 196 | void AudioWidget::setToggleButton( int i, bool down ) { |
197 | if ( down != audioButtons[i].isDown ) | 197 | if ( down != audioButtons[i].isDown ) |
198 | toggleButton( i ); | 198 | toggleButton( i ); |
199 | } | 199 | } |
200 | 200 | ||
201 | 201 | ||
202 | void AudioWidget::toggleButton( int i ) { | 202 | void AudioWidget::toggleButton( int i ) { |
203 | audioButtons[i].isDown = !audioButtons[i].isDown; | 203 | audioButtons[i].isDown = !audioButtons[i].isDown; |
204 | QPainter p(this); | 204 | QPainter p(this); |
205 | paintButton ( &p, i ); | 205 | paintButton ( &p, i ); |
206 | } | 206 | } |
207 | 207 | ||
208 | 208 | ||
209 | void AudioWidget::paintButton( QPainter *p, int i ) { | 209 | void AudioWidget::paintButton( QPainter *p, int i ) { |
210 | int x = audioButtons[i].xPos; | 210 | int x = audioButtons[i].xPos; |
211 | int y = audioButtons[i].yPos; | 211 | int y = audioButtons[i].yPos; |
212 | int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; | 212 | int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; |
213 | int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); | 213 | int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); |
214 | p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); | 214 | p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); |
215 | p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); | 215 | p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); |
216 | } | 216 | } |
217 | 217 | ||
218 | 218 | ||
219 | void AudioWidget::timerEvent( QTimerEvent * ) { | 219 | void AudioWidget::timerEvent( QTimerEvent * ) { |
220 | static int frame = 0; | 220 | static int frame = 0; |
221 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { | 221 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { |
222 | frame = frame >= 7 ? 0 : frame + 1; | 222 | frame = frame >= 7 ? 0 : frame + 1; |
223 | int x = audioButtons[AudioPlay].xPos; | 223 | int x = audioButtons[AudioPlay].xPos; |
224 | int y = audioButtons[AudioPlay].yPos; | 224 | int y = audioButtons[AudioPlay].yPos; |
225 | QPainter p( this ); | 225 | QPainter p( this ); |
226 | // Optimize to only draw the little bit of the changing images which is different | 226 | // Optimize to only draw the little bit of the changing images which is different |
227 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); | 227 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); |
228 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); | 228 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); |
229 | } | 229 | } |
230 | } | 230 | } |
231 | 231 | ||
232 | 232 | ||
233 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 233 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
234 | for ( int i = 0; i < numButtons; i++ ) { | 234 | for ( int i = 0; i < numButtons; i++ ) { |
235 | int size = audioButtons[i].isBig; | 235 | int size = audioButtons[i].isBig; |
236 | int x = audioButtons[i].xPos; | 236 | int x = audioButtons[i].xPos; |
237 | int y = audioButtons[i].yPos; | 237 | int y = audioButtons[i].yPos; |
238 | if ( event->state() == QMouseEvent::LeftButton ) { | 238 | if ( event->state() == QMouseEvent::LeftButton ) { |
239 | // The test to see if the mouse click is inside the circular button or not | 239 | // The test to see if the mouse click is inside the circular button or not |
240 | // (compared with the radius squared to avoid a square-root of our distance) | 240 | // (compared with the radius squared to avoid a square-root of our distance) |
241 | int radius = 32 + 13 * size; | 241 | int radius = 32 + 13 * size; |
242 | QPoint center = QPoint( x + radius, y + radius ); | 242 | QPoint center = QPoint( x + radius, y + radius ); |
243 | QPoint dXY = center - event->pos(); | 243 | QPoint dXY = center - event->pos(); |
244 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); | 244 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); |
245 | bool isOnButton = dist <= (radius * radius); | 245 | bool isOnButton = dist <= (radius * radius); |
246 | // QRect r( x, y, 64 + 22*size, 64 + 22*size ); | 246 | // QRect r( x, y, 64 + 22*size, 64 + 22*size ); |
247 | // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code | 247 | // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code |
248 | if ( isOnButton && !audioButtons[i].isHeld ) { | 248 | if ( isOnButton && !audioButtons[i].isHeld ) { |
249 | audioButtons[i].isHeld = TRUE; | 249 | audioButtons[i].isHeld = TRUE; |
250 | toggleButton(i); | 250 | toggleButton(i); |
251 | qDebug("button toggled1 %d",i); | 251 | qDebug("button toggled1 %d",i); |
252 | switch (i) { | 252 | switch (i) { |
253 | case AudioVolumeUp: emit moreClicked(); return; | 253 | case AudioVolumeUp: emit moreClicked(); return; |
254 | case AudioVolumeDown: emit lessClicked(); return; | 254 | case AudioVolumeDown: emit lessClicked(); return; |
255 | } | 255 | } |
256 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 256 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
257 | audioButtons[i].isHeld = FALSE; | 257 | audioButtons[i].isHeld = FALSE; |
258 | toggleButton(i); | 258 | toggleButton(i); |
259 | qDebug("button toggled2 %d",i); | 259 | qDebug("button toggled2 %d",i); |
260 | } | 260 | } |
261 | } else { | 261 | } else { |
262 | if ( audioButtons[i].isHeld ) { | 262 | if ( audioButtons[i].isHeld ) { |
263 | audioButtons[i].isHeld = FALSE; | 263 | audioButtons[i].isHeld = FALSE; |
264 | if ( !audioButtons[i].isToggle ) | 264 | if ( !audioButtons[i].isToggle ) |
265 | setToggleButton( i, FALSE ); | 265 | setToggleButton( i, FALSE ); |
266 | qDebug("button toggled3 %d",i); | 266 | qDebug("button toggled3 %d",i); |
267 | switch (i) { | 267 | switch (i) { |
268 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; | 268 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; |
269 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 269 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
270 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; | 270 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; |
271 | case AudioNext: mediaPlayerState->setNext(); return; | 271 | case AudioNext: mediaPlayerState->setNext(); return; |
272 | case AudioPrevious: mediaPlayerState->setPrev(); return; | 272 | case AudioPrevious: mediaPlayerState->setPrev(); return; |
273 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; | 273 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; |
274 | case AudioVolumeUp: emit moreReleased(); return; | 274 | case AudioVolumeUp: emit moreReleased(); return; |
275 | case AudioVolumeDown: emit lessReleased(); return; | 275 | case AudioVolumeDown: emit lessReleased(); return; |
276 | case AudioPlayList: mediaPlayerState->setList(); return; | 276 | case AudioPlayList: mediaPlayerState->setList(); return; |
277 | } | 277 | } |
278 | } | 278 | } |
279 | } | 279 | } |
280 | } | 280 | } |
281 | } | 281 | } |
282 | 282 | ||
283 | 283 | ||
284 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 284 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
285 | mouseMoveEvent( event ); | 285 | mouseMoveEvent( event ); |
286 | } | 286 | } |
287 | 287 | ||
288 | 288 | ||
289 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 289 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
290 | mouseMoveEvent( event ); | 290 | mouseMoveEvent( event ); |
291 | } | 291 | } |
292 | 292 | ||
293 | 293 | ||
294 | void AudioWidget::showEvent( QShowEvent* ) { | 294 | void AudioWidget::showEvent( QShowEvent* ) { |
295 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 295 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
296 | mouseMoveEvent( &event ); | 296 | mouseMoveEvent( &event ); |
297 | } | 297 | } |
298 | 298 | ||
299 | 299 | ||
300 | void AudioWidget::closeEvent( QCloseEvent* ) { | 300 | void AudioWidget::closeEvent( QCloseEvent* ) { |
301 | mediaPlayerState->setList(); | 301 | mediaPlayerState->setList(); |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | void AudioWidget::paintEvent( QPaintEvent * ) { | 305 | void AudioWidget::paintEvent( QPaintEvent * ) { |
306 | QPainter p( this ); | 306 | QPainter p( this ); |
307 | for ( int i = 0; i < numButtons; i++ ) | 307 | for ( int i = 0; i < numButtons; i++ ) |
308 | paintButton( &p, i ); | 308 | paintButton( &p, i ); |
309 | } | 309 | } |
310 | 310 | ||
311 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) | 311 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) |
312 | { | 312 | { |
313 | switch ( e->key() ) { | 313 | switch ( e->key() ) { |
314 | ////////////////////////////// Zaurus keys | 314 | ////////////////////////////// Zaurus keys |
315 | case Key_Home: | 315 | case Key_Home: |
316 | break; | 316 | break; |
317 | case Key_F9: //activity | 317 | case Key_F9: //activity |
318 | hide(); | 318 | hide(); |
319 | // qDebug("Audio F9"); | 319 | // qDebug("Audio F9"); |
320 | break; | 320 | break; |
321 | case Key_F10: //contacts | 321 | case Key_F10: //contacts |
322 | break; | 322 | break; |
323 | case Key_F11: //menu | 323 | case Key_F11: //menu |
324 | break; | 324 | break; |
325 | case Key_F12: //home | 325 | case Key_F12: //home |
326 | break; | 326 | break; |
327 | case Key_F13: //mail | 327 | case Key_F13: //mail |
328 | break; | 328 | break; |
329 | case Key_Space: { | 329 | case Key_Space: { |
330 | if(mediaPlayerState->playing()) { | 330 | if(mediaPlayerState->playing()) { |
331 | // toggleButton(1); | 331 | // toggleButton(1); |
332 | mediaPlayerState->setPlaying(FALSE); | 332 | mediaPlayerState->setPlaying(FALSE); |
333 | // toggleButton(1); | 333 | // toggleButton(1); |
334 | } else { | 334 | } else { |
335 | // toggleButton(0); | 335 | // toggleButton(0); |
336 | mediaPlayerState->setPlaying(TRUE); | 336 | mediaPlayerState->setPlaying(TRUE); |
337 | // toggleButton(0); | 337 | // toggleButton(0); |
338 | } | 338 | } |
339 | } | 339 | } |
340 | break; | 340 | break; |
341 | case Key_Down: | 341 | case Key_Down: |
342 | toggleButton(6); | 342 | toggleButton(6); |
343 | emit lessClicked(); | 343 | emit lessClicked(); |
344 | emit lessReleased(); | 344 | emit lessReleased(); |
345 | toggleButton(6); | 345 | toggleButton(6); |
346 | break; | 346 | break; |
347 | case Key_Up: | 347 | case Key_Up: |
348 | toggleButton(5); | 348 | toggleButton(5); |
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp index 3171c4b..70e4a78 100644 --- a/core/multimedia/opieplayer/loopcontrol.cpp +++ b/core/multimedia/opieplayer/loopcontrol.cpp | |||
@@ -1,481 +1,483 @@ | |||
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 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | 23 | ||
24 | #ifdef Q_WS_QWS | 24 | #ifdef Q_WS_QWS |
25 | #include <qpe/qcopenvelope_qws.h> | 25 | #include <qpe/qcopenvelope_qws.h> |
26 | #endif | 26 | #endif |
27 | #include <stdio.h> | 27 | #include <stdio.h> |
28 | #include <stdlib.h> | 28 | #include <stdlib.h> |
29 | #include <string.h> | 29 | #include <string.h> |
30 | #include <pthread.h> | 30 | #include <pthread.h> |
31 | #include <errno.h> | 31 | #include <errno.h> |
32 | #include <unistd.h> | 32 | #include <unistd.h> |
33 | #include "loopcontrol.h" | 33 | #include "loopcontrol.h" |
34 | #include "videowidget.h" | 34 | #include "videowidget.h" |
35 | #include "audiodevice.h" | 35 | #include "audiodevice.h" |
36 | #include <qpe/mediaplayerplugininterface.h> | 36 | #include <qpe/mediaplayerplugininterface.h> |
37 | #include "mediaplayerstate.h" | 37 | #include "mediaplayerstate.h" |
38 | 38 | ||
39 | 39 | ||
40 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame | 40 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame |
41 | extern MediaPlayerState *mediaPlayerState; | 41 | extern MediaPlayerState *mediaPlayerState; |
42 | 42 | ||
43 | 43 | ||
44 | //#define DecodeLoopDebug(x) qDebug x | 44 | //#define DecodeLoopDebug(x) qDebug x |
45 | #define DecodeLoopDebug(x) | 45 | #define DecodeLoopDebug(x) |
46 | 46 | ||
47 | 47 | ||
48 | static char *audioBuffer = NULL; | 48 | static char *audioBuffer = NULL; |
49 | static AudioDevice *audioDevice = NULL; | 49 | static AudioDevice *audioDevice = NULL; |
50 | static bool disabledSuspendScreenSaver = FALSE; | 50 | static bool disabledSuspendScreenSaver = FALSE; |
51 | static bool previousSuspendMode = FALSE; | 51 | static bool previousSuspendMode = FALSE; |
52 | 52 | ||
53 | 53 | ||
54 | pthread_t audio_tid; | 54 | pthread_t audio_tid; |
55 | pthread_attr_t audio_attr; | 55 | pthread_attr_t audio_attr; |
56 | bool threadOkToGo = FALSE; | 56 | bool threadOkToGo = FALSE; |
57 | 57 | ||
58 | 58 | ||
59 | class Mutex { | 59 | class Mutex { |
60 | public: | 60 | public: |
61 | Mutex() { | 61 | Mutex() { |
62 | pthread_mutexattr_t attr; | 62 | pthread_mutexattr_t attr; |
63 | pthread_mutexattr_init( &attr ); | 63 | pthread_mutexattr_init( &attr ); |
64 | pthread_mutex_init( &mutex, &attr ); | 64 | pthread_mutex_init( &mutex, &attr ); |
65 | pthread_mutexattr_destroy( &attr ); | 65 | pthread_mutexattr_destroy( &attr ); |
66 | } | 66 | } |
67 | 67 | ||
68 | ~Mutex() { | 68 | ~Mutex() { |
69 | pthread_mutex_destroy( &mutex ); | 69 | pthread_mutex_destroy( &mutex ); |
70 | } | 70 | } |
71 | 71 | ||
72 | void lock() { | 72 | void lock() { |
73 | pthread_mutex_lock( &mutex ); | 73 | pthread_mutex_lock( &mutex ); |
74 | } | 74 | } |
75 | 75 | ||
76 | void unlock() { | 76 | void unlock() { |
77 | pthread_mutex_unlock( &mutex ); | 77 | pthread_mutex_unlock( &mutex ); |
78 | } | 78 | } |
79 | private: | 79 | private: |
80 | pthread_mutex_t mutex; | 80 | pthread_mutex_t mutex; |
81 | }; | 81 | }; |
82 | 82 | ||
83 | 83 | ||
84 | void *startAudioThread( void *ptr ) { | 84 | void *startAudioThread( void *ptr ) { |
85 | LoopControl *mpegView = (LoopControl *)ptr; | 85 | LoopControl *mpegView = (LoopControl *)ptr; |
86 | while ( TRUE ) { | 86 | while ( TRUE ) { |
87 | if ( threadOkToGo && mpegView->moreAudio ) | 87 | if ( threadOkToGo && mpegView->moreAudio ) |
88 | mpegView->startAudio(); | 88 | mpegView->startAudio(); |
89 | else | 89 | else |
90 | usleep( 10000 ); // Semi-buzy-wait till we are playing again | 90 | usleep( 10000 ); // Semi-buzy-wait till we are playing again |
91 | } | 91 | } |
92 | return 0; | 92 | return 0; |
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | Mutex *audioMutex; | 96 | Mutex *audioMutex; |
97 | 97 | ||
98 | 98 | ||
99 | LoopControl::LoopControl( QObject *parent, const char *name ) | 99 | LoopControl::LoopControl( QObject *parent, const char *name ) |
100 | : QObject( parent, name ) { | 100 | : QObject( parent, name ) { |
101 | isMuted = FALSE; | 101 | isMuted = FALSE; |
102 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); | 102 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); |
103 | //qDebug("starting loopcontrol"); | 103 | //qDebug("starting loopcontrol"); |
104 | audioMutex = new Mutex; | 104 | audioMutex = new Mutex; |
105 | 105 | ||
106 | pthread_attr_init(&audio_attr); | 106 | pthread_attr_init(&audio_attr); |
107 | #define USE_REALTIME_AUDIO_THREAD | 107 | #define USE_REALTIME_AUDIO_THREAD |
108 | #ifdef USE_REALTIME_AUDIO_THREAD | 108 | #ifdef USE_REALTIME_AUDIO_THREAD |
109 | // Attempt to set it to real-time round robin | 109 | // Attempt to set it to real-time round robin |
110 | if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { | 110 | if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { |
111 | sched_param params; | 111 | sched_param params; |
112 | params.sched_priority = 50; | 112 | params.sched_priority = 50; |
113 | pthread_attr_setschedparam(&audio_attr,¶ms); | 113 | pthread_attr_setschedparam(&audio_attr,¶ms); |
114 | } else { | 114 | } else { |
115 | qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); | 115 | qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); |
116 | pthread_attr_destroy(&audio_attr); | 116 | pthread_attr_destroy(&audio_attr); |
117 | pthread_attr_init(&audio_attr); | 117 | pthread_attr_init(&audio_attr); |
118 | } | 118 | } |
119 | #endif | 119 | #endif |
120 | //qDebug("create audio thread"); | 120 | //qDebug("create audio thread"); |
121 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); | 121 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | LoopControl::~LoopControl() { | 125 | LoopControl::~LoopControl() { |
126 | stop(); | 126 | stop(); |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | static long prev_frame = 0; | 130 | static long prev_frame = 0; |
131 | static int currentSample = 0; | 131 | static int currentSample = 0; |
132 | 132 | ||
133 | 133 | ||
134 | void LoopControl::timerEvent( QTimerEvent *te ) { | 134 | void LoopControl::timerEvent( QTimerEvent *te ) { |
135 | 135 | ||
136 | if ( te->timerId() == videoId ) | 136 | if ( te->timerId() == videoId ) |
137 | startVideo(); | 137 | startVideo(); |
138 | 138 | ||
139 | if ( te->timerId() == sliderId ) { | 139 | if ( te->timerId() == sliderId ) { |
140 | if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { | 140 | if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { |
141 | mediaPlayerState->updatePosition( audioSampleCounter ); | 141 | mediaPlayerState->updatePosition( audioSampleCounter ); |
142 | } else if ( hasVideoChannel && moreVideo ) { | 142 | } else if ( hasVideoChannel && moreVideo ) { |
143 | mediaPlayerState->updatePosition( current_frame ); | 143 | mediaPlayerState->updatePosition( current_frame ); |
144 | } | 144 | } |
145 | } | 145 | } |
146 | 146 | ||
147 | if ( !moreVideo && !moreAudio ) { | 147 | if ( !moreVideo && !moreAudio ) { |
148 | mediaPlayerState->setPlaying( FALSE ); | 148 | mediaPlayerState->setPlaying( FALSE ); |
149 | mediaPlayerState->setNext(); | 149 | mediaPlayerState->setNext(); |
150 | } | 150 | } |
151 | } | 151 | } |
152 | 152 | ||
153 | 153 | ||
154 | void LoopControl::setPosition( long pos ) { | 154 | void LoopControl::setPosition( long pos ) { |
155 | audioMutex->lock(); | 155 | audioMutex->lock(); |
156 | 156 | // qDebug("Loop control %d", pos); | |
157 | if ( hasVideoChannel && hasAudioChannel ) { | 157 | if ( hasVideoChannel && hasAudioChannel ) { |
158 | playtime.restart(); | 158 | playtime.restart(); |
159 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); | 159 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); |
160 | current_frame = pos + 1; | 160 | current_frame = pos + 1; |
161 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 161 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
162 | prev_frame = current_frame - 1; | 162 | prev_frame = current_frame - 1; |
163 | currentSample = (int)( (double)current_frame * freq / framerate ); | 163 | currentSample = (int)( (double)current_frame * freq / framerate ); |
164 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); | 164 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); |
165 | audioSampleCounter = currentSample - 1; | 165 | audioSampleCounter = currentSample - 1; |
166 | } else if ( hasVideoChannel ) { | 166 | } else if ( hasVideoChannel ) { |
167 | playtime.restart(); | 167 | playtime.restart(); |
168 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); | 168 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); |
169 | current_frame = pos + 1; | 169 | current_frame = pos + 1; |
170 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 170 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
171 | prev_frame = current_frame - 1; | 171 | prev_frame = current_frame - 1; |
172 | } else if ( hasAudioChannel ) { | 172 | } else if ( hasAudioChannel ) { |
173 | playtime.restart(); | 173 | playtime.restart(); |
174 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); | 174 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); |
175 | currentSample = pos + 1; | 175 | currentSample = pos + 1; |
176 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); | 176 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); |
177 | audioSampleCounter = currentSample - 1; | 177 | audioSampleCounter = currentSample - 1; |
178 | } | 178 | } |
179 | 179 | ||
180 | audioMutex->unlock(); | 180 | audioMutex->unlock(); |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
184 | void LoopControl::startVideo() { | 184 | void LoopControl::startVideo() { |
185 | 185 | ||
186 | if ( moreVideo ) { | 186 | if ( moreVideo ) { |
187 | 187 | ||
188 | if ( mediaPlayerState->curDecoder() ) { | 188 | if ( mediaPlayerState->curDecoder() ) { |
189 | 189 | ||
190 | if ( hasAudioChannel && !isMuted ) { | 190 | if ( hasAudioChannel && !isMuted ) { |
191 | 191 | ||
192 | current_frame = long( playtime.elapsed() * framerate / 1000 ); | 192 | current_frame = long( playtime.elapsed() * framerate / 1000 ); |
193 | 193 | ||
194 | if ( prev_frame != -1 && current_frame <= prev_frame ) | 194 | if ( prev_frame != -1 && current_frame <= prev_frame ) |
195 | return; | 195 | return; |
196 | 196 | ||
197 | } else { | 197 | } else { |
198 | // Don't skip | 198 | // Don't skip |
199 | current_frame++; | 199 | current_frame++; |
200 | } | 200 | } |
201 | 201 | ||
202 | if ( prev_frame == -1 || current_frame > prev_frame ) { | 202 | if ( prev_frame == -1 || current_frame > prev_frame ) { |
203 | if ( current_frame > prev_frame + 1 ) { | 203 | if ( current_frame > prev_frame + 1 ) { |
204 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 204 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
205 | } | 205 | } |
206 | moreVideo = videoUI->playVideo(); | 206 | moreVideo = videoUI->playVideo(); |
207 | prev_frame = current_frame; | 207 | prev_frame = current_frame; |
208 | } | 208 | } |
209 | 209 | ||
210 | } else { | 210 | } else { |
211 | 211 | ||
212 | moreVideo = FALSE; | 212 | moreVideo = FALSE; |
213 | killTimer( videoId ); | 213 | killTimer( videoId ); |
214 | 214 | ||
215 | } | 215 | } |
216 | 216 | ||
217 | } | 217 | } |
218 | } | 218 | } |
219 | 219 | ||
220 | 220 | ||
221 | void LoopControl::startAudio() { | 221 | void LoopControl::startAudio() { |
222 | 222 | ||
223 | //qDebug("start audio"); | ||
224 | audioMutex->lock(); | 223 | audioMutex->lock(); |
225 | if ( moreAudio ) { | 224 | if ( moreAudio ) { |
226 | 225 | ||
227 | if ( !isMuted && mediaPlayerState->curDecoder() ) { | 226 | if ( !isMuted && mediaPlayerState->curDecoder() ) { |
228 | 227 | ||
229 | currentSample = audioSampleCounter + 1; | 228 | currentSample = audioSampleCounter + 1; |
230 | 229 | ||
231 | if ( currentSample != audioSampleCounter + 1 ) | 230 | if ( currentSample != audioSampleCounter + 1 ) |
232 | qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); | 231 | qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); |
233 | 232 | ||
234 | long samplesRead = 0; | 233 | long samplesRead = 0; |
235 | bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); | 234 | bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); |
236 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; | 235 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; |
237 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; | 236 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; |
238 | 237 | ||
239 | // this causes drop outs not sure why its even here | 238 | // this causes drop outs not sure why its even here |
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 | 249 | ||
251 | if( mediaPlayerState->isStreaming == FALSE) | 250 | if( mediaPlayerState->isStreaming == FALSE) |
252 | audioSampleCounter = currentSample + samplesRead - 1; | 251 | audioSampleCounter = currentSample + samplesRead - 1; |
253 | 252 | ||
254 | moreAudio = readOk && (audioSampleCounter <= total_audio_samples); | 253 | moreAudio = readOk && (audioSampleCounter <= total_audio_samples); |
255 | 254 | ||
256 | } else { | 255 | } else { |
257 | 256 | ||
258 | moreAudio = FALSE; | 257 | moreAudio = FALSE; |
259 | 258 | ||
260 | } | 259 | } |
261 | 260 | ||
262 | } | 261 | } |
263 | 262 | ||
264 | audioMutex->unlock(); | 263 | audioMutex->unlock(); |
265 | } | 264 | } |
266 | 265 | ||
267 | 266 | ||
268 | void LoopControl::killTimers() { | 267 | void LoopControl::killTimers() { |
269 | 268 | ||
270 | audioMutex->lock(); | 269 | audioMutex->lock(); |
271 | 270 | ||
272 | if ( hasVideoChannel ) | 271 | if ( hasVideoChannel ) |
273 | killTimer( videoId ); | 272 | killTimer( videoId ); |
274 | killTimer( sliderId ); | 273 | killTimer( sliderId ); |
275 | threadOkToGo = FALSE; | 274 | threadOkToGo = FALSE; |
276 | 275 | ||
277 | audioMutex->unlock(); | 276 | audioMutex->unlock(); |
278 | } | 277 | } |
279 | 278 | ||
280 | 279 | ||
281 | void LoopControl::startTimers() { | 280 | void LoopControl::startTimers() { |
282 | 281 | ||
283 | audioMutex->lock(); | 282 | audioMutex->lock(); |
284 | 283 | ||
285 | moreVideo = FALSE; | 284 | moreVideo = FALSE; |
286 | moreAudio = FALSE; | 285 | moreAudio = FALSE; |
287 | 286 | ||
288 | if ( hasVideoChannel ) { | 287 | if ( hasVideoChannel ) { |
289 | moreVideo = TRUE; | 288 | moreVideo = TRUE; |
290 | int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value | 289 | int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value |
291 | videoId = startTimer( mSecsBetweenFrames ); | 290 | videoId = startTimer( mSecsBetweenFrames ); |
292 | } | 291 | } |
293 | 292 | ||
294 | if ( hasAudioChannel ) { | 293 | if ( hasAudioChannel ) { |
295 | moreAudio = TRUE; | 294 | moreAudio = TRUE; |
296 | threadOkToGo = TRUE; | 295 | threadOkToGo = TRUE; |
297 | } | 296 | } |
298 | 297 | ||
299 | sliderId = startTimer( 300 ); // update slider every 1/3 second | 298 | sliderId = startTimer( 300 ); // update slider every 1/3 second |
300 | 299 | ||
301 | audioMutex->unlock(); | 300 | audioMutex->unlock(); |
302 | } | 301 | } |
303 | 302 | ||
304 | 303 | ||
305 | void LoopControl::setPaused( bool pause ) { | 304 | void LoopControl::setPaused( bool pause ) { |
306 | 305 | ||
307 | if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) | 306 | if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) |
308 | return; | 307 | return; |
309 | 308 | ||
310 | if ( pause ) { | 309 | if ( pause ) { |
311 | killTimers(); | 310 | killTimers(); |
312 | } else { | 311 | } else { |
313 | // Force an update of the position | 312 | // Force an update of the position |
314 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); | 313 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); |
315 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); | 314 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); |
316 | // Just like we never stopped | 315 | // Just like we never stopped |
317 | startTimers(); | 316 | startTimers(); |
318 | } | 317 | } |
319 | } | 318 | } |
320 | 319 | ||
321 | 320 | ||
322 | void LoopControl::stop( bool willPlayAgainShortly ) { | 321 | void LoopControl::stop( bool willPlayAgainShortly ) { |
323 | 322 | ||
324 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 323 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
325 | if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { | 324 | if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { |
326 | disabledSuspendScreenSaver = FALSE; | 325 | disabledSuspendScreenSaver = FALSE; |
327 | // Re-enable the suspend mode | 326 | // Re-enable the suspend mode |
328 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | 327 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; |
329 | } | 328 | } |
330 | #endif | 329 | #endif |
331 | 330 | ||
332 | if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { | 331 | if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { |
333 | 332 | ||
334 | killTimers(); | 333 | killTimers(); |
335 | 334 | ||
336 | audioMutex->lock(); | 335 | audioMutex->lock(); |
337 | 336 | ||
338 | mediaPlayerState->curDecoder()->close(); | 337 | mediaPlayerState->curDecoder()->close(); |
339 | 338 | ||
340 | if ( audioDevice ) { | 339 | if ( audioDevice ) { |
341 | delete audioDevice; | 340 | delete audioDevice; |
342 | delete audioBuffer; | 341 | delete audioBuffer; |
343 | audioDevice = 0; | 342 | audioDevice = 0; |
344 | audioBuffer = 0; | 343 | audioBuffer = 0; |
345 | } | 344 | } |
346 | |||
347 | audioMutex->unlock(); | ||
348 | 345 | ||
346 | audioMutex->unlock(); | ||
349 | } | 347 | } |
348 | audioSampleCounter=0; | ||
349 | current_frame=0; | ||
350 | total_audio_samples=0; | ||
350 | } | 351 | } |
351 | 352 | ||
352 | 353 | ||
353 | bool LoopControl::init( const QString& filename ) { | 354 | bool LoopControl::init( const QString& filename ) { |
354 | stop(); | 355 | stop(); |
355 | |||
356 | audioMutex->lock(); | 356 | audioMutex->lock(); |
357 | 357 | ||
358 | fileName = filename; | 358 | fileName = filename; |
359 | stream = 0; // only play stream 0 for now | 359 | stream = 0; // only play stream 0 for now |
360 | current_frame = total_video_frames = total_audio_samples = 0; | 360 | current_frame = total_video_frames = total_audio_samples = 0; |
361 | 361 | ||
362 | qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); | 362 | qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); |
363 | 363 | ||
364 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin | 364 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin |
365 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { | 365 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { |
366 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename )) { | 366 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename )) { |
367 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); | 367 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); |
368 | mediaPlayerState->libMpeg3Decoder()->close(); | 368 | mediaPlayerState->libMpeg3Decoder()->close(); |
369 | } | 369 | } |
370 | } | 370 | } |
371 | 371 | ||
372 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { | 372 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { |
373 | audioMutex->unlock(); | 373 | audioMutex->unlock(); |
374 | return FALSE; | 374 | return FALSE; |
375 | } | 375 | } |
376 | 376 | ||
377 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; | 377 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; |
378 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; | 378 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; |
379 | 379 | ||
380 | if ( hasAudioChannel ) { | 380 | if ( hasAudioChannel ) { |
381 | int astream = 0; | 381 | int astream = 0; |
382 | 382 | ||
383 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMpeg3Plugin") ) | 383 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMpeg3Plugin") ) |
384 | channels = 2; //dont akx me why, but it needs this hack | 384 | channels = 2; //dont akx me why, but it needs this hack |
385 | else | 385 | else |
386 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); | 386 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); |
387 | 387 | ||
388 | qDebug( "LC- channels = %d", channels ); | 388 | qDebug( "LC- channels = %d", channels ); |
389 | 389 | ||
390 | if ( !total_audio_samples ) | 390 | if ( !total_audio_samples ) |
391 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); | 391 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); |
392 | 392 | ||
393 | total_audio_samples += 1000; | 393 | total_audio_samples += 1000; |
394 | 394 | ||
395 | mediaPlayerState->setLength( total_audio_samples ); | 395 | mediaPlayerState->setLength( total_audio_samples ); |
396 | 396 | ||
397 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); | 397 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); |
398 | qDebug( "LC- frequency = %d", freq ); | 398 | qDebug( "LC- frequency = %d", freq ); |
399 | 399 | ||
400 | audioSampleCounter = 0; | 400 | audioSampleCounter = 0; |
401 | int bits_per_sample; | 401 | int bits_per_sample; |
402 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { | 402 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { |
403 | bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); | 403 | bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); |
404 | qDebug("using stupid hack"); | 404 | qDebug("using stupid hack"); |
405 | } else { | 405 | } else { |
406 | bits_per_sample=0; | 406 | bits_per_sample=0; |
407 | } | 407 | } |
408 | 408 | ||
409 | audioDevice = new AudioDevice( freq, channels, bits_per_sample); | 409 | audioDevice = new AudioDevice( freq, channels, bits_per_sample); |
410 | audioBuffer = new char[ audioDevice->bufferSize() ]; | 410 | audioBuffer = new char[ audioDevice->bufferSize() ]; |
411 | channels = audioDevice->channels(); | 411 | channels = audioDevice->channels(); |
412 | 412 | ||
413 | //### must check which frequency is actually used. | 413 | //### must check which frequency is actually used. |
414 | static const int size = 1; | 414 | static const int size = 1; |
415 | short int buf[size]; | 415 | short int buf[size]; |
416 | long samplesRead = 0; | 416 | long samplesRead = 0; |
417 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); | 417 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); |
418 | } | 418 | } |
419 | 419 | ||
420 | if ( hasVideoChannel ) { | 420 | if ( hasVideoChannel ) { |
421 | total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); | 421 | total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); |
422 | 422 | ||
423 | mediaPlayerState->setLength( total_video_frames ); | 423 | mediaPlayerState->setLength( total_video_frames ); |
424 | 424 | ||
425 | framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); | 425 | framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); |
426 | DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); | 426 | DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); |
427 | 427 | ||
428 | if ( framerate <= 1.0 ) { | 428 | if ( framerate <= 1.0 ) { |
429 | DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); | 429 | DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); |
430 | framerate = 25; | 430 | framerate = 25; |
431 | } | 431 | } |
432 | 432 | ||
433 | if ( total_video_frames == 1 ) { | 433 | if ( total_video_frames == 1 ) { |
434 | DecodeLoopDebug(( "Cannot seek to frame" )); | 434 | DecodeLoopDebug(( "Cannot seek to frame" )); |
435 | } | 435 | } |
436 | 436 | ||
437 | } | 437 | } |
438 | 438 | ||
439 | current_frame = 0; | 439 | current_frame = 0; |
440 | prev_frame = -1; | 440 | prev_frame = -1; |
441 | 441 | ||
442 | connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); | 442 | connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); |
443 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); | 443 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); |
444 | 444 | ||
445 | audioMutex->unlock(); | 445 | audioMutex->unlock(); |
446 | 446 | ||
447 | return TRUE; | 447 | return TRUE; |
448 | } | 448 | } |
449 | 449 | ||
450 | 450 | ||
451 | void LoopControl::play() { | 451 | void LoopControl::play() { |
452 | qDebug("LC- play"); | 452 | qDebug("LC- play"); |
453 | mediaPlayerState->setPosition( 0); //uglyhack | ||
454 | |||
453 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 455 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
454 | if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { | 456 | if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { |
455 | disabledSuspendScreenSaver = TRUE; | 457 | disabledSuspendScreenSaver = TRUE; |
456 | previousSuspendMode = hasVideoChannel; | 458 | previousSuspendMode = hasVideoChannel; |
457 | // Stop the screen from blanking and power saving state | 459 | // Stop the screen from blanking and power saving state |
458 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) | 460 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) |
459 | << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); | 461 | << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); |
460 | } | 462 | } |
461 | #endif | 463 | #endif |
462 | 464 | ||
463 | playtime.start(); | 465 | playtime.start(); |
464 | startTimers(); | 466 | startTimers(); |
465 | } | 467 | } |
466 | 468 | ||
467 | 469 | ||
468 | void LoopControl::setMute( bool on ) { | 470 | void LoopControl::setMute( bool on ) { |
469 | if ( on != isMuted ) { | 471 | if ( on != isMuted ) { |
470 | isMuted = on; | 472 | isMuted = on; |
471 | if ( !on ) { | 473 | if ( !on ) { |
472 | // Force an update of the position | 474 | // Force an update of the position |
473 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); | 475 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); |
474 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); | 476 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); |
475 | // Resume playing audio | 477 | // Resume playing audio |
476 | moreAudio = TRUE; | 478 | moreAudio = TRUE; |
477 | } | 479 | } |
478 | } | 480 | } |
479 | } | 481 | } |
480 | 482 | ||
481 | 483 | ||
diff --git a/core/multimedia/opieplayer/mediaplayer.cpp b/core/multimedia/opieplayer/mediaplayer.cpp index b9e438b..64fdc01 100644 --- a/core/multimedia/opieplayer/mediaplayer.cpp +++ b/core/multimedia/opieplayer/mediaplayer.cpp | |||
@@ -1,219 +1,220 @@ | |||
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 | 20 | ||
21 | #include <qpe/qpeapplication.h> | 21 | #include <qpe/qpeapplication.h> |
22 | #include <qpe/qlibrary.h> | 22 | #include <qpe/qlibrary.h> |
23 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
24 | #include <qpe/config.h> | 24 | #include <qpe/config.h> |
25 | 25 | ||
26 | #include <qmainwindow.h> | 26 | #include <qmainwindow.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | #include <qwidgetstack.h> | 28 | #include <qwidgetstack.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | 30 | ||
31 | #include "mediaplayer.h" | 31 | #include "mediaplayer.h" |
32 | #include "playlistwidget.h" | 32 | #include "playlistwidget.h" |
33 | #include "audiowidget.h" | 33 | #include "audiowidget.h" |
34 | #include "loopcontrol.h" | 34 | #include "loopcontrol.h" |
35 | #include "audiodevice.h" | 35 | #include "audiodevice.h" |
36 | 36 | ||
37 | #include "mediaplayerstate.h" | 37 | #include "mediaplayerstate.h" |
38 | 38 | ||
39 | 39 | ||
40 | extern AudioWidget *audioUI; | 40 | extern AudioWidget *audioUI; |
41 | extern PlayListWidget *playList; | 41 | extern PlayListWidget *playList; |
42 | extern LoopControl *loopControl; | 42 | extern LoopControl *loopControl; |
43 | extern MediaPlayerState *mediaPlayerState; | 43 | extern MediaPlayerState *mediaPlayerState; |
44 | 44 | ||
45 | 45 | ||
46 | MediaPlayer::MediaPlayer( QObject *parent, const char *name ) | 46 | MediaPlayer::MediaPlayer( QObject *parent, const char *name ) |
47 | : QObject( parent, name ), volumeDirection( 0 ), currentFile( NULL ) { | 47 | : QObject( parent, name ), volumeDirection( 0 ), currentFile( NULL ) { |
48 | 48 | ||
49 | // QPEApplication::grabKeyboard(); | 49 | // QPEApplication::grabKeyboard(); |
50 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 50 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
51 | 51 | ||
52 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); | 52 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); |
53 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); | 53 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); |
54 | connect( mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); | 54 | connect( mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); |
55 | connect( mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); | 55 | connect( mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); |
56 | 56 | ||
57 | connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); | 57 | connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); |
58 | connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); | 58 | connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); |
59 | connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); | 59 | connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); |
60 | connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); | 60 | connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); |
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
64 | MediaPlayer::~MediaPlayer() { | 64 | MediaPlayer::~MediaPlayer() { |
65 | |||
65 | } | 66 | } |
66 | 67 | ||
67 | 68 | ||
68 | void MediaPlayer::pauseCheck( bool b ) { | 69 | void MediaPlayer::pauseCheck( bool b ) { |
69 | // Only pause if playing | 70 | // Only pause if playing |
70 | if ( b && !mediaPlayerState->playing() ) | 71 | if ( b && !mediaPlayerState->playing() ) |
71 | mediaPlayerState->setPaused( FALSE ); | 72 | mediaPlayerState->setPaused( FALSE ); |
72 | } | 73 | } |
73 | 74 | ||
74 | 75 | ||
75 | void MediaPlayer::play() { | 76 | void MediaPlayer::play() { |
76 | mediaPlayerState->setPlaying( FALSE ); | 77 | mediaPlayerState->setPlaying( FALSE ); |
77 | mediaPlayerState->setPlaying( TRUE ); | 78 | mediaPlayerState->setPlaying( TRUE ); |
78 | } | 79 | } |
79 | 80 | ||
80 | 81 | ||
81 | void MediaPlayer::setPlaying( bool play ) { | 82 | void MediaPlayer::setPlaying( bool play ) { |
82 | if ( !play ) { | 83 | if ( !play ) { |
83 | mediaPlayerState->setPaused( FALSE ); | 84 | mediaPlayerState->setPaused( FALSE ); |
84 | loopControl->stop( FALSE ); | 85 | loopControl->stop( FALSE ); |
85 | return; | 86 | return; |
86 | } | 87 | } |
87 | 88 | ||
88 | if ( mediaPlayerState->paused() ) { | 89 | if ( mediaPlayerState->paused() ) { |
89 | mediaPlayerState->setPaused( FALSE ); | 90 | mediaPlayerState->setPaused( FALSE ); |
90 | return; | 91 | return; |
91 | } | 92 | } |
92 | 93 | ||
93 | const DocLnk *playListCurrent = playList->current(); | 94 | const DocLnk *playListCurrent = playList->current(); |
94 | if ( playListCurrent != NULL ) { | 95 | if ( playListCurrent != NULL ) { |
95 | loopControl->stop( TRUE ); | 96 | loopControl->stop( TRUE ); |
96 | currentFile = playListCurrent; | 97 | currentFile = playListCurrent; |
97 | } | 98 | } |
98 | if ( currentFile == NULL ) { | 99 | if ( currentFile == NULL ) { |
99 | QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) ); | 100 | QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) ); |
100 | mediaPlayerState->setPlaying( FALSE ); | 101 | mediaPlayerState->setPlaying( FALSE ); |
101 | return; | 102 | return; |
102 | } | 103 | } |
103 | 104 | ||
104 | if ( ((currentFile->file()).left(4) != "http") && !QFile::exists( currentFile->file() ) ) { | 105 | if ( ((currentFile->file()).left(4) != "http") && !QFile::exists( currentFile->file() ) ) { |
105 | QMessageBox::critical( 0, tr( "File not found"), tr( "The following file was not found: <i>" ) + currentFile->file() + "</i>" ); | 106 | QMessageBox::critical( 0, tr( "File not found"), tr( "The following file was not found: <i>" ) + currentFile->file() + "</i>" ); |
106 | mediaPlayerState->setPlaying( FALSE ); | 107 | mediaPlayerState->setPlaying( FALSE ); |
107 | return; | 108 | return; |
108 | } | 109 | } |
109 | 110 | ||
110 | if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) { | 111 | if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) { |
111 | QMessageBox::critical( 0, tr( "No decoder found"), tr( "Sorry, no appropriate decoders found for this file: <i>" ) + currentFile->file() + "</i>" ); | 112 | QMessageBox::critical( 0, tr( "No decoder found"), tr( "Sorry, no appropriate decoders found for this file: <i>" ) + currentFile->file() + "</i>" ); |
112 | mediaPlayerState->setPlaying( FALSE ); | 113 | mediaPlayerState->setPlaying( FALSE ); |
113 | return; | 114 | return; |
114 | } | 115 | } |
115 | 116 | ||
116 | if ( !loopControl->init( currentFile->file() ) ) { | 117 | if ( !loopControl->init( currentFile->file() ) ) { |
117 | QMessageBox::critical( 0, tr( "Error opening file"), tr( "Sorry, an error occured trying to play the file: <i>" ) + currentFile->file() + "</i>" ); | 118 | QMessageBox::critical( 0, tr( "Error opening file"), tr( "Sorry, an error occured trying to play the file: <i>" ) + currentFile->file() + "</i>" ); |
118 | mediaPlayerState->setPlaying( FALSE ); | 119 | mediaPlayerState->setPlaying( FALSE ); |
119 | return; | 120 | return; |
120 | } | 121 | } |
121 | long seconds = loopControl->totalPlaytime(); | 122 | long seconds = loopControl->totalPlaytime(); |
122 | QString time; time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); | 123 | QString time; time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); |
123 | QString tickerText; | 124 | QString tickerText; |
124 | if( currentFile->file().left(4) == "http" ) | 125 | if( currentFile->file().left(4) == "http" ) |
125 | tickerText= tr( " File: " ) + currentFile->name(); | 126 | tickerText= tr( " File: " ) + currentFile->name(); |
126 | else | 127 | else |
127 | tickerText = tr( " File: " ) + currentFile->name() + tr(", Length: ") + time; | 128 | tickerText = tr( " File: " ) + currentFile->name() + tr(", Length: ") + time; |
128 | 129 | ||
129 | QString fileInfo = mediaPlayerState->curDecoder()->fileInfo(); | 130 | QString fileInfo = mediaPlayerState->curDecoder()->fileInfo(); |
130 | if ( !fileInfo.isEmpty() ) | 131 | if ( !fileInfo.isEmpty() ) |
131 | tickerText += ", " + fileInfo; | 132 | tickerText += ", " + fileInfo; |
132 | audioUI->setTickerText( tickerText + "." ); | 133 | audioUI->setTickerText( tickerText + "." ); |
133 | 134 | ||
134 | loopControl->play(); | 135 | loopControl->play(); |
135 | 136 | ||
136 | mediaPlayerState->setView( loopControl->hasVideo() ? 'v' : 'a' ); | 137 | mediaPlayerState->setView( loopControl->hasVideo() ? 'v' : 'a' ); |
137 | } | 138 | } |
138 | 139 | ||
139 | 140 | ||
140 | void MediaPlayer::prev() { | 141 | void MediaPlayer::prev() { |
141 | if ( playList->prev() ) | 142 | if ( playList->prev() ) |
142 | play(); | 143 | play(); |
143 | else if ( mediaPlayerState->looping() ) { | 144 | else if ( mediaPlayerState->looping() ) { |
144 | if ( playList->last() ) | 145 | if ( playList->last() ) |
145 | play(); | 146 | play(); |
146 | } else | 147 | } else |
147 | mediaPlayerState->setList(); | 148 | mediaPlayerState->setList(); |
148 | } | 149 | } |
149 | 150 | ||
150 | 151 | ||
151 | void MediaPlayer::next() { | 152 | void MediaPlayer::next() { |
152 | if ( playList->next() ) | 153 | if ( playList->next() ) |
153 | play(); | 154 | play(); |
154 | else if ( mediaPlayerState->looping() ) { | 155 | else if ( mediaPlayerState->looping() ) { |
155 | if ( playList->first() ) | 156 | if ( playList->first() ) |
156 | play(); | 157 | play(); |
157 | } else | 158 | } else |
158 | mediaPlayerState->setList(); | 159 | mediaPlayerState->setList(); |
159 | } | 160 | } |
160 | 161 | ||
161 | 162 | ||
162 | void MediaPlayer::startDecreasingVolume() { | 163 | void MediaPlayer::startDecreasingVolume() { |
163 | volumeDirection = -1; | 164 | volumeDirection = -1; |
164 | startTimer( 100 ); | 165 | startTimer( 100 ); |
165 | AudioDevice::decreaseVolume(); | 166 | AudioDevice::decreaseVolume(); |
166 | } | 167 | } |
167 | 168 | ||
168 | 169 | ||
169 | void MediaPlayer::startIncreasingVolume() { | 170 | void MediaPlayer::startIncreasingVolume() { |
170 | volumeDirection = +1; | 171 | volumeDirection = +1; |
171 | startTimer( 100 ); | 172 | startTimer( 100 ); |
172 | AudioDevice::increaseVolume(); | 173 | AudioDevice::increaseVolume(); |
173 | } | 174 | } |
174 | 175 | ||
175 | 176 | ||
176 | void MediaPlayer::stopChangingVolume() { | 177 | void MediaPlayer::stopChangingVolume() { |
177 | killTimers(); | 178 | killTimers(); |
178 | } | 179 | } |
179 | 180 | ||
180 | 181 | ||
181 | void MediaPlayer::timerEvent( QTimerEvent * ) { | 182 | void MediaPlayer::timerEvent( QTimerEvent * ) { |
182 | if ( volumeDirection == +1 ) | 183 | if ( volumeDirection == +1 ) |
183 | AudioDevice::increaseVolume(); | 184 | AudioDevice::increaseVolume(); |
184 | else if ( volumeDirection == -1 ) | 185 | else if ( volumeDirection == -1 ) |
185 | AudioDevice::decreaseVolume(); | 186 | AudioDevice::decreaseVolume(); |
186 | } | 187 | } |
187 | 188 | ||
188 | void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { | 189 | void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { |
189 | switch ( e->key() ) { | 190 | switch ( e->key() ) { |
190 | ////////////////////////////// Zaurus keys | 191 | ////////////////////////////// Zaurus keys |
191 | case Key_Home: | 192 | case Key_Home: |
192 | break; | 193 | break; |
193 | case Key_F9: //activity | 194 | case Key_F9: //activity |
194 | break; | 195 | break; |
195 | case Key_F10: //contacts | 196 | case Key_F10: //contacts |
196 | break; | 197 | break; |
197 | case Key_F11: //menu | 198 | case Key_F11: //menu |
198 | break; | 199 | break; |
199 | case Key_F12: //home | 200 | case Key_F12: //home |
200 | qDebug("Blank here"); | 201 | qDebug("Blank here"); |
201 | break; | 202 | break; |
202 | case Key_F13: //mail | 203 | case Key_F13: //mail |
203 | break; | 204 | break; |
204 | } | 205 | } |
205 | } | 206 | } |
206 | 207 | ||
207 | void MediaPlayer::doBlank() { | 208 | void MediaPlayer::doBlank() { |
208 | 209 | ||
209 | } | 210 | } |
210 | 211 | ||
211 | void MediaPlayer::doUnblank() { | 212 | void MediaPlayer::doUnblank() { |
212 | 213 | ||
213 | } | 214 | } |
214 | 215 | ||
215 | void MediaPlayer::cleanUp() { | 216 | void MediaPlayer::cleanUp() { |
216 | // QPEApplication::grabKeyboard(); | 217 | // QPEApplication::grabKeyboard(); |
217 | // QPEApplication::ungrabKeyboard(); | 218 | // QPEApplication::ungrabKeyboard(); |
218 | 219 | ||
219 | } | 220 | } |
diff --git a/core/multimedia/opieplayer/mediaplayerstate.cpp b/core/multimedia/opieplayer/mediaplayerstate.cpp index 3ac9ac4..cf166d6 100644 --- a/core/multimedia/opieplayer/mediaplayerstate.cpp +++ b/core/multimedia/opieplayer/mediaplayerstate.cpp | |||
@@ -1,195 +1,195 @@ | |||
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> | 20 | #include <qpe/qpeapplication.h> |
21 | #include <qpe/qlibrary.h> | 21 | #include <qpe/qlibrary.h> |
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | #include <qvaluelist.h> | 23 | #include <qvaluelist.h> |
24 | #include <qobject.h> | 24 | #include <qobject.h> |
25 | #include <qdir.h> | 25 | #include <qdir.h> |
26 | #include <qpe/mediaplayerplugininterface.h> | 26 | #include <qpe/mediaplayerplugininterface.h> |
27 | #include "mediaplayerstate.h" | 27 | #include "mediaplayerstate.h" |
28 | 28 | ||
29 | 29 | ||
30 | 30 | ||
31 | #ifdef QT_NO_COMPONENT | 31 | #ifdef QT_NO_COMPONENT |
32 | // Plugins which are compiled in when no plugin architecture available | 32 | // Plugins which are compiled in when no plugin architecture available |
33 | #include "libmad/libmadpluginimpl.h" | 33 | #include "libmad/libmadpluginimpl.h" |
34 | #include "libmpeg3/libmpeg3pluginimpl.h" | 34 | #include "libmpeg3/libmpeg3pluginimpl.h" |
35 | #include "wavplugin/wavpluginimpl.h" | 35 | #include "wavplugin/wavpluginimpl.h" |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | 38 | ||
39 | //#define MediaPlayerDebug(x) qDebug x | 39 | //#define MediaPlayerDebug(x) qDebug x |
40 | #define MediaPlayerDebug(x) | 40 | #define MediaPlayerDebug(x) |
41 | 41 | ||
42 | 42 | ||
43 | MediaPlayerState::MediaPlayerState( QObject *parent, const char *name ) | 43 | MediaPlayerState::MediaPlayerState( QObject *parent, const char *name ) |
44 | : QObject( parent, name ), decoder( NULL ), libmpeg3decoder( NULL ) { | 44 | : QObject( parent, name ), decoder( NULL ), libmpeg3decoder( NULL ) { |
45 | Config cfg( "OpiePlayer" ); | 45 | Config cfg( "OpiePlayer" ); |
46 | readConfig( cfg ); | 46 | readConfig( cfg ); |
47 | loadPlugins(); | 47 | loadPlugins(); |
48 | } | 48 | } |
49 | 49 | ||
50 | 50 | ||
51 | MediaPlayerState::~MediaPlayerState() { | 51 | MediaPlayerState::~MediaPlayerState() { |
52 | Config cfg( "OpiePlayer" ); | 52 | Config cfg( "OpiePlayer" ); |
53 | writeConfig( cfg ); | 53 | writeConfig( cfg ); |
54 | } | 54 | } |
55 | 55 | ||
56 | 56 | ||
57 | void MediaPlayerState::readConfig( Config& cfg ) { | 57 | void MediaPlayerState::readConfig( Config& cfg ) { |
58 | cfg.setGroup("Options"); | 58 | cfg.setGroup("Options"); |
59 | isFullscreen = cfg.readBoolEntry( "FullScreen" ); | 59 | isFullscreen = cfg.readBoolEntry( "FullScreen" ); |
60 | isScaled = cfg.readBoolEntry( "Scaling" ); | 60 | isScaled = cfg.readBoolEntry( "Scaling" ); |
61 | isLooping = cfg.readBoolEntry( "Looping" ); | 61 | isLooping = cfg.readBoolEntry( "Looping" ); |
62 | isShuffled = cfg.readBoolEntry( "Shuffle" ); | 62 | isShuffled = cfg.readBoolEntry( "Shuffle" ); |
63 | usePlaylist = cfg.readBoolEntry( "UsePlayList" ); | 63 | usePlaylist = cfg.readBoolEntry( "UsePlayList" ); |
64 | usePlaylist = TRUE; | 64 | usePlaylist = TRUE; |
65 | isPlaying = FALSE; | 65 | isPlaying = FALSE; |
66 | isPaused = FALSE; | 66 | isPaused = FALSE; |
67 | curPosition = 0; | 67 | curPosition = 0; |
68 | curLength = 0; | 68 | curLength = 0; |
69 | curView = 'l'; | 69 | curView = 'l'; |
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | void MediaPlayerState::writeConfig( Config& cfg ) const { | 73 | void MediaPlayerState::writeConfig( Config& cfg ) const { |
74 | cfg.setGroup("Options"); | 74 | cfg.setGroup("Options"); |
75 | cfg.writeEntry("FullScreen", isFullscreen ); | 75 | cfg.writeEntry("FullScreen", isFullscreen ); |
76 | cfg.writeEntry("Scaling", isScaled ); | 76 | cfg.writeEntry("Scaling", isScaled ); |
77 | cfg.writeEntry("Looping", isLooping ); | 77 | cfg.writeEntry("Looping", isLooping ); |
78 | cfg.writeEntry("Shuffle", isShuffled ); | 78 | cfg.writeEntry("Shuffle", isShuffled ); |
79 | cfg.writeEntry("UsePlayList", usePlaylist ); | 79 | cfg.writeEntry("UsePlayList", usePlaylist ); |
80 | } | 80 | } |
81 | 81 | ||
82 | 82 | ||
83 | struct MediaPlayerPlugin { | 83 | struct MediaPlayerPlugin { |
84 | #ifndef QT_NO_COMPONENT | 84 | #ifndef QT_NO_COMPONENT |
85 | QLibrary *library; | 85 | QLibrary *library; |
86 | #endif | 86 | #endif |
87 | MediaPlayerPluginInterface *iface; | 87 | MediaPlayerPluginInterface *iface; |
88 | MediaPlayerDecoder *decoder; | 88 | MediaPlayerDecoder *decoder; |
89 | MediaPlayerEncoder *encoder; | 89 | MediaPlayerEncoder *encoder; |
90 | }; | 90 | }; |
91 | 91 | ||
92 | 92 | ||
93 | static QValueList<MediaPlayerPlugin> pluginList; | 93 | static QValueList<MediaPlayerPlugin> pluginList; |
94 | 94 | ||
95 | 95 | ||
96 | // Find the first decoder which supports this type of file | 96 | // Find the first decoder which supports this type of file |
97 | MediaPlayerDecoder *MediaPlayerState::newDecoder( const QString& file ) { | 97 | MediaPlayerDecoder *MediaPlayerState::newDecoder( const QString& file ) { |
98 | MediaPlayerDecoder *tmpDecoder = NULL; | 98 | MediaPlayerDecoder *tmpDecoder = NULL; |
99 | QValueList<MediaPlayerPlugin>::Iterator it; | 99 | QValueList<MediaPlayerPlugin>::Iterator it; |
100 | for ( it = pluginList.begin(); it != pluginList.end(); ++it ) { | 100 | for ( it = pluginList.begin(); it != pluginList.end(); ++it ) { |
101 | if ( (*it).decoder->isFileSupported( file ) ) { | 101 | if ( (*it).decoder->isFileSupported( file ) ) { |
102 | tmpDecoder = (*it).decoder; | 102 | tmpDecoder = (*it).decoder; |
103 | break; | 103 | break; |
104 | } | 104 | } |
105 | } | 105 | } |
106 | if(file.left(4)=="http") | 106 | if(file.left(4)=="http") |
107 | isStreaming = TRUE; | 107 | isStreaming = TRUE; |
108 | else | 108 | else |
109 | isStreaming = FALSE; | 109 | isStreaming = FALSE; |
110 | return decoder = tmpDecoder; | 110 | return decoder = tmpDecoder; |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | MediaPlayerDecoder *MediaPlayerState::curDecoder() { | 114 | MediaPlayerDecoder *MediaPlayerState::curDecoder() { |
115 | return decoder; | 115 | return decoder; |
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
119 | // ### hack to get true sample count | 119 | // ### hack to get true sample count |
120 | MediaPlayerDecoder *MediaPlayerState::libMpeg3Decoder() { | 120 | MediaPlayerDecoder *MediaPlayerState::libMpeg3Decoder() { |
121 | return libmpeg3decoder; | 121 | return libmpeg3decoder; |
122 | } | 122 | } |
123 | 123 | ||
124 | // ### hack to get true sample count | 124 | // ### hack to get true sample count |
125 | // MediaPlayerDecoder *MediaPlayerState::libWavDecoder() { | 125 | // MediaPlayerDecoder *MediaPlayerState::libWavDecoder() { |
126 | // return libwavdecoder; | 126 | // return libwavdecoder; |
127 | // } | 127 | // } |
128 | 128 | ||
129 | void MediaPlayerState::loadPlugins() { | 129 | void MediaPlayerState::loadPlugins() { |
130 | qDebug("load plugins"); | 130 | qDebug("load plugins"); |
131 | #ifndef QT_NO_COMPONENT | 131 | #ifndef QT_NO_COMPONENT |
132 | QValueList<MediaPlayerPlugin>::Iterator mit; | 132 | QValueList<MediaPlayerPlugin>::Iterator mit; |
133 | for ( mit = pluginList.begin(); mit != pluginList.end(); ++mit ) { | 133 | for ( mit = pluginList.begin(); mit != pluginList.end(); ++mit ) { |
134 | (*mit).iface->release(); | 134 | (*mit).iface->release(); |
135 | (*mit).library->unload(); | 135 | (*mit).library->unload(); |
136 | delete (*mit).library; | 136 | delete (*mit).library; |
137 | } | 137 | } |
138 | pluginList.clear(); | 138 | pluginList.clear(); |
139 | 139 | ||
140 | QString path = QPEApplication::qpeDir() + "/plugins/codecs"; | 140 | QString path = QPEApplication::qpeDir() + "/plugins/codecs"; |
141 | QDir dir( path, "lib*.so" ); | 141 | QDir dir( path, "lib*.so" ); |
142 | QStringList list = dir.entryList(); | 142 | QStringList list = dir.entryList(); |
143 | QStringList::Iterator it; | 143 | QStringList::Iterator it; |
144 | for ( it = list.begin(); it != list.end(); ++it ) { | 144 | for ( it = list.begin(); it != list.end(); ++it ) { |
145 | MediaPlayerPluginInterface *iface = 0; | 145 | MediaPlayerPluginInterface *iface = 0; |
146 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 146 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
147 | // qDebug( "querying: %s", QString( path + "/" + *it ).latin1() ); | 147 | // qDebug( "querying: %s", QString( path + "/" + *it ).latin1() ); |
148 | 148 | ||
149 | if ( lib->queryInterface( IID_MediaPlayerPlugin, (QUnknownInterface**)&iface ) == QS_OK ) { | 149 | if ( lib->queryInterface( IID_MediaPlayerPlugin, (QUnknownInterface**)&iface ) == QS_OK ) { |
150 | 150 | ||
151 | // qDebug( "loading: %s", QString( path + "/" + *it ).latin1() ); | 151 | // qDebug( "loading: %s", QString( path + "/" + *it ).latin1() ); |
152 | 152 | ||
153 | MediaPlayerPlugin plugin; | 153 | MediaPlayerPlugin plugin; |
154 | plugin.library = lib; | 154 | plugin.library = lib; |
155 | plugin.iface = iface; | 155 | plugin.iface = iface; |
156 | plugin.decoder = plugin.iface->decoder(); | 156 | plugin.decoder = plugin.iface->decoder(); |
157 | plugin.encoder = plugin.iface->encoder(); | 157 | plugin.encoder = plugin.iface->encoder(); |
158 | pluginList.append( plugin ); | 158 | pluginList.append( plugin ); |
159 | 159 | ||
160 | // ### hack to get true sample count | 160 | // ### hack to get true sample count |
161 | if ( plugin.decoder->pluginName() == QString("LibMpeg3Plugin") ) | 161 | if ( plugin.decoder->pluginName() == QString("LibMpeg3Plugin") ) |
162 | libmpeg3decoder = plugin.decoder; | 162 | libmpeg3decoder = plugin.decoder; |
163 | 163 | ||
164 | } else { | 164 | } else { |
165 | delete lib; | 165 | delete lib; |
166 | } | 166 | } |
167 | } | 167 | } |
168 | #else | 168 | #else |
169 | pluginList.clear(); | 169 | pluginList.clear(); |
170 | 170 | ||
171 | MediaPlayerPlugin plugin0; | 171 | MediaPlayerPlugin plugin0; |
172 | plugin0.iface = new LibMpeg3PluginImpl; | 172 | plugin0.iface = new LibMpeg3PluginImpl; |
173 | plugin0.decoder = plugin0.iface->decoder(); | 173 | plugin0.decoder = plugin0.iface->decoder(); |
174 | plugin0.encoder = plugin0.iface->encoder(); | 174 | plugin0.encoder = plugin0.iface->encoder(); |
175 | pluginList.append( plugin0 ); | 175 | pluginList.append( plugin0 ); |
176 | 176 | ||
177 | MediaPlayerPlugin plugin1; | 177 | MediaPlayerPlugin plugin1; |
178 | plugin1.iface = new LibMadPluginImpl; | 178 | plugin1.iface = new LibMadPluginImpl; |
179 | plugin1.decoder = plugin1.iface->decoder(); | 179 | plugin1.decoder = plugin1.iface->decoder(); |
180 | plugin1.encoder = plugin1.iface->encoder(); | 180 | plugin1.encoder = plugin1.iface->encoder(); |
181 | pluginList.append( plugin1 ); | 181 | pluginList.append( plugin1 ); |
182 | 182 | ||
183 | MediaPlayerPlugin plugin2; | 183 | MediaPlayerPlugin plugin2; |
184 | plugin2.iface = new WavPluginImpl; | 184 | plugin2.iface = new WavPluginImpl; |
185 | plugin2.decoder = plugin2.iface->decoder(); | 185 | plugin2.decoder = plugin2.iface->decoder(); |
186 | plugin2.encoder = plugin2.iface->encoder(); | 186 | plugin2.encoder = plugin2.iface->encoder(); |
187 | pluginList.append( plugin2 ); | 187 | pluginList.append( plugin2 ); |
188 | #endif | 188 | #endif |
189 | 189 | ||
190 | if ( pluginList.count() ) | 190 | if ( pluginList.count() ) |
191 | MediaPlayerDebug(( "%i decoders found", pluginList.count() )); | 191 | MediaPlayerDebug(( "%i decoders found", pluginList.count() )); |
192 | else | 192 | else |
193 | MediaPlayerDebug(( "No decoders found" )); | 193 | MediaPlayerDebug(( "No decoders found" )); |
194 | } | 194 | } |
195 | 195 | ||
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index 200ec16..35208e4 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp | |||
@@ -1,503 +1,507 @@ | |||
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 | #define QTOPIA_INTERNAL_FSLP | 21 | #define QTOPIA_INTERNAL_FSLP |
22 | #include <qpe/qcopenvelope_qws.h> | 22 | #include <qpe/qcopenvelope_qws.h> |
23 | 23 | ||
24 | #include <qpe/qpemenubar.h> | 24 | #include <qpe/qpemenubar.h> |
25 | #include <qpe/qpetoolbar.h> | 25 | #include <qpe/qpetoolbar.h> |
26 | #include <qpe/fileselector.h> | 26 | #include <qpe/fileselector.h> |
27 | #include <qpe/qpeapplication.h> | 27 | #include <qpe/qpeapplication.h> |
28 | #include <qpe/lnkproperties.h> | 28 | #include <qpe/lnkproperties.h> |
29 | #include <qpe/storage.h> | 29 | #include <qpe/storage.h> |
30 | 30 | ||
31 | #include <qpe/applnk.h> | 31 | #include <qpe/applnk.h> |
32 | #include <qpe/config.h> | 32 | #include <qpe/config.h> |
33 | #include <qpe/global.h> | 33 | #include <qpe/global.h> |
34 | #include <qpe/resource.h> | 34 | #include <qpe/resource.h> |
35 | #include <qaction.h> | 35 | #include <qaction.h> |
36 | #include <qcursor.h> | 36 | #include <qcursor.h> |
37 | #include <qimage.h> | 37 | #include <qimage.h> |
38 | #include <qfile.h> | 38 | #include <qfile.h> |
39 | #include <qdir.h> | 39 | #include <qdir.h> |
40 | #include <qlayout.h> | 40 | #include <qlayout.h> |
41 | #include <qlabel.h> | 41 | #include <qlabel.h> |
42 | #include <qlist.h> | 42 | #include <qlist.h> |
43 | #include <qlistbox.h> | 43 | #include <qlistbox.h> |
44 | #include <qmainwindow.h> | 44 | #include <qmainwindow.h> |
45 | #include <qmessagebox.h> | 45 | #include <qmessagebox.h> |
46 | #include <qtoolbutton.h> | 46 | #include <qtoolbutton.h> |
47 | #include <qtabwidget.h> | 47 | #include <qtabwidget.h> |
48 | #include <qlistview.h> | 48 | #include <qlistview.h> |
49 | #include <qpoint.h> | 49 | #include <qpoint.h> |
50 | #include <qlineedit.h> | 50 | #include <qlineedit.h> |
51 | #include <qpushbutton.h> | 51 | #include <qpushbutton.h> |
52 | #include <qregexp.h> | 52 | #include <qregexp.h> |
53 | #include <qtextstream.h> | 53 | #include <qtextstream.h> |
54 | 54 | ||
55 | //#include <qtimer.h> | 55 | //#include <qtimer.h> |
56 | 56 | ||
57 | #include "playlistselection.h" | 57 | #include "playlistselection.h" |
58 | #include "playlistwidget.h" | 58 | #include "playlistwidget.h" |
59 | #include "mediaplayerstate.h" | 59 | #include "mediaplayerstate.h" |
60 | 60 | ||
61 | #include "inputDialog.h" | 61 | #include "inputDialog.h" |
62 | 62 | ||
63 | #include <stdlib.h> | 63 | #include <stdlib.h> |
64 | #include "audiowidget.h" | 64 | #include "audiowidget.h" |
65 | #include "videowidget.h" | 65 | #include "videowidget.h" |
66 | 66 | ||
67 | #include <unistd.h> | 67 | #include <unistd.h> |
68 | #include <sys/file.h> | 68 | #include <sys/file.h> |
69 | #include <sys/ioctl.h> | 69 | #include <sys/ioctl.h> |
70 | #include <sys/soundcard.h> | 70 | #include <sys/soundcard.h> |
71 | 71 | ||
72 | // for setBacklight() | 72 | // for setBacklight() |
73 | #include <linux/fb.h> | 73 | #include <linux/fb.h> |
74 | #include <sys/types.h> | 74 | #include <sys/types.h> |
75 | #include <sys/stat.h> | 75 | #include <sys/stat.h> |
76 | #include <stdlib.h> | 76 | #include <stdlib.h> |
77 | 77 | ||
78 | #define BUTTONS_ON_TOOLBAR | 78 | #define BUTTONS_ON_TOOLBAR |
79 | #define SIDE_BUTTONS | 79 | #define SIDE_BUTTONS |
80 | #define CAN_SAVE_LOAD_PLAYLISTS | 80 | #define CAN_SAVE_LOAD_PLAYLISTS |
81 | 81 | ||
82 | extern AudioWidget *audioUI; | 82 | extern AudioWidget *audioUI; |
83 | extern VideoWidget *videoUI; | 83 | extern VideoWidget *videoUI; |
84 | extern MediaPlayerState *mediaPlayerState; | 84 | extern MediaPlayerState *mediaPlayerState; |
85 | 85 | ||
86 | // class myFileSelector { | 86 | // class myFileSelector { |
87 | 87 | ||
88 | // }; | 88 | // }; |
89 | class PlayListWidgetPrivate { | 89 | class PlayListWidgetPrivate { |
90 | public: | 90 | public: |
91 | QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; | 91 | QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; |
92 | QFrame *playListFrame; | 92 | QFrame *playListFrame; |
93 | FileSelector *files; | 93 | FileSelector *files; |
94 | PlayListSelection *selectedFiles; | 94 | PlayListSelection *selectedFiles; |
95 | bool setDocumentUsed; | 95 | bool setDocumentUsed; |
96 | DocLnk *current; | 96 | DocLnk *current; |
97 | }; | 97 | }; |
98 | 98 | ||
99 | 99 | ||
100 | class ToolButton : public QToolButton { | 100 | class ToolButton : public QToolButton { |
101 | public: | 101 | public: |
102 | ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) | 102 | ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) |
103 | : QToolButton( parent, name ) { | 103 | : QToolButton( parent, name ) { |
104 | setTextLabel( name ); | 104 | setTextLabel( name ); |
105 | setPixmap( Resource::loadPixmap( icon ) ); | 105 | setPixmap( Resource::loadPixmap( icon ) ); |
106 | setAutoRaise( TRUE ); | 106 | setAutoRaise( TRUE ); |
107 | setFocusPolicy( QWidget::NoFocus ); | 107 | setFocusPolicy( QWidget::NoFocus ); |
108 | setToggleButton( t ); | 108 | setToggleButton( t ); |
109 | connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); | 109 | connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); |
110 | QPEMenuToolFocusManager::manager()->addWidget( this ); | 110 | QPEMenuToolFocusManager::manager()->addWidget( this ); |
111 | } | 111 | } |
112 | }; | 112 | }; |
113 | 113 | ||
114 | 114 | ||
115 | class MenuItem : public QAction { | 115 | class MenuItem : public QAction { |
116 | public: | 116 | public: |
117 | MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) | 117 | MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) |
118 | : QAction( text, QString::null, 0, 0 ) { | 118 | : QAction( text, QString::null, 0, 0 ) { |
119 | connect( this, SIGNAL( activated() ), handler, slot ); | 119 | connect( this, SIGNAL( activated() ), handler, slot ); |
120 | addTo( parent ); | 120 | addTo( parent ); |
121 | } | 121 | } |
122 | }; | 122 | }; |
123 | 123 | ||
124 | 124 | ||
125 | PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) | 125 | PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) |
126 | : QMainWindow( parent, name, fl ) { | 126 | : QMainWindow( parent, name, fl ) { |
127 | 127 | ||
128 | d = new PlayListWidgetPrivate; | 128 | d = new PlayListWidgetPrivate; |
129 | d->setDocumentUsed = FALSE; | 129 | d->setDocumentUsed = FALSE; |
130 | d->current = NULL; | 130 | d->current = NULL; |
131 | fromSetDocument = FALSE; | 131 | fromSetDocument = FALSE; |
132 | insanityBool=FALSE; | 132 | insanityBool=FALSE; |
133 | audioScan = FALSE; | 133 | audioScan = FALSE; |
134 | videoScan = FALSE; | 134 | videoScan = FALSE; |
135 | // menuTimer = new QTimer( this ,"menu timer"), | 135 | // menuTimer = new QTimer( this ,"menu timer"), |
136 | // connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); | 136 | // connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); |
137 | 137 | ||
138 | setBackgroundMode( PaletteButton ); | 138 | setBackgroundMode( PaletteButton ); |
139 | 139 | ||
140 | setCaption( tr("OpiePlayer") ); | 140 | setCaption( tr("OpiePlayer") ); |
141 | setIcon( Resource::loadPixmap( "opieplayer/MPEGPlayer" ) ); | 141 | setIcon( Resource::loadPixmap( "opieplayer/MPEGPlayer" ) ); |
142 | 142 | ||
143 | setToolBarsMovable( FALSE ); | 143 | setToolBarsMovable( FALSE ); |
144 | 144 | ||
145 | // Create Toolbar | 145 | // Create Toolbar |
146 | QPEToolBar *toolbar = new QPEToolBar( this ); | 146 | QPEToolBar *toolbar = new QPEToolBar( this ); |
147 | toolbar->setHorizontalStretchable( TRUE ); | 147 | toolbar->setHorizontalStretchable( TRUE ); |
148 | 148 | ||
149 | // Create Menubar | 149 | // Create Menubar |
150 | QPEMenuBar *menu = new QPEMenuBar( toolbar ); | 150 | QPEMenuBar *menu = new QPEMenuBar( toolbar ); |
151 | menu->setMargin( 0 ); | 151 | menu->setMargin( 0 ); |
152 | 152 | ||
153 | QPEToolBar *bar = new QPEToolBar( this ); | 153 | QPEToolBar *bar = new QPEToolBar( this ); |
154 | bar->setLabel( tr( "Play Operations" ) ); | 154 | bar->setLabel( tr( "Play Operations" ) ); |
155 | // d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "opieplayer/play_current_list", | 155 | // d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "opieplayer/play_current_list", |
156 | // this , SLOT( addSelected()) ); | 156 | // this , SLOT( addSelected()) ); |
157 | tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); | 157 | tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); |
158 | tbDeletePlaylist->setFlat(TRUE); | 158 | tbDeletePlaylist->setFlat(TRUE); |
159 | tbDeletePlaylist->setFixedSize(20,20); | 159 | tbDeletePlaylist->setFixedSize(20,20); |
160 | connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); | ||
161 | 160 | ||
162 | d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "opieplayer/add_to_playlist", | 161 | d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "opieplayer/add_to_playlist", |
163 | this , SLOT(addSelected()) ); | 162 | this , SLOT(addSelected()) ); |
164 | d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "opieplayer/remove_from_playlist", | 163 | d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "opieplayer/remove_from_playlist", |
165 | this , SLOT(removeSelected()) ); | 164 | this , SLOT(removeSelected()) ); |
166 | // d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); | 165 | // d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); |
167 | d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", | 166 | d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", |
168 | this , SLOT( btnPlay(bool) ), TRUE ); | 167 | this , SLOT( btnPlay(bool) ), TRUE ); |
169 | d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle", | 168 | d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle", |
170 | mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); | 169 | mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); |
171 | d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop", | 170 | d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop", |
172 | mediaPlayerState, SLOT(setLooping(bool)), TRUE ); | 171 | mediaPlayerState, SLOT(setLooping(bool)), TRUE ); |
173 | tbDeletePlaylist->hide(); | 172 | tbDeletePlaylist->hide(); |
174 | 173 | ||
175 | QPopupMenu *pmPlayList = new QPopupMenu( this ); | 174 | QPopupMenu *pmPlayList = new QPopupMenu( this ); |
176 | menu->insertItem( tr( "File" ), pmPlayList ); | 175 | menu->insertItem( tr( "File" ), pmPlayList ); |
177 | new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); | 176 | new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); |
178 | new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); | 177 | new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); |
179 | new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); | 178 | new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); |
180 | new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); | 179 | new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); |
181 | // pmPlayList->insertSeparator(-1); | 180 | // pmPlayList->insertSeparator(-1); |
182 | new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); | 181 | new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); |
183 | pmPlayList->insertSeparator(-1); | 182 | pmPlayList->insertSeparator(-1); |
184 | new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); | 183 | new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); |
185 | pmPlayList->insertSeparator(-1); | 184 | pmPlayList->insertSeparator(-1); |
186 | new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) ); | 185 | new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) ); |
187 | new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) ); | 186 | new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) ); |
188 | 187 | ||
189 | QPopupMenu *pmView = new QPopupMenu( this ); | 188 | QPopupMenu *pmView = new QPopupMenu( this ); |
190 | menu->insertItem( tr( "View" ), pmView ); | 189 | menu->insertItem( tr( "View" ), pmView ); |
191 | 190 | ||
192 | fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); | 191 | fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); |
193 | connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); | ||
194 | fullScreenButton->addTo(pmView); | 192 | fullScreenButton->addTo(pmView); |
195 | scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0); | 193 | scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0); |
196 | connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); | ||
197 | scaleButton->addTo(pmView); | 194 | scaleButton->addTo(pmView); |
198 | 195 | ||
199 | QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); | 196 | QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); |
200 | QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); | 197 | QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); |
201 | 198 | ||
202 | QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); | 199 | QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); |
203 | 200 | ||
204 | tabWidget = new QTabWidget( hbox6, "tabWidget" ); | 201 | tabWidget = new QTabWidget( hbox6, "tabWidget" ); |
205 | tabWidget->setTabShape(QTabWidget::Triangular); | 202 | tabWidget->setTabShape(QTabWidget::Triangular); |
206 | 203 | ||
207 | QWidget *pTab; | 204 | QWidget *pTab; |
208 | pTab = new QWidget( tabWidget, "pTab" ); | 205 | pTab = new QWidget( tabWidget, "pTab" ); |
209 | // playlistView = new QListView( pTab, "playlistview" ); | 206 | // playlistView = new QListView( pTab, "playlistview" ); |
210 | // playlistView->setMinimumSize(236,260); | 207 | // playlistView->setMinimumSize(236,260); |
211 | tabWidget->insertTab( pTab,"Playlist"); | 208 | tabWidget->insertTab( pTab,"Playlist"); |
212 | 209 | ||
213 | 210 | ||
214 | // Add the playlist area | 211 | // Add the playlist area |
215 | 212 | ||
216 | QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); | 213 | QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); |
217 | d->playListFrame = vbox3; | 214 | d->playListFrame = vbox3; |
218 | d->playListFrame ->setMinimumSize(235,260); | 215 | d->playListFrame ->setMinimumSize(235,260); |
219 | 216 | ||
220 | QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); | 217 | QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); |
221 | 218 | ||
222 | d->selectedFiles = new PlayListSelection( hbox2); | 219 | d->selectedFiles = new PlayListSelection( hbox2); |
223 | QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); | 220 | QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); |
224 | 221 | ||
225 | QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); | 222 | QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); |
226 | 223 | ||
227 | connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
228 | this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
229 | 224 | ||
230 | 225 | ||
231 | QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch | 226 | QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch |
232 | new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); | 227 | new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); |
233 | new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); | 228 | new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); |
234 | new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); | 229 | new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); |
235 | QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch | 230 | QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch |
236 | 231 | ||
237 | QWidget *aTab; | 232 | QWidget *aTab; |
238 | aTab = new QWidget( tabWidget, "aTab" ); | 233 | aTab = new QWidget( tabWidget, "aTab" ); |
239 | audioView = new QListView( aTab, "Audioview" ); | 234 | audioView = new QListView( aTab, "Audioview" ); |
240 | audioView->setMinimumSize(233,260); | 235 | audioView->setMinimumSize(233,260); |
241 | audioView->addColumn( tr("Title"),140); | 236 | audioView->addColumn( tr("Title"),140); |
242 | audioView->addColumn(tr("Size"), -1); | 237 | audioView->addColumn(tr("Size"), -1); |
243 | audioView->addColumn(tr("Media"),-1); | 238 | audioView->addColumn(tr("Media"),-1); |
244 | audioView->setColumnAlignment(1, Qt::AlignRight); | 239 | audioView->setColumnAlignment(1, Qt::AlignRight); |
245 | audioView->setColumnAlignment(2, Qt::AlignRight); | 240 | audioView->setColumnAlignment(2, Qt::AlignRight); |
246 | audioView->setAllColumnsShowFocus(TRUE); | 241 | audioView->setAllColumnsShowFocus(TRUE); |
247 | 242 | ||
248 | audioView->setMultiSelection( TRUE ); | 243 | audioView->setMultiSelection( TRUE ); |
249 | audioView->setSelectionMode( QListView::Extended); | 244 | audioView->setSelectionMode( QListView::Extended); |
250 | 245 | ||
251 | tabWidget->insertTab(aTab,tr("Audio")); | 246 | tabWidget->insertTab(aTab,tr("Audio")); |
252 | 247 | ||
253 | QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); | 248 | QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); |
254 | connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
255 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
256 | |||
257 | connect( audioView, SIGNAL( returnPressed( QListViewItem *)), | ||
258 | this,SLOT( playIt( QListViewItem *)) ); | ||
259 | 249 | ||
260 | // audioView | 250 | // audioView |
261 | // populateAudioView(); | 251 | // populateAudioView(); |
262 | // videowidget | 252 | // videowidget |
263 | 253 | ||
264 | QWidget *vTab; | 254 | QWidget *vTab; |
265 | vTab = new QWidget( tabWidget, "vTab" ); | 255 | vTab = new QWidget( tabWidget, "vTab" ); |
266 | videoView = new QListView( vTab, "Videoview" ); | 256 | videoView = new QListView( vTab, "Videoview" ); |
267 | videoView->setMinimumSize(233,260); | 257 | videoView->setMinimumSize(233,260); |
268 | 258 | ||
269 | videoView->addColumn(tr("Title"),140); | 259 | videoView->addColumn(tr("Title"),140); |
270 | videoView->addColumn(tr("Size"),-1); | 260 | videoView->addColumn(tr("Size"),-1); |
271 | videoView->addColumn(tr("Media"),-1); | 261 | videoView->addColumn(tr("Media"),-1); |
272 | videoView->setColumnAlignment(1, Qt::AlignRight); | 262 | videoView->setColumnAlignment(1, Qt::AlignRight); |
273 | videoView->setColumnAlignment(2, Qt::AlignRight); | 263 | videoView->setColumnAlignment(2, Qt::AlignRight); |
274 | videoView->setAllColumnsShowFocus(TRUE); | 264 | videoView->setAllColumnsShowFocus(TRUE); |
275 | videoView->setMultiSelection( TRUE ); | 265 | videoView->setMultiSelection( TRUE ); |
276 | videoView->setSelectionMode( QListView::Extended); | 266 | videoView->setSelectionMode( QListView::Extended); |
277 | 267 | ||
278 | QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); | 268 | QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); |
279 | 269 | ||
280 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
281 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
282 | connect( videoView, SIGNAL( returnPressed( QListViewItem *)), | ||
283 | this,SLOT( playIt( QListViewItem *)) ); | ||
284 | |||
285 | tabWidget->insertTab( vTab,tr("Video")); | 270 | tabWidget->insertTab( vTab,tr("Video")); |
286 | // populateVideoView(); | 271 | // populateVideoView(); |
287 | 272 | ||
288 | //playlists list | 273 | //playlists list |
289 | QWidget *LTab; | 274 | QWidget *LTab; |
290 | LTab = new QWidget( tabWidget, "LTab" ); | 275 | LTab = new QWidget( tabWidget, "LTab" ); |
291 | playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy | 276 | playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy |
292 | playLists->setMinimumSize(233,260); | 277 | playLists->setMinimumSize(233,260); |
293 | tabWidget->insertTab(LTab,tr("Lists")); | 278 | tabWidget->insertTab(LTab,tr("Lists")); |
294 | 279 | ||
295 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); | ||
296 | // connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 280 | // connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
297 | 281 | ||
298 | // add the library area | 282 | // add the library area |
299 | 283 | ||
300 | // connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), | 284 | // connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), |
301 | // this, SLOT( fauxPlay( QListViewItem *) ) ); | 285 | // this, SLOT( fauxPlay( QListViewItem *) ) ); |
302 | // connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), | 286 | // connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), |
303 | // this, SLOT( fauxPlay( QListViewItem *)) ); | 287 | // this, SLOT( fauxPlay( QListViewItem *)) ); |
304 | 288 | ||
305 | // connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); | 289 | // connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); |
306 | // connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); | 290 | // connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); |
307 | 291 | ||
308 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | 292 | connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); |
293 | connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); | ||
294 | connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); | ||
295 | connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
296 | this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
297 | |||
298 | connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
299 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
300 | |||
301 | connect( audioView, SIGNAL( returnPressed( QListViewItem *)), | ||
302 | this,SLOT( playIt( QListViewItem *)) ); | ||
303 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | ||
304 | |||
305 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
306 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
307 | connect( videoView, SIGNAL( returnPressed( QListViewItem *)), | ||
308 | this,SLOT( playIt( QListViewItem *)) ); | ||
309 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | 309 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); |
310 | 310 | ||
311 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); | ||
312 | |||
313 | |||
311 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); | 314 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); |
315 | |||
312 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); | 316 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); |
313 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); | 317 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); |
314 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); | 318 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); |
315 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); | 319 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); |
316 | 320 | ||
317 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); | 321 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); |
318 | // connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); | 322 | // connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); |
319 | 323 | ||
320 | setCentralWidget( vbox5 ); | 324 | setCentralWidget( vbox5 ); |
321 | 325 | ||
322 | Config cfg( "OpiePlayer" ); | 326 | Config cfg( "OpiePlayer" ); |
323 | readConfig( cfg ); | 327 | readConfig( cfg ); |
324 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | 328 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); |
325 | // qDebug("currentList is "+currentPlaylist); | 329 | // qDebug("currentList is "+currentPlaylist); |
326 | loadList(DocLnk( currentPlaylist)); | 330 | loadList(DocLnk( currentPlaylist)); |
327 | setCaption(tr("OpiePlayer: ")+ currentPlaylist ); | 331 | setCaption(tr("OpiePlayer: ")+ currentPlaylist ); |
328 | 332 | ||
329 | initializeStates(); | 333 | initializeStates(); |
330 | } | 334 | } |
331 | 335 | ||
332 | 336 | ||
333 | PlayListWidget::~PlayListWidget() { | 337 | PlayListWidget::~PlayListWidget() { |
334 | Config cfg( "OpiePlayer" ); | 338 | Config cfg( "OpiePlayer" ); |
335 | writeConfig( cfg ); | 339 | writeConfig( cfg ); |
336 | 340 | ||
337 | 341 | ||
338 | if ( d->current ) | 342 | if ( d->current ) |
339 | delete d->current; | 343 | delete d->current; |
340 | delete d; | 344 | delete d; |
341 | } | 345 | } |
342 | 346 | ||
343 | 347 | ||
344 | void PlayListWidget::initializeStates() { | 348 | void PlayListWidget::initializeStates() { |
345 | 349 | ||
346 | d->tbPlay->setOn( mediaPlayerState->playing() ); | 350 | d->tbPlay->setOn( mediaPlayerState->playing() ); |
347 | d->tbLoop->setOn( mediaPlayerState->looping() ); | 351 | d->tbLoop->setOn( mediaPlayerState->looping() ); |
348 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); | 352 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); |
349 | // d->tbFull->setOn( mediaPlayerState->fullscreen() ); | 353 | // d->tbFull->setOn( mediaPlayerState->fullscreen() ); |
350 | // d->tbScale->setOn( mediaPlayerState->scaled() ); | 354 | // d->tbScale->setOn( mediaPlayerState->scaled() ); |
351 | // d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); | 355 | // d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); |
352 | // setPlaylist( mediaPlayerState->playlist() ); | 356 | // setPlaylist( mediaPlayerState->playlist() ); |
353 | setPlaylist( true); | 357 | setPlaylist( true); |
354 | // d->selectedFiles->first(); | 358 | // d->selectedFiles->first(); |
355 | 359 | ||
356 | } | 360 | } |
357 | 361 | ||
358 | 362 | ||
359 | void PlayListWidget::readConfig( Config& cfg ) { | 363 | void PlayListWidget::readConfig( Config& cfg ) { |
360 | cfg.setGroup("PlayList"); | 364 | cfg.setGroup("PlayList"); |
361 | QString currentString = cfg.readEntry("current", "" ); | 365 | QString currentString = cfg.readEntry("current", "" ); |
362 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 366 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
363 | for ( int i = 0; i < noOfFiles; i++ ) { | 367 | for ( int i = 0; i < noOfFiles; i++ ) { |
364 | QString entryName; | 368 | QString entryName; |
365 | entryName.sprintf( "File%i", i + 1 ); | 369 | entryName.sprintf( "File%i", i + 1 ); |
366 | QString linkFile = cfg.readEntry( entryName ); | 370 | QString linkFile = cfg.readEntry( entryName ); |
367 | DocLnk lnk( linkFile ); | 371 | DocLnk lnk( linkFile ); |
368 | if ( lnk.isValid() ) { | 372 | if ( lnk.isValid() ) { |
369 | d->selectedFiles->addToSelection( lnk ); | 373 | d->selectedFiles->addToSelection( lnk ); |
370 | } | 374 | } |
371 | } | 375 | } |
372 | d->selectedFiles->setSelectedItem( currentString); | 376 | d->selectedFiles->setSelectedItem( currentString); |
373 | // d->selectedFiles->setSelectedItem( (const QString &)currentString); | 377 | // d->selectedFiles->setSelectedItem( (const QString &)currentString); |
374 | } | 378 | } |
375 | 379 | ||
376 | 380 | ||
377 | void PlayListWidget::writeConfig( Config& cfg ) const { | 381 | void PlayListWidget::writeConfig( Config& cfg ) const { |
378 | 382 | ||
379 | d->selectedFiles->writeCurrent( cfg); | 383 | d->selectedFiles->writeCurrent( cfg); |
380 | cfg.setGroup("PlayList"); | 384 | cfg.setGroup("PlayList"); |
381 | int noOfFiles = 0; | 385 | int noOfFiles = 0; |
382 | d->selectedFiles->first(); | 386 | d->selectedFiles->first(); |
383 | do { | 387 | do { |
384 | const DocLnk *lnk = d->selectedFiles->current(); | 388 | const DocLnk *lnk = d->selectedFiles->current(); |
385 | if ( lnk ) { | 389 | if ( lnk ) { |
386 | QString entryName; | 390 | QString entryName; |
387 | entryName.sprintf( "File%i", noOfFiles + 1 ); | 391 | entryName.sprintf( "File%i", noOfFiles + 1 ); |
388 | // qDebug(entryName); | 392 | // qDebug(entryName); |
389 | cfg.writeEntry( entryName, lnk->linkFile() ); | 393 | cfg.writeEntry( entryName, lnk->linkFile() ); |
390 | // if this link does exist, add it so we have the file | 394 | // if this link does exist, add it so we have the file |
391 | // next time... | 395 | // next time... |
392 | if ( !QFile::exists( lnk->linkFile() ) ) { | 396 | if ( !QFile::exists( lnk->linkFile() ) ) { |
393 | // the way writing lnks doesn't really check for out | 397 | // the way writing lnks doesn't really check for out |
394 | // of disk space, but check it anyway. | 398 | // of disk space, but check it anyway. |
395 | if ( !lnk->writeLink() ) { | 399 | if ( !lnk->writeLink() ) { |
396 | QMessageBox::critical( 0, tr("Out of space"), | 400 | QMessageBox::critical( 0, tr("Out of space"), |
397 | tr( "There was a problem saving " | 401 | tr( "There was a problem saving " |
398 | "the playlist.\n" | 402 | "the playlist.\n" |
399 | "Your playlist " | 403 | "Your playlist " |
400 | "may be missing some entries\n" | 404 | "may be missing some entries\n" |
401 | "the next time you start it." ) | 405 | "the next time you start it." ) |
402 | ); | 406 | ); |
403 | } | 407 | } |
404 | } | 408 | } |
405 | noOfFiles++; | 409 | noOfFiles++; |
406 | } | 410 | } |
407 | } | 411 | } |
408 | while ( d->selectedFiles->next() ); | 412 | while ( d->selectedFiles->next() ); |
409 | cfg.writeEntry("NumberOfFiles", noOfFiles ); | 413 | cfg.writeEntry("NumberOfFiles", noOfFiles ); |
410 | } | 414 | } |
411 | 415 | ||
412 | 416 | ||
413 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { | 417 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { |
414 | // qDebug("add"); | 418 | // qDebug("add"); |
415 | d->setDocumentUsed = FALSE; | 419 | d->setDocumentUsed = FALSE; |
416 | if ( mediaPlayerState->playlist() ) | 420 | if ( mediaPlayerState->playlist() ) |
417 | d->selectedFiles->addToSelection( lnk ); | 421 | d->selectedFiles->addToSelection( lnk ); |
418 | else | 422 | else |
419 | mediaPlayerState->setPlaying( TRUE ); | 423 | mediaPlayerState->setPlaying( TRUE ); |
420 | } | 424 | } |
421 | 425 | ||
422 | 426 | ||
423 | void PlayListWidget::clearList() { | 427 | void PlayListWidget::clearList() { |
424 | while ( first() ) | 428 | while ( first() ) |
425 | d->selectedFiles->removeSelected(); | 429 | d->selectedFiles->removeSelected(); |
426 | } | 430 | } |
427 | 431 | ||
428 | 432 | ||
429 | void PlayListWidget::addAllToList() { | 433 | void PlayListWidget::addAllToList() { |
430 | DocLnkSet filesAll; | 434 | DocLnkSet filesAll; |
431 | Global::findDocuments(&filesAll, "video/*;audio/*"); | 435 | Global::findDocuments(&filesAll, "video/*;audio/*"); |
432 | QListIterator<DocLnk> Adit( filesAll.children() ); | 436 | QListIterator<DocLnk> Adit( filesAll.children() ); |
433 | for ( ; Adit.current(); ++Adit ) | 437 | for ( ; Adit.current(); ++Adit ) |
434 | d->selectedFiles->addToSelection( **Adit ); | 438 | d->selectedFiles->addToSelection( **Adit ); |
435 | } | 439 | } |
436 | 440 | ||
437 | 441 | ||
438 | void PlayListWidget::addAllMusicToList() { | 442 | void PlayListWidget::addAllMusicToList() { |
439 | QListIterator<DocLnk> dit( files.children() ); | 443 | QListIterator<DocLnk> dit( files.children() ); |
440 | for ( ; dit.current(); ++dit ) | 444 | for ( ; dit.current(); ++dit ) |
441 | d->selectedFiles->addToSelection( **dit ); | 445 | d->selectedFiles->addToSelection( **dit ); |
442 | } | 446 | } |
443 | 447 | ||
444 | 448 | ||
445 | void PlayListWidget::addAllVideoToList() { | 449 | void PlayListWidget::addAllVideoToList() { |
446 | QListIterator<DocLnk> dit( vFiles.children() ); | 450 | QListIterator<DocLnk> dit( vFiles.children() ); |
447 | for ( ; dit.current(); ++dit ) | 451 | for ( ; dit.current(); ++dit ) |
448 | d->selectedFiles->addToSelection( **dit ); | 452 | d->selectedFiles->addToSelection( **dit ); |
449 | } | 453 | } |
450 | 454 | ||
451 | 455 | ||
452 | void PlayListWidget::setDocument(const QString& fileref) { | 456 | void PlayListWidget::setDocument(const QString& fileref) { |
453 | qDebug(fileref); | 457 | qDebug(fileref); |
454 | fromSetDocument = TRUE; | 458 | fromSetDocument = TRUE; |
455 | if ( fileref.isNull() ) { | 459 | if ( fileref.isNull() ) { |
456 | QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); | 460 | QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); |
457 | return; | 461 | return; |
458 | } | 462 | } |
459 | // qDebug("setDocument "+fileref); | 463 | // qDebug("setDocument "+fileref); |
460 | if(fileref.find("m3u",0,TRUE) != -1) { //is m3u | 464 | if(fileref.find("m3u",0,TRUE) != -1) { //is m3u |
461 | readm3u( fileref); | 465 | readm3u( fileref); |
462 | } | 466 | } |
463 | else if(fileref.find("pls",0,TRUE) != -1) { //is pls | 467 | else if(fileref.find("pls",0,TRUE) != -1) { //is pls |
464 | readPls( fileref); | 468 | readPls( fileref); |
465 | } | 469 | } |
466 | else if(fileref.find("playlist",0,TRUE) != -1) {//is playlist | 470 | else if(fileref.find("playlist",0,TRUE) != -1) {//is playlist |
467 | clearList(); | 471 | clearList(); |
468 | loadList(DocLnk(fileref)); | 472 | loadList(DocLnk(fileref)); |
469 | d->selectedFiles->first(); | 473 | d->selectedFiles->first(); |
470 | } else { | 474 | } else { |
471 | clearList(); | 475 | clearList(); |
472 | addToSelection( DocLnk( fileref ) ); | 476 | addToSelection( DocLnk( fileref ) ); |
473 | d->setDocumentUsed = TRUE; | 477 | d->setDocumentUsed = TRUE; |
474 | mediaPlayerState->setPlaying( FALSE ); | 478 | mediaPlayerState->setPlaying( FALSE ); |
475 | qApp->processEvents(); | 479 | qApp->processEvents(); |
476 | mediaPlayerState->setPlaying( TRUE ); | 480 | mediaPlayerState->setPlaying( TRUE ); |
477 | qApp->processEvents(); | 481 | qApp->processEvents(); |
478 | setCaption(tr("OpiePlayer")); | 482 | setCaption(tr("OpiePlayer")); |
479 | } | 483 | } |
480 | } | 484 | } |
481 | 485 | ||
482 | 486 | ||
483 | void PlayListWidget::setActiveWindow() { | 487 | void PlayListWidget::setActiveWindow() { |
484 | // When we get raised we need to ensure that it switches views | 488 | // When we get raised we need to ensure that it switches views |
485 | char origView = mediaPlayerState->view(); | 489 | char origView = mediaPlayerState->view(); |
486 | mediaPlayerState->setView( 'l' ); // invalidate | 490 | mediaPlayerState->setView( 'l' ); // invalidate |
487 | mediaPlayerState->setView( origView ); // now switch back | 491 | mediaPlayerState->setView( origView ); // now switch back |
488 | } | 492 | } |
489 | 493 | ||
490 | 494 | ||
491 | void PlayListWidget::useSelectedDocument() { | 495 | void PlayListWidget::useSelectedDocument() { |
492 | d->setDocumentUsed = FALSE; | 496 | d->setDocumentUsed = FALSE; |
493 | } | 497 | } |
494 | 498 | ||
495 | 499 | ||
496 | const DocLnk *PlayListWidget::current() { // this is fugly | 500 | const DocLnk *PlayListWidget::current() { // this is fugly |
497 | 501 | ||
498 | // if( fromSetDocument) { | 502 | // if( fromSetDocument) { |
499 | // qDebug("from setDoc"); | 503 | // qDebug("from setDoc"); |
500 | // DocLnkSet files; | 504 | // DocLnkSet files; |
501 | // Global::findDocuments(&files, "video/*;audio/*"); | 505 | // Global::findDocuments(&files, "video/*;audio/*"); |
502 | // QListIterator<DocLnk> dit( files.children() ); | 506 | // QListIterator<DocLnk> dit( files.children() ); |
503 | // for ( ; dit.current(); ++dit ) { | 507 | // for ( ; dit.current(); ++dit ) { |
@@ -563,467 +567,470 @@ bool PlayListWidget::prev() { | |||
563 | } | 567 | } |
564 | if ( cur == current() ) | 568 | if ( cur == current() ) |
565 | if ( !d->selectedFiles->next() ) | 569 | if ( !d->selectedFiles->next() ) |
566 | d->selectedFiles->first(); | 570 | d->selectedFiles->first(); |
567 | return TRUE; | 571 | return TRUE; |
568 | } else { | 572 | } else { |
569 | if ( !d->selectedFiles->prev() ) { | 573 | if ( !d->selectedFiles->prev() ) { |
570 | if ( mediaPlayerState->looping() ) { | 574 | if ( mediaPlayerState->looping() ) { |
571 | return d->selectedFiles->last(); | 575 | return d->selectedFiles->last(); |
572 | } else { | 576 | } else { |
573 | return FALSE; | 577 | return FALSE; |
574 | } | 578 | } |
575 | } | 579 | } |
576 | return TRUE; | 580 | return TRUE; |
577 | } | 581 | } |
578 | } else { | 582 | } else { |
579 | return mediaPlayerState->looping(); | 583 | return mediaPlayerState->looping(); |
580 | } | 584 | } |
581 | } | 585 | } |
582 | 586 | ||
583 | 587 | ||
584 | bool PlayListWidget::next() { | 588 | bool PlayListWidget::next() { |
585 | if ( mediaPlayerState->playlist() ) { | 589 | if ( mediaPlayerState->playlist() ) { |
586 | if ( mediaPlayerState->shuffled() ) { | 590 | if ( mediaPlayerState->shuffled() ) { |
587 | return prev(); | 591 | return prev(); |
588 | } else { | 592 | } else { |
589 | if ( !d->selectedFiles->next() ) { | 593 | if ( !d->selectedFiles->next() ) { |
590 | if ( mediaPlayerState->looping() ) { | 594 | if ( mediaPlayerState->looping() ) { |
591 | return d->selectedFiles->first(); | 595 | return d->selectedFiles->first(); |
592 | } else { | 596 | } else { |
593 | return FALSE; | 597 | return FALSE; |
594 | } | 598 | } |
595 | } | 599 | } |
596 | return TRUE; | 600 | return TRUE; |
597 | } | 601 | } |
598 | } else { | 602 | } else { |
599 | return mediaPlayerState->looping(); | 603 | return mediaPlayerState->looping(); |
600 | } | 604 | } |
601 | } | 605 | } |
602 | 606 | ||
603 | 607 | ||
604 | bool PlayListWidget::first() { | 608 | bool PlayListWidget::first() { |
605 | if ( mediaPlayerState->playlist() ) | 609 | if ( mediaPlayerState->playlist() ) |
606 | return d->selectedFiles->first(); | 610 | return d->selectedFiles->first(); |
607 | else | 611 | else |
608 | return mediaPlayerState->looping(); | 612 | return mediaPlayerState->looping(); |
609 | } | 613 | } |
610 | 614 | ||
611 | 615 | ||
612 | bool PlayListWidget::last() { | 616 | bool PlayListWidget::last() { |
613 | if ( mediaPlayerState->playlist() ) | 617 | if ( mediaPlayerState->playlist() ) |
614 | return d->selectedFiles->last(); | 618 | return d->selectedFiles->last(); |
615 | else | 619 | else |
616 | return mediaPlayerState->looping(); | 620 | return mediaPlayerState->looping(); |
617 | } | 621 | } |
618 | 622 | ||
619 | 623 | ||
620 | void PlayListWidget::saveList() { | 624 | void PlayListWidget::saveList() { |
621 | 625 | ||
622 | QString filename; | 626 | QString filename; |
623 | InputDialog *fileDlg; | 627 | InputDialog *fileDlg; |
624 | fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0); | 628 | fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0); |
625 | fileDlg->exec(); | 629 | fileDlg->exec(); |
626 | if( fileDlg->result() == 1 ) { | 630 | if( fileDlg->result() == 1 ) { |
627 | if ( d->current ) | 631 | if ( d->current ) |
628 | delete d->current; | 632 | delete d->current; |
629 | filename = fileDlg->LineEdit1->text();//+".playlist"; | 633 | filename = fileDlg->LineEdit1->text();//+".playlist"; |
630 | // qDebug("saving playlist "+filename+".playlist"); | 634 | // qDebug("saving playlist "+filename+".playlist"); |
631 | Config cfg( filename +".playlist"); | 635 | Config cfg( filename +".playlist"); |
632 | writeConfig( cfg ); | 636 | writeConfig( cfg ); |
633 | 637 | ||
634 | DocLnk lnk; | 638 | DocLnk lnk; |
635 | // lnk.setComment( ""); | 639 | // lnk.setComment( ""); |
636 | lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property | 640 | lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property |
637 | lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D | 641 | lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D |
638 | lnk.setIcon("opieplayer/playlist2"); | 642 | lnk.setIcon("opieplayer/playlist2"); |
639 | lnk.setName( filename); //sets file name | 643 | lnk.setName( filename); //sets file name |
640 | // qDebug(filename); | 644 | // qDebug(filename); |
641 | if(!lnk.writeLink()) | 645 | if(!lnk.writeLink()) |
642 | qDebug("Writing doclink did not work"); | 646 | qDebug("Writing doclink did not work"); |
643 | } | 647 | } |
644 | Config config( "OpiePlayer" ); | 648 | Config config( "OpiePlayer" ); |
645 | config.writeEntry("CurrentPlaylist",filename); | 649 | config.writeEntry("CurrentPlaylist",filename); |
646 | setCaption(tr("OpiePlayer: ")+filename); | 650 | setCaption(tr("OpiePlayer: ")+filename); |
647 | d->selectedFiles->first(); | 651 | d->selectedFiles->first(); |
648 | if(fileDlg) | 652 | if(fileDlg) |
649 | delete fileDlg; | 653 | delete fileDlg; |
650 | } | 654 | } |
651 | 655 | ||
652 | void PlayListWidget::loadList( const DocLnk & lnk) { | 656 | void PlayListWidget::loadList( const DocLnk & lnk) { |
653 | QString name= lnk.name(); | 657 | QString name= lnk.name(); |
654 | // qDebug("currentList is "+name); | 658 | // qDebug("currentList is "+name); |
655 | if( name.length()>1) { | 659 | if( name.length()>1) { |
656 | setCaption("OpiePlayer: "+name); | 660 | setCaption("OpiePlayer: "+name); |
657 | // qDebug("load list "+ name+".playlist"); | 661 | // qDebug("load list "+ name+".playlist"); |
658 | clearList(); | 662 | clearList(); |
659 | Config cfg( name+".playlist"); | 663 | Config cfg( name+".playlist"); |
660 | readConfig(cfg); | 664 | readConfig(cfg); |
661 | 665 | ||
662 | tabWidget->setCurrentPage(0); | 666 | tabWidget->setCurrentPage(0); |
663 | 667 | ||
664 | Config config( "OpiePlayer" ); | 668 | Config config( "OpiePlayer" ); |
665 | config.writeEntry("CurrentPlaylist", name); | 669 | config.writeEntry("CurrentPlaylist", name); |
666 | // d->selectedFiles->first(); | 670 | // d->selectedFiles->first(); |
667 | } | 671 | } |
668 | 672 | ||
669 | } | 673 | } |
670 | 674 | ||
671 | void PlayListWidget::setPlaylist( bool shown ) { | 675 | void PlayListWidget::setPlaylist( bool shown ) { |
672 | if ( shown ) | 676 | if ( shown ) |
673 | d->playListFrame->show(); | 677 | d->playListFrame->show(); |
674 | else | 678 | else |
675 | d->playListFrame->hide(); | 679 | d->playListFrame->hide(); |
676 | } | 680 | } |
677 | 681 | ||
678 | void PlayListWidget::setView( char view ) { | 682 | void PlayListWidget::setView( char view ) { |
679 | if ( view == 'l' ) | 683 | if ( view == 'l' ) |
680 | showMaximized(); | 684 | showMaximized(); |
681 | else | 685 | else |
682 | hide(); | 686 | hide(); |
683 | } | 687 | } |
684 | 688 | ||
685 | void PlayListWidget::addSelected() { | 689 | void PlayListWidget::addSelected() { |
686 | 690 | ||
687 | Config cfg( "OpiePlayer" ); | 691 | Config cfg( "OpiePlayer" ); |
688 | cfg.setGroup("PlayList"); | 692 | cfg.setGroup("PlayList"); |
689 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | 693 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); |
690 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 694 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
691 | 695 | ||
692 | switch (tabWidget->currentPageIndex()) { | 696 | switch (tabWidget->currentPageIndex()) { |
693 | case 0: //playlist | 697 | case 0: //playlist |
694 | break; | 698 | break; |
695 | case 1: { //audio | 699 | case 1: { //audio |
696 | // QString entryName; | 700 | // QString entryName; |
697 | // entryName.sprintf( "File%i", i + 1 ); | 701 | // entryName.sprintf( "File%i", i + 1 ); |
698 | // QString linkFile = cfg.readEntry( entryName ); | 702 | // QString linkFile = cfg.readEntry( entryName ); |
699 | QListViewItemIterator it( audioView ); | 703 | QListViewItemIterator it( audioView ); |
700 | // iterate through all items of the listview | 704 | // iterate through all items of the listview |
701 | for ( ; it.current(); ++it ) { | 705 | for ( ; it.current(); ++it ) { |
702 | if ( it.current()->isSelected() ) { | 706 | if ( it.current()->isSelected() ) { |
703 | QListIterator<DocLnk> dit( files.children() ); | 707 | QListIterator<DocLnk> dit( files.children() ); |
704 | for ( ; dit.current(); ++dit ) { | 708 | for ( ; dit.current(); ++dit ) { |
705 | if( dit.current()->name() == it.current()->text(0) ) { | 709 | if( dit.current()->name() == it.current()->text(0) ) { |
706 | d->selectedFiles->addToSelection( **dit ); | 710 | d->selectedFiles->addToSelection( **dit ); |
707 | } | 711 | } |
708 | } | 712 | } |
709 | audioView->setSelected( it.current(),FALSE); | 713 | audioView->setSelected( it.current(),FALSE); |
710 | } | 714 | } |
711 | } | 715 | } |
712 | tabWidget->setCurrentPage(0); | 716 | tabWidget->setCurrentPage(0); |
713 | } | 717 | } |
714 | break; | 718 | break; |
715 | case 2: { // video | 719 | case 2: { // video |
716 | QListViewItemIterator it( videoView ); | 720 | QListViewItemIterator it( videoView ); |
717 | // iterate through all items of the listview | 721 | // iterate through all items of the listview |
718 | for ( ; it.current(); ++it ) { | 722 | for ( ; it.current(); ++it ) { |
719 | if ( it.current()->isSelected() ) { | 723 | if ( it.current()->isSelected() ) { |
720 | QListIterator<DocLnk> dit( vFiles.children() ); | 724 | QListIterator<DocLnk> dit( vFiles.children() ); |
721 | for ( ; dit.current(); ++dit ) { | 725 | for ( ; dit.current(); ++dit ) { |
722 | if( dit.current()->name() == it.current()->text(0) ) { | 726 | if( dit.current()->name() == it.current()->text(0) ) { |
723 | d->selectedFiles->addToSelection( **dit ); | 727 | d->selectedFiles->addToSelection( **dit ); |
724 | } | 728 | } |
725 | } | 729 | } |
726 | 730 | ||
727 | videoView->setSelected( it.current(),FALSE); | 731 | videoView->setSelected( it.current(),FALSE); |
728 | } | 732 | } |
729 | } | 733 | } |
730 | // for ( int i = 0; i < noOfFiles; i++ ) { | 734 | // for ( int i = 0; i < noOfFiles; i++ ) { |
731 | // QString entryName; | 735 | // QString entryName; |
732 | // entryName.sprintf( "File%i", i + 1 ); | 736 | // entryName.sprintf( "File%i", i + 1 ); |
733 | // QString linkFile = cfg.readEntry( entryName ); | 737 | // QString linkFile = cfg.readEntry( entryName ); |
734 | // if( DocLnk( linkFile).name() == videoView->selectedItem()->text(0) ) { | 738 | // if( DocLnk( linkFile).name() == videoView->selectedItem()->text(0) ) { |
735 | // int result= QMessageBox::warning(this,tr("OpiePlayer"), | 739 | // int result= QMessageBox::warning(this,tr("OpiePlayer"), |
736 | // tr("This is all ready in your playlist.\nContinue?"), | 740 | // tr("This is all ready in your playlist.\nContinue?"), |
737 | // tr("Yes"),tr("No"),0,0,1); | 741 | // tr("Yes"),tr("No"),0,0,1); |
738 | // if (result !=0) | 742 | // if (result !=0) |
739 | // return; | 743 | // return; |
740 | // } | 744 | // } |
741 | // } | 745 | // } |
742 | // addToSelection( videoView->selectedItem() ); | 746 | // addToSelection( videoView->selectedItem() ); |
743 | tabWidget->setCurrentPage(0); | 747 | tabWidget->setCurrentPage(0); |
744 | } | 748 | } |
745 | break; | 749 | break; |
746 | }; | 750 | }; |
747 | } | 751 | } |
748 | 752 | ||
749 | void PlayListWidget::removeSelected() { | 753 | void PlayListWidget::removeSelected() { |
750 | d->selectedFiles->removeSelected( ); | 754 | d->selectedFiles->removeSelected( ); |
751 | } | 755 | } |
752 | 756 | ||
753 | void PlayListWidget::playIt( QListViewItem *it) { | 757 | void PlayListWidget::playIt( QListViewItem *it) { |
754 | // d->setDocumentUsed = FALSE; | 758 | // d->setDocumentUsed = FALSE; |
755 | mediaPlayerState->setPlaying(FALSE); | 759 | // mediaPlayerState->curPosition =0; |
760 | qDebug("playIt"); | ||
761 | mediaPlayerState->setPlaying(FALSE); | ||
756 | mediaPlayerState->setPlaying(TRUE); | 762 | mediaPlayerState->setPlaying(TRUE); |
757 | d->selectedFiles->unSelect(); | 763 | d->selectedFiles->unSelect(); |
758 | } | 764 | } |
759 | 765 | ||
760 | void PlayListWidget::addToSelection( QListViewItem *it) { | 766 | void PlayListWidget::addToSelection( QListViewItem *it) { |
761 | d->setDocumentUsed = FALSE; | 767 | d->setDocumentUsed = FALSE; |
762 | 768 | ||
763 | if(it) { | 769 | if(it) { |
764 | switch (tabWidget->currentPageIndex()) { | 770 | switch (tabWidget->currentPageIndex()) { |
765 | case 1: { | 771 | case 1: { |
766 | QListIterator<DocLnk> dit( files.children() ); | 772 | QListIterator<DocLnk> dit( files.children() ); |
767 | for ( ; dit.current(); ++dit ) { | 773 | for ( ; dit.current(); ++dit ) { |
768 | if( dit.current()->name() == it->text(0)) { | 774 | if( dit.current()->name() == it->text(0)) { |
769 | d->selectedFiles->addToSelection( **dit ); | 775 | d->selectedFiles->addToSelection( **dit ); |
770 | } | 776 | } |
771 | } | 777 | } |
772 | } | 778 | } |
773 | break; | 779 | break; |
774 | case 2: { | 780 | case 2: { |
775 | QListIterator<DocLnk> dit( vFiles.children() ); | 781 | QListIterator<DocLnk> dit( vFiles.children() ); |
776 | for ( ; dit.current(); ++dit ) { | 782 | for ( ; dit.current(); ++dit ) { |
777 | if( dit.current()->name() == it->text(0)) { | 783 | if( dit.current()->name() == it->text(0)) { |
778 | d->selectedFiles->addToSelection( **dit ); | 784 | d->selectedFiles->addToSelection( **dit ); |
779 | } | 785 | } |
780 | } | 786 | } |
781 | } | 787 | } |
782 | break; | 788 | break; |
783 | case 0: | 789 | case 0: |
784 | break; | 790 | break; |
785 | }; | 791 | }; |
786 | tabWidget->setCurrentPage(0); | 792 | tabWidget->setCurrentPage(0); |
787 | } | 793 | } |
788 | } | 794 | } |
789 | 795 | ||
790 | void PlayListWidget::tabChanged(QWidget *widg) { | 796 | void PlayListWidget::tabChanged(QWidget *widg) { |
791 | 797 | ||
792 | switch ( tabWidget->currentPageIndex()) { | 798 | switch ( tabWidget->currentPageIndex()) { |
793 | case 0: | 799 | case 0: |
794 | { | 800 | { |
795 | if( !tbDeletePlaylist->isHidden()) | 801 | if( !tbDeletePlaylist->isHidden()) |
796 | tbDeletePlaylist->hide(); | 802 | tbDeletePlaylist->hide(); |
797 | d->tbRemoveFromList->setEnabled(TRUE); | 803 | d->tbRemoveFromList->setEnabled(TRUE); |
798 | d->tbAddToList->setEnabled(FALSE); | 804 | d->tbAddToList->setEnabled(FALSE); |
799 | } | 805 | } |
800 | break; | 806 | break; |
801 | case 1: | 807 | case 1: |
802 | { | 808 | { |
803 | audioView->clear(); | 809 | audioView->clear(); |
804 | populateAudioView(); | 810 | populateAudioView(); |
805 | 811 | ||
806 | if( !tbDeletePlaylist->isHidden()) | 812 | if( !tbDeletePlaylist->isHidden()) |
807 | tbDeletePlaylist->hide(); | 813 | tbDeletePlaylist->hide(); |
808 | d->tbRemoveFromList->setEnabled(FALSE); | 814 | d->tbRemoveFromList->setEnabled(FALSE); |
809 | d->tbAddToList->setEnabled(TRUE); | 815 | d->tbAddToList->setEnabled(TRUE); |
810 | } | 816 | } |
811 | break; | 817 | break; |
812 | case 2: | 818 | case 2: |
813 | { | 819 | { |
814 | videoView->clear(); | 820 | videoView->clear(); |
815 | populateVideoView(); | 821 | populateVideoView(); |
816 | if( !tbDeletePlaylist->isHidden()) | 822 | if( !tbDeletePlaylist->isHidden()) |
817 | tbDeletePlaylist->hide(); | 823 | tbDeletePlaylist->hide(); |
818 | d->tbRemoveFromList->setEnabled(FALSE); | 824 | d->tbRemoveFromList->setEnabled(FALSE); |
819 | d->tbAddToList->setEnabled(TRUE); | 825 | d->tbAddToList->setEnabled(TRUE); |
820 | } | 826 | } |
821 | break; | 827 | break; |
822 | case 3: | 828 | case 3: |
823 | { | 829 | { |
824 | if( tbDeletePlaylist->isHidden()) | 830 | if( tbDeletePlaylist->isHidden()) |
825 | tbDeletePlaylist->show(); | 831 | tbDeletePlaylist->show(); |
826 | playLists->reread(); | 832 | playLists->reread(); |
827 | } | 833 | } |
828 | break; | 834 | break; |
829 | }; | 835 | }; |
830 | } | 836 | } |
831 | 837 | ||
832 | void PlayListWidget::btnPlay(bool b) { | 838 | void PlayListWidget::btnPlay(bool b) { |
833 | 839 | ||
834 | // mediaPlayerState->setPlaying(b); | 840 | // mediaPlayerState->setPlaying(b); |
835 | switch ( tabWidget->currentPageIndex()) { | 841 | switch ( tabWidget->currentPageIndex()) { |
836 | case 0: | 842 | case 0: |
837 | { | 843 | { |
844 | |||
838 | mediaPlayerState->setPlaying(b); | 845 | mediaPlayerState->setPlaying(b); |
839 | } | 846 | } |
840 | break; | 847 | break; |
841 | case 1: | 848 | case 1: |
842 | { | 849 | { |
843 | addToSelection( audioView->currentItem() ); | 850 | addToSelection( audioView->currentItem() ); |
844 | mediaPlayerState->setPlaying(b); | 851 | mediaPlayerState->setPlaying(b); |
845 | d->selectedFiles->removeSelected( ); | 852 | d->selectedFiles->removeSelected( ); |
846 | tabWidget->setCurrentPage(1); | 853 | tabWidget->setCurrentPage(1); |
847 | d->selectedFiles->unSelect(); | 854 | d->selectedFiles->unSelect(); |
848 | insanityBool=FALSE; | 855 | insanityBool=FALSE; |
849 | // audioView->clearSelection(); | 856 | // audioView->clearSelection(); |
850 | } | 857 | } |
851 | break; | 858 | break; |
852 | case 2: | 859 | case 2: |
853 | { | 860 | { |
854 | addToSelection( videoView->currentItem() ); | 861 | addToSelection( videoView->currentItem() ); |
855 | mediaPlayerState->setPlaying(b); | 862 | mediaPlayerState->setPlaying(b); |
856 | qApp->processEvents(); | 863 | qApp->processEvents(); |
857 | d->selectedFiles->removeSelected( ); | 864 | d->selectedFiles->removeSelected( ); |
858 | tabWidget->setCurrentPage(2); | 865 | tabWidget->setCurrentPage(2); |
859 | d->selectedFiles->unSelect(); | 866 | d->selectedFiles->unSelect(); |
860 | insanityBool=FALSE; | 867 | insanityBool=FALSE; |
861 | // videoView->clearSelection(); | 868 | // videoView->clearSelection(); |
862 | } | 869 | } |
863 | break; | 870 | break; |
864 | }; | 871 | }; |
865 | } | 872 | } |
866 | 873 | ||
867 | void PlayListWidget::deletePlaylist() { | 874 | void PlayListWidget::deletePlaylist() { |
868 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), | 875 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), |
869 | (tr("You really want to delete\nthis playlist?")), | 876 | (tr("You really want to delete\nthis playlist?")), |
870 | (tr("Yes")), (tr("No")), 0 )){ | 877 | (tr("Yes")), (tr("No")), 0 )){ |
871 | case 0: // Yes clicked, | 878 | case 0: // Yes clicked, |
872 | QFile().remove(playLists->selected()->file()); | 879 | QFile().remove(playLists->selected()->file()); |
873 | QFile().remove(playLists->selected()->linkFile()); | 880 | QFile().remove(playLists->selected()->linkFile()); |
874 | playLists->reread(); | 881 | playLists->reread(); |
875 | break; | 882 | break; |
876 | case 1: // Cancel | 883 | case 1: // Cancel |
877 | break; | 884 | break; |
878 | }; | 885 | }; |
879 | } | 886 | } |
880 | 887 | ||
881 | void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) | 888 | void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) |
882 | { | 889 | { |
883 | switch (mouse) { | 890 | switch (mouse) { |
884 | case 1: | 891 | case 1: |
885 | break; | 892 | break; |
886 | case 2:{ | 893 | case 2:{ |
887 | 894 | ||
888 | QPopupMenu m; | 895 | QPopupMenu m; |
889 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); | 896 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); |
890 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); | 897 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); |
891 | m.insertSeparator(); | 898 | m.insertSeparator(); |
892 | if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) | 899 | if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) |
893 | m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); | 900 | m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); |
894 | 901 | ||
895 | m.exec( QCursor::pos() ); | 902 | m.exec( QCursor::pos() ); |
896 | } | 903 | } |
897 | break; | 904 | break; |
898 | }; | 905 | }; |
899 | } | 906 | } |
900 | 907 | ||
901 | void PlayListWidget::playSelected() | 908 | void PlayListWidget::playSelected() |
902 | { | 909 | { |
903 | btnPlay( TRUE); | 910 | btnPlay( TRUE); |
904 | // d->selectedFiles->unSelect(); | 911 | // d->selectedFiles->unSelect(); |
905 | } | 912 | } |
906 | 913 | ||
907 | void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) | 914 | void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) |
908 | { | 915 | { |
909 | switch (mouse) { | 916 | switch (mouse) { |
910 | case 1: | 917 | case 1: |
911 | 918 | ||
912 | break; | 919 | break; |
913 | case 2:{ | 920 | case 2:{ |
914 | QPopupMenu m; | 921 | QPopupMenu m; |
915 | m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); | 922 | m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); |
916 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); | 923 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); |
917 | // m.insertSeparator(); | 924 | // m.insertSeparator(); |
918 | // m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); | 925 | // m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); |
919 | m.exec( QCursor::pos() ); | 926 | m.exec( QCursor::pos() ); |
920 | } | 927 | } |
921 | break; | 928 | break; |
922 | }; | 929 | }; |
923 | 930 | ||
924 | } | 931 | } |
925 | 932 | ||
926 | void PlayListWidget::listDelete() { | 933 | void PlayListWidget::listDelete() { |
927 | Config cfg( "OpiePlayer" ); | 934 | Config cfg( "OpiePlayer" ); |
928 | cfg.setGroup("PlayList"); | 935 | cfg.setGroup("PlayList"); |
929 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | 936 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); |
930 | QString file; | 937 | QString file; |
931 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 938 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
932 | switch ( tabWidget->currentPageIndex()) { | 939 | switch ( tabWidget->currentPageIndex()) { |
933 | case 0: | 940 | case 0: |
934 | break; | 941 | break; |
935 | case 1: | 942 | case 1: |
936 | { | 943 | { |
937 | file = audioView->selectedItem()->text(0); | 944 | file = audioView->selectedItem()->text(0); |
938 | // Global::findDocuments(&files, "audio/*"); | 945 | // Global::findDocuments(&files, "audio/*"); |
939 | // AppLnkSet appFiles; | 946 | // AppLnkSet appFiles; |
940 | QListIterator<DocLnk> dit( files.children() ); | 947 | QListIterator<DocLnk> dit( files.children() ); |
941 | for ( ; dit.current(); ++dit ) { | 948 | for ( ; dit.current(); ++dit ) { |
942 | if( dit.current()->name() == file) { | 949 | if( dit.current()->name() == file) { |
943 | // qDebug(file); | 950 | // qDebug(file); |
944 | LnkProperties prop( dit.current() ); | 951 | LnkProperties prop( dit.current() ); |
945 | // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); | 952 | // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); |
946 | prop.showMaximized(); | 953 | prop.showMaximized(); |
947 | prop.exec(); | 954 | prop.exec(); |
948 | } | 955 | } |
949 | } | 956 | } |
950 | populateAudioView(); | 957 | populateAudioView(); |
951 | } | 958 | } |
952 | break; | 959 | break; |
953 | case 2: | 960 | case 2: |
954 | { | 961 | { |
955 | // file = videoView->selectedItem()->text(0); | 962 | // file = videoView->selectedItem()->text(0); |
956 | // for ( int i = 0; i < noOfFiles; i++ ) { | 963 | // for ( int i = 0; i < noOfFiles; i++ ) { |
957 | // QString entryName; | 964 | // QString entryName; |
958 | // entryName.sprintf( "File%i", i + 1 ); | 965 | // entryName.sprintf( "File%i", i + 1 ); |
959 | // QString linkFile = cfg.readEntry( entryName ); | 966 | // QString linkFile = cfg.readEntry( entryName ); |
960 | // AppLnk lnk( AppLnk(linkFile)); | 967 | // AppLnk lnk( AppLnk(linkFile)); |
961 | // if( lnk.name() == file ) { | 968 | // if( lnk.name() == file ) { |
962 | // LnkProperties prop( &lnk); | 969 | // LnkProperties prop( &lnk); |
963 | // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); | 970 | // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); |
964 | // prop.showMaximized(); | 971 | // prop.showMaximized(); |
965 | // prop.exec(); | 972 | // prop.exec(); |
966 | // } | 973 | // } |
967 | // } | 974 | // } |
968 | } | 975 | } |
969 | break; | 976 | break; |
970 | }; | 977 | }; |
971 | } | 978 | } |
972 | 979 | ||
973 | void PlayListWidget::scanForAudio() { | 980 | void PlayListWidget::scanForAudio() { |
974 | qDebug("scan for audio"); | 981 | qDebug("scan for audio"); |
975 | files.detachChildren(); | 982 | files.detachChildren(); |
976 | QListIterator<DocLnk> sdit( files.children() ); | 983 | QListIterator<DocLnk> sdit( files.children() ); |
977 | for ( ; sdit.current(); ++sdit ) { | 984 | for ( ; sdit.current(); ++sdit ) { |
978 | delete sdit.current(); | 985 | delete sdit.current(); |
979 | } | 986 | } |
980 | Global::findDocuments(&files, "audio/*"); | 987 | Global::findDocuments(&files, "audio/*"); |
981 | audioScan = TRUE; | 988 | audioScan = TRUE; |
982 | } | 989 | } |
983 | void PlayListWidget::scanForVideo() { | 990 | void PlayListWidget::scanForVideo() { |
984 | qDebug("scan for video"); | 991 | qDebug("scan for video"); |
985 | vFiles.detachChildren(); | 992 | vFiles.detachChildren(); |
986 | QListIterator<DocLnk> sdit( vFiles.children() ); | 993 | QListIterator<DocLnk> sdit( vFiles.children() ); |
987 | for ( ; sdit.current(); ++sdit ) { | 994 | for ( ; sdit.current(); ++sdit ) { |
988 | delete sdit.current(); | 995 | delete sdit.current(); |
989 | } | 996 | } |
990 | Global::findDocuments(&vFiles, "video/*"); | 997 | Global::findDocuments(&vFiles, "video/*"); |
991 | videoScan = TRUE; | 998 | videoScan = TRUE; |
992 | } | 999 | } |
993 | 1000 | ||
994 | void PlayListWidget::populateAudioView() { | 1001 | void PlayListWidget::populateAudioView() { |
995 | 1002 | ||
996 | audioView->clear(); | 1003 | audioView->clear(); |
997 | StorageInfo storageInfo; | 1004 | StorageInfo storageInfo; |
998 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1005 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
999 | if(!audioScan) scanForAudio(); | 1006 | if(!audioScan) scanForAudio(); |
1000 | 1007 | ||
1001 | QListIterator<DocLnk> dit( files.children() ); | 1008 | QListIterator<DocLnk> dit( files.children() ); |
1002 | QListIterator<FileSystem> it ( fs ); | 1009 | QListIterator<FileSystem> it ( fs ); |
1003 | 1010 | ||
1004 | QString storage; | 1011 | QString storage; |
1005 | for ( ; dit.current(); ++dit ) { | 1012 | for ( ; dit.current(); ++dit ) { |
1006 | for( ; it.current(); ++it ){ | 1013 | for( ; it.current(); ++it ){ |
1007 | const QString name = (*it)->name(); | 1014 | const QString name = (*it)->name(); |
1008 | const QString path = (*it)->path(); | 1015 | const QString path = (*it)->path(); |
1009 | if(dit.current()->file().find(path) != -1 ) storage=name; | 1016 | if(dit.current()->file().find(path) != -1 ) storage=name; |
1010 | } | 1017 | } |
1011 | 1018 | ||
1012 | QListViewItem * newItem; | 1019 | QListViewItem * newItem; |
1013 | if ( QFile( dit.current()->file()).exists() ) { | 1020 | if ( QFile( dit.current()->file()).exists() ) { |
1014 | // qDebug(dit.current()->name()); | 1021 | // qDebug(dit.current()->name()); |
1015 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), | 1022 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), |
1016 | QString::number( QFile( dit.current()->file()).size() ), storage); | 1023 | QString::number( QFile( dit.current()->file()).size() ), storage); |
1017 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); | 1024 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); |
1018 | } | 1025 | } |
1019 | } | 1026 | } |
1020 | 1027 | ||
1021 | } | 1028 | } |
1022 | 1029 | ||
1023 | void PlayListWidget::populateVideoView() { | 1030 | void PlayListWidget::populateVideoView() { |
1024 | videoView->clear(); | 1031 | videoView->clear(); |
1025 | StorageInfo storageInfo; | 1032 | StorageInfo storageInfo; |
1026 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1033 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
1027 | 1034 | ||
1028 | if(!videoScan ) scanForVideo(); | 1035 | if(!videoScan ) scanForVideo(); |
1029 | 1036 | ||