Commit 1bbec389 authored by Scott Wheeler's avatar Scott Wheeler

*) Applied Daniel's patch for hiding and showing columns

*) Reworked that API a bit to allow for saving and restoration of those
   settings and
*) Made the settings apply to all playlists
*) Also fixed prompt the user and ask him if he really wants to remove
   playlists
*) Also, resort after renaming a playlist
*) Added Edit RMB menus to the playlists

svn path=/trunk/kdemultimedia/juk/; revision=207409
parent c45f60b6
......@@ -103,7 +103,7 @@ void JuK::setupActions()
savePlaylistAction = KStdAction::save(splitter, SLOT(savePlaylist()), actionCollection());
saveAsPlaylistAction = KStdAction::saveAs(splitter, SLOT(saveAsPlaylist()), actionCollection());
deleteItemPlaylistAction = new KAction(i18n("Delete"), "editdelete", 0, splitter, SLOT(deleteItemPlaylist()),
deleteItemPlaylistAction = new KAction(i18n("Remove"), "edittrash", 0, splitter, SLOT(deleteItemPlaylist()),
actionCollection(), "deleteItemPlaylist");
KStdAction::quit(this, SLOT(close()), actionCollection());
......
......@@ -31,6 +31,8 @@
#include <qtimer.h>
#include <qapplication.h>
#include <qptrlist.h>
#include <qheader.h>
#include <qcursor.h>
#include <qclipboard.h>
#include <stdlib.h>
......@@ -270,6 +272,10 @@ void Playlist::setName(const QString &n)
emit(nameChanged(playlistName));
}
////////////////////////////////////////////////////////////////////////////////
// public slots
////////////////////////////////////////////////////////////////////////////////
void Playlist::copy()
{
kapp->clipboard()->setData(dragObject(0), QClipboard::Clipboard);
......@@ -285,6 +291,17 @@ void Playlist::clear()
clearItems(selectedItems());
}
void Playlist::slotToggleColumnVisible(int column, bool emitSignal)
{
if(isColumnVisible(column))
hideColumn(column);
else
showColumn(column);
if(emitSignal)
emit signalToggleColumnVisible(column);
}
////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////
......@@ -310,6 +327,12 @@ QDragObject *Playlist::dragObject()
return dragObject(this);
}
bool Playlist::canDecode(QMimeSource *s)
{
KURL::List urls;
return KURLDrag::decode(s, urls) && !urls.isEmpty();
}
void Playlist::decode(QMimeSource *s)
{
KURL::List urls;
......@@ -326,6 +349,24 @@ void Playlist::decode(QMimeSource *s)
splitter->add(fileList, this);
}
bool Playlist::eventFilter(QObject* watched, QEvent* e)
{
if(watched->inherits("QHeader")) { // Gotcha!
if(e->type() == QEvent::MouseButtonPress) {
QMouseEvent *me = static_cast<QMouseEvent*>(e);
if(me->button() == Qt::RightButton) {
headerMenu->popup(QCursor::pos());
return true;
}
}
}
return KListView::eventFilter(watched, e);
}
void Playlist::contentsDropEvent(QDropEvent *e)
{
QListViewItem *moveAfter = itemAt(e->pos());
......@@ -378,6 +419,39 @@ PlaylistItem *Playlist::createItem(const QFileInfo &file, QListViewItem *after)
return 0;
}
void Playlist::hideColumn(int c)
{
headerMenu->setItemChecked(c, false);
setColumnWidthMode(c, Manual);
setColumnWidth(c, 0);
setResizeMode(QListView::LastColumn);
triggerUpdate();
}
void Playlist::showColumn(int c)
{
headerMenu->setItemChecked(c, true);
setColumnWidthMode(c, Maximum);
int w = 0;
QListViewItemIterator it(this);
for (; it.current(); ++it )
w = QMAX(it.current()->width(fontMetrics(), this, c), w);
setColumnWidth(c, w);
triggerUpdate();
}
bool Playlist::isColumnVisible(int c) const
{
if(columnWidth(c) != 0)
return true;
else
return false;
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
......@@ -410,21 +484,56 @@ void Playlist::setup()
setSorting(1);
installEventFilter(header());
//////////////////////////////////////////////////
// setup header RMB menu
//////////////////////////////////////////////////
headerMenu = new KPopupMenu(this);
headerMenu->insertTitle(i18n("Show Columns"));
headerMenu->setCheckable(true);
for(int i =0; i < header()->count(); ++i) {
headerMenu->insertItem(header()->label(i), i);
headerMenu->setItemChecked(i, true);
}
connect(headerMenu, SIGNAL(activated(int)), this, SLOT(slotToggleColumnVisible(int)));
//////////////////////////////////////////////////
// setup playlist RMB menu
//////////////////////////////////////////////////
rmbMenu = new KPopupMenu(this);
rmbMenu->insertItem(SmallIcon("editcut"), i18n("Cut"), this, SLOT(cut()));
rmbMenu->insertItem(SmallIcon("editcopy"), i18n("Copy"), this, SLOT(copy()));
rmbPasteID = rmbMenu->insertItem(SmallIcon("editpaste"), i18n("Paste"), this, SLOT(paste()));
rmbMenu->insertItem(SmallIcon("editclear"), i18n("Clear"), this, SLOT(clear()));
rmbMenu->insertSeparator();
rmbMenu = new QPopupMenu(this);
rmbEditID = rmbMenu->insertItem(SmallIcon("edittool"), i18n("Edit"), this, SLOT(renameTag()));
rmbMenu->insertItem(SmallIcon("editdelete"), i18n("Remove from disk"), this, SLOT(removeSelectedItems()));
rmbMenu->insertSeparator();
rmbEditID = rmbMenu->insertItem(SmallIcon("edittool"), i18n("Edit"), this, SLOT(renameTag()));
connect(this, SIGNAL(selectionChanged()), this, SLOT(emitSelected()));
connect(this, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(emitDoubleClicked(QListViewItem *)));
connect(this, SIGNAL(contextMenuRequested( QListViewItem *, const QPoint&, int)),
this, SLOT(showRMBMenu(QListViewItem *, const QPoint &, int)));
connect(this, SIGNAL(itemRenamed(QListViewItem *, const QString &, int)),
this, SLOT(applyTags(QListViewItem *, const QString &, int)));
//////////////////////////////////////////////////
addColumn(QString::null);
setResizeMode(QListView::LastColumn);
// setFullWidth(true);
setAcceptDrops(true);
allowDuplicates = false;
......@@ -439,6 +548,8 @@ void Playlist::showRMBMenu(QListViewItem *item, const QPoint &point, int column)
if(!item)
return;
rmbMenu->setItemEnabled(rmbPasteID, canDecode(kapp->clipboard()->data()));
bool showEdit =
(column == PlaylistItem::TrackColumn) ||
(column == PlaylistItem::ArtistColumn) ||
......@@ -447,7 +558,7 @@ void Playlist::showRMBMenu(QListViewItem *item, const QPoint &point, int column)
(column == PlaylistItem::GenreColumn) ||
(column == PlaylistItem::YearColumn);
rmbMenu->setItemVisible(rmbEditID, showEdit);
rmbMenu->setItemEnabled(rmbEditID, showEdit);
rmbMenu->popup(point);
currentColumn = column;
......@@ -525,7 +636,6 @@ void Playlist::applyTags(QListViewItem *item, const QString &text, int column)
i->refresh();
}
QDataStream &operator<<(QDataStream &s, const Playlist &p)
{
s << p.name();
......@@ -560,5 +670,4 @@ QDataStream &operator>>(QDataStream &s, Playlist &p)
return s;
}
#include "playlist.moc"
......@@ -28,7 +28,11 @@
class PlaylistSplitter;
class PlaylistBoxItem;
class QPopupMenu;
class KPopupMenu;
class KPopupMenu;
class QEvent;
class Playlist : public KListView
{
......@@ -96,6 +100,10 @@ public:
QString fileName() const { return playlistFileName; }
void setFileName(const QString &n) { playlistFileName = n; }
void hideColumn(int c);
void showColumn(int c);
bool isColumnVisible(int c) const;
/**
* If playlistName has no value -- i.e. the name has not been set to
* something other than the filename, this returns the filename less the
......@@ -121,20 +129,22 @@ public:
PlaylistItem *previousItem(PlaylistItem *current, bool random = false);
public slots:
/**
/**
* Remove the currently selected items from the playlist and disk.
*/
void removeSelectedItems() { remove(selectedItems()); };
virtual void copy();
virtual void clear();
virtual void cut() { copy(); clear(); }
virtual void copy();
virtual void paste();
virtual void clear();
virtual void selectAll() { KListView::selectAll(true); }
protected:
virtual bool eventFilter(QObject* watched, QEvent* e);
virtual QDragObject *dragObject(QWidget *parent);
virtual QDragObject *dragObject();
virtual bool canDecode(QMimeSource *s);
virtual void decode(QMimeSource *s);
virtual void contentsDropEvent(QDropEvent *e);
virtual void contentsDragMoveEvent(QDragMoveEvent *e);
......@@ -175,6 +185,8 @@ signals:
*/
void aboutToRemove(PlaylistItem *item);
void signalToggleColumnVisible(int column);
private:
void setup();
QPtrStack<PlaylistItem> history;
......@@ -185,11 +197,10 @@ private slots:
void showRMBMenu(QListViewItem *item, const QPoint &point, int column);
void applyTags(QListViewItem *item, const QString &text, int column);
void renameTag();
void slotToggleColumnVisible(int column, bool emitSignal = true);
private:
QPopupMenu *rmbMenu;
int currentColumn;
SortedStringList members;
int processed;
bool allowDuplicates;
......@@ -203,7 +214,11 @@ private:
QString playlistName;
PlaylistSplitter *splitter;
PlaylistBoxItem *boxItem;
KPopupMenu *rmbMenu;
KPopupMenu *headerMenu;
int rmbPasteID;
int rmbEditID;
};
......
......@@ -49,7 +49,7 @@ PlaylistBox::PlaylistBox(PlaylistSplitter *parent, const char *name) : KListBox(
playlistContextMenu->insertItem(SmallIcon("filesaveas"), i18n("Save As..."), this, SLOT(contextSaveAs()));
playlistContextMenu->insertItem(i18n("Rename..."), this, SLOT(contextRename()));
playlistContextMenu->insertItem(SmallIcon("editcopy"), i18n("Duplicate..."), this, SLOT(contextDuplicate()));
playlistContextMenu->insertItem(SmallIcon("editdelete"), i18n("Delete"), this, SLOT(contextDeleteItem()));
playlistContextMenu->insertItem(SmallIcon("edittrash"), i18n("Remove"), this, SLOT(contextDeleteItem()));
setAcceptDrops(true);
......@@ -124,20 +124,25 @@ void PlaylistBox::rename()
void PlaylistBox::rename(PlaylistBoxItem *item)
{
if(item) {
bool ok;
if(!item)
return;
QString name = QInputDialog::getText(i18n("Rename..."), i18n("Please enter a name for this playlist:"),
QLineEdit::Normal, item->text(), &ok);
if(ok) {
item->setText(name);
// Telling the playlist to change it's name will emit a signal that
// is connected to PlaylistItem::setName().
bool ok;
if(item->playlist())
item->playlist()->setName(name);
}
QString name = QInputDialog::getText(i18n("Rename..."), i18n("Please enter a name for this playlist:"),
QLineEdit::Normal, item->text(), &ok);
if(ok) {
item->setText(name);
// Telling the playlist to change it's name will emit a signal that
// is connected to PlaylistItem::setName().
if(item->playlist())
item->playlist()->setName(name);
sort();
setSelected(item, true);
ensureCurrentVisible();
}
}
......@@ -182,6 +187,10 @@ void PlaylistBox::deleteItem(PlaylistBoxItem *item)
else if(remove == KMessageBox::Cancel)
return;
}
else {
if(KMessageBox::warningYesNo(this, i18n("Are you sure you want to remove this item?")) == KMessageBox::No)
return;
}
nameList.remove(item->text());
delete item->playlist();
......
......@@ -31,8 +31,10 @@ class PlaylistItem;
class PlaylistBoxItem;
class PlaylistSplitter;
/** This is the play list selection box that is by default on the right side of
JuK's main widget (PlaylistSplitter). */
/**
* This is the play list selection box that is by default on the right side of
* JuK's main widget (PlaylistSplitter).
*/
class PlaylistBox : public KListBox
{
......@@ -102,12 +104,6 @@ private:
KPopupMenu *playlistContextMenu;
PlaylistBoxItem *contextMenuOn;
bool updatePlaylistStack;
#if QT_VERSION < 0x031000
public:
// This method is defined in Qt 3.1 and later.
QListBoxItem *selectedItem() { return item(currentItem()); }
#endif
};
......
......@@ -446,6 +446,25 @@ void PlaylistSplitter::readConfig()
directoryList = config->readListEntry("DirectoryList");
open(directoryList);
}
// restore the list of hidden and shown columns
if(collection) {
// the last column is just a filler
_visibleColumns.resize(collection->columns() - 1, true);
QValueList<int> l = config->readIntListEntry("VisibleColumns");
uint i = 0;
for(QValueList<int>::Iterator it = l.begin(); it != l.end(); ++it) {
if(! bool(*it)) {
kdDebug() << "! column " << i << endl;
_visibleColumns[i] = bool(*it);
collection->hideColumn(i);
}
i++;
}
setupColumns(collection);
}
}
}
......@@ -481,6 +500,12 @@ void PlaylistSplitter::saveConfig()
{ // block for Playlists group
KConfigGroupSaver saver(config, "Playlists");
config->writeEntry("DirectoryList", directoryList);
QValueList<int> l;
for(uint i = 0; i < _visibleColumns.size(); i++)
l.append(int(_visibleColumns[i]));
config->writeEntry("VisibleColumns", l);
}
}
}
......@@ -519,8 +544,11 @@ void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon)
connect(p, SIGNAL(numberOfItemsChanged(Playlist *)), this, SLOT(playlistCountChanged(Playlist *)));
connect(p, SIGNAL(aboutToRemove(PlaylistItem *)), this, SLOT(playlistItemRemoved(PlaylistItem *)));
connect(p, SIGNAL(signalToggleColumnVisible(int)), this, SLOT(slotToggleColumnVisible(int)));
if(raise) {
playlistStack->raiseWidget(p);
setupColumns(p);
playlistBox->setCurrentItem(i);
playlistBox->ensureCurrentVisible();
}
......@@ -537,6 +565,19 @@ Playlist *PlaylistSplitter::openPlaylist(const QString &file)
return p;
}
void PlaylistSplitter::setupColumns(Playlist *p)
{
if(!p)
return;
for(uint i = 0; i < _visibleColumns.size(); i++) {
if(_visibleColumns[i] && ! p->isColumnVisible(i))
p->showColumn(i);
else if(! _visibleColumns[i] && p->isColumnVisible(i))
p->hideColumn(i);
}
}
////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////
......@@ -546,6 +587,7 @@ void PlaylistSplitter::changePlaylist(PlaylistBoxItem *item)
if(item && item->playlist()) {
playlistStack->raiseWidget(item->playlist());
editor->setItems(playlistSelection());
setupColumns(item->playlist());
emit(playlistChanged());
}
}
......@@ -562,4 +604,9 @@ void PlaylistSplitter::playlistItemRemoved(PlaylistItem *item)
playingItem = 0;
}
void PlaylistSplitter::slotToggleColumnVisible(int column)
{
_visibleColumns[column] = ! _visibleColumns[column];
}
#include "playlistsplitter.moc"
......@@ -254,6 +254,8 @@ private:
* Open the playlist (m3u file or simiar) at \a file.
*/
Playlist *openPlaylist(const QString &file);
void setupColumns(Playlist *p);
private slots:
void changePlaylist(PlaylistBoxItem *item);
......@@ -275,6 +277,8 @@ private slots:
*/
void playlistItemRemoved(PlaylistItem *item);
void slotToggleColumnVisible(int column);
private:
PlaylistItem *playingItem;
PlaylistBox *playlistBox;
......@@ -292,6 +296,8 @@ private:
QStringList directoryQueue;
QStringList directoryQueueRemove;
QValueVector<bool> _visibleColumns;
bool showEditor;
bool restore;
};
......
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