<commit_before>/*
    This file is part of KitchenSync.

    Copyright (c) 2002 <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <kconfig.h>
#include <kdebug.h>

#include "idhelper.h"

using namespace KSync;

// TypeORAppName||%%||KonnectorId||%%||KDEID
KonnectorUIDHelper::KonnectorUIDHelper( const QString &dir )
{
//    kdDebug(5201) << "new KonnectorUIDHelper " << dir <<endl;
    m_config = new KConfig( dir + "/konnector-ids.conf");
    m_config->setGroup("uids");
    QString string = m_config->readEntry( "ids" );
    QStringList list = QStringList::split( "%%||%%",  string );

    for ( QStringList::Iterator it = list.begin(); it != list.end() ; ++it ) {
        QStringList list2 = QStringList::split("||%%||",(*it), true ); // allow empty entries
        addId( list2[0],  list2[1], list2[2] );
    }

}
KonnectorUIDHelper::~KonnectorUIDHelper()
{
    save();
    delete m_config;
}
QString KonnectorUIDHelper::konnectorId( const QString &appName,  const QString &kdeId, const QString &defaultId )
{
//    kdDebug(5201) << "IdHelper: KonnectorIdAppName: "
//                  << appName << " KDE Id: "
//                  << kdeId << " defaultId "
//                  << defaultId << endl;

    QMap<QString,  Kontainer::ValueList >::Iterator it;
    it = m_ids.find( appName );
    if ( it != m_ids.end() ) {
        Kontainer::ValueList kontainer = it.data();
        Kontainer::ValueList::Iterator it;
        for ( it = kontainer.begin(); it != kontainer.end(); ++it ) {
            if ( kdeId.stripWhiteSpace() == (*it).second.stripWhiteSpace() ) {
//                kdDebug(5201) << "it.first = " << (*it).first() << endl;
                return (*it).first;
            }
        }
    }
    return defaultId;
}
QString KonnectorUIDHelper::kdeId( const QString &appName,  const QString &konnectorId, const QString &defaultId )
{
//    kdDebug(5201) << "kdeId: AppName: "
//                  << appName  << " konnectorId "
//                  << konnectorId << endl;

    QMap<QString,  Kontainer::ValueList >::Iterator it;
    it = m_ids.find( appName );
    if ( it != m_ids.end() ) {
        Kontainer::ValueList kontainer = it.data();
        Kontainer::ValueList::Iterator it;
        for ( it = kontainer.begin(); it != kontainer.end(); ++it ) {
            if ( konnectorId.stripWhiteSpace() == (*it).first.stripWhiteSpace() ) {
//                kdDebug(5201) << "it.second " << (*it).second() << endl;
                return (*it).second;
            }
        }
    }
    return defaultId;
}
void KonnectorUIDHelper::addId( const QString& appName,
                                const QString& konnectorId,
                                const QString& kdeId )
{
//    kdDebug(5201) << "addId " << appName
//                  << "  konId "  << konnectorId
//                  << " kdeId " << kdeId << endl;

    QMap<QString,  Kontainer::ValueList >::Iterator it;
    it = m_ids.find( appName );

    if ( it == m_ids.end() ) {
//        kdDebug(5201) << "First insert" << endl;
        Kontainer::ValueList kontainer;
        kontainer.append( Kontainer( konnectorId,  kdeId ) );
        m_ids.replace( appName,  kontainer );
    }else{
//        kdDebug(5201) << "Already inserted" << endl;
        Kontainer::ValueList kontainer = it.data();
        Kontainer kont( konnectorId,  kdeId );
        kontainer.remove( kont );
        kontainer.append( kont );
        m_ids.replace( appName,  kontainer );
    }
}
void KonnectorUIDHelper::removeId( const QString &appName,  const QString &id )
{
    QMap<QString,  Kontainer::ValueList >::Iterator it;
    it = m_ids.find( appName );
    if ( it== m_ids.end() ) {
        Kontainer::ValueList kontainer = it.data();
        Kontainer::ValueList::Iterator it;
        for ( it = kontainer.begin(); it != kontainer.end(); ++it ) {
            if ( (*it).first == id || (*it).second == id ) {
                it  = kontainer.remove( it );
                return;
            }
        }
    }
}
void KonnectorUIDHelper::replaceIds( const QString &app,
                                     Kontainer::ValueList ids )
{
    m_ids.replace( app,  ids );
}
void KonnectorUIDHelper::clear()
{<commit_msg>Applyed patch by <NAME>, which fixes some obviously bugs.<commit_after>/*
    This file is part of KitchenSync.

    Copyright (c) 2002 <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <kconfig.h>
#include <kdebug.h>

#include "idhelper.h"

using namespace KSync;

// TypeORAppName||%%||KonnectorId||%%||KDEID
KonnectorUIDHelper::KonnectorUIDHelper( const QString &dir )
{
//    kdDebug(5201) << "new KonnectorUIDHelper " << dir <<endl;
    m_config = new KConfig( dir + "/konnector-ids.conf");
    m_config->setGroup("uids");
    QString string = m_config->readEntry( "ids" );
    QStringList list = QStringList::split( "%%||%%",  string );

    for ( QStringList::Iterator it = list.begin(); it != list.end() ; ++it ) {
        QStringList list2 = QStringList::split("||%%||",(*it), true ); // allow empty entries
        addId( list2[0],  list2[1], list2[2] );
    }

}
KonnectorUIDHelper::~KonnectorUIDHelper()
{
    save();
    delete m_config;
}
QString KonnectorUIDHelper::konnectorId( const QString &appName,  const QString &kdeId, const QString &defaultId )
{
//    kdDebug(5201) << "IdHelper: KonnectorIdAppName: "
//                  << appName << " KDE Id: "
//                  << kdeId << " defaultId "
//                  << defaultId << endl;

    QMap<QString,  Kontainer::ValueList >::Iterator it;
    it = m_ids.find( appName );
    if ( it != m_ids.end() ) {
        Kontainer::ValueList kontainer = it.data();
        Kontainer::ValueList::Iterator it;
        for ( it = kontainer.begin(); it != kontainer.end(); ++it ) {
            if ( kdeId.stripWhiteSpace() == (*it).second.stripWhiteSpace() ) {
//                kdDebug(5201) << "it.first = " << (*it).first() << endl;
                return (*it).first;
            }
        }
    }
    return defaultId;
}
QString KonnectorUIDHelper::kdeId( const QString &appName,  const QString &konnectorId, const QString &defaultId )
{
//    kdDebug(5201) << "kdeId: AppName: "
//                  << appName  << " konnectorId "
//                  << konnectorId << endl;

    QMap<QString,  Kontainer::ValueList >::Iterator it;
    it = m_ids.find( appName );
    if ( it != m_ids.end() ) {
        Kontainer::ValueList kontainer = it.data();
        Kontainer::ValueList::Iterator it;
        for ( it = kontainer.begin(); it != kontainer.end(); ++it ) {
            if ( konnectorId.stripWhiteSpace() == (*it).first.stripWhiteSpace() ) {
//                kdDebug(5201) << "it.second " << (*it).second() << endl;
                return (*it).second;
            }
        }
    }
    return defaultId;
}
void KonnectorUIDHelper::addId( const QString& appName,
                                const QString& konnectorId,
                                const QString& kdeId )
{
//    kdDebug(5201) << "addId " << appName
//                  << "  konId "  << konnectorId
//                  << " kdeId " << kdeId << endl;

    QMap<QString,  Kontainer::ValueList >::Iterator it;
    it = m_ids.find( appName );

    if ( it == m_ids.end() ) {
//        kdDebug(5201) << "First insert" << endl;
        Kontainer::ValueList kontainer;
        kontainer.append( Kontainer( konnectorId,  kdeId ) );
        m_ids.replace( appName,  kontainer );
    }else{
//        kdDebug(5201) << "Already inserted" << endl;
        Kontainer::ValueList &kontainer = it.data();
        Kontainer kont( konnectorId,  kdeId );
        kontainer.remove( kont );
        kontainer.append( kont );
        m_ids.replace( appName,  kontainer );
    }
}
void KonnectorUIDHelper::removeId( const QString &appName,  const QString &id )
{
    QMap<QString,  Kontainer::ValueList >::Iterator it;
    it = m_ids.find( appName );
    if ( it != m_ids.end() ) {
        Kontainer::ValueList &kontainer = it.data();
        Kontainer::ValueList::Iterator it;
        for ( it = kontainer.begin(); it != kontainer.end(); ++it ) {
            if ( (*it).first == id || (*it).second == id ) {
                it  = kontainer.remove( it );
                return;
            }
        }
    }
}
void KonnectorUIDHelper::replaceIds( const QString &app,
                                     Kontainer::ValueList ids )
{
    m_ids.replace( app,  ids );
}
void KonnectorUIDHelper::clear()
{
{'fraction_non_alphanumeric': 0.1389813414019163, 'fraction_numerical': 0.011699445284921835, 'mean_word_length': 2.367062818336163, 'pattern_counts': {'":': 0, '<': 150, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6525224', 'n_tokens_mistral': 3139, 'n_tokens_neox': 3053, 'n_words': 810}