author | jowenn <jowenn> | 2002-11-10 21:08:01 (UTC) |
---|---|---|
committer | jowenn <jowenn> | 2002-11-10 21:08:01 (UTC) |
commit | e97a6da57804aa14907dec327fbae71bff9b383e (patch) (unidiff) | |
tree | 15f6ee292dba24bdda72f5c72f6d2224c3516763 /noncore/apps/tinykate/libkate/document/katebuffer.cpp | |
parent | 7c012ee8cd16d8befacc6f6750711443fac0fd5e (diff) | |
download | opie-e97a6da57804aa14907dec327fbae71bff9b383e.zip opie-e97a6da57804aa14907dec327fbae71bff9b383e.tar.gz opie-e97a6da57804aa14907dec327fbae71bff9b383e.tar.bz2 |
import of tiny kate. (saving not possible yet)
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.cpp | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katebuffer.cpp b/noncore/apps/tinykate/libkate/document/katebuffer.cpp new file mode 100644 index 0000000..22a4917 --- a/dev/null +++ b/noncore/apps/tinykate/libkate/document/katebuffer.cpp | |||
@@ -0,0 +1,179 @@ | |||
1 | /* | ||
2 | This file is part of KWrite | ||
3 | Copyright (c) 2000 Waldo Bastian <bastian@kde.org> | ||
4 | Copyright (c) 2002 Joseph Wenninger <jowenn@kde.org> | ||
5 | |||
6 | $Id$ | ||
7 | |||
8 | This library is free software; you can redistribute it and/or | ||
9 | modify it under the terms of the GNU Library General Public | ||
10 | License version 2 as published by the Free Software Foundation. | ||
11 | |||
12 | This library is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | Library General Public License for more details. | ||
16 | |||
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 | ||
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
20 | Boston, MA 02111-1307, USA. | ||
21 | */ | ||
22 | |||
23 | |||
24 | #include "katebuffer.h" | ||
25 | |||
26 | // Includes for reading file | ||
27 | #include <sys/types.h> | ||
28 | #include <sys/stat.h> | ||
29 | #include <fcntl.h> | ||
30 | #include <errno.h> | ||
31 | #include <unistd.h> | ||
32 | |||
33 | #include <qfile.h> | ||
34 | #include <qtextstream.h> | ||
35 | |||
36 | #include <qtimer.h> | ||
37 | #include <qtextcodec.h> | ||
38 | |||
39 | // | ||
40 | |||
41 | #include <assert.h> | ||
42 | #include <kdebug.h> | ||
43 | |||
44 | /** | ||
45 | * Create an empty buffer. | ||
46 | */ | ||
47 | KWBuffer::KWBuffer() | ||
48 | { | ||
49 | clear(); | ||
50 | } | ||
51 | |||
52 | void | ||
53 | KWBuffer::clear() | ||
54 | { | ||
55 | m_stringListIt=0; | ||
56 | m_stringListCurrent=0; | ||
57 | m_stringList.clear(); | ||
58 | m_lineCount=1; | ||
59 | m_stringListIt = m_stringList.append(new TextLine()); | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Insert a file at line @p line in the buffer. | ||
64 | */ | ||
65 | void | ||
66 | KWBuffer::insertFile(int line, const QString &file, QTextCodec *codec) | ||
67 | { | ||
68 | if (line) { | ||
69 | qDebug("insert File only supports insertion at line 0 == file opening"); | ||
70 | return; | ||
71 | } | ||
72 | clear(); | ||
73 | QFile iofile(file); | ||
74 | iofile.open(IO_ReadOnly); | ||
75 | QTextStream stream(&iofile); | ||
76 | stream.setCodec(codec); | ||
77 | QString qsl; | ||
78 | int count=0; | ||
79 | for (count=0;((qsl=stream.readLine())!=QString::null);count++) | ||
80 | { | ||
81 | if (count==0) | ||
82 | { | ||
83 | (*m_stringListIt)->append(qsl.unicode(),qsl.length()); | ||
84 | } | ||
85 | else | ||
86 | { | ||
87 | TextLine::Ptr tl=new TextLine(); | ||
88 | tl ->append(qsl.unicode(),qsl.length()); | ||
89 | m_stringListIt=m_stringList.append(tl); | ||
90 | } | ||
91 | } | ||
92 | if (count!=0) | ||
93 | { | ||
94 | m_stringListCurrent=count-1; | ||
95 | m_lineCount=count; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | void | ||
100 | KWBuffer::loadFilePart() | ||
101 | { | ||
102 | } | ||
103 | |||
104 | |||
105 | void | ||
106 | KWBuffer::insertData(int line, const QByteArray &data, QTextCodec *codec) | ||
107 | { | ||
108 | } | ||
109 | |||
110 | void | ||
111 | KWBuffer::slotLoadFile() | ||
112 | { | ||
113 | loadFilePart(); | ||
114 | // emit linesChanged(m_totalLines); | ||
115 | emit linesChanged(20); | ||
116 | } | ||
117 | |||
118 | /** | ||
119 | * Return the total number of lines in the buffer. | ||
120 | */ | ||
121 | int | ||
122 | KWBuffer::count() | ||
123 | { | ||
124 | qDebug("m_stringList.count %d",m_stringList.count()); | ||
125 | return m_lineCount; | ||
126 | //return m_stringList.count(); | ||
127 | // return m_totalLines; | ||
128 | } | ||
129 | |||
130 | |||
131 | void KWBuffer::seek(int i) | ||
132 | { | ||
133 | if (m_stringListCurrent == i) | ||
134 | return; | ||
135 | while(m_stringListCurrent < i) | ||
136 | { | ||
137 | ++m_stringListCurrent; | ||
138 | ++m_stringListIt; | ||
139 | } | ||
140 | while(m_stringListCurrent > i) | ||
141 | { | ||
142 | --m_stringListCurrent; | ||
143 | --m_stringListIt; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | |||
148 | TextLine::Ptr | ||
149 | KWBuffer::line(int i) | ||
150 | { | ||
151 | if (i>=m_stringList.count()) return 0; | ||
152 | seek(i); | ||
153 | return *m_stringListIt; | ||
154 | } | ||
155 | |||
156 | void | ||
157 | KWBuffer::insertLine(int i, TextLine::Ptr line) | ||
158 | { | ||
159 | seek(i); | ||
160 | m_stringListIt = m_stringList.insert(m_stringListIt, line); | ||
161 | m_stringListCurrent = i; | ||
162 | m_lineCount++; | ||
163 | } | ||
164 | |||
165 | |||
166 | void | ||
167 | KWBuffer::removeLine(int i) | ||
168 | { | ||
169 | seek(i); | ||
170 | m_stringListIt = m_stringList.remove(m_stringListIt); | ||
171 | m_stringListCurrent = i; | ||
172 | m_lineCount--; | ||
173 | } | ||
174 | |||
175 | void | ||
176 | KWBuffer::changeLine(int i) | ||
177 | { | ||
178 | } | ||
179 | |||