| 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-category |
| 24 |
* @short_description: Category object |
| 25 |
* |
| 26 |
* This GObject represents a category in the group system. |
| 27 |
*/ |
| 28 |
|
| 29 |
#include "config.h" |
| 30 |
|
| 31 |
#include <glib-object.h> |
| 32 |
|
| 33 |
#include <packagekit-glib2/pk-category.h> |
| 34 |
|
| 35 |
static void pk_category_finalize (GObject *object); |
| 36 |
|
| 37 |
/** |
| 38 |
* PkCategoryPrivate: |
| 39 |
* |
| 40 |
* Private #PkCategory data |
| 41 |
**/ |
| 42 |
struct _PkCategoryPrivate |
| 43 |
{ |
| 44 |
gchar *parent_id; |
| 45 |
gchar *cat_id; |
| 46 |
gchar *name; |
| 47 |
gchar *summary; |
| 48 |
gchar *icon; |
| 49 |
}; |
| 50 |
|
| 51 |
enum { |
| 52 |
PROP_0, |
| 53 |
PROP_PARENT_ID, |
| 54 |
PROP_CAT_ID, |
| 55 |
PROP_NAME, |
| 56 |
PROP_SUMMARY, |
| 57 |
PROP_ICON, |
| 58 |
PROP_LAST |
| 59 |
}; |
| 60 |
|
| 61 |
static GParamSpec *obj_properties[PROP_LAST] = { NULL, }; |
| 62 |
|
| 63 |
G_DEFINE_TYPE_WITH_PRIVATE (PkCategory, pk_category, PK_TYPE_SOURCE) |
| 64 |
#define GET_PRIVATE(o) (pk_category_get_instance_private (o)) |
| 65 |
|
| 66 |
/** |
| 67 |
* pk_category_get_parent_id: |
| 68 |
* @category: The #PkCategory |
| 69 |
* |
| 70 |
* Gets the parent category id. |
| 71 |
* |
| 72 |
* Returns: (nullable): the string value, or %NULL for unset. |
| 73 |
* |
| 74 |
* Since: 0.6.2 |
| 75 |
**/ |
| 76 |
const gchar * |
| 77 |
pk_category_get_parent_id (PkCategory *category) |
| 78 |
{ |
| 79 |
PkCategoryPrivate *priv = GET_PRIVATE(category); |
| 80 |
|
| 81 |
g_return_val_if_fail (PK_IS_CATEGORY (category), NULL); |
| 82 |
|
| 83 |
return priv->parent_id; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* pk_category_set_parent_id: |
| 88 |
* @category: The #PkCategory |
| 89 |
* @parent_id: the new value |
| 90 |
* |
| 91 |
* Sets the parent category id. |
| 92 |
* |
| 93 |
* Since: 0.6.2 |
| 94 |
**/ |
| 95 |
void |
| 96 |
pk_category_set_parent_id (PkCategory *category, const gchar *parent_id) |
| 97 |
{ |
| 98 |
PkCategoryPrivate *priv = GET_PRIVATE(category); |
| 99 |
|
| 100 |
g_return_if_fail (PK_IS_CATEGORY (category)); |
| 101 |
|
| 102 |
if (g_strcmp0 (priv->parent_id, parent_id) == 0) |
| 103 |
return; |
| 104 |
|
| 105 |
g_free (priv->parent_id); |
| 106 |
priv->parent_id = g_strdup (parent_id); |
| 107 |
g_object_notify_by_pspec (G_OBJECT(category), obj_properties[PROP_PARENT_ID]); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* pk_category_get_id: |
| 112 |
* @category: The #PkCategory |
| 113 |
* |
| 114 |
* Gets the id specific to this category. |
| 115 |
* |
| 116 |
* Returns: (nullable): the string value, or %NULL for unset. |
| 117 |
* |
| 118 |
* Since: 0.6.2 |
| 119 |
**/ |
| 120 |
const gchar * |
| 121 |
pk_category_get_id (PkCategory *category) |
| 122 |
{ |
| 123 |
PkCategoryPrivate *priv = GET_PRIVATE(category); |
| 124 |
|
| 125 |
g_return_val_if_fail (PK_IS_CATEGORY (category), NULL); |
| 126 |
|
| 127 |
return priv->cat_id; |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* pk_category_set_id: |
| 132 |
* @category: The #PkCategory |
| 133 |
* @cat_id: the new value |
| 134 |
* |
| 135 |
* Sets the id specific to this category. |
| 136 |
* |
| 137 |
* Since: 0.6.2 |
| 138 |
**/ |
| 139 |
void |
| 140 |
pk_category_set_id (PkCategory *category, const gchar *cat_id) |
| 141 |
{ |
| 142 |
PkCategoryPrivate *priv = GET_PRIVATE(category); |
| 143 |
|
| 144 |
g_return_if_fail (PK_IS_CATEGORY (category)); |
| 145 |
|
| 146 |
if (g_strcmp0 (priv->cat_id, cat_id) == 0) |
| 147 |
return; |
| 148 |
|
| 149 |
g_free (priv->cat_id); |
| 150 |
priv->cat_id = g_strdup (cat_id); |
| 151 |
g_object_notify_by_pspec (G_OBJECT(category), obj_properties[PROP_CAT_ID]); |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* pk_category_get_name: |
| 156 |
* @category: The #PkCategory |
| 157 |
* |
| 158 |
* Gets the name. |
| 159 |
* |
| 160 |
* Returns: (nullable): the string value, or %NULL for unset. |
| 161 |
* |
| 162 |
* Since: 0.6.2 |
| 163 |
**/ |
| 164 |
const gchar * |
| 165 |
pk_category_get_name (PkCategory *category) |
| 166 |
{ |
| 167 |
PkCategoryPrivate *priv = GET_PRIVATE(category); |
| 168 |
|
| 169 |
g_return_val_if_fail (PK_IS_CATEGORY (category), NULL); |
| 170 |
|
| 171 |
return priv->name; |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* pk_category_set_name: |
| 176 |
* @category: The #PkCategory |
| 177 |
* @name: the new value |
| 178 |
* |
| 179 |
* Sets the name. |
| 180 |
* |
| 181 |
* Since: 0.6.2 |
| 182 |
**/ |
| 183 |
void |
| 184 |
pk_category_set_name (PkCategory *category, const gchar *name) |
| 185 |
{ |
| 186 |
PkCategoryPrivate *priv = GET_PRIVATE(category); |
| 187 |
|
| 188 |
g_return_if_fail (PK_IS_CATEGORY (category)); |
| 189 |
|
| 190 |
if (g_strcmp0 (priv->name, name) == 0) |
| 191 |
return; |
| 192 |
|
| 193 |
g_free (priv->name); |
| 194 |
priv->name = g_strdup (name); |
| 195 |
g_object_notify_by_pspec (G_OBJECT(category), obj_properties[PROP_NAME]); |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* pk_category_get_summary: |
| 200 |
* @category: The #PkCategory |
| 201 |
* |
| 202 |
* Gets the summary. |
| 203 |
* |
| 204 |
* Returns: (nullable): the string value, or %NULL for unset. |
| 205 |
* |
| 206 |
* Since: 0.6.2 |
| 207 |
**/ |
| 208 |
const gchar * |
| 209 |
pk_category_get_summary (PkCategory *category) |
| 210 |
{ |
| 211 |
PkCategoryPrivate *priv = GET_PRIVATE(category); |
| 212 |
|
| 213 |
g_return_val_if_fail (PK_IS_CATEGORY (category), NULL); |
| 214 |
|
| 215 |
return priv->summary; |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* pk_category_set_summary: |
| 220 |
* @category: The #PkCategory |
| 221 |
* @summary: the new value |
| 222 |
* |
| 223 |
* Sets the summary. |
| 224 |
* |
| 225 |
* Since: 0.6.2 |
| 226 |
**/ |
| 227 |
void |
| 228 |
pk_category_set_summary (PkCategory *category, const gchar *summary) |
| 229 |
{ |
| 230 |
PkCategoryPrivate *priv = GET_PRIVATE(category); |
| 231 |
|
| 232 |
g_return_if_fail (PK_IS_CATEGORY (category)); |
| 233 |
|
| 234 |
if (g_strcmp0 (priv->summary, summary) == 0) |
| 235 |
return; |
| 236 |
|
| 237 |
g_free (priv->summary); |
| 238 |
priv->summary = g_strdup (summary); |
| 239 |
g_object_notify_by_pspec (G_OBJECT(category), obj_properties[PROP_SUMMARY]); |
| 240 |
} |
| 241 |
|
| 242 |
/** |
| 243 |
* pk_category_get_icon: |
| 244 |
* @category: The #PkCategory |
| 245 |
* |
| 246 |
* Gets the icon filename. |
| 247 |
* |
| 248 |
* Returns: (nullable): the string value, or %NULL for unset. |
| 249 |
* |
| 250 |
* Since: 0.6.2 |
| 251 |
**/ |
| 252 |
const gchar * |
| 253 |
pk_category_get_icon (PkCategory *category) |
| 254 |
{ |
| 255 |
PkCategoryPrivate *priv = GET_PRIVATE(category); |
| 256 |
|
| 257 |
g_return_val_if_fail (PK_IS_CATEGORY (category), NULL); |
| 258 |
|
| 259 |
return priv->icon; |
| 260 |
} |
| 261 |
|
| 262 |
/** |
| 263 |
* pk_category_set_icon: |
| 264 |
* @category: The #PkCategory |
| 265 |
* @icon: the new value |
| 266 |
* |
| 267 |
* Sets the icon filename. |
| 268 |
* |
| 269 |
* Since: 0.6.2 |
| 270 |
**/ |
| 271 |
void |
| 272 |
pk_category_set_icon (PkCategory *category, const gchar *icon) |
| 273 |
{ |
| 274 |
PkCategoryPrivate *priv = GET_PRIVATE(category); |
| 275 |
|
| 276 |
g_return_if_fail (PK_IS_CATEGORY (category)); |
| 277 |
|
| 278 |
if (g_strcmp0 (priv->icon, icon) == 0) |
| 279 |
return; |
| 280 |
|
| 281 |
g_free (priv->icon); |
| 282 |
priv->icon = g_strdup (icon); |
| 283 |
g_object_notify_by_pspec (G_OBJECT(category), obj_properties[PROP_ICON]); |
| 284 |
} |
| 285 |
|
| 286 |
/* |
| 287 |
* pk_category_get_property: |
| 288 |
**/ |
| 289 |
static void |
| 290 |
pk_category_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) |
| 291 |
{ |
| 292 |
PkCategory *category = PK_CATEGORY (object); |
| 293 |
PkCategoryPrivate *priv = GET_PRIVATE(category); |
| 294 |
|
| 295 |
switch (prop_id) { |
| 296 |
case PROP_PARENT_ID: |
| 297 |
g_value_set_string (value, priv->parent_id); |
| 298 |
break; |
| 299 |
case PROP_CAT_ID: |
| 300 |
g_value_set_string (value, priv->cat_id); |
| 301 |
break; |
| 302 |
case PROP_NAME: |
| 303 |
g_value_set_string (value, priv->name); |
| 304 |
break; |
| 305 |
case PROP_SUMMARY: |
| 306 |
g_value_set_string (value, priv->summary); |
| 307 |
break; |
| 308 |
case PROP_ICON: |
| 309 |
g_value_set_string (value, priv->icon); |
| 310 |
break; |
| 311 |
default: |
| 312 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 313 |
break; |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
/* |
| 318 |
* pk_category_set_property: |
| 319 |
**/ |
| 320 |
static void |
| 321 |
pk_category_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) |
| 322 |
{ |
| 323 |
PkCategory *category = PK_CATEGORY (object); |
| 324 |
|
| 325 |
switch (prop_id) { |
| 326 |
case PROP_PARENT_ID: |
| 327 |
pk_category_set_parent_id (category, g_value_get_string (value)); |
| 328 |
break; |
| 329 |
case PROP_CAT_ID: |
| 330 |
pk_category_set_id (category, g_value_get_string (value)); |
| 331 |
break; |
| 332 |
case PROP_NAME: |
| 333 |
pk_category_set_name (category, g_value_get_string (value)); |
| 334 |
break; |
| 335 |
case PROP_SUMMARY: |
| 336 |
pk_category_set_summary (category, g_value_get_string (value)); |
| 337 |
break; |
| 338 |
case PROP_ICON: |
| 339 |
pk_category_set_icon (category, g_value_get_string (value)); |
| 340 |
break; |
| 341 |
default: |
| 342 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 343 |
break; |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
/* |
| 348 |
* pk_category_class_init: |
| 349 |
**/ |
| 350 |
static void |
| 351 |
pk_category_class_init (PkCategoryClass *klass) |
| 352 |
{ |
| 353 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 354 |
object_class->finalize = pk_category_finalize; |
| 355 |
object_class->get_property = pk_category_get_property; |
| 356 |
object_class->set_property = pk_category_set_property; |
| 357 |
|
| 358 |
/** |
| 359 |
* PkCategory:parent-id: |
| 360 |
* |
| 361 |
* Since: 0.5.4 |
| 362 |
*/ |
| 363 |
obj_properties[PROP_PARENT_ID] = |
| 364 |
g_param_spec_string ("parent-id", NULL, NULL, |
| 365 |
NULL, |
| 366 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); |
| 367 |
|
| 368 |
/** |
| 369 |
* PkCategory:cat-id: |
| 370 |
* |
| 371 |
* Since: 0.5.4 |
| 372 |
*/ |
| 373 |
obj_properties[PROP_CAT_ID] = |
| 374 |
g_param_spec_string ("cat-id", NULL, NULL, |
| 375 |
NULL, |
| 376 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); |
| 377 |
|
| 378 |
/** |
| 379 |
* PkCategory:name: |
| 380 |
* |
| 381 |
* Since: 0.5.4 |
| 382 |
*/ |
| 383 |
obj_properties[PROP_NAME] = |
| 384 |
g_param_spec_string ("name", NULL, NULL, |
| 385 |
NULL, |
| 386 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); |
| 387 |
|
| 388 |
/** |
| 389 |
* PkCategory:summary: |
| 390 |
* |
| 391 |
* Since: 0.5.4 |
| 392 |
*/ |
| 393 |
obj_properties[PROP_SUMMARY] = |
| 394 |
g_param_spec_string ("summary", NULL, NULL, |
| 395 |
NULL, |
| 396 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); |
| 397 |
|
| 398 |
/** |
| 399 |
* PkCategory:icon: |
| 400 |
* |
| 401 |
* Since: 0.5.4 |
| 402 |
*/ |
| 403 |
obj_properties[PROP_ICON] = |
| 404 |
g_param_spec_string ("icon", NULL, NULL, |
| 405 |
NULL, |
| 406 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); |
| 407 |
|
| 408 |
g_object_class_install_properties (object_class, PROP_LAST, obj_properties); |
| 409 |
} |
| 410 |
|
| 411 |
/* |
| 412 |
* pk_category_init: |
| 413 |
**/ |
| 414 |
static void |
| 415 |
pk_category_init (PkCategory *category) |
| 416 |
{ |
| 417 |
category->priv = GET_PRIVATE(category); |
| 418 |
} |
| 419 |
|
| 420 |
/* |
| 421 |
* pk_category_finalize: |
| 422 |
**/ |
| 423 |
static void |
| 424 |
pk_category_finalize (GObject *object) |
| 425 |
{ |
| 426 |
PkCategory *category = PK_CATEGORY (object); |
| 427 |
PkCategoryPrivate *priv = GET_PRIVATE(category); |
| 428 |
|
| 429 |
g_clear_pointer (&priv->parent_id, g_free); |
| 430 |
g_clear_pointer (&priv->cat_id, g_free); |
| 431 |
g_clear_pointer (&priv->name, g_free); |
| 432 |
g_clear_pointer (&priv->summary, g_free); |
| 433 |
g_clear_pointer (&priv->icon, g_free); |
| 434 |
|
| 435 |
G_OBJECT_CLASS (pk_category_parent_class)->finalize (object); |
| 436 |
} |
| 437 |
|
| 438 |
/** |
| 439 |
* pk_category_new: |
| 440 |
* |
| 441 |
* Return value: a new #PkCategory object. |
| 442 |
* |
| 443 |
* Since: 0.5.4 |
| 444 |
**/ |
| 445 |
PkCategory * |
| 446 |
pk_category_new (void) |
| 447 |
{ |
| 448 |
PkCategory *category; |
| 449 |
category = g_object_new (PK_TYPE_CATEGORY, NULL); |
| 450 |
return PK_CATEGORY (category); |
| 451 |
} |