-
Notifications
You must be signed in to change notification settings - Fork 7
/
about.cpp
84 lines (74 loc) · 3.14 KB
/
about.cpp
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
#include "about.h"
#include <QApplication>
#include <QFileInfo>
#include <QMessageBox>
#include <QProcess>
#include <QPushButton>
#include <QStandardPaths>
#include <QTextEdit>
#include <QVBoxLayout>
#include "common.h"
#include <unistd.h>
extern const QString starting_home;
// display doc as nomal user when run as root
void displayDoc(const QString &url, const QString &title)
{
bool started_as_root = false;
if (qEnvironmentVariable("HOME") == QLatin1String("root")) {
started_as_root = true;
qputenv("HOME", starting_home.toUtf8()); // use original home for theming purposes
}
// prefer mx-viewer otherwise use xdg-open (use runuser to run that as logname user)
QString executablePath = QStandardPaths::findExecutable("mx-viewer");
if (!executablePath.isEmpty()) {
QProcess::startDetached(QStringLiteral("mx-viewer"), {url, title});
} else {
if (getuid() != 0) {
QProcess::startDetached(QStringLiteral("xdg-open"), {url});
} else {
QProcess proc;
proc.start(QStringLiteral("logname"), {}, QIODevice::ReadOnly);
proc.waitForFinished();
QString user = QString::fromUtf8(proc.readAllStandardOutput()).trimmed();
QProcess::startDetached(QStringLiteral("runuser"), {QStringLiteral("-u"), user, QStringLiteral("--"),
QStringLiteral("xdg-open"), url});
}
}
if (started_as_root) {
qputenv("HOME", "/root");
}
}
void displayAboutMsgBox(const QString &title, const QString &message, const QString &licence_url,
const QString &license_title)
{
const auto width = 600;
const auto height = 500;
QMessageBox msgBox(QMessageBox::NoIcon, title, message);
auto *btnLicense = msgBox.addButton(QObject::tr("License"), QMessageBox::HelpRole);
auto *btnChangelog = msgBox.addButton(QObject::tr("Changelog"), QMessageBox::HelpRole);
auto *btnCancel = msgBox.addButton(QObject::tr("Cancel"), QMessageBox::NoRole);
btnCancel->setIcon(QIcon::fromTheme(QStringLiteral("window-close")));
msgBox.exec();
if (msgBox.clickedButton() == btnLicense) {
displayDoc(licence_url, license_title);
} else if (msgBox.clickedButton() == btnChangelog) {
auto *changelog = new QDialog;
changelog->setWindowTitle(QObject::tr("Changelog"));
changelog->resize(width, height);
auto *text = new QTextEdit(changelog);
text->setReadOnly(true);
QProcess proc;
proc.start("zless", {"/usr/share/doc/mx-bootrepair/changelog.gz"}, QIODevice::ReadOnly);
proc.waitForFinished();
text->setText(proc.readAllStandardOutput());
auto *btnClose = new QPushButton(QObject::tr("&Close"), changelog);
btnClose->setIcon(QIcon::fromTheme(QStringLiteral("window-close")));
QObject::connect(btnClose, &QPushButton::clicked, changelog, &QDialog::close);
auto *layout = new QVBoxLayout(changelog);
layout->addWidget(text);
layout->addWidget(btnClose);
changelog->setLayout(layout);
changelog->exec();
delete changelog;
}
}