<commit_before>/***************************************************************************
*   Copyright (C) 2003-2004 by                                                 *
*   <NAME> (<EMAIL>)                             *
*   <NAME> (<EMAIL>)                               *
*   <NAME> (<EMAIL>)                    *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
***************************************************************************/

#include "categorycombobox.h"

#include <qlistbox.h>

#include <klocale.h>
#include <kconfig.h>
#include <kglobal.h>

#include "backends/recipedb.h"
#include "backends/progressinterface.h"
#include "datablocks/elementlist.h"
#include "datablocks/categorytree.h"

CategoryComboBox::CategoryComboBox( QWidget *parent, RecipeDB *db ) : KComboBox( parent ),
		database( db ),
		m_offset(0)
{
	connect( database, SIGNAL( categoryCreated( const Element &, int ) ), SLOT( createCategory( const Element &, int ) ) );
	connect( database, SIGNAL( categoryRemoved( int ) ), SLOT( removeCategory( int ) ) );
	connect( database, SIGNAL( categoryModified( const Element & ) ), SLOT( modifyCategory( const Element & ) ) );
	connect( database, SIGNAL( categoriesMerged( int, int ) ), SLOT( mergeCategories( int, int ) ) );

	reload();
}

void CategoryComboBox::reload()
{
	QString remember_cat_filter = currentText();

	KConfig * config = KGlobal::config();config->setGroup( "Performance" );
	int limit = config->readNumEntry( "CategoryLimit", -1 );

	ProgressInterface pi(this);
	pi.listenOn(database);

	CategoryTree categoryList;
	database->loadCategories( &categoryList, limit, m_offset, -1 );

	clear();
	categoryComboRows.clear();

	// Insert default "All Categories" (row 0, which will be translated to -1 as category in the filtering process)
	insertItem( i18n( "All Categories" ) );

	//Now load the categories
	int row = 1;
	loadCategories(&categoryList,row);

	if ( listBox() ->findItem( remember_cat_filter, Qt::ExactMatch ) ) {
		setCurrentText( remember_cat_filter );
	}
}

void CategoryComboBox::loadCategories( CategoryTree *categoryTree, int &row )
{
	for ( CategoryTree * child_it = categoryTree->firstChild(); child_it; child_it = child_it->nextSibling() ) {
		insertItem( child_it->category.name );
		categoryComboRows.insert( row, child_it->category.id ); // store category id's in the combobox position to obtain the category id later<commit_msg>Disable this progress bar for now.  It is causing crashes in some  circumstances.<commit_after>/***************************************************************************
*   Copyright (C) 2003-2004 by                                                 *
*   <NAME> (<EMAIL>)                             *
*   <NAME> (<EMAIL>)                               *
*   <NAME> (<EMAIL>)                    *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
***************************************************************************/

#include "categorycombobox.h"

#include <qlistbox.h>

#include <klocale.h>
#include <kconfig.h>
#include <kglobal.h>

#include "backends/recipedb.h"
#include "backends/progressinterface.h"
#include "datablocks/elementlist.h"
#include "datablocks/categorytree.h"

CategoryComboBox::CategoryComboBox( QWidget *parent, RecipeDB *db ) : KComboBox( parent ),
		database( db ),
		m_offset(0)
{
	connect( database, SIGNAL( categoryCreated( const Element &, int ) ), SLOT( createCategory( const Element &, int ) ) );
	connect( database, SIGNAL( categoryRemoved( int ) ), SLOT( removeCategory( int ) ) );
	connect( database, SIGNAL( categoryModified( const Element & ) ), SLOT( modifyCategory( const Element & ) ) );
	connect( database, SIGNAL( categoriesMerged( int, int ) ), SLOT( mergeCategories( int, int ) ) );

	reload();
}

void CategoryComboBox::reload()
{
	QString remember_cat_filter = currentText();

	KConfig * config = KGlobal::config();config->setGroup( "Performance" );
	int limit = config->readNumEntry( "CategoryLimit", -1 );

	//ProgressInterface pi(this);
	//pi.listenOn(database);

	CategoryTree categoryList;
	database->loadCategories( &categoryList, limit, m_offset, -1 );

	clear();
	categoryComboRows.clear();

	// Insert default "All Categories" (row 0, which will be translated to -1 as category in the filtering process)
	insertItem( i18n( "All Categories" ) );

	//Now load the categories
	int row = 1;
	loadCategories(&categoryList,row);

	if ( listBox() ->findItem( remember_cat_filter, Qt::ExactMatch ) ) {
		setCurrentText( remember_cat_filter );
	}
}

void CategoryComboBox::loadCategories( CategoryTree *categoryTree, int &row )
{
	for ( CategoryTree * child_it = categoryTree->firstChild(); child_it; child_it = child_it->nextSibling() ) {
		insertItem( child_it->category.name );
		categoryComboRows.insert( row, child_it->category.id ); // store category id's in the combobox position to obtain the category id later
{'fraction_non_alphanumeric': 0.16817359855334538, 'fraction_numerical': 0.006148282097649186, 'mean_word_length': 3.2975912975912975, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3930573', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1508, 'n_words': 441}