Watch subdirectories in the library

This commit is contained in:
David Sansome 2010-01-16 17:17:00 +00:00
parent 4108dc7c73
commit 541f3be7ba
4 changed files with 68 additions and 6 deletions

2
TODO
View File

@ -8,7 +8,7 @@
- Clicking play plays selected item - Clicking play plays selected item
- Edit tags in playlist view - Edit tags in playlist view
- Watch subdirectories in library - Disabled fields in tag editor
Long-term: Long-term:
- iPod - iPod

View File

@ -27,6 +27,9 @@
<property name="text"> <property name="text">
<string>Title</string> <string>Title</string>
</property> </property>
<property name="buddy">
<cstring>title</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
@ -37,6 +40,9 @@
<property name="text"> <property name="text">
<string>Album</string> <string>Album</string>
</property> </property>
<property name="buddy">
<cstring>album</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
@ -47,6 +53,9 @@
<property name="text"> <property name="text">
<string>Artist</string> <string>Artist</string>
</property> </property>
<property name="buddy">
<cstring>artist</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
@ -57,6 +66,9 @@
<property name="text"> <property name="text">
<string>Genre</string> <string>Genre</string>
</property> </property>
<property name="buddy">
<cstring>genre</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
@ -67,6 +79,9 @@
<property name="text"> <property name="text">
<string>Track</string> <string>Track</string>
</property> </property>
<property name="buddy">
<cstring>track</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="4" column="1">
@ -92,6 +107,9 @@
<property name="text"> <property name="text">
<string>Year</string> <string>Year</string>
</property> </property>
<property name="buddy">
<cstring>year</cstring>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -117,6 +135,9 @@
<property name="text"> <property name="text">
<string>Comment</string> <string>Comment</string>
</property> </property>
<property name="buddy">
<cstring>comment</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="5" column="1">
@ -168,6 +189,17 @@
<header>lineedit.h</header> <header>lineedit.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops>
<tabstop>buttonBox</tabstop>
<tabstop>title</tabstop>
<tabstop>album</tabstop>
<tabstop>artist</tabstop>
<tabstop>genre</tabstop>
<tabstop>track</tabstop>
<tabstop>year</tabstop>
<tabstop>comment</tabstop>
<tabstop>filename</tabstop>
</tabstops>
<resources/> <resources/>
<connections> <connections>
<connection> <connection>
@ -177,8 +209,8 @@
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>248</x> <x>591</x>
<y>254</y> <y>262</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>157</x> <x>157</x>
@ -193,8 +225,8 @@
<slot>reject()</slot> <slot>reject()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>316</x> <x>591</x>
<y>260</y> <y>268</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>286</x> <x>286</x>

View File

@ -35,6 +35,16 @@ void LibraryWatcher::AddDirectories(const DirectoryList& directories) {
// Start monitoring this directory for more changes // Start monitoring this directory for more changes
fs_watcher_->addPath(dir.path); fs_watcher_->addPath(dir.path);
// And all the subdirectories
QDirIterator it(dir.path,
QDir::NoDotAndDotDot | QDir::Dirs,
QDirIterator::Subdirectories);
while (it.hasNext()) {
QString subdir(it.next());
fs_watcher_->addPath(subdir);
paths_watched_[subdir] = dir;
}
} }
} }
@ -43,6 +53,16 @@ void LibraryWatcher::RemoveDirectories(const DirectoryList &directories) {
fs_watcher_->removePath(dir.path); fs_watcher_->removePath(dir.path);
paths_watched_.remove(dir.path); paths_watched_.remove(dir.path);
paths_needing_rescan_.removeAll(dir.path); paths_needing_rescan_.removeAll(dir.path);
// And all the subdirectories
QDirIterator it(dir.path,
QDir::NoDotAndDotDot | QDir::Dirs,
QDirIterator::Subdirectories);
while (it.hasNext()) {
QString subdir(it.next());
fs_watcher_->removePath(subdir);
paths_watched_.remove(subdir);
}
} }
} }
@ -140,6 +160,7 @@ bool LibraryWatcher::FindSongByPath(const SongList& list, const QString& path, S
} }
void LibraryWatcher::DirectoryChanged(const QString &path) { void LibraryWatcher::DirectoryChanged(const QString &path) {
qDebug() << path;
if (!paths_needing_rescan_.contains(path)) if (!paths_needing_rescan_.contains(path))
paths_needing_rescan_ << path; paths_needing_rescan_ << path;

View File

@ -1,5 +1,7 @@
#include "song.h" #include "song.h"
#include <sys/stat.h>
#include <taglib/fileref.h> #include <taglib/fileref.h>
#include <taglib/tag.h> #include <taglib/tag.h>
#include <taglib/tstring.h> #include <taglib/tstring.h>
@ -315,5 +317,12 @@ bool Song::Save() const {
ref.tag()->setYear(d->year_); ref.tag()->setYear(d->year_);
ref.tag()->setTrack(d->track_); ref.tag()->setTrack(d->track_);
return ref.save(); bool ret = ref.save();
if (ret) {
// Linux: inotify doesn't seem to notice the change to the file unless we
// change the timestamps as well. (this is what touch does)
utimensat(0, QFile::encodeName(d->filename_).constData(), NULL, 0);
}
return ret;
} }