Commit 60d0fbbb authored by Scott Wheeler's avatar Scott Wheeler

Ok, the last step in adding "history playlist" support. I implemented

streaming operators for the new playlist type to save the date that the
items were played on and integrated this into the rewritten playlist
caching code.

So basically history works, including restoration.

CCMAIL:61294-done@bugs.kde.org

svn path=/trunk/kdemultimedia/juk/; revision=243375
parent 13db0e78
......@@ -16,25 +16,11 @@
***************************************************************************/
#include <klocale.h>
#include <kdebug.h>
#include "historyplaylist.h"
#include "collectionlist.h"
////////////////////////////////////////////////////////////////////////////////
// HistoryPlaylistItem public members
////////////////////////////////////////////////////////////////////////////////
HistoryPlaylistItem::HistoryPlaylistItem(CollectionListItem *item, Playlist *parent, QListViewItem *after) :
PlaylistItem(item, parent, after)
{
setText(0, QDateTime::currentDateTime().toString(LocalDate));
}
HistoryPlaylistItem::~HistoryPlaylistItem()
{
}
////////////////////////////////////////////////////////////////////////////////
// HistoryPlayList public members
////////////////////////////////////////////////////////////////////////////////
......@@ -65,4 +51,75 @@ void HistoryPlaylist::polish()
setSorting(-1);
}
////////////////////////////////////////////////////////////////////////////////
// HistoryPlaylistItem public members
////////////////////////////////////////////////////////////////////////////////
HistoryPlaylistItem::HistoryPlaylistItem(CollectionListItem *item, Playlist *parent, QListViewItem *after) :
PlaylistItem(item, parent, after),
m_dateTime(QDateTime::currentDateTime())
{
setText(0, m_dateTime.toString(LocalDate));
}
HistoryPlaylistItem::HistoryPlaylistItem(CollectionListItem *item, Playlist *parent) :
PlaylistItem(item, parent),
m_dateTime(QDateTime::currentDateTime())
{
setText(0, m_dateTime.toString(LocalDate));
}
HistoryPlaylistItem::~HistoryPlaylistItem()
{
}
void HistoryPlaylistItem::setDateTime(const QDateTime &dt)
{
m_dateTime = dt;
setText(0, m_dateTime.toString(LocalDate));
}
////////////////////////////////////////////////////////////////////////////////
// helper functions
////////////////////////////////////////////////////////////////////////////////
QDataStream &operator<<(QDataStream &s, const HistoryPlaylist &p)
{
PlaylistItemList l = const_cast<HistoryPlaylist *>(&p)->items();
s << Q_INT32(l.count());
for(PlaylistItemList::ConstIterator it = l.begin(); it != l.end(); ++it) {
const HistoryPlaylistItem *i = static_cast<HistoryPlaylistItem *>(*it);
s << i->filePath();
s << i->dateTime();
}
return s;
}
QDataStream &operator>>(QDataStream &s, HistoryPlaylist &p)
{
Q_INT32 count;
s >> count;
HistoryPlaylistItem *after = 0;
QString fileName;
QDateTime dateTime;
for(int i = 0; i < count; i++) {
s >> fileName;
s >> dateTime;
after = p.createItem<HistoryPlaylistItem, CollectionListItem, CollectionList>(QFileInfo(fileName), fileName, after, false);
after->setDateTime(dateTime);
}
p.emitCountChanged();
return s;
}
#include "historyplaylist.moc"
......@@ -47,7 +47,17 @@ class HistoryPlaylistItem : public PlaylistItem
{
public:
HistoryPlaylistItem(CollectionListItem *item, Playlist *parent, QListViewItem *after);
HistoryPlaylistItem(CollectionListItem *item, Playlist *parent);
virtual ~HistoryPlaylistItem();
QDateTime dateTime() const { return m_dateTime; }
void setDateTime(const QDateTime &dt);
private:
QDateTime m_dateTime;
};
QDataStream &operator<<(QDataStream &s, const HistoryPlaylist &p);
QDataStream &operator>>(QDataStream &s, HistoryPlaylist &p);
#endif
......@@ -621,9 +621,12 @@ void JuK::readConfig()
m_showEditorAction->setChecked(showEditor);
m_splitter->slotSetEditorVisible(showEditor);
bool showHistory = config->readBoolEntry("ShowHistory", false);
m_showHistoryAction->setChecked(showHistory);
m_splitter->slotSetHistoryVisible(showHistory);
// The history list will actually be created by the playlist restoration
// code, but we want to remember the checkbox's setting and hope that
// it's in synch with the code that does the real work.
bool showHistory = config->readBoolEntry("ShowHistory", false);
m_showHistoryAction->setChecked(showHistory);
}
{ // general settings
KConfigGroupSaver saver(config, "Settings");
......@@ -661,7 +664,7 @@ void JuK::saveConfig()
config->writeEntry("ShowEditor", m_showEditorAction->isChecked());
config->writeEntry("ShowSearch", m_showSearchAction->isChecked());
config->writeEntry("ShowHistory", m_showHistoryAction->isChecked());
config->writeEntry("ShowHistory", m_showHistoryAction->isChecked());
}
{ // general settings
KConfigGroupSaver saver(config, "Settings");
......
......@@ -39,8 +39,8 @@
#include "playlistitem.h"
#include "playlistsearch.h"
#include "genrelistlist.h"
#include "collectionlist.h"
#include "mediafiles.h"
#include "collectionlist.h"
////////////////////////////////////////////////////////////////////////////////
// Playlist::SharedSettings definition
......@@ -682,45 +682,7 @@ void Playlist::showEvent(QShowEvent *e)
PlaylistItem *Playlist::createItem(const QFileInfo &file, const QString &absFilePath,
QListViewItem *after, bool emitChanged)
{
QString filePath;
if(absFilePath.isNull())
filePath = resolveSymLinks(file);
else
filePath = absFilePath;
CollectionListItem *item = CollectionList::instance()->lookup(filePath);
if(!item) {
item = new CollectionListItem(file, filePath);
// If a valid tag was not created, destroy the CollectionListItem.
if(!item->isValid()) {
kdError() << "Playlist::createItem() -- A valid tag was not created for \""
<< file.filePath() << "\"" << endl;
delete item;
return 0;
}
}
if(item && !m_members.insert(filePath) || m_allowDuplicates) {
PlaylistItem *i;
if(after)
i = new PlaylistItem(item, this, after);
else
i = new PlaylistItem(item, this);
if(!m_randomList.isEmpty() && !m_visibleChanged)
m_randomList.append(i);
emit signalCountChanged(this);
connect(item, SIGNAL(destroyed()), i, SLOT(deleteLater()));
if(emitChanged)
emit signalCountChanged(this);
return i;
}
else
return 0;
return createItem<PlaylistItem, CollectionListItem, CollectionList>(file, absFilePath, after, emitChanged);
}
void Playlist::createItems(const PlaylistItemList &siblings)
......
......@@ -112,6 +112,12 @@ public:
QListViewItem *after = 0,
bool emitChanged = true);
template <class ItemType, class CollectionItemType, class CollectionListType>
ItemType *createItem(const QFileInfo &file,
const QString &absFilePath = QString::null,
QListViewItem *after = 0,
bool emitChanged = true);
virtual void createItems(const PlaylistItemList &siblings);
/**
......@@ -479,6 +485,51 @@ QDataStream &operator>>(QDataStream &s, Playlist &p);
// template method implementations
template <class ItemType, class CollectionItemType, class CollectionListType>
ItemType *Playlist::createItem(const QFileInfo &file, const QString &absFilePath,
QListViewItem *after, bool emitChanged)
{
QString filePath;
if(absFilePath.isNull())
filePath = resolveSymLinks(file);
else
filePath = absFilePath;
CollectionItemType *item = CollectionListType::instance()->lookup(filePath);
if(!item) {
item = new CollectionItemType(file, filePath);
// If a valid tag was not created, destroy the CollectionListItem.
if(!item->isValid()) {
kdError(65432) << "Playlist::createItem() -- A valid tag was not created for \""
<< file.filePath() << "\"" << endl;
delete item;
return 0;
}
}
if(item && !m_members.insert(filePath) || m_allowDuplicates) {
ItemType *i;
if(after)
i = new ItemType(item, this, after);
else
i = new ItemType(item, this);
if(!m_randomList.isEmpty() && !m_visibleChanged)
m_randomList.append(i);
emit signalCountChanged(this);
connect(item, SIGNAL(destroyed()), i, SLOT(deleteLater()));
if(emitChanged)
emit signalCountChanged(this);
return i;
}
else
return 0;
}
template <class CollectionItemType, class ItemType, class SiblingType>
void Playlist::createItems(const QValueList<SiblingType *> &siblings)
{
......
......@@ -708,28 +708,28 @@ void PlaylistSplitter::readPlaylists()
Q_INT32 playlistType;
s >> playlistType;
Playlist *p;
switch(playlistType) {
case Search:
p = new SearchPlaylist(m_playlistStack);
// p = new SearchPlaylist(m_playlistStack);
break;
case History:
p = new HistoryPlaylist(m_playlistStack);
{
slotSetHistoryVisible(true);
s >> *m_history;
break;
}
default:
p = new Playlist(m_playlistStack);
Playlist *p = new Playlist(m_playlistStack);
s >> *p;
if(!p->fileName().isEmpty() && m_playlistFiles.insert(p->fileName())) {
delete p;
p = 0;
}
else
setupPlaylist(p);
break;
}
if(p)
setupPlaylist(p);
}
break;
}
......@@ -778,7 +778,8 @@ void PlaylistSplitter::savePlaylists()
// These first two aren't implemented yet.
if(*it == m_history) {
// s << Q_INT32(History);
s << Q_INT32(History);
s << *m_history;
}
else if(dynamic_cast<SearchPlaylist *>(*it)) {
// s << Q_INT32(Search);
......@@ -928,4 +929,5 @@ void PlaylistSplitter::slotCreateSearchList(const PlaylistSearch &search,
#include "playlistsplitter.moc"
// vim:ts=8
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