-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp index b6525e1..897c458 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp | |||
@@ -1,1119 +1,1120 @@ | |||
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 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 | 40 | ||
41 | #include <qdir.h> | 41 | #include <qdir.h> |
42 | #include <qmessagebox.h> | 42 | #include <qmessagebox.h> |
43 | #include <qregexp.h> | 43 | #include <qregexp.h> |
44 | #include <qtextstream.h> | 44 | #include <qtextstream.h> |
45 | 45 | ||
46 | #include "playlistselection.h" | 46 | #include "playlistselection.h" |
47 | #include "playlistwidget.h" | 47 | #include "playlistwidget.h" |
48 | #include "mediaplayerstate.h" | 48 | #include "mediaplayerstate.h" |
49 | #include "inputDialog.h" | 49 | #include "inputDialog.h" |
50 | #include "om3u.h" | 50 | #include "om3u.h" |
51 | 51 | ||
52 | //only needed for the random play | 52 | //only needed for the random play |
53 | #include <stdlib.h> | 53 | #include <stdlib.h> |
54 | 54 | ||
55 | #include "audiowidget.h" | 55 | #include "audiowidget.h" |
56 | #include "videowidget.h" | 56 | #include "videowidget.h" |
57 | 57 | ||
58 | extern MediaPlayerState *mediaPlayerState; | 58 | extern MediaPlayerState *mediaPlayerState; |
59 | 59 | ||
60 | 60 | ||
61 | PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) | 61 | PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) |
62 | : PlayListWidgetGui( parent, name, fl ) { | 62 | : PlayListWidgetGui( parent, name, fl ) { |
63 | 63 | ||
64 | d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), | 64 | d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), |
65 | "opieplayer2/add_to_playlist", | 65 | "opieplayer2/add_to_playlist", |
66 | this , SLOT(addSelected() ) ); | 66 | this , SLOT(addSelected() ) ); |
67 | d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), | 67 | d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), |
68 | "opieplayer2/remove_from_playlist", | 68 | "opieplayer2/remove_from_playlist", |
69 | this , SLOT(removeSelected() ) ); | 69 | this , SLOT(removeSelected() ) ); |
70 | d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play", | 70 | d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play", |
71 | this , SLOT( btnPlay( bool) ), TRUE ); | 71 | this , SLOT( btnPlay( bool) ), TRUE ); |
72 | d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle", | 72 | d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle", |
73 | mediaPlayerState, SLOT( setShuffled( bool ) ), TRUE ); | 73 | mediaPlayerState, SLOT( setShuffled( bool ) ), TRUE ); |
74 | d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop", | 74 | d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop", |
75 | mediaPlayerState, SLOT( setLooping( bool ) ), TRUE ); | 75 | mediaPlayerState, SLOT( setLooping( bool ) ), TRUE ); |
76 | 76 | ||
77 | (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); | 77 | (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); |
78 | (void)new MenuItem( pmPlayList, tr( "Add all audio files" ), | 78 | (void)new MenuItem( pmPlayList, tr( "Add all audio files" ), |
79 | this, SLOT( addAllMusicToList() ) ); | 79 | this, SLOT( addAllMusicToList() ) ); |
80 | (void)new MenuItem( pmPlayList, tr( "Add all video files" ), | 80 | (void)new MenuItem( pmPlayList, tr( "Add all video files" ), |
81 | this, SLOT( addAllVideoToList() ) ); | 81 | this, SLOT( addAllVideoToList() ) ); |
82 | (void)new MenuItem( pmPlayList, tr( "Add all files" ), | 82 | (void)new MenuItem( pmPlayList, tr( "Add all files" ), |
83 | this, SLOT( addAllToList() ) ); | 83 | this, SLOT( addAllToList() ) ); |
84 | pmPlayList->insertSeparator(-1); | 84 | pmPlayList->insertSeparator(-1); |
85 | // (void)new MenuItem( pmPlayList, tr( "Save PlayList" ), | 85 | // (void)new MenuItem( pmPlayList, tr( "Save PlayList" ), |
86 | // this, SLOT( saveList() ) ); | 86 | // this, SLOT( saveList() ) ); |
87 | (void)new MenuItem( pmPlayList, tr( "Save Playlist" ), | 87 | (void)new MenuItem( pmPlayList, tr( "Save Playlist" ), |
88 | this, SLOT(writem3u() ) ); | 88 | this, SLOT(writem3u() ) ); |
89 | pmPlayList->insertSeparator(-1); | 89 | pmPlayList->insertSeparator(-1); |
90 | (void)new MenuItem( pmPlayList, tr( "Open File or URL" ), | 90 | (void)new MenuItem( pmPlayList, tr( "Open File or URL" ), |
91 | this,SLOT( openFile() ) ); | 91 | this,SLOT( openFile() ) ); |
92 | pmPlayList->insertSeparator(-1); | 92 | pmPlayList->insertSeparator(-1); |
93 | (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), | 93 | (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), |
94 | this,SLOT( scanForAudio() ) ); | 94 | this,SLOT( scanForAudio() ) ); |
95 | (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), | 95 | (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), |
96 | this,SLOT( scanForVideo() ) ); | 96 | this,SLOT( scanForVideo() ) ); |
97 | 97 | ||
98 | pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"), | 98 | pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"), |
99 | mediaPlayerState, SLOT( toggleFullscreen() ) ); | 99 | mediaPlayerState, SLOT( toggleFullscreen() ) ); |
100 | 100 | ||
101 | Config cfg( "OpiePlayer" ); | 101 | Config cfg( "OpiePlayer" ); |
102 | bool b= cfg.readBoolEntry("FullScreen", 0); | 102 | bool b= cfg.readBoolEntry("FullScreen", 0); |
103 | mediaPlayerState->setFullscreen( b ); | 103 | mediaPlayerState->setFullscreen( b ); |
104 | pmView->setItemChecked( -16, b ); | 104 | pmView->setItemChecked( -16, b ); |
105 | 105 | ||
106 | (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up", | 106 | (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up", |
107 | d->selectedFiles, SLOT(moveSelectedUp() ) ); | 107 | d->selectedFiles, SLOT(moveSelectedUp() ) ); |
108 | (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut", | 108 | (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut", |
109 | d->selectedFiles, SLOT(removeSelected() ) ); | 109 | d->selectedFiles, SLOT(removeSelected() ) ); |
110 | (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down", | 110 | (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down", |
111 | d->selectedFiles, SLOT(moveSelectedDown() ) ); | 111 | d->selectedFiles, SLOT(moveSelectedDown() ) ); |
112 | QVBox *stretch2 = new QVBox( vbox1 ); | 112 | QVBox *stretch2 = new QVBox( vbox1 ); |
113 | 113 | ||
114 | connect( tbDeletePlaylist, ( SIGNAL( released() ) ), | 114 | connect( tbDeletePlaylist, ( SIGNAL( released() ) ), |
115 | SLOT( deletePlaylist() ) ); | 115 | SLOT( deletePlaylist() ) ); |
116 | connect( pmView, SIGNAL( activated( int ) ), | 116 | connect( pmView, SIGNAL( activated( int ) ), |
117 | this, SLOT( pmViewActivated( int ) ) ); | 117 | this, SLOT( pmViewActivated( int ) ) ); |
118 | connect( skinsMenu, SIGNAL( activated( int ) ) , | 118 | connect( skinsMenu, SIGNAL( activated( int ) ) , |
119 | this, SLOT( skinsMenuActivated( int ) ) ); | 119 | this, SLOT( skinsMenuActivated( int ) ) ); |
120 | connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), | 120 | connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), |
121 | this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) ); | 121 | this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) ); |
122 | connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ), | 122 | connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ), |
123 | this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) ); | 123 | this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) ); |
124 | connect( audioView, SIGNAL( returnPressed( QListViewItem *) ), | 124 | connect( audioView, SIGNAL( returnPressed( QListViewItem *) ), |
125 | this,SLOT( playIt( QListViewItem *) ) ); | 125 | this,SLOT( playIt( QListViewItem *) ) ); |
126 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), | 126 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), |
127 | this, SLOT( addToSelection( QListViewItem *) ) ); | 127 | this, SLOT( addToSelection( QListViewItem *) ) ); |
128 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), | 128 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), |
129 | this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) ); | 129 | this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) ); |
130 | connect( videoView, SIGNAL( returnPressed( QListViewItem *) ), | 130 | connect( videoView, SIGNAL( returnPressed( QListViewItem *) ), |
131 | this,SLOT( playIt( QListViewItem *) ) ); | 131 | this,SLOT( playIt( QListViewItem *) ) ); |
132 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), | 132 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), |
133 | this, SLOT( addToSelection( QListViewItem *) ) ); | 133 | this, SLOT( addToSelection( QListViewItem *) ) ); |
134 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), | 134 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), |
135 | this, SLOT( loadList( const DocLnk & ) ) ); | 135 | this, SLOT( loadList( const DocLnk & ) ) ); |
136 | connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ), | 136 | connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ), |
137 | this, SLOT( tabChanged( QWidget* ) ) ); | 137 | this, SLOT( tabChanged( QWidget* ) ) ); |
138 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), | 138 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), |
139 | d->tbPlay, SLOT( setOn( bool ) ) ); | 139 | d->tbPlay, SLOT( setOn( bool ) ) ); |
140 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), | 140 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), |
141 | d->tbLoop, SLOT( setOn( bool ) ) ); | 141 | d->tbLoop, SLOT( setOn( bool ) ) ); |
142 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), | 142 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), |
143 | d->tbShuffle, SLOT( setOn( bool ) ) ); | 143 | d->tbShuffle, SLOT( setOn( bool ) ) ); |
144 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), | 144 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), |
145 | this, SLOT( setPlaylist( bool ) ) ); | 145 | this, SLOT( setPlaylist( bool ) ) ); |
146 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), | 146 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), |
147 | this, SLOT( playIt( QListViewItem *) ) ); | 147 | this, SLOT( playIt( QListViewItem *) ) ); |
148 | connect ( gammaSlider, SIGNAL( valueChanged( int ) ), | 148 | connect ( gammaSlider, SIGNAL( valueChanged( int ) ), |
149 | mediaPlayerState, SLOT( setVideoGamma( int ) ) ); | 149 | mediaPlayerState, SLOT( setVideoGamma( int ) ) ); |
150 | 150 | ||
151 | // see which skins are installed | 151 | // see which skins are installed |
152 | videoScan=FALSE; | 152 | videoScan=FALSE; |
153 | audioScan=FALSE; | 153 | audioScan=FALSE; |
154 | populateSkinsMenu(); | 154 | populateSkinsMenu(); |
155 | initializeStates(); | 155 | initializeStates(); |
156 | 156 | ||
157 | cfg.setGroup("PlayList"); | ||
157 | QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "" ); | 158 | QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "" ); |
158 | loadList(DocLnk( currentPlaylist ) ); | 159 | loadList(DocLnk( currentPlaylist ) ); |
159 | setCaption( tr( "OpiePlayer: " ) + currentPlaylist ); | 160 | setCaption( tr( "OpiePlayer: " ) + currentPlaylist ); |
160 | } | 161 | } |
161 | 162 | ||
162 | 163 | ||
163 | PlayListWidget::~PlayListWidget() { | 164 | PlayListWidget::~PlayListWidget() { |
164 | if ( d->current ) { | 165 | if ( d->current ) { |
165 | delete d->current; | 166 | delete d->current; |
166 | } | 167 | } |
167 | delete d; | 168 | delete d; |
168 | } | 169 | } |
169 | 170 | ||
170 | 171 | ||
171 | void PlayListWidget::initializeStates() { | 172 | void PlayListWidget::initializeStates() { |
172 | d->tbPlay->setOn( mediaPlayerState->playing() ); | 173 | d->tbPlay->setOn( mediaPlayerState->playing() ); |
173 | d->tbLoop->setOn( mediaPlayerState->looping() ); | 174 | d->tbLoop->setOn( mediaPlayerState->looping() ); |
174 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); | 175 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); |
175 | setPlaylist( true ); | 176 | setPlaylist( true ); |
176 | } | 177 | } |
177 | 178 | ||
178 | 179 | ||
179 | void PlayListWidget::readConfig( Config& cfg ) { | 180 | void PlayListWidget::readConfig( Config& cfg ) { |
180 | 181 | ||
181 | cfg.setGroup( "PlayList" ); | 182 | cfg.setGroup( "PlayList" ); |
182 | QString currentString = cfg.readEntry( "current", "" ); | 183 | QString currentString = cfg.readEntry( "current", "" ); |
183 | int noOfFiles = cfg.readNumEntry( "NumberOfFiles", 0 ); | 184 | int noOfFiles = cfg.readNumEntry( "NumberOfFiles", 0 ); |
184 | 185 | ||
185 | for ( int i = 0; i < noOfFiles; i++ ) { | 186 | for ( int i = 0; i < noOfFiles; i++ ) { |
186 | QString entryName; | 187 | QString entryName; |
187 | entryName.sprintf( "File%i", i + 1 ); | 188 | entryName.sprintf( "File%i", i + 1 ); |
188 | 189 | ||
189 | QString linkFile = cfg.readEntry( entryName ); | 190 | QString linkFile = cfg.readEntry( entryName ); |
190 | 191 | ||
191 | qDebug("reading "+linkFile); | 192 | qDebug("reading "+linkFile); |
192 | 193 | ||
193 | if( QFileInfo( linkFile ).exists() ) { | 194 | if( QFileInfo( linkFile ).exists() ) { |
194 | 195 | ||
195 | DocLnk lnk( linkFile ); | 196 | DocLnk lnk( linkFile ); |
196 | 197 | ||
197 | if ( QFileInfo( lnk.file() ).exists() || | 198 | if ( QFileInfo( lnk.file() ).exists() || |
198 | 199 | ||
199 | linkFile.find( "http" , 0, TRUE) != -1) { | 200 | linkFile.find( "http" , 0, TRUE) != -1) { |
200 | 201 | ||
201 | d->selectedFiles->addToSelection( lnk ); | 202 | d->selectedFiles->addToSelection( lnk ); |
202 | } | 203 | } |
203 | } | 204 | } |
204 | } | 205 | } |
205 | d->selectedFiles->setSelectedItem( currentString ); | 206 | d->selectedFiles->setSelectedItem( currentString ); |
206 | } | 207 | } |
207 | 208 | ||
208 | 209 | ||
209 | void PlayListWidget::writeConfig( Config& cfg ) const { | 210 | void PlayListWidget::writeConfig( Config& cfg ) const { |
210 | 211 | ||
211 | Config config( "OpiePlayer" ); | 212 | Config config( "OpiePlayer" ); |
212 | config.setGroup( "PlayList" ); | 213 | config.setGroup( "PlayList" ); |
213 | 214 | ||
214 | // if(config.readBoolEntry("newPlaylist")) { | 215 | // if(config.readBoolEntry("newPlaylist")) { |
215 | // new for testing | 216 | // new for testing |
216 | QString name, filename, list; | 217 | QString name, filename, list; |
217 | Om3u *m3uList; | 218 | Om3u *m3uList; |
218 | name = "default"; | 219 | name = "default"; |
219 | 220 | ||
220 | filename=QPEApplication::documentDir() + "/" + name+".m3u"; | 221 | filename=QPEApplication::documentDir() + "/" + name+".m3u"; |
221 | m3uList = new Om3u(filename, IO_ReadWrite); | 222 | m3uList = new Om3u(filename, IO_ReadWrite); |
222 | d->selectedFiles->first(); | 223 | d->selectedFiles->first(); |
223 | do { | 224 | do { |
224 | qDebug(d->selectedFiles->current()->file()); | 225 | qDebug(d->selectedFiles->current()->file()); |
225 | m3uList->add( d->selectedFiles->current()->file() ); | 226 | m3uList->add( d->selectedFiles->current()->file() ); |
226 | } | 227 | } |
227 | while ( d->selectedFiles->next() ); | 228 | while ( d->selectedFiles->next() ); |
228 | // qDebug( list ); | 229 | // qDebug( list ); |
229 | 230 | ||
230 | // m3uList->write(); | 231 | // m3uList->write(); |
231 | m3uList->close(); | 232 | m3uList->close(); |
232 | if(m3uList) delete m3uList; | 233 | if(m3uList) delete m3uList; |
233 | 234 | ||
234 | DocLnk lnk; | 235 | DocLnk lnk; |
235 | lnk.setFile( filename); | 236 | lnk.setFile( filename); |
236 | lnk.setIcon("opieplayer2/playlist2"); | 237 | lnk.setIcon("opieplayer2/playlist2"); |
237 | lnk.setName( name); //sets file name | 238 | lnk.setName( name); //sets file name |
238 | 239 | ||
239 | qDebug("writing default playlist "+filename); | 240 | qDebug("writing default playlist "+filename); |
240 | 241 | ||
241 | config.writeEntry("CurrentPlaylist", filename); | 242 | config.writeEntry("CurrentPlaylist", filename); |
242 | // currentPlayList=filename; | 243 | // currentPlayList=filename; |
243 | if(!lnk.writeLink()) { | 244 | if(!lnk.writeLink()) { |
244 | qDebug("Writing doclink did not work"); | 245 | qDebug("Writing doclink did not work"); |
245 | } | 246 | } |
246 | // } else { | 247 | // } else { |
247 | 248 | ||
248 | // d->selectedFiles->writeCurrent( cfg ); | 249 | // d->selectedFiles->writeCurrent( cfg ); |
249 | // int noOfFiles = 0; | 250 | // int noOfFiles = 0; |
250 | // d->selectedFiles->first(); | 251 | // d->selectedFiles->first(); |
251 | 252 | ||
252 | // do { | 253 | // do { |
253 | // const DocLnk *lnk = d->selectedFiles->current(); | 254 | // const DocLnk *lnk = d->selectedFiles->current(); |
254 | 255 | ||
255 | // if ( lnk ) { | 256 | // if ( lnk ) { |
256 | 257 | ||
257 | // QString entryName; | 258 | // QString entryName; |
258 | // entryName.sprintf( "File%i", noOfFiles + 1 ); | 259 | // entryName.sprintf( "File%i", noOfFiles + 1 ); |
259 | 260 | ||
260 | // cfg.writeEntry( entryName, lnk->linkFile() ); | 261 | // cfg.writeEntry( entryName, lnk->linkFile() ); |
261 | // // if this link does exist, add it so we have the file | 262 | // // if this link does exist, add it so we have the file |
262 | // // next time... | 263 | // // next time... |
263 | 264 | ||
264 | // if ( !QFile::exists( lnk->linkFile() ) ) { | 265 | // if ( !QFile::exists( lnk->linkFile() ) ) { |
265 | // lnk->writeLink(); | 266 | // lnk->writeLink(); |
266 | // } | 267 | // } |
267 | // } | 268 | // } |
268 | // noOfFiles++; | 269 | // noOfFiles++; |
269 | // } | 270 | // } |
270 | // while ( d->selectedFiles->next() ); | 271 | // while ( d->selectedFiles->next() ); |
271 | // cfg.writeEntry("NumberOfFiles", noOfFiles ); | 272 | // cfg.writeEntry("NumberOfFiles", noOfFiles ); |
272 | // } | 273 | // } |
273 | } | 274 | } |
274 | 275 | ||
275 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { | 276 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { |
276 | d->setDocumentUsed = FALSE; | 277 | d->setDocumentUsed = FALSE; |
277 | if ( mediaPlayerState->playlist() ) { | 278 | if ( mediaPlayerState->playlist() ) { |
278 | if( QFileInfo( lnk.file() ).exists() || | 279 | if( QFileInfo( lnk.file() ).exists() || |
279 | lnk.file().left(4) == "http" ) | 280 | lnk.file().left(4) == "http" ) |
280 | d->selectedFiles->addToSelection( lnk ); | 281 | d->selectedFiles->addToSelection( lnk ); |
281 | writeCurrentM3u(); | 282 | writeCurrentM3u(); |
282 | } | 283 | } |
283 | else | 284 | else |
284 | mediaPlayerState->setPlaying( TRUE ); | 285 | mediaPlayerState->setPlaying( TRUE ); |
285 | } | 286 | } |
286 | 287 | ||
287 | 288 | ||
288 | void PlayListWidget::clearList() { | 289 | void PlayListWidget::clearList() { |
289 | while ( first() ) { | 290 | while ( first() ) { |
290 | d->selectedFiles->removeSelected(); | 291 | d->selectedFiles->removeSelected(); |
291 | } | 292 | } |
292 | } | 293 | } |
293 | 294 | ||
294 | void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) { | 295 | void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) { |
295 | switch (mouse) { | 296 | switch (mouse) { |
296 | case 1: | 297 | case 1: |
297 | break; | 298 | break; |
298 | case 2: | 299 | case 2: |
299 | { | 300 | { |
300 | QPopupMenu m; | 301 | QPopupMenu m; |
301 | m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); | 302 | m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); |
302 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); | 303 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); |
303 | m.exec( QCursor::pos() ); | 304 | m.exec( QCursor::pos() ); |
304 | } | 305 | } |
305 | break; | 306 | break; |
306 | } | 307 | } |
307 | } | 308 | } |
308 | 309 | ||
309 | 310 | ||
310 | void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) { | 311 | void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) { |
311 | switch (mouse) { | 312 | switch (mouse) { |
312 | case 1: | 313 | case 1: |
313 | break; | 314 | break; |
314 | case 2: | 315 | case 2: |
315 | { | 316 | { |
316 | QPopupMenu m; | 317 | QPopupMenu m; |
317 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); | 318 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); |
318 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); | 319 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); |
319 | m.exec( QCursor::pos() ); | 320 | m.exec( QCursor::pos() ); |
320 | } | 321 | } |
321 | break; | 322 | break; |
322 | } | 323 | } |
323 | } | 324 | } |
324 | 325 | ||
325 | 326 | ||
326 | void PlayListWidget::addAllToList() { | 327 | void PlayListWidget::addAllToList() { |
327 | DocLnkSet filesAll; | 328 | DocLnkSet filesAll; |
328 | Global::findDocuments(&filesAll, "video/*;audio/*"); | 329 | Global::findDocuments(&filesAll, "video/*;audio/*"); |
329 | QListIterator<DocLnk> Adit( filesAll.children() ); | 330 | QListIterator<DocLnk> Adit( filesAll.children() ); |
330 | for ( ; Adit.current(); ++Adit ) { | 331 | for ( ; Adit.current(); ++Adit ) { |
331 | if( QFileInfo( Adit.current()->file() ).exists() ) { | 332 | if( QFileInfo( Adit.current()->file() ).exists() ) { |
332 | d->selectedFiles->addToSelection( **Adit ); | 333 | d->selectedFiles->addToSelection( **Adit ); |
333 | } | 334 | } |
334 | } | 335 | } |
335 | writeCurrentM3u(); | 336 | writeCurrentM3u(); |
336 | } | 337 | } |
337 | 338 | ||
338 | 339 | ||
339 | void PlayListWidget::addAllMusicToList() { | 340 | void PlayListWidget::addAllMusicToList() { |
340 | QListIterator<DocLnk> dit( files.children() ); | 341 | QListIterator<DocLnk> dit( files.children() ); |
341 | for ( ; dit.current(); ++dit ) { | 342 | for ( ; dit.current(); ++dit ) { |
342 | if( QFileInfo(dit.current()->file() ).exists() ) { | 343 | if( QFileInfo(dit.current()->file() ).exists() ) { |
343 | d->selectedFiles->addToSelection( **dit ); | 344 | d->selectedFiles->addToSelection( **dit ); |
344 | } | 345 | } |
345 | } | 346 | } |
346 | writeCurrentM3u(); | 347 | writeCurrentM3u(); |
347 | } | 348 | } |
348 | 349 | ||
349 | 350 | ||
350 | void PlayListWidget::addAllVideoToList() { | 351 | void PlayListWidget::addAllVideoToList() { |
351 | QListIterator<DocLnk> dit( vFiles.children() ); | 352 | QListIterator<DocLnk> dit( vFiles.children() ); |
352 | for ( ; dit.current(); ++dit ) { | 353 | for ( ; dit.current(); ++dit ) { |
353 | if( QFileInfo( dit.current()->file() ).exists() ) { | 354 | if( QFileInfo( dit.current()->file() ).exists() ) { |
354 | d->selectedFiles->addToSelection( **dit ); | 355 | d->selectedFiles->addToSelection( **dit ); |
355 | } | 356 | } |
356 | } | 357 | } |
357 | writeCurrentM3u(); | 358 | writeCurrentM3u(); |
358 | } | 359 | } |
359 | 360 | ||
360 | 361 | ||
361 | void PlayListWidget::setDocument( const QString& fileref ) { | 362 | void PlayListWidget::setDocument( const QString& fileref ) { |
362 | //qDebug( fileref ); | 363 | //qDebug( fileref ); |
363 | fromSetDocument = TRUE; | 364 | fromSetDocument = TRUE; |
364 | if ( fileref.isNull() ) { | 365 | if ( fileref.isNull() ) { |
365 | QMessageBox::critical( 0, tr( "Invalid File" ), | 366 | QMessageBox::critical( 0, tr( "Invalid File" ), |
366 | tr( "There was a problem in getting the file." ) ); | 367 | tr( "There was a problem in getting the file." ) ); |
367 | return; | 368 | return; |
368 | } | 369 | } |
369 | 370 | ||
370 | if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u | 371 | if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u |
371 | readm3u( fileref ); | 372 | readm3u( fileref ); |
372 | } else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls | 373 | } else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls |
373 | readPls( fileref ); | 374 | readPls( fileref ); |
374 | }// else if( fileref.find( "playlist", 0, TRUE) != -1 ) {//is playlist | 375 | }// else if( fileref.find( "playlist", 0, TRUE) != -1 ) {//is playlist |
375 | // clearList(); | 376 | // clearList(); |
376 | // loadList( DocLnk( fileref ) ); | 377 | // loadList( DocLnk( fileref ) ); |
377 | // d->selectedFiles->first(); | 378 | // d->selectedFiles->first(); |
378 | // } | 379 | // } |
379 | else { | 380 | else { |
380 | clearList(); | 381 | clearList(); |
381 | addToSelection( DocLnk( fileref ) ); | 382 | addToSelection( DocLnk( fileref ) ); |
382 | d->setDocumentUsed = TRUE; | 383 | d->setDocumentUsed = TRUE; |
383 | mediaPlayerState->setPlaying( FALSE ); | 384 | mediaPlayerState->setPlaying( FALSE ); |
384 | mediaPlayerState->setPlaying( TRUE ); | 385 | mediaPlayerState->setPlaying( TRUE ); |
385 | } | 386 | } |
386 | } | 387 | } |
387 | 388 | ||
388 | 389 | ||
389 | void PlayListWidget::useSelectedDocument() { | 390 | void PlayListWidget::useSelectedDocument() { |
390 | d->setDocumentUsed = FALSE; | 391 | d->setDocumentUsed = FALSE; |
391 | } | 392 | } |
392 | 393 | ||
393 | 394 | ||
394 | const DocLnk *PlayListWidget::current() { // this is fugly | 395 | const DocLnk *PlayListWidget::current() { // this is fugly |
395 | switch ( whichList() ) { | 396 | switch ( whichList() ) { |
396 | case 0: //playlist | 397 | case 0: //playlist |
397 | { | 398 | { |
398 | // qDebug("playlist"); | 399 | // qDebug("playlist"); |
399 | if ( mediaPlayerState->playlist() ) { | 400 | if ( mediaPlayerState->playlist() ) { |
400 | return d->selectedFiles->current(); | 401 | return d->selectedFiles->current(); |
401 | } else if ( d->setDocumentUsed && d->current ) { | 402 | } else if ( d->setDocumentUsed && d->current ) { |
402 | return d->current; | 403 | return d->current; |
403 | } else { | 404 | } else { |
404 | return &(d->files->selectedDocument()); | 405 | return &(d->files->selectedDocument()); |
405 | } | 406 | } |
406 | } | 407 | } |
407 | break; | 408 | break; |
408 | }; | 409 | }; |
409 | return 0; | 410 | return 0; |
410 | } | 411 | } |
411 | 412 | ||
412 | 413 | ||
413 | bool PlayListWidget::prev() { | 414 | bool PlayListWidget::prev() { |
414 | if ( mediaPlayerState->playlist() ) { | 415 | if ( mediaPlayerState->playlist() ) { |
415 | if ( mediaPlayerState->shuffled() ) { | 416 | if ( mediaPlayerState->shuffled() ) { |
416 | const DocLnk *cur = current(); | 417 | const DocLnk *cur = current(); |
417 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); | 418 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); |
418 | for ( int i = 0; i < j; i++ ) { | 419 | for ( int i = 0; i < j; i++ ) { |
419 | if ( !d->selectedFiles->next() ) | 420 | if ( !d->selectedFiles->next() ) |
420 | d->selectedFiles->first(); | 421 | d->selectedFiles->first(); |
421 | } | 422 | } |
422 | if ( cur == current() ) | 423 | if ( cur == current() ) |
423 | if ( !d->selectedFiles->next() ) { | 424 | if ( !d->selectedFiles->next() ) { |
424 | d->selectedFiles->first(); | 425 | d->selectedFiles->first(); |
425 | } | 426 | } |
426 | return TRUE; | 427 | return TRUE; |
427 | } else { | 428 | } else { |
428 | if ( !d->selectedFiles->prev() ) { | 429 | if ( !d->selectedFiles->prev() ) { |
429 | if ( mediaPlayerState->looping() ) { | 430 | if ( mediaPlayerState->looping() ) { |
430 | return d->selectedFiles->last(); | 431 | return d->selectedFiles->last(); |
431 | } else { | 432 | } else { |
432 | return FALSE; | 433 | return FALSE; |
433 | } | 434 | } |
434 | } | 435 | } |
435 | return TRUE; | 436 | return TRUE; |
436 | } | 437 | } |
437 | } else { | 438 | } else { |
438 | return mediaPlayerState->looping(); | 439 | return mediaPlayerState->looping(); |
439 | } | 440 | } |
440 | } | 441 | } |
441 | 442 | ||
442 | 443 | ||
443 | bool PlayListWidget::next() { | 444 | bool PlayListWidget::next() { |
444 | //qDebug("<<<<<<<<<<<<next()"); | 445 | //qDebug("<<<<<<<<<<<<next()"); |
445 | if ( mediaPlayerState->playlist() ) { | 446 | if ( mediaPlayerState->playlist() ) { |
446 | if ( mediaPlayerState->shuffled() ) { | 447 | if ( mediaPlayerState->shuffled() ) { |
447 | return prev(); | 448 | return prev(); |
448 | } else { | 449 | } else { |
449 | if ( !d->selectedFiles->next() ) { | 450 | if ( !d->selectedFiles->next() ) { |
450 | if ( mediaPlayerState->looping() ) { | 451 | if ( mediaPlayerState->looping() ) { |
451 | return d->selectedFiles->first(); | 452 | return d->selectedFiles->first(); |
452 | } else { | 453 | } else { |
453 | return FALSE; | 454 | return FALSE; |
454 | } | 455 | } |
455 | } | 456 | } |
456 | return TRUE; | 457 | return TRUE; |
457 | } | 458 | } |
458 | } else { | 459 | } else { |
459 | return mediaPlayerState->looping(); | 460 | return mediaPlayerState->looping(); |
460 | } | 461 | } |
461 | } | 462 | } |
462 | 463 | ||
463 | 464 | ||
464 | bool PlayListWidget::first() { | 465 | bool PlayListWidget::first() { |
465 | if ( mediaPlayerState->playlist() ) | 466 | if ( mediaPlayerState->playlist() ) |
466 | return d->selectedFiles->first(); | 467 | return d->selectedFiles->first(); |
467 | else | 468 | else |
468 | return mediaPlayerState->looping(); | 469 | return mediaPlayerState->looping(); |
469 | } | 470 | } |
470 | 471 | ||
471 | 472 | ||
472 | bool PlayListWidget::last() { | 473 | bool PlayListWidget::last() { |
473 | if ( mediaPlayerState->playlist() ) | 474 | if ( mediaPlayerState->playlist() ) |
474 | return d->selectedFiles->last(); | 475 | return d->selectedFiles->last(); |
475 | else | 476 | else |
476 | return mediaPlayerState->looping(); | 477 | return mediaPlayerState->looping(); |
477 | } | 478 | } |
478 | 479 | ||
479 | 480 | ||
480 | void PlayListWidget::saveList() { | 481 | void PlayListWidget::saveList() { |
481 | writem3u(); | 482 | writem3u(); |
482 | } | 483 | } |
483 | 484 | ||
484 | 485 | ||
485 | void PlayListWidget::loadList( const DocLnk & lnk) { | 486 | void PlayListWidget::loadList( const DocLnk & lnk) { |
486 | QString name = lnk.name(); | 487 | QString name = lnk.name(); |
487 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); | 488 | qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); |
488 | 489 | ||
489 | if( name.length()>0) { | 490 | if( name.length()>0) { |
490 | setCaption("OpiePlayer: "+name); | 491 | setCaption("OpiePlayer: "+name); |
491 | qDebug("<<<<<<<<<<<<load list "+ lnk.file()); | 492 | qDebug("<<<<<<<<<<<<load list "+ lnk.file()); |
492 | clearList(); | 493 | clearList(); |
493 | readm3u(lnk.file()); | 494 | readm3u(lnk.file()); |
494 | tabWidget->setCurrentPage(0); | 495 | tabWidget->setCurrentPage(0); |
495 | } | 496 | } |
496 | } | 497 | } |
497 | 498 | ||
498 | 499 | ||
499 | void PlayListWidget::setPlaylist( bool shown ) { | 500 | void PlayListWidget::setPlaylist( bool shown ) { |
500 | if ( shown ) { | 501 | if ( shown ) { |
501 | d->playListFrame->show(); | 502 | d->playListFrame->show(); |
502 | } else { | 503 | } else { |
503 | d->playListFrame->hide(); | 504 | d->playListFrame->hide(); |
504 | } | 505 | } |
505 | } | 506 | } |
506 | 507 | ||
507 | 508 | ||
508 | void PlayListWidget::addSelected() { | 509 | void PlayListWidget::addSelected() { |
509 | 510 | ||
510 | switch (whichList()) { | 511 | switch (whichList()) { |
511 | case 0: //playlist | 512 | case 0: //playlist |
512 | break; | 513 | break; |
513 | case 1: { //audio | 514 | case 1: { //audio |
514 | QListViewItemIterator it( audioView ); | 515 | QListViewItemIterator it( audioView ); |
515 | // iterate through all items of the listview | 516 | // iterate through all items of the listview |
516 | for ( ; it.current(); ++it ) { | 517 | for ( ; it.current(); ++it ) { |
517 | if ( it.current()->isSelected() ) { | 518 | if ( it.current()->isSelected() ) { |
518 | QListIterator<DocLnk> dit( files.children() ); | 519 | QListIterator<DocLnk> dit( files.children() ); |
519 | for ( ; dit.current(); ++dit ) { | 520 | for ( ; dit.current(); ++dit ) { |
520 | if( dit.current()->name() == it.current()->text(0) ) { | 521 | if( dit.current()->name() == it.current()->text(0) ) { |
521 | if( QFileInfo( dit.current()->file()).exists()) { | 522 | if( QFileInfo( dit.current()->file()).exists()) { |
522 | d->selectedFiles->addToSelection( **dit ); | 523 | d->selectedFiles->addToSelection( **dit ); |
523 | audioView->setSelected( it.current(),FALSE); | 524 | audioView->setSelected( it.current(),FALSE); |
524 | } | 525 | } |
525 | } | 526 | } |
526 | } | 527 | } |
527 | } | 528 | } |
528 | } | 529 | } |
529 | tabWidget->setCurrentPage(0); | 530 | tabWidget->setCurrentPage(0); |
530 | writeCurrentM3u(); | 531 | writeCurrentM3u(); |
531 | } | 532 | } |
532 | break; | 533 | break; |
533 | case 2: { // video | 534 | case 2: { // video |
534 | QListViewItemIterator it( videoView ); | 535 | QListViewItemIterator it( videoView ); |
535 | // iterate through all items of the listview | 536 | // iterate through all items of the listview |
536 | for ( ; it.current(); ++it ) { | 537 | for ( ; it.current(); ++it ) { |
537 | if ( it.current()->isSelected() ) { | 538 | if ( it.current()->isSelected() ) { |
538 | QListIterator<DocLnk> dit( vFiles.children() ); | 539 | QListIterator<DocLnk> dit( vFiles.children() ); |
539 | for ( ; dit.current(); ++dit ) { | 540 | for ( ; dit.current(); ++dit ) { |
540 | if( dit.current()->name() == it.current()->text(0) ) { | 541 | if( dit.current()->name() == it.current()->text(0) ) { |
541 | if(QFileInfo( dit.current()->file()).exists()) { | 542 | if(QFileInfo( dit.current()->file()).exists()) { |
542 | d->selectedFiles->addToSelection( **dit ); | 543 | d->selectedFiles->addToSelection( **dit ); |
543 | videoView->setSelected( it.current(),FALSE); | 544 | videoView->setSelected( it.current(),FALSE); |
544 | } | 545 | } |
545 | } | 546 | } |
546 | } | 547 | } |
547 | } | 548 | } |
548 | } | 549 | } |
549 | tabWidget->setCurrentPage(0); | 550 | tabWidget->setCurrentPage(0); |
550 | writeCurrentM3u(); | 551 | writeCurrentM3u(); |
551 | } | 552 | } |
552 | break; | 553 | break; |
553 | }; | 554 | }; |
554 | } | 555 | } |
555 | 556 | ||
556 | 557 | ||
557 | void PlayListWidget::removeSelected() { | 558 | void PlayListWidget::removeSelected() { |
558 | d->selectedFiles->removeSelected( ); | 559 | d->selectedFiles->removeSelected( ); |
559 | } | 560 | } |
560 | 561 | ||
561 | 562 | ||
562 | void PlayListWidget::playIt( QListViewItem *it) { | 563 | void PlayListWidget::playIt( QListViewItem *it) { |
563 | if(!it) return; | 564 | if(!it) return; |
564 | mediaPlayerState->setPlaying(FALSE); | 565 | mediaPlayerState->setPlaying(FALSE); |
565 | mediaPlayerState->setPlaying(TRUE); | 566 | mediaPlayerState->setPlaying(TRUE); |
566 | d->selectedFiles->unSelect(); | 567 | d->selectedFiles->unSelect(); |
567 | } | 568 | } |
568 | 569 | ||
569 | 570 | ||
570 | void PlayListWidget::addToSelection( QListViewItem *it) { | 571 | void PlayListWidget::addToSelection( QListViewItem *it) { |
571 | d->setDocumentUsed = FALSE; | 572 | d->setDocumentUsed = FALSE; |
572 | 573 | ||
573 | if(it) { | 574 | if(it) { |
574 | switch ( whichList()) { | 575 | switch ( whichList()) { |
575 | case 1: { | 576 | case 1: { |
576 | QListIterator<DocLnk> dit( files.children() ); | 577 | QListIterator<DocLnk> dit( files.children() ); |
577 | for ( ; dit.current(); ++dit ) { | 578 | for ( ; dit.current(); ++dit ) { |
578 | if( dit.current()->name() == it->text(0)) { | 579 | if( dit.current()->name() == it->text(0)) { |
579 | if(QFileInfo( dit.current()->file()).exists()) | 580 | if(QFileInfo( dit.current()->file()).exists()) |
580 | d->selectedFiles->addToSelection( **dit ); | 581 | d->selectedFiles->addToSelection( **dit ); |
581 | } | 582 | } |
582 | } | 583 | } |
583 | writeCurrentM3u(); | 584 | writeCurrentM3u(); |
584 | 585 | ||
585 | } | 586 | } |
586 | 587 | ||
587 | break; | 588 | break; |
588 | case 2: { | 589 | case 2: { |
589 | QListIterator<DocLnk> dit( vFiles.children() ); | 590 | QListIterator<DocLnk> dit( vFiles.children() ); |
590 | for ( ; dit.current(); ++dit ) { | 591 | for ( ; dit.current(); ++dit ) { |
591 | if( dit.current()->name() == it->text(0)) { | 592 | if( dit.current()->name() == it->text(0)) { |
592 | if( QFileInfo( dit.current()->file()).exists() ) | 593 | if( QFileInfo( dit.current()->file()).exists() ) |
593 | d->selectedFiles->addToSelection( **dit ); | 594 | d->selectedFiles->addToSelection( **dit ); |
594 | } | 595 | } |
595 | } | 596 | } |
596 | writeCurrentM3u(); | 597 | writeCurrentM3u(); |
597 | 598 | ||
598 | } | 599 | } |
599 | break; | 600 | break; |
600 | case 0: | 601 | case 0: |
601 | break; | 602 | break; |
602 | }; | 603 | }; |
603 | tabWidget->setCurrentPage(0); | 604 | tabWidget->setCurrentPage(0); |
604 | } | 605 | } |
605 | } | 606 | } |
606 | 607 | ||
607 | 608 | ||
608 | void PlayListWidget::tabChanged(QWidget *) { | 609 | void PlayListWidget::tabChanged(QWidget *) { |
609 | 610 | ||
610 | switch ( whichList()) { | 611 | switch ( whichList()) { |
611 | case 0: | 612 | case 0: |
612 | { | 613 | { |
613 | if( !tbDeletePlaylist->isHidden() ) { | 614 | if( !tbDeletePlaylist->isHidden() ) { |
614 | tbDeletePlaylist->hide(); | 615 | tbDeletePlaylist->hide(); |
615 | } | 616 | } |
616 | d->tbRemoveFromList->setEnabled(TRUE); | 617 | d->tbRemoveFromList->setEnabled(TRUE); |
617 | d->tbAddToList->setEnabled(FALSE); | 618 | d->tbAddToList->setEnabled(FALSE); |
618 | } | 619 | } |
619 | break; | 620 | break; |
620 | case 1: | 621 | case 1: |
621 | { | 622 | { |
622 | audioView->clear(); | 623 | audioView->clear(); |
623 | populateAudioView(); | 624 | populateAudioView(); |
624 | 625 | ||
625 | if( !tbDeletePlaylist->isHidden() ) { | 626 | if( !tbDeletePlaylist->isHidden() ) { |
626 | tbDeletePlaylist->hide(); | 627 | tbDeletePlaylist->hide(); |
627 | } | 628 | } |
628 | d->tbRemoveFromList->setEnabled(FALSE); | 629 | d->tbRemoveFromList->setEnabled(FALSE); |
629 | d->tbAddToList->setEnabled(TRUE); | 630 | d->tbAddToList->setEnabled(TRUE); |
630 | } | 631 | } |
631 | break; | 632 | break; |
632 | case 2: | 633 | case 2: |
633 | { | 634 | { |
634 | videoView->clear(); | 635 | videoView->clear(); |
635 | populateVideoView(); | 636 | populateVideoView(); |
636 | if( !tbDeletePlaylist->isHidden() ) { | 637 | if( !tbDeletePlaylist->isHidden() ) { |
637 | tbDeletePlaylist->hide(); | 638 | tbDeletePlaylist->hide(); |
638 | } | 639 | } |
639 | d->tbRemoveFromList->setEnabled(FALSE); | 640 | d->tbRemoveFromList->setEnabled(FALSE); |
640 | d->tbAddToList->setEnabled(TRUE); | 641 | d->tbAddToList->setEnabled(TRUE); |
641 | } | 642 | } |
642 | break; | 643 | break; |
643 | case 3: | 644 | case 3: |
644 | { | 645 | { |
645 | if( tbDeletePlaylist->isHidden() ) { | 646 | if( tbDeletePlaylist->isHidden() ) { |
646 | tbDeletePlaylist->show(); | 647 | tbDeletePlaylist->show(); |
647 | } | 648 | } |
648 | playLists->reread(); | 649 | playLists->reread(); |
649 | } | 650 | } |
650 | break; | 651 | break; |
651 | }; | 652 | }; |
652 | } | 653 | } |
653 | 654 | ||
654 | 655 | ||
655 | void PlayListWidget::btnPlay(bool b) { | 656 | void PlayListWidget::btnPlay(bool b) { |
656 | // mediaPlayerState->setPlaying(false); | 657 | // mediaPlayerState->setPlaying(false); |
657 | mediaPlayerState->setPlaying(b); | 658 | mediaPlayerState->setPlaying(b); |
658 | insanityBool=FALSE; | 659 | insanityBool=FALSE; |
659 | } | 660 | } |
660 | 661 | ||
661 | void PlayListWidget::deletePlaylist() { | 662 | void PlayListWidget::deletePlaylist() { |
662 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), | 663 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), |
663 | (tr("You really want to delete\nthis playlist?")), | 664 | (tr("You really want to delete\nthis playlist?")), |
664 | (tr("Yes")), (tr("No")), 0 )){ | 665 | (tr("Yes")), (tr("No")), 0 )){ |
665 | case 0: // Yes clicked, | 666 | case 0: // Yes clicked, |
666 | QFile().remove(playLists->selectedDocument().file()); | 667 | QFile().remove(playLists->selectedDocument().file()); |
667 | QFile().remove(playLists->selectedDocument().linkFile()); | 668 | QFile().remove(playLists->selectedDocument().linkFile()); |
668 | playLists->reread(); | 669 | playLists->reread(); |
669 | break; | 670 | break; |
670 | case 1: // Cancel | 671 | case 1: // Cancel |
671 | break; | 672 | break; |
672 | }; | 673 | }; |
673 | } | 674 | } |
674 | 675 | ||
675 | 676 | ||
676 | void PlayListWidget::playSelected() { | 677 | void PlayListWidget::playSelected() { |
677 | btnPlay( TRUE); | 678 | btnPlay( TRUE); |
678 | } | 679 | } |
679 | 680 | ||
680 | 681 | ||
681 | void PlayListWidget::scanForAudio() { | 682 | void PlayListWidget::scanForAudio() { |
682 | // qDebug("scan for audio"); | 683 | // qDebug("scan for audio"); |
683 | files.detachChildren(); | 684 | files.detachChildren(); |
684 | QListIterator<DocLnk> sdit( files.children() ); | 685 | QListIterator<DocLnk> sdit( files.children() ); |
685 | for ( ; sdit.current(); ++sdit ) { | 686 | for ( ; sdit.current(); ++sdit ) { |
686 | delete sdit.current(); | 687 | delete sdit.current(); |
687 | } | 688 | } |
688 | // Global::findDocuments( &files, "audio/*"); | 689 | // Global::findDocuments( &files, "audio/*"); |
689 | Global::findDocuments( &files, "audio/mpeg;audio/x-wav;audio/x-ogg"); | 690 | Global::findDocuments( &files, "audio/mpeg;audio/x-wav;audio/x-ogg"); |
690 | audioScan = TRUE; | 691 | audioScan = TRUE; |
691 | } | 692 | } |
692 | 693 | ||
693 | void PlayListWidget::scanForVideo() { | 694 | void PlayListWidget::scanForVideo() { |
694 | // qDebug("scan for video"); | 695 | // qDebug("scan for video"); |
695 | vFiles.detachChildren(); | 696 | vFiles.detachChildren(); |
696 | QListIterator<DocLnk> sdit( vFiles.children() ); | 697 | QListIterator<DocLnk> sdit( vFiles.children() ); |
697 | for ( ; sdit.current(); ++sdit ) { | 698 | for ( ; sdit.current(); ++sdit ) { |
698 | delete sdit.current(); | 699 | delete sdit.current(); |
699 | } | 700 | } |
700 | Global::findDocuments(&vFiles, "video/*"); | 701 | Global::findDocuments(&vFiles, "video/*"); |
701 | videoScan = TRUE; | 702 | videoScan = TRUE; |
702 | } | 703 | } |
703 | 704 | ||
704 | void PlayListWidget::populateAudioView() { | 705 | void PlayListWidget::populateAudioView() { |
705 | audioView->clear(); | 706 | audioView->clear(); |
706 | StorageInfo storageInfo; | 707 | StorageInfo storageInfo; |
707 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 708 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
708 | if(!audioScan) { | 709 | if(!audioScan) { |
709 | scanForAudio(); | 710 | scanForAudio(); |
710 | } | 711 | } |
711 | 712 | ||
712 | QListIterator<DocLnk> dit( files.children() ); | 713 | QListIterator<DocLnk> dit( files.children() ); |
713 | QListIterator<FileSystem> it ( fs ); | 714 | QListIterator<FileSystem> it ( fs ); |
714 | 715 | ||
715 | QString storage; | 716 | QString storage; |
716 | for ( ; dit.current(); ++dit ) { | 717 | for ( ; dit.current(); ++dit ) { |
717 | for( ; it.current(); ++it ){ | 718 | for( ; it.current(); ++it ){ |
718 | const QString name = (*it)->name(); | 719 | const QString name = (*it)->name(); |
719 | const QString path = (*it)->path(); | 720 | const QString path = (*it)->path(); |
720 | if(dit.current()->file().find(path) != -1 ) { | 721 | if(dit.current()->file().find(path) != -1 ) { |
721 | storage = name; | 722 | storage = name; |
722 | } | 723 | } |
723 | } | 724 | } |
724 | 725 | ||
725 | QListViewItem * newItem; | 726 | QListViewItem * newItem; |
726 | if ( QFile( dit.current()->file()).exists() || | 727 | if ( QFile( dit.current()->file()).exists() || |
727 | dit.current()->file().left(4) == "http" ) { | 728 | dit.current()->file().left(4) == "http" ) { |
728 | long size; | 729 | long size; |
729 | if( dit.current()->file().left(4) == "http" ) | 730 | if( dit.current()->file().left(4) == "http" ) |
730 | size=0; | 731 | size=0; |
731 | else | 732 | else |
732 | size = QFile( dit.current()->file() ).size(); | 733 | size = QFile( dit.current()->file() ).size(); |
733 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), | 734 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), |
734 | QString::number(size ), storage, dit.current()->file()); | 735 | QString::number(size ), storage, dit.current()->file()); |
735 | newItem->setPixmap( 0, Resource::loadPixmap( "opieplayer2/musicfile" ) ); | 736 | newItem->setPixmap( 0, Resource::loadPixmap( "opieplayer2/musicfile" ) ); |
736 | } | 737 | } |
737 | } | 738 | } |
738 | } | 739 | } |
739 | 740 | ||
740 | 741 | ||
741 | void PlayListWidget::populateVideoView() { | 742 | void PlayListWidget::populateVideoView() { |
742 | videoView->clear(); | 743 | videoView->clear(); |
743 | StorageInfo storageInfo; | 744 | StorageInfo storageInfo; |
744 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 745 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
745 | 746 | ||
746 | if(!videoScan ) { | 747 | if(!videoScan ) { |
747 | scanForVideo(); | 748 | scanForVideo(); |
748 | } | 749 | } |
749 | 750 | ||
750 | QListIterator<DocLnk> Vdit( vFiles.children() ); | 751 | QListIterator<DocLnk> Vdit( vFiles.children() ); |
751 | QListIterator<FileSystem> it ( fs ); | 752 | QListIterator<FileSystem> it ( fs ); |
752 | videoView->clear(); | 753 | videoView->clear(); |
753 | QString storage, pathName; | 754 | QString storage, pathName; |
754 | for ( ; Vdit.current(); ++Vdit ) { | 755 | for ( ; Vdit.current(); ++Vdit ) { |
755 | for( ; it.current(); ++it ) { | 756 | for( ; it.current(); ++it ) { |
756 | const QString name = (*it)->name(); | 757 | const QString name = (*it)->name(); |
757 | const QString path = (*it)->path(); | 758 | const QString path = (*it)->path(); |
758 | if( Vdit.current()->file().find(path) != -1 ) { | 759 | if( Vdit.current()->file().find(path) != -1 ) { |
759 | storage=name; | 760 | storage=name; |
760 | pathName=path; | 761 | pathName=path; |
761 | } | 762 | } |
762 | } | 763 | } |
763 | 764 | ||
764 | QListViewItem * newItem; | 765 | QListViewItem * newItem; |
765 | if ( QFile( Vdit.current()->file() ).exists() ) { | 766 | if ( QFile( Vdit.current()->file() ).exists() ) { |
766 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), | 767 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), |
767 | QString::number( QFile( Vdit.current()->file() ).size() ), | 768 | QString::number( QFile( Vdit.current()->file() ).size() ), |
768 | storage, Vdit.current()->file()); | 769 | storage, Vdit.current()->file()); |
769 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer2/videofile" ) ); | 770 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer2/videofile" ) ); |
770 | } | 771 | } |
771 | } | 772 | } |
772 | } | 773 | } |
773 | 774 | ||
774 | 775 | ||
775 | void PlayListWidget::openFile() { | 776 | void PlayListWidget::openFile() { |
776 | QString filename, name; | 777 | QString filename, name; |
777 | InputDialog *fileDlg; | 778 | InputDialog *fileDlg; |
778 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); | 779 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); |
779 | fileDlg->exec(); | 780 | fileDlg->exec(); |
780 | if( fileDlg->result() == 1 ) { | 781 | if( fileDlg->result() == 1 ) { |
781 | filename = fileDlg->text(); | 782 | filename = fileDlg->text(); |
782 | 783 | ||
783 | qDebug( "Selected filename is " + filename ); | 784 | qDebug( "Selected filename is " + filename ); |
784 | 785 | ||
785 | if(filename.left(4) == "http") { //if http, lets write a new m3u | 786 | if(filename.left(4) == "http") { //if http, lets write a new m3u |
786 | Om3u *m3uList; | 787 | Om3u *m3uList; |
787 | DocLnk lnk; | 788 | DocLnk lnk; |
788 | QString m3uFile, m3uFilePath; | 789 | QString m3uFile, m3uFilePath; |
789 | 790 | ||
790 | if(filename.find(":",8,TRUE) != -1) { //found a port | 791 | if(filename.find(":",8,TRUE) != -1) { //found a port |
791 | m3uFile = filename.left( filename.find( ":",8,TRUE)); | 792 | m3uFile = filename.left( filename.find( ":",8,TRUE)); |
792 | m3uFile = m3uFile.right( 7); | 793 | m3uFile = m3uFile.right( 7); |
793 | } else if(filename.left(4) == "http"){ | 794 | } else if(filename.left(4) == "http"){ |
794 | m3uFile=filename; | 795 | m3uFile=filename; |
795 | m3uFile = m3uFile.right( m3uFile.length() - 7); | 796 | m3uFile = m3uFile.right( m3uFile.length() - 7); |
796 | } else{ | 797 | } else{ |
797 | m3uFile=filename; | 798 | m3uFile=filename; |
798 | } | 799 | } |
799 | // qDebug( m3uFile); | 800 | // qDebug( m3uFile); |
800 | 801 | ||
801 | //this is where this new m3u is going to live at | 802 | //this is where this new m3u is going to live at |
802 | m3uFilePath = QDir::homeDirPath() + "/" + m3uFile + ".m3u"; | 803 | m3uFilePath = QDir::homeDirPath() + "/" + m3uFile + ".m3u"; |
803 | // m3uFile += ".m3u"; | 804 | // m3uFile += ".m3u"; |
804 | m3uList = new Om3u( m3uFile+".m3u", IO_ReadWrite ); | 805 | m3uList = new Om3u( m3uFile+".m3u", IO_ReadWrite ); |
805 | m3uList->add( filename); | 806 | m3uList->add( filename); |
806 | m3uList->write(); | 807 | m3uList->write(); |
807 | if(m3uList) delete m3uList; | 808 | if(m3uList) delete m3uList; |
808 | // qDebug( m3uFile); | 809 | // qDebug( m3uFile); |
809 | lnk.setName( filename ); //sets file name | 810 | lnk.setName( filename ); //sets file name |
810 | lnk.setFile( m3uFilePath ); //sets File property | 811 | lnk.setFile( m3uFilePath ); //sets File property |
811 | lnk.setType( MimeType( QFile::encodeName(m3uFilePath) ).id() ); | 812 | lnk.setType( MimeType( QFile::encodeName(m3uFilePath) ).id() ); |
812 | 813 | ||
813 | lnk.setExec( "opieplayer2" ); | 814 | lnk.setExec( "opieplayer2" ); |
814 | lnk.setIcon("opieplayer2/playlist2"); | 815 | lnk.setIcon("opieplayer2/playlist2"); |
815 | 816 | ||
816 | if( !lnk.writeLink() ) { | 817 | if( !lnk.writeLink() ) { |
817 | qDebug( "Writing doclink did not work" ); | 818 | qDebug( "Writing doclink did not work" ); |
818 | } | 819 | } |
819 | d->selectedFiles->addToSelection( lnk ); | 820 | d->selectedFiles->addToSelection( lnk ); |
820 | 821 | ||
821 | } | 822 | } |
822 | else if( filename.right( 3 ) == "m3u" ) { | 823 | else if( filename.right( 3 ) == "m3u" ) { |
823 | readm3u( filename ); | 824 | readm3u( filename ); |
824 | 825 | ||
825 | } else if( filename.right(3) == "pls" ) { | 826 | } else if( filename.right(3) == "pls" ) { |
826 | readPls( filename ); | 827 | readPls( filename ); |
827 | } | 828 | } |
828 | } | 829 | } |
829 | if( fileDlg ) { | 830 | if( fileDlg ) { |
830 | delete fileDlg; | 831 | delete fileDlg; |
831 | } | 832 | } |
832 | } | 833 | } |
833 | 834 | ||
834 | /* | 835 | /* |
835 | reads m3u and adds files/urls to playlist */ | 836 | reads m3u and adds files/urls to playlist */ |
836 | void PlayListWidget::readm3u( const QString &filename ) { | 837 | void PlayListWidget::readm3u( const QString &filename ) { |
837 | qDebug( "read m3u filename " + filename ); | 838 | qDebug( "read m3u filename " + filename ); |
838 | 839 | ||
839 | Om3u *m3uList; | 840 | Om3u *m3uList; |
840 | QString s, name; | 841 | QString s, name; |
841 | m3uList = new Om3u( filename, IO_ReadOnly ); | 842 | m3uList = new Om3u( filename, IO_ReadOnly ); |
842 | m3uList->readM3u(); | 843 | m3uList->readM3u(); |
843 | DocLnk lnk; | 844 | DocLnk lnk; |
844 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | 845 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { |
845 | s = *it; | 846 | s = *it; |
846 | s.replace( QRegExp( "%20" )," " ); | 847 | s.replace( QRegExp( "%20" )," " ); |
847 | // qDebug("reading "+ s); | 848 | // qDebug("reading "+ s); |
848 | 849 | ||
849 | if( QFileInfo( s ).exists() ) { | 850 | if( QFileInfo( s ).exists() ) { |
850 | lnk.setName( QFileInfo(s).baseName()); | 851 | lnk.setName( QFileInfo(s).baseName()); |
851 | // qDebug("set link "+s); | 852 | // qDebug("set link "+s); |
852 | if(s.at(s.length()-4) == '.') //if regular file | 853 | if(s.at(s.length()-4) == '.') //if regular file |
853 | lnk.setFile( s); | 854 | lnk.setFile( s); |
854 | else | 855 | else |
855 | lnk.setFile( s+"/"); //if url with no extension | 856 | lnk.setFile( s+"/"); //if url with no extension |
856 | 857 | ||
857 | d->selectedFiles->addToSelection( lnk ); | 858 | d->selectedFiles->addToSelection( lnk ); |
858 | } | 859 | } |
859 | } | 860 | } |
860 | Config config( "OpiePlayer" ); | 861 | Config config( "OpiePlayer" ); |
861 | config.setGroup( "PlayList" ); | 862 | config.setGroup( "PlayList" ); |
862 | 863 | ||
863 | config.writeEntry("CurrentPlaylist",filename); | 864 | config.writeEntry("CurrentPlaylist",filename); |
864 | config.write(); | 865 | config.write(); |
865 | currentPlayList=filename; | 866 | currentPlayList=filename; |
866 | 867 | ||
867 | m3uList->close(); | 868 | m3uList->close(); |
868 | if(m3uList) delete m3uList; | 869 | if(m3uList) delete m3uList; |
869 | 870 | ||
870 | d->selectedFiles->setSelectedItem( s); | 871 | d->selectedFiles->setSelectedItem( s); |
871 | setCaption(tr("OpiePlayer: ")+ filename); | 872 | setCaption(tr("OpiePlayer: ")+ filename); |
872 | 873 | ||
873 | } | 874 | } |
874 | 875 | ||
875 | /* | 876 | /* |
876 | reads pls and adds files/urls to playlist */ | 877 | reads pls and adds files/urls to playlist */ |
877 | void PlayListWidget::readPls( const QString &filename ) { | 878 | void PlayListWidget::readPls( const QString &filename ) { |
878 | 879 | ||
879 | qDebug( "pls filename is " + filename ); | 880 | qDebug( "pls filename is " + filename ); |
880 | Om3u *m3uList; | 881 | Om3u *m3uList; |
881 | QString s, name; | 882 | QString s, name; |
882 | m3uList = new Om3u( filename, IO_ReadOnly ); | 883 | m3uList = new Om3u( filename, IO_ReadOnly ); |
883 | m3uList->readPls(); | 884 | m3uList->readPls(); |
884 | 885 | ||
885 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | 886 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { |
886 | s = *it; | 887 | s = *it; |
887 | // s.replace( QRegExp( "%20" )," " ); | 888 | // s.replace( QRegExp( "%20" )," " ); |
888 | DocLnk lnk( s ); | 889 | DocLnk lnk( s ); |
889 | QFileInfo f( s ); | 890 | QFileInfo f( s ); |
890 | QString name = f.baseName(); | 891 | QString name = f.baseName(); |
891 | 892 | ||
892 | if( name.left( 4 ) == "http" ) { | 893 | if( name.left( 4 ) == "http" ) { |
893 | name = s.right( s.length() - 7); | 894 | name = s.right( s.length() - 7); |
894 | } else { | 895 | } else { |
895 | name = s; | 896 | name = s; |
896 | } | 897 | } |
897 | 898 | ||
898 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); | 899 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); |
899 | 900 | ||
900 | lnk.setName( name ); | 901 | lnk.setName( name ); |
901 | if( s.at( s.length() - 4) == '.') {// if this is probably a file | 902 | if( s.at( s.length() - 4) == '.') {// if this is probably a file |
902 | lnk.setFile( s ); | 903 | lnk.setFile( s ); |
903 | } else { //if its a url | 904 | } else { //if its a url |
904 | if( name.right( 1 ).find( '/' ) == -1) { | 905 | if( name.right( 1 ).find( '/' ) == -1) { |
905 | s += "/"; | 906 | s += "/"; |
906 | } | 907 | } |
907 | lnk.setFile( s ); | 908 | lnk.setFile( s ); |
908 | } | 909 | } |
909 | lnk.setType( "audio/x-mpegurl" ); | 910 | lnk.setType( "audio/x-mpegurl" ); |
910 | 911 | ||
911 | lnk.writeLink(); | 912 | lnk.writeLink(); |
912 | d->selectedFiles->addToSelection( lnk ); | 913 | d->selectedFiles->addToSelection( lnk ); |
913 | } | 914 | } |
914 | 915 | ||
915 | m3uList->close(); | 916 | m3uList->close(); |
916 | if(m3uList) delete m3uList; | 917 | if(m3uList) delete m3uList; |
917 | } | 918 | } |
918 | 919 | ||
919 | /* | 920 | /* |
920 | writes current playlist to current m3u file */ | 921 | writes current playlist to current m3u file */ |
921 | void PlayListWidget::writeCurrentM3u() { | 922 | void PlayListWidget::writeCurrentM3u() { |
922 | qDebug("writting to current m3u"); | 923 | qDebug("writting to current m3u"); |
923 | Config cfg( "OpiePlayer" ); | 924 | Config cfg( "OpiePlayer" ); |
924 | cfg.setGroup("PlayList"); | 925 | cfg.setGroup("PlayList"); |
925 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | 926 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); |
926 | // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 927 | // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
927 | Om3u *m3uList; | 928 | Om3u *m3uList; |
928 | m3uList = new Om3u( currentPlaylist, IO_ReadWrite ); | 929 | m3uList = new Om3u( currentPlaylist, IO_ReadWrite ); |
929 | d->selectedFiles->first(); | 930 | d->selectedFiles->first(); |
930 | 931 | ||
931 | do { | 932 | do { |
932 | m3uList->add( d->selectedFiles->current()->file()); | 933 | m3uList->add( d->selectedFiles->current()->file()); |
933 | } | 934 | } |
934 | while ( d->selectedFiles->next() ); | 935 | while ( d->selectedFiles->next() ); |
935 | // qDebug( list ); | 936 | // qDebug( list ); |
936 | m3uList->write(); | 937 | m3uList->write(); |
937 | if(m3uList) delete m3uList; | 938 | if(m3uList) delete m3uList; |
938 | } | 939 | } |
939 | 940 | ||
940 | /* | 941 | /* |
941 | writes current playlist to m3u file */ | 942 | writes current playlist to m3u file */ |
942 | void PlayListWidget::writem3u() { | 943 | void PlayListWidget::writem3u() { |
943 | InputDialog *fileDlg; | 944 | InputDialog *fileDlg; |
944 | fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); | 945 | fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); |
945 | fileDlg->exec(); | 946 | fileDlg->exec(); |
946 | QString name, filename, list; | 947 | QString name, filename, list; |
947 | Om3u *m3uList; | 948 | Om3u *m3uList; |
948 | 949 | ||
949 | if( fileDlg->result() == 1 ) { | 950 | if( fileDlg->result() == 1 ) { |
950 | name = fileDlg->text(); | 951 | name = fileDlg->text(); |
951 | qDebug( filename ); | 952 | qDebug( filename ); |
952 | 953 | ||
953 | if( name.left( 1) != "/" ) { | 954 | if( name.left( 1) != "/" ) { |
954 | filename = QPEApplication::documentDir() + "/" + name; | 955 | filename = QPEApplication::documentDir() + "/" + name; |
955 | } | 956 | } |
956 | 957 | ||
957 | if( name.right( 3 ) != "m3u" ) { | 958 | if( name.right( 3 ) != "m3u" ) { |
958 | filename = QPEApplication::documentDir() + "/" +name+".m3u"; | 959 | filename = QPEApplication::documentDir() + "/" +name+".m3u"; |
959 | } | 960 | } |
960 | 961 | ||
961 | m3uList = new Om3u(filename, IO_ReadWrite); | 962 | m3uList = new Om3u(filename, IO_ReadWrite); |
962 | 963 | ||
963 | d->selectedFiles->first(); | 964 | d->selectedFiles->first(); |
964 | 965 | ||
965 | do { | 966 | do { |
966 | m3uList->add( d->selectedFiles->current()->file()); | 967 | m3uList->add( d->selectedFiles->current()->file()); |
967 | } | 968 | } |
968 | while ( d->selectedFiles->next() ); | 969 | while ( d->selectedFiles->next() ); |
969 | // qDebug( list ); | 970 | // qDebug( list ); |
970 | m3uList->write(); | 971 | m3uList->write(); |
971 | } | 972 | } |
972 | if(m3uList) delete m3uList; | 973 | if(m3uList) delete m3uList; |
973 | if(fileDlg) delete fileDlg; | 974 | if(fileDlg) delete fileDlg; |
974 | 975 | ||
975 | DocLnk lnk; | 976 | DocLnk lnk; |
976 | lnk.setFile( filename); | 977 | lnk.setFile( filename); |
977 | lnk.setIcon("opieplayer2/playlist2"); | 978 | lnk.setIcon("opieplayer2/playlist2"); |
978 | lnk.setName( name); //sets file name | 979 | lnk.setName( name); //sets file name |
979 | 980 | ||
980 | // qDebug(filename); | 981 | // qDebug(filename); |
981 | Config config( "OpiePlayer" ); | 982 | Config config( "OpiePlayer" ); |
982 | config.setGroup( "PlayList" ); | 983 | config.setGroup( "PlayList" ); |
983 | 984 | ||
984 | config.writeEntry("CurrentPlaylist",filename); | 985 | config.writeEntry("CurrentPlaylist",filename); |
985 | currentPlayList=filename; | 986 | currentPlayList=filename; |
986 | 987 | ||
987 | if(!lnk.writeLink()) { | 988 | if(!lnk.writeLink()) { |
988 | qDebug("Writing doclink did not work"); | 989 | qDebug("Writing doclink did not work"); |
989 | } | 990 | } |
990 | 991 | ||
991 | setCaption(tr("OpiePlayer: ") + name); | 992 | setCaption(tr("OpiePlayer: ") + name); |
992 | } | 993 | } |
993 | 994 | ||
994 | void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { | 995 | void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { |
995 | switch ( e->key() ) { | 996 | switch ( e->key() ) { |
996 | ////////////////////////////// Zaurus keys | 997 | ////////////////////////////// Zaurus keys |
997 | case Key_F9: //activity | 998 | case Key_F9: //activity |
998 | // if(audioUI->isHidden()) | 999 | // if(audioUI->isHidden()) |
999 | // audioUI->showMaximized(); | 1000 | // audioUI->showMaximized(); |
1000 | break; | 1001 | break; |
1001 | case Key_F10: //contacts | 1002 | case Key_F10: //contacts |
1002 | // if( videoUI->isHidden()) | 1003 | // if( videoUI->isHidden()) |
1003 | // videoUI->showMaximized(); | 1004 | // videoUI->showMaximized(); |
1004 | break; | 1005 | break; |
1005 | case Key_F11: //menu | 1006 | case Key_F11: //menu |
1006 | break; | 1007 | break; |
1007 | case Key_F12: //home | 1008 | case Key_F12: //home |
1008 | // doBlank(); | 1009 | // doBlank(); |
1009 | break; | 1010 | break; |
1010 | case Key_F13: //mail | 1011 | case Key_F13: //mail |
1011 | // doUnblank(); | 1012 | // doUnblank(); |
1012 | break; | 1013 | break; |
1013 | case Key_Q: //add to playlist | 1014 | case Key_Q: //add to playlist |
1014 | addSelected(); | 1015 | addSelected(); |
1015 | break; | 1016 | break; |
1016 | case Key_R: //remove from playlist | 1017 | case Key_R: //remove from playlist |
1017 | removeSelected(); | 1018 | removeSelected(); |
1018 | break; | 1019 | break; |
1019 | // case Key_P: //play | 1020 | // case Key_P: //play |
1020 | // qDebug("Play"); | 1021 | // qDebug("Play"); |
1021 | // playSelected(); | 1022 | // playSelected(); |
1022 | // break; | 1023 | // break; |
1023 | case Key_Space: | 1024 | case Key_Space: |
1024 | // playSelected(); puh | 1025 | // playSelected(); puh |
1025 | break; | 1026 | break; |
1026 | case Key_1: | 1027 | case Key_1: |
1027 | tabWidget->setCurrentPage( 0 ); | 1028 | tabWidget->setCurrentPage( 0 ); |
1028 | break; | 1029 | break; |
1029 | case Key_2: | 1030 | case Key_2: |
1030 | tabWidget->setCurrentPage( 1 ); | 1031 | tabWidget->setCurrentPage( 1 ); |
1031 | break; | 1032 | break; |
1032 | case Key_3: | 1033 | case Key_3: |
1033 | tabWidget->setCurrentPage( 2 ); | 1034 | tabWidget->setCurrentPage( 2 ); |
1034 | break; | 1035 | break; |
1035 | case Key_4: | 1036 | case Key_4: |
1036 | tabWidget->setCurrentPage( 3 ); | 1037 | tabWidget->setCurrentPage( 3 ); |
1037 | break; | 1038 | break; |
1038 | case Key_Down: | 1039 | case Key_Down: |
1039 | if ( !d->selectedFiles->next() ) | 1040 | if ( !d->selectedFiles->next() ) |
1040 | d->selectedFiles->first(); | 1041 | d->selectedFiles->first(); |
1041 | break; | 1042 | break; |
1042 | case Key_Up: | 1043 | case Key_Up: |
1043 | if ( !d->selectedFiles->prev() ) | 1044 | if ( !d->selectedFiles->prev() ) |
1044 | // d->selectedFiles->last(); | 1045 | // d->selectedFiles->last(); |
1045 | break; | 1046 | break; |
1046 | } | 1047 | } |
1047 | } | 1048 | } |
1048 | 1049 | ||
1049 | void PlayListWidget::pmViewActivated(int index) { | 1050 | void PlayListWidget::pmViewActivated(int index) { |
1050 | // qDebug("%d", index); | 1051 | // qDebug("%d", index); |
1051 | switch(index) { | 1052 | switch(index) { |
1052 | case -16: | 1053 | case -16: |
1053 | { | 1054 | { |
1054 | mediaPlayerState->toggleFullscreen(); | 1055 | mediaPlayerState->toggleFullscreen(); |
1055 | bool b=mediaPlayerState->fullscreen(); | 1056 | bool b=mediaPlayerState->fullscreen(); |
1056 | pmView->setItemChecked( index, b); | 1057 | pmView->setItemChecked( index, b); |
1057 | Config cfg( "OpiePlayer" ); | 1058 | Config cfg( "OpiePlayer" ); |
1058 | cfg.writeEntry( "FullScreen", b ); | 1059 | cfg.writeEntry( "FullScreen", b ); |
1059 | } | 1060 | } |
1060 | break; | 1061 | break; |
1061 | }; | 1062 | }; |
1062 | } | 1063 | } |
1063 | 1064 | ||
1064 | void PlayListWidget::populateSkinsMenu() { | 1065 | void PlayListWidget::populateSkinsMenu() { |
1065 | int item = 0; | 1066 | int item = 0; |
1066 | defaultSkinIndex = 0; | 1067 | defaultSkinIndex = 0; |
1067 | QString skinName; | 1068 | QString skinName; |
1068 | Config cfg( "OpiePlayer" ); | 1069 | Config cfg( "OpiePlayer" ); |
1069 | cfg.setGroup("Options" ); | 1070 | cfg.setGroup("Options" ); |
1070 | QString skin = cfg.readEntry( "Skin", "default" ); | 1071 | QString skin = cfg.readEntry( "Skin", "default" ); |
1071 | 1072 | ||
1072 | QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" ); | 1073 | QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" ); |
1073 | skinsDir.setFilter( QDir::Dirs ); | 1074 | skinsDir.setFilter( QDir::Dirs ); |
1074 | skinsDir.setSorting(QDir::Name ); | 1075 | skinsDir.setSorting(QDir::Name ); |
1075 | const QFileInfoList *skinslist = skinsDir.entryInfoList(); | 1076 | const QFileInfoList *skinslist = skinsDir.entryInfoList(); |
1076 | QFileInfoListIterator it( *skinslist ); | 1077 | QFileInfoListIterator it( *skinslist ); |
1077 | QFileInfo *fi; | 1078 | QFileInfo *fi; |
1078 | while ( ( fi = it.current() ) ) { | 1079 | while ( ( fi = it.current() ) ) { |
1079 | skinName = fi->fileName(); | 1080 | skinName = fi->fileName(); |
1080 | // qDebug( fi->fileName() ); | 1081 | // qDebug( fi->fileName() ); |
1081 | if( skinName != "." && skinName != ".." && skinName !="CVS" ) { | 1082 | if( skinName != "." && skinName != ".." && skinName !="CVS" ) { |
1082 | item = skinsMenu->insertItem( fi->fileName() ) ; | 1083 | item = skinsMenu->insertItem( fi->fileName() ) ; |
1083 | } | 1084 | } |
1084 | if( skinName == "default" ) { | 1085 | if( skinName == "default" ) { |
1085 | defaultSkinIndex = item; | 1086 | defaultSkinIndex = item; |
1086 | } | 1087 | } |
1087 | if( skinName == skin ) { | 1088 | if( skinName == skin ) { |
1088 | skinsMenu->setItemChecked( item, TRUE ); | 1089 | skinsMenu->setItemChecked( item, TRUE ); |
1089 | } | 1090 | } |
1090 | ++it; | 1091 | ++it; |
1091 | } | 1092 | } |
1092 | } | 1093 | } |
1093 | 1094 | ||
1094 | void PlayListWidget::skinsMenuActivated( int item ) { | 1095 | void PlayListWidget::skinsMenuActivated( int item ) { |
1095 | for( int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) { | 1096 | for( int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) { |
1096 | skinsMenu->setItemChecked( i, FALSE ); | 1097 | skinsMenu->setItemChecked( i, FALSE ); |
1097 | } | 1098 | } |
1098 | skinsMenu->setItemChecked( item, TRUE ); | 1099 | skinsMenu->setItemChecked( item, TRUE ); |
1099 | 1100 | ||
1100 | Config cfg( "OpiePlayer" ); | 1101 | Config cfg( "OpiePlayer" ); |
1101 | cfg.setGroup("Options"); | 1102 | cfg.setGroup("Options"); |
1102 | cfg.writeEntry("Skin", skinsMenu->text( item ) ); | 1103 | cfg.writeEntry("Skin", skinsMenu->text( item ) ); |
1103 | } | 1104 | } |
1104 | 1105 | ||
1105 | int PlayListWidget::whichList() { | 1106 | int PlayListWidget::whichList() { |
1106 | return tabWidget->currentPageIndex(); | 1107 | return tabWidget->currentPageIndex(); |
1107 | } | 1108 | } |
1108 | 1109 | ||
1109 | QString PlayListWidget::currentFileListPathName() { | 1110 | QString PlayListWidget::currentFileListPathName() { |
1110 | switch (whichList()) { | 1111 | switch (whichList()) { |
1111 | case 1: | 1112 | case 1: |
1112 | return audioView->currentItem()->text(3); | 1113 | return audioView->currentItem()->text(3); |
1113 | break; | 1114 | break; |
1114 | case 2: | 1115 | case 2: |
1115 | return videoView->currentItem()->text(3); | 1116 | return videoView->currentItem()->text(3); |
1116 | break; | 1117 | break; |
1117 | }; | 1118 | }; |
1118 | return ""; | 1119 | return ""; |
1119 | } | 1120 | } |