summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/msn/msnprotocol.cpp
blob: a3ab2532dde0356cdf578ec1ba07c4062492f40a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
    msnprotocol.cpp - Kopete MSN Protocol Plugin

    Copyright (c) 2002      by Duncan Mac-Vicar Prett <duncan@kde.org>
    Copyright (c) 2002-2003 by Martijn Klingens       <klingens@kde.org>
    Copyright (c) 2002-2003 by Olivier Goffart        <ogoffart @ kde.org>
    Copyright (c) 2005      by Michaƫl Larouche       <michael.larouche@kdemail.net>

    Kopete    (c) 2002-2003 by the Kopete developers  <kopete-devel@kde.org>

    *************************************************************************
    *                                                                       *
    * 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 <tqimage.h>

#include <kdebug.h>
#include <kgenericfactory.h>
#include <kconfig.h>
#include <tdeversion.h>
#include <kaboutdata.h>

#include "kopeteaccountmanager.h"
#include "kopeteglobal.h"
#include "kopeteonlinestatusmanager.h"

#include "msnaddcontactpage.h"
#include "msneditaccountwidget.h"
#include "msncontact.h"
#include "msnaccount.h"
#include "msnprotocol.h"
#include "msnchatsession.h"

typedef KGenericFactory<MSNProtocol> MSNProtocolFactory;
#if KDE_IS_VERSION(3,2,90)
static const KAboutData aboutdata("kopete_msn", I18N_NOOP("MSN Messenger") , "1.0" );
K_EXPORT_COMPONENT_FACTORY( libkopete_msn_shared, MSNProtocolFactory( &aboutdata ) )
#else
K_EXPORT_COMPONENT_FACTORY( libkopete_msn_shared, MSNProtocolFactory( "kopete_msn" ) )
#endif

MSNProtocol *MSNProtocol::s_protocol = 0L;

MSNProtocol::MSNProtocol( TQObject *parent, const char *name, const TQStringList & /* args */ )
: Kopete::Protocol( MSNProtocolFactory::instance(), parent, name ),
	NLN( Kopete::OnlineStatus::Online,    25, this, 1, TQString(),               i18n( "Online" ) ,           i18n( "O&nline" ),        Kopete::OnlineStatusManager::Online,Kopete::OnlineStatusManager::HasAwayMessage ),
	BSY( Kopete::OnlineStatus::Away,      20, this, 2, "msn_busy",                  i18n( "Busy" ) ,             i18n( "&Busy" ),          Kopete::OnlineStatusManager::Busy,  Kopete::OnlineStatusManager::HasAwayMessage ),
	BRB( Kopete::OnlineStatus::Away,      22, this, 3, "msn_brb",                   i18n( "Be Right Back" ),     i18n( "Be &Right Back" ) ,  0  ,                              Kopete::OnlineStatusManager::HasAwayMessage ),
	AWY( Kopete::OnlineStatus::Away,      18, this, 4, "contact_away_overlay",      i18n( "Away From Computer" ),i18n( "&Away" ),          Kopete::OnlineStatusManager::Away,  Kopete::OnlineStatusManager::HasAwayMessage ),
	PHN( Kopete::OnlineStatus::Away,      12, this, 5, "contact_phone_overlay",     i18n( "On the Phone" ) ,     i18n( "On The &Phone" )  ,  0  ,                              Kopete::OnlineStatusManager::HasAwayMessage ),
	LUN( Kopete::OnlineStatus::Away,      15, this, 6, "contact_food_overlay",      i18n( "Out to Lunch" ) ,     i18n( "Out To &Lunch" )  ,  0  ,                              Kopete::OnlineStatusManager::HasAwayMessage ),
	FLN( Kopete::OnlineStatus::Offline,    0, this, 7, TQString(),               i18n( "Offline" ) ,          i18n( "&Offline" ),       Kopete::OnlineStatusManager::Offline,Kopete::OnlineStatusManager::DisabledIfOffline ),
	HDN( Kopete::OnlineStatus::Invisible,  3, this, 8, "contact_invisible_overlay", i18n( "Invisible" ) ,        i18n( "&Invisible" ),     Kopete::OnlineStatusManager::Invisible ), 
	IDL( Kopete::OnlineStatus::Away,      10, this, 9, "contact_away_overlay",      i18n( "Idle" ) ,             i18n( "&Idle" ),          Kopete::OnlineStatusManager::Idle , Kopete::OnlineStatusManager::HideFromMenu ),
	UNK( Kopete::OnlineStatus::Unknown,   25, this, 0, "status_unknown",            i18n( "Status not available" ) ),
	CNT( Kopete::OnlineStatus::Connecting, 2, this, 10,"msn_connecting",            i18n( "Connecting" ) ),
	propEmail(Kopete::Global::Properties::self()->emailAddress()),
	propPhoneHome(Kopete::Global::Properties::self()->privatePhone()),
	propPhoneWork(Kopete::Global::Properties::self()->workPhone()),
	propPhoneMobile(Kopete::Global::Properties::self()->privateMobilePhone()),
	propClient("client", i18n("Remote Client"), 0, false),
	propGuid("guid", i18n("Contact GUID"), 0, true),
	propPersonalMessage(Kopete::Global::Properties::self()->awayMessage())
{
	s_protocol = this;

	addAddressBookField( "messaging/msn", Kopete::Plugin::MakeIndexField );

	setCapabilities( Kopete::Protocol::BaseFgColor | Kopete::Protocol::BaseFont | Kopete::Protocol::BaseFormatting );

	// m_status = m_unknowntqStatus = UNK;
}

Kopete::Contact *MSNProtocol::deserializeContact( Kopete::MetaContact *metaContact, const TQMap<TQString, TQString> &serializedData,
	const TQMap<TQString, TQString> & /* addressBookData */ )
{
	TQString contactId   = serializedData[ "contactId" ] ;
	TQString accountId   = serializedData[ "accountId" ] ;
	TQString lists = serializedData[ "lists" ];
	TQStringList groups  = TQStringList::split( ",", serializedData[ "groups" ] );
	TQString contactGuid = serializedData[ "contactGuid" ] ;

	TQDict<Kopete::Account> accounts = Kopete::AccountManager::self()->accounts( this );

	Kopete::Account *account = accounts[ accountId ];
	if( !account )
		account = createNewAccount( accountId );

	// Create MSN contact
	MSNContact *c = new MSNContact( account, contactId, metaContact );

	for( TQStringList::Iterator it = groups.begin() ; it != groups.end(); ++it )
		c->contactAddedToGroup( *it, 0L  /* FIXME - m_groupList[ ( *it ).toUInt() ]*/ );

	c->m_obj= serializedData[ "obj" ];
	c->setInfo( "PHH" , serializedData[ "PHH" ] );
	c->setInfo( "PHW" , serializedData[ "PHW" ] );
	c->setInfo( "PHM" , serializedData[ "PHM" ] );
	c->setProperty( propGuid, contactGuid );

	c->setBlocked(  (bool)(lists.contains('B')) );
	c->setAllowed(  (bool)(lists.contains('A')) );
	c->setReversed( (bool)(lists.contains('R')) );

	return c;
}

AddContactPage *MSNProtocol::createAddContactWidget(TQWidget *parent , Kopete::Account *i)
{
	return (new MSNAddContactPage(i->isConnected(),parent));
}

KopeteEditAccountWidget *MSNProtocol::createEditAccountWidget(Kopete::Account *account, TQWidget *parent)
{
	return new MSNEditAccountWidget(this,account,parent);
}

Kopete::Account *MSNProtocol::createNewAccount(const TQString &accountId)
{
	return new MSNAccount(this, accountId);
}


// NOTE: CALL THIS ONLY BEING CONNECTED
void MSNProtocol::slotSyncContactList()
{
/*	if ( ! mIsConnected )
	{
		return;
	}
	// First, delete D marked contacts
	TQStringList localcontacts;

	contactsFile->setGroup("Default");

	contactsFile->readListEntry("Contacts",localcontacts);
	TQString tmpUin;
	tmpUin.sprintf("%d",uin);
	tmp.append(tmpUin);
	cnt=contactsFile->readNumEntry("Count",0);
*/
}

MSNProtocol* MSNProtocol::protocol()
{
	return s_protocol;
}

bool MSNProtocol::validContactId(const TQString& userid)
{
	return ( userid.contains('@') ==1 && userid.contains('.') >=1 && userid.contains(' ') == 0);
}

TQImage MSNProtocol::scalePicture(const TQImage &picture)
{
	TQImage img(picture);
	img = img.smoothScale( 96, 96, TQ_ScaleMin );
	// crop image if not square
	if(img.width() < img.height())
	{
		img = img.copy((img.width()-img.height())/2, 0, 96, 96);
	}
	else if(img.width() > img.height())
	{
		img = img.copy(0, (img.height()-img.width())/2, 96, 96);
	}

	return img;
}
#include "msnprotocol.moc"

// vim: set noet ts=4 sts=4 sw=4: