bool IpodDeviceHelper::initializeIpod( const QString &mountPoint, const Ui::IpodConfiguration *configureDialogUi, QString &errorMessage ) { DEBUG_BLOCK bool success = true; int currentModelIndex = configureDialogUi->modelComboBox->currentIndex(); QByteArray modelNumber = configureDialogUi->modelComboBox->itemData( currentModelIndex ).toString().toUtf8(); if( !modelNumber.isEmpty() ) { modelNumber.prepend( 'x' ); // ModelNumStr should start with x const char *modelNumberRaw = modelNumber.constData(); Itdb_Device *device = itdb_device_new(); // following call reads existing SysInfo itdb_device_set_mountpoint( device, QFile::encodeName( mountPoint ) ); const char *field = "ModelNumStr"; debug() << "Setting SysInfo field" << field << "to value" << modelNumberRaw; itdb_device_set_sysinfo( device, field, modelNumberRaw ); GError *error = 0; success = itdb_device_write_sysinfo( device, &error ); if( !success ) { if( error ) { errorMessage = i18nc( "Do not translate SysInfo", "Failed to write SysInfo: %1", error->message ); g_error_free( error ); } else errorMessage = i18nc( "Do not translate SysInfo", "Failed to write SysInfo file due to an unreported error" ); } itdb_device_free( device ); if( !success ) return success; } QString name = configureDialogUi->nameLineEdit->text(); if( name.isEmpty() ) name = ipodName( 0 ); // return fallback name GError *error = 0; success = itdb_init_ipod( QFile::encodeName( mountPoint ), 0 /* model number */, name.toUtf8(), &error ); errorMessage.clear(); if( error ) { errorMessage = QString::fromUtf8( error->message ); g_error_free( error ); error = 0; } if( !success && errorMessage.isEmpty() ) errorMessage = i18n( "Cannot initialize iPod due to an unreported error." ); return success; }
/** * itdb_photodb_write: * @photodb: the #Itdb_PhotoDB to write to disk * @error: return location for a #GError or NULL * * Write out a PhotoDB. * * FIXME: error is not set yet. * * Return value: TRUE on success, FALSE on error, in which case @error is * set accordingly. **/ gboolean itdb_photodb_write (Itdb_PhotoDB *photodb, GError **error) { gint result; GList *gl; gint32 id, prev_id; g_return_val_if_fail (photodb, FALSE); g_return_val_if_fail (photodb->device, FALSE); if (photodb->device->byte_order == 0) itdb_device_autodetect_endianess (photodb->device); /* set up photo_ids */ id = 0x40; for (gl=photodb->photos; gl; gl=gl->next) { Itdb_Artwork *photo = gl->data; g_return_val_if_fail (photo, FALSE); photo->id = id; ++id; } /* set up album_ids -- this is how my iPod Nano does it... */ prev_id = 0x64; id = prev_id + g_list_length (photodb->photos); for (gl=photodb->photoalbums; gl; gl=gl->next) { Itdb_PhotoAlbum *album = gl->data; g_return_val_if_fail (album, FALSE); album->album_id = id; album->prev_album_id = prev_id; ++id; ++prev_id; if (gl != photodb->photoalbums) { /* except for the first album */ prev_id += g_list_length (album->members); } } result = ipod_write_photo_db (photodb); /* Write SysInfo file if it has changed */ if (!error || !(*error)) { if (photodb->device->sysinfo_changed) { itdb_device_write_sysinfo (photodb->device, error); } } if (result == -1) return FALSE; else return TRUE; }