3
* Copyright (C) 2003 Ross Burton <ross@burtonini.com>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library 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 GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public
16
* License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
22
#include <glib-object.h>
23
#include <glib/gi18n.h>
27
#ifndef USE_TOTEM_PL_PARSER
29
#include <brasero-medium-selection.h>
31
#include <totem-disc.h>
32
#endif /* USE_TOTEM_PL_PARSER */
34
#include "sj-metadata.h"
35
#include "sj-metadata-marshal.h"
44
sj_metadata_base_init (gpointer g_iface)
46
static gboolean initialized = FALSE;
48
/* TODO: make these constructors */
49
/* TODO: add nice nick and blurb strings */
50
g_object_interface_install_property (g_iface,
51
g_param_spec_string ("device", "device", NULL, NULL,
52
G_PARAM_READABLE|G_PARAM_WRITABLE|
53
G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
55
g_object_interface_install_property (g_iface,
56
g_param_spec_string ("proxy-host", "proxy-host", NULL, NULL,
57
G_PARAM_READABLE|G_PARAM_WRITABLE|
58
G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
60
g_object_interface_install_property (g_iface,
61
g_param_spec_int ("proxy-port", "proxy-port", NULL,
63
G_PARAM_READABLE|G_PARAM_WRITABLE|
64
G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
71
sj_metadata_get_type (void)
73
static GType type = 0;
75
static const GTypeInfo info = {
76
sizeof (SjMetadataClass), /* class_size */
77
sj_metadata_base_init, /* base_init */
78
NULL, /* base_finalize */
80
NULL, /* class_finalize */
81
NULL, /* class_data */
88
type = g_type_register_static (G_TYPE_INTERFACE, "SjMetadata", &info, 0);
89
g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
95
sj_metadata_set_cdrom (SjMetadata *metadata, const char* device)
97
g_object_set (metadata, "device", device, NULL);
101
sj_metadata_set_proxy (SjMetadata *metadata, const char* proxy)
103
g_object_set (metadata, "proxy-host", proxy, NULL);
107
sj_metadata_set_proxy_port (SjMetadata *metadata, const int proxy_port)
109
g_object_set (metadata, "proxy-port", proxy_port, NULL);
113
sj_metadata_list_albums (SjMetadata *metadata, char **url, GError **error)
115
return SJ_METADATA_GET_CLASS (metadata)->list_albums (metadata, url, error);
119
sj_metadata_helper_scan_disc_number (const char *album_title, int *disc_number)
126
disc_regex = g_regex_new (".+( \\(disc (\\d+).*)", 0, 0, NULL);
130
if (g_regex_match (disc_regex, album_title, 0, &info)) {
134
g_match_info_fetch_pos (info, 1, &pos, NULL);
136
new_title = g_strndup (album_title, pos);
139
s = g_match_info_fetch (info, 2);
145
g_match_info_free (info);
146
g_regex_unref (disc_regex);
152
sj_metadata_helper_scan_date (const char *date)
154
int matched, year=1, month=1, day=1;
159
matched = sscanf (date, "%u-%u-%u", &year, &month, &day);
161
return g_date_new_dmy ((day == 0) ? 1 : day, (month == 0) ? 1 : month, year);
168
sj_metadata_helper_check_media (const char *cdrom, GError **error)
170
#ifndef USE_TOTEM_PL_PARSER
171
BraseroMediumMonitor *monitor;
172
BraseroMedium *medium;
176
/* This initialize the library if it isn't done yet */
177
monitor = brasero_medium_monitor_get_default ();
178
if (brasero_medium_monitor_is_probing (monitor)) {
179
/* FIXME: would be nicer to only check if "cdrom" is being probed,
180
* but libbrasero doesn't seem to have an API for that
182
g_set_error (error, SJ_ERROR, SJ_ERROR_CD_BUSY, _("Cannot read CD: %s"),
183
_("Devices haven't been all probed yet"));
186
drive = brasero_medium_monitor_get_drive (monitor, cdrom);
191
medium = brasero_drive_get_medium (drive);
192
g_object_unref (drive);
194
if (!medium || !BRASERO_MEDIUM_VALID (brasero_medium_get_status (medium))) {
198
if (access (cdrom, W_OK) == 0) {
199
msg = g_strdup_printf (_("Device '%s' does not contain any media"), cdrom);
200
err = SJ_ERROR_CD_NO_MEDIA;
202
msg = g_strdup_printf (_("Device '%s' could not be opened. Check the access permissions on the device."), cdrom);
203
err = SJ_ERROR_CD_PERMISSION_ERROR;
205
g_set_error (error, SJ_ERROR, err, _("Cannot read CD: %s"), msg);
211
GError *totem_error = NULL;
213
totem_cd_detect_type (cdrom, &totem_error);
215
if (totem_error != NULL) {
216
g_set_error (error, SJ_ERROR, SJ_ERROR_CD_NO_MEDIA, _("Cannot read CD: %s"), totem_error->message);
217
g_error_free (totem_error);
221
#endif /* !USE_TOTEM_PL_PARSER */