<commit_before>/*
    kopeteaccountmanager.cpp - Kopete Account Manager

    Copyright (c) 2002-2003 by <NAME>      <<EMAIL>>
    Copyright (c) 2003      by <NAME>       <<EMAIL>>

    Kopete    (c) 2002-2004 by the Kopete developers <<EMAIL>>

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

#include "kopeteaccountmanager.h"

#include <qapplication.h>
#include <qregexp.h>
#include <qtimer.h>

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

#include "kopeteaccount.h"
#include "kopeteaway.h"
#include "kopeteprotocol.h"
#include "kopetecontact.h"
#include "kopetepluginmanager.h"

class KopeteAccountPtrList : public QPtrList<KopeteAccount>
{
	protected:
		int compareItems( KopeteAccountPtrList::Item a, KopeteAccountPtrList::Item b )
		{
			uint priority1 = static_cast<KopeteAccount*>(a)->priority();
			uint priority2 = static_cast<KopeteAccount*>(b)->priority();

			if( priority1 == priority2 )
				return 0;
			else if( priority1 > priority2 )
				return 1;
			else
				return -1;
		}
};

class KopeteAccountManagerPrivate
{
public:
	static KopeteAccountManager *s_manager;

	KopeteAccountPtrList accounts;
};

KopeteAccountManager * KopeteAccountManagerPrivate::s_manager = 0L;

KopeteAccountManager * KopeteAccountManager::manager()
{
	if ( !KopeteAccountManagerPrivate::s_manager )
		KopeteAccountManagerPrivate::s_manager = new KopeteAccountManager;

	return KopeteAccountManagerPrivate::s_manager;
}

KopeteAccountManager::KopeteAccountManager()
: QObject( qApp, "KopeteAccountManager" )
{
	d = new KopeteAccountManagerPrivate;
}

KopeteAccountManager::~KopeteAccountManager()
{
	KopeteAccountManagerPrivate::s_manager = 0L;

	delete d;
}

void KopeteAccountManager::connectAll()
{
	for ( QPtrListIterator<KopeteAccount> it( d->accounts ); it.current(); ++it )
		it.current()->connect();
}

void KopeteAccountManager::disconnectAll()
{
	for ( QPtrListIterator<KopeteAccount> it( d->accounts ); it.current(); ++it )
		it.current()->disconnect();
}

void KopeteAccountManager::setAwayAll( const QString &awayReason )
{
	KopeteAway::setGlobalAway( true );

	for ( QPtrListIterator<KopeteAccount> it( d->accounts ); it.current(); ++it )
	{
		if ( it.current()->isConnected() )
			it.current()->setAway( true, awayReason.isNull() ? KopeteAway::message() : awayReason );
	}<commit_msg>When setting globally away, don't change invisible accounts to away. Matt: remember to backport :)<commit_after>/*
    kopeteaccountmanager.cpp - Kopete Account Manager

    Copyright (c) 2002-2003 by <NAME>      <<EMAIL>>
    Copyright (c) 2003      by <NAME>       <<EMAIL>>

    Kopete    (c) 2002-2004 by the Kopete developers <kopete-<EMAIL>>

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

#include "kopeteaccountmanager.h"

#include <qapplication.h>
#include <qregexp.h>
#include <qtimer.h>

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

#include "kopeteaccount.h"
#include "kopeteaway.h"
#include "kopeteprotocol.h"
#include "kopetecontact.h"
#include "kopetepluginmanager.h"

class KopeteAccountPtrList : public QPtrList<KopeteAccount>
{
	protected:
		int compareItems( KopeteAccountPtrList::Item a, KopeteAccountPtrList::Item b )
		{
			uint priority1 = static_cast<KopeteAccount*>(a)->priority();
			uint priority2 = static_cast<KopeteAccount*>(b)->priority();

			if( priority1 == priority2 )
				return 0;
			else if( priority1 > priority2 )
				return 1;
			else
				return -1;
		}
};

class KopeteAccountManagerPrivate
{
public:
	static KopeteAccountManager *s_manager;

	KopeteAccountPtrList accounts;
};

KopeteAccountManager * KopeteAccountManagerPrivate::s_manager = 0L;

KopeteAccountManager * KopeteAccountManager::manager()
{
	if ( !KopeteAccountManagerPrivate::s_manager )
		KopeteAccountManagerPrivate::s_manager = new KopeteAccountManager;

	return KopeteAccountManagerPrivate::s_manager;
}

KopeteAccountManager::KopeteAccountManager()
: QObject( qApp, "KopeteAccountManager" )
{
	d = new KopeteAccountManagerPrivate;
}

KopeteAccountManager::~KopeteAccountManager()
{
	KopeteAccountManagerPrivate::s_manager = 0L;

	delete d;
}

void KopeteAccountManager::connectAll()
{
	for ( QPtrListIterator<KopeteAccount> it( d->accounts ); it.current(); ++it )
		it.current()->connect();
}

void KopeteAccountManager::disconnectAll()
{
	for ( QPtrListIterator<KopeteAccount> it( d->accounts ); it.current(); ++it )
		it.current()->disconnect();
}

void KopeteAccountManager::setAwayAll( const QString &awayReason )
{
	KopeteAway::setGlobalAway( true );

	for ( QPtrListIterator<KopeteAccount> it( d->accounts ); it.current(); ++it )
	{
		// FIXME: ICQ's invisible online should be set to invisible away
		KopeteContact *self = it.current()->myself();
		bool isInvisible = self && self->onlineStatus().status() == KopeteOnlineStatus::Invisible;
		if ( it.current()->isConnected() && !isInvisible )
			it.current()->setAway( true, awayReason.isNull() ? KopeteAway::message() : awayReason );
	}
{'fraction_non_alphanumeric': 0.15901692708333334, 'fraction_numerical': 0.010416666666666666, 'mean_word_length': 3.7488408037094283, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 67, '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': '3378932', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1855, 'n_words': 421}