~verzegnassi-stefano/+junk/ubuntu-terminal-app-uitk13

« back to all changes in this revision

Viewing changes to src/plugin/qmltermwidget/qtermwidget/lib/kptyprocess.cpp

  • Committer: Filippo Scognamiglio
  • Date: 2014-10-25 04:42:31 UTC
  • Revision ID: flscogna@gmail.com-20141025044231-javjhusbqa171127
Initial reboot commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is a part of QTerminal - http://gitorious.org/qterminal
 
3
 *
 
4
 * This file was un-linked from KDE and modified
 
5
 * by Maxim Bourmistrov <maxim@unixconn.com>
 
6
 *
 
7
 */
 
8
 
 
9
/*
 
10
    This file is part of the KDE libraries
 
11
 
 
12
    Copyright (C) 2007 Oswald Buddenhagen <ossi@kde.org>
 
13
 
 
14
    This library is free software; you can redistribute it and/or
 
15
    modify it under the terms of the GNU Library General Public
 
16
    License as published by the Free Software Foundation; either
 
17
    version 2 of the License, or (at your option) any later version.
 
18
 
 
19
    This library is distributed in the hope that it will be useful,
 
20
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
22
    Library General Public License for more details.
 
23
 
 
24
    You should have received a copy of the GNU Library General Public License
 
25
    along with this library; see the file COPYING.LIB.  If not, write to
 
26
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
27
    Boston, MA 02110-1301, USA.
 
28
*/
 
29
 
 
30
 
 
31
#include "kptyprocess.h"
 
32
#include "kprocess.h"
 
33
#include "kptydevice.h"
 
34
 
 
35
#include <stdlib.h>
 
36
#include <unistd.h>
 
37
 
 
38
KPtyProcess::KPtyProcess(QObject *parent) :
 
39
    KProcess(new KPtyProcessPrivate, parent)
 
40
{
 
41
    Q_D(KPtyProcess);
 
42
 
 
43
    d->pty = new KPtyDevice(this);
 
44
    d->pty->open();
 
45
    connect(this, SIGNAL(stateChanged(QProcess::ProcessState)),
 
46
            SLOT(_k_onStateChanged(QProcess::ProcessState)));
 
47
}
 
48
 
 
49
KPtyProcess::KPtyProcess(int ptyMasterFd, QObject *parent) :
 
50
    KProcess(new KPtyProcessPrivate, parent)
 
51
{
 
52
    Q_D(KPtyProcess);
 
53
 
 
54
    d->pty = new KPtyDevice(this);
 
55
    d->pty->open(ptyMasterFd);
 
56
    connect(this, SIGNAL(stateChanged(QProcess::ProcessState)),
 
57
            SLOT(_k_onStateChanged(QProcess::ProcessState)));
 
58
}
 
59
 
 
60
KPtyProcess::~KPtyProcess()
 
61
{
 
62
    Q_D(KPtyProcess);
 
63
 
 
64
    if (state() != QProcess::NotRunning && d->addUtmp) {
 
65
        d->pty->logout();
 
66
        disconnect(SIGNAL(stateChanged(QProcess::ProcessState)),
 
67
                   this, SLOT(_k_onStateChanged(QProcess::ProcessState)));
 
68
    }
 
69
    delete d->pty;
 
70
}
 
71
 
 
72
void KPtyProcess::setPtyChannels(PtyChannels channels)
 
73
{
 
74
    Q_D(KPtyProcess);
 
75
 
 
76
    d->ptyChannels = channels;
 
77
}
 
78
 
 
79
KPtyProcess::PtyChannels KPtyProcess::ptyChannels() const
 
80
{
 
81
    Q_D(const KPtyProcess);
 
82
 
 
83
    return d->ptyChannels;
 
84
}
 
85
 
 
86
void KPtyProcess::setUseUtmp(bool value)
 
87
{
 
88
    Q_D(KPtyProcess);
 
89
 
 
90
    d->addUtmp = value;
 
91
}
 
92
 
 
93
bool KPtyProcess::isUseUtmp() const
 
94
{
 
95
    Q_D(const KPtyProcess);
 
96
 
 
97
    return d->addUtmp;
 
98
}
 
99
 
 
100
KPtyDevice *KPtyProcess::pty() const
 
101
{
 
102
    Q_D(const KPtyProcess);
 
103
 
 
104
    return d->pty;
 
105
}
 
106
 
 
107
void KPtyProcess::setupChildProcess()
 
108
{
 
109
    Q_D(KPtyProcess);
 
110
 
 
111
    d->pty->setCTty();
 
112
 
 
113
#if 0
 
114
    if (d->addUtmp)
 
115
        d->pty->login(KUser(KUser::UseRealUserID).loginName().toLocal8Bit().data(), qgetenv("DISPLAY"));
 
116
#endif
 
117
    if (d->ptyChannels & StdinChannel)
 
118
        dup2(d->pty->slaveFd(), 0);
 
119
 
 
120
    if (d->ptyChannels & StdoutChannel)
 
121
        dup2(d->pty->slaveFd(), 1);
 
122
 
 
123
    if (d->ptyChannels & StderrChannel)
 
124
        dup2(d->pty->slaveFd(), 2);
 
125
 
 
126
    KProcess::setupChildProcess();
 
127
}
 
128
 
 
129
//#include "kptyprocess.moc"