summaryrefslogtreecommitdiffstats
path: root/konsole/konsole/TEHistory.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-12-11 20:21:27 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-12-11 20:21:27 +0000
commit10e41144596fc9ced40fc349d9ecd099b1c2ea19 (patch)
tree88ab04e475ff5a4cd889cb082f5760b6e0bf5e4e /konsole/konsole/TEHistory.cpp
parent4aed2c8219774f5d797760606b8489a92ddc5163 (diff)
downloadtdebase-10e41144.tar.gz
tdebase-10e41144.zip
Initial import of Trinity 3.5.11 to kdebase
Extends krandrtray, adds iccconfig kcontrol module, adds run dialog autocomplete and lots of bugfixes Will need to check for commit warnings and repair as encountered Also needs full compile test git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1061475 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'konsole/konsole/TEHistory.cpp')
-rw-r--r--konsole/konsole/TEHistory.cpp90
1 files changed, 50 insertions, 40 deletions
diff --git a/konsole/konsole/TEHistory.cpp b/konsole/konsole/TEHistory.cpp
index 5a0ee5477..a24635acb 100644
--- a/konsole/konsole/TEHistory.cpp
+++ b/konsole/konsole/TEHistory.cpp
@@ -207,23 +207,24 @@ void HistoryScrollFile::addLine(bool previousWrapped)
// History Scroll Buffer //////////////////////////////////////
HistoryScrollBuffer::HistoryScrollBuffer(unsigned int maxNbLines)
: HistoryScroll(new HistoryTypeBuffer(maxNbLines)),
- m_histBuffer(maxNbLines),
- m_wrappedLine(maxNbLines),
m_maxNbLines(maxNbLines),
m_nbLines(0),
- m_arrayIndex(maxNbLines - 1)
+ m_arrayIndex(0),
+ m_buffFilled(false)
{
+ m_histBuffer.setAutoDelete(true);
+ m_histBuffer.resize(maxNbLines);
+ m_wrappedLine.resize(maxNbLines);
}
HistoryScrollBuffer::~HistoryScrollBuffer()
{
- for(size_t line = 0; line < m_nbLines; ++line) {
- delete m_histBuffer[adjustLineNb(line)];
- }
}
void HistoryScrollBuffer::addCells(ca a[], int count)
{
+ //unsigned int nbLines = countLines(bytes, len);
+
histline* newLine = new histline;
newLine->duplicate(a, count);
@@ -231,15 +232,45 @@ void HistoryScrollBuffer::addCells(ca a[], int count)
++m_arrayIndex;
if (m_arrayIndex >= m_maxNbLines) {
m_arrayIndex = 0;
- }
+ m_buffFilled = true;
+ }
- if (m_nbLines < m_maxNbLines) ++m_nbLines;
+ // FIXME: See BR96605
+ if (m_nbLines < m_maxNbLines - 1) ++m_nbLines;
- delete m_histBuffer[m_arrayIndex];
+ // m_histBuffer.remove(m_arrayIndex); // not necessary
m_histBuffer.insert(m_arrayIndex, newLine);
m_wrappedLine.clearBit(m_arrayIndex);
}
+void HistoryScrollBuffer::normalize()
+{
+ if (!m_buffFilled || !m_arrayIndex) return;
+ QPtrVector<histline> newHistBuffer;
+ newHistBuffer.resize(m_maxNbLines);
+ QBitArray newWrappedLine;
+ newWrappedLine.resize(m_maxNbLines);
+ for(int i = 0; i < (int) m_maxNbLines-2; i++)
+ {
+ int lineno = adjustLineNb(i);
+ newHistBuffer.insert(i+1, m_histBuffer[lineno]);
+ newWrappedLine.setBit(i+1, m_wrappedLine[lineno]);
+ }
+ m_histBuffer.setAutoDelete(false);
+ // Qt 2.3: QVector copy assignment is buggy :-(
+ // m_histBuffer = newHistBuffer;
+ for(int i = 0; i < (int) m_maxNbLines; i++)
+ {
+ m_histBuffer.insert(i, newHistBuffer[i]);
+ m_wrappedLine.setBit(i, newWrappedLine[i]);
+ }
+ m_histBuffer.setAutoDelete(true);
+
+ m_arrayIndex = m_maxNbLines;
+ m_buffFilled = false;
+ m_nbLines = m_maxNbLines-2;
+}
+
void HistoryScrollBuffer::addLine(bool previousWrapped)
{
m_wrappedLine.setBit(m_arrayIndex,previousWrapped);
@@ -284,40 +315,19 @@ void HistoryScrollBuffer::getCells(int lineno, int colno, int count, ca res[])
return;
}
- assert(colno <= (int) l->size() - count);
+ assert((colno < (int) l->size()) || (count == 0));
memcpy(res, l->data() + colno, count * sizeof(ca));
}
void HistoryScrollBuffer::setMaxNbLines(unsigned int nbLines)
{
- QPtrVector<histline> newHistBuffer(nbLines);
- QBitArray newWrappedLine(nbLines);
-
- size_t preservedLines = (nbLines > m_nbLines ? m_nbLines : nbLines); //min
-
- // delete any lines that will be lost
- size_t lineOld;
- for(lineOld = 0; lineOld < m_nbLines - preservedLines; ++lineOld) {
- delete m_histBuffer[adjustLineNb(lineOld)];
- }
-
- // copy the lines to new arrays
- size_t indexNew = 0;
- while(indexNew < preservedLines) {
- newHistBuffer.insert(indexNew, m_histBuffer[adjustLineNb(lineOld)]);
- newWrappedLine.setBit(indexNew, m_wrappedLine[adjustLineNb(lineOld)]);
- ++lineOld;
- ++indexNew;
- }
- m_arrayIndex = preservedLines - 1;
-
- m_histBuffer = newHistBuffer;
- m_wrappedLine = newWrappedLine;
-
+ normalize();
m_maxNbLines = nbLines;
- if (m_nbLines > m_maxNbLines)
- m_nbLines = m_maxNbLines;
+ m_histBuffer.resize(m_maxNbLines);
+ m_wrappedLine.resize(m_maxNbLines);
+ if (m_nbLines > m_maxNbLines - 2)
+ m_nbLines = m_maxNbLines -2;
delete m_histType;
m_histType = new HistoryTypeBuffer(nbLines);
@@ -325,10 +335,10 @@ void HistoryScrollBuffer::setMaxNbLines(unsigned int nbLines)
int HistoryScrollBuffer::adjustLineNb(int lineno)
{
- // lineno = 0: oldest line
- // lineno = getLines() - 1: newest line
-
- return (m_arrayIndex + lineno - (m_nbLines - 1) + m_maxNbLines) % m_maxNbLines;
+ if (m_buffFilled)
+ return (lineno + m_arrayIndex + 2) % m_maxNbLines;
+ else
+ return lineno ? lineno + 1 : 0;
}