[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    PATCH (was Re: konsole's history : is anyone taking care of it ?)
From:       Guillaume Laurent <glaurent () telegraph-road ! org>
Date:       2001-05-27 13:47:15
[Download RAW message or body]

On Friday 25 May 2001 12:48, aleXXX wrote:
> On Friday 25 May 2001 11:19, Guillaume Laurent wrote:
> > It seems that konsole's 'history' feature has been disabled for a while
> > now. I suppose this is because of the hist. files ever growing and taking
> > up all space in /tmp. I'd like to try to fix that, but before I want to
> > make sure that nobody is working on it.
>
> I think so.

Here's a pre-version of a patch. I need a bit of help and advice on the 
following unresolved issues :

- there's a focus pb with the History Type... dialog : when clicking on 
"Off", the "Help" button gets keybd focus. How can I prevent this ?

- Right now, the file name is edited through a mere QLineEdit. The ideal 
would be a KFileDialog but that means linking with libkfile which I suppose 
isn't too good on startup time. No idea on what to do here. A possibility 
would be to let this be set from the kcmodule as a pattern with '%p' for PID 
or something...

- Session management on these new parameters isn't done yet. Should I add all 
the new parameters in the kcmodule ?

-- 
					Guillaume.
					http://www.telegraph-road.org

["konsole_history_patch_pre1.patch" (text/x-c)]

Index: include/TEHistory.h
===================================================================
RCS file: /home/kde/kdebase/konsole/include/TEHistory.h,v
retrieving revision 1.4
diff -u -r1.4 TEHistory.h
--- include/TEHistory.h	2001/02/01 21:54:28	1.4
+++ include/TEHistory.h	2001/05/27 13:39:09
@@ -13,57 +13,201 @@
 #ifndef TEHISTORY_H
 #define TEHISTORY_H
 
+#include <qcstring.h>
+#include <qvector.h>
+
 #include "TECommon.h"
 
 /*
    An extendable tmpfile(1) based buffer.
 */
-class HistoryBuffer
-{
-public:
-  HistoryBuffer();
- ~HistoryBuffer();
 
+class HistoryFile
+{
 public:
-  void setScroll(bool on);
-  bool hasScroll();
+  HistoryFile();
+  virtual ~HistoryFile();
 
-public:
-  void add(const unsigned char* bytes, int len);
-  void get(unsigned char* bytes, int len, int loc);
-  int  len();
+  virtual void add(const unsigned char* bytes, int len);
+  virtual void get(unsigned char* bytes, int len, int loc);
+  virtual int  len();
 
 private:
   int  ion;
   int  length;
 };
 
+//////////////////////////////////////////////////////////////////////
+
+//////////////////////////////////////////////////////////////////////
+// Abstract base class for file and buffer versions
+//////////////////////////////////////////////////////////////////////
+class HistoryType;
+
 class HistoryScroll
 {
 public:
-  HistoryScroll();
- ~HistoryScroll();
+  HistoryScroll(HistoryType*);
+ virtual ~HistoryScroll();
 
-public:
-  void setScroll(bool on);
-  bool hasScroll();
+  virtual bool hasScroll();
 
-public: // access to history
-  int  getLines();
-  int  getLineLen(int lineno);
-  void getCells(int lineno, int colno, int count, ca res[]);
+  // access to history
+  virtual int  getLines() = 0;
+  virtual int  getLineLen(int lineno) = 0;
+  virtual void getCells(int lineno, int colno, int count, ca res[]) = 0;
 
-public: // backward compatibility (obsolete)
+  // backward compatibility (obsolete)
   ca   getCell(int lineno, int colno) { ca res; getCells(lineno,colno,1,&res); \
return res; } +
+  // adding lines.
+  virtual void addCells(ca a[], int count) = 0;
+  virtual void addLine() = 0;
+
+  const HistoryType& getType() { return *m_histType; }
+
+protected:
+  HistoryType* m_histType;
+
+};
+
+//////////////////////////////////////////////////////////////////////
+// File-based history (e.g. file log, no limitation in length)
+//////////////////////////////////////////////////////////////////////
+
+class HistoryScrollFile : public HistoryScroll
+{
+public:
+  HistoryScrollFile(const QString &logFileName);
+  virtual ~HistoryScrollFile();
 
-public: // adding lines.
-  void addCells(ca a[], int count);
-  void addLine();
+  virtual int  getLines();
+  virtual int  getLineLen(int lineno);
+  virtual void getCells(int lineno, int colno, int count, ca res[]);
 
+  virtual void addCells(ca a[], int count);
+  virtual void addLine();
+
 private:
   int startOfLine(int lineno);
-  HistoryBuffer index; // lines Row(int)
-  HistoryBuffer cells; // text  Row(ca)
+
+  QString m_logFileName;
+  HistoryFile index; // lines Row(int)
+  HistoryFile cells; // text  Row(ca)
+};
+
+
+//////////////////////////////////////////////////////////////////////
+// Buffer-based history (limited to a fixed nb of lines)
+//////////////////////////////////////////////////////////////////////
+class HistoryScrollBuffer : public HistoryScroll
+{
+public:
+  typedef QArray<ca> histline;
+
+  HistoryScrollBuffer(unsigned int maxNbLines = 1000);
+  virtual ~HistoryScrollBuffer();
+
+  virtual int  getLines();
+  virtual int  getLineLen(int lineno);
+  virtual void getCells(int lineno, int colno, int count, ca res[]);
+
+  virtual void addCells(ca a[], int count);
+  virtual void addLine();
+
+  void setMaxNbLines(unsigned int nbLines);
+  unsigned int maxNbLines() { return m_maxNbLines; }
+
+private:
+
+  bool m_hasScroll;
+  QVector<histline> m_histBuffer;
+  unsigned int m_maxNbLines;
+  unsigned int m_nbLines;
+  unsigned int m_arrayIndex;
+  
+};
+
+//////////////////////////////////////////////////////////////////////
+// Nothing-based history (no history :-)
+//////////////////////////////////////////////////////////////////////
+class HistoryScrollNone : public HistoryScroll
+{
+public:
+  HistoryScrollNone();
+  virtual ~HistoryScrollNone();
+
+  virtual bool hasScroll();
+
+  virtual int  getLines();
+  virtual int  getLineLen(int lineno);
+  virtual void getCells(int lineno, int colno, int count, ca res[]);
+
+  virtual void addCells(ca a[], int count);
+  virtual void addLine();
+};
+
+//////////////////////////////////////////////////////////////////////
+// History type
+//////////////////////////////////////////////////////////////////////
+
+class HistoryType
+{
+public:
+  HistoryType();
+  virtual ~HistoryType();
+
+  virtual bool isOn() const = 0;
+  virtual unsigned int getNbLines() const = 0;
+  virtual const QString& getFileName() const = 0;
+
+  virtual HistoryScroll* getScroll() const = 0;
+};
+
+class HistoryTypeNone : public HistoryType
+{
+public:
+  HistoryTypeNone();
+
+  virtual bool isOn() const;
+  virtual unsigned int getNbLines() const;
+  virtual const QString& getFileName() const;
+
+  virtual HistoryScroll* getScroll() const;
 };
+
+
+class HistoryTypeBuffer : public HistoryType
+{
+public:
+  HistoryTypeBuffer(unsigned int nbLines);
+  
+  virtual bool isOn() const;
+  virtual unsigned int getNbLines() const;
+  virtual const QString& getFileName() const;
+
+  virtual HistoryScroll* getScroll() const;
+
+protected:
+  unsigned int m_nbLines;
+};
+
+
+class HistoryTypeFile : public HistoryType
+{
+public:
+  HistoryTypeFile(const QString& fileName);
+
+  virtual bool isOn() const;
+  virtual unsigned int getNbLines() const;
+  virtual const QString& getFileName() const;
+
+  virtual HistoryScroll* getScroll() const;
+
+protected:
+  QString m_fileName;
+};
+
+
 
 #endif // TEHISTORY_H
Index: include/TEScreen.h
===================================================================
RCS file: /home/kde/kdebase/konsole/include/TEScreen.h,v
retrieving revision 1.10
diff -u -r1.10 TEScreen.h
--- include/TEScreen.h	2000/01/29 01:47:35	1.10
+++ include/TEScreen.h	2001/05/27 13:39:10
@@ -143,7 +143,8 @@
     int  getHistCursor();
 
     int  getHistLines ();
-    void setScroll(bool on);
+    void setScroll(const HistoryType&);
+    const HistoryType& getScroll();
     bool hasScroll();
 
     //
@@ -192,7 +193,7 @@
     // history buffer ---------------
 
     int histCursor;   // display position relative to start of the history buffer
-    HistoryScroll hist;
+    HistoryScroll *hist;
     
     // cursor location
 
Index: include/TEmulation.h
===================================================================
RCS file: /home/kde/kdebase/konsole/include/TEmulation.h,v
retrieving revision 1.11
diff -u -r1.11 TEmulation.h
--- include/TEmulation.h	2001/03/19 14:34:01	1.11
+++ include/TEmulation.h	2001/05/27 13:39:10
@@ -29,8 +29,8 @@
   ~TEmulation();
 
 public:
-  virtual void setHistory(bool on);
-  virtual bool history();
+  virtual void setHistory(const HistoryType&);
+  virtual const HistoryType& history();
 
 public slots: // signals incoming from TEWidget
 
@@ -80,7 +80,6 @@
   void setCodec(int c); // codec number, 0 = locale, 1=utf8
 
   QTextCodec* codec;
-  QTextCodec* localeCodec;
   QTextDecoder* decoder;
 
   KeyTrans* keytrans;
@@ -101,7 +100,6 @@
 
   QTimer bulk_timer;
   int    bulk_nlcnt;   // bulk newline counter
-  char*  SelectedText;
   int    bulk_incnt;   // bulk counter
 
 
Index: include/konsole.h
===================================================================
RCS file: /home/kde/kdebase/konsole/include/konsole.h,v
retrieving revision 1.39
diff -u -r1.39 konsole.h
--- include/konsole.h	2001/05/20 20:41:28	1.39
+++ include/konsole.h	2001/05/27 13:39:10
@@ -98,6 +98,7 @@
   void slotToggleMenubar();
   void slotToggleFrame();
   void slotRenameSession();
+  void slotHistoryType();
   void slotWordSeps();
   void slotSelectSize();
   void slotSelectFont();
@@ -115,8 +116,6 @@
   void addSession(TESession* s);
   void setColorPixmaps();
 
-  void setHistory(bool);
-
   void setSchema(const QString & path);
   void setSchema(ColorSchema* s);
   void setFont(int fontno);
@@ -196,5 +195,36 @@
 
   QString     title;
 };
+
+class QLineEdit;
+class QSpinBox;
+#include <kdialogbase.h>
+
+class HistoryTypeDialog : public KDialogBase 
+{
+    Q_OBJECT
+public:
+  HistoryTypeDialog(const HistoryType& histType, QWidget *parent);
+
+public slots:
+
+  void slotFileHistChoosen();
+  void slotBufferHistChoosen();
+  void slotNoHistChoosen();
+
+  unsigned int nbLines();
+  QString logFileName();
+
+  bool isBufferBased() { return m_isBufferBased; }
+  bool isOff()         { return m_isOff; }
+
+protected:
+  QLineEdit* m_logFileName;
+  QSpinBox*  m_nbLogLines;
+  bool m_isBufferBased;
+  bool m_isOff;
+};
+
+
 
 #endif
Index: include/session.h
===================================================================
RCS file: /home/kde/kdebase/konsole/include/session.h,v
retrieving revision 1.17
diff -u -r1.17 session.h
--- include/session.h	2001/03/10 21:13:43	1.17
+++ include/session.h	2001/05/27 13:39:11
@@ -40,10 +40,11 @@
   int fontNo();
   const char* emuName();
   const QString& Title();
-  bool history();
   int keymap();
 
-  void setHistory(bool on);
+  void setHistory(const HistoryType&);
+  const HistoryType& history();
+
   void setSchemaNo(int sn);
   void setKeymapNo(int kn);
   void setFontNo(int fn);
Index: src/TEHistory.C
===================================================================
RCS file: /home/kde/kdebase/konsole/src/TEHistory.C,v
retrieving revision 1.12
diff -u -r1.12 TEHistory.C
--- src/TEHistory.C	2001/03/17 14:30:42	1.12
+++ src/TEHistory.C	2001/05/27 13:39:11
@@ -67,73 +67,71 @@
 }
 
 
-// History Buffer ///////////////////////////////////////////
+// History File ///////////////////////////////////////////
 
 /*
-   A Row(X) data type which allows adding elements to the end.
+  A Row(X) data type which allows adding elements to the end.
 */
 
-HistoryBuffer::HistoryBuffer()
+HistoryFile::HistoryFile()
+  : ion(-1),
+    length(0)
 {
-  ion    = -1;
-  length = 0;
+  FILE* tmp = tmpfile(); if (!tmp) { perror("konsole: cannot open temp file.\n"); \
return; } +  ion = dup(fileno(tmp)); if (ion<0) perror("konsole: cannot dup temp \
file.\n"); +  fclose(tmp);
 }
 
-HistoryBuffer::~HistoryBuffer()
+HistoryFile::~HistoryFile()
 {
-  setScroll(FALSE);
+  close(ion);
 }
 
-void HistoryBuffer::setScroll(bool on)
+void HistoryFile::add(const unsigned char* bytes, int len)
 {
-  if (on == hasScroll()) return;
+  int rc = 0;
 
-  if (on)
-  {
-    assert( ion < 0 );
-    assert( length == 0);
-    FILE* tmp = tmpfile(); if (!tmp) { perror("konsole: cannot open temp file.\n"); \
                return; }
-    ion = dup(fileno(tmp)); if (ion<0) perror("konsole: cannot dup temp file.\n");
-    fclose(tmp);
-  }
-  else
-  {
-    assert( ion >= 0 );
-    close(ion);
-    ion    = -1;
-    length = 0;
-  }
+  rc = lseek(ion,length,SEEK_SET); if (rc < 0) { perror("HistoryFile::add.seek"); \
return; } +  rc = write(ion,bytes,len);       if (rc < 0) { \
perror("HistoryFile::add.write"); return; } +  length += rc;
 }
 
-bool HistoryBuffer::hasScroll()
+void HistoryFile::get(unsigned char* bytes, int len, int loc)
 {
-  return ion >= 0;
-}
-
-void HistoryBuffer::add(const unsigned char* bytes, int len)
-{ int rc;
-  assert(hasScroll());
-  rc = lseek(ion,length,SEEK_SET); if (rc < 0) { perror("HistoryBuffer::add.seek"); \
                setScroll(FALSE); return; }
-  rc = write(ion,bytes,len);       if (rc < 0) { perror("HistoryBuffer::add.write"); \
                setScroll(FALSE); return; }
-  length += rc;
-}
+  int rc = 0;
 
-void HistoryBuffer::get(unsigned char* bytes, int len, int loc)
-{ int rc;
-  assert(hasScroll());
   if (loc < 0 || len < 0 || loc + len > length)
     fprintf(stderr,"getHist(...,%d,%d): invalid args.\n",len,loc);
-  rc = lseek(ion,loc,SEEK_SET); if (rc < 0) { perror("HistoryBuffer::get.seek"); \
                setScroll(FALSE); return; }
-  rc = read(ion,bytes,len);     if (rc < 0) { perror("HistoryBuffer::get.read"); \
setScroll(FALSE); return; } +  rc = lseek(ion,loc,SEEK_SET); if (rc < 0) { \
perror("HistoryFile::get.seek"); return; } +  rc = read(ion,bytes,len);     if (rc < \
0) { perror("HistoryFile::get.read"); return; }  }
 
-int HistoryBuffer::len()
+int HistoryFile::len()
 {
   return length;
 }
+
+// History Scroll abstract base class //////////////////////////////////////
 
-// History Scroll //////////////////////////////////////
 
+HistoryScroll::HistoryScroll(HistoryType* t)
+  : m_histType(t)
+{
+}
+
+HistoryScroll::~HistoryScroll()
+{
+  delete m_histType;
+}
+
+bool HistoryScroll::hasScroll()
+{
+  return true;
+}
+
+
+// History Scroll File //////////////////////////////////////
+
 /* 
    The history scroll makes a Row(Row(Cell)) from
    two history buffers. The index buffer contains
@@ -145,64 +143,259 @@
    at 0 in cells.
 */
 
-HistoryScroll::HistoryScroll()
+HistoryScrollFile::HistoryScrollFile(const QString &logFileName)
+  : HistoryScroll(new HistoryTypeFile(logFileName)),
+  m_logFileName(logFileName)
 {
 }
 
-HistoryScroll::~HistoryScroll()
+HistoryScrollFile::~HistoryScrollFile()
 {
 }
  
-void HistoryScroll::setScroll(bool on)
-{
-  index.setScroll(on);
-  cells.setScroll(on);
-}
- 
-bool HistoryScroll::hasScroll()
-{
-  return index.hasScroll() && cells.hasScroll();
-}
-
-int HistoryScroll::getLines()
+int HistoryScrollFile::getLines()
 {
-  if (!hasScroll()) return 0;
   return index.len() / sizeof(int);
 }
 
-int HistoryScroll::getLineLen(int lineno)
+int HistoryScrollFile::getLineLen(int lineno)
 {
-  if (!hasScroll()) return 0;
   return (startOfLine(lineno+1) - startOfLine(lineno)) / sizeof(ca);
 }
 
-int HistoryScroll::startOfLine(int lineno)
+int HistoryScrollFile::startOfLine(int lineno)
 {
   if (lineno <= 0) return 0;
-  if (!hasScroll()) return 0;
   if (lineno <= getLines())
-  { int res;
+    { int res;
     index.get((unsigned char*)&res,sizeof(int),(lineno-1)*sizeof(int));
     return res;
-  }
+    }
   return cells.len();
 }
 
-void HistoryScroll::getCells(int lineno, int colno, int count, ca res[])
+void HistoryScrollFile::getCells(int lineno, int colno, int count, ca res[])
 {
-  assert(hasScroll());
   cells.get((unsigned \
char*)res,count*sizeof(ca),startOfLine(lineno)+colno*sizeof(ca));  }
 
-void HistoryScroll::addCells(ca text[], int count)
+void HistoryScrollFile::addCells(ca text[], int count)
 {
-  if (!hasScroll()) return;
   cells.add((unsigned char*)text,count*sizeof(ca));
 }
 
-void HistoryScroll::addLine()
+void HistoryScrollFile::addLine()
 {
-  if (!hasScroll()) return;
   int locn = cells.len();
   index.add((unsigned char*)&locn,sizeof(int));
 }
+
+
+// History Scroll Buffer //////////////////////////////////////
+HistoryScrollBuffer::HistoryScrollBuffer(unsigned int maxNbLines)
+  : HistoryScroll(new HistoryTypeBuffer(maxNbLines)),
+    m_maxNbLines(maxNbLines),
+    m_nbLines(0),
+    m_arrayIndex(0)
+{
+  m_histBuffer.setAutoDelete(true);
+  m_histBuffer.resize(maxNbLines);
+}
+
+HistoryScrollBuffer::~HistoryScrollBuffer()
+{
+}
+
+void HistoryScrollBuffer::addCells(ca a[], int count)
+{
+  //unsigned int nbLines = countLines(bytes, len);
+
+  histline* newLine = new histline;
+
+  newLine->duplicate(a, count);
+  
+  ++m_arrayIndex;
+  if (m_arrayIndex >= m_maxNbLines) m_arrayIndex = 0;
+
+  if (m_nbLines < m_maxNbLines - 1) ++m_nbLines;
+
+  // m_histBuffer.remove(m_arrayIndex); // not necessary
+  m_histBuffer.insert(m_arrayIndex, newLine);
+}
+
+void HistoryScrollBuffer::addLine()
+{
+  // ? Do nothing
+}
+
+int HistoryScrollBuffer::getLines()
+{
+  return m_nbLines; // m_histBuffer.size();
+}
+
+int HistoryScrollBuffer::getLineLen(int lineno)
+{
+  if (lineno >= m_maxNbLines) return 0;
+  
+  histline *l = m_histBuffer[lineno];
+
+  return l ? l->size() : 0;
+}
+
+
+void HistoryScrollBuffer::getCells(int lineno, int colno, int count, ca res[])
+{
+  if (!count) return;
+
+  assert (lineno < m_maxNbLines);
+  
+  histline *l = m_histBuffer[lineno];
+
+  if (!l) {
+    memset(res, 0, count * sizeof(ca));
+    return;
+  }
+
+  assert(colno < l->size() || count == 0);
+    
+  memcpy(res, l->data() + colno, count * sizeof(ca));
+}
+
+void HistoryScrollBuffer::setMaxNbLines(unsigned int nbLines)
+{
+  m_maxNbLines = nbLines;
+  m_histBuffer.resize(m_maxNbLines);
+}
+
+// History Scroll None //////////////////////////////////////
+
+HistoryScrollNone::HistoryScrollNone()
+  : HistoryScroll(new HistoryTypeNone())
+{
+}
+
+HistoryScrollNone::~HistoryScrollNone()
+{
+}
+
+bool HistoryScrollNone::hasScroll()
+{
+  return false;
+}
+
+int  HistoryScrollNone::getLines()
+{
+  return 0;
+}
+
+int  HistoryScrollNone::getLineLen(int lineno)
+{
+  return 0;
+}
+
+void HistoryScrollNone::getCells(int lineno, int colno, int count, ca res[])
+{
+}
+
+void HistoryScrollNone::addCells(ca a[], int count)
+{
+}
+
+void HistoryScrollNone::addLine()
+{
+}
+
+//////////////////////////////////////////////////////////////////////
+// History Types
+//////////////////////////////////////////////////////////////////////
+
+HistoryType::HistoryType()
+{
+}
+
+HistoryType::~HistoryType()
+{
+}
+
+//////////////////////////////
+
+HistoryTypeNone::HistoryTypeNone()
+{
+}
+
+bool HistoryTypeNone::isOn() const
+{
+  return false;
+}
+
+unsigned int HistoryTypeNone::getNbLines() const
+{
+  return 0;
+}
+
+const QString& HistoryTypeNone::getFileName() const
+{
+  return QString::null;
+}
+
+HistoryScroll* HistoryTypeNone::getScroll() const
+{
+  return new HistoryScrollNone();
+}
+
+
+//////////////////////////////
+
+HistoryTypeBuffer::HistoryTypeBuffer(unsigned int nbLines)
+  : m_nbLines(nbLines)
+{
+}
+
+bool HistoryTypeBuffer::isOn() const
+{
+  return true;
+}
+
+unsigned int HistoryTypeBuffer::getNbLines() const
+{
+  return m_nbLines;
+}
+
+const QString& HistoryTypeBuffer::getFileName() const
+{
+  return QString::null;
+}
+
+HistoryScroll* HistoryTypeBuffer::getScroll() const
+{
+  return new HistoryScrollBuffer(m_nbLines);
+}
+
+
+//////////////////////////////
+
+HistoryTypeFile::HistoryTypeFile(const QString& fileName)
+  : m_fileName(fileName)
+{
+}
+
+bool HistoryTypeFile::isOn() const
+{
+  return true;
+}
+
+unsigned int HistoryTypeFile::getNbLines() const
+{
+  return 0;
+}
+
+const QString& HistoryTypeFile::getFileName() const
+{
+  return m_fileName;
+}
+
+HistoryScroll* HistoryTypeFile::getScroll() const
+{
+  return new HistoryScrollFile(m_fileName);
+}
+
Index: src/TEScreen.C
===================================================================
RCS file: /home/kde/kdebase/konsole/src/TEScreen.C,v
retrieving revision 1.41
diff -u -r1.41 TEScreen.C
--- src/TEScreen.C	2001/03/17 14:30:42	1.41
+++ src/TEScreen.C	2001/05/27 13:39:13
@@ -61,20 +61,35 @@
 /*! creates a `TEScreen' of `lines' lines and `columns' columns.
 */
 
-TEScreen::TEScreen(int lines, int columns)
-{
-  this->lines   = lines;
-  this->columns = columns;
-
-  // we add +1 here as under some weired circumstances konsole crashes
-  // reading out of bound. As a crash is worse, we afford the minimum
-  // of added memory
-  image      = (ca*) malloc((lines+1)*columns*sizeof(ca));
-  tabstops   = NULL; initTabStops();
-  cuX = cuY = sa_cu_re = cu_re = sa_cu_fg = cu_fg = sa_cu_bg = cu_bg = 0;
+TEScreen::TEScreen(int l, int c)
+  : lines(l),
+    columns(c),
+    image(new ca[(lines+1)*columns]),
+    histCursor(0),
+    hist(new HistoryScrollNone()),
+    cuX(0), cuY(0),
+    cu_fg(0), cu_bg(0), cu_re(0),
+    tmargin(0), bmargin(0),
+    tabstops(0),
+    sel_begin(0), sel_TL(0), sel_BR(0),
+    ef_fg(0), ef_bg(0), ef_re(0),
+    sa_cuX(0), sa_cuY(0),
+    sa_cu_re(0), sa_cu_fg(0), sa_cu_bg(0)
+{
+  /*
+    this->lines   = lines;
+    this->columns = columns;
+
+    // we add +1 here as under some weired circumstances konsole crashes
+    // reading out of bound. As a crash is worse, we afford the minimum
+    // of added memory
+    image      = (ca*) malloc((lines+1)*columns*sizeof(ca));
+    tabstops   = NULL; initTabStops();
+    cuX = cuY = sa_cu_re = cu_re = sa_cu_fg = cu_fg = sa_cu_bg = cu_bg = 0;
 
-  histCursor = 0;
-
+    histCursor = 0;
+  */
+  initTabStops();
   clearSelection();
   reset();
 }
@@ -84,8 +99,9 @@
 
 TEScreen::~TEScreen()
 {
-  free(image);
-  if (tabstops) free(tabstops);
+  delete[] image;
+  delete[] tabstops;
+  delete hist;
 }
 
 /* ------------------------------------------------------------------------- */
@@ -421,7 +437,7 @@
     newimg[y*new_columns+x].b = image[loc(x,y)].b;
     newimg[y*new_columns+x].r = image[loc(x,y)].r;
   }
-  free(image);
+  delete[] image;
   image = newimg;
   lines = new_lines;
   columns = new_columns;
@@ -512,13 +528,13 @@
   ca* merged = (ca*)malloc(lines*columns*sizeof(ca));
   ca dft(' ',DEFAULT_FORE_COLOR,DEFAULT_BACK_COLOR,DEFAULT_RENDITION);
 
-  for (y = 0; (y < lines) && (y < (hist.getLines()-histCursor)); y++)
+  for (y = 0; (y < lines) && (y < (hist->getLines()-histCursor)); y++)
   {
-    int len = QMIN(columns,hist.getLineLen(y+histCursor));
+    int len = QMIN(columns,hist->getLineLen(y+histCursor));
     int yp  = y*columns;
     int yq  = (y+histCursor)*columns;
 
-    hist.getCells(y+histCursor,0,len,merged+yp);
+    hist->getCells(y+histCursor,0,len,merged+yp);
     for (x = len; x < columns; x++) merged[yp+x] = dft;
     for (x = 0; x < columns; x++)
     {   int p=x + yp; int q=x + yq;
@@ -526,13 +542,13 @@
           reverseRendition(&merged[p]); // for selection
     }
   }
-  if (lines >= hist.getLines()-histCursor)
+  if (lines >= hist->getLines()-histCursor)
   {
-    for (y = (hist.getLines()-histCursor); y < lines ; y++)
+    for (y = (hist->getLines()-histCursor); y < lines ; y++)
     {
        int yp  = y*columns;
        int yq  = (y+histCursor)*columns;
-       int yr =  (y-hist.getLines()+histCursor)*columns;
+       int yr =  (y-hist->getLines()+histCursor)*columns;
        for (x = 0; x < columns; x++)
        { int p = x + yp; int q = x + yq; int r = x + yr;
          merged[p] = image[r];
@@ -548,11 +564,11 @@
     for (i = 0; i < n; i++)
       reverseRendition(&merged[i]); // for reverse display
   }
-//  if (getMode(MODE_Cursor) && (cuY+(hist.getLines()-histCursor) < lines)) // \
cursor visible +//  if (getMode(MODE_Cursor) && (cuY+(hist->getLines()-histCursor) < \
lines)) // cursor visible  
-  int loc_ = loc(cuX, cuY+hist.getLines()-histCursor);
+  int loc_ = loc(cuX, cuY+hist->getLines()-histCursor);
   if(getMode(MODE_Cursor) && loc_ < columns*lines)
-    reverseRendition(&merged[loc(cuX,cuY+(hist.getLines()-histCursor))]);
+    reverseRendition(&merged[loc(cuX,cuY+(hist->getLines()-histCursor))]);
   return merged;
 }
 
@@ -618,8 +634,9 @@
 
 void TEScreen::initTabStops()
 {
-  if (tabstops) free(tabstops);
-  tabstops = (bool*)malloc(columns*sizeof(bool));
+  delete[] tabstops;
+  tabstops = new bool[columns];
+
   // Arrg! The 1st tabstop has to be one longer than the other.
   // i.e. the kids start counting from 0 instead of 1.
   // Other programs might behave correctly. Be aware.
@@ -647,7 +664,7 @@
 void TEScreen::checkSelection(int from, int to)
 {
   if (sel_begin == -1) return;
-  int scr_TL = loc(0, hist.getLines());
+  int scr_TL = loc(0, hist->getLines());
   //Clear entire selection if it overlaps region [from, to]
   if ( (sel_BR > (from+scr_TL) )&&(sel_TL < (to+scr_TL)) )
   {
@@ -791,7 +808,7 @@
 
 void TEScreen::clearImage(int loca, int loce, char c)
 { int i;
-  int scr_TL=loc(0,hist.getLines());
+  int scr_TL=loc(0,hist->getLines());
   //FIXME: check positions
 
   //Clear entire selection if it overlaps region to be moved...
@@ -998,7 +1015,7 @@
 
   int *m;			// buffer to fill.
   int s, d;			// source index, dest. index.
-  int hist_BR = loc(0, hist.getLines());
+  int hist_BR = loc(0, hist->getLines());
   int hY = sel_TL / columns;
   int hX = sel_TL % columns;
   int eol;			// end of line
@@ -1015,9 +1032,9 @@
   while (s <= sel_BR)
     {
       if (s < hist_BR)
-	{			// get lines from hist.history
+	{			// get lines from hist->history
 				// buffer.
-	  eol = hist.getLineLen(hY);
+	  eol = hist->getLineLen(hY);
 
 	  if ((hY == (sel_BR / columns)) &&
 	      (eol >= (sel_BR % columns)))
@@ -1027,7 +1044,7 @@
 	  
 	  while (hX < eol)
 	    {
-	      m[d++] = hist.getCell(hY, hX++).c;
+	      m[d++] = hist->getCell(hY, hX++).c;
 	      s++;
 	    }
 
@@ -1176,11 +1193,11 @@
     while (end >= 0 && image[end] == dft)
       end -= 1;
 
-    hist.addCells(image,end+1);
-    hist.addLine();
+    hist->addCells(image,end+1);
+    hist->addLine();
 
     // adjust history cursor
-    histCursor += (hist.getLines()-1 == histCursor);
+    histCursor += (hist->getLines()-1 == histCursor);
   }
 
   if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround
@@ -1198,17 +1215,23 @@
 
 int TEScreen::getHistLines()
 {
-  return hist.getLines();
+  return hist->getLines();
 }
 
-void TEScreen::setScroll(bool on)
+void TEScreen::setScroll(const HistoryType& t)
 {
   histCursor = 0;
   clearSelection();
-  hist.setScroll(on);
+  delete hist;
+  hist = t.getScroll();
 }
 
 bool TEScreen::hasScroll()
+{
+  return hist->hasScroll();
+}
+
+const HistoryType& TEScreen::getScroll()
 {
-  return hist.hasScroll();
+  return hist->getType();
 }
Index: src/TEmulation.C
===================================================================
RCS file: /home/kde/kdebase/konsole/src/TEmulation.C,v
retrieving revision 1.21
diff -u -r1.21 TEmulation.C
--- src/TEmulation.C	2001/03/19 14:37:37	1.21
+++ src/TEmulation.C	2001/05/27 13:39:14
@@ -92,19 +92,21 @@
 /*!
 */
 
-TEmulation::TEmulation(TEWidget* gui)
-: decoder(0)
+TEmulation::TEmulation(TEWidget* w)
+: gui(w),
+  scr(0),
+  connected(false),
+  codec(0),
+  decoder(0),
+  keytrans(0),
+  bulk_nlcnt(0),
+  bulk_incnt(0)
 {
-  this->gui = gui;
 
   screen[0] = new TEScreen(gui->Lines(),gui->Columns());
   screen[1] = new TEScreen(gui->Lines(),gui->Columns());
   scr = screen[0];
 
-  bulk_nlcnt = 0; // reset bulk newline counter
-  bulk_incnt = 0; // reset bulk counter
-  connected  = FALSE;
-
   QObject::connect(&bulk_timer, SIGNAL(timeout()), this, SLOT(showBulk()) );
   QObject::connect(gui,SIGNAL(changedImageSizeSignal(int,int)),
                    this,SLOT(onImageSizeChange(int,int)));
@@ -141,16 +143,20 @@
   scr = screen[n&1];
 }
 
-void TEmulation::setHistory(bool on)
+void TEmulation::setHistory(const HistoryType& t)
 {
-  screen[0]->setScroll(on);
+  fprintf(stderr, "TEmulation::setHistory(%d, %d, %s)\n",
+          t.isOn(), t.getNbLines(), t.getFileName().latin1());
+  
+  screen[0]->setScroll(t);
+
   if (!connected) return;
   showBulk();
 }
 
-bool TEmulation::history()
+const HistoryType& TEmulation::history()
 {
-  return screen[0]->hasScroll();
+  return screen[0]->getScroll();
 }
 
 void TEmulation::setCodec(int c)
Index: src/konsole.C
===================================================================
RCS file: /home/kde/kdebase/konsole/src/konsole.C,v
retrieving revision 1.126
diff -u -r1.126 konsole.C
--- src/konsole.C	2001/05/23 00:24:38	1.126
+++ src/konsole.C	2001/05/27 13:39:17
@@ -434,8 +434,11 @@
    // Schema
    m_options->insertItem( SmallIconSet( "colorize" ), i18n( "Schema" ), m_schema);
    m_options->insertSeparator();
-   m_options->insertItem( i18n("&History"), 3 );
-   m_options->setItemEnabled(3, false);
+
+   KAction *historyType = new KAction(i18n("History type..."), 0, this,
+                                      SLOT(slotHistoryType()), this);
+   historyType->plug(m_options);
+   
    m_options->insertSeparator();
    m_options->insertItem( SmallIconSet( "charset" ), i18n( "&Codec" ), m_codec);
    m_options->insertItem( SmallIconSet( "key_bindings" ), i18n( "&Keyboard" ), \
m_keytab ); @@ -988,18 +991,10 @@
                      : QFrame::NoFrame );
 }
 
-void Konsole::setHistory(bool on)
-{
-  b_scroll = on;
-  m_options->setItemChecked(3,b_scroll);
-  if (se) se->setHistory( b_scroll );
-}
 
 void Konsole::opt_menu_activated(int item)
 {
   switch( item )  {
-    case 3: setHistory(!b_scroll);
-            break;
     case 5: setFullScreen(!b_fullscreen);
             break;
     case 8:
@@ -1357,7 +1352,8 @@
   s->setSchemaNo(schmno);
 //kdDebug()<<"setTitle Konsole 1319 "<< txt << endl;
   s->setTitle(txt);
-  s->setHistory(b_scroll); //FIXME: take from schema
+
+  //s->setHistory(b_scroll); //FIXME: take from schema
 
   addSession(s);
   runSession(s); // activate and run
@@ -1633,6 +1629,147 @@
     toolBar()->updateRects();
 //  }
 }
+
+
+//////////////////////////////////////////////////////////////////////
+#include <qspinbox.h>
+#include <qradiobutton.h>
+#include <qlayout.h>
+#include <qbuttongroup.h>
+
+HistoryTypeDialog::HistoryTypeDialog(const HistoryType& histType, QWidget *parent)
+  : KDialogBase(Plain, i18n("History Configuration"),
+                Help | Default | Ok | Cancel, Ok,
+                parent),
+    m_logFileName(0),
+    m_nbLogLines(0),
+    m_isBufferBased(true)
+                
+{
+  QFrame *mainFrame = plainPage();
+  
+  QGridLayout *grid = new QGridLayout(mainFrame, 3, 2);
+
+  QButtonGroup *btnGroup = new QButtonGroup(mainFrame);
+  btnGroup->hide();
+
+  QRadioButton *btnOff    = new QRadioButton(i18n("Off"),      mainFrame);
+  QRadioButton *btnFile   = new QRadioButton(i18n("File :"),   mainFrame);
+  QRadioButton *btnBuffer = new QRadioButton(i18n("Buffer :"), mainFrame);
+
+  btnGroup->insert(btnOff);
+  btnGroup->insert(btnFile);
+  btnGroup->insert(btnBuffer);
+
+  QObject::connect(btnOff, SIGNAL(clicked()),
+                   this,   SLOT(slotNoHistChoosen()));
+
+  QObject::connect(btnFile, SIGNAL(clicked()),
+                   this,    SLOT(slotFileHistChoosen()));
+
+  QObject::connect(btnBuffer, SIGNAL(clicked()),
+                   this,      SLOT(slotBufferHistChoosen()));
+
+  grid->addWidget(btnOff,    0, 0);
+  grid->addWidget(btnFile,   1, 0);
+  grid->addWidget(btnBuffer, 2, 0);
+
+  
+  m_logFileName = new QLineEdit(mainFrame);
+  grid->addWidget(m_logFileName, 1, 1);
+
+  m_nbLogLines = new QSpinBox(0, 10 * 1000 * 1000, 1, mainFrame);
+  grid->addWidget(m_nbLogLines, 2, 1);
+
+  if (!histType.isOn()) {
+
+    btnOff->setChecked(true);
+    slotNoHistChoosen();
+
+  } else if (histType.getNbLines() > 0) {
+
+    btnBuffer->setChecked(true);
+    m_nbLogLines->setValue(histType.getNbLines());
+    slotBufferHistChoosen();
+
+  } else if (histType.getFileName().length()) {
+
+    btnFile->setChecked(true);
+    m_logFileName->setText(histType.getFileName());
+    slotFileHistChoosen();
+
+  } else {
+    // sensible default
+    btnOff->setChecked(true);
+    slotNoHistChoosen();
+  }
+}
+
+void HistoryTypeDialog::slotFileHistChoosen()
+{
+  kdDebug() << "Konsole::slotFileHistChoosen\n";
+  m_isBufferBased = false;
+  m_isOff = false;
+  m_nbLogLines->setEnabled(false);
+  m_logFileName->setEnabled(true);
+  m_logFileName->setFocus();
+}
+
+void HistoryTypeDialog::slotBufferHistChoosen()
+{
+  kdDebug() << "Konsole::slotBufferHistChoosen\n";
+  m_isBufferBased = true;
+  m_isOff = false;
+  m_nbLogLines->setEnabled(true);
+  m_nbLogLines->setFocus();
+  m_logFileName->setEnabled(false);
+}
+
+void HistoryTypeDialog::slotNoHistChoosen()
+{
+  kdDebug() << "Konsole::slotNoHistChoosen\n";
+  m_isBufferBased = false;
+  m_isOff = true;
+  m_nbLogLines->setEnabled(false);
+  m_logFileName->setEnabled(false);
+}
+
+unsigned int HistoryTypeDialog::nbLines()
+{
+  return m_isBufferBased ? m_nbLogLines->value() : 0;
+}
+
+QString HistoryTypeDialog::logFileName()
+{
+  return m_isBufferBased ? QString::null : m_logFileName->text();
+}
+
+
+
+
+void Konsole::slotHistoryType()
+{
+  kdDebug() << "Konsole::slotWordSeps\n";
+  if (!se) return;
+  
+  HistoryTypeDialog dlg(se->history(), this);
+  if (dlg.exec()) {
+
+    if (dlg.isOff())
+
+      se->setHistory(HistoryTypeNone());
+    
+    else if (dlg.isBufferBased())
+
+      se->setHistory(HistoryTypeBuffer(dlg.nbLines()));
+
+    else
+
+      se->setHistory(HistoryTypeFile(dlg.logFileName()));
+  }
+}
+
+//////////////////////////////////////////////////////////////////////
 
 
 void Konsole::slotWordSeps() {
Index: src/konsole_part.C
===================================================================
RCS file: /home/kde/kdebase/konsole/src/konsole_part.C,v
retrieving revision 1.30
diff -u -r1.30 konsole_part.C
--- src/konsole_part.C	2001/05/07 02:17:30	1.30
+++ src/konsole_part.C	2001/05/27 13:39:17
@@ -141,7 +141,7 @@
       te->setColorTable(ctable); 
     }
   
-  initial->setHistory(true);
+  initial->setHistory(HistoryTypeBuffer(1000));
 
   // setXMLFile("konsole_part.rc");
 
Index: src/session.C
===================================================================
RCS file: /home/kde/kdebase/konsole/src/session.C,v
retrieving revision 1.33
diff -u -r1.33 session.C
--- src/session.C	2001/05/12 13:26:34	1.33
+++ src/session.C	2001/05/27 13:39:18
@@ -146,12 +146,12 @@
   return title;
 }
 
-void TESession::setHistory(bool on)
+void TESession::setHistory(const HistoryType &hType)
 {
-  em->setHistory( on );
+  em->setHistory(hType);
 }
 
-bool TESession::history()
+const HistoryType& TESession::history()
 {
   return em->history();
 }



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic