1 #ifndef KVI_NETWORK_H_ 2 #define KVI_NETWORK_H_ 3 //============================================================================= 4 // 5 // File : KviIrcNetwork.h 6 // Creation date : Wed Aug 27 2008 17:44:56 by Alexey Uzhva 7 // 8 // This file is part of the KVIrc IRC client distribution 9 // Copyright (C) 2008 Alexey Uzhva (wizard at opendoor dot ru) 10 // 11 // This program is FREE software. You can redistribute it and/or 12 // modify it under the terms of the GNU General Public License 13 // as published by the Free Software Foundation; either version 2 14 // of the License, or (at your option) any later version. 15 // 16 // This program is distributed in the HOPE that it will be USEFUL, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 // See the GNU General Public License for more details. 20 // 21 // You should have received a copy of the GNU General Public License 22 // along with this program. If not, write to the Free Software Foundation, 23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 24 // 25 //============================================================================= 26 27 /** 28 * \file KviIrcNetwork.cpp 29 * \author Alexey Uzhva 30 * \brief Network handling 31 */ 32 33 #include "kvi_settings.h" 34 #include "KviHeapObject.h" 35 #include "KviPointerList.h" 36 37 #include <QString> 38 #include <QStringList> 39 40 class KviNickServRuleSet; 41 class KviIrcServer; 42 43 /** 44 * \class KviIrcNetwork 45 * \brief Network handling class 46 */ 47 class KVILIB_API KviIrcNetwork : public KviHeapObject 48 { 49 friend class KviIrcServerDataBase; 50 51 public: 52 /** 53 * \brief Construct the network object 54 * \param name The name of the network 55 * \return KviIrcNetwork 56 */ 57 KviIrcNetwork(const QString & name); 58 59 /** 60 * \brief Carbon copy 61 * \param src The source network 62 * \return KviIrcNetwork 63 */ 64 KviIrcNetwork(const KviIrcNetwork & src); 65 66 /** 67 * \brief Destroys the network object 68 */ 69 ~KviIrcNetwork(); 70 71 protected: 72 QString m_szName; 73 QString m_szDescription; 74 QString m_szEncoding; /**< if empty, use system default */ 75 QString m_szTextEncoding; /**< if empty, use system default */ 76 QString m_szNickName; /**< preferred nick name */ 77 QString m_szAlternativeNickName; /**< alternative nick name */ 78 QString m_szUserName; /**< preferred user name */ 79 QString m_szRealName; /**< preferred real name */ 80 QString m_szPass; /**< special password */ 81 QString m_szOnConnectCommand; /**< the command to run on connect */ 82 QString m_szOnLoginCommand; /**< the command to run after login */ 83 QStringList * m_pChannelList; /**< Channels to auto join */ 84 KviNickServRuleSet * m_pNickServRuleSet; /**< set of nick serv rules */ 85 bool m_bAutoConnect; /**< autoconnect */ 86 QString m_szUserIdentityId; /**< The user identity to use for this server: if empty then use the global primary identity moved from KviIrcServerDataBaseRecord */ 87 KviPointerList<KviIrcServer> * m_pServerList; 88 KviIrcServer * m_pCurrentServer = nullptr; 89 90 public: 91 /** 92 * \brief Returns the name of the network 93 * \return const QString & 94 */ name()95 const QString & name() const { return m_szName; } 96 97 /** 98 * \brief Returns the encoding of the network 99 * 100 * Some information as nickname and channel names are encoded when 101 * communicating with the server 102 * \return const QString & 103 */ encoding()104 const QString & encoding() const { return m_szEncoding; } 105 106 /** 107 * \brief Returns the text encoding of the network 108 * 109 * This is the default encoding when talking on channels or queries 110 * \return const QString & 111 */ textEncoding()112 const QString & textEncoding() const { return m_szTextEncoding; } 113 114 /** 115 * \brief Returns the description of the network 116 * \return const QString & 117 */ description()118 const QString & description() const { return m_szDescription; } 119 120 /** 121 * \brief Returns the nickname of the user associated to the network 122 * \return const QString & 123 */ nickName()124 const QString & nickName() const { return m_szNickName; } 125 126 /** 127 * \brief Returns the alternative nickname of the user associated to the network 128 * \return const QString & 129 */ alternativeNickName()130 const QString & alternativeNickName() const { return m_szAlternativeNickName; } 131 132 /** 133 * \brief Returns the realname of the user associated to the network 134 * \return const QString & 135 */ realName()136 const QString & realName() const { return m_szRealName; } 137 138 /** 139 * \brief Returns the username of the user associated to the network 140 * \return const QString & 141 */ userName()142 const QString & userName() const { return m_szUserName; } 143 144 /** 145 * \brief Returns the password of the user associated to the network 146 * \return const QString & 147 */ password()148 const QString & password() const { return m_szPass; } 149 150 /** 151 * \brief Returns the commands to run on network login 152 * \return const QString & 153 */ onLoginCommand()154 const QString & onLoginCommand() const { return m_szOnLoginCommand; } 155 156 /** 157 * \brief Returns the commands to run on network connect 158 * \return const QString & 159 */ onConnectCommand()160 const QString & onConnectCommand() const { return m_szOnConnectCommand; } 161 162 /** 163 * \brief Returns the user identity of the user associated to the network 164 * \return const QString & 165 */ userIdentityId()166 const QString & userIdentityId() const { return m_szUserIdentityId; } 167 168 /** 169 * \brief Returns true if the network has the autoconnect state on 170 * \return bool 171 */ autoConnect()172 bool autoConnect() const { return m_bAutoConnect; } 173 174 /** 175 * \brief Returns the list of channels with autojoin flag 176 * \return QStringList * 177 */ autoJoinChannelList()178 QStringList * autoJoinChannelList() { return m_pChannelList; } 179 180 /** 181 * \brief Returns the list of channels with autojoin flag as a string 182 * \return const QString & 183 */ autoJoinChannelListAsString()184 const QString autoJoinChannelListAsString() { return m_pChannelList ? m_pChannelList->join(",") : ""; } 185 186 /** 187 * \brief Returns a set of rules for the NickServ 188 * \return KviNickServRuleSet * 189 */ nickServRuleSet()190 KviNickServRuleSet * nickServRuleSet() { return m_pNickServRuleSet; } 191 192 /** 193 * \brief Sets the rules for NickServ 194 * \param pSet The rule set where to add rules 195 * \return void 196 */ 197 void setNickServRuleSet(KviNickServRuleSet * pSet); 198 199 /** 200 * \brief Carbon copy 201 * \param net The source network to copy from 202 * \return void 203 */ 204 void copyFrom(const KviIrcNetwork & net); 205 206 /** 207 * \brief Sets the name of the network 208 * \param szName The name of the network 209 * \return void 210 */ setName(const QString & szName)211 void setName(const QString & szName) { m_szName = szName; } 212 213 /** 214 * \brief Sets the encondig of the network 215 * 216 * Some information as nickname and channel names are encoded when 217 * communicating with the server 218 * \param szEncoding The encoding of the network 219 * \return void 220 */ setEncoding(const QString & szEncoding)221 void setEncoding(const QString & szEncoding) { m_szEncoding = szEncoding; } 222 223 /** 224 * \brief Sets the text encondig of the network 225 * 226 * This is the default encoding when talking on channels or queries 227 * \param szEncoding The text encoding of the network 228 * \return void 229 */ setTextEncoding(const QString & szEncoding)230 void setTextEncoding(const QString & szEncoding) { m_szTextEncoding = szEncoding; } 231 232 /** 233 * \brief Sets the description of the network 234 * \param szDescription The description of the network 235 * \return void 236 */ setDescription(const QString & szDescription)237 void setDescription(const QString & szDescription) { m_szDescription = szDescription; } 238 239 /** 240 * \brief Sets the list of commands to run on network connection 241 * \param szCmd The commands list to run 242 * \return void 243 */ setOnConnectCommand(const QString & szCmd)244 void setOnConnectCommand(const QString & szCmd) { m_szOnConnectCommand = szCmd; } 245 246 /** 247 * \brief Sets the list of commands to run on network login 248 * \param szCmd The commands list to run 249 * \return void 250 */ setOnLoginCommand(const QString & szCmd)251 void setOnLoginCommand(const QString & szCmd) { m_szOnLoginCommand = szCmd; } 252 253 /** 254 * \brief Sets the nickname of the user associated to the network 255 * \param szNick The nickname 256 * \return void 257 */ setNickName(const QString & szNick)258 void setNickName(const QString & szNick) { m_szNickName = szNick; } 259 260 /** 261 * \brief Sets the alternative nickname of the user associated to the network 262 * \param szNick The nickname 263 * \return void 264 */ setAlternativeNickName(const QString & szNick)265 void setAlternativeNickName(const QString & szNick) { m_szAlternativeNickName = szNick; } 266 267 /** 268 * \brief Sets the realname of the user associated to the network 269 * \param szReal The realname 270 * \return void 271 */ setRealName(const QString & szReal)272 void setRealName(const QString & szReal) { m_szRealName = szReal; } 273 274 /** 275 * \brief Sets the username of the user associated to the network 276 * \param szUser The username 277 * \return void 278 */ setUserName(const QString & szUser)279 void setUserName(const QString & szUser) { m_szUserName = szUser; } 280 281 /** 282 * \brief Sets the password of the user associated to the network 283 * \param szPass The password 284 * \return void 285 */ setPassword(const QString & szPass)286 void setPassword(const QString & szPass) { m_szPass = szPass; } 287 288 /** 289 * \brief Sets the list of channels to mark for autojoin 290 * \param pNewChannelList The channel list 291 * \return void 292 */ 293 void setAutoJoinChannelList(QStringList * pNewChannelList); 294 295 /** 296 * \brief Sets the list of channels to mark for autojoin 297 * \param szNewChannelList A comma separated list of channels 298 * \return void 299 */ 300 void setAutoJoinChannelList(const QString & szNewChannelList); 301 302 /** 303 * \brief Sets the autoconnect flag 304 * \param bAutoConnect The state of the autoconnect flag 305 * \return void 306 */ setAutoConnect(bool bAutoConnect)307 void setAutoConnect(bool bAutoConnect) { m_bAutoConnect = bAutoConnect; } 308 309 /** 310 * \brief Sets the user identity id of the user associated to the network 311 * \param szUserIdentityId The user identity 312 * \return void 313 */ setUserIdentityId(const QString & szUserIdentityId)314 void setUserIdentityId(const QString & szUserIdentityId) { m_szUserIdentityId = szUserIdentityId; } 315 316 /** 317 * \brief Returns a list of servers associated to the network 318 * \return KviPointerList<KviIrcServer> * 319 */ serverList()320 KviPointerList<KviIrcServer> * serverList() const { return m_pServerList; } 321 322 /** 323 * \brief Returns the current server 324 * \return KviIrcServer 325 */ 326 KviIrcServer * currentServer(); 327 328 /** 329 * \brief Adds a new server to the network 330 * \param pServer The source server to add 331 * \return void 332 */ 333 void insertServer(KviIrcServer * pServer); 334 335 /** 336 * \brief Searches for a server in the network 337 * \param szHostname The hostname of the server to find 338 * \return KviIrcServer 339 */ 340 KviIrcServer * findServer(const QString & szHostname); 341 342 /** 343 * \brief Searches for a server in the network 344 * \param pServer The server to find 345 * \return KviIrcServer 346 */ 347 KviIrcServer * findServer(const KviIrcServer * pServer); 348 349 /** 350 * \brief Sets the current server 351 * \param pServer The source server 352 * \return void 353 */ 354 void setCurrentServer(KviIrcServer * pServer); 355 }; 356 357 #endif // KVI_NETWORK_H_ 358