1 /**************************************************************************
2 *   Copyright (C) 2005-2020 by Oleksandr Shneyder                         *
3 *                              <o.shneyder@phoca-gmbh.de>                 *
4 *                                                                         *
5 *   This program is free software; you can redistribute it and/or modify  *
6 *   it under the terms of the GNU General Public License as published by  *
7 *   the Free Software Foundation; either version 2 of the License, or     *
8 *   (at your option) any later version.                                   *
9 *   This program is distributed in the hope that it will be useful,       *
10 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 *   GNU General Public License for more details.                          *
13 *                                                                         *
14 *   You should have received a copy of the GNU General Public License     *
15 *   along with this program.  If not, see <https://www.gnu.org/licenses/>. *
16 ***************************************************************************/
17 
18 #include "InteractionDialog.h"
19 #include "x2goclientconfig.h"
20 #include "onmainwindow.h"
21 #include <QTextEdit>
22 #include <QVBoxLayout>
23 #include <QPushButton>
24 #include <QLabel>
25 #include <QLineEdit>
26 #include <QScrollBar>
27 #include <QTimer>
28 
29 #ifndef Q_OS_UNIX
30 #if QT_VERSION < 0x050000
31 #include <QPlastiqueStyle>
32 #else
33 #include <QStyleFactory>
34 #endif
35 #endif
36 
InteractionDialog(QWidget * parent)37 InteractionDialog::InteractionDialog(QWidget* parent): SVGFrame(":/img/svg/passform.svg",
38             false,parent )
39 {
40     mw=(ONMainWindow*)parent;
41 
42     if ( !mw->retMiniMode() )
43         setFixedSize ( this->sizeHint().width(),this->sizeHint().height()*1.5 );
44     else
45         setFixedSize ( 310,280 );
46 
47 
48     QPalette pal=this->palette();
49     pal.setBrush ( QPalette::Window, QColor ( 255,255,255,0 ) );
50     pal.setColor ( QPalette::Active, QPalette::WindowText, QPalette::Mid );
51     pal.setColor ( QPalette::Active, QPalette::ButtonText, QPalette::Mid );
52     pal.setColor ( QPalette::Active, QPalette::Text, QPalette::Mid );
53     pal.setColor ( QPalette::Inactive, QPalette::WindowText, QPalette::Mid );
54     pal.setColor ( QPalette::Inactive, QPalette::ButtonText, QPalette::Mid );
55     pal.setColor ( QPalette::Inactive, QPalette::Text, QPalette::Mid );
56 
57     this->setPalette ( pal );
58 
59     pal.setColor ( QPalette::Button, QColor ( 255,255,255,0 ) );
60     pal.setColor ( QPalette::Window, QColor ( 255,255,255,255 ) );
61     pal.setColor ( QPalette::Base, QColor ( 255,255,255,255 ) );
62 
63     QFont fnt=this->font();
64     if ( mw->retMiniMode() )
65 #ifdef Q_WS_HILDON
66         fnt.setPointSize ( 10 );
67 #else
68         fnt.setPointSize ( 9 );
69 #endif
70     this->setFont ( fnt );
71     this->hide();
72 
73     textEdit=new QTextEdit(this);
74     QVBoxLayout* lay=new QVBoxLayout(this);
75     lay->addWidget(new QLabel(tr("Terminal output:")));
76     lay->addWidget(textEdit);
77 
78     textEntry=new QLineEdit(this);
79     textEntry->setEchoMode(QLineEdit::Password);
80     lay->addWidget(textEntry);
81 
82     cancelButton=new QPushButton(tr("Cancel"),this);
83     lay->addWidget(cancelButton);
84     textEdit->setReadOnly(true);
85     connect(textEntry,SIGNAL(returnPressed()),this,SLOT(slotTextEntered()));
86     connect(cancelButton, SIGNAL(clicked(bool)),this,SLOT(slotButtonPressed()));
87     textEdit->setFrameStyle ( QFrame::StyledPanel|QFrame::Plain );
88     cancelButton->setFlat(true);
89 
90 #ifndef Q_OS_UNIX
91     QStyle* widgetExtraStyle;
92 #if QT_VERSION < 0x050000
93     widgetExtraStyle = new QPlastiqueStyle ();
94 #else
95     widgetExtraStyle = QStyleFactory::create ("fusion");
96 #endif
97 
98     this->setStyle(widgetExtraStyle);
99     textEntry->setStyle(widgetExtraStyle);
100     textEdit->setStyle(widgetExtraStyle);
101     textEdit->viewport()->setStyle(widgetExtraStyle);
102     cancelButton->setStyle(widgetExtraStyle);
103 
104 #endif
105 }
106 
~InteractionDialog()107 InteractionDialog::~InteractionDialog()
108 {
109 //     qDebug()<<"Iter dlg destruct\n";
110 }
111 
appendText(QString txt)112 void InteractionDialog::appendText(QString txt)
113 {
114     textEntry->setEnabled(true);
115     textEdit->append(txt);
116     textEntry->setFocus();
117     interrupted=false;
118     display=false;
119     cancelButton->setText(tr("Cancel"));
120     QTimer::singleShot(0, textEntry, SLOT(setFocus()));
121 }
122 
reset()123 void InteractionDialog::reset()
124 {
125     textEdit->clear();
126 }
127 
slotTextEntered()128 void InteractionDialog::slotTextEntered()
129 {
130     QString text=textEntry->text()+"\n";
131     textEntry->clear();
132     emit textEntered(text);
133 }
134 
slotButtonPressed()135 void InteractionDialog::slotButtonPressed()
136 {
137     if(!display)
138     {
139         emit interrupt();
140         interrupted=true;
141     }
142     else
143     {
144         qDebug()<<"reconnect";
145         emit closeInterractionDialog();
146     }
147 }
148 
setDisplayMode()149 void InteractionDialog::setDisplayMode()
150 {
151     cancelButton->setText(tr("Reconnect"));
152     textEntry->setEnabled(false);
153     display=true;
154 }
155 
setInteractionMode(IMode value)156 void InteractionDialog::setInteractionMode(IMode value)
157 {
158     interactionMode=value;
159 }
160 
161