]>
git.ipfire.org Git - thirdparty/freeswitch.git/blob - fscomm/isettings.cpp
4 QMutex
*ISettings::mutex
= new QMutex();
5 QDomDocument
*ISettings::xml
= 0;
7 ISettings::ISettings(QObject
*parent
) :
10 ISettings::mutex
->lock();
11 if (!(ISettings::xml
)) {
12 QFile
*f
= new QFile(QString("%1%2%3").arg(SWITCH_GLOBAL_dirs
.conf_dir
, SWITCH_PATH_SEPARATOR
,"freeswitch.xml"));
13 if ( !f
->open(QIODevice::ReadOnly
| QIODevice::Text
) ) {
14 /* TODO: Let the user know */
15 qDebug() << "Could not read from file.";
19 int errLine
= 0, errCol
= 0;
20 ISettings::xml
= new QDomDocument();
21 if ( !ISettings::xml
->setContent(f
, &errMsg
, &errLine
, &errCol
) ) {
22 /* TODO: Let the user know */
23 qDebug() << "Could not set content";
28 ISettings::mutex
->unlock();
31 QDomElement
ISettings::getConfigNode(QString module
) {
32 /* We don't need to lock since we are just reading (true?) */
33 QDomElement e
= ISettings::xml
->documentElement();
34 QDomNodeList nl
= e
.elementsByTagName("configuration");
35 for(int i
= 0; i
< nl
.count(); i
++) {
36 QDomElement el
= nl
.at(i
).toElement();
37 if ( el
.attribute("name") == module
) {
44 void ISettings::setConfigNode(QDomElement node
, QString module
) {
45 ISettings::mutex
->lock();
46 QDomElement e
= ISettings::xml
->documentElement();
47 QDomNodeList l
= e
.elementsByTagName("configuration");
48 for (int i
= 0; i
< l
.count(); i
++) {
49 QDomElement el
= l
.at(i
).toElement();
50 if ( el
.attribute("name") == module
) {
51 /* Found the proper module to replace */
52 el
.parentNode().replaceChild(node
.toDocumentFragment(),el
);
55 ISettings::mutex
->unlock();
58 void ISettings::saveToFile() {
59 ISettings::mutex
->lock();
61 QFile
*f
= new QFile(QString("%1%2%3").arg(SWITCH_GLOBAL_dirs
.conf_dir
, SWITCH_PATH_SEPARATOR
,"freeswitch.xml"));
62 if ( !f
->open(QFile::WriteOnly
| QFile::Truncate
) ) {
63 /* TODO: Let the user know */
64 qDebug() << "Could not open from file.";
68 ISettings::xml
->save(out
, 2);
70 if ( !f
->open(QFile::ReadOnly
) ) {
71 /* TODO: Let the user know */
72 qDebug() << "Could not open from file.";
76 int errLine
= 0, errCol
= 0;
77 if ( !ISettings::xml
->setContent(f
, &errMsg
, &errLine
, &errCol
) ) {
78 /* TODO: Let the user know */
79 qDebug() << "Could not set content";
84 ISettings::mutex
->unlock();