Added legality checking to shogi.
[tagua/yd.git] / src / mastersettings.h
blob7b796c655ac00ed227378acd12bf37beb1839f8b
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 #ifndef MASTERSETTINGS_H
12 #define MASTERSETTINGS_H
14 #include <memory>
15 #include <iostream>
16 #include <list>
17 #include <QDir>
19 #include "settings.h"
21 class MasterSettings : public QObject
22 , public Settings {
23 Q_OBJECT
24 public:
25 enum LookupType {
26 PathLookup,
27 StandardDirsLookup
29 private:
30 struct Observer {
31 QObject* object;
32 const char* dependency;
33 const char* method;
35 Observer(QObject* obj, const char* meth, const char* dep)
36 : object(obj)
37 , dependency(dep)
38 , method(meth) { }
40 typedef std::list<Observer> ObserverList;
42 ObserverList m_observers;
43 QString m_filename;
44 mutable QDomDocument m_doc;
46 void setupObserver(Observer&);
47 private Q_SLOTS:
48 void objectDestroyed(QObject* o);
50 protected:
51 virtual QDomElement node() const;
53 public:
54 MasterSettings(const QString& file, LookupType lookup = StandardDirsLookup);
56 /**
57 * Bind to the local configuration file.
59 MasterSettings();
60 ~MasterSettings();
62 /**
63 * Set up an observer to be notified whenever settings change.
64 * \param observer The object to be notified.
65 * \param method The callback method for the notification, specified as a C string.
66 * \note @a method should be just the method name (no parentheses, no SLOT macro).
68 void onChange(QObject* observer, const char* method);
70 /**
71 * Set up an observer to be notified whenever settings change.
72 * \param observer The object to be notified.
73 * \param method The callback method for the notification, specified as a C string.
74 * \param dependency A C string representing a type (inheriting from QObject). Objects
75 * of this type will be notified before @a observer.
76 * \note @a method should be just the method name (no parentheses, no SLOT macro).
78 void onChange(QObject* observer, const char* method, const char* dependency);
80 void changed();
81 void sync();
82 QString filename() const;
85 MasterSettings& settings();
87 #endif // MASTERSETTINGS_H