Commit 66b6d3b6 authored by Scott Wheeler's avatar Scott Wheeler

Somewhat modified patch from Ismael Orenstein to add the total time in the

playlist to the status bar.

CCMAIL:67598-done@bugs.kde.org

svn path=/trunk/kdemultimedia/juk/; revision=289250
parent 606fa697
......@@ -278,6 +278,8 @@ void JuK::setupLayout()
connect(m_splitter, SIGNAL(signalSelectedPlaylistCountChanged(int)),
m_statusLabel, SLOT(setPlaylistCount(int)));
connect(m_splitter, SIGNAL(signalSelectedPlaylistTimeChanged(int)),
m_statusLabel, SLOT(setPlaylistTime(int)));
connect(m_statusLabel, SIGNAL(jumpButtonClicked()),
m_splitter, SLOT(slotSelectPlaying()));
......@@ -746,7 +748,8 @@ QString JuK::playingString() const
void JuK::updatePlaylistInfo()
{
m_statusLabel->setPlaylistInfo(m_splitter->visiblePlaylistName(),
m_splitter->selectedPlaylistCount());
m_splitter->selectedPlaylistCount(),
m_splitter->selectedPlaylistTotalTime());
}
void JuK::play(const QString &file)
......
......@@ -451,6 +451,19 @@ void Playlist::setName(const QString &n)
emit signalNameChanged(m_playlistName);
}
int Playlist::totalTime()
{
int time = 0;
QListViewItemIterator it(this);
while (it.current()) {
PlaylistItem *item = static_cast<PlaylistItem *>(it.current());
if (item->tag()->current())
time += item->tag()->seconds();
it++;
}
return time;
}
void Playlist::updateLeftColumn()
{
int newLeftColumn = leftMostVisibleColumn();
......
......@@ -196,6 +196,11 @@ public:
* Returns the number of items in the playlist.
*/
int count() const { return childCount(); }
/**
* Returns the combined time of all the itens.
*/
int totalTime();
/**
* Returns the next item to be played. If random is false this is just
......
......@@ -980,8 +980,10 @@ void PlaylistSplitter::slotChangePlaylist(const PlaylistList &l)
void PlaylistSplitter::slotPlaylistCountChanged(Playlist *p)
{
if(p && p == m_playlistStack->visibleWidget())
if(p && p == m_playlistStack->visibleWidget()) {
emit signalSelectedPlaylistCountChanged(p->childCount());
emit signalSelectedPlaylistTimeChanged(p->totalTime());
}
}
void PlaylistSplitter::slotPlaylistItemRemoved(PlaylistItem *item)
......
......@@ -127,6 +127,10 @@ public:
*/
int selectedPlaylistCount() const { return visiblePlaylist()->childCount(); }
/**
* Returns the combined time of all the itens in the currently selected playlist.
*/
int selectedPlaylistTotalTime() const { return visiblePlaylist()->totalTime(); }
/**
* Returns true if the the collection list is the visible playlist.
*/
......@@ -274,6 +278,7 @@ signals:
void signalListBoxDoubleClicked();
void signalPlaylistChanged();
void signalSelectedPlaylistCountChanged(int);
void signalSelectedPlaylistTimeChanged(int);
private:
......
......@@ -91,22 +91,45 @@ StatusLabel::~StatusLabel()
}
void StatusLabel::setPlaylistInfo(const QString &name, int count)
void StatusLabel::setPlaylistInfo(const QString &name, int count, int totalTime)
{
m_playlistName = name;
m_playlistCount = count;
m_playlistTotalTime = totalTime;
if(mode == PlaylistInfo)
m_playlistLabel->setText(m_playlistName);
if(mode != PlaylistInfo)
return;
setPlaylistCount(count);
m_playlistLabel->setText(m_playlistName);
int days = totalTime / (60 * 60 * 24);
int hours = totalTime / (60 * 60) % 24;
int minutes = totalTime / 60 % 60;
int seconds = totalTime % 60;
QString time;
if(days > 0) {
time = i18n("1 day", "%n days", days);
time.append(" ");
}
if(days > 0 || hours > 0)
time.append(QString().sprintf("%1d:%02d:%02d", hours, minutes, seconds));
else
time.append(QString().sprintf("%1d:%02d", minutes, seconds));
m_trackLabel->setText(i18n("1 item", "%n items", count) + " - " + time);
}
void StatusLabel::setPlaylistCount(int c)
void StatusLabel::setPlaylistTime(int totalTime)
{
m_playlistCount = c;
setPlaylistInfo(m_playlistName, m_playlistCount, totalTime);
}
if(mode == PlaylistInfo)
m_trackLabel->setText(i18n("1 item", "%n items", c));
void StatusLabel::setPlaylistCount(int c)
{
setPlaylistInfo(m_playlistName, c, m_playlistTotalTime);
}
void StatusLabel::setPlayingItemInfo(const QString &track, const QString &playlist)
......@@ -126,7 +149,7 @@ void StatusLabel::clear()
mode = PlaylistInfo;
setPlaylistInfo(m_playlistName, m_playlistCount);
setPlaylistInfo(m_playlistName, m_playlistCount, m_playlistTotalTime);
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -38,9 +38,10 @@ public slots:
* Set the playlist name. This text will only be used when there is not an
* item playing.
*/
void setPlaylistInfo(const QString &name, int count);
void setPlaylistCount(int c);
void setPlayingItemInfo(const QString &track, const QString &playlist);
void setPlaylistInfo(const QString &name, int count, int totalTime);
void setPlaylistTime(int totalTime);
/**
* This clears the information about the playing items and frees that status
......@@ -71,6 +72,7 @@ private:
int m_playlistCount;
int m_itemTotalTime;
int m_itemCurrentTime;
int m_playlistTotalTime;
bool m_showTimeRemaining;
QLabel *m_playlistLabel;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment