summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/ofilenotify.h90
1 files changed, 87 insertions, 3 deletions
diff --git a/libopie2/opiecore/ofilenotify.h b/libopie2/opiecore/ofilenotify.h
index 13b5a6b..bd2f9d0 100644
--- a/libopie2/opiecore/ofilenotify.h
+++ b/libopie2/opiecore/ofilenotify.h
@@ -45,4 +45,24 @@ namespace Opie {
45namespace Core { 45namespace Core {
46 46
47/*======================================================================================
48 * OFileNotificationType
49 *======================================================================================*/
50
51/**
52 * @brief An enumerate for the different types of file notifications
53 *
54 * This enumerate provides a means to specify the type of events that you are interest in.
55 * Valid values are:
56 * <ul>
57 * <li>Access: The file was accessed (read)
58 * <li>Modify The file was modified (write,truncate)
59 * <li>Create = The file was created in the directory
60 * <li>Delete = The file was unlinked from directory
61 * <li>Rename = The file was renamed
62 * <li>Attrib = The file had its attributes changed (chmod,chown,chgrp)
63 * </ul>
64 *
65 **/
66
47enum OFileNotificationType { Single = 0x0000000, 67enum OFileNotificationType { Single = 0x0000000,
48 Multi = DN_MULTISHOT, 68 Multi = DN_MULTISHOT,
@@ -54,4 +74,20 @@ enum OFileNotificationType { Single = 0x0000000,
54 Attrib = DN_ATTRIB }; 74 Attrib = DN_ATTRIB };
55 75
76/*======================================================================================
77 * OFileNotification
78 *======================================================================================*/
79
80/**
81 * @brief Represents a file notification
82 *
83 * This class allows to watch for events happening to files.
84 * It uses the dnotify kernel interface which is a very efficient signalling interface.
85 *
86 * @see <file:///usr/src/linux/Documentation/dnotify.txt>
87 *
88 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
89 *
90 **/
91
56class OFileNotification : public QObject 92class OFileNotification : public QObject
57{ 93{
@@ -61,16 +97,61 @@ class OFileNotification : public QObject
61 OFileNotification( QObject* parent = 0, const char* name = 0 ); 97 OFileNotification( QObject* parent = 0, const char* name = 0 );
62 ~OFileNotification(); 98 ~OFileNotification();
63 99 /**
100 * This static function calls a slot when an event with @a type happens to file @a path.
101 *
102 * It is very convenient to use this function because you do not need to
103 * bother with a timerEvent or to create a local QTimer object.
104 *
105 * Example:
106 * <pre>
107 *
108 * #include <opie2/oapplication.h>
109 * #include <opie2/onitify.h>
110 * using namespace Opie::Core;
111 *
112 * int main( int argc, char **argv )
113 * {
114 * OApplication a( argc, argv, "File Notification Example" );
115 * OFileNotification::singleShot( "/tmp/quit", &a, SLOT(quit()), Create );
116 * ... // create and show your widgets
117 * return a.exec();
118 * }
119 *
120 * This sample program automatically terminates when the file "/tmp/quite" has been created.
121 *
122 *
123 * The @a receiver is the receiving object and the @a member is the slot.
124 **/
64 static void singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type = Modify ); 125 static void singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type = Modify );
65 126 /**
127 * Starts to watch for @a type changes to @a path. Set @a sshot to True if you want to be notified only once.
128 * Note that in that case it may be more convenient to use @ref OFileNotification::singleShot() then.
129 **/
66 int start( const QString& path, bool sshot = false, OFileNotificationType type = Modify ); 130 int start( const QString& path, bool sshot = false, OFileNotificationType type = Modify );
131 /**
132 * Stop watching for file events.
133 **/
67 void stop(); 134 void stop();
68 135 /**
136 * @returns the notification type as set by @ref start().
137 **/
69 OFileNotificationType type() const; 138 OFileNotificationType type() const;
139 /**
140 * @returns the path to the file being watched by this instance.
141 **/
70 QString path() const; 142 QString path() const;
143 /**
144 * @returns the UNIX file descriptor for the file being watched.
145 **/
71 int fileno() const; 146 int fileno() const;
147 /**
148 * @returns if a file is currently being watched.
149 **/
72 bool isActive() const; 150 bool isActive() const;
73 151
74 signals: 152 signals:
153 /**
154 * This signal is emitted if an event happens of the specified type happens to the file being watched.
155 **/
75 void triggered(); 156 void triggered();
76 157
@@ -91,11 +172,14 @@ class OFileNotification : public QObject
91}; 172};
92 173
174#if 0
93 175
94class ODirectoryNotification : public OFileNotification 176class ODirectoryNotification : public OFileNotification
95{ 177{
178
96 public: 179 public:
97 virtual bool hasChanged() { return true; }; 180 virtual bool hasChanged() { return true; };
98}; 181};
99 182
183#endif
100 184
101} 185}