summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-06-26 23:50:27 (UTC)
committer llornkcor <llornkcor>2002-06-26 23:50:27 (UTC)
commita86c09e8a12b504471ffeb8966e34a79dd8518b5 (patch) (unidiff)
treebea361029616edb533136880b973dae4a7e7315e
parentb13d95b210c7d16229514afc66e32a1de09a075c (diff)
downloadopie-a86c09e8a12b504471ffeb8966e34a79dd8518b5.zip
opie-a86c09e8a12b504471ffeb8966e34a79dd8518b5.tar.gz
opie-a86c09e8a12b504471ffeb8966e34a79dd8518b5.tar.bz2
fixed error parsing pls where the url's already have a trailing /, and took out muting for now
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/audiodevice.cpp8
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp9
2 files changed, 11 insertions, 6 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp
index 8f04d0d..59e06a6 100644
--- a/core/multimedia/opieplayer/audiodevice.cpp
+++ b/core/multimedia/opieplayer/audiodevice.cpp
@@ -1,389 +1,389 @@
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> 27#include <qmessagebox.h>
28 28
29#include "audiodevice.h" 29#include "audiodevice.h"
30 30
31 31
32#include <errno.h> 32#include <errno.h>
33 33
34#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)
35#include "qpe/qcopenvelope_qws.h" 35#include "qpe/qcopenvelope_qws.h"
36#endif 36#endif
37 37
38// #ifdef Q_WS_WIN 38// #ifdef Q_WS_WIN
39// #include <windows.h> 39// #include <windows.h>
40// #include <mmsystem.h> 40// #include <mmsystem.h>
41// #include <mmreg.h> 41// #include <mmreg.h>
42// #endif 42// #endif
43#if defined(Q_WS_X11) || defined(Q_WS_QWS) 43#if defined(Q_WS_X11) || defined(Q_WS_QWS)
44#include <fcntl.h> 44#include <fcntl.h>
45#include <sys/ioctl.h> 45#include <sys/ioctl.h>
46#include <sys/soundcard.h> 46#include <sys/soundcard.h>
47#include <sys/stat.h> 47#include <sys/stat.h>
48#include <sys/time.h> 48#include <sys/time.h>
49#include <sys/types.h> 49#include <sys/types.h>
50#include <unistd.h> 50#include <unistd.h>
51#endif 51#endif
52 52
53// #if defined(Q_OS_WIN32) 53// #if defined(Q_OS_WIN32)
54// static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000; 54// static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000;
55// static const int timerResolutionMilliSeconds = 30; 55// static const int timerResolutionMilliSeconds = 30;
56// static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond; 56// static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond;
57// #else 57// #else
58# if defined(QT_QWS_IPAQ) 58# if defined(QT_QWS_IPAQ)
59static const int sound_fragment_shift = 14; 59static const int sound_fragment_shift = 14;
60# else 60# else
61static const int sound_fragment_shift = 16; 61static const int sound_fragment_shift = 16;
62# endif 62# endif
63static const int sound_fragment_bytes = (1<<sound_fragment_shift); 63static const int sound_fragment_bytes = (1<<sound_fragment_shift);
64//#endif 64//#endif
65 65
66 66
67class AudioDevicePrivate { 67class AudioDevicePrivate {
68public: 68public:
69 int handle; 69 int handle;
70 unsigned int frequency; 70 unsigned int frequency;
71 unsigned int channels; 71 unsigned int channels;
72 unsigned int bytesPerSample; 72 unsigned int bytesPerSample;
73 unsigned int bufferSize; 73 unsigned int bufferSize;
74//#ifndef Q_OS_WIN32 74//#ifndef Q_OS_WIN32
75 bool can_GETOSPACE; 75 bool can_GETOSPACE;
76 char* unwrittenBuffer; 76 char* unwrittenBuffer;
77 unsigned int unwritten; 77 unsigned int unwritten;
78//#endif 78//#endif
79 79
80 static int dspFd; 80 static int dspFd;
81 static bool muted; 81 static bool muted;
82 static unsigned int leftVolume; 82 static unsigned int leftVolume;
83 static unsigned int rightVolume; 83 static unsigned int rightVolume;
84}; 84};
85 85
86 86
87#ifdef Q_WS_QWS 87#ifdef Q_WS_QWS
88// 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
89// the device makes clicks and it starts to drive you insane! :) 89// the device makes clicks and it starts to drive you insane! :)
90// 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
91//#define KEEP_DEVICE_OPEN 91//#define KEEP_DEVICE_OPEN
92#endif 92#endif
93 93
94 94
95int AudioDevicePrivate::dspFd = 0; 95int AudioDevicePrivate::dspFd = 0;
96bool AudioDevicePrivate::muted = FALSE; 96bool AudioDevicePrivate::muted = FALSE;
97unsigned int AudioDevicePrivate::leftVolume = 0; 97unsigned int AudioDevicePrivate::leftVolume = 0;
98unsigned int AudioDevicePrivate::rightVolume = 0; 98unsigned int AudioDevicePrivate::rightVolume = 0;
99 99
100 100
101void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { 101void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) {
102 muted = AudioDevicePrivate::muted; 102 muted = AudioDevicePrivate::muted;
103 unsigned int volume; 103 unsigned int volume;
104// #ifdef Q_OS_WIN32 104// #ifdef Q_OS_WIN32
105// HWAVEOUT handle; 105// HWAVEOUT handle;
106// WAVEFORMATEX formatData; 106// WAVEFORMATEX formatData;
107// formatData.cbSize = sizeof(WAVEFORMATEX); 107// formatData.cbSize = sizeof(WAVEFORMATEX);
108// formatData.wFormatTag = WAVE_FORMAT_PCM; 108// formatData.wFormatTag = WAVE_FORMAT_PCM;
109// formatData.nAvgBytesPerSec = 4 * 44000; 109// formatData.nAvgBytesPerSec = 4 * 44000;
110// formatData.nBlockAlign = 4; 110// formatData.nBlockAlign = 4;
111// formatData.nChannels = 2; 111// formatData.nChannels = 2;
112// formatData.nSamplesPerSec = 44000; 112// formatData.nSamplesPerSec = 44000;
113// formatData.wBitsPerSample = 16; 113// formatData.wBitsPerSample = 16;
114// waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); 114// waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL);
115// if ( waveOutGetVolume( handle, (LPDWORD)&volume ) ) 115// if ( waveOutGetVolume( handle, (LPDWORD)&volume ) )
116// // qDebug( "get volume of audio device failed" ); 116// // qDebug( "get volume of audio device failed" );
117// waveOutClose( handle ); 117// waveOutClose( handle );
118// leftVolume = volume & 0xFFFF; 118// leftVolume = volume & 0xFFFF;
119// rightVolume = volume >> 16; 119// rightVolume = volume >> 16;
120// #else 120// #else
121 int mixerHandle = open( "/dev/mixer", O_RDWR ); 121 int mixerHandle = open( "/dev/mixer", O_RDWR );
122 if ( mixerHandle >= 0 ) { 122 if ( mixerHandle >= 0 ) {
123 if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) 123 if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1)
124 perror("ioctl(\"MIXER_READ\")"); 124 perror("ioctl(\"MIXER_READ\")");
125 close( mixerHandle ); 125 close( mixerHandle );
126 } else 126 } else
127 perror("open(\"/dev/mixer\")"); 127 perror("open(\"/dev/mixer\")");
128 leftVolume = ((volume & 0x00FF) << 16) / 101; 128 leftVolume = ((volume & 0x00FF) << 16) / 101;
129 rightVolume = ((volume & 0xFF00) << 8) / 101; 129 rightVolume = ((volume & 0xFF00) << 8) / 101;
130//#endif 130//#endif
131} 131}
132 132
133 133
134void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { 134void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) {
135 AudioDevicePrivate::muted = muted; 135 AudioDevicePrivate::muted = muted;
136 if ( muted ) { 136 if ( muted ) {
137 AudioDevicePrivate::leftVolume = leftVolume; 137 AudioDevicePrivate::leftVolume = leftVolume;
138 AudioDevicePrivate::rightVolume = rightVolume; 138 AudioDevicePrivate::rightVolume = rightVolume;
139 leftVolume = 0; 139 leftVolume = 0;
140 rightVolume = 0; 140 rightVolume = 0;
141 } else { 141 } else {
142 leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); 142 leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume );
143 rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); 143 rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume );
144 } 144 }
145// #ifdef Q_OS_WIN32 145// #ifdef Q_OS_WIN32
146// HWAVEOUT handle; 146// HWAVEOUT handle;
147// WAVEFORMATEX formatData; 147// WAVEFORMATEX formatData;
148// formatData.cbSize = sizeof(WAVEFORMATEX); 148// formatData.cbSize = sizeof(WAVEFORMATEX);
149// formatData.wFormatTag = WAVE_FORMAT_PCM; 149// formatData.wFormatTag = WAVE_FORMAT_PCM;
150// formatData.nAvgBytesPerSec = 4 * 44000; 150// formatData.nAvgBytesPerSec = 4 * 44000;
151// formatData.nBlockAlign = 4; 151// formatData.nBlockAlign = 4;
152// formatData.nChannels = 2; 152// formatData.nChannels = 2;
153// formatData.nSamplesPerSec = 44000; 153// formatData.nSamplesPerSec = 44000;
154// formatData.wBitsPerSample = 16; 154// formatData.wBitsPerSample = 16;
155// waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL); 155// waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL);
156// unsigned int volume = (rightVolume << 16) | leftVolume; 156// unsigned int volume = (rightVolume << 16) | leftVolume;
157// if ( waveOutSetVolume( handle, volume ) ) 157// if ( waveOutSetVolume( handle, volume ) )
158// // qDebug( "set volume of audio device failed" ); 158// // qDebug( "set volume of audio device failed" );
159// waveOutClose( handle ); 159// waveOutClose( handle );
160// #else 160// #else
161 // 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
162 unsigned int rV = (rightVolume * 101) >> 16; 162 unsigned int rV = (rightVolume * 101) >> 16;
163 163
164# if 0 164# if 0
165 unsigned int lV = (leftVolume * 101) >> 16; 165 unsigned int lV = (leftVolume * 101) >> 16;
166 unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); 166 unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF);
167 int mixerHandle = 0; 167 int mixerHandle = 0;
168 if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 168 if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
169 if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) 169 if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1)
170 perror("ioctl(\"MIXER_WRITE\")"); 170 perror("ioctl(\"MIXER_WRITE\")");
171 close( mixerHandle ); 171 close( mixerHandle );
172 } else 172 } else
173 perror("open(\"/dev/mixer\")"); 173 perror("open(\"/dev/mixer\")");
174 174
175# else 175# else
176 // 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
177 // independant right and left channel setting, or setting for different outputs 177 // independant right and left channel setting, or setting for different outputs
178 Config cfg("qpe"); // qtopia is "Sound" 178 Config cfg("qpe"); // qtopia is "Sound"
179 cfg.setGroup("Volume"); // qtopia is "Settings" 179 cfg.setGroup("Volume"); // qtopia is "Settings"
180 cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume 180 cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume
181# endif 181# endif
182 182
183//#endif 183//#endif
184// qDebug( "setting volume to: 0x%x", volume ); 184// qDebug( "setting volume to: 0x%x", volume );
185#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)
186 // Send notification that the volume has changed 186 // Send notification that the volume has changed
187 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; 187 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
188#endif 188#endif
189} 189}
190 190
191 191
192 192
193 193
194AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { 194AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
195 qDebug("creating new audio device"); 195 qDebug("creating new audio device");
196 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; 196 // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
197 d = new AudioDevicePrivate; 197 d = new AudioDevicePrivate;
198 d->frequency = f; 198 d->frequency = f;
199 d->channels = chs; 199 d->channels = chs;
200 d->bytesPerSample = bps; 200 d->bytesPerSample = bps;
201 qDebug("%d",bps); 201 qDebug("%d",bps);
202 int format=0; 202 int format=0;
203 if( bps == 8) format = AFMT_U8; 203 if( bps == 8) format = AFMT_U8;
204 else if( bps <= 0) format = AFMT_S16_LE; 204 else if( bps <= 0) format = AFMT_S16_LE;
205 else format = AFMT_S16_LE; 205 else format = AFMT_S16_LE;
206 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);
207 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); 207 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
208 208
209 int fragments = 0x10000 * 8 + sound_fragment_shift; 209 int fragments = 0x10000 * 8 + sound_fragment_shift;
210 int capabilities = 0; 210 int capabilities = 0;
211 211
212 212
213#ifdef KEEP_DEVICE_OPEN 213#ifdef KEEP_DEVICE_OPEN
214 if ( AudioDevicePrivate::dspFd == 0 ) { 214 if ( AudioDevicePrivate::dspFd == 0 ) {
215#endif 215#endif
216 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { 216 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) {
217 217
218// perror("open(\"/dev/dsp\") sending to /dev/null instead"); 218// perror("open(\"/dev/dsp\") sending to /dev/null instead");
219 perror("open(\"/dev/dsp\")"); 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."); 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")); 221 QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort"));
222 exit(-1); //harsh? 222 exit(-1); //harsh?
223// d->handle = ::open( "/dev/null", O_WRONLY ); 223// d->handle = ::open( "/dev/null", O_WRONLY );
224 // WTF?!?! 224 // WTF?!?!
225 } 225 }
226#ifdef KEEP_DEVICE_OPEN 226#ifdef KEEP_DEVICE_OPEN
227 AudioDevicePrivate::dspFd = d->handle; 227 AudioDevicePrivate::dspFd = d->handle;
228 } else { 228 } else {
229 d->handle = AudioDevicePrivate::dspFd; 229 d->handle = AudioDevicePrivate::dspFd;
230 } 230 }
231#endif 231#endif
232 232
233 if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) 233 if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1)
234 perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); 234 perror("ioctl(\"SNDCTL_DSP_GETCAPS\")");
235 if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) 235 if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1)
236 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); 236 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")");
237 if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) 237 if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1)
238 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 238 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
239 qDebug("freq %d", d->frequency); 239 qDebug("freq %d", d->frequency);
240 if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) 240 if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1)
241 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 241 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
242 qDebug("channels %d",d->channels); 242 qDebug("channels %d",d->channels);
243 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { 243 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) {
244 d->channels = ( d->channels == 1 ) ? 2 : d->channels; 244 d->channels = ( d->channels == 1 ) ? 2 : d->channels;
245 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) 245 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1)
246 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 246 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
247 } 247 }
248 248
249 d->bufferSize = sound_fragment_bytes; 249 d->bufferSize = sound_fragment_bytes;
250 d->unwrittenBuffer = new char[d->bufferSize]; 250 d->unwrittenBuffer = new char[d->bufferSize];
251 d->unwritten = 0; 251 d->unwritten = 0;
252 d->can_GETOSPACE = TRUE; // until we find otherwise 252 d->can_GETOSPACE = TRUE; // until we find otherwise
253 253
254 //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 );
255 //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 );
256 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); 256 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" );
257 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); 257 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" );
258 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); 258 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" );
259 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); 259 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" );
260 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; 260 // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
261 261
262} 262}
263 263
264 264
265AudioDevice::~AudioDevice() { 265AudioDevice::~AudioDevice() {
266 qDebug("destryo audiodevice"); 266 qDebug("destryo audiodevice");
267 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; 267 // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
268 268
269// #ifdef Q_OS_WIN32 269// #ifdef Q_OS_WIN32
270// waveOutClose( (HWAVEOUT)d->handle ); 270// waveOutClose( (HWAVEOUT)d->handle );
271// #else 271// #else
272# ifndef KEEP_DEVICE_OPEN 272# ifndef KEEP_DEVICE_OPEN
273 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
274# endif 274# endif
275 delete d->unwrittenBuffer; 275 delete d->unwrittenBuffer;
276 delete d; 276 delete d;
277//#endif 277//#endif
278 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; 278// QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
279 279
280} 280}
281 281
282 282
283void AudioDevice::volumeChanged( bool muted ) 283void AudioDevice::volumeChanged( bool muted )
284{ 284{
285 AudioDevicePrivate::muted = muted; 285 AudioDevicePrivate::muted = muted;
286} 286}
287 287
288 288
289void AudioDevice::write( char *buffer, unsigned int length ) 289void AudioDevice::write( char *buffer, unsigned int length )
290{ 290{
291// #ifdef Q_OS_WIN32 291// #ifdef Q_OS_WIN32
292// // returns immediately and (to be implemented) emits completedIO() when finished writing 292// // returns immediately and (to be implemented) emits completedIO() when finished writing
293// WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) ); 293// WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) );
294// // maybe the buffer should be copied so that this fool proof, but its a performance hit 294// // maybe the buffer should be copied so that this fool proof, but its a performance hit
295// lpWaveHdr->lpData = buffer; 295// lpWaveHdr->lpData = buffer;
296// lpWaveHdr->dwBufferLength = length; 296// lpWaveHdr->dwBufferLength = length;
297// lpWaveHdr->dwFlags = 0L; 297// lpWaveHdr->dwFlags = 0L;
298// lpWaveHdr->dwLoops = 0L; 298// lpWaveHdr->dwLoops = 0L;
299// waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ); 299// waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) );
300// // waveOutWrite returns immediately. the data is sent in the background. 300// // waveOutWrite returns immediately. the data is sent in the background.
301// if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) ) 301// if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) )
302// qDebug( "failed to write block to audio device" ); 302// qDebug( "failed to write block to audio device" );
303// // emit completedIO(); 303// // emit completedIO();
304// #else 304// #else
305 int t = ::write( d->handle, buffer, length ); 305 int t = ::write( d->handle, buffer, length );
306 if ( t<0 ) t = 0; 306 if ( t<0 ) t = 0;
307 if ( t != (int)length) { 307 if ( t != (int)length) {
308 qDebug("Ahhh!! memcpys 1"); 308 qDebug("Ahhh!! memcpys 1");
309 memcpy(d->unwrittenBuffer,buffer+t,length-t); 309 memcpy(d->unwrittenBuffer,buffer+t,length-t);
310 d->unwritten = length-t; 310 d->unwritten = length-t;
311 } 311 }
312//#endif 312//#endif
313} 313}
314 314
315 315
316unsigned int AudioDevice::channels() const 316unsigned int AudioDevice::channels() const
317{ 317{
318 return d->channels; 318 return d->channels;
319} 319}
320 320
321 321
322unsigned int AudioDevice::frequency() const 322unsigned int AudioDevice::frequency() const
323{ 323{
324 return d->frequency; 324 return d->frequency;
325} 325}
326 326
327 327
328unsigned int AudioDevice::bytesPerSample() const 328unsigned int AudioDevice::bytesPerSample() const
329{ 329{
330 return d->bytesPerSample; 330 return d->bytesPerSample;
331} 331}
332 332
333 333
334unsigned int AudioDevice::bufferSize() const 334unsigned int AudioDevice::bufferSize() const
335{ 335{
336 return d->bufferSize; 336 return d->bufferSize;
337} 337}
338 338
339unsigned int AudioDevice::canWrite() const 339unsigned int AudioDevice::canWrite() const
340{ 340{
341// #ifdef Q_OS_WIN32 341// #ifdef Q_OS_WIN32
342// return bufferSize(); // Any better? 342// return bufferSize(); // Any better?
343// #else 343// #else
344 audio_buf_info info; 344 audio_buf_info info;
345 if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { 345 if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) {
346 d->can_GETOSPACE = FALSE; 346 d->can_GETOSPACE = FALSE;
347 fcntl( d->handle, F_SETFL, O_NONBLOCK ); 347 fcntl( d->handle, F_SETFL, O_NONBLOCK );
348 } 348 }
349 if ( d->can_GETOSPACE ) { 349 if ( d->can_GETOSPACE ) {
350 int t = info.fragments * sound_fragment_bytes; 350 int t = info.fragments * sound_fragment_bytes;
351 return QMIN(t,(int)bufferSize()); 351 return QMIN(t,(int)bufferSize());
352 } else { 352 } else {
353 if ( d->unwritten ) { 353 if ( d->unwritten ) {
354 int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); 354 int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten );
355 if ( t<0 ) t = 0; 355 if ( t<0 ) t = 0;
356 if ( (unsigned)t!=d->unwritten ) { 356 if ( (unsigned)t!=d->unwritten ) {
357 memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); 357 memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t);
358 d->unwritten -= t; 358 d->unwritten -= t;
359 } else { 359 } else {
360 d->unwritten = 0; 360 d->unwritten = 0;
361 } 361 }
362 } 362 }
363 if ( d->unwritten ) 363 if ( d->unwritten )
364 return 0; 364 return 0;
365 else 365 else
366 return d->bufferSize; 366 return d->bufferSize;
367 } 367 }
368//#endif 368//#endif
369} 369}
370 370
371 371
372int AudioDevice::bytesWritten() { 372int AudioDevice::bytesWritten() {
373// #ifdef Q_OS_WIN32 373// #ifdef Q_OS_WIN32
374// MMTIME pmmt = { TIME_BYTES, 0 }; 374// MMTIME pmmt = { TIME_BYTES, 0 };
375// if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) { 375// if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) {
376// qDebug( "failed to get audio device position" ); 376// qDebug( "failed to get audio device position" );
377// return -1; 377// return -1;
378// } 378// }
379// return pmmt.u.cb; 379// return pmmt.u.cb;
380// #else 380// #else
381 int buffered = 0; 381 int buffered = 0;
382 if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { 382 if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) {
383 qDebug( "failed to get audio device position" ); 383 qDebug( "failed to get audio device position" );
384 return -1; 384 return -1;
385 } 385 }
386 return buffered; 386 return buffered;
387//#endif 387//#endif
388} 388}
389 389
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp
index 0332237..4926287 100644
--- a/core/multimedia/opieplayer/playlistwidget.cpp
+++ b/core/multimedia/opieplayer/playlistwidget.cpp
@@ -1,1352 +1,1357 @@
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
82extern AudioWidget *audioUI; 82extern AudioWidget *audioUI;
83extern VideoWidget *videoUI; 83extern VideoWidget *videoUI;
84extern MediaPlayerState *mediaPlayerState; 84extern MediaPlayerState *mediaPlayerState;
85 85
86// class myFileSelector { 86// class myFileSelector {
87 87
88// }; 88// };
89class PlayListWidgetPrivate { 89class PlayListWidgetPrivate {
90public: 90public:
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
100class ToolButton : public QToolButton { 100class ToolButton : public QToolButton {
101public: 101public:
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
115class MenuItem : public QAction { 115class MenuItem : public QAction {
116public: 116public:
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
125PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) 125PlayListWidget::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 160
161 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",
162 this , SLOT(addSelected()) ); 162 this , SLOT(addSelected()) );
163 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",
164 this , SLOT(removeSelected()) ); 164 this , SLOT(removeSelected()) );
165// 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 );
166 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", 166 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play",
167 this , SLOT( btnPlay(bool) ), TRUE ); 167 this , SLOT( btnPlay(bool) ), TRUE );
168 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle", 168 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle",
169 mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); 169 mediaPlayerState, SLOT(setShuffled(bool)), TRUE );
170 d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop", 170 d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop",
171 mediaPlayerState, SLOT(setLooping(bool)), TRUE ); 171 mediaPlayerState, SLOT(setLooping(bool)), TRUE );
172 tbDeletePlaylist->hide(); 172 tbDeletePlaylist->hide();
173 173
174 QPopupMenu *pmPlayList = new QPopupMenu( this ); 174 QPopupMenu *pmPlayList = new QPopupMenu( this );
175 menu->insertItem( tr( "File" ), pmPlayList ); 175 menu->insertItem( tr( "File" ), pmPlayList );
176 new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); 176 new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) );
177 new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); 177 new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) );
178 new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); 178 new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) );
179 new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); 179 new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) );
180 pmPlayList->insertSeparator(-1); 180 pmPlayList->insertSeparator(-1);
181 new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); 181 new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) );
182 new MenuItem( pmPlayList, tr( "Export playlist to m3u" ), this, SLOT(writem3u() ) ); 182 new MenuItem( pmPlayList, tr( "Export playlist to m3u" ), this, SLOT(writem3u() ) );
183 pmPlayList->insertSeparator(-1); 183 pmPlayList->insertSeparator(-1);
184 new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); 184 new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) );
185 pmPlayList->insertSeparator(-1); 185 pmPlayList->insertSeparator(-1);
186 new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) ); 186 new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) );
187 new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) ); 187 new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) );
188 188
189 QPopupMenu *pmView = new QPopupMenu( this ); 189 QPopupMenu *pmView = new QPopupMenu( this );
190 menu->insertItem( tr( "View" ), pmView ); 190 menu->insertItem( tr( "View" ), pmView );
191 191
192 fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); 192 fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0);
193 fullScreenButton->addTo(pmView); 193 fullScreenButton->addTo(pmView);
194 scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0); 194 scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0);
195 scaleButton->addTo(pmView); 195 scaleButton->addTo(pmView);
196 196
197 QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); 197 QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton );
198 QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); 198 QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton );
199 199
200 QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); 200 QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton );
201 201
202 tabWidget = new QTabWidget( hbox6, "tabWidget" ); 202 tabWidget = new QTabWidget( hbox6, "tabWidget" );
203 tabWidget->setTabShape(QTabWidget::Triangular); 203 tabWidget->setTabShape(QTabWidget::Triangular);
204 204
205 QWidget *pTab; 205 QWidget *pTab;
206 pTab = new QWidget( tabWidget, "pTab" ); 206 pTab = new QWidget( tabWidget, "pTab" );
207// playlistView = new QListView( pTab, "playlistview" ); 207// playlistView = new QListView( pTab, "playlistview" );
208// playlistView->setMinimumSize(236,260); 208// playlistView->setMinimumSize(236,260);
209 tabWidget->insertTab( pTab,"Playlist"); 209 tabWidget->insertTab( pTab,"Playlist");
210 210
211 211
212 // Add the playlist area 212 // Add the playlist area
213 213
214 QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); 214 QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton );
215 d->playListFrame = vbox3; 215 d->playListFrame = vbox3;
216 d->playListFrame ->setMinimumSize(235,260); 216 d->playListFrame ->setMinimumSize(235,260);
217 217
218 QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); 218 QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton );
219 219
220 d->selectedFiles = new PlayListSelection( hbox2); 220 d->selectedFiles = new PlayListSelection( hbox2);
221 QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); 221 QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton );
222 222
223 QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); 223 QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold);
224 224
225 225
226 226
227 QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch 227 QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch
228 new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); 228 new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) );
229 new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); 229 new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) );
230 new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); 230 new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) );
231 QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch 231 QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch
232 232
233 QWidget *aTab; 233 QWidget *aTab;
234 aTab = new QWidget( tabWidget, "aTab" ); 234 aTab = new QWidget( tabWidget, "aTab" );
235 audioView = new QListView( aTab, "Audioview" ); 235 audioView = new QListView( aTab, "Audioview" );
236 audioView->setMinimumSize(233,260); 236 audioView->setMinimumSize(233,260);
237 audioView->addColumn( tr("Title"),140); 237 audioView->addColumn( tr("Title"),140);
238 audioView->addColumn(tr("Size"), -1); 238 audioView->addColumn(tr("Size"), -1);
239 audioView->addColumn(tr("Media"),-1); 239 audioView->addColumn(tr("Media"),-1);
240 audioView->setColumnAlignment(1, Qt::AlignRight); 240 audioView->setColumnAlignment(1, Qt::AlignRight);
241 audioView->setColumnAlignment(2, Qt::AlignRight); 241 audioView->setColumnAlignment(2, Qt::AlignRight);
242 audioView->setAllColumnsShowFocus(TRUE); 242 audioView->setAllColumnsShowFocus(TRUE);
243 243
244 audioView->setMultiSelection( TRUE ); 244 audioView->setMultiSelection( TRUE );
245 audioView->setSelectionMode( QListView::Extended); 245 audioView->setSelectionMode( QListView::Extended);
246 246
247 tabWidget->insertTab(aTab,tr("Audio")); 247 tabWidget->insertTab(aTab,tr("Audio"));
248 248
249 QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); 249 QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold);
250 250
251// audioView 251// audioView
252// populateAudioView(); 252// populateAudioView();
253// videowidget 253// videowidget
254 254
255 QWidget *vTab; 255 QWidget *vTab;
256 vTab = new QWidget( tabWidget, "vTab" ); 256 vTab = new QWidget( tabWidget, "vTab" );
257 videoView = new QListView( vTab, "Videoview" ); 257 videoView = new QListView( vTab, "Videoview" );
258 videoView->setMinimumSize(233,260); 258 videoView->setMinimumSize(233,260);
259 259
260 videoView->addColumn(tr("Title"),140); 260 videoView->addColumn(tr("Title"),140);
261 videoView->addColumn(tr("Size"),-1); 261 videoView->addColumn(tr("Size"),-1);
262 videoView->addColumn(tr("Media"),-1); 262 videoView->addColumn(tr("Media"),-1);
263 videoView->setColumnAlignment(1, Qt::AlignRight); 263 videoView->setColumnAlignment(1, Qt::AlignRight);
264 videoView->setColumnAlignment(2, Qt::AlignRight); 264 videoView->setColumnAlignment(2, Qt::AlignRight);
265 videoView->setAllColumnsShowFocus(TRUE); 265 videoView->setAllColumnsShowFocus(TRUE);
266 videoView->setMultiSelection( TRUE ); 266 videoView->setMultiSelection( TRUE );
267 videoView->setSelectionMode( QListView::Extended); 267 videoView->setSelectionMode( QListView::Extended);
268 268
269 QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); 269 QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold);
270 270
271 tabWidget->insertTab( vTab,tr("Video")); 271 tabWidget->insertTab( vTab,tr("Video"));
272// populateVideoView(); 272// populateVideoView();
273 273
274//playlists list 274//playlists list
275 QWidget *LTab; 275 QWidget *LTab;
276 LTab = new QWidget( tabWidget, "LTab" ); 276 LTab = new QWidget( tabWidget, "LTab" );
277 playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy 277 playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy
278 playLists->setMinimumSize(233,260); 278 playLists->setMinimumSize(233,260);
279 tabWidget->insertTab(LTab,tr("Lists")); 279 tabWidget->insertTab(LTab,tr("Lists"));
280 280
281// connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); 281// connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
282 282
283// add the library area 283// add the library area
284 284
285// connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), 285// connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)),
286// this, SLOT( fauxPlay( QListViewItem *) ) ); 286// this, SLOT( fauxPlay( QListViewItem *) ) );
287// connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), 287// connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)),
288// this, SLOT( fauxPlay( QListViewItem *)) ); 288// this, SLOT( fauxPlay( QListViewItem *)) );
289 289
290// connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); 290// connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) );
291// connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); 291// connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) );
292 292
293 connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); 293 connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist()));
294 connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); 294 connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) );
295 connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); 295 connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) );
296 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), 296 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
297 this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); 297 this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) );
298 298
299 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), 299 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
300 this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); 300 this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) );
301 301
302 connect( audioView, SIGNAL( returnPressed( QListViewItem *)), 302 connect( audioView, SIGNAL( returnPressed( QListViewItem *)),
303 this,SLOT( playIt( QListViewItem *)) ); 303 this,SLOT( playIt( QListViewItem *)) );
304 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); 304 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) );
305 305
306 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), 306 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
307 this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); 307 this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) );
308 connect( videoView, SIGNAL( returnPressed( QListViewItem *)), 308 connect( videoView, SIGNAL( returnPressed( QListViewItem *)),
309 this,SLOT( playIt( QListViewItem *)) ); 309 this,SLOT( playIt( QListViewItem *)) );
310 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); 310 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) );
311 311
312 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); 312 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) );
313 313
314 314
315 connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); 315 connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*)));
316 316
317 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); 317 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) );
318 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); 318 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) );
319 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); 319 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) );
320 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); 320 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) );
321 321
322 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); 322 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) );
323// connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); 323// connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) );
324 324
325 setCentralWidget( vbox5 ); 325 setCentralWidget( vbox5 );
326 326
327 Config cfg( "OpiePlayer" ); 327 Config cfg( "OpiePlayer" );
328 readConfig( cfg ); 328 readConfig( cfg );
329 QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); 329 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
330// qDebug("currentList is "+currentPlaylist); 330// qDebug("currentList is "+currentPlaylist);
331 loadList(DocLnk( currentPlaylist)); 331 loadList(DocLnk( currentPlaylist));
332 setCaption(tr("OpiePlayer: ")+ currentPlaylist ); 332 setCaption(tr("OpiePlayer: ")+ currentPlaylist );
333 333
334 initializeStates(); 334 initializeStates();
335} 335}
336 336
337 337
338PlayListWidget::~PlayListWidget() { 338PlayListWidget::~PlayListWidget() {
339 Config cfg( "OpiePlayer" ); 339 Config cfg( "OpiePlayer" );
340 writeConfig( cfg ); 340 writeConfig( cfg );
341 341
342 342
343 if ( d->current ) 343 if ( d->current )
344 delete d->current; 344 delete d->current;
345 delete d; 345 delete d;
346} 346}
347 347
348 348
349void PlayListWidget::initializeStates() { 349void PlayListWidget::initializeStates() {
350 350
351 d->tbPlay->setOn( mediaPlayerState->playing() ); 351 d->tbPlay->setOn( mediaPlayerState->playing() );
352 d->tbLoop->setOn( mediaPlayerState->looping() ); 352 d->tbLoop->setOn( mediaPlayerState->looping() );
353 d->tbShuffle->setOn( mediaPlayerState->shuffled() ); 353 d->tbShuffle->setOn( mediaPlayerState->shuffled() );
354// d->tbFull->setOn( mediaPlayerState->fullscreen() ); 354// d->tbFull->setOn( mediaPlayerState->fullscreen() );
355// d->tbScale->setOn( mediaPlayerState->scaled() ); 355// d->tbScale->setOn( mediaPlayerState->scaled() );
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
364void PlayListWidget::readConfig( Config& cfg ) { 364void 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
382void PlayListWidget::writeConfig( Config& cfg ) const { 382void 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
418void PlayListWidget::addToSelection( const DocLnk& lnk ) { 418void 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
436void PlayListWidget::clearList() { 436void PlayListWidget::clearList() {
437 while ( first() ) 437 while ( first() )
438 d->selectedFiles->removeSelected(); 438 d->selectedFiles->removeSelected();
439} 439}
440 440
441 441
442void PlayListWidget::addAllToList() { 442void 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
452void PlayListWidget::addAllMusicToList() { 452void 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
460void PlayListWidget::addAllVideoToList() { 460void 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
468void PlayListWidget::setDocument(const QString& fileref) { 468void 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}
497 497
498 498
499void PlayListWidget::setActiveWindow() { 499void PlayListWidget::setActiveWindow() {
500 // When we get raised we need to ensure that it switches views 500 // When we get raised we need to ensure that it switches views
501 char origView = mediaPlayerState->view(); 501 char origView = mediaPlayerState->view();
502 mediaPlayerState->setView( 'l' ); // invalidate 502 mediaPlayerState->setView( 'l' ); // invalidate
503 mediaPlayerState->setView( origView ); // now switch back 503 mediaPlayerState->setView( origView ); // now switch back
504} 504}
505 505
506 506
507void PlayListWidget::useSelectedDocument() { 507void PlayListWidget::useSelectedDocument() {
508 d->setDocumentUsed = FALSE; 508 d->setDocumentUsed = FALSE;
509} 509}
510 510
511 511
512const DocLnk *PlayListWidget::current() { // this is fugly 512const DocLnk *PlayListWidget::current() { // this is fugly
513 513
514// if( fromSetDocument) { 514// if( fromSetDocument) {
515// qDebug("from setDoc"); 515// qDebug("from setDoc");
516// DocLnkSet files; 516// DocLnkSet files;
517// Global::findDocuments(&files, "video/*;audio/*"); 517// Global::findDocuments(&files, "video/*;audio/*");
518// QListIterator<DocLnk> dit( files.children() ); 518// QListIterator<DocLnk> dit( files.children() );
519// for ( ; dit.current(); ++dit ) { 519// for ( ; dit.current(); ++dit ) {
520// if(dit.current()->linkFile() == setDocFileRef) { 520// if(dit.current()->linkFile() == setDocFileRef) {
521// qDebug(setDocFileRef); 521// qDebug(setDocFileRef);
522// return dit; 522// return dit;
523// } 523// }
524// } 524// }
525// } else 525// } else
526 526
527 527
528 switch (tabWidget->currentPageIndex()) { 528 switch (tabWidget->currentPageIndex()) {
529 case 0: //playlist 529 case 0: //playlist
530 { 530 {
531 qDebug("playlist"); 531 qDebug("playlist");
532 if ( mediaPlayerState->playlist() ) { 532 if ( mediaPlayerState->playlist() ) {
533 return d->selectedFiles->current(); 533 return d->selectedFiles->current();
534 } 534 }
535 else if ( d->setDocumentUsed && d->current ) { 535 else if ( d->setDocumentUsed && d->current ) {
536 return d->current; 536 return d->current;
537 } else { 537 } else {
538 return d->files->selected(); 538 return d->files->selected();
539 } 539 }
540 } 540 }
541 break; 541 break;
542 case 1://audio 542 case 1://audio
543 { 543 {
544 qDebug("audioView"); 544 qDebug("audioView");
545 QListIterator<DocLnk> dit( files.children() ); 545 QListIterator<DocLnk> dit( files.children() );
546 for ( ; dit.current(); ++dit ) { 546 for ( ; dit.current(); ++dit ) {
547 if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { 547 if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) {
548 qDebug("here"); 548 qDebug("here");
549 insanityBool=TRUE; 549 insanityBool=TRUE;
550 return dit; 550 return dit;
551 } 551 }
552 } 552 }
553 } 553 }
554 break; 554 break;
555 case 2: // video 555 case 2: // video
556 { 556 {
557 qDebug("videoView"); 557 qDebug("videoView");
558 QListIterator<DocLnk> Vdit( vFiles.children() ); 558 QListIterator<DocLnk> Vdit( vFiles.children() );
559 for ( ; Vdit.current(); ++Vdit ) { 559 for ( ; Vdit.current(); ++Vdit ) {
560 if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { 560 if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) {
561 insanityBool=TRUE; 561 insanityBool=TRUE;
562 return Vdit; 562 return Vdit;
563 } 563 }
564 } 564 }
565 } 565 }
566 break; 566 break;
567 }; 567 };
568 return 0; 568 return 0;
569} 569}
570 570
571bool PlayListWidget::prev() { 571bool PlayListWidget::prev() {
572 if ( mediaPlayerState->playlist() ) { 572 if ( mediaPlayerState->playlist() ) {
573 if ( mediaPlayerState->shuffled() ) { 573 if ( mediaPlayerState->shuffled() ) {
574 const DocLnk *cur = current(); 574 const DocLnk *cur = current();
575 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 575 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
576 for ( int i = 0; i < j; i++ ) { 576 for ( int i = 0; i < j; i++ ) {
577 if ( !d->selectedFiles->next() ) 577 if ( !d->selectedFiles->next() )
578 d->selectedFiles->first(); 578 d->selectedFiles->first();
579 } 579 }
580 if ( cur == current() ) 580 if ( cur == current() )
581 if ( !d->selectedFiles->next() ) 581 if ( !d->selectedFiles->next() )
582 d->selectedFiles->first(); 582 d->selectedFiles->first();
583 return TRUE; 583 return TRUE;
584 } else { 584 } else {
585 if ( !d->selectedFiles->prev() ) { 585 if ( !d->selectedFiles->prev() ) {
586 if ( mediaPlayerState->looping() ) { 586 if ( mediaPlayerState->looping() ) {
587 return d->selectedFiles->last(); 587 return d->selectedFiles->last();
588 } else { 588 } else {
589 return FALSE; 589 return FALSE;
590 } 590 }
591 } 591 }
592 return TRUE; 592 return TRUE;
593 } 593 }
594 } else { 594 } else {
595 return mediaPlayerState->looping(); 595 return mediaPlayerState->looping();
596 } 596 }
597} 597}
598 598
599 599
600bool PlayListWidget::next() { 600bool PlayListWidget::next() {
601 if ( mediaPlayerState->playlist() ) { 601 if ( mediaPlayerState->playlist() ) {
602 if ( mediaPlayerState->shuffled() ) { 602 if ( mediaPlayerState->shuffled() ) {
603 return prev(); 603 return prev();
604 } else { 604 } else {
605 if ( !d->selectedFiles->next() ) { 605 if ( !d->selectedFiles->next() ) {
606 if ( mediaPlayerState->looping() ) { 606 if ( mediaPlayerState->looping() ) {
607 return d->selectedFiles->first(); 607 return d->selectedFiles->first();
608 } else { 608 } else {
609 return FALSE; 609 return FALSE;
610 } 610 }
611 } 611 }
612 return TRUE; 612 return TRUE;
613 } 613 }
614 } else { 614 } else {
615 return mediaPlayerState->looping(); 615 return mediaPlayerState->looping();
616 } 616 }
617} 617}
618 618
619 619
620bool PlayListWidget::first() { 620bool PlayListWidget::first() {
621 if ( mediaPlayerState->playlist() ) 621 if ( mediaPlayerState->playlist() )
622 return d->selectedFiles->first(); 622 return d->selectedFiles->first();
623 else 623 else
624 return mediaPlayerState->looping(); 624 return mediaPlayerState->looping();
625} 625}
626 626
627 627
628bool PlayListWidget::last() { 628bool PlayListWidget::last() {
629 if ( mediaPlayerState->playlist() ) 629 if ( mediaPlayerState->playlist() )
630 return d->selectedFiles->last(); 630 return d->selectedFiles->last();
631 else 631 else
632 return mediaPlayerState->looping(); 632 return mediaPlayerState->looping();
633} 633}
634 634
635 635
636void PlayListWidget::saveList() { 636void PlayListWidget::saveList() {
637 637
638 QString filename; 638 QString filename;
639 InputDialog *fileDlg; 639 InputDialog *fileDlg;
640 fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0); 640 fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0);
641 fileDlg->exec(); 641 fileDlg->exec();
642 if( fileDlg->result() == 1 ) { 642 if( fileDlg->result() == 1 ) {
643 if ( d->current ) 643 if ( d->current )
644 delete d->current; 644 delete d->current;
645 filename = fileDlg->LineEdit1->text();//+".playlist"; 645 filename = fileDlg->LineEdit1->text();//+".playlist";
646// qDebug("saving playlist "+filename+".playlist"); 646// qDebug("saving playlist "+filename+".playlist");
647 Config cfg( filename +".playlist"); 647 Config cfg( filename +".playlist");
648 writeConfig( cfg ); 648 writeConfig( cfg );
649 649
650 DocLnk lnk; 650 DocLnk lnk;
651// lnk.setComment( ""); 651// lnk.setComment( "");
652 lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property 652 lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property
653 lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D 653 lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D
654 lnk.setIcon("opieplayer/playlist2"); 654 lnk.setIcon("opieplayer/playlist2");
655 lnk.setName( filename); //sets file name 655 lnk.setName( filename); //sets file name
656// qDebug(filename); 656// qDebug(filename);
657 if(!lnk.writeLink()) 657 if(!lnk.writeLink())
658 qDebug("Writing doclink did not work"); 658 qDebug("Writing doclink did not work");
659 } 659 }
660 Config config( "OpiePlayer" ); 660 Config config( "OpiePlayer" );
661 config.writeEntry("CurrentPlaylist",filename); 661 config.writeEntry("CurrentPlaylist",filename);
662 setCaption(tr("OpiePlayer: ")+filename); 662 setCaption(tr("OpiePlayer: ")+filename);
663 d->selectedFiles->first(); 663 d->selectedFiles->first();
664 if(fileDlg) 664 if(fileDlg)
665 delete fileDlg; 665 delete fileDlg;
666} 666}
667 667
668void PlayListWidget::loadList( const DocLnk & lnk) { 668void PlayListWidget::loadList( const DocLnk & lnk) {
669 QString name= lnk.name(); 669 QString name= lnk.name();
670// qDebug("currentList is "+name); 670// qDebug("currentList is "+name);
671 if( name.length()>1) { 671 if( name.length()>1) {
672 setCaption("OpiePlayer: "+name); 672 setCaption("OpiePlayer: "+name);
673// qDebug("load list "+ name+".playlist"); 673// qDebug("load list "+ name+".playlist");
674 clearList(); 674 clearList();
675 Config cfg( name+".playlist"); 675 Config cfg( name+".playlist");
676 readConfig(cfg); 676 readConfig(cfg);
677 677
678 tabWidget->setCurrentPage(0); 678 tabWidget->setCurrentPage(0);
679 679
680 Config config( "OpiePlayer" ); 680 Config config( "OpiePlayer" );
681 config.writeEntry("CurrentPlaylist", name); 681 config.writeEntry("CurrentPlaylist", name);
682// d->selectedFiles->first(); 682// d->selectedFiles->first();
683 } 683 }
684 684
685} 685}
686 686
687void PlayListWidget::setPlaylist( bool shown ) { 687void PlayListWidget::setPlaylist( bool shown ) {
688 if ( shown ) 688 if ( shown )
689 d->playListFrame->show(); 689 d->playListFrame->show();
690 else 690 else
691 d->playListFrame->hide(); 691 d->playListFrame->hide();
692} 692}
693 693
694void PlayListWidget::setView( char view ) { 694void PlayListWidget::setView( char view ) {
695 if ( view == 'l' ) 695 if ( view == 'l' )
696 showMaximized(); 696 showMaximized();
697 else 697 else
698 hide(); 698 hide();
699} 699}
700 700
701void PlayListWidget::addSelected() { 701void PlayListWidget::addSelected() {
702 702
703 Config cfg( "OpiePlayer" ); 703 Config cfg( "OpiePlayer" );
704 cfg.setGroup("PlayList"); 704 cfg.setGroup("PlayList");
705 QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); 705 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
706 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 706 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
707 707
708 switch (tabWidget->currentPageIndex()) { 708 switch (tabWidget->currentPageIndex()) {
709 case 0: //playlist 709 case 0: //playlist
710 break; 710 break;
711 case 1: { //audio 711 case 1: { //audio
712// QString entryName; 712// QString entryName;
713// entryName.sprintf( "File%i", i + 1 ); 713// entryName.sprintf( "File%i", i + 1 );
714// QString linkFile = cfg.readEntry( entryName ); 714// QString linkFile = cfg.readEntry( entryName );
715 QListViewItemIterator it( audioView ); 715 QListViewItemIterator it( audioView );
716 // iterate through all items of the listview 716 // iterate through all items of the listview
717 for ( ; it.current(); ++it ) { 717 for ( ; it.current(); ++it ) {
718 if ( it.current()->isSelected() ) { 718 if ( it.current()->isSelected() ) {
719 QListIterator<DocLnk> dit( files.children() ); 719 QListIterator<DocLnk> dit( files.children() );
720 for ( ; dit.current(); ++dit ) { 720 for ( ; dit.current(); ++dit ) {
721 if( dit.current()->name() == it.current()->text(0) ) { 721 if( dit.current()->name() == it.current()->text(0) ) {
722 d->selectedFiles->addToSelection( **dit ); 722 d->selectedFiles->addToSelection( **dit );
723 } 723 }
724 } 724 }
725 audioView->setSelected( it.current(),FALSE); 725 audioView->setSelected( it.current(),FALSE);
726 } 726 }
727 } 727 }
728 tabWidget->setCurrentPage(0); 728 tabWidget->setCurrentPage(0);
729 } 729 }
730 break; 730 break;
731 case 2: { // video 731 case 2: { // video
732 QListViewItemIterator it( videoView ); 732 QListViewItemIterator it( videoView );
733 // iterate through all items of the listview 733 // iterate through all items of the listview
734 for ( ; it.current(); ++it ) { 734 for ( ; it.current(); ++it ) {
735 if ( it.current()->isSelected() ) { 735 if ( it.current()->isSelected() ) {
736 QListIterator<DocLnk> dit( vFiles.children() ); 736 QListIterator<DocLnk> dit( vFiles.children() );
737 for ( ; dit.current(); ++dit ) { 737 for ( ; dit.current(); ++dit ) {
738 if( dit.current()->name() == it.current()->text(0) ) { 738 if( dit.current()->name() == it.current()->text(0) ) {
739 d->selectedFiles->addToSelection( **dit ); 739 d->selectedFiles->addToSelection( **dit );
740 } 740 }
741 } 741 }
742 742
743 videoView->setSelected( it.current(),FALSE); 743 videoView->setSelected( it.current(),FALSE);
744 } 744 }
745 } 745 }
746// for ( int i = 0; i < noOfFiles; i++ ) { 746// for ( int i = 0; i < noOfFiles; i++ ) {
747// QString entryName; 747// QString entryName;
748// entryName.sprintf( "File%i", i + 1 ); 748// entryName.sprintf( "File%i", i + 1 );
749// QString linkFile = cfg.readEntry( entryName ); 749// QString linkFile = cfg.readEntry( entryName );
750// if( DocLnk( linkFile).name() == videoView->selectedItem()->text(0) ) { 750// if( DocLnk( linkFile).name() == videoView->selectedItem()->text(0) ) {
751// int result= QMessageBox::warning(this,tr("OpiePlayer"), 751// int result= QMessageBox::warning(this,tr("OpiePlayer"),
752// tr("This is all ready in your playlist.\nContinue?"), 752// tr("This is all ready in your playlist.\nContinue?"),
753// tr("Yes"),tr("No"),0,0,1); 753// tr("Yes"),tr("No"),0,0,1);
754// if (result !=0) 754// if (result !=0)
755// return; 755// return;
756// } 756// }
757// } 757// }
758// addToSelection( videoView->selectedItem() ); 758// addToSelection( videoView->selectedItem() );
759 tabWidget->setCurrentPage(0); 759 tabWidget->setCurrentPage(0);
760 } 760 }
761 break; 761 break;
762 }; 762 };
763} 763}
764 764
765void PlayListWidget::removeSelected() { 765void PlayListWidget::removeSelected() {
766 d->selectedFiles->removeSelected( ); 766 d->selectedFiles->removeSelected( );
767} 767}
768 768
769void PlayListWidget::playIt( QListViewItem *it) { 769void PlayListWidget::playIt( QListViewItem *it) {
770// d->setDocumentUsed = FALSE; 770// d->setDocumentUsed = FALSE;
771// mediaPlayerState->curPosition =0; 771// mediaPlayerState->curPosition =0;
772 qDebug("playIt"); 772 qDebug("playIt");
773 mediaPlayerState->setPlaying(FALSE); 773 mediaPlayerState->setPlaying(FALSE);
774 mediaPlayerState->setPlaying(TRUE); 774 mediaPlayerState->setPlaying(TRUE);
775 d->selectedFiles->unSelect(); 775 d->selectedFiles->unSelect();
776} 776}
777 777
778void PlayListWidget::addToSelection( QListViewItem *it) { 778void PlayListWidget::addToSelection( QListViewItem *it) {
779 d->setDocumentUsed = FALSE; 779 d->setDocumentUsed = FALSE;
780 780
781 if(it) { 781 if(it) {
782 switch (tabWidget->currentPageIndex()) { 782 switch (tabWidget->currentPageIndex()) {
783 case 1: { 783 case 1: {
784 QListIterator<DocLnk> dit( files.children() ); 784 QListIterator<DocLnk> dit( files.children() );
785 for ( ; dit.current(); ++dit ) { 785 for ( ; dit.current(); ++dit ) {
786 if( dit.current()->name() == it->text(0)) { 786 if( dit.current()->name() == it->text(0)) {
787 d->selectedFiles->addToSelection( **dit ); 787 d->selectedFiles->addToSelection( **dit );
788 } 788 }
789 } 789 }
790 } 790 }
791 break; 791 break;
792 case 2: { 792 case 2: {
793 QListIterator<DocLnk> dit( vFiles.children() ); 793 QListIterator<DocLnk> dit( vFiles.children() );
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
808void PlayListWidget::tabChanged(QWidget *widg) { 808void 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
850void PlayListWidget::btnPlay(bool b) { 850void 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
889void PlayListWidget::deletePlaylist() { 889void 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
903void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) 903void 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
923void PlayListWidget::playSelected() 923void PlayListWidget::playSelected()
924{ 924{
925 btnPlay( TRUE); 925 btnPlay( TRUE);
926// d->selectedFiles->unSelect(); 926// d->selectedFiles->unSelect();
927} 927}
928 928
929void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) 929void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *item, const QPoint& point, int i)
930{ 930{
931 switch (mouse) { 931 switch (mouse) {
932 case 1: 932 case 1:
933 933
934 break; 934 break;
935 case 2:{ 935 case 2:{
936 QPopupMenu m; 936 QPopupMenu m;
937 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); 937 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() ));
938 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); 938 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
939// m.insertSeparator(); 939// m.insertSeparator();
940// m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); 940// m.insertItem( tr( "Properties" ), this, SLOT( listDelete() ));
941 m.exec( QCursor::pos() ); 941 m.exec( QCursor::pos() );
942 } 942 }
943 break; 943 break;
944 }; 944 };
945 945
946} 946}
947 947
948void PlayListWidget::listDelete() { 948void PlayListWidget::listDelete() {
949 Config cfg( "OpiePlayer" ); 949 Config cfg( "OpiePlayer" );
950 cfg.setGroup("PlayList"); 950 cfg.setGroup("PlayList");
951 QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); 951 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
952 QString file; 952 QString file;
953 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 953 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
954 switch ( tabWidget->currentPageIndex()) { 954 switch ( tabWidget->currentPageIndex()) {
955 case 0: 955 case 0:
956 break; 956 break;
957 case 1: 957 case 1:
958 { 958 {
959 file = audioView->selectedItem()->text(0); 959 file = audioView->selectedItem()->text(0);
960// Global::findDocuments(&files, "audio/*"); 960// Global::findDocuments(&files, "audio/*");
961// AppLnkSet appFiles; 961// AppLnkSet appFiles;
962 QListIterator<DocLnk> dit( files.children() ); 962 QListIterator<DocLnk> dit( files.children() );
963 for ( ; dit.current(); ++dit ) { 963 for ( ; dit.current(); ++dit ) {
964 if( dit.current()->name() == file) { 964 if( dit.current()->name() == file) {
965// qDebug(file); 965// qDebug(file);
966 LnkProperties prop( dit.current() ); 966 LnkProperties prop( dit.current() );
967// connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); 967// connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *)));
968 prop.showMaximized(); 968 prop.showMaximized();
969 prop.exec(); 969 prop.exec();
970 } 970 }
971 } 971 }
972 populateAudioView(); 972 populateAudioView();
973 } 973 }
974 break; 974 break;
975 case 2: 975 case 2:
976 { 976 {
977// file = videoView->selectedItem()->text(0); 977// file = videoView->selectedItem()->text(0);
978// for ( int i = 0; i < noOfFiles; i++ ) { 978// for ( int i = 0; i < noOfFiles; i++ ) {
979// QString entryName; 979// QString entryName;
980// entryName.sprintf( "File%i", i + 1 ); 980// entryName.sprintf( "File%i", i + 1 );
981// QString linkFile = cfg.readEntry( entryName ); 981// QString linkFile = cfg.readEntry( entryName );
982// AppLnk lnk( AppLnk(linkFile)); 982// AppLnk lnk( AppLnk(linkFile));
983// if( lnk.name() == file ) { 983// if( lnk.name() == file ) {
984// LnkProperties prop( &lnk); 984// LnkProperties prop( &lnk);
985// // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); 985// // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *)));
986// prop.showMaximized(); 986// prop.showMaximized();
987// prop.exec(); 987// prop.exec();
988// } 988// }
989// } 989// }
990 } 990 }
991 break; 991 break;
992 }; 992 };
993} 993}
994 994
995void PlayListWidget::scanForAudio() { 995void PlayListWidget::scanForAudio() {
996 qDebug("scan for audio"); 996 qDebug("scan for audio");
997 files.detachChildren(); 997 files.detachChildren();
998 QListIterator<DocLnk> sdit( files.children() ); 998 QListIterator<DocLnk> sdit( files.children() );
999 for ( ; sdit.current(); ++sdit ) { 999 for ( ; sdit.current(); ++sdit ) {
1000 delete sdit.current(); 1000 delete sdit.current();
1001 } 1001 }
1002 Global::findDocuments(&files, "audio/*"); 1002 Global::findDocuments(&files, "audio/*");
1003 audioScan = TRUE; 1003 audioScan = TRUE;
1004} 1004}
1005void PlayListWidget::scanForVideo() { 1005void PlayListWidget::scanForVideo() {
1006 qDebug("scan for video"); 1006 qDebug("scan for video");
1007 vFiles.detachChildren(); 1007 vFiles.detachChildren();
1008 QListIterator<DocLnk> sdit( vFiles.children() ); 1008 QListIterator<DocLnk> sdit( vFiles.children() );
1009 for ( ; sdit.current(); ++sdit ) { 1009 for ( ; sdit.current(); ++sdit ) {
1010 delete sdit.current(); 1010 delete sdit.current();
1011 } 1011 }
1012 Global::findDocuments(&vFiles, "video/*"); 1012 Global::findDocuments(&vFiles, "video/*");
1013 videoScan = TRUE; 1013 videoScan = TRUE;
1014} 1014}
1015 1015
1016void PlayListWidget::populateAudioView() { 1016void PlayListWidget::populateAudioView() {
1017 1017
1018 audioView->clear(); 1018 audioView->clear();
1019 StorageInfo storageInfo; 1019 StorageInfo storageInfo;
1020 const QList<FileSystem> &fs = storageInfo.fileSystems(); 1020 const QList<FileSystem> &fs = storageInfo.fileSystems();
1021 if(!audioScan) scanForAudio(); 1021 if(!audioScan) scanForAudio();
1022 1022
1023 QListIterator<DocLnk> dit( files.children() ); 1023 QListIterator<DocLnk> dit( files.children() );
1024 QListIterator<FileSystem> it ( fs ); 1024 QListIterator<FileSystem> it ( fs );
1025 1025
1026 QString storage; 1026 QString storage;
1027 for ( ; dit.current(); ++dit ) { 1027 for ( ; dit.current(); ++dit ) {
1028 for( ; it.current(); ++it ){ 1028 for( ; it.current(); ++it ){
1029 const QString name = (*it)->name(); 1029 const QString name = (*it)->name();
1030 const QString path = (*it)->path(); 1030 const QString path = (*it)->path();
1031 if(dit.current()->file().find(path) != -1 ) storage=name; 1031 if(dit.current()->file().find(path) != -1 ) storage=name;
1032 } 1032 }
1033 1033
1034 QListViewItem * newItem; 1034 QListViewItem * newItem;
1035 if ( QFile( dit.current()->file()).exists() ) { 1035 if ( QFile( dit.current()->file()).exists() ) {
1036// qDebug(dit.current()->name()); 1036// qDebug(dit.current()->name());
1037 newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), 1037 newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(),
1038 QString::number( QFile( dit.current()->file()).size() ), storage); 1038 QString::number( QFile( dit.current()->file()).size() ), storage);
1039 newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); 1039 newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" ));
1040 } 1040 }
1041 } 1041 }
1042 1042
1043} 1043}
1044 1044
1045void PlayListWidget::populateVideoView() { 1045void PlayListWidget::populateVideoView() {
1046 videoView->clear(); 1046 videoView->clear();
1047 StorageInfo storageInfo; 1047 StorageInfo storageInfo;
1048 const QList<FileSystem> &fs = storageInfo.fileSystems(); 1048 const QList<FileSystem> &fs = storageInfo.fileSystems();
1049 1049
1050 if(!videoScan ) scanForVideo(); 1050 if(!videoScan ) scanForVideo();
1051 1051
1052 QListIterator<DocLnk> Vdit( vFiles.children() ); 1052 QListIterator<DocLnk> Vdit( vFiles.children() );
1053 QListIterator<FileSystem> it ( fs ); 1053 QListIterator<FileSystem> it ( fs );
1054 videoView->clear(); 1054 videoView->clear();
1055 QString storage; 1055 QString storage;
1056 for ( ; Vdit.current(); ++Vdit ) { 1056 for ( ; Vdit.current(); ++Vdit ) {
1057 for( ; it.current(); ++it ){ 1057 for( ; it.current(); ++it ){
1058 const QString name = (*it)->name(); 1058 const QString name = (*it)->name();
1059 const QString path = (*it)->path(); 1059 const QString path = (*it)->path();
1060 if( Vdit.current()->file().find(path) != -1 ) storage=name; 1060 if( Vdit.current()->file().find(path) != -1 ) storage=name;
1061 } 1061 }
1062 1062
1063 QListViewItem * newItem; 1063 QListViewItem * newItem;
1064 if ( QFile( Vdit.current()->file()).exists() ) { 1064 if ( QFile( Vdit.current()->file()).exists() ) {
1065 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), 1065 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(),
1066 QString::number( QFile( Vdit.current()->file()).size() ), storage); 1066 QString::number( QFile( Vdit.current()->file()).size() ), storage);
1067 newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); 1067 newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" ));
1068 } 1068 }
1069 } 1069 }
1070} 1070}
1071 1071
1072void PlayListWidget::openFile() { 1072void PlayListWidget::openFile() {
1073 QString filename, name; 1073 QString filename, name;
1074 InputDialog *fileDlg; 1074 InputDialog *fileDlg;
1075 fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); 1075 fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0);
1076 fileDlg->exec(); 1076 fileDlg->exec();
1077 if( fileDlg->result() == 1 ) { 1077 if( fileDlg->result() == 1 ) {
1078 filename = fileDlg->LineEdit1->text(); 1078 filename = fileDlg->LineEdit1->text();
1079// http://205.188.234.129:8030 1079// http://205.188.234.129:8030
1080// http://66.28.68.70:8000 1080// http://66.28.68.70:8000
1081// filename.replace(QRegExp("%20")," "); 1081// filename.replace(QRegExp("%20")," ");
1082 if(filename.find(" ",0,TRUE) != -1 || filename.find("%20",0,TRUE) != -1) { 1082 if(filename.find(" ",0,TRUE) != -1 || filename.find("%20",0,TRUE) != -1) {
1083 QMessageBox::message("Note","Spaces in urls are not allowed."); 1083 QMessageBox::message("Note","Spaces in urls are not allowed.");
1084 return; 1084 return;
1085 } else { 1085 } else {
1086 qDebug("Selected filename is "+filename); 1086 qDebug("Selected filename is "+filename);
1087 if(filename.right(3) == "m3u") 1087 if(filename.right(3) == "m3u")
1088 readm3u( filename); 1088 readm3u( filename);
1089 else if(filename.right(3) == "pls") 1089 else if(filename.right(3) == "pls")
1090 readPls( filename); 1090 readPls( filename);
1091 else { 1091 else {
1092 DocLnk lnk; 1092 DocLnk lnk;
1093 1093
1094 lnk.setName(filename); //sets file name 1094 lnk.setName(filename); //sets file name
1095 if(filename.right(1) != "/" && filename.right(3) != "mp3" && filename.right(3) != "MP3") 1095 if(filename.right(1) != "/" && filename.right(3) != "mp3" && filename.right(3) != "MP3")
1096 filename += "/"; 1096 filename += "/";
1097 lnk.setFile(filename); //sets File property 1097 lnk.setFile(filename); //sets File property
1098 1098
1099 lnk.setType("audio/x-mpegurl"); 1099 lnk.setType("audio/x-mpegurl");
1100 lnk.setExec("opieplayer"); 1100 lnk.setExec("opieplayer");
1101 lnk.setIcon("opieplayer/MPEGPlayer"); 1101 lnk.setIcon("opieplayer/MPEGPlayer");
1102 1102
1103 if(!lnk.writeLink()) 1103 if(!lnk.writeLink())
1104 qDebug("Writing doclink did not work"); 1104 qDebug("Writing doclink did not work");
1105 d->selectedFiles->addToSelection( lnk); 1105 d->selectedFiles->addToSelection( lnk);
1106// if(fileDlg2) 1106// if(fileDlg2)
1107// delete fileDlg2; 1107// delete fileDlg2;
1108 } 1108 }
1109 } 1109 }
1110 } 1110 }
1111 if(fileDlg) 1111 if(fileDlg)
1112 delete fileDlg; 1112 delete fileDlg;
1113} 1113}
1114 1114
1115void PlayListWidget::keyReleaseEvent( QKeyEvent *e) 1115void PlayListWidget::keyReleaseEvent( QKeyEvent *e)
1116{ 1116{
1117 switch ( e->key() ) { 1117 switch ( e->key() ) {
1118////////////////////////////// Zaurus keys 1118////////////////////////////// Zaurus keys
1119 case Key_F9: //activity 1119 case Key_F9: //activity
1120// if(audioUI->isHidden()) 1120// if(audioUI->isHidden())
1121// audioUI->showMaximized(); 1121// audioUI->showMaximized();
1122 break; 1122 break;
1123 case Key_F10: //contacts 1123 case Key_F10: //contacts
1124// if( videoUI->isHidden()) 1124// if( videoUI->isHidden())
1125// videoUI->showMaximized(); 1125// videoUI->showMaximized();
1126 break; 1126 break;
1127 case Key_F11: //menu 1127 case Key_F11: //menu
1128 break; 1128 break;
1129 case Key_F12: //home 1129 case Key_F12: //home
1130// doBlank(); 1130// doBlank();
1131 break; 1131 break;
1132 case Key_F13: //mail 1132 case Key_F13: //mail
1133// doUnblank(); 1133// doUnblank();
1134 break; 1134 break;
1135 case Key_Q: //add to playlist 1135 case Key_Q: //add to playlist
1136 qDebug("Add"); 1136 qDebug("Add");
1137 addSelected(); 1137 addSelected();
1138 break; 1138 break;
1139 case Key_R: //remove from playlist 1139 case Key_R: //remove from playlist
1140 removeSelected(); 1140 removeSelected();
1141 break; 1141 break;
1142// case Key_P: //play 1142// case Key_P: //play
1143// qDebug("Play"); 1143// qDebug("Play");
1144// playSelected(); 1144// playSelected();
1145// break; 1145// break;
1146 case Key_Space: 1146 case Key_Space:
1147 qDebug("Play"); 1147 qDebug("Play");
1148// playSelected(); puh 1148// playSelected(); puh
1149 break; 1149 break;
1150 case Key_1: 1150 case Key_1:
1151 tabWidget->setCurrentPage(0); 1151 tabWidget->setCurrentPage(0);
1152 break; 1152 break;
1153 case Key_2: 1153 case Key_2:
1154 tabWidget->setCurrentPage(1); 1154 tabWidget->setCurrentPage(1);
1155 break; 1155 break;
1156 case Key_3: 1156 case Key_3:
1157 tabWidget->setCurrentPage(2); 1157 tabWidget->setCurrentPage(2);
1158 break; 1158 break;
1159 case Key_4: 1159 case Key_4:
1160 tabWidget->setCurrentPage(3); 1160 tabWidget->setCurrentPage(3);
1161 break; 1161 break;
1162 } 1162 }
1163} 1163}
1164 1164
1165void PlayListWidget::keyPressEvent( QKeyEvent *e) 1165void PlayListWidget::keyPressEvent( QKeyEvent *e)
1166{ 1166{
1167// qDebug("Key press"); 1167// qDebug("Key press");
1168// switch ( e->key() ) { 1168// switch ( e->key() ) {
1169// ////////////////////////////// Zaurus keys 1169// ////////////////////////////// Zaurus keys
1170// case Key_A: //add to playlist 1170// case Key_A: //add to playlist
1171// qDebug("Add"); 1171// qDebug("Add");
1172// addSelected(); 1172// addSelected();
1173// break; 1173// break;
1174// case Key_R: //remove from playlist 1174// case Key_R: //remove from playlist
1175// removeSelected(); 1175// removeSelected();
1176// break; 1176// break;
1177// case Key_P: //play 1177// case Key_P: //play
1178// qDebug("Play"); 1178// qDebug("Play");
1179// playSelected(); 1179// playSelected();
1180// break; 1180// break;
1181// case Key_Space: 1181// case Key_Space:
1182// qDebug("Play"); 1182// qDebug("Play");
1183// playSelected(); 1183// playSelected();
1184// break; 1184// break;
1185// } 1185// }
1186} 1186}
1187 1187
1188void PlayListWidget::doBlank() { 1188void PlayListWidget::doBlank() {
1189 qDebug("do blanking"); 1189 qDebug("do blanking");
1190 fd=open("/dev/fb0",O_RDWR); 1190 fd=open("/dev/fb0",O_RDWR);
1191 if (fd != -1) { 1191 if (fd != -1) {
1192 ioctl(fd,FBIOBLANK,1); 1192 ioctl(fd,FBIOBLANK,1);
1193// close(fd); 1193// close(fd);
1194 } 1194 }
1195} 1195}
1196 1196
1197void PlayListWidget::doUnblank() { 1197void PlayListWidget::doUnblank() {
1198 // this crashes opieplayer with a segfault 1198 // this crashes opieplayer with a segfault
1199// int fd; 1199// int fd;
1200// fd=open("/dev/fb0",O_RDWR); 1200// fd=open("/dev/fb0",O_RDWR);
1201 qDebug("do unblanking"); 1201 qDebug("do unblanking");
1202 if (fd != -1) { 1202 if (fd != -1) {
1203 ioctl(fd,FBIOBLANK,0); 1203 ioctl(fd,FBIOBLANK,0);
1204 close(fd); 1204 close(fd);
1205 } 1205 }
1206 QCopEnvelope h("QPE/System", "setBacklight(int)"); 1206 QCopEnvelope h("QPE/System", "setBacklight(int)");
1207 h <<-3;// v[1]; // -3 Force on 1207 h <<-3;// v[1]; // -3 Force on
1208} 1208}
1209 1209
1210void PlayListWidget::readm3u(const QString &filename) { 1210void PlayListWidget::readm3u(const QString &filename) {
1211 1211
1212 qDebug("m3u filename is "+filename); 1212 qDebug("m3u filename is "+filename);
1213 QFile f(filename); 1213 QFile f(filename);
1214 1214
1215 if(f.open(IO_ReadOnly)) { 1215 if(f.open(IO_ReadOnly)) {
1216 QTextStream t(&f); 1216 QTextStream t(&f);
1217 QString s;//, first, second; 1217 QString s;//, first, second;
1218 int i=0; 1218 int i=0;
1219 while ( !t.atEnd()) { 1219 while ( !t.atEnd()) {
1220// Lview->insertLine(t.readLine(),-1); 1220// Lview->insertLine(t.readLine(),-1);
1221 s=t.readLine(); 1221 s=t.readLine();
1222 if(s.find(" ",0,TRUE) != -1 || s.find("%20",0,TRUE) != -1) { 1222 if(s.find(" ",0,TRUE) != -1 || s.find("%20",0,TRUE) != -1) {
1223 QMessageBox::message("Note","Spaces in urls are not allowed."); 1223 QMessageBox::message("Note","Spaces in urls are not allowed.");
1224 } 1224 }
1225 else if(s.find("#",0,TRUE) == -1) { 1225 else if(s.find("#",0,TRUE) == -1) {
1226 if(s.find(" ",0,TRUE) == -1) { // not sure if this is neede since cf uses vfat 1226 if(s.find(" ",0,TRUE) == -1) { // not sure if this is neede since cf uses vfat
1227 if(s.left(2) == "E:" || s.left(2) == "P:") { 1227 if(s.left(2) == "E:" || s.left(2) == "P:") {
1228 s=s.right(s.length()-2); 1228 s=s.right(s.length()-2);
1229 DocLnk lnk( s ); 1229 DocLnk lnk( s );
1230 QFileInfo f(s); 1230 QFileInfo f(s);
1231 QString name = f.baseName(); 1231 QString name = f.baseName();
1232 name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1); 1232 name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1);
1233 lnk.setName( name); 1233 lnk.setName( name);
1234 s=s.replace( QRegExp("\\"),"/"); 1234 s=s.replace( QRegExp("\\"),"/");
1235 lnk.setFile( s); 1235 lnk.setFile( s);
1236 lnk.writeLink(); 1236 lnk.writeLink();
1237// lnk.setIcon(opieplayer/MPEGPlayer); 1237// lnk.setIcon(opieplayer/MPEGPlayer);
1238 qDebug("add "+name); 1238 qDebug("add "+name);
1239 d->selectedFiles->addToSelection( lnk); 1239 d->selectedFiles->addToSelection( lnk);
1240 } else { // is url 1240 } else { // is url
1241 1241
1242 s.replace(QRegExp("%20")," "); 1242 s.replace(QRegExp("%20")," ");
1243 DocLnk lnk( s); 1243 DocLnk lnk( s);
1244 QString name; 1244 QString name;
1245 if(name.left(4)=="http") 1245 if(name.left(4)=="http")
1246 name = s.right( s.length() - 7); 1246 name = s.right( s.length() - 7);
1247 else 1247 else
1248 name=s; 1248 name=s;
1249// name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1); 1249// name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1);
1250 lnk.setName(name); 1250 lnk.setName(name);
1251 if(s.at(s.length()-4) == '.') 1251 if(s.at(s.length()-4) == '.')
1252 lnk.setFile( s); 1252 lnk.setFile( s);
1253 else 1253 else
1254 lnk.setFile( s+"/"); 1254 lnk.setFile( s+"/");
1255// lnk.setFile( filename); 1255// lnk.setFile( filename);
1256// lnk.setComment( s+"/"); 1256// lnk.setComment( s+"/");
1257 lnk.setType("audio/x-mpegurl"); 1257 lnk.setType("audio/x-mpegurl");
1258 lnk.writeLink(); 1258 lnk.writeLink();
1259// lnk.setIcon( "opieplayer/MPEGPlayer"); 1259// lnk.setIcon( "opieplayer/MPEGPlayer");
1260// qDebug("add "+s); 1260// qDebug("add "+s);
1261 d->selectedFiles->addToSelection( lnk); 1261 d->selectedFiles->addToSelection( lnk);
1262 } 1262 }
1263 i++; 1263 i++;
1264 } 1264 }
1265 } 1265 }
1266 } 1266 }
1267 } 1267 }
1268 f.close(); 1268 f.close();
1269} 1269}
1270 1270
1271void PlayListWidget::writem3u() { 1271void PlayListWidget::writem3u() {
1272 1272
1273 InputDialog *fileDlg; 1273 InputDialog *fileDlg;
1274 fileDlg = new InputDialog(this,tr("Save m3u Playlist "),TRUE, 0); 1274 fileDlg = new InputDialog(this,tr("Save m3u Playlist "),TRUE, 0);
1275 fileDlg->exec(); 1275 fileDlg->exec();
1276 QString filename,list; 1276 QString filename,list;
1277 if( fileDlg->result() == 1 ) { 1277 if( fileDlg->result() == 1 ) {
1278 filename = fileDlg->LineEdit1->text(); 1278 filename = fileDlg->LineEdit1->text();
1279 qDebug(filename); 1279 qDebug(filename);
1280 int noOfFiles = 0; 1280 int noOfFiles = 0;
1281 d->selectedFiles->first(); 1281 d->selectedFiles->first();
1282 do { 1282 do {
1283// we dont check for existance because of url's 1283// we dont check for existance because of url's
1284// qDebug(d->selectedFiles->current()->file()); 1284// qDebug(d->selectedFiles->current()->file());
1285 list += d->selectedFiles->current()->file()+"\n"; 1285 list += d->selectedFiles->current()->file()+"\n";
1286 noOfFiles++; 1286 noOfFiles++;
1287 } 1287 }
1288 while ( d->selectedFiles->next() ); 1288 while ( d->selectedFiles->next() );
1289 qDebug(list); 1289 qDebug(list);
1290 if(filename.left(1) != "/") 1290 if(filename.left(1) != "/")
1291 filename=QPEApplication::documentDir()+"/"+filename; 1291 filename=QPEApplication::documentDir()+"/"+filename;
1292 if(filename.right(3) != "m3u") 1292 if(filename.right(3) != "m3u")
1293 filename=filename+".m3u"; 1293 filename=filename+".m3u";
1294 1294
1295 QFile f(filename); 1295 QFile f(filename);
1296 f.open(IO_WriteOnly); 1296 f.open(IO_WriteOnly);
1297 f.writeBlock(list, list.length()); 1297 f.writeBlock(list, list.length());
1298 f.close(); 1298 f.close();
1299 } 1299 }
1300 if(fileDlg) delete fileDlg; 1300 if(fileDlg) delete fileDlg;
1301} 1301}
1302 1302
1303void PlayListWidget::readPls(const QString &filename) { 1303void PlayListWidget::readPls(const QString &filename) {
1304 1304
1305 qDebug("pls filename is "+filename); 1305 qDebug("pls filename is "+filename);
1306 QFile f(filename); 1306 QFile f(filename);
1307 1307
1308 if(f.open(IO_ReadOnly)) { 1308 if(f.open(IO_ReadOnly)) {
1309 QTextStream t(&f); 1309 QTextStream t(&f);
1310 QString s;//, first, second; 1310 QString s;//, first, second;
1311 int i=0; 1311 int i=0;
1312 while ( !t.atEnd()) { 1312 while ( !t.atEnd()) {
1313 s=t.readLine(); 1313 s=t.readLine();
1314 if(s.left(4) == "File") { 1314 if(s.left(4) == "File") {
1315 s=s.right(s.length() - 6); 1315 s=s.right(s.length() - 6);
1316 s.replace(QRegExp("%20")," "); 1316 s.replace(QRegExp("%20")," ");
1317 qDebug("adding "+s+" to playlist"); 1317 qDebug("adding "+s+" to playlist");
1318// numberofentries=2 1318// numberofentries=2
1319// File1=http 1319// File1=http
1320// Title 1320// Title
1321// Length 1321// Length
1322// Version 1322// Version
1323// File2=http 1323// File2=http
1324 1324
1325 s=s.replace( QRegExp("\\"),"/"); 1325 s=s.replace( QRegExp("\\"),"/");
1326 DocLnk lnk( s ); 1326 DocLnk lnk( s );
1327 QFileInfo f(s); 1327 QFileInfo f(s);
1328 QString name = f.baseName(); 1328 QString name = f.baseName();
1329 if(name.left(4)=="http") 1329 if(name.left(4)=="http")
1330 name = s.right( s.length() - 7); 1330 name = s.right( s.length() - 7);
1331 else 1331 else
1332 name=s; 1332 name=s;
1333 name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1); 1333 name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1);
1334// QFileInfo f(s); 1334// QFileInfo f(s);
1335// QString name = f.baseName(); 1335// QString name = f.baseName();
1336// name = name.left(name.length()-4); 1336// name = name.left(name.length()-4);
1337// name = name.right(name.findRev("/",0,TRUE)); 1337// name = name.right(name.findRev("/",0,TRUE));
1338 lnk.setName( name); 1338 lnk.setName( name);
1339 if(s.at(s.length()-4) == '.') 1339 if(s.at(s.length()-4) == '.')
1340 lnk.setFile( s); 1340 lnk.setFile( s);
1341 else 1341 else {
1342 lnk.setFile( s+"/"); 1342 if( name.right(1).find('/') == -1)
1343 s+="/";
1344 // if(s.right(1) != '/')
1345 lnk.setFile( s);
1346
1347 }
1343 lnk.setType("audio/x-mpegurl"); 1348 lnk.setType("audio/x-mpegurl");
1344 1349
1345 qDebug("DocLnk add "+name); 1350 qDebug("DocLnk add "+name);
1346 d->selectedFiles->addToSelection( lnk); 1351 d->selectedFiles->addToSelection( lnk);
1347 } 1352 }
1348 } 1353 }
1349 i++; 1354 i++;
1350 } 1355 }
1351} 1356}
1352 1357