-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettingwidget.cpp
More file actions
173 lines (140 loc) · 4.26 KB
/
Copy pathsettingwidget.cpp
File metadata and controls
173 lines (140 loc) · 4.26 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
#include "settingwidget.h"
#include "ui_settingwidget.h"
#include "songsfile.h"
#include "lyricsfile.h"
#include <QDebug>
SettingWidget::SettingWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::SettingWidget)
{
ui->setupUi(this);
initEtcInfo();
initCheckBoxInfo();
}
SettingWidget::~SettingWidget()
{
delete ui;
}
void SettingWidget::initCheckBoxInfo(void){
readInit("Setting", "Close", m_closeState);
readInit("Setting", "Welcome", m_welcomeState);
if(m_closeState == "true"){
ui->cb_close->setChecked(true);
}else{
ui->cb_close->setChecked(false);
}
if(m_welcomeState == "true"){
ui->cb_welcome->setChecked(true);
}else{
ui->cb_welcome->setChecked(false);
}
}
bool SettingWidget::getCloseCheckBoxStatus(){
if(m_closeState == "true"){
return true;
}else{
return false;
}
}
bool SettingWidget::getWelcomeCheckBoxStatus(){
if(m_welcomeState == "true"){
return true;
}else{
return false;
}
}
void SettingWidget::initEtcInfo(void)
{
QString songsPath;
QString lyricPath;
m_settingFileName = "./../MusicPlayerZ/user.ini";
readInit("Path", "songPath", songsPath);
readInit("Path", "lyricPath", lyricPath);
ui->le_songPath->setText(songsPath);
ui->le_lyricPath->setText(lyricPath);
SongsFile::setSongsPath(songsPath);
LyricsFile::setLyricPath(lyricPath);
}
bool SettingWidget::writeInit(QString group, QString key, QString value)
{
if(group.isEmpty() || key.isEmpty())
{
return false;
}
else
{
//创建配置文件操作对象
QSettings config(m_settingFileName, QSettings::IniFormat);
//将信息写入配置文件
config.beginGroup(group);
config.setValue(key, value);
config.endGroup();
return true;
}
}
bool SettingWidget::readInit(QString group, QString key, QString &value)
{
value.clear();
if(m_settingFileName.isEmpty() || key.isEmpty())
{
return false;
}
else
{
//创建配置文件操作对象
QSettings config(m_settingFileName, QSettings::IniFormat);
//读取用户配置信息
value = config.value(group + "/" + key).toString();
qDebug()<<value;
return true;
}
}
void SettingWidget::on_pb_sure_clicked()
{
writeInit("Path", "songPath", ui->le_songPath->text());
writeInit("Path", "lyricPath", ui->le_lyricPath->text());
emit signalSongsAndLyricChanged(ui->le_songPath->text(),
ui->le_lyricPath->text());
this->hide();
}
void SettingWidget::on_pb_songPath_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this, tr("Select the song path"),
"/home",
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
ui->le_songPath->setText(dir);
}
void SettingWidget::on_pb_lyricPath_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this, tr("Select the lyric path"),
"/home",
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
ui->le_lyricPath->setText(dir);
}
void SettingWidget::on_pb_set_clicked()
{
writeInit("Setting", "Close", ui->cb_close->isChecked());
writeInit("Setting", "Welcome", ui->cb_welcome->isChecked());
readInit("Setting", "Close", m_closeState);
readInit("Setting", "Welcome", m_welcomeState);
this->hide();
}
bool SettingWidget::writeInit(QString group, QString key, bool value)
{
if(group.isEmpty() || key.isEmpty())
{
return false;
}
else
{
//创建配置文件操作对象
QSettings config(m_settingFileName, QSettings::IniFormat);
//将信息写入配置文件
config.beginGroup(group);
config.setValue(key, value);
config.endGroup();
return true;
}
}