Class: RbPod::Database
- Inherits:
-
Object
- Object
- RbPod::Database
- Defined in:
- ext/rbpod/database.c
Class Method Summary collapse
Instance Method Summary collapse
- #device ⇒ Object
- #filename ⇒ Object
- #id ⇒ Object
- #initialize(mount_point) ⇒ Object constructor
- #mountpoint ⇒ Object
- #mountpoint=(path) ⇒ Object
- #playlists ⇒ Object
- #save! ⇒ Object
- #synchronized? ⇒ Boolean
- #tracks ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(mount_point) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'ext/rbpod/database.c', line 86 static VALUE rbpod_database_initialize(VALUE self, VALUE mount_point) { Itdb_iTunesDB *database = TYPED_DATA_PTR(self, Itdb_iTunesDB); Itdb_iTunesDB *previous = database; GError *error = NULL; /* Try to parse the database from the given mount point. */ database = itdb_parse(StringValueCStr(mount_point), &error); if (database == NULL) { return rbpod_raise_error(error); } /* Overwrite our old database with the new one. */ DATA_PTR(self) = database; /* Free the old one. */ itdb_free(previous); return self; } |
Class Method Details
.create!(*args) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'ext/rbpod/database.c', line 114 static VALUE rbpod_database_create(int argc, VALUE *argv, VALUE self) { VALUE mount_point, device_name, model_number, instance; gchar *_mount_point, *_device_name, *_model_number; GDir *directory = NULL; GError *error = NULL; if (rb_scan_args(argc, argv, "12", &mount_point, &device_name, &model_number) < 1) { rb_raise(eRbPodError, "Invalid arguments."); return Qnil; } /* Reject the mount point immediately if it isn't a string. */ if (TYPE(mount_point) != T_STRING && RSTRING_LEN(mount_point) > 0) { rb_raise(eRbPodError, "Mount point must be a non-empty string."); return Qnil; } /* If we didn't specify a device name, default to 'iPod'. */ if (NIL_P(device_name) == TRUE) { device_name = rb_str_new2("iPod"); } /* If the specified device name isn't a string of at least three characters, bail now. */ if (TYPE(device_name) != T_STRING || RSTRING_LEN(device_name) < 3) { rb_raise(eRbPodError, "Device name should be a string of at least three characters."); return Qnil; } /* If the specified model number is specified but isn't a string, bail now. TODO: Use a regexp, stupid. */ if (NIL_P(model_number) == FALSE && (TYPE(model_number) != T_STRING || RSTRING_LEN(model_number) < 4)) { rb_raise(eRbPodError, "Model number should be a string of at least four characters."); return Qnil; } /* Extract pointers for glib use. */ _mount_point = StringValueCStr(mount_point); _device_name = StringValueCStr(device_name); /* GPod can function with a NULL model number, however, artwork may not function properly. */ _model_number = !NIL_P(model_number) ? StringValueCStr(model_number) : NULL; /* Check if the mount point is a directory. */ directory = g_dir_open(_mount_point, 0, &error); if (directory == NULL) { return rbpod_raise_error(error); } /* Glib seems to think so... */ g_dir_close(directory); /* Initialize the iPod at this mount point, with this device name and model number. */ if (itdb_init_ipod(_mount_point, _model_number, _device_name, &error) == FALSE) { return rbpod_raise_error(error); } instance = rbpod_database_allocate(cRbPodDatabase); /* Return an instance of this class using the newly created database. */ return rbpod_database_initialize(instance, mount_point); } |
Instance Method Details
#device ⇒ Object
43 44 45 46 47 |
# File 'ext/rbpod/database.c', line 43 static VALUE rbpod_database_device_get(VALUE self) { Itdb_iTunesDB *database = TYPED_DATA_PTR(self, Itdb_iTunesDB); return rbpod_device_create(database->device); } |
#filename ⇒ Object
49 50 51 52 53 |
# File 'ext/rbpod/database.c', line 49 static VALUE rbpod_database_filename_get(VALUE self) { Itdb_iTunesDB *database = TYPED_DATA_PTR(self, Itdb_iTunesDB); return rb_str_new2(database->filename); } |
#id ⇒ Object
61 62 63 64 65 |
# File 'ext/rbpod/database.c', line 61 static VALUE rbpod_database_id_get(VALUE self) { Itdb_iTunesDB *database = TYPED_DATA_PTR(self, Itdb_iTunesDB); return INT2NUM(database->id); } |
#mountpoint ⇒ Object
67 68 69 70 71 |
# File 'ext/rbpod/database.c', line 67 static VALUE rbpod_database_mountpoint_get(VALUE self) { Itdb_iTunesDB *database = TYPED_DATA_PTR(self, Itdb_iTunesDB); return rb_str_new2(itdb_get_mountpoint(database)); } |
#mountpoint=(path) ⇒ Object
73 74 75 76 77 78 |
# File 'ext/rbpod/database.c', line 73 static VALUE rbpod_database_mountpoint_set(VALUE self, VALUE path) { Itdb_iTunesDB *database = TYPED_DATA_PTR(self, Itdb_iTunesDB); itdb_set_mountpoint(database, StringValueCStr(path)); return rbpod_database_mountpoint_get(self); } |
#playlists ⇒ Object
28 29 30 31 32 |
# File 'ext/rbpod/database.c', line 28 static VALUE rbpod_database_playlists_get(VALUE self) { Itdb_iTunesDB *database = TYPED_DATA_PTR(self, Itdb_iTunesDB); return rbpod_playlist_collection_create(self, database->playlists); } |
#save! ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'ext/rbpod/database.c', line 9 static VALUE rbpod_database_save(VALUE self) { Itdb_iTunesDB *database = TYPED_DATA_PTR(self, Itdb_iTunesDB); GError *error = NULL; if (itdb_write(database, &error) == FALSE) { return rbpod_raise_error(error); } return self; } |
#synchronized? ⇒ Boolean
21 22 23 24 25 26 |
# File 'ext/rbpod/database.c', line 21 static VALUE rbpod_database_synchronized_p(VALUE self) { Itdb_iTunesDB *database = TYPED_DATA_PTR(self, Itdb_iTunesDB); guint32 nontransferred = itdb_tracks_number_nontransferred(database); return BooleanValue(nontransferred == 0); } |
#tracks ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'ext/rbpod/database.c', line 34 static VALUE rbpod_database_tracks_get(VALUE self) { Itdb_iTunesDB *database = TYPED_DATA_PTR(self, Itdb_iTunesDB); Itdb_Playlist *playlist = itdb_playlist_mpl(database); /* Use the master playlist as the parent for the master track list. */ VALUE parent = Data_Wrap_Struct(cRbPodPlaylist, NULL, NULL, (void *) playlist); return rbpod_track_collection_create(parent, database->tracks); } |
#version ⇒ Object
55 56 57 58 59 |
# File 'ext/rbpod/database.c', line 55 static VALUE rbpod_database_version_get(VALUE self) { Itdb_iTunesDB *database = TYPED_DATA_PTR(self, Itdb_iTunesDB); return INT2NUM(database->version); } |