| 1 |
/* sysprof-document-metadata.c |
| 2 |
* |
| 3 |
* Copyright 2023 Christian Hergert <[email protected]> |
| 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 3 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, see <http://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
|
| 23 |
#include "sysprof-document-frame-private.h" |
| 24 |
#include "sysprof-document-metadata.h" |
| 25 |
|
| 26 |
struct _SysprofDocumentMetadata |
| 27 |
{ |
| 28 |
SysprofDocumentFrame parent_instance; |
| 29 |
}; |
| 30 |
|
| 31 |
struct _SysprofDocumentMetadataClass |
| 32 |
{ |
| 33 |
SysprofDocumentFrameClass parent_class; |
| 34 |
}; |
| 35 |
|
| 36 |
enum { |
| 37 |
PROP_0, |
| 38 |
PROP_ID, |
| 39 |
PROP_VALUE, |
| 40 |
N_PROPS |
| 41 |
}; |
| 42 |
|
| 43 |
G_DEFINE_FINAL_TYPE (SysprofDocumentMetadata, sysprof_document_metadata, SYSPROF_TYPE_DOCUMENT_FRAME) |
| 44 |
|
| 45 |
static GParamSpec *properties [N_PROPS]; |
| 46 |
|
| 47 |
static void |
| 48 |
sysprof_document_metadata_get_property (GObject *object, |
| 49 |
guint prop_id, |
| 50 |
GValue *value, |
| 51 |
GParamSpec *pspec) |
| 52 |
{ |
| 53 |
SysprofDocumentMetadata *self = SYSPROF_DOCUMENT_METADATA (object); |
| 54 |
|
| 55 |
switch (prop_id) |
| 56 |
{ |
| 57 |
case PROP_ID: |
| 58 |
g_value_set_string (value, sysprof_document_metadata_get_id (self)); |
| 59 |
break; |
| 60 |
|
| 61 |
case PROP_VALUE: |
| 62 |
g_value_set_string (value, sysprof_document_metadata_get_value (self)); |
| 63 |
break; |
| 64 |
|
| 65 |
default: |
| 66 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
static void |
| 71 |
sysprof_document_metadata_class_init (SysprofDocumentMetadataClass *klass) |
| 72 |
{ |
| 73 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 74 |
|
| 75 |
object_class->get_property = sysprof_document_metadata_get_property; |
| 76 |
|
| 77 |
properties [PROP_ID] = |
| 78 |
g_param_spec_string ("id", NULL, NULL, |
| 79 |
NULL, |
| 80 |
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); |
| 81 |
|
| 82 |
properties [PROP_VALUE] = |
| 83 |
g_param_spec_string ("value", NULL, NULL, |
| 84 |
NULL, |
| 85 |
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); |
| 86 |
|
| 87 |
g_object_class_install_properties (object_class, N_PROPS, properties); |
| 88 |
} |
| 89 |
|
| 90 |
static void |
| 91 |
sysprof_document_metadata_init (SysprofDocumentMetadata *self) |
| 92 |
{ |
| 93 |
} |
| 94 |
|
| 95 |
const char * |
| 96 |
sysprof_document_metadata_get_id (SysprofDocumentMetadata *self) |
| 97 |
{ |
| 98 |
const SysprofCaptureMetadata *meta; |
| 99 |
|
| 100 |
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_METADATA (self), 0); |
| 101 |
|
| 102 |
meta = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureMetadata); |
| 103 |
|
| 104 |
return SYSPROF_DOCUMENT_FRAME_CSTRING (self, meta->id); |
| 105 |
} |
| 106 |
|
| 107 |
const char * |
| 108 |
sysprof_document_metadata_get_value (SysprofDocumentMetadata *self) |
| 109 |
{ |
| 110 |
const SysprofCaptureMetadata *meta; |
| 111 |
|
| 112 |
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_METADATA (self), 0); |
| 113 |
|
| 114 |
meta = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureMetadata); |
| 115 |
|
| 116 |
return SYSPROF_DOCUMENT_FRAME_CSTRING (self, meta->metadata); |
| 117 |
} |