Konsole
History.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef TEHISTORY_H
00022 #define TEHISTORY_H
00023
00024
00025 #include <QtCore/QBitRef>
00026 #include <QtCore/QHash>
00027 #include <QtCore/QVector>
00028
00029
00030 #include <ktemporaryfile.h>
00031
00032
00033 #include "BlockArray.h"
00034 #include "Character.h"
00035
00036 namespace Konsole
00037 {
00038
00039 #if 1
00040
00041
00042
00043
00044 class HistoryFile
00045 {
00046 public:
00047 HistoryFile();
00048 virtual ~HistoryFile();
00049
00050 virtual void add(const unsigned char* bytes, int len);
00051 virtual void get(unsigned char* bytes, int len, int loc);
00052 virtual int len();
00053
00054
00055 void map();
00056
00057 void unmap();
00058
00059 bool isMapped();
00060
00061
00062 private:
00063 int ion;
00064 int length;
00065 KTemporaryFile tmpFile;
00066
00067
00068 char* fileMap;
00069
00070
00071
00072
00073
00074 int readWriteBalance;
00075
00076
00077 static const int MAP_THRESHOLD = -1000;
00078 };
00079 #endif
00080
00082
00084
00086 class HistoryType;
00087
00088 class HistoryScroll
00089 {
00090 public:
00091 HistoryScroll(HistoryType*);
00092 virtual ~HistoryScroll();
00093
00094 virtual bool hasScroll();
00095
00096
00097 virtual int getLines() = 0;
00098 virtual int getLineLen(int lineno) = 0;
00099 virtual void getCells(int lineno, int colno, int count, Character res[]) = 0;
00100 virtual bool isWrappedLine(int lineno) = 0;
00101
00102
00103 Character getCell(int lineno, int colno) { Character res; getCells(lineno,colno,1,&res); return res; }
00104
00105
00106 virtual void addCells(const Character a[], int count) = 0;
00107
00108
00109 virtual void addCellsVector(const QVector<Character>& cells)
00110 {
00111 addCells(cells.data(),cells.size());
00112 }
00113
00114 virtual void addLine(bool previousWrapped=false) = 0;
00115
00116
00117
00118
00119
00120
00121 const HistoryType& getType() { return *m_histType; }
00122
00123 protected:
00124 HistoryType* m_histType;
00125
00126 };
00127
00128 #if 1
00129
00131
00133
00134 class HistoryScrollFile : public HistoryScroll
00135 {
00136 public:
00137 HistoryScrollFile(const QString &logFileName);
00138 virtual ~HistoryScrollFile();
00139
00140 virtual int getLines();
00141 virtual int getLineLen(int lineno);
00142 virtual void getCells(int lineno, int colno, int count, Character res[]);
00143 virtual bool isWrappedLine(int lineno);
00144
00145 virtual void addCells(const Character a[], int count);
00146 virtual void addLine(bool previousWrapped=false);
00147
00148 private:
00149 int startOfLine(int lineno);
00150
00151 QString m_logFileName;
00152 HistoryFile index;
00153 HistoryFile cells;
00154 HistoryFile lineflags;
00155 };
00156
00157
00159
00161 class HistoryScrollBuffer : public HistoryScroll
00162 {
00163 public:
00164 typedef QVector<Character> HistoryLine;
00165
00166 HistoryScrollBuffer(unsigned int maxNbLines = 1000);
00167 virtual ~HistoryScrollBuffer();
00168
00169 virtual int getLines();
00170 virtual int getLineLen(int lineno);
00171 virtual void getCells(int lineno, int colno, int count, Character res[]);
00172 virtual bool isWrappedLine(int lineno);
00173
00174 virtual void addCells(const Character a[], int count);
00175 virtual void addCellsVector(const QVector<Character>& cells);
00176 virtual void addLine(bool previousWrapped=false);
00177
00178 void setMaxNbLines(unsigned int nbLines);
00179 unsigned int maxNbLines() { return _maxLineCount; }
00180
00181
00182 private:
00183 int bufferIndex(int lineNumber);
00184
00185 HistoryLine* _historyBuffer;
00186 QBitArray _wrappedLine;
00187 int _maxLineCount;
00188 int _usedLines;
00189 int _head;
00190
00191
00192
00193
00194
00195
00196
00197 };
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 #endif
00214
00216
00218 class HistoryScrollNone : public HistoryScroll
00219 {
00220 public:
00221 HistoryScrollNone();
00222 virtual ~HistoryScrollNone();
00223
00224 virtual bool hasScroll();
00225
00226 virtual int getLines();
00227 virtual int getLineLen(int lineno);
00228 virtual void getCells(int lineno, int colno, int count, Character res[]);
00229 virtual bool isWrappedLine(int lineno);
00230
00231 virtual void addCells(const Character a[], int count);
00232 virtual void addLine(bool previousWrapped=false);
00233 };
00234
00236
00238 class HistoryScrollBlockArray : public HistoryScroll
00239 {
00240 public:
00241 HistoryScrollBlockArray(size_t size);
00242 virtual ~HistoryScrollBlockArray();
00243
00244 virtual int getLines();
00245 virtual int getLineLen(int lineno);
00246 virtual void getCells(int lineno, int colno, int count, Character res[]);
00247 virtual bool isWrappedLine(int lineno);
00248
00249 virtual void addCells(const Character a[], int count);
00250 virtual void addLine(bool previousWrapped=false);
00251
00252 protected:
00253 BlockArray m_blockArray;
00254 QHash<int,size_t> m_lineLengths;
00255 };
00256
00258
00260
00261 class HistoryType
00262 {
00263 public:
00264 HistoryType();
00265 virtual ~HistoryType();
00266
00271 virtual bool isEnabled() const = 0;
00275 bool isUnlimited() const { return maximumLineCount() == 0; }
00280 virtual int maximumLineCount() const = 0;
00281
00282 virtual HistoryScroll* scroll(HistoryScroll *) const = 0;
00283 };
00284
00285 class HistoryTypeNone : public HistoryType
00286 {
00287 public:
00288 HistoryTypeNone();
00289
00290 virtual bool isEnabled() const;
00291 virtual int maximumLineCount() const;
00292
00293 virtual HistoryScroll* scroll(HistoryScroll *) const;
00294 };
00295
00296 class HistoryTypeBlockArray : public HistoryType
00297 {
00298 public:
00299 HistoryTypeBlockArray(size_t size);
00300
00301 virtual bool isEnabled() const;
00302 virtual int maximumLineCount() const;
00303
00304 virtual HistoryScroll* scroll(HistoryScroll *) const;
00305
00306 protected:
00307 size_t m_size;
00308 };
00309
00310 #if 1
00311 class HistoryTypeFile : public HistoryType
00312 {
00313 public:
00314 HistoryTypeFile(const QString& fileName=QString());
00315
00316 virtual bool isEnabled() const;
00317 virtual const QString& getFileName() const;
00318 virtual int maximumLineCount() const;
00319
00320 virtual HistoryScroll* scroll(HistoryScroll *) const;
00321
00322 protected:
00323 QString m_fileName;
00324 };
00325
00326
00327 class HistoryTypeBuffer : public HistoryType
00328 {
00329 friend class HistoryScrollBuffer;
00330
00331 public:
00332 HistoryTypeBuffer(unsigned int nbLines);
00333
00334 virtual bool isEnabled() const;
00335 virtual int maximumLineCount() const;
00336
00337 virtual HistoryScroll* scroll(HistoryScroll *) const;
00338
00339 protected:
00340 unsigned int m_nbLines;
00341 };
00342
00343 #endif
00344
00345 }
00346
00347 #endif // TEHISTORY_H