1 /*
2 * %kadu copyright begin%
3 * Copyright 2010, 2011, 2012 Piotr Galiszewski (piotr.galiszewski@kadu.im)
4 * Copyright 2009 Wojciech Treter (juzefwt@gmail.com)
5 * Copyright 2009 Bartłomiej Zimoń (uzi18@o2.pl)
6 * Copyright 2010, 2011, 2013, 2014 Bartosz Brachaczek (b.brachaczek@gmail.com)
7 * Copyright 2009, 2010, 2011, 2012, 2013, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
8 * %kadu copyright end%
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #include "accounts/account.h"
25 #include "buddies/group.h"
26 #include "chat/chat-details.h"
27 #include "chat/chat-manager.h"
28 #include "contacts/contact-set.h"
29 #include "core/injected-factory.h"
30
31 #include "chat.h"
32
33 KaduSharedBaseClassImpl(Chat)
34
35 /**
36 * @author Rafal 'Vogel' Malinowski
37 * @short Null Chat object.
38 *
39 * Null Chat object (without @link ChatShared @endlink attached).
40 */
41 Chat Chat::null;
42
Chat()43 Chat::Chat()
44 {
45 }
46
47 /**
48 * @author Rafal 'Vogel' Malinowski
49 * @short Returns new access object for given ChatShared instance.
50 * @return new access object for given ChatShared instance
51 *
52 * Returns new access object for given ChatShared instance.
53 */
Chat(ChatShared * data)54 Chat::Chat(ChatShared *data) :
55 SharedBase<ChatShared>(data)
56 {
57 }
58
59 /**
60 * @author Rafal 'Vogel' Malinowski
61 * @short Casts QObject * to Chat class.
62 * @param data QObject * instance that could be casted to Chat object
63 * @return Chat object from given data object or Chat::null if data cannot be cast to Chat.
64 *
65 * If data parameter contains object of type ChatShared this method will create access
66 * object to this data and return it. Else, Chat::null will be returned.
67 */
Chat(QObject * data)68 Chat::Chat(QObject *data)
69 {
70 ChatShared *shared = qobject_cast<ChatShared *>(data);
71 if (shared)
72 setData(shared);
73 }
74
75 /**
76 * @author Rafal 'Vogel' Malinowski
77 * @short Copy contructor for other Chat object.
78 * @param copy Chat object to copy
79 * @return Chat object that will be access object for the same data as copy object.
80 *
81 * Creates new Chat object that will be access object fot he same data as copy object.
82 */
Chat(const Chat & copy)83 Chat::Chat(const Chat ©) :
84 SharedBase<ChatShared>(copy)
85 {
86 }
87
~Chat()88 Chat::~Chat()
89 {
90 }
91
isInGroup(Group group) const92 bool Chat::isInGroup(Group group) const
93 {
94 return isNull() ? false : data()->isInGroup(group);
95 }
96
showInAllGroup() const97 bool Chat::showInAllGroup() const
98 {
99 return isNull() ? false : data()->showInAllGroup();
100 }
101
addToGroup(Group group) const102 void Chat::addToGroup(Group group) const
103 {
104 if (!isNull() && !data()->isInGroup(group))
105 data()->addToGroup(group);
106
107 }
removeFromGroup(Group group) const108 void Chat::removeFromGroup(Group group) const
109 {
110 if (!isNull() && data()->isInGroup(group))
111 data()->removeFromGroup(group);
112 }
113
KaduSharedBase_PropertyReadDef(Chat,ContactSet,contacts,Contacts,ContactSet ())114 KaduSharedBase_PropertyReadDef(Chat, ContactSet, contacts, Contacts, ContactSet())
115 KaduSharedBase_PropertyReadDef(Chat, QString, name, Name, QString())
116 KaduSharedBase_PropertyReadDef(Chat, ChatDetails *, details, Details, 0)
117 KaduSharedBase_PropertyDefCRW(Chat, Account, chatAccount, ChatAccount, Account::null)
118 KaduSharedBase_PropertyDefCRW(Chat, QString, type, Type, QString())
119 KaduSharedBase_PropertyDefCRW(Chat, QString, display, Display, QString())
120 KaduSharedBase_PropertyBoolDef(Chat, IgnoreAllMessages, false)
121 KaduSharedBase_PropertyDefCRW(Chat, QSet<Group>, groups, Groups, QSet<Group>())
122 KaduSharedBase_PropertyDef(Chat, quint16, unreadMessagesCount, UnreadMessagesCount, 0)
123
124 bool Chat::isConnected() const
125 {
126 if (!isNull())
127 return data()->isConnected();
128 else
129 return false;
130 }
131
isOpen() const132 bool Chat::isOpen() const
133 {
134 if (!isNull())
135 return data()->isOpen();
136 else
137 return false;
138 }
139
setOpen(bool open)140 void Chat::setOpen(bool open)
141 {
142 if (!isNull())
143 data()->setOpen(open);
144 }
145
title(const Chat & chat)146 QString title(const Chat& chat)
147 {
148 if (!chat.display().isEmpty())
149 return chat.display();
150 else
151 return chat.name();
152 }
153