rbpod 0.0.6 → 0.0.7

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/track.c CHANGED
@@ -115,7 +115,7 @@ static VALUE rbpod_track_ipod_path_set(VALUE self, VALUE value)
115
115
  gchar *buffer = NULL;
116
116
 
117
117
  if (track->ipod_path != NULL)
118
- g_free(track);
118
+ g_free(track->ipod_path);
119
119
 
120
120
  buffer = g_strdup(new_path);
121
121
 
@@ -202,12 +202,27 @@ static VALUE rbpod_track_mark_unplayed_set(VALUE self, VALUE value)
202
202
 
203
203
  /*
204
204
  * call-seq:
205
- * initialize() -> RbPod::Track
205
+ * initialize(source = nil) -> RbPod::Track
206
206
  *
207
207
  * Creates a detached track. (Not managed by a database.)
208
208
  */
209
- static VALUE rbpod_track_initialize(VALUE self)
209
+ static VALUE rbpod_track_initialize(int argc, VALUE *argv, VALUE self)
210
210
  {
211
+ Itdb_Track *track = TYPED_DATA_PTR(self, Itdb_Track);
212
+ gchar *buffer = NULL;
213
+ VALUE source = Qnil;
214
+
215
+ if (rb_scan_args(argc, argv, "01", &source) == 1) {
216
+ buffer = StringValueCStr(source);
217
+
218
+ if (g_file_test(buffer, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_SYMLINK) == FALSE) {
219
+ rb_raise(eRbPodError, "Invalid Argument: Source must be a path to an existing file.");
220
+ return Qnil;
221
+ }
222
+
223
+ track->userdata = buffer;
224
+ }
225
+
211
226
  return self;
212
227
  }
213
228
 
@@ -226,6 +241,11 @@ static void rbpod_track_deallocate(void *handle)
226
241
  static VALUE rbpod_track_allocate(VALUE self)
227
242
  {
228
243
  Itdb_Track *track = itdb_track_new();
244
+
245
+ track->userdata = NULL;
246
+ track->userdata_destroy = (ItdbUserDataDestroyFunc) g_free;
247
+ track->userdata_duplicate = (ItdbUserDataDuplicateFunc) g_strdup;
248
+
229
249
  return Data_Wrap_Struct(cRbPodTrack, NULL, rbpod_track_deallocate, (void *) track);
230
250
  }
231
251
 
@@ -238,7 +258,7 @@ void Init_rbpod_track(void)
238
258
 
239
259
  rb_define_alloc_func(cRbPodTrack, rbpod_track_allocate);
240
260
 
241
- rb_define_method(cRbPodTrack, "initialize", rbpod_track_initialize, 0);
261
+ rb_define_method(cRbPodTrack, "initialize", rbpod_track_initialize, -1);
242
262
 
243
263
  sMEDIA_TYPE_AUDIO_VIDEO = rb_intern("MEDIA_TYPE_AUDIO_VIDEO");
244
264
  sMEDIA_TYPE_AUDIO = rb_intern("MEDIA_TYPE_AUDIO");
@@ -76,6 +76,7 @@ static VALUE rbpod_track_collection_insert(int argc, VALUE *argv, VALUE self)
76
76
  VALUE track = Qnil, position = Qnil;
77
77
  Itdb_Track *_track = NULL;
78
78
  gint32 _position = 0;
79
+ GError *error = NULL;
79
80
 
80
81
  if (rb_scan_args(argc, argv, "11", &track, &position) < 1) {
81
82
  rb_raise(eRbPodError, "Invalid arguments: Expected >= 1 argument!");
@@ -91,8 +92,27 @@ static VALUE rbpod_track_collection_insert(int argc, VALUE *argv, VALUE self)
91
92
  return Qnil;
92
93
  }
93
94
 
95
+ /* Has this track already been transferred? If so, just add it to the playlist and be done. */
96
+ if (_track->transferred == TRUE) {
97
+ itdb_playlist_add_track(_playlist, _track, _position);
98
+ return Qnil;
99
+ }
100
+
101
+ /* Do we have a source path for this track? */
102
+ if (_track->userdata != NULL && g_file_test(_track->userdata, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_SYMLINK) == FALSE) {
103
+ rb_raise(eRbPodError, "Invalid argument: Cannot add a track without a source file.");
104
+ return Qnil;
105
+ }
106
+
94
107
  itdb_playlist_add_track(_playlist, _track, _position);
95
108
 
109
+ /* Copy the track to the iPod. XXX: Unlock the GVL instead, stupid. */
110
+ if (itdb_cp_track_to_ipod(_track, _track->userdata, &error) == FALSE) {
111
+ itdb_playlist_remove_track(_playlist, _track);
112
+ return rbpod_raise_error(error);
113
+ }
114
+
115
+
96
116
  return Qnil;
97
117
  }
98
118
 
data/lib/rbpod/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RbPod # :nodoc:
2
- VERSION = "0.0.6" # :nodoc:
2
+ VERSION = "0.0.7" # :nodoc:
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbpod
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -164,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  segments:
166
166
  - 0
167
- hash: -656903251
167
+ hash: 696726817
168
168
  required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  none: false
170
170
  requirements:
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  segments:
175
175
  - 0
176
- hash: -656903251
176
+ hash: 696726817
177
177
  requirements:
178
178
  - libgpod-1.0
179
179
  rubyforge_project: