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

Nepomuk-Core

  • KTp
presence.cpp
Go to the documentation of this file.
1 /*
2  * Global Presence - wrap Tp::Presence with KDE functionality
3  *
4  * Copyright (C) 2011 David Edmundson <kde@davidedmundson.co.uk>
5  * Copyright (C) 2012 Daniele E. Domenichelli <daniele.domenichelli@gmail.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "presence.h"
23 
24 #include <KLocalizedString>
25 #include <KIconLoader>
26 
27 namespace KTp
28 {
29 
30 Presence::Presence() :
31  Tp::Presence()
32 {
33 }
34 
35 Presence::Presence(const Tp::Presence &presence) :
36  Tp::Presence(presence)
37 {
38 }
39 
40 KIcon Presence::icon(bool useImIcons) const
41 {
42  const QString &name(iconName(useImIcons));
43  if (!name.isEmpty()) {
44  return KIcon(name);
45  }
46  return KIcon();
47 }
48 KIcon Presence::icon(QStringList overlays, bool useImIcons) const
49 {
50  const QString &name(iconName(useImIcons));
51  if (!name.isEmpty()) {
52  return KIcon(name,
53  KIconLoader::global(),
54  overlays);
55  }
56  return KIcon();
57 }
58 
59 QString Presence::iconName(bool useImIcons) const
60 {
61  switch (type()) {
62  case Tp::ConnectionPresenceTypeAvailable:
63  return useImIcons ? QLatin1String("im-user") : QLatin1String("user-online");
64  case Tp::ConnectionPresenceTypeBusy:
65  return useImIcons ? QLatin1String("im-user-busy") : QLatin1String("user-busy");
66  case Tp::ConnectionPresenceTypeAway:
67  return useImIcons ? QLatin1String("im-user-away") : QLatin1String("user-away");
68  case Tp::ConnectionPresenceTypeExtendedAway:
69  // FIXME Request an icon "im-user-away-extended"
70  return useImIcons ? QLatin1String("im-user-away") : QLatin1String("user-away-extended");
71  case Tp::ConnectionPresenceTypeHidden:
72  return useImIcons ? QLatin1String("im-invisible-user") : QLatin1String("user-invisible");
73  case Tp::ConnectionPresenceTypeOffline:
74  return useImIcons ? QLatin1String("im-user-offline") : QLatin1String("user-offline");
75  default:
76  return QString();
77  }
78 }
79 
80 bool Presence::operator <(const Presence &other) const
81 {
82  if (sortPriority(type()) < sortPriority(other.type())) {
83  return true;
84  } else if (sortPriority(type()) == sortPriority(other.type())) {
85  return (statusMessage() < other.statusMessage());
86  } else {
87  return false;
88  }
89 }
90 
91 QString Presence::displayString() const
92 {
93  switch (type()) {
94  case Tp::ConnectionPresenceTypeAvailable:
95  return i18nc("IM presence: a person is available", "Available");
96  case Tp::ConnectionPresenceTypeBusy:
97  return i18nc("IM presence: a person is busy", "Busy");
98  case Tp::ConnectionPresenceTypeAway:
99  return i18nc("IM presence: a person is away", "Away");
100  case Tp::ConnectionPresenceTypeExtendedAway:
101  return i18nc("IM presence: a person is not available", "Not Available");
102  case Tp::ConnectionPresenceTypeHidden:
103  return i18nc("IM presence: a person is invisible", "Invisible");
104  case Tp::ConnectionPresenceTypeOffline:
105  return i18nc("IM presence: a person is offline", "Offline");
106  default:
107  return QString();
108  }
109 }
110 
111 int Presence::sortPriority(const Tp::ConnectionPresenceType &type)
112 {
113  switch(type) {
114  case Tp::ConnectionPresenceTypeAvailable:
115  return 0;
116  case Tp::ConnectionPresenceTypeBusy:
117  return 1;
118  case Tp::ConnectionPresenceTypeHidden:
119  return 2;
120  case Tp::ConnectionPresenceTypeAway:
121  return 3;
122  case Tp::ConnectionPresenceTypeExtendedAway:
123  return 4;
124  //don't distinguish between the following three presences
125  case Tp::ConnectionPresenceTypeError:
126  case Tp::ConnectionPresenceTypeUnknown:
127  case Tp::ConnectionPresenceTypeUnset:
128  return 5;
129  case Tp::ConnectionPresenceTypeOffline:
130  default:
131  return 6;
132  }
133 
134  return -1;
135 }
136 
137 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Fri Mar 22 2013 10:58:52 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ktp-common-internals API Reference

Skip menu "ktp-common-internals API Reference"
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