File indexing completed on 2024-04-28 05:42:11
0001 /*************************************************************************** 0002 * Copyright (C) 2006-2009 by Rajko Albrecht * 0003 * ral@alwins-world.de * 0004 * * 0005 * This program is free software; you can redistribute it and/or * 0006 * modify it under the terms of the GNU Lesser General Public * 0007 * License as published by the Free Software Foundation; either * 0008 * version 2.1 of the License, or (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0013 * Lesser General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU Lesser General Public * 0016 * License along with this program (in the file LGPL.txt); if not, * 0017 * write to the Free Software Foundation, Inc., 51 Franklin St, * 0018 * Fifth Floor, Boston, MA 02110-1301 USA * 0019 * * 0020 * This software consists of voluntary contributions made by many * 0021 * individuals. For exact contribution history, see the revision * 0022 * history and logs, available at https://commits.kde.org/kdesvn. * 0023 ***************************************************************************/ 0024 #include "svnfilestream.h" 0025 0026 #include <qfile.h> 0027 0028 namespace svn 0029 { 0030 0031 namespace stream 0032 { 0033 0034 typedef QIODevice::OpenMode openmode; 0035 #define READONLY QIODevice::ReadOnly 0036 #define WRITEONLY QIODevice::WriteOnly 0037 0038 class SVNQT_NOEXPORT SvnFileStream_private 0039 { 0040 public: 0041 SvnFileStream_private(const QString &fn, openmode mode); 0042 virtual ~SvnFileStream_private(); 0043 0044 QFile m_File; 0045 }; 0046 0047 SvnFileStream_private::SvnFileStream_private(const QString &fn, openmode mode) 0048 : m_File(fn) 0049 { 0050 m_File.open(mode); 0051 } 0052 0053 SvnFileStream_private::~SvnFileStream_private() 0054 { 0055 } 0056 0057 SvnFileOStream::SvnFileOStream(const QString &fn, svn_client_ctx_t *ctx) 0058 : SvnStream(false, true, ctx) 0059 { 0060 m_FileData = new SvnFileStream_private(fn, WRITEONLY); 0061 if (!m_FileData->m_File.isOpen()) { 0062 setError(m_FileData->m_File.errorString()); 0063 } 0064 } 0065 0066 SvnFileOStream::~SvnFileOStream() 0067 { 0068 delete m_FileData; 0069 } 0070 0071 bool SvnFileOStream::isOk() const 0072 { 0073 return m_FileData->m_File.isOpen(); 0074 } 0075 0076 long SvnFileOStream::write(const char *data, const unsigned long max) 0077 { 0078 if (!m_FileData->m_File.isOpen()) { 0079 return -1; 0080 } 0081 long res = m_FileData->m_File.write(data, max); 0082 if (res < 0) { 0083 setError(m_FileData->m_File.errorString()); 0084 } 0085 return res; 0086 } 0087 0088 SvnFileIStream::SvnFileIStream(const QString &fn, svn_client_ctx_t *ctx) 0089 : SvnStream(true, false, ctx) 0090 { 0091 m_FileData = new SvnFileStream_private(fn, READONLY); 0092 if (!m_FileData->m_File.isOpen()) { 0093 setError(m_FileData->m_File.errorString()); 0094 } 0095 } 0096 0097 SvnFileIStream::~SvnFileIStream() 0098 { 0099 delete m_FileData; 0100 } 0101 0102 bool SvnFileIStream::isOk() const 0103 { 0104 return m_FileData->m_File.isOpen(); 0105 } 0106 0107 long SvnFileIStream::read(char *data, const unsigned long max) 0108 { 0109 if (!m_FileData->m_File.isOpen()) { 0110 return -1; 0111 } 0112 long res = m_FileData->m_File.read(data, max); 0113 if (res < 0) { 0114 setError(m_FileData->m_File.errorString()); 0115 } 0116 return res; 0117 } 0118 0119 } 0120 0121 }