~ubuntu-branches/ubuntu/raring/workrave/raring

« back to all changes in this revision

Viewing changes to .pc/leak-fix.patch/backend/src/GlibIniConfigurator.cc

  • Committer: Package Import Robot
  • Author(s): Francois Marier, Francois Marier, Jordi Mallach
  • Date: 2012-05-28 11:29:40 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20120528112940-bbbsjkk30fom9s8x
Tags: 1.9.909+abc941eb70-1
[ Francois Marier ]
* New upstream snapshot
  - Drop leak-fix patch (applied upstream)
  - Document how the tarball is built in README.source
* Build GNOME applets and use gsettings
* Massive update of Build-Depends as per configure.ac

* Update README.source with snapshot instructions
* Switch to machine-readable copyright file
* Update alioth git repo links
* Bump debhelper version to 9
* Bump Standards-Version to 3.9.3

[ Jordi Mallach ]
* Avoid references to GNU/Linux in manpage.
* Drop build dependency on libgnet-dev, it's obsolete and unneeded.
* Add myself to Uploaders.
* Rewrite d/rules into dh style.
  - Move all install tweaks to .install files.
  - Install manpages using dh_installman.
* As a side effect, the package installs arch-dependant data in the
  arch triplet directory; add the required Pre-Depends for m-a-support.
* Bring back GNOME Panel applet (for GNOME 3 fallback mode) and ship the
  new GNOME Shell extension (closes: #642514, #666100).
* Add private_dirs.patch: move libworkrave-private and GObject
  Introspection files to a private dir, so they are really out of the
  way, but disable it for now as it breaks the Shell extension.
* Move typelib out of the triplet dir as gobject-introspection is not
  M-A ready yet.
* Enable dh_autoreconf for the above patches.
* Add lintian overrides.
* Add necessary Breaks/Replaces as the xpm icon has moved to workrave-data.
* Prefix all debhelper files with package name.
* Suggest gnome-shell and gnome-panel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// IniConfigurator.cc --- Configuration Access
2
 
//
3
 
// Copyright (C) 2005, 2006, 2007, 2008 Rob Caelers <robc@krandor.nl>
4
 
// All rights reserved.
5
 
//
6
 
// This program is free software: you can redistribute it and/or modify
7
 
// it under the terms of the GNU General Public License as published by
8
 
// the Free Software Foundation, either version 3 of the License, or
9
 
// (at your option) any later version.
10
 
//
11
 
// This program is distributed in the hope that it will be useful,
12
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
// GNU General Public License for more details.
15
 
//
16
 
// You should have received a copy of the GNU General Public License
17
 
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
//
19
 
 
20
 
#ifdef HAVE_CONFIG_H
21
 
#include "config.h"
22
 
#endif
23
 
 
24
 
#include "debug.hh"
25
 
 
26
 
#include <string.h>
27
 
#include <sstream>
28
 
#include <assert.h>
29
 
#include <iostream>
30
 
#include <fstream>
31
 
 
32
 
#include "GlibIniConfigurator.hh"
33
 
#include <glib.h>
34
 
 
35
 
using namespace std;
36
 
 
37
 
GlibIniConfigurator::GlibIniConfigurator()
38
 
  : config(NULL)
39
 
{
40
 
}
41
 
 
42
 
 
43
 
GlibIniConfigurator::~GlibIniConfigurator()
44
 
{
45
 
  if (config != NULL)
46
 
    {
47
 
      g_key_file_free(config);
48
 
    }
49
 
}
50
 
 
51
 
 
52
 
bool
53
 
GlibIniConfigurator::load(string filename)
54
 
{
55
 
  GError *error = NULL;
56
 
  gboolean r = TRUE;
57
 
 
58
 
  last_filename = filename;
59
 
 
60
 
  TRACE_ENTER_MSG("GlibIniConfigurator::load", filename)
61
 
    config = g_key_file_new();
62
 
 
63
 
  r = g_key_file_load_from_file(config, filename.c_str(),
64
 
                                G_KEY_FILE_KEEP_COMMENTS, &error);
65
 
 
66
 
  if (r)
67
 
    {
68
 
    }
69
 
 
70
 
  if (error != NULL)
71
 
    {
72
 
      g_error_free(error);
73
 
    }
74
 
 
75
 
  TRACE_EXIT();
76
 
  return error == NULL;
77
 
}
78
 
 
79
 
 
80
 
bool
81
 
GlibIniConfigurator::save(string filename)
82
 
{
83
 
  GError *error = NULL;
84
 
  char *str = g_key_file_to_data(config, NULL, &error);
85
 
 
86
 
  TRACE_ENTER_MSG("GlibIniConfigurator::save", filename);
87
 
  if (error != NULL)
88
 
    {
89
 
      g_error_free(error);
90
 
    }
91
 
  else
92
 
    {
93
 
      ofstream config_file(filename.c_str());
94
 
 
95
 
      config_file << str;
96
 
 
97
 
      config_file.close();
98
 
    }
99
 
 
100
 
  TRACE_EXIT();
101
 
  return error == NULL;
102
 
}
103
 
 
104
 
 
105
 
bool
106
 
GlibIniConfigurator::save()
107
 
{
108
 
  return save(last_filename);
109
 
}
110
 
 
111
 
 
112
 
bool
113
 
GlibIniConfigurator::remove_key(const std::string &key)
114
 
{
115
 
  bool ret = true;
116
 
  GError *error = NULL;
117
 
  string group;
118
 
  string inikey;
119
 
 
120
 
  TRACE_ENTER_MSG("GlibIniConfigurator::remove_key", key);
121
 
  split_key(key, group, inikey);
122
 
  inikey = key_inify(inikey);
123
 
 
124
 
  g_key_file_remove_key(config, group.c_str(), inikey.c_str(), &error);
125
 
 
126
 
  if (error != NULL)
127
 
    {
128
 
      g_error_free(error);
129
 
      ret = false;
130
 
    }
131
 
 
132
 
  TRACE_EXIT();
133
 
  return ret;
134
 
}
135
 
 
136
 
 
137
 
bool
138
 
GlibIniConfigurator::get_value(const std::string &key, VariantType type,
139
 
                               Variant &out) const
140
 
{
141
 
  bool ret = true;
142
 
  GError *error = NULL;
143
 
  string group;
144
 
  string inikey;
145
 
 
146
 
  TRACE_ENTER_MSG("GlibIniConfigurator::get_value", key);
147
 
  split_key(key, group, inikey);
148
 
  inikey = key_inify(inikey);
149
 
 
150
 
  out.type = type;
151
 
 
152
 
  switch(type)
153
 
    {
154
 
    case VARIANT_TYPE_INT:
155
 
      out.int_value = g_key_file_get_integer(config, group.c_str(), inikey.c_str(), &error);
156
 
      break;
157
 
 
158
 
    case VARIANT_TYPE_BOOL:
159
 
      out.bool_value = g_key_file_get_boolean(config, group.c_str(), inikey.c_str(), &error);
160
 
      break;
161
 
 
162
 
    case VARIANT_TYPE_DOUBLE:
163
 
      {
164
 
        char *s = g_key_file_get_string(config, group.c_str(), inikey.c_str(), &error);
165
 
        if (error == NULL && s != NULL)
166
 
          {
167
 
            sscanf(s, "%lf", &out.double_value);
168
 
          }
169
 
        break;
170
 
      }
171
 
 
172
 
    case VARIANT_TYPE_NONE:
173
 
      out.type = VARIANT_TYPE_STRING;
174
 
      // FALLTHROUGH
175
 
 
176
 
    case VARIANT_TYPE_STRING:
177
 
      {
178
 
        char *s = g_key_file_get_string(config, group.c_str(), inikey.c_str(), &error);
179
 
        if (error == NULL && s != NULL)
180
 
          {
181
 
            out.string_value = s;
182
 
          }
183
 
      }
184
 
      break;
185
 
 
186
 
    default:
187
 
      ret = false;
188
 
    }
189
 
 
190
 
  if (error != NULL)
191
 
    {
192
 
      g_error_free(error);
193
 
      ret = false;
194
 
    }
195
 
 
196
 
  TRACE_EXIT();
197
 
  return ret;
198
 
}
199
 
 
200
 
bool
201
 
GlibIniConfigurator::set_value(const std::string &key, Variant &value)
202
 
{
203
 
  bool ret = true;
204
 
  string group;
205
 
  string inikey;
206
 
 
207
 
  split_key(key, group, inikey);
208
 
  inikey = key_inify(inikey);
209
 
 
210
 
  switch(value.type)
211
 
    {
212
 
    case VARIANT_TYPE_INT:
213
 
      g_key_file_set_integer(config, group.c_str(), inikey.c_str(), value.int_value);
214
 
      break;
215
 
 
216
 
    case VARIANT_TYPE_BOOL:
217
 
      g_key_file_set_boolean(config, group.c_str(), inikey.c_str(), value.bool_value);
218
 
      break;
219
 
 
220
 
    case VARIANT_TYPE_DOUBLE:
221
 
      {
222
 
        char buf[32];
223
 
        sprintf(buf, "%f", value.double_value);
224
 
 
225
 
        split_key(key, group, inikey);
226
 
        inikey = key_inify(inikey);
227
 
 
228
 
        g_key_file_set_string(config, group.c_str(), inikey.c_str(), buf);
229
 
      }
230
 
      break;
231
 
 
232
 
    case VARIANT_TYPE_NONE:
233
 
    case VARIANT_TYPE_STRING:
234
 
      g_key_file_set_string(config, group.c_str(), inikey.c_str(), value.string_value.c_str());
235
 
      break;
236
 
 
237
 
    default:
238
 
      ret = false;
239
 
    }
240
 
 
241
 
  return ret;
242
 
}
243
 
 
244
 
 
245
 
void
246
 
GlibIniConfigurator::split_key(const string &key, string &group, string &out_key) const
247
 
{
248
 
  const char *s = key.c_str();
249
 
  const char *slash = strchr(s, '/');
250
 
  if (slash)
251
 
    {
252
 
      group = key.substr(0, slash-s);
253
 
      out_key = slash+1;
254
 
    }
255
 
  else
256
 
    {
257
 
      group = "";
258
 
      out_key = "";
259
 
    }
260
 
}
261
 
 
262
 
 
263
 
string
264
 
GlibIniConfigurator::key_inify(const string &key) const
265
 
{
266
 
  string rc = key;
267
 
  for (unsigned int i = 0; i < rc.length(); i++)
268
 
    {
269
 
      if (rc[i] == '/')
270
 
        {
271
 
          rc[i] = '.';
272
 
        }
273
 
    }
274
 
  return rc;
275
 
}