Commit 0a5cb1b5 authored by Scott Wheeler's avatar Scott Wheeler

Added support for watching the dir list and automatically adding the files

when they're added to those dirs.

svn path=/trunk/kdemultimedia/juk/; revision=212982
parent dfb22ab9
......@@ -31,16 +31,16 @@
// static methods
////////////////////////////////////////////////////////////////////////////////
CollectionList *CollectionList::list = 0;
CollectionList *CollectionList::m_list = 0;
CollectionList *CollectionList::instance()
{
return list;
return m_list;
}
void CollectionList::initialize(QWidget *parent, bool restoreOnLoad)
{
list = new CollectionList(parent);
m_list = new CollectionList(parent);
if(restoreOnLoad)
for(QDictIterator<Tag>it(*Cache::instance()); it.current(); ++it)
......@@ -90,9 +90,13 @@ void CollectionList::slotCheckCache()
// protected methods
////////////////////////////////////////////////////////////////////////////////
CollectionList::CollectionList(QWidget *parent) : Playlist(parent, i18n("Collection List"))
CollectionList::CollectionList(QWidget *parent) : Playlist(parent, i18n("Collection List")),
m_itemsDict(5003)
{
m_dirWatch = new KDirWatch();
connect(m_dirWatch, SIGNAL(deleted(const QString &)), this, SLOT(slotRemoveItem(const QString &)));
connect(m_dirWatch, SIGNAL(dirty(const QString &)), this, SLOT(slotRefreshItem(const QString &)));
m_dirWatch->startScan();
}
CollectionList::~CollectionList()
......@@ -148,6 +152,21 @@ void CollectionList::addAlbum(const QString &album)
if(album != previousAlbum && !m_albums.insert(album))
previousAlbum = album;
}
////////////////////////////////////////////////////////////////////////////////
// private slots
////////////////////////////////////////////////////////////////////////////////
void CollectionList::slotRemoveItem(const QString &file)
{
clearItem(m_itemsDict[file]);
}
void CollectionList::slotRefreshItem(const QString &file)
{
m_itemsDict[file]->slotRefresh();
}
////////////////////////////////////////////////////////////////////////////////
// CollectionListItem public slots
////////////////////////////////////////////////////////////////////////////////
......@@ -160,26 +179,29 @@ void CollectionListItem::slotRefresh()
CollectionList::instance()->addArtist(text(ArtistColumn));
CollectionList::instance()->addAlbum(text(AlbumColumn));
}
// This is connected to slotRefreshImpl() for all of the items children.
emit(signalRefreshed());
emit signalRefreshed();
}
////////////////////////////////////////////////////////////////////////////////
// CollectionListItem protected methods
////////////////////////////////////////////////////////////////////////////////
CollectionListItem::CollectionListItem(const QFileInfo &file, const QString &path) : PlaylistItem(CollectionList::instance())
CollectionListItem::CollectionListItem(const QFileInfo &file, const QString &path) : PlaylistItem(CollectionList::instance()),
m_path(path)
{
CollectionList *l = CollectionList::instance();
if(l) {
l->addToDict(path, this);
setData(Data::newUser(file, path));
l->addToDict(m_path, this);
setData(Data::newUser(file, m_path));
slotRefresh();
connect(this, SIGNAL(signalRefreshed()), l, SIGNAL(signalDataChanged()));
l->emitNumberOfItemsChanged();
// l->addWatched(m_path);
}
else
kdError() << "CollectionListItems should not be created before"
kdError() << "CollectionListItems should not be created before "
<< "CollectionList::initialize() has been called." << endl;
SplashScreen::increment();
......@@ -188,8 +210,11 @@ CollectionListItem::CollectionListItem(const QFileInfo &file, const QString &pat
CollectionListItem::~CollectionListItem()
{
CollectionList *l = CollectionList::instance();
if(l)
l->removeFromDict(Playlist::resolveSymLinks(*data()));
if(l) {
QString path = Playlist::resolveSymLinks(*data());
// l->removeWatched(m_path);
l->removeFromDict(m_path);
}
}
void CollectionListItem::addChildItem(PlaylistItem *child)
......@@ -200,8 +225,10 @@ void CollectionListItem::addChildItem(PlaylistItem *child)
void CollectionListItem::checkCurrent()
{
if(!data()->exists() || !data()->isFile())
if(!data()->exists() || !data()->isFile()) {
CollectionList::instance()->clearItem(this);
return;
}
else if(!data()->tag()->current())
data()->refresh();
}
......
......@@ -19,6 +19,7 @@
#define COLLECTIONLIST_H
#include <kapplication.h>
#include <kdirwatch.h>
#include <qclipboard.h>
#include <qdict.h>
......@@ -27,6 +28,8 @@
#include "playlistitem.h"
#include "sortedstringlist.h"
class CollectionListItem;
/**
* This is the "collection", or all of the music files that have been opened
* in any playlist and not explicitly removed from the collection.
......@@ -38,8 +41,6 @@
* "initialize()" method.
*/
class CollectionListItem;
class CollectionList : public Playlist
{
friend class CollectionListItem;
......@@ -87,14 +88,22 @@ protected:
void emitNumberOfItemsChanged() { emit signalNumberOfItemsChanged(this); }
void addWatched(const QString &file) { m_dirWatch->addFile(file); }
void removeWatched(const QString &file) { m_dirWatch->removeFile(file); }
signals:
void signalCollectionChanged();
private slots:
void slotRemoveItem(const QString &file);
void slotRefreshItem(const QString &file);
private:
static CollectionList *list;
static CollectionList *m_list;
QDict<CollectionListItem> m_itemsDict;
SortedStringList m_artists;
SortedStringList m_albums;
KDirWatch *m_dirWatch;
};
class CollectionListItem : public PlaylistItem
......@@ -126,6 +135,9 @@ protected:
* moving this action into the event loop.
*/
void checkCurrent();
private:
QString m_path;
};
#endif
......@@ -20,6 +20,7 @@
#include <kapplication.h>
#include <kstandarddirs.h>
#include <kmessagebox.h>
#include <kdirwatch.h>
#include <kdebug.h>
#include <qinputdialog.h>
......@@ -244,15 +245,21 @@ void PlaylistSplitter::slotOpenDirectory()
DirectoryList *l = new DirectoryList(m_directoryList, this, "directoryList");
m_directoryQueue.clear();
m_directoryQueueRemove.clear();
connect(l, SIGNAL(signalDirectoryAdded(const QString &)), this, SLOT(slotQueueDirectory(const QString &)));
connect(l, SIGNAL(signalDirectoryRemoved(const QString &)), this, SLOT(slotQueueDirectoryRemove(const QString &)));
if(l->exec() == QDialog::Accepted) {
open(m_directoryQueue);
for(QStringList::Iterator it = m_directoryQueue.begin(); it != m_directoryQueue.end(); it++)
m_dirWatch->addDir(*it, false, true);
m_directoryList += m_directoryQueue;
for(QStringList::Iterator it = m_directoryQueueRemove.begin(); it != m_directoryQueueRemove.end(); it++)
for(QStringList::Iterator it = m_directoryQueueRemove.begin(); it != m_directoryQueueRemove.end(); it++) {
m_dirWatch->removeDir(*it);
m_directoryList.remove(*it);
}
}
}
void PlaylistSplitter::slotSetEditorVisible(bool visible)
......@@ -408,6 +415,14 @@ void PlaylistSplitter::readConfig()
m_directoryList = config->readListEntry("DirectoryList");
QTimer::singleShot(0, this, SLOT(slotScanDirectories()));
m_dirWatch = new KDirWatch();
connect(m_dirWatch, SIGNAL(dirty(const QString &)), this, SLOT(slotDirChanged(const QString &)));
for(QStringList::Iterator it = m_directoryList.begin(); it != m_directoryList.end(); ++it)
m_dirWatch->addDir(*it, false, true);
m_dirWatch->startScan();
}
// restore the list of hidden and shown columns
......@@ -433,8 +448,7 @@ void PlaylistSplitter::readConfig()
setupColumns(m_collection);
}
}
}
}
void PlaylistSplitter::saveConfig()
{
......
......@@ -31,6 +31,7 @@
class KActionMenu;
class PlaylistItem;
class KDirWatch;
/**
* This is the main layout class of JuK. It should contain a PlaylistBox and
......@@ -284,6 +285,7 @@ private slots:
void slotScanDirectories() { open(m_directoryList); }
void slotSetNextItem(PlaylistItem *item = 0) { m_nextPlaylistItem = item; }
void slotDirChanged(const QString &dir) { open(dir); }
private:
PlaylistItem *m_playingItem;
......@@ -308,6 +310,8 @@ private:
bool m_restore;
PlaylistItem *m_nextPlaylistItem;
KDirWatch *m_dirWatch;
};
#endif
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