| 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-files |
| 24 |
* @short_description: Files object |
| 25 |
* |
| 26 |
* This GObject represents a files 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-files.h> |
| 36 |
|
| 37 |
static void pk_files_finalize (GObject *object); |
| 38 |
|
| 39 |
/** |
| 40 |
* PkFilesPrivate: |
| 41 |
* |
| 42 |
* Private #PkFiles data |
| 43 |
**/ |
| 44 |
struct _PkFilesPrivate |
| 45 |
{ |
| 46 |
gchar *package_id; |
| 47 |
gchar **files; |
| 48 |
}; |
| 49 |
|
| 50 |
enum { |
| 51 |
PROP_0, |
| 52 |
PROP_PACKAGE_ID, |
| 53 |
PROP_FILES, |
| 54 |
PROP_LAST |
| 55 |
}; |
| 56 |
|
| 57 |
G_DEFINE_TYPE_WITH_PRIVATE (PkFiles, pk_files, PK_TYPE_SOURCE) |
| 58 |
#define GET_PRIVATE(o) (pk_files_get_instance_private (o)) |
| 59 |
|
| 60 |
/** |
| 61 |
* pk_files_get_package_id: |
| 62 |
* @files: a valid #PkFiles instance |
| 63 |
* |
| 64 |
* Gets the package-id |
| 65 |
* |
| 66 |
* Return value: Gets the package_id for the files object |
| 67 |
* |
| 68 |
* Since: 0.9.1 |
| 69 |
**/ |
| 70 |
const gchar * |
| 71 |
pk_files_get_package_id (PkFiles *files) |
| 72 |
{ |
| 73 |
PkFilesPrivate *priv = GET_PRIVATE(files); |
| 74 |
|
| 75 |
g_return_val_if_fail (PK_IS_FILES (files), NULL); |
| 76 |
|
| 77 |
return priv->package_id; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* pk_files_get_files: |
| 82 |
* @files: a valid #PkFiles instance |
| 83 |
* |
| 84 |
* Gets the file list |
| 85 |
* |
| 86 |
* Return value: (transfer none): Gets the file list for the files object |
| 87 |
* |
| 88 |
* Since: 0.9.1 |
| 89 |
**/ |
| 90 |
gchar ** |
| 91 |
pk_files_get_files (PkFiles *files) |
| 92 |
{ |
| 93 |
PkFilesPrivate *priv = GET_PRIVATE(files); |
| 94 |
|
| 95 |
g_return_val_if_fail (PK_IS_FILES (files), NULL); |
| 96 |
|
| 97 |
return priv->files; |
| 98 |
} |
| 99 |
|
| 100 |
/* |
| 101 |
* pk_files_get_property: |
| 102 |
**/ |
| 103 |
static void |
| 104 |
pk_files_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) |
| 105 |
{ |
| 106 |
PkFiles *files = PK_FILES (object); |
| 107 |
PkFilesPrivate *priv = GET_PRIVATE(files); |
| 108 |
|
| 109 |
switch (prop_id) { |
| 110 |
case PROP_PACKAGE_ID: |
| 111 |
g_value_set_string (value, priv->package_id); |
| 112 |
break; |
| 113 |
case PROP_FILES: |
| 114 |
g_value_set_boxed (value, priv->files); |
| 115 |
break; |
| 116 |
default: |
| 117 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 118 |
break; |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
/* |
| 123 |
* pk_files_set_property: |
| 124 |
**/ |
| 125 |
static void |
| 126 |
pk_files_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) |
| 127 |
{ |
| 128 |
PkFiles *files = PK_FILES (object); |
| 129 |
PkFilesPrivate *priv = GET_PRIVATE(files); |
| 130 |
|
| 131 |
switch (prop_id) { |
| 132 |
case PROP_PACKAGE_ID: |
| 133 |
g_free (priv->package_id); |
| 134 |
priv->package_id = g_value_dup_string (value); |
| 135 |
break; |
| 136 |
case PROP_FILES: |
| 137 |
if (priv->files != NULL) |
| 138 |
g_strfreev (priv->files); |
| 139 |
priv->files = g_value_dup_boxed (value); |
| 140 |
break; |
| 141 |
default: |
| 142 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 143 |
break; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
/* |
| 148 |
* pk_files_class_init: |
| 149 |
**/ |
| 150 |
static void |
| 151 |
pk_files_class_init (PkFilesClass *klass) |
| 152 |
{ |
| 153 |
GParamSpec *pspec; |
| 154 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 155 |
object_class->finalize = pk_files_finalize; |
| 156 |
object_class->get_property = pk_files_get_property; |
| 157 |
object_class->set_property = pk_files_set_property; |
| 158 |
|
| 159 |
/** |
| 160 |
* PkFiles:package-id: |
| 161 |
* |
| 162 |
* Since: 0.5.4 |
| 163 |
*/ |
| 164 |
pspec = g_param_spec_string ("package-id", NULL, NULL, |
| 165 |
NULL, |
| 166 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
| 167 |
g_object_class_install_property (object_class, PROP_PACKAGE_ID, pspec); |
| 168 |
|
| 169 |
/** |
| 170 |
* PkFiles:files: |
| 171 |
* |
| 172 |
* Since: 0.5.4 |
| 173 |
*/ |
| 174 |
pspec = g_param_spec_boxed ("files", NULL, NULL, |
| 175 |
G_TYPE_STRV, |
| 176 |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); |
| 177 |
g_object_class_install_property (object_class, PROP_FILES, pspec); |
| 178 |
} |
| 179 |
|
| 180 |
/* |
| 181 |
* pk_files_init: |
| 182 |
**/ |
| 183 |
static void |
| 184 |
pk_files_init (PkFiles *files) |
| 185 |
{ |
| 186 |
} |
| 187 |
|
| 188 |
/* |
| 189 |
* pk_files_finalize: |
| 190 |
**/ |
| 191 |
static void |
| 192 |
pk_files_finalize (GObject *object) |
| 193 |
{ |
| 194 |
PkFiles *files = PK_FILES (object); |
| 195 |
PkFilesPrivate *priv = GET_PRIVATE(files); |
| 196 |
|
| 197 |
g_clear_pointer (&priv->package_id, g_free); |
| 198 |
g_clear_pointer (&priv->files, g_strfreev); |
| 199 |
|
| 200 |
G_OBJECT_CLASS (pk_files_parent_class)->finalize (object); |
| 201 |
} |
| 202 |
|
| 203 |
/** |
| 204 |
* pk_files_new: |
| 205 |
* |
| 206 |
* Return value: a new #PkFiles object. |
| 207 |
* |
| 208 |
* Since: 0.5.4 |
| 209 |
**/ |
| 210 |
PkFiles * |
| 211 |
pk_files_new (void) |
| 212 |
{ |
| 213 |
PkFiles *files; |
| 214 |
files = g_object_new (PK_TYPE_FILES, NULL); |
| 215 |
return PK_FILES (files); |
| 216 |
} |