interactiveterminal ViewModule, based on the Konsole KPart.

main
Teo Mrnjavac 10 years ago
parent 05292241c4
commit 49c03bbf2c

@ -0,0 +1,27 @@
find_package(ECM 0.0.13 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH})
include(KDEInstallDirs) # this seems to be necessary for KF5::CoreAddons
include(GenerateExportHeader) # this too, because KDE frameworks always want omnomnom more stuff
find_package( KF5 REQUIRED Service Parts )
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui
${QTERMWIDGET_INCLUDE_DIR} )
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules )
calamares_add_plugin( interactiveterminal
TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO
SOURCES
InteractiveTerminalViewStep.cpp
InteractiveTerminalPage.cpp
LINK_LIBRARIES
calamaresui
KF5::Service
KF5::Parts
SHARED_LIB
)

@ -0,0 +1,125 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* 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 );
}
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.
// Maybe linking against a library seemed too simple and elegant so
// someone decided to have a terminal widget depend on over 9000 other
// KDElibs things that have nothing to do with a terminal widget, and
// have the loading happen at runtime so it's more likely to fail at
// an inconvenient time.
QMessageBox::critical( this,
tr( "Konsole not installed"),
tr( "Please install the kde konsole and try again!" ),
QMessageBox::Ok);
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.
QMessageBox::critical( this,
tr( "Konsole not installed"),
tr( "Please install the kde konsole and try again!" ),
QMessageBox::Ok);
return;
}
// Cast the konsolepart to the TerminalInterface...
TerminalInterface* t = qobject_cast< TerminalInterface* >( p );
if ( !t )
{
// This is why we can't have nice things.
QMessageBox::critical( this,
tr( "Konsole not installed"),
tr( "Please install the kde konsole and try again!" ),
QMessageBox::Ok);
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: &nbsp;<code>%1</code>" )
.arg( m_command ) );
)
}

@ -0,0 +1,44 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* 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/>.
*/
#ifndef INTERACTIVETERMINALPAGE_H
#define INTERACTIVETERMINALPAGE_H
#include <QWidget>
class QLabel;
class QVBoxLayout;
class InteractiveTerminalPage : public QWidget
{
Q_OBJECT
public:
explicit InteractiveTerminalPage( QWidget* parent = nullptr );
void onActivate();
void setCommand( const QString& command );
private:
QVBoxLayout* m_layout;
QWidget* m_termHostWidget;
QString m_command;
QLabel* m_headerLabel;
};
#endif // INTERACTIVETERMINALPAGE_H

@ -0,0 +1,115 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* 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 "InteractiveTerminalViewStep.h"
#include "InteractiveTerminalPage.h"
#include <QVariant>
InteractiveTerminalViewStep::InteractiveTerminalViewStep( QObject* parent )
: Calamares::ViewStep( parent )
, m_widget( new InteractiveTerminalPage() )
{
emit nextStatusChanged( true );
}
InteractiveTerminalViewStep::~InteractiveTerminalViewStep()
{
if ( m_widget && m_widget->parent() == nullptr )
m_widget->deleteLater();
}
QString
InteractiveTerminalViewStep::prettyName() const
{
return tr( "Script" );
}
QWidget*
InteractiveTerminalViewStep::widget()
{
return m_widget;
}
void
InteractiveTerminalViewStep::next()
{
emit done();
}
void
InteractiveTerminalViewStep::back()
{}
bool
InteractiveTerminalViewStep::isNextEnabled() const
{
return true;
}
bool
InteractiveTerminalViewStep::isBackEnabled() const
{
return true;
}
bool
InteractiveTerminalViewStep::isAtBeginning() const
{
return true;
}
bool
InteractiveTerminalViewStep::isAtEnd() const
{
return true;
}
QList< Calamares::job_ptr >
InteractiveTerminalViewStep::jobs() const
{
return QList< Calamares::job_ptr >();
}
void
InteractiveTerminalViewStep::onActivate()
{
m_widget->onActivate();
}
void
InteractiveTerminalViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{
if ( configurationMap.contains( "command" ) &&
configurationMap.value( "command").type() == QVariant::String )
m_widget->setCommand( configurationMap.value( "command" ).toString() );
}

@ -0,0 +1,64 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* 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/>.
*/
#ifndef INTERACTIVETERMINALPAGEPLUGIN_H
#define INTERACTIVETERMINALPAGEPLUGIN_H
#include <QObject>
#include "viewpages/ViewStep.h"
#include "PluginDllMacro.h"
class InteractiveTerminalPage;
class PLUGINDLLEXPORT InteractiveTerminalViewStep : public Calamares::ViewStep
{
Q_OBJECT
Q_PLUGIN_METADATA( IID "calamares.ViewModule/1.0" )
Q_INTERFACES( Calamares::ViewStep )
public:
explicit InteractiveTerminalViewStep( QObject* parent = nullptr );
virtual ~InteractiveTerminalViewStep();
QString prettyName() const override;
QWidget* widget() override;
void next() override;
void back() override;
bool isNextEnabled() const override;
bool isBackEnabled() const override;
bool isAtBeginning() const override;
bool isAtEnd() const override;
QList< Calamares::job_ptr > jobs() const override;
void onActivate() override;
protected:
void setConfigurationMap( const QVariantMap& configurationMap ) override;
private:
InteractiveTerminalPage* m_widget;
};
#endif // INTERACTIVETERMINALPAGEPLUGIN_H

@ -0,0 +1,7 @@
# Module metadata file for interactiveterminal viewmodule
# Syntax is YAML 1.2
---
type: "view"
name: "interactiveterminal"
interface: "qtplugin"
load: "libcalamares_viewmodule_interactiveterminal.so"
Loading…
Cancel
Save