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