Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mwindow.cpp

Go to the documentation of this file.
00001 /*
00002                             This file is part of the Opie Project
00003 
00004                              Copyright (c)  2002 Max Reiss <harlekin@handhelds.org>
00005                              Copyright (c)  2002 L. Potter <ljp@llornkcor.com>
00006                              Copyright (c)  2002 Holger Freyther <zecke@handhelds.org>
00007               =.
00008             .=l.
00009            .>+-=
00010  _;:,     .>    :=|.         This program is free software; you can
00011 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00012 :`=1 )Y*s>-.--   :           the terms of the GNU General Public
00013 .="- .-=="i,     .._         License as published by the Free Software
00014  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00015      ._= =}       :          or (at your option) any later version.
00016     .%`+i>       _;_.
00017     .i_,=:_.      -<s.       This program is distributed in the hope that
00018      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00019     : ..    .:,     . . .    without even the implied warranty of
00020     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00021   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00022 ..}^=.=       =       ;      Library General Public License for more
00023 ++=   -.     .`     .:       details.
00024  :     =  ...= . :.=-
00025  -.   .:....=;==+<;          You should have received a copy of the GNU
00026   -_. . .   )=.  =           Library General Public License along with
00027     --        :-=`           this library; see the file COPYING.LIB.
00028                              If not, write to the Free Software Foundation,
00029                              Inc., 59 Temple Place - Suite 330,
00030                              Boston, MA 02111-1307, USA.
00031 
00032 */
00033 
00034 #include "mwindow.h"
00035 #include "playlist.h"
00036 #include "audiowidget.h"
00037 #include "videowidget.h"
00038 #include "../opieplayer2/lib.h"
00039 
00040 #include <opie2/oapplicationfactory.h>
00041 #include <opie2/owidgetstack.h>
00042 #include <opie2/ofileselector.h>
00043 #include <opie2/odebug.h>
00044 #include <opie2/oresource.h>
00045 
00046 #include <qpe/qpeapplication.h>
00047 
00048 #include <qfileinfo.h>
00049 #include <qfile.h>
00050 #include <qtoolbar.h>
00051 #include <qpopupmenu.h>
00052 #include <qmenubar.h>
00053 #include <qtimer.h>
00054 #include <qslider.h>
00055 #include <qlayout.h>
00056 
00057 OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<PMainWindow>)
00058 
00059 using namespace Opie::Ui;
00060 
00061 PMainWindow::PMainWindow(QWidget*w, const char*name, WFlags f)
00062     : QMainWindow(w,name,f)
00063 {
00064     checkLib();
00065     setCaption(appTitle());
00066 
00067     m_MainBox = new QWidget(this);
00068 
00069     QVBoxLayout*m_l = new QVBoxLayout(m_MainBox);
00070 
00071     m_stack = new OWidgetStack(m_MainBox);
00072     m_stack->forceMode(Opie::Ui::OWidgetStack::SmallScreen);
00073     m_l->addWidget(m_stack);
00074     m_PosSlider = new QSlider(QSlider::Horizontal,m_MainBox);
00075     m_l->addWidget(m_PosSlider);
00076     m_PosSlider->setEnabled(false);
00077 
00078     m_playList = new PlaylistView(m_stack,"playlist");
00079     m_stack->addWidget(m_playList,stack_list);
00080     connect(m_playList,SIGNAL(contentChanged(int)),this,SLOT(slotListChanged(int)));
00081     m_sfl = new OFileSelector("video/*;audio/*",m_stack);
00082     m_stack->addWidget(m_sfl,stack_file);
00083     connect(m_sfl, SIGNAL(fileSelected(const DocLnk &)), m_playList, SLOT(slotAddFile(const DocLnk &)));
00084     m_AudioPlayer = new AudioWidget(m_stack);
00085     m_stack->addWidget(m_AudioPlayer,stack_audio);
00086     connect(this,SIGNAL(sigPos(int)),m_AudioPlayer,SLOT(updatePos(int)));
00087     m_VideoPlayer = new VideoWidget(m_stack);
00088     m_stack->addWidget(m_VideoPlayer,stack_video);
00089     connect(this,SIGNAL(sigPos(int)),m_VideoPlayer,SLOT(updatePos(int)));
00090     connect(m_VideoPlayer,SIGNAL(videoclicked()),this,SLOT(slotVideoclicked()));
00091 
00092     connect(m_PosSlider,SIGNAL(valueChanged(int)),this,SLOT(slotNewPos(int)));
00093     connect(m_PosSlider,SIGNAL(sliderMoved(int)),this,SLOT(slotNewPos(int)));
00094     connect(m_PosSlider,SIGNAL(sliderPressed()),this,SLOT(sliderPressed()));
00095     connect(m_PosSlider,SIGNAL(sliderReleased()),this,SLOT(sliderReleased()));
00096     m_pressed = false;
00097     m_uppos=0;
00098 
00099     m_stack->raiseWidget(stack_list);
00100     m_LastItem = 0;
00101     setupActions();
00102     setupToolBar();
00103     setupMenu();
00104 
00105     setCentralWidget(m_MainBox );
00106 }
00107 
00108 void PMainWindow::slotListChanged(int count)
00109 {
00110     playersGroup->setEnabled(count>0);
00111     if (!m_playList->isVisible()) {
00112         return;
00113     }
00114     a_removeFiles->setEnabled(count>0);
00115 }
00116 
00117 void PMainWindow::mediaWindowraised()
00118 {
00119     playlistOnly->setEnabled(false);
00120     a_appendFiles->setEnabled(true);
00121     a_loadPlaylist->setEnabled(true);
00122     a_showPlaylist->setEnabled(true);
00123     a_ShowMedia->setEnabled(false);
00124 }
00125 
00126 void PMainWindow::checkLib()
00127 {
00128     if (m_PlayLib == 0) {
00129         m_PlayLib = new XINE::Lib(XINE::Lib::InitializeInThread);
00130         qApp->processEvents();
00131 //        m_PlayLib->ensureInitialized();
00132         connect(m_PlayLib,SIGNAL(stopped()),this,SLOT(slotStopped()));
00133     }
00134 }
00135 
00136 PMainWindow::~PMainWindow()
00137 {
00138     if (m_PlayLib) {
00139         m_PlayLib->stop();
00140         delete m_PlayLib;
00141     }
00142 }
00143 
00144 void PMainWindow::fileSelected(const DocLnk&)
00145 {
00146 }
00147 
00148 void PMainWindow::slotAppendFiles()
00149 {
00150     m_stack->raiseWidget(m_sfl);
00151     playlistOnly->setEnabled(false);
00152 
00153     a_showPlaylist->setEnabled(true);
00154     if (m_PlayLib && m_playing) {
00155         a_ShowMedia->setEnabled(true);
00156     } else {
00157         a_ShowMedia->setEnabled(false);
00158     }
00159 }
00160 
00161 void PMainWindow::slotShowList()
00162 {
00163     m_stack->raiseWidget(m_playList);
00164     playlistOnly->setEnabled(true);
00165     a_showPlaylist->setEnabled(false);
00166     if (m_playList->childCount()) {
00167         a_removeFiles->setEnabled(true);
00168     } else {
00169         a_removeFiles->setEnabled(false);
00170     }
00171     if (m_PlayLib && m_playing) {
00172         a_ShowMedia->setEnabled(true);
00173     } else {
00174         a_ShowMedia->setEnabled(false);
00175     }
00176 }
00177 
00178 void PMainWindow::slotShowMediaWindow()
00179 {
00180     if (m_playing && m_LastItem && m_PlayLib) {
00181         if (!m_LastItem->isVideo()) {
00182             m_stack->raiseWidget(stack_audio);
00183         } else {
00184             m_stack->raiseWidget(stack_video);
00185         }
00186         mediaWindowraised();
00187         return;
00188     }
00189 }
00190 
00191 void PMainWindow::slotPlayList()
00192 {
00193     if (m_playing && m_LastItem && m_PlayLib) {
00194         slotShowMediaWindow();
00195         return;
00196     }
00197 
00198     m_LastItem = m_playList->currentItem();
00199     if (!m_LastItem) {
00200         slotPlayNext();
00201         return;
00202     }
00203     //m_VideoPlayer->setFullScreen(a_ShowFull->isOn());
00204     slotPlayCurrent();
00205 }
00206 
00207 void PMainWindow::slotUserStop()
00208 {
00209     if (!m_playing || !m_PlayLib) return;
00210     m_playing = false;
00211     m_PlayLib->stop();
00212     m_PosSlider->setEnabled(false);
00213     hideVideo();
00214     slotShowList();
00215     setCaption(appTitle());
00216 }
00217 
00218 void PMainWindow::slotTogglePlay(bool how)
00219 {
00220     if (how == m_playing) {
00221         if (how) {
00222             slotShowMediaWindow();
00223         }
00224         return;
00225     }
00226     if (how) {
00227         slotPlayList();
00228     } else {
00229         slotUserStop();
00230     }
00231 }
00232 
00233 void PMainWindow::hideVideo()
00234 {
00235     if (m_VideoPlayer->isVisible() && a_ShowFull->isOn()) {
00236         //m_VideoPlayer->showNormal();
00237         m_VideoPlayer->hide();
00238     }
00239 }
00240 
00241 void PMainWindow::slotPlayCurrent()
00242 {
00243     if (!m_LastItem) {
00244         if (m_PlayLib) m_PlayLib->stop();
00245         m_PosSlider->setEnabled(false);
00246         a_playAction->setOn(false);
00247         hideVideo();
00248         slotShowList();
00249         setCaption(appTitle());
00250         return;
00251     }
00252     m_CurrentPos = 0;
00253     m_playList->setCurrentItem(m_LastItem);
00254     m_uppos = 0;
00255     m_PosSlider->setValue(0);
00256     int result = 0;
00257     if (!m_LastItem->isVideo()) {
00258         hideVideo();
00259         m_playing = true;
00260         m_stack->raiseWidget(stack_audio);
00261         result = m_AudioPlayer->playFile(m_LastItem->Lnk(),m_PlayLib);
00262     } else {
00263         m_playing = true;
00264         setupVideo(a_ShowFull->isOn());
00265         result = m_VideoPlayer->playFile(m_LastItem->Lnk(),m_PlayLib);
00266     }
00267     if (result<0) {
00268         // fehler
00269         return;
00270     }
00271     mediaWindowraised();
00272     setCaption(appTitle()+" - "+m_LastItem->Lnk().name());
00273     odebug << "Range: " << result << oendl;
00274     m_PosSlider->setEnabled(true);
00275     m_PosSlider->setRange(0,m_PlayLib->length());
00276     m_PosSlider->setValue(m_PlayLib->currentTime());
00277     QTimer::singleShot( 500, this, SLOT( slotCheckPos() ) );
00278 }
00279 
00280 void PMainWindow::slotPlayNext()
00281 {
00282     PlaylistItem*item = m_playList->nextItem(m_LastItem);
00283     if (!item) return;
00284     m_LastItem = item;
00285     slotPlayCurrent();
00286 }
00287 
00288 void PMainWindow::slotGoNext()
00289 {
00290     m_LastItem = m_playList->nextItem(m_LastItem);
00291     slotPlayCurrent();
00292 }
00293 
00294 void PMainWindow::slotPlayPrevious()
00295 {
00296     PlaylistItem*item = m_playList->prevItem(m_LastItem);
00297     if (!item) return;
00298     m_LastItem = item;
00299     slotPlayCurrent();
00300 }
00301 
00302 void PMainWindow::slotStopped()
00303 {
00304     if (!m_playing) return;
00305     odebug << "Slot stopped" << oendl;
00306     m_playing = false;
00307     slotGoNext();
00308 }
00309 
00310 void PMainWindow::slotCheckPos()
00311 {
00312     if (!m_playing) return;
00313     if (!m_pressed) {
00314         m_uppos = m_PlayLib->currentTime();
00315         emit sigPos(m_uppos);
00316         m_PosSlider->setValue(m_PlayLib->currentTime());
00317     }
00318     qApp->processEvents(100);
00319     QTimer::singleShot( 900, this, SLOT( slotCheckPos() ) );
00320 }
00321 
00322 void PMainWindow::slotRemoveFiles()
00323 {
00324     if (m_playing||!m_playList->isVisible()) return;
00325     PlaylistItem* Item = m_playList->currentItem();
00326     slotShowList();
00327     m_playList->removeFromList(Item);
00328 }
00329 
00330 void PMainWindow::setupActions()
00331 {
00332     a_appendFiles = new QAction(tr("Append file(s)"),Opie::Core::OResource::loadPixmap( "opieplayer2/add_to_playlist",
00333                                 Opie::Core::OResource::SmallIcon ), 0, 0, this, 0, false );
00334     connect(a_appendFiles,SIGNAL(activated()),this,SLOT(slotAppendFiles()));
00335     a_addDir = new QAction(tr("Add directory"),Opie::Core::OResource::loadPixmap("folder_open",
00336                            Opie::Core::OResource::SmallIcon),0,0,this,0,false);
00337     connect(a_addDir,SIGNAL(activated()),m_playList,SLOT(slotAppendDir()));
00338     a_loadPlaylist = new QAction(tr("Append playlist"),Opie::Core::OResource::loadPixmap("opieplayer2/add_to_playlist",
00339                                  Opie::Core::OResource::SmallIcon),0,0,this,0,false);
00340     connect(a_loadPlaylist,SIGNAL(activated()),m_playList,SLOT(slotOpenM3u()));
00341     a_savePlaylist = new QAction(tr("Save playlist"),Opie::Core::OResource::loadPixmap("save",
00342                                  Opie::Core::OResource::SmallIcon),0,0,this,0,false);
00343     connect(a_savePlaylist,SIGNAL(activated()),m_playList,SLOT(slotSaveAsM3u()));
00344 
00345     playlistOnly = new QActionGroup(this,"playlistgroup",false);
00346     playlistOnly->insert(a_appendFiles);
00347     playlistOnly->insert(a_addDir);
00348     playlistOnly->insert(a_loadPlaylist);
00349     playlistOnly->insert(a_savePlaylist);
00350 
00351     a_showPlaylist = new QAction(tr("Show playlist"),Opie::Core::OResource::loadPixmap( "txt",
00352                                  Opie::Core::OResource::SmallIcon ), 0, 0, this, 0, false );
00353     connect(a_showPlaylist,SIGNAL(activated()),this,SLOT(slotShowList()));
00354     a_ShowMedia = new QAction(tr("Show media window"),Opie::Core::OResource::loadPixmap("opieplayer2/musicfile",
00355                               Opie::Core::OResource::SmallIcon), 0, 0, this, 0, false );
00356     connect(a_ShowMedia,SIGNAL(activated()),this,SLOT(slotShowMediaWindow()));
00357 
00358     a_removeFiles = new QAction(tr("Remove file"),Opie::Core::OResource::loadPixmap( "opieplayer2/remove_from_playlist",
00359                                 Opie::Core::OResource::SmallIcon), 0, 0, this, 0, false );
00360     connect(a_removeFiles,SIGNAL(activated()),this,SLOT(slotRemoveFiles()));
00361 
00362     playersGroup = new QActionGroup(this,"playgroup",false);
00363 
00364     a_playAction = new QAction(tr("Play list"),Opie::Core::OResource::loadPixmap( "opieplayer2/play",
00365                                Opie::Core::OResource::SmallIcon ), 0, 0, this, 0, true);
00366     a_playAction->setOn(false);
00367     connect(a_playAction,SIGNAL(toggled(bool)),this,SLOT(slotTogglePlay(bool)));
00368 
00369     a_playNext = new QAction(tr("Play next in list"),Opie::Core::OResource::loadPixmap( "fastforward",
00370                              Opie::Core::OResource::SmallIcon ), 0, 0, this, 0, false );
00371     connect(a_playNext,SIGNAL(activated()),this,SLOT(slotPlayNext()));
00372     a_playPrevious = new QAction(tr("Play previous in list"),Opie::Core::OResource::loadPixmap( "fastback",
00373                                  Opie::Core::OResource::SmallIcon ), 0, 0, this, 0, false );
00374     connect(a_playPrevious,SIGNAL(activated()),this,SLOT(slotPlayPrevious()));
00375     a_ShowFull = new QAction(tr("Show videos fullscreen"),Opie::Core::OResource::loadPixmap( "fullscreen",
00376                              Opie::Core::OResource::SmallIcon ), 0, 0, this, 0, true );
00377     connect(a_ShowFull,SIGNAL(toggled(bool)),this,SLOT(slotToggleFull(bool)));
00378 
00379     playersGroup->insert(a_playPrevious);
00380     playersGroup->insert(a_playAction);
00381     playersGroup->insert(a_playNext);
00382 
00383 
00384     /* initial states of actions */
00385     a_showPlaylist->setEnabled(false);
00386     a_removeFiles->setEnabled(false);
00387     a_ShowMedia->setEnabled(false);
00388     playersGroup->setEnabled(false);
00389 
00390     settingsGroup = new QActionGroup(this,"configgroup",false);
00391 
00392     a_Scaleup = new QAction(tr("Scale videos larger"),Opie::Core::OResource::loadPixmap( "fullscreen",
00393                             Opie::Core::OResource::SmallIcon ), 0, 0, this, 0, true );
00394     connect(a_Scaleup,SIGNAL(toggled(bool)),this,SLOT(slot_scaleupToggled(bool)));
00395     settingsGroup->insert(a_Scaleup);
00396 }
00397 
00398 void PMainWindow::setupToolBar()
00399 {
00400     setToolBarsMovable( false );
00401     m_toolBar = new QToolBar( this );
00402     //m_menuBar = new QMenuBar(m_toolBar);
00403     m_menuBar=menuBar();
00404     addToolBar(m_toolBar);
00405     m_toolBar->setHorizontalStretchable( true );
00406     a_appendFiles->addTo(m_toolBar);
00407     a_removeFiles->addTo(m_toolBar);
00408     a_showPlaylist->addTo(m_toolBar);
00409     a_ShowMedia->addTo(m_toolBar);
00410     a_ShowFull->addTo(m_toolBar);
00411     playersGroup->addTo(m_toolBar);
00412 }
00413 
00414 void PMainWindow::setupVideo(bool full)
00415 {
00416     if (full) {
00417         m_VideoPlayer->setBackgroundColor(black);
00418         m_VideoPlayer->reparent(0, WStyle_Customize | WStyle_NoBorderEx, QPoint(0,0));
00419         m_VideoPlayer->setGeometry(0,0,qApp->desktop()->size().width(),qApp->desktop()->size().height());
00420         m_VideoPlayer->showFullScreen();
00421         connect(m_VideoPlayer,SIGNAL(videoclicked()),this,SLOT(slotVideoclicked()));
00422     } else {
00423         m_VideoPlayer->hide();
00424         m_VideoPlayer->disconnect(this);
00425         m_stack->addWidget(m_VideoPlayer,stack_video);
00426         m_stack->raiseWidget(stack_video);
00427     }
00428     mediaWindowraised();
00429     m_VideoPlayer->fullScreen(full);
00430 }
00431 
00432 void PMainWindow::slotVideoclicked()
00433 {
00434     odebug << "PMainWindow::slotVideoclicked()" << oendl;
00435     if (a_ShowFull->isOn()) {
00436         a_ShowFull->setOn(false);
00437         slotToggleFull(false);
00438     }
00439 }
00440 
00441 void PMainWindow::slotToggleFull(bool how)
00442 {
00443     if (m_PlayLib && m_VideoPlayer->isVisible() && m_PlayLib->isShowingVideo()) {
00444         m_PlayLib->pause(true);
00445         setupVideo(how);
00446         m_PlayLib->pause(false);
00447     }
00448 }
00449 
00450 void PMainWindow::setupMenu()
00451 {
00452     fileMenu = new QPopupMenu( m_menuBar );
00453     m_menuBar->insertItem( tr( "Playlist" ), fileMenu );
00454     a_appendFiles->addTo(fileMenu);
00455     a_removeFiles->addTo(fileMenu);
00456     a_addDir->addTo(fileMenu);
00457     fileMenu->insertSeparator();
00458     a_loadPlaylist->addTo(fileMenu);
00459     a_savePlaylist->addTo(fileMenu);
00460 
00461     dispMenu = new QPopupMenu( m_menuBar );
00462     m_menuBar->insertItem( tr( "Show" ), dispMenu );
00463     a_showPlaylist->addTo(dispMenu);
00464     a_ShowMedia->addTo(dispMenu);
00465     a_ShowFull->addTo(dispMenu);
00466     playMenu = new QPopupMenu(m_menuBar);
00467     m_menuBar->insertItem(tr("Playing"),playMenu);
00468     playersGroup->addTo(playMenu);
00469     configMenu = new QPopupMenu(m_menuBar);
00470     m_menuBar->insertItem(tr("Config"),configMenu);
00471     settingsGroup->addTo(configMenu);
00472 }
00473 
00474 void PMainWindow::slotNewPos(int pos)
00475 {
00476     if (!m_PlayLib) return;
00477     if (m_uppos==pos) return;
00478     m_PlayLib->seekTo(pos);
00479 }
00480 
00481 void PMainWindow::sliderPressed()
00482 {
00483     m_pressed = true;
00484 }
00485 
00486 void PMainWindow::sliderReleased()
00487 {
00488     m_pressed = false;
00489 }
00490 
00491 void PMainWindow::slot_scaleupToggled(bool how)
00492 {
00493     m_VideoPlayer->scaleUp(how);
00494 }

Generated on Sat Nov 5 16:17:33 2005 for OPIE by  doxygen 1.4.2