aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/help/AboutDialog.cpp
blob: ea678a0ef42226f7afae1a9dec59527329fb17f5 (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
/**
 * Copyright (C) 2021-2024 Saturneric <[email protected]>
 *
 * 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 "core/module/ModuleManager.h"
#include "core/utils/BuildInfoUtils.h"
#include "ui/UIModuleManager.h"

namespace GpgFrontend::UI {

AboutDialog::AboutDialog(const QString& default_tab_name, QWidget* parent)
    : GeneralDialog(typeid(AboutDialog).name(), parent) {
  this->setWindowTitle(tr("About") + " " + qApp->applicationName());

  auto* tab_widget = new QTabWidget;
  auto* info_tab = new InfoTab();
  auto* translators_tab = new TranslatorsTab();

  tab_widget->setDocumentMode(true);

  tab_widget->addTab(info_tab, tr("About GpgFrontend"));
  tab_widget->addTab(translators_tab, tr("Translators"));

  auto entries =
      UIModuleManager::GetInstance().QueryMountedEntries("AboutDialogTabs");

  for (const auto& entry : entries) {
    auto* widget = entry.GetWidget();
    if (widget != nullptr) {
      tab_widget->addTab(widget,
                         entry.GetMetaDataByDefault("TabTitle", tr("Unnamed")));
    }
  }

  int default_index = 0;
  for (int i = 0; i < tab_widget->count(); i++) {
    if (tab_widget->tabText(i) == default_tab_name) {
      default_index = i;
    }
  }

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

  auto* main_layout = new QVBoxLayout;
  main_layout->addWidget(tab_widget);
  main_layout->setContentsMargins(QMargins{5, 0, 5, 0});
  setLayout(main_layout);

  this->show();
  this->raise();
  this->activateWindow();
}

void AboutDialog::showEvent(QShowEvent* ev) { QDialog::showEvent(ev); }

InfoTab::InfoTab(QWidget* parent) : QWidget(parent) {
  const auto gpgme_version = Module::RetrieveRTValueTypedOrDefault<>(
      "core", "gpgme.version", QString{"2.0.0"});

  auto pixmap = QPixmap(":/icons/gpgfrontend_logo.png");
  pixmap =
      pixmap.scaled(128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation);

  QString app_info = "<h2 style='text-align:center;'>" +
                     qApp->applicationDisplayName() + "</h2>" + "<center><b>" +
                     GetProjectVersion() + "</b></center>" + "<center>" +
                     GetProjectBuildGitVersion() + "</center>";

  QString developer_info =
      "<b>" + tr("Developer:") + "</b> Saturneric" + "<br /><br />" +
      tr("If you have any questions or suggestions, raise an issue at") +
      " <a href=\"https://github.com/saturneric/GpgFrontend\">GitHub</a> " +
      tr("or send a mail to my mailing list at") +
      " <a href=\"mailto:[email protected]\">[email protected]</a>.";

  QString build_info = tr("Built with Qt") + " " + qVersion() + ", " +
                       OPENSSL_VERSION_TEXT + " " + tr("and") + " GPGME " +
                       gpgme_version + "<br>" + tr("Built at") + " " +
                       QLocale().toString(GetProjectBuildTimestamp());

  auto* layout = new QVBoxLayout();

  auto* pixmap_label = new QLabel();
  pixmap_label->setPixmap(pixmap);
  pixmap_label->setAlignment(Qt::AlignCenter);
  layout->addWidget(pixmap_label);

  auto* app_info_label = new QLabel(app_info);
  app_info_label->setWordWrap(true);
  app_info_label->setAlignment(Qt::AlignCenter);
  layout->addWidget(app_info_label);

  auto* dev_info_group = new QGroupBox(tr("Developer Information"));
  auto* dev_layout = new QVBoxLayout();
  auto* dev_info_label = new QLabel(developer_info);
  dev_info_label->setWordWrap(true);
  dev_info_label->setOpenExternalLinks(true);
  dev_layout->addWidget(dev_info_label);
  dev_info_group->setLayout(dev_layout);
  layout->addWidget(dev_info_group);

  auto* build_info_group = new QGroupBox(tr("Build Information"));
  auto* build_layout = new QVBoxLayout();
  auto* build_info_label = new QLabel(build_info);
  build_info_label->setWordWrap(true);
  build_layout->addWidget(build_info_label);
  build_info_group->setLayout(build_layout);
  layout->addWidget(build_info_group);

  setLayout(layout);
}

TranslatorsTab::TranslatorsTab(QWidget* parent) : QWidget(parent) {
  QFile translators_file(":/TRANSLATORS");

  translators_file.open(QIODevice::ReadOnly);
  auto* label = new QLabel(translators_file.readAll());
  auto* main_layout = new QVBoxLayout(this);
  main_layout->addWidget(label);
  main_layout->addStretch();

  auto* notice_label = new QLabel(
      tr("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);
}

}  // namespace GpgFrontend::UI