KVIrc  4.9.2
DeveloperAPIs
Functions | Variables
KviFileUtils Namespace Reference

A namespace to handle file utilities functions. More...

Functions

void adjustFilePath (QString &szPath)
 Adjusts the file path to the current platform. More...
 
void cleanFileName (QString &szPath)
 Removes any unusable character from a filename (with no path!) More...
 
bool copyFile (const QString &szSrc, const QString &szDst)
 Copy the file (cp -f) More...
 
bool copyFile (const char *pcSrc, const char *pcDst)
 Copy the file (cp -f) More...
 
bool deleteDir (const QString &szPath)
 Removes a dir recursively. More...
 
bool directoryExists (const QString &szPath)
 Returns true if szPath points to an existing directory. More...
 
void encodeFileName (QString &szPath)
 Translates ANY string into a valid filename (with no path!) More...
 
QString extractFileName (const QString &szFileNameWithPath, bool bAllowEmpty=true)
 Extracts the filename from a complete path (strips leading path) More...
 
QString extractFilePath (const QString &szFileNameWithPath)
 Extracts the filename from a complete path (strips leading path) More...
 
bool fileExists (const QString &szPath)
 Returns true if szPath points to an existing file. More...
 
QStringList getFileListing (const QString &szPath)
 
static QStringList getFileListingInternal (const QString &szPath, const QString &szPrefix)
 
bool isAbsolutePath (const QString &szPath)
 Returns true if the path is absolute, false otherwise. More...
 
bool isReadable (const QString &szFname)
 Returns true if the file is readable, false otherwise. More...
 
bool isReadable (const char *pcPath)
 
bool loadFile (const QString &szPath, QString &szBuffer, bool bUtf8=true)
 Loads the file at szPath to szBuffer eventually converting from UTF-8. More...
 
bool makeDir (const QString &szPath)
 Create a directory (mkdir) More...
 
bool makeDir (const char *pcPath)
 Create a directory (mkdir) More...
 
bool readFile (const QString &szPath, QString &szBuffer, unsigned int uMaxSize=65535)
 Reads a complete file and puts it in the string szBuffer. More...
 
bool readFile (const char *pcPath, QString &szBuffer, unsigned int uMaxSize=65535)
 Reads a complete file and puts it in the string szBuffer. More...
 
bool readLine (QFile *pFile, QString &szBuffer, bool bUtf8=true)
 Reads a text line, returns false if EOF is reached. More...
 
bool readLines (QFile *pFile, QStringList &buffer, int iStartLine=0, int iCount=-1, bool bUtf8=true)
 Reads text lines, returns false if EOF is reached. More...
 
bool removeDir (const QString &szPath)
 Removes a dir (must be empty) More...
 
bool removeDir (const char *pcPath)
 Removes a dir (must be empty) More...
 
bool removeFile (const QString &szPath)
 Removes a file. More...
 
bool removeFile (const char *pcPath)
 Removes a file. More...
 
bool renameFile (const QString &szSrc, const QString &szDst)
 Rename or move the file (mv) More...
 
bool renameFile (const char *pcSrc, const char *pcDst)
 Rename or move the file (mv) More...
 
bool writeFile (const QString &szPath, const QByteArray &oData, bool bAppend=false)
 Writes a complete file (UTF-8 version) More...
 
bool writeFile (const QString &szPath, const QString &szData, bool bAppend=false)
 Writes a complete file (UTF-8 version) More...
 
bool writeFile (const char *pcPath, const QString &szData, bool bAppend=false)
 Writes a complete file (UTF-8 version) More...
 
bool writeFileLocal8Bit (const QString &szPath, const QString &szData, bool bAppend=false)
 Writes a complete file (local 8 bit version) More...
 
bool writeFileLocal8Bit (const char *pcPath, const QString &szData, bool bAppend=false)
 Writes a complete file (local 8 bit version) More...
 

Variables

static char cHexChars [16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }
 

Detailed Description

A namespace to handle file utilities functions.

Function Documentation

KVILIB_API void KviFileUtils::adjustFilePath ( QString &  szPath)
KVILIB_API void KviFileUtils::cleanFileName ( QString &  szPath)

Removes any unusable character from a filename (with no path!)

There is NO way to come back to the original string the algo is one-way only

Parameters
szPath
Returns
void

References i.

Referenced by DccBroker::chooseSaveFileName(), and KviWindow::getDefaultLogFileName().

KVILIB_API bool KviFileUtils::copyFile ( const QString &  szSrc,
const QString &  szDst 
)

Copy the file (cp -f)

Parameters
szSrcThe source file
szDstThe destination file
Returns
bool

Referenced by addon_kvs_cmd_installfiles(), OptionsWidget_textIcons::chooseFromFile(), copyFile(), LogViewWindow::createLog(), file_kvs_cmd_copy(), and KviTheme::save().

KVILIB_API bool KviFileUtils::copyFile ( const char *  pcSrc,
const char *  pcDst 
)

Copy the file (cp -f)

Parameters
pcSrcThe source file
pcDstThe destination file
Returns
bool

References copyFile().

KVILIB_API bool KviFileUtils::deleteDir ( const QString &  szPath)

Removes a dir recursively.

Parameters
szPathThe path of the directory to remove
Returns
bool

References d, KviQString::equalCS(), Hidden, removeDir(), and removeFile().

Referenced by ThemeManagementDialog::deleteTheme(), AddonFunctions::installAddonPackage(), and package_kvs_fnc_info().

KVILIB_API bool KviFileUtils::directoryExists ( const QString &  szPath)
KVILIB_API void KviFileUtils::encodeFileName ( QString &  szPath)

Translates ANY string into a valid filename (with no path!)

There is NO way to come back to the original string the algo is one-way only

Parameters
szPath
Returns
void

References cHexChars, and i.

Referenced by KviWindow::getDefaultLogFileName().

KVILIB_API QString KviFileUtils::extractFileName ( const QString &  szFileNameWithPath,
bool  bAllowEmpty = true 
)

Extracts the filename from a complete path (strips leading path)

Extracts the filename from a complete path (strips leading path). If szFileNameWithPath ends with a trailing slash/backslash then if bAllowEmpty is set to true then the name is considered to be empty, if bAllowEmpty is set to false then the trailing slash/backslash is stripped.

Parameters
szFileNameWithPathThe complete path to the file
Returns
QString

References KVI_PATH_SEPARATOR.

Referenced by KviConsoleWindow::checkDefaultAvatar(), file_kvs_fnc_extractfilename(), PluginManager::findPlugin(), KviIconManager::getAvatar(), Plugin::load(), KviThemeInfo::setDirectoryAndLocation(), and SetupWizard::SetupWizard().

KVILIB_API QString KviFileUtils::extractFilePath ( const QString &  szFileNameWithPath)

Extracts the filename from a complete path (strips leading path)

Parameters
szFileNameWithPathThe complete path
Returns
QString

Referenced by SetupWizard::SetupWizard().

bool KviFileUtils::fileExists ( const QString &  szPath)
inline
KVILIB_API QStringList KviFileUtils::getFileListing ( const QString &  szPath)

Build a recursive file listing

References getFileListingInternal().

Referenced by package_kvs_fnc_info().

static QStringList KviFileUtils::getFileListingInternal ( const QString &  szPath,
const QString &  szPrefix 
)
static

References d, and KVI_PATH_SEPARATOR.

Referenced by getFileListing().

KVILIB_API bool KviFileUtils::isAbsolutePath ( const QString &  szPath)

Returns true if the path is absolute, false otherwise.

Parameters
szPathThe path to check
Returns
bool

References f.

Referenced by config_kvs_fnc_id(), config_kvs_fnc_open(), KviApplication::findAudioFile(), KviApplication::findImage(), KviMediaManager::findMediaType(), PluginManager::findPlugin(), and KviApplication::mapImageFile().

KVILIB_API bool KviFileUtils::isReadable ( const QString &  szFname)

Returns true if the file is readable, false otherwise.

Parameters
szFnameThe source file
Returns
bool

References f.

Referenced by KviApplication::checkGlobalKvircDirectory(), isReadable(), and sharedfile_kvs_cmd_add().

bool KviFileUtils::isReadable ( const char *  pcPath)

References isReadable().

KVILIB_API bool KviFileUtils::loadFile ( const QString &  szPath,
QString &  szBuffer,
bool  bUtf8 = true 
)

Loads the file at szPath to szBuffer eventually converting from UTF-8.

Parameters
szPathThe path to the file to load
szBufferThe buffer where to load the file
bUtf8Where to convert from UTF-8
Returns
bool

References f.

Referenced by AboutDialog::AboutDialog(), KviKvsCoreSimpleCommands::KVSCSC(), ScriptEditorImplementation::loadFromFile(), and SetupWizard::SetupWizard().

KVILIB_API bool KviFileUtils::makeDir ( const QString &  szPath)
KVILIB_API bool KviFileUtils::makeDir ( const char *  pcPath)

Create a directory (mkdir)

Parameters
pcPathThe path to the directory
Returns
bool

References makeDir().

KVILIB_API bool KviFileUtils::readFile ( const QString &  szPath,
QString &  szBuffer,
unsigned int  uMaxSize = 65535 
)

Reads a complete file and puts it in the string szBuffer.

The file must be smaller than uMaxSize bytes

Parameters
szPathThe path to the file to read
szBufferThe buffer where to load the file
uMaxSizeThe maximum size of the file to read
Returns
bool

References f.

Referenced by KviLocale::KviLocale(), KviKvsObjectClass::load(), readFile(), and KviApplication::setup().

KVILIB_API bool KviFileUtils::readFile ( const char *  pcPath,
QString &  szBuffer,
unsigned int  uMaxSize = 65535 
)

Reads a complete file and puts it in the string szBuffer.

The file must be smaller than uMaxSize bytes

Parameters
pcPathThe path to the file to read
szBufferThe buffer where to load the file
uMaxSizeThe maximum size of the file to read
Returns
bool

References readFile().

KVILIB_API bool KviFileUtils::readLine ( QFile *  pFile,
QString &  szBuffer,
bool  bUtf8 = true 
)

Reads a text line, returns false if EOF is reached.

Parameters
pFileThe source file
szBufferThe buffer where to store the line read
bUtf8If we want to convert from UTF-8
Returns
bool
KVILIB_API bool KviFileUtils::readLines ( QFile *  pFile,
QStringList &  buffer,
int  iStartLine = 0,
int  iCount = -1,
bool  bUtf8 = true 
)

Reads text lines, returns false if EOF is reached.

Parameters
pFileThe source file
bufferThe buffer where to store the lines read
iStartLineThe number of the first line to read
iCountThe number of lines to read
bUtf8If we want to convert from UTF-8
Returns
bool

References i.

KVILIB_API bool KviFileUtils::removeDir ( const QString &  szPath)

Removes a dir (must be empty)

Parameters
szPathThe directory to remove
Returns
bool

References d.

Referenced by deleteDir(), file_kvs_cmd_rmdir(), and removeDir().

KVILIB_API bool KviFileUtils::removeDir ( const char *  pcPath)

Removes a dir (must be empty)

Parameters
pcPathThe directory to remove
Returns
bool

References removeDir().

KVILIB_API bool KviFileUtils::removeFile ( const QString &  szPath)
KVILIB_API bool KviFileUtils::removeFile ( const char *  pcPath)

Removes a file.

Parameters
pcPathThe file to remove
Returns
bool

References removeFile().

KVILIB_API bool KviFileUtils::renameFile ( const QString &  szSrc,
const QString &  szDst 
)

Rename or move the file (mv)

Parameters
szSrcThe source file
szDstThe destination file
Returns
bool

References d.

Referenced by file_kvs_cmd_rename(), and renameFile().

KVILIB_API bool KviFileUtils::renameFile ( const char *  pcSrc,
const char *  pcDst 
)

Rename or move the file (mv)

Parameters
pcSrcThe source file
pcDstThe destination file
Returns
bool

References renameFile().

KVILIB_API bool KviFileUtils::writeFile ( const QString &  szPath,
const QByteArray &  oData,
bool  bAppend = false 
)
KVILIB_API bool KviFileUtils::writeFile ( const QString &  szPath,
const QString &  szData,
bool  bAppend = false 
)

Writes a complete file (UTF-8 version)

Parameters
szPathThe path to the file
szDataThe data to write
bAppendIf we want to append data or overwrite
Returns
bool

References f.

KVILIB_API bool KviFileUtils::writeFile ( const char *  pcPath,
const QString &  szData,
bool  bAppend = false 
)

Writes a complete file (UTF-8 version)

Parameters
pcPathThe path to the file
szDataThe data to write
bAppendIf we want to append data or overwrite
Returns
bool

References writeFile().

KVILIB_API bool KviFileUtils::writeFileLocal8Bit ( const QString &  szPath,
const QString &  szData,
bool  bAppend = false 
)

Writes a complete file (local 8 bit version)

Parameters
szPathThe path to the file
szDataThe data to write
bAppendIf we want to append data or overwrite
Returns
bool

References f.

Referenced by file_kvs_cmd_write(), and writeFileLocal8Bit().

KVILIB_API bool KviFileUtils::writeFileLocal8Bit ( const char *  pcPath,
const QString &  szData,
bool  bAppend = false 
)

Writes a complete file (local 8 bit version)

Parameters
pcPathThe path to the file
szDataThe data to write
bAppendIf we want to append data or overwrite
Returns
bool

References writeFileLocal8Bit().

Variable Documentation

char KviFileUtils::cHexChars[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }
static

Referenced by encodeFileName().