author | llornkcor <llornkcor> | 2002-06-22 01:38:20 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-06-22 01:38:20 (UTC) |
commit | 9adc4e5ab0a07eda196fffc8921da2d2d4f273e7 (patch) (unidiff) | |
tree | 91500597f01f145b5ec5a6ff80e812c59f95317f | |
parent | 28f2e6b92c40125172c9716790dc98cc30abc7fc (diff) | |
download | opie-9adc4e5ab0a07eda196fffc8921da2d2d4f273e7.zip opie-9adc4e5ab0a07eda196fffc8921da2d2d4f273e7.tar.gz opie-9adc4e5ab0a07eda196fffc8921da2d2d4f273e7.tar.bz2 |
new action if /dev/dsp can't open, instead of sending to bytes to /dev/null.. lets immediately exit
-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 15 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 10 |
2 files changed, 18 insertions, 7 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp index faadd72..8f04d0d 100644 --- a/core/multimedia/opieplayer/audiodevice.cpp +++ b/core/multimedia/opieplayer/audiodevice.cpp | |||
@@ -1,92 +1,97 @@ | |||
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 <qmessagebox.h> | ||
28 | |||
27 | #include "audiodevice.h" | 29 | #include "audiodevice.h" |
28 | 30 | ||
31 | |||
32 | #include <errno.h> | ||
33 | |||
29 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 34 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
30 | #include "qpe/qcopenvelope_qws.h" | 35 | #include "qpe/qcopenvelope_qws.h" |
31 | #endif | 36 | #endif |
32 | 37 | ||
33 | // #ifdef Q_WS_WIN | 38 | // #ifdef Q_WS_WIN |
34 | // #include <windows.h> | 39 | // #include <windows.h> |
35 | // #include <mmsystem.h> | 40 | // #include <mmsystem.h> |
36 | // #include <mmreg.h> | 41 | // #include <mmreg.h> |
37 | // #endif | 42 | // #endif |
38 | #if defined(Q_WS_X11) || defined(Q_WS_QWS) | 43 | #if defined(Q_WS_X11) || defined(Q_WS_QWS) |
39 | #include <fcntl.h> | 44 | #include <fcntl.h> |
40 | #include <sys/ioctl.h> | 45 | #include <sys/ioctl.h> |
41 | #include <sys/soundcard.h> | 46 | #include <sys/soundcard.h> |
42 | #include <sys/stat.h> | 47 | #include <sys/stat.h> |
43 | #include <sys/time.h> | 48 | #include <sys/time.h> |
44 | #include <sys/types.h> | 49 | #include <sys/types.h> |
45 | #include <unistd.h> | 50 | #include <unistd.h> |
46 | #endif | 51 | #endif |
47 | 52 | ||
48 | // #if defined(Q_OS_WIN32) | 53 | // #if defined(Q_OS_WIN32) |
49 | // static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000; | 54 | // static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000; |
50 | // static const int timerResolutionMilliSeconds = 30; | 55 | // static const int timerResolutionMilliSeconds = 30; |
51 | // static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond; | 56 | // static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond; |
52 | // #else | 57 | // #else |
53 | # if defined(QT_QWS_IPAQ) | 58 | # if defined(QT_QWS_IPAQ) |
54 | static const int sound_fragment_shift = 14; | 59 | static const int sound_fragment_shift = 14; |
55 | # else | 60 | # else |
56 | static const int sound_fragment_shift = 16; | 61 | static const int sound_fragment_shift = 16; |
57 | # endif | 62 | # endif |
58 | static const int sound_fragment_bytes = (1<<sound_fragment_shift); | 63 | static const int sound_fragment_bytes = (1<<sound_fragment_shift); |
59 | //#endif | 64 | //#endif |
60 | 65 | ||
61 | 66 | ||
62 | class AudioDevicePrivate { | 67 | class AudioDevicePrivate { |
63 | public: | 68 | public: |
64 | int handle; | 69 | int handle; |
65 | unsigned int frequency; | 70 | unsigned int frequency; |
66 | unsigned int channels; | 71 | unsigned int channels; |
67 | unsigned int bytesPerSample; | 72 | unsigned int bytesPerSample; |
68 | unsigned int bufferSize; | 73 | unsigned int bufferSize; |
69 | //#ifndef Q_OS_WIN32 | 74 | //#ifndef Q_OS_WIN32 |
70 | bool can_GETOSPACE; | 75 | bool can_GETOSPACE; |
71 | char* unwrittenBuffer; | 76 | char* unwrittenBuffer; |
72 | unsigned int unwritten; | 77 | unsigned int unwritten; |
73 | //#endif | 78 | //#endif |
74 | 79 | ||
75 | static int dspFd; | 80 | static int dspFd; |
76 | static bool muted; | 81 | static bool muted; |
77 | static unsigned int leftVolume; | 82 | static unsigned int leftVolume; |
78 | static unsigned int rightVolume; | 83 | static unsigned int rightVolume; |
79 | }; | 84 | }; |
80 | 85 | ||
81 | 86 | ||
82 | #ifdef Q_WS_QWS | 87 | #ifdef Q_WS_QWS |
83 | // This is for keeping the device open in-between playing files when | 88 | // This is for keeping the device open in-between playing files when |
84 | // the device makes clicks and it starts to drive you insane! :) | 89 | // the device makes clicks and it starts to drive you insane! :) |
85 | // Best to have the device not open when not using it though | 90 | // Best to have the device not open when not using it though |
86 | //#define KEEP_DEVICE_OPEN | 91 | //#define KEEP_DEVICE_OPEN |
87 | #endif | 92 | #endif |
88 | 93 | ||
89 | 94 | ||
90 | int AudioDevicePrivate::dspFd = 0; | 95 | int AudioDevicePrivate::dspFd = 0; |
91 | bool AudioDevicePrivate::muted = FALSE; | 96 | bool AudioDevicePrivate::muted = FALSE; |
92 | unsigned int AudioDevicePrivate::leftVolume = 0; | 97 | unsigned int AudioDevicePrivate::leftVolume = 0; |
@@ -148,130 +153,136 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, | |||
148 | // formatData.nSamplesPerSec = 44000; | 153 | // formatData.nSamplesPerSec = 44000; |
149 | // formatData.wBitsPerSample = 16; | 154 | // formatData.wBitsPerSample = 16; |
150 | // waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); | 155 | // waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); |
151 | // unsigned int volume = (rightVolume << 16) | leftVolume; | 156 | // unsigned int volume = (rightVolume << 16) | leftVolume; |
152 | // if ( waveOutSetVolume( handle, volume ) ) | 157 | // if ( waveOutSetVolume( handle, volume ) ) |
153 | // // qDebug( "set volume of audio device failed" ); | 158 | // // qDebug( "set volume of audio device failed" ); |
154 | // waveOutClose( handle ); | 159 | // waveOutClose( handle ); |
155 | // #else | 160 | // #else |
156 | // Volume can be from 0 to 100 which is 101 distinct values | 161 | // Volume can be from 0 to 100 which is 101 distinct values |
157 | unsigned int rV = (rightVolume * 101) >> 16; | 162 | unsigned int rV = (rightVolume * 101) >> 16; |
158 | 163 | ||
159 | # if 0 | 164 | # if 0 |
160 | unsigned int lV = (leftVolume * 101) >> 16; | 165 | unsigned int lV = (leftVolume * 101) >> 16; |
161 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); | 166 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); |
162 | int mixerHandle = 0; | 167 | int mixerHandle = 0; |
163 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 168 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
164 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) | 169 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) |
165 | perror("ioctl(\"MIXER_WRITE\")"); | 170 | perror("ioctl(\"MIXER_WRITE\")"); |
166 | close( mixerHandle ); | 171 | close( mixerHandle ); |
167 | } else | 172 | } else |
168 | perror("open(\"/dev/mixer\")"); | 173 | perror("open(\"/dev/mixer\")"); |
169 | 174 | ||
170 | # else | 175 | # else |
171 | // This is the way this has to be done now I guess, doesn't allow for | 176 | // This is the way this has to be done now I guess, doesn't allow for |
172 | // independant right and left channel setting, or setting for different outputs | 177 | // independant right and left channel setting, or setting for different outputs |
173 | Config cfg("qpe"); // qtopia is "Sound" | 178 | Config cfg("qpe"); // qtopia is "Sound" |
174 | cfg.setGroup("Volume"); // qtopia is "Settings" | 179 | cfg.setGroup("Volume"); // qtopia is "Settings" |
175 | cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume | 180 | cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume |
176 | # endif | 181 | # endif |
177 | 182 | ||
178 | //#endif | 183 | //#endif |
179 | // qDebug( "setting volume to: 0x%x", volume ); | 184 | // qDebug( "setting volume to: 0x%x", volume ); |
180 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 185 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
181 | // Send notification that the volume has changed | 186 | // Send notification that the volume has changed |
182 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; | 187 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; |
183 | #endif | 188 | #endif |
184 | } | 189 | } |
185 | 190 | ||
186 | 191 | ||
187 | 192 | ||
188 | 193 | ||
189 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | 194 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { |
190 | qDebug("creating new audio device"); | 195 | qDebug("creating new audio device"); |
191 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; | 196 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; |
192 | d = new AudioDevicePrivate; | 197 | d = new AudioDevicePrivate; |
193 | d->frequency = f; | 198 | d->frequency = f; |
194 | d->channels = chs; | 199 | d->channels = chs; |
195 | d->bytesPerSample = bps; | 200 | d->bytesPerSample = bps; |
196 | qDebug("%d",bps); | 201 | qDebug("%d",bps); |
197 | int format=0; | 202 | int format=0; |
198 | if( bps == 8) format = AFMT_U8; | 203 | if( bps == 8) format = AFMT_U8; |
199 | else if( bps <= 0) format = AFMT_S16_LE; | 204 | else if( bps <= 0) format = AFMT_S16_LE; |
200 | else format = AFMT_S16_LE; | 205 | else format = AFMT_S16_LE; |
201 | qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); | 206 | qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); |
202 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); | 207 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); |
203 | 208 | ||
204 | int fragments = 0x10000 * 8 + sound_fragment_shift; | 209 | int fragments = 0x10000 * 8 + sound_fragment_shift; |
205 | int capabilities = 0; | 210 | int capabilities = 0; |
206 | 211 | ||
207 | 212 | ||
208 | #ifdef KEEP_DEVICE_OPEN | 213 | #ifdef KEEP_DEVICE_OPEN |
209 | if ( AudioDevicePrivate::dspFd == 0 ) { | 214 | if ( AudioDevicePrivate::dspFd == 0 ) { |
210 | #endif | 215 | #endif |
211 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { | 216 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { |
212 | perror("open(\"/dev/dsp\") sending to /dev/null instead"); | 217 | |
213 | d->handle = ::open( "/dev/null", O_WRONLY ); | 218 | // perror("open(\"/dev/dsp\") sending to /dev/null instead"); |
219 | perror("open(\"/dev/dsp\")"); | ||
220 | QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now."); | ||
221 | QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort")); | ||
222 | exit(-1); //harsh? | ||
223 | // d->handle = ::open( "/dev/null", O_WRONLY ); | ||
224 | // WTF?!?! | ||
214 | } | 225 | } |
215 | #ifdef KEEP_DEVICE_OPEN | 226 | #ifdef KEEP_DEVICE_OPEN |
216 | AudioDevicePrivate::dspFd = d->handle; | 227 | AudioDevicePrivate::dspFd = d->handle; |
217 | } else { | 228 | } else { |
218 | d->handle = AudioDevicePrivate::dspFd; | 229 | d->handle = AudioDevicePrivate::dspFd; |
219 | } | 230 | } |
220 | #endif | 231 | #endif |
221 | 232 | ||
222 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) | 233 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) |
223 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); | 234 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); |
224 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) | 235 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) |
225 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); | 236 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); |
226 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) | 237 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) |
227 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 238 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
228 | qDebug("freq %d", d->frequency); | 239 | qDebug("freq %d", d->frequency); |
229 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) | 240 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) |
230 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 241 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
231 | qDebug("channels %d",d->channels); | 242 | qDebug("channels %d",d->channels); |
232 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { | 243 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { |
233 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; | 244 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; |
234 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) | 245 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) |
235 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 246 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
236 | } | 247 | } |
237 | 248 | ||
238 | d->bufferSize = sound_fragment_bytes; | 249 | d->bufferSize = sound_fragment_bytes; |
239 | d->unwrittenBuffer = new char[d->bufferSize]; | 250 | d->unwrittenBuffer = new char[d->bufferSize]; |
240 | d->unwritten = 0; | 251 | d->unwritten = 0; |
241 | d->can_GETOSPACE = TRUE; // until we find otherwise | 252 | d->can_GETOSPACE = TRUE; // until we find otherwise |
242 | 253 | ||
243 | //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); | 254 | //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); |
244 | //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); | 255 | //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); |
245 | //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); | 256 | //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); |
246 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); | 257 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); |
247 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); | 258 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); |
248 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); | 259 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); |
249 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; | 260 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; |
250 | 261 | ||
251 | } | 262 | } |
252 | 263 | ||
253 | 264 | ||
254 | AudioDevice::~AudioDevice() { | 265 | AudioDevice::~AudioDevice() { |
255 | qDebug("destryo audiodevice"); | 266 | qDebug("destryo audiodevice"); |
256 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; | 267 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; |
257 | 268 | ||
258 | // #ifdef Q_OS_WIN32 | 269 | // #ifdef Q_OS_WIN32 |
259 | // waveOutClose( (HWAVEOUT)d->handle ); | 270 | // waveOutClose( (HWAVEOUT)d->handle ); |
260 | // #else | 271 | // #else |
261 | # ifndef KEEP_DEVICE_OPEN | 272 | # ifndef KEEP_DEVICE_OPEN |
262 | close( d->handle ); // Now it should be safe to shut the handle | 273 | close( d->handle ); // Now it should be safe to shut the handle |
263 | # endif | 274 | # endif |
264 | delete d->unwrittenBuffer; | 275 | delete d->unwrittenBuffer; |
265 | delete d; | 276 | delete d; |
266 | //#endif | 277 | //#endif |
267 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; | 278 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; |
268 | 279 | ||
269 | } | 280 | } |
270 | 281 | ||
271 | 282 | ||
272 | void AudioDevice::volumeChanged( bool muted ) | 283 | void AudioDevice::volumeChanged( bool muted ) |
273 | { | 284 | { |
274 | AudioDevicePrivate::muted = muted; | 285 | AudioDevicePrivate::muted = muted; |
275 | } | 286 | } |
276 | 287 | ||
277 | 288 | ||
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index ae25fe3..0332237 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp | |||
@@ -356,141 +356,141 @@ void PlayListWidget::initializeStates() { | |||
356 | // d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); | 356 | // d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); |
357 | // setPlaylist( mediaPlayerState->playlist() ); | 357 | // setPlaylist( mediaPlayerState->playlist() ); |
358 | setPlaylist( true); | 358 | setPlaylist( true); |
359 | // d->selectedFiles->first(); | 359 | // d->selectedFiles->first(); |
360 | 360 | ||
361 | } | 361 | } |
362 | 362 | ||
363 | 363 | ||
364 | void PlayListWidget::readConfig( Config& cfg ) { | 364 | void PlayListWidget::readConfig( Config& cfg ) { |
365 | cfg.setGroup("PlayList"); | 365 | cfg.setGroup("PlayList"); |
366 | QString currentString = cfg.readEntry("current", "" ); | 366 | QString currentString = cfg.readEntry("current", "" ); |
367 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 367 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
368 | for ( int i = 0; i < noOfFiles; i++ ) { | 368 | for ( int i = 0; i < noOfFiles; i++ ) { |
369 | QString entryName; | 369 | QString entryName; |
370 | entryName.sprintf( "File%i", i + 1 ); | 370 | entryName.sprintf( "File%i", i + 1 ); |
371 | QString linkFile = cfg.readEntry( entryName ); | 371 | QString linkFile = cfg.readEntry( entryName ); |
372 | DocLnk lnk( linkFile ); | 372 | DocLnk lnk( linkFile ); |
373 | if ( lnk.isValid() ) { | 373 | if ( lnk.isValid() ) { |
374 | d->selectedFiles->addToSelection( lnk ); | 374 | d->selectedFiles->addToSelection( lnk ); |
375 | } | 375 | } |
376 | } | 376 | } |
377 | d->selectedFiles->setSelectedItem( currentString); | 377 | d->selectedFiles->setSelectedItem( currentString); |
378 | // d->selectedFiles->setSelectedItem( (const QString &)currentString); | 378 | // d->selectedFiles->setSelectedItem( (const QString &)currentString); |
379 | } | 379 | } |
380 | 380 | ||
381 | 381 | ||
382 | void PlayListWidget::writeConfig( Config& cfg ) const { | 382 | void PlayListWidget::writeConfig( Config& cfg ) const { |
383 | 383 | ||
384 | d->selectedFiles->writeCurrent( cfg); | 384 | d->selectedFiles->writeCurrent( cfg); |
385 | cfg.setGroup("PlayList"); | 385 | cfg.setGroup("PlayList"); |
386 | int noOfFiles = 0; | 386 | int noOfFiles = 0; |
387 | d->selectedFiles->first(); | 387 | d->selectedFiles->first(); |
388 | do { | 388 | do { |
389 | const DocLnk *lnk = d->selectedFiles->current(); | 389 | const DocLnk *lnk = d->selectedFiles->current(); |
390 | if ( lnk ) { | 390 | if ( lnk ) { |
391 | QString entryName; | 391 | QString entryName; |
392 | entryName.sprintf( "File%i", noOfFiles + 1 ); | 392 | entryName.sprintf( "File%i", noOfFiles + 1 ); |
393 | // qDebug(entryName); | 393 | // qDebug(entryName); |
394 | cfg.writeEntry( entryName, lnk->linkFile() ); | 394 | cfg.writeEntry( entryName, lnk->linkFile() ); |
395 | // if this link does exist, add it so we have the file | 395 | // if this link does exist, add it so we have the file |
396 | // next time... | 396 | // next time... |
397 | if ( !QFile::exists( lnk->linkFile() ) ) { | 397 | if ( !QFile::exists( lnk->linkFile() ) ) { |
398 | // the way writing lnks doesn't really check for out | 398 | // the way writing lnks doesn't really check for out |
399 | // of disk space, but check it anyway. | 399 | // of disk space, but check it anyway. |
400 | if ( !lnk->writeLink() ) { | 400 | if ( !lnk->writeLink() ) { |
401 | QMessageBox::critical( 0, tr("Out of space"), | 401 | QMessageBox::critical( 0, tr("Out of space"), |
402 | tr( "There was a problem saving " | 402 | tr( "There was a problem saving " |
403 | "the playlist.\n" | 403 | "the playlist.\n" |
404 | "Your playlist " | 404 | "Your playlist " |
405 | "may be missing some entries\n" | 405 | "may be missing some entries\n" |
406 | "the next time you start it." ) | 406 | "the next time you start it." ) |
407 | ); | 407 | ); |
408 | } | 408 | } |
409 | } | 409 | } |
410 | noOfFiles++; | 410 | noOfFiles++; |
411 | } | 411 | } |
412 | } | 412 | } |
413 | while ( d->selectedFiles->next() ); | 413 | while ( d->selectedFiles->next() ); |
414 | cfg.writeEntry("NumberOfFiles", noOfFiles ); | 414 | cfg.writeEntry("NumberOfFiles", noOfFiles ); |
415 | } | 415 | } |
416 | 416 | ||
417 | 417 | ||
418 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { | 418 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { |
419 | // qDebug("add"); | 419 | // qDebug("add"); |
420 | if( lnk.file().find(" ",0,TRUE) != -1 || lnk.file().find("%20",0,TRUE) != -1) { | 420 | // if( lnk.file().find(" ",0,TRUE) != -1 || lnk.file().find("%20",0,TRUE) != -1) { |
421 | QMessageBox::message("Note","You are trying to play\na malformed url."); | 421 | // QMessageBox::message("Note","You are trying to play\na malformed url."); |
422 | 422 | ||
423 | } else { | 423 | // } else { |
424 | 424 | ||
425 | d->setDocumentUsed = FALSE; | 425 | d->setDocumentUsed = FALSE; |
426 | if ( mediaPlayerState->playlist() ) { | 426 | if ( mediaPlayerState->playlist() ) { |
427 | if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" ) | 427 | if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" ) |
428 | d->selectedFiles->addToSelection( lnk ); | 428 | d->selectedFiles->addToSelection( lnk ); |
429 | } | 429 | } |
430 | else | 430 | else |
431 | mediaPlayerState->setPlaying( TRUE ); | 431 | mediaPlayerState->setPlaying( TRUE ); |
432 | } | 432 | // } |
433 | } | 433 | } |
434 | 434 | ||
435 | 435 | ||
436 | void PlayListWidget::clearList() { | 436 | void PlayListWidget::clearList() { |
437 | while ( first() ) | 437 | while ( first() ) |
438 | d->selectedFiles->removeSelected(); | 438 | d->selectedFiles->removeSelected(); |
439 | } | 439 | } |
440 | 440 | ||
441 | 441 | ||
442 | void PlayListWidget::addAllToList() { | 442 | void PlayListWidget::addAllToList() { |
443 | DocLnkSet filesAll; | 443 | DocLnkSet filesAll; |
444 | Global::findDocuments(&filesAll, "video/*;audio/*"); | 444 | Global::findDocuments(&filesAll, "video/*;audio/*"); |
445 | QListIterator<DocLnk> Adit( filesAll.children() ); | 445 | QListIterator<DocLnk> Adit( filesAll.children() ); |
446 | for ( ; Adit.current(); ++Adit ) | 446 | for ( ; Adit.current(); ++Adit ) |
447 | if(QFileInfo(Adit.current()->file()).exists()) | 447 | if(QFileInfo(Adit.current()->file()).exists()) |
448 | d->selectedFiles->addToSelection( **Adit ); | 448 | d->selectedFiles->addToSelection( **Adit ); |
449 | } | 449 | } |
450 | 450 | ||
451 | 451 | ||
452 | void PlayListWidget::addAllMusicToList() { | 452 | void PlayListWidget::addAllMusicToList() { |
453 | QListIterator<DocLnk> dit( files.children() ); | 453 | QListIterator<DocLnk> dit( files.children() ); |
454 | for ( ; dit.current(); ++dit ) | 454 | for ( ; dit.current(); ++dit ) |
455 | if(QFileInfo(dit.current()->file()).exists()) | 455 | if(QFileInfo(dit.current()->file()).exists()) |
456 | d->selectedFiles->addToSelection( **dit ); | 456 | d->selectedFiles->addToSelection( **dit ); |
457 | } | 457 | } |
458 | 458 | ||
459 | 459 | ||
460 | void PlayListWidget::addAllVideoToList() { | 460 | void PlayListWidget::addAllVideoToList() { |
461 | QListIterator<DocLnk> dit( vFiles.children() ); | 461 | QListIterator<DocLnk> dit( vFiles.children() ); |
462 | for ( ; dit.current(); ++dit ) | 462 | for ( ; dit.current(); ++dit ) |
463 | if(QFileInfo( dit.current()->file()).exists()) | 463 | if(QFileInfo( dit.current()->file()).exists()) |
464 | d->selectedFiles->addToSelection( **dit ); | 464 | d->selectedFiles->addToSelection( **dit ); |
465 | } | 465 | } |
466 | 466 | ||
467 | 467 | ||
468 | void PlayListWidget::setDocument(const QString& fileref) { | 468 | void PlayListWidget::setDocument(const QString& fileref) { |
469 | qDebug(fileref); | 469 | qDebug(fileref); |
470 | fromSetDocument = TRUE; | 470 | fromSetDocument = TRUE; |
471 | if ( fileref.isNull() ) { | 471 | if ( fileref.isNull() ) { |
472 | QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); | 472 | QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); |
473 | return; | 473 | return; |
474 | } | 474 | } |
475 | // qDebug("setDocument "+fileref); | 475 | // qDebug("setDocument "+fileref); |
476 | if(fileref.find("m3u",0,TRUE) != -1) { //is m3u | 476 | if(fileref.find("m3u",0,TRUE) != -1) { //is m3u |
477 | readm3u( fileref); | 477 | readm3u( fileref); |
478 | } | 478 | } |
479 | else if(fileref.find("pls",0,TRUE) != -1) { //is pls | 479 | else if(fileref.find("pls",0,TRUE) != -1) { //is pls |
480 | readPls( fileref); | 480 | readPls( fileref); |
481 | } | 481 | } |
482 | else if(fileref.find("playlist",0,TRUE) != -1) {//is playlist | 482 | else if(fileref.find("playlist",0,TRUE) != -1) {//is playlist |
483 | clearList(); | 483 | clearList(); |
484 | loadList(DocLnk(fileref)); | 484 | loadList(DocLnk(fileref)); |
485 | d->selectedFiles->first(); | 485 | d->selectedFiles->first(); |
486 | } else { | 486 | } else { |
487 | clearList(); | 487 | clearList(); |
488 | addToSelection( DocLnk( fileref ) ); | 488 | addToSelection( DocLnk( fileref ) ); |
489 | d->setDocumentUsed = TRUE; | 489 | d->setDocumentUsed = TRUE; |
490 | mediaPlayerState->setPlaying( FALSE ); | 490 | mediaPlayerState->setPlaying( FALSE ); |
491 | qApp->processEvents(); | 491 | qApp->processEvents(); |
492 | mediaPlayerState->setPlaying( TRUE ); | 492 | mediaPlayerState->setPlaying( TRUE ); |
493 | qApp->processEvents(); | 493 | qApp->processEvents(); |
494 | setCaption(tr("OpiePlayer")); | 494 | setCaption(tr("OpiePlayer")); |
495 | } | 495 | } |
496 | } | 496 | } |
@@ -794,129 +794,129 @@ void PlayListWidget::addToSelection( QListViewItem *it) { | |||
794 | for ( ; dit.current(); ++dit ) { | 794 | for ( ; dit.current(); ++dit ) { |
795 | if( dit.current()->name() == it->text(0)) { | 795 | if( dit.current()->name() == it->text(0)) { |
796 | d->selectedFiles->addToSelection( **dit ); | 796 | d->selectedFiles->addToSelection( **dit ); |
797 | } | 797 | } |
798 | } | 798 | } |
799 | } | 799 | } |
800 | break; | 800 | break; |
801 | case 0: | 801 | case 0: |
802 | break; | 802 | break; |
803 | }; | 803 | }; |
804 | tabWidget->setCurrentPage(0); | 804 | tabWidget->setCurrentPage(0); |
805 | } | 805 | } |
806 | } | 806 | } |
807 | 807 | ||
808 | void PlayListWidget::tabChanged(QWidget *widg) { | 808 | void PlayListWidget::tabChanged(QWidget *widg) { |
809 | 809 | ||
810 | switch ( tabWidget->currentPageIndex()) { | 810 | switch ( tabWidget->currentPageIndex()) { |
811 | case 0: | 811 | case 0: |
812 | { | 812 | { |
813 | if( !tbDeletePlaylist->isHidden()) | 813 | if( !tbDeletePlaylist->isHidden()) |
814 | tbDeletePlaylist->hide(); | 814 | tbDeletePlaylist->hide(); |
815 | d->tbRemoveFromList->setEnabled(TRUE); | 815 | d->tbRemoveFromList->setEnabled(TRUE); |
816 | d->tbAddToList->setEnabled(FALSE); | 816 | d->tbAddToList->setEnabled(FALSE); |
817 | } | 817 | } |
818 | break; | 818 | break; |
819 | case 1: | 819 | case 1: |
820 | { | 820 | { |
821 | audioView->clear(); | 821 | audioView->clear(); |
822 | populateAudioView(); | 822 | populateAudioView(); |
823 | 823 | ||
824 | if( !tbDeletePlaylist->isHidden()) | 824 | if( !tbDeletePlaylist->isHidden()) |
825 | tbDeletePlaylist->hide(); | 825 | tbDeletePlaylist->hide(); |
826 | d->tbRemoveFromList->setEnabled(FALSE); | 826 | d->tbRemoveFromList->setEnabled(FALSE); |
827 | d->tbAddToList->setEnabled(TRUE); | 827 | d->tbAddToList->setEnabled(TRUE); |
828 | } | 828 | } |
829 | break; | 829 | break; |
830 | case 2: | 830 | case 2: |
831 | { | 831 | { |
832 | videoView->clear(); | 832 | videoView->clear(); |
833 | populateVideoView(); | 833 | populateVideoView(); |
834 | if( !tbDeletePlaylist->isHidden()) | 834 | if( !tbDeletePlaylist->isHidden()) |
835 | tbDeletePlaylist->hide(); | 835 | tbDeletePlaylist->hide(); |
836 | d->tbRemoveFromList->setEnabled(FALSE); | 836 | d->tbRemoveFromList->setEnabled(FALSE); |
837 | d->tbAddToList->setEnabled(TRUE); | 837 | d->tbAddToList->setEnabled(TRUE); |
838 | } | 838 | } |
839 | break; | 839 | break; |
840 | case 3: | 840 | case 3: |
841 | { | 841 | { |
842 | if( tbDeletePlaylist->isHidden()) | 842 | if( tbDeletePlaylist->isHidden()) |
843 | tbDeletePlaylist->show(); | 843 | tbDeletePlaylist->show(); |
844 | playLists->reread(); | 844 | playLists->reread(); |
845 | } | 845 | } |
846 | break; | 846 | break; |
847 | }; | 847 | }; |
848 | } | 848 | } |
849 | 849 | ||
850 | void PlayListWidget::btnPlay(bool b) { | 850 | void PlayListWidget::btnPlay(bool b) { |
851 | 851 | ||
852 | // mediaPlayerState->setPlaying(b); | 852 | // mediaPlayerState->setPlaying(b); |
853 | switch ( tabWidget->currentPageIndex()) { | 853 | switch ( tabWidget->currentPageIndex()) { |
854 | case 0: | 854 | case 0: |
855 | { | 855 | { |
856 | // if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 | 856 | // if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 |
857 | // if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) { | 857 | // if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) { |
858 | QMessageBox::message("Note","You are trying to play\na malformed url."); | 858 | // QMessageBox::message("Note","You are trying to play\na malformed url."); |
859 | // } else { | 859 | // } else { |
860 | mediaPlayerState->setPlaying(b); | 860 | mediaPlayerState->setPlaying(b); |
861 | // } | 861 | // } |
862 | } | 862 | } |
863 | break; | 863 | break; |
864 | case 1: | 864 | case 1: |
865 | { | 865 | { |
866 | addToSelection( audioView->currentItem() ); | 866 | addToSelection( audioView->currentItem() ); |
867 | mediaPlayerState->setPlaying(b); | 867 | mediaPlayerState->setPlaying(b); |
868 | d->selectedFiles->removeSelected( ); | 868 | d->selectedFiles->removeSelected( ); |
869 | tabWidget->setCurrentPage(1); | 869 | tabWidget->setCurrentPage(1); |
870 | d->selectedFiles->unSelect(); | 870 | d->selectedFiles->unSelect(); |
871 | insanityBool=FALSE; | 871 | insanityBool=FALSE; |
872 | }// audioView->clearSelection(); | 872 | }// audioView->clearSelection(); |
873 | break; | 873 | break; |
874 | case 2: | 874 | case 2: |
875 | { | 875 | { |
876 | addToSelection( videoView->currentItem() ); | 876 | addToSelection( videoView->currentItem() ); |
877 | mediaPlayerState->setPlaying(b); | 877 | mediaPlayerState->setPlaying(b); |
878 | qApp->processEvents(); | 878 | qApp->processEvents(); |
879 | d->selectedFiles->removeSelected( ); | 879 | d->selectedFiles->removeSelected( ); |
880 | tabWidget->setCurrentPage(2); | 880 | tabWidget->setCurrentPage(2); |
881 | d->selectedFiles->unSelect(); | 881 | d->selectedFiles->unSelect(); |
882 | insanityBool=FALSE; | 882 | insanityBool=FALSE; |
883 | }// videoView->clearSelection(); | 883 | }// videoView->clearSelection(); |
884 | break; | 884 | break; |
885 | }; | 885 | }; |
886 | 886 | ||
887 | } | 887 | } |
888 | 888 | ||
889 | void PlayListWidget::deletePlaylist() { | 889 | void PlayListWidget::deletePlaylist() { |
890 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), | 890 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), |
891 | (tr("You really want to delete\nthis playlist?")), | 891 | (tr("You really want to delete\nthis playlist?")), |
892 | (tr("Yes")), (tr("No")), 0 )){ | 892 | (tr("Yes")), (tr("No")), 0 )){ |
893 | case 0: // Yes clicked, | 893 | case 0: // Yes clicked, |
894 | QFile().remove(playLists->selected()->file()); | 894 | QFile().remove(playLists->selected()->file()); |
895 | QFile().remove(playLists->selected()->linkFile()); | 895 | QFile().remove(playLists->selected()->linkFile()); |
896 | playLists->reread(); | 896 | playLists->reread(); |
897 | break; | 897 | break; |
898 | case 1: // Cancel | 898 | case 1: // Cancel |
899 | break; | 899 | break; |
900 | }; | 900 | }; |
901 | } | 901 | } |
902 | 902 | ||
903 | void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) | 903 | void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) |
904 | { | 904 | { |
905 | switch (mouse) { | 905 | switch (mouse) { |
906 | case 1: | 906 | case 1: |
907 | break; | 907 | break; |
908 | case 2:{ | 908 | case 2:{ |
909 | 909 | ||
910 | QPopupMenu m; | 910 | QPopupMenu m; |
911 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); | 911 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); |
912 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); | 912 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); |
913 | m.insertSeparator(); | 913 | m.insertSeparator(); |
914 | if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) | 914 | if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) |
915 | m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); | 915 | m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); |
916 | 916 | ||
917 | m.exec( QCursor::pos() ); | 917 | m.exec( QCursor::pos() ); |
918 | } | 918 | } |
919 | break; | 919 | break; |
920 | }; | 920 | }; |
921 | } | 921 | } |
922 | 922 | ||