[134] | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
---|
| 2 | * |
---|
| 3 | * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> |
---|
| 4 | * |
---|
| 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 | * |
---|
| 10 | * This program is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU General Public License |
---|
| 16 | * along with this program; if not, write to the Free Software |
---|
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 18 | * |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #include "config.h" |
---|
| 22 | |
---|
| 23 | #include <stdlib.h> |
---|
| 24 | #include <stdio.h> |
---|
| 25 | |
---|
| 26 | #include <glib.h> |
---|
| 27 | #include <glib/gi18n.h> |
---|
| 28 | #include <glib-object.h> |
---|
| 29 | |
---|
| 30 | #include "gdm-display-factory.h" |
---|
| 31 | #include "gdm-display-store.h" |
---|
| 32 | |
---|
| 33 | #define GDM_DISPLAY_FACTORY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_DISPLAY_FACTORY, GdmDisplayFactoryPrivate)) |
---|
| 34 | |
---|
| 35 | struct GdmDisplayFactoryPrivate |
---|
| 36 | { |
---|
| 37 | GdmDisplayStore *display_store; |
---|
| 38 | }; |
---|
| 39 | |
---|
| 40 | enum { |
---|
| 41 | PROP_0, |
---|
| 42 | PROP_DISPLAY_STORE, |
---|
| 43 | }; |
---|
| 44 | |
---|
| 45 | static void gdm_display_factory_class_init (GdmDisplayFactoryClass *klass); |
---|
| 46 | static void gdm_display_factory_init (GdmDisplayFactory *factory); |
---|
| 47 | static void gdm_display_factory_finalize (GObject *object); |
---|
| 48 | |
---|
| 49 | G_DEFINE_ABSTRACT_TYPE (GdmDisplayFactory, gdm_display_factory, G_TYPE_OBJECT) |
---|
| 50 | |
---|
| 51 | GQuark |
---|
| 52 | gdm_display_factory_error_quark (void) |
---|
| 53 | { |
---|
| 54 | static GQuark ret = 0; |
---|
| 55 | if (ret == 0) { |
---|
| 56 | ret = g_quark_from_static_string ("gdm_display_factory_error"); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | return ret; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | GdmDisplayStore * |
---|
| 63 | gdm_display_factory_get_display_store (GdmDisplayFactory *factory) |
---|
| 64 | { |
---|
| 65 | g_return_val_if_fail (GDM_IS_DISPLAY_FACTORY (factory), NULL); |
---|
| 66 | |
---|
| 67 | return factory->priv->display_store; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | gboolean |
---|
| 71 | gdm_display_factory_start (GdmDisplayFactory *factory) |
---|
| 72 | { |
---|
| 73 | gboolean ret; |
---|
| 74 | |
---|
| 75 | g_return_val_if_fail (GDM_IS_DISPLAY_FACTORY (factory), FALSE); |
---|
| 76 | |
---|
| 77 | g_object_ref (factory); |
---|
| 78 | ret = GDM_DISPLAY_FACTORY_GET_CLASS (factory)->start (factory); |
---|
| 79 | g_object_unref (factory); |
---|
| 80 | |
---|
| 81 | return ret; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | gboolean |
---|
| 85 | gdm_display_factory_stop (GdmDisplayFactory *factory) |
---|
| 86 | { |
---|
| 87 | gboolean ret; |
---|
| 88 | |
---|
| 89 | g_return_val_if_fail (GDM_IS_DISPLAY_FACTORY (factory), FALSE); |
---|
| 90 | |
---|
| 91 | g_object_ref (factory); |
---|
| 92 | ret = GDM_DISPLAY_FACTORY_GET_CLASS (factory)->stop (factory); |
---|
| 93 | g_object_unref (factory); |
---|
| 94 | |
---|
| 95 | return ret; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | static void |
---|
| 99 | gdm_display_factory_set_display_store (GdmDisplayFactory *factory, |
---|
| 100 | GdmDisplayStore *display_store) |
---|
| 101 | { |
---|
| 102 | if (factory->priv->display_store != NULL) { |
---|
| 103 | g_object_unref (factory->priv->display_store); |
---|
| 104 | factory->priv->display_store = NULL; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | if (display_store != NULL) { |
---|
| 108 | factory->priv->display_store = g_object_ref (display_store); |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | static void |
---|
| 113 | gdm_display_factory_set_property (GObject *object, |
---|
| 114 | guint prop_id, |
---|
| 115 | const GValue *value, |
---|
| 116 | GParamSpec *pspec) |
---|
| 117 | { |
---|
| 118 | GdmDisplayFactory *self; |
---|
| 119 | |
---|
| 120 | self = GDM_DISPLAY_FACTORY (object); |
---|
| 121 | |
---|
| 122 | switch (prop_id) { |
---|
| 123 | case PROP_DISPLAY_STORE: |
---|
| 124 | gdm_display_factory_set_display_store (self, g_value_get_object (value)); |
---|
| 125 | break; |
---|
| 126 | default: |
---|
| 127 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
| 128 | break; |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | static void |
---|
| 133 | gdm_display_factory_get_property (GObject *object, |
---|
| 134 | guint prop_id, |
---|
| 135 | GValue *value, |
---|
| 136 | GParamSpec *pspec) |
---|
| 137 | { |
---|
| 138 | GdmDisplayFactory *self; |
---|
| 139 | |
---|
| 140 | self = GDM_DISPLAY_FACTORY (object); |
---|
| 141 | |
---|
| 142 | switch (prop_id) { |
---|
| 143 | case PROP_DISPLAY_STORE: |
---|
| 144 | g_value_set_object (value, self->priv->display_store); |
---|
| 145 | break; |
---|
| 146 | default: |
---|
| 147 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
| 148 | break; |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | static void |
---|
| 153 | gdm_display_factory_class_init (GdmDisplayFactoryClass *klass) |
---|
| 154 | { |
---|
| 155 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
---|
| 156 | |
---|
| 157 | object_class->get_property = gdm_display_factory_get_property; |
---|
| 158 | object_class->set_property = gdm_display_factory_set_property; |
---|
| 159 | object_class->finalize = gdm_display_factory_finalize; |
---|
| 160 | |
---|
| 161 | g_object_class_install_property (object_class, |
---|
| 162 | PROP_DISPLAY_STORE, |
---|
| 163 | g_param_spec_object ("display-store", |
---|
| 164 | "display store", |
---|
| 165 | "display store", |
---|
| 166 | GDM_TYPE_DISPLAY_STORE, |
---|
| 167 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); |
---|
| 168 | |
---|
| 169 | g_type_class_add_private (klass, sizeof (GdmDisplayFactoryPrivate)); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | static void |
---|
| 173 | gdm_display_factory_init (GdmDisplayFactory *factory) |
---|
| 174 | { |
---|
| 175 | factory->priv = GDM_DISPLAY_FACTORY_GET_PRIVATE (factory); |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | static void |
---|
| 179 | gdm_display_factory_finalize (GObject *object) |
---|
| 180 | { |
---|
| 181 | GdmDisplayFactory *factory; |
---|
| 182 | |
---|
| 183 | g_return_if_fail (object != NULL); |
---|
| 184 | g_return_if_fail (GDM_IS_DISPLAY_FACTORY (object)); |
---|
| 185 | |
---|
| 186 | factory = GDM_DISPLAY_FACTORY (object); |
---|
| 187 | |
---|
| 188 | g_return_if_fail (factory->priv != NULL); |
---|
| 189 | |
---|
| 190 | G_OBJECT_CLASS (gdm_display_factory_parent_class)->finalize (object); |
---|
| 191 | } |
---|