joachim99@8
|
1 /***************************************************************************
|
joachim99@8
|
2 * Copyright (C) 2003 by Joachim Eibl *
|
joachim99@8
|
3 * joachim.eibl@gmx.de *
|
joachim99@8
|
4 * *
|
joachim99@8
|
5 * This program is free software; you can redistribute it and/or modify *
|
joachim99@8
|
6 * it under the terms of the GNU General Public License as published by *
|
joachim99@8
|
7 * the Free Software Foundation; either version 2 of the License, or *
|
joachim99@8
|
8 * (at your option) any later version. *
|
joachim99@8
|
9 ***************************************************************************/
|
joachim99@8
|
10
|
joachim99@8
|
11 #ifndef FILEACCESS_H
|
joachim99@8
|
12 #define FILEACCESS_H
|
joachim99@8
|
13
|
joachim99@8
|
14 #include <qdialog.h>
|
joachim99@8
|
15 #include <qfileinfo.h>
|
joachim99@8
|
16 #include <kprogress.h>
|
joachim99@8
|
17 #include <kio/job.h>
|
joachim99@8
|
18 #include <kio/jobclasses.h>
|
joachim99@8
|
19 #include <kurldrag.h>
|
joachim99@8
|
20 #include <list>
|
joachim99@8
|
21 #include <qstring.h>
|
joachim99@8
|
22 #include <qdatetime.h>
|
joachim99@8
|
23
|
joachim99@8
|
24 class t_DirectoryList;
|
joachim99@8
|
25
|
joachim99@8
|
26 class FileAccess
|
joachim99@8
|
27 {
|
joachim99@8
|
28 public:
|
joachim99@8
|
29 FileAccess();
|
joachim99@8
|
30 ~FileAccess();
|
joachim99@8
|
31 FileAccess( const QString& name, bool bWantToWrite=false ); // name: local file or dirname or url (when supported)
|
joachim99@8
|
32 void setFile( const QString& name, bool bWantToWrite=false );
|
joachim99@8
|
33
|
joachim99@8
|
34 bool isValid() const;
|
joachim99@8
|
35 bool isFile() const;
|
joachim99@8
|
36 bool isDir() const;
|
joachim99@8
|
37 bool isSymLink() const;
|
joachim99@8
|
38 bool exists() const;
|
joachim99@8
|
39 long size() const; // Size as returned by stat().
|
joachim99@8
|
40 long sizeForReading(); // If the size can't be determined by stat() then the file is copied to a local temp file.
|
joachim99@8
|
41 bool isReadable() const;
|
joachim99@8
|
42 bool isWritable() const;
|
joachim99@8
|
43 bool isExecutable() const;
|
joachim99@8
|
44 bool isHidden() const;
|
joachim99@8
|
45 QString readLink() const;
|
joachim99@8
|
46
|
joachim99@8
|
47 QDateTime created() const;
|
joachim99@8
|
48 QDateTime lastModified() const;
|
joachim99@8
|
49 QDateTime lastRead() const;
|
joachim99@8
|
50
|
joachim99@8
|
51 QString fileName() const; // Just the name-part of the path, without parent directories
|
joachim99@8
|
52 QString filePath() const; // The path-string that was used during construction
|
joachim99@8
|
53 QString prettyAbsPath() const;
|
joachim99@8
|
54 KURL url() const;
|
joachim99@8
|
55 QString absFilePath() const;
|
joachim99@8
|
56
|
joachim99@8
|
57 bool isLocal() const;
|
joachim99@8
|
58
|
joachim99@8
|
59 bool readFile(void* pDestBuffer, unsigned long maxLength );
|
joachim99@8
|
60 bool writeFile(void* pSrcBuffer, unsigned long length );
|
joachim99@8
|
61 bool listDir( t_DirectoryList* pDirList, bool bRecursive, bool bFindHidden,
|
joachim99@8
|
62 const QString& filePattern, const QString& fileAntiPattern,
|
joachim99@8
|
63 const QString& dirAntiPattern, bool bFollowDirLinks, bool bUseCvsIgnore );
|
joachim99@8
|
64 bool copyFile( const QString& destUrl );
|
joachim99@8
|
65 bool createBackup( const QString& bakExtension );
|
joachim99@8
|
66
|
joachim99@8
|
67 static QString tempFileName();
|
joachim99@8
|
68 bool removeFile();
|
joachim99@8
|
69 static bool removeFile( const QString& );
|
joachim99@8
|
70 static bool makeDir( const QString& );
|
joachim99@8
|
71 static bool removeDir( const QString& );
|
joachim99@8
|
72 static bool exists( const QString& );
|
joachim99@8
|
73 static QString cleanDirPath( const QString& );
|
joachim99@8
|
74
|
joachim99@8
|
75 //bool chmod( const QString& );
|
joachim99@8
|
76 bool rename( const QString& );
|
joachim99@8
|
77 static bool symLink( const QString& linkTarget, const QString& linkLocation );
|
joachim99@8
|
78
|
joachim99@8
|
79 void addPath( const QString& txt );
|
joachim99@8
|
80 QString getStatusText();
|
joachim99@8
|
81 private:
|
joachim99@8
|
82 void setUdsEntry( const KIO::UDSEntry& e );
|
joachim99@8
|
83 KURL m_url;
|
joachim99@8
|
84 bool m_bLocal;
|
joachim99@8
|
85 bool m_bValidData;
|
joachim99@8
|
86
|
joachim99@8
|
87 unsigned long m_size;
|
joachim99@8
|
88 QDateTime m_modificationTime;
|
joachim99@8
|
89 QDateTime m_accessTime;
|
joachim99@8
|
90 QDateTime m_creationTime;
|
joachim99@8
|
91 bool m_bReadable;
|
joachim99@8
|
92 bool m_bWritable;
|
joachim99@8
|
93 bool m_bExecutable;
|
joachim99@8
|
94 bool m_bExists;
|
joachim99@8
|
95 bool m_bFile;
|
joachim99@8
|
96 bool m_bDir;
|
joachim99@8
|
97 bool m_bSymLink;
|
joachim99@8
|
98 bool m_bHidden;
|
joachim99@8
|
99 long m_fileType; // for testing only
|
joachim99@8
|
100
|
joachim99@8
|
101 QString m_linkTarget;
|
joachim99@8
|
102 QString m_user;
|
joachim99@8
|
103 QString m_group;
|
joachim99@8
|
104 QString m_name;
|
joachim99@8
|
105 QString m_path;
|
joachim99@8
|
106 QString m_absFilePath;
|
joachim99@8
|
107 QString m_localCopy;
|
joachim99@8
|
108 QString m_statusText; // Might contain an error string, when the last operation didn't succeed.
|
joachim99@8
|
109
|
joachim99@8
|
110 friend class FileAccessJobHandler;
|
joachim99@8
|
111 };
|
joachim99@8
|
112
|
joachim99@8
|
113 class t_DirectoryList : public std::list<FileAccess>
|
joachim99@8
|
114 {};
|
joachim99@8
|
115
|
joachim99@8
|
116
|
joachim99@8
|
117 class FileAccessJobHandler : public QObject
|
joachim99@8
|
118 {
|
joachim99@8
|
119 Q_OBJECT
|
joachim99@8
|
120 public:
|
joachim99@8
|
121 FileAccessJobHandler( FileAccess* pFileAccess );
|
joachim99@8
|
122
|
joachim99@8
|
123 bool get( void* pDestBuffer, long maxLength );
|
joachim99@8
|
124 bool put( void* pSrcBuffer, long maxLength, bool bOverwrite, bool bResume=false, int permissions=-1 );
|
joachim99@8
|
125 bool stat(int detailLevel=2, bool bWantToWrite=false );
|
joachim99@8
|
126 bool copyFile( const QString& dest );
|
joachim99@8
|
127 bool rename( const QString& dest );
|
joachim99@8
|
128 bool listDir( t_DirectoryList* pDirList, bool bRecursive, bool bFindHidden,
|
joachim99@8
|
129 const QString& filePattern, const QString& fileAntiPattern,
|
joachim99@8
|
130 const QString& dirAntiPattern, bool bFollowDirLinks, bool bUseCvsIgnore );
|
joachim99@8
|
131 bool mkDir( const QString& dirName );
|
joachim99@8
|
132 bool rmDir( const QString& dirName );
|
joachim99@8
|
133 bool removeFile( const QString& dirName );
|
joachim99@8
|
134 bool symLink( const QString& linkTarget, const QString& linkLocation );
|
joachim99@8
|
135
|
joachim99@8
|
136 private:
|
joachim99@8
|
137 FileAccess* m_pFileAccess;
|
joachim99@8
|
138 bool m_bSuccess;
|
joachim99@8
|
139
|
joachim99@8
|
140 // Data needed during Job
|
joachim99@8
|
141 long m_transferredBytes;
|
joachim99@8
|
142 char* m_pTransferBuffer; // Needed during get or put
|
joachim99@8
|
143 long m_maxLength;
|
joachim99@8
|
144
|
joachim99@8
|
145 QString m_filePattern;
|
joachim99@8
|
146 QString m_fileAntiPattern;
|
joachim99@8
|
147 QString m_dirAntiPattern;
|
joachim99@8
|
148 t_DirectoryList* m_pDirList;
|
joachim99@8
|
149 bool m_bFindHidden;
|
joachim99@8
|
150 bool m_bRecursive;
|
joachim99@8
|
151 bool m_bFollowDirLinks;
|
joachim99@8
|
152
|
joachim99@8
|
153 bool scanLocalDirectory( const QString& dirName, t_DirectoryList* dirList );
|
joachim99@8
|
154
|
joachim99@8
|
155 private slots:
|
joachim99@8
|
156 void slotStatResult( KIO::Job* );
|
joachim99@8
|
157 void slotSimpleJobResult( KIO::Job* pJob );
|
joachim99@8
|
158 void slotPutJobResult( KIO::Job* pJob );
|
joachim99@8
|
159
|
joachim99@8
|
160 void slotGetData(KIO::Job*,const QByteArray&);
|
joachim99@8
|
161 void slotPutData(KIO::Job*, QByteArray&);
|
joachim99@8
|
162
|
joachim99@8
|
163 void slotListDirInfoMessage( KIO::Job*, const QString& msg );
|
joachim99@8
|
164 void slotListDirProcessNewEntries( KIO::Job *, const KIO::UDSEntryList& l );
|
joachim99@8
|
165
|
joachim99@8
|
166 void slotPercent( KIO::Job* pJob, unsigned long percent );
|
joachim99@8
|
167 };
|
joachim99@8
|
168
|
joachim99@8
|
169 class ProgressDialog : public QDialog
|
joachim99@8
|
170 {
|
joachim99@8
|
171 Q_OBJECT
|
joachim99@8
|
172 public:
|
joachim99@8
|
173 ProgressDialog( QWidget* pParent );
|
joachim99@8
|
174
|
joachim99@8
|
175 void setInformation( const QString& info, bool bRedrawUpdate=true );
|
joachim99@8
|
176 void setInformation( const QString& info, double dCurrent, bool bRedrawUpdate=true );
|
joachim99@8
|
177 void step( bool bRedrawUpdate=true);
|
joachim99@8
|
178 void setMaximum( int maximum );
|
joachim99@8
|
179
|
joachim99@8
|
180 void setSubInformation(const QString& info, double dSubCurrent, bool bRedrawUpdate=true );
|
joachim99@8
|
181 void setSubCurrent( double dSubCurrent, bool bRedrawUpdate=true );
|
joachim99@8
|
182
|
joachim99@8
|
183 // The progressbar goes from 0 to 1 usually.
|
joachim99@8
|
184 // By supplying a subrange transformation the subCurrent-values
|
joachim99@8
|
185 // 0 to 1 will be transformed to dMin to dMax instead.
|
joachim99@8
|
186 // Requirement: 0 < dMin < dMax < 1
|
joachim99@8
|
187 void setSubRangeTransformation( double dMin, double dMax );
|
joachim99@8
|
188
|
joachim99@8
|
189 void exitEventLoop();
|
joachim99@51
|
190 void enterEventLoop( KIO::Job* pJob, const QString& jobInfo );
|
joachim99@8
|
191
|
joachim99@8
|
192 void start();
|
joachim99@8
|
193
|
joachim99@8
|
194 bool wasCancelled();
|
joachim99@8
|
195 void show();
|
joachim99@8
|
196 void hide();
|
joachim99@51
|
197
|
joachim99@51
|
198 virtual void timerEvent(QTimerEvent*);
|
joachim99@8
|
199 private:
|
joachim99@8
|
200 KProgress* m_pProgressBar;
|
joachim99@8
|
201 KProgress* m_pSubProgressBar;
|
joachim99@8
|
202 QLabel* m_pInformation;
|
joachim99@8
|
203 QLabel* m_pSubInformation;
|
joachim99@51
|
204 QLabel* m_pSlowJobInfo;
|
joachim99@51
|
205 QPushButton* m_pAbortButton;
|
joachim99@8
|
206 int m_maximum;
|
joachim99@8
|
207 double m_dCurrent;
|
joachim99@8
|
208 double m_dSubCurrent;
|
joachim99@8
|
209 double m_dSubMin;
|
joachim99@8
|
210 double m_dSubMax;
|
joachim99@8
|
211 void recalc(bool bRedrawUpdate);
|
joachim99@8
|
212 QTime m_t1;
|
joachim99@8
|
213 QTime m_t2;
|
joachim99@8
|
214 bool m_bWasCancelled;
|
joachim99@51
|
215 KIO::Job* m_pJob;
|
joachim99@51
|
216 QString m_currentJobInfo; // Needed if the job doesn't stop after a reasonable time.
|
joachim99@8
|
217 protected:
|
joachim99@8
|
218 virtual void reject();
|
joachim99@8
|
219 private slots:
|
joachim99@8
|
220 void delayedHide();
|
joachim99@51
|
221 void slotAbort();
|
joachim99@8
|
222 };
|
joachim99@8
|
223
|
joachim99@8
|
224 extern ProgressDialog* g_pProgressDialog;
|
joachim99@8
|
225
|
joachim99@8
|
226
|
joachim99@8
|
227
|
joachim99@8
|
228 #endif
|
joachim99@8
|
229
|