Commit f946c053 authored by Scott Wheeler's avatar Scott Wheeler

*) Clean up the PlaylistBox API removing signals, slots and methods that aren't

   used.
*) Add a method to the PlaylistCollection to prompt the user for a playlist name.
   This was duplicated in a few places.
*) Fix PlaylistCollection::uniquePlaylistName() so that it increments the "copy
   number" properly.
*) Implement PlaylistBox::remove()

svn path=/trunk/kdemultimedia/juk/; revision=317434
parent 27deb223
...@@ -471,6 +471,9 @@ void Playlist::playPrevious() ...@@ -471,6 +471,9 @@ void Playlist::playPrevious()
void Playlist::setName(const QString &n) void Playlist::setName(const QString &n)
{ {
m_collection->addName(n);
m_collection->removeName(m_playlistName);
m_playlistName = n; m_playlistName = n;
emit signalNameChanged(m_playlistName); emit signalNameChanged(m_playlistName);
} }
......
...@@ -114,7 +114,7 @@ PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack, ...@@ -114,7 +114,7 @@ PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack,
this, SLOT(slotPlaylistChanged())); this, SLOT(slotPlaylistChanged()));
connect(this, SIGNAL(doubleClicked(QListViewItem *)), connect(this, SIGNAL(doubleClicked(QListViewItem *)),
this, SLOT(slotDoubleClicked(QListViewItem *))); this, SLOT(slotDoubleClicked()));
connect(this, SIGNAL(contextMenuRequested(QListViewItem *, const QPoint &, int)), connect(this, SIGNAL(contextMenuRequested(QListViewItem *, const QPoint &, int)),
this, SLOT(slotShowContextMenu(QListViewItem *, const QPoint &, int))); this, SLOT(slotShowContextMenu(QListViewItem *, const QPoint &, int)));
...@@ -126,13 +126,16 @@ PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack, ...@@ -126,13 +126,16 @@ PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack,
PlaylistBox::~PlaylistBox() PlaylistBox::~PlaylistBox()
{ {
Cache::savePlaylists(playlists()); PlaylistList l;
saveConfig(); CollectionList *collection = CollectionList::instance();
} for(QListViewItemIterator it(this); it.current(); ++it) {
Item *i = static_cast<Item *>(it.current());
if(i->playlist() && i->playlist() != collection)
l.append(i->playlist());
}
void PlaylistBox::createSearchItem(SearchPlaylist *playlist, const QString &searchCategory) Cache::savePlaylists(l);
{ saveConfig();
m_viewModes[m_viewModeIndex]->createSearchItem(this, playlist, searchCategory);
} }
void PlaylistBox::raise(Playlist *playlist) void PlaylistBox::raise(Playlist *playlist)
...@@ -146,26 +149,22 @@ void PlaylistBox::raise(Playlist *playlist) ...@@ -146,26 +149,22 @@ void PlaylistBox::raise(Playlist *playlist)
setSelected(i, true); setSelected(i, true);
setSingleItem(i); setSingleItem(i);
ensureCurrentVisible(); ensureItemVisible(currentItem());
} }
PlaylistList PlaylistBox::playlists() void PlaylistBox::duplicate()
{ {
PlaylistList l; Item *item = static_cast<Item *>(currentItem());
if(!item || !item->playlist())
CollectionList *collection = CollectionList::instance(); return;
Item *i = static_cast<Item *>(firstChild()); QString name = playlistNameDialog(i18n("Duplicate"), item->text(0));
for(; i; i = static_cast<Item *>(i->nextSibling()))
if(i->playlist() && i->playlist() != collection)
l.append(i->playlist());
return l; if(name.isNull())
} return;
void PlaylistBox::duplicate() Playlist *p = new Playlist(this, name);
{ p->createItems(item->playlist()->items());
duplicate(static_cast<Item *>(currentItem()));
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -221,39 +220,10 @@ void PlaylistBox::saveConfig() ...@@ -221,39 +220,10 @@ void PlaylistBox::saveConfig()
} }
} }
void PlaylistBox::duplicate(Item *item) void PlaylistBox::remove()
{
if(item && item->playlist()) {
bool ok;
// If this text is changed, please also change it in PlaylistSplitter::createPlaylist().
QString name = KInputDialog::getText(i18n("New Playlist"),
i18n("Please enter a name for the new playlist:"),
uniquePlaylistName(item->text(0)), &ok);
if(ok) {
Playlist *p = new Playlist(this, name);
p->createItems(item->playlist()->items());
}
}
}
void PlaylistBox::deleteItem(Playlist *playlist)
{ {
Item *i = m_playlistDict.find(playlist); ItemList items = selectedItems();
if(!i)
return;
ItemList l;
l.append(i);
deleteItems(l, false);
}
void PlaylistBox::deleteItems(const ItemList &items, bool confirm)
{
if(items.isEmpty()) if(items.isEmpty())
return; return;
...@@ -264,31 +234,29 @@ void PlaylistBox::deleteItems(const ItemList &items, bool confirm) ...@@ -264,31 +234,29 @@ void PlaylistBox::deleteItems(const ItemList &items, bool confirm)
files.append((*it)->playlist()->fileName()); files.append((*it)->playlist()->fileName());
} }
if(confirm) { if(!files.isEmpty()) {
if(!files.isEmpty()) { int remove = KMessageBox::warningYesNoCancelList(
int remove = KMessageBox::warningYesNoCancelList( this, i18n("Do you want to delete these files from the disk as well?"), files);
this, i18n("Do you want to delete these files from the disk as well?"), files);
if(remove == KMessageBox::Yes) { if(remove == KMessageBox::Yes) {
QStringList couldNotDelete; QStringList couldNotDelete;
for(QStringList::ConstIterator it = files.begin(); it != files.end(); ++it) { for(QStringList::ConstIterator it = files.begin(); it != files.end(); ++it) {
if(!QFile::remove(*it)) if(!QFile::remove(*it))
couldNotDelete.append(*it); couldNotDelete.append(*it);
} }
// Would be nice if there were a KMessageBox::sorryList() to use with // Would be nice if there were a KMessageBox::sorryList() to use with
// couldNotDelete. // couldNotDelete.
if(!couldNotDelete.isEmpty()) if(!couldNotDelete.isEmpty())
KMessageBox::sorry(this, i18n("Could not delete all of the specified files.")); KMessageBox::sorry(this, i18n("Could not delete all of the specified files."));
}
else if(remove == KMessageBox::Cancel)
return;
}
else {
if(KMessageBox::warningYesNo(this, i18n("Are you sure you want to remove these items?")) == KMessageBox::No)
return;
} }
else if(remove == KMessageBox::Cancel)
return;
}
else {
if(KMessageBox::warningYesNo(this, i18n("Are you sure you want to remove these items?")) == KMessageBox::No)
return;
} }
QValueList< QPair<Item *, Playlist *> > removeQueue; QValueList< QPair<Item *, Playlist *> > removeQueue;
...@@ -296,7 +264,7 @@ void PlaylistBox::deleteItems(const ItemList &items, bool confirm) ...@@ -296,7 +264,7 @@ void PlaylistBox::deleteItems(const ItemList &items, bool confirm)
for(ItemList::ConstIterator it = items.begin(); it != items.end(); ++it) { for(ItemList::ConstIterator it = items.begin(); it != items.end(); ++it) {
if(*it != Item::collectionItem() && if(*it != Item::collectionItem() &&
(*it)->playlist() && (*it)->playlist() &&
(!confirm || !(*it)->playlist()->readOnly())) (!(*it)->playlist()->readOnly()))
{ {
m_names.remove((*it)->text(0)); m_names.remove((*it)->text(0));
m_playlistDict.remove((*it)->playlist()); m_playlistDict.remove((*it)->playlist());
...@@ -338,9 +306,14 @@ void PlaylistBox::decode(QMimeSource *s, Item *item) ...@@ -338,9 +306,14 @@ void PlaylistBox::decode(QMimeSource *s, Item *item)
files.append((*it).path()); files.append((*it).path());
if(item && item->playlist()) if(item && item->playlist())
item->playlist()->addFiles(files, importPlaylists()); item->playlist()->addFiles(files, true);
else else {
emit signalCreatePlaylist(files); QString name = playlistNameDialog();
if(!name.isNull()) {
Playlist *p = new Playlist(this, name);
p->addFiles(files, true);
}
}
} }
} }
...@@ -463,10 +436,8 @@ PlaylistBox::ItemList PlaylistBox::selectedItems() ...@@ -463,10 +436,8 @@ PlaylistBox::ItemList PlaylistBox::selectedItems()
{ {
ItemList l; ItemList l;
for(QListViewItemIterator it(this); it.current(); ++it) { for(QListViewItemIterator it(this, QListViewItemIterator::Selected); it.current(); ++it)
if(isSelected(*it)) l.append(static_cast<Item *>(*it));
l.append(static_cast<Item *>(*it));
}
return l; return l;
} }
...@@ -539,7 +510,7 @@ void PlaylistBox::slotPlaylistChanged() ...@@ -539,7 +510,7 @@ void PlaylistBox::slotPlaylistChanged()
playlistStack()->raiseWidget(playlists.front()); playlistStack()->raiseWidget(playlists.front());
} }
void PlaylistBox::slotDoubleClicked(QListViewItem *) void PlaylistBox::slotDoubleClicked()
{ {
action("stop")->activate(); action("stop")->activate();
action("play")->activate(); action("play")->activate();
...@@ -629,7 +600,7 @@ void PlaylistBox::Item::slotSetName(const QString &name) ...@@ -629,7 +600,7 @@ void PlaylistBox::Item::slotSetName(const QString &name)
setSelected(true); setSelected(true);
listView()->sort(); listView()->sort();
listView()->ensureCurrentVisible(); listView()->ensureItemVisible(listView()->currentItem());
} }
} }
......
...@@ -46,66 +46,36 @@ class PlaylistBox : public KListView, public PlaylistCollection ...@@ -46,66 +46,36 @@ class PlaylistBox : public KListView, public PlaylistCollection
Q_OBJECT Q_OBJECT
public: public:
class Item;
friend class Item;
typedef QValueList<Item *> ItemList;
PlaylistBox(QWidget *parent, QWidgetStack *playlistStack, PlaylistBox(QWidget *parent, QWidgetStack *playlistStack,
const QString &name = QString::null); const QString &name = QString::null);
virtual ~PlaylistBox(); virtual ~PlaylistBox();
void createSearchItem(SearchPlaylist *playlist, const QString &searchCategory); virtual void raise(Playlist *playlist);
virtual void duplicate();
void raise(Playlist *playlist); virtual void remove();
QStringList names() const { return m_names; }
/**
* A list of all of the playlists in the PlaylistBox, not counting dynamic
* playlists.
*/
PlaylistList playlists();
void duplicate();
/**
* Delete the item associated with \a playlist.
*/
void deleteItem(Playlist *playlist);
void deleteItems() { deleteItems(selectedItems()); }
bool hasSelection() const { return m_hasSelection; }
ViewMode *viewMode() { return m_viewModes[m_viewModeIndex]; }
int viewModeIndex() const { return m_viewModeIndex; }
void ensureCurrentVisible() { ensureItemVisible(currentItem()); }
class Item;
friend class Item;
typedef QValueList<Item *> ItemList;
Item *dropItem() const { return m_dropItem; } Item *dropItem() const { return m_dropItem; }
public slots: public slots:
void paste(); void paste();
void clear() {} // override the (destructive) default void clear() {}
virtual Playlist *currentPlaylist() const; virtual Playlist *currentPlaylist() const;
protected: protected:
// virtual Playlist *currentPlaylist() const;
virtual void setupPlaylist(Playlist *playlist, const QString &iconName); virtual void setupPlaylist(Playlist *playlist, const QString &iconName);
signals: signals:
void signalDoubleClicked();
void signalCreatePlaylist(const QStringList &files);
void signalCreateSearchList(const PlaylistSearch &search,
const QString &searchCategory,
const QString &name);
void signalCollectionInitialized(); void signalCollectionInitialized();
private: private:
void readConfig(); void readConfig();
void saveConfig(); void saveConfig();
void duplicate(Item *item);
void deleteItems(const QValueList<Item *> &items, bool confirm = true);
virtual void decode(QMimeSource *s, Item *item); virtual void decode(QMimeSource *s, Item *item);
virtual void contentsDropEvent(QDropEvent *e); virtual void contentsDropEvent(QDropEvent *e);
virtual void contentsDragMoveEvent(QDragMoveEvent *e); virtual void contentsDragMoveEvent(QDragMoveEvent *e);
...@@ -115,16 +85,13 @@ private: ...@@ -115,16 +85,13 @@ private:
virtual void keyPressEvent(QKeyEvent *e); virtual void keyPressEvent(QKeyEvent *e);
virtual void keyReleaseEvent(QKeyEvent *e); virtual void keyReleaseEvent(QKeyEvent *e);
/**
* This is used by PlaylistItemBox (a friend class) to add names to the name
* list returned by names().
*/
void addName(const QString &name) { m_names.append(name); }
QValueList<Item *> selectedItems(); QValueList<Item *> selectedItems();
void setSingleItem(QListViewItem *item); void setSingleItem(QListViewItem *item);
void addName(const QString &name) { m_names.append(name); }
void setupItem(Item *item); void setupItem(Item *item);
int viewModeIndex() const { return m_viewModeIndex; }
ViewMode *viewMode() const { return m_viewModes[m_viewModeIndex]; }
private slots: private slots:
/** /**
...@@ -132,7 +99,7 @@ private slots: ...@@ -132,7 +99,7 @@ private slots:
* the signal as currentChanged(Item *). * the signal as currentChanged(Item *).
*/ */
void slotPlaylistChanged(); void slotPlaylistChanged();
void slotDoubleClicked(QListViewItem *); void slotDoubleClicked();
void slotShowContextMenu(QListViewItem *, const QPoint &point, int); void slotShowContextMenu(QListViewItem *, const QPoint &point, int);
void slotSetViewMode(int index); void slotSetViewMode(int index);
......
...@@ -164,13 +164,9 @@ void PlaylistCollection::addFolder() ...@@ -164,13 +164,9 @@ void PlaylistCollection::addFolder()
void PlaylistCollection::rename() void PlaylistCollection::rename()
{ {
bool ok; QString name = playlistNameDialog(i18n("Rename"), currentPlaylist()->name());
QString name = KInputDialog::getText(
i18n("Rename"),
i18n("Please enter a name for this playlist:"), currentPlaylist()->name(), &ok);
if(!ok) if(name.isNull())
return; return;
currentPlaylist()->setName(name); currentPlaylist()->setName(name);
...@@ -181,17 +177,9 @@ void PlaylistCollection::rename() ...@@ -181,17 +177,9 @@ void PlaylistCollection::rename()
void PlaylistCollection::duplicate() void PlaylistCollection::duplicate()
{ {
bool ok; QString name = playlistNameDialog(i18n("Duplicate"), currentPlaylist()->name());
if(name.isNull())
QString name = KInputDialog::getText(
i18n("Duplicate"),
i18n("Please enter a name for this playlist:"),
uniquePlaylistName(currentPlaylist()->name()),
&ok);
if(!ok)
return; return;
raise(new Playlist(this, currentPlaylist()->items(), name)); raise(new Playlist(this, currentPlaylist()->items(), name));
} }
...@@ -262,14 +250,8 @@ void PlaylistCollection::scanFolders() ...@@ -262,14 +250,8 @@ void PlaylistCollection::scanFolders()
void PlaylistCollection::createPlaylist() void PlaylistCollection::createPlaylist()
{ {
bool ok; QString name = playlistNameDialog();
if(!name.isNull())
QString name = KInputDialog::getText(
i18n("Create New Playlist"),
i18n("Please enter a name for the new playlist:"),
uniquePlaylistName(), &ok);
if(ok)
raise(new Playlist(this, name)); raise(new Playlist(this, name));
} }
...@@ -292,14 +274,9 @@ void PlaylistCollection::createFolderPlaylist() ...@@ -292,14 +274,9 @@ void PlaylistCollection::createFolderPlaylist()
return; return;
QString name = uniquePlaylistName(folder.mid(folder.findRev('/') + 1)); QString name = uniquePlaylistName(folder.mid(folder.findRev('/') + 1));
name = playlistNameDialog(i18n("Create Folder Playlist"), name);
bool ok; if(!name.isNull())
name = KInputDialog::getText(
i18n("Create New Playlist"),
i18n("Please enter a name for the new playlist:"),
name, &ok);
if(ok)
raise(new FolderPlaylist(this, folder, name)); raise(new FolderPlaylist(this, folder, name));
} }
...@@ -359,11 +336,11 @@ void PlaylistCollection::setupPlaylist(Playlist *playlist, const QString &) ...@@ -359,11 +336,11 @@ void PlaylistCollection::setupPlaylist(Playlist *playlist, const QString &)
playlist->deleteLater(); playlist->deleteLater();
} }
if(!playlist->name().isNull())
m_playlistNames.insert(playlist->name());
QObject::connect(playlist, SIGNAL(selectionChanged()), QObject::connect(playlist, SIGNAL(selectionChanged()),
object(), SIGNAL(signalSelectedItemsChanged())); object(), SIGNAL(signalSelectedItemsChanged()));
// connect(p, SIGNAL(signalFilesDropped(const QStringList &, Playlist *, PlaylistItem *)),
// this, SLOT(slotAddToPlaylist(const QStringList &, Playlist *, PlaylistItem *)));
} }
bool PlaylistCollection::importPlaylists() const bool PlaylistCollection::importPlaylists() const
...@@ -371,17 +348,49 @@ bool PlaylistCollection::importPlaylists() const ...@@ -371,17 +348,49 @@ bool PlaylistCollection::importPlaylists() const
return m_importPlaylists; return m_importPlaylists;
} }
QString PlaylistCollection::uniquePlaylistName(const QString &suggest) QString PlaylistCollection::playlistNameDialog(const QString &caption,
const QString &suggest) const
{
bool ok;
QString name = KInputDialog::getText(
caption,
i18n("Please enter a name for this playlist:"), uniquePlaylistName(suggest), &ok);
return ok ? uniquePlaylistName(name) : QString::null;
}
QString PlaylistCollection::uniquePlaylistName(const QString &suggest) const
{ {
if(!m_playlistNames.contains(suggest))
return suggest;
QString base = suggest;
base.remove(QRegExp("\\s\\([0-9]+\\)$"));
int count = 1; int count = 1;
QString s = suggest + " (%1)"; QString s = QString("%1 (%2)").arg(base).arg(count);
while(m_playlistNames.find(s.arg(count)) != m_playlistNames.end()) while(m_playlistNames.contains(s)) {
count++; count++;
s = QString("%1 (%2)").arg(base).arg(count);
}
return s;
}
void PlaylistCollection::addName(const QString &name)
{
m_playlistNames.insert(name);
}
return s.arg(count); void PlaylistCollection::removeName(const QString &name)
{
m_playlistNames.remove(name);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// private methods // private methods
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
......
...@@ -55,15 +55,15 @@ public: ...@@ -55,15 +55,15 @@ public:
// Play the top item of the current playlist // Play the top item of the current playlist
void playFirst(); void playFirst();
void open(const QStringList &files = QStringList()); virtual void open(const QStringList &files = QStringList());
void addFolder(); virtual void addFolder();
void rename(); virtual void rename();
void duplicate(); virtual void duplicate();
void save(); virtual void save();
void saveAs(); virtual void saveAs();
void remove(); virtual void remove();
void reload(); virtual void reload();
void editSearch(); virtual void editSearch();
void removeItems(); void removeItems();
void refreshItems(); void refreshItems();
...@@ -94,7 +94,12 @@ protected: ...@@ -94,7 +94,12 @@ protected:
bool importPlaylists() const; bool importPlaylists() const;
QString uniquePlaylistName(const QString &suggest = i18n("Playlist")); QString playlistNameDialog(const QString &caption = i18n("Create New Playlist"),
const QString &suggest = QString::null) const;
QString uniquePlaylistName(const QString &suggest = i18n("Playlist")) const;
void addName(const QString &name);
void removeName(const QString &name);
private: private:
void readConfig(); void readConfig();
...@@ -104,7 +109,7 @@ private: ...@@ -104,7 +109,7 @@ private:
ActionHandler *m_actionHandler; ActionHandler *m_actionHandler;
KDirWatch m_dirWatch; KDirWatch m_dirWatch;
QStringList m_playlistNames; StringHash m_playlistNames;
StringHash m_playlistFiles; StringHash m_playlistFiles;
QStringList m_folderList; QStringList m_folderList;
bool m_importPlaylists; bool m_importPlaylists;
......
...@@ -35,9 +35,6 @@ ViewMode::ViewMode(PlaylistBox *b) : QObject(b), ...@@ -35,9 +35,6 @@ ViewMode::ViewMode(PlaylistBox *b) : QObject(b),
m_visible(false), m_visible(false),
m_needsRefresh(false) m_needsRefresh(false)
{ {
connect(this, SIGNAL(signalCreateSearchList(const PlaylistSearch &, const QString &, const QString &)),
b, SIGNAL(signalCreateSearchList(const PlaylistSearch &, const QString &, const QString &)));
m_playlistBox->viewport()->installEventFilter(this); m_playlistBox->viewport()->installEventFilter(this);
} }
...@@ -261,7 +258,6 @@ TreeViewMode::~TreeViewMode() ...@@ -261,7 +258,6 @@ TreeViewMode::~TreeViewMode()
void TreeViewMode::setShown(bool show) void TreeViewMode::setShown(bool show)
{ {
kdDebug(65432) << k_funcinfo << endl;
CompactViewMode::setShown(show); CompactViewMode::setShown(show);
playlistBox()->setRootIsDecorated(show); playlistBox()->setRootIsDecorated(show);
......
...@@ -62,11 +62,6 @@ protected: ...@@ -62,11 +62,6 @@ protected:
virtual void updateHeights(); virtual void updateHeights();
static void paintDropIndicator(QPainter *painter, int width, int height); static void paintDropIndicator(QPainter *painter, int width, int height);
signals:
void signalCreateSearchList(const PlaylistSearch &search,
const QString &searchCategory,
const QString &name);
private: private:
QStringList lines(const PlaylistBox::Item *item, const QFontMetrics &fm, int width) const; QStringList lines(const PlaylistBox::Item *item, const QFontMetrics &fm, int width) const;
......
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