summaryrefslogtreecommitdiffstats
path: root/src/kvilib/ext
diff options
context:
space:
mode:
Diffstat (limited to 'src/kvilib/ext')
-rw-r--r--src/kvilib/ext/Makefile.am5
-rw-r--r--src/kvilib/ext/kvi_accel.h38
-rw-r--r--src/kvilib/ext/kvi_cmdformatter.cpp242
-rw-r--r--src/kvilib/ext/kvi_cmdformatter.h64
-rw-r--r--src/kvilib/ext/kvi_config.cpp1007
-rw-r--r--src/kvilib/ext/kvi_config.h162
-rw-r--r--src/kvilib/ext/kvi_crypt.cpp240
-rw-r--r--src/kvilib/ext/kvi_crypt.h160
-rw-r--r--src/kvilib/ext/kvi_databuffer.cpp135
-rw-r--r--src/kvilib/ext/kvi_databuffer.h56
-rw-r--r--src/kvilib/ext/kvi_dcophelper.cpp357
-rw-r--r--src/kvilib/ext/kvi_dcophelper.h82
-rw-r--r--src/kvilib/ext/kvi_doublebuffer.cpp90
-rw-r--r--src/kvilib/ext/kvi_doublebuffer.h62
-rw-r--r--src/kvilib/ext/kvi_draganddrop.h45
-rw-r--r--src/kvilib/ext/kvi_garbage.cpp148
-rw-r--r--src/kvilib/ext/kvi_garbage.h51
-rw-r--r--src/kvilib/ext/kvi_imagelib.cpp138
-rw-r--r--src/kvilib/ext/kvi_imagelib.h73
-rw-r--r--src/kvilib/ext/kvi_md5.cpp298
-rw-r--r--src/kvilib/ext/kvi_md5.h68
-rw-r--r--src/kvilib/ext/kvi_mediatype.cpp541
-rw-r--r--src/kvilib/ext/kvi_mediatype.h83
-rw-r--r--src/kvilib/ext/kvi_miscutils.cpp86
-rw-r--r--src/kvilib/ext/kvi_miscutils.h44
-rw-r--r--src/kvilib/ext/kvi_msgtype.cpp68
-rw-r--r--src/kvilib/ext/kvi_msgtype.h74
-rw-r--r--src/kvilib/ext/kvi_osinfo.cpp510
-rw-r--r--src/kvilib/ext/kvi_osinfo.h43
-rw-r--r--src/kvilib/ext/kvi_parameterlist.cpp254
-rw-r--r--src/kvilib/ext/kvi_parameterlist.h72
-rw-r--r--src/kvilib/ext/kvi_pixmap.cpp180
-rw-r--r--src/kvilib/ext/kvi_pixmap.h61
-rw-r--r--src/kvilib/ext/kvi_proxydb.cpp192
-rw-r--r--src/kvilib/ext/kvi_proxydb.h86
-rw-r--r--src/kvilib/ext/kvi_regchan.cpp181
-rw-r--r--src/kvilib/ext/kvi_regchan.h74
-rw-r--r--src/kvilib/ext/kvi_regusersdb.cpp743
-rw-r--r--src/kvilib/ext/kvi_regusersdb.h201
-rw-r--r--src/kvilib/ext/kvi_sharedfiles.cpp391
-rw-r--r--src/kvilib/ext/kvi_sharedfiles.h133
-rw-r--r--src/kvilib/ext/kvi_stringconversion.cpp277
-rw-r--r--src/kvilib/ext/kvi_stringconversion.h91
-rw-r--r--src/kvilib/ext/kvi_xlib.h45
-rw-r--r--src/kvilib/ext/moc_kvi_crypt.cpp94
-rw-r--r--src/kvilib/ext/moc_kvi_garbage.cpp104
-rw-r--r--src/kvilib/ext/moc_kvi_regusersdb.cpp143
-rw-r--r--src/kvilib/ext/moc_kvi_sharedfiles.cpp157
48 files changed, 8449 insertions, 0 deletions
diff --git a/src/kvilib/ext/Makefile.am b/src/kvilib/ext/Makefile.am
new file mode 100644
index 00000000..c84487eb
--- /dev/null
+++ b/src/kvilib/ext/Makefile.am
@@ -0,0 +1,5 @@
+###############################################################################
+# KVirc IRC client Makefile - 16.12.98 Szymon Stefanek <stefanek@tin.it>
+###############################################################################
+
+EXTRA_DIST = *.cpp *.h
diff --git a/src/kvilib/ext/kvi_accel.h b/src/kvilib/ext/kvi_accel.h
new file mode 100644
index 00000000..34cca3c1
--- /dev/null
+++ b/src/kvilib/ext/kvi_accel.h
@@ -0,0 +1,38 @@
+#ifndef _KVI_ACCEL_H_
+#define _KVI_ACCEL_H_
+
+//=============================================================================
+//
+// File : kvi_accel.h
+// Creation date : Wed Feb 01 2007 01:45:21 CEST by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2007 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_settings.h"
+
+#ifdef COMPILE_USE_QT4
+ #include <q3accel.h>
+ #define KviAccel Q3Accel
+#else
+ #include <qaccel.h>
+ #define KviAccel QAccel
+#endif
+
+#endif //!_KVI_ACCEL_H_
diff --git a/src/kvilib/ext/kvi_cmdformatter.cpp b/src/kvilib/ext/kvi_cmdformatter.cpp
new file mode 100644
index 00000000..e2b3e1f6
--- /dev/null
+++ b/src/kvilib/ext/kvi_cmdformatter.cpp
@@ -0,0 +1,242 @@
+//=============================================================================
+//
+// File : kvi_cmdformatter.cpp
+// Creation date : Tue Jun 12 2001 03:08:12 CEST by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2001-2007 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+//=============================================================================
+
+#define __KVILIB__
+
+#include "kvi_cmdformatter.h"
+
+namespace KviCommandFormatter
+{
+ bool hasLeadingChars(KviStr ** array,char c)
+ {
+ if(!(*array))return false; // can't have more leading chars
+ bool bGotIt = false;
+ while(*array)
+ {
+ if(*((*array)->ptr()) == c)
+ {
+ // found at least one such leading char
+ bGotIt = true;
+ } else {
+ // we pretend this line to be empty
+ KviStr tmp = *(*array);
+ tmp.stripWhiteSpace();
+ if(tmp.hasData())return false;
+ *(*array) = ""; // set it to empty also in the main buffer
+ }
+ array++;
+ }
+ return bGotIt;
+ }
+
+ bool hasLeadingChars(QStringList &list,const QChar &c)
+ {
+ bool bGotIt = false;
+ for(QStringList::Iterator it = list.begin();it != list.end();++it)
+ {
+ if((*it).length() < 1)continue;
+ if((*it).at(0) == c)
+ {
+ // found at least one such leading char
+ bGotIt = true;
+ } else {
+ // we pretend this line to be empty
+ QString tmp = *it;
+#ifdef COMPILE_USE_QT4
+ tmp = tmp.trimmed();
+#else
+ tmp = tmp.stripWhiteSpace();
+#endif
+ if(!tmp.isEmpty())return false;
+ *it = ""; // set it to empty also in the main buffer
+ }
+ }
+ return bGotIt;
+ }
+
+ void trimLeading(KviStr ** array)
+ {
+ while(*array)
+ {
+ if((*array)->hasData())(*array)->cutLeft(1);
+ array++;
+ }
+ }
+
+ void trimLeading(QStringList &list)
+ {
+ for(QStringList::Iterator it = list.begin();it != list.end();++it)
+ {
+ (*it).remove(0,1);
+ }
+ }
+
+
+ void addLeading(KviStr ** array,char c)
+ {
+ while(*array)
+ {
+ if((*array)->hasData())(*array)->prepend(c);
+ array++;
+ }
+ }
+
+ void addLeading(QStringList &list,const QChar & c)
+ {
+ for(QStringList::Iterator it = list.begin();it != list.end();++it)
+ {
+ (*it).prepend(c);
+ }
+ }
+
+
+ void unindent(KviStr &buffer)
+ {
+ // we can format correctly up to 65536 lines (that's really enough)
+ int realLen;
+ KviStr ** array = buffer.splitToArray('\n',65536,&realLen);
+ if(array)
+ {
+ while(hasLeadingChars(array,'\t') || hasLeadingChars(array,' '))trimLeading(array);
+ buffer.joinFromArray(array,"\n",true);
+ KviStr::freeArray(array);
+ }
+ }
+
+
+ void unindent(QString &buffer)
+ {
+#ifdef COMPILE_USE_QT4
+ QStringList list = buffer.split("\n",QString::KeepEmptyParts);
+#else
+ QStringList list = QStringList::split("\n",buffer,true);
+#endif
+ while(hasLeadingChars(list,QChar('\t')) || hasLeadingChars(list,QChar(' ')))trimLeading(list);
+ //buffer = list.join("\n"); join implementation sux :D
+ // we WANT the last newline
+ buffer = "";
+ for(QStringList::Iterator it = list.begin();it != list.end();++it)
+ {
+ buffer.append(*it);
+ buffer.append(QChar('\n'));
+ }
+ }
+
+
+ void bufferFromBlock(KviStr &buffer)
+ {
+ buffer.stripWhiteSpace();
+
+ if((*(buffer.ptr()) == '{') && buffer.lastCharIs('}'))
+ {
+ // leading and trailing { must be stripped
+ buffer.cutLeft(1);
+ buffer.cutRight(1);
+ }
+
+ unindent(buffer);
+
+ buffer.stripWhiteSpace();
+ }
+
+ void bufferFromBlock(QString &buffer)
+ {
+#ifdef COMPILE_USE_QT4
+ buffer = buffer.trimmed();
+#else
+ buffer = buffer.stripWhiteSpace();
+#endif
+
+ if(buffer.isEmpty())return;
+
+ if((buffer.at(0) == QChar('{')) && buffer.endsWith(QChar('}')))
+ {
+ buffer.remove(0,1);
+ buffer.remove(buffer.length() - 1,1);
+ while((buffer.length() > 0) && ((buffer.at(0) == QChar('\n')) || (buffer.at(0) == QChar('\r'))))
+ buffer.remove(0,1);
+ }
+
+ unindent(buffer);
+
+#ifdef COMPILE_USE_QT4
+ buffer = buffer.trimmed();
+#else
+ buffer = buffer.stripWhiteSpace();
+#endif
+ }
+
+
+ void indent(KviStr &buffer)
+ {
+ // we can format correctly up to 65536 lines (that's really enough)
+ int realLen;
+ KviStr ** array = buffer.splitToArray('\n',65536,&realLen);
+ if(array)
+ {
+ addLeading(array,'\t');
+ buffer.joinFromArray(array,"\n",true);
+ KviStr::freeArray(array);
+ }
+ }
+
+ void indent(QString &buffer)
+ {
+#ifdef COMPILE_USE_QT4
+ QStringList list = buffer.split("\n",QString::KeepEmptyParts);
+#else
+ QStringList list = QStringList::split("\n",buffer,true);
+#endif
+ addLeading(list,QChar('\t'));
+ //buffer = list.join("\n"); join implementation sux :D
+ // we WANT the last newline
+ buffer = "";
+ for(QStringList::Iterator it = list.begin();it != list.end();++it)
+ {
+ buffer.append(*it);
+ buffer.append(QChar('\n'));
+ }
+ }
+
+
+ void blockFromBuffer(KviStr &buffer)
+ {
+ indent(buffer);
+ buffer.prepend("{\n");
+ buffer.stripRightWhiteSpace();
+ buffer.ensureLastCharIs('\n');
+ buffer.append("}\n");
+ }
+
+ void blockFromBuffer(QString &buffer)
+ {
+ indent(buffer);
+ buffer.prepend("{\n");
+ KviQString::stripRightWhiteSpace(buffer);
+ KviQString::ensureLastCharIs(buffer,'\n');
+ buffer.append("}\n");
+ }
+};
+
+// FIXME: #warning "move popups and events to this formatting stuff!"
diff --git a/src/kvilib/ext/kvi_cmdformatter.h b/src/kvilib/ext/kvi_cmdformatter.h
new file mode 100644
index 00000000..b6efa98b
--- /dev/null
+++ b/src/kvilib/ext/kvi_cmdformatter.h
@@ -0,0 +1,64 @@
+#ifndef _KVI_CMDFORMATTER_H_
+#define _KVI_CMDFORMATTER_H_
+
+//=============================================================================
+//
+// File : kvi_cmdformatter.h
+// Creation date : Tue Jun 12 2001 03:04:05 CEST by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2001-2007 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_string.h"
+#include "kvi_settings.h"
+
+#include "kvi_qstring.h"
+#include <qstringlist.h>
+
+namespace KviCommandFormatter
+{
+ extern KVILIB_API bool hasLeadingChars(KviStr * array,char c);
+ extern KVILIB_API bool hasLeadingChars(QStringList &list,const QChar &c);
+
+ extern KVILIB_API void trimLeading(KviStr ** array);
+ extern KVILIB_API void trimLeading(QStringList &list);
+
+ extern KVILIB_API void addLeading(KviStr ** array,char c);
+ extern KVILIB_API void addLeading(QStringList &list,const QChar &c);
+
+ extern KVILIB_API void trimBlockBraces(KviStr &buffer);
+ extern KVILIB_API void trimBlockBraces(QString &buffer);
+
+ extern KVILIB_API void unindent(KviStr &buffer);
+ extern KVILIB_API void unindent(QString &buffer);
+
+ extern KVILIB_API void bufferFromBlock(KviStr &buffer);
+ extern KVILIB_API void bufferFromBlock(QString &buffer);
+
+ extern KVILIB_API void addBlockBraces(KviStr &buffer);
+ extern KVILIB_API void addBlockBraces(QString &buffer);
+
+ extern KVILIB_API void indent(KviStr &buffer);
+ extern KVILIB_API void indent(QString &buffer);
+
+ extern KVILIB_API void blockFromBuffer(KviStr &buffer);
+ extern KVILIB_API void blockFromBuffer(QString &buffer);
+};
+
+#endif //_KVI_CMDFORMATTER_H_
diff --git a/src/kvilib/ext/kvi_config.cpp b/src/kvilib/ext/kvi_config.cpp
new file mode 100644
index 00000000..eb3dc0bc
--- /dev/null
+++ b/src/kvilib/ext/kvi_config.cpp
@@ -0,0 +1,1007 @@
+//==========================================================================================
+//
+// File : kvi_config.cpp
+// Last major modification : Thu Jan 14 1999 18:03:59 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2007 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+//==========================================================================================
+
+#define __KVILIB__
+
+#include "kvi_config.h"
+#include "kvi_fileutils.h"
+#include "kvi_pixmap.h"
+#include "kvi_msgtype.h"
+#include "kvi_stringconversion.h"
+#include "kvi_memmove.h"
+#include "kvi_malloc.h"
+#include "kvi_file.h"
+
+
+KviConfig::KviConfig(const QString &filename,FileMode f,bool bLocal8Bit)
+{
+ m_bLocal8Bit = bLocal8Bit;
+ m_szFileName = filename;
+ m_bDirty = false;
+ m_szGroup = KVI_CONFIG_DEFAULT_GROUP;
+ m_bPreserveEmptyGroups = false;
+ m_bReadOnly = (f == KviConfig::Read);
+ m_pDict = new KviPointerHashTable<QString,KviConfigGroup>(17,false);
+ m_pDict->setAutoDelete(true);
+ if(f != KviConfig::Write)load();
+}
+
+KviConfig::KviConfig(const char* filename,FileMode f,bool bLocal8Bit)
+{
+ m_bLocal8Bit = bLocal8Bit;
+ m_szFileName = QString::fromUtf8(filename);
+ m_bDirty = false;
+ m_szGroup = KVI_CONFIG_DEFAULT_GROUP;
+ m_bPreserveEmptyGroups = false;
+ m_bReadOnly = (f == KviConfig::Read);
+ m_pDict = new KviPointerHashTable<QString,KviConfigGroup>(17,false);
+ m_pDict->setAutoDelete(true);
+ if(f != KviConfig::Write)load();
+}
+
+
+KviConfig::~KviConfig()
+{
+ if(m_bDirty)save();
+ delete m_pDict;
+}
+
+void KviConfig::clear()
+{
+ delete m_pDict;
+ m_pDict = new KviPointerHashTable<QString,KviConfigGroup>(17,false);
+ m_pDict->setAutoDelete(true);
+ m_bDirty = false;
+ m_szGroup = KVI_CONFIG_DEFAULT_GROUP;
+}
+
+void KviConfig::clearGroup(const QString & szGroup)
+{
+ m_bDirty = true;
+ m_pDict->remove(szGroup);
+ if(!m_pDict->find(m_szGroup))m_szGroup = KVI_CONFIG_DEFAULT_GROUP; //removed the current one
+}
+
+void KviConfig::clearKey(const QString & szKey)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ p_group->remove(szKey);
+ if(p_group->count() == 0)clearGroup(m_szGroup);
+}
+
+/*
+void KviConfig::getContentsString(KviStr &buffer)
+{
+ buffer = __tr("Contents of config file ");
+ buffer.append(m_szFileName.ptr());
+ buffer.append('\n');
+ int sections = 0;
+ int keys = 0;
+ KviPointerHashTableIterator<QString,KviStrDict> it(*m_pDict);
+ while(it.current()){
+ buffer.append(" Section [");
+ buffer.append(it.currentKey());
+ buffer.append("]\n");
+ int sectionKeys = 0;
+ KviPointerHashTableIterator<QString,KviStr> it2(*it.current());
+ while(it2.current()){
+ buffer.append(" Key [");
+ buffer.append(it2.currentKey());
+ buffer.append("] : ");
+ buffer.append(it2.current()->ptr());
+ buffer.append('\n');
+ ++it2;
+ ++sectionKeys;
+ ++keys;
+ }
+ KviStr tmp(KviStr::Format,__tr(" Total: %d keys"),sectionKeys);
+ buffer.append(tmp);
+ buffer.append('\n');
+ ++it;
+ ++sections;
+ }
+ KviStr tmp(KviStr::Format,__tr("Total: %d keys in %d sections"),keys,sections);
+ buffer.append(tmp);
+}
+*/
+
+
+
+#define LOAD_BLOCK_SIZE 32768
+
+bool KviConfig::load()
+{
+ // this is really faster than the old version :)
+
+ // open the file
+ KviFile f(m_szFileName);
+ if(!f.openForReading())return false;
+
+ KviStr tmp;
+ KviConfigGroup * p_group = 0;
+
+ int iLoadBlockSize = LOAD_BLOCK_SIZE;
+
+ char * buffer = (char *)kvi_malloc(iLoadBlockSize * sizeof(char));
+
+ int toRead;
+ int readedLen;
+ int remainingLen = 0;
+
+ char * p = buffer; // start writing to the beginning of the buffer
+
+ do {
+ // compute the length to read
+ toRead = iLoadBlockSize - remainingLen;
+ if(toRead < 1)
+ {
+ // ops... a string longer than iLoadBlockSize - 1 chars
+ iLoadBlockSize += LOAD_BLOCK_SIZE;
+ int iOffset = p - buffer;
+ buffer = (char *)kvi_realloc(buffer,iLoadBlockSize * sizeof(char));
+ p = buffer + iOffset;
+ toRead += LOAD_BLOCK_SIZE;
+ }
+
+ // do read
+ readedLen = f.readBlock(p,toRead);
+ if(readedLen < toRead)
+ {
+ // check for errors
+ if(readedLen <= 0)
+ {
+ if(readedLen < 0)
+ {
+ // error at all
+ f.close();
+ kvi_free(buffer);
+ return true; // nothing more to parse anyway
+ } else {
+ // just a zero byte read
+ if(remainingLen == 0)
+ {
+ // there was nothing in the buffer
+ f.close(); // nothing to parse anyway
+ kvi_free(buffer);
+ return true;
+ }
+ // there is something in the buffer but we have readed 0 bytes
+ // this usually means that the last line in the file has no trailing newline
+ // ...we just fake it :)
+ *p = '\n';
+ readedLen = 1;
+ }
+ } else {
+ // just readed something but less than expected
+ // check if the last readed char is a newline
+ // if it isn't , fake it
+ if(*(p + readedLen - 1) != '\n')
+ {
+ *(p + readedLen) = '\n';
+ readedLen++;
+ }
+ }
+ }
+ // compute the end pointer
+ char * endp = p + readedLen;
+
+ p = buffer; // start from beginning of the data buffer at all
+ // begin of the current string
+ char * begin = p;
+
+ // and loop
+ while(p < endp)
+ {
+ // find a newline
+ if(*p != '\n')
+ {
+ p++;
+ continue;
+ }
+ // newline!
+ *p = 0;
+ // now begin points to the string that terminates in p
+ // skip leading whitespace
+ while((*begin == '\t') || (*begin == ' '))begin++;
+
+ if(p == begin)
+ {
+ // empty line
+ p++;
+ begin = p;
+ continue;
+ }
+ // now p > begin
+ // check if there are trailing spaces (include CR so CRLF is trimmed too)
+ char * trail = p - 1;
+
+ p++;
+
+ while(trail >= begin)
+ {
+ if((*trail == '\r') || (*trail == '\t') || (*trail == ' '))*trail = 0;
+ else break;
+ trail--;
+ }
+
+ // yeah, have some data in this line :D
+ switch(*begin)
+ {
+ case 0:
+ // empty line
+ break;
+ case '#':
+ // comment: just skip it
+ break;
+ case '[':
+ // group ?
+ begin++;
+ if(*begin && (*begin != ']'))
+ {
+ char * z = begin;
+#define COMPAT_WITH_OLD_CONFIGS
+#ifdef COMPAT_WITH_OLD_CONFIGS
+ // run to the end of the string
+ while(*z)z++;
+ // run back to the trailing ']'
+ while((z > begin) && (*z != ']'))z--;
+ // if it is not ther just run back to the end of the string
+ if(*z != ']')while(*z)z++;
+#else
+ // new configs have it always encoded properly
+ while(*z && (*z != ']'))z++;
+#endif
+ *z = 0;
+ tmp.hexDecode(begin);
+ tmp.stripRightWhiteSpace(); // no external spaces in group names
+
+ if(!tmp.isEmpty())
+ {
+ QString szGroup = m_bLocal8Bit ?
+ QString::fromLocal8Bit(tmp.ptr(),tmp.len()) :
+ QString::fromUtf8(tmp.ptr(),tmp.len());
+ p_group = m_pDict->find(szGroup);
+ if(!p_group)
+ {
+ p_group = new KviConfigGroup(17,false);
+ p_group->setAutoDelete(true);
+ m_pDict->insert(szGroup,p_group);
+ }
+ }
+ }
+ break;
+ default:
+ {
+ // real data ?
+ char * z = begin;
+ while(*z && (*z != '='))z++;
+ if(*z && (z != begin))
+ {
+ *z = 0;
+ tmp.hexDecode(begin);
+ tmp.stripRightWhiteSpace(); // No external spaces at all in keys
+ if(!tmp.isEmpty())
+ {
+ QString szKey = m_bLocal8Bit ?
+ QString::fromLocal8Bit(tmp.ptr(),tmp.len()) :
+ QString::fromUtf8(tmp.ptr(),tmp.len());
+ z++;
+ while(*z && ((*z == ' ') || (*z == '\t')))z++;
+ if(*z)
+ {
+ tmp.hexDecode(z);
+ QString * pVal = new QString( m_bLocal8Bit ?
+ QString::fromLocal8Bit(tmp.ptr(),tmp.len()) :
+ QString::fromUtf8(tmp.ptr(),tmp.len())
+ );
+ if(!p_group)
+ {
+ // ops...we're missing a group
+ // use the default one
+ p_group = new KviConfigGroup(17,false);
+ p_group->setAutoDelete(true);
+ m_pDict->insert(KVI_CONFIG_DEFAULT_GROUP,p_group);
+ }
+ p_group->replace(szKey,pVal);
+ } else {
+ // we in fact need this (mercy :D)
+ // otherwise the empty options will be treated as non-existing ones
+ // and will get the defaults (which is bad)
+ QString * pVal = new QString(QString::null);
+ p_group->replace(szKey,pVal);
+ }
+ }
+ }
+ }
+ break;
+ }
+ begin = p;
+ }
+ if(begin != endp)
+ {
+ // there is data with no trailing newline in the buffer
+ remainingLen = endp-begin;
+ if(buffer != begin)
+ {
+ kvi_memmove(buffer,begin,remainingLen);
+ p = buffer + remainingLen;
+ } // else p remains where it is
+ } else {
+ p = buffer;
+ }
+ } while(readedLen == toRead);
+
+ f.close();
+ kvi_free(buffer);
+ return true;
+}
+
+/*
+
+bool KviConfig::load()
+{
+ QFile f(m_szFileName);
+ if(!f.open(IO_ReadOnly))return false;
+
+
+ KviConfigGroup * p_group = 0;
+
+ KviStr dataLine;
+ bool bContinue;
+
+ do {
+ bContinue = kvi_readLine(&f,dataLine);
+ dataLine.stripWhiteSpace();
+ if(dataLine.hasData())
+ {
+ switch(*(dataLine.ptr()))
+ {
+ case '#':
+ // just skip it , it is a comment
+ break;
+ case '[':
+ {
+ //set the group
+ dataLine.cutLeft(1);
+ dataLine.cutRight(1);
+ dataLine.hexDecode();
+ if(dataLine.hasData())
+ {
+ QString szUtf8 = QString::fromUtf8(dataLine.ptr());
+ p_group = m_pDict->find(szUtf8);
+
+ if(!p_group)
+ {
+ p_group = new KviConfigGroup(17,false);
+ p_group->setAutoDelete(true);
+ m_pDict->insert(szUtf8,p_group);
+ }
+ }
+ }
+ break;
+ default:
+ {
+ //data entry...split in two...
+ KviStr name=dataLine.getToken('=');
+ name.stripRightWhiteSpace(); // strip any whitespace added externally
+ name.hexDecode();
+ if(name.hasData())
+ {
+ dataLine.stripLeftWhiteSpace(); // strip any whitespace added externally
+ dataLine.hexDecode();
+ //insert (replace items if needed)
+ QString *p_data=new QString(QString::fromUtf8(dataLine.ptr()));
+ if(!p_group)
+ {
+ // ops...we're missing a group
+ // use the default one
+ p_group = new KviConfigGroup(17,false);
+ p_group->setAutoDelete(true);
+ m_pDict->insert(KVI_CONFIG_DEFAULT_GROUP,p_group);
+ }
+ QString szName = QString::fromUtf8(name.ptr());
+ p_group->replace(szName,p_data);
+ }
+ }
+ break;
+ }
+ }
+ } while (bContinue);
+
+ f.close();
+ return true;
+}
+
+*/
+
+bool KviConfig::save()
+{
+ static unsigned char encode_table[256]=
+ {
+ // 000 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015
+ // NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI
+ 1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
+ // 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031
+ // DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
+ 1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
+ // 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047
+ // ! " # $ % & ' ( ) * + , - . /
+ 1 ,0 ,0 ,1 ,0 ,1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
+ // 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063
+ // 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,0 ,
+ // 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079
+ // @ A B C D E F G H I J K L M N O
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
+ // 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095
+ // P Q R S T U V W X Y Z [ \ ] ^ _
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,1 ,0 ,0 ,
+ // 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111
+ // ` a b c d e f g h i j k l m n o
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
+ // 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
+ // p q r s t u v w x y z { | } ~ 
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
+ // 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
+ //
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
+ // 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
+ //
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
+ // 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
+ //
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
+ // 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
+ //
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
+ // 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
+ // � � � � � � � � � � � � � � � �
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
+ // 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
+ // � � � � � � � � � � � � � � � �
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
+ // 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
+ // � � � � � � � � � � � � � � � �
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
+ // 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
+ // � � � � � � � �
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0
+ };
+
+
+ if(m_bReadOnly)return false;
+
+ KviFile f(m_szFileName);
+ if(!f.openForWriting())return false;
+ if(f.writeBlock("# KVIrc configuration file\n",27) != 27)return false;
+
+ KviPointerHashTableIterator<QString,KviConfigGroup> it(*m_pDict);
+ while (it.current())
+ {
+ if((it.current()->count() != 0) || (m_bPreserveEmptyGroups))
+ {
+ KviStr group(m_bLocal8Bit ? KviQString::toLocal8Bit(it.currentKey()) : KviQString::toUtf8(it.currentKey()));
+ group.hexEncodeWithTable(encode_table);
+
+ if(!f.putChar('['))return false;
+ if(f.writeBlock(group.ptr(),group.len()) < (int) group.len())return false;
+ if(f.writeBlock("]\n",2) < 2)return false;
+
+ KviConfigGroup * dict = (KviConfigGroup *)it.current();
+ KviConfigGroupIterator it2(*dict);
+
+ KviStr szName,szValue;
+ while(QString * p_str = it2.current())
+ {
+ szName = m_bLocal8Bit ? KviQString::toLocal8Bit(it2.currentKey()) : KviQString::toUtf8(it2.currentKey());
+ szValue = m_bLocal8Bit ? KviQString::toLocal8Bit(*p_str) : KviQString::toUtf8(*p_str);
+ szName.hexEncodeWithTable(encode_table);
+ szValue.hexEncodeWhiteSpace();
+
+ if(f.writeBlock(szName.ptr(),szName.len()) < (int) szName.len())return false;
+ if(!f.putChar('='))return false;
+ if(f.writeBlock(szValue.ptr(),szValue.len()) < (int) szValue.len())return false;
+ if(!f.putChar('\n'))return false;
+ ++it2;
+ }
+ }
+ ++it;
+ }
+ f.close();
+ m_bDirty = false;
+ return true;
+}
+
+void KviConfig::setGroup(const QString & szGroup)
+{
+ m_szGroup = szGroup;
+ if(m_bPreserveEmptyGroups)
+ {
+ if(!hasGroup(szGroup))
+ {
+ getCurrentGroup(); // we need it to be created.
+ m_bDirty = true;
+ }
+ }
+}
+
+bool KviConfig::hasKey(const QString & szKey)
+{
+ KviConfigGroup * p_group = getCurrentGroup();
+ return (p_group->find(szKey) != 0);
+}
+
+bool KviConfig::hasGroup(const QString & szGroup)
+{
+ return (m_pDict->find(szGroup) != 0);
+}
+
+KviConfigGroup * KviConfig::getCurrentGroup()
+{
+ if(m_szGroup.isEmpty())m_szGroup = KVI_CONFIG_DEFAULT_GROUP;
+ KviConfigGroup * p_group = m_pDict->find(m_szGroup);
+ if(!p_group)
+ {
+ //create the group
+ p_group = new KviConfigGroup(17,false);
+ p_group->setAutoDelete(true);
+ m_pDict->insert(m_szGroup,p_group);
+ }
+ return p_group;
+}
+
+////////////////////////////////// KviStr
+
+void KviConfig::writeEntry(const QString & szKey,const QString & szValue)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString *p_data=new QString(szValue);
+ p_group->replace(szKey,p_data);
+}
+
+// FIXME: #warning "We have probs here ?"
+
+QString KviConfig::readEntry(const QString & szKey,const QString & szDefault)
+{
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString * p_str = p_group->find(szKey);
+ if(!p_str)
+ {
+ m_szStrBuffer = szDefault;
+ } else {
+ m_szStrBuffer = *p_str;
+ }
+ return m_szStrBuffer;
+}
+
+//////////////////////////////////// QString
+
+/*
+QString KviConfig::readQStringEntry(const char *szKey,const QString &szDefault)
+{
+ KviStrDict * p_group = getCurrentGroup();
+ KviStr * p_str = p_group->find(szKey);
+ if(!p_str)return szDefault;
+ return QString::fromUtf8(p_str->ptr());
+}
+*/
+
+/*
+void KviConfig::writeEntry(const char *szKey,const QString &szValue)
+{
+ m_bDirty = true;
+ KviStrDict * p_group = getCurrentGroup();
+ p_group->replace(szKey,new KviStr(szValue.utf8().data()));
+}
+*/
+
+////////////////////////////////// QStringList
+
+static QString g_szConfigStringListSeparator(",\\[ITEM],");
+
+QStringList KviConfig::readStringListEntry(const QString & szKey,const QStringList &list)
+{
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString * p_str = p_group->find(szKey);
+ if(!p_str)return list;
+#ifdef COMPILE_USE_QT4
+ return p_str->split(g_szConfigStringListSeparator);
+#else
+ return QStringList::split(g_szConfigStringListSeparator,*p_str);
+#endif
+}
+
+void KviConfig::writeEntry(const QString & szKey,const QStringList &list)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString *p_data=new QString(list.join(g_szConfigStringListSeparator));
+ p_group->replace(szKey,p_data);
+}
+
+////////////////////////////////// KviValueList<int>
+
+KviValueList<int> KviConfig::readIntListEntry(const QString & szKey,const KviValueList<int> &list)
+{
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString * p_str = p_group->find(szKey);
+ if(!p_str)
+ {
+ //debug("Returning default list for group %s and key %s",m_szGroup.latin1(),szKey.latin1());
+ return list;
+ }
+#ifdef COMPILE_USE_QT4
+ QStringList sl = p_str->split(",");
+#else
+ QStringList sl = QStringList::split(",",*p_str);
+#endif
+ KviValueList<int> ret;
+
+ //debug("Got option list for group %s and key %s: %s",m_szGroup.latin1(),szKey.latin1(),p_str->latin1());
+
+ for(QStringList::Iterator it = sl.begin();it != sl.end();++it)
+ {
+ bool bOk;
+ int iTmp = (*it).toInt(&bOk);
+ if(bOk)ret.append(iTmp);
+ }
+
+ return ret;
+}
+
+
+void KviConfig::writeEntry(const QString & szKey,const KviValueList<int> &list)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ KviStr szData;
+ for(KviValueList<int>::ConstIterator it = list.begin();it != list.end();++it)
+ {
+ if(szData.hasData())szData.append(',');
+ szData.append(KviStr::Format,"%d",*it);
+ }
+ //debug("Writing option list for group %s and key %s: %s",m_szGroup.latin1(),szKey.latin1(),szData.ptr());
+
+ p_group->replace(szKey,new QString(szData.ptr()));
+}
+
+////////////////////////////////// KviPixmap
+
+// FIXME: #warning "Spaces in image names ?"
+
+void KviConfig::writeEntry(const QString & szKey,const KviPixmap &pixmap)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString *p_data=new QString();
+ KviStringConversion::toString(pixmap,*p_data);
+ p_group->replace(szKey,p_data);
+}
+
+KviPixmap KviConfig::readPixmapEntry(const QString & szKey,const KviPixmap &pixDef)
+{
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString * p_str = p_group->find(szKey);
+ if(p_str)
+ {
+ KviPixmap ret("");
+ return KviStringConversion::fromString(*p_str,ret) ? ret : pixDef;
+ } else {
+ return pixDef;
+ }
+}
+
+////////////////////////////////// KviMsgType
+
+void KviConfig::writeEntry(const QString & szKey,const KviMsgType &msg)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString szData;
+ KviStringConversion::toString(msg,szData);
+ p_group->replace(szKey,new QString(szData));
+}
+
+KviMsgType KviConfig::readMsgTypeEntry(const QString & szKey,const KviMsgType &msgDef)
+{
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString * p_str = p_group->find(szKey);
+ if(!p_str)return msgDef;
+ KviMsgType ret = msgDef;
+ KviStringConversion::fromString(*p_str,ret);
+ return ret;
+}
+
+////////////////////////////////// QColor
+
+void KviConfig::writeEntry(const QString & szKey,const QColor &clr)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ KviStr szData(KviStr::Format,"%d,%d,%d",clr.red(),clr.green(),clr.blue());
+ p_group->replace(szKey,new QString(szData.ptr()));
+}
+
+QColor KviConfig::readColorEntry(const QString & szKey,const QColor &clr)
+{
+ KviConfigGroup * p_group = getCurrentGroup();
+ QColor color(clr);
+ QString * pointer_that_IS_initialized = p_group->find(szKey);
+
+
+ if(pointer_that_IS_initialized)
+ {
+
+ KviStr str(*pointer_that_IS_initialized);
+ str.stripLeftWhiteSpace();
+
+ KviStr red,green,blue;
+
+ str.getToken(red,',');
+ str.getToken(green,',');
+ str.getToken(blue,',');
+
+ if((red.isUnsignedNum())&&(green.isUnsignedNum())&&(blue.isUnsignedNum())){
+ bool bOk;
+ int r = red.toInt(&bOk) % 256;
+ int g = green.toInt(&bOk) % 256;
+ int b = blue.toInt(&bOk) % 256;
+ if(r < 0)r = -r;
+ if(g < 0)g = -g;
+ if(b < 0)b = -b;
+ color.setRgb(r,g,b);
+ }
+ }
+ return color;
+}
+
+////////////////////////////////// QFont
+
+void KviConfig::getFontProperties(KviStr & buffer,QFont *fnt)
+{
+ QString tmp;
+ KviStringConversion::toString(*fnt,tmp);
+ buffer = tmp;
+}
+
+void KviConfig::writeEntry(const QString & szKey,QFont &fnt)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString *p_data = new QString();
+ KviStringConversion::toString(fnt,*p_data);
+ p_group->replace(szKey,p_data);
+}
+
+
+void KviConfig::setFontProperties(KviStr & str,QFont *fnt)
+{
+ KviStringConversion::fromString(str.ptr(),*fnt);
+}
+
+QFont KviConfig::readFontEntry(const QString & szKey,const QFont &fnt)
+{
+ QFont font(fnt);
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString * p_str = p_group->find(szKey);
+ if(p_str)
+ {
+ //FontEntry=Arial,12,9,0,100,italic,underline,strikeout,
+ KviStr str(*p_str);
+ str.stripLeftWhiteSpace();
+ setFontProperties(str,&font);
+ }
+ return font;
+}
+
+////////////////////////////////// bool
+
+void KviConfig::writeEntry(const QString & szKey,bool bTrue)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString *p_data = new QString(bTrue ? "true" : "false");
+ p_group->replace(szKey,p_data);
+}
+
+bool KviConfig::readBoolEntry(const QString & szKey,bool bTrue)
+{
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString * p_str = p_group->find(szKey);
+ if(!p_str)return bTrue;
+ static QString szTrue = "true";
+ return (KviQString::toLower(*p_str) == szTrue);
+}
+
+////////////////////////////////// QRect
+
+void KviConfig::writeEntry(const QString & szKey,const QRect &rct)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString szBuf;
+ KviStringConversion::toString(rct,szBuf);
+ p_group->replace(szKey,new QString(szBuf));
+}
+
+QRect KviConfig::readRectEntry(const QString & szKey,const QRect &rct)
+{
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString * str = p_group->find(szKey);
+ if(!str)return rct;
+ QRect ret;
+ return KviStringConversion::fromString(*str,ret) ? ret : rct;
+}
+
+////////////////////////////////// unsigned short
+
+void KviConfig::writeEntry(const QString & szKey,unsigned short usValue)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString *p_data = new QString();
+ p_data->setNum(usValue);
+ p_group->replace(szKey,p_data);
+}
+
+unsigned short int KviConfig::readUShortEntry(const QString & szKey,unsigned short int usDefault)
+{
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString * p_str = p_group->find(szKey);
+ if(!p_str)return usDefault;
+ bool bOk;
+ unsigned short int usVal=p_str->toUShort(&bOk);
+ return bOk ? usVal : usDefault;
+}
+
+/*
+////////////////////////////////// unsigned long
+
+Unused code
+void KviConfig::writeEntry(const char *szKey,unsigned long lValue)
+{
+ m_bDirty = true;
+ KviStrDict * p_group = getCurrentGroup();
+ KviStr *p_data = new KviStr();
+ p_data->setNum(lValue);
+ p_group->replace(szKey,p_data);
+}
+
+unsigned long KviConfig::readULongEntry(const char *szKey,unsigned long lDefault)
+{
+ KviStrDict * p_group = getCurrentGroup();
+ KviStr * p_str = p_group->find(szKey);
+ if(!p_str)return lDefault;
+ bool bOk;
+ unsigned long lVal=p_str->toULong(&bOk);
+ return bOk ? lVal : lDefault;
+}
+*/
+
+////////////////////////////////// int
+
+void KviConfig::writeEntry(const QString & szKey,int iValue)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString *p_data = new QString();
+ p_data->setNum(iValue);
+ p_group->replace(szKey,p_data);
+}
+
+int KviConfig::readIntEntry(const QString & szKey,int iDefault)
+{
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString * p_str = p_group->find(szKey);
+ if(!p_str)return iDefault;
+ bool bOk;
+ int iVal=p_str->toInt(&bOk);
+ return bOk ? iVal : iDefault;
+}
+
+////////////////////////////////// unsigned int
+
+void KviConfig::writeEntry(const QString & szKey,unsigned int iValue)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString *p_data = new QString();
+ p_data->setNum(iValue);
+ p_group->replace(szKey,p_data);
+}
+
+unsigned int KviConfig::readUIntEntry(const QString & szKey,unsigned int iDefault)
+{
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString * p_str = p_group->find(szKey);
+ if(!p_str)return iDefault;
+ bool bOk;
+ unsigned int iVal=p_str->toUInt(&bOk);
+ return bOk ? iVal : iDefault;
+}
+
+////////////////////////////////// char
+
+void KviConfig::writeEntry(const QString & szKey,char iValue)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString * p_data = new QString();
+ p_data->setNum(iValue);
+ p_group->replace(szKey,p_data);
+}
+
+char KviConfig::readCharEntry(const QString & szKey,char iDefault)
+{
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString * p_str = p_group->find(szKey);
+ if(!p_str)return iDefault;
+ bool bOk;
+ char iVal=(char)p_str->toInt(&bOk);
+ return bOk ? iVal : iDefault;
+}
+
+////////////////////////////////// unsigned char
+
+void KviConfig::writeEntry(const QString & szKey,unsigned char iValue)
+{
+ m_bDirty = true;
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString *p_data = new QString();
+ p_data->setNum(iValue);
+ p_group->replace(szKey,p_data);
+}
+
+unsigned char KviConfig::readUCharEntry(const QString & szKey,unsigned char iDefault)
+{
+ KviConfigGroup * p_group = getCurrentGroup();
+ QString * p_str = p_group->find(szKey);
+ if(!p_str)return iDefault;
+ bool bOk;
+ unsigned char iVal=(unsigned char)p_str->toUInt(&bOk);
+ return bOk ? iVal : iDefault;
+}
+
+
+#ifdef COMPILE_ON_WINDOWS
+
+ // On windows we need to override new and delete operators
+ // to ensure that always the right new/delete pair is called for an object instance
+ // This bug is present in all the classes exported by a module that
+ // can be instantiated/destroyed from external modules.
+ // (this is a well known bug described in Q122675 of MSDN)
+
+ void * KviConfig::operator new(size_t tSize)
+ {
+ return kvi_malloc(tSize);
+ }
+
+ void KviConfig::operator delete(void * p)
+ {
+ kvi_free(p);
+ }
+
+#endif
diff --git a/src/kvilib/ext/kvi_config.h b/src/kvilib/ext/kvi_config.h
new file mode 100644
index 00000000..6eef4e05
--- /dev/null
+++ b/src/kvilib/ext/kvi_config.h
@@ -0,0 +1,162 @@
+#ifndef _KVI_CONFIG_H_INCLUDED_
+#define _KVI_CONFIG_H_INCLUDED_
+
+//=============================================================================
+//
+// File : kvi_config.h (/usr/build/NEW_kvirc/kvirc/kvilib/kvi_config.h)
+// Last major modification : Thu Jan 14 1999 18:01:22 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_string.h"
+#include "kvi_settings.h"
+#include "kvi_heapobject.h"
+#include "kvi_pointerhashtable.h"
+#include "kvi_valuelist.h"
+
+#include <qcolor.h>
+#include <qfont.h>
+#include <qrect.h>
+#include <qstringlist.h>
+
+#define KVI_CONFIG_DEFAULT_GROUP "KVIrc"
+
+class KviPixmap;
+class KviMsgType;
+
+typedef KviPointerHashTable<QString,QString> KviConfigGroup;
+typedef KviPointerHashTableIterator<QString,QString> KviConfigGroupIterator;
+typedef KviPointerHashTableIterator<QString,KviConfigGroup> KviConfigIterator;
+
+class KVILIB_API KviConfig : public KviHeapObject
+{
+public:
+ enum FileMode { Read = 1 , Write = 2 , ReadWrite = 3 };
+public:
+ KviConfig(const QString &filename,FileMode f/* = ReadWrite*/,bool bLocal8Bit = false);
+ KviConfig(const char *filename,FileMode f/* = ReadWrite*/,bool bLocal8Bit = false);
+ ~KviConfig();
+private:
+ bool m_bLocal8Bit;
+ KviPointerHashTable<QString,KviConfigGroup> * m_pDict;
+ QString m_szFileName;
+ bool m_bDirty;
+ QString m_szStrBuffer;
+ QString m_szGroup;
+ bool m_bPreserveEmptyGroups;
+ bool m_bReadOnly;
+private:
+ bool load();
+ bool save();
+ KviConfigGroup * getCurrentGroup();
+public:
+ //
+ // Useful when saving...
+ // Normally this class does not save empty groups
+ // and setGroup() is never a config modification.
+ // If the group is not existing it will be effectively
+ // created only at the first attempt to read from it or write to it.
+ // With this flag set to true the KviConfig class will
+ // write down also the empty groups , and calls to setGroup()
+ // will create the groups if not existing yet (and set the config data
+ // as modified).
+ //
+ void preserveEmptyGroups(bool bPreserve){ m_bPreserveEmptyGroups = bPreserve; };
+ const QString & fileName(){ return m_szFileName; };
+ bool readOnly(){ return m_bReadOnly; };
+ void setReadOnly(bool bReadOnly){ m_bReadOnly = bReadOnly; };
+ bool dirty(){ return m_bDirty; };
+ //
+ // This sets the save path for the config file
+ // In this way you can load a system-wide read-only config file
+ // as default configuration, alter its settings and save it to the
+ // user local configuration directory
+ void setSavePath(const QString & savePath){ m_szFileName = savePath; };
+ KviPointerHashTable<QString,KviConfigGroup> *dict(){ return m_pDict; };
+
+ void clearDirtyFlag(){ m_bDirty = false; };
+ void clear();
+ void clearGroup(const QString & szGroup);
+ void clearKey(const QString & szKey);
+ unsigned int groupsCount(){ return m_pDict->count(); };
+ bool sync(){ return save(); };
+ bool hasKey(const QString & szKey);
+ bool hasGroup(const QString & szGroup);
+ void setGroup(const QString & szGroup);
+ //void getContentsString(KviStr &buffer);
+ const QString & group(){ return m_szGroup; };
+ void writeEntry(const QString & szKey,const QString & szValue);
+ void writeEntry(const QString & szKey,const char * szValue)
+ { writeEntry(szKey,QString::fromUtf8(szValue)); };
+ QString readEntry(const QString & szKey,const QString & szDefault = QString::null);
+ // HACK for KviOptions.. (FIXME)
+ QString readKviStrEntry(const QString &szKey,const KviStr &szDefault)
+ { return readEntry(szKey,szDefault.ptr()); };
+ //void writeEntry(const char *szKey,KviStr &szValue);
+ //const char * readEntry(const char *szKey,KviStr &szDefault);
+ void writeEntry(const QString & szKey,const KviPixmap &pixmap);
+ KviPixmap readPixmapEntry(const QString & szKey,const KviPixmap &pixDef);
+ void writeEntry(const QString & szKey,const KviMsgType &msg);
+ KviMsgType readMsgTypeEntry(const QString & szKey,const KviMsgType &msgDef);
+ void writeEntry(const QString & szKey,const QColor &clr);
+ QColor readColorEntry(const QString & szKey,const QColor &clr);
+ void writeEntry(const QString & szKey,QFont &fnt);
+ QFont readFontEntry(const QString & szKey,const QFont &fnt);
+ void writeEntry(const QString & szKey,bool bTrue);
+ bool readBoolEntry(const QString & szKey,bool bTrue);
+ QRect readRectEntry(const QString & szKey,const QRect &rct);
+ void writeEntry(const QString & szKey,const QRect &rct);
+ QStringList readStringListEntry(const QString & szKey,const QStringList &list);
+ void writeEntry(const QString & szKey,const QStringList &list);
+ KviValueList<int> readIntListEntry(const QString & ,const KviValueList<int> &list);
+ void writeEntry(const QString & szKey,const KviValueList<int> &list);
+ QString readQStringEntry(const QString & szKey,const QString &szDefault = QString::null)
+ { return readEntry(szKey,szDefault); };
+ //void writeEntry(const QString & szKey,const QString &szValue);
+ //void writeEntry(const char *szKey,unsigned long lValue);
+ //unsigned long readULongEntry(const char *szKey,unsigned long lDefault);
+ //void writeEntry(const char *szKey,long lValue);
+ //long readLongEntry(const char *szKey,long lDefault);
+ void writeEntry(const QString & szKey,int iValue);
+ int readIntEntry(const QString & szKey,int iDefault);
+ void writeEntry(const QString & szKey,unsigned short int usValue);
+ unsigned short int readUShortEntry(const QString & szKey,unsigned short int usDefault);
+ void writeEntry(const QString & szKey,unsigned int iValue);
+ unsigned int readUIntEntry(const QString & szKey,unsigned int iDefault);
+ void writeEntry(const QString & szKey,char iValue);
+ char readCharEntry(const QString & szKey,char iDefault);
+ void writeEntry(const QString & szKey,unsigned char iValue);
+ unsigned char readUCharEntry(const QString & szKey,unsigned char iDefault);
+
+ static void getFontProperties(KviStr & buffer,QFont *fnt);
+ static void setFontProperties(KviStr & str,QFont *fnt);
+
+#ifdef COMPILE_ON_WINDOWS
+ // On windows we need to override new and delete operators
+ // to ensure that always the right new/delete pair is called for an object instance
+ // This bug is present in all the classes exported by a module that
+ // can be instantiated/destroyed from external modules.
+ // (this is a well known bug described in Q122675 of MSDN)
+ void * operator new(size_t tSize);
+ void operator delete(void * p);
+#endif
+};
+
+#endif //!_KVI_CONFIG_H_INCLUDED_
diff --git a/src/kvilib/ext/kvi_crypt.cpp b/src/kvilib/ext/kvi_crypt.cpp
new file mode 100644
index 00000000..84a636aa
--- /dev/null
+++ b/src/kvilib/ext/kvi_crypt.cpp
@@ -0,0 +1,240 @@
+//=============================================================================
+//
+// File : kvi_crypt.cpp
+// Creation date : Fri Nov 03 2000 02:34:43 CEST by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2007 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+//=============================================================================
+
+#define __KVILIB__
+
+#include "kvi_crypt.h"
+#include "kvi_locale.h"
+
+#ifdef COMPILE_ON_WINDOWS
+ #include "kvi_malloc.h"
+#endif
+
+/*
+ @doc: crypt_engines
+ @type:
+ generic
+ @keyterms:
+ cryptography, privacy, private key, text transformation
+ @title:
+ Cryptography and text transformation
+ @short:
+ Crypt/text transformation engines and how to use them
+ @body:
+ [big]Introduction[/big][br]
+ Well , there is a concrete background noise about security around the net.
+ And I've thought that adding a little cryptography support to KVIrc wasn't
+ a bad idea. So I've first comed out with the "crypt engines", that
+ allowed to have secure conversations on channels, queries and dcc chats;
+ then found out that the realized structure was perfect to be "generalized"
+ into "text transformation" support.[br]
+ [big]The concept[/big][br]
+ In few words, the "text transformation" engine is a layer between the user and the
+ IRC connection. You type some text in the input line of a query window (for example),
+ the engine transforms the text in some way and then sends it to the remote target.
+ The trick works also in the reverse way: some data come from the remote target,
+ the engine retransforms the text in some other way and displays it to the local user.[br]
+ The "incoming" transformation is usually the inverse of the "outgoing" one, but it
+ is not mandatory. It will become clear in few sentences that some engines will do no "incoming"
+ transformation at all. The original use of the transformation engines was to crypt the
+ outgoing data and to decrypt the incoming data; anyway, the engines can perform
+ other funky tasks. One of them is remapping the local charset to a "standardized" one
+ when sending text to a channel (or some other target) and doing the inverse map on
+ the way back. A totally "fantastic" usage of this concept could be an "on-the-fly translator";
+ it could translate for example Italian to English while sending to a channel
+ and English to Italian on the way back...the implementation of a such engine is left
+ to the reader as exercise :) Another (maybe less interesting) usage is to
+ colorize the outgoing text, or transform it
+ in a way that it is still readable but has a different look. This engine
+ would not require a back transformation (so no "decrypt stage"). A "symmetric"
+ idea could be an engine that strips the color codes from the incoming text: this
+ engine would not require a "crypting" stage.[br]
+
+ [big]The name of this stuf[/big][br]
+ Initially all this stuff was named "cryptography support".
+ Then the "cryptography" comed out to be not "enough" to describe
+ the framework, so "text transformation" is a more generic term.
+ Anyway, both terms were used in the documentation and the source.
+ Just as example, the "text transformation engine" is called
+ KviCryptEngine in the sources. So actually the terms "crypt"
+ and "text transformations" refer to the "same thing".
+ You will often find the term "encrypt" standing for "outgoing text
+ transformation" and "decrypt" standing for "incoming text transformation".[br]
+
+ [big]Yes, but why cryptography (on IRC) ?[/big][br]
+ Because it MAY be useful. More than once people have asked me to add some
+ crypting support to the dcc chats. Yes , I know that there are other
+ "secure communication" tools , but actually I can't find one that is able to
+ implement a "secure real time conversation". And what about a MULTIPLE real
+ time secure conversation ? This can be done on an IRC channel now.[br]
+
+ [big]The working things[/big][br]
+ KVIrc can use a text transformation engine on irc channels, in the queries
+ and the dcc chats. At the time I am writing, only the [module:rijndael]Rijndael[/module] crypt engine
+ is available: this is a private key encryption algorithm that assures
+ a "pretty good" security level. More engines will be surely available
+ at the time of the 3.0.0 release of KVIrc. The engines
+ can be activated by the dedicated dialog that can be accessed from the "button bar"
+ of the window. Once an engine has been enabled all the text that you type
+ in the input line (that is not a command obviously) is encrypted
+ and sent to the remote endpoint. If you want to sent a non crypted message
+ while an engine is working you can use the CTRL+P escape: by placing
+ that character as the FIRST CHARACTER of the line you will avoid crypting.
+ Every engine has different capabilities: some can both encrypt
+ and decrypt, other perform only half of the operations. Some engines
+ need a key (the crypt engines obviously), or two keys (you can specify
+ one for the outgoing data and one for the incoming). You can specify
+ all these options in the crypt/text transformation dialog.[br]
+ Obviously (with the current implementations) all the conversation endpoints
+ must agree on the engine (or better algorithm) used and on the key(s).
+ The key is user specified, so you have to find a secure way to negotiate
+ it with your communication engpoints. If you can meet the persons in the "real life",
+ this is the best way to exchange the keys, otherwise you can use mail & pgp.
+ Yes, this is a "miss" of the crypt protocol: it is missing a public key handshake.[br]
+
+ [big]The first test[/big][br]
+ A cool way to test a crypting engine is to use a "self query": connect to
+ any irc server, and execute [cmd]query[/cmd] <yournickname>; a query window
+ with you both as source and target will popup; activate a crypt engine
+ and enable both encryption and decryption; specify the same key for
+ bot directions and then type some text in the input line: you will see
+ the message twice: one is "your local text" and the other is the server routed one.
+ Then you can try to activate encryption only and leaving decryption disabled:
+ you will see how the text would appear to a possible "man in the middle".
+ You can also try to use different keys for encrypting and decrypting,
+ and play with the CTRL+P escape.[br]
+
+ [big]The protocol[/big][br]
+ Well, there is no protocol actually , only the existing implementations , that
+ can be accessed by anyone that want to reproduce them. There are only some
+ points relating to the crypting engines that need to be cleared:[br]
+ The crypted text must be suitable to be sent thru an IRC connection;
+ this means that some characters can not appear in the crypted text (e.g. CR,LF,NULL....).
+ KVIrc solves it in a simple way: the crypted binary data is encoded,
+ either as hexadecimal numeric string or in base64.[br]
+ An escape character has been defined to identify messages that are "crypted" from the
+ ones that are not: this character has ascii code 30 (decimal).[br]
+ The encoding is used in private messages only and has the following format:[br]
+ PRIVMSG <target> :<escape_char_ascii_30><encrypted message>[br]
+ ASCII 30 does not correspond to any widely used escape sequence and allows
+ mixing encrypted and plain text messages in a conversation...Well, this is not
+ so pretty but you can exchange crypted messages with one or two friends while
+ talking on a normal IRC channel: nobody else than your friends will be able
+ to understand the message; others will see senseless sequences of characters.
+ You will be still able to read the unencrypted messages of the other people
+ on the channel.[br] The escape character is not needed if the engine
+ performs non-crypting tasks: a charset mapper will produce text that
+ is meant to be readed by anyone on the channel, a text colorizer will
+ act in a similar way too. So the escape character is used for the "crypting"
+ engines only.
+
+ [big]An idea for the future implementations[/big][br]
+ A "public key" handshake protocol could be implemented.
+*/
+
+
+ KviCryptEngine::KviCryptEngine()
+ {
+#ifdef COMPILE_CRYPT_SUPPORT
+ setLastError(__tr2qs("Invalid crypt engine"));
+ m_iMaxEncryptLen = -1; // unlimited
+ m_deallocFunc = 0;
+#endif //COMPILE_CRYPT_SUPPORT
+ }
+
+ KviCryptEngine::~KviCryptEngine()
+ {
+ }
+
+#ifdef COMPILE_CRYPT_SUPPORT
+
+ bool KviCryptEngine::init(const char *,int,const char *,int)
+ {
+ return false;
+ }
+
+ KviCryptEngine::EncryptResult KviCryptEngine::encrypt(const char *,KviStr &)
+ {
+// debug("Pure virtual KviCryptEngine::encrypt() called");
+ return EncryptError;
+ }
+
+ KviCryptEngine::DecryptResult KviCryptEngine::decrypt(const char *,KviStr &)
+ {
+// debug("Pure virtual KviCryptEngine::decrypt() called");
+ return DecryptError;
+ }
+
+
+ KviCryptEngineManager::KviCryptEngineManager()
+ {
+ m_pEngineDict = new KviPointerHashTable<QString,KviCryptEngineDescription>;
+ m_pEngineDict->setAutoDelete(true);
+ }
+
+ KviCryptEngineManager::~KviCryptEngineManager()
+ {
+ delete m_pEngineDict;
+ }
+
+ void KviCryptEngineManager::registerEngine(KviCryptEngineDescription * d)
+ {
+ m_pEngineDict->replace(d->szName,d);
+ }
+
+ void KviCryptEngineManager::unregisterEngine(const QString &szName)
+ {
+ m_pEngineDict->remove(szName);
+ }
+
+ void KviCryptEngineManager::unregisterEngines(void * providerHandle)
+ {
+ KviPointerHashTableIterator<QString,KviCryptEngineDescription> it(*m_pEngineDict);
+ while(it.current())
+ {
+ if(it.current()->providerHandle == providerHandle)
+ m_pEngineDict->remove(it.currentKey());
+ else
+ ++it;
+ }
+ }
+
+ KviCryptEngine * KviCryptEngineManager::allocateEngine(const QString &szName)
+ {
+ KviCryptEngineDescription * d = m_pEngineDict->find(szName);
+ if(!d)return 0;
+ KviCryptEngine * e = d->allocFunc();
+ if(!e)return 0;
+ e->m_deallocFunc = d->deallocFunc; // remember the dealloc func from now on
+ return e;
+ }
+
+ void KviCryptEngineManager::deallocateEngine(KviCryptEngine * e)
+ {
+ if(!e)return;
+ crypt_engine_deallocator_func deallocFunc = e->m_deallocFunc;
+ deallocFunc(e);
+ }
+
+#endif //COMPILE_CRYPT_SUPPORT
diff --git a/src/kvilib/ext/kvi_crypt.h b/src/kvilib/ext/kvi_crypt.h
new file mode 100644
index 00000000..ae3bc4f0
--- /dev/null
+++ b/src/kvilib/ext/kvi_crypt.h
@@ -0,0 +1,160 @@
+#ifndef _KVI_CRYPT_H_
+#define _KVI_CRYPT_H_
+
+//=============================================================================
+//
+// File : kvi_crypt.h
+// Creation date : Fri Nov 03 2000 01:45:21 CEST by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2007 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_settings.h"
+
+
+//
+// Base class for all IRC crypt engines
+// These intend to encrypt plain text into something
+// that can be sent through the IRC protocol...
+// so it should not contain NULL, CR , LF and other
+// similar stuff...
+//
+
+
+#include "kvi_qstring.h"
+#include "kvi_string.h"
+#include "kvi_heapobject.h"
+#include "kvi_pointerhashtable.h"
+
+#include <qobject.h>
+
+#ifdef COMPILE_CRYPT_SUPPORT
+ class KviCryptEngine;
+
+ typedef KviCryptEngine * (*crypt_engine_allocator_func)();
+ typedef void (*crypt_engine_deallocator_func)(KviCryptEngine *);
+#endif //COMPILE_CRYPT_SUPPORT
+
+ // we must include this declaration to make moc happy even
+ // if we're not compiling the crypt support
+
+ class KVILIB_API KviCryptEngine : public QObject, public KviHeapObject
+ {
+ Q_OBJECT
+ friend class KviCryptEngineManager;
+ public:
+ KviCryptEngine();
+ virtual ~KviCryptEngine();
+
+#ifdef COMPILE_CRYPT_SUPPORT
+ private:
+ crypt_engine_deallocator_func m_deallocFunc; // this is accessed by KviCryptEngineManager only
+ QString m_szLastError;
+ int m_iMaxEncryptLen;
+ public:
+ void setMaxEncryptLen(int m){ m_iMaxEncryptLen = m; };
+ int maxEncryptLen(){ return m_iMaxEncryptLen; };
+ virtual bool init(const char * encKey,int encKeyLen,const char * decKey,int decKeyLen);
+ //
+ // Encrypts utf8 plainText and returns the encrypted
+ // data in outBuffer. The encrypted data must be
+ // suitable for sending thru an IRC (eventually DCC
+ // that is less restrictive) connection and must be utf8 encoded: so
+ // no NULL, CR and LF in the output.
+ // 0x01 should be also avoided since
+ // it is the CTCP delimiter.
+ // Converting the result in a HEX string
+ // is a good trick...also Base64 could be used.
+ // Should return false in case of an error.
+ // Theoretically we could allow NULLs in plainText
+ // but this is not the case of KVIrc.
+ //
+ enum EncryptResult { Encrypted, Encoded, EncryptError };
+ virtual EncryptResult encrypt(const char * plainText,KviStr &outBuffer);
+ //
+ // Decrypts the utf8 data in inBuffer and puts the decrypted utf8
+ // stuff in plainText. inBuffer is the thingie
+ // that we got from outBuffer of encrupt() so it
+ // follows the same rules.
+ // Should return false in case of error.
+ //
+ enum DecryptResult { DecryptOkWasEncrypted, DecryptOkWasEncoded, DecryptOkWasPlainText, DecryptError };
+ virtual DecryptResult decrypt(const char * inBuffer,KviStr &plainText);
+ //
+ // Returns the string containing the description
+ // of the last error or an empty string if there
+ // was no error after the last init() call.
+ //
+ const QString &lastError(){ return m_szLastError; };
+ protected:
+ //
+ // The following two should have clear meaning
+ //
+ void clearLastError(){ m_szLastError = ""; };
+ void setLastError(const QString &err){ m_szLastError = err; };
+#endif //COMPILE_CRYPT_SUPPORT
+ };
+
+#ifdef COMPILE_CRYPT_SUPPORT
+ #define KVI_CRYPTENGINE_CAN_ENCRYPT 1
+ #define KVI_CRYPTENGINE_CAN_DECRYPT 2
+ #define KVI_CRYPTENGINE_WANT_ENCRYPT_KEY 4
+ #define KVI_CRYPTENGINE_WANT_DECRYPT_KEY 8
+
+ class KVILIB_API KviCryptEngineDescription : public KviHeapObject
+ {
+ public:
+ KviCryptEngineDescription(){};
+ virtual ~KviCryptEngineDescription(){};
+ public:
+ QString szName; // engine name
+ QString szDescription; // details
+ QString szAuthor; // algorithm author
+ int iFlags; // properties
+ crypt_engine_allocator_func allocFunc; // engine allocator
+ crypt_engine_deallocator_func deallocFunc; // deallocation function (if called from outside the origin module)
+ void * providerHandle; // used to identify the provider module
+ };
+
+
+ class KVILIB_API KviCryptEngineManager
+ {
+ public:
+ KviCryptEngineManager();
+ virtual ~KviCryptEngineManager();
+ private:
+ KviPointerHashTable<QString,KviCryptEngineDescription> * m_pEngineDict;
+ public:
+ const KviPointerHashTable<QString,KviCryptEngineDescription> * engineDict(){ return m_pEngineDict; };
+ void registerEngine(KviCryptEngineDescription * d);
+ void unregisterEngine(const QString &szName);
+ void unregisterEngines(void * providerHandle);
+ //
+ // Allocates a crypt engine
+ // Please note that the engine may be deleted from outside
+ // so you'd better connect the "destroyed" signal
+ //
+ KviCryptEngine * allocateEngine(const QString &szName);
+ void deallocateEngine(KviCryptEngine * e);
+ };
+
+#endif //COMPILE_CRYPT_SUPPORT
+
+
+#endif //!_KVI_CRYPT_H_
diff --git a/src/kvilib/ext/kvi_databuffer.cpp b/src/kvilib/ext/kvi_databuffer.cpp
new file mode 100644
index 00000000..7cad39c4
--- /dev/null
+++ b/src/kvilib/ext/kvi_databuffer.cpp
@@ -0,0 +1,135 @@
+//
+// File : kvi_databuffer.cpp
+// Creation date : Thu Aug 23 17:04:24 2001 GMT by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2001 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+
+#define __KVILIB__
+
+
+#define _KVI_DEBUG_CHECK_RANGE_
+
+#include "kvi_debug.h"
+
+#include "kvi_databuffer.h"
+#include "kvi_malloc.h"
+#include "kvi_memmove.h"
+
+// FIXME: this could resize in chunks!...this would be damn faster :)
+
+KviDataBuffer::KviDataBuffer(int uSize,const unsigned char * data)
+{
+ __range_valid(uSize > 0);
+ m_uSize = uSize;
+ m_pData = (unsigned char *)kvi_malloc(sizeof(unsigned char) * uSize);
+ if(data)kvi_memmove(m_pData,data,uSize);
+}
+
+KviDataBuffer::KviDataBuffer()
+{
+ m_uSize = 0;
+ m_pData = 0;
+}
+
+KviDataBuffer::~KviDataBuffer()
+{
+ if(m_pData)
+ {
+ __range_valid(m_uSize);
+ kvi_free(m_pData);
+ }
+}
+
+int KviDataBuffer::find(const unsigned char * block,int uSize)
+{
+ if(uSize < 1)return -1;
+ if(uSize > m_uSize)return -1;
+
+ int uSearchSize = (m_uSize - uSize) + 1;
+
+ for(int i=0;i<uSearchSize;i++)
+ {
+ if(m_pData[i] == *block)
+ {
+ // good beginning
+ if(uSize == 1)return i;
+ int j;
+ for(j = 1;j<uSize;j++)
+ {
+ if(m_pData[i + j] != block[j])
+ {
+ j = 0;
+ break;
+ }
+ }
+ if(j > 0)return i;
+ }
+ }
+
+ return -1;
+}
+
+int KviDataBuffer::find(unsigned char c)
+{
+ const unsigned char * p = m_pData;
+ const unsigned char * e = p + m_uSize;
+ while(p < e)
+ {
+ if(*p == c)return (p - m_pData);
+ p++;
+ }
+ return -1;
+}
+
+
+void KviDataBuffer::remove(int uSize)
+{
+ __range_valid((uSize <= m_uSize) && (uSize > 0));
+
+ m_uSize -= uSize;
+
+ if(m_uSize > 0)
+ {
+ kvi_memmove(m_pData,m_pData + uSize,m_uSize);
+ m_pData = (unsigned char *)kvi_realloc(m_pData,m_uSize * sizeof(unsigned char));
+ } else {
+ kvi_free(m_pData);
+ m_pData = 0;
+ }
+}
+
+void KviDataBuffer::resize(int uSize)
+{
+ __range_valid(uSize >= 0);
+ if(uSize > 0)
+ {
+ m_pData = (unsigned char *)kvi_realloc(m_pData,uSize * sizeof(unsigned char));
+ } else {
+ kvi_free(m_pData);
+ m_pData = 0;
+ }
+ m_uSize = uSize;
+}
+
+void KviDataBuffer::append(const unsigned char * data,int uSize)
+{
+ m_pData = (unsigned char *)kvi_realloc(m_pData,m_uSize + uSize);
+ kvi_memmove(m_pData + m_uSize,data,uSize);
+ m_uSize += uSize;
+}
diff --git a/src/kvilib/ext/kvi_databuffer.h b/src/kvilib/ext/kvi_databuffer.h
new file mode 100644
index 00000000..62e09b06
--- /dev/null
+++ b/src/kvilib/ext/kvi_databuffer.h
@@ -0,0 +1,56 @@
+#ifndef _KVI_DATABUFFER_H_
+#define _KVI_DATABUFFER_H_
+//
+// File : kvi_databuffer.h
+// Creation date : Thu Aug 23 17:04:25 2001 GMT by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2001 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_settings.h"
+#include "kvi_heapobject.h"
+
+class KVILIB_API KviDataBuffer : public KviHeapObject
+{
+public:
+ // uSize MUST be greater than 0
+ // if data is non-zero, it MUST point to a buffer at least uSize bytes long
+ // and the data is COPIED from that buffer!
+ KviDataBuffer(int uSize,const unsigned char * data = 0);
+ KviDataBuffer();
+ ~KviDataBuffer();
+private:
+ int m_uSize;
+ unsigned char * m_pData;
+public:
+ int size() const { return m_uSize; };
+ unsigned char * data() const { return m_pData; };
+ // uSize MUST be smaller or equal to size()
+ // consumes data!
+ void remove(int uSize);
+ void clear(){ if(m_uSize > 0)remove(m_uSize); };
+ // uSize MUST be greater than 0
+ void resize(int uSize);
+ void addSize(int uSize){ resize(m_uSize + uSize); };
+ void append(const unsigned char * data,int uSize);
+ void append(const KviDataBuffer &b){ append(b.data(),b.size()); };
+ int find(unsigned char c);
+ int find(const unsigned char * block,int uSize);
+};
+
+#endif //_KVI_DATABUFFER_H_
diff --git a/src/kvilib/ext/kvi_dcophelper.cpp b/src/kvilib/ext/kvi_dcophelper.cpp
new file mode 100644
index 00000000..83f34f4e
--- /dev/null
+++ b/src/kvilib/ext/kvi_dcophelper.cpp
@@ -0,0 +1,357 @@
+//=============================================================================
+//
+// File : kvi_dcophelper.cpp
+// Created on Sat 20 Jan 2007 12:35:21 by Alexander Stillich
+//
+// This file is part of the KVIrc IRC client distribution
+// Copyright (C) 2005 Szymon Stefanek <pragma at kvirc dot net>
+// Copyright (C) 2007 Alexander Stillich <torque at pltn dot 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 opinion) 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.
+//
+//=============================================================================
+
+#define __KVILIB__
+#include "kvi_dcophelper.h"
+
+#ifdef COMPILE_KDE_SUPPORT
+
+#include "dcopclient.h"
+
+#include <qdatastream.h>
+#include <qvaluelist.h>
+
+// must be included this way, since kvilib is built
+// before kvirc and symlinks to headers aren't set yet
+#include "../../kvirc/kernel/kvi_app.h"
+#include "kvi_thread.h"
+
+KviDCOPHelper::KviDCOPHelper(bool bStartApp, const KviQCString &szAppId)
+{
+ m_szAppId = szAppId;
+}
+
+KviDCOPHelper::~KviDCOPHelper()
+{
+}
+
+bool KviDCOPHelper::ensureAppRunning(const QString &szApp)
+{
+ if (findRunningApp(m_szAppId))
+ return true;
+
+ if (m_bStartApp)
+ return startApp(m_szAppId,400);
+
+ return false;
+}
+
+
+bool KviDCOPHelper::voidRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc)
+{
+ if(!ensureAppRunning(m_szAppId))return false;
+ QByteArray data;
+ return g_pApp->dcopClient()->send(m_szAppId,szObj,szFunc,data);
+}
+
+bool KviDCOPHelper::voidRetBoolDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,bool bVal)
+{
+ if(!ensureAppRunning(m_szAppId))return false;
+ QByteArray data;
+ QDataStream arg(data, IO_WriteOnly);
+ arg << bVal;
+ return g_pApp->dcopClient()->send(m_szAppId,szObj,szFunc,data);
+}
+
+bool KviDCOPHelper::voidRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int iVal)
+{
+ if(!ensureAppRunning(m_szAppId))return false;
+ QByteArray data;
+ QDataStream arg(data, IO_WriteOnly);
+ arg << iVal;
+ return g_pApp->dcopClient()->send(m_szAppId,szObj,szFunc,data);
+}
+
+bool KviDCOPHelper::voidRetIntBoolDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int iVal, bool bVal)
+{
+ if(!ensureAppRunning(m_szAppId))return false;
+ QByteArray data;
+ QDataStream arg(data, IO_WriteOnly);
+ arg << iVal;
+ arg << bVal;
+ return g_pApp->dcopClient()->send(m_szAppId,szObj,szFunc,data);
+}
+
+bool KviDCOPHelper::voidRetIntIntIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int iVal1, int iVal2, int iVal3)
+{
+ if(!ensureAppRunning(m_szAppId))return false;
+ QByteArray data;
+ QDataStream arg(data, IO_WriteOnly);
+ arg << iVal1;
+ arg << iVal2;
+ arg << iVal3;
+ return g_pApp->dcopClient()->send(m_szAppId,szObj,szFunc,data);
+}
+
+bool KviDCOPHelper::voidRetFloatDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,float fVal)
+{
+ if(!ensureAppRunning(m_szAppId))return false;
+ QByteArray data;
+ QDataStream arg(data, IO_WriteOnly);
+ arg << fVal;
+ return g_pApp->dcopClient()->send(m_szAppId,szObj,szFunc,data);
+}
+
+bool KviDCOPHelper::voidRetStringDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,const QString &szVal)
+{
+ if(!ensureAppRunning(m_szAppId))return false;
+ QByteArray data;
+ QDataStream arg(data, IO_WriteOnly);
+ arg << szVal;
+ return g_pApp->dcopClient()->send(m_szAppId,szObj,szFunc,data);
+}
+
+bool KviDCOPHelper::stringRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,QString &szRet)
+{
+ if(!ensureAppRunning(m_szAppId))return false;
+ QByteArray data, replyData;
+ KviQCString replyType;
+ if(!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData))
+ return false;
+ QDataStream reply( replyData, IO_ReadOnly );
+ if(replyType == "QString")
+ {
+ reply >> szRet;
+ return true;
+ }
+ return false;
+}
+
+bool KviDCOPHelper::stringRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,QString &szRet,int iVal)
+{
+ if(!ensureAppRunning(m_szAppId))return false;
+ QByteArray data, replyData;
+ KviQCString replyType;
+
+ QDataStream arg(data, IO_WriteOnly);
+ arg << iVal;
+
+ if(!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData))
+ return false;
+
+ QDataStream reply( replyData, IO_ReadOnly );
+ if(replyType == "QString")
+ {
+ reply >> szRet;
+ return true;
+ }
+ return false;
+}
+
+bool KviDCOPHelper::intRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int &ret)
+{
+ if(!ensureAppRunning(m_szAppId))return false;
+ QByteArray data, replyData;
+ KviQCString replyType;
+ if(!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData))
+ return false;
+ QDataStream reply( replyData, IO_ReadOnly );
+ if(replyType == "int")
+ {
+ reply >> ret;
+ return true;
+ }
+ return false;
+}
+
+bool KviDCOPHelper::intRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int &ret, int iVal)
+{
+ if(!ensureAppRunning(m_szAppId))return false;
+ QByteArray data, replyData;
+ KviQCString replyType;
+
+ QDataStream arg(data, IO_WriteOnly);
+ arg << iVal;
+
+ if(!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData))
+ return false;
+
+ QDataStream reply( replyData, IO_ReadOnly );
+ if(replyType == "int")
+ {
+ reply >> ret;
+ return true;
+ }
+ return false;
+}
+
+bool KviDCOPHelper::boolRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,bool &ret)
+{
+ if(!ensureAppRunning(m_szAppId))return false;
+ QByteArray data, replyData;
+ KviQCString replyType;
+ if(!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData))
+ return false;
+ QDataStream reply( replyData, IO_ReadOnly );
+ if(replyType == "bool")
+ {
+ reply >> ret;
+ return true;
+ }
+ return false;
+}
+
+bool KviDCOPHelper::qvalueListIntRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,KviValueList<int> &ret, int iVal)
+{
+ if(!ensureAppRunning(m_szAppId))
+ return false;
+
+ QByteArray data, replyData;
+ KviQCString replyType;
+ QDataStream arg(data, IO_WriteOnly);
+
+ arg << iVal;
+
+
+ if(!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData))
+ return false;
+
+ if(replyType != "QValueList<int>")
+ return false;
+
+ QDataStream replyStream(replyData, IO_ReadOnly);
+ replyStream >> ret;
+
+ return true;
+}
+
+bool KviDCOPHelper::qcstringListRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,KviQCStringList &ret)
+{
+ QByteArray data, replyData;
+ KviQCString replyType;
+
+ if (!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData))
+ return false;
+
+ if (replyType != "KviQCStringList")
+ return false;
+
+ QDataStream replyStream(replyData, IO_ReadOnly);
+ replyStream >> ret;
+
+ return true;
+}
+
+bool KviDCOPHelper::qcstringListRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,KviQCStringList &ret, int iVal)
+{
+ QByteArray data, replyData;
+ KviQCString replyType;
+
+ QDataStream arg(data, IO_WriteOnly);
+ arg << iVal;
+
+ if (!g_pApp->dcopClient()->call(m_szAppId,szObj,szFunc,data,replyType,replyData))
+ return false;
+
+ if (replyType != "KviQCStringList")
+ return false;
+
+ QDataStream replyStream(replyData, IO_ReadOnly);
+ replyStream >> ret;
+
+ return true;
+}
+
+bool KviDCOPHelper::findRunningApp(const QString &szApp)
+{
+ QValueList<KviQCString> allApps = g_pApp->dcopClient() ->registeredApplications();
+ QValueList<KviQCString>::iterator iterator;
+ KviQCString sz = szApp.local8Bit();
+ for (iterator = allApps.begin();iterator != allApps.end();iterator++)
+ {
+ if(*iterator == sz)
+ return true;
+ }
+ return false;
+}
+
+int KviDCOPHelper::detectApp(const QString &szApp,bool bStart,int iScoreWhenFound,int iScoreWhenStarted)
+{
+ // dcop available
+ if(!g_pApp->dcopClient())
+ return 0;
+
+ if(findRunningApp(szApp))
+ return 95; // found a running app, no need to run further
+
+ // no app found running
+ if(bStart)
+ {
+ // try to start it
+ if(!startApp(szApp,5000))
+ return 10; // very low possibility
+ return findRunningApp(szApp) ? 99 : 0; // try to find it again
+ }
+
+ return 30; // it still might be installed on the system but we're just unable to start it...
+}
+
+
+bool KviDCOPHelper::startApp(const QString &szApp,int iWaitMSecs)
+{
+ // we could use KApplication::startServiceByDesktopName here
+ // but we want to be able to wait a defined amount of time
+ QStringList tmp;
+ QByteArray data, replyData;
+ KviQCString replyType;
+ QDataStream arg(data, IO_WriteOnly);
+ arg << szApp << tmp;
+ if(!g_pApp->dcopClient()->call(
+ "klauncher",
+ "klauncher",
+ "start_service_by_desktop_name(QString,QStringList)",
+ data,
+ replyType,
+ replyData))
+ {
+ return false;
+ } else {
+ QDataStream reply(replyData, IO_ReadOnly);
+ if(replyType != "serviceResult")return false;
+ int result;
+ KviQCString dcopName;
+ QString error;
+ reply >> result >> dcopName >> error;
+ if(result != 0)return false;
+ }
+ // ok , we seem to have started it.. but it might take some seconds
+ // for the app to get registered
+ // we wait up to five seconds
+ if(iWaitMSecs > 0)
+ {
+ int i = 0;
+ while(i < iWaitMSecs)
+ {
+ if(findRunningApp(szApp))return true;
+ KviThread::msleep(100);
+ i += 100;
+ }
+ return findRunningApp(szApp);
+ }
+ return true;
+}
+
+
+#endif //COMPILE_KDE_SUPPORT
diff --git a/src/kvilib/ext/kvi_dcophelper.h b/src/kvilib/ext/kvi_dcophelper.h
new file mode 100644
index 00000000..de605e37
--- /dev/null
+++ b/src/kvilib/ext/kvi_dcophelper.h
@@ -0,0 +1,82 @@
+#ifndef _KVI_DCOPHELPER_H_
+#define _KVI_DCOPHELPER_H_
+//=============================================================================
+//
+// File : kvi_dcophelper.h
+// Created on Sat 20 Jan 2007 12:35:21 by Alexander Stillich
+//
+// This file is part of the KVIrc IRC client distribution
+// Copyright (C) 2005 Szymon Stefanek <pragma at kvirc dot net>
+// Copyright (C) 2007 Alexander Stillich <torque at pltn dot 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 opinion) 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 "kvi_settings.h"
+#include "kvi_qstring.h"
+#include "kvi_qcstring.h"
+#include "kvi_valuelist.h"
+
+#ifdef COMPILE_KDE_SUPPORT
+
+typedef KviValueList<KviQCString> KviQCStringList;
+
+class KVILIB_API KviDCOPHelper
+{
+
+public:
+
+ // Constructs a DCOP helper object.
+ // bStartApp: tries to start application when a dcop call is about to be made and the app is not already running
+ // szAppID: application name as seen by DCOP
+ KviDCOPHelper(bool bStartApp, const KviQCString &szAppId);
+ ~KviDCOPHelper();
+
+protected:
+
+ KviQCString m_szAppId;
+ bool m_bStartApp;
+
+protected:
+
+ bool ensureAppRunning(const QString &szApp);
+ bool findRunningApp(const QString &szApp);
+ bool startApp(const QString &szApp,int iWaitMSecs = 0);
+ int detectApp(const QString &szApp,bool bStart,int iScoreWhenFound,int iScoreWhenStarted);
+
+ // naming convention: [return value] Ret [argument type(s)] DCOPCall
+
+ bool voidRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc);
+ bool voidRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int iVal);
+ bool voidRetIntBoolDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int iVal, bool bVal);
+ bool voidRetIntIntIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int iVal1, int iVal2, int iVal3);
+ bool voidRetBoolDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,bool bVal);
+ bool voidRetStringDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,const QString &szVal);
+ bool voidRetFloatDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,float fVal);
+ bool stringRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,QString &szRet);
+ bool stringRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,QString &szRet,int iVal);
+ bool intRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int &ret);
+ bool intRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,int &ret, int iVal);
+ bool boolRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,bool &ret);
+
+ bool qvalueListIntRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,KviValueList<int> &ret, int iVal);
+ bool qcstringListRetIntDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,KviQCStringList &ret, int iVal);
+ bool qcstringListRetVoidDCOPCall(const KviQCString &szObj,const KviQCString &szFunc,KviQCStringList &ret);
+};
+
+#endif //COMPILE_KDE_SUPPORT
+
+#endif // _KVI_DCOPHELPER_H_
diff --git a/src/kvilib/ext/kvi_doublebuffer.cpp b/src/kvilib/ext/kvi_doublebuffer.cpp
new file mode 100644
index 00000000..5997e934
--- /dev/null
+++ b/src/kvilib/ext/kvi_doublebuffer.cpp
@@ -0,0 +1,90 @@
+//=============================================================================
+//
+// File : kvi_doublebuffer.cpp
+// Created on Fri 27 Jan 2006 18:59:54 by Szymon Stefanek
+//
+// This file is part of the KVIrc IRC Client distribution
+// Copyright (C) 2006 Szymon Stefanek <pragma at kvirc dot net>
+//
+// 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 opinion) 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.
+//
+//=============================================================================
+
+#define __KVILIB__
+
+#include "kvi_doublebuffer.h"
+
+static QPixmap * g_pMemoryPixmap = 0;
+static unsigned int g_uMaxRequestedWidth = 0;
+static unsigned int g_uMaxRequestedHeight = 0;
+
+KviDoubleBuffer::KviDoubleBuffer(unsigned int uWidth,unsigned int uHeight)
+{
+ if((g_pMemoryPixmap->width() < uWidth) || (g_pMemoryPixmap->height() < uHeight))
+ {
+ // The memory buffer is too small
+ // There is either no such user requirement or it has grown by the meantime
+ unsigned int uMaxW = uWidth > g_pMemoryPixmap->width() ? uWidth : g_pMemoryPixmap->width();
+ unsigned int uMaxH = uHeight > g_pMemoryPixmap->height() ? uHeight : g_pMemoryPixmap->height();
+#ifdef COMPILE_USE_QT4
+ // QT4SUX: QPixmap::resize() is missing (it's a widely used function and assigning a new QPixmap() seems to be slower and not intuitive)
+ *g_pMemoryPixmap = QPixmap(uMaxW,uMaxH);
+#else
+ g_pMemoryPixmap->resize(uMaxW,uMaxH);
+#endif
+ }
+
+ if(uWidth > g_uMaxRequestedWidth)g_uMaxRequestedWidth = uWidth;
+ if(uHeight > g_uMaxRequestedHeight)g_uMaxRequestedHeight = uHeight;
+}
+
+KviDoubleBuffer::~KviDoubleBuffer()
+{
+ // We never shrink here (it's time consuming)
+}
+
+QPixmap * KviDoubleBuffer::pixmap()
+{
+ return g_pMemoryPixmap;
+}
+
+void KviDoubleBuffer::init()
+{
+ if(g_pMemoryPixmap)return;
+ g_pMemoryPixmap = new QPixmap();
+}
+
+void KviDoubleBuffer::done()
+{
+ if(!g_pMemoryPixmap)return;
+ delete g_pMemoryPixmap;
+ g_pMemoryPixmap = 0;
+}
+
+void KviDoubleBuffer::heartbeat()
+{
+ if(((g_uMaxRequestedHeight + 64) < g_pMemoryPixmap->height()) || ((g_uMaxRequestedWidth + 64) < g_pMemoryPixmap->width()))
+ {
+ // do shrink :)
+#ifdef COMPILE_USE_QT4
+ // QT4SUX: QPixmap::resize() is missing (it's a widely used function and assigning a new QPixmap() seems to be slower and not intuitive)
+ *g_pMemoryPixmap = QPixmap(g_uMaxRequestedWidth,g_uMaxRequestedHeight);
+#else
+ g_pMemoryPixmap->resize(g_uMaxRequestedWidth,g_uMaxRequestedHeight);
+#endif
+ }
+ g_uMaxRequestedHeight = 0;
+ g_uMaxRequestedWidth = 0;
+}
diff --git a/src/kvilib/ext/kvi_doublebuffer.h b/src/kvilib/ext/kvi_doublebuffer.h
new file mode 100644
index 00000000..103759a1
--- /dev/null
+++ b/src/kvilib/ext/kvi_doublebuffer.h
@@ -0,0 +1,62 @@
+#ifndef _KVI_DOUBLEBUFFER_H_
+#define _KVI_DOUBLEBUFFER_H_
+//=============================================================================
+//
+// File : kvi_doublebuffer.h
+// Created on Fri 27 Jan 2006 18:59:54 by Szymon Stefanek
+//
+// This file is part of the KVIrc IRC Client distribution
+// Copyright (C) 2006 Szymon Stefanek <pragma at kvirc dot net>
+//
+// 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 opinion) 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 "kvi_settings.h"
+
+#include <qpixmap.h>
+
+//
+// This class is basically a huge shared memory pixmap meant to be used in double-buffer
+// painting operations. The memory buffer is resized on the fly so you will always obtain
+// a pixmap that is at least of the specified size. The problem is that this is a time
+// consuming operation (not good in a paint event). We solve it by keeping the buffer
+// with the greatest requested size in the last N minutes.
+//
+// The keyword in all this thingie is "memory is cheap, processing time is not".
+// We know in advance that KVIrc needs a huge double buffer anyway...
+// So we basically grow instantly but we are really lazy at shrinking.
+//
+
+class KVILIB_API KviDoubleBuffer
+{
+public:
+ KviDoubleBuffer(unsigned int uWidth,unsigned int uHeight);
+ ~KviDoubleBuffer();
+public:
+ // This returns a pointer to the memory buffer. The buffer is at least
+ // of the size declared in the constructor.
+ QPixmap * pixmap();
+
+ // The stuff below is internal (used only by KviApp)
+
+ // to be called at application initialisation and cleanup
+ static void init();
+ static void done();
+ // this has to be called at sensible intervals (like 2 minutes)
+ static void heartbeat();
+};
+
+#endif //!_KVI_DOUBLEBUFFER_H_
diff --git a/src/kvilib/ext/kvi_draganddrop.h b/src/kvilib/ext/kvi_draganddrop.h
new file mode 100644
index 00000000..c8bd9f3e
--- /dev/null
+++ b/src/kvilib/ext/kvi_draganddrop.h
@@ -0,0 +1,45 @@
+#ifndef _KVI_DRAGANDDROP_H_
+#define _KVI_DRAGANDDROP_H_
+
+//=============================================================================
+//
+// File : kvi_draganddrop.h
+// Creation date : Wed Feb 01 2007 01:45:21 CEST by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2007 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_settings.h"
+
+
+#ifdef COMPILE_USE_QT4
+ #include <q3dragobject.h>
+ #define KviDragObject Q3DragObject
+ #define KviUriDrag Q3UriDrag
+ #define KviTextDrag Q3TextDrag
+ #define KviImageDrag Q3ImageDrag
+#else
+ #include <qdragobject.h>
+ #define KviDragObject QDragObject
+ #define KviUriDrag QUriDrag
+ #define KviTextDrag QTextDrag
+ #define KviImageDrag QImageDrag
+#endif
+
+#endif //!_KVI_DRAGANDDROP_H_
diff --git a/src/kvilib/ext/kvi_garbage.cpp b/src/kvilib/ext/kvi_garbage.cpp
new file mode 100644
index 00000000..0e2e8881
--- /dev/null
+++ b/src/kvilib/ext/kvi_garbage.cpp
@@ -0,0 +1,148 @@
+//
+// File : kvi_garbage.cpp
+// Creation date : Mon Dec 3 16:49:15 2001 GMT by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2001 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+#define __KVILIB__
+
+
+
+#include "kvi_garbage.h"
+
+#include <qvariant.h>
+
+KviGarbageCollector::KviGarbageCollector()
+: QObject(0)
+{
+ m_pGarbageList = 0;
+ m_pCleanupTimer = 0;
+ m_bForceCleanupNow = false;
+}
+
+KviGarbageCollector::~KviGarbageCollector()
+{
+ m_bForceCleanupNow = true;
+ cleanup();
+}
+
+void KviGarbageCollector::collect(QObject * g)
+{
+ if(!m_pGarbageList)
+ {
+ m_pGarbageList = new KviPointerList<QObject>;
+ m_pGarbageList->setAutoDelete(true);
+ }
+ //debug("COLLECTING GARBAGE %s",g->className());
+ m_pGarbageList->append(g);
+// debug("Registering garbage object %d (%s:%s)",g,g->className(),g->name());
+ connect(g,SIGNAL(destroyed()),this,SLOT(garbageSuicide()));
+ triggerCleanup(0);
+}
+
+void KviGarbageCollector::garbageSuicide()
+{
+ if(!m_pGarbageList)
+ {
+ debug("Ops... garbage suicide while no garbage list");
+ return;
+ }
+ int idx = m_pGarbageList->findRef(sender());
+ if(idx == -1)
+ {
+ debug("Ops... unregistered garbage suicide");
+ return;
+ }
+ m_pGarbageList->removeRef(sender());
+ if(m_pGarbageList->isEmpty())
+ {
+ cleanup();
+ }
+}
+
+void KviGarbageCollector::triggerCleanup(int iTimeout)
+{
+ //debug("TRIGGERING CLEANUP AFTER %d msecs",iTimeout);
+ if(m_pCleanupTimer)
+ {
+ m_pCleanupTimer->stop();
+ } else {
+ m_pCleanupTimer = new QTimer(this);
+ connect(m_pCleanupTimer,SIGNAL(timeout()),this,SLOT(cleanup()));
+ }
+ m_pCleanupTimer->start(iTimeout);
+}
+
+void KviGarbageCollector::cleanup()
+{
+ //debug("CLEANUP CALLED !");
+ if(m_pGarbageList)
+ {
+ //debug("SOME GARBAGE TO DELETE");
+ KviPointerList<QObject> dying;
+ dying.setAutoDelete(false);
+ for(QObject * o = m_pGarbageList->first();o;o = m_pGarbageList->next())
+ {
+ //debug("CHECKING GARBAGE CLASS %s",o->className());
+ bool bDeleteIt = m_bForceCleanupNow;
+ if(!bDeleteIt)
+ {
+ //debug("CLEANUP NOT FORCED");
+ QVariant v = o->property("blockingDelete");
+ if(v.isValid())
+ {
+ //debug("HAS A VALID VARIANT!");
+// debug("[Garbage collector]: garbage has a blockingDelete property");
+ bDeleteIt = !(v.toBool());
+// if(!bDeleteIt)debug("And doesn't want to be delete now!");
+ } else bDeleteIt = true; // must be deleted
+ }
+ if(bDeleteIt)dying.append(o);
+ }
+
+ for(QObject * o2 = dying.first();o2;o2 = dying.next())
+ {
+ //debug("KILLING GARBAGE CLASS %s",o2->className());
+ disconnect(o2,SIGNAL(destroyed()),this,SLOT(garbageSuicide()));
+ m_pGarbageList->removeRef(o2);
+ }
+
+ if(m_pGarbageList->isEmpty())
+ {
+ delete m_pGarbageList;
+ m_pGarbageList = 0;
+ }
+ }
+
+ if(m_pGarbageList)
+ {
+// debug("[Garbage collector cleanup]: Some stuff left to be deleted, will retry in a while");
+ // something left to be destroyed
+ if(m_bForceCleanupNow)debug("[Garbage collector]: Ops...I've left some undeleted stuff!");
+ triggerCleanup(5000); // retry in 5 sec
+ } else {
+// debug("[Garbage collector cleanup]: Completed");
+ // nothing left to delete
+ if(m_pCleanupTimer)
+ {
+ delete m_pCleanupTimer;
+ m_pCleanupTimer = 0;
+ }
+ }
+}
+
diff --git a/src/kvilib/ext/kvi_garbage.h b/src/kvilib/ext/kvi_garbage.h
new file mode 100644
index 00000000..6bb75641
--- /dev/null
+++ b/src/kvilib/ext/kvi_garbage.h
@@ -0,0 +1,51 @@
+#ifndef _KVI_GARBAGE_H_
+#define _KVI_GARBAGE_H_
+//
+// File : kvi_garbage.h
+// Creation date : Mon Dec 3 16:49:13 2001 GMT by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2001 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_settings.h"
+
+#include <qobject.h>
+#include "kvi_pointerlist.h"
+#include <qtimer.h>
+
+
+class KVILIB_API KviGarbageCollector : public QObject
+{
+ Q_OBJECT
+public:
+ KviGarbageCollector();
+ ~KviGarbageCollector();
+protected:
+ KviPointerList<QObject> * m_pGarbageList;
+ QTimer * m_pCleanupTimer;
+ bool m_bForceCleanupNow;
+public:
+ void collect(QObject * g);
+protected:
+ void triggerCleanup(int iTimeout);
+protected slots:
+ void cleanup();
+ void garbageSuicide();
+};
+
+#endif //_KVI_GARBAGE_H_
diff --git a/src/kvilib/ext/kvi_imagelib.cpp b/src/kvilib/ext/kvi_imagelib.cpp
new file mode 100644
index 00000000..10835b25
--- /dev/null
+++ b/src/kvilib/ext/kvi_imagelib.cpp
@@ -0,0 +1,138 @@
+//=============================================================================
+//
+// File : kvi_imagelib.cpp
+// Creation date : Wed Jul 21 1999 16:41:26 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+//=============================================================================
+
+#define __KVILIB__
+
+#include <qnamespace.h>
+
+#include "kvi_imagelib.h"
+#include "kvi_fileutils.h"
+#include "kvi_locale.h"
+#include "kvi_memmove.h"
+
+#include <qpixmap.h>
+
+
+//KviImageLibrary::KviImageLibrary(const QPixmap &pixmap,int imageWidth,int imageHeight)
+//{
+// if(pixmap.isNull())m_pLibrary=0;
+// else m_pLibrary=new QPixmap(pixmap);
+// setImageSize(imageWidth,imageHeight);
+//}
+
+KviImageLibrary::KviImageLibrary(const QString &path,int imageWidth,int imageHeight)
+{
+ m_pLibrary=0;
+ loadLibrary(path);
+ setImageSize(imageWidth,imageHeight);
+}
+
+KviImageLibrary::KviImageLibrary(const QString &path1,const QString &path2,int imageWidth,int imageHeight)
+{
+ m_pLibrary=0;
+ if(KviFileUtils::fileExists(path1))
+ {
+ loadLibrary(path1);
+ if(m_pLibrary==0)loadLibrary(path2);
+ } else loadLibrary(path2);
+ setImageSize(imageWidth,imageHeight);
+}
+
+
+KviImageLibrary::~KviImageLibrary()
+{
+ unloadLibrary();
+}
+
+void KviImageLibrary::unloadLibrary()
+{
+ if(m_pLibrary)delete m_pLibrary;
+ m_pLibrary=0;
+}
+
+bool KviImageLibrary::setImageSize(int imageWidth,int imageHeight)
+{
+ m_iWidth=((imageWidth>0) ? imageWidth : 16);
+ m_iHeight=((imageHeight>0) ? imageHeight : 16);
+ return true;
+}
+
+bool KviImageLibrary::loadLibrary(const QString &path)
+{
+ if(m_pLibrary)delete m_pLibrary;
+ m_pLibrary=new QImage(path);
+ if(m_pLibrary->isNull())
+ {
+ delete m_pLibrary;
+ m_pLibrary=0;
+ debug("WARNING : Can not load image library %s",KviQString::toUtf8(path).data());
+ }
+ return (m_pLibrary != 0);
+}
+
+int KviImageLibrary::imageCount()
+{
+ if(!m_pLibrary)return 0;
+ if((m_iWidth<1)||(m_iHeight<1))return 0;
+ int nRows=m_pLibrary->width()/m_iWidth;
+ return ( nRows * (m_pLibrary->height()/m_iHeight));
+}
+
+QPixmap KviImageLibrary::getImage(int zeroBasedIndex)
+{
+ if((zeroBasedIndex >= imageCount())||(zeroBasedIndex < 0)||(m_pLibrary->depth() < 8))
+ {
+ QPixmap image(32,32);
+ image.fill(); //White fill
+ return image;
+ }
+
+ // Im per row is not zero...because imageCount returned non zero.
+ int imPerRow=(m_pLibrary->width() / m_iWidth);
+ int xOffset=(zeroBasedIndex % imPerRow) * m_iWidth;
+ int yOffset=(zeroBasedIndex / imPerRow) * m_iHeight;
+
+#ifdef COMPILE_USE_QT4
+ QImage image(m_iWidth,m_iHeight,m_pLibrary->format());
+#else
+ QImage image(m_iWidth,m_iHeight,m_pLibrary->depth());
+#endif
+
+ int d = image.depth() / 8;
+#ifndef COMPILE_USE_QT4
+ if(d == 4)image.setAlphaBuffer(true); // Qt 4.x should manage it automagically
+#endif
+ //Copy the image data
+ //bitBlt(&image,0,0,m_pLibrary,xOffset,yOffset,m_iWidth,m_iHeight,Qt::CopyROP,false);
+
+ for(int i=0;i<m_iHeight;i++)
+ kvi_memmove(image.scanLine(i),m_pLibrary->scanLine(i + yOffset) + (xOffset * d),m_iWidth * d);
+
+#ifdef COMPILE_USE_QT4
+ QPixmap p = QPixmap::fromImage(image);
+#else
+ QPixmap p(image);
+#endif
+ return p;
+}
diff --git a/src/kvilib/ext/kvi_imagelib.h b/src/kvilib/ext/kvi_imagelib.h
new file mode 100644
index 00000000..d78c8d19
--- /dev/null
+++ b/src/kvilib/ext/kvi_imagelib.h
@@ -0,0 +1,73 @@
+#ifndef _KVI_IMAGELIB_H_
+#define _KVI_IMAGELIB_H_
+
+//
+// File : kvi_imagelib.h
+// Creation date : Wed Jul 21 1999 16:41:26 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+
+//
+// A class to manage multiple image libraries.
+// The library is in fact a big image that contains
+// several rows of other smaller images of the same size.
+// The images inside the 'library' are indexed in the following way:
+//
+// -------------
+// |...|...|...|
+// |.0.|.1.|.2.|
+// -------------
+// |...|...|...|
+// |.3.|.4.|.5.|
+// -------------
+// |...|...|...|
+//
+// The 'library' image should have the size that is a multiple
+// of the single image size. If not , the remaining part is ignored.
+// The first image starts always in the left upper corner.
+//
+
+// WARNING: This class will be removed in the near future. Don't use it.
+
+#include "kvi_settings.h"
+
+#include <qimage.h>
+
+class KVILIB_API KviImageLibrary
+{
+public: // Consruction & Destruction
+// KviImageLibrary(const QPixmap &pixmap,int imageWidth,int imageHeight);
+ KviImageLibrary(const QString &path,int imageWidth,int imageHeight);
+ KviImageLibrary(const QString &path1,const QString &path2,int imageWidth,int imageHeight);
+ ~KviImageLibrary();
+public: // Fields
+ QImage *m_pLibrary;
+ int m_iWidth;
+ int m_iHeight;
+public: // Methods
+ bool loadLibrary(const QString &path);
+ void unloadLibrary();
+ int imageCount();
+ bool libraryLoaded(){ return (m_pLibrary != 0); };
+ QImage *getLibrary(){ return m_pLibrary; };
+ QPixmap getImage(int zeroBasedIndex);
+ bool setImageSize(int imageWidth,int imageHeight);
+};
+
+#endif //_KVI_IMAGELIB_H_INCLUDED_
diff --git a/src/kvilib/ext/kvi_md5.cpp b/src/kvilib/ext/kvi_md5.cpp
new file mode 100644
index 00000000..cbf01500
--- /dev/null
+++ b/src/kvilib/ext/kvi_md5.cpp
@@ -0,0 +1,298 @@
+//
+// File : kvi_md5.cpp
+// Creation date : Wed Sep 4 22:16:45 2002 GMT by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2002 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+
+#define __KVILIB__
+
+
+
+/*
+ ######################################################################
+
+ MD5Sum - MD5 Message Digest Algorithm.
+
+ This code implements the MD5 message-digest algorithm. The algorithm is
+ due to Ron Rivest. This code was written by Colin Plumb in 1993, no
+ copyright is claimed. This code is in the public domain; do with it what
+ you wish.
+
+ Equivalent code is available from RSA Data Security, Inc. This code has
+ been tested against that, and is equivalent, except that you don't need to
+ include two pages of legalese with every copy.
+
+ To compute the message digest of a chunk of bytes, instantiate the class,
+ and repeatedly call one of the Add() members. When finished the Result
+ method will return the Hash and finalize the value.
+
+ Changed so as no longer to depend on Colin Plumb's `usual.h' header
+ definitions; now uses stuff from dpkg's config.h.
+ - Ian Jackson <ijackson@nyx.cs.du.edu>.
+
+ Changed into a C++ interface and made work with APT's config.h.
+ - Jason Gunthorpe <jgg@gpu.srv.ualberta.ca>
+
+ Interface adapted to the KVIrc irc client
+ - Szymon Stefanek <pragma at kvirc dot net>
+
+ The classes use arrays of char that are a specific size. We cast those
+ arrays to uint8_t's and go from there. This allows us to advoid using
+ the uncommon inttypes.h in a public header or internally newing memory.
+ In theory if C9x becomes nicely accepted
+
+ ##################################################################### */
+
+#include "kvi_md5.h"
+#include "kvi_settings.h"
+#include "kvi_bswap.h"
+#include "kvi_memmove.h"
+
+/* Swap n 32 bit longs in given buffer */
+#ifdef BIG_ENDIAN_MACHINE_BYTE_ORDER
+ static void byteSwap(kvi_u32_t *buf,unsigned int words)
+ {
+// kvi_u8_t *p = (kvi_u8_t *)buf;
+// do
+// {
+// *buf++ = (kvi_u32_t)((unsigned)p[3] << 8 | p[2]) << 16 | ((unsigned)p[1] << 8 | p[0]);
+// p += 4;
+// } while (--words);
+ do {
+ *buf = kvi_swap32(*buf);
+ buf++;
+ } while(--words);
+ }
+#else
+ #define byteSwap(buf,words)
+#endif
+
+/* The core of the MD5 algorithm, this alters an existing MD5 hash to
+ reflect the addition of 16 longwords of new data. Add blocks
+ the data and converts bytes into longwords for this routine. */
+
+// The four core functions - F1 is optimized somewhat
+// #define F1(x, y, z) (x & y | ~x & z)
+#define F1(x, y, z) (z ^ (x & (y ^ z)))
+#define F2(x, y, z) F1(z, x, y)
+#define F3(x, y, z) (x ^ y ^ z)
+#define F4(x, y, z) (y ^ (x | ~z))
+
+// This is the central step in the MD5 algorithm.
+#define MD5STEP(f,w,x,y,z,in,s) \
+ (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
+
+static void MD5Transform(kvi_u32_t buf[4],const kvi_u32_t in[16])
+{
+ register kvi_u32_t a, b, c, d;
+
+ a = buf[0];
+ b = buf[1];
+ c = buf[2];
+ d = buf[3];
+
+ MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
+ MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
+ MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
+ MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
+ MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
+ MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
+ MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
+ MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
+ MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
+ MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
+ MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
+ MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
+ MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
+ MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
+ MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
+ MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
+
+ MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
+ MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
+ MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
+ MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
+ MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
+ MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
+ MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
+ MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
+ MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
+ MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
+ MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
+ MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
+ MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
+ MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
+ MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
+ MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
+
+ MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
+ MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
+ MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
+ MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
+ MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
+ MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
+ MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
+ MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
+ MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
+ MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
+ MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
+ MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
+ MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
+ MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
+ MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
+ MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
+
+ MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
+ MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
+ MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
+ MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
+ MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
+ MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
+ MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
+ MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
+ MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
+ MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
+ MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
+ MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
+ MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
+ MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
+ MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
+ MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
+
+ buf[0] += a;
+ buf[1] += b;
+ buf[2] += c;
+ buf[3] += d;
+}
+
+KviMd5::KviMd5()
+{
+ kvi_u32_t *buf = (kvi_u32_t *)m_pBuf;
+ kvi_u32_t *bytes = (kvi_u32_t *)m_pBytes;
+
+ buf[0] = 0x67452301;
+ buf[1] = 0xefcdab89;
+ buf[2] = 0x98badcfe;
+ buf[3] = 0x10325476;
+
+ bytes[0] = 0;
+ bytes[1] = 0;
+
+ m_bDone = false;
+}
+
+KviMd5::~KviMd5()
+{
+}
+
+bool KviMd5::add(const unsigned char *data,unsigned long len)
+{
+ if(m_bDone)return false;
+
+ kvi_u32_t *buf = (kvi_u32_t *)m_pBuf;
+ kvi_u32_t *bytes = (kvi_u32_t *)m_pBytes;
+ kvi_u32_t *in = (kvi_u32_t *)m_pIn;
+
+ // Update byte count and carry (this could be done with a long long?)
+ kvi_u32_t t = bytes[0];
+
+ if ((bytes[0] = t + len) < t)bytes[1]++;
+
+ // Space available (at least 1)
+ t = 64 - (t & 0x3f);
+ if (t > len)
+ {
+ kvi_fastmove((unsigned char *)in + 64 - t,data,len);
+ return true;
+ }
+
+ // First chunk is an odd size
+ kvi_fastmove((unsigned char *)in + 64 - t,data,t);
+ byteSwap(in, 16);
+
+ MD5Transform(buf,in);
+ data += t;
+ len -= t;
+
+ // Process data in 64-byte chunks
+ while (len >= 64)
+ {
+ kvi_fastmove(in,data,64);
+ byteSwap(in,16);
+ MD5Transform(buf,in);
+ data += 64;
+ len -= 64;
+ }
+
+ // Handle any remaining bytes of data.
+ kvi_memmove(in,data,len);
+
+ return true;
+}
+
+
+// ---------------------------------------------------------------------
+/* Because this must add in the last bytes of the series it prevents anyone
+ from calling add after. */
+
+KviStr KviMd5::result()
+{
+ kvi_u32_t *buf = (kvi_u32_t *)m_pBuf;
+ kvi_u32_t *bytes = (kvi_u32_t *)m_pBytes;
+ kvi_u32_t *in = (kvi_u32_t *)m_pIn;
+
+ if(!m_bDone)
+ {
+ // Number of bytes in In
+ int count = bytes[0] & 0x3f;
+ unsigned char *p = (unsigned char *)in + count;
+
+ // Set the first char of padding to 0x80. There is always room.
+ *p++ = 0x80;
+
+ // Bytes of padding needed to make 56 bytes (-8..55)
+ count = 56 - 1 - count;
+
+ // Padding forces an extra block
+ if (count < 0)
+ {
+ kvi_memset(p,0,count + 8);
+ byteSwap(in, 16);
+ MD5Transform(buf,in);
+ p = (unsigned char *)in;
+ count = 56;
+ }
+
+ kvi_memset(p, 0, count);
+ byteSwap(in, 14);
+
+ // Append length in bits and transform
+ in[14] = bytes[0] << 3;
+ in[15] = bytes[1] << 3 | bytes[0] >> 29;
+ MD5Transform(buf,in);
+ byteSwap(buf,4);
+ m_bDone = true;
+ }
+
+ // m_pBuf now contains the md5 sum
+ KviStr ret;
+ ret.bufferToHex((char *)m_pBuf,16);
+
+ return ret;
+}
diff --git a/src/kvilib/ext/kvi_md5.h b/src/kvilib/ext/kvi_md5.h
new file mode 100644
index 00000000..113c3a7c
--- /dev/null
+++ b/src/kvilib/ext/kvi_md5.h
@@ -0,0 +1,68 @@
+#ifndef _KVI_MD5_H_
+#define _KVI_MD5_H_
+//
+// File : kvi_md5.h
+// Creation date : Wed Sep 4 22:16:44 2002 GMT by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2002 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+
+
+
+/* ######################################################################
+
+ MD5SumValue - Storage for a MD5Sum
+ MD5Summation - MD5 Message Digest Algorithm.
+
+ This is a C++ interface to a set of MD5Sum functions. The class can
+ store a MD5Sum in 16 bytes of memory.
+
+ A MD5Sum is used to generate a (hopefully) unique 16 byte number for a
+ block of data. This can be used to gaurd against corruption of a file.
+ MD5 should not be used for tamper protection, use SHA or something more
+ secure.
+
+ There are two classes because computing a MD5 is not a continual
+ operation unless 64 byte blocks are used. Also the summation requires an
+ extra 18*4 bytes to operate.
+
+ ##################################################################### */
+
+#include "kvi_settings.h"
+#include "kvi_inttypes.h"
+#include "kvi_string.h"
+
+class KviMd5
+{
+public:
+ KviMd5();
+ ~KviMd5();
+protected:
+ unsigned char m_pBuf[4*4];
+ unsigned char m_pBytes[2*4];
+ unsigned char m_pIn[16*4];
+ bool m_bDone;
+
+public:
+ bool add(const unsigned char *Data,unsigned long Size);
+
+ KviStr result();
+};
+
+
+#endif //_KVI_MD5_H_
diff --git a/src/kvilib/ext/kvi_mediatype.cpp b/src/kvilib/ext/kvi_mediatype.cpp
new file mode 100644
index 00000000..87c7926d
--- /dev/null
+++ b/src/kvilib/ext/kvi_mediatype.cpp
@@ -0,0 +1,541 @@
+//
+// File : kvi_mediatype.cpp
+// Creation date : Mon Aug 21 2000 17:51:56 CEST by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2000-2001 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+
+#define __KVILIB__
+
+
+//#define _KVI_DEBUG_CHECK_RANGE_
+
+
+
+#include "kvi_debug.h"
+#include "kvi_mediatype.h"
+#include "kvi_config.h"
+#include "kvi_fileutils.h"
+#include "kvi_locale.h"
+#include "kvi_file.h"
+
+#include "kvi_settings.h"
+
+#include <qregexp.h>
+#include <qdir.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+
+#ifndef COMPILE_ON_WINDOWS
+ #include <unistd.h>
+ #include "kvi_malloc.h"
+#endif
+
+
+
+#ifndef S_ISDIR
+#define S_ISDIR(__f) (__f & _S_IFDIR)
+#endif
+
+#ifndef S_ISFIFO
+#define S_ISFIFO(__f) (__f & _S_IFIFO)
+#endif
+
+#ifndef S_ISREG
+#define S_ISREG(__f) (__f & _S_IFREG)
+#endif
+
+#ifndef S_ISCHR
+#define S_ISCHR(__f) (__f & _S_IFCHR)
+#endif
+
+#ifndef COMPILE_ON_WINDOWS
+ #include <dirent.h>
+#else
+ #include "kvi_malloc.h"
+#endif
+
+
+
+
+KviMediaManager::KviMediaManager()
+: KviMutex()
+{
+ m_pMediaTypeList = new KviPointerList<KviMediaType>;
+ m_pMediaTypeList->setAutoDelete(true);
+}
+
+KviMediaManager::~KviMediaManager()
+{
+ delete m_pMediaTypeList;
+}
+
+KviMediaType * KviMediaManager::findMediaTypeByIanaType(const char * ianaType)
+{
+ __range_valid(locked());
+ for(KviMediaType * mt = m_pMediaTypeList->first();mt;mt = m_pMediaTypeList->next())
+ {
+ if(kvi_strEqualCI(mt->szIanaType.ptr(),ianaType))return mt;
+ }
+
+ return 0;
+}
+
+KviMediaType * KviMediaManager::findMediaTypeByFileMask(const char * filemask)
+{
+ __range_valid(locked());
+ for(KviMediaType * mt = m_pMediaTypeList->first();mt;mt = m_pMediaTypeList->next())
+ {
+// FIXME: #warning "Should this be case sensitive ?"
+ if(kvi_strEqualCI(mt->szFileMask.ptr(),filemask))return mt;
+ }
+
+ return 0;
+}
+
+void KviMediaManager::copyMediaType(KviMediaType * dst,KviMediaType * src)
+{
+ dst->szFileMask = src->szFileMask;
+ dst->szMagicBytes = src->szMagicBytes;
+ dst->szIanaType = src->szIanaType;
+ dst->szDescription = src->szDescription;
+ dst->szSavePath = src->szSavePath;
+ dst->szCommandline = src->szCommandline;
+ dst->szRemoteExecCommandline = src->szRemoteExecCommandline;
+ dst->szIcon = src->szIcon;
+}
+
+
+void KviMediaManager::insertMediaType(KviMediaType * m)
+{
+ __range_valid(locked());
+ int iWildCount = m->szFileMask.occurences('*');
+ int iNonWildCount = m->szFileMask.len() - iWildCount;
+
+ // The masks with no wildcards go first in the list
+ // then we insert the ones with more non-wild chars
+
+ int index = 0;
+ for(KviMediaType * mt = m_pMediaTypeList->first();mt;mt = m_pMediaTypeList->next())
+ {
+ if(iWildCount)
+ {
+ // the new mask has wildcards... if the current one has none, skip it
+ int iWildCountExisting = mt->szFileMask.occurences('*');
+ if(iWildCountExisting)
+ {
+ // the one in the list has wildcards too...
+ // the ones with more non-wild chars go first...
+ int iNonWildCountExisting = mt->szFileMask.len() - iWildCountExisting;
+ if(iNonWildCountExisting < iNonWildCount)
+ {
+ // ok...the new one has more non-wildcards , insert
+ m_pMediaTypeList->insert(index,m);
+ return;
+ } else {
+ if(iNonWildCount == iNonWildCountExisting)
+ {
+ // the same number of non-wildcards
+ // let the number of wildcards decide (it will be eventually equal)
+ if(iWildCount < iWildCountExisting)
+ {
+ // the new one has less wildcards... goes first
+ m_pMediaTypeList->insert(index,m);
+ return;
+ } // else the same number of wildcards and non-wildcards...skip
+ } // else the existing one has more non-wildcards...skip
+ }
+ } // else the current has no wildcards...skip
+ } else {
+ // the new mask has no wildcards....
+ if(mt->szFileMask.contains('*'))
+ {
+ // current one has wildcards...insert
+ m_pMediaTypeList->insert(index,m);
+ return;
+ }
+ // the current one has no wildcards...
+ // the longer masks go first....
+ if(mt->szFileMask.len() < m->szFileMask.len())
+ {
+ // the current one is shorter than the new one...insert
+ m_pMediaTypeList->insert(index,m);
+ return;
+ } // else current one is longer...skip
+ }
+ index++;
+ }
+ m_pMediaTypeList->append(m);
+
+/*
+ // the masks with no wildcards go first
+ // longer masks go first
+
+ bool bHasWildcards = m->szFileMask.contains('*');
+ int index = 0;
+ for(KviMediaType * mt = m_pMediaTypeList->first();mt;mt = m_pMediaTypeList->next())
+ {
+ if(bHasWildcards)
+ {
+ if(mt->szFileMask.len() < m->szFileMask.len())
+ {
+ m_pMediaTypeList->insert(index,m);
+ return;
+ } else if(mt->szFileMask.len() == m->szFileMask.len())
+ {
+ if(mt->szMagicBytes.len() < m->szMagicBytes.len())
+ {
+ m_pMediaTypeList->insert(index,m);
+ return;
+ }
+ }
+ } else {
+ if(mt->szFileMask.contains('*'))
+ {
+ m_pMediaTypeList->insert(index,m);
+ return;
+ } else {
+ if(mt->szFileMask.len() < m->szFileMask.len())
+ {
+ m_pMediaTypeList->insert(index,m);
+ return;
+ } else if(mt->szFileMask.len() == m->szFileMask.len())
+ {
+ if(mt->szMagicBytes.len() < m->szMagicBytes.len())
+ {
+ m_pMediaTypeList->insert(index,m);
+ return;
+ }
+ }
+ }
+ }
+ index++;
+ }
+ m_pMediaTypeList->append(m);
+*/
+}
+
+
+KviMediaType * KviMediaManager::findMediaType(const char * filename,bool bCheckMagic)
+{
+ // FIXME: This should be ported at least to QString....
+ __range_valid(locked());
+
+ KviStr szFullPath = filename;
+ if(!kvi_isAbsolutePath(szFullPath.ptr()))
+ {
+#ifdef COMPILE_USE_QT4
+ KviStr tmp = QDir::currentPath();
+#else
+ KviStr tmp = QDir::currentDirPath();
+#endif
+ tmp.ensureLastCharIs('/');
+ szFullPath.prepend(tmp);
+ }
+
+ KviStr szFile = filename;
+ szFile.cutToLast('/',true);
+
+
+ // first of all , lstat() the file
+#ifdef COMPILE_ON_WINDOWS
+ struct _stat st;
+ if(_stat(szFullPath.ptr(),&st) != 0)
+#else
+ struct stat st;
+ if(lstat(szFullPath.ptr(),&st) != 0)
+#endif
+ {
+ //debug("Problems while stating file %s",szFullPath.ptr());
+ // We do just the pattern matching
+ // it's better to avoid magic checks
+ // if the file is a device , we would be blocked while attempting to read data
+ return findMediaTypeForRegularFile(szFullPath.ptr(),szFile.ptr(),false);
+ } else {
+ // If it is a link , stat() the link target
+#ifndef COMPILE_ON_WINDOWS
+ if(S_ISLNK(st.st_mode))
+ {
+ if(stat(szFullPath.ptr(),&st) != 0)
+ {
+ debug("Problems while stating() target for link %s",szFullPath.ptr());
+ // Same as above
+ return findMediaTypeForRegularFile(szFullPath.ptr(),szFile.ptr(),false);
+ }
+ }
+#endif
+ }
+
+
+ if(S_ISDIR(st.st_mode))
+ {
+ // Directory : return default media type
+ KviMediaType * mtd = findMediaTypeByIanaType("inode/directory");
+ if(!mtd)
+ {
+ // Add it
+ mtd = new KviMediaType;
+ mtd->szIanaType = "inode/directory";
+ mtd->szDescription = __tr("Directory");
+ mtd->szCommandline = "dirbrowser.open -m $0";
+ mtd->szIcon = "kvi_dbfolder.png"; // hardcoded ?
+ insertMediaType(mtd);
+ }
+ return mtd;
+ }
+
+
+#ifndef COMPILE_ON_WINDOWS
+ if(S_ISSOCK(st.st_mode))
+ {
+ // Socket : return default media type
+ KviMediaType * mtd = findMediaTypeByIanaType("inode/socket");
+ if(!mtd)
+ {
+ // Add it
+ mtd = new KviMediaType;
+ mtd->szIanaType = "inode/socket";
+ mtd->szDescription = __tr("Socket");
+ mtd->szIcon = "kvi_dbsocket.png"; // hardcoded ?
+ insertMediaType(mtd);
+ }
+ return mtd;
+ }
+#endif
+
+ if(S_ISFIFO(st.st_mode))
+ {
+ // Fifo: return default media type
+ KviMediaType * mtd = findMediaTypeByIanaType("inode/fifo");
+ if(!mtd)
+ {
+ // Add it
+ mtd = new KviMediaType;
+ mtd->szIanaType = "inode/fifo";
+ mtd->szDescription = __tr("Fifo");
+ mtd->szIcon = "kvi_dbfifo.png"; // hardcoded ?
+ insertMediaType(mtd);
+ }
+ return mtd;
+ }
+
+#ifndef COMPILE_ON_WINDOWS
+ if(S_ISBLK(st.st_mode))
+ {
+ // Block device: return default media type
+ KviMediaType * mtd = findMediaTypeByIanaType("inode/blockdevice");
+ if(!mtd)
+ {
+ // Add it
+ mtd = new KviMediaType;
+ mtd->szIanaType = "inode/blockdevice";
+ mtd->szDescription = __tr("Block device");
+ mtd->szIcon = "kvi_dbblockdevice.png"; // hardcoded ?
+ insertMediaType(mtd);
+ }
+ return mtd;
+ }
+#endif
+
+ if(S_ISCHR(st.st_mode))
+ {
+ // Char device: return default media type
+ KviMediaType * mtd = findMediaTypeByIanaType("inode/chardevice");
+ if(!mtd)
+ {
+ // Add it
+ mtd = new KviMediaType;
+ mtd->szIanaType = "inode/chardevice";
+ mtd->szDescription = __tr("Char device");
+ mtd->szIcon = "kvi_dbchardevice.png"; // hardcoded ?
+ insertMediaType(mtd);
+ }
+ return mtd;
+ }
+
+
+ // this is a regular file (or at least it looks like one)
+ return findMediaTypeForRegularFile(szFullPath.ptr(),szFile.ptr(),bCheckMagic);
+}
+
+KviMediaType * KviMediaManager::findMediaTypeForRegularFile(const char * szFullPath,const char * szFileName,bool bCheckMagic)
+{
+ char buffer[17];
+ int len = 0;
+
+ if(bCheckMagic)
+ {
+ QString szTmp=QString::fromUtf8(szFullPath);
+ KviFile f(szTmp);
+ if(f.openForReading())
+ {
+ len = f.readBlock(buffer,16);
+ if(len > 0)
+ {
+ buffer[len] = '\0';
+ if(buffer[0] == 0)len = 0; // no way to match it
+ }
+ f.close();
+ }
+ }
+
+ for(KviMediaType * m = m_pMediaTypeList->first();m;m = m_pMediaTypeList->next())
+ {
+// FIXME: #warning "Should this be case sensitive ?"
+ if(kvi_matchWildExpr(m->szFileMask.ptr(),szFileName))
+ {
+ if(len && m->szMagicBytes.hasData())
+ {
+ QRegExp re(m->szMagicBytes.ptr());
+ // It looks like they can't decide the name for this function :D
+ // ... well, maybe the latest choice is the best one.
+#ifdef COMPILE_USE_QT4
+ if(re.indexIn(buffer) > -1)return m; // matched!
+#else
+ #if QT_VERSION >= 300
+ if(re.search(buffer) > -1)return m; // matched!
+ #else
+ if(re.find(buffer,0) > -1)return m; // matched!
+ #endif
+#endif
+ // else magic failed...not a match
+ } else return m; // matched! (no magic check)
+ }
+ }
+
+ KviMediaType * mtd = findMediaTypeByIanaType("application/octet-stream");
+ if(!mtd)
+ {
+ // Add it
+ mtd = new KviMediaType;
+ mtd->szIanaType = "application/octet-stream";
+ mtd->szDescription = __tr("Octet stream (unknown)");
+ mtd->szCommandline = "editor.open $0";
+ mtd->szIcon = "kvi_dbunknown.png"; // hardcoded ?
+ insertMediaType(mtd);
+ }
+
+ return mtd;
+}
+
+typedef struct _KviDefaultMediaType
+{
+ const char * filemask;
+ const char * magicbytes;
+ const char * ianatype;
+ const char * description;
+ const char * commandline;
+} KviDefaultMediaType;
+
+
+// FIXME : default handlers for windows ?
+
+static KviDefaultMediaType g_defMediaTypes[]=
+{
+ { "*.jpg","^\\0330\\0377","image/jpeg","JPEG image","run kview $0" },
+ { "*.jpeg","^\\0330\\0377","image/jpeg","JPEG image","run kview $0" },
+ { "*.png","","image/png","PNG image","run kview $0" },
+ { "*.mp3","","audio/mpeg","MPEG audio","run xmms -e $0" },
+ { "*.gif","","image/gif","GIF image","run kvirc $0" },
+ { "*.mpeg","","video/mpeg","MPEG video","run xanim $0" },
+ { "*.exe","","application/x-executable-file","Executable file","run $0" },
+ { "*.zip","^PK\\0003\\0004","application/zip","ZIP archive","run ark $0" },
+ { "*.tar.gz","","application/x-gzip","GZipped tarball","run ark $0" },
+ { "*.tar.bz2","","applicatoin/x-bzip2","BZipped tarball","run ark $0" },
+ { "*.tgz","","application/x-gzip","GZipped tarball","run ark $0" },
+ { "*.wav","","audio/wav","Wave audio","run play $0" },
+ { 0,0,0,0,0 }
+};
+
+void KviMediaManager::load(const char * filename)
+{
+ __range_valid(locked());
+
+ KviConfig cfg(filename,KviConfig::Read);
+ cfg.setGroup("MediaTypes");
+ unsigned int nEntries = cfg.readUIntEntry("NEntries",0);
+ for(unsigned int i = 0; i < nEntries;i++)
+ {
+ KviMediaType * m = new KviMediaType;
+ KviStr tmp(KviStr::Format,"%dFileMask",i);
+ m->szFileMask = cfg.readEntry(tmp.ptr(),"");
+ tmp.sprintf("%dMagicBytes",i);
+ m->szMagicBytes = cfg.readEntry(tmp.ptr(),"");
+ tmp.sprintf("%dIanaType",i);
+ m->szIanaType = cfg.readEntry(tmp.ptr(),"application/unknown");
+ tmp.sprintf("%dDescription",i);
+ m->szDescription = cfg.readEntry(tmp.ptr(),"");
+ tmp.sprintf("%dSavePath",i);
+ m->szSavePath = cfg.readEntry(tmp.ptr(),"");
+ tmp.sprintf("%dCommandline",i);
+ m->szCommandline = cfg.readEntry(tmp.ptr(),"");
+ tmp.sprintf("%dRemoteExecCommandline",i);
+ m->szRemoteExecCommandline = cfg.readEntry(tmp.ptr(),"");
+ tmp.sprintf("%dIcon",i);
+ m->szIcon = cfg.readEntry(tmp.ptr(),"");
+ insertMediaType(m);
+ }
+
+ for(int u = 0;g_defMediaTypes[u].filemask;u++)
+ {
+ if(!findMediaTypeByFileMask(g_defMediaTypes[u].filemask))
+ {
+ KviMediaType * m = new KviMediaType;
+ m->szFileMask = g_defMediaTypes[u].filemask;
+ m->szMagicBytes = g_defMediaTypes[u].magicbytes;
+ m->szIanaType = g_defMediaTypes[u].ianatype;
+ m->szDescription = g_defMediaTypes[u].description;
+ m->szCommandline = g_defMediaTypes[u].commandline;
+ insertMediaType(m);
+ }
+ }
+
+}
+
+void KviMediaManager::save(const char * filename)
+{
+ __range_valid(locked());
+ KviConfig cfg(filename,KviConfig::Write);
+
+ cfg.clear();
+ cfg.setGroup("MediaTypes");
+ cfg.writeEntry("NEntries",m_pMediaTypeList->count());
+ int index = 0;
+ for(KviMediaType * m= m_pMediaTypeList->first();m;m = m_pMediaTypeList->next())
+ {
+ KviStr tmp(KviStr::Format,"%dFileMask",index);
+ cfg.writeEntry(tmp.ptr(),m->szFileMask.ptr());
+ tmp.sprintf("%dMagicBytes",index);
+ cfg.writeEntry(tmp.ptr(),m->szMagicBytes.ptr());
+ tmp.sprintf("%dIanaType",index);
+ cfg.writeEntry(tmp.ptr(),m->szIanaType.ptr());
+ tmp.sprintf("%dDescription",index);
+ cfg.writeEntry(tmp.ptr(),m->szDescription.ptr());
+ tmp.sprintf("%dSavePath",index);
+ cfg.writeEntry(tmp.ptr(),m->szSavePath.ptr());
+ tmp.sprintf("%dCommandline",index);
+ cfg.writeEntry(tmp.ptr(),m->szCommandline.ptr());
+ tmp.sprintf("%dRemoteExecCommandline",index);
+ cfg.writeEntry(tmp.ptr(),m->szRemoteExecCommandline.ptr());
+ tmp.sprintf("%dIcon",index);
+ cfg.writeEntry(tmp.ptr(),m->szIcon.ptr());
+ ++index;
+ }
+}
diff --git a/src/kvilib/ext/kvi_mediatype.h b/src/kvilib/ext/kvi_mediatype.h
new file mode 100644
index 00000000..77e96594
--- /dev/null
+++ b/src/kvilib/ext/kvi_mediatype.h
@@ -0,0 +1,83 @@
+#ifndef _KVI_MEDIATYPE_H_
+#define _KVI_MEDIATYPE_H_
+//
+// File : kvi_mediatype.h
+// Creation date : Mon Aug 21 2000 17:19:56 CEST by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2000-2001 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_settings.h"
+#include "kvi_heapobject.h"
+#include "kvi_string.h"
+#include "kvi_thread.h"
+
+#include "kvi_pointerlist.h"
+
+
+//
+// IANA media-types matching subsystem
+//
+// WARNING: This class is used in multiple threads
+// Thus every usage of the classes and structures defined
+// in this file MUST be protected by calls
+// to KviMediaManager::lock() and KviMediaManager::unlock()
+//
+
+
+class KVILIB_API KviMediaType : public KviHeapObject
+{
+public:
+ KviMediaType(){};
+ ~KviMediaType(){};
+public:
+ KviStr szFileMask;
+ KviStr szMagicBytes;
+ KviStr szIanaType;
+ KviStr szDescription;
+ KviStr szSavePath;
+ KviStr szCommandline;
+ KviStr szRemoteExecCommandline;
+ KviStr szIcon;
+};
+
+class KVILIB_API KviMediaManager : public KviMutex
+{
+public:
+ KviMediaManager();
+ ~KviMediaManager();
+protected:
+ KviPointerList<KviMediaType> * m_pMediaTypeList;
+private:
+ KviMediaType * findMediaTypeForRegularFile(const char * szFullPath,const char * szFileName,bool bCheckMagic);
+public:
+ KviPointerList<KviMediaType> * mediaTypeList(){ return m_pMediaTypeList; };
+ KviMediaType * findMediaTypeByFileMask(const char * filemask);
+ KviMediaType * findMediaTypeByIanaType(const char * ianaType);
+ bool removeMediaType(KviMediaType * t){ return m_pMediaTypeList->removeRef(t); };
+ void clear(){ m_pMediaTypeList->clear(); };
+ void insertMediaType(KviMediaType * t);
+ KviMediaType * findMediaType(const char * filename,bool bCheckMagic = true);
+ static void copyMediaType(KviMediaType * dst,KviMediaType * src);
+
+ void load(const char * filename);
+ void save(const char * filename);
+};
+
+
+#endif //_KVI_MEDIATYPE_H_
diff --git a/src/kvilib/ext/kvi_miscutils.cpp b/src/kvilib/ext/kvi_miscutils.cpp
new file mode 100644
index 00000000..184345ed
--- /dev/null
+++ b/src/kvilib/ext/kvi_miscutils.cpp
@@ -0,0 +1,86 @@
+//=============================================================================
+//
+// File : kvi_miscutils.cpp
+// Created on Mon 08 Jan 2007 04:07:31 by Szymon Stefanek
+//
+// This file is part of the KVIrc IRC Client distribution
+// Copyright (C) 2007 Szymon Stefanek <pragma at kvirc dot net>
+//
+// 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 opinion) 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.
+//
+//=============================================================================
+
+#define __KVILIB__
+#include "kvi_miscutils.h"
+
+#include <qstringlist.h>
+
+namespace KviMiscUtils
+{
+ int compareVersions(const QString &szVersion1,const QString &szVersion2)
+ {
+#ifdef COMPILE_USE_QT4
+ QStringList sl1 = szVersion1.split(".");
+ QStringList sl2 = szVersion2.split(".");
+#else
+ QStringList sl1 = QStringList::split(".",szVersion1);
+ QStringList sl2 = QStringList::split(".",szVersion2);
+#endif
+
+ QStringList::Iterator it1 = sl1.begin();
+ QStringList::Iterator it2 = sl2.begin();
+ while((it1 != sl1.end()) && (it2 != sl2.end()))
+ {
+ bool bOk;
+ int i1 = (*it1).toInt(&bOk);
+ if(!bOk)return 1;
+ int i2 = (*it2).toInt(&bOk);
+ if(!bOk)return -1;
+ if(i1 != i2)
+ {
+ // field not equal
+ if(i1 > i2)return -1;
+ else return 1;
+ }
+ it1++;
+ it2++;
+ }
+ // both are equal until now
+ if(it1 != sl1.end())return -1; // 1 has at least one field more
+ if(it2 != sl2.end())return 1; // 2 has at least one field more
+ // both are equal also in length
+ return 0;
+ }
+
+ bool isValidVersionString(const QString &szVersion)
+ {
+#ifdef COMPILE_USE_QT4
+ QStringList sl = szVersion.split(".");
+#else
+ QStringList sl = QStringList::split(".",szVersion);
+#endif
+ if(sl.isEmpty())return false;
+ // must all be numbers
+ for(QStringList::Iterator it = sl.begin();it != sl.end();++it)
+ {
+ bool bOk;
+ int i = (*it).toInt(&bOk);
+ if(!bOk)return false;
+ if(i < 0)return false;
+ }
+ return true;
+ }
+
+};
diff --git a/src/kvilib/ext/kvi_miscutils.h b/src/kvilib/ext/kvi_miscutils.h
new file mode 100644
index 00000000..f09d63a7
--- /dev/null
+++ b/src/kvilib/ext/kvi_miscutils.h
@@ -0,0 +1,44 @@
+#ifndef _KVI_MISCUTILS_H_
+#define _KVI_MISCUTILS_H_
+//=============================================================================
+//
+// File : kvi_miscutils.h
+// Created on Mon 08 Jan 2007 04:07:31 by Szymon Stefanek
+//
+// This file is part of the KVIrc IRC Client distribution
+// Copyright (C) 2007 Szymon Stefanek <pragma at kvirc dot net>
+//
+// 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 opinion) 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 "kvi_settings.h"
+#include "kvi_qstring.h"
+
+// this is the namespace for single function stuff that doesn't really fit anywhere else
+
+namespace KviMiscUtils
+{
+ // Compare two x.y.z... version strings.
+ // The function behaves like strcmp: it returns 0 when the versions
+ // are equal, -1 if the szVersion1 is greater and 1 if szVersion2 is greater
+ extern KVILIB_API int compareVersions(const QString &szVersion1,const QString &szVersion2);
+
+ // Check if the argument string is a valid x.y.z.... version string
+ extern KVILIB_API bool isValidVersionString(const QString &szVersion);
+
+};
+
+#endif //!_KVI_MISCUTILS_H_
diff --git a/src/kvilib/ext/kvi_msgtype.cpp b/src/kvilib/ext/kvi_msgtype.cpp
new file mode 100644
index 00000000..d79a6220
--- /dev/null
+++ b/src/kvilib/ext/kvi_msgtype.cpp
@@ -0,0 +1,68 @@
+//
+// File : kvi_msgtype.cpp
+// Creation date : Fri 30 24 2000 13:53:21 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+
+#define __KVILIB__
+
+
+#define _KVI_DEBUG_CHECK_RANGE_
+
+#include "kvi_debug.h"
+#include "kvi_msgtype.h"
+
+KviMsgType::KviMsgType(const char * type,int pixId,unsigned char fore,unsigned char back,bool bLog,int iLevel)
+{
+ m_szType = type;
+ m_iPixId = pixId;
+ m_cForeColor = fore;
+ m_cBackColor = back;
+ m_bLogEnabled = bLog;
+ if((iLevel < KVI_MSGTYPE_MINLEVEL) || (iLevel > KVI_MSGTYPE_MAXLEVEL))iLevel = 1;
+ m_iLevel = iLevel;
+}
+
+KviMsgType::KviMsgType(const KviMsgType &msg)
+{
+ m_szType = msg.m_szType;
+ m_iPixId = msg.m_iPixId;
+ m_cForeColor = msg.m_cForeColor;
+ m_cBackColor = msg.m_cBackColor;
+ m_bLogEnabled = msg.m_bLogEnabled;
+ m_iLevel = msg.m_iLevel;
+}
+
+KviMsgType::~KviMsgType()
+{
+}
+
+
+
+KviMsgType & KviMsgType::operator=(const KviMsgType &msg)
+{
+ //if(m_szType.ptr() == msg.m_szType.ptr())return (*this); // self assignment (!!!)
+ m_szType = msg.m_szType;
+ m_iPixId = msg.m_iPixId;
+ m_cForeColor = msg.m_cForeColor;
+ m_cBackColor = msg.m_cBackColor;
+ m_bLogEnabled = msg.m_bLogEnabled;
+ m_iLevel = msg.m_iLevel;
+ return (*this);
+}
diff --git a/src/kvilib/ext/kvi_msgtype.h b/src/kvilib/ext/kvi_msgtype.h
new file mode 100644
index 00000000..ca4553ef
--- /dev/null
+++ b/src/kvilib/ext/kvi_msgtype.h
@@ -0,0 +1,74 @@
+#ifndef _KVI_MSGTYPE_H_
+#define _KVI_MSGTYPE_H_
+
+//
+// File : kvi_msgtype.h
+// Creation date : Fri Jun 30 2000 13:50:11 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_settings.h"
+#include "kvi_string.h"
+
+#define KVI_MSGTYPE_MINLEVEL 0
+#define KVI_MSGTYPE_LEVEL_0 0
+#define KVI_MSGTYPE_LEVEL_1 1
+#define KVI_MSGTYPE_LEVEL_2 2
+#define KVI_MSGTYPE_LEVEL_3 3
+#define KVI_MSGTYPE_LEVEL_4 4
+#define KVI_MSGTYPE_LEVEL_5 5
+#define KVI_MSGTYPE_MAXLEVEL 5
+
+// 1 : Common activity
+// 2 : People talking
+// 3 : Response messages (whois , dns)
+// 4 :
+// 5 : Highlighted text
+
+// FIXME: Check the message ranges!!!
+
+class KVILIB_API KviMsgType
+{
+public:
+ KviMsgType(const char * type,int pixId,unsigned char fore,unsigned char back,bool bLog,int iLevel);
+ KviMsgType(const KviMsgType &msg);
+ ~KviMsgType();
+public:
+ const char * m_szType;
+ int m_iPixId;
+ unsigned char m_cForeColor;
+ unsigned char m_cBackColor;
+ bool m_bLogEnabled;
+ int m_iLevel;
+public:
+ void setBack(char back){ m_cBackColor = back; };
+ void setFore(char fore){ m_cForeColor = fore; };
+ int pixId(){ return m_iPixId; };
+ int level(){ return m_iLevel; };
+ void setLevel(int iLevel){ if((iLevel < KVI_MSGTYPE_MINLEVEL) || (iLevel > KVI_MSGTYPE_MAXLEVEL))m_iLevel = 1; else m_iLevel = iLevel; };
+ void setPixId(int pixId){ m_iPixId = pixId; };
+ unsigned char back(){ return m_cBackColor; };
+ unsigned char fore(){ return m_cForeColor; };
+ bool logEnabled(){ return m_bLogEnabled; };
+ void enableLogging(bool bEnable){ m_bLogEnabled = bEnable; };
+ const char * type(){ return m_szType; };
+ KviMsgType & operator=(const KviMsgType &msg); // deep copy
+};
+
+#endif //_KVI_MSGTYPE_H_
diff --git a/src/kvilib/ext/kvi_osinfo.cpp b/src/kvilib/ext/kvi_osinfo.cpp
new file mode 100644
index 00000000..51037a48
--- /dev/null
+++ b/src/kvilib/ext/kvi_osinfo.cpp
@@ -0,0 +1,510 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// File : kvi_osinfo.cpp
+// Creation date : 19 Jan 2006 GMT by Alexey Uzhva
+//
+// This toolbar is part of the KVirc irc client distribution
+// Copyright (C) 2006 Alexey Uzhva
+//
+// 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 opinion) 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.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#define __KVILIB__
+
+#include "kvi_osinfo.h"
+#include "kvi_locale.h"
+#include "kvi_qstring.h"
+
+#ifndef COMPILE_ON_WINDOWS
+ #include <sys/utsname.h>
+ #include <stdlib.h>
+ #include <unistd.h>
+#endif
+
+#ifdef COMPILE_ON_WINDOWS
+#include <windows.h>
+
+typedef enum QueryInfo
+{
+ Os_Release,
+ Os_Version,
+ Os_Type
+};
+typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
+typedef BOOL (WINAPI *PGETPRODUCTINFO)(DWORD,DWORD,DWORD,DWORD,PDWORD);
+
+#define SM_SERVERR2 89
+#define BUFSIZE 1024
+
+//Vista :/
+
+#define PRODUCT_BUSINESS 0x00000006
+#define PRODUCT_BUSINESS_N 0x00000010
+#define PRODUCT_CLUSTER_SERVER 0x00000012
+#define PRODUCT_DATACENTER_SERVER 0x00000008
+#define PRODUCT_DATACENTER_SERVER_CORE 0x0000000C
+#define PRODUCT_ENTERPRISE 0x00000004
+#define PRODUCT_ENTERPRISE_SERVER 0x0000000A
+#define PRODUCT_ENTERPRISE_SERVER_CORE 0x0000000E
+#define PRODUCT_ENTERPRISE_SERVER_IA64 0x0000000F
+#define PRODUCT_HOME_BASIC 0x00000002
+#define PRODUCT_HOME_BASIC_N 0x00000005
+#define PRODUCT_HOME_PREMIUM 0x00000003
+#define PRODUCT_HOME_SERVER 0x00000013
+#define PRODUCT_SERVER_FOR_SMALLBUSINESS 0x00000018
+#define PRODUCT_SMALLBUSINESS_SERVER 0x00000009
+#define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM 0x00000019
+#define PRODUCT_STANDARD_SERVER 0x00000007
+#define PRODUCT_STANDARD_SERVER_CORE 0x0000000D
+#define PRODUCT_STARTER 0x0000000B
+#define PRODUCT_STORAGE_ENTERPRISE_SERVER 0x00000017
+#define PRODUCT_STORAGE_EXPRESS_SERVER 0x00000014
+#define PRODUCT_STORAGE_STANDARD_SERVER 0x00000015
+#define PRODUCT_STORAGE_WORKGROUP_SERVER 0x00000016
+#define PRODUCT_UNDEFINED 0x00000000
+#define PRODUCT_ULTIMATE 0x00000001
+#define PRODUCT_WEB_SERVER 0x00000011
+
+static QString queryWinInfo( QueryInfo info)
+{
+ QString szVersion;
+ OSVERSIONINFOEX osvi;
+ SYSTEM_INFO si;
+ PGNSI pGNSI;
+ BOOL bOsVersionInfoEx;
+
+ ZeroMemory(&si, sizeof(SYSTEM_INFO));
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
+
+ // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
+ // If that fails, try using the OSVERSIONINFO structure.
+
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
+
+ if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
+ {
+ osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
+ if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
+ return FALSE;
+ }
+
+ // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.
+
+ pGNSI = (PGNSI) GetProcAddress(
+ GetModuleHandle(TEXT("kernel32.dll")),
+ "GetNativeSystemInfo");
+ if(NULL != pGNSI)
+ pGNSI(&si);
+ else GetSystemInfo(&si);
+
+ switch (osvi.dwPlatformId)
+ {
+ // Test for the Windows NT product family.
+
+ case VER_PLATFORM_WIN32_NT:
+
+ // Test for the specific product.
+
+ if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 )
+ {
+ if( osvi.wProductType == VER_NT_WORKSTATION )
+ szVersion+= "Windows Vista ";
+ else szVersion+="Windows Server \"Longhorn\" ";
+ }
+
+ if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
+ {
+ if( GetSystemMetrics(SM_SERVERR2) )
+ szVersion+="Windows Server 2003 \"R2\" ";
+ else if( osvi.wProductType == VER_NT_WORKSTATION &&
+ si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
+ {
+ szVersion+="Windows XP Professional x64 Edition ";
+ }
+ else szVersion+="Windows Server 2003, ";
+ }
+
+ if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
+ szVersion+="Windows XP ";
+
+ if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
+ szVersion+="Windows 2000 ";
+
+ if ( osvi.dwMajorVersion <= 4 )
+ szVersion+="Windows NT ";
+
+ PGETPRODUCTINFO pGetProductInfo;
+ pGetProductInfo = (PGETPRODUCTINFO) GetProcAddress(
+ GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo");
+ // Test for specific product on Windows NT 4.0 SP6 and later.
+ if( bOsVersionInfoEx )
+ {
+ DWORD dwPlatformInfo;
+ if(NULL != pGetProductInfo)
+ if(pGetProductInfo(osvi.dwMajorVersion,osvi.dwMinorVersion,
+ osvi.wServicePackMajor,osvi.wServicePackMinor,&dwPlatformInfo))
+ {
+ switch(dwPlatformInfo)
+ {
+ case PRODUCT_BUSINESS:
+ szVersion+="Business Edition";
+ break;
+ case PRODUCT_BUSINESS_N:
+ szVersion+="Business N Edition";
+ break;
+ case PRODUCT_CLUSTER_SERVER:
+ szVersion+="Cluster Server Edition";
+ break;
+ case PRODUCT_DATACENTER_SERVER:
+ szVersion+="Server Datacenter Edition (full installation)";
+ break;
+ case PRODUCT_DATACENTER_SERVER_CORE:
+ szVersion+="Server Datacenter Edition (core installation)";
+ break;
+ case PRODUCT_ENTERPRISE:
+ szVersion+="Enterprise Edition";
+ break;
+ case PRODUCT_ENTERPRISE_SERVER:
+ szVersion+="Server Enterprise Edition (full installation)";
+ break;
+ case PRODUCT_ENTERPRISE_SERVER_CORE:
+ szVersion+="Server Enterprise Edition (core installation)";
+ break;
+ case PRODUCT_ENTERPRISE_SERVER_IA64:
+ szVersion+="Server Enterprise Edition for Itanium-based Systems";
+ break;
+ case PRODUCT_HOME_BASIC:
+ szVersion+="Home Basic Edition";
+ break;
+ case PRODUCT_HOME_BASIC_N:
+ szVersion+="Home Basic N Edition";
+ break;
+ case PRODUCT_HOME_PREMIUM:
+ szVersion+="Home Premium Edition";
+ break;
+ case PRODUCT_HOME_SERVER:
+ szVersion+="Home Server Edition";
+ break;
+ case PRODUCT_SERVER_FOR_SMALLBUSINESS:
+ szVersion+="Server for Small Business Edition";
+ break;
+ case PRODUCT_SMALLBUSINESS_SERVER:
+ szVersion+="Small Business Server";
+ break;
+ case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
+ szVersion+="Small Business Server Premium Edition";
+ break;
+ case PRODUCT_STANDARD_SERVER:
+ szVersion+="Server Standard Edition (full installation)";
+ break;
+ case PRODUCT_STANDARD_SERVER_CORE:
+ szVersion+="Server Standard Edition (core installation)";
+ break;
+ case PRODUCT_STARTER:
+ szVersion+="Starter Edition";
+ break;
+ case PRODUCT_STORAGE_ENTERPRISE_SERVER:
+ szVersion+="Storage Server Enterprise Edition";
+ break;
+ case PRODUCT_STORAGE_EXPRESS_SERVER:
+ szVersion+="Storage Server Express Edition";
+ break;
+ case PRODUCT_STORAGE_STANDARD_SERVER:
+ szVersion+="Storage Server Standard Edition";
+ break;
+ case PRODUCT_STORAGE_WORKGROUP_SERVER:
+ szVersion+="Storage Server Workgroup Edition";
+ break;
+ case PRODUCT_UNDEFINED:
+ szVersion+="An unknown product";
+ break;
+ case PRODUCT_ULTIMATE:
+ szVersion+="Ultimate Edition";
+ break;
+ case PRODUCT_WEB_SERVER:
+ szVersion+="Web Server Edition";
+ break;
+
+ }
+ szVersion+=" ";
+ if (si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
+ {
+ szVersion+="(x64) ";
+ }
+ } else {
+ // Test for the workstation type.
+ if ( osvi.wProductType == VER_NT_WORKSTATION &&
+ si.wProcessorArchitecture!=PROCESSOR_ARCHITECTURE_AMD64)
+ {
+ if( osvi.dwMajorVersion == 4 )
+ szVersion+= "Workstation 4.0 " ;
+ else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
+ szVersion+= "Home Edition " ;
+ else szVersion+= "Professional " ;
+ }
+
+ // Test for the server type.
+ else if ( osvi.wProductType == VER_NT_SERVER ||
+ osvi.wProductType == VER_NT_DOMAIN_CONTROLLER )
+ {
+ if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==2)
+ {
+ if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64 )
+ {
+ if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
+ szVersion+= "Datacenter Edition for Itanium-based Systems" ;
+ else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
+ szVersion+= "Enterprise Edition for Itanium-based Systems" ;
+ }
+
+ else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
+ {
+ if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
+ szVersion+= "Datacenter x64 Edition " ;
+ else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
+ szVersion+= "Enterprise x64 Edition " ;
+ else szVersion+= "Standard x64 Edition " ;
+ }
+
+ else
+ {
+ if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
+ szVersion+= "Datacenter Edition " ;
+ else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
+ szVersion+= "Enterprise Edition " ;
+ else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
+ szVersion+= "Web Edition " ;
+ else szVersion+= "Standard Edition " ;
+ }
+ }
+ else if(osvi.dwMajorVersion==5 && osvi.dwMinorVersion==0)
+ {
+ if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
+ szVersion+= "Datacenter Server " ;
+ else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
+ szVersion+= "Advanced Server " ;
+ else szVersion+= "Server " ;
+ }
+ else // Windows NT 4.0
+ {
+ if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
+ szVersion+="Server 4.0, Enterprise Edition " ;
+ else szVersion+= "Server 4.0 " ;
+ }
+ }
+ }
+ }
+ // Test for specific product on Windows NT 4.0 SP5 and earlier
+ else
+ {
+ HKEY hKey;
+ TCHAR szProductType[BUFSIZE];
+ DWORD dwBufLen=BUFSIZE*sizeof(TCHAR);
+ LONG lRet;
+
+ lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
+ TEXT("SYSTEM\\CurrentControlSet\\Control\\ProductOptions"),
+ 0, KEY_QUERY_VALUE, &hKey );
+ if( lRet != ERROR_SUCCESS )
+ return FALSE;
+
+ lRet = RegQueryValueEx( hKey, TEXT("ProductType"), NULL, NULL,
+ (LPBYTE) szProductType, &dwBufLen);
+ RegCloseKey( hKey );
+
+ if( (lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE*sizeof(TCHAR)) )
+ return FALSE;
+
+ if ( lstrcmpi( TEXT("WINNT"), szProductType) == 0 )
+ szVersion+= "Workstation " ;
+ if ( lstrcmpi( TEXT("LANMANNT"), szProductType) == 0 )
+ szVersion+= "Server " ;
+ if ( lstrcmpi( TEXT("SERVERNT"), szProductType) == 0 )
+ szVersion+= "Advanced Server " ;
+ }
+
+
+ // Display service pack (if any) and build number.
+
+ if( osvi.dwMajorVersion == 4 &&
+ lstrcmpi( osvi.szCSDVersion, TEXT("Service Pack 6") ) == 0 )
+ {
+ HKEY hKey;
+ LONG lRet;
+
+ // Test for SP6 versus SP6a.
+ lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
+ TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009"),
+ 0, KEY_QUERY_VALUE, &hKey );
+ if( lRet == ERROR_SUCCESS )
+ szVersion+= QString("Service Pack 6a (Build %1)").arg( osvi.dwBuildNumber & 0xFFFF );
+ else // Windows NT 4.0 prior to SP6a
+ {
+ szVersion+= QString( "%1 (Build %2)").arg( osvi.szCSDVersion).arg( osvi.dwBuildNumber & 0xFFFF);
+ }
+
+ RegCloseKey( hKey );
+ }
+ else // not Windows NT 4.0
+ {
+ szVersion+= QString( "%1 (Build %2)").arg( osvi.szCSDVersion).arg( osvi.dwBuildNumber & 0xFFFF);
+ }
+
+ break;
+
+ // Test for the Windows Me/98/95.
+ case VER_PLATFORM_WIN32_WINDOWS:
+
+ if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
+ {
+ szVersion+="Windows 95 ";
+ if (osvi.szCSDVersion[1]=='C' || osvi.szCSDVersion[1]=='B')
+ szVersion+="OSR2 ";
+ }
+
+ if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
+ {
+ szVersion+="Windows 98 ";
+ if ( osvi.szCSDVersion[1]=='A' || osvi.szCSDVersion[1]=='B')
+ szVersion+="SE ";
+ }
+
+ if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
+ {
+ szVersion+="Windows Millennium Edition";
+ }
+ break;
+
+ case VER_PLATFORM_WIN32s:
+
+ szVersion+="Win32s";
+ break;
+ }
+ if(info==Os_Release)
+ {
+ unsigned long major = osvi.dwMajorVersion;
+ unsigned long minor = osvi.dwMinorVersion;
+ unsigned long release = osvi.dwBuildNumber;
+ QString szMajor, szMinor, szRelease, szVersion;
+ szMajor.setNum(major);
+ szMinor.setNum(minor);
+ szRelease.setNum(release);
+ szVersion = "Release : "+szMajor +"."+ szMinor +"."+ szRelease;
+ return szVersion;
+ }
+ if(info==Os_Type)
+ {
+ if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) return " NT ";
+ if(osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) return " Windows ";
+ if(osvi.dwPlatformId == VER_PLATFORM_WIN32s) return " Win32s ";
+ return __tr2qs("Unknown ");
+ }
+ if(info==Os_Version)
+ {
+ return szVersion;
+ }
+
+ return "what's wrong? o.O";
+}
+#endif
+
+
+namespace KviOsInfo
+{
+ QString type()
+ {
+#ifdef COMPILE_ON_WINDOWS
+ return queryWinInfo(Os_Type);
+#else
+ #ifdef Q_OS_MACX
+ return "macosx";
+ #else
+ return "unix";
+ #endif
+#endif
+ }
+
+ QString name()
+ {
+#ifdef COMPILE_ON_WINDOWS
+ return "windows";
+#else
+ struct utsname uts;
+ if(uname(&uts) == 0)
+ return QString::fromLocal8Bit(uts.sysname);
+ return KviQString::empty;
+#endif
+ }
+
+ QString version()
+ {
+#ifdef COMPILE_ON_WINDOWS
+ return queryWinInfo(Os_Version);
+#else
+ struct utsname uts;
+ if(uname(&uts) == 0)
+ return QString::fromLocal8Bit(uts.version);
+ return KviQString::empty;
+#endif
+ }
+
+ QString release()
+ {
+#ifdef COMPILE_ON_WINDOWS
+ return queryWinInfo(Os_Release);
+#else
+ struct utsname uts;
+ if(uname(&uts) == 0)
+ return QString::fromLocal8Bit(uts.release);
+ return KviQString::empty;
+#endif
+ }
+
+ QString machine()
+ {
+#ifdef COMPILE_ON_WINDOWS
+ QString mach = getenv("PROCESSOR_IDENTIFIER");
+ return mach.section(",",0,0);
+#else
+ struct utsname uts;
+ if(uname(&uts) == 0)
+ return QString::fromLocal8Bit(uts.machine);
+ return KviQString::empty;
+#endif
+ }
+
+ QString nodename()
+ {
+#ifdef COMPILE_ON_WINDOWS
+ return "windows";
+#else
+ struct utsname uts;
+ if(uname(&uts) == 0)
+ return QString::fromLocal8Bit(uts.nodename);
+ return KviQString::empty;
+#endif
+ }
+
+ QString hostname()
+ {
+ char hbuffer[1024];
+ if(gethostname(hbuffer,1024) == 0)
+ return QString::fromLocal8Bit(hbuffer);
+ else
+ return KviQString::empty;
+ }
+}
+
diff --git a/src/kvilib/ext/kvi_osinfo.h b/src/kvilib/ext/kvi_osinfo.h
new file mode 100644
index 00000000..9df4a990
--- /dev/null
+++ b/src/kvilib/ext/kvi_osinfo.h
@@ -0,0 +1,43 @@
+#ifndef _KVI_OSINFO_H_
+#define _KVI_OSINFO_H_
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// File : kvi_osinfo.h
+// Creation date : 19 Jan 2006 GMT by Alexey Uzhva
+//
+// This toolbar is part of the KVirc irc client distribution
+// Copyright (C) 2006 Alexey Uzhva
+//
+// 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 opinion) 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 "kvi_settings.h"
+
+#include <qstring.h>
+
+namespace KviOsInfo
+{
+ extern KVILIB_API QString type();
+ extern KVILIB_API QString name();
+ extern KVILIB_API QString version();
+ extern KVILIB_API QString release();
+ extern KVILIB_API QString machine();
+ extern KVILIB_API QString nodename();
+ extern KVILIB_API QString hostname();
+};
+
+#endif //!_KVI_OSINFO_H_
diff --git a/src/kvilib/ext/kvi_parameterlist.cpp b/src/kvilib/ext/kvi_parameterlist.cpp
new file mode 100644
index 00000000..318cd3d1
--- /dev/null
+++ b/src/kvilib/ext/kvi_parameterlist.cpp
@@ -0,0 +1,254 @@
+//
+// File : kvi_parameterlist.cpp
+// Creation date : Tue Sep 12 2000 18:14:01 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+
+#define __KVILIB__
+
+
+#include "kvi_parameterlist.h"
+
+KviParameterList::KviParameterList()
+: KviPointerList<KviStr>()
+{
+ setAutoDelete(true);
+}
+
+KviParameterList::KviParameterList(KviStr *p1)
+: KviPointerList<KviStr>()
+{
+ setAutoDelete(true);
+ append(p1);
+}
+
+KviParameterList::KviParameterList(KviStr *p1,KviStr *p2)
+: KviPointerList<KviStr>()
+{
+ setAutoDelete(true);
+ append(p1);
+ append(p2);
+}
+
+KviParameterList::KviParameterList(KviStr *p1,KviStr *p2,KviStr *p3)
+: KviPointerList<KviStr>()
+{
+ setAutoDelete(true);
+ append(p1);
+ append(p2);
+ append(p3);
+}
+
+KviParameterList::KviParameterList(KviStr *p1,KviStr *p2,KviStr *p3,KviStr *p4)
+: KviPointerList<KviStr>()
+{
+ setAutoDelete(true);
+ append(p1);
+ append(p2);
+ append(p3);
+ append(p4);
+}
+
+KviParameterList::KviParameterList(KviStr *p1,KviStr *p2,KviStr *p3,KviStr *p4,KviStr *p5)
+: KviPointerList<KviStr>()
+{
+ setAutoDelete(true);
+ append(p1);
+ append(p2);
+ append(p3);
+ append(p4);
+ append(p5);
+}
+
+KviParameterList::KviParameterList(KviStr *p1,KviStr *p2,KviStr *p3,KviStr *p4,KviStr *p5,KviStr *p6)
+: KviPointerList<KviStr>()
+{
+ setAutoDelete(true);
+ append(p1);
+ append(p2);
+ append(p3);
+ append(p4);
+ append(p5);
+ append(p6);
+}
+
+
+KviParameterList::KviParameterList(KviStr *p1,KviStr *p2,KviStr *p3,KviStr *p4,KviStr *p5,KviStr *p6,KviStr *p7)
+: KviPointerList<KviStr>()
+{
+ setAutoDelete(true);
+ append(p1);
+ append(p2);
+ append(p3);
+ append(p4);
+ append(p5);
+ append(p6);
+ append(p7);
+}
+
+KviParameterList::KviParameterList(const char *paramBuffer)
+: KviPointerList<KviStr>()
+{
+ setAutoDelete(true);
+ while(*paramBuffer)
+ {
+ KviStr * pStr = new KviStr();
+ paramBuffer = kvi_extractToken(*pStr,paramBuffer);
+ append(pStr);
+ }
+}
+
+KviParameterList::~KviParameterList()
+{
+}
+
+KviStr * KviParameterList::safeFirst()
+{
+ KviStr * f= first();
+ return f ? f : &m_szEmpty;
+}
+
+KviStr * KviParameterList::safeNext()
+{
+ KviStr * f = next();
+ return f ? f : &m_szEmpty;
+}
+
+
+bool KviParameterList::getBool()
+{
+ KviStr * par = current();
+ (void)next();
+ if(par)
+ {
+ if(kvi_strEqualCS(par->ptr(),"0"))return false;
+ }
+ return true; // default
+}
+
+int KviParameterList::getInt(bool * bOk)
+{
+ KviStr * par = current();
+ (void)next();
+ if(par)
+ {
+ return par->toInt(bOk);
+ }
+ if(bOk)*bOk = false;
+ return 0;
+}
+
+unsigned int KviParameterList::getUInt(bool * bOk)
+{
+ KviStr * par = current();
+ (void)next();
+ if(par)
+ {
+ return par->toUInt(bOk);
+ }
+ if(bOk)*bOk = false;
+ return 0;
+}
+
+QRect KviParameterList::getRect(bool * bOk)
+{
+ int val[4];
+ for(int i=0;i<4;i++)
+ {
+ KviStr * pszv = current();
+ (void)next();
+ if(!pszv)
+ {
+ if(bOk)*bOk = false;
+ return QRect(); // invalid
+ }
+ bool mybOk;
+ val[i] = pszv->toInt(&mybOk);
+ if(!mybOk)
+ {
+ if(bOk)*bOk = false;
+ return QRect(); // invalid
+ }
+ }
+ if(bOk)*bOk = true;
+ return QRect(val[0],val[1],val[2],val[3]);
+}
+
+QPoint KviParameterList::getPoint(bool * bOk)
+{
+ int val[2];
+ for(int i=0;i<2;i++)
+ {
+ KviStr * pszv = current();
+ (void)next();
+ if(!pszv)
+ {
+ if(bOk)*bOk = false;
+ return QPoint(); // invalid
+ }
+ bool mybOk;
+ val[i] = pszv->toInt(&mybOk);
+ if(!mybOk)
+ {
+ if(bOk)*bOk = false;
+ return QPoint(); // invalid
+ }
+ }
+ if(bOk)*bOk = true;
+ return QPoint(val[0],val[1]);
+}
+
+QSize KviParameterList::getSize(bool * bOk)
+{
+ int val[2];
+ for(int i=0;i<2;i++)
+ {
+ KviStr * pszv = current();
+ (void)next();
+ if(!pszv)
+ {
+ if(bOk)*bOk = false;
+ return QSize(); // invalid
+ }
+ bool mybOk;
+ val[i] = pszv->toInt(&mybOk);
+ if(!mybOk)
+ {
+ if(bOk)*bOk = false;
+ return QSize(); // invalid
+ }
+ }
+ if(bOk)*bOk = true;
+ return QSize(val[0],val[1]);
+}
+
+//#ifdef COMPILE_ON_WINDOWS
+//
+// #include "kvi_malloc.h"
+//
+// void * KviParameterList::operator new(size_t tSize)
+// {
+// return kvi_malloc(tSize);
+// }
+//
+// void KviParameterList::operator delete(void * p)
+// {
+// kvi_free(p);
+// }
+//#endif
diff --git a/src/kvilib/ext/kvi_parameterlist.h b/src/kvilib/ext/kvi_parameterlist.h
new file mode 100644
index 00000000..51c573e0
--- /dev/null
+++ b/src/kvilib/ext/kvi_parameterlist.h
@@ -0,0 +1,72 @@
+#ifndef _KVI_PARAMETERLIST_H_
+#define _KVI_PARAMETERLIST_H_
+
+//
+// File : kvi_parameterlist.h
+// Creation date : Tue Sep 12 2000 18:00:01 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_settings.h"
+#include "kvi_heapobject.h"
+#include "kvi_string.h"
+
+#include "kvi_pointerlist.h"
+#include <qrect.h>
+#include <qpoint.h>
+#include <qsize.h>
+
+class KVILIB_API KviParameterList : public KviPointerList<KviStr>, public KviHeapObject
+{
+public:
+ KviParameterList();
+ KviParameterList(KviStr *p1);
+ KviParameterList(KviStr *p1,KviStr *p2);
+ KviParameterList(KviStr *p1,KviStr *p2,KviStr *p3);
+ KviParameterList(KviStr *p1,KviStr *p2,KviStr *p3,KviStr *p4);
+ KviParameterList(KviStr *p1,KviStr *p2,KviStr *p3,KviStr *p4,KviStr *p5);
+ KviParameterList(KviStr *p1,KviStr *p2,KviStr *p3,KviStr *p4,KviStr *p5,KviStr *p6);
+ KviParameterList(KviStr *p1,KviStr *p2,KviStr *p3,KviStr *p4,KviStr *p5,KviStr *p6,KviStr *p7);
+ KviParameterList(const char * paramBuffer);
+ virtual ~KviParameterList();
+private:
+ KviStr m_szEmpty;
+public:
+ void init(){ (void)first(); };
+ // These functions have to be called when the
+ // current() points to the FIRST item that has
+ // to be interpreted as Bool,Int,UInt,Rect etc...
+ // At the call exit the current() points
+ // to the first item that was NOT used by the call
+ bool getBool();
+ int getInt(bool * bOk = 0);
+ unsigned int getUInt(bool * bOk = 0);
+ QRect getRect(bool * bOk = 0);
+ QPoint getPoint(bool * bOk = 0);
+ QSize getSize(bool * bOk = 0);
+ KviStr * safeFirst();
+ KviStr * safeNext();
+ const char * safeFirstParam(){ return safeFirst()->ptr(); };
+ const char * safeNextParam(){ return safeNext()->ptr(); };
+
+};
+
+
+
+#endif //_KVI_PARAMETERLIST_H_
diff --git a/src/kvilib/ext/kvi_pixmap.cpp b/src/kvilib/ext/kvi_pixmap.cpp
new file mode 100644
index 00000000..f22b03ef
--- /dev/null
+++ b/src/kvilib/ext/kvi_pixmap.cpp
@@ -0,0 +1,180 @@
+//=============================================================================
+//
+// File : kvi_pixmap.cpp
+// Creation date : Sat Jun 24 2000 14:00:27 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2000-2007 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+//=============================================================================
+
+
+#define __KVILIB__
+
+
+#include "kvi_debug.h"
+#include "kvi_pixmap.h"
+#include "kvi_qstring.h"
+
+#include <qpainter.h>
+
+KviPixmap::KviPixmap()
+{
+ m_pPix = 0;
+}
+
+KviPixmap::KviPixmap(const char * path)
+{
+ m_pPix = 0;
+ load(path);
+}
+
+KviPixmap::KviPixmap(const KviPixmap &pix)
+{
+ m_pPix = 0;
+ m_szPath = pix.path();
+
+ if(!m_szPath.isEmpty())
+ {
+ if(pix.pixmap())
+ {
+ m_pPix = new QPixmap(*(pix.pixmap()));
+ }
+ }
+}
+
+KviPixmap::~KviPixmap()
+{
+ if(m_pPix)delete m_pPix;
+ m_pPix = 0; // just to be sure :)
+}
+
+bool KviPixmap::load(const char * path)
+{
+ if(m_pPix)delete m_pPix;
+ m_pPix = 0;
+ m_szPath = path;
+ if(m_szPath.isEmpty())return false;
+
+ m_pPix = new QPixmap(m_szPath);
+
+ if(m_pPix->isNull())
+ {
+ delete m_pPix;
+ m_pPix = 0;
+ m_szPath = "";
+ return false;
+ }
+ return true;
+}
+
+bool KviPixmap::load(const QString& path)
+{
+ if(m_pPix)delete m_pPix;
+ m_pPix = 0;
+ m_szPath = path;
+ if(m_szPath.isEmpty())return false;
+
+ m_pPix = new QPixmap(m_szPath);
+
+ if(m_pPix->isNull())
+ {
+ delete m_pPix;
+ m_pPix = 0;
+ m_szPath = "";
+ return false;
+ }
+ return true;
+}
+
+void KviPixmap::set(const QPixmap &pix,const QString &szPath)
+{
+ if(pix.isNull())
+ {
+ setNull();
+ return;
+ }
+
+ if(m_pPix)delete m_pPix;
+ m_pPix = new QPixmap(pix);
+ m_szPath = szPath;
+}
+
+
+void KviPixmap::setNull()
+{
+ if(m_pPix)delete m_pPix;
+ m_pPix = 0;
+ m_szPath = "";
+}
+
+KviPixmap & KviPixmap::operator=(const KviPixmap &pix)
+{
+ if(m_pPix == pix.m_pPix)return (*this); // self assignment (!!!)
+ if(KviQString::equalCI(m_szPath,pix.path()))return (*this); // same pix
+
+ if(m_pPix)delete m_pPix;
+ m_pPix = 0;
+ m_szPath = pix.path();
+
+ if(!m_szPath.isEmpty())
+ {
+ if(pix.pixmap())
+ {
+ m_pPix = new QPixmap(*(pix.pixmap()));
+ }
+ }
+ return (*this);
+}
+
+
+void KviPixmapUtils::drawPixmapWithPainter(QPainter* p,QPixmap * pix,int flags,const QRect& paintRect,int iWidgetWidth,int iWidgetHeight,int dx,int dy)
+{
+ if(!pix)return;
+ if(!flags)
+ {
+ p->drawTiledPixmap(paintRect.left(),paintRect.top(),paintRect.width(),paintRect.height(),*pix,dx,dy);
+ return;
+ }
+
+ int iPixWidth=pix->width();
+ int iPixHeight=pix->height();
+ int x=0;
+ int y=0;
+
+ if( !(flags & Qt::AlignHorizontal_Mask ))
+ x=-1;
+ else if ( flags & Qt::AlignRight )
+ x=iWidgetWidth - iPixWidth;
+ else if( flags & Qt::AlignHCenter )
+ x=(iWidgetWidth - iPixWidth)/2;
+
+ if( !(flags & Qt::AlignVertical_Mask ))
+ y=-1;
+ else if ( flags & Qt::AlignBottom )
+ y=iWidgetHeight - iPixHeight;
+ else if( flags & Qt::AlignVCenter )
+ y=(iWidgetHeight - iPixHeight)/2;
+
+ if(x==-1) {
+ p->drawTiledPixmap(paintRect.left(),y,paintRect.width(),iPixHeight,*pix,dx,dy);
+ } else if(y==-1) {
+ p->drawTiledPixmap(x,paintRect.top(),iPixWidth,paintRect.height(),*pix,dx,dy);
+ } else {
+ p->drawPixmap(x,y,*pix);
+ }
+}
diff --git a/src/kvilib/ext/kvi_pixmap.h b/src/kvilib/ext/kvi_pixmap.h
new file mode 100644
index 00000000..7ba91cec
--- /dev/null
+++ b/src/kvilib/ext/kvi_pixmap.h
@@ -0,0 +1,61 @@
+#ifndef _KVI_PIXMAP_H_
+#define _KVI_PIXMAP_H_
+
+//=============================================================================
+//
+// File : kvi_pixmap.h
+// Creation date : Sat Jun 24 2000 13:59:04 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2000-2007 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_settings.h"
+#include "kvi_string.h"
+#include <qpixmap.h>
+
+class KVILIB_API KviPixmap
+{
+public:
+ KviPixmap();
+ KviPixmap(const char * path);
+ KviPixmap(const KviPixmap &pix);
+ ~KviPixmap();
+private:
+ QPixmap * m_pPix;
+ QString m_szPath;
+public:
+ bool isNull(){ return m_pPix == 0; };
+ bool load(const char * path);
+ bool load(const QString& path);
+ const QString& path() const { return m_szPath; };
+ QPixmap * pixmap() const { return m_pPix; };
+ void set(const QPixmap &pix,const QString &szPath);
+ KviPixmap & operator=(const KviPixmap &pix); // deep copy
+ void setNull();
+};
+
+namespace KviPixmapUtils
+{
+ extern KVILIB_API void drawPixmapWithPainter(QPainter* p,QPixmap * pix,int flags,const QRect& paintRect,int iWidgetWidth,int iWidgetHeight,int dx,int dy);
+ inline void drawPixmapWithPainter(QPainter* p,QPixmap * pix,int flags,const QRect& paintRect,int iWidgetWidth,int iWidgetHeight)
+ { KviPixmapUtils::drawPixmapWithPainter(p,pix,flags,paintRect,iWidgetWidth,iWidgetHeight,paintRect.left(),paintRect.top()); };
+};
+
+#endif //_KVI_PIXMAP_H_
diff --git a/src/kvilib/ext/kvi_proxydb.cpp b/src/kvilib/ext/kvi_proxydb.cpp
new file mode 100644
index 00000000..917795c3
--- /dev/null
+++ b/src/kvilib/ext/kvi_proxydb.cpp
@@ -0,0 +1,192 @@
+//
+// File : kvi_proxydb.cpp
+// Creation date : Sat Jul 22 2000 18:23:23 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+
+#define __KVILIB__
+
+
+#include "kvi_proxydb.h"
+#include "kvi_config.h"
+
+
+KviProxy::KviProxy()
+{
+ m_szHostname = "proxy.example.net";
+ m_uPort = 1080;
+ m_protocol = Socks4;
+ m_bIsIpV6 = false;
+}
+
+KviProxy::KviProxy(const KviProxy &prx)
+{
+ m_szHostname = prx.m_szHostname;
+ m_szIp = prx.m_szIp;
+ m_szUser = prx.m_szUser;
+ m_szPass = prx.m_szPass;
+ m_uPort = prx.m_uPort;
+ m_protocol = prx.m_protocol;
+ m_bIsIpV6 = prx.m_bIsIpV6;
+}
+
+KviProxy::~KviProxy()
+{
+}
+
+static const char * proxy_protocols_table[3]= { "SOCKSv4", "SOCKSv5", "HTTP" };
+
+const char * KviProxy::protocolName() const
+{
+ switch(m_protocol)
+ {
+ case Socks5: return proxy_protocols_table[1]; break;
+ case Http: return proxy_protocols_table[2]; break;
+ default: return proxy_protocols_table[0]; break;
+ }
+
+ return proxy_protocols_table[0];
+}
+
+void KviProxy::setNamedProtocol(const char * proto)
+{
+ if(kvi_strEqualCI(proto,"SOCKSv5"))m_protocol = KviProxy::Socks5;
+ else if(kvi_strEqualCI(proto,"HTTP"))m_protocol = KviProxy::Http;
+ else m_protocol = KviProxy::Socks4;
+}
+
+void KviProxy::getSupportedProtocolNames(QStringList & buf)
+{
+ for(int i=0;i<3;i++)buf.append(QString(proxy_protocols_table[i]));
+}
+
+void KviProxy::normalizeUserAndPass()
+{
+ m_szUser.stripWhiteSpace();
+ m_szPass.stripWhiteSpace();
+}
+
+KviProxyDataBase::KviProxyDataBase()
+{
+ m_pProxyList = new KviPointerList<KviProxy>;
+ m_pProxyList->setAutoDelete(true);
+ m_pCurrentProxy = 0;
+}
+
+KviProxyDataBase::~KviProxyDataBase()
+{
+ delete m_pProxyList;
+}
+
+void KviProxyDataBase::updateProxyIp(const char * proxy,const char * ip)
+{
+ for(KviProxy * prx = m_pProxyList->first();prx;prx = m_pProxyList->next())
+ {
+ if(kvi_strEqualCI(proxy,prx->m_szHostname.ptr()))
+ {
+ prx->m_szIp = ip;
+ return;
+ }
+ }
+}
+
+void KviProxyDataBase::clear()
+{
+ delete m_pProxyList;
+ m_pProxyList = new KviPointerList<KviProxy>;
+ m_pProxyList->setAutoDelete(true);
+ m_pCurrentProxy = 0;
+}
+
+void KviProxyDataBase::load(const char * filename)
+{
+ clear();
+ KviConfig cfg(filename,KviConfig::Read);
+
+ unsigned int nEntries = cfg.readUIntEntry("Entries",0);
+
+ for(unsigned int i=0;i<nEntries;i++)
+ {
+ KviProxy * p = new KviProxy();
+ KviStr tmp(KviStr::Format,"%u_Hostname",i);
+ p->m_szHostname = cfg.readEntry(tmp.ptr(),"proxy.example.net");
+ tmp.sprintf("%u_Port",i);
+ p->m_uPort = cfg.readUIntEntry(tmp.ptr(),7000);
+ tmp.sprintf("%u_Ip",i);
+ p->m_szIp = cfg.readEntry(tmp.ptr(),"");
+ tmp.sprintf("%u_User",i);
+ p->m_szUser = cfg.readEntry(tmp.ptr(),"");
+ tmp.sprintf("%u_Pass",i);
+ p->m_szPass = cfg.readEntry(tmp.ptr(),"");
+
+ tmp.sprintf("%u_Protocol",i);
+ KviStr type = cfg.readEntry(tmp.ptr(),"SOCKSv4");
+ p->setNamedProtocol(type.ptr());
+
+ tmp.sprintf("%u_IsIpV6",i);
+ p->m_bIsIpV6 = cfg.readBoolEntry(tmp.ptr(),false);
+ tmp.sprintf("%u_Current",i);
+ if(cfg.readBoolEntry(tmp.ptr(),false))m_pCurrentProxy = p;
+ m_pProxyList->append(p);
+ }
+
+ if(!m_pCurrentProxy)m_pCurrentProxy = m_pProxyList->first();
+}
+
+void KviProxyDataBase::save(const char * filename)
+{
+ KviConfig cfg(filename,KviConfig::Write);
+
+ cfg.clear();
+
+ cfg.writeEntry("Entries",m_pProxyList->count());
+
+
+ int i=0;
+
+ for(KviProxy * p=m_pProxyList->first();p;p=m_pProxyList->next())
+ {
+ KviStr tmp(KviStr::Format,"%u_Hostname",i);
+ cfg.writeEntry(tmp.ptr(),p->m_szHostname.ptr());
+ tmp.sprintf("%u_Port",i);
+ cfg.writeEntry(tmp.ptr(),p->m_uPort);
+ tmp.sprintf("%u_Ip",i);
+ cfg.writeEntry(tmp.ptr(),p->m_szIp.ptr());
+ tmp.sprintf("%u_User",i);
+ cfg.writeEntry(tmp.ptr(),p->m_szUser.ptr());
+ tmp.sprintf("%u_Pass",i);
+ cfg.writeEntry(tmp.ptr(),p->m_szPass.ptr());
+
+ tmp.sprintf("%u_Protocol",i);
+ KviStr type;
+ switch(p->m_protocol)
+ {
+ case KviProxy::Socks5: type = "SOCKSv5"; break;
+ case KviProxy::Http: type = "HTTP"; break;
+ default: type = "SOCKSv4"; break;
+ }
+ cfg.writeEntry(tmp.ptr(),type.ptr());
+
+ tmp.sprintf("%u_IsIpV6",i);
+ cfg.writeEntry(tmp.ptr(),p->m_bIsIpV6);
+ tmp.sprintf("%u_Current",i);
+ if(m_pCurrentProxy == p)cfg.writeEntry(tmp.ptr(),true);
+ i++;
+ }
+}
diff --git a/src/kvilib/ext/kvi_proxydb.h b/src/kvilib/ext/kvi_proxydb.h
new file mode 100644
index 00000000..92fa2c44
--- /dev/null
+++ b/src/kvilib/ext/kvi_proxydb.h
@@ -0,0 +1,86 @@
+#ifndef _KVI_PROXYDB_H_
+#define _KVI_PROXYDB_H_
+
+//
+// File : kvi_proxydb.h
+// Creation date : Sat Jul 22 2000 18:19:01 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_settings.h"
+
+#include "kvi_string.h"
+#include "kvi_inttypes.h"
+#include "kvi_pointerlist.h"
+#include <qstringlist.h>
+
+class KVILIB_API KviProxy
+{
+public:
+ enum Protocol { Socks4 , Socks5 , Http };
+ KviProxy();
+ KviProxy(const KviProxy &prx);
+ ~KviProxy();
+public:
+ KviStr m_szHostname;
+ KviStr m_szIp;
+ KviStr m_szPass;
+ KviStr m_szUser;
+ kvi_u32_t m_uPort;
+ Protocol m_protocol;
+ bool m_bIsIpV6;
+public:
+ bool isIpV6() const { return m_bIsIpV6; };
+ Protocol protocol() const { return m_protocol; };
+ const char * protocolName() const;
+ void setNamedProtocol(const char * proto);
+ kvi_u32_t port() const { return m_uPort; };
+ const char * user() const { return m_szUser.ptr(); };
+ const char * pass() const { return m_szPass.ptr(); };
+ const char * ip() const { return m_szIp.ptr(); };
+ const char * hostname() const { return m_szHostname.ptr(); };
+ void normalizeUserAndPass();
+ bool hasPass() const { return m_szPass.hasData(); };
+ bool hasUser() const { return m_szUser.hasData(); };
+ unsigned int passLen() const { return (unsigned int)m_szPass.len(); };
+ unsigned int userLen() const { return (unsigned int)m_szUser.len(); };
+ static void getSupportedProtocolNames(QStringList & buf);
+};
+
+
+class KVILIB_API KviProxyDataBase
+{
+public:
+ KviProxyDataBase();
+ ~KviProxyDataBase();
+private:
+ KviPointerList<KviProxy> * m_pProxyList;
+ KviProxy * m_pCurrentProxy;
+public:
+ void clear();
+ KviPointerList<KviProxy> * proxyList(){ return m_pProxyList; };
+ KviProxy * currentProxy(){ return m_pCurrentProxy; };
+ void updateProxyIp(const char * proxy,const char * ip);
+ void setCurrentProxy(KviProxy * prx){ m_pCurrentProxy = prx; };
+ void insertProxy(KviProxy * prx){ m_pProxyList->append(prx); };
+ void load(const char * filename);
+ void save(const char * filename);
+};
+
+#endif //_KVI_PROXYDB_H_
diff --git a/src/kvilib/ext/kvi_regchan.cpp b/src/kvilib/ext/kvi_regchan.cpp
new file mode 100644
index 00000000..a26c5969
--- /dev/null
+++ b/src/kvilib/ext/kvi_regchan.cpp
@@ -0,0 +1,181 @@
+//=============================================================================
+//
+// File : kvi_regchan.cpp
+// Creation date : Sat Jun 29 01:01:16 2002 GMT by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2001-2007 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+//=============================================================================
+
+#define __KVILIB__
+
+#include "kvi_regchan.h"
+#include "kvi_config.h"
+#include "kvi_qstring.h"
+
+KviRegisteredChannel::KviRegisteredChannel(const KviStr &name,const KviStr &netmask)
+{
+ m_szName = name;
+ m_szNetMask = netmask;
+ m_pPropertyDict = new KviPointerHashTable<const char *,KviStr>(7,false,true);
+ m_pPropertyDict->setAutoDelete(true);
+}
+
+KviRegisteredChannel::~KviRegisteredChannel()
+{
+ delete m_pPropertyDict;
+}
+
+
+
+KviRegisteredChannelDataBase::KviRegisteredChannelDataBase()
+{
+ m_pChannelDict = new KviPointerHashTable<const char *,KviRegisteredChannelList>(17,false,true);
+ m_pChannelDict->setAutoDelete(true);
+}
+
+KviRegisteredChannelDataBase::~KviRegisteredChannelDataBase()
+{
+ delete m_pChannelDict;
+}
+
+void KviRegisteredChannelDataBase::load(const char * filename)
+{
+ KviConfig cfg(filename,KviConfig::Read);
+ m_pChannelDict->clear();
+ KviConfigIterator it(*(cfg.dict()));
+ while(KviConfigGroup * d = it.current())
+ {
+ KviStr szMask = it.currentKey();
+ KviStr szChan = szMask.leftToLast('@');
+ szMask.cutToLast('@');
+ KviRegisteredChannel * c = new KviRegisteredChannel(szChan,szMask);
+ add(c);
+ KviConfigGroupIterator sit(*d);
+ while(QString * s = sit.current())
+ {
+ c->setProperty(KviQString::toUtf8(sit.currentKey()).data(),new KviStr(*s));
+ ++sit;
+ }
+ ++it;
+ }
+}
+
+void KviRegisteredChannelDataBase::save(const char * filename)
+{
+ KviConfig cfg(filename,KviConfig::Write);
+ cfg.clear();
+
+ KviPointerHashTableIterator<const char *,KviRegisteredChannelList> it(*m_pChannelDict);
+ while(KviRegisteredChannelList * l = it.current())
+ {
+ for(KviRegisteredChannel * c = l->first();c;c = l->next())
+ {
+ KviStr szGrp(KviStr::Format,"%s@%s",c->name().ptr(),c->netMask().ptr());
+ cfg.setGroup(szGrp.ptr());
+ KviPointerHashTableIterator<const char *,KviStr> pit(*(c->propertyDict()));
+ while(KviStr * s = pit.current())
+ {
+ cfg.writeEntry(pit.currentKey(),s->ptr());
+ ++pit;
+ }
+ }
+ ++it;
+ }
+}
+
+KviRegisteredChannel * KviRegisteredChannelDataBase::find(const char * name,const char * net)
+{
+ KviRegisteredChannelList * l = m_pChannelDict->find(name);
+ if(!l)return 0;
+ for(KviRegisteredChannel * c = l->first();c;c = l->next())
+ {
+ if(kvi_matchString(c->netMask().ptr(),net))return c;
+ }
+
+ return 0;
+}
+
+KviRegisteredChannel * KviRegisteredChannelDataBase::findExact(const char * name,const char * netmask)
+{
+ KviRegisteredChannelList * l = m_pChannelDict->find(name);
+ if(!l)return 0;
+ for(KviRegisteredChannel * c = l->first();c;c = l->next())
+ {
+ if(kvi_strEqualCI(c->netMask().ptr(),netmask))return c;
+ }
+ return 0;
+}
+
+void KviRegisteredChannelDataBase::remove(KviRegisteredChannel * c)
+{
+ KviRegisteredChannelList * l = m_pChannelDict->find(c->name().ptr());
+ if(!l)return;
+ for(KviRegisteredChannel * ch = l->first();ch;ch = l->next())
+ {
+ if(ch == c)
+ {
+ if(l->count() <= 1)
+ {
+ m_pChannelDict->remove(c->name().ptr());
+ } else {
+ l->removeRef(c);
+ }
+ return;
+ }
+ }
+}
+
+
+void KviRegisteredChannelDataBase::add(KviRegisteredChannel * c)
+{
+ KviRegisteredChannel * old = findExact(c->name().ptr(),c->netMask().ptr());
+ if(old)
+ {
+ KviPointerHashTableIterator<const char *,KviStr> pit(*(old->propertyDict()));
+ while(KviStr *s = pit.current())
+ {
+ if(!c->property(pit.currentKey()))
+ c->setProperty(pit.currentKey(),new KviStr(*s));
+ ++pit;
+ }
+ remove(old);
+ }
+ KviRegisteredChannelList * l = m_pChannelDict->find(c->name().ptr());
+ if(!l)
+ {
+ l = new KviRegisteredChannelList;
+ l->setAutoDelete(true);
+ m_pChannelDict->insert(c->name().ptr(),l);
+ }
+ // insert where there are less wildcards
+ int o = c->netMask().occurences('*');
+ int idx = 0;
+ for(KviRegisteredChannel * rc = l->first();rc;rc = l->next())
+ {
+ if(rc->netMask().occurences('*') > o)
+ {
+ // the existing has more wildcards , insert here!
+ l->insert(idx,c);
+ return;
+ }
+ idx++;
+ }
+ l->append(c);
+}
+
diff --git a/src/kvilib/ext/kvi_regchan.h b/src/kvilib/ext/kvi_regchan.h
new file mode 100644
index 00000000..f447c313
--- /dev/null
+++ b/src/kvilib/ext/kvi_regchan.h
@@ -0,0 +1,74 @@
+#ifndef _KVI_REGCHAN_H_
+#define _KVI_REGCHAN_H_
+//=============================================================================
+//
+// File : kvi_regchan.h
+// Creation date : Sat Jun 29 01:01:15 2002 GMT by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2001-2007 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_settings.h"
+#include "kvi_heapobject.h"
+#include "kvi_string.h"
+#include "kvi_pointerlist.h"
+
+#include "kvi_pointerhashtable.h"
+
+class KVILIB_API KviRegisteredChannel : public KviHeapObject
+{
+ friend class KviRegisteredChannelDataBase;
+public:
+ KviRegisteredChannel(const KviStr &name,const KviStr &netmask);
+ ~KviRegisteredChannel();
+protected:
+ KviStr m_szName;
+ KviStr m_szNetMask;
+ KviPointerHashTable<const char *,KviStr> * m_pPropertyDict;
+public:
+ KviPointerHashTable<const char *,KviStr> * propertyDict(){ return m_pPropertyDict; };
+ const KviStr & name(){ return m_szName; };
+ const KviStr & netMask(){ return m_szNetMask; };
+ KviStr * property(const char * name){ return m_pPropertyDict->find(name); };
+ // val must be allocated with NEW!
+ void setProperty(const char * name,KviStr * val){ m_pPropertyDict->replace(name,val); };
+ void removeProperty(const char * name){ m_pPropertyDict->remove(name); };
+};
+
+typedef KVILIB_API KviPointerList<KviRegisteredChannel> KviRegisteredChannelList;
+
+class KVILIB_API KviRegisteredChannelDataBase
+{
+public:
+ KviRegisteredChannelDataBase();
+ ~KviRegisteredChannelDataBase();
+protected:
+ KviPointerHashTable<const char *,KviRegisteredChannelList> * m_pChannelDict;
+public:
+ KviPointerHashTable<const char *,KviRegisteredChannelList> * channelDict(){ return m_pChannelDict; };
+ KviRegisteredChannel * find(const char * name,const char * net);
+ KviRegisteredChannel * findExact(const char * name,const char * netmask);
+ void remove(KviRegisteredChannel * c);
+ void add(KviRegisteredChannel * c);
+ void load(const char * filename);
+ void save(const char * filename);
+};
+
+
+#endif //_KVI_REGCHAN_H_
diff --git a/src/kvilib/ext/kvi_regusersdb.cpp b/src/kvilib/ext/kvi_regusersdb.cpp
new file mode 100644
index 00000000..6d36c975
--- /dev/null
+++ b/src/kvilib/ext/kvi_regusersdb.cpp
@@ -0,0 +1,743 @@
+//=================================================================================================
+//
+// File : kvi_regusersdb.cpp
+// Creation date : Sat Sep 09 2000 15:46:12 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2000-2004 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+//=================================================================================================
+
+
+#define __KVILIB__
+
+#include "kvi_debug.h"
+
+#define _KVI_REGUSERDB_CPP_
+#include "kvi_regusersdb.h"
+
+#include "kvi_config.h"
+#include "kvi_locale.h"
+
+/*
+ @doc: registered_users
+ @title:
+ Registered users
+ @type:
+ generic
+ @short:
+ Registration of users in KVIrc
+ @keyterms:
+ registered users, registration mask, registered user properties,
+ user properties, notify property, avatar property
+ @body:
+ [big]Introduction[/big][br]
+ The "registered user database" is basically a set of users with associated
+ [doc:irc_masks]irc-masks[/doc] and properties.[br]
+ It is used to recognize users on IRC and associate properties to them.[br]
+ This works more or less like the IRC ban list, K-Line list, or invite list.[br]
+ [big]User entry[/big][br]
+ A registered user database entry is identified by an [b]unique[/b] name.[br]
+ It may be the nickname of the user that you want to match, or the real name (if you know it)
+ or any other string (even with spaces). The name is an "internal identifier" for the user entry:
+ each name maps to a single entry and each entry has a single name.[br]
+ Each entry has a set of registration [doc:irc_masks]irc-masks[/doc]: these masks
+ are used to recognize the user on irc.[br]
+ [br]
+ [big]Registration masks[/big][br]
+ The masks have the common IRC mask format: [b]<nick>!<user>@<host>[/b][br]
+ The masks may contain '*' and '?' wildcards that match any portion of text.[br]
+ [b]*!*@*[/b][br]
+ [b]Pragma!*@*[/b][br]
+ [b]*!~daemon@*[/b][br]
+ [b]Pragma!*daemon@*.it[/b][br]
+ [b]Pragma!?daemon@some*.it[/b][br]
+ [b]Pragma!~daemon@some.host.it[/b][br]
+ Are examples of valid registration masks.[br]
+ The masks with wildcards can actually match more than a single user.[br]
+ For example the mask *!root@*.host.com will match all the users
+ having root as username and coming from the host.com domain.[br]
+ For this reason putting wildcards in nicknames could become a problem
+ if not used carefully (but may also be used to achieve interesting tricks).[br]
+ If you don't use wildcards in nicknames you are sure that
+ in a single irc connection , a mask will always refer to a single user.[br]
+ You will commonly use the following format:[br]
+ <nick>!*<username>@*.<host>.<top>[br]
+ or[br]
+ <nick>!*<username>@<number>.<number>.<number>.*[br]
+ In this way you can be 95% sure that the mask will really match the correct user.[br]
+ [br]
+ [big]Example of registration and lookups[/big]
+ Assume that you want to registere a friend of yours: Derek Riggs.[br]
+ Derek often uses "Eddie" as his nickname
+ "stranger" as username and has a dial-up connection that makes his IP address appear as
+ <variable-number>.somewhere.in.time.org.[br]
+ You will add an entry with name "Derek Riggs" and a registration mask like the following:
+ Eddie!stranger@*.somewhere.in.time.org.[br]
+ If the IRC servers keep adding strange characters ([doc:irc_masks]prefixes[/doc]) at the beginning of his username you may use
+ Eddie!*stranger@*.somewhere.in.time.org.[br]
+ If Eddie also often connects from the wasted.years.org domain and gets 'eddie' as username there, you might add a second registration mask as follows:
+ Eddie!*eddie@*.wasted.years.org.[br]
+ An alternative could be use only one mask with *.org as domain and allow any username (Eddie!*@*.org) but this
+ could become dangerous since it could match the users that you don't want to.[br]
+ On the other hand, if you dislike the users with the nickname Eddie that come from .org
+ and you're implementing an auto-kick system, the correct mask to register is "Eddie!*@*.org".[br]
+ [br]
+ KVirc ties to be smart , and always find the most correct match for an user:
+ If you have two masks registered: Pragma!*xor@*.myisp.it and *!*@*.myisp.it,
+ kvirc will match Pragma!~xor@233-dyn.myisp.it with the first one even if the second
+ one matches too; the firs one is a best match.[br]
+ [br]
+ [big]Properties[/big][br]
+ A registered user has an (eventually empty) set of properties
+ defined by name/value pairs. (In versions prior to 3.0.0 flags were used instead,
+ but revealed to be insufficient).[br]
+ KVirc recognizes some of these proprietes and associates semantic actions to it; other properties
+ are left for scripting extension. Property names are case insensitive.[br]
+ One of the recognized properties is the "[doc:notify_list]notify[/doc]" property.
+ When an user is found to have this property set to a special value
+ KVIrc will attempt to track the user presence on IRC.
+ Another one is the [doc:avatar]avatar[/doc] property. Its value should be the
+ name of the "default" [doc:avatar]avatar image file[/doc] for the specified user.[br]
+ The "ignore" property should be set to "1" (or "true") for users that have to be ignored (:D).[br]
+ [br]
+ [big]The interface to the database[/big][br]
+ The [module:reguser]reguser module[/module] is the interface to the "registered users database".[br]
+ It provides a set of commands for adding and removing masks and manipulating properties.[br]
+*/
+
+//============================================================================================================
+//
+// KviRegisteredMask
+//
+
+KVILIB_API KviRegisteredUserDataBase* g_pRegisteredUserDataBase = 0;
+
+KviRegisteredMask::KviRegisteredMask(KviRegisteredUser * u,KviIrcMask * m)
+{
+ m_pUser = u;
+ m_pMask = m;
+ m_iMaskNonWildChars = m_pMask->nonWildChars();
+}
+
+//============================================================================================================
+//
+// KviRegisteredUser
+//
+
+
+KviRegisteredUser::KviRegisteredUser(const QString & name)
+{
+ m_iIgnoreFlags =0;
+ m_bIgnoreEnabled=false;
+ m_szName = name;
+ m_pPropertyDict = 0;
+ m_pMaskList = new KviPointerList<KviIrcMask>;
+ m_pMaskList->setAutoDelete(true);
+}
+
+KviRegisteredUser::~KviRegisteredUser()
+{
+ if(m_pPropertyDict)delete m_pPropertyDict;
+ delete m_pMaskList;
+}
+
+bool KviRegisteredUser::isIgnoreEnabledFor(IgnoreFlags flag)
+{
+ if(!m_bIgnoreEnabled) return false;
+ return m_iIgnoreFlags & flag;
+}
+
+KviIrcMask * KviRegisteredUser::findMask(const KviIrcMask &mask)
+{
+ for(KviIrcMask * m = m_pMaskList->first();m;m = m_pMaskList->next())
+ {
+ if(*m == mask)return m;
+ }
+ return 0;
+}
+
+bool KviRegisteredUser::addMask(KviIrcMask * mask)
+{
+ if(findMask(*mask))
+ {
+ delete mask;
+ mask = 0;
+ return false;
+ }
+ m_pMaskList->append(mask);
+ return true;
+}
+
+bool KviRegisteredUser::removeMask(KviIrcMask * mask)
+{
+ if(!mask)return false;
+ return m_pMaskList->removeRef(mask);
+}
+
+bool KviRegisteredUser::matches(const KviIrcMask &mask)
+{
+ for(KviIrcMask * m = m_pMaskList->first();m;m = m_pMaskList->next())
+ {
+ if(m->matches(mask))return true;
+ }
+ return false;
+}
+
+bool KviRegisteredUser::matchesFixed(const KviIrcMask &mask)
+{
+ for(KviIrcMask * m = m_pMaskList->first();m;m = m_pMaskList->next())
+ {
+ if(m->matchesFixed(mask))return true;
+ }
+ return false;
+}
+
+bool KviRegisteredUser::matchesFixed(const QString & nick,const QString & user,const QString & host)
+{
+ for(KviIrcMask * m = m_pMaskList->first();m;m = m_pMaskList->next())
+ {
+ if(m->matchesFixed(nick,user,host))return true;
+ }
+ return false;
+}
+
+void KviRegisteredUser::setProperty(const QString &name,bool value)
+{
+ setProperty(name,value ? QString("true") : QString("false"));
+}
+
+void KviRegisteredUser::setProperty(const QString & name,const QString & value)
+{
+ if(!value.isEmpty())
+ {
+ if(!m_pPropertyDict)
+ {
+ m_pPropertyDict = new KviPointerHashTable<QString,QString>(7,false);
+ m_pPropertyDict->setAutoDelete(true);
+ }
+#ifdef COMPILE_USE_QT4
+ QString * val = new QString(value.trimmed());
+#else
+ QString * val = new QString(value.stripWhiteSpace());
+#endif
+ if(!val->isEmpty())
+ {
+ m_pPropertyDict->replace(name,val);
+ } else {
+ delete val;
+ val = 0;
+ }
+ } else {
+ if(m_pPropertyDict)m_pPropertyDict->remove(name);
+ }
+}
+
+bool KviRegisteredUser::getProperty(const QString & name,QString &value)
+{
+ if(!m_pPropertyDict)return false;
+ if(name.isEmpty()) return false;
+ QString * pValue = m_pPropertyDict->find(name);
+ if(pValue)value = *pValue;
+ else return false;
+ return true;
+}
+
+const QString & KviRegisteredUser::getProperty(const QString & name)
+{
+ if(!m_pPropertyDict)return KviQString::empty;
+ if(name.isEmpty())return KviQString::empty;
+ QString * pValue = m_pPropertyDict->find(name);
+ if(pValue)return *pValue;
+ return KviQString::empty;
+}
+
+bool KviRegisteredUser::getBoolProperty(const QString & name,bool def)
+{
+ if(!m_pPropertyDict)return def;
+ if(name.isEmpty()) return def;
+ QString * pValue = m_pPropertyDict->find(name);
+ if(pValue)
+ {
+ // be flexible , allow more "true" values (pragma)
+ if(KviQString::equalCS(*pValue,"1"))return true;
+ if(KviQString::equalCI(*pValue,"true"))return true;
+ if(KviQString::equalCI(*pValue,"yes"))return true;
+ //if(KviQString::equalCI(*pValue,"yeah"))return true;
+ //if(KviQString::equalCI(*pValue,"sure"))return true;
+ //if(KviQString::equalCI(*pValue,"sureashell"))return true;
+ }
+ return def;
+}
+
+//============================================================================================================
+//
+// KviRegisteredUserGroup
+//
+
+KviRegisteredUserGroup::KviRegisteredUserGroup(const QString &name)
+{
+ setName(name);
+}
+
+KviRegisteredUserGroup::~KviRegisteredUserGroup()
+{
+}
+
+
+//============================================================================================================
+//
+// KviRegisteredUserDb
+//
+
+KviRegisteredUserDataBase::KviRegisteredUserDataBase()
+{
+ m_pUserDict = new KviPointerHashTable<QString,KviRegisteredUser>(31,false); // do not copy keys
+ m_pUserDict->setAutoDelete(true);
+
+ m_pWildMaskList = new KviRegisteredMaskList;
+ m_pWildMaskList->setAutoDelete(true);
+
+ m_pMaskDict = new KviPointerHashTable<QString,KviRegisteredMaskList>(49,false); // copy keys here!
+ m_pMaskDict->setAutoDelete(true);
+
+ m_pGroupDict = new KviPointerHashTable<QString,KviRegisteredUserGroup>(5,false); // copy keys here!
+ m_pGroupDict->setAutoDelete(true);
+}
+
+KviRegisteredUserDataBase::~KviRegisteredUserDataBase()
+{
+ emit(databaseCleared());
+ delete m_pUserDict;
+ delete m_pWildMaskList;
+ delete m_pMaskDict;
+ delete m_pGroupDict;
+}
+
+KviRegisteredUser * KviRegisteredUserDataBase::addUser(const QString & name)
+{
+ if(name.isEmpty()) return false;
+ if(m_pUserDict->find(name))return 0;
+ KviRegisteredUser * u = new KviRegisteredUser(name);
+ m_pUserDict->replace(u->name(),u); //u->name() because we're NOT copying keys!
+ emit(userAdded(name));
+ return u;
+}
+
+KviRegisteredUserGroup * KviRegisteredUserDataBase::addGroup(const QString & name)
+{
+ if(name.isEmpty()) return false;
+ if(m_pGroupDict->find(name))return 0;
+ KviRegisteredUserGroup * pGroup = new KviRegisteredUserGroup(name);
+ m_pGroupDict->replace(pGroup->name(),pGroup); //u->name() because we're NOT copying keys!
+ return pGroup;
+}
+
+KviRegisteredUser * KviRegisteredUserDataBase::getUser(const QString & name)
+{
+ if(name.isEmpty()) return 0;
+ KviRegisteredUser * u = m_pUserDict->find(name);
+ if(!u)
+ {
+ u = new KviRegisteredUser(name);
+ m_pUserDict->replace(u->name(),u); //u->name() because we're NOT copying keys!
+ }
+ return u;
+}
+
+static void append_mask_to_list(KviRegisteredMaskList *l,KviRegisteredUser *u,KviIrcMask *mask)
+{
+ KviRegisteredMask * newMask = new KviRegisteredMask(u,mask);
+ int idx = 0;
+ for(KviRegisteredMask * m = l->first();m;m = l->next())
+ {
+ if(m->nonWildChars() < newMask->nonWildChars())
+ {
+ l->insert(idx,newMask);
+ return;
+ }
+ idx++;
+ }
+ l->append(newMask);
+}
+
+KviRegisteredUser * KviRegisteredUserDataBase::addMask(KviRegisteredUser * u,KviIrcMask * mask)
+{
+ if(!u || !mask) return 0;
+ __range_valid(u == m_pUserDict->find(u->name()));
+
+ KviRegisteredMaskList * l;
+ if(mask->hasWildNick())
+ {
+ for(KviRegisteredMask * m = m_pWildMaskList->first();m;m = m_pWildMaskList->next())
+ {
+ if(*(m->mask()) == *mask)
+ {
+ delete mask;
+ mask = 0;
+ return m->user();
+ }
+ }
+ // not found ...ok... add it
+ // masks with more info go first in the list
+ l = m_pWildMaskList;
+ } else {
+ l = m_pMaskDict->find(mask->nick());
+ if(l)
+ {
+ // FIXME: #warning "Here we could compare the host and username only: nick matches for sure"
+ for(KviRegisteredMask * m = l->first();m;m = l->next())
+ {
+ if(*(m->mask()) == *mask)
+ {
+ delete mask;
+ mask = 0;
+ return m->user();
+ }
+ }
+ // not found ...ok... add it
+ } else {
+ // not found ...ok... add it
+ // this is the first mask in the list
+ l = new KviRegisteredMaskList;
+ l->setAutoDelete(true);
+ if(!u->addMask(mask))
+ {
+ debug(" Ops...got an incoherent regusers action...recovered ?");
+ delete l;
+ l = 0;
+ } else {
+ append_mask_to_list(l,u,mask);
+ m_pMaskDict->insert(mask->nick(),l);
+ }
+ return 0;
+ }
+ }
+ // Ok...add it
+ if(!u->addMask(mask))
+ {
+ debug("ops...got an incoherent regusers action...recovered ?");
+ return 0; // ops...already there ?
+ }
+ append_mask_to_list(l,u,mask);
+ return 0;
+}
+
+void KviRegisteredUserDataBase::copyFrom(KviRegisteredUserDataBase * db)
+{
+ m_pUserDict->clear();
+ m_pWildMaskList->clear();
+ m_pMaskDict->clear();
+ m_pGroupDict->clear();
+ emit(databaseCleared());
+
+ KviPointerHashTableIterator<QString,KviRegisteredUser> it(*(db->m_pUserDict));
+
+ while(KviRegisteredUser * theCur = it.current())
+ {
+ KviRegisteredUser * u = getUser(theCur->name());
+ // copy masks
+ KviPointerList<KviIrcMask> * l = theCur->maskList();
+ for(KviIrcMask * m=l->first();m;m = l->next())
+ {
+ KviIrcMask * m2 = new KviIrcMask(*m);
+ addMask(u,m2);
+ }
+ // copy properties
+ KviPointerHashTable<QString,QString> * pd = theCur->propertyDict();
+ if(pd)
+ {
+ KviPointerHashTableIterator<QString,QString> pdi(*pd);
+ while(pdi.current())
+ {
+ u->setProperty(pdi.currentKey(),*(pdi.current()));
+ ++pdi;
+ }
+ }
+ u->m_iIgnoreFlags=theCur->m_iIgnoreFlags;
+ u->m_bIgnoreEnabled=theCur->m_bIgnoreEnabled;
+ u->setGroup(theCur->group());
+ ++it;
+ }
+
+ KviPointerHashTableIterator<QString,KviRegisteredUserGroup> git(*db->m_pGroupDict);
+ while(git.current())
+ {
+ addGroup(git.currentKey());
+ ++git;
+ }
+}
+
+
+bool KviRegisteredUserDataBase::removeUser(const QString & name)
+{
+ if(name.isEmpty()) return false;
+ KviRegisteredUser * u = m_pUserDict->find(name);
+ if(!u)return false;
+ while(KviIrcMask * mask = u->maskList()->first())
+ {
+ if(!removeMaskByPointer(mask))
+ debug("Ops... removeMaskByPointer(%s) failed ?",KviQString::toUtf8(name).data());
+ }
+ emit(userRemoved(name));
+ m_pUserDict->remove(name);
+ return true;
+}
+bool KviRegisteredUserDataBase::removeGroup(const QString & name)
+{
+ if(name.isEmpty()) return false;
+ m_pGroupDict->remove(name);
+ return true;
+}
+
+bool KviRegisteredUserDataBase::removeMask(const KviIrcMask &mask)
+{
+ // find the mask pointer
+ KviRegisteredMask * m = findExactMask(mask);
+ // and remove it
+ if(m){
+ if(removeMaskByPointer(m->mask()))
+ {
+ return true;
+ }
+ }
+ return 0;
+}
+
+bool KviRegisteredUserDataBase::removeMaskByPointer(KviIrcMask * mask)
+{
+ if(!mask) return 0;
+ if(mask->hasWildNick())
+ {
+ // remove from the wild list
+ for(KviRegisteredMask * m = m_pWildMaskList->first();m;m = m_pWildMaskList->next())
+ {
+ if(m->mask() == mask)
+ {
+ // ok..got it, remove from the list and from the user struct (user struct deletes it!)
+ emit(userChanged(mask->nick()));
+ m->user()->removeMask(mask); // this one deletes m->mask()
+ m_pWildMaskList->removeRef(m); // this one deletes m
+ return true;
+ }
+ }
+ // not found ...opz :)
+ } else {
+ KviRegisteredMaskList * l = m_pMaskDict->find(mask->nick());
+ if(l)
+ {
+ // FIXME: #warning "Here we could compare the host and username only: nick matches for sure"
+ for(KviRegisteredMask * m = l->first();m;m = l->next())
+ {
+ if(m->mask() == mask)
+ {
+ QString nick = mask->nick();
+ emit(userChanged(nick));
+ m->user()->removeMask(mask); // this one deletes m->mask() (or mask)
+ l->removeRef(m); // this one deletes m
+ if(l->count() == 0)m_pMaskDict->remove(nick);
+ return true;
+ }
+ }
+ // not found ...opz
+ }
+ }
+ // not found...
+ return false;
+}
+
+
+
+/*
+KviRegisteredUser * KviRegisteredUserDataBase::findMatchingUser(const KviIrcMask &mask)
+{
+ // first lookup the nickname in the maskDict
+ KviRegisteredMaskList * l = m_pMaskDict->find(mask.nick());
+ if(l)
+ {
+ for(KviRegisteredMask *m = l->first();m;m = l->next())
+ {
+ if(m->mask()->matchesFixed(0,mask.user(),mask.host()))return m->user();
+ }
+ }
+ // not found....lookup the wild ones
+ for(KviRegisteredMask * m = m_pWildMaskList->first();m;m = m_pWildMaskList->next())
+ {
+ if(m->mask()->matchesFixed(mask))return m->user();
+ }
+ return 0; // no match at all
+}
+*/
+KviRegisteredUser * KviRegisteredUserDataBase::findMatchingUser(const QString & nick,const QString &user,const QString & host)
+{
+ KviRegisteredMask * m = findMatchingMask(nick,user,host);
+ if(m)return m->user();
+ return 0; // no match at all
+}
+
+KviRegisteredMask * KviRegisteredUserDataBase::findMatchingMask(const QString & nick,const QString &user,const QString & host)
+{
+ // first lookup the nickname in the maskDict
+ if(nick.isEmpty()) return false;
+ KviRegisteredMaskList * l = m_pMaskDict->find(nick);
+ if(l)
+ {
+ for(KviRegisteredMask *m = l->first();m;m = l->next())
+ {
+ if(m->mask()->matchesFixed(nick,user,host))return m;
+ }
+ }
+ // not found....lookup the wild ones
+ for(KviRegisteredMask * m = m_pWildMaskList->first();m;m = m_pWildMaskList->next())
+ {
+ if(m->mask()->matchesFixed(nick,user,host))return m;
+ }
+ return 0; // no match at all
+}
+
+KviRegisteredUser * KviRegisteredUserDataBase::findUserWithMask(const KviIrcMask &mask)
+{
+ KviRegisteredMask * m = findExactMask(mask);
+ if(m)return m->user();
+ return 0;
+}
+
+KviRegisteredMask * KviRegisteredUserDataBase::findExactMask(const KviIrcMask &mask)
+{
+ // first lookup the nickname in the maskDict
+ if(mask.nick()=="") return 0;
+ KviRegisteredMaskList * l = m_pMaskDict->find(mask.nick());
+ if(l)
+ {
+ for(KviRegisteredMask *m = l->first();m;m = l->next())
+ {
+ if(*(m->mask()) == mask)return m;
+ }
+ }
+ // not found....lookup the wild ones
+ for(KviRegisteredMask * m = m_pWildMaskList->first();m;m = m_pWildMaskList->next())
+ {
+ if(*(m->mask()) == mask)return m;
+ }
+ return 0; // no match at all
+}
+/*
+bool KviRegisteredUserDataBase::isIgnoredUser(const QString & nick,const QString & user,const QString & host)
+{
+ KviRegisteredUser * u = findMatchingUser(nick,user,host);
+ if(u)return u->getBoolProperty("IGNORE");
+ else return false;
+}
+*/
+void KviRegisteredUserDataBase::load(const QString & filename)
+{
+ QString szCurrent;
+ KviConfig cfg(filename,KviConfig::Read);
+
+ KviConfigIterator it(*cfg.dict());
+ while(it.current())
+ {
+ cfg.setGroup(it.currentKey());
+ szCurrent=it.currentKey();
+ if(KviQString::equalCSN("#Group ",szCurrent,7))
+ {
+ szCurrent.remove(0,7);
+ addGroup(szCurrent);
+ } else {
+ KviRegisteredUser * u = addUser(szCurrent);
+
+ if(u)
+ {
+ u->setIgnoreEnabled(cfg.readBoolEntry("IgnoreEnabled",false));
+ u->setIgnoreFlags(cfg.readIntEntry("IgnoreFlags",0));
+ KviConfigGroupIterator sdi(*(it.current()));
+ while(sdi.current())
+ {
+ QString tmp = sdi.currentKey();
+ if(KviQString::equalCSN("prop_",tmp,5))
+ {
+ tmp.remove(0,5);
+ u->setProperty(tmp,*(sdi.current()));
+ } else if(KviQString::equalCSN("mask_",tmp,5))
+ {
+ KviIrcMask * mask = new KviIrcMask(*(sdi.current()));
+ addMask(u,mask);
+ } else if(KviQString::equalCI(tmp,"Group"))
+ {
+ u->setGroup(*(sdi.current()));
+ }
+ ++sdi;
+ }
+ }
+ }
+ ++it;
+ }
+ if(!m_pGroupDict->find(__tr("Default")))
+ addGroup(__tr("Default"));
+}
+
+
+void KviRegisteredUserDataBase::save(const QString & filename)
+{
+ KviConfig cfg(filename,KviConfig::Write);
+ cfg.clear();
+ cfg.preserveEmptyGroups(true);
+
+ KviPointerHashTableIterator<QString,KviRegisteredUser> it(*m_pUserDict);
+
+ while(it.current())
+ {
+ cfg.setGroup(it.current()->name());
+ // Write properties
+ cfg.writeEntry("IgnoreEnabled",it.current()->ignoreEnagled());
+ cfg.writeEntry("IgnoreFlags",it.current()->ignoreFlags());
+ if(it.current()->propertyDict())
+ {
+ KviPointerHashTableIterator<QString,QString> pit(*(it.current()->propertyDict()));
+ while(pit.current())
+ {
+ QString tmp = "prop_";
+ tmp.append(pit.currentKey());
+ cfg.writeEntry(tmp,*(pit.current()));
+ ++pit;
+ }
+ }
+ // Write masks
+ int idx = 0;
+ for(KviIrcMask * m = it.current()->maskList()->first();m;m = it.current()->maskList()->next())
+ {
+ QString tmp;
+ KviQString::sprintf(tmp,"mask_%d",idx);
+ QString mask;
+ m->mask(mask,KviIrcMask::NickUserHost);
+ cfg.writeEntry(tmp,mask);
+ ++idx;
+ }
+ cfg.writeEntry("Group",it.current()->group());
+ ++it;
+ }
+
+ KviPointerHashTableIterator<QString,KviRegisteredUserGroup> git(*m_pGroupDict);
+ QString szTmp;
+ while(git.current())
+ {
+ KviQString::sprintf(szTmp,"#Group %Q",&(git.current()->name()));
+ cfg.setGroup(szTmp);
+ ++git;
+ }
+
+}
diff --git a/src/kvilib/ext/kvi_regusersdb.h b/src/kvilib/ext/kvi_regusersdb.h
new file mode 100644
index 00000000..06152f24
--- /dev/null
+++ b/src/kvilib/ext/kvi_regusersdb.h
@@ -0,0 +1,201 @@
+#ifndef _KVI_REGUSERSDB_H_
+#define _KVI_REGUSERSDB_H_
+//=================================================================================================
+//
+// File : kvi_regusersdb.h
+// Creation date : Sat Sep 09 2000 15:30:56 by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2000-2004 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+//=================================================================================================
+
+//
+// REGISTERED USERS
+//
+// Here we manage users resigered by mask and their (generic!) properties
+//
+
+#include "kvi_settings.h"
+#include "kvi_heapobject.h"
+#include "kvi_qstring.h"
+#include "kvi_ircmask.h"
+#include "kvi_debug.h"
+
+#include "kvi_pointerlist.h"
+#include "kvi_pointerhashtable.h"
+#include <qobject.h>
+
+class KviRegisteredUserDataBase;
+
+#ifndef _KVI_REGUSERDB_CPP_
+ extern KVILIB_API KviRegisteredUserDataBase * g_pRegisteredUserDataBase;
+#endif //!_KVI_REGUSERDB_CPP_
+
+//=================================================================================================
+//
+// KviRegisteredUser
+//
+
+class KVILIB_API KviRegisteredUser : public KviHeapObject
+{
+ friend class KviRegisteredUserDataBase;
+public:
+ enum IgnoreFlags {
+ Channel=1,
+ Query=2,
+ Notice=4,
+ Ctcp=8,
+ Invite=16,
+ Dcc=32
+ };
+
+ KviRegisteredUser(const QString &name);
+ ~KviRegisteredUser();
+private:
+ int m_iIgnoreFlags;
+ bool m_bIgnoreEnabled;
+ QString m_szName;
+ QString m_szGroup;
+ KviPointerHashTable<QString,QString> * m_pPropertyDict; // owned properties
+ KviPointerList<KviIrcMask> * m_pMaskList; // owned masks
+protected:
+ // mask ownership is transferred! (always!) returns false if the mask was already there
+ bool addMask(KviIrcMask * mask);
+ bool removeMask(KviIrcMask * mask);
+ KviIrcMask * findMask(const KviIrcMask &mask);
+public:
+ int ignoreFlags() { return m_iIgnoreFlags; };
+ void setIgnoreFlags(int flags) {m_iIgnoreFlags=flags; };
+ bool ignoreEnagled() { return m_bIgnoreEnabled; };
+ void setIgnoreEnabled(bool enabled) {m_bIgnoreEnabled=enabled;};
+ bool isIgnoreEnabledFor(IgnoreFlags flag);
+
+ const QString &name(){ return m_szName; };
+ bool matches(const KviIrcMask &mask);
+ bool matchesFixed(const KviIrcMask &mask);
+ bool matchesFixed(const QString &nick,const QString &user,const QString &host);
+
+ void setProperty(const QString &name,const QString &value);
+ void setProperty(const QString &name,bool value);
+
+ void setGroup(const QString &name) { m_szGroup=name; };
+ const QString &group(){ return m_szGroup; };
+
+ const QString & getProperty(const QString &name); // returns 0 if the property is not there
+ bool getProperty(const QString &name,QString &value); // returns false if the property is not there
+ bool getBoolProperty(const QString &name,bool def=FALSE); // returns true if the property is there and is true
+ // the propertyDict may be 0!
+ KviPointerHashTable<QString,QString> * propertyDict(){ return m_pPropertyDict; };
+ // this is never zero (but may contain no masks)
+ KviPointerList<KviIrcMask> * maskList(){ return m_pMaskList; };
+};
+
+//============================================================================================================
+//
+// KviRegisteredUserGroup
+//
+
+class KVILIB_API KviRegisteredUserGroup : public KviHeapObject
+{
+ friend class KviRegisteredUserDataBase;
+public:
+ KviRegisteredUserGroup(const QString &name);
+ ~KviRegisteredUserGroup();
+
+ void setName(const QString &name) { m_szName=name; };
+ const QString &name(){ return m_szName; };
+private:
+ QString m_szName;
+};
+//============================================================================================================
+//
+// KviRegisteredMask
+//
+
+class KVILIB_API KviRegisteredMask
+{
+private:
+ KviRegisteredUser * m_pUser; // pointer , not owned!
+ KviIrcMask * m_pMask; // pointer , not owned!
+ int m_iMaskNonWildChars;
+public:
+ KviRegisteredMask(KviRegisteredUser * u,KviIrcMask * m);
+ ~KviRegisteredMask(){};
+public:
+ int nonWildChars(){ return m_iMaskNonWildChars; };
+ KviRegisteredUser * user(){ return m_pUser; };
+ KviIrcMask * mask(){ return m_pMask; };
+};
+
+typedef KviPointerList<KviRegisteredMask> KviRegisteredMaskList;
+
+//=================================================================================================
+//
+// KviRegisteredUsersDb
+//
+// Manages a set of KviRegisteredUser instances stored in the m_pUserDict dictionary
+// The users are identified by masks stored in m_pMaskDict and m_pWildMaskList
+// m_pMaskDict contains lists of non wild-nick KviRegisteredMask that point to users
+// m_pWildMaskList is a list of wild-nick KviRegisteredMask that point to users
+//
+
+class KVILIB_API KviRegisteredUserDataBase : public QObject
+{
+ Q_OBJECT
+public:
+ KviRegisteredUserDataBase();
+ ~KviRegisteredUserDataBase();
+private:
+ KviPointerHashTable<QString,KviRegisteredUser> * m_pUserDict; // unique namespace, owns the objects, does not copy keys
+ KviPointerHashTable<QString,KviRegisteredMaskList> * m_pMaskDict; // owns the objects, copies the keys
+ KviRegisteredMaskList * m_pWildMaskList; // owns the objects
+ KviPointerHashTable<QString,KviRegisteredUserGroup>* m_pGroupDict;
+public:
+ void copyFrom(KviRegisteredUserDataBase * db);
+ KviRegisteredUser * addUser(const QString &name); // returns 0 if already there
+ KviRegisteredUser * getUser(const QString &name); // returns existing or adds
+ bool removeUser(const QString &name);
+ bool removeGroup(const QString &name);
+ KviRegisteredUser * findUserByName(const QString &name){ return m_pUserDict->find(name); };
+ // mask must be allocated on the heap and the ownership is transferred!
+ // returns non zero if there is already an user with this mask (returns the pointer to it!)
+ KviRegisteredUser * addMask(KviRegisteredUser * u,KviIrcMask * mask);
+ bool removeMaskByPointer(KviIrcMask * mask);
+ bool removeMask(const KviIrcMask &mask);
+ KviRegisteredUser * findMatchingUser(const QString &nick,const QString &user,const QString &host);
+ KviRegisteredUser * findUserWithMask(const KviIrcMask &mask);
+ KviRegisteredMask * findExactMask(const KviIrcMask &mask);
+ KviRegisteredMask * findMatchingMask(const QString &nick,const QString &user,const QString &host);
+ //Only used in few places (actually one) of the code, but lot of times;perfect for inlining...
+ //bool isIgnoredUser(const char * nick,const char * user,const char * host);
+ void load(const QString &filename);
+ void save(const QString &filename);
+
+ KviPointerHashTable<QString,KviRegisteredUser> * userDict(){ return m_pUserDict; };
+ KviPointerHashTable<QString,KviRegisteredUserGroup>* groupDict() { return m_pGroupDict; };
+
+ KviRegisteredUserGroup* addGroup(const QString &name);
+signals:
+ void userRemoved(const QString&);
+ void userChanged(const QString&);
+ void userAdded (const QString&);
+ void databaseCleared();
+};
+
+
+#endif //_KVI_REGUSERSDB_H_
diff --git a/src/kvilib/ext/kvi_sharedfiles.cpp b/src/kvilib/ext/kvi_sharedfiles.cpp
new file mode 100644
index 00000000..65ce0d69
--- /dev/null
+++ b/src/kvilib/ext/kvi_sharedfiles.cpp
@@ -0,0 +1,391 @@
+//=============================================================================
+//
+// File : kvi_filetrader.cpp
+// Creation date : Wed Aug 27 2000 10:33:11 CEST by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2007 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+//=============================================================================
+
+#define __KVILIB__
+
+
+#include "kvi_sharedfiles.h"
+
+#include "kvi_config.h"
+#include "kvi_fileutils.h"
+
+#include <qfileinfo.h>
+
+// TODO: Match servers that the file requests come from
+// TODO: Max number of downloads ?
+
+// FIXME: MD5SUM ?
+
+/*
+ @doc: shared_files
+ @title:
+ Sharing files with KVIrc
+ @type:
+ generic
+ @short:
+ Automatically sharing your files with other IRC users
+ @keyterms:
+ file sharing
+ @body:
+ [big]What is this ?[/big]
+ The "file offers" are a simple way to share your files with other IRC users.[br]
+ Basically , you setup an offer by selecting a local file, choosing a "visible name" for it.
+ Remote users will be able to request you the file and download it automatically by
+ issuing a simple DCC GET request.[br]
+ [big]Details[/big]
+ Each offer refers to an existing file on one of your locally mounted file systems.
+ The offer is given a visible name that the remote users will effectively request.
+ To share the file /usr/arch/mp3/SonataArctica_SingInSilence_Live.mp3 you will add a file offer
+ with /usr/arch/mp3/SonataArctica_SingInSilence_Live.mp3 as real file path , something like
+ "SonataArctica_SingInSilence.mp3". A remote user will then request you a DCC GET SonataArctica_SingInSilence.mp3
+ and KVIrc will automatically send the file.[br]
+ Each file offer has an "user mask" that the requesting remote users must match to
+ obtain the file: *!*@* matches any user, Pragma!*@* matches any user with nickname pragma,
+ *!*@*.omnikron.net matches any user coming from the omnikron.net domain.[br]
+ Each offer can have an expire time: the offer will be automatically removed after
+ a defined number of seconds. An expire time of '0' seconds means that the offer should never expire.[br]
+ If you have two file offers with the same name and different file, the remote user can
+ use an additional "size" parameter in the DCC GET request.[br]
+ [big]Security issues[/big]
+ This is a nice but unsecure method of sharing files.[br]
+ The user mask is a good protection but you have to use it properly!.[br]
+ Setting the user mask to Nick!*@* can be easily exploited (just by making an user disconnect
+ in one of the well known ways and then by using his nickname).[br]
+ On the other side, the remote end must know exactly the visible name of the offer to request
+ and noone but you will tell him that name.[br]
+ In sum:[br]
+ Don't share any really important files: this *might* be like putting it on your webpage :D[br]
+ Please don't send complains if someone stoles your /etc/passwd : it is because you have permitted that.[br]
+*/
+
+KviSharedFile::KviSharedFile(const QString &szName,const QString &szAbsPath,const QString &szUserMask,time_t expireTime,unsigned int uFileSize)
+{
+ m_szName = szName;
+ m_szAbsFilePath = szAbsPath;
+ m_szUserMask = szUserMask;
+ m_expireTime = expireTime;
+ m_uFileSize = uFileSize;
+#ifdef COMPILE_USE_QT4
+ // QT4ROX: Because they have finally moved the functionality of QString::contains() to QString::count(), and QString::contains() now does the right job
+ m_uWildCount = m_szUserMask.count('*');
+#else
+ m_uWildCount = m_szUserMask.contains('*');
+#endif
+ m_uNonWildCount = m_szUserMask.length() - m_uWildCount;
+}
+
+KviSharedFile::~KviSharedFile()
+{
+}
+
+
+KviSharedFilesManager::KviSharedFilesManager()
+: QObject()
+{
+ m_pSharedListDict = new KviPointerHashTable<QString,KviSharedFileList>();
+ m_pSharedListDict->setAutoDelete(true);
+ m_pCleanupTimer = new QTimer();
+ connect(m_pCleanupTimer,SIGNAL(timeout()),this,SLOT(cleanup()));
+}
+
+KviSharedFilesManager::~KviSharedFilesManager()
+{
+ if(m_pCleanupTimer->isActive())m_pCleanupTimer->stop();
+ delete m_pCleanupTimer;
+ delete m_pSharedListDict;
+}
+
+void KviSharedFilesManager::cleanup()
+{
+ KviPointerHashTableIterator<QString,KviSharedFileList> it(*m_pSharedListDict);
+ time_t curTime = time(0);
+
+ bool bOtherStuffToCleanup = false;
+ //bool bChanged = false;
+
+ KviPointerList<QString> lDying;
+ lDying.setAutoDelete(true);
+
+ while(KviSharedFileList * l = it.current())
+ {
+ KviPointerList<KviSharedFile> tmp;
+ tmp.setAutoDelete(false);
+ for(KviSharedFile * o = l->first();o;o = l->next())
+ {
+ if(o->expireTime() > 0)
+ {
+ if(((int)o->expireTime()) <= ((int)curTime))
+ {
+ tmp.append(o);
+ //bChanged = true;
+ } else {
+ bOtherStuffToCleanup = true;
+ }
+ }
+ }
+ for(KviSharedFile * fo = tmp.first();fo;fo = tmp.next())
+ {
+ l->removeRef(fo);
+ emit sharedFileRemoved(fo);
+ }
+ if(l->count() == 0)
+ lDying.append(new QString(it.currentKey()));
+
+ ++it;
+ }
+
+ for(QString * pDyingKey = lDying.first();pDyingKey;pDyingKey = lDying.next())
+ m_pSharedListDict->remove(*pDyingKey);
+
+ if(!bOtherStuffToCleanup)m_pCleanupTimer->stop();
+ //if(bChanged)emit sharedFilesChanged();
+}
+
+void KviSharedFilesManager::clear()
+{
+ m_pSharedListDict->clear();
+ emit sharedFilesChanged();
+}
+
+void KviSharedFilesManager::doInsert(KviSharedFileList * l, KviSharedFile * o)
+{
+ int index = 0;
+ for(KviSharedFile * fo =l->first();fo;fo = l->next())
+ {
+ if(o->wildcardCount() > 0)
+ {
+ // the new mask has wildcards... if the current one has none, skip it
+ if(fo->wildcardCount() > 0)
+ {
+ // the one in the list has wildcards too...
+ // the ones with more non-wild chars go first...
+ if(fo->nonWildcardCount() < o->nonWildcardCount())
+ {
+ // ok...the new one has more non-wildcards , insert
+ l->insert(index,o);
+ return;
+ } else {
+ if(o->nonWildcardCount() == fo->nonWildcardCount())
+ {
+ // the same number of non-wildcards
+ // let the number of wildcards decide (it will be eventually equal)
+ if(o->wildcardCount() < fo->wildcardCount())
+ {
+ // the new one has less wildcards... goes first
+ l->insert(index,o);
+ return;
+ } // else the same number of wildcards and non-wildcards...skip
+ } // else the existing one has more non-wildcards...skip
+ }
+ } // else the current has no wildcards...skip
+ } else {
+ // the new mask has no wildcards....
+ if(fo->wildcardCount() > 0)
+ {
+ // current one has wildcards...insert
+ l->insert(index,o);
+ return;
+ }
+ // the current one has no wildcards...
+ // the longer masks go first....
+ if(fo->maskLength() < o->maskLength())
+ {
+ // the current one is shorter than the new one...insert
+ l->insert(index,o);
+ return;
+ } // else current one is longer...skip
+ }
+ index++;
+ }
+ l->append(o);
+}
+
+void KviSharedFilesManager::addSharedFile(KviSharedFile * f)
+{
+ // First find the list
+ KviSharedFileList * l = m_pSharedListDict->find(f->name());
+ if(!l)
+ {
+ l = new KviSharedFileList;
+ l->setAutoDelete(true);
+ m_pSharedListDict->replace(f->name(),l);
+ }
+
+ doInsert(l,f);
+
+ if(((int)f->expireTime()) > 0)
+ {
+ if(!m_pCleanupTimer->isActive())m_pCleanupTimer->start(60000);
+ }
+
+ emit sharedFileAdded(f);
+}
+
+KviSharedFile * KviSharedFilesManager::addSharedFile(const QString &szName,const QString &szAbsPath,const QString &szMask,int timeoutInSecs)
+{
+ QFileInfo inf(szAbsPath);
+ if(inf.exists() && inf.isFile() && inf.isReadable() && (inf.size() > 0))
+ {
+ // First find the list
+ KviSharedFileList * l = m_pSharedListDict->find(szName);
+ if(!l)
+ {
+ l = new KviSharedFileList;
+ l->setAutoDelete(true);
+ m_pSharedListDict->replace(szName,l);
+ }
+
+ // Now insert
+ KviSharedFile * o = new KviSharedFile(szName,szAbsPath,szMask,timeoutInSecs > 0 ? (((int)(time(0))) + timeoutInSecs) : 0,inf.size());
+
+ doInsert(l,o);
+
+ if(((int)o->expireTime()) > 0)
+ {
+ if(!m_pCleanupTimer->isActive())m_pCleanupTimer->start(60000);
+ }
+
+ emit sharedFileAdded(o);
+
+ return o;
+ } else {
+ debug("File %s unreadable: can't add offer",KviQString::toUtf8(szAbsPath).data());
+ return 0;
+ }
+}
+
+KviSharedFile * KviSharedFilesManager::lookupSharedFile(const QString &szName,KviIrcMask * mask,unsigned int uFileSize)
+{
+ KviSharedFileList * l = m_pSharedListDict->find(szName);
+ if(!l)return 0;
+
+ for(KviSharedFile * o = l->first();o;o = l->next())
+ {
+ bool bMatch;
+ if(mask)
+ {
+ KviIrcMask umask(o->userMask());
+ bMatch = mask->matchedBy(umask);
+ } else bMatch = KviQString::equalCS(o->userMask(),"*!*@*");
+ if(bMatch)
+ {
+ if(uFileSize > 0)
+ {
+ if(uFileSize == o->fileSize())return o;
+ } else return o;
+ }
+ }
+
+ return 0;
+}
+bool KviSharedFilesManager::removeSharedFile(const QString &szName,const QString &szMask,unsigned int uFileSize)
+{
+ KviSharedFileList * l = m_pSharedListDict->find(szName);
+ if(!l)return false;
+ for(KviSharedFile * o = l->first();o;o = l->next())
+ {
+ if(KviQString::equalCI(szMask,o->userMask()))
+ {
+ bool bMatch = uFileSize > 0 ? uFileSize == o->fileSize() : true;
+ if(bMatch)
+ {
+ QString save = szName; // <-- szName MAY Be a pointer to o->name()
+ l->removeRef(o);
+ if(l->count() == 0)m_pSharedListDict->remove(save);
+ emit sharedFileRemoved(o);
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+bool KviSharedFilesManager::removeSharedFile(const QString &szName,KviSharedFile * off)
+{
+ KviSharedFileList * l = m_pSharedListDict->find(szName);
+ if(!l)return false;
+ for(KviSharedFile * o = l->first();o;o = l->next())
+ {
+ if(off == o)
+ {
+ QString save = szName; // <-- szName MAY Be a pointer to o->name()
+ l->removeRef(o);
+ if(l->count() == 0)m_pSharedListDict->remove(save);
+ emit sharedFileRemoved(off);
+ return true;
+ }
+ }
+ return false;
+}
+
+
+void KviSharedFilesManager::load(const QString &filename)
+{
+ KviConfig cfg(filename,KviConfig::Read);
+ //cfg.clear();
+ cfg.setGroup("PermanentFileOffers");
+ int num = cfg.readIntEntry("NEntries",0);
+ for(int idx=0;idx<num;idx++)
+ {
+ QString tmp;
+ KviQString::sprintf(tmp,"%dFName",idx);
+ QString szName = cfg.readQStringEntry(tmp,"");
+ KviQString::sprintf(tmp,"%dFilePath",idx);
+ QString szPath = cfg.readQStringEntry(tmp,"");
+ KviQString::sprintf(tmp,"%dUserMask",idx);
+ QString szMask = cfg.readQStringEntry(tmp,"");
+ if(!szMask.isEmpty() && !szPath.isEmpty() && !szName.isEmpty())
+ addSharedFile(szName,szPath,szMask,0);
+ }
+}
+
+void KviSharedFilesManager::save(const QString &filename)
+{
+ KviConfig cfg(filename,KviConfig::Write);
+ cfg.clear();
+ cfg.setGroup("PermanentFileOffers");
+
+ KviPointerHashTableIterator<QString,KviSharedFileList> it(*m_pSharedListDict);
+ int idx = 0;
+ while(KviSharedFileList * l = it.current())
+ {
+ for(KviSharedFile * o = l->first();o;o = l->next())
+ {
+ if(((int)(o->expireTime())) == 0)
+ {
+ QString tmp;
+ KviQString::sprintf(tmp,"%dFName",idx);
+ cfg.writeEntry(tmp,it.currentKey());
+ KviQString::sprintf(tmp,"%dFilePath",idx);
+ cfg.writeEntry(tmp,o->absFilePath());
+ KviQString::sprintf(tmp,"%dUserMask",idx);
+ cfg.writeEntry(tmp,o->userMask());
+ ++idx;
+ }
+ }
+ ++it;
+ }
+ cfg.writeEntry("NEntries",idx);
+}
+
diff --git a/src/kvilib/ext/kvi_sharedfiles.h b/src/kvilib/ext/kvi_sharedfiles.h
new file mode 100644
index 00000000..3a6d2239
--- /dev/null
+++ b/src/kvilib/ext/kvi_sharedfiles.h
@@ -0,0 +1,133 @@
+#ifndef _KVI_FILETRADER_H_
+#define _KVI_FILETRADER_H_
+//=============================================================================
+//
+// File : kvi_filetrader.h
+// Creation date : Wed Aug 27 2000 10:28:51 CEST by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2007 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_settings.h"
+#include "kvi_heapobject.h"
+#include "kvi_string.h"
+#include "kvi_ircmask.h"
+#include "kvi_pointerlist.h"
+#include "kvi_qstring.h"
+
+#include "kvi_pointerhashtable.h"
+
+#include <time.h>
+#include <qtimer.h>
+
+
+class KVILIB_API KviSharedFile : public KviHeapObject
+{
+public:
+ KviSharedFile(const QString &szName,const QString &szAbsPath,const QString &szUserMask,time_t expireTime,unsigned int uFileSize);
+ ~KviSharedFile();
+private:
+ QString m_szName;
+ QString m_szAbsFilePath;
+ time_t m_expireTime;
+ QString m_szUserMask;
+ unsigned int m_uFileSize;
+ unsigned int m_uWildCount;
+ unsigned int m_uNonWildCount;
+public:
+ const QString &name(){ return m_szName; };
+
+ const QString &absFilePath(){ return m_szAbsFilePath; };
+
+ const QString &userMask(){ return m_szUserMask; };
+
+ time_t expireTime(){ return m_expireTime; };
+ bool expires(){ return (m_expireTime != 0); };
+
+ unsigned int fileSize(){ return m_uFileSize; };
+
+ unsigned int wildcardCount(){ return m_uWildCount; };
+ unsigned int nonWildcardCount(){ return m_uNonWildCount; };
+ int maskLength(){ return m_szUserMask.length(); };
+};
+
+
+typedef KviPointerList<KviSharedFile> KviSharedFileList;
+
+
+class KVILIB_API KviSharedFilesManager : public QObject
+{
+ Q_OBJECT
+public:
+ KviSharedFilesManager();
+ ~KviSharedFilesManager();
+private:
+ QTimer * m_pCleanupTimer;
+ KviPointerHashTable<QString,KviSharedFileList> * m_pSharedListDict;
+public:
+ void addSharedFile(KviSharedFile * f);
+ KviSharedFile * addSharedFile(const QString &szName,const QString &szAbsPath,const QString &szMask,int timeoutInSecs);
+ KviSharedFile * lookupSharedFile(const QString &szName,KviIrcMask * mask,unsigned int uFileSize = 0);
+ bool removeSharedFile(const QString &szName,const QString &szMask,unsigned int uFileSize);
+ bool removeSharedFile(const QString &szName,KviSharedFile * off);
+ void load(const QString &filename);
+ void save(const QString &filename);
+ void clear();
+ KviPointerHashTable<QString,KviSharedFileList> * sharedFileListDict(){ return m_pSharedListDict; };
+private:
+ void doInsert(KviSharedFileList * l, KviSharedFile * o);
+private slots:
+ void cleanup();
+signals:
+ void sharedFilesChanged(); // emitted when the list is cleared at once
+ void sharedFileAdded(KviSharedFile * f);
+ void sharedFileRemoved(KviSharedFile * f);
+};
+
+
+/*
+class KviSharedFile
+{
+ KviSharedFile();
+ KviSharedFile(const KviStr &filePath,const KviStr &userMask);
+ ~KviSharedFile();
+protected:
+ KviStr m_szFilePath;
+ KviStr m_szVisibleName;
+ KviStr m_szMd5Sum;
+ KviStr m_szUserMask;
+ unsigned short int m_uWildCount;
+ unsigned short int m_uNonWildCount;
+
+ unsigned int m_uFileSize;
+ time_t m_tExpireTime;
+public:
+ void setFilePath(const KviStr &filePath);
+ void setUserMask(const KviStr &userMask);
+ void setVisibleName(const KviStr &visibleName);
+ void setMd5Sum(const KviStr &md5Sum);
+ void setFileSize(unsigned int uFileSize);
+ void setExpireTime(time_t expireTime);
+ void doNotExpire(){ setExpireTime((time_t)0); };
+
+ void computeMd5Sum();
+};
+*/
+
+#endif //_KVI_FILETRADER_H_
diff --git a/src/kvilib/ext/kvi_stringconversion.cpp b/src/kvilib/ext/kvi_stringconversion.cpp
new file mode 100644
index 00000000..3d0255cc
--- /dev/null
+++ b/src/kvilib/ext/kvi_stringconversion.cpp
@@ -0,0 +1,277 @@
+//=============================================================================
+//
+// File : kvi_stringconversion.cpp
+// Creation date : Thu Oct 20 2000 14:12:21 CEST by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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.
+//
+//=============================================================================
+
+#define __KVILIB__
+
+
+#define _KVI_STRINGCONVERSION_CPP_
+#include "kvi_stringconversion.h"
+
+#include "kvi_qstring.h"
+#include <stdio.h>
+
+QString g_szGlobalDir;
+QString g_szLocalDir;
+
+namespace KviStringConversion
+{
+
+ void init(const QString& szGlobalDir,const QString& szLocalDir)
+ {
+ g_szGlobalDir=szGlobalDir;
+ g_szLocalDir=szLocalDir;
+ }
+
+ void encodePath(QString& buffer)
+ {
+ if(!buffer.isEmpty())
+ {
+ if(!g_szLocalDir.isEmpty())
+ {
+ if(KviQString::find(buffer,g_szLocalDir)==0)
+ {
+ buffer.remove(0,g_szLocalDir.length());
+ buffer.prepend("local://");
+ }
+ }
+ if(!g_szGlobalDir.isEmpty())
+ {
+ if(KviQString::find(buffer,g_szGlobalDir)==0)
+ {
+ buffer.remove(0,g_szGlobalDir.length());
+ buffer.prepend("global://");
+ }
+ }
+ }
+ }
+
+ void decodePath(QString& buffer)
+ {
+ if(!buffer.isEmpty())
+ {
+ if(!g_szLocalDir.isEmpty())
+ {
+ if(KviQString::find(buffer,"local://")==0)
+ {
+ buffer.remove(0,8);
+ buffer.prepend(g_szLocalDir);
+ }
+ }
+ if(!g_szGlobalDir.isEmpty())
+ {
+ if(KviQString::find(buffer,"global://")==0)
+ {
+ buffer.remove(0,9);
+ buffer.prepend(g_szGlobalDir);
+ }
+ }
+ }
+ }
+
+ void encodePath(QStringList& buffer)
+ {
+ for ( QStringList::Iterator it = buffer.begin(); it != buffer.end(); ++it )
+ {
+ encodePath(*it);
+ }
+ }
+
+ void decodePath(QStringList& buffer)
+ {
+ for ( QStringList::Iterator it = buffer.begin(); it != buffer.end(); ++it )
+ {
+ decodePath(*it);
+ }
+ }
+
+ void toString(const bool bValue,QString &buffer)
+ {
+ buffer = bValue ? '1' : '0';
+ }
+
+ bool fromString(const QString & szValue,bool &buffer)
+ {
+ if(szValue.isEmpty())buffer = false;
+ else buffer = !((KviQString::equalCS(szValue,"0")) || (KviQString::equalCI(szValue,"false")));
+ return true;
+ }
+
+ void toString(const int iValue,QString &buffer)
+ {
+ buffer.setNum(iValue);
+ }
+
+ bool fromString(const QString &szValue,int &buffer)
+ {
+ bool bOk;
+ buffer = szValue.toInt(&bOk);
+ return bOk;
+ }
+
+ void toString(const unsigned int uValue,QString &buffer)
+ {
+ buffer.setNum(uValue);
+ }
+
+ bool fromString(const QString & szValue,unsigned int &buffer)
+ {
+ bool bOk;
+ buffer= szValue.toUInt(&bOk);
+ return bOk;
+ }
+
+ void toString(const QRect &rValue,QString &buffer)
+ {
+ buffer.sprintf("%d,%d,%d,%d",rValue.x(),rValue.y(),rValue.width(),rValue.height());
+ }
+
+ bool fromString(const QString & szValue,QRect &buffer)
+ {
+ KviQCString tmp = KviQString::toUtf8(szValue);
+ const char * c = tmp.data();
+ if(!c)return false;
+ int l,t,w,h;
+ if(sscanf(c,"%d,%d,%d,%d",&l,&t,&w,&h) != 4)return false;
+ buffer.setRect(l,t,w,h);
+ return true;
+ }
+
+ void toString(const QString &szValue,QString &buffer)
+ {
+ buffer = szValue;
+ }
+
+ bool fromString(const QString & szValue,QString &buffer)
+ {
+ buffer = szValue;
+ return true;
+ }
+
+ void toString(const KviPixmap &pValue,QString &buffer)
+ {
+ buffer=pValue.path();
+ encodePath(buffer);
+ }
+
+ bool fromString(const QString & szValue,KviPixmap &buffer)
+ {
+ QString szPath(szValue);
+ decodePath(szPath);
+ if(szPath.isEmpty()) {
+ buffer.setNull();
+ return true;
+ } else {
+ return buffer.load(szPath);
+ }
+ }
+
+ void toString(const KviMsgType &mValue,QString &buffer)
+ {
+ buffer.sprintf("%d,%u,%u,%d,%d",mValue.m_iPixId,mValue.m_cForeColor,mValue.m_cBackColor,mValue.m_bLogEnabled,mValue.m_iLevel);
+ }
+
+ bool fromString(const QString & szValue,KviMsgType &buffer)
+ {
+ int iId,iLog,iLevel;
+ unsigned int uFore,uBack;
+ KviQCString tmp = KviQString::toUtf8(szValue);
+ char * cx = tmp.data();
+ if(!cx)return false;
+ if(sscanf(cx,"%d,%u,%u,%d,%d",&iId,&uFore,&uBack,&iLog,&iLevel) != 5)return false;
+ buffer = KviMsgType(buffer.m_szType,iId,uFore,uBack,iLog,iLevel);
+ return true;
+ }
+
+ void toString(const QColor &cValue,QString &buffer)
+ {
+ buffer = cValue.name();
+ }
+
+ bool fromString(const QString & szValue,QColor &buffer)
+ {
+ buffer.setNamedColor(szValue); return true;
+ }
+
+ void toString(const QFont &fValue,QString &buffer)
+ {
+ QString family(fValue.family());
+ buffer.sprintf("%s,%d,%d,%d",KviQString::toUtf8(family).data(),fValue.pointSize(),fValue.styleHint(),fValue.weight());
+ QString options;
+ if(fValue.bold())options.append('b');
+ if(fValue.italic())options.append('i');
+ if(fValue.underline())options.append('u');
+ if(fValue.strikeOut())options.append('s');
+ if(fValue.fixedPitch())options.append('f');
+
+ if(!options.isEmpty())
+ {
+ buffer.append(',');
+ buffer.append(options);
+ }
+ }
+
+ bool fromString(const QString & szValue,QFont &buffer)
+ {
+ KviStr str = szValue;
+ KviStr family,pointSize,styleHint,weight,options;
+ str.getToken(family,',');
+ str.getToken(pointSize,',');
+ str.getToken(styleHint,',');
+ str.getToken(weight,',');
+ if(!family.isEmpty())buffer.setFamily(family.ptr());
+ int i;
+ bool bOk;
+ i = pointSize.toInt(&bOk);
+ if(bOk && (i > 0))buffer.setPointSize(i);
+ i = styleHint.toInt(&bOk);
+ if(bOk && (i >= 0))buffer.setStyleHint((QFont::StyleHint)i);
+ i = weight.toInt(&bOk);
+ if(bOk && (i >= 0))buffer.setWeight(i);
+ if(!str.isEmpty())
+ {
+ buffer.setBold(str.contains("b"));
+ buffer.setItalic(str.contains("i"));
+ buffer.setUnderline(str.contains("u"));
+ buffer.setStrikeOut(str.contains("s"));
+ buffer.setFixedPitch(str.contains("f"));
+ }
+ return true;
+ }
+
+ void toString(const QStringList &sValue,QString &buffer)
+ {
+ buffer = sValue.join(",");
+ }
+
+ bool fromString(const QString & szValue,QStringList &buffer)
+ {
+#ifdef COMPILE_USE_QT4
+ buffer = szValue.split(",");
+#else
+ buffer = QStringList::split(",",szValue);
+#endif
+ return true;
+ }
+
+}
diff --git a/src/kvilib/ext/kvi_stringconversion.h b/src/kvilib/ext/kvi_stringconversion.h
new file mode 100644
index 00000000..78f8d417
--- /dev/null
+++ b/src/kvilib/ext/kvi_stringconversion.h
@@ -0,0 +1,91 @@
+#ifndef _KVI_STRINGCONVERSION_H_
+#define _KVI_STRINGCONVERSION_H_
+
+//=============================================================================
+//
+// File : kvi_stringconversion.h
+// Creation date : Thu Oct 20 2000 13:27:12 CEST by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_settings.h"
+#include "kvi_string.h"
+#include "kvi_pixmap.h"
+#include "kvi_msgtype.h"
+
+#include <qrect.h>
+#include <qcolor.h>
+#include <qfont.h>
+#include <qstringlist.h>
+#include <qstring.h>
+
+
+namespace KviStringConversion
+{
+ extern KVILIB_API void init(const QString& szGlobalDir,const QString& szLocalDir);
+
+ extern KVILIB_API void encodePath(QString& buffer);
+ extern KVILIB_API void decodePath(QString& buffer);
+
+ extern KVILIB_API void encodePath(QStringList& buffer);
+ extern KVILIB_API void decodePath(QStringList& buffer);
+
+ // bool <->
+ extern KVILIB_API void toString(const bool bValue,QString &buffer);
+ extern KVILIB_API bool fromString(const QString &szValue,bool &buffer);
+
+ // int <-> QString
+ extern KVILIB_API void toString(const int iValue,QString &buffer);
+ extern KVILIB_API bool fromString(const QString &szValue,int &buffer);
+
+ // uint <-> QString
+ extern KVILIB_API void toString(const unsigned int uValue,QString &buffer);
+ extern KVILIB_API bool fromString(const QString &szValue,unsigned int &buffer);
+
+ // QRect <-> QString
+ extern KVILIB_API void toString(const QRect &rValue,QString &buffer);
+ extern KVILIB_API bool fromString(const QString &szValue,QRect &buffer);
+
+ // QString <-> QString (Null conversion)
+ extern KVILIB_API void toString(const QString &szValue,QString &buffer);
+ extern KVILIB_API bool fromString(const QString &szValue,QString &buffer);
+
+ // KviPixmap <-> QString
+ extern KVILIB_API void toString(const KviPixmap &pValue,QString &buffer);
+ extern KVILIB_API bool fromString(const QString &szValue,KviPixmap &buffer);
+
+ // QFont <-> QString
+ extern KVILIB_API void toString(const QFont &fValue,QString &buffer);
+ extern KVILIB_API bool fromString(const QString &szValue,QFont &buffer);
+
+ // KviMsgType <-> QString
+ extern KVILIB_API void toString(const KviMsgType &mValue,QString &buffer);
+ extern KVILIB_API bool fromString(const QString &szValue,KviMsgType &buffer);
+
+ // QColor <-> QString
+ extern KVILIB_API void toString(const QColor &cValue,QString &buffer);
+ extern KVILIB_API bool fromString(const QString &szValue,QColor &buffer);
+
+ // QStringList <-> QString
+ extern KVILIB_API void toString(const QStringList &sValue,QString &buffer);
+ extern KVILIB_API bool fromString(const QString &szValue,QStringList &buffer);
+};
+
+#endif //!_KVI_STRINGCONVERSION_H_
diff --git a/src/kvilib/ext/kvi_xlib.h b/src/kvilib/ext/kvi_xlib.h
new file mode 100644
index 00000000..ef6ca177
--- /dev/null
+++ b/src/kvilib/ext/kvi_xlib.h
@@ -0,0 +1,45 @@
+#ifndef _KVI_XLIB_H_
+#define _KVI_XLIB_H_
+//=============================================================================
+//
+// File : kvi_xlib.h
+// Creation date : Tue Aug 14 18:17:21 2001 GMT by Szymon Stefanek
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2001-2005 Szymon Stefanek (pragma at kvirc dot net)
+//
+// 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 opinion) 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 "kvi_settings.h"
+
+#ifndef COMPILE_NO_X
+
+ #ifdef Bool
+ // Someone has defined Bool ?
+ #undef Bool
+ #endif
+
+ #include <X11/Xlib.h>
+
+ // Too bad that X11/Xlib.h defines Bool, Error and Success... this basically
+ // SUX since we can't use them anywhere in the source!
+ // this breaks, enums in Qt, enums in KVIrc and other stuff all around...
+ // Shame on you Xlib.h author :D
+
+#endif // !COMPILE_NO_X
+
+#endif //_KVI_XLIB_H_
diff --git a/src/kvilib/ext/moc_kvi_crypt.cpp b/src/kvilib/ext/moc_kvi_crypt.cpp
new file mode 100644
index 00000000..89c29d46
--- /dev/null
+++ b/src/kvilib/ext/moc_kvi_crypt.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+** KviCryptEngine meta object code from reading C++ file 'kvi_crypt.h'
+**
+** Created: Sun Mar 23 20:56:10 2008
+** by: The Qt MOC ($Id: qt/moc_yacc.cpp 3.3.8 edited Feb 2 14:59 $)
+**
+** WARNING! All changes made in this file will be lost!
+*****************************************************************************/
+
+#undef QT_NO_COMPAT
+#include "kvi_crypt.h"
+#include <qmetaobject.h>
+#include <qapplication.h>
+
+#include <private/qucomextra_p.h>
+#if !defined(Q_MOC_OUTPUT_REVISION) || (Q_MOC_OUTPUT_REVISION != 26)
+#error "This file was generated using the moc from 3.3.8. It"
+#error "cannot be used with the include files from this version of Qt."
+#error "(The moc has changed too much.)"
+#endif
+
+const char *KviCryptEngine::className() const
+{
+ return "KviCryptEngine";
+}
+
+QMetaObject *KviCryptEngine::metaObj = 0;
+static QMetaObjectCleanUp cleanUp_KviCryptEngine( "KviCryptEngine", &KviCryptEngine::staticMetaObject );
+
+#ifndef QT_NO_TRANSLATION
+QString KviCryptEngine::tr( const char *s, const char *c )
+{
+ if ( qApp )
+ return qApp->translate( "KviCryptEngine", s, c, QApplication::DefaultCodec );
+ else
+ return QString::fromLatin1( s );
+}
+#ifndef QT_NO_TRANSLATION_UTF8
+QString KviCryptEngine::trUtf8( const char *s, const char *c )
+{
+ if ( qApp )
+ return qApp->translate( "KviCryptEngine", s, c, QApplication::UnicodeUTF8 );
+ else
+ return QString::fromUtf8( s );
+}
+#endif // QT_NO_TRANSLATION_UTF8
+
+#endif // QT_NO_TRANSLATION
+
+QMetaObject* KviCryptEngine::staticMetaObject()
+{
+ if ( metaObj )
+ return metaObj;
+ QMetaObject* parentObject = QObject::staticMetaObject();
+ metaObj = QMetaObject::new_metaobject(
+ "KviCryptEngine", parentObject,
+ 0, 0,
+ 0, 0,
+#ifndef QT_NO_PROPERTIES
+ 0, 0,
+ 0, 0,
+#endif // QT_NO_PROPERTIES
+ 0, 0 );
+ cleanUp_KviCryptEngine.setMetaObject( metaObj );
+ return metaObj;
+}
+
+void* KviCryptEngine::qt_cast( const char* clname )
+{
+ if ( !qstrcmp( clname, "KviCryptEngine" ) )
+ return this;
+ if ( !qstrcmp( clname, "KviHeapObject" ) )
+ return (KviHeapObject*)this;
+ return QObject::qt_cast( clname );
+}
+
+bool KviCryptEngine::qt_invoke( int _id, QUObject* _o )
+{
+ return QObject::qt_invoke(_id,_o);
+}
+
+bool KviCryptEngine::qt_emit( int _id, QUObject* _o )
+{
+ return QObject::qt_emit(_id,_o);
+}
+#ifndef QT_NO_PROPERTIES
+
+bool KviCryptEngine::qt_property( int id, int f, QVariant* v)
+{
+ return QObject::qt_property( id, f, v);
+}
+
+bool KviCryptEngine::qt_static_property( QObject* , int , int , QVariant* ){ return FALSE; }
+#endif // QT_NO_PROPERTIES
diff --git a/src/kvilib/ext/moc_kvi_garbage.cpp b/src/kvilib/ext/moc_kvi_garbage.cpp
new file mode 100644
index 00000000..0c1a98ef
--- /dev/null
+++ b/src/kvilib/ext/moc_kvi_garbage.cpp
@@ -0,0 +1,104 @@
+/****************************************************************************
+** KviGarbageCollector meta object code from reading C++ file 'kvi_garbage.h'
+**
+** Created: Sun Mar 23 20:56:12 2008
+** by: The Qt MOC ($Id: qt/moc_yacc.cpp 3.3.8 edited Feb 2 14:59 $)
+**
+** WARNING! All changes made in this file will be lost!
+*****************************************************************************/
+
+#undef QT_NO_COMPAT
+#include "kvi_garbage.h"
+#include <qmetaobject.h>
+#include <qapplication.h>
+
+#include <private/qucomextra_p.h>
+#if !defined(Q_MOC_OUTPUT_REVISION) || (Q_MOC_OUTPUT_REVISION != 26)
+#error "This file was generated using the moc from 3.3.8. It"
+#error "cannot be used with the include files from this version of Qt."
+#error "(The moc has changed too much.)"
+#endif
+
+const char *KviGarbageCollector::className() const
+{
+ return "KviGarbageCollector";
+}
+
+QMetaObject *KviGarbageCollector::metaObj = 0;
+static QMetaObjectCleanUp cleanUp_KviGarbageCollector( "KviGarbageCollector", &KviGarbageCollector::staticMetaObject );
+
+#ifndef QT_NO_TRANSLATION
+QString KviGarbageCollector::tr( const char *s, const char *c )
+{
+ if ( qApp )
+ return qApp->translate( "KviGarbageCollector", s, c, QApplication::DefaultCodec );
+ else
+ return QString::fromLatin1( s );
+}
+#ifndef QT_NO_TRANSLATION_UTF8
+QString KviGarbageCollector::trUtf8( const char *s, const char *c )
+{
+ if ( qApp )
+ return qApp->translate( "KviGarbageCollector", s, c, QApplication::UnicodeUTF8 );
+ else
+ return QString::fromUtf8( s );
+}
+#endif // QT_NO_TRANSLATION_UTF8
+
+#endif // QT_NO_TRANSLATION
+
+QMetaObject* KviGarbageCollector::staticMetaObject()
+{
+ if ( metaObj )
+ return metaObj;
+ QMetaObject* parentObject = QObject::staticMetaObject();
+ static const QUMethod slot_0 = {"cleanup", 0, 0 };
+ static const QUMethod slot_1 = {"garbageSuicide", 0, 0 };
+ static const QMetaData slot_tbl[] = {
+ { "cleanup()", &slot_0, QMetaData::Protected },
+ { "garbageSuicide()", &slot_1, QMetaData::Protected }
+ };
+ metaObj = QMetaObject::new_metaobject(
+ "KviGarbageCollector", parentObject,
+ slot_tbl, 2,
+ 0, 0,
+#ifndef QT_NO_PROPERTIES
+ 0, 0,
+ 0, 0,
+#endif // QT_NO_PROPERTIES
+ 0, 0 );
+ cleanUp_KviGarbageCollector.setMetaObject( metaObj );
+ return metaObj;
+}
+
+void* KviGarbageCollector::qt_cast( const char* clname )
+{
+ if ( !qstrcmp( clname, "KviGarbageCollector" ) )
+ return this;
+ return QObject::qt_cast( clname );
+}
+
+bool KviGarbageCollector::qt_invoke( int _id, QUObject* _o )
+{
+ switch ( _id - staticMetaObject()->slotOffset() ) {
+ case 0: cleanup(); break;
+ case 1: garbageSuicide(); break;
+ default:
+ return QObject::qt_invoke( _id, _o );
+ }
+ return TRUE;
+}
+
+bool KviGarbageCollector::qt_emit( int _id, QUObject* _o )
+{
+ return QObject::qt_emit(_id,_o);
+}
+#ifndef QT_NO_PROPERTIES
+
+bool KviGarbageCollector::qt_property( int id, int f, QVariant* v)
+{
+ return QObject::qt_property( id, f, v);
+}
+
+bool KviGarbageCollector::qt_static_property( QObject* , int , int , QVariant* ){ return FALSE; }
+#endif // QT_NO_PROPERTIES
diff --git a/src/kvilib/ext/moc_kvi_regusersdb.cpp b/src/kvilib/ext/moc_kvi_regusersdb.cpp
new file mode 100644
index 00000000..092add9f
--- /dev/null
+++ b/src/kvilib/ext/moc_kvi_regusersdb.cpp
@@ -0,0 +1,143 @@
+/****************************************************************************
+** KviRegisteredUserDataBase meta object code from reading C++ file 'kvi_regusersdb.h'
+**
+** Created: Sun Mar 23 20:56:14 2008
+** by: The Qt MOC ($Id: qt/moc_yacc.cpp 3.3.8 edited Feb 2 14:59 $)
+**
+** WARNING! All changes made in this file will be lost!
+*****************************************************************************/
+
+#undef QT_NO_COMPAT
+#include "kvi_regusersdb.h"
+#include <qmetaobject.h>
+#include <qapplication.h>
+
+#include <private/qucomextra_p.h>
+#if !defined(Q_MOC_OUTPUT_REVISION) || (Q_MOC_OUTPUT_REVISION != 26)
+#error "This file was generated using the moc from 3.3.8. It"
+#error "cannot be used with the include files from this version of Qt."
+#error "(The moc has changed too much.)"
+#endif
+
+const char *KviRegisteredUserDataBase::className() const
+{
+ return "KviRegisteredUserDataBase";
+}
+
+QMetaObject *KviRegisteredUserDataBase::metaObj = 0;
+static QMetaObjectCleanUp cleanUp_KviRegisteredUserDataBase( "KviRegisteredUserDataBase", &KviRegisteredUserDataBase::staticMetaObject );
+
+#ifndef QT_NO_TRANSLATION
+QString KviRegisteredUserDataBase::tr( const char *s, const char *c )
+{
+ if ( qApp )
+ return qApp->translate( "KviRegisteredUserDataBase", s, c, QApplication::DefaultCodec );
+ else
+ return QString::fromLatin1( s );
+}
+#ifndef QT_NO_TRANSLATION_UTF8
+QString KviRegisteredUserDataBase::trUtf8( const char *s, const char *c )
+{
+ if ( qApp )
+ return qApp->translate( "KviRegisteredUserDataBase", s, c, QApplication::UnicodeUTF8 );
+ else
+ return QString::fromUtf8( s );
+}
+#endif // QT_NO_TRANSLATION_UTF8
+
+#endif // QT_NO_TRANSLATION
+
+QMetaObject* KviRegisteredUserDataBase::staticMetaObject()
+{
+ if ( metaObj )
+ return metaObj;
+ QMetaObject* parentObject = QObject::staticMetaObject();
+ static const QUParameter param_signal_0[] = {
+ { 0, &static_QUType_QString, 0, QUParameter::In }
+ };
+ static const QUMethod signal_0 = {"userRemoved", 1, param_signal_0 };
+ static const QUParameter param_signal_1[] = {
+ { 0, &static_QUType_QString, 0, QUParameter::In }
+ };
+ static const QUMethod signal_1 = {"userChanged", 1, param_signal_1 };
+ static const QUParameter param_signal_2[] = {
+ { 0, &static_QUType_QString, 0, QUParameter::In }
+ };
+ static const QUMethod signal_2 = {"userAdded", 1, param_signal_2 };
+ static const QUMethod signal_3 = {"databaseCleared", 0, 0 };
+ static const QMetaData signal_tbl[] = {
+ { "userRemoved(const QString&)", &signal_0, QMetaData::Public },
+ { "userChanged(const QString&)", &signal_1, QMetaData::Public },
+ { "userAdded(const QString&)", &signal_2, QMetaData::Public },
+ { "databaseCleared()", &signal_3, QMetaData::Public }
+ };
+ metaObj = QMetaObject::new_metaobject(
+ "KviRegisteredUserDataBase", parentObject,
+ 0, 0,
+ signal_tbl, 4,
+#ifndef QT_NO_PROPERTIES
+ 0, 0,
+ 0, 0,
+#endif // QT_NO_PROPERTIES
+ 0, 0 );
+ cleanUp_KviRegisteredUserDataBase.setMetaObject( metaObj );
+ return metaObj;
+}
+
+void* KviRegisteredUserDataBase::qt_cast( const char* clname )
+{
+ if ( !qstrcmp( clname, "KviRegisteredUserDataBase" ) )
+ return this;
+ return QObject::qt_cast( clname );
+}
+
+// SIGNAL userRemoved
+void KviRegisteredUserDataBase::userRemoved( const QString& t0 )
+{
+ activate_signal( staticMetaObject()->signalOffset() + 0, t0 );
+}
+
+// SIGNAL userChanged
+void KviRegisteredUserDataBase::userChanged( const QString& t0 )
+{
+ activate_signal( staticMetaObject()->signalOffset() + 1, t0 );
+}
+
+// SIGNAL userAdded
+void KviRegisteredUserDataBase::userAdded( const QString& t0 )
+{
+ activate_signal( staticMetaObject()->signalOffset() + 2, t0 );
+}
+
+// SIGNAL databaseCleared
+void KviRegisteredUserDataBase::databaseCleared()
+{
+ activate_signal( staticMetaObject()->signalOffset() + 3 );
+}
+
+bool KviRegisteredUserDataBase::qt_invoke( int _id, QUObject* _o )
+{
+ return QObject::qt_invoke(_id,_o);
+}
+
+bool KviRegisteredUserDataBase::qt_emit( int _id, QUObject* _o )
+{
+ switch ( _id - staticMetaObject()->signalOffset() ) {
+ case 0: userRemoved((const QString&)static_QUType_QString.get(_o+1)); break;
+ case 1: userChanged((const QString&)static_QUType_QString.get(_o+1)); break;
+ case 2: userAdded((const QString&)static_QUType_QString.get(_o+1)); break;
+ case 3: databaseCleared(); break;
+ default:
+ return QObject::qt_emit(_id,_o);
+ }
+ return TRUE;
+}
+#ifndef QT_NO_PROPERTIES
+
+bool KviRegisteredUserDataBase::qt_property( int id, int f, QVariant* v)
+{
+ return QObject::qt_property( id, f, v);
+}
+
+bool KviRegisteredUserDataBase::qt_static_property( QObject* , int , int , QVariant* ){ return FALSE; }
+#endif // QT_NO_PROPERTIES
diff --git a/src/kvilib/ext/moc_kvi_sharedfiles.cpp b/src/kvilib/ext/moc_kvi_sharedfiles.cpp
new file mode 100644
index 00000000..83ea82a4
--- /dev/null
+++ b/src/kvilib/ext/moc_kvi_sharedfiles.cpp
@@ -0,0 +1,157 @@
+/****************************************************************************
+** KviSharedFilesManager meta object code from reading C++ file 'kvi_sharedfiles.h'
+**
+** Created: Sun Mar 23 20:56:15 2008
+** by: The Qt MOC ($Id: qt/moc_yacc.cpp 3.3.8 edited Feb 2 14:59 $)
+**
+** WARNING! All changes made in this file will be lost!
+*****************************************************************************/
+
+#undef QT_NO_COMPAT
+#include "kvi_sharedfiles.h"
+#include <qmetaobject.h>
+#include <qapplication.h>
+
+#include <private/qucomextra_p.h>
+#if !defined(Q_MOC_OUTPUT_REVISION) || (Q_MOC_OUTPUT_REVISION != 26)
+#error "This file was generated using the moc from 3.3.8. It"
+#error "cannot be used with the include files from this version of Qt."
+#error "(The moc has changed too much.)"
+#endif
+
+const char *KviSharedFilesManager::className() const
+{
+ return "KviSharedFilesManager";
+}
+
+QMetaObject *KviSharedFilesManager::metaObj = 0;
+static QMetaObjectCleanUp cleanUp_KviSharedFilesManager( "KviSharedFilesManager", &KviSharedFilesManager::staticMetaObject );
+
+#ifndef QT_NO_TRANSLATION
+QString KviSharedFilesManager::tr( const char *s, const char *c )
+{
+ if ( qApp )
+ return qApp->translate( "KviSharedFilesManager", s, c, QApplication::DefaultCodec );
+ else
+ return QString::fromLatin1( s );
+}
+#ifndef QT_NO_TRANSLATION_UTF8
+QString KviSharedFilesManager::trUtf8( const char *s, const char *c )
+{
+ if ( qApp )
+ return qApp->translate( "KviSharedFilesManager", s, c, QApplication::UnicodeUTF8 );
+ else
+ return QString::fromUtf8( s );
+}
+#endif // QT_NO_TRANSLATION_UTF8
+
+#endif // QT_NO_TRANSLATION
+
+QMetaObject* KviSharedFilesManager::staticMetaObject()
+{
+ if ( metaObj )
+ return metaObj;
+ QMetaObject* parentObject = QObject::staticMetaObject();
+ static const QUMethod slot_0 = {"cleanup", 0, 0 };
+ static const QMetaData slot_tbl[] = {
+ { "cleanup()", &slot_0, QMetaData::Private }
+ };
+ static const QUMethod signal_0 = {"sharedFilesChanged", 0, 0 };
+ static const QUParameter param_signal_1[] = {
+ { "f", &static_QUType_ptr, "KviSharedFile", QUParameter::In }
+ };
+ static const QUMethod signal_1 = {"sharedFileAdded", 1, param_signal_1 };
+ static const QUParameter param_signal_2[] = {
+ { "f", &static_QUType_ptr, "KviSharedFile", QUParameter::In }
+ };
+ static const QUMethod signal_2 = {"sharedFileRemoved", 1, param_signal_2 };
+ static const QMetaData signal_tbl[] = {
+ { "sharedFilesChanged()", &signal_0, QMetaData::Private },
+ { "sharedFileAdded(KviSharedFile*)", &signal_1, QMetaData::Private },
+ { "sharedFileRemoved(KviSharedFile*)", &signal_2, QMetaData::Private }
+ };
+ metaObj = QMetaObject::new_metaobject(
+ "KviSharedFilesManager", parentObject,
+ slot_tbl, 1,
+ signal_tbl, 3,
+#ifndef QT_NO_PROPERTIES
+ 0, 0,
+ 0, 0,
+#endif // QT_NO_PROPERTIES
+ 0, 0 );
+ cleanUp_KviSharedFilesManager.setMetaObject( metaObj );
+ return metaObj;
+}
+
+void* KviSharedFilesManager::qt_cast( const char* clname )
+{
+ if ( !qstrcmp( clname, "KviSharedFilesManager" ) )
+ return this;
+ return QObject::qt_cast( clname );
+}
+
+// SIGNAL sharedFilesChanged
+void KviSharedFilesManager::sharedFilesChanged()
+{
+ activate_signal( staticMetaObject()->signalOffset() + 0 );
+}
+
+#include <qobjectdefs.h>
+#include <qsignalslotimp.h>
+
+// SIGNAL sharedFileAdded
+void KviSharedFilesManager::sharedFileAdded( KviSharedFile* t0 )
+{
+ if ( signalsBlocked() )
+ return;
+ QConnectionList *clist = receivers( staticMetaObject()->signalOffset() + 1 );
+ if ( !clist )
+ return;
+ QUObject o[2];
+ static_QUType_ptr.set(o+1,t0);
+ activate_signal( clist, o );
+}
+
+// SIGNAL sharedFileRemoved
+void KviSharedFilesManager::sharedFileRemoved( KviSharedFile* t0 )
+{
+ if ( signalsBlocked() )
+ return;
+ QConnectionList *clist = receivers( staticMetaObject()->signalOffset() + 2 );
+ if ( !clist )
+ return;
+ QUObject o[2];
+ static_QUType_ptr.set(o+1,t0);
+ activate_signal( clist, o );
+}
+
+bool KviSharedFilesManager::qt_invoke( int _id, QUObject* _o )
+{
+ switch ( _id - staticMetaObject()->slotOffset() ) {
+ case 0: cleanup(); break;
+ default:
+ return QObject::qt_invoke( _id, _o );
+ }
+ return TRUE;
+}
+
+bool KviSharedFilesManager::qt_emit( int _id, QUObject* _o )
+{
+ switch ( _id - staticMetaObject()->signalOffset() ) {
+ case 0: sharedFilesChanged(); break;
+ case 1: sharedFileAdded((KviSharedFile*)static_QUType_ptr.get(_o+1)); break;
+ case 2: sharedFileRemoved((KviSharedFile*)static_QUType_ptr.get(_o+1)); break;
+ default:
+ return QObject::qt_emit(_id,_o);
+ }
+ return TRUE;
+}
+#ifndef QT_NO_PROPERTIES
+
+bool KviSharedFilesManager::qt_property( int id, int f, QVariant* v)
+{
+ return QObject::qt_property( id, f, v);
+}
+
+bool KviSharedFilesManager::qt_static_property( QObject* , int , int , QVariant* ){ return FALSE; }
+#endif // QT_NO_PROPERTIES