-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettingsdialog.cpp
More file actions
240 lines (194 loc) · 7.16 KB
/
settingsdialog.cpp
File metadata and controls
240 lines (194 loc) · 7.16 KB
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
/*
Copyright (C) 2009–2014 jakago
Copyright (C) 2018–2026 CSReviser Team
This file is part of CaptureStream2, a recorder that supports HLS for
NHK radio language courses.
CaptureStream2 is a modified version of CaptureStream, originally
developed by jakago.
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <https://www.gnu.org/licenses/gpl-2.0.html>.
*/
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
#include "settings.h"
#include "utility.h"
#include "programrepository.h"
#include "programresolver.h"
#include <QMessageBox>
Settingsdialog::Settingsdialog(Settings& ini, QWidget *parent)
: QDialog(parent), ui(new Ui::Settingsdialog), settings(ini)
{
ui->setupUi(this);
applyOptionPresetLabels();
edits = { ui->edit1, ui->edit2, ui->edit3, ui->edit4 };
// ===== 特番(SpecPrograms)を Settings から復元 =====
for (int i = 0; i < Constants::getSpecCount(); i++) {
const auto &p = Constants::SpecPrograms[i];
edits[i]->setText(settings.ids[p.keyId]);
}
ui->radioButton_9->setChecked(true);
// ===== チェックボックスフラグ =====
ui->checkBox_multi_gui->setChecked(settings.checked[QString::fromUtf8(Constants::KEY_MULTI_GUI)]);
ui->checkBox_koza_separation->setChecked(settings.checked[QString::fromUtf8(Constants::KEY_KOZA_SEPARATION)]);
#ifdef Q_OS_MACOS
ui->checkBox_mac_menubar->setChecked(settings.checked[QString::fromUtf8(Constants::KEY_MAC_MENUBAR)]);
#endif
#if !defined( Q_OS_MACOS )
ui->checkBox_mac_menubar->hide();
#endif
}
Settingsdialog::~Settingsdialog()
{
delete ui;
}
void Settingsdialog::applyFlags()
{
settings.checked[QString::fromUtf8(Constants::KEY_KOZA_SEPARATION)] = ui->checkBox_koza_separation->isChecked();
settings.checked[QString::fromUtf8(Constants::KEY_MULTI_GUI)] = ui->checkBox_multi_gui->isChecked();
#ifdef Q_OS_MACOS
settings.checked[QString::fromUtf8(Constants::KEY_MAC_MENUBAR)] = ui->checkBox_mac_menubar->isChecked();
#endif
}
QString Settingsdialog::scramble_set(QString opt, int index)
{
using namespace Constants;
const auto& PRESETS = Constants::getPresets();
std::array<QAbstractButton*, 7> radios = {
ui->radioButton, ui->radioButton_1, ui->radioButton_2,
ui->radioButton_3, ui->radioButton_4, ui->radioButton_5,
ui->radioButton_6
};
// プリセット適用
for (int j = 0; j < PRESETS.size() && j < radios.size(); ++j) {
if (radios[j]->isChecked()) {
opt = PRESETS[j][index];
}
}
// ユーザープリセット
if (ui->radioButton_6->isChecked()) {
auto opt1 = settings.specials;
if (!opt1[index].isEmpty())
opt = opt1[index];
}
QLineEdit* edit = edits[index];
if (!ui->radioButton_9->isChecked()) {
edit->setText(opt);
} else {
// name_map → id_map
auto &repo = ProgramRepository::instance();
if (repo.name_map.contains(edit->text()))
opt = repo.name_map[edit->text()];
if (repo.getProgramNameById(edit->text()).isEmpty())
edit->setText(opt);
}
return opt;
}
void Settingsdialog::accept()
{
for (int i = 0; i < Constants::getSpecCount(); i++){
QString opt = edits[i]->text();
QString resolved = ProgramResolver::resolveUnique(opt);
if (!resolved.isEmpty())
updateSpecial(i, edits[i]->text());
}
applyFlags();
QDialog::accept();
}
void Settingsdialog::updateLabels()
{
QVector<QLabel*> labels =
{ ui->label_2, ui->label_3, ui->label_4, ui->label_5 };
auto &repo = ProgramRepository::instance();
for (int i = 0; i < Constants::getSpecCount(); ++i) {
QString label_tmp = repo.getProgramNameById(edits[i]->text());
label_tmp = repo.normalizeProgramName(label_tmp);
labels[i]->setText(label_tmp);
// labels[i]->setText(repo.getProgramNameById(edits[i]->text()));
}
}
void Settingsdialog::pushbutton()
{
for (int i = 0; i < Constants::getSpecCount(); ++i) {
QString opt = edits[i]->text();
QString resolved = ProgramResolver::resolveUnique(opt);
if (!resolved.isEmpty())
opt = resolved;
opt = scramble_set(opt, i);
edits[i]->setText(opt);
}
ui->radioButton_9->setChecked(true);
updateLabels();
}
void Settingsdialog::pushbutton_2()
{
QStringList labels;
auto &repo = ProgramRepository::instance();
for (int i = 0; i < Constants::getSpecCount(); ++i){
QString label_tmp;
if (!repo.id_map.contains(edits[i]->text())){
label_tmp = repo.getProgramNameById(edits[i]->text());
}else{
label_tmp = repo.id_map.value(edits[i]->text());
}
labels << repo.normalizeProgramName(label_tmp);
}
QString msg =
QStringLiteral("下記内容で上書きします。保存しますか?\n") +
"1:" + labels[0] + "\n" +
"2:" + labels[1] + "\n" +
"3:" + labels[2] + "\n" +
"4:" + labels[3];
if (QMessageBox::question(this, tr("特別番組設定保存"), msg) == QMessageBox::Yes) {
for (int i = 0; i < Constants::getSpecCount(); ++i)
settings.specials[i] = edits[i]->text();
}
}
QString Settingsdialog::updateSpecial(int index, const QString ¤tText)
{
using namespace Constants;
// scramble_set により最終的な ID を決定
QString newValue = scramble_set(currentText, index);
// 対応する keyId を取得
const auto &p = SpecPrograms[index];
QString oldValue = settings.ids[p.keyId];
// 変更なし → 何もせず返す
if (oldValue == newValue)
return newValue;
// ID 更新
settings.ids[p.keyId] = newValue;
// checked を false にする
settings.checked[p.keyChecked] = false;
// タイトル更新(id_map → 番組名)
auto &repo = ProgramRepository::instance();
QString label_tmp;
if (!repo.id_map.contains(newValue)){
label_tmp = repo.getProgramNameById(newValue);
}else{
label_tmp = repo.id_map.value(newValue);
}
label_tmp = repo.normalizeProgramName(label_tmp);
settings.labels[p.keyLabel] = label_tmp;
settings.save(); // INI に書き込み
return newValue;
}
void Settingsdialog::applyOptionPresetLabels()
{
for (int i = 0; i < Constants::getSpecLabelCount(); ++i) {
const auto& item = Constants::SPEC_LABEL[i];
QObject* obj = this->findChild<QObject*>(item.objectName);
if (!obj)
continue;
QRadioButton* rb = qobject_cast<QRadioButton*>(obj);
if (!rb)
continue;
rb->setText(QString::fromUtf8(item.label));
}
}