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; }
GpodDb::InitResult GpodDb::Reinitialize () { const auto& nativePath = QDir::toNativeSeparators (LocalPath_).toUtf8 (); GError *gerr = nullptr; itdb_init_ipod (nativePath, nullptr, "leechpod", &gerr); if (gerr) { const auto& msg = QString::fromUtf8 (gerr->message); g_error_free (gerr); return { Result::OtherError, msg }; } else return { Result::Success, {} }; }
gboolean rb_ipod_helpers_show_first_time_dialog (GMount *mount, const char *builder_file) { /* could be an uninitialised iPod, ask the user */ GtkBuilder *builder; GtkWidget *dialog; GtkWidget *widget; GtkTreeModel *tree_model; GtkTreeIter iter; int response; char *mountpoint; const Itdb_IpodInfo *info; char *ipod_name; GFile *root; GError *error = NULL; root = g_mount_get_root (mount); if (root == NULL) { return FALSE; } mountpoint = g_file_get_path (root); g_object_unref (G_OBJECT (root)); if (mountpoint == NULL) { return FALSE; } /* create message dialog with model-number combo box * and asking whether they want to initialise the iPod */ builder = rb_builder_load (builder_file, NULL); if (builder == NULL) { return FALSE; } dialog = GTK_WIDGET (gtk_builder_get_object (builder, "ipod_init")); widget = GTK_WIDGET (gtk_builder_get_object (builder, "model_combo")); fill_model_combo (widget, mountpoint); g_object_unref (builder); rb_debug ("showing init dialog for ipod mount on '%s'", mountpoint); response = gtk_dialog_run (GTK_DIALOG (dialog)); if (response != GTK_RESPONSE_ACCEPT) { gtk_widget_destroy (dialog); g_free (mountpoint); return FALSE; } /* get model number and name */ tree_model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter)) { gtk_widget_destroy (dialog); g_free (mountpoint); return FALSE; } gtk_tree_model_get (tree_model, &iter, COL_INFO, &info, -1); widget = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry")); ipod_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (widget))); gtk_widget_destroy (dialog); rb_debug ("attempting to init ipod on '%s', with model '%s' and name '%s'", mountpoint, info->model_number, ipod_name); if (!itdb_init_ipod (mountpoint, info->model_number, ipod_name, &error)) { rb_error_dialog (NULL, _("Unable to initialize new iPod"), "%s", error->message); g_free (mountpoint); g_free (ipod_name); g_error_free (error); return FALSE; } g_free (mountpoint); g_free (ipod_name); return TRUE; }
/** * repository_ipod_init: * * Ask for the iPod model and mountpoint and then create the directory * structure on the iPod. * * @itdb: itdb from where to extract the mountpoint. After * initialisation the model number is set. */ gboolean repository_ipod_init(iTunesDB *itdb) { IpodInit *ii; gint response; gboolean result = FALSE; gchar *mountpoint, *new_mount, *name, *model; GError *error = NULL; gchar buf[PATH_MAX]; GtkComboBox *cb; const IpodInfo *info; GtkTreeIter iter; g_return_val_if_fail (itdb, FALSE); /* Create window */ ii = g_new0 (IpodInit, 1); ii->itdb = itdb; ii->builder = init_repository_builder(); ii->window = gtkpod_builder_xml_get_widget(ii->builder, "ipod_init_dialog"); g_return_val_if_fail (ii->window, FALSE); /* Set mountpoint */ mountpoint = get_itdb_prefs_string(itdb, KEY_MOUNTPOINT); if (mountpoint) { gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(GET_WIDGET (ii->builder, IID_MOUNTPOINT_CHOOSER)), mountpoint); } /* Setup model number combo */ cb = GTK_COMBO_BOX (GET_WIDGET (ii->builder, IID_MODEL_COMBO)); repository_init_model_number_combo(cb); /* If available set current model number, otherwise indicate that none is available */ info = itdb_device_get_ipod_info(itdb->device); if (info && (info->ipod_generation != ITDB_IPOD_GENERATION_UNKNOWN)) { g_snprintf(buf, PATH_MAX, "x%s", info->model_number); } else { model = get_itdb_prefs_string(itdb, KEY_IPOD_MODEL); if (model && (strlen(g_strstrip (model)) != 0)) { g_snprintf(buf, PATH_MAX, "%s", model); g_free(model); } else { g_snprintf(buf, PATH_MAX, "%s", gettext (SELECT_OR_ENTER_YOUR_MODEL)); } } /* Try and set buf as the active selection in the combo box */ _model_combo_set_active_iter(cb, buf); gtk_window_set_transient_for(GTK_WINDOW (ii->window), GTK_WINDOW (gtkpod_app)); response = gtk_dialog_run(GTK_DIALOG (ii->window)); switch (response) { case GTK_RESPONSE_OK: new_mount = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(GET_WIDGET (ii->builder, IID_MOUNTPOINT_CHOOSER)))); if (!new_mount || (strlen(new_mount) == 0)) { gtkpod_statusbar_message("No mount point has been selected"); return FALSE; } if (!gtk_combo_box_get_has_entry(cb)) { gtkpod_statusbar_message("No model has been selected"); return FALSE; } /* remove trailing '/' in case it's present. */ if (mountpoint && (strlen(mountpoint) > 0)) { if (G_IS_DIR_SEPARATOR(mountpoint[strlen(mountpoint) - 1])) { mountpoint[strlen(mountpoint) - 1] = 0; } } if (new_mount && (strlen(new_mount) > 0)) { if (G_IS_DIR_SEPARATOR(new_mount[strlen(new_mount) - 1])) { new_mount[strlen(new_mount) - 1] = 0; } } if (!(mountpoint && new_mount && (strcmp(mountpoint, new_mount) == 0))) { /* mountpoint has changed */ g_free(mountpoint); mountpoint = new_mount; new_mount = NULL; set_itdb_prefs_string(itdb, KEY_MOUNTPOINT, mountpoint); call_script("gtkpod.load", mountpoint, NULL); itdb_set_mountpoint(itdb, mountpoint); } else { g_free(new_mount); new_mount = NULL; } g_return_val_if_fail(gtk_combo_box_get_active_iter(cb, &iter), FALSE); gtk_tree_model_get(gtk_combo_box_get_model(cb), &iter, COL_STRING, &model, -1); g_return_val_if_fail(model, FALSE); if ((strcmp(model, gettext(SELECT_OR_ENTER_YOUR_MODEL)) == 0) || (strlen(model) == 0)) { /* User didn't choose a model */ g_free(model); model = NULL; } /* Set model in the prefs system */ set_itdb_prefs_string(itdb, KEY_IPOD_MODEL, model); name = get_itdb_prefs_string(itdb, "name"); result = itdb_init_ipod(mountpoint, model, name, &error); /* Set the model in the sysinfo of the itdb */ itdb_device_set_sysinfo(itdb->device, "ModelNumStr", model); if (!result) { if (error) { gtkpod_warning(_("Error initialising iPod: %s\n"), error->message); g_error_free(error); error = NULL; } else { gtkpod_warning(_("Error initialising iPod, unknown error\n")); } } else { /* Should write the extended info file */ result = gp_create_extended_info(itdb); } g_free(name); g_free(model); break; default: /* canceled -- do nothing */ break; } gtk_widget_destroy(ii->window); g_free(mountpoint); g_free(ii); return result; }