changeset 15649:c22fa57226b2

Fixed bug with ECHOCTL.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Mon, 30 Jan 2012 01:09:16 +0100
parents d49e99269c0b
children ba360324035e
files libqterminal/Emulation.cpp libqterminal/Emulation.h libqterminal/KeyboardTranslator.cpp libqterminal/QTerminal.cpp libqterminal/QTerminal.h libqterminal/TerminalModel.cpp libqterminal/TerminalModel.h libqterminal/kpty.cpp
diffstat 8 files changed, 48 insertions(+), 129 deletions(-) [+]
line wrap: on
line diff
--- a/libqterminal/Emulation.cpp	Fri Jan 27 23:44:07 2012 +0100
+++ b/libqterminal/Emulation.cpp	Mon Jan 30 01:09:16 2012 +0100
@@ -252,117 +252,17 @@
 
 	bufferedUpdate();
     	
-    QString unicodeText = _decoder->toUnicode(text,length);
+        QString unicodeText = _decoder->toUnicode(text,length);
 
 	//send characters to terminal emulator
-	for (int i=0;i<unicodeText.length();i++)
+        for (int i=0;i<unicodeText.length();i++)
 	{
-		receiveChar(unicodeText[i].unicode());
-	}
-
-	//look for z-modem indicator
-	//-- someone who understands more about z-modems that I do may be able to move
-	//this check into the above for loop?
-	for (int i=0;i<length;i++)
-	{
-		if (text[i] == '\030')
-    		{
-      			if ((length-i-1 > 3) && (strncmp(text+i+1, "B00", 3) == 0))
-      				emit zmodemDetected();
-    		}
+                receiveChar(unicodeText[i].unicode());
 	}
 }
 
-//OLDER VERSION
-//This version of onRcvBlock was commented out because
-//	a)  It decoded incoming characters one-by-one, which is slow in the current version of Qt (4.2 tech preview)
-//	b)  It messed up decoding of non-ASCII characters, with the result that (for example) chinese characters
-//	    were not printed properly.
-//
-//There is something about stopping the _decoder if "we get a control code halfway a multi-byte sequence" (see below)
-//which hasn't been ported into the newer function (above).  Hopefully someone who understands this better
-//can find an alternative way of handling the check.  
-
-
-/*void Emulation::onRcvBlock(const char *s, int len)
-{
-  emit notifySessionState(NOTIFYACTIVITY);
-  
-  bufferedUpdate();
-  for (int i = 0; i < len; i++)
-  {
-
-    QString result = _decoder->toUnicode(&s[i],1);
-    int reslen = result.length();
-
-    // If we get a control code halfway a multi-byte sequence
-    // we flush the _decoder and continue with the control code.
-    if ((s[i] < 32) && (s[i] > 0))
-    {
-       // Flush _decoder
-       while(!result.length())
-          result = _decoder->toUnicode(&s[i],1);
-       reslen = 1;
-       result.resize(reslen);
-       result[0] = QChar(s[i]);
-    }
-
-    for (int j = 0; j < reslen; j++)
-    {
-      if (result[j].characterategory() == QChar::Mark_NonSpacing)
-         _currentScreen->compose(result.mid(j,1));
-      else
-         onRcvChar(result[j].unicode());
-    }
-    if (s[i] == '\030')
-    {
-      if ((len-i-1 > 3) && (strncmp(s+i+1, "B00", 3) == 0))
-      	emit zmodemDetected();
-    }
-  }
-}*/
-
 // Selection --------------------------------------------------------------- --
 
-#if 0
-void Emulation::onSelectionBegin(const int x, const int y, const bool columnmode) {
-  if (!connected) return;
-  _currentScreen->setSelectionStart( x,y,columnmode);
-  showBulk();
-}
-
-void Emulation::onSelectionExtend(const int x, const int y) {
-  if (!connected) return;
-  _currentScreen->setSelectionEnd(x,y);
-  showBulk();
-}
-
-void Emulation::setSelection(const bool preserve_line_breaks) {
-  if (!connected) return;
-  QString t = _currentScreen->selectedText(preserve_line_breaks);
-  if (!t.isNull()) 
-  {
-    QListIterator< TerminalDisplay* > viewIter(_views);
-
-    while (viewIter.hasNext())    
-        viewIter.next()->setSelection(t);
-  }
-}
-
-void Emulation::testIsSelected(const int x, const int y, bool &selected)
-{
-  if (!connected) return;
-  selected=_currentScreen->isSelected(x,y);
-}
-
-void Emulation::clearSelection() {
-  if (!connected) return;
-  _currentScreen->clearSelection();
-  showBulk();
-}
-
-#endif 
-
 void Emulation::writeToStream( TerminalCharacterDecoder* _decoder , 
                                int startLine ,
                                int endLine) 
@@ -524,7 +424,3 @@
 
 // global instance
 ExtendedCharTable ExtendedCharTable::instance;
-
-
-//#include "moc_Emulation.cpp"
-
--- a/libqterminal/Emulation.h	Fri Jan 27 23:44:07 2012 +0100
+++ b/libqterminal/Emulation.h	Mon Jan 30 01:09:16 2012 +0100
@@ -297,9 +297,6 @@
    */
   void stateSet(int state);
 
-  /** TODO Document me */
-  void zmodemDetected();
-
 
   /**
    * Requests that the color of the text used
--- a/libqterminal/KeyboardTranslator.cpp	Fri Jan 27 23:44:07 2012 +0100
+++ b/libqterminal/KeyboardTranslator.cpp	Mon Jan 30 01:09:16 2012 +0100
@@ -146,7 +146,6 @@
 
 const KeyboardTranslator* KeyboardTranslatorManager::defaultTranslator()
 {
-    qDebug() << "Loading default translator from text";
     QBuffer textBuffer;
     textBuffer.setData(defaultTranslatorText,strlen(defaultTranslatorText));
 
--- a/libqterminal/QTerminal.cpp	Fri Jan 27 23:44:07 2012 +0100
+++ b/libqterminal/QTerminal.cpp	Mon Jan 30 01:09:16 2012 +0100
@@ -17,32 +17,25 @@
     Boston, MA 02110-1301, USA.
 */
 						
+#include <QDebug>
 
 #include "QTerminal.h"
 #include "kpty.h"
 
+#include <termios.h>
+
 QTerminal::QTerminal(QWidget *parent)
     : QWidget(parent) {
     setMinimumSize(600, 400);
-    init();
-    
-    setFocus(Qt::OtherFocusReason);
-    m_sessionView->resize(this->size());
-    
-    this->setFocusProxy(m_sessionView);
+    initialize();
 }
 
-void QTerminal::init()
+void QTerminal::initialize()
 {
-    KPty *kpty = new KPty();
-    kpty->open();
-    int fds = kpty->slaveFd();
+    m_kpty = new KPty();
+    m_kpty->open();
 
-    dup2 (fds, 0);
-    dup2 (fds, 1);
-    dup2 (fds, 2);
-
-    m_sessionModel = new TerminalModel(kpty);
+    m_sessionModel = new TerminalModel(m_kpty);
 
     m_sessionModel->setAutoClose(true);
     m_sessionModel->setCodec(QTextCodec::codecForName("UTF-8"));
@@ -69,6 +62,32 @@
 
     connect(m_sessionModel, SIGNAL(finished()), this, SLOT(sessionFinished()));
     setFocusProxy(m_sessionView);
+
+    setFocus(Qt::OtherFocusReason);
+    m_sessionView->resize(this->size());
+
+    connectToPty();
+}
+
+void QTerminal::connectToPty()
+{
+    int fds = m_kpty->slaveFd();
+
+    dup2 (fds, STDIN_FILENO);
+    dup2 (fds, STDOUT_FILENO);
+    dup2 (fds, STDERR_FILENO);
+
+    if(!isatty(STDIN_FILENO)) {
+        qDebug("Error: stdin is not a tty.");
+    }
+
+    if(!isatty(STDOUT_FILENO)) {
+        qDebug("Error: stdout is not a tty.");
+    }
+
+    if(!isatty(STDERR_FILENO)) {
+        qDebug("Error: stderr is not a tty.");
+    }
 }
 
 QTerminal::~QTerminal()
--- a/libqterminal/QTerminal.h	Fri Jan 27 23:44:07 2012 +0100
+++ b/libqterminal/QTerminal.h	Mon Jan 30 01:09:16 2012 +0100
@@ -22,6 +22,7 @@
 #define Q_TERMINAL
 
 #include <QtGui>
+#include "kpty.h"
 #include "TerminalModel.h"
 #include "TerminalView.h"
 
@@ -54,9 +55,12 @@
     void sessionFinished();        
     
 private:
-    void init();
+    void initialize();
+    void connectToPty();
+
     TerminalView *m_sessionView;
     TerminalModel *m_sessionModel;
+    KPty *m_kpty;
 };
 
 #endif // Q_TERMINAL
--- a/libqterminal/TerminalModel.cpp	Fri Jan 27 23:44:07 2012 +0100
+++ b/libqterminal/TerminalModel.cpp	Mon Jan 30 01:09:16 2012 +0100
@@ -393,7 +393,7 @@
     _addToUtmp = set;
 }
 
-void TerminalModel::onReceiveBlock( const char* buf, int len )
+void TerminalModel::onReceiveBlock(const char* buf, int len )
 {
     _emulation->receiveData( buf, len );
     emit receivedData( QString::fromLatin1( buf, len ) );
--- a/libqterminal/TerminalModel.h	Fri Jan 27 23:44:07 2012 +0100
+++ b/libqterminal/TerminalModel.h	Mon Jan 30 01:09:16 2012 +0100
@@ -315,7 +315,7 @@
 private slots:
   void done(int);
 
-  void onReceiveBlock( const char* buffer, int len );
+  void onReceiveBlock(const char* buffer, int len );
   void monitorTimerDone();
 
   void onViewSizeChange(int height, int width);
--- a/libqterminal/kpty.cpp	Fri Jan 27 23:44:07 2012 +0100
+++ b/libqterminal/kpty.cpp	Mon Jan 30 01:09:16 2012 +0100
@@ -365,6 +365,10 @@
   fcntl(d->masterFd, F_SETFD, FD_CLOEXEC);
   fcntl(d->slaveFd, F_SETFD, FD_CLOEXEC);
 
+  struct ::termios t;
+  tcGetAttr(&t);
+  t.c_lflag &= ~ECHOCTL;
+  tcSetAttr(&t);
   return true;
 }