aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/help/AboutDialog.cpp
blob: 111a77afa2a82e8617a26a4d4537c287b918d04f (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/**
 * Copyright (C) 2021 Saturneric
 *
 * This file is part of GpgFrontend.
 *
 * GpgFrontend is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GpgFrontend is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
 *
 * The initial version of the source code is inherited from
 * the gpg4usb project, which is under GPL-3.0-or-later.
 *
 * All the source code of GpgFrontend was modified and released by
 * Saturneric<[email protected]> starting on May 12, 2021.
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 */

#include "AboutDialog.h"

#include <openssl/opensslv.h>

#include "GpgFrontendBuildInfo.h"
#include "core/function/GlobalSettingStation.h"
#include "core/thread/TaskRunnerGetter.h"
#include "ui/dialog/help/GnupgTab.h"
#include "ui/thread/VersionCheckTask.h"

namespace GpgFrontend::UI {

AboutDialog::AboutDialog(int defaultIndex, QWidget* parent)
    : GeneralDialog(typeid(AboutDialog).name(), parent) {
  this->setWindowTitle(QString(_("About")) + " " + qApp->applicationName());

  auto* tab_widget = new QTabWidget;
  auto* info_tab = new InfoTab();
  auto* gnupg_tab = new GnupgTab();
  auto* translators_tab = new TranslatorsTab();
  update_tab_ = new UpdateTab();

  tab_widget->addTab(info_tab, _("About GpgFrontend"));
  tab_widget->addTab(gnupg_tab, _("GnuPG"));
  tab_widget->addTab(translators_tab, _("Translators"));
  tab_widget->addTab(update_tab_, _("Update"));

  connect(tab_widget, &QTabWidget::currentChanged, this,
          [&](int index) { SPDLOG_DEBUG("current index: {}", index); });

  if (defaultIndex < tab_widget->count() && defaultIndex >= 0) {
    tab_widget->setCurrentIndex(defaultIndex);
  }

  auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
  connect(buttonBox, &QDialogButtonBox::accepted, this, &AboutDialog::close);

  auto* mainLayout = new QVBoxLayout;
  mainLayout->addWidget(tab_widget);
  mainLayout->addWidget(buttonBox);
  setLayout(mainLayout);

  this->resize(550, 650);
  this->setMinimumWidth(450);
  this->show();
}

void AboutDialog::showEvent(QShowEvent* ev) {
  QDialog::showEvent(ev);
  update_tab_->getLatestVersion();
}

InfoTab::InfoTab(QWidget* parent) : QWidget(parent) {
  auto* pixmap = new QPixmap(":gpgfrontend-logo.png");
  auto* text = new QString(
      "<center><h2>" + qApp->applicationName() + "</h2></center>" +
      "<center><b>" + qApp->applicationVersion() + "</b></center>" +
      "<center>" + GIT_VERSION + "</center>" + "<br><center>" +
      _("GpgFrontend is an easy-to-use, compact, cross-platform, "
        "and installation-free GnuPG Frontend."
        "It visualizes most of the common operations of GnuPG."
        "GpgFrontend is licensed under the GPLv3") +
      "<br><br>"
      "<b>" +
      _("Developer:") + "</b><br>" + "Saturneric" + "<br><br>" +
      _("If you have any questions or suggestions, raise an issue at") +
      "<br/>"
      " <a href=\"https://github.com/saturneric/GpgFrontend\">GitHub</a> " +
      _("or send a mail to my mailing list at") + " <a " +
      "href=\"mailto:[email protected]\">[email protected]</a>." + "<br><br> " +
      _("Built with Qt") + " " + qVersion() + ", " + OPENSSL_VERSION_TEXT +
      " " + _("and") + " " + "GPGME" + " " +
      GpgFrontend::GpgContext::GetInstance()
          .GetInfo(false)
          .GpgMEVersion.c_str() +
      "<br>" + _("Built at") + " " + BUILD_TIMESTAMP + "</center>");

  auto* layout = new QGridLayout();
  auto* pixmapLabel = new QLabel();
  pixmapLabel->setPixmap(*pixmap);
  layout->addWidget(pixmapLabel, 0, 0, 1, -1, Qt::AlignCenter);
  auto* aboutLabel = new QLabel();
  aboutLabel->setText(*text);
  aboutLabel->setWordWrap(true);
  aboutLabel->setOpenExternalLinks(true);
  layout->addWidget(aboutLabel, 1, 0, 1, -1);
  layout->addItem(
      new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Fixed), 2, 1,
      1, 1);

  setLayout(layout);
}

TranslatorsTab::TranslatorsTab(QWidget* parent) : QWidget(parent) {
  QFile translators_qfile;
  auto translators_file =
      GlobalSettingStation::GetInstance().GetResourceDir() / "TRANSLATORS";
  translators_qfile.setFileName(translators_file.u8string().c_str());
#ifdef LINUX
  if (!translators_qfile.exists()) {
    translators_qfile.setFileName("/usr/local/share/GpgFrontend/TRANSLATORS");
  }
#endif

  translators_qfile.open(QIODevice::ReadOnly);
  QByteArray in_buffer = translators_qfile.readAll();

  auto* label = new QLabel(in_buffer);

  auto* main_layout = new QVBoxLayout(this);
  main_layout->addWidget(label);
  main_layout->addStretch();

  auto notice_label = new QLabel(
      _("If you think there are any problems with the translation, why not "
        "participate in the translation work? If you want to participate, "
        "please "
        "read the document or contact me via email."),
      this);
  notice_label->setWordWrap(true);
  main_layout->addWidget(notice_label);

  setLayout(main_layout);
}

UpdateTab::UpdateTab(QWidget* parent) : QWidget(parent) {
  auto* pixmap = new QPixmap(":gpgfrontend-logo.png");
  auto* layout = new QGridLayout();
  auto* pixmap_label = new QLabel();
  pixmap_label->setPixmap(*pixmap);
  layout->addWidget(pixmap_label, 0, 0, 1, -1, Qt::AlignCenter);

  current_version_ = "v" + QString::number(VERSION_MAJOR) + "." +
                     QString::number(VERSION_MINOR) + "." +
                     QString::number(VERSION_PATCH);

  auto tips_label = new QLabel();
  tips_label->setText(
      "<center>" +
      QString(_("It is recommended that you always check the version "
                "of GpgFrontend and upgrade to the latest version.")) +
      "</center><center>" +
      _("New versions not only represent new features, but "
        "also often represent functional and security fixes.") +
      "</center>");
  tips_label->setWordWrap(true);

  current_version_label_ = new QLabel();
  current_version_label_->setText("<center>" + QString(_("Current Version")) +
                                  _(": ") + "<b>" + current_version_ +
                                  "</b></center>");
  current_version_label_->setWordWrap(true);

  latest_version_label_ = new QLabel();
  latest_version_label_->setWordWrap(true);

  upgrade_label_ = new QLabel();
  upgrade_label_->setWordWrap(true);
  upgrade_label_->setOpenExternalLinks(true);
  upgrade_label_->setHidden(true);

  pb_ = new QProgressBar();
  pb_->setRange(0, 0);
  pb_->setTextVisible(false);

  layout->addWidget(tips_label, 1, 0, 1, -1);
  layout->addWidget(current_version_label_, 2, 0, 1, -1);
  layout->addWidget(latest_version_label_, 3, 0, 1, -1);
  layout->addWidget(upgrade_label_, 4, 0, 1, -1);
  layout->addWidget(pb_, 5, 0, 1, -1);
  layout->addItem(
      new QSpacerItem(20, 10, QSizePolicy::Minimum, QSizePolicy::Fixed), 2, 1,
      1, 1);

  setLayout(layout);
}

void UpdateTab::getLatestVersion() {
  this->pb_->setHidden(false);

  SPDLOG_DEBUG("try to get latest version");

  auto* version_task = new VersionCheckTask();

  connect(version_task, &VersionCheckTask::SignalUpgradeVersion, this,
          &UpdateTab::slot_show_version_status);

  Thread::TaskRunnerGetter::GetInstance()
      .GetTaskRunner(Thread::TaskRunnerGetter::kTaskRunnerType_Network)
      ->PostTask(version_task);
}

void UpdateTab::slot_show_version_status(const SoftwareVersion& version) {
  this->pb_->setHidden(true);
  latest_version_label_->setText(
      "<center><b>" + QString(_("Latest Version From Github")) + ": " +
      version.latest_version.c_str() + "</b></center>");

  if (version.NeedUpgrade()) {
    upgrade_label_->setText(
        "<center>" +
        QString(_("The current version is less than the latest version on "
                  "github.")) +
        "</center><center>" + _("Please click") +
        " <a "
        "href=\"https://www.gpgfrontend.bktus.com/#/downloads\">" +
        _("Here") + "</a> " + _("to download the latest stable version.") +
        "</center>");
    upgrade_label_->show();
  } else if (version.VersionWithDrawn()) {
    upgrade_label_->setText(
        "<center>" +
        QString(_("This version has serious problems and has been withdrawn. "
                  "Please stop using it immediately.")) +
        "</center><center>" + _("Please click") +
        " <a "
        "href=\"https://github.com/saturneric/GpgFrontend/releases\">" +
        _("Here") + "</a> " + _("to download the latest stable version.") +
        "</center>");
    upgrade_label_->show();
  } else if (!version.CurrentVersionReleased()) {
    upgrade_label_->setText(
        "<center>" +
        QString(_("This version has not been released yet, it may be a beta "
                  "version. If you are not a tester and care about version "
                  "stability, please do not use this version.")) +
        "</center><center>" + _("Please click") +
        " <a "
        "href=\"https://www.gpgfrontend.bktus.com/#/downloads\">" +
        _("Here") + "</a> " + _("to download the latest stable version.") +
        "</center>");
    upgrade_label_->show();
  }
}

}  // namespace GpgFrontend::UI