-rw-r--r-- | core/multimedia/opieplayer/audiodevice.cpp | 16 | ||||
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 33 | ||||
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol.cpp | 24 | ||||
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol_threaded.cpp | 578 | ||||
-rw-r--r-- | core/multimedia/opieplayer/mediaplayer.cpp | 6 | ||||
-rw-r--r-- | core/multimedia/opieplayer/mediaplayerstate.cpp | 2 | ||||
-rw-r--r-- | core/multimedia/opieplayer/om3u.cpp | 60 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistselection.cpp | 2 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 1300 | ||||
-rw-r--r-- | core/multimedia/opieplayer/videowidget.cpp | 16 |
10 files changed, 1006 insertions, 1031 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp index 73e41dc..d01d2ba 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/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index a1973e9..b187cb4 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -1,513 +1,516 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | 23 | ||
24 | #include <qwidget.h> | 24 | #include <qwidget.h> |
25 | #include <qpixmap.h> | 25 | #include <qpixmap.h> |
26 | #include <qbutton.h> | 26 | #include <qbutton.h> |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | #include <qframe.h> | 28 | #include <qframe.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qdir.h> | 30 | #include <qdir.h> |
31 | #include "audiowidget.h" | 31 | #include "audiowidget.h" |
32 | #include "mediaplayerstate.h" | 32 | #include "mediaplayerstate.h" |
33 | 33 | ||
34 | #include <stdlib.h> | 34 | #include <stdlib.h> |
35 | #include <stdio.h> | 35 | #include <stdio.h> |
36 | 36 | ||
37 | extern MediaPlayerState *mediaPlayerState; | 37 | extern MediaPlayerState *mediaPlayerState; |
38 | 38 | ||
39 | 39 | ||
40 | static const int xo = -2; // movable x offset | 40 | static const int xo = -2; // movable x offset |
41 | static const int yo = 22; // movable y offset | 41 | static const int yo = 22; // movable y offset |
42 | 42 | ||
43 | struct MediaButton { | 43 | struct MediaButton { |
44 | bool isToggle, isHeld, isDown; | 44 | bool isToggle, isHeld, isDown; |
45 | }; | 45 | }; |
46 | 46 | ||
47 | //Layout information for the audioButtons (and if it is a toggle button or not) | 47 | //Layout information for the audioButtons (and if it is a toggle button or not) |
48 | MediaButton audioButtons[] = { | 48 | MediaButton audioButtons[] = { |
49 | { TRUE, FALSE, FALSE }, // play | 49 | { TRUE, FALSE, FALSE }, // play |
50 | { FALSE, FALSE, FALSE }, // stop | 50 | { FALSE, FALSE, FALSE }, // stop |
51 | { FALSE, FALSE, FALSE }, // next | 51 | { FALSE, FALSE, FALSE }, // next |
52 | { FALSE, FALSE, FALSE }, // previous | 52 | { FALSE, FALSE, FALSE }, // previous |
53 | { FALSE, FALSE, FALSE }, // volume up | 53 | { FALSE, FALSE, FALSE }, // volume up |
54 | { FALSE, FALSE, FALSE }, // volume down | 54 | { FALSE, FALSE, FALSE }, // volume down |
55 | { TRUE, FALSE, FALSE }, // repeat/loop | 55 | { TRUE, FALSE, FALSE }, // repeat/loop |
56 | { FALSE, FALSE, FALSE }, // playlist | 56 | { FALSE, FALSE, FALSE }, // playlist |
57 | { FALSE, FALSE, FALSE }, // forward | 57 | { FALSE, FALSE, FALSE }, // forward |
58 | { FALSE, FALSE, FALSE } // back | 58 | { FALSE, FALSE, FALSE } // back |
59 | }; | 59 | }; |
60 | 60 | ||
61 | const char *skin_mask_file_names[10] = { | 61 | const char *skin_mask_file_names[10] = { |
62 | "play", "stop", "next", "prev", "up", | 62 | "play", "stop", "next", "prev", "up", |
63 | "down", "loop", "playlist", "forward", "back" | 63 | "down", "loop", "playlist", "forward", "back" |
64 | }; | 64 | }; |
65 | 65 | ||
66 | static void changeTextColor( QWidget *w ) { | 66 | static void changeTextColor( QWidget *w ) { |
67 | QPalette p = w->palette(); | 67 | QPalette p = w->palette(); |
68 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); | 68 | p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); |
69 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); | 69 | p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); |
70 | w->setPalette( p ); | 70 | w->setPalette( p ); |
71 | } | 71 | } |
72 | 72 | ||
73 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 73 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
74 | 74 | ||
75 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 75 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
76 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) | 76 | QWidget( parent, name, f ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ) |
77 | { | 77 | { |
78 | setCaption( tr("OpiePlayer") ); | 78 | setCaption( tr("OpiePlayer") ); |
79 | qDebug("<<<<<audioWidget"); | 79 | // qDebug("<<<<<audioWidget"); |
80 | 80 | ||
81 | Config cfg("OpiePlayer"); | 81 | Config cfg("OpiePlayer"); |
82 | cfg.setGroup("Options"); | 82 | cfg.setGroup("Options"); |
83 | skin = cfg.readEntry("Skin","default"); | 83 | skin = cfg.readEntry("Skin","default"); |
84 | //skin = "scaleTest"; | 84 | //skin = "scaleTest"; |
85 | // color of background, frame, degree of transparency | 85 | // color of background, frame, degree of transparency |
86 | 86 | ||
87 | // QString skinPath = "opieplayer/skins/" + skin; | 87 | // QString skinPath = "opieplayer/skins/" + skin; |
88 | QString skinPath; | 88 | QString skinPath; |
89 | skinPath = "opieplayer2/skins/" + skin; | 89 | skinPath = "opieplayer2/skins/" + skin; |
90 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) | 90 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) |
91 | skinPath = "opieplayer2/skins/default"; | 91 | skinPath = "opieplayer2/skins/default"; |
92 | 92 | ||
93 | qDebug("skin path " + skinPath); | 93 | // qDebug("skin path " + skinPath); |
94 | 94 | ||
95 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 95 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
96 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); | 96 | imgUp = new QImage( Resource::loadImage( QString("%1/skin_up").arg(skinPath) ) ); |
97 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); | 97 | imgDn = new QImage( Resource::loadImage( QString("%1/skin_down").arg(skinPath) ) ); |
98 | 98 | ||
99 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 99 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
100 | imgButtonMask->fill( 0 ); | 100 | imgButtonMask->fill( 0 ); |
101 | 101 | ||
102 | for ( int i = 0; i < 10; i++ ) { | 102 | for ( int i = 0; i < 10; i++ ) { |
103 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; | 103 | QString filename = QString(getenv("OPIEDIR")) + "/pics/" + skinPath + "/skin_mask_" + skin_mask_file_names[i] + ".png"; |
104 | masks[i] = new QBitmap( filename ); | 104 | masks[i] = new QBitmap( filename ); |
105 | 105 | ||
106 | if ( !masks[i]->isNull() ) { | 106 | if ( !masks[i]->isNull() ) { |
107 | QImage imgMask = masks[i]->convertToImage(); | 107 | QImage imgMask = masks[i]->convertToImage(); |
108 | uchar **dest = imgButtonMask->jumpTable(); | 108 | uchar **dest = imgButtonMask->jumpTable(); |
109 | for ( int y = 0; y < imgUp->height(); y++ ) { | 109 | for ( int y = 0; y < imgUp->height(); y++ ) { |
110 | uchar *line = dest[y]; | 110 | uchar *line = dest[y]; |
111 | for ( int x = 0; x < imgUp->width(); x++ ) | 111 | for ( int x = 0; x < imgUp->width(); x++ ) |
112 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 112 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
113 | line[x] = i + 1; | 113 | line[x] = i + 1; |
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 | ||
117 | } | 117 | } |
118 | 118 | ||
119 | for ( int i = 0; i < 11; i++ ) { | 119 | for ( int i = 0; i < 11; i++ ) { |
120 | buttonPixUp[i] = NULL; | 120 | buttonPixUp[i] = NULL; |
121 | buttonPixDown[i] = NULL; | 121 | buttonPixDown[i] = NULL; |
122 | } | 122 | } |
123 | 123 | ||
124 | setBackgroundPixmap( *pixBg ); | 124 | setBackgroundPixmap( *pixBg ); |
125 | 125 | ||
126 | songInfo.setFocusPolicy( QWidget::NoFocus ); | 126 | songInfo.setFocusPolicy( QWidget::NoFocus ); |
127 | 127 | ||
128 | // changeTextColor( &songInfo ); | 128 | // changeTextColor( &songInfo ); |
129 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); | 129 | // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); |
130 | // songInfo.setFrameStyle( QFrame::NoFrame); | 130 | // songInfo.setFrameStyle( QFrame::NoFrame); |
131 | // songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); | 131 | // songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); |
132 | //NoFrame | 132 | //NoFrame |
133 | // songInfo.setForegroundColor(Qt::white); | 133 | // songInfo.setForegroundColor(Qt::white); |
134 | 134 | ||
135 | slider.setFixedHeight( 20 ); | 135 | slider.setFixedHeight( 20 ); |
136 | slider.setMinValue( 0 ); | 136 | slider.setMinValue( 0 ); |
137 | slider.setMaxValue( 1 ); | 137 | slider.setMaxValue( 1 ); |
138 | slider.setFocusPolicy( QWidget::NoFocus ); | 138 | slider.setFocusPolicy( QWidget::NoFocus ); |
139 | slider.setBackgroundPixmap( *pixBg ); | 139 | slider.setBackgroundPixmap( *pixBg ); |
140 | 140 | ||
141 | time.setFocusPolicy( QWidget::NoFocus ); | 141 | time.setFocusPolicy( QWidget::NoFocus ); |
142 | time.setAlignment( Qt::AlignCenter ); | 142 | time.setAlignment( Qt::AlignCenter ); |
143 | time.setFrame(FALSE); | 143 | time.setFrame(FALSE); |
144 | changeTextColor( &time ); | 144 | changeTextColor( &time ); |
145 | 145 | ||
146 | resizeEvent( NULL ); | 146 | resizeEvent( NULL ); |
147 | 147 | ||
148 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 148 | connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
149 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 149 | connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
150 | 150 | ||
151 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 151 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
152 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 152 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
153 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 153 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
154 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 154 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
155 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 155 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
156 | 156 | ||
157 | // Intialise state | 157 | // Intialise state |
158 | setLength( mediaPlayerState->length() ); | 158 | setLength( mediaPlayerState->length() ); |
159 | setPosition( mediaPlayerState->position() ); | 159 | setPosition( mediaPlayerState->position() ); |
160 | setLooping( mediaPlayerState->fullscreen() ); | 160 | setLooping( mediaPlayerState->fullscreen() ); |
161 | // setPaused( mediaPlayerState->paused() ); | 161 | // setPaused( mediaPlayerState->paused() ); |
162 | setPlaying( mediaPlayerState->playing() ); | 162 | setPlaying( mediaPlayerState->playing() ); |
163 | 163 | this->setFocus(); | |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
167 | AudioWidget::~AudioWidget() { | 167 | AudioWidget::~AudioWidget() { |
168 | // setPlaying( false); | ||
168 | 169 | ||
169 | for ( int i = 0; i < 10; i++ ) { | 170 | for ( int i = 0; i < 10; i++ ) { |
170 | delete buttonPixUp[i]; | 171 | if(buttonPixUp[i]) delete buttonPixUp[i]; |
171 | delete buttonPixDown[i]; | 172 | if(buttonPixDown[i]) delete buttonPixDown[i]; |
172 | } | 173 | } |
173 | delete pixBg; | 174 | if(pixBg) delete pixBg; |
174 | delete imgUp; | 175 | if(imgUp) delete imgUp; |
175 | delete imgDn; | 176 | if(imgDn) delete imgDn; |
176 | delete imgButtonMask; | 177 | if(imgButtonMask) delete imgButtonMask; |
177 | for ( int i = 0; i < 10; i++ ) { | 178 | for ( int i = 0; i < 10; i++ ) { |
178 | delete masks[i]; | 179 | if(masks[i]) delete masks[i]; |
179 | } | 180 | } |
180 | } | 181 | } |
181 | 182 | ||
182 | 183 | ||
183 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 184 | QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
184 | QPixmap pix( img.width(), img.height() ); | 185 | QPixmap pix( img.width(), img.height() ); |
185 | QPainter p( &pix ); | 186 | QPainter p( &pix ); |
186 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 187 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
187 | p.drawImage( 0, 0, img ); | 188 | p.drawImage( 0, 0, img ); |
188 | return new QPixmap( pix ); | 189 | return new QPixmap( pix ); |
189 | } | 190 | } |
190 | 191 | ||
191 | 192 | ||
192 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) | 193 | QPixmap *maskPixToMask( QPixmap pix, QBitmap mask ) |
193 | { | 194 | { |
194 | QPixmap *pixmap = new QPixmap( pix ); | 195 | QPixmap *pixmap = new QPixmap( pix ); |
195 | pixmap->setMask( mask ); | 196 | pixmap->setMask( mask ); |
196 | return pixmap; | 197 | return pixmap; |
197 | } | 198 | } |
198 | 199 | ||
199 | 200 | ||
200 | 201 | ||
201 | void AudioWidget::resizeEvent( QResizeEvent * ) { | 202 | void AudioWidget::resizeEvent( QResizeEvent * ) { |
202 | int h = height(); | 203 | int h = height(); |
203 | int w = width(); | 204 | int w = width(); |
204 | 205 | ||
205 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); | 206 | songInfo.setGeometry( QRect( 2, 10, w - 4, 20 ) ); |
206 | slider.setFixedWidth( w - 110 ); | 207 | slider.setFixedWidth( w - 110 ); |
207 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); | 208 | slider.setGeometry( QRect( 15, h - 30, w - 90, 20 ) ); |
208 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); | 209 | slider.setBackgroundOrigin( QWidget::ParentOrigin ); |
209 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); | 210 | time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); |
210 | 211 | ||
211 | xoff = ( w - imgUp->width() ) / 2; | 212 | xoff = ( w - imgUp->width() ) / 2; |
212 | yoff = (( h - imgUp->height() ) / 2) - 10; | 213 | yoff = (( h - imgUp->height() ) / 2) - 10; |
213 | QPoint p( xoff, yoff ); | 214 | QPoint p( xoff, yoff ); |
214 | 215 | ||
215 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); | 216 | QPixmap *pixUp = combineImageWithBackground( *imgUp, *pixBg, p ); |
216 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); | 217 | QPixmap *pixDn = combineImageWithBackground( *imgDn, *pixBg, p ); |
217 | 218 | ||
218 | for ( int i = 0; i < 10; i++ ) { | 219 | for ( int i = 0; i < 10; i++ ) { |
219 | if ( !masks[i]->isNull() ) { | 220 | if ( !masks[i]->isNull() ) { |
220 | delete buttonPixUp[i]; | 221 | delete buttonPixUp[i]; |
221 | delete buttonPixDown[i]; | 222 | delete buttonPixDown[i]; |
222 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); | 223 | buttonPixUp[i] = maskPixToMask( *pixUp, *masks[i] ); |
223 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); | 224 | buttonPixDown[i] = maskPixToMask( *pixDn, *masks[i] ); |
224 | } | 225 | } |
225 | } | 226 | } |
226 | 227 | ||
227 | delete pixUp; | 228 | delete pixUp; |
228 | delete pixDn; | 229 | delete pixDn; |
229 | } | 230 | } |
230 | 231 | ||
231 | 232 | ||
232 | static bool audioSliderBeingMoved = FALSE; | 233 | static bool audioSliderBeingMoved = FALSE; |
233 | 234 | ||
234 | void AudioWidget::sliderPressed() { | 235 | void AudioWidget::sliderPressed() { |
235 | audioSliderBeingMoved = TRUE; | 236 | audioSliderBeingMoved = TRUE; |
236 | } | 237 | } |
237 | 238 | ||
238 | 239 | ||
239 | void AudioWidget::sliderReleased() { | 240 | void AudioWidget::sliderReleased() { |
240 | audioSliderBeingMoved = FALSE; | 241 | audioSliderBeingMoved = FALSE; |
241 | if ( slider.width() == 0 ) | 242 | if ( slider.width() == 0 ) |
242 | return; | 243 | return; |
243 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); | 244 | long val = long((double)slider.value() * mediaPlayerState->length() / slider.width()); |
244 | mediaPlayerState->setPosition( val ); | 245 | mediaPlayerState->setPosition( val ); |
245 | } | 246 | } |
246 | 247 | ||
247 | 248 | ||
248 | void AudioWidget::setPosition( long i ) { | 249 | void AudioWidget::setPosition( long i ) { |
249 | // qDebug("set position %d",i); | 250 | // qDebug("set position %d",i); |
250 | long length = mediaPlayerState->length(); | 251 | long length = mediaPlayerState->length(); |
251 | updateSlider( i, length ); | 252 | updateSlider( i, length ); |
252 | } | 253 | } |
253 | 254 | ||
254 | 255 | ||
255 | void AudioWidget::setLength( long max ) { | 256 | void AudioWidget::setLength( long max ) { |
256 | updateSlider( mediaPlayerState->position(), max ); | 257 | updateSlider( mediaPlayerState->position(), max ); |
257 | } | 258 | } |
258 | 259 | ||
259 | 260 | ||
260 | void AudioWidget::setView( char view ) { | 261 | void AudioWidget::setView( char view ) { |
261 | 262 | ||
262 | if (mediaPlayerState->isStreaming) { | 263 | if (mediaPlayerState->isStreaming) { |
263 | if( !slider.isHidden()) slider.hide(); | 264 | if( !slider.isHidden()) slider.hide(); |
264 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 265 | disconnect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
265 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 266 | disconnect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
266 | } else { | 267 | } else { |
267 | // this stops the slider from being moved, thus | 268 | // this stops the slider from being moved, thus |
268 | // does not stop stream when it reaches the end | 269 | // does not stop stream when it reaches the end |
269 | slider.show(); | 270 | slider.show(); |
270 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 271 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
271 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 272 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
272 | } | 273 | } |
273 | 274 | ||
274 | if ( view == 'a' ) { | 275 | if ( view == 'a' ) { |
275 | startTimer( 150 ); | 276 | startTimer( 150 ); |
276 | // show(); | 277 | // show(); |
277 | showMaximized(); | 278 | showMaximized(); |
278 | } else { | 279 | } else { |
279 | killTimers(); | 280 | killTimers(); |
280 | hide(); | 281 | hide(); |
281 | } | 282 | } |
283 | |||
282 | } | 284 | } |
283 | 285 | ||
284 | 286 | ||
285 | static QString timeAsString( long length ) { | 287 | static QString timeAsString( long length ) { |
286 | length /= 44100; | 288 | length /= 44100; |
287 | int minutes = length / 60; | 289 | int minutes = length / 60; |
288 | int seconds = length % 60; | 290 | int seconds = length % 60; |
289 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); | 291 | return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); |
290 | } | 292 | } |
291 | 293 | ||
292 | void AudioWidget::updateSlider( long i, long max ) { | 294 | void AudioWidget::updateSlider( long i, long max ) { |
293 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | 295 | this->setFocus(); |
296 | time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); | ||
294 | 297 | ||
295 | if ( max == 0 ) | 298 | if ( max == 0 ) |
296 | return; | 299 | return; |
297 | // Will flicker too much if we don't do this | 300 | // Will flicker too much if we don't do this |
298 | // Scale to something reasonable | 301 | // Scale to something reasonable |
299 | int width = slider.width(); | 302 | int width = slider.width(); |
300 | int val = int((double)i * width / max); | 303 | int val = int((double)i * width / max); |
301 | if ( !audioSliderBeingMoved ) { | 304 | if ( !audioSliderBeingMoved ) { |
302 | if ( slider.value() != val ) | 305 | if ( slider.value() != val ) |
303 | slider.setValue( val ); | 306 | slider.setValue( val ); |
304 | if ( slider.maxValue() != width ) | 307 | if ( slider.maxValue() != width ) |
305 | slider.setMaxValue( width ); | 308 | slider.setMaxValue( width ); |
306 | } | 309 | } |
307 | } | 310 | } |
308 | 311 | ||
309 | 312 | ||
310 | void AudioWidget::setToggleButton( int i, bool down ) { | 313 | void AudioWidget::setToggleButton( int i, bool down ) { |
311 | if ( down != audioButtons[i].isDown ) | 314 | if ( down != audioButtons[i].isDown ) |
312 | toggleButton( i ); | 315 | toggleButton( i ); |
313 | } | 316 | } |
314 | 317 | ||
315 | 318 | ||
316 | void AudioWidget::toggleButton( int i ) { | 319 | void AudioWidget::toggleButton( int i ) { |
317 | audioButtons[i].isDown = !audioButtons[i].isDown; | 320 | audioButtons[i].isDown = !audioButtons[i].isDown; |
318 | QPainter p(this); | 321 | QPainter p(this); |
319 | paintButton ( &p, i ); | 322 | paintButton ( &p, i ); |
320 | } | 323 | } |
321 | 324 | ||
322 | 325 | ||
323 | void AudioWidget::paintButton( QPainter *p, int i ) { | 326 | void AudioWidget::paintButton( QPainter *p, int i ) { |
324 | if ( audioButtons[i].isDown ) | 327 | if ( audioButtons[i].isDown ) |
325 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); | 328 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
326 | else | 329 | else |
327 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); | 330 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
328 | } | 331 | } |
329 | 332 | ||
330 | 333 | ||
331 | void AudioWidget::timerEvent( QTimerEvent * ) { | 334 | void AudioWidget::timerEvent( QTimerEvent * ) { |
332 | /* | 335 | /* |
333 | int x = audioButtons[AudioPlay].xPos; | 336 | int x = audioButtons[AudioPlay].xPos; |
334 | int y = audioButtons[AudioPlay].yPos; | 337 | int y = audioButtons[AudioPlay].yPos; |
335 | QPainter p( this ); | 338 | QPainter p( this ); |
336 | // Optimize to only draw the little bit of the changing images which is different | 339 | // Optimize to only draw the little bit of the changing images which is different |
337 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); | 340 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); |
338 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); | 341 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); |
339 | */ | 342 | */ |
340 | /* | 343 | /* |
341 | static int frame = 0; | 344 | static int frame = 0; |
342 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { | 345 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { |
343 | frame = frame >= 7 ? 0 : frame + 1; | 346 | frame = frame >= 7 ? 0 : frame + 1; |
344 | } | 347 | } |
345 | */ | 348 | */ |
346 | } | 349 | } |
347 | 350 | ||
348 | 351 | ||
349 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 352 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
350 | for ( int i = 0; i < numButtons; i++ ) { | 353 | for ( int i = 0; i < numButtons; i++ ) { |
351 | if ( event->state() == QMouseEvent::LeftButton ) { | 354 | if ( event->state() == QMouseEvent::LeftButton ) { |
352 | 355 | ||
353 | // The test to see if the mouse click is inside the button or not | 356 | // The test to see if the mouse click is inside the button or not |
354 | int x = event->pos().x() - xoff; | 357 | int x = event->pos().x() - xoff; |
355 | int y = event->pos().y() - yoff; | 358 | int y = event->pos().y() - yoff; |
356 | 359 | ||
357 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 360 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
358 | && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 361 | && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
359 | 362 | ||
360 | if ( isOnButton && i == AudioVolumeUp ) | 363 | // if ( isOnButton && i == AudioVolumeUp ) |
361 | qDebug("on up"); | 364 | // qDebug("on up"); |
362 | 365 | ||
363 | if ( isOnButton && !audioButtons[i].isHeld ) { | 366 | if ( isOnButton && !audioButtons[i].isHeld ) { |
364 | audioButtons[i].isHeld = TRUE; | 367 | audioButtons[i].isHeld = TRUE; |
365 | toggleButton(i); | 368 | toggleButton(i); |
366 | switch (i) { | 369 | switch (i) { |
367 | case AudioVolumeUp: | 370 | case AudioVolumeUp: |
368 | qDebug("more clicked"); | 371 | // qDebug("more clicked"); |
369 | emit moreClicked(); | 372 | emit moreClicked(); |
370 | return; | 373 | return; |
371 | case AudioVolumeDown: | 374 | case AudioVolumeDown: |
372 | qDebug("less clicked"); | 375 | // qDebug("less clicked"); |
373 | emit lessClicked(); | 376 | emit lessClicked(); |
374 | return; | 377 | return; |
375 | case AudioForward: | 378 | case AudioForward: |
376 | emit forwardClicked(); | 379 | emit forwardClicked(); |
377 | return; | 380 | return; |
378 | case AudioBack: | 381 | case AudioBack: |
379 | emit backClicked(); | 382 | emit backClicked(); |
380 | return; | 383 | return; |
381 | } | 384 | } |
382 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 385 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
383 | audioButtons[i].isHeld = FALSE; | 386 | audioButtons[i].isHeld = FALSE; |
384 | toggleButton(i); | 387 | toggleButton(i); |
385 | } | 388 | } |
386 | } else { | 389 | } else { |
387 | if ( audioButtons[i].isHeld ) { | 390 | if ( audioButtons[i].isHeld ) { |
388 | audioButtons[i].isHeld = FALSE; | 391 | audioButtons[i].isHeld = FALSE; |
389 | if ( !audioButtons[i].isToggle ) | 392 | if ( !audioButtons[i].isToggle ) |
390 | setToggleButton( i, FALSE ); | 393 | setToggleButton( i, FALSE ); |
391 | switch (i) { | 394 | switch (i) { |
392 | case AudioPlay: | 395 | case AudioPlay: |
393 | if( mediaPlayerState->isPaused ) { | 396 | if( mediaPlayerState->isPaused ) { |
394 | mediaPlayerState->setPaused( FALSE ); | 397 | mediaPlayerState->setPaused( FALSE ); |
395 | return; | 398 | return; |
396 | } else if( !mediaPlayerState->isPaused ) { | 399 | } else if( !mediaPlayerState->isPaused ) { |
397 | mediaPlayerState->setPaused( TRUE ); | 400 | mediaPlayerState->setPaused( TRUE ); |
398 | return; | 401 | return; |
399 | } | 402 | } |
400 | // case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; | 403 | // case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; |
401 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 404 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
402 | // case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; | 405 | // case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; |
403 | case AudioNext: mediaPlayerState->setNext(); return; | 406 | case AudioNext: mediaPlayerState->setNext(); return; |
404 | case AudioPrevious: mediaPlayerState->setPrev(); return; | 407 | case AudioPrevious: mediaPlayerState->setPrev(); return; |
405 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; | 408 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; |
406 | case AudioVolumeUp: emit moreReleased(); return; | 409 | case AudioVolumeUp: emit moreReleased(); return; |
407 | case AudioVolumeDown: emit lessReleased(); return; | 410 | case AudioVolumeDown: emit lessReleased(); return; |
408 | case AudioPlayList: mediaPlayerState->setList(); return; | 411 | case AudioPlayList: mediaPlayerState->setList(); return; |
409 | } | 412 | } |
410 | } | 413 | } |
411 | } | 414 | } |
412 | } | 415 | } |
413 | } | 416 | } |
414 | 417 | ||
415 | 418 | ||
416 | 419 | ||
417 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 420 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
418 | mouseMoveEvent( event ); | 421 | mouseMoveEvent( event ); |
419 | } | 422 | } |
420 | 423 | ||
421 | 424 | ||
422 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 425 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
423 | mouseMoveEvent( event ); | 426 | mouseMoveEvent( event ); |
424 | } | 427 | } |
425 | 428 | ||
426 | 429 | ||
427 | void AudioWidget::showEvent( QShowEvent* ) { | 430 | void AudioWidget::showEvent( QShowEvent* ) { |
428 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 431 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
429 | mouseMoveEvent( &event ); | 432 | mouseMoveEvent( &event ); |
430 | } | 433 | } |
431 | 434 | ||
432 | 435 | ||
433 | void AudioWidget::closeEvent( QCloseEvent* ) { | 436 | void AudioWidget::closeEvent( QCloseEvent* ) { |
434 | mediaPlayerState->setList(); | 437 | mediaPlayerState->setList(); |
435 | } | 438 | } |
436 | 439 | ||
437 | 440 | ||
438 | void AudioWidget::paintEvent( QPaintEvent * pe) { | 441 | void AudioWidget::paintEvent( QPaintEvent * pe) { |
439 | if ( !pe->erased() ) { | 442 | if ( !pe->erased() ) { |
440 | // Combine with background and double buffer | 443 | // Combine with background and double buffer |
441 | QPixmap pix( pe->rect().size() ); | 444 | QPixmap pix( pe->rect().size() ); |
442 | QPainter p( &pix ); | 445 | QPainter p( &pix ); |
443 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 446 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
444 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); | 447 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); |
445 | for ( int i = 0; i < numButtons; i++ ) | 448 | for ( int i = 0; i < numButtons; i++ ) |
446 | paintButton( &p, i ); | 449 | paintButton( &p, i ); |
447 | QPainter p2( this ); | 450 | QPainter p2( this ); |
448 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 451 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
449 | } else { | 452 | } else { |
450 | QPainter p( this ); | 453 | QPainter p( this ); |
451 | for ( int i = 0; i < numButtons; i++ ) | 454 | for ( int i = 0; i < numButtons; i++ ) |
452 | paintButton( &p, i ); | 455 | paintButton( &p, i ); |
453 | } | 456 | } |
454 | } | 457 | } |
455 | 458 | ||
456 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) | 459 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) |
457 | { | 460 | { |
458 | switch ( e->key() ) { | 461 | switch ( e->key() ) { |
459 | ////////////////////////////// Zaurus keys | 462 | ////////////////////////////// Zaurus keys |
460 | case Key_Home: | 463 | case Key_Home: |
461 | break; | 464 | break; |
462 | case Key_F9: //activity | 465 | case Key_F9: //activity |
463 | hide(); | 466 | hide(); |
464 | // qDebug("Audio F9"); | 467 | // qDebug("Audio F9"); |
465 | break; | 468 | break; |
466 | case Key_F10: //contacts | 469 | case Key_F10: //contacts |
467 | break; | 470 | break; |
468 | case Key_F11: //menu | 471 | case Key_F11: //menu |
469 | break; | 472 | break; |
470 | case Key_F12: //home | 473 | case Key_F12: //home |
471 | break; | 474 | break; |
472 | case Key_F13: //mail | 475 | case Key_F13: //mail |
473 | break; | 476 | break; |
474 | case Key_Space: { | 477 | case Key_Space: { |
475 | 478 | ||
476 | if(mediaPlayerState->playing()) { | 479 | if(mediaPlayerState->playing()) { |
477 | // toggleButton(1); | 480 | // toggleButton(1); |
478 | mediaPlayerState->setPlaying(FALSE); | 481 | mediaPlayerState->setPlaying(FALSE); |
479 | // toggleButton(1); | 482 | // toggleButton(1); |
480 | } else { | 483 | } else { |
481 | // toggleButton(0); | 484 | // toggleButton(0); |
482 | mediaPlayerState->setPlaying(TRUE); | 485 | mediaPlayerState->setPlaying(TRUE); |
483 | // toggleButton(0); | 486 | // toggleButton(0); |
484 | } | 487 | } |
485 | } | 488 | } |
486 | break; | 489 | break; |
487 | case Key_Down: //volume | 490 | case Key_Down: //volume |
488 | // toggleButton(6); | 491 | // toggleButton(6); |
489 | emit lessClicked(); | 492 | emit lessClicked(); |
490 | emit lessReleased(); | 493 | emit lessReleased(); |
491 | // toggleButton(6); | 494 | // toggleButton(6); |
492 | break; | 495 | break; |
493 | case Key_Up: //volume | 496 | case Key_Up: //volume |
494 | // toggleButton(5); | 497 | // toggleButton(5); |
495 | emit moreClicked(); | 498 | emit moreClicked(); |
496 | emit moreReleased(); | 499 | emit moreReleased(); |
497 | // toggleButton(5); | 500 | // toggleButton(5); |
498 | break; | 501 | break; |
499 | case Key_Right: //next in playlist | 502 | case Key_Right: //next in playlist |
500 | // toggleButton(3); | 503 | // toggleButton(3); |
501 | mediaPlayerState->setNext(); | 504 | mediaPlayerState->setNext(); |
502 | // toggleButton(3); | 505 | // toggleButton(3); |
503 | break; | 506 | break; |
504 | case Key_Left: // previous in playlist | 507 | case Key_Left: // previous in playlist |
505 | // toggleButton(4); | 508 | // toggleButton(4); |
506 | mediaPlayerState->setPrev(); | 509 | mediaPlayerState->setPrev(); |
507 | // toggleButton(4); | 510 | // toggleButton(4); |
508 | break; | 511 | break; |
509 | case Key_Escape: | 512 | case Key_Escape: |
510 | break; | 513 | break; |
511 | 514 | ||
512 | }; | 515 | }; |
513 | } | 516 | } |
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp index 8cf0a75..82242a3 100644 --- a/core/multimedia/opieplayer/loopcontrol.cpp +++ b/core/multimedia/opieplayer/loopcontrol.cpp | |||
@@ -1,485 +1,485 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // L.J.Potter added changes Fri 02-15-2002 | 20 | // L.J.Potter added changes Fri 02-15-2002 |
21 | 21 | ||
22 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | 23 | ||
24 | #ifdef Q_WS_QWS | 24 | #ifdef Q_WS_QWS |
25 | #include <qpe/qcopenvelope_qws.h> | 25 | #include <qpe/qcopenvelope_qws.h> |
26 | #endif | 26 | #endif |
27 | #include <stdio.h> | 27 | #include <stdio.h> |
28 | #include <stdlib.h> | 28 | #include <stdlib.h> |
29 | #include <string.h> | 29 | #include <string.h> |
30 | #include <pthread.h> | 30 | #include <pthread.h> |
31 | #include <errno.h> | 31 | #include <errno.h> |
32 | #include <unistd.h> | 32 | #include <unistd.h> |
33 | #include "loopcontrol.h" | 33 | #include "loopcontrol.h" |
34 | #include "videowidget.h" | 34 | #include "videowidget.h" |
35 | #include "audiodevice.h" | 35 | #include "audiodevice.h" |
36 | #include <qpe/mediaplayerplugininterface.h> | 36 | #include <qpe/mediaplayerplugininterface.h> |
37 | #include "mediaplayerstate.h" | 37 | #include "mediaplayerstate.h" |
38 | 38 | ||
39 | 39 | ||
40 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame | 40 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame |
41 | extern MediaPlayerState *mediaPlayerState; | 41 | extern MediaPlayerState *mediaPlayerState; |
42 | 42 | ||
43 | 43 | ||
44 | //#define DecodeLoopDebug(x) qDebug x | 44 | //#define DecodeLoopDebug(x) qDebug x |
45 | #define DecodeLoopDebug(x) | 45 | #define DecodeLoopDebug(x) |
46 | 46 | ||
47 | 47 | ||
48 | static char *audioBuffer = NULL; | 48 | static char *audioBuffer = NULL; |
49 | static AudioDevice *audioDevice = NULL; | 49 | static AudioDevice *audioDevice = NULL; |
50 | static bool disabledSuspendScreenSaver = FALSE; | 50 | static bool disabledSuspendScreenSaver = FALSE; |
51 | static bool previousSuspendMode = FALSE; | 51 | static bool previousSuspendMode = FALSE; |
52 | 52 | ||
53 | 53 | ||
54 | pthread_t audio_tid; | 54 | pthread_t audio_tid; |
55 | pthread_attr_t audio_attr; | 55 | pthread_attr_t audio_attr; |
56 | bool threadOkToGo = FALSE; | 56 | bool threadOkToGo = FALSE; |
57 | 57 | ||
58 | 58 | ||
59 | class Mutex { | 59 | class Mutex { |
60 | public: | 60 | public: |
61 | Mutex() { | 61 | Mutex() { |
62 | pthread_mutexattr_t attr; | 62 | pthread_mutexattr_t attr; |
63 | pthread_mutexattr_init( &attr ); | 63 | pthread_mutexattr_init( &attr ); |
64 | pthread_mutex_init( &mutex, &attr ); | 64 | pthread_mutex_init( &mutex, &attr ); |
65 | pthread_mutexattr_destroy( &attr ); | 65 | pthread_mutexattr_destroy( &attr ); |
66 | } | 66 | } |
67 | 67 | ||
68 | ~Mutex() { | 68 | ~Mutex() { |
69 | pthread_mutex_destroy( &mutex ); | 69 | pthread_mutex_destroy( &mutex ); |
70 | } | 70 | } |
71 | 71 | ||
72 | void lock() { | 72 | void lock() { |
73 | pthread_mutex_lock( &mutex ); | 73 | pthread_mutex_lock( &mutex ); |
74 | } | 74 | } |
75 | 75 | ||
76 | void unlock() { | 76 | void unlock() { |
77 | pthread_mutex_unlock( &mutex ); | 77 | pthread_mutex_unlock( &mutex ); |
78 | } | 78 | } |
79 | private: | 79 | private: |
80 | pthread_mutex_t mutex; | 80 | pthread_mutex_t mutex; |
81 | }; | 81 | }; |
82 | 82 | ||
83 | 83 | ||
84 | void *startAudioThread( void *ptr ) { | 84 | void *startAudioThread( void *ptr ) { |
85 | LoopControl *mpegView = (LoopControl *)ptr; | 85 | LoopControl *mpegView = (LoopControl *)ptr; |
86 | while ( TRUE ) { | 86 | while ( TRUE ) { |
87 | if ( threadOkToGo && mpegView->moreAudio ) | 87 | if ( threadOkToGo && mpegView->moreAudio ) |
88 | mpegView->startAudio(); | 88 | mpegView->startAudio(); |
89 | else | 89 | else |
90 | usleep( 10000 ); // Semi-buzy-wait till we are playing again | 90 | usleep( 10000 ); // Semi-buzy-wait till we are playing again |
91 | } | 91 | } |
92 | return 0; | 92 | return 0; |
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | Mutex *audioMutex; | 96 | Mutex *audioMutex; |
97 | 97 | ||
98 | 98 | ||
99 | LoopControl::LoopControl( QObject *parent, const char *name ) | 99 | LoopControl::LoopControl( QObject *parent, const char *name ) |
100 | : QObject( parent, name ) { | 100 | : QObject( parent, name ) { |
101 | isMuted = FALSE; | 101 | isMuted = FALSE; |
102 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); | 102 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); |
103 | qDebug("starting loopcontrol"); | 103 | //qDebug("starting loopcontrol"); |
104 | audioMutex = new Mutex; | 104 | audioMutex = new Mutex; |
105 | 105 | ||
106 | pthread_attr_init(&audio_attr); | 106 | pthread_attr_init(&audio_attr); |
107 | #define USE_REALTIME_AUDIO_THREAD | 107 | #define USE_REALTIME_AUDIO_THREAD |
108 | #ifdef USE_REALTIME_AUDIO_THREAD | 108 | #ifdef USE_REALTIME_AUDIO_THREAD |
109 | // Attempt to set it to real-time round robin | 109 | // Attempt to set it to real-time round robin |
110 | if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { | 110 | if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { |
111 | sched_param params; | 111 | sched_param params; |
112 | params.sched_priority = 50; | 112 | params.sched_priority = 50; |
113 | pthread_attr_setschedparam(&audio_attr,¶ms); | 113 | pthread_attr_setschedparam(&audio_attr,¶ms); |
114 | } else { | 114 | } else { |
115 | qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); | 115 | // qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); |
116 | pthread_attr_destroy(&audio_attr); | 116 | pthread_attr_destroy(&audio_attr); |
117 | pthread_attr_init(&audio_attr); | 117 | pthread_attr_init(&audio_attr); |
118 | } | 118 | } |
119 | #endif | 119 | #endif |
120 | qDebug("create audio thread"); | 120 | //qDebug("create audio thread"); |
121 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); | 121 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | LoopControl::~LoopControl() { | 125 | LoopControl::~LoopControl() { |
126 | stop(); | 126 | stop(); |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | static long prev_frame = 0; | 130 | static long prev_frame = 0; |
131 | static int currentSample = 0; | 131 | static int currentSample = 0; |
132 | 132 | ||
133 | 133 | ||
134 | void LoopControl::timerEvent( QTimerEvent *te ) { | 134 | void LoopControl::timerEvent( QTimerEvent *te ) { |
135 | 135 | ||
136 | if ( te->timerId() == videoId ) | 136 | if ( te->timerId() == videoId ) |
137 | startVideo(); | 137 | startVideo(); |
138 | 138 | ||
139 | if ( te->timerId() == sliderId ) { | 139 | if ( te->timerId() == sliderId ) { |
140 | if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { | 140 | if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { |
141 | mediaPlayerState->updatePosition( audioSampleCounter ); | 141 | mediaPlayerState->updatePosition( audioSampleCounter ); |
142 | } else if ( hasVideoChannel && moreVideo ) { | 142 | } else if ( hasVideoChannel && moreVideo ) { |
143 | mediaPlayerState->updatePosition( current_frame ); | 143 | mediaPlayerState->updatePosition( current_frame ); |
144 | } | 144 | } |
145 | } | 145 | } |
146 | 146 | ||
147 | if ( !moreVideo && !moreAudio ) { | 147 | if ( !moreVideo && !moreAudio ) { |
148 | mediaPlayerState->setPlaying( FALSE ); | 148 | mediaPlayerState->setPlaying( FALSE ); |
149 | mediaPlayerState->setNext(); | 149 | mediaPlayerState->setNext(); |
150 | } | 150 | } |
151 | } | 151 | } |
152 | 152 | ||
153 | 153 | ||
154 | void LoopControl::setPosition( long pos ) { | 154 | void LoopControl::setPosition( long pos ) { |
155 | audioMutex->lock(); | 155 | audioMutex->lock(); |
156 | // qDebug("Loop control %d", pos); | 156 | // qDebug("Loop control %d", pos); |
157 | if ( hasVideoChannel && hasAudioChannel ) { | 157 | if ( hasVideoChannel && hasAudioChannel ) { |
158 | playtime.restart(); | 158 | playtime.restart(); |
159 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); | 159 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); |
160 | current_frame = pos + 1; | 160 | current_frame = pos + 1; |
161 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 161 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
162 | prev_frame = current_frame - 1; | 162 | prev_frame = current_frame - 1; |
163 | currentSample = (int)( (double)current_frame * freq / framerate ); | 163 | currentSample = (int)( (double)current_frame * freq / framerate ); |
164 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); | 164 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); |
165 | audioSampleCounter = currentSample - 1; | 165 | audioSampleCounter = currentSample - 1; |
166 | } else if ( hasVideoChannel ) { | 166 | } else if ( hasVideoChannel ) { |
167 | playtime.restart(); | 167 | playtime.restart(); |
168 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); | 168 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); |
169 | current_frame = pos + 1; | 169 | current_frame = pos + 1; |
170 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 170 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
171 | prev_frame = current_frame - 1; | 171 | prev_frame = current_frame - 1; |
172 | } else if ( hasAudioChannel ) { | 172 | } else if ( hasAudioChannel ) { |
173 | playtime.restart(); | 173 | playtime.restart(); |
174 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); | 174 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); |
175 | currentSample = pos + 1; | 175 | currentSample = pos + 1; |
176 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); | 176 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); |
177 | audioSampleCounter = currentSample - 1; | 177 | audioSampleCounter = currentSample - 1; |
178 | } | 178 | } |
179 | 179 | ||
180 | audioMutex->unlock(); | 180 | audioMutex->unlock(); |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
184 | void LoopControl::startVideo() { | 184 | void LoopControl::startVideo() { |
185 | 185 | ||
186 | if ( moreVideo ) { | 186 | if ( moreVideo ) { |
187 | 187 | ||
188 | if ( mediaPlayerState->curDecoder() ) { | 188 | if ( mediaPlayerState->curDecoder() ) { |
189 | 189 | ||
190 | if ( hasAudioChannel && !isMuted ) { | 190 | if ( hasAudioChannel && !isMuted ) { |
191 | 191 | ||
192 | current_frame = long( playtime.elapsed() * framerate / 1000 ); | 192 | current_frame = long( playtime.elapsed() * framerate / 1000 ); |
193 | 193 | ||
194 | if ( prev_frame != -1 && current_frame <= prev_frame ) | 194 | if ( prev_frame != -1 && current_frame <= prev_frame ) |
195 | return; | 195 | return; |
196 | 196 | ||
197 | } else { | 197 | } else { |
198 | // Don't skip | 198 | // Don't skip |
199 | current_frame++; | 199 | current_frame++; |
200 | } | 200 | } |
201 | 201 | ||
202 | if ( prev_frame == -1 || current_frame > prev_frame ) { | 202 | if ( prev_frame == -1 || current_frame > prev_frame ) { |
203 | if ( current_frame > prev_frame + 1 ) { | 203 | if ( current_frame > prev_frame + 1 ) { |
204 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 204 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
205 | } | 205 | } |
206 | moreVideo = videoUI->playVideo(); | 206 | moreVideo = videoUI->playVideo(); |
207 | prev_frame = current_frame; | 207 | prev_frame = current_frame; |
208 | } | 208 | } |
209 | 209 | ||
210 | } else { | 210 | } else { |
211 | 211 | ||
212 | moreVideo = FALSE; | 212 | moreVideo = FALSE; |
213 | killTimer( videoId ); | 213 | killTimer( videoId ); |
214 | 214 | ||
215 | } | 215 | } |
216 | 216 | ||
217 | } | 217 | } |
218 | } | 218 | } |
219 | 219 | ||
220 | 220 | ||
221 | void LoopControl::startAudio() { | 221 | void LoopControl::startAudio() { |
222 | 222 | ||
223 | audioMutex->lock(); | 223 | audioMutex->lock(); |
224 | if ( moreAudio ) { | 224 | if ( moreAudio ) { |
225 | 225 | ||
226 | if ( !isMuted && mediaPlayerState->curDecoder() ) { | 226 | if ( !isMuted && mediaPlayerState->curDecoder() ) { |
227 | 227 | ||
228 | currentSample = audioSampleCounter + 1; | 228 | currentSample = audioSampleCounter + 1; |
229 | 229 | ||
230 | if ( currentSample != audioSampleCounter + 1 ) | 230 | // if ( currentSample != audioSampleCounter + 1 ) |
231 | qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); | 231 | // qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); |
232 | 232 | ||
233 | long samplesRead = 0; | 233 | long samplesRead = 0; |
234 | bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); | 234 | bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); |
235 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; | 235 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; |
236 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; | 236 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; |
237 | 237 | ||
238 | // this causes drop outs not sure why its even here | 238 | // this causes drop outs not sure why its even here |
239 | if ( hasVideoChannel ) { | 239 | if ( hasVideoChannel ) { |
240 | if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { | 240 | if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { |
241 | usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); | 241 | usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); |
242 | } | 242 | } |
243 | else if ( sampleWaitTime <= -5000 ) { | 243 | else if ( sampleWaitTime <= -5000 ) { |
244 | qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); | 244 | // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); |
245 | // //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); | 245 | // //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); |
246 | currentSample = sampleWeShouldBeAt; | 246 | currentSample = sampleWeShouldBeAt; |
247 | } | 247 | } |
248 | } | 248 | } |
249 | 249 | ||
250 | audioDevice->write( audioBuffer, samplesRead * 2 * channels ); | 250 | audioDevice->write( audioBuffer, samplesRead * 2 * channels ); |
251 | 251 | ||
252 | if( mediaPlayerState->isStreaming == FALSE) | 252 | if( mediaPlayerState->isStreaming == FALSE) |
253 | audioSampleCounter = currentSample + samplesRead - 1; | 253 | audioSampleCounter = currentSample + samplesRead - 1; |
254 | 254 | ||
255 | moreAudio = readOk && (audioSampleCounter <= total_audio_samples); | 255 | moreAudio = readOk && (audioSampleCounter <= total_audio_samples); |
256 | 256 | ||
257 | } else { | 257 | } else { |
258 | 258 | ||
259 | moreAudio = FALSE; | 259 | moreAudio = FALSE; |
260 | 260 | ||
261 | } | 261 | } |
262 | 262 | ||
263 | } | 263 | } |
264 | 264 | ||
265 | audioMutex->unlock(); | 265 | audioMutex->unlock(); |
266 | } | 266 | } |
267 | 267 | ||
268 | 268 | ||
269 | void LoopControl::killTimers() { | 269 | void LoopControl::killTimers() { |
270 | 270 | ||
271 | audioMutex->lock(); | 271 | audioMutex->lock(); |
272 | 272 | ||
273 | if ( hasVideoChannel ) | 273 | if ( hasVideoChannel ) |
274 | killTimer( videoId ); | 274 | killTimer( videoId ); |
275 | killTimer( sliderId ); | 275 | killTimer( sliderId ); |
276 | threadOkToGo = FALSE; | 276 | threadOkToGo = FALSE; |
277 | 277 | ||
278 | audioMutex->unlock(); | 278 | audioMutex->unlock(); |
279 | } | 279 | } |
280 | 280 | ||
281 | 281 | ||
282 | void LoopControl::startTimers() { | 282 | void LoopControl::startTimers() { |
283 | 283 | ||
284 | audioMutex->lock(); | 284 | audioMutex->lock(); |
285 | 285 | ||
286 | moreVideo = FALSE; | 286 | moreVideo = FALSE; |
287 | moreAudio = FALSE; | 287 | moreAudio = FALSE; |
288 | 288 | ||
289 | if ( hasVideoChannel ) { | 289 | if ( hasVideoChannel ) { |
290 | moreVideo = TRUE; | 290 | moreVideo = TRUE; |
291 | int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value | 291 | int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value |
292 | videoId = startTimer( mSecsBetweenFrames ); | 292 | videoId = startTimer( mSecsBetweenFrames ); |
293 | } | 293 | } |
294 | 294 | ||
295 | if ( hasAudioChannel ) { | 295 | if ( hasAudioChannel ) { |
296 | moreAudio = TRUE; | 296 | moreAudio = TRUE; |
297 | threadOkToGo = TRUE; | 297 | threadOkToGo = TRUE; |
298 | } | 298 | } |
299 | 299 | ||
300 | sliderId = startTimer( 300 ); // update slider every 1/3 second | 300 | sliderId = startTimer( 300 ); // update slider every 1/3 second |
301 | 301 | ||
302 | audioMutex->unlock(); | 302 | audioMutex->unlock(); |
303 | } | 303 | } |
304 | 304 | ||
305 | 305 | ||
306 | void LoopControl::setPaused( bool pause ) { | 306 | void LoopControl::setPaused( bool pause ) { |
307 | 307 | ||
308 | if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) | 308 | if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) |
309 | return; | 309 | return; |
310 | 310 | ||
311 | if ( pause ) { | 311 | if ( pause ) { |
312 | killTimers(); | 312 | killTimers(); |
313 | } else { | 313 | } else { |
314 | // Force an update of the position | 314 | // Force an update of the position |
315 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); | 315 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); |
316 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); | 316 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); |
317 | // Just like we never stopped | 317 | // Just like we never stopped |
318 | startTimers(); | 318 | startTimers(); |
319 | } | 319 | } |
320 | } | 320 | } |
321 | 321 | ||
322 | 322 | ||
323 | void LoopControl::stop( bool willPlayAgainShortly ) { | 323 | void LoopControl::stop( bool willPlayAgainShortly ) { |
324 | 324 | ||
325 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 325 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
326 | if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { | 326 | if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { |
327 | disabledSuspendScreenSaver = FALSE; | 327 | disabledSuspendScreenSaver = FALSE; |
328 | // Re-enable the suspend mode | 328 | // Re-enable the suspend mode |
329 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | 329 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; |
330 | } | 330 | } |
331 | #endif | 331 | #endif |
332 | 332 | ||
333 | if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { | 333 | if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { |
334 | 334 | ||
335 | killTimers(); | 335 | killTimers(); |
336 | 336 | ||
337 | audioMutex->lock(); | 337 | audioMutex->lock(); |
338 | 338 | ||
339 | mediaPlayerState->curDecoder()->close(); | 339 | mediaPlayerState->curDecoder()->close(); |
340 | 340 | ||
341 | if ( audioDevice ) { | 341 | if ( audioDevice ) { |
342 | delete audioDevice; | 342 | delete audioDevice; |
343 | delete audioBuffer; | 343 | delete audioBuffer; |
344 | audioDevice = 0; | 344 | audioDevice = 0; |
345 | audioBuffer = 0; | 345 | audioBuffer = 0; |
346 | } | 346 | } |
347 | 347 | ||
348 | audioMutex->unlock(); | 348 | audioMutex->unlock(); |
349 | } | 349 | } |
350 | audioSampleCounter=0; | 350 | audioSampleCounter=0; |
351 | current_frame=0; | 351 | current_frame=0; |
352 | total_audio_samples=0; | 352 | total_audio_samples=0; |
353 | } | 353 | } |
354 | 354 | ||
355 | 355 | ||
356 | bool LoopControl::init( const QString& filename ) { | 356 | bool LoopControl::init( const QString& filename ) { |
357 | stop(); | 357 | stop(); |
358 | audioMutex->lock(); | 358 | audioMutex->lock(); |
359 | 359 | ||
360 | fileName = filename; | 360 | fileName = filename; |
361 | stream = 0; // only play stream 0 for now | 361 | stream = 0; // only play stream 0 for now |
362 | current_frame = total_video_frames = total_audio_samples = 0; | 362 | current_frame = total_video_frames = total_audio_samples = 0; |
363 | 363 | ||
364 | qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); | 364 | // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); |
365 | 365 | ||
366 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin | 366 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin |
367 | // if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { | 367 | // if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { |
368 | // if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename )) { | 368 | // if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename )) { |
369 | // total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); | 369 | // total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); |
370 | // mediaPlayerState->libMpeg3Decoder()->close(); | 370 | // mediaPlayerState->libMpeg3Decoder()->close(); |
371 | // } | 371 | // } |
372 | // } | 372 | // } |
373 | 373 | ||
374 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { | 374 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { |
375 | audioMutex->unlock(); | 375 | audioMutex->unlock(); |
376 | return FALSE; | 376 | return FALSE; |
377 | } | 377 | } |
378 | 378 | ||
379 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; | 379 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; |
380 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; | 380 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; |
381 | 381 | ||
382 | if ( hasAudioChannel ) { | 382 | if ( hasAudioChannel ) { |
383 | int astream = 0; | 383 | int astream = 0; |
384 | 384 | ||
385 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMpeg3Plugin") ) | 385 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMpeg3Plugin") ) |
386 | channels = 2; //dont akx me why, but it needs this hack | 386 | channels = 2; //dont akx me why, but it needs this hack |
387 | else | 387 | else |
388 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); | 388 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); |
389 | 389 | ||
390 | qDebug( "LC- channels = %d", channels ); | 390 | // qDebug( "LC- channels = %d", channels ); |
391 | 391 | ||
392 | // if ( !total_audio_samples ) | 392 | // if ( !total_audio_samples ) |
393 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); | 393 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); |
394 | 394 | ||
395 | total_audio_samples += 1000; | 395 | total_audio_samples += 1000; |
396 | qDebug("total samples %d", total_audio_samples); | 396 | // qDebug("total samples %d", total_audio_samples); |
397 | mediaPlayerState->setLength( total_audio_samples ); | 397 | mediaPlayerState->setLength( total_audio_samples ); |
398 | 398 | ||
399 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); | 399 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); |
400 | qDebug( "LC- frequency = %d", freq ); | 400 | // qDebug( "LC- frequency = %d", freq ); |
401 | 401 | ||
402 | audioSampleCounter = 0; | 402 | audioSampleCounter = 0; |
403 | int bits_per_sample; | 403 | int bits_per_sample; |
404 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { | 404 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { |
405 | bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); | 405 | bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); |
406 | qDebug("using stupid hack"); | 406 | // qDebug("using stupid hack"); |
407 | } else { | 407 | } else { |
408 | bits_per_sample=0; | 408 | bits_per_sample=0; |
409 | } | 409 | } |
410 | 410 | ||
411 | audioDevice = new AudioDevice( freq, channels, bits_per_sample); | 411 | audioDevice = new AudioDevice( freq, channels, bits_per_sample); |
412 | audioBuffer = new char[ audioDevice->bufferSize() ]; | 412 | audioBuffer = new char[ audioDevice->bufferSize() ]; |
413 | channels = audioDevice->channels(); | 413 | channels = audioDevice->channels(); |
414 | 414 | ||
415 | //### must check which frequency is actually used. | 415 | //### must check which frequency is actually used. |
416 | static const int size = 1; | 416 | static const int size = 1; |
417 | short int buf[size]; | 417 | short int buf[size]; |
418 | long samplesRead = 0; | 418 | long samplesRead = 0; |
419 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); | 419 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); |
420 | } | 420 | } |
421 | 421 | ||
422 | if ( hasVideoChannel ) { | 422 | if ( hasVideoChannel ) { |
423 | total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); | 423 | total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); |
424 | 424 | ||
425 | mediaPlayerState->setLength( total_video_frames ); | 425 | mediaPlayerState->setLength( total_video_frames ); |
426 | 426 | ||
427 | framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); | 427 | framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); |
428 | DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); | 428 | DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); |
429 | 429 | ||
430 | if ( framerate <= 1.0 ) { | 430 | if ( framerate <= 1.0 ) { |
431 | DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); | 431 | DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); |
432 | framerate = 25; | 432 | framerate = 25; |
433 | } | 433 | } |
434 | 434 | ||
435 | if ( total_video_frames == 1 ) { | 435 | if ( total_video_frames == 1 ) { |
436 | DecodeLoopDebug(( "Cannot seek to frame" )); | 436 | DecodeLoopDebug(( "Cannot seek to frame" )); |
437 | } | 437 | } |
438 | 438 | ||
439 | } | 439 | } |
440 | 440 | ||
441 | current_frame = 0; | 441 | current_frame = 0; |
442 | prev_frame = -1; | 442 | prev_frame = -1; |
443 | 443 | ||
444 | connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); | 444 | connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); |
445 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); | 445 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); |
446 | 446 | ||
447 | audioMutex->unlock(); | 447 | audioMutex->unlock(); |
448 | 448 | ||
449 | return TRUE; | 449 | return TRUE; |
450 | } | 450 | } |
451 | 451 | ||
452 | 452 | ||
453 | void LoopControl::play() { | 453 | void LoopControl::play() { |
454 | qDebug("LC- play"); | 454 | // qDebug("LC- play"); |
455 | mediaPlayerState->setPosition( 0); //uglyhack | 455 | mediaPlayerState->setPosition( 0); //uglyhack |
456 | 456 | ||
457 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 457 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
458 | if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { | 458 | if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { |
459 | disabledSuspendScreenSaver = TRUE; | 459 | disabledSuspendScreenSaver = TRUE; |
460 | previousSuspendMode = hasVideoChannel; | 460 | previousSuspendMode = hasVideoChannel; |
461 | // Stop the screen from blanking and power saving state | 461 | // Stop the screen from blanking and power saving state |
462 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) | 462 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) |
463 | << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); | 463 | << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); |
464 | } | 464 | } |
465 | #endif | 465 | #endif |
466 | 466 | ||
467 | playtime.start(); | 467 | playtime.start(); |
468 | startTimers(); | 468 | startTimers(); |
469 | } | 469 | } |
470 | 470 | ||
471 | 471 | ||
472 | void LoopControl::setMute( bool on ) { | 472 | void LoopControl::setMute( bool on ) { |
473 | if ( on != isMuted ) { | 473 | if ( on != isMuted ) { |
474 | isMuted = on; | 474 | isMuted = on; |
475 | if ( !on ) { | 475 | if ( !on ) { |
476 | // Force an update of the position | 476 | // Force an update of the position |
477 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); | 477 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); |
478 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); | 478 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); |
479 | // Resume playing audio | 479 | // Resume playing audio |
480 | moreAudio = TRUE; | 480 | moreAudio = TRUE; |
481 | } | 481 | } |
482 | } | 482 | } |
483 | } | 483 | } |
484 | 484 | ||
485 | 485 | ||
diff --git a/core/multimedia/opieplayer/loopcontrol_threaded.cpp b/core/multimedia/opieplayer/loopcontrol_threaded.cpp index e99c97b..364e77b 100644 --- a/core/multimedia/opieplayer/loopcontrol_threaded.cpp +++ b/core/multimedia/opieplayer/loopcontrol_threaded.cpp | |||
@@ -1,625 +1,625 @@ | |||
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 | #define _REENTRANT | 20 | #define _REENTRANT |
21 | 21 | ||
22 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | #include <qimage.h> | 23 | #include <qimage.h> |
24 | #include <qpainter.h> | 24 | #include <qpainter.h> |
25 | #ifdef Q_WS_QWS | 25 | #ifdef Q_WS_QWS |
26 | #include <qpe/qcopenvelope_qws.h> | 26 | #include <qpe/qcopenvelope_qws.h> |
27 | #endif | 27 | #endif |
28 | #include "mediaplayerplugininterface.h" | 28 | #include "mediaplayerplugininterface.h" |
29 | #include <stdio.h> | 29 | #include <stdio.h> |
30 | #include <stdlib.h> | 30 | #include <stdlib.h> |
31 | #include <string.h> | 31 | #include <string.h> |
32 | #include <time.h> | 32 | #include <time.h> |
33 | #include <unistd.h> | 33 | #include <unistd.h> |
34 | #include <pthread.h> | 34 | #include <pthread.h> |
35 | #include "loopcontrol.h" | 35 | #include "loopcontrol.h" |
36 | #include "audiodevice.h" | 36 | #include "audiodevice.h" |
37 | #include "videowidget.h" | 37 | #include "videowidget.h" |
38 | #include "audiowidget.h" | 38 | #include "audiowidget.h" |
39 | #include "mediaplayerstate.h" | 39 | #include "mediaplayerstate.h" |
40 | 40 | ||
41 | 41 | ||
42 | #if defined(QT_QWS_SL5XXX) || defined(QT_QWS_IPAQ) || defined(QT_QWS_RAMSES) | 42 | #if defined(QT_QWS_SL5XXX) || defined(QT_QWS_IPAQ) || defined(QT_QWS_RAMSES) |
43 | #define USE_REALTIME_AUDIO_THREAD | 43 | #define USE_REALTIME_AUDIO_THREAD |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | 46 | ||
47 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame | 47 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame |
48 | extern MediaPlayerState *mediaPlayerState; | 48 | extern MediaPlayerState *mediaPlayerState; |
49 | 49 | ||
50 | 50 | ||
51 | #define DecodeLoopDebug(x) qDebug x | 51 | #define DecodeLoopDebug(x) qDebug x |
52 | //#define DecodeLoopDebug(x) | 52 | //#define DecodeLoopDebug(x) |
53 | 53 | ||
54 | 54 | ||
55 | static char *audioBuffer = NULL; | 55 | static char *audioBuffer = NULL; |
56 | static AudioDevice *audioDevice = NULL; | 56 | static AudioDevice *audioDevice = NULL; |
57 | static bool disabledSuspendScreenSaver = FALSE; | 57 | static bool disabledSuspendScreenSaver = FALSE; |
58 | 58 | ||
59 | 59 | ||
60 | pthread_tvideo_tid; | 60 | pthread_t video_tid; |
61 | pthread_attr_t video_attr; | 61 | pthread_attr_t video_attr; |
62 | pthread_taudio_tid; | 62 | pthread_t audio_tid; |
63 | pthread_attr_t audio_attr; | 63 | pthread_attr_t audio_attr; |
64 | 64 | ||
65 | 65 | ||
66 | bool emitPlayFinished = FALSE; | 66 | bool emitPlayFinished = FALSE; |
67 | bool emitChangePos = FALSE; | 67 | bool emitChangePos = FALSE; |
68 | 68 | ||
69 | 69 | ||
70 | class Mutex { | 70 | class Mutex { |
71 | public: | 71 | public: |
72 | Mutex() { | 72 | Mutex() { |
73 | pthread_mutexattr_t attr; | 73 | pthread_mutexattr_t attr; |
74 | pthread_mutexattr_init( &attr ); | 74 | pthread_mutexattr_init( &attr ); |
75 | pthread_mutex_init( &mutex, &attr ); | 75 | pthread_mutex_init( &mutex, &attr ); |
76 | pthread_mutexattr_destroy( &attr ); | 76 | pthread_mutexattr_destroy( &attr ); |
77 | } | 77 | } |
78 | 78 | ||
79 | ~Mutex() { | 79 | ~Mutex() { |
80 | pthread_mutex_destroy( &mutex ); | 80 | pthread_mutex_destroy( &mutex ); |
81 | } | 81 | } |
82 | 82 | ||
83 | void lock() { | 83 | void lock() { |
84 | pthread_mutex_lock( &mutex ); | 84 | pthread_mutex_lock( &mutex ); |
85 | } | 85 | } |
86 | 86 | ||
87 | void unlock() { | 87 | void unlock() { |
88 | pthread_mutex_unlock( &mutex ); | 88 | pthread_mutex_unlock( &mutex ); |
89 | } | 89 | } |
90 | /* | 90 | /* |
91 | bool locked() { | 91 | bool locked() { |
92 | switch ( pthread_mutex_trylock( &mutex ) ) { | 92 | switch ( pthread_mutex_trylock( &mutex ) ) { |
93 | case EBUSY: | 93 | case EBUSY: |
94 | return TRUE; | 94 | return TRUE; |
95 | case 0: | 95 | case 0: |
96 | pthread_mutex_unlock( &mutex ); | 96 | pthread_mutex_unlock( &mutex ); |
97 | default: | 97 | default: |
98 | return FALSE; | 98 | return FALSE; |
99 | } | 99 | } |
100 | } | 100 | } |
101 | */ | 101 | */ |
102 | private: | 102 | private: |
103 | pthread_mutex_t mutex; | 103 | pthread_mutex_t mutex; |
104 | }; | 104 | }; |
105 | 105 | ||
106 | 106 | ||
107 | class currentFrameObj { | 107 | class currentFrameObj { |
108 | public: | 108 | public: |
109 | currentFrameObj() : value( 0 ) { } | 109 | currentFrameObj() : value( 0 ) { } |
110 | void set( long f ) { | 110 | void set( long f ) { |
111 | mutex.lock(); | 111 | mutex.lock(); |
112 | value = f; | 112 | value = f; |
113 | mediaPlayerState->curDecoder()->videoSetFrame( f, 0 ); | 113 | mediaPlayerState->curDecoder()->videoSetFrame( f, 0 ); |
114 | mutex.unlock(); | 114 | mutex.unlock(); |
115 | } | 115 | } |
116 | long get() { | 116 | long get() { |
117 | return value; | 117 | return value; |
118 | } | 118 | } |
119 | private: | 119 | private: |
120 | long value; | 120 | long value; |
121 | Mutex mutex; | 121 | Mutex mutex; |
122 | }; | 122 | }; |
123 | 123 | ||
124 | 124 | ||
125 | Mutex *videoMutex; | 125 | Mutex *videoMutex; |
126 | Mutex *audioMutex; | 126 | Mutex *audioMutex; |
127 | Mutex *globalMutex; | 127 | Mutex *globalMutex; |
128 | 128 | ||
129 | 129 | ||
130 | clock_tbegin; | 130 | clock_t begin; |
131 | 131 | ||
132 | 132 | ||
133 | LoopControl::LoopControl( QObject *parent, const char *name ) | 133 | LoopControl::LoopControl( QObject *parent, const char *name ) |
134 | : QObject( parent, name ) { | 134 | : QObject( parent, name ) { |
135 | isMuted = FALSE; | 135 | isMuted = FALSE; |
136 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); | 136 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); |
137 | timerid = startTimer( 200 ); | 137 | timerid = startTimer( 200 ); |
138 | videoMutex = new Mutex; | 138 | videoMutex = new Mutex; |
139 | audioMutex = new Mutex; | 139 | audioMutex = new Mutex; |
140 | globalMutex = new Mutex; | 140 | globalMutex = new Mutex; |
141 | //begin = clock(); | 141 | //begin = clock(); |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | LoopControl::~LoopControl() { | 145 | LoopControl::~LoopControl() { |
146 | stop(); | 146 | stop(); |
147 | killTimer( timerid ); | 147 | killTimer( timerid ); |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | static bool sendingNewPos = FALSE; | 151 | static bool sendingNewPos = FALSE; |
152 | static long prev_frame = 0; | 152 | static long prev_frame = 0; |
153 | static int currentSample = 0; | 153 | static int currentSample = 0; |
154 | 154 | ||
155 | 155 | ||
156 | void LoopControl::timerEvent( QTimerEvent* ) { | 156 | void LoopControl::timerEvent( QTimerEvent* ) { |
157 | // We need to emit playFinished from the main thread, not one of the | 157 | // We need to emit playFinished from the main thread, not one of the |
158 | // decoding threads else we'll have all kinds of yucky things happen (reentrance). | 158 | // decoding threads else we'll have all kinds of yucky things happen (reentrance). |
159 | // playFinished will eventually call stop() which stops these threads. | 159 | // playFinished will eventually call stop() which stops these threads. |
160 | if ( emitPlayFinished ) { | 160 | if ( emitPlayFinished ) { |
161 | emitPlayFinished = FALSE; | 161 | emitPlayFinished = FALSE; |
162 | mediaPlayerState->setPlaying( FALSE ); | 162 | mediaPlayerState->setPlaying( FALSE ); |
163 | } | 163 | } |
164 | 164 | ||
165 | if ( emitChangePos ) { | 165 | if ( emitChangePos ) { |
166 | 166 | ||
167 | emitChangePos = FALSE; | 167 | emitChangePos = FALSE; |
168 | 168 | ||
169 | if ( hasVideoChannel && hasAudioChannel ) { | 169 | if ( hasVideoChannel && hasAudioChannel ) { |
170 | sendingNewPos = TRUE; | 170 | sendingNewPos = TRUE; |
171 | mediaPlayerState->setPosition( current_frame ); | 171 | mediaPlayerState->setPosition( current_frame ); |
172 | } else if ( hasVideoChannel ) { | 172 | } else if ( hasVideoChannel ) { |
173 | sendingNewPos = TRUE; | 173 | sendingNewPos = TRUE; |
174 | mediaPlayerState->setPosition( current_frame ); | 174 | mediaPlayerState->setPosition( current_frame ); |
175 | } else if ( hasAudioChannel ) { | 175 | } else if ( hasAudioChannel ) { |
176 | sendingNewPos = TRUE; | 176 | sendingNewPos = TRUE; |
177 | mediaPlayerState->setPosition( audioSampleCounter ); | 177 | mediaPlayerState->setPosition( audioSampleCounter ); |
178 | } | 178 | } |
179 | 179 | ||
180 | } | 180 | } |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
184 | 184 | ||
185 | 185 | ||
186 | void LoopControl::setPosition( long pos ) { | 186 | void LoopControl::setPosition( long pos ) { |
187 | if ( sendingNewPos ) { | 187 | if ( sendingNewPos ) { |
188 | sendingNewPos = FALSE; | 188 | sendingNewPos = FALSE; |
189 | return; | 189 | return; |
190 | } | 190 | } |
191 | 191 | ||
192 | if ( hasVideoChannel && hasAudioChannel ) { | 192 | if ( hasVideoChannel && hasAudioChannel ) { |
193 | videoMutex->lock(); | 193 | videoMutex->lock(); |
194 | audioMutex->lock(); | 194 | audioMutex->lock(); |
195 | qDebug("setting position"); | 195 | //qDebug("setting position"); |
196 | playtime.restart(); | 196 | playtime.restart(); |
197 | playtime = playtime.addMSecs( -pos * 1000 / framerate ); | 197 | playtime = playtime.addMSecs( -pos * 1000 / framerate ); |
198 | //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate; | 198 | //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate; |
199 | current_frame = pos + 1; | 199 | current_frame = pos + 1; |
200 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 200 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
201 | prev_frame = current_frame - 1; | 201 | prev_frame = current_frame - 1; |
202 | currentSample = (int)( current_frame * freq / framerate ); | 202 | currentSample = (int)( current_frame * freq / framerate ); |
203 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); | 203 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); |
204 | audioSampleCounter = currentSample - 1; | 204 | audioSampleCounter = currentSample - 1; |
205 | audioMutex->unlock(); | 205 | audioMutex->unlock(); |
206 | videoMutex->unlock(); | 206 | videoMutex->unlock(); |
207 | } else if ( hasVideoChannel ) { | 207 | } else if ( hasVideoChannel ) { |
208 | videoMutex->lock(); | 208 | videoMutex->lock(); |
209 | playtime.restart(); | 209 | playtime.restart(); |
210 | playtime = playtime.addMSecs( -pos * 1000 / framerate ); | 210 | playtime = playtime.addMSecs( -pos * 1000 / framerate ); |
211 | //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate; | 211 | //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate; |
212 | current_frame = pos + 1; | 212 | current_frame = pos + 1; |
213 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 213 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
214 | videoMutex->unlock(); | 214 | videoMutex->unlock(); |
215 | prev_frame = current_frame - 1; | 215 | prev_frame = current_frame - 1; |
216 | } else if ( hasAudioChannel ) { | 216 | } else if ( hasAudioChannel ) { |
217 | audioMutex->lock(); | 217 | audioMutex->lock(); |
218 | playtime.restart(); | 218 | playtime.restart(); |
219 | playtime = playtime.addMSecs( -pos * 1000 / freq ); | 219 | playtime = playtime.addMSecs( -pos * 1000 / freq ); |
220 | //begin = clock() - (double)pos * CLOCKS_PER_SEC / freq; | 220 | //begin = clock() - (double)pos * CLOCKS_PER_SEC / freq; |
221 | currentSample = pos + 1; // (int)( current_frame * freq / framerate ); | 221 | currentSample = pos + 1; // (int)( current_frame * freq / framerate ); |
222 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); | 222 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); |
223 | audioSampleCounter = currentSample - 1; | 223 | audioSampleCounter = currentSample - 1; |
224 | audioMutex->unlock(); | 224 | audioMutex->unlock(); |
225 | } | 225 | } |
226 | } | 226 | } |
227 | 227 | ||
228 | 228 | ||
229 | void *startVideoThread( void *ptr ) { | 229 | void *startVideoThread( void *ptr ) { |
230 | LoopControl *mpegView = (LoopControl *)ptr; | 230 | LoopControl *mpegView = (LoopControl *)ptr; |
231 | mpegView->startVideo(); | 231 | mpegView->startVideo(); |
232 | return 0; | 232 | return 0; |
233 | } | 233 | } |
234 | 234 | ||
235 | void *startAudioThread( void *ptr ) { | 235 | void *startAudioThread( void *ptr ) { |
236 | LoopControl *mpegView = (LoopControl *)ptr; | 236 | LoopControl *mpegView = (LoopControl *)ptr; |
237 | mpegView->startAudio(); | 237 | mpegView->startAudio(); |
238 | return 0; | 238 | return 0; |
239 | } | 239 | } |
240 | 240 | ||
241 | void LoopControl::startVideo() { | 241 | void LoopControl::startVideo() { |
242 | moreVideo = TRUE; | 242 | moreVideo = TRUE; |
243 | 243 | ||
244 | while ( moreVideo ) { | 244 | while ( moreVideo ) { |
245 | 245 | ||
246 | if ( mediaPlayerState->curDecoder() && hasVideoChannel ) { | 246 | if ( mediaPlayerState->curDecoder() && hasVideoChannel ) { |
247 | 247 | ||
248 | if ( hasAudioChannel && !isMuted ) { | 248 | if ( hasAudioChannel && !isMuted ) { |
249 | 249 | ||
250 | bool done = FALSE; | 250 | bool done = FALSE; |
251 | 251 | ||
252 | do { | 252 | do { |
253 | 253 | ||
254 | 254 | ||
255 | /* | 255 | /* |
256 | videoMutex->lock(); | 256 | videoMutex->lock(); |
257 | current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); | 257 | current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); |
258 | //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC; | 258 | //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC; |
259 | 259 | ||
260 | // Sync to Audio | 260 | // Sync to Audio |
261 | // current_frame = (long)((double)(audioSampleCounter - 1000) * framerate / (double)freq); | 261 | // current_frame = (long)((double)(audioSampleCounter - 1000) * framerate / (double)freq); |
262 | 262 | ||
263 | long mSecsToNextFrame = 0; | 263 | long mSecsToNextFrame = 0; |
264 | 264 | ||
265 | if ( current_frame == prev_frame ) { | 265 | if ( current_frame == prev_frame ) { |
266 | int nf = current_frame + 1; | 266 | int nf = current_frame + 1; |
267 | if ( nf > 0 && nf != total_video_frames ) | 267 | if ( nf > 0 && nf != total_video_frames ) |
268 | // mSecsToNextFrame = long(double(nf * CLOCKS_PER_SEC) / framerate) - ( clock() - begin ); | 268 | // mSecsToNextFrame = long(double(nf * CLOCKS_PER_SEC) / framerate) - ( clock() - begin ); |
269 | mSecsToNextFrame = long(double(nf * 1000) / framerate) - ( playtime.elapsed() ); | 269 | mSecsToNextFrame = long(double(nf * 1000) / framerate) - ( playtime.elapsed() ); |
270 | } | 270 | } |
271 | videoMutex->unlock(); | 271 | videoMutex->unlock(); |
272 | 272 | ||
273 | if ( mSecsToNextFrame ) { | 273 | if ( mSecsToNextFrame ) { |
274 | usleep( mSecsToNextFrame ); // wait a bit | 274 | usleep( mSecsToNextFrame ); // wait a bit |
275 | 275 | ||
276 | videoMutex->lock(); | 276 | videoMutex->lock(); |
277 | // This should now be the next frame | 277 | // This should now be the next frame |
278 | current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); | 278 | current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); |
279 | //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC; | 279 | //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC; |
280 | videoMutex->unlock(); | 280 | videoMutex->unlock(); |
281 | } | 281 | } |
282 | 282 | ||
283 | videoMutex->lock(); | 283 | videoMutex->lock(); |
284 | done = current_frame >= prev_frame; | 284 | done = current_frame >= prev_frame; |
285 | videoMutex->unlock(); | 285 | videoMutex->unlock(); |
286 | */ | 286 | */ |
287 | videoMutex->lock(); | 287 | videoMutex->lock(); |
288 | current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); | 288 | current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); |
289 | done = current_frame >= prev_frame; | 289 | done = current_frame >= prev_frame; |
290 | videoMutex->unlock(); | 290 | videoMutex->unlock(); |
291 | if ( !done ) | 291 | if ( !done ) |
292 | usleep( 1000 ); // wait a bit | 292 | usleep( 1000 ); // wait a bit |
293 | 293 | ||
294 | } while ( !done ); | 294 | } while ( !done ); |
295 | 295 | ||
296 | // qDebug("elapsed: %i %i (%f)", int( playtime.elapsed() ), current_frame, framerate ); | 296 | // qDebug("elapsed: %i %i (%f)", int( playtime.elapsed() ), current_frame, framerate ); |
297 | 297 | ||
298 | } else { | 298 | } else { |
299 | videoMutex->lock(); | 299 | videoMutex->lock(); |
300 | current_frame++; | 300 | current_frame++; |
301 | videoMutex->unlock(); | 301 | videoMutex->unlock(); |
302 | } | 302 | } |
303 | 303 | ||
304 | videoMutex->lock(); | 304 | videoMutex->lock(); |
305 | bool check = current_frame && current_frame > prev_frame; | 305 | bool check = current_frame && current_frame > prev_frame; |
306 | videoMutex->unlock(); | 306 | videoMutex->unlock(); |
307 | 307 | ||
308 | if ( check ) { | 308 | if ( check ) { |
309 | videoMutex->lock(); | 309 | videoMutex->lock(); |
310 | if ( current_frame > prev_frame + 1 ) { | 310 | if ( current_frame > prev_frame + 1 ) { |
311 | qDebug("skipped a frame"); | 311 | // qDebug("skipped a frame"); |
312 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 312 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
313 | } | 313 | } |
314 | prev_frame = current_frame; | 314 | prev_frame = current_frame; |
315 | if ( moreVideo = videoUI->playVideo() ) | 315 | if ( moreVideo = videoUI->playVideo() ) |
316 | emitChangePos = TRUE; | 316 | emitChangePos = TRUE; |
317 | videoMutex->unlock(); | 317 | videoMutex->unlock(); |
318 | } | 318 | } |
319 | 319 | ||
320 | } else | 320 | } else |
321 | moreVideo = FALSE; | 321 | moreVideo = FALSE; |
322 | 322 | ||
323 | } | 323 | } |
324 | 324 | ||
325 | if ( !moreVideo && !moreAudio ) | 325 | if ( !moreVideo && !moreAudio ) |
326 | emitPlayFinished = TRUE; | 326 | emitPlayFinished = TRUE; |
327 | 327 | ||
328 | pthread_exit(NULL); | 328 | pthread_exit(NULL); |
329 | } | 329 | } |
330 | 330 | ||
331 | void LoopControl::startAudio() { | 331 | void LoopControl::startAudio() { |
332 | moreAudio = TRUE; | 332 | moreAudio = TRUE; |
333 | 333 | ||
334 | while ( moreAudio ) { | 334 | while ( moreAudio ) { |
335 | 335 | ||
336 | if ( !isMuted && mediaPlayerState->curDecoder() && hasAudioChannel ) { | 336 | if ( !isMuted && mediaPlayerState->curDecoder() && hasAudioChannel ) { |
337 | 337 | ||
338 | audioMutex->lock(); | 338 | audioMutex->lock(); |
339 | currentSample = mediaPlayerState->curDecoder()->audioGetSample( stream ); | 339 | currentSample = mediaPlayerState->curDecoder()->audioGetSample( stream ); |
340 | 340 | ||
341 | if ( currentSample == 0 ) | 341 | if ( currentSample == 0 ) |
342 | currentSample = audioSampleCounter + 1; | 342 | currentSample = audioSampleCounter + 1; |
343 | 343 | ||
344 | if ( currentSample != audioSampleCounter + 1 ) | 344 | // if ( currentSample != audioSampleCounter + 1 ) |
345 | qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); | 345 | // qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); |
346 | audioMutex->unlock(); | 346 | audioMutex->unlock(); |
347 | 347 | ||
348 | /* | 348 | /* |
349 | int sampleWeShouldBeAt = int( playtime.elapsed() ) * freq / 1000; | 349 | int sampleWeShouldBeAt = int( playtime.elapsed() ) * freq / 1000; |
350 | 350 | ||
351 | if ( sampleWeShouldBeAt - currentSample > 20000 ) { | 351 | if ( sampleWeShouldBeAt - currentSample > 20000 ) { |
352 | mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); | 352 | mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); |
353 | currentSample = sampleWeShouldBeAt; | 353 | currentSample = sampleWeShouldBeAt; |
354 | } | 354 | } |
355 | */ | 355 | */ |
356 | long samplesRead = 0; | 356 | long samplesRead = 0; |
357 | 357 | ||
358 | const long samples = 1024; | 358 | const long samples = 1024; |
359 | 359 | ||
360 | moreAudio = !mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, samples, samplesRead, stream ); | 360 | moreAudio = !mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, samples, samplesRead, stream ); |
361 | 361 | ||
362 | audioMutex->lock(); | 362 | audioMutex->lock(); |
363 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; | 363 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; |
364 | //long sampleWeShouldBeAt = long( clock() - begin ) * (double) freq / CLOCKS_PER_SEC; | 364 | //long sampleWeShouldBeAt = long( clock() - begin ) * (double) freq / CLOCKS_PER_SEC; |
365 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; | 365 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; |
366 | audioMutex->unlock(); | 366 | audioMutex->unlock(); |
367 | 367 | ||
368 | if ( sampleWaitTime >= 0 && sampleWaitTime <= 2000 ) { | 368 | if ( sampleWaitTime >= 0 && sampleWaitTime <= 2000 ) { |
369 | //qDebug("sampleWaitTime: %i", sampleWaitTime); | 369 | //qDebug("sampleWaitTime: %i", sampleWaitTime); |
370 | usleep( ( sampleWaitTime * 1000000 ) / ( freq ) ); | 370 | usleep( ( sampleWaitTime * 1000000 ) / ( freq ) ); |
371 | } else { | 371 | } else { |
372 | audioMutex->lock(); | 372 | audioMutex->lock(); |
373 | if ( sampleWaitTime <= -2000 ) { | 373 | if ( sampleWaitTime <= -2000 ) { |
374 | qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); | 374 | // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); |
375 | mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); | 375 | mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); |
376 | currentSample = sampleWeShouldBeAt; | 376 | currentSample = sampleWeShouldBeAt; |
377 | } | 377 | } |
378 | audioMutex->unlock(); | 378 | audioMutex->unlock(); |
379 | } | 379 | } |
380 | 380 | ||
381 | audioDevice->write( audioBuffer, samplesRead * 2 * channels ); | 381 | audioDevice->write( audioBuffer, samplesRead * 2 * channels ); |
382 | 382 | ||
383 | audioMutex->lock(); | 383 | audioMutex->lock(); |
384 | // audioSampleCounter += samplesRead; | 384 | // audioSampleCounter += samplesRead; |
385 | audioSampleCounter = currentSample + samplesRead - 1; | 385 | audioSampleCounter = currentSample + samplesRead - 1; |
386 | audioMutex->unlock(); | 386 | audioMutex->unlock(); |
387 | 387 | ||
388 | if ( !hasVideoChannel ) | 388 | if ( !hasVideoChannel ) |
389 | emitChangePos = TRUE; | 389 | emitChangePos = TRUE; |
390 | 390 | ||
391 | //qDebug("currentSample: %i audioSampleCounter: %i total_audio_samples: %i", currentSample, audioSampleCounter, total_audio_samples); | 391 | //qDebug("currentSample: %i audioSampleCounter: %i total_audio_samples: %i", currentSample, audioSampleCounter, total_audio_samples); |
392 | // qDebug("current: %i counter: %i total: %i", currentSample, audioSampleCounter, (int)total_audio_samples); | 392 | // qDebug("current: %i counter: %i total: %i", currentSample, audioSampleCounter, (int)total_audio_samples); |
393 | moreAudio = audioSampleCounter <= total_audio_samples; | 393 | moreAudio = audioSampleCounter <= total_audio_samples; |
394 | 394 | ||
395 | } else { | 395 | } else { |
396 | 396 | ||
397 | if ( mediaPlayerState->curDecoder() && hasAudioChannel ) | 397 | if ( mediaPlayerState->curDecoder() && hasAudioChannel ) |
398 | usleep( 100000 ); // Check every 1/10 sec to see if mute is off | 398 | usleep( 100000 ); // Check every 1/10 sec to see if mute is off |
399 | else | 399 | else |
400 | moreAudio = FALSE; | 400 | moreAudio = FALSE; |
401 | 401 | ||
402 | } | 402 | } |
403 | } | 403 | } |
404 | 404 | ||
405 | qDebug( "End of file" ); | 405 | // qDebug( "End of file" ); |
406 | 406 | ||
407 | if ( !moreVideo && !moreAudio ) | 407 | if ( !moreVideo && !moreAudio ) |
408 | emitPlayFinished = TRUE; | 408 | emitPlayFinished = TRUE; |
409 | 409 | ||
410 | pthread_exit(NULL); | 410 | pthread_exit(NULL); |
411 | } | 411 | } |
412 | 412 | ||
413 | void LoopControl::killTimers() { | 413 | void LoopControl::killTimers() { |
414 | if ( hasVideoChannel ) { | 414 | if ( hasVideoChannel ) { |
415 | if ( pthread_self() != video_tid ) { | 415 | if ( pthread_self() != video_tid ) { |
416 | if ( pthread_cancel(video_tid) == 0 ) { | 416 | if ( pthread_cancel(video_tid) == 0 ) { |
417 | void *thread_result = 0; | 417 | void *thread_result = 0; |
418 | if ( pthread_join(video_tid,&thread_result) != 0 ) | 418 | if ( pthread_join(video_tid,&thread_result) != 0 ) |
419 | qDebug("thread join error 1"); | 419 | // qDebug("thread join error 1"); |
420 | pthread_attr_destroy(&video_attr); | 420 | pthread_attr_destroy(&video_attr); |
421 | } | 421 | } |
422 | } | 422 | } |
423 | } | 423 | } |
424 | if ( hasAudioChannel ) { | 424 | if ( hasAudioChannel ) { |
425 | if ( pthread_self() != audio_tid ) { | 425 | if ( pthread_self() != audio_tid ) { |
426 | if ( pthread_cancel(audio_tid) == 0 ) { | 426 | if ( pthread_cancel(audio_tid) == 0 ) { |
427 | void *thread_result = 0; | 427 | void *thread_result = 0; |
428 | if ( pthread_join(audio_tid,&thread_result) != 0 ) | 428 | if ( pthread_join(audio_tid,&thread_result) != 0 ) |
429 | qDebug("thread join error 2"); | 429 | // qDebug("thread join error 2"); |
430 | pthread_attr_destroy(&audio_attr); | 430 | pthread_attr_destroy(&audio_attr); |
431 | } | 431 | } |
432 | } | 432 | } |
433 | } | 433 | } |
434 | } | 434 | } |
435 | 435 | ||
436 | void LoopControl::startTimers() { | 436 | void LoopControl::startTimers() { |
437 | moreVideo = FALSE; | 437 | moreVideo = FALSE; |
438 | moreAudio = FALSE; | 438 | moreAudio = FALSE; |
439 | 439 | ||
440 | if ( hasVideoChannel ) { | 440 | if ( hasVideoChannel ) { |
441 | moreVideo = TRUE; | 441 | moreVideo = TRUE; |
442 | pthread_attr_init(&video_attr); | 442 | pthread_attr_init(&video_attr); |
443 | pthread_create(&video_tid, &video_attr, (void * (*)(void *))startVideoThread, this); | 443 | pthread_create(&video_tid, &video_attr, (void * (*)(void *))startVideoThread, this); |
444 | } | 444 | } |
445 | 445 | ||
446 | if ( hasAudioChannel ) { | 446 | if ( hasAudioChannel ) { |
447 | moreAudio = TRUE; | 447 | moreAudio = TRUE; |
448 | pthread_attr_init(&audio_attr); | 448 | pthread_attr_init(&audio_attr); |
449 | #ifdef USE_REALTIME_AUDIO_THREAD | 449 | #ifdef USE_REALTIME_AUDIO_THREAD |
450 | pthread_attr_setschedpolicy(&audio_attr,SCHED_RR); // Real-time round robin | 450 | pthread_attr_setschedpolicy(&audio_attr,SCHED_RR); // Real-time round robin |
451 | //qDebug("min: %i, max: %i", sched_get_priority_min( SCHED_RR ), sched_get_priority_max( SCHED_RR ) ); | 451 | //qDebug("min: %i, max: %i", sched_get_priority_min( SCHED_RR ), sched_get_priority_max( SCHED_RR ) ); |
452 | sched_param params; | 452 | sched_param params; |
453 | params.sched_priority = 50; | 453 | params.sched_priority = 50; |
454 | pthread_attr_setschedparam(&audio_attr,¶ms); | 454 | pthread_attr_setschedparam(&audio_attr,¶ms); |
455 | #endif | 455 | #endif |
456 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); | 456 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); |
457 | } | 457 | } |
458 | } | 458 | } |
459 | 459 | ||
460 | 460 | ||
461 | 461 | ||
462 | 462 | ||
463 | void LoopControl::setPaused( bool pause ) { | 463 | void LoopControl::setPaused( bool pause ) { |
464 | static int whenPaused = 0; | 464 | static int whenPaused = 0; |
465 | 465 | ||
466 | if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) | 466 | if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) |
467 | return; | 467 | return; |
468 | 468 | ||
469 | if ( pause ) { | 469 | if ( pause ) { |
470 | // Remember where we are | 470 | // Remember where we are |
471 | whenPaused = playtime.elapsed(); | 471 | whenPaused = playtime.elapsed(); |
472 | killTimers(); | 472 | killTimers(); |
473 | } else { | 473 | } else { |
474 | // Just like we never stopped | 474 | // Just like we never stopped |
475 | playtime.restart(); | 475 | playtime.restart(); |
476 | playtime = playtime.addMSecs( -whenPaused ); | 476 | playtime = playtime.addMSecs( -whenPaused ); |
477 | whenPaused = 0; | 477 | whenPaused = 0; |
478 | startTimers(); | 478 | startTimers(); |
479 | } | 479 | } |
480 | } | 480 | } |
481 | 481 | ||
482 | 482 | ||
483 | void LoopControl::stop( bool willPlayAgainShortly ) { | 483 | void LoopControl::stop( bool willPlayAgainShortly ) { |
484 | 484 | ||
485 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 485 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
486 | if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { | 486 | if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { |
487 | disabledSuspendScreenSaver = FALSE; | 487 | disabledSuspendScreenSaver = FALSE; |
488 | // Re-enable the suspend mode | 488 | // Re-enable the suspend mode |
489 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | 489 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; |
490 | } | 490 | } |
491 | #endif | 491 | #endif |
492 | 492 | ||
493 | if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { | 493 | if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { |
494 | 494 | ||
495 | killTimers(); | 495 | killTimers(); |
496 | 496 | ||
497 | mediaPlayerState->curDecoder()->close(); | 497 | mediaPlayerState->curDecoder()->close(); |
498 | 498 | ||
499 | if ( audioDevice ) { | 499 | if ( audioDevice ) { |
500 | delete audioDevice; | 500 | delete audioDevice; |
501 | delete audioBuffer; | 501 | delete audioBuffer; |
502 | audioDevice = 0; | 502 | audioDevice = 0; |
503 | audioBuffer = 0; | 503 | audioBuffer = 0; |
504 | } | 504 | } |
505 | 505 | ||
506 | } | 506 | } |
507 | } | 507 | } |
508 | 508 | ||
509 | 509 | ||
510 | bool LoopControl::init( const QString& filename ) { | 510 | bool LoopControl::init( const QString& filename ) { |
511 | stop(); | 511 | stop(); |
512 | fileName = filename; | 512 | fileName = filename; |
513 | stream = 0; // only play stream 0 for now | 513 | stream = 0; // only play stream 0 for now |
514 | current_frame = total_video_frames = total_audio_samples = 0; | 514 | current_frame = total_video_frames = total_audio_samples = 0; |
515 | 515 | ||
516 | qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); | 516 | // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); |
517 | 517 | ||
518 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin | 518 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin |
519 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { | 519 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { |
520 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { | 520 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { |
521 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); | 521 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); |
522 | mediaPlayerState->libMpeg3Decoder()->close(); | 522 | mediaPlayerState->libMpeg3Decoder()->close(); |
523 | } | 523 | } |
524 | } | 524 | } |
525 | 525 | ||
526 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) | 526 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) |
527 | return FALSE; | 527 | return FALSE; |
528 | 528 | ||
529 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; | 529 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; |
530 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; | 530 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; |
531 | 531 | ||
532 | if ( hasAudioChannel ) { | 532 | if ( hasAudioChannel ) { |
533 | int astream = 0; | 533 | int astream = 0; |
534 | 534 | ||
535 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); | 535 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); |
536 | DecodeLoopDebug(( "channels = %d\n", channels )); | 536 | DecodeLoopDebug(( "channels = %d\n", channels )); |
537 | 537 | ||
538 | if ( !total_audio_samples ) | 538 | if ( !total_audio_samples ) |
539 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); | 539 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); |
540 | 540 | ||
541 | mediaPlayerState->setLength( total_audio_samples ); | 541 | mediaPlayerState->setLength( total_audio_samples ); |
542 | 542 | ||
543 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); | 543 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); |
544 | DecodeLoopDebug(( "frequency = %d\n", freq )); | 544 | DecodeLoopDebug(( "frequency = %d\n", freq )); |
545 | 545 | ||
546 | audioSampleCounter = 0; | 546 | audioSampleCounter = 0; |
547 | 547 | ||
548 | static const int bytes_per_sample = 2; //16 bit | 548 | static const int bytes_per_sample = 2; //16 bit |
549 | 549 | ||
550 | audioDevice = new AudioDevice( freq, channels, bytes_per_sample ); | 550 | audioDevice = new AudioDevice( freq, channels, bytes_per_sample ); |
551 | audioBuffer = new char[ audioDevice->bufferSize() ]; | 551 | audioBuffer = new char[ audioDevice->bufferSize() ]; |
552 | channels = audioDevice->channels(); | 552 | channels = audioDevice->channels(); |
553 | 553 | ||
554 | //### must check which frequency is actually used. | 554 | //### must check which frequency is actually used. |
555 | static const int size = 1; | 555 | static const int size = 1; |
556 | short int buf[size]; | 556 | short int buf[size]; |
557 | long samplesRead = 0; | 557 | long samplesRead = 0; |
558 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); | 558 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); |
559 | } | 559 | } |
560 | 560 | ||
561 | if ( hasVideoChannel ) { | 561 | if ( hasVideoChannel ) { |
562 | total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); | 562 | total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); |
563 | 563 | ||
564 | mediaPlayerState->setLength( total_video_frames ); | 564 | mediaPlayerState->setLength( total_video_frames ); |
565 | 565 | ||
566 | framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); | 566 | framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); |
567 | DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); | 567 | DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); |
568 | 568 | ||
569 | if ( framerate <= 1.0 ) { | 569 | if ( framerate <= 1.0 ) { |
570 | DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); | 570 | DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); |
571 | framerate = 25; | 571 | framerate = 25; |
572 | } | 572 | } |
573 | 573 | ||
574 | if ( total_video_frames == 1 ) { | 574 | if ( total_video_frames == 1 ) { |
575 | DecodeLoopDebug(( "Cannot seek to frame" )); | 575 | DecodeLoopDebug(( "Cannot seek to frame" )); |
576 | } | 576 | } |
577 | 577 | ||
578 | } | 578 | } |
579 | 579 | ||
580 | videoMutex->lock(); | 580 | videoMutex->lock(); |
581 | current_frame = 0; | 581 | current_frame = 0; |
582 | prev_frame = -1; | 582 | prev_frame = -1; |
583 | videoMutex->unlock(); | 583 | videoMutex->unlock(); |
584 | 584 | ||
585 | connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); | 585 | connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); |
586 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); | 586 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); |
587 | 587 | ||
588 | //setBackgroundColor( black ); | 588 | //setBackgroundColor( black ); |
589 | return TRUE; | 589 | return TRUE; |
590 | } | 590 | } |
591 | 591 | ||
592 | 592 | ||
593 | void LoopControl::play() { | 593 | void LoopControl::play() { |
594 | 594 | ||
595 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 595 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
596 | if ( !disabledSuspendScreenSaver ) { | 596 | if ( !disabledSuspendScreenSaver ) { |
597 | disabledSuspendScreenSaver = TRUE; | 597 | disabledSuspendScreenSaver = TRUE; |
598 | // Stop the screen from blanking and power saving state | 598 | // Stop the screen from blanking and power saving state |
599 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) | 599 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) |
600 | << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); | 600 | << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); |
601 | } | 601 | } |
602 | #endif | 602 | #endif |
603 | 603 | ||
604 | //begin = clock(); | 604 | //begin = clock(); |
605 | playtime.start(); | 605 | playtime.start(); |
606 | startTimers(); | 606 | startTimers(); |
607 | //updateGeometry(); | 607 | //updateGeometry(); |
608 | } | 608 | } |
609 | 609 | ||
610 | 610 | ||
611 | void LoopControl::setMute( bool on ) { | 611 | void LoopControl::setMute( bool on ) { |
612 | if ( isMuted != on ) { | 612 | if ( isMuted != on ) { |
613 | isMuted = on; | 613 | isMuted = on; |
614 | if ( isMuted ) { | 614 | if ( isMuted ) { |
615 | } else { | 615 | } else { |
616 | int frame = current_frame; // mediaPlayerState->curDecoder()->videoGetFrame( stream ); | 616 | int frame = current_frame; // mediaPlayerState->curDecoder()->videoGetFrame( stream ); |
617 | playtime.restart(); | 617 | playtime.restart(); |
618 | playtime = playtime.addMSecs( -frame * 1000 / framerate ); | 618 | playtime = playtime.addMSecs( -frame * 1000 / framerate ); |
619 | //begin = clock() - (double)frame * CLOCKS_PER_SEC / framerate; | 619 | //begin = clock() - (double)frame * CLOCKS_PER_SEC / framerate; |
620 | mediaPlayerState->curDecoder()->audioSetSample( frame*freq/framerate, stream ); | 620 | mediaPlayerState->curDecoder()->audioSetSample( frame*freq/framerate, stream ); |
621 | } | 621 | } |
622 | } | 622 | } |
623 | } | 623 | } |
624 | 624 | ||
625 | 625 | ||
diff --git a/core/multimedia/opieplayer/mediaplayer.cpp b/core/multimedia/opieplayer/mediaplayer.cpp index 4f3823a..753b2e3 100644 --- a/core/multimedia/opieplayer/mediaplayer.cpp +++ b/core/multimedia/opieplayer/mediaplayer.cpp | |||
@@ -1,278 +1,278 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <qpe/qpeapplication.h> | 21 | #include <qpe/qpeapplication.h> |
22 | #include <qpe/qlibrary.h> | 22 | #include <qpe/qlibrary.h> |
23 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
24 | #include <qpe/config.h> | 24 | #include <qpe/config.h> |
25 | 25 | ||
26 | #include <qmainwindow.h> | 26 | #include <qmainwindow.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | #include <qwidgetstack.h> | 28 | #include <qwidgetstack.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | 30 | ||
31 | #include "mediaplayer.h" | 31 | #include "mediaplayer.h" |
32 | #include "playlistwidget.h" | 32 | #include "playlistwidget.h" |
33 | #include "audiowidget.h" | 33 | #include "audiowidget.h" |
34 | #include "loopcontrol.h" | 34 | #include "loopcontrol.h" |
35 | #include "audiodevice.h" | 35 | #include "audiodevice.h" |
36 | 36 | ||
37 | #include "mediaplayerstate.h" | 37 | #include "mediaplayerstate.h" |
38 | 38 | ||
39 | 39 | ||
40 | extern AudioWidget *audioUI; | 40 | extern AudioWidget *audioUI; |
41 | extern PlayListWidget *playList; | 41 | extern PlayListWidget *playList; |
42 | extern LoopControl *loopControl; | 42 | extern LoopControl *loopControl; |
43 | extern MediaPlayerState *mediaPlayerState; | 43 | extern MediaPlayerState *mediaPlayerState; |
44 | 44 | ||
45 | 45 | ||
46 | MediaPlayer::MediaPlayer( QObject *parent, const char *name ) | 46 | MediaPlayer::MediaPlayer( QObject *parent, const char *name ) |
47 | : QObject( parent, name ), volumeDirection( 0 ), currentFile( NULL ) { | 47 | : QObject( parent, name ), volumeDirection( 0 ), currentFile( NULL ) { |
48 | 48 | ||
49 | // QPEApplication::grabKeyboard(); | 49 | // QPEApplication::grabKeyboard(); |
50 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 50 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
51 | 51 | ||
52 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); | 52 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); |
53 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); | 53 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); |
54 | connect( mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); | 54 | connect( mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); |
55 | connect( mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); | 55 | connect( mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); |
56 | 56 | ||
57 | connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); | 57 | connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); |
58 | connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); | 58 | connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); |
59 | connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); | 59 | connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); |
60 | connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); | 60 | connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); |
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
64 | MediaPlayer::~MediaPlayer() { | 64 | MediaPlayer::~MediaPlayer() { |
65 | 65 | ||
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
69 | void MediaPlayer::pauseCheck( bool b ) { | 69 | void MediaPlayer::pauseCheck( bool b ) { |
70 | // Only pause if playing | 70 | // Only pause if playing |
71 | if ( b && !mediaPlayerState->playing() ) | 71 | if ( b && !mediaPlayerState->playing() ) |
72 | mediaPlayerState->setPaused( FALSE ); | 72 | mediaPlayerState->setPaused( FALSE ); |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | void MediaPlayer::play() { | 76 | void MediaPlayer::play() { |
77 | mediaPlayerState->setPlaying( FALSE ); | 77 | mediaPlayerState->setPlaying( FALSE ); |
78 | mediaPlayerState->setPlaying( TRUE ); | 78 | mediaPlayerState->setPlaying( TRUE ); |
79 | } | 79 | } |
80 | 80 | ||
81 | 81 | ||
82 | void MediaPlayer::setPlaying( bool play ) { | 82 | void MediaPlayer::setPlaying( bool play ) { |
83 | qDebug("MediaPlayer setPlaying"); | 83 | // qDebug("MediaPlayer setPlaying %d", play); |
84 | if ( !play ) { | 84 | if ( !play ) { |
85 | mediaPlayerState->setPaused( FALSE ); | 85 | mediaPlayerState->setPaused( FALSE ); |
86 | loopControl->stop( FALSE ); | 86 | loopControl->stop( FALSE ); |
87 | return; | 87 | return; |
88 | } | 88 | } |
89 | 89 | ||
90 | if ( mediaPlayerState->paused() ) { | 90 | if ( mediaPlayerState->paused() ) { |
91 | mediaPlayerState->setPaused( FALSE ); | 91 | mediaPlayerState->setPaused( FALSE ); |
92 | return; | 92 | return; |
93 | } | 93 | } |
94 | qDebug("about to ctrash"); | 94 | // qDebug("about to ctrash"); |
95 | const DocLnk *playListCurrent = playList->current(); | 95 | const DocLnk *playListCurrent = playList->current(); |
96 | 96 | ||
97 | if ( playListCurrent != NULL ) { | 97 | if ( playListCurrent != NULL ) { |
98 | loopControl->stop( TRUE ); | 98 | loopControl->stop( TRUE ); |
99 | currentFile = playListCurrent; | 99 | currentFile = playListCurrent; |
100 | } | 100 | } |
101 | if ( currentFile == NULL ) { | 101 | if ( currentFile == NULL ) { |
102 | QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) ); | 102 | QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) ); |
103 | mediaPlayerState->setPlaying( FALSE ); | 103 | mediaPlayerState->setPlaying( FALSE ); |
104 | return; | 104 | return; |
105 | } | 105 | } |
106 | 106 | ||
107 | if ( ((currentFile->file()).left(4) != "http") && !QFile::exists( currentFile->file() ) ) { | 107 | if ( ((currentFile->file()).left(4) != "http") && !QFile::exists( currentFile->file() ) ) { |
108 | QMessageBox::critical( 0, tr( "File not found"), | 108 | QMessageBox::critical( 0, tr( "File not found"), |
109 | tr( "The following file was not found: <i>" ) | 109 | tr( "The following file was not found: <i>" ) |
110 | + currentFile->file() + "</i>" ); | 110 | + currentFile->file() + "</i>" ); |
111 | mediaPlayerState->setPlaying( FALSE ); | 111 | mediaPlayerState->setPlaying( FALSE ); |
112 | return; | 112 | return; |
113 | } | 113 | } |
114 | 114 | ||
115 | if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) { | 115 | if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) { |
116 | QMessageBox::critical( 0, tr( "No decoder found"), | 116 | QMessageBox::critical( 0, tr( "No decoder found"), |
117 | tr( "Sorry, no appropriate decoders found for this file: <i>" ) | 117 | tr( "Sorry, no appropriate decoders found for this file: <i>" ) |
118 | + currentFile->file() + "</i>" ); | 118 | + currentFile->file() + "</i>" ); |
119 | mediaPlayerState->setPlaying( FALSE ); | 119 | mediaPlayerState->setPlaying( FALSE ); |
120 | return; | 120 | return; |
121 | } | 121 | } |
122 | 122 | ||
123 | if ( !loopControl->init( currentFile->file() ) ) { | 123 | if ( !loopControl->init( currentFile->file() ) ) { |
124 | QMessageBox::critical( 0, tr( "Error opening file"), | 124 | QMessageBox::critical( 0, tr( "Error opening file"), |
125 | tr( "Sorry, an error occured trying to play the file: <i>" ) + currentFile->file() + "</i>" ); | 125 | tr( "Sorry, an error occured trying to play the file: <i>" ) + currentFile->file() + "</i>" ); |
126 | mediaPlayerState->setPlaying( FALSE ); | 126 | mediaPlayerState->setPlaying( FALSE ); |
127 | return; | 127 | return; |
128 | } | 128 | } |
129 | long seconds = loopControl->totalPlaytime(); | 129 | long seconds = loopControl->totalPlaytime(); |
130 | QString time; time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); | 130 | QString time; time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); |
131 | QString tickerText; | 131 | QString tickerText; |
132 | if( currentFile->file().left(4) == "http" ) | 132 | if( currentFile->file().left(4) == "http" ) |
133 | tickerText= tr( " File: " ) + currentFile->name(); | 133 | tickerText= tr( " File: " ) + currentFile->name(); |
134 | else | 134 | else |
135 | tickerText = tr( " File: " ) + currentFile->name() + tr(", Length: ") + time; | 135 | tickerText = tr( " File: " ) + currentFile->name() + tr(", Length: ") + time; |
136 | 136 | ||
137 | QString fileInfo = mediaPlayerState->curDecoder()->fileInfo(); | 137 | QString fileInfo = mediaPlayerState->curDecoder()->fileInfo(); |
138 | if ( !fileInfo.isEmpty() ) | 138 | if ( !fileInfo.isEmpty() ) |
139 | tickerText += ", " + fileInfo; | 139 | tickerText += ", " + fileInfo; |
140 | audioUI->setTickerText( tickerText + "." ); | 140 | audioUI->setTickerText( tickerText + "." ); |
141 | 141 | ||
142 | loopControl->play(); | 142 | loopControl->play(); |
143 | 143 | ||
144 | mediaPlayerState->setView( loopControl->hasVideo() ? 'v' : 'a' ); | 144 | mediaPlayerState->setView( loopControl->hasVideo() ? 'v' : 'a' ); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | void MediaPlayer::prev() { | 148 | void MediaPlayer::prev() { |
149 | if ( playList->prev() ) | 149 | if ( playList->prev() ) |
150 | play(); | 150 | play(); |
151 | else if ( mediaPlayerState->looping() ) { | 151 | else if ( mediaPlayerState->looping() ) { |
152 | if ( playList->last() ) | 152 | if ( playList->last() ) |
153 | play(); | 153 | play(); |
154 | } else | 154 | } else |
155 | mediaPlayerState->setList(); | 155 | mediaPlayerState->setList(); |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | void MediaPlayer::next() { | 159 | void MediaPlayer::next() { |
160 | if ( playList->next() ) | 160 | if ( playList->next() ) |
161 | play(); | 161 | play(); |
162 | else if ( mediaPlayerState->looping() ) { | 162 | else if ( mediaPlayerState->looping() ) { |
163 | if ( playList->first() ) | 163 | if ( playList->first() ) |
164 | play(); | 164 | play(); |
165 | } else | 165 | } else |
166 | mediaPlayerState->setList(); | 166 | mediaPlayerState->setList(); |
167 | } | 167 | } |
168 | 168 | ||
169 | 169 | ||
170 | void MediaPlayer::startDecreasingVolume() { | 170 | void MediaPlayer::startDecreasingVolume() { |
171 | volumeDirection = -1; | 171 | volumeDirection = -1; |
172 | startTimer( 100 ); | 172 | startTimer( 100 ); |
173 | AudioDevice::decreaseVolume(); | 173 | AudioDevice::decreaseVolume(); |
174 | } | 174 | } |
175 | 175 | ||
176 | 176 | ||
177 | void MediaPlayer::startIncreasingVolume() { | 177 | void MediaPlayer::startIncreasingVolume() { |
178 | volumeDirection = +1; | 178 | volumeDirection = +1; |
179 | startTimer( 100 ); | 179 | startTimer( 100 ); |
180 | AudioDevice::increaseVolume(); | 180 | AudioDevice::increaseVolume(); |
181 | 181 | ||
182 | } | 182 | } |
183 | 183 | ||
184 | bool drawnOnScreenDisplay = FALSE; | 184 | bool drawnOnScreenDisplay = FALSE; |
185 | unsigned int onScreenDisplayVolume = 0; | 185 | unsigned int onScreenDisplayVolume = 0; |
186 | const int yoff = 110; | 186 | const int yoff = 110; |
187 | 187 | ||
188 | void MediaPlayer::stopChangingVolume() { | 188 | void MediaPlayer::stopChangingVolume() { |
189 | killTimers(); | 189 | killTimers(); |
190 | 190 | ||
191 | // Get rid of the on-screen display stuff | 191 | // Get rid of the on-screen display stuff |
192 | drawnOnScreenDisplay = FALSE; | 192 | drawnOnScreenDisplay = FALSE; |
193 | onScreenDisplayVolume = 0; | 193 | onScreenDisplayVolume = 0; |
194 | int w = audioUI->width(); | 194 | int w = audioUI->width(); |
195 | int h = audioUI->height(); | 195 | int h = audioUI->height(); |
196 | audioUI->repaint( (w - 200) / 2, h - yoff, 200 + 9, 70, FALSE ); | 196 | audioUI->repaint( (w - 200) / 2, h - yoff, 200 + 9, 70, FALSE ); |
197 | } | 197 | } |
198 | 198 | ||
199 | 199 | ||
200 | void MediaPlayer::timerEvent( QTimerEvent * ) { | 200 | void MediaPlayer::timerEvent( QTimerEvent * ) { |
201 | // qDebug("timer"); | 201 | // qDebug("timer"); |
202 | if ( volumeDirection == +1 ) | 202 | if ( volumeDirection == +1 ) |
203 | AudioDevice::increaseVolume(); | 203 | AudioDevice::increaseVolume(); |
204 | else if ( volumeDirection == -1 ) | 204 | else if ( volumeDirection == -1 ) |
205 | AudioDevice::decreaseVolume(); | 205 | AudioDevice::decreaseVolume(); |
206 | 206 | ||
207 | // Display an on-screen display volume | 207 | // Display an on-screen display volume |
208 | unsigned int l, r, v; bool m; | 208 | unsigned int l, r, v; bool m; |
209 | AudioDevice::getVolume( l, r, m ); | 209 | AudioDevice::getVolume( l, r, m ); |
210 | v = ((l + r) * 11) / (2*0xFFFF); | 210 | v = ((l + r) * 11) / (2*0xFFFF); |
211 | 211 | ||
212 | if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) { | 212 | if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) { |
213 | // qDebug("returning %d, %d, %d, %d", v, l, r, m); | 213 | // qDebug("returning %d, %d, %d, %d", v, l, r, m); |
214 | return; | 214 | return; |
215 | } | 215 | } |
216 | 216 | ||
217 | int w = audioUI->width(); | 217 | int w = audioUI->width(); |
218 | int h = audioUI->height(); | 218 | int h = audioUI->height(); |
219 | 219 | ||
220 | if ( drawnOnScreenDisplay ) { | 220 | if ( drawnOnScreenDisplay ) { |
221 | if ( onScreenDisplayVolume > v ) | 221 | if ( onScreenDisplayVolume > v ) |
222 | audioUI->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, | 222 | audioUI->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, |
223 | (onScreenDisplayVolume - v) * 20 + 9, 30, FALSE ); | 223 | (onScreenDisplayVolume - v) * 20 + 9, 30, FALSE ); |
224 | } | 224 | } |
225 | 225 | ||
226 | drawnOnScreenDisplay = TRUE; | 226 | drawnOnScreenDisplay = TRUE; |
227 | onScreenDisplayVolume = v; | 227 | onScreenDisplayVolume = v; |
228 | 228 | ||
229 | QPainter p( audioUI ); | 229 | QPainter p( audioUI ); |
230 | p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); | 230 | p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); |
231 | p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); | 231 | p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); |
232 | 232 | ||
233 | QFont f; | 233 | QFont f; |
234 | f.setPixelSize( 20 ); | 234 | f.setPixelSize( 20 ); |
235 | f.setBold( TRUE ); | 235 | f.setBold( TRUE ); |
236 | p.setFont( f ); | 236 | p.setFont( f ); |
237 | p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") ); | 237 | p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") ); |
238 | 238 | ||
239 | for ( unsigned int i = 0; i < 10; i++ ) { | 239 | for ( unsigned int i = 0; i < 10; i++ ) { |
240 | if ( v > i ) | 240 | if ( v > i ) |
241 | p.drawRect( (w - 200) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); | 241 | p.drawRect( (w - 200) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); |
242 | else | 242 | else |
243 | p.drawRect( (w - 200) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); | 243 | p.drawRect( (w - 200) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); |
244 | } | 244 | } |
245 | } | 245 | } |
246 | 246 | ||
247 | void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { | 247 | void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { |
248 | switch ( e->key() ) { | 248 | switch ( e->key() ) { |
249 | ////////////////////////////// Zaurus keys | 249 | ////////////////////////////// Zaurus keys |
250 | case Key_Home: | 250 | case Key_Home: |
251 | break; | 251 | break; |
252 | case Key_F9: //activity | 252 | case Key_F9: //activity |
253 | break; | 253 | break; |
254 | case Key_F10: //contacts | 254 | case Key_F10: //contacts |
255 | break; | 255 | break; |
256 | case Key_F11: //menu | 256 | case Key_F11: //menu |
257 | break; | 257 | break; |
258 | case Key_F12: //home | 258 | case Key_F12: //home |
259 | qDebug("Blank here"); | 259 | // qDebug("Blank here"); |
260 | break; | 260 | break; |
261 | case Key_F13: //mail | 261 | case Key_F13: //mail |
262 | break; | 262 | break; |
263 | } | 263 | } |
264 | } | 264 | } |
265 | 265 | ||
266 | void MediaPlayer::doBlank() { | 266 | void MediaPlayer::doBlank() { |
267 | 267 | ||
268 | } | 268 | } |
269 | 269 | ||
270 | void MediaPlayer::doUnblank() { | 270 | void MediaPlayer::doUnblank() { |
271 | 271 | ||
272 | } | 272 | } |
273 | 273 | ||
274 | void MediaPlayer::cleanUp() { | 274 | void MediaPlayer::cleanUp() { |
275 | // QPEApplication::grabKeyboard(); | 275 | // QPEApplication::grabKeyboard(); |
276 | // QPEApplication::ungrabKeyboard(); | 276 | // QPEApplication::ungrabKeyboard(); |
277 | 277 | ||
278 | } | 278 | } |
diff --git a/core/multimedia/opieplayer/mediaplayerstate.cpp b/core/multimedia/opieplayer/mediaplayerstate.cpp index cf166d6..6823076 100644 --- a/core/multimedia/opieplayer/mediaplayerstate.cpp +++ b/core/multimedia/opieplayer/mediaplayerstate.cpp | |||
@@ -1,195 +1,195 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
21 | #include <qpe/qlibrary.h> | 21 | #include <qpe/qlibrary.h> |
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | #include <qvaluelist.h> | 23 | #include <qvaluelist.h> |
24 | #include <qobject.h> | 24 | #include <qobject.h> |
25 | #include <qdir.h> | 25 | #include <qdir.h> |
26 | #include <qpe/mediaplayerplugininterface.h> | 26 | #include <qpe/mediaplayerplugininterface.h> |
27 | #include "mediaplayerstate.h" | 27 | #include "mediaplayerstate.h" |
28 | 28 | ||
29 | 29 | ||
30 | 30 | ||
31 | #ifdef QT_NO_COMPONENT | 31 | #ifdef QT_NO_COMPONENT |
32 | // Plugins which are compiled in when no plugin architecture available | 32 | // Plugins which are compiled in when no plugin architecture available |
33 | #include "libmad/libmadpluginimpl.h" | 33 | #include "libmad/libmadpluginimpl.h" |
34 | #include "libmpeg3/libmpeg3pluginimpl.h" | 34 | #include "libmpeg3/libmpeg3pluginimpl.h" |
35 | #include "wavplugin/wavpluginimpl.h" | 35 | #include "wavplugin/wavpluginimpl.h" |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | 38 | ||
39 | //#define MediaPlayerDebug(x) qDebug x | 39 | //#define MediaPlayerDebug(x) qDebug x |
40 | #define MediaPlayerDebug(x) | 40 | #define MediaPlayerDebug(x) |
41 | 41 | ||
42 | 42 | ||
43 | MediaPlayerState::MediaPlayerState( QObject *parent, const char *name ) | 43 | MediaPlayerState::MediaPlayerState( QObject *parent, const char *name ) |
44 | : QObject( parent, name ), decoder( NULL ), libmpeg3decoder( NULL ) { | 44 | : QObject( parent, name ), decoder( NULL ), libmpeg3decoder( NULL ) { |
45 | Config cfg( "OpiePlayer" ); | 45 | Config cfg( "OpiePlayer" ); |
46 | readConfig( cfg ); | 46 | readConfig( cfg ); |
47 | loadPlugins(); | 47 | loadPlugins(); |
48 | } | 48 | } |
49 | 49 | ||
50 | 50 | ||
51 | MediaPlayerState::~MediaPlayerState() { | 51 | MediaPlayerState::~MediaPlayerState() { |
52 | Config cfg( "OpiePlayer" ); | 52 | Config cfg( "OpiePlayer" ); |
53 | writeConfig( cfg ); | 53 | writeConfig( cfg ); |
54 | } | 54 | } |
55 | 55 | ||
56 | 56 | ||
57 | void MediaPlayerState::readConfig( Config& cfg ) { | 57 | void MediaPlayerState::readConfig( Config& cfg ) { |
58 | cfg.setGroup("Options"); | 58 | cfg.setGroup("Options"); |
59 | isFullscreen = cfg.readBoolEntry( "FullScreen" ); | 59 | isFullscreen = cfg.readBoolEntry( "FullScreen" ); |
60 | isScaled = cfg.readBoolEntry( "Scaling" ); | 60 | isScaled = cfg.readBoolEntry( "Scaling" ); |
61 | isLooping = cfg.readBoolEntry( "Looping" ); | 61 | isLooping = cfg.readBoolEntry( "Looping" ); |
62 | isShuffled = cfg.readBoolEntry( "Shuffle" ); | 62 | isShuffled = cfg.readBoolEntry( "Shuffle" ); |
63 | usePlaylist = cfg.readBoolEntry( "UsePlayList" ); | 63 | usePlaylist = cfg.readBoolEntry( "UsePlayList" ); |
64 | usePlaylist = TRUE; | 64 | usePlaylist = TRUE; |
65 | isPlaying = FALSE; | 65 | isPlaying = FALSE; |
66 | isPaused = FALSE; | 66 | isPaused = FALSE; |
67 | curPosition = 0; | 67 | curPosition = 0; |
68 | curLength = 0; | 68 | curLength = 0; |
69 | curView = 'l'; | 69 | curView = 'l'; |
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | void MediaPlayerState::writeConfig( Config& cfg ) const { | 73 | void MediaPlayerState::writeConfig( Config& cfg ) const { |
74 | cfg.setGroup("Options"); | 74 | cfg.setGroup("Options"); |
75 | cfg.writeEntry("FullScreen", isFullscreen ); | 75 | cfg.writeEntry("FullScreen", isFullscreen ); |
76 | cfg.writeEntry("Scaling", isScaled ); | 76 | cfg.writeEntry("Scaling", isScaled ); |
77 | cfg.writeEntry("Looping", isLooping ); | 77 | cfg.writeEntry("Looping", isLooping ); |
78 | cfg.writeEntry("Shuffle", isShuffled ); | 78 | cfg.writeEntry("Shuffle", isShuffled ); |
79 | cfg.writeEntry("UsePlayList", usePlaylist ); | 79 | cfg.writeEntry("UsePlayList", usePlaylist ); |
80 | } | 80 | } |
81 | 81 | ||
82 | 82 | ||
83 | struct MediaPlayerPlugin { | 83 | struct MediaPlayerPlugin { |
84 | #ifndef QT_NO_COMPONENT | 84 | #ifndef QT_NO_COMPONENT |
85 | QLibrary *library; | 85 | QLibrary *library; |
86 | #endif | 86 | #endif |
87 | MediaPlayerPluginInterface *iface; | 87 | MediaPlayerPluginInterface *iface; |
88 | MediaPlayerDecoder *decoder; | 88 | MediaPlayerDecoder *decoder; |
89 | MediaPlayerEncoder *encoder; | 89 | MediaPlayerEncoder *encoder; |
90 | }; | 90 | }; |
91 | 91 | ||
92 | 92 | ||
93 | static QValueList<MediaPlayerPlugin> pluginList; | 93 | static QValueList<MediaPlayerPlugin> pluginList; |
94 | 94 | ||
95 | 95 | ||
96 | // Find the first decoder which supports this type of file | 96 | // Find the first decoder which supports this type of file |
97 | MediaPlayerDecoder *MediaPlayerState::newDecoder( const QString& file ) { | 97 | MediaPlayerDecoder *MediaPlayerState::newDecoder( const QString& file ) { |
98 | MediaPlayerDecoder *tmpDecoder = NULL; | 98 | MediaPlayerDecoder *tmpDecoder = NULL; |
99 | QValueList<MediaPlayerPlugin>::Iterator it; | 99 | QValueList<MediaPlayerPlugin>::Iterator it; |
100 | for ( it = pluginList.begin(); it != pluginList.end(); ++it ) { | 100 | for ( it = pluginList.begin(); it != pluginList.end(); ++it ) { |
101 | if ( (*it).decoder->isFileSupported( file ) ) { | 101 | if ( (*it).decoder->isFileSupported( file ) ) { |
102 | tmpDecoder = (*it).decoder; | 102 | tmpDecoder = (*it).decoder; |
103 | break; | 103 | break; |
104 | } | 104 | } |
105 | } | 105 | } |
106 | if(file.left(4)=="http") | 106 | if(file.left(4)=="http") |
107 | isStreaming = TRUE; | 107 | isStreaming = TRUE; |
108 | else | 108 | else |
109 | isStreaming = FALSE; | 109 | isStreaming = FALSE; |
110 | return decoder = tmpDecoder; | 110 | return decoder = tmpDecoder; |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | MediaPlayerDecoder *MediaPlayerState::curDecoder() { | 114 | MediaPlayerDecoder *MediaPlayerState::curDecoder() { |
115 | return decoder; | 115 | return decoder; |
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
119 | // ### hack to get true sample count | 119 | // ### hack to get true sample count |
120 | MediaPlayerDecoder *MediaPlayerState::libMpeg3Decoder() { | 120 | MediaPlayerDecoder *MediaPlayerState::libMpeg3Decoder() { |
121 | return libmpeg3decoder; | 121 | return libmpeg3decoder; |
122 | } | 122 | } |
123 | 123 | ||
124 | // ### hack to get true sample count | 124 | // ### hack to get true sample count |
125 | // MediaPlayerDecoder *MediaPlayerState::libWavDecoder() { | 125 | // MediaPlayerDecoder *MediaPlayerState::libWavDecoder() { |
126 | // return libwavdecoder; | 126 | // return libwavdecoder; |
127 | // } | 127 | // } |
128 | 128 | ||
129 | void MediaPlayerState::loadPlugins() { | 129 | void MediaPlayerState::loadPlugins() { |
130 | qDebug("load plugins"); | 130 | // qDebug("load plugins"); |
131 | #ifndef QT_NO_COMPONENT | 131 | #ifndef QT_NO_COMPONENT |
132 | QValueList<MediaPlayerPlugin>::Iterator mit; | 132 | QValueList<MediaPlayerPlugin>::Iterator mit; |
133 | for ( mit = pluginList.begin(); mit != pluginList.end(); ++mit ) { | 133 | for ( mit = pluginList.begin(); mit != pluginList.end(); ++mit ) { |
134 | (*mit).iface->release(); | 134 | (*mit).iface->release(); |
135 | (*mit).library->unload(); | 135 | (*mit).library->unload(); |
136 | delete (*mit).library; | 136 | delete (*mit).library; |
137 | } | 137 | } |
138 | pluginList.clear(); | 138 | pluginList.clear(); |
139 | 139 | ||
140 | QString path = QPEApplication::qpeDir() + "/plugins/codecs"; | 140 | QString path = QPEApplication::qpeDir() + "/plugins/codecs"; |
141 | QDir dir( path, "lib*.so" ); | 141 | QDir dir( path, "lib*.so" ); |
142 | QStringList list = dir.entryList(); | 142 | QStringList list = dir.entryList(); |
143 | QStringList::Iterator it; | 143 | QStringList::Iterator it; |
144 | for ( it = list.begin(); it != list.end(); ++it ) { | 144 | for ( it = list.begin(); it != list.end(); ++it ) { |
145 | MediaPlayerPluginInterface *iface = 0; | 145 | MediaPlayerPluginInterface *iface = 0; |
146 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 146 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
147 | // qDebug( "querying: %s", QString( path + "/" + *it ).latin1() ); | 147 | // qDebug( "querying: %s", QString( path + "/" + *it ).latin1() ); |
148 | 148 | ||
149 | if ( lib->queryInterface( IID_MediaPlayerPlugin, (QUnknownInterface**)&iface ) == QS_OK ) { | 149 | if ( lib->queryInterface( IID_MediaPlayerPlugin, (QUnknownInterface**)&iface ) == QS_OK ) { |
150 | 150 | ||
151 | // qDebug( "loading: %s", QString( path + "/" + *it ).latin1() ); | 151 | // qDebug( "loading: %s", QString( path + "/" + *it ).latin1() ); |
152 | 152 | ||
153 | MediaPlayerPlugin plugin; | 153 | MediaPlayerPlugin plugin; |
154 | plugin.library = lib; | 154 | plugin.library = lib; |
155 | plugin.iface = iface; | 155 | plugin.iface = iface; |
156 | plugin.decoder = plugin.iface->decoder(); | 156 | plugin.decoder = plugin.iface->decoder(); |
157 | plugin.encoder = plugin.iface->encoder(); | 157 | plugin.encoder = plugin.iface->encoder(); |
158 | pluginList.append( plugin ); | 158 | pluginList.append( plugin ); |
159 | 159 | ||
160 | // ### hack to get true sample count | 160 | // ### hack to get true sample count |
161 | if ( plugin.decoder->pluginName() == QString("LibMpeg3Plugin") ) | 161 | if ( plugin.decoder->pluginName() == QString("LibMpeg3Plugin") ) |
162 | libmpeg3decoder = plugin.decoder; | 162 | libmpeg3decoder = plugin.decoder; |
163 | 163 | ||
164 | } else { | 164 | } else { |
165 | delete lib; | 165 | delete lib; |
166 | } | 166 | } |
167 | } | 167 | } |
168 | #else | 168 | #else |
169 | pluginList.clear(); | 169 | pluginList.clear(); |
170 | 170 | ||
171 | MediaPlayerPlugin plugin0; | 171 | MediaPlayerPlugin plugin0; |
172 | plugin0.iface = new LibMpeg3PluginImpl; | 172 | plugin0.iface = new LibMpeg3PluginImpl; |
173 | plugin0.decoder = plugin0.iface->decoder(); | 173 | plugin0.decoder = plugin0.iface->decoder(); |
174 | plugin0.encoder = plugin0.iface->encoder(); | 174 | plugin0.encoder = plugin0.iface->encoder(); |
175 | pluginList.append( plugin0 ); | 175 | pluginList.append( plugin0 ); |
176 | 176 | ||
177 | MediaPlayerPlugin plugin1; | 177 | MediaPlayerPlugin plugin1; |
178 | plugin1.iface = new LibMadPluginImpl; | 178 | plugin1.iface = new LibMadPluginImpl; |
179 | plugin1.decoder = plugin1.iface->decoder(); | 179 | plugin1.decoder = plugin1.iface->decoder(); |
180 | plugin1.encoder = plugin1.iface->encoder(); | 180 | plugin1.encoder = plugin1.iface->encoder(); |
181 | pluginList.append( plugin1 ); | 181 | pluginList.append( plugin1 ); |
182 | 182 | ||
183 | MediaPlayerPlugin plugin2; | 183 | MediaPlayerPlugin plugin2; |
184 | plugin2.iface = new WavPluginImpl; | 184 | plugin2.iface = new WavPluginImpl; |
185 | plugin2.decoder = plugin2.iface->decoder(); | 185 | plugin2.decoder = plugin2.iface->decoder(); |
186 | plugin2.encoder = plugin2.iface->encoder(); | 186 | plugin2.encoder = plugin2.iface->encoder(); |
187 | pluginList.append( plugin2 ); | 187 | pluginList.append( plugin2 ); |
188 | #endif | 188 | #endif |
189 | 189 | ||
190 | if ( pluginList.count() ) | 190 | if ( pluginList.count() ) |
191 | MediaPlayerDebug(( "%i decoders found", pluginList.count() )); | 191 | MediaPlayerDebug(( "%i decoders found", pluginList.count() )); |
192 | else | 192 | else |
193 | MediaPlayerDebug(( "No decoders found" )); | 193 | MediaPlayerDebug(( "No decoders found" )); |
194 | } | 194 | } |
195 | 195 | ||
diff --git a/core/multimedia/opieplayer/om3u.cpp b/core/multimedia/opieplayer/om3u.cpp index 3541e5f..8b92a8c 100644 --- a/core/multimedia/opieplayer/om3u.cpp +++ b/core/multimedia/opieplayer/om3u.cpp | |||
@@ -1,172 +1,172 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> | 4 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; General Public License for more | 20 | ..}^=.= = ; General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = General Public License along with | 24 | -_. . . )=. = General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | 29 | ||
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include "playlistwidget.h" | 32 | #include "playlistwidget.h" |
33 | #include "om3u.h" | 33 | #include "om3u.h" |
34 | 34 | ||
35 | #include <qpe/applnk.h> | 35 | #include <qpe/applnk.h> |
36 | #include <qpe/qpeapplication.h> | 36 | #include <qpe/qpeapplication.h> |
37 | #include <qpe/storage.h> | 37 | #include <qpe/storage.h> |
38 | #include <qpe/mimetype.h> | 38 | #include <qpe/mimetype.h> |
39 | #include <qpe/global.h> | 39 | #include <qpe/global.h> |
40 | #include <qpe/resource.h> | 40 | #include <qpe/resource.h> |
41 | 41 | ||
42 | #include <qdir.h> | 42 | #include <qdir.h> |
43 | #include <qregexp.h> | 43 | #include <qregexp.h> |
44 | #include <qstring.h> | 44 | #include <qstring.h> |
45 | #include <qtextstream.h> | 45 | #include <qtextstream.h> |
46 | #include <qstringlist.h> | 46 | #include <qstringlist.h> |
47 | #include <qcstring.h> | 47 | #include <qcstring.h> |
48 | 48 | ||
49 | static inline QString fullBaseName ( const QFileInfo &fi ) | 49 | static inline QString fullBaseName ( const QFileInfo &fi ) |
50 | { | 50 | { |
51 | QString str = fi. fileName ( ); | 51 | QString str = fi. fileName ( ); |
52 | return str. left ( str. findRev ( '.' )); | 52 | return str. left ( str. findRev ( '.' )); |
53 | } | 53 | } |
54 | 54 | ||
55 | 55 | ||
56 | //extern PlayListWidget *playList; | 56 | //extern PlayListWidget *playList; |
57 | 57 | ||
58 | Om3u::Om3u( const QString &filePath, int mode) | 58 | Om3u::Om3u( const QString &filePath, int mode) |
59 | : QStringList (){ | 59 | : QStringList (){ |
60 | //qDebug("<<<<<<<new m3u "+filePath); | 60 | //qDebug("<<<<<<<new m3u "+filePath); |
61 | f.setName(filePath); | 61 | f.setName(filePath); |
62 | f.open(mode); | 62 | f.open(mode); |
63 | } | 63 | } |
64 | 64 | ||
65 | Om3u::~Om3u(){} | 65 | Om3u::~Om3u(){} |
66 | 66 | ||
67 | void Om3u::readM3u() { | 67 | void Om3u::readM3u() { |
68 | // qDebug("<<<<<<reading m3u "+f.name()); | 68 | // qDebug("<<<<<<reading m3u "+f.name()); |
69 | QTextStream t(&f); | 69 | QTextStream t(&f); |
70 | QString s; | 70 | QString s; |
71 | while ( !t.atEnd() ) { | 71 | while ( !t.atEnd() ) { |
72 | s=t.readLine(); | 72 | s=t.readLine(); |
73 | qDebug(s); | 73 | // qDebug(s); |
74 | if( s.find( "#", 0, TRUE) == -1 ) { | 74 | if( s.find( "#", 0, TRUE) == -1 ) { |
75 | if( s.left(2) == "E:" || s.left(2) == "P:" ) { | 75 | if( s.left(2) == "E:" || s.left(2) == "P:" ) { |
76 | s = s.right( s.length() -2 ); | 76 | s = s.right( s.length() -2 ); |
77 | QFileInfo f( s ); | 77 | QFileInfo f( s ); |
78 | QString name = fullBaseName ( f ); | 78 | QString name = fullBaseName ( f ); |
79 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 ); | 79 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 ); |
80 | s=s.replace( QRegExp( "\\" ), "/" ); | 80 | s=s.replace( QRegExp( "\\" ), "/" ); |
81 | append(s); | 81 | append(s); |
82 | // qDebug(s); | 82 | // qDebug(s); |
83 | } else { // is url | 83 | } else { // is url |
84 | s.replace( QRegExp( "%20" )," " ); | 84 | s.replace( QRegExp( "%20" )," " ); |
85 | QString name; | 85 | QString name; |
86 | // if( name.left( 4 ) == "http" ) { | 86 | // if( name.left( 4 ) == "http" ) { |
87 | // name = s.right( s.length() - 7 ); | 87 | // name = s.right( s.length() - 7 ); |
88 | // } else { | 88 | // } else { |
89 | name = s; | 89 | name = s; |
90 | // } | 90 | // } |
91 | append(name); | 91 | append(name); |
92 | // qDebug(name); | 92 | // qDebug(name); |
93 | } | 93 | } |
94 | } | 94 | } |
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | void Om3u::readPls() { //it's a pls file | 98 | void Om3u::readPls() { //it's a pls file |
99 | QTextStream t( &f ); | 99 | QTextStream t( &f ); |
100 | QString s; | 100 | QString s; |
101 | while ( !t.atEnd() ) { | 101 | while ( !t.atEnd() ) { |
102 | s = t.readLine(); | 102 | s = t.readLine(); |
103 | if( s.left(4) == "File" ) { | 103 | if( s.left(4) == "File" ) { |
104 | s = s.right( s.length() - 6 ); | 104 | s = s.right( s.length() - 6 ); |
105 | s.replace( QRegExp( "%20" )," "); | 105 | s.replace( QRegExp( "%20" )," "); |
106 | // qDebug( "adding " + s + " to playlist" ); | 106 | // qDebug( "adding " + s + " to playlist" ); |
107 | // numberofentries=2 | 107 | // numberofentries=2 |
108 | // File1=http | 108 | // File1=http |
109 | // Title | 109 | // Title |
110 | // Length | 110 | // Length |
111 | // Version | 111 | // Version |
112 | // File2=http | 112 | // File2=http |
113 | s = s.replace( QRegExp( "\\" ), "/" ); | 113 | s = s.replace( QRegExp( "\\" ), "/" ); |
114 | QFileInfo f( s ); | 114 | QFileInfo f( s ); |
115 | QString name = fullBaseName ( f ); | 115 | QString name = fullBaseName ( f ); |
116 | if( name.left( 4 ) == "http" ) { | 116 | if( name.left( 4 ) == "http" ) { |
117 | name = s.right( s.length() - 7); | 117 | name = s.right( s.length() - 7); |
118 | } else { | 118 | } else { |
119 | name = s; | 119 | name = s; |
120 | } | 120 | } |
121 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); | 121 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); |
122 | if( s.at( s.length() - 4) == '.') // if this is probably a file | 122 | if( s.at( s.length() - 4) == '.') // if this is probably a file |
123 | append(s); | 123 | append(s); |
124 | else { //if its a url | 124 | else { //if its a url |
125 | if( name.right( 1 ).find( '/' ) == -1) { | 125 | if( name.right( 1 ).find( '/' ) == -1) { |
126 | s += "/"; | 126 | s += "/"; |
127 | } | 127 | } |
128 | append(s); | 128 | append(s); |
129 | } | 129 | } |
130 | } | 130 | } |
131 | } | 131 | } |
132 | } | 132 | } |
133 | 133 | ||
134 | void Om3u::write() { //writes list to m3u file | 134 | void Om3u::write() { //writes list to m3u file |
135 | QString list; | 135 | QString list; |
136 | if(count()>0) { | 136 | if(count()>0) { |
137 | for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { | 137 | for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { |
138 | qDebug(*it); | 138 | // qDebug(*it); |
139 | list += *it+"\n"; | 139 | list += *it+"\n"; |
140 | } | 140 | } |
141 | f.writeBlock( list, list.length() ); | 141 | f.writeBlock( list, list.length() ); |
142 | } | 142 | } |
143 | // f.close(); | 143 | // f.close(); |
144 | } | 144 | } |
145 | 145 | ||
146 | void Om3u::add(const QString &filePath) { //adds to m3u file | 146 | void Om3u::add(const QString &filePath) { //adds to m3u file |
147 | append(filePath); | 147 | append(filePath); |
148 | } | 148 | } |
149 | 149 | ||
150 | void Om3u::remove(const QString &filePath) { //removes from m3u list | 150 | void Om3u::remove(const QString &filePath) { //removes from m3u list |
151 | QString list, currentFile; | 151 | QString list, currentFile; |
152 | if(count()>0) { | 152 | if(count()>0) { |
153 | for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { | 153 | for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { |
154 | currentFile=*it; | 154 | currentFile=*it; |
155 | // qDebug(*it); | 155 | // qDebug(*it); |
156 | 156 | ||
157 | if( filePath != currentFile) | 157 | if( filePath != currentFile) |
158 | list += currentFile+"\n"; | 158 | list += currentFile+"\n"; |
159 | } | 159 | } |
160 | f.writeBlock( list, list.length() ); | 160 | f.writeBlock( list, list.length() ); |
161 | } | 161 | } |
162 | } | 162 | } |
163 | 163 | ||
164 | void Om3u::deleteFile(const QString &filePath) {//deletes m3u file | 164 | void Om3u::deleteFile(const QString &filePath) {//deletes m3u file |
165 | f.close(); | 165 | f.close(); |
166 | f.remove(); | 166 | f.remove(); |
167 | 167 | ||
168 | } | 168 | } |
169 | 169 | ||
170 | void Om3u::close() { //closes m3u file | 170 | void Om3u::close() { //closes m3u file |
171 | f.close(); | 171 | f.close(); |
172 | } | 172 | } |
diff --git a/core/multimedia/opieplayer/playlistselection.cpp b/core/multimedia/opieplayer/playlistselection.cpp index 67187f8..94567f2 100644 --- a/core/multimedia/opieplayer/playlistselection.cpp +++ b/core/multimedia/opieplayer/playlistselection.cpp | |||
@@ -1,216 +1,216 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qpe/applnk.h> | 20 | #include <qpe/applnk.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | 23 | ||
24 | #include <qpainter.h> | 24 | #include <qpainter.h> |
25 | #include <qimage.h> | 25 | #include <qimage.h> |
26 | #include <qheader.h> | 26 | #include <qheader.h> |
27 | #include <qlistview.h> | 27 | #include <qlistview.h> |
28 | #include <qlist.h> | 28 | #include <qlist.h> |
29 | #include <qpixmap.h> | 29 | #include <qpixmap.h> |
30 | 30 | ||
31 | #include "playlistselection.h" | 31 | #include "playlistselection.h" |
32 | 32 | ||
33 | #include <stdlib.h> | 33 | #include <stdlib.h> |
34 | 34 | ||
35 | class PlayListSelectionItem : public QListViewItem { | 35 | class PlayListSelectionItem : public QListViewItem { |
36 | public: | 36 | public: |
37 | PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) { | 37 | PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) { |
38 | setText( 0, f->name() ); | 38 | setText( 0, f->name() ); |
39 | setPixmap( 0, f->pixmap() ); | 39 | setPixmap( 0, f->pixmap() ); |
40 | } | 40 | } |
41 | 41 | ||
42 | ~PlayListSelectionItem() { | 42 | ~PlayListSelectionItem() { |
43 | }; | 43 | }; |
44 | 44 | ||
45 | const DocLnk *file() const { return fl; } | 45 | const DocLnk *file() const { return fl; } |
46 | 46 | ||
47 | private: | 47 | private: |
48 | const DocLnk *fl; | 48 | const DocLnk *fl; |
49 | }; | 49 | }; |
50 | 50 | ||
51 | 51 | ||
52 | PlayListSelection::PlayListSelection( QWidget *parent, const char *name ) | 52 | PlayListSelection::PlayListSelection( QWidget *parent, const char *name ) |
53 | : QListView( parent, name ) | 53 | : QListView( parent, name ) |
54 | { | 54 | { |
55 | // qDebug("starting playlistselector"); | 55 | // qDebug("starting playlistselector"); |
56 | // #ifdef USE_PLAYLIST_BACKGROUND | 56 | // #ifdef USE_PLAYLIST_BACKGROUND |
57 | // setStaticBackground( TRUE ); | 57 | // setStaticBackground( TRUE ); |
58 | // setBackgroundPixmap( Resource::loadPixmap( "opieplayer/background" ) ); | 58 | // setBackgroundPixmap( Resource::loadPixmap( "opieplayer/background" ) ); |
59 | 59 | ||
60 | // setBackgroundPixmap( Resource::loadPixmap( "launcher/opielogo" ) ); | 60 | // setBackgroundPixmap( Resource::loadPixmap( "launcher/opielogo" ) ); |
61 | // #endif | 61 | // #endif |
62 | // addColumn("Title",236); | 62 | // addColumn("Title",236); |
63 | // setAllColumnsShowFocus( TRUE ); | 63 | // setAllColumnsShowFocus( TRUE ); |
64 | addColumn( tr( "Playlist Selection" ) ); | 64 | addColumn( tr( "Playlist Selection" ) ); |
65 | header()->hide(); | 65 | header()->hide(); |
66 | // setSorting( -1, FALSE ); | 66 | // setSorting( -1, FALSE ); |
67 | // FIXME | 67 | // FIXME |
68 | } | 68 | } |
69 | 69 | ||
70 | 70 | ||
71 | PlayListSelection::~PlayListSelection() { | 71 | PlayListSelection::~PlayListSelection() { |
72 | } | 72 | } |
73 | 73 | ||
74 | 74 | ||
75 | // #ifdef USE_PLAYLIST_BACKGROUND | 75 | // #ifdef USE_PLAYLIST_BACKGROUND |
76 | void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) { | 76 | void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) { |
77 | // qDebug("drawBackground"); | 77 | // qDebug("drawBackground"); |
78 | p->fillRect( r, QBrush( white ) ); | 78 | p->fillRect( r, QBrush( white ) ); |
79 | // QImage logo = Resource::loadImage( "launcher/opielogo" ); | 79 | // QImage logo = Resource::loadImage( "launcher/opielogo" ); |
80 | // if ( !logo.isNull() ) | 80 | // if ( !logo.isNull() ) |
81 | // p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo ); | 81 | // p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo ); |
82 | } | 82 | } |
83 | // #endif | 83 | // #endif |
84 | 84 | ||
85 | 85 | ||
86 | void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) { | 86 | void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) { |
87 | if ( event->state() == QMouseEvent::LeftButton ) { | 87 | if ( event->state() == QMouseEvent::LeftButton ) { |
88 | QListViewItem *currentItem = selectedItem(); | 88 | QListViewItem *currentItem = selectedItem(); |
89 | QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) ); | 89 | QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) ); |
90 | if ( currentItem && currentItem->itemAbove() == itemUnder ) | 90 | if ( currentItem && currentItem->itemAbove() == itemUnder ) |
91 | moveSelectedUp(); | 91 | moveSelectedUp(); |
92 | else if ( currentItem && currentItem->itemBelow() == itemUnder ) | 92 | else if ( currentItem && currentItem->itemBelow() == itemUnder ) |
93 | moveSelectedDown(); | 93 | moveSelectedDown(); |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | 97 | ||
98 | const DocLnk *PlayListSelection::current() { | 98 | const DocLnk *PlayListSelection::current() { |
99 | PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem(); | 99 | PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem(); |
100 | if ( item ) | 100 | if ( item ) |
101 | return item->file(); | 101 | return item->file(); |
102 | return NULL; | 102 | return NULL; |
103 | } | 103 | } |
104 | 104 | ||
105 | 105 | ||
106 | void PlayListSelection::addToSelection( const DocLnk &lnk ) { | 106 | void PlayListSelection::addToSelection( const DocLnk &lnk ) { |
107 | PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) ); | 107 | PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) ); |
108 | QListViewItem *current = selectedItem(); | 108 | QListViewItem *current = selectedItem(); |
109 | if ( current ) | 109 | if ( current ) |
110 | item->moveItem( current ); | 110 | item->moveItem( current ); |
111 | setSelected( item, TRUE ); | 111 | setSelected( item, TRUE ); |
112 | ensureItemVisible( item); | 112 | ensureItemVisible( item); |
113 | } | 113 | } |
114 | 114 | ||
115 | 115 | ||
116 | void PlayListSelection::removeSelected() { | 116 | void PlayListSelection::removeSelected() { |
117 | QListViewItem *item = selectedItem(); | 117 | QListViewItem *item = selectedItem(); |
118 | if ( item ) | 118 | if ( item ) |
119 | delete item; | 119 | delete item; |
120 | setSelected( currentItem(), TRUE ); | 120 | setSelected( currentItem(), TRUE ); |
121 | ensureItemVisible( selectedItem() ); | 121 | ensureItemVisible( selectedItem() ); |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | void PlayListSelection::moveSelectedUp() { | 125 | void PlayListSelection::moveSelectedUp() { |
126 | QListViewItem *item = selectedItem(); | 126 | QListViewItem *item = selectedItem(); |
127 | if ( item && item->itemAbove() ) | 127 | if ( item && item->itemAbove() ) |
128 | item->itemAbove()->moveItem( item ); | 128 | item->itemAbove()->moveItem( item ); |
129 | ensureItemVisible( selectedItem() ); | 129 | ensureItemVisible( selectedItem() ); |
130 | } | 130 | } |
131 | 131 | ||
132 | 132 | ||
133 | void PlayListSelection::moveSelectedDown() { | 133 | void PlayListSelection::moveSelectedDown() { |
134 | QListViewItem *item = selectedItem(); | 134 | QListViewItem *item = selectedItem(); |
135 | if ( item && item->itemBelow() ) | 135 | if ( item && item->itemBelow() ) |
136 | item->moveItem( item->itemBelow() ); | 136 | item->moveItem( item->itemBelow() ); |
137 | ensureItemVisible( selectedItem() ); | 137 | ensureItemVisible( selectedItem() ); |
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | bool PlayListSelection::prev() { | 141 | bool PlayListSelection::prev() { |
142 | QListViewItem *item = selectedItem(); | 142 | QListViewItem *item = selectedItem(); |
143 | if ( item && item->itemAbove() ) | 143 | if ( item && item->itemAbove() ) |
144 | setSelected( item->itemAbove(), TRUE ); | 144 | setSelected( item->itemAbove(), TRUE ); |
145 | else | 145 | else |
146 | return FALSE; | 146 | return FALSE; |
147 | ensureItemVisible( selectedItem() ); | 147 | ensureItemVisible( selectedItem() ); |
148 | return TRUE; | 148 | return TRUE; |
149 | } | 149 | } |
150 | 150 | ||
151 | bool PlayListSelection::next() { | 151 | bool PlayListSelection::next() { |
152 | QListViewItem *item = selectedItem(); | 152 | QListViewItem *item = selectedItem(); |
153 | if ( item && item->itemBelow() ) | 153 | if ( item && item->itemBelow() ) |
154 | setSelected( item->itemBelow(), TRUE ); | 154 | setSelected( item->itemBelow(), TRUE ); |
155 | else | 155 | else |
156 | return FALSE; | 156 | return FALSE; |
157 | ensureItemVisible( selectedItem() ); | 157 | ensureItemVisible( selectedItem() ); |
158 | return TRUE; | 158 | return TRUE; |
159 | } | 159 | } |
160 | 160 | ||
161 | 161 | ||
162 | bool PlayListSelection::first() { | 162 | bool PlayListSelection::first() { |
163 | QListViewItem *item = firstChild(); | 163 | QListViewItem *item = firstChild(); |
164 | if ( item ) | 164 | if ( item ) |
165 | setSelected( item, TRUE ); | 165 | setSelected( item, TRUE ); |
166 | else | 166 | else |
167 | return FALSE; | 167 | return FALSE; |
168 | ensureItemVisible( selectedItem() ); | 168 | ensureItemVisible( selectedItem() ); |
169 | return TRUE; | 169 | return TRUE; |
170 | } | 170 | } |
171 | 171 | ||
172 | 172 | ||
173 | bool PlayListSelection::last() { | 173 | bool PlayListSelection::last() { |
174 | QListViewItem *prevItem = NULL; | 174 | QListViewItem *prevItem = NULL; |
175 | QListViewItem *item = firstChild(); | 175 | QListViewItem *item = firstChild(); |
176 | while ( ( item = item->nextSibling() ) ) | 176 | while ( ( item = item->nextSibling() ) ) |
177 | prevItem = item; | 177 | prevItem = item; |
178 | if ( prevItem ) | 178 | if ( prevItem ) |
179 | setSelected( prevItem, TRUE ); | 179 | setSelected( prevItem, TRUE ); |
180 | else | 180 | else |
181 | return FALSE; | 181 | return FALSE; |
182 | ensureItemVisible( selectedItem() ); | 182 | ensureItemVisible( selectedItem() ); |
183 | return TRUE; | 183 | return TRUE; |
184 | } | 184 | } |
185 | 185 | ||
186 | void PlayListSelection::unSelect() | 186 | void PlayListSelection::unSelect() |
187 | { | 187 | { |
188 | QListViewItem *item = selectedItem(); | 188 | QListViewItem *item = selectedItem(); |
189 | setSelected( currentItem(), FALSE); | 189 | setSelected( currentItem(), FALSE); |
190 | } | 190 | } |
191 | 191 | ||
192 | void PlayListSelection::writeCurrent( Config& cfg ) { | 192 | void PlayListSelection::writeCurrent( Config& cfg ) { |
193 | cfg.setGroup("PlayList"); | 193 | cfg.setGroup("PlayList"); |
194 | QListViewItem *item = selectedItem(); | 194 | QListViewItem *item = selectedItem(); |
195 | if ( item ) | 195 | if ( item ) |
196 | cfg.writeEntry("current", item->text(0) ); | 196 | cfg.writeEntry("current", item->text(0) ); |
197 | qDebug(item->text(0)); | 197 | // qDebug(item->text(0)); |
198 | 198 | ||
199 | } | 199 | } |
200 | 200 | ||
201 | void PlayListSelection::setSelectedItem(const QString &strk ) { | 201 | void PlayListSelection::setSelectedItem(const QString &strk ) { |
202 | 202 | ||
203 | unSelect(); | 203 | unSelect(); |
204 | QListViewItemIterator it( this ); | 204 | QListViewItemIterator it( this ); |
205 | for ( ; it.current(); ++it ) { | 205 | for ( ; it.current(); ++it ) { |
206 | // qDebug( it.current()->text(0)); | 206 | // qDebug( it.current()->text(0)); |
207 | if( strk == it.current()->text(0)) { | 207 | if( strk == it.current()->text(0)) { |
208 | // qDebug( "We have a match "+strk); | 208 | // qDebug( "We have a match "+strk); |
209 | setSelected( it.current(), TRUE); | 209 | setSelected( it.current(), TRUE); |
210 | ensureItemVisible( it.current() ); | 210 | ensureItemVisible( it.current() ); |
211 | return; | 211 | return; |
212 | } | 212 | } |
213 | } | 213 | } |
214 | // setSelected( item, TRUE ); | 214 | // setSelected( item, TRUE ); |
215 | // ensureItemVisible( selectedItem() ); | 215 | // ensureItemVisible( selectedItem() ); |
216 | } | 216 | } |
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index 7ea95ab..1fc7dd8 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp | |||
@@ -1,1506 +1,1478 @@ | |||
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;audio/x-ogg"; | 93 | QString audioMimes ="audio/mpeg;audio/x-wav;audio/x-ogg;audio/x-mod;audio/x-ogg"; |
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 | channel = new QCopChannel( "QPE/Application/opieplayer", this ); | 145 | channel = new QCopChannel( "QPE/Application/opieplayer", this ); |
146 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 146 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
147 | this, SLOT( qcopReceive(const QCString&, const QByteArray&)) ); | 147 | this, SLOT( qcopReceive(const QCString&, const QByteArray&)) ); |
148 | 148 | ||
149 | setBackgroundMode( PaletteButton ); | 149 | setBackgroundMode( PaletteButton ); |
150 | 150 | ||
151 | setCaption( tr("OpiePlayer") ); | 151 | setCaption( tr("OpiePlayer") ); |
152 | setIcon( Resource::loadPixmap( "opieplayer/MPEGPlayer" ) ); | 152 | setIcon( Resource::loadPixmap( "opieplayer/MPEGPlayer" ) ); |
153 | 153 | ||
154 | setToolBarsMovable( FALSE ); | 154 | setToolBarsMovable( FALSE ); |
155 | 155 | ||
156 | // Create Toolbar | 156 | // Create Toolbar |
157 | QPEToolBar *toolbar = new QPEToolBar( this ); | 157 | QPEToolBar *toolbar = new QPEToolBar( this ); |
158 | toolbar->setHorizontalStretchable( TRUE ); | 158 | toolbar->setHorizontalStretchable( TRUE ); |
159 | 159 | ||
160 | // Create Menubar | 160 | // Create Menubar |
161 | QPEMenuBar *menu = new QPEMenuBar( toolbar ); | 161 | QPEMenuBar *menu = new QPEMenuBar( toolbar ); |
162 | menu->setMargin( 0 ); | 162 | menu->setMargin( 0 ); |
163 | 163 | ||
164 | QPEToolBar *bar = new QPEToolBar( this ); | 164 | QPEToolBar *bar = new QPEToolBar( this ); |
165 | bar->setLabel( tr( "Play Operations" ) ); | 165 | bar->setLabel( tr( "Play Operations" ) ); |
166 | // d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "opieplayer/play_current_list", | 166 | // d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "opieplayer/play_current_list", |
167 | // this , SLOT( addSelected()) ); | 167 | // this , SLOT( addSelected()) ); |
168 | tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); | 168 | tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); |
169 | tbDeletePlaylist->setFlat(TRUE); | 169 | tbDeletePlaylist->setFlat(TRUE); |
170 | 170 | ||
171 | tbDeletePlaylist->setFixedSize(20,20); | 171 | tbDeletePlaylist->setFixedSize(20,20); |
172 | 172 | ||
173 | d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "opieplayer/add_to_playlist", | 173 | d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "opieplayer/add_to_playlist", |
174 | this , SLOT(addSelected()) ); | 174 | this , SLOT(addSelected()) ); |
175 | d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "opieplayer/remove_from_playlist", | 175 | d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "opieplayer/remove_from_playlist", |
176 | this , SLOT(removeSelected()) ); | 176 | this , SLOT(removeSelected()) ); |
177 | // d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); | 177 | // d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); |
178 | d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", | 178 | d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", |
179 | this , SLOT( btnPlay(bool) ), TRUE ); | 179 | this , SLOT( btnPlay(bool) ), TRUE ); |
180 | d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle", | 180 | d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle", |
181 | mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); | 181 | mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); |
182 | d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop", | 182 | d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop", |
183 | mediaPlayerState, SLOT(setLooping(bool)), TRUE ); | 183 | mediaPlayerState, SLOT(setLooping(bool)), TRUE ); |
184 | tbDeletePlaylist->hide(); | 184 | tbDeletePlaylist->hide(); |
185 | 185 | ||
186 | QPopupMenu *pmPlayList = new QPopupMenu( this ); | 186 | QPopupMenu *pmPlayList = new QPopupMenu( this ); |
187 | menu->insertItem( tr( "File" ), pmPlayList ); | 187 | menu->insertItem( tr( "File" ), pmPlayList ); |
188 | new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); | 188 | new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); |
189 | new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); | 189 | new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); |
190 | new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); | 190 | new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); |
191 | new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); | 191 | new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); |
192 | pmPlayList->insertSeparator(-1); | 192 | pmPlayList->insertSeparator(-1); |
193 | new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); | 193 | new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); |
194 | new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); | 194 | new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); |
195 | pmPlayList->insertSeparator(-1); | 195 | pmPlayList->insertSeparator(-1); |
196 | new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) ); | 196 | new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) ); |
197 | new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) ); | 197 | new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) ); |
198 | 198 | ||
199 | QPopupMenu *pmView = new QPopupMenu( this ); | 199 | QPopupMenu *pmView = new QPopupMenu( this ); |
200 | menu->insertItem( tr( "View" ), pmView ); | 200 | menu->insertItem( tr( "View" ), pmView ); |
201 | 201 | ||
202 | fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); | 202 | fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); |
203 | fullScreenButton->addTo(pmView); | 203 | fullScreenButton->addTo(pmView); |
204 | scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0); | 204 | scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0); |
205 | scaleButton->addTo(pmView); | 205 | scaleButton->addTo(pmView); |
206 | 206 | ||
207 | 207 | ||
208 | skinsMenu = new QPopupMenu( this ); | 208 | skinsMenu = new QPopupMenu( this ); |
209 | menu->insertItem( tr( "Skins" ), skinsMenu ); | 209 | menu->insertItem( tr( "Skins" ), skinsMenu ); |
210 | skinsMenu->isCheckable(); | 210 | skinsMenu->isCheckable(); |
211 | connect( skinsMenu, SIGNAL( activated( int ) ) , | 211 | connect( skinsMenu, SIGNAL( activated( int ) ) , |
212 | this, SLOT( skinsMenuActivated( int ) ) ); | 212 | this, SLOT( skinsMenuActivated( int ) ) ); |
213 | populateSkinsMenu(); | 213 | populateSkinsMenu(); |
214 | 214 | ||
215 | QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); | 215 | QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); |
216 | QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); | 216 | QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); |
217 | 217 | ||
218 | QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); | 218 | QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); |
219 | 219 | ||
220 | tabWidget = new QTabWidget( hbox6, "tabWidget" ); | 220 | tabWidget = new QTabWidget( hbox6, "tabWidget" ); |
221 | // tabWidget->setTabShape(QTabWidget::Triangular); | 221 | // tabWidget->setTabShape(QTabWidget::Triangular); |
222 | 222 | ||
223 | QWidget *pTab; | 223 | QWidget *pTab; |
224 | pTab = new QWidget( tabWidget, "pTab" ); | 224 | pTab = new QWidget( tabWidget, "pTab" ); |
225 | // playlistView = new QListView( pTab, "playlistview" ); | 225 | // playlistView = new QListView( pTab, "playlistview" ); |
226 | // playlistView->setMinimumSize(236,260); | 226 | // playlistView->setMinimumSize(236,260); |
227 | tabWidget->insertTab( pTab,"Playlist"); | 227 | tabWidget->insertTab( pTab,"Playlist"); |
228 | 228 | ||
229 | 229 | ||
230 | // Add the playlist area | 230 | // Add the playlist area |
231 | 231 | ||
232 | QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); | 232 | QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); |
233 | d->playListFrame = vbox3; | 233 | d->playListFrame = vbox3; |
234 | 234 | ||
235 | QGridLayout *layoutF = new QGridLayout( pTab ); | 235 | QGridLayout *layoutF = new QGridLayout( pTab ); |
236 | layoutF->setSpacing( 2); | 236 | layoutF->setSpacing( 2); |
237 | layoutF->setMargin( 2); | 237 | layoutF->setMargin( 2); |
238 | layoutF->addMultiCellWidget( d->playListFrame , 0, 0, 0, 1 ); | 238 | layoutF->addMultiCellWidget( d->playListFrame , 0, 0, 0, 1 ); |
239 | 239 | ||
240 | QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); | 240 | QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); |
241 | 241 | ||
242 | d->selectedFiles = new PlayListSelection( hbox2); | 242 | d->selectedFiles = new PlayListSelection( hbox2); |
243 | QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); | 243 | QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); |
244 | 244 | ||
245 | QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); | 245 | QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); |
246 | 246 | ||
247 | 247 | ||
248 | 248 | ||
249 | QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch | 249 | QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch |
250 | new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); | 250 | new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); |
251 | new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); | 251 | new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); |
252 | new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); | 252 | new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); |
253 | QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch | 253 | QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch |
254 | 254 | ||
255 | QWidget *aTab; | 255 | QWidget *aTab; |
256 | aTab = new QWidget( tabWidget, "aTab" ); | 256 | aTab = new QWidget( tabWidget, "aTab" ); |
257 | audioView = new QListView( aTab, "Audioview" ); | 257 | audioView = new QListView( aTab, "Audioview" ); |
258 | 258 | ||
259 | QGridLayout *layoutA = new QGridLayout( aTab ); | 259 | QGridLayout *layoutA = new QGridLayout( aTab ); |
260 | layoutA->setSpacing( 2); | 260 | layoutA->setSpacing( 2); |
261 | layoutA->setMargin( 2); | 261 | layoutA->setMargin( 2); |
262 | layoutA->addMultiCellWidget( audioView, 0, 0, 0, 1 ); | 262 | layoutA->addMultiCellWidget( audioView, 0, 0, 0, 1 ); |
263 | 263 | ||
264 | audioView->addColumn( tr("Title"),-1); | 264 | audioView->addColumn( tr("Title"),-1); |
265 | audioView->addColumn(tr("Size"), -1); | 265 | audioView->addColumn(tr("Size"), -1); |
266 | audioView->addColumn(tr("Media"),-1); | 266 | audioView->addColumn(tr("Media"),-1); |
267 | audioView->addColumn( tr( "Path" ), -1 ); | 267 | audioView->addColumn( tr( "Path" ), -1 ); |
268 | 268 | ||
269 | audioView->setColumnAlignment(1, Qt::AlignRight); | 269 | audioView->setColumnAlignment(1, Qt::AlignRight); |
270 | audioView->setColumnAlignment(2, Qt::AlignRight); | 270 | audioView->setColumnAlignment(2, Qt::AlignRight); |
271 | audioView->setAllColumnsShowFocus(TRUE); | 271 | audioView->setAllColumnsShowFocus(TRUE); |
272 | 272 | ||
273 | audioView->setMultiSelection( TRUE ); | 273 | audioView->setMultiSelection( TRUE ); |
274 | audioView->setSelectionMode( QListView::Extended); | 274 | audioView->setSelectionMode( QListView::Extended); |
275 | audioView->setSorting( 3, TRUE ); | 275 | audioView->setSorting( 3, TRUE ); |
276 | 276 | ||
277 | tabWidget->insertTab(aTab,tr("Audio")); | 277 | tabWidget->insertTab(aTab,tr("Audio")); |
278 | 278 | ||
279 | QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); | 279 | QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); |
280 | 280 | ||
281 | // audioView | 281 | // audioView |
282 | // populateAudioView(); | 282 | // populateAudioView(); |
283 | // videowidget | 283 | // videowidget |
284 | 284 | ||
285 | QWidget *vTab; | 285 | QWidget *vTab; |
286 | vTab = new QWidget( tabWidget, "vTab" ); | 286 | vTab = new QWidget( tabWidget, "vTab" ); |
287 | videoView = new QListView( vTab, "Videoview" ); | 287 | videoView = new QListView( vTab, "Videoview" ); |
288 | 288 | ||
289 | QGridLayout *layoutV = new QGridLayout( vTab ); | 289 | QGridLayout *layoutV = new QGridLayout( vTab ); |
290 | layoutV->setSpacing( 2); | 290 | layoutV->setSpacing( 2); |
291 | layoutV->setMargin( 2); | 291 | layoutV->setMargin( 2); |
292 | layoutV->addMultiCellWidget( videoView, 0, 0, 0, 1 ); | 292 | layoutV->addMultiCellWidget( videoView, 0, 0, 0, 1 ); |
293 | 293 | ||
294 | videoView->addColumn(tr("Title"),-1); | 294 | videoView->addColumn(tr("Title"),-1); |
295 | videoView->addColumn(tr("Size"),-1); | 295 | videoView->addColumn(tr("Size"),-1); |
296 | videoView->addColumn(tr("Media"),-1); | 296 | videoView->addColumn(tr("Media"),-1); |
297 | videoView->addColumn(tr( "Path" ), -1 ); | 297 | videoView->addColumn(tr( "Path" ), -1 ); |
298 | videoView->setColumnAlignment(1, Qt::AlignRight); | 298 | videoView->setColumnAlignment(1, Qt::AlignRight); |
299 | videoView->setColumnAlignment(2, Qt::AlignRight); | 299 | videoView->setColumnAlignment(2, Qt::AlignRight); |
300 | videoView->setAllColumnsShowFocus(TRUE); | 300 | videoView->setAllColumnsShowFocus(TRUE); |
301 | videoView->setMultiSelection( TRUE ); | 301 | videoView->setMultiSelection( TRUE ); |
302 | videoView->setSelectionMode( QListView::Extended); | 302 | videoView->setSelectionMode( QListView::Extended); |
303 | 303 | ||
304 | QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); | 304 | QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); |
305 | 305 | ||
306 | tabWidget->insertTab( vTab,tr("Video")); | 306 | tabWidget->insertTab( vTab,tr("Video")); |
307 | 307 | ||
308 | QWidget *LTab; | 308 | QWidget *LTab; |
309 | LTab = new QWidget( tabWidget, "LTab" ); | 309 | LTab = new QWidget( tabWidget, "LTab" ); |
310 | playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy | 310 | playLists = new FileSelector( "playlist/plain;audio/x-mpegurl", LTab, "fileselector" , FALSE, FALSE); |
311 | 311 | ||
312 | QGridLayout *layoutL = new QGridLayout( LTab ); | 312 | QGridLayout *layoutL = new QGridLayout( LTab ); |
313 | layoutL->setSpacing( 2); | 313 | layoutL->setSpacing( 2); |
314 | layoutL->setMargin( 2); | 314 | layoutL->setMargin( 2); |
315 | layoutL->addMultiCellWidget( playLists, 0, 0, 0, 1 ); | 315 | layoutL->addMultiCellWidget( playLists, 0, 0, 0, 1 ); |
316 | // playLists->setMinimumSize(233,260); | ||
317 | 316 | ||
318 | tabWidget->insertTab(LTab,tr("Lists")); | 317 | tabWidget->insertTab(LTab,tr("Lists")); |
319 | 318 | ||
320 | connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); | 319 | connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); |
321 | connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); | 320 | connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); |
322 | connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); | 321 | connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); |
323 | 322 | ||
324 | connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 323 | connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
325 | this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); | 324 | this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); |
326 | 325 | ||
327 | 326 | ||
328 | ///audioView | 327 | ///audioView |
329 | connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 328 | connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
330 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | 329 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); |
331 | 330 | ||
332 | connect( audioView, SIGNAL( returnPressed( QListViewItem *)), | 331 | connect( audioView, SIGNAL( returnPressed( QListViewItem *)), |
333 | this,SLOT( playIt( QListViewItem *)) ); | 332 | this,SLOT( playIt( QListViewItem *)) ); |
334 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | 333 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); |
335 | 334 | ||
336 | 335 | ||
337 | //videoView | 336 | //videoView |
338 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 337 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
339 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | 338 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); |
340 | connect( videoView, SIGNAL( returnPressed( QListViewItem *)), | 339 | connect( videoView, SIGNAL( returnPressed( QListViewItem *)), |
341 | this,SLOT( playIt( QListViewItem *)) ); | 340 | this,SLOT( playIt( QListViewItem *)) ); |
342 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | 341 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); |
343 | 342 | ||
344 | //playlists | 343 | //playlists |
345 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); | 344 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); |
346 | 345 | ||
347 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); | 346 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); |
348 | 347 | ||
349 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); | 348 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); |
350 | 349 | ||
351 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); | 350 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); |
352 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); | 351 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); |
353 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); | 352 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); |
354 | 353 | ||
355 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); | 354 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); |
356 | 355 | ||
357 | setCentralWidget( vbox5 ); | 356 | setCentralWidget( vbox5 ); |
358 | 357 | ||
359 | Config cfg( "OpiePlayer" ); | 358 | Config cfg( "OpiePlayer" ); |
360 | readConfig( cfg ); | 359 | readConfig( cfg ); |
361 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default"); | 360 | |
362 | loadList(DocLnk( currentPlaylist)); | 361 | currentPlayList = cfg.readEntry("CurrentPlaylist","default"); |
363 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(currentPlaylist))); | 362 | loadList(DocLnk( currentPlayList)); |
363 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(currentPlayList))); | ||
364 | 364 | ||
365 | initializeStates(); | 365 | initializeStates(); |
366 | // audioUI->setFocus(); | ||
367 | } | 366 | } |
368 | 367 | ||
369 | 368 | ||
370 | PlayListWidget::~PlayListWidget() { | 369 | PlayListWidget::~PlayListWidget() { |
371 | Config cfg( "OpiePlayer" ); | 370 | Config cfg( "OpiePlayer" ); |
372 | writeConfig( cfg ); | 371 | writeConfig( cfg ); |
373 | 372 | ||
374 | if ( d->current ) | 373 | if ( d->current ) |
375 | delete d->current; | 374 | delete d->current; |
376 | if(d) delete d; | 375 | if(d) delete d; |
377 | } | 376 | } |
378 | 377 | ||
379 | 378 | ||
380 | void PlayListWidget::initializeStates() { | 379 | void PlayListWidget::initializeStates() { |
381 | 380 | ||
382 | d->tbPlay->setOn( mediaPlayerState->playing() ); | 381 | d->tbPlay->setOn( mediaPlayerState->playing() ); |
383 | d->tbLoop->setOn( mediaPlayerState->looping() ); | 382 | d->tbLoop->setOn( mediaPlayerState->looping() ); |
384 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); | 383 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); |
385 | setPlaylist( true); | 384 | setPlaylist( true); |
386 | } | 385 | } |
387 | 386 | ||
388 | 387 | ||
389 | void PlayListWidget::readConfig( Config& cfg ) { | 388 | void PlayListWidget::readConfig( Config& cfg ) { |
390 | cfg.setGroup("PlayList"); | 389 | cfg.setGroup("PlayList"); |
391 | QString currentString = cfg.readEntry("current", "" ); | 390 | QString currentString = cfg.readEntry("current", "" ); |
392 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 391 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
393 | for ( int i = 0; i < noOfFiles; i++ ) { | 392 | for ( int i = 0; i < noOfFiles; i++ ) { |
394 | QString entryName; | 393 | QString entryName; |
395 | entryName.sprintf( "File%i", i + 1 ); | 394 | entryName.sprintf( "File%i", i + 1 ); |
396 | QString linkFile = cfg.readEntry( entryName ); | 395 | QString linkFile = cfg.readEntry( entryName ); |
397 | DocLnk lnk( linkFile ); | 396 | DocLnk lnk( linkFile ); |
398 | if ( lnk.isValid() ) { | 397 | if ( lnk.isValid() ) { |
399 | d->selectedFiles->addToSelection( lnk ); | 398 | d->selectedFiles->addToSelection( lnk ); |
400 | } | 399 | } |
401 | } | 400 | } |
402 | d->selectedFiles->setSelectedItem( currentString); | 401 | d->selectedFiles->setSelectedItem( currentString); |
403 | } | 402 | } |
404 | 403 | ||
405 | 404 | ||
406 | void PlayListWidget::writeConfig( Config& cfg ) const { | 405 | void PlayListWidget::writeConfig( Config& cfg ) const { |
407 | 406 | ||
408 | d->selectedFiles->writeCurrent( cfg); | 407 | d->selectedFiles->writeCurrent( cfg); |
409 | cfg.setGroup("PlayList"); | 408 | cfg.setGroup("PlayList"); |
410 | int noOfFiles = 0; | 409 | int noOfFiles = 0; |
411 | d->selectedFiles->first(); | 410 | d->selectedFiles->first(); |
412 | do { | 411 | do { |
413 | const DocLnk *lnk = d->selectedFiles->current(); | 412 | const DocLnk *lnk = d->selectedFiles->current(); |
414 | if ( lnk ) { | 413 | if ( lnk ) { |
415 | QString entryName; | 414 | QString entryName; |
416 | entryName.sprintf( "File%i", noOfFiles + 1 ); | 415 | entryName.sprintf( "File%i", noOfFiles + 1 ); |
417 | // qDebug(entryName); | 416 | // qDebug(entryName); |
418 | cfg.writeEntry( entryName, lnk->linkFile() ); | 417 | cfg.writeEntry( entryName, lnk->linkFile() ); |
419 | // if this link does exist, add it so we have the file | 418 | // if this link does exist, add it so we have the file |
420 | // next time... | 419 | // next time... |
421 | if ( !QFile::exists( lnk->linkFile() ) ) { | 420 | if ( !QFile::exists( lnk->linkFile() ) ) { |
422 | // the way writing lnks doesn't really check for out | 421 | // the way writing lnks doesn't really check for out |
423 | // of disk space, but check it anyway. | 422 | // of disk space, but check it anyway. |
424 | if ( !lnk->writeLink() ) { | 423 | // if ( !lnk->writeLink() ) { |
425 | QMessageBox::critical( 0, tr("Out of space"), | 424 | // QMessageBox::critical( 0, tr("Out of space"), |
426 | tr( "There was a problem saving " | 425 | // tr( "There was a problem saving " |
427 | "the playlist.\n" | 426 | // "the playlist.\n" |
428 | "Your playlist " | 427 | // "Your playlist " |
429 | "may be missing some entries\n" | 428 | // "may be missing some entries\n" |
430 | "the next time you start it." ) | 429 | // "the next time you start it." ) |
431 | ); | 430 | // ); |
432 | } | 431 | // } |
432 | |||
433 | } | 433 | } |
434 | noOfFiles++; | 434 | noOfFiles++; |
435 | } | 435 | } |
436 | } | 436 | } |
437 | while ( d->selectedFiles->next() ); | 437 | while ( d->selectedFiles->next() ); |
438 | cfg.writeEntry("NumberOfFiles", noOfFiles ); | 438 | cfg.writeEntry("NumberOfFiles", noOfFiles ); |
439 | } | 439 | } |
440 | 440 | ||
441 | 441 | ||
442 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { | 442 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { |
443 | d->setDocumentUsed = false; | 443 | d->setDocumentUsed = false; |
444 | if ( mediaPlayerState->playlist() ) { | 444 | if ( mediaPlayerState->playlist() ) { |
445 | if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" ) | 445 | if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" ) |
446 | d->selectedFiles->addToSelection( lnk ); | 446 | d->selectedFiles->addToSelection( lnk ); |
447 | } | 447 | } |
448 | else | 448 | else |
449 | mediaPlayerState->setPlaying( true); | 449 | mediaPlayerState->setPlaying( true); |
450 | |||
450 | } | 451 | } |
451 | 452 | ||
452 | 453 | ||
453 | void PlayListWidget::clearList() { | 454 | void PlayListWidget::clearList() { |
454 | while ( first() ) | 455 | while ( first() ) |
455 | d->selectedFiles->removeSelected(); | 456 | d->selectedFiles->removeSelected(); |
457 | Config cfg( "OpiePlayer" ); | ||
458 | cfg.setGroup("PlayList"); | ||
459 | cfg.writeEntry("CurrentPlaylist",""); | ||
460 | currentPlayList=""; | ||
461 | |||
456 | } | 462 | } |
457 | 463 | ||
458 | 464 | ||
459 | void PlayListWidget::addAllToList() { | 465 | void PlayListWidget::addAllToList() { |
460 | DocLnkSet filesAll; | 466 | DocLnkSet filesAll; |
461 | Global::findDocuments(&filesAll, "video/*;audio/*"); | 467 | Global::findDocuments(&filesAll, "video/*;audio/*"); |
462 | QListIterator<DocLnk> Adit( filesAll.children() ); | 468 | QListIterator<DocLnk> Adit( filesAll.children() ); |
463 | for ( ; Adit.current(); ++Adit ) | 469 | for ( ; Adit.current(); ++Adit ) |
464 | if(QFileInfo(Adit.current()->file()).exists()) | 470 | if(QFileInfo(Adit.current()->file()).exists()) |
465 | d->selectedFiles->addToSelection( **Adit ); | 471 | d->selectedFiles->addToSelection( **Adit ); |
466 | tabWidget->setCurrentPage(0); | 472 | tabWidget->setCurrentPage(0); |
467 | 473 | ||
468 | writeCurrentM3u(); | 474 | writeCurrentM3u(); |
469 | d->selectedFiles->first(); | 475 | d->selectedFiles->first(); |
470 | } | 476 | } |
471 | 477 | ||
472 | 478 | ||
473 | void PlayListWidget::addAllMusicToList() { | 479 | void PlayListWidget::addAllMusicToList() { |
474 | QListIterator<DocLnk> dit( files.children() ); | 480 | QListIterator<DocLnk> dit( files.children() ); |
475 | for ( ; dit.current(); ++dit ) | 481 | for ( ; dit.current(); ++dit ) |
476 | if(QFileInfo(dit.current()->file()).exists()) | 482 | if(QFileInfo(dit.current()->file()).exists()) |
477 | d->selectedFiles->addToSelection( **dit ); | 483 | d->selectedFiles->addToSelection( **dit ); |
478 | tabWidget->setCurrentPage(0); | 484 | tabWidget->setCurrentPage(0); |
479 | 485 | ||
480 | writeCurrentM3u(); | 486 | writeCurrentM3u(); |
481 | d->selectedFiles->first(); | 487 | d->selectedFiles->first(); |
482 | } | 488 | } |
483 | 489 | ||
484 | 490 | ||
485 | void PlayListWidget::addAllVideoToList() { | 491 | void PlayListWidget::addAllVideoToList() { |
486 | QListIterator<DocLnk> dit( vFiles.children() ); | 492 | QListIterator<DocLnk> dit( vFiles.children() ); |
487 | for ( ; dit.current(); ++dit ) | 493 | for ( ; dit.current(); ++dit ) |
488 | if(QFileInfo( dit.current()->file()).exists()) | 494 | if(QFileInfo( dit.current()->file()).exists()) |
489 | d->selectedFiles->addToSelection( **dit ); | 495 | d->selectedFiles->addToSelection( **dit ); |
490 | tabWidget->setCurrentPage(0); | 496 | tabWidget->setCurrentPage(0); |
491 | 497 | ||
492 | writeCurrentM3u(); | 498 | writeCurrentM3u(); |
493 | d->selectedFiles->first(); | 499 | d->selectedFiles->first(); |
494 | } | 500 | } |
495 | 501 | ||
496 | 502 | ||
497 | void PlayListWidget::setDocument(const QString& fileref) { | 503 | void PlayListWidget::setDocument(const QString& fileref) { |
498 | fromSetDocument = true; | 504 | fromSetDocument = true; |
499 | d->setDocumentUsed = TRUE; | 505 | d->setDocumentUsed = TRUE; |
500 | d->selectedFiles->setSelected(d->selectedFiles->firstChild(),true ); | 506 | setDocumentEx(fileref); |
501 | mediaPlayerState->setPlaying( FALSE ); | ||
502 | qApp->processEvents(); | ||
503 | mediaPlayerState->setPlaying( TRUE ); | ||
504 | } | 507 | } |
505 | 508 | ||
506 | void PlayListWidget::setDocumentEx(const QString& fileref) { | 509 | void PlayListWidget::setDocumentEx(const QString& fileref) { |
507 | 510 | qDebug("opieplayer receive "+fileref); | |
508 | QFileInfo fileInfo(fileref); | 511 | clearList(); |
509 | if ( !fileInfo.exists() ) { | 512 | DocLnk lnk; |
510 | QMessageBox::critical( 0, tr( "Invalid File" ), | 513 | QFileInfo fileInfo(fileref); |
511 | tr( "There was a problem in getting the file." ) ); | 514 | if ( !fileInfo.exists() ) { |
512 | return; | 515 | QMessageBox::critical( 0, tr( "Invalid File" ), |
513 | } | 516 | tr( "There was a problem in getting the file." ) ); |
514 | qDebug("setDocument "+fileref); | 517 | return; |
515 | QString extension = fileInfo.extension(false); | 518 | } |
516 | if( extension.find( "m3u", 0, false) != -1) { //is m3u | 519 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<setDocument "+fileref); |
520 | QString extension = fileInfo.extension(false); | ||
521 | if( extension.find( "m3u", 0, false) != -1) { //is m3u | ||
517 | readm3u( fileref); | 522 | readm3u( fileref); |
518 | } | 523 | } |
519 | else if( extension.find( "pls", 0, false) != -1 ) { //is pls | 524 | else if( extension.find( "pls", 0, false) != -1 ) { //is pls |
520 | readPls( fileref); | 525 | readPls( fileref); |
521 | } | 526 | } |
522 | else if( fileref.find("playlist",0,TRUE) != -1) {//is playlist | 527 | else if( fileref.find("playlist",0,TRUE) != -1) {//is playlist |
523 | clearList(); | 528 | clearList(); |
524 | DocLnk lnk; | 529 | lnk.setName( fileInfo.baseName() ); //sets name |
525 | lnk.setName( fileInfo.baseName() ); //sets name | 530 | lnk.setFile( fileref ); //sets file name |
526 | lnk.setFile( fileref ); //sets file name | 531 | lnk.setIcon("Sound"); |
527 | //addToSelection( lnk ); | 532 | //addToSelection( lnk ); |
528 | 533 | ||
529 | loadList( lnk); | 534 | loadList( lnk); |
530 | d->selectedFiles->first(); | 535 | d->selectedFiles->first(); |
531 | } else { | 536 | } else { |
532 | clearList(); | 537 | if( fileref.find(".desktop",0,TRUE) != -1) { |
533 | DocLnk lnk; | 538 | lnk = DocLnk(fileref); |
534 | lnk.setName( fileInfo.baseName() ); //sets name | 539 | } else { |
535 | lnk.setFile( fileref ); //sets file name | 540 | lnk.setName( fileInfo.baseName() ); //sets name |
536 | addToSelection( lnk ); | 541 | lnk.setFile( fileref ); //sets file name |
537 | // addToSelection( DocLnk( fileref ) ); | 542 | lnk.setIcon("Sound"); |
538 | d->setDocumentUsed = TRUE; | 543 | } |
539 | mediaPlayerState->setPlaying( FALSE ); | 544 | |
540 | qApp->processEvents(); | 545 | addToSelection( lnk ); |
541 | mediaPlayerState->setPlaying( TRUE ); | 546 | // addToSelection( DocLnk( fileref ) ); |
542 | // qApp->processEvents(); | 547 | lnk.removeLinkFile(); |
543 | setCaption(tr("OpiePlayer")); | 548 | // qApp->processEvents(); |
544 | } | 549 | } |
550 | setCaption(tr("OpiePlayer")); | ||
551 | d->setDocumentUsed = TRUE; | ||
552 | d->selectedFiles->setSelected(d->selectedFiles->firstChild(),true ); | ||
553 | mediaPlayerState->setPlaying( FALSE ); | ||
554 | qApp->processEvents(); | ||
555 | mediaPlayerState->setPlaying( TRUE ); | ||
556 | |||
545 | } | 557 | } |
546 | 558 | ||
547 | 559 | ||
548 | void PlayListWidget::setActiveWindow() { | 560 | void PlayListWidget::setActiveWindow() { |
549 | qDebug("SETTING active window"); | 561 | // qDebug("SETTING active window"); |
550 | |||
551 | // When we get raised we need to ensure that it switches views | 562 | // When we get raised we need to ensure that it switches views |
552 | char origView = mediaPlayerState->view(); | 563 | char origView = mediaPlayerState->view(); |
553 | mediaPlayerState->setView( 'l' ); // invalidate | 564 | mediaPlayerState->setView( 'l' ); // invalidate |
554 | mediaPlayerState->setView( origView ); // now switch back | 565 | mediaPlayerState->setView( origView ); // now switch back |
555 | } | 566 | } |
556 | 567 | ||
557 | 568 | ||
558 | void PlayListWidget::useSelectedDocument() { | 569 | void PlayListWidget::useSelectedDocument() { |
559 | d->setDocumentUsed = FALSE; | 570 | d->setDocumentUsed = FALSE; |
560 | } | 571 | } |
561 | 572 | ||
562 | 573 | ||
563 | const DocLnk *PlayListWidget::current() { // this is fugly | 574 | const DocLnk *PlayListWidget::current() { // this is fugly |
564 | 575 | switch (tabWidget->currentPageIndex()) { | |
565 | // if( fromSetDocument) { | 576 | case 0: //playlist |
566 | // qDebug("from setDoc"); | 577 | { |
567 | // DocLnkSet files; | 578 | // qDebug("playlist"); |
568 | // Global::findDocuments(&files, "video/*;audio/*"); | 579 | if ( mediaPlayerState->playlist() ) { |
569 | // QListIterator<DocLnk> dit( files.children() ); | 580 | return d->selectedFiles->current(); |
570 | // for ( ; dit.current(); ++dit ) { | ||
571 | // if(dit.current()->linkFile() == setDocFileRef) { | ||
572 | // qDebug(setDocFileRef); | ||
573 | // return dit; | ||
574 | // } | ||
575 | // } | ||
576 | // } else | ||
577 | |||
578 | qDebug("current"); | ||
579 | |||
580 | switch (tabWidget->currentPageIndex()) { | ||
581 | case 0: //playlist | ||
582 | { | ||
583 | qDebug("playlist"); | ||
584 | if ( mediaPlayerState->playlist() ) { | ||
585 | return d->selectedFiles->current(); | ||
586 | } | ||
587 | else if ( d->setDocumentUsed && d->current ) { | ||
588 | return d->current; | ||
589 | } else { | ||
590 | return &(d->files->selectedDocument()); | ||
591 | } | ||
592 | } | 581 | } |
593 | break; | 582 | else if ( d->setDocumentUsed && d->current ) { |
594 | case 1://audio | 583 | return d->current; |
595 | { | 584 | } else { |
596 | qDebug("audioView"); | 585 | return &(d->files->selectedDocument()); |
597 | QListIterator<DocLnk> dit( files.children() ); | ||
598 | for ( ; dit.current(); ++dit ) { | ||
599 | if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { | ||
600 | qDebug("here"); | ||
601 | insanityBool=TRUE; | ||
602 | return dit; | ||
603 | } | ||
604 | } | ||
605 | } | ||
606 | break; | ||
607 | case 2: // video | ||
608 | { | ||
609 | qDebug("videoView"); | ||
610 | QListIterator<DocLnk> Vdit( vFiles.children() ); | ||
611 | for ( ; Vdit.current(); ++Vdit ) { | ||
612 | if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { | ||
613 | insanityBool=TRUE; | ||
614 | return Vdit; | ||
615 | } | ||
616 | } | ||
617 | } | 586 | } |
618 | break; | 587 | } |
619 | }; | 588 | break; |
620 | return 0; | 589 | case 1://audio |
590 | { | ||
591 | // qDebug("audioView"); | ||
592 | QListIterator<DocLnk> dit( files.children() ); | ||
593 | for ( ; dit.current(); ++dit ) { | ||
594 | if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { | ||
595 | insanityBool=TRUE; | ||
596 | return dit; | ||
597 | } | ||
598 | } | ||
599 | } | ||
600 | break; | ||
601 | case 2: // video | ||
602 | { | ||
603 | QListIterator<DocLnk> Vdit( vFiles.children() ); | ||
604 | for ( ; Vdit.current(); ++Vdit ) { | ||
605 | if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { | ||
606 | insanityBool=TRUE; | ||
607 | return Vdit; | ||
608 | } | ||
609 | } | ||
610 | } | ||
611 | break; | ||
612 | }; | ||
613 | return 0; | ||
621 | } | 614 | } |
622 | 615 | ||
623 | bool PlayListWidget::prev() { | 616 | bool PlayListWidget::prev() { |
624 | if ( mediaPlayerState->playlist() ) { | 617 | if ( mediaPlayerState->playlist() ) { |
625 | if ( mediaPlayerState->shuffled() ) { | 618 | if ( mediaPlayerState->shuffled() ) { |
626 | const DocLnk *cur = current(); | 619 | const DocLnk *cur = current(); |
627 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); | 620 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); |
628 | for ( int i = 0; i < j; i++ ) { | 621 | for ( int i = 0; i < j; i++ ) { |
629 | if ( !d->selectedFiles->next() ) | 622 | if ( !d->selectedFiles->next() ) |
630 | d->selectedFiles->first(); | 623 | d->selectedFiles->first(); |
624 | } | ||
625 | if ( cur == current() ) | ||
626 | if ( !d->selectedFiles->next() ) | ||
627 | d->selectedFiles->first(); | ||
628 | return TRUE; | ||
629 | } else { | ||
630 | if ( !d->selectedFiles->prev() ) { | ||
631 | if ( mediaPlayerState->looping() ) { | ||
632 | return d->selectedFiles->last(); | ||
633 | } else { | ||
634 | return FALSE; | ||
631 | } | 635 | } |
632 | if ( cur == current() ) | 636 | } |
633 | if ( !d->selectedFiles->next() ) | 637 | return TRUE; |
634 | d->selectedFiles->first(); | 638 | } |
635 | return TRUE; | 639 | } else { |
636 | } else { | 640 | return mediaPlayerState->looping(); |
637 | if ( !d->selectedFiles->prev() ) { | 641 | } |
638 | if ( mediaPlayerState->looping() ) { | ||
639 | return d->selectedFiles->last(); | ||
640 | } else { | ||
641 | return FALSE; | ||
642 | } | ||
643 | } | ||
644 | return TRUE; | ||
645 | } | ||
646 | } else { | ||
647 | return mediaPlayerState->looping(); | ||
648 | } | ||
649 | } | 642 | } |
650 | 643 | ||
651 | 644 | ||
652 | bool PlayListWidget::next() { | 645 | bool PlayListWidget::next() { |
653 | if ( mediaPlayerState->playlist() ) { | 646 | if ( mediaPlayerState->playlist() ) { |
654 | if ( mediaPlayerState->shuffled() ) { | 647 | if ( mediaPlayerState->shuffled() ) { |
655 | return prev(); | 648 | return prev(); |
656 | } else { | 649 | } else { |
657 | if ( !d->selectedFiles->next() ) { | 650 | if ( !d->selectedFiles->next() ) { |
658 | if ( mediaPlayerState->looping() ) { | 651 | if ( mediaPlayerState->looping() ) { |
659 | return d->selectedFiles->first(); | 652 | return d->selectedFiles->first(); |
660 | } else { | 653 | } else { |
661 | return FALSE; | 654 | return FALSE; |
662 | } | ||
663 | } | 655 | } |
664 | return TRUE; | 656 | } |
665 | } | 657 | return TRUE; |
666 | } else { | 658 | } |
667 | return mediaPlayerState->looping(); | 659 | } else { |
668 | } | 660 | return mediaPlayerState->looping(); |
661 | } | ||
669 | } | 662 | } |
670 | 663 | ||
671 | 664 | ||
672 | bool PlayListWidget::first() { | 665 | bool PlayListWidget::first() { |
673 | if ( mediaPlayerState->playlist() ) | 666 | if ( mediaPlayerState->playlist() ) |
674 | return d->selectedFiles->first(); | 667 | return d->selectedFiles->first(); |
675 | else | 668 | else |
676 | return mediaPlayerState->looping(); | 669 | return mediaPlayerState->looping(); |
677 | } | 670 | } |
678 | 671 | ||
679 | 672 | ||
680 | bool PlayListWidget::last() { | 673 | bool PlayListWidget::last() { |
681 | if ( mediaPlayerState->playlist() ) | 674 | if ( mediaPlayerState->playlist() ) |
682 | return d->selectedFiles->last(); | 675 | return d->selectedFiles->last(); |
683 | else | 676 | else |
684 | return mediaPlayerState->looping(); | 677 | return mediaPlayerState->looping(); |
685 | } | 678 | } |
686 | 679 | ||
687 | 680 | ||
688 | void PlayListWidget::saveList() { | 681 | void PlayListWidget::saveList() { |
689 | writem3u(); | 682 | writem3u(); |
690 | } | 683 | } |
691 | 684 | ||
692 | void PlayListWidget::loadList( const DocLnk & lnk) { | 685 | void PlayListWidget::loadList( const DocLnk & lnk) { |
693 | QString name = lnk.name(); | 686 | QString name = lnk.name(); |
694 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); | 687 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); |
695 | 688 | ||
696 | if( name.length()>0) { | 689 | if( name.length()>0) { |
697 | setCaption("OpiePlayer: "+name); | 690 | setCaption("OpiePlayer: "+name); |
698 | // qDebug("<<<<<<<<<<<<load list "+ lnk.file()); | 691 | // qDebug("<<<<<<<<<<<<load list "+ lnk.file()); |
699 | clearList(); | 692 | clearList(); |
700 | readm3u(lnk.file()); | 693 | readm3u(lnk.file()); |
701 | tabWidget->setCurrentPage(0); | 694 | tabWidget->setCurrentPage(0); |
702 | } | 695 | } |
703 | } | 696 | } |
704 | 697 | ||
705 | void PlayListWidget::setPlaylist( bool shown ) { | 698 | void PlayListWidget::setPlaylist( bool shown ) { |
706 | if ( shown ) | 699 | if ( shown ) |
707 | d->playListFrame->show(); | 700 | d->playListFrame->show(); |
708 | else | 701 | else |
709 | d->playListFrame->hide(); | 702 | d->playListFrame->hide(); |
710 | } | 703 | } |
711 | 704 | ||
712 | void PlayListWidget::setView( char view ) { | 705 | void PlayListWidget::setView( char view ) { |
713 | if ( view == 'l' ) | 706 | if ( view == 'l' ) |
714 | showMaximized(); | 707 | showMaximized(); |
715 | else | 708 | else |
716 | hide(); | 709 | hide(); |
717 | } | 710 | } |
718 | 711 | ||
719 | void PlayListWidget::addSelected() { | 712 | void PlayListWidget::addSelected() { |
720 | qDebug("addSelected"); | 713 | DocLnk lnk; |
721 | DocLnk lnk; | 714 | QString filename; |
722 | QString filename; | 715 | switch (tabWidget->currentPageIndex()) { |
723 | switch (tabWidget->currentPageIndex()) { | 716 | |
724 | 717 | case 0: //playlist | |
725 | case 0: //playlist | 718 | return; |
726 | return; | 719 | break; |
727 | break; | 720 | case 1: { //audio |
728 | case 1: { //audio | ||
729 | QListViewItemIterator it( audioView ); | 721 | QListViewItemIterator it( audioView ); |
730 | for ( ; it.current(); ++it ) { | 722 | for ( ; it.current(); ++it ) { |
731 | if ( it.current()->isSelected() ) { | 723 | if ( it.current()->isSelected() ) { |
732 | filename = it.current()->text(3); | 724 | filename = it.current()->text(3); |
733 | lnk.setName( QFileInfo(filename).baseName() ); //sets name | 725 | lnk.setName( QFileInfo(filename).baseName() ); //sets name |
734 | lnk.setFile( filename ); //sets file name | 726 | lnk.setFile( filename ); //sets file name |
735 | d->selectedFiles->addToSelection( lnk); | 727 | d->selectedFiles->addToSelection( lnk); |
736 | } | 728 | } |
737 | } | 729 | } |
738 | audioView->clearSelection(); | 730 | audioView->clearSelection(); |
739 | // d->selectedFiles->next(); | 731 | // d->selectedFiles->next(); |
740 | } | 732 | } |
741 | break; | 733 | break; |
742 | 734 | ||
743 | case 2: { // video | 735 | case 2: { // video |
744 | QListViewItemIterator it( videoView ); | 736 | QListViewItemIterator it( videoView ); |
745 | for ( ; it.current(); ++it ) { | 737 | for ( ; it.current(); ++it ) { |
746 | if ( it.current()->isSelected() ) { | 738 | if ( it.current()->isSelected() ) { |
747 | 739 | ||
748 | filename = it.current()->text(3); | 740 | filename = it.current()->text(3); |
749 | lnk.setName( QFileInfo(filename).baseName() ); //sets name | 741 | lnk.setName( QFileInfo(filename).baseName() ); //sets name |
750 | lnk.setFile( filename ); //sets file name | 742 | lnk.setFile( filename ); //sets file name |
751 | d->selectedFiles->addToSelection( lnk); | 743 | d->selectedFiles->addToSelection( lnk); |
752 | } | 744 | } |
753 | } | 745 | } |
754 | videoView->clearSelection(); | 746 | videoView->clearSelection(); |
755 | } | 747 | } |
756 | break; | 748 | break; |
757 | }; | 749 | }; |
758 | // tabWidget->setCurrentPage(0); | 750 | // tabWidget->setCurrentPage(0); |
759 | writeCurrentM3u(); | 751 | writeCurrentM3u(); |
760 | 752 | ||
761 | } | 753 | } |
762 | 754 | ||
763 | void PlayListWidget::removeSelected() { | 755 | void PlayListWidget::removeSelected() { |
764 | d->selectedFiles->removeSelected( ); | 756 | d->selectedFiles->removeSelected( ); |
765 | } | 757 | } |
766 | 758 | ||
767 | void PlayListWidget::playIt( QListViewItem *) { | 759 | void PlayListWidget::playIt( QListViewItem *) { |
768 | // d->setDocumentUsed = FALSE; | 760 | // d->setDocumentUsed = FALSE; |
769 | // mediaPlayerState->curPosition =0; | 761 | // mediaPlayerState->curPosition =0; |
770 | qDebug("playIt"); | 762 | // mediaPlayerState->setPlaying(FALSE); |
771 | // mediaPlayerState->setPlaying(FALSE); | 763 | mediaPlayerState->setPlaying(TRUE); |
772 | mediaPlayerState->setPlaying(TRUE); | 764 | d->selectedFiles->unSelect(); |
773 | d->selectedFiles->unSelect(); | ||
774 | } | 765 | } |
775 | 766 | ||
776 | void PlayListWidget::addToSelection( QListViewItem *it) { | 767 | void PlayListWidget::addToSelection( QListViewItem *it) { |
777 | d->setDocumentUsed = FALSE; | 768 | d->setDocumentUsed = FALSE; |
778 | 769 | ||
779 | if(it) { | 770 | if(it) { |
780 | switch ( tabWidget->currentPageIndex()) { | 771 | switch ( tabWidget->currentPageIndex()) { |
781 | case 0: //playlist | 772 | case 0: //playlist |
782 | return; | 773 | return; |
783 | break; | 774 | break; |
784 | }; | 775 | }; |
785 | // case 1: { | 776 | // case 1: { |
786 | DocLnk lnk; | 777 | DocLnk lnk; |
787 | QString filename; | 778 | QString filename; |
788 | 779 | ||
789 | filename=it->text(3); | 780 | filename=it->text(3); |
790 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name | 781 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name |
791 | lnk.setFile( filename ); //sets file name | 782 | lnk.setFile( filename ); //sets file name |
792 | d->selectedFiles->addToSelection( lnk); | 783 | d->selectedFiles->addToSelection( lnk); |
793 | 784 | ||
794 | if(tabWidget->currentPageIndex() == 0) | 785 | if(tabWidget->currentPageIndex() == 0) |
795 | writeCurrentM3u(); | 786 | writeCurrentM3u(); |
796 | // tabWidget->setCurrentPage(0); | 787 | // tabWidget->setCurrentPage(0); |
797 | 788 | ||
798 | } | 789 | } |
799 | } | 790 | } |
800 | 791 | ||
801 | void PlayListWidget::tabChanged(QWidget *) { | 792 | void PlayListWidget::tabChanged(QWidget *) { |
802 | 793 | ||
803 | switch ( tabWidget->currentPageIndex()) { | 794 | switch ( tabWidget->currentPageIndex()) { |
804 | case 0: | 795 | case 0: |
805 | { | 796 | { |
806 | if( !tbDeletePlaylist->isHidden()) | 797 | if( !tbDeletePlaylist->isHidden()) |
807 | tbDeletePlaylist->hide(); | 798 | tbDeletePlaylist->hide(); |
808 | d->tbRemoveFromList->setEnabled(TRUE); | 799 | d->tbRemoveFromList->setEnabled(TRUE); |
809 | d->tbAddToList->setEnabled(FALSE); | 800 | d->tbAddToList->setEnabled(FALSE); |
810 | } | 801 | } |
811 | break; | 802 | break; |
812 | case 1: | 803 | case 1: |
813 | { | 804 | { |
814 | audioView->clear(); | 805 | audioView->clear(); |
815 | populateAudioView(); | 806 | populateAudioView(); |
816 | 807 | ||
817 | if( !tbDeletePlaylist->isHidden()) | 808 | if( !tbDeletePlaylist->isHidden()) |
818 | tbDeletePlaylist->hide(); | 809 | tbDeletePlaylist->hide(); |
819 | d->tbRemoveFromList->setEnabled(FALSE); | 810 | d->tbRemoveFromList->setEnabled(FALSE); |
820 | d->tbAddToList->setEnabled(TRUE); | 811 | d->tbAddToList->setEnabled(TRUE); |
821 | } | 812 | } |
822 | break; | 813 | break; |
823 | case 2: | 814 | case 2: |
824 | { | 815 | { |
825 | videoView->clear(); | 816 | videoView->clear(); |
826 | populateVideoView(); | 817 | populateVideoView(); |
827 | if( !tbDeletePlaylist->isHidden()) | 818 | if( !tbDeletePlaylist->isHidden()) |
828 | tbDeletePlaylist->hide(); | 819 | tbDeletePlaylist->hide(); |
829 | d->tbRemoveFromList->setEnabled(FALSE); | 820 | d->tbRemoveFromList->setEnabled(FALSE); |
830 | d->tbAddToList->setEnabled(TRUE); | 821 | d->tbAddToList->setEnabled(TRUE); |
831 | } | 822 | } |
832 | break; | 823 | break; |
833 | case 3: | 824 | case 3: |
834 | { | 825 | { |
835 | if( tbDeletePlaylist->isHidden()) | 826 | if( tbDeletePlaylist->isHidden()) |
836 | tbDeletePlaylist->show(); | 827 | tbDeletePlaylist->show(); |
837 | playLists->reread(); | 828 | playLists->reread(); |
838 | } | 829 | } |
839 | break; | 830 | break; |
840 | }; | 831 | }; |
841 | } | 832 | } |
842 | 833 | ||
843 | void PlayListWidget::btnPlay(bool b) { | 834 | void PlayListWidget::btnPlay(bool b) { |
844 | qDebug("<<<<<<<<<<<<<<<BtnPlay %d", b); | 835 | // mediaPlayerState->setPlaying(b); |
845 | // mediaPlayerState->setPlaying(b); | 836 | switch ( tabWidget->currentPageIndex()) { |
846 | switch ( tabWidget->currentPageIndex()) { | 837 | case 0: |
847 | case 0: | 838 | { |
848 | { | 839 | // if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 |
849 | qDebug("1"); | 840 | // if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) { |
850 | // if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 | 841 | // QMessageBox::message("Note","You are trying to play\na malformed url."); |
851 | // if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) { | 842 | // } else { |
852 | // QMessageBox::message("Note","You are trying to play\na malformed url."); | 843 | mediaPlayerState->setPlaying(b); |
853 | // } else { | 844 | insanityBool=FALSE; |
854 | mediaPlayerState->setPlaying(b); | 845 | qDebug("insanity"); |
855 | insanityBool=FALSE; | 846 | // } |
856 | qDebug("insanity"); | 847 | } |
857 | // } | 848 | break; |
858 | } | 849 | case 1: |
859 | break; | 850 | { |
860 | case 1: | 851 | // d->selectedFiles->unSelect(); |
861 | { | 852 | addToSelection( audioView->currentItem() ); |
862 | qDebug("2"); | 853 | mediaPlayerState->setPlaying( b); |
863 | // d->selectedFiles->unSelect(); | 854 | d->selectedFiles->removeSelected( ); |
864 | addToSelection( audioView->currentItem() ); | 855 | d->selectedFiles->unSelect(); |
865 | mediaPlayerState->setPlaying( b); | 856 | tabWidget->setCurrentPage(1); |
866 | d->selectedFiles->removeSelected( ); | 857 | insanityBool=FALSE; |
867 | d->selectedFiles->unSelect(); | 858 | }// audioView->clearSelection(); |
868 | tabWidget->setCurrentPage(1); | 859 | break; |
869 | insanityBool=FALSE; | 860 | case 2: |
870 | }// audioView->clearSelection(); | 861 | { |
871 | break; | ||
872 | case 2: | ||
873 | { | ||
874 | qDebug("3"); | ||
875 | 862 | ||
876 | addToSelection( videoView->currentItem() ); | 863 | addToSelection( videoView->currentItem() ); |
877 | mediaPlayerState->setPlaying( b); | 864 | mediaPlayerState->setPlaying( b); |
878 | // qApp->processEvents(); | 865 | // qApp->processEvents(); |
879 | d->selectedFiles->removeSelected( ); | 866 | d->selectedFiles->removeSelected( ); |
880 | d->selectedFiles->unSelect(); | 867 | d->selectedFiles->unSelect(); |
881 | tabWidget->setCurrentPage(2); | 868 | tabWidget->setCurrentPage(2); |
882 | insanityBool=FALSE; | 869 | insanityBool=FALSE; |
883 | }// videoView->clearSelection(); | 870 | }// videoView->clearSelection(); |
884 | break; | 871 | break; |
885 | }; | 872 | }; |
886 | 873 | ||
887 | } | 874 | } |
888 | 875 | ||
889 | void PlayListWidget::deletePlaylist() { | 876 | void PlayListWidget::deletePlaylist() { |
890 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), | 877 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), |
891 | (tr("You really want to delete\nthis playlist?")), | 878 | (tr("You really want to delete\nthis playlist?")), |
892 | (tr("Yes")), (tr("No")), 0 )){ | 879 | (tr("Yes")), (tr("No")), 0 )){ |
893 | case 0: // Yes clicked, | 880 | case 0: // Yes clicked, |
894 | QFile().remove(playLists->selectedDocument().file()); | 881 | QFile().remove(playLists->selectedDocument().file()); |
895 | QFile().remove(playLists->selectedDocument().linkFile()); | 882 | QFile().remove(playLists->selectedDocument().linkFile()); |
896 | playLists->reread(); | 883 | playLists->reread(); |
897 | break; | 884 | break; |
898 | case 1: // Cancel | 885 | case 1: // Cancel |
899 | break; | 886 | break; |
900 | }; | 887 | }; |
901 | } | 888 | } |
902 | 889 | ||
903 | void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint&, int ) | 890 | void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint&, int ) |
904 | { | 891 | { |
905 | switch (mouse) { | 892 | switch (mouse) { |
906 | case 1: | 893 | case 1: |
907 | break; | 894 | break; |
908 | case 2:{ | 895 | case 2:{ |
909 | 896 | ||
910 | QPopupMenu m; | 897 | QPopupMenu m; |
911 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); | 898 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); |
912 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); | 899 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); |
913 | m.insertSeparator(); | 900 | m.insertSeparator(); |
914 | if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) | 901 | if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) |
915 | m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); | 902 | m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); |
916 | 903 | ||
917 | m.exec( QCursor::pos() ); | 904 | m.exec( QCursor::pos() ); |
918 | } | 905 | } |
919 | break; | 906 | break; |
920 | }; | 907 | }; |
921 | } | 908 | } |
922 | 909 | ||
923 | void PlayListWidget::playSelected() | 910 | void PlayListWidget::playSelected() |
924 | { | 911 | { |
925 | qDebug("playSelected"); | ||
926 | btnPlay( true); | 912 | btnPlay( true); |
927 | // d->selectedFiles->unSelect(); | 913 | // d->selectedFiles->unSelect(); |
928 | } | 914 | } |
929 | 915 | ||
930 | void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint&, int) | 916 | void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint&, int) |
931 | { | 917 | { |
932 | switch (mouse) { | 918 | switch (mouse) { |
933 | case 1: | 919 | case 1: |
934 | 920 | ||
935 | break; | ||
936 | case 2:{ | ||
937 | QPopupMenu m; | ||
938 | m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); | ||
939 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); | ||
940 | // m.insertSeparator(); | ||
941 | // m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); | ||
942 | m.exec( QCursor::pos() ); | ||
943 | } | ||
944 | break; | 921 | break; |
945 | }; | 922 | case 2:{ |
923 | QPopupMenu m; | ||
924 | m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); | ||
925 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); | ||
926 | // m.insertSeparator(); | ||
927 | // m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); | ||
928 | m.exec( QCursor::pos() ); | ||
929 | } | ||
930 | break; | ||
931 | }; | ||
946 | 932 | ||
947 | } | 933 | } |
948 | 934 | ||
949 | void PlayListWidget::listDelete() { | 935 | void PlayListWidget::listDelete() { |
950 | Config cfg( "OpiePlayer" ); | 936 | Config cfg( "OpiePlayer" ); |
951 | cfg.setGroup("PlayList"); | 937 | cfg.setGroup("PlayList"); |
952 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | 938 | currentPlayList = cfg.readEntry("CurrentPlaylist",""); |
953 | QString file; | 939 | QString file; |
954 | // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 940 | // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
955 | switch ( tabWidget->currentPageIndex()) { | 941 | switch ( tabWidget->currentPageIndex()) { |
956 | case 0: | 942 | case 0: |
957 | break; | ||
958 | case 1: | ||
959 | { | ||
960 | file = audioView->currentItem()->text(0); | ||
961 | QListIterator<DocLnk> Pdit( files.children() ); | ||
962 | for ( ; Pdit.current(); ++Pdit ) { | ||
963 | if( Pdit.current()->name() == file) { | ||
964 | LnkProperties prop( Pdit.current() ); | ||
965 | prop.showMaximized(); | ||
966 | prop.exec(); | ||
967 | } | ||
968 | } | ||
969 | populateAudioView(); | ||
970 | } | ||
971 | break; | 943 | break; |
972 | case 2: | 944 | case 1: |
973 | { | 945 | { |
974 | // file = videoView->selectedItem()->text(0); | 946 | file = audioView->currentItem()->text(0); |
975 | // for ( int i = 0; i < noOfFiles; i++ ) { | 947 | QListIterator<DocLnk> Pdit( files.children() ); |
976 | // QString entryName; | 948 | for ( ; Pdit.current(); ++Pdit ) { |
977 | // entryName.sprintf( "File%i", i + 1 ); | 949 | if( Pdit.current()->name() == file) { |
978 | // QString linkFile = cfg.readEntry( entryName ); | 950 | LnkProperties prop( Pdit.current() ); |
979 | // AppLnk lnk( AppLnk(linkFile)); | 951 | prop.showMaximized(); |
980 | // if( lnk.name() == file ) { | 952 | prop.exec(); |
981 | // LnkProperties prop( &lnk); | 953 | } |
982 | // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); | ||
983 | // prop.showMaximized(); | ||
984 | // prop.exec(); | ||
985 | // } | ||
986 | // } | ||
987 | } | 954 | } |
988 | break; | 955 | populateAudioView(); |
989 | }; | 956 | } |
957 | break; | ||
958 | case 2: | ||
959 | { | ||
960 | // file = videoView->selectedItem()->text(0); | ||
961 | // for ( int i = 0; i < noOfFiles; i++ ) { | ||
962 | // QString entryName; | ||
963 | // entryName.sprintf( "File%i", i + 1 ); | ||
964 | // QString linkFile = cfg.readEntry( entryName ); | ||
965 | // AppLnk lnk( AppLnk(linkFile)); | ||
966 | // if( lnk.name() == file ) { | ||
967 | // LnkProperties prop( &lnk); | ||
968 | // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); | ||
969 | // prop.showMaximized(); | ||
970 | // prop.exec(); | ||
971 | // } | ||
972 | // } | ||
973 | } | ||
974 | break; | ||
975 | }; | ||
990 | } | 976 | } |
991 | 977 | ||
992 | void PlayListWidget::scanForAudio() { | 978 | void PlayListWidget::scanForAudio() { |
993 | // qDebug("scan for audio"); | 979 | // qDebug("scan for audio"); |
994 | files.detachChildren(); | 980 | files.detachChildren(); |
995 | QListIterator<DocLnk> sdit( files.children() ); | 981 | QListIterator<DocLnk> sdit( files.children() ); |
996 | for ( ; sdit.current(); ++sdit ) { | 982 | for ( ; sdit.current(); ++sdit ) { |
997 | delete sdit.current(); | 983 | delete sdit.current(); |
998 | } | 984 | } |
999 | Global::findDocuments( &files, audioMimes); | 985 | Global::findDocuments( &files, audioMimes); |
1000 | audioScan = true; | 986 | audioScan = true; |
1001 | } | 987 | } |
1002 | void PlayListWidget::scanForVideo() { | 988 | void PlayListWidget::scanForVideo() { |
1003 | // qDebug("scan for video"); | 989 | // qDebug("scan for video"); |
1004 | vFiles.detachChildren(); | 990 | vFiles.detachChildren(); |
1005 | QListIterator<DocLnk> sdit( vFiles.children() ); | 991 | QListIterator<DocLnk> sdit( vFiles.children() ); |
1006 | for ( ; sdit.current(); ++sdit ) { | 992 | for ( ; sdit.current(); ++sdit ) { |
1007 | delete sdit.current(); | 993 | delete sdit.current(); |
1008 | } | 994 | } |
1009 | Global::findDocuments(&vFiles, "video/*"); | 995 | Global::findDocuments(&vFiles, "video/*"); |
1010 | videoScan = true; | 996 | videoScan = true; |
1011 | } | 997 | } |
1012 | 998 | ||
1013 | void PlayListWidget::populateAudioView() { | 999 | void PlayListWidget::populateAudioView() { |
1014 | 1000 | ||
1015 | audioView->clear(); | 1001 | audioView->clear(); |
1016 | StorageInfo storageInfo; | 1002 | StorageInfo storageInfo; |
1017 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1003 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
1018 | if(!audioScan) scanForAudio(); | 1004 | if(!audioScan) scanForAudio(); |
1019 | 1005 | ||
1020 | QListIterator<DocLnk> dit( files.children() ); | 1006 | QListIterator<DocLnk> dit( files.children() ); |
1021 | QListIterator<FileSystem> it ( fs ); | 1007 | QListIterator<FileSystem> it ( fs ); |
1022 | 1008 | ||
1023 | QString storage; | 1009 | QString storage; |
1024 | for ( ; dit.current(); ++dit ) { | 1010 | for ( ; dit.current(); ++dit ) { |
1025 | for( ; it.current(); ++it ){ | 1011 | for( ; it.current(); ++it ){ |
1026 | const QString name = (*it)->name(); | 1012 | const QString name = (*it)->name(); |
1027 | const QString path = (*it)->path(); | 1013 | const QString path = (*it)->path(); |
1028 | if(dit.current()->file().find(path) != -1 ) storage=name; | 1014 | if(dit.current()->file().find(path) != -1 ) storage=name; |
1029 | } | 1015 | } |
1030 | 1016 | ||
1031 | QListViewItem * newItem; | 1017 | QListViewItem * newItem; |
1032 | if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { | 1018 | if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { |
1033 | long size; | 1019 | long size; |
1034 | if( dit.current()->file().left(4) == "http" ) | 1020 | if( dit.current()->file().left(4) == "http" ) |
1035 | size=0; | 1021 | size=0; |
1036 | else | 1022 | else |
1037 | size = QFile( dit.current()->file() ).size(); | 1023 | size = QFile( dit.current()->file() ).size(); |
1038 | // qDebug(dit.current()->name()); | 1024 | // qDebug(dit.current()->name()); |
1039 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), | 1025 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), |
1040 | QString::number(size ), storage, dit.current()->file()); | 1026 | QString::number(size ), storage, dit.current()->file()); |
1041 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); | 1027 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); |
1042 | } | 1028 | } |
1043 | } | 1029 | } |
1044 | 1030 | ||
1045 | } | 1031 | } |
1046 | 1032 | ||
1047 | void PlayListWidget::populateVideoView() { | 1033 | void PlayListWidget::populateVideoView() { |
1048 | videoView->clear(); | 1034 | videoView->clear(); |
1049 | StorageInfo storageInfo; | 1035 | StorageInfo storageInfo; |
1050 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1036 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
1051 | 1037 | ||
1052 | if(!videoScan ) scanForVideo(); | 1038 | if(!videoScan ) scanForVideo(); |
1053 | 1039 | ||
1054 | QListIterator<DocLnk> Vdit( vFiles.children() ); | 1040 | QListIterator<DocLnk> Vdit( vFiles.children() ); |
1055 | QListIterator<FileSystem> it ( fs ); | 1041 | QListIterator<FileSystem> it ( fs ); |
1056 | videoView->clear(); | 1042 | videoView->clear(); |
1057 | QString storage; | 1043 | QString storage; |
1058 | for ( ; Vdit.current(); ++Vdit ) { | 1044 | for ( ; Vdit.current(); ++Vdit ) { |
1059 | for( ; it.current(); ++it ){ | 1045 | for( ; it.current(); ++it ){ |
1060 | const QString name = (*it)->name(); | 1046 | const QString name = (*it)->name(); |
1061 | const QString path = (*it)->path(); | 1047 | const QString path = (*it)->path(); |
1062 | if( Vdit.current()->file().find(path) != -1 ) storage=name; | 1048 | if( Vdit.current()->file().find(path) != -1 ) storage=name; |
1063 | } | 1049 | } |
1064 | 1050 | ||
1065 | QListViewItem * newItem; | 1051 | QListViewItem * newItem; |
1066 | if ( QFile( Vdit.current()->file()).exists() ) { | 1052 | if ( QFile( Vdit.current()->file()).exists() ) { |
1067 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), | 1053 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), |
1068 | QString::number( QFile( Vdit.current()->file() ).size() ), | 1054 | QString::number( QFile( Vdit.current()->file() ).size() ), |
1069 | storage, Vdit.current()->file()); | 1055 | storage, Vdit.current()->file()); |
1070 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); | 1056 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); |
1071 | } | 1057 | } |
1072 | } | 1058 | } |
1073 | } | 1059 | } |
1074 | 1060 | ||
1075 | void PlayListWidget::openFile() { | 1061 | void PlayListWidget::openFile() { |
1076 | qDebug("<<<<<<<<<OPEN File"); | 1062 | QString filename, name; |
1077 | QString filename, name; | 1063 | InputDialog *fileDlg; |
1078 | InputDialog *fileDlg; | 1064 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); |
1079 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); | 1065 | fileDlg->exec(); |
1080 | fileDlg->exec(); | 1066 | if( fileDlg->result() == 1 ) { |
1081 | if( fileDlg->result() == 1 ) { | 1067 | filename = fileDlg->text(); |
1082 | filename = fileDlg->text(); | 1068 | // qDebug( "Selected filename is " + filename ); |
1083 | qDebug( "Selected filename is " + filename ); | 1069 | DocLnk lnk; |
1084 | // Om3u *m3uList; | 1070 | Config cfg( "OpiePlayer" ); |
1085 | DocLnk lnk; | 1071 | cfg.setGroup("PlayList"); |
1086 | Config cfg( "OpiePlayer" ); | ||
1087 | cfg.setGroup("PlayList"); | ||
1088 | |||
1089 | QString m3uFile; | ||
1090 | m3uFile = filename; | ||
1091 | if(filename.left(4) == "http") { | ||
1092 | if(filename.find(":",8,TRUE) != -1) { //found a port | ||
1093 | |||
1094 | // m3uFile = filename.left( filename.find( ":",8,TRUE)); | ||
1095 | m3uFile = filename; | ||
1096 | if( m3uFile.right( 1 ).find( '/' ) == -1) { | ||
1097 | m3uFile += "/"; | ||
1098 | } | ||
1099 | filename = m3uFile; | ||
1100 | // qDebug("1 "+m3uFile); | ||
1101 | // } else if(filename.left(4) == "http"){ | ||
1102 | // m3uFile=filename; | ||
1103 | // m3uFile = m3uFile.right( m3uFile.length() - 7); | ||
1104 | // qDebug("2 "+m3uFile); | ||
1105 | // } else{ | ||
1106 | // m3uFile=filename; | ||
1107 | // qDebug("3 "+m3uFile); | ||
1108 | } | ||
1109 | lnk.setName( m3uFile ); //sets name | ||
1110 | lnk.setFile( filename ); //sets file name | ||
1111 | lnk.setIcon("opieplayer2/musicfile"); | ||
1112 | d->selectedFiles->addToSelection( lnk ); | ||
1113 | writeCurrentM3u(); | ||
1114 | } | ||
1115 | else if( filename.right( 3) == "m3u" ) { | ||
1116 | readm3u( filename ); | ||
1117 | 1072 | ||
1118 | } else if( filename.right(3) == "pls" ) { | 1073 | QString m3uFile; |
1119 | readPls( filename ); | 1074 | m3uFile = filename; |
1120 | } else { | 1075 | if(filename.left(4) == "http") { |
1121 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name | 1076 | if(filename.find(":",8,TRUE) != -1) { //found a port |
1122 | lnk.setFile( filename ); //sets file name | 1077 | |
1123 | d->selectedFiles->addToSelection( lnk); | 1078 | m3uFile = filename; |
1124 | writeCurrentM3u(); | 1079 | if( m3uFile.right( 1 ).find( '/' ) == -1) { |
1125 | } | 1080 | m3uFile += "/"; |
1126 | } | 1081 | } |
1082 | filename = m3uFile; | ||
1083 | = } | ||
1084 | lnk.setName( m3uFile ); //sets name | ||
1085 | lnk.setFile( filename ); //sets file name | ||
1086 | lnk.setIcon("opieplayer2/musicfile"); | ||
1087 | d->selectedFiles->addToSelection( lnk ); | ||
1088 | writeCurrentM3u(); | ||
1089 | } | ||
1090 | else if( filename.right( 3) == "m3u" ) { | ||
1091 | readm3u( filename ); | ||
1092 | |||
1093 | } else if( filename.right(3) == "pls" ) { | ||
1094 | readPls( filename ); | ||
1095 | } else { | ||
1096 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name | ||
1097 | lnk.setFile( filename ); //sets file name | ||
1098 | d->selectedFiles->addToSelection( lnk); | ||
1099 | lnk.removeLinkFile(); | ||
1100 | writeCurrentM3u(); | ||
1101 | } | ||
1102 | } | ||
1127 | 1103 | ||
1128 | if( fileDlg ) { | 1104 | if( fileDlg ) { |
1129 | delete fileDlg; | 1105 | delete fileDlg; |
1130 | } | 1106 | } |
1131 | } | 1107 | } |
1132 | 1108 | ||
1133 | 1109 | ||
1134 | /* | 1110 | /* |
1135 | reads m3u and shows files/urls to playlist widget */ | 1111 | reads m3u and shows files/urls to playlist widget */ |
1136 | void PlayListWidget::readm3u( const QString &filename ) { | 1112 | void PlayListWidget::readm3u( const QString &filename ) { |
1137 | qDebug( "read m3u filename " + filename ); | 1113 | // qDebug( "read m3u filename " + filename ); |
1138 | 1114 | ||
1139 | Om3u *m3uList; | 1115 | Om3u *m3uList; |
1140 | QString s, name; | 1116 | QString s, name; |
1141 | m3uList = new Om3u( filename, IO_ReadOnly ); | 1117 | m3uList = new Om3u( filename, IO_ReadOnly ); |
1142 | m3uList->readM3u(); | 1118 | m3uList->readM3u(); |
1143 | DocLnk lnk; | 1119 | DocLnk lnk; |
1144 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | 1120 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { |
1145 | s = *it; | 1121 | s = *it; |
1146 | // qDebug("reading "+ s); | 1122 | // qDebug("reading "+ s); |
1147 | if(s.left(4)=="http") { | 1123 | if(s.left(4)=="http") { |
1148 | lnk.setName( s ); //sets file name | 1124 | lnk.setName( s ); //sets file name |
1149 | lnk.setIcon("opieplayer2/musicfile"); | 1125 | lnk.setIcon("opieplayer2/musicfile"); |
1150 | 1126 | ||
1151 | // if(s.right(4) != '.' || s.right(5) != '.') | 1127 | // if(s.right(4) != '.' || s.right(5) != '.') |
1152 | if(s.right(4) != '.' || s.right(5) != '.' ) | 1128 | if(s.right(4) != '.' || s.right(5) != '.' ) |
1153 | if( s.right(1) != "/") | 1129 | if( s.right(1) != "/") |
1154 | lnk.setFile( s+"/"); //if url with no extension | 1130 | lnk.setFile( s+"/"); //if url with no extension |
1155 | else | 1131 | else |
1156 | lnk.setFile( s ); //sets file name | 1132 | lnk.setFile( s ); //sets file name |
1157 | 1133 | ||
1158 | } else { | 1134 | } else { |
1159 | // if( QFileInfo( s ).exists() ) { | 1135 | // if( QFileInfo( s ).exists() ) { |
1160 | lnk.setName( fullBaseName ( QFileInfo(s))); | 1136 | lnk.setName( fullBaseName ( QFileInfo(s))); |
1161 | // if(s.right(4) == '.') {//if regular file | 1137 | // if(s.right(4) == '.') {//if regular file |
1162 | if(s.left(1) != "/") { | 1138 | if(s.left(1) != "/") { |
1163 | // qDebug("set link "+QFileInfo(filename).dirPath()+"/"+s); | 1139 | // qDebug("set link "+QFileInfo(filename).dirPath()+"/"+s); |
1164 | lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); | 1140 | lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); |
1165 | lnk.setIcon("SoundPlayer"); | 1141 | lnk.setIcon("SoundPlayer"); |
1166 | } else { | 1142 | } else { |
1167 | // qDebug("set link2 "+s); | 1143 | // qDebug("set link2 "+s); |
1168 | lnk.setFile( s); | 1144 | lnk.setFile( s); |
1169 | lnk.setIcon("SoundPlayer"); | 1145 | lnk.setIcon("SoundPlayer"); |
1170 | } | 1146 | } |
1171 | } | 1147 | } |
1172 | d->selectedFiles->addToSelection( lnk ); | 1148 | d->selectedFiles->addToSelection( lnk ); |
1173 | } | 1149 | } |
1174 | Config config( "OpiePlayer" ); | 1150 | Config config( "OpiePlayer" ); |
1175 | config.setGroup( "PlayList" ); | 1151 | config.setGroup( "PlayList" ); |
1176 | 1152 | ||
1177 | config.writeEntry("CurrentPlaylist",filename); | 1153 | config.writeEntry("CurrentPlaylist",filename); |
1178 | config.write(); | 1154 | config.write(); |
1179 | currentPlayList=filename; | 1155 | currentPlayList=filename; |
1180 | 1156 | ||
1181 | // m3uList->write(); | 1157 | // m3uList->write(); |
1182 | m3uList->close(); | 1158 | m3uList->close(); |
1183 | if(m3uList) delete m3uList; | 1159 | if(m3uList) delete m3uList; |
1184 | 1160 | ||
1185 | d->selectedFiles->setSelectedItem( s); | 1161 | d->selectedFiles->setSelectedItem( s); |
1186 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); | 1162 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); |
1187 | 1163 | ||
1188 | } | 1164 | } |
1189 | 1165 | ||
1190 | /* | 1166 | /* |
1191 | reads pls and adds files/urls to playlist */ | 1167 | reads pls and adds files/urls to playlist */ |
1192 | void PlayListWidget::readPls( const QString &filename ) { | 1168 | void PlayListWidget::readPls( const QString &filename ) { |
1193 | 1169 | ||
1194 | qDebug( "pls filename is " + filename ); | 1170 | // qDebug( "pls filename is " + filename ); |
1195 | Om3u *m3uList; | 1171 | Om3u *m3uList; |
1196 | QString s, name; | 1172 | QString s, name; |
1197 | m3uList = new Om3u( filename, IO_ReadOnly ); | 1173 | m3uList = new Om3u( filename, IO_ReadOnly ); |
1198 | m3uList->readPls(); | 1174 | m3uList->readPls(); |
1199 | 1175 | ||
1200 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | 1176 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { |
1201 | s = *it; | 1177 | s = *it; |
1202 | // s.replace( QRegExp( "%20" )," " ); | 1178 | // s.replace( QRegExp( "%20" )," " ); |
1203 | DocLnk lnk( s ); | 1179 | DocLnk lnk( s ); |
1204 | QFileInfo f( s ); | 1180 | QFileInfo f( s ); |
1205 | QString name = fullBaseName ( f); | 1181 | QString name = fullBaseName ( f); |
1206 | 1182 | ||
1207 | if( name.left( 4 ) == "http" ) { | 1183 | if( name.left( 4 ) == "http" ) { |
1208 | name = s.right( s.length() - 7); | 1184 | name = s.right( s.length() - 7); |
1209 | } else { | 1185 | } else { |
1210 | name = s; | 1186 | name = s; |
1211 | } | 1187 | } |
1212 | 1188 | ||
1213 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); | 1189 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); |
1214 | 1190 | ||
1215 | lnk.setName( name ); | 1191 | lnk.setName( name ); |
1216 | if( s.at( s.length() - 4) == '.') {// if this is probably a file | 1192 | if( s.at( s.length() - 4) == '.') {// if this is probably a file |
1217 | lnk.setFile( s ); | 1193 | lnk.setFile( s ); |
1218 | } else { //if its a url | 1194 | } else { //if its a url |
1219 | if( name.right( 1 ).find( '/' ) == -1) { | 1195 | if( name.right( 1 ).find( '/' ) == -1) { |
1220 | s += "/"; | 1196 | s += "/"; |
1221 | } | 1197 | } |
1222 | lnk.setFile( s ); | 1198 | lnk.setFile( s ); |
1223 | } | 1199 | } |
1224 | lnk.setType( "audio/x-mpegurl" ); | 1200 | lnk.setType( "audio/x-mpegurl" ); |
1225 | 1201 | ||
1226 | lnk.writeLink(); | 1202 | lnk.writeLink(); |
1227 | d->selectedFiles->addToSelection( lnk ); | 1203 | d->selectedFiles->addToSelection( lnk ); |
1228 | } | 1204 | } |
1229 | 1205 | ||
1230 | m3uList->close(); | 1206 | m3uList->close(); |
1231 | if(m3uList) delete m3uList; | 1207 | if(m3uList) delete m3uList; |
1232 | } | 1208 | } |
1233 | 1209 | ||
1234 | /* | 1210 | /* |
1235 | writes current playlist to current m3u file */ | 1211 | writes current playlist to current m3u file */ |
1236 | void PlayListWidget::writeCurrentM3u() { | 1212 | void PlayListWidget::writeCurrentM3u() { |
1237 | qDebug("writing to current m3u"); | 1213 | // qDebug("writing to current m3u"); |
1238 | Config cfg( "OpiePlayer" ); | 1214 | Config cfg( "OpiePlayer" ); |
1239 | cfg.setGroup("PlayList"); | 1215 | cfg.setGroup("PlayList"); |
1240 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | 1216 | currentPlayList = cfg.readEntry("CurrentPlaylist",""); |
1241 | Om3u *m3uList; | 1217 | Om3u *m3uList; |
1242 | m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); | 1218 | m3uList = new Om3u( currentPlayList, IO_ReadWrite | IO_Truncate ); |
1243 | 1219 | ||
1244 | if( d->selectedFiles->first()) { | 1220 | if( d->selectedFiles->first()) { |
1245 | do { | 1221 | do { |
1246 | qDebug( "writeCurrentM3u " +d->selectedFiles->current()->file()); | 1222 | // qDebug( "writeCurrentM3u " +d->selectedFiles->current()->file()); |
1247 | m3uList->add( d->selectedFiles->current()->file() ); | 1223 | m3uList->add( d->selectedFiles->current()->file() ); |
1248 | } | 1224 | } |
1249 | while ( d->selectedFiles->next() ); | 1225 | while ( d->selectedFiles->next() ); |
1250 | qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" ); | 1226 | // qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" ); |
1251 | m3uList->write(); | 1227 | m3uList->write(); |
1252 | m3uList->close(); | 1228 | m3uList->close(); |
1253 | 1229 | ||
1254 | if(m3uList) delete m3uList; | 1230 | if(m3uList) delete m3uList; |
1255 | } | 1231 | } |
1256 | } | 1232 | } |
1257 | 1233 | ||
1258 | /* | 1234 | /* |
1259 | writes current playlist to m3u file */ | 1235 | writes current playlist to m3u file */ |
1260 | void PlayListWidget::writem3u() { | 1236 | void PlayListWidget::writem3u() { |
1261 | InputDialog *fileDlg; | 1237 | InputDialog *fileDlg; |
1262 | fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); | 1238 | fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); |
1263 | fileDlg->exec(); | 1239 | fileDlg->exec(); |
1264 | QString name, filename, list; | 1240 | QString name, filename, list; |
1265 | Om3u *m3uList; | 1241 | Om3u *m3uList; |
1266 | 1242 | ||
1267 | if( fileDlg->result() == 1 ) { | 1243 | if( fileDlg->result() == 1 ) { |
1268 | name = fileDlg->text(); | 1244 | name = fileDlg->text(); |
1269 | // qDebug( filename ); | 1245 | // qDebug( filename ); |
1270 | if( name.find("/",0,true) != -1) {// assume they specify a file path | 1246 | if( name.find("/",0,true) != -1) {// assume they specify a file path |
1271 | filename = name; | 1247 | filename = name; |
1272 | name = name.right(name.length()- name.findRev("/",-1,true) - 1 ); | 1248 | name = name.right(name.length()- name.findRev("/",-1,true) - 1 ); |
1273 | } | 1249 | } |
1274 | else //otherwise dump it somewhere noticable | 1250 | else //otherwise dump it somewhere noticable |
1275 | filename = QPEApplication::documentDir() + "/" + name; | 1251 | filename = QPEApplication::documentDir() + "/" + name; |
1276 | 1252 | ||
1277 | if( filename.right( 3 ) != "m3u" ) //needs filename extension | 1253 | if( filename.right( 3 ) != "m3u" ) //needs filename extension |
1278 | filename += ".m3u"; | 1254 | filename += ".m3u"; |
1279 | 1255 | ||
1280 | if( d->selectedFiles->first()) { | 1256 | if( d->selectedFiles->first()) { |
1281 | m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); | 1257 | m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); |
1282 | 1258 | ||
1283 | do { | 1259 | do { |
1284 | m3uList->add( d->selectedFiles->current()->file()); | 1260 | m3uList->add( d->selectedFiles->current()->file()); |
1285 | } | 1261 | } |
1286 | while ( d->selectedFiles->next() ); | 1262 | while ( d->selectedFiles->next() ); |
1287 | // qDebug( list ); | 1263 | // qDebug( list ); |
1288 | m3uList->write(); | 1264 | m3uList->write(); |
1289 | m3uList->close(); | 1265 | m3uList->close(); |
1290 | if(m3uList) delete m3uList; | 1266 | if(m3uList) delete m3uList; |
1291 | 1267 | ||
1292 | if(fileDlg) delete fileDlg; | 1268 | if(fileDlg) delete fileDlg; |
1293 | 1269 | ||
1294 | DocLnk lnk; | 1270 | DocLnk lnk; |
1295 | lnk.setFile( filename); | 1271 | lnk.setFile( filename); |
1296 | lnk.setIcon("opieplayer2/playlist2"); | 1272 | lnk.setIcon("opieplayer2/playlist2"); |
1297 | lnk.setName( name); //sets file name | 1273 | lnk.setName( name); //sets file name |
1298 | 1274 | ||
1299 | // qDebug(filename); | 1275 | // qDebug(filename); |
1300 | Config config( "OpiePlayer" ); | 1276 | Config config( "OpiePlayer" ); |
1301 | config.setGroup( "PlayList" ); | 1277 | config.setGroup( "PlayList" ); |
1302 | 1278 | ||
1303 | config.writeEntry("CurrentPlaylist",filename); | 1279 | config.writeEntry("CurrentPlaylist",filename); |
1304 | currentPlayList=filename; | 1280 | currentPlayList=filename; |
1305 | 1281 | ||
1306 | if(!lnk.writeLink()) { | 1282 | if(!lnk.writeLink()) { |
1307 | qDebug("Writing doclink did not work"); | 1283 | // qDebug("Writing doclink did not work"); |
1308 | } | 1284 | } |
1309 | 1285 | ||
1310 | setCaption(tr("OpiePlayer: ") + name); | 1286 | setCaption(tr("OpiePlayer: ") + name); |
1311 | } | 1287 | } |
1312 | } | 1288 | } |
1313 | } | 1289 | } |
1314 | 1290 | ||
1315 | 1291 | ||
1316 | void PlayListWidget::keyReleaseEvent( QKeyEvent *e) | 1292 | void PlayListWidget::keyReleaseEvent( QKeyEvent *e) |
1317 | { | 1293 | { |
1318 | switch ( e->key() ) { | 1294 | switch ( e->key() ) { |
1319 | ////////////////////////////// Zaurus keys | 1295 | ////////////////////////////// Zaurus keys |
1320 | case Key_F9: //activity | 1296 | case Key_F9: //activity |
1321 | // if(audioUI->isHidden()) | 1297 | // if(audioUI->isHidden()) |
1322 | // audioUI->showMaximized(); | 1298 | // audioUI->showMaximized(); |
1323 | break; | 1299 | break; |
1324 | case Key_F10: //contacts | 1300 | case Key_F10: //contacts |
1325 | // if( videoUI->isHidden()) | 1301 | // if( videoUI->isHidden()) |
1326 | // videoUI->showMaximized(); | 1302 | // videoUI->showMaximized(); |
1327 | break; | 1303 | break; |
1328 | case Key_F11: //menu | 1304 | case Key_F11: //menu |
1329 | break; | 1305 | break; |
1330 | case Key_F12: //home | 1306 | case Key_F12: //home |
1331 | // doBlank(); | 1307 | // doBlank(); |
1332 | break; | 1308 | break; |
1333 | case Key_F13: //mail | 1309 | case Key_F13: //mail |
1334 | // doUnblank(); | 1310 | // doUnblank(); |
1335 | break; | 1311 | break; |
1336 | case Key_Q: //add to playlist | 1312 | case Key_Q: //add to playlist |
1337 | qDebug("Add"); | ||
1338 | addSelected(); | 1313 | addSelected(); |
1339 | break; | 1314 | break; |
1340 | case Key_R: //remove from playlist | 1315 | case Key_R: //remove from playlist |
1341 | removeSelected(); | 1316 | removeSelected(); |
1342 | break; | 1317 | break; |
1343 | // case Key_P: //play | 1318 | // case Key_P: //play |
1344 | // qDebug("Play"); | 1319 | // qDebug("Play"); |
1345 | // playSelected(); | 1320 | // playSelected(); |
1346 | // break; | 1321 | // break; |
1347 | case Key_Space: | 1322 | case Key_Space: |
1348 | qDebug("Play"); | ||
1349 | // playSelected(); puh | 1323 | // playSelected(); puh |
1350 | break; | 1324 | break; |
1351 | case Key_1: | 1325 | case Key_1: |
1352 | tabWidget->setCurrentPage(0); | 1326 | tabWidget->setCurrentPage(0); |
1353 | break; | 1327 | break; |
1354 | case Key_2: | 1328 | case Key_2: |
1355 | tabWidget->setCurrentPage(1); | 1329 | tabWidget->setCurrentPage(1); |
1356 | break; | 1330 | break; |
1357 | case Key_3: | 1331 | case Key_3: |
1358 | tabWidget->setCurrentPage(2); | 1332 | tabWidget->setCurrentPage(2); |
1359 | break; | 1333 | break; |
1360 | case Key_4: | 1334 | case Key_4: |
1361 | tabWidget->setCurrentPage(3); | 1335 | tabWidget->setCurrentPage(3); |
1362 | break; | 1336 | break; |
1363 | case Key_Down: | 1337 | case Key_Down: |
1364 | if ( !d->selectedFiles->next() ) | 1338 | if ( !d->selectedFiles->next() ) |
1365 | d->selectedFiles->first(); | 1339 | d->selectedFiles->first(); |
1366 | 1340 | ||
1367 | break; | 1341 | break; |
1368 | case Key_Up: | 1342 | case Key_Up: |
1369 | if ( !d->selectedFiles->prev() ) | 1343 | if ( !d->selectedFiles->prev() ) |
1370 | // d->selectedFiles->last(); | 1344 | // d->selectedFiles->last(); |
1371 | 1345 | ||
1372 | break; | 1346 | break; |
1373 | 1347 | ||
1374 | } | 1348 | } |
1375 | } | 1349 | } |
1376 | 1350 | ||
1377 | void PlayListWidget::keyPressEvent( QKeyEvent *) | 1351 | void PlayListWidget::keyPressEvent( QKeyEvent *) |
1378 | { | 1352 | { |
1379 | // qDebug("Key press"); | 1353 | // qDebug("Key press"); |
1380 | // switch ( e->key() ) { | 1354 | // switch ( e->key() ) { |
1381 | // ////////////////////////////// Zaurus keys | 1355 | // ////////////////////////////// Zaurus keys |
1382 | // case Key_A: //add to playlist | 1356 | // case Key_A: //add to playlist |
1383 | // qDebug("Add"); | 1357 | // qDebug("Add"); |
1384 | // addSelected(); | 1358 | // addSelected(); |
1385 | // break; | 1359 | // break; |
1386 | // case Key_R: //remove from playlist | 1360 | // case Key_R: //remove from playlist |
1387 | // removeSelected(); | 1361 | // removeSelected(); |
1388 | // break; | 1362 | // break; |
1389 | // case Key_P: //play | 1363 | // case Key_P: //play |
1390 | // qDebug("Play"); | 1364 | // qDebug("Play"); |
1391 | // playSelected(); | 1365 | // playSelected(); |
1392 | // break; | 1366 | // break; |
1393 | // case Key_Space: | 1367 | // case Key_Space: |
1394 | // qDebug("Play"); | 1368 | // qDebug("Play"); |
1395 | // playSelected(); | 1369 | // playSelected(); |
1396 | // break; | 1370 | // break; |
1397 | // } | 1371 | // } |
1398 | } | 1372 | } |
1399 | 1373 | ||
1400 | void PlayListWidget::doBlank() { | 1374 | void PlayListWidget::doBlank() { |
1401 | qDebug("do blanking"); | 1375 | // qDebug("do blanking"); |
1402 | fd=open("/dev/fb0",O_RDWR); | 1376 | fd=open("/dev/fb0",O_RDWR); |
1403 | if (fd != -1) { | 1377 | if (fd != -1) { |
1404 | ioctl(fd,FBIOBLANK,1); | 1378 | ioctl(fd,FBIOBLANK,1); |
1405 | // close(fd); | 1379 | // close(fd); |
1406 | } | 1380 | } |
1407 | } | 1381 | } |
1408 | 1382 | ||
1409 | void PlayListWidget::doUnblank() { | 1383 | void PlayListWidget::doUnblank() { |
1410 | // this crashes opieplayer with a segfault | 1384 | // this crashes opieplayer with a segfault |
1411 | // int fd; | 1385 | // int fd; |
1412 | // fd=open("/dev/fb0",O_RDWR); | 1386 | // fd=open("/dev/fb0",O_RDWR); |
1413 | qDebug("do unblanking"); | 1387 | // qDebug("do unblanking"); |
1414 | if (fd != -1) { | 1388 | if (fd != -1) { |
1415 | ioctl(fd,FBIOBLANK,0); | 1389 | ioctl(fd,FBIOBLANK,0); |
1416 | close(fd); | 1390 | close(fd); |
1417 | } | 1391 | } |
1418 | QCopEnvelope h("QPE/System", "setBacklight(int)"); | 1392 | QCopEnvelope h("QPE/System", "setBacklight(int)"); |
1419 | h <<-3;// v[1]; // -3 Force on | 1393 | h <<-3;// v[1]; // -3 Force on |
1420 | } | 1394 | } |
1421 | 1395 | ||
1422 | void PlayListWidget::populateSkinsMenu() { | 1396 | void PlayListWidget::populateSkinsMenu() { |
1423 | int item = 0; | 1397 | int item = 0; |
1424 | defaultSkinIndex = 0; | 1398 | defaultSkinIndex = 0; |
1425 | QString skinName; | 1399 | QString skinName; |
1426 | Config cfg( "OpiePlayer" ); | 1400 | Config cfg( "OpiePlayer" ); |
1427 | cfg.setGroup("Options" ); | 1401 | cfg.setGroup("Options" ); |
1428 | QString skin = cfg.readEntry( "Skin", "default" ); | 1402 | QString skin = cfg.readEntry( "Skin", "default" ); |
1429 | 1403 | ||
1430 | QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" ); | 1404 | QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" ); |
1431 | skinsDir.setFilter( QDir::Dirs ); | 1405 | skinsDir.setFilter( QDir::Dirs ); |
1432 | skinsDir.setSorting(QDir::Name ); | 1406 | skinsDir.setSorting(QDir::Name ); |
1433 | const QFileInfoList *skinslist = skinsDir.entryInfoList(); | 1407 | const QFileInfoList *skinslist = skinsDir.entryInfoList(); |
1434 | QFileInfoListIterator it( *skinslist ); | 1408 | QFileInfoListIterator it( *skinslist ); |
1435 | QFileInfo *fi; | 1409 | QFileInfo *fi; |
1436 | while ( ( fi = it.current() ) ) { | 1410 | while ( ( fi = it.current() ) ) { |
1437 | skinName = fi->fileName(); | 1411 | skinName = fi->fileName(); |
1438 | // qDebug( fi->fileName() ); | 1412 | // qDebug( fi->fileName() ); |
1439 | if( skinName != "." && skinName != ".." && skinName !="CVS" ) { | 1413 | if( skinName != "." && skinName != ".." && skinName !="CVS" ) { |
1440 | item = skinsMenu->insertItem( fi->fileName() ) ; | 1414 | item = skinsMenu->insertItem( fi->fileName() ) ; |
1441 | } | 1415 | } |
1442 | if( skinName == "default" ) { | 1416 | if( skinName == "default" ) { |
1443 | defaultSkinIndex = item; | 1417 | defaultSkinIndex = item; |
1444 | } | 1418 | } |
1445 | if( skinName == skin ) { | 1419 | if( skinName == skin ) { |
1446 | skinsMenu->setItemChecked( item, TRUE ); | 1420 | skinsMenu->setItemChecked( item, TRUE ); |
1447 | } | 1421 | } |
1448 | ++it; | 1422 | ++it; |
1449 | } | 1423 | } |
1450 | } | 1424 | } |
1451 | 1425 | ||
1452 | void PlayListWidget::skinsMenuActivated( int item ) { | 1426 | void PlayListWidget::skinsMenuActivated( int item ) { |
1453 | for( int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) { | 1427 | for( int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) { |
1454 | skinsMenu->setItemChecked( i, FALSE ); | 1428 | skinsMenu->setItemChecked( i, FALSE ); |
1455 | } | 1429 | } |
1456 | skinsMenu->setItemChecked( item, TRUE ); | 1430 | skinsMenu->setItemChecked( item, TRUE ); |
1457 | 1431 | ||
1458 | Config cfg( "OpiePlayer" ); | 1432 | Config cfg( "OpiePlayer" ); |
1459 | cfg.setGroup("Options"); | 1433 | cfg.setGroup("Options"); |
1460 | cfg.writeEntry("Skin", skinsMenu->text( item ) ); | 1434 | cfg.writeEntry("Skin", skinsMenu->text( item ) ); |
1461 | } | 1435 | } |
1462 | 1436 | ||
1463 | void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) { | 1437 | void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) { |
1464 | qDebug("qcop message "+msg ); | 1438 | // qDebug("qcop message "+msg ); |
1465 | QDataStream stream ( data, IO_ReadOnly ); | 1439 | QDataStream stream ( data, IO_ReadOnly ); |
1466 | if ( msg == "play()" ) { //plays current selection | 1440 | if ( msg == "play()" ) { //plays current selection |
1467 | btnPlay( true); | 1441 | btnPlay( true); |
1468 | } else if ( msg == "stop()" ) { | 1442 | } else if ( msg == "stop()" ) { |
1469 | mediaPlayerState->setPlaying( false); | 1443 | mediaPlayerState->setPlaying( false); |
1470 | } else if ( msg == "togglePause()" ) { | 1444 | } else if ( msg == "togglePause()" ) { |
1471 | mediaPlayerState->togglePaused(); | 1445 | mediaPlayerState->togglePaused(); |
1472 | } else if ( msg == "next()" ) { //select next in lis | 1446 | } else if ( msg == "next()" ) { //select next in lis |
1473 | mediaPlayerState->setNext(); | 1447 | mediaPlayerState->setNext(); |
1474 | } else if ( msg == "prev()" ) { //select previous in list | 1448 | } else if ( msg == "prev()" ) { //select previous in list |
1475 | mediaPlayerState->setPrev(); | 1449 | mediaPlayerState->setPrev(); |
1476 | } else if ( msg == "toggleLooping()" ) { //loop or not loop | 1450 | } else if ( msg == "toggleLooping()" ) { //loop or not loop |
1477 | mediaPlayerState->toggleLooping(); | 1451 | mediaPlayerState->toggleLooping(); |
1478 | } else if ( msg == "toggleShuffled()" ) { //shuffled or not shuffled | 1452 | } else if ( msg == "toggleShuffled()" ) { //shuffled or not shuffled |
1479 | mediaPlayerState->toggleShuffled(); | 1453 | mediaPlayerState->toggleShuffled(); |
1480 | } else if ( msg == "volUp()" ) { //volume more | 1454 | } else if ( msg == "volUp()" ) { //volume more |
1481 | // emit moreClicked(); | 1455 | // emit moreClicked(); |
1482 | // emit moreReleased(); | 1456 | // emit moreReleased(); |
1483 | } else if ( msg == "volDown()" ) { //volume less | 1457 | } else if ( msg == "volDown()" ) { //volume less |
1484 | // emit lessClicked(); | 1458 | // emit lessClicked(); |
1485 | // emit lessReleased(); | 1459 | // emit lessReleased(); |
1486 | } else if ( msg == "play(QString)" ) { //play this now | 1460 | } else if ( msg == "play(QString)" ) { //play this now |
1487 | QString file; | 1461 | QString file; |
1488 | stream >> file; | 1462 | stream >> file; |
1489 | setDocumentEx( (const QString &) file); | 1463 | setDocumentEx( (const QString &) file); |
1490 | } else if ( msg == "add(QString)" ) { //add to playlist | 1464 | } else if ( msg == "add(QString)" ) { //add to playlist |
1491 | QString file; | 1465 | QString file; |
1492 | stream >> file; | 1466 | stream >> file; |
1493 | QFileInfo fileInfo(file); | 1467 | QFileInfo fileInfo(file); |
1494 | DocLnk lnk; | 1468 | DocLnk lnk; |
1495 | lnk.setName( fileInfo.baseName() ); //sets name | 1469 | lnk.setName( fileInfo.baseName() ); //sets name |
1496 | lnk.setFile( file ); //sets file name | 1470 | lnk.setFile( file ); //sets file name |
1497 | addToSelection( lnk ); | 1471 | addToSelection( lnk ); |
1498 | } else if ( msg == "rem(QString)" ) { //remove from playlist | 1472 | } else if ( msg == "rem(QString)" ) { //remove from playlist |
1499 | QString file; | 1473 | QString file; |
1500 | stream >> file; | 1474 | stream >> file; |
1501 | |||
1502 | } else if ( msg == "setDocument(QString)" ) { //loop or not loop | 1475 | } else if ( msg == "setDocument(QString)" ) { //loop or not loop |
1503 | QCopEnvelope h("QPE/Application/opieplayer", "raise()"); | 1476 | QCopEnvelope h("QPE/Application/opieplayer", "raise()"); |
1504 | } | 1477 | } |
1505 | |||
1506 | } | 1478 | } |
diff --git a/core/multimedia/opieplayer/videowidget.cpp b/core/multimedia/opieplayer/videowidget.cpp index 48104ca..02c8568 100644 --- a/core/multimedia/opieplayer/videowidget.cpp +++ b/core/multimedia/opieplayer/videowidget.cpp | |||
@@ -1,671 +1,671 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
21 | #include <qpe/mediaplayerplugininterface.h> | 21 | #include <qpe/mediaplayerplugininterface.h> |
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
24 | 24 | ||
25 | #include <qdir.h> | 25 | #include <qdir.h> |
26 | #include <qwidget.h> | 26 | #include <qwidget.h> |
27 | #include <qpainter.h> | 27 | #include <qpainter.h> |
28 | #include <qpixmap.h> | 28 | #include <qpixmap.h> |
29 | #include <qslider.h> | 29 | #include <qslider.h> |
30 | #include <qdrawutil.h> | 30 | #include <qdrawutil.h> |
31 | #include "videowidget.h" | 31 | #include "videowidget.h" |
32 | #include "mediaplayerstate.h" | 32 | #include "mediaplayerstate.h" |
33 | 33 | ||
34 | 34 | ||
35 | #ifdef Q_WS_QWS | 35 | #ifdef Q_WS_QWS |
36 | # define USE_DIRECT_PAINTER | 36 | # define USE_DIRECT_PAINTER |
37 | # include <qdirectpainter_qws.h> | 37 | # include <qdirectpainter_qws.h> |
38 | # include <qgfxraster_qws.h> | 38 | # include <qgfxraster_qws.h> |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | 41 | ||
42 | extern MediaPlayerState *mediaPlayerState; | 42 | extern MediaPlayerState *mediaPlayerState; |
43 | 43 | ||
44 | 44 | ||
45 | static const int xo = 2; // movable x offset | 45 | static const int xo = 2; // movable x offset |
46 | static const int yo = 0; // movable y offset | 46 | static const int yo = 0; // movable y offset |
47 | 47 | ||
48 | 48 | ||
49 | struct MediaButton { | 49 | struct MediaButton { |
50 | // int xPos, yPos; | 50 | // int xPos, yPos; |
51 | bool isToggle, isHeld, isDown; | 51 | bool isToggle, isHeld, isDown; |
52 | // int controlType; | 52 | // int controlType; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | 55 | ||
56 | // Layout information for the videoButtons (and if it is a toggle button or not) | 56 | // Layout information for the videoButtons (and if it is a toggle button or not) |
57 | MediaButton videoButtons[] = { | 57 | MediaButton videoButtons[] = { |
58 | { FALSE, FALSE, FALSE }, // stop | 58 | { FALSE, FALSE, FALSE }, // stop |
59 | { FALSE, FALSE, FALSE }, // play | 59 | { FALSE, FALSE, FALSE }, // play |
60 | { FALSE, FALSE, FALSE }, // previous | 60 | { FALSE, FALSE, FALSE }, // previous |
61 | { FALSE, FALSE, FALSE }, // next | 61 | { FALSE, FALSE, FALSE }, // next |
62 | { FALSE, FALSE, FALSE }, // volUp | 62 | { FALSE, FALSE, FALSE }, // volUp |
63 | { FALSE, FALSE, FALSE }, // volDown | 63 | { FALSE, FALSE, FALSE }, // volDown |
64 | { TRUE, FALSE, FALSE } // fullscreen | 64 | { TRUE, FALSE, FALSE } // fullscreen |
65 | }; | 65 | }; |
66 | 66 | ||
67 | //static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); | 67 | //static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); |
68 | 68 | ||
69 | const char *skinV_mask_file_names[7] = { | 69 | const char *skinV_mask_file_names[7] = { |
70 | "stop","play","back","fwd","up","down","full" | 70 | "stop","play","back","fwd","up","down","full" |
71 | }; | 71 | }; |
72 | 72 | ||
73 | static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); | 73 | static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); |
74 | 74 | ||
75 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : | 75 | VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : |
76 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) | 76 | QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) |
77 | { | 77 | { |
78 | setCaption( tr("OpiePlayer") ); | 78 | setCaption( tr("OpiePlayer") ); |
79 | Config cfg("OpiePlayer"); | 79 | Config cfg("OpiePlayer"); |
80 | 80 | ||
81 | cfg.setGroup("Options"); | 81 | cfg.setGroup("Options"); |
82 | skin = cfg.readEntry("Skin","default"); | 82 | skin = cfg.readEntry("Skin","default"); |
83 | 83 | ||
84 | QString skinPath; | 84 | QString skinPath; |
85 | skinPath = "opieplayer2/skins/" + skin; | 85 | skinPath = "opieplayer2/skins/" + skin; |
86 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) | 86 | if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) |
87 | skinPath = "opieplayer2/skins/default"; | 87 | skinPath = "opieplayer2/skins/default"; |
88 | 88 | ||
89 | qDebug("skin path " + skinPath); | 89 | // qDebug("skin path " + skinPath); |
90 | 90 | ||
91 | // QString skinPath = "opieplayer2/skins/" + skin; | 91 | // QString skinPath = "opieplayer2/skins/" + skin; |
92 | 92 | ||
93 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); | 93 | pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); |
94 | imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); | 94 | imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); |
95 | imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); | 95 | imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); |
96 | 96 | ||
97 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); | 97 | imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); |
98 | imgButtonMask->fill( 0 ); | 98 | imgButtonMask->fill( 0 ); |
99 | 99 | ||
100 | for ( int i = 0; i < 7; i++ ) | 100 | for ( int i = 0; i < 7; i++ ) |
101 | { | 101 | { |
102 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + | 102 | QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + |
103 | "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); | 103 | "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); |
104 | qDebug("loading "+filename); | 104 | // qDebug("loading "+filename); |
105 | masks[i] = new QBitmap( filename ); | 105 | masks[i] = new QBitmap( filename ); |
106 | 106 | ||
107 | if ( !masks[i]->isNull() ) | 107 | if ( !masks[i]->isNull() ) |
108 | { | 108 | { |
109 | QImage imgMask = masks[i]->convertToImage(); | 109 | QImage imgMask = masks[i]->convertToImage(); |
110 | uchar **dest = imgButtonMask->jumpTable(); | 110 | uchar **dest = imgButtonMask->jumpTable(); |
111 | for ( int y = 0; y < imgUp->height(); y++ ) | 111 | for ( int y = 0; y < imgUp->height(); y++ ) |
112 | { | 112 | { |
113 | uchar *line = dest[y]; | 113 | uchar *line = dest[y]; |
114 | for ( int x = 0; x < imgUp->width(); x++ ) | 114 | for ( int x = 0; x < imgUp->width(); x++ ) |
115 | { | 115 | { |
116 | if ( !qRed( imgMask.pixel( x, y ) ) ) | 116 | if ( !qRed( imgMask.pixel( x, y ) ) ) |
117 | line[x] = i + 1; | 117 | line[x] = i + 1; |
118 | } | 118 | } |
119 | } | 119 | } |
120 | } | 120 | } |
121 | } | 121 | } |
122 | qDebug("finished loading first pics"); | 122 | // qDebug("finished loading first pics"); |
123 | for ( int i = 0; i < 7; i++ ) | 123 | for ( int i = 0; i < 7; i++ ) |
124 | { | 124 | { |
125 | buttonPixUp[i] = NULL; | 125 | buttonPixUp[i] = NULL; |
126 | buttonPixDown[i] = NULL; | 126 | buttonPixDown[i] = NULL; |
127 | } | 127 | } |
128 | 128 | ||
129 | setBackgroundPixmap( *pixBg ); | 129 | setBackgroundPixmap( *pixBg ); |
130 | 130 | ||
131 | currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); | 131 | currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); |
132 | 132 | ||
133 | slider = new QSlider( Qt::Horizontal, this ); | 133 | slider = new QSlider( Qt::Horizontal, this ); |
134 | slider->setMinValue( 0 ); | 134 | slider->setMinValue( 0 ); |
135 | slider->setMaxValue( 1 ); | 135 | slider->setMaxValue( 1 ); |
136 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); | 136 | slider->setBackgroundPixmap( Resource::loadPixmap( backgroundPix ) ); |
137 | slider->setFocusPolicy( QWidget::NoFocus ); | 137 | slider->setFocusPolicy( QWidget::NoFocus ); |
138 | // slider->setGeometry( QRect( 7, 250, 220, 20 ) ); | 138 | // slider->setGeometry( QRect( 7, 250, 220, 20 ) ); |
139 | 139 | ||
140 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 140 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
141 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 141 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
142 | 142 | ||
143 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 143 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
144 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | 144 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); |
145 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | 145 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); |
146 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 146 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
147 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 147 | // connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
148 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 148 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
149 | 149 | ||
150 | // Intialise state | 150 | // Intialise state |
151 | setLength( mediaPlayerState->length() ); | 151 | setLength( mediaPlayerState->length() ); |
152 | setPosition( mediaPlayerState->position() ); | 152 | setPosition( mediaPlayerState->position() ); |
153 | setFullscreen( mediaPlayerState->fullscreen() ); | 153 | setFullscreen( mediaPlayerState->fullscreen() ); |
154 | // setPaused( mediaPlayerState->paused() ); | 154 | // setPaused( mediaPlayerState->paused() ); |
155 | setPlaying( mediaPlayerState->playing() ); | 155 | setPlaying( mediaPlayerState->playing() ); |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | VideoWidget::~VideoWidget() { | 159 | VideoWidget::~VideoWidget() { |
160 | 160 | ||
161 | for ( int i = 0; i < 7; i++ ) | 161 | for ( int i = 0; i < 7; i++ ) |
162 | { | 162 | { |
163 | delete buttonPixUp[i]; | 163 | delete buttonPixUp[i]; |
164 | delete buttonPixDown[i]; | 164 | delete buttonPixDown[i]; |
165 | } | 165 | } |
166 | 166 | ||
167 | delete pixBg; | 167 | delete pixBg; |
168 | delete imgUp; | 168 | delete imgUp; |
169 | delete imgDn; | 169 | delete imgDn; |
170 | delete imgButtonMask; | 170 | delete imgButtonMask; |
171 | for ( int i = 0; i < 7; i++ ) | 171 | for ( int i = 0; i < 7; i++ ) |
172 | { | 172 | { |
173 | delete masks[i]; | 173 | delete masks[i]; |
174 | } | 174 | } |
175 | 175 | ||
176 | // for ( int i = 0; i < 3; i++ ) | 176 | // for ( int i = 0; i < 3; i++ ) |
177 | // delete pixmaps[i]; | 177 | // delete pixmaps[i]; |
178 | // delete currentFrame; | 178 | // delete currentFrame; |
179 | } | 179 | } |
180 | 180 | ||
181 | 181 | ||
182 | static bool videoSliderBeingMoved = FALSE; | 182 | static bool videoSliderBeingMoved = FALSE; |
183 | 183 | ||
184 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { | 184 | QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { |
185 | QPixmap pix( img.width(), img.height() ); | 185 | QPixmap pix( img.width(), img.height() ); |
186 | QPainter p( &pix ); | 186 | QPainter p( &pix ); |
187 | p.drawTiledPixmap( pix.rect(), bg, offset ); | 187 | p.drawTiledPixmap( pix.rect(), bg, offset ); |
188 | p.drawImage( 0, 0, img ); | 188 | p.drawImage( 0, 0, img ); |
189 | return new QPixmap( pix ); | 189 | return new QPixmap( pix ); |
190 | } | 190 | } |
191 | 191 | ||
192 | QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { | 192 | QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { |
193 | QPixmap *pixmap = new QPixmap( pix ); | 193 | QPixmap *pixmap = new QPixmap( pix ); |
194 | pixmap->setMask( mask ); | 194 | pixmap->setMask( mask ); |
195 | return pixmap; | 195 | return pixmap; |
196 | } | 196 | } |
197 | 197 | ||
198 | void VideoWidget::resizeEvent( QResizeEvent * ) { | 198 | void VideoWidget::resizeEvent( QResizeEvent * ) { |
199 | int h = height(); | 199 | int h = height(); |
200 | int w = width(); | 200 | int w = width(); |
201 | //int Vh = 160; | 201 | //int Vh = 160; |
202 | //int Vw = 220; | 202 | //int Vw = 220; |
203 | 203 | ||
204 | slider->setFixedWidth( w - 20 ); | 204 | slider->setFixedWidth( w - 20 ); |
205 | slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); | 205 | slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); |
206 | slider->setBackgroundOrigin( QWidget::ParentOrigin ); | 206 | slider->setBackgroundOrigin( QWidget::ParentOrigin ); |
207 | slider->setFocusPolicy( QWidget::NoFocus ); | 207 | slider->setFocusPolicy( QWidget::NoFocus ); |
208 | slider->setBackgroundPixmap( *pixBg ); | 208 | slider->setBackgroundPixmap( *pixBg ); |
209 | 209 | ||
210 | xoff = 0;// ( imgUp->width() ) / 2; | 210 | xoff = 0;// ( imgUp->width() ) / 2; |
211 | if(w>h) | 211 | if(w>h) |
212 | yoff = 0; | 212 | yoff = 0; |
213 | else | 213 | else |
214 | yoff = 185;//(( Vh - imgUp->height() ) / 2) - 10; | 214 | yoff = 185;//(( Vh - imgUp->height() ) / 2) - 10; |
215 | QPoint p( xoff, yoff ); | 215 | QPoint p( xoff, yoff ); |
216 | 216 | ||
217 | QPixmap *pixUp = combineVImageWithBackground( *imgUp, *pixBg, p ); | 217 | QPixmap *pixUp = combineVImageWithBackground( *imgUp, *pixBg, p ); |
218 | QPixmap *pixDn = combineVImageWithBackground( *imgDn, *pixBg, p ); | 218 | QPixmap *pixDn = combineVImageWithBackground( *imgDn, *pixBg, p ); |
219 | 219 | ||
220 | for ( int i = 0; i < 7; i++ ) | 220 | for ( int i = 0; i < 7; i++ ) |
221 | { | 221 | { |
222 | if ( !masks[i]->isNull() ) | 222 | if ( !masks[i]->isNull() ) |
223 | { | 223 | { |
224 | delete buttonPixUp[i]; | 224 | delete buttonPixUp[i]; |
225 | delete buttonPixDown[i]; | 225 | delete buttonPixDown[i]; |
226 | buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); | 226 | buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); |
227 | buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); | 227 | buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); |
228 | } | 228 | } |
229 | } | 229 | } |
230 | 230 | ||
231 | delete pixUp; | 231 | delete pixUp; |
232 | delete pixDn; | 232 | delete pixDn; |
233 | } | 233 | } |
234 | 234 | ||
235 | 235 | ||
236 | void VideoWidget::sliderPressed() { | 236 | void VideoWidget::sliderPressed() { |
237 | videoSliderBeingMoved = TRUE; | 237 | videoSliderBeingMoved = TRUE; |
238 | } | 238 | } |
239 | 239 | ||
240 | 240 | ||
241 | void VideoWidget::sliderReleased() { | 241 | void VideoWidget::sliderReleased() { |
242 | videoSliderBeingMoved = FALSE; | 242 | videoSliderBeingMoved = FALSE; |
243 | if ( slider->width() == 0 ) | 243 | if ( slider->width() == 0 ) |
244 | return; | 244 | return; |
245 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 245 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
246 | mediaPlayerState->setPosition( val ); | 246 | mediaPlayerState->setPosition( val ); |
247 | } | 247 | } |
248 | 248 | ||
249 | 249 | ||
250 | void VideoWidget::setPosition( long i ) { | 250 | void VideoWidget::setPosition( long i ) { |
251 | updateSlider( i, mediaPlayerState->length() ); | 251 | updateSlider( i, mediaPlayerState->length() ); |
252 | } | 252 | } |
253 | 253 | ||
254 | 254 | ||
255 | void VideoWidget::setLength( long max ) { | 255 | void VideoWidget::setLength( long max ) { |
256 | updateSlider( mediaPlayerState->position(), max ); | 256 | updateSlider( mediaPlayerState->position(), max ); |
257 | } | 257 | } |
258 | 258 | ||
259 | 259 | ||
260 | void VideoWidget::setView( char view ) { | 260 | void VideoWidget::setView( char view ) { |
261 | if ( view == 'v' ) | 261 | if ( view == 'v' ) |
262 | { | 262 | { |
263 | makeVisible(); | 263 | makeVisible(); |
264 | } | 264 | } |
265 | else | 265 | else |
266 | { | 266 | { |
267 | // Effectively blank the view next time we show it so it looks nicer | 267 | // Effectively blank the view next time we show it so it looks nicer |
268 | scaledWidth = 0; | 268 | scaledWidth = 0; |
269 | scaledHeight = 0; | 269 | scaledHeight = 0; |
270 | hide(); | 270 | hide(); |
271 | } | 271 | } |
272 | } | 272 | } |
273 | 273 | ||
274 | 274 | ||
275 | void VideoWidget::updateSlider( long i, long max ) { | 275 | void VideoWidget::updateSlider( long i, long max ) { |
276 | // Will flicker too much if we don't do this | 276 | // Will flicker too much if we don't do this |
277 | if ( max == 0 ) | 277 | if ( max == 0 ) |
278 | return; | 278 | return; |
279 | int width = slider->width(); | 279 | int width = slider->width(); |
280 | int val = int((double)i * width / max); | 280 | int val = int((double)i * width / max); |
281 | if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) | 281 | if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) |
282 | { | 282 | { |
283 | if ( slider->value() != val ) | 283 | if ( slider->value() != val ) |
284 | slider->setValue( val ); | 284 | slider->setValue( val ); |
285 | if ( slider->maxValue() != width ) | 285 | if ( slider->maxValue() != width ) |
286 | slider->setMaxValue( width ); | 286 | slider->setMaxValue( width ); |
287 | } | 287 | } |
288 | } | 288 | } |
289 | 289 | ||
290 | 290 | ||
291 | void VideoWidget::setToggleButton( int i, bool down ) { | 291 | void VideoWidget::setToggleButton( int i, bool down ) { |
292 | if ( down != videoButtons[i].isDown ) | 292 | if ( down != videoButtons[i].isDown ) |
293 | toggleButton( i ); | 293 | toggleButton( i ); |
294 | } | 294 | } |
295 | 295 | ||
296 | 296 | ||
297 | void VideoWidget::toggleButton( int i ) { | 297 | void VideoWidget::toggleButton( int i ) { |
298 | videoButtons[i].isDown = !videoButtons[i].isDown; | 298 | videoButtons[i].isDown = !videoButtons[i].isDown; |
299 | QPainter p(this); | 299 | QPainter p(this); |
300 | paintButton ( &p, i ); | 300 | paintButton ( &p, i ); |
301 | } | 301 | } |
302 | 302 | ||
303 | 303 | ||
304 | void VideoWidget::paintButton( QPainter *p, int i ) { | 304 | void VideoWidget::paintButton( QPainter *p, int i ) { |
305 | if ( videoButtons[i].isDown ) | 305 | if ( videoButtons[i].isDown ) |
306 | { | 306 | { |
307 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); | 307 | p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); |
308 | } | 308 | } |
309 | else | 309 | else |
310 | { | 310 | { |
311 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); | 311 | p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); |
312 | } | 312 | } |
313 | } | 313 | } |
314 | 314 | ||
315 | 315 | ||
316 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { | 316 | void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { |
317 | for ( int i = 0; i < numVButtons; i++ ) { | 317 | for ( int i = 0; i < numVButtons; i++ ) { |
318 | if ( event->state() == QMouseEvent::LeftButton ) { | 318 | if ( event->state() == QMouseEvent::LeftButton ) { |
319 | // The test to see if the mouse click is inside the button or not | 319 | // The test to see if the mouse click is inside the button or not |
320 | int x = event->pos().x() - xoff; | 320 | int x = event->pos().x() - xoff; |
321 | int y = event->pos().y() - yoff; | 321 | int y = event->pos().y() - yoff; |
322 | 322 | ||
323 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() | 323 | bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() |
324 | && y < imgButtonMask->height() | 324 | && y < imgButtonMask->height() |
325 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); | 325 | && imgButtonMask->pixelIndex( x, y ) == i + 1 ); |
326 | 326 | ||
327 | if ( isOnButton && !videoButtons[i].isHeld ) { | 327 | if ( isOnButton && !videoButtons[i].isHeld ) { |
328 | videoButtons[i].isHeld = TRUE; | 328 | videoButtons[i].isHeld = TRUE; |
329 | toggleButton(i); | 329 | toggleButton(i); |
330 | 330 | ||
331 | switch (i) { | 331 | switch (i) { |
332 | case VideoVolUp: | 332 | case VideoVolUp: |
333 | emit moreClicked(); | 333 | emit moreClicked(); |
334 | return; | 334 | return; |
335 | case VideoVolDown: | 335 | case VideoVolDown: |
336 | emit lessClicked(); | 336 | emit lessClicked(); |
337 | return; | 337 | return; |
338 | } | 338 | } |
339 | } else if ( !isOnButton && videoButtons[i].isHeld ) { | 339 | } else if ( !isOnButton && videoButtons[i].isHeld ) { |
340 | videoButtons[i].isHeld = FALSE; | 340 | videoButtons[i].isHeld = FALSE; |
341 | toggleButton(i); | 341 | toggleButton(i); |
342 | } | 342 | } |
343 | } else { | 343 | } else { |
344 | 344 | ||
345 | if ( videoButtons[i].isHeld ) { | 345 | if ( videoButtons[i].isHeld ) { |
346 | videoButtons[i].isHeld = FALSE; | 346 | videoButtons[i].isHeld = FALSE; |
347 | if ( !videoButtons[i].isToggle ) { | 347 | if ( !videoButtons[i].isToggle ) { |
348 | setToggleButton( i, FALSE ); | 348 | setToggleButton( i, FALSE ); |
349 | } | 349 | } |
350 | 350 | ||
351 | switch(i) { | 351 | switch(i) { |
352 | 352 | ||
353 | case VideoPlay: { | 353 | case VideoPlay: { |
354 | qDebug("play"); | 354 | // qDebug("play"); |
355 | if( !mediaPlayerState->playing()) { | 355 | if( !mediaPlayerState->playing()) { |
356 | mediaPlayerState->setPlaying( true); | 356 | mediaPlayerState->setPlaying( true); |
357 | setToggleButton( i-1, false ); | 357 | setToggleButton( i-1, false ); |
358 | setToggleButton( i, false ); | 358 | setToggleButton( i, false ); |
359 | return; | 359 | return; |
360 | } | 360 | } |
361 | if( mediaPlayerState->isPaused ) { | 361 | if( mediaPlayerState->isPaused ) { |
362 | qDebug("isPaused"); | 362 | // qDebug("isPaused"); |
363 | setToggleButton( i, FALSE ); | 363 | setToggleButton( i, FALSE ); |
364 | mediaPlayerState->setPaused( FALSE ); | 364 | mediaPlayerState->setPaused( FALSE ); |
365 | return; | 365 | return; |
366 | } else if( !mediaPlayerState->isPaused ) { | 366 | } else if( !mediaPlayerState->isPaused ) { |
367 | qDebug("is not paused"); | 367 | // qDebug("is not paused"); |
368 | setToggleButton( i, TRUE ); | 368 | setToggleButton( i, TRUE ); |
369 | mediaPlayerState->setPaused( TRUE ); | 369 | mediaPlayerState->setPaused( TRUE ); |
370 | return; | 370 | return; |
371 | } else { | 371 | } else { |
372 | return; | 372 | return; |
373 | } | 373 | } |
374 | } | 374 | } |
375 | 375 | ||
376 | case VideoStop: qDebug("stop"); mediaPlayerState->setPlaying( FALSE ); setToggleButton( i+1, true); setToggleButton( i, true ); return; | 376 | case VideoStop: mediaPlayerState->setPlaying( FALSE ); setToggleButton( i+1, true); setToggleButton( i, true ); return; |
377 | case VideoNext: mediaPlayerState->setNext(); return; | 377 | case VideoNext: mediaPlayerState->setNext(); return; |
378 | case VideoPrevious: mediaPlayerState->setPrev(); return; | 378 | case VideoPrevious: mediaPlayerState->setPrev(); return; |
379 | case VideoVolUp: emit moreReleased(); return; | 379 | case VideoVolUp: emit moreReleased(); return; |
380 | case VideoVolDown: emit lessReleased(); return; | 380 | case VideoVolDown: emit lessReleased(); return; |
381 | case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; | 381 | case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; |
382 | } | 382 | } |
383 | } | 383 | } |
384 | } | 384 | } |
385 | } | 385 | } |
386 | } | 386 | } |
387 | 387 | ||
388 | 388 | ||
389 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { | 389 | void VideoWidget::mousePressEvent( QMouseEvent *event ) { |
390 | mouseMoveEvent( event ); | 390 | mouseMoveEvent( event ); |
391 | } | 391 | } |
392 | 392 | ||
393 | 393 | ||
394 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { | 394 | void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { |
395 | if ( mediaPlayerState->fullscreen() ) | 395 | if ( mediaPlayerState->fullscreen() ) |
396 | { | 396 | { |
397 | mediaPlayerState->setFullscreen( FALSE ); | 397 | mediaPlayerState->setFullscreen( FALSE ); |
398 | makeVisible(); | 398 | makeVisible(); |
399 | } | 399 | } |
400 | mouseMoveEvent( event ); | 400 | mouseMoveEvent( event ); |
401 | // } | 401 | // } |
402 | } | 402 | } |
403 | 403 | ||
404 | 404 | ||
405 | void VideoWidget::makeVisible() { | 405 | void VideoWidget::makeVisible() { |
406 | if ( mediaPlayerState->fullscreen() ) | 406 | if ( mediaPlayerState->fullscreen() ) |
407 | { | 407 | { |
408 | setBackgroundMode( QWidget::NoBackground ); | 408 | setBackgroundMode( QWidget::NoBackground ); |
409 | showFullScreen(); | 409 | showFullScreen(); |
410 | resize( qApp->desktop()->size() ); | 410 | resize( qApp->desktop()->size() ); |
411 | slider->hide(); | 411 | slider->hide(); |
412 | } | 412 | } |
413 | else | 413 | else |
414 | { | 414 | { |
415 | setBackgroundPixmap( *pixBg ); | 415 | setBackgroundPixmap( *pixBg ); |
416 | showNormal(); | 416 | showNormal(); |
417 | showMaximized(); | 417 | showMaximized(); |
418 | slider->show(); | 418 | slider->show(); |
419 | } | 419 | } |
420 | } | 420 | } |
421 | 421 | ||
422 | 422 | ||
423 | void VideoWidget::paintEvent( QPaintEvent * pe) { | 423 | void VideoWidget::paintEvent( QPaintEvent * pe) { |
424 | QPainter p( this ); | 424 | QPainter p( this ); |
425 | 425 | ||
426 | if ( mediaPlayerState->fullscreen() ) { | 426 | if ( mediaPlayerState->fullscreen() ) { |
427 | // Clear the background | 427 | // Clear the background |
428 | p.setBrush( QBrush( Qt::black ) ); | 428 | p.setBrush( QBrush( Qt::black ) ); |
429 | p.drawRect( rect() ); | 429 | p.drawRect( rect() ); |
430 | } else { | 430 | } else { |
431 | if ( !pe->erased() ) { | 431 | if ( !pe->erased() ) { |
432 | // Combine with background and double buffer | 432 | // Combine with background and double buffer |
433 | QPixmap pix( pe->rect().size() ); | 433 | QPixmap pix( pe->rect().size() ); |
434 | QPainter p( &pix ); | 434 | QPainter p( &pix ); |
435 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); | 435 | p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); |
436 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); | 436 | p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); |
437 | for ( int i = 0; i < numVButtons; i++ ) { | 437 | for ( int i = 0; i < numVButtons; i++ ) { |
438 | paintButton( &p, i ); | 438 | paintButton( &p, i ); |
439 | } | 439 | } |
440 | QPainter p2( this ); | 440 | QPainter p2( this ); |
441 | p2.drawPixmap( pe->rect().topLeft(), pix ); | 441 | p2.drawPixmap( pe->rect().topLeft(), pix ); |
442 | } else { | 442 | } else { |
443 | QPainter p( this ); | 443 | QPainter p( this ); |
444 | for ( int i = 0; i < numVButtons; i++ ) | 444 | for ( int i = 0; i < numVButtons; i++ ) |
445 | paintButton( &p, i ); | 445 | paintButton( &p, i ); |
446 | } | 446 | } |
447 | slider->repaint( TRUE ); | 447 | slider->repaint( TRUE ); |
448 | } | 448 | } |
449 | } | 449 | } |
450 | 450 | ||
451 | 451 | ||
452 | void VideoWidget::closeEvent( QCloseEvent* ) { | 452 | void VideoWidget::closeEvent( QCloseEvent* ) { |
453 | mediaPlayerState->setList(); | 453 | mediaPlayerState->setList(); |
454 | } | 454 | } |
455 | 455 | ||
456 | 456 | ||
457 | bool VideoWidget::playVideo() { | 457 | bool VideoWidget::playVideo() { |
458 | bool result = FALSE; | 458 | bool result = FALSE; |
459 | // qDebug("<<<<<<<<<<<<<<<< play video"); | 459 | // qDebug("<<<<<<<<<<<<<<<< play video"); |
460 | int stream = 0; | 460 | int stream = 0; |
461 | 461 | ||
462 | int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); | 462 | int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); |
463 | int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); | 463 | int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); |
464 | int dd = QPixmap::defaultDepth(); | 464 | int dd = QPixmap::defaultDepth(); |
465 | int w = height(); | 465 | int w = height(); |
466 | int h = width(); | 466 | int h = width(); |
467 | 467 | ||
468 | ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; | 468 | ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; |
469 | 469 | ||
470 | if ( mediaPlayerState->fullscreen() ) | 470 | if ( mediaPlayerState->fullscreen() ) |
471 | { | 471 | { |
472 | #ifdef USE_DIRECT_PAINTER | 472 | #ifdef USE_DIRECT_PAINTER |
473 | QDirectPainter p(this); | 473 | QDirectPainter p(this); |
474 | 474 | ||
475 | if ( ( qt_screen->transformOrientation() == 3 ) && | 475 | if ( ( qt_screen->transformOrientation() == 3 ) && |
476 | ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) | 476 | ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) |
477 | { | 477 | { |
478 | 478 | ||
479 | w = 320; | 479 | w = 320; |
480 | h = 240; | 480 | h = 240; |
481 | 481 | ||
482 | if ( mediaPlayerState->scaled() ) | 482 | if ( mediaPlayerState->scaled() ) |
483 | { | 483 | { |
484 | // maintain aspect ratio | 484 | // maintain aspect ratio |
485 | if ( w * sh > sw * h ) | 485 | if ( w * sh > sw * h ) |
486 | w = sw * h / sh; | 486 | w = sw * h / sh; |
487 | else | 487 | else |
488 | h = sh * w / sw; | 488 | h = sh * w / sw; |
489 | } | 489 | } |
490 | else | 490 | else |
491 | { | 491 | { |
492 | w = sw; | 492 | w = sw; |
493 | h = sh; | 493 | h = sh; |
494 | } | 494 | } |
495 | 495 | ||
496 | w--; // we can't allow libmpeg to overwrite. | 496 | w--; // we can't allow libmpeg to overwrite. |
497 | QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); | 497 | QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); |
498 | 498 | ||
499 | int ox = roff.x() - height() + 2 + (height() - w) / 2; | 499 | int ox = roff.x() - height() + 2 + (height() - w) / 2; |
500 | int oy = roff.y() + (width() - h) / 2; | 500 | int oy = roff.y() + (width() - h) / 2; |
501 | int sx = 0, sy = 0; | 501 | int sx = 0, sy = 0; |
502 | 502 | ||
503 | uchar* fp = p.frameBuffer() + p.lineStep() * oy; | 503 | uchar* fp = p.frameBuffer() + p.lineStep() * oy; |
504 | fp += dd * ox / 8; | 504 | fp += dd * ox / 8; |
505 | uchar **jt = new uchar*[h]; | 505 | uchar **jt = new uchar*[h]; |
506 | 506 | ||
507 | for ( int i = h; i; i-- ) | 507 | for ( int i = h; i; i-- ) |
508 | { | 508 | { |
509 | jt[h - i] = fp; | 509 | jt[h - i] = fp; |
510 | fp += p.lineStep(); | 510 | fp += p.lineStep(); |
511 | } | 511 | } |
512 | 512 | ||
513 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; | 513 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; |
514 | 514 | ||
515 | delete [] jt; | 515 | delete [] jt; |
516 | } | 516 | } |
517 | else | 517 | else |
518 | { | 518 | { |
519 | #endif | 519 | #endif |
520 | QPainter p(this); | 520 | QPainter p(this); |
521 | 521 | ||
522 | w = 320; | 522 | w = 320; |
523 | h = 240; | 523 | h = 240; |
524 | 524 | ||
525 | if ( mediaPlayerState->scaled() ) | 525 | if ( mediaPlayerState->scaled() ) |
526 | { | 526 | { |
527 | // maintain aspect ratio | 527 | // maintain aspect ratio |
528 | if ( w * sh > sw * h ) | 528 | if ( w * sh > sw * h ) |
529 | w = sw * h / sh; | 529 | w = sw * h / sh; |
530 | else | 530 | else |
531 | h = sh * w / sw; | 531 | h = sh * w / sw; |
532 | } | 532 | } |
533 | else | 533 | else |
534 | { | 534 | { |
535 | w = sw; | 535 | w = sw; |
536 | h = sh; | 536 | h = sh; |
537 | } | 537 | } |
538 | 538 | ||
539 | int bytes = ( dd == 16 ) ? 2 : 4; | 539 | int bytes = ( dd == 16 ) ? 2 : 4; |
540 | QImage tempFrame( w, h, bytes << 3 ); | 540 | QImage tempFrame( w, h, bytes << 3 ); |
541 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), | 541 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), |
542 | 0, 0, sw, sh, w, h, format, 0) == 0; | 542 | 0, 0, sw, sh, w, h, format, 0) == 0; |
543 | 543 | ||
544 | if ( result && mediaPlayerState->fullscreen() ) | 544 | if ( result && mediaPlayerState->fullscreen() ) |
545 | { | 545 | { |
546 | 546 | ||
547 | int rw = h, rh = w; | 547 | int rw = h, rh = w; |
548 | QImage rotatedFrame( rw, rh, bytes << 3 ); | 548 | QImage rotatedFrame( rw, rh, bytes << 3 ); |
549 | 549 | ||
550 | ushort* in = (ushort*)tempFrame.bits(); | 550 | ushort* in = (ushort*)tempFrame.bits(); |
551 | ushort* out = (ushort*)rotatedFrame.bits(); | 551 | ushort* out = (ushort*)rotatedFrame.bits(); |
552 | int spl = rotatedFrame.bytesPerLine() / bytes; | 552 | int spl = rotatedFrame.bytesPerLine() / bytes; |
553 | 553 | ||
554 | for (int x=0; x<h; x++) | 554 | for (int x=0; x<h; x++) |
555 | { | 555 | { |
556 | if ( bytes == 2 ) | 556 | if ( bytes == 2 ) |
557 | { | 557 | { |
558 | ushort* lout = out++ + (w - 1)*spl; | 558 | ushort* lout = out++ + (w - 1)*spl; |
559 | for (int y=0; y<w; y++) { | 559 | for (int y=0; y<w; y++) { |
560 | *lout=*in++; | 560 | *lout=*in++; |
561 | lout-=spl; | 561 | lout-=spl; |
562 | } | 562 | } |
563 | } | 563 | } |
564 | else | 564 | else |
565 | { | 565 | { |
566 | ulong* lout = ((ulong *)out)++ + (w - 1)*spl; | 566 | ulong* lout = ((ulong *)out)++ + (w - 1)*spl; |
567 | for (int y=0; y<w; y++) | 567 | for (int y=0; y<w; y++) |
568 | { | 568 | { |
569 | *lout=*((ulong*)in)++; | 569 | *lout=*((ulong*)in)++; |
570 | lout-=spl; | 570 | lout-=spl; |
571 | } | 571 | } |
572 | } | 572 | } |
573 | } | 573 | } |
574 | 574 | ||
575 | p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); | 575 | p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); |
576 | } | 576 | } |
577 | #ifdef USE_DIRECT_PAINTER | 577 | #ifdef USE_DIRECT_PAINTER |
578 | } | 578 | } |
579 | #endif | 579 | #endif |
580 | } | 580 | } |
581 | else | 581 | else |
582 | { | 582 | { |
583 | 583 | ||
584 | w = 220; | 584 | w = 220; |
585 | h = 160; | 585 | h = 160; |
586 | 586 | ||
587 | // maintain aspect ratio | 587 | // maintain aspect ratio |
588 | if ( w * sh > sw * h ) | 588 | if ( w * sh > sw * h ) |
589 | w = sw * h / sh; | 589 | w = sw * h / sh; |
590 | else | 590 | else |
591 | h = sh * w / sw; | 591 | h = sh * w / sw; |
592 | 592 | ||
593 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; | 593 | result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; |
594 | 594 | ||
595 | QPainter p( this ); | 595 | QPainter p( this ); |
596 | int deskW = qApp->desktop()->width(); | 596 | int deskW = qApp->desktop()->width(); |
597 | // Image changed size, therefore need to blank the possibly unpainted regions first | 597 | // Image changed size, therefore need to blank the possibly unpainted regions first |
598 | if ( scaledWidth != w || scaledHeight != h ) | 598 | if ( scaledWidth != w || scaledHeight != h ) |
599 | { | 599 | { |
600 | p.setBrush( QBrush( Qt::black ) ); | 600 | p.setBrush( QBrush( Qt::black ) ); |
601 | p.drawRect( ( deskW -scaledWidth)/2, 20, scaledWidth, 160 ); | 601 | p.drawRect( ( deskW -scaledWidth)/2, 20, scaledWidth, 160 ); |
602 | } | 602 | } |
603 | 603 | ||
604 | scaledWidth = w; | 604 | scaledWidth = w; |
605 | scaledHeight = h; | 605 | scaledHeight = h; |
606 | 606 | ||
607 | if ( result ) | 607 | if ( result ) |
608 | { | 608 | { |
609 | p.drawImage( (deskW - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); | 609 | p.drawImage( (deskW - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); |
610 | } | 610 | } |
611 | 611 | ||
612 | } | 612 | } |
613 | 613 | ||
614 | return result; | 614 | return result; |
615 | } | 615 | } |
616 | 616 | ||
617 | 617 | ||
618 | 618 | ||
619 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) | 619 | void VideoWidget::keyReleaseEvent( QKeyEvent *e) |
620 | { | 620 | { |
621 | switch ( e->key() ) | 621 | switch ( e->key() ) |
622 | { | 622 | { |
623 | ////////////////////////////// Zaurus keys | 623 | ////////////////////////////// Zaurus keys |
624 | case Key_Home: | 624 | case Key_Home: |
625 | break; | 625 | break; |
626 | case Key_F9: //activity | 626 | case Key_F9: //activity |
627 | break; | 627 | break; |
628 | case Key_F10: //contacts | 628 | case Key_F10: //contacts |
629 | // hide(); | 629 | // hide(); |
630 | break; | 630 | break; |
631 | case Key_F11: //menu | 631 | case Key_F11: //menu |
632 | break; | 632 | break; |
633 | case Key_F12: //home | 633 | case Key_F12: //home |
634 | break; | 634 | break; |
635 | case Key_F13: //mail | 635 | case Key_F13: //mail |
636 | break; | 636 | break; |
637 | case Key_Space: | 637 | case Key_Space: |
638 | { | 638 | { |
639 | if(mediaPlayerState->playing()) | 639 | if(mediaPlayerState->playing()) |
640 | { | 640 | { |
641 | mediaPlayerState->setPlaying(FALSE); | 641 | mediaPlayerState->setPlaying(FALSE); |
642 | } | 642 | } |
643 | else | 643 | else |
644 | { | 644 | { |
645 | mediaPlayerState->setPlaying(TRUE); | 645 | mediaPlayerState->setPlaying(TRUE); |
646 | } | 646 | } |
647 | } | 647 | } |
648 | break; | 648 | break; |
649 | case Key_Down: | 649 | case Key_Down: |
650 | // toggleButton(6); | 650 | // toggleButton(6); |
651 | // emit lessClicked(); | 651 | // emit lessClicked(); |
652 | // emit lessReleased(); | 652 | // emit lessReleased(); |
653 | // toggleButton(6); | 653 | // toggleButton(6); |
654 | break; | 654 | break; |
655 | case Key_Up: | 655 | case Key_Up: |
656 | // toggleButton(5); | 656 | // toggleButton(5); |
657 | // emit moreClicked(); | 657 | // emit moreClicked(); |
658 | // emit moreReleased(); | 658 | // emit moreReleased(); |
659 | // toggleButton(5); | 659 | // toggleButton(5); |
660 | break; | 660 | break; |
661 | case Key_Right: | 661 | case Key_Right: |
662 | mediaPlayerState->setNext(); | 662 | mediaPlayerState->setNext(); |
663 | break; | 663 | break; |
664 | case Key_Left: | 664 | case Key_Left: |
665 | mediaPlayerState->setPrev(); | 665 | mediaPlayerState->setPrev(); |
666 | break; | 666 | break; |
667 | case Key_Escape: | 667 | case Key_Escape: |
668 | break; | 668 | break; |
669 | 669 | ||
670 | }; | 670 | }; |
671 | } | 671 | } |