forked from MX-Linux/formatusb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathabout.cpp
More file actions
62 lines (54 loc) · 2.33 KB
/
about.cpp
File metadata and controls
62 lines (54 loc) · 2.33 KB
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
#include "about.h"
#include "cmd.h"
#include "version.h"
#include <QApplication>
#include <QFileInfo>
#include <QMessageBox>
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>
// display doc as nomal user when run as root
void displayDoc(QString url, QString title, bool runned_as_root)
{
if (system("command -v mx-viewer >/dev/null") == 0) {
system("mx-viewer " + url.toUtf8() + " \"" + title.toUtf8() + "\"&");
} else {
if (!runned_as_root) {
system("xdg-open " + url.toUtf8());
} else {
Cmd cmd;
QString user = cmd.getCmdOut("logname", true);
system("su " + user.toUtf8() + " -c \"env XDG_RUNTIME_DIR=/run/user/$(id -u " +
user.toUtf8() + ") xdg-open " + url.toUtf8() + "\"&");
}
}
}
void displayAboutMsgBox(QString title, QString message, QString licence_url, QString license_title, bool runned_as_root)
{
QMessageBox msgBox(QMessageBox::NoIcon, title, message);
QPushButton *btnLicense = msgBox.addButton(QApplication::tr("License"), QMessageBox::HelpRole);
QPushButton *btnChangelog = msgBox.addButton(QApplication::tr("Changelog"), QMessageBox::HelpRole);
QPushButton *btnCancel = msgBox.addButton(QApplication::tr("Cancel"), QMessageBox::NoRole);
btnCancel->setIcon(QIcon::fromTheme("window-close"));
msgBox.exec();
if (msgBox.clickedButton() == btnLicense) {
displayDoc(licence_url, license_title, runned_as_root);
} else if (msgBox.clickedButton() == btnChangelog) {
QDialog *changelog = new QDialog();
changelog->setWindowTitle(QApplication::tr("Changelog"));
changelog->resize(600, 500);
QTextEdit *text = new QTextEdit;
text->setReadOnly(true);
Cmd cmd;
text->setText(cmd.getCmdOut("zless /usr/share/doc/" + QFileInfo(QCoreApplication::applicationFilePath()).fileName() + "/changelog.gz"));
QPushButton *btnClose = new QPushButton(QApplication::tr("&Close"));
btnClose->setIcon(QIcon::fromTheme("window-close"));
QApplication::connect(btnClose, &QPushButton::clicked, changelog, &QDialog::close);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(text);
layout->addWidget(btnClose);
changelog->setLayout(layout);
changelog->exec();
delete changelog;
}
}