Diffstat (limited to 'noncore/multimedia/opieplayer3/playlist.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer3/playlist.cpp | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/noncore/multimedia/opieplayer3/playlist.cpp b/noncore/multimedia/opieplayer3/playlist.cpp index babe8ce..2eb40e3 100644 --- a/noncore/multimedia/opieplayer3/playlist.cpp +++ b/noncore/multimedia/opieplayer3/playlist.cpp | |||
@@ -95,46 +95,57 @@ PlaylistView::PlaylistView(QWidget *parent, const char *name) | |||
95 | m_lastDir = QDir::homeDirPath(); | 95 | m_lastDir = QDir::homeDirPath(); |
96 | } | 96 | } |
97 | 97 | ||
98 | PlaylistView::~PlaylistView() | 98 | PlaylistView::~PlaylistView() |
99 | { | 99 | { |
100 | if (m_Infolib) delete m_Infolib; | 100 | if (m_Infolib) delete m_Infolib; |
101 | } | 101 | } |
102 | 102 | ||
103 | void PlaylistView::checkLib() | 103 | void PlaylistView::checkLib() |
104 | { | 104 | { |
105 | if (!m_Infolib) { | 105 | if (!m_Infolib) { |
106 | m_Infolib = new XINE::Lib(XINE::Lib::InitializeImmediately); | 106 | m_Infolib = new XINE::Lib(XINE::Lib::InitializeImmediately); |
107 | connect(m_Infolib,SIGNAL(stopped()),this,SLOT(slotDummyStop())); | ||
107 | m_Infolib->ensureInitialized(); | 108 | m_Infolib->ensureInitialized(); |
108 | } | 109 | } |
109 | } | 110 | } |
110 | 111 | ||
112 | void PlaylistView::slotDummyStop() | ||
113 | { | ||
114 | odebug << "void PlaylistView::slotDummyStop()" << oendl; | ||
115 | } | ||
116 | |||
111 | void PlaylistView::slotAddFile(const DocLnk&aLink) | 117 | void PlaylistView::slotAddFile(const DocLnk&aLink) |
112 | { | 118 | { |
113 | addFile(aLink.file(),aLink.name()); | 119 | QFileInfo f(aLink.file()); |
120 | if (f.extension(FALSE).lower()=="m3u"||f.extension(FALSE).lower()=="pls") { | ||
121 | readPlayList(aLink.file()); | ||
122 | } else { | ||
123 | addFile(aLink.file(),aLink.name()); | ||
124 | } | ||
114 | emit contentChanged(childCount()); | 125 | emit contentChanged(childCount()); |
115 | } | 126 | } |
116 | 127 | ||
117 | void PlaylistView::addFile(const QString&aFile,const QString&aName) | 128 | void PlaylistView::addFile(const QString&aFile,const QString&aName) |
118 | { | 129 | { |
119 | QFileInfo fileInfo(aFile); | 130 | QFileInfo fileInfo(aFile); |
120 | if (!fileInfo.exists()) return; | 131 | if (!fileInfo.exists()) return; |
121 | checkLib(); | 132 | checkLib(); |
122 | m_Infolib->stop(); | ||
123 | |||
124 | QString name = aName; | 133 | QString name = aName; |
125 | if (name.isEmpty()) { | 134 | if (name.isEmpty()) { |
126 | name = fileInfo.fileName(); | 135 | name = fileInfo.fileName(); |
127 | } | 136 | } |
128 | int i = m_Infolib->setfile(aFile.utf8().data()); | 137 | int i = m_Infolib->setfile(aFile.utf8().data()); |
138 | /* realy! otherwise we get an "stopped" signal when playing! - I don't know why */ | ||
139 | m_Infolib->stop(); | ||
129 | odebug << "File set: " << i << " ("<<aFile.utf8().data()<<")"<<oendl; | 140 | odebug << "File set: " << i << " ("<<aFile.utf8().data()<<")"<<oendl; |
130 | if (i<1) { | 141 | if (i<1) { |
131 | i = m_Infolib->error(); | 142 | i = m_Infolib->error(); |
132 | odebug << "Errorcode: " << i << oendl; | 143 | odebug << "Errorcode: " << i << oendl; |
133 | QString msg; | 144 | QString msg; |
134 | msg = QString(tr("Error open file %1: ")).arg(name); | 145 | msg = QString(tr("Error open file %1: ")).arg(name); |
135 | switch (i) { | 146 | switch (i) { |
136 | case 1: | 147 | case 1: |
137 | msg += tr("No input plugin"); | 148 | msg += tr("No input plugin"); |
138 | break; | 149 | break; |
139 | case 2: | 150 | case 2: |
140 | msg += tr("No demuxer plugin"); | 151 | msg += tr("No demuxer plugin"); |
@@ -171,33 +182,27 @@ void PlaylistView::addFile(const QString&aFile,const QString&aName) | |||
171 | m_lastItem->setText(COL_TITLE,m_Infolib->metaInfo(0)); | 182 | m_lastItem->setText(COL_TITLE,m_Infolib->metaInfo(0)); |
172 | // artist | 183 | // artist |
173 | m_lastItem->setText(COL_ARTIST,m_Infolib->metaInfo(2)); | 184 | m_lastItem->setText(COL_ARTIST,m_Infolib->metaInfo(2)); |
174 | // album | 185 | // album |
175 | m_lastItem->setText(COL_ALBUM,m_Infolib->metaInfo(4)); | 186 | m_lastItem->setText(COL_ALBUM,m_Infolib->metaInfo(4)); |
176 | int l = m_Infolib->length(); | 187 | int l = m_Infolib->length(); |
177 | int h = l/3600; | 188 | int h = l/3600; |
178 | l-=h*3600; | 189 | l-=h*3600; |
179 | int m = l/60; | 190 | int m = l/60; |
180 | l-=m*60; | 191 | l-=m*60; |
181 | codec = ""; | 192 | codec = ""; |
182 | if (h>0) { | 193 | if (h>0) { |
183 | codec+=QString("%1 h").arg(h); | 194 | codec.sprintf("%2i:%2i:%2i h",h,m,l); |
184 | } | 195 | } else { |
185 | if (m>0) { | 196 | codec.sprintf("%02i:%02i m",m,l); |
186 | if (!codec.isEmpty()) codec+=" "; | ||
187 | codec+=QString("%1 m").arg(m); | ||
188 | } | ||
189 | if (l>0) { | ||
190 | if (!codec.isEmpty()) codec+=" "; | ||
191 | codec+=QString("%1 s").arg(l); | ||
192 | } | 197 | } |
193 | // time | 198 | // time |
194 | m_lastItem->setText(COL_TIME,codec); | 199 | m_lastItem->setText(COL_TIME,codec); |
195 | m_lastItem->Video(m_Infolib->hasVideo()); | 200 | m_lastItem->Video(m_Infolib->hasVideo()); |
196 | m_items.append(m_lastItem); | 201 | m_items.append(m_lastItem); |
197 | setSelected(m_lastItem,true); | 202 | setSelected(m_lastItem,true); |
198 | } | 203 | } |
199 | 204 | ||
200 | void PlaylistView::slotAppendDir() | 205 | void PlaylistView::slotAppendDir() |
201 | { | 206 | { |
202 | QString _dir = Opie::Ui::OFileDialog::getDirectory(Opie::Ui::OFileSelector::Extended,m_lastDir,0,m_lastDir); | 207 | QString _dir = Opie::Ui::OFileDialog::getDirectory(Opie::Ui::OFileSelector::Extended,m_lastDir,0,m_lastDir); |
203 | if (_dir.isEmpty()) return; | 208 | if (_dir.isEmpty()) return; |
@@ -207,53 +212,58 @@ void PlaylistView::slotAppendDir() | |||
207 | for (unsigned i = 0; i < list.count();++i) { | 212 | for (unsigned i = 0; i < list.count();++i) { |
208 | addFile(_dir+QString("/")+list[i]); | 213 | addFile(_dir+QString("/")+list[i]); |
209 | } | 214 | } |
210 | emit contentChanged(childCount()); | 215 | emit contentChanged(childCount()); |
211 | } | 216 | } |
212 | 217 | ||
213 | void PlaylistView::slotOpenM3u() | 218 | void PlaylistView::slotOpenM3u() |
214 | { | 219 | { |
215 | QStringList types; | 220 | QStringList types; |
216 | QMap<QString, QStringList> mimeTypes; | 221 | QMap<QString, QStringList> mimeTypes; |
217 | types << "audio/x-mpegurl"; | 222 | types << "audio/x-mpegurl"; |
218 | mimeTypes.insert("Playlists",types); | 223 | mimeTypes.insert("Playlists",types); |
219 | mimeTypes.insert("All",types); | 224 | // mimeTypes.insert("All",types); |
220 | QString fileName= Opie::Ui::OFileDialog::getOpenFileName(Opie::Ui::OFileSelector::EXTENDED, | 225 | QString fileName= Opie::Ui::OFileDialog::getOpenFileName(Opie::Ui::OFileSelector::EXTENDED, |
221 | m_lastDir,"playlist.m3u", mimeTypes); | 226 | m_lastDir,"playlist.m3u", mimeTypes); |
222 | if (fileName.isEmpty()) { | 227 | if (fileName.isEmpty()) { |
223 | return; | 228 | return; |
224 | } | 229 | } |
230 | readPlayList(fileName); | ||
231 | emit contentChanged(childCount()); | ||
232 | } | ||
233 | |||
234 | void PlaylistView::readPlayList(const QString&fileName) | ||
235 | { | ||
225 | QFileInfo f(fileName); | 236 | QFileInfo f(fileName); |
226 | 237 | ||
227 | Om3u _om3u(fileName, IO_ReadOnly); | 238 | Om3u _om3u(fileName, IO_ReadOnly); |
228 | if (f.extension(FALSE).lower()=="m3u") { | 239 | if (f.extension(FALSE).lower()=="m3u") { |
229 | _om3u.readM3u(); | 240 | _om3u.readM3u(); |
230 | } else if (f.extension(FALSE).lower()=="pls") { | 241 | } else if (f.extension(FALSE).lower()=="pls") { |
231 | _om3u.readPls(); | 242 | _om3u.readPls(); |
232 | } | 243 | } |
233 | for (unsigned int j=0; j<_om3u.count();++j) { | 244 | for (unsigned int j=0; j<_om3u.count();++j) { |
234 | addFile(_om3u[j]); | 245 | addFile(_om3u[j]); |
235 | } | 246 | } |
236 | emit contentChanged(childCount()); | ||
237 | } | 247 | } |
238 | 248 | ||
239 | void PlaylistView::slotSaveAsM3u() | 249 | void PlaylistView::slotSaveAsM3u() |
240 | { | 250 | { |
241 | QStringList types; | 251 | QStringList types; |
242 | QMap<QString, QStringList> mimeTypes; | 252 | QMap<QString, QStringList> mimeTypes; |
243 | types << "audio/x-mpegurl"; | 253 | types << "audio/x-mpegurl"; |
244 | mimeTypes.insert("Playlists",types); | 254 | mimeTypes.insert("Playlists",types); |
245 | mimeTypes.insert("All",types); | ||
246 | QString fileName= Opie::Ui::OFileDialog::getSaveFileName(Opie::Ui::OFileSelector::EXTENDED, | 255 | QString fileName= Opie::Ui::OFileDialog::getSaveFileName(Opie::Ui::OFileSelector::EXTENDED, |
247 | m_lastDir,"playlist.m3u", mimeTypes); | 256 | m_lastDir,"playlist.m3u", mimeTypes); |
257 | odebug << "Save as " << fileName << oendl; | ||
248 | if (fileName.isEmpty()) { | 258 | if (fileName.isEmpty()) { |
249 | return; | 259 | return; |
250 | } | 260 | } |
251 | Om3u _om3u(fileName, IO_ReadWrite | IO_Truncate); | 261 | Om3u _om3u(fileName, IO_ReadWrite | IO_Truncate); |
252 | for (unsigned j=0; j<m_items.count();++j) { | 262 | for (unsigned j=0; j<m_items.count();++j) { |
253 | _om3u.add(m_items[j]->Lnk().file()); | 263 | _om3u.add(m_items[j]->Lnk().file()); |
254 | } | 264 | } |
255 | _om3u.write(); | 265 | _om3u.write(); |
256 | } | 266 | } |
257 | 267 | ||
258 | void PlaylistView::removeFromList(PlaylistItem*Item) | 268 | void PlaylistView::removeFromList(PlaylistItem*Item) |
259 | { | 269 | { |