Commit 34c906c5 authored by Scott Wheeler's avatar Scott Wheeler

More cleanups -- this time: finished TagEditor, CollectionList,

Playlist and PlaylistItem

svn path=/trunk/kdemultimedia/juk/; revision=209952
parent 5522fa78
......@@ -181,8 +181,8 @@ CollectionListItem::CollectionListItem(const QFileInfo &file, const QString &pat
if(l) {
l->addToDict(path, this);
setData(Data::newUser(file, path));
refresh();
connect(this, SIGNAL(refreshed()), l, SIGNAL(dataChanged()));
slotRefresh();
connect(this, SIGNAL(signalRefreshed()), l, SIGNAL(signalDataChanged()));
l->emitNumberOfItemsChanged();
}
else
......@@ -201,24 +201,24 @@ CollectionListItem::~CollectionListItem()
void CollectionListItem::addChildItem(PlaylistItem *child)
{
connect(child, SIGNAL(refreshed()), this, SLOT(refresh()));
connect(this, SIGNAL(refreshed()), child, SLOT(refreshImpl()));
connect(child, SIGNAL(signalRefreshed()), this, SLOT(slotRefresh()));
connect(this, SIGNAL(signalRefreshed()), child, SLOT(slotRefreshImpl()));
}
////////////////////////////////////////////////////////////////////////////////
// CollectionListItem public slots
////////////////////////////////////////////////////////////////////////////////
void CollectionListItem::refresh()
void CollectionListItem::slotRefresh()
{
refreshImpl();
slotRefreshImpl();
if(CollectionList::instance()) {
CollectionList::instance()->addArtist(text(ArtistColumn));
CollectionList::instance()->addAlbum(text(AlbumColumn));
}
// This is connected to refreshImpl() for all of the items children.
emit(refreshed());
// This is connected to slotRefreshImpl() for all of the items children.
emit(signalRefreshed());
}
#include "collectionlist.moc"
......@@ -82,7 +82,7 @@ protected:
*/
void addAlbum(const QString &album);
void emitNumberOfItemsChanged() { emit(numberOfItemsChanged(this)); }
void emitNumberOfItemsChanged() { emit signalNumberOfItemsChanged(this); }
private:
static CollectionList *list;
......@@ -103,7 +103,7 @@ public:
virtual ~CollectionListItem();
public slots:
virtual void refresh();
virtual void slotRefresh();
protected:
CollectionListItem(const QFileInfo &file, const QString &path);
......
......@@ -131,7 +131,7 @@ void Playlist::saveAs()
m_playlistFileName.append('.' + extensions.first());
if(m_playlistName.isEmpty())
emit(nameChanged(name()));
emit signalNameChanged(name());
save();
}
......@@ -144,7 +144,7 @@ void Playlist::refresh()
KApplication::setOverrideCursor(Qt::waitCursor);
int j = 0;
for(PlaylistItem *i = static_cast<PlaylistItem *>(firstChild()); i; i = static_cast<PlaylistItem *>(i->itemBelow())) {
i->refreshFromDisk();
i->slotRefreshFromDisk();
if(j % 5 == 0)
kapp->processEvents();
j = j % 5 + 1;
......@@ -156,12 +156,12 @@ void Playlist::clearItems(const PlaylistItemList &items)
{
QPtrListIterator<PlaylistItem> it(items);
while(it.current()) {
emit(aboutToRemove(it.current()));
emit signalAboutToRemove(it.current());
m_members.remove(it.current()->absFilePath());
delete it.current();
++it;
}
emit(numberOfItemsChanged(this));
emit signalNumberOfItemsChanged(this);
}
QStringList Playlist::files() const
......@@ -192,36 +192,6 @@ PlaylistItemList Playlist::selectedItems() const
return list;
}
void Playlist::remove(const PlaylistItemList &items)
{
if(isVisible() && !items.isEmpty()) {
QStringList files;
for(QPtrListIterator<PlaylistItem> it(items); it.current(); ++it)
files.append(it.current()->fileName());
QString message;
if(files.count() == 1)
message = i18n("Do you really want to delete this item from your disk?");
else
message = i18n("Do you really want to delete these %1 items from your disk?").arg(QString::number(files.count()));
if(KMessageBox::questionYesNoList(this, message, files) == KMessageBox::Yes) {
for(QPtrListIterator<PlaylistItem> it(items); it.current(); ++it) {
if(QFile::remove(it.current()->filePath())) {
emit(aboutToRemove(it.current()));
delete it.current();
}
else
KMessageBox::sorry(this, i18n("Could not delete ") + it.current()->fileName() + ".");
}
}
emit(numberOfItemsChanged(this));
}
}
PlaylistItem *Playlist::nextItem(PlaylistItem *current, bool random)
{
if(!current)
......@@ -269,7 +239,7 @@ QString Playlist::name() const
void Playlist::setName(const QString &n)
{
m_playlistName = n;
emit(nameChanged(m_playlistName));
emit signalNameChanged(m_playlistName);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -292,9 +262,39 @@ void Playlist::clear()
}
////////////////////////////////////////////////////////////////////////////////
// protected m_members
// protected members
////////////////////////////////////////////////////////////////////////////////
void Playlist::deleteFromDisk(const PlaylistItemList &items)
{
if(isVisible() && !items.isEmpty()) {
QStringList files;
for(QPtrListIterator<PlaylistItem> it(items); it.current(); ++it)
files.append(it.current()->fileName());
QString message;
if(files.count() == 1)
message = i18n("Do you really want to delete this item from your disk?");
else
message = i18n("Do you really want to delete these %1 items from your disk?").arg(QString::number(files.count()));
if(KMessageBox::questionYesNoList(this, message, files) == KMessageBox::Yes) {
for(QPtrListIterator<PlaylistItem> it(items); it.current(); ++it) {
if(QFile::remove(it.current()->filePath())) {
emit signalAboutToRemove(it.current());
delete it.current();
}
else
KMessageBox::sorry(this, i18n("Could not delete ") + it.current()->fileName() + ".");
}
}
emit signalNumberOfItemsChanged(this);
}
}
QDragObject *Playlist::dragObject(QWidget *parent)
{
PlaylistItemList items = selectedItems();
......@@ -400,7 +400,7 @@ PlaylistItem *Playlist::createItem(const QFileInfo &file, QListViewItem *after)
i = new PlaylistItem(item, this, after);
else
i = new PlaylistItem(item, this);
emit(numberOfItemsChanged(this));
emit signalNumberOfItemsChanged(this);
connect(item, SIGNAL(destroyed()), i, SLOT(deleteLater()));
return i;
}
......@@ -507,18 +507,20 @@ void Playlist::setup()
m_rmbMenu->insertSeparator();
m_rmbMenu->insertItem(SmallIcon("editdelete"), i18n("Remove From Disk"), this, SLOT(removeSelectedItems()));
m_rmbMenu->insertItem(SmallIcon("editdelete"), i18n("Remove From Disk"), this, SLOT(slotDeleteSelectedItems()));
m_rmbMenu->insertSeparator();
m_rmbEditID = m_rmbMenu->insertItem(SmallIcon("edittool"), i18n("Edit"), this, SLOT(renameTag()));
m_rmbEditID = m_rmbMenu->insertItem(SmallIcon("edittool"), i18n("Edit"), this, SLOT(slotRenameTag()));
connect(this, SIGNAL(selectionChanged()), this, SLOT(emitSelected()));
connect(this, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(emitDoubleClicked(QListViewItem *)));
connect(this, SIGNAL(selectionChanged()),
this, SLOT(slotEmitSelected()));
connect(this, SIGNAL(doubleClicked(QListViewItem *)),
this, SLOT(slotEmitDoubleClicked(QListViewItem *)));
connect(this, SIGNAL(contextMenuRequested( QListViewItem *, const QPoint&, int)),
this, SLOT(showRMBMenu(QListViewItem *, const QPoint &, int)));
this, SLOT(slotShowRMBMenu(QListViewItem *, const QPoint &, int)));
connect(this, SIGNAL(itemRenamed(QListViewItem *, const QString &, int)),
this, SLOT(applyTags(QListViewItem *, const QString &, int)));
this, SLOT(slotApplyTags(QListViewItem *, const QString &, int)));
//////////////////////////////////////////////////
......@@ -533,7 +535,7 @@ void Playlist::setup()
// private slots
////////////////////////////////////////////////////////////////////////////////
void Playlist::showRMBMenu(QListViewItem *item, const QPoint &point, int column)
void Playlist::slotShowRMBMenu(QListViewItem *item, const QPoint &point, int column)
{
if(!item)
return;
......@@ -554,7 +556,7 @@ void Playlist::showRMBMenu(QListViewItem *item, const QPoint &point, int column)
m_currentColumn = column;
}
void Playlist::renameTag()
void Playlist::slotRenameTag()
{
// setup completions and validators
......@@ -584,7 +586,7 @@ void Playlist::renameTag()
rename(currentItem(), m_currentColumn);
}
void Playlist::applyTags(QListViewItem *item, const QString &text, int column)
void Playlist::slotApplyTags(QListViewItem *item, const QString &text, int column)
{
// kdDebug() << "Applying " << text << " at column " << column << ", replacing \"" << item->text(column) << "\"" << endl;
......@@ -623,9 +625,13 @@ void Playlist::applyTags(QListViewItem *item, const QString &text, int column)
}
i->tag()->save();
i->refresh();
i->slotRefresh();
}
////////////////////////////////////////////////////////////////////////////////
// helper functions
////////////////////////////////////////////////////////////////////////////////
QDataStream &operator<<(QDataStream &s, const Playlist &p)
{
s << p.name();
......
......@@ -71,7 +71,6 @@ public:
/**
* Returns a list of all of the items in the playlist.
*/
PlaylistItemList items() const;
/**
......@@ -79,12 +78,6 @@ public:
*/
PlaylistItemList selectedItems() const;
/**
* Remove \a items from the playlist and disk. This will ignore items that
* are not actually in the list.
*/
void remove(const PlaylistItemList &items);
/**
* Allow duplicate files in the playlist.
*/
......@@ -131,7 +124,7 @@ public slots:
/**
* Remove the currently selected items from the playlist and disk.
*/
void removeSelectedItems() { remove(selectedItems()); };
void slotDeleteSelectedItems() { deleteFromDisk(selectedItems()); };
virtual void cut() { copy(); clear(); }
virtual void copy();
......@@ -140,6 +133,12 @@ public slots:
virtual void selectAll() { KListView::selectAll(true); }
protected:
/**
* Remove \a items from the playlist and disk. This will ignore items that
* are not actually in the list.
*/
void deleteFromDisk(const PlaylistItemList &items);
virtual bool eventFilter(QObject* watched, QEvent* e);
virtual QDragObject *dragObject(QWidget *parent);
virtual QDragObject *dragObject();
......@@ -154,35 +153,35 @@ signals:
* This signal is connected to PlaylistItem::refreshed() in the
* PlaylistItem class.
*/
void dataChanged();
void signalDataChanged();
/**
* This signal is emitted when items are added to the collection list.
* This happens in the createItem() method when items are added to the
* collection.
*/
void collectionChanged();
void signalCollectionChanged();
/**
* This is emitted when the playlist selection is changed. This is used
* primarily to notify the TagEditor of the new data.
*/
void selectionChanged(const PlaylistItemList &selection);
void signalSelectionChanged(const PlaylistItemList &selection);
/**
* This is connected to the PlaylistBox::Item to let it know when the
* playlist's name has changed.
*/
void nameChanged(const QString &fileName);
void signalNameChanged(const QString &fileName);
void numberOfItemsChanged(Playlist *);
void signalNumberOfItemsChanged(Playlist *);
void doubleClicked();
void signalDoubleClicked();
/**
* This signal is emitted just before a playlist item is removed from the
* list.
*/
void aboutToRemove(PlaylistItem *item);
void signalAboutToRemove(PlaylistItem *item);
void signalToggleColumnVisible(int column);
......@@ -191,11 +190,11 @@ private:
QPtrStack<PlaylistItem> m_history;
private slots:
void emitSelected() { emit(selectionChanged(selectedItems())); }
void emitDoubleClicked(QListViewItem *) { emit(doubleClicked()); }
void showRMBMenu(QListViewItem *item, const QPoint &point, int column);
void applyTags(QListViewItem *item, const QString &text, int column);
void renameTag();
void slotEmitSelected() { emit signalSelectionChanged(selectedItems()); }
void slotEmitDoubleClicked(QListViewItem *) { emit signalDoubleClicked(); }
void slotShowRMBMenu(QListViewItem *item, const QPoint &point, int column);
void slotApplyTags(QListViewItem *item, const QString &text, int column);
void slotRenameTag();
private:
int m_currentColumn;
......
......@@ -391,7 +391,7 @@ PlaylistBox::Item::Item(PlaylistBox *listbox, const QPixmap &pix, const QString
setOrientation(Qt::Vertical);
listbox->addName(text);
connect(l, SIGNAL(nameChanged(const QString &)), this, SLOT(setName(const QString &)));
connect(l, SIGNAL(signalNameChanged(const QString &)), this, SLOT(setName(const QString &)));
}
PlaylistBox::Item::Item(PlaylistBox *listbox, const QString &text, Playlist *l)
......
......@@ -33,7 +33,7 @@ PlaylistItem::~PlaylistItem()
void PlaylistItem::setFile(const QString &file)
{
m_data->setFile(file);
refresh();
slotRefresh();
}
Tag *PlaylistItem::tag() const
......@@ -41,7 +41,8 @@ Tag *PlaylistItem::tag() const
return m_data->tag();
}
// some forwarding methods
// some forwarding methods - these can't be inlined because the Data class
// isn't defined yet
QString PlaylistItem::fileName() const
{
......@@ -72,17 +73,17 @@ bool PlaylistItem::isWritable() const
// PlaylistItem public slots
////////////////////////////////////////////////////////////////////////////////
void PlaylistItem::refresh()
void PlaylistItem::slotRefresh()
{
// This signal will be received by the "parent" CollectionListItem which will
// in turn call refreshImpl() for all of its children, including this item.
emit(refreshed());
// in turn call slotRefreshImpl() for all of its children, including this item.
emit(signalRefreshed());
}
void PlaylistItem::refreshFromDisk()
void PlaylistItem::slotRefreshFromDisk()
{
m_data->refresh();
refresh();
slotRefresh();
}
////////////////////////////////////////////////////////////////////////////////
......@@ -118,7 +119,7 @@ void PlaylistItem::setData(Data *d)
// PlaylistItem protected slots
////////////////////////////////////////////////////////////////////////////////
void PlaylistItem::refreshImpl()
void PlaylistItem::slotRefreshImpl()
{
// This should be the only function that needs to be rewritten if the structure of
// PlaylistItemData changes.
......@@ -142,8 +143,8 @@ void PlaylistItem::setup(CollectionListItem *item, Playlist *parent)
if(item) {
m_data = item->getData()->newUser();
item->addChildItem(this);
refreshImpl();
connect(this, SIGNAL(refreshed()), parent, SIGNAL(dataChanged()));
slotRefreshImpl();
connect(this, SIGNAL(signalRefreshed()), parent, SIGNAL(signalDataChanged()));
}
setDragEnabled(true);
......
......@@ -65,13 +65,13 @@ public slots:
* based on the same file, so if another one of those items changes its m_data
* it is important to refresh the others.
*/
virtual void refresh();
virtual void slotRefresh();
/**
* This rereads the tag from disk. This affects all PlaylistItems based on
* the same file.
*/
virtual void refreshFromDisk();
virtual void slotRefreshFromDisk();
protected:
/**
......@@ -87,10 +87,10 @@ protected:
void setData(Data *d);
protected slots:
void refreshImpl();
void slotRefreshImpl();
signals:
void refreshed();
void signalRefreshed();
private:
void setup(CollectionListItem *item, Playlist *parent);
......@@ -101,7 +101,7 @@ private:
};
/**
* This is the m_data class for PlaylistItems. Several PlaylistItems that are
* This is the data class for PlaylistItems. Several PlaylistItems that are
* based on the same file will share the m_data member. This has both the
* advantages of being memory efficient and allowing the PlaylistItems to stay
* synchronized.
......
......@@ -50,7 +50,7 @@ void processEvents()
////////////////////////////////////////////////////////////////////////////////
PlaylistSplitter::PlaylistSplitter(QWidget *parent, bool restore, const char *name) : QSplitter(Qt::Horizontal, parent, name),
m_playingItem(0), m_restore(restore)
m_playingItem(0), m_restore(restore)
{
if(!m_mediaExtensions && !m_listExtensions) {
m_mediaExtensions = new QStringList();
......@@ -217,7 +217,7 @@ void PlaylistSplitter::addToPlaylist(const QString &file, Playlist *list)
KApplication::restoreOverrideCursor();
if(m_editor)
m_editor->updateCollection();
m_editor->slotUpdateCollection();
}
void PlaylistSplitter::addToPlaylist(const QStringList &files, Playlist *list)
......@@ -228,7 +228,7 @@ void PlaylistSplitter::addToPlaylist(const QStringList &files, Playlist *list)
KApplication::restoreOverrideCursor();
if(m_editor)
m_editor->updateCollection();
m_editor->slotUpdateCollection();
}
QString PlaylistSplitter::extensionsString(const QStringList &extensions, const QString &type) // static
......@@ -349,11 +349,9 @@ void PlaylistSplitter::slotSelectPlaying()
void PlaylistSplitter::slotDeleteSelectedItems()
{
PlaylistItemList items = playlistSelection();
Playlist *p = visiblePlaylist();
if(p)
p->remove(items);
p->slotDeleteSelectedItems();
}
void PlaylistSplitter::slotToggleColumnVisible(int column)
......@@ -532,11 +530,11 @@ void PlaylistSplitter::addImpl(const QString &file, Playlist *list)
void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon)
{
connect(p, SIGNAL(selectionChanged(const PlaylistItemList &)), m_editor, SLOT(setItems(const PlaylistItemList &)));
connect(p, SIGNAL(doubleClicked()), this, SIGNAL(signalDoubleClicked()));
connect(p, SIGNAL(collectionChanged()), m_editor, SLOT(updateCollection()));
connect(p, SIGNAL(numberOfItemsChanged(Playlist *)), this, SLOT(slotPlaylistCountChanged(Playlist *)));
connect(p, SIGNAL(aboutToRemove(PlaylistItem *)), this, SLOT(slotPlaylistItemRemoved(PlaylistItem *)));
connect(p, SIGNAL(signalSelectionChanged(const PlaylistItemList &)), m_editor, SLOT(slotSetItems(const PlaylistItemList &)));
connect(p, SIGNAL(signalDoubleClicked()), this, SIGNAL(signalDoubleClicked()));
connect(p, SIGNAL(signalCollectionChanged()), m_editor, SLOT(slotUpdateCollection()));
connect(p, SIGNAL(signalNumberOfItemsChanged(Playlist *)), this, SLOT(slotPlaylistCountChanged(Playlist *)));
connect(p, SIGNAL(signalAboutToRemove(PlaylistItem *)), this, SLOT(slotPlaylistItemRemoved(PlaylistItem *)));
connect(p, SIGNAL(signalToggleColumnVisible(int)), this, SLOT(slotToggleColumnVisible(int)));
......@@ -582,7 +580,7 @@ void PlaylistSplitter::slotChangePlaylist(Playlist *p)
return;
m_playlistStack->raiseWidget(p);
m_editor->setItems(playlistSelection());
m_editor->slotSetItems(playlistSelection());
setupColumns(p);
emit signalPlaylistChanged();
}
......
......@@ -60,15 +60,15 @@ void TagEditor::setGenreList(const GenreList &list)
// public slots
////////////////////////////////////////////////////////////////////////////////
void TagEditor::setItems(const PlaylistItemList &list)
void TagEditor::slotSetItems(const PlaylistItemList &list)
{
saveChangesPrompt();
m_items = list;
if(isVisible())
refresh();
slotRefresh();
}
void TagEditor::refresh()
void TagEditor::slotRefresh()
{
// This method takes the list of currently selected m_items and tries to
// figure out how to show that in the tag editor. The current strategy --
......@@ -189,10 +189,10 @@ void TagEditor::refresh()
m_dataChanged = false;
}
else
clear();
slotClear();
}
void TagEditor::clear()
void TagEditor::slotClear()
{
m_artistNameBox->lineEdit()->clear();
m_trackNameBox->clear();
......@@ -206,12 +206,7 @@ void TagEditor::clear()
m_commentBox->clear();
}
void TagEditor::save()
{
save(m_items);
}
void TagEditor::updateCollection()
void TagEditor::slotUpdateCollection()
{
CollectionList *list = CollectionList::instance();
......@@ -452,7 +447,7 @@ void TagEditor::save(const PlaylistItemList &list)
item->tag()->save();
item->refresh();
item->slotRefresh();
}
else
errorFiles.append(item->fileName());
......@@ -527,7 +522,7 @@ void TagEditor::addItem(const QString &text, QWidget *item, QBoxLayout *layout)
void TagEditor::showEvent(QShowEvent *e)
{
refresh();
slotRefresh();
QWidget::showEvent(e);
}
......
......@@ -40,17 +40,14 @@ public:
TagEditor(QWidget *parent = 0, const char *name = 0);
virtual ~TagEditor();
void setGenreList(const GenreList &list);
void save() { save(m_items); }
public slots:
void setItems(const PlaylistItemList &list);
void refresh();
void clear();
void save();
void updateCollection();
void slotSetItems(const PlaylistItemList &list);
void slotRefresh();
void slotClear();
void slotUpdateCollection();
signals:
// void signalChanged();
private:
void setupLayout();
void readConfig();
......
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