KUtils
kemoticonsprovider.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kemoticonsprovider.h"
00020 #include "kemoticons.h"
00021
00022 #include <QtCore/QFileInfo>
00023 #include <QtCore/QDir>
00024 #include <QtGui/QTextDocument>
00025
00026 #include <kio/netaccess.h>
00027 #include "kstandarddirs.h"
00028 #include "kdebug.h"
00029
00030 class KEmoticonsProviderPrivate
00031 {
00032 public:
00033 KEmoticonsProviderPrivate();
00034 QString m_themeName;
00035 QString m_fileName;
00036 QString m_themePath;
00037 QHash<QString, QStringList> m_emoticonsMap;
00038 QHash<QChar, QList<KEmoticonsProvider::Emoticon> > m_emoticonsIndex;
00039 };
00040
00041 KEmoticonsProviderPrivate::KEmoticonsProviderPrivate()
00042 {
00043 }
00044
00045 KEmoticonsProvider::KEmoticonsProvider(QObject *parent)
00046 : QObject(parent), d(new KEmoticonsProviderPrivate)
00047 {
00048 }
00049
00050 KEmoticonsProvider::~KEmoticonsProvider()
00051 {
00052 delete d;
00053 }
00054
00055 bool KEmoticonsProvider::loadTheme(const QString &path)
00056 {
00057 QFileInfo info(path);
00058 d->m_fileName = info.fileName();
00059 d->m_themeName = info.dir().dirName();
00060 d->m_themePath = info.absolutePath();
00061 return true;
00062 }
00063
00064 bool KEmoticonsProvider::removeEmoticon(const QString &emo)
00065 {
00066 Q_UNUSED(emo);
00067 return false;
00068 }
00069
00070 bool KEmoticonsProvider::addEmoticon(const QString &emo, const QString &text, AddEmoticonOption option)
00071 {
00072 if (option == Copy) {
00073 KIO::NetAccess::dircopy(KUrl(emo), KUrl(d->m_themePath));
00074 }
00075
00076 Q_UNUSED(text);
00077 return false;
00078 }
00079
00080 void KEmoticonsProvider::save()
00081 {
00082 }
00083
00084 QString KEmoticonsProvider::themeName() const
00085 {
00086 return d->m_themeName;
00087 }
00088
00089 void KEmoticonsProvider::setThemeName(const QString &name)
00090 {
00091 d->m_themeName = name;
00092 }
00093
00094 QString KEmoticonsProvider::themePath() const
00095 {
00096 return d->m_themePath;
00097 }
00098
00099 QString KEmoticonsProvider::fileName() const
00100 {
00101 return d->m_fileName;
00102 }
00103
00104 void KEmoticonsProvider::clearEmoticonsMap()
00105 {
00106 d->m_emoticonsMap.clear();
00107 }
00108
00109 void KEmoticonsProvider::addEmoticonsMap(QString key, QStringList value)
00110 {
00111 d->m_emoticonsMap.insert(key, value);
00112 }
00113
00114 void KEmoticonsProvider::removeEmoticonsMap(QString key)
00115 {
00116 d->m_emoticonsMap.remove(key);
00117 }
00118
00119 QHash<QString, QStringList> KEmoticonsProvider::emoticonsMap() const
00120 {
00121 return d->m_emoticonsMap;
00122 }
00123
00124 void KEmoticonsProvider::createNew()
00125 {
00126 }
00127
00128 QHash<QChar, QList<KEmoticonsProvider::Emoticon> > KEmoticonsProvider::emoticonsIndex() const
00129 {
00130 return d->m_emoticonsIndex;
00131 }
00132
00133 void KEmoticonsProvider::addEmoticonIndex(const QString &path, const QStringList &emoList)
00134 {
00135 foreach(const QString &s, emoList) {
00136 KEmoticonsProvider::Emoticon e;
00137 QPixmap p;
00138
00139 QString escaped = Qt::escape(s);
00140 e.picPath = path;
00141 p.load(path);
00142
00143 e.picHTMLCode = QString("<img align=\"center\" title=\"%1\" alt=\"%1\" src=\"%2\" width=\"%3\" height=\"%4\" />").arg(escaped).arg(path).arg(p.width()).arg(p.height());
00144
00145 e.matchTextEscaped = escaped;
00146 e.matchText = s;
00147
00148 if (!s.isEmpty() && !escaped.isEmpty())
00149 {
00150 d->m_emoticonsIndex[escaped[0]].append(e);
00151 d->m_emoticonsIndex[s[0]].append(e);
00152 }
00153 }
00154 }
00155
00156 void KEmoticonsProvider::removeEmoticonIndex(const QString &path, const QStringList &emoList)
00157 {
00158 foreach(const QString &s, emoList) {
00159 QString escaped = Qt::escape(s);
00160
00161 if (s.isEmpty() || escaped.isEmpty())
00162 {
00163 continue;
00164 }
00165
00166 QList<Emoticon> ls = d->m_emoticonsIndex.value(escaped[0]);
00167
00168 for (int i = 0; i < ls.size(); ++i) {
00169 if (ls.at(i).picPath == path) {
00170 ls.removeAt(i);
00171 }
00172 }
00173
00174 ls = d->m_emoticonsIndex.value(s[0]);
00175
00176 for (int i = 0; i < ls.size(); ++i) {
00177 if (ls.at(i).picPath == path) {
00178 ls.removeAt(i);
00179 }
00180 }
00181 }
00182 }
00183
00184
00185