00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#ifndef ksharedfile_h
00022
#define ksharedfile_h
00023
00024
#include <sys/types.h>
00025
00026
#include <qstring.h>
00027
#include <dcopobject.h>
00028
00029
class QFile;
00030
class QTimer;
00031
00046 class KSharedFile :
public QObject,
public DCOPObject
00047 {
00048 Q_OBJECT
00049 K_DCOP
00050
public:
00051
00056
KSharedFile(
const QString &resource );
00057
00063
KSharedFile(
const QFile &file );
00064 ~
KSharedFile( );
00065
00066
class Ticket
00067 {
00068
friend class KSharedFile;
00069 Ticket (
const QString &filename ) : m_fileName( filename ) {}
00070
private:
00071
QString m_fileName;
00072 };
00073
00077
void setFileName (
const QString &filename );
00078
00082
void setFile(
const QFile &file );
00083
00086
QString fileName( )
const;
00087
00091 Ticket*
requestWriteTicket( );
00092
00096 Ticket*
requestReadTicket();
00097
00103
bool save( Ticket *ticket,
const QString &string );
00104
00112
bool save( Ticket *ticket,
const QByteArray & array);
00113
00114
00115
QFile* save( Ticket *ticket );
00116
00117
QString readAsString(
bool &ok, Ticket *ticket );
00118
QByteArray readAsByteArray(
bool &ok, Ticket *ticket );
00119
QFile* readAsFile( Ticket *ticket );
00120
00123
bool unlockReadFile( Ticket *ticket );
00124
bool unlockWriteFile( Ticket *ticket );
00128
bool canReadLock( );
00129
bool canWriteLock();
00133
bool didIReadLock( );
00134
bool didIWriteLock();
00138
00139 k_dcop:
00140 ASYNC
slotFileChanged(
QString );
00141
00142
private:
00143
QFile *m_file;
00144
QString m_fileName;
00145 time_t m_ChangeTime;
00146
bool readLock;
00147
bool writeLock;
00148
void updateLocks();
00149
00150 signals:
00155
void fileWriteUnlocked(
const QString &filename);
00159
void fileWriteLocked(
const QString &filename );
00164
void fileChanged(
const QString &filename );
00165
00166
00167 };
00168
00169
#endif
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179