summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer3/mwindow.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opieplayer3/mwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer3/mwindow.cpp320
1 files changed, 320 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer3/mwindow.cpp b/noncore/multimedia/opieplayer3/mwindow.cpp
new file mode 100644
index 0000000..dab910a
--- a/dev/null
+++ b/noncore/multimedia/opieplayer3/mwindow.cpp
@@ -0,0 +1,320 @@
1/*
2 This file is part of the Opie Project
3
4 Copyright (c) 2002 Max Reiss <harlekin@handhelds.org>
5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
7 =.
8 .=l.
9 .>+-=
10 _;:, .> :=|. This program is free software; you can
11.> <`_, > . <= redistribute it and/or modify it under
12:`=1 )Y*s>-.-- : the terms of the GNU General Public
13.="- .-=="i, .._ License as published by the Free Software
14 - . .-<_> .<> Foundation; either version 2 of the License,
15 ._= =} : or (at your option) any later version.
16 .%`+i> _;_.
17 .i_,=:_. -<s. This program is distributed in the hope that
18 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
19 : .. .:, . . . without even the implied warranty of
20 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
21 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.= = ; Library General Public License for more
23++= -. .` .: details.
24 : = ...= . :.=-
25 -. .:....=;==+<; You should have received a copy of the GNU
26 -_. . . )=. = Library General Public License along with
27 -- :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA.
31
32*/
33
34#include "mwindow.h"
35#include "playlist.h"
36#include "audiowidget.h"
37#include "videowidget.h"
38#include "../opieplayer2/lib.h"
39
40#include <opie2/oapplicationfactory.h>
41#include <opie2/owidgetstack.h>
42#include <opie2/ofileselector.h>
43#include <opie2/odebug.h>
44
45#include <qpe/resource.h>
46
47#include <qfileinfo.h>
48#include <qfile.h>
49#include <qtoolbar.h>
50#include <qpopupmenu.h>
51#include <qmenubar.h>
52#include <qtimer.h>
53
54OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<PMainWindow>)
55
56using namespace Opie::Ui;
57
58PMainWindow::PMainWindow(QWidget*w, const char*name, WFlags f)
59 : QMainWindow(w,name,f)
60{
61 setCaption( QObject::tr("Opie Mediaplayer 3" ) );
62 setupActions();
63 setupToolBar();
64 setupMenu();
65
66 m_stack = new OWidgetStack(this);
67 m_stack->forceMode(Opie::Ui::OWidgetStack::SmallScreen);
68 setCentralWidget(m_stack );
69 m_playList = new PlaylistView(m_stack,"playlist");
70 m_stack->addWidget(m_playList,stack_list);
71
72 m_sfl = new OFileSelector("video/*;audio/*",m_stack);
73 m_stack->addWidget(m_sfl,stack_file);
74 connect(m_sfl, SIGNAL(fileSelected(const DocLnk &)), m_playList, SLOT(slotAddFile(const DocLnk &)));
75 m_AudioPlayer = new AudioWidget(m_stack);
76 m_stack->addWidget(m_AudioPlayer,stack_audio);
77 connect(this,SIGNAL(sigPos(int)),m_AudioPlayer,SLOT(updatePos(int)));
78 m_VideoPlayer = new VideoWidget(m_stack);
79 m_stack->addWidget(m_VideoPlayer,stack_video);
80 connect(this,SIGNAL(sigPos(int)),m_VideoPlayer,SLOT(updatePos(int)));
81 connect(m_VideoPlayer,SIGNAL(videoclicked()),this,SLOT(slotVideoclicked()));
82
83 m_stack->raiseWidget(stack_list);
84 m_PlayLib = 0;
85 m_LastItem = 0;
86}
87
88void PMainWindow::checkLib()
89{
90 if (m_PlayLib == 0) {
91 m_PlayLib = new XINE::Lib(XINE::Lib::InitializeImmediately);
92 m_PlayLib->ensureInitialized();
93 connect(m_PlayLib,SIGNAL(stopped()),this,SLOT(slotStopped()));
94 }
95}
96
97PMainWindow::~PMainWindow()
98{
99 if (m_PlayLib) {
100 m_PlayLib->stop();
101 delete m_PlayLib;
102 }
103}
104
105void PMainWindow::fileSelected(const DocLnk&)
106{
107}
108
109void PMainWindow::slotAppendFiles()
110{
111 m_stack->raiseWidget(m_sfl);
112}
113
114void PMainWindow::slotShowList()
115{
116 m_stack->raiseWidget(m_playList);
117}
118
119void PMainWindow::slotPlayList()
120{
121 if (m_playing && m_LastItem && m_PlayLib) {
122 if (!m_LastItem->isVideo()) {
123 m_stack->raiseWidget(stack_audio);
124 } else {
125 m_stack->raiseWidget(stack_video);
126 }
127 return;
128 }
129
130 m_LastItem = m_playList->currentItem();
131 if (!m_LastItem) {
132 slotPlayNext();
133 return;
134 }
135 //m_VideoPlayer->setFullScreen(a_ShowFull->isOn());
136 slotPlayCurrent();
137}
138
139void PMainWindow::hideVideo()
140{
141 if (m_VideoPlayer->isVisible() && a_ShowFull->isOn()) {
142 m_VideoPlayer->showNormal();
143 m_VideoPlayer->hide();
144 }
145}
146
147void PMainWindow::slotPlayCurrent()
148{
149 if (!m_LastItem) {
150 if (m_PlayLib) m_PlayLib->stop();
151 hideVideo();
152 m_stack->raiseWidget(stack_list);
153 return;
154 }
155 checkLib();
156 m_CurrentPos = 0;
157 m_playList->setCurrentItem(m_LastItem);
158 odebug << "Pos: " << m_PlayLib->currentTime() << oendl;
159 if (!m_LastItem->isVideo()) {
160 hideVideo();
161 m_playing = true;
162 QTimer::singleShot( 500, this, SLOT( slotCheckPos() ) );
163 m_stack->raiseWidget(stack_audio);
164 m_AudioPlayer->playFile(m_LastItem->Lnk(),m_PlayLib);
165 } else {
166 m_playing = true;
167 QTimer::singleShot( 500, this, SLOT( slotCheckPos() ) );
168 setupVideo(a_ShowFull->isOn());
169 m_VideoPlayer->playFile(m_LastItem->Lnk(),m_PlayLib);
170 }
171}
172
173void PMainWindow::slotPlayNext()
174{
175 PlaylistItem*item = m_playList->nextItem(m_LastItem);
176 if (!item) return;
177 m_LastItem = item;
178 slotPlayCurrent();
179}
180
181void PMainWindow::slotGoNext()
182{
183 m_LastItem = m_playList->nextItem(m_LastItem);
184 slotPlayCurrent();
185}
186
187void PMainWindow::slotPlayPrevious()
188{
189 PlaylistItem*item = m_playList->prevItem(m_LastItem);
190 if (!item) return;
191 m_LastItem = item;
192 slotPlayCurrent();
193}
194
195void PMainWindow::slotUserStop()
196{
197 if (!m_playing || !m_PlayLib) return;
198 m_playing = false;
199 m_PlayLib->stop();
200 hideVideo();
201 m_stack->raiseWidget(stack_list);
202}
203
204void PMainWindow::slotStopped()
205{
206 if (!m_playing) return;
207 m_playing = false;
208 slotGoNext();
209}
210
211void PMainWindow::slotCheckPos()
212{
213 if (!m_playing) return;
214 emit sigPos(m_PlayLib->currentTime());
215 QTimer::singleShot( 1000, this, SLOT( slotCheckPos() ) );
216}
217
218void PMainWindow::slotRemoveFiles()
219{
220 slotUserStop();
221 PlaylistItem* Item = m_playList->currentItem();
222 m_stack->raiseWidget(stack_list);
223 m_playList->removeFromList(Item);
224}
225
226void PMainWindow::setupActions()
227{
228 a_appendFiles = new QAction(tr("Open file(s)"),Resource::loadIconSet( "opieplayer2/add_to_playlist" ), 0, 0, this, 0, false );
229 connect(a_appendFiles,SIGNAL(activated()),this,SLOT(slotAppendFiles()));
230 a_showPlaylist = new QAction(tr("Show playlist"),Resource::loadIconSet( "txt" ), 0, 0, this, 0, false );
231 connect(a_showPlaylist,SIGNAL(activated()),this,SLOT(slotShowList()));
232 a_removeFiles = new QAction(tr("Remove file"),Resource::loadIconSet( "opieplayer2/remove_from_playlist" ), 0, 0, this, 0, false );
233 connect(a_removeFiles,SIGNAL(activated()),this,SLOT(slotRemoveFiles()));
234
235 playersGroup = new QActionGroup(this,"playgroup",false);
236
237 a_playAction = new QAction(tr("Play list"),Resource::loadIconSet( "opieplayer2/play" ), 0, 0, this, 0, false );
238 connect(a_playAction,SIGNAL(activated()),this,SLOT(slotPlayList()));
239 a_playNext = new QAction(tr("Play next in list"),Resource::loadIconSet( "fastforward" ), 0, 0, this, 0, false );
240 connect(a_playNext,SIGNAL(activated()),this,SLOT(slotPlayNext()));
241 a_playPrevious = new QAction(tr("Play previous in list"),Resource::loadIconSet( "fastback" ), 0, 0, this, 0, false );
242 connect(a_playPrevious,SIGNAL(activated()),this,SLOT(slotPlayPrevious()));
243 a_ShowFull = new QAction(tr("Show videos fullscreen"),Resource::loadIconSet( "fullscreen" ), 0, 0, this, 0, true );
244 connect(a_ShowFull,SIGNAL(toggled(bool)),this,SLOT(slotToggleFull(bool)));
245 a_stopPlay = new QAction(tr("Show videos fullscreen"),Resource::loadIconSet( "stop" ), 0, 0, this, 0, false );
246 connect(a_stopPlay,SIGNAL(activated()),this,SLOT(slotUserStop()));
247
248 playersGroup->insert(a_playPrevious);
249 playersGroup->insert(a_playAction);
250 playersGroup->insert(a_stopPlay);
251 playersGroup->insert(a_playNext);
252 //playersGroup->insert(a_ShowFull);
253}
254
255void PMainWindow::setupToolBar()
256{
257 setToolBarsMovable( false );
258 m_toolBar = new QToolBar( this );
259 //m_menuBar = new QMenuBar(m_toolBar);
260 m_menuBar=menuBar();
261 addToolBar(m_toolBar);
262 m_toolBar->setHorizontalStretchable( true );
263 a_appendFiles->addTo(m_toolBar);
264 a_removeFiles->addTo(m_toolBar);
265 a_showPlaylist->addTo(m_toolBar);
266 a_ShowFull->addTo(m_toolBar);
267 playersGroup->addTo(m_toolBar);
268}
269
270void PMainWindow::setupVideo(bool full)
271{
272 if (full) {
273 m_VideoPlayer->setBackgroundColor(black);
274 m_VideoPlayer->reparent(0, WStyle_Customize | WStyle_NoBorderEx, QPoint(0,0));
275 m_VideoPlayer->setGeometry(0,0,qApp->desktop()->size().width(),qApp->desktop()->size().height());
276 m_VideoPlayer->showFullScreen();
277 } else {
278 m_VideoPlayer->hide();
279 m_stack->addWidget(m_VideoPlayer,stack_video);
280 m_stack->raiseWidget(stack_video);
281 }
282 m_VideoPlayer->fullScreen(full);
283 m_VideoPlayer->disconnect(this);
284 connect(m_VideoPlayer,SIGNAL(videoclicked()),this,SLOT(slotVideoclicked()));
285}
286
287void PMainWindow::slotVideoclicked()
288{
289 odebug << "PMainWindow::slotVideoclicked()" << oendl;
290 if (a_ShowFull->isOn()) {
291 a_ShowFull->setOn(false);
292 slotToggleFull(false);
293 }
294}
295
296void PMainWindow::slotToggleFull(bool how)
297{
298 if (m_PlayLib && m_VideoPlayer->isVisible() && m_PlayLib->isShowingVideo()) {
299 m_PlayLib->pause(true);
300 setupVideo(how);
301 m_PlayLib->pause(false);
302 }
303}
304
305void PMainWindow::setupMenu()
306{
307 fileMenu = new QPopupMenu( m_menuBar );
308 m_menuBar->insertItem( tr( "Playlist" ), fileMenu );
309 a_appendFiles->addTo(fileMenu);
310 a_removeFiles->addTo(fileMenu);
311
312 dispMenu = new QPopupMenu( m_menuBar );
313 m_menuBar->insertItem( tr( "Show" ), dispMenu );
314 a_showPlaylist->addTo(dispMenu);
315 a_ShowFull->addTo(dispMenu);
316 playMenu = new QPopupMenu(m_menuBar);
317 m_menuBar->insertItem(tr("Playing"),playMenu);
318
319 playersGroup->addTo(playMenu);
320}