summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/mediaplayer.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opieplayer2/mediaplayer.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/mediaplayer.cpp203
1 files changed, 203 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/mediaplayer.cpp b/noncore/multimedia/opieplayer2/mediaplayer.cpp
new file mode 100644
index 0000000..e6d0525
--- a/dev/null
+++ b/noncore/multimedia/opieplayer2/mediaplayer.cpp
@@ -0,0 +1,203 @@
1#include <qpe/qpeapplication.h>
2#include <qpe/qlibrary.h>
3#include <qpe/resource.h>
4#include <qpe/config.h>
5
6#include <qmainwindow.h>
7#include <qmessagebox.h>
8#include <qwidgetstack.h>
9#include <qfile.h>
10
11#include "mediaplayer.h"
12#include "playlistwidget.h"
13#include "audiowidget.h"
14
15#include "mediaplayerstate.h"
16
17
18extern AudioWidget *audioUI;
19extern PlayListWidget *playList;
20extern MediaPlayerState *mediaPlayerState;
21
22
23MediaPlayer::MediaPlayer( QObject *parent, const char *name )
24 : QObject( parent, name ), volumeDirection( 0 ), currentFile( NULL ) {
25
26
27// QPEApplication::grabKeyboard(); // EVIL
28 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
29
30 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) );
31 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) );
32 connect( mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) );
33 connect( mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) );
34
35 connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) );
36 connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) );
37 connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) );
38 connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) );
39}
40
41MediaPlayer::~MediaPlayer() {
42}
43
44void MediaPlayer::pauseCheck( bool b ) {
45 // Only pause if playing
46 if ( b && !mediaPlayerState->playing() )
47 mediaPlayerState->setPaused( FALSE );
48}
49
50void MediaPlayer::play() {
51 mediaPlayerState->setPlaying( FALSE );
52 mediaPlayerState->setPlaying( TRUE );
53}
54
55void MediaPlayer::setPlaying( bool play ) {
56 if ( !play ) {
57 mediaPlayerState->setPaused( FALSE );
58// loopControl->stop( FALSE );
59 return;
60 }
61
62 if ( mediaPlayerState->paused() ) {
63 mediaPlayerState->setPaused( FALSE );
64 return;
65 }
66
67 const DocLnk *playListCurrent = playList->current();
68 if ( playListCurrent != NULL ) {
69// loopControl->stop( TRUE );
70 currentFile = playListCurrent;
71 }
72
73 /*
74
75 if ( currentFile == NULL ) {
76 QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) );
77 mediaPlayerState->setPlaying( FALSE );
78 return;
79 }
80
81 if ( ((currentFile->file()).left(4) != "http") && !QFile::exists( currentFile->file() ) ) {
82 QMessageBox::critical( 0, tr( "File not found"), tr( "The following file was not found: <i>" ) + currentFile->file() + "</i>" );
83 mediaPlayerState->setPlaying( FALSE );
84 return;
85 }
86
87 if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) {
88 QMessageBox::critical( 0, tr( "No decoder found"), tr( "Sorry, no appropriate decoders found for this file: <i>" ) + currentFile->file() + "</i>" );
89 mediaPlayerState->setPlaying( FALSE );
90 return;
91 }
92
93// if ( !loopControl->init( currentFile->file() ) ) {
94// QMessageBox::critical( 0, tr( "Error opening file"), tr( "Sorry, an error occured trying to play the file: <i>" ) + currentFile->file() + "</i>" );
95// mediaPlayerState->setPlaying( FALSE );
96// return;
97// }
98// long seconds = loopControl->totalPlaytime();
99 long seconds = 120;
100 QString time;
101 time.sprintf("%li:%02i", seconds/60, (int)seconds%60 );
102 QString tickerText;
103 if( currentFile->file().left(4) == "http" )
104 tickerText= tr( " File: " ) + currentFile->name();
105 else
106 tickerText = tr( " File: " ) + currentFile->name() + tr(", Length: ") + time;
107
108 QString fileInfo = mediaPlayerState->curDecoder()->fileInfo();
109 if ( !fileInfo.isEmpty() )
110 tickerText += ", " + fileInfo;
111 audioUI->setTickerText( tickerText + "." );
112
113
114 */ // alles nicht nötig, xine kümmert sich drum, man muss nur den return andio oder video gui geben
115
116
117 // loopControl->play();
118
119 // mediaPlayerState->setView( loopControl->hasVideo() ? 'v' : 'a' );
120}
121
122
123void MediaPlayer::prev() {
124 if ( playList->prev() )
125 play();
126 else if ( mediaPlayerState->looping() ) {
127 if ( playList->last() )
128 play();
129 } else
130 mediaPlayerState->setList();
131}
132
133
134void MediaPlayer::next() {
135 if ( playList->next() )
136 play();
137 else if ( mediaPlayerState->looping() ) {
138 if ( playList->first() )
139 play();
140 } else
141 mediaPlayerState->setList();
142}
143
144
145void MediaPlayer::startDecreasingVolume() {
146 volumeDirection = -1;
147 startTimer( 100 );
148 // sollte volumeapplet machen
149 // AudioDevice::decreaseVolume();
150}
151
152
153void MediaPlayer::startIncreasingVolume() {
154 volumeDirection = +1;
155 startTimer( 100 );
156 // AudioDevice::increaseVolume();
157}
158
159
160void MediaPlayer::stopChangingVolume() {
161 killTimers();
162}
163
164
165void MediaPlayer::timerEvent( QTimerEvent * ) {
166// if ( volumeDirection == +1 )
167// AudioDevice::increaseVolume();
168// else if ( volumeDirection == -1 )
169 // AudioDevice::decreaseVolume();
170}
171
172void MediaPlayer::keyReleaseEvent( QKeyEvent *e) {
173 switch ( e->key() ) {
174////////////////////////////// Zaurus keys
175 case Key_Home:
176 break;
177 case Key_F9: //activity
178 break;
179 case Key_F10: //contacts
180 break;
181 case Key_F11: //menu
182 break;
183 case Key_F12: //home
184 qDebug("Blank here");
185 break;
186 case Key_F13: //mail
187 break;
188 }
189}
190
191void MediaPlayer::doBlank() {
192
193}
194
195void MediaPlayer::doUnblank() {
196
197}
198
199void MediaPlayer::cleanUp() {
200// QPEApplication::grabKeyboard();
201// QPEApplication::ungrabKeyboard();
202
203}