summaryrefslogtreecommitdiff
path: root/raveos-calamares/0003-restart-button.patch
blob: 0d8e0f4b15e0e34bbae5383d182a2fbf8d571d09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
--- a/src/calamares/CalamaresWindow.cpp
+++ b/src/calamares/CalamaresWindow.cpp
@@ -24,6 +24,7 @@
 #include "utils/Logger.h"
 #include "utils/Qml.h"
 #include "utils/Retranslator.h"
+#include "viewpages/ExecutionViewStep.h"
 #include "viewpages/ViewStep.h"
 
 #include <QApplication>
@@ -34,7 +35,10 @@
 #endif
 #include <QFile>
 #include <QFileInfo>
+#include <QDialog>
 #include <QLabel>
+#include <QProcess>
+#include <QPushButton>
 #ifdef WITH_QML
 #include <QQmlContext>
 #include <QQmlEngine>
@@ -207,6 +211,38 @@
     return sideBox;
 }
 
+/** @brief RaveOS: localized confirm dialog for the global restart button. */
+static bool
+raveosConfirmRestart( QWidget* parent )
+{
+    QDialog dialog( parent );
+    dialog.setObjectName( QStringLiteral( "raveosDialog" ) );
+    dialog.setWindowTitle( QStringLiteral( "RaveOS" ) );
+    dialog.setMinimumWidth( 420 );
+
+    auto* layout = new QVBoxLayout( &dialog );
+    auto* label = new QLabel( QCoreApplication::translate( "raveos", "Restart the computer?" ), &dialog );
+    label->setObjectName( QStringLiteral( "raveosDialogLabel" ) );
+    label->setWordWrap( true );
+    layout->addWidget( label );
+    layout->addSpacing( 10 );
+
+    auto* buttons = new QHBoxLayout;
+    buttons->addStretch();
+    auto* cancel = new QPushButton( QCoreApplication::translate( "raveos", "Cancel" ), &dialog );
+    cancel->setObjectName( QStringLiteral( "raveosDialogCancel" ) );
+    auto* ok = new QPushButton( QCoreApplication::translate( "raveos", "Restart" ), &dialog );
+    ok->setObjectName( QStringLiteral( "raveosDialogOk" ) );
+    buttons->addWidget( cancel );
+    buttons->addWidget( ok );
+    layout->addLayout( buttons );
+
+    QObject::connect( cancel, &QPushButton::clicked, &dialog, &QDialog::reject );
+    QObject::connect( ok, &QPushButton::clicked, &dialog, &QDialog::accept );
+
+    return dialog.exec() == QDialog::Accepted;
+}
+
 static QWidget*
 getWidgetNavigation( Calamares::DebugWindowManager*,
                      Calamares::ViewManager* viewManager,
@@ -216,6 +252,45 @@
 {
     QWidget* navigation = new QWidget( parent );
     QBoxLayout* bottomLayout = new QHBoxLayout;
+
+    // RaveOS: globalis ujrainditas gomb a bal also sarokban.
+    // Telepites kozben (exec) es a finish oldalon NEM latszik.
+    {
+        auto* restart = new QPushButton( navigation );
+        restart->setObjectName( "restartButton" );
+        restart->setIcon( getButtonIcon( QStringLiteral( "view-refresh" ) ) );
+        CALAMARES_RETRANSLATE_FOR(
+            restart,
+            restart->setText( QCoreApplication::translate( CalamaresWindow::staticMetaObject.className(),
+                                                           "&Restart",
+                                                           "@button" ) );
+            restart->setToolTip( QCoreApplication::translate( CalamaresWindow::staticMetaObject.className(),
+                                                              "Restart the computer",
+                                                              "@tooltip" ) ); );
+        QObject::connect( restart,
+                          &QPushButton::clicked,
+                          restart,
+                          [restart]()
+                          {
+                              if ( raveosConfirmRestart( restart ) )
+                              {
+                                  QProcess::startDetached( QStringLiteral( "systemctl" ),
+                                                           { QStringLiteral( "-i" ), QStringLiteral( "reboot" ) } );
+                              }
+                          } );
+        bottomLayout->addWidget( restart );
+
+        auto updateVisibility = [restart, viewManager]()
+        {
+            auto* step = viewManager->currentStep();
+            const bool inExec = qobject_cast< Calamares::ExecutionViewStep* >( step ) != nullptr;
+            const bool onFinish = step && step->isAtEnd() && !step->isNextEnabled();
+            restart->setVisible( !inExec && !onFinish );
+        };
+        QObject::connect( viewManager, &Calamares::ViewManager::currentStepChanged, restart, updateVisibility );
+        updateVisibility();
+    }
+
     bottomLayout->addStretch();
 
     // Create buttons and sets an initial icon; the icons may change
@@ -272,7 +347,7 @@
         bottomLayout->addWidget( quit );
     }
 
-    bottomLayout->setContentsMargins( 0, 0, 6, 6 );
+    bottomLayout->setContentsMargins( 6, 0, 6, 6 );
     navigation->setLayout( bottomLayout );
     return navigation;
 }