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 | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katebuffer.cpp b/noncore/apps/tinykate/libkate/document/katebuffer.cpp index 4c15fd0..d89edbd 100644 --- a/noncore/apps/tinykate/libkate/document/katebuffer.cpp +++ b/noncore/apps/tinykate/libkate/document/katebuffer.cpp | |||
@@ -27,97 +27,100 @@ | |||
27 | /* OPIE */ | 27 | /* OPIE */ |
28 | #include <opie2/odebug.h> | 28 | #include <opie2/odebug.h> |
29 | 29 | ||
30 | /* QT */ | 30 | /* QT */ |
31 | #include <qfile.h> | 31 | #include <qfile.h> |
32 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
33 | #include <qtimer.h> | 33 | #include <qtimer.h> |
34 | #include <qtextcodec.h> | 34 | #include <qtextcodec.h> |
35 | 35 | ||
36 | /* STD */ | 36 | /* STD */ |
37 | // Includes for reading file | 37 | // Includes for reading file |
38 | #include <sys/types.h> | 38 | #include <sys/types.h> |
39 | #include <sys/stat.h> | 39 | #include <sys/stat.h> |
40 | #include <fcntl.h> | 40 | #include <fcntl.h> |
41 | #include <errno.h> | 41 | #include <errno.h> |
42 | #include <unistd.h> | 42 | #include <unistd.h> |
43 | #include <assert.h> | 43 | #include <assert.h> |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Create an empty buffer. | 46 | * Create an empty buffer. |
47 | */ | 47 | */ |
48 | KWBuffer::KWBuffer() | 48 | KWBuffer::KWBuffer() |
49 | { | 49 | { |
50 | clear(); | 50 | clear(); |
51 | } | 51 | } |
52 | 52 | ||
53 | void | 53 | void |
54 | KWBuffer::clear() | 54 | KWBuffer::clear() |
55 | { | 55 | { |
56 | m_stringListIt=0; | 56 | m_stringListIt=0; |
57 | m_stringListCurrent=0; | 57 | m_stringListCurrent=0; |
58 | m_stringList.clear(); | 58 | m_stringList.clear(); |
59 | m_lineCount=1; | 59 | m_lineCount=1; |
60 | m_stringListIt = m_stringList.append(new TextLine()); | 60 | m_stringListIt = m_stringList.append(new TextLine()); |
61 | } | 61 | } |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * Insert a file at line @p line in the buffer. | 64 | * Insert a file at line @p line in the buffer. |
65 | */ | 65 | */ |
66 | void | 66 | void |
67 | KWBuffer::insertFile(int line, const QString &file, QTextCodec *codec) | 67 | KWBuffer::insertFile(int line, const QString &file, QTextCodec *codec) |
68 | { | 68 | { |
69 | if (line) { | 69 | if (line) { |
70 | odebug << "insert File only supports insertion at line 0 == file opening" << oendl; | 70 | odebug << "insert File only supports insertion at line 0 == file opening" << oendl; |
71 | return; | 71 | return; |
72 | } | 72 | } |
73 | clear(); | 73 | clear(); |
74 | QFile iofile(file); | 74 | QFile iofile(file); |
75 | iofile.open(IO_ReadOnly); | 75 | if (!iofile.open(IO_ReadOnly)) { |
76 | owarn << "failed to open file " << iofile.name() << oendl; | ||
77 | return; | ||
78 | } | ||
76 | QTextStream stream(&iofile); | 79 | QTextStream stream(&iofile); |
77 | stream.setCodec(codec); | 80 | stream.setCodec(codec); |
78 | QString qsl; | 81 | QString qsl; |
79 | int count=0; | 82 | int count=0; |
80 | for (count=0;((qsl=stream.readLine())!=QString::null); count++) | 83 | for (count=0;((qsl=stream.readLine())!=QString::null); count++) |
81 | { | 84 | { |
82 | if (count==0) | 85 | if (count==0) |
83 | { | 86 | { |
84 | (*m_stringListIt)->append(qsl.unicode(),qsl.length()); | 87 | (*m_stringListIt)->append(qsl.unicode(),qsl.length()); |
85 | } | 88 | } |
86 | else | 89 | else |
87 | { | 90 | { |
88 | TextLine::Ptr tl=new TextLine(); | 91 | TextLine::Ptr tl=new TextLine(); |
89 | tl ->append(qsl.unicode(),qsl.length()); | 92 | tl ->append(qsl.unicode(),qsl.length()); |
90 | m_stringListIt=m_stringList.append(tl); | 93 | m_stringListIt=m_stringList.append(tl); |
91 | } | 94 | } |
92 | } | 95 | } |
93 | if (count!=0) | 96 | if (count!=0) |
94 | { | 97 | { |
95 | m_stringListCurrent=count-1; | 98 | m_stringListCurrent=count-1; |
96 | m_lineCount=count; | 99 | m_lineCount=count; |
97 | } | 100 | } |
98 | } | 101 | } |
99 | 102 | ||
100 | void | 103 | void |
101 | KWBuffer::loadFilePart() | 104 | KWBuffer::loadFilePart() |
102 | { | 105 | { |
103 | } | 106 | } |
104 | 107 | ||
105 | 108 | ||
106 | void | 109 | void |
107 | KWBuffer::insertData(int line, const QByteArray &data, QTextCodec *codec) | 110 | KWBuffer::insertData(int line, const QByteArray &data, QTextCodec *codec) |
108 | { | 111 | { |
109 | } | 112 | } |
110 | 113 | ||
111 | void | 114 | void |
112 | KWBuffer::slotLoadFile() | 115 | KWBuffer::slotLoadFile() |
113 | { | 116 | { |
114 | loadFilePart(); | 117 | loadFilePart(); |
115 | // emit linesChanged(m_totalLines); | 118 | // emit linesChanged(m_totalLines); |
116 | emit linesChanged(20); | 119 | emit linesChanged(20); |
117 | } | 120 | } |
118 | 121 | ||
119 | /** | 122 | /** |
120 | * Return the total number of lines in the buffer. | 123 | * Return the total number of lines in the buffer. |
121 | */ | 124 | */ |
122 | int | 125 | int |
123 | KWBuffer::count() | 126 | KWBuffer::count() |