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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
//=============================================================================
//
// File : KviIrcNetwork.cpp
// Creation date : Wed Aug 27 2008 17:44:56 by Alexey Uzhva
//
// This file is part of the KVIrc IRC client distribution
// Copyright (C) 2008 Alexey Uzhva (wizard at opendoor dot ru)
//
// 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.
//
// This program is distributed in the HOPE that it will be USEFUL,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================
#include "KviIrcNetwork.h"
#include "KviIrcServer.h"
#include "KviNickServRuleSet.h"
#include "KviQString.h"
KviIrcNetwork::KviIrcNetwork(const KviIrcNetwork & src)
{
m_pChannelList = nullptr;
m_pNickServRuleSet = nullptr;
m_pServerList = new KviPointerList<KviIrcServer>;
m_pServerList->setAutoDelete(true);
copyFrom(src);
}
KviIrcNetwork::KviIrcNetwork(const QString & name)
{
m_szName = name;
m_pChannelList = nullptr;
m_pNickServRuleSet = nullptr;
m_bAutoConnect = false;
m_pServerList = new KviPointerList<KviIrcServer>;
m_pServerList->setAutoDelete(true);
m_pCurrentServer = nullptr;
}
KviIrcNetwork::~KviIrcNetwork()
{
if(m_pChannelList)
delete m_pChannelList;
if(m_pNickServRuleSet)
delete m_pNickServRuleSet;
delete m_pServerList;
}
void KviIrcNetwork::setAutoJoinChannelList(QStringList * pNewChannelList)
{
if(m_pChannelList)
delete m_pChannelList;
m_pChannelList = pNewChannelList;
}
void KviIrcNetwork::setAutoJoinChannelList(const QString & szNewChannelList)
{
if(m_pChannelList)
delete m_pChannelList;
QStringList lChans = szNewChannelList.split(",");
if(lChans.isEmpty())
m_pChannelList = nullptr;
else
m_pChannelList = new QStringList(lChans);
}
void KviIrcNetwork::setNickServRuleSet(KviNickServRuleSet * s)
{
if(m_pNickServRuleSet)
delete m_pNickServRuleSet;
m_pNickServRuleSet = s;
}
void KviIrcNetwork::copyFrom(const KviIrcNetwork & src)
{
m_szName = src.m_szName;
m_szEncoding = src.m_szEncoding;
m_szTextEncoding = src.m_szTextEncoding;
m_szDescription = src.m_szDescription;
m_szNickName = src.m_szNickName;
m_szAlternativeNickName = src.m_szAlternativeNickName;
m_szRealName = src.m_szRealName;
m_szUserName = src.m_szUserName;
m_szPass = src.m_szPass;
m_bAutoConnect = src.m_bAutoConnect;
m_szUserIdentityId = src.m_szUserIdentityId;
m_szOnConnectCommand = src.m_szOnConnectCommand;
m_szOnLoginCommand = src.m_szOnLoginCommand;
if(m_pChannelList)
delete m_pChannelList;
if(src.m_pChannelList)
m_pChannelList = new QStringList(*(src.m_pChannelList));
else
m_pChannelList = nullptr;
if(m_pNickServRuleSet)
delete m_pNickServRuleSet;
if(src.m_pNickServRuleSet)
m_pNickServRuleSet = new KviNickServRuleSet(*(src.m_pNickServRuleSet));
else
m_pNickServRuleSet = nullptr;
/*
// We don't copy the server list, since this function is called in KviIrcServerOptionsWidget::commit()
// to recreate the server list from scratch; copying the original servers will mean duplicate servers
// (see bug ticket #300)
for (KviIrcServer *s = src.m_pServerList->first(); s; s = src.m_pServerList->next())
{
m_pServerList->append(new KviIrcServer(*s));
}
*/
}
void KviIrcNetwork::insertServer(KviIrcServer * srv)
{
m_pServerList->append(srv);
}
KviIrcServer * KviIrcNetwork::findServer(const QString & szHostname)
{
for(KviIrcServer * s = m_pServerList->first(); s; s = m_pServerList->next())
{
if(KviQString::equalCI(s->hostName(), szHostname))
return s;
}
return nullptr;
}
KviIrcServer * KviIrcNetwork::findServer(const KviIrcServer * pServer)
{
for(KviIrcServer * s = m_pServerList->first(); s; s = m_pServerList->next())
{
// we better go with the unique id first
if(!s->id().isEmpty())
{
// at least one of the 2 id is not empty, so if they match we're done
if(KviQString::equalCI(s->id(), pServer->id()))
return s;
}
else
{
// failback on the "check everything" method
if(KviQString::equalCI(s->hostName(), pServer->hostName())
&& (s->port() == pServer->port()) && (s->useSSL()
== pServer->useSSL())
&& (s->isIPv6() == pServer->isIPv6()))
return s;
}
}
return nullptr;
}
void KviIrcNetwork::setCurrentServer(KviIrcServer * srv)
{
if(m_pServerList->findRef(srv) != -1)
m_pCurrentServer = srv;
}
KviIrcServer * KviIrcNetwork::currentServer()
{
if(m_pCurrentServer)
return m_pCurrentServer;
m_pCurrentServer = m_pServerList->first();
return m_pCurrentServer;
}
|