Diffstat (limited to 'noncore/multimedia/opieplayer3/playlist.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer3/playlist.cpp | 131 |
1 files changed, 120 insertions, 11 deletions
diff --git a/noncore/multimedia/opieplayer3/playlist.cpp b/noncore/multimedia/opieplayer3/playlist.cpp index 272a71e..babe8ce 100644 --- a/noncore/multimedia/opieplayer3/playlist.cpp +++ b/noncore/multimedia/opieplayer3/playlist.cpp | |||
@@ -29,19 +29,26 @@ | |||
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | #include "playlist.h" | 33 | #include "playlist.h" |
34 | #include "../opieplayer2/lib.h" | 34 | #include "../opieplayer2/lib.h" |
35 | #include "../opieplayer2/om3u.h" | ||
35 | 36 | ||
36 | #include <opie2/odebug.h> | 37 | #include <opie2/odebug.h> |
37 | #include <opie2/oresource.h> | 38 | #include <opie2/oresource.h> |
39 | #include <opie2/ofiledialog.h> | ||
38 | 40 | ||
39 | #include <qpe/resource.h> | 41 | #include <qpe/resource.h> |
40 | 42 | ||
41 | #include <qfileinfo.h> | 43 | #include <qfileinfo.h> |
44 | #include <qmessagebox.h> | ||
45 | #include <qdir.h> | ||
46 | |||
47 | //#define DEFAULT_FILE_TYPES "*.mp3;*.ogg;*.ogm;*.wma;*.wav;*.asf;*.au;*.avi;*.mpeg;*.mpg;*.mv1;*.mov;*.wmv;*.pls;*.m3u;*.mp4;*.m4a" | ||
48 | #define DEFAULT_FILE_TYPES "*.mp3;*.ogg;*.ogm;*.wma;*.wav;*.asf;*.au;*.avi;*.mpeg;*.mpg;*.mv1;*.mov;*.wmv;*.mp4;*.m4a" | ||
42 | 49 | ||
43 | PlaylistItem::PlaylistItem(const DocLnk& aLink,PlaylistView*parent) | 50 | PlaylistItem::PlaylistItem(const DocLnk& aLink,PlaylistView*parent) |
44 | :QListViewItem(parent),m_Content(aLink),m_video(false) | 51 | :QListViewItem(parent),m_Content(aLink),m_video(false) |
45 | { | 52 | { |
46 | } | 53 | } |
47 | 54 | ||
@@ -82,12 +89,13 @@ PlaylistView::PlaylistView(QWidget *parent, const char *name) | |||
82 | } | 89 | } |
83 | m_Infolib=0; | 90 | m_Infolib=0; |
84 | setAllColumnsShowFocus(true); | 91 | setAllColumnsShowFocus(true); |
85 | setSelectionMode(Single); | 92 | setSelectionMode(Single); |
86 | setSorting(-1); | 93 | setSorting(-1); |
87 | m_lastItem = 0; | 94 | m_lastItem = 0; |
95 | m_lastDir = QDir::homeDirPath(); | ||
88 | } | 96 | } |
89 | 97 | ||
90 | PlaylistView::~PlaylistView() | 98 | PlaylistView::~PlaylistView() |
91 | { | 99 | { |
92 | if (m_Infolib) delete m_Infolib; | 100 | if (m_Infolib) delete m_Infolib; |
93 | } | 101 | } |
@@ -99,30 +107,62 @@ void PlaylistView::checkLib() | |||
99 | m_Infolib->ensureInitialized(); | 107 | m_Infolib->ensureInitialized(); |
100 | } | 108 | } |
101 | } | 109 | } |
102 | 110 | ||
103 | void PlaylistView::slotAddFile(const DocLnk&aLink) | 111 | void PlaylistView::slotAddFile(const DocLnk&aLink) |
104 | { | 112 | { |
105 | QFileInfo fileInfo(aLink.file()); | 113 | addFile(aLink.file(),aLink.name()); |
114 | emit contentChanged(childCount()); | ||
115 | } | ||
116 | |||
117 | void PlaylistView::addFile(const QString&aFile,const QString&aName) | ||
118 | { | ||
119 | QFileInfo fileInfo(aFile); | ||
106 | if (!fileInfo.exists()) return; | 120 | if (!fileInfo.exists()) return; |
107 | checkLib(); | 121 | checkLib(); |
108 | |||
109 | m_Infolib->stop(); | 122 | m_Infolib->stop(); |
110 | 123 | ||
111 | if (m_lastItem) { | 124 | QString name = aName; |
112 | m_lastItem = new PlaylistItem(aLink,this,m_lastItem); | 125 | if (name.isEmpty()) { |
113 | } else { | 126 | name = fileInfo.fileName(); |
114 | m_lastItem = new PlaylistItem(aLink,this); | ||
115 | } | 127 | } |
116 | m_lastItem->setExpandable(false); | 128 | int i = m_Infolib->setfile(aFile.utf8().data()); |
117 | m_lastItem->setText(1,aLink.name()); | 129 | odebug << "File set: " << i << " ("<<aFile.utf8().data()<<")"<<oendl; |
118 | int i = m_Infolib->setfile(aLink.file()); | ||
119 | odebug << "File set: " << i << oendl; | ||
120 | if (i<1) { | 130 | if (i<1) { |
131 | i = m_Infolib->error(); | ||
132 | odebug << "Errorcode: " << i << oendl; | ||
133 | QString msg; | ||
134 | msg = QString(tr("Error open file %1: ")).arg(name); | ||
135 | switch (i) { | ||
136 | case 1: | ||
137 | msg += tr("No input plugin"); | ||
138 | break; | ||
139 | case 2: | ||
140 | msg += tr("No demuxer plugin"); | ||
141 | break; | ||
142 | case 3: | ||
143 | msg += tr("Demuxer failed"); | ||
144 | break; | ||
145 | case 4: | ||
146 | msg+=tr("Malformed mrl"); | ||
147 | break; | ||
148 | default: | ||
149 | msg += tr("Unknown error"); | ||
150 | break; | ||
151 | } | ||
152 | QMessageBox::warning(0,tr("Error reading fileheader"),msg); | ||
121 | return; | 153 | return; |
122 | } | 154 | } |
155 | m_lastItem = m_items.last(); | ||
156 | if (m_lastItem) { | ||
157 | m_lastItem = new PlaylistItem(aFile,this,m_lastItem); | ||
158 | } else { | ||
159 | m_lastItem = new PlaylistItem(aFile,this); | ||
160 | } | ||
161 | m_lastItem->setExpandable(false); | ||
162 | m_lastItem->setText(1,name); | ||
123 | 163 | ||
124 | QString codec = m_Infolib->metaInfo(6); | 164 | QString codec = m_Infolib->metaInfo(6); |
125 | if (codec.isEmpty()) { | 165 | if (codec.isEmpty()) { |
126 | codec = m_Infolib->metaInfo(7); | 166 | codec = m_Infolib->metaInfo(7); |
127 | } | 167 | } |
128 | // codec | 168 | // codec |
@@ -151,23 +191,92 @@ void PlaylistView::slotAddFile(const DocLnk&aLink) | |||
151 | codec+=QString("%1 s").arg(l); | 191 | codec+=QString("%1 s").arg(l); |
152 | } | 192 | } |
153 | // time | 193 | // time |
154 | m_lastItem->setText(COL_TIME,codec); | 194 | m_lastItem->setText(COL_TIME,codec); |
155 | m_lastItem->Video(m_Infolib->hasVideo()); | 195 | m_lastItem->Video(m_Infolib->hasVideo()); |
156 | m_items.append(m_lastItem); | 196 | m_items.append(m_lastItem); |
197 | setSelected(m_lastItem,true); | ||
198 | } | ||
199 | |||
200 | void PlaylistView::slotAppendDir() | ||
201 | { | ||
202 | QString _dir = Opie::Ui::OFileDialog::getDirectory(Opie::Ui::OFileSelector::Extended,m_lastDir,0,m_lastDir); | ||
203 | if (_dir.isEmpty()) return; | ||
204 | m_lastDir = _dir; | ||
205 | QDir sDir(_dir); | ||
206 | QStringList list = sDir.entryList(DEFAULT_FILE_TYPES,QDir::Files,QDir::Name | QDir::IgnoreCase); | ||
207 | for (unsigned i = 0; i < list.count();++i) { | ||
208 | addFile(_dir+QString("/")+list[i]); | ||
209 | } | ||
210 | emit contentChanged(childCount()); | ||
211 | } | ||
212 | |||
213 | void PlaylistView::slotOpenM3u() | ||
214 | { | ||
215 | QStringList types; | ||
216 | QMap<QString, QStringList> mimeTypes; | ||
217 | types << "audio/x-mpegurl"; | ||
218 | mimeTypes.insert("Playlists",types); | ||
219 | mimeTypes.insert("All",types); | ||
220 | QString fileName= Opie::Ui::OFileDialog::getOpenFileName(Opie::Ui::OFileSelector::EXTENDED, | ||
221 | m_lastDir,"playlist.m3u", mimeTypes); | ||
222 | if (fileName.isEmpty()) { | ||
223 | return; | ||
224 | } | ||
225 | QFileInfo f(fileName); | ||
226 | |||
227 | Om3u _om3u(fileName, IO_ReadOnly); | ||
228 | if (f.extension(FALSE).lower()=="m3u") { | ||
229 | _om3u.readM3u(); | ||
230 | } else if (f.extension(FALSE).lower()=="pls") { | ||
231 | _om3u.readPls(); | ||
232 | } | ||
233 | for (unsigned int j=0; j<_om3u.count();++j) { | ||
234 | addFile(_om3u[j]); | ||
235 | } | ||
236 | emit contentChanged(childCount()); | ||
237 | } | ||
238 | |||
239 | void PlaylistView::slotSaveAsM3u() | ||
240 | { | ||
241 | QStringList types; | ||
242 | QMap<QString, QStringList> mimeTypes; | ||
243 | types << "audio/x-mpegurl"; | ||
244 | mimeTypes.insert("Playlists",types); | ||
245 | mimeTypes.insert("All",types); | ||
246 | QString fileName= Opie::Ui::OFileDialog::getSaveFileName(Opie::Ui::OFileSelector::EXTENDED, | ||
247 | m_lastDir,"playlist.m3u", mimeTypes); | ||
248 | if (fileName.isEmpty()) { | ||
249 | return; | ||
250 | } | ||
251 | Om3u _om3u(fileName, IO_ReadWrite | IO_Truncate); | ||
252 | for (unsigned j=0; j<m_items.count();++j) { | ||
253 | _om3u.add(m_items[j]->Lnk().file()); | ||
254 | } | ||
255 | _om3u.write(); | ||
157 | } | 256 | } |
158 | 257 | ||
159 | void PlaylistView::removeFromList(PlaylistItem*Item) | 258 | void PlaylistView::removeFromList(PlaylistItem*Item) |
160 | { | 259 | { |
161 | if (!Item)return; | 260 | if (!Item)return; |
162 | t_itemlist::Iterator iter; | 261 | t_itemlist::Iterator iter,it2; |
163 | iter = m_items.find(Item); | 262 | iter = m_items.find(Item); |
263 | it2 = m_items.end(); | ||
164 | if (iter!=m_items.end()) { | 264 | if (iter!=m_items.end()) { |
265 | it2 = iter; | ||
266 | ++it2; | ||
165 | m_items.remove(iter); | 267 | m_items.remove(iter); |
166 | } | 268 | } |
167 | delete Item; | 269 | delete Item; |
270 | if (it2!=m_items.end()) { | ||
271 | setSelected((*it2),true); | ||
272 | } else if (m_items.count()) { | ||
273 | QListViewItem * it = m_items.last(); | ||
274 | setSelected(it,true); | ||
275 | } | ||
276 | emit contentChanged(childCount()); | ||
168 | } | 277 | } |
169 | 278 | ||
170 | XINE::Lib*PlaylistView::getXine() | 279 | XINE::Lib*PlaylistView::getXine() |
171 | { | 280 | { |
172 | checkLib(); | 281 | checkLib(); |
173 | return m_Infolib; | 282 | return m_Infolib; |