aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Fabio Bas2010-04-11 19:50:15 +0000
committerGravatar Fabio Bas2010-04-11 19:50:15 +0000
commitb15ec8764c6f190ff759edac1ae2776bba3bab67 (patch)
tree341791a1e137468c420e2aedabb356d65e8466d5 /src
parentclanage of the theora classes, they should be working now (but using too much... (diff)
downloadKVIrc-b15ec8764c6f190ff759edac1ae2776bba3bab67.tar.gz
KVIrc-b15ec8764c6f190ff759edac1ae2776bba3bab67.tar.bz2
KVIrc-b15ec8764c6f190ff759edac1ae2776bba3bab67.zip
moved the "smart nick colors" functions to their own file.
Added the ability to expose your current personalized nick colors to others git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@4247 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src')
-rw-r--r--src/kvilib/CMakeLists.txt1
-rw-r--r--src/kvilib/ext/kvi_nickcolors.cpp116
-rw-r--r--src/kvilib/ext/kvi_nickcolors.h39
-rw-r--r--src/kvilib/irc/kvi_ircuserdb.cpp29
-rw-r--r--src/kvilib/irc/kvi_ircuserdb.h15
-rw-r--r--src/kvirc/kernel/kvi_ircconnection.cpp25
-rw-r--r--src/kvirc/kernel/kvi_options.cpp3
-rw-r--r--src/kvirc/kernel/kvi_options.h3
-rw-r--r--src/kvirc/ui/kvi_console.cpp77
-rw-r--r--src/modules/options/optw_irc.cpp3
10 files changed, 251 insertions, 60 deletions
diff --git a/src/kvilib/CMakeLists.txt b/src/kvilib/CMakeLists.txt
index f771fc83c..3fd59f264 100644
--- a/src/kvilib/CMakeLists.txt
+++ b/src/kvilib/CMakeLists.txt
@@ -77,6 +77,7 @@ SET(kvilib_SRCS
ext/kvi_pixmap.cpp
ext/kvi_animatedpixmap.cpp
ext/kvi_animatedpixmapcache.cpp
+ ext/kvi_nickcolors.cpp
ext/kvi_proxydb.cpp
ext/kvi_regchan.cpp
ext/kvi_regusersdb.cpp
diff --git a/src/kvilib/ext/kvi_nickcolors.cpp b/src/kvilib/ext/kvi_nickcolors.cpp
new file mode 100644
index 000000000..f662beab1
--- /dev/null
+++ b/src/kvilib/ext/kvi_nickcolors.cpp
@@ -0,0 +1,116 @@
+//=============================================================================
+//
+// File : kvi_nickcolors.cpp
+// Creation date : Sun Apr 11 2010 15:00:01 CEST by Fabio Bas
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2009 Fabio Bas (ctrlaltca at libero dot it)
+//
+// 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_nickcolors.h"
+
+#include "kvi_malloc.h"
+#include <stdio.h>
+
+namespace KviNickColors
+{
+
+ #define KVI_NUM_NICK_COLORS 95
+
+ static const char * g_nickColors[KVI_NUM_NICK_COLORS]=
+ {
+ "0,1" ,"0,2" ,"0,3" ,"0,4" ,"0,5" ,"0,6" ,"0,10" ,"0,12" ,"0,14" , //9
+ "1,0" ,"1,4" ,"1,7" ,"1,8" ,"1,9" ,"1,11" ,"1,15" , //7
+ "2,0" ,"2,4" ,"2,7" ,"2,8" ,"2,9" ,"2,11" ,"2,15" , //7
+ "3,8" ,"3,9" ,"3,0" ,"3,15" , //4
+ "4,0" ,"4,1" ,"4,8" ,"4,9" ,"4,11" ,"4,15" , //6
+ "5,0" ,"5,7" ,"5,8" ,"5,15" , //4
+ "6,0" ,"6,7" ,"6,8" ,"6,9" ,"6,10" ,"6,11" ,"6,15" , //7
+ "7,1" ,"7,2" ,"7,5" ,"7,6" ,"7,14" , //5
+ "8,1" ,"8,2" ,"8,3" ,"8,4" ,"8,5" ,"8,6" ,"8,7" ,"8,10" ,"8,12" ,"8,14" , //10
+ "9,1" ,"9,2" ,"9,3" ,"9,5" ,"9,6" ,"9,14" , //6
+ "10,1" ,"10,2" , //2
+ "11,1" ,"11,2" ,"11,3" ,"11,5" ,"11,6" ,"11,14", //6
+ "12,0" ,"12,7" ,"12,8" ,"12,9" ,"12,10","12,11","12,15", //7
+ "13,0" ,"13,1" ,"13,6" ,"13,8" ,"13,11","13,15", //6
+ "14,0" ,"14,8" ,"14,11","14,15", //4
+ "15,1" ,"15,2" ,"15,3" ,"15,6" ,"15,14" //5
+ };
+
+ int getSmartColorForNick(QString *szNick)
+ {
+ int sum = 0;
+ int i = szNick->length();
+ const QChar * aux = szNick->unicode();
+ // FIXME: Shouldn't this be case insensitive ?
+ while(i > 0)
+ {
+ sum += aux->unicode();
+ aux++;
+ i--;
+ }
+ return sum;
+ }
+
+ const char * getSmartColor(int iPos)
+ {
+ return g_nickColors[iPos % KVI_NUM_NICK_COLORS];
+ }
+
+ int getSmartColorIntByMircColor(unsigned char iFore,unsigned char iBack)
+ {
+ int iBestMatch=-1;
+ char* comb= (char*)kvi_malloc(6);
+ int numm=0;
+ snprintf(comb, 6, "%d,%d", iFore, iBack);
+// qDebug("Nick color %s",comb);
+ for(int i=0; i<KVI_NUM_NICK_COLORS;++i)
+ {
+ int numc=0;
+ // strcmp
+ while(g_nickColors[i][numc] && comb[numc])
+ {
+ if(g_nickColors[i][numc] != comb[numc])
+ break;
+ numc++;
+ }
+ if(numc>0)
+ {
+ // any match
+ if(!g_nickColors[i][numc] && !comb[numc])
+ {
+ //exact match
+// qDebug("Exact match %s",g_nickColors[i]);
+ return i;
+ } else {
+ //partial match
+ if(numc > numm)
+ {
+ //better than any previous one
+ iBestMatch=i;
+ numm=numc;
+ }
+ }
+ }
+ }
+ kvi_free(comb);
+ //no exact match
+// qDebug("Best match %s",g_nickColors[iBestMatch]);
+ return iBestMatch;
+ }
+}
diff --git a/src/kvilib/ext/kvi_nickcolors.h b/src/kvilib/ext/kvi_nickcolors.h
new file mode 100644
index 000000000..809a7ba7b
--- /dev/null
+++ b/src/kvilib/ext/kvi_nickcolors.h
@@ -0,0 +1,39 @@
+#ifndef _KVI_NICKCOLORS_H_
+#define _KVI_NICKCOLORS_H_
+//=============================================================================
+//
+// File : kvi_nickcolors.h
+// Creation date : Sun Apr 11 2010 15:00:01 CEST by Fabio Bas
+//
+// This file is part of the KVirc irc client distribution
+// Copyright (C) 2009 Fabio Bas (ctrlaltca at libero dot it)
+//
+// 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>
+
+namespace KviNickColors
+{
+ extern KVILIB_API int getSmartColorForNick(QString *szNick);
+
+ extern KVILIB_API const char * getSmartColor(int iPos);
+
+ extern KVILIB_API int getSmartColorIntByMircColor(unsigned char iFore,unsigned char iBack);
+}
+#endif // _KVI_NICKCOLORS_H_ \ No newline at end of file
diff --git a/src/kvilib/irc/kvi_ircuserdb.cpp b/src/kvilib/irc/kvi_ircuserdb.cpp
index 73f3fd075..ca41c27e2 100644
--- a/src/kvilib/irc/kvi_ircuserdb.cpp
+++ b/src/kvilib/irc/kvi_ircuserdb.cpp
@@ -29,6 +29,7 @@
#include "kvi_mirccntrl.h"
#include "kvi_qstring.h"
#include "kvi_stringconversion.h"
+#include "kvi_nickcolors.h"
//static int cacheHit = 0;
//static int cacheMiss = 0;
@@ -46,27 +47,27 @@ KviIrcUserEntry::KviIrcUserEntry(const QString &user,const QString &host)
m_bBot = false;
m_bNotFoundRegUserLoockup=false;
m_bUseCustomColor=false;
+ m_iSmartNickColor=-1;
}
void KviIrcUserEntry::setRealName(const QString &rn)
{
- m_szRealName = rn;
- m_szRealName = KviQString::trimmed(m_szRealName);
+ m_szRealName = rn.trimmed();
if(m_szRealName.length()>=3)
{
if( (m_szRealName[0].unicode()==KVI_TEXT_COLOR) && (m_szRealName[2].unicode()==KVI_TEXT_RESET) )
{
// hum.. encoded as hidden color code eh ? publish is somewhere, so others might implement this...
// for backwards compatibily, 3=bot
- if(m_szRealName[1].unicode() & 1 && m_szRealName[1].unicode() & 2)
+ if(m_szRealName[1].unicode() == '3')
{
setBot(true); //3
} else {
- if(m_szRealName[1].unicode() & 1)
+ if(m_szRealName[1].unicode() == '1')
{
setGender(Male); //1
} else {
- if(m_szRealName[1].unicode() & 2)
+ if(m_szRealName[1].unicode() == '2')
{
setGender(Female); //2
}
@@ -75,6 +76,24 @@ void KviIrcUserEntry::setRealName(const QString &rn)
m_szRealName.remove(0,3);
}
}
+
+ // smart nick color code
+ if(m_szRealName.length()>=7)
+ {
+ if((m_szRealName[0].unicode()==KVI_TEXT_COLOR))
+ {
+ unsigned char iFore, iBack;
+ int iPos=getUnicodeColorBytes(m_szRealName, 1, &iFore, &iBack);
+ // extract smart nick color code
+ if(iPos > 1 && m_szRealName[iPos]==KVI_TEXT_RESET)
+ {
+ m_szRealName.truncate(iPos);
+ int color = KviNickColors::getSmartColorIntByMircColor(iFore, iBack);
+ if(color>=0) setSmartNickColor(color);
+ m_szRealName.remove(0,iPos+1);
+ }
+ }
+ }
}
KviIrcUserEntry::~KviIrcUserEntry()
diff --git a/src/kvilib/irc/kvi_ircuserdb.h b/src/kvilib/irc/kvi_ircuserdb.h
index 59ebc2fc5..b7f8792ad 100644
--- a/src/kvilib/irc/kvi_ircuserdb.h
+++ b/src/kvilib/irc/kvi_ircuserdb.h
@@ -111,8 +111,23 @@ protected:
QColor m_cachedColor;
bool m_bUseCustomColor;
+
+ int m_iSmartNickColor;
public:
/**
+ * \brief Returns the ircview smart nick color of the user
+ * \return int
+ */
+ int smartNickColor() { return m_iSmartNickColor; };
+
+ /**
+ * \brief Sets the gender of the user
+ * \param g The gender
+ * \return void
+ */
+ void setSmartNickColor(const int iColor) { m_iSmartNickColor=iColor; };
+
+ /**
* \brief Returns the gender of the user
* \return Gender
*/
diff --git a/src/kvirc/kernel/kvi_ircconnection.cpp b/src/kvirc/kernel/kvi_ircconnection.cpp
index c00ae6866..1a485103f 100644
--- a/src/kvirc/kernel/kvi_ircconnection.cpp
+++ b/src/kvirc/kernel/kvi_ircconnection.cpp
@@ -67,6 +67,7 @@
#include "kvi_useridentity.h"
#include "kvi_identityprofile.h"
#include "kvi_sasl.h"
+#include "kvi_nickcolors.h"
#include <QTimer>
#include <QTextCodec>
@@ -1237,8 +1238,8 @@ void KviIrcConnection::loginToIrcServer()
return;
}
- QString szGenderAvatarTag;
- int iGenderAvatarTag=0;
+ unsigned int iGenderAvatarTag=0;
+
if(KVI_OPTION_BOOL(KviOption_boolPrependGenderInfoToRealname) && !KVI_OPTION_STRING(KviOption_stringCtcpUserInfoGender).isEmpty())
{
if(KVI_OPTION_STRING(KviOption_stringCtcpUserInfoGender).startsWith("m",Qt::CaseInsensitive))
@@ -1255,10 +1256,26 @@ void KviIrcConnection::loginToIrcServer()
iGenderAvatarTag|=4;
}
+ if(KVI_OPTION_BOOL(KviOption_boolPrependNickColorInfoToRealname) &&
+ KVI_OPTION_BOOL(KviOption_boolUseSpecifiedSmartColorForOwnNick))
+ {
+ QString szTags;
+ szTags.sprintf("%c%d,%d%c",
+ KVI_TEXT_COLOR,
+ KVI_OPTION_UINT(KviOption_uintUserIrcViewOwnForeground),
+ KVI_OPTION_UINT(KviOption_uintUserIrcViewOwnBackground),
+ KVI_TEXT_RESET);
+ szReal.prepend(KviQString::toUtf8(szTags));
+ }
+
if(iGenderAvatarTag!=0)
{
- szGenderAvatarTag.sprintf("%c%d%c",KVI_TEXT_COLOR,iGenderAvatarTag,KVI_TEXT_RESET);
- szReal.prepend(KviQString::toUtf8(szGenderAvatarTag));
+ QString szTags;
+ szTags.sprintf("%c%d%c",
+ KVI_TEXT_COLOR,
+ iGenderAvatarTag,
+ KVI_TEXT_RESET);
+ szReal.prepend(KviQString::toUtf8(szTags));
}
if(!sendFmtData("USER %s 0 %s :%s",szUser.data(),
diff --git a/src/kvirc/kernel/kvi_options.cpp b/src/kvirc/kernel/kvi_options.cpp
index 0ac3c708e..bcee89c73 100644
--- a/src/kvirc/kernel/kvi_options.cpp
+++ b/src/kvirc/kernel/kvi_options.cpp
@@ -324,7 +324,8 @@ KviBoolOption g_boolOptionsTable[KVI_NUM_BOOL_OPTIONS]=
BOOL_OPTION("UseAwayMessage",true,KviOption_sectFlagConnection),
BOOL_OPTION("DisableQuietBanListRequestOnJoin",true,KviOption_sectFlagConnection),
BOOL_OPTION("UseSaslIfAvailable",true,KviOption_sectFlagConnection),
- BOOL_OPTION("FrameIsMaximized",false,KviOption_sectFlagGeometry)
+ BOOL_OPTION("FrameIsMaximized",false,KviOption_sectFlagGeometry),
+ BOOL_OPTION("PrependNickColorInfoToRealname",true,KviOption_sectFlagConnection)
};
#define STRING_OPTION(_txt,_val,_flags) KviStringOption(KVI_STRING_OPTIONS_PREFIX _txt,_val,_flags)
diff --git a/src/kvirc/kernel/kvi_options.h b/src/kvirc/kernel/kvi_options.h
index 9617ca1b9..e317911e0 100644
--- a/src/kvirc/kernel/kvi_options.h
+++ b/src/kvirc/kernel/kvi_options.h
@@ -332,8 +332,9 @@ DECLARE_OPTION_STRUCT(KviStringListOption,QStringList)
#define KviOption_boolDisableQuietBanListRequestOnJoin 238 /* channel */
#define KviOption_boolUseSaslIfAvailable 239
#define KviOption_boolFrameIsMaximized 240 /* internal */
+#define KviOption_boolPrependNickColorInfoToRealname 241
-#define KVI_NUM_BOOL_OPTIONS 241
+#define KVI_NUM_BOOL_OPTIONS 242
#define KVI_STRING_OPTIONS_PREFIX "string"
diff --git a/src/kvirc/ui/kvi_console.cpp b/src/kvirc/ui/kvi_console.cpp
index 6f8281a78..3fd2a3ddc 100644
--- a/src/kvirc/ui/kvi_console.cpp
+++ b/src/kvirc/ui/kvi_console.cpp
@@ -71,6 +71,7 @@
#include "kvi_kvs_eventtriggers.h"
#include "kvi_tal_hbox.h"
#include "kvi_tal_popupmenu.h"
+#include "kvi_nickcolors.h"
#ifdef COMPILE_SSL_SUPPORT
#include "kvi_sslmaster.h"
@@ -149,7 +150,8 @@ KviConsole::KviConsole(KviFrame * lpFrm,int iFlags)
applyOptions();
}
-void KviConsole::recentUrlsChanged(){
+void KviConsole::recentUrlsChanged()
+{
QString cur = m_pAddressEdit->currentText();
m_pAddressEdit->clear();
for (
@@ -667,42 +669,6 @@ int KviConsole::applyHighlighting(KviWindow *wnd,int type,const QString &nick,co
return type;
}
-#define KVI_NUM_NICK_COLORS 95
-
-static const char * g_nickColors[KVI_NUM_NICK_COLORS]=
-{
- "0,1" ,"0,2" ,"0,3" ,"0,4" ,"0,5" ,"0,6" ,"0,10" ,"0,12" ,"0,14" , //9
- "1,0" ,"1,4" ,"1,7" ,"1,8" ,"1,9" ,"1,11" ,"1,15" , //7
- "2,0" ,"2,4" ,"2,7" ,"2,8" ,"2,9" ,"2,11" ,"2,15" , //7
- "3,8" ,"3,9" ,"3,0" ,"3,15" , //4
- "4,0" ,"4,1" ,"4,8" ,"4,9" ,"4,11" ,"4,15" , //6
- "5,0" ,"5,7" ,"5,8" ,"5,15" , //4
- "6,0" ,"6,7" ,"6,8" ,"6,9" ,"6,10" ,"6,11" ,"6,15" , //7
- "7,1" ,"7,2" ,"7,5" ,"7,6" ,"7,14" , //5
- "8,1" ,"8,2" ,"8,3" ,"8,4" ,"8,5" ,"8,6" ,"8,7" ,"8,10" ,"8,12" ,"8,14" , //10
- "9,1" ,"9,2" ,"9,3" ,"9,5" ,"9,6" ,"9,14" , //6
- "10,1" ,"10,2" , //2
- "11,1" ,"11,2" ,"11,3" ,"11,5" ,"11,6" ,"11,14", //6
- "12,0" ,"12,7" ,"12,8" ,"12,9" ,"12,10","12,11","12,15", //7
- "13,0" ,"13,1" ,"13,6" ,"13,8" ,"13,11","13,15", //6
- "14,0" ,"14,8" ,"14,11","14,15", //4
- "15,1" ,"15,2" ,"15,3" ,"15,6" ,"15,14" //5
-};
-
-inline static int getSmartColorForNick(QString *szNick)
-{
- int sum = 0;
- int i = szNick->length();
- const QChar * aux = szNick->unicode();
- // FIXME: Shouldn't this be case insensitive ?
- while(i > 0)
- {
- sum += aux->unicode();
- aux++;
- i--;
- }
- return sum;
-}
void KviConsole::outputPrivmsg(KviWindow *wnd,
int type,
@@ -778,22 +744,37 @@ void KviConsole::outputPrivmsg(KviWindow *wnd,
if(bIsChan && KVI_OPTION_BOOL(KviOption_boolShowChannelUserFlagInPrivmsgView))
((KviChannel *)wnd)->prependUserFlag(nick,szNick);
- if(KVI_OPTION_BOOL(KviOption_boolColorNicks))
+ if(KVI_OPTION_BOOL(KviOption_boolColorNicks) && connection())
{
- if(KVI_OPTION_BOOL(KviOption_boolUseSpecifiedSmartColorForOwnNick) && connection())
+ if(KVI_OPTION_BOOL(KviOption_boolUseSpecifiedSmartColorForOwnNick) &&
+ QString::compare(nick,connection()->userInfo()->nickName(),Qt::CaseSensitive)==0)
{
- if(QString::compare(nick,connection()->userInfo()->nickName(),Qt::CaseSensitive)==0)
+ // it's me
+ szNick.prepend(m_szOwnSmartColor);
+ } else {
+ //search for a cached entry
+ KviIrcUserEntry * pUserEntry = connection()->userDataBase()->find(nick);
+ if(pUserEntry)
{
- szNick.prepend(m_szOwnSmartColor);
+ int sum=pUserEntry->smartNickColor();
+ if(sum < 0)
+ {
+ // cache miss, create entry
+ sum=KviNickColors::getSmartColorForNick(&nick);
+ if(KVI_OPTION_BOOL(KviOption_boolUseSpecifiedSmartColorForOwnNick))
+ {
+ //avoid the use of teh color specifier for own nickname
+ if(m_szOwnSmartColor==KviNickColors::getSmartColor(sum))
+ sum++;
+ }
+ pUserEntry->setSmartNickColor(sum);
+ }
+
+ szNick.prepend(KviNickColors::getSmartColor(sum));
} else {
- int sum=getSmartColorForNick(&nick);
- //avoid the use of teh color specifier for own nickname
- if(m_szOwnSmartColor==g_nickColors[sum % KVI_NUM_NICK_COLORS])
- sum++;
- szNick.prepend(g_nickColors[sum % KVI_NUM_NICK_COLORS]);
+ // how can this happen? better fallback than wrong
+ qDebug("BUG Trying to get smart color for a nickname not in userdb (%s)!",szNick.toUtf8().data());
}
- } else {
- szNick.prepend(g_nickColors[getSmartColorForNick(&nick) % KVI_NUM_NICK_COLORS]);
}
szNick.prepend(KVI_TEXT_COLOR);
szNick.append(KVI_TEXT_COLOR);
diff --git a/src/modules/options/optw_irc.cpp b/src/modules/options/optw_irc.cpp
index cd32fd5fe..362e2cff0 100644
--- a/src/modules/options/optw_irc.cpp
+++ b/src/modules/options/optw_irc.cpp
@@ -75,7 +75,8 @@ KviIrcAdvancedOptionsWidget::KviIrcAdvancedOptionsWidget(QWidget * parent)
"Note that if you use this, your QUIT message may be not displayed.</center>","options"));
addBoolSelector(0,1,0,1,__tr2qs_ctx("Prepend gender info to realname","options"),KviOption_boolPrependGenderInfoToRealname);
addBoolSelector(0,2,0,2,__tr2qs_ctx("Prepend avatar info to realname","options"),KviOption_boolPrependAvatarInfoToRealname);
- addRowSpacer(0,3,0,3);
+ addBoolSelector(0,3,0,3,__tr2qs_ctx("Prepend smart nick color info to realname","options"),KviOption_boolPrependNickColorInfoToRealname);
+ addRowSpacer(0,4,0,4);
}
KviIrcAdvancedOptionsWidget::~KviIrcAdvancedOptionsWidget()