Coverage Report

Created: 2026-07-25 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pidgin/libpurple/sound-theme-loader.c
Line
Count
Source
1
/*
2
 * SoundThemeLoader for libpurple
3
 *
4
 * Pidgin is the legal property of its developers, whose names are too numerous
5
 * to list here.  Please refer to the COPYRIGHT file distributed with this
6
 * source distribution.
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 2 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
21
 */
22
23
#include "internal.h"
24
#include "sound-theme-loader.h"
25
#include "sound-theme.h"
26
#include "util.h"
27
#include "xmlnode.h"
28
#include "debug.h"
29
30
/*****************************************************************************
31
 * Sound Theme Builder
32
 *****************************************************************************/
33
34
static PurpleTheme *
35
purple_sound_loader_build(const gchar *dir)
36
0
{
37
0
  xmlnode *root_node = NULL, *sub_node;
38
0
  gchar *filename_full, *data = NULL;
39
0
  PurpleSoundTheme *theme = NULL;
40
0
  const gchar *name;
41
42
  /* Find the theme file */
43
0
  g_return_val_if_fail(dir != NULL, NULL);
44
0
  filename_full = g_build_filename(dir, "theme.xml", NULL);
45
46
0
  if (g_file_test(filename_full, G_FILE_TEST_IS_REGULAR))
47
0
    root_node = xmlnode_from_file(dir, "theme.xml", "sound themes", "sound-theme-loader");
48
49
0
  g_free(filename_full);
50
0
  if (root_node == NULL)
51
0
    return NULL;
52
53
0
  name = xmlnode_get_attrib(root_node, "name");
54
55
0
  if (name && purple_strequal(xmlnode_get_attrib(root_node, "type"), "sound")) {
56
    /* Parse the tree */
57
0
    sub_node = xmlnode_get_child(root_node, "description");
58
0
    data = xmlnode_get_data(sub_node);
59
60
0
    if (xmlnode_get_attrib(root_node, "name") != NULL) {
61
0
      theme = g_object_new(PURPLE_TYPE_SOUND_THEME,
62
0
          "type", "sound",
63
0
          "name", name,
64
0
          "author", xmlnode_get_attrib(root_node, "author"),
65
0
          "image", xmlnode_get_attrib(root_node, "image"),
66
0
          "directory", dir,
67
0
          "description", data, NULL);
68
69
0
      sub_node = xmlnode_get_child(root_node, "event");
70
71
0
      while (sub_node) {
72
0
        purple_sound_theme_set_file(theme,
73
0
            xmlnode_get_attrib(sub_node, "name"),
74
0
            xmlnode_get_attrib(sub_node, "file"));
75
0
        sub_node = xmlnode_get_next_twin(sub_node);
76
0
      }
77
0
    }
78
0
  } else purple_debug_warning("sound-theme-loader", "Missing attribute or problem with the root element\n");
79
80
0
  xmlnode_free(root_node);
81
0
  g_free(data);
82
0
  return PURPLE_THEME(theme);
83
0
}
84
85
/******************************************************************************
86
 * GObject Stuff
87
 *****************************************************************************/
88
89
static void
90
purple_sound_theme_loader_class_init(PurpleSoundThemeLoaderClass *klass)
91
0
{
92
0
  PurpleThemeLoaderClass *loader_klass = PURPLE_THEME_LOADER_CLASS(klass);
93
94
0
  loader_klass->purple_theme_loader_build = purple_sound_loader_build;
95
0
}
96
97
GType
98
purple_sound_theme_loader_get_type(void)
99
0
{
100
0
  static GType type = 0;
101
0
  if (type == 0) {
102
0
    static const GTypeInfo info = {
103
0
      sizeof(PurpleSoundThemeLoaderClass),
104
0
      NULL, /* base_init */
105
0
      NULL, /* base_finalize */
106
0
      (GClassInitFunc)purple_sound_theme_loader_class_init, /* class_init */
107
0
      NULL, /* class_finalize */
108
0
      NULL, /* class_data */
109
0
      sizeof(PurpleSoundThemeLoader),
110
0
      0, /* n_preallocs */
111
0
      NULL, /* instance_init */
112
0
      NULL, /* value table */
113
0
    };
114
0
    type = g_type_register_static(PURPLE_TYPE_THEME_LOADER,
115
0
        "PurpleSoundThemeLoader", &info, 0);
116
0
  }
117
0
  return type;
118
0
}