summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/playlistwidget.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/playlistwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp510
1 files changed, 355 insertions, 155 deletions
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp
index 0423e7a..202f351 100644
--- a/core/multimedia/opieplayer/playlistwidget.cpp
+++ b/core/multimedia/opieplayer/playlistwidget.cpp
@@ -1,10 +1,10 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
@@ -18,12 +18,14 @@
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qpe/qpemenubar.h> 21#include <qpe/qpemenubar.h>
22#include <qpe/qpetoolbar.h> 22#include <qpe/qpetoolbar.h>
23#include <qpe/fileselector.h> 23#include <qpe/fileselector.h>
24#include <qpe/qpeapplication.h>
25
24#include <qpe/applnk.h> 26#include <qpe/applnk.h>
25#include <qpe/config.h> 27#include <qpe/config.h>
26#include <qpe/global.h> 28#include <qpe/global.h>
27#include <qpe/resource.h> 29#include <qpe/resource.h>
28#include <qaction.h> 30#include <qaction.h>
29#include <qimage.h> 31#include <qimage.h>
@@ -32,74 +34,80 @@
32#include <qlabel.h> 34#include <qlabel.h>
33#include <qlist.h> 35#include <qlist.h>
34#include <qlistbox.h> 36#include <qlistbox.h>
35#include <qmainwindow.h> 37#include <qmainwindow.h>
36#include <qmessagebox.h> 38#include <qmessagebox.h>
37#include <qtoolbutton.h> 39#include <qtoolbutton.h>
40#include <qtabwidget.h>
41#include <qlistview.h>
42#include <qpoint.h>
43//#include <qtimer.h>
38 44
39#include "playlistselection.h" 45#include "playlistselection.h"
40#include "playlistwidget.h" 46#include "playlistwidget.h"
41#include "mediaplayerstate.h" 47#include "mediaplayerstate.h"
42 48
43#include <stdlib.h> 49#include <stdlib.h>
44 50
51#define BUTTONS_ON_TOOLBAR
52#define SIDE_BUTTONS
53#define CAN_SAVE_LOAD_PLAYLISTS
45 54
46extern MediaPlayerState *mediaPlayerState; 55extern MediaPlayerState *mediaPlayerState;
47 56
57// class myFileSelector {
48 58
59// };
49class PlayListWidgetPrivate { 60class PlayListWidgetPrivate {
50public: 61public:
51 QToolButton *tbPlay; 62 QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove;
52 QToolButton *tbFull;
53 QToolButton *tbLoop;
54 QToolButton *tbScale;
55 QToolButton *tbShuffle;
56
57 QFrame *playListFrame; 63 QFrame *playListFrame;
58 FileSelector *files; 64 FileSelector *files;
59 PlayListSelection *selectedFiles; 65 PlayListSelection *selectedFiles;
60 bool setDocumentUsed; 66 bool setDocumentUsed;
61 DocLnk *current; 67 DocLnk *current;
62}; 68};
63 69
64 70
65class ToolButton : public QToolButton { 71class ToolButton : public QToolButton {
66public: 72public:
67 ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) 73 ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE )
68 : QToolButton( parent, name ) { 74 : QToolButton( parent, name ) {
69 setTextLabel( name ); 75 setTextLabel( name );
70 setPixmap( Resource::loadPixmap( icon ) ); 76 setPixmap( Resource::loadPixmap( icon ) );
71 setAutoRaise( TRUE ); 77 setAutoRaise( TRUE );
72 setFocusPolicy( QWidget::NoFocus ); 78 setFocusPolicy( QWidget::NoFocus );
73 setToggleButton( t ); 79 setToggleButton( t );
74 connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); 80 connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot );
75 QPEMenuToolFocusManager::manager()->addWidget( this ); 81 QPEMenuToolFocusManager::manager()->addWidget( this );
76 } 82 }
77}; 83};
78 84
79 85
80class MenuItem : public QAction { 86class MenuItem : public QAction {
81public: 87public:
82 MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) 88 MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot )
83 : QAction( text, QString::null, 0, 0 ) { 89 : QAction( text, QString::null, 0, 0 ) {
84 connect( this, SIGNAL( activated() ), handler, slot ); 90 connect( this, SIGNAL( activated() ), handler, slot );
85 addTo( parent ); 91 addTo( parent );
86 } 92 }
87}; 93};
88 94
89 95
90PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) 96PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
91 : QMainWindow( parent, name, fl ) { 97 : QMainWindow( parent, name, fl ) {
92 98
93 d = new PlayListWidgetPrivate; 99 d = new PlayListWidgetPrivate;
94 d->setDocumentUsed = FALSE; 100 d->setDocumentUsed = FALSE;
95 d->current = NULL; 101 d->current = NULL;
102// menuTimer = new QTimer( this ,"menu timer"),
103// connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) );
96 104
97 setBackgroundMode( PaletteButton ); 105 setBackgroundMode( PaletteButton );
98 106
99 setCaption( tr("MediaPlayer") ); 107 setCaption( tr("OpiePlayer") );
100 setIcon( Resource::loadPixmap( "MPEGPlayer" ) ); 108 setIcon( Resource::loadPixmap( "MPEGPlayer" ) );
101 109
102 setToolBarsMovable( FALSE ); 110 setToolBarsMovable( FALSE );
103 111
104 // Create Toolbar 112 // Create Toolbar
105 QPEToolBar *toolbar = new QPEToolBar( this ); 113 QPEToolBar *toolbar = new QPEToolBar( this );
@@ -108,85 +116,152 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
108 // Create Menubar 116 // Create Menubar
109 QPEMenuBar *menu = new QPEMenuBar( toolbar ); 117 QPEMenuBar *menu = new QPEMenuBar( toolbar );
110 menu->setMargin( 0 ); 118 menu->setMargin( 0 );
111 119
112 QPEToolBar *bar = new QPEToolBar( this ); 120 QPEToolBar *bar = new QPEToolBar( this );
113 bar->setLabel( tr( "Play Operations" ) ); 121 bar->setLabel( tr( "Play Operations" ) );
114#ifdef BUTTONS_ON_TOOLBAR 122 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ),"mpegplayer/add_to_playlist",this , SLOT(addSelected()) );
115 d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", mediaPlayerState, SLOT(setPlaying(bool)), TRUE ); 123 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "mpegplayer/remove_from_playlist", this , SLOT(removeSelected()) );
116 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ), "mpegplayer/shuffle", mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); 124 d->tbPlay = new ToolButton( bar, tr( "Play" ),"mpegplayer/play", mediaPlayerState, SLOT( setPlaying(bool)), TRUE );
117#endif 125 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ), "mpegplayer/shuffle", mediaPlayerState, SLOT(setShuffled(bool)), TRUE );
118 d->tbLoop = new ToolButton( bar, tr( "Loop" ), "mpegplayer/loop", mediaPlayerState, SLOT(setLooping(bool)), TRUE ); 126 d->tbLoop = new ToolButton( bar, tr( "Loop" ),"mpegplayer/loop", mediaPlayerState, SLOT(setLooping(bool)), TRUE );
119 d->tbFull = new ToolButton( bar, tr( "Fullscreen" ), "fullscreen", mediaPlayerState, SLOT(setFullscreen(bool)), TRUE );
120 d->tbScale = new ToolButton( bar, tr( "Scale" ), "mpegplayer/scale", mediaPlayerState, SLOT(setScaled(bool)), TRUE );
121 127
122 QPopupMenu *pmPlayList = new QPopupMenu( this ); 128 QPopupMenu *pmPlayList = new QPopupMenu( this );
123 menu->insertItem( tr( "PlayList" ), pmPlayList ); 129 menu->insertItem( tr( "File" ), pmPlayList );
124 new MenuItem( pmPlayList, tr( "Toggle PlayList" ), mediaPlayerState, SLOT( togglePlaylist() ) );
125 new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); 130 new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) );
126 new MenuItem( pmPlayList, tr( "Add all music files" ), this, SLOT( addAllMusicToList() ) ); 131 new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) );
127 new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); 132 new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) );
128 new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); 133 new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) );
129#ifdef CAN_SAVE_LOAD_PLAYLISTS
130 new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); 134 new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) );
131 new MenuItem( pmPlayList, tr( "Load PlayList" ), this, SLOT( loadList() ) ); 135 new MenuItem( pmPlayList, tr( "Load PlayList" ), this, SLOT( loadList() ) );
132#endif 136
137 QPopupMenu *pmView = new QPopupMenu( this );
138 menu->insertItem( tr( "View" ), pmView );
139
140 fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0);
141 connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) );
142 fullScreenButton->addTo(pmView);
143 scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("mpegplayer/scale"), QString::null, 0, this, 0);
144 connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) );
145 scaleButton->addTo(pmView);
133 146
134 QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); 147 QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton );
148 QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton );
149
150 QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton );
151
152 tabWidget = new QTabWidget( hbox6, "tabWidget" );
153 tabWidget->setTabShape(QTabWidget::Triangular);
154
155 QWidget *pTab;
156 pTab = new QWidget( tabWidget, "pTab" );
157 playlistView = new QListView( pTab, "Videoview" );
158 playlistView->setMinimumSize(236,260);
159 tabWidget->insertTab( pTab,"Playlist");
135 160
136 // Add the playlist area 161 // Add the playlist area
137 QVBox *vbox3 = new QVBox( vbox5 ); vbox3->setBackgroundMode( PaletteButton );
138 d->playListFrame = vbox3;
139 162
140 QLabel *plString = new QLabel( tr(" PlayList"), vbox3 ); 163 QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton );
141 plString->setBackgroundMode( QButton::PaletteButton ); 164 d->playListFrame = vbox3;
142 plString->setFont( QFont( "Helvetica", 8, QFont::Bold ) ); 165 d->playListFrame ->setMinimumSize(235,260);
143 166
144 QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); 167 QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton );
145 d->selectedFiles = new PlayListSelection( hbox2 );
146 QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton );
147 168
148#ifndef BUTTONS_ON_TOOLBAR 169 d->selectedFiles = new PlayListSelection( hbox2);
149 d->tbPlay = new ToolButton( vbox1, tr( "Play" ), "mpegplayer/play", mediaPlayerState, SLOT(setPlaying(bool)), TRUE ); 170 QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton );
150 QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch
151#endif
152 new ToolButton( vbox1, tr( "Move Up" ), "mpegplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) );
153 new ToolButton( vbox1, tr( "Remove" ), "mpegplayer/cut", d->selectedFiles, SLOT(removeSelected()) );
154 new ToolButton( vbox1, tr( "Move Down" ), "mpegplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) );
155 QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch
156#ifndef BUTTONS_ON_TOOLBAR
157 d->tbShuffle = new ToolButton( vbox1, tr( "Randomize" ), "mpegplayer/shuffle", mediaPlayerState, SLOT(setShuffled(bool)), TRUE );
158#endif
159 171
172 QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch
173 new ToolButton( vbox1, tr( "Move Up" ), "mpegplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) );
174 new ToolButton( vbox1, tr( "Remove" ), "mpegplayer/cut", d->selectedFiles, SLOT(removeSelected()) );
175 new ToolButton( vbox1, tr( "Move Down" ), "mpegplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) );
176 QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch
177
178 QWidget *aTab;
179 aTab = new QWidget( tabWidget, "aTab" );
180 audioView = new QListView( aTab, "Audioview" );
181 audioView->setMinimumSize(233,260);
182 audioView->addColumn( "Title",150);
183 audioView->addColumn("Size", 45);
184 audioView->addColumn("Media",35);
185 audioView->setColumnAlignment(1, Qt::AlignRight);
186 audioView->setColumnAlignment(2, Qt::AlignRight);
187 tabWidget->insertTab(aTab,"Audio");
188// audioView
189 Global::findDocuments(&files, "audio/*");
190 QListIterator<DocLnk> dit( files.children() );
191 QString storage;
192 for ( ; dit.current(); ++dit ) {
193 QListViewItem * newItem;
194 if(dit.current()->file().find("/mnt/cf") != -1 ) storage="CF";
195 else if(dit.current()->file().find("/mnt/hda") != -1 ) storage="CF";
196 else if(dit.current()->file().find("/mnt/card") != -1 ) storage="SD";
197 else storage="RAM";
198 if ( QFile( dit.current()->file()).exists() ) {
199 newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage);
200 newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/musicfile" ));
201 }
202 }
203// videowidget
204
205 QWidget *vTab;
206 vTab = new QWidget( tabWidget, "vTab" );
207 videoView = new QListView( vTab, "Videoview" );
208 videoView->setMinimumSize(233,260);
209
210 videoView->addColumn("Title",150);
211 videoView->addColumn("Size",45);
212 videoView->addColumn("Media",35);
213 videoView->setColumnAlignment(1, Qt::AlignRight);
214 videoView->setColumnAlignment(2, Qt::AlignRight);
215
216 tabWidget->insertTab( vTab,"Video");
217
218 Global::findDocuments(&vFiles, "video/*");
219 QListIterator<DocLnk> Vdit( vFiles.children() );
220 for ( ; Vdit.current(); ++Vdit ) {
221 if( Vdit.current()->file().find("/mnt/cf") != -1 ) storage="CF";
222 else if( Vdit.current()->file().find("/mnt/hda") != -1 ) storage="CF";
223 else if( Vdit.current()->file().find("/mnt/card") != -1 ) storage="SD";
224 else storage="RAM";
225 QListViewItem * newItem;
226 if ( QFile( Vdit.current()->file()).exists() ) {
227 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage);
228 newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/videofile" ));
229 }
230 }
160 // add the library area 231 // add the library area
161 QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); 232 QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
162 233
163 QLabel *libString = new QLabel( tr(" Media Library"), vbox4 ); 234// connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) );
164 libString->setBackgroundMode( QButton::PaletteButton ); 235// connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) );
165 libString->setFont( QFont( "Helvetica", 8, QFont::Bold ) );
166 236
167 QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); 237 connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) );
168 d->files = new FileSelector( "video/*;audio/*", hbox6, "Find Media Files", FALSE, FALSE ); 238 connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) );
169 d->files->setBackgroundMode( PaletteButton ); 239
170 QVBox *vbox7 = new QVBox( hbox6 ); vbox7->setBackgroundMode( PaletteButton ); 240 connect( audioView, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint&, int ) ),
241 this, SLOT( addToSelection( QListViewItem *, const QPoint&, int )) );
242 connect( videoView, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint&, int ) ),
243 this, SLOT( addToSelection( QListViewItem *, const QPoint&, int )) );
171 244
172#ifdef SIDE_BUTTONS
173 new ToolButton( vbox7, tr( "Add to Playlist" ), "mpegplayer/add_to_playlist", d->selectedFiles, SLOT(addSelected()) );
174 new ToolButton( vbox7, tr( "Remove from Playlist" ), "mpegplayer/remove_from_playlist", d->selectedFiles, SLOT(removeSelected()) );
175 QVBox *stretch3 = new QVBox( vbox1 ); stretch3->setBackgroundMode( PaletteButton ); // add stretch
176#endif
177 245
178 connect( d->files, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); 246 connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*)));
247 // connect( d->files, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) );
248 // connect( d->files, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) );
179 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); 249 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) );
180 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); 250 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) );
181 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); 251 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) );
182 connect( mediaPlayerState, SIGNAL( fullscreenToggled( bool ) ), d->tbFull, SLOT( setOn( bool ) ) ); 252
183 connect( mediaPlayerState, SIGNAL( scaledToggled( bool ) ), d->tbScale, SLOT( setOn( bool ) ) ); 253// connect( mediaPlayerState, SIGNAL( fullscreenToggled( bool ) ), fullScreenButton, SLOT( setOn( bool ) ) );
184 connect( mediaPlayerState, SIGNAL( fullscreenToggled( bool ) ), d->tbScale, SLOT( setEnabled( bool ) ) ); 254// connect( mediaPlayerState, SIGNAL( scaledToggled( bool ) ), scaleButton, SLOT( setEnabled( bool ) ) );
255// connect( mediaPlayerState, SIGNAL( fullscreenToggled( bool ) ), fullScreenButton, SLOT( setEnabled( bool ) ) );
256
185 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); 257 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) );
186 258
259 connect( d->selectedFiles, SIGNAL( clicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) );
260// connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) );
261
187 setCentralWidget( vbox5 ); 262 setCentralWidget( vbox5 );
188 263
189 Config cfg( "MediaPlayer" ); 264 Config cfg( "MediaPlayer" );
190 readConfig( cfg ); 265 readConfig( cfg );
191 266
192 initializeStates(); 267 initializeStates();
@@ -195,39 +270,40 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
195 270
196PlayListWidget::~PlayListWidget() { 271PlayListWidget::~PlayListWidget() {
197 Config cfg( "MediaPlayer" ); 272 Config cfg( "MediaPlayer" );
198 writeConfig( cfg ); 273 writeConfig( cfg );
199 274
200 if ( d->current ) 275 if ( d->current )
201 delete d->current; 276 delete d->current;
202 delete d; 277 delete d;
203} 278}
204 279
205 280
206void PlayListWidget::initializeStates() { 281void PlayListWidget::initializeStates() {
282
207 d->tbPlay->setOn( mediaPlayerState->playing() ); 283 d->tbPlay->setOn( mediaPlayerState->playing() );
208 d->tbLoop->setOn( mediaPlayerState->looping() ); 284 d->tbLoop->setOn( mediaPlayerState->looping() );
209 d->tbShuffle->setOn( mediaPlayerState->shuffled() ); 285 d->tbShuffle->setOn( mediaPlayerState->shuffled() );
210 d->tbFull->setOn( mediaPlayerState->fullscreen() ); 286// d->tbFull->setOn( mediaPlayerState->fullscreen() );
211 d->tbScale->setOn( mediaPlayerState->scaled() ); 287// d->tbScale->setOn( mediaPlayerState->scaled() );
212 d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); 288// d->tbScale->setEnabled( mediaPlayerState->fullscreen() );
213 setPlaylist( mediaPlayerState->playlist() ); 289// setPlaylist( mediaPlayerState->playlist() );
214} 290}
215 291
216 292
217void PlayListWidget::readConfig( Config& cfg ) { 293void PlayListWidget::readConfig( Config& cfg ) {
218 cfg.setGroup("PlayList"); 294 cfg.setGroup("PlayList");
219 295
220 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 296 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
221 297
222 for ( int i = 0; i < noOfFiles; i++ ) { 298 for ( int i = 0; i < noOfFiles; i++ ) {
223 QString entryName; 299 QString entryName;
224 entryName.sprintf( "File%i", i + 1 ); 300 entryName.sprintf( "File%i", i + 1 );
225 QString linkFile = cfg.readEntry( entryName ); 301 QString linkFile = cfg.readEntry( entryName );
226 DocLnk lnk( linkFile ); 302 DocLnk lnk( linkFile );
227 if ( lnk.isValid() ) 303 if ( lnk.isValid() )
228 d->selectedFiles->addToSelection( lnk ); 304 d->selectedFiles->addToSelection( lnk );
229 305
230 } 306 }
231} 307}
232 308
233 309
@@ -235,52 +311,62 @@ void PlayListWidget::writeConfig( Config& cfg ) const {
235 cfg.setGroup("PlayList"); 311 cfg.setGroup("PlayList");
236 312
237 int noOfFiles = 0; 313 int noOfFiles = 0;
238 314
239 d->selectedFiles->first(); 315 d->selectedFiles->first();
240 do { 316 do {
241 const DocLnk *lnk = d->selectedFiles->current(); 317 const DocLnk *lnk = d->selectedFiles->current();
242 if ( lnk ) { 318 if ( lnk ) {
243 QString entryName; 319 QString entryName;
244 entryName.sprintf( "File%i", noOfFiles + 1 ); 320 entryName.sprintf( "File%i", noOfFiles + 1 );
245 cfg.writeEntry( entryName, lnk->linkFile() ); 321 cfg.writeEntry( entryName, lnk->linkFile() );
246 // if this link does exist, add it so we have the file 322 // if this link does exist, add it so we have the file
247 // next time... 323 // next time...
248 if ( !QFile::exists( lnk->linkFile() ) ) { 324 if ( !QFile::exists( lnk->linkFile() ) ) {
249 // the way writing lnks doesn't really check for out 325 // the way writing lnks doesn't really check for out
250 // of disk space, but check it anyway. 326 // of disk space, but check it anyway.
251 if ( !lnk->writeLink() ) { 327 if ( !lnk->writeLink() ) {
252 QMessageBox::critical( 0, tr("Out of space"), 328 QMessageBox::critical( 0, tr("Out of space"),
253 tr( "There was a problem saving " 329 tr( "There was a problem saving "
254 "the playlist.\n" 330 "the playlist.\n"
255 "Your playlist " 331 "Your playlist "
256 "may be missing some entries\n" 332 "may be missing some entries\n"
257 "the next time you start it." ) 333 "the next time you start it." )
258 ); 334 );
259 } 335 }
260 } 336 }
261 noOfFiles++; 337 noOfFiles++;
262 } 338 }
263 } while ( d->selectedFiles->next() ); 339 } while ( d->selectedFiles->next() );
264 340
265 cfg.writeEntry("NumberOfFiles", noOfFiles ); 341 cfg.writeEntry("NumberOfFiles", noOfFiles );
266} 342}
267 343
268 344
269void PlayListWidget::addToSelection( const DocLnk& lnk ) { 345void PlayListWidget::addToSelection( const DocLnk& lnk ) {
270 d->setDocumentUsed = FALSE; 346 d->setDocumentUsed = FALSE;
271 if ( mediaPlayerState->playlist() ) 347 if ( mediaPlayerState->playlist() )
272 d->selectedFiles->addToSelection( lnk ); 348 d->selectedFiles->addToSelection( lnk );
273 else 349 else
274 mediaPlayerState->setPlaying( TRUE ); 350 mediaPlayerState->setPlaying( TRUE );
351}
352
353
354void PlayListWidget::addToSelection( QListViewItem *it ,const QPoint & p, int index) {
355 qDebug("add");
356// d->selectedFiles->addToSelection( lnk );
357 // }
358// else
359// mediaPlayerState->setPlaying( TRUE );
360//
275} 361}
276 362
277 363
278void PlayListWidget::clearList() { 364void PlayListWidget::clearList() {
279 while ( first() ) 365 while ( first() )
280 d->selectedFiles->removeSelected(); 366 d->selectedFiles->removeSelected();
281} 367}
282 368
283 369
284void PlayListWidget::addAllToList() { 370void PlayListWidget::addAllToList() {
285 DocLnkSet files; 371 DocLnkSet files;
286 Global::findDocuments(&files, "video/*;audio/*"); 372 Global::findDocuments(&files, "video/*;audio/*");
@@ -307,22 +393,22 @@ void PlayListWidget::addAllVideoToList() {
307 d->selectedFiles->addToSelection( **dit ); 393 d->selectedFiles->addToSelection( **dit );
308} 394}
309 395
310 396
311void PlayListWidget::setDocument(const QString& fileref) { 397void PlayListWidget::setDocument(const QString& fileref) {
312 if ( fileref.isNull() ) { 398 if ( fileref.isNull() ) {
313 QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); 399 QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) );
314 return; 400 return;
315 } 401 }
316 if ( mediaPlayerState->playlist() ) 402 if ( mediaPlayerState->playlist() )
317 addToSelection( DocLnk( fileref ) ); 403 addToSelection( DocLnk( fileref ) );
318 else { 404 else {
319 d->setDocumentUsed = TRUE; 405 d->setDocumentUsed = TRUE;
320 if ( d->current ) 406 if ( d->current )
321 delete d->current; 407 delete d->current;
322 d->current = new DocLnk( fileref ); 408 d->current = new DocLnk( fileref );
323 } 409 }
324 mediaPlayerState->setPlaying( FALSE ); 410 mediaPlayerState->setPlaying( FALSE );
325 mediaPlayerState->setPlaying( TRUE ); 411 mediaPlayerState->setPlaying( TRUE );
326} 412}
327 413
328 414
@@ -338,82 +424,82 @@ void PlayListWidget::useSelectedDocument() {
338 d->setDocumentUsed = FALSE; 424 d->setDocumentUsed = FALSE;
339} 425}
340 426
341 427
342const DocLnk *PlayListWidget::current() { 428const DocLnk *PlayListWidget::current() {
343 if ( mediaPlayerState->playlist() ) 429 if ( mediaPlayerState->playlist() )
344 return d->selectedFiles->current(); 430 return d->selectedFiles->current();
345 else if ( d->setDocumentUsed && d->current ) { 431 else if ( d->setDocumentUsed && d->current ) {
346 return d->current; 432 return d->current;
347 } else 433 } else
348 return d->files->selected(); 434 return d->files->selected();
349} 435}
350 436
351 437
352bool PlayListWidget::prev() { 438bool PlayListWidget::prev() {
353 if ( mediaPlayerState->playlist() ) { 439 if ( mediaPlayerState->playlist() ) {
354 if ( mediaPlayerState->shuffled() ) { 440 if ( mediaPlayerState->shuffled() ) {
355 const DocLnk *cur = current(); 441 const DocLnk *cur = current();
356 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 442 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
357 for ( int i = 0; i < j; i++ ) { 443 for ( int i = 0; i < j; i++ ) {
358 if ( !d->selectedFiles->next() ) 444 if ( !d->selectedFiles->next() )
359 d->selectedFiles->first(); 445 d->selectedFiles->first();
360 } 446 }
361 if ( cur == current() ) 447 if ( cur == current() )
362 if ( !d->selectedFiles->next() ) 448 if ( !d->selectedFiles->next() )
363 d->selectedFiles->first(); 449 d->selectedFiles->first();
364 return TRUE; 450 return TRUE;
365 } else { 451 } else {
366 if ( !d->selectedFiles->prev() ) { 452 if ( !d->selectedFiles->prev() ) {
367 if ( mediaPlayerState->looping() ) { 453 if ( mediaPlayerState->looping() ) {
368 return d->selectedFiles->last(); 454 return d->selectedFiles->last();
369 } else { 455 } else {
370 return FALSE; 456 return FALSE;
371 } 457 }
372 } 458 }
373 return TRUE; 459 return TRUE;
374 } 460 }
375 } else { 461 } else {
376 return mediaPlayerState->looping(); 462 return mediaPlayerState->looping();
377 } 463 }
378} 464}
379 465
380 466
381bool PlayListWidget::next() { 467bool PlayListWidget::next() {
382 if ( mediaPlayerState->playlist() ) { 468 if ( mediaPlayerState->playlist() ) {
383 if ( mediaPlayerState->shuffled() ) { 469 if ( mediaPlayerState->shuffled() ) {
384 return prev(); 470 return prev();
385 } else { 471 } else {
386 if ( !d->selectedFiles->next() ) { 472 if ( !d->selectedFiles->next() ) {
387 if ( mediaPlayerState->looping() ) { 473 if ( mediaPlayerState->looping() ) {
388 return d->selectedFiles->first(); 474 return d->selectedFiles->first();
389 } else { 475 } else {
390 return FALSE; 476 return FALSE;
391 } 477 }
392 } 478 }
393 return TRUE; 479 return TRUE;
394 } 480 }
395 } else { 481 } else {
396 return mediaPlayerState->looping(); 482 return mediaPlayerState->looping();
397 } 483 }
398} 484}
399 485
400 486
401bool PlayListWidget::first() { 487bool PlayListWidget::first() {
402 if ( mediaPlayerState->playlist() ) 488 if ( mediaPlayerState->playlist() )
403 return d->selectedFiles->first(); 489 return d->selectedFiles->first();
404 else 490 else
405 return mediaPlayerState->looping(); 491 return mediaPlayerState->looping();
406} 492}
407 493
408 494
409bool PlayListWidget::last() { 495bool PlayListWidget::last() {
410 if ( mediaPlayerState->playlist() ) 496 if ( mediaPlayerState->playlist() )
411 return d->selectedFiles->last(); 497 return d->selectedFiles->last();
412 else 498 else
413 return mediaPlayerState->looping(); 499 return mediaPlayerState->looping();
414} 500}
415 501
416 502
417void PlayListWidget::saveList() { 503void PlayListWidget::saveList() {
418 QString filename; 504 QString filename;
419// pseudo code 505// pseudo code
@@ -431,19 +517,133 @@ void PlayListWidget::loadList() {
431 readConfig( cfg ); 517 readConfig( cfg );
432} 518}
433 519
434 520
435void PlayListWidget::setPlaylist( bool shown ) { 521void PlayListWidget::setPlaylist( bool shown ) {
436 if ( shown ) 522 if ( shown )
437 d->playListFrame->show(); 523 d->playListFrame->show();
438 else 524 else
439 d->playListFrame->hide(); 525 d->playListFrame->hide();
440} 526}
441 527
442 528
443void PlayListWidget::setView( char view ) { 529void PlayListWidget::setView( char view ) {
444 if ( view == 'l' ) 530 if ( view == 'l' )
445 showMaximized(); 531 showMaximized();
446 else 532 else
447 hide(); 533 hide();
534}
535
536void PlayListWidget::addSelected() {
537// QMessageBox::message("Note","Bozo the clown thinks\nthere's something actually here");
538 int tabPage=tabWidget->currentPageIndex();
539 switch (tabPage) {
540 case 0: //playlist
541 break;
542 case 1: { //audio
543 addToSelection( audioView->selectedItem() );
544 }
545 break;
546 case 2: { // video
547 addToSelection( videoView->selectedItem() );
548 }
549 break;
550 };
551}
552
553void PlayListWidget::removeSelected() {
554 d->selectedFiles->removeSelected( );
555}
556
557
558void PlayListWidget::playIt( QListViewItem *it) {
559// d->setDocumentUsed = FALSE;
560 mediaPlayerState->setPlaying(true);
561}
562
563void PlayListWidget::addToSelection( QListViewItem *it) {
564 d->setDocumentUsed = FALSE;
565
566 if(it) {
567 qDebug("add to selection");
568 int tabPage=tabWidget->currentPageIndex();
569 switch (tabPage) {
570 case 1: {
571 QListIterator<DocLnk> dit( files.children() );
572 for ( ; dit.current(); ++dit ) {
573 if( dit.current()->name() == it->text(0)) {
574 d->selectedFiles->addToSelection( **dit );
575 }
576 }
577 }
578 break;
579 case 2: {
580 QListIterator<DocLnk> dit( vFiles.children() );
581 for ( ; dit.current(); ++dit ) {
582 qDebug(dit.current()->name());
583 if( dit.current()->name() == it->text(0)) {
584 d->selectedFiles->addToSelection( **dit );
585 }
586 }
587 }
588 break;
589 case 0:
590 break;
591 };
592 tabWidget->setCurrentPage(0);
593// mediaPlayerState->setPlaying( TRUE );
594 }
595}
596
597void PlayListWidget::tabChanged(QWidget *widg) {
598
599 int tabPage=tabWidget->currentPageIndex();
600 switch (tabPage) {
601 case 0:
602 {
603 d->tbRemoveFromList->setEnabled(TRUE);
604 d->tbAddToList->setEnabled(FALSE);
605 }
606 break;
607 case 1:
608 {
609 d->tbRemoveFromList->setEnabled(FALSE);
610 d->tbAddToList->setEnabled(TRUE);
611 }
612 break;
613 case 2:
614 {
615 d->tbRemoveFromList->setEnabled(FALSE);
616 d->tbAddToList->setEnabled(TRUE);
617 }
618 break;
619 };
448} 620}
449 621
622// void PlayListWidget::cancelMenuTimer() {
623// if( menuTimer->isActive() )
624// menuTimer->stop();
625// }
626
627// void PlayListWidget::showFileMenu() {
628
629// }
630
631// void PlayListWidget::contentsMousePressEvent( QMouseEvent * e )
632// {
633// // QListView::contentsMousePressEvent( e );
634// menuTimer->start( 750, TRUE );
635// }
636
637
638// void PlayListWidget::contentsMouseReleaseEvent( QMouseEvent * e )
639// {
640// // QListView::contentsMouseReleaseEvent( e );
641// menuTimer->stop();
642// }
643// // void PlayListWidget::setFullScreen() {
644// mediaPlayerState->toggleFullscreen( );
645// }
646
647// void PlayListWidget::setScaled() {
648// mediaPlayerState->toggleScaled();
649// }