1/*
2 * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#include "projectversioninfowidget.h"
18#include "ui_projectversioninfowidget.h"
19#include <windows.h>
20#include "../mainwindow.h"
21#include "../project.h"
22
23static QStringList languageNames;
24static QList<int> languageIDs;
25
26static BOOL CALLBACK localeEnumProc(
27 _In_ LPTSTR lpLocaleString
28 ) {
29
30 QString s = QString::fromWCharArray(lpLocaleString);
31 bool ok;
32 int aid = s.mid(4,4).toInt(&ok,16);
33 if (ok) {
34 TCHAR buffer [1024];
35 GetLocaleInfo(aid, LOCALE_SLANGUAGE,buffer,sizeof(buffer)/2);
36 languageNames.append(QString::fromWCharArray(buffer));
37 languageIDs.append(aid);
38 }
39 return TRUE;
40}
41
42ProjectVersionInfoWidget::ProjectVersionInfoWidget(const QString &name, const QString &group, QWidget *parent) :
43 SettingsWidget(name,group,parent),
44 ui(new Ui::ProjectVersionInfoWidget)
45{
46 ui->setupUi(this);
47 if (languageNames.isEmpty()) {
48 EnumSystemLocales(localeEnumProc, LCID_SUPPORTED);
49 }
50 ui->cbLanguage->addItems(languageNames);
51}
52
53ProjectVersionInfoWidget::~ProjectVersionInfoWidget()
54{
55 delete ui;
56}
57
58void ProjectVersionInfoWidget::doLoad()
59{
60 std::shared_ptr<Project> project = pMainWindow->project();
61 ui->grpVersionInfo->setChecked(project->options().includeVersionInfo);
62 ui->spinMajor->setValue(project->options().versionInfo.major);
63 ui->spinMinor->setValue(project->options().versionInfo.minor);
64 ui->spinRelease->setValue(project->options().versionInfo.release);
65 ui->spinBuild->setValue(project->options().versionInfo.build);
66 ui->chkAutoIncreaseBuildNumber->setChecked(project->options().versionInfo.autoIncBuildNr);
67 ui->chkSyncProductWithFile->setChecked(project->options().versionInfo.syncProduct);
68 for (int i=0;i<languageIDs.count();i++) {
69 if (languageIDs[i] == project->options().versionInfo.languageID) {
70 ui->cbLanguage->setCurrentIndex(i);
71 break;
72 }
73 }
74 ui->txtFileDescription->setText(project->options().versionInfo.fileDescription);
75 ui->txtFileVersion->setText(project->options().versionInfo.fileVersion);
76 ui->txtProductName->setText(project->options().versionInfo.productName);
77 ui->txtProductVersion->setText(project->options().versionInfo.productVersion);
78 ui->txtOriginalFilename->setText(project->options().versionInfo.originalFilename);
79 ui->txtInternalFilename->setText(project->options().versionInfo.internalName);
80 ui->txtCompanyName->setText(project->options().versionInfo.companyName);
81 ui->txtLegalCopyright->setText(project->options().versionInfo.legalCopyright);
82 ui->txtLegalTrademarks->setText(project->options().versionInfo.legalTrademarks);
83}
84
85void ProjectVersionInfoWidget::doSave()
86{
87 std::shared_ptr<Project> project = pMainWindow->project();
88 project->options().includeVersionInfo = ui->grpVersionInfo->isChecked();
89 project->options().versionInfo.major = ui->spinMajor->value();
90 project->options().versionInfo.minor = ui->spinMinor->value();
91 project->options().versionInfo.release = ui->spinRelease->value();
92 project->options().versionInfo.build = ui->spinBuild->value();
93 project->options().versionInfo.autoIncBuildNr = ui->chkAutoIncreaseBuildNumber->isChecked();
94 project->options().versionInfo.syncProduct = ui->chkSyncProductWithFile->isChecked();
95 if (ui->cbLanguage->currentIndex()>=0)
96 project->options().versionInfo.languageID = languageIDs[ui->cbLanguage->currentIndex()];
97
98 project->options().versionInfo.fileDescription = ui->txtFileDescription->text();
99 project->options().versionInfo.fileVersion = ui->txtFileVersion->text();
100 project->options().versionInfo.productName = ui->txtProductName->text();
101 project->options().versionInfo.productVersion = ui->txtProductVersion->text();
102 project->options().versionInfo.originalFilename = ui->txtOriginalFilename->text();
103 project->options().versionInfo.internalName = ui->txtInternalFilename->text();
104 project->options().versionInfo.companyName = ui->txtCompanyName->text();
105 project->options().versionInfo.legalCopyright = ui->txtLegalCopyright->text();
106 project->options().versionInfo.legalTrademarks = ui->txtLegalTrademarks->text();
107 project->saveOptions();
108}
109