KVIrc 5.2.4
Developer APIs
KviFileUtils.h
Go to the documentation of this file.
1#ifndef _KVI_FILEUTILS_H_
2#define _KVI_FILEUTILS_H_
3//=============================================================================
4//
5// File : KviFileUtils.h
6// Creation date : Fri Dec 25 1998 18:27:04 by Szymon Stefanek
7//
8// This file is part of the KVIrc IRC client distribution
9// Copyright (C) 1998-2010 Szymon Stefanek (pragma at kvirc dot net)
10//
11// This program is FREE software. You can redistribute it and/or
12// modify it under the terms of the GNU General Public License
13// as published by the Free Software Foundation; either version 2
14// of the License, or (at your option) any later version.
15//
16// This program is distributed in the HOPE that it will be USEFUL,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19// See the GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program. If not, write to the Free Software Foundation,
23// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24//
25//=============================================================================
26
36#include "kvi_settings.h"
37
38#include <QFile>
39
40class QByteArray;
41class QString;
42#include <QStringList>
43
44#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
45#define KVI_PATH_SEPARATOR "\\"
46#define KVI_PATH_SEPARATOR_CHAR '\\'
47#else
48#define KVI_PATH_SEPARATOR "/"
49#define KVI_PATH_SEPARATOR_CHAR '/'
50#endif
51
52// #warning "Add kvi_trashFile(const char * path) ? - is it needed in the whole app"
53// #warning "or should it be available only for dirbrowser module?"
58namespace KviFileUtils
59{
60 //KVILIB_API bool readLine(QFile * f,QString &szBuffer,bool bClearBuffer = true);
61 //KVILIB_API bool loadFileStripCR(const QString &szPath,QString &szBuffer);
62
70 KVILIB_API bool loadFile(const QString & szPath, QString & szBuffer, bool bUtf8 = true);
71
77 KVILIB_API void adjustFilePath(QString & szPath);
78
84 KVILIB_API bool directoryExists(const QString & szPath);
85
91 inline bool fileExists(const QString & szPath) { return QFile::exists(szPath); }
92
98 KVILIB_API bool removeFile(const QString & szPath);
99
105 KVILIB_API bool removeFile(const char * pcPath);
106
112 KVILIB_API bool removeDir(const QString & szPath);
113
119 KVILIB_API bool removeDir(const char * pcPath);
120
126 KVILIB_API bool deleteDir(const QString & szPath);
127
135 KVILIB_API bool writeFile(const QString & szPath, const QByteArray & oData, bool bAppend = false);
136
144 KVILIB_API bool writeFile(const QString & szPath, const QString & szData, bool bAppend = false);
145
153 KVILIB_API bool writeFile(const char * pcPath, const QString & szData, bool bAppend = false);
154
162 KVILIB_API bool writeFileLocal8Bit(const QString & szPath, const QString & szData, bool bAppend = false);
163
171 KVILIB_API bool writeFileLocal8Bit(const char * pcPath, const QString & szData, bool bAppend = false);
172
182 KVILIB_API bool readFile(const QString & szPath, QString & szBuffer, unsigned int uMaxSize = 65535);
183
193 KVILIB_API bool readFile(const char * pcPath, QString & szBuffer, unsigned int uMaxSize = 65535);
194
206 KVILIB_API QString extractFileName(const QString & szFileNameWithPath, bool bAllowEmpty = true);
207
213 KVILIB_API QString extractFilePath(const QString & szFileNameWithPath);
214
221 KVILIB_API bool copyFile(const QString & szSrc, const QString & szDst);
222
229 KVILIB_API bool copyFile(const char * pcSrc, const char * pcDst);
230
237 KVILIB_API bool renameFile(const QString & szSrc, const QString & szDst);
238
245 KVILIB_API bool renameFile(const char * pcSrc, const char * pcDst);
246
252 KVILIB_API bool makeDir(const QString & szPath);
253
259 KVILIB_API bool makeDir(const char * pcPath);
260
268 KVILIB_API bool readLine(QFile * pFile, QString & szBuffer, bool bUtf8 = true);
269
279 KVILIB_API bool readLines(QFile * pFile, QStringList & buffer, int iStartLine = 0, int iCount = -1, bool bUtf8 = true);
280
286 KVILIB_API bool isReadable(const QString & szFname);
287
293 KVILIB_API bool isAbsolutePath(const QString & szPath);
294
303 KVILIB_API void encodeFileName(QString & szPath);
304
313 KVILIB_API void cleanFileName(QString & szPath);
314
318 KVILIB_API QStringList getFileListing(const QString & szPath);
319}
320
321#endif //_KVI_FILEUTILS_H
This file contains compile time settings.
#define KVILIB_API
Definition kvi_settings.h:124
A namespace to handle file utilities functions.
Definition KviFileUtils.cpp:45
void encodeFileName(QString &szPath)
Translates ANY string into a valid filename (with no path!)
Definition KviFileUtils.cpp:405
bool readFile(const QString &szPath, QString &szBuffer, unsigned int uMaxSize)
Reads a complete file and puts it in the string szBuffer.
Definition KviFileUtils.cpp:288
bool isAbsolutePath(const QString &szPath)
Returns true if the path is absolute, false otherwise.
Definition KviFileUtils.cpp:399
bool writeFileLocal8Bit(const QString &szPath, const QString &szData, bool bAppend)
Writes a complete file (local 8 bit version)
Definition KviFileUtils.cpp:265
bool writeFile(const QString &szPath, const QByteArray &oData, bool bAppend)
Writes a complete file (UTF-8 version)
Definition KviFileUtils.cpp:236
bool readLine(QFile *pFile, QString &szBuffer, bool bUtf8)
Reads a text line, returns false if EOF is reached.
Definition KviFileUtils.cpp:336
bool deleteDir(const QString &szPath)
Removes a dir recursively.
Definition KviFileUtils.cpp:201
QString extractFileName(const QString &szFileNameWithPath, bool bAllowEmpty)
Extracts the filename from a complete path (strips leading path)
Definition KviFileUtils.cpp:321
QString extractFilePath(const QString &szFileNameWithPath)
Extracts the filename from a complete path (strips leading path)
Definition KviFileUtils.cpp:331
bool loadFile(const QString &szPath, QString &szBuffer, bool bUtf8)
Loads the file at szPath to szBuffer eventually converting from UTF-8.
Definition KviFileUtils.cpp:136
void cleanFileName(QString &szPath)
Removes any unusable character from a filename (with no path!)
Definition KviFileUtils.cpp:435
QStringList getFileListing(const QString &szPath)
Definition KviFileUtils.cpp:483
void adjustFilePath(QString &szPath)
Adjusts the file path to the current platform.
Definition KviFileUtils.cpp:154
bool renameFile(const QString &szSrc, const QString &szDst)
Rename or move the file (mv)
Definition KviFileUtils.cpp:88
bool copyFile(const QString &szSrc, const QString &szDst)
Copy the file (cp -f)
Definition KviFileUtils.cpp:101
bool directoryExists(const QString &szPath)
Returns true if szPath points to an existing directory.
Definition KviFileUtils.cpp:381
bool removeFile(const QString &szPath)
Removes a file.
Definition KviFileUtils.cpp:177
bool fileExists(const QString &szPath)
Returns true if szPath points to an existing file.
Definition KviFileUtils.h:91
bool makeDir(const QString &szPath)
Create a directory (mkdir)
Definition KviFileUtils.cpp:48
bool readLines(QFile *pFile, QStringList &buffer, int iStartLine, int iCount, bool bUtf8)
Reads text lines, returns false if EOF is reached.
Definition KviFileUtils.cpp:353
bool removeDir(const QString &szPath)
Removes a dir (must be empty)
Definition KviFileUtils.cpp:189
bool isReadable(const QString &szFname)
Returns true if the file is readable, false otherwise.
Definition KviFileUtils.cpp:387
char szBuffer[4096]
Definition winamp.cpp:77