summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrangerot <purple@orangerot.dev>2023-04-06 21:42:42 +0200
committerOrangerot <purple@orangerot.dev>2023-04-06 21:42:42 +0200
commit79d2167a226dafbdfa58b45ce76c3cb0617efb29 (patch)
treeff71c4a6ab155d8180e8d974a5bd43dc0e40b203
parent42bacc4e82c22eef09d9748c11f2a193a91a6be4 (diff)
listen for changes in directory
-rw-r--r--dicons.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/dicons.c b/dicons.c
index 4f17f52..34d67a3 100644
--- a/dicons.c
+++ b/dicons.c
@@ -11,12 +11,37 @@ enum
NUM_COLS
};
+GtkListStore *store;
+
+// Callback function for file created signal
+static void file_changed_cb(GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent evtype, gpointer user_data)
+{
+ char *fpath = g_file_get_path(file);
+ char *opath = NULL;
+ if (other_file) {
+ opath = g_file_get_path(other_file);
+ }
+
+ switch(evtype) {
+ case G_FILE_MONITOR_EVENT_DELETED:
+ g_print("%s deleted\n", fpath);
+ break;
+ case G_FILE_MONITOR_EVENT_CREATED:
+ g_print("%s created\n", fpath);
+ break;
+ }
+ if (opath) {
+ g_free(opath);
+ }
+ g_free(fpath);
+}
+
static GtkListStore *create_desktop_list(void)
{
- GtkListStore *store;
GtkTreeIter iter;
GDir *dir;
- GFile *file;
+ GFile *file, *dir_file;
+ GFileMonitor *monitor;
GFileInfo *file_info;
const gchar *file_name, *display_name;
GtkIconTheme *theme;
@@ -35,6 +60,10 @@ static GtkListStore *create_desktop_list(void)
dir = g_dir_open(desktop_path, 0, 0);
+ dir_file = g_file_new_for_path(desktop_path);
+ // monitor = g_file_monitor_directory(dir_file, G_FILE_MONITOR_WATCH_MOVES, NULL, NULL);
+ monitor = g_file_monitor_directory(dir_file, G_FILE_MONITOR_NONE, NULL, NULL);
+
while ( (file_name = g_dir_read_name(dir)) ) {
printf("g %s\n", file_name);
@@ -57,6 +86,8 @@ static GtkListStore *create_desktop_list(void)
);
}
+ g_signal_connect(monitor, "changed", G_CALLBACK(file_changed_cb), NULL);
+
return GTK_LIST_STORE(store);
}