rbpod 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/rbpod/device.c CHANGED
@@ -3,67 +3,78 @@
3
3
  #include "rbpod.h"
4
4
  #include "device.h"
5
5
 
6
- VALUE cRbPodDevice;
7
-
8
- inline VALUE rbpod_device_create(Itdb_Device *device) {
6
+ inline VALUE rbpod_device_create(Itdb_Device *device)
7
+ {
9
8
  return Data_Wrap_Struct(cRbPodDevice, NULL, NULL, (void *) device);
10
9
  }
11
10
 
12
- static VALUE rbpod_device_has_chapter_image_support(VALUE self) {
11
+ static VALUE rbpod_device_chapter_image_support_p(VALUE self)
12
+ {
13
13
  Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
14
14
  return BooleanValue(itdb_device_supports_chapter_image(device));
15
15
  }
16
16
 
17
- static VALUE rbpod_device_has_podcast_support(VALUE self) {
17
+ static VALUE rbpod_device_podcast_support_p(VALUE self)
18
+ {
18
19
  Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
19
20
  return BooleanValue(itdb_device_supports_podcast(device));
20
21
  }
21
22
 
22
- static VALUE rbpod_device_has_artwork_support(VALUE self) {
23
+ static VALUE rbpod_device_artwork_support_p(VALUE self)
24
+ {
23
25
  Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
24
26
  return BooleanValue(itdb_device_supports_artwork(device));
25
27
  }
26
28
 
27
- static VALUE rbpod_device_has_video_support(VALUE self) {
29
+ static VALUE rbpod_device_video_support_p(VALUE self)
30
+ {
28
31
  Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
29
32
  return BooleanValue(itdb_device_supports_video(device));
30
33
  }
31
34
 
32
- static VALUE rbpod_device_has_photo_support(VALUE self) {
35
+ static VALUE rbpod_device_photo_support_p(VALUE self)
36
+ {
33
37
  Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
34
38
  return BooleanValue(itdb_device_supports_photo(device));
35
39
  }
36
40
 
37
- static VALUE rbpod_device_model_name_get(VALUE self) {
41
+ static VALUE rbpod_device_model_name_get(VALUE self)
42
+ {
38
43
  Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
39
44
  const Itdb_IpodInfo *info = itdb_device_get_ipod_info(device);
40
45
  return rb_str_new2(itdb_info_get_ipod_model_name_string(info->ipod_model));
41
46
  }
42
47
 
43
- static VALUE rbpod_device_model_number_get(VALUE self) {
48
+ static VALUE rbpod_device_model_number_get(VALUE self)
49
+ {
44
50
  Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
45
51
  const Itdb_IpodInfo *info = itdb_device_get_ipod_info(device);
46
52
  return rb_str_new2(info->model_number);
47
53
  }
48
54
 
49
- static VALUE rbpod_device_generation_get(VALUE self) {
55
+ static VALUE rbpod_device_generation_get(VALUE self)
56
+ {
50
57
  Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
51
58
  const Itdb_IpodInfo *info = itdb_device_get_ipod_info(device);
52
59
  return rb_str_new2(itdb_info_get_ipod_generation_string(info->ipod_generation));
53
60
  }
54
61
 
55
- static VALUE rbpod_device_capacity_get(VALUE self) {
62
+ static VALUE rbpod_device_capacity_get(VALUE self)
63
+ {
56
64
  Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
57
65
  const Itdb_IpodInfo *info = itdb_device_get_ipod_info(device);
58
66
  return DBL2NUM(info->capacity);
59
67
  }
60
68
 
61
- static VALUE rbpod_device_uuid_get(VALUE self) {
69
+ static VALUE rbpod_device_uuid_get(VALUE self)
70
+ {
62
71
  Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
63
- return rb_str_new2(itdb_device_get_uuid(device));
72
+ const gchar *uuid = itdb_device_get_uuid(device);
73
+ return (uuid == NULL) ? Qnil : rb_str_new2(uuid);
64
74
  }
65
75
 
66
- static VALUE rbpod_device_sysinfo_get(VALUE self, VALUE key) {
76
+ static VALUE rbpod_device_sysinfo_get(VALUE self, VALUE key)
77
+ {
67
78
  Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
68
79
  gchar *value = NULL;
69
80
  VALUE result;
@@ -76,7 +87,8 @@ static VALUE rbpod_device_sysinfo_get(VALUE self, VALUE key) {
76
87
 
77
88
  }
78
89
 
79
- static VALUE rbpod_device_sysinfo_set(VALUE self, VALUE key, VALUE value) {
90
+ static VALUE rbpod_device_sysinfo_set(VALUE self, VALUE key, VALUE value)
91
+ {
80
92
  Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
81
93
  gchar *_value, *_key;
82
94
 
@@ -85,29 +97,42 @@ static VALUE rbpod_device_sysinfo_set(VALUE self, VALUE key, VALUE value) {
85
97
 
86
98
  itdb_device_set_sysinfo(device, _key, _value);
87
99
 
88
- return rbpod_device_sysinfo_get(self, key);
100
+ return Qnil;
89
101
  }
90
102
 
91
- static VALUE rbpod_device_sysinfo_write(VALUE self) {
103
+ static VALUE rbpod_device_sysinfo_save(VALUE self)
104
+ {
92
105
  Itdb_Device *device = TYPED_DATA_PTR(self, Itdb_Device);
93
- /* TODO: Improve error handling. */
94
- return BooleanValue(itdb_device_write_sysinfo(device, NULL));
106
+ GError *error = NULL;
107
+
108
+ if (itdb_device_write_sysinfo(device, &error) == FALSE) {
109
+ return rbpod_raise_error(error);
110
+ }
111
+
112
+ return Qnil;
95
113
  }
96
114
 
97
- static VALUE rbpod_device_initialize(VALUE self) {
115
+ static VALUE rbpod_device_initialize(VALUE self)
116
+ {
98
117
  /* Private method, no setup required yet. */
99
118
  return self;
100
119
  }
101
120
 
102
- static void rbpod_device_deallocate(void *handle) {
121
+ static void rbpod_device_deallocate(void *handle)
122
+ {
103
123
  itdb_device_free((Itdb_Device *) handle);
104
124
  }
105
125
 
106
- static VALUE rbpod_device_allocate(VALUE self) {
126
+ static VALUE rbpod_device_allocate(VALUE self)
127
+ {
107
128
  return Data_Wrap_Struct(cRbPodDevice, NULL, rbpod_device_deallocate, (void *) itdb_device_new());
108
129
  }
109
130
 
110
- void Init_rbpod_device(void) {
131
+ void Init_rbpod_device(void)
132
+ {
133
+ #if RDOC_CAN_PARSE_DOCUMENTATION
134
+ mRbPod = rb_define_module("RbPod");
135
+ #endif
111
136
  cRbPodDevice = rb_define_class_under(mRbPod, "Device", rb_cObject);
112
137
 
113
138
  rb_define_alloc_func(cRbPodDevice, rbpod_device_allocate);
@@ -117,7 +142,7 @@ void Init_rbpod_device(void) {
117
142
 
118
143
  rb_define_method(cRbPodDevice, "[]", rbpod_device_sysinfo_get, 1);
119
144
  rb_define_method(cRbPodDevice, "[]=", rbpod_device_sysinfo_set, 2);
120
- rb_define_method(cRbPodDevice, "save!", rbpod_device_sysinfo_write, 0);
145
+ rb_define_method(cRbPodDevice, "save!", rbpod_device_sysinfo_save, 0);
121
146
 
122
147
  rb_define_method(cRbPodDevice, "uuid", rbpod_device_uuid_get, 0);
123
148
  rb_define_method(cRbPodDevice, "capacity", rbpod_device_capacity_get, 0);
@@ -125,11 +150,11 @@ void Init_rbpod_device(void) {
125
150
  rb_define_method(cRbPodDevice, "model_name", rbpod_device_model_name_get, 0);
126
151
  rb_define_method(cRbPodDevice, "model_number", rbpod_device_model_number_get, 0);
127
152
 
128
- rb_define_method(cRbPodDevice, "supports_photos?", rbpod_device_has_photo_support, 0);
129
- rb_define_method(cRbPodDevice, "supports_videos?", rbpod_device_has_video_support, 0);
130
- rb_define_method(cRbPodDevice, "supports_artwork?", rbpod_device_has_artwork_support, 0);
131
- rb_define_method(cRbPodDevice, "supports_podcasts?", rbpod_device_has_podcast_support, 0);
132
- rb_define_method(cRbPodDevice, "supports_chapter_images?", rbpod_device_has_chapter_image_support, 0);
153
+ rb_define_method(cRbPodDevice, "supports_photos?", rbpod_device_photo_support_p, 0);
154
+ rb_define_method(cRbPodDevice, "supports_videos?", rbpod_device_video_support_p, 0);
155
+ rb_define_method(cRbPodDevice, "supports_artwork?", rbpod_device_artwork_support_p, 0);
156
+ rb_define_method(cRbPodDevice, "supports_podcasts?", rbpod_device_podcast_support_p, 0);
157
+ rb_define_method(cRbPodDevice, "supports_chapter_images?", rbpod_device_chapter_image_support_p, 0);
133
158
 
134
159
  return;
135
160
  }
data/ext/rbpod/device.h CHANGED
@@ -3,7 +3,7 @@
3
3
  #ifndef RBPOD_DEVICE_H
4
4
  #define RBPOD_DEVICE_H
5
5
 
6
- extern VALUE cRbPodDevice;
6
+ RUBY_EXTERN VALUE cRbPodDevice;
7
7
 
8
8
  void Init_rbpod_device(void);
9
9
 
data/ext/rbpod/extconf.rb CHANGED
@@ -4,4 +4,7 @@ require 'mkmf'
4
4
 
5
5
  abort "Please install libgpod-1.0" unless pkg_config('libgpod-1.0')
6
6
 
7
+ # Unfortunately, rdoc isn't capable of a lot of things.
8
+ $defs.push("-DRDOC_CAN_PARSE_DOCUMENTATION=0")
9
+
7
10
  create_makefile('rbpod/rbpod')
data/ext/rbpod/playlist.c CHANGED
@@ -1,86 +1,109 @@
1
1
  /* playlist.c */
2
2
 
3
3
  #include "rbpod.h"
4
- #include "track.h"
5
4
  #include "playlist.h"
6
- #include "collection.h"
5
+ #include "track_collection.h"
7
6
 
8
- VALUE cRbPodPlaylist;
9
- VALUE mRbPodPlaylistCollection;
10
-
11
- inline VALUE rbpod_playlist_collection_create(VALUE parent, GList *items) {
12
- VALUE collection = rbpod_collection_create(items, cRbPodPlaylist);
13
- rb_extend_object(collection, mRbPodPlaylistCollection);
14
- rb_iv_set(collection, "@parent", parent);
15
- return collection;
16
- }
17
-
18
- static VALUE rbpod_playlist_is_podcast(VALUE self) {
7
+ static VALUE rbpod_playlist_podcast_p(VALUE self)
8
+ {
19
9
  Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
20
10
  return BooleanValue(itdb_playlist_is_podcasts(playlist));
21
11
  }
22
12
 
23
- static VALUE rbpod_playlist_is_master(VALUE self) {
13
+ static VALUE rbpod_playlist_master_p(VALUE self)
14
+ {
24
15
  Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
25
16
  return BooleanValue(itdb_playlist_is_mpl(playlist));
26
17
  }
27
18
 
28
- static VALUE rbpod_playlist_is_smart(VALUE self) {
19
+ static VALUE rbpod_playlist_smart_p(VALUE self)
20
+ {
29
21
  Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
30
22
  return BooleanValue(playlist->is_spl);
31
23
  }
32
24
 
33
- static VALUE rbpod_playlist_timestamp_get(VALUE self) {
25
+ static VALUE rbpod_playlist_timestamp_get(VALUE self)
26
+ {
34
27
  Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
35
28
  return rb_funcall(rb_cTime, rb_intern("at"), 1, INT2NUM(playlist->timestamp));
36
29
  }
37
30
 
38
- static VALUE rbpod_playlist_shuffle(VALUE self) {
31
+ static VALUE rbpod_playlist_shuffle(VALUE self)
32
+ {
39
33
  Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
40
34
  itdb_playlist_randomize(playlist);
41
35
  return Qnil;
42
36
  }
43
37
 
44
- static VALUE rbpod_playlist_tracks_get(VALUE self) {
38
+ static VALUE rbpod_playlist_tracks_get(VALUE self)
39
+ {
45
40
  Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
46
41
  return rbpod_track_collection_create(self, playlist->members);
47
42
  }
48
43
 
49
- static VALUE rbpod_playlist_length_get(VALUE self) {
44
+ static VALUE rbpod_playlist_length_get(VALUE self)
45
+ {
50
46
  Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
51
47
  return INT2NUM(itdb_playlist_tracks_number(playlist));
52
48
  }
53
49
 
54
- static VALUE rbpod_playlist_name_get(VALUE self) {
50
+ static VALUE rbpod_playlist_name_get(VALUE self)
51
+ {
55
52
  Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
56
53
  return rb_str_new2(playlist->name);
57
54
  }
58
55
 
59
- static VALUE rbpod_playlist_id_get(VALUE self) {
56
+ static VALUE rbpod_playlist_id_get(VALUE self)
57
+ {
60
58
  Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
61
59
  return INT2NUM(playlist->id);
62
60
  }
63
61
 
64
- static VALUE rbpod_playlist_initialize(VALUE self) {
65
- /* Nothing to intiialize, yet. */
62
+ static VALUE rbpod_playlist_initialize(VALUE self, VALUE playlist_name, VALUE smart_playlist)
63
+ {
64
+ Itdb_Playlist *playlist = TYPED_DATA_PTR(self, Itdb_Playlist);
65
+ gchar *_playlist_name = StringValueCStr(playlist_name);
66
+
67
+ /* Kill off the dummy playlist. */
68
+ itdb_playlist_free(playlist);
69
+
70
+ /* Create a new playlist based on the values provided. */
71
+ playlist = itdb_playlist_new(_playlist_name, (smart_playlist == Qtrue) ? TRUE : FALSE);
72
+
73
+ /* Store the new playlist. */
74
+ DATA_PTR(self) = playlist;
75
+
66
76
  return self;
67
77
  }
68
78
 
69
- static void rbpod_playlist_deallocate(void *handle) {
70
- itdb_playlist_free((Itdb_Playlist *) handle);
79
+ static void rbpod_playlist_deallocate(void *handle)
80
+ {
81
+ Itdb_Playlist *playlist = (Itdb_Playlist *) handle;
82
+
83
+ /* This playlist was unmanaged, so free it manually. */
84
+ if (playlist->itdb == NULL || playlist->id == 0) {
85
+ itdb_playlist_free(playlist);
86
+ }
87
+
88
+ return;
71
89
  }
72
90
 
73
- static VALUE rbpod_playlist_allocate(VALUE self) {
74
- Itdb_Playlist *playlist = itdb_playlist_new("Untitled Playlist", FALSE);
91
+ static VALUE rbpod_playlist_allocate(VALUE self)
92
+ {
93
+ Itdb_Playlist *playlist = itdb_playlist_new("KILROY WAS HERE", FALSE);
75
94
  return Data_Wrap_Struct(cRbPodPlaylist, NULL, rbpod_playlist_deallocate, (void *) playlist);
76
95
  }
77
96
 
78
- void Init_rbpod_playlist(void) {
97
+ void Init_rbpod_playlist(void)
98
+ {
99
+ #if RDOC_CAN_PARSE_DOCUMENTATION
100
+ mRbPod = rb_define_module("RbPod");
101
+ #endif
79
102
  cRbPodPlaylist = rb_define_class_under(mRbPod, "Playlist", rb_cObject);
80
103
 
81
104
  rb_define_alloc_func(cRbPodPlaylist, rbpod_playlist_allocate);
82
105
 
83
- rb_define_method(cRbPodPlaylist, "initialize", rbpod_playlist_initialize, 0);
106
+ rb_define_method(cRbPodPlaylist, "initialize", rbpod_playlist_initialize, 2);
84
107
 
85
108
  rb_define_method(cRbPodPlaylist, "id", rbpod_playlist_id_get, 0);
86
109
  rb_define_method(cRbPodPlaylist, "name", rbpod_playlist_name_get, 0);
@@ -89,11 +112,9 @@ void Init_rbpod_playlist(void) {
89
112
  rb_define_method(cRbPodPlaylist, "shuffle!", rbpod_playlist_shuffle, 0);
90
113
  rb_define_method(cRbPodPlaylist, "created_on", rbpod_playlist_timestamp_get, 0);
91
114
 
92
- rb_define_method(cRbPodPlaylist, "smart_playlist?", rbpod_playlist_is_smart, 0);
93
- rb_define_method(cRbPodPlaylist, "master_playlist?", rbpod_playlist_is_master, 0);
94
- rb_define_method(cRbPodPlaylist, "podcast_playlist?", rbpod_playlist_is_podcast, 0);
95
-
96
- mRbPodPlaylistCollection = rb_define_module_under(cRbPodPlaylist, "Collection");
115
+ rb_define_method(cRbPodPlaylist, "smart_playlist?", rbpod_playlist_smart_p, 0);
116
+ rb_define_method(cRbPodPlaylist, "master_playlist?", rbpod_playlist_master_p, 0);
117
+ rb_define_method(cRbPodPlaylist, "podcast_playlist?", rbpod_playlist_podcast_p, 0);
97
118
 
98
119
  return;
99
120
  }
data/ext/rbpod/playlist.h CHANGED
@@ -3,11 +3,8 @@
3
3
  #ifndef RBPOD_PLAYLIST_H
4
4
  #define RBPOD_PLAYLIST_H
5
5
 
6
- extern VALUE cRbPodPlaylist;
7
- extern VALUE mRbPodPlaylistCollection;
6
+ RUBY_EXTERN VALUE cRbPodPlaylist;
8
7
 
9
8
  void Init_rbpod_playlist(void);
10
9
 
11
- inline VALUE rbpod_playlist_collection_create(VALUE parent, GList *items);
12
-
13
10
  #endif /* RBPOD_PLAYLIST_H */
@@ -0,0 +1,77 @@
1
+ /* playlist_collection.c */
2
+
3
+ #include "rbpod.h"
4
+ #include "playlist.h"
5
+ #include "collection.h"
6
+ #include "playlist_collection.h"
7
+
8
+ static VALUE rbpod_playlist_collection_parent(VALUE self)
9
+ {
10
+ return rb_iv_get(self, "@parent");
11
+ }
12
+
13
+ static VALUE rbpod_playlist_collection_get(VALUE self, VALUE key)
14
+ {
15
+ VALUE parent = rbpod_playlist_collection_parent(self);
16
+ Itdb_iTunesDB *database = TYPED_DATA_PTR(parent, Itdb_iTunesDB);
17
+ Itdb_Playlist *playlist = NULL;
18
+
19
+ switch (TYPE(key)) {
20
+ case T_SYMBOL:
21
+ case T_STRING:
22
+ playlist = itdb_playlist_by_name(database, StringValueCStr(key));
23
+ break;
24
+ case T_FIXNUM:
25
+ playlist = itdb_playlist_by_nr(database, FIX2INT(key));
26
+ break;
27
+ }
28
+
29
+ if (playlist == NULL) {
30
+ return Qnil;
31
+ }
32
+
33
+ return Data_Wrap_Struct(cRbPodPlaylist, NULL, NULL, (void *) playlist);
34
+ }
35
+
36
+ static VALUE rbpod_playlist_collection_podcasts_get(VALUE self)
37
+ {
38
+ VALUE parent = rbpod_playlist_collection_parent(self);
39
+ Itdb_iTunesDB *database = TYPED_DATA_PTR(parent, Itdb_iTunesDB);
40
+ Itdb_Playlist *podcasts = itdb_playlist_podcasts(database);
41
+ return Data_Wrap_Struct(cRbPodPlaylist, NULL, NULL, (void *) podcasts);
42
+ }
43
+
44
+ static VALUE rbpod_playlist_collection_master_get(VALUE self)
45
+ {
46
+ VALUE parent = rbpod_playlist_collection_parent(self);
47
+ Itdb_iTunesDB *database = TYPED_DATA_PTR(parent, Itdb_iTunesDB);
48
+ Itdb_Playlist *master = itdb_playlist_mpl(database);
49
+ return Data_Wrap_Struct(cRbPodPlaylist, NULL, NULL, (void *) master);
50
+ }
51
+
52
+ inline VALUE rbpod_playlist_collection_create(VALUE parent, GList *items)
53
+ {
54
+ VALUE collection = rbpod_collection_create(items, cRbPodPlaylist);
55
+ rb_extend_object(collection, mRbPodPlaylistCollection);
56
+ rb_extend_object(collection, rb_mComparable);
57
+ rb_iv_set(collection, "@parent", parent);
58
+ return collection;
59
+ }
60
+
61
+ void Init_rbpod_playlist_collection(void)
62
+ {
63
+ #if RDOC_CAN_PARSE_DOCUMENTATION
64
+ mRbPod = rb_define_module("RbPod");
65
+ #endif
66
+ mRbPodPlaylistCollection = rb_define_module_under(mRbPod, "PlaylistCollection");
67
+
68
+ rb_define_private_method(mRbPodPlaylistCollection, "parent", rbpod_playlist_collection_parent, 0);
69
+
70
+ rb_define_method(mRbPodPlaylistCollection, "master", rbpod_playlist_collection_master_get, 0);
71
+ rb_define_method(mRbPodPlaylistCollection, "podcasts", rbpod_playlist_collection_podcasts_get, 0);
72
+
73
+ rb_define_method(mRbPodPlaylistCollection, "[]", rbpod_playlist_collection_get, 1);
74
+
75
+ return;
76
+ }
77
+
@@ -0,0 +1,14 @@
1
+ /* playlist_collection.h */
2
+
3
+ #ifndef RBPOD_PLAYLIST_COLLECTION_H
4
+ #define RBPOD_PLAYLIST_COLLECTION_H
5
+
6
+ #include "playlist.h"
7
+
8
+ RUBY_EXTERN VALUE mRbPodPlaylistCollection;
9
+
10
+ void Init_rbpod_playlist_collection(void);
11
+
12
+ inline VALUE rbpod_playlist_collection_create(VALUE parent, GList *items);
13
+
14
+ #endif /* RBPOD_PLAYLIST_COLLECTION_H */
data/ext/rbpod/rbpod.c CHANGED
@@ -6,31 +6,50 @@
6
6
  #include "playlist.h"
7
7
  #include "database.h"
8
8
  #include "collection.h"
9
+ #include "track_collection.h"
10
+ #include "playlist_collection.h"
9
11
 
10
12
  VALUE mRbPod;
11
13
  VALUE eRbPodError;
12
14
 
13
- void Init_rbpod(void) {
14
- /* Set up the top-level RbPod module. */
15
+ VALUE cRbPodDatabase;
16
+ VALUE cRbPodDevice;
17
+
18
+ VALUE cRbPodCollection;
19
+
20
+ VALUE cRbPodPlaylist;
21
+ VALUE mRbPodPlaylistCollection;
22
+
23
+ VALUE cRbPodTrack;
24
+ VALUE mRbPodTrackCollection;
25
+
26
+
27
+ inline VALUE rbpod_raise_error(GError *error)
28
+ {
29
+ VALUE error_message;
30
+
31
+ if (error != NULL) {
32
+ error_message = rb_str_new2(error->message);
33
+ g_error_free(error);
34
+ rb_raise(eRbPodError, "%s", StringValueCStr(error_message));
35
+ }
36
+
37
+ return Qnil;
38
+ }
39
+
40
+ void Init_rbpod(void)
41
+ {
15
42
  mRbPod = rb_define_module("RbPod");
16
43
 
17
- /* Subclass RuntimeError for ourselves. */
18
44
  eRbPodError = rb_define_class_under(mRbPod, "Error", rb_eRuntimeError);
19
45
 
20
- /* Set up the RbPod::Database class. */
21
46
  Init_rbpod_database();
22
-
23
- /* Set up the RbPod::Device class. */
24
47
  Init_rbpod_device();
25
-
26
- /* Set up the RbPod::Collection class. */
27
48
  Init_rbpod_collection();
28
-
29
- /* Set up the RbPod::Playlist class. */
30
49
  Init_rbpod_playlist();
31
-
32
- /* Set up the RbPod::Track class. */
50
+ Init_rbpod_playlist_collection();
33
51
  Init_rbpod_track();
52
+ Init_rbpod_track_collection();
34
53
 
35
54
  return;
36
55
  }
data/ext/rbpod/rbpod.h CHANGED
@@ -10,7 +10,9 @@
10
10
 
11
11
  #define TYPED_DATA_PTR(self, type) ((type *) DATA_PTR(self))
12
12
 
13
- extern VALUE mRbPod;
14
- extern VALUE eRbPodError;
13
+ RUBY_EXTERN VALUE mRbPod;
14
+ RUBY_EXTERN VALUE eRbPodError;
15
+
16
+ inline VALUE rbpod_raise_error(GError *error);
15
17
 
16
18
  #endif /* RBPOD_H */
data/ext/rbpod/track.c CHANGED
@@ -2,68 +2,71 @@
2
2
 
3
3
  #include "rbpod.h"
4
4
  #include "track.h"
5
- #include "collection.h"
6
5
 
7
- VALUE cRbPodTrack;
8
- VALUE mRbPodTrackCollection;
9
-
10
- inline VALUE rbpod_track_collection_create(VALUE parent, GList *items) {
11
- VALUE collection = rbpod_collection_create(items, cRbPodTrack);
12
- rb_extend_object(collection, mRbPodTrackCollection);
13
- rb_iv_set(collection, "@parent", parent);
14
- return collection;
15
- }
16
-
17
- static VALUE rbpod_track_is_transferred(VALUE self) {
6
+ static VALUE rbpod_track_transferred_p(VALUE self)
7
+ {
18
8
  Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
19
9
  return BooleanValue(track->transferred);
20
10
  }
21
11
 
22
- static VALUE rbpod_track_ipod_path_get(VALUE self) {
12
+ static VALUE rbpod_track_ipod_path_get(VALUE self)
13
+ {
23
14
  Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
24
15
  return rb_str_new2(track->ipod_path);
25
16
  }
26
17
 
27
- static VALUE rbpod_track_file_type_get(VALUE self) {
18
+ static VALUE rbpod_track_file_type_get(VALUE self)
19
+ {
28
20
  Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
29
21
  return rb_str_new2(track->filetype);
30
22
  }
31
23
 
32
- static VALUE rbpod_track_artist_get(VALUE self) {
24
+ static VALUE rbpod_track_artist_get(VALUE self)
25
+ {
33
26
  Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
34
27
  return rb_str_new2(track->artist);
35
28
  }
36
29
 
37
- static VALUE rbpod_track_album_get(VALUE self) {
30
+ static VALUE rbpod_track_album_get(VALUE self)
31
+ {
38
32
  Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
39
33
  return rb_str_new2(track->album);
40
34
  }
41
35
 
42
- static VALUE rbpod_track_title_get(VALUE self) {
36
+ static VALUE rbpod_track_title_get(VALUE self)
37
+ {
43
38
  Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
44
39
  return rb_str_new2(track->title);
45
40
  }
46
41
 
47
- static VALUE rbpod_track_id_get(VALUE self) {
42
+ static VALUE rbpod_track_id_get(VALUE self)
43
+ {
48
44
  Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
49
45
  return rb_str_new2(track->filetype);
50
46
  }
51
47
 
52
- static VALUE rbpod_track_initialize(VALUE self) {
48
+ static VALUE rbpod_track_initialize(VALUE self)
49
+ {
53
50
  return self;
54
51
  }
55
52
 
56
- static void rbpod_track_deallocate(void *handle) {
53
+ static void rbpod_track_deallocate(void *handle)
54
+ {
57
55
  itdb_track_free((Itdb_Track *) handle);
58
56
  return;
59
57
  }
60
58
 
61
- static VALUE rbpod_track_allocate(VALUE self) {
59
+ static VALUE rbpod_track_allocate(VALUE self)
60
+ {
62
61
  Itdb_Track *track = itdb_track_new();
63
62
  return Data_Wrap_Struct(cRbPodTrack, NULL, rbpod_track_deallocate, (void *) track);
64
63
  }
65
64
 
66
- void Init_rbpod_track(void) {
65
+ void Init_rbpod_track(void)
66
+ {
67
+ #if RDOC_CAN_PARSE_DOCUMENTATION
68
+ mRbPod = rb_define_module("RbPod");
69
+ #endif
67
70
  cRbPodTrack = rb_define_class_under(mRbPod, "Track", rb_cObject);
68
71
 
69
72
  rb_define_alloc_func(cRbPodTrack, rbpod_track_allocate);
@@ -77,9 +80,7 @@ void Init_rbpod_track(void) {
77
80
  rb_define_method(cRbPodTrack, "file_type", rbpod_track_file_type_get, 0);
78
81
  rb_define_method(cRbPodTrack, "ipod_path", rbpod_track_ipod_path_get, 0);
79
82
 
80
- rb_define_method(cRbPodTrack, "transferred?", rbpod_track_is_transferred, 0);
81
-
82
- mRbPodTrackCollection = rb_define_module_under(cRbPodTrack, "Collection");
83
+ rb_define_method(cRbPodTrack, "transferred?", rbpod_track_transferred_p, 0);
83
84
 
84
85
  return;
85
86
  }
data/ext/rbpod/track.h CHANGED
@@ -3,11 +3,8 @@
3
3
  #ifndef RBPOD_TRACK_H
4
4
  #define RBPOD_TRACK_H
5
5
 
6
- extern VALUE cRbPodTrack;
7
- extern VALUE mRbPodTrackCollection;
6
+ RUBY_EXTERN VALUE cRbPodTrack;
8
7
 
9
8
  void Init_rbpod_track(void);
10
9
 
11
- inline VALUE rbpod_track_collection_create(VALUE parent, GList *items);
12
-
13
10
  #endif /* RBPOD_TRACK_H */
@@ -0,0 +1,33 @@
1
+ /* track_collection.c */
2
+
3
+ #include "rbpod.h"
4
+ #include "track.h"
5
+ #include "collection.h"
6
+ #include "track_collection.h"
7
+
8
+ static VALUE rbpod_track_collection_parent(VALUE self)
9
+ {
10
+ return rb_iv_get(self, "@parent");
11
+ }
12
+
13
+ inline VALUE rbpod_track_collection_create(VALUE parent, GList *items)
14
+ {
15
+ VALUE collection = rbpod_collection_create(items, cRbPodTrack);
16
+ rb_extend_object(collection, mRbPodTrackCollection);
17
+ rb_extend_object(collection, rb_mComparable);
18
+ rb_iv_set(collection, "@parent", parent);
19
+ return collection;
20
+ }
21
+
22
+ void Init_rbpod_track_collection(void)
23
+ {
24
+ #if RDOC_CAN_PARSE_DOCUMENTATION
25
+ mRbPod = rb_define_module("RbPod");
26
+ #endif
27
+ mRbPodTrackCollection = rb_define_module_under(mRbPod, "TrackCollection");
28
+
29
+ rb_define_private_method(mRbPodTrackCollection, "parent", rbpod_track_collection_parent, 0);
30
+
31
+ return;
32
+ }
33
+