~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/kvilib/ext/KviNickColors.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=============================================================================
 
2
//
 
3
//   File : KviNickColors.cpp
 
4
//   Creation date : Sun Apr 11 2010 15:00:01 CEST by Fabio Bas
 
5
//
 
6
//   This file is part of the KVIrc irc client distribution
 
7
//   Copyright (C) 2009 Fabio Bas (ctrlaltca at libero dot it)
 
8
//
 
9
//   This program is FREE software. You can redistribute it and/or
 
10
//   modify it under the terms of the GNU General Public License
 
11
//   as published by the Free Software Foundation; either version 2
 
12
//   of the License, or (at your opinion) any later version.
 
13
//
 
14
//   This program is distributed in the HOPE that it will be USEFUL,
 
15
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
17
//   See the GNU General Public License for more details.
 
18
//
 
19
//   You should have received a copy of the GNU General Public License
 
20
//   along with this program. If not, write to the Free Software Foundation,
 
21
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
22
//
 
23
//=============================================================================
 
24
 
 
25
#include "KviNickColors.h"
 
26
 
 
27
#include "KviMemory.h"
 
28
#include <stdio.h>
 
29
 
 
30
namespace KviNickColors
 
31
{
 
32
 
 
33
        #define KVI_NUM_NICK_COLORS 95
 
34
 
 
35
        static const char * g_nickColors[KVI_NUM_NICK_COLORS]=
 
36
        {
 
37
                "0,1"  ,"0,2"  ,"0,3"  ,"0,4"  ,"0,5"  ,"0,6"  ,"0,10" ,"0,12" ,"0,14" , //9
 
38
                "1,0"  ,"1,4"  ,"1,7"  ,"1,8"  ,"1,9"  ,"1,11" ,"1,15" ,  //7
 
39
                "2,0"  ,"2,4"  ,"2,7"  ,"2,8"  ,"2,9"  ,"2,11" ,"2,15" ,  //7
 
40
                "3,8"  ,"3,9"  ,"3,0"  ,"3,15" , //4
 
41
                "4,0"  ,"4,1"  ,"4,8"  ,"4,9"  ,"4,11" ,"4,15" , //6
 
42
                "5,0"  ,"5,7"  ,"5,8"  ,"5,15" , //4
 
43
                "6,0"  ,"6,7"  ,"6,8"  ,"6,9"  ,"6,10" ,"6,11" ,"6,15" , //7
 
44
                "7,1"  ,"7,2"  ,"7,5"  ,"7,6"  ,"7,14" , //5
 
45
                "8,1"  ,"8,2"  ,"8,3"  ,"8,4"  ,"8,5"  ,"8,6"  ,"8,7"  ,"8,10" ,"8,12" ,"8,14" , //10
 
46
                "9,1"  ,"9,2"  ,"9,3"  ,"9,5"  ,"9,6"  ,"9,14" , //6
 
47
                "10,1" ,"10,2" , //2
 
48
                "11,1" ,"11,2" ,"11,3" ,"11,5" ,"11,6" ,"11,14", //6
 
49
                "12,0" ,"12,7" ,"12,8" ,"12,9" ,"12,10","12,11","12,15", //7
 
50
                "13,0" ,"13,1" ,"13,6" ,"13,8" ,"13,11","13,15", //6
 
51
                "14,0" ,"14,8" ,"14,11","14,15", //4
 
52
                "15,1" ,"15,2" ,"15,3" ,"15,6" ,"15,14" //5
 
53
        };
 
54
 
 
55
        int getSmartColorForNick(QString *szNick)
 
56
        {
 
57
                int sum = 0;
 
58
                int i = szNick->length();
 
59
                const QChar * aux = szNick->unicode();
 
60
                // FIXME: Shouldn't this be case insensitive ?
 
61
                while(i > 0)
 
62
                {
 
63
                        sum += aux->unicode();
 
64
                        aux++;
 
65
                        i--;
 
66
                }
 
67
                return sum;
 
68
        }
 
69
 
 
70
        const char * getSmartColor(int iPos)
 
71
        {
 
72
                return g_nickColors[iPos % KVI_NUM_NICK_COLORS];
 
73
        }
 
74
 
 
75
        int getSmartColorIntByMircColor(unsigned char iFore,unsigned char iBack)
 
76
        {
 
77
                int iBestMatch=-1;
 
78
                char* comb= (char*)KviMemory::allocate(6);
 
79
                int numm=0;
 
80
                // TODO handle KVI_TRANSPARENT and KVI_NOCHANGE (ticket #812)
 
81
#if defined(COMPILE_ON_WINDOWS) && !(defined(MINGW))
 
82
                _snprintf(comb, 6, "%d,%d", iFore % 16, iBack % 16);
 
83
#else
 
84
                snprintf(comb, 6, "%d,%d", iFore % 16, iBack % 16);
 
85
#endif
 
86
//              qDebug("Nick color %s",comb);
 
87
                for(int i=0; i<KVI_NUM_NICK_COLORS;++i)
 
88
                {
 
89
                        int numc=0;
 
90
                        // strcmp
 
91
                        while(g_nickColors[i][numc] && comb[numc])
 
92
                        {
 
93
                                if(g_nickColors[i][numc] != comb[numc])
 
94
                                        break;
 
95
                                numc++;
 
96
                        }
 
97
                        if(numc>0)
 
98
                        {
 
99
                                // any match
 
100
                                if(!g_nickColors[i][numc] && !comb[numc])
 
101
                                {
 
102
                                        //exact match
 
103
//                                      qDebug("Exact match %s",g_nickColors[i]);
 
104
                                        KviMemory::free(comb);
 
105
                                        return i;
 
106
                                } else {
 
107
                                        //partial match
 
108
                                        if(numc > numm)
 
109
                                        {
 
110
                                                //better than any previous one
 
111
                                                iBestMatch=i;
 
112
                                                numm=numc;
 
113
                                        }
 
114
                                }
 
115
                        }
 
116
                }
 
117
                KviMemory::free(comb);
 
118
                //no exact match
 
119
//              qDebug("Best match %s",g_nickColors[iBestMatch]);
 
120
                return iBestMatch;
 
121
        }
 
122
}