summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-07-22 20:08:25 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-22 20:08:25 +0200
commit1511cac715c9d7b6df37cf56d605efc924bf59bb (patch)
treeeb9cffbfbac921b56c1e23379f99ba882f5e4c90 /Libraries
parentc8e2bb5605adea7fff02a0e51b8246f944ba29ad (diff)
downloadserenity-1511cac715c9d7b6df37cf56d605efc924bf59bb.zip
GDirectoryModel: Automagically update on filesystem changes.
Use the new watch_file() mechanism to monitor the currently open directory for changes and refresh the model when notified. This makes FileManager automagically show newly added files. :^)
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/GDirectoryModel.cpp11
-rw-r--r--Libraries/LibGUI/GDirectoryModel.h3
2 files changed, 14 insertions, 0 deletions
diff --git a/Libraries/LibGUI/GDirectoryModel.cpp b/Libraries/LibGUI/GDirectoryModel.cpp
index b682f9bf7e..be68c4dd7e 100644
--- a/Libraries/LibGUI/GDirectoryModel.cpp
+++ b/Libraries/LibGUI/GDirectoryModel.cpp
@@ -308,7 +308,18 @@ void GDirectoryModel::open(const StringView& a_path)
if (!dirp)
return;
closedir(dirp);
+ if (m_notifier)
+ close(m_notifier->fd());
m_path = path;
+ int watch_fd = watch_file(path.characters(), path.length());
+ if (watch_fd < 0) {
+ perror("watch_file");
+ ASSERT_NOT_REACHED();
+ }
+ m_notifier = make<CNotifier>(watch_fd, CNotifier::Event::Read);
+ m_notifier->on_ready_to_read = [this] {
+ update();
+ };
update();
set_selected_index(index(0, 0));
}
diff --git a/Libraries/LibGUI/GDirectoryModel.h b/Libraries/LibGUI/GDirectoryModel.h
index 05ad88cd28..8787a56d17 100644
--- a/Libraries/LibGUI/GDirectoryModel.h
+++ b/Libraries/LibGUI/GDirectoryModel.h
@@ -1,6 +1,7 @@
#pragma once
#include <AK/HashMap.h>
+#include <LibCore/CNotifier.h>
#include <LibGUI/GModel.h>
#include <sys/stat.h>
@@ -77,4 +78,6 @@ private:
HashMap<uid_t, String> m_user_names;
HashMap<gid_t, String> m_group_names;
+
+ OwnPtr<CNotifier> m_notifier;
};