• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kopete/libkopete

  • sources
  • kde-4.14
  • kdenetwork
  • kopete
  • libkopete
kopeteidentity.cpp
Go to the documentation of this file.
1 /*
2  kopeteidentity.cpp - Kopete Identity
3 
4  Copyright (c) 2007 by Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
5  (c) 2007 Will Stephenson <wstephenson@kde.org>
6 
7  Kopete (c) 2002-2007 by the Kopete developers <kopete-devel@kde.org>
8 
9  *************************************************************************
10  * *
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU Lesser General Public *
13  * License as published by the Free Software Foundation; either *
14  * version 2 of the License, or (at your option) any later version. *
15  * *
16  *************************************************************************
17 */
18 
19 #include "kopeteidentity.h"
20 #include "kopetepropertycontainer.h"
21 #include "kopeteaccount.h"
22 #include "kopetecontact.h"
23 #include "kopeteprotocol.h"
24 
25 #include <QStringList>
26 #include <KDebug>
27 #include <KConfigGroup>
28 #include <KGlobal>
29 #include <KSharedConfigPtr>
30 #include <KLocale>
31 #include <KRandom>
32 #include <KMenu>
33 
34 #include <kdeversion.h>
35 
36 namespace Kopete
37 {
38 
39 class Identity::Private
40 {
41 public:
42  Private(const QString &i, const QString &l) : onlineStatus( OnlineStatus::Unknown )
43  {
44  id = i;
45  label = l;
46  configGroup = new KConfigGroup(KGlobal::config(), QString::fromLatin1( "Identity_%1" ).arg( id ));
47  }
48  QList<Kopete::Account*> accounts;
49  QString id;
50  QString label;
51  KConfigGroup *configGroup;
52  OnlineStatus::StatusType onlineStatus;
53  Kopete::StatusMessage statusMessage;
54 };
55 
56 Identity::Identity( const QString &id, const QString &label )
57  : d( new Private(id, label) )
58 {
59  load();
60  connect(this, SIGNAL(propertyChanged(Kopete::PropertyContainer*,QString,QVariant,QVariant)),
61  this, SLOT(slotSaveProperty(Kopete::PropertyContainer*,QString,QVariant,QVariant)));
62 }
63 
64 Identity::Identity(const QString &label)
65 : d( new Private(KRandom::randomString(10), label) )
66 {
67  connect(this, SIGNAL(propertyChanged(Kopete::PropertyContainer*,QString,QVariant,QVariant)),
68  this, SLOT(slotSaveProperty(Kopete::PropertyContainer*,QString,QVariant,QVariant)));
69 }
70 
71 Identity * Identity::clone() const
72 {
73  Identity * id = new Identity( label() );
74  QMap<QString,QString> props;
75  serializeProperties( props );
76  id->deserializeProperties( props );
77 
78  connect(id, SIGNAL(propertyChanged(Kopete::PropertyContainer*,QString,QVariant,QVariant)),
79  id, SLOT(slotSaveProperty(Kopete::PropertyContainer*,QString,QVariant,QVariant)));
80  return id;
81 }
82 
83 Identity::~Identity()
84 {
85  emit identityDestroyed(this);
86 
87  delete d->configGroup;
88  delete d;
89 }
90 
91 QString Identity::id() const
92 {
93  return d->id;
94 }
95 
96 QString Identity::label() const
97 {
98  return d->label;
99 }
100 
101 void Identity::setLabel(const QString& label)
102 {
103  d->label = label;
104  emit identityChanged(this);
105 }
106 
107 bool Identity::excludeConnect() const
108 {
109  //TODO implement
110  return false;
111 }
112 
113 void Identity::setOnlineStatus( uint category, const Kopete::StatusMessage &statusMessage )
114 {
115  OnlineStatusManager::Categories katgor=(OnlineStatusManager::Categories)category;
116 
117  d->statusMessage = statusMessage;
118  foreach( Account *account , d->accounts )
119  {
120  Kopete::OnlineStatus status = OnlineStatusManager::self()->onlineStatus(account->protocol() , katgor);
121  if ( !account->excludeConnect() )
122  account->setOnlineStatus( status, statusMessage );
123  }
124 }
125 
126 void Identity::setStatusMessage( const Kopete::StatusMessage &statusMessage )
127 {
128  d->statusMessage = statusMessage;
129  foreach( Account *account , d->accounts )
130  {
131  if ( !account->excludeConnect() )
132  {
133  Kopete::Contact *self = account->myself();
134  if ( self )
135  {
136  account->setOnlineStatus( self->onlineStatus(), statusMessage );
137  }
138  }
139  }
140 }
141 
142 OnlineStatus::StatusType Identity::onlineStatus() const
143 {
144  return d->onlineStatus;
145 }
146 
147 Kopete::StatusMessage Identity::statusMessage() const
148 {
149  return d->statusMessage;
150 }
151 
152 QString Identity::toolTip() const
153 {
154 
155  QString tt = QLatin1String("<qt>");
156 
157  QString nick;
158  if ( hasProperty(Kopete::Global::Properties::self()->nickName().key()) )
159  nick = property(Kopete::Global::Properties::self()->nickName()).value().toString();
160  else
161  nick = d->label;
162 
163  tt+= i18nc( "Identity tooltip information: <nobr>ICON <b>NAME</b></nobr><br /><br />",
164  "<nobr><img src=\"kopete-identity-icon:%1\"> <b>%2</b></nobr><br /><br />",
165  QString(QUrl::toPercentEncoding( d->label )), nick );
166 
167  foreach(Account *a, d->accounts)
168  {
169  Kopete::Contact *self = a->myself();
170  QString onlineStatus = self ? self->onlineStatus().description() : i18n("Offline");
171  tt += i18nc( "Account tooltip information: <nobr>ICON <b>PROTOCOL:</b> NAME (<i>STATUS</i>)</nobr><br />",
172  "<nobr><img src=\"kopete-account-icon:%3:%4\"> <b>%1:</b> %2 (<i>%5</i>)</nobr><br />",
173  a->protocol()->displayName(), a->accountLabel(), QString(QUrl::toPercentEncoding( a->protocol()->pluginId() )),
174  QString(QUrl::toPercentEncoding( a->accountId() )), onlineStatus );
175  }
176  tt += QLatin1String("</qt>");
177  return tt;
178 }
179 
180 QString Identity::customIcon() const
181 {
182  if (hasProperty( Kopete::Global::Properties::self()->photo().key() ))
183  return property(Kopete::Global::Properties::self()->photo()).value().toString();
184  else
185  return "user-identity";
186 }
187 
188 
189 QList<Account*> Identity::accounts() const
190 {
191  return d->accounts;
192 }
193 
194 void Identity::addAccount( Kopete::Account *account )
195 {
196  // check if we already have this account
197  if ( d->accounts.indexOf( account ) != -1 )
198  return;
199 
200  d->accounts.append( account );
201 
202  if ( account->myself() )
203  {
204  connect( account->myself(),
205  SIGNAL(onlineStatusChanged(Kopete::Contact*,Kopete::OnlineStatus,Kopete::OnlineStatus)),
206  this, SLOT(updateOnlineStatus()));
207  }
208  connect(account, SIGNAL(accountDestroyed(const Kopete::Account*)),
209  this, SLOT(removeAccount(const Kopete::Account*)));
210 
211  updateOnlineStatus();
212  emit identityChanged( this );
213  emit toolTipChanged( this );
214 }
215 
216 void Identity::removeAccount( const Kopete::Account *account )
217 {
218  Kopete::Account *a = const_cast<Kopete::Account*>(account);
219  if ( !d->accounts.contains( a ) )
220  return;
221 
222  disconnect( account );
223  d->accounts.removeAll( a );
224  updateOnlineStatus();
225  emit identityChanged( this );
226  emit toolTipChanged( this );
227 }
228 
229 KConfigGroup *Identity::configGroup() const
230 {
231  return d->configGroup;
232 }
233 
234 void Identity::load()
235 {
236  QMap<QString,QString>::iterator it;
237 
238  QMap<QString,QString> props = d->configGroup->entryMap();
239  deserializeProperties(props);
240 }
241 
242 void Identity::save()
243 {
244  // FIXME: using kconfig for now, but I guess this is going to change
245  QMap<QString,QString> props;
246  serializeProperties(props);
247  QMap<QString,QString>::iterator it;
248  for (it = props.begin(); it != props.end(); ++it)
249  {
250  d->configGroup->writeEntry(it.key(), it.value());
251  }
252 }
253 
254 void Identity::updateOnlineStatus()
255 {
256  Kopete::OnlineStatus mostSignificantStatus;
257  Kopete::OnlineStatus::StatusType newStatus = Kopete::OnlineStatus::Unknown;
258 
259  foreach(Account *account, d->accounts)
260  {
261  // find most significant status
262  if ( account->myself() &&
263  account->myself()->onlineStatus() > mostSignificantStatus )
264  mostSignificantStatus = account->myself()->onlineStatus();
265  }
266 
267  newStatus = mostSignificantStatus.status();
268  if( newStatus != d->onlineStatus )
269  {
270  d->onlineStatus = newStatus;
271  emit onlineStatusChanged( this );
272  }
273  emit toolTipChanged( this );
274 }
275 
276 void Identity::slotSaveProperty( Kopete::PropertyContainer *container, const QString &key,
277  const QVariant &oldValue, const QVariant &newValue )
278 {
279  Q_UNUSED(container);
280  if ( !newValue.isValid() ) // the property was removed, remove the config entry also
281  {
282  QString cfgGrpKey = QString::fromLatin1("prop_%1_%2").arg(QString::fromLatin1(oldValue.typeName()), key );
283  d->configGroup->deleteEntry(cfgGrpKey);
284  }
285  save();
286 }
287 
288 } //END namespace Kopete
289 
290 #include "kopeteidentity.moc"
291 
292 // vim: set noet ts=4 sts=4 sw=4:
293 
Kopete::Account::accountLabel
QString accountLabel() const
The label for this account.
Definition: kopeteaccount.cpp:292
Kopete::OnlineStatus
Definition: kopeteonlinestatus.h:68
Kopete::Account::protocol
Protocol * protocol() const
Definition: kopeteaccount.cpp:216
status
OnlineStatus::StatusType status
Definition: kopeteonlinestatus.cpp:103
Kopete::Identity::toolTipChanged
void toolTipChanged(Kopete::Identity *)
Kopete::Account::myself
Contact * myself() const
Retrieve the 'myself' contact.
Definition: kopeteaccount.cpp:537
Kopete::Identity::excludeConnect
bool excludeConnect() const
This identity should be connected when connect all is called?
Definition: kopeteidentity.cpp:107
Kopete::Identity::setLabel
void setLabel(const QString &label)
Sets the label.
Definition: kopeteidentity.cpp:101
Kopete::Identity::label
QString label() const
The label is used to identify the identity in the UI.
Definition: kopeteidentity.cpp:96
Kopete::PropertyContainer::propertyChanged
void propertyChanged(Kopete::PropertyContainer *container, const QString &key, const QVariant &oldValue, const QVariant &newValue)
Kopete::Global::Properties::self
static Properties * self()
Singleton accessor for this class.
Definition: kopeteglobal.cpp:49
Kopete::Identity::statusMessage
Kopete::StatusMessage statusMessage() const
Get the current status message of the identity.
Definition: kopeteidentity.cpp:147
kopeteaccount.h
Kopete::StatusMessage
This class encapsulate a status message.
Definition: kopetestatusmessage.h:48
Kopete::Plugin::displayName
QString displayName() const
Returns the display name of this plugin.
Definition: kopeteplugin.cpp:52
QMap
Kopete::OnlineStatus::Unknown
Refers to protocols where state cannot be determined.
Definition: kopeteonlinestatus.h:90
Kopete::PropertyContainer::property
const Kopete::Property & property(const QString &key) const
Get the value of a property with key "key".
Definition: kopetepropertycontainer.cpp:111
Kopete::Identity::toolTip
QString toolTip() const
Get the tooltip for this identity.
Definition: kopeteidentity.cpp:152
Kopete::OnlineStatusManager::onlineStatus
OnlineStatus onlineStatus(Protocol *protocol, Categories category) const
return the status of the protocol which is in the category category
Definition: kopeteonlinestatusmanager.cpp:89
Kopete::OnlineStatus::status
StatusType status() const
Return the status.
Definition: kopeteonlinestatus.cpp:242
Kopete::Identity::save
void save()
Save the identity information.
Definition: kopeteidentity.cpp:242
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
Kopete::Identity::~Identity
~Identity()
Definition: kopeteidentity.cpp:83
kopetepropertycontainer.h
Kopete::Identity::configGroup
KConfigGroup * configGroup() const
Returns the KConfigGroup that should be used to read/write settings of this identity.
Definition: kopeteidentity.cpp:229
Kopete::Identity::customIcon
QString customIcon() const
Return the icon for this identity.
Definition: kopeteidentity.cpp:180
Kopete::Contact::onlineStatus
OnlineStatus onlineStatus() const
Get the online status of the contact.
Definition: kopetecontact.cpp:173
Kopete::Identity::setStatusMessage
void setStatusMessage(const Kopete::StatusMessage &statusMessage)
Sets the status message for this identity Sets the status message for each account in this identity...
Definition: kopeteidentity.cpp:126
Kopete::Identity::removeAccount
void removeAccount(const Kopete::Account *account)
Removes an account from the identity.
Definition: kopeteidentity.cpp:216
Kopete::Account::accountId
QString accountId
Definition: kopeteaccount.h:77
Kopete::Plugin::pluginId
QString pluginId() const
Get the plugin id.
Definition: kopeteplugin.cpp:46
Kopete::Account::setOnlineStatus
virtual void setOnlineStatus(const Kopete::OnlineStatus &status, const Kopete::StatusMessage &reason=Kopete::StatusMessage(), const OnlineStatusOptions &options=None)=0
Reimplement this function to set the online status.
kopeteprotocol.h
Kopete::Identity::identityDestroyed
void identityDestroyed(const Kopete::Identity *identity)
Kopete::PropertyContainer::hasProperty
bool hasProperty(const QString &key) const
Check for existence of a certain property stored using "key".
Definition: kopetepropertycontainer.cpp:106
QString
QList< Kopete::Account * >
Kopete::Account::excludeConnect
bool excludeConnect
Definition: kopeteaccount.h:78
QMap::end
iterator end()
Kopete::PropertyContainer::deserializeProperties
void deserializeProperties(const QMap< QString, QString > &serializedData)
Deserialize the contacts persistent properties.
Definition: kopetepropertycontainer.cpp:63
Kopete::Contact
Definition: kopetecontact.h:58
QMap::begin
iterator begin()
Kopete::Identity::identityChanged
void identityChanged(Kopete::Identity *identity)
Kopete::PropertyContainer::serializeProperties
void serializeProperties(QMap< QString, QString > &serializedData) const
Serialize the persistent properties for storage in the contact list.
Definition: kopetepropertycontainer.cpp:46
Kopete::Identity::accounts
QList< Account * > accounts() const
Returns the accounts assigned to this identity.
Definition: kopeteidentity.cpp:189
Kopete::Identity::Identity
Identity(const QString &label)
The main constructor for Kopete Identities.
Definition: kopeteidentity.cpp:64
QLatin1String
Kopete::Identity::onlineStatus
OnlineStatus::StatusType onlineStatus() const
Get the online status of the identity.
Definition: kopeteidentity.cpp:142
Kopete::Identity::load
void load()
Load the identity information.
Definition: kopeteidentity.cpp:234
QVariant::typeName
const char * typeName() const
Kopete::Identity::id
QString id() const
The id is a unique internal handle and should not be exposed in the UI.
Definition: kopeteidentity.cpp:91
Kopete::PropertyContainer
Definition: kopetepropertycontainer.h:39
QUrl::toPercentEncoding
QByteArray toPercentEncoding(const QString &input, const QByteArray &exclude, const QByteArray &include)
Kopete::Identity::clone
Identity * clone() const
Duplicates an existing identity.
Definition: kopeteidentity.cpp:71
Kopete::Property::value
const QVariant & value() const
Getter for this properties value.
Definition: kopeteproperty.cpp:229
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QVariant::isValid
bool isValid() const
Kopete::Identity::onlineStatusChanged
void onlineStatusChanged(Kopete::Identity *)
Kopete::OnlineStatusManager::self
static OnlineStatusManager * self()
Definition: kopeteonlinestatusmanager.cpp:49
Kopete::OnlineStatus::StatusType
StatusType
The available global states.
Definition: kopeteonlinestatus.h:78
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Kopete::Identity::updateOnlineStatus
void updateOnlineStatus()
Definition: kopeteidentity.cpp:254
Kopete::Account
The Kopete::Account class handles one account.
Definition: kopeteaccount.h:72
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QVariant::toString
QString toString() const
Kopete::Identity
Definition: kopeteidentity.h:41
kopeteidentity.h
kopetecontact.h
QMap::iterator
Kopete::Identity::addAccount
void addAccount(Kopete::Account *account)
Adds an account to the identity.
Definition: kopeteidentity.cpp:194
Kopete::Identity::setOnlineStatus
void setOnlineStatus(uint category, const Kopete::StatusMessage &statusMessage)
Sets the online status for this identity Sets the online status for each account in this identity...
Definition: kopeteidentity.cpp:113
QVariant
Kopete::Identity::slotSaveProperty
void slotSaveProperty(Kopete::PropertyContainer *container, const QString &key, const QVariant &oldValue, const QVariant &newValue)
Definition: kopeteidentity.cpp:276
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/libkopete

Skip menu "kopete/libkopete"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal