summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/terminalwidget.cpp
blob: 907de1bea4a549ad99542d06d63720c29be170c3 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include "terminalwidget.h"

/* QT */
#include <qlabel.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qradiobutton.h>
#include <qhgroupbox.h>
#include <qhbuttongroup.h>
#include <qlayout.h>
#include <qhbox.h>

namespace {
    enum TermIds {
        id_term_vt100 = 0,
        id_term_vt102,
        id_term_linux,
        id_term_xterm
    };

    enum ColourIds {
        id_term_black,
        id_term_white,
        id_term_green,
        id_term_orange
    };

    enum FontIds {
        id_size_small,
        id_size_medium,
        id_size_large
    };
};

TerminalWidget::TerminalWidget( const QString& name, QWidget* parent,
                                const char* na )
    : ProfileDialogTerminalWidget( name, parent, na ) {

    m_terminal = new QLabel(tr("Terminal Type"), this );
    m_terminalBox = new QComboBox(this);
    m_colorLabel = new QLabel(tr("Color scheme"), this);
    m_colorCmb = new QComboBox(this );

//     m_groupSize = new QHButtonGroup(tr("Font size"), this );
    m_groupSize = new QHBox( this );
    m_fontSelector = new Opie::Ui::OFontSelector( false, m_groupSize );

//      m_sizeSmall = new QRadioButton(tr("small"),  m_groupSize );
//      m_sizeMedium = new QRadioButton(tr("medium"),  m_groupSize );
//      m_sizeLarge = new QRadioButton(tr("large"),  m_groupSize );

    m_groupConv = new QHGroupBox( tr("Line-break conversions"), this );
    m_convInbound  = new QCheckBox( tr("Inbound"), m_groupConv );
    m_convOutbound = new QCheckBox( tr("Outbound"), m_groupConv );


    m_groupOptions = new QHGroupBox( tr("Options"), this );
    m_optionEcho = new QCheckBox( tr("Local echo"), m_groupOptions );
    m_optionWrap = new QCheckBox( tr("Line wrap"), m_groupOptions );

    m_lroot = new QVBoxLayout( this );
    m_typeBox = new  QVBoxLayout( m_lroot );
    m_colorBox = new QVBoxLayout( m_lroot );

    // Layout
    m_typeBox->add( m_terminal );
    m_typeBox->add( m_terminalBox );
    m_lroot->add( m_groupSize );

    m_colorBox->add( m_colorLabel );
    m_colorBox->add( m_colorCmb );

    m_lroot->add( m_groupConv );
    m_lroot->add( m_groupOptions );
    m_lroot->addStretch( 0 );

    // Fill in some options
    m_terminalBox->insertItem( tr("VT 100"), 0 ); // /*, id_term_vt100*/ );
    m_terminalBox->insertItem( tr("VT 102"), 1 );  // /* , id_term_vt102 */);
    m_terminalBox->insertItem( tr("Linux Console"), 2 ); //, id_term_linux );
    m_terminalBox->insertItem( tr("X-Terminal"), 3 ); //, id_term_xterm );
    //m_terminalBox->insertItem( tr("ANSI"), id_term_ansi );

    m_colorCmb->insertItem( tr("black on white"), id_term_black );
    m_colorCmb->insertItem( tr("white on black"), id_term_white );
    m_colorCmb->insertItem( tr("green on black"), id_term_green );
    m_colorCmb->insertItem( tr("orange on black"), id_term_orange );

    // signals + slots
    /*
    connect(m_terminalBox, SIGNAL(activated(int) ),
            this, SLOT(slotTermTerm(int) ) );
    connect(m_colorBox, SIGNAL(activated(int) ),
            tis, SLOT(slotTermColor(int) ) );
    connect(m_groupSize, SIGNAL(activated(int) ),
            this, SLOT(slotTermFont(int) ) );

    connect(m_optionEcho, SIGNAL(toggled(bool) ),
            this, SLOT(slotTermEcho(bool) ) );
    connect(m_optionWrap, SIGNAL(toggled(bool) ),
            this, SLOT(slotTermWrap(bool) ) );
    connect(m_convInbound, SIGNAL(toggled(bool) ),
            this, SLOT(slotTermInbound(bool) ) );
    connect(m_convOutbound, SIGNAL(toggled(bool) ),
            this, SLOT(slotTermOutbound(bool) ) );
*/
}
TerminalWidget::~TerminalWidget() {
}
void TerminalWidget::load( const Profile& prof ) {
    int term = prof.readNumEntry("Terminal");
    int color = prof.readNumEntry("Color");
//     int fontsize = prof.readNumEntry("Font");
    int opt_echo = prof.readNumEntry("Echo");
    int opt_wrap = prof.readNumEntry("Wrap");
    int opt_inbound = prof.readNumEntry("Inbound");
    int opt_outbound = prof.readNumEntry("Outbound");

    switch( term ) {
    case Profile::VT100:
        m_terminalBox->setCurrentItem(id_term_vt100 );
        break;
    case Profile::VT102:
        m_terminalBox->setCurrentItem(id_term_vt102 );
        break;
    case Profile::Linux:
        m_terminalBox->setCurrentItem(id_term_linux );
        break;
    case Profile::XTerm:
        m_terminalBox->setCurrentItem(id_term_xterm );
        break;
    default:
        m_terminalBox->setCurrentItem(id_term_vt102 );
        break;
    };

    switch( color ) {
    case Profile::Black:
        m_colorCmb->setCurrentItem(id_term_black );
        break;
    case Profile::White:
        m_colorCmb->setCurrentItem(id_term_white );
        break;
    case Profile::Green:
        m_colorCmb->setCurrentItem(id_term_green );
        break;
    case Profile::Orange:
        m_colorCmb->setCurrentItem(id_term_orange );
        break;
    default:
        break;
    };


    m_fontSelector->setSelectedFont( prof.readEntry( "Font"), prof.readEntry( "FontStyle"), prof.readNumEntry( "FontSize"  ), prof.readEntry( "FontCharset") );

//     switch( fontsize ) {
//     case Profile::Micro:
//         m_sizeSmall->setChecked(true );
//         break;
//     case Profile::Small:
//         m_sizeMedium->setChecked(true );
//         break;
//     case Profile::Medium:
//         m_sizeLarge->setChecked( true );
//         break;
//     default:
//         m_sizeMedium->setChecked(true );
//         break;
//     };

    if (opt_echo) m_optionEcho->setChecked( true );
    if (opt_wrap) m_optionWrap->setChecked( true );
    if (opt_inbound) m_convInbound->setChecked( true );
    if (opt_outbound) m_convOutbound->setChecked( true );

}
void TerminalWidget::save( Profile& profile ) {
    switch(m_terminalBox->currentItem() ) {
    case id_term_vt100:
        profile.writeEntry("Terminal", Profile::VT100 );
        break;
    case id_term_vt102:
        profile.writeEntry("Terminal", Profile::VT102 );
        break;
    case id_term_linux:
        profile.writeEntry("Terminal", Profile::Linux );
        break;
    case id_term_xterm:
        profile.writeEntry("Terminal", Profile::XTerm );
        break;
    //case id_term_ansi:
    //    profile.writeEntry("Terminal", Profile::VT102 );
    //    break;
    default:
        break;
    };

    // color
    switch(m_colorCmb->currentItem() ) {
    case id_term_black:
        profile.writeEntry("Color", Profile::Black );
        break;
    case id_term_white:
        profile.writeEntry("Color", Profile::White );
        break;
    case id_term_green:
        profile.writeEntry("Color", Profile::Green );
        break;
    case id_term_orange:
        profile.writeEntry("Color", Profile::Orange );
        break;
    default:
        break;
    };


    profile.writeEntry( "FontSize", m_fontSelector->fontSize() );
    profile.writeEntry( "FontStyle", m_fontSelector->fontStyle() );
    profile.writeEntry( "FontCharset", m_fontSelector->fontCharSet() );
    profile.writeEntry( "Font", m_fontSelector->fontFamily() );


//     if (m_sizeSmall->isChecked() ) {
//         profile.writeEntry("Font", Profile::Micro );
//     }else if (m_sizeMedium->isChecked() ) {
//         profile.writeEntry("Font", Profile::Small );
//     }else {
//         profile.writeEntry("Font", Profile::Medium );
//     }

    profile.writeEntry("Echo", m_optionEcho->isChecked() );
    profile.writeEntry("Wrap", m_optionWrap->isChecked() );
    profile.writeEntry("Inbound", m_convInbound->isChecked() );
    profile.writeEntry("Outbound",m_convOutbound->isChecked() );
}