summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-04-10 19:13:40 (UTC)
committer llornkcor <llornkcor>2002-04-10 19:13:40 (UTC)
commit9237a75548f9b932fbb1900d8ea28dbee9da81ac (patch) (side-by-side diff)
treea0249408df5ce581af8bcee5b6f58bcee1db461a
parent11d754ffa429875b526c49f125d8a844c5cda3d8 (diff)
downloadopie-9237a75548f9b932fbb1900d8ea28dbee9da81ac.zip
opie-9237a75548f9b932fbb1900d8ea28dbee9da81ac.tar.gz
opie-9237a75548f9b932fbb1900d8ea28dbee9da81ac.tar.bz2
bug fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/libmadplugin.cpp13
-rw-r--r--core/multimedia/opieplayer/libmad/libmadplugin.h2
-rw-r--r--core/multimedia/opieplayer/libmpeg3/mpeg3io.c132
-rw-r--r--core/multimedia/opieplayer/playlistselection.cpp20
-rw-r--r--core/multimedia/opieplayer/playlistselection.h6
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp250
6 files changed, 236 insertions, 187 deletions
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp
index 9f8ba65..8ede537 100644
--- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp
+++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp
@@ -1,578 +1,583 @@
/**********************************************************************
** Copyright (C) 2001 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <time.h>
#include <locale.h>
#include <math.h>
#include <assert.h>
#include <qapplication.h>
+#include <qpe/config.h>
//#define HAVE_MMAP
#if defined(HAVE_MMAP)
# include <sys/mman.h>
#endif
#include "libmadplugin.h"
extern "C" {
#include "mad.h"
}
#define MPEG_BUFFER_SIZE 65536
+//#define MPEG_BUFFER_SIZE 32768 //16384 // 8192
//#define debugMsg(a) qDebug(a)
#define debugMsg(a)
class Input {
public:
char const *path;
int fd;
#if defined(HAVE_MMAP)
void *fdm;
#endif
unsigned char *data;
unsigned long length;
int eof;
};
class Output {
public:
mad_fixed_t attenuate;
struct filter *filters;
unsigned int channels_in;
unsigned int channels_out;
unsigned int speed_in;
unsigned int speed_out;
const char *path;
};
# if defined(HAVE_MMAP)
static void *map_file(int fd, unsigned long *length)
{
void *fdm;
*length += MAD_BUFFER_GUARD;
fdm = mmap(0, *length, PROT_READ, MAP_SHARED, fd, 0);
if (fdm == MAP_FAILED)
return 0;
# if defined(HAVE_MADVISE)
madvise(fdm, *length, MADV_SEQUENTIAL);
# endif
return fdm;
}
static int unmap_file(void *fdm, unsigned long length)
{
if (munmap(fdm, length) == -1)
return -1;
return 0;
}
# endif
static inline QString tr( const char *str ) {
// Apparently this is okay from a plugin as it runs in the process space of the owner of the plugin
return qApp->translate( "MediaPlayer", str, "libmad strings for mp3 file info" );
}
class LibMadPluginData {
public:
Input input;
Output output;
int bad_last_frame;
struct mad_stream stream;
struct mad_frame frame;
struct mad_synth synth;
bool flush;
};
LibMadPlugin::LibMadPlugin() {
d = new LibMadPluginData;
d->input.fd = 0;
#if defined(HAVE_MMAP)
d->input.fdm = 0;
#endif
d->input.data = 0;
d->flush = TRUE;
info = tr( "No Song Open" );
}
LibMadPlugin::~LibMadPlugin() {
close();
delete d;
}
bool LibMadPlugin::isFileSupported( const QString& path ) {
debugMsg( "LibMadPlugin::isFileSupported" );
// Mpeg file extensions
// "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3"
// Other media extensions
// "wav","mid","mod","s3m","ogg","avi","mov","sid"
char *ext = strrchr( path.latin1(), '.' );
// Test file extension
if ( ext ) {
if ( strncasecmp(ext, ".mp2", 4) == 0 )
return TRUE;
if ( strncasecmp(ext, ".mp3", 4) == 0 )
return TRUE;
}
return FALSE;
}
bool LibMadPlugin::open( const QString& path ) {
debugMsg( "LibMadPlugin::open" );
-
+ Config cfg("MediaPlayer");
+ cfg.setGroup("Options");
+ bufferSize = cfg.readNumEntry("MPeg_BufferSize",MPEG_BUFFER_SIZE);
+ qDebug("buffer size is %d", bufferSize);
d->bad_last_frame = 0;
d->flush = TRUE;
info = QString( "" );
//qDebug( "Opening %s", path.latin1() );
d->input.path = path.latin1();
d->input.fd = ::open( d->input.path, O_RDONLY );
if (d->input.fd == -1) {
qDebug("error opening %s", d->input.path );
return FALSE;
}
printID3Tags();
#if defined(HAVE_MMAP)
struct stat stat;
if (fstat(d->input.fd, &stat) == -1) {
qDebug("error calling fstat"); return FALSE;
}
if (S_ISREG(stat.st_mode) && stat.st_size > 0) {
d->input.length = stat.st_size;
d->input.fdm = map_file(d->input.fd, &d->input.length);
if (d->input.fdm == 0) {
qDebug("error mmapping file"); return FALSE;
}
d->input.data = (unsigned char *)d->input.fdm;
}
#endif
if (d->input.data == 0) {
- d->input.data = (unsigned char *)malloc(MPEG_BUFFER_SIZE);
+ d->input.data = (unsigned char *)malloc( bufferSize /*MPEG_BUFFER_SIZE*/);
if (d->input.data == 0) {
qDebug("error allocating input buffer");
return FALSE;
}
d->input.length = 0;
}
d->input.eof = 0;
mad_stream_init(&d->stream);
mad_frame_init(&d->frame);
mad_synth_init(&d->synth);
return TRUE;
}
bool LibMadPlugin::close() {
debugMsg( "LibMadPlugin::close" );
int result = TRUE;
mad_synth_finish(&d->synth);
mad_frame_finish(&d->frame);
mad_stream_finish(&d->stream);
#if defined(HAVE_MMAP)
if (d->input.fdm) {
if (unmap_file(d->input.fdm, d->input.length) == -1) {
qDebug("error munmapping file");
result = FALSE;
}
d->input.fdm = 0;
d->input.data = 0;
}
#endif
if (d->input.data) {
free(d->input.data);
d->input.data = 0;
}
if (::close(d->input.fd) == -1) {
qDebug("error closing file %s", d->input.path);
result = FALSE;
}
d->input.fd = 0;
return result;
}
bool LibMadPlugin::isOpen() {
debugMsg( "LibMadPlugin::isOpen" );
return ( d->input.fd != 0 );
}
int LibMadPlugin::audioStreams() {
debugMsg( "LibMadPlugin::audioStreams" );
return 1;
}
int LibMadPlugin::audioChannels( int ) {
debugMsg( "LibMadPlugin::audioChannels" );
/*
long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 );
qDebug( "LibMadPlugin::audioChannels: %i", d->frame.header.mode > 0 ? 2 : 1 );
return d->frame.header.mode > 0 ? 2 : 1;
*/
return 2;
}
int LibMadPlugin::audioFrequency( int ) {
debugMsg( "LibMadPlugin::audioFrequency" );
long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 );
qDebug( "LibMadPlugin::audioFrequency: %i", d->frame.header.samplerate );
return d->frame.header.samplerate;
}
int LibMadPlugin::audioSamples( int ) {
debugMsg( "LibMadPlugin::audioSamples" );
/*
long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 );
mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream );
qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds, d->frame.header.samplerate );
return d->frame.header.duration.seconds * d->frame.header.samplerate;
*/
return 10000000;
}
bool LibMadPlugin::audioSetSample( long, int ) {
debugMsg( "LibMadPlugin::audioSetSample" );
return FALSE;
}
long LibMadPlugin::audioGetSample( int ) {
debugMsg( "LibMadPlugin::audioGetSample" );
return 0;
}
/*
bool LibMadPlugin::audioReadSamples( short *, int, long, int ) {
debugMsg( "LibMadPlugin::audioReadSamples" );
return FALSE;
}
bool LibMadPlugin::audioReReadSamples( short *, int, long, int ) {
debugMsg( "LibMadPlugin::audioReReadSamples" );
return FALSE;
}
*/
bool LibMadPlugin::read() {
debugMsg( "LibMadPlugin::read" );
int len;
if (d->input.eof)
return FALSE;
#if defined(HAVE_MMAP)
if (d->input.fdm) {
unsigned long skip = 0;
if (d->stream.next_frame) {
struct stat stat;
if (fstat(d->input.fd, &stat) == -1)
return FALSE;
if (stat.st_size + MAD_BUFFER_GUARD <= (signed)d->input.length)
return FALSE;
// file size changed; update memory map
skip = d->stream.next_frame - d->input.data;
if (unmap_file(d->input.fdm, d->input.length) == -1) {
d->input.fdm = 0;
d->input.data = 0;
return FALSE;
}
d->input.length = stat.st_size;
d->input.fdm = map_file(d->input.fd, &d->input.length);
if (d->input.fdm == 0) {
d->input.data = 0;
return FALSE;
}
d->input.data = (unsigned char *)d->input.fdm;
}
mad_stream_buffer(&d->stream, d->input.data + skip, d->input.length - skip);
} else
#endif
{
if (d->stream.next_frame) {
memmove(d->input.data, d->stream.next_frame,
d->input.length = &d->input.data[d->input.length] - d->stream.next_frame);
}
do {
- len = ::read(d->input.fd, d->input.data + d->input.length, MPEG_BUFFER_SIZE - d->input.length);
+ len = ::read(d->input.fd, d->input.data + d->input.length, bufferSize /* MPEG_BUFFER_SIZE*/ - d->input.length);
}
while (len == -1 && errno == EINTR);
if (len == -1) {
qDebug("error reading audio");
return FALSE;
}
else if (len == 0) {
d->input.eof = 1;
- assert(MPEG_BUFFER_SIZE - d->input.length >= MAD_BUFFER_GUARD);
+ assert(bufferSize /*MPEG_BUFFER_SIZE*/ - d->input.length >= MAD_BUFFER_GUARD);
while (len < MAD_BUFFER_GUARD)
d->input.data[d->input.length + len++] = 0;
}
mad_stream_buffer(&d->stream, d->input.data, d->input.length += len);
}
return TRUE;
}
static mad_fixed_t left_err, right_err;
static const int bits = 16;
static const int shift = MAD_F_FRACBITS + 1 - bits;
inline long audio_linear_dither( mad_fixed_t sample, mad_fixed_t& error )
{
sample += error;
mad_fixed_t quantized = (sample >= MAD_F_ONE) ? MAD_F_ONE - 1 : ( (sample < -MAD_F_ONE) ? -MAD_F_ONE : sample );
quantized &= ~((1L << shift) - 1);
error = sample - quantized;
return quantized >> shift;
}
inline void audio_pcm( short *data, unsigned int nsamples, mad_fixed_t *left, mad_fixed_t *right )
{
if ( right ) {
while (nsamples--) {
data[0] = audio_linear_dither( *left++, left_err );
data[1] = audio_linear_dither( *right++, right_err );
data += 2;
}
} else {
while (nsamples--) {
data[0] = data[1] = audio_linear_dither( *left++, left_err );
data += 2;
}
}
}
bool LibMadPlugin::decode( short *output, long samples, long& samplesMade ) {
debugMsg( "LibMadPlugin::decode" );
static int buffered = 0;
static mad_fixed_t buffer[2][65536 * 2];
int offset = buffered;
samplesMade = 0;
static int maxBuffered = 8000; // 65536;
if ( samples > maxBuffered )
samples = maxBuffered;
if ( d->flush ) {
buffered = 0;
offset = 0;
d->flush = FALSE;
}
while ( buffered < maxBuffered ) {
while (mad_frame_decode(&d->frame, &d->stream) == -1) {
if (!MAD_RECOVERABLE(d->stream.error)) {
debugMsg( "feed me" );
return FALSE; // Feed me
}
if ( d->stream.error == MAD_ERROR_BADCRC ) {
mad_frame_mute(&d->frame);
qDebug( "error decoding, bad crc" );
}
}
mad_synth_frame(&d->synth, &d->frame);
int decodedSamples = d->synth.pcm.length;
memcpy( &(buffer[0][offset]), d->synth.pcm.samples[0], decodedSamples * sizeof(mad_fixed_t) );
if ( d->synth.pcm.channels == 2 )
memcpy( &(buffer[1][offset]), d->synth.pcm.samples[1], decodedSamples * sizeof(mad_fixed_t) );
offset += decodedSamples;
buffered += decodedSamples;
}
//qApp->processEvents();
audio_pcm( output, samples, buffer[0], (d->synth.pcm.channels == 2) ? buffer[1] : 0 );
// audio_pcm( output, samples, buffer[1], buffer[0] );
// audio_pcm( output, samples, buffer[0], buffer[1] );
samplesMade = samples;
memmove( buffer[0], &(buffer[0][samples]), (buffered - samples) * sizeof(mad_fixed_t) );
if ( d->synth.pcm.channels == 2 )
memmove( buffer[1], &(buffer[1][samples]), (buffered - samples) * sizeof(mad_fixed_t) );
buffered -= samples;
return TRUE;
}
/*
bool LibMadPlugin::audioReadMonoSamples( short *, long, long&, int ) {
debugMsg( "LibMadPlugin::audioReadMonoSamples" );
return FALSE;
}
bool LibMadPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) {
*/
bool LibMadPlugin::audioReadSamples( short *output, int /*channels*/, long samples, long& samplesMade, int ) {
debugMsg( "LibMadPlugin::audioReadStereoSamples" );
static bool needInput = TRUE;
if ( samples == 0 )
return FALSE;
do {
if ( needInput )
if ( !read() ) {
// if ( d->input.eof )
// needInput = FALSE;
// else
return FALSE;
}
needInput = FALSE;
if ( decode( output, samples, samplesMade ) )
return TRUE;
else
needInput = TRUE;
}
while ( ( samplesMade < samples ) && ( !d->input.eof ) );
/*
static bool firstTimeThru = TRUE;
if ( firstTimeThru ) {
firstTimeThru = FALSE;
decode( output, samples, samplesMade );
return FALSE;
} else
*/
return FALSE;
}
double LibMadPlugin::getTime() {
debugMsg( "LibMadPlugin::getTime" );
return 0.0;
}
void LibMadPlugin::printID3Tags() {
debugMsg( "LibMadPlugin::printID3Tags" );
char id3v1[128 + 1];
if ( ::lseek( d->input.fd, -128, SEEK_END ) == -1 ) {
qDebug( "error seeking to id3 tags" );
return;
}
if ( ::read( d->input.fd, id3v1, 128 ) != 128 ) {
qDebug( "error reading in id3 tags" );
return;
}
if ( ::strncmp( (const char *)id3v1, "TAG", 3 ) != 0 ) {
debugMsg( "sorry, no id3 tags" );
} else {
int len[5] = { 30, 30, 30, 4, 30 };
QString label[5] = { tr( "Title" ), tr( "Artist" ), tr( "Album" ), tr( "Year" ), tr( "Comment" ) };
char *ptr = id3v1 + 3, *ptr2 = ptr + len[0];
qDebug( "ID3 tags in file:" );
info = "";
for ( int i = 0; i < 5; ptr += len[i], i++, ptr2 += len[i] ) {
char push = *ptr2;
*ptr2 = '\0';
char *ptr3 = ptr2;
while ( ptr3-1 >= ptr && isspace(ptr3[-1]) ) ptr3--;
char push2 = *ptr3; *ptr3 = '\0';
if ( strcmp( ptr, "" ) )
info += ( i != 0 ? ", " : "" ) + label[i] + ": " + ptr;
//qDebug( info.latin1() );
*ptr3 = push2;
*ptr2 = push;
}
if (id3v1[126] == 0 && id3v1[127] != 0)
info += tr( ", Track: " ) + id3v1[127];
}
if ( ::lseek(d->input.fd, 0, SEEK_SET) == -1 ) {
qDebug( "error seeking back to beginning" );
return;
}
}
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.h b/core/multimedia/opieplayer/libmad/libmadplugin.h
index b240b77..46cd4a1 100644
--- a/core/multimedia/opieplayer/libmad/libmadplugin.h
+++ b/core/multimedia/opieplayer/libmad/libmadplugin.h
@@ -1,110 +1,110 @@
/**********************************************************************
** Copyright (C) 2001 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef LIBMAD_PLUGIN_H
#define LIBMAD_PLUGIN_H
#include <qstring.h>
#include <qpe/mediaplayerplugininterface.h>
/* #include "../mediaplayerplugininterface.h" */
// #define OLD_MEDIAPLAYER_API
class LibMadPluginData;
class LibMadPlugin : public MediaPlayerDecoder {
public:
LibMadPlugin();
~LibMadPlugin();
const char *pluginName() { return "LibMadPlugin"; }
const char *pluginComment() { return "This is the libmad library that has been wrapped as a plugin"; }
double pluginVersion() { return 1.0; }
bool isFileSupported( const QString& );
bool open( const QString& );
bool close();
bool isOpen();
const QString &fileInfo() { return info; }
// If decoder doesn't support audio then return 0 here
int audioStreams();
int audioChannels( int stream );
int audioFrequency( int stream );
int audioSamples( int stream );
bool audioSetSample( long sample, int stream );
/* int audioBitsPerSample(int) {return 0;} */
long audioGetSample( int stream );
#ifdef OLD_MEDIAPLAYER_API
bool audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream );
bool audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream );
bool audioReadSamples( short *output, int channel, long samples, int stream );
bool audioReReadSamples( short *output, int channel, long samples, int stream );
#else
bool audioReadSamples( short *output, int channels, long samples, long& samplesRead, int stream );
#endif
bool read();
bool decode( short *output, long samples, long& samplesRead );
void printID3Tags();
// If decoder doesn't support video then return 0 here
int videoStreams() { return 0; }
int videoWidth( int ) { return 0; }
int videoHeight( int ) { return 0; }
double videoFrameRate( int ) { return 0.0; }
int videoFrames( int ) { return 0; }
bool videoSetFrame( long, int ) { return FALSE; }
long videoGetFrame( int ) { return 0; }
bool videoReadFrame( unsigned char **, int, int, int, int, ColorFormat, int ) { return FALSE; }
bool videoReadScaledFrame( unsigned char **, int, int, int, int, int, int, ColorFormat, int ) { return FALSE; }
bool videoReadYUVFrame( char *, char *, char *, int, int, int, int, int ) { return FALSE; }
// Profiling
double getTime();
// Ignore if these aren't supported
bool setSMP( int ) { return FALSE; }
bool setMMX( bool ) { return FALSE; }
// Capabilities
bool supportsAudio() { return TRUE; }
bool supportsVideo() { return FALSE; }
bool supportsYUV() { return FALSE; }
bool supportsMMX() { return TRUE; }
bool supportsSMP() { return FALSE; }
bool supportsStereo() { return TRUE; }
bool supportsScaling() { return FALSE; }
long getPlayTime() { return -1; }
private:
LibMadPluginData *d;
QString info;
-
+int bufferSize;
};
#endif
diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3io.c b/core/multimedia/opieplayer/libmpeg3/mpeg3io.c
index c5807a7..c5cae00 100644
--- a/core/multimedia/opieplayer/libmpeg3/mpeg3io.c
+++ b/core/multimedia/opieplayer/libmpeg3/mpeg3io.c
@@ -1,127 +1,127 @@
#include "mpeg3private.h"
#include "mpeg3protos.h"
#ifndef _WIN32
#include <mntent.h>
#else
#endif
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
mpeg3_fs_t* mpeg3_new_fs(char *path)
{
- mpeg3_fs_t *fs = (mpeg3_fs_t*)calloc(1, sizeof(mpeg3_fs_t));
- fs->css = mpeg3_new_css();
- strcpy(fs->path, path);
- return fs;
+ mpeg3_fs_t *fs = (mpeg3_fs_t*)calloc(1, sizeof(mpeg3_fs_t));
+ fs->css = mpeg3_new_css();
+ strcpy(fs->path, path);
+ return fs;
}
int mpeg3_delete_fs(mpeg3_fs_t *fs)
{
- mpeg3_delete_css(fs->css);
- free(fs);
- return 0;
+ mpeg3_delete_css(fs->css);
+ free(fs);
+ return 0;
}
int mpeg3_copy_fs(mpeg3_fs_t *dst, mpeg3_fs_t *src)
{
- strcpy(dst->path, src->path);
- dst->current_byte = 0;
- return 0;
+ strcpy(dst->path, src->path);
+ dst->current_byte = 0;
+ return 0;
}
long mpeg3io_get_total_bytes(mpeg3_fs_t *fs)
{
-/*
- * struct stat st;
- * if(stat(fs->path, &st) < 0) return 0;
- * return (long)st.st_size;
- */
-
- fseek(fs->fd, 0, SEEK_END);
- fs->total_bytes = ftell(fs->fd);
- fseek(fs->fd, 0, SEEK_SET);
- return fs->total_bytes;
+
+ struct stat st;
+ if(stat(fs->path, &st) < 0) return 0;
+ return (long)st.st_size;
+
+
+/* fseek(fs->fd, 0, SEEK_END); */
+/* fs->total_bytes = ftell(fs->fd); */
+/* fseek(fs->fd, 0, SEEK_SET); */
+/* return fs->total_bytes; */
}
int mpeg3io_open_file(mpeg3_fs_t *fs)
{
/* Need to perform authentication before reading a single byte. */
- mpeg3_get_keys(fs->css, fs->path);
-
- if(!(fs->fd = fopen(fs->path, "rb")))
- {
- perror("mpeg3io_open_file");
- return 1;
- }
-
- fs->total_bytes = mpeg3io_get_total_bytes(fs);
-
- if(!fs->total_bytes)
- {
- fclose(fs->fd);
- return 1;
- }
- fs->current_byte = 0;
- return 0;
+ mpeg3_get_keys(fs->css, fs->path);
+
+ if(!(fs->fd = fopen(fs->path, "rb")))
+ {
+ perror("mpeg3io_open_file");
+ return 1;
+ }
+
+ fs->total_bytes = mpeg3io_get_total_bytes(fs);
+
+ if(!fs->total_bytes)
+ {
+ fclose(fs->fd);
+ return 1;
+ }
+ fs->current_byte = 0;
+ return 0;
}
int mpeg3io_close_file(mpeg3_fs_t *fs)
{
- if(fs->fd) fclose(fs->fd);
- fs->fd = 0;
- return 0;
+ if(fs->fd) fclose(fs->fd);
+ fs->fd = 0;
+ return 0;
}
int mpeg3io_read_data(unsigned char *buffer, long bytes, mpeg3_fs_t *fs)
{
- int result = 0;
+ int result = 0;
//printf("read %d bytes\n",bytes);
- result = !fread(buffer, 1, bytes, fs->fd);
- fs->current_byte += bytes;
- return (result && bytes);
+ result = !fread(buffer, 1, bytes, fs->fd);
+ fs->current_byte += bytes;
+ return (result && bytes);
}
int mpeg3io_device(char *path, char *device)
{
- struct stat file_st, device_st;
+ struct stat file_st, device_st;
struct mntent *mnt;
- FILE *fp;
+ FILE *fp;
- if(stat(path, &file_st) < 0)
- {
- perror("mpeg3io_device");
- return 1;
- }
+ if(stat(path, &file_st) < 0)
+ {
+ perror("mpeg3io_device");
+ return 1;
+ }
#ifndef _WIN32
- fp = setmntent(MOUNTED, "r");
+ fp = setmntent(MOUNTED, "r");
while(fp && (mnt = getmntent(fp)))
- {
- if(stat(mnt->mnt_fsname, &device_st) < 0) continue;
- if(device_st.st_rdev == file_st.st_dev)
- {
- strncpy(device, mnt->mnt_fsname, MPEG3_STRLEN);
- break;
- }
- }
- endmntent(fp);
+ {
+ if(stat(mnt->mnt_fsname, &device_st) < 0) continue;
+ if(device_st.st_rdev == file_st.st_dev)
+ {
+ strncpy(device, mnt->mnt_fsname, MPEG3_STRLEN);
+ break;
+ }
+ }
+ endmntent(fp);
#endif
- return 0;
+ return 0;
}
int mpeg3io_seek(mpeg3_fs_t *fs, long byte)
{
- fs->current_byte = byte;
- return fseek(fs->fd, byte, SEEK_SET);
+ fs->current_byte = byte;
+ return fseek(fs->fd, byte, SEEK_SET);
}
int mpeg3io_seek_relative(mpeg3_fs_t *fs, long bytes)
{
- fs->current_byte += bytes;
- return fseek(fs->fd, fs->current_byte, SEEK_SET);
+ fs->current_byte += bytes;
+ return fseek(fs->fd, fs->current_byte, SEEK_SET);
}
diff --git a/core/multimedia/opieplayer/playlistselection.cpp b/core/multimedia/opieplayer/playlistselection.cpp
index 6259b3f..8f3711a 100644
--- a/core/multimedia/opieplayer/playlistselection.cpp
+++ b/core/multimedia/opieplayer/playlistselection.cpp
@@ -1,187 +1,203 @@
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include <qpe/applnk.h>
#include <qpe/resource.h>
+#include <qpe/config.h>
+
#include <qpainter.h>
#include <qimage.h>
#include <qheader.h>
#include <qlistview.h>
#include <qlist.h>
#include <qpixmap.h>
#include "playlistselection.h"
#include <stdlib.h>
class PlayListSelectionItem : public QListViewItem {
public:
PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) {
setText( 0, f->name() );
setPixmap( 0, f->pixmap() );
}
~PlayListSelectionItem() {
};
const DocLnk *file() const { return fl; }
private:
const DocLnk *fl;
};
PlayListSelection::PlayListSelection( QWidget *parent, const char *name )
: QListView( parent, name )
{
- qDebug("starting playlistselector");
+// qDebug("starting playlistselector");
// #ifdef USE_PLAYLIST_BACKGROUND
// setStaticBackground( TRUE );
// setBackgroundPixmap( Resource::loadPixmap( "mpegplayer/background" ) );
// setBackgroundPixmap( Resource::loadPixmap( "launcher/opielogo" ) );
// #endif
// addColumn("Title",236);
// setAllColumnsShowFocus( TRUE );
addColumn( tr( "Playlist Selection" ) );
header()->hide();
setSorting( -1, FALSE );
}
PlayListSelection::~PlayListSelection() {
}
// #ifdef USE_PLAYLIST_BACKGROUND
void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) {
// qDebug("drawBackground");
p->fillRect( r, QBrush( white ) );
// QImage logo = Resource::loadImage( "launcher/opielogo" );
// if ( !logo.isNull() )
// p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo );
}
// #endif
void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) {
if ( event->state() == QMouseEvent::LeftButton ) {
QListViewItem *currentItem = selectedItem();
QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) );
if ( currentItem && currentItem->itemAbove() == itemUnder )
moveSelectedUp();
else if ( currentItem && currentItem->itemBelow() == itemUnder )
moveSelectedDown();
}
}
const DocLnk *PlayListSelection::current() {
PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem();
if ( item )
return item->file();
return NULL;
}
void PlayListSelection::addToSelection( const DocLnk &lnk ) {
PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) );
QListViewItem *current = selectedItem();
if ( current )
item->moveItem( current );
setSelected( item, TRUE );
ensureItemVisible( selectedItem() );
}
void PlayListSelection::removeSelected() {
QListViewItem *item = selectedItem();
if ( item )
delete item;
setSelected( currentItem(), TRUE );
ensureItemVisible( selectedItem() );
}
void PlayListSelection::moveSelectedUp() {
QListViewItem *item = selectedItem();
if ( item && item->itemAbove() )
item->itemAbove()->moveItem( item );
ensureItemVisible( selectedItem() );
}
void PlayListSelection::moveSelectedDown() {
QListViewItem *item = selectedItem();
if ( item && item->itemBelow() )
item->moveItem( item->itemBelow() );
ensureItemVisible( selectedItem() );
}
bool PlayListSelection::prev() {
QListViewItem *item = selectedItem();
if ( item && item->itemAbove() )
setSelected( item->itemAbove(), TRUE );
else
return FALSE;
ensureItemVisible( selectedItem() );
return TRUE;
}
bool PlayListSelection::next() {
QListViewItem *item = selectedItem();
if ( item && item->itemBelow() )
setSelected( item->itemBelow(), TRUE );
else
return FALSE;
ensureItemVisible( selectedItem() );
return TRUE;
}
bool PlayListSelection::first() {
QListViewItem *item = firstChild();
if ( item )
setSelected( item, TRUE );
else
return FALSE;
ensureItemVisible( selectedItem() );
return TRUE;
}
bool PlayListSelection::last() {
QListViewItem *prevItem = NULL;
QListViewItem *item = firstChild();
while ( ( item = item->nextSibling() ) )
prevItem = item;
if ( prevItem )
setSelected( prevItem, TRUE );
else
return FALSE;
ensureItemVisible( selectedItem() );
return TRUE;
}
void PlayListSelection::unSelect()
{
QListViewItem *item = selectedItem();
setSelected( currentItem(), FALSE);
-} \ No newline at end of file
+}
+
+void PlayListSelection::writeCurrent( Config& cfg ) {
+ cfg.setGroup("PlayList");
+ QListViewItem *item = selectedItem();
+ if ( item )
+ cfg.writeEntry("current", item->text(0) );
+ qDebug(item->text(0));
+
+}
+
+void PlayListSelection::setSelectedItem(const QString &strk ) {
+// setSelected( item, TRUE );
+// ensureItemVisible( selectedItem() );
+}
diff --git a/core/multimedia/opieplayer/playlistselection.h b/core/multimedia/opieplayer/playlistselection.h
index ba37271..d10bc82 100644
--- a/core/multimedia/opieplayer/playlistselection.h
+++ b/core/multimedia/opieplayer/playlistselection.h
@@ -1,61 +1,63 @@
/**********************************************************************
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef PLAY_LIST_SELECTION_H
#define PLAY_LIST_SELECTION_H
#include <qlist.h>
#include <qlistview.h>
#include <qpe/applnk.h>
-
+#include <qpe/config.h>
class PlayListSelection : public QListView {
Q_OBJECT
public:
PlayListSelection( QWidget *parent, const char *name=0 );
~PlayListSelection();
const DocLnk *current(); // retrieve the current playlist entry (media file link)
public slots:
void addToSelection( const DocLnk & ); // Add a media file to the playlist
void removeSelected(); // Remove a media file from the playlist
void moveSelectedUp(); // Move the media file up the playlist so it is played earlier
void moveSelectedDown(); // Move the media file down the playlist so it is played later
- void unSelect();
+ void unSelect();
+ void writeCurrent( Config &);
+ void setSelectedItem( const QString & );
bool prev();
bool next();
bool first();
bool last();
protected:
virtual void contentsMouseMoveEvent(QMouseEvent *);
/* #ifdef USE_PLAYLIST_BACKGROUND */
virtual void drawBackground( QPainter *p, const QRect &r );
virtual void paintEmptyArea( QPainter *p, const QRect &r ) { drawBackground( p, r ); };
/* #endif */
private:
QList<DocLnk> selectedList;
const DocLnk *lnk;
};
#endif // PLAY_LIST_SELECTION_H
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp
index 3b8f6d7..63df715 100644
--- a/core/multimedia/opieplayer/playlistwidget.cpp
+++ b/core/multimedia/opieplayer/playlistwidget.cpp
@@ -1,941 +1,967 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
// code added by L. J. Potter Sat 03-02-2002 06:17:54
#define QTOPIA_INTERNAL_FSLP
#include <qpe/qpemenubar.h>
#include <qpe/qpetoolbar.h>
#include <qpe/fileselector.h>
#include <qpe/qpeapplication.h>
#include <qpe/lnkproperties.h>
+#include <qpe/storage.h>
#include <qpe/applnk.h>
#include <qpe/config.h>
#include <qpe/global.h>
#include <qpe/resource.h>
#include <qaction.h>
#include <qimage.h>
#include <qfile.h>
#include <qdir.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qlist.h>
#include <qlistbox.h>
#include <qmainwindow.h>
#include <qmessagebox.h>
#include <qtoolbutton.h>
#include <qtabwidget.h>
#include <qlistview.h>
#include <qpoint.h>
#include <qlineedit.h>
#include <qpushbutton.h>
//#include <qtimer.h>
#include "playlistselection.h"
#include "playlistwidget.h"
#include "mediaplayerstate.h"
#include "inputDialog.h"
#include <stdlib.h>
#define BUTTONS_ON_TOOLBAR
#define SIDE_BUTTONS
#define CAN_SAVE_LOAD_PLAYLISTS
extern MediaPlayerState *mediaPlayerState;
// class myFileSelector {
// };
class PlayListWidgetPrivate {
public:
QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove;
QFrame *playListFrame;
FileSelector *files;
PlayListSelection *selectedFiles;
bool setDocumentUsed;
DocLnk *current;
};
class ToolButton : public QToolButton {
public:
ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE )
: QToolButton( parent, name ) {
setTextLabel( name );
setPixmap( Resource::loadPixmap( icon ) );
setAutoRaise( TRUE );
setFocusPolicy( QWidget::NoFocus );
setToggleButton( t );
connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot );
QPEMenuToolFocusManager::manager()->addWidget( this );
}
};
class MenuItem : public QAction {
public:
MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot )
: QAction( text, QString::null, 0, 0 ) {
connect( this, SIGNAL( activated() ), handler, slot );
addTo( parent );
}
};
PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
: QMainWindow( parent, name, fl ) {
d = new PlayListWidgetPrivate;
d->setDocumentUsed = FALSE;
d->current = NULL;
fromSetDocument = FALSE;
insanityBool=FALSE;
// menuTimer = new QTimer( this ,"menu timer"),
// connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) );
setBackgroundMode( PaletteButton );
setCaption( tr("OpiePlayer") );
setIcon( Resource::loadPixmap( "MPEGPlayer" ) );
setToolBarsMovable( FALSE );
// Create Toolbar
QPEToolBar *toolbar = new QPEToolBar( this );
toolbar->setHorizontalStretchable( TRUE );
// Create Menubar
QPEMenuBar *menu = new QPEMenuBar( toolbar );
menu->setMargin( 0 );
QPEToolBar *bar = new QPEToolBar( this );
bar->setLabel( tr( "Play Operations" ) );
// d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "mpegplayer/play_current_list",
// this , SLOT( addSelected()) );
tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close");
tbDeletePlaylist->setFlat(TRUE);
tbDeletePlaylist->setFixedSize(20,20);
connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist()));
d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "mpegplayer/add_to_playlist",
this , SLOT(addSelected()) );
d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "mpegplayer/remove_from_playlist",
this , SLOT(removeSelected()) );
// d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE );
d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play",
this , SLOT( btnPlay(bool) ), TRUE );
d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"mpegplayer/shuffle",
mediaPlayerState, SLOT(setShuffled(bool)), TRUE );
d->tbLoop = new ToolButton( bar, tr( "Loop" ),"mpegplayer/loop",
mediaPlayerState, SLOT(setLooping(bool)), TRUE );
tbDeletePlaylist->hide();
QPopupMenu *pmPlayList = new QPopupMenu( this );
menu->insertItem( tr( "File" ), pmPlayList );
new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) );
new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) );
new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) );
new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) );
new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) );
// new MenuItem( pmPlayList, tr( "Load PlayList" ), this, SLOT( loadList() ) );
QPopupMenu *pmView = new QPopupMenu( this );
menu->insertItem( tr( "View" ), pmView );
fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0);
connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) );
fullScreenButton->addTo(pmView);
scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("mpegplayer/scale"), QString::null, 0, this, 0);
connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) );
scaleButton->addTo(pmView);
QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton );
QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton );
QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton );
tabWidget = new QTabWidget( hbox6, "tabWidget" );
tabWidget->setTabShape(QTabWidget::Triangular);
QWidget *pTab;
pTab = new QWidget( tabWidget, "pTab" );
// playlistView = new QListView( pTab, "playlistview" );
// playlistView->setMinimumSize(236,260);
tabWidget->insertTab( pTab,"Playlist");
// Add the playlist area
QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton );
d->playListFrame = vbox3;
d->playListFrame ->setMinimumSize(235,260);
QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton );
d->selectedFiles = new PlayListSelection( hbox2);
QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton );
QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold);
connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) );
QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch
new ToolButton( vbox1, tr( "Move Up" ), "mpegplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) );
new ToolButton( vbox1, tr( "Remove" ), "mpegplayer/cut", d->selectedFiles, SLOT(removeSelected()) );
new ToolButton( vbox1, tr( "Move Down" ), "mpegplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) );
QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch
QWidget *aTab;
aTab = new QWidget( tabWidget, "aTab" );
audioView = new QListView( aTab, "Audioview" );
audioView->setMinimumSize(233,260);
audioView->addColumn( tr("Title"),140);
audioView->addColumn(tr("Size"), -1);
audioView->addColumn(tr("Media"),-1);
audioView->setColumnAlignment(1, Qt::AlignRight);
audioView->setColumnAlignment(2, Qt::AlignRight);
audioView->setAllColumnsShowFocus(TRUE);
+// audioView->setMultiSelection( TRUE );
+// audioView->setSelectionMode( QListView::Extended);
+
tabWidget->insertTab(aTab,tr("Audio"));
QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold);
connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) );
// audioView
populateAudioView();
// videowidget
QWidget *vTab;
vTab = new QWidget( tabWidget, "vTab" );
videoView = new QListView( vTab, "Videoview" );
videoView->setMinimumSize(233,260);
videoView->addColumn(tr("Title"),140);
videoView->addColumn(tr("Size"),-1);
videoView->addColumn(tr("Media"),-1);
videoView->setColumnAlignment(1, Qt::AlignRight);
videoView->setColumnAlignment(2, Qt::AlignRight);
videoView->setAllColumnsShowFocus(TRUE);
+// videoView->setMultiSelection( TRUE );
+// videoView->setSelectionMode( QListView::Extended);
+
QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold);
connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) );
tabWidget->insertTab( vTab,tr("Video"));
//playlists list
QWidget *LTab;
LTab = new QWidget( tabWidget, "LTab" );
playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy
playLists->setMinimumSize(233,260);;
tabWidget->insertTab(LTab,tr("Lists"));
connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) );
// connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
// add the library area
// connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)),
// this, SLOT( fauxPlay( QListViewItem *) ) );
// connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)),
// this, SLOT( fauxPlay( QListViewItem *)) );
// connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) );
// connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) );
connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) );
connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) );
connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*)));
connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) );
connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) );
connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) );
connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) );
connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) );
// connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) );
setCentralWidget( vbox5 );
Config cfg( "MediaPlayer" );
readConfig( cfg );
QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
// qDebug("currentList is "+currentPlaylist);
loadList(DocLnk( currentPlaylist));
setCaption(tr("OpiePlayer: ")+ currentPlaylist );
initializeStates();
}
PlayListWidget::~PlayListWidget() {
Config cfg( "MediaPlayer" );
writeConfig( cfg );
if ( d->current )
delete d->current;
delete d;
}
void PlayListWidget::initializeStates() {
d->tbPlay->setOn( mediaPlayerState->playing() );
d->tbLoop->setOn( mediaPlayerState->looping() );
d->tbShuffle->setOn( mediaPlayerState->shuffled() );
// d->tbFull->setOn( mediaPlayerState->fullscreen() );
// d->tbScale->setOn( mediaPlayerState->scaled() );
// d->tbScale->setEnabled( mediaPlayerState->fullscreen() );
// setPlaylist( mediaPlayerState->playlist() );
setPlaylist( true);
d->selectedFiles->first();
}
void PlayListWidget::readConfig( Config& cfg ) {
cfg.setGroup("PlayList");
-
+ QString currentString = cfg.readEntry("current", "" );
int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
-
for ( int i = 0; i < noOfFiles; i++ ) {
QString entryName;
entryName.sprintf( "File%i", i + 1 );
QString linkFile = cfg.readEntry( entryName );
DocLnk lnk( linkFile );
- if ( lnk.isValid() )
+ if ( lnk.isValid() ) {
d->selectedFiles->addToSelection( lnk );
+ }
}
+// d->selectedFiles->setSelectedItem( (const QString &)currentString);
}
void PlayListWidget::writeConfig( Config& cfg ) const {
- cfg.setGroup("PlayList");
+ d->selectedFiles->writeCurrent( cfg);
+ cfg.setGroup("PlayList");
int noOfFiles = 0;
-
d->selectedFiles->first();
do {
- const DocLnk *lnk = d->selectedFiles->current();
- if ( lnk ) {
- QString entryName;
- entryName.sprintf( "File%i", noOfFiles + 1 );
- cfg.writeEntry( entryName, lnk->linkFile() );
- // if this link does exist, add it so we have the file
- // next time...
- if ( !QFile::exists( lnk->linkFile() ) ) {
- // the way writing lnks doesn't really check for out
- // of disk space, but check it anyway.
- if ( !lnk->writeLink() ) {
- QMessageBox::critical( 0, tr("Out of space"),
- tr( "There was a problem saving "
- "the playlist.\n"
- "Your playlist "
- "may be missing some entries\n"
- "the next time you start it." )
- );
+ const DocLnk *lnk = d->selectedFiles->current();
+ if ( lnk ) {
+ QString entryName;
+ entryName.sprintf( "File%i", noOfFiles + 1 );
+ qDebug(entryName);
+ cfg.writeEntry( entryName, lnk->linkFile() );
+ // if this link does exist, add it so we have the file
+ // next time...
+ if ( !QFile::exists( lnk->linkFile() ) ) {
+ // the way writing lnks doesn't really check for out
+ // of disk space, but check it anyway.
+ if ( !lnk->writeLink() ) {
+ QMessageBox::critical( 0, tr("Out of space"),
+ tr( "There was a problem saving "
+ "the playlist.\n"
+ "Your playlist "
+ "may be missing some entries\n"
+ "the next time you start it." )
+ );
+ }
+ }
+ noOfFiles++;
+ }
}
- }
- noOfFiles++;
- }
- } while ( d->selectedFiles->next() );
-
+ while ( d->selectedFiles->next() );
cfg.writeEntry("NumberOfFiles", noOfFiles );
-
-
}
void PlayListWidget::addToSelection( const DocLnk& lnk ) {
// qDebug("add");
d->setDocumentUsed = FALSE;
if ( mediaPlayerState->playlist() )
d->selectedFiles->addToSelection( lnk );
else
mediaPlayerState->setPlaying( TRUE );
}
void PlayListWidget::clearList() {
while ( first() )
d->selectedFiles->removeSelected();
}
void PlayListWidget::addAllToList() {
- DocLnkSet files;
- Global::findDocuments(&files, "video/*;audio/*");
- QListIterator<DocLnk> dit( files.children() );
- for ( ; dit.current(); ++dit )
- d->selectedFiles->addToSelection( **dit );
+ DocLnkSet filesAll;
+ Global::findDocuments(&filesAll, "video/*;audio/*");
+ QListIterator<DocLnk> Adit( filesAll.children() );
+ for ( ; Adit.current(); ++Adit )
+ d->selectedFiles->addToSelection( **Adit );
}
void PlayListWidget::addAllMusicToList() {
- DocLnkSet files;
- Global::findDocuments(&files, "audio/*");
+// DocLnkSet files;
+// Global::findDocuments(&files, "audio/*");
QListIterator<DocLnk> dit( files.children() );
for ( ; dit.current(); ++dit )
d->selectedFiles->addToSelection( **dit );
}
void PlayListWidget::addAllVideoToList() {
- DocLnkSet files;
- Global::findDocuments(&files, "video/*");
- QListIterator<DocLnk> dit( files.children() );
+ QListIterator<DocLnk> dit( vFiles.children() );
for ( ; dit.current(); ++dit )
d->selectedFiles->addToSelection( **dit );
}
void PlayListWidget::setDocument(const QString& fileref) {
fromSetDocument = TRUE;
if ( fileref.isNull() ) {
QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) );
return;
}
// qDebug("setDocument "+fileref);
if(fileref.find("playlist",0,TRUE) == -1) {
clearList();
addToSelection( DocLnk( fileref ) );
d->setDocumentUsed = TRUE;
mediaPlayerState->setPlaying( FALSE );
qApp->processEvents();
mediaPlayerState->setPlaying( TRUE );
qApp->processEvents();
setCaption(tr("OpiePlayer"));
} else { //is playlist
clearList();
loadList(DocLnk(fileref));
d->selectedFiles->first();
}
}
void PlayListWidget::setActiveWindow() {
// When we get raised we need to ensure that it switches views
char origView = mediaPlayerState->view();
mediaPlayerState->setView( 'l' ); // invalidate
mediaPlayerState->setView( origView ); // now switch back
}
void PlayListWidget::useSelectedDocument() {
d->setDocumentUsed = FALSE;
}
const DocLnk *PlayListWidget::current() { // this is fugly
// if( fromSetDocument) {
// qDebug("from setDoc");
// DocLnkSet files;
// Global::findDocuments(&files, "video/*;audio/*");
// QListIterator<DocLnk> dit( files.children() );
// for ( ; dit.current(); ++dit ) {
// if(dit.current()->linkFile() == setDocFileRef) {
// qDebug(setDocFileRef);
// return dit;
// }
// }
// } else
// qDebug("current");
// switch (tabWidget->currentPageIndex()) {
// case 0: //playlist
// {
- qDebug("playlist");
- if ( mediaPlayerState->playlist() ) {
- return d->selectedFiles->current();
- }
- else if ( d->setDocumentUsed && d->current ) {
- return d->current;
- } else {
- return d->files->selected();
- }
+ qDebug("playlist");
+ if ( mediaPlayerState->playlist() ) {
+ return d->selectedFiles->current();
+ }
+ else if ( d->setDocumentUsed && d->current ) {
+ return d->current;
+ } else {
+ return d->files->selected();
+ }
// }
// break;
// case 1://audio
// {
// qDebug("audioView");
// Global::findDocuments(&files, "audio/*");
// QListIterator<DocLnk> dit( files.children() );
// for ( ; dit.current(); ++dit ) {
// if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) {
// qDebug("here");
// insanityBool=TRUE;
// return dit;
// }
// }
// }
// break;
// case 2: // video
// {
// qDebug("videoView");
// Global::findDocuments(&vFiles, "video/*");
// QListIterator<DocLnk> Vdit( vFiles.children() );
// for ( ; Vdit.current(); ++Vdit ) {
// if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) {
// insanityBool=TRUE;
// return Vdit;
// }
// }
// }
// break;
// };
// return 0;
}
bool PlayListWidget::prev() {
if ( mediaPlayerState->playlist() ) {
- if ( mediaPlayerState->shuffled() ) {
- const DocLnk *cur = current();
- int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
- for ( int i = 0; i < j; i++ ) {
- if ( !d->selectedFiles->next() )
- d->selectedFiles->first();
- }
- if ( cur == current() )
- if ( !d->selectedFiles->next() )
- d->selectedFiles->first();
- return TRUE;
- } else {
- if ( !d->selectedFiles->prev() ) {
- if ( mediaPlayerState->looping() ) {
- return d->selectedFiles->last();
- } else {
- return FALSE;
- }
- }
- return TRUE;
- }
+ if ( mediaPlayerState->shuffled() ) {
+ const DocLnk *cur = current();
+ int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
+ for ( int i = 0; i < j; i++ ) {
+ if ( !d->selectedFiles->next() )
+ d->selectedFiles->first();
+ }
+ if ( cur == current() )
+ if ( !d->selectedFiles->next() )
+ d->selectedFiles->first();
+ return TRUE;
+ } else {
+ if ( !d->selectedFiles->prev() ) {
+ if ( mediaPlayerState->looping() ) {
+ return d->selectedFiles->last();
+ } else {
+ return FALSE;
+ }
+ }
+ return TRUE;
+ }
} else {
- return mediaPlayerState->looping();
+ return mediaPlayerState->looping();
}
}
bool PlayListWidget::next() {
if ( mediaPlayerState->playlist() ) {
- if ( mediaPlayerState->shuffled() ) {
- return prev();
- } else {
- if ( !d->selectedFiles->next() ) {
- if ( mediaPlayerState->looping() ) {
- return d->selectedFiles->first();
- } else {
- return FALSE;
- }
- }
- return TRUE;
- }
+ if ( mediaPlayerState->shuffled() ) {
+ return prev();
+ } else {
+ if ( !d->selectedFiles->next() ) {
+ if ( mediaPlayerState->looping() ) {
+ return d->selectedFiles->first();
+ } else {
+ return FALSE;
+ }
+ }
+ return TRUE;
+ }
} else {
- return mediaPlayerState->looping();
+ return mediaPlayerState->looping();
}
}
bool PlayListWidget::first() {
if ( mediaPlayerState->playlist() )
- return d->selectedFiles->first();
+ return d->selectedFiles->first();
else
- return mediaPlayerState->looping();
+ return mediaPlayerState->looping();
}
bool PlayListWidget::last() {
if ( mediaPlayerState->playlist() )
- return d->selectedFiles->last();
+ return d->selectedFiles->last();
else
- return mediaPlayerState->looping();
+ return mediaPlayerState->looping();
}
void PlayListWidget::saveList() {
QString filename;
InputDialog *fileDlg;
fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0);
fileDlg->exec();
if( fileDlg->result() == 1 ) {
- if ( d->current )
- delete d->current;
+ if ( d->current )
+ delete d->current;
filename = fileDlg->LineEdit1->text();//+".playlist";
-// qDebug("saving playlist "+filename+".playlist");
+// qDebug("saving playlist "+filename+".playlist");
Config cfg( filename +".playlist");
writeConfig( cfg );
- if( playLists->selected()->name() == filename) {
-// qDebug("same name so delete lnk");
- QFile().remove(playLists->selected()->file());
- QFile().remove(playLists->selected()->linkFile());
- playLists->reread();
- }
-
+
+// qDebug("same name so delete lnk??");
+// if( playLists->selected()->name() == filename) {
+
+// qDebug("same name so delete lnk");
+// QFile().remove(playLists->selected()->file());
+// QFile().remove(playLists->selected()->linkFile());
+// playLists->reread();
+// }
+// qDebug("new doclnk");
DocLnk lnk;
// lnk.setComment( "");
lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property
lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D
lnk.setIcon("mpegplayer/playlist2");
lnk.setName( filename); //sets file name
+ qDebug(filename);
if(!lnk.writeLink())
qDebug("Writing doclink did not work");
}
Config config( "MediaPlayer" );
config.writeEntry("CurrentPlaylist",filename);
setCaption(tr("OpiePlayer: ")+filename);
d->selectedFiles->first();
- if(fileDlg)
- delete fileDlg;
+ if(fileDlg)
+ delete fileDlg;
}
void PlayListWidget::loadList( const DocLnk & lnk) {
QString name= lnk.name();
// qDebug("currentList is "+name);
if( name.length()>1) {
setCaption("OpiePlayer: "+name);
// qDebug("load list "+ name+".playlist");
clearList();
Config cfg( name+".playlist");
readConfig(cfg);
+
tabWidget->setCurrentPage(0);
+
Config config( "MediaPlayer" );
config.writeEntry("CurrentPlaylist", name);
- d->selectedFiles->first();
+// d->selectedFiles->first();
}
+
}
void PlayListWidget::setPlaylist( bool shown ) {
if ( shown )
d->playListFrame->show();
else
d->playListFrame->hide();
}
void PlayListWidget::setView( char view ) {
if ( view == 'l' )
showMaximized();
else
hide();
}
void PlayListWidget::addSelected() {
Config cfg( "MediaPlayer" );
cfg.setGroup("PlayList");
QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
switch (tabWidget->currentPageIndex()) {
case 0: //playlist
break;
case 1: { //audio
for ( int i = 0; i < noOfFiles; i++ ) {
QString entryName;
entryName.sprintf( "File%i", i + 1 );
QString linkFile = cfg.readEntry( entryName );
if( DocLnk( linkFile).name() == audioView->selectedItem()->text(0) ) {
int result= QMessageBox::warning(this,tr("OpiePlayer"),
tr("This is all ready in your playlist.\nContinue?"),
tr("Yes"),tr("No"),0,0,1);
if (result !=0)
return;
}
}
addToSelection( audioView->selectedItem() );
tabWidget->setCurrentPage(1);
}
break;
case 2: { // video
for ( int i = 0; i < noOfFiles; i++ ) {
QString entryName;
entryName.sprintf( "File%i", i + 1 );
QString linkFile = cfg.readEntry( entryName );
if( DocLnk( linkFile).name() == videoView->selectedItem()->text(0) ) {
int result= QMessageBox::warning(this,tr("OpiePlayer"),
tr("This is all ready in your playlist.\nContinue?"),
tr("Yes"),tr("No"),0,0,1);
if (result !=0)
return;
}
}
addToSelection( videoView->selectedItem() );
tabWidget->setCurrentPage(2);
}
break;
};
}
void PlayListWidget::removeSelected() {
d->selectedFiles->removeSelected( );
}
void PlayListWidget::playIt( QListViewItem *it) {
// d->setDocumentUsed = FALSE;
mediaPlayerState->setPlaying(TRUE);
}
void PlayListWidget::addToSelection( QListViewItem *it) {
d->setDocumentUsed = FALSE;
if(it) {
switch (tabWidget->currentPageIndex()) {
case 1: {
QListIterator<DocLnk> dit( files.children() );
for ( ; dit.current(); ++dit ) {
if( dit.current()->name() == it->text(0)) {
d->selectedFiles->addToSelection( **dit );
}
}
}
break;
case 2: {
QListIterator<DocLnk> dit( vFiles.children() );
for ( ; dit.current(); ++dit ) {
if( dit.current()->name() == it->text(0)) {
d->selectedFiles->addToSelection( **dit );
}
}
}
break;
case 0:
break;
};
tabWidget->setCurrentPage(0);
}
}
void PlayListWidget::tabChanged(QWidget *widg) {
switch ( tabWidget->currentPageIndex()) {
case 0:
{
if( !tbDeletePlaylist->isHidden())
tbDeletePlaylist->hide();
d->tbRemoveFromList->setEnabled(TRUE);
d->tbAddToList->setEnabled(FALSE);
}
break;
case 1:
{
if( !tbDeletePlaylist->isHidden())
tbDeletePlaylist->hide();
d->tbRemoveFromList->setEnabled(FALSE);
d->tbAddToList->setEnabled(TRUE);
}
break;
case 2:
{
if( !tbDeletePlaylist->isHidden())
tbDeletePlaylist->hide();
d->tbRemoveFromList->setEnabled(FALSE);
d->tbAddToList->setEnabled(TRUE);
}
break;
case 3:
{
if( tbDeletePlaylist->isHidden())
tbDeletePlaylist->show();
playLists->reread();
}
break;
};
}
void PlayListWidget::btnPlay(bool b) {
// mediaPlayerState->setPlaying(b);
switch ( tabWidget->currentPageIndex()) {
case 0:
{
mediaPlayerState->setPlaying(b);
}
break;
case 1:
{
addToSelection( audioView->selectedItem() );
mediaPlayerState->setPlaying(b);
// qApp->processEvents();
d->selectedFiles->removeSelected( );
tabWidget->setCurrentPage(1);
- d->selectedFiles->unSelect();
+ audioView->clearSelection();
+// d->selectedFiles->unSelect();
// mediaPlayerState->setPlaying(FALSE);
}
break;
case 2:
{
addToSelection( videoView->selectedItem() );
mediaPlayerState->setPlaying(b);
qApp->processEvents();
d->selectedFiles->removeSelected( );
tabWidget->setCurrentPage(2);
- d->selectedFiles->unSelect();
+ videoView->clearSelection();
+// d->selectedFiles->unSelect();
// mediaPlayerState->setPlaying(FALSE);
}
break;
};
}
void PlayListWidget::deletePlaylist() {
switch( QMessageBox::information( this, (tr("Remove Playlist?")),
(tr("You really want to delete\nthis playlist?")),
(tr("Yes")), (tr("No")), 0 )){
case 0: // Yes clicked,
QFile().remove(playLists->selected()->file());
QFile().remove(playLists->selected()->linkFile());
playLists->reread();
break;
case 1: // Cancel
break;
};
}
void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i)
{
switch (mouse) {
case 1:
break;
case 2:{
QPopupMenu m;
m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() ));
m.insertSeparator();
m.insertItem( tr( "Properties" ), this, SLOT( listDelete() ));
m.exec( QCursor::pos() );
}
break;
};
}
void PlayListWidget::playSelected()
{
btnPlay( TRUE);
}
void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *item, const QPoint& point, int i)
{
switch (mouse) {
case 1:
break;
case 2:{
QPopupMenu m;
m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() ));
m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
// m.insertSeparator();
m.exec( QCursor::pos() );
}
break;
};
}
void PlayListWidget::listDelete() {
Config cfg( "MediaPlayer" );
cfg.setGroup("PlayList");
QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
QString file;
int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
switch ( tabWidget->currentPageIndex()) {
case 0:
break;
case 1:
{
file = audioView->selectedItem()->text(0);
// Global::findDocuments(&files, "audio/*");
// AppLnkSet appFiles;
QListIterator<DocLnk> dit( files.children() );
for ( ; dit.current(); ++dit ) {
if( dit.current()->name() == file) {
qDebug(file);
LnkProperties prop( dit.current() );
// connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *)));
prop.showMaximized();
prop.exec();
}
}
populateAudioView();
}
break;
case 2:
{
// file = videoView->selectedItem()->text(0);
// for ( int i = 0; i < noOfFiles; i++ ) {
// QString entryName;
// entryName.sprintf( "File%i", i + 1 );
// QString linkFile = cfg.readEntry( entryName );
// AppLnk lnk( AppLnk(linkFile));
// if( lnk.name() == file ) {
// LnkProperties prop( &lnk);
// // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *)));
// prop.showMaximized();
// prop.exec();
// }
// }
}
break;
};
}
void PlayListWidget::populateAudioView() {
// if(files)
// files.~DocLnkSet();
+ StorageInfo storageInfo;
+ const QList<FileSystem> &fs = storageInfo.fileSystems();
+
Global::findDocuments(&files, "audio/*");
QListIterator<DocLnk> dit( files.children() );
+ QListIterator<FileSystem> it ( fs );
audioView->clear();
QString storage;
for ( ; dit.current(); ++dit ) {
+ for( ; it.current(); ++it ){
+ const QString name = (*it)->name();
+ const QString path = (*it)->path();
+ if(dit.current()->file().find(path) != -1 ) storage=name;
+ }
+
QListViewItem * newItem;
- if(dit.current()->file().find("/mnt/cf") != -1 ) storage=tr("CF");
- else if(dit.current()->file().find("/mnt/hda") != -1 ) storage=tr("CF");
- else if(dit.current()->file().find("/mnt/card") != -1 ) storage=tr("SD");
- else storage=tr("RAM");
if ( QFile( dit.current()->file()).exists() ) {
newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage);
newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/musicfile" ));
}
}
}
void PlayListWidget::populateVideoView() {
+ StorageInfo storageInfo;
+ const QList<FileSystem> &fs = storageInfo.fileSystems();
+
Global::findDocuments(&vFiles, "video/*");
QListIterator<DocLnk> Vdit( vFiles.children() );
+ QListIterator<FileSystem> it ( fs );
videoView->clear();
- QString storage;
+ QString storage;
for ( ; Vdit.current(); ++Vdit ) {
- if( Vdit.current()->file().find("/mnt/cf") != -1 ) storage=tr("CF");
- else if( Vdit.current()->file().find("/mnt/hda") != -1 ) storage=tr("CF");
- else if( Vdit.current()->file().find("/mnt/card") != -1 ) storage=tr("SD");
- else storage=tr("RAM");
+ for( ; it.current(); ++it ){
+ const QString name = (*it)->name();
+ const QString path = (*it)->path();
+ if( Vdit.current()->file().find(path) != -1 ) storage=name;
+ }
+
QListViewItem * newItem;
if ( QFile( Vdit.current()->file()).exists() ) {
newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage);
newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/videofile" ));
}
}
}