joachim99@8: /*************************************************************************** joachim99@8: * Copyright (C) 2003 by Joachim Eibl * joachim99@8: * joachim.eibl@gmx.de * joachim99@8: * * joachim99@8: * This program is free software; you can redistribute it and/or modify * joachim99@8: * it under the terms of the GNU General Public License as published by * joachim99@8: * the Free Software Foundation; either version 2 of the License, or * joachim99@8: * (at your option) any later version. * joachim99@8: ***************************************************************************/ joachim99@8: joachim99@8: #ifndef FILEACCESS_H joachim99@8: #define FILEACCESS_H joachim99@8: joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: joachim99@8: class t_DirectoryList; joachim99@8: joachim99@8: class FileAccess joachim99@8: { joachim99@8: public: joachim99@8: FileAccess(); joachim99@8: ~FileAccess(); joachim99@8: FileAccess( const QString& name, bool bWantToWrite=false ); // name: local file or dirname or url (when supported) joachim99@8: void setFile( const QString& name, bool bWantToWrite=false ); joachim99@8: joachim99@8: bool isValid() const; joachim99@8: bool isFile() const; joachim99@8: bool isDir() const; joachim99@8: bool isSymLink() const; joachim99@8: bool exists() const; joachim99@8: long size() const; // Size as returned by stat(). joachim99@8: long sizeForReading(); // If the size can't be determined by stat() then the file is copied to a local temp file. joachim99@8: bool isReadable() const; joachim99@8: bool isWritable() const; joachim99@8: bool isExecutable() const; joachim99@8: bool isHidden() const; joachim99@8: QString readLink() const; joachim99@8: joachim99@8: QDateTime created() const; joachim99@8: QDateTime lastModified() const; joachim99@8: QDateTime lastRead() const; joachim99@8: joachim99@8: QString fileName() const; // Just the name-part of the path, without parent directories joachim99@8: QString filePath() const; // The path-string that was used during construction joachim99@8: QString prettyAbsPath() const; joachim99@8: KURL url() const; joachim99@8: QString absFilePath() const; joachim99@8: joachim99@8: bool isLocal() const; joachim99@8: joachim99@8: bool readFile(void* pDestBuffer, unsigned long maxLength ); joachim99@58: bool writeFile(const void* pSrcBuffer, unsigned long length ); joachim99@8: bool listDir( t_DirectoryList* pDirList, bool bRecursive, bool bFindHidden, joachim99@8: const QString& filePattern, const QString& fileAntiPattern, joachim99@8: const QString& dirAntiPattern, bool bFollowDirLinks, bool bUseCvsIgnore ); joachim99@8: bool copyFile( const QString& destUrl ); joachim99@8: bool createBackup( const QString& bakExtension ); joachim99@8: joachim99@8: static QString tempFileName(); joachim99@8: bool removeFile(); joachim99@8: static bool removeFile( const QString& ); joachim99@8: static bool makeDir( const QString& ); joachim99@8: static bool removeDir( const QString& ); joachim99@8: static bool exists( const QString& ); joachim99@8: static QString cleanDirPath( const QString& ); joachim99@8: joachim99@8: //bool chmod( const QString& ); joachim99@8: bool rename( const QString& ); joachim99@8: static bool symLink( const QString& linkTarget, const QString& linkLocation ); joachim99@8: joachim99@8: void addPath( const QString& txt ); joachim99@8: QString getStatusText(); joachim99@8: private: joachim99@8: void setUdsEntry( const KIO::UDSEntry& e ); joachim99@8: KURL m_url; joachim99@8: bool m_bLocal; joachim99@8: bool m_bValidData; joachim99@8: joachim99@8: unsigned long m_size; joachim99@8: QDateTime m_modificationTime; joachim99@8: QDateTime m_accessTime; joachim99@8: QDateTime m_creationTime; joachim99@8: bool m_bReadable; joachim99@8: bool m_bWritable; joachim99@8: bool m_bExecutable; joachim99@8: bool m_bExists; joachim99@8: bool m_bFile; joachim99@8: bool m_bDir; joachim99@8: bool m_bSymLink; joachim99@8: bool m_bHidden; joachim99@8: long m_fileType; // for testing only joachim99@8: joachim99@8: QString m_linkTarget; joachim99@8: QString m_user; joachim99@8: QString m_group; joachim99@8: QString m_name; joachim99@8: QString m_path; joachim99@8: QString m_absFilePath; joachim99@8: QString m_localCopy; joachim99@8: QString m_statusText; // Might contain an error string, when the last operation didn't succeed. joachim99@8: joachim99@8: friend class FileAccessJobHandler; joachim99@8: }; joachim99@8: joachim99@8: class t_DirectoryList : public std::list joachim99@8: {}; joachim99@8: joachim99@8: joachim99@8: class FileAccessJobHandler : public QObject joachim99@8: { joachim99@8: Q_OBJECT joachim99@8: public: joachim99@8: FileAccessJobHandler( FileAccess* pFileAccess ); joachim99@8: joachim99@8: bool get( void* pDestBuffer, long maxLength ); joachim99@58: bool put( const void* pSrcBuffer, long maxLength, bool bOverwrite, bool bResume=false, int permissions=-1 ); joachim99@8: bool stat(int detailLevel=2, bool bWantToWrite=false ); joachim99@8: bool copyFile( const QString& dest ); joachim99@8: bool rename( const QString& dest ); joachim99@8: bool listDir( t_DirectoryList* pDirList, bool bRecursive, bool bFindHidden, joachim99@8: const QString& filePattern, const QString& fileAntiPattern, joachim99@8: const QString& dirAntiPattern, bool bFollowDirLinks, bool bUseCvsIgnore ); joachim99@8: bool mkDir( const QString& dirName ); joachim99@8: bool rmDir( const QString& dirName ); joachim99@8: bool removeFile( const QString& dirName ); joachim99@8: bool symLink( const QString& linkTarget, const QString& linkLocation ); joachim99@8: joachim99@8: private: joachim99@8: FileAccess* m_pFileAccess; joachim99@8: bool m_bSuccess; joachim99@8: joachim99@8: // Data needed during Job joachim99@8: long m_transferredBytes; joachim99@8: char* m_pTransferBuffer; // Needed during get or put joachim99@8: long m_maxLength; joachim99@8: joachim99@8: QString m_filePattern; joachim99@8: QString m_fileAntiPattern; joachim99@8: QString m_dirAntiPattern; joachim99@8: t_DirectoryList* m_pDirList; joachim99@8: bool m_bFindHidden; joachim99@8: bool m_bRecursive; joachim99@8: bool m_bFollowDirLinks; joachim99@8: joachim99@8: bool scanLocalDirectory( const QString& dirName, t_DirectoryList* dirList ); joachim99@8: joachim99@8: private slots: joachim99@8: void slotStatResult( KIO::Job* ); joachim99@8: void slotSimpleJobResult( KIO::Job* pJob ); joachim99@8: void slotPutJobResult( KIO::Job* pJob ); joachim99@8: joachim99@8: void slotGetData(KIO::Job*,const QByteArray&); joachim99@8: void slotPutData(KIO::Job*, QByteArray&); joachim99@8: joachim99@8: void slotListDirInfoMessage( KIO::Job*, const QString& msg ); joachim99@8: void slotListDirProcessNewEntries( KIO::Job *, const KIO::UDSEntryList& l ); joachim99@8: joachim99@8: void slotPercent( KIO::Job* pJob, unsigned long percent ); joachim99@8: }; joachim99@8: joachim99@8: class ProgressDialog : public QDialog joachim99@8: { joachim99@8: Q_OBJECT joachim99@8: public: joachim99@8: ProgressDialog( QWidget* pParent ); joachim99@8: joachim99@8: void setInformation( const QString& info, bool bRedrawUpdate=true ); joachim99@8: void setInformation( const QString& info, double dCurrent, bool bRedrawUpdate=true ); joachim99@8: void step( bool bRedrawUpdate=true); joachim99@8: void setMaximum( int maximum ); joachim99@8: joachim99@8: void setSubInformation(const QString& info, double dSubCurrent, bool bRedrawUpdate=true ); joachim99@8: void setSubCurrent( double dSubCurrent, bool bRedrawUpdate=true ); joachim99@8: joachim99@8: // The progressbar goes from 0 to 1 usually. joachim99@8: // By supplying a subrange transformation the subCurrent-values joachim99@8: // 0 to 1 will be transformed to dMin to dMax instead. joachim99@8: // Requirement: 0 < dMin < dMax < 1 joachim99@8: void setSubRangeTransformation( double dMin, double dMax ); joachim99@8: joachim99@8: void exitEventLoop(); joachim99@51: void enterEventLoop( KIO::Job* pJob, const QString& jobInfo ); joachim99@8: joachim99@8: void start(); joachim99@8: joachim99@8: bool wasCancelled(); joachim99@8: void show(); joachim99@8: void hide(); joachim99@51: joachim99@51: virtual void timerEvent(QTimerEvent*); joachim99@8: private: joachim99@8: KProgress* m_pProgressBar; joachim99@8: KProgress* m_pSubProgressBar; joachim99@8: QLabel* m_pInformation; joachim99@8: QLabel* m_pSubInformation; joachim99@51: QLabel* m_pSlowJobInfo; joachim99@51: QPushButton* m_pAbortButton; joachim99@8: int m_maximum; joachim99@8: double m_dCurrent; joachim99@8: double m_dSubCurrent; joachim99@8: double m_dSubMin; joachim99@8: double m_dSubMax; joachim99@8: void recalc(bool bRedrawUpdate); joachim99@8: QTime m_t1; joachim99@8: QTime m_t2; joachim99@8: bool m_bWasCancelled; joachim99@51: KIO::Job* m_pJob; joachim99@51: QString m_currentJobInfo; // Needed if the job doesn't stop after a reasonable time. joachim99@8: protected: joachim99@8: virtual void reject(); joachim99@8: private slots: joachim99@8: void delayedHide(); joachim99@51: void slotAbort(); joachim99@8: }; joachim99@8: joachim99@8: extern ProgressDialog* g_pProgressDialog; joachim99@8: joachim99@8: joachim99@8: joachim99@8: #endif joachim99@8: