各位老大帮帮忙啊
#include "vedio.h"
#include <qvariant.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qslider.h>
#include <qspinbox.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qimage.h>
#include <qpixmap.h>
#include <qprogressbar.h>
#include <qtimer.h>
//////////////////////////////////////////////////////////
#include <qregexp.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <sys/soundcard.h>
#include <math.h>
#include <sys/types.h>
#include <stdlib.h>
#include <dirent.h>
//#include <alloc.h>
#include <string.h>
#include <stdio.h>
DIR *dir;
struct dirent *entry;
struct FileList
{
char filename[256];
struct FileList *next;
struct FileList *pre;
}start,*node,*selfdir;
//////////////////////////////////////////////////////////
/*
* Constructs a Vedio as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* TRUE to construct a modal dialog.
*/
Vedio::Vedio( QWidget* parent, const char* name, bool modal, WFlags fl )
: QDialog( parent, name, modal, fl )
{
if ( !name )
setName( "Vedio" );
///////////////////////////////////////////////////////////////////////
type=begin;
isPause=false;
mixerfd=open("/dev/mixer",O_RDWR,0);
mp=new QProcess(this);
playtimer = new QTimer(this);
playtimer->start(10);
playpos=-1;
soundDev=0;
// mp->setCommunication(QProcess::Stdout);
///////////////////////////////////////////////////////////////////////
group = new QGroupBox( this, "group" );
group->setGeometry( QRect( 0, 310, 280, 73 ) );
group->setFrameShape( QGroupBox::GroupBoxPanel );
group->setFrameShadow( QGroupBox::Sunken );
group->setPaletteBackgroundColor(QColor(180,204,255));
sliderVedio = new QSlider( group, "slider1" );
sliderVedio->setGeometry( QRect( 1, 15, 211, 9 ) );
sliderVedio->setOrientation( QSlider::Horizontal );
sliderVedio->setTickmarks(QSlider::Below);
sliderVedio->setLineStep(1);
sliderVedio->setMinValue(0);
sliderVedio->setMaxValue(100);
schedule = new QProgressBar(group,"schedule");
schedule->setGeometry(QRect(2,24,237,10));
schedule->setFrameShape(QProgressBar::MShape);
schedule->setFrameShadow(QProgressBar::MShadow);
schedule->setProgress(0,100);
spinVolume = new QSpinBox( group, "spinVol" );
spinVolume->setGeometry( QRect( 234, 40, 44, 30 ) );
spinVolume->setPaletteBackgroundColor(QColor(180,204,255));
spinVolume->setMaxValue(100);
spinVolume->setMinValue(0);
spinVolume->setValue(Vedio::getVolume());
volume=spinVolume->value();
ButtStop = new QPushButton( group, "ButtFile" );
ButtStop->setGeometry( QRect( 44, 40, 31, 31 ) );
ButtStop->setPixmap(QPixmap::fromMimeSource( "image/Stop.png"));
ButtStop->setFlat(true);
//ButtStop->setDefault(true);
ButtBack = new QPushButton(group,"ButtBack");
ButtBack->setGeometry( QRect(73,40,31,31));
ButtBack->setPixmap(QPixmap::fromMimeSource( "image/Back.png"));
ButtBack->setFlat(true);
ButtForward = new QPushButton(group,"ButtForward");
ButtForward->setGeometry( QRect(102,40,31,31));
ButtForward->setPixmap(QPixmap::fromMimeSource( "image/Forward.png"));
ButtForward->setFlat(true);
ButtPre = new QPushButton( group, "ButtPre" );
ButtPre->setGeometry( QRect( 131, 40, 31, 31 ) );
ButtPre->setPixmap( QPixmap::fromMimeSource( "image/Pre.png"));
ButtPre->setFlat(true);
ButtPlay = new QPushButton( group, "ButtPlay" );
ButtPlay->setGeometry( QRect( 15, 40, 31, 31 ) );
ButtPlay->setPixmap( QPixmap::fromMimeSource( "image/Play.png" ) );
ButtPlay->setFlat(true);
ButtNext = new QPushButton( group, "ButtNext" );
ButtNext->setGeometry( QRect( 160, 40, 31, 31 ) );
ButtNext->setPixmap( QPixmap::fromMimeSource( "image/Next.png"));
ButtNext->setFlat(true);
//textTime = new QLabel( group, "textTime" );
//textTime->setGeometry( QRect( 220, 10, 61, 21 ) );
ButtAudio = new QPushButton( group, "textAudio" );
ButtAudio->setGeometry( QRect( 204, 40, 31, 31 ) );
ButtAudio->setFlat(true);
if(volume>85)
{
ButtAudio->setPixmap( QPixmap::fromMimeSource( "image/Sound.png"));
}
else if(volume>50&&volume<=85)
{
ButtAudio->setPixmap( QPixmap::fromMimeSource( "image/Sound1.png"));
}
else if(volume>0&&volume<=50)
{
ButtAudio->setPixmap( QPixmap::fromMimeSource( "image/Sound2.png"));
}
else
{
ButtAudio->setPixmap( QPixmap::fromMimeSource( "image/Mute.png"));
}
languageChange();
resize( QSize(280, 383).expandedTo(minimumSizeHint()) );
// signals and slots connections
connect( sliderVedio, SIGNAL( sliderMoved(int) ), this, SLOT ( playSeek() ) );
// connect( sliderVedio, SIGNAL( sliderPressed() ), this, SLOT (playSeek() ) );
connect( spinVolume, SIGNAL( valueChanged(int) ), this, SLOT( setVolume(int) ) );
connect( playtimer, SIGNAL( timeout() ), this,SLOT( updateSliderVedio() ) ) ;
connect( ButtAudio, SIGNAL(clicked() ), this, SLOT( Mute() ) );
connect( ButtPlay, SIGNAL( clicked() ), this, SLOT( Play() ) );
connect( ButtPlay, SIGNAL( pressed() ), this, SLOT( PlayImage() ) );
//connect( ButtNext, SIGNAL( clicked() ), this, SLOT( ) );
connect( ButtNext, SIGNAL( pressed() ), this, SLOT( NextImage() ) );
connect( ButtPre, SIGNAL( clicked() ), this, SLOT( Previous() ) );
connect( ButtPre, SIGNAL( pressed() ), this, SLOT( PreImage() ) );
connect( ButtStop, SIGNAL( clicked()), this, SLOT( Stop() ) );
///////////////////////////////////////////////////////////////////////////////////
setTabOrder(ButtPlay,ButtStop);
setTabOrder(ButtStop,ButtBack);
setTabOrder(ButtBack,ButtForward);
setTabOrder(ButtForward,ButtPre);
setTabOrder(ButtPre,ButtNext);
setTabOrder(ButtNext,ButtAudio);
//////////////////////////////////////////////////////////////////////////////////////
}
/*
* Destroys the object and frees any allocated resources
*/
Vedio::~Vedio()
{
mp->kill();
close(mixerfd);
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void Vedio::languageChange()
{
setCaption( tr( "Vedio" ) );
group->setTitle( QString::null );
ButtStop->setText( QString::null );
ButtPre->setText( QString::null );
ButtPlay->setText( QString::null );
ButtNext->setText( QString::null );
ButtForward->setText(QString::null);
ButtBack->setText(QString::null);
//textTime->setText( QString::null );
ButtAudio->setText( QString::null );
}
void Vedio::Play()
{
if(type==begin)
{
type=play;
ButtPlay->setPixmap(QPixmap::fromMimeSource("image/Pause.png"));
if(!mp->isRunning())
{
if((dir=opendir("movie/"))!=NULL)
{
start.next=NULL;
node=&start;
while((entry=readdir(dir))!=NULL)
{
node->next=(struct FileList *)malloc(sizeof(struct FileList));
node->next->pre=node;
node=node->next;
strcpy(node->filename,entry->d_name);
node->next=NULL;
}
closedir(dir);
node=start.next;
node=node->next;
selfdir=node->next;
node=node->next;
}
Vedio::setProcess(mp);
QString cmd("movie/");
cmd.append(QString::fromAscii(node->filename));
setCaption(tr(cmd));
qWarning(cmd);
mp->addArgument(cmd);
mp->start();
}
}
else if(type==play&&!isPause)
{
isPause=true;
type=pause;
ButtPlay->setPixmap(QPixmap::fromMimeSource("image/Play.png"));
QString s("pause\n");
mp->writeToStdin(s);
}
else if(type==pause&&isPause)
{
type=play;
isPause=false;
ButtPlay->setPixmap(QPixmap::fromMimeSource("image/Pause.png"));
QString s("pause\n");
mp->writeToStdin(s);
}
else if(type==stop)
{
mp=new QProcess(this);
mp->clearArguments();
Vedio::setProcess(mp);
}
}
void Vedio::Stop()
{
if(type!=stop)
{
QString cmd="quit\n";
mp->writeToStdin(cmd);
mp->kill();
isPause=false;
type=stop;
ButtPlay->setPixmap(QPixmap::fromMimeSource("image/Play.png"));
sliderVedio->setValue(0);
}
}
void Vedio::Next()
{
}
void Vedio::Previous()
{
}
void Vedio::Back()
{
if (type==play||type==pause)
{
if (playpos>0)
{
QString cmd="seek -10\n";
mp->writeToStdin(cmd);
}
}
}
void Vedio::Forward()
{
if (type==play||type==pause)
{
if (playpos<100)
{
QString cmd="seek +10\n";
mp->writeToStdin(cmd);
}
}
}
void Vedio::setVolume(int)
{
volume=spinVolume->value();
if(volume>85)
{
ButtAudio->setPixmap( QPixmap::fromMimeSource( "image/Sound.png"));
}
else if(volume>50&&volume<=85)
{
ButtAudio->setPixmap( QPixmap::fromMimeSource( "image/Sound1.png"));
}
else if(volume>0&&volume<=50)
{
ButtAudio->setPixmap( QPixmap::fromMimeSource( "image/Sound2.png"));
}
else
{
ButtAudio->setPixmap( QPixmap::fromMimeSource( "image/Mute.png"));
}
volume=((volume << 8)|(volume & 0xff));
ioctl(mixerfd,MIXER_WRITE(soundDev),&volume);
}
int Vedio::getVolume()
{
int result=-1;
ioctl(mixerfd, MIXER_READ(soundDev),&result);
return result >> 8 ;
}
void Vedio::Mute()
{
volume=spinVolume->value();
int curVol=Vedio::getVolume();
int setVol;
int dev=0;
if(curVol>0)
{
setVol=(0<<8)|(0 & 0xff);
ioctl(mixerfd,MIXER_WRITE(soundDev),&setVol);
ButtAudio->setPixmap(QPixmap::fromMimeSource("image/Mute.png"));
}
else
{
if(volume>85)
{
ButtAudio->setPixmap( QPixmap::fromMimeSource( "image/Sound.png"));
}
else if(volume>50&&volume<=85)
{
ButtAudio->setPixmap( QPixmap::fromMimeSource( "image/Sound1.png"));
}
else if(volume>0&&volume<=50)
{
ButtAudio->setPixmap( QPixmap::fromMimeSource( "image/Sound2.png"));
}
setVol=(volume<<8)|(volume & 0xff);
ioctl(mixerfd,MIXER_WRITE(soundDev),&setVol);
}
}
void Vedio::playSeek()
{
if(type==play||type==pause)
{
QString cmd="seek ";
cmd+=QString::number(sliderVedio->value());
cmd+=" ";
cmd+=QString::number(1);
cmd+="\n";
mp->writeToStdin(cmd);
}
}
void Vedio::updateSliderVedio()
{
if(type==play)
{
QString cmd="get_percent_pos\n";
mp->writeToStdin(cmd);
QRegExp get_percent_pos("ANS_PERCENT_POSITION=(\\d+)");
playpos=get_percent_pos.search(mp->readStdout());
if(palypos>-1&&playpos<100)
{
percentpos=get_percent_pos.cap(1);
sliderVedio->setValue(percentpos.toInt());
schedule->setProgress(percentpos.toInt());
}
else if(playpos>-1&&playpos==100)
{
mp->writeToStdin("quit\n");
mp->kill();
schedule->setProgress(0);
type=stop;
}
}
}
void Vedio::setProcess(QProcess *p)
{
p->addArgument("./mplayer");
p->addArgument("-slave");
p->addArgument("-quiet");
p->addArgument("-vo");
p->addArgument("x11");
p->addArgument("-nomouseinput");
p->addArgument("-noconsolecontrols");
// p->addArgument("-zoom");
p->addArgument("-wid");
p->addArgument(QString::number(this->winId()));
p->addArgument("-zoom");
}
void Vedio::PlayImage()
{
if(type==pause||type==begin)
{
ButtPlay->setPixmap(QPixmap::fromMimeSource("image/Play1.png"));
}
else (type==play)
{
ButtPlay->setPixmap(QPixmap::fromMimeSource("image/Pause1.png"));
}
}
void Vedio::NextImage()
{
ButtNext->setPixmap(QPixmap::fromMimeSource("image/Next1.png"));
}
void Vedio::PreImage()
{
ButtPre->setPixmap(QPixmap::fromMimeSource("image/Pre1.png"));
}