2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2015-08-21 16:44:33 +02:00
|
|
|
*
|
|
|
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
|
|
|
*
|
|
|
|
* Calamares 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "InteractiveTerminalPage.h"
|
|
|
|
|
|
|
|
#include "viewpages/ViewStep.h"
|
|
|
|
#include "utils/Retranslator.h"
|
|
|
|
#include "utils/CalamaresUtilsGui.h"
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
|
|
|
#include <KF5/KService/kservice.h>
|
|
|
|
#include <KF5/KParts/kde_terminal_interface.h>
|
|
|
|
#include <KF5/KParts/kparts/readonlypart.h>
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
|
|
InteractiveTerminalPage::InteractiveTerminalPage( QWidget* parent )
|
|
|
|
: QWidget( parent )
|
|
|
|
, m_layout( new QVBoxLayout( this ) )
|
|
|
|
, m_termHostWidget( nullptr )
|
|
|
|
{
|
|
|
|
setLayout( m_layout );
|
|
|
|
m_layout->setContentsMargins( 0, 0, 0, 0 );
|
|
|
|
|
|
|
|
m_headerLabel = new QLabel( this );
|
|
|
|
m_layout->addWidget( m_headerLabel );
|
|
|
|
}
|
|
|
|
|
2017-11-28 12:45:56 +01:00
|
|
|
void
|
|
|
|
InteractiveTerminalPage::errorKonsoleNotInstalled()
|
2017-11-28 11:05:28 +01:00
|
|
|
{
|
2017-11-28 12:45:56 +01:00
|
|
|
QMessageBox::critical( this,
|
|
|
|
tr( "Konsole not installed"),
|
|
|
|
tr( "Please install KDE Konsole and try again!" ),
|
2017-11-28 11:05:28 +01:00
|
|
|
QMessageBox::Ok );
|
|
|
|
}
|
2015-08-21 16:44:33 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
InteractiveTerminalPage::onActivate()
|
|
|
|
{
|
|
|
|
if ( m_termHostWidget )
|
|
|
|
return;
|
|
|
|
// For whatever reason, instead of simply linking against a library we
|
|
|
|
// need to do a runtime query to KService just to get a sodding terminal
|
|
|
|
// widget.
|
|
|
|
KService::Ptr service = KService::serviceByDesktopName( "konsolepart" );
|
|
|
|
if ( !service )
|
|
|
|
{
|
|
|
|
// And all of this hoping the Konsole application is installed. If not,
|
|
|
|
// tough cookies.
|
2017-11-28 12:45:56 +01:00
|
|
|
errorKonsoleNotInstalled();
|
2015-08-21 16:44:33 +02:00
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create one instance of konsolepart.
|
|
|
|
KParts::ReadOnlyPart* p =
|
|
|
|
service->createInstance< KParts::ReadOnlyPart >( this,
|
|
|
|
this,
|
|
|
|
{} );
|
|
|
|
if ( !p )
|
|
|
|
{
|
|
|
|
// One more opportunity for the loading operation to fail.
|
2017-11-28 12:45:56 +01:00
|
|
|
errorKonsoleNotInstalled();
|
2015-08-21 16:44:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cast the konsolepart to the TerminalInterface...
|
|
|
|
TerminalInterface* t = qobject_cast< TerminalInterface* >( p );
|
|
|
|
if ( !t )
|
|
|
|
{
|
|
|
|
// This is why we can't have nice things.
|
2017-11-28 12:45:56 +01:00
|
|
|
errorKonsoleNotInstalled();
|
2015-08-21 16:44:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make the widget persist even if the KPart goes out of scope...
|
|
|
|
p->setAutoDeleteWidget( false );
|
|
|
|
// ... but kill the KPart if the widget goes out of scope.
|
|
|
|
p->setAutoDeletePart( true );
|
|
|
|
|
|
|
|
m_termHostWidget = p->widget();
|
|
|
|
m_layout->addWidget( m_termHostWidget );
|
|
|
|
cDebug() << "Part widget ought to be"
|
|
|
|
<< m_termHostWidget->metaObject()->className();
|
|
|
|
|
|
|
|
t->showShellInDir( QDir::home().path() );
|
|
|
|
t->sendInput( QString( "%1\n" ).arg( m_command ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
InteractiveTerminalPage::setCommand( const QString& command )
|
|
|
|
{
|
|
|
|
m_command = command;
|
|
|
|
CALAMARES_RETRANSLATE(
|
|
|
|
m_headerLabel->setText( tr( "Executing script: <code>%1</code>" )
|
|
|
|
.arg( m_command ) );
|
|
|
|
)
|
|
|
|
}
|