Commit 92092c18 authored by Scott Wheeler's avatar Scott Wheeler

Updates to the (still only sort of working) history playlist.

Added new virtual methods to Playlist -- readOnly() and columnOffset().

columnOffset() indicates the position at which the Playlist class can expect
to find the standard set of columns.  This let me add a "time" column to
the history playlist.

I adjusted the code in other places to use these two new methods.

Also allow the history playlist to have multiple copies of the same item;
this is still buggy at the moment since this API feature hadn't yet been
used.

svn path=/trunk/kdemultimedia/juk/; revision=241800
parent ce753dd3
......@@ -41,7 +41,7 @@ HistoryPlaylistItem::~HistoryPlaylistItem()
HistoryPlaylist::HistoryPlaylist(QWidget *parent) : Playlist(parent, i18n("History"))
{
setAllowDuplicates(true);
}
HistoryPlaylist::~HistoryPlaylist()
......@@ -53,3 +53,16 @@ void HistoryPlaylist::createItems(const PlaylistItemList &siblings)
{
Playlist::createItems<CollectionListItem, HistoryPlaylistItem, PlaylistItem>(siblings);
}
////////////////////////////////////////////////////////////////////////////////
// HistoryPlaylist protected members
////////////////////////////////////////////////////////////////////////////////
void HistoryPlaylist::polish()
{
addColumn(i18n("Time"));
Playlist::polish();
setSorting(-1);
}
#include "historyplaylist.moc"
......@@ -25,11 +25,21 @@ class HistoryPlaylistItem;
class HistoryPlaylist : public Playlist
{
Q_OBJECT
public:
HistoryPlaylist(QWidget *parent);
virtual ~HistoryPlaylist();
virtual void createItems(const PlaylistItemList &siblings);
virtual int columnOffset() { return 1; }
virtual bool readOnly() { return true; }
public slots:
void cut() {}
void clear() {}
protected:
virtual void polish();
};
......
......@@ -782,7 +782,10 @@ KAction *JuK::createSplitterAction(const QString &text, const char *slot,
void JuK::slotPlaylistChanged()
{
if(m_splitter->collectionListSelected() || !m_splitter->hasListSelected()) {
if(m_splitter->collectionListSelected() ||
!m_splitter->hasListSelected() ||
m_splitter->readOnlyListSelected())
{
actionCollection()->action("file_save")->setEnabled(false);
actionCollection()->action("file_save_as")->setEnabled(false);
actionCollection()->action("renamePlaylist")->setEnabled(false);
......@@ -805,7 +808,6 @@ void JuK::slotPlaylistChanged()
else
actionCollection()->action("duplicatePlaylist")->setEnabled(false);
updatePlaylistInfo();
}
......
......@@ -931,16 +931,25 @@ void Playlist::slotShowRMBMenu(QListViewItem *item, const QPoint &point, int col
m_rmbMenu->insertItem(SmallIconSet("player_play"), i18n("Play Next"), this, SLOT(slotSetNext()));
m_rmbMenu->insertSeparator();
m_rmbMenu->insertItem(SmallIconSet("editcut"), i18n("Cut"), this, SLOT(cut()));
if(!readOnly())
m_rmbMenu->insertItem(SmallIconSet("editcut"), i18n("Cut"), this, SLOT(cut()));
m_rmbMenu->insertItem(SmallIconSet("editcopy"), i18n("Copy"), this, SLOT(copy()));
m_rmbPasteID = m_rmbMenu->insertItem(SmallIconSet("editpaste"), i18n("Paste"), this, SLOT(paste()));
m_rmbMenu->insertItem(SmallIconSet("editclear"), i18n("Clear"), this, SLOT(clear()));
m_rmbMenu->insertSeparator();
if(!readOnly()) {
m_rmbPasteID = m_rmbMenu->insertItem(SmallIconSet("editpaste"), i18n("Paste"), this, SLOT(paste()));
m_rmbMenu->insertItem(SmallIconSet("editclear"), i18n("Clear"), this, SLOT(clear()));
m_rmbMenu->insertSeparator();
}
m_rmbEditID = m_rmbMenu->insertItem(SmallIconSet("edittool"), i18n("Edit"), this, SLOT(slotRenameTag()));
m_rmbMenu->insertItem(SmallIconSet("reload"), i18n("Refresh Items"), this, SLOT(slotRefresh()));
m_rmbMenu->insertItem(SmallIconSet("editdelete"), i18n("Remove From Disk"), this, SLOT(slotRemoveSelectedItems()));
if(!readOnly()) {
m_rmbMenu->insertItem(SmallIconSet("reload"), i18n("Refresh Items"), this, SLOT(slotRefresh()));
m_rmbMenu->insertItem(SmallIconSet("editdelete"), i18n("Remove From Disk"), this, SLOT(slotRemoveSelectedItems()));
}
m_rmbMenu->insertSeparator();
actionCollection->action("guessTag")->plug(m_rmbMenu);
......@@ -949,7 +958,12 @@ void Playlist::slotShowRMBMenu(QListViewItem *item, const QPoint &point, int col
m_rmbMenu->insertItem(SmallIcon("new"), i18n("Create Group From Selected Items"), this, SLOT(slotCreateGroup()));
}
m_rmbMenu->setItemEnabled(m_rmbPasteID, canDecode(kapp->clipboard()->data()));
if(!readOnly())
m_rmbMenu->setItemEnabled(m_rmbPasteID, canDecode(kapp->clipboard()->data()));
// Ignore any columns added by subclasses.
column -= columnOffset();
bool showEdit =
(column == PlaylistItem::TrackColumn) ||
......@@ -979,7 +993,7 @@ void Playlist::slotRenameTag()
KLineEdit *edit = renameLineEdit();
switch(m_currentColumn)
switch(m_currentColumn - columnOffset())
{
case PlaylistItem::TrackColumn:
edit->completionObject()->setItems(list->uniqueSet(CollectionList::Artists));
......@@ -1007,7 +1021,7 @@ void Playlist::applyTag(QListViewItem *item, const QString &text, int column)
{
PlaylistItem *i = static_cast<PlaylistItem *>(item);
switch(column)
switch(column - columnOffset())
{
case PlaylistItem::TrackColumn:
i->tag()->setTrack(text);
......
......@@ -100,7 +100,7 @@ public:
/**
* Allow duplicate files in the playlist.
*/
void setAllowDuplicates(bool allow);
void setAllowDuplicates(bool allow) { m_allowDuplicates = allow; }
/**
* This is being used as a mini-factory of sorts to make the construction
......@@ -213,6 +213,9 @@ public:
*/
void emitCountChanged() { emit signalCountChanged(this); }
virtual int columnOffset() { return 0; }
virtual bool readOnly() { return false; }
public slots:
/**
* Remove the currently selected items from the playlist and disk.
......@@ -478,7 +481,7 @@ void Playlist::createItems(const QValueList<SiblingType *> &siblings)
QValueListConstIterator<SiblingType *> it = siblings.begin();
for(; it != siblings.end(); ++it) {
if(!m_members.insert(resolveSymLinks((*it)->absFilePath()))) {
if(!m_members.insert(resolveSymLinks((*it)->absFilePath())) || m_allowDuplicates) {
previous = new ItemType((*it)->collectionItem(), this, previous);
connect((*it)->collectionItem(), SIGNAL(destroyed()), (*it), SLOT(deleteLater()));
}
......
......@@ -66,7 +66,7 @@ PlaylistBox::PlaylistBox(PlaylistSplitter *parent, const QString &name) :
return;
KActionCollection *actions = static_cast<KMainWindow *>(w)->actionCollection();
actions->action("file_new")->plug(m_contextMenu);
actions->action("renamePlaylist")->plug(m_contextMenu);
actions->action("duplicatePlaylist")->plug(m_contextMenu);
......@@ -340,7 +340,7 @@ void PlaylistBox::deleteItems(const ItemList &items)
void PlaylistBox::decode(QMimeSource *s, Item *item)
{
if(!s)
if(!s || (item->playlist() && item->playlist()->readOnly()))
return;
KURL::List urls;
......@@ -380,6 +380,9 @@ void PlaylistBox::contentsDragMoveEvent(QDragMoveEvent *e)
if(itemAt(e->pos())) {
Item *target = static_cast<Item *>(itemAt(e->pos()));
if(target->playlist() && target->playlist()->readOnly())
return;
// This is a semi-dirty hack to check if the items are coming from within
// JuK. If they are not coming from a Playlist (or subclass) then the
// dynamic_cast will fail and we can safely assume that the item is
......
......@@ -292,20 +292,23 @@ void PlaylistItem::slotRefreshImpl()
// This should be the only function that needs to be rewritten if the structure of
// PlaylistItemData changes.
setText(TrackColumn, tag()->track());
setText(ArtistColumn, tag()->artist());
setText(AlbumColumn, tag()->album());
setText(TrackNumberColumn, tag()->trackNumberString());
setText(GenreColumn, tag()->genre());
setText(YearColumn, tag()->yearString());
setText(LengthColumn, tag()->lengthString());
setText(FileNameColumn, filePath());
int offset = static_cast<Playlist *>(listView())->columnOffset();
setText(TrackColumn + offset, tag()->track());
setText(ArtistColumn + offset, tag()->artist());
setText(AlbumColumn + offset, tag()->album());
setText(TrackNumberColumn + offset, tag()->trackNumberString());
setText(GenreColumn + offset, tag()->genre());
setText(YearColumn + offset, tag()->yearString());
setText(LengthColumn + offset, tag()->lengthString());
setText(FileNameColumn + offset, filePath());
QString shortComment = tag()->comment().simplifyWhiteSpace();
if(shortComment.length() > 50)
shortComment = shortComment.left(47) + "...";
setText(CommentColumn, shortComment);
setText(CommentColumn + offset, shortComment);
}
void PlaylistItem::slotTagGuessResults(const MusicBrainzQuery::TrackList &res)
......
......@@ -137,6 +137,11 @@ public:
*/
bool fileBasedListSelected() { return !visiblePlaylist()->fileName().isNull(); }
/**
* Returns true if the selected list is read only.
*/
bool readOnlyListSelected() { return visiblePlaylist()->readOnly(); }
/**
* Returns true if the currently selected playlist is a dynamic list.
*/
......
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