| 1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- |
| 2 |
* |
| 3 |
* Copyright (C) 2009 Richard Hughes <[email protected]> |
| 4 |
* |
| 5 |
* Licensed under the GNU Lesser General Public License Version 2.1 |
| 6 |
* |
| 7 |
* This library is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2.1 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This library is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this library; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
/** |
| 23 |
* SECTION:pk-repo-detail |
| 24 |
* @short_description: RepoDetail object |
| 25 |
* |
| 26 |
* This GObject represents a repo_detail from a transaction. |
| 27 |
* These objects represent single items of data from the transaction, and are |
| 28 |
* often present in lists (#PkResults) or just refcounted in client programs. |
| 29 |
*/ |
| 30 |
|
| 31 |
#include "config.h" |
| 32 |
|
| 33 |
#include <glib-object.h> |
| 34 |
|
| 35 |
#include <packagekit-glib2/pk-repo-detail.h> |
| 36 |
|
| 37 |
static void pk_repo_detail_finalize (GObject *object); |
| 38 |
|
| 39 |
/** |
| 40 |
* PkRepoDetailPrivate: |
| 41 |
* |
| 42 |
* Private #PkRepoDetail data |
| 43 |
**/ |
| 44 |
struct _PkRepoDetailPrivate |
| 45 |
{ |
| 46 |
gchar *repo_id; |
| 47 |
gchar *description; |
| 48 |
gboolean enabled; |
| 49 |
}; |
| 50 |
|
| 51 |
enum { |
| 52 |
PROP_0, |
| 53 |
PROP_REPO_ID, |
| 54 |
PROP_DESCRIPTION, |
| 55 |
PROP_ENABLED, |
| 56 |
PROP_LAST |
| 57 |
}; |
| 58 |
|
| 59 |
G_DEFINE_TYPE_WITH_PRIVATE (PkRepoDetail, pk_repo_detail, PK_TYPE_SOURCE) |
| 60 |
#define GET_PRIVATE(o) (pk_repo_detail_get_instance_private (o)) |
| 61 |
|
| 62 |
/** |
| 63 |
* pk_repo_detail_get_id: |
| 64 |
* @repo_detail: a valid #PkRepoDetail instance |
| 65 |
* |
| 66 |
* Gets the repository ID. |
| 67 |
* |
| 68 |
* Return value: string ID, e.g. "fedora" |
| 69 |
* |
| 70 |
* Since: 0.9.1 |
| 71 |
**/ |
| 72 |
const gchar * |
| 73 |
pk_repo_detail_get_id (PkRepoDetail *repo_detail) |
| 74 |
{ |
| 75 |
PkRepoDetailPrivate *priv = GET_PRIVATE(repo_detail); |
| 76 |
|
| 77 |
g_return_val_if_fail (PK_IS_REPO_DETAIL (repo_detail), NULL); |
| 78 |
|
| 79 |
return priv->repo_id; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* pk_repo_detail_get_description: |
| 84 |
* @repo_detail: a valid #PkRepoDetail instance |
| 85 |
* |
| 86 |
* Gets the repository description. |
| 87 |
* |
| 88 |
* Return value: string ID, e.g. "Fedora 20 - i386" |
| 89 |
* |
| 90 |
* Since: 0.9.1 |
| 91 |
**/ |
| 92 |
const gchar * |
| 93 |
pk_repo_detail_get_description (PkRepoDetail *repo_detail) |
| 94 |
{ |
| 95 |
PkRepoDetailPrivate *priv = GET_PRIVATE(repo_detail); |
| 96 |
|
| 97 |
g_return_val_if_fail (PK_IS_REPO_DETAIL (repo_detail), NULL); |
| 98 |
|
| 99 |
return priv->description; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* pk_repo_detail_get_enabled: |
| 104 |
* @repo_detail: a valid #PkRepoDetail instance |
| 105 |
* |
| 106 |
* Gets the repository enabled status. |
| 107 |
* |
| 108 |
* Return value: %TRUE for enabled |
| 109 |
* |
| 110 |
* Since: 0.9.1 |
| 111 |
**/ |
| 112 |
gboolean |
| 113 |
pk_repo_detail_get_enabled (PkRepoDetail *repo_detail) |
| 114 |
{ |
| 115 |
PkRepoDetailPrivate *priv = GET_PRIVATE(repo_detail); |
| 116 |
|
| 117 |
g_return_val_if_fail (PK_IS_REPO_DETAIL (repo_detail), FALSE); |
| 118 |
|
| 119 |
return priv->enabled; |
| 120 |
} |
| 121 |
|
| 122 |
/* |
| 123 |
* pk_repo_detail_get_property: |
| 124 |
**/ |
| 125 |
static void |
| 126 |
pk_repo_detail_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) |
| 127 |
{ |
| 128 |
PkRepoDetail *repo_detail = PK_REPO_DETAIL (object); |
| 129 |
PkRepoDetailPrivate *priv = GET_PRIVATE(repo_detail); |
| 130 |
|
| 131 |
switch (prop_id) { |
| 132 |
case PROP_REPO_ID: |
| 133 |
g_value_set_string (value, priv->repo_id); |
| 134 |
break; |
| 135 |
case PROP_DESCRIPTION: |
| 136 |
g_value_set_string (value, priv->description); |
| 137 |
break; |
| 138 |
case PROP_ENABLED: |
| 139 |
g_value_set_boolean (value, priv->enabled); |
| 140 |
break; |
| 141 |
default: |
| 142 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 143 |
break; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
/* |
| 148 |
* pk_repo_detail_set_property: |
| 149 |
**/ |
| 150 |
static void |
| 151 |
pk_repo_detail_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) |
| 152 |
{ |
| 153 |
PkRepoDetail *repo_detail = PK_REPO_DETAIL (object); |
| 154 |
PkRepoDetailPrivate *priv = GET_PRIVATE(repo_detail); |
| 155 |
|
| 156 |
switch (prop_id) { |
| 157 |
case PROP_REPO_ID: |
| 158 |
g_free (priv->repo_id); |
| 159 |
priv->repo_id = g_value_dup_string (value); |
| 160 |
break; |
| 161 |
case PROP_DESCRIPTION: |
| 162 |
g_free (priv->description); |
| 163 |
priv->description = g_value_dup_string (value); |
| 164 |
break; |
| 165 |
case PROP_ENABLED: |
| 166 |
priv->enabled = g_value_get_boolean (value); |
| 167 |
break; |
| 168 |
default: |
| 169 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 170 |
break; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
/* |
| 175 |
* pk_repo_detail_class_init: |
| 176 |
**/ |
| 177 |
static void |
| 178 |
pk_repo_detail_class_init (PkRepoDetailClass *klass) |
| 179 |
{ |
| 180 |
GParamSpec *pspec; |
| 181 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 182 |
object_class->finalize = pk_repo_detail_finalize; |
| 183 |
object_class->get_property = pk_repo_detail_get_property; |
| 184 |
object_class->set_property = pk_repo_detail_set_property; |
| 185 |
|
| 186 |
/** |
| 187 |
* PkRepoDetail:repo-id: |
| 188 |
* |
| 189 |
* Since: 0.5.4 |
| 190 |
*/ |
| 191 |
pspec = g_param_spec_string ("repo-id", NULL, NULL, |
| 192 |
NULL, |
| 193 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
| 194 |
g_object_class_install_property (object_class, PROP_REPO_ID, pspec); |
| 195 |
|
| 196 |
/** |
| 197 |
* PkRepoDetail:description: |
| 198 |
* |
| 199 |
* Since: 0.5.4 |
| 200 |
*/ |
| 201 |
pspec = g_param_spec_string ("description", NULL, NULL, |
| 202 |
NULL, |
| 203 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
| 204 |
g_object_class_install_property (object_class, PROP_DESCRIPTION, pspec); |
| 205 |
|
| 206 |
/** |
| 207 |
* PkRepoDetail:enabled: |
| 208 |
* |
| 209 |
* Since: 0.5.4 |
| 210 |
*/ |
| 211 |
pspec = g_param_spec_boolean ("enabled", NULL, NULL, |
| 212 |
FALSE, |
| 213 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
| 214 |
g_object_class_install_property (object_class, PROP_ENABLED, pspec); |
| 215 |
} |
| 216 |
|
| 217 |
/* |
| 218 |
* pk_repo_detail_init: |
| 219 |
**/ |
| 220 |
static void |
| 221 |
pk_repo_detail_init (PkRepoDetail *repo_detail) |
| 222 |
{ |
| 223 |
repo_detail->priv = GET_PRIVATE(repo_detail); |
| 224 |
} |
| 225 |
|
| 226 |
/* |
| 227 |
* pk_repo_detail_finalize: |
| 228 |
**/ |
| 229 |
static void |
| 230 |
pk_repo_detail_finalize (GObject *object) |
| 231 |
{ |
| 232 |
PkRepoDetail *repo_detail = PK_REPO_DETAIL (object); |
| 233 |
PkRepoDetailPrivate *priv = GET_PRIVATE(repo_detail); |
| 234 |
|
| 235 |
g_clear_pointer (&priv->repo_id, g_free); |
| 236 |
g_clear_pointer (&priv->description, g_free); |
| 237 |
|
| 238 |
G_OBJECT_CLASS (pk_repo_detail_parent_class)->finalize (object); |
| 239 |
} |
| 240 |
|
| 241 |
/** |
| 242 |
* pk_repo_detail_new: |
| 243 |
* |
| 244 |
* Return value: a new #PkRepoDetail object. |
| 245 |
* |
| 246 |
* Since: 0.5.4 |
| 247 |
**/ |
| 248 |
PkRepoDetail * |
| 249 |
pk_repo_detail_new (void) |
| 250 |
{ |
| 251 |
PkRepoDetail *repo_detail; |
| 252 |
repo_detail = g_object_new (PK_TYPE_REPO_DETAIL, NULL); |
| 253 |
return PK_REPO_DETAIL (repo_detail); |
| 254 |
} |