-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 13 | ||||
-rw-r--r-- | core/multimedia/opieplayer/wavplugin/wavplugin.cpp | 2 |
2 files changed, 6 insertions, 9 deletions
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index 1a0c7ca..a6202bc 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp | |||
@@ -37,727 +37,724 @@ | |||
37 | #include <qlistbox.h> | 37 | #include <qlistbox.h> |
38 | #include <qmainwindow.h> | 38 | #include <qmainwindow.h> |
39 | #include <qmessagebox.h> | 39 | #include <qmessagebox.h> |
40 | #include <qtoolbutton.h> | 40 | #include <qtoolbutton.h> |
41 | #include <qtabwidget.h> | 41 | #include <qtabwidget.h> |
42 | #include <qlistview.h> | 42 | #include <qlistview.h> |
43 | #include <qpoint.h> | 43 | #include <qpoint.h> |
44 | #include <qlineedit.h> | 44 | #include <qlineedit.h> |
45 | #include <qpushbutton.h> | 45 | #include <qpushbutton.h> |
46 | 46 | ||
47 | //#include <qtimer.h> | 47 | //#include <qtimer.h> |
48 | 48 | ||
49 | #include "playlistselection.h" | 49 | #include "playlistselection.h" |
50 | #include "playlistwidget.h" | 50 | #include "playlistwidget.h" |
51 | #include "mediaplayerstate.h" | 51 | #include "mediaplayerstate.h" |
52 | 52 | ||
53 | #include "inputDialog.h" | 53 | #include "inputDialog.h" |
54 | 54 | ||
55 | #include <stdlib.h> | 55 | #include <stdlib.h> |
56 | 56 | ||
57 | #define BUTTONS_ON_TOOLBAR | 57 | #define BUTTONS_ON_TOOLBAR |
58 | #define SIDE_BUTTONS | 58 | #define SIDE_BUTTONS |
59 | #define CAN_SAVE_LOAD_PLAYLISTS | 59 | #define CAN_SAVE_LOAD_PLAYLISTS |
60 | 60 | ||
61 | extern MediaPlayerState *mediaPlayerState; | 61 | extern MediaPlayerState *mediaPlayerState; |
62 | 62 | ||
63 | // class myFileSelector { | 63 | // class myFileSelector { |
64 | 64 | ||
65 | // }; | 65 | // }; |
66 | class PlayListWidgetPrivate { | 66 | class PlayListWidgetPrivate { |
67 | public: | 67 | public: |
68 | QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; | 68 | QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; |
69 | QFrame *playListFrame; | 69 | QFrame *playListFrame; |
70 | FileSelector *files; | 70 | FileSelector *files; |
71 | PlayListSelection *selectedFiles; | 71 | PlayListSelection *selectedFiles; |
72 | bool setDocumentUsed; | 72 | bool setDocumentUsed; |
73 | DocLnk *current; | 73 | DocLnk *current; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | 76 | ||
77 | class ToolButton : public QToolButton { | 77 | class ToolButton : public QToolButton { |
78 | public: | 78 | public: |
79 | ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) | 79 | ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) |
80 | : QToolButton( parent, name ) { | 80 | : QToolButton( parent, name ) { |
81 | setTextLabel( name ); | 81 | setTextLabel( name ); |
82 | setPixmap( Resource::loadPixmap( icon ) ); | 82 | setPixmap( Resource::loadPixmap( icon ) ); |
83 | setAutoRaise( TRUE ); | 83 | setAutoRaise( TRUE ); |
84 | setFocusPolicy( QWidget::NoFocus ); | 84 | setFocusPolicy( QWidget::NoFocus ); |
85 | setToggleButton( t ); | 85 | setToggleButton( t ); |
86 | connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); | 86 | connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); |
87 | QPEMenuToolFocusManager::manager()->addWidget( this ); | 87 | QPEMenuToolFocusManager::manager()->addWidget( this ); |
88 | } | 88 | } |
89 | }; | 89 | }; |
90 | 90 | ||
91 | 91 | ||
92 | class MenuItem : public QAction { | 92 | class MenuItem : public QAction { |
93 | public: | 93 | public: |
94 | MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) | 94 | MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) |
95 | : QAction( text, QString::null, 0, 0 ) { | 95 | : QAction( text, QString::null, 0, 0 ) { |
96 | connect( this, SIGNAL( activated() ), handler, slot ); | 96 | connect( this, SIGNAL( activated() ), handler, slot ); |
97 | addTo( parent ); | 97 | addTo( parent ); |
98 | } | 98 | } |
99 | }; | 99 | }; |
100 | 100 | ||
101 | 101 | ||
102 | PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) | 102 | PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) |
103 | : QMainWindow( parent, name, fl ) { | 103 | : QMainWindow( parent, name, fl ) { |
104 | 104 | ||
105 | d = new PlayListWidgetPrivate; | 105 | d = new PlayListWidgetPrivate; |
106 | d->setDocumentUsed = FALSE; | 106 | d->setDocumentUsed = FALSE; |
107 | d->current = NULL; | 107 | d->current = NULL; |
108 | // menuTimer = new QTimer( this ,"menu timer"), | 108 | // menuTimer = new QTimer( this ,"menu timer"), |
109 | // connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); | 109 | // connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); |
110 | 110 | ||
111 | setBackgroundMode( PaletteButton ); | 111 | setBackgroundMode( PaletteButton ); |
112 | 112 | ||
113 | setCaption( tr("OpiePlayer") ); | 113 | setCaption( tr("OpiePlayer") ); |
114 | setIcon( Resource::loadPixmap( "MPEGPlayer" ) ); | 114 | setIcon( Resource::loadPixmap( "MPEGPlayer" ) ); |
115 | 115 | ||
116 | setToolBarsMovable( FALSE ); | 116 | setToolBarsMovable( FALSE ); |
117 | 117 | ||
118 | // Create Toolbar | 118 | // Create Toolbar |
119 | QPEToolBar *toolbar = new QPEToolBar( this ); | 119 | QPEToolBar *toolbar = new QPEToolBar( this ); |
120 | toolbar->setHorizontalStretchable( TRUE ); | 120 | toolbar->setHorizontalStretchable( TRUE ); |
121 | 121 | ||
122 | // Create Menubar | 122 | // Create Menubar |
123 | QPEMenuBar *menu = new QPEMenuBar( toolbar ); | 123 | QPEMenuBar *menu = new QPEMenuBar( toolbar ); |
124 | menu->setMargin( 0 ); | 124 | menu->setMargin( 0 ); |
125 | 125 | ||
126 | QPEToolBar *bar = new QPEToolBar( this ); | 126 | QPEToolBar *bar = new QPEToolBar( this ); |
127 | bar->setLabel( tr( "Play Operations" ) ); | 127 | bar->setLabel( tr( "Play Operations" ) ); |
128 | // d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "mpegplayer/play_current_list", | 128 | // d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "mpegplayer/play_current_list", |
129 | // this , SLOT( addSelected()) ); | 129 | // this , SLOT( addSelected()) ); |
130 | tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); | 130 | tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); |
131 | tbDeletePlaylist->setFlat(TRUE); | 131 | tbDeletePlaylist->setFlat(TRUE); |
132 | tbDeletePlaylist->setFixedSize(20,20); | 132 | tbDeletePlaylist->setFixedSize(20,20); |
133 | connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); | 133 | connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); |
134 | 134 | ||
135 | d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "mpegplayer/add_to_playlist", | 135 | d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "mpegplayer/add_to_playlist", |
136 | this , SLOT(addSelected()) ); | 136 | this , SLOT(addSelected()) ); |
137 | d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "mpegplayer/remove_from_playlist", | 137 | d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "mpegplayer/remove_from_playlist", |
138 | this , SLOT(removeSelected()) ); | 138 | this , SLOT(removeSelected()) ); |
139 | // d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); | 139 | // d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); |
140 | d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", | 140 | d->tbPlay = new ToolButton( bar, tr( "Play" ), "mpegplayer/play", |
141 | this , SLOT( btnPlay(bool) ), TRUE ); | 141 | this , SLOT( btnPlay(bool) ), TRUE ); |
142 | d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"mpegplayer/shuffle", | 142 | d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"mpegplayer/shuffle", |
143 | mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); | 143 | mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); |
144 | d->tbLoop = new ToolButton( bar, tr( "Loop" ),"mpegplayer/loop", | 144 | d->tbLoop = new ToolButton( bar, tr( "Loop" ),"mpegplayer/loop", |
145 | mediaPlayerState, SLOT(setLooping(bool)), TRUE ); | 145 | mediaPlayerState, SLOT(setLooping(bool)), TRUE ); |
146 | tbDeletePlaylist->hide(); | 146 | tbDeletePlaylist->hide(); |
147 | 147 | ||
148 | QPopupMenu *pmPlayList = new QPopupMenu( this ); | 148 | QPopupMenu *pmPlayList = new QPopupMenu( this ); |
149 | menu->insertItem( tr( "File" ), pmPlayList ); | 149 | menu->insertItem( tr( "File" ), pmPlayList ); |
150 | new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); | 150 | new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); |
151 | new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); | 151 | new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); |
152 | new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); | 152 | new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); |
153 | new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); | 153 | new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); |
154 | new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); | 154 | new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); |
155 | // new MenuItem( pmPlayList, tr( "Load PlayList" ), this, SLOT( loadList() ) ); | 155 | // new MenuItem( pmPlayList, tr( "Load PlayList" ), this, SLOT( loadList() ) ); |
156 | 156 | ||
157 | QPopupMenu *pmView = new QPopupMenu( this ); | 157 | QPopupMenu *pmView = new QPopupMenu( this ); |
158 | menu->insertItem( tr( "View" ), pmView ); | 158 | menu->insertItem( tr( "View" ), pmView ); |
159 | 159 | ||
160 | fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); | 160 | fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); |
161 | connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); | 161 | connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); |
162 | fullScreenButton->addTo(pmView); | 162 | fullScreenButton->addTo(pmView); |
163 | scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("mpegplayer/scale"), QString::null, 0, this, 0); | 163 | scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("mpegplayer/scale"), QString::null, 0, this, 0); |
164 | connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); | 164 | connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); |
165 | scaleButton->addTo(pmView); | 165 | scaleButton->addTo(pmView); |
166 | 166 | ||
167 | QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); | 167 | QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); |
168 | QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); | 168 | QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); |
169 | 169 | ||
170 | QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); | 170 | QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); |
171 | 171 | ||
172 | tabWidget = new QTabWidget( hbox6, "tabWidget" ); | 172 | tabWidget = new QTabWidget( hbox6, "tabWidget" ); |
173 | tabWidget->setTabShape(QTabWidget::Triangular); | 173 | tabWidget->setTabShape(QTabWidget::Triangular); |
174 | 174 | ||
175 | QWidget *pTab; | 175 | QWidget *pTab; |
176 | pTab = new QWidget( tabWidget, "pTab" ); | 176 | pTab = new QWidget( tabWidget, "pTab" ); |
177 | playlistView = new QListView( pTab, "Videoview" ); | 177 | playlistView = new QListView( pTab, "Videoview" ); |
178 | playlistView->setMinimumSize(236,260); | 178 | playlistView->setMinimumSize(236,260); |
179 | tabWidget->insertTab( pTab,"Playlist"); | 179 | tabWidget->insertTab( pTab,"Playlist"); |
180 | 180 | ||
181 | // Add the playlist area | 181 | // Add the playlist area |
182 | 182 | ||
183 | QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); | 183 | QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); |
184 | d->playListFrame = vbox3; | 184 | d->playListFrame = vbox3; |
185 | d->playListFrame ->setMinimumSize(235,260); | 185 | d->playListFrame ->setMinimumSize(235,260); |
186 | 186 | ||
187 | QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); | 187 | QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); |
188 | 188 | ||
189 | d->selectedFiles = new PlayListSelection( hbox2); | 189 | d->selectedFiles = new PlayListSelection( hbox2); |
190 | QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); | 190 | QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); |
191 | 191 | ||
192 | QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch | 192 | QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch |
193 | new ToolButton( vbox1, tr( "Move Up" ), "mpegplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); | 193 | new ToolButton( vbox1, tr( "Move Up" ), "mpegplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); |
194 | new ToolButton( vbox1, tr( "Remove" ), "mpegplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); | 194 | new ToolButton( vbox1, tr( "Remove" ), "mpegplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); |
195 | new ToolButton( vbox1, tr( "Move Down" ), "mpegplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); | 195 | new ToolButton( vbox1, tr( "Move Down" ), "mpegplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); |
196 | QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch | 196 | QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch |
197 | 197 | ||
198 | QWidget *aTab; | 198 | QWidget *aTab; |
199 | aTab = new QWidget( tabWidget, "aTab" ); | 199 | aTab = new QWidget( tabWidget, "aTab" ); |
200 | audioView = new QListView( aTab, "Audioview" ); | 200 | audioView = new QListView( aTab, "Audioview" ); |
201 | audioView->setMinimumSize(233,260); | 201 | audioView->setMinimumSize(233,260); |
202 | audioView->addColumn( "Title",150); | 202 | audioView->addColumn( "Title",150); |
203 | audioView->addColumn("Size", 45); | 203 | audioView->addColumn("Size", 45); |
204 | audioView->addColumn("Media",35); | 204 | audioView->addColumn("Media",35); |
205 | audioView->setColumnAlignment(1, Qt::AlignRight); | 205 | audioView->setColumnAlignment(1, Qt::AlignRight); |
206 | audioView->setColumnAlignment(2, Qt::AlignRight); | 206 | audioView->setColumnAlignment(2, Qt::AlignRight); |
207 | tabWidget->insertTab(aTab,"Audio"); | 207 | tabWidget->insertTab(aTab,"Audio"); |
208 | // audioView | 208 | // audioView |
209 | Global::findDocuments(&files, "audio/*"); | 209 | Global::findDocuments(&files, "audio/*"); |
210 | QListIterator<DocLnk> dit( files.children() ); | 210 | QListIterator<DocLnk> dit( files.children() ); |
211 | QString storage; | 211 | QString storage; |
212 | for ( ; dit.current(); ++dit ) { | 212 | for ( ; dit.current(); ++dit ) { |
213 | QListViewItem * newItem; | 213 | QListViewItem * newItem; |
214 | if(dit.current()->file().find("/mnt/cf") != -1 ) storage="CF"; | 214 | if(dit.current()->file().find("/mnt/cf") != -1 ) storage="CF"; |
215 | else if(dit.current()->file().find("/mnt/hda") != -1 ) storage="CF"; | 215 | else if(dit.current()->file().find("/mnt/hda") != -1 ) storage="CF"; |
216 | else if(dit.current()->file().find("/mnt/card") != -1 ) storage="SD"; | 216 | else if(dit.current()->file().find("/mnt/card") != -1 ) storage="SD"; |
217 | else storage="RAM"; | 217 | else storage="RAM"; |
218 | if ( QFile( dit.current()->file()).exists() ) { | 218 | if ( QFile( dit.current()->file()).exists() ) { |
219 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage); | 219 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage); |
220 | newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/musicfile" )); | 220 | newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/musicfile" )); |
221 | } | 221 | } |
222 | } | 222 | } |
223 | // videowidget | 223 | // videowidget |
224 | 224 | ||
225 | QWidget *vTab; | 225 | QWidget *vTab; |
226 | vTab = new QWidget( tabWidget, "vTab" ); | 226 | vTab = new QWidget( tabWidget, "vTab" ); |
227 | videoView = new QListView( vTab, "Videoview" ); | 227 | videoView = new QListView( vTab, "Videoview" ); |
228 | videoView->setMinimumSize(233,260); | 228 | videoView->setMinimumSize(233,260); |
229 | 229 | ||
230 | videoView->addColumn("Title",150); | 230 | videoView->addColumn("Title",150); |
231 | videoView->addColumn("Size",45); | 231 | videoView->addColumn("Size",45); |
232 | videoView->addColumn("Media",35); | 232 | videoView->addColumn("Media",35); |
233 | videoView->setColumnAlignment(1, Qt::AlignRight); | 233 | videoView->setColumnAlignment(1, Qt::AlignRight); |
234 | videoView->setColumnAlignment(2, Qt::AlignRight); | 234 | videoView->setColumnAlignment(2, Qt::AlignRight); |
235 | 235 | ||
236 | tabWidget->insertTab( vTab,"Video"); | 236 | tabWidget->insertTab( vTab,"Video"); |
237 | 237 | ||
238 | Global::findDocuments(&vFiles, "video/*"); | 238 | Global::findDocuments(&vFiles, "video/*"); |
239 | QListIterator<DocLnk> Vdit( vFiles.children() ); | 239 | QListIterator<DocLnk> Vdit( vFiles.children() ); |
240 | for ( ; Vdit.current(); ++Vdit ) { | 240 | for ( ; Vdit.current(); ++Vdit ) { |
241 | if( Vdit.current()->file().find("/mnt/cf") != -1 ) storage="CF"; | 241 | if( Vdit.current()->file().find("/mnt/cf") != -1 ) storage="CF"; |
242 | else if( Vdit.current()->file().find("/mnt/hda") != -1 ) storage="CF"; | 242 | else if( Vdit.current()->file().find("/mnt/hda") != -1 ) storage="CF"; |
243 | else if( Vdit.current()->file().find("/mnt/card") != -1 ) storage="SD"; | 243 | else if( Vdit.current()->file().find("/mnt/card") != -1 ) storage="SD"; |
244 | else storage="RAM"; | 244 | else storage="RAM"; |
245 | QListViewItem * newItem; | 245 | QListViewItem * newItem; |
246 | if ( QFile( Vdit.current()->file()).exists() ) { | 246 | if ( QFile( Vdit.current()->file()).exists() ) { |
247 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage); | 247 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage); |
248 | newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/videofile" )); | 248 | newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/videofile" )); |
249 | } | 249 | } |
250 | } | 250 | } |
251 | 251 | ||
252 | //playlists list | 252 | //playlists list |
253 | QWidget *LTab; | 253 | QWidget *LTab; |
254 | LTab = new QWidget( tabWidget, "LTab" ); | 254 | LTab = new QWidget( tabWidget, "LTab" ); |
255 | playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy | 255 | playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy |
256 | playLists->setMinimumSize(233,260);; | 256 | playLists->setMinimumSize(233,260);; |
257 | tabWidget->insertTab(LTab,"Lists"); | 257 | tabWidget->insertTab(LTab,"Lists"); |
258 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); | 258 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); |
259 | // connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 259 | // connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
260 | 260 | ||
261 | 261 | ||
262 | // add the library area | 262 | // add the library area |
263 | QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); | 263 | QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); |
264 | 264 | ||
265 | 265 | ||
266 | connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), | 266 | connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), |
267 | this, SLOT( fauxPlay( QListViewItem *) ) ); | 267 | this, SLOT( fauxPlay( QListViewItem *) ) ); |
268 | connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), | 268 | connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), |
269 | this, SLOT( fauxPlay( QListViewItem *)) ); | 269 | this, SLOT( fauxPlay( QListViewItem *)) ); |
270 | 270 | ||
271 | // connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); | 271 | // connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); |
272 | // connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); | 272 | // connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); |
273 | 273 | ||
274 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | 274 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); |
275 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | 275 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); |
276 | 276 | ||
277 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); | 277 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); |
278 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); | 278 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); |
279 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); | 279 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); |
280 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); | 280 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); |
281 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); | 281 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); |
282 | 282 | ||
283 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); | 283 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); |
284 | // connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); | 284 | // connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); |
285 | 285 | ||
286 | setCentralWidget( vbox5 ); | 286 | setCentralWidget( vbox5 ); |
287 | 287 | ||
288 | Config cfg( "MediaPlayer" ); | 288 | Config cfg( "MediaPlayer" ); |
289 | readConfig( cfg ); | 289 | readConfig( cfg ); |
290 | 290 | ||
291 | initializeStates(); | 291 | initializeStates(); |
292 | } | 292 | } |
293 | 293 | ||
294 | 294 | ||
295 | PlayListWidget::~PlayListWidget() { | 295 | PlayListWidget::~PlayListWidget() { |
296 | Config cfg( "MediaPlayer" ); | 296 | Config cfg( "MediaPlayer" ); |
297 | writeConfig( cfg ); | 297 | writeConfig( cfg ); |
298 | 298 | ||
299 | if ( d->current ) | 299 | if ( d->current ) |
300 | delete d->current; | 300 | delete d->current; |
301 | delete d; | 301 | delete d; |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | void PlayListWidget::initializeStates() { | 305 | void PlayListWidget::initializeStates() { |
306 | 306 | ||
307 | d->tbPlay->setOn( mediaPlayerState->playing() ); | 307 | d->tbPlay->setOn( mediaPlayerState->playing() ); |
308 | d->tbLoop->setOn( mediaPlayerState->looping() ); | 308 | d->tbLoop->setOn( mediaPlayerState->looping() ); |
309 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); | 309 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); |
310 | // d->tbFull->setOn( mediaPlayerState->fullscreen() ); | 310 | // d->tbFull->setOn( mediaPlayerState->fullscreen() ); |
311 | // d->tbScale->setOn( mediaPlayerState->scaled() ); | 311 | // d->tbScale->setOn( mediaPlayerState->scaled() ); |
312 | // d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); | 312 | // d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); |
313 | // setPlaylist( mediaPlayerState->playlist() ); | 313 | // setPlaylist( mediaPlayerState->playlist() ); |
314 | setPlaylist( true); | 314 | setPlaylist( true); |
315 | d->selectedFiles->first(); | 315 | d->selectedFiles->first(); |
316 | 316 | ||
317 | } | 317 | } |
318 | 318 | ||
319 | 319 | ||
320 | void PlayListWidget::readConfig( Config& cfg ) { | 320 | void PlayListWidget::readConfig( Config& cfg ) { |
321 | cfg.setGroup("PlayList"); | 321 | cfg.setGroup("PlayList"); |
322 | 322 | ||
323 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 323 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
324 | 324 | ||
325 | for ( int i = 0; i < noOfFiles; i++ ) { | 325 | for ( int i = 0; i < noOfFiles; i++ ) { |
326 | QString entryName; | 326 | QString entryName; |
327 | entryName.sprintf( "File%i", i + 1 ); | 327 | entryName.sprintf( "File%i", i + 1 ); |
328 | QString linkFile = cfg.readEntry( entryName ); | 328 | QString linkFile = cfg.readEntry( entryName ); |
329 | DocLnk lnk( linkFile ); | 329 | DocLnk lnk( linkFile ); |
330 | if ( lnk.isValid() ) | 330 | if ( lnk.isValid() ) |
331 | d->selectedFiles->addToSelection( lnk ); | 331 | d->selectedFiles->addToSelection( lnk ); |
332 | } | 332 | } |
333 | } | 333 | } |
334 | 334 | ||
335 | 335 | ||
336 | void PlayListWidget::writeConfig( Config& cfg ) const { | 336 | void PlayListWidget::writeConfig( Config& cfg ) const { |
337 | cfg.setGroup("PlayList"); | 337 | cfg.setGroup("PlayList"); |
338 | 338 | ||
339 | int noOfFiles = 0; | 339 | int noOfFiles = 0; |
340 | 340 | ||
341 | d->selectedFiles->first(); | 341 | d->selectedFiles->first(); |
342 | do { | 342 | do { |
343 | const DocLnk *lnk = d->selectedFiles->current(); | 343 | const DocLnk *lnk = d->selectedFiles->current(); |
344 | if ( lnk ) { | 344 | if ( lnk ) { |
345 | QString entryName; | 345 | QString entryName; |
346 | entryName.sprintf( "File%i", noOfFiles + 1 ); | 346 | entryName.sprintf( "File%i", noOfFiles + 1 ); |
347 | cfg.writeEntry( entryName, lnk->linkFile() ); | 347 | cfg.writeEntry( entryName, lnk->linkFile() ); |
348 | // if this link does exist, add it so we have the file | 348 | // if this link does exist, add it so we have the file |
349 | // next time... | 349 | // next time... |
350 | if ( !QFile::exists( lnk->linkFile() ) ) { | 350 | if ( !QFile::exists( lnk->linkFile() ) ) { |
351 | // the way writing lnks doesn't really check for out | 351 | // the way writing lnks doesn't really check for out |
352 | // of disk space, but check it anyway. | 352 | // of disk space, but check it anyway. |
353 | if ( !lnk->writeLink() ) { | 353 | if ( !lnk->writeLink() ) { |
354 | QMessageBox::critical( 0, tr("Out of space"), | 354 | QMessageBox::critical( 0, tr("Out of space"), |
355 | tr( "There was a problem saving " | 355 | tr( "There was a problem saving " |
356 | "the playlist.\n" | 356 | "the playlist.\n" |
357 | "Your playlist " | 357 | "Your playlist " |
358 | "may be missing some entries\n" | 358 | "may be missing some entries\n" |
359 | "the next time you start it." ) | 359 | "the next time you start it." ) |
360 | ); | 360 | ); |
361 | } | 361 | } |
362 | } | 362 | } |
363 | noOfFiles++; | 363 | noOfFiles++; |
364 | } | 364 | } |
365 | } while ( d->selectedFiles->next() ); | 365 | } while ( d->selectedFiles->next() ); |
366 | 366 | ||
367 | cfg.writeEntry("NumberOfFiles", noOfFiles ); | 367 | cfg.writeEntry("NumberOfFiles", noOfFiles ); |
368 | 368 | ||
369 | 369 | ||
370 | } | 370 | } |
371 | 371 | ||
372 | 372 | ||
373 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { | 373 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { |
374 | qDebug("add"); | 374 | qDebug("add"); |
375 | d->setDocumentUsed = FALSE; | 375 | d->setDocumentUsed = FALSE; |
376 | if ( mediaPlayerState->playlist() ) | 376 | if ( mediaPlayerState->playlist() ) |
377 | d->selectedFiles->addToSelection( lnk ); | 377 | d->selectedFiles->addToSelection( lnk ); |
378 | else | 378 | else |
379 | mediaPlayerState->setPlaying( TRUE ); | 379 | mediaPlayerState->setPlaying( TRUE ); |
380 | } | 380 | } |
381 | 381 | ||
382 | 382 | ||
383 | void PlayListWidget::clearList() { | 383 | void PlayListWidget::clearList() { |
384 | while ( first() ) | 384 | while ( first() ) |
385 | d->selectedFiles->removeSelected(); | 385 | d->selectedFiles->removeSelected(); |
386 | } | 386 | } |
387 | 387 | ||
388 | 388 | ||
389 | void PlayListWidget::addAllToList() { | 389 | void PlayListWidget::addAllToList() { |
390 | DocLnkSet files; | 390 | DocLnkSet files; |
391 | Global::findDocuments(&files, "video/*;audio/*"); | 391 | Global::findDocuments(&files, "video/*;audio/*"); |
392 | QListIterator<DocLnk> dit( files.children() ); | 392 | QListIterator<DocLnk> dit( files.children() ); |
393 | for ( ; dit.current(); ++dit ) | 393 | for ( ; dit.current(); ++dit ) |
394 | d->selectedFiles->addToSelection( **dit ); | 394 | d->selectedFiles->addToSelection( **dit ); |
395 | } | 395 | } |
396 | 396 | ||
397 | 397 | ||
398 | void PlayListWidget::addAllMusicToList() { | 398 | void PlayListWidget::addAllMusicToList() { |
399 | DocLnkSet files; | 399 | DocLnkSet files; |
400 | Global::findDocuments(&files, "audio/*"); | 400 | Global::findDocuments(&files, "audio/*"); |
401 | QListIterator<DocLnk> dit( files.children() ); | 401 | QListIterator<DocLnk> dit( files.children() ); |
402 | for ( ; dit.current(); ++dit ) | 402 | for ( ; dit.current(); ++dit ) |
403 | d->selectedFiles->addToSelection( **dit ); | 403 | d->selectedFiles->addToSelection( **dit ); |
404 | } | 404 | } |
405 | 405 | ||
406 | 406 | ||
407 | void PlayListWidget::addAllVideoToList() { | 407 | void PlayListWidget::addAllVideoToList() { |
408 | DocLnkSet files; | 408 | DocLnkSet files; |
409 | Global::findDocuments(&files, "video/*"); | 409 | Global::findDocuments(&files, "video/*"); |
410 | QListIterator<DocLnk> dit( files.children() ); | 410 | QListIterator<DocLnk> dit( files.children() ); |
411 | for ( ; dit.current(); ++dit ) | 411 | for ( ; dit.current(); ++dit ) |
412 | d->selectedFiles->addToSelection( **dit ); | 412 | d->selectedFiles->addToSelection( **dit ); |
413 | } | 413 | } |
414 | 414 | ||
415 | 415 | ||
416 | void PlayListWidget::setDocument(const QString& fileref) { | 416 | void PlayListWidget::setDocument(const QString& fileref) { |
417 | if ( fileref.isNull() ) { | 417 | if ( fileref.isNull() ) { |
418 | QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); | 418 | QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); |
419 | return; | 419 | return; |
420 | } | 420 | } |
421 | if ( mediaPlayerState->playlist() ) | 421 | addToSelection( DocLnk( fileref ) ); |
422 | addToSelection( DocLnk( fileref ) ); | 422 | d->setDocumentUsed = TRUE; |
423 | else { | 423 | qApp->processEvents(); |
424 | d->setDocumentUsed = TRUE; | ||
425 | if ( d->current ) | ||
426 | delete d->current; | ||
427 | d->current = new DocLnk( fileref ); | ||
428 | } | ||
429 | mediaPlayerState->setPlaying( FALSE ); | 424 | mediaPlayerState->setPlaying( FALSE ); |
425 | qApp->processEvents(); | ||
430 | mediaPlayerState->setPlaying( TRUE ); | 426 | mediaPlayerState->setPlaying( TRUE ); |
427 | d->selectedFiles->removeSelected( ); | ||
431 | } | 428 | } |
432 | 429 | ||
433 | 430 | ||
434 | void PlayListWidget::setActiveWindow() { | 431 | void PlayListWidget::setActiveWindow() { |
435 | // When we get raised we need to ensure that it switches views | 432 | // When we get raised we need to ensure that it switches views |
436 | char origView = mediaPlayerState->view(); | 433 | char origView = mediaPlayerState->view(); |
437 | mediaPlayerState->setView( 'l' ); // invalidate | 434 | mediaPlayerState->setView( 'l' ); // invalidate |
438 | mediaPlayerState->setView( origView ); // now switch back | 435 | mediaPlayerState->setView( origView ); // now switch back |
439 | } | 436 | } |
440 | 437 | ||
441 | 438 | ||
442 | void PlayListWidget::useSelectedDocument() { | 439 | void PlayListWidget::useSelectedDocument() { |
443 | d->setDocumentUsed = FALSE; | 440 | d->setDocumentUsed = FALSE; |
444 | } | 441 | } |
445 | 442 | ||
446 | 443 | ||
447 | const DocLnk *PlayListWidget::current() { | 444 | const DocLnk *PlayListWidget::current() { |
448 | 445 | ||
449 | // qDebug("in Playlist widget ::current"); | 446 | // qDebug("in Playlist widget ::current"); |
450 | if ( mediaPlayerState->playlist() ) { | 447 | if ( mediaPlayerState->playlist() ) { |
451 | return d->selectedFiles->current(); | 448 | return d->selectedFiles->current(); |
452 | } | 449 | } |
453 | else if ( d->setDocumentUsed && d->current ) { | 450 | else if ( d->setDocumentUsed && d->current ) { |
454 | return d->current; | 451 | return d->current; |
455 | } else { | 452 | } else { |
456 | return d->files->selected(); | 453 | return d->files->selected(); |
457 | } | 454 | } |
458 | } | 455 | } |
459 | 456 | ||
460 | 457 | ||
461 | bool PlayListWidget::prev() { | 458 | bool PlayListWidget::prev() { |
462 | if ( mediaPlayerState->playlist() ) { | 459 | if ( mediaPlayerState->playlist() ) { |
463 | if ( mediaPlayerState->shuffled() ) { | 460 | if ( mediaPlayerState->shuffled() ) { |
464 | const DocLnk *cur = current(); | 461 | const DocLnk *cur = current(); |
465 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); | 462 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); |
466 | for ( int i = 0; i < j; i++ ) { | 463 | for ( int i = 0; i < j; i++ ) { |
467 | if ( !d->selectedFiles->next() ) | 464 | if ( !d->selectedFiles->next() ) |
468 | d->selectedFiles->first(); | 465 | d->selectedFiles->first(); |
469 | } | 466 | } |
470 | if ( cur == current() ) | 467 | if ( cur == current() ) |
471 | if ( !d->selectedFiles->next() ) | 468 | if ( !d->selectedFiles->next() ) |
472 | d->selectedFiles->first(); | 469 | d->selectedFiles->first(); |
473 | return TRUE; | 470 | return TRUE; |
474 | } else { | 471 | } else { |
475 | if ( !d->selectedFiles->prev() ) { | 472 | if ( !d->selectedFiles->prev() ) { |
476 | if ( mediaPlayerState->looping() ) { | 473 | if ( mediaPlayerState->looping() ) { |
477 | return d->selectedFiles->last(); | 474 | return d->selectedFiles->last(); |
478 | } else { | 475 | } else { |
479 | return FALSE; | 476 | return FALSE; |
480 | } | 477 | } |
481 | } | 478 | } |
482 | return TRUE; | 479 | return TRUE; |
483 | } | 480 | } |
484 | } else { | 481 | } else { |
485 | return mediaPlayerState->looping(); | 482 | return mediaPlayerState->looping(); |
486 | } | 483 | } |
487 | } | 484 | } |
488 | 485 | ||
489 | 486 | ||
490 | bool PlayListWidget::next() { | 487 | bool PlayListWidget::next() { |
491 | if ( mediaPlayerState->playlist() ) { | 488 | if ( mediaPlayerState->playlist() ) { |
492 | if ( mediaPlayerState->shuffled() ) { | 489 | if ( mediaPlayerState->shuffled() ) { |
493 | return prev(); | 490 | return prev(); |
494 | } else { | 491 | } else { |
495 | if ( !d->selectedFiles->next() ) { | 492 | if ( !d->selectedFiles->next() ) { |
496 | if ( mediaPlayerState->looping() ) { | 493 | if ( mediaPlayerState->looping() ) { |
497 | return d->selectedFiles->first(); | 494 | return d->selectedFiles->first(); |
498 | } else { | 495 | } else { |
499 | return FALSE; | 496 | return FALSE; |
500 | } | 497 | } |
501 | } | 498 | } |
502 | return TRUE; | 499 | return TRUE; |
503 | } | 500 | } |
504 | } else { | 501 | } else { |
505 | return mediaPlayerState->looping(); | 502 | return mediaPlayerState->looping(); |
506 | } | 503 | } |
507 | } | 504 | } |
508 | 505 | ||
509 | 506 | ||
510 | bool PlayListWidget::first() { | 507 | bool PlayListWidget::first() { |
511 | if ( mediaPlayerState->playlist() ) | 508 | if ( mediaPlayerState->playlist() ) |
512 | return d->selectedFiles->first(); | 509 | return d->selectedFiles->first(); |
513 | else | 510 | else |
514 | return mediaPlayerState->looping(); | 511 | return mediaPlayerState->looping(); |
515 | } | 512 | } |
516 | 513 | ||
517 | 514 | ||
518 | bool PlayListWidget::last() { | 515 | bool PlayListWidget::last() { |
519 | if ( mediaPlayerState->playlist() ) | 516 | if ( mediaPlayerState->playlist() ) |
520 | return d->selectedFiles->last(); | 517 | return d->selectedFiles->last(); |
521 | else | 518 | else |
522 | return mediaPlayerState->looping(); | 519 | return mediaPlayerState->looping(); |
523 | } | 520 | } |
524 | 521 | ||
525 | 522 | ||
526 | void PlayListWidget::saveList() { | 523 | void PlayListWidget::saveList() { |
527 | 524 | ||
528 | QString filename; | 525 | QString filename; |
529 | InputDialog *fileDlg; | 526 | InputDialog *fileDlg; |
530 | fileDlg=new InputDialog(this,"Save Playlist",TRUE, 0); | 527 | fileDlg=new InputDialog(this,"Save Playlist",TRUE, 0); |
531 | fileDlg->exec(); | 528 | fileDlg->exec(); |
532 | if( fileDlg->result() == 1 ) { | 529 | if( fileDlg->result() == 1 ) { |
533 | filename = fileDlg->LineEdit1->text();//+".playlist"; | 530 | filename = fileDlg->LineEdit1->text();//+".playlist"; |
534 | qDebug("saving playlist "+filename+".playlist"); | 531 | qDebug("saving playlist "+filename+".playlist"); |
535 | 532 | ||
536 | // DocLnk *lnk; | 533 | // DocLnk *lnk; |
537 | // lnk.setName( filename); //sets file name | 534 | // lnk.setName( filename); //sets file name |
538 | // // lnk.setComment(title); | 535 | // // lnk.setComment(title); |
539 | // lnk.setFile( filename+".playlist"); //sets File property | 536 | // lnk.setFile( filename+".playlist"); //sets File property |
540 | // lnk.setType("player/plain");// hey is this a REGISTERED mime type?!?!? ;D | 537 | // lnk.setType("player/plain");// hey is this a REGISTERED mime type?!?!? ;D |
541 | // lnk.setIcon("MPEGPlayer"); | 538 | // lnk.setIcon("MPEGPlayer"); |
542 | // if(!lnk.writeLink()) | 539 | // if(!lnk.writeLink()) |
543 | // qDebug("Writing doclink did not work"); | 540 | // qDebug("Writing doclink did not work"); |
544 | 541 | ||
545 | Config cfg( filename +".playlist"); | 542 | Config cfg( filename +".playlist"); |
546 | writeConfig( cfg ); | 543 | writeConfig( cfg ); |
547 | } | 544 | } |
548 | DocLnk lnk; | 545 | DocLnk lnk; |
549 | lnk.setName( filename); //sets file name | 546 | lnk.setName( filename); //sets file name |
550 | // lnk.setComment(title); | 547 | // lnk.setComment(title); |
551 | lnk.setFile(QPEApplication::qpeDir()+"Settings/"+filename+".playlist.conf"); //sets File property | 548 | lnk.setFile(QPEApplication::qpeDir()+"Settings/"+filename+".playlist.conf"); //sets File property |
552 | lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D | 549 | lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D |
553 | lnk.setIcon("MPEGPlayer"); | 550 | lnk.setIcon("MPEGPlayer"); |
554 | if(!lnk.writeLink()) | 551 | if(!lnk.writeLink()) |
555 | qDebug("Writing doclink did not work"); | 552 | qDebug("Writing doclink did not work"); |
556 | 553 | ||
557 | if(fileDlg) | 554 | if(fileDlg) |
558 | delete fileDlg; | 555 | delete fileDlg; |
559 | } | 556 | } |
560 | 557 | ||
561 | 558 | ||
562 | void PlayListWidget::loadList( const DocLnk & lnk) { | 559 | void PlayListWidget::loadList( const DocLnk & lnk) { |
563 | qDebug("load list "+ lnk.name()+".playlist"); | 560 | qDebug("load list "+ lnk.name()+".playlist"); |
564 | clearList(); | 561 | clearList(); |
565 | Config cfg( lnk.name()+".playlist"); | 562 | Config cfg( lnk.name()+".playlist"); |
566 | readConfig(cfg); | 563 | readConfig(cfg); |
567 | tabWidget->setCurrentPage(0); | 564 | tabWidget->setCurrentPage(0); |
568 | setCaption("OpiePlayer: "+lnk.name()); | 565 | setCaption("OpiePlayer: "+lnk.name()); |
569 | } | 566 | } |
570 | 567 | ||
571 | 568 | ||
572 | void PlayListWidget::setPlaylist( bool shown ) { | 569 | void PlayListWidget::setPlaylist( bool shown ) { |
573 | if ( shown ) | 570 | if ( shown ) |
574 | d->playListFrame->show(); | 571 | d->playListFrame->show(); |
575 | else | 572 | else |
576 | d->playListFrame->hide(); | 573 | d->playListFrame->hide(); |
577 | } | 574 | } |
578 | 575 | ||
579 | 576 | ||
580 | void PlayListWidget::setView( char view ) { | 577 | void PlayListWidget::setView( char view ) { |
581 | if ( view == 'l' ) | 578 | if ( view == 'l' ) |
582 | showMaximized(); | 579 | showMaximized(); |
583 | else | 580 | else |
584 | hide(); | 581 | hide(); |
585 | } | 582 | } |
586 | 583 | ||
587 | void PlayListWidget::addSelected() { | 584 | void PlayListWidget::addSelected() { |
588 | 585 | ||
589 | switch (tabWidget->currentPageIndex()) { | 586 | switch (tabWidget->currentPageIndex()) { |
590 | case 0: //playlist | 587 | case 0: //playlist |
591 | break; | 588 | break; |
592 | case 1: { //audio | 589 | case 1: { //audio |
593 | addToSelection( audioView->selectedItem() ); | 590 | addToSelection( audioView->selectedItem() ); |
594 | } | 591 | } |
595 | break; | 592 | break; |
596 | case 2: { // video | 593 | case 2: { // video |
597 | addToSelection( videoView->selectedItem() ); | 594 | addToSelection( videoView->selectedItem() ); |
598 | } | 595 | } |
599 | break; | 596 | break; |
600 | }; | 597 | }; |
601 | } | 598 | } |
602 | 599 | ||
603 | void PlayListWidget::removeSelected() { | 600 | void PlayListWidget::removeSelected() { |
604 | d->selectedFiles->removeSelected( ); | 601 | d->selectedFiles->removeSelected( ); |
605 | } | 602 | } |
606 | 603 | ||
607 | 604 | ||
608 | void PlayListWidget::playIt( QListViewItem *it) { | 605 | void PlayListWidget::playIt( QListViewItem *it) { |
609 | // d->setDocumentUsed = FALSE; | 606 | // d->setDocumentUsed = FALSE; |
610 | mediaPlayerState->setPlaying(TRUE); | 607 | mediaPlayerState->setPlaying(TRUE); |
611 | } | 608 | } |
612 | 609 | ||
613 | void PlayListWidget::addToSelection( QListViewItem *it) { | 610 | void PlayListWidget::addToSelection( QListViewItem *it) { |
614 | d->setDocumentUsed = FALSE; | 611 | d->setDocumentUsed = FALSE; |
615 | 612 | ||
616 | if(it) { | 613 | if(it) { |
617 | // qDebug("add to selection"); | 614 | // qDebug("add to selection"); |
618 | switch (tabWidget->currentPageIndex()) { | 615 | switch (tabWidget->currentPageIndex()) { |
619 | case 1: { | 616 | case 1: { |
620 | // qDebug("case 1"); | 617 | // qDebug("case 1"); |
621 | QListIterator<DocLnk> dit( files.children() ); | 618 | QListIterator<DocLnk> dit( files.children() ); |
622 | for ( ; dit.current(); ++dit ) { | 619 | for ( ; dit.current(); ++dit ) { |
623 | // qDebug(dit.current()->name()); | 620 | // qDebug(dit.current()->name()); |
624 | if( dit.current()->name() == it->text(0)) { | 621 | if( dit.current()->name() == it->text(0)) { |
625 | d->selectedFiles->addToSelection( **dit ); | 622 | d->selectedFiles->addToSelection( **dit ); |
626 | } | 623 | } |
627 | } | 624 | } |
628 | } | 625 | } |
629 | break; | 626 | break; |
630 | case 2: { | 627 | case 2: { |
631 | // qDebug("case 2"); | 628 | // qDebug("case 2"); |
632 | QListIterator<DocLnk> dit( vFiles.children() ); | 629 | QListIterator<DocLnk> dit( vFiles.children() ); |
633 | for ( ; dit.current(); ++dit ) { | 630 | for ( ; dit.current(); ++dit ) { |
634 | // qDebug(dit.current()->name()); | 631 | // qDebug(dit.current()->name()); |
635 | if( dit.current()->name() == it->text(0)) { | 632 | if( dit.current()->name() == it->text(0)) { |
636 | d->selectedFiles->addToSelection( **dit ); | 633 | d->selectedFiles->addToSelection( **dit ); |
637 | } | 634 | } |
638 | } | 635 | } |
639 | } | 636 | } |
640 | break; | 637 | break; |
641 | case 0: | 638 | case 0: |
642 | break; | 639 | break; |
643 | }; | 640 | }; |
644 | tabWidget->setCurrentPage(0); | 641 | tabWidget->setCurrentPage(0); |
645 | // mediaPlayerState->setPlaying( TRUE ); | 642 | // mediaPlayerState->setPlaying( TRUE ); |
646 | } | 643 | } |
647 | } | 644 | } |
648 | 645 | ||
649 | void PlayListWidget::tabChanged(QWidget *widg) { | 646 | void PlayListWidget::tabChanged(QWidget *widg) { |
650 | 647 | ||
651 | switch ( tabWidget->currentPageIndex()) { | 648 | switch ( tabWidget->currentPageIndex()) { |
652 | case 0: | 649 | case 0: |
653 | { | 650 | { |
654 | if( !tbDeletePlaylist->isHidden()) | 651 | if( !tbDeletePlaylist->isHidden()) |
655 | tbDeletePlaylist->hide(); | 652 | tbDeletePlaylist->hide(); |
656 | d->tbRemoveFromList->setEnabled(TRUE); | 653 | d->tbRemoveFromList->setEnabled(TRUE); |
657 | d->tbAddToList->setEnabled(FALSE); | 654 | d->tbAddToList->setEnabled(FALSE); |
658 | } | 655 | } |
659 | break; | 656 | break; |
660 | case 1: | 657 | case 1: |
661 | { | 658 | { |
662 | if( !tbDeletePlaylist->isHidden()) | 659 | if( !tbDeletePlaylist->isHidden()) |
663 | tbDeletePlaylist->hide(); | 660 | tbDeletePlaylist->hide(); |
664 | d->tbRemoveFromList->setEnabled(FALSE); | 661 | d->tbRemoveFromList->setEnabled(FALSE); |
665 | d->tbAddToList->setEnabled(TRUE); | 662 | d->tbAddToList->setEnabled(TRUE); |
666 | } | 663 | } |
667 | break; | 664 | break; |
668 | case 2: | 665 | case 2: |
669 | { | 666 | { |
670 | if( !tbDeletePlaylist->isHidden()) | 667 | if( !tbDeletePlaylist->isHidden()) |
671 | tbDeletePlaylist->hide(); | 668 | tbDeletePlaylist->hide(); |
672 | d->tbRemoveFromList->setEnabled(FALSE); | 669 | d->tbRemoveFromList->setEnabled(FALSE); |
673 | d->tbAddToList->setEnabled(TRUE); | 670 | d->tbAddToList->setEnabled(TRUE); |
674 | } | 671 | } |
675 | break; | 672 | break; |
676 | case 3: | 673 | case 3: |
677 | { | 674 | { |
678 | if( tbDeletePlaylist->isHidden()) | 675 | if( tbDeletePlaylist->isHidden()) |
679 | tbDeletePlaylist->show(); | 676 | tbDeletePlaylist->show(); |
680 | playLists->reread(); | 677 | playLists->reread(); |
681 | } | 678 | } |
682 | break; | 679 | break; |
683 | }; | 680 | }; |
684 | } | 681 | } |
685 | 682 | ||
686 | /* | 683 | /* |
687 | list is right clicked*/ | 684 | list is right clicked*/ |
688 | void PlayListWidget::fauxPlay(QListViewItem *it) { | 685 | void PlayListWidget::fauxPlay(QListViewItem *it) { |
689 | 686 | ||
690 | switch (tabWidget->currentPageIndex()) { | 687 | switch (tabWidget->currentPageIndex()) { |
691 | case 0: //playlist | 688 | case 0: //playlist |
692 | break; | 689 | break; |
693 | case 1: { //audio | 690 | case 1: { //audio |
694 | QListIterator<DocLnk> dit( files.children() ); | 691 | QListIterator<DocLnk> dit( files.children() ); |
695 | for ( ; dit.current(); ++dit ) { | 692 | for ( ; dit.current(); ++dit ) { |
696 | // qDebug(dit.current()->name()); | 693 | // qDebug(dit.current()->name()); |
697 | if( dit.current()->name() == it->text(0)) { | 694 | if( dit.current()->name() == it->text(0)) { |
698 | d->selectedFiles->addToSelection( **dit ); | 695 | d->selectedFiles->addToSelection( **dit ); |
699 | } | 696 | } |
700 | } | 697 | } |
701 | } | 698 | } |
702 | break; | 699 | break; |
703 | case 2: { // video | 700 | case 2: { // video |
704 | QListIterator<DocLnk> dit( vFiles.children() ); | 701 | QListIterator<DocLnk> dit( vFiles.children() ); |
705 | for ( ; dit.current(); ++dit ) { | 702 | for ( ; dit.current(); ++dit ) { |
706 | // qDebug(dit.current()->name()); | 703 | // qDebug(dit.current()->name()); |
707 | if( dit.current()->name() == it->text(0)) { | 704 | if( dit.current()->name() == it->text(0)) { |
708 | d->selectedFiles->addToSelection( **dit ); | 705 | d->selectedFiles->addToSelection( **dit ); |
709 | } | 706 | } |
710 | } | 707 | } |
711 | } | 708 | } |
712 | break; | 709 | break; |
713 | }; | 710 | }; |
714 | mediaPlayerState->setPlaying( TRUE ); | 711 | mediaPlayerState->setPlaying( TRUE ); |
715 | // tabWidget->setCurrentPage(0); | 712 | // tabWidget->setCurrentPage(0); |
716 | d->selectedFiles->removeSelected(); | 713 | d->selectedFiles->removeSelected(); |
717 | } | 714 | } |
718 | 715 | ||
719 | /* | 716 | /* |
720 | play button is pressed*/ | 717 | play button is pressed*/ |
721 | void PlayListWidget::btnPlay(bool b) { // this is fugly | 718 | void PlayListWidget::btnPlay(bool b) { // this is fugly |
722 | switch ( tabWidget->currentPageIndex()) { | 719 | switch ( tabWidget->currentPageIndex()) { |
723 | case 0: | 720 | case 0: |
724 | { | 721 | { |
725 | mediaPlayerState->setPlaying(b); | 722 | mediaPlayerState->setPlaying(b); |
726 | } | 723 | } |
727 | break; | 724 | break; |
728 | case 1: | 725 | case 1: |
729 | { | 726 | { |
730 | addToSelection( audioView->selectedItem() ); | 727 | addToSelection( audioView->selectedItem() ); |
731 | mediaPlayerState->setPlaying(b); | 728 | mediaPlayerState->setPlaying(b); |
732 | qApp->processEvents(); | 729 | qApp->processEvents(); |
733 | d->selectedFiles->removeSelected( ); | 730 | d->selectedFiles->removeSelected( ); |
734 | tabWidget->setCurrentPage(1); | 731 | tabWidget->setCurrentPage(1); |
735 | } | 732 | } |
736 | break; | 733 | break; |
737 | case 2: | 734 | case 2: |
738 | { | 735 | { |
739 | addToSelection( videoView->selectedItem() ); | 736 | addToSelection( videoView->selectedItem() ); |
740 | mediaPlayerState->setPlaying(b); | 737 | mediaPlayerState->setPlaying(b); |
741 | qApp->processEvents(); | 738 | qApp->processEvents(); |
742 | d->selectedFiles->removeSelected( ); | 739 | d->selectedFiles->removeSelected( ); |
743 | tabWidget->setCurrentPage(2); | 740 | tabWidget->setCurrentPage(2); |
744 | } | 741 | } |
745 | break; | 742 | break; |
746 | }; | 743 | }; |
747 | 744 | ||
748 | } | 745 | } |
749 | 746 | ||
750 | void PlayListWidget::deletePlaylist() { | 747 | void PlayListWidget::deletePlaylist() { |
751 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), | 748 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), |
752 | (tr("You really want to delete\nthis playlist?")), | 749 | (tr("You really want to delete\nthis playlist?")), |
753 | (tr("Yes")), (tr("No")), 0 )){ | 750 | (tr("Yes")), (tr("No")), 0 )){ |
754 | case 0: // Yes clicked, | 751 | case 0: // Yes clicked, |
755 | QFile().remove(playLists->selected()->file()); | 752 | QFile().remove(playLists->selected()->file()); |
756 | QFile().remove(playLists->selected()->linkFile()); | 753 | QFile().remove(playLists->selected()->linkFile()); |
757 | playLists->reread(); | 754 | playLists->reread(); |
758 | break; | 755 | break; |
759 | case 1: // Cancel | 756 | case 1: // Cancel |
760 | break; | 757 | break; |
761 | }; | 758 | }; |
762 | 759 | ||
763 | } | 760 | } |
diff --git a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp index 4a0da16..4e82900 100644 --- a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp +++ b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp | |||
@@ -1,342 +1,342 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of 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 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // L.J.Potter added changes Fri 02-15-2002 | 20 | // L.J.Potter added changes Fri 02-15-2002 |
21 | 21 | ||
22 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | #include <stdarg.h> | 23 | #include <stdarg.h> |
24 | #include <stdlib.h> | 24 | #include <stdlib.h> |
25 | #include <errno.h> | 25 | #include <errno.h> |
26 | #include <unistd.h> | 26 | #include <unistd.h> |
27 | #include <qfile.h> | 27 | #include <qfile.h> |
28 | #include "wavplugin.h" | 28 | #include "wavplugin.h" |
29 | 29 | ||
30 | //#define debugMsg(a) qDebug(a) | 30 | //#define debugMsg(a) qDebug(a) |
31 | #define debugMsg(a) | 31 | #define debugMsg(a) |
32 | 32 | ||
33 | 33 | ||
34 | struct RiffChunk { | 34 | struct RiffChunk { |
35 | char id[4]; | 35 | char id[4]; |
36 | Q_UINT32 size; | 36 | Q_UINT32 size; |
37 | char data[4]; | 37 | char data[4]; |
38 | }; | 38 | }; |
39 | 39 | ||
40 | 40 | ||
41 | struct ChunkData { | 41 | struct ChunkData { |
42 | Q_INT16 formatTag; | 42 | Q_INT16 formatTag; |
43 | Q_INT16 channels; | 43 | Q_INT16 channels; |
44 | Q_INT32 samplesPerSec; | 44 | Q_INT32 samplesPerSec; |
45 | Q_INT32 avgBytesPerSec; | 45 | Q_INT32 avgBytesPerSec; |
46 | Q_INT16 blockAlign; | 46 | Q_INT16 blockAlign; |
47 | Q_INT16 wBitsPerSample; | 47 | Q_INT16 wBitsPerSample; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | 50 | ||
51 | const int sound_buffer_size = 512; // 4096; // you got to be kidding right? | 51 | const int sound_buffer_size = 512; // 4096; // you got to be kidding right? |
52 | 52 | ||
53 | 53 | ||
54 | class WavPluginData { | 54 | class WavPluginData { |
55 | public: | 55 | public: |
56 | QFile *input; | 56 | QFile *input; |
57 | 57 | ||
58 | int wavedata_remaining; | 58 | int wavedata_remaining; |
59 | ChunkData chunkdata; | 59 | ChunkData chunkdata; |
60 | RiffChunk chunk; | 60 | RiffChunk chunk; |
61 | uchar data[sound_buffer_size+32]; // +32 to handle badly aligned input data | 61 | uchar data[sound_buffer_size+32]; // +32 to handle badly aligned input data |
62 | int out,max; | 62 | int out,max; |
63 | int samples_due; | 63 | int samples_due; |
64 | int samples; | 64 | int samples; |
65 | 65 | ||
66 | WavPluginData() { | 66 | WavPluginData() { |
67 | max = out = sound_buffer_size; | 67 | max = out = sound_buffer_size; |
68 | wavedata_remaining = 0; | 68 | wavedata_remaining = 0; |
69 | samples_due = 0; | 69 | samples_due = 0; |
70 | samples = -1; | 70 | samples = -1; |
71 | } | 71 | } |
72 | 72 | ||
73 | // expands out samples to the frequency of 44kHz //not any more | 73 | // expands out samples to the frequency of 44kHz //not any more |
74 | bool add( short *output, long count, long& done, bool stereo ) | 74 | bool add( short *output, long count, long& done, bool stereo ) |
75 | { | 75 | { |
76 | done = 0; | 76 | done = 0; |
77 | qApp->processEvents(); | ||
78 | 77 | ||
79 | if ( input == 0 ) { | 78 | if ( input == 0 ) { |
80 | qDebug("no input"); | 79 | qDebug("no input"); |
81 | return FALSE; | 80 | return FALSE; |
82 | } | 81 | } |
83 | 82 | ||
84 | while ( count ) { | 83 | while ( count ) { |
85 | int l,r; | 84 | int l,r; |
86 | if ( getSample(l, r) == FALSE ) { | 85 | if ( getSample(l, r) == FALSE ) { |
87 | qDebug("didn't get sample"); | 86 | qDebug("didn't get sample"); |
88 | return FALSE; | 87 | return FALSE; |
89 | } | 88 | } |
90 | samples_due += chunkdata.samplesPerSec; | 89 | samples_due += chunkdata.samplesPerSec; |
91 | printf("samples due %d\r", samples_due); | 90 | printf("samples due %d\r", samples_due); |
92 | fflush(stdout); | 91 | fflush(stdout); |
93 | while ( count && (samples_due > chunkdata.samplesPerSec) ) { | 92 | while ( count && (samples_due > chunkdata.samplesPerSec) ) { |
94 | *output++ = l; | 93 | *output++ = l; |
95 | if ( stereo ) | 94 | if ( stereo ) |
96 | *output++ = r; | 95 | *output++ = r; |
97 | samples_due -= chunkdata.samplesPerSec; | 96 | samples_due -= chunkdata.samplesPerSec; |
98 | count--; | 97 | count--; |
99 | done++; | 98 | done++; |
100 | } | 99 | } |
101 | } | 100 | } |
102 | return TRUE; | 101 | return TRUE; |
103 | } | 102 | } |
104 | 103 | ||
105 | bool initialise() { | 104 | bool initialise() { |
106 | if ( input == 0 ) | 105 | if ( input == 0 ) |
107 | return FALSE; | 106 | return FALSE; |
108 | 107 | ||
109 | wavedata_remaining = -1; | 108 | wavedata_remaining = -1; |
110 | 109 | ||
111 | while ( wavedata_remaining == -1 ) { | 110 | while ( wavedata_remaining == -1 ) { |
112 | // Keep reading chunks... | 111 | // Keep reading chunks... |
113 | const int n = sizeof(chunk) - sizeof(chunk.data); | 112 | const int n = sizeof(chunk) - sizeof(chunk.data); |
114 | int t = input->readBlock( (char*)&chunk, n ); | 113 | int t = input->readBlock( (char*)&chunk, n ); |
115 | if ( t != n ) { | 114 | if ( t != n ) { |
116 | if ( t == -1 ) | 115 | if ( t == -1 ) |
117 | return FALSE; | 116 | return FALSE; |
118 | return TRUE; | 117 | return TRUE; |
119 | } | 118 | } |
120 | if ( qstrncmp(chunk.id,"data",4) == 0 ) { | 119 | if ( qstrncmp(chunk.id,"data",4) == 0 ) { |
121 | samples = wavedata_remaining = chunk.size; | 120 | samples = wavedata_remaining = chunk.size; |
122 | } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { | 121 | } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { |
123 | char d[4]; | 122 | char d[4]; |
124 | if ( input->readBlock(d,4) != 4 ) { | 123 | if ( input->readBlock(d,4) != 4 ) { |
125 | return FALSE; | 124 | return FALSE; |
126 | } | 125 | } |
127 | if ( qstrncmp(d,"WAVE",4) != 0 ) { | 126 | if ( qstrncmp(d,"WAVE",4) != 0 ) { |
128 | // skip | 127 | // skip |
129 | if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size-4) ) { | 128 | if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size-4) ) { |
130 | return FALSE; | 129 | return FALSE; |
131 | } | 130 | } |
132 | } | 131 | } |
133 | } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) { | 132 | } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) { |
134 | if ( input->readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) { | 133 | if ( input->readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) { |
135 | return FALSE; | 134 | return FALSE; |
136 | } | 135 | } |
137 | #define WAVE_FORMAT_PCM 1 | 136 | #define WAVE_FORMAT_PCM 1 |
138 | if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { | 137 | if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { |
139 | qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); | 138 | qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); |
140 | return FALSE; | 139 | return FALSE; |
141 | } | 140 | } |
142 | } else { | 141 | } else { |
143 | // ignored chunk | 142 | // ignored chunk |
144 | if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size) ) { | 143 | if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size) ) { |
145 | return FALSE; | 144 | return FALSE; |
146 | } | 145 | } |
147 | } | 146 | } |
148 | } // while | 147 | } // while |
149 | qDebug("bits %d", chunkdata.wBitsPerSample); | 148 | qDebug("bits %d", chunkdata.wBitsPerSample); |
150 | return TRUE; | 149 | return TRUE; |
151 | } | 150 | } |
152 | 151 | ||
153 | 152 | ||
154 | // gets a sample from the file | 153 | // gets a sample from the file |
155 | bool getSample(int& l, int& r) | 154 | bool getSample(int& l, int& r) |
156 | { | 155 | { |
157 | l = r = 0; | 156 | l = r = 0; |
158 | 157 | ||
159 | if ( input == 0 ) | 158 | if ( input == 0 ) |
160 | return FALSE; | 159 | return FALSE; |
161 | 160 | ||
162 | if ( (wavedata_remaining < 0) || !max ) | 161 | if ( (wavedata_remaining < 0) || !max ) |
163 | return FALSE; | 162 | return FALSE; |
164 | 163 | ||
165 | if ( out >= max ) { | 164 | if ( out >= max ) { |
166 | max = input->readBlock( (char*)data, (uint)QMIN(sound_buffer_size,wavedata_remaining) ); | 165 | max = input->readBlock( (char*)data, (uint)QMIN(sound_buffer_size,wavedata_remaining) ); |
167 | 166 | ||
168 | wavedata_remaining -= max; | 167 | wavedata_remaining -= max; |
169 | 168 | ||
170 | out = 0; | 169 | out = 0; |
171 | if ( max <= 0 ) { | 170 | if ( max <= 0 ) { |
172 | max = 0; | 171 | max = 0; |
173 | return TRUE; | 172 | return TRUE; |
174 | } | 173 | } |
175 | } | 174 | } |
176 | if ( chunkdata.wBitsPerSample == 8 ) { | 175 | if ( chunkdata.wBitsPerSample == 8 ) { |
177 | l = (data[out++] - 128) * 128; | 176 | l = (data[out++] - 128) * 128; |
178 | } else { | 177 | } else { |
179 | l = ((short*)data)[out/2]; | 178 | l = ((short*)data)[out/2]; |
180 | out += 2; | 179 | out += 2; |
181 | } | 180 | } |
182 | if ( chunkdata.channels == 1 ) { | 181 | if ( chunkdata.channels == 1 ) { |
183 | r = l; | 182 | r = l; |
184 | } else { | 183 | } else { |
185 | if ( chunkdata.wBitsPerSample == 8 ) { | 184 | if ( chunkdata.wBitsPerSample == 8 ) { |
186 | r = (data[out++] - 128) * 128; | 185 | r = (data[out++] - 128) * 128; |
187 | } else { | 186 | } else { |
188 | r = ((short*)data)[out/2]; | 187 | r = ((short*)data)[out/2]; |
189 | out += 2; | 188 | out += 2; |
190 | } | 189 | } |
191 | } | 190 | } |
192 | return TRUE; | 191 | return TRUE; |
193 | } // getSample | 192 | } // getSample |
194 | 193 | ||
195 | }; | 194 | }; |
196 | 195 | ||
197 | 196 | ||
198 | WavPlugin::WavPlugin() { | 197 | WavPlugin::WavPlugin() { |
199 | d = new WavPluginData; | 198 | d = new WavPluginData; |
200 | d->input = 0; | 199 | d->input = 0; |
201 | } | 200 | } |
202 | 201 | ||
203 | 202 | ||
204 | WavPlugin::~WavPlugin() { | 203 | WavPlugin::~WavPlugin() { |
205 | close(); | 204 | close(); |
206 | delete d; | 205 | delete d; |
207 | } | 206 | } |
208 | 207 | ||
209 | 208 | ||
210 | bool WavPlugin::isFileSupported( const QString& path ) { | 209 | bool WavPlugin::isFileSupported( const QString& path ) { |
211 | // qDebug( "WavPlugin::isFileSupported" ); | 210 | // qDebug( "WavPlugin::isFileSupported" ); |
212 | 211 | ||
213 | char *ext = strrchr( path.latin1(), '.' ); | 212 | char *ext = strrchr( path.latin1(), '.' ); |
214 | 213 | ||
215 | // Test file extension | 214 | // Test file extension |
216 | if ( ext ) { | 215 | if ( ext ) { |
217 | if ( strncasecmp(ext, ".raw", 4) == 0 ) | 216 | if ( strncasecmp(ext, ".raw", 4) == 0 ) |
218 | return TRUE; | 217 | return TRUE; |
219 | if ( strncasecmp(ext, ".wav", 4) == 0 ) | 218 | if ( strncasecmp(ext, ".wav", 4) == 0 ) |
220 | return TRUE; | 219 | return TRUE; |
221 | if ( strncasecmp(ext, ".wave", 4) == 0 ) | 220 | if ( strncasecmp(ext, ".wave", 4) == 0 ) |
222 | return TRUE; | 221 | return TRUE; |
223 | } | 222 | } |
224 | 223 | ||
225 | return FALSE; | 224 | return FALSE; |
226 | } | 225 | } |
227 | 226 | ||
228 | 227 | ||
229 | bool WavPlugin::open( const QString& path ) { | 228 | bool WavPlugin::open( const QString& path ) { |
230 | // qDebug( "WavPlugin::open" ); | 229 | // qDebug( "WavPlugin::open" ); |
231 | 230 | ||
232 | d->max = d->out = sound_buffer_size; | 231 | d->max = d->out = sound_buffer_size; |
233 | d->wavedata_remaining = 0; | 232 | d->wavedata_remaining = 0; |
234 | d->samples_due = 0; | 233 | d->samples_due = 0; |
235 | 234 | ||
236 | d->input = new QFile( path ); | 235 | d->input = new QFile( path ); |
237 | if ( d->input->open(IO_ReadOnly) == FALSE ) { | 236 | if ( d->input->open(IO_ReadOnly) == FALSE ) { |
238 | qDebug("couldn't open file"); | 237 | qDebug("couldn't open file"); |
239 | delete d->input; | 238 | delete d->input; |
240 | d->input = 0; | 239 | d->input = 0; |
241 | return FALSE; | 240 | return FALSE; |
242 | } | 241 | } |
243 | 242 | ||
244 | d->initialise(); | 243 | d->initialise(); |
244 | qApp->processEvents(); | ||
245 | 245 | ||
246 | return TRUE; | 246 | return TRUE; |
247 | } | 247 | } |
248 | 248 | ||
249 | 249 | ||
250 | bool WavPlugin::close() { | 250 | bool WavPlugin::close() { |
251 | // qDebug( "WavPlugin::close" ); | 251 | // qDebug( "WavPlugin::close" ); |
252 | 252 | ||
253 | d->input->close(); | 253 | d->input->close(); |
254 | delete d->input; | 254 | delete d->input; |
255 | d->input = 0; | 255 | d->input = 0; |
256 | return TRUE; | 256 | return TRUE; |
257 | } | 257 | } |
258 | 258 | ||
259 | 259 | ||
260 | bool WavPlugin::isOpen() { | 260 | bool WavPlugin::isOpen() { |
261 | // qDebug( "WavPlugin::isOpen" ); | 261 | // qDebug( "WavPlugin::isOpen" ); |
262 | return ( d->input != 0 ); | 262 | return ( d->input != 0 ); |
263 | } | 263 | } |
264 | 264 | ||
265 | 265 | ||
266 | int WavPlugin::audioStreams() { | 266 | int WavPlugin::audioStreams() { |
267 | // qDebug( "WavPlugin::audioStreams" ); | 267 | // qDebug( "WavPlugin::audioStreams" ); |
268 | return 1; | 268 | return 1; |
269 | } | 269 | } |
270 | 270 | ||
271 | 271 | ||
272 | int WavPlugin::audioChannels( int ) { | 272 | int WavPlugin::audioChannels( int ) { |
273 | // qDebug( "WavPlugin::audioChannels" ); | 273 | // qDebug( "WavPlugin::audioChannels" ); |
274 | return d->chunkdata.channels;// 2; // ### Always scale audio to stereo samples | 274 | return d->chunkdata.channels;// 2; // ### Always scale audio to stereo samples |
275 | } | 275 | } |
276 | 276 | ||
277 | 277 | ||
278 | int WavPlugin::audioFrequency( int ) { | 278 | int WavPlugin::audioFrequency( int ) { |
279 | // qDebug( "WavPlugin::audioFrequency %d", d->chunkdata.samplesPerSec ); | 279 | // qDebug( "WavPlugin::audioFrequency %d", d->chunkdata.samplesPerSec ); |
280 | return d->chunkdata.samplesPerSec; //44100; // ### Always scale to frequency of 44100 | 280 | return d->chunkdata.samplesPerSec; //44100; // ### Always scale to frequency of 44100 |
281 | } | 281 | } |
282 | 282 | ||
283 | 283 | ||
284 | int WavPlugin::audioSamples( int ) { | 284 | int WavPlugin::audioSamples( int ) { |
285 | // qDebug( "WavPlugin::audioSamples" ); | 285 | // qDebug( "WavPlugin::audioSamples" ); |
286 | return d->samples / d->chunkdata.channels/2; // ### Scaled samples will be made stereo, | 286 | return d->samples / d->chunkdata.channels/2; // ### Scaled samples will be made stereo, |
287 | // Therefore if source is mono we will double the number of samples | 287 | // Therefore if source is mono we will double the number of samples |
288 | } | 288 | } |
289 | 289 | ||
290 | 290 | ||
291 | bool WavPlugin::audioSetSample( long, int ) { | 291 | bool WavPlugin::audioSetSample( long, int ) { |
292 | // qDebug( "WavPlugin::audioSetSample" ); | 292 | // qDebug( "WavPlugin::audioSetSample" ); |
293 | return FALSE; | 293 | return FALSE; |
294 | } | 294 | } |
295 | 295 | ||
296 | 296 | ||
297 | long WavPlugin::audioGetSample( int ) { | 297 | long WavPlugin::audioGetSample( int ) { |
298 | // qDebug( "WavPlugin::audioGetSample" ); | 298 | // qDebug( "WavPlugin::audioGetSample" ); |
299 | return 0; | 299 | return 0; |
300 | } | 300 | } |
301 | 301 | ||
302 | /* | 302 | /* |
303 | bool WavPlugin::audioReadSamples( short *, int, long, int ) { | 303 | bool WavPlugin::audioReadSamples( short *, int, long, int ) { |
304 | debugMsg( "WavPlugin::audioReadSamples" ); | 304 | debugMsg( "WavPlugin::audioReadSamples" ); |
305 | return FALSE; | 305 | return FALSE; |
306 | } | 306 | } |
307 | 307 | ||
308 | 308 | ||
309 | bool WavPlugin::audioReReadSamples( short *, int, long, int ) { | 309 | bool WavPlugin::audioReReadSamples( short *, int, long, int ) { |
310 | debugMsg( "WavPlugin::audioReReadSamples" ); | 310 | debugMsg( "WavPlugin::audioReReadSamples" ); |
311 | return FALSE; | 311 | return FALSE; |
312 | } | 312 | } |
313 | 313 | ||
314 | 314 | ||
315 | bool WavPlugin::audioReadMonoSamples( short *output, long samples, long& samplesMade, int ) { | 315 | bool WavPlugin::audioReadMonoSamples( short *output, long samples, long& samplesMade, int ) { |
316 | debugMsg( "WavPlugin::audioReadMonoSamples" ); | 316 | debugMsg( "WavPlugin::audioReadMonoSamples" ); |
317 | return !d->add( output, samples, samplesMade, FALSE ); | 317 | return !d->add( output, samples, samplesMade, FALSE ); |
318 | } | 318 | } |
319 | 319 | ||
320 | 320 | ||
321 | bool WavPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { | 321 | bool WavPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { |
322 | debugMsg( "WavPlugin::audioReadStereoSamples" ); | 322 | debugMsg( "WavPlugin::audioReadStereoSamples" ); |
323 | return !d->add( output, samples, samplesMade, TRUE ); | 323 | return !d->add( output, samples, samplesMade, TRUE ); |
324 | } | 324 | } |
325 | */ | 325 | */ |
326 | 326 | ||
327 | bool WavPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesMade, int ) { | 327 | bool WavPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesMade, int ) { |
328 | // qDebug( "WavPlugin::audioReadSamples" ); | 328 | // qDebug( "WavPlugin::audioReadSamples" ); |
329 | return d->add( output, samples, samplesMade, channels != 1 ); | 329 | return d->add( output, samples, samplesMade, channels != 1 ); |
330 | } | 330 | } |
331 | 331 | ||
332 | double WavPlugin::getTime() { | 332 | double WavPlugin::getTime() { |
333 | // qDebug( "WavPlugin::getTime" ); //this is a stupid hack here!! | 333 | // qDebug( "WavPlugin::getTime" ); //this is a stupid hack here!! |
334 | return d->chunkdata.wBitsPerSample; /*0.0*/; | 334 | return d->chunkdata.wBitsPerSample; /*0.0*/; |
335 | } | 335 | } |
336 | 336 | ||
337 | // int WavPlugin::audioBitsPerSample( int ) { | 337 | // int WavPlugin::audioBitsPerSample( int ) { |
338 | // // qDebug( "WavPlugin::audioFormat %d", d->chunkdata.wBitsPerSample ); | 338 | // // qDebug( "WavPlugin::audioFormat %d", d->chunkdata.wBitsPerSample ); |
339 | // return d->chunkdata.wBitsPerSample; // | 339 | // return d->chunkdata.wBitsPerSample; // |
340 | // } | 340 | // } |
341 | 341 | ||
342 | 342 | ||