summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/irc/libkirc/kircentity.cpp
blob: 2086ab9d8fc0fc5809e7a3c3c419c9e80589e00c (plain)
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 TQRegExp Entity::sm_userRegExp(TQString::tqfromLatin1("^([^\\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 TQRegExp Entity::sm_userStrictRegExp(TQString::tqfromLatin1("^([^\\s,:!@]+)!([^\\s,:!@]+)@([^\\s,:!@]+)$"));

const TQRegExp Entity::sm_channelRegExp( TQString::tqfromLatin1("^[#!+&][^\\s,]+$") );

Entity::Entity(const TQString &, const Type type)
	: TQObject(0, "KIRC::Entity"),
	  m_type(type)
{
//	rename(name, type);
}

Entity::~Entity()
{
	emit destroyed(this);
}

TQString Entity::name() const
{
	return m_name;
}

TQString 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 TQString();
	}
}

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 TQString &)
{
	return Unknown;
}

TQString Entity::userNick() const
{
	return userNick(m_name);
}

TQString Entity::userNick(const TQString &s)
{
	return userInfo(s, 1);
}

TQString Entity::userName() const
{
	return userName(m_name);
}

TQString Entity::userName(const TQString &s)
{
	return userInfo(s, 2);
}

TQString Entity::userHost() const
{
	return userHost(m_name);
}

TQString Entity::userHost(const TQString &s)
{
	return userInfo(s, 3);
}

TQString Entity::userInfo(const TQString &s, int num)
{
	TQRegExp userRegExp(sm_userRegExp);
	userRegExp.search(s);
	return userRegExp.cap(num);
}

#include "kircentity.moc"