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