setup.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "setup.h"
  2. #include "ui_setup.h"
  3. #include <QJsonObject>
  4. #include <QJsonDocument>
  5. #include <QCryptographicHash>
  6. #include <QFile>
  7. #include <QDir>
  8. QJsonObject setupConfig;
  9. void saveSettings(QString pwd, QString cmd) {
  10. QString md5 = QCryptographicHash::hash(pwd.toLatin1(), QCryptographicHash::Md5).toHex();
  11. setupConfig["pwdHash"] = QJsonValue(md5);
  12. setupConfig["command"] = QJsonValue(cmd);
  13. QDir dir;
  14. QString homePath = getenv("HOME");
  15. dir.mkpath(homePath + "/.config/fake-gnome-keyring");
  16. QString configPath = homePath + "/.config/fake-gnome-keyring/config.json";
  17. QJsonDocument doc(setupConfig);
  18. QFile jsonFile(configPath);
  19. jsonFile.open(QFile::WriteOnly);
  20. jsonFile.write(doc.toJson(QJsonDocument::Indented));
  21. jsonFile.close();
  22. }
  23. Setup::Setup(QWidget *parent) : QWidget(parent), ui(new Ui::Setup) {
  24. ui->setupUi(this);
  25. this->connect(ui->cancelPushButton, &QPushButton::clicked, this,
  26. []() {
  27. exit(0);
  28. });
  29. this->connect(ui->okPushButton, &QPushButton::clicked, this,
  30. [this]() {
  31. saveSettings(ui->pwdLineEdit->text(), ui->cmdLineEdit->text());
  32. exit(0);
  33. });
  34. }
  35. Setup::~Setup() {
  36. delete ui;
  37. }