def save_settings(config, ui):
    """Save current UI configuration to the OS repository, called when exiting the main application"""
    config.setValue('fan1_percent', ui.horizontalSliderFan1.value())
    config.setValue('fan2_percent', ui.horizontalSliderFan2.value())
    config.setValue('fan3_percent', ui.horizontalSliderFan3.value())
    config.setValue('fan4_percent', ui.horizontalSliderFan4.value())
    config.setValue('fan5_percent', ui.horizontalSliderFan5.value())
    config.setValue('fan6_percent', ui.horizontalSliderFan6.value())
    config.setValue('port', ui.comboBoxComPorts.currentText())
    config.setValue('polling', ui.comboBoxPolling.currentText())
    config.setValue('automatic_control', ui.radioButtonAutomatic.isChecked())
    config.setValue('manual_control', ui.radioButtonManual.isChecked())
    root = ui.treeWidgetSelectedCPUSensors.invisibleRootItem()
    child_count = root.childCount()
    cpu_sensor_ids = []
    for i in range(child_count):
        item = root.child(i)
        cpu_sensor_ids.append(item.text(1))
    config.setValue('cpu_sensor_ids', cpu_sensor_ids)
    root = ui.treeWidgetSelectedGPUSensors.invisibleRootItem()
    child_count = root.childCount()
    gpu_sensor_ids = []
    for i in range(child_count):
        item = root.child(i)
        gpu_sensor_ids.append(item.text(1))
    config.setValue('gpu_sensor_ids', gpu_sensor_ids)
    config.setValue('cpu_use_max', ui.radioButtonCPUMax.isChecked())
    config.setValue('cpu_use_avg', ui.radioButtonCPUAverage.isChecked())
    config.setValue('gpu_use_max', ui.radioButtonGPUMax.isChecked())
    config.setValue('gpu_use_avg', ui.radioButtonGPUAverage.isChecked())
    config.setValue('cpu_fan_1', ui.radioButtonCPUFan1.isChecked())
    config.setValue('cpu_fan_2', ui.radioButtonCPUFan2.isChecked())
    config.setValue('cpu_fan_3', ui.radioButtonCPUFan3.isChecked())
    config.setValue('cpu_fan_4', ui.radioButtonCPUFan4.isChecked())
    config.setValue('cpu_fan_5', ui.radioButtonCPUFan5.isChecked())
    config.setValue('cpu_fan_6', ui.radioButtonCPUFan6.isChecked())
    config.setValue('gpu_fan_1', ui.radioButtonGPUFan1.isChecked())
    config.setValue('gpu_fan_2', ui.radioButtonGPUFan2.isChecked())
    config.setValue('gpu_fan_3', ui.radioButtonGPUFan3.isChecked())
    config.setValue('gpu_fan_4', ui.radioButtonGPUFan4.isChecked())
    config.setValue('gpu_fan_5', ui.radioButtonGPUFan5.isChecked())
    config.setValue('gpu_fan_6', ui.radioButtonGPUFan6.isChecked())
    config.setValue('min_speed_fan_1', ui.spinBoxMinSpeedFan1.value())
    config.setValue('min_speed_fan_2', ui.spinBoxMinSpeedFan2.value())
    config.setValue('min_speed_fan_3', ui.spinBoxMinSpeedFan3.value())
    config.setValue('min_speed_fan_4', ui.spinBoxMinSpeedFan4.value())
    config.setValue('min_speed_fan_5', ui.spinBoxMinSpeedFan5.value())
    config.setValue('min_speed_fan_6', ui.spinBoxMinSpeedFan6.value())
    config.setValue('start_increase_speed_fan_1', ui.
        spinBoxStartIncreaseSpeedFan1.value())
    config.setValue('start_increase_speed_fan_2', ui.
        spinBoxStartIncreaseSpeedFan2.value())
    config.setValue('start_increase_speed_fan_3', ui.
        spinBoxStartIncreaseSpeedFan3.value())
    config.setValue('start_increase_speed_fan_4', ui.
        spinBoxStartIncreaseSpeedFan4.value())
    config.setValue('start_increase_speed_fan_5', ui.
        spinBoxStartIncreaseSpeedFan5.value())
    config.setValue('start_increase_speed_fan_6', ui.
        spinBoxStartIncreaseSpeedFan6.value())
    config.setValue('intermediate_speed_fan_1', ui.
        spinBoxIntermediateSpeedFan1.value())
    config.setValue('intermediate_speed_fan_2', ui.
        spinBoxIntermediateSpeedFan2.value())
    config.setValue('intermediate_speed_fan_3', ui.
        spinBoxIntermediateSpeedFan3.value())
    config.setValue('intermediate_speed_fan_4', ui.
        spinBoxIntermediateSpeedFan4.value())
    config.setValue('intermediate_speed_fan_5', ui.
        spinBoxIntermediateSpeedFan5.value())
    config.setValue('intermediate_speed_fan_6', ui.
        spinBoxIntermediateSpeedFan6.value())
    config.setValue('intermediate_temp_fan_1', ui.
        spinBoxIntermediateTempFan1.value())
    config.setValue('intermediate_temp_fan_2', ui.
        spinBoxIntermediateTempFan2.value())
    config.setValue('intermediate_temp_fan_3', ui.
        spinBoxIntermediateTempFan3.value())
    config.setValue('intermediate_temp_fan_4', ui.
        spinBoxIntermediateTempFan4.value())
    config.setValue('intermediate_temp_fan_5', ui.
        spinBoxIntermediateTempFan5.value())
    config.setValue('intermediate_temp_fan_6', ui.
        spinBoxIntermediateTempFan6.value())
    config.setValue('max_speed_fan_1', ui.spinBoxMaxSpeedFan1.value())
    config.setValue('max_speed_fan_2', ui.spinBoxMaxSpeedFan2.value())
    config.setValue('max_speed_fan_3', ui.spinBoxMaxSpeedFan3.value())
    config.setValue('max_speed_fan_4', ui.spinBoxMaxSpeedFan4.value())
    config.setValue('max_speed_fan_5', ui.spinBoxMaxSpeedFan5.value())
    config.setValue('max_speed_fan_6', ui.spinBoxMaxSpeedFan6.value())
    config.setValue('max_temp_fan_1', ui.spinBoxMaxTempFan1.value())
    config.setValue('max_temp_fan_2', ui.spinBoxMaxTempFan2.value())
    config.setValue('max_temp_fan_3', ui.spinBoxMaxTempFan3.value())
    config.setValue('max_temp_fan_4', ui.spinBoxMaxTempFan4.value())
    config.setValue('max_temp_fan_5', ui.spinBoxMaxTempFan5.value())
    config.setValue('max_temp_fan_6', ui.spinBoxMaxTempFan6.value())
    config.setValue('fan1_name', ui.lineEditFan1.text())
    config.setValue('fan2_name', ui.lineEditFan2.text())
    config.setValue('fan3_name', ui.lineEditFan3.text())
    config.setValue('fan4_name', ui.lineEditFan4.text())
    config.setValue('fan5_name', ui.lineEditFan5.text())
    config.setValue('fan6_name', ui.lineEditFan6.text())
