diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/kvilib/config/kvi_shortcuts.h | 20 | ||||
| -rw-r--r-- | src/kvilib/ext/kvi_config.cpp | 18 | ||||
| -rw-r--r-- | src/kvilib/ext/kvi_mediatype.cpp | 4 | ||||
| -rw-r--r-- | src/kvilib/file/kvi_file.cpp | 45 | ||||
| -rw-r--r-- | src/kvilib/file/kvi_file.h | 236 | ||||
| -rw-r--r-- | src/kvilib/file/kvi_fileutils.cpp | 22 | ||||
| -rw-r--r-- | src/kvilib/file/kvi_packagefile.cpp | 40 | ||||
| -rw-r--r-- | src/kvilib/net/kvi_http.cpp | 10 | ||||
| -rw-r--r-- | src/kvilib/system/kvi_locale.cpp | 6 | ||||
| -rw-r--r-- | src/modules/file/libkvifile.cpp | 15 | ||||
| -rw-r--r-- | src/modules/objects/class_file.h | 4 | ||||
| -rw-r--r-- | src/modules/objects/class_memorybuffer.cpp | 18 | ||||
| -rw-r--r-- | src/modules/objects/class_socket.cpp | 2 | ||||
| -rw-r--r-- | src/modules/reguser/dialog.cpp | 4 |
14 files changed, 302 insertions, 142 deletions
diff --git a/src/kvilib/config/kvi_shortcuts.h b/src/kvilib/config/kvi_shortcuts.h index 9d3092480..4d4926333 100644 --- a/src/kvilib/config/kvi_shortcuts.h +++ b/src/kvilib/config/kvi_shortcuts.h @@ -93,7 +93,7 @@ CursorLeft:[/b] Move the cursor to the left :)[br] Shift+CursorLeft:[/b] Move the selection to the left[br] Shift+RightCursor:[/b] Move the selection to the right[br] - Alt+Enter:[/b] Show/hide the multiline editor[br] +* \def KVI_SHORTCUTS_MULTILINE Show/hide the multiline editor Ctrl+Enter:[/b] Send message as plain text, ignoring / commands[br] Alt+<numeric_sequence>:[/b] Insert the character by ASCII/Unicode code[br] [example] @@ -143,14 +143,14 @@ #define KVI_SHORTCUTS_THEME "Ctrl+Shift+T" #define KVI_SHORTCUTS_USERS "Ctrl+Shift+U" #define KVI_SHORTCUTS_EXEC "Ctrl+Shift+X" -#define KVI_SHORTCUTS_WIN_PREV Qt::ALT + Qt::Key_Up -#define KVI_SHORTCUTS_WIN_NEXT Qt::ALT + Qt::Key_Down -#define KVI_SHORTCUTS_CONTEXT_WIN_PREV Qt::ALT + Qt::SHIFT + Qt::Key_Up -#define KVI_SHORTCUTS_CONTEXT_WIN_NEXT Qt::ALT + Qt::SHIFT + Qt::Key_Down -#define KVI_SHORTCUTS_HIGHLIGHT_WIN_PREV Qt::ALT + Qt::Key_PageUp -#define KVI_SHORTCUTS_HIGHLIGHT_WIN_NEXT Qt::ALT + Qt::Key_PageDown -#define KVI_SHORTCUTS_WIN_MAXIMIZE Qt::CTRL + Qt::Key_Up -#define KVI_SHORTCUTS_WIN_MINIMIZE Qt::CTRL + Qt::Key_Down +#define KVI_SHORTCUTS_WIN_PREV Qt::AltModifier + Qt::Key_Up +#define KVI_SHORTCUTS_WIN_NEXT Qt::AltModifier + Qt::Key_Down +#define KVI_SHORTCUTS_CONTEXT_WIN_PREV Qt::AltModifier + Qt::ShiftModifier + Qt::Key_Up +#define KVI_SHORTCUTS_CONTEXT_WIN_NEXT Qt::AltModifier + Qt::ShiftModifier + Qt::Key_Down +#define KVI_SHORTCUTS_HIGHLIGHT_WIN_PREV Qt::AltModifier + Qt::Key_PageUp +#define KVI_SHORTCUTS_HIGHLIGHT_WIN_NEXT Qt::AltModifier + Qt::Key_PageDown +#define KVI_SHORTCUTS_WIN_MAXIMIZE Qt::ControlModifier + Qt::Key_Up +#define KVI_SHORTCUTS_WIN_MINIMIZE Qt::ControlModifier + Qt::Key_Down // Shift+<F1-F12>:[/b] window switch[br] // PageUp:[/b] Scroll the output window up one page[br] // PageDown:[/b] Scroll the output window down one page[br] @@ -169,7 +169,7 @@ // CursorLeft:[/b] Move the cursor to the left :)[br] // Shift+CursorLeft:[/b] Move the selection to the left[br] // Shift+RightCursor:[/b] Move the selection to the right[br] -// Alt+Enter:[/b] Show/hide the multiline editor[br] +#define KVI_SHORTCUTS_MULTILINE Qt::AltModifier + Qt::Key_Return // Ctrl+Enter:[/b] Send message as plain text, ignoring / commands[br] // Alt+<numeric_sequence>:[/b] Insert the character by ASCII/Unicode code[br] // [example] diff --git a/src/kvilib/ext/kvi_config.cpp b/src/kvilib/ext/kvi_config.cpp index 1c1c248b0..85a59dbca 100644 --- a/src/kvilib/ext/kvi_config.cpp +++ b/src/kvilib/ext/kvi_config.cpp @@ -136,7 +136,7 @@ bool KviConfig::load() // open the file KviFile f(m_szFileName); - if(!f.openForReading())return false; + if(!f.open(QFile::ReadOnly)) return false; KviStr tmp; KviConfigGroup * p_group = 0; @@ -165,7 +165,7 @@ bool KviConfig::load() } // do read - readedLen = f.readBlock(p,toRead); + readedLen = f.read(p,toRead); if(readedLen < toRead) { // check for errors @@ -490,11 +490,11 @@ bool KviConfig::save() }; - if(m_bReadOnly)return false; + if(m_bReadOnly) return false; KviFile f(m_szFileName); - if(!f.openForWriting())return false; - if(f.writeBlock("# KVIrc configuration file\n",27) != 27)return false; + if(!f.open(QFile::WriteOnly | QFile::Truncate)) return false; + if(f.write("# KVIrc configuration file\n",27) != 27) return false; KviPointerHashTableIterator<QString,KviConfigGroup> it(*m_pDict); while (it.current()) @@ -505,8 +505,8 @@ bool KviConfig::save() group.hexEncodeWithTable(encode_table); if(!f.putChar('['))return false; - if(f.writeBlock(group.ptr(),group.len()) < (unsigned int) group.len())return false; - if(f.writeBlock("]\n",2) < 2)return false; + if(f.write(group.ptr(),group.len()) < (unsigned int) group.len())return false; + if(f.write("]\n",2) < 2)return false; KviConfigGroup * dict = (KviConfigGroup *)it.current(); KviConfigGroupIterator it2(*dict); @@ -519,9 +519,9 @@ bool KviConfig::save() szName.hexEncodeWithTable(encode_table); szValue.hexEncodeWhiteSpace(); - if(f.writeBlock(szName.ptr(),szName.len()) < (unsigned int) szName.len())return false; + if(f.write(szName.ptr(),szName.len()) < (unsigned int) szName.len())return false; if(!f.putChar('='))return false; - if(f.writeBlock(szValue.ptr(),szValue.len()) < (unsigned int) szValue.len())return false; + if(f.write(szValue.ptr(),szValue.len()) < (unsigned int) szValue.len())return false; if(!f.putChar('\n'))return false; ++it2; } diff --git a/src/kvilib/ext/kvi_mediatype.cpp b/src/kvilib/ext/kvi_mediatype.cpp index c499739c3..4b29a930b 100644 --- a/src/kvilib/ext/kvi_mediatype.cpp +++ b/src/kvilib/ext/kvi_mediatype.cpp @@ -380,9 +380,9 @@ KviMediaType * KviMediaManager::findMediaTypeForRegularFile(const char * szFullP { QString szTmp=QString::fromUtf8(szFullPath); KviFile f(szTmp); - if(f.openForReading()) + if(f.open(QFile::ReadOnly)) { - len = f.readBlock(buffer,16); + len = f.read(buffer,16); if(len > 0) { buffer[len] = '\0'; diff --git a/src/kvilib/file/kvi_file.cpp b/src/kvilib/file/kvi_file.cpp index 6c451c04a..feac5a54d 100644 --- a/src/kvilib/file/kvi_file.cpp +++ b/src/kvilib/file/kvi_file.cpp @@ -4,7 +4,8 @@ // Creation date : Mon Dec 17 2001 00:04:12 by Szymon Stefanek // // This file is part of the KVirc irc client distribution -// Copyright (C) 2001-2008 Szymon Stefanek (pragma at kvirc dot net) +// Copyright (C) 2001-2009 Szymon Stefanek (pragma at kvirc dot net) +// Copyright (C) 2010 Elvio Basello (hell at hellvis69 dot netsons dot org) // // This program is FREE software. You can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -33,8 +34,8 @@ KviFile::KviFile() { } -KviFile::KviFile(const QString &name) -: QFile(name) +KviFile::KviFile(const QString & szName) +: QFile(szName) { } @@ -42,20 +43,10 @@ KviFile::~KviFile() { } -bool KviFile::openForReading() -{ - return open(QFile::ReadOnly); -} - -bool KviFile::openForWriting(bool bAppend) -{ - return open(QFile::WriteOnly | (bAppend ? QFile::Append : QFile::Truncate)); -} - bool KviFile::save(const QByteArray &bData) { if(!save((kvi_u32_t)(bData.size())))return false; - return (writeBlock(bData.data(),bData.size()) == ((unsigned int)(bData.size()))); + return (write(bData.data(),bData.size()) == ((unsigned int)(bData.size()))); } bool KviFile::load(QByteArray &bData) @@ -63,7 +54,7 @@ bool KviFile::load(QByteArray &bData) kvi_u32_t iLen; if(!load(iLen))return false; bData.resize(iLen); // it is automatically null terminated in Qt 4.x... BLEAH :D - if(readBlock((char *)(bData.data()),iLen) != iLen)return false; + if(read((char *)(bData.data()),iLen) != iLen)return false; return true; } @@ -71,7 +62,7 @@ bool KviFile::save(const QString &szData) { QByteArray c = KviQString::toUtf8(szData); if(!save((kvi_u32_t)(c.length())))return false; - return (writeBlock(c.data(),c.length()) == ((unsigned int)(c.length()))); + return (write(c.data(),c.length()) == ((unsigned int)(c.length()))); } bool KviFile::load(QString &szData) @@ -80,7 +71,7 @@ bool KviFile::load(QString &szData) if(!load(iLen))return false; QByteArray tmp; tmp.resize(iLen + 1); - if(readBlock((char *)(tmp.data()),iLen) != iLen)return false; + if(read((char *)(tmp.data()),iLen) != iLen)return false; *(tmp.data() + iLen) = 0; szData = QString::fromUtf8(tmp.data()); return true; @@ -89,7 +80,7 @@ bool KviFile::load(QString &szData) bool KviFile::save(const KviStr &szData) { if(!save((kvi_u32_t)(szData.len())))return false; - return (writeBlock(szData.ptr(),szData.len()) == (unsigned int) szData.len()); + return (write(szData.ptr(),szData.len()) == (unsigned int) szData.len()); } bool KviFile::load(KviStr &szData) @@ -97,7 +88,7 @@ bool KviFile::load(KviStr &szData) kvi_u32_t iLen; if(!load(iLen))return false; szData.setLength(iLen); - return (readBlock((char *)(szData.ptr()),iLen) == iLen); + return (read((char *)(szData.ptr()),iLen) == iLen); } bool KviFile::save(kvi_u32_t t) @@ -105,12 +96,12 @@ bool KviFile::save(kvi_u32_t t) #ifndef LOCAL_CPU_LITTLE_ENDIAN t = kvi_localCpuToLittleEndian32(t); #endif - return (writeBlock((const char *)(&t),sizeof(kvi_u32_t)) == sizeof(kvi_u32_t)); + return (write((const char *)(&t),sizeof(kvi_u32_t)) == sizeof(kvi_u32_t)); } bool KviFile::load(kvi_u32_t &t) { - if(!(readBlock((char *)(&t),sizeof(kvi_u32_t)) == sizeof(kvi_u32_t)))return false; + if(!(read((char *)(&t),sizeof(kvi_u32_t)) == sizeof(kvi_u32_t)))return false; #ifndef LOCAL_CPU_LITTLE_ENDIAN t = kvi_littleEndianToLocalCpu32(t); #endif @@ -122,12 +113,12 @@ bool KviFile::save(kvi_u64_t t) #ifndef LOCAL_CPU_LITTLE_ENDIAN t = kvi_localCpuToLittleEndian64(t); #endif - return (writeBlock((const char *)(&t),sizeof(kvi_u64_t)) == sizeof(kvi_u64_t)); + return (write((const char *)(&t),sizeof(kvi_u64_t)) == sizeof(kvi_u64_t)); } bool KviFile::load(kvi_u64_t &t) { - if(!(readBlock((char *)(&t),sizeof(kvi_u32_t)) == sizeof(kvi_u32_t)))return false; + if(!(read((char *)(&t),sizeof(kvi_u32_t)) == sizeof(kvi_u32_t)))return false; #ifndef LOCAL_CPU_LITTLE_ENDIAN t = kvi_littleEndianToLocalCpu32(t); #endif @@ -139,12 +130,12 @@ bool KviFile::save(kvi_u16_t t) #ifndef LOCAL_CPU_LITTLE_ENDIAN t = kvi_localCpuToLittleEndian16(t); #endif - return (writeBlock((const char *)(&t),sizeof(kvi_u16_t)) == sizeof(kvi_u16_t)); + return (write((const char *)(&t),sizeof(kvi_u16_t)) == sizeof(kvi_u16_t)); } bool KviFile::load(kvi_u16_t &t) { - if(!(readBlock((char *)(&t),sizeof(kvi_u16_t)) == sizeof(kvi_u16_t)))return false; + if(!(read((char *)(&t),sizeof(kvi_u16_t)) == sizeof(kvi_u16_t)))return false; #ifndef LOCAL_CPU_LITTLE_ENDIAN t = kvi_littleEndianToLocalCpu16(t); #endif @@ -153,12 +144,12 @@ bool KviFile::load(kvi_u16_t &t) bool KviFile::save(kvi_u8_t t) { - return (writeBlock((const char *)(&t),sizeof(kvi_u8_t)) == sizeof(kvi_u8_t)); + return (write((const char *)(&t),sizeof(kvi_u8_t)) == sizeof(kvi_u8_t)); } bool KviFile::load(kvi_u8_t &t) { - return (readBlock((char *)(&t),sizeof(kvi_u8_t)) == sizeof(kvi_u8_t)); + return (read((char *)(&t),sizeof(kvi_u8_t)) == sizeof(kvi_u8_t)); } bool KviFile::save(KviPointerList<KviStr> * pData) diff --git a/src/kvilib/file/kvi_file.h b/src/kvilib/file/kvi_file.h index 4618914da..a2c6d4b4c 100644 --- a/src/kvilib/file/kvi_file.h +++ b/src/kvilib/file/kvi_file.h @@ -25,6 +25,12 @@ // //============================================================================= +/** +* \file kvi_file.h +* \author Szymon Stefanek +* \brief This file handles file operations performed by KVIrc +*/ + #include "kvi_settings.h" #include "kvi_heapobject.h" #include "kvi_qstring.h" @@ -39,63 +45,225 @@ #define kvi_file_offset_t qlonglong - +/** +* \class KviFile +* \brief KVIrc File class +*/ class KVILIB_API KviFile : public QFile, public KviHeapObject { public: + /** + * \brief Constructs file object + * \return KviFile + */ KviFile(); - KviFile(const QString &name); + + /** + * \brief Constructs file object + * \param szName The name of the file + * \return KviFile + */ + KviFile(const QString & szName); + + /** + * \brief Destroys file object + */ ~KviFile(); public: - // Wrappers portable across Qt 3.x and Qt 4.x - bool openForReading(); - bool openForWriting(bool bAppend = false); + /** + * \brief Saves a file + * \param file The file to save + * \warning This function saves LITTLE ENDIAN DATA! + * \return bool + */ + bool save(kvi_u64_t file); + /** + * \brief Saves a file + * \param file The file to save + * \warning This function saves LITTLE ENDIAN DATA! + * \return bool + */ + bool save(kvi_i64_t file){ return save((kvi_u64_t)file); }; - // Missing functions in Qt 4.x - qint64 writeBlock(const char * data,quint64 uLen){ return write(data,uLen); }; - qint64 readBlock(char * data,quint64 uLen){ return read(data,uLen); }; + /** + * \brief Saves a file + * \param file The file to save + * \warning This function saves LITTLE ENDIAN DATA! + * \return bool + */ + bool save(kvi_u32_t file); - // This stuff loads and saves LITTLE ENDIAN DATA! - bool save(kvi_u64_t t); - bool load(kvi_u64_t &t); + /** + * \brief Saves a file + * \param file The file to save + * \warning This function saves LITTLE ENDIAN DATA! + * \return bool + */ + bool save(kvi_i32_t file){ return save((kvi_u32_t)file); }; - bool save(kvi_i64_t t){ return save((kvi_u64_t)t); }; - bool load(kvi_i64_t &t){ return load((kvi_u64_t &)t); }; + /** + * \brief Saves a file + * \param file The file to save + * \warning This function saves LITTLE ENDIAN DATA! + * \return bool + */ + bool save(kvi_u16_t file); - bool save(kvi_u32_t t); - bool load(kvi_u32_t &t); + /** + * \brief Saves a file + * \param file The file to save + * \warning This function saves LITTLE ENDIAN DATA! + * \return bool + */ + bool save(kvi_i16_t file){ return save((kvi_u16_t)file); }; - bool save(kvi_i32_t t){ return save((kvi_u32_t)t); }; - bool load(kvi_i32_t &t){ return load((kvi_u32_t &)t); }; + /** + * \brief Saves a file + * \param file The file to save + * \warning This function saves LITTLE ENDIAN DATA! + * \return bool + */ + bool save(kvi_u8_t file); - bool save(kvi_u16_t t); - bool load(kvi_u16_t &t); + /** + * \brief Saves a file + * \param file The file to save + * \warning This function saves LITTLE ENDIAN DATA! + * \return bool + */ + bool save(kvi_i8_t file){ return save((kvi_u8_t)file); }; - bool save(kvi_i16_t t){ return save((kvi_u16_t)t); }; - bool load(kvi_i16_t &t){ return load((kvi_u16_t &)t); }; + /** + * \brief Saves a file + * \param szData The file to save + * \warning This function saves LITTLE ENDIAN DATA! + * \return bool + */ + bool save(const KviStr & szData); - bool save(kvi_u8_t t); - bool load(kvi_u8_t &t); + /** + * \brief Saves a file + * \param data The file to save + * \warning This function saves LITTLE ENDIAN DATA! + * \return bool + */ + bool save(const QByteArray & data); - bool save(kvi_i8_t t){ return save((kvi_u8_t)t); }; - bool load(kvi_i8_t &t){ return load((kvi_u8_t &)t); }; + /** + * \brief Saves a file + * \param szData The file to save + * \warning This function saves LITTLE ENDIAN DATA! + * \return bool + */ + bool save(const QString & szData); - bool save(const KviStr &szData); - bool load(KviStr &szData); + /** + * \brief Saves a file to a list + * \param pData The list where file to save is + * \warning This function saves LITTLE ENDIAN DATA! + * \return bool + */ + bool save(KviPointerList<KviStr> * pData); + + /** + * \brief Loads a file + * \param file The file to load + * \warning This function loads LITTLE ENDIAN DATA! + * \return bool + */ + bool load(kvi_u64_t & file); + /** + * \brief Loads a file + * \param file The file to load + * \warning This function loads LITTLE ENDIAN DATA! + * \return bool + */ + bool load(kvi_i64_t & file){ return load((kvi_u64_t &)file); }; - bool save(const QByteArray &bData); - bool load(QByteArray &bData); + /** + * \brief Loads a file + * \param file The file to load + * \warning This function loads LITTLE ENDIAN DATA! + * \return bool + */ + bool load(kvi_u32_t & file); - bool save(const QString &szData); - bool load(QString &szData); + /** + * \brief Loads a file + * \param file The file to load + * \warning This function loads LITTLE ENDIAN DATA! + * \return bool + */ + bool load(kvi_i32_t & file){ return load((kvi_u32_t &)file); }; - bool skipFirst(char t,unsigned int maxdist = 0xffffffff); - bool skipFirst(const KviStr &t,unsigned int maxdist = 0xffffffff); + /** + * \brief Loads a file + * \param file The file to load + * \warning This function loads LITTLE ENDIAN DATA! + * \return bool + */ + bool load(kvi_u16_t & file); - bool save(KviPointerList<KviStr> * pData); + /** + * \brief Loads a file + * \param file The file to load + * \warning This function loads LITTLE ENDIAN DATA! + * \return bool + */ + bool load(kvi_i16_t & file){ return load((kvi_u16_t &)file); }; + + /** + * \brief Loads a file + * \param file The file to load + * \warning This function loads LITTLE ENDIAN DATA! + * \return bool + */ + bool load(kvi_u8_t & file); + + /** + * \brief Loads a file + * \param file The file to load + * \warning This function loads LITTLE ENDIAN DATA! + * \return bool + */ + bool load(kvi_i8_t & file){ return load((kvi_u8_t &)file); }; + + /** + * \brief Loads a file + * \param szData The file to load + * \warning This function loads LITTLE ENDIAN DATA! + * \return bool + */ + bool load(KviStr & szData); + + /** + * \brief Loads a file + * \param data The file to load + * \warning This function loads LITTLE ENDIAN DATA! + * \return bool + */ + bool load(QByteArray & data); + + /** + * \brief Loads a file + * \param szData The file to load + * \warning This function loads LITTLE ENDIAN DATA! + * \return bool + */ + bool load(QString & szData); + + /** + * \brief Loads a file from a list + * \param pData The list of files to load + * \warning This function loads LITTLE ENDIAN DATA! + * \return bool + */ bool load(KviPointerList<KviStr> * pData); + + bool skipFirst(char t,unsigned int maxdist = 0xffffffff); + bool skipFirst(const KviStr &t,unsigned int maxdist = 0xffffffff); }; diff --git a/src/kvilib/file/kvi_fileutils.cpp b/src/kvilib/file/kvi_fileutils.cpp index e205c9a12..5ed95e55d 100644 --- a/src/kvilib/file/kvi_fileutils.cpp +++ b/src/kvilib/file/kvi_fileutils.cpp @@ -153,10 +153,10 @@ namespace KviFileUtils bool copyFile(const QString & szSrc, const QString & szDst) { KviFile f1(szSrc); - if(!f1.openForReading()) + if(!f1.open(QFile::ReadOnly)) return false; KviFile f2(szDst); - if(!f2.openForWriting()) + if(!f2.open(QFile::WriteOnly | QFile::Truncate)) { f1.close(); return false; @@ -164,14 +164,14 @@ namespace KviFileUtils char cBuffer[1024]; while(!f1.atEnd()) { - int iLen = f1.readBlock(cBuffer,1024); + int iLen = f1.read(cBuffer,1024); if(iLen <= 0) { f1.close(); f2.close(); return false; //"serious error" } - f2.writeBlock(cBuffer,iLen); + f2.write(cBuffer,iLen); } f1.close(); f2.close(); @@ -188,7 +188,7 @@ namespace KviFileUtils bool loadFile(const QString & szPath, QString & szBuffer, bool bUtf8) { KviFile f(szPath); - if(!f.openForReading()) + if(!f.open(QFile::ReadOnly)) return false; if(bUtf8) { @@ -283,12 +283,12 @@ namespace KviFileUtils bool writeFile(const QString & szPath, const QString & szData, bool bAppend) { KviFile f(szPath); - if(!f.openForWriting(bAppend)) + if(!f.open(QFile::WriteOnly | (bAppend ? QFile::Append : QFile::Truncate))) return false; QByteArray szTmp = KviQString::toUtf8(szData); if(!szTmp.data()) return true; - if(f.writeBlock(szTmp.data(),szTmp.length()) != ((unsigned int)(szTmp.length()))) + if(f.write(szTmp.data(),szTmp.length()) != ((unsigned int)(szTmp.length()))) return false; return true; } @@ -302,12 +302,12 @@ namespace KviFileUtils bool writeFileLocal8Bit(const QString & szPath, const QString & szData, bool bAppend) { KviFile f(szPath); - if(!f.openForWriting(bAppend)) + if(!f.open(QFile::WriteOnly | (bAppend ? QFile::Append : QFile::Truncate))) return false; QByteArray szTmp = QTextCodec::codecForLocale()->fromUnicode(szData); if(!szTmp.data()) return true; - if(f.writeBlock(szTmp.data(),szTmp.length()) != ((unsigned int)(szTmp.length()))) + if(f.write(szTmp.data(),szTmp.length()) != ((unsigned int)(szTmp.length()))) return false; return true; } @@ -321,7 +321,7 @@ namespace KviFileUtils bool readFile(const QString & szPath, QString & szBuffer, unsigned int uMaxSize) { KviFile f(szPath); - if(!f.openForReading()) + if(!f.open(QFile::ReadOnly)) return false; if(f.size() < 1) { @@ -332,7 +332,7 @@ namespace KviFileUtils if(f.size() > uMaxSize) return false; char * pcBuf = new char[f.size() + 1]; - if(f.readBlock(pcBuf,f.size()) != ((long int)f.size())) + if(f.read(pcBuf,f.size()) != ((long int)f.size())) { delete[] pcBuf; pcBuf = 0; diff --git a/src/kvilib/file/kvi_packagefile.cpp b/src/kvilib/file/kvi_packagefile.cpp index eb607b23b..07972f8af 100644 --- a/src/kvilib/file/kvi_packagefile.cpp +++ b/src/kvilib/file/kvi_packagefile.cpp @@ -280,7 +280,7 @@ bool KviPackageWriter::packFile(KviFile * pFile,DataField * pDataField) KviFile source(pDataField->m_szFileLocalName); - if(!source.openForReading()) + if(!source.open(QFile::ReadOnly)) { setLastError(__tr2qs("Failed to open a source file for reading")); return false; @@ -318,7 +318,7 @@ bool KviPackageWriter::packFile(KviFile * pFile,DataField * pDataField) unsigned char ibuffer[BUFFER_SIZE]; unsigned char obuffer[BUFFER_SIZE]; - kvi_i32_t iReaded = source.readBlock((char *)ibuffer,BUFFER_SIZE); + kvi_i32_t iReaded = source.read((char *)ibuffer,BUFFER_SIZE); if(iReaded < 0) return readError(); @@ -352,7 +352,7 @@ bool KviPackageWriter::packFile(KviFile * pFile,DataField * pDataField) { int iCompressed = zstr.next_out - obuffer; pDataField->m_uWrittenFieldLength += iCompressed; - if(pFile->writeBlock((char *)obuffer,iCompressed) != iCompressed) + if(pFile->write((char *)obuffer,iCompressed) != iCompressed) { deflateEnd(&zstr); return writeError(); @@ -371,7 +371,7 @@ bool KviPackageWriter::packFile(KviFile * pFile,DataField * pDataField) memmove(ibuffer,zstr.next_in,zstr.avail_in); } } - iReaded = source.readBlock((char *)(ibuffer + zstr.avail_in),iDataToRead); + iReaded = source.read((char *)(ibuffer + zstr.avail_in),iDataToRead); if(iReaded < 0) { deflateEnd(&zstr); @@ -406,7 +406,7 @@ bool KviPackageWriter::packFile(KviFile * pFile,DataField * pDataField) { int iCompressed = zstr.next_out - obuffer; pDataField->m_uWrittenFieldLength += iCompressed; - if(pFile->writeBlock((char *)obuffer,iCompressed) != iCompressed) + if(pFile->write((char *)obuffer,iCompressed) != iCompressed) { deflateEnd(&zstr); return writeError(); @@ -442,7 +442,7 @@ bool KviPackageWriter::packFile(KviFile * pFile,DataField * pDataField) #endif unsigned char buffer[BUFFER_SIZE]; int iTotalFileSize = 0; - kvi_i32_t iReaded = source.readBlock((char *)buffer,BUFFER_SIZE); + kvi_i32_t iReaded = source.read((char *)buffer,BUFFER_SIZE); if(iReaded < 0) return readError(); while(iReaded > 0) @@ -457,9 +457,9 @@ bool KviPackageWriter::packFile(KviFile * pFile,DataField * pDataField) return false; // aborted } pDataField->m_uWrittenFieldLength += iReaded; - if(pFile->writeBlock((char *)buffer,iReaded) != iReaded) + if(pFile->write((char *)buffer,iReaded) != iReaded) return writeError(); - iReaded = source.readBlock((char *)buffer,BUFFER_SIZE); + iReaded = source.read((char *)buffer,BUFFER_SIZE); } #ifdef COMPILE_ZLIB_SUPPORT } @@ -488,7 +488,7 @@ bool KviPackageWriter::packInternal(const QString &szFileName,kvi_u32_t) { KviFile f(szFileName); - if(!f.openForWriting()) + if(!f.open(QFile::WriteOnly | QFile::Truncate)) { setLastError(__tr2qs("Can't open file for writing")); return false; @@ -502,7 +502,7 @@ bool KviPackageWriter::packInternal(const QString &szFileName,kvi_u32_t) magic[1] = 'V'; magic[2] = 'P'; magic[3] = 'F'; - if(f.writeBlock(magic,4) != 4)return writeError(); + if(f.write(magic,4) != 4)return writeError(); // Version kvi_u32_t uVersion = 0x1; @@ -604,7 +604,7 @@ bool KviPackageReader::readHeaderInternal(KviFile * pFile,const QString &) // Magic char magic[4]; - if(pFile->readBlock(magic,4) != 4)return readError(); + if(pFile->read(magic,4) != 4) return readError(); if((magic[0] != 'K') || (magic[1] != 'V') || (magic[2] != 'P') || (magic[3] != 'F')) { setLastError(__tr2qs("The file specified is not a valid KVIrc package")); @@ -674,7 +674,7 @@ bool KviPackageReader::readHeaderInternal(KviFile * pFile,const QString &) bool KviPackageReader::readHeader(const QString &szLocalFileName) { KviFile f(szLocalFileName); - if(!f.openForReading()) + if(!f.open(QFile::ReadOnly)) { setLastError(__tr2qs("Can't open file for reading")); return false; @@ -724,7 +724,7 @@ bool KviPackageReader::unpackFile(KviFile * pFile,const QString &szUnpackPath) } KviFile dest(szFileName); - if(!dest.openForWriting()) + if(!dest.open(QFile::WriteOnly | QFile::Truncate)) { setLastError(__tr2qs("Failed to open a source file for reading")); return false; @@ -750,7 +750,7 @@ bool KviPackageReader::unpackFile(KviFile * pFile,const QString &szUnpackPath) int iToRead = iRemainingSize; if(iToRead > BUFFER_SIZE)iToRead = BUFFER_SIZE; - int iReaded = pFile->readBlock((char *)ibuffer,iToRead); + int iReaded = pFile->read((char *)ibuffer,iToRead); iRemainingSize -= iReaded; z_stream zstr; @@ -782,7 +782,7 @@ bool KviPackageReader::unpackFile(KviFile * pFile,const QString &szUnpackPath) if(zstr.avail_out < BUFFER_SIZE) { int iDecompressed = zstr.next_out - obuffer; - if(dest.writeBlock((char *)obuffer,iDecompressed) != iDecompressed) + if(dest.write((char *)obuffer,iDecompressed) != iDecompressed) { inflateEnd(&zstr); return writeError(); @@ -805,7 +805,7 @@ bool KviPackageReader::unpackFile(KviFile * pFile,const QString &szUnpackPath) if(iDataToRead > iRemainingSize) iDataToRead = iRemainingSize; - iReaded = pFile->readBlock((char *)(ibuffer + zstr.avail_in),iDataToRead); + iReaded = pFile->read((char *)(ibuffer + zstr.avail_in),iDataToRead); if(iReaded < 0) { inflateEnd(&zstr); @@ -841,7 +841,7 @@ bool KviPackageReader::unpackFile(KviFile * pFile,const QString &szUnpackPath) if(zstr.avail_out < BUFFER_SIZE) { int iDecompressed = zstr.next_out - obuffer; - if(dest.writeBlock((char *)obuffer,iDecompressed) != iDecompressed) + if(dest.write((char *)obuffer,iDecompressed) != iDecompressed) { inflateEnd(&zstr); return writeError(); @@ -878,7 +878,7 @@ bool KviPackageReader::unpackFile(KviFile * pFile,const QString &szUnpackPath) while((iReaded > 0) && (iToRead > 0)) { - iReaded = pFile->readBlock((char *)buffer,iToRead); + iReaded = pFile->read((char *)buffer,iToRead); if(iReaded > 0) { iTotalFileSize += iReaded; @@ -893,7 +893,7 @@ bool KviPackageReader::unpackFile(KviFile * pFile,const QString &szUnpackPath) return false; // aborted } - if(dest.writeBlock((char *)buffer,iReaded) != iReaded) + if(dest.write((char *)buffer,iReaded) != iReaded) return writeError(); } @@ -927,7 +927,7 @@ bool KviPackageReader::unpackInternal(const QString &szLocalFileName,const QStri { KviFile f(szLocalFileName); - if(!f.openForReading()) + if(!f.open(QFile::ReadOnly)) { setLastError(__tr2qs("Can't open file for reading")); return false; diff --git a/src/kvilib/net/kvi_http.cpp b/src/kvilib/net/kvi_http.cpp index bbc9b889e..bacb9bbf0 100644 --- a/src/kvilib/net/kvi_http.cpp +++ b/src/kvilib/net/kvi_http.cpp @@ -308,7 +308,7 @@ bool KviHttpRequest::event(QEvent *e) break; case StoreToFile: // same as above... should never happen.. but well :D - if(m_pFile && m_pBuffer->size() > 0)m_pFile->writeBlock((const char *)(m_pBuffer->data()),m_pBuffer->size()); + if(m_pFile && m_pBuffer->size() > 0)m_pFile->write((const char *)(m_pBuffer->data()),m_pBuffer->size()); break; default: // nothing... just make gcc happy @@ -437,7 +437,7 @@ bool KviHttpRequest::openFile() m_pFile = new KviFile(m_szFileName); - if(!m_pFile->openForWriting(bAppend)) + if(!m_pFile->open(QFile::WriteOnly | (bAppend ? QFile::Append : QFile::Truncate))) { resetInternalStatus(); KviQString::sprintf(m_szLastError,__tr2qs("Can't open file \"%Q\" for writing"),&m_szFileName); @@ -693,7 +693,7 @@ void KviHttpRequest::processData(KviDataBuffer * data) emit binaryData(*data); break; case StoreToFile: - m_pFile->writeBlock((const char *)(data->data()),data->size()); + m_pFile->write((const char *)(data->data()),data->size()); break; default: break; @@ -759,7 +759,7 @@ void KviHttpRequest::processData(KviDataBuffer * data) } break; case StoreToFile: - m_pFile->writeBlock((const char *)(m_pBuffer->data()),uProcessSize); + m_pFile->write((const char *)(m_pBuffer->data()),uProcessSize); m_pBuffer->remove(uProcessSize); break; default: @@ -830,7 +830,7 @@ void KviHttpRequest::processData(KviDataBuffer * data) if(m_pBuffer->size() > 0)emitLines(m_pBuffer); break; case StoreToFile: - m_pFile->writeBlock((const char *)(m_pBuffer->data()),m_pBuffer->size()); + m_pFile->write((const char *)(m_pBuffer->data()),m_pBuffer->size()); m_pBuffer->clear(); break; default: diff --git a/src/kvilib/system/kvi_locale.cpp b/src/kvilib/system/kvi_locale.cpp index b364e887a..11bbfb605 100644 --- a/src/kvilib/system/kvi_locale.cpp +++ b/src/kvilib/system/kvi_locale.cpp @@ -427,7 +427,7 @@ bool KviMessageCatalogue::load(const QString& name) // Try to load the header KviFile f(szCatalogueFile); - if(!f.openForReading()) + if(!f.open(QFile::ReadOnly)) { debug("[KviLocale]: Failed to open the messages file %s: probably doesn't exist",KviQString::toUtf8(szCatalogueFile).data()); return false; @@ -435,7 +435,7 @@ bool KviMessageCatalogue::load(const QString& name) GnuMoFileHeader hdr; - if(f.readBlock((char *)&hdr,sizeof(GnuMoFileHeader)) < (int)sizeof(GnuMoFileHeader)) + if(f.read((char *)&hdr,sizeof(GnuMoFileHeader)) < (int)sizeof(GnuMoFileHeader)) { debug("KviLocale: Failed to read header of %s",KviQString::toUtf8(szCatalogueFile).data()); f.close(); @@ -486,7 +486,7 @@ bool KviMessageCatalogue::load(const QString& name) char * buffer = (char *)kvi_malloc(fSize); // FIXME: maybe read it in blocks eh ? - if(f.readBlock(buffer,fSize) < (int)fSize) + if(f.read(buffer,fSize) < (int)fSize) { debug("KviLocale: Error while reading the translation file %s",KviQString::toUtf8(szCatalogueFile).data()); kvi_free(buffer); diff --git a/src/modules/file/libkvifile.cpp b/src/modules/file/libkvifile.cpp index 05dbc50e4..5b457ca93 100644 --- a/src/modules/file/libkvifile.cpp +++ b/src/modules/file/libkvifile.cpp @@ -696,7 +696,7 @@ static bool file_kvs_fnc_ls(KviKvsModuleFunctionCall * c) An empty string is returned if a serious error occures.[br] The <filename> is adjusted according to the system that KVIrc is running on.[br] Flags are actually limited to the single letter 'l'. By default the file - is decoded from the ut8 characters set. If 'l' is present the the file + is decoded from the utf8 characters set. If 'l' is present the the file is decoded by using the local 8 bit character set instead. @examples: [example] @@ -904,17 +904,18 @@ static bool file_kvs_cmd_writeLines(KviKvsModuleCommandCall * c) KviFile f(szFile); - if(!f.openForWriting(c->switches()->find('a',"append"))) + bool bAppend = c->switches()->find('a',"append"); + bool bLocal8Bit = c->switches()->find('l',"local-8-bit"); + bool bNoSeparator = c->switches()->find('n',"no-separator"); + bool bAddCR = c->switches()->find('c',"crlf"); + + if(!f.open(QFile::WriteOnly | (bAppend ? QFile::Append : QFile::Truncate))) { if(!c->switches()->find('q',"quiet")) c->warning(__tr2qs("Can't open the file \"%Q\" for writing"),&szFile); return true; } - bool bLocal8Bit = c->switches()->find('l',"local-8-bit"); - bool bNoSeparator = c->switches()->find('n',"no-separator"); - bool bAddCR = c->switches()->find('c',"crlf"); - unsigned int u = 0; while(u < a.array()->size()) { @@ -931,7 +932,7 @@ static bool file_kvs_cmd_writeLines(KviKvsModuleCommandCall * c) if(bAddCR)dat += "\r\n"; else dat += '\n'; } - f.writeBlock(dat.data(),dat.length()); + f.write(dat.data(),dat.length()); } u++; } diff --git a/src/modules/objects/class_file.h b/src/modules/objects/class_file.h index 8c41312be..e184a95c8 100644 --- a/src/modules/objects/class_file.h +++ b/src/modules/objects/class_file.h @@ -35,10 +35,10 @@ class KviKvsObject_file : public KviKvsObject_widget public: KVSO_DECLARE_OBJECT(KviKvsObject_file) protected: - KviFile* m_pFile; + KviFile * m_pFile; public: - KviFile *pFile(){return m_pFile;}; + KviFile * file(){ return m_pFile; }; bool setName(KviKvsObjectFunctionCall *c); bool name(KviKvsObjectFunctionCall *c); bool open(KviKvsObjectFunctionCall *c); diff --git a/src/modules/objects/class_memorybuffer.cpp b/src/modules/objects/class_memorybuffer.cpp index 58e93488a..bff3f425a 100644 --- a/src/modules/objects/class_memorybuffer.cpp +++ b/src/modules/objects/class_memorybuffer.cpp @@ -86,14 +86,14 @@ KVSO_CLASS_FUNCTION(memorybuffer,loadFromFile) { KviFile f(szFileName); - debug("loading file %s",szFileName.toUtf8().data()); - if (f.open(QIODevice::ReadOnly)) - { - m_pBuffer->resize(f.size()); - f.readBlock(m_pBuffer->data(),f.size()); - f.close(); - } - else debug("Error in load file!"); + debug("loading file %s",szFileName.toUtf8().data()); + if (f.open(QIODevice::ReadOnly)) + { + m_pBuffer->resize(f.size()); + f.read(m_pBuffer->data(),f.size()); + f.close(); + } + else debug("Error in load file!"); } else c->warning(__tr2qs_ctx("The file '%Q' does not exist","objects"),&szFileName); return true; @@ -108,7 +108,7 @@ KVSO_CLASS_FUNCTION(memorybuffer,saveToFile) KviFile f(szFileName); if (f.open(QIODevice::WriteOnly)) { - f.writeBlock(m_pBuffer->data(),m_pBuffer->size()); + f.write(m_pBuffer->data(),m_pBuffer->size()); f.close(); } else diff --git a/src/modules/objects/class_socket.cpp b/src/modules/objects/class_socket.cpp index 934264356..63dcf0b62 100644 --- a/src/modules/objects/class_socket.cpp +++ b/src/modules/objects/class_socket.cpp @@ -511,7 +511,7 @@ KVSO_CLASS_FUNCTION(socket,write) } else if (pObject->inheritsClass("file")) { - KviFile *pFile=((KviKvsObject_file *)pObject)->pFile(); + KviFile *pFile=((KviKvsObject_file *)pObject)->file(); if (!pFile->isOpen()) { c->warning(__tr2qs_ctx("File is not open!","objects")); diff --git a/src/modules/reguser/dialog.cpp b/src/modules/reguser/dialog.cpp index e7696e781..9f6b8c59e 100644 --- a/src/modules/reguser/dialog.cpp +++ b/src/modules/reguser/dialog.cpp @@ -732,7 +732,7 @@ void KviRegisteredUsersDialog::exportClicked() hf.version = KVI_REGUSER_DB_FILE_VERSION; hf.nentries = nEntries; - if(f.writeBlock((const char *)&hf,sizeof(KviReguserDbFileHeader)) != sizeof(KviReguserDbFileHeader))goto write_error; + if(f.write((const char *)&hf,sizeof(KviReguserDbFileHeader)) != sizeof(KviReguserDbFileHeader))goto write_error; for(int i=0; i<list.count(); i++) { @@ -834,7 +834,7 @@ void KviRegisteredUsersDialog::importClicked() KviReguserDbFileHeader hf; unsigned int idx; - if(f.readBlock((char *)&hf,sizeof(KviReguserDbFileHeader)) != sizeof(KviReguserDbFileHeader))goto read_error; + if(f.read((char *)&hf,sizeof(KviReguserDbFileHeader)) != sizeof(KviReguserDbFileHeader))goto read_error; if(hf.magic != KVI_REGUSER_DB_FILE_MAGIC) { |
