<commit_before>/* This file is part of Strigi Desktop Search
 *
 * Copyright (C) 2006 <NAME> <<EMAIL>>
 *                    <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., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "daemonconfigurator.h"
#include "../strigilogging.h"

#include <algorithm>
#include <fstream>
#include <sstream>
#include <stdlib.h>

using namespace std;
using namespace Strigi;

class FindRepository {
private:
    string m_repoName;

public:
    FindRepository(string repoName) { m_repoName = repoName; }

    bool operator()(Repository repo) {
        if (repo.a_name.compare(m_repoName) == 0) {
            return true;
        }
        return false;
    }
};

DaemonConfigurator::DaemonConfigurator (const string& confFile)
        : m_confFile (confFile) {
    // find the strigi directory
    string strigidir;
    string::size_type slashpos = confFile.rfind('/');
    if (slashpos != string::npos) {
        strigidir = confFile.substr(0, slashpos);
    } else {
        strigidir = getenv("HOME") + string("/.strigi");
    }

    stringbuf xml;
    ifstream f(confFile.c_str(), ios::binary);
    f.get(xml, '\0');
    f.close();

    if (xml.str().length()) {
        XMLStream stream(xml.str());
        stream >> *this;
    }
    FindRepository findRepository("localhost");
    list<Repository>::iterator match = find_if(e_repository.begin(),
                                               e_repository.end(),
                                               findRepository);

    // entry for localhost repository doesn't exists
    if (match == e_repository.end()) {
        a_useDBus = true;
        Repository r;
        r.a_name = "localhost";
        string home;
        if (getenv("HOME")) {
            home.assign(getenv("HOME"));
        }
        r.a_indexdir = strigidir + "/clucene";
        r.a_writeable = true;
        r.a_type = "clucene";
        r.a_pollingInterval = DEFAULT_POLLING_INTERVAL;

        Path p;
        p.a_path = home;                 r.e_path.push_back(p);
        p.a_path = home + "/.kde";       r.e_path.push_back(p);
        p.a_path = home + "/.gnome2";    r.e_path.push_back(p);
        p.a_path = home + "/.evolution"; r.e_path.push_back(p);
        p.a_path = home + "/.mozilla";   r.e_path.push_back(p);
        p.a_path = home + "/.mozilla-thunderbird";   r.e_path.push_back(p);
        e_repository.push_back(r);

        // add pattern to ignore hidden directories and hidden files
        Filter f;
        f.a_include = true;
        f.a_pattern = ".*.directory/"; // mail box directory
        e_filters.e_filter.push_back(f);
        f.a_include = false;
        f.a_pattern = ".*/";<commit_msg>Add ~/.kde4 to the default directories to index.<commit_after>/* This file is part of Strigi Desktop Search
 *
 * Copyright (C) 2006 <NAME> <<EMAIL>>
 *                    J<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., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "daemonconfigurator.h"
#include "../strigilogging.h"

#include <algorithm>
#include <fstream>
#include <sstream>
#include <stdlib.h>

using namespace std;
using namespace Strigi;

class FindRepository {
private:
    string m_repoName;

public:
    FindRepository(string repoName) { m_repoName = repoName; }

    bool operator()(Repository repo) {
        if (repo.a_name.compare(m_repoName) == 0) {
            return true;
        }
        return false;
    }
};

DaemonConfigurator::DaemonConfigurator (const string& confFile)
        : m_confFile (confFile) {
    // find the strigi directory
    string strigidir;
    string::size_type slashpos = confFile.rfind('/');
    if (slashpos != string::npos) {
        strigidir = confFile.substr(0, slashpos);
    } else {
        strigidir = getenv("HOME") + string("/.strigi");
    }

    stringbuf xml;
    ifstream f(confFile.c_str(), ios::binary);
    f.get(xml, '\0');
    f.close();

    if (xml.str().length()) {
        XMLStream stream(xml.str());
        stream >> *this;
    }
    FindRepository findRepository("localhost");
    list<Repository>::iterator match = find_if(e_repository.begin(),
                                               e_repository.end(),
                                               findRepository);

    // entry for localhost repository doesn't exists
    if (match == e_repository.end()) {
        a_useDBus = true;
        Repository r;
        r.a_name = "localhost";
        string home;
        if (getenv("HOME")) {
            home.assign(getenv("HOME"));
        }
        r.a_indexdir = strigidir + "/clucene";
        r.a_writeable = true;
        r.a_type = "clucene";
        r.a_pollingInterval = DEFAULT_POLLING_INTERVAL;

        Path p;
        p.a_path = home;                 r.e_path.push_back(p);
        p.a_path = home + "/.kde";       r.e_path.push_back(p);
        p.a_path = home + "/.kde4";      r.e_path.push_back(p);
        p.a_path = home + "/.gnome2";    r.e_path.push_back(p);
        p.a_path = home + "/.evolution"; r.e_path.push_back(p);
        p.a_path = home + "/.mozilla";   r.e_path.push_back(p);
        p.a_path = home + "/.mozilla-thunderbird";   r.e_path.push_back(p);
        e_repository.push_back(r);

        // add pattern to ignore hidden directories and hidden files
        Filter f;
        f.a_include = true;
        f.a_pattern = ".*.directory/"; // mail box directory
        e_filters.e_filter.push_back(f);
        f.a_include = false;
        f.a_pattern = ".*/";
{'fraction_non_alphanumeric': 0.1184593023255814, 'fraction_numerical': 0.006104651162790698, 'mean_word_length': 2.3680861478218307, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1863313', 'n_tokens_mistral': 2141, 'n_tokens_neox': 2073, 'n_words': 605}