<commit_before>/*
    msnaccount.h - Manages a single MSN account

    Copyright (c) 2003 by <NAME>        <<EMAIL>>
    Kopete    (c) 2003 by the Kopete developers  <<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 <kdebug.h>
#include <kaction.h>
#include <kpopupmenu.h>
#include <klineeditdlg.h>
#include <kmessagebox.h>

#include "msnaccount.h"
#include "msncontact.h"
#include "msnnotifysocket.h"
#include "msnmessagemanager.h"
#include "msnpreferences.h"
#include "newuserimpl.h"
#include "kopetecontactlist.h"
#include "kopetemetacontact.h"

#if !defined NDEBUG
#include "msndebugrawcmddlg.h"
#endif

MSNAccount::MSNAccount( MSNProtocol *parent, const QString& AccountID, const char *name )
: KopeteAccount ( parent, AccountID , name )
{
	m_notifySocket = 0L;
	m_connectstatus = MSNProtocol::protocol()->NLN;
	m_addWizard_metaContact=0L;
	m_badpassword=false;

	// Init the myself contact
	// FIXME: I think we should add a global self metaContact (Olivier)
	m_myself = new MSNContact( this, accountId(), accountId(), 0L );
	m_myself->setOnlineStatus( MSNProtocol::protocol()->FLN );

	QObject::connect( KopeteContactList::contactList(), SIGNAL( groupRenamed( KopeteGroup *, const QString & ) ),
		SLOT( slotKopeteGroupRenamed( KopeteGroup * ) ) );
	QObject::connect( KopeteContactList::contactList(), SIGNAL( groupRemoved( KopeteGroup * ) ),
		SLOT( slotKopeteGroupRemoved( KopeteGroup * ) ) );

	m_openInboxAction = new KAction ( i18n( "Open Inbo&x" ), "mail_generic", 0, this, SLOT( slotOpenInbox() ), this, "m_openInboxAction" );
	m_openInboxAction->setEnabled(false);
}

MSNAccount::~MSNAccount()
{
}

void MSNAccount::loaded()
{
	QString publicName= pluginData(protocol(),QString::fromLatin1("displayName"));
	if(!publicName.isNull())
		m_myself->setDisplayName(publicName);
	m_blockList=QStringList::split(',' ,pluginData(protocol(),QString::fromLatin1("blockList")) );
	m_allowList=QStringList::split(',' ,pluginData(protocol(),QString::fromLatin1("allowList")) );
}

void MSNAccount::setAway( bool away, const QString & awayReason )
{
	m_awayReason=awayReason;
	if( away )
		setOnlineStatus( MSNProtocol::protocol()->IDL );
	else //if( m_myself->onlineStatus() == MSNProtocol::statusIDL )
		setOnlineStatus( MSNProtocol::protocol()->NLN );
}

KopeteContact* MSNAccount::myself() const
{
	return m_myself;
}

void MSNAccount::connect()
{
	if( isConnected() )
	{
		kdDebug(14140) << "MSNAccount::connect: Ignoring Connect request "
			<< "(Already Connected)" << endl;
		return;
	}

	if(m_notifySocket)
	{
		kdDebug(14140) << "MSNAccount::connect: Ignoring Connect request (Already connecting)"  <<endl;
		return;
	}


	QString passwd=getPassword(m_badpassword);
	if(passwd.isNull())
	{
		kdDebug(14140) << "MSNAccount::connect: Abort connection (null password)"  <<endl;
		return;
	}
	m_badpassword=false;

	if(contacts().count() <= 1)
	{
		//Maybe the contactlist.xml has been removed, and the serial number not updated
		// (the 1 is for the myself contact)
		setPluginData(protocol() , "serial" , "0" );
	}


	m_notifySocket = new MSNNotifySocket( this, accountId() );

	QObject::connect( m_notifySocket, SIGNAL( groupAdded( const QString&, uint ) ),
		SLOT( slotGroupAdded( const QString&, uint  ) ) );
	QObject::connect( m_notifySocket, SIGNAL( groupRenamed( const QString&, uint ) ),
		SLOT( slotGroupRenamed( const QString&, uint ) ) );
	QObject::connect( m_notifySocket, SIGNAL( groupListed( const QString&, uint ) ),
		SLOT( slotGroupAdded( const QString&, uint ) ) );
	QObject::connect( m_notifySocket, SIGNAL(groupRemoved( uint ) ),
		SLOT( slotGroupRemoved( uint ) ) );
	QObject::connect( m_notifySocket, SIGNAL( contactList( const QString&, const QString&, const QString&, const QString& ) ),
		SLOT( slotContactListed( const QString&, const QString&, const QString&, const QString& ) ) );
	QObject::connect( m_notifySocket, SIGNAL( contactAdded( const QString&, const QString&, const QString&, uint ) ),
		SLOT( slotContactAdded( const QString&, const QString&, const QString&, uint ) ) );
	QObject::connect( m_notifySocket, SIGNAL( contactRemoved( const QString&, const QString&, uint ) ),
		SLOT( slotContactRemoved( const QString&, const QString&, uint ) ) );
	QObject::connect( m_notifySocket, SIGNAL( statusChanged( const KopeteOnlineStatus & ) ),
		SLOT( slotStatusChanged( const KopeteOnlineStatus & ) ) );
	QObject::connect( m_notifySocket, SIGNAL( onlineStatusChanged( MSNSocket::OnlineStatus ) ),
		SLOT( slotNotifySocketStatusChanged( MSNSocket::OnlineStatus ) ) );
	QObject::connect( m_notifySocket, SIGNAL( publicNameChanged( const QString& ) ),
		SLOT( slotPublicNameChanged( const QString& ) ) );
	QObject::connect( m_notifySocket, SIGNAL( invitedToChat( const QString&, const QString&, const QString&, const QString&, const QString& ) ),
		SLOT( slotCreateChat( const QString&, const QString&, const QString&, const QString&, const QString& ) ) );
	QObject::connect( m_notifySocket, SIGNAL( startChat( const QString&, const QString& ) ),
		SLOT( slotCreateChat( const QString&, const QString& ) ) );
	QObject::connect( m_notifySocket, SIGNAL( socketClosed( int ) ),
		SLOT( slotNotifySocketClosed( int ) ) );
	QObject::connect( m_notifySocket, SIGNAL( newContactList() ) ,
		SLOT( slotNewContactList() ) );
	QObject::connect( m_notifySocket, SIGNAL( hotmailSeted( bool ) ),
		m_openInboxAction, SLOT( setEnabled( bool ) ) );


	m_notifySocket->setStatus( m_connectstatus );
	m_notifySocket->connect( passwd );
	m_myself->setOnlineStatus( MSNProtocol::protocol()->CNT );
	m_openInboxAction->setEnabled(false);

}
void MSNAccount::disconnect()
{
	if( m_notifySocket )
		m_notifySocket->disconnect();
}

KActionMenu* MSNAccount::actionMenu()
{
	KActionMenu *m_actionMenu = new KActionMenu( accountId(), this );
	m_actionMenu->popupMenu()->insertTitle( m_myself->onlineStatus().iconFor( m_myself ), i18n( "%2 <%1>" ).
#if QT_VERSION < 0x030200
		arg( accountId() ).arg( m_myself->displayName() )
#else
		arg( accountId(), m_myself->displayName() )
#endif
	);

	m_actionMenu->insert( new KAction ( i18n("Go O&nline"), MSNProtocol::protocol()->NLN.iconFor( this ), 0, this, SLOT(slotGoOnline()), m_actionMenu, "actionMSNConnect" ) );
	m_actionMenu->insert( new KAction ( i18n("Go &Offline"), MSNProtocol::protocol()->FLN.iconFor( this ), 0, this, SLOT(slotGoOffline()), m_actionMenu, "actionMSNConnect" ) );
	m_actionMenu->insert( new KAction ( i18n("Set &Away"), MSNProtocol::protocol()->AWY.iconFor( this ), 0, this, SLOT(slotGoAway()), m_actionMenu, "actionMSNConnect" ) );
	m_actionMenu->insert( new KAction ( i18n("Set &Busy"), MSNProtocol::protocol()->BSY.iconFor( this ), 0, this, SLOT(slotGoBusy()), m_actionMenu, "actionMSNConnect")  );
	m_actionMenu->insert( new KAction ( i18n("Set Be &Right Back"), MSNProtocol::protocol()->BRB.iconFor( this ), 0, this, SLOT(slotGoBeRightBack()), m_actionMenu, "actionMSNConnect" ) );
	m_actionMenu->insert( new KAction ( i18n("Set on &Phone"), MSNProtocol::protocol()->PHN.iconFor( this ), 0, this, SLOT(slotGoOnThePhone()), m_actionMenu, "actionMSNConnect" ) );
	m_actionMenu->insert( new KAction ( i18n("Set Out to &Lunch"), MSNProtocol::protocol()->LUN.iconFor( this ), 0, this, SLOT(slotGoOutToLunch()), m_actionMenu, "actionMSNConnect" ) );
	m_actionMenu->insert( new KAction ( i18n("Set &Invisible"), MSNProtocol::protocol()->HDN.iconFor( this ), 0, this, SLOT(slotGoInvisible()), m_actionMenu, "actionMSNConnect" ) );

	m_actionMenu->popupMenu()->insertSeparator();
	m_actionMenu->insert( new KAction ( i18n( "&Change Nickname..." ), QString::null, 0, this, SLOT( slotChangePublicName() ), m_actionMenu, "renameAction" ) );
	m_actionMenu->insert( new KAction ( i18n( "&Start Chat..." ), "mail_generic", 0, this, SLOT( slotStartChat() ), m_actionMenu, "startChatAction" ) );
	m_actionMenu->popupMenu()->insertSeparator();
	m_actionMenu->insert( m_openInboxAction );

#if !defined NDEBUG
	KActionMenu *debugMenu = new KActionMenu( "Debug", m_actionMenu );
	debugMenu->insert( new KAction( i18n( "Send Raw C&ommand..." ), 0, this, SLOT( slotDebugRawCommand() ), debugMenu, "m_debugRawCommand" ) );
	m_actionMenu->popupMenu()->insertSeparator();
	m_actionMenu->insert( debugMenu );
#endif

	return m_actionMenu;
}

MSNNotifySocket *MSNAccount::notifySocket() 
{
	return m_notifySocket;<commit_msg>Make the MSN account menu in the right order<commit_after>/*
    msnaccount.h - Manages a single MSN account

    Copyright (c) 2003 by <NAME>        <<EMAIL>>
    Kopete    (c) 2003 by the Kopete developers  <<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 <kdebug.h>
#include <kaction.h>
#include <kpopupmenu.h>
#include <klineeditdlg.h>
#include <kmessagebox.h>

#include "msnaccount.h"
#include "msncontact.h"
#include "msnnotifysocket.h"
#include "msnmessagemanager.h"
#include "msnpreferences.h"
#include "newuserimpl.h"
#include "kopetecontactlist.h"
#include "kopetemetacontact.h"

#if !defined NDEBUG
#include "msndebugrawcmddlg.h"
#endif

MSNAccount::MSNAccount( MSNProtocol *parent, const QString& AccountID, const char *name )
: KopeteAccount ( parent, AccountID , name )
{
	m_notifySocket = 0L;
	m_connectstatus = MSNProtocol::protocol()->NLN;
	m_addWizard_metaContact=0L;
	m_badpassword=false;

	// Init the myself contact
	// FIXME: I think we should add a global self metaContact (Olivier)
	m_myself = new MSNContact( this, accountId(), accountId(), 0L );
	m_myself->setOnlineStatus( MSNProtocol::protocol()->FLN );

	QObject::connect( KopeteContactList::contactList(), SIGNAL( groupRenamed( KopeteGroup *, const QString & ) ),
		SLOT( slotKopeteGroupRenamed( KopeteGroup * ) ) );
	QObject::connect( KopeteContactList::contactList(), SIGNAL( groupRemoved( KopeteGroup * ) ),
		SLOT( slotKopeteGroupRemoved( KopeteGroup * ) ) );

	m_openInboxAction = new KAction ( i18n( "Open Inbo&x" ), "mail_generic", 0, this, SLOT( slotOpenInbox() ), this, "m_openInboxAction" );
	m_openInboxAction->setEnabled(false);
}

MSNAccount::~MSNAccount()
{
}

void MSNAccount::loaded()
{
	QString publicName= pluginData(protocol(),QString::fromLatin1("displayName"));
	if(!publicName.isNull())
		m_myself->setDisplayName(publicName);
	m_blockList=QStringList::split(',' ,pluginData(protocol(),QString::fromLatin1("blockList")) );
	m_allowList=QStringList::split(',' ,pluginData(protocol(),QString::fromLatin1("allowList")) );
}

void MSNAccount::setAway( bool away, const QString & awayReason )
{
	m_awayReason=awayReason;
	if( away )
		setOnlineStatus( MSNProtocol::protocol()->IDL );
	else //if( m_myself->onlineStatus() == MSNProtocol::statusIDL )
		setOnlineStatus( MSNProtocol::protocol()->NLN );
}

KopeteContact* MSNAccount::myself() const
{
	return m_myself;
}

void MSNAccount::connect()
{
	if( isConnected() )
	{
		kdDebug(14140) << "MSNAccount::connect: Ignoring Connect request "
			<< "(Already Connected)" << endl;
		return;
	}

	if(m_notifySocket)
	{
		kdDebug(14140) << "MSNAccount::connect: Ignoring Connect request (Already connecting)"  <<endl;
		return;
	}


	QString passwd=<PASSWORD>(m_<PASSWORD>);
	if(passwd.isNull())
	{
		kdDebug(14140) << "MSNAccount::connect: Abort connection (null password)"  <<endl;
		return;
	}
	m_badpassword=false;

	if(contacts().count() <= 1)
	{
		//Maybe the contactlist.xml has been removed, and the serial number not updated
		// (the 1 is for the myself contact)
		setPluginData(protocol() , "serial" , "0" );
	}


	m_notifySocket = new MSNNotifySocket( this, accountId() );

	QObject::connect( m_notifySocket, SIGNAL( groupAdded( const QString&, uint ) ),
		SLOT( slotGroupAdded( const QString&, uint  ) ) );
	QObject::connect( m_notifySocket, SIGNAL( groupRenamed( const QString&, uint ) ),
		SLOT( slotGroupRenamed( const QString&, uint ) ) );
	QObject::connect( m_notifySocket, SIGNAL( groupListed( const QString&, uint ) ),
		SLOT( slotGroupAdded( const QString&, uint ) ) );
	QObject::connect( m_notifySocket, SIGNAL(groupRemoved( uint ) ),
		SLOT( slotGroupRemoved( uint ) ) );
	QObject::connect( m_notifySocket, SIGNAL( contactList( const QString&, const QString&, const QString&, const QString& ) ),
		SLOT( slotContactListed( const QString&, const QString&, const QString&, const QString& ) ) );
	QObject::connect( m_notifySocket, SIGNAL( contactAdded( const QString&, const QString&, const QString&, uint ) ),
		SLOT( slotContactAdded( const QString&, const QString&, const QString&, uint ) ) );
	QObject::connect( m_notifySocket, SIGNAL( contactRemoved( const QString&, const QString&, uint ) ),
		SLOT( slotContactRemoved( const QString&, const QString&, uint ) ) );
	QObject::connect( m_notifySocket, SIGNAL( statusChanged( const KopeteOnlineStatus & ) ),
		SLOT( slotStatusChanged( const KopeteOnlineStatus & ) ) );
	QObject::connect( m_notifySocket, SIGNAL( onlineStatusChanged( MSNSocket::OnlineStatus ) ),
		SLOT( slotNotifySocketStatusChanged( MSNSocket::OnlineStatus ) ) );
	QObject::connect( m_notifySocket, SIGNAL( publicNameChanged( const QString& ) ),
		SLOT( slotPublicNameChanged( const QString& ) ) );
	QObject::connect( m_notifySocket, SIGNAL( invitedToChat( const QString&, const QString&, const QString&, const QString&, const QString& ) ),
		SLOT( slotCreateChat( const QString&, const QString&, const QString&, const QString&, const QString& ) ) );
	QObject::connect( m_notifySocket, SIGNAL( startChat( const QString&, const QString& ) ),
		SLOT( slotCreateChat( const QString&, const QString& ) ) );
	QObject::connect( m_notifySocket, SIGNAL( socketClosed( int ) ),
		SLOT( slotNotifySocketClosed( int ) ) );
	QObject::connect( m_notifySocket, SIGNAL( newContactList() ) ,
		SLOT( slotNewContactList() ) );
	QObject::connect( m_notifySocket, SIGNAL( hotmailSeted( bool ) ),
		m_openInboxAction, SLOT( setEnabled( bool ) ) );


	m_notifySocket->setStatus( m_connectstatus );
	m_notifySocket->connect( passwd );
	m_myself->setOnlineStatus( MSNProtocol::protocol()->CNT );
	m_openInboxAction->setEnabled(false);

}
void MSNAccount::disconnect()
{
	if( m_notifySocket )
		m_notifySocket->disconnect();
}

KActionMenu* MSNAccount::actionMenu()
{
	KActionMenu *m_actionMenu = new KActionMenu( accountId(), this );
	m_actionMenu->popupMenu()->insertTitle( m_myself->onlineStatus().iconFor( m_myself ), i18n( "%2 <%1>" ).
#if QT_VERSION < 0x030200
		arg( accountId() ).arg( m_myself->displayName() )
#else
		arg( accountId(), m_myself->displayName() )
#endif
	);

	m_actionMenu->insert( new KAction ( i18n("Go O&nline"), MSNProtocol::protocol()->NLN.iconFor( this ), 0, this, SLOT(slotGoOnline()), m_actionMenu, "actionMSNConnect" ) );
	m_actionMenu->insert( new KAction ( i18n("Set &Away"), MSNProtocol::protocol()->AWY.iconFor( this ), 0, this, SLOT(slotGoAway()), m_actionMenu, "actionMSNConnect" ) );
	m_actionMenu->insert( new KAction ( i18n("Set &Busy"), MSNProtocol::protocol()->BSY.iconFor( this ), 0, this, SLOT(slotGoBusy()), m_actionMenu, "actionMSNConnect")  );
	m_actionMenu->insert( new KAction ( i18n("Set Be &Right Back"), MSNProtocol::protocol()->BRB.iconFor( this ), 0, this, SLOT(slotGoBeRightBack()), m_actionMenu, "actionMSNConnect" ) );
	m_actionMenu->insert( new KAction ( i18n("Set on &Phone"), MSNProtocol::protocol()->PHN.iconFor( this ), 0, this, SLOT(slotGoOnThePhone()), m_actionMenu, "actionMSNConnect" ) );
	m_actionMenu->insert( new KAction ( i18n("Set Out to &Lunch"), MSNProtocol::protocol()->LUN.iconFor( this ), 0, this, SLOT(slotGoOutToLunch()), m_actionMenu, "actionMSNConnect" ) );
	m_actionMenu->insert( new KAction ( i18n("Set &Invisible"), MSNProtocol::protocol()->HDN.iconFor( this ), 0, this, SLOT(slotGoInvisible()), m_actionMenu, "actionMSNConnect" ) );
	m_actionMenu->insert( new KAction ( i18n("Go &Offline"), MSNProtocol::protocol()->FLN.iconFor( this ), 0, this, SLOT(slotGoOffline()), m_actionMenu, "actionMSNConnect" ) );

	m_actionMenu->popupMenu()->insertSeparator();
	m_actionMenu->insert( new KAction ( i18n( "&Change Nickname..." ), QString::null, 0, this, SLOT( slotChangePublicName() ), m_actionMenu, "renameAction" ) );
	m_actionMenu->insert( new KAction ( i18n( "&Start Chat..." ), "mail_generic", 0, this, SLOT( slotStartChat() ), m_actionMenu, "startChatAction" ) );
	m_actionMenu->popupMenu()->insertSeparator();
	m_actionMenu->insert( m_openInboxAction );

#if !defined NDEBUG
	KActionMenu *debugMenu = new KActionMenu( "Debug", m_actionMenu );
	debugMenu->insert( new KAction( i18n( "Send Raw C&ommand..." ), 0, this, SLOT( slotDebugRawCommand() ), debugMenu, "m_debugRawCommand" ) );
	m_actionMenu->popupMenu()->insertSeparator();
	m_actionMenu->insert( debugMenu );
#endif

	return m_actionMenu;
}

MSNNotifySocket *MSNAccount::notifySocket()
{
	return m_notifySocket;
{'fraction_non_alphanumeric': 0.1614027200179836, 'fraction_numerical': 0.008991794987074295, 'mean_word_length': 5.305811481218994, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 119, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '898157', 'n_tokens_mistral': 6116, 'n_tokens_neox': 5822, 'n_words': 1329}