1 #ifndef _KVI_IRCSERVERDB_H_ 2 #define _KVI_IRCSERVERDB_H_ 3 //============================================================================= 4 // 5 // File : KviIrcServerDataBase.h 6 // Creation date : Mon Jul 10 2000 14:15:42 by Szymon Stefanek 7 // 8 // This file is part of the KVIrc IRC client distribution 9 // Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net) 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 KviIrcServerDataBase.h 29 * \author Szymon Stefanek 30 * \brief Irc server database handling 31 */ 32 33 #include "kvi_settings.h" 34 #include "kvi_inttypes.h" 35 #include "KviPointerHashTable.h" 36 37 #include <QString> 38 39 class KviIrcNetwork; 40 class KviIrcServer; 41 42 /** 43 * \typedef KviIrcServerDefinition 44 * \struct _KviIrcServerDefinition 45 * \brief Server definition 46 */ 47 struct KviIrcServerDefinition 48 { 49 QString szServer; 50 kvi_u32_t uPort; 51 bool bPortIsValid; 52 bool bIPv6; 53 bool bSSL; 54 bool bSTARTTLS; 55 QString szLinkFilter; 56 QString szPass; 57 QString szNick; 58 QString szInitUMode; 59 QString szId; 60 }; 61 62 /** 63 * \class KviIrcServerDataBase 64 * \brief Irc server database handling class 65 */ 66 class KVILIB_API KviIrcServerDataBase 67 { 68 public: 69 /** 70 * \brief Constructs the server database object 71 * \return KviIrcServerDataBase 72 */ 73 KviIrcServerDataBase(); 74 75 /** 76 * \brief Destroys the server database object 77 */ 78 ~KviIrcServerDataBase(); 79 80 private: 81 KviPointerHashTable<QString, KviIrcNetwork> * m_pRecords; 82 QString m_szCurrentNetwork; 83 KviPointerList<KviIrcServer> * m_pAutoConnectOnStartupServers; 84 KviPointerList<KviIrcNetwork> * m_pAutoConnectOnStartupNetworks; 85 86 public: 87 /** 88 * \brief Deletes the database 89 * \return void 90 */ 91 void clear(); 92 93 /** 94 * \brief Returns the record dictionary of the database 95 * \return KviPointerHashTable<QString,KviIrcNetwork> * 96 */ recordDict()97 KviPointerHashTable<QString, KviIrcNetwork> * recordDict() const { return m_pRecords; } 98 99 /** 100 * \brief Returns a list of servers to connect on startup 101 * This list is computed when the data are loaded from disk during the startup 102 * and is used by KviApplication to start the connections. 103 * The pointer is zero if there are no autoConnect servers. The list is valid 104 * only during the startup phase because it contains shallow pointers to the 105 * servers really contained in the server/network list and it is never updated 106 * later. 107 * \return KviPointerList<KviIrcServer> * 108 */ autoConnectOnStartupServers()109 KviPointerList<KviIrcServer> * autoConnectOnStartupServers() const { return m_pAutoConnectOnStartupServers; } 110 111 /** 112 * \brief Returns a list of networks to connect on startup 113 * This list is computed when the data are loaded from disk during the startup 114 * and is used by KviApplication to start the connections. 115 * The pointer is zero if there are no autoConnect networks. The list is valid 116 * only during the startup phase because it contains shallow pointers to the 117 * networks really contained in the server/network list and it is never 118 * updated later. 119 * \return KviPointerList<KviIrcNetwork> * 120 */ autoConnectOnStartupNetworks()121 KviPointerList<KviIrcNetwork> * autoConnectOnStartupNetworks() const { return m_pAutoConnectOnStartupNetworks; } 122 123 /** 124 * \brief Deletes the list of autoconnect servers 125 * \return void 126 */ 127 void clearAutoConnectOnStartupServers(); 128 129 /** 130 * \brief Deletes the list of autoconnect networks 131 * \return void 132 */ 133 void clearAutoConnectOnStartupNetworks(); 134 135 /** 136 * \brief Sets the current network 137 * \param szNetName The name of the network 138 * \return void 139 */ setCurrentNetwork(const QString & szNetName)140 void setCurrentNetwork(const QString & szNetName) { m_szCurrentNetwork = szNetName; } 141 142 /** 143 * \brief Returns the current network name 144 * \return const QString & 145 */ currentNetworkName()146 const QString & currentNetworkName() const { return m_szCurrentNetwork; } 147 148 /** 149 * \brief Returns the current network 150 * \return KviIrcNetwork 151 */ 152 KviIrcNetwork * currentNetwork(); 153 154 /** 155 * \brief Adds a network to the database 156 * \param pNet The source network 157 * \return void 158 */ 159 void addNetwork(KviIrcNetwork * pNet); 160 161 /** 162 * \brief Searches for a network 163 * \param szName The name of the network to find 164 * \return KviIrcNetwork 165 */ 166 KviIrcNetwork * findNetwork(const QString & szName); 167 168 /** 169 * \brief Returns the number of networks 170 * \return unsigned integer 171 */ 172 unsigned int networkCount() const; 173 174 /** 175 * \brief Loads the database data 176 * \param szFilename The filename of the database data to load 177 * \return void 178 */ 179 void load(const QString & szFilename); 180 181 /** 182 * \brief Saves the database data 183 * \param szFilename The filename of the database data to save 184 * \return void 185 */ 186 void save(const QString & szFilename); 187 188 /** 189 * \brief Import servers and networks from a mirc ini file 190 * \param filename The database file where to add new servers 191 * \param szMircIni The source mirc ini file to import 192 * \param recentServers The list of recent servers where to add new servers 193 * \return void 194 */ 195 void importFromMircIni(const QString & filename, const QString & szMircIni, QStringList & recentServers); 196 197 /** 198 * \brief Marks a server as current 199 * \param pDef The server definition 200 * \param szError The container for a possible error 201 * \return bool 202 */ 203 bool makeCurrentServer(KviIrcServerDefinition * pDef, QString & szError); 204 205 /** 206 * \brief Marks the current servers as the best in the network 207 * \param szNetName The name of the network 208 * \param pNet The source network 209 * \param szError The container for a possible error 210 * \return bool 211 */ 212 bool makeCurrentBestServerInNetwork(const QString & szNetName, KviIrcNetwork * pNet, QString & szError); 213 }; 214 215 #endif //_KVI_IRCSERVERDB_H_ 216