Fairly large overhaul of the JuK codebase to beat out a lot of the Qt 3 stuff.
[kdemultimedia.git] / juk / historyplaylist.cpp
bloba4e380e1b8664cd1582667537d92fee6f66a6b97
1 /***************************************************************************
2 begin : Fri Aug 8 2003
3 copyright : (C) 2003 - 2004 by Scott Wheeler
4 email : wheeler@kde.org
5 ***************************************************************************/
7 /***************************************************************************
8 * *
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. *
13 * *
14 ***************************************************************************/
16 #include "historyplaylist.h"
17 #include "collectionlist.h"
18 #include "playermanager.h"
20 #include <QTimer>
22 #include <klocale.h>
23 #include <kglobal.h>
24 #include <kdebug.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)
48 if(!after)
49 after = lastItem();
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"));
66 Playlist::polish();
67 setSorting(-1);
70 ////////////////////////////////////////////////////////////////////////////////
71 // private slots
72 ////////////////////////////////////////////////////////////////////////////////
74 void HistoryPlaylist::slotAddPlaying()
76 m_file = PlayerManager::instance()->playingFile();
77 m_timer->stop();
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()) {
87 createItem(m_file);
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)
117 m_dateTime = dt;
118 setText(0, KGlobal::locale()->formatDateTime(m_dateTime));
121 ////////////////////////////////////////////////////////////////////////////////
122 // helper functions
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();
134 s << i->dateTime();
137 return s;
140 QDataStream &operator>>(QDataStream &s, HistoryPlaylist &p)
142 qint32 count;
143 s >> count;
145 HistoryPlaylistItem *after = 0;
147 QString fileName;
148 QDateTime dateTime;
150 for(int i = 0; i < count; i++) {
151 s >> fileName;
152 s >> dateTime;
154 after = p.createItem(FileHandle(fileName), after, false);
155 after->setDateTime(dateTime);
158 p.dataChanged();
160 return s;
163 #include "historyplaylist.moc"
165 // vim: set et sw=4 tw=0 sta: