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_free: * @photodb: an #Itdb_PhotoDB * * Free the memory taken by @photodb. **/ void itdb_photodb_free (Itdb_PhotoDB *photodb) { if (photodb) { g_list_foreach (photodb->photoalbums, (GFunc)(itdb_photodb_photoalbum_free), NULL); g_list_free (photodb->photoalbums); g_list_foreach (photodb->photos, (GFunc)(itdb_artwork_free), NULL); g_list_free (photodb->photos); itdb_device_free (photodb->device); if (photodb->userdata && photodb->userdata_destroy) (*photodb->userdata_destroy) (photodb->userdata); g_free (photodb); } }
static void fill_model_combo (GtkWidget *combo, const char *mount_path) { GHashTable *models; Itdb_Device *device; GtkTreeStore *store; const Itdb_IpodInfo *ipod_info; GtkCellRenderer *renderer; struct FillModelContext ctx; device = itdb_device_new (); itdb_device_set_mountpoint (device, mount_path); itdb_device_read_sysinfo (device); ipod_info = itdb_device_get_ipod_info (device); itdb_device_free (device); store = gtk_tree_store_new (1, G_TYPE_POINTER); gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (store)); ctx.combo = combo; ctx.store = store; ctx.ipod_info = ipod_info; models = build_model_table (mount_path); g_hash_table_foreach (models, fill_one_generation, &ctx); g_hash_table_destroy (models); g_object_unref (store); gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo)); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, FALSE); gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo), renderer, set_cell, NULL, NULL); }