1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
kircentity.cpp - IRC Client
Copyright (c) 2004 by Michel Hermier <michel.hermier@wanadoo.fr>
Kopete (c) 2004 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
*************************************************************************
*/
#include "kircengine.h"
#include "kircentity.h"
#include <kdebug.h>
using namespace KIRC;
using namespace KNetwork;
/**
* Match a possible user definition:
* nick!user@host
* where user and host are optionnal.
* NOTE: If changes are done to the regexp string, update also the sm_userStrictRegExp regexp string.
*/
const QRegExp Entity::sm_userRegExp(QString::fromLatin1("^([^\\s,:!@]+)(?:(?:!([^\\s,:!@]+))?(?:@([^\\s,!@]+)))?$"));
/**
* Regexp to match strictly the complete user definition:
* nick!user@host
* NOTE: If changes are done to the regexp string, update also the sm_userRegExp regexp string.
*/
const QRegExp Entity::sm_userStrictRegExp(QString::fromLatin1("^([^\\s,:!@]+)!([^\\s,:!@]+)@([^\\s,:!@]+)$"));
const QRegExp Entity::sm_channelRegExp( QString::fromLatin1("^[#!+&][^\\s,]+$") );
Entity::Entity(const QString &, const Type type)
: QObject(0, "KIRC::Entity"),
m_type(type)
{
// rename(name, type);
}
Entity::~Entity()
{
emit destroyed(this);
}
QString Entity::name() const
{
return m_name;
}
QString Entity::host() const
{
switch(m_type)
{
// case Unknown:
case Server:
return m_name;
// case Channel:
case Service:
case User:
return userHost();
default:
kdDebug(14121) << k_funcinfo << "No host defined for type:" << m_type;
return QString::null;
}
}
KIRC::Entity::Type Entity::type() const
{
return m_type;
}
KIRC::Entity::Type Entity::guessType()
{
m_type = guessType(m_name);
return m_type;
}
// FIXME: Implement me
KIRC::Entity::Type Entity::guessType(const QString &)
{
return Unknown;
}
QString Entity::userNick() const
{
return userNick(m_name);
}
QString Entity::userNick(const QString &s)
{
return userInfo(s, 1);
}
QString Entity::userName() const
{
return userName(m_name);
}
QString Entity::userName(const QString &s)
{
return userInfo(s, 2);
}
QString Entity::userHost() const
{
return userHost(m_name);
}
QString Entity::userHost(const QString &s)
{
return userInfo(s, 3);
}
QString Entity::userInfo(const QString &s, int num)
{
QRegExp userRegExp(sm_userRegExp);
userRegExp.search(s);
return userRegExp.cap(num);
}
#include "kircentity.moc"
|