File indexing completed on 2024-04-21 15:42:59
0001 /* 0002 * This file is part of TelepathyLoggerQt 0003 * 0004 * Copyright (C) 2011 Stefano Sanfilippo <stefano.k.sanfilippo@gmail.com> 0005 * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/> 0006 * 0007 * This library is free software; you can redistribute it and/or modify 0008 * it under the terms of the GNU Lesser General Public License as published 0009 * by the Free Software Foundation; either version 2.1 of the License, or 0010 * (at your option) any later version. 0011 * 0012 * This program is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 * GNU General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public License 0018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #include "entity.h" 0022 #include "utils.h" 0023 0024 #include <TelepathyQt/Contact> 0025 0026 #include <telepathy-logger/entity.h> 0027 0028 using namespace Tpl; 0029 0030 EntityPtr Entity::create(const char *id, EntityType type, const char *alias, const char *avatarToken) 0031 { 0032 TplEntity *entity = tpl_entity_new(id, (TplEntityType) type, alias, avatarToken); 0033 return TPLoggerQtWrapper::wrap<TplEntity, Entity>(entity); 0034 } 0035 0036 EntityPtr Entity::create(const Tp::ContactPtr & contact, EntityType type) 0037 { 0038 #if 0 0039 // TODO how to go from Tp::ContactPtr to TpContact ? 0040 //TplEntity *entity = tpl_entity_new_from_tp_contact(0, (TplEntityType) type); 0041 return EntityPtr::wrap(entity, false); 0042 #else 0043 QString id = contact->id(); 0044 QString alias = contact->alias(); 0045 QString avatarToken = contact->avatarToken(); 0046 return Entity::create(id.toUtf8(), type, alias.toUtf8(), avatarToken.toUtf8()); 0047 #endif 0048 } 0049 0050 EntityPtr Entity::create(const char *room_id) 0051 { 0052 TplEntity *entity = tpl_entity_new_from_room_id(room_id); 0053 return TPLoggerQtWrapper::wrap<TplEntity, Entity>(entity, false); 0054 } 0055 0056 QString Entity::alias() const 0057 { 0058 const gchar *s = tpl_entity_get_alias(object<TplEntity>()); 0059 QString str = QString::fromUtf8(s); 0060 return str; 0061 } 0062 0063 QString Entity::identifier() const 0064 { 0065 const gchar *s = tpl_entity_get_identifier(object<TplEntity>()); 0066 QString str = QString::fromUtf8(s); 0067 return str; 0068 } 0069 0070 EntityType Entity::entityType() const 0071 { 0072 TplEntityType entityType = tpl_entity_get_entity_type(object<TplEntity>()); 0073 return EntityType(entityType); 0074 } 0075 0076 QString Entity::avatarToken() const 0077 { 0078 const gchar *s = tpl_entity_get_avatar_token(object<TplEntity>()); 0079 QString str = QString::fromUtf8(s); 0080 return str; 0081 }