Commit a6e9563d authored by Scott Wheeler's avatar Scott Wheeler

Ported the saving of visible columns to the new Playlist::SharedSettings

class and removed the settings from the PlaylistSplitter.

svn path=/trunk/kdemultimedia/juk/; revision=214961
parent b4b089f1
......@@ -47,8 +47,47 @@
#include "tag.h"
#include "genrelistlist.h"
////////////////////////////////////////////////////////////////////////////////
// Playlist::SharedSettings definition
////////////////////////////////////////////////////////////////////////////////
/**
* Shared settings between the playlists.
*/
class Playlist::SharedSettings
{
public:
static SharedSettings *instance();
/**
* Sets the default column order to that of Playlist @param p.
*/
void setColumnOrder(const Playlist *l);
void toggleColumnVisible(int column);
/**
* Apply the settings.
*/
void apply(Playlist *l) const;
protected:
SharedSettings();
~SharedSettings() {}
private:
void writeConfig();
static SharedSettings *m_instance;
QValueList<int> m_columnOrder;
QValueVector<bool> m_columnsVisible;
};
Playlist::SharedSettings *Playlist::SharedSettings::m_instance = 0;
////////////////////////////////////////////////////////////////////////////////
// Playlist::SharedSettings public members
////////////////////////////////////////////////////////////////////////////////
Playlist::SharedSettings *Playlist::SharedSettings::instance()
{
if(!m_instance)
......@@ -66,31 +105,82 @@ void Playlist::SharedSettings::setColumnOrder(const Playlist *l)
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();
}
writeConfig();
}
void Playlist::SharedSettings::restoreColumnOrder(const Playlist *l)
void Playlist::SharedSettings::toggleColumnVisible(int column)
{
if(column >= int(m_columnsVisible.size()))
m_columnsVisible.resize(column + 1, true);
m_columnsVisible[column] = !m_columnsVisible[column];
writeConfig();
}
void Playlist::SharedSettings::apply(Playlist *l) const
{
if(!l)
return;
int i = 0;
for(QValueListIterator<int> it = m_columnOrder.begin(); it != m_columnOrder.end(); ++it)
for(QValueListConstIterator<int> it = m_columnOrder.begin(); it != m_columnOrder.end(); ++it)
l->header()->moveSection(i++, *it);
for(uint i = 0; i < m_columnsVisible.size(); i++) {
if(m_columnsVisible[i] && ! l->isColumnVisible(i))
l->showColumn(i);
else if(! m_columnsVisible[i] && l->isColumnVisible(i))
l->hideColumn(i);
}
}
////////////////////////////////////////////////////////////////////////////////
// Playlist::ShareSettings protected members
////////////////////////////////////////////////////////////////////////////////
Playlist::SharedSettings::SharedSettings()
{
KConfig *config = kapp->config();
{
KConfigGroupSaver(config, "PlaylistShared");
// save column order
m_columnOrder = config->readIntListEntry("ColumnOrder");
QValueList<int> l = config->readIntListEntry("VisibleColumns");
m_columnsVisible.resize(l.size(), true);
// save visible columns
uint i = 0;
for(QValueList<int>::Iterator it = l.begin(); it != l.end(); ++it) {
if(! bool(*it))
m_columnsVisible[i] = bool(*it);
i++;
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Playlist::SharedSettings private members
////////////////////////////////////////////////////////////////////////////////
void Playlist::SharedSettings::writeConfig()
{
KConfig *config = kapp->config();
{
KConfigGroupSaver(config, "PlaylistShared");
config->writeEntry("ColumnOrder", m_columnOrder);
QValueList<int> l;
for(uint i = 0; i < m_columnsVisible.size(); i++)
l.append(int(m_columnsVisible[i]));
config->writeEntry("VisibleColumns", l);
}
config->sync();
}
////////////////////////////////////////////////////////////////////////////////
......@@ -439,7 +529,7 @@ void Playlist::contentsDragMoveEvent(QDragMoveEvent *e)
void Playlist::showEvent(QShowEvent *e)
{
SharedSettings::instance()->restoreColumnOrder(this);
SharedSettings::instance()->apply(this);
KListView::showEvent(e);
}
......@@ -572,7 +662,7 @@ void Playlist::setup()
m_headerMenu->setItemChecked(i, true);
}
connect(m_headerMenu, SIGNAL(activated(int)), this, SIGNAL(signalToggleColumnVisible(int)));
connect(m_headerMenu, SIGNAL(activated(int)), this, SLOT(slotToggleColumnVisible(int)));
//////////////////////////////////////////////////
// setup playlist RMB menu
......@@ -757,6 +847,16 @@ void Playlist::slotColumnOrderChanged(int, int from, int to)
SharedSettings::instance()->setColumnOrder(this);
}
void Playlist::slotToggleColumnVisible(int column)
{
if(isColumnVisible(column))
hideColumn(column);
else
showColumn(column);
SharedSettings::instance()->toggleColumnVisible(column);
}
int Playlist::leftMostVisibleColumn() const
{
int i = 0;
......
......@@ -21,6 +21,7 @@
#include <klistview.h>
#include <qstringlist.h>
#include <qvaluevector.h>
#include <qptrstack.h>
#include "playlistitem.h"
......@@ -140,12 +141,6 @@ 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.
......@@ -191,7 +186,6 @@ signals:
* list.
*/
void signalAboutToRemove(PlaylistItem *item);
void signalToggleColumnVisible(int column);
void signalFilesDropped(const QStringList &files, Playlist *);
void signalSetNext(PlaylistItem *item);
......@@ -200,6 +194,12 @@ private:
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()); }
void slotEmitDoubleClicked(QListViewItem *) { emit signalDoubleClicked(); }
......@@ -207,6 +207,7 @@ private slots:
void slotApplyModification(QListViewItem *item, const QString &text, int column);
void slotRenameTag();
void slotColumnOrderChanged(int, int from, int to);
void slotToggleColumnVisible(int column);
private:
int m_currentColumn;
......@@ -234,28 +235,6 @@ 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);
......
......@@ -335,13 +335,6 @@ void PlaylistSplitter::slotAddToPlaylist(const QStringList &files, Playlist *lis
m_editor->slotUpdateCollection();
}
void PlaylistSplitter::slotToggleColumnVisible(int column)
{
m_visibleColumns[column] = ! m_visibleColumns[column];
if(visiblePlaylist())
setupColumns(visiblePlaylist());
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
......@@ -433,27 +426,10 @@ void PlaylistSplitter::readConfig()
// restore the list of hidden and shown columns
if(m_collection) {
// the last column is just a filler
m_visibleColumns.resize(m_collection->columns() - 1, true);
QValueList<int> l = config->readIntListEntry("VisibleColumns");
m_collection->setSorting(config->readNumEntry("SortColumn", 1));
uint i = 0;
for(QValueList<int>::Iterator it = l.begin(); it != l.end(); ++it) {
if(! bool(*it)) {
m_visibleColumns[i] = bool(*it);
m_collection->hideColumn(i);
}
// while we're looping go ahead and populate m_columnNames
if(m_collection)
for(int i = 0; i < m_collection->columns(); i++)
m_columnNames.append(m_collection->columnText(i));
i++;
}
setupColumns(m_collection);
}
}
}
......@@ -484,14 +460,7 @@ void PlaylistSplitter::saveConfig()
{ // block for Playlists group
KConfigGroupSaver saver(config, "Playlists");
config->writeEntry("DirectoryList", m_directoryList);
QValueList<int> l;
for(uint i = 0; i < m_visibleColumns.size(); i++)
l.append(int(m_visibleColumns[i]));
config->writeEntry("VisibleColumns", l);
config->writeEntry("SortColumn", m_collection->sortColumn());
config->writeEntry("PlaylistSplitterSizes", sizes());
}
}
......@@ -528,14 +497,10 @@ void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon)
connect(p, SIGNAL(signalFilesDropped(const QStringList &, Playlist *)), this, SLOT(slotAddToPlaylist(const QStringList &, Playlist *)));
connect(p, SIGNAL(signalSetNext(PlaylistItem *)), this, SLOT(slotSetNextItem(PlaylistItem *)));
connect(p, SIGNAL(signalToggleColumnVisible(int)), this, SLOT(slotToggleColumnVisible(int)));
m_playlistBox->createItem(p, icon, raise);
if(raise) {
if(raise)
m_playlistStack->raiseWidget(p);
setupColumns(p);
}
}
Playlist *PlaylistSplitter::openPlaylist(const QString &file)
......@@ -549,19 +514,6 @@ Playlist *PlaylistSplitter::openPlaylist(const QString &file)
return p;
}
void PlaylistSplitter::setupColumns(Playlist *p)
{
if(!p)
return;
for(uint i = 0; i < m_visibleColumns.size(); i++) {
if(m_visibleColumns[i] && ! p->isColumnVisible(i))
p->showColumn(i);
else if(! m_visibleColumns[i] && p->isColumnVisible(i))
p->hideColumn(i);
}
}
QString PlaylistSplitter::play(PlaylistItem *item)
{
stop();
......@@ -590,7 +542,6 @@ void PlaylistSplitter::slotChangePlaylist(Playlist *p)
m_nextPlaylistItem = 0;
m_playlistStack->raiseWidget(p);
m_editor->slotSetItems(playlistSelection());
setupColumns(p);
emit signalPlaylistChanged();
}
......
......@@ -221,8 +221,6 @@ public slots:
void slotDuplicatePlaylist() { m_playlistBox->duplicate(); }
void slotDeletePlaylist() { m_playlistBox->deleteItem(); }
void slotToggleColumnVisible(int column);
signals:
void signalDoubleClicked();
void signalListBoxDoubleClicked();
......@@ -304,7 +302,6 @@ private:
QStringList m_directoryQueue;
QStringList m_directoryQueueRemove;
QValueVector<bool> m_visibleColumns;
QStringList m_columnNames;
bool m_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