1 /* *************************************************************************
2 * copyright: (C) 2003 Richard Lärkäng <nouseforaname@home.se> *
3 * copyright: (C) 2003 Gav Wood <gav@kde.org> *
4 *************************************************************************
7 /* *************************************************************************
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
14 *************************************************************************
18 #include <kconfigbase.h>
22 #include <kmessagebox.h>
23 #include <kactioncollection.h>
25 #include "kopetechatsessionmanager.h"
26 #include "kopeteaccount.h"
27 #include "kopeteuiglobal.h"
29 #include "smscontact.h"
30 #include "smsprotocol.h"
31 #include "smsservice.h"
32 #include "smsaccount.h"
33 #include "smsuserpreferences.h"
35 SMSContact::SMSContact( Kopete::Account
* _account
, const QString
&phoneNumber
,
36 const QString
&displayName
, Kopete::MetaContact
*parent
)
37 : Kopete::Contact( _account
, phoneNumber
, parent
), m_phoneNumber( phoneNumber
)
39 // kWarning( 14160 ) << " this = " << this << ", phone = " << phoneNumber;
40 setNickName( displayName
);
45 if( account()->isConnected() )
46 setOnlineStatus( SMSProtocol::protocol()->SMSOnline
);
49 void SMSContact::slotSendingSuccess(const Kopete::Message
&msg
)
51 manager(Kopete::Contact::CanCreate
)->messageSucceeded();
52 manager(Kopete::Contact::CanCreate
)->appendMessage((Kopete::Message
&)msg
);
55 void SMSContact::slotSendingFailure(const Kopete::Message
&/*msg*/, const QString
&error
)
57 KMessageBox::detailedError(Kopete::UI::Global::mainWidget(), i18n("Something went wrong while sending the message."), error
,
58 i18n("Could Not Send Message"));
59 // manager()->messageFailed();
60 // TODO: swap for failed as above. show it anyway for now to allow closing of window.
61 manager(Kopete::Contact::CanCreate
)->messageSucceeded();
64 void SMSContact::serialize( QMap
<QString
, QString
> &serializedData
,
65 QMap
<QString
, QString
> & /* addressBookData */ )
67 // Contact id and display name are already set for us
68 if (m_phoneNumber
!= contactId())
69 serializedData
[ "contactId" ] = m_phoneNumber
;
72 Kopete::ChatSession
* SMSContact::manager( Kopete::Contact::CanCreateFlags canCreate
)
74 if ( m_msgManager
|| canCreate
!= Kopete::Contact::CanCreate
)
80 QList
<Kopete::Contact
*> contacts
;
81 contacts
.append(this);
82 m_msgManager
= Kopete::ChatSessionManager::self()->create(account()->myself(), contacts
, protocol());
83 connect(m_msgManager
, SIGNAL(messageSent(Kopete::Message
&, Kopete::ChatSession
*)),
84 account(), SLOT(slotSendMessage(Kopete::Message
&)));
85 connect(m_msgManager
, SIGNAL(destroyed()), this, SLOT(slotChatSessionDestroyed()));
90 void SMSContact::slotChatSessionDestroyed()
96 void SMSContact::slotUserInfo()
100 void SMSContact::deleteContact()
105 const QString
SMSContact::qualifiedNumber()
107 QString number
= m_phoneNumber
;
108 dynamic_cast<SMSAccount
*>(account())->translateNumber(number
);
112 const QString
&SMSContact::phoneNumber()
114 return m_phoneNumber
;
117 void SMSContact::setPhoneNumber( const QString phoneNumber
)
120 new SMSContact(account(), phoneNumber
, nickName(), metaContact());
123 KActionCollection
* SMSContact::customContextMenuActions(QWidget
*parent
)
125 KActionCollection
*m_actionCollection
= new KActionCollection(parent
);
129 m_actionPrefs
= new KAction(i18n("&Contact Settings"),
130 m_actionCollection
);
132 // dynamic_cast<QObject*>(this),
133 // SLOT(userPrefs()),
134 // dynamic_cast<QObject*>(this),
136 QObject::connect(m_actionPrefs
,
137 SIGNAL(triggered(bool)),
138 dynamic_cast<QObject
*>(this),
142 m_actionCollection
->addAction("userPrefs", m_actionPrefs
);
144 return m_actionCollection
;
147 void SMSContact::userPrefs()
149 SMSUserPreferences
* p
= new SMSUserPreferences( this );
153 #include "smscontact.moc"
155 // vim: set noet ts=4 sts=4 sw=4: