author | llornkcor <llornkcor> | 2002-04-21 03:26:09 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-04-21 03:26:09 (UTC) |
commit | 6818807a46b80774de328b4c3001d4bc9d788666 (patch) (unidiff) | |
tree | 1bede7ebbb324058b664330abf481f7afb25eb73 | |
parent | 1c459273c0e9e387fd5fe2e2c05bef4db5bce115 (diff) | |
download | opie-6818807a46b80774de328b4c3001d4bc9d788666.zip opie-6818807a46b80774de328b4c3001d4bc9d788666.tar.gz opie-6818807a46b80774de328b4c3001d4bc9d788666.tar.bz2 |
fixed when playing stream, slider moved and stopped stream when it reached the end
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.cpp | 7 | ||||
-rw-r--r-- | core/multimedia/opieplayer/audiowidget.h | 20 | ||||
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol.cpp | 18 | ||||
-rw-r--r-- | core/multimedia/opieplayer/mediaplayerstate.h | 2 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 1 |
5 files changed, 28 insertions, 20 deletions
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp index 3212001..20345b7 100644 --- a/core/multimedia/opieplayer/audiowidget.cpp +++ b/core/multimedia/opieplayer/audiowidget.cpp | |||
@@ -1,338 +1,341 @@ | |||
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 | 22 | ||
23 | #include <qwidget.h> | 23 | #include <qwidget.h> |
24 | #include <qpixmap.h> | 24 | #include <qpixmap.h> |
25 | #include <qbutton.h> | 25 | #include <qbutton.h> |
26 | #include <qpainter.h> | 26 | #include <qpainter.h> |
27 | #include <qframe.h> | 27 | #include <qframe.h> |
28 | 28 | ||
29 | #include "audiowidget.h" | 29 | #include "audiowidget.h" |
30 | #include "mediaplayerstate.h" | 30 | #include "mediaplayerstate.h" |
31 | 31 | ||
32 | extern MediaPlayerState *mediaPlayerState; | 32 | extern MediaPlayerState *mediaPlayerState; |
33 | 33 | ||
34 | 34 | ||
35 | static const int xo = -2; // movable x offset | 35 | static const int xo = -2; // movable x offset |
36 | static const int yo = 22; // movable y offset | 36 | static const int yo = 22; // movable y offset |
37 | 37 | ||
38 | 38 | ||
39 | struct MediaButton { | 39 | struct MediaButton { |
40 | int xPos, yPos; | 40 | int xPos, yPos; |
41 | int color; | 41 | int color; |
42 | bool isToggle, isBig, isHeld, isDown; | 42 | bool isToggle, isBig, isHeld, isDown; |
43 | }; | 43 | }; |
44 | 44 | ||
45 | 45 | ||
46 | // Layout information for the audioButtons (and if it is a toggle button or not) | 46 | // Layout information for the audioButtons (and if it is a toggle button or not) |
47 | MediaButton audioButtons[] = { | 47 | MediaButton audioButtons[] = { |
48 | { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play | 48 | { 3*30-15+xo, 3*30-13+yo, 0, TRUE, TRUE, FALSE, FALSE }, // play |
49 | { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop | 49 | { 1*30+xo, 5*30+yo, 2, FALSE, FALSE, FALSE, FALSE }, // stop |
50 | { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause | 50 | { 5*30+xo, 5*30+yo, 2, TRUE, FALSE, FALSE, FALSE }, // pause |
51 | { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next | 51 | { 6*30-5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // next |
52 | { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous | 52 | { 0*30+5+xo, 3*30+yo, 1, FALSE, FALSE, FALSE, FALSE }, // previous |
53 | { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up | 53 | { 3*30+xo, 0*30+5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume up |
54 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down | 54 | { 3*30+xo, 6*30-5+yo, 3, FALSE, FALSE, FALSE, FALSE }, // volume down |
55 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop | 55 | { 5*30+xo, 1*30+yo, 0, TRUE, FALSE, FALSE, FALSE }, // repeat/loop |
56 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist | 56 | { 1*30+xo, 1*30+yo, 0, FALSE, FALSE, FALSE, FALSE } // playlist |
57 | }; | 57 | }; |
58 | 58 | ||
59 | 59 | ||
60 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); | 60 | static const int numButtons = (sizeof(audioButtons)/sizeof(MediaButton)); |
61 | 61 | ||
62 | 62 | ||
63 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : | 63 | AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) : |
64 | QWidget( parent, name, f ) | 64 | QWidget( parent, name, f ) |
65 | { | 65 | { |
66 | // QPEApplication::grabKeyboard(); | 66 | // QPEApplication::grabKeyboard(); |
67 | setCaption( tr("OpiePlayer") ); | 67 | setCaption( tr("OpiePlayer") ); |
68 | setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); | 68 | setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); |
69 | pixmaps[0] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsAll" ) ); | 69 | pixmaps[0] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsAll" ) ); |
70 | pixmaps[1] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsBig" ) ); | 70 | pixmaps[1] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaButtonsBig" ) ); |
71 | pixmaps[2] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaControls" ) ); | 71 | pixmaps[2] = new QPixmap( Resource::loadPixmap( "opieplayer/mediaControls" ) ); |
72 | pixmaps[3] = new QPixmap( Resource::loadPixmap( "opieplayer/animatedButton" ) ); | 72 | pixmaps[3] = new QPixmap( Resource::loadPixmap( "opieplayer/animatedButton" ) ); |
73 | 73 | ||
74 | songInfo = new Ticker( this ); | 74 | songInfo = new Ticker( this ); |
75 | songInfo->setFocusPolicy( QWidget::NoFocus ); | 75 | songInfo->setFocusPolicy( QWidget::NoFocus ); |
76 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); | 76 | songInfo->setGeometry( QRect( 7, 3, 220, 20 ) ); |
77 | 77 | ||
78 | slider = new QSlider( Qt::Horizontal, this ); | 78 | slider = new QSlider( Qt::Horizontal, this ); |
79 | slider->setFixedWidth( 220 ); | 79 | slider->setFixedWidth( 220 ); |
80 | slider->setFixedHeight( 20 ); | 80 | slider->setFixedHeight( 20 ); |
81 | slider->setMinValue( 0 ); | 81 | slider->setMinValue( 0 ); |
82 | slider->setMaxValue( 1 ); | 82 | slider->setMaxValue( 1 ); |
83 | slider->setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); | 83 | slider->setBackgroundPixmap( Resource::loadPixmap( "opieplayer/metalFinish" ) ); |
84 | slider->setFocusPolicy( QWidget::NoFocus ); | 84 | slider->setFocusPolicy( QWidget::NoFocus ); |
85 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); | 85 | slider->setGeometry( QRect( 7, 262, 220, 20 ) ); |
86 | 86 | ||
87 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); | 87 | connect( slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); |
88 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); | 88 | connect( slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); |
89 | 89 | ||
90 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); | 90 | connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); |
91 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | ||
92 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | ||
93 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); | 91 | connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); |
94 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); | 92 | connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); |
95 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); | 93 | connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); |
96 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); | 94 | connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); |
97 | 95 | ||
96 | if( !mediaPlayerState->isStreaming) { // this stops the slider from being moved, thus | ||
97 | // does not stop stream when it reaches the end | ||
98 | connect( mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); | ||
99 | connect( mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); | ||
100 | } | ||
98 | // Intialise state | 101 | // Intialise state |
99 | setLength( mediaPlayerState->length() ); | 102 | setLength( mediaPlayerState->length() ); |
100 | setPosition( mediaPlayerState->position() ); | 103 | setPosition( mediaPlayerState->position() ); |
101 | setLooping( mediaPlayerState->fullscreen() ); | 104 | setLooping( mediaPlayerState->fullscreen() ); |
102 | setPaused( mediaPlayerState->paused() ); | 105 | setPaused( mediaPlayerState->paused() ); |
103 | setPlaying( mediaPlayerState->playing() ); | 106 | setPlaying( mediaPlayerState->playing() ); |
104 | 107 | ||
105 | } | 108 | } |
106 | 109 | ||
107 | 110 | ||
108 | AudioWidget::~AudioWidget() { | 111 | AudioWidget::~AudioWidget() { |
109 | for ( int i = 0; i < 4; i++ ) | 112 | for ( int i = 0; i < 4; i++ ) |
110 | delete pixmaps[i]; | 113 | delete pixmaps[i]; |
111 | } | 114 | } |
112 | 115 | ||
113 | 116 | ||
114 | static bool audioSliderBeingMoved = FALSE; | 117 | static bool audioSliderBeingMoved = FALSE; |
115 | 118 | ||
116 | 119 | ||
117 | void AudioWidget::sliderPressed() { | 120 | void AudioWidget::sliderPressed() { |
118 | audioSliderBeingMoved = TRUE; | 121 | audioSliderBeingMoved = TRUE; |
119 | } | 122 | } |
120 | 123 | ||
121 | 124 | ||
122 | void AudioWidget::sliderReleased() { | 125 | void AudioWidget::sliderReleased() { |
123 | audioSliderBeingMoved = FALSE; | 126 | audioSliderBeingMoved = FALSE; |
124 | if ( slider->width() == 0 ) | 127 | if ( slider->width() == 0 ) |
125 | return; | 128 | return; |
126 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); | 129 | long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); |
127 | mediaPlayerState->setPosition( val ); | 130 | mediaPlayerState->setPosition( val ); |
128 | } | 131 | } |
129 | 132 | ||
130 | 133 | ||
131 | void AudioWidget::setPosition( long i ) { | 134 | void AudioWidget::setPosition( long i ) { |
132 | updateSlider( i, mediaPlayerState->length() ); | 135 | updateSlider( i, mediaPlayerState->length() ); |
133 | } | 136 | } |
134 | 137 | ||
135 | 138 | ||
136 | void AudioWidget::setLength( long max ) { | 139 | void AudioWidget::setLength( long max ) { |
137 | updateSlider( mediaPlayerState->position(), max ); | 140 | updateSlider( mediaPlayerState->position(), max ); |
138 | } | 141 | } |
139 | 142 | ||
140 | 143 | ||
141 | void AudioWidget::setView( char view ) { | 144 | void AudioWidget::setView( char view ) { |
142 | if ( view == 'a' ) { | 145 | if ( view == 'a' ) { |
143 | startTimer( 150 ); | 146 | startTimer( 150 ); |
144 | showMaximized(); | 147 | showMaximized(); |
145 | } else { | 148 | } else { |
146 | killTimers(); | 149 | killTimers(); |
147 | hide(); | 150 | hide(); |
148 | } | 151 | } |
149 | } | 152 | } |
150 | 153 | ||
151 | 154 | ||
152 | void AudioWidget::updateSlider( long i, long max ) { | 155 | void AudioWidget::updateSlider( long i, long max ) { |
153 | if ( max == 0 ) | 156 | if ( max == 0 ) |
154 | return; | 157 | return; |
155 | // Will flicker too much if we don't do this | 158 | // Will flicker too much if we don't do this |
156 | // Scale to something reasonable | 159 | // Scale to something reasonable |
157 | int width = slider->width(); | 160 | int width = slider->width(); |
158 | int val = int((double)i * width / max); | 161 | int val = int((double)i * width / max); |
159 | if ( !audioSliderBeingMoved ) { | 162 | if ( !audioSliderBeingMoved ) { |
160 | if ( slider->value() != val ) | 163 | if ( slider->value() != val ) |
161 | slider->setValue( val ); | 164 | slider->setValue( val ); |
162 | if ( slider->maxValue() != width ) | 165 | if ( slider->maxValue() != width ) |
163 | slider->setMaxValue( width ); | 166 | slider->setMaxValue( width ); |
164 | } | 167 | } |
165 | } | 168 | } |
166 | 169 | ||
167 | 170 | ||
168 | void AudioWidget::setToggleButton( int i, bool down ) { | 171 | void AudioWidget::setToggleButton( int i, bool down ) { |
169 | if ( down != audioButtons[i].isDown ) | 172 | if ( down != audioButtons[i].isDown ) |
170 | toggleButton( i ); | 173 | toggleButton( i ); |
171 | } | 174 | } |
172 | 175 | ||
173 | 176 | ||
174 | void AudioWidget::toggleButton( int i ) { | 177 | void AudioWidget::toggleButton( int i ) { |
175 | audioButtons[i].isDown = !audioButtons[i].isDown; | 178 | audioButtons[i].isDown = !audioButtons[i].isDown; |
176 | QPainter p(this); | 179 | QPainter p(this); |
177 | paintButton ( &p, i ); | 180 | paintButton ( &p, i ); |
178 | } | 181 | } |
179 | 182 | ||
180 | 183 | ||
181 | void AudioWidget::paintButton( QPainter *p, int i ) { | 184 | void AudioWidget::paintButton( QPainter *p, int i ) { |
182 | int x = audioButtons[i].xPos; | 185 | int x = audioButtons[i].xPos; |
183 | int y = audioButtons[i].yPos; | 186 | int y = audioButtons[i].yPos; |
184 | int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; | 187 | int offset = 22 + 14 * audioButtons[i].isBig + audioButtons[i].isDown; |
185 | int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); | 188 | int buttonSize = 64 + audioButtons[i].isBig * (90 - 64); |
186 | p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); | 189 | p->drawPixmap( x, y, *pixmaps[audioButtons[i].isBig], buttonSize * (audioButtons[i].isDown + 2 * audioButtons[i].color), 0, buttonSize, buttonSize ); |
187 | p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); | 190 | p->drawPixmap( x + offset, y + offset, *pixmaps[2], 18 * i, 0, 18, 18 ); |
188 | } | 191 | } |
189 | 192 | ||
190 | 193 | ||
191 | void AudioWidget::timerEvent( QTimerEvent * ) { | 194 | void AudioWidget::timerEvent( QTimerEvent * ) { |
192 | static int frame = 0; | 195 | static int frame = 0; |
193 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { | 196 | if ( !mediaPlayerState->paused() && audioButtons[ AudioPlay ].isDown ) { |
194 | frame = frame >= 7 ? 0 : frame + 1; | 197 | frame = frame >= 7 ? 0 : frame + 1; |
195 | int x = audioButtons[AudioPlay].xPos; | 198 | int x = audioButtons[AudioPlay].xPos; |
196 | int y = audioButtons[AudioPlay].yPos; | 199 | int y = audioButtons[AudioPlay].yPos; |
197 | QPainter p( this ); | 200 | QPainter p( this ); |
198 | // Optimize to only draw the little bit of the changing images which is different | 201 | // Optimize to only draw the little bit of the changing images which is different |
199 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); | 202 | p.drawPixmap( x + 14, y + 8, *pixmaps[3], 32 * frame, 0, 32, 32 ); |
200 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); | 203 | p.drawPixmap( x + 37, y + 37, *pixmaps[2], 18 * AudioPlay, 0, 6, 3 ); |
201 | } | 204 | } |
202 | } | 205 | } |
203 | 206 | ||
204 | 207 | ||
205 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { | 208 | void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { |
206 | for ( int i = 0; i < numButtons; i++ ) { | 209 | for ( int i = 0; i < numButtons; i++ ) { |
207 | int size = audioButtons[i].isBig; | 210 | int size = audioButtons[i].isBig; |
208 | int x = audioButtons[i].xPos; | 211 | int x = audioButtons[i].xPos; |
209 | int y = audioButtons[i].yPos; | 212 | int y = audioButtons[i].yPos; |
210 | if ( event->state() == QMouseEvent::LeftButton ) { | 213 | if ( event->state() == QMouseEvent::LeftButton ) { |
211 | // The test to see if the mouse click is inside the circular button or not | 214 | // The test to see if the mouse click is inside the circular button or not |
212 | // (compared with the radius squared to avoid a square-root of our distance) | 215 | // (compared with the radius squared to avoid a square-root of our distance) |
213 | int radius = 32 + 13 * size; | 216 | int radius = 32 + 13 * size; |
214 | QPoint center = QPoint( x + radius, y + radius ); | 217 | QPoint center = QPoint( x + radius, y + radius ); |
215 | QPoint dXY = center - event->pos(); | 218 | QPoint dXY = center - event->pos(); |
216 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); | 219 | int dist = dXY.x() * dXY.x() + dXY.y() * dXY.y(); |
217 | bool isOnButton = dist <= (radius * radius); | 220 | bool isOnButton = dist <= (radius * radius); |
218 | // QRect r( x, y, 64 + 22*size, 64 + 22*size ); | 221 | // QRect r( x, y, 64 + 22*size, 64 + 22*size ); |
219 | // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code | 222 | // bool isOnButton = r.contains( event->pos() ); // Rectangular Button code |
220 | if ( isOnButton && !audioButtons[i].isHeld ) { | 223 | if ( isOnButton && !audioButtons[i].isHeld ) { |
221 | audioButtons[i].isHeld = TRUE; | 224 | audioButtons[i].isHeld = TRUE; |
222 | toggleButton(i); | 225 | toggleButton(i); |
223 | qDebug("button toggled1 %d",i); | 226 | qDebug("button toggled1 %d",i); |
224 | switch (i) { | 227 | switch (i) { |
225 | case AudioVolumeUp: emit moreClicked(); return; | 228 | case AudioVolumeUp: emit moreClicked(); return; |
226 | case AudioVolumeDown: emit lessClicked(); return; | 229 | case AudioVolumeDown: emit lessClicked(); return; |
227 | } | 230 | } |
228 | } else if ( !isOnButton && audioButtons[i].isHeld ) { | 231 | } else if ( !isOnButton && audioButtons[i].isHeld ) { |
229 | audioButtons[i].isHeld = FALSE; | 232 | audioButtons[i].isHeld = FALSE; |
230 | toggleButton(i); | 233 | toggleButton(i); |
231 | qDebug("button toggled2 %d",i); | 234 | qDebug("button toggled2 %d",i); |
232 | } | 235 | } |
233 | } else { | 236 | } else { |
234 | if ( audioButtons[i].isHeld ) { | 237 | if ( audioButtons[i].isHeld ) { |
235 | audioButtons[i].isHeld = FALSE; | 238 | audioButtons[i].isHeld = FALSE; |
236 | if ( !audioButtons[i].isToggle ) | 239 | if ( !audioButtons[i].isToggle ) |
237 | setToggleButton( i, FALSE ); | 240 | setToggleButton( i, FALSE ); |
238 | qDebug("button toggled3 %d",i); | 241 | qDebug("button toggled3 %d",i); |
239 | switch (i) { | 242 | switch (i) { |
240 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; | 243 | case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; |
241 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; | 244 | case AudioStop: mediaPlayerState->setPlaying(FALSE); return; |
242 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; | 245 | case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; |
243 | case AudioNext: mediaPlayerState->setNext(); return; | 246 | case AudioNext: mediaPlayerState->setNext(); return; |
244 | case AudioPrevious: mediaPlayerState->setPrev(); return; | 247 | case AudioPrevious: mediaPlayerState->setPrev(); return; |
245 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; | 248 | case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; |
246 | case AudioVolumeUp: emit moreReleased(); return; | 249 | case AudioVolumeUp: emit moreReleased(); return; |
247 | case AudioVolumeDown: emit lessReleased(); return; | 250 | case AudioVolumeDown: emit lessReleased(); return; |
248 | case AudioPlayList: mediaPlayerState->setList(); return; | 251 | case AudioPlayList: mediaPlayerState->setList(); return; |
249 | } | 252 | } |
250 | } | 253 | } |
251 | } | 254 | } |
252 | } | 255 | } |
253 | } | 256 | } |
254 | 257 | ||
255 | 258 | ||
256 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { | 259 | void AudioWidget::mousePressEvent( QMouseEvent *event ) { |
257 | mouseMoveEvent( event ); | 260 | mouseMoveEvent( event ); |
258 | } | 261 | } |
259 | 262 | ||
260 | 263 | ||
261 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { | 264 | void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { |
262 | mouseMoveEvent( event ); | 265 | mouseMoveEvent( event ); |
263 | } | 266 | } |
264 | 267 | ||
265 | 268 | ||
266 | void AudioWidget::showEvent( QShowEvent* ) { | 269 | void AudioWidget::showEvent( QShowEvent* ) { |
267 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); | 270 | QMouseEvent event( QEvent::MouseMove, QPoint( 0, 0 ), 0, 0 ); |
268 | mouseMoveEvent( &event ); | 271 | mouseMoveEvent( &event ); |
269 | } | 272 | } |
270 | 273 | ||
271 | 274 | ||
272 | void AudioWidget::closeEvent( QCloseEvent* ) { | 275 | void AudioWidget::closeEvent( QCloseEvent* ) { |
273 | mediaPlayerState->setList(); | 276 | mediaPlayerState->setList(); |
274 | } | 277 | } |
275 | 278 | ||
276 | 279 | ||
277 | void AudioWidget::paintEvent( QPaintEvent * ) { | 280 | void AudioWidget::paintEvent( QPaintEvent * ) { |
278 | QPainter p( this ); | 281 | QPainter p( this ); |
279 | for ( int i = 0; i < numButtons; i++ ) | 282 | for ( int i = 0; i < numButtons; i++ ) |
280 | paintButton( &p, i ); | 283 | paintButton( &p, i ); |
281 | } | 284 | } |
282 | 285 | ||
283 | 286 | ||
284 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) | 287 | void AudioWidget::keyReleaseEvent( QKeyEvent *e) |
285 | { | 288 | { |
286 | switch ( e->key() ) { | 289 | switch ( e->key() ) { |
287 | ////////////////////////////// Zaurus keys | 290 | ////////////////////////////// Zaurus keys |
288 | case Key_Home: | 291 | case Key_Home: |
289 | break; | 292 | break; |
290 | case Key_F9: //activity | 293 | case Key_F9: //activity |
291 | break; | 294 | break; |
292 | case Key_F10: //contacts | 295 | case Key_F10: //contacts |
293 | break; | 296 | break; |
294 | case Key_F11: //menu | 297 | case Key_F11: //menu |
295 | break; | 298 | break; |
296 | case Key_F12: //home | 299 | case Key_F12: //home |
297 | break; | 300 | break; |
298 | case Key_F13: //mail | 301 | case Key_F13: //mail |
299 | break; | 302 | break; |
300 | case Key_Space: { | 303 | case Key_Space: { |
301 | if(mediaPlayerState->playing()) { | 304 | if(mediaPlayerState->playing()) { |
302 | // toggleButton(1); | 305 | // toggleButton(1); |
303 | mediaPlayerState->setPlaying(FALSE); | 306 | mediaPlayerState->setPlaying(FALSE); |
304 | // toggleButton(1); | 307 | // toggleButton(1); |
305 | } else { | 308 | } else { |
306 | // toggleButton(0); | 309 | // toggleButton(0); |
307 | mediaPlayerState->setPlaying(TRUE); | 310 | mediaPlayerState->setPlaying(TRUE); |
308 | // toggleButton(0); | 311 | // toggleButton(0); |
309 | } | 312 | } |
310 | } | 313 | } |
311 | break; | 314 | break; |
312 | case Key_Down: | 315 | case Key_Down: |
313 | toggleButton(6); | 316 | toggleButton(6); |
314 | emit lessClicked(); | 317 | emit lessClicked(); |
315 | emit lessReleased(); | 318 | emit lessReleased(); |
316 | toggleButton(6); | 319 | toggleButton(6); |
317 | break; | 320 | break; |
318 | case Key_Up: | 321 | case Key_Up: |
319 | toggleButton(5); | 322 | toggleButton(5); |
320 | emit moreClicked(); | 323 | emit moreClicked(); |
321 | emit moreReleased(); | 324 | emit moreReleased(); |
322 | toggleButton(5); | 325 | toggleButton(5); |
323 | break; | 326 | break; |
324 | case Key_Right: | 327 | case Key_Right: |
325 | // toggleButton(3); | 328 | // toggleButton(3); |
326 | mediaPlayerState->setNext(); | 329 | mediaPlayerState->setNext(); |
327 | // toggleButton(3); | 330 | // toggleButton(3); |
328 | break; | 331 | break; |
329 | case Key_Left: | 332 | case Key_Left: |
330 | // toggleButton(4); | 333 | // toggleButton(4); |
331 | mediaPlayerState->setPrev(); | 334 | mediaPlayerState->setPrev(); |
332 | // toggleButton(4); | 335 | // toggleButton(4); |
333 | break; | 336 | break; |
334 | case Key_Escape: | 337 | case Key_Escape: |
335 | break; | 338 | break; |
336 | 339 | ||
337 | }; | 340 | }; |
338 | } | 341 | } |
diff --git a/core/multimedia/opieplayer/audiowidget.h b/core/multimedia/opieplayer/audiowidget.h index d1d72b6..4ffd167 100644 --- a/core/multimedia/opieplayer/audiowidget.h +++ b/core/multimedia/opieplayer/audiowidget.h | |||
@@ -1,145 +1,145 @@ | |||
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 | 20 | ||
21 | #ifndef AUDIO_WIDGET_H | 21 | #ifndef AUDIO_WIDGET_H |
22 | #define AUDIO_WIDGET_H | 22 | #define AUDIO_WIDGET_H |
23 | 23 | ||
24 | #include <qwidget.h> | 24 | #include <qwidget.h> |
25 | #include <qpainter.h> | 25 | #include <qpainter.h> |
26 | #include <qdrawutil.h> | 26 | #include <qdrawutil.h> |
27 | #include <qpixmap.h> | 27 | #include <qpixmap.h> |
28 | #include <qstring.h> | 28 | #include <qstring.h> |
29 | #include <qslider.h> | 29 | #include <qslider.h> |
30 | #include <qframe.h> | 30 | #include <qframe.h> |
31 | 31 | ||
32 | 32 | ||
33 | class QPixmap; | 33 | class QPixmap; |
34 | 34 | ||
35 | 35 | ||
36 | enum AudioButtons { | 36 | enum AudioButtons { |
37 | AudioPlay, | 37 | AudioPlay, |
38 | AudioStop, | 38 | AudioStop, |
39 | AudioPause, | 39 | AudioPause, |
40 | AudioNext, | 40 | AudioNext, |
41 | AudioPrevious, | 41 | AudioPrevious, |
42 | AudioVolumeUp, | 42 | AudioVolumeUp, |
43 | AudioVolumeDown, | 43 | AudioVolumeDown, |
44 | AudioLoop, | 44 | AudioLoop, |
45 | AudioPlayList | 45 | AudioPlayList |
46 | }; | 46 | }; |
47 | 47 | ||
48 | 48 | ||
49 | #define USE_DBLBUF | 49 | #define USE_DBLBUF |
50 | 50 | ||
51 | 51 | ||
52 | class Ticker : public QFrame { | 52 | class Ticker : public QFrame { |
53 | Q_OBJECT | 53 | Q_OBJECT |
54 | public: | 54 | public: |
55 | Ticker( QWidget* parent=0 ) : QFrame( parent ) { | 55 | Ticker( QWidget* parent=0 ) : QFrame( parent ) { |
56 | setFrameStyle( WinPanel | Sunken ); | 56 | setFrameStyle( WinPanel | Sunken ); |
57 | setText( "No Song" ); | 57 | setText( "No Song" ); |
58 | } | 58 | } |
59 | ~Ticker() { } | 59 | ~Ticker() { } |
60 | void setText( const QString& text ) { | 60 | void setText( const QString& text ) { |
61 | pos = 0; // reset it everytime the text is changed | 61 | pos = 0; // reset it everytime the text is changed |
62 | scrollText = text; | 62 | scrollText = text; |
63 | pixelLen = fontMetrics().width( scrollText ); | 63 | pixelLen = fontMetrics().width( scrollText ); |
64 | killTimers(); | 64 | killTimers(); |
65 | if ( pixelLen > width() ) | 65 | if ( pixelLen > width() ) |
66 | startTimer( 50 ); | 66 | startTimer( 50 ); |
67 | update(); | 67 | update(); |
68 | } | 68 | } |
69 | protected: | 69 | protected: |
70 | void timerEvent( QTimerEvent * ) { | 70 | void timerEvent( QTimerEvent * ) { |
71 | pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; | 71 | pos = ( pos + 1 > pixelLen ) ? 0 : pos + 1; |
72 | #ifndef USE_DBLBUF | 72 | #ifndef USE_DBLBUF |
73 | scroll( -1, 0, contentsRect() ); | 73 | scroll( -1, 0, contentsRect() ); |
74 | #else | 74 | #else |
75 | repaint( FALSE ); | 75 | repaint( FALSE ); |
76 | #endif | 76 | #endif |
77 | } | 77 | } |
78 | void drawContents( QPainter *p ) { | 78 | void drawContents( QPainter *p ) { |
79 | #ifndef USE_DBLBUF | 79 | #ifndef USE_DBLBUF |
80 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) | 80 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) |
81 | p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); | 81 | p->drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); |
82 | #else | 82 | #else |
83 | // Double buffering code. | 83 | // Double buffering code. |
84 | // Looks like qvfb makes it look like it flickers but I don't think it really is | 84 | // Looks like qvfb makes it look like it flickers but I don't think it really is |
85 | QPixmap pm( width(), height() ); | 85 | QPixmap pm( width(), height() ); |
86 | pm.fill( colorGroup().base() ); | 86 | pm.fill( colorGroup().base() ); |
87 | QPainter pmp( &pm ); | 87 | QPainter pmp( &pm ); |
88 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) | 88 | for ( int i = 0; i - pos < width() && (i < 1 || pixelLen > width()); i += pixelLen ) |
89 | pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); | 89 | pmp.drawText( i - pos, 0, INT_MAX, height(), AlignVCenter, scrollText ); |
90 | p->drawPixmap( 0, 0, pm ); | 90 | p->drawPixmap( 0, 0, pm ); |
91 | #endif | 91 | #endif |
92 | } | 92 | } |
93 | private: | 93 | private: |
94 | QString scrollText; | 94 | QString scrollText; |
95 | int pos, pixelLen; | 95 | int pos, pixelLen; |
96 | }; | 96 | }; |
97 | 97 | ||
98 | 98 | ||
99 | class AudioWidget : public QWidget { | 99 | class AudioWidget : public QWidget { |
100 | Q_OBJECT | 100 | Q_OBJECT |
101 | public: | 101 | public: |
102 | AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 ); | 102 | AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 ); |
103 | ~AudioWidget(); | 103 | ~AudioWidget(); |
104 | void setTickerText( const QString &text ) { songInfo->setText( text ); } | 104 | void setTickerText( const QString &text ) { songInfo->setText( text ); } |
105 | 105 | bool isStreaming; | |
106 | public slots: | 106 | public slots: |
107 | void updateSlider( long, long ); | 107 | void updateSlider( long, long ); |
108 | void sliderPressed( ); | 108 | void sliderPressed( ); |
109 | void sliderReleased( ); | 109 | void sliderReleased( ); |
110 | void setPaused( bool b) { setToggleButton( AudioPause, b ); } | 110 | void setPaused( bool b) { setToggleButton( AudioPause, b ); } |
111 | void setLooping( bool b) { setToggleButton( AudioLoop, b ); } | 111 | void setLooping( bool b) { setToggleButton( AudioLoop, b ); } |
112 | void setPlaying( bool b) { setToggleButton( AudioPlay, b ); } | 112 | void setPlaying( bool b) { setToggleButton( AudioPlay, b ); } |
113 | void setPosition( long ); | 113 | void setPosition( long ); |
114 | void setLength( long ); | 114 | void setLength( long ); |
115 | void setView( char ); | 115 | void setView( char ); |
116 | 116 | ||
117 | signals: | 117 | signals: |
118 | void moreClicked(); | 118 | void moreClicked(); |
119 | void lessClicked(); | 119 | void lessClicked(); |
120 | void moreReleased(); | 120 | void moreReleased(); |
121 | void lessReleased(); | 121 | void lessReleased(); |
122 | void sliderMoved(long); | 122 | void sliderMoved(long); |
123 | 123 | ||
124 | protected: | 124 | protected: |
125 | void paintEvent( QPaintEvent *pe ); | 125 | void paintEvent( QPaintEvent *pe ); |
126 | void showEvent( QShowEvent *se ); | 126 | void showEvent( QShowEvent *se ); |
127 | void mouseMoveEvent( QMouseEvent *event ); | 127 | void mouseMoveEvent( QMouseEvent *event ); |
128 | void mousePressEvent( QMouseEvent *event ); | 128 | void mousePressEvent( QMouseEvent *event ); |
129 | void mouseReleaseEvent( QMouseEvent *event ); | 129 | void mouseReleaseEvent( QMouseEvent *event ); |
130 | void timerEvent( QTimerEvent *event ); | 130 | void timerEvent( QTimerEvent *event ); |
131 | void closeEvent( QCloseEvent *event ); | 131 | void closeEvent( QCloseEvent *event ); |
132 | void keyReleaseEvent( QKeyEvent *e); | 132 | void keyReleaseEvent( QKeyEvent *e); |
133 | 133 | ||
134 | private: | 134 | private: |
135 | void toggleButton( int ); | 135 | void toggleButton( int ); |
136 | void setToggleButton( int, bool ); | 136 | void setToggleButton( int, bool ); |
137 | void paintButton( QPainter *p, int i ); | 137 | void paintButton( QPainter *p, int i ); |
138 | QPixmap *pixmaps[4]; | 138 | QPixmap *pixmaps[4]; |
139 | Ticker *songInfo; | 139 | Ticker *songInfo; |
140 | QSlider *slider; | 140 | QSlider *slider; |
141 | }; | 141 | }; |
142 | 142 | ||
143 | 143 | ||
144 | #endif // AUDIO_WIDGET_H | 144 | #endif // AUDIO_WIDGET_H |
145 | 145 | ||
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp index b9f96de..45c2d3e 100644 --- a/core/multimedia/opieplayer/loopcontrol.cpp +++ b/core/multimedia/opieplayer/loopcontrol.cpp | |||
@@ -1,474 +1,478 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // L.J.Potter added changes Fri 02-15-2002 | 20 | // L.J.Potter added changes Fri 02-15-2002 |
21 | 21 | ||
22 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | 23 | ||
24 | #ifdef Q_WS_QWS | 24 | #ifdef Q_WS_QWS |
25 | #include <qpe/qcopenvelope_qws.h> | 25 | #include <qpe/qcopenvelope_qws.h> |
26 | #endif | 26 | #endif |
27 | #include <stdio.h> | 27 | #include <stdio.h> |
28 | #include <stdlib.h> | 28 | #include <stdlib.h> |
29 | #include <string.h> | 29 | #include <string.h> |
30 | #include <pthread.h> | 30 | #include <pthread.h> |
31 | #include <errno.h> | 31 | #include <errno.h> |
32 | #include <unistd.h> | 32 | #include <unistd.h> |
33 | #include "loopcontrol.h" | 33 | #include "loopcontrol.h" |
34 | #include "videowidget.h" | 34 | #include "videowidget.h" |
35 | #include "audiodevice.h" | 35 | #include "audiodevice.h" |
36 | #include <qpe/mediaplayerplugininterface.h> | 36 | #include <qpe/mediaplayerplugininterface.h> |
37 | #include "mediaplayerstate.h" | 37 | #include "mediaplayerstate.h" |
38 | 38 | ||
39 | 39 | ||
40 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame | 40 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame |
41 | extern MediaPlayerState *mediaPlayerState; | 41 | extern MediaPlayerState *mediaPlayerState; |
42 | 42 | ||
43 | 43 | ||
44 | //#define DecodeLoopDebug(x) qDebug x | 44 | //#define DecodeLoopDebug(x) qDebug x |
45 | #define DecodeLoopDebug(x) | 45 | #define DecodeLoopDebug(x) |
46 | 46 | ||
47 | 47 | ||
48 | static char *audioBuffer = NULL; | 48 | static char *audioBuffer = NULL; |
49 | static AudioDevice *audioDevice = NULL; | 49 | static AudioDevice *audioDevice = NULL; |
50 | static bool disabledSuspendScreenSaver = FALSE; | 50 | static bool disabledSuspendScreenSaver = FALSE; |
51 | static bool previousSuspendMode = FALSE; | 51 | static bool previousSuspendMode = FALSE; |
52 | 52 | ||
53 | 53 | ||
54 | pthread_t audio_tid; | 54 | pthread_t audio_tid; |
55 | pthread_attr_t audio_attr; | 55 | pthread_attr_t audio_attr; |
56 | bool threadOkToGo = FALSE; | 56 | bool threadOkToGo = FALSE; |
57 | 57 | ||
58 | 58 | ||
59 | class Mutex { | 59 | class Mutex { |
60 | public: | 60 | public: |
61 | Mutex() { | 61 | Mutex() { |
62 | pthread_mutexattr_t attr; | 62 | pthread_mutexattr_t attr; |
63 | pthread_mutexattr_init( &attr ); | 63 | pthread_mutexattr_init( &attr ); |
64 | pthread_mutex_init( &mutex, &attr ); | 64 | pthread_mutex_init( &mutex, &attr ); |
65 | pthread_mutexattr_destroy( &attr ); | 65 | pthread_mutexattr_destroy( &attr ); |
66 | } | 66 | } |
67 | 67 | ||
68 | ~Mutex() { | 68 | ~Mutex() { |
69 | pthread_mutex_destroy( &mutex ); | 69 | pthread_mutex_destroy( &mutex ); |
70 | } | 70 | } |
71 | 71 | ||
72 | void lock() { | 72 | void lock() { |
73 | pthread_mutex_lock( &mutex ); | 73 | pthread_mutex_lock( &mutex ); |
74 | } | 74 | } |
75 | 75 | ||
76 | void unlock() { | 76 | void unlock() { |
77 | pthread_mutex_unlock( &mutex ); | 77 | pthread_mutex_unlock( &mutex ); |
78 | } | 78 | } |
79 | private: | 79 | private: |
80 | pthread_mutex_t mutex; | 80 | pthread_mutex_t mutex; |
81 | }; | 81 | }; |
82 | 82 | ||
83 | 83 | ||
84 | void *startAudioThread( void *ptr ) { | 84 | void *startAudioThread( void *ptr ) { |
85 | LoopControl *mpegView = (LoopControl *)ptr; | 85 | LoopControl *mpegView = (LoopControl *)ptr; |
86 | while ( TRUE ) { | 86 | while ( TRUE ) { |
87 | if ( threadOkToGo && mpegView->moreAudio ) | 87 | if ( threadOkToGo && mpegView->moreAudio ) |
88 | mpegView->startAudio(); | 88 | mpegView->startAudio(); |
89 | else | 89 | else |
90 | usleep( 10000 ); // Semi-buzy-wait till we are playing again | 90 | usleep( 10000 ); // Semi-buzy-wait till we are playing again |
91 | } | 91 | } |
92 | return 0; | 92 | return 0; |
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | Mutex *audioMutex; | 96 | Mutex *audioMutex; |
97 | 97 | ||
98 | 98 | ||
99 | LoopControl::LoopControl( QObject *parent, const char *name ) | 99 | LoopControl::LoopControl( QObject *parent, const char *name ) |
100 | : QObject( parent, name ) { | 100 | : QObject( parent, name ) { |
101 | isMuted = FALSE; | 101 | isMuted = FALSE; |
102 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); | 102 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); |
103 | //qDebug("starting loopcontrol"); | 103 | //qDebug("starting loopcontrol"); |
104 | audioMutex = new Mutex; | 104 | audioMutex = new Mutex; |
105 | 105 | ||
106 | pthread_attr_init(&audio_attr); | 106 | pthread_attr_init(&audio_attr); |
107 | #define USE_REALTIME_AUDIO_THREAD | 107 | #define USE_REALTIME_AUDIO_THREAD |
108 | #ifdef USE_REALTIME_AUDIO_THREAD | 108 | #ifdef USE_REALTIME_AUDIO_THREAD |
109 | // Attempt to set it to real-time round robin | 109 | // Attempt to set it to real-time round robin |
110 | if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { | 110 | if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { |
111 | sched_param params; | 111 | sched_param params; |
112 | params.sched_priority = 50; | 112 | params.sched_priority = 50; |
113 | pthread_attr_setschedparam(&audio_attr,¶ms); | 113 | pthread_attr_setschedparam(&audio_attr,¶ms); |
114 | } else { | 114 | } else { |
115 | qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); | 115 | qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); |
116 | pthread_attr_destroy(&audio_attr); | 116 | pthread_attr_destroy(&audio_attr); |
117 | pthread_attr_init(&audio_attr); | 117 | pthread_attr_init(&audio_attr); |
118 | } | 118 | } |
119 | #endif | 119 | #endif |
120 | //qDebug("create audio thread"); | 120 | //qDebug("create audio thread"); |
121 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); | 121 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | LoopControl::~LoopControl() { | 125 | LoopControl::~LoopControl() { |
126 | stop(); | 126 | stop(); |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | static long prev_frame = 0; | 130 | static long prev_frame = 0; |
131 | static int currentSample = 0; | 131 | static int currentSample = 0; |
132 | 132 | ||
133 | 133 | ||
134 | void LoopControl::timerEvent( QTimerEvent *te ) { | 134 | void LoopControl::timerEvent( QTimerEvent *te ) { |
135 | 135 | ||
136 | if ( te->timerId() == videoId ) | 136 | if ( te->timerId() == videoId ) |
137 | startVideo(); | 137 | startVideo(); |
138 | 138 | ||
139 | if ( te->timerId() == sliderId ) { | 139 | if ( te->timerId() == sliderId ) { |
140 | if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { | 140 | if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { |
141 | mediaPlayerState->updatePosition( audioSampleCounter ); | 141 | mediaPlayerState->updatePosition( audioSampleCounter ); |
142 | } else if ( hasVideoChannel && moreVideo ) { | 142 | } else if ( hasVideoChannel && moreVideo ) { |
143 | mediaPlayerState->updatePosition( current_frame ); | 143 | mediaPlayerState->updatePosition( current_frame ); |
144 | } | 144 | } |
145 | } | 145 | } |
146 | 146 | ||
147 | if ( !moreVideo && !moreAudio ) { | 147 | if ( !moreVideo && !moreAudio ) { |
148 | mediaPlayerState->setPlaying( FALSE ); | 148 | mediaPlayerState->setPlaying( FALSE ); |
149 | mediaPlayerState->setNext(); | 149 | mediaPlayerState->setNext(); |
150 | } | 150 | } |
151 | } | 151 | } |
152 | 152 | ||
153 | 153 | ||
154 | void LoopControl::setPosition( long pos ) { | 154 | void LoopControl::setPosition( long pos ) { |
155 | audioMutex->lock(); | 155 | audioMutex->lock(); |
156 | 156 | ||
157 | if ( hasVideoChannel && hasAudioChannel ) { | 157 | if ( hasVideoChannel && hasAudioChannel ) { |
158 | playtime.restart(); | 158 | playtime.restart(); |
159 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); | 159 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); |
160 | current_frame = pos + 1; | 160 | current_frame = pos + 1; |
161 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 161 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
162 | prev_frame = current_frame - 1; | 162 | prev_frame = current_frame - 1; |
163 | currentSample = (int)( (double)current_frame * freq / framerate ); | 163 | currentSample = (int)( (double)current_frame * freq / framerate ); |
164 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); | 164 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); |
165 | audioSampleCounter = currentSample - 1; | 165 | audioSampleCounter = currentSample - 1; |
166 | } else if ( hasVideoChannel ) { | 166 | } else if ( hasVideoChannel ) { |
167 | playtime.restart(); | 167 | playtime.restart(); |
168 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); | 168 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); |
169 | current_frame = pos + 1; | 169 | current_frame = pos + 1; |
170 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 170 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
171 | prev_frame = current_frame - 1; | 171 | prev_frame = current_frame - 1; |
172 | } else if ( hasAudioChannel ) { | 172 | } else if ( hasAudioChannel ) { |
173 | playtime.restart(); | 173 | playtime.restart(); |
174 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); | 174 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); |
175 | currentSample = pos + 1; | 175 | currentSample = pos + 1; |
176 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); | 176 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); |
177 | audioSampleCounter = currentSample - 1; | 177 | audioSampleCounter = currentSample - 1; |
178 | } | 178 | } |
179 | 179 | ||
180 | audioMutex->unlock(); | 180 | audioMutex->unlock(); |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
184 | void LoopControl::startVideo() { | 184 | void LoopControl::startVideo() { |
185 | 185 | ||
186 | if ( moreVideo ) { | 186 | if ( moreVideo ) { |
187 | 187 | ||
188 | if ( mediaPlayerState->curDecoder() ) { | 188 | if ( mediaPlayerState->curDecoder() ) { |
189 | 189 | ||
190 | if ( hasAudioChannel && !isMuted ) { | 190 | if ( hasAudioChannel && !isMuted ) { |
191 | 191 | ||
192 | current_frame = long( playtime.elapsed() * framerate / 1000 ); | 192 | current_frame = long( playtime.elapsed() * framerate / 1000 ); |
193 | 193 | ||
194 | if ( prev_frame != -1 && current_frame <= prev_frame ) | 194 | if ( prev_frame != -1 && current_frame <= prev_frame ) |
195 | return; | 195 | return; |
196 | 196 | ||
197 | } else { | 197 | } else { |
198 | // Don't skip | 198 | // Don't skip |
199 | current_frame++; | 199 | current_frame++; |
200 | } | 200 | } |
201 | 201 | ||
202 | if ( prev_frame == -1 || current_frame > prev_frame ) { | 202 | if ( prev_frame == -1 || current_frame > prev_frame ) { |
203 | if ( current_frame > prev_frame + 1 ) { | 203 | if ( current_frame > prev_frame + 1 ) { |
204 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 204 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
205 | } | 205 | } |
206 | moreVideo = videoUI->playVideo(); | 206 | moreVideo = videoUI->playVideo(); |
207 | prev_frame = current_frame; | 207 | prev_frame = current_frame; |
208 | } | 208 | } |
209 | 209 | ||
210 | } else { | 210 | } else { |
211 | 211 | ||
212 | moreVideo = FALSE; | 212 | moreVideo = FALSE; |
213 | killTimer( videoId ); | 213 | killTimer( videoId ); |
214 | 214 | ||
215 | } | 215 | } |
216 | 216 | ||
217 | } | 217 | } |
218 | } | 218 | } |
219 | 219 | ||
220 | 220 | ||
221 | void LoopControl::startAudio() { | 221 | void LoopControl::startAudio() { |
222 | 222 | ||
223 | //qDebug("start audio"); | 223 | //qDebug("start audio"); |
224 | audioMutex->lock(); | 224 | audioMutex->lock(); |
225 | if ( moreAudio ) { | 225 | if ( moreAudio ) { |
226 | 226 | ||
227 | if ( !isMuted && mediaPlayerState->curDecoder() ) { | 227 | if ( !isMuted && mediaPlayerState->curDecoder() ) { |
228 | 228 | ||
229 | currentSample = audioSampleCounter + 1; | 229 | currentSample = audioSampleCounter + 1; |
230 | 230 | ||
231 | if ( currentSample != audioSampleCounter + 1 ) | 231 | if ( currentSample != audioSampleCounter + 1 ) |
232 | qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); | 232 | qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); |
233 | 233 | ||
234 | long samplesRead = 0; | 234 | long samplesRead = 0; |
235 | bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); | 235 | bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); |
236 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; | 236 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; |
237 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; | 237 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; |
238 | 238 | ||
239 | // if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { | 239 | // this causes drop outs not sure why its even here |
240 | // usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); | 240 | // if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { |
241 | // usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); | ||
242 | // } | ||
243 | // else if ( sampleWaitTime <= -5000 ) { | ||
244 | // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); | ||
245 | // //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); | ||
246 | // currentSample = sampleWeShouldBeAt; | ||
241 | // } | 247 | // } |
242 | // else if ( sampleWaitTime <= -5000 ) { | ||
243 | // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); | ||
244 | // //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); | ||
245 | // currentSample = sampleWeShouldBeAt; | ||
246 | // } | ||
247 | 248 | ||
248 | audioDevice->write( audioBuffer, samplesRead * 2 * channels ); | 249 | audioDevice->write( audioBuffer, samplesRead * 2 * channels ); |
249 | audioSampleCounter = currentSample + samplesRead - 1; | 250 | audioSampleCounter = currentSample + samplesRead - 1; |
250 | 251 | ||
251 | moreAudio = readOk && (audioSampleCounter <= total_audio_samples); | 252 | moreAudio = readOk && (audioSampleCounter <= total_audio_samples); |
252 | 253 | ||
253 | } else { | 254 | } else { |
254 | 255 | ||
255 | moreAudio = FALSE; | 256 | moreAudio = FALSE; |
256 | 257 | ||
257 | } | 258 | } |
258 | 259 | ||
259 | } | 260 | } |
260 | 261 | ||
261 | audioMutex->unlock(); | 262 | audioMutex->unlock(); |
262 | } | 263 | } |
263 | 264 | ||
264 | 265 | ||
265 | void LoopControl::killTimers() { | 266 | void LoopControl::killTimers() { |
266 | 267 | ||
267 | audioMutex->lock(); | 268 | audioMutex->lock(); |
268 | 269 | ||
269 | if ( hasVideoChannel ) | 270 | if ( hasVideoChannel ) |
270 | killTimer( videoId ); | 271 | killTimer( videoId ); |
271 | killTimer( sliderId ); | 272 | killTimer( sliderId ); |
272 | threadOkToGo = FALSE; | 273 | threadOkToGo = FALSE; |
273 | 274 | ||
274 | audioMutex->unlock(); | 275 | audioMutex->unlock(); |
275 | } | 276 | } |
276 | 277 | ||
277 | 278 | ||
278 | void LoopControl::startTimers() { | 279 | void LoopControl::startTimers() { |
279 | 280 | ||
280 | audioMutex->lock(); | 281 | audioMutex->lock(); |
281 | 282 | ||
282 | moreVideo = FALSE; | 283 | moreVideo = FALSE; |
283 | moreAudio = FALSE; | 284 | moreAudio = FALSE; |
284 | 285 | ||
285 | if ( hasVideoChannel ) { | 286 | if ( hasVideoChannel ) { |
286 | moreVideo = TRUE; | 287 | moreVideo = TRUE; |
287 | int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value | 288 | int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value |
288 | videoId = startTimer( mSecsBetweenFrames ); | 289 | videoId = startTimer( mSecsBetweenFrames ); |
289 | } | 290 | } |
290 | 291 | ||
291 | if ( hasAudioChannel ) { | 292 | if ( hasAudioChannel ) { |
292 | moreAudio = TRUE; | 293 | moreAudio = TRUE; |
293 | threadOkToGo = TRUE; | 294 | threadOkToGo = TRUE; |
294 | } | 295 | } |
295 | 296 | ||
296 | sliderId = startTimer( 300 ); // update slider every 1/3 second | 297 | sliderId = startTimer( 300 ); // update slider every 1/3 second |
297 | 298 | ||
298 | audioMutex->unlock(); | 299 | audioMutex->unlock(); |
299 | } | 300 | } |
300 | 301 | ||
301 | 302 | ||
302 | void LoopControl::setPaused( bool pause ) { | 303 | void LoopControl::setPaused( bool pause ) { |
303 | 304 | ||
304 | if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) | 305 | if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) |
305 | return; | 306 | return; |
306 | 307 | ||
307 | if ( pause ) { | 308 | if ( pause ) { |
308 | killTimers(); | 309 | killTimers(); |
309 | } else { | 310 | } else { |
310 | // Force an update of the position | 311 | // Force an update of the position |
311 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); | 312 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); |
312 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); | 313 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); |
313 | // Just like we never stopped | 314 | // Just like we never stopped |
314 | startTimers(); | 315 | startTimers(); |
315 | } | 316 | } |
316 | } | 317 | } |
317 | 318 | ||
318 | 319 | ||
319 | void LoopControl::stop( bool willPlayAgainShortly ) { | 320 | void LoopControl::stop( bool willPlayAgainShortly ) { |
320 | 321 | ||
321 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 322 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
322 | if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { | 323 | if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { |
323 | disabledSuspendScreenSaver = FALSE; | 324 | disabledSuspendScreenSaver = FALSE; |
324 | // Re-enable the suspend mode | 325 | // Re-enable the suspend mode |
325 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | 326 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; |
326 | } | 327 | } |
327 | #endif | 328 | #endif |
328 | 329 | ||
329 | if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { | 330 | if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { |
330 | 331 | ||
331 | killTimers(); | 332 | killTimers(); |
332 | 333 | ||
333 | audioMutex->lock(); | 334 | audioMutex->lock(); |
334 | 335 | ||
335 | mediaPlayerState->curDecoder()->close(); | 336 | mediaPlayerState->curDecoder()->close(); |
336 | 337 | ||
337 | if ( audioDevice ) { | 338 | if ( audioDevice ) { |
338 | delete audioDevice; | 339 | delete audioDevice; |
339 | delete audioBuffer; | 340 | delete audioBuffer; |
340 | audioDevice = 0; | 341 | audioDevice = 0; |
341 | audioBuffer = 0; | 342 | audioBuffer = 0; |
342 | } | 343 | } |
343 | 344 | ||
344 | audioMutex->unlock(); | 345 | audioMutex->unlock(); |
345 | 346 | ||
346 | } | 347 | } |
347 | } | 348 | } |
348 | 349 | ||
349 | 350 | ||
350 | bool LoopControl::init( const QString& filename ) { | 351 | bool LoopControl::init( const QString& filename ) { |
351 | stop(); | 352 | stop(); |
352 | 353 | ||
353 | audioMutex->lock(); | 354 | audioMutex->lock(); |
354 | 355 | ||
355 | fileName = filename; | 356 | fileName = filename; |
356 | stream = 0; // only play stream 0 for now | 357 | stream = 0; // only play stream 0 for now |
357 | current_frame = total_video_frames = total_audio_samples = 0; | 358 | current_frame = total_video_frames = total_audio_samples = 0; |
358 | 359 | ||
359 | qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); | 360 | qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); |
360 | 361 | ||
361 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin | 362 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin |
362 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { | 363 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { |
363 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { | 364 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { |
364 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); | 365 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); |
365 | mediaPlayerState->libMpeg3Decoder()->close(); | 366 | mediaPlayerState->libMpeg3Decoder()->close(); |
366 | } | 367 | } |
367 | } | 368 | } |
368 | 369 | ||
369 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { | 370 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { |
370 | audioMutex->unlock(); | 371 | audioMutex->unlock(); |
371 | return FALSE; | 372 | return FALSE; |
372 | } | 373 | } |
373 | 374 | ||
374 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; | 375 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; |
375 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; | 376 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; |
376 | 377 | ||
377 | if ( hasAudioChannel ) { | 378 | if ( hasAudioChannel ) { |
378 | int astream = 0; | 379 | int astream = 0; |
379 | 380 | ||
380 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); | 381 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); |
381 | qDebug( "LC- channels = %d", channels ); | 382 | qDebug( "LC- channels = %d", channels ); |
382 | 383 | ||
383 | if ( !total_audio_samples ) | 384 | if ( !total_audio_samples ) |
384 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); | 385 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); |
385 | 386 | ||
386 | // total_audio_samples += 1000; | 387 | // total_audio_samples += 1000; |
387 | 388 | ||
388 | mediaPlayerState->setLength( total_audio_samples ); | 389 | mediaPlayerState->setLength( total_audio_samples ); |
389 | 390 | ||
390 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); | 391 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); |
391 | qDebug( "LC- frequency = %d", freq ); | 392 | qDebug( "LC- frequency = %d", freq ); |
392 | 393 | ||
393 | audioSampleCounter = 0; | 394 | audioSampleCounter = 0; |
394 | int bits_per_sample; | 395 | int bits_per_sample; |
395 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { | 396 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { |
396 | bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); | 397 | bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); |
397 | qDebug("using stupid hack"); | 398 | qDebug("using stupid hack"); |
398 | } else { | 399 | } else { |
399 | bits_per_sample=0; | 400 | bits_per_sample=0; |
400 | } | 401 | } |
401 | 402 | ||
402 | audioDevice = new AudioDevice( freq, channels, bits_per_sample); | 403 | audioDevice = new AudioDevice( freq, channels, bits_per_sample); |
403 | audioBuffer = new char[ audioDevice->bufferSize() ]; | 404 | audioBuffer = new char[ audioDevice->bufferSize() ]; |
404 | channels = audioDevice->channels(); | 405 | channels = audioDevice->channels(); |
405 | 406 | ||
406 | //### must check which frequency is actually used. | 407 | //### must check which frequency is actually used. |
407 | static const int size = 1; | 408 | static const int size = 1; |
408 | short int buf[size]; | 409 | short int buf[size]; |
409 | long samplesRead = 0; | 410 | long samplesRead = 0; |
410 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); | 411 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); |
411 | } | 412 | } |
412 | 413 | ||
413 | if ( hasVideoChannel ) { | 414 | if ( hasVideoChannel ) { |
414 | total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); | 415 | total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); |
415 | 416 | ||
416 | mediaPlayerState->setLength( total_video_frames ); | 417 | mediaPlayerState->setLength( total_video_frames ); |
417 | 418 | ||
418 | framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); | 419 | framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); |
419 | DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); | 420 | DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); |
420 | 421 | ||
421 | if ( framerate <= 1.0 ) { | 422 | if ( framerate <= 1.0 ) { |
422 | DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); | 423 | DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); |
423 | framerate = 25; | 424 | framerate = 25; |
424 | } | 425 | } |
425 | 426 | ||
426 | if ( total_video_frames == 1 ) { | 427 | if ( total_video_frames == 1 ) { |
427 | DecodeLoopDebug(( "Cannot seek to frame" )); | 428 | DecodeLoopDebug(( "Cannot seek to frame" )); |
428 | } | 429 | } |
429 | 430 | ||
430 | } | 431 | } |
431 | 432 | ||
432 | current_frame = 0; | 433 | current_frame = 0; |
433 | prev_frame = -1; | 434 | prev_frame = -1; |
434 | 435 | ||
436 | if( fileName.left(7) == "http://") | ||
437 | mediaPlayerState->isStreaming = TRUE; | ||
438 | |||
435 | connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); | 439 | connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); |
436 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); | 440 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); |
437 | 441 | ||
438 | audioMutex->unlock(); | 442 | audioMutex->unlock(); |
439 | 443 | ||
440 | return TRUE; | 444 | return TRUE; |
441 | } | 445 | } |
442 | 446 | ||
443 | 447 | ||
444 | void LoopControl::play() { | 448 | void LoopControl::play() { |
445 | qDebug("LC- play"); | 449 | qDebug("LC- play"); |
446 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 450 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
447 | if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { | 451 | if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { |
448 | disabledSuspendScreenSaver = TRUE; | 452 | disabledSuspendScreenSaver = TRUE; |
449 | previousSuspendMode = hasVideoChannel; | 453 | previousSuspendMode = hasVideoChannel; |
450 | // Stop the screen from blanking and power saving state | 454 | // Stop the screen from blanking and power saving state |
451 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) | 455 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) |
452 | << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); | 456 | << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); |
453 | } | 457 | } |
454 | #endif | 458 | #endif |
455 | 459 | ||
456 | playtime.start(); | 460 | playtime.start(); |
457 | startTimers(); | 461 | startTimers(); |
458 | } | 462 | } |
459 | 463 | ||
460 | 464 | ||
461 | void LoopControl::setMute( bool on ) { | 465 | void LoopControl::setMute( bool on ) { |
462 | if ( on != isMuted ) { | 466 | if ( on != isMuted ) { |
463 | isMuted = on; | 467 | isMuted = on; |
464 | if ( !on ) { | 468 | if ( !on ) { |
465 | // Force an update of the position | 469 | // Force an update of the position |
466 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); | 470 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); |
467 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); | 471 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); |
468 | // Resume playing audio | 472 | // Resume playing audio |
469 | moreAudio = TRUE; | 473 | moreAudio = TRUE; |
470 | } | 474 | } |
471 | } | 475 | } |
472 | } | 476 | } |
473 | 477 | ||
474 | 478 | ||
diff --git a/core/multimedia/opieplayer/mediaplayerstate.h b/core/multimedia/opieplayer/mediaplayerstate.h index ad273f1..06c5556 100644 --- a/core/multimedia/opieplayer/mediaplayerstate.h +++ b/core/multimedia/opieplayer/mediaplayerstate.h | |||
@@ -1,119 +1,119 @@ | |||
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 | #ifndef MEDIA_PLAYER_STATE_H | 20 | #ifndef MEDIA_PLAYER_STATE_H |
21 | #define MEDIA_PLAYER_STATE_H | 21 | #define MEDIA_PLAYER_STATE_H |
22 | 22 | ||
23 | 23 | ||
24 | #include <qobject.h> | 24 | #include <qobject.h> |
25 | 25 | ||
26 | 26 | ||
27 | class MediaPlayerDecoder; | 27 | class MediaPlayerDecoder; |
28 | class Config; | 28 | class Config; |
29 | 29 | ||
30 | 30 | ||
31 | class MediaPlayerState : public QObject { | 31 | class MediaPlayerState : public QObject { |
32 | Q_OBJECT | 32 | Q_OBJECT |
33 | public: | 33 | public: |
34 | MediaPlayerState( QObject *parent, const char *name ); | 34 | MediaPlayerState( QObject *parent, const char *name ); |
35 | ~MediaPlayerState(); | 35 | ~MediaPlayerState(); |
36 | 36 | ||
37 | 37 | bool isStreaming; | |
38 | bool fullscreen() { return isFullscreen; } | 38 | bool fullscreen() { return isFullscreen; } |
39 | bool scaled() { return isScaled; } | 39 | bool scaled() { return isScaled; } |
40 | bool looping() { return isLooping; } | 40 | bool looping() { return isLooping; } |
41 | bool shuffled() { return isShuffled; } | 41 | bool shuffled() { return isShuffled; } |
42 | bool playlist() { return usePlaylist; } | 42 | bool playlist() { return usePlaylist; } |
43 | bool paused() { return isPaused; } | 43 | bool paused() { return isPaused; } |
44 | bool playing() { return isPlaying; } | 44 | bool playing() { return isPlaying; } |
45 | long position() { return curPosition; } | 45 | long position() { return curPosition; } |
46 | long length() { return curLength; } | 46 | long length() { return curLength; } |
47 | char view() { return curView; } | 47 | char view() { return curView; } |
48 | 48 | ||
49 | MediaPlayerDecoder *newDecoder( const QString& file ); | 49 | MediaPlayerDecoder *newDecoder( const QString& file ); |
50 | MediaPlayerDecoder *curDecoder(); | 50 | MediaPlayerDecoder *curDecoder(); |
51 | MediaPlayerDecoder *libMpeg3Decoder(); // ### Yucky hack needed to use libmpeg3plugin to get the | 51 | MediaPlayerDecoder *libMpeg3Decoder(); // ### Yucky hack needed to use libmpeg3plugin to get the |
52 | // number of audio samples if we are using the libmad plugin | 52 | // number of audio samples if we are using the libmad plugin |
53 | public slots: | 53 | public slots: |
54 | void setFullscreen( bool b ) { if ( isFullscreen == b ) return; isFullscreen = b; emit fullscreenToggled(b); } | 54 | void setFullscreen( bool b ) { if ( isFullscreen == b ) return; isFullscreen = b; emit fullscreenToggled(b); } |
55 | void setScaled( bool b ) { if ( isScaled == b ) return; isScaled = b; emit scaledToggled(b); } | 55 | void setScaled( bool b ) { if ( isScaled == b ) return; isScaled = b; emit scaledToggled(b); } |
56 | void setLooping( bool b ) { if ( isLooping == b ) return; isLooping = b; emit loopingToggled(b); } | 56 | void setLooping( bool b ) { if ( isLooping == b ) return; isLooping = b; emit loopingToggled(b); } |
57 | void setShuffled( bool b ) { if ( isShuffled == b ) return; isShuffled = b; emit shuffledToggled(b); } | 57 | void setShuffled( bool b ) { if ( isShuffled == b ) return; isShuffled = b; emit shuffledToggled(b); } |
58 | void setPlaylist( bool b ) { if ( usePlaylist == b ) return; usePlaylist = b; emit playlistToggled(b); } | 58 | void setPlaylist( bool b ) { if ( usePlaylist == b ) return; usePlaylist = b; emit playlistToggled(b); } |
59 | void setPaused( bool b ) { if ( isPaused == b ) return; isPaused = b; emit pausedToggled(b); } | 59 | void setPaused( bool b ) { if ( isPaused == b ) return; isPaused = b; emit pausedToggled(b); } |
60 | void setPlaying( bool b ) { if ( isPlaying == b ) return; isPlaying = b; emit playingToggled(b); } | 60 | void setPlaying( bool b ) { if ( isPlaying == b ) return; isPlaying = b; emit playingToggled(b); } |
61 | void setPosition( long p ) { if ( curPosition == p ) return; curPosition = p; emit positionChanged(p); } | 61 | void setPosition( long p ) { if ( curPosition == p ) return; curPosition = p; emit positionChanged(p); } |
62 | void updatePosition( long p ){ if ( curPosition == p ) return; curPosition = p; emit positionUpdated(p); } | 62 | void updatePosition( long p ){ if ( curPosition == p ) return; curPosition = p; emit positionUpdated(p); } |
63 | void setLength( long l ) { if ( curLength == l ) return; curLength = l; emit lengthChanged(l); } | 63 | void setLength( long l ) { if ( curLength == l ) return; curLength = l; emit lengthChanged(l); } |
64 | void setView( char v ) { if ( curView == v ) return; curView = v; emit viewChanged(v); } | 64 | void setView( char v ) { if ( curView == v ) return; curView = v; emit viewChanged(v); } |
65 | 65 | ||
66 | void setPrev() { emit prev(); } | 66 | void setPrev() { emit prev(); } |
67 | void setNext() { emit next(); } | 67 | void setNext() { emit next(); } |
68 | void setList() { setPlaying( FALSE ); setView('l'); } | 68 | void setList() { setPlaying( FALSE ); setView('l'); } |
69 | void setVideo() { setView('v'); } | 69 | void setVideo() { setView('v'); } |
70 | void setAudio() { setView('a'); } | 70 | void setAudio() { setView('a'); } |
71 | 71 | ||
72 | void toggleFullscreen() { setFullscreen( !isFullscreen ); } | 72 | void toggleFullscreen() { setFullscreen( !isFullscreen ); } |
73 | void toggleScaled() { setScaled( !isScaled); } | 73 | void toggleScaled() { setScaled( !isScaled); } |
74 | void toggleLooping() { setLooping( !isLooping); } | 74 | void toggleLooping() { setLooping( !isLooping); } |
75 | void toggleShuffled() { setShuffled( !isShuffled); } | 75 | void toggleShuffled() { setShuffled( !isShuffled); } |
76 | void togglePlaylist() { setPlaylist( !usePlaylist); } | 76 | void togglePlaylist() { setPlaylist( !usePlaylist); } |
77 | void togglePaused() { setPaused( !isPaused); } | 77 | void togglePaused() { setPaused( !isPaused); } |
78 | void togglePlaying() { setPlaying( !isPlaying); } | 78 | void togglePlaying() { setPlaying( !isPlaying); } |
79 | 79 | ||
80 | signals: | 80 | signals: |
81 | void fullscreenToggled( bool ); | 81 | void fullscreenToggled( bool ); |
82 | void scaledToggled( bool ); | 82 | void scaledToggled( bool ); |
83 | void loopingToggled( bool ); | 83 | void loopingToggled( bool ); |
84 | void shuffledToggled( bool ); | 84 | void shuffledToggled( bool ); |
85 | void playlistToggled( bool ); | 85 | void playlistToggled( bool ); |
86 | void pausedToggled( bool ); | 86 | void pausedToggled( bool ); |
87 | void playingToggled( bool ); | 87 | void playingToggled( bool ); |
88 | void positionChanged( long ); // When the slider is moved | 88 | void positionChanged( long ); // When the slider is moved |
89 | void positionUpdated( long ); // When the media file progresses | 89 | void positionUpdated( long ); // When the media file progresses |
90 | void lengthChanged( long ); | 90 | void lengthChanged( long ); |
91 | void viewChanged( char ); | 91 | void viewChanged( char ); |
92 | 92 | ||
93 | void prev(); | 93 | void prev(); |
94 | void next(); | 94 | void next(); |
95 | 95 | ||
96 | private: | 96 | private: |
97 | bool isFullscreen; | 97 | bool isFullscreen; |
98 | bool isScaled; | 98 | bool isScaled; |
99 | bool isLooping; | 99 | bool isLooping; |
100 | bool isShuffled; | 100 | bool isShuffled; |
101 | bool usePlaylist; | 101 | bool usePlaylist; |
102 | bool isPaused; | 102 | bool isPaused; |
103 | bool isPlaying; | 103 | bool isPlaying; |
104 | long curPosition; | 104 | long curPosition; |
105 | long curLength; | 105 | long curLength; |
106 | char curView; | 106 | char curView; |
107 | 107 | ||
108 | MediaPlayerDecoder *decoder; | 108 | MediaPlayerDecoder *decoder; |
109 | MediaPlayerDecoder *libmpeg3decoder; | 109 | MediaPlayerDecoder *libmpeg3decoder; |
110 | // MediaPlayerDecoder *libwavdecoder; | 110 | // MediaPlayerDecoder *libwavdecoder; |
111 | 111 | ||
112 | void loadPlugins(); | 112 | void loadPlugins(); |
113 | void readConfig( Config& cfg ); | 113 | void readConfig( Config& cfg ); |
114 | void writeConfig( Config& cfg ) const; | 114 | void writeConfig( Config& cfg ) const; |
115 | }; | 115 | }; |
116 | 116 | ||
117 | 117 | ||
118 | #endif // MEDIA_PLAYER_STATE_H | 118 | #endif // MEDIA_PLAYER_STATE_H |
119 | 119 | ||
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index 250645c..ff156f8 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp | |||
@@ -228,794 +228,795 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) | |||
228 | 228 | ||
229 | QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); | 229 | QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); |
230 | connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 230 | connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
231 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | 231 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); |
232 | 232 | ||
233 | 233 | ||
234 | // audioView | 234 | // audioView |
235 | populateAudioView(); | 235 | populateAudioView(); |
236 | // videowidget | 236 | // videowidget |
237 | 237 | ||
238 | QWidget *vTab; | 238 | QWidget *vTab; |
239 | vTab = new QWidget( tabWidget, "vTab" ); | 239 | vTab = new QWidget( tabWidget, "vTab" ); |
240 | videoView = new QListView( vTab, "Videoview" ); | 240 | videoView = new QListView( vTab, "Videoview" ); |
241 | videoView->setMinimumSize(233,260); | 241 | videoView->setMinimumSize(233,260); |
242 | 242 | ||
243 | videoView->addColumn(tr("Title"),140); | 243 | videoView->addColumn(tr("Title"),140); |
244 | videoView->addColumn(tr("Size"),-1); | 244 | videoView->addColumn(tr("Size"),-1); |
245 | videoView->addColumn(tr("Media"),-1); | 245 | videoView->addColumn(tr("Media"),-1); |
246 | videoView->setColumnAlignment(1, Qt::AlignRight); | 246 | videoView->setColumnAlignment(1, Qt::AlignRight); |
247 | videoView->setColumnAlignment(2, Qt::AlignRight); | 247 | videoView->setColumnAlignment(2, Qt::AlignRight); |
248 | videoView->setAllColumnsShowFocus(TRUE); | 248 | videoView->setAllColumnsShowFocus(TRUE); |
249 | // videoView->setMultiSelection( TRUE ); | 249 | // videoView->setMultiSelection( TRUE ); |
250 | // videoView->setSelectionMode( QListView::Extended); | 250 | // videoView->setSelectionMode( QListView::Extended); |
251 | 251 | ||
252 | QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); | 252 | QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); |
253 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 253 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
254 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | 254 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); |
255 | 255 | ||
256 | tabWidget->insertTab( vTab,tr("Video")); | 256 | tabWidget->insertTab( vTab,tr("Video")); |
257 | populateVideoView(); | 257 | populateVideoView(); |
258 | 258 | ||
259 | //playlists list | 259 | //playlists list |
260 | QWidget *LTab; | 260 | QWidget *LTab; |
261 | LTab = new QWidget( tabWidget, "LTab" ); | 261 | LTab = new QWidget( tabWidget, "LTab" ); |
262 | playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy | 262 | playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy |
263 | playLists->setMinimumSize(233,260);; | 263 | playLists->setMinimumSize(233,260);; |
264 | tabWidget->insertTab(LTab,tr("Lists")); | 264 | tabWidget->insertTab(LTab,tr("Lists")); |
265 | 265 | ||
266 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); | 266 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); |
267 | // connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 267 | // connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
268 | 268 | ||
269 | 269 | ||
270 | // add the library area | 270 | // add the library area |
271 | 271 | ||
272 | // connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), | 272 | // connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), |
273 | // this, SLOT( fauxPlay( QListViewItem *) ) ); | 273 | // this, SLOT( fauxPlay( QListViewItem *) ) ); |
274 | // connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), | 274 | // connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), |
275 | // this, SLOT( fauxPlay( QListViewItem *)) ); | 275 | // this, SLOT( fauxPlay( QListViewItem *)) ); |
276 | 276 | ||
277 | // connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); | 277 | // connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); |
278 | // connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); | 278 | // connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); |
279 | 279 | ||
280 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | 280 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); |
281 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | 281 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); |
282 | 282 | ||
283 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); | 283 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); |
284 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); | 284 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); |
285 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); | 285 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); |
286 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); | 286 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); |
287 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); | 287 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); |
288 | 288 | ||
289 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); | 289 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); |
290 | // connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); | 290 | // connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); |
291 | 291 | ||
292 | setCentralWidget( vbox5 ); | 292 | setCentralWidget( vbox5 ); |
293 | 293 | ||
294 | Config cfg( "OpiePlayer" ); | 294 | Config cfg( "OpiePlayer" ); |
295 | readConfig( cfg ); | 295 | readConfig( cfg ); |
296 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | 296 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); |
297 | // qDebug("currentList is "+currentPlaylist); | 297 | // qDebug("currentList is "+currentPlaylist); |
298 | loadList(DocLnk( currentPlaylist)); | 298 | loadList(DocLnk( currentPlaylist)); |
299 | setCaption(tr("OpiePlayer: ")+ currentPlaylist ); | 299 | setCaption(tr("OpiePlayer: ")+ currentPlaylist ); |
300 | 300 | ||
301 | initializeStates(); | 301 | initializeStates(); |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | PlayListWidget::~PlayListWidget() { | 305 | PlayListWidget::~PlayListWidget() { |
306 | Config cfg( "OpiePlayer" ); | 306 | Config cfg( "OpiePlayer" ); |
307 | writeConfig( cfg ); | 307 | writeConfig( cfg ); |
308 | 308 | ||
309 | 309 | ||
310 | if ( d->current ) | 310 | if ( d->current ) |
311 | delete d->current; | 311 | delete d->current; |
312 | delete d; | 312 | delete d; |
313 | } | 313 | } |
314 | 314 | ||
315 | 315 | ||
316 | void PlayListWidget::initializeStates() { | 316 | void PlayListWidget::initializeStates() { |
317 | 317 | ||
318 | d->tbPlay->setOn( mediaPlayerState->playing() ); | 318 | d->tbPlay->setOn( mediaPlayerState->playing() ); |
319 | d->tbLoop->setOn( mediaPlayerState->looping() ); | 319 | d->tbLoop->setOn( mediaPlayerState->looping() ); |
320 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); | 320 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); |
321 | // d->tbFull->setOn( mediaPlayerState->fullscreen() ); | 321 | // d->tbFull->setOn( mediaPlayerState->fullscreen() ); |
322 | // d->tbScale->setOn( mediaPlayerState->scaled() ); | 322 | // d->tbScale->setOn( mediaPlayerState->scaled() ); |
323 | // d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); | 323 | // d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); |
324 | // setPlaylist( mediaPlayerState->playlist() ); | 324 | // setPlaylist( mediaPlayerState->playlist() ); |
325 | setPlaylist( true); | 325 | setPlaylist( true); |
326 | // d->selectedFiles->first(); | 326 | // d->selectedFiles->first(); |
327 | 327 | ||
328 | } | 328 | } |
329 | 329 | ||
330 | 330 | ||
331 | void PlayListWidget::readConfig( Config& cfg ) { | 331 | void PlayListWidget::readConfig( Config& cfg ) { |
332 | cfg.setGroup("PlayList"); | 332 | cfg.setGroup("PlayList"); |
333 | QString currentString = cfg.readEntry("current", "" ); | 333 | QString currentString = cfg.readEntry("current", "" ); |
334 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 334 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
335 | for ( int i = 0; i < noOfFiles; i++ ) { | 335 | for ( int i = 0; i < noOfFiles; i++ ) { |
336 | QString entryName; | 336 | QString entryName; |
337 | entryName.sprintf( "File%i", i + 1 ); | 337 | entryName.sprintf( "File%i", i + 1 ); |
338 | QString linkFile = cfg.readEntry( entryName ); | 338 | QString linkFile = cfg.readEntry( entryName ); |
339 | DocLnk lnk( linkFile ); | 339 | DocLnk lnk( linkFile ); |
340 | if ( lnk.isValid() ) { | 340 | if ( lnk.isValid() ) { |
341 | d->selectedFiles->addToSelection( lnk ); | 341 | d->selectedFiles->addToSelection( lnk ); |
342 | } | 342 | } |
343 | } | 343 | } |
344 | d->selectedFiles->setSelectedItem( currentString); | 344 | d->selectedFiles->setSelectedItem( currentString); |
345 | // d->selectedFiles->setSelectedItem( (const QString &)currentString); | 345 | // d->selectedFiles->setSelectedItem( (const QString &)currentString); |
346 | } | 346 | } |
347 | 347 | ||
348 | 348 | ||
349 | void PlayListWidget::writeConfig( Config& cfg ) const { | 349 | void PlayListWidget::writeConfig( Config& cfg ) const { |
350 | 350 | ||
351 | d->selectedFiles->writeCurrent( cfg); | 351 | d->selectedFiles->writeCurrent( cfg); |
352 | cfg.setGroup("PlayList"); | 352 | cfg.setGroup("PlayList"); |
353 | int noOfFiles = 0; | 353 | int noOfFiles = 0; |
354 | d->selectedFiles->first(); | 354 | d->selectedFiles->first(); |
355 | do { | 355 | do { |
356 | const DocLnk *lnk = d->selectedFiles->current(); | 356 | const DocLnk *lnk = d->selectedFiles->current(); |
357 | if ( lnk ) { | 357 | if ( lnk ) { |
358 | QString entryName; | 358 | QString entryName; |
359 | entryName.sprintf( "File%i", noOfFiles + 1 ); | 359 | entryName.sprintf( "File%i", noOfFiles + 1 ); |
360 | // qDebug(entryName); | 360 | // qDebug(entryName); |
361 | cfg.writeEntry( entryName, lnk->linkFile() ); | 361 | cfg.writeEntry( entryName, lnk->linkFile() ); |
362 | // if this link does exist, add it so we have the file | 362 | // if this link does exist, add it so we have the file |
363 | // next time... | 363 | // next time... |
364 | if ( !QFile::exists( lnk->linkFile() ) ) { | 364 | if ( !QFile::exists( lnk->linkFile() ) ) { |
365 | // the way writing lnks doesn't really check for out | 365 | // the way writing lnks doesn't really check for out |
366 | // of disk space, but check it anyway. | 366 | // of disk space, but check it anyway. |
367 | if ( !lnk->writeLink() ) { | 367 | if ( !lnk->writeLink() ) { |
368 | QMessageBox::critical( 0, tr("Out of space"), | 368 | QMessageBox::critical( 0, tr("Out of space"), |
369 | tr( "There was a problem saving " | 369 | tr( "There was a problem saving " |
370 | "the playlist.\n" | 370 | "the playlist.\n" |
371 | "Your playlist " | 371 | "Your playlist " |
372 | "may be missing some entries\n" | 372 | "may be missing some entries\n" |
373 | "the next time you start it." ) | 373 | "the next time you start it." ) |
374 | ); | 374 | ); |
375 | } | 375 | } |
376 | } | 376 | } |
377 | noOfFiles++; | 377 | noOfFiles++; |
378 | } | 378 | } |
379 | } | 379 | } |
380 | while ( d->selectedFiles->next() ); | 380 | while ( d->selectedFiles->next() ); |
381 | cfg.writeEntry("NumberOfFiles", noOfFiles ); | 381 | cfg.writeEntry("NumberOfFiles", noOfFiles ); |
382 | } | 382 | } |
383 | 383 | ||
384 | 384 | ||
385 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { | 385 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { |
386 | // qDebug("add"); | 386 | // qDebug("add"); |
387 | d->setDocumentUsed = FALSE; | 387 | d->setDocumentUsed = FALSE; |
388 | if ( mediaPlayerState->playlist() ) | 388 | if ( mediaPlayerState->playlist() ) |
389 | d->selectedFiles->addToSelection( lnk ); | 389 | d->selectedFiles->addToSelection( lnk ); |
390 | else | 390 | else |
391 | mediaPlayerState->setPlaying( TRUE ); | 391 | mediaPlayerState->setPlaying( TRUE ); |
392 | } | 392 | } |
393 | 393 | ||
394 | 394 | ||
395 | void PlayListWidget::clearList() { | 395 | void PlayListWidget::clearList() { |
396 | while ( first() ) | 396 | while ( first() ) |
397 | d->selectedFiles->removeSelected(); | 397 | d->selectedFiles->removeSelected(); |
398 | } | 398 | } |
399 | 399 | ||
400 | 400 | ||
401 | void PlayListWidget::addAllToList() { | 401 | void PlayListWidget::addAllToList() { |
402 | DocLnkSet filesAll; | 402 | DocLnkSet filesAll; |
403 | Global::findDocuments(&filesAll, "video/*;audio/*"); | 403 | Global::findDocuments(&filesAll, "video/*;audio/*"); |
404 | QListIterator<DocLnk> Adit( filesAll.children() ); | 404 | QListIterator<DocLnk> Adit( filesAll.children() ); |
405 | for ( ; Adit.current(); ++Adit ) | 405 | for ( ; Adit.current(); ++Adit ) |
406 | d->selectedFiles->addToSelection( **Adit ); | 406 | d->selectedFiles->addToSelection( **Adit ); |
407 | } | 407 | } |
408 | 408 | ||
409 | 409 | ||
410 | void PlayListWidget::addAllMusicToList() { | 410 | void PlayListWidget::addAllMusicToList() { |
411 | // DocLnkSet files; | 411 | // DocLnkSet files; |
412 | // Global::findDocuments(&files, "audio/*"); | 412 | // Global::findDocuments(&files, "audio/*"); |
413 | QListIterator<DocLnk> dit( files.children() ); | 413 | QListIterator<DocLnk> dit( files.children() ); |
414 | for ( ; dit.current(); ++dit ) | 414 | for ( ; dit.current(); ++dit ) |
415 | d->selectedFiles->addToSelection( **dit ); | 415 | d->selectedFiles->addToSelection( **dit ); |
416 | } | 416 | } |
417 | 417 | ||
418 | 418 | ||
419 | void PlayListWidget::addAllVideoToList() { | 419 | void PlayListWidget::addAllVideoToList() { |
420 | QListIterator<DocLnk> dit( vFiles.children() ); | 420 | QListIterator<DocLnk> dit( vFiles.children() ); |
421 | for ( ; dit.current(); ++dit ) | 421 | for ( ; dit.current(); ++dit ) |
422 | d->selectedFiles->addToSelection( **dit ); | 422 | d->selectedFiles->addToSelection( **dit ); |
423 | } | 423 | } |
424 | 424 | ||
425 | 425 | ||
426 | void PlayListWidget::setDocument(const QString& fileref) { | 426 | void PlayListWidget::setDocument(const QString& fileref) { |
427 | qDebug(fileref); | 427 | qDebug(fileref); |
428 | fromSetDocument = TRUE; | 428 | fromSetDocument = TRUE; |
429 | if ( fileref.isNull() ) { | 429 | if ( fileref.isNull() ) { |
430 | QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); | 430 | QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); |
431 | return; | 431 | return; |
432 | } | 432 | } |
433 | // qDebug("setDocument "+fileref); | 433 | // qDebug("setDocument "+fileref); |
434 | // if(fileref.find("m3u",0,TRUE) != -1) { //is m3u | 434 | // if(fileref.find("m3u",0,TRUE) != -1) { //is m3u |
435 | // clearList(); | 435 | // clearList(); |
436 | // addToSelection( DocLnk( fileref ) ); | 436 | // addToSelection( DocLnk( fileref ) ); |
437 | // d->setDocumentUsed = TRUE; | 437 | // d->setDocumentUsed = TRUE; |
438 | // d->selectedFiles->first(); | 438 | // d->selectedFiles->first(); |
439 | // qApp->processEvents(); | 439 | // qApp->processEvents(); |
440 | // } | 440 | // } |
441 | // else | 441 | // else |
442 | if(fileref.find("playlist",0,TRUE) != -1) {//is playlist | 442 | if(fileref.find("playlist",0,TRUE) != -1) {//is playlist |
443 | clearList(); | 443 | clearList(); |
444 | loadList(DocLnk(fileref)); | 444 | loadList(DocLnk(fileref)); |
445 | d->selectedFiles->first(); | 445 | d->selectedFiles->first(); |
446 | } else { | 446 | } else { |
447 | clearList(); | 447 | clearList(); |
448 | addToSelection( DocLnk( fileref ) ); | 448 | addToSelection( DocLnk( fileref ) ); |
449 | d->setDocumentUsed = TRUE; | 449 | d->setDocumentUsed = TRUE; |
450 | mediaPlayerState->setPlaying( FALSE ); | 450 | mediaPlayerState->setPlaying( FALSE ); |
451 | qApp->processEvents(); | 451 | qApp->processEvents(); |
452 | mediaPlayerState->setPlaying( TRUE ); | 452 | mediaPlayerState->setPlaying( TRUE ); |
453 | qApp->processEvents(); | 453 | qApp->processEvents(); |
454 | setCaption(tr("OpiePlayer")); | 454 | setCaption(tr("OpiePlayer")); |
455 | } | 455 | } |
456 | } | 456 | } |
457 | 457 | ||
458 | 458 | ||
459 | void PlayListWidget::setActiveWindow() { | 459 | void PlayListWidget::setActiveWindow() { |
460 | // When we get raised we need to ensure that it switches views | 460 | // When we get raised we need to ensure that it switches views |
461 | char origView = mediaPlayerState->view(); | 461 | char origView = mediaPlayerState->view(); |
462 | mediaPlayerState->setView( 'l' ); // invalidate | 462 | mediaPlayerState->setView( 'l' ); // invalidate |
463 | mediaPlayerState->setView( origView ); // now switch back | 463 | mediaPlayerState->setView( origView ); // now switch back |
464 | } | 464 | } |
465 | 465 | ||
466 | 466 | ||
467 | void PlayListWidget::useSelectedDocument() { | 467 | void PlayListWidget::useSelectedDocument() { |
468 | d->setDocumentUsed = FALSE; | 468 | d->setDocumentUsed = FALSE; |
469 | } | 469 | } |
470 | 470 | ||
471 | 471 | ||
472 | const DocLnk *PlayListWidget::current() { // this is fugly | 472 | const DocLnk *PlayListWidget::current() { // this is fugly |
473 | 473 | ||
474 | // if( fromSetDocument) { | 474 | // if( fromSetDocument) { |
475 | // qDebug("from setDoc"); | 475 | // qDebug("from setDoc"); |
476 | // DocLnkSet files; | 476 | // DocLnkSet files; |
477 | // Global::findDocuments(&files, "video/*;audio/*"); | 477 | // Global::findDocuments(&files, "video/*;audio/*"); |
478 | // QListIterator<DocLnk> dit( files.children() ); | 478 | // QListIterator<DocLnk> dit( files.children() ); |
479 | // for ( ; dit.current(); ++dit ) { | 479 | // for ( ; dit.current(); ++dit ) { |
480 | // if(dit.current()->linkFile() == setDocFileRef) { | 480 | // if(dit.current()->linkFile() == setDocFileRef) { |
481 | // qDebug(setDocFileRef); | 481 | // qDebug(setDocFileRef); |
482 | // return dit; | 482 | // return dit; |
483 | // } | 483 | // } |
484 | // } | 484 | // } |
485 | // } else | 485 | // } else |
486 | 486 | ||
487 | 487 | ||
488 | switch (tabWidget->currentPageIndex()) { | 488 | switch (tabWidget->currentPageIndex()) { |
489 | case 0: //playlist | 489 | case 0: //playlist |
490 | { | 490 | { |
491 | qDebug("playlist"); | 491 | qDebug("playlist"); |
492 | if ( mediaPlayerState->playlist() ) { | 492 | if ( mediaPlayerState->playlist() ) { |
493 | return d->selectedFiles->current(); | 493 | return d->selectedFiles->current(); |
494 | } | 494 | } |
495 | else if ( d->setDocumentUsed && d->current ) { | 495 | else if ( d->setDocumentUsed && d->current ) { |
496 | return d->current; | 496 | return d->current; |
497 | } else { | 497 | } else { |
498 | return d->files->selected(); | 498 | return d->files->selected(); |
499 | } | 499 | } |
500 | } | 500 | } |
501 | break; | 501 | break; |
502 | case 1://audio | 502 | case 1://audio |
503 | { | 503 | { |
504 | qDebug("audioView"); | 504 | qDebug("audioView"); |
505 | // Global::findDocuments(&files, "audio/*"); | 505 | // Global::findDocuments(&files, "audio/*"); |
506 | QListIterator<DocLnk> dit( files.children() ); | 506 | QListIterator<DocLnk> dit( files.children() ); |
507 | for ( ; dit.current(); ++dit ) { | 507 | for ( ; dit.current(); ++dit ) { |
508 | if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { | 508 | if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { |
509 | qDebug("here"); | 509 | qDebug("here"); |
510 | insanityBool=TRUE; | 510 | insanityBool=TRUE; |
511 | return dit; | 511 | return dit; |
512 | } | 512 | } |
513 | } | 513 | } |
514 | } | 514 | } |
515 | break; | 515 | break; |
516 | case 2: // video | 516 | case 2: // video |
517 | { | 517 | { |
518 | qDebug("videoView"); | 518 | qDebug("videoView"); |
519 | // Global::findDocuments(&vFiles, "video/*"); | 519 | // Global::findDocuments(&vFiles, "video/*"); |
520 | QListIterator<DocLnk> Vdit( vFiles.children() ); | 520 | QListIterator<DocLnk> Vdit( vFiles.children() ); |
521 | for ( ; Vdit.current(); ++Vdit ) { | 521 | for ( ; Vdit.current(); ++Vdit ) { |
522 | if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { | 522 | if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { |
523 | insanityBool=TRUE; | 523 | insanityBool=TRUE; |
524 | return Vdit; | 524 | return Vdit; |
525 | } | 525 | } |
526 | } | 526 | } |
527 | } | 527 | } |
528 | break; | 528 | break; |
529 | }; | 529 | }; |
530 | return 0; | 530 | return 0; |
531 | } | 531 | } |
532 | 532 | ||
533 | bool PlayListWidget::prev() { | 533 | bool PlayListWidget::prev() { |
534 | if ( mediaPlayerState->playlist() ) { | 534 | if ( mediaPlayerState->playlist() ) { |
535 | if ( mediaPlayerState->shuffled() ) { | 535 | if ( mediaPlayerState->shuffled() ) { |
536 | const DocLnk *cur = current(); | 536 | const DocLnk *cur = current(); |
537 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); | 537 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); |
538 | for ( int i = 0; i < j; i++ ) { | 538 | for ( int i = 0; i < j; i++ ) { |
539 | if ( !d->selectedFiles->next() ) | 539 | if ( !d->selectedFiles->next() ) |
540 | d->selectedFiles->first(); | 540 | d->selectedFiles->first(); |
541 | } | 541 | } |
542 | if ( cur == current() ) | 542 | if ( cur == current() ) |
543 | if ( !d->selectedFiles->next() ) | 543 | if ( !d->selectedFiles->next() ) |
544 | d->selectedFiles->first(); | 544 | d->selectedFiles->first(); |
545 | return TRUE; | 545 | return TRUE; |
546 | } else { | 546 | } else { |
547 | if ( !d->selectedFiles->prev() ) { | 547 | if ( !d->selectedFiles->prev() ) { |
548 | if ( mediaPlayerState->looping() ) { | 548 | if ( mediaPlayerState->looping() ) { |
549 | return d->selectedFiles->last(); | 549 | return d->selectedFiles->last(); |
550 | } else { | 550 | } else { |
551 | return FALSE; | 551 | return FALSE; |
552 | } | 552 | } |
553 | } | 553 | } |
554 | return TRUE; | 554 | return TRUE; |
555 | } | 555 | } |
556 | } else { | 556 | } else { |
557 | return mediaPlayerState->looping(); | 557 | return mediaPlayerState->looping(); |
558 | } | 558 | } |
559 | } | 559 | } |
560 | 560 | ||
561 | 561 | ||
562 | bool PlayListWidget::next() { | 562 | bool PlayListWidget::next() { |
563 | if ( mediaPlayerState->playlist() ) { | 563 | if ( mediaPlayerState->playlist() ) { |
564 | if ( mediaPlayerState->shuffled() ) { | 564 | if ( mediaPlayerState->shuffled() ) { |
565 | return prev(); | 565 | return prev(); |
566 | } else { | 566 | } else { |
567 | if ( !d->selectedFiles->next() ) { | 567 | if ( !d->selectedFiles->next() ) { |
568 | if ( mediaPlayerState->looping() ) { | 568 | if ( mediaPlayerState->looping() ) { |
569 | return d->selectedFiles->first(); | 569 | return d->selectedFiles->first(); |
570 | } else { | 570 | } else { |
571 | return FALSE; | 571 | return FALSE; |
572 | } | 572 | } |
573 | } | 573 | } |
574 | return TRUE; | 574 | return TRUE; |
575 | } | 575 | } |
576 | } else { | 576 | } else { |
577 | return mediaPlayerState->looping(); | 577 | return mediaPlayerState->looping(); |
578 | } | 578 | } |
579 | } | 579 | } |
580 | 580 | ||
581 | 581 | ||
582 | bool PlayListWidget::first() { | 582 | bool PlayListWidget::first() { |
583 | if ( mediaPlayerState->playlist() ) | 583 | if ( mediaPlayerState->playlist() ) |
584 | return d->selectedFiles->first(); | 584 | return d->selectedFiles->first(); |
585 | else | 585 | else |
586 | return mediaPlayerState->looping(); | 586 | return mediaPlayerState->looping(); |
587 | } | 587 | } |
588 | 588 | ||
589 | 589 | ||
590 | bool PlayListWidget::last() { | 590 | bool PlayListWidget::last() { |
591 | if ( mediaPlayerState->playlist() ) | 591 | if ( mediaPlayerState->playlist() ) |
592 | return d->selectedFiles->last(); | 592 | return d->selectedFiles->last(); |
593 | else | 593 | else |
594 | return mediaPlayerState->looping(); | 594 | return mediaPlayerState->looping(); |
595 | } | 595 | } |
596 | 596 | ||
597 | 597 | ||
598 | void PlayListWidget::saveList() { | 598 | void PlayListWidget::saveList() { |
599 | 599 | ||
600 | QString filename; | 600 | QString filename; |
601 | InputDialog *fileDlg; | 601 | InputDialog *fileDlg; |
602 | fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0); | 602 | fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0); |
603 | fileDlg->exec(); | 603 | fileDlg->exec(); |
604 | if( fileDlg->result() == 1 ) { | 604 | if( fileDlg->result() == 1 ) { |
605 | if ( d->current ) | 605 | if ( d->current ) |
606 | delete d->current; | 606 | delete d->current; |
607 | filename = fileDlg->LineEdit1->text();//+".playlist"; | 607 | filename = fileDlg->LineEdit1->text();//+".playlist"; |
608 | // qDebug("saving playlist "+filename+".playlist"); | 608 | // qDebug("saving playlist "+filename+".playlist"); |
609 | Config cfg( filename +".playlist"); | 609 | Config cfg( filename +".playlist"); |
610 | writeConfig( cfg ); | 610 | writeConfig( cfg ); |
611 | 611 | ||
612 | // qDebug("same name so delete lnk??"); | 612 | // qDebug("same name so delete lnk??"); |
613 | // if( playLists->selected()->name() == filename) { | 613 | // if( playLists->selected()->name() == filename) { |
614 | 614 | ||
615 | // qDebug("same name so delete lnk"); | 615 | // qDebug("same name so delete lnk"); |
616 | // QFile().remove(playLists->selected()->file()); | 616 | // QFile().remove(playLists->selected()->file()); |
617 | // QFile().remove(playLists->selected()->linkFile()); | 617 | // QFile().remove(playLists->selected()->linkFile()); |
618 | // playLists->reread(); | 618 | // playLists->reread(); |
619 | // } | 619 | // } |
620 | // qDebug("new doclnk"); | 620 | // qDebug("new doclnk"); |
621 | DocLnk lnk; | 621 | DocLnk lnk; |
622 | // lnk.setComment( ""); | 622 | // lnk.setComment( ""); |
623 | lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property | 623 | lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property |
624 | lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D | 624 | lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D |
625 | lnk.setIcon("opieplayer/playlist2"); | 625 | lnk.setIcon("opieplayer/playlist2"); |
626 | lnk.setName( filename); //sets file name | 626 | lnk.setName( filename); //sets file name |
627 | // qDebug(filename); | 627 | // qDebug(filename); |
628 | if(!lnk.writeLink()) | 628 | if(!lnk.writeLink()) |
629 | qDebug("Writing doclink did not work"); | 629 | qDebug("Writing doclink did not work"); |
630 | } | 630 | } |
631 | Config config( "OpiePlayer" ); | 631 | Config config( "OpiePlayer" ); |
632 | config.writeEntry("CurrentPlaylist",filename); | 632 | config.writeEntry("CurrentPlaylist",filename); |
633 | setCaption(tr("OpiePlayer: ")+filename); | 633 | setCaption(tr("OpiePlayer: ")+filename); |
634 | d->selectedFiles->first(); | 634 | d->selectedFiles->first(); |
635 | if(fileDlg) | 635 | if(fileDlg) |
636 | delete fileDlg; | 636 | delete fileDlg; |
637 | } | 637 | } |
638 | 638 | ||
639 | void PlayListWidget::loadList( const DocLnk & lnk) { | 639 | void PlayListWidget::loadList( const DocLnk & lnk) { |
640 | QString name= lnk.name(); | 640 | QString name= lnk.name(); |
641 | // qDebug("currentList is "+name); | 641 | // qDebug("currentList is "+name); |
642 | if( name.length()>1) { | 642 | if( name.length()>1) { |
643 | setCaption("OpiePlayer: "+name); | 643 | setCaption("OpiePlayer: "+name); |
644 | // qDebug("load list "+ name+".playlist"); | 644 | // qDebug("load list "+ name+".playlist"); |
645 | clearList(); | 645 | clearList(); |
646 | Config cfg( name+".playlist"); | 646 | Config cfg( name+".playlist"); |
647 | readConfig(cfg); | 647 | readConfig(cfg); |
648 | 648 | ||
649 | tabWidget->setCurrentPage(0); | 649 | tabWidget->setCurrentPage(0); |
650 | 650 | ||
651 | Config config( "OpiePlayer" ); | 651 | Config config( "OpiePlayer" ); |
652 | config.writeEntry("CurrentPlaylist", name); | 652 | config.writeEntry("CurrentPlaylist", name); |
653 | // d->selectedFiles->first(); | 653 | // d->selectedFiles->first(); |
654 | } | 654 | } |
655 | 655 | ||
656 | } | 656 | } |
657 | 657 | ||
658 | void PlayListWidget::setPlaylist( bool shown ) { | 658 | void PlayListWidget::setPlaylist( bool shown ) { |
659 | if ( shown ) | 659 | if ( shown ) |
660 | d->playListFrame->show(); | 660 | d->playListFrame->show(); |
661 | else | 661 | else |
662 | d->playListFrame->hide(); | 662 | d->playListFrame->hide(); |
663 | } | 663 | } |
664 | 664 | ||
665 | void PlayListWidget::setView( char view ) { | 665 | void PlayListWidget::setView( char view ) { |
666 | if ( view == 'l' ) | 666 | if ( view == 'l' ) |
667 | showMaximized(); | 667 | showMaximized(); |
668 | else | 668 | else |
669 | hide(); | 669 | hide(); |
670 | } | 670 | } |
671 | 671 | ||
672 | void PlayListWidget::addSelected() { | 672 | void PlayListWidget::addSelected() { |
673 | 673 | ||
674 | Config cfg( "OpiePlayer" ); | 674 | Config cfg( "OpiePlayer" ); |
675 | cfg.setGroup("PlayList"); | 675 | cfg.setGroup("PlayList"); |
676 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | 676 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); |
677 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 677 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
678 | 678 | ||
679 | switch (tabWidget->currentPageIndex()) { | 679 | switch (tabWidget->currentPageIndex()) { |
680 | case 0: //playlist | 680 | case 0: //playlist |
681 | break; | 681 | break; |
682 | case 1: { //audio | 682 | case 1: { //audio |
683 | for ( int i = 0; i < noOfFiles; i++ ) { | 683 | for ( int i = 0; i < noOfFiles; i++ ) { |
684 | QString entryName; | 684 | QString entryName; |
685 | entryName.sprintf( "File%i", i + 1 ); | 685 | entryName.sprintf( "File%i", i + 1 ); |
686 | QString linkFile = cfg.readEntry( entryName ); | 686 | QString linkFile = cfg.readEntry( entryName ); |
687 | if( DocLnk( linkFile).name() == audioView->selectedItem()->text(0) ) { | 687 | if( DocLnk( linkFile).name() == audioView->selectedItem()->text(0) ) { |
688 | int result= QMessageBox::warning(this,tr("OpiePlayer"), | 688 | int result= QMessageBox::warning(this,tr("OpiePlayer"), |
689 | tr("This is all ready in your playlist.\nContinue?"), | 689 | tr("This is all ready in your playlist.\nContinue?"), |
690 | tr("Yes"),tr("No"),0,0,1); | 690 | tr("Yes"),tr("No"),0,0,1); |
691 | if (result !=0) | 691 | if (result !=0) |
692 | return; | 692 | return; |
693 | } | 693 | } |
694 | } | 694 | } |
695 | addToSelection( audioView->selectedItem() ); | 695 | addToSelection( audioView->selectedItem() ); |
696 | tabWidget->setCurrentPage(1); | 696 | tabWidget->setCurrentPage(1); |
697 | } | 697 | } |
698 | break; | 698 | break; |
699 | case 2: { // video | 699 | case 2: { // video |
700 | for ( int i = 0; i < noOfFiles; i++ ) { | 700 | for ( int i = 0; i < noOfFiles; i++ ) { |
701 | QString entryName; | 701 | QString entryName; |
702 | entryName.sprintf( "File%i", i + 1 ); | 702 | entryName.sprintf( "File%i", i + 1 ); |
703 | QString linkFile = cfg.readEntry( entryName ); | 703 | QString linkFile = cfg.readEntry( entryName ); |
704 | if( DocLnk( linkFile).name() == videoView->selectedItem()->text(0) ) { | 704 | if( DocLnk( linkFile).name() == videoView->selectedItem()->text(0) ) { |
705 | int result= QMessageBox::warning(this,tr("OpiePlayer"), | 705 | int result= QMessageBox::warning(this,tr("OpiePlayer"), |
706 | tr("This is all ready in your playlist.\nContinue?"), | 706 | tr("This is all ready in your playlist.\nContinue?"), |
707 | tr("Yes"),tr("No"),0,0,1); | 707 | tr("Yes"),tr("No"),0,0,1); |
708 | if (result !=0) | 708 | if (result !=0) |
709 | return; | 709 | return; |
710 | } | 710 | } |
711 | } | 711 | } |
712 | addToSelection( videoView->selectedItem() ); | 712 | addToSelection( videoView->selectedItem() ); |
713 | tabWidget->setCurrentPage(2); | 713 | tabWidget->setCurrentPage(2); |
714 | } | 714 | } |
715 | break; | 715 | break; |
716 | }; | 716 | }; |
717 | } | 717 | } |
718 | 718 | ||
719 | void PlayListWidget::removeSelected() { | 719 | void PlayListWidget::removeSelected() { |
720 | d->selectedFiles->removeSelected( ); | 720 | d->selectedFiles->removeSelected( ); |
721 | } | 721 | } |
722 | 722 | ||
723 | void PlayListWidget::playIt( QListViewItem *it) { | 723 | void PlayListWidget::playIt( QListViewItem *it) { |
724 | // d->setDocumentUsed = FALSE; | 724 | // d->setDocumentUsed = FALSE; |
725 | mediaPlayerState->setPlaying(TRUE); | 725 | mediaPlayerState->setPlaying(TRUE); |
726 | } | 726 | } |
727 | 727 | ||
728 | void PlayListWidget::addToSelection( QListViewItem *it) { | 728 | void PlayListWidget::addToSelection( QListViewItem *it) { |
729 | d->setDocumentUsed = FALSE; | 729 | d->setDocumentUsed = FALSE; |
730 | 730 | ||
731 | if(it) { | 731 | if(it) { |
732 | switch (tabWidget->currentPageIndex()) { | 732 | switch (tabWidget->currentPageIndex()) { |
733 | case 1: { | 733 | case 1: { |
734 | QListIterator<DocLnk> dit( files.children() ); | 734 | QListIterator<DocLnk> dit( files.children() ); |
735 | for ( ; dit.current(); ++dit ) { | 735 | for ( ; dit.current(); ++dit ) { |
736 | if( dit.current()->name() == it->text(0)) { | 736 | if( dit.current()->name() == it->text(0)) { |
737 | d->selectedFiles->addToSelection( **dit ); | 737 | d->selectedFiles->addToSelection( **dit ); |
738 | } | 738 | } |
739 | } | 739 | } |
740 | } | 740 | } |
741 | break; | 741 | break; |
742 | case 2: { | 742 | case 2: { |
743 | QListIterator<DocLnk> dit( vFiles.children() ); | 743 | QListIterator<DocLnk> dit( vFiles.children() ); |
744 | for ( ; dit.current(); ++dit ) { | 744 | for ( ; dit.current(); ++dit ) { |
745 | if( dit.current()->name() == it->text(0)) { | 745 | if( dit.current()->name() == it->text(0)) { |
746 | d->selectedFiles->addToSelection( **dit ); | 746 | d->selectedFiles->addToSelection( **dit ); |
747 | } | 747 | } |
748 | } | 748 | } |
749 | } | 749 | } |
750 | break; | 750 | break; |
751 | case 0: | 751 | case 0: |
752 | break; | 752 | break; |
753 | }; | 753 | }; |
754 | tabWidget->setCurrentPage(0); | 754 | tabWidget->setCurrentPage(0); |
755 | } | 755 | } |
756 | } | 756 | } |
757 | 757 | ||
758 | void PlayListWidget::tabChanged(QWidget *widg) { | 758 | void PlayListWidget::tabChanged(QWidget *widg) { |
759 | 759 | ||
760 | switch ( tabWidget->currentPageIndex()) { | 760 | switch ( tabWidget->currentPageIndex()) { |
761 | case 0: | 761 | case 0: |
762 | { | 762 | { |
763 | if( !tbDeletePlaylist->isHidden()) | 763 | if( !tbDeletePlaylist->isHidden()) |
764 | tbDeletePlaylist->hide(); | 764 | tbDeletePlaylist->hide(); |
765 | d->tbRemoveFromList->setEnabled(TRUE); | 765 | d->tbRemoveFromList->setEnabled(TRUE); |
766 | d->tbAddToList->setEnabled(FALSE); | 766 | d->tbAddToList->setEnabled(FALSE); |
767 | } | 767 | } |
768 | break; | 768 | break; |
769 | case 1: | 769 | case 1: |
770 | { | 770 | { |
771 | if( !tbDeletePlaylist->isHidden()) | 771 | if( !tbDeletePlaylist->isHidden()) |
772 | tbDeletePlaylist->hide(); | 772 | tbDeletePlaylist->hide(); |
773 | d->tbRemoveFromList->setEnabled(FALSE); | 773 | d->tbRemoveFromList->setEnabled(FALSE); |
774 | d->tbAddToList->setEnabled(TRUE); | 774 | d->tbAddToList->setEnabled(TRUE); |
775 | } | 775 | } |
776 | break; | 776 | break; |
777 | case 2: | 777 | case 2: |
778 | { | 778 | { |
779 | if( !tbDeletePlaylist->isHidden()) | 779 | if( !tbDeletePlaylist->isHidden()) |
780 | tbDeletePlaylist->hide(); | 780 | tbDeletePlaylist->hide(); |
781 | d->tbRemoveFromList->setEnabled(FALSE); | 781 | d->tbRemoveFromList->setEnabled(FALSE); |
782 | d->tbAddToList->setEnabled(TRUE); | 782 | d->tbAddToList->setEnabled(TRUE); |
783 | } | 783 | } |
784 | break; | 784 | break; |
785 | case 3: | 785 | case 3: |
786 | { | 786 | { |
787 | if( tbDeletePlaylist->isHidden()) | 787 | if( tbDeletePlaylist->isHidden()) |
788 | tbDeletePlaylist->show(); | 788 | tbDeletePlaylist->show(); |
789 | playLists->reread(); | 789 | playLists->reread(); |
790 | } | 790 | } |
791 | break; | 791 | break; |
792 | }; | 792 | }; |
793 | } | 793 | } |
794 | 794 | ||
795 | 795 | ||
796 | 796 | ||
797 | void PlayListWidget::btnPlay(bool b) { | 797 | void PlayListWidget::btnPlay(bool b) { |
798 | 798 | ||
799 | // mediaPlayerState->setPlaying(b); | 799 | // mediaPlayerState->setPlaying(b); |
800 | switch ( tabWidget->currentPageIndex()) { | 800 | switch ( tabWidget->currentPageIndex()) { |
801 | case 0: | 801 | case 0: |
802 | { | 802 | { |
803 | mediaPlayerState->setPlaying(b); | 803 | mediaPlayerState->setPlaying(b); |
804 | } | 804 | } |
805 | break; | 805 | break; |
806 | case 1: | 806 | case 1: |
807 | { | 807 | { |
808 | addToSelection( audioView->selectedItem() ); | 808 | addToSelection( audioView->selectedItem() ); |
809 | mediaPlayerState->setPlaying(b); | 809 | mediaPlayerState->setPlaying(b); |
810 | d->selectedFiles->removeSelected( ); | 810 | d->selectedFiles->removeSelected( ); |
811 | tabWidget->setCurrentPage(1); | 811 | tabWidget->setCurrentPage(1); |
812 | d->selectedFiles->unSelect(); | 812 | d->selectedFiles->unSelect(); |
813 | // audioView->clearSelection(); | 813 | // audioView->clearSelection(); |
814 | } | 814 | } |
815 | break; | 815 | break; |
816 | case 2: | 816 | case 2: |
817 | { | 817 | { |
818 | addToSelection( videoView->selectedItem() ); | 818 | addToSelection( videoView->selectedItem() ); |
819 | mediaPlayerState->setPlaying(b); | 819 | mediaPlayerState->setPlaying(b); |
820 | qApp->processEvents(); | 820 | qApp->processEvents(); |
821 | d->selectedFiles->removeSelected( ); | 821 | d->selectedFiles->removeSelected( ); |
822 | tabWidget->setCurrentPage(2); | 822 | tabWidget->setCurrentPage(2); |
823 | d->selectedFiles->unSelect(); | 823 | d->selectedFiles->unSelect(); |
824 | // videoView->clearSelection(); | 824 | // videoView->clearSelection(); |
825 | } | 825 | } |
826 | break; | 826 | break; |
827 | }; | 827 | }; |
828 | } | 828 | } |
829 | 829 | ||
830 | void PlayListWidget::deletePlaylist() { | 830 | void PlayListWidget::deletePlaylist() { |
831 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), | 831 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), |
832 | (tr("You really want to delete\nthis playlist?")), | 832 | (tr("You really want to delete\nthis playlist?")), |
833 | (tr("Yes")), (tr("No")), 0 )){ | 833 | (tr("Yes")), (tr("No")), 0 )){ |
834 | case 0: // Yes clicked, | 834 | case 0: // Yes clicked, |
835 | QFile().remove(playLists->selected()->file()); | 835 | QFile().remove(playLists->selected()->file()); |
836 | QFile().remove(playLists->selected()->linkFile()); | 836 | QFile().remove(playLists->selected()->linkFile()); |
837 | playLists->reread(); | 837 | playLists->reread(); |
838 | break; | 838 | break; |
839 | case 1: // Cancel | 839 | case 1: // Cancel |
840 | break; | 840 | break; |
841 | }; | 841 | }; |
842 | 842 | ||
843 | } | 843 | } |
844 | 844 | ||
845 | void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) | 845 | void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) |
846 | { | 846 | { |
847 | switch (mouse) { | 847 | switch (mouse) { |
848 | case 1: | 848 | case 1: |
849 | break; | 849 | break; |
850 | case 2:{ | 850 | case 2:{ |
851 | QPopupMenu m; | 851 | QPopupMenu m; |
852 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); | 852 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); |
853 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); | 853 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); |
854 | m.insertSeparator(); | 854 | m.insertSeparator(); |
855 | m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); | 855 | m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); |
856 | m.exec( QCursor::pos() ); | 856 | m.exec( QCursor::pos() ); |
857 | } | 857 | } |
858 | break; | 858 | break; |
859 | }; | 859 | }; |
860 | } | 860 | } |
861 | 861 | ||
862 | void PlayListWidget::playSelected() | 862 | void PlayListWidget::playSelected() |
863 | { | 863 | { |
864 | btnPlay( TRUE); | 864 | btnPlay( TRUE); |
865 | } | 865 | } |
866 | 866 | ||
867 | void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) | 867 | void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) |
868 | { | 868 | { |
869 | switch (mouse) { | 869 | switch (mouse) { |
870 | case 1: | 870 | case 1: |
871 | break; | 871 | break; |
872 | case 2:{ | 872 | case 2:{ |
873 | QPopupMenu m; | 873 | QPopupMenu m; |
874 | m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); | 874 | m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); |
875 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); | 875 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); |
876 | // m.insertSeparator(); | 876 | // m.insertSeparator(); |
877 | m.exec( QCursor::pos() ); | 877 | m.exec( QCursor::pos() ); |
878 | } | 878 | } |
879 | break; | 879 | break; |
880 | }; | 880 | }; |
881 | 881 | ||
882 | } | 882 | } |
883 | 883 | ||
884 | void PlayListWidget::listDelete() { | 884 | void PlayListWidget::listDelete() { |
885 | Config cfg( "OpiePlayer" ); | 885 | Config cfg( "OpiePlayer" ); |
886 | cfg.setGroup("PlayList"); | 886 | cfg.setGroup("PlayList"); |
887 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | 887 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); |
888 | QString file; | 888 | QString file; |
889 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 889 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
890 | switch ( tabWidget->currentPageIndex()) { | 890 | switch ( tabWidget->currentPageIndex()) { |
891 | case 0: | 891 | case 0: |
892 | break; | 892 | break; |
893 | case 1: | 893 | case 1: |
894 | { | 894 | { |
895 | file = audioView->selectedItem()->text(0); | 895 | file = audioView->selectedItem()->text(0); |
896 | // Global::findDocuments(&files, "audio/*"); | 896 | // Global::findDocuments(&files, "audio/*"); |
897 | // AppLnkSet appFiles; | 897 | // AppLnkSet appFiles; |
898 | QListIterator<DocLnk> dit( files.children() ); | 898 | QListIterator<DocLnk> dit( files.children() ); |
899 | for ( ; dit.current(); ++dit ) { | 899 | for ( ; dit.current(); ++dit ) { |
900 | if( dit.current()->name() == file) { | 900 | if( dit.current()->name() == file) { |
901 | // qDebug(file); | 901 | // qDebug(file); |
902 | LnkProperties prop( dit.current() ); | 902 | LnkProperties prop( dit.current() ); |
903 | // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); | 903 | // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); |
904 | prop.showMaximized(); | 904 | prop.showMaximized(); |
905 | prop.exec(); | 905 | prop.exec(); |
906 | } | 906 | } |
907 | } | 907 | } |
908 | populateAudioView(); | 908 | populateAudioView(); |
909 | } | 909 | } |
910 | break; | 910 | break; |
911 | case 2: | 911 | case 2: |
912 | { | 912 | { |
913 | // file = videoView->selectedItem()->text(0); | 913 | // file = videoView->selectedItem()->text(0); |
914 | // for ( int i = 0; i < noOfFiles; i++ ) { | 914 | // for ( int i = 0; i < noOfFiles; i++ ) { |
915 | // QString entryName; | 915 | // QString entryName; |
916 | // entryName.sprintf( "File%i", i + 1 ); | 916 | // entryName.sprintf( "File%i", i + 1 ); |
917 | // QString linkFile = cfg.readEntry( entryName ); | 917 | // QString linkFile = cfg.readEntry( entryName ); |
918 | // AppLnk lnk( AppLnk(linkFile)); | 918 | // AppLnk lnk( AppLnk(linkFile)); |
919 | // if( lnk.name() == file ) { | 919 | // if( lnk.name() == file ) { |
920 | // LnkProperties prop( &lnk); | 920 | // LnkProperties prop( &lnk); |
921 | // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); | 921 | // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); |
922 | // prop.showMaximized(); | 922 | // prop.showMaximized(); |
923 | // prop.exec(); | 923 | // prop.exec(); |
924 | // } | 924 | // } |
925 | // } | 925 | // } |
926 | } | 926 | } |
927 | break; | 927 | break; |
928 | }; | 928 | }; |
929 | } | 929 | } |
930 | 930 | ||
931 | void PlayListWidget::populateAudioView() { | 931 | void PlayListWidget::populateAudioView() { |
932 | // if(files) | 932 | // if(files) |
933 | // files.~DocLnkSet(); | 933 | // files.~DocLnkSet(); |
934 | StorageInfo storageInfo; | 934 | StorageInfo storageInfo; |
935 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 935 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
936 | 936 | ||
937 | Global::findDocuments(&files, "audio/*"); | 937 | Global::findDocuments(&files, "audio/*"); |
938 | QListIterator<DocLnk> dit( files.children() ); | 938 | QListIterator<DocLnk> dit( files.children() ); |
939 | QListIterator<FileSystem> it ( fs ); | 939 | QListIterator<FileSystem> it ( fs ); |
940 | audioView->clear(); | 940 | audioView->clear(); |
941 | QString storage; | 941 | QString storage; |
942 | for ( ; dit.current(); ++dit ) { | 942 | for ( ; dit.current(); ++dit ) { |
943 | for( ; it.current(); ++it ){ | 943 | for( ; it.current(); ++it ){ |
944 | const QString name = (*it)->name(); | 944 | const QString name = (*it)->name(); |
945 | const QString path = (*it)->path(); | 945 | const QString path = (*it)->path(); |
946 | if(dit.current()->file().find(path) != -1 ) storage=name; | 946 | if(dit.current()->file().find(path) != -1 ) storage=name; |
947 | } | 947 | } |
948 | 948 | ||
949 | QListViewItem * newItem; | 949 | QListViewItem * newItem; |
950 | if ( QFile( dit.current()->file()).exists() ) { | 950 | if ( QFile( dit.current()->file()).exists() ) { |
951 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage); | 951 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage); |
952 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); | 952 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); |
953 | } | 953 | } |
954 | } | 954 | } |
955 | } | 955 | } |
956 | 956 | ||
957 | void PlayListWidget::populateVideoView() { | 957 | void PlayListWidget::populateVideoView() { |
958 | StorageInfo storageInfo; | 958 | StorageInfo storageInfo; |
959 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 959 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
960 | 960 | ||
961 | Global::findDocuments(&vFiles, "video/*"); | 961 | Global::findDocuments(&vFiles, "video/*"); |
962 | QListIterator<DocLnk> Vdit( vFiles.children() ); | 962 | QListIterator<DocLnk> Vdit( vFiles.children() ); |
963 | QListIterator<FileSystem> it ( fs ); | 963 | QListIterator<FileSystem> it ( fs ); |
964 | videoView->clear(); | 964 | videoView->clear(); |
965 | QString storage; | 965 | QString storage; |
966 | for ( ; Vdit.current(); ++Vdit ) { | 966 | for ( ; Vdit.current(); ++Vdit ) { |
967 | for( ; it.current(); ++it ){ | 967 | for( ; it.current(); ++it ){ |
968 | const QString name = (*it)->name(); | 968 | const QString name = (*it)->name(); |
969 | const QString path = (*it)->path(); | 969 | const QString path = (*it)->path(); |
970 | if( Vdit.current()->file().find(path) != -1 ) storage=name; | 970 | if( Vdit.current()->file().find(path) != -1 ) storage=name; |
971 | } | 971 | } |
972 | 972 | ||
973 | QListViewItem * newItem; | 973 | QListViewItem * newItem; |
974 | if ( QFile( Vdit.current()->file()).exists() ) { | 974 | if ( QFile( Vdit.current()->file()).exists() ) { |
975 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage); | 975 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage); |
976 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); | 976 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); |
977 | } | 977 | } |
978 | } | 978 | } |
979 | } | 979 | } |
980 | 980 | ||
981 | void PlayListWidget::openFile() { | 981 | void PlayListWidget::openFile() { |
982 | QString filename, name; | 982 | QString filename, name; |
983 | InputDialog *fileDlg; | 983 | InputDialog *fileDlg; |
984 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); | 984 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); |
985 | fileDlg->exec(); | 985 | fileDlg->exec(); |
986 | if( fileDlg->result() == 1 ) { | 986 | if( fileDlg->result() == 1 ) { |
987 | filename = fileDlg->LineEdit1->text(); | 987 | filename = fileDlg->LineEdit1->text(); |
988 | 988 | ||
989 | // InputDialog *fileDlg2; | 989 | // InputDialog *fileDlg2; |
990 | // fileDlg2 = new InputDialog(this,tr("Name"),TRUE, 0); | 990 | // fileDlg2 = new InputDialog(this,tr("Name"),TRUE, 0); |
991 | // fileDlg2->exec(); | 991 | // fileDlg2->exec(); |
992 | // if( fileDlg2->result() == 1 ) { | 992 | // if( fileDlg2->result() == 1 ) { |
993 | // name = fileDlg2->LineEdit1->text(); | 993 | // name = fileDlg2->LineEdit1->text(); |
994 | // } | 994 | // } |
995 | //http://205.188.234.129:8030 | 995 | //http://205.188.234.129:8030 |
996 | // http://66.28.68.70:8000 | ||
996 | qDebug(filename); | 997 | qDebug(filename); |
997 | DocLnk lnk; | 998 | DocLnk lnk; |
998 | // if(filename.left(7) == "http://") | 999 | // if(filename.left(7) == "http://") |
999 | // name= filename.right(filename.length()-filename.find("http://")-7); | 1000 | // name= filename.right(filename.length()-filename.find("http://")-7); |
1000 | // else name = filename; | 1001 | // else name = filename; |
1001 | // qDebug("name is "+name); | 1002 | // qDebug("name is "+name); |
1002 | // lnk.setComment(filename); | 1003 | // lnk.setComment(filename); |
1003 | lnk.setName(filename); //sets file name | 1004 | lnk.setName(filename); //sets file name |
1004 | if(filename.right(1) != "/" && filename.right(3) != "mp3" && filename.right(3) != "MP3") | 1005 | if(filename.right(1) != "/" && filename.right(3) != "mp3" && filename.right(3) != "MP3") |
1005 | filename += "/"; | 1006 | filename += "/"; |
1006 | lnk.setFile(filename); //sets File property | 1007 | lnk.setFile(filename); //sets File property |
1007 | 1008 | ||
1008 | lnk.setType("audio/x-mpegurl"); | 1009 | lnk.setType("audio/x-mpegurl"); |
1009 | lnk.setExec("opieplayer"); | 1010 | lnk.setExec("opieplayer"); |
1010 | lnk.setIcon("opieplayer/MPEGPlayer"); | 1011 | lnk.setIcon("opieplayer/MPEGPlayer"); |
1011 | 1012 | ||
1012 | if(!lnk.writeLink()) | 1013 | if(!lnk.writeLink()) |
1013 | qDebug("Writing doclink did not work"); | 1014 | qDebug("Writing doclink did not work"); |
1014 | d->selectedFiles->addToSelection( lnk); | 1015 | d->selectedFiles->addToSelection( lnk); |
1015 | // if(fileDlg2) | 1016 | // if(fileDlg2) |
1016 | // delete fileDlg2; | 1017 | // delete fileDlg2; |
1017 | } | 1018 | } |
1018 | 1019 | ||
1019 | if(fileDlg) | 1020 | if(fileDlg) |
1020 | delete fileDlg; | 1021 | delete fileDlg; |
1021 | } | 1022 | } |