Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 6d969076 authored by Scott Wheeler's avatar Scott Wheeler

Save and restore column order.

svn path=/trunk/kdemultimedia/juk/; revision=214951
parent d37fe7ea
......@@ -47,19 +47,51 @@
#include "tag.h"
#include "genrelistlist.h"
class Playlist::SharedSettings
Playlist::SharedSettings *Playlist::SharedSettings::m_instance = 0;
Playlist::SharedSettings *Playlist::SharedSettings::instance()
{
if(!m_instance)
m_instance = new SharedSettings;
return m_instance;
}
void Playlist::SharedSettings::setColumnOrder(const Playlist *l)
{
public:
static SharedSettings *instance() {
if(!m_instance)
m_instance = new SharedSettings;
return m_instance;
if(!l)
return;
m_columnOrder.clear();
for(int i = 0; i < l->columns(); ++i)
m_columnOrder.append(l->header()->mapToIndex(i));
KConfig *config = kapp->config();
{
KConfigGroupSaver(config, "PlaylistShared");
config->writeEntry("ColumnOrder", m_columnOrder);
config->sync();
}
private:
static SharedSettings *m_instance;
};
}
Playlist::SharedSettings* Playlist::SharedSettings::m_instance = 0;
void Playlist::SharedSettings::restoreColumnOrder(const Playlist *l)
{
if(!l)
return;
int i = 0;
for(QValueListIterator<int> it = m_columnOrder.begin(); it != m_columnOrder.end(); ++it)
l->header()->moveSection(i++, *it);
}
Playlist::SharedSettings::SharedSettings()
{
KConfig *config = kapp->config();
{
KConfigGroupSaver(config, "PlaylistShared");
m_columnOrder = config->readIntListEntry("ColumnOrder");
}
}
////////////////////////////////////////////////////////////////////////////////
// public members
......@@ -405,6 +437,12 @@ void Playlist::contentsDragMoveEvent(QDragMoveEvent *e)
e->accept(false);
}
void Playlist::showEvent(QShowEvent *e)
{
SharedSettings::instance()->restoreColumnOrder(this);
KListView::showEvent(e);
}
PlaylistItem *Playlist::createItem(const QFileInfo &file, QListViewItem *after)
{
QString filePath = resolveSymLinks(file);
......@@ -715,6 +753,8 @@ void Playlist::slotColumnOrderChanged(int, int from, int to)
}
m_leftColumn = header()->mapToSection(0);
}
SharedSettings::instance()->setColumnOrder(this);
}
int Playlist::leftMostVisibleColumn() const
......
......@@ -140,6 +140,12 @@ public slots:
virtual void selectAll() { KListView::selectAll(true); }
protected:
/**
* This class is used internally to store settings that are shared by all
* of the playlists, such as column order. It is implemented as a singleton.
*/
class SharedSettings;
/**
* Remove \a items from the playlist and disk. This will ignore items that
* are not actually in the list.
......@@ -153,9 +159,10 @@ protected:
virtual void decode(QMimeSource *s);
virtual void contentsDropEvent(QDropEvent *e);
virtual void contentsDragMoveEvent(QDragMoveEvent *e);
virtual void showEvent(QShowEvent *e);
static QString resolveSymLinks(const QFileInfo &file);
signals:
/**
* This signal is connected to PlaylistItem::refreshed() in the
......@@ -192,12 +199,6 @@ private:
void setup();
void applyTag(QListViewItem *item, const QString &text, int column);
int leftMostVisibleColumn() const;
/**
* This class is used internally to store settings that are shared by all
* of the playlists, such as column order. It is implemented as a singleton.
*/
class SharedSettings;
private slots:
void slotEmitSelected() { emit signalSelectionChanged(selectedItems()); }
......@@ -233,6 +234,28 @@ private:
int m_leftColumn;
};
class Playlist::SharedSettings
{
public:
static SharedSettings *instance();
/**
* Sets the default column order to that of Playlist @param p.
*/
void setColumnOrder(const Playlist *p);
/**
* Sets the columns of @param p to match the stored settings.
*/
void restoreColumnOrder(const Playlist *p);
protected:
SharedSettings();
~SharedSettings() {}
private:
static SharedSettings *m_instance;
QValueList<int> m_columnOrder;
};
QDataStream &operator<<(QDataStream &s, const Playlist &p);
QDataStream &operator>>(QDataStream &s, Playlist &p);
......
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