Debian Codegraph @

src/playlistitem.cpp

raw symbols SCIP
1 /*
2 Copyright (C) 2005-2014 Mario Stephan <[email protected]>
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "playlistitem.h"
19 #include "playlist.h"
20 #include "ratingwidget.h"
21
22 #include <QObject>
23 #include <qdebug.h>
24 #include <qlistview.h>
25
26 PlaylistItem::PlaylistItem(Playlist* parent, QTreeWidgetItem* lvi)
27 : QTreeWidgetItem(parent, lvi)
28 , m_track(new Track())
29 , m_parent(parent)
30 {
31 //qDebug() << u << " 2."<<m_url;
32 }
33
34 PlaylistItem::~PlaylistItem()
35 {
36 if (m_track)
37 delete m_track;
38 }
39
40 void PlaylistItem::setTrack(Track* track)
41 {
42 m_track = track;
43 setTexts(m_track);
44 }
45
46 void PlaylistItem::setTexts(Track* track)
47 {
48 //qDebug()<<track->url();
49
50 setText(Column_Url, track->url().toString());
51 setText(Column_Artist, (track->artist() != "") ? track->artist() : QObject::tr("Unknown"));
52 setText(Column_Title, (track->title() != "") ? track->title() : QObject::tr("Unknown"));
53 setText(Column_Album, track->album());
54 setText(Column_Year, track->year());
55 setText(Column_Genre, track->genre());
56 setText(Column_Length, track->prettyLength());
57 setText(Column_Tracknumber, track->tracknumber());
58 setText(Column_Played, QString::number(track->counter()));
59
60 const QString body = "<tr><td><b>%1</b></td><td>%2</td></tr>";
61
62 QString
63 str
64 = "<html><body><table STYLE=\"border-collapse: collapse\"> width=\"100%\" border=\"1\">";
65 str += body.arg(QObject::tr("Title"), track->title());
66 str += body.arg(QObject::tr("Artist"), track->artist());
67 str += body.arg(QObject::tr("Album"), track->album());
68 str += body.arg(QObject::tr("Genre"), track->genre());
69 str += body.arg(QObject::tr("Year"), track->year());
70 str += body.arg(QObject::tr("Location"), track->url().toString());
71 str += "</table></body></html>";
72
73 setToolTip(Column_Artist, str);
74
75 m_track = track;
76 }
77
78 void PlaylistItem::setText(int c, QString text)
79 {
80 QTreeWidgetItem::setText(c, (text != "") ? text : QObject::tr("Unknown"));
81 switch (c) {
82 case Column_Url:
83 m_track->setUrl(QUrl::fromLocalFile(text));
84 break;
85 case Column_Artist:
86 m_track->setArtist(text);
87 break;
88 case Column_Title:
89 m_track->setTitle(text);
90 break;
91 case Column_Album:
92 m_track->setAlbum(text);
93 break;
94 case Column_Played:
95 m_track->setCounter(text);
96 break;
97 case Column_Genre:
98 m_track->setGenre(text);
99 break;
100 case Column_Length:
101 m_track->setLength(text);
102 break;
103 }
104 }
105
106 void PlaylistItem::update()
107 {
108 // paint item in special color
109 for (int i = 0; i <= columnCount() - 1; i++)
110 setForeground(i, QBrush(m_foreColor));
111 }
112
113 int PlaylistItem::rate()
114 {
115 return ((RatingWidget*)m_parent->itemWidget(this, Column_Rate))->rating() * 0.1;
116 }
117
118 bool PlaylistItem::operator<(const QTreeWidgetItem& other) const
119 {
120 bool ok;
121 int sortCol = treeWidget()->sortColumn();
122 QString otherText = other.text(sortCol).replace(QObject::tr("Unknown"), "0");
123
124 if (sortCol == Column_Length) {
125 int otherLength = -1;
126 if (otherText.contains(':')) {
127 QStringList list = otherText.split(':');
128 otherLength = list.at(0).toInt(&ok) * 60;
129 otherLength += list.at(1).toInt(&ok);
130 if (ok)
131 return m_track->length() < otherLength;
132 }
133 } else {
134 int value = text(sortCol).replace(QObject::tr("Unknown"), "0").toInt(&ok);
135 int otherValue = otherText.toInt(&ok);
136 if (ok)
137 return value < otherValue;
138 }
139
140 return QTreeWidgetItem::operator<(other);
141 }