2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2015-01-29 22:45:39 +01:00
|
|
|
*
|
|
|
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
2019-05-06 09:52:09 +02:00
|
|
|
* Copyright 2017, 2019, Adriaan de Groot <groot@kde.org>
|
2019-04-08 17:55:03 +02:00
|
|
|
* Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com>
|
2015-01-29 22:45:39 +01:00
|
|
|
*
|
|
|
|
* 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 "FinishedViewStep.h"
|
|
|
|
#include "FinishedPage.h"
|
2019-05-06 10:35:09 +02:00
|
|
|
|
|
|
|
#include "Branding.h"
|
2017-07-03 17:04:23 +02:00
|
|
|
#include "JobQueue.h"
|
2019-05-06 10:35:09 +02:00
|
|
|
#include "Settings.h"
|
2017-07-03 17:04:23 +02:00
|
|
|
|
|
|
|
#include "utils/Logger.h"
|
2019-05-06 10:35:09 +02:00
|
|
|
#include "utils/NamedEnum.h"
|
2019-05-06 09:52:09 +02:00
|
|
|
#include "utils/Variant.h"
|
2015-01-29 22:45:39 +01:00
|
|
|
|
2017-08-21 23:48:27 +02:00
|
|
|
#include <QtDBus/QDBusConnection>
|
|
|
|
#include <QtDBus/QDBusInterface>
|
|
|
|
#include <QtDBus/QDBusReply>
|
2015-01-29 22:45:39 +01:00
|
|
|
#include <QVariantMap>
|
|
|
|
|
2019-05-06 10:35:09 +02:00
|
|
|
static const NamedEnumTable< FinishedViewStep::RestartMode >&
|
|
|
|
modeNames()
|
|
|
|
{
|
|
|
|
using Mode = FinishedViewStep::RestartMode;
|
|
|
|
|
|
|
|
static const NamedEnumTable< Mode > names{
|
|
|
|
{ QStringLiteral( "never" ), Mode::Never },
|
|
|
|
{ QStringLiteral( "user-unchecked" ), Mode::UserUnchecked },
|
|
|
|
{ QStringLiteral( "user-checked" ), Mode::UserChecked },
|
|
|
|
{ QStringLiteral( "always" ), Mode::Always }
|
|
|
|
} ;
|
|
|
|
|
|
|
|
return names;
|
|
|
|
}
|
2017-08-21 23:48:27 +02:00
|
|
|
|
2015-01-29 22:45:39 +01:00
|
|
|
FinishedViewStep::FinishedViewStep( QObject* parent )
|
|
|
|
: Calamares::ViewStep( parent )
|
|
|
|
, m_widget( new FinishedPage() )
|
2017-08-23 11:25:07 +02:00
|
|
|
, installFailed( false )
|
2017-09-25 16:22:03 +02:00
|
|
|
, m_notifyOnFinished( false )
|
2015-01-29 22:45:39 +01:00
|
|
|
{
|
2017-08-23 11:25:07 +02:00
|
|
|
auto jq = Calamares::JobQueue::instance();
|
|
|
|
connect( jq, &Calamares::JobQueue::failed,
|
2017-08-21 23:48:27 +02:00
|
|
|
m_widget, &FinishedPage::onInstallationFailed );
|
2017-08-23 11:25:07 +02:00
|
|
|
connect( jq, &Calamares::JobQueue::failed,
|
|
|
|
this, &FinishedViewStep::onInstallationFailed );
|
2017-07-03 17:04:23 +02:00
|
|
|
|
2015-01-29 22:45:39 +01:00
|
|
|
emit nextStatusChanged( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FinishedViewStep::~FinishedViewStep()
|
|
|
|
{
|
|
|
|
if ( m_widget && m_widget->parent() == nullptr )
|
|
|
|
m_widget->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
FinishedViewStep::prettyName() const
|
|
|
|
{
|
2015-09-09 18:45:52 +02:00
|
|
|
return tr( "Finish" );
|
2015-01-29 22:45:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget*
|
|
|
|
FinishedViewStep::widget()
|
|
|
|
{
|
|
|
|
return m_widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
FinishedViewStep::isNextEnabled() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
FinishedViewStep::isBackEnabled() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
FinishedViewStep::isAtBeginning() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
FinishedViewStep::isAtEnd() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-21 23:48:27 +02:00
|
|
|
void
|
|
|
|
FinishedViewStep::sendNotification()
|
|
|
|
{
|
2017-08-23 11:25:07 +02:00
|
|
|
// If the installation failed, don't send notification popup;
|
|
|
|
// there's a (modal) dialog popped up with the failure notice.
|
2017-09-25 16:35:58 +02:00
|
|
|
if ( installFailed )
|
2017-08-23 11:25:07 +02:00
|
|
|
return;
|
|
|
|
|
2017-08-21 23:48:27 +02:00
|
|
|
QDBusInterface notify( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications" );
|
|
|
|
if ( notify.isValid() )
|
|
|
|
{
|
|
|
|
QDBusReply<uint> r = notify.call( "Notify",
|
|
|
|
QString( "Calamares" ),
|
|
|
|
QVariant( 0U ),
|
|
|
|
QString( "calamares" ),
|
2019-04-08 17:55:03 +02:00
|
|
|
Calamares::Settings::instance()->isSetupMode()
|
|
|
|
? tr( "Setup Complete" )
|
|
|
|
: tr( "Installation Complete" ),
|
|
|
|
Calamares::Settings::instance()->isSetupMode()
|
|
|
|
? tr( "The setup of %1 is complete." ).arg( *Calamares::Branding::VersionedName )
|
|
|
|
: tr( "The installation of %1 is complete." ).arg( *Calamares::Branding::VersionedName ),
|
2017-08-21 23:48:27 +02:00
|
|
|
QStringList(),
|
|
|
|
QVariantMap(),
|
|
|
|
QVariant( 0 )
|
|
|
|
);
|
|
|
|
if ( !r.isValid() )
|
2019-05-06 09:53:24 +02:00
|
|
|
cWarning() << "Could not call org.freedesktop.Notifications.Notify at end of installation." << r.error();
|
2017-08-21 23:48:27 +02:00
|
|
|
}
|
|
|
|
else
|
2019-05-06 09:53:24 +02:00
|
|
|
cWarning() << "Could not get dbus interface for notifications at end of installation." << notify.lastError();
|
2017-08-21 23:48:27 +02:00
|
|
|
}
|
|
|
|
|
2015-01-29 22:45:39 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
FinishedViewStep::onActivate()
|
|
|
|
{
|
|
|
|
m_widget->setUpRestart();
|
2017-08-21 23:48:27 +02:00
|
|
|
|
2017-09-25 16:22:03 +02:00
|
|
|
if ( m_notifyOnFinished )
|
|
|
|
sendNotification();
|
2015-01-29 22:45:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-28 13:20:19 +02:00
|
|
|
Calamares::JobList
|
2015-01-29 22:45:39 +01:00
|
|
|
FinishedViewStep::jobs() const
|
|
|
|
{
|
2019-05-28 13:20:19 +02:00
|
|
|
return Calamares::JobList();
|
2015-01-29 22:45:39 +01:00
|
|
|
}
|
|
|
|
|
2017-08-23 11:25:07 +02:00
|
|
|
void
|
|
|
|
FinishedViewStep::onInstallationFailed( const QString& message, const QString& details )
|
|
|
|
{
|
2019-04-17 11:57:46 +02:00
|
|
|
Q_UNUSED( message )
|
|
|
|
Q_UNUSED( details )
|
2017-08-23 11:25:07 +02:00
|
|
|
installFailed = true;
|
|
|
|
}
|
2015-01-29 22:45:39 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
|
|
|
{
|
2019-05-06 10:35:09 +02:00
|
|
|
RestartMode mode = RestartMode::Never;
|
|
|
|
|
|
|
|
QString restartMode = CalamaresUtils::getString( configurationMap, "restartNowMode" );
|
|
|
|
if ( restartMode.isEmpty() )
|
|
|
|
{
|
|
|
|
if ( configurationMap.contains( "restartNowEnabled" ) )
|
|
|
|
cWarning() << "Configuring the finished module with deprecated restartNowEnabled settings";
|
|
|
|
|
|
|
|
bool restartNowEnabled = CalamaresUtils::getBool( configurationMap, "restartNowEnabled", false );
|
|
|
|
bool restartNowChecked = CalamaresUtils::getBool( configurationMap, "restartNowChecked", false );
|
|
|
|
|
|
|
|
if ( !restartNowEnabled )
|
|
|
|
mode = RestartMode::Never;
|
|
|
|
else
|
|
|
|
mode = restartNowChecked ? RestartMode::UserChecked : RestartMode::UserUnchecked;
|
|
|
|
}
|
2019-05-06 12:23:10 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
mode = modeNames().find( restartMode, ok );
|
|
|
|
if ( !ok )
|
|
|
|
cWarning() << "Configuring the finished module with bad restartNowMode" << restartMode;
|
|
|
|
}
|
2019-05-06 09:52:09 +02:00
|
|
|
|
2019-05-06 10:35:09 +02:00
|
|
|
m_widget->setRestart( mode );
|
2019-05-06 09:52:09 +02:00
|
|
|
|
2019-05-06 10:35:09 +02:00
|
|
|
if ( mode != RestartMode::Never )
|
2015-01-29 22:45:39 +01:00
|
|
|
{
|
2019-05-06 09:52:09 +02:00
|
|
|
QString restartNowCommand = CalamaresUtils::getString( configurationMap, "restartNowCommand" );
|
|
|
|
if ( restartNowCommand.isEmpty() )
|
|
|
|
restartNowCommand = QStringLiteral( "shutdown -r now" );
|
|
|
|
m_widget->setRestartNowCommand( restartNowCommand );
|
2015-01-29 22:45:39 +01:00
|
|
|
}
|
2019-05-06 09:52:09 +02:00
|
|
|
|
|
|
|
m_notifyOnFinished = CalamaresUtils::getBool( configurationMap, "notifyOnFinished", false );
|
2015-01-29 22:45:39 +01:00
|
|
|
}
|
|
|
|
|
2015-09-09 18:45:52 +02:00
|
|
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( FinishedViewStepFactory, registerPlugin<FinishedViewStep>(); )
|