Answer the question
In order to leave comments, you need to log in
How to hang a monitor on all directories?
I hang up the monitor on one directory and on a signal "changed" this function is caused. in this function, if another directory is created in this directory, then another monitor is hung on it, but this does not work for me. monitors only one directory, which is the very first one.
static void monitors_gfile_monitor_changed_cb ( GFileMonitor *monitor,
GFile *file,
GFile *other_file,
GFileMonitorEvent event_type,
gpointer data ) {
std::string *path = ( std::string * ) data;
if ( access ( current_path_project, F_OK ) ) exit ( EXIT_FAILURE );
if ( access ( (*path).c_str(), F_OK ) ) {
GFileInfo *info_file = g_file_query_info ( file, "*", G_FILE_QUERY_INFO_NONE, NULL, NULL );
if ( g_file_info_get_file_type ( info_file ) == G_FILE_TYPE_DIRECTORY ) {
printf ( "удален монитор: %s\n", (*path).c_str() );
GFileMonitor *monitor = mon [ path ];
g_file_monitor_cancel ( monitor );
}
g_object_unref ( info_file );
return;
}
switch ( event_type ) {
case G_FILE_MONITOR_EVENT_CHANGED: {
}
break;
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: {
}
break;
case G_FILE_MONITOR_EVENT_DELETED:{
}
break;
case G_FILE_MONITOR_EVENT_CREATED:{
printf ( "->%s: ", (*path).c_str() );
const char *name_file = g_file_get_path ( file );
GFileInfo *info_file = g_file_query_info ( file, "*", G_FILE_QUERY_INFO_NONE, NULL, NULL );
if ( g_file_info_get_file_type ( info_file ) == G_FILE_TYPE_DIRECTORY ) {
std::string *path = new std::string ( name_file );
GFileMonitor *monitor = g_file_monitor_directory ( file, G_FILE_MONITOR_WATCH_MOVES, NULL, NULL );
if ( !monitor ) printf ( "error\n" );
mon [ path ] = monitor;
g_signal_connect ( monitor, "changed", G_CALLBACK ( monitors_gfile_monitor_changed_cb ), path );
}
g_object_unref ( info_file );
printf ( "file:%s = created\n", name_file );
}
break;
case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED: {
}
break;
case G_FILE_MONITOR_EVENT_PRE_UNMOUNT: {
}
break;
case G_FILE_MONITOR_EVENT_UNMOUNTED: {
}
break;
case G_FILE_MONITOR_EVENT_MOVED: {
}
break;
case G_FILE_MONITOR_EVENT_RENAMED: {
}
break;
case G_FILE_MONITOR_EVENT_MOVED_IN: {
}
break;
case G_FILE_MONITOR_EVENT_MOVED_OUT: {
}
break;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question