Diffstat (limited to 'noncore/multimedia/opieplayer2/playlistwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 1348 |
1 files changed, 1348 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp new file mode 100644 index 0000000..0390c99 --- a/dev/null +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp | |||
@@ -0,0 +1,1348 @@ | |||
1 | |||
2 | // code added by L. J. Potter Sat 03-02-2002 06:17:54 | ||
3 | #define QTOPIA_INTERNAL_FSLP | ||
4 | #include <qpe/qcopenvelope_qws.h> | ||
5 | |||
6 | #include <qpe/qpemenubar.h> | ||
7 | #include <qpe/qpetoolbar.h> | ||
8 | #include <qpe/fileselector.h> | ||
9 | #include <qpe/qpeapplication.h> | ||
10 | #include <qpe/lnkproperties.h> | ||
11 | #include <qpe/storage.h> | ||
12 | |||
13 | #include <qpe/applnk.h> | ||
14 | #include <qpe/config.h> | ||
15 | #include <qpe/global.h> | ||
16 | #include <qpe/resource.h> | ||
17 | #include <qaction.h> | ||
18 | #include <qcursor.h> | ||
19 | #include <qimage.h> | ||
20 | #include <qfile.h> | ||
21 | #include <qdir.h> | ||
22 | #include <qlayout.h> | ||
23 | #include <qlabel.h> | ||
24 | #include <qlist.h> | ||
25 | #include <qlistbox.h> | ||
26 | #include <qmainwindow.h> | ||
27 | #include <qmessagebox.h> | ||
28 | #include <qtoolbutton.h> | ||
29 | #include <qtabwidget.h> | ||
30 | #include <qlistview.h> | ||
31 | #include <qpoint.h> | ||
32 | #include <qlineedit.h> | ||
33 | #include <qpushbutton.h> | ||
34 | #include <qregexp.h> | ||
35 | #include <qtextstream.h> | ||
36 | |||
37 | //#include <qtimer.h> | ||
38 | |||
39 | #include "playlistselection.h" | ||
40 | #include "playlistwidget.h" | ||
41 | #include "mediaplayerstate.h" | ||
42 | |||
43 | #include "inputDialog.h" | ||
44 | |||
45 | #include <stdlib.h> | ||
46 | #include "audiowidget.h" | ||
47 | #include "videowidget.h" | ||
48 | |||
49 | #include <unistd.h> | ||
50 | #include <sys/file.h> | ||
51 | #include <sys/ioctl.h> | ||
52 | #include <sys/soundcard.h> | ||
53 | |||
54 | // for setBacklight() | ||
55 | #include <linux/fb.h> | ||
56 | #include <sys/types.h> | ||
57 | #include <sys/stat.h> | ||
58 | #include <stdlib.h> | ||
59 | |||
60 | #define BUTTONS_ON_TOOLBAR | ||
61 | #define SIDE_BUTTONS | ||
62 | #define CAN_SAVE_LOAD_PLAYLISTS | ||
63 | |||
64 | extern AudioWidget *audioUI; | ||
65 | extern VideoWidget *videoUI; | ||
66 | extern MediaPlayerState *mediaPlayerState; | ||
67 | |||
68 | // class myFileSelector { | ||
69 | |||
70 | // }; | ||
71 | class PlayListWidgetPrivate { | ||
72 | public: | ||
73 | QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; | ||
74 | QFrame *playListFrame; | ||
75 | FileSelector *files; | ||
76 | PlayListSelection *selectedFiles; | ||
77 | bool setDocumentUsed; | ||
78 | DocLnk *current; | ||
79 | }; | ||
80 | |||
81 | |||
82 | class ToolButton : public QToolButton { | ||
83 | public: | ||
84 | ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) | ||
85 | : QToolButton( parent, name ) { | ||
86 | setTextLabel( name ); | ||
87 | setPixmap( Resource::loadPixmap( icon ) ); | ||
88 | setAutoRaise( TRUE ); | ||
89 | setFocusPolicy( QWidget::NoFocus ); | ||
90 | setToggleButton( t ); | ||
91 | connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); | ||
92 | QPEMenuToolFocusManager::manager()->addWidget( this ); | ||
93 | } | ||
94 | }; | ||
95 | |||
96 | |||
97 | class MenuItem : public QAction { | ||
98 | public: | ||
99 | MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) | ||
100 | : QAction( text, QString::null, 0, 0 ) { | ||
101 | connect( this, SIGNAL( activated() ), handler, slot ); | ||
102 | addTo( parent ); | ||
103 | } | ||
104 | }; | ||
105 | |||
106 | |||
107 | PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) | ||
108 | : QMainWindow( parent, name, fl ) { | ||
109 | |||
110 | d = new PlayListWidgetPrivate; | ||
111 | d->setDocumentUsed = FALSE; | ||
112 | d->current = NULL; | ||
113 | fromSetDocument = FALSE; | ||
114 | insanityBool=FALSE; | ||
115 | audioScan = FALSE; | ||
116 | videoScan = FALSE; | ||
117 | // menuTimer = new QTimer( this ,"menu timer"), | ||
118 | // connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); | ||
119 | |||
120 | setBackgroundMode( PaletteButton ); | ||
121 | |||
122 | setCaption( tr("OpiePlayer") ); | ||
123 | setIcon( Resource::loadPixmap( "opieplayer/MPEGPlayer" ) ); | ||
124 | |||
125 | setToolBarsMovable( FALSE ); | ||
126 | |||
127 | // Create Toolbar | ||
128 | QPEToolBar *toolbar = new QPEToolBar( this ); | ||
129 | toolbar->setHorizontalStretchable( TRUE ); | ||
130 | |||
131 | // Create Menubar | ||
132 | QPEMenuBar *menu = new QPEMenuBar( toolbar ); | ||
133 | menu->setMargin( 0 ); | ||
134 | |||
135 | QPEToolBar *bar = new QPEToolBar( this ); | ||
136 | bar->setLabel( tr( "Play Operations" ) ); | ||
137 | // d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "opieplayer/play_current_list", | ||
138 | // this , SLOT( addSelected()) ); | ||
139 | tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); | ||
140 | tbDeletePlaylist->setFlat(TRUE); | ||
141 | tbDeletePlaylist->setFixedSize(20,20); | ||
142 | |||
143 | d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "opieplayer/add_to_playlist", | ||
144 | this , SLOT(addSelected()) ); | ||
145 | d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "opieplayer/remove_from_playlist", | ||
146 | this , SLOT(removeSelected()) ); | ||
147 | // d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); | ||
148 | d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", | ||
149 | this , SLOT( btnPlay(bool) ), TRUE ); | ||
150 | d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle", | ||
151 | mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); | ||
152 | d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop", | ||
153 | mediaPlayerState, SLOT(setLooping(bool)), TRUE ); | ||
154 | tbDeletePlaylist->hide(); | ||
155 | |||
156 | QPopupMenu *pmPlayList = new QPopupMenu( this ); | ||
157 | menu->insertItem( tr( "File" ), pmPlayList ); | ||
158 | new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); | ||
159 | new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); | ||
160 | new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); | ||
161 | new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); | ||
162 | pmPlayList->insertSeparator(-1); | ||
163 | new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); | ||
164 | new MenuItem( pmPlayList, tr( "Export playlist to m3u" ), this, SLOT(writem3u() ) ); | ||
165 | pmPlayList->insertSeparator(-1); | ||
166 | new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); | ||
167 | pmPlayList->insertSeparator(-1); | ||
168 | new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) ); | ||
169 | new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) ); | ||
170 | |||
171 | QPopupMenu *pmView = new QPopupMenu( this ); | ||
172 | menu->insertItem( tr( "View" ), pmView ); | ||
173 | |||
174 | fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); | ||
175 | fullScreenButton->addTo(pmView); | ||
176 | scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0); | ||
177 | scaleButton->addTo(pmView); | ||
178 | |||
179 | QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); | ||
180 | QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); | ||
181 | |||
182 | QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); | ||
183 | |||
184 | tabWidget = new QTabWidget( hbox6, "tabWidget" ); | ||
185 | tabWidget->setTabShape(QTabWidget::Triangular); | ||
186 | |||
187 | QWidget *pTab; | ||
188 | pTab = new QWidget( tabWidget, "pTab" ); | ||
189 | // playlistView = new QListView( pTab, "playlistview" ); | ||
190 | // playlistView->setMinimumSize(236,260); | ||
191 | tabWidget->insertTab( pTab,"Playlist"); | ||
192 | |||
193 | |||
194 | // Add the playlist area | ||
195 | |||
196 | QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); | ||
197 | d->playListFrame = vbox3; | ||
198 | d->playListFrame ->setMinimumSize(235,260); | ||
199 | |||
200 | QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); | ||
201 | |||
202 | d->selectedFiles = new PlayListSelection( hbox2); | ||
203 | QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); | ||
204 | |||
205 | QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); | ||
206 | |||
207 | |||
208 | |||
209 | QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch | ||
210 | new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); | ||
211 | new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); | ||
212 | new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); | ||
213 | QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch | ||
214 | |||
215 | QWidget *aTab; | ||
216 | aTab = new QWidget( tabWidget, "aTab" ); | ||
217 | audioView = new QListView( aTab, "Audioview" ); | ||
218 | audioView->setMinimumSize(233,260); | ||
219 | audioView->addColumn( tr("Title"),140); | ||
220 | audioView->addColumn(tr("Size"), -1); | ||
221 | audioView->addColumn(tr("Media"),-1); | ||
222 | audioView->setColumnAlignment(1, Qt::AlignRight); | ||
223 | audioView->setColumnAlignment(2, Qt::AlignRight); | ||
224 | audioView->setAllColumnsShowFocus(TRUE); | ||
225 | |||
226 | audioView->setMultiSelection( TRUE ); | ||
227 | audioView->setSelectionMode( QListView::Extended); | ||
228 | |||
229 | tabWidget->insertTab(aTab,tr("Audio")); | ||
230 | |||
231 | QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); | ||
232 | |||
233 | // audioView | ||
234 | // populateAudioView(); | ||
235 | // videowidget | ||
236 | |||
237 | QWidget *vTab; | ||
238 | vTab = new QWidget( tabWidget, "vTab" ); | ||
239 | videoView = new QListView( vTab, "Videoview" ); | ||
240 | videoView->setMinimumSize(233,260); | ||
241 | |||
242 | videoView->addColumn(tr("Title"),140); | ||
243 | videoView->addColumn(tr("Size"),-1); | ||
244 | videoView->addColumn(tr("Media"),-1); | ||
245 | videoView->setColumnAlignment(1, Qt::AlignRight); | ||
246 | videoView->setColumnAlignment(2, Qt::AlignRight); | ||
247 | videoView->setAllColumnsShowFocus(TRUE); | ||
248 | videoView->setMultiSelection( TRUE ); | ||
249 | videoView->setSelectionMode( QListView::Extended); | ||
250 | |||
251 | QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); | ||
252 | |||
253 | tabWidget->insertTab( vTab,tr("Video")); | ||
254 | // populateVideoView(); | ||
255 | |||
256 | //playlists list | ||
257 | QWidget *LTab; | ||
258 | LTab = new QWidget( tabWidget, "LTab" ); | ||
259 | playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy | ||
260 | playLists->setMinimumSize(233,260); | ||
261 | tabWidget->insertTab(LTab,tr("Lists")); | ||
262 | |||
263 | // connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | ||
264 | |||
265 | // add the library area | ||
266 | |||
267 | // connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), | ||
268 | // this, SLOT( fauxPlay( QListViewItem *) ) ); | ||
269 | // connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), | ||
270 | // this, SLOT( fauxPlay( QListViewItem *)) ); | ||
271 | |||
272 | // connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); | ||
273 | // connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); | ||
274 | |||
275 | connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); | ||
276 | connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); | ||
277 | connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); | ||
278 | connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
279 | this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
280 | |||
281 | connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
282 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
283 | |||
284 | connect( audioView, SIGNAL( returnPressed( QListViewItem *)), | ||
285 | this,SLOT( playIt( QListViewItem *)) ); | ||
286 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | ||
287 | |||
288 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | ||
289 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | ||
290 | connect( videoView, SIGNAL( returnPressed( QListViewItem *)), | ||
291 | this,SLOT( playIt( QListViewItem *)) ); | ||
292 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | ||
293 | |||
294 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); | ||
295 | |||
296 | |||
297 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); | ||
298 | |||
299 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); | ||
300 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); | ||
301 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); | ||
302 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); | ||
303 | |||
304 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); | ||
305 | // connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); | ||
306 | |||
307 | setCentralWidget( vbox5 ); | ||
308 | |||
309 | Config cfg( "OpiePlayer" ); | ||
310 | readConfig( cfg ); | ||
311 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | ||
312 | // qDebug("currentList is "+currentPlaylist); | ||
313 | loadList(DocLnk( currentPlaylist)); | ||
314 | setCaption(tr("OpiePlayer: ")+ currentPlaylist ); | ||
315 | |||
316 | initializeStates(); | ||
317 | } | ||
318 | |||
319 | |||
320 | PlayListWidget::~PlayListWidget() { | ||
321 | Config cfg( "OpiePlayer" ); | ||
322 | writeConfig( cfg ); | ||
323 | |||
324 | |||
325 | if ( d->current ) | ||
326 | delete d->current; | ||
327 | delete d; | ||
328 | } | ||
329 | |||
330 | |||
331 | void PlayListWidget::initializeStates() { | ||
332 | |||
333 | d->tbPlay->setOn( mediaPlayerState->playing() ); | ||
334 | d->tbLoop->setOn( mediaPlayerState->looping() ); | ||
335 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); | ||
336 | // d->tbFull->setOn( mediaPlayerState->fullscreen() ); | ||
337 | // d->tbScale->setOn( mediaPlayerState->scaled() ); | ||
338 | // d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); | ||
339 | // setPlaylist( mediaPlayerState->playlist() ); | ||
340 | setPlaylist( true); | ||
341 | // d->selectedFiles->first(); | ||
342 | |||
343 | } | ||
344 | |||
345 | |||
346 | void PlayListWidget::readConfig( Config& cfg ) { | ||
347 | cfg.setGroup("PlayList"); | ||
348 | QString currentString = cfg.readEntry("current", "" ); | ||
349 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | ||
350 | for ( int i = 0; i < noOfFiles; i++ ) { | ||
351 | QString entryName; | ||
352 | entryName.sprintf( "File%i", i + 1 ); | ||
353 | QString linkFile = cfg.readEntry( entryName ); | ||
354 | DocLnk lnk( linkFile ); | ||
355 | if ( lnk.isValid() ) { | ||
356 | d->selectedFiles->addToSelection( lnk ); | ||
357 | } | ||
358 | } | ||
359 | d->selectedFiles->setSelectedItem( currentString); | ||
360 | // d->selectedFiles->setSelectedItem( (const QString &)currentString); | ||
361 | } | ||
362 | |||
363 | |||
364 | void PlayListWidget::writeConfig( Config& cfg ) const { | ||
365 | |||
366 | d->selectedFiles->writeCurrent( cfg); | ||
367 | cfg.setGroup("PlayList"); | ||
368 | int noOfFiles = 0; | ||
369 | d->selectedFiles->first(); | ||
370 | do { | ||
371 | const DocLnk *lnk = d->selectedFiles->current(); | ||
372 | if ( lnk ) { | ||
373 | QString entryName; | ||
374 | entryName.sprintf( "File%i", noOfFiles + 1 ); | ||
375 | // qDebug(entryName); | ||
376 | cfg.writeEntry( entryName, lnk->linkFile() ); | ||
377 | // if this link does exist, add it so we have the file | ||
378 | // next time... | ||
379 | if ( !QFile::exists( lnk->linkFile() ) ) { | ||
380 | // the way writing lnks doesn't really check for out | ||
381 | // of disk space, but check it anyway. | ||
382 | if ( !lnk->writeLink() ) { | ||
383 | QMessageBox::critical( 0, tr("Out of space"), | ||
384 | tr( "There was a problem saving " | ||
385 | "the playlist.\n" | ||
386 | "Your playlist " | ||
387 | "may be missing some entries\n" | ||
388 | "the next time you start it." ) | ||
389 | ); | ||
390 | } | ||
391 | } | ||
392 | noOfFiles++; | ||
393 | } | ||
394 | } | ||
395 | while ( d->selectedFiles->next() ); | ||
396 | cfg.writeEntry("NumberOfFiles", noOfFiles ); | ||
397 | } | ||
398 | |||
399 | |||
400 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { | ||
401 | // qDebug("add"); | ||
402 | // if( lnk.file().find(" ",0,TRUE) != -1 || lnk.file().find("%20",0,TRUE) != -1) { | ||
403 | // QMessageBox::message("Note","You are trying to play\na malformed url."); | ||
404 | |||
405 | // } else { | ||
406 | |||
407 | d->setDocumentUsed = FALSE; | ||
408 | if ( mediaPlayerState->playlist() ) { | ||
409 | if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" ) | ||
410 | d->selectedFiles->addToSelection( lnk ); | ||
411 | } | ||
412 | else | ||
413 | mediaPlayerState->setPlaying( TRUE ); | ||
414 | // } | ||
415 | } | ||
416 | |||
417 | |||
418 | void PlayListWidget::clearList() { | ||
419 | while ( first() ) | ||
420 | d->selectedFiles->removeSelected(); | ||
421 | } | ||
422 | |||
423 | |||
424 | void PlayListWidget::addAllToList() { | ||
425 | DocLnkSet filesAll; | ||
426 | Global::findDocuments(&filesAll, "video/*;audio/*"); | ||
427 | QListIterator<DocLnk> Adit( filesAll.children() ); | ||
428 | for ( ; Adit.current(); ++Adit ) | ||
429 | if(QFileInfo(Adit.current()->file()).exists()) | ||
430 | d->selectedFiles->addToSelection( **Adit ); | ||
431 | } | ||
432 | |||
433 | |||
434 | void PlayListWidget::addAllMusicToList() { | ||
435 | QListIterator<DocLnk> dit( files.children() ); | ||
436 | for ( ; dit.current(); ++dit ) | ||
437 | if(QFileInfo(dit.current()->file()).exists()) | ||
438 | d->selectedFiles->addToSelection( **dit ); | ||
439 | } | ||
440 | |||
441 | |||
442 | void PlayListWidget::addAllVideoToList() { | ||
443 | QListIterator<DocLnk> dit( vFiles.children() ); | ||
444 | for ( ; dit.current(); ++dit ) | ||
445 | if(QFileInfo( dit.current()->file()).exists()) | ||
446 | d->selectedFiles->addToSelection( **dit ); | ||
447 | } | ||
448 | |||
449 | |||
450 | void PlayListWidget::setDocument(const QString& fileref) { | ||
451 | qDebug(fileref); | ||
452 | fromSetDocument = TRUE; | ||
453 | if ( fileref.isNull() ) { | ||
454 | QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); | ||
455 | return; | ||
456 | } | ||
457 | // qDebug("setDocument "+fileref); | ||
458 | if(fileref.find("m3u",0,TRUE) != -1) { //is m3u | ||
459 | readm3u( fileref); | ||
460 | } | ||
461 | else if(fileref.find("pls",0,TRUE) != -1) { //is pls | ||
462 | readPls( fileref); | ||
463 | } | ||
464 | else if(fileref.find("playlist",0,TRUE) != -1) {//is playlist | ||
465 | clearList(); | ||
466 | loadList(DocLnk(fileref)); | ||
467 | d->selectedFiles->first(); | ||
468 | } else { | ||
469 | clearList(); | ||
470 | addToSelection( DocLnk( fileref ) ); | ||
471 | d->setDocumentUsed = TRUE; | ||
472 | mediaPlayerState->setPlaying( FALSE ); | ||
473 | qApp->processEvents(); | ||
474 | mediaPlayerState->setPlaying( TRUE ); | ||
475 | qApp->processEvents(); | ||
476 | setCaption(tr("OpiePlayer")); | ||
477 | } | ||
478 | } | ||
479 | |||
480 | |||
481 | void PlayListWidget::setActiveWindow() { | ||
482 | // When we get raised we need to ensure that it switches views | ||
483 | char origView = mediaPlayerState->view(); | ||
484 | mediaPlayerState->setView( 'l' ); // invalidate | ||
485 | mediaPlayerState->setView( origView ); // now switch back | ||
486 | } | ||
487 | |||
488 | |||
489 | void PlayListWidget::useSelectedDocument() { | ||
490 | d->setDocumentUsed = FALSE; | ||
491 | } | ||
492 | |||
493 | |||
494 | const DocLnk *PlayListWidget::current() { // this is fugly | ||
495 | |||
496 | // if( fromSetDocument) { | ||
497 | // qDebug("from setDoc"); | ||
498 | // DocLnkSet files; | ||
499 | // Global::findDocuments(&files, "video/*;audio/*"); | ||
500 | // QListIterator<DocLnk> dit( files.children() ); | ||
501 | // for ( ; dit.current(); ++dit ) { | ||
502 | // if(dit.current()->linkFile() == setDocFileRef) { | ||
503 | // qDebug(setDocFileRef); | ||
504 | // return dit; | ||
505 | // } | ||
506 | // } | ||
507 | // } else | ||
508 | |||
509 | |||
510 | switch (tabWidget->currentPageIndex()) { | ||
511 | case 0: //playlist | ||
512 | { | ||
513 | qDebug("playlist"); | ||
514 | if ( mediaPlayerState->playlist() ) { | ||
515 | return d->selectedFiles->current(); | ||
516 | } | ||
517 | else if ( d->setDocumentUsed && d->current ) { | ||
518 | return d->current; | ||
519 | } else { | ||
520 | return d->files->selected(); | ||
521 | } | ||
522 | } | ||
523 | break; | ||
524 | case 1://audio | ||
525 | { | ||
526 | qDebug("audioView"); | ||
527 | QListIterator<DocLnk> dit( files.children() ); | ||
528 | for ( ; dit.current(); ++dit ) { | ||
529 | if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { | ||
530 | qDebug("here"); | ||
531 | insanityBool=TRUE; | ||
532 | return dit; | ||
533 | } | ||
534 | } | ||
535 | } | ||
536 | break; | ||
537 | case 2: // video | ||
538 | { | ||
539 | qDebug("videoView"); | ||
540 | QListIterator<DocLnk> Vdit( vFiles.children() ); | ||
541 | for ( ; Vdit.current(); ++Vdit ) { | ||
542 | if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { | ||
543 | insanityBool=TRUE; | ||
544 | return Vdit; | ||
545 | } | ||
546 | } | ||
547 | } | ||
548 | break; | ||
549 | }; | ||
550 | return 0; | ||
551 | } | ||
552 | |||
553 | bool PlayListWidget::prev() { | ||
554 | if ( mediaPlayerState->playlist() ) { | ||
555 | if ( mediaPlayerState->shuffled() ) { | ||
556 | const DocLnk *cur = current(); | ||
557 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); | ||
558 | for ( int i = 0; i < j; i++ ) { | ||
559 | if ( !d->selectedFiles->next() ) | ||
560 | d->selectedFiles->first(); | ||
561 | } | ||
562 | if ( cur == current() ) | ||
563 | if ( !d->selectedFiles->next() ) | ||
564 | d->selectedFiles->first(); | ||
565 | return TRUE; | ||
566 | } else { | ||
567 | if ( !d->selectedFiles->prev() ) { | ||
568 | if ( mediaPlayerState->looping() ) { | ||
569 | return d->selectedFiles->last(); | ||
570 | } else { | ||
571 | return FALSE; | ||
572 | } | ||
573 | } | ||
574 | return TRUE; | ||
575 | } | ||
576 | } else { | ||
577 | return mediaPlayerState->looping(); | ||
578 | } | ||
579 | } | ||
580 | |||
581 | |||
582 | bool PlayListWidget::next() { | ||
583 | if ( mediaPlayerState->playlist() ) { | ||
584 | if ( mediaPlayerState->shuffled() ) { | ||
585 | return prev(); | ||
586 | } else { | ||
587 | if ( !d->selectedFiles->next() ) { | ||
588 | if ( mediaPlayerState->looping() ) { | ||
589 | return d->selectedFiles->first(); | ||
590 | } else { | ||
591 | return FALSE; | ||
592 | } | ||
593 | } | ||
594 | return TRUE; | ||
595 | } | ||
596 | } else { | ||
597 | return mediaPlayerState->looping(); | ||
598 | } | ||
599 | } | ||
600 | |||
601 | |||
602 | bool PlayListWidget::first() { | ||
603 | if ( mediaPlayerState->playlist() ) | ||
604 | return d->selectedFiles->first(); | ||
605 | else | ||
606 | return mediaPlayerState->looping(); | ||
607 | } | ||
608 | |||
609 | |||
610 | bool PlayListWidget::last() { | ||
611 | if ( mediaPlayerState->playlist() ) | ||
612 | return d->selectedFiles->last(); | ||
613 | else | ||
614 | return mediaPlayerState->looping(); | ||
615 | } | ||
616 | |||
617 | |||
618 | void PlayListWidget::saveList() { | ||
619 | |||
620 | QString filename; | ||
621 | InputDialog *fileDlg; | ||
622 | fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0); | ||
623 | fileDlg->exec(); | ||
624 | if( fileDlg->result() == 1 ) { | ||
625 | if ( d->current ) | ||
626 | delete d->current; | ||
627 | filename = fileDlg->LineEdit1->text();//+".playlist"; | ||
628 | // qDebug("saving playlist "+filename+".playlist"); | ||
629 | Config cfg( filename +".playlist"); | ||
630 | writeConfig( cfg ); | ||
631 | |||
632 | DocLnk lnk; | ||
633 | // lnk.setComment( ""); | ||
634 | lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property | ||
635 | lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D | ||
636 | lnk.setIcon("opieplayer/playlist2"); | ||
637 | lnk.setName( filename); //sets file name | ||
638 | // qDebug(filename); | ||
639 | if(!lnk.writeLink()) | ||
640 | qDebug("Writing doclink did not work"); | ||
641 | } | ||
642 | Config config( "OpiePlayer" ); | ||
643 | config.writeEntry("CurrentPlaylist",filename); | ||
644 | setCaption(tr("OpiePlayer: ")+filename); | ||
645 | d->selectedFiles->first(); | ||
646 | if(fileDlg) | ||
647 | delete fileDlg; | ||
648 | } | ||
649 | |||
650 | void PlayListWidget::loadList( const DocLnk & lnk) { | ||
651 | QString name= lnk.name(); | ||
652 | // qDebug("currentList is "+name); | ||
653 | if( name.length()>1) { | ||
654 | setCaption("OpiePlayer: "+name); | ||
655 | // qDebug("load list "+ name+".playlist"); | ||
656 | clearList(); | ||
657 | Config cfg( name+".playlist"); | ||
658 | readConfig(cfg); | ||
659 | |||
660 | tabWidget->setCurrentPage(0); | ||
661 | |||
662 | Config config( "OpiePlayer" ); | ||
663 | config.writeEntry("CurrentPlaylist", name); | ||
664 | // d->selectedFiles->first(); | ||
665 | } | ||
666 | |||
667 | } | ||
668 | |||
669 | void PlayListWidget::setPlaylist( bool shown ) { | ||
670 | if ( shown ) | ||
671 | d->playListFrame->show(); | ||
672 | else | ||
673 | d->playListFrame->hide(); | ||
674 | } | ||
675 | |||
676 | void PlayListWidget::setView( char view ) { | ||
677 | if ( view == 'l' ) | ||
678 | showMaximized(); | ||
679 | else | ||
680 | hide(); | ||
681 | } | ||
682 | |||
683 | void PlayListWidget::addSelected() { | ||
684 | |||
685 | Config cfg( "OpiePlayer" ); | ||
686 | cfg.setGroup("PlayList"); | ||
687 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | ||
688 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | ||
689 | |||
690 | switch (tabWidget->currentPageIndex()) { | ||
691 | case 0: //playlist | ||
692 | break; | ||
693 | case 1: { //audio | ||
694 | // QString entryName; | ||
695 | // entryName.sprintf( "File%i", i + 1 ); | ||
696 | // QString linkFile = cfg.readEntry( entryName ); | ||
697 | QListViewItemIterator it( audioView ); | ||
698 | // iterate through all items of the listview | ||
699 | for ( ; it.current(); ++it ) { | ||
700 | if ( it.current()->isSelected() ) { | ||
701 | QListIterator<DocLnk> dit( files.children() ); | ||
702 | for ( ; dit.current(); ++dit ) { | ||
703 | if( dit.current()->name() == it.current()->text(0) ) { | ||
704 | d->selectedFiles->addToSelection( **dit ); | ||
705 | } | ||
706 | } | ||
707 | audioView->setSelected( it.current(),FALSE); | ||
708 | } | ||
709 | } | ||
710 | tabWidget->setCurrentPage(0); | ||
711 | } | ||
712 | break; | ||
713 | case 2: { // video | ||
714 | QListViewItemIterator it( videoView ); | ||
715 | // iterate through all items of the listview | ||
716 | for ( ; it.current(); ++it ) { | ||
717 | if ( it.current()->isSelected() ) { | ||
718 | QListIterator<DocLnk> dit( vFiles.children() ); | ||
719 | for ( ; dit.current(); ++dit ) { | ||
720 | if( dit.current()->name() == it.current()->text(0) ) { | ||
721 | d->selectedFiles->addToSelection( **dit ); | ||
722 | } | ||
723 | } | ||
724 | |||
725 | videoView->setSelected( it.current(),FALSE); | ||
726 | } | ||
727 | } | ||
728 | // for ( int i = 0; i < noOfFiles; i++ ) { | ||
729 | // QString entryName; | ||
730 | // entryName.sprintf( "File%i", i + 1 ); | ||
731 | // QString linkFile = cfg.readEntry( entryName ); | ||
732 | // if( DocLnk( linkFile).name() == videoView->selectedItem()->text(0) ) { | ||
733 | // int result= QMessageBox::warning(this,tr("OpiePlayer"), | ||
734 | // tr("This is all ready in your playlist.\nContinue?"), | ||
735 | // tr("Yes"),tr("No"),0,0,1); | ||
736 | // if (result !=0) | ||
737 | // return; | ||
738 | // } | ||
739 | // } | ||
740 | // addToSelection( videoView->selectedItem() ); | ||
741 | tabWidget->setCurrentPage(0); | ||
742 | } | ||
743 | break; | ||
744 | }; | ||
745 | } | ||
746 | |||
747 | void PlayListWidget::removeSelected() { | ||
748 | d->selectedFiles->removeSelected( ); | ||
749 | } | ||
750 | |||
751 | void PlayListWidget::playIt( QListViewItem *it) { | ||
752 | // d->setDocumentUsed = FALSE; | ||
753 | // mediaPlayerState->curPosition =0; | ||
754 | qDebug("playIt"); | ||
755 | mediaPlayerState->setPlaying(FALSE); | ||
756 | mediaPlayerState->setPlaying(TRUE); | ||
757 | d->selectedFiles->unSelect(); | ||
758 | } | ||
759 | |||
760 | void PlayListWidget::addToSelection( QListViewItem *it) { | ||
761 | d->setDocumentUsed = FALSE; | ||
762 | |||
763 | if(it) { | ||
764 | switch (tabWidget->currentPageIndex()) { | ||
765 | case 1: { | ||
766 | QListIterator<DocLnk> dit( files.children() ); | ||
767 | for ( ; dit.current(); ++dit ) { | ||
768 | if( dit.current()->name() == it->text(0)) { | ||
769 | d->selectedFiles->addToSelection( **dit ); | ||
770 | } | ||
771 | } | ||
772 | } | ||
773 | break; | ||
774 | case 2: { | ||
775 | QListIterator<DocLnk> dit( vFiles.children() ); | ||
776 | for ( ; dit.current(); ++dit ) { | ||
777 | if( dit.current()->name() == it->text(0)) { | ||
778 | d->selectedFiles->addToSelection( **dit ); | ||
779 | } | ||
780 | } | ||
781 | } | ||
782 | break; | ||
783 | case 0: | ||
784 | break; | ||
785 | }; | ||
786 | tabWidget->setCurrentPage(0); | ||
787 | } | ||
788 | } | ||
789 | |||
790 | void PlayListWidget::tabChanged(QWidget *widg) { | ||
791 | |||
792 | switch ( tabWidget->currentPageIndex()) { | ||
793 | case 0: | ||
794 | { | ||
795 | if( !tbDeletePlaylist->isHidden()) | ||
796 | tbDeletePlaylist->hide(); | ||
797 | d->tbRemoveFromList->setEnabled(TRUE); | ||
798 | d->tbAddToList->setEnabled(FALSE); | ||
799 | } | ||
800 | break; | ||
801 | case 1: | ||
802 | { | ||
803 | audioView->clear(); | ||
804 | populateAudioView(); | ||
805 | |||
806 | if( !tbDeletePlaylist->isHidden()) | ||
807 | tbDeletePlaylist->hide(); | ||
808 | d->tbRemoveFromList->setEnabled(FALSE); | ||
809 | d->tbAddToList->setEnabled(TRUE); | ||
810 | } | ||
811 | break; | ||
812 | case 2: | ||
813 | { | ||
814 | videoView->clear(); | ||
815 | populateVideoView(); | ||
816 | if( !tbDeletePlaylist->isHidden()) | ||
817 | tbDeletePlaylist->hide(); | ||
818 | d->tbRemoveFromList->setEnabled(FALSE); | ||
819 | d->tbAddToList->setEnabled(TRUE); | ||
820 | } | ||
821 | break; | ||
822 | case 3: | ||
823 | { | ||
824 | if( tbDeletePlaylist->isHidden()) | ||
825 | tbDeletePlaylist->show(); | ||
826 | playLists->reread(); | ||
827 | } | ||
828 | break; | ||
829 | }; | ||
830 | } | ||
831 | |||
832 | void PlayListWidget::btnPlay(bool b) { | ||
833 | |||
834 | // mediaPlayerState->setPlaying(b); | ||
835 | switch ( tabWidget->currentPageIndex()) { | ||
836 | case 0: | ||
837 | { | ||
838 | // if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 | ||
839 | // if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) { | ||
840 | // QMessageBox::message("Note","You are trying to play\na malformed url."); | ||
841 | // } else { | ||
842 | mediaPlayerState->setPlaying(b); | ||
843 | // } | ||
844 | } | ||
845 | break; | ||
846 | case 1: | ||
847 | { | ||
848 | addToSelection( audioView->currentItem() ); | ||
849 | mediaPlayerState->setPlaying(b); | ||
850 | d->selectedFiles->removeSelected( ); | ||
851 | tabWidget->setCurrentPage(1); | ||
852 | d->selectedFiles->unSelect(); | ||
853 | insanityBool=FALSE; | ||
854 | }// audioView->clearSelection(); | ||
855 | break; | ||
856 | case 2: | ||
857 | { | ||
858 | addToSelection( videoView->currentItem() ); | ||
859 | mediaPlayerState->setPlaying(b); | ||
860 | qApp->processEvents(); | ||
861 | d->selectedFiles->removeSelected( ); | ||
862 | tabWidget->setCurrentPage(2); | ||
863 | d->selectedFiles->unSelect(); | ||
864 | insanityBool=FALSE; | ||
865 | }// videoView->clearSelection(); | ||
866 | break; | ||
867 | }; | ||
868 | |||
869 | } | ||
870 | |||
871 | void PlayListWidget::deletePlaylist() { | ||
872 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), | ||
873 | (tr("You really want to delete\nthis playlist?")), | ||
874 | (tr("Yes")), (tr("No")), 0 )){ | ||
875 | case 0: // Yes clicked, | ||
876 | QFile().remove(playLists->selected()->file()); | ||
877 | QFile().remove(playLists->selected()->linkFile()); | ||
878 | playLists->reread(); | ||
879 | break; | ||
880 | case 1: // Cancel | ||
881 | break; | ||
882 | }; | ||
883 | } | ||
884 | |||
885 | void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) | ||
886 | { | ||
887 | switch (mouse) { | ||
888 | case 1: | ||
889 | break; | ||
890 | case 2:{ | ||
891 | |||
892 | QPopupMenu m; | ||
893 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); | ||
894 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); | ||
895 | m.insertSeparator(); | ||
896 | if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) | ||
897 | m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); | ||
898 | |||
899 | m.exec( QCursor::pos() ); | ||
900 | } | ||
901 | break; | ||
902 | }; | ||
903 | } | ||
904 | |||
905 | void PlayListWidget::playSelected() | ||
906 | { | ||
907 | btnPlay( TRUE); | ||
908 | // d->selectedFiles->unSelect(); | ||
909 | } | ||
910 | |||
911 | void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) | ||
912 | { | ||
913 | switch (mouse) { | ||
914 | case 1: | ||
915 | |||
916 | break; | ||
917 | case 2:{ | ||
918 | QPopupMenu m; | ||
919 | m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); | ||
920 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); | ||
921 | // m.insertSeparator(); | ||
922 | // m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); | ||
923 | m.exec( QCursor::pos() ); | ||
924 | } | ||
925 | break; | ||
926 | }; | ||
927 | |||
928 | } | ||
929 | |||
930 | void PlayListWidget::listDelete() { | ||
931 | Config cfg( "OpiePlayer" ); | ||
932 | cfg.setGroup("PlayList"); | ||
933 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | ||
934 | QString file; | ||
935 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | ||
936 | switch ( tabWidget->currentPageIndex()) { | ||
937 | case 0: | ||
938 | break; | ||
939 | case 1: | ||
940 | { | ||
941 | file = audioView->selectedItem()->text(0); | ||
942 | // Global::findDocuments(&files, "audio/*"); | ||
943 | // AppLnkSet appFiles; | ||
944 | QListIterator<DocLnk> dit( files.children() ); | ||
945 | for ( ; dit.current(); ++dit ) { | ||
946 | if( dit.current()->name() == file) { | ||
947 | // qDebug(file); | ||
948 | LnkProperties prop( dit.current() ); | ||
949 | // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); | ||
950 | prop.showMaximized(); | ||
951 | prop.exec(); | ||
952 | } | ||
953 | } | ||
954 | populateAudioView(); | ||
955 | } | ||
956 | break; | ||
957 | case 2: | ||
958 | { | ||
959 | // file = videoView->selectedItem()->text(0); | ||
960 | // for ( int i = 0; i < noOfFiles; i++ ) { | ||
961 | // QString entryName; | ||
962 | // entryName.sprintf( "File%i", i + 1 ); | ||
963 | // QString linkFile = cfg.readEntry( entryName ); | ||
964 | // AppLnk lnk( AppLnk(linkFile)); | ||
965 | // if( lnk.name() == file ) { | ||
966 | // LnkProperties prop( &lnk); | ||
967 | // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); | ||
968 | // prop.showMaximized(); | ||
969 | // prop.exec(); | ||
970 | // } | ||
971 | // } | ||
972 | } | ||
973 | break; | ||
974 | }; | ||
975 | } | ||
976 | |||
977 | void PlayListWidget::scanForAudio() { | ||
978 | qDebug("scan for audio"); | ||
979 | files.detachChildren(); | ||
980 | QListIterator<DocLnk> sdit( files.children() ); | ||
981 | for ( ; sdit.current(); ++sdit ) { | ||
982 | delete sdit.current(); | ||
983 | } | ||
984 | Global::findDocuments(&files, "audio/*"); | ||
985 | audioScan = TRUE; | ||
986 | } | ||
987 | void PlayListWidget::scanForVideo() { | ||
988 | qDebug("scan for video"); | ||
989 | vFiles.detachChildren(); | ||
990 | QListIterator<DocLnk> sdit( vFiles.children() ); | ||
991 | for ( ; sdit.current(); ++sdit ) { | ||
992 | delete sdit.current(); | ||
993 | } | ||
994 | Global::findDocuments(&vFiles, "video/*"); | ||
995 | videoScan = TRUE; | ||
996 | } | ||
997 | |||
998 | void PlayListWidget::populateAudioView() { | ||
999 | |||
1000 | audioView->clear(); | ||
1001 | StorageInfo storageInfo; | ||
1002 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | ||
1003 | if(!audioScan) scanForAudio(); | ||
1004 | |||
1005 | QListIterator<DocLnk> dit( files.children() ); | ||
1006 | QListIterator<FileSystem> it ( fs ); | ||
1007 | |||
1008 | QString storage; | ||
1009 | for ( ; dit.current(); ++dit ) { | ||
1010 | for( ; it.current(); ++it ){ | ||
1011 | const QString name = (*it)->name(); | ||
1012 | const QString path = (*it)->path(); | ||
1013 | if(dit.current()->file().find(path) != -1 ) storage=name; | ||
1014 | } | ||
1015 | |||
1016 | QListViewItem * newItem; | ||
1017 | if ( QFile( dit.current()->file()).exists() ) { | ||
1018 | // qDebug(dit.current()->name()); | ||
1019 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), | ||
1020 | QString::number( QFile( dit.current()->file()).size() ), storage); | ||
1021 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); | ||
1022 | } | ||
1023 | } | ||
1024 | |||
1025 | } | ||
1026 | |||
1027 | void PlayListWidget::populateVideoView() { | ||
1028 | videoView->clear(); | ||
1029 | StorageInfo storageInfo; | ||
1030 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | ||
1031 | |||
1032 | if(!videoScan ) scanForVideo(); | ||
1033 | |||
1034 | QListIterator<DocLnk> Vdit( vFiles.children() ); | ||
1035 | QListIterator<FileSystem> it ( fs ); | ||
1036 | videoView->clear(); | ||
1037 | QString storage; | ||
1038 | for ( ; Vdit.current(); ++Vdit ) { | ||
1039 | for( ; it.current(); ++it ){ | ||
1040 | const QString name = (*it)->name(); | ||
1041 | const QString path = (*it)->path(); | ||
1042 | if( Vdit.current()->file().find(path) != -1 ) storage=name; | ||
1043 | } | ||
1044 | |||
1045 | QListViewItem * newItem; | ||
1046 | if ( QFile( Vdit.current()->file()).exists() ) { | ||
1047 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), | ||
1048 | QString::number( QFile( Vdit.current()->file()).size() ), storage); | ||
1049 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); | ||
1050 | } | ||
1051 | } | ||
1052 | } | ||
1053 | |||
1054 | void PlayListWidget::openFile() { | ||
1055 | QString filename, name; | ||
1056 | InputDialog *fileDlg; | ||
1057 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); | ||
1058 | fileDlg->exec(); | ||
1059 | if( fileDlg->result() == 1 ) { | ||
1060 | filename = fileDlg->LineEdit1->text(); | ||
1061 | // http://205.188.234.129:8030 | ||
1062 | // http://66.28.68.70:8000 | ||
1063 | // filename.replace(QRegExp("%20")," "); | ||
1064 | if(filename.find(" ",0,TRUE) != -1 || filename.find("%20",0,TRUE) != -1) { | ||
1065 | QMessageBox::message("Note","Spaces in urls are not allowed."); | ||
1066 | return; | ||
1067 | } else { | ||
1068 | qDebug("Selected filename is "+filename); | ||
1069 | if(filename.right(3) == "m3u") | ||
1070 | readm3u( filename); | ||
1071 | else if(filename.right(3) == "pls") | ||
1072 | readPls( filename); | ||
1073 | else { | ||
1074 | DocLnk lnk; | ||
1075 | |||
1076 | lnk.setName(filename); //sets file name | ||
1077 | if(filename.right(1) != "/" && filename.right(3) != "mp3" && filename.right(3) != "MP3") | ||
1078 | filename += "/"; | ||
1079 | lnk.setFile(filename); //sets File property | ||
1080 | |||
1081 | lnk.setType("audio/x-mpegurl"); | ||
1082 | lnk.setExec("opieplayer"); | ||
1083 | lnk.setIcon("opieplayer/MPEGPlayer"); | ||
1084 | |||
1085 | if(!lnk.writeLink()) | ||
1086 | qDebug("Writing doclink did not work"); | ||
1087 | d->selectedFiles->addToSelection( lnk); | ||
1088 | // if(fileDlg2) | ||
1089 | // delete fileDlg2; | ||
1090 | } | ||
1091 | } | ||
1092 | } | ||
1093 | if(fileDlg) | ||
1094 | delete fileDlg; | ||
1095 | } | ||
1096 | |||
1097 | void PlayListWidget::keyReleaseEvent( QKeyEvent *e) | ||
1098 | { | ||
1099 | switch ( e->key() ) { | ||
1100 | ////////////////////////////// Zaurus keys | ||
1101 | case Key_F9: //activity | ||
1102 | // if(audioUI->isHidden()) | ||
1103 | // audioUI->showMaximized(); | ||
1104 | break; | ||
1105 | case Key_F10: //contacts | ||
1106 | // if( videoUI->isHidden()) | ||
1107 | // videoUI->showMaximized(); | ||
1108 | break; | ||
1109 | case Key_F11: //menu | ||
1110 | break; | ||
1111 | case Key_F12: //home | ||
1112 | // doBlank(); | ||
1113 | break; | ||
1114 | case Key_F13: //mail | ||
1115 | // doUnblank(); | ||
1116 | break; | ||
1117 | case Key_Q: //add to playlist | ||
1118 | qDebug("Add"); | ||
1119 | addSelected(); | ||
1120 | break; | ||
1121 | case Key_R: //remove from playlist | ||
1122 | removeSelected(); | ||
1123 | break; | ||
1124 | // case Key_P: //play | ||
1125 | // qDebug("Play"); | ||
1126 | // playSelected(); | ||
1127 | // break; | ||
1128 | case Key_Space: | ||
1129 | qDebug("Play"); | ||
1130 | // playSelected(); puh | ||
1131 | break; | ||
1132 | case Key_1: | ||
1133 | tabWidget->setCurrentPage(0); | ||
1134 | break; | ||
1135 | case Key_2: | ||
1136 | tabWidget->setCurrentPage(1); | ||
1137 | break; | ||
1138 | case Key_3: | ||
1139 | tabWidget->setCurrentPage(2); | ||
1140 | break; | ||
1141 | case Key_4: | ||
1142 | tabWidget->setCurrentPage(3); | ||
1143 | break; | ||
1144 | case Key_Down: | ||
1145 | if ( !d->selectedFiles->next() ) | ||
1146 | d->selectedFiles->first(); | ||
1147 | |||
1148 | break; | ||
1149 | case Key_Up: | ||
1150 | if ( !d->selectedFiles->prev() ) | ||
1151 | // d->selectedFiles->last(); | ||
1152 | |||
1153 | break; | ||
1154 | |||
1155 | } | ||
1156 | } | ||
1157 | |||
1158 | void PlayListWidget::keyPressEvent( QKeyEvent *e) | ||
1159 | { | ||
1160 | // qDebug("Key press"); | ||
1161 | // switch ( e->key() ) { | ||
1162 | // ////////////////////////////// Zaurus keys | ||
1163 | // case Key_A: //add to playlist | ||
1164 | // qDebug("Add"); | ||
1165 | // addSelected(); | ||
1166 | // break; | ||
1167 | // case Key_R: //remove from playlist | ||
1168 | // removeSelected(); | ||
1169 | // break; | ||
1170 | // case Key_P: //play | ||
1171 | // qDebug("Play"); | ||
1172 | // playSelected(); | ||
1173 | // break; | ||
1174 | // case Key_Space: | ||
1175 | // qDebug("Play"); | ||
1176 | // playSelected(); | ||
1177 | // break; | ||
1178 | // } | ||
1179 | } | ||
1180 | |||
1181 | void PlayListWidget::doBlank() { | ||
1182 | qDebug("do blanking"); | ||
1183 | fd=open("/dev/fb0",O_RDWR); | ||
1184 | if (fd != -1) { | ||
1185 | ioctl(fd,FBIOBLANK,1); | ||
1186 | // close(fd); | ||
1187 | } | ||
1188 | } | ||
1189 | |||
1190 | void PlayListWidget::doUnblank() { | ||
1191 | // this crashes opieplayer with a segfault | ||
1192 | // int fd; | ||
1193 | // fd=open("/dev/fb0",O_RDWR); | ||
1194 | qDebug("do unblanking"); | ||
1195 | if (fd != -1) { | ||
1196 | ioctl(fd,FBIOBLANK,0); | ||
1197 | close(fd); | ||
1198 | } | ||
1199 | QCopEnvelope h("QPE/System", "setBacklight(int)"); | ||
1200 | h <<-3;// v[1]; // -3 Force on | ||
1201 | } | ||
1202 | |||
1203 | void PlayListWidget::readm3u(const QString &filename) { | ||
1204 | |||
1205 | qDebug("m3u filename is "+filename); | ||
1206 | QFile f(filename); | ||
1207 | |||
1208 | if(f.open(IO_ReadOnly)) { | ||
1209 | QTextStream t(&f); | ||
1210 | QString s;//, first, second; | ||
1211 | int i=0; | ||
1212 | while ( !t.atEnd()) { | ||
1213 | // Lview->insertLine(t.readLine(),-1); | ||
1214 | s=t.readLine(); | ||
1215 | if(s.find(" ",0,TRUE) != -1 || s.find("%20",0,TRUE) != -1) { | ||
1216 | QMessageBox::message("Note","Spaces in urls are not allowed."); | ||
1217 | } | ||
1218 | else if(s.find("#",0,TRUE) == -1) { | ||
1219 | if(s.find(" ",0,TRUE) == -1) { // not sure if this is neede since cf uses vfat | ||
1220 | if(s.left(2) == "E:" || s.left(2) == "P:") { | ||
1221 | s=s.right(s.length()-2); | ||
1222 | DocLnk lnk( s ); | ||
1223 | QFileInfo f(s); | ||
1224 | QString name = f.baseName(); | ||
1225 | name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1); | ||
1226 | lnk.setName( name); | ||
1227 | s=s.replace( QRegExp("\\"),"/"); | ||
1228 | lnk.setFile( s); | ||
1229 | lnk.writeLink(); | ||
1230 | // lnk.setIcon(opieplayer/MPEGPlayer); | ||
1231 | qDebug("add "+name); | ||
1232 | d->selectedFiles->addToSelection( lnk); | ||
1233 | } else { // is url | ||
1234 | |||
1235 | s.replace(QRegExp("%20")," "); | ||
1236 | DocLnk lnk( s); | ||
1237 | QString name; | ||
1238 | if(name.left(4)=="http") | ||
1239 | name = s.right( s.length() - 7); | ||
1240 | else | ||
1241 | name=s; | ||
1242 | // name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1); | ||
1243 | lnk.setName(name); | ||
1244 | if(s.at(s.length()-4) == '.') | ||
1245 | lnk.setFile( s); | ||
1246 | else | ||
1247 | lnk.setFile( s+"/"); | ||
1248 | // lnk.setFile( filename); | ||
1249 | // lnk.setComment( s+"/"); | ||
1250 | lnk.setType("audio/x-mpegurl"); | ||
1251 | lnk.writeLink(); | ||
1252 | // lnk.setIcon( "opieplayer/MPEGPlayer"); | ||
1253 | // qDebug("add "+s); | ||
1254 | d->selectedFiles->addToSelection( lnk); | ||
1255 | } | ||
1256 | i++; | ||
1257 | } | ||
1258 | } | ||
1259 | } | ||
1260 | } | ||
1261 | f.close(); | ||
1262 | } | ||
1263 | |||
1264 | void PlayListWidget::writem3u() { | ||
1265 | |||
1266 | InputDialog *fileDlg; | ||
1267 | fileDlg = new InputDialog(this,tr("Save m3u Playlist "),TRUE, 0); | ||
1268 | fileDlg->exec(); | ||
1269 | QString filename,list; | ||
1270 | if( fileDlg->result() == 1 ) { | ||
1271 | filename = fileDlg->LineEdit1->text(); | ||
1272 | qDebug(filename); | ||
1273 | int noOfFiles = 0; | ||
1274 | d->selectedFiles->first(); | ||
1275 | do { | ||
1276 | // we dont check for existance because of url's | ||
1277 | // qDebug(d->selectedFiles->current()->file()); | ||
1278 | list += d->selectedFiles->current()->file()+"\n"; | ||
1279 | noOfFiles++; | ||
1280 | } | ||
1281 | while ( d->selectedFiles->next() ); | ||
1282 | qDebug(list); | ||
1283 | if(filename.left(1) != "/") | ||
1284 | filename=QPEApplication::documentDir()+"/"+filename; | ||
1285 | if(filename.right(3) != "m3u") | ||
1286 | filename=filename+".m3u"; | ||
1287 | |||
1288 | QFile f(filename); | ||
1289 | f.open(IO_WriteOnly); | ||
1290 | f.writeBlock(list, list.length()); | ||
1291 | f.close(); | ||
1292 | } | ||
1293 | if(fileDlg) delete fileDlg; | ||
1294 | } | ||
1295 | |||
1296 | void PlayListWidget::readPls(const QString &filename) { | ||
1297 | |||
1298 | qDebug("pls filename is "+filename); | ||
1299 | QFile f(filename); | ||
1300 | |||
1301 | if(f.open(IO_ReadOnly)) { | ||
1302 | QTextStream t(&f); | ||
1303 | QString s;//, first, second; | ||
1304 | int i=0; | ||
1305 | while ( !t.atEnd()) { | ||
1306 | s=t.readLine(); | ||
1307 | if(s.left(4) == "File") { | ||
1308 | s=s.right(s.length() - 6); | ||
1309 | s.replace(QRegExp("%20")," "); | ||
1310 | qDebug("adding "+s+" to playlist"); | ||
1311 | // numberofentries=2 | ||
1312 | // File1=http | ||
1313 | // Title | ||
1314 | // Length | ||
1315 | // Version | ||
1316 | // File2=http | ||
1317 | |||
1318 | s=s.replace( QRegExp("\\"),"/"); | ||
1319 | DocLnk lnk( s ); | ||
1320 | QFileInfo f(s); | ||
1321 | QString name = f.baseName(); | ||
1322 | if(name.left(4)=="http") | ||
1323 | name = s.right( s.length() - 7); | ||
1324 | else | ||
1325 | name=s; | ||
1326 | name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1); | ||
1327 | // QFileInfo f(s); | ||
1328 | // QString name = f.baseName(); | ||
1329 | // name = name.left(name.length()-4); | ||
1330 | // name = name.right(name.findRev("/",0,TRUE)); | ||
1331 | lnk.setName( name); | ||
1332 | if(s.at(s.length()-4) == '.') // if this is probably a file | ||
1333 | lnk.setFile( s); | ||
1334 | else { //if its a url | ||
1335 | if( name.right(1).find('/') == -1) | ||
1336 | s+="/"; | ||
1337 | lnk.setFile( s); | ||
1338 | } | ||
1339 | lnk.setType("audio/x-mpegurl"); | ||
1340 | |||
1341 | qDebug("DocLnk add "+name); | ||
1342 | d->selectedFiles->addToSelection( lnk); | ||
1343 | } | ||
1344 | } | ||
1345 | i++; | ||
1346 | } | ||
1347 | } | ||
1348 | |||