2020-11-11 02:16:16 +08:00
|
|
|
#include "informationbox.h"
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QDebug>
|
|
|
|
|
2020-11-19 05:47:38 +08:00
|
|
|
void InformationBox::ShowMessage(QString title, QString message, QString messageID)
|
2020-11-11 02:16:16 +08:00
|
|
|
{
|
|
|
|
// check if the user still wants to see this message
|
2020-11-19 05:47:38 +08:00
|
|
|
unsigned int hash;
|
|
|
|
if(messageID.isEmpty()) {
|
|
|
|
hash = qHash(message);
|
|
|
|
} else {
|
|
|
|
hash = qHash(messageID);
|
|
|
|
}
|
2020-11-11 02:16:16 +08:00
|
|
|
|
|
|
|
QSettings s;
|
|
|
|
if(!s.contains(hashToSettingsKey(hash))) {
|
2020-11-19 05:47:38 +08:00
|
|
|
auto box = new InformationBox(title, message, hash, nullptr);
|
2020-11-11 02:16:16 +08:00
|
|
|
box->exec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InformationBox::InformationBox(QString title, QString message, unsigned int hash, QWidget *parent)
|
|
|
|
: QMessageBox(parent),
|
|
|
|
hash(hash)
|
|
|
|
{
|
|
|
|
setWindowTitle(title);
|
|
|
|
setText(message);
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
setIcon(QMessageBox::Information);
|
|
|
|
|
|
|
|
auto cb = new QCheckBox("Do not show this message again");
|
|
|
|
setCheckBox(cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
InformationBox::~InformationBox()
|
|
|
|
{
|
|
|
|
auto cb = checkBox();
|
|
|
|
if(cb->isChecked()) {
|
|
|
|
QSettings s;
|
|
|
|
s.setValue(hashToSettingsKey(hash), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString InformationBox::hashToSettingsKey(unsigned int hash)
|
|
|
|
{
|
|
|
|
return QString("DoNotShowDialog/") + QString::number(hash);
|
|
|
|
}
|