/gpump/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/gpump/trunk

« back to all changes in this revision

Viewing changes to src/GPumpSettingsData.c

  • Committer: Gustav Hatvigsson
  • Date: 2014-04-13 13:53:09 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140413135309-mb8mrjww5cc2vikr
* Added a singeltonian class to keep settings data in.
* removed GSettings from GPumpApp and GPumpSettings, this should be done 
  using the GPumpSettingsData object instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "GPumpSettingsData.h"
 
3
 
 
4
G_DEFINE_TYPE (GPumpSettingsData, gpump_settings_data, G_TYPE_OBJECT)
 
5
 
 
6
 
 
7
/* * Override the default constructer *****************************************/
 
8
GObject * _constructor (GType type,
 
9
                        guint n_construct_params,
 
10
                        GObjectConstructParam * construct_params);
 
11
 
 
12
 
 
13
/******************************************************************************/
 
14
GPumpSettingsData * gpump_settings_data_get_default () {
 
15
  GPumpSettingsData * self = g_object_new (GPUMP_TYPE_SETTINGS_DATA,
 
16
                                           NULL);
 
17
  
 
18
  return self;
 
19
}
 
20
 
 
21
void gpump_settings_data_init (GPumpSettingsData * self) {
 
22
  g_print ("Init GPumpSettingsData\n");
 
23
  self->ui_settings = g_settings_new ("org.gego.gpump.ui");
 
24
  self->gpump_settings = g_settings_new ("org.gego.gpump");
 
25
}
 
26
 
 
27
 
 
28
void gpump_settings_data_class_init (GPumpSettingsDataClass * klass) {
 
29
  GObjectClass * parent = G_OBJECT_CLASS (klass);
 
30
  
 
31
  parent->constructor = _constructor;
 
32
}
 
33
 
 
34
/* * Implementation of the constructor ****************************************
 
35
 *
 
36
 * See: blogs.gnome.org/xclaesse/2010/02/11/how-to-make-a-gobject-singleton/
 
37
 * for more information.
 
38
 */
 
39
GObject * _constructor (GType type,
 
40
                        guint n_construct_params,
 
41
                        GObjectConstructParam * construct_params) {
 
42
  static GObject * self = NULL;
 
43
  static GMutex mutex;
 
44
  
 
45
  g_mutex_lock (&mutex);
 
46
  if (self == NULL) {
 
47
    self = G_OBJECT_CLASS (gpump_settings_data_parent_class)->constructor (
 
48
      type, n_construct_params, construct_params);
 
49
    g_object_add_weak_pointer (self, (gpointer) &self);
 
50
    g_mutex_unlock (&mutex);
 
51
    return self;
 
52
  }
 
53
  g_mutex_unlock (&mutex);
 
54
  return g_object_ref (self);
 
55
}
 
56
 
 
57