summaryrefslogtreecommitdiffstats
path: root/yakuake/src/terminal.cpp
blob: 75dd9420f7a979c860d5a3458b2d0f6dd88ac40f (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
/*
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
*/

/*
  Copyright (C) 2005 Francois Chazal <neptune3k@free.fr>
  Copyright (C) 2006-2007 Eike Hein <hein@kde.org>
*/


#include "terminal.h"
#include "terminal.moc"


int Terminal::available_terminal_id = 0;

Terminal::Terminal(TQWidget* parent, const char* name) : TQObject(parent, name)
{
    terminal_id = available_terminal_id;
    available_terminal_id++;

    setenv("DCOP_YAKUAKE_TERMINAL", TQString::number(terminal_id).ascii(), 1);
    putenv((char*)"COLORTERM="); // Trigger mc's color detection.

    KLibFactory* factory = NULL;

    terminal_part = NULL;
    terminal_title = "";
    terminal_widget = NULL;
    terminal_interface = NULL;

    if ((factory = KLibLoader::self()->factory("libkonsolepart")) != NULL)
    {
        TQStringList args = TQStringList();
        args.append(TQString("Terminal-") + TQString::number(terminal_id));
        terminal_part = (KParts::Part *) (factory->create(TQT_TQOBJECT(parent), 0, "KParts::Part", args));
    }

    if (terminal_part != NULL)
    {
        terminal_widget = terminal_part->widget();
        terminal_widget->setFocusPolicy(TQ_WheelFocus);
        terminal_interface = (TerminalInterface *) (terminal_part->tqt_cast("TerminalInterface"));

        connect(terminal_part, TQT_SIGNAL(destroyed()), this, TQT_SLOT(deleteLater()));
        connect(terminal_part, TQT_SIGNAL(setWindowCaption(const TQString &)), this, TQT_SLOT(slotUpdateSessionTitle(const TQString &)));
    }
}

Terminal::~Terminal()
{
    emit destroyed(terminal_id);
}

TQWidget* Terminal::widget()
{
    return terminal_widget;
}

TerminalInterface* Terminal::terminal()
{
    return terminal_interface;
}

const TQString Terminal::title()
{
    return terminal_title;
}

void Terminal::setTitle(const TQString& title)
{
    slotUpdateSessionTitle(title);
}

void Terminal::slotUpdateSessionTitle(const TQString& title)
{
    terminal_title = title;

    // Remove trailing " -" from the caption. If needed this is
    // handled later in TitleBar.
    if (terminal_title.endsWith(" - "))
        terminal_title.truncate(terminal_title.length() - 3);

    emit titleChanged(terminal_widget, terminal_title);
}