-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcustomizedialog.cpp
133 lines (116 loc) · 5.37 KB
/
customizedialog.cpp
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
/*
Copyright (C) 2009-2013 jakago
This file is part of CaptureStream, the flv downloader for NHK radio
language courses.
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 <http://www.gnu.org/licenses/>.
*/
#include "customizedialog.h"
#include "mainwindow.h"
#include "utility.h"
#include <QDir>
#include <QSettings>
#define SETTING_GROUP "CustomizeDialog"
#define DefaultTitle "%k_%Y_%M_%D"
#define DefaultFileName "%k_%Y_%M_%D"
typedef struct LineEdit {
QLineEdit* lineEdit;
QString titleKey;
QString fileNameKey;
} LineEdit;
QStringList CustomizeDialog::courses = QStringList()
<< QString::fromUtf8( "小学生の基礎英語" ) << QString::fromUtf8( "中学生の基礎英語【レベル1】" )
<< QString::fromUtf8( "中学生の基礎英語【レベル2】" ) << QString::fromUtf8( "中高生の基礎英語_in_English" )
<< QString::fromUtf8( "英会話タイムトライアル" ) << QString::fromUtf8( "ラジオ英会話" )
<< QString::fromUtf8( "ラジオビジネス英語" ) << QString::fromUtf8( "エンジョイ・シンプル・イングリッシュ" )
<< QString::fromUtf8( "ボキャブライダー" )
<< QString::fromUtf8( "まいにち中国語" ) << QString::fromUtf8( "ステップアップ中国語" )
<< QString::fromUtf8( "まいにちフランス語" ) << QString::fromUtf8( "まいにちイタリア語" )
<< QString::fromUtf8( "まいにちハングル講座" ) << QString::fromUtf8( "ステップアップハングル講座" )
<< QString::fromUtf8( "まいにちドイツ語" ) << QString::fromUtf8( "まいにちスペイン語" )
<< QString::fromUtf8( "まいにちロシア語" );
QStringList CustomizeDialog::titleKeys = QStringList()
<< "basic0_title" << "basic1_title" << "basic2_title" << "basic3_title"
<< "timetrial_title" << "kaiwa_title"
<< "business1_title" << "enjoy_title"
<< "vrradio_title"
<< "chinese_title" << "stepup-chinese_title"
<< "french_title" << "italian_title"
<< "hangeul_title" << "stepup-hangeul_title"
<< "german_title" << "spanish_title"
<< "russian_title";
QStringList CustomizeDialog::fileNameKeys = QStringList()
<< "basic0_file_name" << "basic1_file_name" << "basic2_file_name" << "basic3_file_name"
<< "timetrial_file_name" << "kaiwa_file_name"
<< "business1_file_name" << "enjoy_file_name"
<< "vrradio_file_name"
<< "chinese_file_name" << "stepup-chinese_file_name"
<< "french_file_name" << "italian_file_name"
<< "hangeul_file_name" << "stepup-hangeul_file_name"
<< "german_file_name" << "spanish_file_name"
<< "russian_file_name";
void CustomizeDialog::formats( QString course, QString& titleFormat, QString& fileNameFormat ) {
course.remove( QString::fromUtf8( "【初級編】" ) ); course.remove( QString::fromUtf8( "【入門編】" ) );
course.remove( QString::fromUtf8( "【中級編】" ) ); course.remove( QString::fromUtf8( "【応用編】" ) );
int index = courses.indexOf( course );
if ( index >= 0 ) {
QString path = MainWindow::ini_file_path;
QSettings settings( path + INI_FILE, QSettings::IniFormat );
settings.beginGroup( SETTING_GROUP );
titleFormat = settings.value( titleKeys[index], DefaultTitle ).toString();
fileNameFormat = settings.value( fileNameKeys[index], DefaultFileName ).toString();
settings.endGroup();
} else {
titleFormat = DefaultTitle;
fileNameFormat = DefaultFileName;
}
}
CustomizeDialog::CustomizeDialog( Ui::DialogMode mode, QWidget *parent ) :
QDialog(parent), mode(mode)
{
ui.setupUi(this);
this->setWindowTitle( mode == Ui::TitleMode ? QString::fromUtf8( "タイトルタグ設定" ) : QString::fromUtf8( "ファイル名設定" ) );
settings( false );
connect( this, SIGNAL( accepted() ), this, SLOT( accepted() ) );
}
void CustomizeDialog::settings( bool write ) {
QLineEdit* lineEdits[] = {
ui.lineEdit_0, ui.lineEdit_1, ui.lineEdit_2, ui.lineEdit_3,
ui.lineEdit_4, ui.lineEdit_5, ui.lineEdit_6,
ui.lineEdit_7, ui.lineEdit_8, ui.lineEdit_9, ui.lineEdit_10,
ui.lineEdit_11, ui.lineEdit_12, ui.lineEdit_13, ui.lineEdit_14,
ui.lineEdit_15, ui.lineEdit_16, ui.lineEdit_17,
NULL
};
QString path = MainWindow::ini_file_path;
QSettings settings( path + INI_FILE, QSettings::IniFormat );
settings.beginGroup( SETTING_GROUP );
if ( !write ) {
for ( int i = 0; lineEdits[i] != NULL; i++ ) {
QString format = mode == Ui::TitleMode ?
settings.value( titleKeys[i], DefaultTitle ).toString() :
settings.value( fileNameKeys[i], DefaultFileName ).toString();
lineEdits[i]->setText( format );
}
} else {
for ( int i = 0; lineEdits[i] != NULL; i++ ) {
QString text = lineEdits[i]->text();
if ( mode == Ui::TitleMode )
settings.setValue( titleKeys[i], text.length() == 0 ? DefaultTitle : text );
else
settings.setValue( fileNameKeys[i], text.length() == 0 ? DefaultFileName : text );
}
}
settings.endGroup();
}
void CustomizeDialog::accepted() {
settings( true );
}