-
Notifications
You must be signed in to change notification settings - Fork 0
/
messagejingledialog.cpp
179 lines (167 loc) · 4.65 KB
/
messagejingledialog.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
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
/*!
* \file messagejingledialog.cpp
*/
#include "messagejingledialog.h"
#include "ui_messagejingledialog.h"
#include <QComboBox>
/*!
* \class MessageJingleDialog
* \fn MessageJingleDialog::MessageJingleDialog(QWidget *parent) :
* \brief constructeur de la classe MessageJingleDialog
* \param[in] parent Parent de la fenetre (toujours la MainWindow)
*/
MessageJingleDialog::MessageJingleDialog(QWidget *parent) :
QDialog(parent), ui(new Ui::MessageJingleDialog)
{
ui->setupUi(this);
creerList();
fullComboBox();
load();
creerConnect();
}
/*!
* \fn MessageJingleDialog::~MessageJingleDialog()
* \brief destructeur de la classe
*
*/
MessageJingleDialog::~MessageJingleDialog()
{
delete ui;
}
/*!
* \fn MessageJingleDialog::fullComboBox()
* \brief remplit les combo box avec le contenu du dossier
*
*/
void MessageJingleDialog::fullComboBox()
{
QDir repertoire = Tools::cd("src/jingle");
repertoire.setFilter(QDir::NoDotAndDotDot | QDir::Files);
repertoire.setNameFilters(QStringList() << "*.wav");
for(int i=0; i<comboBoxList.size();i++)
comboBoxList.at(i)->addItem(tr("aucun message"));
/*!
* Parcours le répertoire src/fermeture à la recherche de wav
*/
QString name;
foreach(QFileInfo fileInfo, repertoire.entryInfoList())
{
name = fileInfo.fileName().split(".").at(0);
for(int i=0; i<comboBoxList.size();i++)
comboBoxList.at(i)->addItem(name);
}
}
/*!
* \fn MessageJingleDialog::creerList()
* \brief Créer une liste comprenant les combo box.
*
* Créer une liste comprenant les combo box de la fenetre de facon a ce que ce soit plus facil a utiliser.
*/
void MessageJingleDialog::creerList()
{
comboBoxList.append(ui->ouvertureComboBox);
comboBoxList.append(ui->femetureComboBox);
comboBoxList.append(ui->promotionComboBox);
comboBoxList.append(ui->programmesComboBox);
comboBoxList.append(ui->envoiComboBox);
}
/*!
* \fn QStringList MessageJingleDialog::getValue()
* \brief retourne l'état de chacun des champs
* \return QStringList état des champs sous forme de string
*
*/
QStringList MessageJingleDialog::getValue()
{
QStringList values;
QString value;
for(int i=0; i<comboBoxList.size();i++)
{
if(comboBoxList.at(i)->currentIndex() != 0)
value = Tools::prepare(comboBoxList.at(i)->currentText());
else
value = "";
values.append(value);
}
return values;
}
/*!
* \fn void MessageJingleDialog::creerConnect()
* \brief Creer les connection
*
*/
void MessageJingleDialog::creerConnect()
{
connect(ui->saveButton,SIGNAL(clicked()),this,SLOT(save()));
connect(ui->closeSaveButton,SIGNAL(clicked()),this,SLOT(save()));
}
/*!
* \fn void MessageJingleDialog::save()
* \brief sauvegarde l'etat des champs
*
* sauvegarde l'état des champs dans un fichier de sauvegarde
*/
void MessageJingleDialog::save()
{
QFile fichier(Tools::absolutePathFile("src/jingle.txt"));
if(fichier.open(QIODevice::WriteOnly | QIODevice::Text))
{
QStringList values = getValue();
QTextStream flux(&fichier);
foreach(QString value, values)
flux << value << "\n";
fichier.close();
}
emit jingleChange();
}
/*!
* \fn void MessageJingleDialog::load()
* \brief charge l'état des champs
*
* charge l'état des champs situé dans le fichier de sauvegarde
*/
void MessageJingleDialog::load()
{
QFile fichier(Tools::absolutePathFile("src/jingle.txt"));
if(fichier.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream flux(&fichier);
QStringList values;
for(int i=0; i<5 ;i++)
values.append(flux.readLine());
setValue(values);
fichier.close();
}
}
/*!
* \fn void MessageJingleDialog::setValue(QStringList values)
* \brief assigne un état au différent champs
* \param[in] values état des champs
*
* assigne pour chacun des champs le svaleur situé dans values
* chaque String correspond a un message
*/
void MessageJingleDialog::setValue(QStringList values)
{
int index = 0;
QString echapName;
bool find;
foreach(QString value, values)
{
find = false;
if(value != "")
{
echapName = Tools::unPrepare(value);
for(int i=1; i<comboBoxList.size();i++)
{
comboBoxList.at(index)->setCurrentIndex(i);
if(comboBoxList.at(index)->currentText() == echapName){
find = true;
break;
}
}
if(!find) comboBoxList.at(index)->setCurrentIndex(0);
}
index ++;
}
}