вешаю монитор на один каталог и по сигналу "changed" вызывается эта функция. в этой функции если в этом каталоге создается ещё каталог, то на него вешается ещё монитор, но у меня это не работает. мониторит только один каталог, который самый первый.
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;
}
}