2 wlmcontact.cpp - Kopete Wlm Protocol
4 Copyright (c) 2008 by Tiago Salem Herrmann <tiagosh@gmail.com>
5 Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
7 *************************************************************************
9 * This library is free software; you can redistribute it and/or *
10 * modify it under the terms of the GNU General Public *
11 * License as published by the Free Software Foundation; either *
12 * version 2 of the License, or (at your option) any later version. *
14 *************************************************************************
17 #include "wlmcontact.h"
22 #include <ktoggleaction.h>
23 #include <kactioncollection.h>
24 #include <kmessagebox.h>
25 #include <kfiledialog.h>
26 #include <KToolInvocation>
29 #include "kopeteaccount.h"
30 #include "kopetechatsessionmanager.h"
31 #include "kopetemetacontact.h"
32 #include "kopeteuiglobal.h"
34 #include "ui_wlminfo.h"
35 #include "wlmaccount.h"
36 #include "wlmprotocol.h"
38 WlmContact::WlmContact (Kopete::Account
* _account
,
39 const QString
& uniqueName
,
40 const QString
& contactSerial
,
41 const QString
& displayName
,
42 Kopete::MetaContact
* parent
):
43 Kopete::Contact (_account
, uniqueName
, parent
)
45 kDebug (14210) << k_funcinfo
<< " uniqueName: " << uniqueName
<<
46 ", displayName: " << displayName
;
48 m_account
= qobject_cast
<WlmAccount
*>(account());
49 setFileCapable (true);
50 setOnlineStatus (WlmProtocol::protocol ()->wlmOffline
);
51 m_contactSerial
= contactSerial
;
53 m_actionBlockContact
= new KToggleAction(KIcon("wlm_blocked"), i18n("Block Contact"), this );
54 QObject::connect( m_actionBlockContact
, SIGNAL(triggered(bool)), this, SLOT(blockContact(bool)) );
56 m_actionShowProfile
= new KAction(i18n("Show Profile"), this);
57 QObject::connect(m_actionShowProfile
, SIGNAL(triggered(bool)), this, SLOT(slotShowProfile()));
60 WlmContact::~WlmContact ()
65 WlmContact::isReachable ()
67 // always true, as we can send offline messages
72 WlmContact::slotShowProfile()
74 KToolInvocation::invokeBrowser(QString::fromLatin1("http://members.msn.com/default.msnw?mem=") + contactId()) ;
78 WlmContact::sendFile (const KUrl
& sourceURL
, const QString
& fileName
,
86 if (!sourceURL
.isValid ())
88 KFileDialog::getOpenFileName (KUrl (), "*", 0l,
89 i18n ("Kopete File Transfer"));
91 filePath
= sourceURL
.path (KUrl::RemoveTrailingSlash
);
93 if (!filePath
.isEmpty ())
95 quint32 fileSize
= QFileInfo (filePath
).size ();
97 static_cast <WlmChatSession
*>
98 (manager (Kopete::Contact::CanCreate
))->sendFile (filePath
,
104 WlmContact::serialize (QMap
< QString
, QString
> &serializedData
,
105 QMap
< QString
, QString
> & /* addressBookData */ )
107 serializedData
["displayPicture"] =
108 property (Kopete::Global::Properties::self ()->photo ()).value ().
110 serializedData
["contactSerial"] = m_contactSerial
;
113 Kopete::ChatSession
*
114 WlmContact::manager (Kopete::Contact::CanCreateFlags canCreate
)
116 Kopete::ContactPtrList chatmembers
;
117 chatmembers
.append (this);
119 Kopete::ChatSession
* _manager
=
120 Kopete::ChatSessionManager::self ()->
121 findChatSession (account ()->myself (), chatmembers
, protocol ());
122 WlmChatSession
*manager
= qobject_cast
<WlmChatSession
*>(_manager
);
123 if (!manager
&& canCreate
== Kopete::Contact::CanCreate
)
126 new WlmChatSession (protocol (), account ()->myself (),
132 QList
< KAction
* >* WlmContact::customContextMenuActions () //OBSOLETE
134 QList
<KAction
*> *actions
= new QList
<KAction
*>();
136 m_actionBlockContact
->setEnabled(m_account
->isConnected());
137 m_actionBlockContact
->setChecked(m_account
->isBlocked(contactId()));
138 actions
->append(m_actionBlockContact
);
139 actions
->append(m_actionShowProfile
);
141 // temporary action collection, used to apply Kiosk policy to the actions
142 KActionCollection
tempCollection((QObject
*)0);
143 tempCollection
.addAction(QLatin1String("contactBlock"), m_actionBlockContact
);
144 tempCollection
.addAction(QLatin1String("contactViewProfile"), m_actionShowProfile
);
149 void WlmContact::blockContact(bool block
)
151 if (!m_account
->isConnected())
154 m_account
->blockContact(contactId(), block
);
157 void WlmContact::slotUserInfo()
160 infoDialog
.setButtons( KDialog::Close
);
161 infoDialog
.setDefaultButton(KDialog::Close
);
162 const QString nick
= property(Kopete::Global::Properties::self()->nickName()).value().toString();
163 const QString personalMessage
= statusMessage().message();
165 info
.setupUi(infoDialog
.mainWidget());
166 info
.m_id
->setText(contactId());
167 info
.m_displayName
->setText(nick
);
168 info
.m_personalMessage
->setText(personalMessage
);
169 // info.m_phh->setText(m_phoneHome); //TODO enable and fill
170 // info.m_phw->setText(m_phoneWork);
171 // info.m_phm->setText(m_phoneMobile);
172 // info.m_reversed->setChecked(m_reversed);
174 // connect( info.m_reversed, SIGNAL(toggled(bool)) , this, SLOT(slotUserInfoDialogReversedToggled()));
176 info
.groupBox
->setVisible(false);
177 info
.m_reversed
->setVisible(false);
179 infoDialog
.setCaption(nick
);
184 WlmContact::showContactSettings ()
186 //WlmContactSettings* p = new WlmContactSettings( this );
191 WlmContact::sendMessage (Kopete::Message
& message
)
193 kDebug (14210) << k_funcinfo
;
194 // give it back to the manager to display
195 manager ()->appendMessage (message
);
196 // tell the manager it was sent successfully
197 manager ()->messageSucceeded ();
201 WlmContact::deleteContact ()
203 if (account ()->isConnected ())
205 qobject_cast
<WlmAccount
*>(account ())->server ()->mainConnection
->
206 delFromAddressBook (m_contactSerial
.toLatin1 ().data (),
207 contactId ().toLatin1 ().data ());
212 KMessageBox::error (Kopete::UI::Global::mainWidget (),
214 ("<qt>You need to go online to remove a contact from your contact list. This contact will appear again when you reconnect.</qt>"),
215 i18n ("WLM Plugin"));
220 WlmContact::receivedMessage (const QString
& message
)
222 // Create a Kopete::Message
223 Kopete::ContactPtrList contactList
;
225 contactList
.append (account ()->myself ());
226 Kopete::Message
newMessage (this, contactList
);
227 newMessage
.setPlainBody (message
);
228 newMessage
.setDirection (Kopete::Message::Inbound
);
230 // Add it to the manager
231 manager ()->appendMessage (newMessage
);
235 WlmContact::slotChatSessionDestroyed ()
237 //FIXME: the chat window was closed? Take appropriate steps.
242 WlmContact::setOnlineStatus(const Kopete::OnlineStatus
& status
)
244 bool isBlocked
= qobject_cast
<WlmAccount
*>(account())->isOnBlockList(contactId());
246 // if this contact is blocked, and currently has a regular status,
247 // create a custom status and add wlm_blocked to ovelayIcons
248 if(isBlocked
&& status
.internalStatus() < 15)
250 Kopete::Contact::setOnlineStatus(
251 Kopete::OnlineStatus(status
.status() ,
252 (status
.weight()==0) ? 0 : (status
.weight() -1),
254 status
.internalStatus()+15,
255 status
.overlayIcons() + QStringList("wlm_blocked"),
256 i18n("%1|Blocked", status
.description() ) ) );
258 else if (!isBlocked
&& status
.internalStatus() >= 15)
260 // if this contact was previously blocked, set a regular status again
261 switch(status
.internalStatus()-15)
264 Kopete::Contact::setOnlineStatus(WlmProtocol::protocol()->wlmOnline
);
267 Kopete::Contact::setOnlineStatus(WlmProtocol::protocol()->wlmAway
);
270 Kopete::Contact::setOnlineStatus(WlmProtocol::protocol()->wlmBusy
);
273 Kopete::Contact::setOnlineStatus(WlmProtocol::protocol()->wlmBeRightBack
);
276 Kopete::Contact::setOnlineStatus(WlmProtocol::protocol()->wlmOnThePhone
);
279 Kopete::Contact::setOnlineStatus(WlmProtocol::protocol()->wlmOutToLunch
);
282 Kopete::Contact::setOnlineStatus(WlmProtocol::protocol()->wlmInvisible
);
285 Kopete::Contact::setOnlineStatus(WlmProtocol::protocol()->wlmOffline
);
288 Kopete::Contact::setOnlineStatus(WlmProtocol::protocol()->wlmIdle
);
291 Kopete::Contact::setOnlineStatus(WlmProtocol::protocol()->wlmUnknown
);
297 Kopete::Contact::setOnlineStatus(status
);
300 #include "wlmcontact.moc"
302 // vim: set noet ts=4 sts=4 sw=4: