source: calamares/trunk/fuentes/src/modules/finished/FinishedViewStep.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 5.2 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
4 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
5 *
6 *   Calamares is free software: you can redistribute it and/or modify
7 *   it under the terms of the GNU General Public License as published by
8 *   the Free Software Foundation, either version 3 of the License, or
9 *   (at your option) any later version.
10 *
11 *   Calamares is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *   GNU General Public License for more details.
15 *
16 *   You should have received a copy of the GNU General Public License
17 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "FinishedViewStep.h"
21#include "FinishedPage.h"
22#include "JobQueue.h"
23
24#include "utils/Logger.h"
25
26#include <QtDBus/QDBusConnection>
27#include <QtDBus/QDBusInterface>
28#include <QtDBus/QDBusReply>
29#include <QVariantMap>
30
31#include "Branding.h"
32
33FinishedViewStep::FinishedViewStep( QObject* parent )
34    : Calamares::ViewStep( parent )
35    , m_widget( new FinishedPage() )
36    , installFailed( false )
37    , m_notifyOnFinished( false )
38{
39    auto jq = Calamares::JobQueue::instance();
40    connect( jq, &Calamares::JobQueue::failed,
41             m_widget, &FinishedPage::onInstallationFailed );
42    connect( jq, &Calamares::JobQueue::failed,
43             this, &FinishedViewStep::onInstallationFailed );
44
45    emit nextStatusChanged( true );
46}
47
48
49FinishedViewStep::~FinishedViewStep()
50{
51    if ( m_widget && m_widget->parent() == nullptr )
52        m_widget->deleteLater();
53}
54
55
56QString
57FinishedViewStep::prettyName() const
58{
59    return tr( "Finish" );
60}
61
62
63QWidget*
64FinishedViewStep::widget()
65{
66    return m_widget;
67}
68
69
70void
71FinishedViewStep::next()
72{
73    emit done();
74}
75
76
77void
78FinishedViewStep::back()
79{}
80
81
82bool
83FinishedViewStep::isNextEnabled() const
84{
85    return false;
86}
87
88
89bool
90FinishedViewStep::isBackEnabled() const
91{
92    return false;
93}
94
95
96bool
97FinishedViewStep::isAtBeginning() const
98{
99    return true;
100}
101
102
103bool
104FinishedViewStep::isAtEnd() const
105{
106    return true;
107}
108
109void
110FinishedViewStep::sendNotification()
111{
112    // If the installation failed, don't send notification popup;
113    // there's a (modal) dialog popped up with the failure notice.
114    if ( installFailed )
115        return;
116
117    QDBusInterface notify( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications" );
118    if ( notify.isValid() )
119    {
120        QDBusReply<uint> r = notify.call( "Notify",
121                                          QString( "Calamares" ),
122                                          QVariant( 0U ),
123                                          QString( "calamares" ),
124                                          tr( "Installation Complete" ),
125                                          tr( "The installation of %1 is complete." ).arg( *Calamares::Branding::VersionedName ),
126                                          QStringList(),
127                                          QVariantMap(),
128                                          QVariant( 0 )
129                                        );
130        if ( !r.isValid() )
131            cDebug() << "Could not call notify for end of installation." << r.error();
132    }
133    else
134        cDebug() << "Could not get dbus interface for notifications." << notify.lastError();
135}
136
137
138void
139FinishedViewStep::onActivate()
140{
141    m_widget->setUpRestart();
142
143    if ( m_notifyOnFinished )
144        sendNotification();
145}
146
147
148QList< Calamares::job_ptr >
149FinishedViewStep::jobs() const
150{
151    return QList< Calamares::job_ptr >();
152}
153
154void
155FinishedViewStep::onInstallationFailed( const QString& message, const QString& details )
156{
157    Q_UNUSED( message );
158    Q_UNUSED( details );
159    installFailed = true;
160}
161
162void
163FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap )
164{
165    if ( configurationMap.contains( "restartNowEnabled" ) &&
166            configurationMap.value( "restartNowEnabled" ).type() == QVariant::Bool )
167    {
168        bool restartNowEnabled = configurationMap.value( "restartNowEnabled" ).toBool();
169
170        m_widget->setRestartNowEnabled( restartNowEnabled );
171        if ( restartNowEnabled )
172        {
173            if ( configurationMap.contains( "restartNowChecked" ) &&
174                    configurationMap.value( "restartNowChecked" ).type() == QVariant::Bool )
175                m_widget->setRestartNowChecked( configurationMap.value( "restartNowChecked" ).toBool() );
176
177            if ( configurationMap.contains( "restartNowCommand" ) &&
178                    configurationMap.value( "restartNowCommand" ).type() == QVariant::String )
179                m_widget->setRestartNowCommand( configurationMap.value( "restartNowCommand" ).toString() );
180            else
181                m_widget->setRestartNowCommand( "shutdown -r now" );
182        }
183    }
184    if ( configurationMap.contains( "notifyOnFinished" ) &&
185            configurationMap.value( "notifyOnFinished" ).type() == QVariant::Bool )
186        m_notifyOnFinished = configurationMap.value( "notifyOnFinished" ).toBool();
187}
188
189CALAMARES_PLUGIN_FACTORY_DEFINITION( FinishedViewStepFactory, registerPlugin<FinishedViewStep>(); )
Note: See TracBrowser for help on using the repository browser.