Skip to content

Commit

Permalink
Minor edit
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianTM committed Jul 19, 2024
1 parent a4756d7 commit cd25071
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@
#include "common.h"
#include <unistd.h>

// Display doc as nomal user when run as root
// Display document as normal user when run as root
void displayDoc(const QString &url, const QString &title)
{
bool started_as_root = false;
if (qEnvironmentVariable("HOME") == "root") {
started_as_root = true;
qputenv("HOME", starting_home.toUtf8()); // Use original home for theming purposes
bool isRunningAsRoot = (qEnvironmentVariable("HOME") == "root");
QString originalHome = isRunningAsRoot ? starting_home : QString();

if (isRunningAsRoot) {
qputenv("HOME", originalHome.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("mx-viewer", {url, title});

// Prefer mx-viewer, otherwise use xdg-open (use runuser to run that as logname user)
QString viewerExecutable = QStandardPaths::findExecutable("mx-viewer");
if (!viewerExecutable.isEmpty()) {
QProcess::startDetached(viewerExecutable, {url, title});
} else {
if (getuid() != 0) {
QProcess::startDetached("xdg-open", {url});
Expand All @@ -56,17 +58,19 @@ void displayDoc(const QString &url, const QString &title)
QProcess::startDetached("runuser", {"-u", user, "--", "xdg-open", url});
}
}
if (started_as_root) {

if (isRunningAsRoot) {
qputenv("HOME", "/root");
}
}

void displayAboutMsgBox(const QString &title, const QString &message, const QString &licence_url,
const QString &license_title)
void displayAboutMsgBox(const QString &title, const QString &message, const QString &licenceUrl,
const QString &licenseTitle)
{
const auto width = 600;
const auto height = 500;
const int dialogWidth = 600;
const int dialogHeight = 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);
Expand All @@ -75,30 +79,31 @@ void displayAboutMsgBox(const QString &title, const QString &message, const QStr
msgBox.exec();

if (msgBox.clickedButton() == btnLicense) {
displayDoc(licence_url, license_title);
displayDoc(licenceUrl, licenseTitle);
} else if (msgBox.clickedButton() == btnChangelog) {
auto *changelog = new QDialog;
changelog->setWindowTitle(QObject::tr("Changelog"));
changelog->resize(width, height);
auto *changelogDialog = new QDialog;
changelogDialog->setWindowTitle(QObject::tr("Changelog"));
changelogDialog->resize(dialogWidth, dialogHeight);

auto *textEdit = new QTextEdit(changelogDialog);
textEdit->setReadOnly(true);

auto *text = new QTextEdit(changelog);
text->setReadOnly(true);
QProcess proc;
proc.start(
QProcess changelogProc;
changelogProc.start(
"zless",
{"/usr/share/doc/" + QFileInfo(QCoreApplication::applicationFilePath()).fileName() + "/changelog.gz"},
QIODevice::ReadOnly);
proc.waitForFinished();
text->setText(proc.readAllStandardOutput());
changelogProc.waitForFinished();
textEdit->setText(changelogProc.readAllStandardOutput());

auto *btnClose = new QPushButton(QObject::tr("&Close"), changelog);
auto *btnClose = new QPushButton(QObject::tr("&Close"), changelogDialog);
btnClose->setIcon(QIcon::fromTheme("window-close"));
QObject::connect(btnClose, &QPushButton::clicked, changelog, &QDialog::close);
QObject::connect(btnClose, &QPushButton::clicked, changelogDialog, &QDialog::close);

auto *layout = new QVBoxLayout(changelog);
layout->addWidget(text);
auto *layout = new QVBoxLayout(changelogDialog);
layout->addWidget(textEdit);
layout->addWidget(btnClose);
changelog->setLayout(layout);
changelog->exec();
changelogDialog->setLayout(layout);
changelogDialog->exec();
}
}

0 comments on commit cd25071

Please sign in to comment.