1 /***************************************************************************
2  *   Copyright (C) 2011 by David Edmundson <kde@davidedmundson.co.uk>      *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
18  ***************************************************************************/
19 
20 #include "adium-theme-content-info.h"
21 #include <QString>
22 #include <QStringList>
23 #include <QHash>
24 
25 
26 // List of colors used by %senderColor%. Copied from
27 // adium/Frameworks/AIUtilities\ Framework/Source/AIColorAdditions.m
28 static const QString defaultColors(QLatin1String("aqua:aquamarine:blue:"
29     "blueviolet:brown:burlywood:cadetblue:chartreuse:chocolate:coral:"
30     "cornflowerblue:crimson:cyan:darkblue:darkcyan:darkgoldenrod:darkgreen:"
31     "darkgrey:darkkhaki:darkmagenta:darkolivegreen:darkorange:darkorchid:"
32     "darkred:darksalmon:darkseagreen:darkslateblue:darkslategrey:darkturquoise:"
33     "darkviolet:deeppink:deepskyblue:dimgrey:dodgerblue:firebrick:forestgreen:"
34     "fuchsia:gold:goldenrod:green:greenyellow:grey:hotpink:indianred:indigo:"
35     "lawngreen:lightblue:lightcoral:lightgreen:lightgrey:lightpink:lightsalmon:"
36     "lightseagreen:lightskyblue:lightslategrey:lightsteelblue:lime:limegreen:"
37     "magenta:maroon:mediumaquamarine:mediumblue:mediumorchid:mediumpurple:"
38     "mediumseagreen:mediumslateblue:mediumspringgreen:mediumturquoise:"
39     "mediumvioletred:midnightblue:navy:olive:olivedrab:orange:orangered:orchid:"
40     "palegreen:paleturquoise:palevioletred:peru:pink:plum:powderblue:purple:"
41     "red:rosybrown:royalblue:saddlebrown:salmon:sandybrown:seagreen:sienna:"
42     "silver:skyblue:slateblue:slategrey:springgreen:steelblue:tan:teal:thistle:"
43     "tomato:turquoise:violet:yellowgreen"));
44 
45 static const QStringList defaultColorList(defaultColors.split(QLatin1Char(':')));
46 
47 
48 class AdiumThemeContentInfoPrivate
49 {
50 public:
51     QString userIconPath;
52     QString senderColor;
53     QString senderStatusIcon;
54     QString senderScreenName;
55     QString textbackgroundcolor;
56 };
57 
AdiumThemeContentInfo()58 AdiumThemeContentInfo::AdiumThemeContentInfo()
59     : AdiumThemeMessageInfo(),
60     d(new AdiumThemeContentInfoPrivate)
61 {
62 }
63 
64 
AdiumThemeContentInfo(AdiumThemeMessageInfo::MessageType type)65 AdiumThemeContentInfo::AdiumThemeContentInfo(AdiumThemeMessageInfo::MessageType type)
66     : AdiumThemeMessageInfo(type),
67       d(new AdiumThemeContentInfoPrivate)
68 {
69 }
70 
AdiumThemeContentInfo(const AdiumThemeContentInfo & other)71 AdiumThemeContentInfo::AdiumThemeContentInfo(const AdiumThemeContentInfo &other)
72     : AdiumThemeMessageInfo(other),
73       d(new AdiumThemeContentInfoPrivate(*other.d))
74 {
75 }
76 
~AdiumThemeContentInfo()77 AdiumThemeContentInfo::~AdiumThemeContentInfo()
78 {
79     delete d;
80 }
81 
operator =(const AdiumThemeContentInfo & other)82 AdiumThemeContentInfo& AdiumThemeContentInfo::operator=(const AdiumThemeContentInfo& other)
83 {
84     AdiumThemeMessageInfo::operator =(other);
85     *d = *other.d;
86     return *this;
87 }
88 
89 
userIconPath() const90 QString AdiumThemeContentInfo::userIconPath() const
91 {
92     return d->userIconPath;
93 }
94 
setUserIconPath(const QString & userIconPath)95 void AdiumThemeContentInfo::setUserIconPath(const QString &userIconPath)
96 {
97     d->userIconPath = userIconPath;
98 }
99 
senderScreenName() const100 QString AdiumThemeContentInfo::senderScreenName() const
101 {
102     return d->senderScreenName;
103 }
104 
setSenderScreenName(const QString & senderScreenName)105 void AdiumThemeContentInfo::setSenderScreenName(const QString & senderScreenName)
106 {
107     d->senderScreenName = senderScreenName;
108 }
109 
senderColor() const110 QString AdiumThemeContentInfo::senderColor() const
111 {
112     return d->senderColor;
113 }
114 
setSenderColor(const QString & senderColor)115 void AdiumThemeContentInfo::setSenderColor(const QString &senderColor)
116 {
117     d->senderColor = senderColor;
118 }
119 
senderStatusIcon() const120 QString AdiumThemeContentInfo::senderStatusIcon() const
121 {
122     return d->senderStatusIcon;
123 }
124 
setSenderStatusIcon(const QString & senderStatusIcon)125 void AdiumThemeContentInfo::setSenderStatusIcon(const QString &senderStatusIcon)
126 {
127     d->senderStatusIcon = senderStatusIcon;
128 }
129 
senderDisplayName() const130 QString AdiumThemeContentInfo::senderDisplayName() const
131 {
132     return sender();
133 
134 }
135 
setSenderDisplayName(const QString & senderDisplayName)136 void AdiumThemeContentInfo::setSenderDisplayName(const QString &senderDisplayName)
137 {
138     setSender(senderDisplayName);
139 
140     // FIXME Themes can have a SenderColors.txt file to specify which colors to
141     //       use instead of the default ones.
142     d->senderColor = defaultColorList.at(qHash(senderDisplayName) % defaultColorList.size());
143 }
144