1 /***************************************************************************
3 copyright : (C) 2003 - 2004 by Scott Wheeler
4 email : wheeler@kde.org
5 ***************************************************************************/
7 /***************************************************************************
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
14 ***************************************************************************/
16 #include "historyplaylist.h"
17 #include "collectionlist.h"
18 #include "playermanager.h"
26 ////////////////////////////////////////////////////////////////////////////////
27 // HistoryPlayList public members
28 ////////////////////////////////////////////////////////////////////////////////
30 HistoryPlaylist::HistoryPlaylist(PlaylistCollection
*collection
) :
31 Playlist(collection
, true), m_timer(0)
33 setAllowDuplicates(true);
34 m_timer
= new QTimer(this);
36 connect(PlayerManager::instance(), SIGNAL(signalPlay()), this, SLOT(slotAddPlaying()));
37 connect(m_timer
, SIGNAL(timeout()), this, SLOT(slotCreateNewItem()));
40 HistoryPlaylist::~HistoryPlaylist()
45 HistoryPlaylistItem
*HistoryPlaylist::createItem(const FileHandle
&file
,
46 Q3ListViewItem
*after
, bool emitChanged
)
50 return Playlist::createItem
<HistoryPlaylistItem
, CollectionListItem
,
51 CollectionList
>(file
, after
, emitChanged
);
54 void HistoryPlaylist::createItems(const PlaylistItemList
&siblings
)
56 Playlist::createItems
<CollectionListItem
, HistoryPlaylistItem
, PlaylistItem
>(siblings
);
59 ////////////////////////////////////////////////////////////////////////////////
60 // HistoryPlaylist protected members
61 ////////////////////////////////////////////////////////////////////////////////
63 void HistoryPlaylist::polish()
65 addColumn(i18n("Time"));
70 ////////////////////////////////////////////////////////////////////////////////
72 ////////////////////////////////////////////////////////////////////////////////
74 void HistoryPlaylist::slotAddPlaying()
76 m_file
= PlayerManager::instance()->playingFile();
78 m_timer
->setSingleShot(true);
79 m_timer
->start(delay());
82 void HistoryPlaylist::slotCreateNewItem()
84 PlayerManager
*player
= PlayerManager::instance();
86 if(player
->playing() && m_file
== player
->playingFile()) {
88 m_file
= FileHandle::null();
92 ////////////////////////////////////////////////////////////////////////////////
93 // HistoryPlaylistItem public members
94 ////////////////////////////////////////////////////////////////////////////////
96 HistoryPlaylistItem::HistoryPlaylistItem(CollectionListItem
*item
, Playlist
*parent
, Q3ListViewItem
*after
) :
97 PlaylistItem(item
, parent
, after
),
98 m_dateTime(QDateTime::currentDateTime())
100 setText(0, KGlobal::locale()->formatDateTime(m_dateTime
));
103 HistoryPlaylistItem::HistoryPlaylistItem(CollectionListItem
*item
, Playlist
*parent
) :
104 PlaylistItem(item
, parent
),
105 m_dateTime(QDateTime::currentDateTime())
107 setText(0, KGlobal::locale()->formatDateTime(m_dateTime
));
110 HistoryPlaylistItem::~HistoryPlaylistItem()
115 void HistoryPlaylistItem::setDateTime(const QDateTime
&dt
)
118 setText(0, KGlobal::locale()->formatDateTime(m_dateTime
));
121 ////////////////////////////////////////////////////////////////////////////////
123 ////////////////////////////////////////////////////////////////////////////////
125 QDataStream
&operator<<(QDataStream
&s
, const HistoryPlaylist
&p
)
127 PlaylistItemList l
= const_cast<HistoryPlaylist
*>(&p
)->items();
129 s
<< qint32(l
.count());
131 for(PlaylistItemList::ConstIterator it
= l
.begin(); it
!= l
.end(); ++it
) {
132 const HistoryPlaylistItem
*i
= static_cast<HistoryPlaylistItem
*>(*it
);
133 s
<< i
->file().absFilePath();
140 QDataStream
&operator>>(QDataStream
&s
, HistoryPlaylist
&p
)
145 HistoryPlaylistItem
*after
= 0;
150 for(int i
= 0; i
< count
; i
++) {
154 after
= p
.createItem(FileHandle(fileName
), after
, false);
155 after
->setDateTime(dateTime
);
163 #include "historyplaylist.moc"
165 // vim: set et sw=4 tw=0 sta: