summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2005-03-06 04:52:03 (UTC)
committer llornkcor <llornkcor>2005-03-06 04:52:03 (UTC)
commitb9360499c5f84ab53e080861e0292a70e446f5e4 (patch) (unidiff)
tree97cbc739073f03296bd9dc39b4ada35f1123baad
parent7e44f77d3749db2f43a1313d835a06684ecc1cd6 (diff)
downloadopie-b9360499c5f84ab53e080861e0292a70e446f5e4.zip
opie-b9360499c5f84ab53e080861e0292a70e446f5e4.tar.gz
opie-b9360499c5f84ab53e080861e0292a70e446f5e4.tar.bz2
patches from Paul, human readable sizes and play button #1216
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/playlistfileview.cpp13
-rw-r--r--noncore/multimedia/opieplayer2/playlistfileview.h1
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp56
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.h1
4 files changed, 59 insertions, 12 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistfileview.cpp b/noncore/multimedia/opieplayer2/playlistfileview.cpp
index 3ef4d03..3094876 100644
--- a/noncore/multimedia/opieplayer2/playlistfileview.cpp
+++ b/noncore/multimedia/opieplayer2/playlistfileview.cpp
@@ -1,95 +1,106 @@
1 1
2#include "playlistfileview.h" 2#include "playlistfileview.h"
3 3
4#include <qfile.h> 4#include <qfile.h>
5#include <qpe/global.h> 5#include <qpe/global.h>
6#include <qpe/resource.h> 6#include <qpe/resource.h>
7 7
8PlayListFileView::PlayListFileView( const QString &mimeTypePattern, const QString &itemPixmapName, QWidget *parent, const char *name ) 8PlayListFileView::PlayListFileView( const QString &mimeTypePattern, const QString &itemPixmapName, QWidget *parent, const char *name )
9 : PlayListView( parent, name ), m_mimeTypePattern( mimeTypePattern ), m_itemPixmapName( itemPixmapName ), m_scannedFiles( false ), 9 : PlayListView( parent, name ), m_mimeTypePattern( mimeTypePattern ), m_itemPixmapName( itemPixmapName ), m_scannedFiles( false ),
10 m_viewPopulated( false ) 10 m_viewPopulated( false )
11{ 11{
12 addColumn( tr( "Title" ), 140); 12 addColumn( tr( "Title" ), 140);
13 addColumn( tr( "Size" ), -1 ); 13 addColumn( tr( "Size" ), -1 );
14 addColumn(tr( "Media" ), 0 ); 14 addColumn(tr( "Media" ), 0 );
15 addColumn(tr( "Path" ), -1 ); 15 addColumn(tr( "Path" ), -1 );
16 setColumnAlignment( 1, Qt::AlignRight ); 16 setColumnAlignment( 1, Qt::AlignRight );
17 setColumnAlignment( 2, Qt::AlignRight ); 17 setColumnAlignment( 2, Qt::AlignRight );
18 setAllColumnsShowFocus( TRUE ); 18 setAllColumnsShowFocus( TRUE );
19 setSorting( 3, TRUE ); 19 setSorting( 3, TRUE );
20 setMultiSelection( TRUE ); 20 setMultiSelection( TRUE );
21 setSelectionMode( QListView::Extended ); 21 setSelectionMode( QListView::Extended );
22 22
23 connect( this, SIGNAL( selectionChanged() ), 23 connect( this, SIGNAL( selectionChanged() ),
24 this, SLOT( checkSelection() ) ); 24 this, SLOT( checkSelection() ) );
25} 25}
26 26
27PlayListFileView::~PlayListFileView() 27PlayListFileView::~PlayListFileView()
28{ 28{
29} 29}
30 30
31bool PlayListFileView::hasSelection() const 31bool PlayListFileView::hasSelection() const
32{ 32{
33 for ( QListViewItemIterator it( const_cast<PlayListFileView *>( this ) ); it.current(); ++it ) 33 for ( QListViewItemIterator it( const_cast<PlayListFileView *>( this ) ); it.current(); ++it )
34 if ( it.current()->isSelected() ) 34 if ( it.current()->isSelected() )
35 return true; 35 return true;
36 36
37 return false; 37 return false;
38} 38}
39 39
40void PlayListFileView::scanFiles() 40void PlayListFileView::scanFiles()
41{ 41{
42 m_files.detachChildren(); 42 m_files.detachChildren();
43 QListIterator<DocLnk> sdit( m_files.children() ); 43 QListIterator<DocLnk> sdit( m_files.children() );
44 for ( ; sdit.current(); ++sdit ) 44 for ( ; sdit.current(); ++sdit )
45 delete sdit.current(); 45 delete sdit.current();
46 46
47 Global::findDocuments( &m_files, m_mimeTypePattern ); 47 Global::findDocuments( &m_files, m_mimeTypePattern );
48 48
49 if ( m_viewPopulated ) { 49 if ( m_viewPopulated ) {
50 m_viewPopulated = false; 50 m_viewPopulated = false;
51 populateView(); 51 populateView();
52 } 52 }
53} 53}
54 54
55void PlayListFileView::populateView() 55void PlayListFileView::populateView()
56{ 56{
57 if ( m_viewPopulated ) 57 if ( m_viewPopulated )
58 return; 58 return;
59 59
60 clear(); 60 clear();
61 61
62 if( !m_scannedFiles ) { 62 if( !m_scannedFiles ) {
63 m_viewPopulated = false; // avoid a recursion :) 63 m_viewPopulated = false; // avoid a recursion :)
64 scanFiles(); 64 scanFiles();
65 m_scannedFiles = true; 65 m_scannedFiles = true;
66 } 66 }
67 67
68 m_viewPopulated = true; 68 m_viewPopulated = true;
69 69
70 QString storage; 70 QString storage;
71 QListIterator<DocLnk> dit( m_files.children() ); 71 QListIterator<DocLnk> dit( m_files.children() );
72 for ( ; dit.current(); ++dit ) { 72 for ( ; dit.current(); ++dit ) {
73 73
74 QListViewItem *newItem; 74 QListViewItem *newItem;
75 75
76 if ( QFile::exists( dit.current()->file() ) || 76 if ( QFile::exists( dit.current()->file() ) ||
77 dit.current()->file().left( 4 ) == "http" ) { 77 dit.current()->file().left( 4 ) == "http" ) {
78 78
79 unsigned long size = QFile( dit.current()->file() ).size(); 79 unsigned long size = QFile( dit.current()->file() ).size();
80 QString sizestr;
81 fileSize(size, sizestr);
80 82
81 newItem = new QListViewItem( this, dit.current()->name(), 83 newItem = new QListViewItem( this, dit.current()->name(),
82 QString::number( size ), "" /*storage*/, 84 sizestr, "" /*storage*/,
83 dit.current()->file() ); 85 dit.current()->file() );
84 newItem->setPixmap( 0, Resource::loadPixmap( m_itemPixmapName ) ); 86 newItem->setPixmap( 0, Resource::loadPixmap( m_itemPixmapName ) );
85 } 87 }
86 } 88 }
87} 89}
88 90
89void PlayListFileView::checkSelection() 91void PlayListFileView::checkSelection()
90{ 92{
91 emit itemsSelected( hasSelection() ); 93 emit itemsSelected( hasSelection() );
92} 94}
93 95
96void PlayListFileView::fileSize(unsigned long size, QString &str) {
97 if( size > 1048576 )
98 str.sprintf( "%.0fM", size / 1048576.0 );
99 else if( size > 1024 )
100 str.sprintf( "%.0fK", size / 1024.0 );
101 else
102 str.sprintf( "%d", size );
103}
104
94/* vim: et sw=4 ts=4 105/* vim: et sw=4 ts=4
95 */ 106 */
diff --git a/noncore/multimedia/opieplayer2/playlistfileview.h b/noncore/multimedia/opieplayer2/playlistfileview.h
index 5b15526..d92f258 100644
--- a/noncore/multimedia/opieplayer2/playlistfileview.h
+++ b/noncore/multimedia/opieplayer2/playlistfileview.h
@@ -1,37 +1,38 @@
1#ifndef PLAYLISTFILEVIEW_H 1#ifndef PLAYLISTFILEVIEW_H
2#define PLAYLISTFILEVIEW_H 2#define PLAYLISTFILEVIEW_H
3 3
4#include "playlistview.h" 4#include "playlistview.h"
5 5
6#include <qpe/applnk.h> 6#include <qpe/applnk.h>
7 7
8class PlayListFileView : public PlayListView 8class PlayListFileView : public PlayListView
9{ 9{
10 Q_OBJECT 10 Q_OBJECT
11public: 11public:
12 PlayListFileView( const QString &mimeTypePattern, const QString &itemPixmapName, QWidget *parent, const char *name = 0 ); 12 PlayListFileView( const QString &mimeTypePattern, const QString &itemPixmapName, QWidget *parent, const char *name = 0 );
13 virtual ~PlayListFileView(); 13 virtual ~PlayListFileView();
14 14
15 bool hasSelection() const; 15 bool hasSelection() const;
16 16
17public slots: 17public slots:
18 void scanFiles(); 18 void scanFiles();
19 void populateView(); 19 void populateView();
20 20
21signals: 21signals:
22 void itemsSelected( bool selected ); 22 void itemsSelected( bool selected );
23 23
24private slots: 24private slots:
25 void checkSelection(); 25 void checkSelection();
26 26
27private: 27private:
28 void fileSize(unsigned long size, QString &str);
28 QString m_mimeTypePattern; 29 QString m_mimeTypePattern;
29 QString m_itemPixmapName; 30 QString m_itemPixmapName;
30 DocLnkSet m_files; 31 DocLnkSet m_files;
31 bool m_scannedFiles; 32 bool m_scannedFiles;
32 bool m_viewPopulated; 33 bool m_viewPopulated;
33}; 34};
34 35
35#endif // PLAYLISTFILEVIEW_H 36#endif // PLAYLISTFILEVIEW_H
36/* vim: et sw=4 ts=4 37/* vim: et sw=4 ts=4
37 */ 38 */
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp
index 5f4159c..83eb83b 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.cpp
+++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp
@@ -87,791 +87,825 @@ PlayListWidget::PlayListWidget(QWidget* parent, const char* name, WFlags fl )
87 this,SLOT( openURL() ) ); 87 this,SLOT( openURL() ) );
88 (void)new MenuItem( pmPlayList, tr( "Add Directory"), 88 (void)new MenuItem( pmPlayList, tr( "Add Directory"),
89 this, SLOT(openDirectory())); 89 this, SLOT(openDirectory()));
90 pmPlayList->insertSeparator(-1); 90 pmPlayList->insertSeparator(-1);
91 (void)new MenuItem( pmPlayList, tr( "Save Playlist" ), 91 (void)new MenuItem( pmPlayList, tr( "Save Playlist" ),
92 this, SLOT(writem3u() ) ); 92 this, SLOT(writem3u() ) );
93 pmPlayList->insertSeparator(-1); 93 pmPlayList->insertSeparator(-1);
94 (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), 94 (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ),
95 audioView, SLOT( scanFiles() ) ); 95 audioView, SLOT( scanFiles() ) );
96 (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), 96 (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ),
97 videoView, SLOT( scanFiles() ) ); 97 videoView, SLOT( scanFiles() ) );
98 98
99 pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"), 99 pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"),
100 mediaPlayerState, SLOT( toggleFullscreen() ) ); 100 mediaPlayerState, SLOT( toggleFullscreen() ) );
101 101
102 Config cfg( "OpiePlayer" ); 102 Config cfg( "OpiePlayer" );
103 bool b= cfg.readBoolEntry("FullScreen", 0); 103 bool b= cfg.readBoolEntry("FullScreen", 0);
104 mediaPlayerState->setFullscreen( b ); 104 mediaPlayerState->setFullscreen( b );
105 pmView->setItemChecked( -16, b ); 105 pmView->setItemChecked( -16, b );
106 106
107 (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up", 107 (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up",
108 d->selectedFiles, SLOT(moveSelectedUp() ) ); 108 d->selectedFiles, SLOT(moveSelectedUp() ) );
109 (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut", 109 (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut",
110 d->selectedFiles, SLOT(removeSelected() ) ); 110 d->selectedFiles, SLOT(removeSelected() ) );
111 (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down", 111 (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down",
112 d->selectedFiles, SLOT(moveSelectedDown() ) ); 112 d->selectedFiles, SLOT(moveSelectedDown() ) );
113 QVBox *stretch2 = new QVBox( vbox1 ); 113 QVBox *stretch2 = new QVBox( vbox1 );
114 114
115 connect( tbDeletePlaylist, ( SIGNAL( released() ) ), 115 connect( tbDeletePlaylist, ( SIGNAL( released() ) ),
116 SLOT( deletePlaylist() ) ); 116 SLOT( deletePlaylist() ) );
117 connect( pmView, SIGNAL( activated(int) ), 117 connect( pmView, SIGNAL( activated(int) ),
118 this, SLOT( pmViewActivated(int) ) ); 118 this, SLOT( pmViewActivated(int) ) );
119 connect( skinsMenu, SIGNAL( activated(int) ) , 119 connect( skinsMenu, SIGNAL( activated(int) ) ,
120 this, SLOT( skinsMenuActivated(int) ) ); 120 this, SLOT( skinsMenuActivated(int) ) );
121 connect( d->selectedFiles, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ), 121 connect( d->selectedFiles, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),
122 this,SLOT( playlistViewPressed(int,QListViewItem*,const QPoint&,int) ) ); 122 this,SLOT( playlistViewPressed(int,QListViewItem*,const QPoint&,int) ) );
123 connect( audioView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ), 123 connect( audioView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),
124 this,SLOT( viewPressed(int,QListViewItem*,const QPoint&,int) ) ); 124 this,SLOT( viewPressed(int,QListViewItem*,const QPoint&,int) ) );
125 connect( audioView, SIGNAL( returnPressed(QListViewItem*) ), 125 connect( audioView, SIGNAL( returnPressed(QListViewItem*) ),
126 this,SLOT( playIt(QListViewItem*) ) ); 126 this,SLOT( playIt(QListViewItem*) ) );
127 connect( audioView, SIGNAL( doubleClicked(QListViewItem*) ), 127 connect( audioView, SIGNAL( doubleClicked(QListViewItem*) ),
128 this, SLOT( addToSelection(QListViewItem*) ) ); 128 this, SLOT( addToSelection(QListViewItem*) ) );
129 connect( videoView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ), 129 connect( videoView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),
130 this,SLOT( viewPressed(int,QListViewItem*,const QPoint&,int) ) ); 130 this,SLOT( viewPressed(int,QListViewItem*,const QPoint&,int) ) );
131 connect( videoView, SIGNAL( returnPressed(QListViewItem*) ), 131 connect( videoView, SIGNAL( returnPressed(QListViewItem*) ),
132 this,SLOT( playIt(QListViewItem*) ) ); 132 this,SLOT( playIt(QListViewItem*) ) );
133 connect( videoView, SIGNAL( doubleClicked(QListViewItem*) ), 133 connect( videoView, SIGNAL( doubleClicked(QListViewItem*) ),
134 this, SLOT( addToSelection(QListViewItem*) ) ); 134 this, SLOT( addToSelection(QListViewItem*) ) );
135 connect( playLists, SIGNAL( fileSelected(const DocLnk&) ), 135 connect( playLists, SIGNAL( fileSelected(const DocLnk&) ),
136 this, SLOT( loadList(const DocLnk&) ) ); 136 this, SLOT( loadList(const DocLnk&) ) );
137 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ), 137 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ),
138 this, SLOT( tabChanged(QWidget*) ) ); 138 this, SLOT( tabChanged(QWidget*) ) );
139 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), 139 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ),
140 d->tbPlay, SLOT( setOn(bool) ) ); 140 d->tbPlay, SLOT( setOn(bool) ) );
141 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), 141 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ),
142 d->tbLoop, SLOT( setOn(bool) ) ); 142 d->tbLoop, SLOT( setOn(bool) ) );
143 connect( mediaPlayerState, SIGNAL( shuffledToggled(bool) ), 143 connect( mediaPlayerState, SIGNAL( shuffledToggled(bool) ),
144 d->tbShuffle, SLOT( setOn(bool) ) ); 144 d->tbShuffle, SLOT( setOn(bool) ) );
145 connect( d->selectedFiles, SIGNAL( doubleClicked(QListViewItem*) ), 145 connect( d->selectedFiles, SIGNAL( doubleClicked(QListViewItem*) ),
146 this, SLOT( playIt(QListViewItem*) ) ); 146 this, SLOT( playIt(QListViewItem*) ) );
147 connect ( gammaSlider, SIGNAL( valueChanged(int) ), 147 connect ( gammaSlider, SIGNAL( valueChanged(int) ),
148 mediaPlayerState, SLOT( setVideoGamma(int) ) ); 148 mediaPlayerState, SLOT( setVideoGamma(int) ) );
149 149
150 connect( this, SIGNAL(skinSelected() ), 150 connect( this, SIGNAL(skinSelected() ),
151 m_mp, SLOT( reloadSkins() ) ); 151 m_mp, SLOT( reloadSkins() ) );
152 152
153 // see which skins are installed 153 // see which skins are installed
154 populateSkinsMenu(); 154 populateSkinsMenu();
155 initializeStates(); 155 initializeStates();
156 156
157 channel = new QCopChannel( "QPE/Application/opieplayer2", this ); 157 channel = new QCopChannel( "QPE/Application/opieplayer2", this );
158 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 158 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
159 this, SLOT( qcopReceive(const QCString&,const QByteArray&)) ); 159 this, SLOT( qcopReceive(const QCString&,const QByteArray&)) );
160 160
161 161
162 cfg.setGroup("PlayList"); 162 cfg.setGroup("PlayList");
163 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); 163 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default");
164 loadList(DocLnk( currentPlaylist ) ); 164 loadList(DocLnk( currentPlaylist ) );
165 165
166 tabWidget->showPage( playListTab ); 166 tabWidget->showPage( playListTab );
167} 167}
168 168
169 169
170PlayListWidget::~PlayListWidget() { 170PlayListWidget::~PlayListWidget() {
171 delete d; 171 delete d;
172 delete m_mp; 172 delete m_mp;
173} 173}
174 174
175 175
176void PlayListWidget::initializeStates() { 176void PlayListWidget::initializeStates() {
177 d->tbPlay->setOn( mediaPlayerState->isPlaying() ); 177 d->tbPlay->setOn( mediaPlayerState->isPlaying() );
178 d->tbLoop->setOn( mediaPlayerState->isLooping() ); 178 d->tbLoop->setOn( mediaPlayerState->isLooping() );
179 d->tbShuffle->setOn( mediaPlayerState->isShuffled() ); 179 d->tbShuffle->setOn( mediaPlayerState->isShuffled() );
180 d->playListFrame->show(); 180 d->playListFrame->show();
181} 181}
182 182
183void PlayListWidget::setButtons(void) {
184 bool hasitem;
185
186 switch ( currentTab() ) {
187 case CurrentPlayList:
188 {
189 hasitem = !d->selectedFiles->isEmpty();
190 d->tbPlay->setEnabled( hasitem );
191 d->tbRemoveFromList->setEnabled( hasitem );
192 }
193 break;
194 case AudioFiles:
195 {
196 d->tbPlay->setEnabled( audioView->hasSelection() );
197 d->tbRemoveFromList->setEnabled( false );
198 }
199 break;
200 case VideoFiles:
201 {
202 d->tbPlay->setEnabled( videoView->hasSelection() );
203 d->tbRemoveFromList->setEnabled( false );
204 }
205 break;
206 case PlayLists:
207 {
208 d->tbPlay->setEnabled( false );
209 d->tbRemoveFromList->setEnabled( false );
210 }
211 break;
212 };
213}
214
183void PlayListWidget::writeDefaultPlaylist() { 215void PlayListWidget::writeDefaultPlaylist() {
184 216
185 Config config( "OpiePlayer" ); 217 Config config( "OpiePlayer" );
186 config.setGroup( "PlayList" ); 218 config.setGroup( "PlayList" );
187 QString filename=QPEApplication::documentDir() + "/default.m3u"; 219 QString filename=QPEApplication::documentDir() + "/default.m3u";
188 QString currentString = config.readEntry( "CurrentPlaylist", filename); 220 QString currentString = config.readEntry( "CurrentPlaylist", filename);
189 if( currentString == filename) { 221 if( currentString == filename) {
190 Om3u *m3uList; 222 Om3u *m3uList;
191 if( d->selectedFiles->first() ) { 223 if( d->selectedFiles->first() ) {
192 m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); 224 m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate);
193 do { 225 do {
194 m3uList->add( d->selectedFiles->current()->file() ); 226 m3uList->add( d->selectedFiles->current()->file() );
195 } 227 }
196 while ( d->selectedFiles->next() ); 228 while ( d->selectedFiles->next() );
197 229
198 m3uList->write(); 230 m3uList->write();
199 m3uList->close(); 231 m3uList->close();
200 delete m3uList; 232 delete m3uList;
201 233
202 } 234 }
203 } 235 }
204} 236}
205 237
206void PlayListWidget::addToSelection( const DocLnk& lnk ) { 238void PlayListWidget::addToSelection( const DocLnk& lnk ) {
207 d->setDocumentUsed = FALSE; 239 d->setDocumentUsed = FALSE;
208 if( QFileInfo( lnk.file() ).exists() || 240 if( QFileInfo( lnk.file() ).exists() ||
209 lnk.file().left(4) == "http" ) { 241 lnk.file().left(4) == "http" ) {
210 d->selectedFiles->addToSelection( lnk ); 242 d->selectedFiles->addToSelection( lnk );
211 } 243 }
212} 244}
213 245
214 246
215void PlayListWidget::clearList() { 247void PlayListWidget::clearList() {
216 while ( first() ) { 248 while ( first() ) {
217 d->selectedFiles->removeSelected(); 249 d->selectedFiles->removeSelected();
218 } 250 }
219 Config cfg( "OpiePlayer" ); 251 Config cfg( "OpiePlayer" );
220 cfg.setGroup("PlayList"); 252 cfg.setGroup("PlayList");
221 cfg.writeEntry("CurrentPlaylist","default"); 253 cfg.writeEntry("CurrentPlaylist","default");
222 setCaption("OpiePlayer"); 254 setCaption("OpiePlayer");
255 setButtons();
223} 256}
224 257
225void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) { 258void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) {
226 switch (mouse) { 259 switch (mouse) {
227 case LeftButton: 260 case LeftButton:
228 break; 261 break;
229 case RightButton: 262 case RightButton:
230 { 263 {
231 QPopupMenu m; 264 QPopupMenu m;
232 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); 265 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() ));
233 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); 266 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() ));
234 m.exec( QCursor::pos() ); 267 m.exec( QCursor::pos() );
235 } 268 }
236 break; 269 break;
237 } 270 }
238} 271}
239 272
240 273
241void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) { 274void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) {
242 switch (mouse) { 275 switch (mouse) {
243 case LeftButton: 276 case LeftButton:
244 break; 277 break;
245 case RightButton: 278 case RightButton:
246 { 279 {
247 QPopupMenu m; 280 QPopupMenu m;
248 m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); 281 m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
249 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); 282 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
250 m.exec( QCursor::pos() ); 283 m.exec( QCursor::pos() );
251 } 284 }
252 break; 285 break;
253 } 286 }
254} 287}
255 288
256 289
257void PlayListWidget::addAllToList() { 290void PlayListWidget::addAllToList() {
258 291
259 292
260 audioView->populateView(); 293 audioView->populateView();
261 294
262 QListViewItemIterator audioIt( audioView ); 295 QListViewItemIterator audioIt( audioView );
263 DocLnk lnk; 296 DocLnk lnk;
264 QString filename; 297 QString filename;
265 // iterate through all items of the listview 298 // iterate through all items of the listview
266 for ( ; audioIt.current(); ++audioIt ) { 299 for ( ; audioIt.current(); ++audioIt ) {
267 filename = audioIt.current()->text(3); 300 filename = audioIt.current()->text(3);
268 lnk.setName( QFileInfo(filename).baseName() ); //sets name 301 lnk.setName( QFileInfo(filename).baseName() ); //sets name
269 lnk.setFile( filename ); //sets file name 302 lnk.setFile( filename ); //sets file name
270 d->selectedFiles->addToSelection( lnk); 303 d->selectedFiles->addToSelection( lnk);
271 } 304 }
272 305
273 videoView->populateView(); 306 videoView->populateView();
274 307
275 QListViewItemIterator videoIt( videoView ); 308 QListViewItemIterator videoIt( videoView );
276 for ( ; videoIt.current(); ++videoIt ) { 309 for ( ; videoIt.current(); ++videoIt ) {
277 filename = videoIt.current()->text(3); 310 filename = videoIt.current()->text(3);
278 lnk.setName( QFileInfo(filename).baseName() ); //sets name 311 lnk.setName( QFileInfo(filename).baseName() ); //sets name
279 lnk.setFile( filename ); //sets file name 312 lnk.setFile( filename ); //sets file name
280 d->selectedFiles->addToSelection( lnk); 313 d->selectedFiles->addToSelection( lnk);
281 } 314 }
282 315
283 tabWidget->setCurrentPage(0); 316 tabWidget->setCurrentPage(0);
284 317
285 writeCurrentM3u(); 318 writeCurrentM3u();
286 d->selectedFiles->first(); 319 d->selectedFiles->first();
320
321 setButtons();
287} 322}
288 323
289 324
290void PlayListWidget::addAllMusicToList() { 325void PlayListWidget::addAllMusicToList() {
291 326
292 audioView->populateView(); 327 audioView->populateView();
293 328
294 QListViewItemIterator audioIt( audioView ); 329 QListViewItemIterator audioIt( audioView );
295 DocLnk lnk; 330 DocLnk lnk;
296 QString filename; 331 QString filename;
297 // iterate through all items of the listview 332 // iterate through all items of the listview
298 for ( ; audioIt.current(); ++audioIt ) { 333 for ( ; audioIt.current(); ++audioIt ) {
299 filename = audioIt.current()->text(3); 334 filename = audioIt.current()->text(3);
300 lnk.setName( QFileInfo(filename).baseName() ); //sets name 335 lnk.setName( QFileInfo(filename).baseName() ); //sets name
301 lnk.setFile( filename ); //sets file name 336 lnk.setFile( filename ); //sets file name
302 d->selectedFiles->addToSelection( lnk); 337 d->selectedFiles->addToSelection( lnk);
303 } 338 }
304 339
305 tabWidget->setCurrentPage(0); 340 tabWidget->setCurrentPage(0);
306 writeCurrentM3u(); 341 writeCurrentM3u();
307 d->selectedFiles->first(); 342 d->selectedFiles->first();
343
344 setButtons();
308} 345}
309 346
310 347
311void PlayListWidget::addAllVideoToList() { 348void PlayListWidget::addAllVideoToList() {
312 349
313 videoView->populateView(); 350 videoView->populateView();
314 351
315 QListViewItemIterator videoIt( videoView ); 352 QListViewItemIterator videoIt( videoView );
316 DocLnk lnk; 353 DocLnk lnk;
317 QString filename; 354 QString filename;
318 for ( ; videoIt.current(); ++videoIt ) { 355 for ( ; videoIt.current(); ++videoIt ) {
319 filename = videoIt.current()->text(3); 356 filename = videoIt.current()->text(3);
320 lnk.setName( QFileInfo(filename).baseName() ); //sets name 357 lnk.setName( QFileInfo(filename).baseName() ); //sets name
321 lnk.setFile( filename ); //sets file name 358 lnk.setFile( filename ); //sets file name
322 d->selectedFiles->addToSelection( lnk); 359 d->selectedFiles->addToSelection( lnk);
323 } 360 }
324 tabWidget->setCurrentPage(0); 361 tabWidget->setCurrentPage(0);
325 writeCurrentM3u(); 362 writeCurrentM3u();
326 d->selectedFiles->first(); 363 d->selectedFiles->first();
364
365 setButtons();
327} 366}
328 367
329 368
330void PlayListWidget::setDocument( const QString& _fileref ) { 369void PlayListWidget::setDocument( const QString& _fileref ) {
331 // odebug << "<<<<<<<<set document>>>>>>>>>> "+fileref << oendl; 370 // odebug << "<<<<<<<<set document>>>>>>>>>> "+fileref << oendl;
332 QString fileref = _fileref; 371 QString fileref = _fileref;
333 fromSetDocument = TRUE; 372 fromSetDocument = TRUE;
334 373
335 DocLnk lnk(_fileref); 374 DocLnk lnk(_fileref);
336 if(lnk.isValid()) 375 if(lnk.isValid())
337 fileref = lnk.file(); 376 fileref = lnk.file();
338 377
339 QFileInfo fileInfo(fileref); 378 QFileInfo fileInfo(fileref);
340 379
341 if ( !fileInfo.exists() ) { 380 if ( !fileInfo.exists() ) {
342 QMessageBox::warning( this, tr( "Invalid File" ), 381 QMessageBox::warning( this, tr( "Invalid File" ),
343 tr( "There was a problem in getting the file." ) ); 382 tr( "There was a problem in getting the file." ) );
344 return; 383 return;
345 } 384 }
346 385
347 clearList(); 386 clearList();
348 QString extension = fileInfo.extension(false); 387 QString extension = fileInfo.extension(false);
349 388
350 if( extension.find( "m3u", 0, false) != -1 389 if( extension.find( "m3u", 0, false) != -1
351 || extension.find( "pls", 0, false) != -1 ) { 390 || extension.find( "pls", 0, false) != -1 ) {
352 readListFromFile( fileref ); 391 readListFromFile( fileref );
353 } else { 392 } else {
354 clearList(); 393 clearList();
355 DocLnk lnk; 394 DocLnk lnk;
356 lnk.setName( fileInfo.baseName() ); //sets name 395 lnk.setName( fileInfo.baseName() ); //sets name
357 lnk.setFile( fileref ); //sets file name 396 lnk.setFile( fileref ); //sets file name
358 addToSelection( lnk ); 397 addToSelection( lnk );
359 writeCurrentM3u(); 398 writeCurrentM3u();
360 399
361 d->setDocumentUsed = TRUE; 400 d->setDocumentUsed = TRUE;
362 mediaPlayerState->setPlaying( FALSE ); 401 mediaPlayerState->setPlaying( FALSE );
363 mediaPlayerState->setPlaying( TRUE ); 402 mediaPlayerState->setPlaying( TRUE );
364 } 403 }
365} 404}
366 405
367 406
368void PlayListWidget::useSelectedDocument() { 407void PlayListWidget::useSelectedDocument() {
369 d->setDocumentUsed = FALSE; 408 d->setDocumentUsed = FALSE;
370} 409}
371 410
372 411
373const DocLnk *PlayListWidget::current() const { // this is fugly 412const DocLnk *PlayListWidget::current() const { // this is fugly
374 assert( currentTab() == CurrentPlayList ); 413 assert( currentTab() == CurrentPlayList );
375 414
376 const DocLnk *lnk = d->selectedFiles->current(); 415 const DocLnk *lnk = d->selectedFiles->current();
377 if ( !lnk ) { 416 if ( !lnk ) {
378 d->selectedFiles->first(); 417 d->selectedFiles->first();
379 lnk = d->selectedFiles->current(); 418 lnk = d->selectedFiles->current();
380 } 419 }
381 assert( lnk ); 420 assert( lnk );
382 return lnk; 421 return lnk;
383} 422}
384 423
385 424
386bool PlayListWidget::prev() { 425bool PlayListWidget::prev() {
387 if ( mediaPlayerState->isShuffled() ) { 426 if ( mediaPlayerState->isShuffled() ) {
388 const DocLnk *cur = current(); 427 const DocLnk *cur = current();
389 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 428 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
390 for ( int i = 0; i < j; i++ ) { 429 for ( int i = 0; i < j; i++ ) {
391 if ( !d->selectedFiles->next() ) 430 if ( !d->selectedFiles->next() )
392 d->selectedFiles->first(); 431 d->selectedFiles->first();
393 } 432 }
394 if ( cur == current() ) 433 if ( cur == current() )
395 if ( !d->selectedFiles->next() ) { 434 if ( !d->selectedFiles->next() ) {
396 d->selectedFiles->first(); 435 d->selectedFiles->first();
397 } 436 }
398 return TRUE; 437 return TRUE;
399 } else { 438 } else {
400 if ( !d->selectedFiles->prev() ) { 439 if ( !d->selectedFiles->prev() ) {
401 if ( mediaPlayerState->isLooping() ) { 440 if ( mediaPlayerState->isLooping() ) {
402 return d->selectedFiles->last(); 441 return d->selectedFiles->last();
403 } else { 442 } else {
404 return FALSE; 443 return FALSE;
405 } 444 }
406 } 445 }
407 return TRUE; 446 return TRUE;
408 } 447 }
409} 448}
410 449
411 450
412bool PlayListWidget::next() { 451bool PlayListWidget::next() {
413//odebug << "<<<<<<<<<<<<next()" << oendl; 452//odebug << "<<<<<<<<<<<<next()" << oendl;
414 if ( mediaPlayerState->isShuffled() ) { 453 if ( mediaPlayerState->isShuffled() ) {
415 return prev(); 454 return prev();
416 } else { 455 } else {
417 if ( !d->selectedFiles->next() ) { 456 if ( !d->selectedFiles->next() ) {
418 if ( mediaPlayerState->isLooping() ) { 457 if ( mediaPlayerState->isLooping() ) {
419 return d->selectedFiles->first(); 458 return d->selectedFiles->first();
420 } else { 459 } else {
421 return FALSE; 460 return FALSE;
422 } 461 }
423 } 462 }
424 return TRUE; 463 return TRUE;
425 } 464 }
426} 465}
427 466
428 467
429bool PlayListWidget::first() { 468bool PlayListWidget::first() {
430 return d->selectedFiles->first(); 469 return d->selectedFiles->first();
431} 470}
432 471
433 472
434bool PlayListWidget::last() { 473bool PlayListWidget::last() {
435 return d->selectedFiles->last(); 474 return d->selectedFiles->last();
436} 475}
437 476
438 477
439 void PlayListWidget::saveList() { 478 void PlayListWidget::saveList() {
440 writem3u(); 479 writem3u();
441 } 480 }
442 481
443 482
444void PlayListWidget::loadList( const DocLnk & lnk) { 483void PlayListWidget::loadList( const DocLnk & lnk) {
445 QString name = lnk.name(); 484 QString name = lnk.name();
446 485
447 if( name.length()>0) { 486 if( name.length()>0) {
448 setCaption("OpiePlayer: "+name); 487 setCaption("OpiePlayer: "+name);
449 clearList(); 488 clearList();
450 readListFromFile(lnk.file()); 489 readListFromFile(lnk.file());
451 tabWidget->setCurrentPage(0); 490 tabWidget->setCurrentPage(0);
452 } 491 }
453} 492}
454 493
455void PlayListWidget::addSelected() { 494void PlayListWidget::addSelected() {
456 assert( inFileListMode() ); 495 assert( inFileListMode() );
457 496
458 QListViewItemIterator it( currentFileListView ); 497 QListViewItemIterator it( currentFileListView );
459 for ( ; it.current(); ++it ) 498 for ( ; it.current(); ++it )
460 if ( it.current()->isSelected() ) { 499 if ( it.current()->isSelected() ) {
461 QString filename = it.current()->text(3); 500 QString filename = it.current()->text(3);
462 501
463 DocLnk lnk; 502 DocLnk lnk;
464 lnk.setName( QFileInfo( filename ).baseName() ); //sets name 503 lnk.setName( QFileInfo( filename ).baseName() ); //sets name
465 lnk.setFile( filename ); //sets file name 504 lnk.setFile( filename ); //sets file name
466 505
467 d->selectedFiles->addToSelection( lnk ); 506 d->selectedFiles->addToSelection( lnk );
468 } 507 }
469 508
470 currentFileListView->clearSelection(); 509 currentFileListView->clearSelection();
471 510
472 writeCurrentM3u(); 511 writeCurrentM3u();
473} 512}
474 513
475 514
476void PlayListWidget::removeSelected() { 515void PlayListWidget::removeSelected() {
477 d->selectedFiles->removeSelected( ); 516 d->selectedFiles->removeSelected( );
478 writeCurrentM3u(); 517 writeCurrentM3u();
518 setButtons();
479} 519}
480 520
481 521
482void PlayListWidget::playIt( QListViewItem *it) { 522void PlayListWidget::playIt( QListViewItem *it) {
483 if(!it) return; 523 if(!it) return;
484 mediaPlayerState->setPlaying(FALSE); 524 mediaPlayerState->setPlaying(FALSE);
485 mediaPlayerState->setPlaying(TRUE); 525 mediaPlayerState->setPlaying(TRUE);
486 d->selectedFiles->unSelect(); 526 d->selectedFiles->unSelect();
487} 527}
488 528
489 529
490void PlayListWidget::addToSelection( QListViewItem *it) { 530void PlayListWidget::addToSelection( QListViewItem *it) {
491 d->setDocumentUsed = FALSE; 531 d->setDocumentUsed = FALSE;
492 532
493 if(it) { 533 if(it) {
494 if ( currentTab() == CurrentPlayList ) 534 if ( currentTab() == CurrentPlayList )
495 return; 535 return;
496 DocLnk lnk; 536 DocLnk lnk;
497 QString filename; 537 QString filename;
498 538
499 filename=it->text(3); 539 filename=it->text(3);
500 lnk.setName( QFileInfo(filename).baseName() ); //sets name 540 lnk.setName( QFileInfo(filename).baseName() ); //sets name
501 lnk.setFile( filename ); //sets file name 541 lnk.setFile( filename ); //sets file name
502 d->selectedFiles->addToSelection( lnk); 542 d->selectedFiles->addToSelection( lnk);
503 543
504 writeCurrentM3u(); 544 writeCurrentM3u();
505// tabWidget->setCurrentPage(0); 545// tabWidget->setCurrentPage(0);
506 546
507 } 547 }
508} 548}
509 549
510 550
511void PlayListWidget::tabChanged(QWidget *) { 551void PlayListWidget::tabChanged(QWidget *) {
512 552
513 d->tbPlay->setEnabled( true );
514
515 disconnect( audioView, SIGNAL( itemsSelected(bool) ), 553 disconnect( audioView, SIGNAL( itemsSelected(bool) ),
516 d->tbPlay, SLOT( setEnabled(bool) ) ); 554 d->tbPlay, SLOT( setEnabled(bool) ) );
517 disconnect( videoView, SIGNAL( itemsSelected(bool) ), 555 disconnect( videoView, SIGNAL( itemsSelected(bool) ),
518 d->tbPlay, SLOT( setEnabled(bool) ) ); 556 d->tbPlay, SLOT( setEnabled(bool) ) );
519 557
520 currentFileListView = 0; 558 currentFileListView = 0;
521 559
522 switch ( currentTab() ) { 560 switch ( currentTab() ) {
523 case CurrentPlayList: 561 case CurrentPlayList:
524 { 562 {
525 if( !tbDeletePlaylist->isHidden() ) { 563 if( !tbDeletePlaylist->isHidden() ) {
526 tbDeletePlaylist->hide(); 564 tbDeletePlaylist->hide();
527 } 565 }
528 d->tbRemoveFromList->setEnabled(TRUE);
529 d->tbAddToList->setEnabled(FALSE); 566 d->tbAddToList->setEnabled(FALSE);
530 567
531 d->tbPlay->setEnabled( !d->selectedFiles->isEmpty() );
532 } 568 }
533 break; 569 break;
534 case AudioFiles: 570 case AudioFiles:
535 { 571 {
536 audioView->populateView(); 572 audioView->populateView();
537 573
538 if( !tbDeletePlaylist->isHidden() ) { 574 if( !tbDeletePlaylist->isHidden() ) {
539 tbDeletePlaylist->hide(); 575 tbDeletePlaylist->hide();
540 } 576 }
541 d->tbRemoveFromList->setEnabled(FALSE);
542 d->tbAddToList->setEnabled(TRUE); 577 d->tbAddToList->setEnabled(TRUE);
543 578
544 connect( audioView, SIGNAL( itemsSelected(bool) ), 579 connect( audioView, SIGNAL( itemsSelected(bool) ),
545 d->tbPlay, SLOT( setEnabled(bool) ) ); 580 d->tbPlay, SLOT( setEnabled(bool) ) );
546 581
547 d->tbPlay->setEnabled( audioView->hasSelection() );
548
549 currentFileListView = audioView; 582 currentFileListView = audioView;
550 } 583 }
551 break; 584 break;
552 case VideoFiles: 585 case VideoFiles:
553 { 586 {
554 videoView->populateView(); 587 videoView->populateView();
555 if( !tbDeletePlaylist->isHidden() ) { 588 if( !tbDeletePlaylist->isHidden() ) {
556 tbDeletePlaylist->hide(); 589 tbDeletePlaylist->hide();
557 } 590 }
558 d->tbRemoveFromList->setEnabled(FALSE);
559 d->tbAddToList->setEnabled(TRUE); 591 d->tbAddToList->setEnabled(TRUE);
560 592
561 connect( videoView, SIGNAL( itemsSelected(bool) ), 593 connect( videoView, SIGNAL( itemsSelected(bool) ),
562 d->tbPlay, SLOT( setEnabled(bool) ) ); 594 d->tbPlay, SLOT( setEnabled(bool) ) );
563 595
564 d->tbPlay->setEnabled( videoView->hasSelection() );
565
566 currentFileListView = videoView; 596 currentFileListView = videoView;
567 } 597 }
568 break; 598 break;
569 case PlayLists: 599 case PlayLists:
570 { 600 {
571 if( tbDeletePlaylist->isHidden() ) { 601 if( tbDeletePlaylist->isHidden() ) {
572 tbDeletePlaylist->show(); 602 tbDeletePlaylist->show();
573 } 603 }
574 playLists->reread(); 604 playLists->reread();
575 d->tbAddToList->setEnabled(FALSE); 605 d->tbAddToList->setEnabled(FALSE);
576 606
577 d->tbPlay->setEnabled( false );
578 } 607 }
579 break; 608 break;
580 }; 609 };
610
611 setButtons();
581} 612}
582 613
583 614
584void PlayListWidget::btnPlay(bool b) { 615void PlayListWidget::btnPlay(bool b) {
585// mediaPlayerState->setPlaying(false); 616// mediaPlayerState->setPlaying(false);
586 mediaPlayerState->setPlaying(b); 617 mediaPlayerState->setPlaying(b);
587 insanityBool=FALSE; 618 insanityBool=FALSE;
588} 619}
589 620
590void PlayListWidget::deletePlaylist() { 621void PlayListWidget::deletePlaylist() {
591 switch( QMessageBox::information( this, (tr("Remove Playlist?")), 622 switch( QMessageBox::information( this, (tr("Remove Playlist?")),
592 (tr("You really want to delete\nthis playlist?")), 623 (tr("You really want to delete\nthis playlist?")),
593 (tr("Yes")), (tr("No")), 0 )){ 624 (tr("Yes")), (tr("No")), 0 )){
594 case 0: // Yes clicked, 625 case 0: // Yes clicked,
595 QFile().remove(playLists->selectedDocument().file()); 626 QFile().remove(playLists->selectedDocument().file());
596 QFile().remove(playLists->selectedDocument().linkFile()); 627 QFile().remove(playLists->selectedDocument().linkFile());
597 playLists->reread(); 628 playLists->reread();
598 break; 629 break;
599 case 1: // Cancel 630 case 1: // Cancel
600 break; 631 break;
601 }; 632 };
602} 633}
603 634
604 635
605void PlayListWidget::playSelected() { 636void PlayListWidget::playSelected() {
606 btnPlay( TRUE); 637 btnPlay( TRUE);
607} 638}
608 639
609bool PlayListWidget::inFileListMode() const 640bool PlayListWidget::inFileListMode() const
610{ 641{
611 TabType tab = currentTab(); 642 TabType tab = currentTab();
612 return tab == AudioFiles || tab == VideoFiles; 643 return tab == AudioFiles || tab == VideoFiles;
613} 644}
614 645
615void PlayListWidget::openURL() { 646void PlayListWidget::openURL() {
616 // http://66.28.164.33:2080 647 // http://66.28.164.33:2080
617 // http://somafm.com/star0242.m3u 648 // http://somafm.com/star0242.m3u
618 QString filename, name; 649 QString filename, name;
619 InputDialog *fileDlg; 650 InputDialog *fileDlg;
620 fileDlg = new InputDialog(this,tr("Add URL"),TRUE, 0); 651 fileDlg = new InputDialog(this,tr("Add URL"),TRUE, 0);
621 fileDlg->exec(); 652 fileDlg->exec();
622 if( fileDlg->result() == 1 ) { 653 if( fileDlg->result() == 1 ) {
623 filename = fileDlg->text(); 654 filename = fileDlg->text();
624 odebug << "Selected filename is " + filename << oendl; 655 odebug << "Selected filename is " + filename << oendl;
625 // Om3u *m3uList; 656 // Om3u *m3uList;
626 DocLnk lnk; 657 DocLnk lnk;
627 Config cfg( "OpiePlayer" ); 658 Config cfg( "OpiePlayer" );
628 cfg.setGroup("PlayList"); 659 cfg.setGroup("PlayList");
629 660
630 if(filename.left(4) == "http") { 661 if(filename.left(4) == "http") {
631 QString m3uFile, m3uFilePath; 662 QString m3uFile, m3uFilePath;
632 if(filename.find(":",8,TRUE) != -1) { //found a port 663 if(filename.find(":",8,TRUE) != -1) { //found a port
633 m3uFile = filename.left( filename.find( ":",8,TRUE)); 664 m3uFile = filename.left( filename.find( ":",8,TRUE));
634 m3uFile = m3uFile.right( 7); 665 m3uFile = m3uFile.right( 7);
635 } else if(filename.left(4) == "http"){ 666 } else if(filename.left(4) == "http"){
636 m3uFile=filename; 667 m3uFile=filename;
637 m3uFile = m3uFile.right( m3uFile.length() - 7); 668 m3uFile = m3uFile.right( m3uFile.length() - 7);
638 } else{ 669 } else{
639 m3uFile=filename; 670 m3uFile=filename;
640 } 671 }
641 672
642 lnk.setName( filename ); //sets name 673 lnk.setName( filename ); //sets name
643 lnk.setFile( filename ); //sets file name 674 lnk.setFile( filename ); //sets file name
644 675
645// lnk.setIcon("opieplayer2/musicfile"); 676// lnk.setIcon("opieplayer2/musicfile");
646 677
647 d->selectedFiles->addToSelection( lnk ); 678 d->selectedFiles->addToSelection( lnk );
648 writeCurrentM3u(); 679 writeCurrentM3u();
649 d->selectedFiles->setSelectedItem( lnk.name()); 680 d->selectedFiles->setSelectedItem( lnk.name());
650 } 681 }
651 else if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) { 682 else if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) {
652 readListFromFile( filename ); 683 readListFromFile( filename );
653 } else { 684 } else {
654 lnk.setName( QFileInfo(filename).baseName() ); //sets name 685 lnk.setName( QFileInfo(filename).baseName() ); //sets name
655 lnk.setFile( filename ); //sets file name 686 lnk.setFile( filename ); //sets file name
656 d->selectedFiles->addToSelection( lnk); 687 d->selectedFiles->addToSelection( lnk);
657 writeCurrentM3u(); 688 writeCurrentM3u();
658 d->selectedFiles->setSelectedItem( lnk.name()); 689 d->selectedFiles->setSelectedItem( lnk.name());
659 } 690 }
660 } 691 }
661 692
662 693
663 delete fileDlg; 694 delete fileDlg;
664} 695}
665 696
666 697
667static MimeTypes fileSelectorMimeTypes() { 698static MimeTypes fileSelectorMimeTypes() {
668 MimeTypes types; 699 MimeTypes types;
669 QStringList audio, video, all; 700 QStringList audio, video, all;
670 audio << "audio/*"; 701 audio << "audio/*";
671 audio << "playlist/plain"; 702 audio << "playlist/plain";
672 audio << "audio/x-ogg"; 703 audio << "audio/x-ogg";
673 audio << "audio/x-mpegurl"; 704 audio << "audio/x-mpegurl";
674 705
675 video << "video/*"; 706 video << "video/*";
676 video << "playlist/plain"; 707 video << "playlist/plain";
677 708
678 all += audio; 709 all += audio;
679 all += video; 710 all += video;
680 types.insert("All Media Files", all ); 711 types.insert("All Media Files", all );
681 types.insert("Audio", audio ); 712 types.insert("Audio", audio );
682 types.insert("Video", video ); 713 types.insert("Video", video );
683 714
684 return types; 715 return types;
685} 716}
686 717
687void PlayListWidget::openFile() { 718void PlayListWidget::openFile() {
688 719
689 QString filename, name; 720 QString filename, name;
690 721
691 Config cfg( "OpiePlayer" ); 722 Config cfg( "OpiePlayer" );
692 cfg.setGroup("Dialog"); 723 cfg.setGroup("Dialog");
693 MimeTypes types = fileSelectorMimeTypes(); 724 MimeTypes types = fileSelectorMimeTypes();
694 725
695 726
696 QString str = OFileDialog::getOpenFileName( 1, QString::null, 727 QString str = OFileDialog::getOpenFileName( 1, QString::null,
697 QString::null, types, 0, 728 QString::null, types, 0,
698 tr("Add File to Playlist") ); 729 tr("Add File to Playlist") );
699 730
700 if( str.isEmpty() ) 731 if( str.isEmpty() )
701 return; 732 return;
702 733
703 if(str.left(2) == "//") str=str.right(str.length()-1); 734 if(str.left(2) == "//") str=str.right(str.length()-1);
704 735
705 736
706 if( str.right( 3) == "m3u" || str.right(3) == "pls" ) { 737 if( str.right( 3) == "m3u" || str.right(3) == "pls" ) {
707 readListFromFile( str ); 738 readListFromFile( str );
708 } else { 739 } else {
709 QFileInfo info( str ); 740 QFileInfo info( str );
710 DocLnk lnk = addFileToPlaylist( str, info.baseName() ); 741 DocLnk lnk = addFileToPlaylist( str, info.baseName() );
711 d->selectedFiles->setSelectedItem( lnk.name() ); 742 d->selectedFiles->setSelectedItem( lnk.name() );
712 } 743 }
744
745 setButtons();
713} 746}
714 747
715void PlayListWidget::openDirectory() { 748void PlayListWidget::openDirectory() {
716 QString str = OFileDialog::getDirectory( OFileSelector::DirectorySelector, 749 QString str = OFileDialog::getDirectory( OFileSelector::DirectorySelector,
717 QString::null, 0, 750 QString::null, 0,
718 tr( "Add Files from Directory")); 751 tr( "Add Files from Directory"));
719 752
720 if(str.isEmpty() ) 753 if(str.isEmpty() )
721 return; 754 return;
722 755
723 if(str.left(2) == "//") str=str.right(str.length()-1); 756 if(str.left(2) == "//") str=str.right(str.length()-1);
724 QDir dir( str ); 757 QDir dir( str );
725 QStringList lst = dir.entryList(QDir::Files|QDir::Readable); 758 QStringList lst = dir.entryList(QDir::Files|QDir::Readable);
726 759
727 for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { 760 for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
728 QString filename = str + "/" + *it; 761 QString filename = str + "/" + *it;
729 762
730 if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) 763 if( filename.right( 3) == "m3u" || filename.right(3) == "pls" )
731 readListFromFile( filename ); 764 readListFromFile( filename );
732 else { 765 else {
733 addFileToPlaylist( filename, QFileInfo(*it).baseName() ); 766 addFileToPlaylist( filename, QFileInfo(*it).baseName() );
734 } 767 }
735 } 768 }
736} 769}
737 770
738void PlayListWidget::readListFromFile( const QString &filename ) { 771void PlayListWidget::readListFromFile( const QString &filename ) {
739 odebug << "read list filename " + filename << oendl; 772 odebug << "read list filename " + filename << oendl;
740 QFileInfo fi(filename); 773 QFileInfo fi(filename);
741 Om3u *m3uList; 774 Om3u *m3uList;
742 QString s, name; 775 QString s, name;
743 m3uList = new Om3u( filename, IO_ReadOnly ); 776 m3uList = new Om3u( filename, IO_ReadOnly );
744 if(fi.extension(false).find("m3u",0,false) != -1 ) 777 if(fi.extension(false).find("m3u",0,false) != -1 )
745 m3uList->readM3u(); 778 m3uList->readM3u();
746 else if(fi.extension(false).find("pls",0,false) != -1 ) 779 else if(fi.extension(false).find("pls",0,false) != -1 )
747 m3uList->readPls(); 780 m3uList->readPls();
748 781
749 DocLnk lnk; 782 DocLnk lnk;
750 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { 783 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
751 s = *it; 784 s = *it;
752 // odebug << s << oendl; 785 // odebug << s << oendl;
753 if(s.left(4)=="http") { 786 if(s.left(4)=="http") {
754 lnk.setName( s ); //sets file name 787 lnk.setName( s ); //sets file name
755 lnk.setIcon("opieplayer2/musicfile"); 788 lnk.setIcon("opieplayer2/musicfile");
756 lnk.setFile( s ); //sets file name 789 lnk.setFile( s ); //sets file name
757 790
758 } else { //is file 791 } else { //is file
759 lnk.setName( QFileInfo(s).baseName()); 792 lnk.setName( QFileInfo(s).baseName());
760 if(s.left(1) != "/") { 793 if(s.left(1) != "/") {
761 794
762 lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); 795 lnk.setFile( QFileInfo(filename).dirPath()+"/"+s);
763 } else { 796 } else {
764 lnk.setFile( s); 797 lnk.setFile( s);
765 } 798 }
766 } 799 }
767 d->selectedFiles->addToSelection( lnk ); 800 d->selectedFiles->addToSelection( lnk );
768 } 801 }
769 Config config( "OpiePlayer" ); 802 Config config( "OpiePlayer" );
770 config.setGroup( "PlayList" ); 803 config.setGroup( "PlayList" );
771 804
772 config.writeEntry("CurrentPlaylist",filename); 805 config.writeEntry("CurrentPlaylist",filename);
773 config.write(); 806 config.write();
774 currentPlayList=filename; 807 currentPlayList=filename;
775 808
776 m3uList->close(); 809 m3uList->close();
777 delete m3uList; 810 delete m3uList;
778 811
779 d->selectedFiles->setSelectedItem( s); 812 d->selectedFiles->setSelectedItem( s);
780 setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName()); 813 setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName());
781 814
815 setButtons();
782} 816}
783 817
784// writes current playlist to current m3u file */ 818// writes current playlist to current m3u file */
785 void PlayListWidget::writeCurrentM3u() { 819 void PlayListWidget::writeCurrentM3u() {
786 odebug << "writing to current m3u" << oendl; 820 odebug << "writing to current m3u" << oendl;
787 Config cfg( "OpiePlayer" ); 821 Config cfg( "OpiePlayer" );
788 cfg.setGroup("PlayList"); 822 cfg.setGroup("PlayList");
789 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default"); 823 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default");
790 824
791 Om3u *m3uList; 825 Om3u *m3uList;
792 m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); 826 m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate );
793 if( d->selectedFiles->first()) { 827 if( d->selectedFiles->first()) {
794 828
795 do { 829 do {
796 // odebug << "add writeCurrentM3u " +d->selectedFiles->current()->file() << oendl; 830 // odebug << "add writeCurrentM3u " +d->selectedFiles->current()->file() << oendl;
797 m3uList->add( d->selectedFiles->current()->file() ); 831 m3uList->add( d->selectedFiles->current()->file() );
798 } 832 }
799 while ( d->selectedFiles->next() ); 833 while ( d->selectedFiles->next() );
800 // odebug << "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" << oendl; 834 // odebug << "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" << oendl;
801 m3uList->write(); 835 m3uList->write();
802 m3uList->close(); 836 m3uList->close();
803 } 837 }
804 delete m3uList; 838 delete m3uList;
805 839
806 } 840 }
807 841
808 /* 842 /*
809 writes current playlist to m3u file */ 843 writes current playlist to m3u file */
810void PlayListWidget::writem3u() { 844void PlayListWidget::writem3u() {
811 845
812 Config cfg( "OpiePlayer" ); 846 Config cfg( "OpiePlayer" );
813 cfg.setGroup("Dialog"); 847 cfg.setGroup("Dialog");
814 MimeTypes types = fileSelectorMimeTypes(); 848 MimeTypes types = fileSelectorMimeTypes();
815 849
816 QString str = OFileDialog::getOpenFileName( 1, QString::null, 850 QString str = OFileDialog::getOpenFileName( 1, QString::null,
817 QString::null, types, 0, 851 QString::null, types, 0,
818 tr( "Save Playlist" )); 852 tr( "Save Playlist" ));
819 853
820 if(str.left(2) == "//") str=str.right(str.length()-1); 854 if(str.left(2) == "//") str=str.right(str.length()-1);
821 855
822 QString name, filename, list; 856 QString name, filename, list;
823 Om3u *m3uList; 857 Om3u *m3uList;
824 858
825 if( !str.isEmpty() ) { 859 if( !str.isEmpty() ) {
826 name = str; 860 name = str;
827 // name = fileDlg->text(); 861 // name = fileDlg->text();
828// odebug << filename << oendl; 862// odebug << filename << oendl;
829 if( name.find("/",0,true) != -1) {// assume they specify a file path 863 if( name.find("/",0,true) != -1) {// assume they specify a file path
830 filename = name; 864 filename = name;
831 name = name.right(name.length()- name.findRev("/",-1,true) - 1 ); 865 name = name.right(name.length()- name.findRev("/",-1,true) - 1 );
832 } 866 }
833 else //otherwise dump it somewhere noticable 867 else //otherwise dump it somewhere noticable
834 filename = QPEApplication::documentDir() + "/" + name; 868 filename = QPEApplication::documentDir() + "/" + name;
835 869
836 if( filename.right( 3 ) != "m3u" ) //needs filename extension 870 if( filename.right( 3 ) != "m3u" ) //needs filename extension
837 filename += ".m3u"; 871 filename += ".m3u";
838 872
839 if( d->selectedFiles->first()) { //ramble through playlist view 873 if( d->selectedFiles->first()) { //ramble through playlist view
840 m3uList = new Om3u( filename, IO_ReadWrite | IO_Truncate); 874 m3uList = new Om3u( filename, IO_ReadWrite | IO_Truncate);
841 875
842 do { 876 do {
843 m3uList->add( d->selectedFiles->current()->file()); 877 m3uList->add( d->selectedFiles->current()->file());
844 } 878 }
845 while ( d->selectedFiles->next() ); 879 while ( d->selectedFiles->next() );
846 // odebug << list << oendl; 880 // odebug << list << oendl;
847 m3uList->write(); 881 m3uList->write();
848 m3uList->close(); 882 m3uList->close();
849 delete m3uList; 883 delete m3uList;
850 884
851 //delete fileDlg; 885 //delete fileDlg;
852 886
853 DocLnk lnk; 887 DocLnk lnk;
854 lnk.setFile( filename); 888 lnk.setFile( filename);
855 lnk.setIcon("opieplayer2/playlist2"); 889 lnk.setIcon("opieplayer2/playlist2");
856 lnk.setName( name); //sets file name 890 lnk.setName( name); //sets file name
857 891
858 // odebug << filename << oendl; 892 // odebug << filename << oendl;
859 Config config( "OpiePlayer" ); 893 Config config( "OpiePlayer" );
860 config.setGroup( "PlayList" ); 894 config.setGroup( "PlayList" );
861 895
862 config.writeEntry("CurrentPlaylist",filename); 896 config.writeEntry("CurrentPlaylist",filename);
863 currentPlayList=filename; 897 currentPlayList=filename;
864 898
865 if(!lnk.writeLink()) { 899 if(!lnk.writeLink()) {
866 odebug << "Writing doclink did not work" << oendl; 900 odebug << "Writing doclink did not work" << oendl;
867 } 901 }
868 902
869 setCaption(tr("OpiePlayer: ") + name); 903 setCaption(tr("OpiePlayer: ") + name);
870 } 904 }
871 } 905 }
872} 906}
873 907
874void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { 908void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) {
875 switch ( e->key() ) { 909 switch ( e->key() ) {
876 ////////////////////////////// Zaurus keys 910 ////////////////////////////// Zaurus keys
877 case Key_F9: //activity 911 case Key_F9: //activity
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.h b/noncore/multimedia/opieplayer2/playlistwidget.h
index 1f5ba92..7db0029 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.h
+++ b/noncore/multimedia/opieplayer2/playlistwidget.h
@@ -39,107 +39,108 @@
39#include <qpopupmenu.h> 39#include <qpopupmenu.h>
40#include <qpe/qcopenvelope_qws.h> 40#include <qpe/qcopenvelope_qws.h>
41 41
42#include "playlistwidgetgui.h" 42#include "playlistwidgetgui.h"
43 43
44class Config; 44class Config;
45class QListViewItem; 45class QListViewItem;
46class QListView; 46class QListView;
47class QPoint; 47class QPoint;
48class QAction; 48class QAction;
49class QLabel; 49class QLabel;
50class MediaPlayerState; 50class MediaPlayerState;
51class MediaPlayer; 51class MediaPlayer;
52 52
53class PlayListWidget : public PlayListWidgetGui { 53class PlayListWidget : public PlayListWidgetGui {
54 Q_OBJECT 54 Q_OBJECT
55public: 55public:
56 enum TabType { CurrentPlayList, AudioFiles, VideoFiles, PlayLists }; 56 enum TabType { CurrentPlayList, AudioFiles, VideoFiles, PlayLists };
57 enum { TabTypeCount = 4 }; 57 enum { TabTypeCount = 4 };
58 58
59 struct Entry 59 struct Entry
60 { 60 {
61 Entry( const QString &_name, const QString &_fileName ) 61 Entry( const QString &_name, const QString &_fileName )
62 : name( _name ), file( _fileName ) {} 62 : name( _name ), file( _fileName ) {}
63 Entry( const QString &_fileName ) 63 Entry( const QString &_fileName )
64 : name( _fileName ), file( _fileName ) {} 64 : name( _fileName ), file( _fileName ) {}
65 65
66 QString name; 66 QString name;
67 QString file; 67 QString file;
68 }; 68 };
69 69
70 static QString appName() { return QString::fromLatin1("opieplayer2"); } 70 static QString appName() { return QString::fromLatin1("opieplayer2"); }
71 PlayListWidget( QWidget* parent=0, const char* name=0, WFlags = 0 ); 71 PlayListWidget( QWidget* parent=0, const char* name=0, WFlags = 0 );
72 ~PlayListWidget(); 72 ~PlayListWidget();
73 73
74 // retrieve the current playlist entry (media file link) 74 // retrieve the current playlist entry (media file link)
75 const DocLnk *current() const; 75 const DocLnk *current() const;
76 void useSelectedDocument(); 76 void useSelectedDocument();
77 TabType currentTab() const; 77 TabType currentTab() const;
78 78
79 Entry currentEntry() const; 79 Entry currentEntry() const;
80 80
81public slots: 81public slots:
82 bool first(); 82 bool first();
83 bool last(); 83 bool last();
84 bool next(); 84 bool next();
85 bool prev(); 85 bool prev();
86 void writeDefaultPlaylist( ); 86 void writeDefaultPlaylist( );
87 QString currentFileListPathName() const; 87 QString currentFileListPathName() const;
88protected: 88protected:
89 QCopChannel * channel; 89 QCopChannel * channel;
90 void keyReleaseEvent( QKeyEvent *e); 90 void keyReleaseEvent( QKeyEvent *e);
91 91
92signals: 92signals:
93 void skinSelected(); 93 void skinSelected();
94 94
95private: 95private:
96 int defaultSkinIndex; 96 int defaultSkinIndex;
97/* void readm3u(const QString &); */ 97/* void readm3u(const QString &); */
98/* void readPls(const QString &); */ 98/* void readPls(const QString &); */
99 void readListFromFile(const QString &); 99 void readListFromFile(const QString &);
100 void initializeStates(); 100 void initializeStates();
101 101
102 bool inFileListMode() const; 102 bool inFileListMode() const;
103 103
104private slots: 104private slots:
105 void qcopReceive(const QCString&, const QByteArray&); 105 void qcopReceive(const QCString&, const QByteArray&);
106 void populateSkinsMenu(); 106 void populateSkinsMenu();
107 void skinsMenuActivated(int); 107 void skinsMenuActivated(int);
108 void pmViewActivated(int); 108 void pmViewActivated(int);
109 void writem3u(); 109 void writem3u();
110 void writeCurrentM3u(); 110 void writeCurrentM3u();
111 void openFile(); 111 void openFile();
112 void openURL(); 112 void openURL();
113 void openDirectory(); 113 void openDirectory();
114 void setDocument( const QString& fileref ); 114 void setDocument( const QString& fileref );
115 void addToSelection( const DocLnk& ); // Add a media file to the playlist 115 void addToSelection( const DocLnk& ); // Add a media file to the playlist
116 void addToSelection( QListViewItem* ); // Add a media file to the playlist 116 void addToSelection( QListViewItem* ); // Add a media file to the playlist
117 void clearList(); 117 void clearList();
118 void addAllToList(); 118 void addAllToList();
119 void addAllMusicToList(); 119 void addAllMusicToList();
120 void addAllVideoToList(); 120 void addAllVideoToList();
121 void saveList(); // Save the playlist 121 void saveList(); // Save the playlist
122 void loadList( const DocLnk &); // Load a playlist 122 void loadList( const DocLnk &); // Load a playlist
123 void playIt( QListViewItem *); 123 void playIt( QListViewItem *);
124 void btnPlay(bool); 124 void btnPlay(bool);
125 void deletePlaylist(); 125 void deletePlaylist();
126 void addSelected(); 126 void addSelected();
127 void removeSelected(); 127 void removeSelected();
128 void tabChanged(QWidget*); 128 void tabChanged(QWidget*);
129 void viewPressed( int, QListViewItem *, const QPoint&, int); 129 void viewPressed( int, QListViewItem *, const QPoint&, int);
130 void playlistViewPressed( int, QListViewItem *, const QPoint&, int); 130 void playlistViewPressed( int, QListViewItem *, const QPoint&, int);
131 void playSelected(); 131 void playSelected();
132 132
133private: 133private:
134 DocLnk addFileToPlaylist(const QString& directory, const QString& name); 134 DocLnk addFileToPlaylist(const QString& directory, const QString& name);
135 void setButtons(void);
135 bool fromSetDocument; 136 bool fromSetDocument;
136 bool insanityBool; 137 bool insanityBool;
137 QString setDocFileRef, currentPlayList; 138 QString setDocFileRef, currentPlayList;
138 int selected; 139 int selected;
139 QListView *currentFileListView; 140 QListView *currentFileListView;
140 141
141 MediaPlayer *m_mp; 142 MediaPlayer *m_mp;
142}; 143};
143 144
144#endif // PLAY_LIST_WIDGET_H 145#endif // PLAY_LIST_WIDGET_H
145 146