summaryrefslogtreecommitdiff
path: root/noncore/apps/tinykate/libkate/document/katebuffer.cpp
Unidiff
Diffstat (limited to 'noncore/apps/tinykate/libkate/document/katebuffer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/libkate/document/katebuffer.cpp89
1 files changed, 45 insertions, 44 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katebuffer.cpp b/noncore/apps/tinykate/libkate/document/katebuffer.cpp
index 22a4917..4c15fd0 100644
--- a/noncore/apps/tinykate/libkate/document/katebuffer.cpp
+++ b/noncore/apps/tinykate/libkate/document/katebuffer.cpp
@@ -13,42 +13,43 @@
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23 23
24#include "katebuffer.h" 24#include "katebuffer.h"
25#include "kdebug.h"
25 26
26// Includes for reading file 27/* OPIE */
27#include <sys/types.h> 28#include <opie2/odebug.h>
28#include <sys/stat.h>
29#include <fcntl.h>
30#include <errno.h>
31#include <unistd.h>
32 29
30/* QT */
33#include <qfile.h> 31#include <qfile.h>
34#include <qtextstream.h> 32#include <qtextstream.h>
35
36#include <qtimer.h> 33#include <qtimer.h>
37#include <qtextcodec.h> 34#include <qtextcodec.h>
38 35
39// 36/* STD */
40 37// Includes for reading file
38#include <sys/types.h>
39#include <sys/stat.h>
40#include <fcntl.h>
41#include <errno.h>
42#include <unistd.h>
41#include <assert.h> 43#include <assert.h>
42#include <kdebug.h>
43 44
44/** 45/**
45 * Create an empty buffer. 46 * Create an empty buffer.
46 */ 47 */
47KWBuffer::KWBuffer() 48KWBuffer::KWBuffer()
48{ 49{
49 clear(); 50 clear();
50} 51}
51 52
52void 53void
53KWBuffer::clear() 54KWBuffer::clear()
54{ 55{
@@ -56,53 +57,53 @@ KWBuffer::clear()
56 m_stringListCurrent=0; 57 m_stringListCurrent=0;
57 m_stringList.clear(); 58 m_stringList.clear();
58 m_lineCount=1; 59 m_lineCount=1;
59 m_stringListIt = m_stringList.append(new TextLine()); 60 m_stringListIt = m_stringList.append(new TextLine());
60} 61}
61 62
62/** 63/**
63 * Insert a file at line @p line in the buffer. 64 * Insert a file at line @p line in the buffer.
64 */ 65 */
65void 66void
66KWBuffer::insertFile(int line, const QString &file, QTextCodec *codec) 67KWBuffer::insertFile(int line, const QString &file, QTextCodec *codec)
67{ 68{
68 if (line) { 69 if (line) {
69 qDebug("insert File only supports insertion at line 0 == file opening"); 70 odebug << "insert File only supports insertion at line 0 == file opening" << oendl;
70 return; 71 return;
71 } 72 }
72 clear(); 73 clear();
73 QFile iofile(file); 74 QFile iofile(file);
74 iofile.open(IO_ReadOnly); 75 iofile.open(IO_ReadOnly);
75 QTextStream stream(&iofile); 76 QTextStream stream(&iofile);
76 stream.setCodec(codec); 77 stream.setCodec(codec);
77 QString qsl; 78 QString qsl;
78 int count=0; 79 int count=0;
79 for (count=0;((qsl=stream.readLine())!=QString::null);count++) 80 for (count=0;((qsl=stream.readLine())!=QString::null); count++)
80 { 81 {
81 if (count==0) 82 if (count==0)
82 { 83 {
83 (*m_stringListIt)->append(qsl.unicode(),qsl.length()); 84 (*m_stringListIt)->append(qsl.unicode(),qsl.length());
84 } 85 }
85 else 86 else
86 { 87 {
87 TextLine::Ptr tl=new TextLine(); 88 TextLine::Ptr tl=new TextLine();
88 tl ->append(qsl.unicode(),qsl.length()); 89 tl ->append(qsl.unicode(),qsl.length());
89 m_stringListIt=m_stringList.append(tl); 90 m_stringListIt=m_stringList.append(tl);
90 } 91 }
91 } 92 }
92 if (count!=0) 93 if (count!=0)
93 { 94 {
94 m_stringListCurrent=count-1; 95 m_stringListCurrent=count-1;
95 m_lineCount=count; 96 m_lineCount=count;
96 } 97 }
97} 98}
98 99
99void 100void
100KWBuffer::loadFilePart() 101KWBuffer::loadFilePart()
101{ 102{
102} 103}
103 104
104 105
105void 106void
106KWBuffer::insertData(int line, const QByteArray &data, QTextCodec *codec) 107KWBuffer::insertData(int line, const QByteArray &data, QTextCodec *codec)
107{ 108{
108} 109}
@@ -112,54 +113,54 @@ KWBuffer::slotLoadFile()
112{ 113{
113 loadFilePart(); 114 loadFilePart();
114// emit linesChanged(m_totalLines); 115// emit linesChanged(m_totalLines);
115 emit linesChanged(20); 116 emit linesChanged(20);
116} 117}
117 118
118/** 119/**
119 * Return the total number of lines in the buffer. 120 * Return the total number of lines in the buffer.
120 */ 121 */
121int 122int
122KWBuffer::count() 123KWBuffer::count()
123{ 124{
124 qDebug("m_stringList.count %d",m_stringList.count()); 125 odebug << "m_stringList.count " << m_stringList.count() << "" << oendl;
125 return m_lineCount; 126 return m_lineCount;
126 //return m_stringList.count(); 127// return m_stringList.count();
127// return m_totalLines; 128// return m_totalLines;
128} 129}
129 130
130 131
131void KWBuffer::seek(int i) 132void KWBuffer::seek(int i)
132{ 133{
133 if (m_stringListCurrent == i) 134 if (m_stringListCurrent == i)
134 return; 135 return;
135 while(m_stringListCurrent < i) 136 while(m_stringListCurrent < i)
136 { 137 {
137 ++m_stringListCurrent; 138 ++m_stringListCurrent;
138 ++m_stringListIt; 139 ++m_stringListIt;
139 } 140 }
140 while(m_stringListCurrent > i) 141 while(m_stringListCurrent > i)
141 { 142 {
142 --m_stringListCurrent; 143 --m_stringListCurrent;
143 --m_stringListIt; 144 --m_stringListIt;
144 } 145 }
145} 146}
146 147
147 148
148TextLine::Ptr 149TextLine::Ptr
149KWBuffer::line(int i) 150KWBuffer::line(int i)
150{ 151{
151 if (i>=m_stringList.count()) return 0; 152 if (i>=m_stringList.count()) return 0;
152 seek(i); 153 seek(i);
153 return *m_stringListIt; 154 return *m_stringListIt;
154} 155}
155 156
156void 157void
157KWBuffer::insertLine(int i, TextLine::Ptr line) 158KWBuffer::insertLine(int i, TextLine::Ptr line)
158{ 159{
159 seek(i); 160 seek(i);
160 m_stringListIt = m_stringList.insert(m_stringListIt, line); 161 m_stringListIt = m_stringList.insert(m_stringListIt, line);
161 m_stringListCurrent = i; 162 m_stringListCurrent = i;
162 m_lineCount++; 163 m_lineCount++;
163} 164}
164 165
165 166