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