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