1 /* 2 * %kadu copyright begin% 3 * Copyright 2015 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com) 4 * %kadu copyright end% 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "jabber-presence-service.h" 21 22 #include "status/status-type.h" 23 #include "status/status.h" 24 25 #include <qxmpp/QXmppPresence.h> 26 JabberPresenceService(QObject * parent)27JabberPresenceService::JabberPresenceService(QObject *parent) : 28 QObject{parent} 29 { 30 } 31 ~JabberPresenceService()32JabberPresenceService::~JabberPresenceService() 33 { 34 } 35 statusToPresence(const Status & status)36QXmppPresence JabberPresenceService::statusToPresence(const Status &status) 37 { 38 auto result = QXmppPresence{}; 39 result.setType(QXmppPresence::Available); 40 result.setStatusText(status.description()); 41 42 switch (status.type()) 43 { 44 case StatusType::FreeForChat: 45 result.setAvailableStatusType(QXmppPresence::Chat); 46 break; 47 case StatusType::Online: 48 result.setAvailableStatusType(QXmppPresence::Online); 49 break; 50 case StatusType::Away: 51 result.setAvailableStatusType(QXmppPresence::Away); 52 break; 53 case StatusType::NotAvailable: 54 result.setAvailableStatusType(QXmppPresence::XA); 55 break; 56 case StatusType::DoNotDisturb: 57 result.setAvailableStatusType(QXmppPresence::DND); 58 break; 59 case StatusType::Invisible: 60 result.setAvailableStatusType(QXmppPresence::DND); 61 break; 62 case StatusType::Offline: 63 default: 64 result.setType(QXmppPresence::Unavailable); 65 break; 66 } 67 68 return result; 69 } 70 presenceToStatus(const QXmppPresence & presence)71Status JabberPresenceService::presenceToStatus(const QXmppPresence &presence) 72 { 73 auto status = Status{}; 74 if (presence.type() == QXmppPresence::Available) 75 { 76 switch (presence.availableStatusType()) 77 { 78 case QXmppPresence::AvailableStatusType::Online: 79 status.setType(StatusType::Online); 80 break; 81 case QXmppPresence::AvailableStatusType::Away: 82 status.setType(StatusType::Away); 83 break; 84 case QXmppPresence::AvailableStatusType::XA: 85 status.setType(StatusType::NotAvailable); 86 break; 87 case QXmppPresence::AvailableStatusType::DND: 88 status.setType(StatusType::DoNotDisturb); 89 break; 90 case QXmppPresence::AvailableStatusType::Chat: 91 status.setType(StatusType::FreeForChat); 92 break; 93 case QXmppPresence::AvailableStatusType::Invisible: 94 status.setType(StatusType::DoNotDisturb); 95 break; 96 } 97 } 98 else if (presence.type() == QXmppPresence::Unavailable) 99 status.setType(StatusType::Offline); 100 101 status.setDescription(presence.statusText()); 102 103 return status; 104 } 105 106 #include "moc_jabber-presence-service.cpp" 107