def populateCombo(combo, items):
    """Populate the combo with the list of items given.

    This also makes sure the currently entered text persists,
    or if currenttext is set, use this
    """
    currenttext = combo.currentText()
    if currenttext not in items:
        items = items + [currenttext]
    for i, val in enumerate(items):
        if i >= combo.count():
            combo.addItem(val)
        elif combo.itemText(i) != val:
            combo.insertItem(i, val)
    while combo.count() > len(items):
        combo.removeItem(combo.count() - 1)
    index = combo.findText(currenttext)
    combo.setCurrentIndex(index)
