Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

emulation_handler.cpp

Go to the documentation of this file.
00001 #include "TEmuVt102.h"
00002 #include "profile.h"
00003 #include "emulation_handler.h"
00004 #include "script.h"
00005 #include "logger.h"
00006 
00007 /* OPIE */
00008 #include <qpe/config.h>
00009 
00010 /* QT */
00011 #include <qfile.h>
00012 #include <qtextstream.h>
00013 
00014 EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const char* name )
00015     : QObject(0, name )
00016 {
00017     m_teWid = new TEWidget( parent, "TerminalMain");
00018         // use setWrapAt(0) for classic behaviour (wrap at screen width, no scrollbar)
00019         // use setWrapAt(80) for normal console with scrollbar
00020         setWrap(prof.readNumEntry("Wrap", 80) ? 0 : 80);
00021     m_teWid->setMinimumSize(150, 70 );
00022     m_script = 0;
00023     m_log = 0;
00024     parent->resize( m_teWid->calcSize(80, 24 ) );
00025     m_teEmu = new TEmuVt102(m_teWid );
00026 
00027     connect(m_teEmu,SIGNAL(ImageSizeChanged(int,int) ),
00028             this, SIGNAL(changeSize(int,int) ) );
00029     connect(m_teEmu, SIGNAL(sndBlock(const char*,int) ),
00030             this, SLOT(recvEmulation(const char*,int) ) );
00031     m_teEmu->setConnect( true );
00032     m_teEmu->setHistory( TRUE );
00033     load( prof );
00034 
00035 
00036 
00037 }
00038 TEmulation* EmulationHandler::emulation() {
00039     return m_teEmu;
00040 }
00041 EmulationHandler::~EmulationHandler() {
00042     if (isRecording())
00043         clearScript();
00044     delete m_teEmu;
00045     delete m_teWid;
00046     delete m_log;
00047 }
00048 
00049 void EmulationHandler::load( const Profile& prof) {
00050 
00051     // try to read the fontconfig from the profile
00052     QString aFont = prof.readEntry( "Font" );
00053     int aFontSize = prof.readNumEntry( "FontSize" );
00054     // use defaults from qpe.conf if no profile yet
00055     if ( ( aFontSize == -1 ) || ( aFont == QString::null ) )
00056     {
00057         Config c( "qpe" );
00058         c.setGroup( "Appearance" );
00059         aFont = c.readEntry( "FixedFontFamily", "Fixed" );
00060         aFontSize = c.readNumEntry( "FixedFontSize", 7 );
00061     }
00062     QFont font( aFont, aFontSize );
00063     font.setFixedPitch( TRUE );
00064     m_teWid->setVTFont( font );
00065 
00066     int num = prof.readNumEntry("Color", 0);
00067     setColor( foreColor(num), backColor(num) );
00068     m_teWid->setBackgroundColor(backColor(num) );
00069 
00070     int term = prof.readNumEntry("Terminal",  0) ;
00071     switch(term) {
00072     default:
00073     case Profile::VT102:
00074     case Profile::VT100:
00075         m_teEmu->setKeytrans("vt100.keytab");
00076         break;
00077     case Profile::Linux:
00078         m_teEmu->setKeytrans("linux.keytab");
00079         break;
00080     case Profile::XTerm:
00081         m_teEmu->setKeytrans("default.Keytab");
00082         break;
00083     }
00084 }
00085 void EmulationHandler::recv( const QByteArray& ar) {
00086     m_teEmu->onRcvBlock(ar.data(), ar.count() );
00087         if ( isLogging() ) {
00088                 m_log->append( ar );
00089         }
00090 }
00091 
00092 void EmulationHandler::recvEmulation(const char* src, int len ) {
00093     QByteArray ar(len);
00094 
00095     memcpy(ar.data(), src, sizeof(char) * len );
00096     if (isRecording())
00097         m_script->append(ar);
00098     emit send(ar);
00099 }
00100 
00101 
00102 QWidget* EmulationHandler::widget() {
00103     return m_teWid;
00104 }
00105 /*
00106  * allocate a new table of colors
00107  */
00108 void EmulationHandler::setColor( const QColor& fore, const QColor& back ) {
00109     ColorEntry table[TABLE_COLORS];
00110     const ColorEntry *defaultCt = m_teWid->getdefaultColorTable();
00111 
00112     for (int i = 0; i < TABLE_COLORS; i++ ) {
00113         if ( i == 0 || i == 10 ) {
00114             table[i].color = fore;
00115         }else if ( i == 1 || i == 11 ) {
00116             table[i].color = back;
00117             table[i].transparent = 0;
00118         }else {
00119             table[i].color = defaultCt[i].color;
00120         }
00121     }
00122     m_teWid->setColorTable(table );
00123     m_teWid->update();
00124 }
00125 QFont EmulationHandler::font( int id ) {
00126     QString name;
00127     int size = 0;
00128     switch(id ) {
00129     default: // fall through
00130     case 0:
00131         name = QString::fromLatin1("Micro");
00132         size = 4;
00133         break;
00134     case 1:
00135         name = QString::fromLatin1("Fixed");
00136         size = 7;
00137         break;
00138     case 2:
00139         name = QString::fromLatin1("Fixed");
00140         size = 12;
00141         break;
00142     }
00143     QFont font(name, size, QFont::Normal );
00144     font.setFixedPitch(TRUE );
00145     return font;
00146 }
00147 QColor EmulationHandler::foreColor(int col) {
00148     QColor co;
00149     /* we need to switch it */
00150     switch( col ) {
00151     default:
00152     case Profile::White:
00153         /* color is black */
00154         co = Qt::white;
00155         break;
00156     case Profile::Black:
00157         co = Qt::black;
00158         break;
00159     case Profile::Green:
00160         co = Qt::green;
00161         break;
00162     case Profile::Orange:
00163         co.setRgb( 231, 184, 98 );
00164         break;
00165     }
00166 
00167     return co;
00168 }
00169 QColor EmulationHandler::backColor(int col ) {
00170   QColor co;
00171     /* we need to switch it */
00172     switch( col ) {
00173     default:
00174     case Profile::White:
00175         /* color is white */
00176         co = Qt::black;
00177         break;
00178     case Profile::Black:
00179         co = Qt::white;
00180         break;
00181     case Profile::Green:
00182         co = Qt::black;
00183         break;
00184     case Profile::Orange:
00185         co = Qt::black;
00186         break;
00187     }
00188 
00189     return co;
00190 }
00191 
00192 QPushButton*  EmulationHandler::cornerButton() {
00193     return m_teWid->cornerButton();
00194 }
00195 
00196 
00197 Script *EmulationHandler::script() {
00198     return m_script;
00199 }
00200 
00201 bool EmulationHandler::isRecording() {
00202     return (m_script != 0);
00203 }
00204 
00205 bool EmulationHandler::isLogging() {
00206         return (m_log != 0);
00207 }
00208 
00209 void EmulationHandler::startRecording() {
00210     if (!isRecording())
00211         m_script = new Script();
00212 }
00213 
00214 void EmulationHandler::startLogging(const QString fileName) {
00215         m_logFileName = fileName;
00216         if (!isLogging())
00217                 m_log = new Logger(m_logFileName);
00218 }
00219 
00220 QString EmulationHandler::logFileName() {
00221         return m_logFileName;
00222 }
00223 
00224 void EmulationHandler::clearScript() {
00225     if (isRecording()) {
00226         delete m_script;
00227         m_script = 0;
00228     }
00229 }
00230 
00231 void EmulationHandler::clearLog() {
00232         if (isLogging()) {
00233                 delete m_log;
00234                 m_log = 0;
00235         }
00236 }
00237 
00238 void EmulationHandler::runScript(const Script *script) {
00239     emit send(script->script());
00240 }
00241 
00242 void EmulationHandler::copy() {
00243     m_teWid->emitSelection();
00244 }
00245 void EmulationHandler::paste() {
00246     m_teWid->pasteClipboard();
00247 }
00248 
00249 void EmulationHandler::setWrap(int columns) {
00250   m_teWid->setWrapAt(columns);
00251 }
00252 
00253 void EmulationHandler::setScrollbarLocation(int index) {
00254   m_teWid->setScrollbarLocation(index);
00255 }

Generated on Sat Nov 5 16:16:49 2005 for OPIE by  doxygen 1.4.2