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