summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/emulation_handler.cpp
blob: 9f34d2c3d7ce74a39239b9b435a92eb3e78f5382 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <qwidget.h>

#include "TEWidget.h"
#include "TEmuVt102.h"

#include "profile.h"
#include "emulation_handler.h"


EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const char* name )
    : QObject(0, name )
{
    m_teWid = new TEWidget( parent, "TerminalMain");
    m_teWid->setMinimumSize(150, 70 );
    parent->resize( m_teWid->calcSize(80, 24 ) );
    m_teEmu = new TEmuVt102(m_teWid );

    connect(m_teEmu,SIGNAL(ImageSizeChanged(int, int) ),
            this, SIGNAL(changeSize(int, int) ) );
    connect(m_teEmu, SIGNAL(sndBlock(const char*, int) ),
            this, SLOT(recvEmulation(const char*, int) ) );
    m_teEmu->setConnect( true );
    m_teEmu->setHistory( TRUE );
    load( prof );



}
EmulationHandler::~EmulationHandler() {
    delete m_teEmu;
    delete m_teWid;
}
void EmulationHandler::load( const Profile& prof) {
    m_teWid->setVTFont( font( prof.readNumEntry("Font")  )  );
    int num = prof.readNumEntry("Color");
    setColor( foreColor(num), backColor(num) );
     m_teWid->setBackgroundColor(backColor(num) );
}
void EmulationHandler::recv( const QByteArray& ar) {
    qWarning("received in EmulationHandler!");
    m_teEmu->onRcvBlock(ar.data(), ar.count() );
}
void EmulationHandler::recvEmulation(const char* src, int len ) {
    qWarning("received from te ");
    QByteArray ar(len);

    memcpy(ar.data(), src, sizeof(char) * len );

    emit send(ar);
}
QWidget* EmulationHandler::widget() {
    return m_teWid;
}
/*
 * allocate a new table of colors
 */
void EmulationHandler::setColor( const QColor& fore, const QColor& back ) {
    ColorEntry table[TABLE_COLORS];
    const ColorEntry *defaultCt = m_teWid->getdefaultColorTable();

    for (int i = 0; i < TABLE_COLORS; i++ ) {
        if ( i == 0 || i == 10 ) {
            table[i].color = fore;
        }else if ( i == 1 || i == 11 ) {
            table[i].color = back;
            table[i].transparent = 0;
        }else {
            table[i].color = defaultCt[i].color;
        }
    }
    m_teWid->setColorTable(table );
    m_teWid->update();
}
QFont EmulationHandler::font( int id ) {
    QString name;
    int size = 0;
    switch(id ) {
    default: // fall through
    case 0:
        name = QString::fromLatin1("Micro");
        size = 4;
        break;
    case 1:
        name = QString::fromLatin1("Fixed");
        size = 7;
        break;
    case 2:
        name = QString::fromLatin1("Fixed");
        size = 12;
        break;
    }
    QFont font(name, size, QFont::Normal );
    font.setFixedPitch(TRUE );
    return font;
}
QColor EmulationHandler::foreColor(int col) {
    QColor co;
    /* we need to switch it */
    switch( col ) {
    default:
    case Profile::White:
        qWarning("Foreground black");
        /* color is black */
        co = Qt::white;
        break;
    case Profile::Black:
        qWarning("Foreground white");
        co = Qt::black;
        break;
    }

    return co;
}
QColor EmulationHandler::backColor(int col ) {
  QColor co;
    /* we need to switch it */
    switch( col ) {
    default:
    case Profile::White:
        qWarning("Background white");
        /* color is white */
        co = Qt::black;
        break;
    case Profile::Black:
        qWarning("Background black");
        co = Qt::white;
        break;
    }

    return co;
}