Finish do-release-upgrade support (untested)

ubuntu/noble
Aaron Rainbolt 11 months ago
parent d71a36f0ef
commit 86c512a2ff

@ -41,6 +41,9 @@ set(PROJECT_SOURCES
src/releaseupgradewindow.h src/releaseupgradewindow.h
src/releaseupgradewindow.cpp src/releaseupgradewindow.cpp
src/releaseupgradewindow.ui src/releaseupgradewindow.ui
src/upgradedelaywindow.h
src/upgradedelaywindow.cpp
src/upgradedelaywindow.ui
${TS_FILES} ${TS_FILES}
) )

@ -165,4 +165,8 @@ elif [ "$1" = 'doupdate' ]; then
fi fi
echo 'Update installation complete.' echo 'Update installation complete.'
elif [ "$1" = 'doReleaseUpgrade' ]; then
do-release-upgrade -m desktop -f DistUpgradeViewKDE;
elif [ "$1" = 'declineReleaseUpgrade' ]; then
sed -i -E 's/^Prompt=(never|lts|normal)$/Prompt=never/' /etc/update-manager/release-upgrades;
fi fi

@ -1,11 +1,13 @@
#include "orchestrator.h" #include "orchestrator.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "aptmanager.h" #include "aptmanager.h"
#include "releaseupgradewindow.h"
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QIcon> #include <QIcon>
#include <QProcess>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QTimer> #include <QTimer>
@ -40,11 +42,13 @@ Orchestrator::Orchestrator(QObject *parent)
} }
} }
} }
configFile.close();
connect(checkTimer, &QTimer::timeout, this, &Orchestrator::checkForUpdates); connect(checkTimer, &QTimer::timeout, this, &Orchestrator::checkForUpdates);
connect(trayIcon, &QSystemTrayIcon::activated, this, &Orchestrator::displayUpdater); connect(trayIcon, &QSystemTrayIcon::activated, this, &Orchestrator::displayUpdater);
connect(&updaterWindow, &MainWindow::updatesInstalled, this, &Orchestrator::handleUpdatesInstalled); connect(&updaterWindow, &MainWindow::updatesInstalled, this, &Orchestrator::handleUpdatesInstalled);
connect(&updaterWindow, &MainWindow::updatesRefreshed, this, &Orchestrator::handleUpdatesRefreshed); connect(&updaterWindow, &MainWindow::updatesRefreshed, this, &Orchestrator::handleUpdatesRefreshed);
connect(&updaterWindow, &MainWindow::newReleaseAvailable, this, &Orchestrator::onNewReleaseAvailable);
checkTimer->start(21600000); // check four times a day, at least one of those times unattended-upgrades should have refreshed the apt database checkTimer->start(21600000); // check four times a day, at least one of those times unattended-upgrades should have refreshed the apt database
@ -131,9 +135,51 @@ void Orchestrator::onNewReleaseAvailable(QStringList releaseCodes)
if (((releaseYear % 2 == 0) && (releaseMonth == 4)) || druType == "normal") { if (((releaseYear % 2 == 0) && (releaseMonth == 4)) || druType == "normal") {
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
if (nextUpgradeCheck < now) { if (nextUpgradeCheck < now) {
// TODO: attempt to show window here ReleaseUpgradeWindow upgradeWindow(releaseCodes[i]);
upgradeWindow.exec();
if (upgradeWindow.getUpgradeAccepted()) {
doReleaseUpgrade();
} else if (upgradeWindow.getUpgradeDelayStamp() > 0) {
delayReleaseUpgrade(upgradeWindow.getUpgradeDelayStamp());
} else {
declineReleaseUpgrade();
}
break;
} }
} }
} }
} }
} }
void Orchestrator::doReleaseUpgrade()
{
QProcess druProcess;
druProcess.setProgram("/usr/bin/lxqt-sudo");
druProcess.setArguments(QStringList() << "/usr/libexec/lubuntu-update-backend" << "doReleaseUpgrade");
druProcess.start();
druProcess.waitForFinished(-1);
}
void Orchestrator::delayReleaseUpgrade(qint64 timestamp)
{
QFile configFile(QDir::homePath() + "/.config/lubuntu-update.conf");
bool success = configFile.open(QFile::WriteOnly);
if (success) {
configFile.write("nextDoReleaseUpgradeNotify=");
configFile.write(QString::number(timestamp).toUtf8());
configFile.write("\n");
} else {
qWarning() << "Could not write to " + QDir::homePath() + "/.config/lubuntu-update.conf, check permissions";
}
configFile.close();
nextUpgradeCheck = QDateTime::fromSecsSinceEpoch(timestamp);
}
void Orchestrator::declineReleaseUpgrade()
{
QProcess druProcess;
druProcess.setProgram("/usr/bin/lxqt-sudo");
druProcess.setArguments(QStringList() << "/usr/libexec/lubuntu-update-backend" << "declineReleaseUpgrade");
druProcess.start();
druProcess.waitForFinished(-1);
}

@ -9,6 +9,7 @@
class QTimer; class QTimer;
class QSystemTrayIcon; class QSystemTrayIcon;
class ReleaseUpgradeWindow;
class Orchestrator : public QObject class Orchestrator : public QObject
{ {
@ -31,6 +32,9 @@ private:
QList<QStringList> updateInfo; QList<QStringList> updateInfo;
MainWindow updaterWindow; MainWindow updaterWindow;
QDateTime nextUpgradeCheck; QDateTime nextUpgradeCheck;
void doReleaseUpgrade();
void delayReleaseUpgrade(qint64 timestamp);
void declineReleaseUpgrade();
}; };
#endif // ORCHESTRATOR_H #endif // ORCHESTRATOR_H

@ -1,12 +1,18 @@
#include "releaseupgradewindow.h" #include "releaseupgradewindow.h"
#include "ui_releaseupgradewindow.h" #include "ui_releaseupgradewindow.h"
#include "upgradedelaywindow.h"
#include <QDateTime>
#include <QMessageBox>
ReleaseUpgradeWindow::ReleaseUpgradeWindow(QString releaseCode, QWidget *parent) : ReleaseUpgradeWindow::ReleaseUpgradeWindow(QString releaseCode, QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::ReleaseUpgradeWindow) ui(new Ui::ReleaseUpgradeWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->upgradeLabel->setText(tr("An upgrade to Lubuntu %1 is available! Would you like to install this upgrade now?").arg(releaseCode)); ui->upgradeLabel->setText(tr("An upgrade to Lubuntu %1 is available! Would you like to install this upgrade now?").arg(releaseCode));
code=releaseCode;
connect(ui->upgradeButton, &QPushButton::clicked, this, &ReleaseUpgradeWindow::onUpgradeClicked); connect(ui->upgradeButton, &QPushButton::clicked, this, &ReleaseUpgradeWindow::onUpgradeClicked);
connect(ui->remindButton, &QPushButton::clicked, this, &ReleaseUpgradeWindow::onRemindClicked); connect(ui->remindButton, &QPushButton::clicked, this, &ReleaseUpgradeWindow::onRemindClicked);
connect(ui->declineButton, &QPushButton::clicked, this, &ReleaseUpgradeWindow::onDeclineClicked); connect(ui->declineButton, &QPushButton::clicked, this, &ReleaseUpgradeWindow::onDeclineClicked);
@ -17,17 +23,45 @@ ReleaseUpgradeWindow::~ReleaseUpgradeWindow()
delete ui; delete ui;
} }
void ReleaseUpgradeWindow::onUpgradeClicked() bool ReleaseUpgradeWindow::getUpgradeAccepted()
{ {
return upgradeAccepted;
}
qint64 ReleaseUpgradeWindow::getUpgradeDelayStamp()
{
return upgradeDelayStamp;
} }
void ReleaseUpgradeWindow::onRemindClicked() void ReleaseUpgradeWindow::onUpgradeClicked()
{ {
upgradeAccepted = true;
this->done(0);
}
void ReleaseUpgradeWindow::onRemindClicked()
{
UpgradeDelayWindow delayWindow;
delayWindow.exec();
if (delayWindow.getDelayDays() > 0) {
QDateTime delayDateTime = QDateTime::currentDateTime();
delayDateTime = delayDateTime.addDays(delayWindow.getDelayDays());
upgradeAccepted = false;
upgradeDelayStamp = delayDateTime.toSecsSinceEpoch();
this->done(0);
}
} }
void ReleaseUpgradeWindow::onDeclineClicked() void ReleaseUpgradeWindow::onDeclineClicked()
{ {
QMessageBox confirmDialog;
confirmDialog.setWindowTitle(tr("Lubuntu Update"));
confirmDialog.setText(tr("You have declined the upgrade to Lubuntu %1.\nYou can upgrade manually by following the directions at https://manual.lubuntu.me/stable/D/upgrading.html.").arg(code));
confirmDialog.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
int result = confirmDialog.exec();
if (result == QMessageBox::Ok) {
upgradeDelayStamp = 0;
upgradeAccepted = false;
this->done(0);
}
} }

@ -14,6 +14,8 @@ class ReleaseUpgradeWindow : public QDialog
public: public:
explicit ReleaseUpgradeWindow(QString releaseCode, QWidget *parent = nullptr); explicit ReleaseUpgradeWindow(QString releaseCode, QWidget *parent = nullptr);
~ReleaseUpgradeWindow(); ~ReleaseUpgradeWindow();
bool getUpgradeAccepted();
qint64 getUpgradeDelayStamp();
private slots: private slots:
void onUpgradeClicked(); void onUpgradeClicked();
@ -22,6 +24,9 @@ private slots:
private: private:
Ui::ReleaseUpgradeWindow *ui; Ui::ReleaseUpgradeWindow *ui;
QString code;
bool upgradeAccepted = false;
qint64 upgradeDelayStamp = 0;
}; };
#endif // RELEASEUPGRADEWINDOW_H #endif // RELEASEUPGRADEWINDOW_H

@ -0,0 +1,42 @@
#include "upgradedelaywindow.h"
#include "ui_upgradedelaywindow.h"
UpgradeDelayWindow::UpgradeDelayWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::UpgradeDelayWindow)
{
ui->setupUi(this);
connect(ui->okButton, &QPushButton::clicked, this, &UpgradeDelayWindow::onOkClicked);
connect(ui->cancelButton, &QPushButton::clicked, this, &UpgradeDelayWindow::onCancelClicked);
}
UpgradeDelayWindow::~UpgradeDelayWindow()
{
delete ui;
}
qint64 UpgradeDelayWindow::getDelayDays()
{
return delayDays;
}
void UpgradeDelayWindow::onOkClicked()
{
switch (ui->timeTypeComboBox->currentIndex()) {
case 0: // days
delayDays = ui->timeSpinBox->value();
break;
case 1: // weeks
delayDays = ui->timeSpinBox->value() * 7;
break;
case 2: // months
delayDays = ui->timeSpinBox->value() * 28;
break;
}
this->done(0);
}
void UpgradeDelayWindow::onCancelClicked()
{
this->done(0);
}

@ -0,0 +1,28 @@
#ifndef UPGRADEDELAYWINDOW_H
#define UPGRADEDELAYWINDOW_H
#include <QDialog>
namespace Ui {
class UpgradeDelayWindow;
}
class UpgradeDelayWindow : public QDialog
{
Q_OBJECT
public:
explicit UpgradeDelayWindow(QWidget *parent = nullptr);
~UpgradeDelayWindow();
qint64 getDelayDays();
private slots:
void onOkClicked();
void onCancelClicked();
private:
Ui::UpgradeDelayWindow *ui;
qint64 delayDays;
};
#endif // UPGRADEDELAYWINDOW_H

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UpgradeDelayWindow</class>
<widget class="QDialog" name="UpgradeDelayWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>457</width>
<height>106</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>How long would you like to wait before being reminded of the upgrade again?</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QSpinBox" name="timeSpinBox"/>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="okButton">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="timeTypeComboBox">
<item>
<property name="text">
<string>Days</string>
</property>
</item>
<item>
<property name="text">
<string>Weeks</string>
</property>
</item>
<item>
<property name="text">
<string>Months</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Loading…
Cancel
Save