delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / kioslave / sftp / sftpfileattr.h
blob16dbcfac3e7dcc3e59096d29ac03e982f94d43e1
1 /***************************************************************************
2 sftpfileattr.h - description
3 -------------------
4 begin : Sat Jun 30 2001
5 copyright : (C) 2001 by Lucas Fisher
6 email : ljfisher@iastate.edu
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #ifndef SFTPFILEATTR_H
19 #define SFTPFILEATTR_H
21 #include <sys/types.h>
23 #include <QtCore/QBool>
24 #include <QtCore/QByteArray>
25 #include <QtCore/QDataStream>
26 #include <QtCore/QString>
28 #include <kio/global.h>
29 #include <kdebug.h>
31 #include "sftp.h"
33 /**
34 *@author Lucas Fisher
37 class KRemoteEncoding;
38 namespace KIO
40 class UDSEntry;
41 } // namespace KIO
43 class sftpFileAttr {
45 private: // Private attributes
46 /** Name of file. */
47 QString mFilename;
49 /** Specifies which fields of the file attribute are available. */
50 quint32 mFlags;
52 /** Size of the file in bytes. Should be 64 bit safe. */
53 quint64 mSize;
55 /** User id of the owner of the file. */
56 uid_t mUid;
58 /** Group id of the group to which the file belongs. */
59 gid_t mGid;
61 /** POSIX permissions of the file. */
62 mode_t mPermissions;
64 /** Last access time of the file in seconds from Jan 1, 1970. */
65 time_t mAtime;
67 /** Last modification time of file in seconds since Jan. 1, 1970. */
68 time_t mMtime;
70 /** Number of file attribute extensions.
71 Not currently implemented */
72 quint32 mExtendedCount;
74 /** Longname of the file as found in a SSH_FXP_NAME sftp packet.
75 These contents are parse to return the file's owner name and
76 gr oup name. */
77 QByteArray mLongname;
79 QString mUserName;
80 QString mGroupName;
82 /** If file is a link, contains the destination of the link */
83 QString mLinkDestination;
85 /** If resource is a link, contains the type the link,e.g. file,dir... */
86 mode_t mLinkType;
88 /** Whether >> operator should read filename and longname from the stream. */
89 bool mDirAttrs;
91 /** Holds the encoding of the remote host */
92 KRemoteEncoding* mEncoding;
94 public:
95 sftpFileAttr();
97 sftpFileAttr(KRemoteEncoding* encoding);
99 ~sftpFileAttr();
101 /** Constructor to initialize the file attributes on declaration. */
102 sftpFileAttr(quint64 size_, uid_t uid_, gid_t gid_, mode_t permissions_,
103 time_t atime_, time_t mtime_, quint32 extendedCount_ = 0);
105 /** Return the size of the sftp attribute not including filename or longname*/
106 quint32 size() const;
108 /** Clear all attributes and flags. */
109 void clear();
111 /** Set the size of the file. */
112 void setFileSize(quint64 s)
113 { mSize = s; mFlags |= SSH2_FILEXFER_ATTR_SIZE; }
115 /** The size file attribute will not be included in the UDSEntry
116 or when the file attribute is written to the sftp packet. */
117 void clearFileSize()
118 { mSize = 0; mFlags &= ~SSH2_FILEXFER_ATTR_SIZE; }
120 /** Returns the size of the file. */
121 quint64 fileSize() const { return mSize; }
123 /** Sets the POSIX permissions of the file. */
124 void setPermissions(mode_t p)
125 { mPermissions = p; mFlags |= SSH2_FILEXFER_ATTR_PERMISSIONS; }
127 /** The permissions file attribute will not be included in the UDSEntry
128 or when the file attribute is written to the sftp packet. */
129 void clearPermissions()
130 { mPermissions = 0; mFlags &= ~SSH2_FILEXFER_ATTR_PERMISSIONS; }
132 /** Returns the POSIX permissons of the file. */
133 mode_t permissions() const { return mPermissions; }
135 /** Sets the group id of the file. */
136 void setGid(gid_t id)
137 { mGid = id; mFlags |= SSH2_FILEXFER_ATTR_UIDGID; }
139 /** Neither the gid or uid file attributes will not be included in the UDSEntry
140 or when the file attribute is written to the sftp packet. This is
141 equivalent to clearUid() */
142 void clearGid()
143 { mGid = 0; mFlags &= SSH2_FILEXFER_ATTR_UIDGID; }
145 /** Returns the group id of the file. */
146 gid_t gid() const { return mGid; }
148 /** Sets the uid of the file. */
149 void setUid(uid_t id)
150 { mUid = id; mFlags |= SSH2_FILEXFER_ATTR_UIDGID; }
152 /** Neither the gid or uid file attributes will not be included in the UDSEntry
153 or when the file attribute is written to the sftp packet. This is
154 equivalent to clearGid() */
155 void clearUid()
156 { mUid = 0; mFlags &= SSH2_FILEXFER_ATTR_UIDGID; }
158 /** Returns the user id of the file. */
159 gid_t uid() const { return mUid; }
161 /** Set the modificatoin time of the file in seconds since Jan. 1, 1970. */
162 void setMtime(time_t t)
163 { mMtime = t; mFlags |= SSH2_FILEXFER_ATTR_ACMODTIME; }
165 /** Neither the mtime or atime file attributes will not be included in the UDSEntry
166 or when the file attribute is written to the sftp packet. This is
167 equivalent to clearAtime() */
168 void clearMtime()
169 { mMtime = 0; mFlags &= SSH2_FILEXFER_ATTR_ACMODTIME; }
171 /** Returns the modification time of the file in seconds since Jan. 1, 1970. */
172 time_t mtime() const { return mMtime; }
174 /** Sets the access time of the file in seconds since Jan. 1, 1970. */
175 void setAtime(time_t t)
176 { mAtime = t; mFlags |= SSH2_FILEXFER_ATTR_ACMODTIME; }
178 /** Neither the atime or mtime file attributes will not be included in the UDSEntry
179 or when the file attribute is written to the sftp packet. This is
180 equivalent to clearMtime() */
181 void clearAtime()
182 { mAtime = 0; mFlags &= SSH2_FILEXFER_ATTR_ACMODTIME; }
184 /** Returns the last access time of the file in seconds since Jan. 1, 1970. */
185 time_t atime() const { return mAtime; }
187 /** Sets the number of file attribute extensions. */
188 void setExtendedCount(unsigned int c)
189 { mExtendedCount = c; mFlags |= SSH2_FILEXFER_ATTR_EXTENDED; }
191 /** No extensions will be included when the file attribute is written
192 to a sftp packet. */
193 void clearExtensions()
194 { mExtendedCount = 0; mFlags &= ~SSH2_FILEXFER_ATTR_EXTENDED; }
196 /** Returns the number of file attribute extentsions. */
197 unsigned int extendedCount() const { return mExtendedCount; }
199 /** Returns the flags for the sftp file attributes. */
200 unsigned int flags() const { return mFlags; }
202 /** Sets file's longname. See sftpFileAttr::longname. */
203 void setLongname(QString l) { mLongname = l.toLatin1(); }
205 /** Returns a string describing the file attributes. The format is specific
206 to the implementation of the sftp server. In most cases (ie OpenSSH)
207 this is similar to the long output of 'ls'. */
208 QString longname() const { return mLongname; }
210 void setLinkDestination(const QString& target)
211 { mLinkDestination = target; }
213 QString linkDestination()
214 { return mLinkDestination; }
216 /** Sets the actual type a symbolic link points to. */
217 void setLinkType (mode_t type) { mLinkType = type; }
219 mode_t linkType() const { return mLinkType; }
221 /** No descriptions */
222 void setFilename(const QString& fn)
223 { mFilename = fn; }
225 QString filename() const
226 { return mFilename; }
228 /** Returns a UDSEntry describing the file.
229 The UDSEntry is generated from the sftp file attributes. */
230 KIO::UDSEntry entry();
232 /** Use to output the file attributes to a sftp packet
233 This will only write the sftp ATTR structure to the stream.
234 It will never write the filename and longname because the client
235 never sends those to the server. */
236 friend QDataStream& operator<< (QDataStream&, const sftpFileAttr&);
238 /** Use to read a file attribute from a sftp packet.
239 Read this carefully! If the DirAttrs flag is true, this will
240 read the filename, longname, and file attributes from the stream.
241 This is for use with listing directories.
242 If the DirAttrs flag is false, this will only read file attributes
243 from the stream.
244 BY DEFAULT, A NEW INSTANCE HAS DirAttrs == false */
245 friend QDataStream& operator>> (QDataStream&, sftpFileAttr&);
247 /** Parse longname for the owner and group names. */
248 void getUserGroupNames();
250 /** Sets the DirAttrs flag. This flag affects how the >> operator works on data streams. */
251 void setDirAttrsFlag(bool flag){ mDirAttrs = flag; }
253 /** Gets the DirAttrs flag. */
254 bool getDirAttrsFlag() const { return mDirAttrs; }
256 friend kdbgstream& operator<< (kdbgstream& s, sftpFileAttr& a);
257 friend kndbgstream& operator<< (kndbgstream& s, sftpFileAttr& a);
259 /** Returns the file type as determined from the file permissions */
260 mode_t fileType() const;
262 /** Set the encoding of the remote file system */
263 void setEncoding( KRemoteEncoding* encoding );
266 #endif