summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/playlistwidget.cpp
authorharlekin <harlekin>2003-06-18 20:19:16 (UTC)
committer harlekin <harlekin>2003-06-18 20:19:16 (UTC)
commit9bfda722eeba2f5861393e9f5f41170fab502da8 (patch) (unidiff)
treeeb01205e55bfe4f59d48d4c45b60013f1bd434ee /noncore/multimedia/opieplayer2/playlistwidget.cpp
parentdb7c5730e22188f365eb9d52aed961066fbda026 (diff)
downloadopie-9bfda722eeba2f5861393e9f5f41170fab502da8.zip
opie-9bfda722eeba2f5861393e9f5f41170fab502da8.tar.gz
opie-9bfda722eeba2f5861393e9f5f41170fab502da8.tar.bz2
separate Add URL from Add file
Diffstat (limited to 'noncore/multimedia/opieplayer2/playlistwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp80
1 files changed, 67 insertions, 13 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp
index c91a565..4e31670 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.cpp
+++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp
@@ -1,185 +1,190 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> 4              Copyright (c) 2002,2003 Max Reiss <harlekin@handhelds.org>
5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com> 5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU General Public 12:`=1 )Y*s>-.--   : the terms of the GNU General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; General Public License for more 22..}^=.=       =       ; General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = General Public License along with 26  -_. . .   )=.  = General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#include <qpe/qpetoolbar.h> 34#include <qpe/qpetoolbar.h>
35#include <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
36#include <qpe/storage.h> 36#include <qpe/storage.h>
37#include <qpe/mimetype.h> 37#include <qpe/mimetype.h>
38#include <qpe/global.h> 38#include <qpe/global.h>
39#include <qpe/resource.h> 39#include <qpe/resource.h>
40#include <qpe/config.h>
41
42#include <opie/ofiledialog.h>
40 43
41#include <qdatetime.h> 44#include <qdatetime.h>
42#include <qdir.h> 45#include <qdir.h>
43#include <qmessagebox.h> 46#include <qmessagebox.h>
44#include <qregexp.h> 47#include <qregexp.h>
45#include <qtextstream.h> 48#include <qtextstream.h>
46 49
47#include "playlistselection.h" 50#include "playlistselection.h"
48#include "playlistwidget.h" 51#include "playlistwidget.h"
49#include "mediaplayerstate.h" 52#include "mediaplayerstate.h"
50#include "inputDialog.h" 53#include "inputDialog.h"
51#include "om3u.h" 54#include "om3u.h"
52#include "playlistfileview.h" 55#include "playlistfileview.h"
53 56
54//only needed for the random play 57//only needed for the random play
55#include <stdlib.h> 58#include <stdlib.h>
56#include <assert.h> 59#include <assert.h>
57 60
58PlayListWidget::PlayListWidget( MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name ) 61PlayListWidget::PlayListWidget( MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name )
59 : PlayListWidgetGui( mediaPlayerState, parent, name ) , currentFileListView( 0 ) 62 : PlayListWidgetGui( mediaPlayerState, parent, name ) , currentFileListView( 0 )
60{ 63{
61 64
62 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), 65 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ),
63 "opieplayer2/add_to_playlist", 66 "opieplayer2/add_to_playlist",
64 this , SLOT(addSelected() ) ); 67 this , SLOT(addSelected() ) );
65 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), 68 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ),
66 "opieplayer2/remove_from_playlist", 69 "opieplayer2/remove_from_playlist",
67 this , SLOT(removeSelected() ) ); 70 this , SLOT(removeSelected() ) );
68 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play", 71 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play",
69 this , SLOT( btnPlay( bool) ), TRUE ); 72 this , SLOT( btnPlay( bool) ), TRUE );
70 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle", 73 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle",
71 &mediaPlayerState, SLOT( setShuffled( bool ) ), TRUE ); 74 &mediaPlayerState, SLOT( setShuffled( bool ) ), TRUE );
72 d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop", 75 d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop",
73 &mediaPlayerState, SLOT( setLooping( bool ) ), TRUE ); 76 &mediaPlayerState, SLOT( setLooping( bool ) ), TRUE );
74 77
75 (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); 78 (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) );
76 (void)new MenuItem( pmPlayList, tr( "Add all audio files" ), 79 (void)new MenuItem( pmPlayList, tr( "Add all audio files" ),
77 this, SLOT( addAllMusicToList() ) ); 80 this, SLOT( addAllMusicToList() ) );
78 (void)new MenuItem( pmPlayList, tr( "Add all video files" ), 81 (void)new MenuItem( pmPlayList, tr( "Add all video files" ),
79 this, SLOT( addAllVideoToList() ) ); 82 this, SLOT( addAllVideoToList() ) );
80 (void)new MenuItem( pmPlayList, tr( "Add all files" ), 83 (void)new MenuItem( pmPlayList, tr( "Add all files" ),
81 this, SLOT( addAllToList() ) ); 84 this, SLOT( addAllToList() ) );
82 pmPlayList->insertSeparator(-1); 85 pmPlayList->insertSeparator(-1);
83// (void)new MenuItem( pmPlayList, tr( "Save PlayList" ), 86// (void)new MenuItem( pmPlayList, tr( "Save PlayList" ),
84// this, SLOT( saveList() ) ); 87// this, SLOT( saveList() ) );
85 (void)new MenuItem( pmPlayList, tr( "Save Playlist" ), 88 (void)new MenuItem( pmPlayList, tr( "Save Playlist" ),
86 this, SLOT(writem3u() ) ); 89 this, SLOT(writem3u() ) );
87 pmPlayList->insertSeparator(-1); 90 pmPlayList->insertSeparator(-1);
88 (void)new MenuItem( pmPlayList, tr( "Open File or URL" ), 91 (void)new MenuItem( pmPlayList, tr( "Add File" ),
89 this,SLOT( openFile() ) ); 92 this,SLOT( openFile() ) );
93 (void)new MenuItem( pmPlayList, tr("Add URL"),
94 this,SLOT( openURL() ) );
90 pmPlayList->insertSeparator(-1); 95 pmPlayList->insertSeparator(-1);
91 (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), 96 (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ),
92 audioView, SLOT( scanFiles() ) ); 97 audioView, SLOT( scanFiles() ) );
93 (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), 98 (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ),
94 videoView, SLOT( scanFiles() ) ); 99 videoView, SLOT( scanFiles() ) );
95 100
96 pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"), 101 pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"),
97 &mediaPlayerState, SLOT( toggleFullscreen() ) ); 102 &mediaPlayerState, SLOT( toggleFullscreen() ) );
98 103
99 Config cfg( "OpiePlayer" ); 104 Config cfg( "OpiePlayer" );
100 bool b= cfg.readBoolEntry("FullScreen", 0); 105 bool b= cfg.readBoolEntry("FullScreen", 0);
101 mediaPlayerState.setFullscreen( b ); 106 mediaPlayerState.setFullscreen( b );
102 pmView->setItemChecked( -16, b ); 107 pmView->setItemChecked( -16, b );
103 108
104 (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up", 109 (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up",
105 d->selectedFiles, SLOT(moveSelectedUp() ) ); 110 d->selectedFiles, SLOT(moveSelectedUp() ) );
106 (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut", 111 (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut",
107 d->selectedFiles, SLOT(removeSelected() ) ); 112 d->selectedFiles, SLOT(removeSelected() ) );
108 (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down", 113 (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down",
109 d->selectedFiles, SLOT(moveSelectedDown() ) ); 114 d->selectedFiles, SLOT(moveSelectedDown() ) );
110 // QVBox *stretch2 = new QVBox( vbox1 ); 115 // QVBox *stretch2 = new QVBox( vbox1 );
111 116
112 connect( tbDeletePlaylist, ( SIGNAL( released() ) ), 117 connect( tbDeletePlaylist, ( SIGNAL( released() ) ),
113 SLOT( deletePlaylist() ) ); 118 SLOT( deletePlaylist() ) );
114 connect( pmView, SIGNAL( activated( int ) ), 119 connect( pmView, SIGNAL( activated( int ) ),
115 this, SLOT( pmViewActivated( int ) ) ); 120 this, SLOT( pmViewActivated( int ) ) );
116 connect( skinsMenu, SIGNAL( activated( int ) ) , 121 connect( skinsMenu, SIGNAL( activated( int ) ) ,
117 this, SLOT( skinsMenuActivated( int ) ) ); 122 this, SLOT( skinsMenuActivated( int ) ) );
118 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), 123 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ),
119 this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) ); 124 this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) );
120 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ), 125 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ),
121 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) ); 126 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) );
122 connect( audioView, SIGNAL( returnPressed( QListViewItem *) ), 127 connect( audioView, SIGNAL( returnPressed( QListViewItem *) ),
123 this,SLOT( playIt( QListViewItem *) ) ); 128 this,SLOT( playIt( QListViewItem *) ) );
124 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), 129 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ),
125 this, SLOT( addToSelection( QListViewItem *) ) ); 130 this, SLOT( addToSelection( QListViewItem *) ) );
126 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), 131 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ),
127 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) ); 132 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) );
128 connect( videoView, SIGNAL( returnPressed( QListViewItem *) ), 133 connect( videoView, SIGNAL( returnPressed( QListViewItem *) ),
129 this,SLOT( playIt( QListViewItem *) ) ); 134 this,SLOT( playIt( QListViewItem *) ) );
130 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), 135 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ),
131 this, SLOT( addToSelection( QListViewItem *) ) ); 136 this, SLOT( addToSelection( QListViewItem *) ) );
132 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), 137 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ),
133 this, SLOT( loadList( const DocLnk & ) ) ); 138 this, SLOT( loadList( const DocLnk & ) ) );
134 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ), 139 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ),
135 this, SLOT( tabChanged( QWidget* ) ) ); 140 this, SLOT( tabChanged( QWidget* ) ) );
136 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), 141 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ),
137 d->tbPlay, SLOT( setOn( bool ) ) ); 142 d->tbPlay, SLOT( setOn( bool ) ) );
138 connect( &mediaPlayerState, SIGNAL( loopingToggled( bool ) ), 143 connect( &mediaPlayerState, SIGNAL( loopingToggled( bool ) ),
139 d->tbLoop, SLOT( setOn( bool ) ) ); 144 d->tbLoop, SLOT( setOn( bool ) ) );
140 connect( &mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), 145 connect( &mediaPlayerState, SIGNAL( shuffledToggled( bool ) ),
141 d->tbShuffle, SLOT( setOn( bool ) ) ); 146 d->tbShuffle, SLOT( setOn( bool ) ) );
142 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), 147 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ),
143 this, SLOT( playIt( QListViewItem *) ) ); 148 this, SLOT( playIt( QListViewItem *) ) );
144 connect ( gammaSlider, SIGNAL( valueChanged( int ) ), 149 connect ( gammaSlider, SIGNAL( valueChanged( int ) ),
145 &mediaPlayerState, SLOT( setVideoGamma( int ) ) ); 150 &mediaPlayerState, SLOT( setVideoGamma( int ) ) );
146 151
147 // see which skins are installed 152 // see which skins are installed
148 populateSkinsMenu(); 153 populateSkinsMenu();
149 initializeStates(); 154 initializeStates();
150 155
151 channel = new QCopChannel( "QPE/Application/opieplayer2", this ); 156 channel = new QCopChannel( "QPE/Application/opieplayer2", this );
152 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 157 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
153 this, SLOT( qcopReceive(const QCString&, const QByteArray&)) ); 158 this, SLOT( qcopReceive(const QCString&, const QByteArray&)) );
154 159
155 160
156 cfg.setGroup("PlayList"); 161 cfg.setGroup("PlayList");
157 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); 162 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default");
158 loadList(DocLnk( currentPlaylist ) ); 163 loadList(DocLnk( currentPlaylist ) );
159 164
160 tabWidget->showPage( playListTab ); 165 tabWidget->showPage( playListTab );
161} 166}
162 167
163 168
164PlayListWidget::~PlayListWidget() { 169PlayListWidget::~PlayListWidget() {
165 delete d; 170 delete d;
166} 171}
167 172
168 173
169void PlayListWidget::initializeStates() { 174void PlayListWidget::initializeStates() {
170 d->tbPlay->setOn( mediaPlayerState.isPlaying() ); 175 d->tbPlay->setOn( mediaPlayerState.isPlaying() );
171 d->tbLoop->setOn( mediaPlayerState.isLooping() ); 176 d->tbLoop->setOn( mediaPlayerState.isLooping() );
172 d->tbShuffle->setOn( mediaPlayerState.isShuffled() ); 177 d->tbShuffle->setOn( mediaPlayerState.isShuffled() );
173 d->playListFrame->show(); 178 d->playListFrame->show();
174} 179}
175 180
176void PlayListWidget::writeDefaultPlaylist() { 181void PlayListWidget::writeDefaultPlaylist() {
177 182
178 Config config( "OpiePlayer" ); 183 Config config( "OpiePlayer" );
179 config.setGroup( "PlayList" ); 184 config.setGroup( "PlayList" );
180 QString filename=QPEApplication::documentDir() + "/default.m3u"; 185 QString filename=QPEApplication::documentDir() + "/default.m3u";
181 QString currentString = config.readEntry( "CurrentPlaylist", filename); 186 QString currentString = config.readEntry( "CurrentPlaylist", filename);
182 if( currentString == filename) { 187 if( currentString == filename) {
183 Om3u *m3uList; 188 Om3u *m3uList;
184 // qDebug("<<<<<<<<<<<<<default>>>>>>>>>>>>>>>>>>>"); 189 // qDebug("<<<<<<<<<<<<<default>>>>>>>>>>>>>>>>>>>");
185 if( d->selectedFiles->first() ) { 190 if( d->selectedFiles->first() ) {
@@ -234,203 +239,203 @@ void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , in
234} 239}
235 240
236 241
237void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) { 242void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) {
238 switch (mouse) { 243 switch (mouse) {
239 case LeftButton: 244 case LeftButton:
240 break; 245 break;
241 case RightButton: 246 case RightButton:
242 { 247 {
243 QPopupMenu m; 248 QPopupMenu m;
244 m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); 249 m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
245 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); 250 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
246 m.exec( QCursor::pos() ); 251 m.exec( QCursor::pos() );
247 } 252 }
248 break; 253 break;
249 } 254 }
250} 255}
251 256
252 257
253void PlayListWidget::addAllToList() { 258void PlayListWidget::addAllToList() {
254 259
255 260
256 audioView->populateView(); 261 audioView->populateView();
257 262
258 QListViewItemIterator audioIt( audioView ); 263 QListViewItemIterator audioIt( audioView );
259 DocLnk lnk; 264 DocLnk lnk;
260 QString filename; 265 QString filename;
261 // iterate through all items of the listview 266 // iterate through all items of the listview
262 for ( ; audioIt.current(); ++audioIt ) { 267 for ( ; audioIt.current(); ++audioIt ) {
263 filename = audioIt.current()->text(3); 268 filename = audioIt.current()->text(3);
264 lnk.setName( QFileInfo(filename).baseName() ); //sets name 269 lnk.setName( QFileInfo(filename).baseName() ); //sets name
265 lnk.setFile( filename ); //sets file name 270 lnk.setFile( filename ); //sets file name
266 d->selectedFiles->addToSelection( lnk); 271 d->selectedFiles->addToSelection( lnk);
267 } 272 }
268 273
269 videoView->populateView(); 274 videoView->populateView();
270 275
271 QListViewItemIterator videoIt( videoView ); 276 QListViewItemIterator videoIt( videoView );
272 for ( ; videoIt.current(); ++videoIt ) { 277 for ( ; videoIt.current(); ++videoIt ) {
273 filename = videoIt.current()->text(3); 278 filename = videoIt.current()->text(3);
274 lnk.setName( QFileInfo(filename).baseName() ); //sets name 279 lnk.setName( QFileInfo(filename).baseName() ); //sets name
275 lnk.setFile( filename ); //sets file name 280 lnk.setFile( filename ); //sets file name
276 d->selectedFiles->addToSelection( lnk); 281 d->selectedFiles->addToSelection( lnk);
277 } 282 }
278 283
279 tabWidget->setCurrentPage(0); 284 tabWidget->setCurrentPage(0);
280 285
281 writeCurrentM3u(); 286 writeCurrentM3u();
282 d->selectedFiles->first(); 287 d->selectedFiles->first();
283} 288}
284 289
285 290
286void PlayListWidget::addAllMusicToList() { 291void PlayListWidget::addAllMusicToList() {
287 292
288 audioView->populateView(); 293 audioView->populateView();
289 294
290 QListViewItemIterator audioIt( audioView ); 295 QListViewItemIterator audioIt( audioView );
291 DocLnk lnk; 296 DocLnk lnk;
292 QString filename; 297 QString filename;
293 // iterate through all items of the listview 298 // iterate through all items of the listview
294 for ( ; audioIt.current(); ++audioIt ) { 299 for ( ; audioIt.current(); ++audioIt ) {
295 filename = audioIt.current()->text(3); 300 filename = audioIt.current()->text(3);
296 lnk.setName( QFileInfo(filename).baseName() ); //sets name 301 lnk.setName( QFileInfo(filename).baseName() ); //sets name
297 lnk.setFile( filename ); //sets file name 302 lnk.setFile( filename ); //sets file name
298 d->selectedFiles->addToSelection( lnk); 303 d->selectedFiles->addToSelection( lnk);
299 } 304 }
300 305
301 tabWidget->setCurrentPage(0); 306 tabWidget->setCurrentPage(0);
302 writeCurrentM3u(); 307 writeCurrentM3u();
303 d->selectedFiles->first(); 308 d->selectedFiles->first();
304} 309}
305 310
306 311
307void PlayListWidget::addAllVideoToList() { 312void PlayListWidget::addAllVideoToList() {
308 313
309 videoView->populateView(); 314 videoView->populateView();
310 315
311 QListViewItemIterator videoIt( videoView ); 316 QListViewItemIterator videoIt( videoView );
312 DocLnk lnk; 317 DocLnk lnk;
313 QString filename; 318 QString filename;
314 for ( ; videoIt.current(); ++videoIt ) { 319 for ( ; videoIt.current(); ++videoIt ) {
315 filename = videoIt.current()->text(3); 320 filename = videoIt.current()->text(3);
316 lnk.setName( QFileInfo(filename).baseName() ); //sets name 321 lnk.setName( QFileInfo(filename).baseName() ); //sets name
317 lnk.setFile( filename ); //sets file name 322 lnk.setFile( filename ); //sets file name
318 d->selectedFiles->addToSelection( lnk); 323 d->selectedFiles->addToSelection( lnk);
319 } 324 }
320 tabWidget->setCurrentPage(0); 325 tabWidget->setCurrentPage(0);
321 writeCurrentM3u(); 326 writeCurrentM3u();
322 d->selectedFiles->first(); 327 d->selectedFiles->first();
323} 328}
324 329
325 330
326void PlayListWidget::setDocument( const QString& fileref ) { 331void PlayListWidget::setDocument( const QString& fileref ) {
327 // qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref ); 332 // qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref );
328 fromSetDocument = TRUE; 333 fromSetDocument = TRUE;
329 QFileInfo fileInfo(fileref); 334 QFileInfo fileInfo(fileref);
330 335
331 if ( !fileInfo.exists() ) { 336 if ( !fileInfo.exists() ) {
332 QMessageBox::warning( this, tr( "Invalid File" ), 337 QMessageBox::warning( this, tr( "Invalid File" ),
333 tr( "There was a problem in getting the file." ) ); 338 tr( "There was a problem in getting the file." ) );
334 return; 339 return;
335 } 340 }
336 341
337 clearList(); 342 clearList();
338 QString extension = fileInfo.extension(false); 343 QString extension = fileInfo.extension(false);
339 344
340 if( extension.find( "m3u", 0, false) != -1 345 if( extension.find( "m3u", 0, false) != -1
341 || extension.find( "pls", 0, false) != -1 ) { 346 || extension.find( "pls", 0, false) != -1 ) {
342 readListFromFile( fileref ); 347 readListFromFile( fileref );
343 } else { 348 } else {
344 clearList(); 349 clearList();
345 DocLnk lnk; 350 DocLnk lnk;
346 lnk.setName( fileInfo.baseName() ); //sets name 351 lnk.setName( fileInfo.baseName() ); //sets name
347 lnk.setFile( fileref ); //sets file name 352 lnk.setFile( fileref ); //sets file name
348 addToSelection( lnk ); 353 addToSelection( lnk );
349 writeCurrentM3u(); 354 writeCurrentM3u();
350 355
351 d->setDocumentUsed = TRUE; 356 d->setDocumentUsed = TRUE;
352 mediaPlayerState.setPlaying( FALSE ); 357 mediaPlayerState.setPlaying( FALSE );
353 mediaPlayerState.setPlaying( TRUE ); 358 mediaPlayerState.setPlaying( TRUE );
354 } 359 }
355} 360}
356 361
357 362
358void PlayListWidget::useSelectedDocument() { 363void PlayListWidget::useSelectedDocument() {
359 d->setDocumentUsed = FALSE; 364 d->setDocumentUsed = FALSE;
360} 365}
361 366
362 367
363const DocLnk *PlayListWidget::current() const { // this is fugly 368const DocLnk *PlayListWidget::current() const { // this is fugly
364 assert( currentTab() == CurrentPlayList ); 369 assert( currentTab() == CurrentPlayList );
365 370
366 const DocLnk *lnk = d->selectedFiles->current(); 371 const DocLnk *lnk = d->selectedFiles->current();
367 if ( !lnk ) { 372 if ( !lnk ) {
368 d->selectedFiles->first(); 373 d->selectedFiles->first();
369 lnk = d->selectedFiles->current(); 374 lnk = d->selectedFiles->current();
370 } 375 }
371 assert( lnk ); 376 assert( lnk );
372 return lnk; 377 return lnk;
373} 378}
374 379
375 380
376bool PlayListWidget::prev() { 381bool PlayListWidget::prev() {
377 if ( mediaPlayerState.isShuffled() ) { 382 if ( mediaPlayerState.isShuffled() ) {
378 const DocLnk *cur = current(); 383 const DocLnk *cur = current();
379 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 384 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
380 for ( int i = 0; i < j; i++ ) { 385 for ( int i = 0; i < j; i++ ) {
381 if ( !d->selectedFiles->next() ) 386 if ( !d->selectedFiles->next() )
382 d->selectedFiles->first(); 387 d->selectedFiles->first();
383 } 388 }
384 if ( cur == current() ) 389 if ( cur == current() )
385 if ( !d->selectedFiles->next() ) { 390 if ( !d->selectedFiles->next() ) {
386 d->selectedFiles->first(); 391 d->selectedFiles->first();
387 } 392 }
388 return TRUE; 393 return TRUE;
389 } else { 394 } else {
390 if ( !d->selectedFiles->prev() ) { 395 if ( !d->selectedFiles->prev() ) {
391 if ( mediaPlayerState.isLooping() ) { 396 if ( mediaPlayerState.isLooping() ) {
392 return d->selectedFiles->last(); 397 return d->selectedFiles->last();
393 } else { 398 } else {
394 return FALSE; 399 return FALSE;
395 } 400 }
396 } 401 }
397 return TRUE; 402 return TRUE;
398 } 403 }
399} 404}
400 405
401 406
402bool PlayListWidget::next() { 407bool PlayListWidget::next() {
403//qDebug("<<<<<<<<<<<<next()"); 408//qDebug("<<<<<<<<<<<<next()");
404 if ( mediaPlayerState.isShuffled() ) { 409 if ( mediaPlayerState.isShuffled() ) {
405 return prev(); 410 return prev();
406 } else { 411 } else {
407 if ( !d->selectedFiles->next() ) { 412 if ( !d->selectedFiles->next() ) {
408 if ( mediaPlayerState.isLooping() ) { 413 if ( mediaPlayerState.isLooping() ) {
409 return d->selectedFiles->first(); 414 return d->selectedFiles->first();
410 } else { 415 } else {
411 return FALSE; 416 return FALSE;
412 } 417 }
413 } 418 }
414 return TRUE; 419 return TRUE;
415 } 420 }
416} 421}
417 422
418 423
419bool PlayListWidget::first() { 424bool PlayListWidget::first() {
420 return d->selectedFiles->first(); 425 return d->selectedFiles->first();
421} 426}
422 427
423 428
424bool PlayListWidget::last() { 429bool PlayListWidget::last() {
425 return d->selectedFiles->last(); 430 return d->selectedFiles->last();
426} 431}
427 432
428 433
429 void PlayListWidget::saveList() { 434 void PlayListWidget::saveList() {
430 writem3u(); 435 writem3u();
431 } 436 }
432 437
433 438
434void PlayListWidget::loadList( const DocLnk & lnk) { 439void PlayListWidget::loadList( const DocLnk & lnk) {
435 QString name = lnk.name(); 440 QString name = lnk.name();
436 441
@@ -509,457 +514,506 @@ void PlayListWidget::tabChanged(QWidget *) {
509 514
510 currentFileListView = 0; 515 currentFileListView = 0;
511 516
512 switch ( currentTab() ) { 517 switch ( currentTab() ) {
513 case CurrentPlayList: 518 case CurrentPlayList:
514 { 519 {
515 if( !tbDeletePlaylist->isHidden() ) { 520 if( !tbDeletePlaylist->isHidden() ) {
516 tbDeletePlaylist->hide(); 521 tbDeletePlaylist->hide();
517 } 522 }
518 d->tbRemoveFromList->setEnabled(TRUE); 523 d->tbRemoveFromList->setEnabled(TRUE);
519 d->tbAddToList->setEnabled(FALSE); 524 d->tbAddToList->setEnabled(FALSE);
520 525
521 d->tbPlay->setEnabled( !d->selectedFiles->isEmpty() ); 526 d->tbPlay->setEnabled( !d->selectedFiles->isEmpty() );
522 } 527 }
523 break; 528 break;
524 case AudioFiles: 529 case AudioFiles:
525 { 530 {
526 audioView->populateView(); 531 audioView->populateView();
527 532
528 if( !tbDeletePlaylist->isHidden() ) { 533 if( !tbDeletePlaylist->isHidden() ) {
529 tbDeletePlaylist->hide(); 534 tbDeletePlaylist->hide();
530 } 535 }
531 d->tbRemoveFromList->setEnabled(FALSE); 536 d->tbRemoveFromList->setEnabled(FALSE);
532 d->tbAddToList->setEnabled(TRUE); 537 d->tbAddToList->setEnabled(TRUE);
533 538
534 connect( audioView, SIGNAL( itemsSelected( bool ) ), 539 connect( audioView, SIGNAL( itemsSelected( bool ) ),
535 d->tbPlay, SLOT( setEnabled( bool ) ) ); 540 d->tbPlay, SLOT( setEnabled( bool ) ) );
536 541
537 d->tbPlay->setEnabled( audioView->hasSelection() ); 542 d->tbPlay->setEnabled( audioView->hasSelection() );
538 543
539 currentFileListView = audioView; 544 currentFileListView = audioView;
540 } 545 }
541 break; 546 break;
542 case VideoFiles: 547 case VideoFiles:
543 { 548 {
544 videoView->populateView(); 549 videoView->populateView();
545 if( !tbDeletePlaylist->isHidden() ) { 550 if( !tbDeletePlaylist->isHidden() ) {
546 tbDeletePlaylist->hide(); 551 tbDeletePlaylist->hide();
547 } 552 }
548 d->tbRemoveFromList->setEnabled(FALSE); 553 d->tbRemoveFromList->setEnabled(FALSE);
549 d->tbAddToList->setEnabled(TRUE); 554 d->tbAddToList->setEnabled(TRUE);
550 555
551 connect( videoView, SIGNAL( itemsSelected( bool ) ), 556 connect( videoView, SIGNAL( itemsSelected( bool ) ),
552 d->tbPlay, SLOT( setEnabled( bool ) ) ); 557 d->tbPlay, SLOT( setEnabled( bool ) ) );
553 558
554 d->tbPlay->setEnabled( videoView->hasSelection() ); 559 d->tbPlay->setEnabled( videoView->hasSelection() );
555 560
556 currentFileListView = videoView; 561 currentFileListView = videoView;
557 } 562 }
558 break; 563 break;
559 case PlayLists: 564 case PlayLists:
560 { 565 {
561 if( tbDeletePlaylist->isHidden() ) { 566 if( tbDeletePlaylist->isHidden() ) {
562 tbDeletePlaylist->show(); 567 tbDeletePlaylist->show();
563 } 568 }
564 playLists->reread(); 569 playLists->reread();
565 d->tbAddToList->setEnabled(FALSE); 570 d->tbAddToList->setEnabled(FALSE);
566 571
567 d->tbPlay->setEnabled( false ); 572 d->tbPlay->setEnabled( false );
568 } 573 }
569 break; 574 break;
570 }; 575 };
571} 576}
572 577
573 578
574void PlayListWidget::btnPlay(bool b) { 579void PlayListWidget::btnPlay(bool b) {
575// mediaPlayerState->setPlaying(false); 580// mediaPlayerState->setPlaying(false);
576 mediaPlayerState.setPlaying(b); 581 mediaPlayerState.setPlaying(b);
577 insanityBool=FALSE; 582 insanityBool=FALSE;
578} 583}
579 584
580void PlayListWidget::deletePlaylist() { 585void PlayListWidget::deletePlaylist() {
581 switch( QMessageBox::information( this, (tr("Remove Playlist?")), 586 switch( QMessageBox::information( this, (tr("Remove Playlist?")),
582 (tr("You really want to delete\nthis playlist?")), 587 (tr("You really want to delete\nthis playlist?")),
583 (tr("Yes")), (tr("No")), 0 )){ 588 (tr("Yes")), (tr("No")), 0 )){
584 case 0: // Yes clicked, 589 case 0: // Yes clicked,
585 QFile().remove(playLists->selectedDocument().file()); 590 QFile().remove(playLists->selectedDocument().file());
586 QFile().remove(playLists->selectedDocument().linkFile()); 591 QFile().remove(playLists->selectedDocument().linkFile());
587 playLists->reread(); 592 playLists->reread();
588 break; 593 break;
589 case 1: // Cancel 594 case 1: // Cancel
590 break; 595 break;
591 }; 596 };
592} 597}
593 598
594 599
595void PlayListWidget::playSelected() { 600void PlayListWidget::playSelected() {
596 btnPlay( TRUE); 601 btnPlay( TRUE);
597} 602}
598 603
599bool PlayListWidget::inFileListMode() const 604bool PlayListWidget::inFileListMode() const
600{ 605{
601 TabType tab = currentTab(); 606 TabType tab = currentTab();
602 return tab == AudioFiles || tab == VideoFiles; 607 return tab == AudioFiles || tab == VideoFiles;
603} 608}
604 609
605void PlayListWidget::openFile() { 610void PlayListWidget::openURL() {
606 // http://66.28.164.33:2080 611 // http://66.28.164.33:2080
607 // http://somafm.com/star0242.m3u 612 // http://somafm.com/star0242.m3u
608 QString filename, name; 613 QString filename, name;
609 InputDialog *fileDlg; 614 InputDialog *fileDlg;
610 fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); 615 fileDlg = new InputDialog(this,tr("Add URL"),TRUE, 0);
611 fileDlg->exec(); 616 fileDlg->exec();
612 if( fileDlg->result() == 1 ) { 617 if( fileDlg->result() == 1 ) {
613 filename = fileDlg->text(); 618 filename = fileDlg->text();
614 qDebug( "Selected filename is " + filename ); 619 qDebug( "Selected filename is " + filename );
615 // Om3u *m3uList; 620 // Om3u *m3uList;
616 DocLnk lnk; 621 DocLnk lnk;
617 Config cfg( "OpiePlayer" ); 622 Config cfg( "OpiePlayer" );
618 cfg.setGroup("PlayList"); 623 cfg.setGroup("PlayList");
619 624
620 if(filename.left(4) == "http") { 625 if(filename.left(4) == "http") {
621 QString m3uFile, m3uFilePath; 626 QString m3uFile, m3uFilePath;
622 if(filename.find(":",8,TRUE) != -1) { //found a port 627 if(filename.find(":",8,TRUE) != -1) { //found a port
623 m3uFile = filename.left( filename.find( ":",8,TRUE)); 628 m3uFile = filename.left( filename.find( ":",8,TRUE));
624 m3uFile = m3uFile.right( 7); 629 m3uFile = m3uFile.right( 7);
625 } else if(filename.left(4) == "http"){ 630 } else if(filename.left(4) == "http"){
626 m3uFile=filename; 631 m3uFile=filename;
627 m3uFile = m3uFile.right( m3uFile.length() - 7); 632 m3uFile = m3uFile.right( m3uFile.length() - 7);
628 } else{ 633 } else{
629 m3uFile=filename; 634 m3uFile=filename;
630 } 635 }
631 636
632 lnk.setName( filename ); //sets name 637 lnk.setName( filename ); //sets name
633 lnk.setFile( filename ); //sets file name 638 lnk.setFile( filename ); //sets file name
634 639
635// lnk.setIcon("opieplayer2/musicfile"); 640// lnk.setIcon("opieplayer2/musicfile");
636 641
637 d->selectedFiles->addToSelection( lnk ); 642 d->selectedFiles->addToSelection( lnk );
638 writeCurrentM3u(); 643 writeCurrentM3u();
639 d->selectedFiles->setSelectedItem( lnk.name()); 644 d->selectedFiles->setSelectedItem( lnk.name());
640 } 645 }
641 else if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) { 646 else if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) {
642 readListFromFile( filename ); 647 readListFromFile( filename );
643 } else { 648 } else {
644 lnk.setName( QFileInfo(filename).baseName() ); //sets name 649 lnk.setName( QFileInfo(filename).baseName() ); //sets name
645 lnk.setFile( filename ); //sets file name 650 lnk.setFile( filename ); //sets file name
646 d->selectedFiles->addToSelection( lnk); 651 d->selectedFiles->addToSelection( lnk);
647 writeCurrentM3u(); 652 writeCurrentM3u();
648 d->selectedFiles->setSelectedItem( lnk.name()); 653 d->selectedFiles->setSelectedItem( lnk.name());
649 } 654 }
650 } 655 }
651 656
652 657
653 delete fileDlg; 658 delete fileDlg;
654} 659}
655 660
661
662void PlayListWidget::openFile() {
663
664 QString filename, name;
665
666 Config cfg( "OpiePlayer" );
667 cfg.setGroup("Dialog");
668 MimeTypes types;
669 QStringList audio, video, all;
670 audio << "audio/*";
671 audio << "playlist/plain";
672 audio << "audio/x-mpegurl";
673
674 video << "video/*";
675 video << "playlist/plain";
676
677 all += audio;
678 all += video;
679 types.insert("All Media Files", all );
680 types.insert("Audio", audio );
681 types.insert("Video", video );
682
683 QString str = OFileDialog::getOpenFileName( 1,
684 cfg.readEntry("LastDirectory",QPEApplication::documentDir()),"",
685 types, 0 );
686 if(str.left(2) == "//") str=str.right(str.length()-1);
687 cfg.writeEntry("LastDirectory" ,QFileInfo(str).dirPath());
688
689
690 if( !str.isEmpty() ) {
691 qDebug( "Selected filename is " + str );
692 filename = str;
693 DocLnk lnk;
694 Config cfg( "OpiePlayer" );
695 cfg.setGroup("PlayList");
696
697 if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) {
698 readListFromFile( filename );
699 } else {
700 lnk.setName( QFileInfo(filename).baseName() ); //sets name
701 lnk.setFile( filename ); //sets file name
702 d->selectedFiles->addToSelection( lnk);
703 writeCurrentM3u();
704 d->selectedFiles->setSelectedItem( lnk.name());
705 }
706 }
707}
708
709
656void PlayListWidget::readListFromFile( const QString &filename ) { 710void PlayListWidget::readListFromFile( const QString &filename ) {
657 qDebug( "read list filename " + filename ); 711 qDebug( "read list filename " + filename );
658 QFileInfo fi(filename); 712 QFileInfo fi(filename);
659 Om3u *m3uList; 713 Om3u *m3uList;
660 QString s, name; 714 QString s, name;
661 m3uList = new Om3u( filename, IO_ReadOnly ); 715 m3uList = new Om3u( filename, IO_ReadOnly );
662 if(fi.extension(false).find("m3u",0,false) != -1 ) 716 if(fi.extension(false).find("m3u",0,false) != -1 )
663 m3uList->readM3u(); 717 m3uList->readM3u();
664 else if(fi.extension(false).find("pls",0,false) != -1 ) 718 else if(fi.extension(false).find("pls",0,false) != -1 )
665 m3uList->readPls(); 719 m3uList->readPls();
666 720
667 DocLnk lnk; 721 DocLnk lnk;
668 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { 722 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
669 s = *it; 723 s = *it;
670 // qDebug(s); 724 // qDebug(s);
671 if(s.left(4)=="http") { 725 if(s.left(4)=="http") {
672 lnk.setName( s ); //sets file name 726 lnk.setName( s ); //sets file name
673 lnk.setIcon("opieplayer2/musicfile"); 727 lnk.setIcon("opieplayer2/musicfile");
674 lnk.setFile( s ); //sets file name 728 lnk.setFile( s ); //sets file name
675 729
676 } else { //is file 730 } else { //is file
677 lnk.setName( QFileInfo(s).baseName()); 731 lnk.setName( QFileInfo(s).baseName());
678 if(s.left(1) != "/") { 732 if(s.left(1) != "/") {
679 733
680 lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); 734 lnk.setFile( QFileInfo(filename).dirPath()+"/"+s);
681 } else { 735 } else {
682 lnk.setFile( s); 736 lnk.setFile( s);
683 } 737 }
684 } 738 }
685 d->selectedFiles->addToSelection( lnk ); 739 d->selectedFiles->addToSelection( lnk );
686 } 740 }
687 Config config( "OpiePlayer" ); 741 Config config( "OpiePlayer" );
688 config.setGroup( "PlayList" ); 742 config.setGroup( "PlayList" );
689 743
690 config.writeEntry("CurrentPlaylist",filename); 744 config.writeEntry("CurrentPlaylist",filename);
691 config.write(); 745 config.write();
692 currentPlayList=filename; 746 currentPlayList=filename;
693 747
694 m3uList->close(); 748 m3uList->close();
695 delete m3uList; 749 delete m3uList;
696 750
697 d->selectedFiles->setSelectedItem( s); 751 d->selectedFiles->setSelectedItem( s);
698 setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName()); 752 setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName());
699 753
700} 754}
701 755
702// writes current playlist to current m3u file */ 756// writes current playlist to current m3u file */
703 void PlayListWidget::writeCurrentM3u() { 757 void PlayListWidget::writeCurrentM3u() {
704 qDebug("writing to current m3u"); 758 qDebug("writing to current m3u");
705 Config cfg( "OpiePlayer" ); 759 Config cfg( "OpiePlayer" );
706 cfg.setGroup("PlayList"); 760 cfg.setGroup("PlayList");
707 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default"); 761 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default");
708 762
709 Om3u *m3uList; 763 Om3u *m3uList;
710 m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); 764 m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate );
711 if( d->selectedFiles->first()) { 765 if( d->selectedFiles->first()) {
712 766
713 do { 767 do {
714 // qDebug( "add writeCurrentM3u " +d->selectedFiles->current()->file()); 768 // qDebug( "add writeCurrentM3u " +d->selectedFiles->current()->file());
715 m3uList->add( d->selectedFiles->current()->file() ); 769 m3uList->add( d->selectedFiles->current()->file() );
716 } 770 }
717 while ( d->selectedFiles->next() ); 771 while ( d->selectedFiles->next() );
718 // qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" ); 772 // qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" );
719 m3uList->write(); 773 m3uList->write();
720 m3uList->close(); 774 m3uList->close();
721 } 775 }
722 delete m3uList; 776 delete m3uList;
723 777
724 } 778 }
725 779
726 /* 780 /*
727 writes current playlist to m3u file */ 781 writes current playlist to m3u file */
728void PlayListWidget::writem3u() { 782void PlayListWidget::writem3u() {
729 InputDialog *fileDlg; 783 InputDialog *fileDlg;
730 fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); 784 fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0);
731 fileDlg->exec(); 785 fileDlg->exec();
732 QString name, filename, list; 786 QString name, filename, list;
733 Om3u *m3uList; 787 Om3u *m3uList;
734 788
735 if( fileDlg->result() == 1 ) { 789 if( fileDlg->result() == 1 ) {
736 name = fileDlg->text(); 790 name = fileDlg->text();
737// qDebug( filename ); 791// qDebug( filename );
738 if( name.find("/",0,true) != -1) {// assume they specify a file path 792 if( name.find("/",0,true) != -1) {// assume they specify a file path
739 filename = name; 793 filename = name;
740 name = name.right(name.length()- name.findRev("/",-1,true) - 1 ); 794 name = name.right(name.length()- name.findRev("/",-1,true) - 1 );
741 } 795 }
742 else //otherwise dump it somewhere noticable 796 else //otherwise dump it somewhere noticable
743 filename = QPEApplication::documentDir() + "/" + name; 797 filename = QPEApplication::documentDir() + "/" + name;
744 798
745 if( filename.right( 3 ) != "m3u" ) //needs filename extension 799 if( filename.right( 3 ) != "m3u" ) //needs filename extension
746 filename += ".m3u"; 800 filename += ".m3u";
747 801
748 if( d->selectedFiles->first()) { //ramble through playlist view 802 if( d->selectedFiles->first()) { //ramble through playlist view
749 m3uList = new Om3u( filename, IO_ReadWrite | IO_Truncate); 803 m3uList = new Om3u( filename, IO_ReadWrite | IO_Truncate);
750 804
751 do { 805 do {
752 m3uList->add( d->selectedFiles->current()->file()); 806 m3uList->add( d->selectedFiles->current()->file());
753 } 807 }
754 while ( d->selectedFiles->next() ); 808 while ( d->selectedFiles->next() );
755 // qDebug( list ); 809 // qDebug( list );
756 m3uList->write(); 810 m3uList->write();
757 m3uList->close(); 811 m3uList->close();
758 delete m3uList; 812 delete m3uList;
759 813
760 delete fileDlg; 814 delete fileDlg;
761 815
762 DocLnk lnk; 816 DocLnk lnk;
763 lnk.setFile( filename); 817 lnk.setFile( filename);
764 lnk.setIcon("opieplayer2/playlist2"); 818 lnk.setIcon("opieplayer2/playlist2");
765 lnk.setName( name); //sets file name 819 lnk.setName( name); //sets file name
766 820
767 // qDebug(filename); 821 // qDebug(filename);
768 Config config( "OpiePlayer" ); 822 Config config( "OpiePlayer" );
769 config.setGroup( "PlayList" ); 823 config.setGroup( "PlayList" );
770 824
771 config.writeEntry("CurrentPlaylist",filename); 825 config.writeEntry("CurrentPlaylist",filename);
772 currentPlayList=filename; 826 currentPlayList=filename;
773 827
774 if(!lnk.writeLink()) { 828 if(!lnk.writeLink()) {
775 qDebug("Writing doclink did not work"); 829 qDebug("Writing doclink did not work");
776 } 830 }
777 831
778 setCaption(tr("OpiePlayer: ") + name); 832 setCaption(tr("OpiePlayer: ") + name);
779 } 833 }
780 } 834 }
781} 835}
782 836
783void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { 837void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) {
784 switch ( e->key() ) { 838 switch ( e->key() ) {
785 ////////////////////////////// Zaurus keys 839 ////////////////////////////// Zaurus keys
786 case Key_F9: //activity 840 case Key_F9: //activity
787 // if(audioUI->isHidden()) 841 // if(audioUI->isHidden())
788 // audioUI->showMaximized(); 842 // audioUI->showMaximized();
789 break; 843 break;
790 case Key_F10: //contacts 844 case Key_F10: //contacts
791 // if( videoUI->isHidden()) 845 // if( videoUI->isHidden())
792 // videoUI->showMaximized(); 846 // videoUI->showMaximized();
793 break; 847 break;
794 case Key_F11: //menu 848 case Key_F11: //menu
795 break; 849 break;
796 case Key_F12: //home 850 case Key_F12: //home
797 // doBlank(); 851 // doBlank();
798 break; 852 break;
799 case Key_F13: //mail 853 case Key_F13: //mail
800 // doUnblank(); 854 // doUnblank();
801 break; 855 break;
802 case Key_Q: //add to playlist 856 case Key_Q: //add to playlist
803 addSelected(); 857 addSelected();
804 break; 858 break;
805 case Key_R: //remove from playlist 859 case Key_R: //remove from playlist
806 removeSelected(); 860 removeSelected();
807 break; 861 break;
808 // case Key_P: //play 862 // case Key_P: //play
809 // qDebug("Play"); 863 // qDebug("Play");
810 // playSelected(); 864 // playSelected();
811 // break; 865 // break;
812 case Key_Space: 866 case Key_Space:
813 // playSelected(); puh 867 // playSelected(); puh
814 break; 868 break;
815 case Key_1: 869 case Key_1:
816 tabWidget->setCurrentPage( 0 ); 870 tabWidget->setCurrentPage( 0 );
817 break; 871 break;
818 case Key_2: 872 case Key_2:
819 tabWidget->setCurrentPage( 1 ); 873 tabWidget->setCurrentPage( 1 );
820 break; 874 break;
821 case Key_3: 875 case Key_3:
822 tabWidget->setCurrentPage( 2 ); 876 tabWidget->setCurrentPage( 2 );
823 break; 877 break;
824 case Key_4: 878 case Key_4:
825 tabWidget->setCurrentPage( 3 ); 879 tabWidget->setCurrentPage( 3 );
826 break; 880 break;
827 case Key_Down: 881 case Key_Down:
828 if ( !d->selectedFiles->next() ) 882 if ( !d->selectedFiles->next() )
829 d->selectedFiles->first(); 883 d->selectedFiles->first();
830 break; 884 break;
831 case Key_Up: 885 case Key_Up:
832 if ( !d->selectedFiles->prev() ) 886 if ( !d->selectedFiles->prev() )
833 // d->selectedFiles->last(); 887 // d->selectedFiles->last();
834 break; 888 break;
835 } 889 }
836} 890}
837 891
838void PlayListWidget::pmViewActivated(int index) { 892void PlayListWidget::pmViewActivated(int index) {
839// qDebug("%d", index); 893// qDebug("%d", index);
840 switch(index) { 894 switch(index) {
841 case -16: 895 case -16:
842 { 896 {
843 mediaPlayerState.toggleFullscreen(); 897 mediaPlayerState.toggleFullscreen();
844 bool b=mediaPlayerState.isFullscreen(); 898 bool b=mediaPlayerState.isFullscreen();
845 pmView->setItemChecked( index, b); 899 pmView->setItemChecked( index, b);
846 Config cfg( "OpiePlayer" ); 900 Config cfg( "OpiePlayer" );
847 cfg.writeEntry( "FullScreen", b ); 901 cfg.writeEntry( "FullScreen", b );
848 } 902 }
849 break; 903 break;
850 }; 904 };
851} 905}
852 906
853void PlayListWidget::populateSkinsMenu() { 907void PlayListWidget::populateSkinsMenu() {
854 int item = 0; 908 int item = 0;
855 defaultSkinIndex = 0; 909 defaultSkinIndex = 0;
856 QString skinName; 910 QString skinName;
857 Config cfg( "OpiePlayer" ); 911 Config cfg( "OpiePlayer" );
858 cfg.setGroup("Options" ); 912 cfg.setGroup("Options" );
859 QString skin = cfg.readEntry( "Skin", "default" ); 913 QString skin = cfg.readEntry( "Skin", "default" );
860 914
861 QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" ); 915 QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" );
862 skinsDir.setFilter( QDir::Dirs ); 916 skinsDir.setFilter( QDir::Dirs );
863 skinsDir.setSorting(QDir::Name ); 917 skinsDir.setSorting(QDir::Name );
864 const QFileInfoList *skinslist = skinsDir.entryInfoList(); 918 const QFileInfoList *skinslist = skinsDir.entryInfoList();
865 QFileInfoListIterator it( *skinslist ); 919 QFileInfoListIterator it( *skinslist );
866 QFileInfo *fi; 920 QFileInfo *fi;
867 while ( ( fi = it.current() ) ) { 921 while ( ( fi = it.current() ) ) {
868 skinName = fi->fileName(); 922 skinName = fi->fileName();
869// qDebug( fi->fileName() ); 923// qDebug( fi->fileName() );
870 if( skinName != "." && skinName != ".." && skinName !="CVS" ) { 924 if( skinName != "." && skinName != ".." && skinName !="CVS" ) {
871 item = skinsMenu->insertItem( fi->fileName() ) ; 925 item = skinsMenu->insertItem( fi->fileName() ) ;
872 } 926 }
873 if( skinName == "default" ) { 927 if( skinName == "default" ) {
874 defaultSkinIndex = item; 928 defaultSkinIndex = item;
875 } 929 }
876 if( skinName == skin ) { 930 if( skinName == skin ) {
877 skinsMenu->setItemChecked( item, TRUE ); 931 skinsMenu->setItemChecked( item, TRUE );
878 } 932 }
879 ++it; 933 ++it;
880 } 934 }
881} 935}
882 936
883void PlayListWidget::skinsMenuActivated( int item ) { 937void PlayListWidget::skinsMenuActivated( int item ) {
884 for(unsigned int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) { 938 for(unsigned int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) {
885 skinsMenu->setItemChecked( i, FALSE ); 939 skinsMenu->setItemChecked( i, FALSE );
886 } 940 }
887 skinsMenu->setItemChecked( item, TRUE ); 941 skinsMenu->setItemChecked( item, TRUE );
888 942
889 { 943 {
890 Config cfg( "OpiePlayer" ); 944 Config cfg( "OpiePlayer" );
891 cfg.setGroup("Options"); 945 cfg.setGroup("Options");
892 cfg.writeEntry("Skin", skinsMenu->text( item ) ); 946 cfg.writeEntry("Skin", skinsMenu->text( item ) );
893 } 947 }
894 948
895 emit skinSelected(); 949 emit skinSelected();
896} 950}
897 951
898PlayListWidget::TabType PlayListWidget::currentTab() const 952PlayListWidget::TabType PlayListWidget::currentTab() const
899{ 953{
900 static const TabType indexToTabType[ TabTypeCount ] = 954 static const TabType indexToTabType[ TabTypeCount ] =
901 { CurrentPlayList, AudioFiles, VideoFiles, PlayLists }; 955 { CurrentPlayList, AudioFiles, VideoFiles, PlayLists };
902 956
903 int index = tabWidget->currentPageIndex(); 957 int index = tabWidget->currentPageIndex();
904 assert( index < TabTypeCount && index >= 0 ); 958 assert( index < TabTypeCount && index >= 0 );
905 959
906 return indexToTabType[ index ]; 960 return indexToTabType[ index ];
907} 961}
908 962
909PlayListWidget::Entry PlayListWidget::currentEntry() const 963PlayListWidget::Entry PlayListWidget::currentEntry() const
910{ 964{
911 if ( currentTab() == CurrentPlayList ) { 965 if ( currentTab() == CurrentPlayList ) {
912 const DocLnk *lnk = current(); 966 const DocLnk *lnk = current();
913 return Entry( lnk->name(), lnk->file() ); 967 return Entry( lnk->name(), lnk->file() );
914 } 968 }
915 969
916 return Entry( currentFileListPathName() ); 970 return Entry( currentFileListPathName() );
917} 971}
918 972
919QString PlayListWidget::currentFileListPathName() const { 973QString PlayListWidget::currentFileListPathName() const {
920 return currentFileListView->currentItem()->text( 3 ); 974 return currentFileListView->currentItem()->text( 3 );
921} 975}
922 976
923 977
924void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) { 978void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) {
925 qDebug("qcop message "+msg ); 979 qDebug("qcop message "+msg );
926 QDataStream stream ( data, IO_ReadOnly ); 980 QDataStream stream ( data, IO_ReadOnly );
927 if ( msg == "play()" ) { //plays current selection 981 if ( msg == "play()" ) { //plays current selection
928 btnPlay( true); 982 btnPlay( true);
929 } else if ( msg == "stop()" ) { 983 } else if ( msg == "stop()" ) {
930 mediaPlayerState.setPlaying( false); 984 mediaPlayerState.setPlaying( false);
931 } else if ( msg == "togglePause()" ) { 985 } else if ( msg == "togglePause()" ) {
932 mediaPlayerState.togglePaused(); 986 mediaPlayerState.togglePaused();
933 } else if ( msg == "next()" ) { //select next in list 987 } else if ( msg == "next()" ) { //select next in list
934 mediaPlayerState.setNext(); 988 mediaPlayerState.setNext();
935 } else if ( msg == "prev()" ) { //select previous in list 989 } else if ( msg == "prev()" ) { //select previous in list
936 mediaPlayerState.setPrev(); 990 mediaPlayerState.setPrev();
937 } else if ( msg == "toggleLooping()" ) { //loop or not loop 991 } else if ( msg == "toggleLooping()" ) { //loop or not loop
938 mediaPlayerState.toggleLooping(); 992 mediaPlayerState.toggleLooping();
939 } else if ( msg == "toggleShuffled()" ) { //shuffled or not shuffled 993 } else if ( msg == "toggleShuffled()" ) { //shuffled or not shuffled
940 mediaPlayerState.toggleShuffled(); 994 mediaPlayerState.toggleShuffled();
941 } else if ( msg == "volUp()" ) { //volume more 995 } else if ( msg == "volUp()" ) { //volume more
942// emit moreClicked(); 996// emit moreClicked();
943// emit moreReleased(); 997// emit moreReleased();
944 } else if ( msg == "volDown()" ) { //volume less 998 } else if ( msg == "volDown()" ) { //volume less
945// emit lessClicked(); 999// emit lessClicked();
946// emit lessReleased(); 1000// emit lessReleased();
947 } else if ( msg == "play(QString)" ) { //play this now 1001 } else if ( msg == "play(QString)" ) { //play this now
948 QString file; 1002 QString file;
949 stream >> file; 1003 stream >> file;
950 setDocument( (const QString &) file); 1004 setDocument( (const QString &) file);
951 } else if ( msg == "add(QString)" ) { //add to playlist 1005 } else if ( msg == "add(QString)" ) { //add to playlist
952 QString file; 1006 QString file;
953 stream >> file; 1007 stream >> file;
954 QFileInfo fileInfo(file); 1008 QFileInfo fileInfo(file);
955 DocLnk lnk; 1009 DocLnk lnk;
956 lnk.setName( fileInfo.baseName() ); //sets name 1010 lnk.setName( fileInfo.baseName() ); //sets name
957 lnk.setFile( file ); //sets file name 1011 lnk.setFile( file ); //sets file name
958 addToSelection( lnk ); 1012 addToSelection( lnk );
959 } else if ( msg == "rem(QString)" ) { //remove from playlist 1013 } else if ( msg == "rem(QString)" ) { //remove from playlist
960 QString file; 1014 QString file;
961 stream >> file; 1015 stream >> file;
962 1016
963 } 1017 }
964 1018
965} 1019}