No more pool method in AbstractPosition...
[tagua.git] / src / global.cpp
blob23d080c1d0ccd46a23637cb0758227790e5a4b9f
1 /*
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.
9 */
11 #include "global.h"
12 #include "common.h"
13 #include <QTextStream>
15 QDomElement MasterSettings::node() const {
16 if (m_node.isNull()) {
17 QFile f(m_filename);
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
22 // {
23 // QFile stub(m_filename);
24 // if (!stub.open(QFile::WriteOnly | QFile::Text)) {
25 // std::cout << "Unable to write to configuration file." << std::endl;
26 // exit(1);
27 // }
28 // QTextStream stream(&stub);
29 // stream << "<?xml version=\"1.0\"?>\n"
30 // "<configuration>\n"
31 // "</configuration>\n";
32 // }
34 // // reopen it
35 // if (!f.open(QFile::ReadOnly | QFile::Text))
36 // exit(1);
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());
48 return m_node;
51 MasterSettings::MasterSettings(const QString& filename)
52 : m_filename(QDir(QDir::homePath()).filePath(filename)) { }
54 MasterSettings::~MasterSettings() {
55 sync();
58 void MasterSettings::onChange(QObject* obj, const char* slot) {
59 connect(this, SIGNAL(settingsChanged()), obj, slot);
62 void MasterSettings::sync() {
63 // store to file
64 QFile f(m_filename);
65 if (!f.open(QFile::WriteOnly | QFile::Text))
66 std::cout << "ERROR: cannot open configuration file for writing" << std::endl;
67 else {
68 QTextStream stream(&f);
69 stream << node().ownerDocument().toString();
74 void MasterSettings::changed() {
75 emit settingsChanged();
76 sync();
79 MasterSettings settings(".kboardrc.xml");