~matttbe/ubuntu/raring/rhythmbox/lp1010619_RB_2.98

« back to all changes in this revision

Viewing changes to plugins/audiocd/sj-metadata.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-11-06 20:52:57 UTC
  • mfrom: (1.1.67) (214.1.1 quantal-proposed)
  • Revision ID: package-import@ubuntu.com-20121106205257-0btjh8jqley153el
Tags: 2.98-0ubuntu1
* New upstream release (LP: #1060601)
* debian/control.in:
  - Bump minimum glib, gtk, totem-plparser, clutter, and clutter-gst
  - Drop no longer needed musicbrainz dependency
* Refreshed 09_keywords.patch
* Updated 11_fix_cd_pausing.patch with fix from git
* Dropped patches applied in new version:
  - 00git_musicbrainz5.patch
  - 08_CVE-2012-3355.patch
  - dont_free_consumed_floating_gvariant.patch
  - git_scale_click.patch
  - git_crash_during_monitor.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * sj-metadata.c
3
 
 * Copyright (C) 2003 Ross Burton <ross@burtonini.com>
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
19
 
 */
20
 
 
21
 
#include "config.h"
22
 
#include <glib-object.h>
23
 
#include <glib/gi18n.h>
24
 
#include <stdlib.h>
25
 
#include <stdio.h>
26
 
 
27
 
#ifndef USE_TOTEM_PL_PARSER
28
 
#include <unistd.h>
29
 
#include <brasero-medium-selection.h>
30
 
#else
31
 
#include <totem-disc.h>
32
 
#endif /* USE_TOTEM_PL_PARSER */
33
 
 
34
 
#include "sj-metadata.h"
35
 
#include "sj-metadata-marshal.h"
36
 
#include "sj-error.h"
37
 
 
38
 
enum {
39
 
  METADATA,
40
 
  LAST_SIGNAL
41
 
};
42
 
 
43
 
static void
44
 
sj_metadata_base_init (gpointer g_iface)
45
 
{
46
 
  static gboolean initialized = FALSE;
47
 
  if (!initialized) {
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));
54
 
 
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));
59
 
 
60
 
    g_object_interface_install_property (g_iface,
61
 
                                         g_param_spec_int ("proxy-port", "proxy-port", NULL,
62
 
                                                           0, G_MAXINT, 0,
63
 
                                                           G_PARAM_READABLE|G_PARAM_WRITABLE|
64
 
                                                           G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
65
 
 
66
 
    initialized = TRUE;
67
 
  }
68
 
}
69
 
 
70
 
GType
71
 
sj_metadata_get_type (void)
72
 
{
73
 
  static GType type = 0;
74
 
  if (type == 0) {
75
 
    static const GTypeInfo info = {
76
 
      sizeof (SjMetadataClass), /* class_size */
77
 
      sj_metadata_base_init,   /* base_init */
78
 
      NULL,           /* base_finalize */
79
 
      NULL,
80
 
      NULL,           /* class_finalize */
81
 
      NULL,           /* class_data */
82
 
      0,
83
 
      0,              /* n_preallocs */
84
 
      NULL,
85
 
      NULL
86
 
    };
87
 
    
88
 
    type = g_type_register_static (G_TYPE_INTERFACE, "SjMetadata", &info, 0);
89
 
    g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
90
 
  }
91
 
  return type;
92
 
}
93
 
 
94
 
void
95
 
sj_metadata_set_cdrom (SjMetadata *metadata, const char* device)
96
 
{
97
 
  g_object_set (metadata, "device", device, NULL);
98
 
}
99
 
 
100
 
void
101
 
sj_metadata_set_proxy (SjMetadata *metadata, const char* proxy)
102
 
{
103
 
  g_object_set (metadata, "proxy-host", proxy, NULL);
104
 
}
105
 
 
106
 
void
107
 
sj_metadata_set_proxy_port (SjMetadata *metadata, const int proxy_port)
108
 
{
109
 
  g_object_set (metadata, "proxy-port", proxy_port, NULL);
110
 
}
111
 
 
112
 
GList *
113
 
sj_metadata_list_albums (SjMetadata *metadata, char **url, GError **error)
114
 
{
115
 
  return SJ_METADATA_GET_CLASS (metadata)->list_albums (metadata, url, error);
116
 
}
117
 
 
118
 
char *
119
 
sj_metadata_helper_scan_disc_number (const char *album_title, int *disc_number)
120
 
{
121
 
  GRegex *disc_regex;
122
 
  GMatchInfo *info;
123
 
  char *new_title;
124
 
  int num;
125
 
 
126
 
  disc_regex = g_regex_new (".+( \\(disc (\\d+).*)", 0, 0, NULL);
127
 
  new_title = NULL;
128
 
  *disc_number = 0;
129
 
 
130
 
  if (g_regex_match (disc_regex, album_title, 0, &info)) {
131
 
    int pos = 0;
132
 
    char *s;
133
 
 
134
 
    g_match_info_fetch_pos (info, 1, &pos, NULL);
135
 
    if (pos) {
136
 
      new_title = g_strndup (album_title, pos);
137
 
    }
138
 
 
139
 
    s = g_match_info_fetch (info, 2);
140
 
    num = atoi (s);
141
 
    *disc_number = num;
142
 
    g_free (s);
143
 
  }
144
 
 
145
 
  g_match_info_free (info);
146
 
  g_regex_unref (disc_regex);
147
 
 
148
 
  return new_title;
149
 
}
150
 
 
151
 
GDate *
152
 
sj_metadata_helper_scan_date (const char *date)
153
 
{
154
 
  int matched, year=1, month=1, day=1;
155
 
 
156
 
  if (date == NULL)
157
 
    return NULL;
158
 
 
159
 
  matched = sscanf (date, "%u-%u-%u", &year, &month, &day);
160
 
  if (matched >= 1) {
161
 
    return g_date_new_dmy ((day == 0) ? 1 : day, (month == 0) ? 1 : month, year);
162
 
  }
163
 
 
164
 
  return NULL;
165
 
}
166
 
 
167
 
gboolean
168
 
sj_metadata_helper_check_media (const char *cdrom, GError **error)
169
 
{
170
 
#ifndef USE_TOTEM_PL_PARSER
171
 
  BraseroMediumMonitor *monitor;
172
 
  BraseroMedium *medium;
173
 
  BraseroDrive *drive;
174
 
 
175
 
 
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
181
 
       */
182
 
      g_set_error (error, SJ_ERROR, SJ_ERROR_CD_BUSY, _("Cannot read CD: %s"),
183
 
                   _("Devices haven't been all probed yet"));
184
 
      return FALSE;
185
 
  }
186
 
  drive = brasero_medium_monitor_get_drive (monitor, cdrom);
187
 
  if (drive == NULL) {
188
 
    return FALSE;
189
 
  }
190
 
 
191
 
  medium = brasero_drive_get_medium (drive);
192
 
  g_object_unref (drive);
193
 
 
194
 
  if (!medium || !BRASERO_MEDIUM_VALID (brasero_medium_get_status (medium))) {
195
 
    char *msg;
196
 
    SjError err;
197
 
 
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;
201
 
    } else {
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;
204
 
    }
205
 
    g_set_error (error, SJ_ERROR, err, _("Cannot read CD: %s"), msg);
206
 
    g_free (msg);
207
 
 
208
 
    return FALSE;
209
 
  }
210
 
#else
211
 
  GError *totem_error = NULL;
212
 
 
213
 
  totem_cd_detect_type (cdrom, &totem_error);
214
 
 
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);
218
 
 
219
 
    return FALSE;
220
 
  }
221
 
#endif /* !USE_TOTEM_PL_PARSER */
222
 
 
223
 
  return TRUE;
224
 
}
225