annotate kdiff3/src-QT4/fileaccess.h @ 113:7bca1f1340f6 tip

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