-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathabout.cpp
67 lines (57 loc) · 2.42 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
#include "about.h"
#include "version.h"
#include <QApplication>
#include <QFileInfo>
#include <QMessageBox>
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>
#include <unistd.h>
// Display doc as nomal user when run as root
void displayDoc(const QString &url, const QString &title, bool runned_as_root)
{
if (system("command -v mx-viewer >/dev/null") == 0) {
system("mx-viewer " + url.toUtf8() + " \"" + title.toUtf8() + "\"&");
return;
}
if (system("command -v antix-viewer >/dev/null") == 0) {
system("antix-viewer " + url.toUtf8() + " \"" + title.toUtf8() + "\"&");
return;
}
if (getuid() != 0) {
QString cmd = "xdg-open " + url;
system(cmd.toUtf8());
} else {
system("su $(logname) -c \"env XDG_RUNTIME_DIR=/run/user/$(id -u $(logname)) xdg-open " + url.toUtf8() + "\"&");
}
}
void displayAboutMsgBox(const QString &title, const QString &message, const QString &licence_url,
const QString &license_title, bool runned_as_root)
{
QMessageBox msgBox(QMessageBox::NoIcon, title, message);
QPushButton *btnLicense = msgBox.addButton(QObject::tr("License"), QMessageBox::HelpRole);
QPushButton *btnChangelog = msgBox.addButton(QObject::tr("Changelog"), QMessageBox::HelpRole);
QPushButton *btnCancel = msgBox.addButton(QObject::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(QObject::tr("Changelog"));
changelog->resize(600, 500);
QTextEdit *text = new QTextEdit;
text->setReadOnly(true);
Cmd cmd;
text->setText(cmd.getOut("zless /usr/share/doc/" + QFileInfo(QCoreApplication::applicationFilePath()).fileName()
+ "/changelog.gz"));
QPushButton *btnClose = new QPushButton(QObject::tr("&Close"));
btnClose->setIcon(QIcon::fromTheme("window-close"));
QObject::connect(btnClose, &QPushButton::clicked, changelog, &QDialog::close);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(text);
layout->addWidget(btnClose);
changelog->setLayout(layout);
changelog->exec();
}
}