summaryrefslogtreecommitdiff
authorsimon <simon>2002-12-02 23:33:37 (UTC)
committer simon <simon>2002-12-02 23:33:37 (UTC)
commitc3c95ff297355f7024c15134bbc1d15d340bf8fd (patch) (unidiff)
treead5ed1eef8ad82d53aef634bfa4b247210200c20
parent22e232bdb4bae5e28013a4d14bfda3c068827557 (diff)
downloadopie-c3c95ff297355f7024c15134bbc1d15d340bf8fd.zip
opie-c3c95ff297355f7024c15134bbc1d15d340bf8fd.tar.gz
opie-c3c95ff297355f7024c15134bbc1d15d340bf8fd.tar.bz2
- I better be a good boy and delete what I allocate :)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/mediaplayer.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/mediaplayer.cpp b/noncore/multimedia/opieplayer2/mediaplayer.cpp
index 8acc488..06b1a04 100644
--- a/noncore/multimedia/opieplayer2/mediaplayer.cpp
+++ b/noncore/multimedia/opieplayer2/mediaplayer.cpp
@@ -1,254 +1,256 @@
1#include <qpe/qpeapplication.h> 1#include <qpe/qpeapplication.h>
2#include <qpe/qlibrary.h> 2#include <qpe/qlibrary.h>
3#include <qpe/resource.h> 3#include <qpe/resource.h>
4#include <qpe/config.h> 4#include <qpe/config.h>
5#include <qpe/qcopenvelope_qws.h> 5#include <qpe/qcopenvelope_qws.h>
6#include <qfileinfo.h> 6#include <qfileinfo.h>
7 7
8#include <qmainwindow.h> 8#include <qmainwindow.h>
9#include <qmessagebox.h> 9#include <qmessagebox.h>
10#include <qwidgetstack.h> 10#include <qwidgetstack.h>
11#include <qfile.h> 11#include <qfile.h>
12 12
13#include "mediaplayer.h" 13#include "mediaplayer.h"
14#include "playlistwidget.h" 14#include "playlistwidget.h"
15#include "audiowidget.h" 15#include "audiowidget.h"
16#include "videowidget.h" 16#include "videowidget.h"
17#include "volumecontrol.h" 17#include "volumecontrol.h"
18 18
19#include "mediaplayerstate.h" 19#include "mediaplayerstate.h"
20 20
21// for setBacklight() 21// for setBacklight()
22#include <linux/fb.h> 22#include <linux/fb.h>
23#include <sys/file.h> 23#include <sys/file.h>
24#include <sys/ioctl.h> 24#include <sys/ioctl.h>
25 25
26 26
27 27
28 28
29#define FBIOBLANK 0x4611 29#define FBIOBLANK 0x4611
30 30
31MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name ) 31MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name )
32 : QObject( parent, name ), volumeDirection( 0 ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) { 32 : QObject( parent, name ), volumeDirection( 0 ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) {
33 33
34 audioUI = 0; 34 audioUI = 0;
35 videoUI = 0; 35 videoUI = 0;
36 xineControl = 0; 36 xineControl = 0;
37 recreateAudioAndVideoWidgets(); 37 recreateAudioAndVideoWidgets();
38 38
39 fd=-1;fl=-1; 39 fd=-1;fl=-1;
40 playList.setCaption( tr( "OpiePlayer: Initializating" ) ); 40 playList.setCaption( tr( "OpiePlayer: Initializating" ) );
41 41
42 qApp->processEvents(); 42 qApp->processEvents();
43 // QPEApplication::grabKeyboard(); // EVIL 43 // QPEApplication::grabKeyboard(); // EVIL
44 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); 44 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
45 45
46 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); 46 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) );
47 47
48 connect( &mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); 48 connect( &mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) );
49 49
50 connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); 50 connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) );
51 connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); 51 connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) );
52 connect( &mediaPlayerState, SIGNAL( blankToggled( bool ) ), this, SLOT ( blank( bool ) ) ); 52 connect( &mediaPlayerState, SIGNAL( blankToggled( bool ) ), this, SLOT ( blank( bool ) ) );
53 53
54 volControl = new VolumeControl; 54 volControl = new VolumeControl;
55 Config cfg( "OpiePlayer" ); 55 Config cfg( "OpiePlayer" );
56 cfg.setGroup("PlayList"); 56 cfg.setGroup("PlayList");
57 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); 57 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default");
58 playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() ); 58 playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() );
59} 59}
60 60
61MediaPlayer::~MediaPlayer() { 61MediaPlayer::~MediaPlayer() {
62 delete xineControl; 62 delete xineControl;
63 delete audioUI;
64 delete videoUI;
63 delete volControl; 65 delete volControl;
64} 66}
65 67
66void MediaPlayer::pauseCheck( bool b ) { 68void MediaPlayer::pauseCheck( bool b ) {
67 if ( b && !mediaPlayerState.isPlaying() ) { 69 if ( b && !mediaPlayerState.isPlaying() ) {
68 mediaPlayerState.setPaused( FALSE ); 70 mediaPlayerState.setPaused( FALSE );
69 } 71 }
70} 72}
71 73
72void MediaPlayer::play() { 74void MediaPlayer::play() {
73 mediaPlayerState.setPlaying( FALSE ); 75 mediaPlayerState.setPlaying( FALSE );
74 mediaPlayerState.setPlaying( TRUE ); 76 mediaPlayerState.setPlaying( TRUE );
75} 77}
76 78
77void MediaPlayer::setPlaying( bool play ) { 79void MediaPlayer::setPlaying( bool play ) {
78 if ( !play ) { 80 if ( !play ) {
79 return; 81 return;
80 } 82 }
81 83
82 if ( mediaPlayerState.isPaused() ) { 84 if ( mediaPlayerState.isPaused() ) {
83 mediaPlayerState.setPaused( FALSE ); 85 mediaPlayerState.setPaused( FALSE );
84 return; 86 return;
85 } 87 }
86 88
87 QString tickerText, time, fileName; 89 QString tickerText, time, fileName;
88 if ( playList.currentTab() != PlayListWidget::CurrentPlayList ) { 90 if ( playList.currentTab() != PlayListWidget::CurrentPlayList ) {
89 //if playing in file list.. play in a different way 91 //if playing in file list.. play in a different way
90 // random and looping settings enabled causes problems here, 92 // random and looping settings enabled causes problems here,
91 // since there is no selected file in the playlist, but a selected file in the file list, 93 // since there is no selected file in the playlist, but a selected file in the file list,
92 // so we remember and shutoff 94 // so we remember and shutoff
93 l = mediaPlayerState.isLooping(); 95 l = mediaPlayerState.isLooping();
94 if(l) { 96 if(l) {
95 mediaPlayerState.setLooping( false ); 97 mediaPlayerState.setLooping( false );
96 } 98 }
97 r = mediaPlayerState.isShuffled(); 99 r = mediaPlayerState.isShuffled();
98 mediaPlayerState.setShuffled( false ); 100 mediaPlayerState.setShuffled( false );
99 } 101 }
100 102
101 PlayListWidget::Entry playListEntry = playList.currentEntry(); 103 PlayListWidget::Entry playListEntry = playList.currentEntry();
102 fileName = playListEntry.name; 104 fileName = playListEntry.name;
103 xineControl->play( playListEntry.file ); 105 xineControl->play( playListEntry.file );
104 106
105 long seconds = mediaPlayerState.length(); 107 long seconds = mediaPlayerState.length();
106 time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); 108 time.sprintf("%li:%02i", seconds/60, (int)seconds%60 );
107 109
108 if( fileName.left(4) == "http" ) { 110 if( fileName.left(4) == "http" ) {
109 fileName = QFileInfo( fileName ).baseName(); 111 fileName = QFileInfo( fileName ).baseName();
110 if ( xineControl->getMetaInfo().isEmpty() ) { 112 if ( xineControl->getMetaInfo().isEmpty() ) {
111 tickerText = tr( " File: " ) + fileName; 113 tickerText = tr( " File: " ) + fileName;
112 } else { 114 } else {
113 tickerText = xineControl->getMetaInfo(); 115 tickerText = xineControl->getMetaInfo();
114 } 116 }
115 } else { 117 } else {
116 if ( xineControl->getMetaInfo().isEmpty() ) { 118 if ( xineControl->getMetaInfo().isEmpty() ) {
117 tickerText = tr( " File: " ) + fileName + tr( ", Length: " ) + time + " "; 119 tickerText = tr( " File: " ) + fileName + tr( ", Length: " ) + time + " ";
118 } else { 120 } else {
119 tickerText = xineControl->getMetaInfo() + " Length: " + time + " "; 121 tickerText = xineControl->getMetaInfo() + " Length: " + time + " ";
120 } 122 }
121 } 123 }
122 audioUI->setTickerText( tickerText ); 124 audioUI->setTickerText( tickerText );
123} 125}
124 126
125 127
126void MediaPlayer::prev() { 128void MediaPlayer::prev() {
127 if( playList.currentTab() == PlayListWidget::CurrentPlayList ) { //if using the playlist 129 if( playList.currentTab() == PlayListWidget::CurrentPlayList ) { //if using the playlist
128 if ( playList.prev() ) { 130 if ( playList.prev() ) {
129 play(); 131 play();
130 } else if ( mediaPlayerState.isLooping() ) { 132 } else if ( mediaPlayerState.isLooping() ) {
131 if ( playList.last() ) { 133 if ( playList.last() ) {
132 play(); 134 play();
133 } 135 }
134 } else { 136 } else {
135 mediaPlayerState.setList(); 137 mediaPlayerState.setList();
136 } 138 }
137 } 139 }
138} 140}
139 141
140 142
141void MediaPlayer::next() { 143void MediaPlayer::next() {
142 144
143 if(playList.currentTab() == PlayListWidget::CurrentPlayList) { //if using the playlist 145 if(playList.currentTab() == PlayListWidget::CurrentPlayList) { //if using the playlist
144 if ( playList.next() ) { 146 if ( playList.next() ) {
145 play(); 147 play();
146 } else if ( mediaPlayerState.isLooping() ) { 148 } else if ( mediaPlayerState.isLooping() ) {
147 if ( playList.first() ) { 149 if ( playList.first() ) {
148 play(); 150 play();
149 } 151 }
150 } else { 152 } else {
151 mediaPlayerState.setList(); 153 mediaPlayerState.setList();
152 } 154 }
153 } else { //if playing from file list, let's just stop 155 } else { //if playing from file list, let's just stop
154 qDebug("<<<<<<<<<<<<<<<<<stop for filelists"); 156 qDebug("<<<<<<<<<<<<<<<<<stop for filelists");
155 mediaPlayerState.setPlaying(false); 157 mediaPlayerState.setPlaying(false);
156 mediaPlayerState.setDisplayType( MediaPlayerState::MediaSelection ); 158 mediaPlayerState.setDisplayType( MediaPlayerState::MediaSelection );
157 if(l) mediaPlayerState.setLooping(l); 159 if(l) mediaPlayerState.setLooping(l);
158 if(r) mediaPlayerState.setShuffled(r); 160 if(r) mediaPlayerState.setShuffled(r);
159 } 161 }
160 qApp->processEvents(); 162 qApp->processEvents();
161} 163}
162 164
163 165
164void MediaPlayer::startDecreasingVolume() { 166void MediaPlayer::startDecreasingVolume() {
165 volumeDirection = -1; 167 volumeDirection = -1;
166 startTimer( 100 ); 168 startTimer( 100 );
167 volControl->decVol(2); 169 volControl->decVol(2);
168} 170}
169 171
170 172
171void MediaPlayer::startIncreasingVolume() { 173void MediaPlayer::startIncreasingVolume() {
172 volumeDirection = +1; 174 volumeDirection = +1;
173 startTimer( 100 ); 175 startTimer( 100 );
174 volControl->incVol(2); 176 volControl->incVol(2);
175} 177}
176 178
177 179
178bool drawnOnScreenDisplay = FALSE; 180bool drawnOnScreenDisplay = FALSE;
179unsigned int onScreenDisplayVolume = 0; 181unsigned int onScreenDisplayVolume = 0;
180const int yoff = 110; 182const int yoff = 110;
181 183
182void MediaPlayer::stopChangingVolume() { 184void MediaPlayer::stopChangingVolume() {
183 killTimers(); 185 killTimers();
184 // Get rid of the on-screen display stuff 186 // Get rid of the on-screen display stuff
185 drawnOnScreenDisplay = FALSE; 187 drawnOnScreenDisplay = FALSE;
186 onScreenDisplayVolume = 0; 188 onScreenDisplayVolume = 0;
187 int w=0; 189 int w=0;
188 int h=0; 190 int h=0;
189 if( !xineControl->hasVideo() ) { 191 if( !xineControl->hasVideo() ) {
190 w = audioUI->width(); 192 w = audioUI->width();
191 h = audioUI->height(); 193 h = audioUI->height();
192 audioUI->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); 194 audioUI->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE );
193 } else { 195 } else {
194 w = videoUI->width(); 196 w = videoUI->width();
195 h = videoUI->height(); 197 h = videoUI->height();
196 videoUI->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE ); 198 videoUI->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE );
197 } 199 }
198} 200}
199 201
200 202
201void MediaPlayer::timerEvent( QTimerEvent * ) { 203void MediaPlayer::timerEvent( QTimerEvent * ) {
202 if ( volumeDirection == +1 ) { 204 if ( volumeDirection == +1 ) {
203 volControl->incVol( 2 ); 205 volControl->incVol( 2 );
204 } else if ( volumeDirection == -1 ) { 206 } else if ( volumeDirection == -1 ) {
205 volControl->decVol( 2 ); 207 volControl->decVol( 2 );
206 } 208 }
207 209
208 210
209 // TODO FIXME 211 // TODO FIXME
210 // huh?? 212 // huh??
211 unsigned int v= 0; 213 unsigned int v= 0;
212 v = volControl->volume(); 214 v = volControl->volume();
213 v = v / 10; 215 v = v / 10;
214 216
215 if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) { 217 if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) {
216 return; 218 return;
217 } 219 }
218 220
219 int w=0; int h=0; 221 int w=0; int h=0;
220 if( !xineControl->hasVideo() ) { 222 if( !xineControl->hasVideo() ) {
221 w = audioUI->width(); 223 w = audioUI->width();
222 h = audioUI->height(); 224 h = audioUI->height();
223 225
224 if ( drawnOnScreenDisplay ) { 226 if ( drawnOnScreenDisplay ) {
225 if ( onScreenDisplayVolume > v ) { 227 if ( onScreenDisplayVolume > v ) {
226 audioUI->repaint( ( w - 200 ) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); 228 audioUI->repaint( ( w - 200 ) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE );
227 } 229 }
228 } 230 }
229 drawnOnScreenDisplay = TRUE; 231 drawnOnScreenDisplay = TRUE;
230 onScreenDisplayVolume = v; 232 onScreenDisplayVolume = v;
231 QPainter p( audioUI ); 233 QPainter p( audioUI );
232 p.setPen( QColor( 0x10, 0xD0, 0x10 ) ); 234 p.setPen( QColor( 0x10, 0xD0, 0x10 ) );
233 p.setBrush( QColor( 0x10, 0xD0, 0x10 ) ); 235 p.setBrush( QColor( 0x10, 0xD0, 0x10 ) );
234 236
235 QFont f; 237 QFont f;
236 f.setPixelSize( 20 ); 238 f.setPixelSize( 20 );
237 f.setBold( TRUE ); 239 f.setBold( TRUE );
238 p.setFont( f ); 240 p.setFont( f );
239 p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") ); 241 p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") );
240 242
241 for ( unsigned int i = 0; i < 10; i++ ) { 243 for ( unsigned int i = 0; i < 10; i++ ) {
242 if ( v > i ) { 244 if ( v > i ) {
243 p.drawRect( ( w - 200 ) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 ); 245 p.drawRect( ( w - 200 ) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 );
244 } else { 246 } else {
245 p.drawRect( ( w - 200 ) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 ); 247 p.drawRect( ( w - 200 ) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 );
246 } 248 }
247 } 249 }
248 } else { 250 } else {
249 w = videoUI->width(); 251 w = videoUI->width();
250 h = videoUI->height(); 252 h = videoUI->height();
251 253
252 if ( drawnOnScreenDisplay ) { 254 if ( drawnOnScreenDisplay ) {
253 if ( onScreenDisplayVolume > v ) { 255 if ( onScreenDisplayVolume > v ) {
254 videoUI->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE ); 256 videoUI->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE );