<commit_before>
/***************************************************************************
                          dlgjabberservices.cpp  -  description
                             -------------------
    begin                : Mon Dec 9 2002
    copyright            : (C) 2002 by <NAME>
    email                : <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 <kmessagebox.h>
#include <klocale.h>
#include <kdebug.h>

#include <qpushbutton.h>
#include <qlineedit.h>
#include <qtable.h>


#include "jabberaccount.h"
#include "dlgjabberregister.h"
#include "dlgjabberbrowse.h"
#include "dlgjabberservices.h"

#include "dlgjabberservices.moc"

dlgJabberServices::dlgJabberServices (JabberAccount *account, QWidget *parent, const char *name):dlgServices (parent, name)
{
	m_account = account;

	if(m_account->isConnected())
	{
		// pre-populate the server field
		leServer->setText(m_account->server());
	}

	// disable the left margin
	tblServices->setLeftMargin (0);

	// no content for now
	tblServices->setNumRows (0);

	// disable the buttons as long as nothing has been selected
	btnRegister->setDisabled (true);
	btnBrowse->setDisabled (true);

	// allow autostretching
	tblServices->setColumnStretchable (0, true);
	tblServices->setColumnStretchable (1, true);

	// disable user selections
	tblServices->setSelectionMode (QTable::NoSelection);

	// name table headers
	tblServices->horizontalHeader ()->setLabel (0, i18n ("Name"));
	tblServices->horizontalHeader ()->setLabel (1, i18n ("Address"));

	connect (btnQuery, SIGNAL (clicked ()), this, SLOT (slotQuery ()));
	connect (tblServices, SIGNAL (clicked (int, int, int, const QPoint &)), this, SLOT (slotSetSelection (int, int, int, const QPoint &)));

	connect (btnRegister, SIGNAL (clicked ()), this, SLOT (slotRegister ()));
	connect (btnBrowse, SIGNAL (clicked ()), this, SLOT (slotBrowse ()));

	serviceTask = 0L;

	selectedRow = 0;

}

void dlgJabberServices::slotSetSelection (int row, int, int, const QPoint &)
{

	tblServices->clearSelection (true);
	tblServices->addSelection (QTableSelection (row, 0, row, 1));

	// query the agent list about the selected item
	btnRegister->setDisabled (!serviceTask->agents ()[row].canRegister ());
	btnBrowse->setDisabled (!serviceTask->agents ()[row].canSearch ());

	selectedRow = row;<commit_msg>Fix crash in the services dialog when trying to click on an empty list<commit_after>
/***************************************************************************
                          dlgjabberservices.cpp  -  description
                             -------------------
    begin                : Mon Dec 9 2002
    copyright            : (C) 2002 by <NAME>
    email                : <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 <kmessagebox.h>
#include <klocale.h>
#include <kdebug.h>

#include <qpushbutton.h>
#include <qlineedit.h>
#include <qtable.h>


#include "jabberaccount.h"
#include "dlgjabberregister.h"
#include "dlgjabberbrowse.h"
#include "dlgjabberservices.h"

#include "dlgjabberservices.moc"

dlgJabberServices::dlgJabberServices (JabberAccount *account, QWidget *parent, const char *name):dlgServices (parent, name)
{
	m_account = account;

	if(m_account->isConnected())
	{
		// pre-populate the server field
		leServer->setText(m_account->server());
	}

	// disable the left margin
	tblServices->setLeftMargin (0);

	// no content for now
	tblServices->setNumRows (0);

	// disable the buttons as long as nothing has been selected
	btnRegister->setDisabled (true);
	btnBrowse->setDisabled (true);

	// allow autostretching
	tblServices->setColumnStretchable (0, true);
	tblServices->setColumnStretchable (1, true);

	// disable user selections
	tblServices->setSelectionMode (QTable::NoSelection);

	// name table headers
	tblServices->horizontalHeader ()->setLabel (0, i18n ("Name"));
	tblServices->horizontalHeader ()->setLabel (1, i18n ("Address"));

	connect (btnQuery, SIGNAL (clicked ()), this, SLOT (slotQuery ()));
	connect (tblServices, SIGNAL (clicked (int, int, int, const QPoint &)), this, SLOT (slotSetSelection (int, int, int, const QPoint &)));

	connect (btnRegister, SIGNAL (clicked ()), this, SLOT (slotRegister ()));
	connect (btnBrowse, SIGNAL (clicked ()), this, SLOT (slotBrowse ()));

	serviceTask = 0L;

	selectedRow = 0;

}

void dlgJabberServices::slotSetSelection (int row, int, int, const QPoint &)
{

	if(serviceTask && (row <= serviceTask->agents().count()))
	{
		tblServices->clearSelection (true);
		tblServices->addSelection (QTableSelection (row, 0, row, 1));

		// query the agent list about the selected item
		btnRegister->setDisabled (!serviceTask->agents ()[row].canRegister ());
		btnBrowse->setDisabled (!serviceTask->agents ()[row].canSearch ());

		selectedRow = row;
	}
{'fraction_non_alphanumeric': 0.2137693066053237, 'fraction_numerical': 0.007886953664147224, 'mean_word_length': 3.1634746922024624, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6528385', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1633, 'n_words': 459}