2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
13 #include <QTextStream>
15 QDomElement
MasterSettings::node() const {
16 if (m_node
.isNull()) {
18 if (!f
.open(QFile::ReadOnly
| QFile::Text
) || !m_doc
.setContent(&f
)) {
19 std::cout
<< "Unable to open configuration file for reading." << std::endl
;
21 // // create a stub configuration file
23 // QFile stub(m_filename);
24 // if (!stub.open(QFile::WriteOnly | QFile::Text)) {
25 // std::cout << "Unable to write to configuration file." << std::endl;
28 // QTextStream stream(&stub);
29 // stream << "<?xml version=\"1.0\"?>\n"
30 // "<configuration>\n"
31 // "</configuration>\n";
35 // if (!f.open(QFile::ReadOnly | QFile::Text))
38 m_doc
.appendChild(m_doc
.createElement("configuration"));
39 std::cout
<< m_doc
.toString() << std::endl
;
43 const_cast<QDomElement
&>(m_node
) = m_doc
.documentElement();
44 Q_ASSERT(!m_node
.isNull());
45 Q_ASSERT(!m_node
.ownerDocument().isNull());
51 MasterSettings::MasterSettings(const QString
& filename
)
52 : m_filename(QDir(QDir::homePath()).filePath(filename
)) { }
54 MasterSettings::~MasterSettings() {
58 void MasterSettings::onChange(QObject
* obj
, const char* slot
) {
59 connect(this, SIGNAL(settingsChanged()), obj
, slot
);
62 void MasterSettings::sync() {
65 if (!f
.open(QFile::WriteOnly
| QFile::Text
))
66 std::cout
<< "ERROR: cannot open configuration file for writing" << std::endl
;
68 QTextStream
stream(&f
);
69 stream
<< node().ownerDocument().toString();
74 void MasterSettings::changed() {
75 emit
settingsChanged();
79 MasterSettings
settings(".kboardrc.xml");