231a7165fd481925e71f7d91ea5a9073e8169a5f
[vicar] / src / vicar-lib / cpp / gconfutility.cpp
1 /*
2 @version: 0.6
3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
5 */
6
7 #include "gconfutility.h"
8 #include <gconf/gconf-client.h>
9 #include <QDebug>
10
11 GConfUtility::GConfUtility(QObject *parent) :
12     QObject(parent)
13 {
14     /* Get a GConf client */
15     gconfClient = gconf_client_get_default();
16     g_assert(GCONF_IS_CLIENT(gconfClient));
17 }
18
19 GConfUtility::~GConfUtility(){
20     /* release GConf client */
21     g_object_unref(gconfClient);
22     gconfClient = 0;
23 }
24
25 QString GConfUtility::getGconfValueString(QString strKey){
26
27     char* strValue = NULL;
28
29     if (!strKey.isEmpty()) {
30         strKey.prepend(GCONF_DIR);
31
32         strValue = gconf_client_get_string(gconfClient, strKey.toAscii().constData(), NULL);
33         qDebug() << "Gconf: "<<strKey.toAscii().constData()<< " is "<<strValue;
34     }
35
36     return QString(strValue);
37 }
38
39 void GConfUtility::setGconfValueString(QString strKey,QString strValue){
40
41     if (!strKey.isEmpty()){
42
43         strKey.prepend(GCONF_DIR);
44
45         if (!strValue.isEmpty()){
46                 gconf_client_set_string(gconfClient, strKey.toAscii().constData(), strValue.toAscii().constData(),NULL);
47                 qDebug() << "Assigned "<<strKey.toAscii().constData()<< " to "<<strValue.toAscii().constData();
48         }
49         else{
50                 gconf_client_unset(gconfClient, strKey.toAscii().constData(),NULL);
51                 qDebug() << "Assigned "<<strKey.toAscii().constData()<< " to NULL";
52         }
53
54     }
55 }
56
57 bool GConfUtility::getGconfValueBoolean(QString strKey){
58
59     bool boolValue = false;
60
61     if (!strKey.isEmpty()) {
62         strKey.prepend(GCONF_DIR);
63
64         boolValue = gconf_client_get_bool(gconfClient, strKey.toAscii().constData(), NULL);
65         qDebug() << "Gconf: "<<strKey.toAscii().constData()<< " is "<<boolValue;
66     }
67
68     return boolValue;
69 }
70
71 void GConfUtility::setGconfValueBoolean(QString strKey,bool boolValue){
72
73     if (!strKey.isEmpty()){
74
75         strKey.prepend(GCONF_DIR);
76
77         gconf_client_set_bool(gconfClient, strKey.toAscii().constData(),boolValue,NULL);
78         qDebug() << "Assigned "<<strKey.toAscii().constData()<< " to "<<boolValue;
79     }
80 }
81
82 int GConfUtility::getGconfValueInteger(QString strKey){
83
84     int intValue = 0;
85
86     if (!strKey.isEmpty()) {
87         strKey.prepend(GCONF_DIR);
88
89         intValue = gconf_client_get_int(gconfClient, strKey.toAscii().constData(), NULL);
90         qDebug() << "Gconf: "<<strKey.toAscii().constData()<< " is "<<intValue;
91     }
92
93     return intValue;
94 }
95
96 void GConfUtility::setGconfValueInteger(QString strKey,int intValue){
97
98     if (!strKey.isEmpty()){
99
100         strKey.prepend(GCONF_DIR);
101
102         gconf_client_set_int(gconfClient, strKey.toAscii().constData(),intValue,NULL);
103         qDebug() << "Assigned "<<strKey.toAscii().constData()<< " to "<<intValue;
104     }
105 }