1 /*
2 Copyright (C) 2008-2020 The Communi Project
3
4 You may use this file under the terms of BSD license as follows:
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of the copyright holder nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "ircchannel.h"
30 #include "ircchannel_p.h"
31 #include "ircuser.h"
32 #include "ircuser_p.h"
33 #include <qdebug.h>
34
35 IRC_BEGIN_NAMESPACE
36
37 /*!
38 \file ircuser.h
39 \brief \#include <IrcUser>
40 */
41
42 /*!
43 \class IrcUser ircuser.h <IrcUser>
44 \ingroup models
45 \brief Keeps track of user status on a channel.
46
47 \sa IrcUserModel
48 */
49
50 #ifndef IRC_DOXYGEN
setName(const QString & n)51 void IrcUserPrivate::setName(const QString& n)
52 {
53 Q_Q(IrcUser);
54 if (name != n) {
55 name = n;
56 emit q->nameChanged(name);
57 emit q->titleChanged(q->title());
58 }
59 }
60
setPrefix(const QString & p)61 void IrcUserPrivate::setPrefix(const QString& p)
62 {
63 Q_Q(IrcUser);
64 if (prefix != p) {
65 prefix = p;
66 emit q->prefixChanged(prefix);
67 emit q->titleChanged(q->title());
68 }
69 }
70
setMode(const QString & m)71 void IrcUserPrivate::setMode(const QString& m)
72 {
73 Q_Q(IrcUser);
74 if (mode != m) {
75 mode = m;
76 emit q->modeChanged(mode);
77 }
78 }
79
setServOp(const bool & o)80 void IrcUserPrivate::setServOp(const bool& o)
81 {
82 Q_Q(IrcUser);
83 if (servOp != o) {
84 servOp = o;
85 emit q->servOpChanged(servOp);
86 }
87 }
88
setAway(const bool & a)89 void IrcUserPrivate::setAway(const bool& a)
90 {
91 Q_Q(IrcUser);
92 if (away != a) {
93 away = a;
94 emit q->awayChanged(away);
95 }
96 }
97 #endif // IRC_DOXYGEN
98
99 /*!
100 Constructs a new user with \a parent.
101 */
IrcUser(QObject * parent)102 IrcUser::IrcUser(QObject* parent)
103 : QObject(parent), d_ptr(new IrcUserPrivate)
104 {
105 Q_D(IrcUser);
106 d->q_ptr = this;
107 d->channel = nullptr;
108 d->away = false;
109 d->servOp = false;
110 }
111
112 /*!
113 Destructs the user object.
114 */
~IrcUser()115 IrcUser::~IrcUser()
116 {
117 }
118
119 /*!
120 This property holds the title.
121
122 The title consists of \ref prefix and \ref name.
123
124 \par Access function:
125 \li QString <b>title</b>() const
126
127 \par Notifier signal:
128 \li void <b>titleChanged</b>(const QString& title)
129 */
title() const130 QString IrcUser::title() const
131 {
132 Q_D(const IrcUser);
133 return d->prefix.left(1) + d->name;
134 }
135
136 /*!
137 This property holds the name.
138
139 \par Access function:
140 \li QString <b>name</b>() const
141
142 \par Notifier signal:
143 \li void <b>nameChanged</b>(const QString& name)
144 */
name() const145 QString IrcUser::name() const
146 {
147 Q_D(const IrcUser);
148 return d->name;
149 }
150
151 /*!
152 This property holds the prefix character.
153
154 Typical prefix characters are \c @ (op) and \c + (voice).
155
156 \note The prefix may be multiple characters if the \c multi-prefix
157 capability is enabled.
158
159 \par Access function:
160 \li QString <b>prefix</b>() const
161
162 \par Notifier signal:
163 \li void <b>prefixChanged</b>(const QString& prefix)
164
165 \sa mode, \ref ircv3
166 */
prefix() const167 QString IrcUser::prefix() const
168 {
169 Q_D(const IrcUser);
170 return d->prefix;
171 }
172
173 /*!
174 This property holds the mode letter.
175
176 Typical mode letters are \c o (op) and \c v (voice).
177
178 \note The mode may be multiple characters if the \c multi-prefix
179 capability is enabled.
180
181 \par Access function:
182 \li QString <b>mode</b>() const
183
184 \par Notifier signal:
185 \li void <b>modeChanged</b>(const QString& mode)
186
187 \sa prefix, \ref ircv3
188 */
mode() const189 QString IrcUser::mode() const
190 {
191 Q_D(const IrcUser);
192 return d->mode;
193 }
194
195 /*!
196 \since 3.1
197
198 \property bool IrcUser::servOp
199 This property holds whether the user is a server operator.
200
201 \note IRC servers do not send this information by default.
202 In order to fetch the information for all users on a channel,
203 issue a WHO command on the channel:
204 \code
205 IrcChannel* channel = user->channel();
206 IrcCommand* command = IrcCommand::createWho(channel->title());
207 channel->sendCommand(command);
208 \endcode
209
210 \par Access function:
211 \li bool <b>isServOp</b>() const
212
213 \par Notifier signal:
214 \li void <b>servOpChanged</b>(bool servOp)
215 */
isServOp() const216 bool IrcUser::isServOp() const
217 {
218 Q_D(const IrcUser);
219 return d->servOp;
220 }
221
222 /*!
223 \since 3.1
224
225 \property bool IrcUser::away
226 This property holds whether the user is marked as being away.
227
228 \note IRC servers do not send this information by default.
229 In order to fetch the information for all users on a channel,
230 issue a WHO command on the channel:
231 \code
232 IrcChannel* channel = user->channel();
233 IrcCommand* command = IrcCommand::createWho(channel->title());
234 channel->sendCommand(command);
235 \endcode
236
237 \par Access function:
238 \li bool <b>isAway</b>() const
239
240 \par Notifier signal:
241 \li void <b>awayChanged</b>(bool away)
242 */
isAway() const243 bool IrcUser::isAway() const
244 {
245 Q_D(const IrcUser);
246 return d->away;
247 }
248
249 /*!
250 This property holds the channel of the user.
251
252 \par Access function:
253 \li \ref IrcChannel* <b>channel</b>() const
254 */
channel() const255 IrcChannel* IrcUser::channel() const
256 {
257 Q_D(const IrcUser);
258 return d->channel;
259 }
260
261 #ifndef QT_NO_DEBUG_STREAM
operator <<(QDebug debug,const IrcUser * user)262 QDebug operator<<(QDebug debug, const IrcUser* user)
263 {
264 if (!user)
265 return debug << "IrcUser(0x0) ";
266 debug.nospace() << user->metaObject()->className() << '(' << (void*) user;
267 if (!user->objectName().isEmpty())
268 debug.nospace() << ", name=" << qPrintable(user->objectName());
269 if (!user->name().isEmpty())
270 debug.nospace() << ", user=" << qPrintable(user->name());
271 debug.nospace() << ')';
272 return debug.space();
273 }
274 #endif // QT_NO_DEBUG_STREAM
275
276 #include "moc_ircuser.cpp"
277
278 IRC_END_NAMESPACE
279