-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 8 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 11 |
2 files changed, 11 insertions, 8 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp index 136e06c..73e41dc 100644 --- a/core/multimedia/opieplayer/audiodevice.cpp +++ b/core/multimedia/opieplayer/audiodevice.cpp | |||
@@ -1,313 +1,313 @@ | |||
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 | #if defined(Q_WS_X11) || defined(Q_WS_QWS) | 38 | #if defined(Q_WS_X11) || defined(Q_WS_QWS) |
39 | #include <fcntl.h> | 39 | #include <fcntl.h> |
40 | #include <sys/ioctl.h> | 40 | #include <sys/ioctl.h> |
41 | #include <sys/soundcard.h> | 41 | #include <sys/soundcard.h> |
42 | #include <sys/stat.h> | 42 | #include <sys/stat.h> |
43 | #include <sys/time.h> | 43 | #include <sys/time.h> |
44 | #include <sys/types.h> | 44 | #include <sys/types.h> |
45 | #include <unistd.h> | 45 | #include <unistd.h> |
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | # if defined(QT_QWS_IPAQ) | 48 | # if defined(QT_QWS_IPAQ) |
49 | static const int sound_fragment_shift = 14; | 49 | static const int sound_fragment_shift = 14; |
50 | # else | 50 | # else |
51 | static const int sound_fragment_shift = 16; | 51 | static const int sound_fragment_shift = 16; |
52 | # endif | 52 | # endif |
53 | static const int sound_fragment_bytes = (1<<sound_fragment_shift); | 53 | static const int sound_fragment_bytes = (1<<sound_fragment_shift); |
54 | //#endif | 54 | //#endif |
55 | 55 | ||
56 | 56 | ||
57 | class AudioDevicePrivate { | 57 | class AudioDevicePrivate { |
58 | public: | 58 | public: |
59 | int handle; | 59 | int handle; |
60 | unsigned int frequency; | 60 | unsigned int frequency; |
61 | unsigned int channels; | 61 | unsigned int channels; |
62 | unsigned int bytesPerSample; | 62 | unsigned int bytesPerSample; |
63 | unsigned int bufferSize; | 63 | unsigned int bufferSize; |
64 | //#ifndef Q_OS_WIN32 | 64 | //#ifndef Q_OS_WIN32 |
65 | bool can_GETOSPACE; | 65 | bool can_GETOSPACE; |
66 | char* unwrittenBuffer; | 66 | char* unwrittenBuffer; |
67 | unsigned int unwritten; | 67 | unsigned int unwritten; |
68 | //#endif | 68 | //#endif |
69 | 69 | ||
70 | static int dspFd; | 70 | static int dspFd; |
71 | static bool muted; | 71 | static bool muted; |
72 | static unsigned int leftVolume; | 72 | static unsigned int leftVolume; |
73 | static unsigned int rightVolume; | 73 | static unsigned int rightVolume; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | 76 | ||
77 | #ifdef Q_WS_QWS | 77 | #ifdef Q_WS_QWS |
78 | // This is for keeping the device open in-between playing files when | 78 | // This is for keeping the device open in-between playing files when |
79 | // the device makes clicks and it starts to drive you insane! :) | 79 | // the device makes clicks and it starts to drive you insane! :) |
80 | // Best to have the device not open when not using it though | 80 | // Best to have the device not open when not using it though |
81 | //#define KEEP_DEVICE_OPEN | 81 | //#define KEEP_DEVICE_OPEN |
82 | #endif | 82 | #endif |
83 | 83 | ||
84 | 84 | ||
85 | int AudioDevicePrivate::dspFd = 0; | 85 | int AudioDevicePrivate::dspFd = 0; |
86 | bool AudioDevicePrivate::muted = FALSE; | 86 | bool AudioDevicePrivate::muted = FALSE; |
87 | unsigned int AudioDevicePrivate::leftVolume = 0; | 87 | unsigned int AudioDevicePrivate::leftVolume = 0; |
88 | unsigned int AudioDevicePrivate::rightVolume = 0; | 88 | unsigned int AudioDevicePrivate::rightVolume = 0; |
89 | 89 | ||
90 | 90 | ||
91 | void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { | 91 | void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { |
92 | muted = AudioDevicePrivate::muted; | 92 | muted = AudioDevicePrivate::muted; |
93 | unsigned int volume; | 93 | unsigned int volume; |
94 | int mixerHandle = open( "/dev/mixer", O_RDWR ); | 94 | int mixerHandle = open( "/dev/mixer", O_RDWR ); |
95 | if ( mixerHandle >= 0 ) { | 95 | if ( mixerHandle >= 0 ) { |
96 | if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) | 96 | if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) |
97 | perror("ioctl(\"MIXER_READ\")"); | 97 | perror("ioctl(\"MIXER_READ\")"); |
98 | close( mixerHandle ); | 98 | close( mixerHandle ); |
99 | } else | 99 | } else |
100 | perror("open(\"/dev/mixer\")"); | 100 | perror("open(\"/dev/mixer\")"); |
101 | leftVolume = ((volume & 0x00FF) << 16) / 101; | 101 | leftVolume = ((volume & 0x00FF) << 16) / 101; |
102 | rightVolume = ((volume & 0xFF00) << 8) / 101; | 102 | rightVolume = ((volume & 0xFF00) << 8) / 101; |
103 | } | 103 | } |
104 | 104 | ||
105 | 105 | ||
106 | void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { | 106 | void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { |
107 | AudioDevicePrivate::muted = muted; | 107 | AudioDevicePrivate::muted = muted; |
108 | if ( muted ) { | 108 | if ( muted ) { |
109 | AudioDevicePrivate::leftVolume = leftVolume; | 109 | AudioDevicePrivate::leftVolume = leftVolume; |
110 | AudioDevicePrivate::rightVolume = rightVolume; | 110 | AudioDevicePrivate::rightVolume = rightVolume; |
111 | leftVolume = 0; | 111 | leftVolume = 0; |
112 | rightVolume = 0; | 112 | rightVolume = 0; |
113 | } else { | 113 | } else { |
114 | leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); | 114 | leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); |
115 | rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); | 115 | rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); |
116 | } | 116 | } |
117 | // Volume can be from 0 to 100 which is 101 distinct values | 117 | // Volume can be from 0 to 100 which is 101 distinct values |
118 | unsigned int rV = (rightVolume * 101) >> 16; | 118 | unsigned int rV = (rightVolume * 101) >> 16; |
119 | 119 | ||
120 | # if 0 | 120 | # if 0 |
121 | unsigned int lV = (leftVolume * 101) >> 16; | 121 | unsigned int lV = (leftVolume * 101) >> 16; |
122 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); | 122 | unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); |
123 | int mixerHandle = 0; | 123 | int mixerHandle = 0; |
124 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 124 | if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
125 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) | 125 | if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) |
126 | perror("ioctl(\"MIXER_WRITE\")"); | 126 | perror("ioctl(\"MIXER_WRITE\")"); |
127 | close( mixerHandle ); | 127 | close( mixerHandle ); |
128 | } else | 128 | } else |
129 | perror("open(\"/dev/mixer\")"); | 129 | perror("open(\"/dev/mixer\")"); |
130 | 130 | ||
131 | # else | 131 | # else |
132 | // This is the way this has to be done now I guess, doesn't allow for | 132 | // This is the way this has to be done now I guess, doesn't allow for |
133 | // independant right and left channel setting, or setting for different outputs | 133 | // independant right and left channel setting, or setting for different outputs |
134 | Config cfg("qpe"); // qtopia is "Sound" | 134 | Config cfg("qpe"); // qtopia is "Sound" |
135 | cfg.setGroup("Volume"); // qtopia is "Settings" | 135 | cfg.setGroup("Volume"); // qtopia is "Settings" |
136 | cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume | 136 | cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume |
137 | # endif | 137 | # endif |
138 | 138 | ||
139 | //#endif | 139 | //#endif |
140 | // qDebug( "setting volume to: 0x%x", volume ); | 140 | // qDebug( "setting volume to: 0x%x", volume ); |
141 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 141 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
142 | // Send notification that the volume has changed | 142 | // Send notification that the volume has changed |
143 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; | 143 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; |
144 | #endif | 144 | #endif |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | 148 | ||
149 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { | 149 | AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { |
150 | qDebug("creating new audio device"); | 150 | qDebug("creating new audio device"); |
151 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; | 151 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; |
152 | d = new AudioDevicePrivate; | 152 | d = new AudioDevicePrivate; |
153 | d->frequency = f; | 153 | d->frequency = f; |
154 | d->channels = chs; | 154 | d->channels = chs; |
155 | d->bytesPerSample = bps; | 155 | d->bytesPerSample = bps; |
156 | qDebug("%d",bps); | 156 | qDebug("%d",bps); |
157 | int format=0; | 157 | int format=0; |
158 | if( bps == 8) format = AFMT_U8; | 158 | if( bps == 8) format = AFMT_U8; |
159 | else if( bps <= 0) format = AFMT_S16_LE; | 159 | else if( bps <= 0) format = AFMT_S16_LE; |
160 | else format = AFMT_S16_LE; | 160 | else format = AFMT_S16_LE; |
161 | qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); | 161 | qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); |
162 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); | 162 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); |
163 | 163 | ||
164 | int fragments = 0x10000 * 8 + sound_fragment_shift; | 164 | int fragments = 0x10000 * 8 + sound_fragment_shift; |
165 | int capabilities = 0; | 165 | int capabilities = 0; |
166 | 166 | ||
167 | 167 | ||
168 | #ifdef KEEP_DEVICE_OPEN | 168 | #ifdef KEEP_DEVICE_OPEN |
169 | if ( AudioDevicePrivate::dspFd == 0 ) { | 169 | if ( AudioDevicePrivate::dspFd == 0 ) { |
170 | #endif | 170 | #endif |
171 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { | 171 | if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { |
172 | 172 | ||
173 | // perror("open(\"/dev/dsp\") sending to /dev/null instead"); | 173 | // perror("open(\"/dev/dsp\") sending to /dev/null instead"); |
174 | perror("open(\"/dev/dsp\")"); | 174 | perror("open(\"/dev/dsp\")"); |
175 | QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now."); | 175 | QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now."); |
176 | QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort")); | 176 | QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort")); |
177 | exit(-1); //harsh? | 177 | exit(-1); //harsh? |
178 | // d->handle = ::open( "/dev/null", O_WRONLY ); | 178 | // d->handle = ::open( "/dev/null", O_WRONLY ); |
179 | // WTF?!?! | 179 | // WTF?!?! |
180 | } | 180 | } |
181 | #ifdef KEEP_DEVICE_OPEN | 181 | #ifdef KEEP_DEVICE_OPEN |
182 | AudioDevicePrivate::dspFd = d->handle; | 182 | AudioDevicePrivate::dspFd = d->handle; |
183 | } else { | 183 | } else { |
184 | d->handle = AudioDevicePrivate::dspFd; | 184 | d->handle = AudioDevicePrivate::dspFd; |
185 | } | 185 | } |
186 | #endif | 186 | #endif |
187 | 187 | ||
188 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) | 188 | if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) |
189 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); | 189 | perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); |
190 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) | 190 | if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) |
191 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); | 191 | perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); |
192 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) | 192 | if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) |
193 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); | 193 | perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); |
194 | qDebug("freq %d", d->frequency); | 194 | qDebug("freq %d", d->frequency); |
195 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) | 195 | if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) |
196 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); | 196 | perror("ioctl(\"SNDCTL_DSP_SPEED\")"); |
197 | qDebug("channels %d",d->channels); | 197 | qDebug("channels %d",d->channels); |
198 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { | 198 | if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { |
199 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; | 199 | d->channels = ( d->channels == 1 ) ? 2 : d->channels; |
200 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) | 200 | if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) |
201 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); | 201 | perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); |
202 | } | 202 | } |
203 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; | 203 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; |
204 | 204 | ||
205 | d->bufferSize = sound_fragment_bytes; | 205 | d->bufferSize = sound_fragment_bytes; |
206 | d->unwrittenBuffer = new char[d->bufferSize]; | 206 | d->unwrittenBuffer = new char[d->bufferSize]; |
207 | d->unwritten = 0; | 207 | d->unwritten = 0; |
208 | d->can_GETOSPACE = TRUE; // until we find otherwise | 208 | d->can_GETOSPACE = TRUE; // until we find otherwise |
209 | 209 | ||
210 | //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); | 210 | //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); |
211 | //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); | 211 | //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); |
212 | //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); | 212 | //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); |
213 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); | 213 | //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); |
214 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); | 214 | //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); |
215 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); | 215 | //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); |
216 | 216 | ||
217 | } | 217 | } |
218 | 218 | ||
219 | 219 | ||
220 | AudioDevice::~AudioDevice() { | 220 | AudioDevice::~AudioDevice() { |
221 | qDebug("destryo audiodevice"); | 221 | qDebug("destryo audiodevice"); |
222 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; | 222 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; |
223 | 223 | ||
224 | # ifndef KEEP_DEVICE_OPEN | 224 | # ifndef KEEP_DEVICE_OPEN |
225 | close( d->handle ); // Now it should be safe to shut the handle | 225 | close( d->handle ); // Now it should be safe to shut the handle |
226 | # endif | 226 | # endif |
227 | delete d->unwrittenBuffer; | 227 | delete d->unwrittenBuffer; |
228 | delete d; | 228 | delete d; |
229 | QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; | 229 | // QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; |
230 | 230 | ||
231 | } | 231 | } |
232 | 232 | ||
233 | 233 | ||
234 | void AudioDevice::volumeChanged( bool muted ) | 234 | void AudioDevice::volumeChanged( bool muted ) |
235 | { | 235 | { |
236 | AudioDevicePrivate::muted = muted; | 236 | AudioDevicePrivate::muted = muted; |
237 | } | 237 | } |
238 | 238 | ||
239 | 239 | ||
240 | void AudioDevice::write( char *buffer, unsigned int length ) | 240 | void AudioDevice::write( char *buffer, unsigned int length ) |
241 | { | 241 | { |
242 | int t = ::write( d->handle, buffer, length ); | 242 | int t = ::write( d->handle, buffer, length ); |
243 | if ( t<0 ) t = 0; | 243 | if ( t<0 ) t = 0; |
244 | if ( t != (int)length) { | 244 | if ( t != (int)length) { |
245 | qDebug("Ahhh!! memcpys 1"); | 245 | qDebug("Ahhh!! memcpys 1"); |
246 | memcpy(d->unwrittenBuffer,buffer+t,length-t); | 246 | memcpy(d->unwrittenBuffer,buffer+t,length-t); |
247 | d->unwritten = length-t; | 247 | d->unwritten = length-t; |
248 | } | 248 | } |
249 | //#endif | 249 | //#endif |
250 | } | 250 | } |
251 | 251 | ||
252 | 252 | ||
253 | unsigned int AudioDevice::channels() const | 253 | unsigned int AudioDevice::channels() const |
254 | { | 254 | { |
255 | return d->channels; | 255 | return d->channels; |
256 | } | 256 | } |
257 | 257 | ||
258 | 258 | ||
259 | unsigned int AudioDevice::frequency() const | 259 | unsigned int AudioDevice::frequency() const |
260 | { | 260 | { |
261 | return d->frequency; | 261 | return d->frequency; |
262 | } | 262 | } |
263 | 263 | ||
264 | 264 | ||
265 | unsigned int AudioDevice::bytesPerSample() const | 265 | unsigned int AudioDevice::bytesPerSample() const |
266 | { | 266 | { |
267 | return d->bytesPerSample; | 267 | return d->bytesPerSample; |
268 | } | 268 | } |
269 | 269 | ||
270 | 270 | ||
271 | unsigned int AudioDevice::bufferSize() const | 271 | unsigned int AudioDevice::bufferSize() const |
272 | { | 272 | { |
273 | return d->bufferSize; | 273 | return d->bufferSize; |
274 | } | 274 | } |
275 | 275 | ||
276 | unsigned int AudioDevice::canWrite() const | 276 | unsigned int AudioDevice::canWrite() const |
277 | { | 277 | { |
278 | audio_buf_info info; | 278 | audio_buf_info info; |
279 | if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { | 279 | if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { |
280 | d->can_GETOSPACE = FALSE; | 280 | d->can_GETOSPACE = FALSE; |
281 | fcntl( d->handle, F_SETFL, O_NONBLOCK ); | 281 | fcntl( d->handle, F_SETFL, O_NONBLOCK ); |
282 | } | 282 | } |
283 | if ( d->can_GETOSPACE ) { | 283 | if ( d->can_GETOSPACE ) { |
284 | int t = info.fragments * sound_fragment_bytes; | 284 | int t = info.fragments * sound_fragment_bytes; |
285 | return QMIN(t,(int)bufferSize()); | 285 | return QMIN(t,(int)bufferSize()); |
286 | } else { | 286 | } else { |
287 | if ( d->unwritten ) { | 287 | if ( d->unwritten ) { |
288 | int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); | 288 | int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); |
289 | if ( t<0 ) t = 0; | 289 | if ( t<0 ) t = 0; |
290 | if ( (unsigned)t!=d->unwritten ) { | 290 | if ( (unsigned)t!=d->unwritten ) { |
291 | memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); | 291 | memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); |
292 | d->unwritten -= t; | 292 | d->unwritten -= t; |
293 | } else { | 293 | } else { |
294 | d->unwritten = 0; | 294 | d->unwritten = 0; |
295 | } | 295 | } |
296 | } | 296 | } |
297 | if ( d->unwritten ) | 297 | if ( d->unwritten ) |
298 | return 0; | 298 | return 0; |
299 | else | 299 | else |
300 | return d->bufferSize; | 300 | return d->bufferSize; |
301 | } | 301 | } |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | int AudioDevice::bytesWritten() { | 305 | int AudioDevice::bytesWritten() { |
306 | int buffered = 0; | 306 | int buffered = 0; |
307 | if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { | 307 | if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { |
308 | qDebug( "failed to get audio device position" ); | 308 | qDebug( "failed to get audio device position" ); |
309 | return -1; | 309 | return -1; |
310 | } | 310 | } |
311 | return buffered; | 311 | return buffered; |
312 | } | 312 | } |
313 | 313 | ||
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index 3c5734e..a0bf4db 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp | |||
@@ -1,1276 +1,1279 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // code added by L. J. Potter Sat 03-02-2002 06:17:54 | 20 | // code added by L. J. Potter Sat 03-02-2002 06:17:54 |
21 | #define QTOPIA_INTERNAL_FSLP | 21 | #define QTOPIA_INTERNAL_FSLP |
22 | #include <qpe/qcopenvelope_qws.h> | 22 | #include <qpe/qcopenvelope_qws.h> |
23 | 23 | ||
24 | #include <qpe/qpemenubar.h> | 24 | #include <qpe/qpemenubar.h> |
25 | #include <qpe/qpetoolbar.h> | 25 | #include <qpe/qpetoolbar.h> |
26 | #include <qpe/fileselector.h> | 26 | #include <qpe/fileselector.h> |
27 | #include <qpe/qpeapplication.h> | 27 | #include <qpe/qpeapplication.h> |
28 | #include <qpe/lnkproperties.h> | 28 | #include <qpe/lnkproperties.h> |
29 | #include <qpe/storage.h> | 29 | #include <qpe/storage.h> |
30 | 30 | ||
31 | #include <qpe/applnk.h> | 31 | #include <qpe/applnk.h> |
32 | #include <qpe/config.h> | 32 | #include <qpe/config.h> |
33 | #include <qpe/global.h> | 33 | #include <qpe/global.h> |
34 | #include <qpe/resource.h> | 34 | #include <qpe/resource.h> |
35 | #include <qaction.h> | 35 | #include <qaction.h> |
36 | #include <qcursor.h> | 36 | #include <qcursor.h> |
37 | #include <qimage.h> | 37 | #include <qimage.h> |
38 | #include <qfile.h> | 38 | #include <qfile.h> |
39 | #include <qdir.h> | 39 | #include <qdir.h> |
40 | #include <qlayout.h> | 40 | #include <qlayout.h> |
41 | #include <qlabel.h> | 41 | #include <qlabel.h> |
42 | #include <qlist.h> | 42 | #include <qlist.h> |
43 | #include <qlistbox.h> | 43 | #include <qlistbox.h> |
44 | #include <qmainwindow.h> | 44 | #include <qmainwindow.h> |
45 | #include <qmessagebox.h> | 45 | #include <qmessagebox.h> |
46 | #include <qtoolbutton.h> | 46 | #include <qtoolbutton.h> |
47 | #include <qtabwidget.h> | 47 | #include <qtabwidget.h> |
48 | #include <qlistview.h> | 48 | #include <qlistview.h> |
49 | #include <qpoint.h> | 49 | #include <qpoint.h> |
50 | #include <qlineedit.h> | 50 | #include <qlineedit.h> |
51 | #include <qpushbutton.h> | 51 | #include <qpushbutton.h> |
52 | #include <qregexp.h> | 52 | #include <qregexp.h> |
53 | #include <qtextstream.h> | 53 | #include <qtextstream.h> |
54 | 54 | ||
55 | //#include <qtimer.h> | 55 | //#include <qtimer.h> |
56 | 56 | ||
57 | #include "playlistselection.h" | 57 | #include "playlistselection.h" |
58 | #include "playlistwidget.h" | 58 | #include "playlistwidget.h" |
59 | #include "mediaplayerstate.h" | 59 | #include "mediaplayerstate.h" |
60 | 60 | ||
61 | #include "inputDialog.h" | 61 | #include "inputDialog.h" |
62 | 62 | ||
63 | #include <stdlib.h> | 63 | #include <stdlib.h> |
64 | #include "audiowidget.h" | 64 | #include "audiowidget.h" |
65 | #include "videowidget.h" | 65 | #include "videowidget.h" |
66 | 66 | ||
67 | #include <unistd.h> | 67 | #include <unistd.h> |
68 | #include <sys/file.h> | 68 | #include <sys/file.h> |
69 | #include <sys/ioctl.h> | 69 | #include <sys/ioctl.h> |
70 | #include <sys/soundcard.h> | 70 | #include <sys/soundcard.h> |
71 | 71 | ||
72 | // for setBacklight() | 72 | // for setBacklight() |
73 | #include <linux/fb.h> | 73 | #include <linux/fb.h> |
74 | #include <sys/types.h> | 74 | #include <sys/types.h> |
75 | #include <sys/stat.h> | 75 | #include <sys/stat.h> |
76 | #include <stdlib.h> | 76 | #include <stdlib.h> |
77 | 77 | ||
78 | #define BUTTONS_ON_TOOLBAR | 78 | #define BUTTONS_ON_TOOLBAR |
79 | #define SIDE_BUTTONS | 79 | #define SIDE_BUTTONS |
80 | #define CAN_SAVE_LOAD_PLAYLISTS | 80 | #define CAN_SAVE_LOAD_PLAYLISTS |
81 | 81 | ||
82 | extern AudioWidget *audioUI; | 82 | extern AudioWidget *audioUI; |
83 | extern VideoWidget *videoUI; | 83 | extern VideoWidget *videoUI; |
84 | extern MediaPlayerState *mediaPlayerState; | 84 | extern MediaPlayerState *mediaPlayerState; |
85 | 85 | ||
86 | static inline QString fullBaseName ( const QFileInfo &fi ) | 86 | static inline QString fullBaseName ( const QFileInfo &fi ) |
87 | { | 87 | { |
88 | QString str = fi. fileName ( ); | 88 | QString str = fi. fileName ( ); |
89 | return str. left ( str. findRev ( '.' )); | 89 | return str. left ( str. findRev ( '.' )); |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | QString audioMimes ="audio/mpeg;audio/x-wav;audio/x-ogg;audio/x-mod"; | 93 | QString audioMimes ="audio/mpeg;audio/x-wav;audio/x-ogg;audio/x-mod"; |
94 | // class myFileSelector { | 94 | // class myFileSelector { |
95 | 95 | ||
96 | // }; | 96 | // }; |
97 | class PlayListWidgetPrivate { | 97 | class PlayListWidgetPrivate { |
98 | public: | 98 | public: |
99 | QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; | 99 | QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; |
100 | QFrame *playListFrame; | 100 | QFrame *playListFrame; |
101 | FileSelector *files; | 101 | FileSelector *files; |
102 | PlayListSelection *selectedFiles; | 102 | PlayListSelection *selectedFiles; |
103 | bool setDocumentUsed; | 103 | bool setDocumentUsed; |
104 | DocLnk *current; | 104 | DocLnk *current; |
105 | }; | 105 | }; |
106 | 106 | ||
107 | 107 | ||
108 | class ToolButton : public QToolButton { | 108 | class ToolButton : public QToolButton { |
109 | public: | 109 | public: |
110 | ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) | 110 | ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) |
111 | : QToolButton( parent, name ) { | 111 | : QToolButton( parent, name ) { |
112 | setTextLabel( name ); | 112 | setTextLabel( name ); |
113 | setPixmap( Resource::loadPixmap( icon ) ); | 113 | setPixmap( Resource::loadPixmap( icon ) ); |
114 | setAutoRaise( TRUE ); | 114 | setAutoRaise( TRUE ); |
115 | setFocusPolicy( QWidget::NoFocus ); | 115 | setFocusPolicy( QWidget::NoFocus ); |
116 | setToggleButton( t ); | 116 | setToggleButton( t ); |
117 | connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); | 117 | connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); |
118 | QPEMenuToolFocusManager::manager()->addWidget( this ); | 118 | QPEMenuToolFocusManager::manager()->addWidget( this ); |
119 | } | 119 | } |
120 | }; | 120 | }; |
121 | 121 | ||
122 | 122 | ||
123 | class MenuItem : public QAction { | 123 | class MenuItem : public QAction { |
124 | public: | 124 | public: |
125 | MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) | 125 | MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) |
126 | : QAction( text, QString::null, 0, 0 ) { | 126 | : QAction( text, QString::null, 0, 0 ) { |
127 | connect( this, SIGNAL( activated() ), handler, slot ); | 127 | connect( this, SIGNAL( activated() ), handler, slot ); |
128 | addTo( parent ); | 128 | addTo( parent ); |
129 | } | 129 | } |
130 | }; | 130 | }; |
131 | 131 | ||
132 | 132 | ||
133 | PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) | 133 | PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) |
134 | : QMainWindow( parent, name, fl ) { | 134 | : QMainWindow( parent, name, fl ) { |
135 | 135 | ||
136 | d = new PlayListWidgetPrivate; | 136 | d = new PlayListWidgetPrivate; |
137 | d->setDocumentUsed = FALSE; | 137 | d->setDocumentUsed = FALSE; |
138 | d->current = NULL; | 138 | d->current = NULL; |
139 | fromSetDocument = FALSE; | 139 | fromSetDocument = FALSE; |
140 | insanityBool=FALSE; | 140 | insanityBool=FALSE; |
141 | audioScan = FALSE; | 141 | audioScan = FALSE; |
142 | videoScan = FALSE; | 142 | videoScan = FALSE; |
143 | // menuTimer = new QTimer( this ,"menu timer"), | 143 | // menuTimer = new QTimer( this ,"menu timer"), |
144 | // connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); | 144 | // connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); |
145 | 145 | ||
146 | setBackgroundMode( PaletteButton ); | 146 | setBackgroundMode( PaletteButton ); |
147 | 147 | ||
148 | setCaption( tr("OpiePlayer") ); | 148 | setCaption( tr("OpiePlayer") ); |
149 | setIcon( Resource::loadPixmap( "opieplayer/MPEGPlayer" ) ); | 149 | setIcon( Resource::loadPixmap( "opieplayer/MPEGPlayer" ) ); |
150 | 150 | ||
151 | setToolBarsMovable( FALSE ); | 151 | setToolBarsMovable( FALSE ); |
152 | 152 | ||
153 | // Create Toolbar | 153 | // Create Toolbar |
154 | QPEToolBar *toolbar = new QPEToolBar( this ); | 154 | QPEToolBar *toolbar = new QPEToolBar( this ); |
155 | toolbar->setHorizontalStretchable( TRUE ); | 155 | toolbar->setHorizontalStretchable( TRUE ); |
156 | 156 | ||
157 | // Create Menubar | 157 | // Create Menubar |
158 | QPEMenuBar *menu = new QPEMenuBar( toolbar ); | 158 | QPEMenuBar *menu = new QPEMenuBar( toolbar ); |
159 | menu->setMargin( 0 ); | 159 | menu->setMargin( 0 ); |
160 | 160 | ||
161 | QPEToolBar *bar = new QPEToolBar( this ); | 161 | QPEToolBar *bar = new QPEToolBar( this ); |
162 | bar->setLabel( tr( "Play Operations" ) ); | 162 | bar->setLabel( tr( "Play Operations" ) ); |
163 | // d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "opieplayer/play_current_list", | 163 | // d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "opieplayer/play_current_list", |
164 | // this , SLOT( addSelected()) ); | 164 | // this , SLOT( addSelected()) ); |
165 | tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); | 165 | tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); |
166 | tbDeletePlaylist->setFlat(TRUE); | 166 | tbDeletePlaylist->setFlat(TRUE); |
167 | tbDeletePlaylist->setFixedSize(20,20); | 167 | tbDeletePlaylist->setFixedSize(20,20); |
168 | 168 | ||
169 | d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "opieplayer/add_to_playlist", | 169 | d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "opieplayer/add_to_playlist", |
170 | this , SLOT(addSelected()) ); | 170 | this , SLOT(addSelected()) ); |
171 | d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "opieplayer/remove_from_playlist", | 171 | d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "opieplayer/remove_from_playlist", |
172 | this , SLOT(removeSelected()) ); | 172 | this , SLOT(removeSelected()) ); |
173 | // d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); | 173 | // d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); |
174 | d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", | 174 | d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", |
175 | this , SLOT( btnPlay(bool) ), TRUE ); | 175 | this , SLOT( btnPlay(bool) ), TRUE ); |
176 | d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle", | 176 | d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle", |
177 | mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); | 177 | mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); |
178 | d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop", | 178 | d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop", |
179 | mediaPlayerState, SLOT(setLooping(bool)), TRUE ); | 179 | mediaPlayerState, SLOT(setLooping(bool)), TRUE ); |
180 | tbDeletePlaylist->hide(); | 180 | tbDeletePlaylist->hide(); |
181 | 181 | ||
182 | QPopupMenu *pmPlayList = new QPopupMenu( this ); | 182 | QPopupMenu *pmPlayList = new QPopupMenu( this ); |
183 | menu->insertItem( tr( "File" ), pmPlayList ); | 183 | menu->insertItem( tr( "File" ), pmPlayList ); |
184 | new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); | 184 | new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); |
185 | new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); | 185 | new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); |
186 | new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); | 186 | new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); |
187 | new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); | 187 | new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); |
188 | pmPlayList->insertSeparator(-1); | 188 | pmPlayList->insertSeparator(-1); |
189 | new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); | 189 | new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); |
190 | new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); | 190 | new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); |
191 | pmPlayList->insertSeparator(-1); | 191 | pmPlayList->insertSeparator(-1); |
192 | new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) ); | 192 | new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) ); |
193 | new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) ); | 193 | new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) ); |
194 | 194 | ||
195 | QPopupMenu *pmView = new QPopupMenu( this ); | 195 | QPopupMenu *pmView = new QPopupMenu( this ); |
196 | menu->insertItem( tr( "View" ), pmView ); | 196 | menu->insertItem( tr( "View" ), pmView ); |
197 | 197 | ||
198 | fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); | 198 | fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); |
199 | fullScreenButton->addTo(pmView); | 199 | fullScreenButton->addTo(pmView); |
200 | scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0); | 200 | scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0); |
201 | scaleButton->addTo(pmView); | 201 | scaleButton->addTo(pmView); |
202 | 202 | ||
203 | 203 | ||
204 | skinsMenu = new QPopupMenu( this ); | 204 | skinsMenu = new QPopupMenu( this ); |
205 | menu->insertItem( tr( "Skins" ), skinsMenu ); | 205 | menu->insertItem( tr( "Skins" ), skinsMenu ); |
206 | skinsMenu->isCheckable(); | 206 | skinsMenu->isCheckable(); |
207 | connect( skinsMenu, SIGNAL( activated( int ) ) , | 207 | connect( skinsMenu, SIGNAL( activated( int ) ) , |
208 | this, SLOT( skinsMenuActivated( int ) ) ); | 208 | this, SLOT( skinsMenuActivated( int ) ) ); |
209 | populateSkinsMenu(); | 209 | populateSkinsMenu(); |
210 | 210 | ||
211 | QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); | 211 | QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); |
212 | QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); | 212 | QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); |
213 | 213 | ||
214 | QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); | 214 | QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); |
215 | 215 | ||
216 | tabWidget = new QTabWidget( hbox6, "tabWidget" ); | 216 | tabWidget = new QTabWidget( hbox6, "tabWidget" ); |
217 | tabWidget->setTabShape(QTabWidget::Triangular); | 217 | // tabWidget->setTabShape(QTabWidget::Triangular); |
218 | 218 | ||
219 | QWidget *pTab; | 219 | QWidget *pTab; |
220 | pTab = new QWidget( tabWidget, "pTab" ); | 220 | pTab = new QWidget( tabWidget, "pTab" ); |
221 | // playlistView = new QListView( pTab, "playlistview" ); | 221 | // playlistView = new QListView( pTab, "playlistview" ); |
222 | // playlistView->setMinimumSize(236,260); | 222 | // playlistView->setMinimumSize(236,260); |
223 | tabWidget->insertTab( pTab,"Playlist"); | 223 | tabWidget->insertTab( pTab,"Playlist"); |
224 | 224 | ||
225 | 225 | ||
226 | // Add the playlist area | 226 | // Add the playlist area |
227 | 227 | ||
228 | QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); | 228 | QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); |
229 | d->playListFrame = vbox3; | 229 | d->playListFrame = vbox3; |
230 | d->playListFrame ->setMinimumSize(235,260); | 230 | d->playListFrame ->setMinimumSize(235,260); |
231 | 231 | ||
232 | QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); | 232 | QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); |
233 | 233 | ||
234 | d->selectedFiles = new PlayListSelection( hbox2); | 234 | d->selectedFiles = new PlayListSelection( hbox2); |
235 | QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); | 235 | QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); |
236 | 236 | ||
237 | QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); | 237 | QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); |
238 | 238 | ||
239 | 239 | ||
240 | 240 | ||
241 | QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch | 241 | QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch |
242 | new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); | 242 | new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); |
243 | new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); | 243 | new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); |
244 | new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); | 244 | new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); |
245 | QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch | 245 | QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch |
246 | 246 | ||
247 | QWidget *aTab; | 247 | QWidget *aTab; |
248 | aTab = new QWidget( tabWidget, "aTab" ); | 248 | aTab = new QWidget( tabWidget, "aTab" ); |
249 | audioView = new QListView( aTab, "Audioview" ); | 249 | audioView = new QListView( aTab, "Audioview" ); |
250 | audioView->setMinimumSize(233,260); | 250 | audioView->setMinimumSize(233,260); |
251 | audioView->addColumn( tr("Title"),140); | 251 | audioView->addColumn( tr("Title"),140); |
252 | audioView->addColumn(tr("Size"), -1); | 252 | audioView->addColumn(tr("Size"), -1); |
253 | audioView->addColumn(tr("Media"),-1); | 253 | audioView->addColumn(tr("Media"),-1); |
254 | audioView->addColumn( tr( "Path" ), 0 ); | 254 | audioView->addColumn( tr( "Path" ), 0 ); |
255 | 255 | ||
256 | audioView->setColumnAlignment(1, Qt::AlignRight); | 256 | audioView->setColumnAlignment(1, Qt::AlignRight); |
257 | audioView->setColumnAlignment(2, Qt::AlignRight); | 257 | audioView->setColumnAlignment(2, Qt::AlignRight); |
258 | audioView->setAllColumnsShowFocus(TRUE); | 258 | audioView->setAllColumnsShowFocus(TRUE); |
259 | 259 | ||
260 | audioView->setMultiSelection( TRUE ); | 260 | audioView->setMultiSelection( TRUE ); |
261 | audioView->setSelectionMode( QListView::Extended); | 261 | audioView->setSelectionMode( QListView::Extended); |
262 | audioView->setSorting( 3, TRUE ); | 262 | audioView->setSorting( 3, TRUE ); |
263 | 263 | ||
264 | tabWidget->insertTab(aTab,tr("Audio")); | 264 | tabWidget->insertTab(aTab,tr("Audio")); |
265 | 265 | ||
266 | QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); | 266 | QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); |
267 | 267 | ||
268 | // audioView | 268 | // audioView |
269 | // populateAudioView(); | 269 | // populateAudioView(); |
270 | // videowidget | 270 | // videowidget |
271 | 271 | ||
272 | QWidget *vTab; | 272 | QWidget *vTab; |
273 | vTab = new QWidget( tabWidget, "vTab" ); | 273 | vTab = new QWidget( tabWidget, "vTab" ); |
274 | videoView = new QListView( vTab, "Videoview" ); | 274 | videoView = new QListView( vTab, "Videoview" ); |
275 | videoView->setMinimumSize(233,260); | 275 | videoView->setMinimumSize(233,260); |
276 | 276 | ||
277 | videoView->addColumn(tr("Title"),140); | 277 | videoView->addColumn(tr("Title"),140); |
278 | videoView->addColumn(tr("Size"),-1); | 278 | videoView->addColumn(tr("Size"),-1); |
279 | videoView->addColumn(tr("Media"),-1); | 279 | videoView->addColumn(tr("Media"),-1); |
280 | videoView->addColumn(tr( "Path" ), 0 ); | 280 | videoView->addColumn(tr( "Path" ), 0 ); |
281 | videoView->setColumnAlignment(1, Qt::AlignRight); | 281 | videoView->setColumnAlignment(1, Qt::AlignRight); |
282 | videoView->setColumnAlignment(2, Qt::AlignRight); | 282 | videoView->setColumnAlignment(2, Qt::AlignRight); |
283 | videoView->setAllColumnsShowFocus(TRUE); | 283 | videoView->setAllColumnsShowFocus(TRUE); |
284 | videoView->setMultiSelection( TRUE ); | 284 | videoView->setMultiSelection( TRUE ); |
285 | videoView->setSelectionMode( QListView::Extended); | 285 | videoView->setSelectionMode( QListView::Extended); |
286 | 286 | ||
287 | QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); | 287 | QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); |
288 | 288 | ||
289 | tabWidget->insertTab( vTab,tr("Video")); | 289 | tabWidget->insertTab( vTab,tr("Video")); |
290 | 290 | ||
291 | QWidget *LTab; | 291 | QWidget *LTab; |
292 | LTab = new QWidget( tabWidget, "LTab" ); | 292 | LTab = new QWidget( tabWidget, "LTab" ); |
293 | playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy | 293 | playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy |
294 | playLists->setMinimumSize(233,260); | 294 | playLists->setMinimumSize(233,260); |
295 | tabWidget->insertTab(LTab,tr("Lists")); | 295 | tabWidget->insertTab(LTab,tr("Lists")); |
296 | 296 | ||
297 | connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); | 297 | connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); |
298 | connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); | 298 | connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); |
299 | connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); | 299 | connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); |
300 | 300 | ||
301 | connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 301 | connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
302 | this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); | 302 | this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); |
303 | 303 | ||
304 | 304 | ||
305 | ///audioView | 305 | ///audioView |
306 | connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 306 | connect( audioView, 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 | 308 | ||
309 | connect( audioView, SIGNAL( returnPressed( QListViewItem *)), | 309 | connect( audioView, SIGNAL( returnPressed( QListViewItem *)), |
310 | this,SLOT( playIt( QListViewItem *)) ); | 310 | this,SLOT( playIt( QListViewItem *)) ); |
311 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | 311 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); |
312 | 312 | ||
313 | 313 | ||
314 | //videoView | 314 | //videoView |
315 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 315 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
316 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | 316 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); |
317 | connect( videoView, SIGNAL( returnPressed( QListViewItem *)), | 317 | connect( videoView, SIGNAL( returnPressed( QListViewItem *)), |
318 | this,SLOT( playIt( QListViewItem *)) ); | 318 | this,SLOT( playIt( QListViewItem *)) ); |
319 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | 319 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); |
320 | 320 | ||
321 | 321 | ||
322 | //playlists | 322 | //playlists |
323 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); | 323 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); |
324 | 324 | ||
325 | 325 | ||
326 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); | 326 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); |
327 | 327 | ||
328 | // connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); | 328 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); |
329 | |||
330 | |||
331 | |||
329 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); | 332 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); |
330 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); | 333 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); |
331 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); | 334 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); |
332 | 335 | ||
333 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); | 336 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); |
334 | 337 | ||
335 | setCentralWidget( vbox5 ); | 338 | setCentralWidget( vbox5 ); |
336 | 339 | ||
337 | Config cfg( "OpiePlayer" ); | 340 | Config cfg( "OpiePlayer" ); |
338 | readConfig( cfg ); | 341 | readConfig( cfg ); |
339 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default"); | 342 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default"); |
340 | loadList(DocLnk( currentPlaylist)); | 343 | loadList(DocLnk( currentPlaylist)); |
341 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(currentPlaylist))); | 344 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(currentPlaylist))); |
342 | 345 | ||
343 | initializeStates(); | 346 | initializeStates(); |
344 | } | 347 | } |
345 | 348 | ||
346 | 349 | ||
347 | PlayListWidget::~PlayListWidget() { | 350 | PlayListWidget::~PlayListWidget() { |
348 | Config cfg( "OpiePlayer" ); | 351 | Config cfg( "OpiePlayer" ); |
349 | writeConfig( cfg ); | 352 | writeConfig( cfg ); |
350 | 353 | ||
351 | if ( d->current ) | 354 | if ( d->current ) |
352 | delete d->current; | 355 | delete d->current; |
353 | delete d; | 356 | delete d; |
354 | } | 357 | } |
355 | 358 | ||
356 | 359 | ||
357 | void PlayListWidget::initializeStates() { | 360 | void PlayListWidget::initializeStates() { |
358 | 361 | ||
359 | d->tbPlay->setOn( mediaPlayerState->playing() ); | 362 | d->tbPlay->setOn( mediaPlayerState->playing() ); |
360 | d->tbLoop->setOn( mediaPlayerState->looping() ); | 363 | d->tbLoop->setOn( mediaPlayerState->looping() ); |
361 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); | 364 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); |
362 | setPlaylist( true); | 365 | setPlaylist( true); |
363 | } | 366 | } |
364 | 367 | ||
365 | 368 | ||
366 | void PlayListWidget::readConfig( Config& cfg ) { | 369 | void PlayListWidget::readConfig( Config& cfg ) { |
367 | cfg.setGroup("PlayList"); | 370 | cfg.setGroup("PlayList"); |
368 | QString currentString = cfg.readEntry("current", "" ); | 371 | QString currentString = cfg.readEntry("current", "" ); |
369 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 372 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
370 | for ( int i = 0; i < noOfFiles; i++ ) { | 373 | for ( int i = 0; i < noOfFiles; i++ ) { |
371 | QString entryName; | 374 | QString entryName; |
372 | entryName.sprintf( "File%i", i + 1 ); | 375 | entryName.sprintf( "File%i", i + 1 ); |
373 | QString linkFile = cfg.readEntry( entryName ); | 376 | QString linkFile = cfg.readEntry( entryName ); |
374 | DocLnk lnk( linkFile ); | 377 | DocLnk lnk( linkFile ); |
375 | if ( lnk.isValid() ) { | 378 | if ( lnk.isValid() ) { |
376 | d->selectedFiles->addToSelection( lnk ); | 379 | d->selectedFiles->addToSelection( lnk ); |
377 | } | 380 | } |
378 | } | 381 | } |
379 | d->selectedFiles->setSelectedItem( currentString); | 382 | d->selectedFiles->setSelectedItem( currentString); |
380 | } | 383 | } |
381 | 384 | ||
382 | 385 | ||
383 | void PlayListWidget::writeConfig( Config& cfg ) const { | 386 | void PlayListWidget::writeConfig( Config& cfg ) const { |
384 | 387 | ||
385 | d->selectedFiles->writeCurrent( cfg); | 388 | d->selectedFiles->writeCurrent( cfg); |
386 | cfg.setGroup("PlayList"); | 389 | cfg.setGroup("PlayList"); |
387 | int noOfFiles = 0; | 390 | int noOfFiles = 0; |
388 | d->selectedFiles->first(); | 391 | d->selectedFiles->first(); |
389 | do { | 392 | do { |
390 | const DocLnk *lnk = d->selectedFiles->current(); | 393 | const DocLnk *lnk = d->selectedFiles->current(); |
391 | if ( lnk ) { | 394 | if ( lnk ) { |
392 | QString entryName; | 395 | QString entryName; |
393 | entryName.sprintf( "File%i", noOfFiles + 1 ); | 396 | entryName.sprintf( "File%i", noOfFiles + 1 ); |
394 | // qDebug(entryName); | 397 | // qDebug(entryName); |
395 | cfg.writeEntry( entryName, lnk->linkFile() ); | 398 | cfg.writeEntry( entryName, lnk->linkFile() ); |
396 | // if this link does exist, add it so we have the file | 399 | // if this link does exist, add it so we have the file |
397 | // next time... | 400 | // next time... |
398 | if ( !QFile::exists( lnk->linkFile() ) ) { | 401 | if ( !QFile::exists( lnk->linkFile() ) ) { |
399 | // the way writing lnks doesn't really check for out | 402 | // the way writing lnks doesn't really check for out |
400 | // of disk space, but check it anyway. | 403 | // of disk space, but check it anyway. |
401 | if ( !lnk->writeLink() ) { | 404 | if ( !lnk->writeLink() ) { |
402 | QMessageBox::critical( 0, tr("Out of space"), | 405 | QMessageBox::critical( 0, tr("Out of space"), |
403 | tr( "There was a problem saving " | 406 | tr( "There was a problem saving " |
404 | "the playlist.\n" | 407 | "the playlist.\n" |
405 | "Your playlist " | 408 | "Your playlist " |
406 | "may be missing some entries\n" | 409 | "may be missing some entries\n" |
407 | "the next time you start it." ) | 410 | "the next time you start it." ) |
408 | ); | 411 | ); |
409 | } | 412 | } |
410 | } | 413 | } |
411 | noOfFiles++; | 414 | noOfFiles++; |
412 | } | 415 | } |
413 | } | 416 | } |
414 | while ( d->selectedFiles->next() ); | 417 | while ( d->selectedFiles->next() ); |
415 | cfg.writeEntry("NumberOfFiles", noOfFiles ); | 418 | cfg.writeEntry("NumberOfFiles", noOfFiles ); |
416 | } | 419 | } |
417 | 420 | ||
418 | 421 | ||
419 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { | 422 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { |
420 | d->setDocumentUsed = false; | 423 | d->setDocumentUsed = false; |
421 | if ( mediaPlayerState->playlist() ) { | 424 | if ( mediaPlayerState->playlist() ) { |
422 | if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" ) | 425 | if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" ) |
423 | d->selectedFiles->addToSelection( lnk ); | 426 | d->selectedFiles->addToSelection( lnk ); |
424 | } | 427 | } |
425 | else | 428 | else |
426 | mediaPlayerState->setPlaying( true); | 429 | mediaPlayerState->setPlaying( true); |
427 | } | 430 | } |
428 | 431 | ||
429 | 432 | ||
430 | void PlayListWidget::clearList() { | 433 | void PlayListWidget::clearList() { |
431 | while ( first() ) | 434 | while ( first() ) |
432 | d->selectedFiles->removeSelected(); | 435 | d->selectedFiles->removeSelected(); |
433 | } | 436 | } |
434 | 437 | ||
435 | 438 | ||
436 | void PlayListWidget::addAllToList() { | 439 | void PlayListWidget::addAllToList() { |
437 | DocLnkSet filesAll; | 440 | DocLnkSet filesAll; |
438 | Global::findDocuments(&filesAll, "video/*;audio/*"); | 441 | Global::findDocuments(&filesAll, "video/*;audio/*"); |
439 | QListIterator<DocLnk> Adit( filesAll.children() ); | 442 | QListIterator<DocLnk> Adit( filesAll.children() ); |
440 | for ( ; Adit.current(); ++Adit ) | 443 | for ( ; Adit.current(); ++Adit ) |
441 | if(QFileInfo(Adit.current()->file()).exists()) | 444 | if(QFileInfo(Adit.current()->file()).exists()) |
442 | d->selectedFiles->addToSelection( **Adit ); | 445 | d->selectedFiles->addToSelection( **Adit ); |
443 | tabWidget->setCurrentPage(0); | 446 | tabWidget->setCurrentPage(0); |
444 | 447 | ||
445 | writeCurrentM3u(); | 448 | writeCurrentM3u(); |
446 | d->selectedFiles->first(); | 449 | d->selectedFiles->first(); |
447 | } | 450 | } |
448 | 451 | ||
449 | 452 | ||
450 | void PlayListWidget::addAllMusicToList() { | 453 | void PlayListWidget::addAllMusicToList() { |
451 | QListIterator<DocLnk> dit( files.children() ); | 454 | QListIterator<DocLnk> dit( files.children() ); |
452 | for ( ; dit.current(); ++dit ) | 455 | for ( ; dit.current(); ++dit ) |
453 | if(QFileInfo(dit.current()->file()).exists()) | 456 | if(QFileInfo(dit.current()->file()).exists()) |
454 | d->selectedFiles->addToSelection( **dit ); | 457 | d->selectedFiles->addToSelection( **dit ); |
455 | tabWidget->setCurrentPage(0); | 458 | tabWidget->setCurrentPage(0); |
456 | 459 | ||
457 | writeCurrentM3u(); | 460 | writeCurrentM3u(); |
458 | d->selectedFiles->first(); | 461 | d->selectedFiles->first(); |
459 | } | 462 | } |
460 | 463 | ||
461 | 464 | ||
462 | void PlayListWidget::addAllVideoToList() { | 465 | void PlayListWidget::addAllVideoToList() { |
463 | QListIterator<DocLnk> dit( vFiles.children() ); | 466 | QListIterator<DocLnk> dit( vFiles.children() ); |
464 | for ( ; dit.current(); ++dit ) | 467 | for ( ; dit.current(); ++dit ) |
465 | if(QFileInfo( dit.current()->file()).exists()) | 468 | if(QFileInfo( dit.current()->file()).exists()) |
466 | d->selectedFiles->addToSelection( **dit ); | 469 | d->selectedFiles->addToSelection( **dit ); |
467 | tabWidget->setCurrentPage(0); | 470 | tabWidget->setCurrentPage(0); |
468 | 471 | ||
469 | writeCurrentM3u(); | 472 | writeCurrentM3u(); |
470 | d->selectedFiles->first(); | 473 | d->selectedFiles->first(); |
471 | } | 474 | } |
472 | 475 | ||
473 | 476 | ||
474 | void PlayListWidget::setDocument(const QString& fileref) { | 477 | void PlayListWidget::setDocument(const QString& fileref) { |
475 | qDebug(fileref); | 478 | qDebug(fileref); |
476 | fromSetDocument = TRUE; | 479 | fromSetDocument = TRUE; |
477 | QFileInfo fileInfo(fileref); | 480 | QFileInfo fileInfo(fileref); |
478 | if ( !fileInfo.exists() ) { | 481 | if ( !fileInfo.exists() ) { |
479 | QMessageBox::critical( 0, tr( "Invalid File" ), | 482 | QMessageBox::critical( 0, tr( "Invalid File" ), |
480 | tr( "There was a problem in getting the file." ) ); | 483 | tr( "There was a problem in getting the file." ) ); |
481 | return; | 484 | return; |
482 | } | 485 | } |
483 | // qDebug("setDocument "+fileref); | 486 | // qDebug("setDocument "+fileref); |
484 | QString extension = fileInfo.extension(false); | 487 | QString extension = fileInfo.extension(false); |
485 | if( extension.find( "m3u", 0, false) != -1) { //is m3u | 488 | if( extension.find( "m3u", 0, false) != -1) { //is m3u |
486 | readm3u( fileref); | 489 | readm3u( fileref); |
487 | } | 490 | } |
488 | else if( extension.find( "pls", 0, false) != -1 ) { //is pls | 491 | else if( extension.find( "pls", 0, false) != -1 ) { //is pls |
489 | readPls( fileref); | 492 | readPls( fileref); |
490 | } | 493 | } |
491 | else if( fileref.find("playlist",0,TRUE) != -1) {//is playlist | 494 | else if( fileref.find("playlist",0,TRUE) != -1) {//is playlist |
492 | clearList(); | 495 | clearList(); |
493 | DocLnk lnk; | 496 | DocLnk lnk; |
494 | lnk.setName( fileInfo.baseName() ); //sets name | 497 | lnk.setName( fileInfo.baseName() ); //sets name |
495 | lnk.setFile( fileref ); //sets file name | 498 | lnk.setFile( fileref ); //sets file name |
496 | //addToSelection( lnk ); | 499 | //addToSelection( lnk ); |
497 | 500 | ||
498 | loadList( lnk); | 501 | loadList( lnk); |
499 | d->selectedFiles->first(); | 502 | d->selectedFiles->first(); |
500 | } else { | 503 | } else { |
501 | clearList(); | 504 | clearList(); |
502 | DocLnk lnk; | 505 | DocLnk lnk; |
503 | lnk.setName( fileInfo.baseName() ); //sets name | 506 | lnk.setName( fileInfo.baseName() ); //sets name |
504 | lnk.setFile( fileref ); //sets file name | 507 | lnk.setFile( fileref ); //sets file name |
505 | addToSelection( lnk ); | 508 | addToSelection( lnk ); |
506 | // addToSelection( DocLnk( fileref ) ); | 509 | // addToSelection( DocLnk( fileref ) ); |
507 | d->setDocumentUsed = TRUE; | 510 | d->setDocumentUsed = TRUE; |
508 | mediaPlayerState->setPlaying( FALSE ); | 511 | mediaPlayerState->setPlaying( FALSE ); |
509 | qApp->processEvents(); | 512 | qApp->processEvents(); |
510 | mediaPlayerState->setPlaying( TRUE ); | 513 | mediaPlayerState->setPlaying( TRUE ); |
511 | qApp->processEvents(); | 514 | qApp->processEvents(); |
512 | setCaption(tr("OpiePlayer")); | 515 | setCaption(tr("OpiePlayer")); |
513 | } | 516 | } |
514 | } | 517 | } |
515 | 518 | ||
516 | 519 | ||
517 | void PlayListWidget::setActiveWindow() { | 520 | void PlayListWidget::setActiveWindow() { |
518 | qDebug("SETTING active window"); | 521 | qDebug("SETTING active window"); |
519 | 522 | ||
520 | // When we get raised we need to ensure that it switches views | 523 | // When we get raised we need to ensure that it switches views |
521 | char origView = mediaPlayerState->view(); | 524 | char origView = mediaPlayerState->view(); |
522 | mediaPlayerState->setView( 'l' ); // invalidate | 525 | mediaPlayerState->setView( 'l' ); // invalidate |
523 | mediaPlayerState->setView( origView ); // now switch back | 526 | mediaPlayerState->setView( origView ); // now switch back |
524 | } | 527 | } |
525 | 528 | ||
526 | 529 | ||
527 | void PlayListWidget::useSelectedDocument() { | 530 | void PlayListWidget::useSelectedDocument() { |
528 | d->setDocumentUsed = FALSE; | 531 | d->setDocumentUsed = FALSE; |
529 | } | 532 | } |
530 | 533 | ||
531 | 534 | ||
532 | const DocLnk *PlayListWidget::current() { // this is fugly | 535 | const DocLnk *PlayListWidget::current() { // this is fugly |
533 | 536 | ||
534 | // if( fromSetDocument) { | 537 | // if( fromSetDocument) { |
535 | // qDebug("from setDoc"); | 538 | // qDebug("from setDoc"); |
536 | // DocLnkSet files; | 539 | // DocLnkSet files; |
537 | // Global::findDocuments(&files, "video/*;audio/*"); | 540 | // Global::findDocuments(&files, "video/*;audio/*"); |
538 | // QListIterator<DocLnk> dit( files.children() ); | 541 | // QListIterator<DocLnk> dit( files.children() ); |
539 | // for ( ; dit.current(); ++dit ) { | 542 | // for ( ; dit.current(); ++dit ) { |
540 | // if(dit.current()->linkFile() == setDocFileRef) { | 543 | // if(dit.current()->linkFile() == setDocFileRef) { |
541 | // qDebug(setDocFileRef); | 544 | // qDebug(setDocFileRef); |
542 | // return dit; | 545 | // return dit; |
543 | // } | 546 | // } |
544 | // } | 547 | // } |
545 | // } else | 548 | // } else |
546 | 549 | ||
547 | qDebug("current"); | 550 | qDebug("current"); |
548 | 551 | ||
549 | switch (tabWidget->currentPageIndex()) { | 552 | switch (tabWidget->currentPageIndex()) { |
550 | case 0: //playlist | 553 | case 0: //playlist |
551 | { | 554 | { |
552 | qDebug("playlist"); | 555 | qDebug("playlist"); |
553 | if ( mediaPlayerState->playlist() ) { | 556 | if ( mediaPlayerState->playlist() ) { |
554 | return d->selectedFiles->current(); | 557 | return d->selectedFiles->current(); |
555 | } | 558 | } |
556 | else if ( d->setDocumentUsed && d->current ) { | 559 | else if ( d->setDocumentUsed && d->current ) { |
557 | return d->current; | 560 | return d->current; |
558 | } else { | 561 | } else { |
559 | return &(d->files->selectedDocument()); | 562 | return &(d->files->selectedDocument()); |
560 | } | 563 | } |
561 | } | 564 | } |
562 | break; | 565 | break; |
563 | case 1://audio | 566 | case 1://audio |
564 | { | 567 | { |
565 | qDebug("audioView"); | 568 | qDebug("audioView"); |
566 | QListIterator<DocLnk> dit( files.children() ); | 569 | QListIterator<DocLnk> dit( files.children() ); |
567 | for ( ; dit.current(); ++dit ) { | 570 | for ( ; dit.current(); ++dit ) { |
568 | if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { | 571 | if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { |
569 | qDebug("here"); | 572 | qDebug("here"); |
570 | insanityBool=TRUE; | 573 | insanityBool=TRUE; |
571 | return dit; | 574 | return dit; |
572 | } | 575 | } |
573 | } | 576 | } |
574 | } | 577 | } |
575 | break; | 578 | break; |
576 | case 2: // video | 579 | case 2: // video |
577 | { | 580 | { |
578 | qDebug("videoView"); | 581 | qDebug("videoView"); |
579 | QListIterator<DocLnk> Vdit( vFiles.children() ); | 582 | QListIterator<DocLnk> Vdit( vFiles.children() ); |
580 | for ( ; Vdit.current(); ++Vdit ) { | 583 | for ( ; Vdit.current(); ++Vdit ) { |
581 | if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { | 584 | if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { |
582 | insanityBool=TRUE; | 585 | insanityBool=TRUE; |
583 | return Vdit; | 586 | return Vdit; |
584 | } | 587 | } |
585 | } | 588 | } |
586 | } | 589 | } |
587 | break; | 590 | break; |
588 | }; | 591 | }; |
589 | return 0; | 592 | return 0; |
590 | } | 593 | } |
591 | 594 | ||
592 | bool PlayListWidget::prev() { | 595 | bool PlayListWidget::prev() { |
593 | if ( mediaPlayerState->playlist() ) { | 596 | if ( mediaPlayerState->playlist() ) { |
594 | if ( mediaPlayerState->shuffled() ) { | 597 | if ( mediaPlayerState->shuffled() ) { |
595 | const DocLnk *cur = current(); | 598 | const DocLnk *cur = current(); |
596 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); | 599 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); |
597 | for ( int i = 0; i < j; i++ ) { | 600 | for ( int i = 0; i < j; i++ ) { |
598 | if ( !d->selectedFiles->next() ) | 601 | if ( !d->selectedFiles->next() ) |
599 | d->selectedFiles->first(); | 602 | d->selectedFiles->first(); |
600 | } | 603 | } |
601 | if ( cur == current() ) | 604 | if ( cur == current() ) |
602 | if ( !d->selectedFiles->next() ) | 605 | if ( !d->selectedFiles->next() ) |
603 | d->selectedFiles->first(); | 606 | d->selectedFiles->first(); |
604 | return TRUE; | 607 | return TRUE; |
605 | } else { | 608 | } else { |
606 | if ( !d->selectedFiles->prev() ) { | 609 | if ( !d->selectedFiles->prev() ) { |
607 | if ( mediaPlayerState->looping() ) { | 610 | if ( mediaPlayerState->looping() ) { |
608 | return d->selectedFiles->last(); | 611 | return d->selectedFiles->last(); |
609 | } else { | 612 | } else { |
610 | return FALSE; | 613 | return FALSE; |
611 | } | 614 | } |
612 | } | 615 | } |
613 | return TRUE; | 616 | return TRUE; |
614 | } | 617 | } |
615 | } else { | 618 | } else { |
616 | return mediaPlayerState->looping(); | 619 | return mediaPlayerState->looping(); |
617 | } | 620 | } |
618 | } | 621 | } |
619 | 622 | ||
620 | 623 | ||
621 | bool PlayListWidget::next() { | 624 | bool PlayListWidget::next() { |
622 | if ( mediaPlayerState->playlist() ) { | 625 | if ( mediaPlayerState->playlist() ) { |
623 | if ( mediaPlayerState->shuffled() ) { | 626 | if ( mediaPlayerState->shuffled() ) { |
624 | return prev(); | 627 | return prev(); |
625 | } else { | 628 | } else { |
626 | if ( !d->selectedFiles->next() ) { | 629 | if ( !d->selectedFiles->next() ) { |
627 | if ( mediaPlayerState->looping() ) { | 630 | if ( mediaPlayerState->looping() ) { |
628 | return d->selectedFiles->first(); | 631 | return d->selectedFiles->first(); |
629 | } else { | 632 | } else { |
630 | return FALSE; | 633 | return FALSE; |
631 | } | 634 | } |
632 | } | 635 | } |
633 | return TRUE; | 636 | return TRUE; |
634 | } | 637 | } |
635 | } else { | 638 | } else { |
636 | return mediaPlayerState->looping(); | 639 | return mediaPlayerState->looping(); |
637 | } | 640 | } |
638 | } | 641 | } |
639 | 642 | ||
640 | 643 | ||
641 | bool PlayListWidget::first() { | 644 | bool PlayListWidget::first() { |
642 | if ( mediaPlayerState->playlist() ) | 645 | if ( mediaPlayerState->playlist() ) |
643 | return d->selectedFiles->first(); | 646 | return d->selectedFiles->first(); |
644 | else | 647 | else |
645 | return mediaPlayerState->looping(); | 648 | return mediaPlayerState->looping(); |
646 | } | 649 | } |
647 | 650 | ||
648 | 651 | ||
649 | bool PlayListWidget::last() { | 652 | bool PlayListWidget::last() { |
650 | if ( mediaPlayerState->playlist() ) | 653 | if ( mediaPlayerState->playlist() ) |
651 | return d->selectedFiles->last(); | 654 | return d->selectedFiles->last(); |
652 | else | 655 | else |
653 | return mediaPlayerState->looping(); | 656 | return mediaPlayerState->looping(); |
654 | } | 657 | } |
655 | 658 | ||
656 | 659 | ||
657 | void PlayListWidget::saveList() { | 660 | void PlayListWidget::saveList() { |
658 | writem3u(); | 661 | writem3u(); |
659 | } | 662 | } |
660 | 663 | ||
661 | void PlayListWidget::loadList( const DocLnk & lnk) { | 664 | void PlayListWidget::loadList( const DocLnk & lnk) { |
662 | QString name = lnk.name(); | 665 | QString name = lnk.name(); |
663 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); | 666 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); |
664 | 667 | ||
665 | if( name.length()>0) { | 668 | if( name.length()>0) { |
666 | setCaption("OpiePlayer: "+name); | 669 | setCaption("OpiePlayer: "+name); |
667 | // qDebug("<<<<<<<<<<<<load list "+ lnk.file()); | 670 | // qDebug("<<<<<<<<<<<<load list "+ lnk.file()); |
668 | clearList(); | 671 | clearList(); |
669 | readm3u(lnk.file()); | 672 | readm3u(lnk.file()); |
670 | tabWidget->setCurrentPage(0); | 673 | tabWidget->setCurrentPage(0); |
671 | } | 674 | } |
672 | } | 675 | } |
673 | 676 | ||
674 | void PlayListWidget::setPlaylist( bool shown ) { | 677 | void PlayListWidget::setPlaylist( bool shown ) { |
675 | if ( shown ) | 678 | if ( shown ) |
676 | d->playListFrame->show(); | 679 | d->playListFrame->show(); |
677 | else | 680 | else |
678 | d->playListFrame->hide(); | 681 | d->playListFrame->hide(); |
679 | } | 682 | } |
680 | 683 | ||
681 | void PlayListWidget::setView( char view ) { | 684 | void PlayListWidget::setView( char view ) { |
682 | if ( view == 'l' ) | 685 | if ( view == 'l' ) |
683 | showMaximized(); | 686 | showMaximized(); |
684 | else | 687 | else |
685 | hide(); | 688 | hide(); |
686 | } | 689 | } |
687 | 690 | ||
688 | void PlayListWidget::addSelected() { | 691 | void PlayListWidget::addSelected() { |
689 | qDebug("addSelected"); | 692 | qDebug("addSelected"); |
690 | DocLnk lnk; | 693 | DocLnk lnk; |
691 | QString filename; | 694 | QString filename; |
692 | switch (tabWidget->currentPageIndex()) { | 695 | switch (tabWidget->currentPageIndex()) { |
693 | 696 | ||
694 | case 0: //playlist | 697 | case 0: //playlist |
695 | return; | 698 | return; |
696 | break; | 699 | break; |
697 | case 1: { //audio | 700 | case 1: { //audio |
698 | QListViewItemIterator it( audioView ); | 701 | QListViewItemIterator it( audioView ); |
699 | for ( ; it.current(); ++it ) { | 702 | for ( ; it.current(); ++it ) { |
700 | if ( it.current()->isSelected() ) { | 703 | if ( it.current()->isSelected() ) { |
701 | filename = it.current()->text(3); | 704 | filename = it.current()->text(3); |
702 | lnk.setName( QFileInfo(filename).baseName() ); //sets name | 705 | lnk.setName( QFileInfo(filename).baseName() ); //sets name |
703 | lnk.setFile( filename ); //sets file name | 706 | lnk.setFile( filename ); //sets file name |
704 | d->selectedFiles->addToSelection( lnk); | 707 | d->selectedFiles->addToSelection( lnk); |
705 | } | 708 | } |
706 | } | 709 | } |
707 | audioView->clearSelection(); | 710 | audioView->clearSelection(); |
708 | // d->selectedFiles->next(); | 711 | // d->selectedFiles->next(); |
709 | } | 712 | } |
710 | break; | 713 | break; |
711 | 714 | ||
712 | case 2: { // video | 715 | case 2: { // video |
713 | QListViewItemIterator it( videoView ); | 716 | QListViewItemIterator it( videoView ); |
714 | for ( ; it.current(); ++it ) { | 717 | for ( ; it.current(); ++it ) { |
715 | if ( it.current()->isSelected() ) { | 718 | if ( it.current()->isSelected() ) { |
716 | 719 | ||
717 | filename = it.current()->text(3); | 720 | filename = it.current()->text(3); |
718 | lnk.setName( QFileInfo(filename).baseName() ); //sets name | 721 | lnk.setName( QFileInfo(filename).baseName() ); //sets name |
719 | lnk.setFile( filename ); //sets file name | 722 | lnk.setFile( filename ); //sets file name |
720 | d->selectedFiles->addToSelection( lnk); | 723 | d->selectedFiles->addToSelection( lnk); |
721 | } | 724 | } |
722 | } | 725 | } |
723 | videoView->clearSelection(); | 726 | videoView->clearSelection(); |
724 | } | 727 | } |
725 | break; | 728 | break; |
726 | }; | 729 | }; |
727 | tabWidget->setCurrentPage(0); | 730 | // tabWidget->setCurrentPage(0); |
728 | writeCurrentM3u(); | 731 | writeCurrentM3u(); |
729 | 732 | ||
730 | } | 733 | } |
731 | 734 | ||
732 | void PlayListWidget::removeSelected() { | 735 | void PlayListWidget::removeSelected() { |
733 | d->selectedFiles->removeSelected( ); | 736 | d->selectedFiles->removeSelected( ); |
734 | } | 737 | } |
735 | 738 | ||
736 | void PlayListWidget::playIt( QListViewItem *) { | 739 | void PlayListWidget::playIt( QListViewItem *) { |
737 | // d->setDocumentUsed = FALSE; | 740 | // d->setDocumentUsed = FALSE; |
738 | // mediaPlayerState->curPosition =0; | 741 | // mediaPlayerState->curPosition =0; |
739 | qDebug("playIt"); | 742 | qDebug("playIt"); |
740 | mediaPlayerState->setPlaying(FALSE); | 743 | mediaPlayerState->setPlaying(FALSE); |
741 | mediaPlayerState->setPlaying(TRUE); | 744 | mediaPlayerState->setPlaying(TRUE); |
742 | d->selectedFiles->unSelect(); | 745 | d->selectedFiles->unSelect(); |
743 | } | 746 | } |
744 | 747 | ||
745 | void PlayListWidget::addToSelection( QListViewItem *it) { | 748 | void PlayListWidget::addToSelection( QListViewItem *it) { |
746 | d->setDocumentUsed = FALSE; | 749 | d->setDocumentUsed = FALSE; |
747 | 750 | ||
748 | if(it) { | 751 | if(it) { |
749 | switch ( tabWidget->currentPageIndex()) { | 752 | switch ( tabWidget->currentPageIndex()) { |
750 | case 0: //playlist | 753 | case 0: //playlist |
751 | return; | 754 | return; |
752 | break; | 755 | break; |
753 | }; | 756 | }; |
754 | // case 1: { | 757 | // case 1: { |
755 | DocLnk lnk; | 758 | DocLnk lnk; |
756 | QString filename; | 759 | QString filename; |
757 | 760 | ||
758 | filename=it->text(3); | 761 | filename=it->text(3); |
759 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name | 762 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name |
760 | lnk.setFile( filename ); //sets file name | 763 | lnk.setFile( filename ); //sets file name |
761 | d->selectedFiles->addToSelection( lnk); | 764 | d->selectedFiles->addToSelection( lnk); |
762 | 765 | ||
763 | writeCurrentM3u(); | 766 | writeCurrentM3u(); |
764 | tabWidget->setCurrentPage(0); | 767 | // tabWidget->setCurrentPage(0); |
765 | 768 | ||
766 | } | 769 | } |
767 | } | 770 | } |
768 | 771 | ||
769 | void PlayListWidget::tabChanged(QWidget *) { | 772 | void PlayListWidget::tabChanged(QWidget *) { |
770 | 773 | ||
771 | switch ( tabWidget->currentPageIndex()) { | 774 | switch ( tabWidget->currentPageIndex()) { |
772 | case 0: | 775 | case 0: |
773 | { | 776 | { |
774 | if( !tbDeletePlaylist->isHidden()) | 777 | if( !tbDeletePlaylist->isHidden()) |
775 | tbDeletePlaylist->hide(); | 778 | tbDeletePlaylist->hide(); |
776 | d->tbRemoveFromList->setEnabled(TRUE); | 779 | d->tbRemoveFromList->setEnabled(TRUE); |
777 | d->tbAddToList->setEnabled(FALSE); | 780 | d->tbAddToList->setEnabled(FALSE); |
778 | } | 781 | } |
779 | break; | 782 | break; |
780 | case 1: | 783 | case 1: |
781 | { | 784 | { |
782 | audioView->clear(); | 785 | audioView->clear(); |
783 | populateAudioView(); | 786 | populateAudioView(); |
784 | 787 | ||
785 | if( !tbDeletePlaylist->isHidden()) | 788 | if( !tbDeletePlaylist->isHidden()) |
786 | tbDeletePlaylist->hide(); | 789 | tbDeletePlaylist->hide(); |
787 | d->tbRemoveFromList->setEnabled(FALSE); | 790 | d->tbRemoveFromList->setEnabled(FALSE); |
788 | d->tbAddToList->setEnabled(TRUE); | 791 | d->tbAddToList->setEnabled(TRUE); |
789 | } | 792 | } |
790 | break; | 793 | break; |
791 | case 2: | 794 | case 2: |
792 | { | 795 | { |
793 | videoView->clear(); | 796 | videoView->clear(); |
794 | populateVideoView(); | 797 | populateVideoView(); |
795 | if( !tbDeletePlaylist->isHidden()) | 798 | if( !tbDeletePlaylist->isHidden()) |
796 | tbDeletePlaylist->hide(); | 799 | tbDeletePlaylist->hide(); |
797 | d->tbRemoveFromList->setEnabled(FALSE); | 800 | d->tbRemoveFromList->setEnabled(FALSE); |
798 | d->tbAddToList->setEnabled(TRUE); | 801 | d->tbAddToList->setEnabled(TRUE); |
799 | } | 802 | } |
800 | break; | 803 | break; |
801 | case 3: | 804 | case 3: |
802 | { | 805 | { |
803 | if( tbDeletePlaylist->isHidden()) | 806 | if( tbDeletePlaylist->isHidden()) |
804 | tbDeletePlaylist->show(); | 807 | tbDeletePlaylist->show(); |
805 | playLists->reread(); | 808 | playLists->reread(); |
806 | } | 809 | } |
807 | break; | 810 | break; |
808 | }; | 811 | }; |
809 | } | 812 | } |
810 | 813 | ||
811 | void PlayListWidget::btnPlay(bool b) { | 814 | void PlayListWidget::btnPlay(bool b) { |
812 | qDebug("<<<<<<<<<<<<<<<BtnPlay"); | 815 | qDebug("<<<<<<<<<<<<<<<BtnPlay"); |
813 | // mediaPlayerState->setPlaying(b); | 816 | // mediaPlayerState->setPlaying(b); |
814 | switch ( tabWidget->currentPageIndex()) { | 817 | switch ( tabWidget->currentPageIndex()) { |
815 | case 0: | 818 | case 0: |
816 | { | 819 | { |
817 | qDebug("1"); | 820 | qDebug("1"); |
818 | // if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 | 821 | // if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 |
819 | // if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) { | 822 | // if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) { |
820 | // QMessageBox::message("Note","You are trying to play\na malformed url."); | 823 | // QMessageBox::message("Note","You are trying to play\na malformed url."); |
821 | // } else { | 824 | // } else { |
822 | mediaPlayerState->setPlaying(b); | 825 | mediaPlayerState->setPlaying(b); |
823 | insanityBool=FALSE; | 826 | insanityBool=FALSE; |
824 | qDebug("insanity"); | 827 | qDebug("insanity"); |
825 | // } | 828 | // } |
826 | } | 829 | } |
827 | break; | 830 | break; |
828 | case 1: | 831 | case 1: |
829 | { | 832 | { |
830 | qDebug("2"); | 833 | qDebug("2"); |
831 | // d->selectedFiles->unSelect(); | 834 | // d->selectedFiles->unSelect(); |
832 | addToSelection( audioView->currentItem() ); | 835 | addToSelection( audioView->currentItem() ); |
833 | mediaPlayerState->setPlaying(true); | 836 | mediaPlayerState->setPlaying(true); |
834 | d->selectedFiles->removeSelected( ); | 837 | d->selectedFiles->removeSelected( ); |
835 | d->selectedFiles->unSelect(); | 838 | d->selectedFiles->unSelect(); |
836 | tabWidget->setCurrentPage(1); | 839 | tabWidget->setCurrentPage(1); |
837 | insanityBool=FALSE; | 840 | insanityBool=FALSE; |
838 | }// audioView->clearSelection(); | 841 | }// audioView->clearSelection(); |
839 | break; | 842 | break; |
840 | case 2: | 843 | case 2: |
841 | { | 844 | { |
842 | qDebug("3"); | 845 | qDebug("3"); |
843 | 846 | ||
844 | addToSelection( videoView->currentItem() ); | 847 | addToSelection( videoView->currentItem() ); |
845 | mediaPlayerState->setPlaying(true); | 848 | mediaPlayerState->setPlaying(true); |
846 | // qApp->processEvents(); | 849 | // qApp->processEvents(); |
847 | d->selectedFiles->removeSelected( ); | 850 | d->selectedFiles->removeSelected( ); |
848 | d->selectedFiles->unSelect(); | 851 | d->selectedFiles->unSelect(); |
849 | tabWidget->setCurrentPage(2); | 852 | tabWidget->setCurrentPage(2); |
850 | insanityBool=FALSE; | 853 | insanityBool=FALSE; |
851 | }// videoView->clearSelection(); | 854 | }// videoView->clearSelection(); |
852 | break; | 855 | break; |
853 | }; | 856 | }; |
854 | 857 | ||
855 | } | 858 | } |
856 | 859 | ||
857 | void PlayListWidget::deletePlaylist() { | 860 | void PlayListWidget::deletePlaylist() { |
858 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), | 861 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), |
859 | (tr("You really want to delete\nthis playlist?")), | 862 | (tr("You really want to delete\nthis playlist?")), |
860 | (tr("Yes")), (tr("No")), 0 )){ | 863 | (tr("Yes")), (tr("No")), 0 )){ |
861 | case 0: // Yes clicked, | 864 | case 0: // Yes clicked, |
862 | QFile().remove(playLists->selectedDocument().file()); | 865 | QFile().remove(playLists->selectedDocument().file()); |
863 | QFile().remove(playLists->selectedDocument().linkFile()); | 866 | QFile().remove(playLists->selectedDocument().linkFile()); |
864 | playLists->reread(); | 867 | playLists->reread(); |
865 | break; | 868 | break; |
866 | case 1: // Cancel | 869 | case 1: // Cancel |
867 | break; | 870 | break; |
868 | }; | 871 | }; |
869 | } | 872 | } |
870 | 873 | ||
871 | void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint&, int ) | 874 | void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint&, int ) |
872 | { | 875 | { |
873 | switch (mouse) { | 876 | switch (mouse) { |
874 | case 1: | 877 | case 1: |
875 | break; | 878 | break; |
876 | case 2:{ | 879 | case 2:{ |
877 | 880 | ||
878 | QPopupMenu m; | 881 | QPopupMenu m; |
879 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); | 882 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); |
880 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); | 883 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); |
881 | m.insertSeparator(); | 884 | m.insertSeparator(); |
882 | if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) | 885 | if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) |
883 | m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); | 886 | m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); |
884 | 887 | ||
885 | m.exec( QCursor::pos() ); | 888 | m.exec( QCursor::pos() ); |
886 | } | 889 | } |
887 | break; | 890 | break; |
888 | }; | 891 | }; |
889 | } | 892 | } |
890 | 893 | ||
891 | void PlayListWidget::playSelected() | 894 | void PlayListWidget::playSelected() |
892 | { | 895 | { |
893 | qDebug("playSelected"); | 896 | qDebug("playSelected"); |
894 | btnPlay( true); | 897 | btnPlay( true); |
895 | // d->selectedFiles->unSelect(); | 898 | // d->selectedFiles->unSelect(); |
896 | } | 899 | } |
897 | 900 | ||
898 | void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint&, int) | 901 | void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint&, int) |
899 | { | 902 | { |
900 | switch (mouse) { | 903 | switch (mouse) { |
901 | case 1: | 904 | case 1: |
902 | 905 | ||
903 | break; | 906 | break; |
904 | case 2:{ | 907 | case 2:{ |
905 | QPopupMenu m; | 908 | QPopupMenu m; |
906 | m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); | 909 | m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); |
907 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); | 910 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); |
908 | // m.insertSeparator(); | 911 | // m.insertSeparator(); |
909 | // m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); | 912 | // m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); |
910 | m.exec( QCursor::pos() ); | 913 | m.exec( QCursor::pos() ); |
911 | } | 914 | } |
912 | break; | 915 | break; |
913 | }; | 916 | }; |
914 | 917 | ||
915 | } | 918 | } |
916 | 919 | ||
917 | void PlayListWidget::listDelete() { | 920 | void PlayListWidget::listDelete() { |
918 | Config cfg( "OpiePlayer" ); | 921 | Config cfg( "OpiePlayer" ); |
919 | cfg.setGroup("PlayList"); | 922 | cfg.setGroup("PlayList"); |
920 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | 923 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); |
921 | QString file; | 924 | QString file; |
922 | // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 925 | // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
923 | switch ( tabWidget->currentPageIndex()) { | 926 | switch ( tabWidget->currentPageIndex()) { |
924 | case 0: | 927 | case 0: |
925 | break; | 928 | break; |
926 | case 1: | 929 | case 1: |
927 | { | 930 | { |
928 | file = audioView->currentItem()->text(0); | 931 | file = audioView->currentItem()->text(0); |
929 | QListIterator<DocLnk> Pdit( files.children() ); | 932 | QListIterator<DocLnk> Pdit( files.children() ); |
930 | for ( ; Pdit.current(); ++Pdit ) { | 933 | for ( ; Pdit.current(); ++Pdit ) { |
931 | if( Pdit.current()->name() == file) { | 934 | if( Pdit.current()->name() == file) { |
932 | LnkProperties prop( Pdit.current() ); | 935 | LnkProperties prop( Pdit.current() ); |
933 | prop.showMaximized(); | 936 | prop.showMaximized(); |
934 | prop.exec(); | 937 | prop.exec(); |
935 | } | 938 | } |
936 | } | 939 | } |
937 | populateAudioView(); | 940 | populateAudioView(); |
938 | } | 941 | } |
939 | break; | 942 | break; |
940 | case 2: | 943 | case 2: |
941 | { | 944 | { |
942 | // file = videoView->selectedItem()->text(0); | 945 | // file = videoView->selectedItem()->text(0); |
943 | // for ( int i = 0; i < noOfFiles; i++ ) { | 946 | // for ( int i = 0; i < noOfFiles; i++ ) { |
944 | // QString entryName; | 947 | // QString entryName; |
945 | // entryName.sprintf( "File%i", i + 1 ); | 948 | // entryName.sprintf( "File%i", i + 1 ); |
946 | // QString linkFile = cfg.readEntry( entryName ); | 949 | // QString linkFile = cfg.readEntry( entryName ); |
947 | // AppLnk lnk( AppLnk(linkFile)); | 950 | // AppLnk lnk( AppLnk(linkFile)); |
948 | // if( lnk.name() == file ) { | 951 | // if( lnk.name() == file ) { |
949 | // LnkProperties prop( &lnk); | 952 | // LnkProperties prop( &lnk); |
950 | // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); | 953 | // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); |
951 | // prop.showMaximized(); | 954 | // prop.showMaximized(); |
952 | // prop.exec(); | 955 | // prop.exec(); |
953 | // } | 956 | // } |
954 | // } | 957 | // } |
955 | } | 958 | } |
956 | break; | 959 | break; |
957 | }; | 960 | }; |
958 | } | 961 | } |
959 | 962 | ||
960 | void PlayListWidget::scanForAudio() { | 963 | void PlayListWidget::scanForAudio() { |
961 | // qDebug("scan for audio"); | 964 | // qDebug("scan for audio"); |
962 | files.detachChildren(); | 965 | files.detachChildren(); |
963 | QListIterator<DocLnk> sdit( files.children() ); | 966 | QListIterator<DocLnk> sdit( files.children() ); |
964 | for ( ; sdit.current(); ++sdit ) { | 967 | for ( ; sdit.current(); ++sdit ) { |
965 | delete sdit.current(); | 968 | delete sdit.current(); |
966 | } | 969 | } |
967 | Global::findDocuments( &files, audioMimes); | 970 | Global::findDocuments( &files, audioMimes); |
968 | audioScan = true; | 971 | audioScan = true; |
969 | } | 972 | } |
970 | void PlayListWidget::scanForVideo() { | 973 | void PlayListWidget::scanForVideo() { |
971 | // qDebug("scan for video"); | 974 | // qDebug("scan for video"); |
972 | vFiles.detachChildren(); | 975 | vFiles.detachChildren(); |
973 | QListIterator<DocLnk> sdit( vFiles.children() ); | 976 | QListIterator<DocLnk> sdit( vFiles.children() ); |
974 | for ( ; sdit.current(); ++sdit ) { | 977 | for ( ; sdit.current(); ++sdit ) { |
975 | delete sdit.current(); | 978 | delete sdit.current(); |
976 | } | 979 | } |
977 | Global::findDocuments(&vFiles, "video/*"); | 980 | Global::findDocuments(&vFiles, "video/*"); |
978 | videoScan = true; | 981 | videoScan = true; |
979 | } | 982 | } |
980 | 983 | ||
981 | void PlayListWidget::populateAudioView() { | 984 | void PlayListWidget::populateAudioView() { |
982 | 985 | ||
983 | audioView->clear(); | 986 | audioView->clear(); |
984 | StorageInfo storageInfo; | 987 | StorageInfo storageInfo; |
985 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 988 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
986 | if(!audioScan) scanForAudio(); | 989 | if(!audioScan) scanForAudio(); |
987 | 990 | ||
988 | QListIterator<DocLnk> dit( files.children() ); | 991 | QListIterator<DocLnk> dit( files.children() ); |
989 | QListIterator<FileSystem> it ( fs ); | 992 | QListIterator<FileSystem> it ( fs ); |
990 | 993 | ||
991 | QString storage; | 994 | QString storage; |
992 | for ( ; dit.current(); ++dit ) { | 995 | for ( ; dit.current(); ++dit ) { |
993 | for( ; it.current(); ++it ){ | 996 | for( ; it.current(); ++it ){ |
994 | const QString name = (*it)->name(); | 997 | const QString name = (*it)->name(); |
995 | const QString path = (*it)->path(); | 998 | const QString path = (*it)->path(); |
996 | if(dit.current()->file().find(path) != -1 ) storage=name; | 999 | if(dit.current()->file().find(path) != -1 ) storage=name; |
997 | } | 1000 | } |
998 | 1001 | ||
999 | QListViewItem * newItem; | 1002 | QListViewItem * newItem; |
1000 | if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { | 1003 | if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { |
1001 | long size; | 1004 | long size; |
1002 | if( dit.current()->file().left(4) == "http" ) | 1005 | if( dit.current()->file().left(4) == "http" ) |
1003 | size=0; | 1006 | size=0; |
1004 | else | 1007 | else |
1005 | size = QFile( dit.current()->file() ).size(); | 1008 | size = QFile( dit.current()->file() ).size(); |
1006 | // qDebug(dit.current()->name()); | 1009 | // qDebug(dit.current()->name()); |
1007 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), | 1010 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), |
1008 | QString::number(size ), storage, dit.current()->file()); | 1011 | QString::number(size ), storage, dit.current()->file()); |
1009 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); | 1012 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); |
1010 | } | 1013 | } |
1011 | } | 1014 | } |
1012 | 1015 | ||
1013 | } | 1016 | } |
1014 | 1017 | ||
1015 | void PlayListWidget::populateVideoView() { | 1018 | void PlayListWidget::populateVideoView() { |
1016 | videoView->clear(); | 1019 | videoView->clear(); |
1017 | StorageInfo storageInfo; | 1020 | StorageInfo storageInfo; |
1018 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1021 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
1019 | 1022 | ||
1020 | if(!videoScan ) scanForVideo(); | 1023 | if(!videoScan ) scanForVideo(); |
1021 | 1024 | ||
1022 | QListIterator<DocLnk> Vdit( vFiles.children() ); | 1025 | QListIterator<DocLnk> Vdit( vFiles.children() ); |
1023 | QListIterator<FileSystem> it ( fs ); | 1026 | QListIterator<FileSystem> it ( fs ); |
1024 | videoView->clear(); | 1027 | videoView->clear(); |
1025 | QString storage; | 1028 | QString storage; |
1026 | for ( ; Vdit.current(); ++Vdit ) { | 1029 | for ( ; Vdit.current(); ++Vdit ) { |
1027 | for( ; it.current(); ++it ){ | 1030 | for( ; it.current(); ++it ){ |
1028 | const QString name = (*it)->name(); | 1031 | const QString name = (*it)->name(); |
1029 | const QString path = (*it)->path(); | 1032 | const QString path = (*it)->path(); |
1030 | if( Vdit.current()->file().find(path) != -1 ) storage=name; | 1033 | if( Vdit.current()->file().find(path) != -1 ) storage=name; |
1031 | } | 1034 | } |
1032 | 1035 | ||
1033 | QListViewItem * newItem; | 1036 | QListViewItem * newItem; |
1034 | if ( QFile( Vdit.current()->file()).exists() ) { | 1037 | if ( QFile( Vdit.current()->file()).exists() ) { |
1035 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), | 1038 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), |
1036 | QString::number( QFile( Vdit.current()->file() ).size() ), | 1039 | QString::number( QFile( Vdit.current()->file() ).size() ), |
1037 | storage, Vdit.current()->file()); | 1040 | storage, Vdit.current()->file()); |
1038 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); | 1041 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); |
1039 | } | 1042 | } |
1040 | } | 1043 | } |
1041 | } | 1044 | } |
1042 | 1045 | ||
1043 | void PlayListWidget::openFile() { | 1046 | void PlayListWidget::openFile() { |
1044 | qDebug("<<<<<<<<<OPEN File"); | 1047 | qDebug("<<<<<<<<<OPEN File"); |
1045 | QString filename, name; | 1048 | QString filename, name; |
1046 | InputDialog *fileDlg; | 1049 | InputDialog *fileDlg; |
1047 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); | 1050 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); |
1048 | fileDlg->exec(); | 1051 | fileDlg->exec(); |
1049 | if( fileDlg->result() == 1 ) { | 1052 | if( fileDlg->result() == 1 ) { |
1050 | filename = fileDlg->text(); | 1053 | filename = fileDlg->text(); |
1051 | qDebug( "Selected filename is " + filename ); | 1054 | qDebug( "Selected filename is " + filename ); |
1052 | // Om3u *m3uList; | 1055 | // Om3u *m3uList; |
1053 | DocLnk lnk; | 1056 | DocLnk lnk; |
1054 | Config cfg( "OpiePlayer" ); | 1057 | Config cfg( "OpiePlayer" ); |
1055 | cfg.setGroup("PlayList"); | 1058 | cfg.setGroup("PlayList"); |
1056 | 1059 | ||
1057 | if(filename.left(4) == "http") { | 1060 | if(filename.left(4) == "http") { |
1058 | QString m3uFile, m3uFilePath; | 1061 | QString m3uFile, m3uFilePath; |
1059 | if(filename.find(":",8,TRUE) != -1) { //found a port | 1062 | if(filename.find(":",8,TRUE) != -1) { //found a port |
1060 | m3uFile = filename.left( filename.find( ":",8,TRUE)); | 1063 | m3uFile = filename.left( filename.find( ":",8,TRUE)); |
1061 | m3uFile = m3uFile.right( 7); | 1064 | m3uFile = m3uFile.right( 7); |
1062 | } else if(filename.left(4) == "http"){ | 1065 | } else if(filename.left(4) == "http"){ |
1063 | m3uFile=filename; | 1066 | m3uFile=filename; |
1064 | m3uFile = m3uFile.right( m3uFile.length() - 7); | 1067 | m3uFile = m3uFile.right( m3uFile.length() - 7); |
1065 | } else{ | 1068 | } else{ |
1066 | m3uFile=filename; | 1069 | m3uFile=filename; |
1067 | } | 1070 | } |
1068 | 1071 | ||
1069 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"+ m3uFile); | 1072 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"+ m3uFile); |
1070 | lnk.setName( filename ); //sets name | 1073 | lnk.setName( filename ); //sets name |
1071 | lnk.setFile( filename ); //sets file name | 1074 | lnk.setFile( filename ); //sets file name |
1072 | lnk.setIcon("opieplayer2/musicfile"); | 1075 | lnk.setIcon("opieplayer2/musicfile"); |
1073 | d->selectedFiles->addToSelection( lnk ); | 1076 | d->selectedFiles->addToSelection( lnk ); |
1074 | writeCurrentM3u(); | 1077 | writeCurrentM3u(); |
1075 | } | 1078 | } |
1076 | else if( filename.right( 3) == "m3u" ) { | 1079 | else if( filename.right( 3) == "m3u" ) { |
1077 | readm3u( filename ); | 1080 | readm3u( filename ); |
1078 | 1081 | ||
1079 | } else if( filename.right(3) == "pls" ) { | 1082 | } else if( filename.right(3) == "pls" ) { |
1080 | readPls( filename ); | 1083 | readPls( filename ); |
1081 | } else { | 1084 | } else { |
1082 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name | 1085 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name |
1083 | lnk.setFile( filename ); //sets file name | 1086 | lnk.setFile( filename ); //sets file name |
1084 | d->selectedFiles->addToSelection( lnk); | 1087 | d->selectedFiles->addToSelection( lnk); |
1085 | writeCurrentM3u(); | 1088 | writeCurrentM3u(); |
1086 | } | 1089 | } |
1087 | } | 1090 | } |
1088 | 1091 | ||
1089 | if( fileDlg ) { | 1092 | if( fileDlg ) { |
1090 | delete fileDlg; | 1093 | delete fileDlg; |
1091 | } | 1094 | } |
1092 | } | 1095 | } |
1093 | 1096 | ||
1094 | 1097 | ||
1095 | /* | 1098 | /* |
1096 | reads m3u and shows files/urls to playlist widget */ | 1099 | reads m3u and shows files/urls to playlist widget */ |
1097 | void PlayListWidget::readm3u( const QString &filename ) { | 1100 | void PlayListWidget::readm3u( const QString &filename ) { |
1098 | qDebug( "read m3u filename " + filename ); | 1101 | qDebug( "read m3u filename " + filename ); |
1099 | 1102 | ||
1100 | Om3u *m3uList; | 1103 | Om3u *m3uList; |
1101 | QString s, name; | 1104 | QString s, name; |
1102 | m3uList = new Om3u( filename, IO_ReadOnly ); | 1105 | m3uList = new Om3u( filename, IO_ReadOnly ); |
1103 | m3uList->readM3u(); | 1106 | m3uList->readM3u(); |
1104 | DocLnk lnk; | 1107 | DocLnk lnk; |
1105 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | 1108 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { |
1106 | s = *it; | 1109 | s = *it; |
1107 | // qDebug("reading "+ s); | 1110 | // qDebug("reading "+ s); |
1108 | if(s.left(4)=="http") { | 1111 | if(s.left(4)=="http") { |
1109 | lnk.setName( s ); //sets file name | 1112 | lnk.setName( s ); //sets file name |
1110 | lnk.setIcon("opieplayer2/musicfile"); | 1113 | lnk.setIcon("opieplayer2/musicfile"); |
1111 | if(s.right(4) != '.' || s.right(5) != '.') | 1114 | if(s.right(4) != '.' || s.right(5) != '.') |
1112 | lnk.setFile( s+"/"); //if url with no extension | 1115 | lnk.setFile( s+"/"); //if url with no extension |
1113 | else | 1116 | else |
1114 | lnk.setFile( s ); //sets file name | 1117 | lnk.setFile( s ); //sets file name |
1115 | 1118 | ||
1116 | } else { | 1119 | } else { |
1117 | // if( QFileInfo( s ).exists() ) { | 1120 | // if( QFileInfo( s ).exists() ) { |
1118 | lnk.setName( fullBaseName ( QFileInfo(s))); | 1121 | lnk.setName( fullBaseName ( QFileInfo(s))); |
1119 | // if(s.right(4) == '.') {//if regular file | 1122 | // if(s.right(4) == '.') {//if regular file |
1120 | if(s.left(1) != "/") { | 1123 | if(s.left(1) != "/") { |
1121 | // qDebug("set link "+QFileInfo(filename).dirPath()+"/"+s); | 1124 | // qDebug("set link "+QFileInfo(filename).dirPath()+"/"+s); |
1122 | lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); | 1125 | lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); |
1123 | lnk.setIcon("SoundPlayer"); | 1126 | lnk.setIcon("SoundPlayer"); |
1124 | } else { | 1127 | } else { |
1125 | // qDebug("set link2 "+s); | 1128 | // qDebug("set link2 "+s); |
1126 | lnk.setFile( s); | 1129 | lnk.setFile( s); |
1127 | lnk.setIcon("SoundPlayer"); | 1130 | lnk.setIcon("SoundPlayer"); |
1128 | } | 1131 | } |
1129 | } | 1132 | } |
1130 | d->selectedFiles->addToSelection( lnk ); | 1133 | d->selectedFiles->addToSelection( lnk ); |
1131 | } | 1134 | } |
1132 | Config config( "OpiePlayer" ); | 1135 | Config config( "OpiePlayer" ); |
1133 | config.setGroup( "PlayList" ); | 1136 | config.setGroup( "PlayList" ); |
1134 | 1137 | ||
1135 | config.writeEntry("CurrentPlaylist",filename); | 1138 | config.writeEntry("CurrentPlaylist",filename); |
1136 | config.write(); | 1139 | config.write(); |
1137 | currentPlayList=filename; | 1140 | currentPlayList=filename; |
1138 | 1141 | ||
1139 | // m3uList->write(); | 1142 | // m3uList->write(); |
1140 | m3uList->close(); | 1143 | m3uList->close(); |
1141 | if(m3uList) delete m3uList; | 1144 | if(m3uList) delete m3uList; |
1142 | 1145 | ||
1143 | d->selectedFiles->setSelectedItem( s); | 1146 | d->selectedFiles->setSelectedItem( s); |
1144 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); | 1147 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); |
1145 | 1148 | ||
1146 | } | 1149 | } |
1147 | 1150 | ||
1148 | /* | 1151 | /* |
1149 | reads pls and adds files/urls to playlist */ | 1152 | reads pls and adds files/urls to playlist */ |
1150 | void PlayListWidget::readPls( const QString &filename ) { | 1153 | void PlayListWidget::readPls( const QString &filename ) { |
1151 | 1154 | ||
1152 | qDebug( "pls filename is " + filename ); | 1155 | qDebug( "pls filename is " + filename ); |
1153 | Om3u *m3uList; | 1156 | Om3u *m3uList; |
1154 | QString s, name; | 1157 | QString s, name; |
1155 | m3uList = new Om3u( filename, IO_ReadOnly ); | 1158 | m3uList = new Om3u( filename, IO_ReadOnly ); |
1156 | m3uList->readPls(); | 1159 | m3uList->readPls(); |
1157 | 1160 | ||
1158 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | 1161 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { |
1159 | s = *it; | 1162 | s = *it; |
1160 | // s.replace( QRegExp( "%20" )," " ); | 1163 | // s.replace( QRegExp( "%20" )," " ); |
1161 | DocLnk lnk( s ); | 1164 | DocLnk lnk( s ); |
1162 | QFileInfo f( s ); | 1165 | QFileInfo f( s ); |
1163 | QString name = fullBaseName ( f); | 1166 | QString name = fullBaseName ( f); |
1164 | 1167 | ||
1165 | if( name.left( 4 ) == "http" ) { | 1168 | if( name.left( 4 ) == "http" ) { |
1166 | name = s.right( s.length() - 7); | 1169 | name = s.right( s.length() - 7); |
1167 | } else { | 1170 | } else { |
1168 | name = s; | 1171 | name = s; |
1169 | } | 1172 | } |
1170 | 1173 | ||
1171 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); | 1174 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); |
1172 | 1175 | ||
1173 | lnk.setName( name ); | 1176 | lnk.setName( name ); |
1174 | if( s.at( s.length() - 4) == '.') {// if this is probably a file | 1177 | if( s.at( s.length() - 4) == '.') {// if this is probably a file |
1175 | lnk.setFile( s ); | 1178 | lnk.setFile( s ); |
1176 | } else { //if its a url | 1179 | } else { //if its a url |
1177 | if( name.right( 1 ).find( '/' ) == -1) { | 1180 | if( name.right( 1 ).find( '/' ) == -1) { |
1178 | s += "/"; | 1181 | s += "/"; |
1179 | } | 1182 | } |
1180 | lnk.setFile( s ); | 1183 | lnk.setFile( s ); |
1181 | } | 1184 | } |
1182 | lnk.setType( "audio/x-mpegurl" ); | 1185 | lnk.setType( "audio/x-mpegurl" ); |
1183 | 1186 | ||
1184 | lnk.writeLink(); | 1187 | lnk.writeLink(); |
1185 | d->selectedFiles->addToSelection( lnk ); | 1188 | d->selectedFiles->addToSelection( lnk ); |
1186 | } | 1189 | } |
1187 | 1190 | ||
1188 | m3uList->close(); | 1191 | m3uList->close(); |
1189 | if(m3uList) delete m3uList; | 1192 | if(m3uList) delete m3uList; |
1190 | } | 1193 | } |
1191 | 1194 | ||
1192 | /* | 1195 | /* |
1193 | writes current playlist to current m3u file */ | 1196 | writes current playlist to current m3u file */ |
1194 | void PlayListWidget::writeCurrentM3u() { | 1197 | void PlayListWidget::writeCurrentM3u() { |
1195 | qDebug("writing to current m3u"); | 1198 | qDebug("writing to current m3u"); |
1196 | Config cfg( "OpiePlayer" ); | 1199 | Config cfg( "OpiePlayer" ); |
1197 | cfg.setGroup("PlayList"); | 1200 | cfg.setGroup("PlayList"); |
1198 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | 1201 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); |
1199 | Om3u *m3uList; | 1202 | Om3u *m3uList; |
1200 | m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); | 1203 | m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); |
1201 | 1204 | ||
1202 | if( d->selectedFiles->first()) { | 1205 | if( d->selectedFiles->first()) { |
1203 | do { | 1206 | do { |
1204 | qDebug( "writeCurrentM3u " +d->selectedFiles->current()->file()); | 1207 | qDebug( "writeCurrentM3u " +d->selectedFiles->current()->file()); |
1205 | m3uList->add( d->selectedFiles->current()->file() ); | 1208 | m3uList->add( d->selectedFiles->current()->file() ); |
1206 | } | 1209 | } |
1207 | while ( d->selectedFiles->next() ); | 1210 | while ( d->selectedFiles->next() ); |
1208 | qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" ); | 1211 | qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" ); |
1209 | m3uList->write(); | 1212 | m3uList->write(); |
1210 | m3uList->close(); | 1213 | m3uList->close(); |
1211 | 1214 | ||
1212 | if(m3uList) delete m3uList; | 1215 | if(m3uList) delete m3uList; |
1213 | } | 1216 | } |
1214 | } | 1217 | } |
1215 | 1218 | ||
1216 | /* | 1219 | /* |
1217 | writes current playlist to m3u file */ | 1220 | writes current playlist to m3u file */ |
1218 | void PlayListWidget::writem3u() { | 1221 | void PlayListWidget::writem3u() { |
1219 | InputDialog *fileDlg; | 1222 | InputDialog *fileDlg; |
1220 | fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); | 1223 | fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); |
1221 | fileDlg->exec(); | 1224 | fileDlg->exec(); |
1222 | QString name, filename, list; | 1225 | QString name, filename, list; |
1223 | Om3u *m3uList; | 1226 | Om3u *m3uList; |
1224 | 1227 | ||
1225 | if( fileDlg->result() == 1 ) { | 1228 | if( fileDlg->result() == 1 ) { |
1226 | name = fileDlg->text(); | 1229 | name = fileDlg->text(); |
1227 | // qDebug( filename ); | 1230 | // qDebug( filename ); |
1228 | if( name.find("/",0,true) != -1) {// assume they specify a file path | 1231 | if( name.find("/",0,true) != -1) {// assume they specify a file path |
1229 | filename = name; | 1232 | filename = name; |
1230 | name = name.right(name.length()- name.findRev("/",-1,true) - 1 ); | 1233 | name = name.right(name.length()- name.findRev("/",-1,true) - 1 ); |
1231 | } | 1234 | } |
1232 | else //otherwise dump it somewhere noticable | 1235 | else //otherwise dump it somewhere noticable |
1233 | filename = QPEApplication::documentDir() + "/" + name; | 1236 | filename = QPEApplication::documentDir() + "/" + name; |
1234 | 1237 | ||
1235 | if( filename.right( 3 ) != "m3u" ) //needs filename extension | 1238 | if( filename.right( 3 ) != "m3u" ) //needs filename extension |
1236 | filename += ".m3u"; | 1239 | filename += ".m3u"; |
1237 | 1240 | ||
1238 | if( d->selectedFiles->first()) { | 1241 | if( d->selectedFiles->first()) { |
1239 | m3uList = new Om3u(filename, IO_ReadWrite); | 1242 | m3uList = new Om3u(filename, IO_ReadWrite); |
1240 | 1243 | ||
1241 | do { | 1244 | do { |
1242 | m3uList->add( d->selectedFiles->current()->file()); | 1245 | m3uList->add( d->selectedFiles->current()->file()); |
1243 | } | 1246 | } |
1244 | while ( d->selectedFiles->next() ); | 1247 | while ( d->selectedFiles->next() ); |
1245 | // qDebug( list ); | 1248 | // qDebug( list ); |
1246 | m3uList->write(); | 1249 | m3uList->write(); |
1247 | m3uList->close(); | 1250 | m3uList->close(); |
1248 | if(m3uList) delete m3uList; | 1251 | if(m3uList) delete m3uList; |
1249 | 1252 | ||
1250 | if(fileDlg) delete fileDlg; | 1253 | if(fileDlg) delete fileDlg; |
1251 | 1254 | ||
1252 | DocLnk lnk; | 1255 | DocLnk lnk; |
1253 | lnk.setFile( filename); | 1256 | lnk.setFile( filename); |
1254 | lnk.setIcon("opieplayer2/playlist2"); | 1257 | lnk.setIcon("opieplayer2/playlist2"); |
1255 | lnk.setName( name); //sets file name | 1258 | lnk.setName( name); //sets file name |
1256 | 1259 | ||
1257 | // qDebug(filename); | 1260 | // qDebug(filename); |
1258 | Config config( "OpiePlayer" ); | 1261 | Config config( "OpiePlayer" ); |
1259 | config.setGroup( "PlayList" ); | 1262 | config.setGroup( "PlayList" ); |
1260 | 1263 | ||
1261 | config.writeEntry("CurrentPlaylist",filename); | 1264 | config.writeEntry("CurrentPlaylist",filename); |
1262 | currentPlayList=filename; | 1265 | currentPlayList=filename; |
1263 | 1266 | ||
1264 | if(!lnk.writeLink()) { | 1267 | if(!lnk.writeLink()) { |
1265 | qDebug("Writing doclink did not work"); | 1268 | qDebug("Writing doclink did not work"); |
1266 | } | 1269 | } |
1267 | 1270 | ||
1268 | setCaption(tr("OpiePlayer: ") + name); | 1271 | setCaption(tr("OpiePlayer: ") + name); |
1269 | } | 1272 | } |
1270 | } | 1273 | } |
1271 | } | 1274 | } |
1272 | 1275 | ||
1273 | 1276 | ||
1274 | void PlayListWidget::keyReleaseEvent( QKeyEvent *e) | 1277 | void PlayListWidget::keyReleaseEvent( QKeyEvent *e) |
1275 | { | 1278 | { |
1276 | switch ( e->key() ) { | 1279 | switch ( e->key() ) { |