summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/mediaplayer.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/mediaplayer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/mediaplayer.cpp65
1 files changed, 30 insertions, 35 deletions
diff --git a/core/multimedia/opieplayer/mediaplayer.cpp b/core/multimedia/opieplayer/mediaplayer.cpp
index ce42c2c..c971a3c 100644
--- a/core/multimedia/opieplayer/mediaplayer.cpp
+++ b/core/multimedia/opieplayer/mediaplayer.cpp
@@ -27,157 +27,152 @@
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28#include <qwidgetstack.h> 28#include <qwidgetstack.h>
29#include <qfile.h> 29#include <qfile.h>
30 30
31#include "mediaplayer.h" 31#include "mediaplayer.h"
32#include "playlistwidget.h" 32#include "playlistwidget.h"
33#include "audiowidget.h" 33#include "audiowidget.h"
34#include "loopcontrol.h" 34#include "loopcontrol.h"
35#include "audiodevice.h" 35#include "audiodevice.h"
36 36
37#include "mediaplayerstate.h" 37#include "mediaplayerstate.h"
38 38
39 39
40extern AudioWidget *audioUI; 40extern AudioWidget *audioUI;
41extern PlayListWidget *playList; 41extern PlayListWidget *playList;
42extern LoopControl *loopControl; 42extern LoopControl *loopControl;
43extern MediaPlayerState *mediaPlayerState; 43extern MediaPlayerState *mediaPlayerState;
44 44
45 45
46MediaPlayer::MediaPlayer( QObject *parent, const char *name ) 46MediaPlayer::MediaPlayer( QObject *parent, const char *name )
47 : QObject( parent, name ), volumeDirection( 0 ), currentFile( NULL ) { 47 : QObject( parent, name ), volumeDirection( 0 ), currentFile( NULL ) {
48 48
49 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); 49 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) );
50 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); 50 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) );
51 connect( mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); 51 connect( mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) );
52 connect( mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); 52 connect( mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) );
53 53
54 connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); 54 connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) );
55 connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); 55 connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) );
56 connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); 56 connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) );
57 connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); 57 connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) );
58} 58}
59 59
60 60
61MediaPlayer::~MediaPlayer() { 61MediaPlayer::~MediaPlayer() {
62} 62}
63 63
64 64
65void MediaPlayer::pauseCheck( bool b ) { 65void MediaPlayer::pauseCheck( bool b ) {
66 // Only pause if playing 66 // Only pause if playing
67 if ( b && !mediaPlayerState->playing() ) 67 if ( b && !mediaPlayerState->playing() )
68 mediaPlayerState->setPaused( FALSE ); 68 mediaPlayerState->setPaused( FALSE );
69} 69}
70 70
71 71
72void MediaPlayer::play() { 72void MediaPlayer::play() {
73 mediaPlayerState->setPlaying( FALSE ); 73 mediaPlayerState->setPlaying( FALSE );
74 mediaPlayerState->setPlaying( TRUE ); 74 mediaPlayerState->setPlaying( TRUE );
75} 75}
76 76
77 77
78void MediaPlayer::setPlaying( bool play ) { 78void MediaPlayer::setPlaying( bool play ) {
79
80 if ( !play ) { 79 if ( !play ) {
81 mediaPlayerState->setPaused( FALSE ); 80 mediaPlayerState->setPaused( FALSE );
82 loopControl->stop( FALSE ); 81 loopControl->stop( FALSE );
83 return; 82 return;
84 } 83 }
85 84
86 if ( mediaPlayerState->paused() ) { 85 if ( mediaPlayerState->paused() ) {
87 mediaPlayerState->setPaused( FALSE ); 86 mediaPlayerState->setPaused( FALSE );
88 return; 87 return;
89 } 88 }
90 89
91 const DocLnk *playListCurrent = playList->current(); 90 const DocLnk *playListCurrent = playList->current();
92
93 if ( playListCurrent != NULL ) { 91 if ( playListCurrent != NULL ) {
94 loopControl->stop( TRUE ); 92 loopControl->stop( TRUE );
95 currentFile = playListCurrent; 93 currentFile = playListCurrent;
96 } 94 }
97
98 if ( currentFile == NULL ) { 95 if ( currentFile == NULL ) {
99 QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) ); 96 QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) );
100 mediaPlayerState->setPlaying( FALSE ); 97 mediaPlayerState->setPlaying( FALSE );
101 return; 98 return;
102 } 99 }
103
104 if ( !QFile::exists( currentFile->file() ) ) { 100 if ( !QFile::exists( currentFile->file() ) ) {
105 QMessageBox::critical( 0, tr( "File not found"), tr( "The following file was not found: <i>" ) + currentFile->file() + "</i>" ); 101 QMessageBox::critical( 0, tr( "File not found"), tr( "The following file was not found: <i>" ) + currentFile->file() + "</i>" );
106 mediaPlayerState->setPlaying( FALSE ); 102 mediaPlayerState->setPlaying( FALSE );
107 return; 103 return;
108 } 104 }
109 105
110 if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) { 106 if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) {
111 QMessageBox::critical( 0, tr( "No decoder found"), tr( "Sorry, no appropriate decoders found for this file: <i>" ) + currentFile->file() + "</i>" ); 107 QMessageBox::critical( 0, tr( "No decoder found"), tr( "Sorry, no appropriate decoders found for this file: <i>" ) + currentFile->file() + "</i>" );
112 mediaPlayerState->setPlaying( FALSE ); 108 mediaPlayerState->setPlaying( FALSE );
113 return; 109 return;
114 } 110 }
115 111
116 if ( !loopControl->init( currentFile->file() ) ) { 112 if ( !loopControl->init( currentFile->file() ) ) {
117 QMessageBox::critical( 0, tr( "Error opening file"), tr( "Sorry, an error occured trying to play the file: <i>" ) + currentFile->file() + "</i>" ); 113 QMessageBox::critical( 0, tr( "Error opening file"), tr( "Sorry, an error occured trying to play the file: <i>" ) + currentFile->file() + "</i>" );
118 mediaPlayerState->setPlaying( FALSE ); 114 mediaPlayerState->setPlaying( FALSE );
119 return; 115 return;
120 } 116 }
121
122 long seconds = loopControl->totalPlaytime(); 117 long seconds = loopControl->totalPlaytime();
123 QString time; time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); 118 QString time; time.sprintf("%li:%02i", seconds/60, (int)seconds%60 );
124 QString tickerText = tr( " File: " ) + currentFile->name() + tr(", Length: ") + time; 119 QString tickerText = tr( " File: " ) + currentFile->name() + tr(", Length: ") + time;
125 QString fileInfo = mediaPlayerState->curDecoder()->fileInfo(); 120 QString fileInfo = mediaPlayerState->curDecoder()->fileInfo();
126 if ( !fileInfo.isEmpty() ) 121 if ( !fileInfo.isEmpty() )
127 tickerText += ", " + fileInfo; 122 tickerText += ", " + fileInfo;
128 audioUI->setTickerText( tickerText + "." ); 123 audioUI->setTickerText( tickerText + "." );
129 124
130 loopControl->play(); 125 loopControl->play();
131 126
132 mediaPlayerState->setView( loopControl->hasVideo() ? 'v' : 'a' ); 127 mediaPlayerState->setView( loopControl->hasVideo() ? 'v' : 'a' );
133} 128}
134 129
135 130
136void MediaPlayer::prev() { 131void MediaPlayer::prev() {
137 if ( playList->prev() ) 132 if ( playList->prev() )
138 play(); 133 play();
139 else if ( mediaPlayerState->looping() ) { 134 else if ( mediaPlayerState->looping() ) {
140 if ( playList->last() ) 135 if ( playList->last() )
141 play(); 136 play();
142 } else 137 } else
143 mediaPlayerState->setList(); 138 mediaPlayerState->setList();
144} 139}
145 140
146 141
147void MediaPlayer::next() { 142void MediaPlayer::next() {
148 if ( playList->next() ) 143 if ( playList->next() )
149 play(); 144 play();
150 else if ( mediaPlayerState->looping() ) { 145 else if ( mediaPlayerState->looping() ) {
151 if ( playList->first() ) 146 if ( playList->first() )
152 play(); 147 play();
153 } else 148 } else
154 mediaPlayerState->setList(); 149 mediaPlayerState->setList();
155} 150}
156 151
157 152
158void MediaPlayer::startDecreasingVolume() { 153void MediaPlayer::startDecreasingVolume() {
159 volumeDirection = -1; 154 volumeDirection = -1;
160 startTimer( 100 ); 155 startTimer( 100 );
161 AudioDevice::decreaseVolume(); 156 AudioDevice::decreaseVolume();
162} 157}
163 158
164 159
165void MediaPlayer::startIncreasingVolume() { 160void MediaPlayer::startIncreasingVolume() {
166 volumeDirection = +1; 161 volumeDirection = +1;
167 startTimer( 100 ); 162 startTimer( 100 );
168 AudioDevice::increaseVolume(); 163 AudioDevice::increaseVolume();
169} 164}
170 165
171 166
172void MediaPlayer::stopChangingVolume() { 167void MediaPlayer::stopChangingVolume() {
173 killTimers(); 168 killTimers();
174} 169}
175 170
176 171
177void MediaPlayer::timerEvent( QTimerEvent * ) { 172void MediaPlayer::timerEvent( QTimerEvent * ) {
178 if ( volumeDirection == +1 ) 173 if ( volumeDirection == +1 )
179 AudioDevice::increaseVolume(); 174 AudioDevice::increaseVolume();
180 else if ( volumeDirection == -1 ) 175 else if ( volumeDirection == -1 )
181 AudioDevice::decreaseVolume(); 176 AudioDevice::decreaseVolume();
182} 177}
183 178