00001
00002
00003 #ifndef _GCONFMM_CLIENT_H
00004 #define _GCONFMM_CLIENT_H
00005
00006 #include <glibmm.h>
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <gconf/gconf-client.h>
00031
00032 #include <glibmm/object.h>
00033
00034 #include <glibmm/error.h>
00035 #include <gconfmm/value.h>
00036 #include <gconfmm/callback.h>
00037 #include <gconfmm/entry.h>
00038 #include <gconfmm/schema.h>
00039 #include <gconfmm/setinterface.h>
00040 #include <gconfmm/changeset.h>
00041
00042
00043 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00044 typedef struct _GConfClient GConfClient;
00045 typedef struct _GConfClientClass GConfClientClass;
00046 #endif
00047
00048
00049 namespace Gnome
00050 {
00051
00052 namespace Conf
00053 { class Client_Class; }
00054
00055 }
00056 namespace Gnome
00057 {
00058 namespace Conf
00059 {
00060
00066 enum ClientErrorHandlingMode
00067 {
00068 CLIENT_HANDLE_NONE,
00069 CLIENT_HANDLE_UNRETURNED,
00070 CLIENT_HANDLE_ALL
00071 };
00072
00073 }
00074
00075 }
00076
00077
00078 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00079 namespace Glib
00080 {
00081
00082 template <>
00083 class Value<Gnome::Conf::ClientErrorHandlingMode> : public Glib::Value_Enum<Gnome::Conf::ClientErrorHandlingMode>
00084 {
00085 public:
00086 static GType value_type() G_GNUC_CONST;
00087 };
00088
00089 }
00090 #endif
00091
00092
00093 namespace Gnome
00094 {
00095
00096 namespace Conf
00097 {
00098
00102 enum ClientPreloadType
00103 {
00104 CLIENT_PRELOAD_NONE,
00105 CLIENT_PRELOAD_ONELEVEL,
00106 CLIENT_PRELOAD_RECURSIVE
00107 };
00108
00109 }
00110
00111 }
00112
00113
00114 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00115 namespace Glib
00116 {
00117
00118 template <>
00119 class Value<Gnome::Conf::ClientPreloadType> : public Glib::Value_Enum<Gnome::Conf::ClientPreloadType>
00120 {
00121 public:
00122 static GType value_type() G_GNUC_CONST;
00123 };
00124
00125 }
00126 #endif
00127
00128
00129 namespace Gnome
00130 {
00131
00132 namespace Conf
00133 {
00134
00135
00138 class Error : public Glib::Error
00139 {
00140 public:
00141 enum Code
00142 {
00143 SUCCESS = 0,
00144 NO_SERVER = 2,
00145 NO_PERMISSION = 3,
00146 BAD_ADDRESS = 4,
00147 PARSE_ERROR = 6,
00148 CORRUPT = 7,
00149 TYPE_MISMATCH = 8,
00150 IS_DIR = 9,
00151 IS_KEY = 10,
00152 OVERRIDDEN = 11,
00153 OAF_ERROR = 12,
00154 LOCAL_ENGINE = 13,
00155 LOCK_FAILED = 14,
00156 NO_WRITABLE_DATABASE = 15,
00157 IN_SHUTDOWN = 16
00158 };
00159
00160 Error(Code error_code, const Glib::ustring& error_message);
00161 explicit Error(GError* gobject);
00162 Code code() const;
00163
00164 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00165 private:
00166 static void throw_func(GError* gobject);
00167 friend void wrap_init();
00168 #endif
00169 };
00170
00171 }
00172
00173 }
00174
00175 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00176 namespace Glib
00177 {
00178
00179 template <>
00180 class Value<Gnome::Conf::Error::Code> : public Glib::Value_Enum<Gnome::Conf::Error::Code>
00181 {
00182 public:
00183 static GType value_type() G_GNUC_CONST;
00184 };
00185
00186 }
00187 #endif
00188
00189
00190 namespace Gnome
00191 {
00192
00193 namespace Conf
00194 {
00195
00196
00197 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00198 template <typename T>
00199 struct BasicTypeTraits
00200 {
00201 typedef T CppType;
00202 typedef CppType* CType;
00203 typedef CppType* CTypeNonConst;
00204
00205 static CType to_c_type(CppType val)
00206 {
00207 CType pVal = new CppType;
00208 *pVal = val;
00209 return pVal;
00210 }
00211
00212 static CType to_c_type(CType ptr)
00213 { return ptr; }
00214
00215 static CppType to_cpp_type(CType ptr)
00216 {
00217 if(ptr)
00218 {
00219 return *ptr;
00220 }
00221 else
00222 return CppType();
00223 }
00224
00225 static void release_c_type(CType ptr)
00226 {
00227 if(ptr)
00228 delete ptr;
00229 }
00230 };
00231
00232
00233
00234 template <>
00235 struct BasicTypeTraits<int>
00236 {
00237 typedef int CppType;
00238 typedef CppType* CType;
00239 typedef CppType* CTypeNonConst;
00240
00241 static CType to_c_type(CppType val)
00242 { return (int*)GINT_TO_POINTER(val); }
00243
00244 static CType to_c_type(CType ptr)
00245 { return ptr; }
00246
00247 static CppType to_cpp_type(CType ptr)
00248 {
00249 if(ptr)
00250 {
00251 return GPOINTER_TO_INT(ptr);
00252 }
00253 else
00254 return CppType();
00255 }
00256
00257 static void release_c_type(CType )
00258 {
00259 }
00260 };
00261
00262 template <>
00263 struct BasicTypeTraits<bool>
00264 {
00265 typedef bool CppType;
00266 typedef gboolean* CType;
00267 typedef gboolean* CTypeNonConst;
00268
00269 static CType to_c_type(CppType val)
00270 {
00271 return (int*)GINT_TO_POINTER(val);
00272 }
00273
00274 static CType to_c_type(CType ptr)
00275 { return ptr; }
00276
00277 static CppType to_cpp_type(CType ptr)
00278 {
00279 if(ptr)
00280 {
00281
00282 return GPOINTER_TO_INT(ptr);
00283 }
00284 else
00285 return CppType();
00286 }
00287
00288 static void release_c_type(CType )
00289 {
00290
00291 }
00292 };
00293
00294 #endif //DOXYGEN_SHOULD_SKIP_THIS
00295
00296
00307 class Client : public Glib::Object, public SetInterface
00308 {
00309
00310 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00311
00312 public:
00313 typedef Client CppObjectType;
00314 typedef Client_Class CppClassType;
00315 typedef GConfClient BaseObjectType;
00316 typedef GConfClientClass BaseClassType;
00317
00318 private: friend class Client_Class;
00319 static CppClassType client_class_;
00320
00321 private:
00322
00323 Client(const Client&);
00324 Client& operator=(const Client&);
00325
00326 protected:
00327 explicit Client(const Glib::ConstructParams& construct_params);
00328 explicit Client(GConfClient* castitem);
00329
00330 #endif
00331
00332 public:
00333 virtual ~Client();
00334
00335 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00336 static GType get_type() G_GNUC_CONST;
00337 static GType get_base_type() G_GNUC_CONST;
00338 #endif
00339
00341 GConfClient* gobj() { return reinterpret_cast<GConfClient*>(gobject_); }
00342
00344 const GConfClient* gobj() const { return reinterpret_cast<GConfClient*>(gobject_); }
00345
00347 GConfClient* gobj_copy();
00348
00349 private:
00350
00351
00352 public:
00353
00357 static Glib::RefPtr<Client> get_default_client();
00358 static Glib::RefPtr<Client> get_client_for_engine(GConfEngine* engine);
00359
00373 void add_dir(const Glib::ustring& dir, ClientPreloadType preload = CLIENT_PRELOAD_NONE);
00374
00378 void remove_dir(const Glib::ustring& dir);
00379
00380
00399 guint notify_add(const Glib::ustring& namespace_section, Callback callback);
00400
00401
00407 void notify_remove(guint cnxn);
00408
00409
00410 void set_error_handling(ClientErrorHandlingMode mode);
00411
00414 void clear_cache();
00415
00422 void preload(const Glib::ustring& dirname, ClientPreloadType type);
00423
00430 Value get(const Glib::ustring& key) const;
00431
00440 Value get_without_default(const Glib::ustring& key) const;
00441
00448 Value get_default_from_schema(const Glib::ustring& key) const;
00449
00458 Entry get_entry(const Glib::ustring& key, bool use_schema_default = true) const;
00459
00469 Entry get_entry(const Glib::ustring& key, const char* locale, bool use_schema_default = true) const;
00470
00476 void unset(const Glib::ustring& key);
00477
00485 Glib::SListHandle<Entry> all_entries(const Glib::ustring& dir) const;
00486
00493 Glib::SListHandle<Glib::ustring> all_dirs(const Glib::ustring& dir) const;
00494
00500 void suggest_sync();
00501
00507 bool dir_exists(const Glib::ustring&) const;
00508
00514 bool key_is_writable(const Glib::ustring&) const;
00515
00523 double get_float(const Glib::ustring& key) const;
00524
00528 gint get_int(const Glib::ustring& key) const;
00529
00533 bool get_bool(const Glib::ustring& key) const;
00534
00538 Glib::ustring get_string(const Glib::ustring& key) const;
00539
00543 Schema get_schema(const Glib::ustring& key) const;
00544
00552 SListHandle_ValueInt get_int_list(const Glib::ustring& key) const;
00553
00556 SListHandle_ValueBool get_bool_list(const Glib::ustring& key) const;
00557
00560 SListHandle_ValueFloat get_float_list(const Glib::ustring& key) const;
00561
00564 SListHandle_ValueSchema get_schema_list(const Glib::ustring& key) const;
00565
00568 SListHandle_ValueString get_string_list(const Glib::ustring& key) const;
00569
00570
00579 ValuePair get_pair(const Glib::ustring& key, ValueTypePair types) const;
00580
00581
00588 void set(const Glib::ustring& key, int what);
00589
00593 void set(const Glib::ustring& key, bool what);
00594
00598 void set(const Glib::ustring& key,double what);
00599
00603 void set(const Glib::ustring& key, const Glib::ustring& what);
00604
00608 void set(const Glib::ustring& key, const Schema& what);
00609
00614 void set(const Glib::ustring& key, const Value& what);
00615
00616
00617 typedef Glib::SListHandle< int, BasicTypeTraits<int> > SListHandleInts;
00618 void set_int_list(const Glib::ustring& key, const SListHandleInts& what);
00619
00620 typedef Glib::SListHandle< bool, BasicTypeTraits<bool> > SListHandleBools;
00621 void set_bool_list(const Glib::ustring& key, const SListHandleBools& what);
00622
00623 typedef Glib::SListHandle< double, BasicTypeTraits<double> > SListHandleFloats;
00624 void set_float_list(const Glib::ustring& key, const SListHandleFloats& what);
00625
00626 void set_schema_list(const Glib::ustring& key, const Glib::SListHandle<Schema>& what);
00627 void set_string_list(const Glib::ustring& key, const Glib::SListHandle<Glib::ustring>& what);
00628
00638 ChangeSet change_set_from_current(const Glib::SArray& set);
00639
00640
00652 void change_set_commit(ChangeSet& set, bool remove_commited);
00653
00665 ChangeSet change_set_reverse(const ChangeSet& set);
00666
00672 Glib::SignalProxy2< void,const Glib::ustring&,const Value& > signal_value_changed();
00673
00674
00675 void value_changed(const Glib::ustring& key, const Value& value);
00676
00677 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00678
00679
00680
00681
00682 Glib::SignalProxy1< void,const Glib::Error& > signal_unreturned_error();
00683
00684
00685 void unreturned_error(const Glib::Error& error);
00686 #endif
00687
00693 Glib::SignalProxy1< void,const Glib::Error& > signal_error();
00694
00695
00696 void error(const Glib::Error& error);
00697
00698 private:
00699 void handle_error(GError* pError) const;
00700
00701 GSList* get_list(const Glib::ustring& key, GConfValueType list_type) const;
00702
00703
00704 public:
00705
00706 public:
00707
00708
00709 protected:
00710
00711
00712
00713 virtual void on_value_changed(const Glib::ustring& key, const Value& value);
00714 virtual void on_unreturned_error(const Glib::Error& error);
00715 virtual void on_error(const Glib::Error& error);
00716
00717
00718 };
00719
00720 }
00721 }
00722
00723
00724 namespace Glib
00725 {
00731 Glib::RefPtr<Gnome::Conf::Client> wrap(GConfClient* object, bool take_copy = false);
00732 }
00733
00734
00735 #endif
00736