]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/fswatcher_inotify.cpp
support for inheriting non-standard attributes (explicit fonts instead of window...
[wxWidgets.git] / src / unix / fswatcher_inotify.cpp
index 5bcc475698ef63bc3fb3f6c5329a4796619c2fe3..f7438727dfdccd0a1ce328f255e417b631376fa9 100644 (file)
@@ -261,10 +261,17 @@ protected:
         // check out for error/warning condition
         if (flags & wxFSW_EVENT_WARNING || flags & wxFSW_EVENT_ERROR)
         {
         // check out for error/warning condition
         if (flags & wxFSW_EVENT_WARNING || flags & wxFSW_EVENT_ERROR)
         {
-            wxString errMsg = GetErrorDescription(Watcher2NativeFlags(flags));
+            wxString errMsg = GetErrorDescription(nativeFlags);
             wxFileSystemWatcherEvent event(flags, errMsg);
             SendEvent(event);
         }
             wxFileSystemWatcherEvent event(flags, errMsg);
             SendEvent(event);
         }
+        // Now IN_UNMOUNT. We must do so here, as it's not in the watch flags
+        if (nativeFlags & IN_UNMOUNT)
+        {
+            wxFileName path = GetEventPath(watch, inevt);
+            wxFileSystemWatcherEvent event(wxFSW_EVENT_UNMOUNT, path, path);
+            SendEvent(event);
+        }
         // filter out ignored events and those not asked for.
         // we never filter out warnings or exceptions
         else if ((flags == 0) || !(flags & watch.GetFlags()))
         // filter out ignored events and those not asked for.
         // we never filter out warnings or exceptions
         else if ((flags == 0) || !(flags & watch.GetFlags()))
@@ -479,10 +486,33 @@ protected:
         return path;
     }
 
         return path;
     }
 
-    static int Watcher2NativeFlags(int WXUNUSED(flags))
+    static int Watcher2NativeFlags(int flags)
     {
     {
-        // TODO: it would be nice to subscribe only to the events we really need
-        return IN_ALL_EVENTS;
+        // Start with the standard case of wanting all events
+        if (flags == wxFSW_EVENT_ALL)
+        {
+            return IN_ALL_EVENTS;
+        }
+
+        static const int flag_mapping[][2] = {
+            { wxFSW_EVENT_ACCESS, IN_ACCESS   },
+            { wxFSW_EVENT_MODIFY, IN_MODIFY   },
+            { wxFSW_EVENT_ATTRIB, IN_ATTRIB   },
+            { wxFSW_EVENT_RENAME, IN_MOVE     },
+            { wxFSW_EVENT_CREATE, IN_CREATE   },
+            { wxFSW_EVENT_DELETE, IN_DELETE|IN_DELETE_SELF|IN_MOVE_SELF },
+            { wxFSW_EVENT_UNMOUNT, IN_UNMOUNT }
+            // wxFSW_EVENT_ERROR/WARNING make no sense here
+        };
+
+        int native_flags = 0;
+        for ( unsigned int i=0; i < WXSIZEOF(flag_mapping); ++i)
+        {
+            if (flags & flag_mapping[i][0])
+                native_flags |= flag_mapping[i][1];
+        }
+
+        return native_flags;
     }
 
     static int Native2WatcherFlags(int flags)
     }
 
     static int Native2WatcherFlags(int flags)
@@ -490,7 +520,7 @@ protected:
         static const int flag_mapping[][2] = {
             { IN_ACCESS,        wxFSW_EVENT_ACCESS }, // generated during read!
             { IN_MODIFY,        wxFSW_EVENT_MODIFY },
         static const int flag_mapping[][2] = {
             { IN_ACCESS,        wxFSW_EVENT_ACCESS }, // generated during read!
             { IN_MODIFY,        wxFSW_EVENT_MODIFY },
-            { IN_ATTRIB,        0 },
+            { IN_ATTRIB,        wxFSW_EVENT_ATTRIB },
             { IN_CLOSE_WRITE,   0 },
             { IN_CLOSE_NOWRITE, 0 },
             { IN_OPEN,          0 },
             { IN_CLOSE_WRITE,   0 },
             { IN_CLOSE_NOWRITE, 0 },
             { IN_OPEN,          0 },
@@ -501,10 +531,10 @@ protected:
             { IN_DELETE_SELF,   wxFSW_EVENT_DELETE },
             { IN_MOVE_SELF,     wxFSW_EVENT_DELETE },
 
             { IN_DELETE_SELF,   wxFSW_EVENT_DELETE },
             { IN_MOVE_SELF,     wxFSW_EVENT_DELETE },
 
-            { IN_UNMOUNT,       wxFSW_EVENT_ERROR  },
+            { IN_UNMOUNT,       wxFSW_EVENT_UNMOUNT},
             { IN_Q_OVERFLOW,    wxFSW_EVENT_WARNING},
 
             { IN_Q_OVERFLOW,    wxFSW_EVENT_WARNING},
 
-            // ignored, because this is genereted mainly by watcher::Remove()
+            // ignored, because this is generated mainly by watcher::Remove()
             { IN_IGNORED,        0 }
         };
 
             { IN_IGNORED,        0 }
         };
 
@@ -527,8 +557,6 @@ protected:
     {
         switch ( flag )
         {
     {
         switch ( flag )
         {
-        case IN_UNMOUNT:
-            return _("File system containing watched object was unmounted");
         case IN_Q_OVERFLOW:
             return _("Event queue overflowed");
         }
         case IN_Q_OVERFLOW:
             return _("Event queue overflowed");
         }