Commit 6fa40a24 authored by Scott Wheeler's avatar Scott Wheeler
Browse files

API Cleanups -- made PlaylistBoxItem the private class PlaylistBox::Item

and cleaned up the API to support that decoupling.

svn path=/trunk/kdemultimedia/juk/; revision=207975
parent cc09ad56
......@@ -52,8 +52,7 @@
Playlist::Playlist(PlaylistSplitter *s, QWidget *parent, const QString &name) : KListView(parent, name.latin1()),
playlistName(name),
splitter(s),
boxItem(0)
splitter(s)
{
setup();
}
......
......@@ -27,7 +27,6 @@
#include "sortedstringlist.h"
class PlaylistSplitter;
class PlaylistBoxItem;
class KPopupMenu;
class KPopupMenu;
......@@ -117,9 +116,6 @@ public:
*/
void setName(const QString &n);
PlaylistBoxItem *playlistBoxItem() const { return boxItem; }
void setPlaylistBoxItem(PlaylistBoxItem *item) { boxItem = item; }
int count() const { return childCount(); }
/**
......@@ -173,7 +169,7 @@ signals:
void selectionChanged(const PlaylistItemList &selection);
/**
* This is connected to the PlaylistBoxItem to let it know when the
* This is connected to the PlaylistBox::Item to let it know when the
* playlist's name has changed.
*/
void nameChanged(const QString &fileName);
......@@ -215,7 +211,6 @@ private:
*/
QString playlistName;
PlaylistSplitter *splitter;
PlaylistBoxItem *boxItem;
KPopupMenu *rmbMenu;
KPopupMenu *headerMenu;
......
......@@ -65,6 +65,20 @@ PlaylistBox::~PlaylistBox()
delete playlistContextMenu;
}
void PlaylistBox::createItem(Playlist *playlist, const char *icon, bool raise)
{
if(!playlist)
return;
Item *i = new Item(this, SmallIcon(icon, 32), playlist->name(), playlist);
_playlistDict.insert(playlist, i);
if(raise) {
setCurrentItem(i);
ensureCurrentVisible();
}
}
void PlaylistBox::sort()
{
QListBoxItem *collectionItem = firstItem();
......@@ -86,43 +100,91 @@ void PlaylistBox::sort()
updatePlaylistStack = true;
}
void PlaylistBox::raise(Playlist *playlist)
{
if(!playlist)
return;
Item *i = _playlistDict.find(playlist);
clearSelection();
setSelected(i, true);
setCurrentItem(i);
ensureCurrentVisible();
}
QStringList PlaylistBox::names() const
{
return nameList;
}
QPtrList<Playlist> PlaylistBox::playlists() const
{
QPtrList<Playlist> l;
// skip the collection list
for(uint j = 1; j < count(); j++) {
Item *i = static_cast<Item *>(item(j));
l.append(i->playlist());
}
return l;
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistBox public slots
////////////////////////////////////////////////////////////////////////////////
void PlaylistBox::save()
{
save(static_cast<PlaylistBoxItem *>(selectedItem()));
save(static_cast<Item *>(selectedItem()));
}
void PlaylistBox::save(PlaylistBoxItem *item)
void PlaylistBox::saveAs()
{
if(item)
item->playlist()->save();
saveAs(static_cast<Item *>(selectedItem()));
}
void PlaylistBox::saveAs()
void PlaylistBox::rename()
{
rename(static_cast<Item *>(selectedItem()));
}
void PlaylistBox::duplicate()
{
saveAs(static_cast<PlaylistBoxItem *>(selectedItem()));
duplicate(static_cast<Item *>(selectedItem()));
}
void PlaylistBox::saveAs(PlaylistBoxItem *item)
void PlaylistBox::deleteItem()
{
deleteItem(static_cast<Item *>(selectedItem()));
}
void PlaylistBox::paste()
{
Item *i = static_cast<Item *>(selectedItem());
decode(kapp->clipboard()->data(), i);
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistBox private methods
////////////////////////////////////////////////////////////////////////////////
void PlaylistBox::save(Item *item)
{
if(item)
item->playlist()->saveAs();
item->playlist()->save();
}
void PlaylistBox::rename()
void PlaylistBox::saveAs(Item *item)
{
rename(static_cast<PlaylistBoxItem *>(selectedItem()));
if(item)
item->playlist()->saveAs();
}
void PlaylistBox::rename(PlaylistBoxItem *item)
void PlaylistBox::rename(Item *item)
{
if(!item)
return;
......@@ -146,12 +208,7 @@ void PlaylistBox::rename(PlaylistBoxItem *item)
}
}
void PlaylistBox::duplicate()
{
duplicate(static_cast<PlaylistBoxItem *>(selectedItem()));
}
void PlaylistBox::duplicate(PlaylistBoxItem *item)
void PlaylistBox::duplicate(Item *item)
{
if(item) {
bool ok;
......@@ -167,12 +224,7 @@ void PlaylistBox::duplicate(PlaylistBoxItem *item)
}
}
void PlaylistBox::deleteItem()
{
deleteItem(static_cast<PlaylistBoxItem *>(selectedItem()));
}
void PlaylistBox::deleteItem(PlaylistBoxItem *item)
void PlaylistBox::deleteItem(Item *item)
{
if(!item || !item->playlist())
return;
......@@ -193,20 +245,11 @@ void PlaylistBox::deleteItem(PlaylistBoxItem *item)
}
nameList.remove(item->text());
_playlistDict.remove(item->playlist());
delete item->playlist();
delete item;
}
void PlaylistBox::paste()
{
PlaylistBoxItem *i = static_cast<PlaylistBoxItem *>(selectedItem());
decode(kapp->clipboard()->data(), i);
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistBox private methods
////////////////////////////////////////////////////////////////////////////////
void PlaylistBox::resizeEvent(QResizeEvent *e)
{
triggerUpdate(true);
......@@ -214,7 +257,7 @@ void PlaylistBox::resizeEvent(QResizeEvent *e)
KListBox::resizeEvent(e);
}
void PlaylistBox::decode(QMimeSource *s, PlaylistBoxItem *item)
void PlaylistBox::decode(QMimeSource *s, Item *item)
{
if(!s || !item || !item->playlist())
return;
......@@ -234,20 +277,20 @@ void PlaylistBox::decode(QMimeSource *s, PlaylistBoxItem *item)
void PlaylistBox::dropEvent(QDropEvent *e)
{
PlaylistBoxItem *i = static_cast<PlaylistBoxItem *>(itemAt(e->pos()));
Item *i = static_cast<Item *>(itemAt(e->pos()));
decode(e, i);
}
void PlaylistBox::dragMoveEvent(QDragMoveEvent *e)
{
// If we can decode the input source, there is a non-null item at the "move"
// position, the playlist for that PlaylistBoxItem is non-null, is not the
// position, the playlist for that Item is non-null, is not the
// selected playlist and is not the CollectionList, then accept the event.
//
// Otherwise, do not accept the event.
if(KURLDrag::canDecode(e) && itemAt(e->pos())) {
PlaylistBoxItem *i = static_cast<PlaylistBoxItem *>(itemAt(e->pos()));
Item *i = static_cast<Item *>(itemAt(e->pos()));
// 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
......@@ -296,15 +339,15 @@ void PlaylistBox::addName(const QString &name)
void PlaylistBox::playlistChanged(QListBoxItem *item)
{
PlaylistBoxItem *i = dynamic_cast<PlaylistBoxItem *>(item);
if(updatePlaylistStack && i)
emit(currentChanged(i));
Item *i = dynamic_cast<Item *>(item);
if(updatePlaylistStack && i && i->playlist())
emit(currentChanged(i->playlist()));
}
void PlaylistBox::playlistDoubleClicked(QListBoxItem *)
{
/*
PlaylistBoxItem *i = dynamic_cast<PlaylistBoxItem *>(item);
Item *i = dynamic_cast<Item *>(item);
if(i)
emit(doubleClicked(i));
*/
......@@ -313,7 +356,7 @@ void PlaylistBox::playlistDoubleClicked(QListBoxItem *)
void PlaylistBox::drawContextMenu(QListBoxItem *item, const QPoint &point)
{
PlaylistBoxItem *i = static_cast<PlaylistBoxItem *>(item);
Item *i = static_cast<Item *>(item);
contextMenuOn = i;
......@@ -351,10 +394,10 @@ void PlaylistBox::contextDeleteItem()
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistBoxItem public methods
// PlaylistBox::Item public methods
////////////////////////////////////////////////////////////////////////////////
PlaylistBoxItem::PlaylistBoxItem(PlaylistBox *listbox, const QPixmap &pix, const QString &text, Playlist *l)
PlaylistBox::Item::Item(PlaylistBox *listbox, const QPixmap &pix, const QString &text, Playlist *l)
: QObject(listbox), ListBoxPixmap(listbox, pix, text)
{
list = l;
......@@ -364,29 +407,29 @@ PlaylistBoxItem::PlaylistBoxItem(PlaylistBox *listbox, const QPixmap &pix, const
connect(l, SIGNAL(nameChanged(const QString &)), this, SLOT(setName(const QString &)));
}
PlaylistBoxItem::PlaylistBoxItem(PlaylistBox *listbox, const QString &text, Playlist *l)
PlaylistBox::Item::Item(PlaylistBox *listbox, const QString &text, Playlist *l)
: ListBoxPixmap(listbox, SmallIcon("midi", 32), text)
{
list = l;
setOrientation(Qt::Vertical);
}
PlaylistBoxItem::~PlaylistBoxItem()
PlaylistBox::Item::~Item()
{
}
Playlist *PlaylistBoxItem::playlist() const
Playlist *PlaylistBox::Item::playlist() const
{
return list;
}
PlaylistBox *PlaylistBoxItem::listBox() const
PlaylistBox *PlaylistBox::Item::listBox() const
{
return dynamic_cast<PlaylistBox *>(ListBoxPixmap::listBox());
}
void PlaylistBoxItem::setName(const QString &name)
void PlaylistBox::Item::setName(const QString &name)
{
if(listBox()) {
listBox()->nameList.remove(text());
......
......@@ -22,13 +22,14 @@
#include <kpopupmenu.h>
#include <qwidgetstack.h>
#include <qptrlist.h>
#include <qptrdict.h>
#include "listboxpixmap.h"
class Playlist;
class PlaylistItem;
class PlaylistBoxItem;
class PlaylistSplitter;
/**
......@@ -38,40 +39,52 @@ class PlaylistSplitter;
class PlaylistBox : public KListBox
{
friend class PlaylistBoxItem;
Q_OBJECT
public:
enum ItemType { Collection, Plain };
PlaylistBox(PlaylistSplitter *parent = 0, const char *name = 0);
virtual ~PlaylistBox();
void createItem(Playlist *playlist, const char *icon = 0, bool raise = false);
void sort();
void raise(Playlist *playlist);
QStringList names() const;
QPtrList<Playlist> playlists() const;
public slots:
// All of the slots without parameters default to the selected item.
void save();
void save(PlaylistBoxItem *item);
void saveAs();
void saveAs(PlaylistBoxItem *item);
void rename();
void rename(PlaylistBoxItem *item);
void duplicate();
void duplicate(PlaylistBoxItem *item);
void deleteItem();
void deleteItem(PlaylistBoxItem *item);
void paste();
/**
* Override the default behavior of clear so that the clipboard code doesn't
* do bad things.
*/
void clear() {}
signals:
void currentChanged(PlaylistBoxItem *);
void currentChanged(Playlist *);
void doubleClicked();
private:
class Item;
friend class Item;
void save(Item *item);
void saveAs(Item *item);
void rename(Item *item);
void duplicate(Item *item);
void deleteItem(Item *item);
virtual void resizeEvent(QResizeEvent *e);
virtual void decode(QMimeSource *s, PlaylistBoxItem *item);
virtual void decode(QMimeSource *s, Item *item);
virtual void dropEvent(QDropEvent *e);
virtual void dragMoveEvent(QDragMoveEvent *e);
virtual void mousePressEvent(QMouseEvent *e);
......@@ -84,7 +97,7 @@ private:
private slots:
/**
* Catches QListBox::currentChanged(QListBoxItem *), does a cast and then re-emits
* the signal as currentChanged(PlaylistBoxItem *).
* the signal as currentChanged(Item *).
*/
void playlistChanged(QListBoxItem *item);
void playlistDoubleClicked(QListBoxItem *);
......@@ -102,22 +115,23 @@ private:
QStringList nameList;
KPopupMenu *collectionContextMenu;
KPopupMenu *playlistContextMenu;
PlaylistBoxItem *contextMenuOn;
Item *contextMenuOn;
bool updatePlaylistStack;
QPtrDict<Item> _playlistDict;
};
class PlaylistBoxItem : public QObject, public ListBoxPixmap
class PlaylistBox::Item : public QObject, public ListBoxPixmap
{
friend class PlaylistBox;
Q_OBJECT
public:
PlaylistBoxItem(PlaylistBox *listbox, const QPixmap &pix, const QString &text, Playlist *l = 0);
PlaylistBoxItem(PlaylistBox *listbox, const QString &text, Playlist *l = 0);
virtual ~PlaylistBoxItem();
Item(PlaylistBox *listbox, const QPixmap &pix, const QString &text, Playlist *l = 0);
Item(PlaylistBox *listbox, const QString &text, Playlist *l = 0);
virtual ~Item();
Playlist *playlist() const;
PlaylistBox *listBox() const;
......
......@@ -331,29 +331,14 @@ void PlaylistSplitter::selectPlaying()
Playlist *l = static_cast<Playlist *>(playingItem->listView());
if(l) {
if(!l)
return;
l->clearSelection();
l->setSelected(playingItem, true);
l->ensureItemVisible(playingItem);
// Now move on to the PlaylistBox. The Playlist knows which
// PlaylistBoxItem that it is associated with, so we'll just get
// that and then figure out the PlaylistBox from there.
//
// Once we have that we can set the appropriate Playlist to be
// visible.
if(l->playlistBoxItem() && l->playlistBoxItem()->listBox()) {
QListBox *b = l->playlistBoxItem()->listBox();
b->clearSelection();
b->setSelected(l->playlistBoxItem(), true);
b->setCurrentItem(l->playlistBoxItem());
b->ensureCurrentVisible();
}
}
l->clearSelection();
l->setSelected(playingItem, true);
l->ensureItemVisible(playingItem);
playlistBox->raise(l);
}
void PlaylistSplitter::removeSelectedItems()
......@@ -398,8 +383,8 @@ void PlaylistSplitter::setupLayout()
// Make the connection that will update the selected playlist when a
// selection is made in the playlist box.
connect(playlistBox, SIGNAL(currentChanged(PlaylistBoxItem *)),
this, SLOT(changePlaylist(PlaylistBoxItem *)));
connect(playlistBox, SIGNAL(currentChanged(Playlist *)),
this, SLOT(changePlaylist(Playlist *)));
connect(playlistBox, SIGNAL(doubleClicked()), this, SIGNAL(listBoxDoubleClicked()));
......@@ -497,16 +482,12 @@ void PlaylistSplitter::saveConfig()
QDataStream s(&f);
for(uint i = 1; i < playlistBox->count(); i++) {
PlaylistBoxItem *item = static_cast<PlaylistBoxItem *>(playlistBox->item(i));
if(item && item->playlist()) {
Playlist *p = item->playlist();
s << *p;
}
}
QPtrList<Playlist> l = playlistBox->playlists();
f.close();
for(Playlist *p = l.first(); p; p = l.next())
s << *p;
f.close();
}
{ // block for Playlists group
KConfigGroupSaver saver(config, "Playlists");
......@@ -547,10 +528,6 @@ void PlaylistSplitter::addImpl(const QString &file, Playlist *list)
void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon)
{
PlaylistBoxItem *i = new PlaylistBoxItem(playlistBox, SmallIcon(icon, 32), p->name(), p);
p->setPlaylistBoxItem(i);
playlistBox->sort();
connect(p, SIGNAL(selectionChanged(const PlaylistItemList &)), editor, SLOT(setItems(const PlaylistItemList &)));
connect(p, SIGNAL(doubleClicked()), this, SIGNAL(doubleClicked()));
connect(p, SIGNAL(collectionChanged()), editor, SLOT(updateCollection()));
......@@ -559,11 +536,11 @@ void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon)
connect(p, SIGNAL(signalToggleColumnVisible(int)), this, SLOT(slotToggleColumnVisible(int)));
playlistBox->createItem(p, icon, raise);
if(raise) {
playlistStack->raiseWidget(p);
setupColumns(p);
playlistBox->setCurrentItem(i);
playlistBox->ensureCurrentVisible();
}
}
......@@ -595,14 +572,15 @@ void PlaylistSplitter::setupColumns(Playlist *p)
// private slots
////////////////////////////////////////////////////////////////////////////////
void PlaylistSplitter::changePlaylist(PlaylistBoxItem *item)
void PlaylistSplitter::changePlaylist(Playlist *p)
{
if(item && item->playlist()) {
playlistStack->raiseWidget(item->playlist());
editor->setItems(playlistSelection());
setupColumns(item->playlist());
emit(playlistChanged());
}
if(!p)
return;
playlistStack->raiseWidget(p);
editor->setItems(playlistSelection());
setupColumns(p);
emit(playlistChanged());
}
void PlaylistSplitter::playlistCountChanged(Playlist *p)
......
......@@ -30,7 +30,6 @@
#include "tageditor.h"
class KActionMenu;
class PlaylistBoxItem;
class PlaylistItem;
/**
......@@ -264,7 +263,7 @@ private:
void setupColumns(Playlist *p);
private slots:
void changePlaylist(PlaylistBoxItem *item);
void changePlaylist(Playlist *p);
void playlistCountChanged(Playlist *p);
/**
* Add a directory to the directory list queue. We need to queue these
......
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