void MPRISPlayerConfigurationUiHandler::delPlayer()
{
    QString playerToRemove = PlayersBox->currentText();

    QSettings globalPlayersSettings(MPRISPlayer::globalPlayersListFileName(m_pathsProvider), QSettings::IniFormat);
    globalPlayersSettings.setIniCodec("ISO8859-2");
    QSettings userPlayersSettings(MPRISPlayer::userPlayersListFileName(m_pathsProvider), QSettings::IniFormat);
    userPlayersSettings.setIniCodec("ISO8859-2");

    QStringList sections = globalPlayersSettings.childGroups();

    if (!sections.contains(playerToRemove))
        sections = userPlayersSettings.childGroups();

    for (auto const &section : sections)
    {
        if (section != playerToRemove)
            continue;

        userPlayersSettings.remove(section + "/player");
        userPlayersSettings.remove(section + "/service");
        break;
    }

    userPlayersSettings.sync();

    loadPlayersListFromFile();
    fillPlayersBox();

    PlayersBox->setCurrentIndex(-1);
}
void MPRISPlayerConfigurationUiHandler::loadPlayersListFromFile()
{
    QSettings userPlayersSettings(MPRISPlayer::userPlayersListFileName(m_pathsProvider), QSettings::IniFormat);
    userPlayersSettings.setIniCodec("ISO8859-2");

    QSettings globalPlayersSettings(MPRISPlayer::globalPlayersListFileName(m_pathsProvider), QSettings::IniFormat);
    globalPlayersSettings.setIniCodec("ISO8859-2");

    QStringList globalSections = globalPlayersSettings.childGroups();
    QStringList userSections = userPlayersSettings.childGroups();

    PlayersMap.clear();

    for (auto const &section : userSections)
    {
        QString player = userPlayersSettings.value(section + "/player").toString();
        QString service = userPlayersSettings.value(section + "/service").toString();

        if (!player.isEmpty() && !service.isEmpty())
            PlayersMap.insert(player, service);
    }

    for (auto const &globalSection : globalSections)
    {
        if (userSections.contains(globalSection))
            continue;

        QString player = globalPlayersSettings.value(globalSection + "/player").toString();
        QString service = globalPlayersSettings.value(globalSection + "/service").toString();

        if (!player.isEmpty() && !service.isEmpty())
            PlayersMap.insert(player, service);
    }
}
void MPRISPlayerConfigurationUiHandler::editPlayer()
{
    MPRISPlayerDialog Dialog(true);

    QString oldPlayer = PlayersBox->currentText();
    QString oldService = PlayersMap.value(oldPlayer);

    if ((oldPlayer.isEmpty() || oldService.isEmpty()))
        return;

    Dialog.setPlayer(oldPlayer);
    Dialog.setService(oldService);

    if (Dialog.exec() != QDialog::Accepted)
        return;

    QString newPlayer = Dialog.getPlayer();
    QString newService = Dialog.getService();

    if ((newPlayer.isEmpty() || newService.isEmpty()) || (newPlayer == oldPlayer && oldService == newService))
        return;

    QSettings globalPlayersSettings(MPRISPlayer::globalPlayersListFileName(m_pathsProvider), QSettings::IniFormat);
    globalPlayersSettings.setIniCodec("ISO8859-2");
    QSettings userPlayersSettings(MPRISPlayer::userPlayersListFileName(m_pathsProvider), QSettings::IniFormat);
    userPlayersSettings.setIniCodec("ISO8859-2");
    QStringList sections = globalPlayersSettings.childGroups();

    if (!sections.contains(oldPlayer))
        sections = userPlayersSettings.childGroups();

    for (auto const &section : sections)
    {
        if (section != oldPlayer)
            continue;

        userPlayersSettings.remove(section + "/player");
        userPlayersSettings.remove(section + "/service");

        userPlayersSettings.setValue(newPlayer + "/player", newPlayer);
        userPlayersSettings.setValue(newPlayer + "/service", newService);
        break;
    }

    userPlayersSettings.sync();

    loadPlayersListFromFile();
    fillPlayersBox();

    PlayersBox->setCurrentIndex(PlayersBox->findText(newPlayer));
}
void MPRISPlayerConfigurationUiHandler::loadPlayersListFromFile()
{
	QSettings userPlayersSettings(MPRISPlayer::userPlayersListFileName(), QSettings::IniFormat);
	userPlayersSettings.setIniCodec("ISO8859-2");

	QSettings globalPlayersSettings(MPRISPlayer::globalPlayersListFileName(), QSettings::IniFormat);
	globalPlayersSettings.setIniCodec("ISO8859-2");

	QStringList globalSections = globalPlayersSettings.childGroups();
	QStringList userSections = userPlayersSettings.childGroups();

	PlayersMap.clear();

	foreach (const QString &section, userSections)
	{
		QString player = userPlayersSettings.value(section + "/player").toString();
		QString service = userPlayersSettings.value(section + "/service").toString();

		if (!player.isEmpty() && !service.isEmpty())
			PlayersMap.insert(player, service);
	}