summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer3/playlist.cpp
blob: 272a71eaedb78361e800f5d18c89e44e742d856b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
                            This file is part of the Opie Project

                             Copyright (c)  2002 Max Reiss <harlekin@handhelds.org>
                             Copyright (c)  2002 L. Potter <ljp@llornkcor.com>
                             Copyright (c)  2002 Holger Freyther <zecke@handhelds.org>
              =.
            .=l.
           .>+-=
 _;:,     .>    :=|.         This program is free software; you can
.> <`_,   >  .   <=          redistribute it and/or  modify it under
:`=1 )Y*s>-.--   :           the terms of the GNU General Public
.="- .-=="i,     .._         License as published by the Free Software
 - .   .-<_>     .<>         Foundation; either version 2 of the License,
     ._= =}       :          or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s.       This program is distributed in the hope that
     +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
    : ..    .:,     . . .    without even the implied warranty of
    =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ;      Library General Public License for more
++=   -.     .`     .:       details.
 :     =  ...= . :.=-
 -.   .:....=;==+<;          You should have received a copy of the GNU
  -_. . .   )=.  =           Library General Public License along with
    --        :-=`           this library; see the file COPYING.LIB.
                             If not, write to the Free Software Foundation,
                             Inc., 59 Temple Place - Suite 330,
                             Boston, MA 02111-1307, USA.

*/
#include "playlist.h"
#include "../opieplayer2/lib.h"

#include <opie2/odebug.h>
#include <opie2/oresource.h>

#include <qpe/resource.h>

#include <qfileinfo.h>

PlaylistItem::PlaylistItem(const DocLnk& aLink,PlaylistView*parent)
    :QListViewItem(parent),m_Content(aLink),m_video(false)
{
}

PlaylistItem::PlaylistItem(const DocLnk&aLink,PlaylistView*parent,PlaylistItem*after)
    :QListViewItem(parent,after),m_Content(aLink),m_video(false)
{
}

void PlaylistItem::Video(bool y)
{
    m_video=y;
    if (m_video) {
        setPixmap(0,Opie::Core::OResource::loadPixmap("opieplayer2/videofile"));
    } else {
        setPixmap(0,Opie::Core::OResource::loadPixmap("opieplayer2/musicfile"));
    }
}

PlaylistItem::~PlaylistItem()
{
}

/* PlaylistView Methods */
PlaylistView::PlaylistView(QWidget *parent, const char *name)
    : QListView(parent,name)
{
//    columnLabels << tr("FullName");
    columnLabels << tr("");                 // icon
    columnLabels << tr("File");
    columnLabels << tr("Playtime");
    columnLabels << tr("Artist");
    columnLabels << tr("Album");
    columnLabels << tr("Title");
    columnLabels << tr("Type");
    columnLabels << tr("Size");
    for (QStringList::Iterator it = columnLabels.begin(); it != columnLabels.end(); ++it) {
        addColumn(*it);
    }
    m_Infolib=0;
    setAllColumnsShowFocus(true);
    setSelectionMode(Single);
    setSorting(-1);
    m_lastItem = 0;
}

PlaylistView::~PlaylistView()
{
    if (m_Infolib) delete m_Infolib;
}

void PlaylistView::checkLib()
{
    if (!m_Infolib) {
        m_Infolib = new XINE::Lib(XINE::Lib::InitializeImmediately);
        m_Infolib->ensureInitialized();
    }
}

void PlaylistView::slotAddFile(const DocLnk&aLink)
{
    QFileInfo fileInfo(aLink.file());
    if (!fileInfo.exists()) return;
    checkLib();

    m_Infolib->stop();

    if (m_lastItem) {
        m_lastItem = new PlaylistItem(aLink,this,m_lastItem);
    } else {
        m_lastItem = new PlaylistItem(aLink,this);
    }
    m_lastItem->setExpandable(false);
    m_lastItem->setText(1,aLink.name());
    int i = m_Infolib->setfile(aLink.file());
    odebug << "File set: " << i << oendl;
    if (i<1) {
        return;
    }

    QString codec = m_Infolib->metaInfo(6);
    if (codec.isEmpty()) {
        codec = m_Infolib->metaInfo(7);
    }
    // codec
    m_lastItem->setText(COL_TYPE,codec);
    // title
    m_lastItem->setText(COL_TITLE,m_Infolib->metaInfo(0));
    // artist
    m_lastItem->setText(COL_ARTIST,m_Infolib->metaInfo(2));
    // album
    m_lastItem->setText(COL_ALBUM,m_Infolib->metaInfo(4));
    int l = m_Infolib->length();
    int h = l/3600;
    l-=h*3600;
    int m = l/60;
    l-=m*60;
    codec = "";
    if (h>0) {
        codec+=QString("%1 h").arg(h);
    }
    if (m>0) {
        if (!codec.isEmpty()) codec+=" ";
        codec+=QString("%1 m").arg(m);
    }
    if (l>0) {
        if (!codec.isEmpty()) codec+=" ";
        codec+=QString("%1 s").arg(l);
    }
    // time
    m_lastItem->setText(COL_TIME,codec);
    m_lastItem->Video(m_Infolib->hasVideo());
    m_items.append(m_lastItem);
}

void PlaylistView::removeFromList(PlaylistItem*Item)
{
    if (!Item)return;
    t_itemlist::Iterator iter;
    iter = m_items.find(Item);
    if (iter!=m_items.end()) {
        m_items.remove(iter);
    }
    delete Item;
}

XINE::Lib*PlaylistView::getXine()
{
    checkLib();
    return m_Infolib;
}

void PlaylistView::setCurrentItem(PlaylistItem*aItem)
{
    setSelected(aItem,true);
}

PlaylistItem* PlaylistView::currentItem()const
{
    QListViewItem*it = selectedItem();
    if (!it) return 0;
    return (PlaylistItem*)it;
}

PlaylistItem* PlaylistView::nextItem(PlaylistItem*parent)const
{
    if (m_items.count()==0) return 0;
    if (!parent) return m_items[0];
    for (unsigned j=0; j<m_items.count()-1;++j) {
        if (m_items[j]==parent) {
            return m_items[j+1];
        }
    }
    return 0;
}

PlaylistItem* PlaylistView::prevItem(PlaylistItem*parent)const
{
    if (m_items.count()==0) return 0;
    if (!parent) return m_items[m_items.count()-1];
    for (unsigned j=m_items.count()-1; j>0;--j) {
        if (m_items[j]==parent) {
            return m_items[j-1];
        }
    }
    return 0;
}